Commit 03d2581b authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

improve subtyping suport for structs

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
parent f8801359
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
......
/* 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"));
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment