annotate tools/AstPrinter.d @ 101:fea8d61a2451 new_gen

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...?)
author Anders Johnsen <skabet@gmail.com>
date Wed, 07 May 2008 19:58:13 +0200
parents 48bb2287c035
children cd066f3b539a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1 module tools.AstPrinter;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
2
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
3 import tango.io.Stdout;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
7 ast.Stmt,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
8 ast.Exp;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
9
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 79
diff changeset
10 import basic.SourceManager;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
11
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
12 class AstPrinter
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
13 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
14 const char[] tabType = " "; // 4 spaces
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
15
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 79
diff changeset
16 this(SourceManager sm)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
17 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
18
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 79
diff changeset
19 this.sm = sm;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
20 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
21
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
22 void print(Module m)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
23 {
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
24 printBeginLine("module ");
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 printEndLine(m.moduleName);
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
26 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
27 foreach(decl ; m.decls)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
28 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
29 printDecl(decl);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
30 }
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
31 printEndLine();
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
32 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
33
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
34 void printDecl(Decl decl)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
35 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
36 switch(decl.declType)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
37 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
38 case DeclType.FuncDecl:
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
39 auto funcDecl = cast(FuncDecl)decl;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
40 printBeginLine();
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
41 printIdentifier(funcDecl.returnType);
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
42 space;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
43 printIdentifier(funcDecl.identifier);
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
44 printFuncArgs(funcDecl);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
45 printOpenBrace();
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
46 foreach(stmt ; funcDecl.statements)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
47 printStatement(stmt);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
48 printCloseBrace();
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
49 break;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
50
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
51 case DeclType.VarDecl:
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
52 auto varDecl = cast(VarDecl)decl;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
53 printBeginLine();
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
54 printExp(varDecl.varType);
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
55 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
56 printExp(varDecl.identifier);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
57 if(varDecl.init)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
58 {
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
59 print(" = ");
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
60 printExp(varDecl.init);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
61 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
62 printEndLine(";");
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
63 break;
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
64
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
65 case DeclType.StructDecl:
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
66 auto structDecl = cast(StructDecl)decl;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
67 printBeginLine("struct ");
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
68 printIdentifier(structDecl.identifier);
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
69 printEndLine;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
70 printOpenBrace;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
71 foreach( var ; structDecl.vars)
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
72 printDecl(var);
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
73 printCloseBrace;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
74 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
75
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
76 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
77 auto i = cast(ImportDecl)decl;
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
78 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
79 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
80 break;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
81 }
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
82 printEndLine();
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
83 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
84
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
85 void printStatement(Stmt stmt)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
86 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
87 switch(stmt.stmtType)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
88 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
89 case StmtType.Return:
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
90 auto ret = cast(ReturnStmt)stmt;
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
91 printBeginLine("return");
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
92 if(ret.exp)
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
93 {
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
94 space;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
95 printExp(ret.exp);
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
96 }
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
97 printEndLine(";");
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
98 break;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
99 case StmtType.Decl:
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
100 auto declStmt = cast(DeclStmt)stmt;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
101 printDecl(declStmt.decl);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
102 break;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
103 case StmtType.Exp:
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
104 auto expStmt = cast(ExpStmt)stmt;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
105 printBeginLine();
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
106 printExp(expStmt.exp);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
107 printEndLine(";");
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
108 break;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
109
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
110 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
111 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
112
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
113 void printExp(Exp exp)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
114 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
115 switch(exp.expType)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
116 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
117 case ExpType.Binary:
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
118 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
119 print("(");
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
120 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
121 print(" " ~ binaryExp.getOp[binaryExp.op] ~ " ");
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
122 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
123 print(")");
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
124 break;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
125 case ExpType.IntegerLit:
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
126 auto integetLit = cast(IntegerLit)exp;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 79
diff changeset
127 print(integetLit.get);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
128 break;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
129 case ExpType.Negate:
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
130 auto negateExp = cast(NegateExp)exp;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
131 print("-");
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
132 printExp(negateExp.exp);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
133 break;
78
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
134 case ExpType.Deref:
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
135 auto derefExp = cast(DerefExp)exp;
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
136 print("*");
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
137 printExp(derefExp.exp);
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
138 break;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
139 case ExpType.AssignExp:
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
140 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
141 printExp(assignExp.identifier);
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
142 print(" = ");
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
143 printExp(assignExp.exp);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
144 break;
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
145 case ExpType.MemberReference:
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
146 auto mrExp = cast(MemberReference)exp;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
147 printExp(mrExp.target);
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
148 print(".");
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
149 printIdentifier(mrExp.child);
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
150 break;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
151 case ExpType.Identifier:
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
152 auto iden = cast(Identifier)exp;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
153 printIdentifier(iden);
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
154 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
155 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
156 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
157 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
158 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
159 break;
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
160 case ExpType.CallExp:
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
161 auto callExp = cast(CallExp)exp;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
162 printExp(callExp.exp);
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
163 print("(");
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
164 foreach(i, e; callExp.args)
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
165 {
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
166 printExp(e);
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
167 if(i+1 < callExp.args.length)
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
168 print(", ");
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
169 }
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
170 print(")");
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 break;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
180 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
181
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
182 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
183
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
184 void printFuncArgs(FuncDecl decl)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
185 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
186 print("(");
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
187
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
188 foreach(i, d; decl.funcArgs)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
189 {
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
190 printIdentifier(d.varType);
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
191 if(i == 0 && decl.sret)
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
192 print("*");
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
193 space;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
194 printIdentifier(d.identifier);
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
195 if(i+1 < decl.funcArgs.length)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
196 print(",");
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
197 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
198
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
199 printEndLine(")");
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
200 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
201
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
202 void printIdentifier(Identifier identifier)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
203 {
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
204 print(identifier.get);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
205 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
206
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
207 void printOpenBrace()
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
208 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
209 printEndLine(tabIndex~"{");
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
210 tabIndex ~= tabType;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
211 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
212
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
213 void printCloseBrace()
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
214 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
215 tabIndex = tabIndex[0 .. $-tabType.length];
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
216 printEndLine(tabIndex~"}");
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
217 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
218
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
219 void printBeginLine(char[] line = "")
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
220 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
221 Stdout(tabIndex~line);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
222 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
223
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
224 void printEndLine(char[] line = "")
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
225 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
226 Stdout(line).newline;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
227 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
228
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
229 void print(char[] line)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
230 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
231 Stdout(line);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
232 }
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
233
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
234 void space()
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
235 {
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
236 print(" ");
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 28
diff changeset
237 }
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
238 private:
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 79
diff changeset
239 SourceManager sm;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
240 char[] tabIndex;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
241 }