瀏覽代碼

Fix calling of functions with generic parameters

Stan Hebben 6 年之前
父節點
當前提交
bcebf627ba
共有 16 個檔案被更改,包括 36 行新增27 行删除
  1. 13
    6
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/DefinitionFormatter.java
  2. 3
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java
  3. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java
  4. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java
  5. 4
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialTypeExpression.java
  6. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java
  7. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  8. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/DefinitionScope.java
  9. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/FileScope.java
  10. 1
    1
      Linker/src/main/java/org/openzen/zenscript/linker/FunctionScope.java
  11. 1
    1
      Linker/src/main/java/org/openzen/zenscript/linker/GenericFunctionScope.java
  12. 1
    1
      Linker/src/main/java/org/openzen/zenscript/linker/ImplementationScope.java
  13. 1
    1
      Linker/src/main/java/org/openzen/zenscript/linker/symbol/TypeSymbol.java
  14. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionSuper.java
  15. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTypeExpression.java
  16. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeGenericMap.java

+ 13
- 6
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/DefinitionFormatter.java 查看文件

@@ -15,7 +15,7 @@ import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
15 15
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
16 16
 import org.openzen.zenscript.codemodel.definition.StructDefinition;
17 17
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
18
-import org.openzen.zenscript.codemodel.expression.CallArguments;
18
+import org.openzen.zenscript.codemodel.member.CallerMember;
19 19
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
20 20
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
21 21
 
