Commit 3279b441 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

add experimental support for class declarations in multiple source files

2007-04-30  Jürg Billeter  <j@bitron.ch>

	* vala/parser.y, vala/valasymbolbuilder.vala, vala/valaclass.vala,
	  vala/valanamespace.vala: add experimental support for class
	  declarations in multiple source files

svn path=/trunk/; revision=295
parent c6fa0202
2007-04-30 Jürg Billeter <j@bitron.ch>
* vala/parser.y, vala/valasymbolbuilder.vala, vala/valaclass.vala,
vala/valanamespace.vala: add experimental support for class
declarations in multiple source files
2007-04-30 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: check whether specified collection is
......
......@@ -2401,7 +2401,7 @@ class_member_declaration
{
/* skip declarations with errors */
if ($1 != NULL) {
vala_class_add_property (current_class, $1);
vala_class_add_property (current_class, $1, FALSE);
g_object_unref ($1);
}
}
......
......@@ -188,10 +188,10 @@ public class Vala.Class : DataType {
*
* @param prop a property
*/
public void add_property (Property! prop) {
public void add_property (Property! prop, bool no_field = false) {
properties.append (prop);
if (prop.set_accessor != null && prop.set_accessor.body == null &&
if (!no_field && prop.set_accessor != null && prop.set_accessor.body == null &&
source_reference != null && !source_reference.file.pkg) {
/* automatic property accessor body generation */
var field_type = prop.type_reference.copy ();
......@@ -395,3 +395,4 @@ public class Vala.Class : DataType {
return -1;
}
}
/* valanamespace.vala
*
* Copyright (C) 2006 Jürg Billeter
* Copyright (C) 2006-2007 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -67,7 +67,17 @@ public class Vala.Namespace : CodeNode {
classes.append (cl);
cl.@namespace = this;
}
/**
* Removes the specified class from this namespace.
*
* @param cl a class
*/
public void remove_class (Class! cl) {
cl.@namespace = null;
classes.remove (cl);
}
/**
* Adds the specified interface to this namespace.
*
......
......@@ -85,11 +85,46 @@ public class Vala.SymbolBuilder : CodeVisitor {
}
public override void visit_begin_class (Class! cl) {
if (add_symbol (cl.name, cl) == null) {
return;
var class_symbol = current_symbol.lookup (cl.name);
if (class_symbol == null || !(class_symbol.node is Class)) {
class_symbol = add_symbol (cl.name, cl);
} else {
/* merge this class declaration with existing class symbol */
var main_class = (Class) class_symbol.node;
foreach (TypeReference base_type in cl.get_base_types ()) {
main_class.add_base_type (base_type);
}
foreach (Field f in cl.get_fields ()) {
main_class.add_field (f);
}
foreach (Method m in cl.get_methods ()) {
main_class.add_method (m);
}
foreach (Property prop in cl.get_properties ()) {
main_class.add_property (prop, true);
}
foreach (Signal sig in cl.get_signals ()) {
main_class.add_signal (sig);
}
if (cl.constructor != null) {
if (main_class.constructor != null) {
cl.error = true;
Report.error (cl.constructor.source_reference, "`%s' already contains a constructor".printf (current_symbol.get_full_name ()));
return;
}
main_class.constructor = cl.constructor;
}
if (cl.destructor != null) {
if (main_class.destructor != null) {
cl.error = true;
Report.error (cl.destructor.source_reference, "`%s' already contains a destructor".printf (current_symbol.get_full_name ()));
return;
}
main_class.destructor = cl.destructor;
}
}
current_symbol = cl.symbol;
current_symbol = class_symbol;
}
public override void visit_end_class (Class! cl) {
......@@ -99,6 +134,11 @@ public class Vala.SymbolBuilder : CodeVisitor {
}
current_symbol = current_symbol.parent_symbol;
if (cl.symbol == null) {
/* remove merged class */
cl.@namespace.remove_class (cl);
}
}
public override void visit_begin_struct (Struct! st) {
......@@ -386,3 +426,4 @@ public class Vala.SymbolBuilder : CodeVisitor {
add_symbol (p.name, p);
}
}
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