diff options
author | Daniel Espinosa <esodan@gmail.com> | 2018-01-16 09:57:23 -0600 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2018-01-17 11:06:46 +0100 |
commit | ce9af515cd92afa111756d23d353f0e1a0a94e6a (patch) | |
tree | 29b1c5c3056f46e4435e0f8538fce2599b2b17a5 | |
parent | 7c327fe09b65c94089d6c30e393c5d6772d0f7b3 (diff) | |
download | vala-ce9af515cd92afa111756d23d353f0e1a0a94e6a.tar.gz |
vala: Move member lists from Class/Interface up to ObjectTypeSymbol
Members are fields, methods, properties and signals
https://bugzilla.gnome.org/show_bug.cgi?id=789069
-rw-r--r-- | vala/valaclass.vala | 84 | ||||
-rw-r--r-- | vala/valainterface.vala | 83 | ||||
-rw-r--r-- | vala/valaobjecttypesymbol.vala | 99 |
3 files changed, 122 insertions, 144 deletions
diff --git a/vala/valaclass.vala b/vala/valaclass.vala index fdac092e4..b956cd109 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -101,10 +101,6 @@ public class Vala.Class : ObjectTypeSymbol { private List<DataType> base_types = new ArrayList<DataType> (); private List<Constant> constants = new ArrayList<Constant> (); - private List<Field> fields = new ArrayList<Field> (); - private List<Method> methods = new ArrayList<Method> (); - private List<Property> properties = new ArrayList<Property> (); - private List<Signal> signals = new ArrayList<Signal> (); // inner types private List<Class> classes = new ArrayList<Class> (); @@ -254,25 +250,16 @@ public class Vala.Class : ObjectTypeSymbol { * @param f a field */ public override void add_field (Field f) { - fields.add (f); + base.add_field (f); + if (f.access == SymbolAccessibility.PRIVATE && f.binding == MemberBinding.INSTANCE) { has_private_fields = true; } else if (f.access == SymbolAccessibility.PRIVATE && f.binding == MemberBinding.CLASS) { has_class_private_fields = true; } - scope.add (f.name, f); } /** - * Returns a copy of the list of fields. - * - * @return list of fields - */ - public List<Field> get_fields () { - return fields; - } - - /** * Returns a copy of the list of constants. * * @return list of constants @@ -316,32 +303,21 @@ public class Vala.Class : ObjectTypeSymbol { } } - methods.add (m); - if (m.base_interface_type == null) { - scope.add (m.name, m); - } else { - // explicit interface method implementation + base.add_method (m); + // explicit interface method implementation + if (m.base_interface_type != null) { + scope.remove (m.name); scope.add (null, m); } } /** - * Returns a copy of the list of methods. - * - * @return list of methods - */ - public override List<Method> get_methods () { - return methods; - } - - /** * Adds the specified property as a member to this class. * * @param prop a property */ public override void add_property (Property prop) { - properties.add (prop); - scope.add (prop.name, prop); + base.add_property (prop); prop.this_parameter = new Parameter ("this", get_this_type ()); prop.scope.add (prop.this_parameter.name, prop.this_parameter); @@ -352,34 +328,6 @@ public class Vala.Class : ObjectTypeSymbol { } /** - * Returns a copy of the list of properties. - * - * @return list of properties - */ - public override List<Property> get_properties () { - return properties; - } - - /** - * Adds the specified signal as a member to this class. - * - * @param sig a signal - */ - public override void add_signal (Signal sig) { - signals.add (sig); - scope.add (sig.name, sig); - } - - /** - * Returns a copy of the list of signals. - * - * @return list of signals - */ - public override List<Signal> get_signals () { - return signals; - } - - /** * Adds the specified class as an inner class. * * @param cl a class @@ -475,7 +423,7 @@ public class Vala.Class : ObjectTypeSymbol { en.accept (visitor); } - foreach (Field f in fields) { + foreach (Field f in get_fields ()) { f.accept (visitor); } @@ -483,15 +431,15 @@ public class Vala.Class : ObjectTypeSymbol { c.accept (visitor); } - foreach (Method m in methods) { + foreach (Method m in get_methods ()) { m.accept (visitor); } - foreach (Property prop in properties) { + foreach (Property prop in get_properties ()) { prop.accept (visitor); } - foreach (Signal sig in signals) { + foreach (Signal sig in get_signals ()) { sig.accept (visitor); } @@ -661,7 +609,7 @@ public class Vala.Class : ObjectTypeSymbol { en.check (context); } - foreach (Field f in fields) { + foreach (Field f in get_fields ()) { f.check (context); } @@ -669,11 +617,11 @@ public class Vala.Class : ObjectTypeSymbol { c.check (context); } - foreach (Method m in methods) { + foreach (Method m in get_methods ()) { m.check (context); } - foreach (Property prop in properties) { + foreach (Property prop in get_properties ()) { if (prop.get_attribute ("NoAccessorMethod") != null && !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"); @@ -682,7 +630,7 @@ public class Vala.Class : ObjectTypeSymbol { prop.check (context); } - foreach (Signal sig in signals) { + foreach (Signal sig in get_signals ()) { sig.check (context); } @@ -732,7 +680,7 @@ public class Vala.Class : ObjectTypeSymbol { } if (!external && !external_package && base_class != null && base_class != context.analyzer.gsource_type) { - foreach (Field f in fields) { + foreach (Field f in get_fields ()) { if (f.binding == MemberBinding.INSTANCE) { error = true; Report.error (source_reference, "derived compact classes may not have instance fields"); diff --git a/vala/valainterface.vala b/vala/valainterface.vala index 621c6e8ce..e2d12085c 100644 --- a/vala/valainterface.vala +++ b/vala/valainterface.vala @@ -28,11 +28,7 @@ using GLib; public class Vala.Interface : ObjectTypeSymbol { private List<DataType> prerequisites = new ArrayList<DataType> (); - private List<Method> methods = new ArrayList<Method> (); - private List<Field> fields = new ArrayList<Field> (); private List<Constant> constants = new ArrayList<Constant> (); - private List<Property> properties = new ArrayList<Property> (); - private List<Signal> signals = new ArrayList<Signal> (); private List<Symbol> virtuals = new ArrayList<Symbol> (); // inner types @@ -139,37 +135,7 @@ public class Vala.Interface : ObjectTypeSymbol { m.result_var.is_result = true; } - methods.add (m); - scope.add (m.name, m); - } - - /** - * Returns a copy of the list of methods. - * - * @return list of methods - */ - public override List<Method> get_methods () { - return methods; - } - - /** - * Adds the specified field as a member to this interface. The field - * must be private and static. - * - * @param f a field - */ - public override void add_field (Field f) { - fields.add (f); - scope.add (f.name, f); - } - - /** - * Returns a copy of the list of fields. - * - * @return list of fields - */ - public List<Field> get_fields () { - return fields; + base.add_method (m); } /** @@ -204,41 +170,12 @@ public class Vala.Interface : ObjectTypeSymbol { return; } - properties.add (prop); - scope.add (prop.name, prop); + base.add_property (prop); prop.this_parameter = new Parameter ("this", new ObjectType (this)); prop.scope.add (prop.this_parameter.name, prop.this_parameter); } - /** - * Returns a copy of the list of properties. - * - * @return list of properties - */ - public override List<Property> get_properties () { - return properties; - } - - /** - * Adds the specified signal as a member to this interface. - * - * @param sig a signal - */ - public override void add_signal (Signal sig) { - signals.add (sig); - scope.add (sig.name, sig); - } - - /** - * Returns a copy of the list of signals. - * - * @return list of signals - */ - public override List<Signal> get_signals () { - return signals; - } - public virtual List<Symbol> get_virtuals () { return virtuals; } @@ -301,11 +238,11 @@ public class Vala.Interface : ObjectTypeSymbol { en.accept (visitor); } - foreach (Method m in methods) { + foreach (Method m in get_methods ()) { m.accept (visitor); } - foreach (Field f in fields) { + foreach (Field f in get_fields ()) { f.accept (visitor); } @@ -313,11 +250,11 @@ public class Vala.Interface : ObjectTypeSymbol { c.accept (visitor); } - foreach (Property prop in properties) { + foreach (Property prop in get_properties ()) { prop.accept (visitor); } - foreach (Signal sig in signals) { + foreach (Signal sig in get_signals ()) { sig.accept (visitor); } @@ -426,14 +363,14 @@ public class Vala.Interface : ObjectTypeSymbol { en.check (context); } - foreach (Method m in methods) { + foreach (Method m in get_methods ()) { m.check (context); if (m.is_virtual || m.is_abstract) { virtuals.add (m); } } - foreach (Field f in fields) { + foreach (Field f in get_fields ()) { f.check (context); } @@ -441,14 +378,14 @@ public class Vala.Interface : ObjectTypeSymbol { c.check (context); } - foreach (Signal sig in signals) { + foreach (Signal sig in get_signals ()) { sig.check (context); if (sig.is_virtual) { virtuals.add (sig); } } - foreach (Property prop in properties) { + foreach (Property prop in get_properties ()) { prop.check (context); if (prop.is_virtual || prop.is_abstract) { virtuals.add (prop); diff --git a/vala/valaobjecttypesymbol.vala b/vala/valaobjecttypesymbol.vala index 14fc230da..6f8415032 100644 --- a/vala/valaobjecttypesymbol.vala +++ b/vala/valaobjecttypesymbol.vala @@ -31,13 +31,106 @@ public abstract class Vala.ObjectTypeSymbol : TypeSymbol { private List<TypeParameter> type_parameters = new ArrayList<TypeParameter> (); + private List<Symbol> members = new ArrayList<Symbol> (); + + // member symbols + private List<Field> fields = new ArrayList<Field> (); + private List<Method> methods = new ArrayList<Method> (); + private List<Property> properties = new ArrayList<Property> (); + private List<Signal> signals = new ArrayList<Signal> (); + public ObjectTypeSymbol (string name, SourceReference? source_reference = null, Comment? comment = null) { base (name, source_reference, comment); } - public abstract List<Method> get_methods (); - public abstract List<Signal> get_signals (); - public abstract List<Property> get_properties (); + /** + * Returns the list of members. + * + * @return list of members + */ + public List<Symbol> get_members () { + return members; + } + + /** + * Returns the list of fields. + * + * @return list of fields + */ + public List<Field> get_fields () { + return fields; + } + + /** + * Returns the list of methods. + * + * @return list of methods + */ + public List<Method> get_methods () { + return methods; + } + + /** + * Returns the list of properties. + * + * @return list of properties + */ + public List<Property> get_properties () { + return properties; + } + + /** + * Returns the list of signals. + * + * @return list of signals + */ + public List<Signal> get_signals () { + return signals; + } + + /** + * Adds the specified field as a member to this object-symbol. + * + * @param f a field + */ + public override void add_field (Field f) { + fields.add (f); + members.add (f); + scope.add (f.name, f); + } + + /** + * Adds the specified method as a member to this object-symbol. + * + * @param m a method + */ + public override void add_method (Method m) { + methods.add (m); + members.add (m); + scope.add (m.name, m); + } + + /** + * Adds the specified property as a member to this object-symbol. + * + * @param prop a property + */ + public override void add_property (Property prop) { + properties.add (prop); + members.add (prop); + scope.add (prop.name, prop); + } + + /** + * Adds the specified signal as a member to this object-symbol. + * + * @param sig a signal + */ + public override void add_signal (Signal sig) { + signals.add (sig); + members.add (sig); + scope.add (sig.name, sig); + } /** * Appends the specified parameter to the list of type parameters. |