[vala/parallel] use CodeWriterType instead of bool construct args
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/parallel] use CodeWriterType instead of bool construct args
- Date: Sun, 22 Aug 2010 19:08:43 +0000 (UTC)
commit e1e0f2f89377a6605170d5c273aba377a002e491
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Aug 19 12:44:01 2010 -0400
use CodeWriterType instead of bool construct args
type can be EXTERNAL (default), INTERNAL, FAST, DUMP
compiler/valacompiler.vala | 7 ++---
vala/valacodewriter.vala | 65 ++++++++++++++++++++-----------------------
2 files changed, 33 insertions(+), 39 deletions(-)
---
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 5402a43..1424f0e 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -408,8 +408,7 @@ class Vala.Compiler {
}
if (fast_internal_vapi_filename != null) {
- var interface_writer = new CodeWriter (false, true);
- interface_writer.set_emit_using (true);
+ var interface_writer = new CodeWriter (CodeWriterType.FAST);
interface_writer.write_file (context, fast_internal_vapi_filename);
return quit ();
}
@@ -432,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);
}
@@ -512,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 7916b1b..b9c7465 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -37,16 +37,13 @@ public class Vala.CodeWriter : CodeVisitor {
Scope current_scope;
- bool dump_tree;
- bool emit_internal;
- bool emit_using;
+ 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;
}
/**
@@ -61,14 +58,6 @@ public class Vala.CodeWriter : CodeVisitor {
}
/**
- * Allows emitting 'using' into the output
- * @param enabled if using should be emitted
- */
- public void set_emit_using (bool enabled) {
- emit_using = enabled;
- }
-
- /**
* Writes the public interface of the specified code context into the
* specified file.
*
@@ -101,10 +90,8 @@ public class Vala.CodeWriter : CodeVisitor {
}
public override void visit_using_directive (UsingDirective ns) {
- if (emit_using) {
- var symbol_name = ns.namespace_symbol.name;
-
- write_string ("using %s;\n".printf (symbol_name));
+ if (type == CodeWriterType.FAST) {
+ write_string ("using %s;\n".printf (ns.namespace_symbol.name));
}
}
@@ -932,7 +919,7 @@ public class Vala.CodeWriter : CodeVisitor {
}
public override void visit_constructor (Constructor c) {
- if (!dump_tree) {
+ if (type != CodeWriterType.DUMP) {
return;
}
@@ -949,7 +936,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;
}
}
@@ -1872,7 +1859,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;
}
@@ -1898,22 +1885,23 @@ 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:
+ case CodeWriterType.FAST:
+ 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) {
@@ -1964,3 +1952,10 @@ public class Vala.CodeWriter : CodeVisitor {
}
}
}
+
+public enum CodeWriterType {
+ EXTERNAL,
+ INTERNAL,
+ FAST,
+ DUMP
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]