Quellcode durchsuchen

- Function and method bodies are now single statements (which can, of course, be a BlockStatement), this simplifies code

- Function parameters are taggable, and Java parameter indices are now tagged on these parameters
- Improved constructor forwarding code
- Added handling for potential situations where multiple code blocks exist for the same script file (this can happen in generated code)
- Continue WIP on code formatting for definitions
Stan Hebben vor 6 Jahren
Ursprung
Commit
6d97220a92
33 geänderte Dateien mit 716 neuen und 332 gelöschten Zeilen
  1. 22
    3
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/DefinitionFormatter.java
  2. 24
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingSettings.java
  3. 178
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java
  4. 197
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java
  5. 1
    48
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java
  6. 0
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  7. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionParameter.java
  8. 11
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java
  9. 4
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java
  10. 3
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/FunctionExpression.java
  11. 19
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java
  12. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CustomIteratorMember.java
  13. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java
  14. 0
    12
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/Statement.java
  15. 7
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaClassInfo.java
  16. 5
    3
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  17. 0
    11
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaEnumInfo.java
  18. 18
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaParameterInfo.java
  19. 28
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java
  20. 16
    6
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  21. 31
    30
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  22. 14
    3
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  23. 58
    103
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java
  24. 44
    36
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java
  25. 2
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java
  26. 3
    4
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedEmptyFunctionBody.java
  27. 1
    2
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedFunctionBody.java
  28. 3
    8
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedLambdaFunctionBody.java
  29. 4
    2
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatement.java
  30. 5
    9
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementsFunctionBody.java
  31. 1
    0
      Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java
  32. 10
    24
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java
  33. 1
    4
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java

+ 22
- 3
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/DefinitionFormatter.java Datei anzeigen

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
13 13
 import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
14 14
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
15 15
 import org.openzen.zenscript.codemodel.definition.StructDefinition;
16
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
16 17
 
17 18
 /**
18 19
  *
@@ -35,20 +36,33 @@ public class DefinitionFormatter implements DefinitionVisitor<Void> {
35 36
 		FormattingUtils.formatModifiers(output, definition.modifiers);
36 37
 		output.append("class ");
37 38
 		output.append(definition.name);
38
-		if (definition.genericParameters.length > 0) {
39
-			
40
-		}
39
+		FormattingUtils.formatTypeParameters(output, definition.genericParameters, typeFormatter);
41 40
 		output.append(" ");
42 41
 		if (definition.superType != null) {
43 42
 			output.append("extends ");
44 43
 			output.append(definition.superType.accept(typeFormatter));
45 44
 			output.append(" ");
46 45
 		}
46
+		if (settings.classBracketOnSameLine) {
47
+			output.append("{\n");
48
+		} else {
49
+			output.append("\n")
50
+					.append(indent)
51
+					.append("{\n")
52
+					.append(indent + settings.indent);
53
+		}
54
+		
55
+		for (IDefinitionMember member : definition.members) {
56
+			member.accept(new MemberFormatter(settings, output, indent + settings.indent, typeFormatter));
57
+		}
58
+		
59
+		output.append("}\n");
47 60
 		return null;
48 61
 	}
49 62
 
50 63
 	@Override
51 64
 	public Void visitInterface(InterfaceDefinition definition) {
65
+		
52 66
 		return null;
53 67
 	}
54 68
 
@@ -64,6 +78,11 @@ public class DefinitionFormatter implements DefinitionVisitor<Void> {
64 78
 
65 79
 	@Override
66 80
 	public Void visitFunction(FunctionDefinition definition) {
81
+		FormattingUtils.formatModifiers(output, definition.modifiers);
82
+		output.append("function ");
83
+		output.append(definition.name);
84
+		FormattingUtils.formatHeader(output, settings, definition.header, typeFormatter);
85
+		FormattingUtils.formatBody(output, settings, indent, typeFormatter, definition.statement);
67 86
 		return null;
68 87
 	}
69 88
 

+ 24
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingSettings.java Datei anzeigen

@@ -33,6 +33,9 @@ public class FormattingSettings {
33 33
 	public final boolean loopBracketOnSameLine;
34 34
 	public final boolean tryCatchNewLine; // new line between } and catch or } and finally
35 35
 	public final boolean tryCatchBracketOnSameLine;
36
+	public final boolean classBracketOnSameLine;
37
+	public final boolean functionBracketOnSameLine;
38
+	public final boolean lambdaMethodOnSameLine;
36 39
 	
37 40
 	public final String indent;
38 41
 	
@@ -58,6 +61,9 @@ public class FormattingSettings {
58 61
 		loopBracketOnSameLine = builder.loopBracketOnSameLine;
59 62
 		tryCatchNewLine = builder.tryCatchNewLine;
60 63
 		tryCatchBracketOnSameLine = builder.tryCatchBracketOnSameLine;
64
+		classBracketOnSameLine = builder.classBracketOnSameLine;
65
+		functionBracketOnSameLine = builder.functionBracketOnSameLine;
66
+		lambdaMethodOnSameLine = builder.lambdaMethodOnSameLine;
61 67
 		
62 68
 		if (useTabs) {
63 69
 			indent = "\t";
@@ -159,6 +165,9 @@ public class FormattingSettings {
159 165
 		private boolean loopBracketOnSameLine = true;
160 166
 		private boolean tryCatchNewLine = true;
161 167
 		private boolean tryCatchBracketOnSameLine = true;
168
+		private boolean classBracketOnSameLine = false;
169
+		private boolean functionBracketOnSameLine = false;
170
+		private boolean lambdaMethodOnSameLine = false;
162 171
 		
163 172
 		public Builder showAnyInFunctionHeaders(boolean show) {
164 173
 			showAnyInFunctionHeaders = show;
@@ -265,6 +274,21 @@ public class FormattingSettings {
265 274
 			return this;
266 275
 		}
267 276
 		
277
+		public Builder classBracketOnSameLine(boolean sameLine) {
278
+			classBracketOnSameLine = sameLine;
279
+			return this;
280
+		}
281
+		
282
+		public Builder functionBracketOnSameLine(boolean sameLine) {
283
+			functionBracketOnSameLine = sameLine;
284
+			return this;
285
+		}
286
+		
287
+		public Builder lambdaMethodOnSameLine(boolean sameLine) {
288
+			lambdaMethodOnSameLine = sameLine;
289
+			return this;
290
+		}
291
+		
268 292
 		public FormattingSettings build() {
269 293
 			return new FormattingSettings(this);
270 294
 		}

+ 178
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java Datei anzeigen

@@ -5,7 +5,28 @@
5 5
  */
6 6
 package org.openzen.zenscript.formatter;
7 7
 
8
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
+import org.openzen.zenscript.codemodel.FunctionParameter;
8 10
 import org.openzen.zenscript.codemodel.Modifiers;
11
+import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
12
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
+import org.openzen.zenscript.codemodel.statement.BlockStatement;
14
+import org.openzen.zenscript.codemodel.statement.BreakStatement;
15
+import org.openzen.zenscript.codemodel.statement.ContinueStatement;
16
+import org.openzen.zenscript.codemodel.statement.DoWhileStatement;
17
+import org.openzen.zenscript.codemodel.statement.EmptyStatement;
18
+import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
19
+import org.openzen.zenscript.codemodel.statement.ForeachStatement;
20
+import org.openzen.zenscript.codemodel.statement.IfStatement;
21
+import org.openzen.zenscript.codemodel.statement.LockStatement;
22
+import org.openzen.zenscript.codemodel.statement.ReturnStatement;
23
+import org.openzen.zenscript.codemodel.statement.Statement;
24
+import org.openzen.zenscript.codemodel.statement.StatementVisitor;
25
+import org.openzen.zenscript.codemodel.statement.ThrowStatement;
26
+import org.openzen.zenscript.codemodel.statement.TryCatchStatement;
27
+import org.openzen.zenscript.codemodel.statement.VarStatement;
28
+import org.openzen.zenscript.codemodel.statement.WhileStatement;
29
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9 30
 
