File tree Expand file tree Collapse file tree 3 files changed +45
-5
lines changed Expand file tree Collapse file tree 3 files changed +45
-5
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ open Hashtbl
3
3
4
4
exception ParentClassNotDefined of string
5
5
exception SameFunctionAlreadyDefined of string
6
+ exception SameFunctionConstructorsDefined of string
6
7
7
8
type classDescriptor =
8
9
{
@@ -115,7 +116,14 @@ let addMethodsToClassDesciptor className methods cmethod =
115
116
end
116
117
117
118
let addConstructorsToClassDesciptor constructorsClass constructor =
118
- 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
119
127
120
128
let addMethodsToClassDesciptorFromParent classTable methodsClass c =
121
129
if (Hashtbl. mem classTable c.cparent.tid) = true
@@ -181,6 +189,7 @@ let rec compileClass methodTable classTable ast asttype =
181
189
addToMethodTable methodTable asttype.id c;
182
190
with
183
191
| SameFunctionAlreadyDefined str -> raise(SameFunctionAlreadyDefined (str))
192
+ | SameFunctionConstructorsDefined str -> raise(SameFunctionConstructorsDefined (str))
184
193
| _ -> raise(ParentClassNotDefined (c.cparent.tid))
185
194
end
186
195
end
Original file line number Diff line number Diff line change @@ -6,20 +6,35 @@ public void f1(){
6
6
class A {
7
7
8
8
int a = 5 ;
9
- Sttring b ="abc" ;
9
+ String b ="abc" ;
10
10
public void f1 (){
11
11
}
12
+
13
+ public void f1 (int b ,int c ){
14
+ }
15
+
16
+ public void f1 (int d ){
17
+ }
18
+
12
19
public void f2 (){
13
20
}
14
21
15
22
public A (int num )
16
23
{
17
- a = num ;
24
+ int a = num ;
18
25
}
19
26
20
- public A (int num ,String name )
27
+
28
+ public A (int num1 ,int num2 )
21
29
{
22
- a = num ;
30
+ int a = num ;
23
31
}
24
32
33
+
34
+ }
35
+
36
+
37
+
38
+ class C {
39
+
25
40
}
Original file line number Diff line number Diff line change @@ -10,17 +10,33 @@ class A {
10
10
public void f1 (){
11
11
}
12
12
13
+ //test same function exception
13
14
public void f1 (int b ){
14
15
}
15
16
16
17
public void f1 (int d ){
17
18
}
18
19
20
+ public void f1 (int d ,int c ){
21
+ }
22
+
23
+ //test constructor exception
19
24
public A (int num )
20
25
{
21
26
int a = num ;
22
27
}
23
28
29
+ public A (int num ,int b )
30
+ {
31
+ int a = num ;
32
+ }
33
+
34
+ public A (int num1 )
35
+ {
36
+ int a = num ;
37
+ }
38
+
39
+
24
40
25
41
}
26
42
You can’t perform that action at this time.
0 commit comments