]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
support constants in namespaces and constants without initializer depend
authorJürg Billeter <j@bitron.ch>
Thu, 10 Aug 2006 11:54:15 +0000 (11:54 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 10 Aug 2006 11:54:15 +0000 (11:54 +0000)
2006-08-10  Jürg Billeter  <j@bitron.ch>

* 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
vala/vala/parser.y
vala/vala/valacodegenerator.vala
vala/vala/valaconstant.vala
vala/vala/valainterface.vala
vala/vala/valainterfacewriter.vala
vala/vala/valanamespace.vala
vala/vala/valasemanticanalyzer.vala

index aaae701494133bf12bd08c975c9dd199349925d8..37a90e84638fc1bc519f83e7c89d8d6f1636c8b2 100644 (file)
@@ -1,3 +1,16 @@
+2006-08-10  Jürg Billeter  <j@bitron.ch>
+
+       * 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  <j@bitron.ch>
 
        * vala/scanner.l: accept real literals with trailing dot
index 109e52a87fd9329df96c6ee3bca66c99baa5dd9c..591387b3c937dcbc3fa14f3e41732d67cd24f8b2 100644 (file)
@@ -296,7 +296,6 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 %type <flags> flags_declaration
 %type <callback> callback_declaration
 %type <constant> constant_declaration
-%type <variable_declarator> constant_declarator
 %type <field> field_declaration
 %type <list> variable_declarators
 %type <variable_declarator> 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) {
index fd25b1879daa60d0c3552e43acab77b6a3ea25a3..c5f1df4d45e856c103b817fba31c7abaaa958b49 100644 (file)
@@ -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<string> 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;
                }
index a8a17670f9449bd522bf6405c1acc2db3dee13db..be3a9936b6d29365336241746e8587e06ef2d731 100644 (file)
@@ -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);
        }
index d878f6d089e171d47ff3dcebb19d8ae4e3be3cf5..f6d46d857724e943c78307def67ae5eeabbded4c 100644 (file)
@@ -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 ();
        }
index 843aeb0a7b94d037d71820716152fd5231c5bcc0..5494cd2ab8d82123eadc5fc9fe48c2a425b092b1 100644 (file)
@@ -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 ");
index 63b3825df1ee92058f18c031f64d52ce3891fdc5..3de10731939ba7b97d8da2dd49c916072919c4cf 100644 (file)
@@ -37,6 +37,7 @@ public class Vala.Namespace : CodeNode {
        private List<Enum> enums;
        private List<Flags> flags_;
        private List<Callback> callbacks;
+       private List<Constant> constants;
        private List<Field> fields;
        private List<Method> methods;
        
@@ -135,6 +136,15 @@ public class Vala.Namespace : CodeNode {
                return classes.copy ();
        }
        
+       /**
+        * 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.
         *
@@ -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);
                }
index 4b556c93a4b29263ca943c9337bec258589c5486..b28ac7468757ab250534526367e7084277953760 100644 (file)
@@ -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) {