Commit bb3a6298 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

support interfaces, adapt to Class/Struct/Type changes, improve error

2006-05-31  Jürg Billeter  <j@bitron.ch>

	* vala/parser.y: support interfaces, adapt to Class/Struct/Type changes,
	  improve error handling
	* vala/valacodevisitor.vala: support interfaces
	* vala/valasymbolbuilder.vala: improve error handling
	* vala/valasymbolresolver.vala: use operators to compare strings
	* vala/valasemanticanalyzer.vala: improve error handling, convert method
	  argument and type mismatch warnings to errors, add skeleton for
	  expressoin type checks, support string comparison operators
	* vala/valacodegenerator.vala: fix warning, create structs for
	  interfaces, adapt to Class/Struct/Type changes, refactor and fix code
	  in visit_simple_name and visit_member_access, use operators to compare
	  strings
	* vala/valainterfacewriter.vala: use operators to compare strings
	* vala/valasourcefile.vala: fix warnings
	* vala/valaclass.vala: don't inherit from Struct
	* vala/valacodenode.vala: add error flag
	* vala/valaconstant.vala: add get_cname method
	* vala/valaenum.vala: override get_upper_case_cname method
	* vala/valaenumvalue.vala: adapt to Class/Struct/Type changes
	* vala/valafield.vala: use operators to compare strings
	* vala/valainterface.vala
	* vala/valainvocationexpression.vala: add add_argument method
	* vala/valamethod.vala: adapt to Class/Struct/Type changes, use
	  operators to compare strings
	* vala/valanamespace.vala: support interfaces, use operators to compare
	  strings
	* vala/valastringliteral.vala: fix warning
	* vala/valastruct.vala: inline visit_children method, use operators to
	  compare strings
	* vala/valatype.vala: add abstract get_lower_case_cname method
	* vala/valatypereference.vala: add to_string method
	* vala/vala.h: update
	* vala/Makefile.am: update
	* vapi/glib-2.0.vala: small fixes

