]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Replace current_return_type field by property
authorJürg Billeter <j@bitron.ch>
Sun, 16 Aug 2009 10:19:04 +0000 (12:19 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 16 Aug 2009 10:19:04 +0000 (12:19 +0200)
codegen/valaccodebasemodule.vala
codegen/valaccodemethodmodule.vala
vala/valacreationmethod.vala
vala/valamethod.vala
vala/valapropertyaccessor.vala
vala/valasemanticanalyzer.vala

index 1939e42e78119fb3ba158a6c7048478091e819b4..aceec9a608bf18bb845acbba51e9c535eed71b60 100644 (file)
@@ -32,9 +32,25 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
        public Symbol root_symbol;
        public Symbol current_symbol;
-       public DataType current_return_type;
        public TryStatement current_try;
 
+       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 Method? current_method {
                get {
                        var sym = current_symbol;
@@ -55,23 +71,26 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                }
        }
 
-       public TypeSymbol? current_type_symbol {
+       public DataType? current_return_type {
                get {
-                       var sym = current_symbol;
-                       while (sym != null) {
-                               if (sym is TypeSymbol) {
-                                       return (TypeSymbol) sym;
+                       var m = current_method;
+                       if (m != null) {
+                               return m.return_type;
+                       }
+
+                       var acc = current_property_accessor;
+                       if (acc != null) {
+                               if (acc.readable) {
+                                       return acc.value_type;
+                               } else {
+                                       return void_type;
                                }
-                               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;
        public CCodeDeclarationSpace source_declarations;
@@ -114,6 +133,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
        public bool current_method_inner_error = false;
        public int next_coroutine_state = 1;
 
+       public DataType void_type = new VoidType ();
        public DataType bool_type;
        public DataType char_type;
        public DataType uchar_type;
@@ -1276,13 +1296,6 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
                bool returns_real_struct = prop.property_type.is_real_struct_type ();
 
-               var old_return_type = current_return_type;
-               if (acc.readable && !returns_real_struct) {
-                       current_return_type = acc.value_type;
-               } else {
-                       current_return_type = new VoidType ();
-               }
-
                acc.accept_children (codegen);
 
                var t = (ObjectTypeSymbol) prop.parent_symbol;
@@ -1508,7 +1521,6 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                }
 
                current_symbol = old_symbol;
-               current_return_type = old_return_type;
                current_method_inner_error = old_method_inner_error;
        }
 
index d1ada7eec7fe54da7762e86afcf5f41a251d0046..93150df80a3ea0fc163045fd08a4c57158eec23d 100644 (file)
@@ -184,7 +184,6 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 
        public override void visit_method (Method m) {
                var old_symbol = current_symbol;
-               DataType old_return_type = current_return_type;
                bool old_method_inner_error = current_method_inner_error;
                bool old_in_creation_method = in_creation_method;
                int old_next_temp_var_id = next_temp_var_id;
@@ -193,7 +192,6 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
                var old_variable_name_map = variable_name_map;
                var old_try = current_try;
                current_symbol = m;
-               current_return_type = m.return_type;
                current_method_inner_error = false;
                next_temp_var_id = 0;
                temp_vars = new ArrayList<LocalVariable> ();
@@ -299,7 +297,6 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
                bool inner_error = current_method_inner_error;
 
                current_symbol = old_symbol;
-               current_return_type = old_return_type;
                current_method_inner_error = old_method_inner_error;
                next_temp_var_id = old_next_temp_var_id;
                temp_vars = old_temp_vars;
index e73a1951ae5a26f725eba63c29c41cce2bb43aeb..7f78ae4cee9b6c5cf5c3c7c94e9a1443b363cbe5 100644 (file)
@@ -134,13 +134,11 @@ public class Vala.CreationMethod : Method {
 
                var old_source_file = analyzer.current_source_file;
                var old_symbol = analyzer.current_symbol;
-               var old_return_type = analyzer.current_return_type;
 
                if (source_reference != null) {
                        analyzer.current_source_file = source_reference.file;
                }
                analyzer.current_symbol = this;
-               analyzer.current_return_type = return_type;
 
                foreach (FormalParameter param in get_parameters()) {
                        param.check (analyzer);
@@ -156,13 +154,6 @@ public class Vala.CreationMethod : Method {
 
                analyzer.current_source_file = old_source_file;
                analyzer.current_symbol = old_symbol;
-               analyzer.current_return_type = old_return_type;
-
-               if (analyzer.current_symbol.parent_symbol is Method) {
-                       /* lambda expressions produce nested methods */
-                       var up_method = (Method) analyzer.current_symbol.parent_symbol;
-                       analyzer.current_return_type = up_method.return_type;
-               }
 
                if (is_abstract || is_virtual || overrides) {
                        Report.error (source_reference, "The creation method `%s' cannot be marked as override, virtual, or abstract".printf (get_full_name ()));
index e26c56fc794a14d25d2bcca2fbbd092c3d24912c..51ea569ef06eb8936b5fcabc100eb5e219a0849f 100644 (file)
@@ -720,13 +720,11 @@ public class Vala.Method : Member {
 
                var old_source_file = analyzer.current_source_file;
                var old_symbol = analyzer.current_symbol;
-               var old_return_type = analyzer.current_return_type;
 
                if (source_reference != null) {
                        analyzer.current_source_file = source_reference.file;
                }
                analyzer.current_symbol = this;
-               analyzer.current_return_type = return_type;
 
                return_type.check (analyzer);
 
@@ -765,15 +763,8 @@ public class Vala.Method : Member {
 
                analyzer.current_source_file = old_source_file;
                analyzer.current_symbol = old_symbol;
-               analyzer.current_return_type = old_return_type;
 
-               if (analyzer.current_symbol.parent_symbol is Method) {
-                       /* lambda expressions produce nested methods */
-                       var up_method = (Method) analyzer.current_symbol.parent_symbol;
-                       analyzer.current_return_type = up_method.return_type;
-               }
-
-               if (analyzer.current_symbol is Struct) {
+               if (analyzer.current_struct != null) {
                        if (is_abstract || is_virtual || overrides) {
                                Report.error (source_reference, "A struct member `%s' cannot be marked as override, virtual, or abstract".printf (get_full_name ()));
                                return false;
index 63cbfe011eb7d14c1869da3e6ae12dc173ab8a55..b37f08e173b6e3d5dbddfa7363a65925e8eb7766 100644 (file)
@@ -170,15 +170,8 @@ public class Vala.PropertyAccessor : Symbol {
                }
 
                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 {
-                       // void
-                       analyzer.current_return_type = new VoidType ();
-               }
 
                if (!prop.external_package) {
                        if (body == null && !prop.interface_only && !prop.is_abstract) {
@@ -211,7 +204,6 @@ public class Vala.PropertyAccessor : Symbol {
                }
 
                analyzer.current_symbol = old_symbol;
-               analyzer.current_return_type = old_return_type;
 
                return !error;
        }
index c62fe5e662e470cb58ab19f3e278c7e884d7aa30..147e602bc3ad9d2e002bc857e0c949fd03cdec62 100644 (file)
@@ -34,7 +34,6 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public Symbol root_symbol;
        public Symbol current_symbol { get; set; }
        public SourceFile current_source_file { get; set; }
-       public DataType current_return_type;
 
        public TypeSymbol? current_type_symbol {
                get {
@@ -58,8 +57,49 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                get { return current_type_symbol as Struct; }
        }
 
+       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 DataType? current_return_type {
+               get {
+                       var m = current_method;
+                       if (m != null) {
+                               return m.return_type;
+                       }
+
+                       var acc = current_property_accessor;
+                       if (acc != null) {
+                               if (acc.readable) {
+                                       return acc.value_type;
+                               } else {
+                                       return void_type;
+                               }
+                       }
+
+                       return null;
+               }
+       }
+
        public Block insert_block;
 
+       public DataType void_type = new VoidType ();
        public DataType bool_type;
        public DataType string_type;
        public DataType uchar_type;