Selaa lähdekoodia

- Added some java source generation optimizations

- Regenerated shared
Stan Hebben 6 vuotta sitten
vanhempi
commit
38eff3ce08

+ 13
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/OperatorMember.java Näytä tiedosto

9
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.Modifiers;
12
 import org.openzen.zenscript.codemodel.OperatorType;
13
 import org.openzen.zenscript.codemodel.OperatorType;
13
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
14
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
14
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
66
 	public <C, R> R accept(C context, MemberVisitorWithContext<C, R> visitor) {
67
 	public <C, R> R accept(C context, MemberVisitorWithContext<C, R> visitor) {
67
 		return visitor.visitOperator(context, this);
68
 		return visitor.visitOperator(context, this);
68
 	}
69
 	}
70
+	
71
+	@Override
72
+	public int getEffectiveModifiers() {
73
+		int result = super.getEffectiveModifiers();
74
+		if (overrides != null) {
75
+			if (overrides.getTarget().isPublic())
76
+				result |= Modifiers.PUBLIC;
77
+			if (overrides.getTarget().isProtected())
78
+				result |= Modifiers.PROTECTED;
79
+		}
80
+		return result;
81
+	}
69
 
82
 
70
 	@Override
83
 	@Override
71
 	public FunctionalMemberRef getOverrides() {
84
 	public FunctionalMemberRef getOverrides() {

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/BaseMemberCompiler.java Näytä tiedosto

74
 	}
74
 	}
75
 	
75
 	
