[vala/wip/transform: 356/373] Parse statements from a string



commit 35405629932643845fe71162a62b26e2d4c03cbf
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun Feb 2 23:32:35 2014 +0100

    Parse statements from a string

 codegen/valaccodetransformer.vala |  3 ++-
 vala/valacodebuilder.vala         |  4 ++++
 vala/valacodetransformer.vala     |  4 ++++
 vala/valaparser.vala              | 25 +++++++++++++++++++++++++
 4 files changed, 35 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index cca398826..86d8edf3d 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -223,7 +223,8 @@ public class Vala.CCodeTransformer : CodeTransformer {
                                b.add_expression (it_expr);
                        }
                        b.add_else ();
-                       b.add_assignment (expression (notfirst), expression ("true"));
+                       statements (@"$notfirst = true;");
+                       /* b.add_assignment (expression (notfirst), expression ("true")); */
                        b.close ();
 
                        if (stmt.condition != null && !always_true (stmt.condition)) {
diff --git a/vala/valacodebuilder.vala b/vala/valacodebuilder.vala
index ab174ffb9..036303cb9 100644
--- a/vala/valacodebuilder.vala
+++ b/vala/valacodebuilder.vala
@@ -272,6 +272,10 @@ public class Vala.CodeBuilder {
                return new Parser().parse_expression_string (str, source_reference);
        }
 
+       public void statements (string str) {
+               new Parser().parse_statements_string (str, current_block, source_reference);
+       }
+
        // only qualified types, will slightly simplify the work of SymbolResolver
        public static Symbol? symbol_from_string (string symbol_string, Symbol? parent_symbol = null) {
                Symbol sym = parent_symbol != null ? parent_symbol : CodeContext.get().root;
diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala
index b7b829737..f6444b8e9 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -184,6 +184,10 @@ public class Vala.CodeTransformer : CodeVisitor {
                return b.expression (str);
        }
 
+       public void statements (string str) {
+               b.statements (str);
+       }
+
        public void check (CodeNode node) {
                var sym = context.analyzer.get_current_symbol (node);
                if (sym != null) {
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 58b136393..2919d81fc 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -346,12 +346,33 @@ public class Vala.Parser : CodeVisitor {
                try {
                        return parse_expression ();
                } catch (Error e) {
+                       Report.error (source_reference, "Internal compiler error: %s".printf (e.message));
                }
 
                scanner = null;
                return null;
        }
 
+       public void parse_statements_string (string str, Block block, SourceReference source_reference) {
+               compiler_code = true;
+               context = source_reference.file.context;
+               from_string_reference = source_reference;
+
+               scanner = new Scanner.from_string (str, source_reference.file);
+               index = -1;
+               size = 0;
+
+               next ();
+
+               try {
+                       parse_statements (block);
+               } catch (Error e) {
+                       Report.error (source_reference, "Internal compiler error: %s".printf (e.message));
+               }
+
+               scanner = null;
+       }
+
        public void parse_file (SourceFile source_file) {
                var has_global_context = (context != null);
                if (!has_global_context) {
@@ -1627,6 +1648,10 @@ public class Vala.Parser : CodeVisitor {
                                        break;
                                default:
                                        bool is_expr = is_expression ();
+                                       if (!is_expr && compiler_code && current () == TokenType.DOT) {
+                                               // compiler variable assignment
+                                               is_expr = true;
+                                       }
                                        if (is_expr) {
                                                stmt = parse_expression_statement ();
                                        } else {


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