From: Rico Tzschichholz Date: Tue, 19 Mar 2019 12:42:13 +0000 (+0100) Subject: vala: Add CodeContext.get_source_file() and perform some sanity checks X-Git-Tag: 0.45.1~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67a8ac1983aca5217b5d1c733594a89c86b662e6;p=thirdparty%2Fvala.git vala: Add CodeContext.get_source_file() and perform some sanity checks --- diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 8b1a78be4..42e6dabb2 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -203,6 +203,7 @@ public class Vala.CodeContext { public string[] gresources_directories { get; set; default = {}; } private List source_files = new ArrayList (); + private Map source_files_map = new HashMap (str_hash, str_equal); private List c_source_files = new ArrayList (); private Namespace _root = new Namespace (null); @@ -302,7 +303,23 @@ public class Vala.CodeContext { * @param file a source file */ public void add_source_file (SourceFile file) { + if (source_files_map.contains (file.filename)) { + Report.warning (null, "Ignoring source file `%s', which was already added to this context".printf (file.filename)); + return; + } + source_files.add (file); + source_files_map.set (file.filename, file); + } + + /** + * Returns the source file for a given path. + * + * @param filename a path to a source file + * @return the source file if found + */ + public unowned Vala.SourceFile? get_source_file (string filename) { + return source_files_map.get (filename); } /** @@ -445,11 +462,17 @@ public class Vala.CodeContext { } add_source_file (source_file); + if (rpath != filename) { + source_files_map.set (filename, source_file); + } } else if (filename.has_suffix (".vapi") || filename.has_suffix (".gir")) { var source_file = new SourceFile (this, SourceFileType.PACKAGE, rpath, null, cmdline); source_file.relative_filename = filename; add_source_file (source_file); + if (rpath != filename) { + source_files_map.set (filename, source_file); + } } else if (filename.has_suffix (".c")) { add_c_source_file (rpath); } else if (filename.has_suffix (".h")) { diff --git a/vala/valasourcefile.vala b/vala/valasourcefile.vala index 35eaf5f26..4dca01224 100644 --- a/vala/valasourcefile.vala +++ b/vala/valasourcefile.vala @@ -29,7 +29,7 @@ public class Vala.SourceFile { /** * The name of this source file. */ - public string filename { get; set; } + public string filename { get; private set; } public string? relative_filename { set { diff --git a/vapigen/valavapigen.vala b/vapigen/valavapigen.vala index 63205499d..ef0b37200 100644 --- a/vapigen/valavapigen.vala +++ b/vapigen/valavapigen.vala @@ -184,10 +184,9 @@ class Vala.VAPIGen { // mark relative metadata as source string? metadata_filename = context.get_metadata_path (file.filename); if (metadata_filename != null) { - foreach (SourceFile metadata_file in context.get_source_files ()) { - if (metadata_file.filename == metadata_filename) { - metadata_file.file_type = SourceFileType.SOURCE; - } + unowned SourceFile? metadata_file = context.get_source_file (metadata_filename); + if (metadata_file != null) { + metadata_file.file_type = SourceFileType.SOURCE; } } if (file.from_commandline && file.package_name != null) {