]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
add has_argument, get_string, and get_integer methods add get_attribute
authorJürg Billeter <j@bitron.ch>
Tue, 21 Nov 2006 10:58:08 +0000 (10:58 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Tue, 21 Nov 2006 10:58:08 +0000 (10:58 +0000)
2006-11-21  Jürg Billeter  <j@bitron.ch>

* vala/valaattribute.vala: add has_argument, get_string, and get_integer
  methods
* vala/valacodenode.vala: add get_attribute method
* vala/valamethod.vala: use new attribute functionality

svn path=/trunk/; revision=177

vala/ChangeLog
vala/vala/valaattribute.vala
vala/vala/valacodenode.vala
vala/vala/valamethod.vala

index ce49625c6001f71f84ada968281329e3637d3d7c..384f12e40db6b32b47af046fee350675fd329b5f 100644 (file)
@@ -1,3 +1,10 @@
+2006-11-21  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaattribute.vala: add has_argument, get_string, and get_integer
+         methods
+       * vala/valacodenode.vala: add get_attribute method
+       * vala/valamethod.vala: use new attribute functionality
+
 2006-11-21  Jürg Billeter  <j@bitron.ch>
 
        * vala/valasymbolresolver.vala, vala/valasemanticanalyzer.vala: don't
index 57bd0b7ad37a981586bd676ada505b5247ce3997..fdd4cf0417b26142b46fc8b3a5a45b56787dbcf2 100644 (file)
@@ -56,4 +56,65 @@ public class Vala.Attribute : CodeNode {
        public void add_argument (NamedArgument! arg) {
                args.append (arg);
        }
+       
+       /**
+        * Returns whether this attribute has the specified named argument.
+        *
+        * @param name argument name
+        * @return     true if the argument has been found, false otherwise
+        */
+       public bool has_argument (string! name) {
+               // FIXME: use hash table
+               foreach (NamedArgument arg in args) {
+                       if (arg.name == name) {
+                               return true;
+                       }
+               }
+               
+               return false;
+       }
+       
+       /**
+        * Returns the string value of the specified named argument.
+        *
+        * @param name argument name
+        * @return     string value
+        */
+       public ref string get_string (string! name) {
+               // FIXME: use hash table
+               foreach (NamedArgument arg in args) {
+                       if (arg.name == name) {
+                               if (arg.argument is LiteralExpression) {
+                                       var lit = ((LiteralExpression) arg.argument).literal;
+                                       if (lit is StringLiteral) {
+                                               return ((StringLiteral) lit).eval ();
+                                       }
+                               }
+                       }
+               }
+               
+               return null;
+       }
+       
+       /**
+        * Returns the integer value of the specified named argument.
+        *
+        * @param name argument name
+        * @return     integer value
+        */
+       public int get_integer (string! name) {
+               // FIXME: use hash table
+               foreach (NamedArgument arg in args) {
+                       if (arg.name == name) {
+                               if (arg.argument is LiteralExpression) {
+                                       var lit = ((LiteralExpression) arg.argument).literal;
+                                       if (lit is IntegerLiteral) {
+                                               return ((IntegerLiteral) lit).value.to_int ();
+                                       }
+                               }
+                       }
+               }
+               
+               return 0;
+       }
 }
index 02effecd6967bd1341ab3142c98c404a649bc068..8b39b45354b9bd3ceffddbcd7293e1fa19d835a1 100644 (file)
@@ -84,5 +84,22 @@ public abstract class Vala.CodeNode {
        public virtual void replace (CodeNode! old_node, CodeNode! new_node) {
        }
        
+       /**
+        * Returns the specified attribute.
+        *
+        * @param name attribute name
+        * @return     attribute
+        */
+       public Attribute get_attribute (string! name) {
+               // FIXME: use hash table
+               foreach (Attribute a in attributes) {
+                       if (a.name == name) {
+                               return a;
+                       }
+               }
+               
+               return null;
+       }
+       
        private CCodeNode _ccodenode;
 }
index 6c1b1dcfbfc90f4912f8301d4f46e9f039d5064a..3cb8d59772752afa1636fa2b39f32f99979ed527 100644 (file)
@@ -254,16 +254,8 @@ public class Vala.Method : Member, Invokable {
        }
        
        private 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 ());
-                                       }
-                               }
-                       }
+               if (a.has_argument ("cname")) {
+                       set_cname (a.get_string ("cname"));
                }
        }