This now serves as base for CCodeMacroReplacement too.
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 \
-/* 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 ();
}
}
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);
}
}
/**
* 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);
}
}