Pārlūkot izejas kodu

Initial commit.

Stan Hebben 6 gadus atpakaļ
revīzija
ed994e4d3b
100 mainītis faili ar 3782 papildinājumiem un 0 dzēšanām
  1. 3
    0
      .gitignore
  2. 18
    0
      CodeModel/build.gradle
  3. 14
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/AccessScope.java
  4. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/CompareType.java
  5. 218
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  6. 83
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionParameter.java
  7. 65
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java
  8. 43
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/Modifiers.java
  9. 62
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/OperatorType.java
  10. 48
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/PackageDefinitions.java
  11. 21
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/ScriptBlock.java
  12. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/AliasDefinition.java
  13. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ClassDefinition.java
  14. 26
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/DefinitionVisitor.java
  15. 23
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/EnumDefinition.java
  16. 26
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ExpansionDefinition.java
  17. 37
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java
  18. 32
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/InterfaceDefinition.java
  19. 23
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/StructDefinition.java
  20. 94
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java
  21. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/AndAndExpression.java
  22. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ArrayExpression.java
  23. 35
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/BasicCompareExpression.java
  24. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallArguments.java
  25. 33
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallExpression.java
  26. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java
  27. 27
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedClosureExpression.java
  28. 26
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedDirectExpression.java
  29. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedExpression.java
  30. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedLocalVariableExpression.java
  31. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedParameterExpression.java
  32. 24
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedThisExpression.java
  33. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CheckNullExpression.java
  34. 29
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CoalesceExpression.java
  35. 40
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConditionalExpression.java
  36. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantBoolExpression.java
  37. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantByteExpression.java
  38. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantCharExpression.java
  39. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantDoubleExpression.java
  40. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantFloatExpression.java
  41. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantIntExpression.java
  42. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantLongExpression.java
  43. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantSByteExpression.java
  44. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantShortExpression.java
  45. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantStringExpression.java
  46. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUIntExpression.java
  47. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantULongExpression.java
  48. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUShortExpression.java
  49. 34
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstructorCallExpression.java
  50. 38
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EnumConstantExpression.java
  51. 31
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EqualsExpression.java
  52. 82
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java
  53. 124
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java
  54. 39
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/FunctionExpression.java
  55. 31
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GenericCompareExpression.java
  56. 43
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFieldExpression.java
  57. 41
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFunctionParameterExpression.java
  58. 41
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetLocalVariableExpression.java
  59. 41
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetStaticFieldExpression.java
  60. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetterExpression.java
  61. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/InterfaceCastExpression.java
  62. 31
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/IsExpression.java
  63. 16
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/LambdaClosure.java
  64. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MakeConstExpression.java
  65. 34
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MapExpression.java
  66. 31
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/NewExpression.java
  67. 27
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/NotExpression.java
  68. 29
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/NullExpression.java
  69. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/OrOrExpression.java
  70. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/RangeExpression.java
  71. 32
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetFieldExpression.java
  72. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetFunctionParameterExpression.java
  73. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetLocalVariableExpression.java
  74. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetStaticFieldExpression.java
  75. 32
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetterExpression.java
  76. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StaticGetterExpression.java
  77. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StaticSetterExpression.java
  78. 31
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StringConcatExpression.java
  79. 29
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SubstringExpression.java
  80. 32
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ThisExpression.java
  81. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/WrapOptionalExpression.java
  82. 24
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/GenericParameterBound.java
  83. 39
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterSuperBound.java
  84. 43
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java
  85. 60
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java
  86. 20
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/iterator/ForeachIteratorVisitor.java
  87. 45
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CallerMember.java
  88. 68
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CasterMember.java
  89. 47
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java
  90. 74
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CustomIteratorMember.java
  91. 32
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DefinitionMember.java
  92. 49
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EnumConstantMember.java
  93. 92
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EqualsMember.java
  94. 58
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java
  95. 61
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java
  96. 76
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java
  97. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ICallableMember.java
  98. 22
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ICasterMember.java
  99. 30
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IDefinitionMember.java
  100. 0
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IGettableMember.java

+ 3
- 0
.gitignore Parādīt failu

@@ -0,0 +1,3 @@
1
+.gradle
2
+.nb-gradle
3
+build

+ 18
- 0
CodeModel/build.gradle Parādīt failu

@@ -0,0 +1,18 @@
1
+// Note: "common.gradle" in the root project contains additional initialization
2
+//   for this project. This initialization is applied in the "build.gradle"
3
+//   of the root project.
4
+
5
+// NetBeans will automatically add "run" and "debug" tasks relying on the
6
+// "mainClass" property. You may however define the property prior executing
7
+// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
8
+//
9
+// Note however, that you may define your own "run" and "debug" task if you
10
+// prefer. In this case NetBeans will not add these tasks but you may rely on
11
+// your own implementation.
12
+if (!hasProperty('mainClass')) {
13
+    ext.mainClass = ''
14
+}
15
+
16
+dependencies {
17
+	compile project(':Shared')
18
+}

+ 14
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/AccessScope.java Parādīt failu

@@ -0,0 +1,14 @@
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.codemodel;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class AccessScope {
13
+	
14
+}

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/CompareType.java Parādīt failu

@@ -0,0 +1,17 @@
1
+package org.openzen.zenscript.codemodel;
2
+
3
+/**
4
+ * Used to indicate comparison types.
5
+ * 
6
+ * @author Stan Hebben
7
+ */
8
+public enum CompareType {
9
+	LT,
10
+	GT,
11
+	EQ,
12
+	NE,
13
+	LE,
14
+	GE,
15
+	SAME,
16
+	NOTSAME
17
+}

+ 218
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java Parādīt failu

@@ -0,0 +1,218 @@
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.codemodel;
7
+
8
+import java.util.HashMap;
9
+import java.util.List;
10
+import java.util.Map;
11
+import org.openzen.zenscript.codemodel.expression.CallArguments;
12
+import org.openzen.zenscript.codemodel.expression.Expression;
13
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
15
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
+import org.openzen.zenscript.codemodel.type.ITypeID;
17
+import org.openzen.zenscript.codemodel.scope.TypeScope;
18
+
19
+/**
20
+ *
21
+ * @author Hoofdgebruiker
22
+ */
23
+public class FunctionHeader {
24
+	private static final TypeParameter[] NO_GENERIC_PARAMETERS = new TypeParameter[0];
25
+	private static final FunctionParameter[] NO_PARAMETERS = new FunctionParameter[0];
26
+	
27
+	public final TypeParameter[] typeParameters;
28
+	public final ITypeID returnType;
29
+	public final FunctionParameter[] parameters;
30
+	
31
+	public FunctionHeader(ITypeID returnType) {
32
+		this.typeParameters = NO_GENERIC_PARAMETERS;
33
+		this.returnType = returnType;
34
+		this.parameters = NO_PARAMETERS;
35
+	}
36
+	
37
+	public FunctionHeader(ITypeID returnType, FunctionParameter... parameters) {
38
+		this.typeParameters = NO_GENERIC_PARAMETERS;
39
+		this.returnType = returnType;
40
+		this.parameters = parameters;
41
+	}
42
+	
43
+	public FunctionHeader(TypeParameter[] genericParameters, ITypeID returnType, FunctionParameter[] parameters) {
44
+		this.typeParameters = genericParameters;
45
+		this.returnType = returnType;
46
+		this.parameters = parameters;
47
+	}
48
+	
49
+	public FunctionHeader instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
50
+		TypeParameter[] genericParameters = new TypeParameter[this.typeParameters.length];
51
+		for (int i = 0; i < genericParameters.length; i++)
52
+			genericParameters[i] = this.typeParameters[i].withGenericArguments(registry, mapping);
53
+		ITypeID returnType = this.returnType.withGenericArguments(registry, mapping);
54
+		FunctionParameter[] parameters = new FunctionParameter[this.parameters.length];
55
+		for (int i = 0; i < parameters.length; i++)
56
+			parameters[i] = this.parameters[i].withGenericArguments(registry, mapping);
57
+		
58
+		return new FunctionHeader(genericParameters, returnType, parameters);
59
+	}
60
+	
61
+	public ITypeID[] inferTypes(CallArguments arguments, List<ITypeID> resultHint) {
62
+		if (arguments.arguments.length != this.parameters.length)
63
+			return null;
64
+		
65
+		Map<TypeParameter, ITypeID> mapping = new HashMap<>();
66
+		if (!resultHint.isEmpty()) {
67
+			Map<TypeParameter, ITypeID> temp = new HashMap<>();
68
+			for (ITypeID hint : resultHint) {
69
+				if (returnType.inferTypeParameters(hint, temp)) {
70
+					mapping = temp;
71
+					break;
72
+				}
73
+			}
74
+		}
75
+		
76
+		// TODO: lambda header inference
77
+		for (int i = 0; i < parameters.length; i++)
78
+			if (!parameters[i].type.inferTypeParameters(arguments.arguments[i].type, mapping))
79
+				return null;
80
+		
81
+		if (mapping.size() > typeParameters.length)
82
+			return null;
83
+		
84
+		ITypeID[] result = new ITypeID[typeParameters.length];
85
+		for (int i = 0; i < typeParameters.length; i++) {
86
+			TypeParameter typeParameter = typeParameters[i];
87
+			if (!mapping.containsKey(typeParameter)) {
88
+				return null;
89
+			} else {
90
+				result[i] = mapping.get(typeParameter);
91
+			}
92
+		}
93
+		
94
+		return result;
95
+	}
96
+	
97
+	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
98
+		for (int i = 0; i < this.parameters.length; i++)
99
+			if (this.parameters[i].type.hasInferenceBlockingTypeParameters(parameters))
100
+				return true;
101
+		
102
+		return false;
103
+	}
104
+	
105
+	public boolean canCastTo(TypeScope scope, FunctionHeader header) {
106
+		if (parameters.length != header.parameters.length)
107
+			return false;
108
+		
109
+		if (!scope.getTypeMembers(returnType).canCastImplicit(header.returnType))
110
+			return false;
111
+		
112
+		for (int i = 0; i < parameters.length; i++) {
113
+			if (!scope.getTypeMembers(header.parameters[i].type).canCastImplicit(parameters[i].type))
114
+				return false;
115
+		}
116
+		
117
+		return true;
118
+	}
119
+	
120
+	public boolean accepts(TypeScope scope, Expression... arguments) {
121
+		if (parameters.length != arguments.length)
122
+			return false;
123
+		
124
+		for (int i = 0; i < arguments.length; i++) {
125
+			if (!scope.getTypeMembers(arguments[i].type).canCastImplicit(parameters[i].type))
126
+				return false;
127
+		}
128
+		
129
+		return true;
130
+	}
131
+	
132
+	public boolean isEquivalentTo(FunctionHeader other) {
133
+		if (parameters.length != other.parameters.length)
134
+			return false;
135
+		
136
+		for (int i = 0; i < parameters.length; i++) {
137
+			if (parameters[i] != other.parameters[i])
138
+				return false;
139
+		}
140
+		
141
+		return true;
142
+	}
143
+	
144
+	public FunctionHeader withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
145
+		ITypeID returnType = this.returnType.withGenericArguments(registry, arguments);
146
+		FunctionParameter[] parameters = new FunctionParameter[this.parameters.length];
147
+		for (int i = 0; i < parameters.length; i++) {
148
+			ITypeID modified = this.parameters[i].type.withGenericArguments(registry, arguments);
149
+			parameters[i] = modified == this.parameters[i].type ? this.parameters[i] : new FunctionParameter(modified, this.parameters[i].name);
150
+		}
151
+		return new FunctionHeader(typeParameters, returnType, parameters);
152
+	}
153
+	
154
+	public FunctionHeader withGenericArguments(GlobalTypeRegistry registry, ITypeID[] arguments) {
155
+		Map<TypeParameter, ITypeID> typeArguments = new HashMap<>();
156
+		for (int i = 0; i < typeParameters.length; i++)
157
+			typeArguments.put(typeParameters[i], arguments[i]);
158
+		
159
+		ITypeID returnType = this.returnType.withGenericArguments(registry, typeArguments);
160
+		FunctionParameter[] parameters = new FunctionParameter[this.parameters.length];
161
+		for (int i = 0; i < parameters.length; i++) {
162
+			ITypeID modified = this.parameters[i].type.withGenericArguments(registry, typeArguments);
163
+			parameters[i] = modified == this.parameters[i].type ? this.parameters[i] : new FunctionParameter(modified, this.parameters[i].name);
164
+		}
165
+		return new FunctionHeader(returnType, parameters);
166
+	}
167
+	
168
+	public FunctionHeader forTypeParameterInference() {
169
+		return new FunctionHeader(BasicTypeID.UNDETERMINED, parameters);
170
+	}
171
+	
172
+	public FunctionHeader forLambda(FunctionHeader lambdaHeader) {
173
+		FunctionParameter[] parameters = new FunctionParameter[lambdaHeader.parameters.length];
174
+		for (int i = 0; i < lambdaHeader.parameters.length; i++)
175
+			parameters[i] = new FunctionParameter(this.parameters[i].type, lambdaHeader.parameters[i].name);
176
+		
177
+		return new FunctionHeader(typeParameters, returnType, parameters);
178
+		//return this;
179
+	}
180
+	
181
+	public String explainWhyIncompatible(TypeScope scope, CallArguments arguments) {
182
+		if (this.parameters.length != arguments.arguments.length)
183
+			return parameters.length + " parameters expected but " + arguments.arguments.length + " given.";
184
+		
185
+		if (typeParameters.length != arguments.typeArguments.length)
186
+			return typeParameters.length + " type parameters expected but " + arguments.typeArguments.length + " given.";
187
+		
188
+		for (int i = 0; i < parameters.length; i++) {
189
+			if (!scope.getTypeMembers(arguments.arguments[i].getType()).canCastImplicit(parameters[i].type)) {
190
+				return "Parameter " + i + ": cannot cast " + arguments.arguments[i].getType() + " to " + parameters[i].type;
191
+			}
192
+		}
193
+		
194
+		return "Method should be compatible";
195
+	}
196
+	
197
+	@Override
198
+	public String toString() {
199
+		StringBuilder result = new StringBuilder();
200
+		if (typeParameters.length > 0) {
201
+			result.append("<");
202
+			for (int i = 0; i < typeParameters.length; i++) {
203
+				if (i > 0)
204
+					result.append(", ");
205
+				result.append(typeParameters[i].toString());
206
+			}
207
+			result.append(">");
208
+		}
209
+		result.append("(");
210
+		for (int i = 0; i < parameters.length; i++) {
211
+			if (i > 0)
212
+				result.append(", ");
213
+			result.append(parameters[i].toString());
214
+		}
215
+		result.append(")");
216
+		return result.toString();
217
+	}
218
+}

