[vala/parallel: 1/11] SourceFile: introduce SourceFileType enumeration



commit df928f19c4ac4d681cadaec25c2285c8749dc75b
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 +-
 9 files changed, 41 insertions(+), 37 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 5b4b39f..9e92ccd 100644
--- a/vala/valagenieparser.vala
+++ b/vala/valagenieparser.vala
@@ -2614,7 +2614,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;
@@ -2727,7 +2727,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) {
@@ -2763,7 +2763,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) {
@@ -2982,7 +2982,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;
@@ -3030,7 +3030,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;
 		}
 		
@@ -3112,7 +3112,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) {
@@ -3294,7 +3294,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);
@@ -3362,7 +3362,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);
@@ -3620,7 +3620,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;
 		}
 		
@@ -3681,7 +3681,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 04f0d59..a307b53 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -2334,7 +2334,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);
@@ -2348,7 +2348,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;
@@ -2394,7 +2394,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) {
@@ -2430,7 +2430,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) {
@@ -2600,7 +2600,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;
 		}
 
@@ -2647,7 +2647,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) {
@@ -2837,7 +2837,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);
@@ -2880,7 +2880,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);
@@ -2915,7 +2915,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);
@@ -2971,7 +2971,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);
@@ -3217,7 +3217,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;
 		}
 
@@ -3246,7 +3246,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..f4ff771 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 a46112f..89ac310 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);
 		}
 	}
 



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