]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Simplify current symbol tracking
authorJürg Billeter <j@bitron.ch>
Sun, 16 Aug 2009 09:59:27 +0000 (11:59 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 16 Aug 2009 09:59:27 +0000 (11:59 +0200)
Replace current_type_symbol, current_class, current_struct,
current_method, and current_property_accessor fields by properties.

12 files changed:
codegen/valaccodebasemodule.vala
codegen/valaccodemethodmodule.vala
codegen/valaccodestructmodule.vala
codegen/valagasyncmodule.vala
codegen/valagtypemodule.vala
vala/valaclass.vala
vala/valacreationmethod.vala
vala/valamethod.vala
vala/valaproperty.vala
vala/valapropertyaccessor.vala
vala/valasemanticanalyzer.vala
vala/valastruct.vala

index 10237f758ff4246257de0e53970ecebcaee69084..1939e42e78119fb3ba158a6c7048478091e819b4 100644 (file)
@@ -32,12 +32,45 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
        public Symbol root_symbol;
        public Symbol current_symbol;
-       public TypeSymbol current_type_symbol;
-       public Class current_class;
-       public Method current_method;
        public DataType current_return_type;
        public TryStatement current_try;
-       public PropertyAccessor current_property_accessor;
+
+       public Method? current_method {
+               get {
+                       var sym = current_symbol;
+                       while (sym is Block) {
+                               sym = sym.parent_symbol;
+                       }
+                       return sym as Method;
+               }
+       }
+
+       public PropertyAccessor? current_property_accessor {
+               get {
+                       var sym = current_symbol;
+                       while (sym is Block) {
+                               sym = sym.parent_symbol;
+                       }
+                       return sym as PropertyAccessor;
+               }
+       }
+
+       public TypeSymbol? current_type_symbol {
+               get {
+                       var sym = current_symbol;
+                       while (sym != null) {
+                               if (sym is TypeSymbol) {
+                                       return (TypeSymbol) sym;
+                               }
+                               sym = sym.parent_symbol;
+                       }
+                       return null;
+               }
+       }
+
+       public Class? current_class {
+               get { return current_type_symbol as Class; }
+       }
 
        public CCodeDeclarationSpace header_declarations;
        public CCodeDeclarationSpace internal_header_declarations;
@@ -1234,9 +1267,9 @@ internal class Vala.CCodeBaseModule : CCodeModule {
        }
 
        public override void visit_property_accessor (PropertyAccessor acc) {
-               var old_property_accessor = current_property_accessor;
+               var old_symbol = current_symbol;
                bool old_method_inner_error = current_method_inner_error;
-               current_property_accessor = acc;
+               current_symbol = acc;
                current_method_inner_error = false;
 
                var prop = (Property) acc.prop;
@@ -1474,7 +1507,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                        source_type_member_definition.append (function);
                }
 
-               current_property_accessor = old_property_accessor;
+               current_symbol = old_symbol;
                current_return_type = old_return_type;
                current_method_inner_error = old_method_inner_error;
        }
index 9e83e6ad792f2c61d44409bb8c3846eff469eed4..d1ada7eec7fe54da7762e86afcf5f41a251d0046 100644 (file)
@@ -183,9 +183,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
        }
 
        public override void visit_method (Method m) {
-               var old_type_symbol = current_type_symbol;
                var old_symbol = current_symbol;
-               Method old_method = current_method;
                DataType old_return_type = current_return_type;
                bool old_method_inner_error = current_method_inner_error;
                bool old_in_creation_method = in_creation_method;
@@ -194,11 +192,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
                var old_temp_ref_vars = temp_ref_vars;
                var old_variable_name_map = variable_name_map;
                var old_try = current_try;
-               if (m.parent_symbol is TypeSymbol) {
-                       current_type_symbol = (TypeSymbol) m.parent_symbol;
-               }
                current_symbol = m;
-               current_method = m;
                current_return_type = m.return_type;
                current_method_inner_error = false;
                next_temp_var_id = 0;
@@ -304,9 +298,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 
                bool inner_error = current_method_inner_error;
 
-               current_type_symbol = old_type_symbol;
                current_symbol = old_symbol;
-               current_method = old_method;
                current_return_type = old_return_type;
                current_method_inner_error = old_method_inner_error;
                next_temp_var_id = old_next_temp_var_id;
index 9ffc52aa7043bcf13b1abc339fda8c4cd220e635..f6175984216595a8beab81cd05c8fff20eb6f681 100644 (file)
@@ -139,9 +139,9 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
        }
 
        public override void visit_struct (Struct st) {
-               var old_type_symbol = current_type_symbol;
+               var old_symbol = current_symbol;
                var old_instance_finalize_fragment = instance_finalize_fragment;
-               current_type_symbol = st;
+               current_symbol = st;
                instance_finalize_fragment = new CCodeFragment ();
 
                generate_struct_declaration (st, source_declarations);
@@ -163,7 +163,7 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
                        add_struct_free_function (st);
                }
 
