commit fb1e19477efd75e2018f401929d1bc1074e4c0fb
parent b337bcfe98f0f09aca8688f1d3bc9f2053890631
Author: Sebastian <sebastian@sebsite.pw>
Date: Thu, 24 Feb 2022 20:47:31 -0500
ast: store both start and end location in decl
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
6 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/cmd/haredoc/sort.ha b/cmd/haredoc/sort.ha
@@ -37,7 +37,8 @@ fn sort_decls(decls: []ast::decl) summary = {
};
append(bucket, ast::decl {
exported = true,
- loc = decl.loc,
+ start = decl.start,
+ end = decl.end,
decl = {
// XXX: Kind of bad
let new: []ast::decl_type = [];
@@ -51,7 +52,8 @@ fn sort_decls(decls: []ast::decl) summary = {
for (let j = 0z; j < len(c); j += 1) {
append(sorted.constants, ast::decl {
exported = true,
- loc = decl.loc,
+ start = decl.start,
+ end = decl.end,
decl = {
// XXX: Kind of bad
let new: []ast::decl_const = [];
@@ -65,7 +67,8 @@ fn sort_decls(decls: []ast::decl) summary = {
for (let j = 0z; j < len(g); j += 1) {
append(sorted.globals, ast::decl {
exported = true,
- loc = decl.loc,
+ start = decl.start,
+ end = decl.end,
decl = {
// XXX: Kind of bad
let new: []ast::decl_global = [];
diff --git a/hare/ast/decl.ha b/hare/ast/decl.ha
@@ -54,7 +54,8 @@ export type decl_func = struct {
// A Hare declaration.
export type decl = struct {
exported: bool,
- loc: lex::location,
+ start: lex::location,
+ end: lex::location,
decl: ([]decl_const | []decl_global | []decl_type | decl_func),
// Only valid if the lexer has comments enabled
diff --git a/hare/parse/decl.ha b/hare/parse/decl.ha
@@ -181,6 +181,7 @@ export fn decls(lexer: *lex::lexer) ([]ast::decl | error) = {
let decls: []ast::decl = [];
for (true) {
if (peek(lexer, ltok::EOF)? is lex::token) break;
+ const start = lex::mkloc(lexer);
let comment = "";
let exported = match (try(lexer, ltok::EXPORT)?) {
case void =>
@@ -210,7 +211,8 @@ export fn decls(lexer: *lex::lexer) ([]ast::decl | error) = {
};
append(decls, ast::decl {
exported = exported,
- loc = lex::mkloc(lexer),
+ start = start,
+ end = lex::mkloc(lexer),
decl = decl,
docs = comment,
});
diff --git a/hare/unit/process.ha b/hare/unit/process.ha
@@ -70,7 +70,8 @@ fn process_func(
return decl {
exported = adecl.exported,
- loc = adecl.loc,
+ start = adecl.start,
+ end = adecl.end,
decl = decl_func {
symbol = afndecl.symbol,
// TODO: Add namespace to ident
diff --git a/hare/unit/unit.ha b/hare/unit/unit.ha
@@ -24,7 +24,8 @@ export type decl_func = struct {
// A declaration within a unit.
export type decl = struct {
exported: bool,
- loc: lex::location,
+ start: lex::location,
+ end: lex::location,
decl: (decl_func | void), // TODO: Other decl types
};
diff --git a/hare/unparse/decl.ha b/hare/unparse/decl.ha
@@ -160,8 +160,9 @@ fn decl_test(d: ast::decl, expected: str) bool = {
};
let d = ast::decl {
- loc = loc,
exported = false,
+ start = loc,
+ end = loc,
decl = [
ast::decl_global {
is_const = false,