1
1
open AST
2
2
open Hashtbl
3
3
4
-
4
+ exception ParentClassNotDefined of string
5
+ exception SameFunctionAlreadyDefined of string
6
+ exception SameFunctionConstructorsDefined of string
5
7
6
8
type classDescriptor =
7
9
{
@@ -84,13 +86,13 @@ let printClassTable classTable =
84
86
*)
85
87
86
88
let addMethodsToMethodTable className methodTable cmethod =
87
- let nameMethod = className ^ " _" ^ cmethod.mname in
89
+ let nameMethod = className ^ " _" ^ cmethod.mname ^ " _ " ^ ( ListII. concat_map " , " stringOf_argType cmethod.margstype) in
88
90
if (verifyHashtbl methodTable nameMethod) = false
89
91
then begin
90
92
Hashtbl. add methodTable nameMethod cmethod
91
93
end
92
94
else begin
93
- print_endline( " function " ^ cmethod.mname ^ " already in the method table " )
95
+ raise( SameFunctionAlreadyDefined (nameMethod ^ " already defined in method Table " ) )
94
96
end
95
97
96
98
@@ -102,17 +104,26 @@ let addToMethodTable methodTable className c =
102
104
ulity: add methods, constructors,attributes in the Hashtbl classTable
103
105
*)
104
106
let addMethodsToClassDesciptor className methods cmethod =
105
- if (verifyHashtbl methods cmethod.mname) = false
107
+ let nameKey = cmethod.mname ^ " _" ^ (ListII. concat_map " ," stringOf_argType cmethod.margstype) in
108
+
109
+ if (verifyHashtbl methods nameKey) = false
106
110
then begin
107
- let nameMethod = className ^ " _" ^ cmethod.mname in
108
- Hashtbl. add methods cmethod.mname nameMethod
111
+ let nameMethod = className ^ " _" ^ cmethod.mname ^ " _ " ^ ( ListII. concat_map " , " stringOf_argType cmethod.margstype) in
112
+ Hashtbl. add methods nameKey nameMethod
109
113
end
110
114
else begin
111
- print_endline( " function " ^ cmethod.mname ^ " already defined" )
115
+ raise( SameFunctionAlreadyDefined (nameKey ^ " already defined in ClassDesciptor " ^ className ) )
112
116
end
113
117
114
118
let addConstructorsToClassDesciptor constructorsClass constructor =
115
- Hashtbl. add constructorsClass (ListII. concat_map " ," stringOf_argType constructor.cargstype) constructor
119
+ let args = (ListII. concat_map " ," stringOf_argType constructor.cargstype) in
120
+ if (verifyHashtbl constructorsClass args) = false
121
+ then begin
122
+ Hashtbl. add constructorsClass args constructor
123
+ end
124
+ else begin
125
+ raise(SameFunctionConstructorsDefined (args ^ " type constructor already defined in ClassDesciptor " ))
126
+ end
116
127
117
128
let addMethodsToClassDesciptorFromParent classTable methodsClass c =
118
129
if (Hashtbl. mem classTable c.cparent.tid) = true
@@ -155,9 +166,11 @@ let addToClassTable classTable className c =
155
166
(* asttype ={ mutable modifiers : modifier list; id : string; info : type_info;}
156
167
ulity: add class and methods in the Hashtbl
157
168
*)
158
- let rec findParentClass cname typelist = match typelist with
169
+ let rec findParentClass cname typelist =
170
+ match typelist with
159
171
| head ::liste -> if head.id = cname then head else findParentClass cname liste
160
172
173
+
161
174
let rec compileClass methodTable classTable ast asttype =
162
175
match asttype.info with
163
176
| Class c -> if (verifyHashtbl classTable asttype.id) = false
@@ -169,10 +182,15 @@ let rec compileClass methodTable classTable ast asttype =
169
182
end
170
183
else
171
184
begin
172
- let parenttype = findParentClass c.cparent.tid ast.type_list in
173
- compileClass methodTable classTable ast parenttype;
174
- addToClassTable classTable asttype.id c;
175
- addToMethodTable methodTable asttype.id c
185
+ try
186
+ let parenttype = findParentClass c.cparent.tid ast.type_list in
187
+ compileClass methodTable classTable ast parenttype;
188
+ addToClassTable classTable asttype.id c;
189
+ addToMethodTable methodTable asttype.id c;
190
+ with
191
+ | SameFunctionAlreadyDefined str -> raise(SameFunctionAlreadyDefined (str))
192
+ | SameFunctionConstructorsDefined str -> raise(SameFunctionConstructorsDefined (str))
193
+ | _ -> raise(ParentClassNotDefined (c.cparent.tid))
176
194
end
177
195
end
178
196
0 commit comments