diff options
-rw-r--r-- | src/code.l | 39 | ||||
-rw-r--r-- | src/pre.l | 45 | ||||
-rw-r--r-- | src/scanner.l | 16 | ||||
-rw-r--r-- | testing/073/073__typed__enum_8cpp.xml | 96 | ||||
-rw-r--r-- | testing/073_typed_enum.cpp | 18 |
5 files changed, 176 insertions, 38 deletions
@@ -650,16 +650,22 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER} yyextra->code->codify(yytext); BEGIN( SkipCPP ) ; } +<SkipCPP>\" { + yyextra->code->codify(yytext); + yyextra->lastStringContext=YY_START; + BEGIN( SkipString ) ; + } <SkipCPP>. { yyextra->code->codify(yytext); } -<SkipCPP>[^\n\/\\]+ { +<SkipCPP>[^\n\/\\\"]+ { yyextra->code->codify(yytext); } <SkipCPP>\\[\r]?\n { codifyLines(yyscanner,yytext); } -<SkipCPP>"//" { +<SkipCPP>"//"/[^/!] { + REJECT; yyextra->code->codify(yytext); } <Body,FuncCall>"{" { @@ -2004,15 +2010,25 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER} yyextra->yyLineNr+=QCString(yytext).contains('\n'); } <RemoveSpecialCComment>"*/"{B}*\n({B}*\n)*({B}*(("//@"[{}])|("/*@"[{}]"*/")){B}*\n)? { - yyextra->yyLineNr+=QCString(yytext).contains('\n'); - nextCodeLine(yyscanner); if (yyextra->lastSpecialCContext==SkipCxxComment) { // force end of C++ comment here + yyextra->yyLineNr+=QCString(yytext).contains('\n'); + nextCodeLine(yyscanner); endFontClass(yyscanner); BEGIN( yyextra->lastCContext ) ; } else { + yyextra->yyLineNr+=QCString(yytext).contains('\n'); + if (yytext[yyleng-1]=='\n') + { + yyextra->yyLineNr--; + unput('\n'); + } + else + { + nextCodeLine(yyscanner); + } BEGIN(yyextra->lastSpecialCContext); } } @@ -2033,7 +2049,7 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER} if (YY_START==SkipCPP) REJECT; if (Config_getBool(STRIP_CODE_COMMENTS)) { - yyextra->yyLineNr+=((QCString)yytext).contains('\n'); + yyextra->yyLineNr+=QCString(yytext).contains('\n'); nextCodeLine(yyscanner); } else @@ -2048,10 +2064,10 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER} BEGIN( yyextra->lastCContext ) ; } } -<SkipCPP>\n/.*\n { +<SkipCPP>\n/.*\n { endFontClass(yyscanner); - codifyLines(yyscanner,yytext); BEGIN( yyextra->lastSkipCppContext ) ; + unput('\n'); } <*>\n{B}*"//@"[{}].*\n { // remove one-line group marker if (Config_getBool(STRIP_CODE_COMMENTS)) @@ -2134,14 +2150,9 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER} endFontClass(yyscanner); } } -<*>"//"[!/][^\n]*\n { // strip special one-line comment +<*>"//"[!/][^\n]*/\n { // strip special one-line comment if (YY_START==SkipComment || YY_START==SkipString) REJECT; - if (Config_getBool(STRIP_CODE_COMMENTS)) - { - char c[2]; c[0]='\n'; c[1]=0; - codifyLines(yyscanner,c); - } - else + if (!Config_getBool(STRIP_CODE_COMMENTS)) { startFontClass(yyscanner,"comment"); codifyLines(yyscanner,yytext); @@ -1502,7 +1502,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) } } <SkipDoubleQuote>"//"[/]? { yyextra->defText += yytext; yyextra->defLitText+=yytext; } -<SkipDoubleQuote>"/*" { yyextra->defText += yytext; yyextra->defLitText+=yytext; } +<SkipDoubleQuote>"/*"[*]? { yyextra->defText += yytext; yyextra->defLitText+=yytext; } <SkipDoubleQuote>\" { yyextra->defText += *yytext; yyextra->defLitText+=yytext; BEGIN(DefineText); @@ -2036,7 +2036,7 @@ static bool replaceFunctionMacro(yyscan_t yyscanner,const QCString &expr,QCStrin QCString arg; int argCount=0; bool done=FALSE; - + // PHASE 1: read the macro arguments if (def->nargs==0) { @@ -2395,7 +2395,7 @@ static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,in } else if (def && def->nargs>=0) // function macro { - //printf(" >>>> call replaceFunctionMacro\n"); + //printf(" >>>> call replaceFunctionMacro expr='%s'\n",qPrint(expr)); replaced=replaceFunctionMacro(yyscanner,expr,rest,p+l,len,def,expMacro,level); //printf(" <<<< call replaceFunctionMacro: replaced=%d\n",replaced); len+=l; @@ -3186,22 +3186,34 @@ static void initPredefined(yyscan_t yyscanner,const char *fileName) i_obrace<i_cbrace ) // predefined function macro definition { - //printf("predefined function macro '%s'\n",defStr); - QRegExp reId("[a-z_A-Z\x80-\xFF][a-z_A-Z0-9\x80-\xFF]*"); // regexp matching an id + bool varArgs = false; + int count = 0; + int i,pi,l; std::map<std::string,int> argMap; - int i=i_obrace+1,pi,l,count=0; - // gather the formal arguments in a dictionary - while (i<i_cbrace && (pi=reId.match(ds,i,&l))) + QRegExp reId("[a-z_A-Z\x80-\xFF][a-z_A-Z0-9\x80-\xFF]*"); // regexp matching an id + if (ds.mid(i_obrace+1,i_cbrace-i_obrace-1)=="...") { - if (l>0) // see bug375037 - { - argMap.emplace(toStdString(ds.mid(pi,l)),count); - count++; - i=pi+l; - } - else + varArgs = true; + argMap.emplace("__VA_ARGS__",count); + count++; + } + else + { + //printf("predefined function macro '%s'\n",qPrint(ds.mid(i_obrace+1,i_cbrace-i_obrace-1))); + i=i_obrace+1; + // gather the formal arguments in a dictionary + while (i<i_cbrace && (pi=reId.match(ds,i,&l))) { - i++; + if (l>0) // see bug375037 + { + argMap.emplace(toStdString(ds.mid(pi,l)),count); + count++; + i=pi+l; + } + else + { + i++; + } } } // strip definition part @@ -3241,6 +3253,7 @@ static void initPredefined(yyscan_t yyscanner,const char *fileName) def.nonRecursive = nonRecursive; def.fileDef = state->yyFileDef; def.fileName = fileName; + def.varArgs = varArgs; state->contextDefines.insert(std::make_pair(def.name.str(),def)); //printf("#define '%s' '%s' #nargs=%d\n", diff --git a/src/scanner.l b/src/scanner.l index e4e7184..e56f151 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -60,6 +60,9 @@ #define USE_STATE2STRING 0 +static AtomicInt anonCount; +static AtomicInt anonNSCount; + struct scannerYY_state { OutlineParserInterface *thisParser; @@ -105,8 +108,6 @@ struct scannerYY_state int yyBegLineNr = 1 ; int yyColNr = 1 ; int yyBegColNr = 1 ; - int anonCount = 0 ; - int anonNSCount = 0 ; QCString yyFileName; MethodTypes mtype = Method; bool stat = false; @@ -3784,7 +3785,7 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) BEGIN(MemberSpecSkip); } <TypedefName>";" { /* typedef of anonymous type */ - yyextra->current->name.sprintf("@%d",yyextra->anonCount++); + yyextra->current->name.sprintf("@%d",anonCount++); if ((yyextra->current->section == Entry::ENUM_SEC) || (yyextra->current->spec&Entry::Enum)) { yyextra->current->program+=','; // add field terminator @@ -3859,7 +3860,7 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) { // anonymous compound yyextra->inside -> insert dummy variable name //printf("Adding anonymous variable for scope %s\n",p->name.data()); - yyextra->msName.sprintf("@%d",yyextra->anonCount++); + yyextra->msName.sprintf("@%d",anonCount++); break; } } @@ -5644,12 +5645,12 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) } else // use invisible name { - yyextra->current->name.sprintf("@%d",yyextra->anonNSCount); + yyextra->current->name.sprintf("@%d",anonNSCount.load()); } } else { - yyextra->current->name.sprintf("@%d",yyextra->anonCount++); + yyextra->current->name.sprintf("@%d",anonCount++); } } yyextra->curlyCount=0; @@ -7254,7 +7255,6 @@ static void parseMain(yyscan_t yyscanner, yyextra->column = 0; scannerYYrestart(0,yyscanner); - //yyextra->anonCount = 0; // don't reset per file //depthIf = 0; yyextra->protection = Public; yyextra->mtype = Method; @@ -7308,7 +7308,7 @@ static void parseMain(yyscan_t yyscanner, parseCompounds(yyscanner,rt); - yyextra->anonNSCount++; + anonNSCount++; // add additional entries that were created during processing for (auto &kv: yyextra->outerScopeEntries) diff --git a/testing/073/073__typed__enum_8cpp.xml b/testing/073/073__typed__enum_8cpp.xml index 7e68f3e..9d6947e 100644 --- a/testing/073/073__typed__enum_8cpp.xml +++ b/testing/073/073__typed__enum_8cpp.xml @@ -15,6 +15,102 @@ </inbodydescription> <location file="073_typed_enum.cpp" line="7" column="1" bodyfile="073_typed_enum.cpp" bodystart="7" bodyend="7"/> </memberdef> + <memberdef kind="enum" id="073__typed__enum_8cpp_1a2890437f40d5bcd72710a06cd6a934f5" prot="public" static="no" strong="yes"> + <type>unsigned char</type> + <name>Mem</name> + <enumvalue id="073__typed__enum_8cpp_1a2890437f40d5bcd72710a06cd6a934f5a2ad9d63b69c4a10a5cc9cad923133bc4" prot="public"> + <name>Bottom</name> + <initializer>= 0</initializer> + <briefdescription> + </briefdescription> + <detaileddescription> + </detaileddescription> + </enumvalue> + <enumvalue id="073__typed__enum_8cpp_1a2890437f40d5bcd72710a06cd6a934f5ac946366be0e03f425017b1a97b4a7fbb" prot="public"> + <name>NotMem</name> + <initializer>= 1U << 0</initializer> + <briefdescription> + </briefdescription> + <detaileddescription> + </detaileddescription> + </enumvalue> + <enumvalue id="073__typed__enum_8cpp_1a2890437f40d5bcd72710a06cd6a934f5a165d3d525f6d0cbd55e42cc3058cafcc" prot="public"> + <name>Ptr</name> + <initializer>= 1U << 1</initializer> + <briefdescription> + </briefdescription> + <detaileddescription> + </detaileddescription> + </enumvalue> + <enumvalue id="073__typed__enum_8cpp_1a2890437f40d5bcd72710a06cd6a934f5abd34ea97de15a451a2117e2e4cd49c12" prot="public"> + <name>Lval</name> + <initializer>= 1U << 2</initializer> + <briefdescription> + </briefdescription> + <detaileddescription> + </detaileddescription> + </enumvalue> + <enumvalue id="073__typed__enum_8cpp_1a2890437f40d5bcd72710a06cd6a934f5adba5553473d129a7985fb532dc249ff4" prot="public"> + <name>Mem</name> + <initializer>= Ptr | Lval</initializer> + <briefdescription> + </briefdescription> + <detaileddescription> + </detaileddescription> + </enumvalue> + <enumvalue id="073__typed__enum_8cpp_1a2890437f40d5bcd72710a06cd6a934f5aa4ffdcf0dc1f31b9acaf295d75b51d00" prot="public"> + <name>Top</name> + <initializer>= NotMem | Mem</initializer> + <briefdescription> + </briefdescription> + <detaileddescription> + </detaileddescription> + </enumvalue> + <briefdescription> + <para>Strongly types enum when values that has the same name as the enum. </para> + </briefdescription> + <detaileddescription> + </detaileddescription> + <inbodydescription> + </inbodydescription> + <location file="073_typed_enum.cpp" line="10" column="1" bodyfile="073_typed_enum.cpp" bodystart="10" bodyend="17"/> + </memberdef> + <memberdef kind="enum" id="073__typed__enum_8cpp_1a06fc87d81c62e9abb8790b6e5713c55b" prot="public" static="no" strong="no"> + <type/> + <name>@0</name> + <enumvalue id="073__typed__enum_8cpp_1a06fc87d81c62e9abb8790b6e5713c55ba52c998ad250c15a855ff5559e6d0d1d6" prot="public"> + <name>Unnamed1</name> + <briefdescription> + </briefdescription> + <detaileddescription> + </detaileddescription> + </enumvalue> + <briefdescription> + </briefdescription> + <detaileddescription> + </detaileddescription> + <inbodydescription> + </inbodydescription> + <location file="073_typed_enum.cpp" line="19" column="1" bodyfile="073_typed_enum.cpp" bodystart="19" bodyend="21"/> + </memberdef> + <memberdef kind="enum" id="073__typed__enum_8cpp_1adf764cbdea00d65edcd07bb9953ad2b7" prot="public" static="no" strong="no"> + <type/> + <name>@1</name> + <enumvalue id="073__typed__enum_8cpp_1adf764cbdea00d65edcd07bb9953ad2b7a7b130af0c5cb18bfee8c60994fe1d5ee" prot="public"> + <name>Unnamed2</name> + <briefdescription> + </briefdescription> + <detaileddescription> + </detaileddescription> + </enumvalue> + <briefdescription> + </briefdescription> + <detaileddescription> + </detaileddescription> + <inbodydescription> + </inbodydescription> + <location file="073_typed_enum.cpp" line="23" column="1" bodyfile="073_typed_enum.cpp" bodystart="23" bodyend="25"/> + </memberdef> </sectiondef> <briefdescription> </briefdescription> diff --git a/testing/073_typed_enum.cpp b/testing/073_typed_enum.cpp index 0818463..7248c96 100644 --- a/testing/073_typed_enum.cpp +++ b/testing/073_typed_enum.cpp @@ -5,3 +5,21 @@ /** @brief A strongly-typed enum */ enum class E: unsigned short {}; + +/** @brief Strongly types enum when values that has the same name as the enum */ +enum class Mem : unsigned char { + Bottom = 0, + NotMem = 1U << 0, + Ptr = 1U << 1, + Lval = 1U << 2, + Mem = Ptr | Lval, + Top = NotMem | Mem, +}; + +enum { + Unnamed1 +}; + +enum { + Unnamed2 +}; |