]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7260) Added a new DerivedProperty to SCLValues 82/582/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 31 May 2017 12:47:17 +0000 (15:47 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 31 May 2017 12:47:17 +0000 (15:47 +0300)
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

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/DerivedProperty.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/MethodImplementation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/translation/ValueRepository.java

index 9c7c77470c55b57a91c7dc768d49ff3408e2c9ff..cc883c0eafc9ceefd03212975777a54377419beb 100644 (file)
@@ -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
index 1cba44207ee7c124de787ceff3b7631421084c1b..7887ed717f032b7d29aed50782a69e0f6b42c916 100644 (file)
@@ -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.<Expression>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 (file)
index 0000000..b487290
--- /dev/null
@@ -0,0 +1,5 @@
+package org.simantics.scl.compiler.elaboration.modules;
+
+public enum DerivedProperty implements SCLValueProperty {
+    INSTANCE;
+}
index a381915014364e6ea63ec62f04790cfc819146ca..b9b0269e967b9daa9bb52f027568b07c9bb13366 100644 (file)
@@ -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;
-    }
-    
 }
index d0e81402d17fa6e07636f0bd685fef830ba64017..a0d5702222c5a157eb10a49169872f8f18ff7b08 100644 (file)
@@ -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<String, ArrayList<DValueAst>> values = 
             new THashMap<String, ArrayList<DValueAst>>();
     THashMap<String, ArrayList<DAnnotationAst>> annotations = 
             new THashMap<String, ArrayList<DAnnotationAst>>();
+    THashSet<String> derived = new THashSet<String>(); 
     TObjectLongHashMap<String> locations = new TObjectLongHashMap<String>(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);
+    }
 }