@@ -1775,48 +1775,57 @@ void parseTreeToDCode(T)(ref CodeWriter code, DWriterData data, T tree, immutabl
17751775 {
17761776 auto codeWrapper = ConditionalCodeWrapper(condition, data);
17771777
1778+ immutable (Formula)* conditionIsArray = semantic.logicSystem.false_;
17781779 foreach (combination; iterateCombinations())
17791780 {
17801781 IteratePPVersions ppVersion = IteratePPVersions(combination,
1781- semantic.logicSystem, condition);
1782- Appender! string app;
1782+ semantic.logicSystem, condition, null , semantic.mergedTreeDatas);
17831783
17841784 auto t = chooseType(semantic.extraInfo(tree.childs[0 ]).type, ppVersion, true );
17851785
17861786 if (t.kind == TypeKind.array)
1787- app.put(" [0]" );
1787+ conditionIsArray = semantic.logicSystem.or(conditionIsArray, ppVersion.condition);
1788+ }
1789+
1790+ bool shouldDescent (Tree tree)
1791+ {
1792+ return tree.nonterminalID == nonterminalIDFor! " SimpleTemplateId" ;
1793+ }
17881794
1789- app.put( " . " );
1795+ codeWrapper.checkTree(tree.childs, false , &shouldDescent );
17901796
1791- void buildSuffix (Tree tree, ref IteratePPVersions ppVersion)
1797+ void onTree (Tree tree, immutable (Formula)* condition2)
1798+ {
1799+ if (tree.nonterminalID == nonterminalIDFor! " SimpleTemplateId" )
17921800 {
1793- if (tree.nodeType == NodeType.token)
1794- {
1795- if (tree.content.length)
1796- {
1797- app.put(replaceKeywords(tree.content));
1798- }
1799- }
1800- else
1801- {
1802- foreach (c; tree.childs)
1803- iteratePPVersions! buildSuffix(c, ppVersion);
1804- }
1801+ codeWrapper.writeTree(code, &onTree, tree.childs[0 ], condition2);
1802+ codeWrapper.writeCode(code, " !(" , condition2);
1803+ skipToken(code, data, tree.childs[1 ]);
1804+ codeWrapper.writeTree(code, &onTree, tree.childs[2 ], condition2);
1805+ codeWrapper.writeCode(code, " )" , condition2);
1806+ skipToken(code, data, tree.childs[3 ]);
1807+ return ;
1808+ }
1809+ parseTreeToDCode(code, data, tree, condition2, currentScope);
1810+ if (tree.location.context ! is null )
1811+ {
1812+ writeComments(code, data, data.sourceTokenManager.collectTokens(tree.location.end));
1813+ writeComments(code, data,
1814+ data.sourceTokenManager.collectTokensUntilLineEnd(tree.location.end,
1815+ condition2));
18051816 }
1806-
1807- foreach (c; tree.childs[2 .. $])
1808- iteratePPVersions! buildSuffix(c, ppVersion);
1809-
1810- codeWrapper.add(" " , app.data, ppVersion.condition);
18111817 }
18121818
18131819 codeWrapper.begin(code, condition);
1814- parseTreeToDCode(code, data, tree.childs[0 ], condition, currentScope);
1815- if (data.sourceTokenManager.tokensLeft.data.length > 0 )
1816- writeComments(code, data, tree.childs[1 ].start);
1820+
1821+ codeWrapper.writeTree(code, &onTree, tree.childs[0 ]);
1822+ if (! conditionIsArray.isFalse)
1823+ codeWrapper.writeString(code, " [0]" , conditionIsArray);
1824+ skipToken(code, data, tree.childs[1 ]);
1825+ codeWrapper.writeCode(code, " ." );
1826+ foreach (c; tree.childs[2 .. $])
1827+ codeWrapper.writeTree(code, &onTree, c);
18171828 codeWrapper.end(code, condition);
1818- if (data.sourceTokenManager.tokensLeft.data.length > 0 )
1819- writeComments(code, data, tree.end, true );
18201829 }
18211830 else if (auto match = tree.matchTreePattern! q{
18221831 Designator(" ." , * )
@@ -2080,7 +2089,18 @@ void parseTreeToDCode(T)(ref CodeWriter code, DWriterData data, T tree, immutabl
20802089 }
20812090 else
20822091 {
2083- string name = declarationNameToCode(e.data, data, contextScope, newCondition);
2092+ string name;
2093+ size_t indexInParentExpr = indexInParent;
2094+ Tree parentExpr = parent;
2095+ while (parentExpr.nonterminalID == nonterminalIDFor! " SimpleTemplateId" )
2096+ parentExpr = getRealParent(parentExpr, semantic, &indexInParentExpr);
2097+ if (parentExpr.nonterminalID == nonterminalIDFor! " PostfixExpression"
2098+ && parentExpr.childs[1 ].nodeType == NodeType.token
2099+ && parentExpr.childs[1 ].content.among(" ." , " ->" )
2100+ && indexInParentExpr == parentExpr.childs.length - 1 )
2101+ name = chooseDeclarationName(e.data, data);
2102+ else
2103+ name = declarationNameToCode(e.data, data, contextScope, newCondition);
20842104 if (e.data ! in data.fileByDecl && realId.conditionAll ! is null )
20852105 newCondition = logicSystem.and(newCondition, realId.conditionAll.negated);
20862106 realId.addReplace(newCondition, name, logicSystem);
0 commit comments