Commit 8b48ec9a authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

use defines for public constants

2007-11-03  Juerg Billeter  <j@bitron.ch>

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

svn path=/trunk/; revision=677
parent 8fd6b40c
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
......
/* 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 ();
}
}
......@@ -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);
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment