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 = \
valaccodeenumvalue.vala \
valaccodeexpression.vala \
valaccodeexpressionstatement.vala \
valaccodefile.vala \
valaccodeformalparameter.vala \
valaccodeforstatement.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
* modify it under the terms of the GNU Lesser General Public
......@@ -21,16 +21,18 @@
*/
public class Vala.CCodeDeclarationSpace {
public class Vala.CCodeFile {
public bool is_header { get; set; }
Set<string> declarations = new HashSet<string> (str_hash, str_equal);
Set<string> includes = new HashSet<string> (str_hash, str_equal);
internal CCodeFragment include_directives = new CCodeFragment ();
internal CCodeFragment type_declaration = new CCodeFragment ();
internal CCodeFragment type_definition = new CCodeFragment ();
internal CCodeFragment type_member_declaration = new CCodeFragment ();
internal CCodeFragment constant_declaration = new CCodeFragment ();
CCodeFragment comments = new CCodeFragment ();
CCodeFragment include_directives = new CCodeFragment ();
CCodeFragment type_declaration = new CCodeFragment ();
CCodeFragment type_definition = 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) {
if (name in declarations) {
......@@ -40,6 +42,10 @@ public class Vala.CCodeDeclarationSpace {
return false;
}
public void add_comment (CCodeComment comment) {
comments.append (comment);
}
public void add_include (string filename, bool local = false) {
if (!(filename in includes)) {
include_directives.append (new CCodeIncludeDirective (filename, local));
......@@ -62,5 +68,106 @@ public class Vala.CCodeDeclarationSpace {
public void add_constant_declaration (CCodeNode 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 = \
valaccodebasemodule.vala \
valaccodecompiler.vala \
valaccodecontrolflowmodule.vala \
valaccodedeclarationspace.vala \
valaccodedelegatemodule.vala \
valaccodememberaccessmodule.vala \
valaccodemethodcallmodule.vala \
......
......@@ -61,7 +61,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
CCodeFunctionCall gnew;
if (context.profile == Profile.POSIX) {
source_declarations.add_include ("stdlib.h");
cfile.add_include ("stdlib.h");
gnew = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
} else {
gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
......@@ -479,7 +479,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
public override string? append_struct_array_free (Struct st) {
string cname = "_vala_%s_array_free".printf (st.get_cname ());;
if (source_declarations.add_declaration (cname)) {
if (cfile.add_declaration (cname)) {
return cname;
}
......@@ -487,7 +487,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.modifiers = CCodeModifiers.STATIC;
fun.add_parameter (new CCodeFormalParameter ("array", "%s*".printf (st.get_cname ())));
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 ();
......@@ -506,7 +506,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
carrfree.add_argument (new CCodeIdentifier ("array"));
fun.block.add_statement (new CCodeExpressionStatement (carrfree));
source_type_member_definition.append (fun);
cfile.add_function (fun);
return cname;
}
......@@ -540,7 +540,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
fun.add_parameter (new CCodeFormalParameter ("array_length", "gint"));
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 ();
......@@ -556,7 +556,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.block = new CCodeBlock ();
fun.block.add_statement (cif);
source_type_member_definition.append (fun);
cfile.add_function (fun);
// _vala_array_free frees elements and array
......@@ -565,7 +565,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
fun.add_parameter (new CCodeFormalParameter ("array_length", "gint"));
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
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_destroy"));
......@@ -580,11 +580,11 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
carrfree.add_argument (new CCodeIdentifier ("array"));
fun.block.add_statement (new CCodeExpressionStatement (carrfree));
source_type_member_definition.append (fun);
cfile.add_function (fun);
}
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
// FIXME will leak memory if that's not the case
......@@ -595,7 +595,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.add_parameter (new CCodeFormalParameter ("src", "gint"));
fun.add_parameter (new CCodeFormalParameter ("dest", "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 element_size = new CCodeIdentifier ("element_size");
......@@ -630,14 +630,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
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 () {
var fun = new CCodeFunction ("_vala_array_length", "gint");
fun.modifiers = CCodeModifiers.STATIC;
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 ();
......@@ -662,7 +662,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
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) {
......@@ -805,10 +805,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
// append to file
source_declarations.add_type_member_declaration (function.copy ());
cfile.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
cfile.add_function (function);
return dup_func;
}
......@@ -854,7 +854,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
pop_context ();
} else {
source_declarations.add_include ("string.h");
cfile.add_include ("string.h");
var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
dup_call.add_argument (new CCodeIdentifier ("dest"));
......@@ -869,10 +869,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
// append to file
source_declarations.add_type_member_declaration (function.copy ());
cfile.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
cfile.add_function (function);
return dup_func;
}
......@@ -941,10 +941,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
// append to file
source_declarations.add_type_member_declaration (function.copy ());
cfile.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
cfile.add_function (function);
return add_func;
}
......@@ -985,7 +985,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
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)) {
base.generate_parameter (param, decl_space, cparam_map, carg_map);
return;
......
......@@ -34,7 +34,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
var prop = (Property) assignment.left.symbol_reference;
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) {
// internal VAPI properties
......@@ -212,7 +212,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode;
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
// simple assignments do not work in C
......
This diff is collapsed.
......@@ -235,7 +235,7 @@ public class Vala.CCodeControlFlowModule : CCodeMethodModule {
if (context.profile == Profile.GOBJECT) {
stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("TRUE"), (CCodeStatement) stmt.body.ccodenode);
} else {
source_declarations.add_include ("stdbool.h");
cfile.add_include ("stdbool.h");
stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("true"), (CCodeStatement) stmt.body.ccodenode);
}
}
......
......@@ -27,7 +27,7 @@
* The link between an assignment and generated code.
*/
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 ())) {
return;
}
......@@ -114,13 +114,13 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
public override void visit_delegate (Delegate d) {
d.accept_children (this);
generate_delegate_declaration (d, source_declarations);
generate_delegate_declaration (d, cfile);
if (!d.is_internal_symbol ()) {
generate_delegate_declaration (d, header_declarations);
generate_delegate_declaration (d, header_file);
}
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 {
if (d.sender_type != null) {
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 ();
......@@ -401,7 +401,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
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) {
// return array length if appropriate
......@@ -600,15 +600,15 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
// append to file
source_declarations.add_type_member_declaration (function.copy ());
cfile.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
cfile.add_function (function);
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)) {
base.generate_parameter (param, decl_space, cparam_map, carg_map);
return;
......
......@@ -34,7 +34,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
var m = (Method) expr.symbol_reference;
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) {
// internal VAPI methods
......@@ -106,7 +106,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
inst = new CCodeMemberAccess.pointer (pub_inst, "priv");
} else {
if (cl != null) {
generate_class_struct_declaration (cl, source_declarations);
generate_class_struct_declaration (cl, cfile);
}
inst = pub_inst;
}
......@@ -155,20 +155,20 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
} else {
generate_field_declaration (f, source_declarations);
generate_field_declaration (f, cfile);
expr.ccodenode = new CCodeIdentifier (f.get_cname ());
}
} else if (expr.symbol_reference is EnumValue) {
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 ());
} else if (expr.symbol_reference is Constant) {
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.file == expr.source_reference.file);
......@@ -192,7 +192,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
var prop = (Property) expr.symbol_reference;
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) {
// internal VAPI properties
......
......@@ -54,13 +54,13 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
// constructor
var cl = (Class) ((ObjectType) itype).type_symbol;
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 ()));
} else if (itype is StructValueType) {
// constructor
var st = (Struct) ((StructValueType) itype).type_symbol;
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 ()));
} else if (itype is DelegateType) {
deleg = ((DelegateType) itype).delegate_symbol;
......@@ -769,7 +769,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
temp_vars.add (temp_decl);
/* 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 celems = (CCodeExpression) ma.inner.ccodenode;
......
......@@ -61,7 +61,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
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;
if (m is CreationMethod) {
var cl = m.parent_symbol as Class;
......@@ -158,7 +158,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
return complete_block;
}
public override void generate_method_declaration (Method m, CCodeDeclarationSpace decl_space) {
public override void generate_method_declaration (Method m, CCodeFile decl_space) {
if (m.is_async_callback) {
return;
}
......@@ -318,18 +318,18 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
// do not declare overriding methods and interface implementations
if (m.is_abstract || m.is_virtual
|| (m.base_method == null && m.base_interface_method == null)) {
generate_method_declaration (m, source_declarations);
generate_method_declaration (m, cfile);
if (!m.is_internal_symbol ()) {
generate_method_declaration (m, header_declarations);
generate_method_declaration (m, header_file);
}
if (!m.is_private_symbol ()) {
generate_method_declaration (m, internal_header_declarations);
generate_method_declaration (m, internal_header_file);
}
}
if (m.comment != null) {
source_type_member_definition.append (new CCodeComment (m.comment.content));
cfile.add_type_member_definition (new CCodeComment (m.comment.content));
}
CCodeFunction function;
......@@ -342,7 +342,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
generate_cparameters (m, source_declarations, cparam_map, function);
generate_cparameters (m, cfile, cparam_map, function);
// generate *_real_* functions for virtual methods
// also generate them for abstract methods of classes to prevent faulty subclassing
......@@ -351,7 +351,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
if (m.base_method != null || m.base_interface_method != null) {
// declare *_real_* function
function.modifiers |= CCodeModifiers.STATIC;
source_declarations.add_type_member_declaration (function.copy ());
cfile.add_type_member_declaration (function.copy ());
} else if (m.is_private_symbol ()) {
function.modifiers |= CCodeModifiers.STATIC;
}
......@@ -371,7 +371,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
function.add_parameter (new CCodeFormalParameter ("data", Symbol.lower_case_to_camel_case (m.get_cname ()) + "Data*"));
function.modifiers |= CCodeModifiers.STATIC;
source_declarations.add_type_member_declaration (function.copy ());
cfile.add_type_member_declaration (function.copy ());
}
}
}
......@@ -590,7 +590,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
var st = (Struct) m.parent_symbol;
// memset needs string.h
source_declarations.add_include ("string.h");
cfile.add_include ("string.h");
var czero = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
czero.add_argument (new CCodeIdentifier ("self"));
czero.add_argument (new CCodeConstant ("0"));
......@@ -655,7 +655,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
}
}
source_type_member_definition.append (function);
cfile.add_function (function);
} else if (m.is_abstract) {
// generate helpful error message if a sublcass does not implement an abstract method.
// This is only meaningful for subclasses implemented in C since the vala compiler would
......@@ -688,7 +688,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
cblock.add_statement (new CCodeReturnStatement (default_value_for_type (creturn_type, false)));
function.block = cblock;
source_type_member_definition.append (function);
cfile.add_function (function);
}
}
......@@ -755,11 +755,11 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
main_block.add_statement (main_stmt);
}
cmain.block = main_block;
source_type_member_definition.append (cmain);
cfile.add_function (cmain);
}
}
public virtual void generate_parameter (FormalParameter param, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
public virtual void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
if (!param.ellipsis) {
string ctypename = param.variable_type.get_cname ();
......@@ -794,7 +794,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
}
}
public override void generate_cparameters (Method m, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
public override void generate_cparameters (Method m, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
if (m.closure) {
var closure_block = current_closure_block;
int block_id = get_block_id (closure_block);
......@@ -960,7 +960,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
var vcall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, cname + suffix));
carg_map.set (get_param_pos (m.cinstance_parameter_position), new CCodeIdentifier ("self"));
generate_cparameters (m, source_declarations, cparam_map, vfunc, null, carg_map, vcall, direction);
generate_cparameters (m, cfile, cparam_map, vfunc, null, carg_map, vcall, direction);
CCodeStatement cstmt;
if (return_type is VoidType || return_type.is_real_non_null_struct_type ()) {
......@@ -991,7 +991,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
vfunc.block = vblock;
source_type_member_definition.append (vfunc);
cfile.add_function (vfunc);
}
private CCodeStatement? create_method_type_check_statement (Method m, DataType return_type, TypeSymbol t, bool non_null, string var_name) {
......@@ -1088,7 +1088,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
var vcall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
vcall.add_argument (new CCodeIdentifier (current_class.get_type_id ()));
generate_cparameters (m, source_declarations, cparam_map, vfunc, null, carg_map, vcall);
generate_cparameters (m, cfile, cparam_map, vfunc, null, carg_map, vcall);
CCodeStatement cstmt = new CCodeReturnStatement (vcall);
cstmt.line = vfunc.line;
vblock.add_statement (cstmt);
......@@ -1099,7 +1099,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
vfunc.block = vblock;
source_type_member_definition.append (vfunc);
cfile.add_function (vfunc);
}
if (current_type_symbol is Class && gobject_type != null && current_class.is_subtype_of (gobject_type)
......
......@@ -25,7 +25,7 @@
using GLib;
public class Vala.CCodeStructModule : CCodeBaseModule {
public override void generate_struct_declaration (Struct st, CCodeDeclarationSpace decl_space) {
public override void generate_struct_declaration (Struct st, CCodeFile decl_space) {
if (add_symbol_declaration (decl_space, st, st.get_cname ())) {
return;
}
......@@ -145,13 +145,13 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
var old_instance_finalize_fragment = instance_finalize_fragment;
instance_finalize_fragment = new CCodeFragment ();
generate_struct_declaration (st, source_declarations);
generate_struct_declaration (st, cfile);
if (!st.is_internal_symbol ()) {
generate_struct_declaration (st, header_declarations);
generate_struct_declaration (st, header_file);
}
if (!st.is_private_symbol ()) {
generate_struct_declaration (st, internal_header_declarations);
generate_struct_declaration (st, internal_header_file);
}
st.accept_children (this);
......@@ -196,7 +196,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
copy_call.add_argument (new CCodeIdentifier ("dup"));
cblock.add_statement (new CCodeExpressionStatement (copy_call));
} else {
source_declarations.add_include ("string.h");
cfile.add_include ("string.h");
var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
sizeof_call.add_argument (new CCodeConstant (st.get_cname ()));
......@@ -212,7 +212,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
function.block = cblock;
source_type_member_definition.append (function);
cfile.add_function (function);
}
void add_struct_free_function (Struct st) {
......@@ -237,7 +237,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
function.block = cblock;
source_type_member_definition.append (function);
cfile.add_function (function);
}
void add_struct_copy_function (Struct st) {
......@@ -269,7 +269,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
var array_type = f.variable_type as ArrayType;
if (array_type != null && array_type.fixed_length) {
// fixed-length (stack-allocated) arrays
source_declarations.add_include ("string.h");
cfile.add_include ("string.h");
var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
......@@ -299,7 +299,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
function.block = cblock;
source_type_member_definition.append (function);