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> 2007-04-30 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: check whether specified collection is * vala/valasemanticanalyzer.vala: check whether specified collection is
......
...@@ -2401,7 +2401,7 @@ class_member_declaration ...@@ -2401,7 +2401,7 @@ class_member_declaration
{ {
/* skip declarations with errors */ /* skip declarations with errors */
if ($1 != NULL) { if ($1 != NULL) {
vala_class_add_property (current_class, $1); vala_class_add_property (current_class, $1, FALSE);
g_object_unref ($1); g_object_unref ($1);
} }
} }
......
...@@ -188,10 +188,10 @@ public class Vala.Class : DataType { ...@@ -188,10 +188,10 @@ public class Vala.Class : DataType {
* *
* @param prop a property * @param prop a property
*/ */
public void add_property (Property! prop) { public void add_property (Property! prop, bool no_field = false) {
properties.append (prop); 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) { source_reference != null && !source_reference.file.pkg) {
/* automatic property accessor body generation */ /* automatic property accessor body generation */
var field_type = prop.type_reference.copy (); var field_type = prop.type_reference.copy ();
...@@ -395,3 +395,4 @@ public class Vala.Class : DataType { ...@@ -395,3 +395,4 @@ public class Vala.Class : DataType {
return -1; return -1;
} }
} }
/* valanamespace.vala /* 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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -67,7 +67,17 @@ public class Vala.Namespace : CodeNode { ...@@ -67,7 +67,17 @@ public class Vala.Namespace : CodeNode {
classes.append (cl); classes.append (cl);
cl.@namespace = this; 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. * Adds the specified interface to this namespace.
* *
......
...@@ -85,11 +85,46 @@ public class Vala.SymbolBuilder : CodeVisitor { ...@@ -85,11 +85,46 @@ public class Vala.SymbolBuilder : CodeVisitor {
} }
public override void visit_begin_class (Class! cl) { public override void visit_begin_class (Class! cl) {
if (add_symbol (cl.name, cl) == null) { var class_symbol = current_symbol.lookup (cl.name);
return; 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) { public override void visit_end_class (Class! cl) {
...@@ -99,6 +134,11 @@ public class Vala.SymbolBuilder : CodeVisitor { ...@@ -99,6 +134,11 @@ public class Vala.SymbolBuilder : CodeVisitor {
} }
current_symbol = current_symbol.parent_symbol; 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) { public override void visit_begin_struct (Struct! st) {
...@@ -386,3 +426,4 @@ public class Vala.SymbolBuilder : CodeVisitor { ...@@ -386,3 +426,4 @@ public class Vala.SymbolBuilder : CodeVisitor {
add_symbol (p.name, p); 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