+ 83
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionParameter.java Parādīt failu

@@ -0,0 +1,83 @@
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.codemodel;
7
+
8
+import java.util.Map;
9
+import java.util.Objects;
10
+import org.openzen.zenscript.codemodel.expression.Expression;
11
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13
+import org.openzen.zenscript.codemodel.type.ITypeID;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class FunctionParameter {
20
+	public final ITypeID type;
21
+	public final String name;
22
+	public final Expression defaultValue;
23
+	public final boolean variadic;
24
+	
25
+	public FunctionParameter(ITypeID type) {
26
+		this.type = type;
27
+		this.name = "";
28
+		this.defaultValue = null;
29
+		this.variadic = false;
30
+	}
31
+	
32
+	public FunctionParameter(ITypeID type, String name) {
33
+		this.type = type;
34
+		this.name = name;
35
+		this.defaultValue = null;
36
+		this.variadic = false;
37
+	}
38
+	
39
+	public FunctionParameter(ITypeID type, String name, Expression defaultValue, boolean variadic) {
40
+		this.type = type;
41
+		this.name = name;
42
+		this.defaultValue = defaultValue;
43
+		this.variadic = variadic;
44
+	}
45
+	
46
+	public FunctionParameter withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
47
+		return new FunctionParameter(type.withGenericArguments(registry, arguments), name, defaultValue, variadic);
48
+	}
49
+	
50
+	@Override
51
+	public String toString() {
52
+		return name + " as " + type.toString();
53
+	}
54
+
55
+	@Override
56
+	public int hashCode() {
57
+		int hash = 5;
58
+		hash = 17 * hash + Objects.hashCode(this.type);
59
+		hash = 17 * hash + (this.variadic ? 1 : 0);
60
+		return hash;
61
+	}
62
+
63
+	@Override
64
+	public boolean equals(Object obj) {
65
+		if (this == obj) {
66
+			return true;
67
+		}
68
+		if (obj == null) {
69
+			return false;
70
+		}
71
+		if (getClass() != obj.getClass()) {
72
+			return false;
73
+		}
74
+		final FunctionParameter other = (FunctionParameter) obj;
75
+		if (this.variadic != other.variadic) {
76
+			return false;
77
+		}
78
+		if (!Objects.equals(this.type, other.type)) {
79
+			return false;
80
+		}
81
+		return true;
82
+	}
83
+}

+ 65
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java Parādīt failu

@@ -0,0 +1,65 @@
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.codemodel;
7
+
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+import org.openzen.zenscript.codemodel.definition.DefinitionVisitor;
11
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.member.FieldMember;
13
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
14
+import org.openzen.zenscript.codemodel.type.ITypeID;
15
+
16
+/**
17
+ *
18
+ * @author Hoofdgebruiker
19
+ */
20
+public abstract class HighLevelDefinition {
21
+	public final String name;
22
+	public final int modifiers;
23
+	public final List<IDefinitionMember> members = new ArrayList<>();
24
+	public final List<TypeParameter> genericParameters = new ArrayList<>();
25
+	
26
+	public HighLevelDefinition outerDefinition;
27
+	public ITypeID superType;
28
+	
29
+	public HighLevelDefinition(String name, int modifiers, HighLevelDefinition outerDefinition) {
30
+		this.name = name;
31
+		this.modifiers = modifiers;
32
+		this.outerDefinition = outerDefinition;
33
+	}
34
+	
35
+	public void setOuterDefinition(HighLevelDefinition outerDefinition) {
36
+		this.outerDefinition = outerDefinition;
37
+	}
38
+	
39
+	public boolean isInnerDefinition() {
40
+		return outerDefinition != null;
41
+	}
42
+	
43
+	public void addMember(IDefinitionMember member) {
44
+		if (!members.contains(member))
45
+			members.add(member);
46
+	}
47
+	
48
+	public void addGenericParameter(TypeParameter parameter) {
49
+		genericParameters.add(parameter);
50
+	}
51
+	
52
+	public List<FieldMember> getFields() {
53
+		List<FieldMember> fields = new ArrayList<>();
54
+		for (IDefinitionMember member : members)
55
+			if (member instanceof FieldMember)
56
+				fields.add((FieldMember)member);
57
+		return fields;
58
+	}
59
+	
60
+	public boolean isStatic() {
61
+		return (modifiers & Modifiers.MODIFIER_STATIC) > 0;
62
+	}
63
+	
64
+	public abstract <T> T accept(DefinitionVisitor<T> visitor);
65
+}

+ 43
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/Modifiers.java Parādīt failu

@@ -0,0 +1,43 @@
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.codemodel;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class Modifiers {
13
+	public static final int MODIFIER_PUBLIC = 1;
14
+	public static final int MODIFIER_EXPORT = 2;
15
+	public static final int MODIFIER_PRIVATE = 4;
16
+	public static final int MODIFIER_ABSTRACT = 8;
17
+	public static final int MODIFIER_FINAL = 16;
18
+	public static final int MODIFIER_CONST = 32;
19
+	public static final int MODIFIER_CONST_OPTIONAL = 64;
20
+	public static final int MODIFIER_STATIC = 128;
21
+	public static final int MODIFIER_PROTECTED = 256;
22
+	public static final int MODIFIER_IMPLICIT = 512;
23
+	
24
+	public static boolean isAbstract(int modifiers) {
25
+		return (modifiers & MODIFIER_ABSTRACT) > 0;
26
+	}
27
+	
28
+	public static boolean isFinal(int modifiers) {
29
+		return (modifiers & MODIFIER_FINAL) > 0;
30
+	}
31
+	
32
+	public static boolean isConst(int modifiers) {
33
+		return (modifiers & MODIFIER_CONST) > 0;
34
+	}
35
+	
36
+	public static boolean isStatic(int modifiers) {
37
+		return (modifiers & MODIFIER_STATIC) > 0;
38
+	}
39
+	
40
+	public static boolean isImplicit(int modifiers) {
41
+		return (modifiers & MODIFIER_IMPLICIT) > 0;
42
+	}
43
+}

+ 62
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/OperatorType.java Parādīt failu

@@ -0,0 +1,62 @@
1
+package org.openzen.zenscript.codemodel;
2
+
3
+/**
4
+ * Enum used to indicate operator type.
5
+ * 
6
+ * @author Stan Hebben
7
+ */
8
+public enum OperatorType {
9
+	ADD("+", "add"),
10
+	SUB("-", "subtract"),
11
+	MUL("*", "multiply"),
12
+	DIV("/", "divide"),
13
+	MOD("%", "modulo"),
14
+	CAT("~", "concat"),
15
+	OR("|", "or"),
16
+	AND("&", "and"),
17
+	XOR("^", "xor"),
18
+	NEG("-", "negate"),
19
+	NOT("!", "not"),
20
+	INDEXSET("[]=", "setElement"),
21
+	INDEXGET("[]", "getElement"),
22
+	CONTAINS("in", "contains"),
23
+	COMPARE("compare", "compareTo"),
24
+	MEMBERGETTER(".", "getMember"),
25
+	MEMBERSETTER(".=", "setMember"),
26
+	EQUALS("==", "equals"),
27
+	
28
+	ADDASSIGN("+=", "addAssign", ADD),
29
+	SUBASSIGN("-=", "subAssign", SUB),
30
+	MULASSIGN("*=", "mulAssign", MUL),
31
+	DIVASSIGN("/=", "divAssign", DIV),
32
+	MODASSIGN("%=", "modAssign", MOD),
33
+	CATASSIGN("~=", "concatAssign", CAT),
34
+	ORASSIGN("|=", "orAssign", OR),
35
+	ANDASSIGN("&=", "andAssign", AND),
36
+	XORASSIGN("^=", "xorAssign", XOR),
37
+	
38
+	POST_INCREMENT("x++", "postIncrement"),
39
+	POST_DECREMENT("x--", "postDecrement"),
40
+	PRE_INCREMENT("++x", "preIncrement"),
41
+	PRE_DECREMENT("--x", "preDecrement"),
42
+	
43
+	CONSTRUCTOR("this", "construct"),
44
+	CALL("()", "call"),
45
+	CAST("as", "cast");
46
+	
47
+	public final OperatorType assignOperatorFor;
48
+	public final String operator;
49
+	public final String compiledName;
50
+	
51
+	private OperatorType(String operator, String compiledName) {
52
+		this.operator = operator;
53
+		this.compiledName = compiledName;
54
+		assignOperatorFor = null;
55
+	}
56
+	
57
+	private OperatorType(String operator, String compiledName, OperatorType assignOperatorFor) {
58
+		this.operator = operator;
59
+		this.compiledName = compiledName;
60
+		this.assignOperatorFor = assignOperatorFor;
61
+	}
62
+}

+ 48
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/PackageDefinitions.java Parādīt failu

@@ -0,0 +1,48 @@
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.codemodel;
7
+
8
+import java.util.ArrayList;
9
+import java.util.HashMap;
10
+import java.util.List;
11
+import java.util.Map;
12
+import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
13
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class PackageDefinitions {
20
+	private final List<HighLevelDefinition> definitions = new ArrayList<>();
21
+	private final Map<String, HighLevelDefinition> definitionsByName = new HashMap<>();
22
+	
23
+	public List<HighLevelDefinition> getAll() {
24
+		return definitions;
25
+	}
26
+	
27
+	public void add(HighLevelDefinition definition) {
28
+		definitions.add(definition);
29
+		definitionsByName.put(definition.name, definition);
30
+	}
31
+	
32
+	public HighLevelDefinition getDefinition(String name) {
33
+		return definitionsByName.get(name);
34
+	}
35
+	
36
+	public void registerTo(ZSPackage pkg) {
37
+		for (HighLevelDefinition definition : definitions) {
38
+			pkg.register(definition);
39
+		}
40
+	}
41
+	
42
+	public void registerExpansionsTo(List<ExpansionDefinition> expansions) {
43
+		for (HighLevelDefinition definition : definitions) {
44
+			if (definition instanceof ExpansionDefinition)
45
+				expansions.add((ExpansionDefinition) definition);
46
+		}
47
+	}
48
+}

