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;
12 public class EVar extends ASTExpression {
13 public final String name;
15 public EVar(long location, String name) {
16 this.location = location;
20 public EVar(String name) {
21 this(Locations.NO_LOCATION, name);
25 public EVar getPatternHead() {
30 public LhsType getLhsType() throws NotPatternException {
31 if(TranslationContext.isConstructorName(name))
32 return new PatternMatchingLhs();
34 return new FunctionDefinitionLhs(name);
38 protected void collectVariableNames(PatternMatchingLhs lhsType)
39 throws NotPatternException {
40 if(!TranslationContext.isConstructorName(name))
41 lhsType.variableNames.add(name);
45 public Expression resolve(TranslationContext context) {
46 return context.resolveExpression(location, name);
50 public void getParameters(TranslationContext translationContext,
51 ArrayList<Expression> parameters) {
55 public Expression resolveAsPattern(TranslationContext context) {
56 return context.resolvePattern(this);
60 public int getFunctionDefinitionPatternArity() throws NotPatternException {
61 if(TranslationContext.isConstructorName(name))
62 throw new NotPatternException(this);
68 public boolean isConstructorApplication() {
69 return TranslationContext.isConstructorName(name);
73 public void setLocationDeep(long loc) {
74 if(location == Locations.NO_LOCATION)
79 public Expression accept(ExpressionTransformer transformer) {
80 return transformer.transform(this);