@@ -1814,25 +1814,28 @@ void processMacroContent(ParserWrapper)(immutable(LocationContext)* locationCont
18141814Tuple ! (Tree, Location)[] mapParams(ParserWrapper)(Location start, Tree nameToken, MacroParam[string ] paramMap,
18151815 Context! (ParserWrapper) context, Location funcMacroLocation, immutable (Formula)* condition)
18161816{
1817+ auto startLoc = paramMap[nameToken.content].startLoc;
1818+ auto endLoc = paramMap[nameToken.content].endLoc;
1819+ bool goodParam = startLoc.context ! is null && startLoc.context is endLoc.context;
1820+
1821+ assert (start.context.name.among(" ^" , " ##" , " #" ));
1822+
1823+ auto locationContextX1 = context.getLocationContext(immutable (LocationContext)(start.context,
1824+ start.context.name == " #" ? LocationN.init : nameToken.start.loc,
1825+ start.context.name == " #" ? LocationN.LocationDiff.init : nameToken.inputLength,
1826+ funcMacroLocation.context.prev.name ~ " ." ~ nameToken.content,
1827+ goodParam ? startLoc.context.filename : " " ));
1828+
18171829 Tuple ! (Tree, Location)[] r;
18181830 foreach (i, t2; paramMap[nameToken.content].tokens)
18191831 {
18201832 LocationX commonLoc1 = t2.t.start;
18211833 LocationX commonLoc2 = funcMacroLocation;
18221834 findCommonLocationContext(commonLoc1, commonLoc2);
18231835
1824- auto startLoc = paramMap[nameToken.content].startLoc;
1825- auto endLoc = paramMap[nameToken.content].endLoc;
1826- bool goodParam = startLoc.context ! is null && startLoc.context is endLoc.context;
1827-
1828- assert (start.context.name.among(" ^" , " ##" ));
1829- auto locationContextX1 = context.getLocationContext(immutable (LocationContext)(start.context,
1830- nameToken.start.loc, nameToken.inputLength,
1831- funcMacroLocation.context.prev.name ~ " ." ~ nameToken.content,
1832- goodParam ? startLoc.context.filename : " " ));
1833- auto locationContextX = context.getLocationContext(immutable (LocationContext)(locationContextX1, goodParam
1834- ? startLoc.loc : LocationN.init, goodParam
1835- ? (endLoc.loc - startLoc.loc) : LocationN.LocationDiff.init,
1836+ auto locationContextX = context.getLocationContext(immutable (LocationContext)(locationContextX1,
1837+ goodParam ? startLoc.loc : LocationN.init,
1838+ goodParam ? (endLoc.loc - startLoc.loc) : LocationN.LocationDiff.init,
18361839 " ^" , commonLoc1.context.filename));
18371840
18381841 context.locationContextInfoMap.getLocationContextInfo(locationContextX)
@@ -2079,33 +2082,30 @@ do
20792082
20802083 assert (start.context.name == " ^" );
20812084
2082- string newText = " \" " ;
20832085 ParamToken[] paramTokens;
20842086 if (name in paramMap)
20852087 paramTokens = paramMap[name].tokens;
2086- foreach (i, t2; paramTokens)
2087- {
2088- if (i && t2.t.start > paramTokens[i - 1 ].t.end)
2089- {
2090- newText ~= " " ;
2091- }
2092- newText ~= t2.t.content.escapeD;
2093- }
2094- newText ~= " \" " ;
2095-
2096- Tree newToken = Tree(newText, SymbolID.max, ProductionID.max, NodeType.token, []);
20972088
20982089 assert (token.start.context.filename == start.context.filename);
20992090 auto locationContextX0 = context.getLocationContext(immutable (LocationContext)(start.context,
2100- token.start.loc, token.inputLength, " #" , start.context.filename));
2091+ token.start.loc, token.inputLength, " #" , " " ));
2092+
2093+ Tuple ! (Tree, Location)[] mappedTokens;
2094+ if (name in paramMap)
2095+ mappedTokens = mapParams(Location(LocationN.init, locationContextX0), token.childs[2 ], paramMap, context,
2096+ funcMacroLocation, condition);
21012097
21022098 Tree firstChild = Tree(token.childs[0 ].content, SymbolID.max,
21032099 ProductionID.max, NodeType.token, []);
21042100 firstChild.setStartEnd(start,
21052101 start + LocationN.LocationDiff.fromStr(token.childs[0 ].content));
21062102 Tree[] newChilds;
2107- foreach (i, t2; paramTokens)
2108- newChilds ~= t2.t;
2103+ foreach (i, t2; mappedTokens)
2104+ {
2105+ Tree token2 = Tree(t2[0 ].content, SymbolID.max, ProductionID.max, NodeType.token, []);
2106+ token2.setStartEnd(t2[1 ], t2[1 ] + t2[0 ].inputLength);
2107+ newChilds ~= token2;
2108+ }
21092109 Tree arr = createArrayTree(newChilds);
21102110 auto grammarInfo = getDummyGrammarInfo(" ParamExpansion" );
21112111 Tree sourceTokens = Tree(" ParamExpansion" , grammarInfo.startNonterminalID,
@@ -2116,25 +2116,24 @@ do
21162116 context.locationContextInfoMap.getLocationContextInfo(locationContextX0)
21172117 .condition = condition;
21182118
2119- auto locationContextX1 = context.getLocationContext(immutable (LocationContext)(locationContextX0,
2120- start.loc, token.inputLength, start.context.prev.name ~ " ." ~ name, " " ));
2121- auto locationContextX = context.getLocationContext(
2122- immutable (LocationContext)(locationContextX1, LocationN.init,
2123- LocationN.LocationDiff.init, " ^" , funcMacroLocation.context.filename));
2124-
2125- context.locationContextInfoMap.getLocationContextInfo(locationContextX)
2126- .condition = condition;
2127-
2128- LocationN start2, end2;
2129- if (name in paramMap && paramMap[name].tokens.length)
2119+ LocationX lastEnd;
2120+ string newText = " \" " ;
2121+ foreach (i, t2; mappedTokens)
21302122 {
2131- start2 = paramMap[name].tokens[0 ].t.start.loc;
2132- end2 = paramMap[name].tokens[$ - 1 ].t.end.loc;
2123+ if (i && t2[1 ] > lastEnd)
2124+ {
2125+ newText ~= " " ;
2126+ }
2127+ newText ~= t2[0 ].content.escapeD;
2128+ lastEnd = LocationX(t2[0 ].end.loc, t2[1 ].context);
21332129 }
2130+ newText ~= " \" " ;
2131+
2132+ Tree newToken = Tree(newText, SymbolID.max, ProductionID.max, NodeType.token, []);
21342133
2135- newToken.setStartEnd(LocationX(start2, locationContextX ),
2136- LocationX(end2, locationContextX ));
2137- processDirectToken(LocationX(start2, locationContextX ), newToken,
2134+ newToken.setStartEnd(Location(LocationN.init, locationContextX0 ),
2135+ Location(LocationN.init + Location.LocationDiff.fromStr(newText), locationContextX0 ));
2136+ processDirectToken(Location(LocationN.init, locationContextX0 ), newToken,
21382137 context, parallelParser, condition, macrosDone, false , parentParser);
21392138 }
21402139 else if (token.name == " ParamConcat" )
0 commit comments