]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/SCLValue.java
Showing compilation warnings in SCL issue view and editors
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / modules / SCLValue.java
1 package org.simantics.scl.compiler.elaboration.modules;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.simantics.scl.compiler.common.names.Name;
7 import org.simantics.scl.compiler.common.precedence.Precedence;
8 import org.simantics.scl.compiler.constants.Constant;
9 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
10 import org.simantics.scl.compiler.elaboration.expressions.Expression;
11 import org.simantics.scl.compiler.elaboration.macros.MacroRule;
12 import org.simantics.scl.compiler.errors.Locations;
13 import org.simantics.scl.compiler.internal.codegen.references.IVal;
14 import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
15 import org.simantics.scl.compiler.types.Type;
16 import org.simantics.scl.compiler.types.util.Typed;
17
18 /**
19  * Information about SCL values that is needed in parsing 
20  * and elaboration phases.
21  * @author Hannu Niemistö
22  */
23 public final class SCLValue implements Typed {
24     private static final int SIMPLIFIED = 1;
25     private static final int INLINE_IN_SIMPLIFICATION = 2;
26     private static final int FLAG_MASK = 0xffff;
27     
28     private Name name;
29     private Type type;
30     private Precedence precedence = Precedence.DEFAULT;
31     private IVal value;
32     private Expression expression;
33     private MacroRule macroRule;
34     private int flags = 0;
35     private ArrayList<SCLValueProperty> properties = new ArrayList<SCLValueProperty>(2);
36     public String documentation;
37     public long definitionLocation = Locations.NO_LOCATION;
38     
39     public SCLValue(Name name) {
40         this.name = name;
41     }
42     
43     public SCLValue(Name name, Constant value) {
44         this(name);
45         setValue(value);
46     }
47
48     public Name getName() {
49         return name;
50     }
51     
52     public Type getType() {
53         return type;
54     }
55     
56     public void setType(Type type) {
57         this.type = type;
58     }
59     
60     public void addProperty(SCLValueProperty property) {
61         properties.add(property);
62     }
63     
64     public List<SCLValueProperty> getProperties() {
65         return properties;
66     }
67     
68     public Precedence getPrecedence() {
69         return precedence;
70     }
71     
72     public void setPrecedence(Precedence precedence) {
73         this.precedence = precedence;
74     }
75     
76     public IVal getValue() {
77         return value;
78     }
79     
80     public void setValue(IVal value) {
81         this.value = value;
82         if(type == null)
83             type = value.getType();
84     }
85     
86     public Expression getExpression() {
87         return expression;
88     }
89     
90     public Expression getSimplifiedExpression(SimplificationContext context) {
91         if(expression != null && (flags & SIMPLIFIED) == 0) {
92             //System.out.println("Simplify: " + name);
93             //System.out.println("BEFORE: " + expression);
94             expression = expression.simplify(context);
95             //System.out.println("AFTER: " + expression);
96             flags |= SIMPLIFIED;
97         }
98         return expression;
99     }
100     
101     public void setExpression(Expression expression) {
102         this.expression = expression;
103     }
104     
105     public MacroRule getMacroRule() {
106         return macroRule;
107     }
108     
109     public void setMacroRule(MacroRule macroRule) {
110         this.macroRule = macroRule;
111     }
112     
113     @Override
114     public String toString() {
115         return name.toString();
116     }
117     
118     private void setFlag(int flagMask, boolean value) {
119         if(value)
120             flags |= flagMask;
121         else
122             flags &= FLAG_MASK - flagMask; 
123     }
124     
125     public void setSimplified(boolean value) {
126         setFlag(SIMPLIFIED, value);
127     }
128     
129     public void setInlineInSimplification(boolean value) {
130         setFlag(INLINE_IN_SIMPLIFICATION, value);
131     }
132     
133     public boolean getInlineInSimplification() {
134         return (flags & INLINE_IN_SIMPLIFICATION) != 0; 
135     }
136     
137     public Object realizeValue(TransientClassBuilder classLoader) {
138         return getValue().realizeValue(classLoader);
139     }
140
141         public boolean isPrivate() {
142                 for(SCLValueProperty property : properties)
143                         if(property == PrivateProperty.INSTANCE)
144                                 return true;
145                 return false;
146         }
147         
148         public String isDeprecated() {
149             for(SCLValueProperty property : properties)
150             if(property instanceof DeprecatedProperty)
151                 return ((DeprecatedProperty)property).description;
152         return null;
153         }
154
155         public void setDocumentation(String documentation) {
156                 this.documentation = documentation;
157         }
158         
159         public String getDocumentation() {
160                 return documentation;
161         }
162 }