]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5224
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 8 Sep 2014 07:34:29 +0000 (07:34 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 8 Sep 2014 07:34:29 +0000 (07:34 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30221 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/Utils.java

index 8c34ffc4c43cbe3250973962109f7937569a2cc3..12ffdf4fd0ced12f860b972c9584235e619700dc 100644 (file)
@@ -428,7 +428,8 @@ public class Array implements IExpression {
        private Object subscript(IEnvironment environment, IExpression[] subscripts, int position) {\r
                \r
                IExpression e = subscripts[position];\r
-               int index = Utils.getIndex(e.evaluate(environment));\r
+               Object indexObject = e.evaluate(environment);\r
+               int index = Utils.getIndex(indexObject);\r
                if(index == -2) {\r
                        Array ret = new Array();\r
                        for(Object element : elements) {\r
@@ -450,6 +451,32 @@ public class Array implements IExpression {
                                }\r
                        }\r
                        return ret;\r
+               } else if (index == -3) {\r
+                       \r
+                       Array arr = (Array)indexObject;\r
+                       Array ret = new Array();\r
+                       for(Object indexO : arr.elements()) {\r
+                               index = ((Double)indexO).intValue()-1;\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
+                                               ret.addElement(exp.evaluate(environment));\r
+                                       } else {\r
+                                               ret.addElement(element);\r
+                                       }\r
+                               } else {\r
+                                       if(element instanceof Array) {\r
+                                               ret.addElement(((Array)element).subscript(environment, subscripts, position+1));\r
+                                       } else {\r
+                                               throw new IllegalStateException();\r
+                                       }\r
+                               }\r
+                       }\r
+                       return ret;\r
+                       \r
                } else {\r
                        Object element = element(index);\r
                        // Last position should not be array\r
index 70508e471cfdff5804fd21a97757e88ee3ae2bb4..d4d4af1b60c14f3546ae0ca4191c2cf1509b5220 100644 (file)
@@ -17,6 +17,8 @@ public class Utils {
                        return ((Double)value).intValue()-1;\r
                } else if (value instanceof Constant) {\r
                        return getIndex(((Constant)value).value);\r
+               } else if (value instanceof Array) {\r
+                       return -3;\r
                } else {\r
                        throw new IllegalStateException();\r
                }\r