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;
38 public String[] parameterNames;
40 public SCLValue(Name name) {
44 public SCLValue(Name name, Constant value) {
49 public Name getName() {
53 public Type getType() {
57 public void setType(Type type) {
61 public void addProperty(SCLValueProperty property) {
62 properties.add(property);
65 public List<SCLValueProperty> getProperties() {
69 public Precedence getPrecedence() {
73 public void setPrecedence(Precedence precedence) {
74 this.precedence = precedence;
77 public IVal getValue() {
81 public void setValue(IVal value) {
84 type = value.getType();
87 public Expression getExpression() {
91 public Expression getSimplifiedExpression(SimplificationContext context) {
92 if(expression != null && (flags & SIMPLIFIED) == 0) {
93 //System.out.println("Simplify: " + name);
94 //System.out.println("BEFORE: " + expression);
95 expression = expression.simplify(context);
96 //System.out.println("AFTER: " + expression);
102 public void setExpression(Expression expression) {
103 this.expression = expression;
106 public MacroRule getMacroRule() {
110 public void setMacroRule(MacroRule macroRule) {
111 this.macroRule = macroRule;
115 public String toString() {
116 return name.toString();
119 private void setFlag(int flagMask, boolean value) {
123 flags &= FLAG_MASK - flagMask;
126 public void setSimplified(boolean value) {
127 setFlag(SIMPLIFIED, value);
130 public void setInlineInSimplification(boolean value) {
131 setFlag(INLINE_IN_SIMPLIFICATION, value);
134 public boolean getInlineInSimplification() {
135 return (flags & INLINE_IN_SIMPLIFICATION) != 0;
138 public Object realizeValue(TransientClassBuilder classLoader) {
139 return getValue().realizeValue(classLoader);
142 public boolean isPrivate() {
143 for(SCLValueProperty property : properties)
144 if(property == PrivateProperty.INSTANCE)
149 public String isDeprecated() {
150 for(SCLValueProperty property : properties)
151 if(property instanceof DeprecatedProperty)
152 return ((DeprecatedProperty)property).description;
156 public void setDocumentation(String documentation) {
157 this.documentation = documentation;
160 public String getDocumentation() {
161 return documentation;
164 public boolean isPrivateOrDerived() {
165 for(SCLValueProperty property : properties)
166 if(property == PrivateProperty.INSTANCE || property == DerivedProperty.INSTANCE)