@@ -140,11 +140,18 @@ public class DefinitionFormatter implements DefinitionVisitor<Void> {
140 140
 
141 141
 	@Override
142 142
 	public Void visitFunction(FunctionDefinition definition) {
143
-		FormattingUtils.formatModifiers(output, definition.modifiers);
144
-		output.append("function ");
145
-		output.append(definition.name);
146
-		FormattingUtils.formatHeader(output, settings, definition.header, typeFormatter);
147
-		FormattingUtils.formatBody(output, settings, indent, typeFormatter, definition.statement);
143
+		for (IDefinitionMember member : definition.members) {
144
+			if (member instanceof CallerMember) {
145
+				CallerMember caller = (CallerMember) member;
146
+				FormattingUtils.formatModifiers(output, definition.modifiers);
147
+				output.append("function ");
148
+				output.append(definition.name);
149
+				
150
+				FormattingUtils.formatHeader(output, settings, caller.header, typeFormatter);
151
+				FormattingUtils.formatBody(output, settings, indent, typeFormatter, caller.body);
152
+			}
153
+		}
154
+		
148 155
 		return null;
149 156
 	}
150 157
 

+ 3
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java 查看文件

@@ -9,6 +9,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
9 9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10 10
 import org.openzen.zenscript.codemodel.Modifiers;
11 11
 import org.openzen.zenscript.codemodel.OperatorType;
12
+import org.openzen.zenscript.codemodel.member.CallerMember;
12 13
 import org.openzen.zenscript.codemodel.member.OperatorMember;
13 14
 import org.openzen.zenscript.codemodel.statement.Statement;
14 15
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
@@ -22,7 +23,7 @@ import org.openzen.zenscript.shared.CodePosition;
22 23
 public class FunctionDefinition extends HighLevelDefinition {
23 24
 	public FunctionHeader header;
24 25
 	public Statement statement;
25
-	public OperatorMember caller;
26
+	public CallerMember caller;
26 27
 	public final DefinitionMemberGroup callerGroup;
27 28
 	
28 29
 	public FunctionDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
@@ -37,9 +38,7 @@ public class FunctionDefinition extends HighLevelDefinition {
37 38
 	
38 39
 	public void setHeader(FunctionHeader header) {
39 40
 		this.header = header;
40
-		this.genericParameters = header.typeParameters;
41
-		header = new FunctionHeader(null, header.returnType, header.thrownType, header.parameters);
42
-		addMember(caller = new OperatorMember(position, this, modifiers | Modifiers.STATIC, OperatorType.CALL, header));
41
+		addMember(caller = new CallerMember(position, this, modifiers | Modifiers.STATIC, header));
43 42
 		callerGroup.addMethod(caller, TypeMemberPriority.SPECIFIED);
44 43
 	}
45 44
 	

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java 查看文件

@@ -49,7 +49,7 @@ public class ZSPackage {
49 49
 			if (types.get(name.name).genericParameters.length != name.getNumberOfArguments())
50 50
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
51 51
 			
52
-			return new PartialTypeExpression(position, registry.getForDefinition(types.get(name.name), name.arguments));
52
+			return new PartialTypeExpression(position, registry.getForDefinition(types.get(name.name), name.arguments), name.arguments);
53 53
 		}
54 54
 		
55 55
 		return null;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java 查看文件

@@ -22,7 +22,7 @@ public class CallStaticExpression extends Expression {
22 22
 	public final FunctionHeader instancedHeader;
23 23
 	
24 24
 	public CallStaticExpression(CodePosition position, ITypeID target, FunctionalMember member, CallArguments arguments, FunctionHeader instancedHeader, TypeScope scope) {
25
-		super(position, member.header.returnType, multiThrow(position, arguments.arguments));
25
+		super(position, instancedHeader.returnType, multiThrow(position, arguments.arguments));
26 26
 		
27 27
 		this.member = member;
28 28
 		this.target = target;

+ 4
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialTypeExpression.java 查看文件

@@ -26,10 +26,12 @@ import org.openzen.zenscript.codemodel.scope.TypeScope;
26 26
 public class PartialTypeExpression implements IPartialExpression {
27 27
 	private final CodePosition position;
28 28
 	private final ITypeID type;
29
+	private final ITypeID[] typeParameters;
29 30
 	
30
-	public PartialTypeExpression(CodePosition position, ITypeID type) {
31
+	public PartialTypeExpression(CodePosition position, ITypeID type, ITypeID[] typeParameters) {
31 32
 		this.position = position;
32 33
 		this.type = type;
34
+		this.typeParameters = typeParameters;
33 35
 	}
34 36
 
35 37
 	@Override
@@ -64,7 +66,7 @@ public class PartialTypeExpression implements IPartialExpression {
64 66
 
65 67
 	@Override
66 68
 	public ITypeID[] getGenericCallTypes() {
67
-		return null;
69
+		return typeParameters;
68 70
 	}
69 71
 	
70 72
 	@Override

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java 查看文件

@@ -10,6 +10,7 @@ import java.util.HashMap;
10 10
 import java.util.Map;
11 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
12 12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
13 14
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
14 15
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
15 16
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_CONST;
@@ -119,7 +120,7 @@ public class GlobalTypeRegistry {
119 120
 	
120 121
 	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID[] typeParameters, Map<TypeParameter, ITypeID> outerInstance) {
121 122
 		DefinitionTypeID id;
122
-		if (definition.genericParameters == null && typeParameters == null && outerInstance.isEmpty()) {
123
+		if ((definition instanceof FunctionDefinition) || (definition.genericParameters == null && typeParameters == null && outerInstance.isEmpty())) {
123 124
 			// make it a static one
124 125
 			id = new StaticDefinitionTypeID(definition);
125 126
 		} else {

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java 查看文件

@@ -439,7 +439,7 @@ public final class TypeMembers {
439 439
 		if (members.containsKey(name.name))
440 440
 			return new PartialStaticMemberGroupExpression(position, type, members.get(name.name), name.arguments);
441 441
 		if (innerTypes.containsKey(name.name))
442
-			return new PartialTypeExpression(position, innerTypes.get(name.name).instance(cache.getRegistry(), name.arguments));
442
+			return new PartialTypeExpression(position, innerTypes.get(name.name).instance(cache.getRegistry(), name.arguments), name.arguments);
443 443
 		
444 444
 		return null;
445 445
 	}

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/DefinitionScope.java 查看文件

@@ -75,12 +75,12 @@ public class DefinitionScope extends BaseScope {
75 75
 	public IPartialExpression get(CodePosition position, GenericName name) {
76 76
 		if (members != null) {
77 77
 			if (members.hasInnerType(name.name))
78
-				return new PartialTypeExpression(position, members.getInnerType(position, name));
78
+				return new PartialTypeExpression(position, members.getInnerType(position, name), name.arguments);
79 79
 			if (members.hasMember(name.name) && !name.hasArguments())
80 80
 				return members.getMemberExpression(position, new ThisExpression(position, type), name, true);
81 81
 		}
82 82
 		if (genericParameters.containsKey(name.name) && !name.hasArguments())
83
-			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(genericParameters.get(name.name)));
83
+			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(genericParameters.get(name.name)), name.arguments);
84 84
 		
85 85
 		return outer.get(position, name);
86 86
 	}

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/FileScope.java 查看文件

@@ -69,11 +69,11 @@ public class FileScope extends BaseScope {
69 69
 	@Override
70 70
 	public IPartialExpression get(CodePosition position, GenericName name) {
71 71
 		if (importedTypes.containsKey(name.name))
72
-			return new PartialTypeExpression(position, getTypeRegistry().getForDefinition(importedTypes.get(name.name), name.arguments));
72
+			return new PartialTypeExpression(position, getTypeRegistry().getForDefinition(importedTypes.get(name.name), name.arguments), name.arguments);
73 73
 		
74 74
 		HighLevelDefinition localDefinition = packageDefinitions.getDefinition(name.name);
75 75
 		if (localDefinition != null)
76
-			return new PartialTypeExpression(position, globalRegistry.getForDefinition(localDefinition, name.arguments));
76
+			return new PartialTypeExpression(position, globalRegistry.getForDefinition(localDefinition, name.arguments), name.arguments);
77 77
 		
78 78
 		if (globalSymbols.containsKey(name.name)) {
79 79
 			IPartialExpression resolution = globalSymbols.get(name.name).getExpression(position, globalRegistry, name.arguments);

+ 1
- 1
Linker/src/main/java/org/openzen/zenscript/linker/FunctionScope.java 查看文件

@@ -64,7 +64,7 @@ public class FunctionScope extends StatementScope {
64 64
 			if (header.typeParameters != null) {
65 65
 				for (TypeParameter parameter : header.typeParameters) {
66 66
 					if (parameter.name.equals(name.name))
67
-						return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameter));
67
+						return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameter), name.arguments);
68 68
 				}
69 69
 			}
70 70
 		}

+ 1
- 1
Linker/src/main/java/org/openzen/zenscript/linker/GenericFunctionScope.java 查看文件

@@ -44,7 +44,7 @@ public class GenericFunctionScope extends BaseScope {
44 44
 	@Override
45 45
 	public IPartialExpression get(CodePosition position, GenericName name) {
46 46
 		if (parameters.containsKey(name.name) && name.hasNoArguments())
47
-			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameters.get(name.name)));
47
+			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameters.get(name.name)), name.arguments);
48 48
 		
49 49
 		return outer.get(position, name);
50 50
 	}

+ 1
- 1
Linker/src/main/java/org/openzen/zenscript/linker/ImplementationScope.java 查看文件

@@ -52,7 +52,7 @@ public class ImplementationScope extends BaseScope {
52 52
 	@Override
53 53
 	public IPartialExpression get(CodePosition position, GenericName name) {
54 54
 		if (members.hasInnerType(name.name))
55
-			return new PartialTypeExpression(position, members.getInnerType(position, name));
55
+			return new PartialTypeExpression(position, members.getInnerType(position, name), name.arguments);
56 56
 		if (members.hasMember(name.name))
57 57
 			return members.getMemberExpression(position, new ThisExpression(position, outer.getThisType()), name, true);
58 58
 		

+ 1
- 1
Linker/src/main/java/org/openzen/zenscript/linker/symbol/TypeSymbol.java 查看文件

@@ -25,7 +25,7 @@ public class TypeSymbol implements ISymbol {
25 25
 	
26 26
 	@Override
27 27
 	public IPartialExpression getExpression(CodePosition position, GlobalTypeRegistry types, ITypeID[] typeArguments) {
28
-		return new PartialTypeExpression(position, types.getForDefinition(definition, typeArguments));
28
+		return new PartialTypeExpression(position, types.getForDefinition(definition, typeArguments), typeArguments);
29 29
 	}
30 30
 
31 31
 	@Override

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionSuper.java 查看文件

@@ -28,7 +28,7 @@ public class ParsedExpressionSuper extends ParsedExpression {
28 28
 		if (type.getSuperType() == null)
29 29
 			throw new CompileException(position, CompileExceptionCode.SUPER_CALL_NO_SUPERCLASS, "Type has no superclass");
30 30
 		
31
-		return new PartialTypeExpression(position, scope.getThisType().getSuperType());
31
+		return new PartialTypeExpression(position, scope.getThisType().getSuperType(), null);
32 32
 	}
33 33
 
34 34
 	@Override

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTypeExpression.java 查看文件

@@ -26,7 +26,7 @@ public class ParsedTypeExpression extends ParsedExpression {
26 26
 
27 27
 	@Override
28 28
 	public IPartialExpression compile(ExpressionScope scope) {
29
-		return new PartialTypeExpression(position, type.compile(scope));
29
+		return new PartialTypeExpression(position, type.compile(scope), null);
30 30
 	}
31 31
 
32 32
 	@Override

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeGenericMap.java 查看文件

@@ -76,7 +76,7 @@ public class ParsedTypeGenericMap implements IParsedType {
76 76
 		@Override
77 77
 		public IPartialExpression get(CodePosition position, GenericName name) {
78 78
 			if (typeParameters.containsKey(name.name) && name.hasNoArguments())
79
-				return new PartialTypeExpression(position, getTypeRegistry().getGeneric(typeParameters.get(name.name)));
79
+				return new PartialTypeExpression(position, getTypeRegistry().getGeneric(typeParameters.get(name.name)), name.arguments);
80 80
 			
81 81
 			return outer.get(position, name);
82 82
 		}

Loading…
取消
儲存