diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-03-13 10:39:42 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-03-22 13:18:08 +0100 |
commit | 7584b130672622bdf4701388315ee5edc5b03d14 (patch) | |
tree | 3c250ed5dc0eaa7e2ec568162f0fd60caa9943aa /ccode | |
parent | 230cd3543514a6152236aecb39169a5f87eb3c86 (diff) | |
download | vala-7584b130672622bdf4701388315ee5edc5b03d14.tar.gz |
ccode: Rename CCodeFeatureTestMacro to CCodeDefine and generalize it
This now serves as base for CCodeMacroReplacement too.
Diffstat (limited to 'ccode')
-rw-r--r-- | ccode/Makefile.am | 2 | ||||
-rw-r--r-- | ccode/valaccodedefine.vala (renamed from ccode/valaccodefeaturetestmacro.vala) | 34 | ||||
-rw-r--r-- | ccode/valaccodefile.vala | 2 | ||||
-rw-r--r-- | 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 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); } } |