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 Expression resolved = context.resolveVariable(location, name);
53 if(context.isExpandedFromWildcard(this))
54 context.addExpandedFromWildcard(resolved);
59 public void getParameters(TranslationContext translationContext,
60 ArrayList<Expression> parameters) {
64 public Expression resolveAsPattern(TranslationContext context) {
65 Expression resolved = context.resolvePattern(this);
66 if(context.isExpandedFromWildcard(this))
67 context.addExpandedFromWildcard(resolved);
72 public int getFunctionDefinitionPatternArity() throws NotPatternException {
73 if(TranslationContext.isConstructorName(name))
74 throw new NotPatternException(this);
80 public boolean isConstructorApplication() {
81 return TranslationContext.isConstructorName(name);
85 public void setLocationDeep(long loc) {
86 if(location == Locations.NO_LOCATION)
91 public Expression accept(ExpressionTransformer transformer) {
92 return transformer.transform(this);
96 public void accept(ExpressionVisitor visitor) {