@@ -3014,6 +3014,7 @@ static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,in
30143014 {
30153015 if (state->expandedDict .find (macroName.str ())==state->expandedDict .end ()) // expand macro
30163016 {
3017+ bool expanded=false ;
30173018 Define *def=isDefined (yyscanner,macroName);
30183019 // In case EXPAND_ONLY_PREDEF is enabled prevent expansion unless the macro was explicitly
30193020 // predefined
@@ -3046,7 +3047,28 @@ static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,in
30463047 // printf(" <<<< call replaceFunctionMacro: replaced=%d\n",replaced);
30473048 len+=l;
30483049 }
3049- // printf(" macroName='%s' expMacro='%s' replaced=%d\n",qPrint(macroName),qPrint(expMacro),replaced);
3050+ else if (macroName==" __VA_OPT__" )
3051+ {
3052+ // expr='( something __VA_OPT__(value) )' or '( something __VA_OPT__(value) something_else )'
3053+ static const reg::Ex re (R"( __VA_OPT__\((.*)\)(.*)\))" );
3054+ reg::Match m;
3055+ if (reg::search (expr.mid (p).str (),m,re))
3056+ {
3057+ assert (m.size ()==3 );
3058+ std::string value = m[1 ].str ();
3059+ std::string remainder = m[2 ].str ();
3060+ // printf("value='%s' remainder='%s'\n",qPrint(value),qPrint(remainder));
3061+ expMacro = stripWhiteSpace (remainder).empty () ? std::string () : value;
3062+ expanded=true ;
3063+ replaced=true ;
3064+ len+=l+2 +m[1 ].str ().length ();
3065+ }
3066+ else
3067+ {
3068+ // printf("no match for '%s'\n",qPrint(expr));
3069+ }
3070+ }
3071+ // printf(" macroName='%s' expMacro='%s' replaced=%d expanded=%d\n",qPrint(macroName),qPrint(expMacro),replaced,expanded);
30503072
30513073 if (replaced) // expand the macro and rescan the expression
30523074 {
@@ -3055,8 +3077,7 @@ static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,in
30553077 QCString restExpr=expr.right (expr.length ()-len-p);
30563078 addSeparatorsIfNeeded (yyscanner,expr,resultExpr,restExpr,p);
30573079 processConcatOperators (resultExpr);
3058- // printf(" macroName=%s restExpr='%s' def->nonRecursive=%d\n",qPrint(macroName),qPrint(restExpr),def->nonRecursive);
3059- bool expanded=false ;
3080+ // printf(" macroName=%s restExpr='%s' def->nonRecursive=%d\n",qPrint(macroName),qPrint(restExpr),def ? def->nonRecursive : false);
30603081 if (def && !def->nonRecursive )
30613082 {
30623083 state->expandedDict .emplace (toStdString (macroName),def);
0 commit comments