76
 	protected void modifiers(int modifiers) {
76
 	protected void modifiers(int modifiers) {
77
-		if (Modifiers.isPublic(modifiers))
77
+		if (Modifiers.isPublic(modifiers) && !definition.isInterface())
78
 			output.append("public ");
78
 			output.append("public ");
79
 		if (Modifiers.isProtected(modifiers))
79
 		if (Modifiers.isProtected(modifiers))
80
 			output.append("protected ");
80
 			output.append("protected ");

+ 0
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java Näytä tiedosto

84
 		if (isInterface && method.name.equals("toString") && header.parameters.length == 0) {
84
 		if (isInterface && method.name.equals("toString") && header.parameters.length == 0) {
85
 			hasBody = false;
85
 			hasBody = false;
86
 		}
86
 		}
87
-			
88
 		
87
 		
89
 		begin(ElementType.METHOD);
88
 		begin(ElementType.METHOD);
90
 		override(member.getOverrides() != null);
89
 		override(member.getOverrides() != null);

+ 10
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java Näytä tiedosto

462
 	public ExpressionString visitGetter(GetterExpression expression) {
462
 	public ExpressionString visitGetter(GetterExpression expression) {
463
 		if (expression.getter.member.builtin != null)
463
 		if (expression.getter.member.builtin != null)
464
 			return visitBuiltinGetter(expression, expression.getter.member.builtin);
464
 			return visitBuiltinGetter(expression, expression.getter.member.builtin);
465
+		
466
+		ExpressionString target = expression.target.accept(this);
465
 		if (expression.getter.member.hasTag(JavaField.class)) {
467
 		if (expression.getter.member.hasTag(JavaField.class)) {
466
 			JavaField field = expression.getter.member.getTag(JavaField.class);
468
 			JavaField field = expression.getter.member.getTag(JavaField.class);
467
-			return expression.target.accept(this).unaryPostfix(JavaOperator.MEMBER, "." + field.name);
469
+			if (target.value.equals("this") && !scope.hasLocalVariable(field.name))
470
+				return new ExpressionString(field.name, JavaOperator.PRIMARY);
471
+			
472
+			return target.unaryPostfix(JavaOperator.MEMBER, "." + field.name);
468
 		}
473
 		}
469
 		
474
 		
470
 		JavaMethod method = expression.getter.getTag(JavaMethod.class);
475
 		JavaMethod method = expression.getter.getTag(JavaMethod.class);
471
 		StringBuilder result = new StringBuilder();
476
 		StringBuilder result = new StringBuilder();
472
-		result.append(expression.target.accept(this));
473
-		result.append(".");
477
+		if (!target.value.equals("this") || scope.hasLocalVariable(method.name)) {
478
+			result.append(target.value);
479
+			result.append(".");
480
+		}
474
 		result.append(method.name);
481
 		result.append(method.name);
475
 		result.append("()");
482
 		result.append("()");
476
 		return new ExpressionString(result.toString(), JavaOperator.MEMBER);
483
 		return new ExpressionString(result.toString(), JavaOperator.MEMBER);

+ 1
- 1
Shared/src/main/java/listeners/ListenerList.java Näytä tiedosto

46
     public void accept(Consumer<T> consumer) {
46
     public void accept(Consumer<T> consumer) {
47
         ListenerList<T>.EventListenerNode current = first;
47
         ListenerList<T>.EventListenerNode current = first;
48
         while (current != null) {
48
         while (current != null) {
49
-            consumer.accept(current.getListener());
49
+            consumer.accept(current.listener);
50
             current = current.next;
50
             current = current.next;
51
         }
51
         }
52
     }
52
     }

+ 2
- 2
Shared/src/main/java/live/LiveArrayList.java Näytä tiedosto

6
 import listeners.ListenerHandle;
6
 import listeners.ListenerHandle;
7
 import listeners.ListenerList;
7
 import listeners.ListenerList;
8
 
8
 
9
-final class LiveArrayList<T> implements MutableLiveList<T>, AutoCloseable {
9
+public final class LiveArrayList<T> implements MutableLiveList<T>, AutoCloseable {
10
     private final List<T> values = new ArrayList<T>();
10
     private final List<T> values = new ArrayList<T>();
11
     private final ListenerList<LiveList.Listener<T>> listeners = new ListenerList<LiveList.Listener<T>>();
11
     private final ListenerList<LiveList.Listener<T>> listeners = new ListenerList<LiveList.Listener<T>>();
12
     
12
     
50
     
50
     
51
     @Override
51
     @Override
52
     public void clear() {
52
     public void clear() {
53
-        int i = this.getLength();
53
+        int i = getLength();
54
         while (i > 0) {
54
         while (i > 0) {
55
             i--;
55
             i--;
56
             this.remove(i);
56
             this.remove(i);

+ 1
- 2
Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java Näytä tiedosto

4
     public static final CodePosition BUILTIN = new CodePosition(new VirtualSourceFile("builtin"), 0, 0, 0, 0);
4
     public static final CodePosition BUILTIN = new CodePosition(new VirtualSourceFile("builtin"), 0, 0, 0, 0);
5
     public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
5
     public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
6
     public static final CodePosition META = new CodePosition(new VirtualSourceFile("meta"), 0, 0, 0, 0);
6
     public static final CodePosition META = new CodePosition(new VirtualSourceFile("meta"), 0, 0, 0, 0);
7
-	public static final CodePosition UNKNOWN = new CodePosition(new VirtualSourceFile("unknown"), 0, 0, 0, 0);
8
-
7
+    public static final CodePosition UNKNOWN = new CodePosition(new VirtualSourceFile("unknown"), 0, 0, 0, 0);
9
     public final SourceFile file;
8
     public final SourceFile file;
10
     public final int fromLine;
9
     public final int fromLine;
11
     public final int fromLineOffset;
10
     public final int fromLineOffset;

+ 1
- 1
Shared/src/main/java/stdlib/Integers.java Näytä tiedosto

1
 package stdlib;
1
 package stdlib;
2
 
2
 
3
-final class Integers {
3
+public final class Integers {
4
     private Integers() {}
4
     private Integers() {}
5
 }
5
 }

+ 1
- 1
Shared/src/main/java/stdlib/USize.java Näytä tiedosto

1
 package stdlib;
1
 package stdlib;
2
 
2
 
3
-final class USize {
3
+public final class USize {
4
     private USize() {}
4
     private USize() {}
5
 }
5
 }

Loading…
Peruuta
Tallenna