
lt.compiler.syntactic.def.FunDef Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of latte-compiler Show documentation
Show all versions of latte-compiler Show documentation
The latte-lang compiler project, which contains compiler and runtime required library.
The newest version!
package lt.compiler.syntactic.def;
import lt.compiler.CompileUtil;
import lt.compiler.LineCol;
import lt.compiler.syntactic.AST;
import lt.compiler.syntactic.Definition;
import lt.compiler.syntactic.Statement;
import lt.lang.function.Function2;
import java.util.List;
import java.util.Set;
/**
* function definitions.
*/
public class FunDef implements Definition {
public final String name;
public final List params;
public final AST.Access superType;
public final Set annos;
public final List statements;
private final LineCol lineCol;
public FunDef(String name, List params, AST.Access superType, Set annos, List statements, LineCol lineCol) {
this.name = name;
this.params = params;
this.superType = superType;
this.annos = annos;
this.statements = statements;
this.lineCol = lineCol;
}
@Override
public LineCol line_col() {
return lineCol;
}
@Override
public void foreachInnerStatements(Function2 f, T t) throws Exception {
CompileUtil.visitStmt(params, f, t);
CompileUtil.visitStmt(superType, f, t);
CompileUtil.visitStmt(annos, f, t);
CompileUtil.visitStmt(statements, f, t);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FunDef funDef = (FunDef) o;
if (name != null ? !name.equals(funDef.name) : funDef.name != null) return false;
if (params != null ? !params.equals(funDef.params) : funDef.params != null) return false;
if (superType != null ? !superType.equals(funDef.superType) : funDef.superType != null) return false;
if (annos != null ? !annos.equals(funDef.annos) : funDef.annos != null) return false;
//
return statements != null ? statements.equals(funDef.statements) : funDef.statements == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (params != null ? params.hashCode() : 0);
result = 31 * result + (superType != null ? superType.hashCode() : 0);
result = 31 * result + (annos != null ? annos.hashCode() : 0);
result = 31 * result + (statements != null ? statements.hashCode() : 0);
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("(");
for (AST.Anno anno : annos) {
sb.append(anno).append(" ");
}
sb.append("fun ").append(name);
sb.append("(");
boolean isFirst = true;
for (VariableDef v : params) {
if (isFirst) {
isFirst = false;
} else {
sb.append(",");
}
sb.append(v);
}
sb.append(") : ").append(superType).append(" ").append(statements).append(")");
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy