Skip to content

Commit

Permalink
fix(zscript): 'loop()'s not having location metadata associated with …
Browse files Browse the repository at this point in the history
…their identifier
  • Loading branch information
EmilyV99 committed May 3, 2024
1 parent 84b024e commit 68a5f70
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/parser/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ void ASTStmtForEach::execute(ASTVisitor& visitor, void* param)

uint ASTStmtRangeLoop::next_comment_id = 0;

ASTStmtRangeLoop::ASTStmtRangeLoop(ASTDataType* type, string const& iden,
ASTStmtRangeLoop::ASTStmtRangeLoop(ASTDataType* type, ASTString* iden,
ASTRange* range, ASTExpr* increment, ASTStmt* body, LocationData const& location)
: ASTStmt(location), iden(iden), decl(nullptr), type(type),
increment(increment), body(body), range(range),
Expand Down
4 changes: 2 additions & 2 deletions src/parser/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -634,13 +634,13 @@ namespace ZScript
{
DEF_COMMENT_UID();
public:
ASTStmtRangeLoop(ASTDataType* type, string const& iden, ASTRange* range,
ASTStmtRangeLoop(ASTDataType* type, ASTString* iden, ASTRange* range,
ASTExpr* increment, ASTStmt* body, LocationData const& location = LOC_NONE);
ASTStmtRangeLoop* clone() const {return new ASTStmtRangeLoop(*this);}

void execute(ASTVisitor& visitor, void* param = NULL);

string iden;
owning_ptr<ASTString> iden;
uint overflow;
owning_ptr<ASTDataType> type;
owning_ptr<ASTDataDecl> decl;
Expand Down
2 changes: 1 addition & 1 deletion src/parser/SemanticAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ void SemanticAnalyzer::caseStmtRangeLoop(ASTStmtRangeLoop& host, void* param)

//The data declaration
ASTDataDecl* decl = new ASTDataDecl(host.location);
decl->identifier = new ASTString(host.iden);
decl->identifier = host.iden.release();
decl->baseType = new ASTDataType(dataty, host.location);
auto incrval = host.increment->getCompileTimeValue(this, scope);
optional<int> declval;
Expand Down
16 changes: 6 additions & 10 deletions src/parser/ffscript.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,8 +1687,7 @@ Statement_Loop_Range_Base :
ASTRange* range = (ASTRange*)$6;
ASTExpr* incr = (ASTExpr*)$8;
ASTStmt* body = (ASTStmt*)$10;
$$ = new ASTStmtRangeLoop(type, iden->getValue(), range, incr, body, @$);
delete iden;
$$ = new ASTStmtRangeLoop(type, iden, range, incr, body, @$);
}
| LOOP LPAREN IDENTIFIER Token_In Expression_Range COMMA Expression RPAREN Block_Statement
{
Expand All @@ -1697,16 +1696,15 @@ Statement_Loop_Range_Base :
ASTRange* range = (ASTRange*)$5;
ASTExpr* incr = (ASTExpr*)$7;
ASTStmt* body = (ASTStmt*)$9;
$$ = new ASTStmtRangeLoop(type, iden->getValue(), range, incr, body, @$);
delete iden;
$$ = new ASTStmtRangeLoop(type, iden, range, incr, body, @$);
}
| LOOP LPAREN Expression_Range COMMA Expression RPAREN Block_Statement
{
ASTDataType* type = new ASTDataType(DataType::CFLOAT, @$);
ASTRange* range = (ASTRange*)$3;
ASTExpr* incr = (ASTExpr*)$5;
ASTStmt* body = (ASTStmt*)$7;
$$ = new ASTStmtRangeLoop(type, "__LOOP_ITER", range, incr, body, @$);
$$ = new ASTStmtRangeLoop(type, new ASTString("__LOOP_ITER", @$), range, incr, body, @$);
}
| LOOP LPAREN DataType IDENTIFIER Token_In Expression_Range RPAREN Block_Statement
{
Expand All @@ -1715,8 +1713,7 @@ Statement_Loop_Range_Base :
ASTRange* range = (ASTRange*)$6;
ASTExpr* incr = new ASTNumberLiteral(new ASTFloat("1", ASTFloat::TYPE_DECIMAL, @$), @$);
ASTStmt* body = (ASTStmt*)$8;
$$ = new ASTStmtRangeLoop(type, iden->getValue(), range, incr, body, @$);
delete iden;
$$ = new ASTStmtRangeLoop(type, iden, range, incr, body, @$);
}
| LOOP LPAREN IDENTIFIER Token_In Expression_Range RPAREN Block_Statement
{
Expand All @@ -1725,16 +1722,15 @@ Statement_Loop_Range_Base :
ASTRange* range = (ASTRange*)$5;
ASTExpr* incr = new ASTNumberLiteral(new ASTFloat("1", ASTFloat::TYPE_DECIMAL, @$), @$);
ASTStmt* body = (ASTStmt*)$7;
$$ = new ASTStmtRangeLoop(type, iden->getValue(), range, incr, body, @$);
delete iden;
$$ = new ASTStmtRangeLoop(type, iden, range, incr, body, @$);
}
| LOOP LPAREN Expression_Range RPAREN Block_Statement
{
ASTDataType* type = new ASTDataType(DataType::CFLOAT, @$);
ASTRange* range = (ASTRange*)$3;
ASTExpr* incr = new ASTNumberLiteral(new ASTFloat("1", ASTFloat::TYPE_DECIMAL, @$), @$);
ASTStmt* body = (ASTStmt*)$5;
$$ = new ASTStmtRangeLoop(type, "__LOOP_ITER", range, incr, body, @$);
$$ = new ASTStmtRangeLoop(type, new ASTString("__LOOP_ITER", @$), range, incr, body, @$);
}
;

Expand Down

0 comments on commit 68a5f70

Please sign in to comment.