Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/robin/fix-locations'
Browse files Browse the repository at this point in the history
* origin/topic/robin/fix-locations:
  Adjust end of Bison-generated locations.
  Extend location printing to include single-line ranges.
  Fix Bison locations.
  • Loading branch information
rsmmr committed Jan 23, 2024
2 parents d6f5027 + 49bd768 commit daa2e3c
Show file tree
Hide file tree
Showing 215 changed files with 1,167 additions and 1,113 deletions.
20 changes: 20 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
1.10.0-dev.129 | 2024-01-23 17:48:19 +0100

* Adjust end of Bison-generated locations. (Robin Sommer, Corelight)

The Bison-side end column points one beyond the element, which isn't
that nice in error messages, so we adjust them now.

* Extend location printing to include single-line ranges. (Robin Sommer, Corelight)

For a location of, e.g., "line 1, column 5 to 10", we now print
`1:5-10`, whereas we used to print it as only `1:5`, hence dropping
information.

* Fix Bison locations. (Robin Sommer, Corelight)

If a Bison rule started with an optional element, its location would
start at the end of the *previous* token if that optional element
wasn't present. We now skip token locations that are zero-sized at the
beginning of a rule.

1.10.0-dev.125 | 2024-01-23 16:27:43 +0100

* Bump 3rdparty/any from `e88b1bf` to `7c76129`
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0-dev.125
1.10.0-dev.129
2 changes: 1 addition & 1 deletion hilti/toolchain/src/ast/location.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ std::string Location::render(bool no_path) const {
else
lines = util::fmt(":%d", _from_line);

if ( _to_line >= 0 && _to_line != _from_line ) {
if ( _to_line >= 0 ) {
if ( _to_character >= 0 )
lines += util::fmt("-%d:%d", _to_line, _to_character);
else
Expand Down
19 changes: 18 additions & 1 deletion hilti/toolchain/src/compiler/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ namespace hilti { namespace detail { class Parser; } }
#define yylex driver->scanner()->lex

static hilti::Meta toMeta(hilti::detail::parser::location l) {
return hilti::Meta(hilti::Location(*l.begin.filename, l.begin.line, l.end.line, l.begin.column, l.end.column));
return hilti::Meta(hilti::Location(*l.begin.filename, l.begin.line, l.end.line, l.begin.column,
(l.end.column > 0 ? l.end.column - 1 : 0)));
}

static hilti::Type iteratorForType(hilti::Type t, bool const_, hilti::Meta m) {
Expand All @@ -67,6 +68,22 @@ static hilti::Type viewForType(hilti::Type t, hilti::Meta m) {

#define __loc__ toMeta(yylhs.location)

#define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
bool done = false; \
for ( int i = 1; i <= N; i++ ) { \
if ( YYRHSLOC(Rhs, i).begin.line != YYRHSLOC(Rhs, i).end.line || \
YYRHSLOC(Rhs, i).begin.column != YYRHSLOC(Rhs, i).end.column ) { \
(Current).begin = YYRHSLOC(Rhs, i).begin; \
(Current).end = YYRHSLOC(Rhs, N).end; \
done = true; \
break; \
} \
} \
if ( ! done ) \
(Current).begin = (Current).end = YYRHSLOC(Rhs, 0).end; \
} while ( false )

static int _field_width = 0;

%}
Expand Down
19 changes: 18 additions & 1 deletion spicy/toolchain/src/compiler/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ namespace spicy { namespace detail { class Parser; } }
#define yylex driver->scanner()->lex

static hilti::Meta toMeta(spicy::detail::parser::location l) {
return hilti::Meta(hilti::Location(*l.begin.filename, l.begin.line, l.end.line, l.begin.column, l.end.column));
return hilti::Meta(hilti::Location(*l.begin.filename, l.begin.line, l.end.line, l.begin.column,
(l.end.column > 0 ? l.end.column - 1 : 0)));
}

static hilti::Type iteratorForType(hilti::Type t, bool const_, hilti::Meta m) {
Expand Down Expand Up @@ -87,6 +88,22 @@ static uint64_t check_int64_range(uint64_t x, bool positive, const hilti::Meta&

#define __loc__ toMeta(yylhs.location)

#define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
bool done = false; \
for ( int i = 1; i <= N; i++ ) { \
if ( YYRHSLOC(Rhs, i).begin.line != YYRHSLOC(Rhs, i).end.line || \
YYRHSLOC(Rhs, i).begin.column != YYRHSLOC(Rhs, i).end.column ) { \
(Current).begin = YYRHSLOC(Rhs, i).begin; \
(Current).end = YYRHSLOC(Rhs, N).end; \
done = true; \
break; \
} \
} \
if ( ! done ) \
(Current).begin = (Current).end = YYRHSLOC(Rhs, 0).end; \
} while ( false )

static int _field_width = 0;

// We keep a stack of doc strings here that's maintained during parsing. There
Expand Down
40 changes: 20 additions & 20 deletions tests/Baseline/hilti.ast.basic-module/output
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@
[debug/compiler] [HILTI] coercing nodes in module Foo
[debug/compiler] [HILTI] resolving nodes in module Foo
[debug/ast-final] # [HILTI] Foo: Final AST (round 1)
[debug/ast-final] - Module %4 (basic-module.hlt:5:1-11:2) [@m:XXX]
[debug/ast-final] - Module %4 (basic-module.hlt:5:1-11:1) [@m:XXX]
[debug/ast-final] | Foo -> declaration::Module %6 <id="Foo"> [canon-id: Foo] [@d:XXX] ([@d:XXX])
[debug/ast-final] | X -> declaration::Type %1 <linkage="private"> [canon-id: Foo::X] (resolved) [@d:XXX] ([@d:XXX])
[debug/ast-final] | foo -> declaration::Function %2 <linkage="private" parent_type="%???"> [canon-id: Foo::foo] [@d:XXX] ([@d:XXX])
[debug/ast-final] - ID <name="Foo"> (basic-module.hlt:5:8) [@i:XXX]
[debug/ast-final] - statement::Block (basic-module.hlt:5:1-11:2) [@s:XXX]
[debug/ast-final] - declaration::Type %1 <linkage="private"> (basic-module.hlt:5:13-7:15) [canon-id: Foo::X] (resolved) [@d:XXX]
[debug/ast-final] - ID <name="X"> (basic-module.hlt:7:6) [@i:XXX]
[debug/ast-final] - type::Bool (basic-module.hlt:7:10) (const) (type-id: Foo::X) (resolved) [@t:XXX]
[debug/ast-final] - node::None (basic-module.hlt:5:13-7:15) [@n:XXX]
[debug/ast-final] - declaration::Function %2 <linkage="private" parent_type="%???"> (basic-module.hlt:9:1) [canon-id: Foo::foo] [@d:XXX]
[debug/ast-final] - ID <name="Foo"> (basic-module.hlt:5:8-5:10) [@i:XXX]
[debug/ast-final] - statement::Block (basic-module.hlt:5:1-11:1) [@s:XXX]
[debug/ast-final] - declaration::Type %1 <linkage="private"> (basic-module.hlt:7:1-7:14) [canon-id: Foo::X] (resolved) [@d:XXX]
[debug/ast-final] - ID <name="X"> (basic-module.hlt:7:6-7:6) [@i:XXX]
[debug/ast-final] - type::Bool (basic-module.hlt:7:10-7:13) (const) (type-id: Foo::X) (resolved) [@t:XXX]
[debug/ast-final] - node::None (basic-module.hlt:7:1-7:14) [@n:XXX]
[debug/ast-final] - declaration::Function %2 <linkage="private" parent_type="%???"> (basic-module.hlt:9:1-9:29) [canon-id: Foo::foo] [@d:XXX]
[debug/ast-final] | bar -> declaration::Parameter %3 <is_type_param="false" kind="in"> [canon-id: Foo::foo::bar] [@d:XXX] ([@d:XXX])
[debug/ast-final] - Function <cc="<standard>"> (basic-module.hlt:9:8) [@f:XXX]
[debug/ast-final] - ID <name="foo"> (basic-module.hlt:9:16) [@i:XXX]
[debug/ast-final] - type::Function <flavor="standard"> (basic-module.hlt:9:8) (const) (resolved) [@t:XXX]
[debug/ast-final] - type::function::Result (basic-module.hlt:9:9) [@t:XXX]
[debug/ast-final] - type::String (basic-module.hlt:9:9) (const) (resolved) [@t:XXX]
[debug/ast-final] - declaration::Parameter %3 <is_type_param="false" kind="in"> (basic-module.hlt:9:20) [canon-id: Foo::foo::bar] [@d:XXX]
[debug/ast-final] - ID <name="bar"> (basic-module.hlt:9:25) [@i:XXX]
[debug/ast-final] - type::Real (basic-module.hlt:9:20) (const) (resolved) [@t:XXX]
[debug/ast-final] - node::None (basic-module.hlt:5:13-7:15) [@n:XXX]
[debug/ast-final] - node::None (basic-module.hlt:5:13-7:15) [@n:XXX]
[debug/ast-final] - node::None (basic-module.hlt:5:13-7:15) [@n:XXX]
[debug/ast-final] - node::None (basic-module.hlt:5:13-7:15) [@n:XXX]
[debug/ast-final] - Function <cc="<standard>"> (basic-module.hlt:9:9-9:28) [@f:XXX]
[debug/ast-final] - ID <name="foo"> (basic-module.hlt:9:16-9:18) [@i:XXX]
[debug/ast-final] - type::Function <flavor="standard"> (basic-module.hlt:9:9-9:28) (const) (resolved) [@t:XXX]
[debug/ast-final] - type::function::Result (basic-module.hlt:9:9-9:14) [@t:XXX]
[debug/ast-final] - type::String (basic-module.hlt:9:9-9:14) (const) (resolved) [@t:XXX]
[debug/ast-final] - declaration::Parameter %3 <is_type_param="false" kind="in"> (basic-module.hlt:9:20-9:27) [canon-id: Foo::foo::bar] [@d:XXX]
[debug/ast-final] - ID <name="bar"> (basic-module.hlt:9:25-9:27) [@i:XXX]
[debug/ast-final] - type::Real (basic-module.hlt:9:20-9:23) (const) (resolved) [@t:XXX]
[debug/ast-final] - node::None (basic-module.hlt:7:1-7:14) [@n:XXX]
[debug/ast-final] - node::None (basic-module.hlt:7:1-7:14) [@n:XXX]
[debug/ast-final] - node::None (basic-module.hlt:7:1-7:14) [@n:XXX]
[debug/ast-final] - node::None (basic-module.hlt:7:1-7:14) [@n:XXX]
[debug/compiler] [HILTI] validating module Foo (post)
[debug/compiler] finalized module Foo
[debug/compiler] compiling module Foo to C++
Expand Down
Loading

0 comments on commit daa2e3c

Please sign in to comment.