+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
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;
+ }
}
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;
}
}
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"));
}
}