fixes
[oweals/gnunet.git] / src / monkey / seaspider / org / gnunet / seaspider / ExpressionExtractorVisitor.java
index ea3294e2e7b5e1787d236cb335afcc44acd0962f..b93b19d3d7b43fcc8c6bf9e834766958fb06bafa 100644 (file)
@@ -106,25 +106,42 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
 
        public void visit(InitDeclaratorList n) {
                assert skip_mode == true;
-               super.visit (n);                
+               super.visit(n);
                assert skip_mode == true;
        }
-       
+
        public void visit(Initializer n) {
                assert skip_mode == true;
-               super.visit (n);                
+               if (n.f0.which == 0) {
+                       boolean old_mode = skip_mode;
+                       skip_mode = false;
+                       ExpressionBuilder old = current_expression;
+                       current_expression = new ExpressionBuilder();
+                       n.f0.accept(this);
+                       LineNumberInfo lin = LineNumberInfo.get(n);
+                       if (old != null) {
+                               old.push(current_expression.expression);
+                               old.commit(lin.lineEnd);
+                       } else {
+                               current_expression.commit(lin.lineEnd);
+                       }                       
+                       current_expression = old;
+                       skip_mode = old_mode;
+               } else {
+                       super.visit(n);
+               }
                assert skip_mode == true;
        }
 
        public void visit(InitializerList n) {
                assert skip_mode == true;
-               super.visit (n);                
+               super.visit(n);
                assert skip_mode == true;
        }