+ 21
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/ScriptBlock.java Parādīt failu

@@ -0,0 +1,21 @@
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.codemodel;
7
+
8
+import java.util.List;
9
+import org.openzen.zenscript.codemodel.statement.Statement;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ScriptBlock {
16
+	public final List<Statement> statements;
17
+	
18
+	public ScriptBlock(List<Statement> statements) {
19
+		this.statements = statements;
20
+	}
21
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/AliasDefinition.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.definition;
7
+
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.type.ITypeID;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class AliasDefinition extends HighLevelDefinition {
16
+	public ITypeID type;
17
+	
18
+	public AliasDefinition(String name, int modifiers, HighLevelDefinition outerDefinition) {
19
+		super(name, modifiers, outerDefinition);
20
+	}
21
+	
22
+	public void setType(ITypeID type) {
23
+		this.type = type;
24
+	}
25
+
26
+	@Override
27
+	public <T> T accept(DefinitionVisitor<T> visitor) {
28
+		return visitor.visitAlias(this);
29
+	}
30
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ClassDefinition.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.definition;
7
+
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.type.ITypeID;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ClassDefinition extends HighLevelDefinition {
16
+	public ClassDefinition(String name, int modifiers, HighLevelDefinition outerDefinition) {
17
+		super(name, modifiers, outerDefinition);
18
+	}
19
+	
20
+	public void setSuperclass(ITypeID superclass) {
21
+		this.superType = superclass;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(DefinitionVisitor<T> visitor) {
26
+		return visitor.visitClass(this);
27
+	}
28
+}

+ 26
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/DefinitionVisitor.java Parādīt failu

@@ -0,0 +1,26 @@
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.codemodel.definition;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface DefinitionVisitor<T> {
13
+	public T visitClass(ClassDefinition definition);
14
+	
15
+	public T visitInterface(InterfaceDefinition definition);
16
+	
17
+	public T visitEnum(EnumDefinition definition);
18
+	
19
+	public T visitStruct(StructDefinition definition);
20
+	
21
+	public T visitFunction(FunctionDefinition definition);
22
+	
23
+	public T visitExpansion(ExpansionDefinition definition);
24
+	
25
+	public T visitAlias(AliasDefinition definition);
26
+}

+ 23
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/EnumDefinition.java Parādīt failu

@@ -0,0 +1,23 @@
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.codemodel.definition;
7
+
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class EnumDefinition extends HighLevelDefinition {
15
+	public EnumDefinition(String name, int modifiers, HighLevelDefinition outerDefinition) {
16
+		super(name, modifiers, outerDefinition);
17
+	}
18
+
19
+	@Override
20
+	public <T> T accept(DefinitionVisitor<T> visitor) {
21
+		return visitor.visitEnum(this);
22
+	}
23
+}

+ 26
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ExpansionDefinition.java Parādīt failu

@@ -0,0 +1,26 @@
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.codemodel.definition;
7
+
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.type.ITypeID;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ExpansionDefinition extends HighLevelDefinition {
16
+	public ITypeID target;
17
+	
18
+	public ExpansionDefinition(int modifiers, HighLevelDefinition outerDefinition) {
19
+		super(null, modifiers, outerDefinition);
20
+	}
21
+
22
+	@Override
23
+	public <T> T accept(DefinitionVisitor<T> visitor) {
24
+		return visitor.visitExpansion(this);
25
+	}
26
+}

+ 37
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java Parādīt failu

@@ -0,0 +1,37 @@
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.codemodel.definition;
7
+
8
+import java.util.List;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.statement.Statement;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class FunctionDefinition extends HighLevelDefinition {
18
+	public FunctionHeader header;
19
+	public List<Statement> statements;
20
+	
21
+	public FunctionDefinition(String name, int modifiers, HighLevelDefinition outerDefinition) {
22
+		super(name, modifiers, outerDefinition);
23
+	}
24
+	
25
+	public void setHeader(FunctionHeader header) {
26
+		this.header = header;
27
+	}
28
+	
29
+	public void setCode(List<Statement> statements) {
30
+		this.statements = statements;
31
+	}
32
+
33
+	@Override
34
+	public <T> T accept(DefinitionVisitor<T> visitor) {
35
+		return visitor.visitFunction(this);
36
+	}
37
+}

+ 32
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/InterfaceDefinition.java Parādīt failu

@@ -0,0 +1,32 @@
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.codemodel.definition;
7
+
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.type.ITypeID;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class InterfaceDefinition extends HighLevelDefinition {
18
+	private final List<ITypeID> baseInterfaces = new ArrayList<>();
19
+	
20
+	public InterfaceDefinition(String name, int modifiers, HighLevelDefinition outerDefinition) {
21
+		super(name, modifiers, outerDefinition);
22
+	}
23
+	
24
+	public void addBaseInterface(ITypeID baseInterface) {
25
+		baseInterfaces.add(baseInterface);
26
+	}
27
+
28
+	@Override
29
+	public <T> T accept(DefinitionVisitor<T> visitor) {
30
+		return visitor.visitInterface(this);
31
+	}
32
+}

+ 23
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/StructDefinition.java Parādīt failu

@@ -0,0 +1,23 @@
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.codemodel.definition;
7
+
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class StructDefinition extends HighLevelDefinition {
15
+	public StructDefinition(String name, int modifiers, HighLevelDefinition outerDefinition) {
16
+		super(name, modifiers, outerDefinition);
17
+	}
18
+
19
+	@Override
20
+	public <T> T accept(DefinitionVisitor<T> visitor) {
21
+		return visitor.visitStruct(this);
22
+	}
23
+}

+ 94
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java Parādīt failu

@@ -0,0 +1,94 @@
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.codemodel.definition;
7
+
8
+import java.util.HashMap;
9
+import java.util.List;
10
+import java.util.Map;
11
+import org.openzen.zenscript.shared.CompileException;
12
+import org.openzen.zenscript.shared.CompileExceptionCode;
13
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
+import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
+import org.openzen.zenscript.codemodel.partial.PartialPackageExpression;
16
+import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
17
+import org.openzen.zenscript.codemodel.type.GenericName;
18
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19
+import org.openzen.zenscript.codemodel.type.ITypeID;
20
+import org.openzen.zenscript.shared.CodePosition;
21
+import org.openzen.zenscript.codemodel.scope.TypeScope;
22
+
23
+/**
24
+ *
25
+ * @author Hoofdgebruiker
26
+ */
27
+public class ZSPackage {
28
+	private final Map<String, ZSPackage> subPackages = new HashMap<>();
29
+	private final Map<String, HighLevelDefinition> types = new HashMap<>();
30
+	
31
+	public IPartialExpression getMember(CodePosition position, GlobalTypeRegistry registry, GenericName name) {
32
+		if (subPackages.containsKey(name.name) && name.arguments.isEmpty())
33
+			return new PartialPackageExpression(position, subPackages.get(name.name));
34
+		
35
+		if (types.containsKey(name.name)) {
36
+			if (types.get(name.name).genericParameters.size() != name.arguments.size())
37
+				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
38
+			
39
+			return new PartialTypeExpression(position, registry.getForDefinition(types.get(name.name), name.arguments));
40
+		}
41
+		
42
+		return null;
43
+	}
44
+	
45
+	public HighLevelDefinition getImport(List<String> name, int depth) {
46
+		if (depth >= name.size())
47
+			return null;
48
+		
49
+		if (subPackages.containsKey(name.get(depth)))
50
+			return subPackages.get(name.get(depth)).getImport(name, depth + 1);
51
+		
52
+		if (depth == name.size() - 1 && types.containsKey(name.get(depth)))
53
+			return types.get(name.get(depth));
54
+		
55
+		return null;
56
+	}
57
+	
58
+	public ITypeID getType(CodePosition position, TypeScope scope, List<GenericName> nameParts, int depth) {
59
+		if (depth >= nameParts.size())
60
+			return null;
61
+		
62
+		GenericName name = nameParts.get(depth);
63
+		if (subPackages.containsKey(name.name) && name.arguments.isEmpty())
64
+			return subPackages.get(name.name).getType(position, scope, nameParts, depth + 1);
65
+		
66
+		if (types.containsKey(name.name)) {
67
+			ITypeID type = scope.getTypeRegistry().getForDefinition(types.get(name.name), name.arguments);
68
+			depth++;
69
+			while (depth < nameParts.size()) {
70
+				GenericName innerName = nameParts.get(depth++);
71
+				type = scope.getTypeMembers(type).getInnerType(position, innerName);
72
+				if (type == null)
73
+					return null;
74
+			}
75
+			
76
+			return type;
77
+		}
78
+		
79
+		return null;
80
+	}
81
+	
82
+	public ZSPackage getOrCreatePackage(String name) {
83
+		if (subPackages.containsKey(name))
84
+			return subPackages.get(name);
85
+		
86
+		ZSPackage result = new ZSPackage();
87
+		subPackages.put(name, result);
88
+		return result;
89
+	}
90
+	
91
+	public void register(HighLevelDefinition definition) {
92
+		types.put(definition.name, definition);
93
+	}
94
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/AndAndExpression.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class AndAndExpression extends Expression {
16
+	public final Expression left;
17
+	public final Expression right;
18
+	
19
+	public AndAndExpression(CodePosition position, Expression left, Expression right) {
20
+		super(position, BasicTypeID.BOOL);
21
+		
22
+		this.left = left;
23
+		this.right = right;
24
+	}
25
+
26
+	@Override
27
+	public <T> T accept(ExpressionVisitor<T> visitor) {
28
+		return visitor.visitAndAnd(this);
29
+	}
30
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ArrayExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ArrayExpression extends Expression {
16
+	public final Expression[] expressions;
17
+	
18
+	public ArrayExpression(CodePosition position, Expression[] expressions, ITypeID type) {
19
+		super(position, type);
20
+		
21
+		this.expressions = expressions;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitArray(this);
27
+	}
28
+}

+ 35
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/BasicCompareExpression.java Parādīt failu

@@ -0,0 +1,35 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.CompareType;
9
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
10
+import org.openzen.zenscript.shared.CodePosition;
11
+
12
+/**
13
+ * Compare expression for basic types. Left and right MUST be of the same type,
14
+ * and MUST be a basic type. (any integer or floating point type, char, string)
15
+ * 
16
+ * @author Hoofdgebruiker
17
+ */
18
+public class BasicCompareExpression extends Expression {
19
+	public final Expression left;
20
+	public final Expression right;
21
+	public final CompareType operator;
22
+	
23
+	public BasicCompareExpression(CodePosition position, Expression left, Expression right, CompareType operator) {
24
+		super(position, BasicTypeID.BOOL);
25
+		
26
+		this.left = left;
27
+		this.right = right;
28
+		this.operator = operator;
29
+	}
30
+
31
+	@Override
32
+	public <T> T accept(ExpressionVisitor<T> visitor) {
33
+		return visitor.visitCompare(this);
34
+	}
35
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallArguments.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class CallArguments {
15
+	public static final CallArguments EMPTY = new CallArguments(new Expression[0]);
16
+	public static final ITypeID[] NO_TYPE_ARGUMENTS = new ITypeID[0];
17
+	
18
+	public final ITypeID[] typeArguments;
19
+	public final Expression[] arguments;
20
+	
21
+	public CallArguments(Expression... arguments) {
22
+		this.typeArguments = NO_TYPE_ARGUMENTS;
23
+		this.arguments = arguments;
24
+	}
25
+	
26
+	public CallArguments(ITypeID[] typeArguments, Expression[] arguments) {
27
+		this.typeArguments = typeArguments;
28
+		this.arguments = arguments;
29
+	}
30
+}

+ 33
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallExpression.java Parādīt failu

@@ -0,0 +1,33 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
10
+import org.openzen.zenscript.shared.CodePosition;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class CallExpression extends Expression {
17
+	public final Expression target;
18
+	public final FunctionalMember member;
19
+	public final CallArguments arguments;
20
+	
21
+	public CallExpression(CodePosition position, Expression target, FunctionalMember member, FunctionHeader instancedHeader, CallArguments arguments) {
22
+		super(position, instancedHeader.returnType);
23
+		
24
+		this.target = target;
25
+		this.member = member;
26
+		this.arguments = arguments;
27
+	}
28
+
29
+	@Override
30
+	public <T> T accept(ExpressionVisitor<T> visitor) {
31
+		return visitor.visitCall(this);
32
+	}
33
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class CallStaticExpression extends Expression {
16
+	public final FunctionalMember member;
17
+	public final CallArguments arguments;
18
+	
19
+	public CallStaticExpression(CodePosition position, FunctionalMember member, CallArguments arguments) {
20
+		super(position, member.header.returnType);
21
+		
22
+		this.member = member;
23
+		this.arguments = arguments;
24
+	}
25
+
26
+	@Override
27
+	public <T> T accept(ExpressionVisitor<T> visitor) {
28
+		return visitor.visitCallStatic(this);
29
+	}
30
+}

+ 27
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedClosureExpression.java Parādīt failu

@@ -0,0 +1,27 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.shared.CodePosition;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class CapturedClosureExpression extends CapturedExpression {
15
+	public final CapturedExpression value;
16
+	
17
+	public CapturedClosureExpression(CodePosition position, CapturedExpression value, LambdaClosure closure) {
18
+		super(position, value.type, closure);
19
+		
20
+		this.value = value;
21
+	}
22
+
23
+	@Override
24
+	public <T> T accept(ExpressionVisitor<T> visitor) {
25
+		return visitor.visitCapturedClosure(this);
26
+	}
27
+}

+ 26
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedDirectExpression.java Parādīt failu

@@ -0,0 +1,26 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.shared.CodePosition;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class CapturedDirectExpression extends CapturedExpression {
15
+	public final Expression value;
16
+	
17
+	public CapturedDirectExpression(CodePosition position, LambdaClosure closure, Expression value) {
18
+		super(position, value.type, closure);
19
+		this.value = value;
20
+	}
21
+
22
+	@Override
23
+	public <T> T accept(ExpressionVisitor<T> visitor) {
24
+		return visitor.visitCapturedDirect(this);
25
+	}
26
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedExpression.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public abstract class CapturedExpression extends Expression {
16
+	public final LambdaClosure closure;
17
+	
18
+	public CapturedExpression(CodePosition position, ITypeID type, LambdaClosure closure) {
19
+		super(position, type);
20
+		
21
+		this.closure = closure;
22
+	}
23
+	
24
+	@Override
25
+	public CapturedExpression capture(CodePosition position, LambdaClosure closure) {
26
+		CapturedExpression result = new CapturedClosureExpression(position, this, closure);
27
+		closure.add(result);
28
+		return result;
29
+	}
30
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedLocalVariableExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.statement.VarStatement;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class CapturedLocalVariableExpression extends CapturedExpression {
16
+	public final VarStatement variable;
17
+	
18
+	public CapturedLocalVariableExpression(CodePosition position, VarStatement variable, LambdaClosure closure) {
19
+		super(position, variable.type, closure);
20
+		
21
+		this.variable = variable;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitCapturedLocalVariable(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedParameterExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.FunctionParameter;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class CapturedParameterExpression extends CapturedExpression {
16
+	public final FunctionParameter parameter;
17
+	
18
+	public CapturedParameterExpression(CodePosition position, FunctionParameter parameter, LambdaClosure closure) {
19
+		super(position, parameter.type, closure);
20
+		
21
+		this.parameter = parameter;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitCapturedParameter(this);
27
+	}
28
+}

+ 24
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedThisExpression.java Parādīt failu

@@ -0,0 +1,24 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class CapturedThisExpression extends CapturedExpression {
16
+	public CapturedThisExpression(CodePosition position, ITypeID type, LambdaClosure closure) {
17
+		super(position, type, closure);
18
+	}
19
+
20
+	@Override
21
+	public <T> T accept(ExpressionVisitor<T> visitor) {
22
+		return visitor.visitCapturedThis(this);
23
+	}
24
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CheckNullExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.shared.CodePosition;
9
+
10
+/**
11
+ * Converts a value from X? to X. Throws a NullPointerException if the value is null.
12
+ * 
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class CheckNullExpression extends Expression {
16
+	public final Expression value;
17
+	
18
+	public CheckNullExpression(CodePosition position, Expression value) {
19
+		super(position, value.type.unwrap());
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitCheckNull(this);
27
+	}
28
+}

+ 29
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CoalesceExpression.java Parādīt failu

@@ -0,0 +1,29 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.shared.CodePosition;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class CoalesceExpression extends Expression {
15
+	public final Expression left;
16
+	public final Expression right;
17
+	
18
+	public CoalesceExpression(CodePosition position, Expression left, Expression right) {
19
+		super(position, right.type);
20
+		
21
+		this.left = left;
22
+		this.right = right;
23
+	}
24
+
25
+	@Override
26
+	public <T> T accept(ExpressionVisitor<T> visitor) {
27
+		return visitor.visitCoalesce(this);
28
+	}
29
+}

+ 40
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConditionalExpression.java Parādīt failu

@@ -0,0 +1,40 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConditionalExpression extends Expression {
16
+	public final Expression condition;
17
+	public final Expression ifThen;
18
+	public final Expression ifElse;
19
+	
20
+	public ConditionalExpression(
21
+			CodePosition position,
22
+			Expression condition,
23
+			Expression ifThen,
24
+			Expression ifElse,
25
+			ITypeID type) {
26
+		super(position, ifThen.type);
27
+		
28
+		if (ifThen.type != ifElse.type)
29
+			throw new AssertionError();
30
+		
31
+		this.condition = condition;
32
+		this.ifThen = ifThen;
33
+		this.ifElse = ifElse;
34
+	}
35
+
36
+	@Override
37
+	public <T> T accept(ExpressionVisitor<T> visitor) {
38
+		return visitor.visitConditional(this);
39
+	}
40
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantBoolExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantBoolExpression extends Expression {
16
+	public final boolean value;
17
+	
18
+	public ConstantBoolExpression(CodePosition position, boolean value) {
19
+		super(position, BasicTypeID.BOOL);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantBool(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantByteExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantByteExpression extends Expression {
16
+	public final byte value;
17
+	
18
+	public ConstantByteExpression(CodePosition position, byte value) {
19
+		super(position, BasicTypeID.BYTE);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantByte(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantCharExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantCharExpression extends Expression {
16
+	public final char value;
17
+	
18
+	public ConstantCharExpression(CodePosition position, char value) {
19
+		super(position, BasicTypeID.CHAR);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantChar(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantDoubleExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantDoubleExpression extends Expression {
16
+	public final double value;
17
+	
18
+	public ConstantDoubleExpression(CodePosition position, double value) {
19
+		super(position, BasicTypeID.DOUBLE);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantDouble(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantFloatExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantFloatExpression extends Expression {
16
+	public final float value;
17
+	
18
+	public ConstantFloatExpression(CodePosition position, float value) {
19
+		super(position, BasicTypeID.FLOAT);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantFloat(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantIntExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantIntExpression extends Expression {
16
+	public final int value;
17
+	
18
+	public ConstantIntExpression(CodePosition position, int value) {
19
+		super(position, BasicTypeID.INT);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantInt(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantLongExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantLongExpression extends Expression {
16
+	public final long value;
17
+	
18
+	public ConstantLongExpression(CodePosition position, long value) {
19
+		super(position, BasicTypeID.LONG);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantLong(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantSByteExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantSByteExpression extends Expression {
16
+	public final byte value;
17
+	
18
+	public ConstantSByteExpression(CodePosition position, byte value) {
19
+		super(position, BasicTypeID.SBYTE);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantSByte(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantShortExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantShortExpression extends Expression {
16
+	public final short value;
17
+	
18
+	public ConstantShortExpression(CodePosition position, short value) {
19
+		super(position, BasicTypeID.SHORT);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantShort(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantStringExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantStringExpression extends Expression {
16
+	public final String value;
17
+	
18
+	public ConstantStringExpression(CodePosition position, String value) {
19
+		super(position, BasicTypeID.STRING);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantString(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUIntExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantUIntExpression extends Expression {
16
+	public final int value;
17
+	
18
+	public ConstantUIntExpression(CodePosition position, int value) {
19
+		super(position, BasicTypeID.UINT);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantUInt(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantULongExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantULongExpression extends Expression {
16
+	public final long value;
17
+	
18
+	public ConstantULongExpression(CodePosition position, long value) {
19
+		super(position, BasicTypeID.ULONG);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantULong(this);
27
+	}
28
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUShortExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ConstantUShortExpression extends Expression {
16
+	public final short value;
17
+	
18
+	public ConstantUShortExpression(CodePosition position, short value) {
19
+		super(position, BasicTypeID.USHORT);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitConstantUShort(this);
27
+	}
28
+}

+ 34
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstructorCallExpression.java Parādīt failu

@@ -0,0 +1,34 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.member.ConstructorMember;
9
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
10
+import org.openzen.zenscript.codemodel.type.ITypeID;
11
+import org.openzen.zenscript.shared.CodePosition;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class ConstructorCallExpression extends Expression {
18
+	public final ITypeID objectType;
19
+	public final ConstructorMember constructor;
20
+	public final CallArguments arguments;
21
+	
22
+	public ConstructorCallExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments) {
23
+		super(position, BasicTypeID.VOID);
24
+		
25
+		this.objectType = type;
26
+		this.constructor = constructor;
27
+		this.arguments = arguments;
28
+	}
29
+
30
+	@Override
31
+	public <T> T accept(ExpressionVisitor<T> visitor) {
32
+		return visitor.visitConstructorCall(this);
33
+	}
34
+}

+ 38
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EnumConstantExpression.java Parādīt failu

@@ -0,0 +1,38 @@
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.codemodel.expression;
7
+
8
+import java.util.Collections;
9
+import org.openzen.zenscript.codemodel.definition.EnumDefinition;
10
+import org.openzen.zenscript.codemodel.member.EnumConstantMember;
11
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
+import org.openzen.zenscript.codemodel.type.ITypeID;
13
+import org.openzen.zenscript.shared.CodePosition;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class EnumConstantExpression extends Expression {
20
+	public final EnumConstantMember value;
21
+	
22
+	public EnumConstantExpression(CodePosition position, ITypeID type, EnumConstantMember value) {
23
+		super(position, type);
24
+		
25
+		this.value = value;
26
+	}
27
+	
28
+	public EnumConstantExpression(CodePosition position, GlobalTypeRegistry registry, EnumDefinition type, EnumConstantMember value) {
29
+		super(position, registry.getForDefinition(type, Collections.emptyList()));
30
+		
31
+		this.value = value;
32
+	}
33
+
34
+	@Override
35
+	public <T> T accept(ExpressionVisitor<T> visitor) {
36
+		return visitor.visitEnumConstant(this);
37
+	}
38
+}

+ 31
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EqualsExpression.java Parādīt failu

@@ -0,0 +1,31 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ * Checks if two values are identical (===).
13
+ * 
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class EqualsExpression extends Expression {
17
+	public final Expression left;
18
+	public final Expression right;
19
+	
20
+	public EqualsExpression(CodePosition position, Expression left, Expression right) {
21
+		super(position, BasicTypeID.BOOL);
22
+		
23
+		this.left = left;
24
+		this.right = right;
25
+	}
26
+
27
+	@Override
28
+	public <T> T accept(ExpressionVisitor<T> visitor) {
29
+		return visitor.visitEquals(this);
30
+	}
31
+}

+ 82
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java Parādīt failu

@@ -0,0 +1,82 @@
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.codemodel.expression;
7
+
8
+import java.util.Collections;
9
+import java.util.List;
10
+import java.util.stream.Collectors;
11
+import org.openzen.zenscript.codemodel.FunctionHeader;
12
+import org.openzen.zenscript.codemodel.OperatorType;
13
+import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
+import org.openzen.zenscript.codemodel.type.GenericName;
15
+import org.openzen.zenscript.codemodel.type.ITypeID;
16
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17
+import org.openzen.zenscript.shared.CodePosition;
18
+import org.openzen.zenscript.codemodel.scope.TypeScope;
19
+
20
+/**
21
+ *
22
+ * @author Hoofdgebruiker
23
+ */
24
+public abstract class Expression implements IPartialExpression {
25
+	public final CodePosition position;
26
+	public final ITypeID type;
27
+	
28
+	public Expression(CodePosition position, ITypeID type) {
29
+		this.position = position;
30
+		this.type = type;
31
+	}
32
+	
33
+	public ITypeID getType() {
34
+		return type;
35
+	}
36
+	
37
+	public abstract <T> T accept(ExpressionVisitor<T> visitor);
38
+	
39
+	@Override
40
+	public List<ITypeID> getAssignHints() {
41
+		return Collections.singletonList(type);
42
+	}
43
+	
44
+	@Override
45
+	public Expression eval() {
46
+		return this;
47
+	}
48
+	
49
+	public Expression castExplicit(CodePosition position, TypeScope scope, ITypeID asType, boolean optional) {
50
+		return scope.getTypeMembers(type).castExplicit(position, this, asType, optional);
51
+	}
52
+	
53
+	public Expression castImplicit(CodePosition position, TypeScope scope, ITypeID asType) {
54
+		return scope.getTypeMembers(type).castImplicit(position, this, asType);
55
+	}
56
+	
57
+	@Override
58
+	public List<ITypeID>[] predictCallTypes(TypeScope scope, List<ITypeID> hints, int arguments) {
59
+		return scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CALL).predictCallTypes(scope, hints, arguments);
60
+	}
61
+	
62
+	@Override
63
+	public List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<ITypeID> hints, int arguments) {
64
+		return scope.getTypeMembers(type)
65
+				.getOrCreateGroup(OperatorType.CALL)
66
+				.getMethodMembers().stream()
67
+				.filter(method -> method.member.getHeader().parameters.length == arguments && !method.member.isStatic())
68
+				.map(method -> method.member.getHeader())
69
+				.collect(Collectors.toList());
70
+	}
71
+	
72
+	@Override
73
+	public Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments) {
74
+		return scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CALL).call(position, scope, this, arguments, false);
75
+	}
76
+	
77
+	@Override
78
+	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<ITypeID> hints, GenericName name) {
79
+		TypeMembers members = scope.getTypeMembers(type);
80
+		return members.getMemberExpression(position, this, name, false);
81
+	}
82
+}

+ 124
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java Parādīt failu

@@ -0,0 +1,124 @@
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.codemodel.expression;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface ExpressionVisitor<T> {
13
+	public T visitAndAnd(AndAndExpression expression);
14
+	
15
+	public T visitArray(ArrayExpression expression);
16
+	
17
+	public T visitCompare(BasicCompareExpression expression);
18
+	
19
+	public T visitCall(CallExpression expression);
20
+	
21
+	public T visitCallStatic(CallStaticExpression expression);
22
+	
23
+	public T visitCapturedClosure(CapturedClosureExpression expression);
24
+	
25
+	public T visitCapturedDirect(CapturedDirectExpression expression);
26
+	
27
+	public T visitCapturedLocalVariable(CapturedLocalVariableExpression expression);
28
+	
29
+	public T visitCapturedParameter(CapturedParameterExpression expression);
30
+	
31
+	public T visitCapturedThis(CapturedThisExpression expression);
32
+	
33
+	public T visitCheckNull(CheckNullExpression expression);
34
+	
35
+	public T visitCoalesce(CoalesceExpression expression);
36
+	
37
+	public T visitConditional(ConditionalExpression expression);
38
+	
39
+	public T visitConstantBool(ConstantBoolExpression expression);
40
+	
41
+	public T visitConstantByte(ConstantByteExpression expression);
42
+	
43
+	public T visitConstantChar(ConstantCharExpression expression);
44
+	
45
+	public T visitConstantDouble(ConstantDoubleExpression expression);
46
+	
47
+	public T visitConstantFloat(ConstantFloatExpression expression);
48
+	
49
+	public T visitConstantInt(ConstantIntExpression expression);
50
+	
51
+	public T visitConstantLong(ConstantLongExpression expression);
52
+	
53
+	public T visitConstantSByte(ConstantSByteExpression expression);
54
+	
55
+	public T visitConstantShort(ConstantShortExpression expression);
56
+	
57
+	public T visitConstantString(ConstantStringExpression expression);
58
+	
59
+	public T visitConstantUInt(ConstantUIntExpression expression);
60
+	
61
+	public T visitConstantULong(ConstantULongExpression expression);
62
+	
63
+	public T visitConstantUShort(ConstantUShortExpression expression);
64
+	
65
+	public T visitConstructorCall(ConstructorCallExpression expression);
66
+	
67
+	public T visitEnumConstant(EnumConstantExpression expression);
68
+	
69
+	public T visitEquals(EqualsExpression expression);
70
+	
71
+	public T visitFunction(FunctionExpression expression);
72
+	
73
+	public T visitGenericCompare(GenericCompareExpression expression);
74
+	
75
+	public T visitGetField(GetFieldExpression expression);
76
+	
77
+	public T visitGetFunctionParameter(GetFunctionParameterExpression expression);
78
+	
79
+	public T visitGetLocalVariable(GetLocalVariableExpression expression);
80
+	
81
+	public T visitGetStaticField(GetStaticFieldExpression expression);
82
+	
83
+	public T visitGetter(GetterExpression expression);
84
+	
85
+	public T visitInterfaceCast(InterfaceCastExpression expression);
86
+	
87
+	public T visitIs(IsExpression expression);
88
+	
89
+	public T visitMakeConst(MakeConstExpression expression);
90
+	
91
+	public T visitMap(MapExpression expression);
92
+	
93
+	public T visitNew(NewExpression expression);
94
+	
95
+	public T visitNot(NotExpression expression);
96
+	
97
+	public T visitNull(NullExpression expression);
98
+	
99
+	public T visitOrOr(OrOrExpression expression);
100
+	
101
+	public T visitRange(RangeExpression expression);
102
+	
103
+	public T visitSetField(SetFieldExpression expression);
104
+	
105
+	public T visitSetFunctionParameter(SetFunctionParameterExpression expression);
106
+	
107
+	public T visitSetLocalVariable(SetLocalVariableExpression expression);
108
+	
109
+	public T visitSetStaticField(SetStaticFieldExpression expression);
110
+	
111
+	public T visitSetter(SetterExpression expression);
112
+	
113
+	public T visitStaticGetter(StaticGetterExpression expression);
114
+	
115
+	public T visitStaticSetter(StaticSetterExpression expression);
116
+	
117
+	public T visitStringConcat(StringConcatExpression expression);
118
+	
119
+	public T visitSubstring(SubstringExpression expression);
120
+	
121
+	public T visitThis(ThisExpression expression);
122
+	
123
+	public T visitWrapOptional(WrapOptionalExpression expression);
124
+}

+ 39
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/FunctionExpression.java Parādīt failu

@@ -0,0 +1,39 @@
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.codemodel.expression;
7
+
8
+import java.util.List;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.statement.Statement;
11
+import org.openzen.zenscript.codemodel.type.FunctionTypeID;
12
+import org.openzen.zenscript.shared.CodePosition;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public class FunctionExpression extends Expression {
19
+	public final FunctionHeader header;
20
+	public final LambdaClosure closure;
21
+	public final List<Statement> statements;
22
+	
23
+	public FunctionExpression(
24
+			CodePosition position,
25
+			FunctionTypeID type,
26
+			LambdaClosure closure,
27
+			List<Statement> statements) {
28
+		super(position, type);
29
+		
30
+		this.header = type.header;
31
+		this.closure = closure;
32
+		this.statements = statements;
33
+	}
34
+
35
+	@Override
36
+	public <T> T accept(ExpressionVisitor<T> visitor) {
37
+		return visitor.visitFunction(this);
38
+	}
39
+}

+ 31
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GenericCompareExpression.java Parādīt failu

@@ -0,0 +1,31 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.CompareType;
9
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
10
+import org.openzen.zenscript.shared.CodePosition;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class GenericCompareExpression extends Expression {
17
+	public final Expression value;
18
+	public final CompareType operator;
19
+	
20
+	public GenericCompareExpression(CodePosition position, Expression value, CompareType operator) {
21
+		super(position, BasicTypeID.BOOL);
22
+		
23
+		this.value = value;
24
+		this.operator = operator;
25
+	}
26
+
27
+	@Override
28
+	public <T> T accept(ExpressionVisitor<T> visitor) {
29
+		return visitor.visitGenericCompare(this);
30
+	}
31
+}

+ 43
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFieldExpression.java Parādīt failu

@@ -0,0 +1,43 @@
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.codemodel.expression;
7
+
8
+import java.util.Collections;
9
+import java.util.List;
10
+import org.openzen.zenscript.codemodel.member.FieldMember;
11
+import org.openzen.zenscript.codemodel.type.ITypeID;
12
+import org.openzen.zenscript.shared.CodePosition;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public class GetFieldExpression extends Expression {
19
+	public final Expression target;
20
+	public final FieldMember field;
21
+	
22
+	public GetFieldExpression(CodePosition position, Expression target, FieldMember field) {
23
+		super(position, field.type);
24
+		
25
+		this.target = target;
26
+		this.field = field;
27
+	}
28
+	
29
+	@Override
30
+	public List<ITypeID> getAssignHints() {
31
+		return Collections.singletonList(type);
32
+	}
33
+	
34
+	@Override
35
+	public CapturedExpression capture(CodePosition position, LambdaClosure closure) {
36
+		return new CapturedDirectExpression(position, closure, this);
37
+	}
38
+
39
+	@Override
40
+	public <T> T accept(ExpressionVisitor<T> visitor) {
41
+		return visitor.visitGetField(this);
42
+	}
43
+}

+ 41
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFunctionParameterExpression.java Parādīt failu

@@ -0,0 +1,41 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.FunctionParameter;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+import org.openzen.zenscript.codemodel.scope.TypeScope;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class GetFunctionParameterExpression extends Expression {
17
+	public final FunctionParameter parameter;
18
+	
19
+	public GetFunctionParameterExpression(CodePosition position, FunctionParameter parameter) {
20
+		super(position, parameter.type);
21
+		
22
+		this.parameter = parameter;
23
+	}
24
+	
25
+	@Override
26
+	public Expression assign(CodePosition position, TypeScope scope, Expression value) {
27
+		return new SetFunctionParameterExpression(position, parameter, value.castImplicit(position, scope, type));
28
+	}
29
+	
30
+	@Override
31
+	public CapturedExpression capture(CodePosition position, LambdaClosure closure) {
32
+		CapturedExpression result = new CapturedParameterExpression(position, parameter, closure);
33
+		closure.add(result);
34
+		return result;
35
+	}
36
+
37
+	@Override
38
+	public <T> T accept(ExpressionVisitor<T> visitor) {
39
+		return visitor.visitGetFunctionParameter(this);
40
+	}
41
+}

+ 41
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetLocalVariableExpression.java Parādīt failu

@@ -0,0 +1,41 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.statement.VarStatement;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+import org.openzen.zenscript.codemodel.scope.TypeScope;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class GetLocalVariableExpression extends Expression {
17
+	public final VarStatement variable;
18
+	
19
+	public GetLocalVariableExpression(CodePosition position, VarStatement variable) {
20
+		super(position, variable.type);
21
+		
22
+		this.variable = variable;
23
+	}
24
+	
25
+	@Override
26
+	public Expression assign(CodePosition position, TypeScope scope, Expression value) {
27
+		return new SetLocalVariableExpression(position, variable, value.castImplicit(position, scope, type));
28
+	}
29
+	
30
+	@Override
31
+	public CapturedExpression capture(CodePosition position, LambdaClosure closure) {
32
+		CapturedExpression result = new CapturedLocalVariableExpression(position, variable, closure);
33
+		closure.add(result);
34
+		return result;
35
+	}
36
+
37
+	@Override
38
+	public <T> T accept(ExpressionVisitor<T> visitor) {
39
+		return visitor.visitGetLocalVariable(this);
40
+	}
41
+}

+ 41
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetStaticFieldExpression.java Parādīt failu

@@ -0,0 +1,41 @@
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.codemodel.expression;
7
+
8
+import java.util.Collections;
9
+import java.util.List;
10
+import org.openzen.zenscript.codemodel.member.FieldMember;
11
+import org.openzen.zenscript.codemodel.type.ITypeID;
12
+import org.openzen.zenscript.shared.CodePosition;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public class GetStaticFieldExpression extends Expression {
19
+	public final FieldMember field;
20
+	
21
+	public GetStaticFieldExpression(CodePosition position, FieldMember field) {
22
+		super(position, field.type);
23
+		
24
+		this.field = field;
25
+	}
26
+	
27
+	@Override
28
+	public List<ITypeID> getAssignHints() {
29
+		return Collections.singletonList(field.type);
30
+	}
31
+	
32
+	@Override
33
+	public CapturedExpression capture(CodePosition position, LambdaClosure closure) {
34
+		return new CapturedDirectExpression(position, closure, this);
35
+	}
36
+
37
+	@Override
38
+	public <T> T accept(ExpressionVisitor<T> visitor) {
39
+		return visitor.visitGetStaticField(this);
40
+	}
41
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetterExpression.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.member.GetterMember;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class GetterExpression extends Expression {
16
+	public final Expression target;
17
+	public final GetterMember getter;
18
+	
19
+	public GetterExpression(CodePosition position, Expression target, GetterMember getter) {
20
+		super(position, getter.type);
21
+		
22
+		this.target = target;
23
+		this.getter = getter;
24
+	}
25
+
26
+	@Override
27
+	public <T> T accept(ExpressionVisitor<T> visitor) {
28
+		return visitor.visitGetter(this);
29
+	}
30
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/InterfaceCastExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class InterfaceCastExpression extends Expression {
16
+	public final Expression value;
17
+	
18
+	public InterfaceCastExpression(CodePosition position, Expression value, ITypeID toType) {
19
+		super(position, toType);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitInterfaceCast(this);
27
+	}
28
+}

+ 31
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/IsExpression.java Parādīt failu

@@ -0,0 +1,31 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.codemodel.type.ITypeID;
10
+import org.openzen.zenscript.shared.CodePosition;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class IsExpression extends Expression {
17
+	public final Expression value;
18
+	public final ITypeID isType;
19
+	
20
+	public IsExpression(CodePosition position, Expression value, ITypeID type) {
21
+		super(position, BasicTypeID.BOOL);
22
+		
23
+		this.value = value;
24
+		this.isType = type;
25
+	}
26
+
27
+	@Override
28
+	public <T> T accept(ExpressionVisitor<T> visitor) {
29
+		return visitor.visitIs(this);
30
+	}
31
+}

+ 16
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/LambdaClosure.java Parādīt failu

@@ -0,0 +1,16 @@
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.codemodel.expression;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class LambdaClosure {
13
+	public void add(CapturedExpression capture) {
14
+		
15
+	}
16
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MakeConstExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class MakeConstExpression extends Expression {
16
+	public final Expression value;
17
+	
18
+	public MakeConstExpression(CodePosition position, Expression value, ITypeID constType) {
19
+		super(position, constType);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitMakeConst(this);
27
+	}
28
+}

+ 34
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MapExpression.java Parādīt failu

@@ -0,0 +1,34 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class MapExpression extends Expression {
16
+	public final Expression[] keys;
17
+	public final Expression[] values;
18
+	
19
+	public MapExpression(
20
+			CodePosition position,
21
+			Expression[] keys,
22
+			Expression[] values,
23
+			ITypeID type) {
24
+		super(position, type);
25
+		
26
+		this.keys = keys;
27
+		this.values = values;
28
+	}
29
+
30
+	@Override
31
+	public <T> T accept(ExpressionVisitor<T> visitor) {
32
+		return visitor.visitMap(this);
33
+	}
34
+}

+ 31
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/NewExpression.java Parādīt failu

@@ -0,0 +1,31 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.member.ConstructorMember;
9
+import org.openzen.zenscript.codemodel.type.ITypeID;
10
+import org.openzen.zenscript.shared.CodePosition;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class NewExpression extends Expression {
17
+	public final ConstructorMember constructor;
18
+	public final CallArguments arguments;
19
+	
20
+	public NewExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments) {
21
+		super(position, type);
22
+		
23
+		this.constructor = constructor;
24
+		this.arguments = arguments;
25
+	}
26
+
27
+	@Override
28
+	public <T> T accept(ExpressionVisitor<T> visitor) {
29
+		return visitor.visitNew(this);
30
+	}
31
+}

+ 27
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/NotExpression.java Parādīt failu

@@ -0,0 +1,27 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.shared.CodePosition;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class NotExpression extends Expression {
15
+	public final Expression value;
16
+	
17
+	public NotExpression(CodePosition position, Expression value) {
18
+		super(position, value.type);
19
+		
20
+		this.value = value;
21
+	}
22
+
23
+	@Override
24
+	public <T> T accept(ExpressionVisitor<T> visitor) {
25
+		return visitor.visitNot(this);
26
+	}
27
+}

+ 29
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/NullExpression.java Parādīt failu

@@ -0,0 +1,29 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.codemodel.type.ITypeID;
10
+import org.openzen.zenscript.shared.CodePosition;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class NullExpression extends Expression {
17
+	public NullExpression(CodePosition position) {
18
+		super(position, BasicTypeID.NULL);
19
+	}
20
+	
21
+	public NullExpression(CodePosition position, ITypeID optionalType) {
22
+		super(position, optionalType);
23
+	}
24
+
25
+	@Override
26
+	public <T> T accept(ExpressionVisitor<T> visitor) {
27
+		return visitor.visitNull(this);
28
+	}
29
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/OrOrExpression.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class OrOrExpression extends Expression {
16
+	public final Expression left;
17
+	public final Expression right;
18
+	
19
+	public OrOrExpression(CodePosition position, Expression left, Expression right) {
20
+		super(position, BasicTypeID.BOOL);
21
+		
22
+		this.left = left;
23
+		this.right = right;
24
+	}
25
+
26
+	@Override
27
+	public <T> T accept(ExpressionVisitor<T> visitor) {
28
+		return visitor.visitOrOr(this);
29
+	}
30
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/RangeExpression.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class RangeExpression extends Expression {
16
+	public final Expression from;
17
+	public final Expression to;
18
+	
19
+	public RangeExpression(CodePosition position, GlobalTypeRegistry registry, Expression from, Expression to) {
20
+		super(position, registry.getRange(from.getType(), to.getType()));
21
+	
22
+		this.from = from;
23
+		this.to = to;
24
+	}
25
+
26
+	@Override
27
+	public <T> T accept(ExpressionVisitor<T> visitor) {
28
+		return visitor.visitRange(this);
29
+	}
30
+}

+ 32
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetFieldExpression.java Parādīt failu

@@ -0,0 +1,32 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.member.FieldMember;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class SetFieldExpression extends Expression {
16
+	public final Expression target;
17
+	public final FieldMember field;
18
+	public final Expression value;
19
+	
20
+	public SetFieldExpression(CodePosition position, Expression target, FieldMember field, Expression value) {
21
+		super(position, field.type);
22
+		
23
+		this.target = target;
24
+		this.field = field;
25
+		this.value = value;
26
+	}
27
+
28
+	@Override
29
+	public <T> T accept(ExpressionVisitor<T> visitor) {
30
+		return visitor.visitSetField(this);
31
+	}
32
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetFunctionParameterExpression.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.FunctionParameter;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class SetFunctionParameterExpression extends Expression {
16
+	public final FunctionParameter parameter;
17
+	public final Expression value;
18
+	
19
+	public SetFunctionParameterExpression(CodePosition position, FunctionParameter parameter, Expression value) {
20
+		super(position, parameter.type);
21
+		
22
+		this.parameter = parameter;
23
+		this.value = value;
24
+	}
25
+
26
+	@Override
27
+	public <T> T accept(ExpressionVisitor<T> visitor) {
28
+		return visitor.visitSetFunctionParameter(this);
29
+	}
30
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetLocalVariableExpression.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.statement.VarStatement;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class SetLocalVariableExpression extends Expression {
16
+	public final VarStatement variable;
17
+	public final Expression value;
18
+	
19
+	public SetLocalVariableExpression(CodePosition position, VarStatement variable, Expression value) {
20
+		super(position, variable.type);
21
+		
22
+		this.variable = variable;
23
+		this.value = value;
24
+	}
25
+
26
+	@Override
27
+	public <T> T accept(ExpressionVisitor<T> visitor) {
28
+		return visitor.visitSetLocalVariable(this);
29
+	}
30
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetStaticFieldExpression.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.member.FieldMember;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class SetStaticFieldExpression extends Expression {
16
+	public final FieldMember field;
17
+	public final Expression value;
18
+	
19
+	public SetStaticFieldExpression(CodePosition position, FieldMember field, Expression value) {
20
+		super(position, field.type);
21
+		
22
+		this.field = field;
23
+		this.value = value;
24
+	}
25
+
26
+	@Override
27
+	public <T> T accept(ExpressionVisitor<T> visitor) {
28
+		return visitor.visitSetStaticField(this);
29
+	}
30
+}

+ 32
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetterExpression.java Parādīt failu

@@ -0,0 +1,32 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.member.SetterMember;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class SetterExpression extends Expression {
16
+	public final Expression target;
17
+	public final SetterMember setter;
18
+	public final Expression value;
19
+	
20
+	public SetterExpression(CodePosition position, Expression target, SetterMember setter, Expression value) {
21
+		super(position, setter.type);
22
+		
23
+		this.target = target;
24
+		this.setter = setter;
25
+		this.value = value;
26
+	}
27
+
28
+	@Override
29
+	public <T> T accept(ExpressionVisitor<T> visitor) {
30
+		return visitor.visitSetter(this);
31
+	}
32
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StaticGetterExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.member.GetterMember;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class StaticGetterExpression extends Expression {
16
+	public final GetterMember getter;
17
+	
18
+	public StaticGetterExpression(CodePosition position, GetterMember getter) {
19
+		super(position, getter.type);
20
+		
21
+		this.getter = getter;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitStaticGetter(this);
27
+	}
28
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StaticSetterExpression.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.member.SetterMember;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class StaticSetterExpression extends Expression {
16
+	public final SetterMember setter;
17
+	public final Expression value;
18
+	
19
+	public StaticSetterExpression(CodePosition position, SetterMember setter, Expression value) {
20
+		super(position, setter.type);
21
+		
22
+		this.setter = setter;
23
+		this.value = value;
24
+	}
25
+
26
+	@Override
27
+	public <T> T accept(ExpressionVisitor<T> visitor) {
28
+		return visitor.visitStaticSetter(this);
29
+	}
30
+}

+ 31
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StringConcatExpression.java Parādīt failu

@@ -0,0 +1,31 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class StringConcatExpression extends Expression {
16
+	// either of these must be a basic type
17
+	public final Expression left;
18
+	public final Expression right;
19
+	
20
+	public StringConcatExpression(CodePosition position, Expression left, Expression right) {
21
+		super(position, BasicTypeID.STRING);
22
+		
23
+		this.left = left;
24
+		this.right = right;
25
+	}
26
+
27
+	@Override
28
+	public <T> T accept(ExpressionVisitor<T> visitor) {
29
+		return visitor.visitStringConcat(this);
30
+	}
31
+}

+ 29
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SubstringExpression.java Parādīt failu

@@ -0,0 +1,29 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.shared.CodePosition;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class SubstringExpression extends Expression {
15
+	public final Expression value;
16
+	public final Expression range;
17
+	
18
+	public SubstringExpression(CodePosition position, Expression value, Expression range) {
19
+		super(position, value.type);
20
+		
21
+		this.value = value;
22
+		this.range = range;
23
+	}
24
+
25
+	@Override
26
+	public <T> T accept(ExpressionVisitor<T> visitor) {
27
+		return visitor.visitSubstring(this);
28
+	}
29
+}

+ 32
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ThisExpression.java Parādīt failu

@@ -0,0 +1,32 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.partial.IPartialExpression;
9
+import org.openzen.zenscript.codemodel.type.ITypeID;
10
+import org.openzen.zenscript.shared.CodePosition;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class ThisExpression extends Expression {
17
+	public ThisExpression(CodePosition position, ITypeID type) {
18
+		super(position, type);
19
+	}
20
+	
21
+	@Override
22
+	public IPartialExpression capture(CodePosition position, LambdaClosure closure) {
23
+		CapturedExpression result = new CapturedThisExpression(position, type, closure);
24
+		closure.add(result);
25
+		return result;
26
+	}
27
+
28
+	@Override
29
+	public <T> T accept(ExpressionVisitor<T> visitor) {
30
+		return visitor.visitThis(this);
31
+	}
32
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/WrapOptionalExpression.java Parādīt failu

@@ -0,0 +1,28 @@
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.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class WrapOptionalExpression extends Expression {
16
+	public final Expression value;
17
+	
18
+	public WrapOptionalExpression(CodePosition position, Expression value, ITypeID optionalType) {
19
+		super(position, optionalType);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitWrapOptional(this);
27
+	}
28
+}

+ 24
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/GenericParameterBound.java Parādīt failu

@@ -0,0 +1,24 @@
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.codemodel.generic;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
10
+import org.openzen.zenscript.codemodel.type.ITypeID;
11
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
12
+import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public abstract class GenericParameterBound {
19
+	public abstract void registerMembers(LocalMemberCache cache, TypeMembers type);
20
+	
21
+	public abstract boolean matches(ITypeID type);
22
+	
23
+	public abstract GenericParameterBound withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments);
24
+}

+ 39
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterSuperBound.java Parādīt failu

@@ -0,0 +1,39 @@
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.codemodel.generic;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
10
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
11
+import org.openzen.zenscript.codemodel.type.ITypeID;
12
+import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public class ParameterSuperBound extends GenericParameterBound {
19
+	public final ITypeID type;
20
+	
21
+	public ParameterSuperBound(ITypeID type) {
22
+		this.type = type;
23
+	}
24
+
25
+	@Override
26
+	public void registerMembers(LocalMemberCache cache, TypeMembers type) {
27
+		// TODO: nothing?
28
+	}
29
+
30
+	@Override
31
+	public boolean matches(ITypeID type) {
32
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
33
+	}
34
+
35
+	@Override
36
+	public GenericParameterBound withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
37
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
38
+	}
39
+}

+ 43
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java Parādīt failu

@@ -0,0 +1,43 @@
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.codemodel.generic;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
10
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
11
+import org.openzen.zenscript.codemodel.type.ITypeID;
12
+import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
13
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
14
+import org.openzen.zenscript.shared.CodePosition;
15
+
16
+/**
17
+ *
18
+ * @author Hoofdgebruiker
19
+ */
20
+public class ParameterTypeBound extends GenericParameterBound {
21
+	public final CodePosition position;
22
+	public final ITypeID type;
23
+	
24
+	public ParameterTypeBound(CodePosition position, ITypeID type) {
25
+		this.position = position;
26
+		this.type = type;
27
+	}
28
+
29
+	@Override
30
+	public void registerMembers(LocalMemberCache cache, TypeMembers type) {
31
+		cache.get(this.type).copyMembersTo(position, type, TypeMemberPriority.SPECIFIED);
32
+	}
33
+
34
+	@Override
35
+	public boolean matches(ITypeID type) {
36
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
37
+	}
38
+
39
+	@Override
40
+	public GenericParameterBound withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
41
+		return new ParameterTypeBound(position, type.withGenericArguments(registry, arguments));
42
+	}
43
+}

+ 60
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java Parādīt failu

@@ -0,0 +1,60 @@
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.codemodel.generic;
7
+
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+import java.util.Map;
11
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
+import org.openzen.zenscript.codemodel.type.ITypeID;
13
+import org.openzen.zenscript.shared.CodePosition;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class TypeParameter {
20
+	public final CodePosition position;
21
+	public final String name;
22
+	public final List<GenericParameterBound> bounds = new ArrayList<>();
23
+	
24
+	public TypeParameter(CodePosition position, String name) {
25
+		this.position = position;
26
+		this.name = name;
27
+	}
28
+	
29
+	private TypeParameter(CodePosition position, String name, List<GenericParameterBound> bounds) {
30
+		this.position = position;
31
+		this.name = name;
32
+		bounds.addAll(bounds);
33
+	}
34
+	
35
+	public void addBound(GenericParameterBound bound) {
36
+		bounds.add(bound);
37
+	}
38
+	
39
+	public boolean matches(ITypeID type) {
40
+		for (GenericParameterBound bound : bounds) {
41
+			if (!bound.matches(type))
42
+				return false;
43
+		}
44
+		
45
+		return true;
46
+	}
47
+	
48
+	public TypeParameter withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
49
+		// TODO: think about this...
50
+		//List<GenericParameterBound> bounds = new ArrayList<>();
51
+		//for (GenericParameterBound bound : this.bounds)
52
+		//	bounds.add(bound.withGenericArguments(registry, arguments));
53
+		//return new TypeParameter(name, bounds);
54
+		return this;
55
+	}
56
+	
57
+	public String toString() {
58
+		return name + "[" + position.toShortString() + "]";
59
+	}
60
+}

+ 20
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/iterator/ForeachIteratorVisitor.java Parādīt failu

@@ -0,0 +1,20 @@
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.codemodel.iterator;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface ForeachIteratorVisitor<T> {
13
+	T visitIntRange();
14
+	
15
+	T visitArrayValueIterator();
16
+	
17
+	T visitArrayKeyValueIterator();
18
+	
19
+	T visitCustomIterator();
20
+}

+ 45
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CallerMember.java Parādīt failu

@@ -0,0 +1,45 @@
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.codemodel.member;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
+import org.openzen.zenscript.codemodel.type.ITypeID;
13
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
14
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15
+import org.openzen.zenscript.shared.CodePosition;
16
+
17
+/**
18
+ *
19
+ * @author Hoofdgebruiker
20
+ */
21
+public class CallerMember extends FunctionalMember {
22
+	public CallerMember(CodePosition position, int modifiers, FunctionHeader header) {
23
+		super(position, modifiers, header);
24
+	}
25
+
26
+	@Override
27
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
28
+		type.addCaller(this, priority);
29
+	}
30
+
31
+	@Override
32
+	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
33
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
34
+	}
35
+
36
+	@Override
37
+	public String describe() {
38
+		return "caller " + header.toString();
39
+	}
40
+
41
+	@Override
42
+	public <T> T accept(MemberVisitor<T> visitor) {
43
+		return visitor.visitCaller(this);
44
+	}
45
+}

+ 68
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CasterMember.java Parādīt failu

@@ -0,0 +1,68 @@
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.codemodel.member;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.Modifiers;
11
+import org.openzen.zenscript.codemodel.expression.CallArguments;
12
+import org.openzen.zenscript.codemodel.expression.CallExpression;
13
+import org.openzen.zenscript.codemodel.expression.Expression;
14
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
15
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17
+import org.openzen.zenscript.codemodel.type.ITypeID;
18
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
19
+import org.openzen.zenscript.shared.CodePosition;
20
+
21
+/**
22
+ *
23
+ * @author Hoofdgebruiker
24
+ */
25
+public class CasterMember extends FunctionalMember implements ICasterMember {
26
+	public final ITypeID toType;
27
+	
28
+	public CasterMember(CodePosition position, int modifiers, ITypeID toType) {
29
+		super(position, modifiers, new FunctionHeader(toType));
30
+		
31
+		this.toType = toType;
32
+	}
33
+
34
+	@Override
35
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
36
+		type.addCaster(this, priority);
37
+	}
38
+
39
+	@Override
40
+	public String describe() {
41
+		return "caster to " + toType.toString();
42
+	}
43
+
44
+	@Override
45
+	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
46
+		return new CasterMember(position, modifiers, toType.withGenericArguments(registry, mapping));
47
+	}
48
+	
49
+	@Override
50
+	public ITypeID getTargetType() {
51
+		return toType;
52
+	}
53
+
54
+	@Override
55
+	public Expression cast(CodePosition position, Expression value, ITypeID toType) {
56
+		return new CallExpression(position, value, this, header, CallArguments.EMPTY);
57
+	}
58
+	
59
+	@Override
60
+	public boolean isImplicit() {
61
+		return Modifiers.isImplicit(modifiers);
62
+	}
63
+
64
+	@Override
65
+	public <T> T accept(MemberVisitor<T> visitor) {
66
+		return visitor.visitCaster(this);
67
+	}
68
+}

+ 47
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java Parādīt failu

@@ -0,0 +1,47 @@
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.codemodel.member;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
12
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13
+import org.openzen.zenscript.codemodel.type.ITypeID;
14
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
15
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16
+import org.openzen.zenscript.shared.CodePosition;
17
+
18
+/**
19
+ *
20
+ * @author Hoofdgebruiker
21
+ */
22
+public class ConstructorMember extends FunctionalMember {
23
+	public ConstructorMember(CodePosition position, int modifiers, FunctionHeader header) {
24
+		super(position, modifiers, new FunctionHeader(header.typeParameters, BasicTypeID.VOID, header.parameters));
25
+	}
26
+
27
+	@Override
28
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
29
+		if (priority == TypeMemberPriority.SPECIFIED)
30
+			type.addConstructor(this, priority);
31
+	}
32
+
33
+	@Override
34
+	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
35
+		return new ConstructorMember(position, modifiers, header.instance(registry, mapping));
36
+	}
37
+
38
+	@Override
39
+	public String describe() {
40
+		return "constructor " + header.toString();
41
+	}
42
+
43
+	@Override
44
+	public <T> T accept(MemberVisitor<T> visitor) {
45
+		return visitor.visitConstructor(this);
46
+	}
47
+}

+ 74
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CustomIteratorMember.java Parādīt failu

@@ -0,0 +1,74 @@
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.codemodel.member;
7
+
8
+import java.util.List;
9
+import java.util.Map;
10
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
+import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12
+import org.openzen.zenscript.codemodel.statement.Statement;
13
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
14
+import org.openzen.zenscript.codemodel.type.ITypeID;
15
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
16
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17
+import org.openzen.zenscript.shared.CodePosition;
18
+
19
+/**
20
+ *
21
+ * @author Hoofdgebruiker
22
+ */
23
+public class CustomIteratorMember extends DefinitionMember implements IIteratorMember {
24
+	private final ITypeID[] iteratorTypes;
25
+	private List<Statement> content;
26
+	
27
+	public CustomIteratorMember(CodePosition position, int modifiers, ITypeID[] iteratorTypes) {
28
+		super(position, modifiers);
29
+		
30
+		this.iteratorTypes = iteratorTypes;
31
+	}
32
+	
33
+	public void setContent(List<Statement> content) {
34
+		this.content = content;
35
+	}
36
+
37
+	@Override
38
+	public int getLoopVariableCount() {
39
+		return iteratorTypes.length;
40
+	}
41
+
42
+	@Override
43
+	public ITypeID[] getLoopVariableTypes() {
44
+		return iteratorTypes;
45
+	}
46
+
47
+	@Override
48
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
49
+		type.addIterator(this, priority);
50
+	}
51
+
52
+	@Override
53
+	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
54
+		ITypeID[] newIteratorTypes = new ITypeID[iteratorTypes.length];
55
+		for (int i = 0; i < newIteratorTypes.length; i++)
56
+			newIteratorTypes[i] = iteratorTypes[i].withGenericArguments(registry, mapping);
57
+		return new CustomIteratorMember(position, modifiers, newIteratorTypes);
58
+	}
59
+
60
+	@Override
61
+	public String describe() {
62
+		return "iterator with " + iteratorTypes.length + " variables";
63
+	}
64
+
65
+	@Override
66
+	public <T> T accept(MemberVisitor<T> visitor) {
67
+		return visitor.visitCustomIterator(this);
68
+	}
69
+
70
+	@Override
71
+	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
72
+		return visitor.visitCustomIterator();
73
+	}
74
+}

+ 32
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DefinitionMember.java Parādīt failu

@@ -0,0 +1,32 @@
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.codemodel.member;
7
+
8
+import org.openzen.zenscript.codemodel.Modifiers;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public abstract class DefinitionMember implements IDefinitionMember {
16
+	public final CodePosition position;
17
+	public final int modifiers;
18
+	
19
+	public DefinitionMember(CodePosition position, int modifiers) {
20
+		this.position = position;
21
+		this.modifiers = modifiers;
22
+	}
23
+	
24
+	@Override
25
+	public final CodePosition getPosition() {
26
+		return position;
27
+	}
28
+	
29
+	public boolean isStatic() {
30
+		return Modifiers.isStatic(modifiers);
31
+	}
32
+}

+ 49
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EnumConstantMember.java Parādīt failu

@@ -0,0 +1,49 @@
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.codemodel.member;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.Modifiers;
10
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
+import org.openzen.zenscript.codemodel.type.ITypeID;
13
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
14
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15
+import org.openzen.zenscript.shared.CodePosition;
16
+
17
+/**
18
+ *
19
+ * @author Hoofdgebruiker
20
+ */
21
+public class EnumConstantMember extends DefinitionMember {
22
+	public final String name;
23
+	
24
+	public EnumConstantMember(CodePosition position, String name) {
25
+		super(position, Modifiers.MODIFIER_STATIC);
26
+		
27
+		this.name = name;
28
+	}
29
+
30
+	@Override
31
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
32
+		type.addEnumMember(this, priority);
33
+	}
34
+
35
+	@Override
36
+	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
37
+		throw new UnsupportedOperationException("Enums can't have type parameters");
38
+	}
39
+
40
+	@Override
41
+	public String describe() {
42
+		return "enum member " + name;
43
+	}
44
+
45
+	@Override
46
+	public <T> T accept(MemberVisitor<T> visitor) {
47
+		return visitor.visitEnumConstant(this);
48
+	}
49
+}

+ 92
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EqualsMember.java Parādīt failu

@@ -0,0 +1,92 @@
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.codemodel.member;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.CompareType;
10
+import org.openzen.zenscript.codemodel.FunctionHeader;
11
+import org.openzen.zenscript.codemodel.FunctionParameter;
12
+import org.openzen.zenscript.codemodel.OperatorType;
13
+import org.openzen.zenscript.codemodel.expression.CallArguments;
14
+import org.openzen.zenscript.codemodel.expression.EqualsExpression;
15
+import org.openzen.zenscript.codemodel.expression.Expression;
16
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
17
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
18
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19
+import org.openzen.zenscript.codemodel.type.ITypeID;
20
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
21
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
22
+import org.openzen.zenscript.shared.CodePosition;
23
+
24
+/**
25
+ *
26
+ * @author Hoofdgebruiker
27
+ */
28
+public class EqualsMember implements ICallableMember {
29
+	private final ITypeID type;
30
+	private final FunctionHeader header;
31
+	
32
+	public EqualsMember(ITypeID type) {
33
+		this.type = type;
34
+		this.header = new FunctionHeader(BasicTypeID.BOOL, new FunctionParameter(type));
35
+	}
36
+	
37
+	@Override
38
+	public boolean isStatic() {
39
+		return false;
40
+	}
41
+
42
+	@Override
43
+	public FunctionHeader getHeader() {
44
+		return header;
45
+	}
46
+
47
+	@Override
48
+	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
49
+		return new EqualsExpression(position, target, arguments.arguments[0]);
50
+	}
51
+
52
+	@Override
53
+	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
54
+		throw new UnsupportedOperationException("Comparator not supported here");
55
+	}
56
+
57
+	@Override
58
+	public Expression callStatic(CodePosition position, FunctionHeader instancedHeader, CallArguments arguments) {
59
+		throw new UnsupportedOperationException("Cannot be called statically");
60
+	}
61
+
62
+	@Override
63
+	public Expression callStaticWithComparator(CodePosition position, CompareType operator, FunctionHeader instancedHeader, CallArguments arguments) {
64
+		throw new UnsupportedOperationException("Cannot be called statically");
65
+	}
66
+
67
+	@Override
68
+	public CodePosition getPosition() {
69
+		return CodePosition.BUILTIN;
70
+	}
71
+
72
+	@Override
73
+	public String describe() {
74
+		return "equals operator";
75
+	}
76
+
77
+	@Override
78
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
79
+		type.addOperator(OperatorType.EQUALS, this, priority);
80
+	}
81
+
82
+	@Override
83
+	public IDefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
84
+		ITypeID instanced = type.withGenericArguments(registry, mapping);
85
+		return instanced == type ? this : new EqualsMember(instanced);
86
+	}
87
+
88
+	@Override
89
+	public <T> T accept(MemberVisitor<T> visitor) {
90
+		throw new UnsupportedOperationException("Not yet supported");
91
+	}
92
+}

+ 58
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java Parādīt failu

@@ -0,0 +1,58 @@
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.codemodel.member;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.expression.Expression;
10
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
13
+import org.openzen.zenscript.codemodel.type.ITypeID;
14
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
15
+import org.openzen.zenscript.shared.CodePosition;
16
+
17
+/**
18
+ *
19
+ * @author Hoofdgebruiker
20
+ */
21
+public class FieldMember extends DefinitionMember {
22
+	public final String name;
23
+	public final ITypeID type;
24
+	public final boolean isFinal;
25
+	public Expression initializer;
26
+	
27
+	public FieldMember(CodePosition position, int modifiers, String name, ITypeID type, boolean isFinal) {
28
+		super(position, modifiers);
29
+		
30
+		this.name = name;
31
+		this.type = type;
32
+		this.isFinal = isFinal;
33
+	}
34
+	
35
+	public void setInitializer(Expression initializer) {
36
+		this.initializer = initializer;
37
+	}
38
+
39
+	@Override
40
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
41
+		type.addField(this, priority);
42
+	}
43
+
44
+	@Override
45
+	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
46
+		return new FieldMember(position, modifiers, name, type.withGenericArguments(registry, mapping), isFinal);
47
+	}
48
+
49
+	@Override
50
+	public String describe() {
51
+		return "field " + name;
52
+	}
53
+
54
+	@Override
55
+	public <T> T accept(MemberVisitor<T> visitor) {
56
+		return visitor.visitField(this);
57
+	}
58
+}

