support REAL_LITERAL, TILDE, SIGNAL support flags, signals, constructors,
authorJürg Billeter <j@bitron.ch>
Wed, 7 Jun 2006 08:31:14 +0000 (08:31 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Wed, 7 Jun 2006 08:31:14 +0000 (08:31 +0000)
2006-06-07  Jürg Billeter  <j@bitron.ch>

* vala/scanner.l: support REAL_LITERAL, TILDE, SIGNAL
* vala/parser.y: support flags, signals, constructors, destructors, real
  literals, assignment operators, and non-null types
* vala/valacodevisitor.vala: add visit methods for signals,
  constructors, destructors, and real literals
* vala/valasymbolbuilder.vala: support signals, constructors,
  destructors
* vala/valasemanticanalyzer.vala: support constructors, real literals,
  and default arguments, fix lookup in namespaces of using directives
* vala/valacodegenerator.vala: use default arguments and type register
  function classes, support constructors, interfaces, real literals,
  default arguments, casts, and signals, cast method arguments if
  necessary
* vala/valasourcefile.vala: use default arguments
* vala/valaassignment.vala: add operator
* vala/valacallback.vala: skeleton for callbacks
* vala/valaclass.vala: add signals, constructor, and destructor
* vala/valaclassregisterfunction.vala: get_type function for classes
* vala/valaconstant.vala: use default arguments
* vala/valaconstructor.vala
* vala/valadestructor.vala
* vala/valaenum.vala: use default arguments
* vala/valaflags.vala
* vala/valaflagsvalue.vala:
* vala/valaformalparameter.vala: add default_expression
* vala/valainstancecast.vala: dynamic instance cast
* vala/valainterface.vala: add signals
* vala/valainterfaceregisterfunction.vala: get_type function for
  interfaces
* vala/valanamespace.vala: add flags, use default arguments
* vala/valaproperty.vala: use default arguments
* vala/valarealliteral.vala:
* vala/valasignal.vala
* vala/valastruct.vala: use default arguments
* vala/valastringliteral.vala: use default arguments
* vala/valatypereference.vala: add is_weak property
* vala/valatyperegisterfunction.vala
* vala/vala.h: update
* vala/Makefile.am: update
* ccode/valaccodeblock.vala: add prepend_statement method
* ccode/valaccodewriter.vala: correctly indent multi-line comments
* vapi/glib-2.0.vala: add float and double, use default arguments,
  temporarily remove astring

svn path=/trunk/; revision=39

35 files changed:
vala/ChangeLog
vala/ccode/valaccodeblock.vala
vala/ccode/valaccodewriter.vala
vala/vala/Makefile.am
vala/vala/parser.y
vala/vala/scanner.l
vala/vala/vala.h
vala/vala/valaassignment.vala
vala/vala/valacallback.vala [new file with mode: 0644]
vala/vala/valaclass.vala
vala/vala/valaclassregisterfunction.vala [new file with mode: 0644]
vala/vala/valacodegenerator.vala
vala/vala/valacodevisitor.vala
vala/vala/valaconstant.vala
vala/vala/valaconstructor.vala [new file with mode: 0644]
vala/vala/valadestructor.vala [new file with mode: 0644]
vala/vala/valaenum.vala
vala/vala/valaflags.vala [new file with mode: 0644]
vala/vala/valaflagsvalue.vala [new file with mode: 0644]
vala/vala/valaformalparameter.vala
vala/vala/valainstancecast.vala [new file with mode: 0644]
vala/vala/valainterface.vala
vala/vala/valainterfaceregisterfunction.vala [new file with mode: 0644]
vala/vala/valanamespace.vala
vala/vala/valaproperty.vala
vala/vala/valarealliteral.vala [new file with mode: 0644]
vala/vala/valasemanticanalyzer.vala
vala/vala/valasignal.vala [new file with mode: 0644]
vala/vala/valasourcefile.vala
vala/vala/valastringliteral.vala
vala/vala/valastruct.vala
vala/vala/valasymbolbuilder.vala
vala/vala/valatypereference.vala
vala/vala/valatyperegisterfunction.vala [new file with mode: 0644]
vala/vapi/glib-2.0.vala

index fd504e5..8eabc98 100644 (file)
@@ -1,3 +1,49 @@
+2006-06-07  Jürg Billeter  <j@bitron.ch>
+
+       * vala/scanner.l: support REAL_LITERAL, TILDE, SIGNAL
+       * vala/parser.y: support flags, signals, constructors, destructors, real
+         literals, assignment operators, and non-null types
+       * vala/valacodevisitor.vala: add visit methods for signals,
+         constructors, destructors, and real literals
+       * vala/valasymbolbuilder.vala: support signals, constructors,
+         destructors
+       * vala/valasemanticanalyzer.vala: support constructors, real literals,
+         and default arguments, fix lookup in namespaces of using directives
+       * vala/valacodegenerator.vala: use default arguments and type register
+         function classes, support constructors, interfaces, real literals,
+         default arguments, casts, and signals, cast method arguments if
+         necessary
+       * vala/valasourcefile.vala: use default arguments
+       * vala/valaassignment.vala: add operator
+       * vala/valacallback.vala: skeleton for callbacks
+       * vala/valaclass.vala: add signals, constructor, and destructor
+       * vala/valaclassregisterfunction.vala: get_type function for classes
+       * vala/valaconstant.vala: use default arguments
+       * vala/valaconstructor.vala
+       * vala/valadestructor.vala
+       * vala/valaenum.vala: use default arguments
+       * vala/valaflags.vala
+       * vala/valaflagsvalue.vala: 
+       * vala/valaformalparameter.vala: add default_expression
+       * vala/valainstancecast.vala: dynamic instance cast
+       * vala/valainterface.vala: add signals
+       * vala/valainterfaceregisterfunction.vala: get_type function for
+         interfaces
+       * vala/valanamespace.vala: add flags, use default arguments
+       * vala/valaproperty.vala: use default arguments
+       * vala/valarealliteral.vala: 
+       * vala/valasignal.vala
+       * vala/valastruct.vala: use default arguments
+       * vala/valastringliteral.vala: use default arguments
+       * vala/valatypereference.vala: add is_weak property
+       * vala/valatyperegisterfunction.vala
+       * vala/vala.h: update
+       * vala/Makefile.am: update
+       * ccode/valaccodeblock.vala: add prepend_statement method
+       * ccode/valaccodewriter.vala: correctly indent multi-line comments
+       * vapi/glib-2.0.vala: add float and double, use default arguments,
+         temporarily remove astring
+
 2006-05-31  Jürg Billeter  <j@bitron.ch>
 
        * vala/parser.y: support interfaces, adapt to Class/Struct/Type changes,
index 4b853d9..a310ca9 100644 (file)
@@ -27,6 +27,10 @@ namespace Vala {
                List<CCodeNode> statements;
                public bool suppress_newline;
                
+               public void prepend_statement (CCodeNode statement) {
+                       statements.prepend (statement);
+               }
+               
                public void add_statement (CCodeNode statement) {
                        /* allow generic nodes to include comments */
                        statements.append (statement);
index 9722167..80bbb3b 100644 (file)
@@ -117,7 +117,17 @@ namespace Vala {
                
                public void write_comment (string text) {
                        write_indent ();
-                       stream.printf ("/*%s*/", text);
+                       stream.printf ("/*");
+                       bool first = true;
+                       foreach (string line in text.split ("\n")) {
+                               if (!first) {
+                                       write_indent ();
+                               } else {
+                                       first = false;
+                               }
+                               stream.printf ("%s", line);
+                       }
+                       stream.printf ("*/");
                        write_newline ();
                }
        }
index 26b833b..41f2be5 100644 (file)
@@ -38,6 +38,9 @@ libvala_la_SOURCES = \
        valabreakstatement.c \
        valabreakstatement.h \
        valabreakstatement.vala \
+       valacallback.c \
+       valacallback.h \
+       valacallback.vala \
        valacastexpression.c \
        valacastexpression.h \
        valacastexpression.vala \
@@ -47,6 +50,9 @@ libvala_la_SOURCES = \
        valaclass.c \
        valaclass.h \
        valaclass.vala \
+       valaclassregisterfunction.c \
+       valaclassregisterfunction.h \
+       valaclassregisterfunction.vala \
        valacodecontext.c \
        valacodecontext.h \
        valacodecontext.vala \
@@ -65,12 +71,18 @@ libvala_la_SOURCES = \
        valaconstant.c \
        valaconstant.h \
        valaconstant.vala \
+       valaconstructor.c \
+       valaconstructor.h \
+       valaconstructor.vala \
        valacontinuestatement.c \
        valacontinuestatement.h \
        valacontinuestatement.vala \
        valadeclarationstatement.c \
        valadeclarationstatement.h \
        valadeclarationstatement.vala \
+       valadestructor.c \
+       valadestructor.h \
+       valadestructor.vala \
        valaemptystatement.c \
        valaemptystatement.h \
        valaemptystatement.vala \
@@ -89,6 +101,12 @@ libvala_la_SOURCES = \
        valafield.c \
        valafield.h \
        valafield.vala \
+       valaflags.c \
+       valaflags.h \
+       valaflags.vala \
+       valaflagsvalue.c \
+       valaflagsvalue.h \
+       valaflagsvalue.vala \
        valaforeachstatement.c \
        valaforeachstatement.h \
        valaforeachstatement.vala \
@@ -104,12 +122,18 @@ libvala_la_SOURCES = \
        valainitializerlist.c \
        valainitializerlist.h \
        valainitializerlist.vala \
+       valainstancecast.c \
+       valainstancecast.h \
+       valainstancecast.vala \
        valaintegerliteral.c \
        valaintegerliteral.h \
        valaintegerliteral.vala \
        valainterface.c \
        valainterface.h \
        valainterface.vala \
+       valainterfaceregisterfunction.c \
+       valainterfaceregisterfunction.h \
+       valainterfaceregisterfunction.vala \
        valainterfacewriter.c \
        valainterfacewriter.h \
        valainterfacewriter.vala \
@@ -164,6 +188,9 @@ libvala_la_SOURCES = \
        valaproperty.c \
        valaproperty.h \
        valaproperty.vala \
+       valarealliteral.c \
+       valarealliteral.h \
+       valarealliteral.vala \
        valareport.c \
        valareport.h \
        valareport.vala \
@@ -173,6 +200,9 @@ libvala_la_SOURCES = \
        valasemanticanalyzer.c \
        valasemanticanalyzer.h \
        valasemanticanalyzer.vala \
+       valasignal.c \
+       valasignal.h \
+       valasignal.vala \
        valasimplename.c \
        valasimplename.h \
        valasimplename.vala \
@@ -215,6 +245,9 @@ libvala_la_SOURCES = \
        valatypereference.c \
        valatypereference.h \
        valatypereference.vala \
+       valatyperegisterfunction.c \
+       valatyperegisterfunction.h \
+       valatyperegisterfunction.vala \
        valaunaryexpression.c \
        valaunaryexpression.h \
        valaunaryexpression.vala \
index 50ea90b..890d417 100644 (file)
@@ -76,12 +76,17 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
        ValaInterface *interface;
        ValaEnum *enum_;
        ValaEnumValue *enum_value;
+       ValaFlags *flags;
+       ValaFlagsValue *flags_value;
        ValaConstant *constant;
        ValaField *field;
        ValaMethod *method;
        ValaFormalParameter *formal_parameter;
        ValaProperty *property;
        ValaPropertyAccessor *property_accessor;
+       ValaSignal *signal;
+       ValaConstructor *constructor;
+       ValaDestructor *destructor;
        ValaLocalVariableDeclaration *local_variable_declaration;
        ValaVariableDeclarator *variable_declarator;
        ValaTypeParameter *type_parameter;
@@ -132,6 +137,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 %token BITWISE_AND "&"
 %token OP_OR "||"
 %token OP_AND "&&"
+%token TILDE "~"
 
 %token ASSIGN "="
 %token PLUS "+"
@@ -166,6 +172,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 %token PRIVATE "private"
 %token REF "ref"
 %token SET "set"
+%token SIGNAL "signal"
 %token STATIC "static"
 %token STRUCT "struct"
 %token RETURN "return"
@@ -178,6 +185,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 
 %token <str> IDENTIFIER "identifier"
 %token <str> INTEGER_LITERAL "integer"
+%token <str> REAL_LITERAL "real"
 %token <str> CHARACTER_LITERAL "character"
 %token <str> STRING_LITERAL "string"
 
@@ -186,7 +194,6 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 %type <literal> boolean_literal
 %type <type_reference> type_name
 %type <type_reference> type
-%type <num> opt_ref
 %type <list> opt_argument_list
 %type <list> argument_list
 %type <expression> argument
@@ -213,6 +220,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 %type <expression> conditional_or_expression
 %type <expression> conditional_expression
 %type <expression> assignment
+%type <num> assignment_operator
 %type <expression> opt_expression
 %type <expression> expression
 %type <statement> statement
@@ -224,6 +232,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 %type <statement> declaration_statement
 %type <local_variable_declaration> local_variable_declaration
 %type <type_reference> local_variable_type
+%type <num> opt_op_neg
 %type <statement> expression_statement
 %type <expression> statement_expression
 %type <statement> selection_statement
@@ -257,6 +266,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 %type <interface> interface_declaration
 %type <method> interface_method_declaration
 %type <property> interface_property_declaration
+%type <signal> interface_signal_declaration
 %type <property_accessor> interface_get_accessor_declaration
 %type <property_accessor> opt_interface_set_accessor_declaration
 %type <property_accessor> interface_set_accessor_declaration
@@ -265,6 +275,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 %type <list> opt_enum_member_declarations
 %type <list> enum_member_declarations
 %type <enum_value> enum_member_declaration
+%type <flags> flags_declaration
 %type <constant> constant_declaration
 %type <variable_declarator> constant_declarator
 %type <field> field_declaration
@@ -279,6 +290,9 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 %type <list> formal_parameter_list
 %type <list> fixed_parameters
 %type <formal_parameter> fixed_parameter
+%type <signal> signal_declaration
+%type <constructor> constructor_declaration
+%type <destructor> destructor_declaration
 %type <list> opt_attributes
 %type <list> attributes
 %type <list> attribute_sections
@@ -316,6 +330,10 @@ literal
          {
                $$ = VALA_LITERAL (vala_integer_literal_new ($1, src(@1)));
          }
+       | REAL_LITERAL
+         {
+               $$ = VALA_LITERAL (vala_real_literal_new ($1, src(@1)));
+         }
        | CHARACTER_LITERAL
          {
                $$ = VALA_LITERAL (vala_character_literal_new ($1, src(@1)));
@@ -365,29 +383,41 @@ type_name
        ;
 
 type
-       : type_name
+       : type_name opt_op_neg
          {
                $$ = $1;
+               if ($2) {
+                       vala_type_reference_set_non_null ($$, TRUE);
+               }
          }
-       | type array_qualifier
+       | REF type_name opt_op_neg
          {
-               $$ = $1;
-               vala_type_reference_set_array ($$, TRUE);
+               $$ = $2;
+               vala_type_reference_set_is_ref ($$, TRUE);
+               if ($3) {
+                       vala_type_reference_set_non_null ($$, TRUE);
+               }
          }
-       ;
-
-opt_ref
-       : /* empty */
+       | WEAK type_name opt_op_neg
          {
-               $$ = 0;
+               $$ = $2;
+               vala_type_reference_set_is_weak ($$, TRUE);
+               if ($3) {
+                       vala_type_reference_set_non_null ($$, TRUE);
+               }
          }
-       | REF
+       | OUT type_name opt_op_neg
          {
-               $$ = 1;
+               $$ = $2;
+               vala_type_reference_set_is_out ($$, TRUE);
+               if ($3) {
+                       vala_type_reference_set_non_null ($$, TRUE);
+               }
          }
-       | WEAK
+       | type array_qualifier
          {
-               $$ = 2;
+               $$ = $1;
+               vala_type_reference_set_array ($$, TRUE);
          }
        ;
 
@@ -650,22 +680,55 @@ conditional_expression
 assignment
        : unary_expression assignment_operator expression
          {
-               $$ = VALA_EXPRESSION (vala_assignment_new ($1, $3, src (@2)));
+               $$ = VALA_EXPRESSION (vala_assignment_new ($1, $2, $3, src (@2)));
          }
        ;
 
 assignment_operator
        : ASSIGN
+         {
+               $$ = VALA_ASSIGNMENT_OPERATOR_SIMPLE;
+         }
        | ASSIGN_BITWISE_OR
+         {
+               $$ = VALA_ASSIGNMENT_OPERATOR_BITWISE_OR;
+         }
        | ASSIGN_BITWISE_AND
+         {
+               $$ = VALA_ASSIGNMENT_OPERATOR_BITWISE_AND;
+         }
        | ASSIGN_BITWISE_XOR
+         {
+               $$ = VALA_ASSIGNMENT_OPERATOR_BITWISE_XOR;
+         }
        | ASSIGN_ADD
+         {
+               $$ = VALA_ASSIGNMENT_OPERATOR_ADD;
+         }
        | ASSIGN_SUB
+         {
+               $$ = VALA_ASSIGNMENT_OPERATOR_SUB;
+         }
        | ASSIGN_MUL
+         {
+               $$ = VALA_ASSIGNMENT_OPERATOR_MUL;
+         }
        | ASSIGN_DIV
+         {
+               $$ = VALA_ASSIGNMENT_OPERATOR_DIV;
+         }
        | ASSIGN_PERCENT
+         {
+               $$ = VALA_ASSIGNMENT_OPERATOR_PERCENT;
+         }
        | ASSIGN_SHIFT_LEFT
+         {
+               $$ = VALA_ASSIGNMENT_OPERATOR_SHIFT_LEFT;
+         }
        | ASSIGN_SHIFT_RIGHT
+         {
+               $$ = VALA_ASSIGNMENT_OPERATOR_SHIFT_RIGHT;
+         }
        ;
 
 opt_expression
@@ -757,13 +820,20 @@ local_variable_declaration
 
 /* don't use type to prevent reduce/reduce conflict */
 local_variable_type
-       : primary_expression
+       : primary_expression opt_op_neg
          {
                $$ = vala_type_reference_new_from_expression ($1, src(@1));
+               if ($2) {
+                       vala_type_reference_set_non_null ($$, TRUE);
+               }
          }
-       | REF primary_expression
+       | REF primary_expression opt_op_neg
          {
                $$ = vala_type_reference_new_from_expression ($2, src(@2));
+               vala_type_reference_set_is_ref ($$, TRUE);
+               if ($2) {
+                       vala_type_reference_set_non_null ($$, TRUE);
+               }
          }
        | local_variable_type array_qualifier
          {
@@ -772,6 +842,17 @@ local_variable_type
          }
        ;
 
+opt_op_neg
+       : /* empty */
+         {
+               $$ = FALSE;
+         }
+       | OP_NEG
+         {
+               $$ = TRUE;
+         }
+       ;
+
 expression_statement
        : comment statement_expression SEMICOLON
          {
@@ -792,13 +873,13 @@ selection_statement
        ;
 
 if_statement
-       : IF OPEN_PARENS expression CLOSE_PARENS embedded_statement
+       : comment IF OPEN_PARENS expression CLOSE_PARENS embedded_statement
          {
-               $$ = VALA_STATEMENT (vala_if_statement_new ($3, $5, NULL, src(@3)));
+               $$ = VALA_STATEMENT (vala_if_statement_new ($4, $6, NULL, src_com(@4, $1)));
          }
-       | IF OPEN_PARENS expression CLOSE_PARENS embedded_statement ELSE embedded_statement
+       | comment IF OPEN_PARENS expression CLOSE_PARENS embedded_statement ELSE embedded_statement
          {
-               $$ = VALA_STATEMENT (vala_if_statement_new ($3, $5, $7, src(@3)));
+               $$ = VALA_STATEMENT (vala_if_statement_new ($4, $6, $8, src_com(@4, $1)));
          }
        ;
 
@@ -969,6 +1050,12 @@ namespace_member_declaration
                }
          }
        | flags_declaration
+         {
+               /* skip declarations with errors */
+               if ($1 != NULL) {
+                       vala_namespace_add_flags (current_namespace, $1);
+               }
+         }
        | field_declaration
          {
                /* skip declarations with errors */
@@ -1134,6 +1221,27 @@ class_member_declaration
                        vala_class_add_property (current_class, $1);
                }
          }
+       | signal_declaration
+         {
+               /* skip declarations with errors */
+               if ($1 != NULL) {
+                       vala_class_add_signal (current_class, $1);
+               }
+         }
+       | constructor_declaration
+         {
+               /* skip declarations with errors */
+               if ($1 != NULL) {
+                       vala_class_set_constructor (current_class, $1);
+               }
+         }
+       | destructor_declaration
+         {
+               /* skip declarations with errors */
+               if ($1 != NULL) {
+                       vala_class_set_destructor (current_class, $1);
+               }
+         }
        ;
 
 constant_declaration
@@ -1151,9 +1259,9 @@ constant_declarator
        ;
 
 field_declaration
-       : comment opt_attributes opt_access_modifier opt_modifiers opt_ref type variable_declarator SEMICOLON
+       : comment opt_attributes opt_access_modifier opt_modifiers type variable_declarator SEMICOLON
          {
-               $$ = vala_field_new (vala_variable_declarator_get_name ($7), $6, vala_variable_declarator_get_initializer ($7), src_com (@6, $1));
+               $$ = vala_field_new (vala_variable_declarator_get_name ($6), $5, vala_variable_declarator_get_initializer ($6), src_com (@5, $1));
                if ($3 != 0) {
                        $$->access = $3;
                }
@@ -1225,11 +1333,11 @@ method_declaration
        ;
 
 method_header
-       : comment opt_attributes opt_access_modifier opt_modifiers opt_ref type identifier_or_new OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+       : comment opt_attributes opt_access_modifier opt_modifiers type identifier_or_new OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          {
                GList *l;
                
-               $$ = vala_method_new ($7, $6, src_com (@7, $1));
+               $$ = vala_method_new ($6, $5, src_com (@6, $1));
                if ($3 != 0) {
                        $$->access = $3;
                }
@@ -1247,7 +1355,7 @@ method_header
                }
                VALA_CODE_NODE($$)->attributes = $2;
                
-               for (l = $9; l != NULL; l = l->next) {
+               for (l = $8; l != NULL; l = l->next) {
                        vala_method_add_parameter ($$, l->data);
                }       
          }
@@ -1293,30 +1401,25 @@ fixed_parameters
        ;
 
 fixed_parameter
-       : opt_attributes opt_parameter_modifier type IDENTIFIER
+       : opt_attributes type IDENTIFIER
          {
-               $$ = vala_formal_parameter_new ($4, $3, src (@3));
+               $$ = vala_formal_parameter_new ($3, $2, src (@2));
+         }
+       | opt_attributes type IDENTIFIER ASSIGN expression
+         {
+               $$ = vala_formal_parameter_new ($3, $2, src (@2));
+               vala_formal_parameter_set_default_expression ($$, $5);
          }
-       ;
-
-opt_parameter_modifier
-       : /* empty */
-       | parameter_modifier
-       ;
-
-parameter_modifier
-       : REF
-       | OUT
        ;
 
 property_declaration
-       : comment opt_attributes opt_access_modifier opt_modifiers opt_ref type IDENTIFIER OPEN_BRACE get_accessor_declaration opt_set_accessor_declaration CLOSE_BRACE
+       : comment opt_attributes opt_access_modifier opt_modifiers type IDENTIFIER OPEN_BRACE get_accessor_declaration opt_set_accessor_declaration CLOSE_BRACE
          {
-               $$ = vala_property_new ($7, $6, $9, $10, src_com (@6, $1));
+               $$ = vala_property_new ($6, $5, $8, $9, src_com (@5, $1));
          }
-       | comment opt_attributes opt_access_modifier opt_modifiers opt_ref type IDENTIFIER OPEN_BRACE set_accessor_declaration CLOSE_BRACE
+       | comment opt_attributes opt_access_modifier opt_modifiers type IDENTIFIER OPEN_BRACE set_accessor_declaration CLOSE_BRACE
          {
-               $$ = vala_property_new ($7, $6, NULL, $9, src_com (@6, $1));
+               $$ = vala_property_new ($6, $5, NULL, $8, src_com (@5, $1));
          }
        ;
 
@@ -1350,6 +1453,39 @@ set_accessor_declaration
          }
        ;
 
+signal_declaration
+       : comment opt_attributes opt_access_modifier SIGNAL type identifier_or_new OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON
+         {
+               GList *l;
+               
+               $$ = vala_signal_new ($6, $5, src_com (@6, $1));
+               if ($3 != 0) {
+                       $$->access = $3;
+               }
+               VALA_CODE_NODE($$)->attributes = $2;
+               
+               for (l = $8; l != NULL; l = l->next) {
+                       vala_signal_add_parameter ($$, l->data);
+               }       
+         }
+       ;
+
+constructor_declaration
+       : comment opt_attributes opt_access_modifier opt_modifiers IDENTIFIER OPEN_PARENS CLOSE_PARENS block
+         {
+               $$ = vala_constructor_new (src_com (@5, $1));
+               vala_constructor_set_body ($$, $8);
+         }
+       ;
+
+destructor_declaration
+       : comment opt_attributes opt_access_modifier opt_modifiers TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
+         {
+               $$ = vala_destructor_new (src_com (@6, $1));
+               vala_destructor_set_body ($$, $9);
+         }
+       ;
+
 struct_declaration
        : struct_header
          {
@@ -1448,32 +1584,39 @@ interface_member_declaration
                        vala_interface_add_property (current_interface, $1);
                }
          }
+       | interface_signal_declaration
+         {
+               /* skip declarations with errors */
+               if ($1 != NULL) {
+                       vala_interface_add_signal (current_interface, $1);
+               }
+         }
        ;
 
 interface_method_declaration
-       : comment opt_attributes opt_ref type identifier_or_new OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON
+       : comment opt_attributes type identifier_or_new OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON
          {
                GList *l;
                
-               $$ = vala_method_new ($5, $4, src_com (@5, $1));
+               $$ = vala_method_new ($4, $3, src_com (@4, $1));
                $$->access = VALA_MEMBER_ACCESSIBILITY_PUBLIC;
                $$->is_abstract = TRUE;
                VALA_CODE_NODE($$)->attributes = $2;
                
-               for (l = $7; l != NULL; l = l->next) {
+               for (l = $6; l != NULL; l = l->next) {
                        vala_method_add_parameter ($$, l->data);
                }       
          }
        ;
 
 interface_property_declaration
-       : comment opt_attributes opt_ref type IDENTIFIER OPEN_BRACE interface_get_accessor_declaration opt_interface_set_accessor_declaration CLOSE_BRACE
+       : comment opt_attributes type IDENTIFIER OPEN_BRACE interface_get_accessor_declaration opt_interface_set_accessor_declaration CLOSE_BRACE
          {
-               $$ = vala_property_new ($5, $4, $7, $8, src_com (@4, $1));
+               $$ = vala_property_new ($4, $3, $6, $7, src_com (@3, $1));
          }
-       | comment opt_attributes opt_ref type IDENTIFIER OPEN_BRACE interface_set_accessor_declaration CLOSE_BRACE
+       | comment opt_attributes type IDENTIFIER OPEN_BRACE interface_set_accessor_declaration CLOSE_BRACE
          {
-               $$ = vala_property_new ($5, $4, NULL, $7, src_com (@4, $1));
+               $$ = vala_property_new ($4, $3, NULL, $6, src_com (@3, $1));
          }
        ;
 
@@ -1507,6 +1650,20 @@ interface_set_accessor_declaration
          }
        ;
 
+interface_signal_declaration
+       : comment opt_attributes SIGNAL type identifier_or_new OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON
+         {
+               GList *l;
+               
+               $$ = vala_signal_new ($5, $4, src_com (@5, $1));
+               VALA_CODE_NODE($$)->attributes = $2;
+               
+               for (l = $7; l != NULL; l = l->next) {
+                       vala_signal_add_parameter ($$, l->data);
+               }       
+         }
+       ;
+
 enum_declaration
        : comment opt_attributes opt_access_modifier ENUM IDENTIFIER enum_body
          {
@@ -1556,6 +1713,9 @@ enum_member_declaration
 
 flags_declaration
        : comment opt_attributes opt_access_modifier FLAGS IDENTIFIER flags_body
+         {
+               $$ = vala_flags_new ($5, src_com (@5, $1));
+         }
        ;
 
 flags_body
@@ -1721,10 +1881,7 @@ type_arguments
        ;
 
 type_argument
-       : opt_ref type
-         {
-               $$ = $2;
-         }
+       : type
        ;
 
 %%
index 8a1e48c..5332e5f 100644 (file)
@@ -43,9 +43,10 @@ static gboolean file_comment = FALSE;
 space                  [ \t\n]*
 ident                  [[:alnum:]_]+
 literal_integer                [[:digit:]]+
+literal_real           [[:digit:]]+"."[[:digit:]]+
 literal_character      \'([^\'\\]|\\[\'\"\?\\abfnrtv])*\'
 literal_string         \"([^\"\\]|\\[\'\"\?\\abfnrtv])*\"
-literal                        ({literal_integer}|{literal_character}|{literal_string})
+literal                        ({literal_integer}|{literal_real}|{literal_character}|{literal_string})
 
 %%
 
@@ -100,6 +101,7 @@ literal                     ({literal_integer}|{literal_character}|{literal_string})
 "&&"           { uploc; return OP_AND; }
 "&"            { uploc; return BITWISE_AND; }
 "^"            { uploc; return CARRET; }
+"~"            { uploc; return TILDE; }
 
 "="            { uploc; return ASSIGN; }
 "+"            { uploc; return PLUS; }
@@ -136,6 +138,7 @@ literal                     ({literal_integer}|{literal_character}|{literal_string})
 "private"      { uploc; return PRIVATE; }
 "ref"          { uploc; return REF; }
 "set"          { uploc; return SET; }
+"signal"       { uploc; return SIGNAL; }
 "static"       { uploc; return STATIC; }
 "struct"       { uploc; return STRUCT; }
 "return"       { uploc; return RETURN; }
@@ -146,6 +149,7 @@ literal                     ({literal_integer}|{literal_character}|{literal_string})
 "weak"         { uploc; return WEAK; }
 "while"                { uploc; return WHILE; }
 
+{literal_real}         { uploc; yylval->str = g_strdup (yytext); return REAL_LITERAL; }
 {literal_integer}      { uploc; yylval->str = g_strdup (yytext); return INTEGER_LITERAL; }
 
 {literal_character}    { uploc; yylval->str = g_strdup (yytext); return CHARACTER_LITERAL; }
index fdfdca9..df839d3 100644 (file)
 #include <vala/valacodecontext.h>
 #include <vala/valaconditionalexpression.h>
 #include <vala/valaconstant.h>
+#include <vala/valaconstructor.h>
 #include <vala/valacontinuestatement.h>
 #include <vala/valadeclarationstatement.h>
+#include <vala/valadestructor.h>
 #include <vala/valaemptystatement.h>
 #include <vala/valaenum.h>
 #include <vala/valaenumvalue.h>
@@ -42,6 +44,7 @@
 #include <vala/valaproperty.h>
 #include <vala/valapropertyaccessor.h>
 #include <vala/valareturnstatement.h>
+#include <vala/valasignal.h>
 #include <vala/valasimplename.h>
 #include <vala/valasourcefile.h>
 #include <vala/valasourcereference.h>
index 1a9ce24..0f060f8 100644 (file)
@@ -25,11 +25,12 @@ using GLib;
 namespace Vala {
        public class Assignment : Expression {
                public Expression left { get; construct; }
+               public AssignmentOperator operator { get; construct; }
                public Expression right { get; construct; }
                public SourceReference source_reference { get; construct; }
                
-               public static ref Assignment new (Expression left, Expression right, SourceReference source) {
-                       return (new Assignment (left = left, right = right, source_reference = source));
+               public static ref Assignment new (Expression left, AssignmentOperator op, Expression right, SourceReference source) {
+                       return (new Assignment (left = left, operator = op, right = right, source_reference = source));
                }
                
                public override void accept (CodeVisitor visitor) {
@@ -39,4 +40,18 @@ namespace Vala {
                        visitor.visit_assignment (this);
                }
        }
+       
+       public enum AssignmentOperator {
+               SIMPLE,
+               BITWISE_OR,
+               BITWISE_AND,
+               BITWISE_XOR,
+               ADD,
+               SUB,
+               MUL,
+               DIV,
+               PERCENT,
+               SHIFT_LEFT,
+               SHIFT_RIGHT
+       }
 }
diff --git a/vala/vala/valacallback.vala b/vala/vala/valacallback.vala
new file mode 100644 (file)
index 0000000..9cc73ac
--- /dev/null
@@ -0,0 +1,28 @@
+/* valacallback.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public class Callback : Type_ {
+       }
+}
index e7128cb..fdec348 100644 (file)
@@ -33,6 +33,10 @@ namespace Vala {
                List<Field> fields;
                List<Method> methods;
                List<Property> properties;
+               List<Signal> signals;
+               
+               public Constructor constructor { get; set; }
+               public Destructor destructor { get; set; }
                
                public string cname;
                public string lower_case_csuffix;
@@ -91,6 +95,14 @@ namespace Vala {
                        return properties.copy ();
                }
                
+               public void add_signal (Signal sig) {
+                       signals.append (sig);
+               }
+               
+               public ref List<Signal> get_signals () {
+                       return signals.copy ();
+               }
+               
                public override void accept (CodeVisitor visitor) {
                        visitor.visit_begin_class (this);
                        
@@ -117,6 +129,18 @@ namespace Vala {
                        foreach (Property prop in properties) {
                                prop.accept (visitor);
                        }
+                       
+                       foreach (Signal sig in signals) {
+                               sig.accept (visitor);
+                       }
+                       
+                       if (constructor != null) {
+                               constructor.accept (visitor);
+                       }
+
+                       if (destructor != null) {
+                               destructor.accept (visitor);
+                       }
 
                        visitor.visit_end_class (this);
                }
@@ -151,7 +175,7 @@ namespace Vala {
                }
                
                public override ref string get_upper_case_cname (string infix) {
-                       return get_lower_case_cname (infix).up (-1);
+                       return get_lower_case_cname (infix).up ();
                }
 
                public override bool is_reference_type () {
diff --git a/vala/vala/valaclassregisterfunction.vala b/vala/vala/valaclassregisterfunction.vala
new file mode 100644 (file)
index 0000000..f80acf0
--- /dev/null
@@ -0,0 +1,53 @@
+/* valaclassregisterfunction.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public class ClassRegisterFunction : TypeRegisterFunction {
+               public Class class_reference { get; construct; }
+               
+               public override Type_ get_type_declaration () {
+                       return class_reference;
+               }
+               
+               public override ref string get_type_struct_name () {
+                       return "%sClass".printf (class_reference.get_cname ());
+               }
+               
+               public override ref string get_class_init_func_name () {
+                       return "%s_class_init".printf (class_reference.get_lower_case_cname (null));
+               }
+               
+               public override ref string get_instance_struct_size () {
+                       return "sizeof (%s)".printf (class_reference.get_cname ());
+               }
+               
+               public override ref string get_instance_init_func_name () {
+                       return "%s_init".printf (class_reference.get_lower_case_cname (null));
+               }
+               
+               public override ref string get_parent_type_name () {
+                       return class_reference.base_class.get_upper_case_cname ("TYPE_");
+               }
+       }
+}
index 27410aa..a0e8dfc 100644 (file)
@@ -108,7 +108,7 @@ namespace Vala {
                        var define = String.new ("__");
                        
                        var i = filename;
-                       while (i.len (-1) > 0) {
+                       while (i.len () > 0) {
                                var c = i.get_char ();
                                /* FIXME: remove explicit cast when implicit cast works */
                                if (c.isalnum  () && c < (unichar) 128) {
@@ -238,37 +238,10 @@ namespace Vala {
                        add_set_property_function (cl);
                        add_class_init_function (cl);
                        add_instance_init_function (cl);
-                       add_type_register_function (cl);                        
-               }
-               
-               private void add_type_register_function (Class cl) {
-                       var type_fun = new CCodeFunction (name = "%s_get_type".printf (cl.get_lower_case_cname (null)), return_type = "GType");
-                       header_type_member_declaration.append (type_fun.copy ());
-                       
-                       var type_block = new CCodeBlock ();
-                       var cdecl = new CCodeDeclaration (type_name = "GType");
-                       cdecl.add_declarator (new CCodeVariableDeclarator (name = "g_define_type_id", initializer = new CCodeConstant (name = "0")));
-                       cdecl.modifiers = CCodeModifiers.STATIC;
-                       type_block.add_statement (cdecl);
-                       
-                       var cond = new CCodeFunctionCall (call = new CCodeIdentifier (name = "G_UNLIKELY"));
-                       cond.add_argument (new CCodeBinaryExpression (operator = CCodeBinaryOperator.EQUALITY, left = new CCodeIdentifier (name = "g_define_type_id"), right = new CCodeConstant (name = "0")));
-                       var type_init = new CCodeBlock ();
-                       var ctypedecl = new CCodeDeclaration (type_name = "const GTypeInfo");
-                       ctypedecl.modifiers = CCodeModifiers.STATIC;
-                       ctypedecl.add_declarator (new CCodeVariableDeclarator (name = "g_define_type_info", initializer = new CCodeConstant (name = "{ sizeof (%sClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) %s_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (%s), 0, (GInstanceInitFunc) %s_init }".printf (cl.get_cname (), cl.get_lower_case_cname (null), cl.get_cname (), cl.get_lower_case_cname (null)))));
-                       type_init.add_statement (ctypedecl);
-                       var reg_call = new CCodeFunctionCall (call = new CCodeIdentifier (name = "g_type_register_static"));
-                       reg_call.add_argument (new CCodeIdentifier (name = cl.base_class.get_upper_case_cname ("TYPE_")));
-                       reg_call.add_argument (new CCodeConstant (name = "\"%s\"".printf (cl.get_cname ())));
-                       reg_call.add_argument (new CCodeIdentifier (name = "&g_define_type_info"));
-                       reg_call.add_argument (new CCodeConstant (name = "0"));
-                       type_init.add_statement (new CCodeExpressionStatement (expression = new CCodeAssignment (left = new CCodeIdentifier (name = "g_define_type_id"), right = reg_call)));
-                       var cif = new CCodeIfStatement (condition = cond, true_statement = type_init);
-                       type_block.add_statement (cif);
-                       type_block.add_statement (new CCodeReturnStatement (return_expression = new CCodeIdentifier (name = "g_define_type_id")));
-                       
-                       type_fun.block = type_block;
+                       
+                       var type_fun = new ClassRegisterFunction (class_reference = cl);
+                       type_fun.init_from_type ();
+                       header_type_member_declaration.append (type_fun.get_declaration ());
                        source_type_member_definition.append (type_fun);
                }
                
@@ -294,6 +267,12 @@ namespace Vala {
                        init_block.add_statement (new CCodeExpressionStatement (expression = new CCodeAssignment (left = new CCodeMemberAccess (inner = ccall, member_name = "get_property", is_pointer = true), right = new CCodeIdentifier (name = "%s_get_property".printf (cl.get_lower_case_cname (null))))));
                        init_block.add_statement (new CCodeExpressionStatement (expression = new CCodeAssignment (left = new CCodeMemberAccess (inner = ccall, member_name = "set_property", is_pointer = true), right = new CCodeIdentifier (name = "%s_set_property".printf (cl.get_lower_case_cname (null))))));
                        
+                       if (cl.constructor != null) {
+                               var ccast = new CCodeFunctionCall (call = new CCodeIdentifier (name = "G_OBJECT_CLASS"));
+                               ccast.add_argument (new CCodeIdentifier (name = "klass"));
+                               init_block.add_statement (new CCodeExpressionStatement (expression = new CCodeAssignment (left = new CCodeMemberAccess (inner = ccast, member_name = "constructor", is_pointer = true), right = new CCodeIdentifier (name = "%s_constructor".printf (cl.get_lower_case_cname (null))))));
+                       }
+                       
                        foreach (Method m in cl.get_methods ()) {
                                if (m.is_virtual || m.is_override) {
                                        var ccast = new CCodeFunctionCall (call = new CCodeIdentifier (name = "%s_CLASS".printf (((Class) m.base_method.symbol.parent_symbol.node).get_upper_case_cname (null))));
@@ -513,6 +492,10 @@ namespace Vala {
                }
 
                public override void visit_end_interface (Interface iface) {
+                       var type_fun = new InterfaceRegisterFunction (interface_reference = iface);
+                       type_fun.init_from_type ();
+                       header_type_member_declaration.append (type_fun.get_declaration ());
+                       source_type_member_definition.append (type_fun);
                }
                
                public override void visit_begin_enum (Enum en) {
@@ -599,19 +582,28 @@ namespace Vala {
                                }
                        }
                        
+                       /* real function declaration and definition not needed
+                        * for abstract methods */
                        if (!m.is_abstract) {
                                if (m.access == MemberAccessibility.PUBLIC && !(m.is_virtual || m.is_override)) {
+                                       /* public methods need function declaration in
+                                        * header file except virtual/overridden methods */
                                        header_type_member_declaration.append (function.copy ());
                                } else {
+                                       /* declare all other functions in source file to
+                                        * avoid dependency on order within source file */
                                        function.modifiers |= CCodeModifiers.STATIC;
                                        source_type_member_declaration.append (function.copy ());
                                }
                                
+                               /* Methods imported from a plain C file don't
+                                * have a body, e.g. Vala.Parser.parse_file () */
                                if (m.body != null) {
+                                       function.block = m.body.ccodenode;
                                        if (m.is_override) {
                                                var cl = (Class) m.symbol.parent_symbol.node;
 
-                                               var cblock = new CCodeBlock ();
+                                               var cblock = new CCodeFragment ();
                                                
                                                var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = cl.get_upper_case_cname (null)));
                                                ccall.add_argument (new CCodeIdentifier (name = "base"));
@@ -619,20 +611,15 @@ namespace Vala {
                                                var cdecl = new CCodeDeclaration (type_name = "%s *".printf (cl.get_cname ()));
                                                cdecl.add_declarator (new CCodeVariableDeclarator (name = "self", initializer = ccall));
                                                
-                                               cblock.add_statement (cdecl);
-                                               cblock.add_statement (m.body.ccodenode);
-                                               function.block = cblock;
-                                       } else {
-                                               function.block = m.body.ccodenode;
+                                               cblock.append (cdecl);
+                                               function.block.prepend_statement (cblock);
                                        }
-                               } else if (m.is_abstract) {
-                                       function.block = new CCodeBlock ();
-                               }
 
-                               if (m.source_reference.comment != null) {
-                                       source_type_member_definition.append (new CCodeComment (text = m.source_reference.comment));
+                                       if (m.source_reference.comment != null) {
+                                               source_type_member_definition.append (new CCodeComment (text = m.source_reference.comment));
+                                       }
+                                       source_type_member_definition.append (function);
                                }
-                               source_type_member_definition.append (function);
                        }
                        
                        if (m.is_abstract || m.is_virtual) {
@@ -718,6 +705,74 @@ namespace Vala {
                        
                        source_type_member_definition.append (function);
                }
+               
+               public override void visit_end_constructor (Constructor c) {
+                       var cl = (Class) c.symbol.parent_symbol.node;
+               
+                       function = new CCodeFunction (name = "%s_constructor".printf (cl.get_lower_case_cname (null)), return_type = "GObject *");
+                       function.modifiers = CCodeModifiers.STATIC;
+                       
+                       function.add_parameter (new CCodeFormalParameter (name = "type", type_name = "GType"));
+                       function.add_parameter (new CCodeFormalParameter (name = "n_construct_properties", type_name = "guint"));
+                       function.add_parameter (new CCodeFormalParameter (name = "construct_properties", type_name = "GObjectConstructParam *"));
+                       
+                       source_type_member_declaration.append (function.copy ());
+
+
+                       var cblock = new CCodeBlock ();
+                       var cdecl = new CCodeDeclaration (type_name = "GObject *");
+                       cdecl.add_declarator (new CCodeVariableDeclarator (name = "obj"));
+                       cblock.add_statement (cdecl);
+
+                       cdecl = new CCodeDeclaration (type_name = "%sClass *".printf (cl.get_cname ()));
+                       cdecl.add_declarator (new CCodeVariableDeclarator (name = "klass"));
+                       cblock.add_statement (cdecl);
+
+                       cdecl = new CCodeDeclaration (type_name = "GObjectClass *");
+                       cdecl.add_declarator (new CCodeVariableDeclarator (name = "parent_class"));
+                       cblock.add_statement (cdecl);
+       
+       
+                       var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = "g_type_class_peek"));
+                       ccall.add_argument (new CCodeIdentifier (name = cl.get_upper_case_cname ("TYPE_")));
+                       var ccast = new CCodeFunctionCall (call = new CCodeIdentifier (name = "%s_CLASS".printf (cl.get_upper_case_cname (null))));
+                       ccast.add_argument (ccall);
+                       cblock.add_statement (new CCodeExpressionStatement (expression = new CCodeAssignment (left = new CCodeIdentifier (name = "klass"), right = ccast)));
+
+                       ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = "g_type_class_peek_parent"));
+                       ccall.add_argument (new CCodeIdentifier (name = "klass"));
+                       ccast = new CCodeFunctionCall (call = new CCodeIdentifier (name = "G_OBJECT_CLASS"));
+                       ccast.add_argument (ccall);
+                       cblock.add_statement (new CCodeExpressionStatement (expression = new CCodeAssignment (left = new CCodeIdentifier (name = "parent_class"), right = ccast)));
+
+                       
+                       ccall = new CCodeFunctionCall (call = new CCodeMemberAccess (inner = new CCodeIdentifier (name = "parent_class"), member_name = "constructor", is_pointer = true));
+                       ccall.add_argument (new CCodeIdentifier (name = "type"));
+                       ccall.add_argument (new CCodeIdentifier (name = "n_construct_properties"));
+                       ccall.add_argument (new CCodeIdentifier (name = "construct_properties"));
+                       cblock.add_statement (new CCodeExpressionStatement (expression = new CCodeAssignment (left = new CCodeIdentifier (name = "obj"), right = ccall)));
+
+
+                       ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = cl.get_upper_case_cname (null)));
+                       ccall.add_argument (new CCodeIdentifier (name = "obj"));
+                       
+                       cdecl = new CCodeDeclaration (type_name = "%s *".printf (cl.get_cname ()));
+                       cdecl.add_declarator (new CCodeVariableDeclarator (name = "self", initializer = ccall));
+                       
+                       cblock.add_statement (cdecl);
+
+
+                       cblock.add_statement (c.body.ccodenode);
+                       
+                       cblock.add_statement (new CCodeReturnStatement (return_expression = new CCodeIdentifier (name = "obj")));
+                       
+                       function.block = cblock;
+
+                       if (c.source_reference.comment != null) {
+                               source_type_member_definition.append (new CCodeComment (text = c.source_reference.comment));
+                       }
+                       source_type_member_definition.append (function);
+               }
 
                public override void visit_end_block (Block b) {
                        var cblock = new CCodeBlock ();
@@ -762,7 +817,16 @@ namespace Vala {
 
                public override void visit_variable_declarator (VariableDeclarator decl) {
                        if (decl.initializer != null) {
-                               decl.ccodenode = new CCodeVariableDeclarator (name = decl.name, initializer = decl.initializer.ccodenode);
+                               var rhs = (CCodeExpression) decl.initializer.ccodenode;
+                               
+                               if (decl.type_reference.type != null
+                                   && decl.initializer.static_type.type != null
+                                   && decl.type_reference.type.is_reference_type ()
+                                   && decl.initializer.static_type.type != decl.type_reference.type) {
+                                       rhs = new InstanceCast (type_reference = decl.type_reference.type, inner = rhs);
+                               }
+                               
+                               decl.ccodenode = new CCodeVariableDeclarator (name = decl.name, initializer = rhs);
                        } else {
                                decl.ccodenode = new CCodeVariableDeclarator (name = decl.name);
                        }
@@ -771,7 +835,7 @@ namespace Vala {
                public override void visit_initializer_list (InitializerList list) {
                        var clist = new CCodeInitializerList ();
                        foreach (Expression expr in list.initializers) {
-                               clist.append (expr.ccodenode);
+                               clist.append ((CCodeExpression) expr.ccodenode);
                        }
                        list.ccodenode = clist;
                }
@@ -888,6 +952,10 @@ namespace Vala {
                        expr.ccodenode = new CCodeConstant (name = expr.value);
                }
 
+               public override void visit_real_literal (RealLiteral expr) {
+                       expr.ccodenode = new CCodeConstant (name = expr.value);
+               }
+
                public override void visit_string_literal (StringLiteral expr) {
                        expr.ccodenode = new CCodeConstant (name = expr.value);
                }
@@ -900,7 +968,7 @@ namespace Vala {
                        expr.ccodenode = expr.literal.ccodenode;
                }
                
-               private void process_cmember (Expression expr, CCodeIdentifier pub_inst, Type_ base_type) {
+               private void process_cmember (Expression expr, CCodeExpression pub_inst, Type_ base_type) {
                        if (expr.symbol_reference.node is Method) {
                                var m = (Method) expr.symbol_reference.node;
                                if (!m.is_override) {
@@ -940,6 +1008,14 @@ namespace Vala {
                                var prop = (Property) expr.symbol_reference.node;
                                var cl = (Class) prop.symbol.parent_symbol.node;
                                var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = "%s_get_%s".printf (cl.get_lower_case_cname (null), prop.name)));
+
+                               /* cast if necessary */
+                               if (prop.symbol.parent_symbol.node != base_type) {
+                                       var ccast = new CCodeFunctionCall (call = new CCodeIdentifier (name = ((Type_) prop.symbol.parent_symbol.node).get_upper_case_cname (null)));
+                                       ccast.add_argument (pub_inst);
+                                       pub_inst = ccast;
+                               }
+
                                ccall.add_argument (pub_inst);
                                expr.ccodenode = ccall;
                        } else if (expr.symbol_reference.node is EnumValue) {
@@ -970,7 +1046,7 @@ namespace Vala {
                }
 
                public override void visit_member_access (MemberAccess expr) {
-                       var pub_inst = expr.inner.ccodenode;
+                       var pub_inst = (CCodeExpression) expr.inner.ccodenode;
                        Type_ base_type = null;
                        if (expr.inner.static_type != null) {
                                base_type = expr.inner.static_type.type;
@@ -983,22 +1059,83 @@ namespace Vala {
                        var ccall = new CCodeFunctionCall (call = (CCodeExpression) expr.call.ccodenode);
                        
                        var m = (Method) expr.call.symbol_reference.node;
+                       var base_method = m;
+                       if (m.is_override) {
+                               base_method = m.base_method;
+                       }
+                       
                        CCodeExpression instance;
                        if (m.instance) {
+                               var req_cast = false;
                                if (expr.call is SimpleName) {
                                        instance = new CCodeIdentifier (name = "self");
+                                       /* require casts for override methods */
+                                       req_cast = m.is_override;
                                } else if (expr.call is MemberAccess) {
-                                       instance = ((MemberAccess) expr.call).inner.ccodenode;
+                                       var ma = (MemberAccess) expr.call;
+                                       instance = ma.inner.ccodenode;
+                                       /* reqiure casts if the type of the used instance is different than the type which declared the method */
+                                       req_cast = base_method.symbol.parent_symbol.node != ma.inner.static_type.type;
                                } else {
                                        Report.error (expr.source_reference, "unsupported method invocation");
                                }
+                               
+                               if (req_cast && ((Type_) m.symbol.parent_symbol.node).is_reference_type ()) {
+                                       var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = ((Type_) base_method.symbol.parent_symbol.node).get_upper_case_cname (null)));
+                                       ccall.add_argument (instance);
+                                       instance = ccall;
+                               }
+                               
                                if (!m.instance_last) {
                                        ccall.add_argument (instance);
                                }
                        }
                        
+                       var params = m.get_parameters ();
+                       var i = 1;
                        foreach (Expression arg in expr.argument_list) {
-                               ccall.add_argument ((CCodeExpression) arg.ccodenode);
+                               var cexpr = (CCodeExpression) arg.ccodenode;
+                               if (params != null) {
+                                       var param = (FormalParameter) params.data;
+                                       if (!param.ellipsis
+                                           && param.type_reference.type != null
+                                           && param.type_reference.type.is_reference_type ()
+                                           && arg.static_type.type != null
+                                           && param.type_reference.type != arg.static_type.type) {
+                                               var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = param.type_reference.type.get_upper_case_cname (null)));
+                                               ccall.add_argument (cexpr);
+                                               cexpr = ccall;
+                                       }
+                               }
+                       
+                               ccall.add_argument (cexpr);
+                               i++;
+                               
+                               if (params != null) {
+                                       params = params.next;
+                               }
+                       }
+                       while (params != null) {
+                               var param = (FormalParameter) params.data;
+                               
+                               if (param.ellipsis) {
+                                       break;
+                               }
+                               
+                               if (param.default_expression == null) {
+                                       Report.error (expr.source_reference, "no default expression for argument %d".printf (i));
+                                       return;
+                               }
+                               
+                               /* evaluate default expression here as the code
+                                * generator might not have visited the formal
+                                * parameter yet */
+                               param.default_expression.accept (this);
+                       
+                               ccall.add_argument ((CCodeExpression) param.default_expression.ccodenode);
+                               i++;
+                       
+                               params = params.next;
                        }
                        
                        if (m.instance && m.instance_last) {
@@ -1053,7 +1190,11 @@ namespace Vala {
                }
 
                public override void visit_cast_expression (CastExpression expr) {
-                       expr.ccodenode = expr.inner.ccodenode;
+                       if (expr.type_reference.type is Struct || expr.type_reference.type is Enum || expr.type_reference.type is Flags) {
+                               expr.ccodenode = expr.inner.ccodenode;
+                       } else {
+                               expr.ccodenode = new InstanceCast (type_reference = expr.type_reference.type, inner = (CCodeExpression) expr.inner.ccodenode);
+                       }
                }
 
                public override void visit_binary_expression (BinaryExpression expr) {
@@ -1062,7 +1203,7 @@ namespace Vala {
 
                public override void visit_type_check (TypeCheck expr) {
                        var ccheck = new CCodeFunctionCall (call = new CCodeIdentifier (name = expr.type_reference.type.get_upper_case_cname ("IS_")));
-                       ccheck.add_argument (expr.expression.ccodenode);
+                       ccheck.add_argument ((CCodeExpression) expr.expression.ccodenode);
                        expr.ccodenode = ccheck;
                }
 
@@ -1073,16 +1214,61 @@ namespace Vala {
                                var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = "%s_set_%s".printf (cl.get_lower_case_cname (null), prop.name)));
                                if (a.left is MemberAccess) {
                                        var expr = (MemberAccess) a.left;
-                                       ccall.add_argument (expr.inner.ccodenode);
+                                       ccall.add_argument ((CCodeExpression) expr.inner.ccodenode);
                                } else if (a.left is SimpleName) {
                                        ccall.add_argument (new CCodeIdentifier (name = "self"));
                                } else {
                                        Report.error (a.source_reference, "unexpected lvalue in assignment");
+                                       return;
                                }
                                ccall.add_argument ((CCodeExpression) a.right.ccodenode);
                                a.ccodenode = ccall;
+                       } else if (a.left.symbol_reference.node is Signal) {
+                               var sig = (Signal) a.left.symbol_reference.node;
+                               var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = "g_signal_connect_object"));
+                               
+                               var m = (Method) a.right.symbol_reference.node;
+                       
+                               if (a.left is MemberAccess) {
+                                       var expr = (MemberAccess) a.left;
+                                       ccall.add_argument ((CCodeExpression) expr.inner.ccodenode);
+                               } else if (a.left is SimpleName) {
+                                       ccall.add_argument (new CCodeIdentifier (name = "self"));
+                               } else {
+                                       Report.error (a.source_reference, "unexpected lvalue in assignment");
+                                       return;
+                               }
+
+                               ccall.add_argument (new CCodeConstant (name = "\"%s\"".printf (sig.name)));
+
+                               ccall.add_argument (new CCodeIdentifier (name = m.get_cname ()));
+
+                               if (a.right is MemberAccess) {
+                                       var expr = (MemberAccess) a.right;
+                                       ccall.add_argument ((CCodeExpression) expr.inner.ccodenode);
+                               } else if (a.right is SimpleName) {
+                                       ccall.add_argument (new CCodeIdentifier (name = "self"));
+                               } else {
+                                       Report.error (a.source_reference, "unsupported expression for signal handler");
+                                       return;
+                               }
+
+                               ccall.add_argument (new CCodeConstant (name = "G_CONNECT_SWAPPED"));
+                               
+                               a.ccodenode = ccall;
                        } else {
-                               a.ccodenode = new CCodeAssignment (left = (CCodeExpression) a.left.ccodenode, right = (CCodeExpression) a.right.ccodenode);
+                               var rhs = (CCodeExpression) a.right.ccodenode;
+                               
+                               if (a.left.static_type.type != null
+                                   && a.right.static_type.type != null
+                                   && a.left.static_type.type.is_reference_type ()
+                                   && a.right.static_type.type != a.left.static_type.type) {
+                                       var ccast = new CCodeFunctionCall (call = new CCodeIdentifier (name = a.left.static_type.type.get_upper_case_cname (null)));
+                                       ccast.add_argument (rhs);
+                                       rhs = ccast;
+                               }
+                               
+                               a.ccodenode = new CCodeAssignment (left = (CCodeExpression) a.left.ccodenode, right = rhs);
                        }
                }
        }
index d5165c6..1a35f56 100644 (file)
@@ -63,6 +63,15 @@ namespace Vala {
                public virtual void visit_enum_value (EnumValue ev) {
                }
 
+               public virtual void visit_begin_flags (Flags fl) {
+               }
+
+               public virtual void visit_end_flags (Flags fl) {
+               }
+
+               public virtual void visit_flags_value (FlagsValue fv) {
+               }
+
                public virtual void visit_constant (Constant c) {
                }
 
@@ -90,6 +99,24 @@ namespace Vala {
                public virtual void visit_end_property_accessor (PropertyAccessor acc) {
                }
 
+               public virtual void visit_begin_signal (Signal sig) {
+               }
+
+               public virtual void visit_end_signal (Signal sig) {
+               }
+
+               public virtual void visit_begin_constructor (Constructor c) {
+               }
+
+               public virtual void visit_end_constructor (Constructor c) {
+               }
+
+               public virtual void visit_begin_destructor (Destructor d) {
+               }
+
+               public virtual void visit_end_destructor (Destructor d) {
+               }
+
                public virtual void visit_named_argument (NamedArgument n) {
                }
 
@@ -159,6 +186,9 @@ namespace Vala {
                public virtual void visit_integer_literal (IntegerLiteral expr) {
                }
 
+               public virtual void visit_real_literal (RealLiteral expr) {
+               }
+
                public virtual void visit_string_literal (StringLiteral expr) {
                }
 
index 80de1d7..e84d7f2 100644 (file)
@@ -49,7 +49,7 @@ namespace Vala {
                                        cname = "%s_%s".printf (t.get_upper_case_cname (null), name);
                                } else {
                                        var ns = (Namespace) symbol.parent_symbol.node;
-                                       cname = "%s%s".printf (ns.get_cprefix ().up (-1), name);
+                                       cname = "%s%s".printf (ns.get_cprefix ().up (), name);
                                }
                        }
                        return cname;
diff --git a/vala/vala/valaconstructor.vala b/vala/vala/valaconstructor.vala
new file mode 100644 (file)
index 0000000..4beeca9
--- /dev/null
@@ -0,0 +1,45 @@
+/* valaconstructor.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public class Constructor : CodeNode {
+               public SourceReference source_reference { get; construct; }
+               public Statement body { get; construct; }
+               public bool instance = true;
+               
+               public static ref Constructor new (SourceReference source) {
+                       return (new Constructor (source_reference = source));
+               }
+               
+               public override void accept (CodeVisitor visitor) {
+                       visitor.visit_begin_constructor (this);
+                       
+                       if (body != null) {
+                               body.accept (visitor);
+                       }
+
+                       visitor.visit_end_constructor (this);
+               }
+       }
+}
diff --git a/vala/vala/valadestructor.vala b/vala/vala/valadestructor.vala
new file mode 100644 (file)
index 0000000..16ce024
--- /dev/null
@@ -0,0 +1,45 @@
+/* valadestructor.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public class Destructor : CodeNode {
+               public SourceReference source_reference { get; construct; }
+               public Statement body { get; construct; }
+               public bool instance = true;
+               
+               public static ref Destructor new (SourceReference source) {
+                       return (new Destructor (source_reference = source));
+               }
+               
+               public override void accept (CodeVisitor visitor) {
+                       visitor.visit_begin_destructor (this);
+                       
+                       if (body != null) {
+                               body.accept (visitor);
+                       }
+
+                       visitor.visit_end_destructor (this);
+               }
+       }
+}
index 9a8f54c..01a5117 100644 (file)
@@ -53,7 +53,7 @@ namespace Vala {
                }
                
                public override string get_upper_case_cname (string infix) {
-                       return "%s%s".printf (@namespace.get_lower_case_cprefix (), Namespace.camel_case_to_lower_case (name)).up (-1);
+                       return "%s%s".printf (@namespace.get_lower_case_cprefix (), Namespace.camel_case_to_lower_case (name)).up ();
                }
 
                public override bool is_reference_type () {
diff --git a/vala/vala/valaflags.vala b/vala/vala/valaflags.vala
new file mode 100644 (file)
index 0000000..06801d6
--- /dev/null
@@ -0,0 +1,63 @@
+/* valaflags.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public class Flags : Type_ {
+               List<FlagsValue> values;
+
+               public static ref Flags new (string name, SourceReference source) {
+                       return (new Flags (name = name, source_reference = source));
+               }
+               
+               public void add_value (FlagsValue value) {
+                       values.append (value);
+               }
+               
+               public override void accept (CodeVisitor visitor) {
+                       visitor.visit_begin_flags (this);
+                       
+                       foreach (FlagsValue value in values) {
+                               value.accept (visitor);
+                       }
+
+                       visitor.visit_end_flags (this);
+               }
+
+               string cname;
+               public override string get_cname () {
+                       if (cname == null) {
+                               cname = "%s%s".printf (@namespace.get_cprefix (), name);
+                       }
+                       return cname;
+               }
+               
+               public override string get_upper_case_cname (string infix) {
+                       return "%s%s".printf (@namespace.get_lower_case_cprefix (), Namespace.camel_case_to_lower_case (name)).up ();
+               }
+
+               public override bool is_reference_type () {
+                       return false;
+               }
+       }
+}
diff --git a/vala/vala/valaflagsvalue.vala b/vala/vala/valaflagsvalue.vala
new file mode 100644 (file)
index 0000000..379d3e8
--- /dev/null
@@ -0,0 +1,52 @@
+/* valaflagsvalue.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public class FlagsValue : CodeNode {
+               public string name { get; construct; }
+               public IntegerLiteral value { get; construct; }
+               public SourceReference source_reference { get; construct; }
+
+               public static ref FlagsValue new (string name) {
+                       return (new FlagsValue (name = name));
+               }
+
+               public static ref FlagsValue new_with_value (string name, int value) {
+                       return (new FlagsValue (name = name, value = value));
+               }
+               
+               public override void accept (CodeVisitor visitor) {
+                       visitor.visit_flags_value (this);
+               }
+               
+               string cname;
+               public string get_cname () {
+                       if (cname == null) {
+                               var fl = (Flags) symbol.parent_symbol.node;
+                               cname = "%s_%s".printf (fl.get_upper_case_cname (null), name);
+                       }
+                       return cname;
+               }
+       }
+}
index 73fb5ae..4d4c9d7 100644 (file)
@@ -28,6 +28,7 @@ namespace Vala {
                public TypeReference type_reference { get; construct; }
                public bool ellipsis { get; construct; }
                public SourceReference source_reference { get; construct; }
+               public Expression default_expression { get; set construct; }
                
                public static ref FormalParameter new (string name, TypeReference type, SourceReference source) {
                        return (new FormalParameter (name = name, type_reference = type, source_reference = source));
diff --git a/vala/vala/valainstancecast.vala b/vala/vala/valainstancecast.vala
new file mode 100644 (file)
index 0000000..acd3bc7
--- /dev/null
@@ -0,0 +1,38 @@
+/* valainstancecast.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public class InstanceCast : CCodeFunctionCall {
+               public Type_ type_reference { get; construct; }
+               public CCodeExpression inner { get; construct; }
+               
+               InstanceCast () {
+                       call = new CCodeIdentifier (name = type_reference.get_upper_case_cname (null));
+                       add_argument ((CCodeExpression) inner);
+               }
+       }
+}
+
+
+
index 2b2c54c..27e8f8a 100644 (file)
@@ -29,6 +29,7 @@ namespace Vala {
 
                List<Method> methods;
                List<Property> properties;
+               List<Signal> signals;
                
                public static ref Interface new (string name, SourceReference source) {
                        return (new Interface (name = name, source_reference = source));
@@ -61,6 +62,14 @@ namespace Vala {
                        return properties.copy ();
                }
                
+               public void add_signal (Signal sig) {
+                       signals.append (sig);
+               }
+               
+               public ref List<Signal> get_signals () {
+                       return signals.copy ();
+               }
+               
                private string cname;
                private string lower_case_csuffix;
                
@@ -90,7 +99,7 @@ namespace Vala {
                }
                
                public override ref string get_upper_case_cname (string infix) {
-                       return get_lower_case_cname (infix).up (-1);
+                       return get_lower_case_cname (infix).up ();
                }
                
                public override void accept (CodeVisitor visitor) {
diff --git a/vala/vala/valainterfaceregisterfunction.vala b/vala/vala/valainterfaceregisterfunction.vala
new file mode 100644 (file)
index 0000000..66ad166
--- /dev/null
@@ -0,0 +1,53 @@
+/* valainterfaceregisterfunction.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public class InterfaceRegisterFunction : TypeRegisterFunction {
+               public Interface interface_reference { get; construct; }
+               
+               public override Type_ get_type_declaration () {
+                       return interface_reference;
+               }
+               
+               public override ref string get_type_struct_name () {
+                       return "%sInterface".printf (interface_reference.get_cname ());
+               }
+               
+               public override ref string get_class_init_func_name () {
+                       return "NULL";
+               }
+               
+               public override ref string get_instance_struct_size () {
+                       return "0";
+               }
+               
+               public override ref string get_instance_init_func_name () {
+                       return "NULL";
+               }
+               
+               public override ref string get_parent_type_name () {
+                       return "G_TYPE_INTERFACE";
+               }
+       }
+}
index c4e73d7..b11fa50 100644 (file)
@@ -31,6 +31,7 @@ namespace Vala {
                List<Interface> interfaces;
                List<Struct> structs;
                List<Enum> enums;
+               List<Flags> flags_;
                List<Field> fields;
                List<Method> methods;
                
@@ -70,6 +71,11 @@ namespace Vala {
                        enums.append (en);
                        en.@namespace = this;
                }
+                               
+               public void add_flags (Flags fl) {
+                       flags_.append (fl);
+                       fl.@namespace = this;
+               }
 
                public ref List<Struct> get_structs () {
                        return structs.copy ();
@@ -106,6 +112,10 @@ namespace Vala {
                                en.accept (visitor);
                        }
 
+                       foreach (Flags fl in flags_) {
+                               fl.accept (visitor);
+                       }
+
                        foreach (Field f in fields) {
                                f.accept (visitor);
                        }
@@ -123,7 +133,7 @@ namespace Vala {
                        string i = camel_case;
                        
                        bool first = true;
-                       while (i.len (-1) > 0) {
+                       while (i.len () > 0) {
                                unichar c = i.get_char ();
                                if (c.isupper () && !first) {
                                        /* current character is upper case and
@@ -132,10 +142,10 @@ namespace Vala {
                                        bool prev_upper = t.get_char ().isupper ();
                                        t = i.next_char ();
                                        bool next_upper = t.get_char ().isupper ();
-                                       if (!prev_upper || (i.len (-1) >= 2 && !next_upper)) {
+                                       if (!prev_upper || (i.len () >= 2 && !next_upper)) {
                                                /* previous character wasn't upper case or
                                                 * next character isn't upper case*/
-                                               int len = result.str.len (-1);
+                                               int len = result.str.len ();
                                                if (len != 1 && result.str.offset (len - 2).get_char () != '_') {
                                                        /* we're not creating 1 character words */
                                                        result.append_c ('_');
index 205f346..b186a6a 100644 (file)
@@ -51,7 +51,7 @@ namespace Vala {
                }
                
                public ref string get_upper_case_cname () {
-                       return "%s_%s".printf (((Class) symbol.parent_symbol.node).get_lower_case_cname (null), Namespace.camel_case_to_lower_case (name)).up (-1);
+                       return "%s_%s".printf (((Class) symbol.parent_symbol.node).get_lower_case_cname (null), Namespace.camel_case_to_lower_case (name)).up ();
                }
        }
 }
diff --git a/vala/vala/valarealliteral.vala b/vala/vala/valarealliteral.vala
new file mode 100644 (file)
index 0000000..e4f78ea
--- /dev/null
@@ -0,0 +1,38 @@
+/* valarealliteral.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public class RealLiteral : Literal {
+               public string value { get; construct; }
+               public SourceReference source_reference { get; construct; }
+
+               public static ref RealLiteral new (string r, SourceReference source) {
+                       return (new RealLiteral (value = r, source_reference = source));
+               }
+               
+               public override void accept (CodeVisitor visitor) {
+                       visitor.visit_real_literal (this);
+               }
+       }
+}
index 986fa07..327b57f 100644 (file)
@@ -149,6 +149,22 @@ namespace Vala {
                        }
                }
 
+               public override void visit_begin_constructor (Constructor c) {
+                       current_symbol = c.symbol;
+               }
+
+               public override void visit_end_constructor (Constructor c) {
+                       current_symbol = current_symbol.parent_symbol;
+               }
+
+               public override void visit_begin_destructor (Destructor d) {
+                       current_symbol = d.symbol;
+               }
+
+               public override void visit_end_destructor (Destructor d) {
+                       current_symbol = current_symbol.parent_symbol;
+               }
+
                public override void visit_named_argument (NamedArgument n) {
                }
 
@@ -200,6 +216,11 @@ namespace Vala {
                        expr.static_type.type = (Type_) root_symbol.lookup ("int").node;
                }
 
+               public override void visit_real_literal (IntegerLiteral expr) {
+                       expr.static_type = new TypeReference ();
+                       expr.static_type.type = (Type_) root_symbol.lookup ("double").node;
+               }
+
                public override void visit_string_literal (StringLiteral expr) {
                        expr.static_type = string_type;
                }
@@ -261,11 +282,13 @@ namespace Vala {
                        if (expr.symbol_reference == null) {
                                foreach (NamespaceReference ns in current_using_directives) {
                                        var local_sym = ns.namespace_symbol.lookup (expr.name);
-                                       if (expr.symbol_reference != null && local_sym != null) {
-                                               Report.error (expr.source_reference, "`%s' is an ambiguous reference between `%s' and `%s'".printf (expr.name, expr.symbol_reference.get_full_name (), local_sym.get_full_name ()));
-                                               return;
+                                       if (local_sym != null) {
+                                               if (expr.symbol_reference != null) {
+                                                       Report.error (expr.source_reference, "`%s' is an ambiguous reference between `%s' and `%s'".printf (expr.name, expr.symbol_reference.get_full_name (), local_sym.get_full_name ()));
+                                                       return;
+                                               }
+                                               expr.symbol_reference = local_sym;
                                        }
-                                       expr.symbol_reference = local_sym;
                                }
                        }
 
@@ -338,6 +361,11 @@ namespace Vala {
                                return true;
                        }
                        
+                       /* int may be implicitly casted to double */
+                       if (expression_type.type == root_symbol.lookup ("int").node && expected_type.type == root_symbol.lookup ("double").node) {
+                               return true;
+                       }
+                       
                        /* char may be implicitly casted to unichar */
                        if (expression_type.type == root_symbol.lookup ("char").node && expected_type.type == root_symbol.lookup ("unichar").node) {
                                return true;
@@ -352,12 +380,12 @@ namespace Vala {
                        
                        var base_class = cl.base_class;
                        for (; base_class != null; base_class = base_class.base_class) {
-                               if (base_class == expected_type) {
+                               if (base_class == expected_type.type) {
                                        return true;
                                }
                        }
                        
-                       return true;
+                       return false;
                }
 
                public override void visit_invocation_expression (InvocationExpression expr) {
@@ -379,23 +407,29 @@ namespace Vala {
                                        break;
                                }
 
-                               if (arg_it == null) {
-                                       /* if (param.default_argument) { } */
-                                       Report.error (expr.source_reference, "Method `%s' does not take %d arguments".printf (m.symbol.get_full_name (), expr.argument_list.length ()));
-                                       return;
+                               /* header file necessary if we need to cast argument */
+                               if (param.type_reference.type != null) {
+                                       current_source_file.add_symbol_dependency (param.type_reference.type.symbol, SourceFileDependencyType.SOURCE);
                                }
-                               
-                               var arg = (Expression) arg_it.data;
-                               if (arg.static_type != null && !is_type_compatible (arg.static_type, param.type_reference)) {
-                                       /* if there was an error in the argument,
-                                        * i.e. arg.static_type == null, skip type check */
-                                       Report.error (expr.source_reference, "Argument %d: Cannot convert from `%s' to `%s'".printf (i + 1, arg.static_type.type.symbol.get_full_name (), param.type_reference.to_string ()));
-                                       return;
-                               }
-                               
-                               arg_it = arg_it.next;
 
-                               i++;
+                               if (arg_it == null) {
+                                       if (param.default_expression == null) {
+                                               Report.error (expr.source_reference, "Method `%s' does not take %d arguments".printf (m.symbol.get_full_name (), expr.argument_list.length ()));
+                                               return;
+                                       }
+                               } else {
+                                       var arg = (Expression) arg_it.data;
+                                       if (arg.static_type != null && !is_type_compatible (arg.static_type, param.type_reference)) {
+                                               /* if there was an error in the argument,
+                                                * i.e. arg.static_type == null, skip type check */
+                                               Report.error (expr.source_reference, "Argument %d: Cannot convert from `%s' to `%s'".printf (i + 1, arg.static_type.type.symbol.get_full_name (), param.type_reference.to_string ()));
+                                               return;
+                                       }
+                                       
+                                       arg_it = arg_it.next;
+
+                                       i++;
+                               }
                        }
                        
                        if (!ellipsis && arg_it != null) {
@@ -530,8 +564,10 @@ namespace Vala {
                                   || expr.operator == BinaryOperator.INEQUALITY) {
                                /* relational operation */
 
-                               if (!check_binary_type (expr, "Equality operation")) {
-                                       return;
+                               if (!is_type_compatible (expr.right.static_type, expr.left.static_type)
+                                   && !is_type_compatible (expr.left.static_type, expr.right.static_type)) {
+                                       Report.error (expr.source_reference, "Equality operation: `%s' and `%s' are incompatible, comparison would always evaluate to false".printf (expr.right.static_type.to_string (), expr.left.static_type.to_string ()));
+                                       return false;
                                }
                                
                                if (expr.left.static_type.type == string_type.type
diff --git a/vala/vala/valasignal.vala b/vala/vala/valasignal.vala
new file mode 100644 (file)
index 0000000..1e90ccb
--- /dev/null
@@ -0,0 +1,57 @@
+/* valasignal.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public class Signal : CodeNode {
+               public string name { get; construct; }
+               public TypeReference return_type { get; construct; }
+               public SourceReference source_reference { get; construct; }
+               public MemberAccessibility access;
+               public List<FormalParameter> parameters;
+               
+               public static ref Signal new (string name, TypeReference return_type, SourceReference source) {
+                       return (new Signal (name = name, return_type = return_type, source_reference = source));
+               }
+               
+               public void add_parameter (FormalParameter param) {
+                       parameters.append (param);
+               }
+               
+               public ref List<FormalParameter> get_parameters () {
+                       return parameters.copy ();
+               }
+               
+               public override void accept (CodeVisitor visitor) {
+                       visitor.visit_begin_signal (this);
+                       
+                       return_type.accept (visitor);
+                       
+                       foreach (FormalParameter param in parameters) {
+                               param.accept (visitor);
+                       }
+
+                       visitor.visit_end_signal (this);
+               }
+       }
+}
index 2108773..9bc7231 100644 (file)
@@ -77,7 +77,7 @@ namespace Vala {
                
                public string get_cheader_filename () {
                        if (cheader_filename == null) {
-                               var basename = filename.ndup ((uint) (filename.len (-1) - ".vala".len (-1)));
+                               var basename = filename.ndup ((uint) (filename.len () - ".vala".len ()));
                                cheader_filename = "%s.h".printf (basename);
                        }
                        return cheader_filename;
@@ -87,7 +87,7 @@ namespace Vala {
                
                public string get_csource_filename () {
                        if (csource_filename == null) {
-                               var basename = filename.ndup ((uint) (filename.len (-1) - ".vala".len (-1)));
+                               var basename = filename.ndup ((uint) (filename.len () - ".vala".len ()));
                                csource_filename = "%s.c".printf (basename);
                        }
                        return csource_filename;
index 2551e4b..3f49cfc 100644 (file)
@@ -33,7 +33,7 @@ namespace Vala {
                
                public ref string eval () {
                        /* remove quotes */
-                       var noquotes = value.offset (1).ndup ((uint) (value.len (-1) - 2));
+                       var noquotes = value.offset (1).ndup ((uint) (value.len () - 2));
                        /* unescape string */
                        return noquotes.compress ();
                }
index 8ee7cc1..1a6a94b 100644 (file)
@@ -116,7 +116,7 @@ namespace Vala {
                }
                
                public override ref string get_upper_case_cname (string infix) {
-                       return get_lower_case_cname (infix).up (-1);
+                       return get_lower_case_cname (infix).up ();
                }
                
                public override bool is_reference_type () {
index e731a7a..786051b 100644 (file)
@@ -248,6 +248,46 @@ namespace Vala {
                        current_symbol = current_symbol.parent_symbol;
                }
 
+               public override void visit_begin_signal (Signal sig) {
+                       if (current_symbol.lookup (sig.name) != null) {
+                               sig.error = true;
+                               Report.error (sig.source_reference, "The type `%s' already contains a definition for `%s'".printf (current_symbol.get_full_name (), sig.name));
+                               return;
+                       }
+                       sig.symbol = new Symbol (node = sig);
+                       current_symbol.add (sig.name, sig.symbol);
+                       current_symbol = sig.symbol;
+               }
+
+               public override void visit_end_signal (Signal sig) {
+                       if (sig.error) {
+                               /* skip signals with errors */
+                               return;
+                       }
+                       
+                       current_symbol = current_symbol.parent_symbol;
+               }
+
+               public override void visit_begin_constructor (Constructor c) {
+                       c.symbol = new Symbol (node = c);
+                       c.symbol.parent_symbol = current_symbol;
+                       current_symbol = c.symbol;
+               }
+
+               public override void visit_end_constructor (Constructor c) {
+                       current_symbol = current_symbol.parent_symbol;
+               }
+
+               public override void visit_begin_destructor (Destructor d) {
+                       d.symbol = new Symbol (node = d);
+                       d.symbol.parent_symbol = current_symbol;
+                       current_symbol = d.symbol;
+               }
+
+               public override void visit_end_destructor (Destructor d) {
+                       current_symbol = current_symbol.parent_symbol;
+               }
+
                public override void visit_begin_block (Block b) {
                        b.symbol = new Symbol (node = b);
                        b.symbol.parent_symbol = current_symbol;
index 7579246..7711113 100644 (file)
@@ -27,37 +27,14 @@ namespace Vala {
                public string namespace_name { get; construct; }
                public string type_name { get; construct; }
                public SourceReference source_reference { get; construct; }
-               bool _own;
-               public bool own {
-                       get {
-                               return _own;
-                       }
-                       set {
-                               _own = value;
-                       }
-               }
-               int _array;
-               public bool array {
-                       get {
-                               return _array;
-                       }
-                       set {
-                               _array = value;
-                       }
-               }
-               int _array_own;
-               public bool array_own {
-                       get {
-                               return _array_own;
-                       }
-                       set {
-                               _array_own = value;
-                       }
-               }
+               public bool is_ref { get; set; }
+               public bool is_weak { get; set; }
+               public bool is_out { get; set; }
+               public bool array { get; set; }
+               public bool array_own { get; set; }
+               public bool non_null { get; set; }
                public Type_ type;
                public TypeParameter type_parameter;
-               public bool is_ref;
-               public bool is_out;
 
                List<TypeReference> type_argument_list;
 
diff --git a/vala/vala/valatyperegisterfunction.vala b/vala/vala/valatyperegisterfunction.vala
new file mode 100644 (file)
index 0000000..63bc274
--- /dev/null
@@ -0,0 +1,68 @@
+/* valatyperegisterfunction.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public abstract class TypeRegisterFunction : CCodeFunction {
+               public void init_from_type () {
+                       name = "%s_get_type".printf (get_type_declaration ().get_lower_case_cname (null));
+                       return_type = "GType";
+
+                       var type_block = new CCodeBlock ();
+                       var cdecl = new CCodeDeclaration (type_name = "GType");
+                       cdecl.add_declarator (new CCodeVariableDeclarator (name = "g_define_type_id", initializer = new CCodeConstant (name = "0")));
+                       cdecl.modifiers = CCodeModifiers.STATIC;
+                       type_block.add_statement (cdecl);
+                       
+                       var cond = new CCodeFunctionCall (call = new CCodeIdentifier (name = "G_UNLIKELY"));
+                       cond.add_argument (new CCodeBinaryExpression (operator = CCodeBinaryOperator.EQUALITY, left = new CCodeIdentifier (name = "g_define_type_id"), right = new CCodeConstant (name = "0")));
+                       var type_init = new CCodeBlock ();
+                       var ctypedecl = new CCodeDeclaration (type_name = "const GTypeInfo");
+                       ctypedecl.modifiers = CCodeModifiers.STATIC;
+                       ctypedecl.add_declarator (new CCodeVariableDeclarator (name = "g_define_type_info", initializer = new CCodeConstant (name = "{ sizeof (%s), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) %s, (GClassFinalizeFunc) NULL, NULL, %s, 0, (GInstanceInitFunc) %s }".printf (get_type_struct_name (), get_class_init_func_name (), get_instance_struct_size (), get_instance_init_func_name ()))));
+                       type_init.add_statement (ctypedecl);
+                       var reg_call = new CCodeFunctionCall (call = new CCodeIdentifier (name = "g_type_register_static"));
+                       reg_call.add_argument (new CCodeIdentifier (name = get_parent_type_name ()));
+                       reg_call.add_argument (new CCodeConstant (name = "\"%s\"".printf (get_type_declaration ().get_cname ())));
+                       reg_call.add_argument (new CCodeIdentifier (name = "&g_define_type_info"));
+                       reg_call.add_argument (new CCodeConstant (name = "0"));
+                       type_init.add_statement (new CCodeExpressionStatement (expression = new CCodeAssignment (left = new CCodeIdentifier (name = "g_define_type_id"), right = reg_call)));
+                       var cif = new CCodeIfStatement (condition = cond, true_statement = type_init);
+                       type_block.add_statement (cif);
+                       type_block.add_statement (new CCodeReturnStatement (return_expression = new CCodeIdentifier (name = "g_define_type_id")));
+
+                       block = type_block;
+               }
+               
+               public abstract Type_ get_type_declaration ();
+               public abstract ref string get_type_struct_name ();
+               public abstract ref string get_class_init_func_name ();
+               public abstract ref string get_instance_struct_size ();
+               public abstract ref string get_instance_init_func_name ();
+               public abstract ref string get_parent_type_name ();
+               
+               public ref CCodeFunction get_declaration () {
+                       return new CCodeFunction (name = name, return_type = return_type);
+               }
+       }
+}
index 9338360..b53a923 100644 (file)
@@ -92,6 +92,14 @@ public struct int64 {
 public struct uint64 {
 }
 
+[CCode (cname = "float", cheader_filename = "glib.h")]
+public struct float {
+}
+
+[CCode (cname = "double", cheader_filename = "glib.h")]
+public struct double {
+}
+
 [CCode (cname = "gunichar", cheader_filename = "glib.h")]
 public struct unichar {
        [CCode (cname = "g_unichar_isalnum")]
@@ -105,32 +113,6 @@ public struct unichar {
 }
 
 [ReferenceType ()]
-[AllowPointerArithmetic ()]
-[CCode (cname = "char", cheader_filename = "string.h,glib.h")]
-public struct astring {
-       [CCode (cname = "g_str_has_suffix")]
-       public bool has_suffix (string suffix);
-       [CCode (cname = "g_strdup_printf")]
-       public ref astring printf (...);
-       [CCode (cname = "g_ascii_strup")]
-       public ref astring up (long len /* = -1 */);
-       [CCode (cname = "g_ascii_strdown")]
-       public ref astring down (long len /* = -1 */);
-       [CCode (cname = "g_strconcat")]
-       public ref astring concat (string string2);
-       [CCode (cname = "g_strdup")]
-       public ref astring dup ();
-       [CCode (cname = "g_strndup")]
-       public ref astring ndup (int n);
-       [CCode (cname = "strlen")]
-       public int len ();
-       [CCode (cname = "g_strcompress")]
-       public ref astring compress ();
-       [CCode (cname = "strcmp")]
-       public int cmp ();
-}
-
-[ReferenceType ()]
 [CCode (cname = "char", cheader_filename = "string.h,glib.h")]
 public struct string {
        [CCode (cname = "g_str_has_suffix")]
@@ -144,7 +126,7 @@ public struct string {
        [CCode (cname = "g_strcompress")]
        public ref string compress ();
        [CCode (cname = "g_strsplit")]
-       public ref string[] split (string delimiter, int max_tokens /* = 0 */);
+       public ref string[] split (string delimiter, int max_tokens = 0);
        
        [CCode (cname = "g_utf8_next_char")]
        public string next_char ();
@@ -158,12 +140,12 @@ public struct string {
        [CCode (cname = "g_utf8_prev_char")]
        public string prev_char ();
        [CCode (cname = "g_utf8_strlen")]
-       public long len (int max /*= -1*/);
+       public long len (int max = -1);
        [CCode (cname = "g_utf8_strchr")]
        public string chr (int len, unichar c);
        
        [CCode (cname = "g_utf8_strup")]
-       public ref string up (int len /*= -1*/);
+       public ref string up (int len = -1);
        [CCode (cname = "g_utf8_collate")]
        public int collate (string str2);
 }