annotate ast/Decl.d @ 129:ed815b31479b

Added a Symbol
author Anders Halager <halager@gmail.com>
date Sat, 21 Jun 2008 20:41:18 +0200
parents c3b24e7e8cf8
children 2be29b296081
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,
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
11 sema.Symbol,
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
12 sema.DType,
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 107
diff changeset
13 basic.SmallArray,
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 107
diff changeset
14 basic.Attribute;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
15
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
16 enum DeclType
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
17 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
18 VarDecl,
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
19 DummyDecl,
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
20 ImportDecl,
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
21 FuncDecl,
22
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
22 StructDecl,
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
23 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
24
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
25 class Decl
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
26 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
27 this(DeclType declType)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
28 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
29 this.declType = declType;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
30 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
31
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
32 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
33 {
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
34 }
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
35
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
36 DType type()
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
37 {
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
38 if (sym !is null)
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
39 return sym.type;
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
40 return null;
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
41 }
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
42
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
43 DeclType declType;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
44 Scope env;
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
45 Symbol sym;
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 107
diff changeset
46 Attribute att;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
47 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
48
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
49 class DummyDecl : Decl
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
50 {
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
51 this()
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
52 {
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
53 super(DeclType.DummyDecl);
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
54 }
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
55 }
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
56
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
57 class VarDecl : Decl
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
58 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
59 this(Identifier type, Identifier identifier,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
60 Exp e = null)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
61 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
62 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
63 this.varType = type;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
64 this.identifier = identifier;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
65 this.init = e;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
66 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
67
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
68 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
69 {
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
70 }
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
71
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
72 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
73 {
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
74 return env.findType(varType);
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
75 }
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
76
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
77 Identifier varType, identifier;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
78 Exp init;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
79 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
80
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
81 class ImportDecl : Decl
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
82 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
83 this()
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
84 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
85 super(DeclType.ImportDecl);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
86 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
87
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: 99
diff changeset
88 char[] 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: 99
diff changeset
89 {
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: 99
diff changeset
90 char[] res;
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: 99
diff changeset
91 foreach(i ; packages)
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: 99
diff changeset
92 res ~= 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: 99
diff changeset
93 res ~= name.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: 99
diff changeset
94 return res;
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: 99
diff changeset
95 }
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: 99
diff changeset
96
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
97 bool isStatic = false;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
98
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
99 Identifier[] packages;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
100 Identifier name;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
101 Identifier aliasedName;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
102
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
103 Identifier[2][] explicitSymbols;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
104 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 93
diff changeset
105
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
106 class FuncDecl : Decl
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
107 {
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
108 this(Identifier type, Identifier identifier)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
109 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
110 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
111 this.returnType = type;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
112 this.identifier = identifier;
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
113 }
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
114
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 64
diff changeset
115 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
116 {
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
117 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
118 }
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
119
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
120 void setBody(CompoundStatement stmts)
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
121 {
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 22
diff changeset
122 statements = stmts.statements;
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 64
diff changeset
123 emptyFunction = false;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
124 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
125
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
126 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
127 {
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
128 /*
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
129 if(auto t = env.find(identifier).type.asFunction())
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
130 {
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 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
132 {
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
133 VarDecl[] funcArgs;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
134 auto i = new Identifier("ret.val");
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
135 i.env = env;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
136 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
137 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
138 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
139 var.env = env;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
140 funcArgs ~= var;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
141 funcArgs ~= this.funcArgs;
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
142 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
143 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
144 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
145 env.find(identifier).setType(t);
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
146 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
147
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
148 myType = null;
60
2451f0904bf6 Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents: 56
diff changeset
149 }
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
150 }
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 126
diff changeset
151 */
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
152
107
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 102
diff changeset
153 foreach (funcArg; funcArgs)
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
154 funcArg.simplify();
107
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 102
diff changeset
155 foreach (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
156 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
157 }
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
158
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
159 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
160 {
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
161 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
162 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
163
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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 }
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
174
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 Identifier returnType, identifier;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
176 VarDecl[] funcArgs;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
177 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
178 bool sret = false;
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 64
diff changeset
179 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
180 private DFunction myType;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
181 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
182
22
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
183 class StructDecl : Decl
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
184 {
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
185 this(Identifier identifier)
22
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
186 {
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
187 super(DeclType.StructDecl);
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
188 this.identifier = identifier;
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
189 }
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
190
102
cd066f3b539a Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents: 101
diff changeset
191 void addMember(Decl decl)
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
192 {
102
cd066f3b539a Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents: 101
diff changeset
193 decls ~= decl;
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
194 }
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
195
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
196 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
197 {
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
198 }
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
199
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
200 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
201 {
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
202 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
203 }
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
204
22
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
205 Identifier identifier;
102
cd066f3b539a Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents: 101
diff changeset
206 Decl[] decls;
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
207 private DType myType;
22
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
208 }
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 1
diff changeset
209