summaryrefslogtreecommitdiff
path: root/ccode
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2021-02-01 14:54:55 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2021-02-01 14:54:55 +0100
commit54eb054f49336af900a7b7b06bbf1a523eaeca5e (patch)
tree13e8fbd67d1004a7031e10e0d75536dd1fa6c93d /ccode
parent2df469dfc7619aaa31319f150af453e577665597 (diff)
downloadvala-54eb054f49336af900a7b7b06bbf1a523eaeca5e.tar.gz
codegen: Use CCodeDeclaratorSuffix to emit array length of constants
Diffstat (limited to 'ccode')
-rw-r--r--ccode/valaccodevariabledeclarator.vala24
1 files changed, 18 insertions, 6 deletions
diff --git a/ccode/valaccodevariabledeclarator.vala b/ccode/valaccodevariabledeclarator.vala
index f39eff0ed..f5d2302cf 100644
--- a/ccode/valaccodevariabledeclarator.vala
+++ b/ccode/valaccodevariabledeclarator.vala
@@ -97,20 +97,32 @@ public class Vala.CCodeVariableDeclarator : CCodeDeclarator {
public class Vala.CCodeDeclaratorSuffix {
bool array;
- CCodeExpression? array_length;
+ List<CCodeExpression>? array_length;
public CCodeDeclaratorSuffix.with_array (CCodeExpression? array_length = null) {
+ if (array_length != null) {
+ this.array_length = new ArrayList<CCodeExpression> ();
+ this.array_length.add (array_length);
+ }
+ array = true;
+ }
+
+ public CCodeDeclaratorSuffix.with_multi_array (List<CCodeExpression>? array_length = null) {
this.array_length = array_length;
array = true;
}
public void write (CCodeWriter writer) {
- if (array) {
- writer.write_string ("[");
- if (array_length != null) {
- array_length.write (writer);
+ if (array_length != null && array_length.size > 0) {
+ foreach (var length in array_length) {
+ writer.write_string ("[");
+ if (length != null) {
+ length.write (writer);
+ }
+ writer.write_string ("]");
}
- writer.write_string ("]");
+ } else if (array) {
+ writer.write_string ("[]");
}
}
}