-       
+
        public void visit(VariableDeclaration n) {
                assert skip_mode == true;
-               super.visit (n);
+               super.visit(n);
        }
 
        public void visit(FunctionDeclaration n) {
@@ -142,8 +159,7 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
        public void visit(ParameterDeclaration n) {
                skip_mode = false;
                assert current_expression == null;
-               if (n.f1.present())
-               {
+               if (n.f1.present()) {
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        Node var = ns.elementAt(0);
                        current_expression = new ExpressionBuilder();
@@ -284,28 +300,41 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                }
                old.push(current_expression.expression);
                current_expression = old;
-       }
-
-       public void visit(AssignmentExpression n) {
-               boolean old_mode = skip_mode;
-               skip_mode = false;
-               ExpressionBuilder old = current_expression;
-               current_expression = new ExpressionBuilder();
-               n.f0.accept(this);
-               if (old != null) {
-                       old.push(current_expression.expression);
-                       LineNumberInfo lin = LineNumberInfo.get(n);
-                       old.commit(lin.lineEnd);
-               }
-               current_expression = old;
-               skip_mode = old_mode;
-       }
-
+       }       
+       
        public void visit(AssignmentOperator n) {
                operator = true;
                super.visit(n);
                operator = false;
        }
+       
+       public void visit(AssignmentExpression n)
+       {
+               if (0 == n.f0.which)
+               {
+                       NodeSequence ns = (NodeSequence) n.f0.choice;
+                       UnaryExpression u = (UnaryExpression) ns.elementAt(0);
+                       AssignmentOperator ao = (AssignmentOperator) ns.elementAt(1);
+                       AssignmentExpression ae = (AssignmentExpression) ns.elementAt(2);
+                       LineNumberInfo lin = LineNumberInfo.get(n);
+
+                       ExpressionBuilder old = current_expression;
+                       current_expression = new ExpressionBuilder();
+                       u.accept(this);
+                       current_expression.commit(lin.lineEnd);
+                       ao.accept (this);
+                       old.push(current_expression.expression);
+                       current_expression = new ExpressionBuilder();
+                       ae.accept(this);
+                       current_expression.commit(lin.lineEnd);
+                       old.push(current_expression.expression);
+                       current_expression = old;
+               }
+               else
+               {
+                       n.f0.choice.accept (this);
+               }
+       }
 
        public void visit(ConditionalExpression n) {
                ExpressionBuilder old = current_expression;
@@ -313,16 +342,18 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                n.f0.accept(this);
                old.push(current_expression.expression);
                if (n.f1.present()) {
+                       LineNumberInfo lin = LineNumberInfo.get(n);
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        current_expression = new ExpressionBuilder();
                        ns.elementAt(1).accept(this);
+                       current_expression.commit(lin.lineEnd);
                        old.push("?");
                        old.push(current_expression.expression);
                        current_expression = new ExpressionBuilder();
                        ns.elementAt(3).accept(this);
+                       current_expression.commit(lin.lineEnd);
                        old.push(":");
                        old.push(current_expression.expression);
-                       LineNumberInfo lin = LineNumberInfo.get(n);
                        old.commit(lin.lineEnd);
                }
                current_expression = old;
@@ -338,11 +369,16 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                current_expression = new ExpressionBuilder();
                n.f0.accept(this);
                if (n.f1.present()) {
+                       LineNumberInfo lin = LineNumberInfo.get(n);
+                       current_expression.commit(lin.lineEnd);
                        operator = true;
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        ns.nodes.get(0).accept(this);
                        operator = false;
+                       old.push(current_expression.expression);                        
+                       current_expression = new ExpressionBuilder();                   
                        ns.nodes.get(1).accept(this);
+                       current_expression.commit(lin.lineEnd);
                }
                old.push(current_expression.expression);
                current_expression = old;
@@ -354,11 +390,16 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                current_expression = new ExpressionBuilder();
                n.f0.accept(this);
                if (n.f1.present()) {
+                       LineNumberInfo lin = LineNumberInfo.get(n);
+                       current_expression.commit(lin.lineEnd);
                        operator = true;
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        ns.nodes.get(0).accept(this);
                        operator = false;
+                       old.push(current_expression.expression);                        
+                       current_expression = new ExpressionBuilder();                   
                        ns.nodes.get(1).accept(this);
+                       current_expression.commit(lin.lineEnd);
                }
                old.push(current_expression.expression);
                current_expression = old;
@@ -370,11 +411,19 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                current_expression = new ExpressionBuilder();
                n.f0.accept(this);
                if (n.f1.present()) {
+                       LineNumberInfo lin = LineNumberInfo.get(n.f0);
+                       current_expression.commit(lin.lineEnd);
                        operator = true;
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        ns.nodes.get(0).accept(this);
                        operator = false;
+                       ExpressionBuilder tmp = current_expression;
+                       current_expression = new ExpressionBuilder();                           
                        ns.nodes.get(1).accept(this);
+                       lin = LineNumberInfo.get(ns.nodes.get(1));
+                       current_expression.commit(lin.lineEnd);
+                       tmp.push (current_expression.expression);
+                       current_expression = tmp;
                }
                old.push(current_expression.expression);
                current_expression = old;
@@ -386,11 +435,19 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                current_expression = new ExpressionBuilder();
                n.f0.accept(this);
                if (n.f1.present()) {
+                       LineNumberInfo lin = LineNumberInfo.get(n.f0);
+                       current_expression.commit(lin.lineEnd);
                        operator = true;
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        ns.nodes.get(0).accept(this);
                        operator = false;
+                       ExpressionBuilder tmp = current_expression;
+                       current_expression = new ExpressionBuilder();                           
                        ns.nodes.get(1).accept(this);
+                       lin = LineNumberInfo.get(ns.nodes.get(1));
+                       current_expression.commit(lin.lineEnd);
+                       tmp.push (current_expression.expression);
+                       current_expression = tmp;
                }
                old.push(current_expression.expression);
                current_expression = old;
@@ -402,11 +459,19 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                current_expression = new ExpressionBuilder();
                n.f0.accept(this);
                if (n.f1.present()) {
+                       LineNumberInfo lin = LineNumberInfo.get(n.f0);
+                       current_expression.commit(lin.lineEnd);
                        operator = true;
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        ns.nodes.get(0).accept(this);
                        operator = false;
+                       ExpressionBuilder tmp = current_expression;
+                       current_expression = new ExpressionBuilder();                           
                        ns.nodes.get(1).accept(this);
+                       lin = LineNumberInfo.get(ns.nodes.get(1));
+                       current_expression.commit(lin.lineEnd);
+                       tmp.push (current_expression.expression);
+                       current_expression = tmp;
                }
                old.push(current_expression.expression);
                current_expression = old;
@@ -421,7 +486,7 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                n.f0.accept(this);
                if (n.f1.present()) {
                        LineNumberInfo lin = LineNumberInfo.get(n);
-                       current_expression.commit(lin.lineEnd);                 
+                       current_expression.commit(lin.lineEnd);
                        operator = true;
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        ns.nodes.get(0).accept(this);
@@ -429,7 +494,7 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                        old.push(current_expression.expression);
                        current_expression = new ExpressionBuilder();
                        ns.nodes.get(1).accept(this);
-                       current_expression.commit(lin.lineEnd);                 
+                       current_expression.commit(lin.lineEnd);
                }
                old.push(current_expression.expression);
                current_expression = old;
@@ -441,11 +506,16 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                current_expression = new ExpressionBuilder();
                n.f0.accept(this);
                if (n.f1.present()) {
+                       LineNumberInfo lin = LineNumberInfo.get(n);
+                       current_expression.commit(lin.lineEnd);
                        operator = true;
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        ns.nodes.get(0).accept(this);
                        operator = false;
+                       old.push(current_expression.expression);
+                       current_expression = new ExpressionBuilder();
                        ns.nodes.get(1).accept(this);
+                       current_expression.commit(lin.lineEnd);
                }
                old.push(current_expression.expression);
                current_expression = old;
@@ -457,11 +527,19 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                current_expression = new ExpressionBuilder();
                n.f0.accept(this);
                if (n.f1.present()) {
+                       LineNumberInfo lin = LineNumberInfo.get(n.f0);
+                       current_expression.commit(lin.lineEnd);
                        operator = true;
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        ns.nodes.get(0).accept(this);
                        operator = false;
+                       ExpressionBuilder tmp = current_expression;
+                       current_expression = new ExpressionBuilder();                           
                        ns.nodes.get(1).accept(this);
+                       lin = LineNumberInfo.get(ns.nodes.get(1));
+                       current_expression.commit(lin.lineEnd);
+                       tmp.push (current_expression.expression);
+                       current_expression = tmp;
                }
                old.push(current_expression.expression);
                current_expression = old;
@@ -473,11 +551,19 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                current_expression = new ExpressionBuilder();
                n.f0.accept(this);
                if (n.f1.present()) {
+                       LineNumberInfo lin = LineNumberInfo.get(n.f0);
+                       current_expression.commit(lin.lineEnd);
                        operator = true;
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        ns.nodes.get(0).accept(this);
                        operator = false;
+                       ExpressionBuilder tmp = current_expression;
+                       current_expression = new ExpressionBuilder();                           
                        ns.nodes.get(1).accept(this);
+                       lin = LineNumberInfo.get(ns.nodes.get(1));
+                       current_expression.commit(lin.lineEnd);
+                       tmp.push (current_expression.expression);
+                       current_expression = tmp;
                }
                old.push(current_expression.expression);
                current_expression = old;
@@ -489,11 +575,19 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                current_expression = new ExpressionBuilder();
                n.f0.accept(this);
                if (n.f1.present()) {
+                       LineNumberInfo lin = LineNumberInfo.get(n.f0);
+                       current_expression.commit(lin.lineEnd);
                        operator = true;
                        NodeSequence ns = (NodeSequence) n.f1.node;
                        ns.nodes.get(0).accept(this);
                        operator = false;
+                       ExpressionBuilder tmp = current_expression;
+                       current_expression = new ExpressionBuilder();                           
                        ns.nodes.get(1).accept(this);
+                       lin = LineNumberInfo.get(ns.nodes.get(1));
+                       current_expression.commit(lin.lineEnd);
+                       tmp.push (current_expression.expression);
+                       current_expression = tmp;
                }
                old.push(current_expression.expression);
                current_expression = old;
@@ -535,7 +629,7 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                                NodeSequence ns = (NodeSequence) nc.choice;
                                ns.elementAt(1).accept(this);
                                LineNumberInfo lin = LineNumberInfo.get(n);
-                               current_expression.commit(lin.colEnd);
+                               current_expression.commit(lin.lineEnd);
                                old.push("[");
                                old.push(current_expression.expression);
                                old.push("]");
@@ -547,6 +641,8 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                                current_expression = new ExpressionBuilder();
                                NodeSequence ns = (NodeSequence) nc.choice;
                                ns.elementAt(1).accept(this);
+                               LineNumberInfo lin = LineNumberInfo.get (ns.elementAt(1));
+                               current_expression.commit(lin.lineEnd);
                                old.push("(");
                                old.push(current_expression.expression);
                                old.push(")");
@@ -586,6 +682,8 @@ public class ExpressionExtractorVisitor extends DepthFirstVisitor {
                        current_expression = new ExpressionBuilder();
                        NodeSequence ns = (NodeSequence) n.f0.choice;
                        ns.elementAt(1).accept(this);
+                       LineNumberInfo lin1 = LineNumberInfo.get (ns.elementAt(1));
+                       current_expression.commit(lin1.lineEnd);
                        old.push("(");
                        old.push(current_expression.expression);
                        old.push(")");