[vala/wip/attributes: 4/4] Refactor checks in Struct to use the new attributes methods
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/attributes: 4/4] Refactor checks in Struct to use the new attributes methods
- Date: Fri, 24 Jun 2011 12:16:21 +0000 (UTC)
commit b3a54a976cfc10b173e16ff71bc81c06a0610fd8
Author: Luca Bruno <lucabru src gnome org>
Date: Fri Jun 24 14:02:40 2011 +0200
Refactor checks in Struct to use the new attributes methods
vala/valastruct.vala | 97 ++++++++++++++++++++++++-------------------------
1 files changed, 48 insertions(+), 49 deletions(-)
---
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index 0b01ffa..9a908d1 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -38,10 +38,6 @@ public class Vala.Struct : TypeSymbol {
private string type_id;
private string lower_case_cprefix;
private string lower_case_csuffix;
- private bool boolean_type;
- private bool integer_type;
- private bool floating_type;
- private bool decimal_floating_type;
private int rank;
private string marshaller_type_name;
private string get_value_function;
@@ -341,13 +337,16 @@ public class Vala.Struct : TypeSymbol {
* @return true if this is a boolean type, false otherwise
*/
public bool is_boolean_type () {
- if (base_type != null) {
- var st = base_struct;
- if (st != null && st.is_boolean_type ()) {
- return true;
- }
+ if (has_attribute ("BooleanType")) {
+ return true;
+ }
+
+ var st = base_struct;
+ if (st != null && st.is_boolean_type ()) {
+ set_default_attribute ("BooleanType");
+ return true;
}
- return boolean_type;
+ return false;
}
/**
@@ -356,13 +355,15 @@ public class Vala.Struct : TypeSymbol {
* @return true if this is an integer type, false otherwise
*/
public bool is_integer_type () {
- if (base_type != null) {
- var st = base_struct;
- if (st != null && st.is_integer_type ()) {
- return true;
- }
+ if (has_attribute ("IntegerType")) {
+ return true;
+ }
+
+ var st = base_struct;
+ if (st != null && st.is_integer_type ()) {
+ set_default_attribute ("IntegerType");
}
- return integer_type;
+ return false;
}
/**
@@ -371,23 +372,28 @@ public class Vala.Struct : TypeSymbol {
* @return true if this is a floating point type, false otherwise
*/
public bool is_floating_type () {
- if (base_type != null) {
- var st = base_struct;
- if (st != null && st.is_floating_type ()) {
- return true;
- }
+ if (has_attribute ("FloatingType")) {
+ return true;
+ }
+
+ var st = base_struct;
+ if (st != null && st.is_floating_type ()) {
+ set_default_attribute ("FloatingType");
}
- return floating_type;
+ return false;
}
public bool is_decimal_floating_type () {
- if (base_type != null) {
- var st = base_struct;
- if (st != null && st.is_decimal_floating_type ()) {
- return true;
- }
+ if (get_attribute_bool ("FloatingType", "decimal")) {
+ return true;
}
- return decimal_floating_type;
+
+ var st = base_struct;
+ if (st != null && st.is_decimal_floating_type ()) {
+ set_attribute_default_argument ("FloatingType", "decimal", true);
+ return true;
+ }
+ return false;
}
/**
@@ -462,12 +468,7 @@ public class Vala.Struct : TypeSymbol {
}
}
- private void process_boolean_type_attribute (Attribute a) {
- boolean_type = true;
- }
-
private void process_integer_type_attribute (Attribute a) {
- integer_type = true;
if (a.has_argument ("rank")) {
rank = a.get_integer ("rank");
}
@@ -480,13 +481,9 @@ public class Vala.Struct : TypeSymbol {
}
private void process_floating_type_attribute (Attribute a) {
- floating_type = true;
if (a.has_argument ("rank")) {
rank = a.get_integer ("rank");
}
- if (a.has_argument ("decimal")) {
- decimal_floating_type = a.get_bool ("decimal");
- }
if (a.has_argument ("width")) {
width = a.get_integer ("width");
}
@@ -499,8 +496,6 @@ public class Vala.Struct : TypeSymbol {
foreach (Attribute a in attributes.get_values ()) {
if (a.name == "CCode") {
process_ccode_attribute (a);
- } else if (a.name == "BooleanType") {
- process_boolean_type_attribute (a);
} else if (a.name == "IntegerType") {
process_integer_type_attribute (a);
} else if (a.name == "FloatingType") {
@@ -663,9 +658,9 @@ public class Vala.Struct : TypeSymbol {
}
if (CodeContext.get ().profile == Profile.DOVA) {
- if (boolean_type) {
+ if (is_boolean_type ()) {
return "false";
- } else if (integer_type || floating_type) {
+ } else if (is_integer_type () || is_floating_type ()) {
return "0";
}
}
@@ -695,17 +690,21 @@ public class Vala.Struct : TypeSymbol {
* instances are passed by value.
*/
public bool is_simple_type () {
- if (base_type != null) {
- var st = base_struct;
- if (st != null && st.is_simple_type ()) {
- return true;
- }
+ if (CodeContext.get ().profile == Profile.DOVA || has_attribute ("SimpleType")) {
+ return true;
}
- if (CodeContext.get ().profile == Profile.DOVA) {
+
+ if (has_attribute ("BooleanType") || has_attribute ("IntegerType") || has_attribute ("FloatingType")) {
+ set_default_attribute ("SimpleType");
+ return true;
+ }
+
+ var st = base_struct;
+ if (st != null && st.is_simple_type ()) {
+ set_default_attribute ("SimpleType");
return true;
}
- return (boolean_type || integer_type || floating_type
- || get_attribute ("SimpleType") != null);
+ return false;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]