Mercurial > projects > dang
annotate tools/AstPrinter.d @ 163:362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 22 Jul 2008 16:50:47 +0200 |
parents | 57b0b4464a0b |
children | 01c2c49775ef |
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(); | |
163
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
43 if (printAtt) printAttribute(decl.att); |
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
44 if (funcDecl.identifier.get != "this") |
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
45 { |
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
46 printIdentifier(funcDecl.returnType); |
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
47 space; |
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
48 } |
1 | 49 printIdentifier(funcDecl.identifier); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
50 printFuncArgs(funcDecl); |
1 | 51 printOpenBrace(); |
52 foreach(stmt ; funcDecl.statements) | |
53 printStatement(stmt); | |
54 printCloseBrace(); | |
55 break; | |
56 | |
57 case DeclType.VarDecl: | |
58 auto varDecl = cast(VarDecl)decl; | |
59 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
|
60 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
|
61 printExp(varDecl.varType); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
62 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
|
63 printExp(varDecl.identifier); |
1 | 64 if(varDecl.init) |
65 { | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
66 print(" = "); |
1 | 67 printExp(varDecl.init); |
68 } | |
69 printEndLine(";"); | |
70 break; | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
71 |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
72 case DeclType.StructDecl: |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
73 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
|
74 if(printAtt) printAttribute(decl.att); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
75 printBeginLine("struct "); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
76 printIdentifier(structDecl.identifier); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
77 printEndLine; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
78 printOpenBrace; |
102
cd066f3b539a
Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
79 foreach( var ; structDecl.decls) |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
80 printDecl(var); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
81 printCloseBrace; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
82 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
|
83 |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
84 case DeclType.ClassDecl: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
85 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
|
86 if(printAtt) printAttribute(decl.att); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
87 printBeginLine("class "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
88 printIdentifier(classDecl.identifier); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
89 foreach(i, iden ; classDecl.baseClasses ) |
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 print(i ? " : " : ", "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
92 printIdentifier(iden); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
93 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
94 printEndLine; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
95 printOpenBrace; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
96 foreach( var ; classDecl.decls) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
97 printDecl(var); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
98 printCloseBrace; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
99 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
100 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
101 case DeclType.InterfaceDecl: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
102 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
|
103 if(printAtt) printAttribute(decl.att); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
104 printBeginLine("interface "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
105 printIdentifier(interfaceDecl.identifier); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
106 foreach(i, iden ; interfaceDecl.baseClasses ) |
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 print(i ? " : " : ", "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
109 printIdentifier(iden); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
110 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
111 printEndLine; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
112 printOpenBrace; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
113 foreach( var ; interfaceDecl.decls) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
114 printDecl(var); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
115 printCloseBrace; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
116 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
117 |
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 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 break; |
1 | 124 } |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
125 // printEndLine(); |
1 | 126 } |
127 | |
128 void printStatement(Stmt stmt) | |
129 { | |
130 switch(stmt.stmtType) | |
131 { | |
132 case StmtType.Return: | |
133 auto ret = cast(ReturnStmt)stmt; | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
134 printBeginLine("return"); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
135 if(ret.exp) |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
136 { |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
137 space; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
138 printExp(ret.exp); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
139 } |
1 | 140 printEndLine(";"); |
141 break; | |
142 case StmtType.Decl: | |
143 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
|
144 printDecl(declStmt.decl, false); |
1 | 145 break; |
146 case StmtType.Exp: | |
147 auto expStmt = cast(ExpStmt)stmt; | |
148 printBeginLine(); | |
149 printExp(expStmt.exp); | |
150 printEndLine(";"); | |
151 break; | |
152 | |
153 } | |
154 } | |
155 | |
156 void printExp(Exp exp) | |
157 { | |
158 switch(exp.expType) | |
159 { | |
160 case ExpType.Binary: | |
161 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
|
162 print("("); |
1 | 163 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
|
164 print(" " ~ binaryExp.getOp[binaryExp.op] ~ " "); |
1 | 165 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
|
166 print(")"); |
1 | 167 break; |
168 case ExpType.IntegerLit: | |
169 auto integetLit = cast(IntegerLit)exp; | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
79
diff
changeset
|
170 print(integetLit.get); |
1 | 171 break; |
172 case ExpType.Negate: | |
173 auto negateExp = cast(NegateExp)exp; | |
174 print("-"); | |
175 printExp(negateExp.exp); | |
176 break; | |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
177 case ExpType.Deref: |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
178 auto derefExp = cast(DerefExp)exp; |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
179 print("*"); |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
180 printExp(derefExp.exp); |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
181 break; |
1 | 182 case ExpType.AssignExp: |
183 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
|
184 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
|
185 print(" "); |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
102
diff
changeset
|
186 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
|
187 print(" "); |
1 | 188 printExp(assignExp.exp); |
189 break; | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
190 case ExpType.MemberReference: |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
191 auto mrExp = cast(MemberReference)exp; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
192 printExp(mrExp.target); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
193 print("."); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
194 printIdentifier(mrExp.child); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
195 break; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
196 case ExpType.Identifier: |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
197 auto iden = cast(Identifier)exp; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
198 printIdentifier(iden); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
199 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 break; |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
205 case ExpType.CallExp: |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
206 auto callExp = cast(CallExp)exp; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
207 printExp(callExp.exp); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
208 print("("); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
209 foreach(i, e; callExp.args) |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
210 { |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
211 printExp(e); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
212 if(i+1 < callExp.args.length) |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
213 print(", "); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
214 } |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
215 print(")"); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 { |
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 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
|
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(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
|
233 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
|
234 } |
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 } |
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 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
|
238 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
|
239 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
|
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(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
|
242 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
|
243 } |
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
|
244 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
|
245 break; |
1 | 246 } |
247 | |
248 } | |
249 | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
250 void printFuncArgs(FuncDecl decl) |
1 | 251 { |
252 print("("); | |
253 | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
254 foreach(i, d; decl.funcArgs) |
1 | 255 { |
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
|
256 printIdentifier(d.varType); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
257 if(i == 0 && decl.sret) |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
258 print("*"); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
259 space; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
260 printIdentifier(d.identifier); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
261 if(i+1 < decl.funcArgs.length) |
1 | 262 print(","); |
263 } | |
264 | |
265 printEndLine(")"); | |
266 } | |
267 | |
268 void printIdentifier(Identifier identifier) | |
269 { | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
270 print(identifier.get); |
1 | 271 } |
272 | |
273 void printOpenBrace() | |
274 { | |
275 printEndLine(tabIndex~"{"); | |
276 tabIndex ~= tabType; | |
277 } | |
278 | |
279 void printCloseBrace() | |
280 { | |
281 tabIndex = tabIndex[0 .. $-tabType.length]; | |
282 printEndLine(tabIndex~"}"); | |
283 } | |
284 | |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
285 void printAttribute(Attribute a) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
286 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
287 switch(a.getExtern) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
288 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
289 case Extern.C: |
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.CPlusPlus: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
293 print("extern(C++) "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
294 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
295 case Extern.D: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
296 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
297 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
298 switch(a.getProtection) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
299 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
300 case Protection.Public: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
301 print("public "); |
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.Private: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
304 print("private "); |
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.Package: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
307 print("package "); |
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.Protected: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
310 print("protected "); |
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 case Protection.Export: |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
313 print("export "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
314 break; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
315 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
316 if ( a.getStatic ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
317 print("static "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
318 if ( a.getFinal ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
319 print("final "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
320 if ( a.getConst ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
321 print("const "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
322 if ( a.getAbstract ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
323 print("abstract "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
324 if ( a.getOverride ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
325 print("override "); |
148
6ec686d9c87d
Fixed some for parsing, and removed a little ugly bug.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
326 if ( a.getDeprecated ) |
6ec686d9c87d
Fixed some for parsing, and removed a little ugly bug.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
327 print("deprecated "); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
328 if ( a.getAuto ) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
329 print("auto "); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
330 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
331 |
1 | 332 void printBeginLine(char[] line = "") |
333 { | |
334 Stdout(tabIndex~line); | |
335 } | |
336 | |
337 void printEndLine(char[] line = "") | |
338 { | |
339 Stdout(line).newline; | |
340 } | |
341 | |
342 void print(char[] line) | |
343 { | |
344 Stdout(line); | |
345 } | |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
346 |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
347 void space() |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
348 { |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
349 print(" "); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
28
diff
changeset
|
350 } |
1 | 351 private: |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
79
diff
changeset
|
352 SourceManager sm; |
1 | 353 char[] tabIndex; |
354 } |