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 {
}
}
public override List<Symbol> 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) {
......
......@@ -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<Symbol> get_symbols () {
var symbols = new ArrayList<Symbol> ();
// 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) {
......
......@@ -93,10 +93,8 @@ public class Vala.DelegateType : DataType {
}
}
public override List<Symbol> get_symbols () {
var symbols = new ArrayList<Symbol> ();
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 () {
......
......@@ -118,8 +118,8 @@ public class Vala.PointerType : DataType {
return SemanticAnalyzer.symbol_lookup_inherited (base_symbol, member_name);
}
public override List<Symbol> 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 () {
......
......@@ -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) {
......
......@@ -113,9 +113,7 @@ public class Vala.SignalType : DataType {
return null;
}
public override List<Symbol> get_symbols () {
var symbols = new ArrayList<Symbol> ();
symbols.add (signal_symbol);
return symbols;
public override bool is_accessible (Symbol sym) {
return signal_symbol.is_accessible (sym);
}
}
......@@ -497,6 +497,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 virtual void add_namespace (Namespace ns) {
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