+ 61
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java Parādīt failu

@@ -0,0 +1,61 @@
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.codemodel.member;
7
+
8
+import java.util.List;
9
+import org.openzen.zenscript.codemodel.CompareType;
10
+import org.openzen.zenscript.codemodel.FunctionHeader;
11
+import org.openzen.zenscript.codemodel.expression.CallArguments;
12
+import org.openzen.zenscript.codemodel.expression.CallExpression;
13
+import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
14
+import org.openzen.zenscript.codemodel.expression.Expression;
15
+import org.openzen.zenscript.codemodel.expression.GenericCompareExpression;
16
+import org.openzen.zenscript.codemodel.statement.Statement;
17
+import org.openzen.zenscript.shared.CodePosition;
18
+
19
+/**
20
+ *
21
+ * @author Hoofdgebruiker
22
+ */
23
+public abstract class FunctionalMember extends DefinitionMember implements ICallableMember {
24
+	public final FunctionHeader header;
25
+	public List<Statement> body;
26
+	
27
+	public FunctionalMember(CodePosition position, int modifiers, FunctionHeader header) {
28
+		super(position, modifiers);
29
+		
30
+		this.header = header;
31
+	}
32
+	
33
+	public void setBody(List<Statement> body) {
34
+		this.body = body;
35
+	}
36
+	
37
+	@Override
38
+	public FunctionHeader getHeader() {
39
+		return header;
40
+	}
41
+
42
+	@Override
43
+	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
44
+		return new CallExpression(position, target, this, instancedHeader, arguments);
45
+	}
46
+	
47
+	@Override
48
+	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
49
+		return new GenericCompareExpression(position, call(position, target, instancedHeader, arguments), operator);
50
+	}
51
+	
52
+	@Override
53
+	public Expression callStatic(CodePosition position, FunctionHeader instancedHeader, CallArguments arguments) {
54
+		return new CallStaticExpression(position, this, arguments);
55
+	}
56
+	
57
+	@Override
58
+	public Expression callStaticWithComparator(CodePosition position, CompareType operator, FunctionHeader instancedHeader, CallArguments arguments) {
59
+		return new GenericCompareExpression(position, callStatic(position, instancedHeader, arguments), operator);
60
+	}
61
+}

