improve subtyping suport for structs
authorJürg Billeter <j@bitron.ch>
Sun, 25 Feb 2007 20:21:50 +0000 (20:21 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sun, 25 Feb 2007 20:21:50 +0000 (20:21 +0000)
2007-02-25  Jürg Billeter  <j@bitron.ch>

* vala/valasemanticanalyzer.vala, vala/valacodegenerator.vala: improve
  subtyping suport for structs

svn path=/trunk/; revision=198

vala/ChangeLog
vala/vala/valacodegenerator.vala
vala/vala/valasemanticanalyzer.vala

index 2ca1faf..7bd8a3e 100644 (file)
@@ -1,5 +1,10 @@
 2007-02-25  Jürg Billeter  <j@bitron.ch>
 
+       * vala/valasemanticanalyzer.vala, vala/valacodegenerator.vala: improve
+         subtyping suport for structs
+
+2007-02-25  Jürg Billeter  <j@bitron.ch>
+
        * tests/test-026.vala, tests/test-026.out: test hidden base method
          access
        * tests/Makefile.am: update
index 6fd5f6f..6ea39a3 100644 (file)
@@ -1,6 +1,6 @@
 /* valacodegenerator.vala
  *
- * Copyright (C) 2006  Jürg Billeter, Raffaele Sandrini
+ * Copyright (C) 2006-2007  Jürg Billeter, Raffaele Sandrini
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1253,7 +1253,7 @@ public class Vala.CodeGenerator : CodeVisitor {
                                }
                                source_type_member_definition.append (function);
                                
-                               if (m.construction) {
+                               if (m.construction && current_class != null) {
                                        // declare construction parameter array
                                        var cparamsinit = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
                                        cparamsinit.add_argument (new CCodeIdentifier ("GParameter"));
index 57bbf52..0057a6e 100644 (file)
@@ -723,6 +723,14 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                        return result;
                                }
                        }
+               } else if (sym.node is Struct) {
+                       var st = (Struct) sym.node;
+                       foreach (TypeReference base_type in st.get_base_types ()) {
+                               result = symbol_lookup_inherited (base_type.data_type.symbol, name);
+                               if (result != null) {
+                                       return result;
+                               }
+                       }
                } else if (sym.node is Interface) {
                        var iface = (Interface) sym.node;
                        foreach (TypeReference base_type in iface.get_base_types ()) {
@@ -1054,14 +1062,21 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
 
        public override void visit_base_access (BaseAccess! expr) {
                if (current_class == null) {
-                       expr.error = true;
-                       Report.error (expr.source_reference, "Base access invalid outside of a class");
-                       return;
+                       if (current_struct == null) {
+                               expr.error = true;
+                               Report.error (expr.source_reference, "Base access invalid outside of class and struct");
+                               return;
+                       } else if (current_struct.get_base_types ().length () != 1) {
+                               expr.error = true;
+                               Report.error (expr.source_reference, "Base access invalid without base type %d".printf (current_struct.get_base_types ().length ()));
+                               return;
+                       }
+                       expr.static_type = current_struct.get_base_types ().first ().data;
+               } else {
+                       expr.static_type = new TypeReference ();
+                       expr.static_type.data_type = current_class.base_class;
                }
 
-               expr.static_type = new TypeReference ();
-               expr.static_type.data_type = current_class.base_class;
-
                expr.symbol_reference = expr.static_type.data_type.symbol;
        }