Fix goto def when implicit functions are called.

Don't import the implicit functions into the 'all symbols' structure. This fixes symbol lookup.
This commit is contained in:
Jacob Dufault 2017-05-22 23:57:46 -07:00
parent 2e4c5474da
commit ee90938b28
3 changed files with 17 additions and 18 deletions

View File

@ -87,13 +87,15 @@ struct IndexFuncRef {
IndexFuncRef(Range loc, bool is_implicit) : id(IndexFuncId((size_t)-1)), loc(loc), is_implicit(is_implicit) {}
inline bool operator==(const IndexFuncRef& other) {
return id == other.id && loc == other.loc;
return id == other.id && loc == other.loc && is_implicit == other.is_implicit;
}
inline bool operator!=(const IndexFuncRef& other) { return !(*this == other); }
inline bool operator<(const IndexFuncRef& other) const {
if (id < other.id)
return true;
return id == other.id && loc < other.loc;
if (id == other.id && loc < other.loc)
return true;
return id == other.id && loc == other.loc && is_implicit < other.is_implicit;
}
};

View File

@ -205,8 +205,10 @@ QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) {
add_all_symbols(id_map.ToSymbol(func.id), decl);
add_outline(id_map.ToSymbol(func.id), decl);
}
for (const IndexFuncRef& caller : func.callers)
for (const IndexFuncRef& caller : func.callers) {
if (caller.is_implicit) continue;
add_all_symbols(id_map.ToSymbol(func.id), caller.loc);
}
}
for (const IndexVar& var : indexed.vars) {
if (var.def.definition_spelling.has_value())
@ -339,7 +341,7 @@ QueryVarId IdMap::ToQuery(IndexVarId id) const {
return QueryVarId(cached_var_ids_.find(id)->second);
}
QueryFuncRef IdMap::ToQuery(IndexFuncRef ref) const {
return QueryFuncRef(ToQuery(ref.id), ToQuery(ref.loc));
return QueryFuncRef(ToQuery(ref.id), ToQuery(ref.loc), ref.is_implicit);
}
optional<QueryLocation> IdMap::ToQuery(optional<Range> range) const {

View File

@ -100,31 +100,26 @@ struct SymbolRef {
MAKE_REFLECT_STRUCT(SymbolRef, idx, loc);
struct QueryFuncRef {
QueryFuncId id() const {
assert(has_id());
return id_;
}
bool has_id() const {
return id_.id != -1;
}
QueryFuncId id_;
QueryFuncId id;
QueryLocation loc;
bool is_implicit = false;
QueryFuncRef() {} // Do not use, needed for reflect.
QueryFuncRef(QueryFuncId id, QueryLocation loc) : id_(id), loc(loc) {}
QueryFuncRef(QueryFuncId id, QueryLocation loc, bool is_implicit) : id(id), loc(loc), is_implicit(is_implicit) {}
bool operator==(const QueryFuncRef& that) const {
return id_ == that.id_ && loc == that.loc;
return id == that.id && loc == that.loc && is_implicit == that.is_implicit;
}
bool operator!=(const QueryFuncRef& that) const { return !(*this == that); }
bool operator<(const QueryFuncRef& that) const {
if (id_ < that.id_)
if (id < that.id)
return true;
return id_ == that.id_ && loc.range.start < that.loc.range.start;
if (id == that.id && loc.range.start < that.loc.range.start)
return true;
return id == that.id && loc.range.start == that.loc.range.start && is_implicit < that.is_implicit;
}
};
MAKE_REFLECT_STRUCT(QueryFuncRef, id_, loc);
MAKE_REFLECT_STRUCT(QueryFuncRef, id, loc, is_implicit);
// There are two sources of reindex updates: the (single) definition of a
// symbol has changed, or one of many users of the symbol has changed.