+ 76
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java Parādīt failu

@@ -0,0 +1,76 @@
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.codemodel.member;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.expression.Expression;
11
+import org.openzen.zenscript.codemodel.expression.GetterExpression;
12
+import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
13
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16
+import org.openzen.zenscript.codemodel.type.ITypeID;
17
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
18
+import org.openzen.zenscript.shared.CodePosition;
19
+
20
+/**
21
+ *
22
+ * @author Hoofdgebruiker
23
+ */
24
+public class GetterMember extends FunctionalMember implements IGettableMember {
25
+	public final String name;
26
+	public final ITypeID type;
27
+	
28
+	public String compiledName;
29
+	
30
+	public GetterMember(CodePosition position, int modifiers, String name, ITypeID type) {
31
+		super(position, modifiers, new FunctionHeader(type));
32
+		
33
+		this.name = name;
34
+		this.type = type;
35
+	}
36
+	
37
+	@Override
38
+	public String getName() {
39
+		return name;
40
+	}
41
+	
42
+	@Override
43
+	public ITypeID getType() {
44
+		return type;
45
+	}
46
+	
47
+	@Override
48
+	public Expression get(CodePosition position, Expression target) {
49
+		return new GetterExpression(position, target, this);
50
+	}
51
+	
52
+	@Override
53
+	public Expression getStatic(CodePosition position) {
54
+		return new StaticGetterExpression(position, this);
55
+	}
56
+
57
+	@Override
58
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
59
+		type.addGetter(this, priority);
60
+	}
61
+
62
+	@Override
63
+	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
64
+		return new GetterMember(position, modifiers, name, type.withGenericArguments(registry, mapping));
65
+	}
66
+
67
+	@Override
68
+	public String describe() {
69
+		return "getter " + name;
70
+	}
71
+
72
+	@Override
73
+	public <T> T accept(MemberVisitor<T> visitor) {
74
+		return visitor.visitGetter(this);
75
+	}
76
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ICallableMember.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.member;
7
+
8
+import org.openzen.zenscript.codemodel.CompareType;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.expression.CallArguments;
11
+import org.openzen.zenscript.codemodel.expression.Expression;
12
+import org.openzen.zenscript.shared.CodePosition;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public interface ICallableMember extends IDefinitionMember {
19
+	public boolean isStatic();
20
+	
21
+	public FunctionHeader getHeader();
22
+	
23
+	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments);
24
+	
25
+	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments);
26
+	
27
+	public Expression callStatic(CodePosition position, FunctionHeader instancedHeader, CallArguments arguments);
28
+	
29
+	public Expression callStaticWithComparator(CodePosition position, CompareType operator, FunctionHeader instancedHeader, CallArguments arguments);
30
+}

