1 package org.simantics.scl.compiler.elaboration.expressions;
3 import java.util.ArrayList;
5 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
6 import org.simantics.scl.compiler.elaboration.errors.NotPatternException;
7 import org.simantics.scl.compiler.elaboration.expressions.lhstype.FunctionDefinitionLhs;
8 import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType;
9 import org.simantics.scl.compiler.elaboration.expressions.lhstype.PatternMatchingLhs;
10 import org.simantics.scl.compiler.errors.Locations;
11 import org.simantics.scl.compiler.internal.parsing.Token;
13 public class EVar extends ASTExpression {
14 public final String name;
16 public EVar(Token token) {
17 this.location = token.location;
18 this.name = token.text;
21 public EVar(long location, String name) {
22 this.location = location;
26 public EVar(String name) {
27 this(Locations.NO_LOCATION, name);
31 public EVar getPatternHead() {
36 public LhsType getLhsType() throws NotPatternException {
37 if(TranslationContext.isConstructorName(name))
38 return new PatternMatchingLhs();
40 return new FunctionDefinitionLhs(name);
44 protected void collectVariableNames(PatternMatchingLhs lhsType)
45 throws NotPatternException {
46 if(!TranslationContext.isConstructorName(name))
47 lhsType.variableNames.add(name);
51 public Expression resolve(TranslationContext context) {
52 return context.resolveVariable(location, name);
56 public void getParameters(TranslationContext translationContext,
57 ArrayList<Expression> parameters) {
61 public Expression resolveAsPattern(TranslationContext context) {
62 return context.resolvePattern(this);
66 public int getFunctionDefinitionPatternArity() throws NotPatternException {
67 if(TranslationContext.isConstructorName(name))
68 throw new NotPatternException(this);
74 public boolean isConstructorApplication() {
75 return TranslationContext.isConstructorName(name);
79 public void setLocationDeep(long loc) {
80 if(location == Locations.NO_LOCATION)
85 public Expression accept(ExpressionTransformer transformer) {
86 return transformer.transform(this);
90 public void accept(ExpressionVisitor visitor) {