]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5224
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 26 Aug 2014 07:19:58 +0000 (07:19 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 26 Aug 2014 07:19:58 +0000 (07:19 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30136 ac1ea38d-2e2b-0410-8846-a27921b304fc

fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Parser.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/VariableBase.java

index 4e65b150382f8435459eb25b10ff8aa6fb2b6c32..8747c51898cf5985989a87dfe5e43ef5e31391fa 100644 (file)
@@ -454,4 +454,55 @@ public class Array implements IExpression {
                return isVector;\r
        }\r
 \r
+       private Object subscript(IEnvironment environment, IExpression[] subscripts, int position) {\r
+               \r
+               IExpression e = subscripts[position];\r
+               int index = Utils.getIndex(e.evaluate(environment));\r
+               if(index == -2) {\r
+                       Array ret = new Array();\r
+                       for(Object element : elements) {\r
+                               // Last position should not be array\r
+                               if(position == subscripts.length-1) {\r
+                                       if(element instanceof Array) throw new IllegalStateException();\r
+                                       if(element instanceof IExpression) {\r
+                                               IExpression exp = (IExpression)element;\r
+                                               return exp.evaluate(environment);\r
+                                       } else {\r
+                                               ret.addElement(element);\r
+                                       }\r
+                               } else {\r
+                                       if(element instanceof Array) {\r
+                                               return ret.addElement(((Array)element).subscript(environment, subscripts, position+1));\r
+                                       } else {\r
+                                               throw new IllegalStateException();\r
+                                       }\r
+                               }\r
+                       }\r
+                       return ret;\r
+               } else {\r
+                       Object element = element(index);\r
+                       // Last position should not be array\r
+                       if(position == subscripts.length-1) {\r
+                               if(element instanceof Array) throw new IllegalStateException();\r
+                               if(element instanceof IExpression) {\r
+                                       IExpression exp = (IExpression)element;\r
+                                       return exp.evaluate(environment);\r
+                               } else {\r
+                                       return element;\r
+                               }\r
+                       } else {\r
+                               if(element instanceof Array) {\r
+                                       return ((Array)element).subscript(environment, subscripts, position+1);\r
+                               } else {\r
+                                       throw new IllegalStateException();\r
+                               }\r
+                       }\r
+               }\r
+               \r
+       }\r
+       \r
+       public Object subscript(IEnvironment environment, IExpression[] subscripts) {\r
+               return subscript(environment, subscripts, 0);\r
+       }\r
+\r
 }\r
index d9ab2c96630ef623222d8586fe94d3a28b638a74..84d8afed45b0624bf54bbb31045d06d36bee8bf4 100644 (file)
@@ -273,14 +273,16 @@ final public class Environment implements IEnvironment, ISystem {
                        public Object evaluate(IEnvironment environment, int argc) {\r
                                Object value = environment.getValue(0);\r
                                if(value instanceof Double) {\r
-                                       return ((Double)value).intValue();\r
+                                       double d = ((Double)value).intValue(); \r
+                                       return d;\r
                                } else if(value instanceof Array) {\r
                                        return ((Array)value).copy(new Modifier() {\r
 \r
                                                @Override\r
                                                public Object modify(Object o) {\r
                                                        if(o instanceof Double) {\r
-                                                               return ((Double)o).intValue();\r
+                                                               double d = ((Double)o).intValue(); \r
+                                                               return d;\r
                                                        } else {\r
                                                                throw new IllegalStateException();\r
                                                        }\r
index f9a177303a3af98216929fc1d964f95a9b6d6820..95d0116602b3a5e6a4ae6759988b4af6dde9b57f 100644 (file)
@@ -376,7 +376,9 @@ public class Parser {
                                                                ArrayList<Object> os = (ArrayList<Object>)os_;\r
                                                                for(Object o : os) {\r
                                                                        VariableDeclaration decl = (VariableDeclaration)o;\r
-                                                                       function.internals.add(decl);\r
+                                                                       if("input".equals(decl.direction)) function.inputs.add(decl);\r
+                                                                       else if ("output".equals(decl.direction)) function.outputs.add(decl);\r
+                                                                       else function.internals.add(decl);\r
                                                                }\r
                                                        }\r
                                                }\r
@@ -389,14 +391,14 @@ public class Parser {
                                                        VariableDeclaration decl = (VariableDeclaration)os_;\r
                                                        if("input".equals(decl.direction)) function.inputs.add(decl);\r
                                                        else if ("output".equals(decl.direction)) function.outputs.add(decl);\r
-                                                       else throw new IllegalStateException();\r
+                                                       else function.internals.add(decl);\r
                                                } else {\r
                                                        ArrayList<Object> os = (ArrayList<Object>)os_;\r
                                                        for(Object o : os) {\r
                                                                VariableDeclaration decl = (VariableDeclaration)o;\r
                                                                if("input".equals(decl.direction)) function.inputs.add(decl);\r
                                                                else if ("output".equals(decl.direction)) function.outputs.add(decl);\r
-                                                               else throw new IllegalStateException();\r
+                                                               else function.internals.add(decl);\r
                                                        }\r
                                                }\r
                                        }\r
index 355c7919b74c8459055e823c6630bd8fad6aab06..e0a57a6c5c77d083604de828a92f54f540a45720 100644 (file)
@@ -130,10 +130,10 @@ public class VariableBase {
                return result;\r
        }\r
        \r
-       private boolean hasScalarSubscript(IExpression[] subscripts) {\r
-               if(subscripts == null) return false;\r
-               else return true;\r
-       }\r
+//     private boolean hasScalarSubscript(IExpression[] subscripts) {\r
+//             if(subscripts == null) return false;\r
+//             else return true;\r
+//     }\r
        \r
        public int intoArray(IEnvironment env, int index, int d, Array target) {\r
 \r
@@ -213,12 +213,8 @@ public class VariableBase {
                if(isStoredAsArray(environment)) {\r
                        \r
                        Array array = (Array)environment.getValue(index);\r
-                       if(hasScalarSubscript(subscripts)) {\r
-                               Object o = getArrayIndex(environment, subscripts, array);\r
-                               if(o instanceof Variable) throw new IllegalStateException();\r
-                               if(o instanceof Array)\r
-                                       throw new IllegalStateException();\r
-                               return o;\r
+                       if(subscripts != null) {\r
+                               return array.subscript(environment, subscripts);\r
                        }\r
                        else return array;\r
                        \r