]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Improved error reporting
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 2 Oct 2014 11:20:05 +0000 (11:20 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 2 Oct 2014 11:20:05 +0000 (11:20 +0000)
refs #5224

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30356 ac1ea38d-2e2b-0410-8846-a27921b304fc

12 files changed:
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Assignment.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/ExecutionException.java [new file with mode: 0644]
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Function.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Model.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Parser.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Variable.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParser.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/SimpleNode.java

index 6cdc5b83ae9fa9be1e9732e9c3ddf2768118f9b3..cb16d4b9f8b64cc28baeec70c4830fd67392e402 100644 (file)
@@ -515,7 +515,7 @@ public class Array implements IExpression {
                        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 Array) throw new ExecutionException("Array size does not match subscripts.");\r
                                if(element instanceof IExpression) {\r
                                        IExpression exp = (IExpression)element;\r
                                        return exp.evaluate(environment);\r
index 6607c19809bab7536403a1cfe8cfcec1566d4df1..67752379c360df09395883314cd46caa9e80ebdb 100644 (file)
  *******************************************************************************/\r
 package fi.semantum.sysdyn.solver;\r
 \r
-\r
 public class Assignment {\r
-       \r
+\r
+       private static final boolean VALIDATE = true;   \r
+\r
+       public IFrame model;\r
        public Variable target;\r
        public IExpression[] subscripts;\r
     public IExpression expression;\r
     public boolean assigned = false;\r
     public boolean isConstant = false;\r
     \r
-    public Assignment(Variable target, IExpression[] subscripts, IExpression expression) {\r
+    public Assignment(IFrame model, Variable target, IExpression[] subscripts, IExpression expression) {\r
+       this.model = model;\r
        this.target = target;\r
        this.subscripts = subscripts;\r
        this.expression = expression;\r
@@ -35,10 +38,46 @@ public class Assignment {
                IExpression[] subscripts2 = new IExpression[subscripts.length];\r
                for(int i=0;i<subscripts.length;i++)\r
                        subscripts2[i] = subscripts[i].withBase(frame, prefix);\r
-               return new Assignment(target.withBase(frame, prefix), subscripts2, expression.withBase(frame, prefix));\r
+               return new Assignment(frame, target.withBase(frame, prefix), subscripts2, expression.withBase(frame, prefix));\r
        } else {\r
-               return new Assignment(target.withBase(frame, prefix), null, expression.withBase(frame, prefix));\r
+               return new Assignment(frame, target.withBase(frame, prefix), null, expression.withBase(frame, prefix));\r
+       }\r
+    }\r
+    \r
+    public void assign(IEnvironment env) {\r
+       try {\r
+                       Object value = expression.evaluate(env);\r
+                       if(value != null) {\r
+                               validate(target, value);\r
+                               target.assign(env, subscripts, value);\r
+                               assigned = true;\r
+                       }\r
+       } catch (ExecutionException e) {\r
+               if(model instanceof Model) {\r
+                       throw new ExecutionException("Line " + (target.line-((Model)model).line) + ": while evaluating " + target.base.name + ": " + e.getMessage());\r
+               } else {\r
+                       throw new ExecutionException("While evaluating " + target.base.name + ": " + e.getMessage());\r
+               }\r
        }\r
     }\r
     \r
+    \r
+       private void validate(Variable var, Object value) {\r
+               if(VALIDATE) {\r
+                       if(value instanceof Double) {\r
+                               if(Double.isNaN((Double)value)) {\r
+                                       System.err.println("value is invalid (NaN): " + var.base.name);\r
+                                       throw new IllegalStateException("value is invalid (NaN)");\r
+                               }\r
+                               if(Double.isInfinite((Double)value)) {\r
+                                       System.err.println("value is invalid (Infinite): " + var.base.name);\r
+                                       throw new IllegalStateException("value is invalid (Infinite)");\r
+                               }\r
+                       }\r
+                       if(value instanceof Array) {\r
+                               for(Object o : ((Array)value).elements()) validate(var, o);\r
+                       }\r
+               }\r
+       }\r
+    \r
 }\r
diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/ExecutionException.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/ExecutionException.java
new file mode 100644 (file)
index 0000000..ebea363
--- /dev/null
@@ -0,0 +1,18 @@
+package fi.semantum.sysdyn.solver;\r
+\r
+public class ExecutionException extends RuntimeException {\r
+\r
+       private static final long serialVersionUID = 8394963990462508948L;\r
+       \r
+       public int line = -1;\r
+       \r
+       public ExecutionException(String message) {\r
+               super(message);\r
+       }\r
+\r
+       public ExecutionException(String message, int line) {\r
+               super(message);\r
+               this.line = line;\r
+       }\r
+\r
+}\r
index 9af1f4b34a0a9102c5ae9a45af4ea6662d286000..f78c04a6b68634f5811fe1fd2a54203263b87d28 100644 (file)
@@ -28,10 +28,13 @@ final public class Function implements Fn, IFrame {
        public Variable[] parameters;\r
        \r
        public ArrayList<ForIndex> indices = new ArrayList<ForIndex>();\r
+       \r
+       public int line;\r
 \r
-       public Function(String name, IStatement statement) {\r
+       public Function(String name, IStatement statement, int line) {\r
                this.name = name;\r
                this.statement = statement;\r
+               this.line = line;\r
        }\r
        \r
        public Object evaluate(IEnvironment environment, int argc) {\r
index 537d238f783bd57577f6ab4ea67b824edcc51e38..ab861d89034a5da8b5726e88d7f5a42ba512508c 100644 (file)
@@ -40,6 +40,7 @@ class Model implements IFrame {
        \r
        public final Globals globals;\r
        \r
+       public int line = -1;\r
        public String name;\r
        public boolean isEnumClass;\r
        \r
@@ -82,6 +83,16 @@ class Model implements IFrame {
                return base;\r
        }\r
        \r
+       private void reportException(Fn fn, ExecutionException e) throws ExecutionException {\r
+               \r
+               if(fn instanceof Function) {\r
+                       throw new ExecutionException("function " + name + ": " + (e.line - ((Function)fn).line) + ": " + e.getMessage());\r
+               } else {\r
+                       throw new ExecutionException("function " + name + ": " + (e.line - ((Function)fn).line) + ": " + e.getMessage());\r
+               }\r
+               \r
+       }\r
+       \r
        public Object evaluateFunction(IEnvironment environment, String name, ArgumentList args) {\r
                Fn fn = getFunction(name);\r
                if(fn == null) {\r
@@ -109,7 +120,15 @@ class Model implements IFrame {
 \r
                        fn.setLocals(frame);\r
                        \r
-                       return fn.evaluate(frame, args.args.length+1);\r
+                       try {\r
+                       \r
+                               return fn.evaluate(frame, args.args.length+1);\r
+                               \r
+                       } catch (ExecutionException e) {\r
+                               \r
+                               reportException(fn, e);\r
+                               \r
+                       }\r
                        \r
                } else {\r
                        \r
@@ -157,13 +176,24 @@ class Model implements IFrame {
                                }\r
                                \r
                                fn.setLocals(frame);\r
-                               Object value = fn.evaluate(frame, args.args.length); \r
-                               return value;\r
+                               \r
+                               try {\r
+\r
+                                       return fn.evaluate(frame, args.args.length); \r
+\r
+                               } catch (ExecutionException e) {\r
+\r
+                                       reportException(fn, e);\r
+\r
+                               }\r
                                \r
                        }\r
                        \r
                }\r
                        \r
+               // This cannot happen - reportException always throws\r
+               throw new IllegalStateException();\r
+               \r
        }\r
        \r
        private Array arrayEvaluate(Frame frame, Fn fn, Variable[] parameters, Object[] ps, boolean[] vector, List<Array> arrs) {\r
index 6560e2d148da85fe4658b615a23b68a7ea1eea8e..14c73e870c23b82eb0df8bfc28518b5e2710e2d2 100644 (file)
@@ -74,12 +74,12 @@ public class Parser {
                        IExpression exp = (IExpression)walk((SimpleNode)n.jjtGetChild(1), indent+2, frame);\r
                        if(v instanceof Derivative) {\r
                                Derivative der = (Derivative)v;\r
-                               Assignment eq = new Assignment(der.variable, der.variable.subscripts, new Derivate(der.variable, der.variable.subscripts, exp));\r
+                               Assignment eq = new Assignment(model, der.variable, der.variable.subscripts, new Derivate(der.variable, der.variable.subscripts, exp));\r
                                model.derivatives.add(eq);\r
                                return eq;\r
                        } else {\r
                                Variable var = (Variable)v;\r
-                               Assignment eq = new Assignment(var, var.subscripts, exp);\r
+                               Assignment eq = new Assignment(model, var, var.subscripts, exp);\r
                                if(model.initial)\r
                                        model.initials.add(eq);\r
                                else\r
@@ -338,18 +338,18 @@ public class Parser {
                        return subs;\r
                case declaration:\r
                        if(n.jjtGetNumChildren() == 0) {\r
-                               return new Declaration(new Variable(frame, n.op, null), null);\r
+                               return new Declaration(new Variable(frame, n.op, null, n.line), null);\r
                        } else if(n.jjtGetNumChildren() == 1) {\r
                                Object o = walk((SimpleNode)n.jjtGetChild(0), indent+2, frame);\r
                                if(o instanceof IExpression[]) {\r
-                                       return new Declaration(new Variable(frame, n.op, (IExpression[])o), null);\r
+                                       return new Declaration(new Variable(frame, n.op, (IExpression[])o, n.line), null);\r
                                } else {\r
-                                       return new Declaration(new Variable(frame, n.op, null), o);\r
+                                       return new Declaration(new Variable(frame, n.op, null, n.line), o);\r
                                }\r
                        } else if(n.jjtGetNumChildren() == 2) {\r
                                IExpression[] subscripts2 = (IExpression[])walk((SimpleNode)n.jjtGetChild(0), indent+2, frame);\r
                                Object modification = walk((SimpleNode)n.jjtGetChild(1), indent+2, frame);\r
-                               return new Declaration(new Variable(frame, n.op,subscripts2), modification);\r
+                               return new Declaration(new Variable(frame, n.op,subscripts2, n.line), modification);\r
                        } else {\r
                                StringBuilder b = new StringBuilder();\r
                                b.append("declaration: ");\r
@@ -365,8 +365,9 @@ public class Parser {
                                SimpleNode child = (SimpleNode)n.jjtGetChild(0);\r
                                String packagePath = getPackagePath(child);\r
                                String functionName = packagePath + child.op;\r
+                               System.err.println("function " + functionName + " at line " + child.line);\r
                                ArrayList<IStatement> stms2 = new ArrayList<IStatement>();\r
-                               Function function = new Function(functionName, new StatementList(stms2));\r
+                               Function function = new Function(functionName, new StatementList(stms2), child.line);\r
                                ArrayList<Object> composition = (ArrayList<Object>)walk(child, indent+2, function);\r
                                for(int i=1;i<composition.size();i++) {\r
                                        Object comp = composition.get(i);\r
@@ -411,11 +412,14 @@ public class Parser {
                                                }\r
                                        }\r
                                }\r
+                               \r
                                model.functions.put(functionName, function);\r
                                return function;\r
                                \r
                        } else if("model".equals(n.op)) {\r
 \r
+                               model.line = n.line;\r
+                               \r
                                if(n.jjtGetNumChildren() == 1) {\r
                                        return walk((SimpleNode)n.jjtGetChild(0), indent+2, frame);\r
                                } else {\r
@@ -431,8 +435,8 @@ public class Parser {
                                walk(specifier, indent+2, clazz);\r
                                \r
                                if(clazz.isEnumClass) {\r
-                                       Variable sizeVariable = new Variable(clazz, "size", null);\r
-                                       Variable elementsVariable = new Variable(clazz, "elements", new IExpression[] { new Constant(""+clazz.variables.size()) });\r
+                                       Variable sizeVariable = new Variable(clazz, "size", null, n.line);\r
+                                       Variable elementsVariable = new Variable(clazz, "elements", new IExpression[] { new Constant(""+clazz.variables.size()) }, n.line);\r
                                        clazz.parameters.add(new ParameterDeclaration(sizeVariable, sizeVariable.getPossibleConstant()));\r
                                        clazz.parameters.add(new ParameterDeclaration(elementsVariable, elementsVariable.getPossibleConstant()));\r
                                }\r
@@ -469,12 +473,12 @@ public class Parser {
                        }\r
                case component_reference:\r
                        if(n.jjtGetNumChildren() == 1) {\r
-                               return Variable.make(frame, n.op, (IExpression[])walk((SimpleNode)n.jjtGetChild(0), indent+2, frame));\r
+                               return Variable.make(frame, n.op, (IExpression[])walk((SimpleNode)n.jjtGetChild(0), indent+2, frame), n.line);\r
                        } else {\r
                                if ("time".equals(n.op)) {\r
                                        return new TimeVariable();\r
                                }\r
-                               return Variable.make(frame, n.op, null);\r
+                               return Variable.make(frame, n.op, null, n.line);\r
                        }\r
                case relation:\r
                        if(n.jjtGetNumChildren() == 3) {\r
index d66eb549b8ea846ea5c434ecb91f12623b6a5c2a..80484a5608303380faa4de56761e03b812d1fe79 100644 (file)
@@ -255,14 +255,8 @@ public class Solver {
                        \r
                        for(Assignment ass : assignments) {\r
                                try {\r
-                                       if(!ass.assigned) {\r
-                                               Object value = ass.expression.evaluate(env);\r
-                                               if(value != null) {\r
-                                                       validate(ass.target, value);\r
-                                                       ass.target.assign(env, ass.subscripts, value);\r
-                                                       ass.assigned = true;\r
-                                               }\r
-                                       }\r
+                                       if(!ass.assigned)\r
+                                               ass.assign(env);\r
                                } catch (Exception e) {\r
                                        String error = "  -" + ass.target.toString() + ": " + e.getMessage();\r
                                        if(errors != null) {\r
@@ -316,13 +310,15 @@ public class Solver {
                                Assignment[] assignments = model.assignmentArray;\r
                                for(int i=0;i<assignments.length;i++) {\r
                                        if(assignments[i].isConstant) continue;\r
-                                       Object value = assignments[i].expression.evaluate(env);\r
-                                       assignments[i].target.assign(env, assignments[i].subscripts, value);\r
+                                       assignments[i].assign(env);\r
+//                                     Object value = assignments[i].expression.evaluate(env);\r
+//                                     assignments[i].target.assign(env, assignments[i].subscripts, value);\r
                                }\r
                                for(Assignment ass : model.initials) {\r
                                        if(ass.isConstant) continue;\r
-                                       Object value = ass.expression.evaluate(env);\r
-                                       ass.target.assign(env, ass.subscripts, value);\r
+                                       ass.assign(env);\r
+//                                     Object value = ass.expression.evaluate(env);\r
+//                                     ass.target.assign(env, ass.subscripts, value);\r
                                }\r
        \r
                                for(VariableDeclaration vd : model.variables) {\r
@@ -397,8 +393,9 @@ public class Solver {
                // Next solve algebraic equations\r
                for(int i=0;i<assignments.length;i++) {\r
                        if(assignments[i].isConstant) continue;\r
-                       Object value = assignments[i].expression.evaluate(env);\r
-                       assignments[i].target.assign(env, assignments[i].subscripts, value);\r
+                       assignments[i].assign(env);\r
+//                     Object value = assignments[i].expression.evaluate(env);\r
+//                     assignments[i].target.assign(env, assignments[i].subscripts, value);\r
                }\r
 \r
        }\r
index 2f28d4b89bc828d11394b6917dbbde138927d4c1..fe222fc86bbbf5b79186ef20c6a0502e94ac708d 100644 (file)
@@ -19,18 +19,20 @@ public class Variable implements IExpression {
 \r
        public VariableBase base;\r
        public IExpression[] subscripts = null;\r
+       public int line = -1;\r
        \r
-       public Variable(IFrame frame, String name, IExpression[] subscripts) {\r
+       public Variable(IFrame frame, String name, IExpression[] subscripts, int line) {\r
                base = frame.getBase(name);\r
                this.subscripts = subscripts;\r
+               this.line = line;\r
        }\r
        \r
-       public static Object make(IFrame frame, String name, IExpression[] subscripts) {\r
+       public static Object make(IFrame frame, String name, IExpression[] subscripts, int line) {\r
 //             Array enumElements = enumerationElements(frame, name);\r
 //             if(enumElements != null) return enumElements;\r
 //             Constant enumSize = enumerationSize(frame, name);\r
 //             if(enumSize != null) return enumSize;\r
-               return new Variable(frame, name, subscripts);\r
+               return new Variable(frame, name, subscripts, line);\r
        }\r
        \r
        public Variable(VariableBase base) {\r
@@ -203,9 +205,17 @@ public class Variable implements IExpression {
        @Override\r
        public Object evaluate(IEnvironment environment) {\r
                \r
-               if(constantIndex == -2) constantIndex = base.getConstantIndex(environment, subscripts);\r
+               try {\r
                \r
-               return base.evaluate(environment, subscripts, constantIndex);\r
+                       if(constantIndex == -2) constantIndex = base.getConstantIndex(environment, subscripts);\r
+                       \r
+                       return base.evaluate(environment, subscripts, constantIndex);\r
+                       \r
+               } catch (ExecutionException e) {\r
+                       \r
+                       throw new ExecutionException(base.name + ": " + e.getMessage(), line);\r
+                       \r
+               }\r
                \r
        }\r
 \r
index bcd1d520d1cc1c2385e85fc0839513c8274fa2c0..b1101a81cba1fa497b44c1d7807555402b3d6bda 100644 (file)
@@ -166,9 +166,9 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo
 /*** Class Definition **********************************************/\r
   final public void class_definition() throws ParseException {\r
                            /*@bgen(jjtree) class_definition */\r
-  SimpleNode jjtn000 = new SimpleNode(JJTCLASS_DEFINITION);\r
-  boolean jjtc000 = true;\r
-  jjtree.openNodeScope(jjtn000);\r
+                            SimpleNode jjtn000 = new SimpleNode(JJTCLASS_DEFINITION);\r
+                            boolean jjtc000 = true;\r
+                            jjtree.openNodeScope(jjtn000);Token t;\r
     try {\r
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {\r
       case 30:\r
@@ -192,8 +192,8 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo
                 jjtn000.op = "class";\r
         break;\r
       case 7:\r
-        jj_consume_token(7);\r
-                                                    jjtn000.op = "model";\r
+        t = jj_consume_token(7);\r
+                                                        jjtn000.op = "model"; jjtn000.line = t.beginLine;\r
         break;\r
       case 61:\r
         jj_consume_token(61);\r
@@ -268,7 +268,7 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo
     try {\r
       if (jj_2_1(2)) {\r
         t = jj_consume_token(IDENT);\r
-                             jjtn000.op = t.image;\r
+                             jjtn000.op = t.image; jjtn000.line = t.beginLine;\r
         string_comment();\r
         composition();\r
         jj_consume_token(35);\r
@@ -1403,7 +1403,7 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo
     Parameter ret = new Parameter();\r
     try {\r
       jj_consume_token(IDENT);\r
-                  ret.name = new String(token.image); jjtn000.op = token.image;\r
+                  ret.name = new String(token.image); jjtn000.op = token.image; jjtn000.line = token.beginLine;\r
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {\r
       case 66:\r
         array_subscripts();\r
@@ -4047,7 +4047,7 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo
         ;\r
       }\r
       t = jj_consume_token(IDENT);\r
-                             jjtn000.op = t.image;\r
+                             jjtn000.op = t.image; jjtn000.line = t.beginLine;\r
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {\r
       case 66:\r
         array_subscripts();\r
@@ -5204,6 +5204,14 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo
     return false;\r
   }\r
 \r
+  private boolean jj_3R_107() {\r
+    Token xsp;\r
+    xsp = jj_scanpos;\r
+    if (jj_scan_token(50)) jj_scanpos = xsp;\r
+    if (jj_scan_token(44)) return true;\r
+    return false;\r
+  }\r
+\r
   private boolean jj_3R_66() {\r
     if (jj_3R_80()) return true;\r
     return false;\r
@@ -5293,14 +5301,6 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo
     return false;\r
   }\r
 \r
-  private boolean jj_3R_107() {\r
-    Token xsp;\r
-    xsp = jj_scanpos;\r
-    if (jj_scan_token(50)) jj_scanpos = xsp;\r
-    if (jj_scan_token(44)) return true;\r
-    return false;\r
-  }\r
-\r
   private boolean jj_3R_84() {\r
     Token xsp;\r
     xsp = jj_scanpos;\r
@@ -5524,6 +5524,12 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo
     return false;\r
   }\r
 \r
+  private boolean jj_3R_165() {\r
+    if (jj_scan_token(68)) return true;\r
+    if (jj_scan_token(IDENT)) return true;\r
+    return false;\r
+  }\r
+\r
   private boolean jj_3R_58() {\r
     if (jj_scan_token(IDENT)) return true;\r
     if (jj_3R_74()) return true;\r
@@ -5587,9 +5593,8 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo
     return false;\r
   }\r
 \r
-  private boolean jj_3R_165() {\r
-    if (jj_scan_token(68)) return true;\r
-    if (jj_scan_token(IDENT)) return true;\r
+  private boolean jj_3R_164() {\r
+    if (jj_3R_170()) return true;\r
     return false;\r
   }\r
 \r
@@ -5663,11 +5668,6 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo
     return false;\r
   }\r
 \r
-  private boolean jj_3R_164() {\r
-    if (jj_3R_170()) return true;\r
-    return false;\r
-  }\r
-\r
   private boolean jj_3R_48() {\r
     Token xsp;\r
     xsp = jj_scanpos;\r
index 3f9084834011988743fbcda3566674c6d10aaa8d..d5f57adb877ac32bbe64832bbc07c51cb4e90207 100644 (file)
@@ -177,10 +177,10 @@ Node stored_definition()         : {/*@bgen(jjtree) STORED */
 /*** Class Definition **********************************************/\r
   \r
 void class_definition() : {/*@bgen(jjtree) class_definition */\r
-  SimpleNode jjtn000 = new SimpleNode(JJTCLASS_DEFINITION);\r
-  boolean jjtc000 = true;\r
-  jjtree.openNodeScope(jjtn000);\r
-/*@egen*/\r
+                            SimpleNode jjtn000 = new SimpleNode(JJTCLASS_DEFINITION);\r
+                            boolean jjtc000 = true;\r
+                            jjtree.openNodeScope(jjtn000);\r
+/*@egen*/ Token t;\r
 } {/*@bgen(jjtree) class_definition */\r
     try {\r
 /*@egen*/\r
@@ -192,7 +192,7 @@ void class_definition() : {/*@bgen(jjtree) class_definition */
 //  class_specifier\r
     ( "encapsulated" )?\r
     ( "partial" )?\r
-    ( "class" { jjtn000.op = "class"; } | "model" { jjtn000.op = "model"; } | "record" | "block" | ( "expandable" )? "connector" | "type" |\r
+    ( "class" { jjtn000.op = "class"; } | t = "model" { jjtn000.op = "model"; jjtn000.line = t.beginLine; } | "record" | "block" | ( "expandable" )? "connector" | "type" |\r
     "package" { jjtn000.op = "package"; } | "function" { jjtn000.op = "function"; } | "operator" | "operator function" | "operator record" )\r
     class_specifier()/*@bgen(jjtree)*/\r
     } catch (Throwable jjte000) {\r
@@ -234,7 +234,7 @@ void class_specifier() : {/*@bgen(jjtree) class_specifier */
 //  | IDENT "=" der "(" name "," IDENT { "," IDENT } ")" comment\r
 //  | extends IDENT [ class_modification ] string_comment composition\r
 //  end IDENT  \r
-    LOOKAHEAD(2) t=<IDENT> { jjtn000.op = t.image; } string_comment() composition() "end" <IDENT>\r
+    LOOKAHEAD(2) t=<IDENT> { jjtn000.op = t.image; jjtn000.line = t.beginLine; } string_comment() composition() "end" <IDENT>\r
     | LOOKAHEAD(2) <IDENT> "=" base_prefix() name() ( array_subscripts() )? ( class_modification() )? comment()\r
     | LOOKAHEAD(3)  <IDENT> "=" "der" "(" name() "," <IDENT> ( "," <IDENT> )* ")" comment()\r
     | LOOKAHEAD(3) <IDENT> "=" "enumeration" "(" ( ( enum_list() )? | ":" ) ")" comment()/*@bgen(jjtree)*/\r
@@ -924,7 +924,7 @@ Parameter declaration() : {/*@bgen(jjtree) declaration */
         try {\r
 /*@egen*/\r
 //     IDENT [ array_subscripts ] [ modification ]\r
-       <IDENT> { ret.name = new String(token.image); jjtn000.op = token.image; }\r
+       <IDENT> { ret.name = new String(token.image); jjtn000.op = token.image; jjtn000.line = token.beginLine; }\r
        ( array_subscripts() )?\r
        ( ret.optional = modification() )?/*@bgen(jjtree)*/\r
         {\r
@@ -2643,7 +2643,7 @@ void component_reference() : {/*@bgen(jjtree) component_reference */
         try {\r
 /*@egen*/\r
 //     [ "." ] IDENT [ array_subscripts ] { "." IDENT [ array_subscripts ] }\r
-       ( "." )? t=<IDENT> { jjtn000.op = t.image; } ( array_subscripts() )? ( "." <IDENT> ( array_subscripts() )? )*/*@bgen(jjtree)*/\r
+       ( "." )? t=<IDENT> { jjtn000.op = t.image; jjtn000.line = t.beginLine; } ( array_subscripts() )? ( "." <IDENT> ( array_subscripts() )? )*/*@bgen(jjtree)*/\r
         } catch (Throwable jjte000) {\r
           if (jjtc000) {\r
             jjtree.clearNodeScope(jjtn000);\r
index b4231401e04f5489713f52e9a3117b34fa1f0216..87103388fce5d648059b3ae03f9cf3b052d80475 100644 (file)
@@ -110,7 +110,7 @@ Node stored_definition() #STORED : {
 \r
 /*** Class Definition **********************************************/\r
   \r
-void class_definition() : {\r
+void class_definition() : { Token t;\r
 } {\r
 //  class_definition :\r
 //  [ encapsulated ]\r
@@ -120,7 +120,7 @@ void class_definition() : {
 //  class_specifier\r
     ( "encapsulated" )?\r
     ( "partial" )?\r
-    ( "class" { jjtThis.op = "class"; } | "model" { jjtThis.op = "model"; } | "record" | "block" | ( "expandable" )? "connector" | "type" |\r
+    ( "class" { jjtThis.op = "class"; } | t = "model" { jjtThis.op = "model"; jjtThis.line = t.beginLine; } | "record" | "block" | ( "expandable" )? "connector" | "type" |\r
     "package" { jjtThis.op = "package"; } | "function" { jjtThis.op = "function"; } | "operator" | "operator function" | "operator record" )\r
     class_specifier()\r
 }\r
@@ -136,7 +136,7 @@ void class_specifier() : { Token t;
 //  | IDENT "=" der "(" name "," IDENT { "," IDENT } ")" comment\r
 //  | extends IDENT [ class_modification ] string_comment composition\r
 //  end IDENT  \r
-    LOOKAHEAD(2) t=<IDENT> { jjtThis.op = t.image; } string_comment() composition() "end" <IDENT>\r
+    LOOKAHEAD(2) t=<IDENT> { jjtThis.op = t.image; jjtThis.line = t.beginLine; } string_comment() composition() "end" <IDENT>\r
     | LOOKAHEAD(2) <IDENT> "=" base_prefix() name() ( array_subscripts() )? ( class_modification() )? comment()\r
     | LOOKAHEAD(3)  <IDENT> "=" "der" "(" name() "," <IDENT> ( "," <IDENT> )* ")" comment()\r
     | LOOKAHEAD(3) <IDENT> "=" "enumeration" "(" ( ( enum_list() )? | ":" ) ")" comment()\r
@@ -320,7 +320,7 @@ Parameter declaration() : { Token t;
     Parameter ret = new Parameter();\r
 } {\r
 //     IDENT [ array_subscripts ] [ modification ]\r
-       <IDENT> { ret.name = new String(token.image); jjtThis.op = token.image; }\r
+       <IDENT> { ret.name = new String(token.image); jjtThis.op = token.image; jjtThis.line = token.beginLine; }\r
        ( array_subscripts() )?\r
        ( ret.optional = modification() )?\r
        {\r              return ret;\r    }\r
@@ -710,7 +710,7 @@ void component_reference() : {
   Token t;\r
 } {\r
 //     [ "." ] IDENT [ array_subscripts ] { "." IDENT [ array_subscripts ] }\r
-       ( "." )? t=<IDENT> { jjtThis.op = t.image; } ( array_subscripts() )? ( "." <IDENT> ( array_subscripts() )? )*\r
+       ( "." )? t=<IDENT> { jjtThis.op = t.image; jjtThis.line = t.beginLine; } ( array_subscripts() )? ( "." <IDENT> ( array_subscripts() )? )*\r
 }\r
 \r
 void function_call_args() : {\r
index b399a88f63cd2742b635f088940c3db98e56d496..4a12bf77a95b09db01ea3b49d549bb9170dcf98f 100644 (file)
@@ -11,6 +11,7 @@ class SimpleNode implements Node {
   protected Object value;\r
   protected ModelParser parser;\r
   \r
+  public int line = -1;\r
   public String op;\r
 \r
   public SimpleNode(int i) {\r