NO_REPLY
}
- public CCodeConstant get_dbus_timeout (Symbol symbol) {
- int timeout = -1;
-
+ public CCodeExpression get_dbus_timeout (Symbol symbol) {
var dbus = symbol.get_attribute ("DBus");
if (dbus != null && dbus.has_argument ("timeout")) {
- timeout = dbus.get_integer ("timeout");
+ return get_ccodenode (dbus.get_expression ("timeout"));
} else if (symbol.parent_symbol != null) {
return get_dbus_timeout (symbol.parent_symbol);
}
- return new CCodeConstant (timeout.to_string ());
+ return new CCodeConstant ("-1");
}
public override void generate_dynamic_method_wrapper (DynamicMethod method) {
push_function (func);
if (method.dynamic_type.type_symbol == dbus_proxy_type) {
- generate_marshalling (method, CallType.SYNC, null, method.name, -1);
+ generate_marshalling (method, CallType.SYNC, null, method.name, null);
} else {
Report.error (method.source_reference, "dynamic methods are not supported for `%s'", method.dynamic_type.to_string ());
}
cfile.add_function (cfunc);
}
- void generate_marshalling (Method m, CallType call_type, string? iface_name, string? method_name, int method_timeout) {
+ void generate_marshalling (Method m, CallType call_type, string? iface_name, string? method_name, CCodeExpression? method_timeout) {
var gdbusproxy = new CCodeCastExpression (new CCodeIdentifier ("self"), "GDBusProxy *");
var connection = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_proxy_get_connection"));
object_path.add_argument (gdbusproxy);
CCodeExpression timeout;
- if (method_timeout <= 0) {
+ if (method_timeout == null) {
timeout = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_proxy_get_default_timeout"));
((CCodeFunctionCall) timeout).add_argument (gdbusproxy);
} else {
- timeout = new CCodeConstant ("%d".printf (method_timeout));
+ timeout = method_timeout;
}
// register errors
push_function (function);
- generate_marshalling (m, CallType.FINISH, null, null, -1);
+ generate_marshalling (m, CallType.FINISH, null, null, null);
pop_function ();
return Symbol.lower_case_to_camel_case (symbol.name);
}
- public static int get_dbus_timeout_for_member (Symbol symbol) {
- return symbol.get_attribute_integer ("DBus", "timeout", -1);
+ public CCodeExpression get_dbus_timeout_for_member (Symbol symbol) {
+ var dbus = symbol.get_attribute ("DBus");
+ if (dbus != null && dbus.has_argument ("timeout")) {
+ return get_ccodenode (dbus.get_expression ("timeout"));
+ }
+
+ return null; //new CCodeConstant ("-1");
}
public static bool is_dbus_visible (CodeNode node) {
if (arg_name != "cheader_filename") {
builder.append_attribute (arg_name);
builder.append_attribute ("=");
- builder.append_literal (attr.args.get (arg_name));
+ builder.append_literal (attr.args.get (arg_name).to_string ());
}
separator = ", ";
}
/**
* Contains all specified attribute arguments.
*/
- public Vala.Map<string,string> args { get; private set; }
+ public Vala.Map<string,Expression> args { get; private set; }
/**
* Creates a new attribute.
public Attribute (string name, SourceReference? source_reference = null) {
this.name = name;
this.source_reference = source_reference;
- this.args = new HashMap<string,string> (str_hash, str_equal);
+ this.args = new HashMap<string,Expression> (str_hash, str_equal);
if (!CodeContext.get ().deprecated) {
if (name == "Deprecated") {
* @param key argument name
* @param value argument value
*/
- public void add_argument (string key, string value) {
+ public void add_argument (string key, Expression value) {
args.set (key, value);
}
return args.contains (name);
}
+ /**
+ * Returns the expression of the specified named argument.
+ *
+ * @param name argument name
+ * @return expression value
+ */
+ public Expression? get_expression (string name, Expression? default_value = null) {
+ Expression? value = args.get (name);
+
+ if (value == null) {
+ return default_value;
+ }
+
+ return value;
+ }
+
/**
* Returns the string value of the specified named argument.
*
* @return string value
*/
public string? get_string (string name, string? default_value = null) {
- string value = args.get (name);
+ Expression? value = args.get (name);
if (value == null) {
return default_value;
}
- /* remove quotes */
- var noquotes = value.substring (1, (uint) (value.length - 2));
- /* unescape string */
- return noquotes.compress ();
+ assert (value is StringLiteral);
+
+ return ((StringLiteral) value).eval ();
}
/**
* @return integer value
*/
public int get_integer (string name, int default_value = 0) {
- string value = args.get (name);
+ Expression? value = args.get (name);
if (value == null) {
return default_value;
}
- return int.parse (value);
+ assert (value is IntegerLiteral);
+
+ return int.parse (((IntegerLiteral) value).value);
}
/**
* @return double value
*/
public double get_double (string name, double default_value = 0) {
- string value = args.get (name);
+ Expression? value = args.get (name);
if (value == null) {
return default_value;
}
- return double.parse (value);
+ assert (value is RealLiteral || value is IntegerLiteral);
+
+ if (value is IntegerLiteral) {
+ return int.parse (((IntegerLiteral) value).value);
+ } else {
+ return double.parse (((RealLiteral) value).value);
+ }
}
/**
* @return boolean value
*/
public bool get_bool (string name, bool default_value = false) {
- string value = args.get (name);
+ Expression? value = args.get (name);
if (value == null) {
return default_value;
}
- return bool.parse (value);
+ assert (value is BooleanLiteral);
+
+ return ((BooleanLiteral) value).value;
+ }
+
+ public override bool check (CodeContext context) {
+ foreach (var attr in args.get_values ()) {
+ if (!attr.check (context)) {
+ return false;
+ }
+ if (!attr.is_constant ()) {
+ Report.error (attr.source_reference, "attribute values must be constant");
+ return false;
+ }
+ }
+
+ return true;
}
}
}
context.analyzer.current_symbol = this;
+ base.check (context);
+
foreach (DataType base_type_reference in get_base_types ()) {
if (!base_type_reference.check (context)) {
error = true;
}
public virtual bool check (CodeContext context) {
+ foreach (unowned Attribute a in attributes) {
+ a.check (context);
+ }
+
return true;
}
}
unowned Attribute a = get_or_create_attribute (attribute);
- a.add_argument (argument, "\"%s\"".printf (value));
+ a.add_argument (argument, new StringLiteral ("\"%s\"".printf (value)));
}
/**
*/
public void set_attribute_integer (string attribute, string argument, int value, SourceReference? source_reference = null) {
unowned Attribute a = get_or_create_attribute (attribute);
- a.add_argument (argument, value.to_string ());
+ a.add_argument (argument, new IntegerLiteral (value.to_string (), source_reference));
}
/**
*/
public void set_attribute_double (string attribute, string argument, double value, SourceReference? source_reference = null) {
unowned Attribute a = get_or_create_attribute (attribute);
- a.add_argument (argument, value.format (new char[double.DTOSTR_BUF_SIZE]));
+ a.add_argument (argument, new RealLiteral (value.format (new char[double.DTOSTR_BUF_SIZE]), source_reference));
}
/**
*/
public void set_attribute_bool (string attribute, string argument, bool value, SourceReference? source_reference = null) {
unowned Attribute a = get_or_create_attribute (attribute);
- a.add_argument (argument, value.to_string ());
+ a.add_argument (argument, new BooleanLiteral (value, source_reference));
}
/**
if (arg_name == "cheader_filename") {
stream.printf ("%scheader_filename = \"%s\"", separator, get_cheaders (sym));
} else {
- stream.printf ("%s%s = %s", separator, arg_name, attr.args.get (arg_name));
+ stream.printf ("%s%s = ", separator, arg_name);
+ attr.args.get (arg_name).accept (this);
}
separator = ", ";
}
context.analyzer.current_symbol = this;
}
+ base.check (context);
+
type_reference.check (context);
if (!check_const_type (type_reference, context)) {
context.analyzer.current_source_file = source_reference.file;
}
+ base.check (context);
+
foreach (TypeParameter p in type_parameters) {
p.check (context);
}
}
context.analyzer.current_symbol = this;
+ base.check (context);
+
if (values.size <= 0) {
Report.error (source_reference, "Enum `%s' requires at least one value", get_full_name ());
error = true;
checked = true;
+ base.check (context);
+
if (value != null) {
value.check (context);
checked = true;
+ base.check (context);
+
if (value != null) {
value.check (context);
}
checked = true;
+ base.check (context);
+
if (codes.size <= 0) {
Report.error (source_reference, "Error domain `%s' requires at least one code", get_full_name ());
error = true;
}
context.analyzer.current_symbol = this;
+ base.check (context);
+
if (variable_type is VoidType) {
error = true;
Report.error (source_reference, "'void' not supported as field type");
return new DeleteStatement (expr, get_src (begin));
}
- string parse_attribute_value () throws ParseError {
- switch (current ()) {
- case TokenType.NULL:
- case TokenType.TRUE:
- case TokenType.FALSE:
- case TokenType.INTEGER_LITERAL:
- case TokenType.REAL_LITERAL:
- case TokenType.STRING_LITERAL:
- next ();
- return get_last_string ();
- case TokenType.MINUS:
- next ();
- switch (current ()) {
- case TokenType.INTEGER_LITERAL:
- case TokenType.REAL_LITERAL:
- next ();
- return "-" + get_last_string ();
- default:
- throw new ParseError.SYNTAX ("expected number");
- }
- default:
- throw new ParseError.SYNTAX ("expected literal");
- }
- }
-
List<Attribute>? parse_attributes (bool parameter) throws ParseError {
if (current () != TokenType.OPEN_BRACKET) {
return null;
do {
id = parse_identifier ();
expect (TokenType.ASSIGN);
- attr.add_argument (id, parse_attribute_value ());
+ attr.add_argument (id, parse_unary_expression ());
} while (accept (TokenType.COMMA));
}
expect (TokenType.CLOSE_PARENS);
checked = true;
+ base.check (context);
+
if (this_parameter != null) {
this_parameter.check (context);
}
checked = true;
+ base.check (context);
+
var a = get_attribute ("CCode");
if (a != null && a.has_argument ("gir_namespace")) {
var new_gir = a.get_string ("gir_namespace");
}
context.analyzer.current_symbol = parent_symbol;
+ base.check (context);
+
if (variable_type != null) {
if (variable_type is VoidType) {
error = true;
return new WithStatement (local, expr, body, src);
}
- string parse_attribute_value () throws ParseError {
- switch (current ()) {
- case TokenType.NULL:
- case TokenType.TRUE:
- case TokenType.FALSE:
- case TokenType.INTEGER_LITERAL:
- case TokenType.REAL_LITERAL:
- case TokenType.STRING_LITERAL:
- next ();
- return get_last_string ();
- case TokenType.MINUS:
- next ();
- switch (current ()) {
- case TokenType.INTEGER_LITERAL:
- case TokenType.REAL_LITERAL:
- next ();
- return "-" + get_last_string ();
- default:
- throw new ParseError.SYNTAX ("expected number");
- }
- default:
- throw new ParseError.SYNTAX ("expected literal");
- }
- }
-
List<Attribute>? parse_attributes () throws ParseError {
if (current () != TokenType.OPEN_BRACKET) {
return null;
do {
id = parse_identifier ();
expect (TokenType.ASSIGN);
- attr.add_argument (id, parse_attribute_value ());
+ attr.add_argument (id, parse_unary_expression ());
} while (accept (TokenType.COMMA));
}
expect (TokenType.CLOSE_PARENS);
checked = true;
+ base.check (context);
+
// parent_symbol may be null for dynamic signals
unowned Class? parent_cl = parent_symbol as Class;
if (parent_cl != null && parent_cl.is_compact) {
}
context.analyzer.current_symbol = this;
+ base.check (context);
+
if (base_type != null) {
base_type.check (context);