From 16122da163cb12969eb2aee2d46cb6d15fb1bd64 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Thu, 18 May 2006 13:57:34 +0000 Subject: [PATCH] support member and access modifiers, static methods process method MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2006-05-18 Jürg Billeter * vala/parser.y: support member and access modifiers, static methods * vala/valaattributeprocessor.vala: process method attributes * vala/valaclass.vala: don't set parent_type member of children * vala/valaconstant.vala: remove unnecessary parent_type member * vala/valafield.vala: remove unnecessary parent_type member * vala/valamethod.vala: support cname attribute * vala/valanamespace.vala: add methods * vala/valaproperty.vala: remove unnecessary parent_type member * vala/valastruct.vala: don't set parent_type member of children svn path=/trunk/; revision=26 --- vala/ChangeLog | 12 +++++++ vala/vala/parser.y | 52 +++++++++++++++++++++++++++ vala/vala/valaattributeprocessor.vala | 4 +++ vala/vala/valaclass.vala | 1 - vala/vala/valaconstant.vala | 1 - vala/vala/valafield.vala | 1 - vala/vala/valamethod.vala | 23 +++++++++++- vala/vala/valanamespace.vala | 9 +++++ vala/vala/valaproperty.vala | 1 - vala/vala/valastruct.vala | 2 -- 10 files changed, 99 insertions(+), 7 deletions(-) diff --git a/vala/ChangeLog b/vala/ChangeLog index c7099112b..1bc83cc77 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,3 +1,15 @@ +2006-05-18 Jürg Billeter + + * vala/parser.y: support member and access modifiers, static methods + * vala/valaattributeprocessor.vala: process method attributes + * vala/valaclass.vala: don't set parent_type member of children + * vala/valaconstant.vala: remove unnecessary parent_type member + * vala/valafield.vala: remove unnecessary parent_type member + * vala/valamethod.vala: support cname attribute + * vala/valanamespace.vala: add methods + * vala/valaproperty.vala: remove unnecessary parent_type member + * vala/valastruct.vala: don't set parent_type member of children + 2006-05-18 Jürg Billeter * vala/parser.y: adapt to BinaryOperator enum changes diff --git a/vala/vala/parser.y b/vala/vala/parser.y index 8325bddea..8a596297f 100644 --- a/vala/vala/parser.y +++ b/vala/vala/parser.y @@ -42,6 +42,14 @@ static ValaSourceFile *current_source_file; static ValaNamespace *current_namespace; static ValaStruct *current_struct; +typedef enum { + VALA_MODIFIER_NONE, + VALA_MODIFIER_ABSTRACT = 1 << 0, + VALA_MODIFIER_OVERRIDE = 1 << 1, + VALA_MODIFIER_STATIC = 1 << 2, + VALA_MODIFIER_VIRTUAL = 1 << 3, +} ValaModifier; + int yylex (YYSTYPE *yylval_param, YYLTYPE *yylloc_param, ValaParser *parser); static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); %} @@ -224,6 +232,11 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); %type return_statement %type namespace_declaration %type class_declaration +%type opt_access_modifier +%type access_modifier +%type opt_modifiers +%type modifiers +%type modifier %type opt_class_base %type class_base %type type_list @@ -906,6 +919,9 @@ namespace_member_declaration vala_namespace_add_field (current_namespace, $1); } | method_declaration + { + vala_namespace_add_method (current_namespace, $1); + } ; class_declaration @@ -929,29 +945,59 @@ class_declaration opt_access_modifier : /* empty */ + { + $$ = 0; + } | access_modifier ; access_modifier : PUBLIC + { + $$ = VALA_MEMBER_ACCESSIBILITY_PUBLIC; + } | PRIVATE + { + $$ = VALA_MEMBER_ACCESSIBILITY_PRIVATE; + } ; opt_modifiers : /* empty */ + { + $$ = VALA_MODIFIER_NONE; + } | modifiers ; modifiers : modifier | modifiers modifier + { + if (($1 & $2) == $2) { + /* modifier specified twice, signal error */ + } + $$ = $1 | $2; + } ; modifier : ABSTRACT + { + $$ = VALA_MODIFIER_ABSTRACT; + } | OVERRIDE + { + $$ = VALA_MODIFIER_OVERRIDE; + } | STATIC + { + $$ = VALA_MODIFIER_STATIC; + } | VIRTUAL + { + $$ = VALA_MODIFIER_VIRTUAL; + } ; opt_class_base @@ -1100,6 +1146,12 @@ method_header GList *l; $$ = vala_method_new ($7, $6, src_com (@7, $1)); + if ($3 != 0) { + $$->access = $3; + } + if (($4 & VALA_MODIFIER_STATIC) == VALA_MODIFIER_STATIC) { + $$->instance = FALSE; + } VALA_CODE_NODE($$)->attributes = $2; for (l = $9; l != NULL; l = l->next) { diff --git a/vala/vala/valaattributeprocessor.vala b/vala/vala/valaattributeprocessor.vala index 6b3339ab9..f7798f7ce 100644 --- a/vala/vala/valaattributeprocessor.vala +++ b/vala/vala/valaattributeprocessor.vala @@ -39,5 +39,9 @@ namespace Vala { public override void visit_begin_class (Class cl) { cl.process_attributes (); } + + public override void visit_begin_method (Method m) { + m.process_attributes (); + } } } diff --git a/vala/vala/valaclass.vala b/vala/vala/valaclass.vala index 01977d941..77a8a4667 100644 --- a/vala/vala/valaclass.vala +++ b/vala/vala/valaclass.vala @@ -40,7 +40,6 @@ namespace Vala { public void add_property (Property prop) { properties.append (prop); - prop.parent_type = this; if (prop.set_accessor != null && prop.set_accessor.body == null) { /* automatic property accessor body generation */ diff --git a/vala/vala/valaconstant.vala b/vala/vala/valaconstant.vala index dc2f9affd..572c5ca48 100644 --- a/vala/vala/valaconstant.vala +++ b/vala/vala/valaconstant.vala @@ -28,7 +28,6 @@ namespace Vala { public TypeReference type_reference { get; construct; } public Expression initializer { get; construct; } public SourceReference source_reference { get; construct; } - public weak CodeNode parent_type; public static ref Constant new (string name, TypeReference type, Expression init, SourceReference source) { return (new Constant (name = name, type_reference = type, initializer = init, source_reference = source)); diff --git a/vala/vala/valafield.vala b/vala/vala/valafield.vala index d8d5d8d9b..83e90791a 100644 --- a/vala/vala/valafield.vala +++ b/vala/vala/valafield.vala @@ -28,7 +28,6 @@ namespace Vala { public TypeReference type_reference { get; construct; } public Expression initializer { get; construct; } public SourceReference source_reference { get; construct; } - public weak CodeNode parent_type; public static ref Field new (string name, TypeReference type, Expression init, SourceReference source) { return (new Field (name = name, type_reference = type, initializer = init, source_reference = source)); diff --git a/vala/vala/valamethod.vala b/vala/vala/valamethod.vala index db4763926..7910d48da 100644 --- a/vala/vala/valamethod.vala +++ b/vala/vala/valamethod.vala @@ -27,7 +27,6 @@ namespace Vala { public string name { get; construct; } public TypeReference return_type { get; construct; } public SourceReference source_reference { get; construct; } - public weak CodeNode parent_type; Statement _body; public Statement body { get { @@ -85,5 +84,27 @@ namespace Vala { public void set_cname (string cname) { this.cname = cname; } + + void process_ccode_attribute (Attribute a) { + foreach (NamedArgument arg in a.args) { + if (arg.name.collate ("cname") == 0) { + /* 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 ()); + } + } + } + } + } + + public void process_attributes () { + foreach (Attribute a in attributes) { + if (a.name.collate ("CCode") == 0) { + process_ccode_attribute (a); + } + } + } } } diff --git a/vala/vala/valanamespace.vala b/vala/vala/valanamespace.vala index b8a831f10..3cd627bad 100644 --- a/vala/vala/valanamespace.vala +++ b/vala/vala/valanamespace.vala @@ -31,6 +31,7 @@ namespace Vala { List structs; List enums; List fields; + List methods; public string cprefix; public string lower_case_cprefix; @@ -72,6 +73,10 @@ namespace Vala { fields.append (f); } + public void add_method (Method m) { + methods.append (m); + } + public override void accept (CodeVisitor visitor) { visitor.visit_begin_namespace (this); @@ -91,6 +96,10 @@ namespace Vala { f.accept (visitor); } + foreach (Method m in methods) { + m.accept (visitor); + } + visitor.visit_end_namespace (this); } diff --git a/vala/vala/valaproperty.vala b/vala/vala/valaproperty.vala index 7bb5a5583..058b5bc06 100644 --- a/vala/vala/valaproperty.vala +++ b/vala/vala/valaproperty.vala @@ -29,7 +29,6 @@ namespace Vala { public PropertyAccessor get_accessor { get; construct; } public PropertyAccessor set_accessor { get; construct; } public SourceReference source_reference { get; construct; } - public weak CodeNode parent_type; public MemberAccessibility access; public static ref Property new (string name, TypeReference type, PropertyAccessor get_accessor, PropertyAccessor set_accessor, SourceReference source) { diff --git a/vala/vala/valastruct.vala b/vala/vala/valastruct.vala index bb8b6bd42..9d5db8958 100644 --- a/vala/vala/valastruct.vala +++ b/vala/vala/valastruct.vala @@ -52,12 +52,10 @@ namespace Vala { public void add_field (Field f) { fields.append (f); - f.parent_type = this; } public void add_method (Method m) { methods.append (m); - m.parent_type = this; } public override void accept (CodeVisitor visitor) { -- 2.47.3