Commit be9b5f4c authored by Daniel Clifford's avatar Daniel Clifford Committed by Commit Bot

[torque]: Fix bugs reported by Peter Wong

* Empty string literals (e.g. "" and '') were not recognized a strings. This is
  now fixed.
* return statements without expressions (e.g. for functions with void return
  types) caused crashes.

Change-Id: Ied60f9abffca457a0d85c9e01e3795839fe777c9
Reviewed-on: https://chromium-review.googlesource.com/1042310
Commit-Queue: Daniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52997}
parent 6b1457cf
......@@ -80,8 +80,8 @@ INCREMENT: '++';
DECREMENT: '--';
NOT: '!';
STRING_LITERAL : ('"' ( ESCAPE | ~('"' | '\\' | '\n' | '\r') ) + '"')
| ('\'' ( ESCAPE | ~('"' | '\\' | '\n' | '\r') ) + '\'');
STRING_LITERAL : ('"' ( ESCAPE | ~('"' | '\\' | '\n' | '\r') ) * '"')
| ('\'' ( ESCAPE | ~('"' | '\\' | '\n' | '\r') ) * '\'');
fragment ESCAPE : '\\' ( '\'' | '\\' | '"' );
IDENTIFIER : [A-Za-z][0-9A-Za-z_]* ;
......
This diff is collapsed.
......@@ -287,8 +287,13 @@ antlrcpp::Any AstGenerator::visitExpressionStatement(
antlrcpp::Any AstGenerator::visitReturnStatement(
TorqueParser::ReturnStatementContext* context) {
return implicit_cast<Statement*>(RegisterNode(new ReturnStatement{
Pos(context), context->expression()->accept(this).as<Expression*>()}));
if (context->expression() != nullptr) {
return implicit_cast<Statement*>(RegisterNode(new ReturnStatement{
Pos(context), context->expression()->accept(this).as<Expression*>()}));
} else {
return implicit_cast<Statement*>(
RegisterNode(new ReturnStatement{Pos(context), {}}));
}
}
antlrcpp::Any AstGenerator::visitBreakStatement(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment