Merge changes Ib64cf026,I238948da
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 12 May 2017 12:22:15 +0000 (15:22 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Fri, 12 May 2017 12:22:15 +0000 (15:22 +0300)
* changes:
  Enhancements to modelled STS-tests
  Minor SCL enhancements and fixes for logging and test executing

18 files changed:
bundles/org.simantics.graph.db/META-INF/MANIFEST.MF
bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldMissingDependencyException.java [deleted file]
bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphImportProcess1.java [deleted file]
bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphs.java [deleted file]
bundles/org.simantics.graph/META-INF/MANIFEST.MF
bundles/org.simantics.graph/src/org/simantics/graph/query/TransferableGraphConversion.java
bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java
bundles/org.simantics.graph/src/org/simantics/graph/refactoring/PrintReferencesTool.java [deleted file]
bundles/org.simantics.graph/src/org/simantics/graph/refactoring/RefactoringTool.java [deleted file]
bundles/org.simantics.graph/src/org/simantics/graph/representation/old/OldTransferableGraph1.java [deleted file]
bundles/org.simantics.graph/src/org/simantics/graph/representation/old/OldValue1.java [deleted file]
bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/TestRefactoring.java [deleted file]
bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/TestRefactoring2.java [deleted file]
bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/mappingSpec.txt [deleted file]
bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/xor5.aprosSymbol [deleted file]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Switch.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Matching6.scl [new file with mode: 0644]

index f21b3e776dd1dd7cd981113b6da07374c1b9c9f4..165a104edcb543c35a24b29ad32ed016675a46bc 100644 (file)
@@ -9,6 +9,5 @@ Require-Bundle: org.simantics.graph;bundle-version="1.0.0";visibility:=reexport,
  gnu.trove3;bundle-version="3.0.3",
  org.simantics.layer0;bundle-version="1.0.0",
  org.slf4j.api;bundle-version="1.7.2"
-Export-Package: org.simantics.graph.db,
- org.simantics.graph.db.old
+Export-Package: org.simantics.graph.db
 Bundle-Vendor: VTT Technical Research Centre of Finland
diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldMissingDependencyException.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldMissingDependencyException.java
deleted file mode 100644 (file)
index 7ca83f3..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.simantics.graph.db.old;
-
-import java.util.Set;
-
-import org.simantics.db.exception.DatabaseException;
-
-public class OldMissingDependencyException extends DatabaseException {
-
-       private static final long serialVersionUID = -1579450497603555931L;
-       
-       private final OldTransferableGraphImportProcess1 process;
-       
-       public OldMissingDependencyException(OldTransferableGraphImportProcess1 process) {
-               super(createMessage(process));
-               this.process = process;
-       }
-
-       private static String createMessage(OldTransferableGraphImportProcess1 process) {
-               StringBuilder b = new StringBuilder();
-               b.append("The following references were not found:\r\n");
-               for(String missing : process.missingExternals) {
-                       b.append(" -" + missing + "\r\n");
-               }
-               return b.toString();
-       }
-       
-       public Set<String> getMissingURIs() {
-               return process.missingExternals;
-       }
-
-}
diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphImportProcess1.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphImportProcess1.java
deleted file mode 100644 (file)
index 6a69e8d..0000000
+++ /dev/null
@@ -1,479 +0,0 @@
-package org.simantics.graph.db.old;
-
-import java.io.DataOutput;
-import java.io.DataOutputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.simantics.databoard.Bindings;
-import org.simantics.databoard.adapter.AdaptException;
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.db.ReadGraph;
-import org.simantics.db.Resource;
-import org.simantics.db.VirtualGraph;
-import org.simantics.db.WriteOnlyGraph;
-import org.simantics.db.common.WriteBindings;
-import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
-import org.simantics.db.common.uri.UnescapedChildMapOfResource;
-import org.simantics.db.common.utils.Logger;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.exception.ResourceNotFoundException;
-import org.simantics.db.service.ClusterBuilder;
-import org.simantics.db.service.ClusterBuilder.ResourceHandle;
-import org.simantics.db.service.SerialisationSupport;
-import org.simantics.db.service.TransferableGraphSupport;
-import org.simantics.graph.db.CoreInitialization;
-import org.simantics.graph.db.IImportAdvisor;
-import org.simantics.graph.representation.Extensions;
-import org.simantics.graph.representation.External;
-import org.simantics.graph.representation.Identity;
-import org.simantics.graph.representation.IdentityDefinition;
-import org.simantics.graph.representation.Internal;
-import org.simantics.graph.representation.Optional;
-import org.simantics.graph.representation.Root;
-import org.simantics.graph.representation.TransferableGraphUtils;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
-import org.simantics.graph.representation.old.OldValue1;
-
-public class OldTransferableGraphImportProcess1 {
-       
-    public static String LOG_FILE = "transferableGraphs.log";
-    final static private boolean LOG = false;
-    
-    static DataOutput log;
-
-    static {
-
-        if (LOG) {
-            try {
-                FileOutputStream stream = new FileOutputStream(LOG_FILE);
-                log = new DataOutputStream(stream);
-            } catch (FileNotFoundException e) {
-                e.printStackTrace();
-            }
-        }
-
-    }
-    
-    private static void log(String line) {
-        if (LOG) {
-            try {
-                log.writeUTF(line + "\n");
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-    }
-    
-    OldTransferableGraph1 tg;
-    IImportAdvisor advisor;
-    
-    Resource[] resources;
-    ResourceHandle[] handles;
-    
-    Set<String> missingExternals = new HashSet<String>(); 
-    
-    // Builtins
-    Resource RootLibrary;
-    Resource String;
-    Resource Library;
-    
-    Resource InstanceOf;
-    Resource ConsistsOf;
-    Resource PartOf;
-    Resource HasName;
-    Resource NameOf;    
-                
-    public OldTransferableGraphImportProcess1(OldTransferableGraph1 tg, IImportAdvisor advisor) {
-        this.tg = tg;
-        this.advisor = advisor;
-        /*System.out.println("Transferable graph identities:");
-        for(Identity id : tg.identities) {
-            if(id.definition instanceof Internal) {
-                Internal def = (Internal)id.definition;
-                System.out.println("    internal " + def.name);
-            }
-            else if(id.definition instanceof External) {
-                External def = (External)id.definition;
-                System.out.println("    external " + def.name);
-            }
-        }*/
-    }
-    
-    public void findBuiltins(WriteOnlyGraph g) throws DatabaseException {
-        RootLibrary = g.getBuiltin("http:/");
-        String = g.getBuiltin(CoreInitialization.LAYER0 + "String");
-        Library = g.getBuiltin(CoreInitialization.LAYER0 + "Library");
-        InstanceOf = g.getBuiltin(CoreInitialization.LAYER0 + "InstanceOf");
-        ConsistsOf = g.getBuiltin(CoreInitialization.LAYER0 + "ConsistsOf");
-        PartOf = g.getBuiltin(CoreInitialization.LAYER0 + "PartOf");
-        HasName = g.getBuiltin(CoreInitialization.LAYER0 + "HasName");
-        NameOf = g.getBuiltin(CoreInitialization.LAYER0 + "NameOf");
-    }
-    
-    public void findBuiltins(ReadGraph g) throws DatabaseException {
-        RootLibrary = g.getBuiltin("http:/");
-        String = g.getBuiltin(CoreInitialization.LAYER0 + "String");
-        Library = g.getBuiltin(CoreInitialization.LAYER0 + "Library");
-        InstanceOf = g.getBuiltin(CoreInitialization.LAYER0 + "InstanceOf");
-        ConsistsOf = g.getBuiltin(CoreInitialization.LAYER0 + "ConsistsOf");
-        PartOf = g.getBuiltin(CoreInitialization.LAYER0 + "PartOf");
-        HasName = g.getBuiltin(CoreInitialization.LAYER0 + "HasName");
-        NameOf = g.getBuiltin(CoreInitialization.LAYER0 + "NameOf");
-    }
-
-    /* Preparation that is used when the core is empty. 
-     */
-    void initialPrepare(WriteOnlyGraph graph) throws DatabaseException {
-        findBuiltins(graph);
-        
-        resources = new Resource[tg.resourceCount];
-        
-        int Root = -1;
-        int SimanticsDomain = -1;
-        int Layer0 = -1;
-        
-        for(Identity identity : tg.identities) {
-            if(identity.definition instanceof Internal) {
-                Internal def = (Internal)identity.definition;
-                Resource res = null;
-                if(def.parent == Layer0) {
-                    try {
-                        res = graph.getBuiltin(CoreInitialization.LAYER0 + def.name);
-                    } catch(ResourceNotFoundException e) {                                      
-                    }
-                }
-                else if(def.parent == SimanticsDomain) {
-                    if(def.name.equals("Layer0-1.1"))
-                        Layer0 = identity.resource;
-                }
-                else if(def.parent == Root) {
-                    if(def.name.equals("www.simantics.org"))
-                        SimanticsDomain = identity.resource;
-                }
-
-                if(res == null)
-                    res = createChild(graph, resources[def.parent], def.name);
-                else
-                    createChild(graph, res, resources[def.parent], def.name);
-                resources[identity.resource] = res;
-            }
-            else if(identity.definition instanceof Root) {
-                Root = identity.resource;
-                resources[identity.resource] = RootLibrary;             
-            } 
-        }
-    }
-    
-    void addMissing(String external) {
-        Set<String> removals = new HashSet<String>();
-        for(String ext : missingExternals) if(ext.startsWith(external)) return;
-        for(String ext : missingExternals) if(external.startsWith(ext)) removals.add(ext);
-        missingExternals.removeAll(removals);
-        missingExternals.add(external);
-    }
-    
-    void prepare(ReadGraph graph) throws DatabaseException {
-        findBuiltins(graph);
-        
-        Resource[] resources = new Resource[tg.resourceCount];
-        
-        for(Identity identity : tg.identities) {
-            IdentityDefinition definition = identity.definition;
-            if(definition instanceof External) {
-                External def = (External)definition;
-                if(def.parent == -1) {
-                    resources[identity.resource] = RootLibrary;
-                } else {
-                    if("@inverse".equals(def.name)) {
-                        Resource parent = resources[def.parent];
-                        Resource child = graph.getInverse(parent);
-                        resources[identity.resource] = child;
-                    } else {
-                        Resource parent = resources[def.parent];
-                        // TODO: escape should be removed when names become well-behaving
-                        if(parent != null) {
-                            Resource child = graph
-                            .syncRequest(new UnescapedChildMapOfResource(parent),
-                                    new TransientCacheAsyncListener<Map<String, Resource>>())
-                                    .get(def.name);
-                            if(child == null) {
-                                addMissing(graph.getURI(parent) + "/" + def.name);
-                            }
-                            resources[identity.resource] = child;
-                        } else {
-                            addMissing(TransferableGraphUtils.getURI(tg.resourceCount, tg.identities, def.parent) + "/" + def.name);
-                        }
-                    }
-                }
-            }
-            else if(definition instanceof Internal) {
-                // Do not do anything for now
-            }
-            else if(definition instanceof Root) {
-                Root root = (Root)definition;
-                if(root.name.equals(""))
-                    resources[identity.resource] = RootLibrary;
-                else 
-                    advisor.analyzeRoot(graph, root);                   
-            }
-            else if(definition instanceof Optional) {
-                External def = (External)definition;
-                Resource parent = resources[def.parent];
-                if(parent != null)
-                    resources[identity.resource] = 
-                        graph.syncRequest(new UnescapedChildMapOfResource(parent)).get(def.name);               
-            }
-        }       
-        
-        this.resources = resources;
-        
-        if(!missingExternals.isEmpty()) throw new OldMissingDependencyException(this);
-        
-    }
-
-    Resource createChild(WriteOnlyGraph graph, Resource parent, String name) throws DatabaseException {
-        Resource child = graph.newResource();
-        graph.claim(parent, ConsistsOf, PartOf, child);
-        Resource nameResource = graph.newResource();
-        graph.claim(nameResource, InstanceOf, null, String);
-        graph.claimValue(nameResource, name, WriteBindings.STRING);
-        graph.claim(child, HasName, NameOf, nameResource);
-        return child;
-    }
-    
-    void createChild(WriteOnlyGraph graph, Resource child, Resource parent, String name) throws DatabaseException {
-        graph.claim(parent, ConsistsOf, PartOf, child);
-        Resource nameResource = graph.newResource();
-        graph.claim(nameResource, InstanceOf, null, String);
-        graph.claimValue(nameResource, name, WriteBindings.STRING);
-        graph.claim(child, HasName, NameOf, nameResource);
-    }
-    
-    int[] getClustering() {
-        Variant v = tg.extensions.get(Extensions.CLUSTERING);
-        if(v == null) return null;
-        try {
-            return (int[])v.getValue(Bindings.INT_ARRAY);
-        } catch (AdaptException e) {
-            Logger.defaultLogError(e);
-            return null;
-        }
-    }
-    
-    void write(WriteOnlyGraph graph) throws DatabaseException {
-
-        Resource[] resources = this.resources;
-
-        this.handles = new ResourceHandle[resources.length];
-        
-        ResourceHandle[] handles = this.handles; 
-
-        int[] clustering = getClustering();
-
-        // Internal identities      
-        for(Identity identity : tg.identities) {
-            IdentityDefinition definition = identity.definition;
-            if(resources[identity.resource] != null)
-                continue;
-            if(definition instanceof External) {
-                // Already done everything
-            }
-            else if(definition instanceof Internal) {
-                Internal def = (Internal)definition;
-                resources[identity.resource] = 
-                    createChild(graph, resources[def.parent], def.name);
-            }
-            else if(definition instanceof Root) {
-                Root root = (Root)definition;               
-                resources[identity.resource] = advisor.createRoot(graph, root);                 
-            }
-            else if(definition instanceof Optional) {
-                Optional def = (Optional)definition;
-                Resource child = createChild(graph, resources[def.parent], def.name);
-                graph.claim(child, InstanceOf, null, Library); // ???
-                resources[identity.resource] = child;                   
-            }
-        }       
-
-        ClusterBuilder builder = graph.getService(ClusterBuilder.class);
-        SerialisationSupport ss = graph.getService(SerialisationSupport.class);
-
-        if(clustering != null) {
-            
-            int i = 0;
-            for(int c : clustering) {
-                builder.newCluster();
-                for(int r=0;r<c;r++, i++)
-                    if(resources[i] == null)
-                        handles[i] = builder.newResource();
-                    else 
-                        handles[i] = builder.resource(resources[i]);
-
-            }
-
-            for(;i<resources.length;++i)
-                if(resources[i] == null)
-                    handles[i] = builder.newResource();
-                else 
-                    handles[i] = builder.resource(resources[i]);
-            
-        } else {
-        
-            // Create blank resources
-            for(int i=0;i<resources.length;++i)
-                if(resources[i] == null)
-                    handles[i] = builder.newResource();
-                else 
-                    handles[i] = builder.resource(resources[i]);
-
-        }
-        
-        // Write statements
-        int[] statements = tg.statements;
-        
-        int internals = tg.resourceCount - tg.identities.length;
-        
-        for(int i=0;i<statements.length;i+=4) {
-
-            int sub = statements[i];
-            int pred = statements[i+1];
-            int inv = statements[i+2];
-            int obj = statements[i+3];
-
-            ResourceHandle subject = handles[sub];
-            ResourceHandle predicate = handles[pred];
-            ResourceHandle object = handles[obj];
-
-            if(resources[sub] == null) {
-                subject.addStatement(graph, predicate, object); 
-            } else {
-                graph.claim(
-                        handles[sub].resource(ss),
-                        handles[pred].resource(ss),
-                        null, handles[obj].resource(ss));
-            }
-            
-            if(inv >= 0) {
-                
-                if(resources[obj] == null) {
-                    ResourceHandle inverse = handles[inv];
-                    object.addStatement(graph, inverse, subject);   
-                } else {
-                    graph.claim(
-                            handles[obj].resource(ss),
-                            handles[inv].resource(ss),
-                            null, handles[sub].resource(ss));
-                }
-                
-            }
-            
-            if(LOG) {
-                log("[STATEMENT] " + resources[statements[i]].getResourceId() + ", " + resources[statements[i+1]].getResourceId() + ", " + resources[statements[i+3]].getResourceId());
-            }
-            
-        }
-                
-        // Write values
-        TransferableGraphSupport tgSupport = 
-            graph.getService(TransferableGraphSupport.class);
-        VirtualGraph vg = graph.getProvider();
-        for(OldValue1 value : tg.values) {
-            int file = value.resource & 0x80000000;
-            int resource = value.resource & 0x7FFFFFFF;
-            if (file != 0) {
-                graph.claimValue(handles[resource].resource(ss), value.value, Bindings.BYTE_ARRAY);
-            } else {
-                if(resource < internals) {
-                    handles[resource].addValue(graph, value.value);
-                } else {
-                    tgSupport.setValue(graph, handles[resource].resource(ss), vg, value.value);
-                }
-                //tgSupport.setValue(resources[resource], vg, value.value);
-            }
-        }
-    }
-    
-    void write2(WriteOnlyGraph graph) throws DatabaseException {
-        Resource[] resources = this.resources;
-        
-        // Internal identities      
-        for(Identity identity : tg.identities) {
-            IdentityDefinition definition = identity.definition;
-            if(resources[identity.resource] != null)
-                continue;
-            if(definition instanceof External) {
-                // Already done everything
-            }
-            else if(definition instanceof Internal) {
-                Internal def = (Internal)definition;
-                resources[identity.resource] = 
-                    createChild(graph, resources[def.parent], def.name);
-            }
-            else if(definition instanceof Root) {               
-                Root root = (Root)definition;               
-                resources[identity.resource] = advisor.createRoot(graph, root);                 
-            }
-            else if(definition instanceof Optional) {
-                Optional def = (Optional)definition;
-                Resource child = createChild(graph, resources[def.parent], def.name);
-                graph.claim(child, InstanceOf, null, Library); // ???
-                resources[identity.resource] = child;                   
-            }
-        }       
-        
-        // Create blank resources
-        for(int i=0;i<resources.length;++i)
-            if(resources[i] == null)
-                resources[i] = graph.newResource();
-        
-        // Write statements
-        int[] statements = tg.statements;
-        
-        for(int i=0;i<statements.length;i+=4) {
-            int inv = statements[i+2];
-            graph.claim(
-                    resources[statements[i]],
-                    resources[statements[i+1]],
-                    inv < 0 ? null : resources[inv],
-                    resources[statements[i+3]]
-                    );
-            if(LOG) {
-                log("[STATEMENT] " + resources[statements[i]].getResourceId() + ", " + resources[statements[i+1]].getResourceId() + ", " + resources[statements[i+3]].getResourceId());
-            }
-        }
-                
-        // Write values
-        TransferableGraphSupport tgSupport = 
-            graph.getService(TransferableGraphSupport.class);
-        VirtualGraph vg = graph.getProvider();
-        for(OldValue1 value : tg.values) {
-            int file = value.resource & 0x80000000;
-            int resource = value.resource & 0x7FFFFFFF;
-            if (file != 0) {
-                graph.claimValue(resources[resource], value.value, Bindings.BYTE_ARRAY);
-            } else {
-                tgSupport.setValue(graph, resources[resource], vg, value.value);
-            }
-        }
-    }
-    
-    
-    public long[] getResourceIds(SerialisationSupport serializer) throws DatabaseException {
-        final int count = resources.length;
-        long[] resourceIds = new long[count];
-        if(handles != null) {
-            for(int i=0;i<count;++i)
-                resourceIds[i] = serializer.getRandomAccessId(handles[i].resource(serializer));
-        } else {
-            for(int i=0;i<count;++i)
-                resourceIds[i] = serializer.getRandomAccessId(resources[i]);
-        }
-        return resourceIds;
-    }
-    
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphs.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphs.java
deleted file mode 100644 (file)
index 4786abd..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.graph.db.old;
-
-import java.util.function.BiFunction;
-
-import org.simantics.db.ReadGraph;
-import org.simantics.db.Session;
-import org.simantics.db.WriteGraph;
-import org.simantics.db.WriteOnlyGraph;
-import org.simantics.db.common.request.ReadRequest;
-import org.simantics.db.common.request.WriteOnlyRequest;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.graph.db.IImportAdvisor;
-import org.simantics.graph.db.ImportAdvisor;
-import org.simantics.graph.db.TransferableGraphException;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
-
-public class OldTransferableGraphs {
-
-    public static void importGraph1(Session session, final OldTransferableGraph1 tg, IImportAdvisor advisor, final BiFunction<WriteOnlyGraph, OldTransferableGraphImportProcess1, Boolean> callback) throws DatabaseException, TransferableGraphException {
-        final OldTransferableGraphImportProcess1 process = new OldTransferableGraphImportProcess1(tg, 
-                advisor == null ? new ImportAdvisor() : advisor);
-        session.syncRequest(new ReadRequest() {
-            @Override
-            public void run(ReadGraph graph) throws DatabaseException {
-                process.prepare(graph);
-            }
-        });
-        session.syncRequest(new WriteOnlyRequest() {
-            @Override
-            public void perform(WriteOnlyGraph graph) throws DatabaseException {
-                process.write(graph);
-                if(callback != null)
-                    callback.apply(graph, process);
-            }
-        });
-    }
-    
-    public static void importGraph1(WriteGraph graph, final OldTransferableGraph1 tg, IImportAdvisor advisor) throws DatabaseException {
-        final OldTransferableGraphImportProcess1 process = new OldTransferableGraphImportProcess1(tg, 
-                advisor == null ? new ImportAdvisor() : advisor);
-        process.prepare(graph);
-        process.write2(graph);
-       
-    }
-    
-}
index d64e63f57228046ce763af88b54e7019462ea286..6ae6e86fe08dfbfbbf7a901827a061f43d989732 100644 (file)
@@ -12,7 +12,6 @@ Export-Package: org.simantics.graph,
  org.simantics.graph.query,
  org.simantics.graph.refactoring,
  org.simantics.graph.representation,
- org.simantics.graph.representation.old,
  org.simantics.graph.store,
  org.simantics.graph.tests.conversion,
  org.simantics.graph.utils
index 850c47d8598c3bbdd46bc49ae5eb4f0356bdc10d..9c96f834dd61c6ca75292630b2481ab765b47129 100644 (file)
@@ -15,7 +15,6 @@ import org.simantics.graph.representation.Optional;
 import org.simantics.graph.representation.Root;
 import org.simantics.graph.representation.TransferableGraph1;
 import org.simantics.graph.representation.Value;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
 import org.simantics.graph.store.GraphStore;
 import org.simantics.graph.store.IStore;
 import org.simantics.graph.store.IdentityStore;
@@ -44,10 +43,6 @@ public class TransferableGraphConversion {
            return extractIdentities(tg.resourceCount, tg.identities);
        }
        
-       public static IdentityStore extractIdentities(OldTransferableGraph1 tg) {
-        return extractIdentities(tg.resourceCount, tg.identities);
-    }
-       
        private static IdentityStore extractIdentities(int resourceCount, Identity[] ids) {
            IdentityStore identities = new IdentityStore();
         identities.setResourceCount(resourceCount);
index ddc31aa5b15811722b65b785886b871e31c4053b..9f8eca398f139c10a5a18801522230427fa29f08 100644 (file)
@@ -1,6 +1,5 @@
 package org.simantics.graph.refactoring;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 
 import org.simantics.databoard.util.URIStringUtils;
@@ -11,14 +10,10 @@ import org.simantics.graph.query.UriUtils;
 import org.simantics.graph.refactoring.MappingSpecification.MappingRule;
 import org.simantics.graph.representation.External;
 import org.simantics.graph.representation.Identity;
-import org.simantics.graph.representation.IdentityDefinition;
 import org.simantics.graph.representation.Internal;
-import org.simantics.graph.representation.Optional;
 import org.simantics.graph.representation.Root;
 import org.simantics.graph.representation.TransferableGraph1;
 import org.simantics.graph.representation.TransferableGraphUtils;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
-import org.simantics.graph.representation.old.OldValue1;
 import org.simantics.graph.store.GraphStore;
 import org.simantics.graph.store.IdentityStore;
 import org.slf4j.Logger;
@@ -159,69 +154,4 @@ public class GraphRefactoringUtils {
         }
     }
 
-    public static void compactify(OldTransferableGraph1 tg,
-            TIntHashSet removed) {
-        // Filter removed set
-        for(Identity id : tg.identities) {
-            IdentityDefinition def = id.definition;
-            if(def instanceof Root)
-                removed.remove(id.resource);
-            else if(def instanceof External)
-                removed.remove(((External)def).parent);
-            else if(def instanceof Internal)
-                removed.remove(((Internal)def).parent);
-            else if(def instanceof Optional)
-                removed.remove(((Optional)def).parent);
-        }
-        for(int r : tg.statements)
-            removed.remove(r);
-        for(OldValue1 value : tg.values)
-            removed.remove(value.resource);
-        
-        // Compactify
-        if(!removed.isEmpty()) {
-            // create map
-            int resourceCount = tg.resourceCount;
-            int[] map = new int[resourceCount];
-            for(int i=0;i<resourceCount;++i)
-                map[i] = i;
-            for(int r : removed.toArray()) {
-                map[--resourceCount] = map[r];
-            }
-            
-            // map
-            ArrayList<Identity> newIdentities = new ArrayList<Identity>(tg.identities.length);
-            for(Identity id : tg.identities) {
-                if(removed.contains(id.resource))
-                    continue;
-                else
-                    newIdentities.add(id);                
-                id.resource = map[id.resource];
-                IdentityDefinition def = id.definition;
-                if(def instanceof External) {
-                    External d = (External)def;
-                    d.parent = map[d.parent];
-                }
-                else if(def instanceof Internal) {
-                    External d = (External)def;
-                    d.parent = map[d.parent];
-                }
-                else if(def instanceof Optional) {
-                    External d = (External)def;
-                    d.parent = map[d.parent];
-                }
-            }
-            tg.identities = newIdentities.toArray(new Identity[newIdentities.size()]);
-            int[] statements = tg.statements;
-            for(int i=0;i<statements.length;++i) {
-                int r = statements[i];                        
-                if(r >= 0)
-                    statements[i] = map[r];
-            }
-            for(OldValue1 value : tg.values)
-                value.resource = map[value.resource];
-            tg.resourceCount = resourceCount;
-        }
-    }
-
 }
diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/PrintReferencesTool.java b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/PrintReferencesTool.java
deleted file mode 100644 (file)
index d980692..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.simantics.graph.refactoring;
-
-import gnu.trove.map.hash.THashMap;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-
-import org.simantics.databoard.Files;
-import org.simantics.graph.query.TransferableGraphConversion;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
-import org.simantics.graph.store.IdentityStore;
-import org.simantics.graph.store.IdentityStore.ConsistsOf;
-
-public class PrintReferencesTool {
-
-    public static void main(String[] args) throws Exception {
-        print(new File(args[0]));
-    }
-    
-    public static void print(File input) throws IOException {
-        OldTransferableGraph1 tg = (OldTransferableGraph1)
-                Files.readFile(input, OldTransferableGraph1.BINDING);
-        GraphRefactoringUtils.fixIncorrectRoot(tg.identities);
-        IdentityStore idStore = TransferableGraphConversion.extractIdentities(tg);
-        printExternals(idStore, idStore.getRoot(""), 0);
-    }
-
-    private static void printExternals(IdentityStore idStore, int cur, int indentation) {
-        THashMap<String, ConsistsOf> map = idStore.getChildMap(cur);
-        if(map == null)
-            return;
-        ArrayList<String> names = new ArrayList<String>(map.keySet());
-        Collections.sort(names);
-        for(String name : names) {
-            ConsistsOf co = map.get(name);
-            if(!idStore.isNewResource(co.child)) {
-                for(int i=0;i<indentation;++i)
-                    System.out.print("    ");
-                System.out.println(name);
-                printExternals(idStore, co.child, indentation+1);
-            }
-        }
-    }
-    
-}
diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/RefactoringTool.java b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/RefactoringTool.java
deleted file mode 100644 (file)
index c172e98..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-package org.simantics.graph.refactoring;
-
-import gnu.trove.set.hash.TIntHashSet;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-
-import org.simantics.databoard.Files;
-import org.simantics.graph.query.Path;
-import org.simantics.graph.query.TransferableGraphConversion;
-import org.simantics.graph.query.UriUtils;
-import org.simantics.graph.refactoring.MappingSpecification.MappingRule;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
-import org.simantics.graph.store.IdentityStore;
-
-
-public class RefactoringTool {
-
-    public static void main(String[] args) throws Exception {
-        if(args.length != 3)
-            System.out.println("Usage: java " + RefactoringTool.class.getCanonicalName() + " mappingSpec input.tg ouput.tg");
-        refactor(new File(args[0]), new File(args[1]), new File(args[2]));
-    }
-
-    public static void refactor(File mappingSpec, File input, File output) throws IOException, GraphRefactoringException  {
-        if(!mappingSpec.exists()) {
-            System.out.println("Mapping specification " + mappingSpec + " does not exist.");
-            return;
-        }
-        if(!input.exists()) {
-            System.out.println("Input tg " + input + " does not exist.");
-            return;
-        }
-         
-        MappingSpecification spec = readMappingSpec(mappingSpec);
-        
-        // Refactor old format
-        OldTransferableGraph1 tg = (OldTransferableGraph1)
-                Files.readFile(input, OldTransferableGraph1.BINDING);
-        boolean fixed = GraphRefactoringUtils.fixIncorrectRoot(tg.identities);
-        IdentityStore idStore = TransferableGraphConversion.extractIdentities(tg);
-        TIntHashSet parentsAffected = new TIntHashSet(); 
-        GraphRefactoringUtils.refactor(null, idStore, spec, parentsAffected);
-        tg.resourceCount = idStore.getResourceCount();
-        tg.identities = idStore.toArray();
-        GraphRefactoringUtils.compactify(tg, parentsAffected);
-        if(fixed)
-            GraphRefactoringUtils.unfixIncorrectRoot(tg.identities);
-        
-        // Write to output file
-        Files.writeFile(output, OldTransferableGraph1.BINDING, tg);
-    }
-
-    private static MappingSpecification readMappingSpec(File mappingSpec) throws IOException {
-        BufferedReader reader = new BufferedReader(new FileReader(mappingSpec));
-        ArrayList<MappingRule> rules = new ArrayList<MappingRule>();
-        while(true) {
-            String line = reader.readLine();
-            if(line == null)
-                break;
-            line = line.trim();
-            if(line.isEmpty())
-                continue;
-            String[] parts = line.trim().split(" ");
-            if(parts.length != 2)
-                throw new IOException("Invalid mapping spec format. Every non-empty line should contain two URIs.");
-            
-            Path from = UriUtils.uriToPath(parts[0]);
-            Path to = UriUtils.uriToPath(parts[1]);
-            
-            rules.add(new MappingRule(from, to));
-        }
-        reader.close();
-        
-        return new MappingSpecification(rules);
-    }
-           
-}
diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/representation/old/OldTransferableGraph1.java b/bundles/org.simantics.graph/src/org/simantics/graph/representation/old/OldTransferableGraph1.java
deleted file mode 100644 (file)
index b68bea3..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.graph.representation.old;
-
-import java.util.TreeMap;
-
-import org.simantics.databoard.Bindings;
-import org.simantics.databoard.binding.Binding;
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.databoard.serialization.Serializer;
-import org.simantics.graph.representation.External;
-import org.simantics.graph.representation.Identity;
-import org.simantics.graph.representation.Internal;
-import org.simantics.graph.representation.Root;
-import org.simantics.graph.tests.conversion.TransferableGraph0;
-
-
-/**
- * Transferable graph datatype. 
- * See <a href="https://www.simantics.org/wiki/index.php/Graph_exchange_format">specification</a>. 
- * @author Hannu Niemist´┐Ż
- * 
- * @deprecated superceded by {@link TransferableGraph0}
- */
-@Deprecated
-public class OldTransferableGraph1 {
-       public static Binding BINDING = Bindings.getBindingUnchecked(OldTransferableGraph1.class);
-       public static Serializer SERIALIZER = Bindings.getSerializerUnchecked(BINDING);
-       
-       public int resourceCount;
-       public Identity[] identities;   
-       public int[] statements;
-       public OldValue1[] values;
-       public TreeMap<String, Variant> extensions;
-       
-       public OldTransferableGraph1() {}
-       
-       public OldTransferableGraph1(int resourceCount, Identity[] identities,
-                       int[] statements, OldValue1[] values) {
-               this(resourceCount, identities, statements, values,
-                               new TreeMap<String, Variant>());
-       }
-       
-       public OldTransferableGraph1(int resourceCount, Identity[] identities,
-                       int[] statements, OldValue1[] values, TreeMap<String, Variant> extensions) {
-               this.resourceCount = resourceCount;
-               this.identities = identities;
-               this.statements = statements;
-               this.values = values;
-               this.extensions = extensions;
-       }
-
-       public void print() {
-               System.out.println("Identities");
-               for(Identity id : identities) {
-                       System.out.print("    " + id.resource + " = ");
-                       if(id.definition instanceof Root) {
-                               Root def = (Root)id.definition;
-                               System.out.println("ROOT(" + def.name + ")");
-                       }
-                       else if(id.definition instanceof External) {
-                               External def = (External)id.definition;
-                               System.out.println("EXTERNAL(" + def.parent + ", " + def.name + ")");
-                       }
-                       else if(id.definition instanceof Internal) {
-                               Internal def = (Internal)id.definition;
-                               System.out.println("INTERNAL(" + def.parent + ", " + def.name + ")");
-                       }
-               }
-               System.out.println("Statements:");
-               for(int i=0;i<statements.length;i+=4)
-                       System.out.println("    " + 
-                                       statements[i] + " " +
-                                       statements[i+1] + " " +
-                                       statements[i+2] + " " +
-                                       statements[i+3]
-                                       );
-       }
-}
diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/representation/old/OldValue1.java b/bundles/org.simantics.graph/src/org/simantics/graph/representation/old/OldValue1.java
deleted file mode 100644 (file)
index 0994b07..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.graph.representation.old;
-
-
-/**
- * A part of TransferableGraph data structure.
- * Says that the resource has a literal with given value.
- * @author Hannu Niemist´┐Ż
- */
-public class OldValue1 {
-       public int resource;
-       public byte[] value;
-       
-       public OldValue1() {
-       }
-       
-       public OldValue1(int resource, byte[] value) {
-               this.resource = resource;
-               this.value = value;
-       }       
-}
diff --git a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/TestRefactoring.java b/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/TestRefactoring.java
deleted file mode 100644 (file)
index f7c7cb1..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.simantics.graph.tests.refactoring;
-
-import java.io.File;
-import java.net.URLDecoder;
-
-import org.simantics.graph.refactoring.PrintReferencesTool;
-import org.simantics.graph.refactoring.RefactoringTool;
-
-public class TestRefactoring {
-
-    public static void main(String[] args) throws Exception {
-        File dir = new File(URLDecoder.decode(TestRefactoring.class.getResource(".").getPath(), "UTF-8")).getAbsoluteFile();// new File(TestRefactoring.class.getResource(".").getFile());
-        System.out.println(dir);
-        File input = new File(dir, "xor5.aprosSymbol");
-        File mappingSpec = new File(dir, "mappingSpec.txt");
-        File output = new File(dir, "xor5_refactored.aprosSymbol");
-        
-        System.out.println("-- Before refactoring");
-        System.out.println("------------------------------------------");
-        PrintReferencesTool.print(input);
-        
-        RefactoringTool.refactor(mappingSpec, input, output);
-        
-        System.out.println("-- After refactoring");
-        System.out.println("------------------------------------------");
-        PrintReferencesTool.print(output);
-    }
-    
-}
diff --git a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/TestRefactoring2.java b/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/TestRefactoring2.java
deleted file mode 100644 (file)
index c122cff..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.simantics.graph.tests.refactoring;
-
-import java.io.File;
-import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.simantics.graph.refactoring.RefactoringTool;
-
-public class TestRefactoring2 {
-
-    public static void main(String[] args) throws Exception {
-        File dir = new File(URLDecoder.decode(TestRefactoring2.class.getResource(".").getPath(), "UTF-8")).getAbsoluteFile();// new File(TestRefactoring.class.getResource(".").getFile());
-        System.out.println(dir);
-        File allFiles[] = dir.listFiles();
-        List<File> inputFiles = new ArrayList<File>();
-        List<File> outputFiles = new ArrayList<File>();
-        String ext = ".aprosSymbol";
-        File outDir = new File(dir,"out");
-        if (!outDir.exists())
-               outDir.mkdir();
-        for (File f: allFiles) {
-               if (!f.isFile())
-                       continue;
-               if (!f.getName().endsWith(ext))
-                       continue;
-               inputFiles.add(f);
-               String outputName = f.getName();
-               outputFiles.add(new File(outDir,outputName));
-        }
-        
-        File mappingSpec = new File(dir, "mappingSpec.txt");
-        for (int i = 0; i < inputFiles.size() ; i++) {
-               
-               File input = inputFiles.get(i);
-               File output = outputFiles.get(i);
-               
-               System.out.println(input + " -> " + output);   
-               
-               RefactoringTool.refactor(mappingSpec, input, output);
-        }
-    }
-    
-}
diff --git a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/mappingSpec.txt b/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/mappingSpec.txt
deleted file mode 100644 (file)
index d85d332..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-http://www.apros.fi/AprosStatic-6.0 http://www.apros.fi/Combustion/Configuration-6.0
-http://www.apros.fi/AprosDiagram-6.0/Terminals http://www.apros.fi/Apros-6.1/Terminals
-http://www.apros.fi/AprosDiagram-6.0/Relations http://www.apros.fi/Combustion/Diagram-6.0/Relations
-http://www.apros.fi/AprosDiagram-6.0/Symbols http://www.apros.fi/Combustion/Diagram-6.0/Symbols
-http://www.apros.fi/AprosDiagram-6.0/AnalogSignalOutputRelation http://www.apros.fi/Combustion/Diagram-6.0/AnalogSignalOutputRelation
-http://www.apros.fi/AprosDiagram-6.0/BinarySignalOutputRelation http://www.apros.fi/Combustion/Diagram-6.0/BinarySignalOutputRelation
\ No newline at end of file
diff --git a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/xor5.aprosSymbol b/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/xor5.aprosSymbol
deleted file mode 100644 (file)
index d005eb2..0000000
Binary files a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/xor5.aprosSymbol and /dev/null differ
index 27f853e0283b3d714757f4d3369cab4379cf470d..386199d838d3cfd0e60cb1faea0375bb45791e21 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.scl.compiler.internal.codegen.ssa.exits;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 
 import org.objectweb.asm.Label;
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
@@ -26,6 +27,8 @@ import org.simantics.scl.compiler.types.TVar;
 import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
 
+import gnu.trove.map.hash.TIntObjectHashMap;
+
 public class Switch extends SSAExit implements ValRefBinder {
 
     ValRef scrutinee;
@@ -60,14 +63,19 @@ public class Switch extends SSAExit implements ValRefBinder {
         int defaultId;
         for(defaultId=0;defaultId<branches.length-1&&branches[defaultId].constructor!=null;++defaultId);
         int[] values = new int[defaultId];
-        Label[] labels = new Label[defaultId];
         Cont[] continuations = new Cont[defaultId+1];
+        TIntObjectHashMap<Label> labelMap = new TIntObjectHashMap<Label>(defaultId); 
         for(int i=0;i<defaultId;++i) {
-            values[i] = ((IntegerConstant)branches[i].constructor).getValue();
+            int value = ((IntegerConstant)branches[i].constructor).getValue();
+            values[i] = value;
             Cont cont = branches[i].cont.getBinding();
-            labels[i] = mb.getLabel(cont);
+            labelMap.put(value,  mb.getLabel(cont));
             continuations[i] = cont;
         }
+        Arrays.sort(values);
+        Label[] labels = new Label[defaultId];
+        for(int i=0;i<defaultId;++i)
+            labels[i] = labelMap.get(values[i]);
         Label defaultLabel;
         {
             Cont cont = branches[defaultId].cont.getBinding();
index 4701e2586e961465e9a9a6c95085b984eb8111a2..dc2c775241574595b88c5f36ccdf75e8610782c6 100644 (file)
@@ -147,6 +147,7 @@ public class ModuleRegressionTests extends TestBase {
     @Test public void Matching2() { test(); }
     @Test public void Matching4() { test(); }
     @Test public void Matching5() { test(); }
+    @Test public void Matching6() { test(); }
     @Test public void MatchingWithMissingParameter() { test(); }
     @Test public void MatchingWithoutTypeAnnotations() { test(); }
     @Test public void MaximumBy() { test(); }
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Matching6.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Matching6.scl
new file mode 100644 (file)
index 0000000..f4f7cc4
--- /dev/null
@@ -0,0 +1,9 @@
+import "Prelude"
+
+main = do 
+    match 1+1 :: Integer with
+        2 -> 2
+        0 -> 0
+        1 -> 1
+--
+2
\ No newline at end of file