From 35dd14213886c4a251b04261a69d34cb8fd38622 Mon Sep 17 00:00:00 2001 From: villberg Date: Tue, 24 Jun 2014 11:03:27 +0000 Subject: [PATCH] refs #5009 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29718 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../fi/semantum/sysdyn/solver/NodeClass.java | 1 + .../src/fi/semantum/sysdyn/solver/Parser.java | 20 +- .../sysdyn/solver/parser/ModelParser.java | 266 +++++++++--------- .../sysdyn/solver/parser/ModelicaParser.jj | 2 +- .../sysdyn/solver/parser/ModelicaParser.jjt | 2 +- 5 files changed, 158 insertions(+), 133 deletions(-) diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NodeClass.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NodeClass.java index 81b86df7..532c053a 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NodeClass.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NodeClass.java @@ -36,6 +36,7 @@ public enum NodeClass { array_subscripts, declaration, class_definition, + class_specifier, array, primary, component_reference, diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Parser.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Parser.java index bd6fc87d..5bc59bce 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Parser.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Parser.java @@ -40,6 +40,17 @@ public class Parser { static Map nodeNameMap = new HashMap(); + public String getPackagePath(SimpleNode n) { + SimpleNode parent = (SimpleNode)n.jjtGetParent(); + if(parent == null) return ""; + NodeClass nc = NodeClass.of(parent.toString()); + if (nc == NodeClass.class_specifier) { + return getPackagePath(parent) + parent.op + "."; + } else { + return getPackagePath(parent); + } + } + public Object walk_(SimpleNode n, int indent, IFrame frame) { Model model = frame instanceof Model ? (Model)frame : null; @@ -318,10 +329,13 @@ public class Parser { } return b.toString(); } + case class_specifier: + return walk((SimpleNode)n.jjtGetChild(0), indent+2, frame); case class_definition: if("function".equals(n.op)) { SimpleNode child = (SimpleNode)n.jjtGetChild(0); - String functionName = child.op; + String packagePath = getPackagePath(child); + String functionName = packagePath + child.op; ArrayList stms2 = new ArrayList(); Function function = new Function(functionName, new StatementList(stms2)); ArrayList composition = (ArrayList)walk(child, indent+2, function); @@ -392,6 +406,10 @@ public class Parser { return null; + } else if("package".equals(n.op)) { + + return walk((SimpleNode)n.jjtGetChild(0), indent+2, frame); + } else { System.err.println("class_definition " + n.op); } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParser.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParser.java index de6a2b25..c50c6058 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParser.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParser.java @@ -218,10 +218,11 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo break; case 37: jj_consume_token(37); + jjtn000.op = "package"; break; case 26: jj_consume_token(26); - jjtn000.op = "function"; + jjtn000.op = "function"; break; case 17: jj_consume_token(17); @@ -4658,31 +4659,31 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo if (jj_scan_token(62)) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_166()) jj_scanpos = xsp; + if (jj_3R_167()) jj_scanpos = xsp; if (jj_scan_token(63)) return true; return false; } - private boolean jj_3R_129() { + private boolean jj_3R_130() { if (jj_scan_token(49)) return true; return false; } - private boolean jj_3R_124() { + private boolean jj_3R_125() { if (jj_scan_token(75)) return true; return false; } - private boolean jj_3R_153() { + private boolean jj_3R_154() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(68)) jj_scanpos = xsp; if (jj_scan_token(IDENT)) return true; xsp = jj_scanpos; - if (jj_3R_161()) jj_scanpos = xsp; + if (jj_3R_162()) jj_scanpos = xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_162()) { jj_scanpos = xsp; break; } + if (jj_3R_163()) { jj_scanpos = xsp; break; } } return false; } @@ -4693,7 +4694,7 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_159() { + private boolean jj_3R_160() { if (jj_scan_token(58)) return true; return false; } @@ -4703,7 +4704,7 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_150() { + private boolean jj_3R_151() { if (jj_scan_token(84)) return true; return false; } @@ -4739,55 +4740,53 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_123() { + private boolean jj_3R_124() { if (jj_scan_token(74)) return true; return false; } - private boolean jj_3R_146() { - if (jj_3R_155()) return true; + private boolean jj_3R_147() { + if (jj_3R_156()) return true; return false; } - private boolean jj_3R_164() { + private boolean jj_3R_165() { if (jj_scan_token(70)) return true; return false; } - private boolean jj_3R_145() { + private boolean jj_3R_146() { if (jj_scan_token(66)) return true; - if (jj_3R_154()) return true; + if (jj_3R_155()) return true; if (jj_scan_token(67)) return true; return false; } - private boolean jj_3R_144() { + private boolean jj_3R_145() { if (jj_scan_token(62)) return true; if (jj_3R_47()) return true; if (jj_scan_token(63)) return true; return false; } - private boolean jj_3R_142() { - if (jj_3R_152()) return true; + private boolean jj_3R_143() { + if (jj_3R_153()) return true; return false; } - private boolean jj_3R_157() { + private boolean jj_3R_158() { if (jj_scan_token(87)) return true; return false; } - private boolean jj_3R_143() { - if (jj_3R_153()) return true; + private boolean jj_3R_144() { + if (jj_3R_154()) return true; return false; } - private boolean jj_3R_134() { + private boolean jj_3R_135() { Token xsp; xsp = jj_scanpos; - if (jj_3R_137()) { - jj_scanpos = xsp; if (jj_3R_138()) { jj_scanpos = xsp; if (jj_3R_139()) { @@ -4806,6 +4805,8 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo jj_scanpos = xsp; if (jj_3R_146()) { jj_scanpos = xsp; + if (jj_3R_147()) { + jj_scanpos = xsp; if (jj_scan_token(35)) return true; } } @@ -4820,182 +4821,182 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_137() { + private boolean jj_3R_138() { if (jj_scan_token(UNSIGNED_NUMBER)) return true; return false; } - private boolean jj_3R_141() { + private boolean jj_3R_142() { if (jj_scan_token(33)) return true; return false; } - private boolean jj_3R_140() { + private boolean jj_3R_141() { if (jj_scan_token(6)) return true; return false; } - private boolean jj_3R_139() { + private boolean jj_3R_140() { if (jj_scan_token(STRING)) return true; return false; } - private boolean jj_3R_138() { + private boolean jj_3R_139() { if (jj_scan_token(UNSIGNED_INTEGER)) return true; return false; } - private boolean jj_3R_149() { + private boolean jj_3R_150() { if (jj_scan_token(83)) return true; return false; } - private boolean jj_3R_128() { + private boolean jj_3R_129() { if (jj_scan_token(42)) return true; return false; } - private boolean jj_3R_155() { + private boolean jj_3R_156() { if (jj_scan_token(64)) return true; - if (jj_3R_165()) return true; + if (jj_3R_166()) return true; if (jj_scan_token(65)) return true; return false; } - private boolean jj_3R_135() { - if (jj_3R_147()) return true; - if (jj_3R_134()) return true; + private boolean jj_3R_136() { + if (jj_3R_148()) return true; + if (jj_3R_135()) return true; return false; } - private boolean jj_3R_154() { - if (jj_3R_163()) return true; + private boolean jj_3R_155() { + if (jj_3R_164()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_164()) { jj_scanpos = xsp; break; } + if (jj_3R_165()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_158() { + private boolean jj_3R_159() { if (jj_3R_60()) return true; return false; } - private boolean jj_3R_133() { + private boolean jj_3R_134() { if (jj_scan_token(79)) return true; return false; } - private boolean jj_3R_152() { + private boolean jj_3R_153() { Token xsp; xsp = jj_scanpos; - if (jj_3R_158()) { - jj_scanpos = xsp; if (jj_3R_159()) { jj_scanpos = xsp; - if (jj_3R_160()) return true; + if (jj_3R_160()) { + jj_scanpos = xsp; + if (jj_3R_161()) return true; } } if (jj_3R_74()) return true; return false; } - private boolean jj_3R_122() { + private boolean jj_3R_123() { if (jj_scan_token(73)) return true; return false; } - private boolean jj_3R_147() { + private boolean jj_3R_148() { Token xsp; xsp = jj_scanpos; - if (jj_3R_156()) { + if (jj_3R_157()) { jj_scanpos = xsp; - if (jj_3R_157()) return true; + if (jj_3R_158()) return true; } return false; } - private boolean jj_3R_156() { + private boolean jj_3R_157() { if (jj_scan_token(86)) return true; return false; } - private boolean jj_3R_119() { - if (jj_3R_134()) return true; + private boolean jj_3R_120() { + if (jj_3R_135()) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_135()) jj_scanpos = xsp; + if (jj_3R_136()) jj_scanpos = xsp; return false; } - private boolean jj_3R_120() { - if (jj_3R_136()) return true; - if (jj_3R_119()) return true; + private boolean jj_3R_121() { + if (jj_3R_137()) return true; + if (jj_3R_120()) return true; return false; } private boolean jj_3R_104() { - if (jj_3R_114()) return true; + if (jj_3R_115()) return true; if (jj_3R_103()) return true; return false; } - private boolean jj_3R_113() { - if (jj_3R_118()) return true; - if (jj_3R_112()) return true; + private boolean jj_3R_114() { + if (jj_3R_119()) return true; + if (jj_3R_113()) return true; return false; } - private boolean jj_3R_136() { + private boolean jj_3R_137() { Token xsp; xsp = jj_scanpos; - if (jj_3R_148()) { - jj_scanpos = xsp; if (jj_3R_149()) { jj_scanpos = xsp; if (jj_3R_150()) { jj_scanpos = xsp; - if (jj_3R_151()) return true; + if (jj_3R_151()) { + jj_scanpos = xsp; + if (jj_3R_152()) return true; } } } return false; } - private boolean jj_3R_148() { + private boolean jj_3R_149() { if (jj_scan_token(82)) return true; return false; } - private boolean jj_3R_110() { + private boolean jj_3R_111() { if (jj_3R_60()) return true; return false; } - private boolean jj_3R_112() { - if (jj_3R_119()) return true; + private boolean jj_3R_113() { + if (jj_3R_120()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_120()) { jj_scanpos = xsp; break; } + if (jj_3R_121()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_131() { + private boolean jj_3R_132() { if (jj_scan_token(56)) return true; return false; } - private boolean jj_3R_118() { + private boolean jj_3R_119() { Token xsp; xsp = jj_scanpos; - if (jj_3R_132()) { - jj_scanpos = xsp; if (jj_3R_133()) { jj_scanpos = xsp; + if (jj_3R_134()) { + jj_scanpos = xsp; if (jj_scan_token(80)) { jj_scanpos = xsp; if (jj_scan_token(81)) return true; @@ -5005,7 +5006,7 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_132() { + private boolean jj_3R_133() { if (jj_scan_token(78)) return true; return false; } @@ -5016,40 +5017,40 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_117() { + private boolean jj_3R_118() { Token xsp; xsp = jj_scanpos; - if (jj_3R_130()) { + if (jj_3R_131()) { jj_scanpos = xsp; - if (jj_3R_131()) return true; + if (jj_3R_132()) return true; } return false; } - private boolean jj_3R_130() { + private boolean jj_3R_131() { if (jj_scan_token(32)) return true; return false; } - private boolean jj_3R_111() { - if (jj_3R_118()) return true; + private boolean jj_3R_112() { + if (jj_3R_119()) return true; return false; } - private boolean jj_3R_116() { + private boolean jj_3R_117() { Token xsp; xsp = jj_scanpos; - if (jj_3R_127()) { - jj_scanpos = xsp; if (jj_3R_128()) { jj_scanpos = xsp; - if (jj_3R_129()) return true; + if (jj_3R_129()) { + jj_scanpos = xsp; + if (jj_3R_130()) return true; } } return false; } - private boolean jj_3R_127() { + private boolean jj_3R_128() { if (jj_scan_token(5)) return true; return false; } @@ -5057,16 +5058,16 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo private boolean jj_3R_103() { Token xsp; xsp = jj_scanpos; - if (jj_3R_111()) jj_scanpos = xsp; - if (jj_3R_112()) return true; + if (jj_3R_112()) jj_scanpos = xsp; + if (jj_3R_113()) return true; while (true) { xsp = jj_scanpos; - if (jj_3R_113()) { jj_scanpos = xsp; break; } + if (jj_3R_114()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_115() { + private boolean jj_3R_116() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(16)) { @@ -5076,11 +5077,9 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_114() { + private boolean jj_3R_115() { Token xsp; xsp = jj_scanpos; - if (jj_3R_121()) { - jj_scanpos = xsp; if (jj_3R_122()) { jj_scanpos = xsp; if (jj_3R_123()) { @@ -5089,7 +5088,9 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo jj_scanpos = xsp; if (jj_3R_125()) { jj_scanpos = xsp; - if (jj_3R_126()) return true; + if (jj_3R_126()) { + jj_scanpos = xsp; + if (jj_3R_127()) return true; } } } @@ -5098,7 +5099,7 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_121() { + private boolean jj_3R_122() { if (jj_scan_token(72)) return true; return false; } @@ -5115,14 +5116,14 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_109() { + private boolean jj_3R_110() { Token xsp; xsp = jj_scanpos; - if (jj_3R_115()) jj_scanpos = xsp; - xsp = jj_scanpos; if (jj_3R_116()) jj_scanpos = xsp; xsp = jj_scanpos; if (jj_3R_117()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_118()) jj_scanpos = xsp; return false; } @@ -5191,8 +5192,8 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo } private boolean jj_3R_102() { - if (jj_3R_109()) return true; if (jj_3R_110()) return true; + if (jj_3R_111()) return true; return false; } @@ -5399,6 +5400,11 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } + private boolean jj_3R_109() { + if (jj_scan_token(26)) return true; + return false; + } + private boolean jj_3R_106() { if (jj_scan_token(7)) return true; return false; @@ -5438,13 +5444,13 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_108() { - if (jj_scan_token(26)) return true; + private boolean jj_3R_105() { + if (jj_scan_token(34)) return true; return false; } - private boolean jj_3R_105() { - if (jj_scan_token(34)) return true; + private boolean jj_3R_108() { + if (jj_scan_token(37)) return true; return false; } @@ -5467,10 +5473,10 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo jj_scanpos = xsp; if (jj_scan_token(38)) { jj_scanpos = xsp; - if (jj_scan_token(37)) { - jj_scanpos = xsp; if (jj_3R_108()) { jj_scanpos = xsp; + if (jj_3R_109()) { + jj_scanpos = xsp; if (jj_scan_token(17)) { jj_scanpos = xsp; if (jj_scan_token(95)) { @@ -5531,7 +5537,7 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_173() { + private boolean jj_3R_174() { if (jj_3R_47()) return true; return false; } @@ -5563,7 +5569,7 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_162() { + private boolean jj_3R_163() { if (jj_scan_token(68)) return true; if (jj_scan_token(IDENT)) return true; return false; @@ -5601,7 +5607,7 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_126() { + private boolean jj_3R_127() { if (jj_scan_token(77)) return true; return false; } @@ -5619,28 +5625,28 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_172() { + private boolean jj_3R_173() { if (jj_scan_token(69)) return true; return false; } - private boolean jj_3R_168() { + private boolean jj_3R_169() { if (jj_scan_token(71)) return true; return false; } - private boolean jj_3R_170() { + private boolean jj_3R_171() { Token xsp; xsp = jj_scanpos; - if (jj_3R_172()) { + if (jj_3R_173()) { jj_scanpos = xsp; - if (jj_3R_173()) return true; + if (jj_3R_174()) return true; } return false; } - private boolean jj_3R_161() { - if (jj_3R_167()) return true; + private boolean jj_3R_162() { + if (jj_3R_168()) return true; return false; } @@ -5659,50 +5665,50 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_167() { + private boolean jj_3R_168() { if (jj_scan_token(66)) return true; - if (jj_3R_170()) return true; + if (jj_3R_171()) return true; return false; } - private boolean jj_3R_125() { + private boolean jj_3R_126() { if (jj_scan_token(76)) return true; return false; } - private boolean jj_3R_163() { + private boolean jj_3R_164() { if (jj_3R_47()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_168()) { jj_scanpos = xsp; break; } + if (jj_3R_169()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_174() { + private boolean jj_3R_175() { if (jj_scan_token(IDENT)) return true; if (jj_scan_token(88)) return true; return false; } - private boolean jj_3R_160() { + private boolean jj_3R_161() { if (jj_scan_token(46)) return true; return false; } - private boolean jj_3R_171() { - if (jj_3R_174()) return true; + private boolean jj_3R_172() { + if (jj_3R_175()) return true; return false; } - private boolean jj_3R_151() { + private boolean jj_3R_152() { if (jj_scan_token(85)) return true; return false; } - private boolean jj_3R_169() { - if (jj_3R_171()) return true; + private boolean jj_3R_170() { + if (jj_3R_172()) return true; return false; } @@ -5714,18 +5720,18 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo return false; } - private boolean jj_3R_165() { + private boolean jj_3R_166() { Token xsp; xsp = jj_scanpos; if (jj_3_10()) { jj_scanpos = xsp; - if (jj_3R_169()) return true; + if (jj_3R_170()) return true; } return false; } - private boolean jj_3R_166() { - if (jj_3R_165()) return true; + private boolean jj_3R_167() { + if (jj_3R_166()) return true; return false; } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj index 839340c8..6c8fb791 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj @@ -193,7 +193,7 @@ void class_definition() : {/*@bgen(jjtree) class_definition */ ( "encapsulated" )? ( "partial" )? ( "class" { jjtn000.op = "class"; } | "model" { jjtn000.op = "model"; } | "record" | "block" | ( "expandable" )? "connector" | "type" | - "package" | "function" { jjtn000.op = "function"; } | "operator" | "operator function" | "operator record" ) + "package" { jjtn000.op = "package"; } | "function" { jjtn000.op = "function"; } | "operator" | "operator function" | "operator record" ) class_specifier()/*@bgen(jjtree)*/ } catch (Throwable jjte000) { if (jjtc000) { diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt index c65900fd..977d83d7 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt @@ -121,7 +121,7 @@ void class_definition() : { ( "encapsulated" )? ( "partial" )? ( "class" { jjtThis.op = "class"; } | "model" { jjtThis.op = "model"; } | "record" | "block" | ( "expandable" )? "connector" | "type" | - "package" | "function" { jjtThis.op = "function"; } | "operator" | "operator function" | "operator record" ) + "package" { jjtThis.op = "package"; } | "function" { jjtThis.op = "function"; } | "operator" | "operator function" | "operator record" ) class_specifier() } -- 2.47.1