Commit f4f655d2 authored by Jürg Billeter's avatar Jürg Billeter

Replace CCodeDeclarationSpace by CCodeFile

parent ceb6c387
...@@ -32,6 +32,7 @@ libvalaccode_la_VALASOURCES = \ ...@@ -32,6 +32,7 @@ libvalaccode_la_VALASOURCES = \
valaccodeenumvalue.vala \ valaccodeenumvalue.vala \
valaccodeexpression.vala \ valaccodeexpression.vala \
valaccodeexpressionstatement.vala \ valaccodeexpressionstatement.vala \
valaccodefile.vala \
valaccodeformalparameter.vala \ valaccodeformalparameter.vala \
valaccodeforstatement.vala \ valaccodeforstatement.vala \
valaccodefragment.vala \ valaccodefragment.vala \
......
/* valaccodedeclarationspace.vala /* valaccodefile.vala
* *
* Copyright (C) 2009 Jürg Billeter * Copyright (C) 2009-2010 Jürg Billeter
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -21,16 +21,18 @@ ...@@ -21,16 +21,18 @@
*/ */
public class Vala.CCodeDeclarationSpace { public class Vala.CCodeFile {
public bool is_header { get; set; } public bool is_header { get; set; }
Set<string> declarations = new HashSet<string> (str_hash, str_equal); Set<string> declarations = new HashSet<string> (str_hash, str_equal);
Set<string> includes = new HashSet<string> (str_hash, str_equal); Set<string> includes = new HashSet<string> (str_hash, str_equal);
internal CCodeFragment include_directives = new CCodeFragment (); CCodeFragment comments = new CCodeFragment ();
internal CCodeFragment type_declaration = new CCodeFragment (); CCodeFragment include_directives = new CCodeFragment ();
internal CCodeFragment type_definition = new CCodeFragment (); CCodeFragment type_declaration = new CCodeFragment ();
internal CCodeFragment type_member_declaration = new CCodeFragment (); CCodeFragment type_definition = new CCodeFragment ();
internal CCodeFragment constant_declaration = new CCodeFragment (); CCodeFragment type_member_declaration = new CCodeFragment ();
CCodeFragment constant_declaration = new CCodeFragment ();
CCodeFragment type_member_definition = new CCodeFragment ();
public bool add_declaration (string name) { public bool add_declaration (string name) {
if (name in declarations) { if (name in declarations) {
...@@ -40,6 +42,10 @@ public class Vala.CCodeDeclarationSpace { ...@@ -40,6 +42,10 @@ public class Vala.CCodeDeclarationSpace {
return false; return false;
} }
public void add_comment (CCodeComment comment) {
comments.append (comment);
}
public void add_include (string filename, bool local = false) { public void add_include (string filename, bool local = false) {
if (!(filename in includes)) { if (!(filename in includes)) {
include_directives.append (new CCodeIncludeDirective (filename, local)); include_directives.append (new CCodeIncludeDirective (filename, local));
...@@ -62,5 +68,106 @@ public class Vala.CCodeDeclarationSpace { ...@@ -62,5 +68,106 @@ public class Vala.CCodeDeclarationSpace {
public void add_constant_declaration (CCodeNode node) { public void add_constant_declaration (CCodeNode node) {
constant_declaration.append (node); constant_declaration.append (node);
} }
public void add_type_member_definition (CCodeNode node) {
type_member_definition.append (node);
}
public void add_function (CCodeFunction func) {
type_member_definition.append (func);
}
public List<string> get_symbols () {
var symbols = new ArrayList<string> ();
foreach (CCodeNode node in type_member_declaration.get_children ()) {
var func = node as CCodeFunction;
if (func != null) {
symbols.add (func.name);
}
}
return symbols;
}
static string get_define_for_filename (string filename) {
var define = new StringBuilder ("__");
var i = filename;
while (i.length > 0) {
var c = i.get_char ();
if (c.isalnum () && c < 0x80) {
define.append_unichar (c.toupper ());
} else {
define.append_c ('_');
}
i = i.next_char ();
}
define.append ("__");
return define.str;
}
public bool store (string filename, string? source_filename, bool write_version, bool line_directives, string? begin_decls = null, string? end_decls = null) {
var writer = new CCodeWriter (filename, source_filename);
if (!writer.open (write_version)) {
return false;
}
if (!is_header) {
writer.line_directives = line_directives;
comments.write (writer);
writer.write_newline ();
include_directives.write (writer);
writer.write_newline ();
type_declaration.write_combined (writer);
writer.write_newline ();
type_definition.write_combined (writer);
writer.write_newline ();
type_member_declaration.write_declaration (writer);
writer.write_newline ();
type_member_declaration.write (writer);
writer.write_newline ();
constant_declaration.write_combined (writer);
writer.write_newline ();
type_member_definition.write (writer);
writer.write_newline ();
} else {
writer.write_newline ();
var once = new CCodeOnceSection (get_define_for_filename (writer.filename));
once.append (new CCodeNewline ());
once.append (include_directives);
once.append (new CCodeNewline ());
if (begin_decls != null) {
once.append (new CCodeIdentifier (begin_decls));
once.append (new CCodeNewline ());
}
once.append (new CCodeNewline ());
once.append (type_declaration);
once.append (new CCodeNewline ());
once.append (type_definition);
once.append (new CCodeNewline ());
once.append (type_member_declaration);
once.append (new CCodeNewline ());
once.append (constant_declaration);
once.append (new CCodeNewline ());
if (begin_decls != null) {
once.append (new CCodeIdentifier (end_decls));
once.append (new CCodeNewline ());
}
once.append (new CCodeNewline ());
once.write (writer);
}
writer.close ();
return true;
}
} }
...@@ -20,7 +20,6 @@ libvala_la_VALASOURCES = \ ...@@ -20,7 +20,6 @@ libvala_la_VALASOURCES = \
valaccodebasemodule.vala \ valaccodebasemodule.vala \
valaccodecompiler.vala \ valaccodecompiler.vala \
valaccodecontrolflowmodule.vala \ valaccodecontrolflowmodule.vala \
valaccodedeclarationspace.vala \
valaccodedelegatemodule.vala \ valaccodedelegatemodule.vala \
valaccodememberaccessmodule.vala \ valaccodememberaccessmodule.vala \
valaccodemethodcallmodule.vala \ valaccodemethodcallmodule.vala \
......
...@@ -61,7 +61,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -61,7 +61,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
CCodeFunctionCall gnew; CCodeFunctionCall gnew;
if (context.profile == Profile.POSIX) { if (context.profile == Profile.POSIX) {
source_declarations.add_include ("stdlib.h"); cfile.add_include ("stdlib.h");
gnew = new CCodeFunctionCall (new CCodeIdentifier ("calloc")); gnew = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
} else { } else {
gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0")); gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
...@@ -479,7 +479,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -479,7 +479,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
public override string? append_struct_array_free (Struct st) { public override string? append_struct_array_free (Struct st) {
string cname = "_vala_%s_array_free".printf (st.get_cname ());; string cname = "_vala_%s_array_free".printf (st.get_cname ());;
if (source_declarations.add_declaration (cname)) { if (cfile.add_declaration (cname)) {
return cname; return cname;
} }
...@@ -487,7 +487,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -487,7 +487,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.modifiers = CCodeModifiers.STATIC; fun.modifiers = CCodeModifiers.STATIC;
fun.add_parameter (new CCodeFormalParameter ("array", "%s*".printf (st.get_cname ()))); fun.add_parameter (new CCodeFormalParameter ("array", "%s*".printf (st.get_cname ())));
fun.add_parameter (new CCodeFormalParameter ("array_length", "gint")); fun.add_parameter (new CCodeFormalParameter ("array_length", "gint"));
source_declarations.add_type_member_declaration (fun.copy ()); cfile.add_type_member_declaration (fun.copy ());
var cdofree = new CCodeBlock (); var cdofree = new CCodeBlock ();
...@@ -506,7 +506,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -506,7 +506,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
carrfree.add_argument (new CCodeIdentifier ("array")); carrfree.add_argument (new CCodeIdentifier ("array"));
fun.block.add_statement (new CCodeExpressionStatement (carrfree)); fun.block.add_statement (new CCodeExpressionStatement (carrfree));
source_type_member_definition.append (fun); cfile.add_function (fun);
return cname; return cname;
} }
...@@ -540,7 +540,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -540,7 +540,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.add_parameter (new CCodeFormalParameter ("array", "gpointer")); fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
fun.add_parameter (new CCodeFormalParameter ("array_length", "gint")); fun.add_parameter (new CCodeFormalParameter ("array_length", "gint"));
fun.add_parameter (new CCodeFormalParameter ("destroy_func", "GDestroyNotify")); fun.add_parameter (new CCodeFormalParameter ("destroy_func", "GDestroyNotify"));
source_declarations.add_type_member_declaration (fun.copy ()); cfile.add_type_member_declaration (fun.copy ());
var cdofree = new CCodeBlock (); var cdofree = new CCodeBlock ();
...@@ -556,7 +556,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -556,7 +556,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.block = new CCodeBlock (); fun.block = new CCodeBlock ();
fun.block.add_statement (cif); fun.block.add_statement (cif);
source_type_member_definition.append (fun); cfile.add_function (fun);
// _vala_array_free frees elements and array // _vala_array_free frees elements and array
...@@ -565,7 +565,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -565,7 +565,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.add_parameter (new CCodeFormalParameter ("array", "gpointer")); fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
fun.add_parameter (new CCodeFormalParameter ("array_length", "gint")); fun.add_parameter (new CCodeFormalParameter ("array_length", "gint"));
fun.add_parameter (new CCodeFormalParameter ("destroy_func", "GDestroyNotify")); fun.add_parameter (new CCodeFormalParameter ("destroy_func", "GDestroyNotify"));
source_declarations.add_type_member_declaration (fun.copy ()); cfile.add_type_member_declaration (fun.copy ());
// call _vala_array_destroy to free the array elements // call _vala_array_destroy to free the array elements
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_destroy")); var ccall = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_destroy"));
...@@ -580,11 +580,11 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -580,11 +580,11 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
carrfree.add_argument (new CCodeIdentifier ("array")); carrfree.add_argument (new CCodeIdentifier ("array"));
fun.block.add_statement (new CCodeExpressionStatement (carrfree)); fun.block.add_statement (new CCodeExpressionStatement (carrfree));
source_type_member_definition.append (fun); cfile.add_function (fun);
} }
public override void append_vala_array_move () { public override void append_vala_array_move () {
source_declarations.add_include ("string.h"); cfile.add_include ("string.h");
// assumes that overwritten array elements are null before invocation // assumes that overwritten array elements are null before invocation
// FIXME will leak memory if that's not the case // FIXME will leak memory if that's not the case
...@@ -595,7 +595,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -595,7 +595,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.add_parameter (new CCodeFormalParameter ("src", "gint")); fun.add_parameter (new CCodeFormalParameter ("src", "gint"));
fun.add_parameter (new CCodeFormalParameter ("dest", "gint")); fun.add_parameter (new CCodeFormalParameter ("dest", "gint"));
fun.add_parameter (new CCodeFormalParameter ("length", "gint")); fun.add_parameter (new CCodeFormalParameter ("length", "gint"));
source_declarations.add_type_member_declaration (fun.copy ()); cfile.add_type_member_declaration (fun.copy ());
var array = new CCodeCastExpression (new CCodeIdentifier ("array"), "char*"); var array = new CCodeCastExpression (new CCodeIdentifier ("array"), "char*");
var element_size = new CCodeIdentifier ("element_size"); var element_size = new CCodeIdentifier ("element_size");
...@@ -630,14 +630,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -630,14 +630,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.block.add_statement (new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, src, dest), czeroblock1, czeroblock2)); fun.block.add_statement (new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, src, dest), czeroblock1, czeroblock2));
source_type_member_definition.append (fun); cfile.add_function (fun);
} }
public override void append_vala_array_length () { public override void append_vala_array_length () {
var fun = new CCodeFunction ("_vala_array_length", "gint"); var fun = new CCodeFunction ("_vala_array_length", "gint");
fun.modifiers = CCodeModifiers.STATIC; fun.modifiers = CCodeModifiers.STATIC;
fun.add_parameter (new CCodeFormalParameter ("array", "gpointer")); fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
source_declarations.add_type_member_declaration (fun.copy ()); cfile.add_type_member_declaration (fun.copy ());
var block = new CCodeBlock (); var block = new CCodeBlock ();
...@@ -662,7 +662,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -662,7 +662,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.block = block; fun.block = block;
source_type_member_definition.append (fun); cfile.add_function (fun);
} }
public override CCodeExpression? get_ref_cexpression (DataType expression_type, CCodeExpression cexpr, Expression? expr, CodeNode node) { public override CCodeExpression? get_ref_cexpression (DataType expression_type, CCodeExpression cexpr, Expression? expr, CodeNode node) {
...@@ -805,10 +805,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -805,10 +805,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
// append to file // append to file
source_declarations.add_type_member_declaration (function.copy ()); cfile.add_type_member_declaration (function.copy ());
function.block = block; function.block = block;
source_type_member_definition.append (function); cfile.add_function (function);
return dup_func; return dup_func;
} }
...@@ -854,7 +854,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -854,7 +854,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
pop_context (); pop_context ();
} else { } else {
source_declarations.add_include ("string.h"); cfile.add_include ("string.h");
var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("memcpy")); var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
dup_call.add_argument (new CCodeIdentifier ("dest")); dup_call.add_argument (new CCodeIdentifier ("dest"));
...@@ -869,10 +869,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -869,10 +869,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
// append to file // append to file
source_declarations.add_type_member_declaration (function.copy ()); cfile.add_type_member_declaration (function.copy ());
function.block = block; function.block = block;
source_type_member_definition.append (function); cfile.add_function (function);
return dup_func; return dup_func;
} }
...@@ -941,10 +941,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -941,10 +941,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
// append to file // append to file
source_declarations.add_type_member_declaration (function.copy ()); cfile.add_type_member_declaration (function.copy ());
function.block = block; function.block = block;
source_type_member_definition.append (function); cfile.add_function (function);
return add_func; return add_func;
} }
...@@ -985,7 +985,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -985,7 +985,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
assignment.ccodenode = ccall; assignment.ccodenode = ccall;
} }
public override void generate_parameter (FormalParameter param, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) { public override void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
if (!(param.variable_type is ArrayType)) { if (!(param.variable_type is ArrayType)) {
base.generate_parameter (param, decl_space, cparam_map, carg_map); base.generate_parameter (param, decl_space, cparam_map, carg_map);
return; return;
......
...@@ -34,7 +34,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule { ...@@ -34,7 +34,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
var prop = (Property) assignment.left.symbol_reference; var prop = (Property) assignment.left.symbol_reference;
if (!(prop is DynamicProperty)) { if (!(prop is DynamicProperty)) {
generate_property_accessor_declaration (prop.set_accessor, source_declarations); generate_property_accessor_declaration (prop.set_accessor, cfile);
if (!prop.external && prop.external_package) { if (!prop.external && prop.external_package) {
// internal VAPI properties // internal VAPI properties
...@@ -212,7 +212,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule { ...@@ -212,7 +212,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode; CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode;
CCodeExpression lhs = (CCodeExpression) get_ccodenode (assignment.left); CCodeExpression lhs = (CCodeExpression) get_ccodenode (assignment.left);
source_declarations.add_include ("string.h"); cfile.add_include ("string.h");
// it is necessary to use memcpy for fixed-length (stack-allocated) arrays // it is necessary to use memcpy for fixed-length (stack-allocated) arrays
// simple assignments do not work in C // simple assignments do not work in C
......
This diff is collapsed.
...@@ -235,7 +235,7 @@ public class Vala.CCodeControlFlowModule : CCodeMethodModule { ...@@ -235,7 +235,7 @@ public class Vala.CCodeControlFlowModule : CCodeMethodModule {
if (context.profile == Profile.GOBJECT) { if (context.profile == Profile.GOBJECT) {
stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("TRUE"), (CCodeStatement) stmt.body.ccodenode); stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("TRUE"), (CCodeStatement) stmt.body.ccodenode);
} else { } else {
source_declarations.add_include ("stdbool.h"); cfile.add_include ("stdbool.h");
stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("true"), (CCodeStatement) stmt.body.ccodenode); stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("true"), (CCodeStatement) stmt.body.ccodenode);
} }
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* The link between an assignment and generated code. * The link between an assignment and generated code.
*/ */
public class Vala.CCodeDelegateModule : CCodeArrayModule { public class Vala.CCodeDelegateModule : CCodeArrayModule {
public override void generate_delegate_declaration (Delegate d, CCodeDeclarationSpace decl_space) { public override void generate_delegate_declaration (Delegate d, CCodeFile decl_space) {
if (add_symbol_declaration (decl_space, d, d.get_cname ())) { if (add_symbol_declaration (decl_space, d, d.get_cname ())) {
return; return;
} }
...@@ -114,13 +114,13 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { ...@@ -114,13 +114,13 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
public override void visit_delegate (Delegate d) { public override void visit_delegate (Delegate d) {
d.accept_children (this); d.accept_children (this);
generate_delegate_declaration (d, source_declarations); generate_delegate_declaration (d, cfile);
if (!d.is_internal_symbol ()) { if (!d.is_internal_symbol ()) {
generate_delegate_declaration (d, header_declarations); generate_delegate_declaration (d, header_file);
} }
if (!d.is_private_symbol ()) { if (!d.is_private_symbol ()) {
generate_delegate_declaration (d, internal_header_declarations); generate_delegate_declaration (d, internal_header_file);
} }
} }
...@@ -388,7 +388,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { ...@@ -388,7 +388,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
if (d.sender_type != null) { if (d.sender_type != null) {
var param = new FormalParameter ("_sender", d.sender_type); var param = new FormalParameter ("_sender", d.sender_type);
generate_parameter (param, source_declarations, cparam_map, null); generate_parameter (param, cfile, cparam_map, null);
} }
var d_params = d.get_parameters (); var d_params = d.get_parameters ();
...@@ -401,7 +401,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { ...@@ -401,7 +401,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
param.array_null_terminated = true; param.array_null_terminated = true;
} }
generate_parameter (param, source_declarations, cparam_map, null); generate_parameter (param, cfile, cparam_map, null);
} }
if (!d.no_array_length && d.return_type is ArrayType) { if (!d.no_array_length && d.return_type is ArrayType) {
// return array length if appropriate // return array length if appropriate
...@@ -600,15 +600,15 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { ...@@ -600,15 +600,15 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
// append to file // append to file
source_declarations.add_type_member_declaration (function.copy ()); cfile.add_type_member_declaration (function.copy ());
function.block = block; function.block = block;
source_type_member_definition.append (function); cfile.add_function (function);
return wrapper_name; return wrapper_name;
} }
public override void generate_parameter (FormalParameter param, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) { public override void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
if (!(param.variable_type is DelegateType || param.variable_type is MethodType)) { if (!(param.variable_type is DelegateType || param.variable_type is MethodType)) {
base.generate_parameter (param, decl_space, cparam_map, carg_map); base.generate_parameter (param, decl_space, cparam_map, carg_map);
return; return;
......
...@@ -34,7 +34,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { ...@@ -34,7 +34,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
var m = (Method) expr.symbol_reference; var m = (Method) expr.symbol_reference;
if (!(m is DynamicMethod || m is ArrayMoveMethod || m is ArrayResizeMethod)) { if (!(m is DynamicMethod || m is ArrayMoveMethod || m is ArrayResizeMethod)) {
generate_method_declaration (m, source_declarations); generate_method_declaration (m, cfile);
if (!m.external && m.external_package) { if (!m.external && m.external_package) {
// internal VAPI methods // internal VAPI methods
...@@ -106,7 +106,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { ...@@ -106,7 +106,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
inst = new CCodeMemberAccess.pointer (pub_inst, "priv"); inst = new CCodeMemberAccess.pointer (pub_inst, "priv");
} else { } else {
if (cl != null) { if (cl != null) {
generate_class_struct_declaration (cl, source_declarations); generate_class_struct_declaration (cl, cfile);
} }
inst = pub_inst; inst = pub_inst;
} }
...@@ -155,20 +155,20 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { ...@@ -155,20 +155,20 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
} }
} else { } else {
generate_field_declaration (f, source_declarations); generate_field_declaration (f, cfile);
expr.ccodenode = new CCodeIdentifier (f.get_cname ()); expr.ccodenode = new CCodeIdentifier (f.get_cname ());
} }
} else if (expr.symbol_reference is EnumValue) { } else if (expr.symbol_reference is EnumValue) {
var ev = (EnumValue) expr.symbol_reference; var ev = (EnumValue) expr.symbol_reference;
generate_enum_declaration ((Enum) ev.parent_symbol, source_declarations); generate_enum_declaration ((Enum) ev.parent_symbol, cfile);
expr.ccodenode = new CCodeConstant (ev.get_cname ()); expr.ccodenode = new CCodeConstant (ev.get_cname ());
} else if (expr.symbol_reference is Constant) { } else if (expr.symbol_reference is Constant) {
var c = (Constant) expr.symbol_reference; var c = (Constant) expr.symbol_reference;
generate_constant_declaration (c, source_declarations, generate_constant_declaration (c, cfile,
c.source_reference != null && expr.source_reference != null && c.source_reference != null && expr.source_reference != null &&
c.source_reference.file == expr.source_reference.file); c.source_reference.file == expr.source_reference.file);
...@@ -192,7 +192,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { ...@@ -192,7 +192,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
var prop = (Property) expr.symbol_reference; var prop = (Property) expr.symbol_reference;
if (!(prop is DynamicProperty)) { if (!(prop is DynamicProperty)) {
generate_property_accessor_declaration (prop.get_accessor, source_declarations); generate_property_accessor_declaration (prop.get_accessor, cfile);
if (!prop.external && prop.external_package) { if (!prop.external && prop.external_package) {
// internal VAPI properties // internal VAPI properties
......
...@@ -54,13 +54,13 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { ...@@ -54,13 +54,13 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
// constructor // constructor
var cl = (Class) ((ObjectType) itype).type_symbol; var cl = (Class) ((ObjectType) itype).type_symbol;
m = cl.default_construction_method; m = cl.default_construction_method;
generate_method_declaration (m, source_declarations); generate_method_declaration (m, cfile);
ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ())); ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
} else if (itype is StructValueType) { } else if (itype is StructValueType) {
// constructor // constructor
var st = (Struct) ((StructValueType) itype).type_symbol; var st = (Struct) ((StructValueType) itype).type_symbol;
m = st.default_construction_method; m = st.default_construction_method;
generate_method_declaration (m, source_declarations); generate_method_declaration (m, cfile);
ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ())); ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
} else if (itype is DelegateType) { } else if (itype is DelegateType) {
deleg = ((DelegateType) itype).delegate_symbol; deleg = ((DelegateType) itype).delegate_symbol;
...@@ -769,7 +769,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { ...@@ -769,7 +769,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
temp_vars.add (temp_decl); temp_vars.add (temp_decl);
/* memset needs string.h */ /* memset needs string.h */
source_declarations.add_include ("string.h"); cfile.add_include ("string.h");
var clen = get_array_length_cexpression (ma.inner, 1); var clen = get_array_length_cexpression (ma.inner, 1);
var celems = (CCodeExpression) ma.inner.ccodenode; var celems = (CCodeExpression) ma.inner.ccodenode;
......
...@@ -61,7 +61,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule { ...@@ -61,7 +61,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
return result; return result;
} }
public virtual void generate_method_result_declaration (Method m, CCodeDeclarationSpace decl_space, CCodeFunction cfunc, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) { public virtual void generate_method_result_declaration (Method m, CCodeFile decl_space, CCodeFunction cfunc, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
var creturn_type = m.return_type; var creturn_type = m.return_type;
if (m is CreationMethod) { if (m is CreationMethod) {