Commit f870d093 authored by Jürg Billeter's avatar Jürg Billeter

Improve performance of SemanticAnalyzer.is_type_accessible

parent db40a8ea
...@@ -232,8 +232,8 @@ public class Vala.ArrayType : ReferenceType { ...@@ -232,8 +232,8 @@ public class Vala.ArrayType : ReferenceType {
} }
} }
public override List<Symbol> get_symbols () { public override bool is_accessible (Symbol sym) {
return element_type.get_symbols (); return element_type.is_accessible (sym);
} }
public override bool check (SemanticAnalyzer analyzer) { public override bool check (SemanticAnalyzer analyzer) {
......
...@@ -435,17 +435,12 @@ public abstract class Vala.DataType : CodeNode { ...@@ -435,17 +435,12 @@ public abstract class Vala.DataType : CodeNode {
return false; return false;
} }
/** // check whether this type is at least as accessible as the specified symbol
* Returns a list of symbols that define this type. public virtual bool is_accessible (Symbol sym) {
*
* @return symbol list
*/
public virtual List<Symbol> get_symbols () {
var symbols = new ArrayList<Symbol> ();
if (data_type != null) { 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) { public virtual Symbol? get_member (string member_name) {
......
...@@ -93,10 +93,8 @@ public class Vala.DelegateType : DataType { ...@@ -93,10 +93,8 @@ public class Vala.DelegateType : DataType {
} }
} }
public override List<Symbol> get_symbols () { public override bool is_accessible (Symbol sym) {
var symbols = new ArrayList<Symbol> (); return delegate_symbol.is_accessible (sym);
symbols.add (delegate_symbol);
return symbols;
} }
public override string? get_type_id () { public override string? get_type_id () {
......
...@@ -118,8 +118,8 @@ public class Vala.PointerType : DataType { ...@@ -118,8 +118,8 @@ public class Vala.PointerType : DataType {
return SemanticAnalyzer.symbol_lookup_inherited (base_symbol, member_name); return SemanticAnalyzer.symbol_lookup_inherited (base_symbol, member_name);
} }
public override List<Symbol> get_symbols () { public override bool is_accessible (Symbol sym) {
return base_type.get_symbols (); return base_type.is_accessible (sym);
} }
public override string? get_type_id () { public override string? get_type_id () {
......
...@@ -241,16 +241,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { ...@@ -241,16 +241,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
// check whether type is at least as accessible as the specified symbol // check whether type is at least as accessible as the specified symbol
public bool is_type_accessible (Symbol sym, DataType type) { public bool is_type_accessible (Symbol sym, DataType type) {
foreach (Symbol type_symbol in type.get_symbols ()) { return type.is_accessible (sym);
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;
} }
public DataType? get_value_type_for_symbol (Symbol sym, bool lvalue) { public DataType? get_value_type_for_symbol (Symbol sym, bool lvalue) {
......
...@@ -113,9 +113,7 @@ public class Vala.SignalType : DataType { ...@@ -113,9 +113,7 @@ public class Vala.SignalType : DataType {
return null; return null;
} }
public override List<Symbol> get_symbols () { public override bool is_accessible (Symbol sym) {
var symbols = new ArrayList<Symbol> (); return signal_symbol.is_accessible (sym);
symbols.add (signal_symbol);
return symbols;
} }
} }
...@@ -497,6 +497,18 @@ public abstract class Vala.Symbol : CodeNode { ...@@ -497,6 +497,18 @@ public abstract class Vala.Symbol : CodeNode {
return null; 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 virtual void add_namespace (Namespace ns) { public virtual void add_namespace (Namespace ns) {
Report.error (ns.source_reference, "unexpected declaration"); Report.error (ns.source_reference, "unexpected declaration");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment