From 8eef4a63f70c488487e2cfbcd98cc81dc3a0f53d Mon Sep 17 00:00:00 2001 From: villberg Date: Mon, 8 Sep 2014 07:34:29 +0000 Subject: [PATCH] refs #5224 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30221 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../src/fi/semantum/sysdyn/solver/Array.java | 29 ++++++++++++++++++- .../src/fi/semantum/sysdyn/solver/Utils.java | 2 ++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java index 8c34ffc4..12ffdf4f 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java @@ -428,7 +428,8 @@ public class Array implements IExpression { private Object subscript(IEnvironment environment, IExpression[] subscripts, int position) { IExpression e = subscripts[position]; - int index = Utils.getIndex(e.evaluate(environment)); + Object indexObject = e.evaluate(environment); + int index = Utils.getIndex(indexObject); if(index == -2) { Array ret = new Array(); for(Object element : elements) { @@ -450,6 +451,32 @@ public class Array implements IExpression { } } return ret; + } else if (index == -3) { + + Array arr = (Array)indexObject; + Array ret = new Array(); + for(Object indexO : arr.elements()) { + index = ((Double)indexO).intValue()-1; + Object element = element(index); + // Last position should not be array + if(position == subscripts.length-1) { + if(element instanceof Array) throw new IllegalStateException(); + if(element instanceof IExpression) { + IExpression exp = (IExpression)element; + ret.addElement(exp.evaluate(environment)); + } else { + ret.addElement(element); + } + } else { + if(element instanceof Array) { + ret.addElement(((Array)element).subscript(environment, subscripts, position+1)); + } else { + throw new IllegalStateException(); + } + } + } + return ret; + } else { Object element = element(index); // Last position should not be array diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Utils.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Utils.java index 70508e47..d4d4af1b 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Utils.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Utils.java @@ -17,6 +17,8 @@ public class Utils { return ((Double)value).intValue()-1; } else if (value instanceof Constant) { return getIndex(((Constant)value).value); + } else if (value instanceof Array) { + return -3; } else { throw new IllegalStateException(); } -- 2.47.1