1 package org.simantics.scl.compiler.elaboration.modules;
3 import java.util.ArrayList;
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;
19 * Information about SCL values that is needed in parsing
20 * and elaboration phases.
21 * @author Hannu Niemistö
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;
30 private Precedence precedence = Precedence.DEFAULT;
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;
39 public SCLValue(Name name) {
43 public SCLValue(Name name, Constant value) {
48 public Name getName() {
52 public Type getType() {
56 public void setType(Type type) {
60 public void addProperty(SCLValueProperty property) {
61 properties.add(property);
64 public List<SCLValueProperty> getProperties() {
68 public Precedence getPrecedence() {
72 public void setPrecedence(Precedence precedence) {
73 this.precedence = precedence;
76 public IVal getValue() {
80 public void setValue(IVal value) {
83 type = value.getType();
86 public Expression getExpression() {
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);
101 public void setExpression(Expression expression) {
102 this.expression = expression;
105 public MacroRule getMacroRule() {
109 public void setMacroRule(MacroRule macroRule) {
110 this.macroRule = macroRule;
114 public String toString() {
115 return name.toString();
118 private void setFlag(int flagMask, boolean value) {
122 flags &= FLAG_MASK - flagMask;
125 public void setSimplified(boolean value) {
126 setFlag(SIMPLIFIED, value);
129 public void setInlineInSimplification(boolean value) {
130 setFlag(INLINE_IN_SIMPLIFICATION, value);
133 public boolean getInlineInSimplification() {
134 return (flags & INLINE_IN_SIMPLIFICATION) != 0;
137 public Object realizeValue(TransientClassBuilder classLoader) {
138 return getValue().realizeValue(classLoader);
141 public boolean isPrivate() {
142 for(SCLValueProperty property : properties)
143 if(property == PrivateProperty.INSTANCE)
148 public String isDeprecated() {
149 for(SCLValueProperty property : properties)
150 if(property instanceof DeprecatedProperty)
151 return ((DeprecatedProperty)property).description;
155 public void setDocumentation(String documentation) {
156 this.documentation = documentation;
159 public String getDocumentation() {
160 return documentation;
163 public boolean isPrivateOrDerived() {
164 for(SCLValueProperty property : properties)
165 if(property == PrivateProperty.INSTANCE || property == DerivedProperty.INSTANCE)