]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVar.java
Merge "List the unsatisfied dependencies in CanvasContext"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / EVar.java
1 package org.simantics.scl.compiler.elaboration.expressions;
2
3 import java.util.ArrayList;
4
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
12 public class EVar extends ASTExpression {
13     public final String name;
14
15     public EVar(long location, String name) {
16         this.location = location;
17         this.name = name;
18     }
19     
20     public EVar(String name) {
21         this(Locations.NO_LOCATION, name);
22     }
23    
24     @Override
25     public EVar getPatternHead() {
26         return this;
27     }
28     
29     @Override
30     public LhsType getLhsType() throws NotPatternException {
31         if(TranslationContext.isConstructorName(name))
32             return new PatternMatchingLhs();
33         else
34             return new FunctionDefinitionLhs(name);
35     }
36     
37     @Override
38     protected void collectVariableNames(PatternMatchingLhs lhsType)
39             throws NotPatternException {
40         if(!TranslationContext.isConstructorName(name))
41             lhsType.variableNames.add(name);
42     }
43
44     @Override
45     public Expression resolve(TranslationContext context) {
46         return context.resolveExpression(location, name);
47     }
48     
49     @Override
50     public void getParameters(TranslationContext translationContext,
51             ArrayList<Expression> parameters) {
52     }
53     
54     @Override
55     public Expression resolveAsPattern(TranslationContext context) {
56         return context.resolvePattern(this);
57     }
58     
59     @Override
60     public int getFunctionDefinitionPatternArity() throws NotPatternException {
61         if(TranslationContext.isConstructorName(name))
62             throw new NotPatternException(this);
63         else
64             return 0;
65     }
66     
67     @Override
68     public boolean isConstructorApplication() {
69         return TranslationContext.isConstructorName(name);
70     }
71     
72     @Override
73     public void setLocationDeep(long loc) {
74         if(location == Locations.NO_LOCATION)
75             location = loc;
76     }
77     
78     @Override
79     public Expression accept(ExpressionTransformer transformer) {
80         return transformer.transform(this);
81     }
82 }