2008-06-23 Jürg Billeter <j@bitron.ch>
+ * vala/valagenieparser.vala:
+ * vala/valanamespacereference.vala:
+ * vala/valasourcefile.vala:
+ * compiler/valacompiler.vala:
+
+ Import members of the GLib namespace by default, fixes bug 539596
+
+2008-06-23 Jürg Billeter <j@bitron.ch>
+
* gobject/valaccodedynamicpropertybinding.vala:
Support dynamic D-Bus properties
if (FileUtils.test (source, FileTest.EXISTS)) {
var rpath = realpath (source);
if (source.has_suffix (".vala") || source.has_suffix (".gs")) {
- context.add_source_file (new SourceFile (context, rpath));
+ var source_file = new SourceFile (context, rpath);
+
+ // import the GLib namespace by default (namespace of backend-specific standard library)
+ source_file.add_using_directive (new NamespaceReference ("GLib"));
+
+ context.add_source_file (source_file);
} else if (source.has_suffix (".vapi")) {
context.add_source_file (new SourceFile (context, rpath, true));
} else if (source.has_suffix (".c")) {
string class_name;
- /* we need to know whether to automatically add these using directives */
- bool has_uses_glib;
-
/* hack needed to know if any part of an expression is a lambda one */
bool current_expr_is_lambda;
construct {
tokens = new TokenInfo[BUFFER_SIZE];
- has_uses_glib = false;
class_name = null;
current_expr_is_lambda = false;
}
var ns_ref = new NamespaceReference (sym.name, get_src (begin));
scanner.source_file.add_using_directive (ns_ref);
-
- if (sym.name == "GLib") {
- has_uses_glib = true;
- }
}
void parse_using_directives () throws ParseError {
}
}
- if (!has_uses_glib) {
- var ns_ref = new NamespaceReference ("GLib", get_src (begin));
- scanner.source_file.add_using_directive (ns_ref);
- }
-
}
Symbol parse_class_declaration (Gee.List<Attribute>? attrs) throws ParseError {
/* valanamespacereference.vala
*
- * Copyright (C) 2006-2007 Jürg Billeter
+ * Copyright (C) 2006-2008 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
* @param source_reference reference to source code
* @return newly created namespace reference
*/
- public NamespaceReference (string name, SourceReference source_reference) {
- this.source_reference = source_reference;
+ public NamespaceReference (string name, SourceReference? source_reference = null) {
this.name = name;
+ this.source_reference = source_reference;
}
public override void accept (CodeVisitor visitor) {
* @param ns reference to namespace
*/
public void add_using_directive (NamespaceReference ns) {
+ foreach (NamespaceReference using_directive in using_directives) {
+ if (using_directive.name == ns.name) {
+ // ignore duplicates
+ return;
+ }
+ }
using_directives.add (ns);
}