dparse.astprinter 0/593(0%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
940
950
960
970
980
990
1000
1010
1020
1030
1040
1050
1060
1070
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1230
1240
1250
1260
1270
1280
1290
1300
1310
1320
1330
1340
1350
1360
1370
1380
1390
1400
1410
1420
1430
1440
1450
1460
1470
1480
1490
1500
1510
1520
1530
1540
1550
1560
1570
1580
1590
1600
1610
1620
1630
1640
1650
1660
1670
1680
1690
1700
1710
1720
1730
1740
1750
1760
1770
1780
1790
1800
1810
1820
1830
1840
1850
1860
1870
1880
1890
1900
1910
1920
1930
1940
1950
1960
1970
1980
1990
2000
2010
2020
2030
2040
2050
2060
2070
2080
2090
2100
2110
2120
2130
2140
2150
2160
2170
2180
2190
2200
2210
2220
2230
2240
2250
2260
2270
2280
2290
2300
2310
2320
2330
2340
2350
2360
2370
2380
2390
2400
2410
2420
2430
2440
2450
2460
2470
2480
2490
2500
2510
2520
2530
2540
2550
2560
2570
2580
2590
2600
2610
2620
2630
2640
2650
2660
2670
2680
2690
2700
2710
2720
2730
2740
2750
2760
2770
2780
2790
2800
2810
2820
2830
2840
2850
2860
2870
2880
2890
2900
2910
2920
2930
2940
2950
2960
2970
2980
2990
3000
3010
3020
3030
3040
3050
3060
3070
3080
3090
3100
3110
3120
3130
3140
3150
3160
3170
3180
3190
3200
3210
3220
3230
3240
3250
3260
3270
3280
3290
3300
3310
3320
3330
3340
3350
3360
3370
3380
3390
3400
3410
3420
3430
3440
3450
3460
3470
3480
3490
3500
3510
3520
3530
3540
3550
3560
3570
3580
3590
3600
3610
3620
3630
3640
3650
3660
3670
3680
3690
3700
3710
3720
3730
3740
3750
3760
3770
3780
3790
3800
3810
3820
3830
3840
3850
3860
3870
3880
3890
3900
3910
3920
3930
3940
3950
3960
3970
3980
3990
4000
4010
4020
4030
4040
4050
4060
4070
4080
4090
4100
4110
4120
4130
4140
4150
4160
4170
4180
4190
4200
4210
4220
4230
4240
4250
4260
4270
4280
4290
4300
4310
4320
4330
4340
4350
4360
4370
4380
4390
4400
4410
4420
4430
4440
4450
4460
4470
4480
4490
4500
4510
4520
4530
4540
4550
4560
4570
4580
4590
4600
4610
4620
4630
4640
4650
4660
4670
4680
4690
4700
4710
4720
4730
4740
4750
4760
4770
4780
4790
4800
4810
4820
4830
4840
4850
4860
4870
4880
4890
4900
4910
4920
4930
4940
4950
4960
4970
4980
4990
5000
5010
5020
5030
5040
5050
5060
5070
5080
5090
5100
5110
5120
5130
5140
5150
5160
5170
5180
5190
5200
5210
5220
5230
5240
5250
5260
5270
5280
5290
5300
5310
5320
5330
5340
5350
5360
5370
5380
5390
5400
5410
5420
5430
5440
5450
5460
5470
5480
5490
5500
5510
5520
5530
5540
5550
5560
5570
5580
5590
5600
5610
5620
5630
5640
5650
5660
5670
5680
5690
5700
5710
5720
5730
5740
5750
5760
5770
5780
5790
5800
5810
5820
5830
5840
5850
5860
5870
5880
5890
5900
5910
5920
5930
5940
5950
5960
5970
5980
5990
6000
6010
6020
6030
6040
6050
6060
6070
6080
6090
6100
6110
6120
6130
6140
6150
6160
6170
6180
6190
6200
6210
6220
6230
6240
6250
6260
6270
6280
6290
6300
6310
6320
6330
6340
6350
6360
6370
6380
6390
6400
6410
6420
6430
6440
6450
6460
6470
6480
6490
6500
6510
6520
6530
6540
6550
6560
6570
6580
6590
6600
6610
6620
6630
6640
6650
6660
6670
6680
6690
6700
6710
6720
6730
6740
6750
6760
6770
6780
6790
6800
6810
6820
6830
6840
6850
6860
6870
6880
6890
6900
6910
6920
6930
6940
6950
6960
6970
6980
6990
7000
7010
7020
7030
7040
7050
7060
7070
7080
7090
7100
7110
7120
7130
7140
7150
7160
7170
7180
7190
7200
7210
7220
7230
7240
7250
7260
7270
7280
7290
7300
7310
7320
7330
7340
7350
7360
7370
7380
7390
7400
7410
7420
7430
7440
7450
7460
7470
7480
7490
7500
7510
7520
7530
7540
7550
7560
7570
7580
7590
7600
7610
7620
7630
7640
7650
7660
7670
7680
7690
7700
7710
7720
7730
7740
7750
7760
7770
7780
7790
7800
7810
7820
7830
7840
7850
7860
7870
7880
7890
7900
7910
7920
7930
7940
7950
7960
7970
7980
7990
8000
8010
8020
8030
8040
8050
8060
8070
8080
8090
8100
8110
8120
8130
8140
8150
8160
8170
8180
8190
8200
8210
8220
8230
8240
8250
8260
8270
8280
8290
8300
8310
8320
8330
8340
8350
8360
8370
8380
8390
8400
8410
8420
8430
8440
8450
8460
8470
8480
8490
8500
8510
8520
8530
8540
8550
8560
8570
8580
8590
8600
8610
8620
8630
8640
8650
8660
8670
8680
8690
8700
8710
8720
8730
8740
8750
8760
8770
8780
8790
8800
8810
8820
8830
8840
8850
8860
8870
8880
8890
8900
8910
8920
8930
8940
8950
8960
8970
8980
8990
9000
9010
9020
9030
9040
9050
9060
9070
9080
9090
9100
9110
9120
9130
9140
9150
9160
9170
9180
9190
9200
9210
9220
9230
9240
9250
9260
9270
9280
9290
9300
9310
9320
9330
9340
9350
9360
9370
9380
9390
9400
9410
9420
9430
9440
9450
9460
9470
9480
9490
9500
9510
9520
9530
9540
9550
9560
9570
9580
9590
9600
9610
9620
9630
9640
9650
9660
9670
9680
9690
9700
9710
9720
9730
9740
9750
9760
9770
9780
9790
9800
9810
9820
9830
9840
9850
9860
9870
9880
9890
9900
9910
9920
9930
9940
9950
9960
9970
9980
9990
10000
10010
10020
10030
10040
10050
10060
10070
10080
10090
10100
10110
10120
10130
10140
10150
10160
10170
10180
10190
10200
10210
10220
10230
10240
10250
10260
10270
10280
10290
10300
10310
10320
10330
10340
10350
10360
10370
10380
10390
10400
10410
10420
10430
10440
10450
10460
10470
10480
10490
10500
10510
10520
10530
10540
10550
10560
10570
10580
10590
10600
10610
10620
10630
10640
10650
10660
10670
10680
10690
10700
10710
10720
10730
10740
10750
10760
10770
10780
10790
10800
10810
10820
10830
10840
10850
10860
10870
10880
10890
10900
10910
10920
10930
10940
10950
10960
10970
10980
10990
11000
11010
11020
11030
11040
11050
11060
11070
11080
11090
11100
11110
11120
11130
11140
11150
11160
11170
11180
11190
11200
11210
11220
11230
11240
11250
11260
11270
11280
11290
11300
11310
11320
11330
11340
11350
11360
11370
11380
11390
11400
11410
11420
11430
11440
11450
11460
11470
11480
11490
11500
11510
11520
11530
11540
11550
11560
11570
11580
11590
11600
11610
11620
11630
11640
11650
11660
11670
11680
11690
11700
11710
11720
11730
11740
11750
11760
11770
11780
11790
11800
11810
11820
11830
11840
11850
11860
11870
11880
11890
11900
11910
11920
11930
11940
11950
11960
11970
11980
11990
// Copyright Brian Schott (Hackerpilot) 2012. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) module dparse.astprinter; import std.array; import std.stdio; import std.string; import dparse.ast; import dparse.formatter; import dparse.lexer; /** * AST visitor that outputs an XML representation of the AST to its file. */ class XMLPrinter : ASTVisitor { override void visit(const AddExpression addExpression) { output.writeln("<addExpression operator=\"", str(addExpression.operator), "\">"); output.writeln("<left>"); visit(addExpression.left); output.writeln("</left>"); if (addExpression.right !is null) { output.writeln("<right>"); visit(addExpression.right); output.writeln("</right>"); } output.writeln("</addExpression>"); } override void visit(const AliasDeclaration aliasDeclaration) { output.writeln("<aliasDeclaration>"); writeDdoc(aliasDeclaration.comment); aliasDeclaration.accept(this); output.writeln("</aliasDeclaration>"); } override void visit(const AlignAttribute alignAttribute) { if (alignAttribute.assignExpression is null) output.writeln("<alignAttribute/>"); else { output.write("<alignAttribute align=\""); format(output.lockingTextWriter, alignAttribute.assignExpression); output.writeln("\"/>"); } } override void visit(const AndAndExpression andAndExpression) { output.writeln("<andAndExpression>"); output.writeln("<left>"); visit(andAndExpression.left); output.writeln("</left>"); if (andAndExpression.right !is null) { output.writeln("<right>"); visit(andAndExpression.right); output.writeln("</right>"); } output.writeln("</andAndExpression>"); } override void visit(const AndExpression andExpression) { output.writeln("<andExpression>"); output.writeln("<left>"); visit(andExpression.left); output.writeln("</left>"); if (andExpression.right !is null) { output.writeln("<right>"); visit(andExpression.right); output.writeln("</right>"); } output.writeln("</andExpression>"); } override void visit(const AsmInstruction asmInstruction) { output.writeln("<asmInstruction>"); if (asmInstruction.hasAlign) { output.writeln("<align>"); visit(asmInstruction.identifierOrIntegerOrOpcode); output.writeln("</align>"); } if (asmInstruction.asmInstruction !is null) { output.writeln("<label label=\"", asmInstruction.identifierOrIntegerOrOpcode.text, "\"/>"); asmInstruction.asmInstruction.accept(this); } else if (asmInstruction.identifierOrIntegerOrOpcode != tok!"") visit(asmInstruction.identifierOrIntegerOrOpcode); if (asmInstruction.operands !is null) { visit(asmInstruction.operands); } output.writeln("</asmInstruction>"); } override void visit(const AssignExpression assignExpression) { if (assignExpression.expression is null) output.writeln("<expression>"); else output.writeln("<expression operator=\"", xmlAttributeEscape(str(assignExpression.operator)), "\">"); assignExpression.accept(this); output.writeln("</expression>"); } override void visit(const AtAttribute atAttribute) { output.writeln("<atAttribute>"); if (atAttribute.identifier.type != tok!"") output.writeln("<identifier>", atAttribute.identifier.text, "</identifier>"); atAttribute.accept(this); output.writeln("</atAttribute>"); } override void visit(const Attribute attribute) { if (attribute.attribute == tok!"") { output.writeln("<attribute>"); attribute.accept(this); output.writeln("</attribute>"); } else if (attribute.identifierChain is null) output.writeln("<attribute attribute=\"", str(attribute.attribute.type), "\"/>"); else { output.writeln("<attribute attribute=\"", str(attribute.attribute.type), "\">"); visit(attribute.identifierChain); output.writeln("</attribute>"); } } override void visit(const AutoDeclaration autoDec) { output.writeln("<autoDeclaration>"); output.writeln("<storageClasses>"); foreach (sc; autoDec.storageClasses) visit(sc); output.writeln("</storageClasses>"); foreach (part; autoDec.parts) visit(part); output.writeln("</autoDeclaration>"); } override void visit(const AutoDeclarationPart part) { output.writeln("<autoDeclarationPart>"); output.writeln("<item>"); output.writeln("<name line=\"", part.identifier.line, "\">", part.identifier.text, "</name>"); visit(part.initializer); output.writeln("</item>"); output.writeln("</autoDeclarationPart>"); } override void visit(const BreakStatement breakStatement) { if (breakStatement.label.type == tok!"") output.writeln("<breakStatement/>"); else output.writeln("<breakStatement label=\"", breakStatement.label.text, "\"/>"); } override void visit(const CaseRangeStatement caseRangeStatement) { output.writeln("<caseRangeStatement>"); if (caseRangeStatement.low !is null) { output.writeln("<low>"); visit(caseRangeStatement.low); output.writeln("</low>"); } if (caseRangeStatement.high !is null) { output.writeln("<high>"); visit(caseRangeStatement.high); output.writeln("</high>"); } if (caseRangeStatement.declarationsAndStatements !is null) visit(caseRangeStatement.declarationsAndStatements); output.writeln("</caseRangeStatement>"); } override void visit(const Catch catch_) { output.writeln("<catch>"); catch_.accept(this); output.writeln("</catch>"); } override void visit(const ClassDeclaration classDec) { output.writeln("<classDeclaration line=\"", classDec.name.line, "\">"); writeName(classDec.name.text); writeDdoc(classDec.comment); classDec.accept(this); output.writeln("</classDeclaration>"); } override void visit(const ConditionalDeclaration conditionalDeclaration) { output.writeln("<conditionalDeclaration>"); visit(conditionalDeclaration.compileCondition); output.writeln("<trueDeclarations style=\"", conditionalDeclaration.trueStyle, "\">"); foreach (dec; conditionalDeclaration.trueDeclarations) visit(dec); output.writeln("</trueDeclarations>"); if (conditionalDeclaration.falseDeclarations.length > 0) { output.writeln("<falseDeclarations style=\"", conditionalDeclaration.trueStyle, "\">"); foreach (dec; conditionalDeclaration.falseDeclarations) visit(dec); output.writeln("</falseDeclarations>"); } output.writeln("</conditionalDeclaration>"); } override void visit(const ConditionalStatement conditionalStatement) { output.writeln("<conditionalStatement>"); visit(conditionalStatement.compileCondition); output.writeln("<trueStatement>"); visit(conditionalStatement.trueStatement); output.writeln("</trueStatement>"); if (conditionalStatement.falseStatement !is null) { output.writeln("<falseStatement>"); visit(conditionalStatement.falseStatement); output.writeln("</falseStatement>"); } output.writeln("</conditionalStatement>"); } override void visit(const ContinueStatement continueStatement) { if (continueStatement.label.type == tok!"") output.writeln("<continueStatement/>"); else output.writeln("<continueStatement label=\"", continueStatement.label.text, "\"/>"); } override void visit(const DebugCondition debugCondition) { if (debugCondition.identifierOrInteger.type == tok!"") output.writeln("<debugCondition/>"); else output.writeln("<debugCondition condition=\"", debugCondition.identifierOrInteger.text, "\"/>"); } override void visit(const DebugSpecification debugSpecification) { if (debugSpecification.identifierOrInteger.type == tok!"") output.writeln("<debugSpecification/>"); else output.writeln("<debugSpecification condition=\"", debugSpecification.identifierOrInteger.text, "\"/>"); } override void visit(const Declarator declarator) { output.writeln("<declarator line=\"", declarator.name.line, "\">"); writeName(declarator.name.text); writeDdoc(declarator.comment); declarator.accept(this); output.writeln("</declarator>"); } override void visit(const Deprecated deprecated_) { if (deprecated_.assignExpression !is null) { output.writeln("<deprecated>"); visit(deprecated_.assignExpression); output.writeln("</deprecated>"); } else output.writeln("<deprecated/>"); } override void visit(const EnumDeclaration enumDec) { output.writeln("<enumDeclaration line=\"", enumDec.name.line, "\">"); writeDdoc(enumDec.comment); if (enumDec.name.type == tok!"identifier") writeName(enumDec.name.text); enumDec.accept(this); output.writeln("</enumDeclaration>"); } override void visit(const AnonymousEnumMember enumMember) { output.writeln("<anonymousEnumMember line=\"", enumMember.name.line, "\">"); writeDdoc(enumMember.comment); if (enumMember.type !is null) visit(enumMember.type); output.write("<name>", enumMember.name.text, "</name>"); if (enumMember.assignExpression !is null) visit(enumMember.assignExpression); output.writeln("</anonymousEnumMember>"); } override void visit(const EnumMember enumMem) { output.writeln("<enumMember line=\"", enumMem.name.line, "\">"); writeDdoc(enumMem.comment); enumMem.accept(this); output.writeln("</enumMember>"); } override void visit(const EqualExpression equalExpression) { output.writeln("<equalExpression operator=\"", str(equalExpression.operator), "\">"); output.writeln("<left>"); visit(equalExpression.left); output.writeln("</left>"); output.writeln("<right>"); visit(equalExpression.right); output.writeln("</right>"); output.writeln("</equalExpression>"); } override void visit(const Finally finally_) { output.writeln("<finally>"); finally_.accept(this); output.writeln("</finally>"); } override void visit(const ForStatement forStatement) { output.writeln("<forStatement>"); if (forStatement.initialization !is null) { output.writeln("<initialization>"); visit(forStatement.initialization); output.writeln("</initialization>"); } if (forStatement.test !is null) { output.writeln("<test>"); visit(forStatement.test); output.writeln("</test>"); } if (forStatement.increment !is null) { output.writeln("<increment>"); visit(forStatement.increment); output.writeln("</increment>"); } if (forStatement.declarationOrStatement !is null) visit(forStatement.declarationOrStatement); output.writeln("</forStatement>"); } override void visit(const ForeachStatement foreachStatement) { output.writeln("<foreachStatement type=\"", str(foreachStatement.type), "\">"); if (foreachStatement.foreachType !is null) visit(foreachStatement.foreachType); if (foreachStatement.foreachTypeList !is null) visit(foreachStatement.foreachTypeList); output.writeln("<low>"); visit(foreachStatement.low); output.writeln("</low>"); if (foreachStatement.high !is null) { output.writeln("<high>"); visit(foreachStatement.high); output.writeln("</high>"); } visit(foreachStatement.declarationOrStatement); output.writeln("</foreachStatement>"); } override void visit(const ForeachType foreachType) { output.writeln("<foreachType>"); foreach (constructor; foreachType.typeConstructors) { output.writeln("<typeConstructor>", str(constructor), "</typeConstructor>"); } if (foreachType.type !is null) visit(foreachType.type); visit(foreachType.identifier); output.writeln("</foreachType>"); } override void visit(const FunctionDeclaration functionDec) { output.writeln("<functionDeclaration line=\"", functionDec.name.line, "\">"); writeName(functionDec.name.text); writeDdoc(functionDec.comment); if (functionDec.hasAuto) output.writeln("<auto/>"); if (functionDec.hasRef) output.writeln("<ref/>"); functionDec.accept(this); output.writeln("</functionDeclaration>"); } override void visit(const FunctionLiteralExpression functionLiteralExpression) { output.writeln("<functionLiteralExpression type=\"", functionLiteralExpression.functionOrDelegate != tok!"" ? str(functionLiteralExpression.functionOrDelegate) : "auto", "\">"); functionLiteralExpression.accept(this); output.writeln("</functionLiteralExpression>"); } override void visit(const GotoStatement gotoStatement) { if (gotoStatement.label.type == tok!"default") output.writeln("<gotoStatement default=\"true\"/>"); else if (gotoStatement.label.type == tok!"identifier") output.writeln("<gotoStatement label=\"", gotoStatement.label.text, "\"/>"); else { output.writeln("<gotoStatement>"); output.writeln("<case>"); if (gotoStatement.expression) visit(gotoStatement.expression); output.writeln("</case>"); output.writeln("</gotoStatement>"); } } override void visit(const IdentityExpression identityExpression) { if (identityExpression.negated) output.writeln("<identityExpression operator=\"!is\">"); else output.writeln("<identityExpression operator=\"is\">"); output.writeln("<left>"); visit(identityExpression.left); output.writeln("</left>"); output.writeln("<right>"); visit(identityExpression.right); output.writeln("</right>"); output.writeln("</identityExpression>"); } override void visit(const IfStatement ifStatement) { output.writeln("<ifStatement>"); output.writeln("<condition>"); if (ifStatement.identifier.type != tok!"") { if (ifStatement.type is null) output.writeln("<auto/>"); else visit(ifStatement.type); visit(ifStatement.identifier); } ifStatement.expression.accept(this); output.writeln("</condition>"); output.writeln("<then>"); ifStatement.thenStatement.accept(this); output.writeln("</then>"); if (ifStatement.elseStatement !is null) { output.writeln("<else>"); ifStatement.elseStatement.accept(this); output.writeln("</else>"); } output.writeln("</ifStatement>"); } override void visit(const ImportBind importBind) { if (importBind.right.type == tok!"") output.writeln("<importBind symbol=\"", importBind.left.text, "\"/>"); else output.writeln("<importBind symbol=\"", importBind.right.text, "\" rename=\"", importBind.left.text, "\"/>"); } override void visit(const InExpression inExpression) { if (inExpression.negated) output.writeln("<inExpression operator=\"!in\">"); else output.writeln("<inExpression operator=\"in\">"); output.writeln("<left>"); visit(inExpression.left); output.writeln("</left>"); output.writeln("<right>"); visit(inExpression.right); output.writeln("</right>"); output.writeln("</inExpression>"); } override void visit(const Initialize initialize) { if (initialize.statementNoCaseNoDefault is null) output.writeln("<initialize/>"); else { output.writeln("<initialize>"); visit(initialize.statementNoCaseNoDefault); output.writeln("</initialize>"); } } override void visit(const Initializer initializer) { if (initializer.nonVoidInitializer is null) output.writeln("<initializer void=\"true\"/>"); else { output.writeln("<initializer>"); visit(initializer.nonVoidInitializer); output.writeln("</initializer>"); } } override void visit(const InterfaceDeclaration interfaceDec) { output.writeln("<interfaceDeclaration line=\"", interfaceDec.name.line, "\">"); writeName(interfaceDec.name.text); writeDdoc(interfaceDec.comment); interfaceDec.accept(this); output.writeln("</interfaceDeclaration>"); } override void visit(const Invariant invariant_) { output.writeln("<invariant>"); writeDdoc(invariant_.comment); invariant_.accept(this); output.writeln("</invariant>"); } override void visit(const IsExpression isExpression) { output.writeln("<isExpression>"); visit(isExpression.type); if (isExpression.identifier.type != tok!"") visit(isExpression.identifier); if (isExpression.typeSpecialization !is null) { if (isExpression.equalsOrColon == tok!":") output.writeln("<colon/>"); else output.writeln("<equals/>"); visit(isExpression.typeSpecialization); if (isExpression.templateParameterList !is null) visit(isExpression.templateParameterList); } output.writeln("</isExpression>"); } override void visit(const KeyValuePair keyValuePair) { output.writeln("<keyValuePair>"); output.writeln("<key>"); visit(keyValuePair.key); output.writeln("</key>"); output.writeln("<value>"); visit(keyValuePair.value); output.writeln("</value>"); output.writeln("</keyValuePair>"); } override void visit(const LabeledStatement labeledStatement) { output.writeln("<labeledStatement label=\"", labeledStatement.identifier.text, "\">"); if (labeledStatement.declarationOrStatement !is null) visit(labeledStatement.declarationOrStatement); output.writeln("</labeledStatement>"); } override void visit(const LinkageAttribute linkageAttribute) { if (linkageAttribute.hasPlusPlus) { output.write("<linkageAttribute linkage=\"C++\""); if (linkageAttribute.typeIdentifierPart !is null && linkageAttribute.typeIdentifierPart.typeIdentifierPart !is null) { output.write(" namespace=\""); format(output.lockingTextWriter, linkageAttribute.typeIdentifierPart); output.writeln("\"/>"); } else if (linkageAttribute.classOrStruct == tok!"class") output.writeln(" mangleAs=\"class\"/>"); else if (linkageAttribute.classOrStruct == tok!"struct") output.writeln(" mangleAs=\"struct\"/>"); else output.writeln("/>"); } else if (linkageAttribute.identifier.text == "Objective") output.writeln("<linkageAttribute linkage=\"Objective-C\"/>"); else output.writeln("<linkageAttribute linkage=\"", linkageAttribute.identifier.text, "\"/>"); } override void visit(const MemberFunctionAttribute memberFunctionAttribute) { output.writeln("<memberFunctionAttribute>"); if (memberFunctionAttribute.atAttribute is null) output.writeln(str(memberFunctionAttribute.tokenType)); else memberFunctionAttribute.accept(this); output.writeln("</memberFunctionAttribute>"); } override void visit(const Module module_) { output.writeln("<?xml version=\"1.0\"?>"); output.writeln("<module>"); module_.accept(this); output.writeln("</module>"); } override void visit(const MulExpression mulExpression) { output.writeln("<mulExpression operator=\"", str(mulExpression.operator), "\">"); output.writeln("<left>"); visit(mulExpression.left); output.writeln("</left>"); if (mulExpression.right !is null) { output.writeln("<right>"); visit(mulExpression.right); output.writeln("</right>"); } output.writeln("</mulExpression>"); } override void visit(const OrOrExpression orOrExpression) { output.writeln("<orOrExpression>"); output.writeln("<left>"); visit(orOrExpression.left); output.writeln("</left>"); if (orOrExpression.right !is null) { output.writeln("<right>"); visit(orOrExpression.right); output.writeln("</right>"); } output.writeln("</orOrExpression>"); } override void visit(const ParameterAttribute pa) { output.writeln("<parameterAttribute>"); if (pa.atAttribute) visit(pa.atAttribute); else writeln(str(pa.idType)); output.writeln("</parameterAttribute>"); } override void visit(const Parameter param) { output.writeln("<parameter>"); if (param.name.type == tok!"identifier") writeName(param.name.text); param.accept(this); if (param.vararg) output.writeln("<vararg/>"); output.writeln("</parameter>"); } override void visit(const PowExpression powExpression) { output.writeln("<powExpression>"); output.writeln("<left>"); visit(powExpression.left); output.writeln("</left>"); if (powExpression.right !is null) { output.writeln("<right>"); visit(powExpression.right); output.writeln("</right>"); } output.writeln("</powExpression>"); } override void visit(const RelExpression relExpression) { output.writeln("<relExpression operator=\"", xmlAttributeEscape(str(relExpression.operator)), "\">"); output.writeln("<left>"); visit(relExpression.left); output.writeln("</left>"); output.writeln("<right>"); visit(relExpression.right); output.writeln("</right>"); output.writeln("</relExpression>"); } override void visit(const ReturnStatement returnStatement) { if (returnStatement.expression is null) output.writeln("<returnStatement/>"); else { output.writeln("<returnStatement>"); returnStatement.accept(this); output.writeln("</returnStatement>"); } } override void visit(const ShiftExpression shiftExpression) { output.writeln("<shiftExpression operator=\"", xmlAttributeEscape(str(shiftExpression.operator)), "\">"); output.writeln("<left>"); visit(shiftExpression.left); output.writeln("</left>"); output.writeln("<right>"); visit(shiftExpression.right); output.writeln("</right>"); output.writeln("</shiftExpression>"); } override void visit(const SingleImport singleImport) { if (singleImport.rename.type == tok!"") output.writeln("<singleImport>"); else output.writeln("<singleImport rename=\"", singleImport.rename.text, "\">"); visit(singleImport.identifierChain); output.writeln("</singleImport>"); } override void visit(const StructDeclaration structDec) { output.writeln("<structDeclaration line=\"", structDec.name.line, "\">"); writeName(structDec.name.text); writeDdoc(structDec.comment); structDec.accept(this); output.writeln("</structDeclaration>"); } override void visit(const TemplateAliasParameter templateAliasParameter) { output.writeln("<templateAliasParameter>"); if (templateAliasParameter.type !is null) visit(templateAliasParameter.type); visit(templateAliasParameter.identifier); if (templateAliasParameter.colonExpression !is null) { output.writeln("<specialization>"); visit(templateAliasParameter.colonExpression); output.writeln("</specialization>"); } else if (templateAliasParameter.colonType !is null) { output.writeln("<specialization>"); visit(templateAliasParameter.colonType); output.writeln("</specialization>"); } if (templateAliasParameter.assignExpression !is null) { output.writeln("<default>"); visit(templateAliasParameter.assignExpression); output.writeln("</default>"); } else if (templateAliasParameter.assignType !is null) { output.writeln("<default>"); visit(templateAliasParameter.assignType); output.writeln("</default>"); } output.writeln("</templateAliasParameter>"); } override void visit(const TemplateDeclaration templateDeclaration) { writeDdoc(templateDeclaration.comment); output.writeln("<templateDeclaration line=\"", templateDeclaration.name.line, "\">"); writeName(templateDeclaration.name.text); visit(templateDeclaration.templateParameters); if (templateDeclaration.constraint !is null) visit(templateDeclaration.constraint); foreach (dec; templateDeclaration.declarations) { if (dec !is null) visit(dec); } output.writeln("</templateDeclaration>"); } override void visit(const Token token) { string tagName; switch (token.type) { case tok!"": return; case tok!"identifier": tagName = "identifier"; break; case tok!"doubleLiteral": tagName = "doubleLiteral"; break; case tok!"idoubleLiteral": tagName = "idoubleLiteral"; break; case tok!"floatLiteral": tagName = "floatLiteral"; break; case tok!"ifloatLiteral": tagName = "ifloatLiteral"; break; case tok!"intLiteral": tagName = "intLiteral"; break; case tok!"uintLiteral": tagName = "uintLiteral"; break; case tok!"longLiteral": tagName = "longLiteral"; break; case tok!"ulongLiteral": tagName = "ulongLiteral"; break; case tok!"realLiteral": tagName = "realLiteral"; break; case tok!"irealLiteral": tagName = "irealLiteral"; break; case tok!"characterLiteral": tagName = "characterLiteral"; break; case tok!"stringLiteral": tagName = "stringLiteral"; break; case tok!"dstringLiteral": tagName = "dstringLiteral"; break; case tok!"wstringLiteral": tagName = "wstringLiteral"; break; case tok!"scriptLine": tagName = "scriptLine"; break; case tok!"$": output.writeln("<dollar/>"); return; case tok!".": output.writeln("<dot/>"); return; default: output.writeln("<", str(token.type), "/>"); return; } output.writeln("<", tagName, ">", xmlEscape(token.text), "</", tagName, ">"); } override void visit(const Type type) { auto app = appender!string(); auto formatter = new Formatter!(typeof(app))(app); formatter.format(type); output.writeln("<type pretty=\"", xmlAttributeEscape(app.data), "\">"); type.accept(this); output.writeln("</type>"); } override void visit(const Type2 type2) { if (type2.builtinType != tok!"") { output.writeln("<type2>", str(type2.builtinType), "</type2>"); if (type2.typeIdentifierPart !is null) visit(type2.typeIdentifierPart); } else { output.writeln("<type2>"); type2.accept(this); output.writeln("</type2>"); } } override void visit(const TypeSuffix typeSuffix) { if (typeSuffix.star != tok!"") output.writeln("<typeSuffix type=\"*\"/>"); else if (typeSuffix.array) { if (typeSuffix.low is null && typeSuffix.type is null) output.writeln("<typeSuffix type=\"[]\"/>"); else { if (typeSuffix.low is null) { output.writeln("<typeSuffix type=\"[]\">"); visit(typeSuffix.type); output.writeln("</typeSuffix>"); } else { output.writeln("<typeSuffix type=\"[]\">"); if (typeSuffix.high !is null) { output.writeln("<low>"); visit(typeSuffix.low); output.writeln("</low>"); output.writeln("<high>"); visit(typeSuffix.high); output.writeln("</high>"); } else visit(typeSuffix.low); output.writeln("</typeSuffix>"); } } } else { visit(typeSuffix.delegateOrFunction); visit(typeSuffix.parameters); foreach (attr; typeSuffix.memberFunctionAttributes) { if (attr !is null) visit(attr); } } } override void visit(const UnaryExpression unaryExpression) { output.writeln("<unaryExpression>"); if (unaryExpression.prefix != tok!"") { output.writeln("<prefix>", xmlEscape(str(unaryExpression.prefix.type)), "</prefix>"); unaryExpression.unaryExpression.accept(this); } else { if (unaryExpression.suffix != tok!"") { assert(unaryExpression.suffix.text == ""); unaryExpression.unaryExpression.accept(this); output.writeln("<suffix>", str(unaryExpression.suffix.type), "</suffix>"); } else unaryExpression.accept(this); } output.writeln("</unaryExpression>"); } override void visit(const UnionDeclaration unionDeclaration) { output.writeln("<unionDeclaration line=\"", unionDeclaration.name.line, "\">"); if (unionDeclaration.name != tok!"") writeName(unionDeclaration.name.text); if (unionDeclaration.templateParameters !is null) visit(unionDeclaration.templateParameters); if (unionDeclaration.constraint !is null) visit(unionDeclaration.constraint); if (unionDeclaration.structBody !is null) visit(unionDeclaration.structBody); output.writeln("</unionDeclaration>"); } override void visit(const Unittest unittest_) { output.writeln("<unittest>"); unittest_.accept(this); output.writeln("</unittest>"); } override void visit(const VariableDeclaration variableDeclaration) { output.writeln("<variableDeclaration>"); writeDdoc(variableDeclaration.comment); variableDeclaration.accept(this); output.writeln("</variableDeclaration>"); } override void visit(const XorExpression xorExpression) { output.writeln("<xorExpression>"); output.writeln("<left>"); visit(xorExpression.left); output.writeln("</left>"); if (xorExpression.right !is null) { output.writeln("<right>"); visit(xorExpression.right); output.writeln("</right>"); } output.writeln("</xorExpression>"); } override void visit(const Index index) { output.writeln("<index>"); if (index.high) { output.writeln("<low>"); visit(index.low); output.writeln("</low>"); output.writeln("<high>"); visit(index.high); output.writeln("</high>"); } else visit(index.low); output.writeln("</index>"); } // dfmt off override void visit(const AliasInitializer aliasInitializer) { mixin (tagAndAccept!"aliasInitializer"); } override void visit(const AliasThisDeclaration aliasThisDeclaration) { mixin (tagAndAccept!"aliasThisDeclaration"); } override void visit(const AnonymousEnumDeclaration anonymousEnumDeclaration) { mixin (tagAndAccept!"anonymousEnumDeclaration"); } override void visit(const ArgumentList argumentList) { mixin (tagAndAccept!"argumentList"); } override void visit(const Arguments arguments) { mixin (tagAndAccept!"arguments"); } override void visit(const ArrayInitializer arrayInitializer) { mixin (tagAndAccept!"arrayInitializer"); } override void visit(const ArrayLiteral arrayLiteral) { mixin (tagAndAccept!"arrayLiteral"); } override void visit(const ArrayMemberInitialization arrayMemberInitialization) { mixin (tagAndAccept!"arrayMemberInitialization"); } override void visit(const AsmAddExp asmAddExp) { mixin (tagAndAccept!"asmAddExp"); } override void visit(const AsmAndExp asmAndExp) { mixin (tagAndAccept!"asmAndExp"); } override void visit(const AsmBrExp asmBrExp) { mixin (tagAndAccept!"asmBrExp"); } override void visit(const AsmEqualExp asmEqualExp) { mixin (tagAndAccept!"asmEqualExp"); } override void visit(const AsmExp asmExp) { mixin (tagAndAccept!"asmExp"); } override void visit(const AsmLogAndExp asmLogAndExp) { mixin (tagAndAccept!"asmLogAndExp"); } override void visit(const AsmLogOrExp asmLogOrExp) { mixin (tagAndAccept!"asmLogOrExp"); } override void visit(const AsmMulExp asmMulExp) { mixin (tagAndAccept!"asmMulExp"); } override void visit(const AsmOrExp asmOrExp) { mixin (tagAndAccept!"asmOrExp"); } override void visit(const AsmPrimaryExp asmPrimaryExp) { mixin (tagAndAccept!"asmPrimaryExp"); } override void visit(const AsmRelExp asmRelExp) { mixin (tagAndAccept!"asmRelExp"); } override void visit(const AsmShiftExp asmShiftExp) { mixin (tagAndAccept!"asmShiftExp"); } override void visit(const AsmStatement asmStatement) { mixin (tagAndAccept!"asmStatement"); } override void visit(const AsmTypePrefix asmTypePrefix) { mixin (tagAndAccept!"asmTypePrefix"); } override void visit(const AsmUnaExp asmUnaExp) { mixin (tagAndAccept!"asmUnaExp"); } override void visit(const AsmXorExp asmXorExp) { mixin (tagAndAccept!"asmXorExp"); } override void visit(const AssocArrayLiteral assocArrayLiteral) { mixin (tagAndAccept!"assocArrayLiteral"); } override void visit(const AssertExpression assertExpression) { mixin (tagAndAccept!"assertExpression"); } override void visit(const AssertArguments assertArguments) { mixin (tagAndAccept!"assertArguments"); } override void visit(const AttributeDeclaration attributeDeclaration) { mixin (tagAndAccept!"attributeDeclaration"); } override void visit(const BaseClass baseClass) { mixin (tagAndAccept!"baseClass"); } override void visit(const BaseClassList baseClassList) { mixin (tagAndAccept!"baseClassList"); } override void visit(const BlockStatement blockStatement) { mixin (tagAndAccept!"blockStatement"); } override void visit(const CaseStatement caseStatement) { mixin (tagAndAccept!"caseStatement"); } override void visit(const CastExpression castExpression) { mixin (tagAndAccept!"castExpression"); } override void visit(const CastQualifier castQualifier) { mixin (tagAndAccept!"castQualifier"); } override void visit(const Catches catches) { mixin (tagAndAccept!"catches"); } override void visit(const CmpExpression cmpExpression) { mixin (tagAndAccept!"cmpExpression"); } override void visit(const CompileCondition compileCondition) { mixin (tagAndAccept!"compileCondition"); } override void visit(const Constraint constraint) { mixin (tagAndAccept!"constraint"); } override void visit(const Constructor constructor) { mixin (tagAndAccept!"constructor"); } override void visit(const Declaration declaration) { mixin (tagAndAccept!"declaration"); } override void visit(const DeclarationOrStatement declarationOrStatement) { mixin (tagAndAccept!"declarationOrStatement"); } override void visit(const DeclarationsAndStatements declarationsAndStatements) { mixin (tagAndAccept!"declarationsAndStatements"); } override void visit(const DeclaratorIdentifierList declaratorIdentifierList) { mixin (tagAndAccept!"declaratorIdentifierList"); } override void visit(const DefaultStatement defaultStatement) { mixin (tagAndAccept!"defaultStatement"); } override void visit(const DeleteExpression deleteExpression) { mixin (tagAndAccept!"deleteExpression"); } override void visit(const DeleteStatement deleteStatement) { mixin (tagAndAccept!"deleteStatement"); } override void visit(const Destructor destructor) { mixin (tagAndAccept!"destructor"); } override void visit(const DoStatement doStatement) { mixin (tagAndAccept!"doStatement"); } override void visit(const EnumBody enumBody) { mixin (tagAndAccept!"enumBody"); } override void visit(const EponymousTemplateDeclaration eponymousTemplateDeclaration) { mixin (tagAndAccept!"eponymousTemplateDeclaration"); } override void visit(const Expression expression) { mixin (tagAndAccept!"expression"); } override void visit(const ExpressionStatement expressionStatement) { mixin (tagAndAccept!"expressionStatement"); } override void visit(const FinalSwitchStatement finalSwitchStatement) { mixin (tagAndAccept!"finalSwitchStatement"); } override void visit(const ForeachTypeList foreachTypeList) { mixin (tagAndAccept!"foreachTypeList"); } override void visit(const FunctionAttribute functionAttribute) { mixin (tagAndAccept!"functionAttribute"); } override void visit(const FunctionBody functionBody) { mixin (tagAndAccept!"functionBody"); } override void visit(const FunctionCallExpression functionCallExpression) { mixin (tagAndAccept!"functionCallExpression"); } override void visit(const IdentifierChain identifierChain) { mixin (tagAndAccept!"identifierChain"); } override void visit(const IdentifierOrTemplateChain identifierOrTemplateChain) { mixin (tagAndAccept!"identifierOrTemplateChain"); } override void visit(const IdentifierOrTemplateInstance identifierOrTemplateInstance) { mixin (tagAndAccept!"identifierOrTemplateInstance"); } override void visit(const ImportBindings importBindings) { mixin (tagAndAccept!"importBindings"); } override void visit(const ImportDeclaration importDeclaration) { mixin (tagAndAccept!"importDeclaration"); } override void visit(const ImportExpression importExpression) { mixin (tagAndAccept!"importExpression"); } override void visit(const IndexExpression indexExpression) { mixin (tagAndAccept!"indexExpression"); } override void visit(const InStatement inStatement) { mixin (tagAndAccept!"inStatement"); } override void visit(const InContractExpression inContractExpression) { mixin (tagAndAccept!"inContractExpression"); } override void visit(const InOutContractExpression inOutContractExpression) { mixin (tagAndAccept!"inOutContractExpression"); } override void visit(const KeyValuePairs keyValuePairs) { mixin (tagAndAccept!"keyValuePairs"); } override void visit(const MixinExpression mixinExpression) { mixin (tagAndAccept!"mixinExpression"); } override void visit(const MixinTemplateDeclaration mixinTemplateDeclaration) { mixin (tagAndAccept!"mixinTemplateDeclaration"); } override void visit(const MixinTemplateName mixinTemplateName) { mixin (tagAndAccept!"mixinTemplateName"); } override void visit(const ModuleDeclaration moduleDeclaration) { mixin (tagAndAccept!"moduleDeclaration"); } override void visit(const LastCatch lastCatch) { mixin (tagAndAccept!"lastCatch"); } override void visit(const NewExpression newExpression) { mixin (tagAndAccept!"newExpression"); } override void visit(const NonVoidInitializer nonVoidInitializer) { mixin (tagAndAccept!"nonVoidInitializer"); } override void visit(const Operands operands) { mixin (tagAndAccept!"operands"); } override void visit(const OrExpression orExpression) { mixin (tagAndAccept!"orExpression"); } override void visit(const OutStatement outStatement) { mixin (tagAndAccept!"outStatement"); } override void visit(const MixinDeclaration mixinDeclaration) { mixin (tagAndAccept!"mixinDeclaration"); } override void visit(const Parameters parameters) { mixin (tagAndAccept!"parameters"); } override void visit(const Postblit postblit) { mixin (tagAndAccept!"postblit"); } override void visit(const NewAnonClassExpression newAnonClassExpression) { mixin (tagAndAccept!"newAnonClassExpression"); } override void visit(const PragmaDeclaration pragmaDeclaration) { mixin (tagAndAccept!"pragmaDeclaration"); } override void visit(const PragmaExpression pragmaExpression) { mixin (tagAndAccept!"pragmaExpression"); } override void visit(const PrimaryExpression primaryExpression) { mixin (tagAndAccept!"primaryExpression"); } override void visit(const Register register) { mixin (tagAndAccept!"register"); } override void visit(const ScopeGuardStatement scopeGuardStatement) { mixin (tagAndAccept!"scopeGuardStatement"); } override void visit(const SharedStaticConstructor sharedStaticConstructor) { mixin (tagAndAccept!"sharedStaticConstructor"); } override void visit(const SharedStaticDestructor sharedStaticDestructor) { mixin (tagAndAccept!"sharedStaticDestructor"); } override void visit(const ShortenedFunctionBody shortenedFunctionBody) { mixin (tagAndAccept!"shortenedFunctionBody"); } override void visit(const StatementNoCaseNoDefault statementNoCaseNoDefault) { mixin (tagAndAccept!"statementNoCaseNoDefault"); } override void visit(const StaticAssertDeclaration staticAssertDeclaration) { mixin (tagAndAccept!"staticAssertDeclaration"); } override void visit(const StaticAssertStatement staticAssertStatement) { mixin (tagAndAccept!"staticAssertStatement"); } override void visit(const StaticConstructor staticConstructor) { mixin (tagAndAccept!"staticConstructor"); } override void visit(const StaticDestructor staticDestructor) { mixin (tagAndAccept!"staticDestructor"); } override void visit(const StaticIfCondition staticIfCondition) { mixin (tagAndAccept!"staticIfCondition"); } override void visit(const StorageClass storageClass) { mixin (tagAndAccept!"storageClass"); } override void visit(const StructBody structBody) { mixin (tagAndAccept!"structBody"); } override void visit(const StructInitializer structInitializer) { mixin (tagAndAccept!"structInitializer"); } override void visit(const StructMemberInitializers structMemberInitializers) { mixin (tagAndAccept!"structMemberInitializers"); } override void visit(const StructMemberInitializer structMemberInitializer) { mixin (tagAndAccept!"structMemberInitializer"); } override void visit(const SwitchStatement switchStatement) { mixin (tagAndAccept!"switchStatement"); } override void visit(const Symbol symbol) { mixin (tagAndAccept!"symbol"); } override void visit(const SynchronizedStatement synchronizedStatement) { mixin (tagAndAccept!"synchronizedStatement"); } override void visit(const Statement statement) { mixin (tagAndAccept!"statement"); } override void visit(const TemplateArgumentList templateArgumentList) { mixin (tagAndAccept!"templateArgumentList"); } override void visit(const TemplateArguments templateArguments) { mixin (tagAndAccept!"templateArguments"); } override void visit(const TemplateArgument templateArgument) { mixin (tagAndAccept!"templateArgument"); } override void visit(const TemplateMixinExpression templateMixinExpression) { mixin (tagAndAccept!"templateMixinExpression"); } override void visit(const TemplateParameterList templateParameterList) { mixin (tagAndAccept!"templateParameterList"); } override void visit(const TemplateParameters templateParameters) { mixin (tagAndAccept!"templateParameters"); } override void visit(const TemplateParameter templateParameter) { mixin (tagAndAccept!"templateParameter"); } override void visit(const TemplateSingleArgument templateSingleArgument) { mixin (tagAndAccept!"templateSingleArgument"); } override void visit(const TemplateThisParameter templateThisParameter) { mixin (tagAndAccept!"templateThisParameter"); } override void visit(const TemplateTupleParameter templateTupleParameter) { mixin (tagAndAccept!"templateTupleParameter"); } override void visit(const TemplateTypeParameter templateTypeParameter) { mixin (tagAndAccept!"templateTypeParameter"); } override void visit(const TemplateValueParameterDefault templateValueParameterDefault) { mixin (tagAndAccept!"templateValueParameterDefault"); } override void visit(const TemplateValueParameter templateValueParameter) { mixin (tagAndAccept!"templateValueParameter"); } override void visit(const TernaryExpression ternaryExpression) { mixin (tagAndAccept!"ternaryExpression"); } override void visit(const TypeIdentifierPart typeIdentifierPart) { mixin (tagAndAccept!"typeIdentifierPart"); } override void visit(const ThrowExpression throwExpression) { mixin (tagAndAccept!"throwExpression"); } override void visit(const TryStatement tryStatement) { mixin (tagAndAccept!"tryStatement"); } override void visit(const TemplateInstance templateInstance) { mixin (tagAndAccept!"templateInstance"); } override void visit(const TypeofExpression typeofExpression) { mixin (tagAndAccept!"typeofExpression"); } override void visit(const TypeSpecialization typeSpecialization) { mixin (tagAndAccept!"typeSpecialization"); } override void visit(const TraitsExpression traitsExpression) { mixin (tagAndAccept!"traitsExpression"); } override void visit(const Vector vector) { mixin (tagAndAccept!"vector"); } override void visit(const VersionCondition versionCondition) { mixin (tagAndAccept!"versionCondition"); } override void visit(const VersionSpecification versionSpecification) { mixin (tagAndAccept!"versionSpecification"); } override void visit(const WhileStatement whileStatement) { mixin (tagAndAccept!"whileStatement"); } override void visit(const WithStatement withStatement) { mixin (tagAndAccept!"withStatement"); } override void visit(const TypeidExpression typeidExpression) { mixin (tagAndAccept!"typeidExpression"); } // dfmt on alias visit = ASTVisitor.visit; private static string xmlEscape(string s) { return s.translate(['<' : "<", '>' : ">", '&' : "&"]); } private static string xmlAttributeEscape(string s) { return s.translate(['<' : "<", '>' : ">", '&' : "&", '\"' : """, '\'' : "'"]); } private void writeName(string name) { output.writeln("<name>", name, "</name>"); } private void writeDdoc(string comment) { if (comment.ptr is null) return; output.writeln("<ddoc>", xmlEscape(comment), "</ddoc>"); } /** * File that output is written to. */ File output; } private: template tagAndAccept(string tagName) { immutable tagAndAccept = `output.writeln("<` ~ tagName ~ `>");` ~ tagName ~ `.accept(this);` ~ `output.writeln("</` ~ tagName ~ `>");`; }