indexer: handle DecltypeType and empty main file; diag: -Wno-unused-function for headers

Don't replace name with qualified name in Cls::*name
This commit is contained in:
Fangrui Song 2018-11-22 20:07:39 -08:00
parent afa654f0d1
commit f6fca76088
2 changed files with 27 additions and 7 deletions

View File

@ -481,6 +481,9 @@ void *DiagnosticMain(void *manager_) {
BuildCompilerInvocation(session->file.args, FS);
if (!CI)
continue;
// If main file is a header, add -Wno-unused-function
if (lookupExtension(session->file.filename).second)
CI->getDiagnosticOpts().Warnings.push_back("no-unused-function");
CI->getDiagnosticOpts().IgnoreWarnings = false;
CI->getLangOpts()->SpellChecking = g_config->diagnostics.spellChecking;
StoreDiags DC(path);

View File

@ -527,11 +527,12 @@ public:
// e.g. operator type-parameter-1
i = 0;
def.short_name_offset = 0;
} else if (short_name.size() && (!i || name[i - 1] != ':')) {
} else if (short_name.empty() || (i >= 2 && name[i - 2] == ':')) {
// Don't replace name with qualified name in ns::name Cls::*name
def.short_name_offset = i;
} else {
name.replace(i, short_name.size(), qualified);
def.short_name_offset = i + qualified.size() - short_name.size();
} else {
def.short_name_offset = i;
}
def.short_name_size = short_name.size();
for (int paren = 0; i; i--) {
@ -552,7 +553,7 @@ public:
std::string_view qualified, IndexVar::Def &def) {
QualType T;
const Expr *init = nullptr;
bool binding = false;
bool deduced = false;
if (auto *VD = dyn_cast<VarDecl>(D)) {
T = VD->getType();
init = VD->getAnyInitializer();
@ -562,9 +563,21 @@ public:
init = FD->getInClassInitializer();
} else if (auto *BD = dyn_cast<BindingDecl>(D)) {
T = BD->getType();
binding = true;
deduced = true;
}
if (!T.isNull() && (binding || T->getContainedDeducedType())) {
if (!T.isNull()) {
if (T->getContainedDeducedType()) {
deduced = true;
} else if (auto *DT = dyn_cast<DecltypeType>(T)) {
// decltype(y) x;
while (DT && !DT->getUnderlyingType().isNull()) {
T = DT->getUnderlyingType();
DT = dyn_cast<DecltypeType>(T);
}
deduced = true;
}
}
if (!T.isNull() && deduced) {
SmallString<256> Str;
llvm::raw_svector_ostream OS(Str);
PrintingPolicy PP = GetDefaultPolicy();
@ -671,7 +684,11 @@ public:
public:
IndexDataConsumer(IndexParam &param) : param(param) {}
void initialize(ASTContext &Ctx) override { this->Ctx = param.Ctx = &Ctx; }
void initialize(ASTContext &Ctx) override {
this->Ctx = param.Ctx = &Ctx;
SourceManager &SM = Ctx.getSourceManager();
(void)param.ConsumeFile(*SM.getFileEntryForID(SM.getMainFileID()));
}
bool handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles,
ArrayRef<index::SymbolRelation> Relations,
#if LLVM_VERSION_MAJOR >= 7