[vala/staging: 1/3] Add CCodeNode "modifiers" and transform CCodeFunction's "attributes" to it
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 1/3] Add CCodeNode "modifiers" and transform CCodeFunction's "attributes" to it
- Date: Tue, 8 Nov 2016 17:49:09 +0000 (UTC)
commit dcac30061993d9625fc6ebb74ad9e42cafb9ff65
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Nov 8 12:00:48 2016 +0100
Add CCodeNode "modifiers" and transform CCodeFunction's "attributes" to it
ccode/valaccodedeclaration.vala | 5 -----
ccode/valaccodefunction.vala | 22 +++++++++++-----------
ccode/valaccodemodifiers.vala | 6 +++++-
ccode/valaccodenode.vala | 6 ++++++
codegen/valaccodebasemodule.vala | 7 +++----
codegen/valaccodemethodmodule.vala | 6 ++----
codegen/valagdbusclientmodule.vala | 2 +-
codegen/valagtypemodule.vala | 18 ++++++------------
codegen/valatyperegisterfunction.vala | 10 ++++------
9 files changed, 38 insertions(+), 44 deletions(-)
---
diff --git a/ccode/valaccodedeclaration.vala b/ccode/valaccodedeclaration.vala
index 634165a..4d0fa74 100644
--- a/ccode/valaccodedeclaration.vala
+++ b/ccode/valaccodedeclaration.vala
@@ -31,11 +31,6 @@ public class Vala.CCodeDeclaration : CCodeStatement {
*/
public string type_name { get; set; }
- /**
- * The declaration modifier.
- */
- public CCodeModifiers modifiers { get; set; }
-
private List<CCodeDeclarator> declarators = new ArrayList<CCodeDeclarator> ();
public CCodeDeclaration (string type_name) {
diff --git a/ccode/valaccodefunction.vala b/ccode/valaccodefunction.vala
index 44dd5b9..43bfb6c 100644
--- a/ccode/valaccodefunction.vala
+++ b/ccode/valaccodefunction.vala
@@ -32,17 +32,10 @@ public class Vala.CCodeFunction : CCodeNode {
public string name { get; set; }
/**
- * The function modifiers.
- */
- public CCodeModifiers modifiers { get; set; }
-
- /**
* The function return type.
*/
public string return_type { get; set; }
- public string attributes { get; set; }
-
public bool is_declaration { get; set; }
/**
@@ -96,7 +89,6 @@ public class Vala.CCodeFunction : CCodeNode {
public CCodeFunction copy () {
var func = new CCodeFunction (name, return_type);
func.modifiers = modifiers;
- func.attributes = attributes;
/* no deep copy for lists available yet
* func.parameters = parameters.copy ();
@@ -153,9 +145,17 @@ public class Vala.CCodeFunction : CCodeNode {
writer.write_string (" G_GNUC_FORMAT(%d)".printf (format_arg_index + 1));
}
- if (attributes != null) {
- writer.write_string (" ");
- writer.write_string (attributes);
+ if (CCodeModifiers.CONST in modifiers) {
+ writer.write_string (" G_GNUC_CONST");
+ }
+ if (CCodeModifiers.UNUSED in modifiers) {
+ writer.write_string (" G_GNUC_UNUSED");
+ }
+
+ if (CCodeModifiers.CONSTRUCTOR in modifiers) {
+ writer.write_string (" __attribute__((constructor))");
+ } else if (CCodeModifiers.DESTRUCTOR in modifiers) {
+ writer.write_string (" __attribute__((destructor))");
}
writer.write_string (";");
diff --git a/ccode/valaccodemodifiers.vala b/ccode/valaccodemodifiers.vala
index 600751d..086056f 100644
--- a/ccode/valaccodemodifiers.vala
+++ b/ccode/valaccodemodifiers.vala
@@ -34,5 +34,9 @@ public enum Vala.CCodeModifiers {
VOLATILE = 1 << 4,
DEPRECATED = 1 << 5,
THREAD_LOCAL = 1 << 6,
- INTERNAL = 1 << 7
+ INTERNAL = 1 << 7,
+ CONST = 1 << 8,
+ UNUSED = 1 << 9,
+ CONSTRUCTOR = 1 << 10,
+ DESTRUCTOR = 1 << 11
}
diff --git a/ccode/valaccodenode.vala b/ccode/valaccodenode.vala
index 6ab095f..d8c3e5c 100644
--- a/ccode/valaccodenode.vala
+++ b/ccode/valaccodenode.vala
@@ -33,6 +33,12 @@ public abstract class Vala.CCodeNode {
public CCodeLineDirective line { get; set; }
/**
+ * The modifiers for this code node which will be handled as needed
+ * in every subclass.
+ */
+ public CCodeModifiers modifiers { get; set; }
+
+ /**
* Writes this code node and all children with the specified C code
* writer.
*
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index cdab6f1..adccba7 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -827,14 +827,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var fun_name = "%s_get_type".printf (get_ccode_lower_case_name (en, null));
var regfun = new CCodeFunction (fun_name, "GType");
- regfun.attributes = "G_GNUC_CONST";
+ regfun.modifiers = CCodeModifiers.CONST;
if (en.is_private_symbol ()) {
- regfun.modifiers = CCodeModifiers.STATIC;
// avoid C warning as this function is not always used
- regfun.attributes += " G_GNUC_UNUSED";
+ regfun.modifiers |= CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
} else if (context.hide_internal && en.is_internal_symbol ()) {
- regfun.modifiers = CCodeModifiers.INTERNAL;
+ regfun.modifiers |= CCodeModifiers.INTERNAL;
}
decl_space.add_function_declaration (regfun);
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index b50380a..195592f 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -369,8 +369,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
cfile.add_type_member_declaration (timer_decl);
var constructor = new CCodeFunction (prefix + "_init");
- constructor.modifiers = CCodeModifiers.STATIC;
- constructor.attributes = "__attribute__((constructor))";
+ constructor.modifiers = CCodeModifiers.STATIC | CCodeModifiers.CONSTRUCTOR;
cfile.add_function_declaration (constructor);
push_function (constructor);
@@ -385,8 +384,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
var destructor = new CCodeFunction (prefix + "_exit");
- destructor.modifiers = CCodeModifiers.STATIC;
- destructor.attributes = "__attribute__((destructor))";
+ destructor.modifiers = CCodeModifiers.STATIC | CCodeModifiers.DESTRUCTOR;
cfile.add_function_declaration (destructor);
push_function (destructor);
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index 079ac52..20229fd 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -163,7 +163,7 @@ public class Vala.GDBusClientModule : GDBusModule {
// declare proxy_get_type function
var proxy_get_type = new CCodeFunction (get_type_name, "GType");
- proxy_get_type.attributes = "G_GNUC_CONST";
+ proxy_get_type.modifiers = CCodeModifiers.CONST;
decl_space.add_function_declaration (proxy_get_type);
if (in_plugin) {
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 692a9bd..d4313d1 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -119,9 +119,8 @@ public class Vala.GTypeModule : GErrorModule {
function.add_parameter (new CCodeParameter ("flags", "GParamFlags"));
if (cl.is_private_symbol ()) {
- function.modifiers = CCodeModifiers.STATIC;
// avoid C warning as this function is not always used
- function.attributes = "G_GNUC_UNUSED";
+ function.modifiers = CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
} else if (context.hide_internal && cl.is_internal_symbol ()) {
function.modifiers = CCodeModifiers.INTERNAL;
}
@@ -133,13 +132,11 @@ public class Vala.GTypeModule : GErrorModule {
function.add_parameter (new CCodeParameter ("v_object", "gpointer"));
if (cl.is_private_symbol ()) {
- function.modifiers = CCodeModifiers.STATIC;
// avoid C warning as this function is not always used
- function.attributes = "G_GNUC_UNUSED";
+ function.modifiers = CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
} else if (context.hide_internal && cl.is_internal_symbol ()) {
- function.modifiers = CCodeModifiers.INTERNAL;
// avoid C warning as this function is not always used
- function.attributes = "G_GNUC_UNUSED";
+ function.modifiers = CCodeModifiers.INTERNAL | CCodeModifiers.UNUSED;
}
decl_space.add_function_declaration (function);
@@ -149,9 +146,8 @@ public class Vala.GTypeModule : GErrorModule {
function.add_parameter (new CCodeParameter ("v_object", "gpointer"));
if (cl.is_private_symbol ()) {
- function.modifiers = CCodeModifiers.STATIC;
// avoid C warning as this function is not always used
- function.attributes = "G_GNUC_UNUSED";
+ function.modifiers = CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
} else if (context.hide_internal && cl.is_internal_symbol ()) {
function.modifiers = CCodeModifiers.INTERNAL;
}
@@ -162,13 +158,11 @@ public class Vala.GTypeModule : GErrorModule {
function.add_parameter (new CCodeParameter ("value", "const GValue*"));
if (cl.is_private_symbol ()) {
- function.modifiers = CCodeModifiers.STATIC;
// avoid C warning as this function is not always used
- function.attributes = "G_GNUC_UNUSED";
+ function.modifiers = CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
} else if (context.hide_internal && cl.is_internal_symbol ()) {
- function.modifiers = CCodeModifiers.INTERNAL;
// avoid C warning as this function is not always used
- function.attributes = "G_GNUC_UNUSED";
+ function.modifiers = CCodeModifiers.INTERNAL | CCodeModifiers.UNUSED;
}
decl_space.add_function_declaration (function);
diff --git a/codegen/valatyperegisterfunction.vala b/codegen/valatyperegisterfunction.vala
index b7c18f8..9617f82 100644
--- a/codegen/valatyperegisterfunction.vala
+++ b/codegen/valatyperegisterfunction.vala
@@ -68,24 +68,22 @@ public abstract class Vala.TypeRegisterFunction {
CCodeFunction fun;
if (!plugin) {
fun = new CCodeFunction ("%s_get_type".printf
(CCodeBaseModule.get_ccode_lower_case_name (get_type_declaration ())), "GType");
- fun.attributes = "G_GNUC_CONST";
+ fun.modifiers = CCodeModifiers.CONST;
/* Function will not be prototyped anyway */
if (get_accessibility () == SymbolAccessibility.PRIVATE) {
- fun.modifiers = CCodeModifiers.STATIC;
// avoid C warning as this function is not always used
- fun.attributes += " G_GNUC_UNUSED";
+ fun.modifiers |= CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
} else if (context.hide_internal && get_accessibility () ==
SymbolAccessibility.INTERNAL) {
- fun.modifiers = CCodeModifiers.INTERNAL;
// avoid C warning as this function is not always used
- fun.attributes += " G_GNUC_UNUSED";
+ fun.modifiers |= CCodeModifiers.INTERNAL | CCodeModifiers.UNUSED;
}
} else {
fun = new CCodeFunction ("%s_register_type".printf
(CCodeBaseModule.get_ccode_lower_case_name (get_type_declaration ())), "GType");
fun.add_parameter (new CCodeParameter ("module", "GTypeModule *"));
var get_fun = new CCodeFunction ("%s_get_type".printf
(CCodeBaseModule.get_ccode_lower_case_name (get_type_declaration ())), "GType");
- get_fun.attributes = "G_GNUC_CONST";
+ get_fun.modifiers = CCodeModifiers.CONST;
get_fun.is_declaration = true;
declaration_fragment.append (get_fun.copy ());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]