From: Hannu Niemistö Date: Wed, 31 May 2017 12:47:17 +0000 (+0300) Subject: (refs #7260) Added a new DerivedProperty to SCLValues X-Git-Tag: v1.29.0~5^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ae92649da4fec272f59516a858011413f4453758;p=simantics%2Fplatform.git (refs #7260) Added a new DerivedProperty to SCLValues DerivedProperty prevents certain optimizations applied for private values. This is needed because mechanisms deriving values are assuming that certain Java methods will be generated. Change-Id: I1ca9d839b6a4a4c9faa63e5faaa832e49f2d76d8 --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java index 9c7c77470..cc883c0ea 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java @@ -17,6 +17,7 @@ import org.simantics.scl.compiler.constants.ThisConstant; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.macros.StandardMacroRule; +import org.simantics.scl.compiler.elaboration.modules.DerivedProperty; import org.simantics.scl.compiler.elaboration.modules.InlineProperty; import org.simantics.scl.compiler.elaboration.modules.MethodImplementation; import org.simantics.scl.compiler.elaboration.modules.PrivateProperty; @@ -124,13 +125,18 @@ public class CodeGeneration { decomposed.typeParameters, decomposed.returnType, decomposed.parameterTypes));*/ + boolean isDerived = false; for(SCLValueProperty prop : value.getProperties()) { if(prop instanceof InlineProperty) { InlineProperty inlineProperty = (InlineProperty)prop; constant.setInlineArity(inlineProperty.arity, inlineProperty.phaseMask); } else if(prop == PrivateProperty.INSTANCE) - constant.setPrivate(true); + constant.setPrivate(!isDerived); + else if(prop == DerivedProperty.INSTANCE) { + constant.setPrivate(false); + isDerived = true; + } } } // This is quite hackish optimization that can be possibly removed when diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java index 1cba44207..7887ed717 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java @@ -39,6 +39,7 @@ import org.simantics.scl.compiler.elaboration.fundeps.Fundep; import org.simantics.scl.compiler.elaboration.java.JavaMethodDeclaration; import org.simantics.scl.compiler.elaboration.macros.StandardMacroRule; import org.simantics.scl.compiler.elaboration.modules.DeprecatedProperty; +import org.simantics.scl.compiler.elaboration.modules.DerivedProperty; import org.simantics.scl.compiler.elaboration.modules.InlineProperty; import org.simantics.scl.compiler.elaboration.modules.MethodImplementation; import org.simantics.scl.compiler.elaboration.modules.PrivateProperty; @@ -587,6 +588,7 @@ public class Elaboration { String fullName = instancePrefix + valueName; long loc = valueDefs.getDefinition(valueName).get(0).location; valueDefinitionsAst.addFrom(valueDefs, valueName, fullName); + valueDefinitionsAst.setDerived(fullName); /*valueDefinitionsAst.addAnnotation(fullName, new DAnnotationAst(new EVar("@private"), Collections.emptyList()));*/ TypeClassMethod method = typeClass.methods.get(valueName); @@ -1144,6 +1146,8 @@ public class Elaboration { value.definitionLocation = location; if(module.addValue(value)) errorLog.log(location, "Value " + name + " is already defined."); + if(valueDefinitionsAst.isDerived(name)) + value.addProperty(DerivedProperty.INSTANCE); } for(DValueTypeAst valueTypeAst : typeAnnotationsAst) for(EVar name : valueTypeAst.names) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/DerivedProperty.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/DerivedProperty.java new file mode 100644 index 000000000..b4872904d --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/DerivedProperty.java @@ -0,0 +1,5 @@ +package org.simantics.scl.compiler.elaboration.modules; + +public enum DerivedProperty implements SCLValueProperty { + INSTANCE; +} diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/MethodImplementation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/MethodImplementation.java index a38191501..b9b0269e9 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/MethodImplementation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/MethodImplementation.java @@ -6,19 +6,9 @@ public class MethodImplementation { public final Name name; public final boolean isDefault; - private SCLValue value; public MethodImplementation(Name name, boolean isDefault) { this.name = name; this.isDefault = isDefault; } - - public SCLValue getValue() { - return value; - } - - public void setValue(SCLValue value) { - this.value = value; - } - } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/translation/ValueRepository.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/translation/ValueRepository.java index d0e81402d..a0d570222 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/translation/ValueRepository.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/translation/ValueRepository.java @@ -12,12 +12,14 @@ import org.simantics.scl.compiler.internal.parsing.declarations.DValueAst; import gnu.trove.impl.Constants; import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.TObjectLongHashMap; +import gnu.trove.set.hash.THashSet; public class ValueRepository { THashMap> values = new THashMap>(); THashMap> annotations = new THashMap>(); + THashSet derived = new THashSet(); TObjectLongHashMap locations = new TObjectLongHashMap(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, Locations.NO_LOCATION); @@ -85,4 +87,12 @@ public class ValueRepository { public long getLocation(String name) { return locations.get(name); } + + public boolean isDerived(String name) { + return derived.contains(name); + } + + public void setDerived(String name) { + derived.add(name); + } }