Skip to content

Commit

Permalink
issue #8882 Java: Issue with virtual as identifier
Browse files Browse the repository at this point in the history
Some C++ keywords are not Java keywords and can be used as normal identifiers.
This problem has been solved for `inline`, `requires` and `virtual`.
  • Loading branch information
albert-github committed Nov 9, 2021
1 parent 096a1c1 commit 84e1339
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/code.l
Original file line number Diff line number Diff line change
Expand Up @@ -3737,7 +3737,22 @@ static bool skipLanguageSpecificKeyword(yyscan_t yyscanner,const char *keyword)
"gcnew", "gcroot", "generic", "get",
"internal", "null", "pin_ptr", "raise",
"remove", "self", "set", "transient"};
return yyextra->lang==SrcLangExt_Cpp && (non_cpp_keywords.find(keyword) != non_cpp_keywords.end());
static std::unordered_set<std::string> non_java_keywords = {
"inline", "requires", "virtual"};
bool retval;
switch (yyextra->lang)
{
case SrcLangExt_Cpp:
retval = (non_cpp_keywords.find(keyword) != non_cpp_keywords.end());
break;
case SrcLangExt_Java:
retval = (non_java_keywords.find(keyword) != non_java_keywords.end());
break;
default:
retval = false;
break;
}
return retval;
}

static bool isCastKeyword(const char *keyword)
Expand Down
10 changes: 8 additions & 2 deletions src/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,8 @@ NONLopt [^\n]*
REJECT;
}
}
<FindMembers>{B}*"virtual"{BN}+ { yyextra->current->type += " virtual ";
<FindMembers>{B}*"virtual"{BN}+ { if (yyextra->insideJava) REJECT;
yyextra->current->type += " virtual ";
yyextra->current->virt = Virtual;
lineCount(yyscanner);
}
Expand Down Expand Up @@ -1124,7 +1125,8 @@ NONLopt [^\n]*
}
lineCount(yyscanner);
}
<FindMembers>{B}*"inline"{BN}+ { yyextra->current->spec|=Entry::Inline;
<FindMembers>{B}*"inline"{BN}+ { if (yyextra->insideJava) REJECT;
yyextra->current->spec|=Entry::Inline;
lineCount(yyscanner);
}
<FindMembers>{B}*"mutable"{BN}+ { yyextra->current->spec|=Entry::Mutable;
Expand Down Expand Up @@ -2103,16 +2105,19 @@ NONLopt [^\n]*
BEGIN(FindMembers);
}
<FindMembers>"requires" { // C++20 requires clause
if (yyextra->insideJava) REJECT;
yyextra->current->req.resize(0);
yyextra->requiresContext = YY_START;
BEGIN(RequiresClause);
}
<RequiresClause>"requires"{BN}*/"{" { // requires requires { ... }
if (yyextra->insideJava) REJECT;
lineCount(yyscanner) ;
yyextra->current->req+=yytext;
BEGIN( RequiresExpression ) ;
}
<RequiresClause>"requires"{BN}*"(" { // requires requires(T x) { ... }
if (yyextra->insideJava) REJECT;
lineCount(yyscanner) ;
yyextra->current->req+=yytext;
yyextra->lastRoundContext=RequiresExpression;
Expand Down Expand Up @@ -4839,6 +4844,7 @@ NONLopt [^\n]*
BEGIN(FuncQual);
}
<TrailingReturn>"requires"{BN}+ {
if (yyextra->insideJava) REJECT;
yyextra->requiresContext = FuncQual;
yyextra->current->req+=' ';
BEGIN(RequiresClause);
Expand Down

0 comments on commit 84e1339

Please sign in to comment.