Commit df2d8a2c authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

add has_argument, get_string, and get_integer methods add get_attribute

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
parent 7cf83333
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
......
......@@ -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;
}
}
......@@ -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;
}
......@@ -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"));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment