summaryrefslogtreecommitdiff
path: root/ccode
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2016-11-08 12:00:48 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2016-11-08 12:40:17 +0100
commitdcac30061993d9625fc6ebb74ad9e42cafb9ff65 (patch)
tree12be29951496af11b3566f52993c146733256c3f /ccode
parent43e617dd33c335645335a5b68f8658f011de7afc (diff)
downloadvala-dcac30061993d9625fc6ebb74ad9e42cafb9ff65.tar.gz
Add CCodeNode "modifiers" and transform CCodeFunction's "attributes" to it
Diffstat (limited to 'ccode')
-rw-r--r--ccode/valaccodedeclaration.vala5
-rw-r--r--ccode/valaccodefunction.vala22
-rw-r--r--ccode/valaccodemodifiers.vala6
-rw-r--r--ccode/valaccodenode.vala6
4 files changed, 22 insertions, 17 deletions
diff --git a/ccode/valaccodedeclaration.vala b/ccode/valaccodedeclaration.vala
index 634165a69..4d0fa7425 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 44dd5b956..43bfb6cbb 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 600751d6c..086056f67 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 6ab095f60..d8c3e5cdf 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.
*