From: Juerg Billeter Date: Sat, 22 Mar 2008 22:03:19 +0000 (+0000) Subject: use extern appropriately for static fields, based on patch by Daniel X-Git-Tag: VALA_0_2_0~36 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dd5ab7ea0e3cb6a726af787ad6b91b9e5727742b;p=platform%2Fupstream%2Fvala.git use extern appropriately for static fields, based on patch by Daniel 2008-03-22 Juerg Billeter * ccode/valaccodedeclaration.vala, gobject/valaccodegenerator.vala: use extern appropriately for static fields, based on patch by Daniel Silverstone, fixes bug 523768 svn path=/trunk/; revision=1150 --- diff --git a/ChangeLog b/ChangeLog index cda8b31..e7ae469 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-03-22 Jürg Billeter + * ccode/valaccodedeclaration.vala, gobject/valaccodegenerator.vala: + use extern appropriately for static fields, + based on patch by Daniel Silverstone, fixes bug 523768 + +2008-03-22 Jürg Billeter + * vala/parser.y: fix source reference of fields, patch by Daniel Silverstone, fixes bug 523761 diff --git a/ccode/valaccodedeclaration.vala b/ccode/valaccodedeclaration.vala index b2ebc79..21c87d3 100644 --- a/ccode/valaccodedeclaration.vala +++ b/ccode/valaccodedeclaration.vala @@ -1,6 +1,6 @@ /* valaccodedeclaration.vala * - * Copyright (C) 2006-2007 Jürg Billeter + * Copyright (C) 2006-2008 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 @@ -58,6 +58,9 @@ public class Vala.CCodeDeclaration : CCodeStatement { if ((modifiers & CCodeModifiers.STATIC) != 0) { writer.write_string ("static "); } + if ((modifiers & CCodeModifiers.EXTERN) != 0 && !has_initializer ()) { + writer.write_string ("extern "); + } writer.write_string (type_name); writer.write_string (" "); @@ -80,6 +83,16 @@ public class Vala.CCodeDeclaration : CCodeStatement { } } + private bool has_initializer () { + foreach (CCodeDeclarator decl in declarators) { + var var_decl = decl as CCodeVariableDeclarator; + if (var_decl != null && var_decl.initializer == null) { + return false; + } + } + return true; + } + public override void write_declaration (CCodeWriter! writer) { if ((modifiers & (CCodeModifiers.STATIC | CCodeModifiers.EXTERN)) != 0) { // no separate declaration for static variables diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala index ce81bbb..f9f33e4 100644 --- a/gobject/valaccodegenerator.vala +++ b/gobject/valaccodegenerator.vala @@ -517,18 +517,21 @@ public class Vala.CCodeGenerator : CodeGenerator { cdecl.modifiers = CCodeModifiers.EXTERN; header_type_member_declaration.append (cdecl); + var var_decl = new CCodeVariableDeclarator (f.get_cname ()); + var_decl.initializer = default_value_for_type (f.type_reference); + if (f.initializer != null) { var init = (CCodeExpression) f.initializer.ccodenode; if (is_constant_ccode_expression (init)) { - var cinit_decl = new CCodeDeclaration (field_ctype); - var var_decl = new CCodeVariableDeclarator (f.get_cname ()); var_decl.initializer = init; - cinit_decl.add_declarator (var_decl); - cinit_decl.modifiers = CCodeModifiers.EXTERN; - source_type_member_declaration.append (cinit_decl); } } + var var_def = new CCodeDeclaration (field_ctype); + var_def.add_declarator (var_decl); + var_def.modifiers = CCodeModifiers.EXTERN; + source_type_member_declaration.append (var_def); + lhs = new CCodeIdentifier (f.get_cname ()); } } else if (f.access == SymbolAccessibility.PRIVATE) {