1
1
open AST
2
2
open Hashtbl
3
3
4
-
4
+ exception ParentClassNotDefined of string
5
+ exception SameFunctionAlreadyDefined of string
5
6
6
7
type classDescriptor =
7
8
{
@@ -84,7 +85,7 @@ let printClassTable classTable =
84
85
*)
85
86
86
87
let addMethodsToMethodTable className methodTable cmethod =
87
- let nameMethod = className ^ " _" ^ cmethod.mname in
88
+ let nameMethod = className ^ " _" ^ cmethod.mname ^ " _ " ^ ( ListII. concat_map " , " stringOf_argType cmethod.margstype) in
88
89
if (verifyHashtbl methodTable nameMethod) = false
89
90
then begin
90
91
Hashtbl. add methodTable nameMethod cmethod
@@ -102,10 +103,12 @@ let addToMethodTable methodTable className c =
102
103
ulity: add methods, constructors,attributes in the Hashtbl classTable
103
104
*)
104
105
let addMethodsToClassDesciptor className methods cmethod =
105
- if (verifyHashtbl methods cmethod.mname) = false
106
+ let nameKey = cmethod.mname ^ " _" ^ (ListII. concat_map " ," stringOf_argType cmethod.margstype) in
107
+
108
+ if (verifyHashtbl methods nameKey) = false
106
109
then begin
107
- let nameMethod = className ^ " _" ^ cmethod.mname in
108
- Hashtbl. add methods cmethod.mname nameMethod
110
+ let nameMethod = className ^ " _" ^ cmethod.mname ^ " _ " ^ ( ListII. concat_map " , " stringOf_argType cmethod.margstype) in
111
+ Hashtbl. add methods nameKey nameMethod
109
112
end
110
113
else begin
111
114
print_endline(" function " ^ cmethod.mname ^ " already defined" )
@@ -155,9 +158,11 @@ let addToClassTable classTable className c =
155
158
(* asttype ={ mutable modifiers : modifier list; id : string; info : type_info;}
156
159
ulity: add class and methods in the Hashtbl
157
160
*)
158
- let rec findParentClass cname typelist = match typelist with
161
+ let rec findParentClass cname typelist =
162
+ match typelist with
159
163
| head ::liste -> if head.id = cname then head else findParentClass cname liste
160
164
165
+
161
166
let rec compileClass methodTable classTable ast asttype =
162
167
match asttype.info with
163
168
| Class c -> if (verifyHashtbl classTable asttype.id) = false
@@ -169,10 +174,13 @@ let rec compileClass methodTable classTable ast asttype =
169
174
end
170
175
else
171
176
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
177
+ try
178
+ let parenttype = findParentClass c.cparent.tid ast.type_list in
179
+ compileClass methodTable classTable ast parenttype;
180
+ addToClassTable classTable asttype.id c;
181
+ addToMethodTable methodTable asttype.id c;
182
+ with
183
+ | _ -> raise(ParentClassNotDefined (c.cparent.tid))
176
184
end
177
185
end
178
186
0 commit comments