Commit b0a16279 authored by Allison Karlitskaya's avatar Allison Karlitskaya Committed by Jürg Billeter

SourceFile: Introduce SourceFileType enumeration

SourceFileType has 2 possible values:
  SOURCE
  PACKAGE

and replaces the CodeWriter.external_package boolean with a new field
called 'file_type'.
parent 3b5d28ea
......@@ -417,7 +417,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
/* we're only interested in non-pkg source files */
var source_files = context.get_source_files ();
foreach (SourceFile file in source_files) {
if (!file.external_package) {
if (file.file_type == SourceFileType.SOURCE) {
file.accept (this);
}
}
......@@ -751,7 +751,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
return;
}
if (!c.external) {
if (c.source_reference.file.file_type != SourceFileType.PACKAGE) {
generate_type_declaration (c.type_reference, decl_space);
c.value.emit (this);
......
......@@ -105,7 +105,7 @@ public class Vala.CCodeCompiler {
/* we're only interested in non-pkg source files */
var source_files = context.get_source_files ();
foreach (SourceFile file in source_files) {
if (!file.external_package) {
if (file.file_type == SourceFileType.SOURCE) {
cmdline += " " + Shell.quote (file.get_csource_filename ());
}
}
......@@ -137,7 +137,7 @@ public class Vala.CCodeCompiler {
/* remove generated C source and header files */
foreach (SourceFile file in source_files) {
if (!file.external_package) {
if (file.file_type == SourceFileType.SOURCE) {
if (!context.save_csources) {
FileUtils.unlink (file.get_csource_filename ());
}
......
......@@ -292,7 +292,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
/* we're only interested in non-pkg source files */
var source_files = context.get_source_files ();
foreach (SourceFile file in source_files) {
if (!file.external_package) {
if (file.file_type == SourceFileType.SOURCE) {
file.accept (this);
}
}
......
......@@ -151,7 +151,7 @@ class Vala.Compiler {
return false;
}
context.add_source_file (new SourceFile (context, gir_path, true));
context.add_source_file (new SourceFile (context, SourceFileType.PACKAGE, gir_path));
return true;
}
......@@ -170,7 +170,7 @@ class Vala.Compiler {
context.add_package (pkg);
context.add_source_file (new SourceFile (context, package_path, true));
context.add_source_file (new SourceFile (context, SourceFileType.PACKAGE, package_path));
var deps_filename = Path.build_filename (Path.get_dirname (package_path), "%s.deps".printf (pkg));
if (FileUtils.test (deps_filename, FileTest.EXISTS)) {
......@@ -352,7 +352,7 @@ class Vala.Compiler {
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, rpath);
var source_file = new SourceFile (context, SourceFileType.SOURCE, rpath);
source_file.relative_filename = source;
if (context.profile == Profile.POSIX) {
......@@ -374,7 +374,7 @@ class Vala.Compiler {
context.add_source_file (source_file);
} else if (source.has_suffix (".vapi") || source.has_suffix (".gir")) {
var source_file = new SourceFile (context, rpath, true);
var source_file = new SourceFile (context, SourceFileType.PACKAGE, rpath);
source_file.relative_filename = source;
context.add_source_file (source_file);
......
......@@ -108,7 +108,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
/* we're only interested in non-pkg source files */
var source_files = context.get_source_files ();
foreach (SourceFile file in source_files) {
if (!file.external_package) {
if (file.file_type == SourceFileType.SOURCE) {
file.accept (this);
}
}
......
......@@ -2638,7 +2638,7 @@ public class Vala.Genie.Parser : CodeVisitor {
parse_declarations (cl);
// ensure there is always a default construction method
if (!scanner.source_file.external_package
if (scanner.source_file.file_type == SourceFileType.SOURCE
&& cl.default_construction_method == null) {
var m = new CreationMethod (cl.name, null, cl.source_reference);
m.access = SymbolAccessibility.PUBLIC;
......@@ -2751,7 +2751,7 @@ public class Vala.Genie.Parser : CodeVisitor {
var c = new Constant (id, type, initializer, get_src (begin), comment);
c.access = get_access (id);
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
c.external = true;
}
if (ModifierFlags.NEW in flags) {
......@@ -2787,7 +2787,7 @@ public class Vala.Genie.Parser : CodeVisitor {
set_attributes (f, attrs);
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
f.external = true;
}
if (ModifierFlags.NEW in flags) {
......@@ -3006,7 +3006,7 @@ public class Vala.Genie.Parser : CodeVisitor {
if (accept_block ()) {
method.body = parse_block ();
} else if (scanner.source_file.external_package) {
} else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
method.external = true;
}
return method;
......@@ -3054,7 +3054,7 @@ public class Vala.Genie.Parser : CodeVisitor {
if (ModifierFlags.NEW in flags) {
prop.hides = true;
}
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
prop.external = true;
}
......@@ -3136,7 +3136,7 @@ public class Vala.Genie.Parser : CodeVisitor {
expect_terminator ();
}
if (!prop.is_abstract && !scanner.source_file.external_package) {
if (!prop.is_abstract && scanner.source_file.file_type == SourceFileType.SOURCE) {
var needs_var = (readonly && (prop.get_accessor != null && prop.get_accessor.body == null));
if (!needs_var) {
......@@ -3318,7 +3318,7 @@ public class Vala.Genie.Parser : CodeVisitor {
} else {
iface.access = get_access (sym.name);
}
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
iface.external = true;
}
set_attributes (iface, attrs);
......@@ -3386,7 +3386,7 @@ public class Vala.Genie.Parser : CodeVisitor {
} else {
en.access = get_access (sym.name);
}
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
en.external = true;
}
set_attributes (en, attrs);
......@@ -3644,7 +3644,7 @@ public class Vala.Genie.Parser : CodeVisitor {
if (accept_block ()) {
method.body = parse_block ();
} else if (scanner.source_file.external_package) {
} else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
method.external = true;
}
......@@ -3705,7 +3705,7 @@ public class Vala.Genie.Parser : CodeVisitor {
if (!(ModifierFlags.STATIC in flags)) {
d.has_target = true;
}
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
d.external = true;
}
......
......@@ -2360,7 +2360,7 @@ public class Vala.Parser : CodeVisitor {
if (ModifierFlags.ABSTRACT in flags) {
cl.is_abstract = true;
}
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
cl.external = true;
}
set_attributes (cl, attrs);
......@@ -2374,7 +2374,7 @@ public class Vala.Parser : CodeVisitor {
parse_declarations (cl);
// ensure there is always a default construction method
if (!scanner.source_file.external_package
if (scanner.source_file.file_type == SourceFileType.SOURCE
&& cl.default_construction_method == null) {
var m = new CreationMethod (cl.name, null, cl.source_reference);
m.access = SymbolAccessibility.PUBLIC;
......@@ -2420,7 +2420,7 @@ public class Vala.Parser : CodeVisitor {
var c = new Constant (id, type, initializer, get_src (begin), comment);
c.access = access;
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
c.external = true;
}
if (ModifierFlags.NEW in flags) {
......@@ -2456,7 +2456,7 @@ public class Vala.Parser : CodeVisitor {
|| ModifierFlags.OVERRIDE in flags) {
Report.error (f.source_reference, "abstract, virtual, and override modifiers are not applicable to fields");
}
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
f.external = true;
}
if (ModifierFlags.NEW in flags) {
......@@ -2626,7 +2626,7 @@ public class Vala.Parser : CodeVisitor {
}
if (!accept (TokenType.SEMICOLON)) {
method.body = parse_block ();
} else if (scanner.source_file.external_package) {
} else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
method.external = true;
}
......@@ -2673,7 +2673,7 @@ public class Vala.Parser : CodeVisitor {
if (ModifierFlags.ASYNC in flags) {
Report.error (prop.source_reference, "async properties are not supported yet");
}
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
prop.external = true;
}
if (context.profile == Profile.DOVA) {
......@@ -2863,7 +2863,7 @@ public class Vala.Parser : CodeVisitor {
}
var st = new Struct (sym.name, get_src (begin), comment);
st.access = access;
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
st.external = true;
}
set_attributes (st, attrs);
......@@ -2906,7 +2906,7 @@ public class Vala.Parser : CodeVisitor {
}
var iface = new Interface (sym.name, get_src (begin), comment);
iface.access = access;
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
iface.external = true;
}
set_attributes (iface, attrs);
......@@ -2941,7 +2941,7 @@ public class Vala.Parser : CodeVisitor {
var sym = parse_symbol_name ();
var en = new Enum (sym.name, get_src (begin), comment);
en.access = access;
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
en.external = true;
}
set_attributes (en, attrs);
......@@ -2997,7 +2997,7 @@ public class Vala.Parser : CodeVisitor {
var sym = parse_symbol_name ();
var ed = new ErrorDomain (sym.name, get_src (begin), comment);
ed.access = access;
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
ed.external = true;
}
set_attributes (ed, attrs);
......@@ -3243,7 +3243,7 @@ public class Vala.Parser : CodeVisitor {
set_attributes (method, attrs);
if (!accept (TokenType.SEMICOLON)) {
method.body = parse_block ();
} else if (scanner.source_file.external_package) {
} else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
method.external = true;
}
......@@ -3272,7 +3272,7 @@ public class Vala.Parser : CodeVisitor {
} else {
d.has_target = true;
}
if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
d.external = true;
}
foreach (TypeParameter type_param in type_param_list) {
......
......@@ -40,7 +40,7 @@ public class Vala.SourceFile {
/**
* Specifies whether this file is a VAPI package file.
*/
public bool external_package { get; set; }
public SourceFileType file_type { get; set; }
/**
* GIR Namespace for this source file, if it's a VAPI package
......@@ -91,10 +91,10 @@ public class Vala.SourceFile {
* @param pkg true if this is a VAPI package file
* @return newly created source file
*/
public SourceFile (CodeContext context, string filename, bool pkg = false, string? content = null) {
this.filename = filename;
this.external_package = pkg;
public SourceFile (CodeContext context, SourceFileType type, string filename, string? content = null) {
this.context = context;
this.file_type = type;
this.filename = filename;
this.content = content;
}
......@@ -314,3 +314,7 @@ public class Vala.SourceFile {
}
}
public enum SourceFileType {
SOURCE,
PACKAGE
}
......@@ -156,7 +156,7 @@ public abstract class Vala.Symbol : CodeNode {
*/
public bool external_package {
get {
return (source_reference != null && source_reference.file.external_package);
return (source_reference != null && source_reference.file.file_type == SourceFileType.PACKAGE);
}
}
......
......@@ -24,8 +24,8 @@ using GLib;
class Vala.VAPICheck : Object {
public VAPICheck (string gidlname, CodeContext context = new CodeContext ()) {
gidl = new SourceFile (context, gidlname);
metadata = new SourceFile (context, gidlname.substring (0, gidlname.length - 5) + ".metadata");
gidl = new SourceFile (context, SourceFileType.SOURCE, gidlname);
metadata = new SourceFile (context, SourceFileType.SOURCE, gidlname.substring (0, gidlname.length - 5) + ".metadata");
this.context = context;
}
......
......@@ -77,7 +77,7 @@ class Vala.VAPIGen : Object {
context.add_package (pkg);
context.add_source_file (new SourceFile (context, package_path, true));
context.add_source_file (new SourceFile (context, SourceFileType.PACKAGE, package_path));
var deps_filename = Path.build_filename (Path.get_dirname (package_path), "%s.deps".printf (pkg));
if (FileUtils.test (deps_filename, FileTest.EXISTS)) {
......@@ -176,7 +176,7 @@ class Vala.VAPIGen : Object {
foreach (string source in sources) {
if (FileUtils.test (source, FileTest.EXISTS)) {
context.add_source_file (new SourceFile (context, source, true));
context.add_source_file (new SourceFile (context, SourceFileType.PACKAGE, source));
} else {
Report.error (null, "%s not found".printf (source));
}
......@@ -240,7 +240,7 @@ class Vala.VAPIGen : Object {
// interface writer ignores external packages
foreach (SourceFile file in context.get_source_files ()) {
if (!file.filename.has_suffix (".vapi")) {
file.external_package = false;
file.file_type = SourceFileType.SOURCE;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment