@@ -1146,8 +1146,20 @@ class Macro {
11461146 } else if (tok->op == ' #' && sameline (tok, tok->next ) && tok->next ->op != ' #' ) {
11471147 tok = expandHash (tokens, tok->location , tok, macros, expandedmacros, parametertokens);
11481148 } else {
1149- if (!expandArg (tokens, tok, tok->location , macros, expandedmacros, parametertokens))
1150- tokens->push_back (new Token (*tok));
1149+ if (!expandArg (tokens, tok, tok->location , macros, expandedmacros, parametertokens)) {
1150+ bool expanded = false ;
1151+ if (macros.find (tok->str ) != macros.end () && expandedmacros.find (tok->str ) == expandedmacros.end ()) {
1152+ const std::map<TokenString, Macro>::const_iterator it = macros.find (tok->str );
1153+ const Macro &m = it->second ;
1154+ if (!m.functionLike ()) {
1155+ m.expand (tokens, tok, macros, files);
1156+ expanded = true ;
1157+ }
1158+ }
1159+ if (!expanded)
1160+ tokens->push_back (new Token (*tok));
1161+ }
1162+
11511163 if (tok->op == ' (' )
11521164 ++par;
11531165 else if (tok->op == ' )' ) {
@@ -1243,6 +1255,8 @@ class Macro {
12431255 if (tok->op != ' #' ) {
12441256 // A##B => AB
12451257 if (tok->next && tok->next ->op == ' #' && tok->next ->next && tok->next ->next ->op == ' #' ) {
1258+ if (!sameline (tok, tok->next ->next ->next ))
1259+ throw invalidHashHash (tok->location , name ());
12461260 output->push_back (newMacroToken (expandArgStr (tok, parametertokens2), loc, isReplaced (expandedmacros)));
12471261 tok = tok->next ;
12481262 } else {
@@ -1441,7 +1455,19 @@ class Macro {
14411455 throw invalidHashHash (tok->location , name ());
14421456
14431457 Token *B = tok->next ->next ;
1444- const std::string strAB = A->str + expandArgStr (B, parametertokens);
1458+ std::string strAB;
1459+
1460+ TokenList tokensB (files);
1461+ if (expandArg (&tokensB, B, parametertokens)) {
1462+ if (tokensB.empty ())
1463+ strAB = A->str ;
1464+ else {
1465+ strAB = A->str + tokensB.cfront ()->str ;
1466+ tokensB.deleteToken (tokensB.front ());
1467+ }
1468+ } else {
1469+ strAB = A->str + B->str ;
1470+ }
14451471
14461472 bool removeComma = false ;
14471473 if (variadic && strAB == " ," && tok->previous ->str == " ," && args.size () >= 1U && B->str == args[args.size ()-1U ])
@@ -1454,6 +1480,9 @@ class Macro {
14541480 tokens.push_back (new Token (strAB, tok->location ));
14551481 // TODO: For functionLike macros, push the (...)
14561482 expandToken (output, loc, tokens.cfront (), macros, expandedmacros, parametertokens);
1483+ for (Token *b = tokensB.front (); b; b = b->next )
1484+ b->location = loc;
1485+ output->takeTokens (tokensB);
14571486 }
14581487
14591488 return B->next ;
@@ -1498,11 +1527,11 @@ class Macro {
14981527namespace simplecpp {
14991528#ifdef SIMPLECPP_WINDOWS
15001529std::string realFilename (const std::string &f) {
1501- WIN32_FIND_DATA FindFileData;
1502- TCHAR buf[4096 ] = {0 };
1503- for (unsigned int i = 0 ; i < f.size (); ++i)
1504- buf[i] = f[i];
1505- HANDLE hFind = FindFirstFile (buf, &FindFileData);
1530+ WIN32_FIND_DATA FindFileData;
1531+ TCHAR buf[4096 ] = {0 };
1532+ for (unsigned int i = 0 ; i < f.size (); ++i)
1533+ buf[i] = f[i];
1534+ HANDLE hFind = FindFirstFile (buf, &FindFileData);
15061535 if (hFind == INVALID_HANDLE_VALUE)
15071536 return f;
15081537 std::ostringstream ostr;
0 commit comments