-               current_type_symbol = old_type_symbol;
+               current_symbol = old_symbol;
                instance_finalize_fragment = old_instance_finalize_fragment;
        }
 
index 438cbab2609f17f22a40cca7ca67c320474cb03f..a33635f73a50f450daeb277938a39f990503ca16 100644 (file)
@@ -71,10 +71,11 @@ internal class Vala.GAsyncModule : GSignalModule {
                        var v = new LocalVariable (m.return_type, "result");
                        var ma = new MemberAccess.simple ("result");
                        ma.symbol_reference = v;
-                       current_method = m;
+                       var old_symbol = current_symbol;
+                       current_symbol = m;
                        var unref_expr = get_unref_expression (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "result"), m.return_type, ma);
                        freeblock.add_statement (new CCodeExpressionStatement (unref_expr));
-                       current_method = null;
+                       current_symbol = old_symbol;
                }
 
                var freecall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
index a26ce66362c5cf5e5adc21a3d991c7689383db38..229c7bf2acfded2206091bb88c9120d7b0e1b885 100644 (file)
@@ -461,8 +461,6 @@ internal class Vala.GTypeModule : GErrorModule {
 
        public override void visit_class (Class cl) {
                var old_symbol = current_symbol;
-               var old_type_symbol = current_type_symbol;
-               var old_class = current_class;
                var old_param_spec_struct = param_spec_struct;
                var old_prop_enum = prop_enum;
                var old_class_init_fragment = class_init_fragment;
@@ -472,8 +470,6 @@ internal class Vala.GTypeModule : GErrorModule {
                var old_instance_init_fragment = instance_init_fragment;
                var old_instance_finalize_fragment = instance_finalize_fragment;
                current_symbol = cl;
-               current_type_symbol = cl;
-               current_class = cl;
 
                bool is_gtypeinstance = !cl.is_compact;
                bool is_fundamental = is_gtypeinstance && cl.base_class == null;
@@ -652,8 +648,6 @@ internal class Vala.GTypeModule : GErrorModule {
                }
 
                current_symbol = old_symbol;
-               current_type_symbol = old_type_symbol;
-               current_class = old_class;
                param_spec_struct = old_param_spec_struct;
                prop_enum = old_prop_enum;
                class_init_fragment = old_class_init_fragment;
@@ -1797,8 +1791,8 @@ internal class Vala.GTypeModule : GErrorModule {
        }
 
        public override void visit_interface (Interface iface) {
+               var old_symbol = current_symbol;
                current_symbol = iface;
-               current_type_symbol = iface;
 
                if (iface.get_cname().len () < 3) {
                        iface.error = true;
@@ -1816,7 +1810,7 @@ internal class Vala.GTypeModule : GErrorModule {
                type_fun.init_from_type ();
                source_type_member_definition.append (type_fun.get_definition ());
 
-               current_type_symbol = null;
+               current_symbol = old_symbol;
        }
 
        public virtual TypeRegisterFunction create_interface_register_function (Interface iface) {
index ad76ded983a2525399af9a46c92375484fb4d41c..68862a7842ad486896a38765acedb928369a8198 100644 (file)
@@ -914,13 +914,11 @@ public class Vala.Class : ObjectTypeSymbol {
 
                var old_source_file = analyzer.current_source_file;
                var old_symbol = analyzer.current_symbol;
-               var old_class = analyzer.current_class;
 
                if (source_reference != null) {
                        analyzer.current_source_file = source_reference.file;
                }
                analyzer.current_symbol = this;
-               analyzer.current_class = this;
 
                foreach (DataType base_type_reference in get_base_types ()) {
                        if (!base_type_reference.check (analyzer)) {
@@ -1141,7 +1139,6 @@ public class Vala.Class : ObjectTypeSymbol {
 
                analyzer.current_source_file = old_source_file;
                analyzer.current_symbol = old_symbol;
-               analyzer.current_class = old_class;
 
                return !error;
        }
index 3dc1aec8bf4feafcf62a742e8b32581361855d29..e73a1951ae5a26f725eba63c29c41cce2bb43aeb 100644 (file)
@@ -134,19 +134,12 @@ public class Vala.CreationMethod : Method {
 
                var old_source_file = analyzer.current_source_file;
                var old_symbol = analyzer.current_symbol;
-               var old_class = analyzer.current_class;
-               var old_struct = analyzer.current_struct;
                var old_return_type = analyzer.current_return_type;
 
                if (source_reference != null) {
                        analyzer.current_source_file = source_reference.file;
                }
                analyzer.current_symbol = this;
-               if (parent_symbol is Class) {
-                       analyzer.current_class = (Class) parent_symbol;
-               } else if (parent_symbol is Struct) {
-                       analyzer.current_struct = (Struct) parent_symbol;
-               }
                analyzer.current_return_type = return_type;
 
                foreach (FormalParameter param in get_parameters()) {
@@ -163,8 +156,6 @@ public class Vala.CreationMethod : Method {
 
                analyzer.current_source_file = old_source_file;
                analyzer.current_symbol = old_symbol;
-               analyzer.current_class = old_class;
-               analyzer.current_struct = old_struct;
                analyzer.current_return_type = old_return_type;
 
                if (analyzer.current_symbol.parent_symbol is Method) {
index 43f3d306a1428ebc1d5014124667d8aee43c54c5..e26c56fc794a14d25d2bcca2fbbd092c3d24912c 100644 (file)
@@ -720,19 +720,12 @@ public class Vala.Method : Member {
 
                var old_source_file = analyzer.current_source_file;
                var old_symbol = analyzer.current_symbol;
-               var old_class = analyzer.current_class;
-               var old_struct = analyzer.current_struct;
                var old_return_type = analyzer.current_return_type;
 
                if (source_reference != null) {
                        analyzer.current_source_file = source_reference.file;
                }
                analyzer.current_symbol = this;
-               if (parent_symbol is Class) {
-                       analyzer.current_class = (Class) parent_symbol;
-               } else if (parent_symbol is Struct) {
-                       analyzer.current_struct = (Struct) parent_symbol;
-               }
                analyzer.current_return_type = return_type;
 
                return_type.check (analyzer);
@@ -772,8 +765,6 @@ public class Vala.Method : Member {
 
                analyzer.current_source_file = old_source_file;
                analyzer.current_symbol = old_symbol;
-               analyzer.current_class = old_class;
-               analyzer.current_struct = old_struct;
                analyzer.current_return_type = old_return_type;
 
                if (analyzer.current_symbol.parent_symbol is Method) {
index e807410efe05103f47e707204db146be958e0482..64eaa8ec13a47c7a66bad6a1bcf8b77f9083d176 100644 (file)
@@ -48,7 +48,7 @@ public class Vala.Property : Member, Lockable {
                set {
                        _get_accessor = value;
                        if (value != null) {
-                               value.prop = this;
+                               value.owner = scope;
                        }
                }
        }
@@ -61,7 +61,7 @@ public class Vala.Property : Member, Lockable {
                set {
                        _set_accessor = value;
                        if (value != null) {
-                               value.prop = this;
+                               value.owner = scope;
                        }
                }
        }
index de017c289a0f894e81ece32934fac12ca345d64a..63cbfe011eb7d14c1869da3e6ae12dc173ab8a55 100644 (file)
@@ -25,11 +25,13 @@ using GLib;
 /**
  * Represents a get or set accessor of a property in the source code.
  */
-public class Vala.PropertyAccessor : CodeNode {
+public class Vala.PropertyAccessor : Symbol {
        /**
         * The corresponding property.
         */
-       public weak Property prop { get; set; }
+       public Property prop {
+               get { return parent_symbol as Property; }
+       }
 
        /**
         * The property type.
@@ -60,15 +62,18 @@ public class Vala.PropertyAccessor : CodeNode {
         */
        public bool construction { get; set; }
 
-       /**
-        * Specifies the accessibility of this property accessor.
-        */
-       public SymbolAccessibility access { get; set; }
-
        /**
         * The accessor body.
         */
-       public Block? body { get; set; }
+       public Block? body {
+               get { return _body; }
+               set {
+                       _body = value;
+                       if (_body != null) {
+                               _body.owner = scope;
+                       }
+               }
+       }
 
        public BasicBlock entry_block { get; set; }
 
@@ -104,6 +109,7 @@ public class Vala.PropertyAccessor : CodeNode {
 
        private DataType _value_type;
        private string? _cname;
+       private Block _body;
        
        /**
         * Creates a new property accessor.
@@ -116,12 +122,12 @@ public class Vala.PropertyAccessor : CodeNode {
         * @return             newly created property accessor
         */
        public PropertyAccessor (bool readable, bool writable, bool construction, DataType? value_type, Block? body, SourceReference? source_reference) {
+               base (null, source_reference);
                this.readable = readable;
                this.writable = writable;
                this.construction = construction;
                this.value_type = value_type;
                this.body = body;
-               this.source_reference = source_reference;
        }
 
        public override void accept (CodeVisitor visitor) {
@@ -163,7 +169,10 @@ public class Vala.PropertyAccessor : CodeNode {
                        return false;
                }
 
+               var old_symbol = analyzer.current_symbol;
                var old_return_type = analyzer.current_return_type;
+
+               analyzer.current_symbol = this;
                if (readable) {
                        analyzer.current_return_type = value_type;
                } else {
@@ -201,6 +210,7 @@ public class Vala.PropertyAccessor : CodeNode {
                        body.check (analyzer);
                }
 
+               analyzer.current_symbol = old_symbol;
                analyzer.current_return_type = old_return_type;
 
                return !error;
index 0b6febaa9f7779d8a3eafec8637b95593925062c..c62fe5e662e470cb58ab19f3e278c7e884d7aa30 100644 (file)
@@ -35,8 +35,28 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public Symbol current_symbol { get; set; }
        public SourceFile current_source_file { get; set; }
        public DataType current_return_type;
-       public Class current_class;
-       public Struct current_struct;
+
+       public TypeSymbol? current_type_symbol {
+               get {
+                       var sym = current_symbol;
+                       while (sym != null) {
+                               if (sym is TypeSymbol) {
+                                       return (TypeSymbol) sym;
+                               }
+                               sym = sym.parent_symbol;
+                       }
+                       return null;
+               }
+       }
+
+       public Class? current_class {
+               get { return current_type_symbol as Class; }
+       }
+
+
+       public Struct? current_struct {
+               get { return current_type_symbol as Struct; }
+       }
 
        public Block insert_block;
 
index c2d61bfb520025862dfa43488f208d48c6f0938d..33956d7a41ab928ec4494deaaae2cdf19814cab2 100644 (file)
@@ -717,13 +717,11 @@ public class Vala.Struct : TypeSymbol {
 
                var old_source_file = analyzer.current_source_file;
                var old_symbol = analyzer.current_symbol;
-               var old_struct = analyzer.current_struct;
 
                if (source_reference != null) {
                        analyzer.current_source_file = source_reference.file;
                }
                analyzer.current_symbol = this;
-               analyzer.current_struct = this;
 
                if (base_type != null) {
                        base_type.check (analyzer);
@@ -765,7 +763,6 @@ public class Vala.Struct : TypeSymbol {
 
                analyzer.current_source_file = old_source_file;
                analyzer.current_symbol = old_symbol;
-               analyzer.current_struct = old_struct;
 
                return !error;
        }