[vala/wip/transform: 354/373] Set the scope of the codebuilder block for symbol resolution



commit baf2125a9dd387951a3ceb0674cc73b404110867
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun Feb 2 20:39:52 2014 +0100

    Set the scope of the codebuilder block for symbol resolution

 codegen/valaccodetransformer.vala         | 5 +++--
 vala/valaassignment.vala                  | 2 +-
 vala/valacodebuilder.vala                 | 1 +
 vala/valacodetransformer.vala             | 4 ++++
 vala/valamemberaccess.vala                | 2 +-
 vala/valamethodcall.vala                  | 2 +-
 vala/valapointerindirection.vala          | 4 ++++
 vala/valareferencetransferexpression.vala | 4 ++++
 vala/valasymbolresolver.vala              | 2 +-
 vala/valatypecheck.vala                   | 4 ++++
 10 files changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index 850cd4283..8504c489b 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -166,11 +166,12 @@ public class Vala.CCodeTransformer : CodeTransformer {
        public override void visit_while_statement (WhileStatement stmt) {
                // convert to simple loop
                push_builder (new CodeBuilder (context, stmt, stmt.source_reference));
-
+               Expression cond = null;
                if (!always_false (stmt.condition)) {
                        b.open_loop ();
                        if (!always_true (stmt.condition)) {
-                               b.open_if (new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, 
stmt.condition, stmt.condition.source_reference));
+                               cond = expression (@"!$(stmt.condition)");
+                               b.open_if (cond);
                                b.add_break ();
                                b.close ();
                        }
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index d30ad45ac..b744eec28 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -102,7 +102,7 @@ public class Vala.Assignment : Expression {
        }
 
        public override string to_string () {
-               return left.to_string () + get_operator_string () + right.to_string ();
+               return "("+left.to_string () + get_operator_string () + right.to_string ()+")";
        }
 
        public override void replace_expression (Expression old_node, Expression new_node) {
diff --git a/vala/valacodebuilder.vala b/vala/valacodebuilder.vala
index 7a09f3b6e..2e52c8b6b 100644
--- a/vala/valacodebuilder.vala
+++ b/vala/valacodebuilder.vala
@@ -34,6 +34,7 @@ public class Vala.CodeBuilder {
                this.source_reference = source_reference;
 
                current_block = new Block (source_reference);
+               current_block.owner = context.analyzer.get_current_symbol (insert_statement).scope;
                insert_block = context.analyzer.get_current_block (insert_statement);
                insert_block.insert_before (insert_statement, current_block);
                this.insert_statement = current_block;
diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala
index c70ce2073..5799ca2ef 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -133,6 +133,10 @@ public class Vala.CodeTransformer : CodeVisitor {
        }
 
        public void check (CodeNode node) {
+               var sym = context.analyzer.get_current_symbol (node);
+               if (sym != null) {
+                       context.resolver.current_scope = sym.scope;
+               }
                node.accept (context.resolver);
                if (!node.check (context)) {
                        return;
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 258e7e06f..33327ee22 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -136,7 +136,7 @@ public class Vala.MemberAccess : Expression {
                        if (inner == null) {
                                return member_name;
                        } else {
-                               return "%s.%s".printf (inner.to_string (), member_name);
+                               return "%s%s%s".printf (inner.to_string (), pointer_member_access ? "->" : 
".", member_name);
                        }
                } else {
                        // ensure to always use fully-qualified name
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 80b00d9f4..d1ce21937 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -657,7 +657,7 @@ public class Vala.MethodCall : Expression {
                                b.append (", ");
                        }
                        b.append (expr.to_string ());
-                       first = true;
+                       first = false;
                }
                b.append ("))");
 
diff --git a/vala/valapointerindirection.vala b/vala/valapointerindirection.vala
index 93be9306e..85d84f5c6 100644
--- a/vala/valapointerindirection.vala
+++ b/vala/valapointerindirection.vala
@@ -114,4 +114,8 @@ public class Vala.PointerIndirection : Expression {
 
                codegen.visit_expression (this);
        }
+
+       public override string to_string () {
+               return "(*"+inner.to_string()+")";
+       }
 }
diff --git a/vala/valareferencetransferexpression.vala b/vala/valareferencetransferexpression.vala
index 2458fdeb3..bcbca099d 100644
--- a/vala/valareferencetransferexpression.vala
+++ b/vala/valareferencetransferexpression.vala
@@ -120,4 +120,8 @@ public class Vala.ReferenceTransferExpression : Expression {
 
                codegen.visit_expression (this);
        }
+
+       public override string to_string () {
+               return "(owned) "+inner.to_string ();
+       }
 }
diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala
index 8bbd63323..d69e40801 100644
--- a/vala/valasymbolresolver.vala
+++ b/vala/valasymbolresolver.vala
@@ -29,7 +29,7 @@ using GLib;
  */
 public class Vala.SymbolResolver : CodeVisitor {
        Symbol root_symbol;
-       Scope current_scope;
+       public Scope current_scope;
 
        /**
         * Resolve symbol names in the specified code context.
diff --git a/vala/valatypecheck.vala b/vala/valatypecheck.vala
index 5b22d75d4..8cfd4566d 100644
--- a/vala/valatypecheck.vala
+++ b/vala/valatypecheck.vala
@@ -132,4 +132,8 @@ public class Vala.TypeCheck : Expression {
 
                codegen.visit_expression (this);
        }
+
+       public override string to_string () {
+               return @"($expression is $type_reference)";
+       }
 }


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