Skip to content

Commit

Permalink
Skip alignas specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
usiems committed Nov 24, 2023
1 parent 84976a0 commit 9674bee
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
12 changes: 12 additions & 0 deletions generator/parser/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,18 @@ void Lexer::scanKeyword7()
{
switch (*cursor)
{
case 'a':
if (*(cursor + 1) == 'l' &&
*(cursor + 2) == 'i' &&
*(cursor + 3) == 'g' &&
*(cursor + 4) == 'n' &&
*(cursor + 5) == 'a' &&
*(cursor + 6) == 's')
{
token_stream[(int)index++].kind = Token_alignas;
return;
}
break;
case 'd':
if (*(cursor + 1) == 'e' &&
*(cursor + 2) == 'f' &&
Expand Down
33 changes: 28 additions & 5 deletions generator/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ void Parser::keepTrackDebug()
#endif
}

bool Parser::skipAlignas()
{
// we are currently not interested in alignas, so we just skip it
if (token_stream.lookAhead() == Token_alignas)
{
nextToken();
if (token_stream.lookAhead() == '(')
{
if (skip('(', ')'))
{
nextToken();
}
}
return true;
}
return false;
}

bool Parser::skipAttributes()
{
bool any = false;
Expand Down Expand Up @@ -422,7 +440,10 @@ bool Parser::parseName(NameAST *&node, bool acceptTemplateId)
std::size_t start = token_stream.cursor();

WinDeclSpecAST *winDeclSpec = 0;
parseWinDeclSpec(winDeclSpec);
while (skipAlignas() || (!winDeclSpec && parseWinDeclSpec(winDeclSpec)))
{
;
}

NameAST *ast = CreateNode<NameAST>(_M_pool);

Expand Down Expand Up @@ -2054,9 +2075,10 @@ bool Parser::parseClassSpecifier(TypeSpecifierAST *&node)
nextToken();

WinDeclSpecAST *winDeclSpec = 0;
parseWinDeclSpec(winDeclSpec);

skipAttributes();
while (skipAttributes() || skipAlignas() || (!winDeclSpec && parseWinDeclSpec(winDeclSpec)))
{
;
}

while (token_stream.lookAhead() == Token_identifier
&& token_stream.lookAhead(1) == Token_identifier)
Expand Down Expand Up @@ -3359,7 +3381,8 @@ bool Parser::parseDeclarationInternal(DeclarationAST *&node)
// so just consume then until no specifiers are left.
// Luckily the parse methods can be called multiple times, they just add to existing nodes.
while (skipAttributes() ||
parseWinDeclSpec(winDeclSpec) ||
skipAlignas() ||
(!winDeclSpec && parseWinDeclSpec(winDeclSpec)) ||
parseCvQualify(cv) ||
parseFunctionSpecifier(funSpec) ||
parseStorageClassSpecifier(storageSpec))
Expand Down
1 change: 1 addition & 0 deletions generator/parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class Parser
bool parseQ_ENUMS(DeclarationAST *&node);
bool parseQ_ENUM(DeclarationAST *&node);

bool skipAlignas();
bool skipAttributes();
bool skipUntil(int token);
bool skipUntilDeclaration();
Expand Down
1 change: 1 addition & 0 deletions generator/parser/tokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static char const * const _S_token_names[] = {
"Q_PROPERTY",
"__attribute__",
"__typeof",
"alignas",
"and",
"and_eq",
"arrow",
Expand Down
1 change: 1 addition & 0 deletions generator/parser/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum TOKEN_KIND
Token_Q_PROPERTY,
Token___attribute__,
Token___typeof,
Token_alignas,
Token_and,
Token_and_eq,
Token_arrow,
Expand Down

0 comments on commit 9674bee

Please sign in to comment.