[vala/wip/transform: 28/99] Move gvariant helper methods down to CodeTransformer



commit a828a3458298e8eacedcfdb7a372b1b26ca70486
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jan 3 13:14:31 2012 +0100

    Move gvariant helper methods down to CodeTransformer

 codegen/valagvarianttransformer.vala |   47 ---------------------------------
 vala/valacodetransformer.vala        |   48 ++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 47 deletions(-)
---
diff --git a/codegen/valagvarianttransformer.vala b/codegen/valagvarianttransformer.vala
index 7e5acb7..41720c2 100644
--- a/codegen/valagvarianttransformer.vala
+++ b/codegen/valagvarianttransformer.vala
@@ -45,9 +45,6 @@ public class Vala.GVariantTransformer : CodeTransformer {
                { "g", "signature", true }
        };
 
-       CodeBuilder b;
-       HashMap<string, CodeNode> wrapper_cache = new HashMap<string, CodeNode> (str_hash, str_equal);
-
        bool get_basic_type_info (string signature, out BasicTypeInfo basic_type) {
                foreach (BasicTypeInfo info in basic_types) {
                        if (info.signature == signature) {
@@ -150,36 +147,6 @@ public class Vala.GVariantTransformer : CodeTransformer {
                }
        }
 
-       DataType copy_type (DataType type, bool value_owned) {
-               var ret = type.copy ();
-               ret.value_owned = value_owned;
-               return ret;
-       }
-
-       bool get_cached_wrapper (string key, out CodeNode node) {
-               node = wrapper_cache.get (key);
-               return node != null;
-       }
-
-       void add_cached_wrapper (string key, CodeNode node) {
-               wrapper_cache.set (key, node);
-       }
-
-       bool wrapper_method (DataType return_type, string cache_key, out Method m) {
-               CodeNode n;
-               if (get_cached_wrapper (cache_key, out n)) {
-                       m = (Method) n;
-                       return true;
-               }
-               var name = CodeNode.get_temp_name ().replace (".", "");
-               name = "_vala_func_"+name;
-               m = new Method (name, return_type, b.source_reference);
-               context.root.add_method (m);
-               m.access = SymbolAccessibility.PRIVATE;
-               add_cached_wrapper (cache_key, m);
-               return false;
-       }
-
        Expression serialize_array (ArrayType array_type, Expression array_expr) {
                Method m;
                if (!wrapper_method (data_type ("GLib.Variant"), "gvariant_serialize_array 
"+array_type.to_string(), out m)) {
@@ -456,20 +423,6 @@ public class Vala.GVariantTransformer : CodeTransformer {
                return result;
        }
 
-       Symbol symbol_from_string (string symbol_string) {
-               Symbol sym = context.root;
-               foreach (unowned string s in symbol_string.split (".")) {
-                       sym = sym.scope.lookup (s);
-               }
-               return sym;
-       }
-
-       DataType data_type (string s, bool value_owned = true) {
-               DataType type = context.analyzer.get_data_type_for_symbol ((TypeSymbol) symbol_from_string 
(s));
-               type.value_owned = value_owned;
-               return type;
-       }
-
        public override void visit_cast_expression (CastExpression expr) {
                base.visit_cast_expression (expr);
 
diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala
index b10416a..47dc721 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -26,6 +26,9 @@
 public class Vala.CodeTransformer : CodeVisitor {
        public CodeContext context;
 
+       public CodeBuilder b;
+       public HashMap<string, CodeNode> wrapper_cache = new HashMap<string, CodeNode> (str_hash, str_equal);
+
        /**
         * Transform the code tree for the specified code context.
         *
@@ -44,6 +47,51 @@ public class Vala.CodeTransformer : CodeVisitor {
                }
        }
 
+       public static DataType copy_type (DataType type, bool value_owned) {
+               var ret = type.copy ();
+               ret.value_owned = value_owned;
+               return ret;
+       }
+
+       public bool get_cached_wrapper (string key, out CodeNode node) {
+               node = wrapper_cache.get (key);
+               return node != null;
+       }
+
+       public void add_cached_wrapper (string key, CodeNode node) {
+               wrapper_cache.set (key, node);
+       }
+
+       public bool wrapper_method (DataType return_type, string cache_key, out Method m) {
+               CodeNode n;
+               if (get_cached_wrapper (cache_key, out n)) {
+                       m = (Method) n;
+                       return true;
+               }
+               var name = CodeNode.get_temp_name ().replace (".", "");
+               name = "_vala_func_"+name;
+               m = new Method (name, return_type, b.source_reference);
+               context.root.add_method (m);
+               m.access = SymbolAccessibility.PRIVATE;
+               add_cached_wrapper (cache_key, m);
+               return false;
+       }
+
+       public Symbol symbol_from_string (string symbol_string) {
+               Symbol sym = context.root;
+               foreach (unowned string s in symbol_string.split (".")) {
+                       sym = sym.scope.lookup (s);
+               }
+               return sym;
+       }
+
+       // only qualified types, will slightly simplify the work of SymbolResolver
+       public DataType data_type (string s, bool value_owned = true) {
+               DataType type = context.analyzer.get_data_type_for_symbol ((TypeSymbol) symbol_from_string 
(s));
+               type.value_owned = value_owned;
+               return type;
+       }
+
        public void check (CodeNode node) {
                node.accept (context.resolver);
                if (!node.check (context)) {


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