Line data Source code
1 : /* valaccodedefine.vala
2 : *
3 : * Copyright (C) 2018 Dr. Michael 'Mickey' Lauer
4 : *
5 : * This library is free software; you can redistribute it and/or
6 : * modify it under the terms of the GNU Lesser General Public
7 : * License as published by the Free Software Foundation; either
8 : * version 2.1 of the License, or (at your option) any later version.
9 :
10 : * This library is distributed in the hope that it will be useful,
11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : * Lesser General Public License for more details.
14 :
15 : * You should have received a copy of the GNU Lesser General Public
16 : * License along with this library; if not, write to the Free Software
17 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 : *
19 : * Author:
20 : * Dr. Michael 'Mickey' Lauer <mickey@vanille-media.de>
21 : * Rico Tzschichholz <ricotz@ubuntu.com>
22 : */
23 :
24 : using GLib;
25 :
26 : /**
27 : * Represents a definition in the C code.
28 : */
29 19577 : public class Vala.CCodeDefine : CCodeNode {
30 : /**
31 : * The name of this definition.
32 : */
33 56205 : public string name { get; set; }
34 :
35 : /**
36 : * The value of this definition.
37 : */
38 48485 : public string? value { get; set; }
39 :
40 : /**
41 : * The value expression of this definition.
42 : */
43 22595 : public CCodeExpression? value_expression { get; set; }
44 :
45 33837 : public CCodeDefine (string name, string? value = null) {
46 14875 : this.name = name;
47 14875 : this.value = value;
48 : }
49 :
50 7883 : public CCodeDefine.with_expression (string name, CCodeExpression expression) {
51 3860 : this.name = name;
52 3860 : this.value_expression = expression;
53 : }
54 :
55 11035 : public override void write (CCodeWriter writer) {
56 11035 : writer.write_indent ();
57 11035 : writer.write_string ("#define ");
58 11035 : writer.write_string (name);
59 11035 : if (value != null) {
60 7240 : writer.write_string (" ");
61 7240 : writer.write_string (@value);
62 3795 : } else if (value_expression != null) {
63 3794 : writer.write_string (" ");
64 3794 : value_expression.write_inner (writer);
65 : }
66 11035 : writer.write_newline ();
67 : }
68 : }
|