Report invalid octal numbers correctly.
Previously, we'd report them as an overflowed integer. Change-Id: Ia3632b4bc880829fb04b08a002d7ce9523567a54 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/472056 Commit-Queue: Brian Osman <brianosman@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
33fb008669
commit
77da3e24dd
@ -114,12 +114,32 @@ DSLParser::DSLParser(Compiler* compiler, const ProgramSettings& settings, Progra
|
|||||||
}
|
}
|
||||||
|
|
||||||
Token DSLParser::nextRawToken() {
|
Token DSLParser::nextRawToken() {
|
||||||
|
Token token;
|
||||||
if (fPushback.fKind != Token::Kind::TK_NONE) {
|
if (fPushback.fKind != Token::Kind::TK_NONE) {
|
||||||
Token result = fPushback;
|
// Retrieve the token from the pushback buffer.
|
||||||
|
token = fPushback;
|
||||||
fPushback.fKind = Token::Kind::TK_NONE;
|
fPushback.fKind = Token::Kind::TK_NONE;
|
||||||
return result;
|
} else {
|
||||||
|
// Fetch a token from the lexer.
|
||||||
|
token = fLexer.next();
|
||||||
|
|
||||||
|
// Some tokens are always invalid, so we detect and report them here.
|
||||||
|
switch (token.fKind) {
|
||||||
|
case Token::Kind::TK_RESERVED:
|
||||||
|
this->error(token, "'" + this->text(token) + "' is a reserved word");
|
||||||
|
token.fKind = Token::Kind::TK_IDENTIFIER; // reduces additional follow-up errors
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Token::Kind::TK_BAD_OCTAL:
|
||||||
|
this->error(token, "'" + this->text(token) + "' is not a valid octal number");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return fLexer.next();
|
|
||||||
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
Token DSLParser::nextToken() {
|
Token DSLParser::nextToken() {
|
||||||
@ -131,11 +151,6 @@ Token DSLParser::nextToken() {
|
|||||||
case Token::Kind::TK_BLOCK_COMMENT:
|
case Token::Kind::TK_BLOCK_COMMENT:
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case Token::Kind::TK_RESERVED:
|
|
||||||
this->error(token, "'" + this->text(token) + "' is a reserved word");
|
|
||||||
token.fKind = Token::Kind::TK_IDENTIFIER;
|
|
||||||
[[fallthrough]];
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,7 @@ struct Token {
|
|||||||
TK_END_OF_FILE,
|
TK_END_OF_FILE,
|
||||||
TK_FLOAT_LITERAL,
|
TK_FLOAT_LITERAL,
|
||||||
TK_INT_LITERAL,
|
TK_INT_LITERAL,
|
||||||
|
TK_BAD_OCTAL,
|
||||||
TK_TRUE_LITERAL,
|
TK_TRUE_LITERAL,
|
||||||
TK_FALSE_LITERAL,
|
TK_FALSE_LITERAL,
|
||||||
TK_IF,
|
TK_IF,
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -2460,7 +2460,7 @@ static uint8_t SKSL_INCLUDE_sksl_public[] = {199,3,
|
|||||||
46,23,2,2,
|
46,23,2,2,
|
||||||
1,
|
1,
|
||||||
45,
|
45,
|
||||||
55,149,2,0,3,0,1,2,51,
|
55,149,2,0,3,0,1,2,52,
|
||||||
27,
|
27,
|
||||||
46,153,0,185,0,2,
|
46,153,0,185,0,2,
|
||||||
45,
|
45,
|
||||||
@ -2477,7 +2477,7 @@ static uint8_t SKSL_INCLUDE_sksl_public[] = {199,3,
|
|||||||
46,18,2,2,
|
46,18,2,2,
|
||||||
1,
|
1,
|
||||||
45,
|
45,
|
||||||
55,151,2,0,3,0,1,2,51,
|
55,151,2,0,3,0,1,2,52,
|
||||||
27,
|
27,
|
||||||
46,145,0,177,0,2,
|
46,145,0,177,0,2,
|
||||||
45,
|
45,
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
// rebuild, and then set it back to 1.
|
// rebuild, and then set it back to 1.
|
||||||
|
|
||||||
FLOAT_LITERAL = [0-9]*\.[0-9]+([eE][+-]?[0-9]+)?|[0-9]+\.[0-9]*([eE][+-]?[0-9]+)?|[0-9]+([eE][+-]?[0-9]+)
|
FLOAT_LITERAL = [0-9]*\.[0-9]+([eE][+-]?[0-9]+)?|[0-9]+\.[0-9]*([eE][+-]?[0-9]+)?|[0-9]+([eE][+-]?[0-9]+)
|
||||||
INT_LITERAL = ([0-9]+|0[xX][0-9a-fA-F]+)[uU]?
|
INT_LITERAL = ([1-9][0-9]*|0[0-7]*|0[xX][0-9a-fA-F]+)[uU]?
|
||||||
|
BAD_OCTAL = (0[0-9]+)[uU]?
|
||||||
TRUE_LITERAL = "true"
|
TRUE_LITERAL = "true"
|
||||||
FALSE_LITERAL = "false"
|
FALSE_LITERAL = "false"
|
||||||
IF = "if"
|
IF = "if"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
### Compilation failed:
|
### Compilation failed:
|
||||||
|
|
||||||
error: 1: integer is too large: 08
|
error: 1: '08' is not a valid octal number
|
||||||
error: 2: integer is too large: 012349
|
error: 1: expected expression, but found '08'
|
||||||
2 errors
|
2 errors
|
||||||
|
Loading…
Reference in New Issue
Block a user