1 package org.simantics.scl.compiler.elaboration.expressions;
3 import java.util.ArrayList;
5 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
6 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
7 import org.simantics.scl.compiler.elaboration.errors.NotPatternException;
8 import org.simantics.scl.compiler.elaboration.expressions.lhstype.FunctionDefinitionLhs;
9 import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType;
10 import org.simantics.scl.compiler.elaboration.expressions.lhstype.PatternMatchingLhs;
11 import org.simantics.scl.compiler.errors.Locations;
13 public class EVar extends ASTExpression {
14 public final String name;
16 public EVar(long location, String name) {
17 this.location = location;
21 public EVar(String name) {
22 this(Locations.NO_LOCATION, name);
26 public EVar getPatternHead() {
31 public LhsType getLhsType() throws NotPatternException {
32 if(TranslationContext.isConstructorName(name))
33 return new PatternMatchingLhs();
35 return new FunctionDefinitionLhs(name);
39 protected void collectVariableNames(PatternMatchingLhs lhsType)
40 throws NotPatternException {
41 if(!TranslationContext.isConstructorName(name))
42 lhsType.variableNames.add(name);
46 public Expression resolve(TranslationContext context) {
47 return context.resolveVariable(location, name);
51 public void getParameters(TranslationContext translationContext,
52 ArrayList<Expression> parameters) {
56 public Expression resolveAsPattern(TranslationContext context) {
57 return context.resolvePattern(this);
61 public int getFunctionDefinitionPatternArity() throws NotPatternException {
62 if(TranslationContext.isConstructorName(name))
63 throw new NotPatternException(this);
69 public boolean isConstructorApplication() {
70 return TranslationContext.isConstructorName(name);
74 public void setLocationDeep(long loc) {
75 if(location == Locations.NO_LOCATION)
80 public Expression accept(ExpressionTransformer transformer) {
81 return transformer.transform(this);
85 public void accept(ExpressionVisitor visitor) {