X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FELiteral.java;h=bef28f20ff298a75b65f594cf4bbea08446017d7;hp=0d00a65d2cf3fffdd921efa963f7a8ee1d8ca812;hb=666ee533a3cfa9f59e79215a269f8342227cdbda;hpb=593a8f75d9dbc363234002dc500c346afbeba040 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java old mode 100755 new mode 100644 index 0d00a65d2..bef28f20f --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java @@ -1,151 +1,122 @@ -package org.simantics.scl.compiler.elaboration.expressions; - -import java.util.ArrayList; - -import org.simantics.scl.compiler.constants.Constant; -import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; -import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; -import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; -import org.simantics.scl.compiler.elaboration.contexts.TypingContext; -import org.simantics.scl.compiler.environment.Environment; -import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.codegen.references.IVal; -import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; -import org.simantics.scl.compiler.internal.interpreted.IConstant; -import org.simantics.scl.compiler.internal.interpreted.IExpression; -import org.simantics.scl.compiler.top.ExpressionInterpretationContext; -import org.simantics.scl.compiler.types.Type; -import org.simantics.scl.compiler.types.exceptions.MatchException; -import org.simantics.scl.compiler.types.util.TypeUnparsingContext; - -import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; -import gnu.trove.set.hash.TIntHashSet; - -public class ELiteral extends Expression { - Constant value; - - public ELiteral(Constant value) { - this.value = value; - setType(value.getType()); - } - - public ELiteral(long loc, Constant value) { - super(loc); - this.value = value; - } - - public Constant getValue() { - return value; - } - - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - } - - public void toString(StringBuilder b, TypeUnparsingContext tuc) { - b.append(value); - } - - @Override - protected void updateType() throws MatchException { - setType(value.getType()); - } - - @Override - public IVal toVal(Environment env, CodeWriter w) { - return value; - } - - @Override - public void collectFreeVariables(THashSet vars) { - } - - - @Override - public Expression simplify(SimplificationContext context) { - return this; - } - - @Override - public Expression resolve(TranslationContext context) { - return this; - } - - @Override - public Expression resolveAsPattern(TranslationContext context) { - return this; - } - - @Override - public void getParameters(TranslationContext translationContext, - ArrayList parameters) { - } - - @Override - public Expression replace(ReplaceContext context) { - return new ELiteral(value); - } - - @Override - public void removeFreeVariables(THashSet vars) { - } - - @Override - public IExpression toIExpression(ExpressionInterpretationContext target) { - return new IConstant(value.realizeValue(target.localClassBuilder)); - } - - @Override - public Expression inferType(TypingContext context) { - return this; - } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } - - @Override - public void collectEffects(THashSet effects) { - } - - @Override - public void setLocationDeep(long loc) { - if(location == Locations.NO_LOCATION) - location = loc; - } - - @Override - public void accept(ExpressionVisitor visitor) { - visitor.visit(this); - } - - @Override - public void forVariables(VariableProcedure procedure) { - } - - @Override - public boolean isPattern(int arity) { - return value.constructorTag() >= 0 && value.getArity() == arity; - } - - @Override - public Expression accept(ExpressionTransformer transformer) { - return transformer.transform(this); - } - - @Override - public boolean equalsExpression(Expression expression) { - if(expression.getClass() != getClass()) - return false; - ELiteral other = (ELiteral)expression; - return value.equals(other.value); - } - -} +package org.simantics.scl.compiler.elaboration.expressions; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Set; + +import org.simantics.scl.compiler.compilation.CompilationContext; +import org.simantics.scl.compiler.constants.Constant; +import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; +import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; +import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; +import org.simantics.scl.compiler.elaboration.contexts.TypingContext; +import org.simantics.scl.compiler.errors.Locations; +import org.simantics.scl.compiler.internal.codegen.references.IVal; +import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; +import org.simantics.scl.compiler.internal.interpreted.IConstant; +import org.simantics.scl.compiler.internal.interpreted.IExpression; +import org.simantics.scl.compiler.top.ExpressionInterpretationContext; +import org.simantics.scl.compiler.types.exceptions.MatchException; +import org.simantics.scl.compiler.types.util.TypeUnparsingContext; + +public class ELiteral extends Expression { + Constant value; + + public ELiteral(Constant value) { + this.value = value; + setType(value.getType()); + } + + public ELiteral(long loc, Constant value) { + super(loc); + this.value = value; + } + + public Constant getValue() { + return value; + } + + @Override + public Set getFreeVariables() { + return Collections.emptySet(); + } + + public void toString(StringBuilder b, TypeUnparsingContext tuc) { + b.append(value); + } + + @Override + protected void updateType() throws MatchException { + setType(value.getType()); + } + + @Override + public IVal toVal(CompilationContext context, CodeWriter w) { + return value; + } + + @Override + public Expression simplify(SimplificationContext context) { + return this; + } + + @Override + public Expression resolve(TranslationContext context) { + return this; + } + + @Override + public Expression resolveAsPattern(TranslationContext context) { + return this; + } + + @Override + public void getParameters(TranslationContext translationContext, + ArrayList parameters) { + } + + @Override + public Expression replace(ReplaceContext context) { + return new ELiteral(value); + } + + @Override + public IExpression toIExpression(ExpressionInterpretationContext target) { + return new IConstant(value.realizeValue(target.localClassBuilder)); + } + + @Override + public Expression inferType(TypingContext context) { + return this; + } + + @Override + public void setLocationDeep(long loc) { + if(location == Locations.NO_LOCATION) + location = loc; + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public boolean isPattern(int arity) { + return value.constructorTag() >= 0 && value.getArity() == arity; + } + + @Override + public Expression accept(ExpressionTransformer transformer) { + return transformer.transform(this); + } + + @Override + public boolean equalsExpression(Expression expression) { + if(expression.getClass() != getClass()) + return false; + ELiteral other = (ELiteral)expression; + return value.equals(other.value); + } + +}