annotate ast/Decl.d @ 99:857f0d530789 new_gen

Imports and improved module statement Allow "module a.b.c" Supports most forms of D's import. import A, B; import A, B = C; import A, B : a = b, c;
author Anders Halager <halager@gmail.com>
date Tue, 06 May 2008 21:59:22 +0200
parents 621cedba53ea
children fea8d61a2451
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 ast.Decl;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
2
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
3 import ast.Exp,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
4 ast.Stmt;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
5
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
6 import lexer.Token;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
7
56
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
8 import tango.io.Stdout;
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
9
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 86
diff changeset
10 import sema.Scope,
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
11 sema.DType,
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
12 basic.SmallArray;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
13
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
14 enum DeclType
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
15 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
16 VarDecl,
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
17 ImportDecl,
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
18 FuncDecl,
22
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
19 StructDecl,
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
20 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
21
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
22 class Decl
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
23 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
24 this(DeclType declType)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
25 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
26 this.declType = declType;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
27 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
28
56
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
29 void simplify()
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
30 {
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
31 }
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
32
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
33 DType type() { return null; }
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
34
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
35 DeclType declType;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
36 Scope env;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
37 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
38
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
39 class VarDecl : Decl
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
40 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
41 this(Identifier type, Identifier identifier,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
42 Exp e = null)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
43 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
44 super(DeclType.VarDecl);
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
45 this.varType = type;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
46 this.identifier = identifier;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
47 this.init = e;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
48 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
49
56
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
50 void simplify()
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
51 {
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
52 }
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
53
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
54 override DType type()
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
55 {
86
29f486ccc203 Fixed a bug that made arrays as params fail big time
Anders Johnsen <skabet@gmail.com>
parents: 82
diff changeset
56 return env.find(identifier).type;
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
57 }
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
58
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
59 Identifier varType, identifier;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
60 Exp init;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
61 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
62
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
63 class ImportDecl : Decl
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
64 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
65 this()
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
66 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
67 super(DeclType.ImportDecl);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
68 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
69
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
70 bool isStatic = false;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
71
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
72 Identifier[] packages;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
73 Identifier name;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
74 Identifier aliasedName;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
75
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
76 Identifier[2][] explicitSymbols;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
77 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
78
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
79 class FuncDecl : Decl
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
80 {
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
81 this(Identifier type, Identifier identifier)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
82 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
83 super(DeclType.FuncDecl);
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
84 this.returnType = type;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
85 this.identifier = identifier;
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
86 }
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
87
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 64
diff changeset
88 void addParam(Identifier type, Identifier name = null)
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
89 {
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
90 funcArgs ~= new VarDecl(type, name, null);
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
91 }
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
92
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
93 void setBody(CompoundStatement stmts)
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
94 {
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
95 statements = stmts.statements;
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 64
diff changeset
96 emptyFunction = false;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
97 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
98
56
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
99 void simplify()
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
100 {
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
101 if(auto t = cast(DFunction)env.find(identifier).type)
56
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
102 {
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
103 if(auto s = cast(DStruct)t.returnType)
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
104 {
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
105 VarDecl[] funcArgs;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
106 auto i = new Identifier("ret.val");
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
107 i.env = env;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
108 i.env.add(i);
93
621cedba53ea Removed the Symbol from semantics - it was not needed anymore. From now on you set the type by doing a setType on an Identifier.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
109 i.env.find(i).setType( s );
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
110 auto var = new VarDecl(returnType, i);
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
111 var.env = env;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
112 funcArgs ~= var;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
113 funcArgs ~= this.funcArgs;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
114 this.funcArgs = funcArgs;
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
115 t.returnType = DType.Void;
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
116 this.returnType = new Identifier("void");
93
621cedba53ea Removed the Symbol from semantics - it was not needed anymore. From now on you set the type by doing a setType on an Identifier.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
117 env.find(identifier).setType(t);
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
118 sret = true;
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
119
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
120 myType = null;
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
121 }
56
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
122 }
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
123
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
124 foreach ( funcArg ; funcArgs )
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
125 funcArg.simplify();
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
126 foreach ( stmt ; statements )
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
127 stmt.simplify();
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
128 }
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
129
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
130 override DFunction type()
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
131 {
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
132 if (myType !is null)
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
133 return myType;
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
134
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
135 auto t = new DFunction(identifier);
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
136 t.returnType = env.findType(returnType);
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
137 SmallArray!(DType) array;
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
138 foreach (a; funcArgs)
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
139 array ~= a.type();
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
140 t.params = array.safe();
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
141 t.firstParamIsReturnValue = this.sret;
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
142 myType = t;
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
143 return myType;
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
144 }
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
145
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
146 Identifier returnType, identifier;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
147 VarDecl[] funcArgs;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
148 Stmt[] statements;
56
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
149 bool sret = false;
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 64
diff changeset
150 bool emptyFunction = true;
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
151 private DFunction myType;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
152 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
153
22
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
154 class StructDecl : Decl
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
155 {
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 44
diff changeset
156 this(Identifier identifier)
22
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
157 {
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
158 super(DeclType.StructDecl);
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
159 this.identifier = identifier;
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
160 this.vars = vars;
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
161 }
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
162
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 44
diff changeset
163 void addMember(Identifier type, Identifier name, Exp exp)
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 44
diff changeset
164 {
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 44
diff changeset
165 vars ~= new VarDecl(type, name, exp);
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 44
diff changeset
166 }
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 44
diff changeset
167
56
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
168 void simplify()
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
169 {
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
170 }
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 53
diff changeset
171
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
172 override DType type()
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
173 {
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
174 return env.findType(identifier);
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
175 }
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
176
22
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
177 Identifier identifier;
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
178 VarDecl[] vars;
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
179 private DType myType;
22
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
180 }
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
181