@@ -1845,6 +1845,13 @@ namespace simplecpp {
18451845 class Macro ;
18461846 using MacroMap = std::unordered_map<TokenString,Macro>;
18471847
1848+ /* * Set the location of all tokens */
1849+ static void setLocation (TokenList &tokens, const Location &loc)
1850+ {
1851+ for (Token *tok = tokens.front (); tok; tok = tok->next )
1852+ tok->location = loc;
1853+ }
1854+
18481855 class Macro {
18491856 public:
18501857 explicit Macro (std::vector<std::string> &f) : nameTokDef(nullptr ), valueToken(nullptr ), endToken(nullptr ), files(f), tokenListDefine(f), variadic(false ), variadicOpt(false ), valueDefinedInCode_(false ) {}
@@ -2294,8 +2301,7 @@ namespace simplecpp {
22942301 tok = tok->next ;
22952302 }
22962303 }
2297- for (Token *tok2 = tokens.front (); tok2; tok2 = tok2->next )
2298- tok2->location = lpar->location ;
2304+ setLocation (tokens, lpar->location );
22992305 return sameline (lpar,tok) ? tok : nullptr ;
23002306 }
23012307
@@ -2750,8 +2756,7 @@ namespace simplecpp {
27502756 // It seems clearer to handle this case separately even though the code is similar-ish, but we don't want to merge here.
27512757 // TODO The question is whether the ## or varargs may still apply, and how to provoke?
27522758 if (expandArg (tokensB, B, parametertokens)) {
2753- for (Token *b = tokensB.front (); b; b = b->next )
2754- b->location = loc;
2759+ setLocation (tokensB, loc);
27552760 } else {
27562761 tokensB.push_back (new Token (*B));
27572762 tokensB.back ()->location = loc;
@@ -2786,8 +2791,7 @@ namespace simplecpp {
27862791 }
27872792 else if (strAB != " ," && macros.find (strAB) == macros.end ()) {
27882793 A->setstr (strAB);
2789- for (Token *b = tokensB.front (); b; b = b->next )
2790- b->location = loc;
2794+ setLocation (tokensB, loc);
27912795 output.takeTokens (tokensB);
27922796 } else if (sameline (B, nextTok) && sameline (B, nextTok->next ) && nextTok->op == ' #' && nextTok->next ->op == ' #' ) {
27932797 TokenList output2 (files);
@@ -2812,8 +2816,7 @@ namespace simplecpp {
28122816 expandToken (output, loc, tokens.cfront (), macros, expandedmacros, parametertokens, outputList);
28132817 else
28142818 output.takeTokens (tokens);
2815- for (Token *b = tokensB.front (); b; b = b->next )
2816- b->location = loc;
2819+ setLocation (tokensB, loc);
28172820 output.takeTokens (tokensB);
28182821 }
28192822 }
0 commit comments