Commit 114013c4 authored by Luca Bruno's avatar Luca Bruno

Move DataType.get_cdeclarator_suffix to the codegen

parent ef31992e
......@@ -904,7 +904,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
var cdecl = new CCodeDeclaration (field_ctype);
cdecl.add_declarator (new CCodeVariableDeclarator (get_ccode_name (f), null, f.variable_type.get_cdeclarator_suffix ()));
cdecl.add_declarator (new CCodeVariableDeclarator (get_ccode_name (f), null, get_ccode_declarator_suffix (f.variable_type)));
if (f.is_private_symbol ()) {
cdecl.modifiers = CCodeModifiers.STATIC;
} else {
......@@ -1083,7 +1083,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
lhs = new CCodeIdentifier (get_ccode_name (f));
var var_decl = new CCodeVariableDeclarator (get_ccode_name (f), null, f.variable_type.get_cdeclarator_suffix ());
var var_decl = new CCodeVariableDeclarator (get_ccode_name (f), null, get_ccode_declarator_suffix (f.variable_type));
var_decl.initializer = default_value_for_type (f.variable_type, true);
if (class_init_context != null) {
......@@ -1769,7 +1769,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (local.captured) {
generate_type_declaration (local.variable_type, cfile);
data.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + local.variable_type.get_cdeclarator_suffix ());
data.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + get_ccode_declarator_suffix (local.variable_type));
if (local.variable_type is ArrayType) {
var array_type = (ArrayType) local.variable_type;
......@@ -2092,9 +2092,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (!local.captured) {
if (current_method != null && current_method.coroutine) {
closure_struct.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + local.variable_type.get_cdeclarator_suffix ());
closure_struct.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + get_ccode_declarator_suffix (local.variable_type));
} else {
var cvar = new CCodeVariableDeclarator (get_variable_cname (local.name), null, local.variable_type.get_cdeclarator_suffix ());
var cvar = new CCodeVariableDeclarator (get_variable_cname (local.name), null, get_ccode_declarator_suffix (local.variable_type));
// try to initialize uninitialized variables
// initialization not necessary for variables stored in closure
......@@ -3119,7 +3119,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
}
} else {
var cvar = new CCodeVariableDeclarator (local.name, null, local.variable_type.get_cdeclarator_suffix ());
var cvar = new CCodeVariableDeclarator (local.name, null, get_ccode_declarator_suffix (local.variable_type));
if (init) {
cvar.initializer = default_value_for_type (local.variable_type, true);
cvar.init0 = true;
......@@ -5814,6 +5814,18 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return prop.get_attribute_bool ("CCode", "notify", true);
}
public static string get_ccode_declarator_suffix (DataType type) {
var array_type = type as ArrayType;
if (array_type != null) {
if (array_type.fixed_length) {
return "[%d]".printf (array_type.length);
} else if (array_type.inline_allocated) {
return "[]";
}
}
return "";
}
public CCodeConstant get_signal_canonical_constant (Signal sig, string? detail = null) {
var str = new StringBuilder ("\"");
......
......@@ -64,7 +64,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
if (f.binding == MemberBinding.INSTANCE) {
generate_type_declaration (f.variable_type, decl_space);
instance_struct.add_field (field_ctype, get_ccode_name (f) + f.variable_type.get_cdeclarator_suffix (), f.deprecated ? " G_GNUC_DEPRECATED" : null);
instance_struct.add_field (field_ctype, get_ccode_name (f) + get_ccode_declarator_suffix (f.variable_type), f.deprecated ? " G_GNUC_DEPRECATED" : null);
if (f.variable_type is ArrayType && get_ccode_array_length (f)) {
// create fields to store array dimensions
var array_type = (ArrayType) f.variable_type;
......
......@@ -676,7 +676,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
if (local.captured) {
generate_type_declaration (local.variable_type, cfile);
data.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + local.variable_type.get_cdeclarator_suffix ());
data.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + get_ccode_declarator_suffix (local.variable_type));
}
}
// free in reverse order
......@@ -868,7 +868,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id ((Block) local.parent_symbol))), get_variable_cname (local.name)), rhs);
}
} else {
var cvar = new CCodeVariableDeclarator (get_variable_cname (local.name), rhs, local.variable_type.get_cdeclarator_suffix ());
var cvar = new CCodeVariableDeclarator (get_variable_cname (local.name), rhs, get_ccode_declarator_suffix (local.variable_type));
var cdecl = new CCodeDeclaration (get_ccode_name (local.variable_type));
cdecl.add_declarator (cvar);
......@@ -1151,7 +1151,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
public void emit_temp_var (LocalVariable local) {
var cdecl = new CCodeDeclaration (get_ccode_name (local.variable_type));
var vardecl = new CCodeVariableDeclarator (local.name, null, local.variable_type.get_cdeclarator_suffix ());
var vardecl = new CCodeVariableDeclarator (local.name, null, get_ccode_declarator_suffix (local.variable_type));
cdecl.add_declarator (vardecl);
var st = local.variable_type.data_type as Struct;
......@@ -2350,6 +2350,10 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
return CCodeBaseModule.get_ccode_sentinel (m);
}
public string get_ccode_declarator_suffix (DataType type) {
return CCodeBaseModule.get_ccode_declarator_suffix (type);
}
public DataType? get_this_type () {
if (current_method != null && current_method.binding == MemberBinding.INSTANCE) {
return current_method.this_parameter.variable_type;
......
......@@ -153,7 +153,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
field_ctype = "volatile " + field_ctype;
}
instance_priv_struct.add_field (field_ctype, get_ccode_name (f) + f.variable_type.get_cdeclarator_suffix ());
instance_priv_struct.add_field (field_ctype, get_ccode_name (f) + get_ccode_declarator_suffix (f.variable_type));
}
}
......
......@@ -60,7 +60,7 @@ public abstract class Vala.DovaStructModule : DovaBaseModule {
if (f.binding == MemberBinding.INSTANCE) {
generate_type_declaration (f.variable_type, decl_space);
instance_struct.add_field (field_ctype, get_ccode_name (f) + f.variable_type.get_cdeclarator_suffix ());
instance_struct.add_field (field_ctype, get_ccode_name (f) + get_ccode_declarator_suffix (f.variable_type));
}
}
......
......@@ -312,7 +312,7 @@ public class Vala.GTypeModule : GErrorModule {
if (f.binding == MemberBinding.INSTANCE) {
generate_type_declaration (f.variable_type, decl_space);
instance_struct.add_field (field_ctype, get_ccode_name (f), f.variable_type.get_cdeclarator_suffix ());
instance_struct.add_field (field_ctype, get_ccode_name (f), get_ccode_declarator_suffix (f.variable_type));
if (f.variable_type is ArrayType && get_ccode_array_length (f)) {
// create fields to store array dimensions
var array_type = (ArrayType) f.variable_type;
......@@ -419,7 +419,7 @@ public class Vala.GTypeModule : GErrorModule {
if (f.access == SymbolAccessibility.PRIVATE) {
generate_type_declaration (f.variable_type, decl_space);
instance_priv_struct.add_field (field_ctype, get_ccode_name (f), f.variable_type.get_cdeclarator_suffix ());
instance_priv_struct.add_field (field_ctype, get_ccode_name (f), get_ccode_declarator_suffix (f.variable_type));
if (f.variable_type is ArrayType && get_ccode_array_length (f)) {
// create fields to store array dimensions
var array_type = (ArrayType) f.variable_type;
......
......@@ -148,16 +148,6 @@ public class Vala.ArrayType : ReferenceType {
return result;
}
public override string get_cdeclarator_suffix () {
if (fixed_length) {
return "[%d]".printf (length);
} else if (inline_allocated) {
return "[]";
} else {
return "";
}
}
public override bool is_array () {
return true;
}
......
......@@ -117,10 +117,6 @@ public abstract class Vala.DataType : CodeNode {
}
}
public virtual string get_cdeclarator_suffix () {
return "";
}
public override string to_string () {
return to_qualified_string (null);
}
......
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