Mercurial > projects > dang
comparison src/ast/Decl.d @ 206:d3c148ca429b
Major moving of files. all src now goes into src, all docs in docs.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 12 Aug 2008 18:14:56 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
205:8387cbaa85ab | 206:d3c148ca429b |
---|---|
1 module ast.Decl; | |
2 | |
3 import ast.Expr; | |
4 | |
5 /** | |
6 The base class for all Declarations. | |
7 | |
8 Declarations comes in two forms: | |
9 | |
10 $(OL | |
11 $(LI members, such as variables and functions.) | |
12 $(LI types, such as classes, structs.)) | |
13 | |
14 */ | |
15 class Decl | |
16 { | |
17 | |
18 /// Method for doing cast(FunctionDecl) | |
19 FunctionDecl asFunctionDecl() { return null;} | |
20 | |
21 /// Returns true if it is a FunctionDecl | |
22 bool isFunctionDecl() { return false;} | |
23 | |
24 /// Method for doing cast(VarDecl) | |
25 VarDecl asVarDecl() { return null;} | |
26 | |
27 /// Returns true if it is a VarDecl | |
28 bool isVarDecl() { return false;} | |
29 | |
30 /// Method for doing cast(StructDecl) | |
31 StructDecl asStructDecl() { return null;} | |
32 | |
33 /// Returns true if it is a StructDecl | |
34 bool isStructDecl() { return false;} | |
35 | |
36 /// Method for doing cast(ClassDecl) | |
37 ClassDecl asClassDecl() { return null;} | |
38 | |
39 /// Returns true if it is a ClassDecl | |
40 bool isClassDecl() { return false;} | |
41 | |
42 /// Method for doing cast(InterfaceDecl) | |
43 InterfaceDecl asInterfaceDecl() { return null;} | |
44 | |
45 /// Returns true if it is a InterfaceDecl | |
46 bool isInterfaceDecl() { return false;} | |
47 | |
48 /// Method for doing cast(TypedefDecl) | |
49 TypedefDecl asTypedefDecl() { return null;} | |
50 | |
51 /// Returns true if it is a TypedefDecl | |
52 bool isTypedefDecl() { return false;} | |
53 } | |
54 | |
55 /** | |
56 The FunctionDecl contains a set of VarDecls, being the parameters of the | |
57 method. It also contains a potentiel list of statements. | |
58 */ | |
59 class FunctionDecl : Decl | |
60 { | |
61 /// Returns the parameters of the method. | |
62 VarDecl[] getParams() { return params;} | |
63 /// Return the parameter on a given index. | |
64 VarDecl getParam(int index) { return params[index];} | |
65 /// Returns the number of parameters. | |
66 int getNumberOfParamst() { return params.length;} | |
67 /** | |
68 Returns the number of required arguments, that should be given to | |
69 call this method. | |
70 */ | |
71 int getMinimumNumberOfParams() | |
72 { | |
73 assert(0, "Unimplemented"); | |
74 return 0; | |
75 } | |
76 | |
77 override FunctionDecl asFunctionDecl() { return this;} | |
78 override bool isFunctionDecl() { return true;} | |
79 | |
80 private: | |
81 VarDecl[] params; | |
82 } | |
83 | |
84 /** | |
85 The VarDecl contains as a minimum a Type. As an addition, i will also | |
86 in most cases contain an Identifier that it'll be reconized by and in | |
87 some cases it will also contain an expression that'll be it initializer. | |
88 | |
89 Some cases to check: | |
90 | |
91 $(UL | |
92 $(LI | |
93 If the VarDecl is a param in a FunctionDecl the initializer, if | |
94 present, should be a constant expression(Enum, Number, String | |
95 or the like). | |
96 ) | |
97 ) | |
98 */ | |
99 class VarDecl : Decl | |
100 { | |
101 /// Return true if the VarDecl has an identifier/name. | |
102 bool hasIdentifier() { return !(identifier is null);} | |
103 /// Return true if the VarDecl has en initializer. | |
104 bool hasInitializer() { return !(initializer is null);} | |
105 | |
106 override VarDecl asVarDecl() { return this;} | |
107 override bool isVarDecl() { return true;} | |
108 | |
109 private: | |
110 Identifier identifier; | |
111 Expr initializer; | |
112 } | |
113 | |
114 class StructDecl : Decl | |
115 { | |
116 override StructDecl asStructDecl() { return this;} | |
117 override bool isStructDecl() { return true;} | |
118 } | |
119 | |
120 class ClassDecl : Decl | |
121 { | |
122 override ClassDecl asClassDecl() { return this;} | |
123 override bool isClassDecl() { return true;} | |
124 } | |
125 | |
126 class InterfaceDecl : Decl | |
127 { | |
128 override InterfaceDecl asInterfaceDecl() { return this;} | |
129 override bool isInterfaceDecl() { return true;} | |
130 } | |
131 | |
132 class TypedefDecl : Decl | |
133 { | |
134 override TypedefDecl asTypedefDecl() { return this;} | |
135 override bool isTypedefDecl() { return true;} | |
136 } | |
137 |