]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
ccode: Rename CCodeFeatureTestMacro to CCodeDefine and generalize it
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 13 Mar 2019 09:39:42 +0000 (10:39 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 22 Mar 2019 12:18:08 +0000 (13:18 +0100)
This now serves as base for CCodeMacroReplacement too.

ccode/Makefile.am
ccode/valaccodedefine.vala [moved from ccode/valaccodefeaturetestmacro.vala with 58% similarity]
ccode/valaccodefile.vala
ccode/valaccodemacroreplacement.vala

index b0d9b1358c6f4c8275d7a09a2192ff997c62acd3..18bb86364490e1f81bc5863852c4f7ec23bd257d 100644 (file)
@@ -29,13 +29,13 @@ libvalaccode_la_VALASOURCES = \
        valaccodecontinuestatement.vala \
        valaccodedeclaration.vala \
        valaccodedeclarator.vala \
+       valaccodedefine.vala \
        valaccodedostatement.vala \
        valaccodeemptystatement.vala \
        valaccodeenum.vala \
        valaccodeenumvalue.vala \
        valaccodeexpression.vala \
        valaccodeexpressionstatement.vala \
-       valaccodefeaturetestmacro.vala \
        valaccodefile.vala \
        valaccodeforstatement.vala \
        valaccodefragment.vala \
similarity index 58%
rename from ccode/valaccodefeaturetestmacro.vala
rename to ccode/valaccodedefine.vala
index d18f28dcb17748297f57c1fa7faed4f4b29b6085..24ad09828f48caa0ce181261a2b3f9d1e41bf882 100644 (file)
@@ -1,4 +1,4 @@
-/* valaccodefeaturetestmacro.vala
+/* valaccodedefine.vala
  *
  * Copyright (C) 2018  Dr. Michael 'Mickey' Lauer
  *
  *
  * Author:
  *     Dr. Michael 'Mickey' Lauer <mickey@vanille-media.de>
+ *     Rico Tzschichholz <ricotz@ubuntu.com>
  */
 
 using GLib;
 
 /**
- * Represents a feature test macro definition in the C code.
+ * Represents a definition in the C code.
  */
-public class Vala.CCodeFeatureTestMacro : CCodeNode {
+public class Vala.CCodeDefine : CCodeNode {
        /**
-        * The name of this macro.
+        * The name of this definition.
         */
        public string name { get; set; }
 
-       public CCodeFeatureTestMacro (string name) {
+       /**
+        * The value of this definition.
+        */
+       public string? value { get; set; }
+
+       /**
+        * The value expression of this definition.
+        */
+       public CCodeExpression? value_expression { get; set; }
+
+       public CCodeDefine (string name, string? value = null) {
+               this.name = name;
+               this.value = value;
+       }
+
+       public CCodeDefine.with_expression (string name, CCodeExpression expression) {
                this.name = name;
+               this.value_expression = expression;
        }
 
        public override void write (CCodeWriter writer) {
                writer.write_indent ();
                writer.write_string ("#define ");
                writer.write_string (name);
+               if (value != null) {
+                       writer.write_string (" ");
+                       writer.write_string (@value);
+               } else if (value_expression != null) {
+                       writer.write_string (" ");
+                       value_expression.write_inner (writer);
+               }
                writer.write_newline ();
        }
 }
index 6a8ae8ce310ffb3216b582cedbaf0831f77c47a0..adbdb188067ba9d0d4212ed5820f32993eb91dc9 100644 (file)
@@ -56,7 +56,7 @@ public class Vala.CCodeFile {
 
        public void add_feature_test_macro (string feature_test_macro) {
                if (!(feature_test_macro in features)) {
-                       feature_test_macros.append (new CCodeFeatureTestMacro (feature_test_macro));
+                       feature_test_macros.append (new CCodeDefine (feature_test_macro));
                        features.add (feature_test_macro);
                }
        }
index d865387ecc8791cf251e82bc85521555a5c8874b..c295eedf9e9a5ffb7769bba170b6cf3b53d80c98 100644 (file)
@@ -25,42 +25,12 @@ using GLib;
 /**
  * Represents a preprocessor macro replacement definition in the C code.
  */
-public class Vala.CCodeMacroReplacement : CCodeNode {
-       /**
-        * The name of this macro.
-        */
-       public string name { get; set; }
-
-       /**
-        * The replacement of this macro.
-        */
-       public string replacement { get; set; }
-
-       /**
-        * The replacement expression of this macro.
-        */
-       public CCodeExpression replacement_expression { get; set; }
-
+public class Vala.CCodeMacroReplacement : CCodeDefine {
        public CCodeMacroReplacement (string name, string replacement) {
-               this.replacement = replacement;
-               this.name = name;
+               base (name, replacement);
        }
 
        public CCodeMacroReplacement.with_expression (string name, CCodeExpression replacement_expression) {
-               this.name = name;
-               this.replacement_expression = replacement_expression;
-       }
-
-       public override void write (CCodeWriter writer) {
-               writer.write_indent ();
-               writer.write_string ("#define ");
-               writer.write_string (name);
-               writer.write_string (" ");
-               if (replacement != null) {
-                       writer.write_string (replacement);
-               } else {
-                       replacement_expression.write_inner (writer);
-               }
-               writer.write_newline ();
+               base.with_expression (name, replacement_expression);
        }
 }