svn path=/trunk/; revision=38
parent 0ae4d550
2006-05-31 Jürg Billeter <j@bitron.ch>
* vala/parser.y: support interfaces, adapt to Class/Struct/Type changes,
improve error handling
* vala/valacodevisitor.vala: support interfaces
* vala/valasymbolbuilder.vala: improve error handling
* vala/valasymbolresolver.vala: use operators to compare strings
* vala/valasemanticanalyzer.vala: improve error handling, convert method
argument and type mismatch warnings to errors, add skeleton for
expressoin type checks, support string comparison operators
* vala/valacodegenerator.vala: fix warning, create structs for
interfaces, adapt to Class/Struct/Type changes, refactor and fix code
in visit_simple_name and visit_member_access, use operators to compare
strings
* vala/valainterfacewriter.vala: use operators to compare strings
* vala/valasourcefile.vala: fix warnings
* vala/valaclass.vala: don't inherit from Struct
* vala/valacodenode.vala: add error flag
* vala/valaconstant.vala: add get_cname method
* vala/valaenum.vala: override get_upper_case_cname method
* vala/valaenumvalue.vala: adapt to Class/Struct/Type changes
* vala/valafield.vala: use operators to compare strings
* vala/valainterface.vala
* vala/valainvocationexpression.vala: add add_argument method
* vala/valamethod.vala: adapt to Class/Struct/Type changes, use
operators to compare strings
* vala/valanamespace.vala: support interfaces, use operators to compare
strings
* vala/valastringliteral.vala: fix warning
* vala/valastruct.vala: inline visit_children method, use operators to
compare strings
* vala/valatype.vala: add abstract get_lower_case_cname method
* vala/valatypereference.vala: add to_string method
* vala/vala.h: update
* vala/Makefile.am: update
* vapi/glib-2.0.vala: small fixes
2006-05-26 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: fix member access to namespaces
......
......@@ -107,6 +107,9 @@ libvala_la_SOURCES = \
valaintegerliteral.c \
valaintegerliteral.h \
valaintegerliteral.vala \
valainterface.c \
valainterface.h \
valainterface.vala \
valainterfacewriter.c \
valainterfacewriter.h \
valainterfacewriter.vala \
......
......@@ -40,7 +40,9 @@
static ValaSourceFile *current_source_file;
static ValaNamespace *current_namespace;
static ValaClass *current_class;
static ValaStruct *current_struct;
static ValaInterface *current_interface;
typedef enum {
VALA_MODIFIER_NONE,
......@@ -71,6 +73,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
ValaNamespace *namespace;
ValaClass *class;
ValaStruct *struct_;
ValaInterface *interface;
ValaEnum *enum_;
ValaEnumValue *enum_value;
ValaConstant *constant;
......@@ -251,6 +254,12 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
%type <property_accessor> set_accessor_declaration
%type <struct_> struct_declaration
%type <struct_> struct_header
%type <interface> interface_declaration
%type <method> interface_method_declaration
%type <property> interface_property_declaration
%type <property_accessor> interface_get_accessor_declaration
%type <property_accessor> opt_interface_set_accessor_declaration
%type <property_accessor> interface_set_accessor_declaration
%type <enum_> enum_declaration
%type <list> enum_body
%type <list> opt_enum_member_declarations
......@@ -670,6 +679,10 @@ opt_expression
expression
: conditional_expression
| assignment
| error
{
$$ = NULL;
}
;
statement
......@@ -929,25 +942,46 @@ namespace_member_declarations
namespace_member_declaration
: class_declaration
{
vala_namespace_add_class (current_namespace, $1);
/* skip declarations with errors */
if ($1 != NULL) {
vala_namespace_add_class (current_namespace, $1);
}
}
| struct_declaration
{
vala_namespace_add_struct (current_namespace, $1);
/* skip declarations with errors */
if ($1 != NULL) {
vala_namespace_add_struct (current_namespace, $1);
}
}
| interface_declaration
{
/* skip declarations with errors */
if ($1 != NULL) {
vala_namespace_add_interface (current_namespace, $1);
}
}
| enum_declaration
{
vala_namespace_add_enum (current_namespace, $1);
/* skip declarations with errors */
if ($1 != NULL) {
vala_namespace_add_enum (current_namespace, $1);
}
}
| flags_declaration
| field_declaration
{
vala_namespace_add_field (current_namespace, $1);
/* skip declarations with errors */
if ($1 != NULL) {
vala_namespace_add_field (current_namespace, $1);
}
}
| method_declaration
{
vala_namespace_add_method (current_namespace, $1);
/* skip declarations with errors */
if ($1 != NULL) {
vala_namespace_add_method (current_namespace, $1);
}
}
;
......@@ -955,22 +989,22 @@ class_declaration
: comment opt_attributes opt_access_modifier opt_modifiers CLASS IDENTIFIER opt_type_parameter_list opt_class_base
{
GList *l;
current_struct = VALA_STRUCT (vala_class_new ($6, src_com (@6, $1)));
VALA_CODE_NODE(current_struct)->attributes = $2;
current_class = vala_class_new ($6, src_com (@6, $1));
VALA_CODE_NODE(current_class)->attributes = $2;
if ($3 != 0) {
VALA_TYPE_(current_struct)->access = $3;
VALA_TYPE_(current_class)->access = $3;
}
for (l = $7; l != NULL; l = l->next) {
vala_struct_add_type_parameter (current_struct, l->data);
vala_class_add_type_parameter (current_class, l->data);
}
for (l = $8; l != NULL; l = l->next) {
vala_class_add_base_type (VALA_CLASS (current_struct), l->data);
vala_class_add_base_type (current_class, l->data);
}
}
class_body
{
$$ = VALA_CLASS (current_struct);
current_struct = NULL;
$$ = current_class;
current_class = NULL;
}
;
......@@ -1074,19 +1108,31 @@ class_member_declarations
class_member_declaration
: constant_declaration
{
vala_struct_add_constant (current_struct, $1);
/* skip declarations with errors */
if ($1 != NULL) {
vala_class_add_constant (current_class, $1);
}
}
| field_declaration
{
vala_struct_add_field (current_struct, $1);
/* skip declarations with errors */
if ($1 != NULL) {
vala_class_add_field (current_class, $1);
}
}
| method_declaration
{
vala_struct_add_method (current_struct, $1);
/* skip declarations with errors */
if ($1 != NULL) {
vala_class_add_method (current_class, $1);
}
}
| property_declaration
{
vala_class_add_property (VALA_CLASS (current_struct), $1);
/* skip declarations with errors */
if ($1 != NULL) {
vala_class_add_property (current_class, $1);
}
}
;
......@@ -1348,16 +1394,29 @@ struct_member_declarations
struct_member_declaration
: field_declaration
{
vala_struct_add_field (current_struct, $1);
/* skip declarations with errors */
if ($1 != NULL) {
vala_struct_add_field (current_struct, $1);
}
}
| method_declaration
{
vala_struct_add_method (current_struct, $1);
/* skip declarations with errors */
if ($1 != NULL) {
vala_struct_add_method (current_struct, $1);
}
}
;
interface_declaration
: comment opt_attributes opt_access_modifier INTERFACE IDENTIFIER interface_body
: comment opt_attributes opt_access_modifier INTERFACE IDENTIFIER
{
current_interface = vala_interface_new ($5, src_com (@5, $1));
}
interface_body
{
$$ = current_interface;
}
;
interface_body
......@@ -1375,7 +1434,77 @@ interface_member_declarations
;
interface_member_declaration
: method_declaration
: interface_method_declaration
{
/* skip declarations with errors */
if ($1 != NULL) {
vala_interface_add_method (current_interface, $1);
}
}
| interface_property_declaration
{
/* skip declarations with errors */
if ($1 != NULL) {
vala_interface_add_property (current_interface, $1);
}
}
;
interface_method_declaration
: comment opt_attributes opt_ref type identifier_or_new OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON
{
GList *l;
$$ = vala_method_new ($5, $4, src_com (@5, $1));
$$->access = VALA_MEMBER_ACCESSIBILITY_PUBLIC;
$$->is_abstract = TRUE;
VALA_CODE_NODE($$)->attributes = $2;
for (l = $7; 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
{
$$ = vala_property_new ($5, $4, $7, $8, src_com (@4, $1));
}
| comment opt_attributes opt_ref type IDENTIFIER OPEN_BRACE interface_set_accessor_declaration CLOSE_BRACE
{
$$ = vala_property_new ($5, $4, NULL, $7, src_com (@4, $1));
}
;
interface_get_accessor_declaration
: opt_attributes GET SEMICOLON
{
$$ = vala_property_accessor_new (TRUE, FALSE, FALSE, NULL, src (@2));
}
;
opt_interface_set_accessor_declaration
: /* empty */
{
$$ = NULL;
}
| interface_set_accessor_declaration
;
interface_set_accessor_declaration
: opt_attributes SET SEMICOLON
{
$$ = vala_property_accessor_new (FALSE, TRUE, FALSE, NULL, src (@2));
}
| opt_attributes SET CONSTRUCT SEMICOLON
{
$$ = vala_property_accessor_new (FALSE, TRUE, TRUE, NULL, src (@2));
}
| opt_attributes CONSTRUCT SEMICOLON
{
$$ = vala_property_accessor_new (FALSE, FALSE, TRUE, NULL, src (@2));
}
;
enum_declaration
......@@ -1606,7 +1735,8 @@ extern int yylineno;
static void
yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg)
{
printf ("%s:%d.%d-%d.%d: %s\n", vala_source_file_get_filename (current_source_file), locp->first_line, locp->first_column, locp->last_line, locp->last_column, msg);
ValaSourceReference *source_reference = vala_source_reference_new (current_source_file, locp->first_line, locp->first_column, locp->last_line, locp->last_column);
vala_report_error (source_reference, msg);
}
void
......
......@@ -24,6 +24,7 @@
#include <vala/valaifstatement.h>
#include <vala/valainitializerlist.h>
#include <vala/valaintegerliteral.h>
#include <vala/valainterface.h>
#include <vala/valainvocationexpression.h>
#include <vala/valaliteral.h>
#include <vala/valaliteralexpression.h>
......
......@@ -23,19 +23,57 @@
using GLib;
namespace Vala {
public class Class : Struct {
public class Class : Type_ {
List<string> type_parameters;
public List<TypeReference> base_types;
public Class base_class;
public bool is_abstract;
List<Constant> constants;
List<Field> fields;
List<Method> methods;
List<Property> properties;
public string cname;
public string lower_case_csuffix;
public bool has_private_fields;
public static ref Class new (string name, SourceReference source) {
return (new Class (name = name, source_reference = source));
}
public void add_base_type (TypeReference type) {
base_types.append (type);
}
public void add_type_parameter (TypeParameter p) {
type_parameters.append (p);
p.type = this;
}
public static ref Class new (string name, SourceReference source) {
return (new Class (name = name, source_reference = source));
public void add_constant (Constant c) {
constants.append (c);
}
public void add_field (Field f) {
fields.append (f);
if (f.access == MemberAccessibility.PRIVATE) {
has_private_fields = true;
}
}
public ref List<Field> get_fields () {
return fields.copy ();
}
public void add_method (Method m) {
return_if_fail (m != null);
methods.append (m);
}
public ref List<Method> get_methods () {
return methods.copy ();
}
public void add_property (Property prop) {
......@@ -60,7 +98,21 @@ namespace Vala {
type.accept (visitor);
}
visit_children (visitor);
foreach (TypeParameter p in type_parameters) {
p.accept (visitor);
}
foreach (Field f in fields) {
f.accept (visitor);
}
foreach (Constant c in constants) {
c.accept (visitor);
}
foreach (Method m in methods) {
m.accept (visitor);
}
foreach (Property prop in properties) {
prop.accept (visitor);
......@@ -68,9 +120,75 @@ namespace Vala {
visitor.visit_end_class (this);
}
public override string get_cname () {
if (cname == null) {
cname = "%s%s".printf (@namespace.get_cprefix (), name);
}
return cname;
}
public void set_cname (string cname) {
this.cname = cname;
}
public string get_lower_case_csuffix () {
if (lower_case_csuffix == null) {
lower_case_csuffix = Namespace.camel_case_to_lower_case (name);
}
return lower_case_csuffix;
}
public void set_lower_case_csuffix (string csuffix) {
this.lower_case_csuffix = csuffix;
}
public override ref string get_lower_case_cname (string infix) {
if (infix == null) {
infix = "";
}
return "%s%s%s".printf (@namespace.get_lower_case_cprefix (), infix, get_lower_case_csuffix ());
}
public override ref string get_upper_case_cname (string infix) {
return get_lower_case_cname (infix).up (-1);
}
public override bool is_reference_type () {
return true;
}
void process_ccode_attribute (Attribute a) {
foreach (NamedArgument arg in a.args) {
if (arg.name == "cname") {
/* this will already be checked during semantic analysis */
if (arg.argument is LiteralExpression) {
var lit = ((LiteralExpression) arg.argument).literal;
if (lit is StringLiteral) {
set_cname (((StringLiteral) lit).eval ());
}
}
} else if (arg.name == "cheader_filename") {
/* this will already be checked during semantic analysis */
if (arg.argument is LiteralExpression) {
var lit = ((LiteralExpression) arg.argument).literal;
if (lit is StringLiteral) {
var val = ((StringLiteral) lit).eval ();
foreach (string filename in val.split (",", 0)) {
cheader_filenames.append (filename);
}
}
}
}
}
}
public void process_attributes () {
foreach (Attribute a in attributes) {
if (a.name == "CCode") {
process_ccode_attribute (a);
}
}
}
}
}
<
......@@ -36,7 +36,7 @@ namespace Vala {
CCodeFragment source_type_member_definition;
CCodeStruct instance_struct;
CCodeStruct class_struct;
CCodeStruct type_struct;
CCodeStruct instance_priv_struct;
CCodeEnum prop_enum;
CCodeEnum cenum;
......@@ -110,7 +110,8 @@ namespace Vala {
var i = filename;
while (i.len (-1) > 0) {
var c = i.get_char ();
if (c.isalnum () && c < 128) {
/* FIXME: remove explicit cast when implicit cast works */
if (c.isalnum () && c < (unichar) 128) {
define.append_unichar (c.toupper ());
} else {
define.append_c ('_');
......@@ -184,7 +185,7 @@ namespace Vala {
current_symbol = cl.symbol;
instance_struct = new CCodeStruct (name = "_%s".printf (cl.get_cname ()));
class_struct = new CCodeStruct (name = "_%sClass".printf (cl.get_cname ()));
type_struct = new CCodeStruct (name = "_%sClass".printf (cl.get_cname ()));
instance_priv_struct = new CCodeStruct (name = "_%sPrivate".printf (cl.get_cname ()));
prop_enum = new CCodeEnum ();
prop_enum.add_value ("%s_DUMMY_PROPERTY".printf (cl.get_upper_case_cname (null)), null);
......@@ -213,19 +214,19 @@ namespace Vala {
if (cl.source_reference.file.cycle == null) {
header_type_declaration.append (new CCodeTypeDefinition (type_name = "struct %s".printf (instance_struct.name), typedef_name = cl.get_cname ()));
header_type_declaration.append (new CCodeTypeDefinition (type_name = "struct %s".printf (class_struct.name), typedef_name = "%sClass".printf (cl.get_cname ())));
header_type_declaration.append (new CCodeTypeDefinition (type_name = "struct %s".printf (type_struct.name), typedef_name = "%sClass".printf (cl.get_cname ())));
}
header_type_declaration.append (new CCodeTypeDefinition (type_name = "struct %s".printf (instance_priv_struct.name), typedef_name = "%sPrivate".printf (cl.get_cname ())));
instance_struct.add_field (cl.base_class.get_cname (), "parent");
instance_struct.add_field ("%sPrivate *".printf (cl.get_cname ()), "priv");
class_struct.add_field ("%sClass".printf (cl.base_class.get_cname ()), "parent");
type_struct.add_field ("%sClass".printf (cl.base_class.get_cname ()), "parent");
if (cl.source_reference.comment != null) {
header_type_definition.append (new CCodeComment (text = cl.source_reference.comment));
}
header_type_definition.append (instance_struct);
header_type_definition.append (class_struct);
header_type_definition.append (type_struct);
source_type_member_declaration.append (instance_priv_struct);
macro = "(G_TYPE_INSTANCE_GET_PRIVATE ((o), %s, %sPrivate))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ());
source_type_member_declaration.append (new CCodeMacroReplacement (name = "%s_GET_PRIVATE(o)".printf (cl.get_upper_case_cname (null)), replacement = macro));
......@@ -312,15 +313,16 @@ namespace Vala {
if (prop.type_reference.type is Class) {
cspec.call = new CCodeIdentifier (name = "g_param_spec_object");
cspec.add_argument (new CCodeIdentifier (name = prop.type_reference.type.get_upper_case_cname ("TYPE_")));
} else if (prop.type_reference.type_name.collate ("string") == 0) {
} else if (prop.type_reference.type_name == "string") {
cspec.call = new CCodeIdentifier (name = "g_param_spec_string");
cspec.add_argument (new CCodeConstant (name = "NULL"));
} else if (prop.type_reference.type_name.collate ("int") == 0 || prop.type_reference.type is Enum) {
} else if (prop.type_reference.type_name == "int"
|| prop.type_reference.type is Enum) {
cspec.call = new CCodeIdentifier (name = "g_param_spec_int");
cspec.add_argument (new CCodeConstant (name = "G_MININT"));
cspec.add_argument (new CCodeConstant (name = "G_MAXINT"));
cspec.add_argument (new CCodeConstant (name = "0"));
} else if (prop.type_reference.type_name.collate ("bool") == 0) {
} else if (prop.type_reference.type_name == "bool") {
cspec.call = new CCodeIdentifier (name = "g_param_spec_boolean");
cspec.add_argument (new CCodeConstant (name = "FALSE"));
} else {
......@@ -399,11 +401,12 @@ namespace Vala {
var csetcall = new CCodeFunctionCall ();
if (prop.type_reference.type is Class) {
csetcall.call = new CCodeIdentifier (name = "g_value_set_object");
} else if (prop.type_reference.type_name.collate ("string") == 0) {
} else if (prop.type_reference.type_name == "string") {
csetcall.call = new CCodeIdentifier (name = "g_value_set_string");
} else if (prop.type_reference.type_name.collate ("int") == 0 || prop.type_reference.type is Enum) {
} else if (prop.type_reference.type_name == "int"
|| prop.type_reference.type is Enum) {
csetcall.call = new CCodeIdentifier (name = "g_value_set_int");
} else if (prop.type_reference.type_name.collate ("bool") == 0) {
} else if (prop.type_reference.type_name == "bool") {
csetcall.call = new CCodeIdentifier (name = "g_value_set_boolean");
} else {
csetcall.call = new CCodeIdentifier (name = "g_value_set_pointer");
......@@ -444,11 +447,12 @@ namespace Vala {
var cgetcall = new CCodeFunctionCall ();
if (prop.type_reference.type is Class) {
cgetcall.call = new CCodeIdentifier (name = "g_value_get_object");
} else if (prop.type_reference.type_name.collate ("string") == 0) {
} else if (prop.type_reference.type_name == "string") {
cgetcall.call = new CCodeIdentifier (name = "g_value_dup_string");
} else if (prop.type_reference.type_name.collate ("int") == 0 || prop.type_reference.type is Enum) {
} else if (prop.type_reference.type_name == "int"
|| prop.type_reference.type is Enum) {
cgetcall.call = new CCodeIdentifier (name = "g_value_get_int");
} else if (prop.type_reference.type_name.collate ("bool") == 0) {
} else if (prop.type_reference.type_name == "bool") {
cgetcall.call = new CCodeIdentifier (name = "g_value_get_boolean");
} else {
cgetcall.call = new CCodeIdentifier (name = "g_value_get_pointer");
......@@ -474,6 +478,42 @@ namespace Vala {
}
header_type_definition.append (instance_struct);
}
public override void visit_begin_interface (Interface iface) {
current_symbol = iface.symbol;
type_struct = new CCodeStruct (name = "_%sInterface".printf (iface.get_cname ()));
header_type_declaration.append (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (iface.get_lower_case_cname (null));
header_type_declaration.append (new CCodeMacroReplacement (name = iface.get_upper_case_cname ("TYPE_"), replacement = macro));
macro = "(G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, %s))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_cname ());
header_type_declaration.append (new CCodeMacroReplacement (name = "%s(obj)".printf (iface.get_upper_case_cname (null)), replacement = macro));
macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (iface.get_upper_case_cname ("TYPE_"));
header_type_declaration.append (new CCodeMacroReplacement (name = "%s(obj)".printf (iface.get_upper_case_cname ("IS_")), replacement = macro));
macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %sInterface))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_cname ());
header_type_declaration.append (new CCodeMacroReplacement (name = "%s_GET_INTERFACE(obj)".printf (iface.get_upper_case_cname (null)), replacement = macro));
header_type_declaration.append (new CCodeNewline ());
if (iface.source_reference.file.cycle == null) {
header_type_declaration.append (new CCodeTypeDefinition (type_name = "struct _%s".printf (iface.get_cname ()), typedef_name = iface.get_cname ()));
header_type_declaration.append (new CCodeTypeDefinition (type_name = "struct %s".printf (type_struct.name), typedef_name = "%sInterface".printf (iface.get_cname ())));
}
type_struct.add_field ("GTypeInterface", "parent");
if (iface.source_reference.comment != null) {
header_type_definition.append (new CCodeComment (text = iface.source_reference.comment));
}
header_type_definition.append (type_struct);
}
public override void visit_end_interface (Interface iface) {
}
public override void visit_begin_enum (Enum en) {
cenum = new CCodeEnum (name = en.get_cname ());
......@@ -489,8 +529,8 @@ namespace Vala {
}
public override void visit_constant (Constant c) {
if (c.symbol.parent_symbol.node is Struct) {
var t = (Struct) c.symbol.parent_symbol.node;
if (c.symbol.parent_symbol.node is Type_) {
var t = (Type_) c.symbol.parent_symbol.node;
var cdecl = new CCodeDeclaration (type_name = c.type_reference.get_const_cname ());
var arr = "";
if (c.type_reference.array) {
......@@ -509,8 +549,8 @@ namespace Vala {
if (f.instance) {
instance_priv_struct.add_field (f.type_reference.get_cname (), f.get_cname ());
} else {
if (f.symbol.parent_symbol.node is Struct) {
var t = (Struct) f.symbol.parent_symbol.node;
if (f.symbol.parent_symbol.node is Type_) {
var t = (Type_) f.symbol.parent_symbol.node;
var cdecl = new CCodeDeclaration (type_name = f.type_reference.get_cname ());
cdecl.add_declarator (new CCodeVariableDeclarator (name = "%s_%s".printf (t.get_lower_case_cname (null), f.get_cname ())));
cdecl.modifiers = CCodeModifiers.STATIC;
......@@ -521,7 +561,7 @@ namespace Vala {
}
public override void visit_end_method (Method m) {
if (m.name.collate ("init") == 0) {
if (m.name == "init") {
return;
}
......@@ -530,9 +570,8 @@ namespace Vala {
CCodeFunctionDeclarator vdeclarator = null;
if (m.instance) {
var st = (Struct) m.symbol.parent_symbol.node;
var this_type = new TypeReference ();
this_type.type = st;
this_type.type = (Type_) m.symbol.parent_symbol.node;
if (!m.is_override) {
var cparam = new CCodeFormalParameter (type_name = this_type.get_cname (), name = "self");
function.add_parameter (cparam);
......@@ -546,7 +585,7 @@ namespace Vala {
var vdecl = new CCodeDeclaration (type_name = m.return_type.get_cname ());
vdeclarator = new CCodeFunctionDeclarator (name = m.name);
vdecl.add_declarator (vdeclarator);
class_struct.add_declaration (vdecl);
type_struct.add_declaration (vdecl);
var cparam = new CCodeFormalParameter (type_name = this_type.get_cname (), name = "self");
vdeclarator.add_parameter (cparam);
......@@ -601,9 +640,8 @@ namespace Vala {
var vfunc = new CCodeFunction (name = m.get_cname (), return_type = m.return_type.get_cname ());
var st = (Struct) m.symbol.parent_symbol.node;
var this_type = new TypeReference ();
this_type.type = st;
this_type.type = (Type_) m.symbol.parent_symbol.node;
var cparam = new CCodeFormalParameter (type_name = this_type.get_cname (), name = "self");
vfunc.add_parameter (cparam);
......@@ -630,7 +668,7 @@ namespace Vala {
source_type_member_definition.append (vfunc);
}
if (m.name.collate ("main") == 0) {
if (m.name == "main") {
var cmain = new CCodeFunction (name = "main", return_type = "int");
cmain.add_parameter (new CCodeFormalParameter (type_name = "int", name = "argc"));
cmain.add_parameter (new CCodeFormalParameter (type_name = "char **", name = "argv"));
......@@ -651,16 +689,10 @@ namespace Vala {
}
}
public override void visit_begin_property (Property prop) {
}
public override void visit_end_property (Property prop) {
prop_enum.add_value (prop.get_upper_case_cname (), null);
}
public override void visit_begin_property_accessor (PropertyAccessor acc) {
}
public override void visit_end_property_accessor (PropertyAccessor acc) {
var prop = (Property) acc.symbol.parent_symbol.node;
var cl = (Class) prop.symbol.parent_symbol.node;
......@@ -798,7 +830,7 @@ namespace Vala {
cfor.add_initializer (new CCodeAssignment (left = new CCodeIdentifier (name = it_name), right = (CCodeExpression) stmt.collection.ccodenode));
cfor.add_iterator (new CCodeAssignment (left = new CCodeIdentifier (name = it_name), right = new CCodeBinaryExpression (operator = CCodeBinaryOperator.PLUS, left = new CCodeIdentifier (name = it_name), right = new CCodeConstant (name = "1"))));
cblock.add_statement (cfor);
} else if (stmt.collection.static_type.type.name.collate ("List") == 0) {