+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,
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);
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 ();
}
}
valabreakstatement.c \
valabreakstatement.h \
valabreakstatement.vala \
+ valacallback.c \
+ valacallback.h \
+ valacallback.vala \
valacastexpression.c \
valacastexpression.h \
valacastexpression.vala \
valaclass.c \
valaclass.h \
valaclass.vala \
+ valaclassregisterfunction.c \
+ valaclassregisterfunction.h \
+ valaclassregisterfunction.vala \
valacodecontext.c \
valacodecontext.h \
valacodecontext.vala \
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 \
valafield.c \
valafield.h \
valafield.vala \
+ valaflags.c \
+ valaflags.h \
+ valaflags.vala \
+ valaflagsvalue.c \
+ valaflagsvalue.h \
+ valaflagsvalue.vala \
valaforeachstatement.c \
valaforeachstatement.h \
valaforeachstatement.vala \
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 \
valaproperty.c \
valaproperty.h \
valaproperty.vala \
+ valarealliteral.c \
+ valarealliteral.h \
+ valarealliteral.vala \
valareport.c \
valareport.h \
valareport.vala \
valasemanticanalyzer.c \
valasemanticanalyzer.h \
valasemanticanalyzer.vala \
+ valasignal.c \
+ valasignal.h \
+ valasignal.vala \
valasimplename.c \
valasimplename.h \
valasimplename.vala \
valatypereference.c \
valatypereference.h \
valatypereference.vala \
+ valatyperegisterfunction.c \
+ valatyperegisterfunction.h \
+ valatyperegisterfunction.vala \
valaunaryexpression.c \
valaunaryexpression.h \
valaunaryexpression.vala \
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;
%token BITWISE_AND "&"
%token OP_OR "||"
%token OP_AND "&&"
+%token TILDE "~"
%token ASSIGN "="
%token PLUS "+"
%token PRIVATE "private"
%token REF "ref"
%token SET "set"
+%token SIGNAL "signal"
%token STATIC "static"
%token STRUCT "struct"
%token RETURN "return"
%token <str> IDENTIFIER "identifier"
%token <str> INTEGER_LITERAL "integer"
+%token <str> REAL_LITERAL "real"
%token <str> CHARACTER_LITERAL "character"
%token <str> STRING_LITERAL "string"
%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
%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
%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
%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
%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
%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
{
$$ = 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)));
;
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);
}
;
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
/* 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
{
}
;
+opt_op_neg
+ : /* empty */
+ {
+ $$ = FALSE;
+ }
+ | OP_NEG
+ {
+ $$ = TRUE;
+ }
+ ;
+
expression_statement
: comment statement_expression SEMICOLON
{
;
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)));
}
;
}
}
| flags_declaration
+ {
+ /* skip declarations with errors */
+ if ($1 != NULL) {
+ vala_namespace_add_flags (current_namespace, $1);
+ }
+ }
| field_declaration
{
/* skip declarations with errors */
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
;
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;
}
;
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;
}
}
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);
}
}
;
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));
}
;
}
;
+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
{
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));
}
;
}
;
+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
{
flags_declaration
: comment opt_attributes opt_access_modifier FLAGS IDENTIFIER flags_body
+ {
+ $$ = vala_flags_new ($5, src_com (@5, $1));
+ }
;
flags_body
;
type_argument
- : opt_ref type
- {
- $$ = $2;
- }
+ : type
;
%%
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})
%%
"&&" { uploc; return OP_AND; }
"&" { uploc; return BITWISE_AND; }
"^" { uploc; return CARRET; }
+"~" { uploc; return TILDE; }
"=" { uploc; return ASSIGN; }
"+" { uploc; return PLUS; }
"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; }
"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; }
#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>
#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>
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) {
visitor.visit_assignment (this);
}
}
+
+ public enum AssignmentOperator {
+ SIMPLE,
+ BITWISE_OR,
+ BITWISE_AND,
+ BITWISE_XOR,
+ ADD,
+ SUB,
+ MUL,
+ DIV,
+ PERCENT,
+ SHIFT_LEFT,
+ SHIFT_RIGHT
+ }
}
--- /dev/null
+/* 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_ {
+ }
+}
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;
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);
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);
}
}
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 () {
--- /dev/null
+/* 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_");
+ }
+ }
+}
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) {
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);
}
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))));
}
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) {
}
}
+ /* 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"));
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) {
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 ();
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);
}
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;
}
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);
}
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) {
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) {
}
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;
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) {
}
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) {
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;
}
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);
}
}
}
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) {
}
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) {
}
public virtual void visit_integer_literal (IntegerLiteral expr) {
}
+ public virtual void visit_real_literal (RealLiteral expr) {
+ }
+
public virtual void visit_string_literal (StringLiteral expr) {
}
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;
--- /dev/null
+/* 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);
+ }
+ }
+}
--- /dev/null
+/* 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);
+ }
+ }
+}
}
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 () {
--- /dev/null
+/* 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;
+ }
+ }
+}
--- /dev/null
+/* 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;
+ }
+ }
+}
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));
--- /dev/null
+/* 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);
+ }
+ }
+}
+
+
+
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));
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;
}
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) {
--- /dev/null
+/* 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";
+ }
+ }
+}
List<Interface> interfaces;
List<Struct> structs;
List<Enum> enums;
+ List<Flags> flags_;
List<Field> fields;
List<Method> methods;
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 ();
en.accept (visitor);
}
+ foreach (Flags fl in flags_) {
+ fl.accept (visitor);
+ }
+
foreach (Field f in fields) {
f.accept (visitor);
}
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
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 ('_');
}
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 ();
}
}
}
--- /dev/null
+/* 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);
+ }
+ }
+}
}
}
+ 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) {
}
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;
}
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;
}
}
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;
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) {
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) {
|| 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
--- /dev/null
+/* 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);
+ }
+ }
+}
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;
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;
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 ();
}
}
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 () {
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;
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;
--- /dev/null
+/* 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);
+ }
+ }
+}
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")]
}
[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")]
[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 ();
[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);
}