8
8
import Syntax .Type ;
9
9
10
10
import java .lang .reflect .InvocationTargetException ;
11
- import java .util .ArrayList ;
12
- import java .util .Arrays ;
13
- import java .util .Collections ;
14
- import java .util .HashMap ;
11
+ import java .util .*;
15
12
16
13
public class DefinedFunction {
17
14
private static final ParamDeclaration intParam = new ParamDeclaration (Type .INT , "dummy" );
@@ -20,15 +17,24 @@ public class DefinedFunction {
20
17
private static final ParamDeclaration charParam = new ParamDeclaration (Type .CHAR , "dummy" );
21
18
private static final ParamDeclaration dateParam = new ParamDeclaration (Type .DATE , "dummy" );
22
19
private static final ParamDeclaration timeParam = new ParamDeclaration (Type .TIME , "dummy" );
20
+
23
21
private static FunctionSet functionSet ;
24
22
private static HashMap <String , ArrayList <FunctionInfo >> overloadMap ;
25
23
26
- public static final ArrayList <String > predefinedFunc = new ArrayList <>(Arrays .asList (
27
- "write" , "read" , "lf" , "getHour" , "getMin" , "getSec" , "getYear" , "getMonth" , "getDay" ,
28
- "addTime" , "addDate" , "subTime" , "subDate" , "mulTime" , "divTime" , "modTime" ,
29
- "validTime" , "validDate" ,
30
- "addFloat" , "subFloat" , "mulFloat" , "divFloat" , "modFloat"
31
- ));
24
+ private static final String [] UCodeFunction = {
25
+ "write" , "read" , "lf" , "addFloat" , "subFloat" ,
26
+ "mulFloat" , "divFloat" , "modFloat" , "negFloat" , "F2I" , "I2F" ,
27
+ "writeF" , "writeC" , "writeT" , "writeD"
28
+ };
29
+
30
+ private static final String [] customFunc = {
31
+ "getHour" , "getMin" , "getSec" , "getYear" , "getMonth" , "getDay" ,
32
+ "addTime" , "subTime" , "mulTime" , "divTime" , "modTime" ,
33
+ "addDate" , "subDate" ,
34
+ "validTime"
35
+ };
36
+
37
+ public static final HashSet <String > predefinedFunc = new HashSet <>(Arrays .asList (customFunc ));
32
38
33
39
public static void defineFunc (FunctionSet functionSet , HashMap <String , ArrayList <FunctionInfo >> overloadMap ) {
34
40
DefinedFunction .functionSet = functionSet ;
@@ -39,16 +45,17 @@ public static void defineFunc(FunctionSet functionSet, HashMap<String, ArrayList
39
45
createFunc (Type .VOID , "write" , charParam );
40
46
createFunc (Type .VOID , "write" , dateParam );
41
47
createFunc (Type .VOID , "write" , timeParam );
48
+ createFunc (Type .VOID , "write" , floatParam );
42
49
createFunc (Type .INT , "read" , intParam );
43
50
createFunc (Type .VOID , "lf" );
44
-
51
+
45
52
createFunc (Type .INT , "getHour" , timeParam );
46
53
createFunc (Type .INT , "getMin" , timeParam );
47
54
createFunc (Type .INT , "getSec" , timeParam );
48
55
createFunc (Type .INT , "getYear" , dateParam );
49
56
createFunc (Type .INT , "getMonth" , dateParam );
50
57
createFunc (Type .INT , "getDay" , dateParam );
51
-
58
+
52
59
createFunc (Type .TIME , "addTime" , timeParam , timeParam );
53
60
createFunc (Type .TIME , "subTime" , timeParam , timeParam );
54
61
createFunc (Type .TIME , "mulTime" , timeParam , intParam );
@@ -58,7 +65,6 @@ public static void defineFunc(FunctionSet functionSet, HashMap<String, ArrayList
58
65
59
66
createFunc (Type .DATE , "addDate" , dateParam , dateParam );
60
67
createFunc (Type .DATE , "subDate" , dateParam , dateParam );
61
- createFunc (Type .DATE , "validDate" , dateParam );
62
68
}
63
69
64
70
private static void createFunc (Type type , String name , ParamDeclaration ... params ) {
@@ -190,7 +196,7 @@ protected static void mulTime() {
190
196
CodeGenerator .genCode ("ldp" );
191
197
CodeGenerator .genCode ("lod" , 2 , 1 );
192
198
CodeGenerator .genCode ("lod" , 2 , 2 );
193
- CodeGenerator .genCode ("multi " );
199
+ CodeGenerator .genCode ("mult " );
194
200
CodeGenerator .call ("validTime" );
195
201
196
202
CodeGenerator .genCode ("retv" );
@@ -244,18 +250,28 @@ protected static void validTime() {
244
250
245
251
protected static void addDate () {
246
252
// todo
247
- }
253
+ CodeGenerator .genFunc ("addDate" , 2 , 2 , 2 );
254
+ CodeGenerator .genCode ("sym" , 2 , 1 , 1 );
255
+ CodeGenerator .genCode ("sym" , 2 , 2 , 1 );
248
256
249
- protected static void subDate () {
250
- // todo
257
+ CodeGenerator .genCode ("lod" , 2 , 1 );
258
+ CodeGenerator .genCode ("lod" , 2 , 2 );
259
+ CodeGenerator .genCode ("add" );
260
+
261
+ CodeGenerator .call ("validDate" );
262
+
263
+ CodeGenerator .genCode ("end" );
251
264
}
252
265
253
- protected static void validDate () {
266
+ protected static void subDate () {
254
267
// todo
255
- CodeGenerator .genFunc ("validDate " , 1 , 2 , 2 );
268
+ CodeGenerator .genFunc ("addDate " , 2 , 2 , 2 );
256
269
CodeGenerator .genCode ("sym" , 2 , 1 , 1 );
270
+ CodeGenerator .genCode ("sym" , 2 , 2 , 1 );
257
271
258
272
CodeGenerator .genCode ("lod" , 2 , 1 );
273
+ CodeGenerator .genCode ("lod" , 2 , 2 );
274
+ CodeGenerator .genCode ("sub" );
259
275
260
276
CodeGenerator .genCode ("retv" );
261
277
CodeGenerator .genCode ("end" );
0 commit comments