//generated by abstract-syntax-gen package de.peeeq.wurstscript.jassIm; import java.util.*; @SuppressWarnings({"cast", "unused", "rawtypes"}) class ImFunctionImpl implements ImFunction{ ImFunctionImpl(de.peeeq.wurstscript.ast.Element trace, String name, ImTypeVars typeVariables, ImVars parameters, ImType returnType, ImVars locals, ImStmts body, java.util.List flags) { if (trace == null) throw new IllegalArgumentException("Element trace must not be null."); if (name == null) throw new IllegalArgumentException("Element name must not be null."); if (typeVariables == null) throw new IllegalArgumentException("Element typeVariables must not be null."); if (parameters == null) throw new IllegalArgumentException("Element parameters must not be null."); if (returnType == null) throw new IllegalArgumentException("Element returnType must not be null."); if (locals == null) throw new IllegalArgumentException("Element locals must not be null."); if (body == null) throw new IllegalArgumentException("Element body must not be null."); if (flags == null) throw new IllegalArgumentException("Element flags must not be null."); this.trace = trace; this.name = name; this.typeVariables = typeVariables; this.parameters = parameters; this.returnType = returnType; this.locals = locals; this.body = body; this.flags = flags; typeVariables.setParent(this); parameters.setParent(this); locals.setParent(this); body.setParent(this); } private Element parent; public Element getParent() { return parent; } public void setParent(Element parent) { if (parent != null && this.parent != null) { throw new Error("Cannot change parent of element " + this.getClass().getSimpleName() + ", as it is already used in another tree." + "Use the copy method to create a new tree or remove the tree from its old parent or set the parent to null before moving the tree. "); } this.parent = parent; } public void replaceBy(Element other) { if (parent == null) throw new RuntimeException("Node not attached to tree."); for (int i=0; i flags; public void setFlags(java.util.List flags) { if (flags == null) throw new IllegalArgumentException(); this.flags = flags; } public java.util.List getFlags() { return flags; } public Element get(int i) { switch (i) { case 0: return typeVariables; case 1: return parameters; case 2: return locals; case 3: return body; default: throw new IllegalArgumentException("Index out of range: " + i); } } public Element set(int i, Element newElem) { Element oldElem; switch (i) { case 0: oldElem = typeVariables; setTypeVariables((ImTypeVars) newElem); return oldElem; case 1: oldElem = parameters; setParameters((ImVars) newElem); return oldElem; case 2: oldElem = locals; setLocals((ImVars) newElem); return oldElem; case 3: oldElem = body; setBody((ImStmts) newElem); return oldElem; default: throw new IllegalArgumentException("Index out of range: " + i); } } @Override public void forEachElement(java.util.function.Consumer action) { action.accept(this.typeVariables); action.accept(this.parameters); action.accept(this.locals); action.accept(this.body); } public int size() { return 4; } @Override public ImFunction copy() { ImFunction result = new ImFunctionImpl(trace, name, (ImTypeVars) this.typeVariables.copy(), (ImVars) this.parameters.copy(), returnType, (ImVars) this.locals.copy(), (ImStmts) this.body.copy(), flags); return result; } @Override public ImFunction copyWithRefs() { ImFunction res = copy(); Element self = this; res.accept(new Element.DefaultVisitor() { @Override public void visit(ImVarArrayAccess e) { super.visit(e); // check reference var { Element elem = e.getVar(); while (elem != self && elem != null) { elem = elem.getParent(); } if (elem == self) { e.setVar((ImVar) res.followPath(self.pathTo(e.getVar()))); } } } @Override public void visit(ImVarargLoop e) { super.visit(e); // check reference loopVar { Element elem = e.getLoopVar(); while (elem != self && elem != null) { elem = elem.getParent(); } if (elem == self) { e.setLoopVar((ImVar) res.followPath(self.pathTo(e.getLoopVar()))); } } } @Override public void visit(ImMemberAccess e) { super.visit(e); // check reference var { Element elem = e.getVar(); while (elem != self && elem != null) { elem = elem.getParent(); } if (elem == self) { e.setVar((ImVar) res.followPath(self.pathTo(e.getVar()))); } } } @Override public void visit(ImFuncRef e) { super.visit(e); // check reference func { Element elem = e.getFunc(); while (elem != self && elem != null) { elem = elem.getParent(); } if (elem == self) { e.setFunc((ImFunction) res.followPath(self.pathTo(e.getFunc()))); } } } @Override public void visit(ImFunctionCall e) { super.visit(e); // check reference func { Element elem = e.getFunc(); while (elem != self && elem != null) { elem = elem.getParent(); } if (elem == self) { e.setFunc((ImFunction) res.followPath(self.pathTo(e.getFunc()))); } } } @Override public void visit(ImVarAccess e) { super.visit(e); // check reference var { Element elem = e.getVar(); while (elem != self && elem != null) { elem = elem.getParent(); } if (elem == self) { e.setVar((ImVar) res.followPath(self.pathTo(e.getVar()))); } } } @Override public void visit(ImTypeVarDispatch e) { super.visit(e); // check reference typeVariable { Element elem = e.getTypeVariable(); while (elem != self && elem != null) { elem = elem.getParent(); } if (elem == self) { e.setTypeVariable((ImTypeVar) res.followPath(self.pathTo(e.getTypeVariable()))); } } } }); return res; } @Override public void clearAttributes() { typeVariables.clearAttributes(); parameters.clearAttributes(); locals.clearAttributes(); body.clearAttributes(); clearAttributesLocal(); } @Override public void clearAttributesLocal() { } @Override public void accept(Visitor v) { v.visit(this); } @Override public T match(JassImElementWithName.Matcher matcher) { return matcher.case_ImFunction(this); } @Override public void match(JassImElementWithName.MatcherVoid matcher) { matcher.case_ImFunction(this); } @Override public T match(ElementWithTrace.Matcher matcher) { return matcher.case_ImFunction(this); } @Override public void match(ElementWithTrace.MatcherVoid matcher) { matcher.case_ImFunction(this); } @Override public T match(ImPrintable.Matcher matcher) { return matcher.case_ImFunction(this); } @Override public void match(ImPrintable.MatcherVoid matcher) { matcher.case_ImFunction(this); } @Override public T match(Element.Matcher matcher) { return matcher.case_ImFunction(this); } @Override public void match(Element.MatcherVoid matcher) { matcher.case_ImFunction(this); } public boolean structuralEquals(Element e) { if (e instanceof ImFunction) { ImFunction o = (ImFunction) e; return java.util.Objects.equals(name, o.getName()) && this.typeVariables.structuralEquals(o.getTypeVariables()) && this.parameters.structuralEquals(o.getParameters()) && this.returnType == o.getReturnType() && this.locals.structuralEquals(o.getLocals()) && this.body.structuralEquals(o.getBody()) && java.util.Objects.equals(flags, o.getFlags()); } else { return false; } } /** */ public void print(java.lang.Appendable sb, int indent) { de.peeeq.wurstscript.translation.imtranslation.ImPrinter.print((ImFunction)this, sb, indent); } /** */ public String toString() { return de.peeeq.wurstscript.translation.imtranslation.ImPrinter.asString((ImFunction)this); } /** */ public void flatten(de.peeeq.wurstscript.translation.imtranslation.ImTranslator translator) { de.peeeq.wurstscript.translation.imtranslation.Flatten.flattenFunc((ImFunction)this, translator); } /** */ public ImFunction getNearestFunc() { return de.peeeq.wurstscript.translation.imtojass.ImAttributes.getNearestFunc((ImFunction)this); } /** */ public boolean isNative() { return de.peeeq.wurstscript.translation.imtojass.ImAttributes.isNative((ImFunction)this); } /** */ public boolean isBj() { return de.peeeq.wurstscript.translation.imtojass.ImAttributes.isBj((ImFunction)this); } /** */ public boolean isExtern() { return de.peeeq.wurstscript.translation.imtojass.ImAttributes.isExtern((ImFunction)this); } /** */ public boolean isCompiletime() { return de.peeeq.wurstscript.translation.imtojass.ImAttributes.isCompiletime((ImFunction)this); } /** */ public boolean hasFlag(de.peeeq.wurstscript.translation.imtranslation.FunctionFlag flag) { return de.peeeq.wurstscript.translation.imtojass.ImAttributes.hasFlag((ImFunction)this, flag); } /** */ public de.peeeq.wurstscript.ast.Element attrTrace() { return de.peeeq.wurstscript.translation.imtojass.ImAttributes.getTrace((ImFunction)this); } /** */ public ImProg attrProg() { return de.peeeq.wurstscript.translation.imtojass.ImAttributes.getProg((ImFunction)this); } /** */ public java.util.Set calcUsedVariables() { return de.peeeq.wurstscript.translation.imtranslation.UsedVariables.calculate((ImFunction)this); } /** */ public java.util.Set calcReadVariables() { return de.peeeq.wurstscript.translation.imtranslation.UsedVariables.calculateReadVars((ImFunction)this); } /** */ public java.util.Set calcUsedFunctions() { return de.peeeq.wurstscript.translation.imtranslation.UsedFunctions.calculate((ImFunction)this); } }