Mercurial > projects > dang
annotate tools/AstPrinter.d @ 158:57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 22 Jul 2008 00:33:58 +0200 |
parents | 6ec686d9c87d |
children | 362265427838 |
rev | line source |
---|---|
1 | 1 module tools.AstPrinter; |
2 | |
3 import tango.io.Stdout; | |
4 | |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
5 import ast.Module, |
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
6 ast.Decl, |
1 | 7 ast.Stmt, |
8 ast.Exp; | |
9 | |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
10 import basic.SourceManager, |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
11 basic.Attribute; |
1 | 12 |
13 class AstPrinter | |
14 { | |
15 const char[] tabType = " "; // 4 spaces | |
16 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
79
diff
changeset
|
17 this(SourceManager sm) |
1 | 18 { |
19 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
79
diff
changeset
|
20 this.sm = sm; |
1 | 21 } |
22 | |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
23 void print(Module m) |
1 | 24 { |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
25 printBeginLine("module "); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
26 print(m.moduleName); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
27 printEndLine(";"); |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
28 printEndLine(); |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
29 foreach(decl ; m.decls) |
1 | 30 { |
31 printDecl(decl); | |
32 } | |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
33 printEndLine(); |
1 | 34 } |
35 | |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
36 void printDecl(Decl decl, bool printAtt = true) |
1 | 37 { |
38 switch(decl.declType) | |
39 { | |
40 case DeclType.FuncDecl: | |
41 auto funcDecl = cast(FuncDecl)decl; | |
42 printBeginLine(); | |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
43 if(printAtt) printAttribute(decl.att); |
63
9f8131676242
Now Decl's have a DType type(), and should use varType and returnType to get the old type id
Anders Halager <halager@gmail.com>
parents:
60
diff
changeset
|
44 printIdentifier(funcDecl.returnType); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
45 space; |
1 | 46 printIdentifier(funcDecl.identifier); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
47 printFuncArgs(funcDecl); |
1 | 48 printOpenBrace(); |
49 foreach(stmt ; funcDecl.statements) | |
50 printStatement(stmt); | |
51 printCloseBrace(); | |
52 break; | |
53 | |
54 case DeclType.VarDecl: | |
55 auto varDecl = cast(VarDecl)decl; | |
56 printBeginLine(); | |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
57 if(printAtt) printAttribute(decl.att); |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
58 printExp(varDecl.varType); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
59 space; |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
60 printExp(varDecl.identifier); |
1 | 61 if(varDecl.init) |
62 { | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
63 print(" = "); |
1 | 64 printExp(varDecl.init); |
65 } | |
66 printEndLine(";"); | |
67 break; | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
68 |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
69 case DeclType.StructDecl: |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
70 auto structDecl = cast(StructDecl)decl; |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
71 if(printAtt) printAttribute(decl.att); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
72 printBeginLine("struct "); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
73 printIdentifier(structDecl.identifier); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
74 printEndLine; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
75 printOpenBrace; |
102
cd066f3b539a
Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
76 foreach( var ; structDecl.decls) |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
77 printDecl(var); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
78 printCloseBrace; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
79 break; |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
80 |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
81 case DeclType.ClassDecl: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
82 auto classDecl = cast(ClassDecl)decl; |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
83 if(printAtt) printAttribute(decl.att); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
84 printBeginLine("class "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
85 printIdentifier(classDecl.identifier); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
86 foreach(i, iden ; classDecl.baseClasses ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
87 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
88 print(i ? " : " : ", "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
89 printIdentifier(iden); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
90 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
91 printEndLine; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
92 printOpenBrace; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
93 foreach( var ; classDecl.decls) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
94 printDecl(var); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
95 printCloseBrace; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
96 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
97 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
98 case DeclType.InterfaceDecl: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
99 auto interfaceDecl = cast(InterfaceDecl)decl; |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
100 if(printAtt) printAttribute(decl.att); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
101 printBeginLine("interface "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
102 printIdentifier(interfaceDecl.identifier); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
103 foreach(i, iden ; interfaceDecl.baseClasses ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
104 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
105 print(i ? " : " : ", "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
106 printIdentifier(iden); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
107 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
108 printEndLine; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
109 printOpenBrace; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
110 foreach( var ; interfaceDecl.decls) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
111 printDecl(var); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
112 printCloseBrace; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
113 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
114 |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
115 case DeclType.ImportDecl: |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
116 auto i = cast(ImportDecl)decl; |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
117 if(printAtt) printAttribute(decl.att); |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
118 printBeginLine("import "); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
119 printEndLine(i.get); |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
94
diff
changeset
|
120 break; |
1 | 121 } |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
122 // printEndLine(); |
1 | 123 } |
124 | |
125 void printStatement(Stmt stmt) | |
126 { | |
127 switch(stmt.stmtType) | |
128 { | |
129 case StmtType.Return: | |
130 auto ret = cast(ReturnStmt)stmt; | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
131 printBeginLine("return"); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
132 if(ret.exp) |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
133 { |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
134 space; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
135 printExp(ret.exp); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
136 } |
1 | 137 printEndLine(";"); |
138 break; | |
139 case StmtType.Decl: | |
140 auto declStmt = cast(DeclStmt)stmt; | |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
141 printDecl(declStmt.decl, false); |
1 | 142 break; |
143 case StmtType.Exp: | |
144 auto expStmt = cast(ExpStmt)stmt; | |
145 printBeginLine(); | |
146 printExp(expStmt.exp); | |
147 printEndLine(";"); | |
148 break; | |
149 | |
150 } | |
151 } | |
152 | |
153 void printExp(Exp exp) | |
154 { | |
155 switch(exp.expType) | |
156 { | |
157 case ExpType.Binary: | |
158 auto binaryExp = cast(BinaryExp)exp; | |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
159 print("("); |
1 | 160 printExp(binaryExp.left); |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
161 print(" " ~ binaryExp.getOp[binaryExp.op] ~ " "); |
1 | 162 printExp(binaryExp.right); |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
163 print(")"); |
1 | 164 break; |
165 case ExpType.IntegerLit: | |
166 auto integetLit = cast(IntegerLit)exp; | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
79
diff
changeset
|
167 print(integetLit.get); |
1 | 168 break; |
169 case ExpType.Negate: | |
170 auto negateExp = cast(NegateExp)exp; | |
171 print("-"); | |
172 printExp(negateExp.exp); | |
173 break; | |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
174 case ExpType.Deref: |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
175 auto derefExp = cast(DerefExp)exp; |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
176 print("*"); |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
177 printExp(derefExp.exp); |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
178 break; |
1 | 179 case ExpType.AssignExp: |
180 auto assignExp = cast(AssignExp)exp; | |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
181 printExp(assignExp.identifier); |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
102
diff
changeset
|
182 print(" "); |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
102
diff
changeset
|
183 print(assignExp.getOp[assignExp.op]); |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
102
diff
changeset
|
184 print(" "); |
1 | 185 printExp(assignExp.exp); |
186 break; | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
187 case ExpType.MemberReference: |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
188 auto mrExp = cast(MemberReference)exp; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
189 printExp(mrExp.target); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
190 print("."); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
191 printIdentifier(mrExp.child); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
192 break; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
193 case ExpType.Identifier: |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
194 auto iden = cast(Identifier)exp; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
195 printIdentifier(iden); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
196 break; |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
197 case ExpType.PointerIdentifier: |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
198 auto iden = cast(PointerIdentifier)exp; |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
199 printExp(iden.pointerOf); |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
200 print("*"); |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
201 break; |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
202 case ExpType.CallExp: |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
203 auto callExp = cast(CallExp)exp; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
204 printExp(callExp.exp); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
205 print("("); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
206 foreach(i, e; callExp.args) |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
207 { |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
208 printExp(e); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
209 if(i+1 < callExp.args.length) |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
210 print(", "); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
211 } |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
212 print(")"); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
213 break; |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
214 case ExpType.CastExp: |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
215 auto castExp = cast(CastExp)exp; |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
216 print("cast"); |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
217 print("("); |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
218 printExp(castExp.castType); |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
219 print(")"); |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
220 printExp(castExp.exp); |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
221 break; |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
222 case ExpType.NewExp: |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
223 auto newExp = cast(NewExp)exp; |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
224 print("new "); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
225 if(newExp.a_args.length) |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
226 { |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
227 foreach( i, a ; newExp.a_args ) |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
228 { |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
229 print(i ? ", " : "("); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
230 printExp(a); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
231 } |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
232 print(")"); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
233 } |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
234 printExp(newExp.newType); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
235 print("("); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
236 foreach( i, c ; newExp.c_args ) |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
237 { |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
238 print(i ? ", " : ""); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
239 printExp(c); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
240 } |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
241 print(")"); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
148
diff
changeset
|
242 break; |
1 | 243 } |
244 | |
245 } | |
246 | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
247 void printFuncArgs(FuncDecl decl) |
1 | 248 { |
249 print("("); | |
250 | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
251 foreach(i, d; decl.funcArgs) |
1 | 252 { |
63
9f8131676242
Now Decl's have a DType type(), and should use varType and returnType to get the old type id
Anders Halager <halager@gmail.com>
parents:
60
diff
changeset
|
253 printIdentifier(d.varType); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
254 if(i == 0 && decl.sret) |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
255 print("*"); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
256 space; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
257 printIdentifier(d.identifier); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
258 if(i+1 < decl.funcArgs.length) |
1 | 259 print(","); |
260 } | |
261 | |
262 printEndLine(")"); | |
263 } | |
264 | |
265 void printIdentifier(Identifier identifier) | |
266 { | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
267 print(identifier.get); |
1 | 268 } |
269 | |
270 void printOpenBrace() | |
271 { | |
272 printEndLine(tabIndex~"{"); | |
273 tabIndex ~= tabType; | |
274 } | |
275 | |
276 void printCloseBrace() | |
277 { | |
278 tabIndex = tabIndex[0 .. $-tabType.length]; | |
279 printEndLine(tabIndex~"}"); | |
280 } | |
281 | |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
282 void printAttribute(Attribute a) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
283 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
284 switch(a.getExtern) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
285 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
286 case Extern.C: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
287 print("extern(C) "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
288 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
289 case Extern.CPlusPlus: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
290 print("extern(C++) "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
291 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
292 case Extern.D: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
293 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
294 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
295 switch(a.getProtection) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
296 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
297 case Protection.Public: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
298 print("public "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
299 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
300 case Protection.Private: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
301 print("private "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
302 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
303 case Protection.Package: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
304 print("package "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
305 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
306 case Protection.Protected: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
307 print("protected "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
308 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
309 case Protection.Export: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
310 print("export "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
311 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
312 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
313 if ( a.getStatic ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
314 print("static "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
315 if ( a.getFinal ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
316 print("final "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
317 if ( a.getConst ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
318 print("const "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
319 if ( a.getAbstract ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
320 print("abstract "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
321 if ( a.getOverride ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
322 print("override "); |
148
6ec686d9c87d
Fixed some for parsing, and removed a little ugly bug.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
323 if ( a.getDeprecated ) |
6ec686d9c87d
Fixed some for parsing, and removed a little ugly bug.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
324 print("deprecated "); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
325 if ( a.getAuto ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
326 print("auto "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
327 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
328 |
1 | 329 void printBeginLine(char[] line = "") |
330 { | |
331 Stdout(tabIndex~line); | |
332 } | |
333 | |
334 void printEndLine(char[] line = "") | |
335 { | |
336 Stdout(line).newline; | |
337 } | |
338 | |
339 void print(char[] line) | |
340 { | |
341 Stdout(line); | |
342 } | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
343 |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
344 void space() |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
345 { |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
346 print(" "); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
347 } |
1 | 348 private: |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
79
diff
changeset
|
349 SourceManager sm; |
1 | 350 char[] tabIndex; |
351 } |