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.
Added some more keywords.
  • Loading branch information
albert-github committed Nov 9, 2021
1 parent 84e1339 commit da6dc3d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/code.l
Expand Up @@ -3738,7 +3738,20 @@ static bool skipLanguageSpecificKeyword(yyscan_t yyscanner,const char *keyword)
"internal", "null", "pin_ptr", "raise",
"remove", "self", "set", "transient"};
static std::unordered_set<std::string> non_java_keywords = {
"inline", "requires", "virtual"};
"alignas", "alignof", "and", "and_eq", "asm",
"atomic_cancel", "atomic_commit", "atomic_noexcept", "auto", "bitand",
"bitor", "bool", "char8_t", "char16_t", "char32_t",
"compl", "concept", "consteval", "constexpr", "constinit",
"const_cast", "co_await", "co_return", "co_yield", "decltype",
"delete", "dynamic_cast", "explicit", "export", "extern",
"friend", "inline", "mutable", "namespace", "noexcept",
"not", "not_eq", "nullptr", "operator", "or",
"or_eq", "reflexpr", "register", "reinterpret_cast", "requires",
"signed", "sizeof", "static_assert", "static_cast", "struct",
"template", "thread_local", "typedef", "typeid", "typename",
"union", "unsigned", "using", "virtual", "wchar_t",
"xor", "xor_eq"
};
bool retval;
switch (yyextra->lang)
{
Expand Down
21 changes: 15 additions & 6 deletions src/scanner.l
Expand Up @@ -1053,7 +1053,7 @@ NONLopt [^\n]*
yyextra->curlyCount=0;
BEGIN( ReadNSBody );
}
<FindMembers>{B}*"initonly"{BN}+ {
<FindMembers>{B}*"initonly"{BN}+ { if (yyextra->insideJava) REJECT;
yyextra->current->type += " initonly ";
if (yyextra->insideCli) yyextra->current->spec |= Entry::Initonly;
lineCount(yyscanner);
Expand All @@ -1062,7 +1062,7 @@ NONLopt [^\n]*
yyextra->current->stat = TRUE;
lineCount(yyscanner);
}
<FindMembers>{B}*"extern"{BN}+ {
<FindMembers>{B}*"extern"{BN}+ { if (yyextra->insideJava) REJECT;
yyextra->current->stat = FALSE;
yyextra->current->explicitExternal = TRUE;
lineCount(yyscanner);
Expand Down Expand Up @@ -1129,13 +1129,16 @@ NONLopt [^\n]*
yyextra->current->spec|=Entry::Inline;
lineCount(yyscanner);
}
<FindMembers>{B}*"mutable"{BN}+ { yyextra->current->spec|=Entry::Mutable;
<FindMembers>{B}*"mutable"{BN}+ { if (yyextra->insideJava) REJECT;
yyextra->current->spec|=Entry::Mutable;
lineCount(yyscanner);
}
<FindMembers>{B}*"explicit"{BN}+ { yyextra->current->spec|=Entry::Explicit;
<FindMembers>{B}*"explicit"{BN}+ { if (yyextra->insideJava) REJECT;
yyextra->current->spec|=Entry::Explicit;
lineCount(yyscanner);
}
<FindMembers>{B}*"local"{BN}+ { yyextra->current->spec|=Entry::Local;
<FindMembers>{B}*"local"{BN}+ { if (yyextra->insideJava) REJECT;
yyextra->current->spec|=Entry::Local;
lineCount(yyscanner);
}
<FindMembers>{B}*"@required"{BN}+ { // Objective C 2.0 protocol required section
Expand All @@ -1152,7 +1155,7 @@ NONLopt [^\n]*
}
*/
<FindMembers>{B}*"typename"{BN}+ { lineCount(yyscanner); }
<FindMembers>{B}*"namespace"{BNopt}/[^a-z_A-Z0-9] {
<FindMembers>{B}*"namespace"{BNopt}/[^a-z_A-Z0-9] { if (yyextra->insideJava) REJECT;
yyextra->isTypedef=FALSE;
yyextra->current->section = Entry::NAMESPACE_SEC;
yyextra->current->type = "namespace" ;
Expand Down Expand Up @@ -1358,6 +1361,7 @@ NONLopt [^\n]*
BEGIN( CompoundName );
}
<FindMembers>{B}*"exception"{BN}+ { // Corba IDL/Slice exception
if (yyextra->insideJava) REJECT;
yyextra->isTypedef=FALSE;
yyextra->current->section = Entry::CLASS_SEC;
// preserve UNO IDL, Slice local
Expand Down Expand Up @@ -1489,6 +1493,7 @@ NONLopt [^\n]*
}
<FindMembers>{B}*{TYPEDEFPREFIX}"struct{" |
<FindMembers>{B}*{TYPEDEFPREFIX}"struct"/{BN}+ {
if (yyextra->insideJava) REJECT;
QCString decl = yytext;
yyextra->isTypedef=decl.find("typedef")!=-1;
bool isConst=decl.find("const")!=-1;
Expand Down Expand Up @@ -1570,6 +1575,7 @@ NONLopt [^\n]*
}
<FindMembers>{B}*{TYPEDEFPREFIX}"union{" |
<FindMembers>{B}*{TYPEDEFPREFIX}"union"{BN}+ {
if (yyextra->insideJava) REJECT;
QCString decl=yytext;
yyextra->isTypedef=decl.find("typedef")!=-1;
bool isConst=decl.find("const")!=-1;
Expand Down Expand Up @@ -1633,6 +1639,7 @@ NONLopt [^\n]*
BEGIN( CompoundName ) ;
}
<FindMembers>{B}*"concept"{BN}+ { // C++20 concept
if (yyextra->insideJava) REJECT;
yyextra->isTypedef=FALSE;
yyextra->current->section = Entry::CONCEPT_SEC;
addType(yyscanner);
Expand Down Expand Up @@ -1683,6 +1690,7 @@ NONLopt [^\n]*
BEGIN( ReadTempArgs );
}
<FindMembers>"namespace"{BN}+/{ID}{BN}*"=" { // namespace alias
if (yyextra->insideJava) REJECT;
lineCount(yyscanner);
BEGIN( NSAliasName );
}
Expand Down Expand Up @@ -1773,6 +1781,7 @@ NONLopt [^\n]*
BEGIN(Using);
}
<FindMembers>"using"{BN}+ {
if (yyextra->insideJava) REJECT;
yyextra->current->startLine=yyextra->yyLineNr;
yyextra->current->startColumn = yyextra->yyColNr;
lineCount(yyscanner);
Expand Down

0 comments on commit da6dc3d

Please sign in to comment.