]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
support member and access modifiers, static methods process method
authorJürg Billeter <j@bitron.ch>
Thu, 18 May 2006 13:57:34 +0000 (13:57 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 18 May 2006 13:57:34 +0000 (13:57 +0000)
2006-05-18  Jürg Billeter  <j@bitron.ch>

* 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
vala/vala/parser.y
vala/vala/valaattributeprocessor.vala
vala/vala/valaclass.vala
vala/vala/valaconstant.vala
vala/vala/valafield.vala
vala/vala/valamethod.vala
vala/vala/valanamespace.vala
vala/vala/valaproperty.vala
vala/vala/valastruct.vala

index c7099112badc4e75d6fcf1b56ab1602e21dc15c9..1bc83cc77b02526b3cbd44b0292309c4a21ab860 100644 (file)
@@ -1,3 +1,15 @@
+2006-05-18  Jürg Billeter  <j@bitron.ch>
+
+       * 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  <j@bitron.ch>
 
        * vala/parser.y: adapt to BinaryOperator enum changes
index 8325bddea6768b37186742e685bb97a8c341e3f2..8a596297fc909c7f75688440fafde051e53b2bd5 100644 (file)
@@ -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 <statement> return_statement
 %type <namespace> namespace_declaration
 %type <class> class_declaration
+%type <num> opt_access_modifier
+%type <num> access_modifier
+%type <num> opt_modifiers
+%type <num> modifiers
+%type <num> modifier
 %type <list> opt_class_base
 %type <list> class_base
 %type <list> 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) {
index 6b3339ab9607a92eb734fe5c0f1d488d1ede9a45..f7798f7ceed4b3ceb8b0e7d42da8cf04b78910cc 100644 (file)
@@ -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 ();
+               }
        }
 }
index 01977d941ce602179be679e2fd07237e73875eed..77a8a4667be9490cec37c667d814ae257510842c 100644 (file)
@@ -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 */
index dc2f9affd0be1dd71b0798de80c8f5a331d5e683..572c5ca48c57e6c6e7fa04a81cb54c85e3ff7a8e 100644 (file)
@@ -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));
index d8d5d8d9bd7db4f625954ca9b25113a275723bda..83e90791a02a2a02f9e58e60dd28d87bce96b007 100644 (file)
@@ -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));
index db47639263437221e66f7d8a2d73866c254587d1..7910d48da61c180ae2dfe184d536c062fbadefe2 100644 (file)
@@ -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);
+                               }
+                       }
+               }
        }
 }
index b8a831f101524a5f842c0c5eff2031eae41d4522..3cd627bad7b470da8191f934ea7cd3432474ff20 100644 (file)
@@ -31,6 +31,7 @@ namespace Vala {
                List<Struct> structs;
                List<Enum> enums;
                List<Field> fields;
+               List<Method> 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);
                }
 
index 7bb5a5583c1db4079567b05fc967b3ace9756684..058b5bc069ed9b5807e0cd2c7298eda384fc859b 100644 (file)
@@ -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) {
index bb8b6bd4293d612e38f92c7e8d1d5951df90f62e..9d5db89582532c85c4adcb4fb1f05b4a25ac322d 100644 (file)
@@ -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) {