[vala] dova: Write all C code to a single file
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] dova: Write all C code to a single file
- Date: Sun, 11 Jul 2010 13:23:32 +0000 (UTC)
commit 379353d74d78ea12011839f973891e8d20dfdbb9
Author: Jürg Billeter <j bitron ch>
Date: Sun Jul 11 14:24:16 2010 +0200
dova: Write all C code to a single file
This extends possibilities of internal members and enables global
optimizations by the C compiler.
codegen/valadovabasemodule.vala | 118 +++++++++++++++--------------------
codegen/valadovadelegatemodule.vala | 7 +--
codegen/valadovaobjectmodule.vala | 44 +++++++++----
codegen/valadovastructmodule.vala | 1 -
codegen/valadovavaluemodule.vala | 13 ++--
5 files changed, 90 insertions(+), 93 deletions(-)
---
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 94cce07..2526caa 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -113,9 +113,10 @@ internal class Vala.DovaBaseModule : CCodeModule {
}
public CCodeDeclarationSpace header_declarations;
- public CCodeDeclarationSpace internal_header_declarations;
public CCodeDeclarationSpace source_declarations;
+ string? csource_filename;
+
public CCodeFragment source_type_member_definition;
public CCodeFragment instance_init_fragment;
public CCodeFragment instance_finalize_fragment;
@@ -238,7 +239,16 @@ internal class Vala.DovaBaseModule : CCodeModule {
error_class = (Class) dova_ns.scope.lookup ("Error");
header_declarations = new CCodeDeclarationSpace ();
- internal_header_declarations = new CCodeDeclarationSpace ();
+
+
+ source_declarations = new CCodeDeclarationSpace ();
+ source_type_member_definition = new CCodeFragment ();
+
+ next_temp_var_id = 0;
+ variable_name_map.clear ();
+
+ generated_external_symbols = new HashSet<Symbol> ();
+
/* we're only interested in non-pkg source files */
var source_files = context.get_source_files ();
@@ -248,6 +258,36 @@ internal class Vala.DovaBaseModule : CCodeModule {
}
}
+ if (csource_filename != null) {
+ var writer = new CCodeWriter (csource_filename);
+ if (!writer.open (context.version_header)) {
+ Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
+ return;
+ }
+ writer.line_directives = context.debug;
+
+ writer.write_newline ();
+ source_declarations.include_directives.write (writer);
+ writer.write_newline ();
+ source_declarations.type_declaration.write_combined (writer);
+ writer.write_newline ();
+ source_declarations.type_definition.write_combined (writer);
+ writer.write_newline ();
+ source_declarations.type_member_declaration.write_declaration (writer);
+ writer.write_newline ();
+ source_declarations.type_member_declaration.write (writer);
+ writer.write_newline ();
+ source_declarations.constant_declaration.write_combined (writer);
+ writer.write_newline ();
+ source_type_member_definition.write (writer);
+ writer.write_newline ();
+ writer.close ();
+ }
+
+ source_declarations = null;
+ source_type_member_definition = null;
+
+
// generate C header file for public API
if (context.header_filename != null) {
var writer = new CCodeWriter (context.header_filename);
@@ -276,78 +316,25 @@ internal class Vala.DovaBaseModule : CCodeModule {
once.write (writer);
writer.close ();
}
+ }
- // generate C header file for internal API
- if (context.internal_header_filename != null) {
- var writer = new CCodeWriter (context.internal_header_filename);
+ public override void visit_source_file (SourceFile source_file) {
+ if (csource_filename == null) {
+ csource_filename = source_file.get_csource_filename ();
+ } else {
+ var writer = new CCodeWriter (source_file.get_csource_filename ());
if (!writer.open (context.version_header)) {
Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
return;
}
- writer.write_newline ();
-
- var once = new CCodeOnceSection (get_define_for_filename (writer.filename));
- once.append (new CCodeNewline ());
- once.append (internal_header_declarations.include_directives);
- once.append (new CCodeNewline ());
-
- once.append (new CCodeNewline ());
- once.append (internal_header_declarations.type_declaration);
- once.append (new CCodeNewline ());
- once.append (internal_header_declarations.type_definition);
- once.append (new CCodeNewline ());
- once.append (internal_header_declarations.type_member_declaration);
- once.append (new CCodeNewline ());
- once.append (internal_header_declarations.constant_declaration);
- once.append (new CCodeNewline ());
-
- once.append (new CCodeNewline ());
- once.write (writer);
writer.close ();
}
- }
-
- public override void visit_source_file (SourceFile source_file) {
- source_declarations = new CCodeDeclarationSpace ();
- source_type_member_definition = new CCodeFragment ();
-
- next_temp_var_id = 0;
- variable_name_map.clear ();
-
- generated_external_symbols = new HashSet<Symbol> ();
source_file.accept_children (codegen);
if (context.report.get_errors () > 0) {
return;
}
-
- var writer = new CCodeWriter (source_file.get_csource_filename ());
- if (!writer.open (context.version_header)) {
- Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
- return;
- }
- writer.line_directives = context.debug;
-
- writer.write_newline ();
- source_declarations.include_directives.write (writer);
- writer.write_newline ();
- source_declarations.type_declaration.write_combined (writer);
- writer.write_newline ();
- source_declarations.type_definition.write_combined (writer);
- writer.write_newline ();
- source_declarations.type_member_declaration.write_declaration (writer);
- writer.write_newline ();
- source_declarations.type_member_declaration.write (writer);
- writer.write_newline ();
- source_declarations.constant_declaration.write_combined (writer);
- writer.write_newline ();
- source_type_member_definition.write (writer);
- writer.write_newline ();
- writer.close ();
-
- source_declarations = null;
- source_type_member_definition = null;
}
private static string get_define_for_filename (string filename) {
@@ -398,7 +385,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
if (!en.is_internal_symbol ()) {
generate_enum_declaration (en, header_declarations);
}
- generate_enum_declaration (en, internal_header_declarations);
}
public override void visit_member (Member m) {
@@ -435,7 +421,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
if (!c.is_internal_symbol ()) {
generate_constant_declaration (c, header_declarations);
}
- generate_constant_declaration (c, internal_header_declarations);
}
public void generate_field_declaration (Field f, CCodeDeclarationSpace decl_space) {
@@ -452,7 +437,7 @@ internal class Vala.DovaBaseModule : CCodeModule {
var cdecl = new CCodeDeclaration (field_ctype);
cdecl.add_declarator (new CCodeVariableDeclarator (f.get_cname ()));
- if (f.is_private_symbol ()) {
+ if (f.is_internal_symbol ()) {
cdecl.modifiers = CCodeModifiers.STATIC;
} else {
cdecl.modifiers = CCodeModifiers.EXTERN;
@@ -473,7 +458,7 @@ internal class Vala.DovaBaseModule : CCodeModule {
}
if (f.binding == MemberBinding.INSTANCE) {
- if (cl != null && f.access == SymbolAccessibility.PRIVATE) {
+ if (cl != null && f.is_internal_symbol ()) {
var priv_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_PRIVATE".printf (cl.get_upper_case_cname (null))));
priv_call.add_argument (new CCodeIdentifier ("this"));
lhs = new CCodeMemberAccess.pointer (priv_call, f.get_cname ());
@@ -511,7 +496,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
if (!f.is_internal_symbol ()) {
generate_field_declaration (f, header_declarations);
}
- generate_field_declaration (f, internal_header_declarations);
lhs = new CCodeIdentifier (f.get_cname ());
@@ -527,7 +511,7 @@ internal class Vala.DovaBaseModule : CCodeModule {
var var_def = new CCodeDeclaration (field_ctype);
var_def.add_declarator (var_decl);
- if (!f.is_private_symbol ()) {
+ if (!f.is_internal_symbol ()) {
var_def.modifiers = CCodeModifiers.EXTERN;
} else {
var_def.modifiers = CCodeModifiers.STATIC;
diff --git a/codegen/valadovadelegatemodule.vala b/codegen/valadovadelegatemodule.vala
index 41edade..6a9d62c 100644
--- a/codegen/valadovadelegatemodule.vala
+++ b/codegen/valadovadelegatemodule.vala
@@ -60,7 +60,7 @@ internal class Vala.DovaDelegateModule : DovaValueModule {
CCodeFunction generate_new_function (Delegate d, CCodeDeclarationSpace decl_space) {
var function = new CCodeFunction ("%s_new".printf (d.get_lower_case_cname ()), "%s*".printf (d.get_cname ()));
- if (d.is_private_symbol ()) {
+ if (d.is_internal_symbol ()) {
function.modifiers |= CCodeModifiers.STATIC;
}
@@ -94,7 +94,7 @@ internal class Vala.DovaDelegateModule : DovaValueModule {
CCodeFunction generate_invoke_function (Delegate d, CCodeDeclarationSpace decl_space) {
var function = new CCodeFunction ("%s_invoke".printf (d.get_lower_case_cname ()));
- if (d.is_private_symbol ()) {
+ if (d.is_internal_symbol ()) {
function.modifiers |= CCodeModifiers.STATIC;
}
@@ -190,9 +190,6 @@ internal class Vala.DovaDelegateModule : DovaValueModule {
if (!d.is_internal_symbol ()) {
generate_delegate_declaration (d, header_declarations);
}
- if (!d.is_private_symbol ()) {
- generate_delegate_declaration (d, internal_header_declarations);
- }
generate_type_get_function (d, delegate_class);
diff --git a/codegen/valadovaobjectmodule.vala b/codegen/valadovaobjectmodule.vala
index 1ebe2fa..a673d49 100644
--- a/codegen/valadovaobjectmodule.vala
+++ b/codegen/valadovaobjectmodule.vala
@@ -76,12 +76,18 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
generate_method_declaration ((Method) object_class.scope.lookup ("unref"), decl_space);
var type_fun = new CCodeFunction ("%s_type_get".printf (cl.get_lower_case_cname ()), "DovaType *");
+ if (cl.is_internal_symbol ()) {
+ type_fun.modifiers = CCodeModifiers.STATIC;
+ }
foreach (var type_param in cl.get_type_parameters ()) {
type_fun.add_parameter (new CCodeFormalParameter ("%s_type".printf (type_param.name.down ()), "DovaType *"));
}
decl_space.add_type_member_declaration (type_fun);
var type_init_fun = new CCodeFunction ("%s_type_init".printf (cl.get_lower_case_cname ()));
+ if (cl.is_internal_symbol ()) {
+ type_init_fun.modifiers = CCodeModifiers.STATIC;
+ }
type_init_fun.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
foreach (var type_param in cl.get_type_parameters ()) {
type_init_fun.add_parameter (new CCodeFormalParameter ("%s_type".printf (type_param.name.down ()), "DovaType *"));
@@ -316,6 +322,9 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
source_declarations.add_type_member_declaration (cdecl);
var type_fun = new CCodeFunction ("%s_type_get".printf (cl.get_lower_case_cname ()), "DovaType *");
+ if (cl.is_internal_symbol ()) {
+ type_fun.modifiers = CCodeModifiers.STATIC;
+ }
var object_type_symbol = cl as ObjectTypeSymbol;
if (object_type_symbol != null) {
@@ -461,6 +470,9 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
source_type_member_definition.append (type_fun);
var type_init_fun = new CCodeFunction ("%s_type_init".printf (cl.get_lower_case_cname ()));
+ if (cl.is_internal_symbol ()) {
+ type_init_fun.modifiers = CCodeModifiers.STATIC;
+ }
type_init_fun.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
if (object_type_symbol != null) {
foreach (var type_param in object_type_symbol.get_type_parameters ()) {
@@ -587,7 +599,6 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
if (!cl.is_internal_symbol ()) {
generate_class_declaration (cl, header_declarations);
}
- generate_class_declaration (cl, internal_header_declarations);
cl.accept_children (codegen);
@@ -674,7 +685,6 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
declare_set_value_copy_function (source_declarations);
declare_set_value_copy_function (header_declarations);
- declare_set_value_copy_function (internal_header_declarations);
source_type_member_definition.append (create_set_value_copy_function ());
var value_equals_function = new CCodeFunction ("dova_type_value_equals", "bool");
@@ -697,7 +707,6 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
declare_set_value_equals_function (source_declarations);
declare_set_value_equals_function (header_declarations);
- declare_set_value_equals_function (internal_header_declarations);
source_type_member_definition.append (create_set_value_equals_function ());
var value_hash_function = new CCodeFunction ("dova_type_value_hash", "int32_t");
@@ -716,7 +725,6 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
declare_set_value_hash_function (source_declarations);
declare_set_value_hash_function (header_declarations);
- declare_set_value_hash_function (internal_header_declarations);
source_type_member_definition.append (create_set_value_hash_function ());
}
@@ -755,6 +763,9 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
source_declarations.add_type_member_declaration (cdecl);
var type_fun = new CCodeFunction ("%s_type_get".printf (iface.get_lower_case_cname ()), "DovaType *");
+ if (iface.is_internal_symbol ()) {
+ type_fun.modifiers = CCodeModifiers.STATIC;
+ }
foreach (var type_param in iface.get_type_parameters ()) {
type_fun.add_parameter (new CCodeFormalParameter ("%s_type".printf (type_param.name.down ()), "DovaType *"));
}
@@ -782,6 +793,9 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
source_type_member_definition.append (type_fun);
var type_init_fun = new CCodeFunction ("%s_type_init".printf (iface.get_lower_case_cname ()));
+ if (iface.is_internal_symbol ()) {
+ type_init_fun.modifiers = CCodeModifiers.STATIC;
+ }
type_init_fun.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
foreach (var type_param in iface.get_type_parameters ()) {
type_init_fun.add_parameter (new CCodeFormalParameter ("%s_type".printf (type_param.name.down ()), "DovaType *"));
@@ -857,7 +871,7 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
function.add_parameter (cvalueparam);
}
- if (prop.is_private_symbol () || acc.access == SymbolAccessibility.PRIVATE) {
+ if (prop.is_internal_symbol () || acc.is_internal_symbol ()) {
function.modifiers |= CCodeModifiers.STATIC;
}
decl_space.add_type_member_declaration (function);
@@ -898,7 +912,6 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
|| acc.access == SymbolAccessibility.PROTECTED)) {
generate_property_accessor_declaration (acc, header_declarations);
}
- generate_property_accessor_declaration (acc, internal_header_declarations);
}
DataType this_type;
@@ -926,7 +939,7 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
function.add_parameter (cvalueparam);
}
- if (prop.is_private_symbol () || !(acc.readable || acc.writable) || acc.access == SymbolAccessibility.PRIVATE) {
+ if (prop.is_internal_symbol () || !(acc.readable || acc.writable) || acc.is_internal_symbol ()) {
// accessor function should be private if the property is an internal symbol
function.modifiers |= CCodeModifiers.STATIC;
}
@@ -984,7 +997,7 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
function.add_parameter (cvalueparam);
}
- if (prop.is_private_symbol () || !(acc.readable || acc.writable) || acc.access == SymbolAccessibility.PRIVATE) {
+ if (prop.is_internal_symbol () || !(acc.readable || acc.writable) || acc.is_internal_symbol ()) {
// accessor function should be private if the property is an internal symbol
function.modifiers |= CCodeModifiers.STATIC;
}
@@ -1018,12 +1031,18 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
generate_class_declaration (type_class, decl_space);
var type_fun = new CCodeFunction ("%s_type_get".printf (iface.get_lower_case_cname ()), "DovaType *");
+ if (iface.is_internal_symbol ()) {
+ type_fun.modifiers = CCodeModifiers.STATIC;
+ }
foreach (var type_param in iface.get_type_parameters ()) {
type_fun.add_parameter (new CCodeFormalParameter ("%s_type".printf (type_param.name.down ()), "DovaType *"));
}
decl_space.add_type_member_declaration (type_fun);
var type_init_fun = new CCodeFunction ("%s_type_init".printf (iface.get_lower_case_cname ()));
+ if (iface.is_internal_symbol ()) {
+ type_init_fun.modifiers = CCodeModifiers.STATIC;
+ }
type_init_fun.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
foreach (var type_param in iface.get_type_parameters ()) {
type_init_fun.add_parameter (new CCodeFormalParameter ("%s_type".printf (type_param.name.down ()), "DovaType *"));
@@ -1054,7 +1073,7 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
var function = new CCodeFunction (m.get_cname ());
- if (m.is_private_symbol ()) {
+ if (m.is_internal_symbol ()) {
function.modifiers |= CCodeModifiers.STATIC;
if (m.is_inline) {
function.modifiers |= CCodeModifiers.INLINE;
@@ -1096,7 +1115,7 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
// _init function
function = new CCodeFunction (m.get_real_cname ());
- if (m.is_private_symbol ()) {
+ if (m.is_internal_symbol ()) {
function.modifiers |= CCodeModifiers.STATIC;
}
@@ -1143,7 +1162,6 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
if (!m.is_internal_symbol ()) {
generate_method_declaration (m, header_declarations);
}
- generate_method_declaration (m, internal_header_declarations);
var function = new CCodeFunction (m.get_real_cname ());
m.ccodenode = function;
@@ -1156,7 +1174,7 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
// declare *_real_* function
function.modifiers |= CCodeModifiers.STATIC;
source_declarations.add_type_member_declaration (function.copy ());
- } else if (m.is_private_symbol ()) {
+ } else if (m.is_internal_symbol ()) {
function.modifiers |= CCodeModifiers.STATIC;
}
@@ -1453,7 +1471,7 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
}
public override void visit_creation_method (CreationMethod m) {
- bool visible = !m.is_private_symbol ();
+ bool visible = !m.is_internal_symbol ();
head.visit_method (m);
diff --git a/codegen/valadovastructmodule.vala b/codegen/valadovastructmodule.vala
index ba33a1a..4cc286b 100644
--- a/codegen/valadovastructmodule.vala
+++ b/codegen/valadovastructmodule.vala
@@ -90,7 +90,6 @@ internal class Vala.DovaStructModule : DovaBaseModule {
if (!st.is_internal_symbol ()) {
generate_struct_declaration (st, header_declarations);
}
- generate_struct_declaration (st, internal_header_declarations);
st.accept_children (codegen);
diff --git a/codegen/valadovavaluemodule.vala b/codegen/valadovavaluemodule.vala
index ff59302..75221f4 100644
--- a/codegen/valadovavaluemodule.vala
+++ b/codegen/valadovavaluemodule.vala
@@ -37,14 +37,14 @@ internal class Vala.DovaValueModule : DovaObjectModule {
}
var type_fun = new CCodeFunction ("%s_type_get".printf (cl.get_lower_case_cname ()), "DovaType *");
- if (cl.access == SymbolAccessibility.PRIVATE) {
+ if (cl.is_internal_symbol ()) {
type_fun.modifiers = CCodeModifiers.STATIC;
}
decl_space.add_type_member_declaration (type_fun);
var type_init_fun = new CCodeFunction ("%s_type_init".printf (cl.get_lower_case_cname ()));
type_init_fun.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
- if (cl.access == SymbolAccessibility.PRIVATE) {
+ if (cl.is_internal_symbol ()) {
type_init_fun.modifiers = CCodeModifiers.STATIC;
}
decl_space.add_type_member_declaration (type_init_fun);
@@ -96,7 +96,6 @@ internal class Vala.DovaValueModule : DovaObjectModule {
if (!cl.is_internal_symbol ()) {
generate_class_declaration (cl, header_declarations);
}
- generate_class_declaration (cl, internal_header_declarations);
var cdecl = new CCodeDeclaration ("DovaType *");
@@ -270,20 +269,20 @@ internal class Vala.DovaValueModule : DovaObjectModule {
generate_class_declaration (type_class, decl_space);
var type_fun = new CCodeFunction ("%s_type_get".printf (st.get_lower_case_cname ()), "DovaType *");
- if (st.access == SymbolAccessibility.PRIVATE) {
+ if (st.is_internal_symbol ()) {
type_fun.modifiers = CCodeModifiers.STATIC;
}
decl_space.add_type_member_declaration (type_fun);
var type_init_fun = new CCodeFunction ("%s_type_init".printf (st.get_lower_case_cname ()));
type_init_fun.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
- if (st.access == SymbolAccessibility.PRIVATE) {
+ if (st.is_internal_symbol ()) {
type_init_fun.modifiers = CCodeModifiers.STATIC;
}
decl_space.add_type_member_declaration (type_init_fun);
var function = new CCodeFunction (st.get_copy_function (), "void");
- if (st.access == SymbolAccessibility.PRIVATE) {
+ if (st.is_internal_symbol ()) {
function.modifiers = CCodeModifiers.STATIC;
}
@@ -464,7 +463,7 @@ internal class Vala.DovaValueModule : DovaObjectModule {
void add_struct_copy_function (Struct st) {
var function = new CCodeFunction (st.get_copy_function (), "void");
- if (st.access == SymbolAccessibility.PRIVATE) {
+ if (st.is_internal_symbol ()) {
function.modifiers = CCodeModifiers.STATIC;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]