Fix .. in compdb path; better type alias

This commit is contained in:
Fangrui Song 2018-06-08 18:20:51 -07:00
parent 1830103ec6
commit 9b9bf1cd19
5 changed files with 33 additions and 41 deletions

View File

@ -65,6 +65,15 @@ OUTPUT:
"types": [],
"funcs": [],
"vars": [{
"L": 3348817847649945564,
"R": -1
}, {
"L": 4821094820988543895,
"R": -1
}, {
"L": 15292551660437765731,
"R": -1
}, {
"L": 1963212417280098348,
"R": 0
}],

View File

@ -401,12 +401,9 @@ std::unique_ptr<ClangTranslationUnit> ClangTranslationUnit::Create(
std::unique_ptr<ClangTranslationUnit> ClangTranslationUnit::Reparse(
std::unique_ptr<ClangTranslationUnit> tu,
std::vector<CXUnsavedFile>& unsaved) {
int error_code;
{
error_code = clang_reparseTranslationUnit(
tu->cx_tu, (unsigned)unsaved.size(), unsaved.data(),
clang_defaultReparseOptions(tu->cx_tu));
}
int error_code = clang_reparseTranslationUnit(
tu->cx_tu, (unsigned)unsaved.size(), unsaved.data(),
clang_defaultReparseOptions(tu->cx_tu));
if (error_code != CXError_Success && tu->cx_tu)
EmitDiagnostics("<unknown>", {}, tu->cx_tu);

View File

@ -1655,16 +1655,23 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
case CXIdxEntity_Typedef:
case CXIdxEntity_CXXTypeAlias: {
// Note we want to fetch the first TypeRef. Running
// ResolveCursorType(decl->cursor) would return
// the type of the typedef/using, not the type of the referenced type.
IndexType* alias_of = AddDeclTypeUsages(
db, cursor, nullptr, decl->semanticContainer, decl->lexicalContainer);
IndexType& type = db->ToType(HashUsr(decl->entityInfo->USR));
if (alias_of)
type.def.alias_of = alias_of->usr;
CXType Type = clang_getCursorType(decl->entityInfo->cursor);
CXType CanonType = clang_getCanonicalType(Type);;
if (clang_equalTypes(Type, CanonType) == 0) {
Usr type_usr = ClangType(CanonType).get_usr_hash();
if (db->usr2type.count(type_usr)) {
type.def.alias_of = type_usr;
} else {
// Note we want to fetch the first TypeRef. Running
// ResolveCursorType(decl->cursor) would return
// the type of the typedef/using, not the type of the referenced type.
IndexType* alias_of = AddDeclTypeUsages(
db, cursor, nullptr, decl->semanticContainer, decl->lexicalContainer);
if (alias_of)
type.def.alias_of = alias_of->usr;
}
}
Range spell = cursor.get_spell();
Range extent = cursor.get_extent();
@ -1709,17 +1716,11 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
IndexType& type = db->ToType(HashUsr(decl->entityInfo->USR));
// TODO: Eventually run with this if. Right now I want to iron out bugs
// this may shadow.
// TODO: For type section, verify if this ever runs for non definitions?
// if (!decl->isRedeclaration) {
SetTypeName(type, cursor, decl->semanticContainer, decl->entityInfo->name,
param);
type.def.kind = GetSymbolKind(decl->entityInfo->kind);
if (g_config->index.comments)
type.def.comments = Intern(cursor.get_comments());
// }
if (decl->isDefinition) {
type.def.spell = SetUse(db, spell, sem_parent, Role::Definition);
@ -1781,12 +1782,6 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
}
}
// type_def->alias_of
// type_def->funcs
// type_def->types
// type_def->uses
// type_def->vars
// Add type-level inheritance information.
CXIdxCXXClassDeclInfo const* class_info =
clang_index_getCXXClassDeclInfo(decl);

View File

@ -94,17 +94,9 @@ bool FileNeedsParse(int64_t write_time,
}
// Command-line arguments changed.
auto is_file = [](const std::string& arg) {
return EndsWithAny(arg, {".h", ".c", ".cc", ".cpp", ".hpp", ".m", ".mm"});
};
if (opt_previous_index) {
auto& prev_args = opt_previous_index->args;
bool same = prev_args.size() == args.size();
for (size_t i = 0; i < args.size() && same; ++i) {
same = prev_args[i] == args[i] ||
(is_file(prev_args[i]) && is_file(args[i]));
}
if (!same) {
if (prev_args != args) {
LOG_S(INFO) << "args changed for " << path << (from ? " (via " + *from + ")" : std::string());
return true;
}
@ -483,11 +475,10 @@ void MainLoop() {
Main_OnIndexed(&db, &semantic_cache, &working_files, &*update);
}
// Cleanup and free any unused memory.
FreeUnusedMemory();
if (!did_work)
if (!did_work) {
FreeUnusedMemory();
main_waiter->Wait(on_indexed, on_request);
}
}
}

View File

@ -48,7 +48,7 @@ struct CompileCommandsEntry {
return path;
SmallString<256> Ret;
sys::path::append(Ret, directory, path);
return Ret.str();
return NormalizePath(Ret.str());
}
};
MAKE_REFLECT_STRUCT(CompileCommandsEntry, directory, file, command, args);