[vala/wip/transform: 101/104] Fix accepting method call children



commit 2a4d3232ac5ceea41780dd9f7e59c316bed41043
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Mar 13 23:41:47 2014 +0100

    Fix accepting method call children

 codegen/valaccodetransformer.vala |    3 +--
 vala/valacodetransformer.vala     |   13 +++++++++++++
 vala/valasemanticanalyzer.vala    |    3 +++
 3 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index aef6926..a2c7bf8 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -323,7 +323,6 @@ public class Vala.CCodeTransformer : CodeTransformer {
        }
 
        public override void visit_expression (Expression expr) {
-               expr.accept_children (head);
        }
 
        public override void visit_method_call (MethodCall expr) {
@@ -345,7 +344,7 @@ public class Vala.CCodeTransformer : CodeTransformer {
                        }
                }
 
-               expr.accept_children (head);
+               accept_method_call_children (expr);
        }
 
        public override void visit_conditional_expression (ConditionalExpression expr) {
diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala
index c5e1ad5..3815465 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -275,6 +275,19 @@ public class Vala.CodeTransformer : CodeVisitor {
                return file.file_type == SourceFileType.SOURCE || (context.header_filename != null && 
file.file_type == SourceFileType.FAST);
        }
 
+       public void accept_method_call_children (MethodCall expr) {
+               /* Semantic analysis adds parameter initializers as arguments
+                * this breaks a lot of assumption, and at the same time it's hard to fix in general.
+                * Thus we make a little hack here to not accept such arguments. */
+               expr.call.accept (head);
+
+               foreach (Expression arg in expr.get_argument_list ()) {
+                       if (arg.parent_node == expr) {
+                               arg.accept (head);
+                       }
+               }
+       }
+
        public void accept_external (CodeNode node) {
                if (node.source_reference != null) {
                        if (!is_visited (node) && !unit_generated.contains (node)) {
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index 4dac0ac..cfdc3e4 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -438,10 +438,13 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                } else {
                                        var invocation_expr = expr as MethodCall;
                                        var object_creation_expr = expr as ObjectCreationExpression;
+                                       var old_parent = param.initializer.parent_node;
                                        if (invocation_expr != null) {
                                                invocation_expr.add_argument (param.initializer);
+                                               param.initializer.parent_node = old_parent;
                                        } else if (object_creation_expr != null) {
                                                object_creation_expr.add_argument (param.initializer);
+                                               param.initializer.parent_node = old_parent;
                                        } else {
                                                assert_not_reached ();
                                        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]