summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorLuca Bruno <lethalman88@gmail.com>2010-08-23 18:21:31 +0200
committerJürg Billeter <j@bitron.ch>2010-10-03 22:17:39 +0200
commita4e5ac478be74988afa411b60300bb0d3aaa5dfa (patch)
tree343266762183d73f92a5ff3219b361635f030afa /compiler
parent6f4efc93f0ffff0a5da3965a61c96494fbc34665 (diff)
downloadvala-a4e5ac478be74988afa411b60300bb0d3aaa5dfa.tar.gz
Move source file adding logic to CodeContext
Diffstat (limited to 'compiler')
-rw-r--r--compiler/valacompiler.vala124
1 files changed, 9 insertions, 115 deletions
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 90182279f..33cfc1949 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -238,12 +238,12 @@ class Vala.Compiler {
context.includedir = includedir;
context.output = output;
if (basedir == null) {
- context.basedir = realpath (".");
+ context.basedir = CodeContext.realpath (".");
} else {
- context.basedir = realpath (basedir);
+ context.basedir = CodeContext.realpath (basedir);
}
if (directory != null) {
- context.directory = realpath (directory);
+ context.directory = CodeContext.realpath (directory);
} else {
context.directory = context.basedir;
}
@@ -337,7 +337,7 @@ class Vala.Compiler {
if (fast_vapis != null) {
foreach (string vapi in fast_vapis) {
- var rpath = realpath (vapi);
+ var rpath = CodeContext.realpath (vapi);
var source_file = new SourceFile (context, SourceFileType.FAST, rpath);
context.add_source_file (source_file);
}
@@ -365,43 +365,11 @@ class Vala.Compiler {
bool has_c_files = false;
foreach (string source in sources) {
- if (FileUtils.test (source, FileTest.EXISTS)) {
- var rpath = realpath (source);
- if (run_output || source.has_suffix (".vala") || source.has_suffix (".gs")) {
- var source_file = new SourceFile (context, SourceFileType.SOURCE, rpath);
- source_file.relative_filename = source;
-
- if (context.profile == Profile.POSIX) {
- // import the Posix namespace by default (namespace of backend-specific standard library)
- var ns_ref = new UsingDirective (new UnresolvedSymbol (null, "Posix", null));
- source_file.add_using_directive (ns_ref);
- context.root.add_using_directive (ns_ref);
- } else if (context.profile == Profile.GOBJECT) {
- // import the GLib namespace by default (namespace of backend-specific standard library)
- var ns_ref = new UsingDirective (new UnresolvedSymbol (null, "GLib", null));
- source_file.add_using_directive (ns_ref);
- context.root.add_using_directive (ns_ref);
- } else if (context.profile == Profile.DOVA) {
- // import the Dova namespace by default (namespace of backend-specific standard library)
- var ns_ref = new UsingDirective (new UnresolvedSymbol (null, "Dova", null));
- source_file.add_using_directive (ns_ref);
- context.root.add_using_directive (ns_ref);
- }
-
- context.add_source_file (source_file);
- } else if (source.has_suffix (".vapi") || source.has_suffix (".gir")) {
- var source_file = new SourceFile (context, SourceFileType.PACKAGE, rpath);
- source_file.relative_filename = source;
-
- context.add_source_file (source_file);
- } else if (source.has_suffix (".c")) {
- context.add_c_source_file (rpath);
- has_c_files = true;
- } else {
- Report.error (null, "%s is not a supported source file type. Only .vala, .vapi, .gs, and .c files are supported.".printf (source));
- }
- } else {
- Report.error (null, "%s not found".printf (source));
+ if (!context.add_source_filename (source, run_output)) {
+ break;
+ }
+ if (source.has_suffix (".c")) {
+ has_c_files = true;
}
}
sources = null;
@@ -566,80 +534,6 @@ class Vala.Compiler {
return quit ();
}
- private static bool ends_with_dir_separator (string s) {
- return Path.is_dir_separator (s.offset (s.length - 1).get_char ());
- }
-
- /* ported from glibc */
- private static string realpath (string name) {
- string rpath;
-
- // start of path component
- weak string start;
- // end of path component
- weak string end;
-
- if (!Path.is_absolute (name)) {
- // relative path
- rpath = Environment.get_current_dir ();
-
- start = end = name;
- } else {
- // set start after root
- start = end = Path.skip_root (name);
-
- // extract root
- rpath = name.substring (0, name.pointer_to_offset (start));
- }
-
- long root_len = rpath.pointer_to_offset (Path.skip_root (rpath));
-
- for (; start.get_char () != 0; start = end) {
- // skip sequence of multiple path-separators
- while (Path.is_dir_separator (start.get_char ())) {
- start = start.next_char ();
- }
-
- // find end of path component
- long len = 0;
- for (end = start; end.get_char () != 0 && !Path.is_dir_separator (end.get_char ()); end = end.next_char ()) {
- len++;
- }
-
- if (len == 0) {
- break;
- } else if (len == 1 && start.get_char () == '.') {
- // do nothing
- } else if (len == 2 && start.has_prefix ("..")) {
- // back up to previous component, ignore if at root already
- if (rpath.length > root_len) {
- do {
- rpath = rpath.substring (0, rpath.length - 1);
- } while (!ends_with_dir_separator (rpath));
- }
- } else {
- if (!ends_with_dir_separator (rpath)) {
- rpath += Path.DIR_SEPARATOR_S;
- }
-
- rpath += start.substring (0, len);
- }
- }
-
- if (rpath.length > root_len && ends_with_dir_separator (rpath)) {
- rpath = rpath.substring (0, rpath.length - 1);
- }
-
- if (Path.DIR_SEPARATOR != '/') {
- // don't use backslashes internally,
- // to avoid problems in #include directives
- string[] components = rpath.split ("\\");
- rpath = string.joinv ("/", components);
- }
-
- return rpath;
- }
-
static int run_source (string[] args) {
int i = 1;
if (args[i] != null && args[i].has_prefix ("-")) {