[vala/0.10-parallel: 9/32] CodeWriter: Introduce CodeWriterType enumeration



commit 7b9847de29a297e07310231655346f5d56a5b1ad
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Aug 24 19:10:24 2010 +0200

    CodeWriter: Introduce CodeWriterType enumeration
    
    CodeWriterType has 3 possible values:
      DUMP
      INTERNAL
      EXTERNAL
    
    and replaces CodeWriter.emit_internal and CodeWriter.dump_tree booleans
    with a new field called 'type'.

 compiler/valacompiler.vala |    4 +-
 vala/valacodewriter.vala   |   48 +++++++++++++++++++++++--------------------
 2 files changed, 28 insertions(+), 24 deletions(-)
---
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 37bf15c..b8a4550 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -431,7 +431,7 @@ class Vala.Compiler {
 		}
 
 		if (dump_tree != null) {
-			var code_writer = new CodeWriter (true);
+			var code_writer = new CodeWriter (CodeWriterType.DUMP);
 			code_writer.write_file (context, dump_tree);
 		}
 
@@ -511,7 +511,7 @@ class Vala.Compiler {
 				return quit();
 			}
 
-			var interface_writer = new CodeWriter (false, true);
+			var interface_writer = new CodeWriter (CodeWriterType.INTERNAL);
 			interface_writer.set_cheader_override(header_filename, internal_header_filename);
 			string vapi_filename = internal_vapi_filename;
 
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index 07bb4b6..cd3a6a8 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -37,15 +37,13 @@ public class Vala.CodeWriter : CodeVisitor {
 
 	Scope current_scope;
 
-	bool dump_tree;
-	bool emit_internal;
+	CodeWriterType type;
 
 	string? override_header = null;
 	string? header_to_override = null;
 
-	public CodeWriter (bool dump_tree = false, bool emit_internal = false) {
-		this.dump_tree = dump_tree;
-		this.emit_internal = emit_internal;
+	public CodeWriter (CodeWriterType type = CodeWriterType.EXTERNAL) {
+		this.type = type;
 	}
 
 	/**
@@ -919,7 +917,7 @@ public class Vala.CodeWriter : CodeVisitor {
 	}
 
 	public override void visit_constructor (Constructor c) {
-		if (!dump_tree) {
+		if (type != CodeWriterType.DUMP) {
 			return;
 		}
 
@@ -936,7 +934,7 @@ public class Vala.CodeWriter : CodeVisitor {
 
 		// don't write interface implementation unless it's an abstract or virtual method
 		if (!check_accessibility (m) || (m.base_interface_method != null && !m.is_abstract && !m.is_virtual)) {
-			if (!dump_tree) {
+			if (type != CodeWriterType.DUMP) {
 				return;
 			}
 		}
@@ -1867,7 +1865,7 @@ public class Vala.CodeWriter : CodeVisitor {
 	}
 	
 	void write_code_block (Block? block) {
-		if (block == null || !dump_tree) {
+		if (block == null || type != CodeWriterType.DUMP) {
 			write_string (";");
 			return;
 		}
@@ -1893,22 +1891,22 @@ public class Vala.CodeWriter : CodeVisitor {
 	}
 
 	private bool check_accessibility (Symbol sym) {
-		if (dump_tree) {
-			return true;
-		} else {
-		    if (!emit_internal &&
-			( sym.access == SymbolAccessibility.PUBLIC ||
-			  sym.access == SymbolAccessibility.PROTECTED)) {
-			return true;
-		    } else if (emit_internal &&
-			( sym.access == SymbolAccessibility.INTERNAL ||
-			  sym.access == SymbolAccessibility.PUBLIC ||
-			  sym.access == SymbolAccessibility.PROTECTED)) {
+		switch (type) {
+		case CodeWriterType.EXTERNAL:
+			return sym.access == SymbolAccessibility.PUBLIC ||
+			       sym.access == SymbolAccessibility.PROTECTED;
+
+		case CodeWriterType.INTERNAL:
+			return sym.access == SymbolAccessibility.INTERNAL ||
+			       sym.access == SymbolAccessibility.PUBLIC ||
+			       sym.access == SymbolAccessibility.PROTECTED;
+
+		case CodeWriterType.DUMP:
 			return true;
-		    }
-		}
 
-		return false;
+		default:
+			assert_not_reached ();
+		}
 	}
 
 	private void write_attributes (CodeNode node) {
@@ -1957,3 +1955,9 @@ public class Vala.CodeWriter : CodeVisitor {
 		}
 	}
 }
+
+public enum CodeWriterType {
+	EXTERNAL,
+	INTERNAL,
+	DUMP
+}



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