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
/* 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
* 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 ();
}
}
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);
+ }
}
}
}