}
public static bool get_ccode_no_accessor_method (Property p) {
- return p.get_attribute ("NoAccessorMethod") != null;
+ return p.has_attribute ("NoAccessorMethod");
}
public static bool get_ccode_concrete_accessor (Property p) {
- return p.get_attribute ("ConcreteAccessor") != null;
+ return p.has_attribute ("ConcreteAccessor");
}
public static bool get_ccode_has_emitter (Signal sig) {
- return sig.get_attribute ("HasEmitter") != null;
+ return sig.has_attribute ("HasEmitter");
}
public static bool get_ccode_has_type_id (TypeSymbol sym) {
}
public static bool get_ccode_no_wrapper (Method m) {
- return m.get_attribute ("NoWrapper") != null;
+ return m.has_attribute ("NoWrapper");
}
public static string get_ccode_sentinel (Method m) {
public bool array_length {
get {
if (_array_length == null) {
- if (node.get_attribute ("NoArrayLength") != null) {
+ if (node.has_attribute ("NoArrayLength")) {
Report.deprecated (node.source_reference, "[NoArrayLength] is deprecated, use [CCode (array_length = false)] instead.");
_array_length = false;
} else if (ccode != null && ccode.has_argument ("array_length")) {
}
void require_generic_accessors (Interface iface) {
- if (iface.get_attribute ("GenericAccessors") == null) {
+ if (!iface.has_attribute ("GenericAccessors")) {
Report.error (iface.source_reference,
"missing generic type for interface `%s', add GenericAccessors attribute to interface declaration",
iface.get_full_name ());
}
// TODO: don't duplicate the code in CCodeMethodModule, we do this right now because it needs to be before return
- if (current_method != null && current_method.get_attribute ("Profile") != null) {
+ if (current_method != null && current_method.has_attribute ("Profile")) {
string prefix = "_vala_prof_%s".printf (get_ccode_real_name (current_method));
var level = new CCodeIdentifier (prefix + "_level");
unowned Class? cl = expr.value_type.type_symbol as Class;
if (cl != null && cl.is_compact && expr.parent_node is MemberAccess) {
unowned MethodType? mt = ((MemberAccess) expr.parent_node).value_type as MethodType;
- if (mt != null && mt.method_symbol != null && mt.method_symbol.get_attribute ("DestroysInstance") != null) {
+ if (mt != null && mt.method_symbol != null && mt.method_symbol.has_attribute ("DestroysInstance")) {
return true;
}
}
bool in_gobject_creation_method = false;
bool in_fundamental_creation_method = false;
- bool profile = m.get_attribute ("Profile") != null;
+ bool profile = m.has_attribute ("Profile");
string real_name = get_ccode_real_name (m);
generate_struct_declaration (st.base_struct, decl_space);
} else if (!st.external_package) {
// custom simple type structs cannot have a type id which depends on head-allocation
- if (st.get_attribute ("SimpleType") != null && !st.has_attribute_argument ("CCode", "type_id")) {
+ if (st.has_attribute ("SimpleType") && !st.has_attribute_argument ("CCode", "type_id")) {
st.set_attribute_bool ("CCode", "has_type_id", false);
}
}
}
public override void visit_property (Property prop) {
- if (prop.get_attribute ("GtkChild") != null && prop.field == null) {
+ if (prop.has_attribute ("GtkChild") && prop.field == null) {
Report.error (prop.source_reference, "[GtkChild] is only allowed on automatic properties");
}
return;
}
- if (f.binding != MemberBinding.INSTANCE || f.get_attribute ("GtkChild") == null) {
+ if (f.binding != MemberBinding.INSTANCE || !f.has_attribute ("GtkChild")) {
return;
}
return;
}
- if (m.get_attribute ("GtkCallback") == null) {
+ if (!m.has_attribute ("GtkCallback")) {
return;
}
}
}
- if (iface.get_attribute ("GenericAccessors") != null) {
+ if (iface.has_attribute ("GenericAccessors")) {
foreach (TypeParameter p in iface.get_type_parameters ()) {
GenericType p_type = new GenericType (p);
DataType p_data_type = p_type.get_actual_type (SemanticAnalyzer.get_data_type_for_symbol (cl), null, cl);
type_struct.add_field ("GTypeInterface", "parent_iface");
- if (iface.get_attribute ("GenericAccessors") != null) {
+ if (iface.has_attribute ("GenericAccessors")) {
foreach (TypeParameter p in iface.get_type_parameters ()) {
var vdeclarator = new CCodeFunctionDeclarator ("get_%s".printf (get_ccode_type_id (p)));
var this_type = SemanticAnalyzer.get_data_type_for_symbol (iface);
public override void visit_struct (Struct st) {
// custom simple type structs cannot have a type id which depends on head-allocation
- if (st.get_attribute ("SimpleType") != null && !st.has_attribute_argument ("CCode", "type_id")) {
+ if (st.has_attribute ("SimpleType") && !st.has_attribute_argument ("CCode", "type_id")) {
st.set_attribute_bool ("CCode", "has_type_id", false);
}
base_prop = prop.base_interface_property;
}
- if (base_prop.get_attribute ("NoAccessorMethod") == null &&
+ if (!base_prop.has_attribute ("NoAccessorMethod") &&
prop.name == "type" && ((cl != null && !cl.is_compact) || (st != null && get_ccode_has_type_id (st)))) {
Report.error (prop.source_reference, "Property 'type' not allowed");
return;
return false;
}
- if (ma.symbol_reference.get_attribute ("GtkChild") != null) {
+ if (ma.symbol_reference.has_attribute ("GtkChild")) {
error = true;
Report.error (source_reference, "Assignment of [GtkChild] `%s' is not allowed", ma.symbol_reference.get_full_name ());
return false;
if (base_class != null && !base_class.is_subtype_of (this)) {
_is_compact = base_class.is_compact;
} else {
- _is_compact = get_attribute ("Compact") != null;
+ _is_compact = has_attribute ("Compact");
}
}
return _is_compact;
if (base_class != null && !base_class.is_subtype_of (this)) {
_is_immutable = base_class.is_immutable;
} else {
- _is_immutable = get_attribute ("Immutable") != null;
+ _is_immutable = has_attribute ("Immutable");
}
}
return _is_immutable;
public bool is_singleton {
get {
if (_is_singleton == null) {
- _is_singleton = get_attribute ("SingleInstance") != null;
+ _is_singleton = has_attribute ("SingleInstance");
}
return _is_singleton;
}
*/
public bool is_error_base {
get {
- return get_attribute ("ErrorBase") != null;
+ return has_attribute ("ErrorBase");
}
}
}
foreach (Property prop in get_properties ()) {
- if (prop.get_attribute ("NoAccessorMethod") != null && !is_subtype_of (context.analyzer.object_type)) {
+ if (prop.has_attribute ("NoAccessorMethod") && !is_subtype_of (context.analyzer.object_type)) {
error = true;
Report.error (prop.source_reference, "NoAccessorMethod is only allowed for properties in classes derived from GLib.Object");
return false;
return (!) a;
}
+ /**
+ * Returns true if the specified attribute is set.
+ *
+ * @param attribute attribute name
+ * @return true if the node has the given attribute
+ */
+ public bool has_attribute (string attribute) {
+ return get_attribute (attribute) != null;
+ }
+
/**
* Returns true if the specified attribute argument is set.
*
foreach (var attr in node.attributes) {
attributes.insert_sorted (attr, (a, b) => strcmp (a.name, b.name));
}
- if (need_cheaders && node.get_attribute ("CCode") == null) {
+ if (need_cheaders && !node.has_attribute ("CCode")) {
attributes.insert_sorted (new Attribute ("CCode"), (a, b) => strcmp (a.name, b.name));
}
public bool is_flags {
get {
if (_is_flags == null) {
- _is_flags = get_attribute ("Flags") != null;
+ _is_flags = has_attribute ("Flags");
}
return _is_flags;
}
return false;
}
- if (get_attribute ("GtkChild") != null && variable_type.value_owned) {
+ if (has_attribute ("GtkChild") && variable_type.value_owned) {
Report.warning (source_reference, "[GtkChild] fields must be declared as `unowned'");
variable_type.value_owned = false;
}
&& !(m is CreationMethod)) {
if (!m.is_private_symbol () && (context.internal_header_filename != null || context.use_fast_vapi)) {
// do not warn if internal member may be used outside this compilation unit
- } else if (m.parent_symbol != null && m.parent_symbol.get_attribute ("DBus") != null
+ } else if (m.parent_symbol != null && m.parent_symbol.has_attribute ("DBus")
&& m.get_attribute_bool ("DBus", "visible", true)) {
// do not warn if internal member is a visible DBus method
} else {
if (stmt.expression is MethodCall) {
unowned MethodCall expr = (MethodCall) stmt.expression;
unowned MemberAccess? ma = expr.call as MemberAccess;
- if (ma != null && ma.symbol_reference != null && ma.symbol_reference.get_attribute ("NoReturn") != null) {
+ if (ma != null && ma.symbol_reference != null && ma.symbol_reference.has_attribute ("NoReturn")) {
mark_unreachable ();
return;
}
void set_attributes (CodeNode node, List<Attribute>? attributes) {
if (attributes != null) {
foreach (Attribute attr in (List<Attribute>) attributes) {
- if (node.get_attribute (attr.name) != null) {
+ if (node.has_attribute (attr.name)) {
Report.error (attr.source_reference, "duplicate attribute `%s'", attr.name);
}
node.attributes.append (attr);
for (unowned Node? node = this ; node != null ; node = node.parent) {
if (node.symbol is Namespace) {
- if (node.symbol.get_attribute_string ("CCode", "gir_namespace") != null) {
+ if (node.symbol.has_attribute_argument ("CCode", "gir_namespace")) {
break;
}
}
} else if (sym is Method && !(sym is CreationMethod) && node != this) {
if (m.is_virtual || m.is_abstract) {
bool different_invoker = false;
- var attr = m.get_attribute ("NoWrapper");
- if (attr != null) {
+ var no_wrapper = m.has_attribute ("NoWrapper");
+ if (no_wrapper) {
/* no invoker but this method has the same name,
most probably the invoker has a different name
and g-ir-scanner missed it */
}
}
if (!different_invoker) {
- if (attr != null) {
+ if (no_wrapper) {
Report.warning (symbol.source_reference, "Virtual method `%s' conflicts with method of the same name", get_full_name ());
}
node.merged = true;
}
}
- if (prop.get_attribute ("NoAccessorMethod") == null && prop.set_accessor != null && prop.set_accessor.writable) {
+ if (!prop.has_attribute ("NoAccessorMethod") && prop.set_accessor != null && prop.set_accessor.writable) {
var m = setter != null ? setter.symbol as Method : null;
// ensure setter vfunc if the property is abstract
if (m != null) {
prop.set_attribute ("ConcreteAccessor", false);
} else {
prop.set_accessor.value_type.value_owned = m.get_parameters()[0].variable_type.value_owned;
- if (prop.get_attribute ("ConcreteAccessor") != null && !m.is_abstract && !m.is_virtual && prop.is_abstract) {
+ if (prop.has_attribute ("ConcreteAccessor") && !m.is_abstract && !m.is_virtual && prop.is_abstract) {
prop.set_attribute ("ConcreteAccessor", true);
prop.set_attribute ("NoAccessorMethod", false);
}
}
}
- if (prop.get_attribute ("NoAccessorMethod") != null) {
+ if (prop.has_attribute ("NoAccessorMethod")) {
if (!prop.overrides && parent.symbol is Class) {
// bug 742012
// find base interface property with ConcreteAccessor and this overriding property with NoAccessorMethod
base_prop_node.process (parser);
var base_property = (Property) base_prop_node.symbol;
- if (base_property.get_attribute ("ConcreteAccessor") != null) {
+ if (base_property.has_attribute ("ConcreteAccessor")) {
prop.set_attribute ("NoAccessorMethod", false);
if (prop.get_accessor != null) {
prop.get_accessor.value_type.value_owned = base_property.get_accessor.value_type.value_owned;
prop.set_attribute ("NoAccessorMethod", metadata.get_bool (ArgumentType.NO_ACCESSOR_METHOD));
}
- if (prop.get_attribute ("NoAccessorMethod") != null) {
+ if (prop.has_attribute ("NoAccessorMethod")) {
// gobject defaults
if (prop.get_accessor != null) {
prop.get_accessor.value_type.value_owned = true;
unowned CodeNode? parent = ma.parent_node;
if (parent != null && !(parent is ElementAccess) && !(((MemberAccess) ma).inner is BaseAccess)
&& (!(parent is MethodCall) || ((MethodCall) parent).get_argument_list ().contains (this))) {
- if (sig.get_attribute ("HasEmitter") != null) {
+ if (sig.has_attribute ("HasEmitter")) {
if (!sig.check (context)) {
return false;
}
}
}
- if (symbol_reference is Method && ((Method) symbol_reference).get_attribute ("DestroysInstance") != null) {
+ if (symbol_reference is Method && ((Method) symbol_reference).has_attribute ("DestroysInstance")) {
unowned Class? cl = ((Method) symbol_reference).parent_symbol as Class;
if (cl != null && cl.is_compact && ma != null) {
ma.lvalue = true;
*/
public bool returns_modified_pointer {
get {
- return get_attribute ("ReturnsModifiedPointer") != null;
+ return has_attribute ("ReturnsModifiedPointer");
}
set {
set_attribute ("ReturnsModifiedPointer", value);
*/
public bool printf_format {
get {
- return get_attribute ("PrintfFormat") != null;
+ return has_attribute ("PrintfFormat");
}
set {
set_attribute ("PrintfFormat", value);
*/
public bool scanf_format {
get {
- return get_attribute ("ScanfFormat") != null;
+ return has_attribute ("ScanfFormat");
}
set {
set_attribute ("ScanfFormat", value);
this_parameter.check (context);
}
- if (get_attribute ("DestroysInstance") != null) {
+ if (has_attribute ("DestroysInstance")) {
this_parameter.variable_type.value_owned = true;
}
- if (get_attribute ("NoThrow") != null) {
+ if (has_attribute ("NoThrow")) {
error_types = null;
}
return false;
}
- if (get_attribute ("NoWrapper") != null && !(is_abstract || is_virtual)) {
+ if (has_attribute ("NoWrapper") && !(is_abstract || is_virtual)) {
error = true;
Report.error (source_reference, "[NoWrapper] methods must be declared abstract or virtual");
return false;
return false;
}
- var init_attr = get_attribute ("ModuleInit");
- if (init_attr != null) {
+ if (has_attribute ("ModuleInit")) {
source_reference.file.context.module_init_method = this;
}
Report.error (parameters[0].source_reference, "Named parameter required before `...'");
}
- if (get_attribute ("Print") != null && (parameters.size != 1 || parameters[0].variable_type.type_symbol != context.analyzer.string_type.type_symbol)) {
+ if (has_attribute ("Print") && (parameters.size != 1 || parameters[0].variable_type.type_symbol != context.analyzer.string_type.type_symbol)) {
error = true;
Report.error (source_reference, "[Print] methods must have exactly one parameter of type `string'");
}
// check that DBus methods at least throw "GLib.Error" or "GLib.DBusError, GLib.IOError"
if (!(this is CreationMethod) && binding == MemberBinding.INSTANCE
&& !overrides && access == SymbolAccessibility.PUBLIC
- && parent_symbol is ObjectTypeSymbol && parent_symbol.get_attribute ("DBus") != null) {
+ && parent_symbol is ObjectTypeSymbol && parent_symbol.has_attribute ("DBus")) {
Attribute? dbus_attr = get_attribute ("DBus");
if (dbus_attr == null || dbus_attr.get_bool ("visible", true)) {
bool throws_gerror = false;
}
}
- if (get_attribute ("GtkCallback") != null) {
+ if (has_attribute ("GtkCallback")) {
used = true;
}
}
}
- if (ma.symbol_reference != null && ma.symbol_reference.get_attribute ("Assert") != null) {
+ if (ma.symbol_reference != null && ma.symbol_reference.has_attribute ("Assert")) {
this.is_assert = true;
if (argument_list.size == 1) {
}
// concatenate stringified arguments for methods with attribute [Print]
- if (mtype is MethodType && ((MethodType) mtype).method_symbol.get_attribute ("Print") != null) {
+ if (mtype is MethodType && ((MethodType) mtype).method_symbol.has_attribute ("Print")) {
var template = new Template (source_reference);
foreach (Expression arg in argument_list) {
arg.parent_node = null;
old_ns.add_comment (c);
}
foreach (Attribute a in ns.attributes) {
- if (old_ns.get_attribute (a.name) == null) {
+ if (!old_ns.has_attribute (a.name)) {
old_ns.attributes.append(a);
}
}
if (target_type is GenericType ||
target_type is PointerType ||
target_type.nullable ||
- target_type.type_symbol.get_attribute ("PointerType") != null) {
+ target_type.type_symbol.has_attribute ("PointerType")) {
return true;
}
while (cl != null) {
// FIXME: use target values in the codegen
- if (cl.get_attribute_string ("CCode", "ref_sink_function") != null) {
+ if (cl.has_attribute_argument ("CCode", "ref_sink_function")) {
value_type.floating_reference = true;
break;
}
return !error;
}
- if (!external_package && get_attribute ("DBus") != null && !context.has_package ("gio-2.0")) {
+ if (!external_package && has_attribute ("DBus") && !context.has_package ("gio-2.0")) {
error = true;
Report.error (source_reference, "gio-2.0 package required for DBus support");
}
public bool format_arg {
get {
- return get_attribute ("FormatArg") != null;
+ return has_attribute ("FormatArg");
}
}
void set_attributes (CodeNode node, List<Attribute>? attributes) {
if (attributes != null) {
foreach (Attribute attr in (List<Attribute>) attributes) {
- if (node.get_attribute (attr.name) != null) {
+ if (node.has_attribute (attr.name)) {
Report.error (attr.source_reference, "duplicate attribute `%s'", attr.name);
}
node.attributes.append (attr);
return base_type.compatible (tt.base_type);
}
- if ((target_type.type_symbol != null && target_type.type_symbol.get_attribute ("PointerType") != null)) {
+ if ((target_type.type_symbol != null && target_type.type_symbol.has_attribute ("PointerType"))) {
return true;
}
Report.error (source_reference, "Property setter must have a body");
}
if (!get_has_body && !set_has_body) {
- if (get_attribute ("GtkChild") != null && property_type.value_owned) {
+ if (has_attribute ("GtkChild") && property_type.value_owned) {
Report.warning (source_reference, "[GtkChild] properties must be declared as `unowned'");
property_type.value_owned = false;
}
_field.access = SymbolAccessibility.PRIVATE;
_field.binding = binding;
// apply gtk-child attribute to backing field for gtk-template support
- if (get_attribute ("GtkChild") != null) {
+ if (has_attribute ("GtkChild")) {
_field.set_attribute_string ("GtkChild", "name", get_attribute_string ("GtkChild", "name", name));
_field.set_attribute_bool ("GtkChild", "internal", get_attribute_bool ("GtkChild", "internal"));
}
get_accessor.check (context);
}
if (set_accessor != null) {
- if (get_attribute ("GtkChild") != null) {
+ if (has_attribute ("GtkChild")) {
Report.warning (set_accessor.source_reference, "[GtkChild] property `%s' is not allowed to have `set' accessor", get_full_name ());
}
set_accessor.check (context);
if (context.profile == Profile.GOBJECT
&& readable && ((TypeSymbol) prop.parent_symbol).is_subtype_of (context.analyzer.object_type)) {
//FIXME Code duplication with CCodeMemberAccessModule.visit_member_access()
- if (prop.get_attribute ("NoAccessorMethod") != null) {
+ if (prop.has_attribute ("NoAccessorMethod")) {
if (value_type.is_real_struct_type ()) {
if (source_reference == null || source_reference.file == null) {
// Hopefully good as is
return false;
}
- if (type_sym is Interface && type_sym.get_attribute ("DBus") != null) {
+ if (type_sym is Interface && type_sym.has_attribute ("DBus")) {
// GObject properties not currently supported in D-Bus interfaces
return false;
}
Expression prev_arg = null;
Iterator<Expression> arg_it = args.iterator ();
- bool diag = (mtype is MethodType && ((MethodType) mtype).method_symbol.get_attribute ("Diagnostics") != null);
+ bool diag = (mtype is MethodType && ((MethodType) mtype).method_symbol.has_attribute ("Diagnostics"));
bool ellipsis = false;
int i = 0;
default_handler.check (context);
}
- if (get_attribute ("HasEmitter") != null) {
+ if (has_attribute ("HasEmitter")) {
emitter = new Method (name, return_type, source_reference);
emitter.owner = owner;
public bool is_immutable {
get {
if (_is_immutable == null) {
- _is_immutable = get_attribute ("Immutable") != null;
+ _is_immutable = has_attribute ("Immutable");
}
return _is_immutable;
}
return true;
}
if (boolean_type == null) {
- boolean_type = get_attribute ("BooleanType") != null;
+ boolean_type = has_attribute ("BooleanType");
}
return boolean_type;
}
return true;
}
if (integer_type == null) {
- integer_type = get_attribute ("IntegerType") != null;
+ integer_type = has_attribute ("IntegerType");
}
return integer_type;
}
return true;
}
if (floating_type == null) {
- floating_type = get_attribute ("FloatingType") != null;
+ floating_type = has_attribute ("FloatingType");
}
return floating_type;
}
return true;
}
if (simple_type == null) {
- simple_type = get_attribute ("SimpleType") != null || get_attribute ("BooleanType") != null || get_attribute ("IntegerType") != null || get_attribute ("FloatingType") != null;
+ simple_type = has_attribute ("SimpleType") || has_attribute ("BooleanType") || has_attribute ("IntegerType") || has_attribute ("FloatingType");
}
return simple_type;
}
}
public bool is_disposable () {
- if (get_attribute_string ("CCode", "destroy_function") != null) {
+ if (has_attribute_argument ("CCode", "destroy_function")) {
return true;
}
}
// attributes are not processed yet, access them directly
- if (base_struct.get_attribute ("BooleanType") != null) {
+ if (base_struct.has_attribute ("BooleanType")) {
return new BooleanType (st, source_reference);
- } else if (base_struct.get_attribute ("IntegerType") != null) {
+ } else if (base_struct.has_attribute ("IntegerType")) {
return new IntegerType (st, null, null, source_reference);
- } else if (base_struct.get_attribute ("FloatingType") != null) {
+ } else if (base_struct.has_attribute ("FloatingType")) {
return new FloatingType (st, source_reference);
} else {
return new StructValueType (st, source_reference);
Report.error (source_reference, "ref and out method arguments can only be used with fields, parameters, local variables, and array element access");
return false;
}
- if (inner.symbol_reference != null && inner.symbol_reference.get_attribute ("GtkChild") != null) {
+ if (inner.symbol_reference != null && inner.symbol_reference.has_attribute ("GtkChild")) {
error = true;
Report.error (source_reference, "Assignment of [GtkChild] `%s' is not allowed", inner.symbol_reference.get_full_name ());
return false;
get {
if (_deprecated == null) {
_deprecated = symbol.get_attribute_bool ("Version", "deprecated", false)
- || symbol.get_attribute_string ("Version", "deprecated_since") != null
- || symbol.get_attribute_string ("Version", "replacement") != null
+ || symbol.has_attribute_argument ("Version", "deprecated_since")
+ || symbol.has_attribute_argument ("Version", "replacement")
// [Deprecated] is deprecated
- || symbol.get_attribute ("Deprecated") != null;
+ || symbol.has_attribute ("Deprecated");
}
return _deprecated;
}
get {
if (_experimental == null) {
_experimental = symbol.get_attribute_bool ("Version", "experimental", false)
- || symbol.get_attribute_string ("Version", "experimental_until") != null
- || symbol.get_attribute ("Experimental") != null;
+ || symbol.has_attribute_argument ("Version", "experimental_until")
+ || symbol.has_attribute ("Experimental");
}
return _experimental;
}
prop.set_attribute ("NoAccessorMethod", true);
}
- if (prop.get_attribute ("NoAccessorMethod") != null && prop.get_accessor != null) {
+ if (prop.has_attribute ("NoAccessorMethod") && prop.get_accessor != null) {
prop.get_accessor.value_type.value_owned = true;
}
}
prop.set_attribute ("NoAccessorMethod", true);
}
- if (prop.get_attribute ("NoAccessorMethod") != null && prop.get_accessor != null) {
+ if (prop.has_attribute ("NoAccessorMethod") && prop.get_accessor != null) {
prop.get_accessor.value_type.value_owned = true;
}
}