*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser;\r
\r
import org.simantics.sysdyn.unitParser.nodes.FunctionArguments;\r
import org.simantics.sysdyn.unitParser.nodes.FunctionCall;\r
import org.simantics.sysdyn.unitParser.nodes.IfThenElse;\r
+import org.simantics.sysdyn.unitParser.nodes.LogicalExpression;\r
+import org.simantics.sysdyn.unitParser.nodes.LogicalFactor;\r
+import org.simantics.sysdyn.unitParser.nodes.LogicalTerm;\r
import org.simantics.sysdyn.unitParser.nodes.Multiplication;\r
import org.simantics.sysdyn.unitParser.nodes.NamedArguments;\r
import org.simantics.sysdyn.unitParser.nodes.ParenthesisExpression;\r
private static HashMap<String, Class<?>> constructors = new HashMap<String, Class<?>>();\r
\r
static {\r
+ constructors.put("logical_expression", LogicalExpression.class);\r
+ constructors.put("logical_term", LogicalTerm.class);\r
+ constructors.put("logical_factor", LogicalFactor.class);\r
constructors.put("relation", Relation.class);\r
- constructors.put("term", Term.class);\r
+ constructors.put("term", Term.class);\r
constructors.put("factor", Factor.class);\r
constructors.put("arithmetic_expression", Arithmetic.class);\r
constructors.put("ifthenelse", IfThenElse.class);\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2014 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.unitParser.nodes;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.simantics.sysdyn.unitParser.UnitCheckingException;\r
+import org.simantics.sysdyn.unitParser.UnitCheckingNode;\r
+import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType;\r
+import org.simantics.sysdyn.utils.Function;\r
+\r
+/**\r
+ * See UnitCheckingNodeFactory for mapping\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class LogicalExpression extends UnitCheckingNode {\r
+\r
+ public LogicalExpression(int id) {\r
+ super(id);\r
+ }\r
+\r
+ @Override\r
+ public UnitResult getUnits(HashMap<String, String> units, ArrayList<Function> functions, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result;\r
+ \r
+ if (jjtGetNumChildren() == 1) {\r
+ result = ((UnitCheckingNode)jjtGetChild(0)).getUnits(units, functions, allowEquivalents);\r
+ } else {\r
+ // If the logical expression is of type logical_term or logical_term, allow\r
+ // all units as input and output unit is scalar\r
+ result = new UnitResult(allowEquivalents);\r
+ result.setUnitType(UnitType.SCALAR);\r
+ }\r
+ \r
+ return result;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2014 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.unitParser.nodes;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.simantics.sysdyn.unitParser.UnitCheckingException;\r
+import org.simantics.sysdyn.unitParser.UnitCheckingNode;\r
+import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType;\r
+import org.simantics.sysdyn.utils.Function;\r
+\r
+/**\r
+ * See UnitCheckingNodeFactory for mapping\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class LogicalFactor extends UnitCheckingNode {\r
+\r
+ public LogicalFactor(int id) {\r
+ super(id);\r
+ }\r
+\r
+ @Override\r
+ public UnitResult getUnits(HashMap<String, String> units, ArrayList<Function> functions, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result;\r
+ \r
+ if (jjtGetNumChildren() == 1) {\r
+ result = ((UnitCheckingNode)jjtGetChild(0)).getUnits(units, functions, allowEquivalents);\r
+ } else {\r
+ // If the logical factor is of type not relation, allow\r
+ // all units as input and output unit is scalar\r
+ result = new UnitResult(allowEquivalents);\r
+ result.setUnitType(UnitType.SCALAR);\r
+ }\r
+ \r
+ return result;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2014 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.unitParser.nodes;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.simantics.sysdyn.unitParser.UnitCheckingException;\r
+import org.simantics.sysdyn.unitParser.UnitCheckingNode;\r
+import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType;\r
+import org.simantics.sysdyn.utils.Function;\r
+\r
+/**\r
+ * See UnitCheckingNodeFactory for mapping\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class LogicalTerm extends UnitCheckingNode {\r
+\r
+ public LogicalTerm(int id) {\r
+ super(id);\r
+ }\r
+\r
+ @Override\r
+ public UnitResult getUnits(HashMap<String, String> units, ArrayList<Function> functions, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result;\r
+ \r
+ if (jjtGetNumChildren() == 1) {\r
+ result = ((UnitCheckingNode)jjtGetChild(0)).getUnits(units, functions, allowEquivalents);\r
+ } else {\r
+ // If the logical term is of type logical_factor and logical_factor, allow\r
+ // all units as input and output unit is scalar\r
+ result = new UnitResult(allowEquivalents);\r
+ result.setUnitType(UnitType.SCALAR);\r
+ }\r
+ \r
+ return result;\r
+ }\r
+\r
+}\r
\r
import org.simantics.sysdyn.unitParser.UnitCheckingException;\r
import org.simantics.sysdyn.unitParser.UnitCheckingNode;\r
+import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType;\r
import org.simantics.sysdyn.utils.Function;\r
\r
/**\r
UnitCheckingNode candidateNode = null;\r
\r
base = ((UnitCheckingNode)jjtGetChild(0));\r
- if(!(base instanceof Arithmetic) && jjtGetNumChildren() > 1)\r
+ if(!(base instanceof Arithmetic) && jjtGetNumChildren() > 1) {\r
base = ((UnitCheckingNode)jjtGetChild(1));\r
+ }\r
\r
if(base instanceof Arithmetic) {\r
result.appendResult(base.getUnits(units, functions, allowEquivalents));\r
operator = ((UnitCheckingNode)jjtGetChild(i-1));\r
UnitResult candidateUnits = candidateNode.getUnits(units, functions, allowEquivalents);\r
if(!result.equals(candidateUnits)) {\r
- result.equals(candidateUnits);\r
throw new UnitCheckingException("Not equals exception: " +\r
base.printNode() + " [" + result.getFullUnit() + "] " + operator.printNode() + " " +\r
candidateNode.printNode() + " [" + candidateUnits.getFullUnit() + "]"\r
);\r
}\r
}\r
-\r
}\r
+ \r
+ if (jjtGetNumChildren() > 1) {\r
+ // If there is an actual relation (e.g. a > b), the output\r
+ // unit is a scalar.\r
+ result = new UnitResult(allowEquivalents);\r
+ result.setUnitType(UnitType.SCALAR);\r
+ }\r
+\r
}\r
\r
return result;\r