11open AST
22open Hashtbl
33
4-
4+ exception ParentClassNotDefined of string
5+ exception SameFunctionAlreadyDefined of string
56
67type classDescriptor =
78{
@@ -84,7 +85,7 @@ let printClassTable classTable =
8485*)
8586
8687let 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
8889 if (verifyHashtbl methodTable nameMethod) = false
8990 then begin
9091 Hashtbl. add methodTable nameMethod cmethod
@@ -102,10 +103,12 @@ let addToMethodTable methodTable className c =
102103 ulity: add methods, constructors,attributes in the Hashtbl classTable
103104*)
104105let 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
106109 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
109112 end
110113 else begin
111114 print_endline(" function " ^ cmethod.mname ^ " already defined" )
@@ -155,9 +158,11 @@ let addToClassTable classTable className c =
155158(* asttype ={ mutable modifiers : modifier list; id : string; info : type_info;}
156159ulity: add class and methods in the Hashtbl
157160*)
158- let rec findParentClass cname typelist = match typelist with
161+ let rec findParentClass cname typelist =
162+ match typelist with
159163 | head ::liste -> if head.id = cname then head else findParentClass cname liste
160164
165+
161166let rec compileClass methodTable classTable ast asttype =
162167 match asttype.info with
163168 | Class c -> if (verifyHashtbl classTable asttype.id) = false
@@ -169,10 +174,13 @@ let rec compileClass methodTable classTable ast asttype =
169174 end
170175 else
171176 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))
176184 end
177185 end
178186
0 commit comments