[vala/staging: 5/5] vala: Add CodeContext.get_source_file() and perform some sanity checks
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 5/5] vala: Add CodeContext.get_source_file() and perform some sanity checks
- Date: Tue, 19 Mar 2019 15:13:52 +0000 (UTC)
commit 75394368658d3b3a28bfae30c7e5b951b180e11a
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Mar 19 13:42:13 2019 +0100
vala: Add CodeContext.get_source_file() and perform some sanity checks
vala/valacodecontext.vala | 23 +++++++++++++++++++++++
vala/valasourcefile.vala | 2 +-
vapigen/valavapigen.vala | 7 +++----
3 files changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala
index 8b1a78be4..6b6043e25 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<SourceFile> source_files = new ArrayList<SourceFile> ();
+ private Map<string,unowned SourceFile> source_files_map = new HashMap<string,unowned SourceFile> ();
private List<string> c_source_files = new ArrayList<string> ();
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 path a path to a source file
+ * @return the source file if found
+ */
+ public unowned Vala.SourceFile? get_source_file (string path) {
+ return source_files_map.get (path);
}
/**
@@ -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) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]