+ 22
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ICasterMember.java Parādīt failu

@@ -0,0 +1,22 @@
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.codemodel.member;
7
+
8
+import org.openzen.zenscript.codemodel.expression.Expression;
9
+import org.openzen.zenscript.codemodel.type.ITypeID;
10
+import org.openzen.zenscript.shared.CodePosition;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public interface ICasterMember extends IDefinitionMember {
17
+	public ITypeID getTargetType();
18
+	
19
+	public Expression cast(CodePosition position, Expression value, ITypeID toType);
20
+	
21
+	public boolean isImplicit();
22
+}

+ 30
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IDefinitionMember.java Parādīt failu

@@ -0,0 +1,30 @@
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.codemodel.member;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
10
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
11
+import org.openzen.zenscript.codemodel.type.ITypeID;
12
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
13
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
14
+import org.openzen.zenscript.shared.CodePosition;
15
+
16
+/**
17
+ *
18
+ * @author Hoofdgebruiker
19
+ */
20
+public interface IDefinitionMember {
21
+	public CodePosition getPosition();
22
+	
23
+	public String describe();
24
+	
25
+	public void registerTo(TypeMembers type, TypeMemberPriority priority);
26
+	
27
+	public IDefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping);
28
+	
29
+	public <T> T accept(MemberVisitor<T> visitor);
30
+}

+ 0
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IGettableMember.java Parādīt failu


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels

Notiek ielāde…
Atcelt
Saglabāt