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
iterable in foreach statements, fixes bug 434514
*
* @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 ();
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
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.
*
}
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) {
}
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) {
add_symbol (p.name, p);
}
}
+