[vala/wip/defines: 1/2] ccode: Rename CCodeFeatureTestMacro to CCodeDefine and generalize it



commit 02fa01e94380f4a815692b030466a3e607ca2c04
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Mar 13 10:39:42 2019 +0100

    ccode: Rename CCodeFeatureTestMacro to CCodeDefine and generalize it
    
    This now serves as base for CCodeMacroReplacement too.

 ccode/Makefile.am                                  |  2 +-
 ...efeaturetestmacro.vala => valaccodedefine.vala} | 34 +++++++++++++++++---
 ccode/valaccodefile.vala                           |  2 +-
 ccode/valaccodemacroreplacement.vala               | 36 ++--------------------
 4 files changed, 34 insertions(+), 40 deletions(-)
---
diff --git a/ccode/Makefile.am b/ccode/Makefile.am
index b0d9b1358..18bb86364 100644
--- a/ccode/Makefile.am
+++ b/ccode/Makefile.am
@@ -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 \
diff --git a/ccode/valaccodefeaturetestmacro.vala b/ccode/valaccodedefine.vala
similarity index 58%
rename from ccode/valaccodefeaturetestmacro.vala
rename to ccode/valaccodedefine.vala
index d18f28dcb..24ad09828 100644
--- a/ccode/valaccodefeaturetestmacro.vala
+++ b/ccode/valaccodedefine.vala
@@ -1,4 +1,4 @@
-/* valaccodefeaturetestmacro.vala
+/* valaccodedefine.vala
  *
  * Copyright (C) 2018  Dr. Michael 'Mickey' Lauer
  *
@@ -18,27 +18,51 @@
  *
  * 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 ();
        }
 }
diff --git a/ccode/valaccodefile.vala b/ccode/valaccodefile.vala
index 6a8ae8ce3..adbdb1880 100644
--- a/ccode/valaccodefile.vala
+++ b/ccode/valaccodefile.vala
@@ -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);
                }
        }
diff --git a/ccode/valaccodemacroreplacement.vala b/ccode/valaccodemacroreplacement.vala
index d865387ec..c295eedf9 100644
--- a/ccode/valaccodemacroreplacement.vala
+++ b/ccode/valaccodemacroreplacement.vala
@@ -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);
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]