use defines for public constants
authorJuerg Billeter <j@bitron.ch>
Sat, 3 Nov 2007 22:42:43 +0000 (22:42 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sat, 3 Nov 2007 22:42:43 +0000 (22:42 +0000)
2007-11-03  Juerg Billeter  <j@bitron.ch>

* gobject/valaccodegenerator.vala, ccode/valaccodemacroreplacement.vala:
  use defines for public constants

svn path=/trunk/; revision=677

ChangeLog
ccode/valaccodemacroreplacement.vala
gobject/valaccodegenerator.vala

index 14508d4..439978e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2007-11-03  Jürg Billeter  <j@bitron.ch>
 
+       * gobject/valaccodegenerator.vala, ccode/valaccodemacroreplacement.vala:
+         use defines for public constants
+
+2007-11-03  Jürg Billeter  <j@bitron.ch>
+
        * gobject/valaccodegeneratorsourcefile.vala: avoid void pointer
          arithmetic in _vala_array_move
 
index 1d117b1..744f711 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodemacroreplacement.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -30,23 +30,33 @@ public class Vala.CCodeMacroReplacement : CCodeNode {
         * The name of this macro.
         */
        public string! name { get; set construct; }
-       
+
        /**
         * The replacement of this macro.
         */
-       public string! replacement { get; set construct; }
-       
-       public CCodeMacroReplacement (string! n, string! replace) {
-               name = n;
-               replacement = replace;
+       public string! replacement { get; set; }
+
+       /**
+        * The replacement expression of this macro.
+        */
+       public CCodeExpression replacement_expression { get; set; }
+
+       public CCodeMacroReplacement (construct string! name, construct string! replacement) {
+       }
+
+       public CCodeMacroReplacement.with_expression (construct string! name, construct CCodeExpression! replacement_expression) {
        }
-       
+
        public override void write (CCodeWriter! writer) {
                writer.write_indent ();
                writer.write_string ("#define ");
                writer.write_string (name);
                writer.write_string (" ");
-               writer.write_string (replacement);
+               if (replacement != null) {
+                       writer.write_string (replacement);
+               } else {
+                       replacement_expression.write (writer);
+               }
                writer.write_newline ();
        }
 }
index 147086b..d7074fe 100644 (file)
@@ -386,18 +386,24 @@ public class Vala.CCodeGenerator : CodeGenerator {
 
                if (c.parent_symbol is DataType) {
                        var t = (DataType) c.parent_symbol;
-                       var cdecl = new CCodeDeclaration (c.type_reference.get_const_cname ());
-                       var arr = "";
-                       if (c.type_reference.data_type is Array) {
-                               arr = "[]";
-                       }
-                       cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("%s%s".printf (c.get_cname (), arr), (CCodeExpression) c.initializer.ccodenode));
-                       cdecl.modifiers = CCodeModifiers.STATIC;
                        
-                       if (!c.is_internal_symbol ()) {
-                               header_type_member_declaration.append (cdecl);
+                       if (!c.is_internal_symbol () && !(c.type_reference.data_type is Array)) {
+                               var cdefine = new CCodeMacroReplacement.with_expression (c.get_cname (), (CCodeExpression) c.initializer.ccodenode);
+                               header_type_member_declaration.append (cdefine);
                        } else {
-                               source_type_member_declaration.append (cdecl);
+                               var cdecl = new CCodeDeclaration (c.type_reference.get_const_cname ());
+                               var arr = "";
+                               if (c.type_reference.data_type is Array) {
+                                       arr = "[]";
+                               }
+                               cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("%s%s".printf (c.get_cname (), arr), (CCodeExpression) c.initializer.ccodenode));
+                               cdecl.modifiers = CCodeModifiers.STATIC;
+                       
+                               if (!c.is_internal_symbol ()) {
+                                       header_type_member_declaration.append (cdecl);
+                               } else {
+                                       source_type_member_declaration.append (cdecl);
+                               }
                        }
                }
        }