[vala] SourceFile: Introduce SourceFileType enumeration



commit b0a16279ff67cb54054d6c12c681abc4f4541f6f
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Aug 24 19:01:39 2010 +0200

    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'.

 codegen/valaccodebasemodule.vala |    4 ++--
 codegen/valaccodecompiler.vala   |    4 ++--
 codegen/valadovabasemodule.vala  |    2 +-
 compiler/valacompiler.vala       |    8 ++++----
 vala/valaflowanalyzer.vala       |    2 +-
 vala/valagenieparser.vala        |   20 ++++++++++----------
 vala/valaparser.vala             |   24 ++++++++++++------------
 vala/valasourcefile.vala         |   12 ++++++++----
 vala/valasymbol.vala             |    2 +-
 vapigen/valavapicheck.vala       |    4 ++--
 vapigen/valavapigen.vala         |    6 +++---
 11 files changed, 46 insertions(+), 42 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index fcfe5c9..8bb281d 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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);
diff --git a/codegen/valaccodecompiler.vala b/codegen/valaccodecompiler.vala
index 6bec313..09ab3d6 100644
--- a/codegen/valaccodecompiler.vala
+++ b/codegen/valaccodecompiler.vala
@@ -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 ());
 				}
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index de3c3ca..4e35053 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -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);
 			}
 		}
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 0e313a4..49383da 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -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);
diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala
index 74c35f6..5394e86 100644
--- a/vala/valaflowanalyzer.vala
+++ b/vala/valaflowanalyzer.vala
@@ -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);
 			}
 		}
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index 0649c28..36a8d52 100644
--- a/vala/valagenieparser.vala
+++ b/vala/valagenieparser.vala
@@ -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;
 		}
 
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index edc4813..4de1f23 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -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) {
diff --git a/vala/valasourcefile.vala b/vala/valasourcefile.vala
index e58e009..ff4be85 100644
--- a/vala/valasourcefile.vala
+++ b/vala/valasourcefile.vala
@@ -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
+}
diff --git a/vala/valasymbol.vala b/vala/valasymbol.vala
index 9bea678..0df385d 100644
--- a/vala/valasymbol.vala
+++ b/vala/valasymbol.vala
@@ -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);
 		}
 	}
 
diff --git a/vapigen/valavapicheck.vala b/vapigen/valavapicheck.vala
index b6fa644..daa8776 100644
--- a/vapigen/valavapicheck.vala
+++ b/vapigen/valavapicheck.vala
@@ -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;
 	}
 
diff --git a/vapigen/valavapigen.vala b/vapigen/valavapigen.vala
index 403fa89..577d519 100644
--- a/vapigen/valavapigen.vala
+++ b/vapigen/valavapigen.vala
@@ -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;
 				}
 	 		}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]