From: Jürg Billeter Date: Tue, 21 Nov 2006 10:58:08 +0000 (+0000) Subject: add has_argument, get_string, and get_integer methods add get_attribute X-Git-Tag: VALA_0_0_6~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=df2d8a2c942171453653190e233aa7d2c473c3df;p=thirdparty%2Fvala.git add has_argument, get_string, and get_integer methods add get_attribute 2006-11-21 Jürg Billeter * 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 --- diff --git a/vala/ChangeLog b/vala/ChangeLog index ce49625c6..384f12e40 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,3 +1,10 @@ +2006-11-21 Jürg Billeter + + * 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 * vala/valasymbolresolver.vala, vala/valasemanticanalyzer.vala: don't diff --git a/vala/vala/valaattribute.vala b/vala/vala/valaattribute.vala index 57bd0b7ad..fdd4cf041 100644 --- a/vala/vala/valaattribute.vala +++ b/vala/vala/valaattribute.vala @@ -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; + } } diff --git a/vala/vala/valacodenode.vala b/vala/vala/valacodenode.vala index 02effecd6..8b39b4535 100644 --- a/vala/vala/valacodenode.vala +++ b/vala/vala/valacodenode.vala @@ -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; } diff --git a/vala/vala/valamethod.vala b/vala/vala/valamethod.vala index 6c1b1dcfb..3cb8d5977 100644 --- a/vala/vala/valamethod.vala +++ b/vala/vala/valamethod.vala @@ -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")); } }