Commit 2fb2383e authored by Evan Nemerson's avatar Evan Nemerson Committed by Jürg Billeter

codegen: write G_GNUC_DEPRECATED in generated C where appropriate

parent a2c97938
......@@ -30,7 +30,7 @@ public class Vala.CCodeDeclaration : CCodeStatement {
* The type of the local variable.
*/
public string type_name { get; set; }
/**
* The declaration modifier.
*/
......@@ -95,6 +95,10 @@ public class Vala.CCodeDeclaration : CCodeStatement {
decl.write (writer);
}
if (CCodeModifiers.DEPRECATED in modifiers) {
writer.write_string (" G_GNUC_DEPRECATED");
}
writer.write_string (";");
writer.write_newline ();
return;
......
......@@ -30,6 +30,11 @@ public class Vala.CCodeEnum : CCodeNode {
* The name of this enum.
*/
public string name { get; set; }
/**
* Whether the enum is deprecated.
*/
public bool deprecated { get; set; default = false; }
private List<CCodeEnumValue> values = new ArrayList<CCodeEnumValue> ();
......@@ -71,6 +76,9 @@ public class Vala.CCodeEnum : CCodeNode {
writer.write_string (" ");
writer.write_string (name);
}
if (deprecated) {
writer.write_string (" G_GNUC_DEPRECATED");
}
writer.write_string (";");
writer.write_newline ();
}
......
......@@ -31,6 +31,11 @@ public class Vala.CCodeEnumValue : CCodeNode {
*/
public string name { get; set; }
/**
* Whether this enum value is deprecated.
*/
public bool deprecated { get; set; default = false; }
/**
* The numerical representation of this enum value.
*/
......
......@@ -117,6 +117,10 @@ public class Vala.CCodeFunction : CCodeNode {
writer.write_string (")");
if (CCodeModifiers.DEPRECATED in modifiers) {
writer.write_string (" G_GNUC_DEPRECATED");
}
if (block == null) {
if (attributes != null) {
writer.write_string (" ");
......
......@@ -30,5 +30,6 @@ public enum Vala.CCodeModifiers {
REGISTER = 1 << 1,
EXTERN = 1 << 2,
INLINE = 1 << 3,
VOLATILE = 1 << 4
VOLATILE = 1 << 4,
DEPRECATED = 1 << 5
}
......@@ -30,6 +30,11 @@ public class Vala.CCodeStruct : CCodeNode {
* The struct name.
*/
public string name { get; set; }
/**
* Whether the struct is deprecated.
*/
public bool deprecated { get; set; default = false; }
private List<CCodeDeclaration> declarations = new ArrayList<CCodeDeclaration> ();
......@@ -65,7 +70,11 @@ public class Vala.CCodeStruct : CCodeNode {
foreach (CCodeDeclaration decl in declarations) {
decl.write_declaration (writer);
}
writer.write_end_block ();
if (deprecated) {
writer.write_string (" G_GNUC_DEPRECATED");
}
writer.write_string (";");
writer.write_newline ();
writer.write_newline ();
......
......@@ -35,6 +35,11 @@ public class Vala.CCodeTypeDefinition : CCodeNode {
* The type declarator.
*/
public CCodeDeclarator declarator { get; set; }
/**
* Whether the type is deprecated.
*/
public bool deprecated { get; set; default = false; }
public CCodeTypeDefinition (string type, CCodeDeclarator decl) {
type_name = type;
......@@ -53,7 +58,11 @@ public class Vala.CCodeTypeDefinition : CCodeNode {
writer.write_string (" ");
declarator.write_declaration (writer);
if (deprecated) {
writer.write_string (" G_GNUC_DEPRECATED");
}
writer.write_string (";");
writer.write_newline ();
}
......
......@@ -767,13 +767,18 @@ public class Vala.CCodeBaseModule : CCodeModule {
var cenum = new CCodeEnum (en.get_cname ());
cenum.deprecated = en.deprecated;
foreach (EnumValue ev in en.get_values ()) {
CCodeEnumValue c_ev;
if (ev.value == null) {
cenum.add_value (new CCodeEnumValue (ev.get_cname ()));
c_ev = new CCodeEnumValue (ev.get_cname ());
} else {
ev.value.accept (codegen);
cenum.add_value (new CCodeEnumValue (ev.get_cname (), (CCodeExpression) ev.value.ccodenode));
c_ev = new CCodeEnumValue (ev.get_cname (), (CCodeExpression) ev.value.ccodenode);
}
c_ev.deprecated = ev.deprecated;
cenum.add_value (c_ev);
}
decl_space.add_type_definition (cenum);
......@@ -879,7 +884,7 @@ public class Vala.CCodeBaseModule : CCodeModule {
} else {
cdecl.modifiers = CCodeModifiers.EXTERN;
}
decl_space.add_constant_declaration (cdecl);
} else {
var cdefine = new CCodeMacroReplacement.with_expression (c.get_cname (), (CCodeExpression) c.initializer.ccodenode);
......@@ -918,6 +923,9 @@ public class Vala.CCodeBaseModule : CCodeModule {
} else {
cdecl.modifiers = CCodeModifiers.EXTERN;
}
if (f.deprecated) {
cdecl.modifiers |= CCodeModifiers.DEPRECATED;
}
decl_space.add_type_member_declaration (cdecl);
if (f.get_lock_used ()) {
......
......@@ -110,6 +110,8 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
}
var ctypedef = new CCodeTypeDefinition (return_type_cname, cfundecl);
ctypedef.deprecated = d.deprecated;
decl_space.add_type_definition (ctypedef);
}
......
......@@ -179,6 +179,10 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
}
}
if (m.deprecated) {
function.modifiers |= CCodeModifiers.DEPRECATED;
}
var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
var carg_map = new HashMap<int,CCodeExpression> (direct_hash, direct_equal);
......
......@@ -63,6 +63,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
}
var instance_struct = new CCodeStruct ("_%s".printf (st.get_cname ()));
instance_struct.deprecated = st.deprecated;
foreach (Field f in st.get_fields ()) {
string field_ctype = f.field_type.get_cname ();
......@@ -73,7 +74,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
if (f.binding == MemberBinding.INSTANCE) {
generate_type_declaration (f.field_type, decl_space);
instance_struct.add_field (field_ctype, f.get_cname () + f.field_type.get_cdeclarator_suffix ());
instance_struct.add_field (field_ctype, f.get_cname () + f.field_type.get_cdeclarator_suffix (), f.deprecated ? " G_GNUC_DEPRECATED" : null);
if (f.field_type is ArrayType && !f.no_array_length) {
// create fields to store array dimensions
var array_type = (ArrayType) f.field_type;
......
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