10 31
 /**
11 32
  *
@@ -40,4 +61,161 @@ public class FormattingUtils {
40 61
 		if (Modifiers.isConstOptional(modifiers))
41 62
 			output.append("const? ");
42 63
 	}
64
+	
65
+	public static void formatHeader(StringBuilder result, FormattingSettings settings, FunctionHeader header, TypeFormatter typeFormatter) {
66
+		FormattingUtils.formatTypeParameters(result, header.typeParameters, typeFormatter);
67
+		result.append("(");
68
+		int parameterIndex = 0;
69
+		for (FunctionParameter parameter : header.parameters) {
70
+			if (parameterIndex > 0)
71
+				result.append(", ");
72
+			
73
+			result.append(parameter.name);
74
+			if (parameter.variadic)
75
+				result.append("...");
76
+			
77
+			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.ANY) {
78
+				result.append(" as ");
79
+				result.append(header.returnType.accept(typeFormatter));
80
+			}
81
+			
82
+			parameterIndex++;
83
+		}
84
+		result.append(")");
85
+		if (!settings.showAnyInFunctionHeaders || header.returnType != BasicTypeID.ANY) {
86
+			result.append(" as ");
87
+			result.append(header.returnType.accept(typeFormatter));
88
+		}
89
+	}
90
+	
91
+	public static void formatTypeParameters(StringBuilder result, TypeParameter[] parameters, TypeFormatter typeFormatter) {
92
+		if (parameters.length > 0) {
93
+			result.append("<");
94
+			int index = 0;
95
+			for (TypeParameter parameter : parameters) {
96
+				if (index > 0)
97
+					result.append(", ");
98
+				
99
+				result.append(parameter.name);
100
+				
101
+				if (parameter.bounds.size() > 0) {
102
+					for (GenericParameterBound bound : parameter.bounds) {
103
+						result.append(": ");
104
+						result.append(bound.accept(typeFormatter));
105
+					}
106
+				}
107
+				
108
+				index++;
109
+			}
110
+			result.append(">");
111
+		}
112
+	}
113
+	
114
+	public static void formatBody(StringBuilder output, FormattingSettings settings, String indent, TypeFormatter typeFormatter, Statement body) {
115
+		body.accept(new BodyFormatter(output, settings, indent, typeFormatter));
116
+	}
117
+	
118
+	private static class BodyFormatter implements StatementVisitor<Void> {
119
+		private final StringBuilder output;
120
+		private final FormattingSettings settings;
121
+		private final StatementFormatter statementFormatter;
122
+		private final String indent;
123
+		private final TypeFormatter typeFormatter;
124
+		
125
+		public BodyFormatter(StringBuilder output, FormattingSettings settings, String indent, TypeFormatter typeFormatter) {
126
+			this.output = output;
127
+			this.settings = settings;
128
+			this.indent = indent;
129
+			this.typeFormatter = typeFormatter;
130
+			
131
+			statementFormatter = new StatementFormatter(indent + settings.indent, settings, new ExpressionFormatter(settings, typeFormatter)); 
132
+		}
133
+
134
+		@Override
135
+		public Void visitBlock(BlockStatement statement) {
136
+			return statementFormatter.visitBlock(statement);
137
+		}
138
+
139
+		@Override
140
+		public Void visitBreak(BreakStatement statement) {
141
+			return statementFormatter.visitBreak(statement);
142
+		}
143
+
144
+		@Override
145
+		public Void visitContinue(ContinueStatement statement) {
146
+			return statementFormatter.visitContinue(statement);
147
+		}
148
+
149
+		@Override
150
+		public Void visitDoWhile(DoWhileStatement statement) {
151
+			return statementFormatter.visitDoWhile(statement);
152
+		}
153
+
154
+		@Override
155
+		public Void visitEmpty(EmptyStatement statement) {
156
+			output.append(";\n");
157
+			return null;
158
+		}
159
+
160
+		@Override
161
+		public Void visitExpression(ExpressionStatement statement) {
162
+			if (settings.lambdaMethodOnSameLine) {
163
+				output.append(" => ");
164
+			} else {
165
+				output.append("\n").append(indent).append(settings.indent).append("=> ");
166
+			}
167
+			
168
+			output.append(statement.expression.accept(new ExpressionFormatter(settings, typeFormatter)));
169
+			output.append(";");
170
+			return null;
171
+		}
172
+
173
+		@Override
174
+		public Void visitForeach(ForeachStatement statement) {
175
+			return statementFormatter.visitForeach(statement);
176
+		}
177
+
178
+		@Override
179
+		public Void visitIf(IfStatement statement) {
180
+			return statementFormatter.visitIf(statement);
181
+		}
182
+
183
+		@Override
184
+		public Void visitLock(LockStatement statement) {
185
+			return statementFormatter.visitLock(statement);
186
+		}
187
+
188
+		@Override
189
+		public Void visitReturn(ReturnStatement statement) {
190
+			if (settings.lambdaMethodOnSameLine) {
191
+				output.append(" => ");
192
+			} else {
193
+				output.append("\n").append(indent).append(settings.indent).append("=> ");
194
+			}
195
+			
196
+			output.append(statement.value.accept(new ExpressionFormatter(settings, typeFormatter)));
197
+			output.append(";");
198
+			return null;
199
+		}
200
+
201
+		@Override
202
+		public Void visitThrow(ThrowStatement statement) {
203
+			return statementFormatter.visitThrow(statement);
204
+		}
205
+
206
+		@Override
207
+		public Void visitTryCatch(TryCatchStatement statement) {
208
+			return statementFormatter.visitTryCatch(statement);
209
+		}
210
+
211
+		@Override
212
+		public Void visitVar(VarStatement statement) {
213
+			return statementFormatter.visitVar(statement);
214
+		}
215
+
216
+		@Override
217
+		public Void visitWhile(WhileStatement statement) {
218
+			return statementFormatter.visitWhile(statement);
219
+		}
220
+	}
43 221
 }

+ 197
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java Datei anzeigen

@@ -0,0 +1,197 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.formatter;
7
+
8
+import java.util.List;
9
+import org.openzen.zenscript.codemodel.Modifiers;
10
+import org.openzen.zenscript.codemodel.member.CallerMember;
11
+import org.openzen.zenscript.codemodel.member.CasterMember;
12
+import org.openzen.zenscript.codemodel.member.ConstructorMember;
13
+import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
14
+import org.openzen.zenscript.codemodel.member.EnumConstantMember;
15
+import org.openzen.zenscript.codemodel.member.FieldMember;
16
+import org.openzen.zenscript.codemodel.member.GetterMember;
17
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
18
+import org.openzen.zenscript.codemodel.member.ImplementationMember;
19
+import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
20
+import org.openzen.zenscript.codemodel.member.MemberVisitor;
21
+import org.openzen.zenscript.codemodel.member.MethodMember;
22
+import org.openzen.zenscript.codemodel.member.OperatorMember;
23
+import org.openzen.zenscript.codemodel.member.SetterMember;
24
+import org.openzen.zenscript.codemodel.statement.ReturnStatement;
25
+import org.openzen.zenscript.codemodel.statement.Statement;
26
+
27
+/**
28
+ *
29
+ * @author Hoofdgebruiker
30
+ */
31
+public class MemberFormatter implements MemberVisitor<Void> {
32
+	private final FormattingSettings settings;
33
+	private final StringBuilder output;
34
+	private final String indent;
35
+	private final TypeFormatter typeFormatter;
36
+	
37
+	public MemberFormatter(FormattingSettings settings, StringBuilder output, String indent, TypeFormatter typeFormatter) {
38
+		this.settings = settings;
39
+		this.output = output;
40
+		this.indent = indent;
41
+		this.typeFormatter = typeFormatter;
42
+	}
43
+
44
+	@Override
45
+	public Void visitField(FieldMember member) {
46
+		FormattingUtils.formatModifiers(output, member.modifiers & ~Modifiers.FINAL);
47
+		output.append(member.isFinal() ? "val " : "var ")
48
+				.append(member.name)
49
+				.append(" as ")
50
+				.append(member.type.accept(typeFormatter));
51
+		
52
+		if (member.initializer != null) {
53
+			output.append(" = ")
54
+					.append(member.initializer.accept(new ExpressionFormatter(settings, typeFormatter)));
55
+		}
56
+		output.append(";").append("\n").append(indent);
57
+		return null;
58
+	}
59
+
60
+	@Override
61
+	public Void visitConstructor(ConstructorMember member) {
62
+		FormattingUtils.formatModifiers(output, member.modifiers & ~Modifiers.FINAL);
63
+		output.append("this");
64
+		FormattingUtils.formatHeader(output, settings, member.header, typeFormatter);
65
+		formatBody(member.body);
66
+		return null;
67
+	}
68
+
69
+	@Override
70
+	public Void visitMethod(MethodMember member) {
71
+		FormattingUtils.formatModifiers(output, member.modifiers & ~Modifiers.FINAL);
72
+		output.append(member.name);
73
+		FormattingUtils.formatHeader(output, settings, member.header, typeFormatter);
74
+		formatBody(member.body);
75
+		return null;
76
+	}
77
+
78
+	@Override
79
+	public Void visitGetter(GetterMember member) {
80
+		FormattingUtils.formatModifiers(output, member.modifiers & ~Modifiers.FINAL);
81
+		output.append("get ");
82
+		output.append(member.name);
83
+		output.append(" as ");
84
+		output.append(member.type.accept(typeFormatter));
85
+		formatBody(member.body);
86
+		return null;
87
+	}
88
+
89
+	@Override
90
+	public Void visitSetter(SetterMember member) {
91
+		FormattingUtils.formatModifiers(output, member.modifiers & ~Modifiers.FINAL);
92
+		output.append("set ");
93
+		output.append(member.name);
94
+		output.append(" as ");
95
+		output.append(member.type.accept(typeFormatter));
96
+		formatBody(member.body);
97
+		return null;
98
+	}
99
+
100
+	@Override
101
+	public Void visitEnumConstant(EnumConstantMember member) {
102
+		return null; // TODO: handle separately
103
+	}
104
+
105
+	@Override
106
+	public Void visitOperator(OperatorMember member) {
107
+		FormattingUtils.formatModifiers(output, member.modifiers & ~Modifiers.FINAL);
108
+		switch (member.operator) {
109
+			case ADD: output.append("+"); break;
110
+			case SUB: output.append("-"); break;
111
+			case MUL: output.append("*"); break;
112
+			case DIV: output.append("/"); break;
113
+			case MOD: output.append("%"); break;
114
+			case CAT: output.append("~"); break;
115
+			case OR: output.append("|"); break;
116
+			case AND: output.append("&"); break;
117
+			case XOR: output.append("^"); break;
118
+			case NEG: output.append("-"); break;
119
+			case NOT: output.append("!"); break;
120
+			case INDEXSET: output.append("[]="); break;
121
+			case INDEXGET: output.append("[]"); break;
122
+			case CONTAINS: output.append("in"); break;
123
+			case MEMBERGETTER: output.append("."); break;
124
+			case MEMBERSETTER: output.append(".="); break;
125
+			case EQUALS: output.append("=="); break;
126
+			case ADDASSIGN: output.append("+="); break;
127
+			case SUBASSIGN: output.append("-="); break;
128
+			case MULASSIGN: output.append("*="); break;
129
+			case DIVASSIGN: output.append("/="); break;
130
+			case MODASSIGN: output.append("%="); break;
131
+			case CATASSIGN: output.append("~="); break;
132
+			case ORASSIGN: output.append("|="); break;
133
+			case ANDASSIGN: output.append("&="); break;
134
+			case XORASSIGN: output.append("^="); break;
135
+	
136
+			case POST_INCREMENT: output.append("++"); break;
137
+			case POST_DECREMENT: output.append("--"); break;
138
+			default:
139
+				throw new UnsupportedOperationException("Unknown operator: " + member.operator);
140
+		}
141
+		FormattingUtils.formatHeader(output, settings, member.header, typeFormatter);
142
+		formatBody(member.body);
143
+		return null;
144
+	}
145
+
146
+	@Override
147
+	public Void visitCaster(CasterMember member) {
148
+		FormattingUtils.formatModifiers(output, member.modifiers & ~Modifiers.FINAL);
149
+		output.append(" as ");
150
+		output.append(member.toType.accept(typeFormatter));
151
+		formatBody(member.body);
152
+		return null;
153
+	}
154
+
155
+	@Override
156
+	public Void visitCustomIterator(CustomIteratorMember member) {
157
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
158
+	}
159
+
160
+	@Override
161
+	public Void visitCaller(CallerMember member) {
162
+		FormattingUtils.formatModifiers(output, member.modifiers & ~Modifiers.FINAL);
163
+		FormattingUtils.formatHeader(output, settings, member.header, typeFormatter);
164
+		formatBody(member.body);
165
+		return null;
166
+	}
167
+
168
+	@Override
169
+	public Void visitImplementation(ImplementationMember implementation) {
170
+		FormattingUtils.formatModifiers(output, implementation.modifiers & ~Modifiers.FINAL);
171
+		output.append("implements ");
172
+		output.append(implementation.type.accept(typeFormatter));
173
+		if (settings.classBracketOnSameLine) {
174
+			output.append("{\n");
175
+		} else {
176
+			output.append("\n").append(indent).append("{\n");
177
+		}
178
+		
179
+		for (IDefinitionMember member : implementation.members) {
180
+			member.accept(new MemberFormatter(settings, output, indent + settings.indent, typeFormatter));
181
+		}
182
+		
183
+		output.append("}\n");
184
+		return null;
185
+	}
186
+
187
+	@Override
188
+	public Void visitInnerDefinition(InnerDefinitionMember member) {
189
+		String formatted = member.innerDefinition.accept(new DefinitionFormatter(settings, typeFormatter, indent + settings.indent)).toString();
190
+		output.append(formatted);
191
+		return null;
192
+	}
193
+	
194
+	private void formatBody(Statement body) {
195
+		FormattingUtils.formatBody(output, settings, indent, typeFormatter, body);
196
+	}
197
+}

+ 1
- 48
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java Datei anzeigen

@@ -68,31 +68,7 @@ public class TypeFormatter implements ITypeVisitor<String>, GenericParameterBoun
68 68
 	public String visitFunction(FunctionTypeID function) {
69 69
 		StringBuilder result = new StringBuilder();
70 70
 		result.append("function");
71
-		
72
-		FunctionHeader header = function.header;
73
-		formatTypeParameters(result, header.typeParameters);
74
-		result.append("(");
75
-		int parameterIndex = 0;
76
-		for (FunctionParameter parameter : header.parameters) {
77
-			if (parameterIndex > 0)
78
-				result.append(", ");
79
-			
80
-			result.append(parameter.name);
81
-			if (parameter.variadic)
82
-				result.append("...");
83
-			
84
-			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.ANY) {
85
-				result.append(" as ");
86
-				result.append(header.returnType.accept(this));
87
-			}
88
-			
89
-			parameterIndex++;
90
-		}
91
-		result.append(")");
92
-		if (!settings.showAnyInFunctionHeaders || header.returnType != BasicTypeID.ANY) {
93
-			result.append(" as ");
94
-			result.append(header.returnType.accept(this));
95
-		}
71
+		FormattingUtils.formatHeader(result, settings, function.header, this);
96 72
 		return result.toString();
97 73
 	}
98 74
 
@@ -135,29 +111,6 @@ public class TypeFormatter implements ITypeVisitor<String>, GenericParameterBoun
135 111
 	public String visitOptional(OptionalTypeID optional) {
136 112
 		return optional.baseType.accept(this) + "?";
137 113
 	}
138
-	
139
-	private void formatTypeParameters(StringBuilder result, TypeParameter[] parameters) {
140
-		if (parameters.length > 0) {
141
-			result.append("<");
142
-			int index = 0;
143
-			for (TypeParameter parameter : parameters) {
144
-				if (index > 0)
145
-					result.append(", ");
146
-				
147
-				result.append(parameter.name);
148
-				
149
-				if (parameter.bounds.size() > 0) {
150
-					for (GenericParameterBound bound : parameter.bounds) {
151
-						result.append(": ");
152
-						result.append(bound.accept(this));
153
-					}
154
-				}
155
-				
156
-				index++;
157
-			}
158
-			result.append(">");
159
-		}
160
-	}
161 114
 
162 115
 	@Override
