From 6430451a85c4a72695e33d9071ccfe09ffdcabd7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Thu, 10 Aug 2006 11:54:15 +0000 Subject: [PATCH] support constants in namespaces and constants without initializer depend MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2006-08-10 Jürg Billeter * vala/parser.y: support constants in namespaces and constants without initializer * vala/valasemanticanalyzer.vala: depend on implemented interfaces * vala/valacodegenerator.vala: always include glib-object.h for interfaces, append NULL to variable argument list calls * vala/valainterfacewriter.vala: support constants and ellipsis parameters * vala/valaconstant.vala: make initializer optional * vala/valainterface.vala: implement get_lower_case_cprefix () * vala/valanamespace.vala: support constants svn path=/trunk/; revision=95 --- vala/ChangeLog | 13 +++++++++++++ vala/vala/parser.y | 26 +++++++++++++------------- vala/vala/valacodegenerator.vala | 20 +++++++++++++++++++- vala/vala/valaconstant.vala | 10 ++++++---- vala/vala/valainterface.vala | 4 ++++ vala/vala/valainterfacewriter.vala | 17 +++++++++++++++++ vala/vala/valanamespace.vala | 14 ++++++++++++++ vala/vala/valasemanticanalyzer.vala | 4 ++++ 8 files changed, 90 insertions(+), 18 deletions(-) diff --git a/vala/ChangeLog b/vala/ChangeLog index aaae701..37a90e8 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,5 +1,18 @@ 2006-08-10 Jürg Billeter + * vala/parser.y: support constants in namespaces and constants without + initializer + * vala/valasemanticanalyzer.vala: depend on implemented interfaces + * vala/valacodegenerator.vala: always include glib-object.h for + interfaces, append NULL to variable argument list calls + * vala/valainterfacewriter.vala: support constants and ellipsis + parameters + * vala/valaconstant.vala: make initializer optional + * vala/valainterface.vala: implement get_lower_case_cprefix () + * vala/valanamespace.vala: support constants + +2006-08-10 Jürg Billeter + * vala/scanner.l: accept real literals with trailing dot * vala/valasymbolresolver.vala: ignore non-type symbols * vala/valacodegenerator.vala: support float and double properties, diff --git a/vala/vala/parser.y b/vala/vala/parser.y index 109e52a..591387b 100644 --- a/vala/vala/parser.y +++ b/vala/vala/parser.y @@ -296,7 +296,6 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); %type flags_declaration %type callback_declaration %type constant_declaration -%type constant_declarator %type field_declaration %type variable_declarators %type variable_declarator @@ -1735,6 +1734,14 @@ namespace_member_declaration current_namespace_implicit = FALSE; } } + | constant_declaration + { + /* skip declarations with errors */ + if ($1 != NULL) { + vala_namespace_add_constant (current_namespace, $1); + g_object_unref ($1); + } + } | field_declaration { /* skip declarations with errors */ @@ -1971,7 +1978,7 @@ class_member_declaration ; constant_declaration - : comment opt_attributes opt_access_modifier CONST type constant_declarator SEMICOLON + : comment opt_attributes opt_access_modifier CONST type variable_declarator SEMICOLON { ValaSourceReference *src = src_com(@5, $1); $$ = vala_constant_new (vala_variable_declarator_get_name ($6), $5, vala_variable_declarator_get_initializer ($6), src); @@ -1981,17 +1988,6 @@ constant_declaration } ; -constant_declarator - : IDENTIFIER ASSIGN initializer - { - ValaSourceReference *src = src(@1); - $$ = vala_variable_declarator_new ($1, $3, src); - g_object_unref (src); - g_free ($1); - g_object_unref ($3); - } - ; - field_declaration : comment opt_attributes opt_access_modifier opt_modifiers type variable_declarator SEMICOLON { @@ -2490,6 +2486,10 @@ interface_declaration g_free (name); g_object_unref (src); + VALA_CODE_NODE(current_interface)->attributes = $2; + if ($3 != 0) { + VALA_DATA_TYPE(current_interface)->access = $3; + } if ($7 != NULL) { GList *l; for (l = $7; l != NULL; l = l->next) { diff --git a/vala/vala/valacodegenerator.vala b/vala/vala/valacodegenerator.vala index fd25b18..c5f1df4 100644 --- a/vala/vala/valacodegenerator.vala +++ b/vala/vala/valacodegenerator.vala @@ -125,10 +125,12 @@ public class Vala.CodeGenerator : CodeVisitor { next_temp_var_id = 0; header_begin.append (new CCodeIncludeDirective ("glib.h")); + header_begin.append (new CCodeIncludeDirective ("glib-object.h")); source_include_directives.append (new CCodeIncludeDirective (source_file.get_cheader_filename (), true)); ref List used_includes = null; used_includes.append ("glib.h"); + used_includes.append ("glib-object.h"); used_includes.append (source_file.get_cheader_filename ()); foreach (string filename1 in source_file.get_header_external_includes ()) { @@ -1940,6 +1942,8 @@ public class Vala.CodeGenerator : CodeVisitor { } } + bool ellipsis = false; + var i = 1; foreach (Expression arg in expr.get_argument_list ()) { /* explicitly use strong reference as ccall gets @@ -1948,6 +1952,7 @@ public class Vala.CodeGenerator : CodeVisitor { ref CCodeExpression cexpr = (CCodeExpression) arg.ccodenode; if (params != null) { var param = (FormalParameter) params.data; + ellipsis = param.ellipsis; if (!param.ellipsis && param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () @@ -1970,6 +1975,7 @@ public class Vala.CodeGenerator : CodeVisitor { var param = (FormalParameter) params.data; if (param.ellipsis) { + ellipsis = true; break; } @@ -1991,6 +1997,9 @@ public class Vala.CodeGenerator : CodeVisitor { if (m != null && m.instance && m.instance_last) { ccall.add_argument (instance); + } else if (ellipsis) { + // ensure variable argument list ends with NULL + ccall.add_argument (new CCodeConstant ("NULL")); } if (m != null && m.instance && m.returns_modified_pointer) { @@ -2114,8 +2123,10 @@ public class Vala.CodeGenerator : CodeVisitor { var params = m.get_parameters (); var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_cname ())); + + bool ellipsis = false; - var i = 1; + int i = 1; foreach (Expression arg in expr.get_argument_list ()) { /* explicitly use strong reference as ccall gets * unrefed at end of inner block @@ -2123,6 +2134,7 @@ public class Vala.CodeGenerator : CodeVisitor { ref CCodeExpression cexpr = (CCodeExpression) arg.ccodenode; if (params != null) { var param = (FormalParameter) params.data; + ellipsis = param.ellipsis; if (!param.ellipsis && param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () @@ -2145,6 +2157,7 @@ public class Vala.CodeGenerator : CodeVisitor { var param = (FormalParameter) params.data; if (param.ellipsis) { + ellipsis = true; break; } @@ -2163,6 +2176,11 @@ public class Vala.CodeGenerator : CodeVisitor { params = params.next; } + + if (ellipsis) { + // ensure variable argument list ends with NULL + ccall.add_argument (new CCodeConstant ("NULL")); + } expr.ccodenode = ccall; } diff --git a/vala/vala/valaconstant.vala b/vala/vala/valaconstant.vala index a8a1767..be3a993 100644 --- a/vala/vala/valaconstant.vala +++ b/vala/vala/valaconstant.vala @@ -39,7 +39,7 @@ public class Vala.Constant : CodeNode { /** * The value of this constant. */ - public Expression! initializer { get; set construct; } + public Expression initializer { get; set; } private string cname; @@ -52,7 +52,7 @@ public class Vala.Constant : CodeNode { * @param source reference to source code * @return newly created constant */ - public construct (string! _name, TypeReference! type, Expression! init, SourceReference source) { + public construct (string! _name, TypeReference! type, Expression init, SourceReference source) { name = _name; type_reference = type; initializer = init; @@ -61,8 +61,10 @@ public class Vala.Constant : CodeNode { public override void accept (CodeVisitor! visitor) { type_reference.accept (visitor); - - initializer.accept (visitor); + + if (initializer != null) { + initializer.accept (visitor); + } visitor.visit_constant (this); } diff --git a/vala/vala/valainterface.vala b/vala/vala/valainterface.vala index d878f6d..f6d46d8 100644 --- a/vala/vala/valainterface.vala +++ b/vala/vala/valainterface.vala @@ -160,6 +160,10 @@ public class Vala.Interface : DataType { return "%s%s%s".printf (@namespace.get_lower_case_cprefix (), infix, get_lower_case_csuffix ()); } + public override ref string get_lower_case_cprefix () { + return "%s_".printf (get_lower_case_cname (null)); + } + public override ref string get_upper_case_cname (string infix) { return get_lower_case_cname (infix).up (); } diff --git a/vala/vala/valainterfacewriter.vala b/vala/vala/valainterfacewriter.vala index 843aeb0..5494cd2 100644 --- a/vala/vala/valainterfacewriter.vala +++ b/vala/vala/valainterfacewriter.vala @@ -215,6 +215,18 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_constant (Constant! c) { + if (internal_scope) { + return; + } + + write_indent (); + write_string ("public const "); + write_string (c.type_reference.data_type.symbol.get_full_name ()); + + write_string (" "); + write_identifier (c.name); + write_string (";"); + write_newline (); } public override void visit_field (Field! f) { @@ -262,6 +274,11 @@ public class Vala.InterfaceWriter : CodeVisitor { first = false; } + if (param.ellipsis) { + write_string ("..."); + continue; + } + if (param.type_reference.reference_to_value_type || param.type_reference.takes_ownership) { write_string ("ref "); diff --git a/vala/vala/valanamespace.vala b/vala/vala/valanamespace.vala index 63b3825..3de1073 100644 --- a/vala/vala/valanamespace.vala +++ b/vala/vala/valanamespace.vala @@ -37,6 +37,7 @@ public class Vala.Namespace : CodeNode { private List enums; private List flags_; private List callbacks; + private List constants; private List fields; private List methods; @@ -136,6 +137,15 @@ public class Vala.Namespace : CodeNode { } /** + * Adds the specified constant to this namespace. + * + * @param constant a constant + */ + public void add_constant (Constant! constant) { + constants.append (constant); + } + + /** * Adds the specified field to this namespace. * * @param f a field @@ -180,6 +190,10 @@ public class Vala.Namespace : CodeNode { cb.accept (visitor); } + foreach (Constant c in constants) { + c.accept (visitor); + } + foreach (Field f in fields) { f.accept (visitor); } diff --git a/vala/vala/valasemanticanalyzer.vala b/vala/vala/valasemanticanalyzer.vala index 4b556c9..b28ac74 100644 --- a/vala/vala/valasemanticanalyzer.vala +++ b/vala/vala/valasemanticanalyzer.vala @@ -103,6 +103,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor { if (cl.base_class != null) { current_source_file.add_symbol_dependency (cl.base_class.symbol, SourceFileDependencyType.HEADER_FULL); } + + foreach (TypeReference base_type_reference in cl.get_base_types ()) { + current_source_file.add_symbol_dependency (base_type_reference.data_type.symbol, SourceFileDependencyType.HEADER_FULL); + } } public override void visit_end_class (Class! cl) { -- 2.7.4