From 5a25a7f33af4a53462a6ddea9e8b82d0d9f23280 Mon Sep 17 00:00:00 2001 From: albert-github Date: Mon, 23 Sep 2019 13:27:51 +0200 Subject: Bug 340202 - @code: static_cast, const_cast, etc C++ keywords The `*_cast` had already been introduced, but there were some other places that needed the "REJECT" as well. Also the cast was missing a whitesace between the cast name and the `<`. Tested also against he doxygen internal documentation. --- src/code.l | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/code.l b/src/code.l index 4998705..f8a062f 100644 --- a/src/code.l +++ b/src/code.l @@ -2606,7 +2606,7 @@ RAWEND ")"[^ \t\(\)\\]{0,16}\" [*^]* { codifyLines(yytext); } -{CASTKW}"<" { // static_cast( +{CASTKW}{B}*"<" { // static_cast( startFontClass("keyword"); codifyLines(yytext); endFontClass(); @@ -2651,6 +2651,12 @@ RAWEND ")"[^ \t\(\)\\]{0,16}\" } {SCOPETNAME}{B}*"<"[^\n\/\-\.\{\"\>]*">"/{BN}*"(" | {SCOPETNAME}/{BN}*"(" { // a() or c::a() or t::a() or A\B\foo() + int i=QCString(yytext).find('<'); + QCString kw = QCString(yytext).left(i).stripWhiteSpace(); + if (kw.right(5)=="_cast" && YY_START==Body) + { + REJECT; + } addType(); generateFunctionLink(*g_code,yytext); g_bracketCount=0; @@ -3062,6 +3068,12 @@ RAWEND ")"[^ \t\(\)\\]{0,16}\" endFontClass(); } {ID}(({B}*"<"[^\n\[\](){}<>]*">")?({B}*"::"{B}*{ID})?)* { + int i=QCString(yytext).find('<'); + QCString kw = QCString(yytext).left(i).stripWhiteSpace(); + if (kw.right(5)=="_cast") + { + REJECT; + } addParmType(); g_parmName=yytext; generateClassOrGlobalLink(*g_code,yytext,!g_insideBody); -- cgit v0.12 From fe66145d44ad4cf79e2bb4928b190c415aaf5b90 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Tue, 24 Sep 2019 20:11:58 +0200 Subject: Avoid code duplication and make the keyword matching more robust --- src/code.l | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/code.l b/src/code.l index f8a062f..9428432 100644 --- a/src/code.l +++ b/src/code.l @@ -1806,6 +1806,14 @@ static bool skipLanguageSpecificKeyword(const QCString &kw) return g_insideCpp && (kw == "remove" || kw == "set" || kw == "get"); } +static bool isCastKeyword(const QCString &s) +{ + int i=s.find('<'); + if (i==-1) return FALSE; + QCString kw = s.left(i).stripWhiteSpace(); + return kw=="const_cast" || kw=="static_cast" || kw=="dynamic_cast" || kw=="reinterpret_cast"; +} + /* ----------------------------------------------------------------- */ #undef YY_INPUT @@ -2619,9 +2627,7 @@ RAWEND ")"[^ \t\(\)\\]{0,16}\" g_name+=yytext+7; } {SCOPENAME}{B}*"<"[^\n\/\-\.\{\"\>\(]*">"("::"{ID})*/{B}* { // A *pt; - int i=QCString(yytext).find('<'); - QCString kw = QCString(yytext).left(i).stripWhiteSpace(); - if (kw.right(5)=="_cast" && YY_START==Body) + if (isCastKeyword(yytext) && YY_START==Body) { REJECT; } @@ -2651,9 +2657,7 @@ RAWEND ")"[^ \t\(\)\\]{0,16}\" } {SCOPETNAME}{B}*"<"[^\n\/\-\.\{\"\>]*">"/{BN}*"(" | {SCOPETNAME}/{BN}*"(" { // a() or c::a() or t::a() or A\B\foo() - int i=QCString(yytext).find('<'); - QCString kw = QCString(yytext).left(i).stripWhiteSpace(); - if (kw.right(5)=="_cast" && YY_START==Body) + if (isCastKeyword(yytext)) { REJECT; } @@ -3068,9 +3072,7 @@ RAWEND ")"[^ \t\(\)\\]{0,16}\" endFontClass(); } {ID}(({B}*"<"[^\n\[\](){}<>]*">")?({B}*"::"{B}*{ID})?)* { - int i=QCString(yytext).find('<'); - QCString kw = QCString(yytext).left(i).stripWhiteSpace(); - if (kw.right(5)=="_cast") + if (isCastKeyword(yytext)) { REJECT; } -- cgit v0.12