Skip to content

Commit 33ec109

Browse files
committed
重构Fel类
add方法在编译时支持未知类型的参数 解决\n等转义字符带来的问题 加入print函数
1 parent e1d439f commit 33ec109

26 files changed

+611
-387
lines changed

Fel.g

Lines changed: 321 additions & 312 deletions
Large diffs are not rendered by default.

src/main/com/greenpineyu/fel/common/FelBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static SecurityMgr newSecurityMgr() {
4747

4848
public static EventMgr newEventMgr(){
4949
EventMgr mgr = new EventMgr();
50-
mgr.addListener(new EventListener<Event>() {
50+
/* mgr.addListener(new EventListener<Event>() {
5151
5252
@Override
5353
public Object onEvent(Event event) {
@@ -58,7 +58,7 @@ public Object onEvent(Event event) {
5858
public String getId() {
5959
return Events.UNDEFINED_VARIABLE;
6060
}
61-
});
61+
});*/
6262
return mgr;
6363
}
6464

src/main/com/greenpineyu/fel/common/Null.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/main/com/greenpineyu/fel/common/NumberUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public static <T extends Comparable<T>> int compare(T a,T b){
417417
* @param obj
418418
* @return
419419
*/
420-
public static Object calArray(Object obj) {
420+
/* public static Object calArray(Object obj) {
421421
if (!(obj instanceof Object[]))
422422
return obj;
423423
@@ -428,7 +428,7 @@ public static Object calArray(Object obj) {
428428
}
429429
}
430430
return result;
431-
}
431+
}*/
432432

433433

434434
/**

src/main/com/greenpineyu/fel/common/ObjectUtils.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.greenpineyu.fel.common;
22

3+
import com.greenpineyu.fel.compile.SourceBuilder;
4+
35

46
public class ObjectUtils {
57
/**
@@ -49,7 +51,9 @@ public static boolean equals(Object object1, Object object2) {
4951
* @since 2.0
5052
*/
5153
public static String toString(Object obj) {
52-
return obj == null ? "" : obj.toString();
54+
//return obj == null ? "" : obj.toString();
55+
//modify by yqs
56+
return obj == null ? "null" : obj.toString();
5357
}
5458

5559
/**
@@ -74,4 +78,10 @@ public static String toString(Object obj) {
7478
public static boolean notEqual(Object object1, Object object2) {
7579
return ObjectUtils.equals(object1, object2) == false;
7680
}
81+
82+
//append by yqs
83+
static public Object print(Object arg){
84+
System.out.print(arg);
85+
return SourceBuilder.VOID;
86+
}
7787
}

src/main/com/greenpineyu/fel/common/ReflectUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.util.HashMap;
55
import java.util.Map;
66

7+
import com.greenpineyu.fel.context.FelContext;
8+
79
public class ReflectUtil {
810

911
/**
@@ -220,7 +222,7 @@ private static Method match(String methodName, Class<?>[] paramValueTypes,
220222
}
221223

222224
public static boolean isTypeMatch(Class<?> c1,Class<?> c2){
223-
if(c1 == c2||c2==Null.class){
225+
if(c1 == c2||c2==FelContext.NULL.getClass()){
224226
//当c2为Null.class时,表示参数值是null,null值可以与任何类型匹配类型
225227
return true;
226228
}

src/main/com/greenpineyu/fel/compile/CompileService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public Expression compile(FelContext ctx, FelNode node, String originalExp) {
102102
ConstExpSrc s = (ConstExpSrc) src;
103103
return s.getValue();
104104
}
105-
src.setSource("// 表达式:" + originalExp + "\n" + src.getSource());
105+
src.setSource("/*表达式:" + originalExp + "*/\n" + src.getSource());
106106
// System.out.println("****************\n" + src.getSource());
107107
return complier.compile(src);
108108
} catch (Exception e) {

src/main/com/greenpineyu/fel/compile/FelMethod.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ public class FelMethod implements SourceBuilder {
1111
private Class<?> returnType;
1212

1313
private String code;
14+
15+
/**
16+
* 类型是否VOID
17+
* @param c
18+
* @return
19+
*/
20+
public static boolean isVoidType(Class<?> c){
21+
return c == VOID.getClass();
22+
}
23+
24+
/**
25+
* 对象是否VOID
26+
* @param obj
27+
* @return
28+
*/
29+
public static boolean isVoid(Object obj){
30+
return obj == VOID;
31+
}
1432

1533

1634
public FelMethod(Class<?> returnType,String code){
@@ -37,6 +55,7 @@ public String source(FelContext ctx, FelNode node) {
3755
public void setCode(String code) {
3856
this.code = code;
3957
}
58+
4059

4160

4261
}

src/main/com/greenpineyu/fel/compile/InterpreterSourceBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public String source(FelContext ctx, FelNode node) {
4141
Interpreter inte = node.getInterpreter();
4242
SourceBuilder nodeBuilder = node.toMethod(ctx);
4343
Class<?> type =nodeBuilder.returnType(ctx, node);
44+
if(type == FelContext.NOT_FOUND_TYPE){
45+
type = Object.class;
46+
}
4447
String code = "("+type.getName()+")";
4548
String varName = VarBuffer.push(inte,Interpreter.class);
4649
String nodeVarName = VarBuffer.push(node, FelNode.class);

src/main/com/greenpineyu/fel/compile/SourceBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
*/
1111
public interface SourceBuilder {
1212

13+
/**
14+
* 返回void类型
15+
*/
16+
Object VOID=new Object(){};
17+
1318
/**
1419
* 类型
1520
* @param ctx TODO

0 commit comments

Comments
 (0)