163 116
 	public String visitSuper(ParameterSuperBound bound) {

+ 0
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java Datei anzeigen

@@ -38,18 +38,12 @@ public class FunctionHeader {
38 38
 		this.typeParameters = NO_GENERIC_PARAMETERS;
39 39
 		this.returnType = returnType;
40 40
 		this.parameters = parameters;
41
-		
42
-		for (int i = 0; i < parameters.length; i++)
43
-			parameters[i].index = i;
44 41
 	}
45 42
 	
46 43
 	public FunctionHeader(TypeParameter[] genericParameters, ITypeID returnType, FunctionParameter[] parameters) {
47 44
 		this.typeParameters = genericParameters;
48 45
 		this.returnType = returnType;
49 46
 		this.parameters = parameters;
50
-		
51
-		for (int i = 0; i < parameters.length; i++)
52
-			parameters[i].index = i;
53 47
 	}
54 48
 	
55 49
 	public FunctionHeader instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionParameter.java Datei anzeigen

@@ -11,13 +11,13 @@ import org.openzen.zenscript.codemodel.expression.Expression;
11 11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12 12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
+import org.openzen.zenscript.shared.Taggable;
14 15
 
15 16
 /**
16 17
  *
17 18
  * @author Hoofdgebruiker
18 19
  */
19
-public class FunctionParameter {
20
-	public int index = -1;
20
+public class FunctionParameter extends Taggable {
21 21
 	public final ITypeID type;
22 22
 	public final String name;
23 23
 	public final Expression defaultValue;

+ 11
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java Datei anzeigen

@@ -10,6 +10,7 @@ import java.util.List;
10 10
 import org.openzen.zenscript.codemodel.definition.DefinitionVisitor;
11 11
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
12 12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
+import org.openzen.zenscript.codemodel.member.EnumConstantMember;
13 14
 import org.openzen.zenscript.codemodel.member.FieldMember;
14 15
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
15 16
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -63,9 +64,19 @@ public abstract class HighLevelDefinition extends Taggable {
63 64
 		for (IDefinitionMember member : members)
64 65
 			if (member instanceof FieldMember)
65 66
 				fields.add((FieldMember)member);
67
+		
66 68
 		return fields;
67 69
 	}
68 70
 	
71
+	public List<EnumConstantMember> getEnumConstants() {
72
+		List<EnumConstantMember> enumMembers = new ArrayList<>();
73
+		for (IDefinitionMember member : members)
74
+            if (member instanceof EnumConstantMember)
75
+				enumMembers.add((EnumConstantMember) member);
76
+		
77
+		return enumMembers;
78
+	}
79
+	
69 80
 	public boolean isStatic() {
70 81
 		return (modifiers & Modifiers.STATIC) > 0;
71 82
 	}

+ 4
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java Datei anzeigen

@@ -22,7 +22,7 @@ import org.openzen.zenscript.shared.CodePosition;
22 22
  */
23 23
 public class FunctionDefinition extends HighLevelDefinition {
24 24
 	public FunctionHeader header;
25
-	public List<Statement> statements;
25
+	public Statement statement;
26 26
 	public OperatorMember caller;
27 27
 	public DefinitionMemberGroup callerGroup = new DefinitionMemberGroup();
28 28
 	
@@ -41,9 +41,9 @@ public class FunctionDefinition extends HighLevelDefinition {
41 41
 		callerGroup.addMethod(caller, TypeMemberPriority.SPECIFIED);
42 42
 	}
43 43
 	
44
-	public void setCode(List<Statement> statements) {
45
-		this.statements = statements;
46
-		caller.setBody(statements);
44
+	public void setCode(Statement statement) {
45
+		this.statement = statement;
46
+		caller.setBody(statement);
47 47
 	}
48 48
 
49 49
 	@Override

+ 3
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/FunctionExpression.java Datei anzeigen

@@ -5,7 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.expression;
7 7
 
8
-import java.util.List;
9 8
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 9
 import org.openzen.zenscript.codemodel.statement.Statement;
11 10
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
@@ -18,18 +17,18 @@ import org.openzen.zenscript.shared.CodePosition;
18 17
 public class FunctionExpression extends Expression {
19 18
 	public final FunctionHeader header;
20 19
 	public final LambdaClosure closure;
21
-	public final List<Statement> statements;
20
+	public final Statement body;
22 21
 	
23 22
 	public FunctionExpression(
24 23
 			CodePosition position,
25 24
 			FunctionTypeID type,
26 25
 			LambdaClosure closure,
27
-			List<Statement> statements) {
26
+			Statement body) {
28 27
 		super(position, type);
29 28
 		
30 29
 		this.header = type.header;
31 30
 		this.closure = closure;
32
-		this.statements = statements;
31
+		this.body = body;
33 32
 	}
34 33
 
35 34
 	@Override

+ 19
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java Datei anzeigen

@@ -8,7 +8,11 @@ package org.openzen.zenscript.codemodel.member;
8 8
 import java.util.Map;
9 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
12
+import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
11 13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
+import org.openzen.zenscript.codemodel.statement.BlockStatement;
15
+import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
12 16
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
13 17
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
14 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -24,6 +28,21 @@ public class ConstructorMember extends FunctionalMember {
24 28
 	public ConstructorMember(CodePosition position, HighLevelDefinition definition, int modifiers, FunctionHeader header) {
25 29
 		super(position, definition, modifiers, "this", new FunctionHeader(header.typeParameters, BasicTypeID.VOID, header.parameters));
26 30
 	}
31
+	
32
+	public boolean isConstructorForwarded() {
33
+		ExpressionStatement firstExpression = null;
34
+		if (body instanceof ExpressionStatement) {
35
+			firstExpression = (ExpressionStatement) body;
36
+		} else if (body instanceof BlockStatement) {
37
+			BlockStatement blockBody = (BlockStatement) body;
38
+			if (blockBody.statements.size() > 0 && blockBody.statements.get(0) instanceof ExpressionStatement)
39
+				firstExpression = (ExpressionStatement) blockBody.statements.get(0);
40
+		}
41
+		
42
+		return firstExpression != null && (
43
+				firstExpression.expression instanceof ConstructorSuperCallExpression
44
+				|| firstExpression.expression instanceof ConstructorThisCallExpression);
45
+	}
27 46
 
28 47
 	@Override
29 48
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CustomIteratorMember.java Datei anzeigen

@@ -23,7 +23,7 @@ import org.openzen.zenscript.shared.CodePosition;
23 23
  */
24 24
 public class CustomIteratorMember extends DefinitionMember implements IIteratorMember {
25 25
 	private final ITypeID[] iteratorTypes;
26
-	private List<Statement> content;
26
+	private Statement content;
27 27
 	
28 28
 	public CustomIteratorMember(CodePosition position, HighLevelDefinition definition, int modifiers, ITypeID[] iteratorTypes) {
29 29
 		super(position, definition, modifiers);
@@ -31,7 +31,7 @@ public class CustomIteratorMember extends DefinitionMember implements IIteratorM
31 31
 		this.iteratorTypes = iteratorTypes;
32 32
 	}
33 33
 	
34
-	public void setContent(List<Statement> content) {
34
+	public void setContent(Statement content) {
35 35
 		this.content = content;
36 36
 	}
37 37
 

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java Datei anzeigen

@@ -24,7 +24,7 @@ import org.openzen.zenscript.shared.CodePosition;
24 24
 public abstract class FunctionalMember extends DefinitionMember implements ICallableMember {
25 25
 	public final FunctionHeader header;
26 26
 	public final String name;
27
-	public List<Statement> body;
27
+	public Statement body;
28 28
 	
29 29
 	public FunctionalMember(CodePosition position, HighLevelDefinition definition, int modifiers, String name, FunctionHeader header) {
30 30
 		super(position, definition, modifiers);
@@ -33,7 +33,7 @@ public abstract class FunctionalMember extends DefinitionMember implements ICall
33 33
 		this.header = header;
34 34
 	}
35 35
 	
36
-	public void setBody(List<Statement> body) {
36
+	public void setBody(Statement body) {
37 37
 		this.body = body;
38 38
 	}
39 39
 	

+ 0
- 12
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/Statement.java Datei anzeigen

@@ -33,18 +33,6 @@ public abstract class Statement extends Taggable {
33 33
 	
34 34
 	public abstract <T> T accept(StatementVisitor<T> visitor);
35 35
 	
36
-	public static ITypeID getReturnType(TypeScope scope, List<Statement> statements) {
37
-		ITypeID result = null;
38
-		for (Statement statement : statements) {
39
-			ITypeID statementType = statement.getReturnType();
40
-			if (result == null)
41
-				result = statementType;
42
-			else
43
-				result = scope.getTypeMembers(result).union(statementType);
44
-		}
45
-		return result;
46
-	}
47
-	
48 36
 	public static List<Statement> withReturnType(TypeScope scope, List<Statement> statements, ITypeID returnType) {
49 37
 		return statements.stream()
50 38
 				.map(statement -> statement.withReturnType(scope, returnType))

+ 7
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaClassInfo.java Datei anzeigen

@@ -13,12 +13,18 @@ import org.objectweb.asm.Type;
13 13
  */
14 14
 public class JavaClassInfo {
15 15
 	public static JavaClassInfo get(Class<?> cls) {
16
-		return new JavaClassInfo(Type.getInternalName(cls));
16
+		return new JavaClassInfo(Type.getInternalName(cls), cls.isEnum());
17 17
 	}
18 18
 	
19 19
 	public final String internalClassName;
20
+	public final boolean isEnum;
20 21
 	
21 22
 	public JavaClassInfo(String internalClassName) {
23
+		this(internalClassName, false);
24
+	}
25
+	
26
+	public JavaClassInfo(String internalClassName, boolean isEnum) {
22 27
 		this.internalClassName = internalClassName;
28
+		this.isEnum = isEnum;
23 29
 	}
24 30
 }

+ 5
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java Datei anzeigen

@@ -156,14 +156,16 @@ public class JavaCompiler {
156 156
 		final SourceFile sourceFile = script.getTag(SourceFile.class);
157 157
 		final String className = getClassName(sourceFile == null ? null : sourceFile.filename);
158 158
 		JavaScriptFile scriptFile = getScriptFile(className);
159
+		
160
+		String methodName = scriptFile.scriptMethods.isEmpty() ? "run" : "run" + scriptFile.scriptMethods.size();
159 161
 
160 162
 		// convert scripts into methods (add them to a Scripts class?)
161 163
 		// (TODO: can we break very long scripts into smaller methods? for the extreme scripts)
162 164
 		final JavaClassWriter visitor = scriptFile.classWriter;
163
-		JavaMethodInfo method = new JavaMethodInfo(new JavaClassInfo(className), "run", "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
165
+		JavaMethodInfo method = new JavaMethodInfo(new JavaClassInfo(className), methodName, "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
164 166
 		scriptFile.scriptMethods.add(method);
165 167
 		
166
-		final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(new JavaWriter(visitor, method, null, null));
168
+		final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(new JavaWriter(visitor, method, null, null, null));
167 169
 		statementVisitor.start();
168 170
 		for (Statement statement : script.statements) {
169 171
 			statement.accept(statementVisitor);
@@ -198,7 +200,7 @@ public class JavaCompiler {
198 200
 		finished = true;
199 201
 		
200 202
 		JavaMethodInfo runMethod = new JavaMethodInfo(new JavaClassInfo("Scripts"), "run", "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
201
-		final JavaWriter runWriter = new JavaWriter(scriptsClassWriter, runMethod, null, null);
203
+		final JavaWriter runWriter = new JavaWriter(scriptsClassWriter, runMethod, null, null, null);
202 204
 		runWriter.start();
203 205
 		for (Map.Entry<String, JavaScriptFile> entry : scriptBlocks.entrySet()) {
204 206
 			for (JavaMethodInfo method : entry.getValue().scriptMethods)

+ 0
- 11
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaEnumInfo.java Datei anzeigen

@@ -1,11 +0,0 @@
1
-package org.openzen.zenscript.javabytecode;
2
-
3
-import org.openzen.zenscript.javabytecode.compiler.JavaStatementVisitor;
4
-
5
-public class JavaEnumInfo {
6
-    public final JavaStatementVisitor clinitVisitor;
7
-
8
-    public JavaEnumInfo(JavaStatementVisitor clinitVisitor) {
9
-        this.clinitVisitor = clinitVisitor;
10
-    }
11
-}

+ 18
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaParameterInfo.java Datei anzeigen

@@ -0,0 +1,18 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javabytecode;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class JavaParameterInfo {
13
+	public final int index;
14
+	
15
+	public JavaParameterInfo(int index) {
16
+		this.index = index;
17
+	}
18
+}

+ 28
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java Datei anzeigen

@@ -4,9 +4,13 @@ import org.objectweb.asm.Opcodes;
4 4
 import org.objectweb.asm.Type;
5 5
 import org.openzen.zenscript.codemodel.FunctionHeader;
6 6
 import org.openzen.zenscript.codemodel.FunctionParameter;
7
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
7 8
 import org.openzen.zenscript.codemodel.Modifiers;
9
+import org.openzen.zenscript.codemodel.member.FieldMember;
10
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
8 11
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
9 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
+import org.openzen.zenscript.javabytecode.JavaParameterInfo;
10 14
 import org.openzen.zenscript.shared.CodePosition;
11 15
 
12 16
 public class CompilerUtils {
@@ -72,4 +76,28 @@ public class CompilerUtils {
72 76
     public static String calcClasName(CodePosition position) {
73 77
         return position.filename.substring(0, position.filename.lastIndexOf('.')).replace("/", "_");
74 78
     }
79
+	
80
+	public static void tagMethodParameters(FunctionHeader header, boolean isStatic) {
81
+		for (int i = 0; i < header.parameters.length; i++) {
82
+			header.parameters[i].setTag(JavaParameterInfo.class, new JavaParameterInfo(isStatic ? i : i + 1));
83
+		}
84
+	}
85
+	
86
+	public static void tagConstructorParameters(FunctionHeader header, boolean isEnum) {
87
+		for (int i = 0; i < header.parameters.length; i++) {
88
+			header.parameters[i].setTag(JavaParameterInfo.class, new JavaParameterInfo(isEnum ? i + 3 : i + 1));
89
+		}
90
+	}
91
+	
92
+	public static void writeDefaultFieldInitializers(JavaWriter constructorWriter, HighLevelDefinition definition) {
93
+		JavaExpressionVisitor expressionVisitor = new JavaExpressionVisitor(constructorWriter);
94
+		for (final IDefinitionMember definitionMember : definition.members) {
95
+			if (definitionMember instanceof FieldMember && ((FieldMember) definitionMember).initializer != null) {
96
+				final FieldMember field = (FieldMember) definitionMember;
97
+				constructorWriter.loadObject(0);
98
+				field.initializer.accept(expressionVisitor);
99
+				constructorWriter.putField(definition.name, field.name, Type.getDescriptor(field.type.accept(JavaTypeClassVisitor.INSTANCE)));
100
+			}
101
+		}
102
+	}
75 103
 }

+ 16
- 6
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Datei anzeigen

@@ -275,11 +275,19 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
275 275
     @Override
276 276
     public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
277 277
         Type type = expression.objectType.accept(JavaTypeVisitor.INSTANCE);
278
-        //javaWriter.loadObject(0);
278
+		
279
+		if (javaWriter.method.javaClass.isEnum) {
280
+			javaWriter.loadObject(0);
281
+			javaWriter.loadObject(1);
282
+			javaWriter.loadInt(2);
283
+		} else {
284
+			javaWriter.loadObject(0);
285
+		}
286
+		
279 287
         for (Expression argument : expression.arguments.arguments) {
280 288
             argument.accept(this);
281 289
         }
282
-        javaWriter.invokeSpecial(type.getInternalName(), "<init>", CompilerUtils.calcDesc(expression.constructor.header, expression.constructor.hasTag(JavaEnumInfo.class)));
290
+        javaWriter.invokeSpecial(type.getInternalName(), "<init>", CompilerUtils.calcDesc(expression.constructor.header, javaWriter.method.javaClass.isEnum));
283 291
         return null;
284 292
     }
285 293
 
@@ -291,6 +299,8 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
291 299
         }
292 300
         //No super calls in enums possible, and that's already handled in the enum constructor itself.
293 301
         javaWriter.invokeSpecial(expression.objectType.accept(JavaTypeClassVisitor.INSTANCE), "<init>", CompilerUtils.calcDesc(expression.constructor.header, false));
302
+		
303
+		CompilerUtils.writeDefaultFieldInitializers(javaWriter, javaWriter.forDefinition);
294 304
         return null;
295 305
     }
296 306
 
@@ -322,9 +332,8 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
322 332
 
323 333
     @Override
324 334
     public Void visitGetFunctionParameter(GetFunctionParameterExpression expression) {
325
-        //TODO is Static?
326
-        final boolean isStatic = false;
327
-        javaWriter.load(Type.getType(expression.parameter.type.accept(JavaTypeClassVisitor.INSTANCE)), isStatic ? expression.parameter.index : expression.parameter.index + 1);
335
+		JavaParameterInfo parameter = expression.parameter.getTag(JavaParameterInfo.class);
336
+        javaWriter.load(Type.getType(expression.parameter.type.accept(JavaTypeClassVisitor.INSTANCE)), parameter.index);
328 337
         return null;
329 338
     }
330 339
 
@@ -473,7 +482,8 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
473 482
     @Override
474 483
     public Void visitSetFunctionParameter(SetFunctionParameterExpression expression) {
475 484
         expression.value.accept(this);
476
-        javaWriter.store(expression.type.accept(JavaTypeVisitor.INSTANCE), javaWriter.method.isStatic() ? expression.parameter.index : expression.parameter.index + 1);
485
+		JavaParameterInfo parameter = expression.parameter.getTag(JavaParameterInfo.class);
486
+        javaWriter.store(expression.type.accept(JavaTypeVisitor.INSTANCE), parameter.index);
477 487
         return null;
478 488
     }
479 489
 

+ 31
- 30
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java Datei anzeigen

@@ -5,7 +5,7 @@ import org.objectweb.asm.Type;
5 5
 import org.openzen.zenscript.codemodel.statement.*;
6 6
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
7 7
 
8
-public class JavaStatementVisitor implements StatementVisitor<Void> {
8
+public class JavaStatementVisitor implements StatementVisitor<Boolean> {
9 9
     private final JavaWriter javaWriter;
10 10
     public final JavaExpressionVisitor expressionVisitor;
11 11
 	
@@ -18,27 +18,28 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
18 18
     }
19 19
 
20 20
     @Override
21
-    public Void visitBlock(BlockStatement statement) {
21
+    public Boolean visitBlock(BlockStatement statement) {
22
+		Boolean returns = false;
22 23
         for (Statement statement1 : statement.statements) {
23
-            statement1.accept(this);
24
+            returns = statement1.accept(this);
24 25
         }
25
-        return null;
26
+        return returns;
26 27
     }
27 28
 
28 29
     @Override
29
-    public Void visitBreak(BreakStatement statement) {
30
+    public Boolean visitBreak(BreakStatement statement) {
30 31
         javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_end"));
31
-        return null;
32
+        return false;
32 33
     }
33 34
 
34 35
     @Override
35
-    public Void visitContinue(ContinueStatement statement) {
36
+    public Boolean visitContinue(ContinueStatement statement) {
36 37
         javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_start"));
37
-        return null;
38
+        return false;
38 39
     }
39 40
 
40 41
     @Override
41
-    public Void visitDoWhile(DoWhileStatement statement) {
42
+    public Boolean visitDoWhile(DoWhileStatement statement) {
42 43
         Label start = new Label();
43 44
         Label end = new Label();
44 45
         if (statement.label == null)
@@ -53,23 +54,23 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
53 54
 
54 55
         //Only needed for break statements, should be nop if not used
55 56
         javaWriter.label(end);
56
-        return null;
57
+        return false;
57 58
     }
58 59
 
59 60
     @Override
60
-    public Void visitEmpty(EmptyStatement statement) {
61
+    public Boolean visitEmpty(EmptyStatement statement) {
61 62
         //No-Op
62
-        return null;
63
+        return false;
63 64
     }
64 65
 
65 66
     @Override
66
-    public Void visitExpression(ExpressionStatement statement) {
67
+    public Boolean visitExpression(ExpressionStatement statement) {
67 68
         statement.expression.accept(expressionVisitor);
68
-        return null;
69
+        return false;
69 70
     }
70 71
 
71 72
     @Override
72
-    public Void visitForeach(ForeachStatement statement) {
73
+    public Boolean visitForeach(ForeachStatement statement) {
73 74
         //Create Labels
74 75
         Label start = new Label();
75 76
         Label end = new Label();
@@ -97,11 +98,11 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
97 98
         statement.iterator.acceptForIterator(new JavaForeachVisitor(this, statement.loopVariables, statement.content, start, end));
98 99
         javaWriter.goTo(start);
99 100
         javaWriter.label(end);
100
-        return null;
101
+        return false;
101 102
     }
102 103
 
103 104
     @Override
104
-    public Void visitIf(IfStatement statement) {
105
+    public Boolean visitIf(IfStatement statement) {
105 106
         statement.condition.accept(expressionVisitor);
106 107
         Label onElse = null;
107 108
         Label end = new Label();
@@ -119,30 +120,30 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
119 120
             statement.onElse.accept(this);
120 121
         }
121 122
         javaWriter.label(end);
122
-        return null;
123
+        return false;
123 124
     }
124 125
 
125 126
     @Override
126
-    public Void visitLock(LockStatement statement) {
127
-        return null;
127
+    public Boolean visitLock(LockStatement statement) {
128
+        return false;
128 129
     }
129 130
 
130 131
     @Override
131
-    public Void visitReturn(ReturnStatement statement) {
132
+    public Boolean visitReturn(ReturnStatement statement) {
132 133
         statement.value.accept(expressionVisitor);
133 134
         javaWriter.returnType(Type.getType(statement.value.type.accept(JavaTypeClassVisitor.INSTANCE)));
134
-        return null;
135
+        return true;
135 136
     }
136 137
 
137 138
     @Override
138
-    public Void visitThrow(ThrowStatement statement) {
139
+    public Boolean visitThrow(ThrowStatement statement) {
139 140
         statement.value.accept(expressionVisitor);
140 141
         javaWriter.aThrow();
141
-        return null;
142
+        return false;
142 143
     }
143 144
 
144 145
     @Override
145
-    public Void visitTryCatch(TryCatchStatement statement) {
146
+    public Boolean visitTryCatch(TryCatchStatement statement) {
146 147
         final Label tryCatchStart = new Label();
147 148
         final Label tryFinish = new Label();
148 149
         final Label tryCatchFinish = new Label();
@@ -189,11 +190,11 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
189 190
         }
190 191
         javaWriter.label(tryCatchFinish);
191 192
 
192
-        return null;
193
+        return false;
193 194
     }
194 195
 
195 196
     @Override
196
-    public Void visitVar(VarStatement statement) {
197
+    public Boolean visitVar(VarStatement statement) {
197 198
         Type type = statement.type.accept(JavaTypeVisitor.INSTANCE);
198 199
         int local = javaWriter.local(type);
199 200
         if (statement.initializer != null) {
@@ -205,11 +206,11 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
205 206
         final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, local, variableStart, statement.name);
206 207
         statement.setTag(JavaLocalVariableInfo.class, info);
207 208
         javaWriter.addVariableInfo(info);
208
-        return null;
209
+        return false;
209 210
     }
210 211
 
211 212
     @Override
212
-    public Void visitWhile(WhileStatement statement) {
213
+    public Boolean visitWhile(WhileStatement statement) {
213 214
         Label start = new Label();
214 215
         Label end = new Label();
215 216
 
@@ -225,7 +226,7 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
225 226
         statement.content.accept(this);
226 227
         javaWriter.goTo(start);
227 228
         javaWriter.label(end);
228
-        return null;
229
+        return false;
229 230
     }
230 231
 
231 232
     public void start() {

+ 14
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java Datei anzeigen

@@ -12,6 +12,7 @@ import java.util.List;
12 12
 import java.util.Map;
13 13
 
14 14
 import static org.objectweb.asm.Opcodes.*;
15
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
15 16
 import org.openzen.zenscript.javabytecode.JavaClassInfo;
16 17
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
17 18
 
@@ -24,6 +25,7 @@ public class JavaWriter {
24 25
 			Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
25 26
 	
26 27
 	public final JavaMethodInfo method;
28
+	public final HighLevelDefinition forDefinition;
27 29
 	
28 30
     private final LocalVariablesSorter visitor;
29 31
     private final List<JavaLocalVariableInfo> localVariableInfos = new ArrayList<>();
@@ -32,8 +34,17 @@ public class JavaWriter {
32 34
     private int labelIndex = 1;
33 35
     private Map<Label, String> labelNames = new HashMap<>();
34 36
 
35
-    public JavaWriter(ClassVisitor visitor, boolean nameVariables, JavaMethodInfo method, String signature, String[] exceptions, String... annotations) {
37
+    public JavaWriter(
38
+			ClassVisitor visitor,
39
+			boolean nameVariables,
40
+			JavaMethodInfo method,
41
+			HighLevelDefinition forDefinition,
42
+			String signature,
43
+			String[] exceptions,
44
+			String... annotations)
45
+	{
36 46
 		this.method = method;
47
+		this.forDefinition = forDefinition;
37 48
 		
38 49
         final MethodVisitor methodVisitor = visitor.visitMethod(method.modifiers, method.name, method.descriptor, signature, exceptions);
39 50
 
@@ -45,8 +56,8 @@ public class JavaWriter {
45 56
         this.nameVariables = nameVariables;
46 57
     }
47 58
 
48
-    public JavaWriter(ClassVisitor visitor, JavaMethodInfo method, String signature, String[] exceptions, String... annotations) {
49
-        this(visitor, true, method, signature, exceptions, annotations);
59
+    public JavaWriter(ClassVisitor visitor, JavaMethodInfo method, HighLevelDefinition forDefinition, String signature, String[] exceptions, String... annotations) {
60
+        this(visitor, true, method, forDefinition, signature, exceptions, annotations);
50 61
     }
51 62
 
52 63
     private static String signature(Class aClass) {

+ 58
- 103
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java Datei anzeigen

@@ -1,27 +1,19 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler.definitions;
2 2
 
3
+import java.util.List;
3 4
 import org.objectweb.asm.ClassWriter;
4 5
 import org.objectweb.asm.Opcodes;
5 6
 import org.objectweb.asm.Type;
6
-import org.openzen.zenscript.codemodel.FunctionParameter;
7 7
 import org.openzen.zenscript.codemodel.definition.*;
8 8
 import org.openzen.zenscript.codemodel.expression.Expression;
9
-import org.openzen.zenscript.codemodel.expression.ExpressionVisitor;
10
-import org.openzen.zenscript.codemodel.member.ConstructorMember;
11 9
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
12
-import org.openzen.zenscript.codemodel.member.FieldMember;
13 10
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
14
-import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
15
-import org.openzen.zenscript.codemodel.statement.ReturnStatement;
16
-import org.openzen.zenscript.codemodel.statement.Statement;
17 11
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
18 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
19 13
 import org.openzen.zenscript.javabytecode.JavaClassInfo;
20
-import org.openzen.zenscript.javabytecode.JavaEnumInfo;
21 14
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
22 15
 import org.openzen.zenscript.javabytecode.compiler.*;
23 16
 
24
-import java.util.Iterator;
25 17
 
26 18
 public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
27 19
 	private static final JavaClassInfo T_CLASS = new JavaClassInfo("java/lang/Class");
@@ -65,31 +57,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
65 57
 
66 58
         writer.visit(Opcodes.V1_8, definition.modifiers, definition.name, signature, superType.getInternalName(), null);
67 59
         for (IDefinitionMember member : definition.members) {
68
-            if (member instanceof ConstructorMember) {
69
-                final ConstructorMember constructorMember = (ConstructorMember) member;
70
-                constructorMember.body.add(0, new ExpressionStatement(constructorMember.position, new Expression(constructorMember.position, BasicTypeID.VOID) {
71
-                    @Override
72
-                    public <T> T accept(ExpressionVisitor<T> visitor) {
73
-                        if (visitor instanceof JavaExpressionVisitor) {
74
-                            JavaWriter javaWriter = ((JavaExpressionVisitor) visitor).getJavaWriter();
75
-                            javaWriter.loadObject(0);
76
-                            //TODO Super constructor?
77
-                            javaWriter.invokeSpecial(Type.getInternalName(Object.class), "<init>", "()V");
78
-                            for (final IDefinitionMember definitionMember : definition.members) {
79
-                                if (definitionMember instanceof FieldMember && ((FieldMember) definitionMember).initializer != null) {
80
-                                    final FieldMember field = (FieldMember) definitionMember;
81
-                                    javaWriter.loadObject(0);
82
-                                    field.initializer.accept(visitor);
83
-                                    javaWriter.putField(definition.name, field.name, Type.getDescriptor(field.type.accept(JavaTypeClassVisitor.INSTANCE)));
84
-                                }
85
-                            }
86
-                        }
87
-                        return null;
88
-                    }
89
-                }));
90
-            }
91
-			
92
-            member.accept(new JavaMemberVisitor(writer, toClass));
60
+            member.accept(new JavaMemberVisitor(writer, toClass, definition));
93 61
         }
94 62
         writer.visitEnd();
95 63
         return writer.toByteArray();
@@ -105,7 +73,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
105 73
         String signature = null;
106 74
         writer.visit(Opcodes.V1_8, definition.modifiers | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, definition.name, signature, Type.getInternalName(Object.class), null);
107 75
         for (IDefinitionMember member : definition.members) {
108
-            member.accept(new JavaMemberVisitor(writer, toClass));
76
+            member.accept(new JavaMemberVisitor(writer, toClass, definition));
109 77
         }
110 78
         writer.visitEnd();
111 79
         return writer.toByteArray();
@@ -113,6 +81,8 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
113 81
 
114 82
     @Override
115 83
     public byte[] visitEnum(EnumDefinition definition) {
84
+		System.out.println("Compiling enum " + definition.name + " in " + definition.position.filename);
85
+		
116 86
         final Type superType;
117 87
         if (definition.superType == null)
118 88
             superType = Type.getType(Object.class);
@@ -127,66 +97,24 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
127 97
             if (member instanceof EnumConstantMember) {
128 98
                 EnumConstantMember constantMember = (EnumConstantMember) member;
129 99
                 writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_ENUM, constantMember.name, "L" + definition.name + ";", null, null).visitEnd();
130
-            } else if (member instanceof ConstructorMember) {
131
-                member.setTag(JavaEnumInfo.class, null);
132 100
             }
133 101
         }
134 102
 
135
-		JavaClassInfo toClass = new JavaClassInfo(definition.name);
136
-		JavaMethodInfo clinitInfo = new JavaMethodInfo(toClass, "<clinit>", "()V", Opcodes.ACC_STATIC);
137
-        final JavaWriter clinitWriter = new JavaWriter(writer, clinitInfo, null, null);
138
-        final JavaStatementVisitor clinitVisitor = new JavaStatementVisitor(clinitWriter);
139
-        clinitVisitor.start();
140
-        int constantCount = 0;
141
-        for (IDefinitionMember member : definition.members) {
142
-            if (member instanceof ConstructorMember) {
143
-                final ConstructorMember constructorMember = (ConstructorMember) member;
144
-
145
-
146
-                constructorMember.body.add(0, new ExpressionStatement(constructorMember.position, new Expression(constructorMember.position, BasicTypeID.VOID) {
147
-                    @Override
148
-                    public <T> T accept(ExpressionVisitor<T> visitor) {
149
-                        if (visitor instanceof JavaExpressionVisitor) {
150
-                            JavaWriter javaWriter = ((JavaExpressionVisitor) visitor).getJavaWriter();
151
-                            javaWriter.getVisitor().newLocal(Type.getType(String.class));
152
-                            javaWriter.getVisitor().newLocal(Type.getType(int.class));
153
-                            javaWriter.loadObject(0);
154
-                            javaWriter.loadObject(1);
155
-                            javaWriter.loadInt(2);
156
-                            //javaWriter.invokeSpecial(Type.getInternalName(Enum.class), "<init>", "(Ljava/lang/String;I)V");
157
-                        }
158
-                        return null;
159
-                    }
160
-                }));
161
-            } else if (member instanceof EnumConstantMember) {
162
-                ++constantCount;
163
-                member.setTag(JavaEnumInfo.class, new JavaEnumInfo(clinitVisitor));
164
-            }
165
-            member.accept(new JavaMemberVisitor(writer, toClass));
166
-        }
167
-
168
-        clinitWriter.constant(constantCount);
169
-        clinitWriter.newArray(Type.getType("L" + definition.name + ";"));
170
-
171
-        for (IDefinitionMember member : definition.members) {
172
-            if (!(member instanceof EnumConstantMember)) continue;
173
-            final EnumConstantMember constantMember = (EnumConstantMember) member;
174
-            clinitWriter.dup();
175
-            clinitWriter.constant(constantMember.value);
176
-            clinitWriter.getStaticField(definition.name, constantMember.name, "L" + definition.name + ";");
177
-            clinitWriter.arrayStore(Type.getType("L" + definition.name + ";"));
178
-        }
179
-        clinitWriter.putStaticField(definition.name, "$VALUES", "[L" + definition.name + ";");
180
-        clinitVisitor.end();
103
+		JavaClassInfo toClass = new JavaClassInfo(definition.name, true);
104
+		writeEnumStaticInitializer(definition, toClass, writer);
181 105
 
182 106
         //Enum Stuff(required!)
183 107
         writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, "$VALUES", "[L" + definition.name + ";", null, null).visitEnd();
184 108
 		
109
+        for (IDefinitionMember member : definition.members) {
110
+            member.accept(new JavaMemberVisitor(writer, toClass, definition));
111
+        }
112
+		
185 113
 		JavaClassInfo arrayClass = new JavaClassInfo("[L" + definition.name + ";");
186 114
 		JavaMethodInfo arrayClone = new JavaMethodInfo(arrayClass, "clone", "()Ljava/lang/Object;", Opcodes.ACC_PUBLIC);
187 115
 
188 116
 		JavaMethodInfo valuesMethodInfo = new JavaMethodInfo(toClass, "values", "()[L" + definition.name + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
189
-        JavaWriter valuesWriter = new JavaWriter(writer, true, valuesMethodInfo, null, null);
117
+        JavaWriter valuesWriter = new JavaWriter(writer, true, valuesMethodInfo, definition, null, null);
190 118
         valuesWriter.start();
191 119
         valuesWriter.getStaticField(definition.name, "$VALUES", "[L" + definition.name + ";");
192 120
         valuesWriter.invokeVirtual(arrayClone);
@@ -195,7 +123,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
195 123
         valuesWriter.end();
196 124
 
197 125
 		JavaMethodInfo valueOfMethodInfo = new JavaMethodInfo(toClass, "valueOf", "(Ljava/lang/String;)L" + definition.name + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
198
-        JavaWriter valueOfWriter = new JavaWriter(writer, true, valueOfMethodInfo, null, null);
126
+        JavaWriter valueOfWriter = new JavaWriter(writer, true, valueOfMethodInfo, definition, null, null);
199 127
         valueOfWriter.start();
200 128
         valueOfWriter.invokeStatic(CLASS_FORNAME);
201 129
         valueOfWriter.loadObject(0);
@@ -208,6 +136,40 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
208 136
         writer.visitEnd();
209 137
         return writer.toByteArray();
210 138
     }
139
+	
140
+	private void writeEnumStaticInitializer(EnumDefinition definition, JavaClassInfo toClass, ClassWriter writer) {
141
+		JavaMethodInfo clinitInfo = new JavaMethodInfo(toClass, "<clinit>", "()V", Opcodes.ACC_STATIC);
142
+        final JavaWriter clinitWriter = new JavaWriter(writer, clinitInfo, definition, null, null);
143
+        final JavaStatementVisitor clinitVisitor = new JavaStatementVisitor(clinitWriter);
144
+        clinitVisitor.start();
145
+		
146
+		List<EnumConstantMember> enumConstants = definition.getEnumConstants();
147
+		for (EnumConstantMember enumConstant : enumConstants) {
148
+			final String internalName = enumConstant.constructor.type.accept(JavaTypeVisitor.INSTANCE).getInternalName();
149
+
150
+			clinitWriter.newObject(internalName);
151
+			clinitWriter.dup();
152
+			clinitWriter.constant(enumConstant.name);
153
+			clinitWriter.constant(enumConstant.value);
154
+			for (Expression argument : enumConstant.constructor.arguments.arguments) {
155
+				argument.accept(clinitVisitor.expressionVisitor);
156
+			}
157
+			clinitWriter.invokeSpecial(internalName, "<init>", CompilerUtils.calcDesc(enumConstant.constructor.constructor.header, true));
158
+			clinitWriter.putStaticField(internalName, enumConstant.name, "L" + internalName + ";");
159
+		}
160
+
161
+        clinitWriter.constant(enumConstants.size());
162
+        clinitWriter.newArray(Type.getType("L" + definition.name + ";"));
163
+
164
+        for (EnumConstantMember enumConstant : enumConstants) {
165
+            clinitWriter.dup();
166
+            clinitWriter.constant(enumConstant.value);
167
+            clinitWriter.getStaticField(definition.name, enumConstant.name, "L" + definition.name + ";");
168
+            clinitWriter.arrayStore(Type.getType("L" + definition.name + ";"));
169
+        }
170
+        clinitWriter.putStaticField(definition.name, "$VALUES", "[L" + definition.name + ";");
171
+        clinitVisitor.end();
172
+	}
211 173
 
212 174
     @Override
213 175
     public byte[] visitStruct(StructDefinition definition) {
@@ -216,31 +178,24 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
216 178
 
217 179
     @Override
218 180
     public byte[] visitFunction(FunctionDefinition definition) {
181
+		CompilerUtils.tagMethodParameters(definition.header, true);
182
+		
219 183
         final String signature = CompilerUtils.calcSign(definition.header, false);
220 184
 		
221 185
 		final JavaClassInfo toClass = new JavaClassInfo(CompilerUtils.calcClasName(definition.position));
222 186
 		final JavaMethodInfo methodInfo = new JavaMethodInfo(toClass, definition.name, CompilerUtils.calcDesc(definition.header, false), CompilerUtils.calcAccess(definition.modifiers) | Opcodes.ACC_STATIC);
223 187
 
224
-		final JavaWriter writer = new JavaWriter(outerWriter, true, methodInfo, signature, null);
188
+		final JavaWriter writer = new JavaWriter(outerWriter, true, methodInfo, definition, signature, null);
225 189
         final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(writer);
226 190
         statementVisitor.start();
227
-        final Iterator<Statement> statementIterator = definition.statements.iterator();
228
-
229
-        //TODO this is dirty, fix when there is a way of knowing if a parameter is static or not
230
-        for (FunctionParameter parameter : definition.header.parameters) {
231
-            parameter.index -= 1;
232
-        }
233
-        while (statementIterator.hasNext()) {
234
-            final Statement statement = statementIterator.next();
235
-            statement.accept(statementVisitor);
236
-            if (!statementIterator.hasNext() && !(statement instanceof ReturnStatement)) {
237
-                ITypeID type = definition.header.returnType;
238
-                if (CompilerUtils.isPrimitive(type))
239
-                    writer.iConst0();
240
-                else if (type != BasicTypeID.VOID)
241
-                    writer.aConstNull();
242
-                writer.returnType(type.accept(JavaTypeVisitor.INSTANCE));
243
-            }
191
+		boolean returns = definition.statement.accept(statementVisitor);
192
+		if (!returns) {
193
+			ITypeID type = definition.header.returnType;
194
+			if (CompilerUtils.isPrimitive(type))
195
+				writer.iConst0();
196
+			else if (type != BasicTypeID.VOID)
197
+				writer.aConstNull();
198
+			writer.returnType(type.accept(JavaTypeVisitor.INSTANCE));
244 199
         }
245 200
 
246 201
         statementVisitor.end();

+ 44
- 36
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java Datei anzeigen

@@ -5,24 +5,26 @@ import org.objectweb.asm.Label;
5 5
 import org.objectweb.asm.Opcodes;
6 6
 import org.objectweb.asm.Type;
7 7
 import org.openzen.zenscript.codemodel.FunctionParameter;
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
8 9
 import org.openzen.zenscript.codemodel.Modifiers;
9
-import org.openzen.zenscript.codemodel.expression.Expression;
10
+import org.openzen.zenscript.codemodel.definition.EnumDefinition;
10 11
 import org.openzen.zenscript.codemodel.member.*;
11
-import org.openzen.zenscript.codemodel.statement.Statement;
12 12
 import org.openzen.zenscript.javabytecode.JavaClassInfo;
13
-import org.openzen.zenscript.javabytecode.JavaEnumInfo;
14 13
 import org.openzen.zenscript.javabytecode.JavaFieldInfo;
15 14
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
15
+import org.openzen.zenscript.javabytecode.JavaParameterInfo;
16 16
 import org.openzen.zenscript.javabytecode.compiler.*;
17 17
 
18 18
 public class JavaMemberVisitor implements MemberVisitor<Void> {
19 19
 
20 20
     private final ClassWriter writer;
21 21
 	private final JavaClassInfo toClass;
22
+	private final HighLevelDefinition definition;
22 23
 
23
-    public JavaMemberVisitor(ClassWriter writer, JavaClassInfo toClass) {
24
+    public JavaMemberVisitor(ClassWriter writer, JavaClassInfo toClass, HighLevelDefinition definition) {
24 25
         this.writer = writer;
25 26
 		this.toClass = toClass;
27
+		this.definition = definition;
26 28
     }
27 29
 
28 30
     @Override
@@ -38,25 +40,48 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
38 40
 
39 41
     @Override
40 42
     public Void visitConstructor(ConstructorMember member) {
41
-        final boolean isEnum = member.hasTag(JavaEnumInfo.class);
43
+		System.out.println("Compiling constructor " + member.header.toString());
44
+		
45
+        final boolean isEnum = definition instanceof EnumDefinition;
42 46
 		String descriptor = CompilerUtils.calcDesc(member.header, isEnum);
43 47
 		final JavaMethodInfo method = new JavaMethodInfo(toClass, "<init>", descriptor, isEnum ? Opcodes.ACC_PRIVATE : CompilerUtils.calcAccess(member.modifiers));
44 48
 		
45 49
         final Label constructorStart = new Label();
46 50
         final Label constructorEnd = new Label();
47
-        final JavaWriter constructorWriter = new JavaWriter(writer, method, CompilerUtils.calcSign(member.header, isEnum), null);
51
+        final JavaWriter constructorWriter = new JavaWriter(writer, method, definition, CompilerUtils.calcSign(member.header, isEnum), null);
48 52
         constructorWriter.label(constructorStart);
53
+		CompilerUtils.tagConstructorParameters(member.header, isEnum);
49 54
         for (FunctionParameter parameter : member.header.parameters) {
50
-            if(isEnum)
51
-                parameter.index += 2;
52
-            constructorWriter.nameVariable(parameter.index + 1, parameter.name, constructorStart, constructorEnd, Type.getType(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
55
+            constructorWriter.nameVariable(
56
+					parameter.getTag(JavaParameterInfo.class).index,
57
+					parameter.name,
58
+					constructorStart,
59
+					constructorEnd,
60
+					Type.getType(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
53 61
         }
62
+		
54 63
         final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(constructorWriter);
55 64
         statementVisitor.start();
56
-
57
-        for (Statement statement : member.body) {
58
-            statement.accept(statementVisitor);
59
-        }
65
+		
66
+		if (!member.isConstructorForwarded()) {
67
+			if (isEnum) {
68
+				System.out.println("Writing enum constructor");
69
+				constructorWriter.getVisitor().newLocal(Type.getType(String.class));
70
+				constructorWriter.getVisitor().newLocal(Type.getType(int.class));
71
+				constructorWriter.loadObject(0);
72
+				constructorWriter.loadObject(1);
73
+				constructorWriter.loadInt(2);
74
+				constructorWriter.invokeSpecial(Type.getInternalName(Enum.class), "<init>", "(Ljava/lang/String;I)V");
75
+			} else if (definition.superType == null) {
76
+				System.out.println("Writing regular constructor");
77
+				constructorWriter.load(Type.getType(Object.class), 0);
78
+				constructorWriter.invokeSpecial(Type.getInternalName(Object.class), "<init>", "()V");
79
+			}
80
+			
81
+			CompilerUtils.writeDefaultFieldInitializers(constructorWriter, definition);
82
+		}
83
+		
84
+        member.body.accept(statementVisitor);
60 85
         constructorWriter.label(constructorEnd);
61 86
         statementVisitor.end();
62 87
         return null;
@@ -64,7 +89,9 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
64 89
 
65 90
     @Override
66 91
     public Void visitMethod(MethodMember member) {
67
-        final boolean isAbstract = member.body == null || member.body.isEmpty() || Modifiers.isAbstract(member.modifiers);
92
+		CompilerUtils.tagMethodParameters(member.header, member.isStatic());
93
+		
94
+        final boolean isAbstract = member.body == null || Modifiers.isAbstract(member.modifiers);
68 95
 		int modifiers = (isAbstract ? Opcodes.ACC_ABSTRACT : 0)
69 96
 				| (member.isStatic() ? Opcodes.ACC_STATIC : 0)
70 97
 				| CompilerUtils.calcAccess(member.modifiers);
@@ -76,22 +103,19 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
76 103
 		
77 104
         final Label methodStart = new Label();
78 105
         final Label methodEnd = new Label();
79
-        final JavaWriter methodWriter = new JavaWriter(writer, method, CompilerUtils.calcSign(member.header, false), null);
106
+        final JavaWriter methodWriter = new JavaWriter(writer, method, definition, CompilerUtils.calcSign(member.header, false), null);
80 107
         methodWriter.label(methodStart);
81 108
         for (final FunctionParameter parameter : member.header.parameters) {
82 109
             methodWriter.nameParameter(0, parameter.name);
83 110
             if (!isAbstract)
84
-                methodWriter.nameVariable(parameter.index + (member.isStatic() ? 0 : 1), parameter.name, methodStart, methodEnd, Type.getType(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
111
+                methodWriter.nameVariable(parameter.getTag(JavaParameterInfo.class).index, parameter.name, methodStart, methodEnd, Type.getType(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
85 112
         }
86 113
 
87 114
         final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(methodWriter);
88 115
 
89 116
         if (!isAbstract) {
90 117
             statementVisitor.start();
91
-            for (Statement statement : member.body) {
92
-                statement.accept(statementVisitor);
93
-            }
94
-
118
+			member.body.accept(statementVisitor);
95 119
             methodWriter.label(methodEnd);
96 120
             statementVisitor.end();
97 121
         }
@@ -112,21 +136,6 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
112 136
 
113 137
     @Override
114 138
     public Void visitEnumConstant(EnumConstantMember member) {
115
-        final JavaStatementVisitor clinitVisitor = member.getTag(JavaEnumInfo.class).clinitVisitor;
116
-        final JavaWriter clinitWriter = clinitVisitor.getJavaWriter();
117
-        final String internalName = member.constructor.type.accept(JavaTypeVisitor.INSTANCE).getInternalName();
118
-
119
-        clinitWriter.newObject(internalName);
120
-        clinitWriter.dup();
121
-        clinitWriter.constant(member.name);
122
-        clinitWriter.constant(member.value);
123
-        for (Expression argument : member.constructor.arguments.arguments) {
124
-            argument.accept(clinitVisitor.expressionVisitor);
125
-        }
126
-        clinitWriter.invokeSpecial(internalName, "<init>", CompilerUtils.calcDesc(member.constructor.constructor.header, true));
127
-        clinitWriter.putStaticField(internalName, member.name, "L" + internalName + ";");
128
-
129
-
130 139
         return null;
131 140
     }
132 141
 
@@ -159,5 +168,4 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
159 168
     public Void visitInnerDefinition(InnerDefinitionMember member) {
160 169
         return null;
161 170
     }
162
-
163 171
 }

+ 2
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java Datei anzeigen

@@ -7,7 +7,6 @@
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import java.util.HashMap;
10
-import java.util.List;
11 10
 import java.util.Map;
12 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 12
 import org.openzen.zenscript.codemodel.expression.FunctionExpression;
@@ -66,10 +65,10 @@ public class ParsedExpressionFunction extends ParsedExpression {
66 65
 		
67 66
 		LambdaClosure closure = new LambdaClosure();
68 67
 		StatementScope innerScope = new LambdaScope(scope, closure, header);
69
-		List<Statement> statements = body.compile(innerScope, header);
68
+		Statement statements = body.compile(innerScope, header);
70 69
 		if (!scope.genericInferenceMap.isEmpty()) {
71 70
 			// perform type parameter inference
72
-			ITypeID returnType = Statement.getReturnType(scope, statements);
71
+			ITypeID returnType = statements.getReturnType();
73 72
 			Map<TypeParameter, ITypeID> inferredTypes = new HashMap<>();
74 73
 			if (!genericHeader.returnType.inferTypeParameters(returnType, inferredTypes))
75 74
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");

+ 3
- 4
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedEmptyFunctionBody.java Datei anzeigen

@@ -5,9 +5,8 @@
5 5
  */
6 6
 package org.openzen.zenscript.parser.statements;
7 7
 
8
-import java.util.Collections;
9
-import java.util.List;
10 8
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
+import org.openzen.zenscript.codemodel.statement.EmptyStatement;
11 10
 import org.openzen.zenscript.codemodel.statement.Statement;
12 11
 import org.openzen.zenscript.linker.StatementScope;
13 12
 import org.openzen.zenscript.shared.CodePosition;
@@ -24,7 +23,7 @@ public class ParsedEmptyFunctionBody extends ParsedFunctionBody {
24 23
 	}
25 24
 	
26 25
 	@Override
27
-	public List<Statement> compile(StatementScope scope, FunctionHeader header) {
28
-		return Collections.emptyList();
26
+	public Statement compile(StatementScope scope, FunctionHeader header) {
27
+		return new EmptyStatement(position);
29 28
 	}
30 29
 }

+ 1
- 2
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedFunctionBody.java Datei anzeigen

@@ -5,7 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.parser.statements;
7 7
 
8
-import java.util.List;
9 8
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 9
 import org.openzen.zenscript.codemodel.statement.Statement;
11 10
 import org.openzen.zenscript.linker.StatementScope;
@@ -15,5 +14,5 @@ import org.openzen.zenscript.linker.StatementScope;
15 14
  * @author Hoofdgebruiker
16 15
  */
17 16
 public abstract class ParsedFunctionBody {
18
-	public abstract List<Statement> compile(StatementScope scope, FunctionHeader header);
17
+	public abstract Statement compile(StatementScope scope, FunctionHeader header);
19 18
 }

+ 3
- 8
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedLambdaFunctionBody.java Datei anzeigen

@@ -5,8 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.parser.statements;
7 7
 
8
-import java.util.ArrayList;
9
-import java.util.List;
10 8
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 9
 import org.openzen.zenscript.codemodel.expression.Expression;
12 10
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
@@ -29,19 +27,16 @@ public class ParsedLambdaFunctionBody extends ParsedFunctionBody {
29 27
 	}
30 28
 	
31 29
 	@Override
32
-	public List<Statement> compile(StatementScope scope, FunctionHeader header) {
33
-		List<Statement> statements = new ArrayList<>();
30
+	public Statement compile(StatementScope scope, FunctionHeader header) {
34 31
 		if (header.returnType == BasicTypeID.VOID) {
35 32
 			Expression value = this.value.compile(new ExpressionScope(scope)).eval();
36
-			statements.add(new ExpressionStatement(value.position, value));
37
-			statements.add(new ReturnStatement(value.position, null));
33
+			return new ExpressionStatement(value.position, value);
38 34
 		} else {
39 35
 			Expression returnValue = value
40 36
 					.compile(new ExpressionScope(scope, header.returnType))
41 37
 					.eval()
42 38
 					.castImplicit(value.position, scope, header.returnType);
43
-			statements.add(new ReturnStatement(value.position, returnValue));
39
+			return new ReturnStatement(value.position, returnValue);
44 40
 		}
45
-		return statements;
46 41
 	}
47 42
 }

+ 4
- 2
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatement.java Datei anzeigen

@@ -17,12 +17,13 @@ import org.openzen.zenscript.shared.CodePosition;
17 17
 
18 18
 public abstract class ParsedStatement {
19 19
 	public static ParsedFunctionBody parseLambdaBody(ZSTokenStream tokens, boolean inExpression) {
20
+		ZSToken start = tokens.peek();
20 21
 		if (tokens.optional(T_AOPEN) != null) {
21 22
 			List<ParsedStatement> statements = new ArrayList<>();
22 23
 			while (tokens.optional(T_ACLOSE) == null)
23 24
 				statements.add(ParsedStatement.parse(tokens));
24 25
 			
25
-			return new ParsedStatementsFunctionBody(statements);
26
+			return new ParsedStatementsFunctionBody(new ParsedStatementBlock(start.position, null, null, statements));
26 27
 		} else {
27 28
 			ParsedFunctionBody result = new ParsedLambdaFunctionBody(ParsedExpression.parse(tokens));
28 29
 			if (!inExpression)
@@ -32,6 +33,7 @@ public abstract class ParsedStatement {
32 33
 	}
33 34
 	
34 35
 	public static ParsedFunctionBody parseFunctionBody(ZSTokenStream tokens) {
36
+		ZSToken start = tokens.peek();
35 37
 		if (tokens.optional(T_LAMBDA) != null) {
36 38
 			return parseLambdaBody(tokens, false);
37 39
 		} else if (tokens.optional(T_SEMICOLON) != null) {
@@ -42,7 +44,7 @@ public abstract class ParsedStatement {
42 44
 			while (tokens.optional(T_ACLOSE) == null) {
43 45
 				statements.add(ParsedStatement.parse(tokens));
44 46
 			}
45
-			return new ParsedStatementsFunctionBody(statements);
47
+			return new ParsedStatementsFunctionBody(new ParsedStatementBlock(start.position, null, null, statements));
46 48
 		}
47 49
 	}
48 50
 	

+ 5
- 9
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementsFunctionBody.java Datei anzeigen

@@ -5,8 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.parser.statements;
7 7
 
8
-import java.util.List;
9
-import java.util.stream.Collectors;
10 8
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 9
 import org.openzen.zenscript.codemodel.statement.Statement;
12 10
 import org.openzen.zenscript.linker.StatementScope;
@@ -16,16 +14,14 @@ import org.openzen.zenscript.linker.StatementScope;
16 14
  * @author Hoofdgebruiker
17 15
  */
18 16
 public class ParsedStatementsFunctionBody extends ParsedFunctionBody {
19
-	private final List<ParsedStatement> statements;
17
+	private final ParsedStatement body;
20 18
 	
21
-	public ParsedStatementsFunctionBody(List<ParsedStatement> statements) {
22
-		this.statements = statements;
19
+	public ParsedStatementsFunctionBody(ParsedStatement body) {
20
+		this.body = body;
23 21
 	}
24 22
 	
25 23
 	@Override
26
-	public List<Statement> compile(StatementScope scope, FunctionHeader header) {
27
-		return statements.stream()
28
-				.map(s -> s.compile(scope))
29
-				.collect(Collectors.toList());
24
+	public Statement compile(StatementScope scope, FunctionHeader header) {
25
+		return body.compile(scope);
30 26
 	}
31 27
 }

+ 1
- 0
Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java Datei anzeigen

@@ -44,6 +44,7 @@ public class ValidationLogEntry {
44 44
 		VARIADIC_PARAMETER_MUST_BE_LAST,
45 45
 		CONSTRUCTOR_FORWARD_OUTSIDE_CONSTRUCTOR,
46 46
 		CONSTRUCTOR_FORWARD_NOT_FIRST_STATEMENT,
47
+		CONSTRUCTOR_FORWARD_MISSING,
47 48
 		DUPLICATE_CONSTRUCTOR,
48 49
 		DUPLICATE_METHOD,
49 50
 		BODY_REQUIRED,

+ 10
- 24
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java Datei anzeigen

@@ -25,7 +25,6 @@ import org.openzen.zenscript.codemodel.member.MemberVisitor;
25 25
 import org.openzen.zenscript.codemodel.member.MethodMember;
26 26
 import org.openzen.zenscript.codemodel.member.OperatorMember;
27 27
 import org.openzen.zenscript.codemodel.member.SetterMember;
28
-import org.openzen.zenscript.codemodel.statement.Statement;
29 28
 import org.openzen.zenscript.codemodel.statement.VarStatement;
30 29
 import org.openzen.zenscript.codemodel.type.ITypeID;
31 30
 import org.openzen.zenscript.validator.ValidationLogEntry;
@@ -89,12 +88,11 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
89 88
 			validator.logError(ValidationLogEntry.Code.BODY_REQUIRED, member.position, "Constructors must have a body");
90 89
 		} else {
91 90
 			StatementValidator statementValidator = new StatementValidator(validator, new ConstructorStatementScope(member.header));
92
-			for (Statement statement : member.body) {
93
-				isValid &= statement.accept(statementValidator);
94
-			}
91
+			isValid &= member.body.accept(statementValidator);
95 92
 			
96
-			if (!statementValidator.constructorForwarded) {
97
-				// TODO: does this type have a supertype with no-argument constructor?
93
+			if (member.definition.superType != null && !statementValidator.constructorForwarded) {
94
+				validator.logError(ValidationLogEntry.Code.CONSTRUCTOR_FORWARD_MISSING, member.position, "Constructor not forwarded to base type");
95
+				isValid &= false;
98 96
 			}
99 97
 		}
100 98
 		
@@ -109,9 +107,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
109 107
 		
110 108
 		if (member.body != null) {
111 109
 			StatementValidator statementValidator = new StatementValidator(validator, new ConstructorStatementScope(member.header));
112
-			for (Statement statement : member.body) {
113
-				isValid &= statement.accept(statementValidator);
114
-			}
110
+			isValid &= member.body.accept(statementValidator);
115 111
 		}
116 112
 		
117 113
 		return isValid;
@@ -125,9 +121,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
125 121
 		
126 122
 		if (member.body != null) {
127 123
 			StatementValidator statementValidator = new StatementValidator(validator, new ConstructorStatementScope(member.header));
128
-			for (Statement statement : member.body) {
129
-				isValid &= statement.accept(statementValidator);
130
-			}
124
+			isValid &= member.body.accept(statementValidator);
131 125
 		}
132 126
 		
133 127
 		return isValid;
@@ -141,9 +135,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
141 135
 		
142 136
 		if (member.body != null) {
143 137
 			StatementValidator statementValidator = new StatementValidator(validator, new ConstructorStatementScope(member.header));
144
-			for (Statement statement : member.body) {
145
-				isValid &= statement.accept(statementValidator);
146
-			}
138
+			isValid &= member.body.accept(statementValidator);
147 139
 		}
148 140
 		
149 141
 		return isValid;
@@ -172,9 +164,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
172 164
 		
173 165
 		if (member.body != null) {
174 166
 			StatementValidator statementValidator = new StatementValidator(validator, new ConstructorStatementScope(member.header));
175
-			for (Statement statement : member.body) {
176
-				isValid &= statement.accept(statementValidator);
177
-			}
167
+			isValid &= member.body.accept(statementValidator);
178 168
 		}
179 169
 		
180 170
 		return isValid;
@@ -187,9 +177,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
187 177
 		
188 178
 		if (member.body != null) {
189 179
 			StatementValidator statementValidator = new StatementValidator(validator, new ConstructorStatementScope(member.header));
190
-			for (Statement statement : member.body) {
191
-				isValid &= statement.accept(statementValidator);
192
-			}
180
+			isValid &= member.body.accept(statementValidator);
193 181
 		}
194 182
 		
195 183
 		return isValid;
@@ -207,9 +195,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
207 195
 		
208 196
 		if (member.body != null) {
209 197
 			StatementValidator statementValidator = new StatementValidator(validator, new ConstructorStatementScope(member.header));
210
-			for (Statement statement : member.body) {
211
-				isValid &= statement.accept(statementValidator);
212
-			}
198
+			isValid &= member.body.accept(statementValidator);
213 199
 		}
214 200
 		
215 201
 		return isValid;

+ 1
- 4
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java Datei anzeigen

@@ -17,7 +17,6 @@ import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
17 17
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
18 18
 import org.openzen.zenscript.codemodel.definition.StructDefinition;
19 19
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20
-import org.openzen.zenscript.codemodel.statement.Statement;
21 20
 import org.openzen.zenscript.validator.Validator;
22 21
 import org.openzen.zenscript.validator.analysis.StatementScope;
23 22
 
@@ -122,9 +121,7 @@ public class DefinitionValidator implements DefinitionVisitor<Boolean> {
122 121
 				definition.name);
123 122
 				
124 123
 		StatementValidator statementValidator = new StatementValidator(validator, new FunctionStatementScope(definition.header));
125
-		for (Statement statement : definition.statements) {
126
-			isValid &= statement.accept(statementValidator);
127
-		}
124
+		isValid &= definition.statement.accept(statementValidator);
128 125
 		return isValid;
129 126
 	}
130 127
 

Laden…
Abbrechen
Speichern