EOS 2  1.1.0
Einfache Objektbasierte Sprache
Invoke.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.baseparser;
2 
3 import java.util.ArrayList;
4 
5 import de.lathanda.eos.vm.Command;
6 import de.lathanda.eos.vm.DebugPoint;
7 
14 public class Invoke extends Expression {
15  private Expression target;
16  private final String methodname;
17  private final Arguments arguments;
18  private MethodType methodType;
19 
20  public Invoke(Expression target, String methodname, Arguments arguments) {
21  this.target = target;
22  this.methodname = methodname;
23  this.arguments = arguments;
24  prio = 7;
25  }
26 
27  public String getMethodname() {
28  return methodname;
29  }
30 
32  return arguments;
33  }
34 
35  @Override
36  public void compile(ArrayList<Command> ops, boolean autowindow) throws Exception {
37  if (methodType == null) {
38  return;
39  }
40  arguments.compile(ops, autowindow);
41  ops.add(new DebugPoint(marker));
42  methodType.compile(ops, target, autowindow);
43  }
44 
45  @Override
46  public void resolveNamesAndTypes(Expression with, Environment env) {
47  arguments.resolveNamesAndTypes(with, env);
48  if (target == null) {
49  // Systemfunktion
50  methodType = SystemFunctionType.getSystemFunction(methodname, arguments.getTypes());
51  if (methodType != null) {
52  if (!methodType.checkType(arguments.getTypes())) {
53  env.addError(marker, "FunctionType", methodType, arguments);
54  }
55  type = methodType.getReturnType();
56  return;
57  } else {
58  methodType = env.getFunctionSignature(methodname, arguments.getTypes().length);
59  if (methodType != null) {
60  // usermethod
61  if (!methodType.checkType(arguments.getTypes())) {
62  env.addError(marker, "FunctionType", methodType, arguments);
63  }
64  type = methodType.getReturnType();
65  return;
66  } else {
67  if (with == null) {
68  env.addError(marker, "ProcedureNotFound", methodname);
69  return;
70  } else {
71  // apply with
72  target = with;
73  target.resolveNamesAndTypes(null, env);
74  }
75  }
76  }
77  } else {
78  // method
79  target.resolveNamesAndTypes(with, env);
80  }
81 
82  Type tartype = target.getType();
83  if (tartype == null) {
84  env.addError(marker, "UnknownVariable", target);
85  } else {
86  methodType = tartype.getMethod(methodname, arguments.getTypes());
87  }
88 
89  if (methodType == null) {
90  env.addError(marker, "UnknownInvoke", methodname, arguments.getTypes().length, tartype);
91  } else if (!methodType.checkType(arguments.getTypes())) {
92  env.addError(marker, "ParameterType", methodType, arguments);
93  } else if (methodType != null) {
94  type = methodType.getReturnType();
95 
96  } else {
97  env.addError(marker, "MethodNotFound", methodname);
98  }
99  }
100 
101  @Override
102  public String toString() {
103  if (target != null) {
104  return target + "." + methodname + arguments;
105  } else {
106  return methodname + arguments;
107  }
108  }
109 
110  @Override
111  public String getLabel() {
112  if (target != null) {
113  return createText("InvokeA.Label", getLabelLeft(target), methodname, arguments.getLabel());
114  } else {
115  return createText("InvokeB.Label", methodname, arguments.getLabel());
116  }
117  }
118 }
void resolveNamesAndTypes(Expression with, Environment env)
Definition: Arguments.java:36
void compile(ArrayList< Command > ops, boolean autoWindow)
Definition: Arguments.java:28
MethodType getFunctionSignature(String name, int args)
void addError(Marker marker, String errorId, Object... data)
Invoke(Expression target, String methodname, Arguments arguments)
Definition: Invoke.java:20
void resolveNamesAndTypes(Expression with, Environment env)
Definition: Invoke.java:46
void compile(ArrayList< Command > ops, boolean autowindow)
Definition: Invoke.java:36
final String createText(String id, Object... args)
Definition: Node.java:34
abstract void resolveNamesAndTypes(Expression with, Environment env)
static SystemFunctionType getSystemFunction(String name, Type[] types)
MethodType getMethod(String name, Type[] parameters)
Definition: Type.java:140
void compile(ArrayList< Command > ops, Expression target, boolean autowindow)
Impressum