Просмотр исходного кода

- Added some java source generation optimizations

- Regenerated shared
Stan Hebben 6 лет назад
Родитель
Сommit
38eff3ce08

+ 13
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/OperatorMember.java Просмотреть файл

@@ -9,6 +9,7 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.Modifiers;
12 13
 import org.openzen.zenscript.codemodel.OperatorType;
13 14
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
14 15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
@@ -66,6 +67,18 @@ public class OperatorMember extends FunctionalMember {
66 67
 	public <C, R> R accept(C context, MemberVisitorWithContext<C, R> visitor) {
67 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 83
 	@Override
71 84
 	public FunctionalMemberRef getOverrides() {

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/BaseMemberCompiler.java Просмотреть файл

@@ -74,7 +74,7 @@ public abstract class BaseMemberCompiler implements MemberVisitor<Void> {
74 74
 	}
75 75
 	
76 76
 	protected void modifiers(int modifiers) {
77
-		if (Modifiers.isPublic(modifiers))
77
+		if (Modifiers.isPublic(modifiers) && !definition.isInterface())
78 78
 			output.append("public ");
79 79
 		if (Modifiers.isProtected(modifiers))
80 80
 			output.append("protected ");

+ 0
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java Просмотреть файл

@@ -84,7 +84,6 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
84 84
 		if (isInterface && method.name.equals("toString") && header.parameters.length == 0) {
85 85
 			hasBody = false;
86 86
 		}
87
-			
88 87
 		
89 88
 		begin(ElementType.METHOD);
90 89
 		override(member.getOverrides() != null);

+ 10
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java Просмотреть файл

@@ -462,15 +462,22 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
462 462
 	public ExpressionString visitGetter(GetterExpression expression) {
463 463
 		if (expression.getter.member.builtin != null)
464 464
 			return visitBuiltinGetter(expression, expression.getter.member.builtin);
465
+		
466
+		ExpressionString target = expression.target.accept(this);
465 467
 		if (expression.getter.member.hasTag(JavaField.class)) {
466 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 475
 		JavaMethod method = expression.getter.getTag(JavaMethod.class);
471 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 481
 		result.append(method.name);
475 482
 		result.append("()");
476 483
 		return new ExpressionString(result.toString(), JavaOperator.MEMBER);

+ 1
- 1
Shared/src/main/java/listeners/ListenerList.java Просмотреть файл

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

+ 2
- 2
Shared/src/main/java/live/LiveArrayList.java Просмотреть файл

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

+ 1
- 2
Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java Просмотреть файл

@@ -4,8 +4,7 @@ public final class CodePosition {
4 4
     public static final CodePosition BUILTIN = new CodePosition(new VirtualSourceFile("builtin"), 0, 0, 0, 0);
5 5
     public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
6 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 8
     public final SourceFile file;
10 9
     public final int fromLine;
11 10
     public final int fromLineOffset;

+ 1
- 1
Shared/src/main/java/stdlib/Integers.java Просмотреть файл

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

+ 1
- 1
Shared/src/main/java/stdlib/USize.java Просмотреть файл

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

Загрузка…
Отмена
Сохранить