From: Jürg Billeter Date: Sat, 21 Aug 2010 10:07:28 +0000 (+0200) Subject: Improve performance of SemanticAnalyzer.is_type_accessible X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95285bc021348808a334fa7bd26aaa5e790d045a;p=thirdparty%2Fvala.git Improve performance of SemanticAnalyzer.is_type_accessible --- diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala index ee57df57d..9c651e739 100644 --- a/vala/valaarraytype.vala +++ b/vala/valaarraytype.vala @@ -232,8 +232,8 @@ public class Vala.ArrayType : ReferenceType { } } - public override List get_symbols () { - return element_type.get_symbols (); + public override bool is_accessible (Symbol sym) { + return element_type.is_accessible (sym); } public override bool check (SemanticAnalyzer analyzer) { diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala index 67bba3245..aa838d1e3 100644 --- a/vala/valadatatype.vala +++ b/vala/valadatatype.vala @@ -435,17 +435,12 @@ public abstract class Vala.DataType : CodeNode { return false; } - /** - * Returns a list of symbols that define this type. - * - * @return symbol list - */ - public virtual List get_symbols () { - var symbols = new ArrayList (); + // check whether this type is at least as accessible as the specified symbol + public virtual bool is_accessible (Symbol sym) { if (data_type != null) { - symbols.add (data_type); + return data_type.is_accessible (sym); } - return symbols; + return true; } public virtual Symbol? get_member (string member_name) { diff --git a/vala/valadelegatetype.vala b/vala/valadelegatetype.vala index 5e4938503..c904caf29 100644 --- a/vala/valadelegatetype.vala +++ b/vala/valadelegatetype.vala @@ -93,10 +93,8 @@ public class Vala.DelegateType : DataType { } } - public override List get_symbols () { - var symbols = new ArrayList (); - symbols.add (delegate_symbol); - return symbols; + public override bool is_accessible (Symbol sym) { + return delegate_symbol.is_accessible (sym); } public override string? get_type_id () { diff --git a/vala/valapointertype.vala b/vala/valapointertype.vala index f1b318d9a..9d11d8d34 100644 --- a/vala/valapointertype.vala +++ b/vala/valapointertype.vala @@ -118,8 +118,8 @@ public class Vala.PointerType : DataType { return SemanticAnalyzer.symbol_lookup_inherited (base_symbol, member_name); } - public override List get_symbols () { - return base_type.get_symbols (); + public override bool is_accessible (Symbol sym) { + return base_type.is_accessible (sym); } public override string? get_type_id () { diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 0d9057ffa..576412c37 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -241,16 +241,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { // check whether type is at least as accessible as the specified symbol public bool is_type_accessible (Symbol sym, DataType type) { - foreach (Symbol type_symbol in type.get_symbols ()) { - Scope method_scope = sym.get_top_accessible_scope (); - Scope type_scope = type_symbol.get_top_accessible_scope (); - if ((method_scope == null && type_scope != null) - || (method_scope != null && !method_scope.is_subscope_of (type_scope))) { - return false; - } - } - - return true; + return type.is_accessible (sym); } public DataType? get_value_type_for_symbol (Symbol sym, bool lvalue) { diff --git a/vala/valasignaltype.vala b/vala/valasignaltype.vala index 11a110933..6ab5568cc 100644 --- a/vala/valasignaltype.vala +++ b/vala/valasignaltype.vala @@ -113,9 +113,7 @@ public class Vala.SignalType : DataType { return null; } - public override List get_symbols () { - var symbols = new ArrayList (); - symbols.add (signal_symbol); - return symbols; + public override bool is_accessible (Symbol sym) { + return signal_symbol.is_accessible (sym); } } diff --git a/vala/valasymbol.vala b/vala/valasymbol.vala index fd74c6ce7..cfe25402c 100644 --- a/vala/valasymbol.vala +++ b/vala/valasymbol.vala @@ -534,6 +534,18 @@ public abstract class Vala.Symbol : CodeNode { return null; } + + // check whether this symbol is at least as accessible as the specified symbol + public bool is_accessible (Symbol sym) { + Scope sym_scope = sym.get_top_accessible_scope (); + Scope this_scope = this.get_top_accessible_scope (); + if ((sym_scope == null && this_scope != null) + || (sym_scope != null && !sym_scope.is_subscope_of (this_scope))) { + return false; + } + + return true; + } } public enum Vala.SymbolAccessibility {