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%2FEExternalConstant.java;h=213c30bf198b323da9806fa973827f36d68a7be7;hp=56ea79a2a458bbe0d01e1065fd428dde31480ad2;hb=a8d72a172fdc815c8a9f0f584f010f7e35286f92;hpb=eecd74faded034bd067094b42bbac0d286d8d9fa diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java old mode 100755 new mode 100644 index 56ea79a2a..213c30bf1 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java @@ -1,135 +1,118 @@ -package org.simantics.scl.compiler.elaboration.expressions; - -import java.util.ArrayList; - -import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; -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.codegen.writer.ModuleWriter; -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 EExternalConstant extends Expression { - Object value; - - public EExternalConstant(Object value, Type type) { - this.value = value; - setType(type); - } - - public Object 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 { - throw new InternalCompilerError("EExternalConstants must have explicitly defined type."); - } - - @Override - public IVal toVal(Environment env, CodeWriter w) { - ModuleWriter mw = w.getModuleWriter(); - return mw.getExternalConstant(value, getType()); - } - - @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 EExternalConstant(value, getType().replace(context.tvarMap)); - } - - @Override - public void removeFreeVariables(THashSet vars) { - } - - @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 IExpression toIExpression(ExpressionInterpretationContext context) { - return new IConstant(value); - } - - @Override - public void forVariables(VariableProcedure procedure) { - } - - @Override - public Expression accept(ExpressionTransformer transformer) { - return transformer.transform(this); - } - -} +package org.simantics.scl.compiler.elaboration.expressions; + +import java.util.ArrayList; + +import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.compilation.CompilationContext; +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.codegen.writer.ModuleWriter; +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 EExternalConstant extends Expression { + Object value; + + public EExternalConstant(Object value, Type type) { + this.value = value; + setType(type); + } + + public Object getValue() { + return value; + } + + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { + } + + public void toString(StringBuilder b, TypeUnparsingContext tuc) { + b.append(value); + } + + @Override + protected void updateType() throws MatchException { + throw new InternalCompilerError("EExternalConstants must have explicitly defined type."); + } + + @Override + public IVal toVal(CompilationContext context, CodeWriter w) { + ModuleWriter mw = w.getModuleWriter(); + return mw.getExternalConstant(value, getType()); + } + + @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 EExternalConstant(value, getType().replace(context.tvarMap)); + } + + @Override + public void removeFreeVariables(THashSet vars) { + } + + @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 IExpression toIExpression(ExpressionInterpretationContext context) { + return new IConstant(value); + } + + @Override + public Expression accept(ExpressionTransformer transformer) { + return transformer.transform(this); + } + +}