diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-04-27 20:18:34 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-04-28 09:27:06 +0200 |
commit | d4c9da248919d6e604d1da5a738013e73b6e8860 (patch) | |
tree | 445e8b789e2e1777e06eaaec4e93eae4d00a49df /vala/valasemanticanalyzer.vala | |
parent | 777119440d6ab2a7eb96726596ec8455592dd058 (diff) | |
download | vala-d4c9da248919d6e604d1da5a738013e73b6e8860.tar.gz |
codegen: Move GObject property validity checks to SemanticAnalyzer
Diffstat (limited to 'vala/valasemanticanalyzer.vala')
-rw-r--r-- | vala/valasemanticanalyzer.vala | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 485ab222d..af7e63eb6 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -406,6 +406,66 @@ public class Vala.SemanticAnalyzer : CodeVisitor { return sym; } + public bool is_gobject_property (Property prop) { + var type_sym = prop.parent_symbol as ObjectTypeSymbol; + if (type_sym == null || !type_sym.is_subtype_of (object_type)) { + return false; + } + + if (prop.binding != MemberBinding.INSTANCE) { + return false; + } + + if (prop.access == SymbolAccessibility.PRIVATE) { + return false; + } + + if (!is_gobject_property_type (prop.property_type)) { + return false; + } + + if (type_sym is Class && prop.base_interface_property != null && + !is_gobject_property (prop.base_interface_property)) { + return false; + } + + if (!prop.name[0].isalpha ()) { + // GObject requires properties to start with a letter + return false; + } + + if (type_sym is Interface && !prop.is_abstract && !prop.external && !prop.external_package) { + // GObject does not support non-abstract interface properties, + // however we assume external properties always are GObject properties + return false; + } + + if (type_sym is Interface && type_sym.get_attribute ("DBus") != null) { + // GObject properties not currently supported in D-Bus interfaces + return false; + } + + return true; + } + + public bool is_gobject_property_type (DataType property_type) { + var st = property_type.data_type as Struct; + if (st != null && (!st.get_attribute_bool ("CCode", "has_type_id", true) || property_type.nullable)) { + return false; + } + + if (property_type is ArrayType && ((ArrayType) property_type).element_type.data_type != string_type.data_type) { + return false; + } + + var d = property_type as DelegateType; + if (d != null && d.delegate_symbol.has_target) { + return false; + } + + return true; + } + public bool check_arguments (Expression expr, DataType mtype, List<Parameter> params, List<Expression> args) { bool error = false; |