[vala/wip/transform: 165/169] Make CodeTransformer pluggable



commit fc5c856a6e1d7c4f30a179e45398512f672b6e5d
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Feb 4 21:33:44 2014 +0100

    Make CodeTransformer pluggable

 codegen/valaccodetransformer.vala |  195 ++++++++++++----------
 compiler/valacompiler.vala        |    1 +
 vala/valacodetransformer.vala     |  341 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 448 insertions(+), 89 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index 70c7d98..0357d4c 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -25,92 +25,84 @@
  */
 public class Vala.CCodeTransformer : CodeTransformer {
        public override void visit_source_file (SourceFile source_file) {
-               source_file.accept_children (this);
+               source_file.accept_children (head);
        }
 
        public override void visit_class (Class cl) {
-               cl.accept_children (this);
+               cl.accept_children (head);
        }
 
        public override void visit_struct (Struct st) {
-               st.accept_children (this);
+               st.accept_children (head);
        }
 
        public override void visit_interface (Interface iface) {
-               iface.accept_children (this);
+               iface.accept_children (head);
        }
 
        public override void visit_enum (Enum en) {
-               en.accept_children (this);
+               en.accept_children (head);
        }
 
        public override void visit_enum_value (EnumValue ev) {
-               ev.accept_children (this);
+               ev.accept_children (head);
        }
 
        public override void visit_error_domain (ErrorDomain edomain) {
-               edomain.accept_children (this);
+               edomain.accept_children (head);
        }
 
        public override void visit_error_code (ErrorCode ecode) {
-               ecode.accept_children (this);
+               ecode.accept_children (head);
        }
 
        public override void visit_delegate (Delegate d) {
-               d.accept_children (this);
+               d.accept_children (head);
        }
 
        public override void visit_constant (Constant c) {
                c.active = true;
-               c.accept_children (this);
+               c.accept_children (head);
        }
 
        public override void visit_field (Field f) {
-               f.accept_children (this);
+               f.accept_children (head);
        }
 
        public override void visit_method (Method m) {
-               if (m.body == null) {
-                       return;
-               }
-
-               m.accept_children (this);
+               m.accept_children (head);
        }
 
        public override void visit_creation_method (CreationMethod m) {
-               if (m.body == null) {
-                       return;
-               }
-               
-               m.accept_children (this);
+               m.accept_children (head);
        }
 
        public override void visit_formal_parameter (Parameter p) {
-               p.accept_children (this);
+               p.accept_children (head);
        }
 
        public override void visit_property (Property prop) {
-               prop.accept_children (this);
+               prop.accept_children (head);
        }
 
        public override void visit_property_accessor (PropertyAccessor acc) {
-               acc.accept_children (this);
+               acc.accept_children (head);
        }
 
        public override void visit_signal (Signal sig) {
-               sig.accept_children (this);
+               sig.accept_children (head);
        }
 
        public override void visit_constructor (Constructor c) {
-               c.accept_children (this);
+               c.accept_children (head);
        }
 
        public override void visit_destructor (Destructor d) {
-               d.accept_children (this);
+               d.accept_children (head);
        }
 
        public override void visit_block (Block b) {
-               b.accept_children (this);
+               b.accept_children (head);
 
                foreach (LocalVariable local in b.get_local_variables ()) {
                        local.active = false;
@@ -121,50 +113,40 @@ public class Vala.CCodeTransformer : CodeTransformer {
        }
 
        public override void visit_declaration_statement (DeclarationStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_local_variable (LocalVariable local) {
                local.active = true;
-               local.accept_children (this);
+               local.accept_children (head);
        }
 
        public override void visit_initializer_list (InitializerList list) {
-               list.accept_children (this);
+               list.accept_children (head);
        }
 
        public override void visit_expression_statement (ExpressionStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_if_statement (IfStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_switch_statement (SwitchStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_switch_section (SwitchSection section) {
-               section.accept_children (this);
+               section.accept_children (head);
        }
 
        public override void visit_switch_label (SwitchLabel label) {
-               label.accept_children (this);
-       }
-
-       bool always_true (Expression condition) {
-               var literal = condition as BooleanLiteral;
-               return (literal != null && literal.value);
-       }
-
-       bool always_false (Expression condition) {
-               var literal = condition as BooleanLiteral;
-               return (literal != null && !literal.value);
+               label.accept_children (head);
        }
 
        public override void visit_loop (Loop loop) {
-               loop.accept_children (this);
+               loop.accept_children (head);
        }
 
        public override void visit_while_statement (WhileStatement stmt) {
@@ -301,47 +283,47 @@ public class Vala.CCodeTransformer : CodeTransformer {
        }
 
        public override void visit_break_statement (BreakStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_continue_statement (ContinueStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_return_statement (ReturnStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_yield_statement (YieldStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_throw_statement (ThrowStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_try_statement (TryStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_catch_clause (CatchClause clause) {
-               clause.accept_children (this);
+               clause.accept_children (head);
        }
 
        public override void visit_lock_statement (LockStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_unlock_statement (UnlockStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_delete_statement (DeleteStatement stmt) {
-               stmt.accept_children (this);
+               stmt.accept_children (head);
        }
 
        public override void visit_expression (Expression expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_method_call (MethodCall expr) {
@@ -360,11 +342,10 @@ public class Vala.CCodeTransformer : CodeTransformer {
                                var replacement = return_temp_access (local, expr.value_type, target_type, 
formal_target_type);
 
                                end_replace_expression (replacement);
-                               return;
                        }
                }
 
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_conditional_expression (ConditionalExpression expr) {
@@ -388,7 +369,6 @@ public class Vala.CCodeTransformer : CodeTransformer {
        public override void visit_binary_expression (BinaryExpression expr) {
                var parent_statement = expr.parent_statement;
                if (parent_statement == null) {
-                       base.visit_binary_expression (expr);
                        return;
                }
 
@@ -434,14 +414,13 @@ public class Vala.CCodeTransformer : CodeTransformer {
                        end_replace_expression (replacement);
                } else {
                        end_replace_expression (null);
-                       base.visit_binary_expression (expr);
+                       expr.accept_children (head);
                }
        }
 
        public override void visit_unary_expression (UnaryExpression expr) {
                var parent_statement = expr.parent_statement;
                if (parent_statement == null) {
-                       base.visit_unary_expression (expr);
                        return;
                }
 
@@ -461,7 +440,7 @@ public class Vala.CCodeTransformer : CodeTransformer {
                        return;
                }
 
-               base.visit_unary_expression (expr);
+               expr.accept_children (head);
        }
 
        public override void visit_object_creation_expression (ObjectCreationExpression expr) {
@@ -484,15 +463,7 @@ public class Vala.CCodeTransformer : CodeTransformer {
                        }
                }
 
-               expr.accept_children (this);
-       }
-
-       Expression stringify (Expression expr) {
-               if (expr.value_type.data_type != null && expr.value_type.data_type.is_subtype_of 
(context.analyzer.string_type.data_type)) {
-                       return expr;
-               } else {
-                       return expression (@"%?.to_string ()", {expr});
-               }
+               expr.accept_children (head);
        }
 
        public override void visit_template (Template expr) {
@@ -531,63 +502,111 @@ public class Vala.CCodeTransformer : CodeTransformer {
        }
 
        public override void visit_assignment (Assignment a) {
-               a.accept_children (this);
+               a.accept_children (head);
        }
 
        public override void visit_cast_expression (CastExpression expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_lambda_expression (LambdaExpression expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        
        public override void visit_array_creation_expression (ArrayCreationExpression expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_member_access (MemberAccess expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_element_access (ElementAccess expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_slice_expression (SliceExpression expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_base_access (BaseAccess expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_sizeof_expression (SizeofExpression expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_typeof_expression (TypeofExpression expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_named_argument (NamedArgument expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_pointer_indirection (PointerIndirection expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_addressof_expression (AddressofExpression expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_reference_transfer_expression (ReferenceTransferExpression expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
        }
 
        public override void visit_type_check (TypeCheck expr) {
-               expr.accept_children (this);
+               expr.accept_children (head);
+       }
+
+       public override void visit_type_parameter (TypeParameter p) {
+               p.accept_children (head);
+       }
+
+       public override void visit_using_directive (UsingDirective ns) {
+               ns.accept_children (head);
+       }
+
+       public override void visit_data_type (DataType type) {
+               type.accept_children (head);
+       }
+
+       public override void visit_end_full_expression (Expression expr) {
+               expr.accept_children (head);
+       }
+
+       public override void visit_boolean_literal (BooleanLiteral lit) {
+               lit.accept_children (head);
+       }
+
+       public override void visit_character_literal (CharacterLiteral lit) {
+               lit.accept_children (head);
+       }
+
+       public override void visit_integer_literal (IntegerLiteral lit) {
+               lit.accept_children (head);
+       }
+
+       public override void visit_real_literal (RealLiteral lit) {
+               lit.accept_children (head);
+       }
+
+       public override void visit_regex_literal (RegexLiteral lit) {
+               lit.accept_children (head);
+       }
+
+       public override void visit_string_literal (StringLiteral lit) {
+               lit.accept_children (head);
+       }
+
+       public override void visit_tuple (Tuple tuple) {
+               tuple.accept_children (head);
+       }
+
+       public override void visit_null_literal (NullLiteral lit) {
+               lit.accept_children (head);
        }
 }
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 515403a..f62b18d 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -371,6 +371,7 @@ class Vala.Compiler {
                }
 
                var transformer = new GDBusServerTransformer ();
+               transformer.head = transformer;
                transformer.transform (context);
 
                if (context.report.get_errors () > 0 || (fatal_warnings && context.report.get_warnings () > 
0)) {
diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala
index 1fa43c7..e09d559 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -1,6 +1,6 @@
 /* valacodetransformer.vala
  *
- * Copyright (C) 2011  Luca Bruno
+ * Copyright (C) 2011-2014  Luca Bruno
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -34,6 +34,9 @@ public class Vala.CodeTransformer : CodeVisitor {
 
        public Namespace current_namespace = null;
 
+       public weak CodeTransformer head;
+       public CodeTransformer next;
+       
        public void push_builder (CodeBuilder builder) {
                builder_stack.add (b);
                b = builder;
@@ -213,4 +216,340 @@ public class Vala.CodeTransformer : CodeVisitor {
                        }
                }
        }
+
+       public bool always_true (Expression condition) {
+               var literal = condition as BooleanLiteral;
+               return (literal != null && literal.value);
+       }
+
+       public bool always_false (Expression condition) {
+               var literal = condition as BooleanLiteral;
+               return (literal != null && !literal.value);
+       }
+
+       public Expression stringify (Expression expr) {
+               if (expr.value_type.data_type != null && expr.value_type.data_type.is_subtype_of 
(context.analyzer.string_type.data_type)) {
+                       return expr;
+               } else {
+                       return expression (@"%?.to_string ()", {expr});
+               }
+       }
+
+       /////////////
+       
+       public override void visit_source_file (SourceFile source_file) {
+               next.visit_source_file (source_file);
+       }
+
+       public override void visit_class (Class cl) {
+               next.visit_class (cl);
+       }
+
+       public override void visit_struct (Struct st) {
+               next.visit_struct (st);
+       }
+
+       public override void visit_interface (Interface iface) {
+               next.visit_interface (iface);
+       }
+
+       public override void visit_enum (Enum en) {
+               next.visit_enum (en);
+       }
+
+       public override void visit_enum_value (EnumValue ev) {
+               next.visit_enum_value (ev);
+       }
+
+       public override void visit_error_domain (ErrorDomain edomain) {
+               next.visit_error_domain (edomain);
+       }
+
+       public override void visit_error_code (ErrorCode ecode) {
+               next.visit_error_code (ecode);
+       }
+
+       public override void visit_delegate (Delegate d) {
+               next.visit_delegate (d);
+       }
+
+       public override void visit_constant (Constant c) {
+               next.visit_constant (c);
+       }
+
+       public override void visit_field (Field f) {
+               next.visit_field (f);
+       }
+
+       public override void visit_method (Method m) {
+               next.visit_method (m);
+       }
+
+       public override void visit_creation_method (CreationMethod m) {
+               next.visit_creation_method (m);
+       }
+
+       public override void visit_formal_parameter (Parameter p) {
+               next.visit_formal_parameter (p);
+       }
+
+       public override void visit_property (Property prop) {
+               next.visit_property (prop);
+       }
+
+       public override void visit_property_accessor (PropertyAccessor acc) {
+               next.visit_property_accessor (acc);
+       }
+
+       public override void visit_signal (Signal sig) {
+               next.visit_signal (sig);
+       }
+
+       public override void visit_constructor (Constructor c) {
+               next.visit_constructor (c);
+       }
+
+       public override void visit_destructor (Destructor d) {
+               next.visit_destructor (d);
+       }
+
+       public override void visit_type_parameter (TypeParameter p) {
+               next.visit_type_parameter (p);
+       }
+
+       public override void visit_using_directive (UsingDirective ns) {
+               next.visit_using_directive (ns);
+       }
+
+       public override void visit_data_type (DataType type) {
+               next.visit_data_type (type);
+       }
+
+       public override void visit_block (Block b) {
+               next.visit_block (b);
+       }
+
+       public override void visit_empty_statement (EmptyStatement stmt) {
+               next.visit_empty_statement (stmt);
+       }
+
+       public override void visit_declaration_statement (DeclarationStatement stmt) {
+               next.visit_declaration_statement (stmt);
+       }
+
+       public override void visit_local_variable (LocalVariable local) {
+               next.visit_local_variable (local);
+       }
+
+       public override void visit_initializer_list (InitializerList list) {
+               next.visit_initializer_list (list);
+       }
+
+       public override void visit_expression_statement (ExpressionStatement stmt) {
+               next.visit_expression_statement (stmt);
+       }
+
+       public override void visit_if_statement (IfStatement stmt) {
+               next.visit_if_statement (stmt);
+       }
+
+       public override void visit_switch_statement (SwitchStatement stmt) {
+               next.visit_switch_statement (stmt);
+       }
+
+       public override void visit_switch_section (SwitchSection section) {
+               next.visit_switch_section (section);
+       }
+
+       public override void visit_switch_label (SwitchLabel label) {
+               next.visit_switch_label (label);
+       }
+
+       public override void visit_loop (Loop stmt) {
+               next.visit_loop (stmt);
+       }
+
+       public override void visit_while_statement (WhileStatement stmt) {
+               next.visit_while_statement (stmt);
+       }
+
+       public override void visit_do_statement (DoStatement stmt) {
+               next.visit_do_statement (stmt);
+       }
+
+       public override void visit_for_statement (ForStatement stmt) {
+               next.visit_for_statement (stmt);
+       }
+
+       public override void visit_foreach_statement (ForeachStatement stmt) {
+               next.visit_foreach_statement (stmt);
+       }
+
+       public override void visit_break_statement (BreakStatement stmt) {
+               next.visit_break_statement (stmt);
+       }
+
+       public override void visit_continue_statement (ContinueStatement stmt) {
+               next.visit_continue_statement (stmt);
+       }
+
+       public override void visit_return_statement (ReturnStatement stmt) {
+               next.visit_return_statement (stmt);
+       }
+
+       public override void visit_yield_statement (YieldStatement y) {
+               next.visit_yield_statement (y);
+       }
+
+       public override void visit_throw_statement (ThrowStatement stmt) {
+               next.visit_throw_statement (stmt);
+       }
+
+       public override void visit_try_statement (TryStatement stmt) {
+               next.visit_try_statement (stmt);
+       }
+
+       public override void visit_catch_clause (CatchClause clause) {
+               next.visit_catch_clause (clause);
+       }
+
+       public override void visit_lock_statement (LockStatement stmt) {
+               next.visit_lock_statement (stmt);
+       }
+
+       public override void visit_unlock_statement (UnlockStatement stmt) {
+               next.visit_unlock_statement (stmt);
+       }
+
+       public override void visit_delete_statement (DeleteStatement stmt) {
+               next.visit_delete_statement (stmt);
+       }
+
+       public override void visit_expression (Expression expr) {
+               next.visit_expression (expr);
+       }
+
+       public override void visit_array_creation_expression (ArrayCreationExpression expr) {
+               next.visit_array_creation_expression (expr);
+       }
+
+       public override void visit_boolean_literal (BooleanLiteral lit) {
+               next.visit_boolean_literal (lit);
+       }
+
+       public override void visit_character_literal (CharacterLiteral lit) {
+               next.visit_character_literal (lit);
+       }
+
+       public override void visit_integer_literal (IntegerLiteral lit) {
+               next.visit_integer_literal (lit);
+       }
+
+       public override void visit_real_literal (RealLiteral lit) {
+               next.visit_real_literal (lit);
+       }
+
+       public override void visit_regex_literal (RegexLiteral lit) {
+               next.visit_regex_literal (lit);
+       }
+
+       public override void visit_string_literal (StringLiteral lit) {
+               next.visit_string_literal (lit);
+       }
+
+       public override void visit_template (Template tmpl) {
+               next.visit_template (tmpl);
+       }
+
+       public override void visit_tuple (Tuple tuple) {
+               next.visit_tuple (tuple);
+       }
+
+       public override void visit_null_literal (NullLiteral lit) {
+               next.visit_null_literal (lit);
+       }
+
+       public override void visit_member_access (MemberAccess expr) {
+               next.visit_member_access (expr);
+       }
+
+       public override void visit_method_call (MethodCall expr) {
+               next.visit_method_call (expr);
+       }
+       
+       public override void visit_element_access (ElementAccess expr) {
+               next.visit_element_access (expr);
+       }
+
+       public override void visit_slice_expression (SliceExpression expr) {
+               next.visit_slice_expression (expr);
+       }
+
+       public override void visit_base_access (BaseAccess expr) {
+               next.visit_base_access (expr);
+       }
+
+       public override void visit_postfix_expression (PostfixExpression expr) {
+               next.visit_postfix_expression (expr);
+       }
+
+       public override void visit_object_creation_expression (ObjectCreationExpression expr) {
+               next.visit_object_creation_expression (expr);
+       }
+
+       public override void visit_sizeof_expression (SizeofExpression expr) {
+               next.visit_sizeof_expression (expr);
+       }
+
+       public override void visit_typeof_expression (TypeofExpression expr) {
+               next.visit_typeof_expression (expr);
+       }
+
+       public override void visit_unary_expression (UnaryExpression expr) {
+               next.visit_unary_expression (expr);
+       }
+
+       public override void visit_cast_expression (CastExpression expr) {
+               next.visit_cast_expression (expr);
+       }
+
+       public override void visit_named_argument (NamedArgument expr) {
+               next.visit_named_argument (expr);
+       }
+
+       public override void visit_pointer_indirection (PointerIndirection expr) {
+               next.visit_pointer_indirection (expr);
+       }
+
+       public override void visit_addressof_expression (AddressofExpression expr) {
+               next.visit_addressof_expression (expr);
+       }
+
+       public override void visit_reference_transfer_expression (ReferenceTransferExpression expr) {
+               next.visit_reference_transfer_expression (expr);
+       }
+
+       public override void visit_binary_expression (BinaryExpression expr) {
+               next.visit_binary_expression (expr);
+       }
+
+       public override void visit_type_check (TypeCheck expr) {
+               next.visit_type_check (expr);
+       }
+
+       public override void visit_conditional_expression (ConditionalExpression expr) {
+               next.visit_conditional_expression (expr);
+       }
+
+       public override void visit_lambda_expression (LambdaExpression expr) {
+               next.visit_lambda_expression (expr);
+       }
+
+       public override void visit_assignment (Assignment a) {
+               next.visit_assignment (a);
+       }
+
+       public override void visit_end_full_expression (Expression expr) {
+               next.visit_end_full_expression (expr);
+       }
 }


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