diff options
author | John Thompson <John.Thompson.JTSoftware@gmail.com> | 2014-04-23 12:57:01 +0000 |
---|---|---|
committer | John Thompson <John.Thompson.JTSoftware@gmail.com> | 2014-04-23 12:57:01 +0000 |
commit | 9be87f878588e7ed414dbfa29805883cc9cbb885 (patch) | |
tree | 1ce960127f08105e2ab290221b1106441d34d757 /lib/Sema | |
parent | 0f0e18f77f5ceaee634653c3a80f79298d7b7407 (diff) | |
download | clang-9be87f878588e7ed414dbfa29805883cc9cbb885.tar.gz |
Initial implementation of -modules-earch-all option, for searching for symbols in non-imported modules.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206977 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaCXXScopeSpec.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 15 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 8 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 7 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/SemaExprMember.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/SemaInit.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 36 | ||||
-rw-r--r-- | lib/Sema/SemaOpenMP.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateVariadic.cpp | 2 |
12 files changed, 69 insertions, 25 deletions
diff --git a/lib/Sema/SemaCXXScopeSpec.cpp b/lib/Sema/SemaCXXScopeSpec.cpp index 7d038f72e9..707d1b2e81 100644 --- a/lib/Sema/SemaCXXScopeSpec.cpp +++ b/lib/Sema/SemaCXXScopeSpec.cpp @@ -547,7 +547,8 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, Found.clear(); if (TypoCorrection Corrected = CorrectTypo(Found.getLookupNameInfo(), Found.getLookupKind(), S, - &SS, Validator, LookupCtx, EnteringContext)) { + &SS, Validator, CTK_ErrorRecovery, LookupCtx, + EnteringContext)) { if (LookupCtx) { bool DroppedSpecifier = Corrected.WillReplaceSpecifier() && diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 50462b7927..7603e2c254 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -218,7 +218,8 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, if (CorrectedII) { TypeNameValidatorCCC Validator(true, isClassName); TypoCorrection Correction = CorrectTypo(Result.getLookupNameInfo(), - Kind, S, SS, Validator); + Kind, S, SS, Validator, + CTK_ErrorRecovery); IdentifierInfo *NewII = Correction.getCorrectionAsIdentifierInfo(); TemplateTy Template; bool MemberOfUnknownSpecialization; @@ -408,7 +409,7 @@ bool Sema::DiagnoseUnknownTypeName(IdentifierInfo *&II, TypeNameValidatorCCC Validator(false, false, AllowClassTemplates); if (TypoCorrection Corrected = CorrectTypo(DeclarationNameInfo(II, IILoc), LookupOrdinaryName, S, SS, - Validator)) { + Validator, CTK_ErrorRecovery)) { if (Corrected.isKeyword()) { // We corrected to a keyword. diagnoseTypo(Corrected, PDiag(diag::err_unknown_typename_suggest) << II); @@ -650,7 +651,8 @@ Corrected: SecondTry = true; if (TypoCorrection Corrected = CorrectTypo(Result.getLookupNameInfo(), Result.getLookupKind(), S, - &SS, *CCC)) { + &SS, *CCC, + CTK_ErrorRecovery)) { unsigned UnqualifiedDiag = diag::err_undeclared_var_use_suggest; unsigned QualifiedDiag = diag::err_no_member_suggest; @@ -1422,7 +1424,7 @@ ObjCInterfaceDecl *Sema::getObjCInterfaceDecl(IdentifierInfo *&Id, DeclFilterCCC<ObjCInterfaceDecl> Validator; if (TypoCorrection C = CorrectTypo(DeclarationNameInfo(Id, IdLoc), LookupOrdinaryName, TUScope, NULL, - Validator)) { + Validator, CTK_ErrorRecovery)) { diagnoseTypo(C, PDiag(diag::err_undef_interface_suggest) << Id); IDecl = C.getCorrectionDeclAs<ObjCInterfaceDecl>(); Id = IDecl->getIdentifier(); @@ -6160,7 +6162,7 @@ static NamedDecl *DiagnoseInvalidRedeclaration( } else if ((Correction = SemaRef.CorrectTypo( Prev.getLookupNameInfo(), Prev.getLookupKind(), S, &ExtraArgs.D.getCXXScopeSpec(), Validator, - IsLocalFriend ? 0 : NewDC))) { + Sema::CTK_ErrorRecovery, IsLocalFriend ? 0 : NewDC))) { // Set up everything for the call to ActOnFunctionDeclarator ExtraArgs.D.SetIdentifier(Correction.getCorrectionAsIdentifierInfo(), ExtraArgs.D.getIdentifierLoc()); @@ -10100,7 +10102,8 @@ NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, TypoCorrection Corrected; DeclFilterCCC<FunctionDecl> Validator; if (S && (Corrected = CorrectTypo(DeclarationNameInfo(&II, Loc), - LookupOrdinaryName, S, 0, Validator))) + LookupOrdinaryName, S, 0, Validator, + CTK_NonError))) diagnoseTypo(Corrected, PDiag(diag::note_function_suggestion), /*ErrorRecovery*/false); } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 197518f99e..e3bedf78e6 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2605,7 +2605,7 @@ Sema::BuildMemInitializer(Decl *ConstructorD, MemInitializerValidatorCCC Validator(ClassDecl); if (R.empty() && BaseType.isNull() && (Corr = CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, &SS, - Validator, ClassDecl))) { + Validator, CTK_ErrorRecovery, ClassDecl))) { if (FieldDecl *Member = Corr.getCorrectionDeclAs<FieldDecl>()) { // We have found a non-static data member with a similar // name to what was typed; complain and initialize that @@ -6900,7 +6900,8 @@ static bool TryNamespaceTypoCorrection(Sema &S, LookupResult &R, Scope *Sc, R.clear(); if (TypoCorrection Corrected = S.CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), Sc, &SS, - Validator)) { + Validator, + Sema::CTK_ErrorRecovery)) { if (DeclContext *DC = S.computeDeclContext(SS, false)) { std::string CorrectedStr(Corrected.getAsString(S.getLangOpts())); bool DroppedSpecifier = Corrected.WillReplaceSpecifier() && @@ -7471,7 +7472,8 @@ NamedDecl *Sema::BuildUsingDeclaration(Scope *S, AccessSpecifier AS, UsingValidatorCCC CCC(HasTypenameKeyword, IsInstantiation, CurContext->isRecord()); if (TypoCorrection Corrected = CorrectTypo(R.getLookupNameInfo(), - R.getLookupKind(), S, &SS, CCC)){ + R.getLookupKind(), S, &SS, CCC, + CTK_ErrorRecovery)){ // We reject any correction for which ND would be NULL. NamedDecl *ND = Corrected.getCorrectionDecl(); R.setLookupName(Corrected.getCorrection()); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index d59dd8b995..7fbca6aadb 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -524,7 +524,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, ObjCInterfaceValidatorCCC Validator(IDecl); if (TypoCorrection Corrected = CorrectTypo( DeclarationNameInfo(SuperName, SuperLoc), LookupOrdinaryName, TUScope, - NULL, Validator)) { + NULL, Validator, CTK_ErrorRecovery)) { diagnoseTypo(Corrected, PDiag(diag::err_undef_superclass_suggest) << SuperName << ClassName); PrevDecl = Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>(); @@ -794,7 +794,7 @@ Sema::FindProtocolDeclaration(bool WarnOnDeclarations, DeclFilterCCC<ObjCProtocolDecl> Validator; TypoCorrection Corrected = CorrectTypo( DeclarationNameInfo(ProtocolId[i].first, ProtocolId[i].second), - LookupObjCProtocolName, TUScope, NULL, Validator); + LookupObjCProtocolName, TUScope, NULL, Validator, CTK_ErrorRecovery); if ((PDecl = Corrected.getCorrectionDeclAs<ObjCProtocolDecl>())) diagnoseTypo(Corrected, PDiag(diag::err_undeclared_protocol_suggest) << ProtocolId[i].first); @@ -1034,7 +1034,8 @@ Decl *Sema::ActOnStartClassImplementation( ObjCInterfaceValidatorCCC Validator; TypoCorrection Corrected = CorrectTypo(DeclarationNameInfo(ClassName, ClassLoc), - LookupOrdinaryName, TUScope, NULL, Validator); + LookupOrdinaryName, TUScope, NULL, Validator, + CTK_NonError); if (Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>()) { // Suggest the (potentially) correct interface name. Don't provide a // code-modification hint or use the typo name for recovery, because diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index a38c7c1ef8..1c6cfb8484 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1843,7 +1843,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, // We didn't find anything, so try to correct for a typo. TypoCorrection Corrected; if (S && (Corrected = CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), - S, &SS, CCC))) { + S, &SS, CCC, CTK_ErrorRecovery))) { std::string CorrectedStr(Corrected.getAsString(getLangOpts())); bool DroppedSpecifier = Corrected.WillReplaceSpecifier() && Name.getAsString() == CorrectedStr; @@ -4004,7 +4004,8 @@ static TypoCorrection TryTypoCorrectionForCall(Sema &S, Expr *Fn, if (TypoCorrection Corrected = S.CorrectTypo( DeclarationNameInfo(FuncName, NameLoc), Sema::LookupOrdinaryName, - S.getScopeForContext(S.CurContext), NULL, CCC)) { + S.getScopeForContext(S.CurContext), NULL, CCC, + Sema::CTK_ErrorRecovery)) { if (NamedDecl *ND = Corrected.getCorrectionDecl()) { if (Corrected.isOverloaded()) { OverloadCandidateSet OCS(NameLoc, OverloadCandidateSet::CSK_Normal); diff --git a/lib/Sema/SemaExprMember.cpp b/lib/Sema/SemaExprMember.cpp index 675c69fa88..95e3668f33 100644 --- a/lib/Sema/SemaExprMember.cpp +++ b/lib/Sema/SemaExprMember.cpp @@ -627,7 +627,8 @@ LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R, RecordMemberExprValidatorCCC Validator(RTy); TypoCorrection Corrected = SemaRef.CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), NULL, - &SS, Validator, DC); + &SS, Validator, + Sema::CTK_ErrorRecovery, DC); R.clear(); if (Corrected.isResolved() && !Corrected.isKeyword()) { R.setLookupName(Corrected.getCorrection()); @@ -1270,7 +1271,8 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr, Validator.IsObjCIvarLookup = IsArrow; if (TypoCorrection Corrected = CorrectTypo(R.getLookupNameInfo(), LookupMemberName, NULL, NULL, - Validator, IDecl)) { + Validator, CTK_ErrorRecovery, + IDecl)) { IV = Corrected.getCorrectionDeclAs<ObjCIvarDecl>(); diagnoseTypo(Corrected, PDiag(diag::err_typecheck_member_reference_ivar_suggest) diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index d316c13f94..7b0db1cfc1 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -1669,7 +1669,7 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, DeclFilterCCC<ObjCPropertyDecl> Validator; if (TypoCorrection Corrected = CorrectTypo( DeclarationNameInfo(MemberName, MemberLoc), LookupOrdinaryName, NULL, - NULL, Validator, IFace, false, OPT)) { + NULL, Validator, CTK_ErrorRecovery, IFace, false, OPT)) { diagnoseTypo(Corrected, PDiag(diag::err_property_not_found_suggest) << MemberName << QualType(OPT, 0)); DeclarationName TypoResult = Corrected.getCorrection(); @@ -1901,7 +1901,8 @@ Sema::ObjCMessageKind Sema::getObjCMessageKind(Scope *S, ObjCInterfaceOrSuperCCC Validator(getCurMethodDecl()); if (TypoCorrection Corrected = CorrectTypo(Result.getLookupNameInfo(), Result.getLookupKind(), S, - NULL, Validator, NULL, false, NULL, false)) { + NULL, Validator, CTK_ErrorRecovery, NULL, false, NULL, + false)) { if (Corrected.isKeyword()) { // If we've found the keyword "super" (the only keyword that would be // returned by CorrectTypo), this is a send to super. diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 9c90ac0d9a..2cf5598581 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -1816,7 +1816,7 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity, if (TypoCorrection Corrected = SemaRef.CorrectTypo( DeclarationNameInfo(FieldName, D->getFieldLoc()), Sema::LookupMemberName, /*Scope=*/ 0, /*SS=*/ 0, Validator, - RT->getDecl())) { + Sema::CTK_ErrorRecovery, RT->getDecl())) { SemaRef.diagnoseTypo( Corrected, SemaRef.PDiag(diag::err_field_designator_unknown_suggest) diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 779d2d48e7..c0d49a7dd9 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -23,6 +23,9 @@ #include "clang/AST/ExprCXX.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/LangOptions.h" +#include "clang/Lex/HeaderSearch.h" +#include "clang/Lex/ModuleLoader.h" +#include "clang/Lex/Preprocessor.h" #include "clang/Sema/DeclSpec.h" #include "clang/Sema/ExternalSemaSource.h" #include "clang/Sema/Overload.h" @@ -32,6 +35,8 @@ #include "clang/Sema/SemaInternal.h" #include "clang/Sema/TemplateDeduction.h" #include "clang/Sema/TypoCorrection.h" +#include "clang/Serialization/GlobalModuleIndex.h" +#include "clang/Serialization/Module.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" @@ -3924,6 +3929,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, + CorrectTypoKind Mode, DeclContext *MemberContext, bool EnteringContext, const ObjCObjectPointerType *OPT, @@ -3978,10 +3984,36 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, if (getLangOpts().AltiVec && Typo->isStr("vector")) return TypoCorrection(); - NamespaceSpecifierSet Namespaces(Context, CurContext, SS); - TypoCorrectionConsumer Consumer(*this, Typo); + // Get the module loader (usually compiler instance). + ModuleLoader &Loader = PP.getModuleLoader(); + + // Look for the symbol in non-imported modules, but only if an error + // actually occurred. + if ((Mode == CTK_ErrorRecovery) && !Loader.buildingModule() && + getLangOpts().Modules && getLangOpts().ModulesSearchAll) { + // Load global module index, or retrieve a previously loaded one. + GlobalModuleIndex *GlobalIndex = Loader.loadGlobalModuleIndex( + TypoName.getLocStart()); + + // Only if we have a global index. + if (GlobalIndex) { + GlobalModuleIndex::HitSet FoundModules; + + // Find the modules that reference the identifier. + // Note that this only finds top-level modules. + // We'll let diagnoseTypo find the actual declaration module. + if (GlobalIndex->lookupIdentifier(Typo->getName(), FoundModules)) { + TypoCorrection TC(TypoName.getName(), (NestedNameSpecifier *)0, 0); + TC.setCorrectionRange(SS, TypoName); + TC.setRequiresImport(true); + } + } + } + + NamespaceSpecifierSet Namespaces(Context, CurContext, SS); + // If a callback object considers an empty typo correction candidate to be // viable, assume it does not do any actual validation of the candidates. TypoCorrection EmptyCorrection; diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 0c592a6144..b4d359edb4 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -429,7 +429,7 @@ ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, if (!Lookup.isSingleResult()) { VarDeclFilterCCC Validator(*this); if (TypoCorrection Corrected = CorrectTypo(Id, LookupOrdinaryName, CurScope, - 0, Validator)) { + 0, Validator, CTK_ErrorRecovery)) { diagnoseTypo(Corrected, PDiag(Lookup.empty()? diag::err_undeclared_var_use_suggest : diag::err_omp_expected_var_arg_suggest) diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index a7764d8df9..64c3263805 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -325,7 +325,8 @@ void Sema::LookupTemplateName(LookupResult &Found, FilterCCC.WantCXXNamedCasts = true; if (TypoCorrection Corrected = CorrectTypo(Found.getLookupNameInfo(), Found.getLookupKind(), S, &SS, - FilterCCC, LookupCtx)) { + FilterCCC, CTK_ErrorRecovery, + LookupCtx)) { Found.setLookupName(Corrected.getCorrection()); if (Corrected.getCorrectionDecl()) Found.addDecl(Corrected.getCorrectionDecl()); diff --git a/lib/Sema/SemaTemplateVariadic.cpp b/lib/Sema/SemaTemplateVariadic.cpp index de850e3901..8439f9f7d0 100644 --- a/lib/Sema/SemaTemplateVariadic.cpp +++ b/lib/Sema/SemaTemplateVariadic.cpp @@ -810,7 +810,7 @@ ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S, case LookupResult::NotFoundInCurrentInstantiation: if (TypoCorrection Corrected = CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, 0, - Validator)) { + Validator, CTK_ErrorRecovery)) { diagnoseTypo(Corrected, PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name, PDiag(diag::note_parameter_pack_here)); |