Commit 2127e9b0 authored by Rico Tzschichholz's avatar Rico Tzschichholz

codegen: Don't hold reference of CodeContext in TypeRegisterFunction

parent 2dc47785
......@@ -59,8 +59,8 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
var macro = "(%s_get_type ())".printf (get_ccode_lower_case_name (st, null));
decl_space.add_type_declaration (new CCodeMacroReplacement (get_ccode_type_id (st), macro));
var type_fun = new StructRegisterFunction (st, context);
type_fun.init_from_type (false, true);
var type_fun = new StructRegisterFunction (st);
type_fun.init_from_type (context, false, true);
decl_space.add_type_member_declaration (type_fun.get_declaration ());
}
......
......@@ -37,9 +37,8 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
* @param cl a class
* @return newly created class register function
*/
public ClassRegisterFunction (Class cl, CodeContext context) {
public ClassRegisterFunction (Class cl) {
class_reference = cl;
this.context = context;
}
public override TypeSymbol get_type_declaration () {
......@@ -171,7 +170,7 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
return frag;
}
public override void get_type_interface_init_statements (CCodeBlock block, bool plugin) {
public override void get_type_interface_init_statements (CodeContext context, CCodeBlock block, bool plugin) {
foreach (DataType base_type in class_reference.get_base_types ()) {
if (!(base_type.data_type is Interface)) {
continue;
......
......@@ -38,9 +38,8 @@ public class Vala.EnumRegisterFunction : TypeRegisterFunction {
* @param en an enum
* @return newly created enum register function
*/
public EnumRegisterFunction (Enum en, CodeContext context) {
public EnumRegisterFunction (Enum en) {
enum_reference = en;
this.context = context;
}
public override TypeSymbol get_type_declaration () {
......
......@@ -186,8 +186,8 @@ public class Vala.GTypeModule : GErrorModule {
if (is_gtypeinstance) {
decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%sClass".printf (get_ccode_name (cl)), new CCodeVariableDeclarator ("%sClass".printf (get_ccode_name (cl)))));
var type_fun = new ClassRegisterFunction (cl, context);
type_fun.init_from_type (in_plugin, true);
var type_fun = new ClassRegisterFunction (cl);
type_fun.init_from_type (context, in_plugin, true);
decl_space.add_type_member_declaration (type_fun.get_declaration ());
}
}
......@@ -670,8 +670,8 @@ public class Vala.GTypeModule : GErrorModule {
cfile.add_type_member_definition (new CCodeComment (cl.comment.content));
}
var type_fun = new ClassRegisterFunction (cl, context);
type_fun.init_from_type (in_plugin, false);
var type_fun = new ClassRegisterFunction (cl);
type_fun.init_from_type (context, in_plugin, false);
cfile.add_type_member_declaration (type_fun.get_source_declaration ());
cfile.add_type_member_definition (type_fun.get_definition ());
......@@ -2064,8 +2064,8 @@ public class Vala.GTypeModule : GErrorModule {
decl_space.add_type_definition (type_struct);
var type_fun = new InterfaceRegisterFunction (iface, context);
type_fun.init_from_type (in_plugin, true);
var type_fun = new InterfaceRegisterFunction (iface);
type_fun.init_from_type (context, in_plugin, true);
decl_space.add_type_member_declaration (type_fun.get_declaration ());
}
......@@ -2110,8 +2110,8 @@ public class Vala.GTypeModule : GErrorModule {
cfile.add_type_member_definition (new CCodeComment (iface.comment.content));
}
var type_fun = new InterfaceRegisterFunction (iface, context);
type_fun.init_from_type (in_plugin, false);
var type_fun = new InterfaceRegisterFunction (iface);
type_fun.init_from_type (context, in_plugin, false);
cfile.add_type_member_declaration (type_fun.get_source_declaration ());
cfile.add_type_member_definition (type_fun.get_definition ());
......@@ -2213,8 +2213,8 @@ public class Vala.GTypeModule : GErrorModule {
if (get_ccode_has_type_id (st)) {
push_line (st.source_reference);
var type_fun = new StructRegisterFunction (st, context);
type_fun.init_from_type (false, false);
var type_fun = new StructRegisterFunction (st);
type_fun.init_from_type (context, false, false);
cfile.add_type_member_definition (type_fun.get_definition ());
pop_line ();
}
......@@ -2225,8 +2225,8 @@ public class Vala.GTypeModule : GErrorModule {
if (get_ccode_has_type_id (en)) {
push_line (en.source_reference);
var type_fun = new EnumRegisterFunction (en, context);
type_fun.init_from_type (false, false);
var type_fun = new EnumRegisterFunction (en);
type_fun.init_from_type (context, false, false);
cfile.add_type_member_definition (type_fun.get_definition ());
pop_line ();
}
......
......@@ -33,9 +33,8 @@ public class Vala.InterfaceRegisterFunction : TypeRegisterFunction {
*/
public weak Interface interface_reference { get; set; }
public InterfaceRegisterFunction (Interface iface, CodeContext context) {
public InterfaceRegisterFunction (Interface iface) {
interface_reference = iface;
this.context = context;
}
public override TypeSymbol get_type_declaration () {
......@@ -78,7 +77,7 @@ public class Vala.InterfaceRegisterFunction : TypeRegisterFunction {
return interface_reference.access;
}
public override void get_type_interface_init_statements (CCodeBlock block, bool plugin) {
public override void get_type_interface_init_statements (CodeContext context, CCodeBlock block, bool plugin) {
/* register all prerequisites */
foreach (DataType prereq_ref in interface_reference.get_prerequisites ()) {
var prereq = prereq_ref.data_type;
......
......@@ -37,9 +37,8 @@ public class Vala.StructRegisterFunction : TypeRegisterFunction {
* @param st a struct
* @return newly created struct register function
*/
public StructRegisterFunction (Struct st, CodeContext context) {
public StructRegisterFunction (Struct st) {
struct_reference = st;
this.context = context;
}
public override TypeSymbol get_type_declaration () {
......
......@@ -30,12 +30,10 @@ public abstract class Vala.TypeRegisterFunction {
CCodeFragment declaration_fragment = new CCodeFragment ();
CCodeFragment definition_fragment = new CCodeFragment ();
public CodeContext context { get; set; }
/**
* Constructs the C function from the specified type.
*/
public void init_from_type (bool plugin, bool declaration_only) {
public void init_from_type (CodeContext context, bool plugin, bool declaration_only) {
bool use_thread_safe = !plugin;
bool fundamental = false;
......@@ -215,7 +213,7 @@ public abstract class Vala.TypeRegisterFunction {
}
if (!declaration_only) {
get_type_interface_init_statements (type_init, plugin);
get_type_interface_init_statements (context, type_init, plugin);
}
if (!plugin) {
......@@ -414,7 +412,7 @@ public abstract class Vala.TypeRegisterFunction {
/**
* Returns additional C initialization statements to setup interfaces.
*/
public virtual void get_type_interface_init_statements (CCodeBlock block, bool plugin) {
public virtual void get_type_interface_init_statements (CodeContext context, CCodeBlock block, bool plugin) {
}
public CCodeFragment get_source_declaration () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment