| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/CXXInheritance.h" |
| 16 | #include "clang/AST/Decl.h" |
| 17 | #include "clang/AST/DeclCXX.h" |
| 18 | #include "clang/AST/DeclLookups.h" |
| 19 | #include "clang/AST/DeclObjC.h" |
| 20 | #include "clang/AST/DeclTemplate.h" |
| 21 | #include "clang/AST/Expr.h" |
| 22 | #include "clang/AST/ExprCXX.h" |
| 23 | #include "clang/Basic/Builtins.h" |
| 24 | #include "clang/Basic/LangOptions.h" |
| 25 | #include "clang/Lex/HeaderSearch.h" |
| 26 | #include "clang/Lex/ModuleLoader.h" |
| 27 | #include "clang/Lex/Preprocessor.h" |
| 28 | #include "clang/Sema/DeclSpec.h" |
| 29 | #include "clang/Sema/Lookup.h" |
| 30 | #include "clang/Sema/Overload.h" |
| 31 | #include "clang/Sema/Scope.h" |
| 32 | #include "clang/Sema/ScopeInfo.h" |
| 33 | #include "clang/Sema/Sema.h" |
| 34 | #include "clang/Sema/SemaInternal.h" |
| 35 | #include "clang/Sema/TemplateDeduction.h" |
| 36 | #include "clang/Sema/TypoCorrection.h" |
| 37 | #include "llvm/ADT/STLExtras.h" |
| 38 | #include "llvm/ADT/SmallPtrSet.h" |
| 39 | #include "llvm/ADT/TinyPtrVector.h" |
| 40 | #include "llvm/ADT/edit_distance.h" |
| 41 | #include "llvm/Support/ErrorHandling.h" |
| 42 | #include <algorithm> |
| 43 | #include <iterator> |
| 44 | #include <list> |
| 45 | #include <set> |
| 46 | #include <utility> |
| 47 | #include <vector> |
| 48 | |
| 49 | using namespace clang; |
| 50 | using namespace sema; |
| 51 | |
| 52 | namespace { |
| 53 | class UnqualUsingEntry { |
| 54 | const DeclContext *Nominated; |
| 55 | const DeclContext *CommonAncestor; |
| 56 | |
| 57 | public: |
| 58 | UnqualUsingEntry(const DeclContext *Nominated, |
| 59 | const DeclContext *CommonAncestor) |
| 60 | : Nominated(Nominated), CommonAncestor(CommonAncestor) { |
| 61 | } |
| 62 | |
| 63 | const DeclContext *getCommonAncestor() const { |
| 64 | return CommonAncestor; |
| 65 | } |
| 66 | |
| 67 | const DeclContext *getNominatedNamespace() const { |
| 68 | return Nominated; |
| 69 | } |
| 70 | |
| 71 | |
| 72 | struct Comparator { |
| 73 | bool operator()(const UnqualUsingEntry &L, const UnqualUsingEntry &R) { |
| 74 | return L.getCommonAncestor() < R.getCommonAncestor(); |
| 75 | } |
| 76 | |
| 77 | bool operator()(const UnqualUsingEntry &E, const DeclContext *DC) { |
| 78 | return E.getCommonAncestor() < DC; |
| 79 | } |
| 80 | |
| 81 | bool operator()(const DeclContext *DC, const UnqualUsingEntry &E) { |
| 82 | return DC < E.getCommonAncestor(); |
| 83 | } |
| 84 | }; |
| 85 | }; |
| 86 | |
| 87 | |
| 88 | |
| 89 | class UnqualUsingDirectiveSet { |
| 90 | Sema &SemaRef; |
| 91 | |
| 92 | typedef SmallVector<UnqualUsingEntry, 8> ListTy; |
| 93 | |
| 94 | ListTy list; |
| 95 | llvm::SmallPtrSet<DeclContext*, 8> visited; |
| 96 | |
| 97 | public: |
| 98 | UnqualUsingDirectiveSet(Sema &SemaRef) : SemaRef(SemaRef) {} |
| 99 | |
| 100 | void visitScopeChain(Scope *S, Scope *InnermostFileScope) { |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | DeclContext *InnermostFileDC = InnermostFileScope->getEntity(); |
| 106 | isFileContext()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 106, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(InnermostFileDC && InnermostFileDC->isFileContext()); |
| 107 | |
| 108 | for (; S; S = S->getParent()) { |
| 109 | |
| 110 | |
| 111 | |
| 112 | DeclContext *Ctx = S->getEntity(); |
| 113 | if (Ctx && Ctx->isFileContext()) { |
| 114 | visit(Ctx, Ctx); |
| 115 | } else if (!Ctx || Ctx->isFunctionOrMethod()) { |
| 116 | for (auto *I : S->using_directives()) |
| 117 | if (SemaRef.isVisible(I)) |
| 118 | visit(I, InnermostFileDC); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | void visit(DeclContext *DC, DeclContext *EffectiveDC) { |
| 131 | if (!visited.insert(DC).second) |
| 132 | return; |
| 133 | |
| 134 | addUsingDirectives(DC, EffectiveDC); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | void visit(UsingDirectiveDecl *UD, DeclContext *EffectiveDC) { |
| 141 | DeclContext *NS = UD->getNominatedNamespace(); |
| 142 | if (!visited.insert(NS).second) |
| 143 | return; |
| 144 | |
| 145 | addUsingDirective(UD, EffectiveDC); |
| 146 | addUsingDirectives(NS, EffectiveDC); |
| 147 | } |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | void addUsingDirectives(DeclContext *DC, DeclContext *EffectiveDC) { |
| 153 | SmallVector<DeclContext*, 4> queue; |
| 154 | while (true) { |
| 155 | for (auto UD : DC->using_directives()) { |
| 156 | DeclContext *NS = UD->getNominatedNamespace(); |
| 157 | if (SemaRef.isVisible(UD) && visited.insert(NS).second) { |
| 158 | addUsingDirective(UD, EffectiveDC); |
| 159 | queue.push_back(NS); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if (queue.empty()) |
| 164 | return; |
| 165 | |
| 166 | DC = queue.pop_back_val(); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | void addUsingDirective(UsingDirectiveDecl *UD, DeclContext *EffectiveDC) { |
| 178 | |
| 179 | |
| 180 | DeclContext *Common = UD->getNominatedNamespace(); |
| 181 | while (!Common->Encloses(EffectiveDC)) |
| 182 | Common = Common->getParent(); |
| 183 | Common = Common->getPrimaryContext(); |
| 184 | |
| 185 | list.push_back(UnqualUsingEntry(UD->getNominatedNamespace(), Common)); |
| 186 | } |
| 187 | |
| 188 | void done() { llvm::sort(list, UnqualUsingEntry::Comparator()); } |
| 189 | |
| 190 | typedef ListTy::const_iterator const_iterator; |
| 191 | |
| 192 | const_iterator begin() const { return list.begin(); } |
| 193 | const_iterator end() const { return list.end(); } |
| 194 | |
| 195 | llvm::iterator_range<const_iterator> |
| 196 | getNamespacesFor(DeclContext *DC) const { |
| 197 | return llvm::make_range(std::equal_range(begin(), end(), |
| 198 | DC->getPrimaryContext(), |
| 199 | UnqualUsingEntry::Comparator())); |
| 200 | } |
| 201 | }; |
| 202 | } |
| 203 | |
| 204 | |
| 205 | |
| 206 | static inline unsigned getIDNS(Sema::LookupNameKind NameKind, |
| 207 | bool CPlusPlus, |
| 208 | bool Redeclaration) { |
| 209 | unsigned IDNS = 0; |
| 210 | switch (NameKind) { |
| 211 | case Sema::LookupObjCImplicitSelfParam: |
| 212 | case Sema::LookupOrdinaryName: |
| 213 | case Sema::LookupRedeclarationWithLinkage: |
| 214 | case Sema::LookupLocalFriendName: |
| 215 | IDNS = Decl::IDNS_Ordinary; |
| 216 | if (CPlusPlus) { |
| 217 | IDNS |= Decl::IDNS_Tag | Decl::IDNS_Member | Decl::IDNS_Namespace; |
| 218 | if (Redeclaration) |
| 219 | IDNS |= Decl::IDNS_TagFriend | Decl::IDNS_OrdinaryFriend; |
| 220 | } |
| 221 | if (Redeclaration) |
| 222 | IDNS |= Decl::IDNS_LocalExtern; |
| 223 | break; |
| 224 | |
| 225 | case Sema::LookupOperatorName: |
| 226 | |
| 227 | |
| 228 | (0) . __assert_fail ("!Redeclaration && \"cannot do redeclaration operator lookup\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 228, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Redeclaration && "cannot do redeclaration operator lookup"); |
| 229 | IDNS = Decl::IDNS_NonMemberOperator; |
| 230 | break; |
| 231 | |
| 232 | case Sema::LookupTagName: |
| 233 | if (CPlusPlus) { |
| 234 | IDNS = Decl::IDNS_Type; |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | if (Redeclaration) |
| 242 | IDNS |= Decl::IDNS_Tag | Decl::IDNS_TagFriend | Decl::IDNS_Namespace; |
| 243 | } else { |
| 244 | IDNS = Decl::IDNS_Tag; |
| 245 | } |
| 246 | break; |
| 247 | |
| 248 | case Sema::LookupLabel: |
| 249 | IDNS = Decl::IDNS_Label; |
| 250 | break; |
| 251 | |
| 252 | case Sema::LookupMemberName: |
| 253 | IDNS = Decl::IDNS_Member; |
| 254 | if (CPlusPlus) |
| 255 | IDNS |= Decl::IDNS_Tag | Decl::IDNS_Ordinary; |
| 256 | break; |
| 257 | |
| 258 | case Sema::LookupNestedNameSpecifierName: |
| 259 | IDNS = Decl::IDNS_Type | Decl::IDNS_Namespace; |
| 260 | break; |
| 261 | |
| 262 | case Sema::LookupNamespaceName: |
| 263 | IDNS = Decl::IDNS_Namespace; |
| 264 | break; |
| 265 | |
| 266 | case Sema::LookupUsingDeclName: |
| 267 | (0) . __assert_fail ("Redeclaration && \"should only be used for redecl lookup\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 267, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Redeclaration && "should only be used for redecl lookup"); |
| 268 | IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Member | |
| 269 | Decl::IDNS_Using | Decl::IDNS_TagFriend | Decl::IDNS_OrdinaryFriend | |
| 270 | Decl::IDNS_LocalExtern; |
| 271 | break; |
| 272 | |
| 273 | case Sema::LookupObjCProtocolName: |
| 274 | IDNS = Decl::IDNS_ObjCProtocol; |
| 275 | break; |
| 276 | |
| 277 | case Sema::LookupOMPReductionName: |
| 278 | IDNS = Decl::IDNS_OMPReduction; |
| 279 | break; |
| 280 | |
| 281 | case Sema::LookupOMPMapperName: |
| 282 | IDNS = Decl::IDNS_OMPMapper; |
| 283 | break; |
| 284 | |
| 285 | case Sema::LookupAnyName: |
| 286 | IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Member |
| 287 | | Decl::IDNS_Using | Decl::IDNS_Namespace | Decl::IDNS_ObjCProtocol |
| 288 | | Decl::IDNS_Type; |
| 289 | break; |
| 290 | } |
| 291 | return IDNS; |
| 292 | } |
| 293 | |
| 294 | void LookupResult::configure() { |
| 295 | IDNS = getIDNS(LookupKind, getSema().getLangOpts().CPlusPlus, |
| 296 | isForRedeclaration()); |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | switch (NameInfo.getName().getCXXOverloadedOperator()) { |
| 302 | case OO_New: |
| 303 | case OO_Delete: |
| 304 | case OO_Array_New: |
| 305 | case OO_Array_Delete: |
| 306 | getSema().DeclareGlobalNewDelete(); |
| 307 | break; |
| 308 | |
| 309 | default: |
| 310 | break; |
| 311 | } |
| 312 | |
| 313 | |
| 314 | |
| 315 | if (IdentifierInfo *Id = NameInfo.getName().getAsIdentifierInfo()) { |
| 316 | if (unsigned BuiltinID = Id->getBuiltinID()) { |
| 317 | if (!getSema().Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) |
| 318 | AllowHidden = true; |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | bool LookupResult::sanity() const { |
| 324 | |
| 325 | assert(ResultKind != NotFound || Decls.size() == 0); |
| 326 | assert(ResultKind != Found || Decls.size() == 1); |
| 327 | 1 || (Decls.size() == 1 && isa((*begin())->getUnderlyingDecl()))", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 329, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ResultKind != FoundOverloaded || Decls.size() > 1 || |
| 328 | 1 || (Decls.size() == 1 && isa((*begin())->getUnderlyingDecl()))", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 329, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> (Decls.size() == 1 && |
| 329 | 1 || (Decls.size() == 1 && isa((*begin())->getUnderlyingDecl()))", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 329, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> isa<FunctionTemplateDecl>((*begin())->getUnderlyingDecl()))); |
| 330 | assert(ResultKind != FoundUnresolvedValue || sanityCheckUnresolved()); |
| 331 | 1 || (Decls.size() == 1 && (Ambiguity == AmbiguousBaseSubobjects || Ambiguity == AmbiguousBaseSubobjectTypes))", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 333, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ResultKind != Ambiguous || Decls.size() > 1 || |
| 332 | 1 || (Decls.size() == 1 && (Ambiguity == AmbiguousBaseSubobjects || Ambiguity == AmbiguousBaseSubobjectTypes))", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 333, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> (Decls.size() == 1 && (Ambiguity == AmbiguousBaseSubobjects || |
| 333 | 1 || (Decls.size() == 1 && (Ambiguity == AmbiguousBaseSubobjects || Ambiguity == AmbiguousBaseSubobjectTypes))", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 333, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> Ambiguity == AmbiguousBaseSubobjectTypes))); |
| 334 | assert((Paths != nullptr) == (ResultKind == Ambiguous && |
| 335 | (Ambiguity == AmbiguousBaseSubobjectTypes || |
| 336 | Ambiguity == AmbiguousBaseSubobjects))); |
| 337 | return true; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | void LookupResult::deletePaths(CXXBasePaths *Paths) { |
| 342 | delete Paths; |
| 343 | } |
| 344 | |
| 345 | |
| 346 | |
| 347 | static DeclContext *getContextForScopeMatching(Decl *D) { |
| 348 | |
| 349 | |
| 350 | |
| 351 | DeclContext *DC = D->getLexicalDeclContext(); |
| 352 | if (DC->isFunctionOrMethod()) |
| 353 | return DC; |
| 354 | |
| 355 | |
| 356 | |
| 357 | return D->getDeclContext()->getRedeclContext(); |
| 358 | } |
| 359 | |
| 360 | |
| 361 | |
| 362 | static bool isPreferredLookupResult(Sema &S, Sema::LookupNameKind Kind, |
| 363 | NamedDecl *D, NamedDecl *Existing) { |
| 364 | |
| 365 | |
| 366 | if (Kind == Sema::LookupUsingDeclName && isa<UsingShadowDecl>(D) && |
| 367 | !isa<UsingShadowDecl>(Existing)) |
| 368 | return true; |
| 369 | |
| 370 | auto *DUnderlying = D->getUnderlyingDecl(); |
| 371 | auto *EUnderlying = Existing->getUnderlyingDecl(); |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | if (DUnderlying->getCanonicalDecl() != EUnderlying->getCanonicalDecl()) { |
| 380 | (DUnderlying) && isa(EUnderlying)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 380, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<TypeDecl>(DUnderlying) && isa<TypeDecl>(EUnderlying)); |
| 381 | bool HaveTag = isa<TagDecl>(EUnderlying); |
| 382 | bool WantTag = Kind == Sema::LookupTagName; |
| 383 | return HaveTag != WantTag; |
| 384 | } |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | if (auto *DFD = dyn_cast<FunctionDecl>(DUnderlying)) { |
| 391 | auto *EFD = cast<FunctionDecl>(EUnderlying); |
| 392 | unsigned DMin = DFD->getMinRequiredArguments(); |
| 393 | unsigned EMin = EFD->getMinRequiredArguments(); |
| 394 | |
| 395 | if (DMin != EMin) |
| 396 | return DMin < EMin; |
| 397 | |
| 398 | |
| 399 | } |
| 400 | |
| 401 | |
| 402 | if (auto *DTD = dyn_cast<TemplateDecl>(DUnderlying)) { |
| 403 | auto *ETD = cast<TemplateDecl>(EUnderlying); |
| 404 | unsigned DMin = DTD->getTemplateParameters()->getMinRequiredArguments(); |
| 405 | unsigned EMin = ETD->getTemplateParameters()->getMinRequiredArguments(); |
| 406 | |
| 407 | |
| 408 | |
| 409 | if (DMin != EMin) |
| 410 | return DMin < EMin; |
| 411 | |
| 412 | |
| 413 | |
| 414 | for (unsigned I = DMin, N = DTD->getTemplateParameters()->size(); |
| 415 | I != N; ++I) { |
| 416 | if (!S.hasVisibleDefaultArgument( |
| 417 | ETD->getTemplateParameters()->getParam(I)) && |
| 418 | S.hasVisibleDefaultArgument( |
| 419 | DTD->getTemplateParameters()->getParam(I))) |
| 420 | return true; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | |
| 425 | |
| 426 | if (VarDecl *DVD = dyn_cast<VarDecl>(DUnderlying)) { |
| 427 | VarDecl *EVD = cast<VarDecl>(EUnderlying); |
| 428 | if (EVD->getType()->isIncompleteType() && |
| 429 | !DVD->getType()->isIncompleteType()) { |
| 430 | |
| 431 | return S.isVisible(DVD); |
| 432 | } |
| 433 | return false; |
| 434 | } |
| 435 | |
| 436 | |
| 437 | if (!isa<FunctionDecl>(DUnderlying) && !isa<VarDecl>(DUnderlying)) { |
| 438 | |
| 439 | |
| 440 | return !S.isVisible(Existing); |
| 441 | } |
| 442 | |
| 443 | |
| 444 | for (Decl *Prev = DUnderlying->getPreviousDecl(); Prev; |
| 445 | Prev = Prev->getPreviousDecl()) |
| 446 | if (Prev == EUnderlying) |
| 447 | return true; |
| 448 | return false; |
| 449 | } |
| 450 | |
| 451 | |
| 452 | static bool canHideTag(NamedDecl *D) { |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | D = D->getUnderlyingDecl(); |
| 466 | return isa<VarDecl>(D) || isa<EnumConstantDecl>(D) || isa<FunctionDecl>(D) || |
| 467 | isa<FunctionTemplateDecl>(D) || isa<FieldDecl>(D) || |
| 468 | isa<UnresolvedUsingValueDecl>(D); |
| 469 | } |
| 470 | |
| 471 | |
| 472 | void LookupResult::resolveKind() { |
| 473 | unsigned N = Decls.size(); |
| 474 | |
| 475 | |
| 476 | if (N == 0) { |
| 477 | assert(ResultKind == NotFound || |
| 478 | ResultKind == NotFoundInCurrentInstantiation); |
| 479 | return; |
| 480 | } |
| 481 | |
| 482 | |
| 483 | |
| 484 | if (N == 1) { |
| 485 | NamedDecl *D = (*Decls.begin())->getUnderlyingDecl(); |
| 486 | if (isa<FunctionTemplateDecl>(D)) |
| 487 | ResultKind = FoundOverloaded; |
| 488 | else if (isa<UnresolvedUsingValueDecl>(D)) |
| 489 | ResultKind = FoundUnresolvedValue; |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | |
| 494 | if (ResultKind == Ambiguous) return; |
| 495 | |
| 496 | llvm::SmallDenseMap<NamedDecl*, unsigned, 16> Unique; |
| 497 | llvm::SmallDenseMap<QualType, unsigned, 16> UniqueTypes; |
| 498 | |
| 499 | bool Ambiguous = false; |
| 500 | bool HasTag = false, HasFunction = false; |
| 501 | bool HasFunctionTemplate = false, HasUnresolved = false; |
| 502 | NamedDecl *HasNonFunction = nullptr; |
| 503 | |
| 504 | llvm::SmallVector<NamedDecl*, 4> EquivalentNonFunctions; |
| 505 | |
| 506 | unsigned UniqueTagIndex = 0; |
| 507 | |
| 508 | unsigned I = 0; |
| 509 | while (I < N) { |
| 510 | NamedDecl *D = Decls[I]->getUnderlyingDecl(); |
| 511 | D = cast<NamedDecl>(D->getCanonicalDecl()); |
| 512 | |
| 513 | |
| 514 | if (D->isInvalidDecl() && !(I == 0 && N == 1)) { |
| 515 | Decls[I] = Decls[--N]; |
| 516 | continue; |
| 517 | } |
| 518 | |
| 519 | llvm::Optional<unsigned> ExistingI; |
| 520 | |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) { |
| 526 | QualType T = getSema().Context.getTypeDeclType(TD); |
| 527 | auto UniqueResult = UniqueTypes.insert( |
| 528 | std::make_pair(getSema().Context.getCanonicalType(T), I)); |
| 529 | if (!UniqueResult.second) { |
| 530 | |
| 531 | ExistingI = UniqueResult.first->second; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | |
| 536 | |
| 537 | if (!ExistingI) { |
| 538 | auto UniqueResult = Unique.insert(std::make_pair(D, I)); |
| 539 | if (!UniqueResult.second) { |
| 540 | |
| 541 | ExistingI = UniqueResult.first->second; |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | if (ExistingI) { |
| 546 | |
| 547 | |
| 548 | if (isPreferredLookupResult(getSema(), getLookupKind(), Decls[I], |
| 549 | Decls[*ExistingI])) |
| 550 | Decls[*ExistingI] = Decls[I]; |
| 551 | Decls[I] = Decls[--N]; |
| 552 | continue; |
| 553 | } |
| 554 | |
| 555 | |
| 556 | |
| 557 | if (isa<UnresolvedUsingValueDecl>(D)) { |
| 558 | HasUnresolved = true; |
| 559 | } else if (isa<TagDecl>(D)) { |
| 560 | if (HasTag) |
| 561 | Ambiguous = true; |
| 562 | UniqueTagIndex = I; |
| 563 | HasTag = true; |
| 564 | } else if (isa<FunctionTemplateDecl>(D)) { |
| 565 | HasFunction = true; |
| 566 | HasFunctionTemplate = true; |
| 567 | } else if (isa<FunctionDecl>(D)) { |
| 568 | HasFunction = true; |
| 569 | } else { |
| 570 | if (HasNonFunction) { |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction, |
| 576 | D)) { |
| 577 | EquivalentNonFunctions.push_back(D); |
| 578 | Decls[I] = Decls[--N]; |
| 579 | continue; |
| 580 | } |
| 581 | |
| 582 | Ambiguous = true; |
| 583 | } |
| 584 | HasNonFunction = D; |
| 585 | } |
| 586 | I++; |
| 587 | } |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | if (N > 1 && HideTags && HasTag && !Ambiguous && |
| 599 | (HasFunction || HasNonFunction || HasUnresolved)) { |
| 600 | NamedDecl *OtherDecl = Decls[UniqueTagIndex ? 0 : N - 1]; |
| 601 | if (isa<TagDecl>(Decls[UniqueTagIndex]->getUnderlyingDecl()) && |
| 602 | getContextForScopeMatching(Decls[UniqueTagIndex])->Equals( |
| 603 | getContextForScopeMatching(OtherDecl)) && |
| 604 | canHideTag(OtherDecl)) |
| 605 | Decls[UniqueTagIndex] = Decls[--N]; |
| 606 | else |
| 607 | Ambiguous = true; |
| 608 | } |
| 609 | |
| 610 | |
| 611 | |
| 612 | if (!EquivalentNonFunctions.empty() && !Ambiguous) |
| 613 | getSema().diagnoseEquivalentInternalLinkageDeclarations( |
| 614 | getNameLoc(), HasNonFunction, EquivalentNonFunctions); |
| 615 | |
| 616 | Decls.set_size(N); |
| 617 | |
| 618 | if (HasNonFunction && (HasFunction || HasUnresolved)) |
| 619 | Ambiguous = true; |
| 620 | |
| 621 | if (Ambiguous) |
| 622 | setAmbiguous(LookupResult::AmbiguousReference); |
| 623 | else if (HasUnresolved) |
| 624 | ResultKind = LookupResult::FoundUnresolvedValue; |
| 625 | else if (N > 1 || HasFunctionTemplate) |
| 626 | ResultKind = LookupResult::FoundOverloaded; |
| 627 | else |
| 628 | ResultKind = LookupResult::Found; |
| 629 | } |
| 630 | |
| 631 | void LookupResult::addDeclsFromBasePaths(const CXXBasePaths &P) { |
| 632 | CXXBasePaths::const_paths_iterator I, E; |
| 633 | for (I = P.begin(), E = P.end(); I != E; ++I) |
| 634 | for (DeclContext::lookup_iterator DI = I->Decls.begin(), |
| 635 | DE = I->Decls.end(); DI != DE; ++DI) |
| 636 | addDecl(*DI); |
| 637 | } |
| 638 | |
| 639 | void LookupResult::setAmbiguousBaseSubobjects(CXXBasePaths &P) { |
| 640 | Paths = new CXXBasePaths; |
| 641 | Paths->swap(P); |
| 642 | addDeclsFromBasePaths(*Paths); |
| 643 | resolveKind(); |
| 644 | setAmbiguous(AmbiguousBaseSubobjects); |
| 645 | } |
| 646 | |
| 647 | void LookupResult::setAmbiguousBaseSubobjectTypes(CXXBasePaths &P) { |
| 648 | Paths = new CXXBasePaths; |
| 649 | Paths->swap(P); |
| 650 | addDeclsFromBasePaths(*Paths); |
| 651 | resolveKind(); |
| 652 | setAmbiguous(AmbiguousBaseSubobjectTypes); |
| 653 | } |
| 654 | |
| 655 | void LookupResult::print(raw_ostream &Out) { |
| 656 | Out << Decls.size() << " result(s)"; |
| 657 | if (isAmbiguous()) Out << ", ambiguous"; |
| 658 | if (Paths) Out << ", base paths present"; |
| 659 | |
| 660 | for (iterator I = begin(), E = end(); I != E; ++I) { |
| 661 | Out << "\n"; |
| 662 | (*I)->print(Out, 2); |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | LLVM_DUMP_METHOD void LookupResult::dump() { |
| 667 | llvm::errs() << "lookup results for " << getLookupName().getAsString() |
| 668 | << ":\n"; |
| 669 | for (NamedDecl *D : *this) |
| 670 | D->dump(); |
| 671 | } |
| 672 | |
| 673 | |
| 674 | |
| 675 | static bool LookupBuiltin(Sema &S, LookupResult &R) { |
| 676 | Sema::LookupNameKind NameKind = R.getLookupKind(); |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | if (NameKind == Sema::LookupOrdinaryName || |
| 682 | NameKind == Sema::LookupRedeclarationWithLinkage) { |
| 683 | IdentifierInfo *II = R.getLookupName().getAsIdentifierInfo(); |
| 684 | if (II) { |
| 685 | if (S.getLangOpts().CPlusPlus && NameKind == Sema::LookupOrdinaryName) { |
| 686 | if (II == S.getASTContext().getMakeIntegerSeqName()) { |
| 687 | R.addDecl(S.getASTContext().getMakeIntegerSeqDecl()); |
| 688 | return true; |
| 689 | } else if (II == S.getASTContext().getTypePackElementName()) { |
| 690 | R.addDecl(S.getASTContext().getTypePackElementDecl()); |
| 691 | return true; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | |
| 696 | if (unsigned BuiltinID = II->getBuiltinID()) { |
| 697 | |
| 698 | |
| 699 | if ((S.getLangOpts().CPlusPlus || S.getLangOpts().OpenCL) && |
| 700 | S.Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) |
| 701 | return false; |
| 702 | |
| 703 | if (NamedDecl *D = S.LazilyCreateBuiltin((IdentifierInfo *)II, |
| 704 | BuiltinID, S.TUScope, |
| 705 | R.isForRedeclaration(), |
| 706 | R.getNameLoc())) { |
| 707 | R.addDecl(D); |
| 708 | return true; |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | return false; |
| 715 | } |
| 716 | |
| 717 | |
| 718 | |
| 719 | static bool CanDeclareSpecialMemberFunction(const CXXRecordDecl *Class) { |
| 720 | |
| 721 | if (!Class->getDefinition() || Class->isDependentContext()) |
| 722 | return false; |
| 723 | |
| 724 | |
| 725 | return !Class->isBeingDefined(); |
| 726 | } |
| 727 | |
| 728 | void Sema::ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class) { |
| 729 | if (!CanDeclareSpecialMemberFunction(Class)) |
| 730 | return; |
| 731 | |
| 732 | |
| 733 | if (Class->needsImplicitDefaultConstructor()) |
| 734 | DeclareImplicitDefaultConstructor(Class); |
| 735 | |
| 736 | |
| 737 | if (Class->needsImplicitCopyConstructor()) |
| 738 | DeclareImplicitCopyConstructor(Class); |
| 739 | |
| 740 | |
| 741 | if (Class->needsImplicitCopyAssignment()) |
| 742 | DeclareImplicitCopyAssignment(Class); |
| 743 | |
| 744 | if (getLangOpts().CPlusPlus11) { |
| 745 | |
| 746 | if (Class->needsImplicitMoveConstructor()) |
| 747 | DeclareImplicitMoveConstructor(Class); |
| 748 | |
| 749 | |
| 750 | if (Class->needsImplicitMoveAssignment()) |
| 751 | DeclareImplicitMoveAssignment(Class); |
| 752 | } |
| 753 | |
| 754 | |
| 755 | if (Class->needsImplicitDestructor()) |
| 756 | DeclareImplicitDestructor(Class); |
| 757 | } |
| 758 | |
| 759 | |
| 760 | |
| 761 | static bool isImplicitlyDeclaredMemberFunctionName(DeclarationName Name) { |
| 762 | switch (Name.getNameKind()) { |
| 763 | case DeclarationName::CXXConstructorName: |
| 764 | case DeclarationName::CXXDestructorName: |
| 765 | return true; |
| 766 | |
| 767 | case DeclarationName::CXXOperatorName: |
| 768 | return Name.getCXXOverloadedOperator() == OO_Equal; |
| 769 | |
| 770 | default: |
| 771 | break; |
| 772 | } |
| 773 | |
| 774 | return false; |
| 775 | } |
| 776 | |
| 777 | |
| 778 | |
| 779 | static void DeclareImplicitMemberFunctionsWithName(Sema &S, |
| 780 | DeclarationName Name, |
| 781 | SourceLocation Loc, |
| 782 | const DeclContext *DC) { |
| 783 | if (!DC) |
| 784 | return; |
| 785 | |
| 786 | switch (Name.getNameKind()) { |
| 787 | case DeclarationName::CXXConstructorName: |
| 788 | if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) |
| 789 | if (Record->getDefinition() && CanDeclareSpecialMemberFunction(Record)) { |
| 790 | CXXRecordDecl *Class = const_cast<CXXRecordDecl *>(Record); |
| 791 | if (Record->needsImplicitDefaultConstructor()) |
| 792 | S.DeclareImplicitDefaultConstructor(Class); |
| 793 | if (Record->needsImplicitCopyConstructor()) |
| 794 | S.DeclareImplicitCopyConstructor(Class); |
| 795 | if (S.getLangOpts().CPlusPlus11 && |
| 796 | Record->needsImplicitMoveConstructor()) |
| 797 | S.DeclareImplicitMoveConstructor(Class); |
| 798 | } |
| 799 | break; |
| 800 | |
| 801 | case DeclarationName::CXXDestructorName: |
| 802 | if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) |
| 803 | if (Record->getDefinition() && Record->needsImplicitDestructor() && |
| 804 | CanDeclareSpecialMemberFunction(Record)) |
| 805 | S.DeclareImplicitDestructor(const_cast<CXXRecordDecl *>(Record)); |
| 806 | break; |
| 807 | |
| 808 | case DeclarationName::CXXOperatorName: |
| 809 | if (Name.getCXXOverloadedOperator() != OO_Equal) |
| 810 | break; |
| 811 | |
| 812 | if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) { |
| 813 | if (Record->getDefinition() && CanDeclareSpecialMemberFunction(Record)) { |
| 814 | CXXRecordDecl *Class = const_cast<CXXRecordDecl *>(Record); |
| 815 | if (Record->needsImplicitCopyAssignment()) |
| 816 | S.DeclareImplicitCopyAssignment(Class); |
| 817 | if (S.getLangOpts().CPlusPlus11 && |
| 818 | Record->needsImplicitMoveAssignment()) |
| 819 | S.DeclareImplicitMoveAssignment(Class); |
| 820 | } |
| 821 | } |
| 822 | break; |
| 823 | |
| 824 | case DeclarationName::CXXDeductionGuideName: |
| 825 | S.DeclareImplicitDeductionGuides(Name.getCXXDeductionGuideTemplate(), Loc); |
| 826 | break; |
| 827 | |
| 828 | default: |
| 829 | break; |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | |
| 834 | |
| 835 | static bool LookupDirect(Sema &S, LookupResult &R, const DeclContext *DC) { |
| 836 | bool Found = false; |
| 837 | |
| 838 | |
| 839 | if (S.getLangOpts().CPlusPlus) |
| 840 | DeclareImplicitMemberFunctionsWithName(S, R.getLookupName(), R.getNameLoc(), |
| 841 | DC); |
| 842 | |
| 843 | |
| 844 | DeclContext::lookup_result DR = DC->lookup(R.getLookupName()); |
| 845 | for (NamedDecl *D : DR) { |
| 846 | if ((D = R.getAcceptableDecl(D))) { |
| 847 | R.addDecl(D); |
| 848 | Found = true; |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | if (!Found && DC->isTranslationUnit() && LookupBuiltin(S, R)) |
| 853 | return true; |
| 854 | |
| 855 | if (R.getLookupName().getNameKind() |
| 856 | != DeclarationName::CXXConversionFunctionName || |
| 857 | R.getLookupName().getCXXNameType()->isDependentType() || |
| 858 | !isa<CXXRecordDecl>(DC)) |
| 859 | return Found; |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | |
| 865 | const CXXRecordDecl *Record = cast<CXXRecordDecl>(DC); |
| 866 | if (!Record->isCompleteDefinition()) |
| 867 | return Found; |
| 868 | |
| 869 | |
| 870 | |
| 871 | |
| 872 | auto *ContainedDeducedType = |
| 873 | R.getLookupName().getCXXNameType()->getContainedDeducedType(); |
| 874 | if (R.getLookupName().getNameKind() == |
| 875 | DeclarationName::CXXConversionFunctionName && |
| 876 | ContainedDeducedType && ContainedDeducedType->isUndeducedType()) |
| 877 | return Found; |
| 878 | |
| 879 | for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(), |
| 880 | UEnd = Record->conversion_end(); U != UEnd; ++U) { |
| 881 | FunctionTemplateDecl *ConvTemplate = dyn_cast<FunctionTemplateDecl>(*U); |
| 882 | if (!ConvTemplate) |
| 883 | continue; |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | if (R.isForRedeclaration()) { |
| 890 | R.addDecl(ConvTemplate); |
| 891 | Found = true; |
| 892 | continue; |
| 893 | } |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | TemplateDeductionInfo Info(R.getNameLoc()); |
| 906 | FunctionDecl *Specialization = nullptr; |
| 907 | |
| 908 | const FunctionProtoType *ConvProto |
| 909 | = ConvTemplate->getTemplatedDecl()->getType()->getAs<FunctionProtoType>(); |
| 910 | (0) . __assert_fail ("ConvProto && \"Nonsensical conversion function template type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 910, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ConvProto && "Nonsensical conversion function template type"); |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | FunctionProtoType::ExtProtoInfo EPI = ConvProto->getExtProtoInfo(); |
| 916 | EPI.ExtInfo = EPI.ExtInfo.withCallingConv(CC_C); |
| 917 | EPI.ExceptionSpec = EST_None; |
| 918 | QualType ExpectedType |
| 919 | = R.getSema().Context.getFunctionType(R.getLookupName().getCXXNameType(), |
| 920 | None, EPI); |
| 921 | |
| 922 | |
| 923 | |
| 924 | if (R.getSema().DeduceTemplateArguments(ConvTemplate, nullptr, ExpectedType, |
| 925 | Specialization, Info) |
| 926 | == Sema::TDK_Success) { |
| 927 | R.addDecl(Specialization); |
| 928 | Found = true; |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | return Found; |
| 933 | } |
| 934 | |
| 935 | |
| 936 | static bool |
| 937 | CppNamespaceLookup(Sema &S, LookupResult &R, ASTContext &Context, |
| 938 | DeclContext *NS, UnqualUsingDirectiveSet &UDirs) { |
| 939 | |
| 940 | (0) . __assert_fail ("NS && NS->isFileContext() && \"CppNamespaceLookup() requires namespace!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 940, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(NS && NS->isFileContext() && "CppNamespaceLookup() requires namespace!"); |
| 941 | |
| 942 | |
| 943 | bool Found = LookupDirect(S, R, NS); |
| 944 | |
| 945 | |
| 946 | |
| 947 | for (const UnqualUsingEntry &UUE : UDirs.getNamespacesFor(NS)) |
| 948 | if (LookupDirect(S, R, UUE.getNominatedNamespace())) |
| 949 | Found = true; |
| 950 | |
| 951 | R.resolveKind(); |
| 952 | |
| 953 | return Found; |
| 954 | } |
| 955 | |
| 956 | static bool isNamespaceOrTranslationUnitScope(Scope *S) { |
| 957 | if (DeclContext *Ctx = S->getEntity()) |
| 958 | return Ctx->isFileContext(); |
| 959 | return false; |
| 960 | } |
| 961 | |
| 962 | |
| 963 | |
| 964 | |
| 965 | |
| 966 | |
| 967 | |
| 968 | |
| 969 | static std::pair<DeclContext *, bool> findOuterContext(Scope *S) { |
| 970 | DeclContext *DC = S->getEntity(); |
| 971 | DeclContext *Lexical = nullptr; |
| 972 | for (Scope *OuterS = S->getParent(); OuterS; |
| 973 | OuterS = OuterS->getParent()) { |
| 974 | if (OuterS->getEntity()) { |
| 975 | Lexical = OuterS->getEntity(); |
| 976 | break; |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | |
| 987 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | |
| 992 | |
| 993 | |
| 994 | |
| 995 | |
| 996 | |
| 997 | |
| 998 | |
| 999 | |
| 1000 | |
| 1001 | |
| 1002 | if (!Lexical || !DC || !S->getParent() || |
| 1003 | !S->getParent()->isTemplateParamScope()) |
| 1004 | return std::make_pair(Lexical, false); |
| 1005 | |
| 1006 | |
| 1007 | |
| 1008 | |
| 1009 | Scope *OutermostTemplateScope = S->getParent(); |
| 1010 | while (OutermostTemplateScope->getParent() && |
| 1011 | OutermostTemplateScope->getParent()->isTemplateParamScope()) |
| 1012 | OutermostTemplateScope = OutermostTemplateScope->getParent(); |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | DeclContext *Semantic = DC; |
| 1017 | while (!Semantic->isFileContext()) |
| 1018 | Semantic = Semantic->getParent(); |
| 1019 | |
| 1020 | |
| 1021 | |
| 1022 | |
| 1023 | |
| 1024 | if (Lexical->isFileContext() && !Lexical->Equals(Semantic) && |
| 1025 | Lexical->Encloses(Semantic)) |
| 1026 | return std::make_pair(Semantic, true); |
| 1027 | |
| 1028 | return std::make_pair(Lexical, false); |
| 1029 | } |
| 1030 | |
| 1031 | namespace { |
| 1032 | |
| 1033 | |
| 1034 | struct FindLocalExternScope { |
| 1035 | FindLocalExternScope(LookupResult &R) |
| 1036 | : R(R), OldFindLocalExtern(R.getIdentifierNamespace() & |
| 1037 | Decl::IDNS_LocalExtern) { |
| 1038 | R.setFindLocalExtern(R.getIdentifierNamespace() & |
| 1039 | (Decl::IDNS_Ordinary | Decl::IDNS_NonMemberOperator)); |
| 1040 | } |
| 1041 | void restore() { |
| 1042 | R.setFindLocalExtern(OldFindLocalExtern); |
| 1043 | } |
| 1044 | ~FindLocalExternScope() { |
| 1045 | restore(); |
| 1046 | } |
| 1047 | LookupResult &R; |
| 1048 | bool OldFindLocalExtern; |
| 1049 | }; |
| 1050 | } |
| 1051 | |
| 1052 | bool Sema::CppLookupName(LookupResult &R, Scope *S) { |
| 1053 | (0) . __assert_fail ("getLangOpts().CPlusPlus && \"Can perform only C++ lookup\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1053, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(getLangOpts().CPlusPlus && "Can perform only C++ lookup"); |
| 1054 | |
| 1055 | DeclarationName Name = R.getLookupName(); |
| 1056 | Sema::LookupNameKind NameKind = R.getLookupKind(); |
| 1057 | |
| 1058 | |
| 1059 | |
| 1060 | if (isImplicitlyDeclaredMemberFunctionName(Name)) { |
| 1061 | for (Scope *PreS = S; PreS; PreS = PreS->getParent()) |
| 1062 | if (DeclContext *DC = PreS->getEntity()) |
| 1063 | DeclareImplicitMemberFunctionsWithName(*this, Name, R.getNameLoc(), DC); |
| 1064 | } |
| 1065 | |
| 1066 | |
| 1067 | |
| 1068 | |
| 1069 | Scope *Initial = S; |
| 1070 | IdentifierResolver::iterator |
| 1071 | I = IdResolver.begin(Name), |
| 1072 | IEnd = IdResolver.end(); |
| 1073 | |
| 1074 | |
| 1075 | |
| 1076 | |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | UnqualUsingDirectiveSet UDirs(*this); |
| 1093 | bool VisitedUsingDirectives = false; |
| 1094 | bool LeftStartingScope = false; |
| 1095 | DeclContext *OutsideOfTemplateParamDC = nullptr; |
| 1096 | |
| 1097 | |
| 1098 | FindLocalExternScope FindLocals(R); |
| 1099 | |
| 1100 | for (; S && !isNamespaceOrTranslationUnitScope(S); S = S->getParent()) { |
| 1101 | DeclContext *Ctx = S->getEntity(); |
| 1102 | bool SearchNamespaceScope = true; |
| 1103 | |
| 1104 | for (; I != IEnd && S->isDeclScope(*I); ++I) { |
| 1105 | if (NamedDecl *ND = R.getAcceptableDecl(*I)) { |
| 1106 | if (NameKind == LookupRedeclarationWithLinkage && |
| 1107 | !(*I)->isTemplateParameter()) { |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | |
| 1112 | |
| 1113 | if (!LeftStartingScope && !Initial->isDeclScope(*I)) |
| 1114 | LeftStartingScope = true; |
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | if (LeftStartingScope && !((*I)->hasLinkage())) { |
| 1119 | R.setShadowed(); |
| 1120 | continue; |
| 1121 | } |
| 1122 | } else { |
| 1123 | |
| 1124 | |
| 1125 | SearchNamespaceScope = false; |
| 1126 | } |
| 1127 | R.addDecl(ND); |
| 1128 | } |
| 1129 | } |
| 1130 | if (!SearchNamespaceScope) { |
| 1131 | R.resolveKind(); |
| 1132 | if (S->isClassScope()) |
| 1133 | if (CXXRecordDecl *Record = dyn_cast_or_null<CXXRecordDecl>(Ctx)) |
| 1134 | R.setNamingClass(Record); |
| 1135 | return true; |
| 1136 | } |
| 1137 | |
| 1138 | if (NameKind == LookupLocalFriendName && !S->isClassScope()) { |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | |
| 1143 | |
| 1144 | return false; |
| 1145 | } |
| 1146 | |
| 1147 | if (!Ctx && S->isTemplateParamScope() && OutsideOfTemplateParamDC && |
| 1148 | S->getParent() && !S->getParent()->isTemplateParamScope()) { |
| 1149 | |
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | Ctx = OutsideOfTemplateParamDC; |
| 1155 | OutsideOfTemplateParamDC = nullptr; |
| 1156 | } |
| 1157 | |
| 1158 | if (Ctx) { |
| 1159 | DeclContext *OuterCtx; |
| 1160 | bool SearchAfterTemplateScope; |
| 1161 | std::tie(OuterCtx, SearchAfterTemplateScope) = findOuterContext(S); |
| 1162 | if (SearchAfterTemplateScope) |
| 1163 | OutsideOfTemplateParamDC = OuterCtx; |
| 1164 | |
| 1165 | for (; Ctx && !Ctx->Equals(OuterCtx); Ctx = Ctx->getLookupParent()) { |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | if (Ctx->isTransparentContext()) |
| 1170 | continue; |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | if (Ctx->isFunctionOrMethod()) { |
| 1176 | |
| 1177 | |
| 1178 | if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(Ctx)) { |
| 1179 | if (Method->isInstanceMethod() && Name.getAsIdentifierInfo()) |
| 1180 | if (ObjCInterfaceDecl *Class = Method->getClassInterface()) { |
| 1181 | ObjCInterfaceDecl *ClassDeclared; |
| 1182 | if (ObjCIvarDecl *Ivar = Class->lookupInstanceVariable( |
| 1183 | Name.getAsIdentifierInfo(), |
| 1184 | ClassDeclared)) { |
| 1185 | if (NamedDecl *ND = R.getAcceptableDecl(Ivar)) { |
| 1186 | R.addDecl(ND); |
| 1187 | R.resolveKind(); |
| 1188 | return true; |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | continue; |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | if (Ctx->isFileContext()) { |
| 1200 | |
| 1201 | if (!VisitedUsingDirectives) { |
| 1202 | |
| 1203 | for (DeclContext *UCtx = Ctx; UCtx; UCtx = UCtx->getParent()) { |
| 1204 | if (UCtx->isTransparentContext()) |
| 1205 | continue; |
| 1206 | |
| 1207 | UDirs.visit(UCtx, UCtx); |
| 1208 | } |
| 1209 | |
| 1210 | |
| 1211 | |
| 1212 | Scope *InnermostFileScope = S; |
| 1213 | while (InnermostFileScope && |
| 1214 | !isNamespaceOrTranslationUnitScope(InnermostFileScope)) |
| 1215 | InnermostFileScope = InnermostFileScope->getParent(); |
| 1216 | UDirs.visitScopeChain(Initial, InnermostFileScope); |
| 1217 | |
| 1218 | UDirs.done(); |
| 1219 | |
| 1220 | VisitedUsingDirectives = true; |
| 1221 | } |
| 1222 | |
| 1223 | if (CppNamespaceLookup(*this, R, Context, Ctx, UDirs)) { |
| 1224 | R.resolveKind(); |
| 1225 | return true; |
| 1226 | } |
| 1227 | |
| 1228 | continue; |
| 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | |
| 1237 | if (LookupQualifiedName(R, Ctx, )) |
| 1238 | return true; |
| 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | if (!S) return false; |
| 1246 | |
| 1247 | |
| 1248 | if (NameKind == LookupMemberName) |
| 1249 | return false; |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | |
| 1255 | |
| 1256 | if (!VisitedUsingDirectives) { |
| 1257 | UDirs.visitScopeChain(Initial, S); |
| 1258 | UDirs.done(); |
| 1259 | } |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 | if (!R.isForRedeclaration()) |
| 1264 | FindLocals.restore(); |
| 1265 | |
| 1266 | |
| 1267 | |
| 1268 | |
| 1269 | |
| 1270 | for (; S; S = S->getParent()) { |
| 1271 | |
| 1272 | bool Found = false; |
| 1273 | for (; I != IEnd && S->isDeclScope(*I); ++I) { |
| 1274 | if (NamedDecl *ND = R.getAcceptableDecl(*I)) { |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | |
| 1279 | Found = true; |
| 1280 | R.addDecl(ND); |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | if (Found && S->isTemplateParamScope()) { |
| 1285 | R.resolveKind(); |
| 1286 | return true; |
| 1287 | } |
| 1288 | |
| 1289 | DeclContext *Ctx = S->getEntity(); |
| 1290 | if (!Ctx && S->isTemplateParamScope() && OutsideOfTemplateParamDC && |
| 1291 | S->getParent() && !S->getParent()->isTemplateParamScope()) { |
| 1292 | |
| 1293 | |
| 1294 | |
| 1295 | |
| 1296 | |
| 1297 | Ctx = OutsideOfTemplateParamDC; |
| 1298 | OutsideOfTemplateParamDC = nullptr; |
| 1299 | } |
| 1300 | |
| 1301 | if (Ctx) { |
| 1302 | DeclContext *OuterCtx; |
| 1303 | bool SearchAfterTemplateScope; |
| 1304 | std::tie(OuterCtx, SearchAfterTemplateScope) = findOuterContext(S); |
| 1305 | if (SearchAfterTemplateScope) |
| 1306 | OutsideOfTemplateParamDC = OuterCtx; |
| 1307 | |
| 1308 | for (; Ctx && !Ctx->Equals(OuterCtx); Ctx = Ctx->getLookupParent()) { |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | if (Ctx->isTransparentContext()) |
| 1313 | continue; |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | if (!(Found && S->isTemplateParamScope())) { |
| 1319 | (0) . __assert_fail ("Ctx->isFileContext() && \"We should have been looking only at file context here already.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1320, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Ctx->isFileContext() && |
| 1320 | (0) . __assert_fail ("Ctx->isFileContext() && \"We should have been looking only at file context here already.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1320, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "We should have been looking only at file context here already."); |
| 1321 | |
| 1322 | |
| 1323 | if (CppNamespaceLookup(*this, R, Context, Ctx, UDirs)) |
| 1324 | Found = true; |
| 1325 | } |
| 1326 | |
| 1327 | if (Found) { |
| 1328 | R.resolveKind(); |
| 1329 | return true; |
| 1330 | } |
| 1331 | |
| 1332 | if (R.isForRedeclaration() && !Ctx->isTransparentContext()) |
| 1333 | return false; |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | if (R.isForRedeclaration() && Ctx && !Ctx->isTransparentContext()) |
| 1338 | return false; |
| 1339 | } |
| 1340 | |
| 1341 | return !R.empty(); |
| 1342 | } |
| 1343 | |
| 1344 | void Sema::makeMergedDefinitionVisible(NamedDecl *ND) { |
| 1345 | if (auto *M = getCurrentModule()) |
| 1346 | Context.mergeDefinitionIntoModule(ND, M); |
| 1347 | else |
| 1348 | |
| 1349 | ND->setVisibleDespiteOwningModule(); |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | if (auto *TD = dyn_cast<TemplateDecl>(ND)) |
| 1354 | for (auto *Param : *TD->getTemplateParameters()) |
| 1355 | makeMergedDefinitionVisible(Param); |
| 1356 | } |
| 1357 | |
| 1358 | |
| 1359 | static Module *getDefiningModule(Sema &S, Decl *Entity) { |
| 1360 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(Entity)) { |
| 1361 | |
| 1362 | |
| 1363 | if (FunctionDecl *Pattern = FD->getTemplateInstantiationPattern()) |
| 1364 | Entity = Pattern; |
| 1365 | } else if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Entity)) { |
| 1366 | if (CXXRecordDecl *Pattern = RD->getTemplateInstantiationPattern()) |
| 1367 | Entity = Pattern; |
| 1368 | } else if (EnumDecl *ED = dyn_cast<EnumDecl>(Entity)) { |
| 1369 | if (auto *Pattern = ED->getTemplateInstantiationPattern()) |
| 1370 | Entity = Pattern; |
| 1371 | } else if (VarDecl *VD = dyn_cast<VarDecl>(Entity)) { |
| 1372 | if (VarDecl *Pattern = VD->getTemplateInstantiationPattern()) |
| 1373 | Entity = Pattern; |
| 1374 | } |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | DeclContext *Context = Entity->getLexicalDeclContext(); |
| 1379 | if (Context->isFileContext()) |
| 1380 | return S.getOwningModule(Entity); |
| 1381 | return getDefiningModule(S, cast<Decl>(Context)); |
| 1382 | } |
| 1383 | |
| 1384 | llvm::DenseSet<Module*> &Sema::getLookupModules() { |
| 1385 | unsigned N = CodeSynthesisContexts.size(); |
| 1386 | for (unsigned I = CodeSynthesisContextLookupModules.size(); |
| 1387 | I != N; ++I) { |
| 1388 | Module *M = getDefiningModule(*this, CodeSynthesisContexts[I].Entity); |
| 1389 | if (M && !LookupModulesCache.insert(M).second) |
| 1390 | M = nullptr; |
| 1391 | CodeSynthesisContextLookupModules.push_back(M); |
| 1392 | } |
| 1393 | return LookupModulesCache; |
| 1394 | } |
| 1395 | |
| 1396 | |
| 1397 | |
| 1398 | static bool isInCurrentModule(const Module *M, const LangOptions &LangOpts) { |
| 1399 | |
| 1400 | |
| 1401 | return M->getTopLevelModuleName() == LangOpts.CurrentModule || |
| 1402 | (M->Kind == Module::GlobalModuleFragment && !M->Parent); |
| 1403 | } |
| 1404 | |
| 1405 | bool Sema::hasVisibleMergedDefinition(NamedDecl *Def) { |
| 1406 | for (const Module *Merged : Context.getModulesWithMergedDefinition(Def)) |
| 1407 | if (isModuleVisible(Merged)) |
| 1408 | return true; |
| 1409 | return false; |
| 1410 | } |
| 1411 | |
| 1412 | bool Sema::hasMergedDefinitionInCurrentModule(NamedDecl *Def) { |
| 1413 | for (const Module *Merged : Context.getModulesWithMergedDefinition(Def)) |
| 1414 | if (isInCurrentModule(Merged, getLangOpts())) |
| 1415 | return true; |
| 1416 | return false; |
| 1417 | } |
| 1418 | |
| 1419 | template<typename ParmDecl> |
| 1420 | static bool |
| 1421 | hasVisibleDefaultArgument(Sema &S, const ParmDecl *D, |
| 1422 | llvm::SmallVectorImpl<Module *> *Modules) { |
| 1423 | if (!D->hasDefaultArgument()) |
| 1424 | return false; |
| 1425 | |
| 1426 | while (D) { |
| 1427 | auto &DefaultArg = D->getDefaultArgStorage(); |
| 1428 | if (!DefaultArg.isInherited() && S.isVisible(D)) |
| 1429 | return true; |
| 1430 | |
| 1431 | if (!DefaultArg.isInherited() && Modules) { |
| 1432 | auto *NonConstD = const_cast<ParmDecl*>(D); |
| 1433 | Modules->push_back(S.getOwningModule(NonConstD)); |
| 1434 | } |
| 1435 | |
| 1436 | |
| 1437 | D = DefaultArg.getInheritedFrom(); |
| 1438 | } |
| 1439 | return false; |
| 1440 | } |
| 1441 | |
| 1442 | bool Sema::hasVisibleDefaultArgument(const NamedDecl *D, |
| 1443 | llvm::SmallVectorImpl<Module *> *Modules) { |
| 1444 | if (auto *P = dyn_cast<TemplateTypeParmDecl>(D)) |
| 1445 | return ::hasVisibleDefaultArgument(*this, P, Modules); |
| 1446 | if (auto *P = dyn_cast<NonTypeTemplateParmDecl>(D)) |
| 1447 | return ::hasVisibleDefaultArgument(*this, P, Modules); |
| 1448 | return ::hasVisibleDefaultArgument(*this, cast<TemplateTemplateParmDecl>(D), |
| 1449 | Modules); |
| 1450 | } |
| 1451 | |
| 1452 | template<typename Filter> |
| 1453 | static bool hasVisibleDeclarationImpl(Sema &S, const NamedDecl *D, |
| 1454 | llvm::SmallVectorImpl<Module *> *Modules, |
| 1455 | Filter F) { |
| 1456 | bool HasFilteredRedecls = false; |
| 1457 | |
| 1458 | for (auto *Redecl : D->redecls()) { |
| 1459 | auto *R = cast<NamedDecl>(Redecl); |
| 1460 | if (!F(R)) |
| 1461 | continue; |
| 1462 | |
| 1463 | if (S.isVisible(R)) |
| 1464 | return true; |
| 1465 | |
| 1466 | HasFilteredRedecls = true; |
| 1467 | |
| 1468 | if (Modules) |
| 1469 | Modules->push_back(R->getOwningModule()); |
| 1470 | } |
| 1471 | |
| 1472 | |
| 1473 | if (HasFilteredRedecls) |
| 1474 | return false; |
| 1475 | |
| 1476 | return true; |
| 1477 | } |
| 1478 | |
| 1479 | bool Sema::hasVisibleExplicitSpecialization( |
| 1480 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules) { |
| 1481 | return hasVisibleDeclarationImpl(*this, D, Modules, [](const NamedDecl *D) { |
| 1482 | if (auto *RD = dyn_cast<CXXRecordDecl>(D)) |
| 1483 | return RD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization; |
| 1484 | if (auto *FD = dyn_cast<FunctionDecl>(D)) |
| 1485 | return FD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization; |
| 1486 | if (auto *VD = dyn_cast<VarDecl>(D)) |
| 1487 | return VD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization; |
| 1488 | llvm_unreachable("unknown explicit specialization kind"); |
| 1489 | }); |
| 1490 | } |
| 1491 | |
| 1492 | bool Sema::hasVisibleMemberSpecialization( |
| 1493 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules) { |
| 1494 | (0) . __assert_fail ("isa(D->getDeclContext()) && \"not a member specialization\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1495, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<CXXRecordDecl>(D->getDeclContext()) && |
| 1495 | (0) . __assert_fail ("isa(D->getDeclContext()) && \"not a member specialization\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1495, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "not a member specialization"); |
| 1496 | return hasVisibleDeclarationImpl(*this, D, Modules, [](const NamedDecl *D) { |
| 1497 | |
| 1498 | |
| 1499 | |
| 1500 | |
| 1501 | |
| 1502 | |
| 1503 | |
| 1504 | return D->getLexicalDeclContext()->isFileContext(); |
| 1505 | }); |
| 1506 | } |
| 1507 | |
| 1508 | |
| 1509 | |
| 1510 | |
| 1511 | |
| 1512 | |
| 1513 | |
| 1514 | |
| 1515 | |
| 1516 | bool LookupResult::isVisibleSlow(Sema &SemaRef, NamedDecl *D) { |
| 1517 | (0) . __assert_fail ("D->isHidden() && \"should not call this. not in slow case\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1517, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D->isHidden() && "should not call this: not in slow case"); |
| 1518 | |
| 1519 | Module *DeclModule = SemaRef.getOwningModule(D); |
| 1520 | (0) . __assert_fail ("DeclModule && \"hidden decl has no owning module\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1520, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DeclModule && "hidden decl has no owning module"); |
| 1521 | |
| 1522 | |
| 1523 | if (SemaRef.isModuleVisible(DeclModule, D->isModulePrivate())) |
| 1524 | return true; |
| 1525 | |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | auto IsEffectivelyFileContext = [](const DeclContext *DC) { |
| 1530 | return DC->isFileContext() || isa<LinkageSpecDecl>(DC) || |
| 1531 | isa<ExportDecl>(DC); |
| 1532 | }; |
| 1533 | |
| 1534 | |
| 1535 | |
| 1536 | DeclContext *DC = D->getLexicalDeclContext(); |
| 1537 | if (DC && !IsEffectivelyFileContext(DC)) { |
| 1538 | |
| 1539 | |
| 1540 | |
| 1541 | |
| 1542 | |
| 1543 | |
| 1544 | |
| 1545 | bool VisibleWithinParent; |
| 1546 | if (D->isTemplateParameter() || isa<ParmVarDecl>(D) || |
| 1547 | (isa<FunctionDecl>(DC) && !SemaRef.getLangOpts().CPlusPlus)) |
| 1548 | VisibleWithinParent = isVisible(SemaRef, cast<NamedDecl>(DC)); |
| 1549 | else if (D->isModulePrivate()) { |
| 1550 | |
| 1551 | |
| 1552 | VisibleWithinParent = false; |
| 1553 | do { |
| 1554 | if (SemaRef.hasMergedDefinitionInCurrentModule(cast<NamedDecl>(DC))) { |
| 1555 | VisibleWithinParent = true; |
| 1556 | break; |
| 1557 | } |
| 1558 | DC = DC->getLexicalParent(); |
| 1559 | } while (!IsEffectivelyFileContext(DC)); |
| 1560 | } else { |
| 1561 | VisibleWithinParent = SemaRef.hasVisibleDefinition(cast<NamedDecl>(DC)); |
| 1562 | } |
| 1563 | |
| 1564 | if (VisibleWithinParent && SemaRef.CodeSynthesisContexts.empty() && |
| 1565 | |
| 1566 | !SemaRef.getLangOpts().ModulesLocalVisibility) { |
| 1567 | |
| 1568 | |
| 1569 | D->setVisibleDespiteOwningModule(); |
| 1570 | } |
| 1571 | return VisibleWithinParent; |
| 1572 | } |
| 1573 | |
| 1574 | return false; |
| 1575 | } |
| 1576 | |
| 1577 | bool Sema::isModuleVisible(const Module *M, bool ModulePrivate) { |
| 1578 | |
| 1579 | |
| 1580 | |
| 1581 | if (ModulePrivate) { |
| 1582 | if (isInCurrentModule(M, getLangOpts())) |
| 1583 | return true; |
| 1584 | } else { |
| 1585 | if (VisibleModules.isVisible(M)) |
| 1586 | return true; |
| 1587 | } |
| 1588 | |
| 1589 | |
| 1590 | |
| 1591 | |
| 1592 | |
| 1593 | const auto &LookupModules = getLookupModules(); |
| 1594 | if (LookupModules.empty()) |
| 1595 | return false; |
| 1596 | |
| 1597 | |
| 1598 | if (LookupModules.count(M)) |
| 1599 | return true; |
| 1600 | |
| 1601 | |
| 1602 | if (ModulePrivate) |
| 1603 | return false; |
| 1604 | |
| 1605 | |
| 1606 | return llvm::any_of(LookupModules, [&](const Module *LookupM) { |
| 1607 | return LookupM->isModuleVisible(M); |
| 1608 | }); |
| 1609 | } |
| 1610 | |
| 1611 | bool Sema::isVisibleSlow(const NamedDecl *D) { |
| 1612 | return LookupResult::isVisible(*this, const_cast<NamedDecl*>(D)); |
| 1613 | } |
| 1614 | |
| 1615 | bool Sema::shouldLinkPossiblyHiddenDecl(LookupResult &R, const NamedDecl *New) { |
| 1616 | |
| 1617 | |
| 1618 | |
| 1619 | |
| 1620 | |
| 1621 | |
| 1622 | |
| 1623 | |
| 1624 | |
| 1625 | for (auto *D : R) { |
| 1626 | if (isVisible(D)) |
| 1627 | return true; |
| 1628 | (0) . __assert_fail ("D->isExternallyDeclarable() && \"should not have hidden, non-externally-declarable result here\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1629, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D->isExternallyDeclarable() && |
| 1629 | (0) . __assert_fail ("D->isExternallyDeclarable() && \"should not have hidden, non-externally-declarable result here\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1629, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "should not have hidden, non-externally-declarable result here"); |
| 1630 | } |
| 1631 | |
| 1632 | |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | |
| 1637 | |
| 1638 | |
| 1639 | |
| 1640 | |
| 1641 | |
| 1642 | |
| 1643 | |
| 1644 | |
| 1645 | |
| 1646 | |
| 1647 | |
| 1648 | return New->isExternallyDeclarable(); |
| 1649 | } |
| 1650 | |
| 1651 | |
| 1652 | |
| 1653 | |
| 1654 | |
| 1655 | |
| 1656 | |
| 1657 | |
| 1658 | |
| 1659 | static NamedDecl *findAcceptableDecl(Sema &SemaRef, NamedDecl *D, |
| 1660 | unsigned IDNS) { |
| 1661 | (0) . __assert_fail ("!LookupResult..isVisible(SemaRef, D) && \"not in slow case\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1661, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!LookupResult::isVisible(SemaRef, D) && "not in slow case"); |
| 1662 | |
| 1663 | for (auto RD : D->redecls()) { |
| 1664 | |
| 1665 | if (RD == D) |
| 1666 | continue; |
| 1667 | |
| 1668 | auto ND = cast<NamedDecl>(RD); |
| 1669 | |
| 1670 | |
| 1671 | |
| 1672 | if (ND->isInIdentifierNamespace(IDNS) && |
| 1673 | LookupResult::isVisible(SemaRef, ND)) |
| 1674 | return ND; |
| 1675 | } |
| 1676 | |
| 1677 | return nullptr; |
| 1678 | } |
| 1679 | |
| 1680 | bool Sema::hasVisibleDeclarationSlow(const NamedDecl *D, |
| 1681 | llvm::SmallVectorImpl<Module *> *Modules) { |
| 1682 | (0) . __assert_fail ("!isVisible(D) && \"not in slow case\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1682, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!isVisible(D) && "not in slow case"); |
| 1683 | return hasVisibleDeclarationImpl(*this, D, Modules, |
| 1684 | [](const NamedDecl *) { return true; }); |
| 1685 | } |
| 1686 | |
| 1687 | NamedDecl *LookupResult::getAcceptableDeclSlow(NamedDecl *D) const { |
| 1688 | if (auto *ND = dyn_cast<NamespaceDecl>(D)) { |
| 1689 | |
| 1690 | |
| 1691 | |
| 1692 | |
| 1693 | |
| 1694 | |
| 1695 | auto *Key = ND->getCanonicalDecl(); |
| 1696 | if (auto *Acceptable = getSema().VisibleNamespaceCache.lookup(Key)) |
| 1697 | return Acceptable; |
| 1698 | auto *Acceptable = isVisible(getSema(), Key) |
| 1699 | ? Key |
| 1700 | : findAcceptableDecl(getSema(), Key, IDNS); |
| 1701 | if (Acceptable) |
| 1702 | getSema().VisibleNamespaceCache.insert(std::make_pair(Key, Acceptable)); |
| 1703 | return Acceptable; |
| 1704 | } |
| 1705 | |
| 1706 | return findAcceptableDecl(getSema(), D, IDNS); |
| 1707 | } |
| 1708 | |
| 1709 | |
| 1710 | |
| 1711 | |
| 1712 | |
| 1713 | |
| 1714 | |
| 1715 | |
| 1716 | |
| 1717 | |
| 1718 | |
| 1719 | |
| 1720 | |
| 1721 | |
| 1722 | |
| 1723 | |
| 1724 | |
| 1725 | |
| 1726 | |
| 1727 | |
| 1728 | |
| 1729 | |
| 1730 | |
| 1731 | |
| 1732 | |
| 1733 | |
| 1734 | |
| 1735 | |
| 1736 | |
| 1737 | bool Sema::LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation) { |
| 1738 | DeclarationName Name = R.getLookupName(); |
| 1739 | if (!Name) return false; |
| 1740 | |
| 1741 | LookupNameKind NameKind = R.getLookupKind(); |
| 1742 | |
| 1743 | if (!getLangOpts().CPlusPlus) { |
| 1744 | |
| 1745 | |
| 1746 | if (NameKind == Sema::LookupRedeclarationWithLinkage) { |
| 1747 | |
| 1748 | while (!(S->getFlags() & Scope::DeclScope) || |
| 1749 | (S->getEntity() && S->getEntity()->isTransparentContext())) |
| 1750 | S = S->getParent(); |
| 1751 | } |
| 1752 | |
| 1753 | |
| 1754 | FindLocalExternScope FindLocals(R); |
| 1755 | |
| 1756 | |
| 1757 | |
| 1758 | |
| 1759 | |
| 1760 | bool LeftStartingScope = false; |
| 1761 | |
| 1762 | for (IdentifierResolver::iterator I = IdResolver.begin(Name), |
| 1763 | IEnd = IdResolver.end(); |
| 1764 | I != IEnd; ++I) |
| 1765 | if (NamedDecl *D = R.getAcceptableDecl(*I)) { |
| 1766 | if (NameKind == LookupRedeclarationWithLinkage) { |
| 1767 | |
| 1768 | |
| 1769 | if (!LeftStartingScope && !S->isDeclScope(*I)) |
| 1770 | LeftStartingScope = true; |
| 1771 | |
| 1772 | |
| 1773 | |
| 1774 | if (LeftStartingScope && !((*I)->hasLinkage())) { |
| 1775 | R.setShadowed(); |
| 1776 | continue; |
| 1777 | } |
| 1778 | } |
| 1779 | else if (NameKind == LookupObjCImplicitSelfParam && |
| 1780 | !isa<ImplicitParamDecl>(*I)) |
| 1781 | continue; |
| 1782 | |
| 1783 | R.addDecl(D); |
| 1784 | |
| 1785 | |
| 1786 | |
| 1787 | if (I != IEnd) { |
| 1788 | |
| 1789 | |
| 1790 | while (S && !S->isDeclScope(D)) |
| 1791 | S = S->getParent(); |
| 1792 | |
| 1793 | |
| 1794 | |
| 1795 | |
| 1796 | if (S && isNamespaceOrTranslationUnitScope(S)) |
| 1797 | S = nullptr; |
| 1798 | |
| 1799 | |
| 1800 | DeclContext *DC = nullptr; |
| 1801 | if (!S) |
| 1802 | DC = (*I)->getDeclContext()->getRedeclContext(); |
| 1803 | |
| 1804 | IdentifierResolver::iterator LastI = I; |
| 1805 | for (++LastI; LastI != IEnd; ++LastI) { |
| 1806 | if (S) { |
| 1807 | |
| 1808 | if (!S->isDeclScope(*LastI)) |
| 1809 | break; |
| 1810 | } else { |
| 1811 | |
| 1812 | DeclContext *LastDC |
| 1813 | = (*LastI)->getDeclContext()->getRedeclContext(); |
| 1814 | if (!LastDC->Equals(DC)) |
| 1815 | break; |
| 1816 | } |
| 1817 | |
| 1818 | |
| 1819 | if (NamedDecl *LastD = R.getAcceptableDecl(*LastI)) |
| 1820 | R.addDecl(LastD); |
| 1821 | } |
| 1822 | |
| 1823 | R.resolveKind(); |
| 1824 | } |
| 1825 | |
| 1826 | return true; |
| 1827 | } |
| 1828 | } else { |
| 1829 | |
| 1830 | if (CppLookupName(R, S)) |
| 1831 | return true; |
| 1832 | } |
| 1833 | |
| 1834 | |
| 1835 | |
| 1836 | |
| 1837 | if (AllowBuiltinCreation && LookupBuiltin(*this, R)) |
| 1838 | return true; |
| 1839 | |
| 1840 | |
| 1841 | |
| 1842 | |
| 1843 | |
| 1844 | return (ExternalSource && ExternalSource->LookupUnqualified(R, S)); |
| 1845 | } |
| 1846 | |
| 1847 | |
| 1848 | |
| 1849 | |
| 1850 | |
| 1851 | |
| 1852 | |
| 1853 | |
| 1854 | |
| 1855 | |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | |
| 1861 | |
| 1862 | |
| 1863 | |
| 1864 | |
| 1865 | |
| 1866 | |
| 1867 | |
| 1868 | |
| 1869 | |
| 1870 | |
| 1871 | |
| 1872 | |
| 1873 | |
| 1874 | static bool LookupQualifiedNameInUsingDirectives(Sema &S, LookupResult &R, |
| 1875 | DeclContext *StartDC) { |
| 1876 | (0) . __assert_fail ("StartDC->isFileContext() && \"start context is not a file context\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1876, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(StartDC->isFileContext() && "start context is not a file context"); |
| 1877 | |
| 1878 | |
| 1879 | |
| 1880 | SmallVector<NamespaceDecl*, 8> Queue; |
| 1881 | |
| 1882 | |
| 1883 | llvm::SmallPtrSet<DeclContext*, 8> Visited; |
| 1884 | Visited.insert(StartDC); |
| 1885 | |
| 1886 | |
| 1887 | |
| 1888 | for (auto *I : StartDC->using_directives()) { |
| 1889 | NamespaceDecl *ND = I->getNominatedNamespace()->getOriginalNamespace(); |
| 1890 | if (S.isVisible(I) && Visited.insert(ND).second) |
| 1891 | Queue.push_back(ND); |
| 1892 | } |
| 1893 | |
| 1894 | |
| 1895 | |
| 1896 | |
| 1897 | |
| 1898 | bool FoundTag = false; |
| 1899 | bool FoundNonTag = false; |
| 1900 | |
| 1901 | LookupResult LocalR(LookupResult::Temporary, R); |
| 1902 | |
| 1903 | bool Found = false; |
| 1904 | while (!Queue.empty()) { |
| 1905 | NamespaceDecl *ND = Queue.pop_back_val(); |
| 1906 | |
| 1907 | |
| 1908 | |
| 1909 | bool UseLocal = !R.empty(); |
| 1910 | LookupResult &DirectR = UseLocal ? LocalR : R; |
| 1911 | bool FoundDirect = LookupDirect(S, DirectR, ND); |
| 1912 | |
| 1913 | if (FoundDirect) { |
| 1914 | |
| 1915 | DirectR.resolveKind(); |
| 1916 | |
| 1917 | |
| 1918 | if (DirectR.isSingleTagDecl()) |
| 1919 | FoundTag = true; |
| 1920 | else |
| 1921 | FoundNonTag = true; |
| 1922 | |
| 1923 | |
| 1924 | if (UseLocal) { |
| 1925 | R.addAllDecls(LocalR); |
| 1926 | LocalR.clear(); |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | |
| 1931 | if (FoundDirect) { |
| 1932 | Found = true; |
| 1933 | continue; |
| 1934 | } |
| 1935 | |
| 1936 | for (auto I : ND->using_directives()) { |
| 1937 | NamespaceDecl *Nom = I->getNominatedNamespace(); |
| 1938 | if (S.isVisible(I) && Visited.insert(Nom).second) |
| 1939 | Queue.push_back(Nom); |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | if (Found) { |
| 1944 | if (FoundTag && FoundNonTag) |
| 1945 | R.setAmbiguousQualifiedTagHiding(); |
| 1946 | else |
| 1947 | R.resolveKind(); |
| 1948 | } |
| 1949 | |
| 1950 | return Found; |
| 1951 | } |
| 1952 | |
| 1953 | |
| 1954 | static bool LookupAnyMember(const CXXBaseSpecifier *Specifier, |
| 1955 | CXXBasePath &Path, DeclarationName Name) { |
| 1956 | RecordDecl *BaseRecord = Specifier->getType()->getAs<RecordType>()->getDecl(); |
| 1957 | |
| 1958 | Path.Decls = BaseRecord->lookup(Name); |
| 1959 | return !Path.Decls.empty(); |
| 1960 | } |
| 1961 | |
| 1962 | |
| 1963 | |
| 1964 | template<typename InputIterator> |
| 1965 | static bool HasOnlyStaticMembers(InputIterator First, InputIterator Last) { |
| 1966 | Decl *D = (*First)->getUnderlyingDecl(); |
| 1967 | if (isa<VarDecl>(D) || isa<TypeDecl>(D) || isa<EnumConstantDecl>(D)) |
| 1968 | return true; |
| 1969 | |
| 1970 | if (isa<CXXMethodDecl>(D)) { |
| 1971 | |
| 1972 | bool AllMethodsAreStatic = true; |
| 1973 | for(; First != Last; ++First) { |
| 1974 | D = (*First)->getUnderlyingDecl(); |
| 1975 | |
| 1976 | if (!isa<CXXMethodDecl>(D)) { |
| 1977 | (0) . __assert_fail ("isa(D) && \"Non-function must be a tag decl\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 1977, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<TagDecl>(D) && "Non-function must be a tag decl"); |
| 1978 | break; |
| 1979 | } |
| 1980 | |
| 1981 | if (!cast<CXXMethodDecl>(D)->isStatic()) { |
| 1982 | AllMethodsAreStatic = false; |
| 1983 | break; |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | if (AllMethodsAreStatic) |
| 1988 | return true; |
| 1989 | } |
| 1990 | |
| 1991 | return false; |
| 1992 | } |
| 1993 | |
| 1994 | |
| 1995 | |
| 1996 | |
| 1997 | |
| 1998 | |
| 1999 | |
| 2000 | |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | |
| 2005 | |
| 2006 | |
| 2007 | |
| 2008 | |
| 2009 | |
| 2010 | |
| 2011 | |
| 2012 | |
| 2013 | |
| 2014 | |
| 2015 | |
| 2016 | bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
| 2017 | bool InUnqualifiedLookup) { |
| 2018 | (0) . __assert_fail ("LookupCtx && \"Sema..LookupQualifiedName requires a lookup context\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2018, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(LookupCtx && "Sema::LookupQualifiedName requires a lookup context"); |
| 2019 | |
| 2020 | if (!R.getLookupName()) |
| 2021 | return false; |
| 2022 | |
| 2023 | |
| 2024 | (0) . __assert_fail ("(!isa(LookupCtx) || LookupCtx->isDependentContext() || cast(LookupCtx)->isCompleteDefinition() || cast(LookupCtx)->isBeingDefined()) && \"Declaration context must already be complete!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2028, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((!isa<TagDecl>(LookupCtx) || |
| 2025 | (0) . __assert_fail ("(!isa(LookupCtx) || LookupCtx->isDependentContext() || cast(LookupCtx)->isCompleteDefinition() || cast(LookupCtx)->isBeingDefined()) && \"Declaration context must already be complete!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2028, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> LookupCtx->isDependentContext() || |
| 2026 | (0) . __assert_fail ("(!isa(LookupCtx) || LookupCtx->isDependentContext() || cast(LookupCtx)->isCompleteDefinition() || cast(LookupCtx)->isBeingDefined()) && \"Declaration context must already be complete!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2028, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> cast<TagDecl>(LookupCtx)->isCompleteDefinition() || |
| 2027 | (0) . __assert_fail ("(!isa(LookupCtx) || LookupCtx->isDependentContext() || cast(LookupCtx)->isCompleteDefinition() || cast(LookupCtx)->isBeingDefined()) && \"Declaration context must already be complete!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2028, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> cast<TagDecl>(LookupCtx)->isBeingDefined()) && |
| 2028 | (0) . __assert_fail ("(!isa(LookupCtx) || LookupCtx->isDependentContext() || cast(LookupCtx)->isCompleteDefinition() || cast(LookupCtx)->isBeingDefined()) && \"Declaration context must already be complete!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2028, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Declaration context must already be complete!"); |
| 2029 | |
| 2030 | struct QualifiedLookupInScope { |
| 2031 | bool oldVal; |
| 2032 | DeclContext *Context; |
| 2033 | |
| 2034 | QualifiedLookupInScope(DeclContext *ctx) : Context(ctx) { |
| 2035 | oldVal = ctx->setUseQualifiedLookup(); |
| 2036 | } |
| 2037 | ~QualifiedLookupInScope() { |
| 2038 | Context->setUseQualifiedLookup(oldVal); |
| 2039 | } |
| 2040 | } QL(LookupCtx); |
| 2041 | |
| 2042 | if (LookupDirect(*this, R, LookupCtx)) { |
| 2043 | R.resolveKind(); |
| 2044 | if (isa<CXXRecordDecl>(LookupCtx)) |
| 2045 | R.setNamingClass(cast<CXXRecordDecl>(LookupCtx)); |
| 2046 | return true; |
| 2047 | } |
| 2048 | |
| 2049 | |
| 2050 | |
| 2051 | |
| 2052 | |
| 2053 | |
| 2054 | |
| 2055 | |
| 2056 | |
| 2057 | |
| 2058 | if (R.isForRedeclaration()) |
| 2059 | return false; |
| 2060 | |
| 2061 | |
| 2062 | if (LookupCtx->isFileContext()) |
| 2063 | return LookupQualifiedNameInUsingDirectives(*this, R, LookupCtx); |
| 2064 | |
| 2065 | |
| 2066 | |
| 2067 | CXXRecordDecl *LookupRec = dyn_cast<CXXRecordDecl>(LookupCtx); |
| 2068 | if (!LookupRec || !LookupRec->getDefinition()) |
| 2069 | return false; |
| 2070 | |
| 2071 | |
| 2072 | |
| 2073 | |
| 2074 | |
| 2075 | |
| 2076 | if (!InUnqualifiedLookup && LookupRec->isDependentContext() && |
| 2077 | LookupRec->hasAnyDependentBases()) { |
| 2078 | R.setNotFoundInCurrentInstantiation(); |
| 2079 | return false; |
| 2080 | } |
| 2081 | |
| 2082 | |
| 2083 | CXXBasePaths Paths; |
| 2084 | Paths.setOrigin(LookupRec); |
| 2085 | |
| 2086 | |
| 2087 | bool (*BaseCallback)(const CXXBaseSpecifier *Specifier, CXXBasePath &Path, |
| 2088 | DeclarationName Name) = nullptr; |
| 2089 | switch (R.getLookupKind()) { |
| 2090 | case LookupObjCImplicitSelfParam: |
| 2091 | case LookupOrdinaryName: |
| 2092 | case LookupMemberName: |
| 2093 | case LookupRedeclarationWithLinkage: |
| 2094 | case LookupLocalFriendName: |
| 2095 | BaseCallback = &CXXRecordDecl::FindOrdinaryMember; |
| 2096 | break; |
| 2097 | |
| 2098 | case LookupTagName: |
| 2099 | BaseCallback = &CXXRecordDecl::FindTagMember; |
| 2100 | break; |
| 2101 | |
| 2102 | case LookupAnyName: |
| 2103 | BaseCallback = &LookupAnyMember; |
| 2104 | break; |
| 2105 | |
| 2106 | case LookupOMPReductionName: |
| 2107 | BaseCallback = &CXXRecordDecl::FindOMPReductionMember; |
| 2108 | break; |
| 2109 | |
| 2110 | case LookupOMPMapperName: |
| 2111 | BaseCallback = &CXXRecordDecl::FindOMPMapperMember; |
| 2112 | break; |
| 2113 | |
| 2114 | case LookupUsingDeclName: |
| 2115 | |
| 2116 | |
| 2117 | case LookupOperatorName: |
| 2118 | case LookupNamespaceName: |
| 2119 | case LookupObjCProtocolName: |
| 2120 | case LookupLabel: |
| 2121 | |
| 2122 | return false; |
| 2123 | |
| 2124 | case LookupNestedNameSpecifierName: |
| 2125 | BaseCallback = &CXXRecordDecl::FindNestedNameSpecifierMember; |
| 2126 | break; |
| 2127 | } |
| 2128 | |
| 2129 | DeclarationName Name = R.getLookupName(); |
| 2130 | if (!LookupRec->lookupInBases( |
| 2131 | [=](const CXXBaseSpecifier *Specifier, CXXBasePath &Path) { |
| 2132 | return BaseCallback(Specifier, Path, Name); |
| 2133 | }, |
| 2134 | Paths)) |
| 2135 | return false; |
| 2136 | |
| 2137 | R.setNamingClass(LookupRec); |
| 2138 | |
| 2139 | |
| 2140 | |
| 2141 | |
| 2142 | |
| 2143 | |
| 2144 | |
| 2145 | QualType SubobjectType; |
| 2146 | int SubobjectNumber = 0; |
| 2147 | AccessSpecifier SubobjectAccess = AS_none; |
| 2148 | |
| 2149 | for (CXXBasePaths::paths_iterator Path = Paths.begin(), PathEnd = Paths.end(); |
| 2150 | Path != PathEnd; ++Path) { |
| 2151 | const CXXBasePathElement &PathElement = Path->back(); |
| 2152 | |
| 2153 | |
| 2154 | |
| 2155 | SubobjectAccess = std::min(SubobjectAccess, Path->Access); |
| 2156 | |
| 2157 | |
| 2158 | if (SubobjectType.isNull()) { |
| 2159 | |
| 2160 | SubobjectType = Context.getCanonicalType(PathElement.Base->getType()); |
| 2161 | SubobjectNumber = PathElement.SubobjectNumber; |
| 2162 | continue; |
| 2163 | } |
| 2164 | |
| 2165 | if (SubobjectType |
| 2166 | != Context.getCanonicalType(PathElement.Base->getType())) { |
| 2167 | |
| 2168 | |
| 2169 | |
| 2170 | if (HasOnlyStaticMembers(Path->Decls.begin(), Path->Decls.end())) { |
| 2171 | CXXBasePaths::paths_iterator FirstPath = Paths.begin(); |
| 2172 | DeclContext::lookup_iterator FirstD = FirstPath->Decls.begin(); |
| 2173 | DeclContext::lookup_iterator CurrentD = Path->Decls.begin(); |
| 2174 | |
| 2175 | |
| 2176 | auto GetRepresentativeDecl = [&](NamedDecl *D) -> Decl * { |
| 2177 | |
| 2178 | |
| 2179 | |
| 2180 | |
| 2181 | |
| 2182 | |
| 2183 | |
| 2184 | |
| 2185 | if (R.isTemplateNameLookup()) |
| 2186 | if (auto *TD = getAsTemplateNameDecl(D)) |
| 2187 | D = TD; |
| 2188 | return D->getUnderlyingDecl()->getCanonicalDecl(); |
| 2189 | }; |
| 2190 | |
| 2191 | while (FirstD != FirstPath->Decls.end() && |
| 2192 | CurrentD != Path->Decls.end()) { |
| 2193 | if (GetRepresentativeDecl(*FirstD) != |
| 2194 | GetRepresentativeDecl(*CurrentD)) |
| 2195 | break; |
| 2196 | |
| 2197 | ++FirstD; |
| 2198 | ++CurrentD; |
| 2199 | } |
| 2200 | |
| 2201 | if (FirstD == FirstPath->Decls.end() && |
| 2202 | CurrentD == Path->Decls.end()) |
| 2203 | continue; |
| 2204 | } |
| 2205 | |
| 2206 | R.setAmbiguousBaseSubobjectTypes(Paths); |
| 2207 | return true; |
| 2208 | } |
| 2209 | |
| 2210 | if (SubobjectNumber != PathElement.SubobjectNumber) { |
| 2211 | |
| 2212 | |
| 2213 | |
| 2214 | |
| 2215 | |
| 2216 | |
| 2217 | if (HasOnlyStaticMembers(Path->Decls.begin(), Path->Decls.end())) |
| 2218 | continue; |
| 2219 | |
| 2220 | |
| 2221 | |
| 2222 | R.setAmbiguousBaseSubobjects(Paths); |
| 2223 | return true; |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | |
| 2228 | |
| 2229 | for (auto *D : Paths.front().Decls) { |
| 2230 | AccessSpecifier AS = CXXRecordDecl::MergeAccess(SubobjectAccess, |
| 2231 | D->getAccess()); |
| 2232 | R.addDecl(D, AS); |
| 2233 | } |
| 2234 | R.resolveKind(); |
| 2235 | return true; |
| 2236 | } |
| 2237 | |
| 2238 | |
| 2239 | |
| 2240 | |
| 2241 | |
| 2242 | |
| 2243 | |
| 2244 | |
| 2245 | |
| 2246 | |
| 2247 | |
| 2248 | |
| 2249 | |
| 2250 | |
| 2251 | |
| 2252 | |
| 2253 | bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
| 2254 | CXXScopeSpec &SS) { |
| 2255 | auto *NNS = SS.getScopeRep(); |
| 2256 | if (NNS && NNS->getKind() == NestedNameSpecifier::Super) |
| 2257 | return LookupInSuper(R, NNS->getAsRecordDecl()); |
| 2258 | else |
| 2259 | |
| 2260 | return LookupQualifiedName(R, LookupCtx); |
| 2261 | } |
| 2262 | |
| 2263 | |
| 2264 | |
| 2265 | |
| 2266 | |
| 2267 | |
| 2268 | |
| 2269 | |
| 2270 | |
| 2271 | |
| 2272 | |
| 2273 | |
| 2274 | |
| 2275 | |
| 2276 | |
| 2277 | |
| 2278 | |
| 2279 | |
| 2280 | |
| 2281 | |
| 2282 | bool Sema::LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, |
| 2283 | bool AllowBuiltinCreation, bool EnteringContext) { |
| 2284 | if (SS && SS->isInvalid()) { |
| 2285 | |
| 2286 | |
| 2287 | return false; |
| 2288 | } |
| 2289 | |
| 2290 | if (SS && SS->isSet()) { |
| 2291 | NestedNameSpecifier *NNS = SS->getScopeRep(); |
| 2292 | if (NNS->getKind() == NestedNameSpecifier::Super) |
| 2293 | return LookupInSuper(R, NNS->getAsRecordDecl()); |
| 2294 | |
| 2295 | if (DeclContext *DC = computeDeclContext(*SS, EnteringContext)) { |
| 2296 | |
| 2297 | |
| 2298 | if (!DC->isDependentContext() && RequireCompleteDeclContext(*SS, DC)) |
| 2299 | return false; |
| 2300 | |
| 2301 | R.setContextRange(SS->getRange()); |
| 2302 | return LookupQualifiedName(R, DC); |
| 2303 | } |
| 2304 | |
| 2305 | |
| 2306 | |
| 2307 | |
| 2308 | R.setNotFoundInCurrentInstantiation(); |
| 2309 | R.setContextRange(SS->getRange()); |
| 2310 | return false; |
| 2311 | } |
| 2312 | |
| 2313 | |
| 2314 | return LookupName(R, S, AllowBuiltinCreation); |
| 2315 | } |
| 2316 | |
| 2317 | |
| 2318 | |
| 2319 | |
| 2320 | |
| 2321 | |
| 2322 | |
| 2323 | |
| 2324 | |
| 2325 | |
| 2326 | bool Sema::LookupInSuper(LookupResult &R, CXXRecordDecl *Class) { |
| 2327 | |
| 2328 | |
| 2329 | |
| 2330 | |
| 2331 | for (const auto &BaseSpec : Class->bases()) { |
| 2332 | CXXRecordDecl *RD = cast<CXXRecordDecl>( |
| 2333 | BaseSpec.getType()->castAs<RecordType>()->getDecl()); |
| 2334 | LookupResult Result(*this, R.getLookupNameInfo(), R.getLookupKind()); |
| 2335 | Result.setBaseObjectType(Context.getRecordType(Class)); |
| 2336 | LookupQualifiedName(Result, RD); |
| 2337 | |
| 2338 | |
| 2339 | |
| 2340 | for (auto I = Result.begin(), E = Result.end(); I != E; ++I) { |
| 2341 | R.addDecl(I.getDecl(), |
| 2342 | CXXRecordDecl::MergeAccess(BaseSpec.getAccessSpecifier(), |
| 2343 | I.getAccess())); |
| 2344 | } |
| 2345 | |
| 2346 | Result.suppressDiagnostics(); |
| 2347 | } |
| 2348 | |
| 2349 | R.resolveKind(); |
| 2350 | R.setNamingClass(Class); |
| 2351 | |
| 2352 | return !R.empty(); |
| 2353 | } |
| 2354 | |
| 2355 | |
| 2356 | |
| 2357 | |
| 2358 | |
| 2359 | void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) { |
| 2360 | (0) . __assert_fail ("Result.isAmbiguous() && \"Lookup result must be ambiguous\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2360, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Result.isAmbiguous() && "Lookup result must be ambiguous"); |
| 2361 | |
| 2362 | DeclarationName Name = Result.getLookupName(); |
| 2363 | SourceLocation NameLoc = Result.getNameLoc(); |
| 2364 | SourceRange LookupRange = Result.getContextRange(); |
| 2365 | |
| 2366 | switch (Result.getAmbiguityKind()) { |
| 2367 | case LookupResult::AmbiguousBaseSubobjects: { |
| 2368 | CXXBasePaths *Paths = Result.getBasePaths(); |
| 2369 | QualType SubobjectType = Paths->front().back().Base->getType(); |
| 2370 | Diag(NameLoc, diag::err_ambiguous_member_multiple_subobjects) |
| 2371 | << Name << SubobjectType << getAmbiguousPathsDisplayString(*Paths) |
| 2372 | << LookupRange; |
| 2373 | |
| 2374 | DeclContext::lookup_iterator Found = Paths->front().Decls.begin(); |
| 2375 | while (isa<CXXMethodDecl>(*Found) && |
| 2376 | cast<CXXMethodDecl>(*Found)->isStatic()) |
| 2377 | ++Found; |
| 2378 | |
| 2379 | Diag((*Found)->getLocation(), diag::note_ambiguous_member_found); |
| 2380 | break; |
| 2381 | } |
| 2382 | |
| 2383 | case LookupResult::AmbiguousBaseSubobjectTypes: { |
| 2384 | Diag(NameLoc, diag::err_ambiguous_member_multiple_subobject_types) |
| 2385 | << Name << LookupRange; |
| 2386 | |
| 2387 | CXXBasePaths *Paths = Result.getBasePaths(); |
| 2388 | std::set<Decl *> DeclsPrinted; |
| 2389 | for (CXXBasePaths::paths_iterator Path = Paths->begin(), |
| 2390 | PathEnd = Paths->end(); |
| 2391 | Path != PathEnd; ++Path) { |
| 2392 | Decl *D = Path->Decls.front(); |
| 2393 | if (DeclsPrinted.insert(D).second) |
| 2394 | Diag(D->getLocation(), diag::note_ambiguous_member_found); |
| 2395 | } |
| 2396 | break; |
| 2397 | } |
| 2398 | |
| 2399 | case LookupResult::AmbiguousTagHiding: { |
| 2400 | Diag(NameLoc, diag::err_ambiguous_tag_hiding) << Name << LookupRange; |
| 2401 | |
| 2402 | llvm::SmallPtrSet<NamedDecl*, 8> TagDecls; |
| 2403 | |
| 2404 | for (auto *D : Result) |
| 2405 | if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 2406 | TagDecls.insert(TD); |
| 2407 | Diag(TD->getLocation(), diag::note_hidden_tag); |
| 2408 | } |
| 2409 | |
| 2410 | for (auto *D : Result) |
| 2411 | if (!isa<TagDecl>(D)) |
| 2412 | Diag(D->getLocation(), diag::note_hiding_object); |
| 2413 | |
| 2414 | |
| 2415 | LookupResult::Filter F = Result.makeFilter(); |
| 2416 | while (F.hasNext()) { |
| 2417 | if (TagDecls.count(F.next())) |
| 2418 | F.erase(); |
| 2419 | } |
| 2420 | F.done(); |
| 2421 | break; |
| 2422 | } |
| 2423 | |
| 2424 | case LookupResult::AmbiguousReference: { |
| 2425 | Diag(NameLoc, diag::err_ambiguous_reference) << Name << LookupRange; |
| 2426 | |
| 2427 | for (auto *D : Result) |
| 2428 | Diag(D->getLocation(), diag::note_ambiguous_candidate) << D; |
| 2429 | break; |
| 2430 | } |
| 2431 | } |
| 2432 | } |
| 2433 | |
| 2434 | namespace { |
| 2435 | struct AssociatedLookup { |
| 2436 | AssociatedLookup(Sema &S, SourceLocation InstantiationLoc, |
| 2437 | Sema::AssociatedNamespaceSet &Namespaces, |
| 2438 | Sema::AssociatedClassSet &Classes) |
| 2439 | : S(S), Namespaces(Namespaces), Classes(Classes), |
| 2440 | InstantiationLoc(InstantiationLoc) { |
| 2441 | } |
| 2442 | |
| 2443 | bool addClassTransitive(CXXRecordDecl *RD) { |
| 2444 | Classes.insert(RD); |
| 2445 | return ClassesTransitive.insert(RD); |
| 2446 | } |
| 2447 | |
| 2448 | Sema &S; |
| 2449 | Sema::AssociatedNamespaceSet &Namespaces; |
| 2450 | Sema::AssociatedClassSet &Classes; |
| 2451 | SourceLocation InstantiationLoc; |
| 2452 | |
| 2453 | private: |
| 2454 | Sema::AssociatedClassSet ClassesTransitive; |
| 2455 | }; |
| 2456 | } |
| 2457 | |
| 2458 | static void |
| 2459 | addAssociatedClassesAndNamespaces(AssociatedLookup &Result, QualType T); |
| 2460 | |
| 2461 | static void CollectEnclosingNamespace(Sema::AssociatedNamespaceSet &Namespaces, |
| 2462 | DeclContext *Ctx) { |
| 2463 | |
| 2464 | |
| 2465 | |
| 2466 | |
| 2467 | |
| 2468 | |
| 2469 | |
| 2470 | |
| 2471 | while (Ctx->isRecord() || Ctx->isTransparentContext() || |
| 2472 | Ctx->isInlineNamespace()) |
| 2473 | Ctx = Ctx->getParent(); |
| 2474 | |
| 2475 | if (Ctx->isFileContext()) |
| 2476 | Namespaces.insert(Ctx->getPrimaryContext()); |
| 2477 | } |
| 2478 | |
| 2479 | |
| 2480 | |
| 2481 | static void |
| 2482 | addAssociatedClassesAndNamespaces(AssociatedLookup &Result, |
| 2483 | const TemplateArgument &Arg) { |
| 2484 | |
| 2485 | |
| 2486 | switch (Arg.getKind()) { |
| 2487 | case TemplateArgument::Null: |
| 2488 | break; |
| 2489 | |
| 2490 | case TemplateArgument::Type: |
| 2491 | |
| 2492 | |
| 2493 | |
| 2494 | addAssociatedClassesAndNamespaces(Result, Arg.getAsType()); |
| 2495 | break; |
| 2496 | |
| 2497 | case TemplateArgument::Template: |
| 2498 | case TemplateArgument::TemplateExpansion: { |
| 2499 | |
| 2500 | |
| 2501 | |
| 2502 | TemplateName Template = Arg.getAsTemplateOrTemplatePattern(); |
| 2503 | if (ClassTemplateDecl *ClassTemplate |
| 2504 | = dyn_cast<ClassTemplateDecl>(Template.getAsTemplateDecl())) { |
| 2505 | DeclContext *Ctx = ClassTemplate->getDeclContext(); |
| 2506 | if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx)) |
| 2507 | Result.Classes.insert(EnclosingClass); |
| 2508 | |
| 2509 | CollectEnclosingNamespace(Result.Namespaces, Ctx); |
| 2510 | } |
| 2511 | break; |
| 2512 | } |
| 2513 | |
| 2514 | case TemplateArgument::Declaration: |
| 2515 | case TemplateArgument::Integral: |
| 2516 | case TemplateArgument::Expression: |
| 2517 | case TemplateArgument::NullPtr: |
| 2518 | |
| 2519 | |
| 2520 | break; |
| 2521 | |
| 2522 | case TemplateArgument::Pack: |
| 2523 | for (const auto &P : Arg.pack_elements()) |
| 2524 | addAssociatedClassesAndNamespaces(Result, P); |
| 2525 | break; |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | |
| 2530 | |
| 2531 | |
| 2532 | static void |
| 2533 | addAssociatedClassesAndNamespaces(AssociatedLookup &Result, |
| 2534 | CXXRecordDecl *Class) { |
| 2535 | |
| 2536 | |
| 2537 | if (Class->getDeclName() == Result.S.VAListTagName) |
| 2538 | return; |
| 2539 | |
| 2540 | |
| 2541 | |
| 2542 | |
| 2543 | |
| 2544 | |
| 2545 | |
| 2546 | |
| 2547 | |
| 2548 | |
| 2549 | DeclContext *Ctx = Class->getDeclContext(); |
| 2550 | if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx)) |
| 2551 | Result.Classes.insert(EnclosingClass); |
| 2552 | |
| 2553 | CollectEnclosingNamespace(Result.Namespaces, Ctx); |
| 2554 | |
| 2555 | |
| 2556 | |
| 2557 | |
| 2558 | |
| 2559 | |
| 2560 | |
| 2561 | |
| 2562 | |
| 2563 | |
| 2564 | if (ClassTemplateSpecializationDecl *Spec |
| 2565 | = dyn_cast<ClassTemplateSpecializationDecl>(Class)) { |
| 2566 | DeclContext *Ctx = Spec->getSpecializedTemplate()->getDeclContext(); |
| 2567 | if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx)) |
| 2568 | Result.Classes.insert(EnclosingClass); |
| 2569 | |
| 2570 | CollectEnclosingNamespace(Result.Namespaces, Ctx); |
| 2571 | |
| 2572 | const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); |
| 2573 | for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I) |
| 2574 | addAssociatedClassesAndNamespaces(Result, TemplateArgs[I]); |
| 2575 | } |
| 2576 | |
| 2577 | |
| 2578 | |
| 2579 | if (!Result.addClassTransitive(Class)) |
| 2580 | return; |
| 2581 | |
| 2582 | |
| 2583 | if (!Result.S.isCompleteType(Result.InstantiationLoc, |
| 2584 | Result.S.Context.getRecordType(Class))) |
| 2585 | return; |
| 2586 | |
| 2587 | |
| 2588 | |
| 2589 | SmallVector<CXXRecordDecl *, 32> Bases; |
| 2590 | Bases.push_back(Class); |
| 2591 | while (!Bases.empty()) { |
| 2592 | |
| 2593 | Class = Bases.pop_back_val(); |
| 2594 | |
| 2595 | |
| 2596 | for (const auto &Base : Class->bases()) { |
| 2597 | const RecordType *BaseType = Base.getType()->getAs<RecordType>(); |
| 2598 | |
| 2599 | |
| 2600 | |
| 2601 | |
| 2602 | |
| 2603 | |
| 2604 | if (!BaseType) |
| 2605 | continue; |
| 2606 | CXXRecordDecl *BaseDecl = cast<CXXRecordDecl>(BaseType->getDecl()); |
| 2607 | if (Result.addClassTransitive(BaseDecl)) { |
| 2608 | |
| 2609 | DeclContext *BaseCtx = BaseDecl->getDeclContext(); |
| 2610 | CollectEnclosingNamespace(Result.Namespaces, BaseCtx); |
| 2611 | |
| 2612 | |
| 2613 | if (BaseDecl->bases_begin() != BaseDecl->bases_end()) |
| 2614 | Bases.push_back(BaseDecl); |
| 2615 | } |
| 2616 | } |
| 2617 | } |
| 2618 | } |
| 2619 | |
| 2620 | |
| 2621 | |
| 2622 | |
| 2623 | static void |
| 2624 | addAssociatedClassesAndNamespaces(AssociatedLookup &Result, QualType Ty) { |
| 2625 | |
| 2626 | |
| 2627 | |
| 2628 | |
| 2629 | |
| 2630 | |
| 2631 | |
| 2632 | |
| 2633 | |
| 2634 | |
| 2635 | |
| 2636 | SmallVector<const Type *, 16> Queue; |
| 2637 | const Type *T = Ty->getCanonicalTypeInternal().getTypePtr(); |
| 2638 | |
| 2639 | while (true) { |
| 2640 | switch (T->getTypeClass()) { |
| 2641 | |
| 2642 | #define TYPE(Class, Base) |
| 2643 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: |
| 2644 | #define NON_CANONICAL_TYPE(Class, Base) case Type::Class: |
| 2645 | #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class: |
| 2646 | #define ABSTRACT_TYPE(Class, Base) |
| 2647 | #include "clang/AST/TypeNodes.def" |
| 2648 | |
| 2649 | |
| 2650 | |
| 2651 | |
| 2652 | |
| 2653 | break; |
| 2654 | |
| 2655 | |
| 2656 | |
| 2657 | case Type::Pointer: |
| 2658 | T = cast<PointerType>(T)->getPointeeType().getTypePtr(); |
| 2659 | continue; |
| 2660 | case Type::ConstantArray: |
| 2661 | case Type::IncompleteArray: |
| 2662 | case Type::VariableArray: |
| 2663 | T = cast<ArrayType>(T)->getElementType().getTypePtr(); |
| 2664 | continue; |
| 2665 | |
| 2666 | |
| 2667 | |
| 2668 | case Type::Builtin: |
| 2669 | break; |
| 2670 | |
| 2671 | |
| 2672 | |
| 2673 | |
| 2674 | |
| 2675 | |
| 2676 | case Type::Record: { |
| 2677 | CXXRecordDecl *Class = |
| 2678 | cast<CXXRecordDecl>(cast<RecordType>(T)->getDecl()); |
| 2679 | addAssociatedClassesAndNamespaces(Result, Class); |
| 2680 | break; |
| 2681 | } |
| 2682 | |
| 2683 | |
| 2684 | |
| 2685 | |
| 2686 | |
| 2687 | case Type::Enum: { |
| 2688 | EnumDecl *Enum = cast<EnumType>(T)->getDecl(); |
| 2689 | |
| 2690 | DeclContext *Ctx = Enum->getDeclContext(); |
| 2691 | if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx)) |
| 2692 | Result.Classes.insert(EnclosingClass); |
| 2693 | |
| 2694 | |
| 2695 | CollectEnclosingNamespace(Result.Namespaces, Ctx); |
| 2696 | |
| 2697 | break; |
| 2698 | } |
| 2699 | |
| 2700 | |
| 2701 | |
| 2702 | |
| 2703 | case Type::FunctionProto: { |
| 2704 | const FunctionProtoType *Proto = cast<FunctionProtoType>(T); |
| 2705 | for (const auto &Arg : Proto->param_types()) |
| 2706 | Queue.push_back(Arg.getTypePtr()); |
| 2707 | |
| 2708 | LLVM_FALLTHROUGH; |
| 2709 | } |
| 2710 | case Type::FunctionNoProto: { |
| 2711 | const FunctionType *FnType = cast<FunctionType>(T); |
| 2712 | T = FnType->getReturnType().getTypePtr(); |
| 2713 | continue; |
| 2714 | } |
| 2715 | |
| 2716 | |
| 2717 | |
| 2718 | |
| 2719 | |
| 2720 | |
| 2721 | |
| 2722 | |
| 2723 | |
| 2724 | |
| 2725 | case Type::MemberPointer: { |
| 2726 | const MemberPointerType *MemberPtr = cast<MemberPointerType>(T); |
| 2727 | |
| 2728 | |
| 2729 | Queue.push_back(MemberPtr->getClass()); |
| 2730 | |
| 2731 | |
| 2732 | T = MemberPtr->getPointeeType().getTypePtr(); |
| 2733 | continue; |
| 2734 | } |
| 2735 | |
| 2736 | |
| 2737 | case Type::BlockPointer: |
| 2738 | T = cast<BlockPointerType>(T)->getPointeeType().getTypePtr(); |
| 2739 | continue; |
| 2740 | |
| 2741 | |
| 2742 | |
| 2743 | case Type::LValueReference: |
| 2744 | case Type::RValueReference: |
| 2745 | T = cast<ReferenceType>(T)->getPointeeType().getTypePtr(); |
| 2746 | continue; |
| 2747 | |
| 2748 | |
| 2749 | case Type::Vector: |
| 2750 | case Type::ExtVector: |
| 2751 | case Type::Complex: |
| 2752 | break; |
| 2753 | |
| 2754 | |
| 2755 | case Type::Auto: |
| 2756 | case Type::DeducedTemplateSpecialization: |
| 2757 | break; |
| 2758 | |
| 2759 | |
| 2760 | |
| 2761 | |
| 2762 | case Type::ObjCObject: |
| 2763 | case Type::ObjCInterface: |
| 2764 | case Type::ObjCObjectPointer: |
| 2765 | Result.Namespaces.insert(Result.S.Context.getTranslationUnitDecl()); |
| 2766 | break; |
| 2767 | |
| 2768 | |
| 2769 | |
| 2770 | case Type::Atomic: |
| 2771 | T = cast<AtomicType>(T)->getValueType().getTypePtr(); |
| 2772 | continue; |
| 2773 | case Type::Pipe: |
| 2774 | T = cast<PipeType>(T)->getElementType().getTypePtr(); |
| 2775 | continue; |
| 2776 | } |
| 2777 | |
| 2778 | if (Queue.empty()) |
| 2779 | break; |
| 2780 | T = Queue.pop_back_val(); |
| 2781 | } |
| 2782 | } |
| 2783 | |
| 2784 | |
| 2785 | |
| 2786 | |
| 2787 | |
| 2788 | |
| 2789 | |
| 2790 | |
| 2791 | void Sema::FindAssociatedClassesAndNamespaces( |
| 2792 | SourceLocation InstantiationLoc, ArrayRef<Expr *> Args, |
| 2793 | AssociatedNamespaceSet &AssociatedNamespaces, |
| 2794 | AssociatedClassSet &AssociatedClasses) { |
| 2795 | AssociatedNamespaces.clear(); |
| 2796 | AssociatedClasses.clear(); |
| 2797 | |
| 2798 | AssociatedLookup Result(*this, InstantiationLoc, |
| 2799 | AssociatedNamespaces, AssociatedClasses); |
| 2800 | |
| 2801 | |
| 2802 | |
| 2803 | |
| 2804 | |
| 2805 | |
| 2806 | |
| 2807 | |
| 2808 | for (unsigned ArgIdx = 0; ArgIdx != Args.size(); ++ArgIdx) { |
| 2809 | Expr *Arg = Args[ArgIdx]; |
| 2810 | |
| 2811 | if (Arg->getType() != Context.OverloadTy) { |
| 2812 | addAssociatedClassesAndNamespaces(Result, Arg->getType()); |
| 2813 | continue; |
| 2814 | } |
| 2815 | |
| 2816 | |
| 2817 | |
| 2818 | |
| 2819 | |
| 2820 | |
| 2821 | |
| 2822 | |
| 2823 | OverloadExpr *OE = OverloadExpr::find(Arg).Expression; |
| 2824 | |
| 2825 | for (const NamedDecl *D : OE->decls()) { |
| 2826 | |
| 2827 | const FunctionDecl *FDecl = D->getUnderlyingDecl()->getAsFunction(); |
| 2828 | |
| 2829 | |
| 2830 | |
| 2831 | addAssociatedClassesAndNamespaces(Result, FDecl->getType()); |
| 2832 | } |
| 2833 | } |
| 2834 | } |
| 2835 | |
| 2836 | NamedDecl *Sema::LookupSingleName(Scope *S, DeclarationName Name, |
| 2837 | SourceLocation Loc, |
| 2838 | LookupNameKind NameKind, |
| 2839 | RedeclarationKind Redecl) { |
| 2840 | LookupResult R(*this, Name, Loc, NameKind, Redecl); |
| 2841 | LookupName(R, S); |
| 2842 | return R.getAsSingle<NamedDecl>(); |
| 2843 | } |
| 2844 | |
| 2845 | |
| 2846 | ObjCProtocolDecl *Sema::LookupProtocol(IdentifierInfo *II, |
| 2847 | SourceLocation IdLoc, |
| 2848 | RedeclarationKind Redecl) { |
| 2849 | Decl *D = LookupSingleName(TUScope, II, IdLoc, |
| 2850 | LookupObjCProtocolName, Redecl); |
| 2851 | return cast_or_null<ObjCProtocolDecl>(D); |
| 2852 | } |
| 2853 | |
| 2854 | void Sema::LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, |
| 2855 | QualType T1, QualType T2, |
| 2856 | UnresolvedSetImpl &Functions) { |
| 2857 | |
| 2858 | |
| 2859 | |
| 2860 | |
| 2861 | |
| 2862 | |
| 2863 | DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(Op); |
| 2864 | LookupResult Operators(*this, OpName, SourceLocation(), LookupOperatorName); |
| 2865 | LookupName(Operators, S); |
| 2866 | |
| 2867 | (0) . __assert_fail ("!Operators.isAmbiguous() && \"Operator lookup cannot be ambiguous\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2867, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Operators.isAmbiguous() && "Operator lookup cannot be ambiguous"); |
| 2868 | Functions.append(Operators.begin(), Operators.end()); |
| 2869 | } |
| 2870 | |
| 2871 | Sema::SpecialMemberOverloadResult Sema::LookupSpecialMember(CXXRecordDecl *RD, |
| 2872 | CXXSpecialMember SM, |
| 2873 | bool ConstArg, |
| 2874 | bool VolatileArg, |
| 2875 | bool RValueThis, |
| 2876 | bool ConstThis, |
| 2877 | bool VolatileThis) { |
| 2878 | (0) . __assert_fail ("CanDeclareSpecialMemberFunction(RD) && \"doing special member lookup into record that isn't fully complete\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2879, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(CanDeclareSpecialMemberFunction(RD) && |
| 2879 | (0) . __assert_fail ("CanDeclareSpecialMemberFunction(RD) && \"doing special member lookup into record that isn't fully complete\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2879, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "doing special member lookup into record that isn't fully complete"); |
| 2880 | RD = RD->getDefinition(); |
| 2881 | if (RValueThis || ConstThis || VolatileThis) |
| 2882 | (0) . __assert_fail ("(SM == CXXCopyAssignment || SM == CXXMoveAssignment) && \"constructors and destructors always have unqualified lvalue this\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2883, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((SM == CXXCopyAssignment || SM == CXXMoveAssignment) && |
| 2883 | (0) . __assert_fail ("(SM == CXXCopyAssignment || SM == CXXMoveAssignment) && \"constructors and destructors always have unqualified lvalue this\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2883, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "constructors and destructors always have unqualified lvalue this"); |
| 2884 | if (ConstArg || VolatileArg) |
| 2885 | (0) . __assert_fail ("(SM != CXXDefaultConstructor && SM != CXXDestructor) && \"parameter-less special members can't have qualified arguments\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2886, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((SM != CXXDefaultConstructor && SM != CXXDestructor) && |
| 2886 | (0) . __assert_fail ("(SM != CXXDefaultConstructor && SM != CXXDestructor) && \"parameter-less special members can't have qualified arguments\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2886, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "parameter-less special members can't have qualified arguments"); |
| 2887 | |
| 2888 | |
| 2889 | SourceLocation LookupLoc = RD->getLocation(); |
| 2890 | |
| 2891 | llvm::FoldingSetNodeID ID; |
| 2892 | ID.AddPointer(RD); |
| 2893 | ID.AddInteger(SM); |
| 2894 | ID.AddInteger(ConstArg); |
| 2895 | ID.AddInteger(VolatileArg); |
| 2896 | ID.AddInteger(RValueThis); |
| 2897 | ID.AddInteger(ConstThis); |
| 2898 | ID.AddInteger(VolatileThis); |
| 2899 | |
| 2900 | void *InsertPoint; |
| 2901 | SpecialMemberOverloadResultEntry *Result = |
| 2902 | SpecialMemberCache.FindNodeOrInsertPos(ID, InsertPoint); |
| 2903 | |
| 2904 | |
| 2905 | if (Result) |
| 2906 | return *Result; |
| 2907 | |
| 2908 | Result = BumpAlloc.Allocate<SpecialMemberOverloadResultEntry>(); |
| 2909 | Result = new (Result) SpecialMemberOverloadResultEntry(ID); |
| 2910 | SpecialMemberCache.InsertNode(Result, InsertPoint); |
| 2911 | |
| 2912 | if (SM == CXXDestructor) { |
| 2913 | if (RD->needsImplicitDestructor()) |
| 2914 | DeclareImplicitDestructor(RD); |
| 2915 | CXXDestructorDecl *DD = RD->getDestructor(); |
| 2916 | (0) . __assert_fail ("DD && \"record without a destructor\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 2916, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DD && "record without a destructor"); |
| 2917 | Result->setMethod(DD); |
| 2918 | Result->setKind(DD->isDeleted() ? |
| 2919 | SpecialMemberOverloadResult::NoMemberOrDeleted : |
| 2920 | SpecialMemberOverloadResult::Success); |
| 2921 | return *Result; |
| 2922 | } |
| 2923 | |
| 2924 | |
| 2925 | |
| 2926 | CanQualType CanTy = Context.getCanonicalType(Context.getTagDeclType(RD)); |
| 2927 | DeclarationName Name; |
| 2928 | Expr *Arg = nullptr; |
| 2929 | unsigned NumArgs; |
| 2930 | |
| 2931 | QualType ArgType = CanTy; |
| 2932 | ExprValueKind VK = VK_LValue; |
| 2933 | |
| 2934 | if (SM == CXXDefaultConstructor) { |
| 2935 | Name = Context.DeclarationNames.getCXXConstructorName(CanTy); |
| 2936 | NumArgs = 0; |
| 2937 | if (RD->needsImplicitDefaultConstructor()) |
| 2938 | DeclareImplicitDefaultConstructor(RD); |
| 2939 | } else { |
| 2940 | if (SM == CXXCopyConstructor || SM == CXXMoveConstructor) { |
| 2941 | Name = Context.DeclarationNames.getCXXConstructorName(CanTy); |
| 2942 | if (RD->needsImplicitCopyConstructor()) |
| 2943 | DeclareImplicitCopyConstructor(RD); |
| 2944 | if (getLangOpts().CPlusPlus11 && RD->needsImplicitMoveConstructor()) |
| 2945 | DeclareImplicitMoveConstructor(RD); |
| 2946 | } else { |
| 2947 | Name = Context.DeclarationNames.getCXXOperatorName(OO_Equal); |
| 2948 | if (RD->needsImplicitCopyAssignment()) |
| 2949 | DeclareImplicitCopyAssignment(RD); |
| 2950 | if (getLangOpts().CPlusPlus11 && RD->needsImplicitMoveAssignment()) |
| 2951 | DeclareImplicitMoveAssignment(RD); |
| 2952 | } |
| 2953 | |
| 2954 | if (ConstArg) |
| 2955 | ArgType.addConst(); |
| 2956 | if (VolatileArg) |
| 2957 | ArgType.addVolatile(); |
| 2958 | |
| 2959 | |
| 2960 | |
| 2961 | |
| 2962 | |
| 2963 | |
| 2964 | |
| 2965 | |
| 2966 | if (SM == CXXCopyConstructor || SM == CXXCopyAssignment) |
| 2967 | VK = VK_LValue; |
| 2968 | else |
| 2969 | VK = VK_RValue; |
| 2970 | } |
| 2971 | |
| 2972 | OpaqueValueExpr FakeArg(LookupLoc, ArgType, VK); |
| 2973 | |
| 2974 | if (SM != CXXDefaultConstructor) { |
| 2975 | NumArgs = 1; |
| 2976 | Arg = &FakeArg; |
| 2977 | } |
| 2978 | |
| 2979 | |
| 2980 | QualType ThisTy = CanTy; |
| 2981 | if (ConstThis) |
| 2982 | ThisTy.addConst(); |
| 2983 | if (VolatileThis) |
| 2984 | ThisTy.addVolatile(); |
| 2985 | Expr::Classification Classification = |
| 2986 | OpaqueValueExpr(LookupLoc, ThisTy, |
| 2987 | RValueThis ? VK_RValue : VK_LValue).Classify(Context); |
| 2988 | |
| 2989 | |
| 2990 | |
| 2991 | |
| 2992 | OverloadCandidateSet OCS(LookupLoc, OverloadCandidateSet::CSK_Normal); |
| 2993 | DeclContext::lookup_result R = RD->lookup(Name); |
| 2994 | |
| 2995 | if (R.empty()) { |
| 2996 | |
| 2997 | |
| 2998 | |
| 2999 | |
| 3000 | (0) . __assert_fail ("SM == CXXDefaultConstructor && \"lookup for a constructor or assignment operator was empty\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3001, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(SM == CXXDefaultConstructor && |
| 3001 | (0) . __assert_fail ("SM == CXXDefaultConstructor && \"lookup for a constructor or assignment operator was empty\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3001, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "lookup for a constructor or assignment operator was empty"); |
| 3002 | Result->setMethod(nullptr); |
| 3003 | Result->setKind(SpecialMemberOverloadResult::NoMemberOrDeleted); |
| 3004 | return *Result; |
| 3005 | } |
| 3006 | |
| 3007 | |
| 3008 | |
| 3009 | SmallVector<NamedDecl *, 8> Candidates(R.begin(), R.end()); |
| 3010 | |
| 3011 | for (NamedDecl *CandDecl : Candidates) { |
| 3012 | if (CandDecl->isInvalidDecl()) |
| 3013 | continue; |
| 3014 | |
| 3015 | DeclAccessPair Cand = DeclAccessPair::make(CandDecl, AS_public); |
| 3016 | auto CtorInfo = getConstructorInfo(Cand); |
| 3017 | if (CXXMethodDecl *M = dyn_cast<CXXMethodDecl>(Cand->getUnderlyingDecl())) { |
| 3018 | if (SM == CXXCopyAssignment || SM == CXXMoveAssignment) |
| 3019 | AddMethodCandidate(M, Cand, RD, ThisTy, Classification, |
| 3020 | llvm::makeArrayRef(&Arg, NumArgs), OCS, true); |
| 3021 | else if (CtorInfo) |
| 3022 | AddOverloadCandidate(CtorInfo.Constructor, CtorInfo.FoundDecl, |
| 3023 | llvm::makeArrayRef(&Arg, NumArgs), OCS, true); |
| 3024 | else |
| 3025 | AddOverloadCandidate(M, Cand, llvm::makeArrayRef(&Arg, NumArgs), OCS, |
| 3026 | true); |
| 3027 | } else if (FunctionTemplateDecl *Tmpl = |
| 3028 | dyn_cast<FunctionTemplateDecl>(Cand->getUnderlyingDecl())) { |
| 3029 | if (SM == CXXCopyAssignment || SM == CXXMoveAssignment) |
| 3030 | AddMethodTemplateCandidate( |
| 3031 | Tmpl, Cand, RD, nullptr, ThisTy, Classification, |
| 3032 | llvm::makeArrayRef(&Arg, NumArgs), OCS, true); |
| 3033 | else if (CtorInfo) |
| 3034 | AddTemplateOverloadCandidate( |
| 3035 | CtorInfo.ConstructorTmpl, CtorInfo.FoundDecl, nullptr, |
| 3036 | llvm::makeArrayRef(&Arg, NumArgs), OCS, true); |
| 3037 | else |
| 3038 | AddTemplateOverloadCandidate( |
| 3039 | Tmpl, Cand, nullptr, llvm::makeArrayRef(&Arg, NumArgs), OCS, true); |
| 3040 | } else { |
| 3041 | (0) . __assert_fail ("isa(Cand.getDecl()) && \"illegal Kind of operator = Decl\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3042, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<UsingDecl>(Cand.getDecl()) && |
| 3042 | (0) . __assert_fail ("isa(Cand.getDecl()) && \"illegal Kind of operator = Decl\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3042, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "illegal Kind of operator = Decl"); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | OverloadCandidateSet::iterator Best; |
| 3047 | switch (OCS.BestViableFunction(*this, LookupLoc, Best)) { |
| 3048 | case OR_Success: |
| 3049 | Result->setMethod(cast<CXXMethodDecl>(Best->Function)); |
| 3050 | Result->setKind(SpecialMemberOverloadResult::Success); |
| 3051 | break; |
| 3052 | |
| 3053 | case OR_Deleted: |
| 3054 | Result->setMethod(cast<CXXMethodDecl>(Best->Function)); |
| 3055 | Result->setKind(SpecialMemberOverloadResult::NoMemberOrDeleted); |
| 3056 | break; |
| 3057 | |
| 3058 | case OR_Ambiguous: |
| 3059 | Result->setMethod(nullptr); |
| 3060 | Result->setKind(SpecialMemberOverloadResult::Ambiguous); |
| 3061 | break; |
| 3062 | |
| 3063 | case OR_No_Viable_Function: |
| 3064 | Result->setMethod(nullptr); |
| 3065 | Result->setKind(SpecialMemberOverloadResult::NoMemberOrDeleted); |
| 3066 | break; |
| 3067 | } |
| 3068 | |
| 3069 | return *Result; |
| 3070 | } |
| 3071 | |
| 3072 | |
| 3073 | CXXConstructorDecl *Sema::LookupDefaultConstructor(CXXRecordDecl *Class) { |
| 3074 | SpecialMemberOverloadResult Result = |
| 3075 | LookupSpecialMember(Class, CXXDefaultConstructor, false, false, false, |
| 3076 | false, false); |
| 3077 | |
| 3078 | return cast_or_null<CXXConstructorDecl>(Result.getMethod()); |
| 3079 | } |
| 3080 | |
| 3081 | |
| 3082 | CXXConstructorDecl *Sema::LookupCopyingConstructor(CXXRecordDecl *Class, |
| 3083 | unsigned Quals) { |
| 3084 | (0) . __assert_fail ("!(Quals & ~(Qualifiers..Const | Qualifiers..Volatile)) && \"non-const, non-volatile qualifiers for copy ctor arg\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3085, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!(Quals & ~(Qualifiers::Const | Qualifiers::Volatile)) && |
| 3085 | (0) . __assert_fail ("!(Quals & ~(Qualifiers..Const | Qualifiers..Volatile)) && \"non-const, non-volatile qualifiers for copy ctor arg\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3085, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "non-const, non-volatile qualifiers for copy ctor arg"); |
| 3086 | SpecialMemberOverloadResult Result = |
| 3087 | LookupSpecialMember(Class, CXXCopyConstructor, Quals & Qualifiers::Const, |
| 3088 | Quals & Qualifiers::Volatile, false, false, false); |
| 3089 | |
| 3090 | return cast_or_null<CXXConstructorDecl>(Result.getMethod()); |
| 3091 | } |
| 3092 | |
| 3093 | |
| 3094 | CXXConstructorDecl *Sema::LookupMovingConstructor(CXXRecordDecl *Class, |
| 3095 | unsigned Quals) { |
| 3096 | SpecialMemberOverloadResult Result = |
| 3097 | LookupSpecialMember(Class, CXXMoveConstructor, Quals & Qualifiers::Const, |
| 3098 | Quals & Qualifiers::Volatile, false, false, false); |
| 3099 | |
| 3100 | return cast_or_null<CXXConstructorDecl>(Result.getMethod()); |
| 3101 | } |
| 3102 | |
| 3103 | |
| 3104 | DeclContext::lookup_result Sema::LookupConstructors(CXXRecordDecl *Class) { |
| 3105 | |
| 3106 | if (CanDeclareSpecialMemberFunction(Class)) { |
| 3107 | if (Class->needsImplicitDefaultConstructor()) |
| 3108 | DeclareImplicitDefaultConstructor(Class); |
| 3109 | if (Class->needsImplicitCopyConstructor()) |
| 3110 | DeclareImplicitCopyConstructor(Class); |
| 3111 | if (getLangOpts().CPlusPlus11 && Class->needsImplicitMoveConstructor()) |
| 3112 | DeclareImplicitMoveConstructor(Class); |
| 3113 | } |
| 3114 | |
| 3115 | CanQualType T = Context.getCanonicalType(Context.getTypeDeclType(Class)); |
| 3116 | DeclarationName Name = Context.DeclarationNames.getCXXConstructorName(T); |
| 3117 | return Class->lookup(Name); |
| 3118 | } |
| 3119 | |
| 3120 | |
| 3121 | CXXMethodDecl *Sema::LookupCopyingAssignment(CXXRecordDecl *Class, |
| 3122 | unsigned Quals, bool RValueThis, |
| 3123 | unsigned ThisQuals) { |
| 3124 | (0) . __assert_fail ("!(Quals & ~(Qualifiers..Const | Qualifiers..Volatile)) && \"non-const, non-volatile qualifiers for copy assignment arg\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3125, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!(Quals & ~(Qualifiers::Const | Qualifiers::Volatile)) && |
| 3125 | (0) . __assert_fail ("!(Quals & ~(Qualifiers..Const | Qualifiers..Volatile)) && \"non-const, non-volatile qualifiers for copy assignment arg\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3125, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "non-const, non-volatile qualifiers for copy assignment arg"); |
| 3126 | (0) . __assert_fail ("!(ThisQuals & ~(Qualifiers..Const | Qualifiers..Volatile)) && \"non-const, non-volatile qualifiers for copy assignment this\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3127, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!(ThisQuals & ~(Qualifiers::Const | Qualifiers::Volatile)) && |
| 3127 | (0) . __assert_fail ("!(ThisQuals & ~(Qualifiers..Const | Qualifiers..Volatile)) && \"non-const, non-volatile qualifiers for copy assignment this\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3127, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "non-const, non-volatile qualifiers for copy assignment this"); |
| 3128 | SpecialMemberOverloadResult Result = |
| 3129 | LookupSpecialMember(Class, CXXCopyAssignment, Quals & Qualifiers::Const, |
| 3130 | Quals & Qualifiers::Volatile, RValueThis, |
| 3131 | ThisQuals & Qualifiers::Const, |
| 3132 | ThisQuals & Qualifiers::Volatile); |
| 3133 | |
| 3134 | return Result.getMethod(); |
| 3135 | } |
| 3136 | |
| 3137 | |
| 3138 | CXXMethodDecl *Sema::LookupMovingAssignment(CXXRecordDecl *Class, |
| 3139 | unsigned Quals, |
| 3140 | bool RValueThis, |
| 3141 | unsigned ThisQuals) { |
| 3142 | (0) . __assert_fail ("!(ThisQuals & ~(Qualifiers..Const | Qualifiers..Volatile)) && \"non-const, non-volatile qualifiers for copy assignment this\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3143, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!(ThisQuals & ~(Qualifiers::Const | Qualifiers::Volatile)) && |
| 3143 | (0) . __assert_fail ("!(ThisQuals & ~(Qualifiers..Const | Qualifiers..Volatile)) && \"non-const, non-volatile qualifiers for copy assignment this\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3143, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "non-const, non-volatile qualifiers for copy assignment this"); |
| 3144 | SpecialMemberOverloadResult Result = |
| 3145 | LookupSpecialMember(Class, CXXMoveAssignment, Quals & Qualifiers::Const, |
| 3146 | Quals & Qualifiers::Volatile, RValueThis, |
| 3147 | ThisQuals & Qualifiers::Const, |
| 3148 | ThisQuals & Qualifiers::Volatile); |
| 3149 | |
| 3150 | return Result.getMethod(); |
| 3151 | } |
| 3152 | |
| 3153 | |
| 3154 | |
| 3155 | |
| 3156 | |
| 3157 | |
| 3158 | |
| 3159 | CXXDestructorDecl *Sema::LookupDestructor(CXXRecordDecl *Class) { |
| 3160 | return cast<CXXDestructorDecl>(LookupSpecialMember(Class, CXXDestructor, |
| 3161 | false, false, false, |
| 3162 | false, false).getMethod()); |
| 3163 | } |
| 3164 | |
| 3165 | |
| 3166 | |
| 3167 | |
| 3168 | |
| 3169 | |
| 3170 | |
| 3171 | Sema::LiteralOperatorLookupResult |
| 3172 | Sema::LookupLiteralOperator(Scope *S, LookupResult &R, |
| 3173 | ArrayRef<QualType> ArgTys, |
| 3174 | bool AllowRaw, bool AllowTemplate, |
| 3175 | bool AllowStringTemplate, bool DiagnoseMissing) { |
| 3176 | LookupName(R, S); |
| 3177 | (0) . __assert_fail ("R.getResultKind() != LookupResult..Ambiguous && \"literal operator lookup can't be ambiguous\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3178, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(R.getResultKind() != LookupResult::Ambiguous && |
| 3178 | (0) . __assert_fail ("R.getResultKind() != LookupResult..Ambiguous && \"literal operator lookup can't be ambiguous\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3178, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "literal operator lookup can't be ambiguous"); |
| 3179 | |
| 3180 | |
| 3181 | LookupResult::Filter F = R.makeFilter(); |
| 3182 | |
| 3183 | bool FoundRaw = false; |
| 3184 | bool FoundTemplate = false; |
| 3185 | bool FoundStringTemplate = false; |
| 3186 | bool FoundExactMatch = false; |
| 3187 | |
| 3188 | while (F.hasNext()) { |
| 3189 | Decl *D = F.next(); |
| 3190 | if (UsingShadowDecl *USD = dyn_cast<UsingShadowDecl>(D)) |
| 3191 | D = USD->getTargetDecl(); |
| 3192 | |
| 3193 | |
| 3194 | if (D->isInvalidDecl()) { |
| 3195 | F.erase(); |
| 3196 | continue; |
| 3197 | } |
| 3198 | |
| 3199 | bool IsRaw = false; |
| 3200 | bool IsTemplate = false; |
| 3201 | bool IsStringTemplate = false; |
| 3202 | bool IsExactMatch = false; |
| 3203 | |
| 3204 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 3205 | if (FD->getNumParams() == 1 && |
| 3206 | FD->getParamDecl(0)->getType()->getAs<PointerType>()) |
| 3207 | IsRaw = true; |
| 3208 | else if (FD->getNumParams() == ArgTys.size()) { |
| 3209 | IsExactMatch = true; |
| 3210 | for (unsigned ArgIdx = 0; ArgIdx != ArgTys.size(); ++ArgIdx) { |
| 3211 | QualType ParamTy = FD->getParamDecl(ArgIdx)->getType(); |
| 3212 | if (!Context.hasSameUnqualifiedType(ArgTys[ArgIdx], ParamTy)) { |
| 3213 | IsExactMatch = false; |
| 3214 | break; |
| 3215 | } |
| 3216 | } |
| 3217 | } |
| 3218 | } |
| 3219 | if (FunctionTemplateDecl *FD = dyn_cast<FunctionTemplateDecl>(D)) { |
| 3220 | TemplateParameterList *Params = FD->getTemplateParameters(); |
| 3221 | if (Params->size() == 1) |
| 3222 | IsTemplate = true; |
| 3223 | else |
| 3224 | IsStringTemplate = true; |
| 3225 | } |
| 3226 | |
| 3227 | if (IsExactMatch) { |
| 3228 | FoundExactMatch = true; |
| 3229 | AllowRaw = false; |
| 3230 | AllowTemplate = false; |
| 3231 | AllowStringTemplate = false; |
| 3232 | if (FoundRaw || FoundTemplate || FoundStringTemplate) { |
| 3233 | |
| 3234 | |
| 3235 | F.restart(); |
| 3236 | FoundRaw = FoundTemplate = FoundStringTemplate = false; |
| 3237 | } |
| 3238 | } else if (AllowRaw && IsRaw) { |
| 3239 | FoundRaw = true; |
| 3240 | } else if (AllowTemplate && IsTemplate) { |
| 3241 | FoundTemplate = true; |
| 3242 | } else if (AllowStringTemplate && IsStringTemplate) { |
| 3243 | FoundStringTemplate = true; |
| 3244 | } else { |
| 3245 | F.erase(); |
| 3246 | } |
| 3247 | } |
| 3248 | |
| 3249 | F.done(); |
| 3250 | |
| 3251 | |
| 3252 | |
| 3253 | |
| 3254 | if (FoundExactMatch) |
| 3255 | return LOLR_Cooked; |
| 3256 | |
| 3257 | |
| 3258 | |
| 3259 | if (FoundRaw && FoundTemplate) { |
| 3260 | Diag(R.getNameLoc(), diag::err_ovl_ambiguous_call) << R.getLookupName(); |
| 3261 | for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) |
| 3262 | NoteOverloadCandidate(*I, (*I)->getUnderlyingDecl()->getAsFunction()); |
| 3263 | return LOLR_Error; |
| 3264 | } |
| 3265 | |
| 3266 | if (FoundRaw) |
| 3267 | return LOLR_Raw; |
| 3268 | |
| 3269 | if (FoundTemplate) |
| 3270 | return LOLR_Template; |
| 3271 | |
| 3272 | if (FoundStringTemplate) |
| 3273 | return LOLR_StringTemplate; |
| 3274 | |
| 3275 | |
| 3276 | if (DiagnoseMissing) { |
| 3277 | Diag(R.getNameLoc(), diag::err_ovl_no_viable_literal_operator) |
| 3278 | << R.getLookupName() << (int)ArgTys.size() << ArgTys[0] |
| 3279 | << (ArgTys.size() == 2 ? ArgTys[1] : QualType()) << AllowRaw |
| 3280 | << (AllowTemplate || AllowStringTemplate); |
| 3281 | return LOLR_Error; |
| 3282 | } |
| 3283 | |
| 3284 | return LOLR_ErrorNoDiagnostic; |
| 3285 | } |
| 3286 | |
| 3287 | void ADLResult::insert(NamedDecl *New) { |
| 3288 | NamedDecl *&Old = Decls[cast<NamedDecl>(New->getCanonicalDecl())]; |
| 3289 | |
| 3290 | |
| 3291 | |
| 3292 | if (Old == nullptr || Old == New) { |
| 3293 | Old = New; |
| 3294 | return; |
| 3295 | } |
| 3296 | |
| 3297 | |
| 3298 | FunctionDecl *OldFD = Old->getAsFunction(); |
| 3299 | FunctionDecl *NewFD = New->getAsFunction(); |
| 3300 | |
| 3301 | FunctionDecl *Cursor = NewFD; |
| 3302 | while (true) { |
| 3303 | Cursor = Cursor->getPreviousDecl(); |
| 3304 | |
| 3305 | |
| 3306 | |
| 3307 | if (!Cursor) return; |
| 3308 | |
| 3309 | |
| 3310 | if (Cursor == OldFD) break; |
| 3311 | |
| 3312 | |
| 3313 | } |
| 3314 | |
| 3315 | Old = New; |
| 3316 | } |
| 3317 | |
| 3318 | void Sema::ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, |
| 3319 | ArrayRef<Expr *> Args, ADLResult &Result) { |
| 3320 | |
| 3321 | |
| 3322 | AssociatedNamespaceSet AssociatedNamespaces; |
| 3323 | AssociatedClassSet AssociatedClasses; |
| 3324 | FindAssociatedClassesAndNamespaces(Loc, Args, |
| 3325 | AssociatedNamespaces, |
| 3326 | AssociatedClasses); |
| 3327 | |
| 3328 | |
| 3329 | |
| 3330 | |
| 3331 | |
| 3332 | |
| 3333 | |
| 3334 | |
| 3335 | |
| 3336 | |
| 3337 | |
| 3338 | |
| 3339 | for (auto *NS : AssociatedNamespaces) { |
| 3340 | |
| 3341 | |
| 3342 | |
| 3343 | |
| 3344 | |
| 3345 | |
| 3346 | |
| 3347 | |
| 3348 | |
| 3349 | |
| 3350 | |
| 3351 | DeclContext::lookup_result R = NS->lookup(Name); |
| 3352 | for (auto *D : R) { |
| 3353 | auto *Underlying = D; |
| 3354 | if (auto *USD = dyn_cast<UsingShadowDecl>(D)) |
| 3355 | Underlying = USD->getTargetDecl(); |
| 3356 | |
| 3357 | if (!isa<FunctionDecl>(Underlying) && |
| 3358 | !isa<FunctionTemplateDecl>(Underlying)) |
| 3359 | continue; |
| 3360 | |
| 3361 | |
| 3362 | |
| 3363 | |
| 3364 | bool Visible = false; |
| 3365 | for (D = D->getMostRecentDecl(); D; |
| 3366 | D = cast_or_null<NamedDecl>(D->getPreviousDecl())) { |
| 3367 | if (D->getIdentifierNamespace() & Decl::IDNS_Ordinary) { |
| 3368 | if (isVisible(D)) { |
| 3369 | Visible = true; |
| 3370 | break; |
| 3371 | } |
| 3372 | } else if (D->getFriendObjectKind()) { |
| 3373 | auto *RD = cast<CXXRecordDecl>(D->getLexicalDeclContext()); |
| 3374 | if (AssociatedClasses.count(RD) && isVisible(D)) { |
| 3375 | Visible = true; |
| 3376 | break; |
| 3377 | } |
| 3378 | } |
| 3379 | } |
| 3380 | |
| 3381 | |
| 3382 | if (Visible) |
| 3383 | Result.insert(Underlying); |
| 3384 | } |
| 3385 | } |
| 3386 | } |
| 3387 | |
| 3388 | |
| 3389 | |
| 3390 | |
| 3391 | VisibleDeclConsumer::~VisibleDeclConsumer() { } |
| 3392 | |
| 3393 | bool VisibleDeclConsumer::includeHiddenDecls() const { return false; } |
| 3394 | |
| 3395 | namespace { |
| 3396 | |
| 3397 | class ShadowContextRAII; |
| 3398 | |
| 3399 | class VisibleDeclsRecord { |
| 3400 | public: |
| 3401 | |
| 3402 | |
| 3403 | |
| 3404 | typedef llvm::TinyPtrVector<NamedDecl*> ShadowMapEntry; |
| 3405 | |
| 3406 | private: |
| 3407 | |
| 3408 | |
| 3409 | typedef llvm::DenseMap<DeclarationName, ShadowMapEntry> ShadowMap; |
| 3410 | |
| 3411 | |
| 3412 | std::list<ShadowMap> ShadowMaps; |
| 3413 | |
| 3414 | |
| 3415 | llvm::SmallPtrSet<DeclContext *, 8> VisitedContexts; |
| 3416 | |
| 3417 | friend class ShadowContextRAII; |
| 3418 | |
| 3419 | public: |
| 3420 | |
| 3421 | |
| 3422 | bool visitedContext(DeclContext *Ctx) { |
| 3423 | return !VisitedContexts.insert(Ctx).second; |
| 3424 | } |
| 3425 | |
| 3426 | bool alreadyVisitedContext(DeclContext *Ctx) { |
| 3427 | return VisitedContexts.count(Ctx); |
| 3428 | } |
| 3429 | |
| 3430 | |
| 3431 | |
| 3432 | |
| 3433 | |
| 3434 | |
| 3435 | NamedDecl *checkHidden(NamedDecl *ND); |
| 3436 | |
| 3437 | |
| 3438 | void add(NamedDecl *ND) { |
| 3439 | ShadowMaps.back()[ND->getDeclName()].push_back(ND); |
| 3440 | } |
| 3441 | }; |
| 3442 | |
| 3443 | |
| 3444 | class ShadowContextRAII { |
| 3445 | VisibleDeclsRecord &Visible; |
| 3446 | |
| 3447 | typedef VisibleDeclsRecord::ShadowMap ShadowMap; |
| 3448 | |
| 3449 | public: |
| 3450 | ShadowContextRAII(VisibleDeclsRecord &Visible) : Visible(Visible) { |
| 3451 | Visible.ShadowMaps.emplace_back(); |
| 3452 | } |
| 3453 | |
| 3454 | ~ShadowContextRAII() { |
| 3455 | Visible.ShadowMaps.pop_back(); |
| 3456 | } |
| 3457 | }; |
| 3458 | |
| 3459 | } |
| 3460 | |
| 3461 | NamedDecl *VisibleDeclsRecord::checkHidden(NamedDecl *ND) { |
| 3462 | unsigned IDNS = ND->getIdentifierNamespace(); |
| 3463 | std::list<ShadowMap>::reverse_iterator SM = ShadowMaps.rbegin(); |
| 3464 | for (std::list<ShadowMap>::reverse_iterator SMEnd = ShadowMaps.rend(); |
| 3465 | SM != SMEnd; ++SM) { |
| 3466 | ShadowMap::iterator Pos = SM->find(ND->getDeclName()); |
| 3467 | if (Pos == SM->end()) |
| 3468 | continue; |
| 3469 | |
| 3470 | for (auto *D : Pos->second) { |
| 3471 | |
| 3472 | if (D->hasTagIdentifierNamespace() && |
| 3473 | (IDNS & (Decl::IDNS_Member | Decl::IDNS_Ordinary | |
| 3474 | Decl::IDNS_ObjCProtocol))) |
| 3475 | continue; |
| 3476 | |
| 3477 | |
| 3478 | if (((D->getIdentifierNamespace() & Decl::IDNS_ObjCProtocol) |
| 3479 | || (IDNS & Decl::IDNS_ObjCProtocol)) && |
| 3480 | D->getIdentifierNamespace() != IDNS) |
| 3481 | continue; |
| 3482 | |
| 3483 | |
| 3484 | |
| 3485 | |
| 3486 | if (D->getUnderlyingDecl()->isFunctionOrFunctionTemplate() && |
| 3487 | ND->getUnderlyingDecl()->isFunctionOrFunctionTemplate() && |
| 3488 | SM == ShadowMaps.rbegin()) |
| 3489 | continue; |
| 3490 | |
| 3491 | |
| 3492 | |
| 3493 | if (isa<UsingShadowDecl>(ND) && isa<UsingDecl>(D) && |
| 3494 | cast<UsingShadowDecl>(ND)->getUsingDecl() == D) |
| 3495 | continue; |
| 3496 | |
| 3497 | |
| 3498 | return D; |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | return nullptr; |
| 3503 | } |
| 3504 | |
| 3505 | static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result, |
| 3506 | bool QualifiedNameLookup, |
| 3507 | bool InBaseClass, |
| 3508 | VisibleDeclConsumer &Consumer, |
| 3509 | VisibleDeclsRecord &Visited, |
| 3510 | bool IncludeDependentBases, |
| 3511 | bool LoadExternal) { |
| 3512 | if (!Ctx) |
| 3513 | return; |
| 3514 | |
| 3515 | |
| 3516 | if (Visited.visitedContext(Ctx->getPrimaryContext())) |
| 3517 | return; |
| 3518 | |
| 3519 | Consumer.EnteredContext(Ctx); |
| 3520 | |
| 3521 | |
| 3522 | if (isa<TranslationUnitDecl>(Ctx) && |
| 3523 | !Result.getSema().getLangOpts().CPlusPlus) { |
| 3524 | auto &S = Result.getSema(); |
| 3525 | auto &Idents = S.Context.Idents; |
| 3526 | |
| 3527 | |
| 3528 | if (LoadExternal) |
| 3529 | if (IdentifierInfoLookup *External = Idents.getExternalIdentifierLookup()) { |
| 3530 | std::unique_ptr<IdentifierIterator> Iter(External->getIdentifiers()); |
| 3531 | for (StringRef Name = Iter->Next(); !Name.empty(); Name = Iter->Next()) |
| 3532 | Idents.get(Name); |
| 3533 | } |
| 3534 | |
| 3535 | |
| 3536 | for (const auto &Ident : Idents) { |
| 3537 | for (auto I = S.IdResolver.begin(Ident.getValue()), |
| 3538 | E = S.IdResolver.end(); |
| 3539 | I != E; ++I) { |
| 3540 | if (S.IdResolver.isDeclInScope(*I, Ctx)) { |
| 3541 | if (NamedDecl *ND = Result.getAcceptableDecl(*I)) { |
| 3542 | Consumer.FoundDecl(ND, Visited.checkHidden(ND), Ctx, InBaseClass); |
| 3543 | Visited.add(ND); |
| 3544 | } |
| 3545 | } |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | return; |
| 3550 | } |
| 3551 | |
| 3552 | if (CXXRecordDecl *Class = dyn_cast<CXXRecordDecl>(Ctx)) |
| 3553 | Result.getSema().ForceDeclarationOfImplicitMembers(Class); |
| 3554 | |
| 3555 | |
| 3556 | bool Load = LoadExternal || |
| 3557 | !(isa<TranslationUnitDecl>(Ctx) || isa<NamespaceDecl>(Ctx)); |
| 3558 | |
| 3559 | for (DeclContextLookupResult R : |
| 3560 | Load ? Ctx->lookups() |
| 3561 | : Ctx->noload_lookups()) { |
| 3562 | for (auto *D : R) { |
| 3563 | if (auto *ND = Result.getAcceptableDecl(D)) { |
| 3564 | Consumer.FoundDecl(ND, Visited.checkHidden(ND), Ctx, InBaseClass); |
| 3565 | Visited.add(ND); |
| 3566 | } |
| 3567 | } |
| 3568 | } |
| 3569 | |
| 3570 | |
| 3571 | if (QualifiedNameLookup) { |
| 3572 | ShadowContextRAII Shadow(Visited); |
| 3573 | for (auto I : Ctx->using_directives()) { |
| 3574 | if (!Result.getSema().isVisible(I)) |
| 3575 | continue; |
| 3576 | LookupVisibleDecls(I->getNominatedNamespace(), Result, |
| 3577 | QualifiedNameLookup, InBaseClass, Consumer, Visited, |
| 3578 | IncludeDependentBases, LoadExternal); |
| 3579 | } |
| 3580 | } |
| 3581 | |
| 3582 | |
| 3583 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Ctx)) { |
| 3584 | if (!Record->hasDefinition()) |
| 3585 | return; |
| 3586 | |
| 3587 | for (const auto &B : Record->bases()) { |
| 3588 | QualType BaseType = B.getType(); |
| 3589 | |
| 3590 | RecordDecl *RD; |
| 3591 | if (BaseType->isDependentType()) { |
| 3592 | if (!IncludeDependentBases) { |
| 3593 | |
| 3594 | |
| 3595 | continue; |
| 3596 | } |
| 3597 | const auto *TST = BaseType->getAs<TemplateSpecializationType>(); |
| 3598 | if (!TST) |
| 3599 | continue; |
| 3600 | TemplateName TN = TST->getTemplateName(); |
| 3601 | const auto *TD = |
| 3602 | dyn_cast_or_null<ClassTemplateDecl>(TN.getAsTemplateDecl()); |
| 3603 | if (!TD) |
| 3604 | continue; |
| 3605 | RD = TD->getTemplatedDecl(); |
| 3606 | } else { |
| 3607 | const auto *Record = BaseType->getAs<RecordType>(); |
| 3608 | if (!Record) |
| 3609 | continue; |
| 3610 | RD = Record->getDecl(); |
| 3611 | } |
| 3612 | |
| 3613 | |
| 3614 | |
| 3615 | |
| 3616 | |
| 3617 | |
| 3618 | |
| 3619 | |
| 3620 | |
| 3621 | |
| 3622 | |
| 3623 | |
| 3624 | |
| 3625 | |
| 3626 | |
| 3627 | |
| 3628 | |
| 3629 | |
| 3630 | |
| 3631 | |
| 3632 | |
| 3633 | ShadowContextRAII Shadow(Visited); |
| 3634 | LookupVisibleDecls(RD, Result, QualifiedNameLookup, , |
| 3635 | Consumer, Visited, IncludeDependentBases, |
| 3636 | LoadExternal); |
| 3637 | } |
| 3638 | } |
| 3639 | |
| 3640 | |
| 3641 | if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Ctx)) { |
| 3642 | |
| 3643 | for (auto *Cat : IFace->visible_categories()) { |
| 3644 | ShadowContextRAII Shadow(Visited); |
| 3645 | LookupVisibleDecls(Cat, Result, QualifiedNameLookup, false, Consumer, |
| 3646 | Visited, IncludeDependentBases, LoadExternal); |
| 3647 | } |
| 3648 | |
| 3649 | |
| 3650 | for (auto *I : IFace->all_referenced_protocols()) { |
| 3651 | ShadowContextRAII Shadow(Visited); |
| 3652 | LookupVisibleDecls(I, Result, QualifiedNameLookup, false, Consumer, |
| 3653 | Visited, IncludeDependentBases, LoadExternal); |
| 3654 | } |
| 3655 | |
| 3656 | |
| 3657 | if (IFace->getSuperClass()) { |
| 3658 | ShadowContextRAII Shadow(Visited); |
| 3659 | LookupVisibleDecls(IFace->getSuperClass(), Result, QualifiedNameLookup, |
| 3660 | true, Consumer, Visited, IncludeDependentBases, |
| 3661 | LoadExternal); |
| 3662 | } |
| 3663 | |
| 3664 | |
| 3665 | |
| 3666 | if (IFace->getImplementation()) { |
| 3667 | ShadowContextRAII Shadow(Visited); |
| 3668 | LookupVisibleDecls(IFace->getImplementation(), Result, |
| 3669 | QualifiedNameLookup, InBaseClass, Consumer, Visited, |
| 3670 | IncludeDependentBases, LoadExternal); |
| 3671 | } |
| 3672 | } else if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Ctx)) { |
| 3673 | for (auto *I : Protocol->protocols()) { |
| 3674 | ShadowContextRAII Shadow(Visited); |
| 3675 | LookupVisibleDecls(I, Result, QualifiedNameLookup, false, Consumer, |
| 3676 | Visited, IncludeDependentBases, LoadExternal); |
| 3677 | } |
| 3678 | } else if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(Ctx)) { |
| 3679 | for (auto *I : Category->protocols()) { |
| 3680 | ShadowContextRAII Shadow(Visited); |
| 3681 | LookupVisibleDecls(I, Result, QualifiedNameLookup, false, Consumer, |
| 3682 | Visited, IncludeDependentBases, LoadExternal); |
| 3683 | } |
| 3684 | |
| 3685 | |
| 3686 | if (Category->getImplementation()) { |
| 3687 | ShadowContextRAII Shadow(Visited); |
| 3688 | LookupVisibleDecls(Category->getImplementation(), Result, |
| 3689 | QualifiedNameLookup, true, Consumer, Visited, |
| 3690 | IncludeDependentBases, LoadExternal); |
| 3691 | } |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | static void LookupVisibleDecls(Scope *S, LookupResult &Result, |
| 3696 | UnqualUsingDirectiveSet &UDirs, |
| 3697 | VisibleDeclConsumer &Consumer, |
| 3698 | VisibleDeclsRecord &Visited, |
| 3699 | bool LoadExternal) { |
| 3700 | if (!S) |
| 3701 | return; |
| 3702 | |
| 3703 | if (!S->getEntity() || |
| 3704 | (!S->getParent() && |
| 3705 | !Visited.alreadyVisitedContext(S->getEntity())) || |
| 3706 | (S->getEntity())->isFunctionOrMethod()) { |
| 3707 | FindLocalExternScope FindLocals(Result); |
| 3708 | |
| 3709 | |
| 3710 | SmallVector<Decl *, 8> ScopeDecls(S->decls().begin(), S->decls().end()); |
| 3711 | for (Decl *D : ScopeDecls) { |
| 3712 | if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
| 3713 | if ((ND = Result.getAcceptableDecl(ND))) { |
| 3714 | Consumer.FoundDecl(ND, Visited.checkHidden(ND), nullptr, false); |
| 3715 | Visited.add(ND); |
| 3716 | } |
| 3717 | } |
| 3718 | } |
| 3719 | |
| 3720 | |
| 3721 | DeclContext *Entity = nullptr; |
| 3722 | if (S->getEntity()) { |
| 3723 | |
| 3724 | |
| 3725 | |
| 3726 | Entity = S->getEntity(); |
| 3727 | DeclContext *OuterCtx = findOuterContext(S).first; |
| 3728 | |
| 3729 | for (DeclContext *Ctx = Entity; Ctx && !Ctx->Equals(OuterCtx); |
| 3730 | Ctx = Ctx->getLookupParent()) { |
| 3731 | if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(Ctx)) { |
| 3732 | if (Method->isInstanceMethod()) { |
| 3733 | |
| 3734 | LookupResult IvarResult(Result.getSema(), Result.getLookupName(), |
| 3735 | Result.getNameLoc(), Sema::LookupMemberName); |
| 3736 | if (ObjCInterfaceDecl *IFace = Method->getClassInterface()) { |
| 3737 | LookupVisibleDecls(IFace, IvarResult, , |
| 3738 | , Consumer, Visited, |
| 3739 | , LoadExternal); |
| 3740 | } |
| 3741 | } |
| 3742 | |
| 3743 | |
| 3744 | |
| 3745 | |
| 3746 | break; |
| 3747 | } |
| 3748 | |
| 3749 | if (Ctx->isFunctionOrMethod()) |
| 3750 | continue; |
| 3751 | |
| 3752 | LookupVisibleDecls(Ctx, Result, , |
| 3753 | , Consumer, Visited, |
| 3754 | , LoadExternal); |
| 3755 | } |
| 3756 | } else if (!S->getParent()) { |
| 3757 | |
| 3758 | |
| 3759 | |
| 3760 | |
| 3761 | |
| 3762 | |
| 3763 | |
| 3764 | |
| 3765 | |
| 3766 | Entity = Result.getSema().Context.getTranslationUnitDecl(); |
| 3767 | LookupVisibleDecls(Entity, Result, , |
| 3768 | , Consumer, Visited, |
| 3769 | , LoadExternal); |
| 3770 | } |
| 3771 | |
| 3772 | if (Entity) { |
| 3773 | |
| 3774 | |
| 3775 | for (const UnqualUsingEntry &UUE : UDirs.getNamespacesFor(Entity)) |
| 3776 | LookupVisibleDecls(const_cast<DeclContext *>(UUE.getNominatedNamespace()), |
| 3777 | Result, , |
| 3778 | , Consumer, Visited, |
| 3779 | , LoadExternal); |
| 3780 | } |
| 3781 | |
| 3782 | |
| 3783 | ShadowContextRAII Shadow(Visited); |
| 3784 | LookupVisibleDecls(S->getParent(), Result, UDirs, Consumer, Visited, |
| 3785 | LoadExternal); |
| 3786 | } |
| 3787 | |
| 3788 | void Sema::LookupVisibleDecls(Scope *S, LookupNameKind Kind, |
| 3789 | VisibleDeclConsumer &Consumer, |
| 3790 | bool IncludeGlobalScope, bool LoadExternal) { |
| 3791 | |
| 3792 | |
| 3793 | Scope *Initial = S; |
| 3794 | UnqualUsingDirectiveSet UDirs(*this); |
| 3795 | if (getLangOpts().CPlusPlus) { |
| 3796 | |
| 3797 | while (S && !isNamespaceOrTranslationUnitScope(S)) |
| 3798 | S = S->getParent(); |
| 3799 | |
| 3800 | UDirs.visitScopeChain(Initial, S); |
| 3801 | } |
| 3802 | UDirs.done(); |
| 3803 | |
| 3804 | |
| 3805 | LookupResult Result(*this, DeclarationName(), SourceLocation(), Kind); |
| 3806 | Result.setAllowHidden(Consumer.includeHiddenDecls()); |
| 3807 | VisibleDeclsRecord Visited; |
| 3808 | if (!IncludeGlobalScope) |
| 3809 | Visited.visitedContext(Context.getTranslationUnitDecl()); |
| 3810 | ShadowContextRAII Shadow(Visited); |
| 3811 | ::LookupVisibleDecls(Initial, Result, UDirs, Consumer, Visited, LoadExternal); |
| 3812 | } |
| 3813 | |
| 3814 | void Sema::LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, |
| 3815 | VisibleDeclConsumer &Consumer, |
| 3816 | bool IncludeGlobalScope, |
| 3817 | bool IncludeDependentBases, bool LoadExternal) { |
| 3818 | LookupResult Result(*this, DeclarationName(), SourceLocation(), Kind); |
| 3819 | Result.setAllowHidden(Consumer.includeHiddenDecls()); |
| 3820 | VisibleDeclsRecord Visited; |
| 3821 | if (!IncludeGlobalScope) |
| 3822 | Visited.visitedContext(Context.getTranslationUnitDecl()); |
| 3823 | ShadowContextRAII Shadow(Visited); |
| 3824 | ::LookupVisibleDecls(Ctx, Result, , |
| 3825 | , Consumer, Visited, |
| 3826 | IncludeDependentBases, LoadExternal); |
| 3827 | } |
| 3828 | |
| 3829 | |
| 3830 | |
| 3831 | |
| 3832 | |
| 3833 | LabelDecl *Sema::LookupOrCreateLabel(IdentifierInfo *II, SourceLocation Loc, |
| 3834 | SourceLocation GnuLabelLoc) { |
| 3835 | |
| 3836 | NamedDecl *Res = nullptr; |
| 3837 | |
| 3838 | if (GnuLabelLoc.isValid()) { |
| 3839 | |
| 3840 | Res = LabelDecl::Create(Context, CurContext, Loc, II, GnuLabelLoc); |
| 3841 | Scope *S = CurScope; |
| 3842 | PushOnScopeChains(Res, S, true); |
| 3843 | return cast<LabelDecl>(Res); |
| 3844 | } |
| 3845 | |
| 3846 | |
| 3847 | Res = LookupSingleName(CurScope, II, Loc, LookupLabel, NotForRedeclaration); |
| 3848 | |
| 3849 | |
| 3850 | if (Res && Res->getDeclContext() != CurContext) |
| 3851 | Res = nullptr; |
| 3852 | if (!Res) { |
| 3853 | |
| 3854 | Res = LabelDecl::Create(Context, CurContext, Loc, II); |
| 3855 | Scope *S = CurScope->getFnParent(); |
| 3856 | (0) . __assert_fail ("S && \"Not in a function?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 3856, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(S && "Not in a function?"); |
| 3857 | PushOnScopeChains(Res, S, true); |
| 3858 | } |
| 3859 | return cast<LabelDecl>(Res); |
| 3860 | } |
| 3861 | |
| 3862 | |
| 3863 | |
| 3864 | |
| 3865 | |
| 3866 | static bool isCandidateViable(CorrectionCandidateCallback &CCC, |
| 3867 | TypoCorrection &Candidate) { |
| 3868 | Candidate.setCallbackDistance(CCC.RankCandidate(Candidate)); |
| 3869 | return Candidate.getEditDistance(false) != TypoCorrection::InvalidDistance; |
| 3870 | } |
| 3871 | |
| 3872 | static void LookupPotentialTypoResult(Sema &SemaRef, |
| 3873 | LookupResult &Res, |
| 3874 | IdentifierInfo *Name, |
| 3875 | Scope *S, CXXScopeSpec *SS, |
| 3876 | DeclContext *MemberContext, |
| 3877 | bool EnteringContext, |
| 3878 | bool isObjCIvarLookup, |
| 3879 | bool FindHidden); |
| 3880 | |
| 3881 | |
| 3882 | |
| 3883 | |
| 3884 | static void checkCorrectionVisibility(Sema &SemaRef, TypoCorrection &TC) { |
| 3885 | TypoCorrection::decl_iterator DI = TC.begin(), DE = TC.end(); |
| 3886 | |
| 3887 | for (; DI != DE; ++DI) |
| 3888 | if (!LookupResult::isVisible(SemaRef, *DI)) |
| 3889 | break; |
| 3890 | |
| 3891 | if (DI == DE) { |
| 3892 | TC.setRequiresImport(false); |
| 3893 | return; |
| 3894 | } |
| 3895 | |
| 3896 | llvm::SmallVector<NamedDecl*, 4> NewDecls(TC.begin(), DI); |
| 3897 | bool AnyVisibleDecls = !NewDecls.empty(); |
| 3898 | |
| 3899 | for (; DI != DE; ++DI) { |
| 3900 | if (LookupResult::isVisible(SemaRef, *DI)) { |
| 3901 | if (!AnyVisibleDecls) { |
| 3902 | |
| 3903 | AnyVisibleDecls = true; |
| 3904 | NewDecls.clear(); |
| 3905 | } |
| 3906 | NewDecls.push_back(*DI); |
| 3907 | } else if (!AnyVisibleDecls && !(*DI)->isModulePrivate()) |
| 3908 | NewDecls.push_back(*DI); |
| 3909 | } |
| 3910 | |
| 3911 | if (NewDecls.empty()) |
| 3912 | TC = TypoCorrection(); |
| 3913 | else { |
| 3914 | TC.setCorrectionDecls(NewDecls); |
| 3915 | TC.setRequiresImport(!AnyVisibleDecls); |
| 3916 | } |
| 3917 | } |
| 3918 | |
| 3919 | |
| 3920 | |
| 3921 | |
| 3922 | static void getNestedNameSpecifierIdentifiers( |
| 3923 | NestedNameSpecifier *NNS, |
| 3924 | SmallVectorImpl<const IdentifierInfo*> &Identifiers) { |
| 3925 | if (NestedNameSpecifier *Prefix = NNS->getPrefix()) |
| 3926 | getNestedNameSpecifierIdentifiers(Prefix, Identifiers); |
| 3927 | else |
| 3928 | Identifiers.clear(); |
| 3929 | |
| 3930 | const IdentifierInfo *II = nullptr; |
| 3931 | |
| 3932 | switch (NNS->getKind()) { |
| 3933 | case NestedNameSpecifier::Identifier: |
| 3934 | II = NNS->getAsIdentifier(); |
| 3935 | break; |
| 3936 | |
| 3937 | case NestedNameSpecifier::Namespace: |
| 3938 | if (NNS->getAsNamespace()->isAnonymousNamespace()) |
| 3939 | return; |
| 3940 | II = NNS->getAsNamespace()->getIdentifier(); |
| 3941 | break; |
| 3942 | |
| 3943 | case NestedNameSpecifier::NamespaceAlias: |
| 3944 | II = NNS->getAsNamespaceAlias()->getIdentifier(); |
| 3945 | break; |
| 3946 | |
| 3947 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3948 | case NestedNameSpecifier::TypeSpec: |
| 3949 | II = QualType(NNS->getAsType(), 0).getBaseTypeIdentifier(); |
| 3950 | break; |
| 3951 | |
| 3952 | case NestedNameSpecifier::Global: |
| 3953 | case NestedNameSpecifier::Super: |
| 3954 | return; |
| 3955 | } |
| 3956 | |
| 3957 | if (II) |
| 3958 | Identifiers.push_back(II); |
| 3959 | } |
| 3960 | |
| 3961 | void TypoCorrectionConsumer::FoundDecl(NamedDecl *ND, NamedDecl *Hiding, |
| 3962 | DeclContext *Ctx, bool InBaseClass) { |
| 3963 | |
| 3964 | if (Hiding) |
| 3965 | return; |
| 3966 | |
| 3967 | |
| 3968 | |
| 3969 | |
| 3970 | IdentifierInfo *Name = ND->getIdentifier(); |
| 3971 | if (!Name) |
| 3972 | return; |
| 3973 | |
| 3974 | |
| 3975 | |
| 3976 | if (!LookupResult::isVisible(SemaRef, ND) && Name != Typo) |
| 3977 | return; |
| 3978 | |
| 3979 | FoundName(Name->getName()); |
| 3980 | } |
| 3981 | |
| 3982 | void TypoCorrectionConsumer::FoundName(StringRef Name) { |
| 3983 | |
| 3984 | |
| 3985 | addName(Name, nullptr); |
| 3986 | } |
| 3987 | |
| 3988 | void TypoCorrectionConsumer::addKeywordResult(StringRef Keyword) { |
| 3989 | |
| 3990 | |
| 3991 | addName(Keyword, nullptr, nullptr, true); |
| 3992 | } |
| 3993 | |
| 3994 | void TypoCorrectionConsumer::addName(StringRef Name, NamedDecl *ND, |
| 3995 | NestedNameSpecifier *NNS, bool isKeyword) { |
| 3996 | |
| 3997 | |
| 3998 | StringRef TypoStr = Typo->getName(); |
| 3999 | unsigned MinED = abs((int)Name.size() - (int)TypoStr.size()); |
| 4000 | if (MinED && TypoStr.size() / MinED < 3) |
| 4001 | return; |
| 4002 | |
| 4003 | |
| 4004 | |
| 4005 | unsigned UpperBound = (TypoStr.size() + 2) / 3; |
| 4006 | unsigned ED = TypoStr.edit_distance(Name, true, UpperBound); |
| 4007 | if (ED > UpperBound) return; |
| 4008 | |
| 4009 | TypoCorrection TC(&SemaRef.Context.Idents.get(Name), ND, NNS, ED); |
| 4010 | if (isKeyword) TC.makeKeyword(); |
| 4011 | TC.setCorrectionRange(nullptr, Result.getLookupNameInfo()); |
| 4012 | addCorrection(TC); |
| 4013 | } |
| 4014 | |
| 4015 | static const unsigned MaxTypoDistanceResultSets = 5; |
| 4016 | |
| 4017 | void TypoCorrectionConsumer::addCorrection(TypoCorrection Correction) { |
| 4018 | StringRef TypoStr = Typo->getName(); |
| 4019 | StringRef Name = Correction.getCorrectionAsIdentifierInfo()->getName(); |
| 4020 | |
| 4021 | |
| 4022 | |
| 4023 | |
| 4024 | if (TypoStr.size() < 3 && |
| 4025 | (Name != TypoStr || Correction.getEditDistance(true) > TypoStr.size())) |
| 4026 | return; |
| 4027 | |
| 4028 | |
| 4029 | if (Correction.isResolved()) { |
| 4030 | checkCorrectionVisibility(SemaRef, Correction); |
| 4031 | if (!Correction || !isCandidateViable(*CorrectionValidator, Correction)) |
| 4032 | return; |
| 4033 | } |
| 4034 | |
| 4035 | TypoResultList &CList = |
| 4036 | CorrectionResults[Correction.getEditDistance(false)][Name]; |
| 4037 | |
| 4038 | if (!CList.empty() && !CList.back().isResolved()) |
| 4039 | CList.pop_back(); |
| 4040 | if (NamedDecl *NewND = Correction.getCorrectionDecl()) { |
| 4041 | std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts()); |
| 4042 | for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end(); |
| 4043 | RI != RIEnd; ++RI) { |
| 4044 | |
| 4045 | |
| 4046 | |
| 4047 | |
| 4048 | if (RI->getCorrectionDecl() == NewND) { |
| 4049 | if (CorrectionStr < RI->getAsString(SemaRef.getLangOpts())) |
| 4050 | *RI = Correction; |
| 4051 | return; |
| 4052 | } |
| 4053 | } |
| 4054 | } |
| 4055 | if (CList.empty() || Correction.isResolved()) |
| 4056 | CList.push_back(Correction); |
| 4057 | |
| 4058 | while (CorrectionResults.size() > MaxTypoDistanceResultSets) |
| 4059 | CorrectionResults.erase(std::prev(CorrectionResults.end())); |
| 4060 | } |
| 4061 | |
| 4062 | void TypoCorrectionConsumer::addNamespaces( |
| 4063 | const llvm::MapVector<NamespaceDecl *, bool> &KnownNamespaces) { |
| 4064 | SearchNamespaces = true; |
| 4065 | |
| 4066 | for (auto KNPair : KnownNamespaces) |
| 4067 | Namespaces.addNameSpecifier(KNPair.first); |
| 4068 | |
| 4069 | bool SSIsTemplate = false; |
| 4070 | if (NestedNameSpecifier *NNS = |
| 4071 | (SS && SS->isValid()) ? SS->getScopeRep() : nullptr) { |
| 4072 | if (const Type *T = NNS->getAsType()) |
| 4073 | SSIsTemplate = T->getTypeClass() == Type::TemplateSpecialization; |
| 4074 | } |
| 4075 | |
| 4076 | |
| 4077 | |
| 4078 | auto &Types = SemaRef.getASTContext().getTypes(); |
| 4079 | for (unsigned I = 0; I != Types.size(); ++I) { |
| 4080 | const auto *TI = Types[I]; |
| 4081 | if (CXXRecordDecl *CD = TI->getAsCXXRecordDecl()) { |
| 4082 | CD = CD->getCanonicalDecl(); |
| 4083 | if (!CD->isDependentType() && !CD->isAnonymousStructOrUnion() && |
| 4084 | !CD->isUnion() && CD->getIdentifier() && |
| 4085 | (SSIsTemplate || !isa<ClassTemplateSpecializationDecl>(CD)) && |
| 4086 | (CD->isBeingDefined() || CD->isCompleteDefinition())) |
| 4087 | Namespaces.addNameSpecifier(CD); |
| 4088 | } |
| 4089 | } |
| 4090 | } |
| 4091 | |
| 4092 | const TypoCorrection &TypoCorrectionConsumer::getNextCorrection() { |
| 4093 | if (++CurrentTCIndex < ValidatedCorrections.size()) |
| 4094 | return ValidatedCorrections[CurrentTCIndex]; |
| 4095 | |
| 4096 | CurrentTCIndex = ValidatedCorrections.size(); |
| 4097 | while (!CorrectionResults.empty()) { |
| 4098 | auto DI = CorrectionResults.begin(); |
| 4099 | if (DI->second.empty()) { |
| 4100 | CorrectionResults.erase(DI); |
| 4101 | continue; |
| 4102 | } |
| 4103 | |
| 4104 | auto RI = DI->second.begin(); |
| 4105 | if (RI->second.empty()) { |
| 4106 | DI->second.erase(RI); |
| 4107 | performQualifiedLookups(); |
| 4108 | continue; |
| 4109 | } |
| 4110 | |
| 4111 | TypoCorrection TC = RI->second.pop_back_val(); |
| 4112 | if (TC.isResolved() || TC.requiresImport() || resolveCorrection(TC)) { |
| 4113 | ValidatedCorrections.push_back(TC); |
| 4114 | return ValidatedCorrections[CurrentTCIndex]; |
| 4115 | } |
| 4116 | } |
| 4117 | return ValidatedCorrections[0]; |
| 4118 | } |
| 4119 | |
| 4120 | bool TypoCorrectionConsumer::resolveCorrection(TypoCorrection &Candidate) { |
| 4121 | IdentifierInfo *Name = Candidate.getCorrectionAsIdentifierInfo(); |
| 4122 | DeclContext *TempMemberContext = MemberContext; |
| 4123 | CXXScopeSpec *TempSS = SS.get(); |
| 4124 | retry_lookup: |
| 4125 | LookupPotentialTypoResult(SemaRef, Result, Name, S, TempSS, TempMemberContext, |
| 4126 | EnteringContext, |
| 4127 | CorrectionValidator->IsObjCIvarLookup, |
| 4128 | Name == Typo && !Candidate.WillReplaceSpecifier()); |
| 4129 | switch (Result.getResultKind()) { |
| 4130 | case LookupResult::NotFound: |
| 4131 | case LookupResult::NotFoundInCurrentInstantiation: |
| 4132 | case LookupResult::FoundUnresolvedValue: |
| 4133 | if (TempSS) { |
| 4134 | |
| 4135 | TempSS = nullptr; |
| 4136 | Candidate.WillReplaceSpecifier(true); |
| 4137 | goto retry_lookup; |
| 4138 | } |
| 4139 | if (TempMemberContext) { |
| 4140 | if (SS && !TempSS) |
| 4141 | TempSS = SS.get(); |
| 4142 | TempMemberContext = nullptr; |
| 4143 | goto retry_lookup; |
| 4144 | } |
| 4145 | if (SearchNamespaces) |
| 4146 | QualifiedResults.push_back(Candidate); |
| 4147 | break; |
| 4148 | |
| 4149 | case LookupResult::Ambiguous: |
| 4150 | |
| 4151 | break; |
| 4152 | |
| 4153 | case LookupResult::Found: |
| 4154 | case LookupResult::FoundOverloaded: |
| 4155 | |
| 4156 | for (auto *TRD : Result) |
| 4157 | Candidate.addCorrectionDecl(TRD); |
| 4158 | checkCorrectionVisibility(SemaRef, Candidate); |
| 4159 | if (!isCandidateViable(*CorrectionValidator, Candidate)) { |
| 4160 | if (SearchNamespaces) |
| 4161 | QualifiedResults.push_back(Candidate); |
| 4162 | break; |
| 4163 | } |
| 4164 | Candidate.setCorrectionRange(SS.get(), Result.getLookupNameInfo()); |
| 4165 | return true; |
| 4166 | } |
| 4167 | return false; |
| 4168 | } |
| 4169 | |
| 4170 | void TypoCorrectionConsumer::performQualifiedLookups() { |
| 4171 | unsigned TypoLen = Typo->getName().size(); |
| 4172 | for (const TypoCorrection &QR : QualifiedResults) { |
| 4173 | for (const auto &NSI : Namespaces) { |
| 4174 | DeclContext *Ctx = NSI.DeclCtx; |
| 4175 | const Type *NSType = NSI.NameSpecifier->getAsType(); |
| 4176 | |
| 4177 | |
| 4178 | |
| 4179 | |
| 4180 | |
| 4181 | if (CXXRecordDecl *NSDecl = NSType ? NSType->getAsCXXRecordDecl() : |
| 4182 | nullptr) { |
| 4183 | if (NSDecl->getIdentifier() == QR.getCorrectionAsIdentifierInfo()) |
| 4184 | continue; |
| 4185 | } |
| 4186 | |
| 4187 | TypoCorrection TC(QR); |
| 4188 | TC.ClearCorrectionDecls(); |
| 4189 | TC.setCorrectionSpecifier(NSI.NameSpecifier); |
| 4190 | TC.setQualifierDistance(NSI.EditDistance); |
| 4191 | TC.setCallbackDistance(0); |
| 4192 | |
| 4193 | |
| 4194 | |
| 4195 | |
| 4196 | unsigned TmpED = TC.getEditDistance(true); |
| 4197 | if (QR.getCorrectionAsIdentifierInfo() != Typo && TmpED && |
| 4198 | TypoLen / TmpED < 3) |
| 4199 | continue; |
| 4200 | |
| 4201 | Result.clear(); |
| 4202 | Result.setLookupName(QR.getCorrectionAsIdentifierInfo()); |
| 4203 | if (!SemaRef.LookupQualifiedName(Result, Ctx)) |
| 4204 | continue; |
| 4205 | |
| 4206 | |
| 4207 | |
| 4208 | switch (Result.getResultKind()) { |
| 4209 | case LookupResult::Found: |
| 4210 | case LookupResult::FoundOverloaded: { |
| 4211 | if (SS && SS->isValid()) { |
| 4212 | std::string NewQualified = TC.getAsString(SemaRef.getLangOpts()); |
| 4213 | std::string OldQualified; |
| 4214 | llvm::raw_string_ostream OldOStream(OldQualified); |
| 4215 | SS->getScopeRep()->print(OldOStream, SemaRef.getPrintingPolicy()); |
| 4216 | OldOStream << Typo->getName(); |
| 4217 | |
| 4218 | |
| 4219 | |
| 4220 | if (OldOStream.str() == NewQualified) |
| 4221 | break; |
| 4222 | } |
| 4223 | for (LookupResult::iterator TRD = Result.begin(), TRDEnd = Result.end(); |
| 4224 | TRD != TRDEnd; ++TRD) { |
| 4225 | if (SemaRef.CheckMemberAccess(TC.getCorrectionRange().getBegin(), |
| 4226 | NSType ? NSType->getAsCXXRecordDecl() |
| 4227 | : nullptr, |
| 4228 | TRD.getPair()) == Sema::AR_accessible) |
| 4229 | TC.addCorrectionDecl(*TRD); |
| 4230 | } |
| 4231 | if (TC.isResolved()) { |
| 4232 | TC.setCorrectionRange(SS.get(), Result.getLookupNameInfo()); |
| 4233 | addCorrection(TC); |
| 4234 | } |
| 4235 | break; |
| 4236 | } |
| 4237 | case LookupResult::NotFound: |
| 4238 | case LookupResult::NotFoundInCurrentInstantiation: |
| 4239 | case LookupResult::Ambiguous: |
| 4240 | case LookupResult::FoundUnresolvedValue: |
| 4241 | break; |
| 4242 | } |
| 4243 | } |
| 4244 | } |
| 4245 | QualifiedResults.clear(); |
| 4246 | } |
| 4247 | |
| 4248 | TypoCorrectionConsumer::NamespaceSpecifierSet::NamespaceSpecifierSet( |
| 4249 | ASTContext &Context, DeclContext *CurContext, CXXScopeSpec *CurScopeSpec) |
| 4250 | : Context(Context), CurContextChain(buildContextChain(CurContext)) { |
| 4251 | if (NestedNameSpecifier *NNS = |
| 4252 | CurScopeSpec ? CurScopeSpec->getScopeRep() : nullptr) { |
| 4253 | llvm::raw_string_ostream SpecifierOStream(CurNameSpecifier); |
| 4254 | NNS->print(SpecifierOStream, Context.getPrintingPolicy()); |
| 4255 | |
| 4256 | getNestedNameSpecifierIdentifiers(NNS, CurNameSpecifierIdentifiers); |
| 4257 | } |
| 4258 | |
| 4259 | |
| 4260 | |
| 4261 | for (DeclContext *C : llvm::reverse(CurContextChain)) { |
| 4262 | if (auto *ND = dyn_cast_or_null<NamespaceDecl>(C)) |
| 4263 | CurContextIdentifiers.push_back(ND->getIdentifier()); |
| 4264 | } |
| 4265 | |
| 4266 | |
| 4267 | SpecifierInfo SI = {cast<DeclContext>(Context.getTranslationUnitDecl()), |
| 4268 | NestedNameSpecifier::GlobalSpecifier(Context), 1}; |
| 4269 | DistanceMap[1].push_back(SI); |
| 4270 | } |
| 4271 | |
| 4272 | auto TypoCorrectionConsumer::NamespaceSpecifierSet::buildContextChain( |
| 4273 | DeclContext *Start) -> DeclContextList { |
| 4274 | (0) . __assert_fail ("Start && \"Building a context chain from a null context\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 4274, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Start && "Building a context chain from a null context"); |
| 4275 | DeclContextList Chain; |
| 4276 | for (DeclContext *DC = Start->getPrimaryContext(); DC != nullptr; |
| 4277 | DC = DC->getLookupParent()) { |
| 4278 | NamespaceDecl *ND = dyn_cast_or_null<NamespaceDecl>(DC); |
| 4279 | if (!DC->isInlineNamespace() && !DC->isTransparentContext() && |
| 4280 | !(ND && ND->isAnonymousNamespace())) |
| 4281 | Chain.push_back(DC->getPrimaryContext()); |
| 4282 | } |
| 4283 | return Chain; |
| 4284 | } |
| 4285 | |
| 4286 | unsigned |
| 4287 | TypoCorrectionConsumer::NamespaceSpecifierSet::buildNestedNameSpecifier( |
| 4288 | DeclContextList &DeclChain, NestedNameSpecifier *&NNS) { |
| 4289 | unsigned NumSpecifiers = 0; |
| 4290 | for (DeclContext *C : llvm::reverse(DeclChain)) { |
| 4291 | if (auto *ND = dyn_cast_or_null<NamespaceDecl>(C)) { |
| 4292 | NNS = NestedNameSpecifier::Create(Context, NNS, ND); |
| 4293 | ++NumSpecifiers; |
| 4294 | } else if (auto *RD = dyn_cast_or_null<RecordDecl>(C)) { |
| 4295 | NNS = NestedNameSpecifier::Create(Context, NNS, RD->isTemplateDecl(), |
| 4296 | RD->getTypeForDecl()); |
| 4297 | ++NumSpecifiers; |
| 4298 | } |
| 4299 | } |
| 4300 | return NumSpecifiers; |
| 4301 | } |
| 4302 | |
| 4303 | void TypoCorrectionConsumer::NamespaceSpecifierSet::addNameSpecifier( |
| 4304 | DeclContext *Ctx) { |
| 4305 | NestedNameSpecifier *NNS = nullptr; |
| 4306 | unsigned NumSpecifiers = 0; |
| 4307 | DeclContextList NamespaceDeclChain(buildContextChain(Ctx)); |
| 4308 | DeclContextList FullNamespaceDeclChain(NamespaceDeclChain); |
| 4309 | |
| 4310 | |
| 4311 | for (DeclContext *C : llvm::reverse(CurContextChain)) { |
| 4312 | if (NamespaceDeclChain.empty() || NamespaceDeclChain.back() != C) |
| 4313 | break; |
| 4314 | NamespaceDeclChain.pop_back(); |
| 4315 | } |
| 4316 | |
| 4317 | |
| 4318 | NumSpecifiers = buildNestedNameSpecifier(NamespaceDeclChain, NNS); |
| 4319 | |
| 4320 | |
| 4321 | if (NamespaceDeclChain.empty()) { |
| 4322 | |
| 4323 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
| 4324 | NumSpecifiers = |
| 4325 | buildNestedNameSpecifier(FullNamespaceDeclChain, NNS); |
| 4326 | } else if (NamedDecl *ND = |
| 4327 | dyn_cast_or_null<NamedDecl>(NamespaceDeclChain.back())) { |
| 4328 | IdentifierInfo *Name = ND->getIdentifier(); |
| 4329 | bool SameNameSpecifier = false; |
| 4330 | if (std::find(CurNameSpecifierIdentifiers.begin(), |
| 4331 | CurNameSpecifierIdentifiers.end(), |
| 4332 | Name) != CurNameSpecifierIdentifiers.end()) { |
| 4333 | std::string NewNameSpecifier; |
| 4334 | llvm::raw_string_ostream SpecifierOStream(NewNameSpecifier); |
| 4335 | SmallVector<const IdentifierInfo *, 4> NewNameSpecifierIdentifiers; |
| 4336 | getNestedNameSpecifierIdentifiers(NNS, NewNameSpecifierIdentifiers); |
| 4337 | NNS->print(SpecifierOStream, Context.getPrintingPolicy()); |
| 4338 | SpecifierOStream.flush(); |
| 4339 | SameNameSpecifier = NewNameSpecifier == CurNameSpecifier; |
| 4340 | } |
| 4341 | if (SameNameSpecifier || |
| 4342 | std::find(CurContextIdentifiers.begin(), CurContextIdentifiers.end(), |
| 4343 | Name) != CurContextIdentifiers.end()) { |
| 4344 | |
| 4345 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
| 4346 | NumSpecifiers = |
| 4347 | buildNestedNameSpecifier(FullNamespaceDeclChain, NNS); |
| 4348 | } |
| 4349 | } |
| 4350 | |
| 4351 | |
| 4352 | |
| 4353 | |
| 4354 | |
| 4355 | if (NNS && !CurNameSpecifierIdentifiers.empty()) { |
| 4356 | SmallVector<const IdentifierInfo*, 4> NewNameSpecifierIdentifiers; |
| 4357 | getNestedNameSpecifierIdentifiers(NNS, NewNameSpecifierIdentifiers); |
| 4358 | NumSpecifiers = llvm::ComputeEditDistance( |
| 4359 | llvm::makeArrayRef(CurNameSpecifierIdentifiers), |
| 4360 | llvm::makeArrayRef(NewNameSpecifierIdentifiers)); |
| 4361 | } |
| 4362 | |
| 4363 | SpecifierInfo SI = {Ctx, NNS, NumSpecifiers}; |
| 4364 | DistanceMap[NumSpecifiers].push_back(SI); |
| 4365 | } |
| 4366 | |
| 4367 | |
| 4368 | static void LookupPotentialTypoResult(Sema &SemaRef, |
| 4369 | LookupResult &Res, |
| 4370 | IdentifierInfo *Name, |
| 4371 | Scope *S, CXXScopeSpec *SS, |
| 4372 | DeclContext *MemberContext, |
| 4373 | bool EnteringContext, |
| 4374 | bool isObjCIvarLookup, |
| 4375 | bool FindHidden) { |
| 4376 | Res.suppressDiagnostics(); |
| 4377 | Res.clear(); |
| 4378 | Res.setLookupName(Name); |
| 4379 | Res.setAllowHidden(FindHidden); |
| 4380 | if (MemberContext) { |
| 4381 | if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(MemberContext)) { |
| 4382 | if (isObjCIvarLookup) { |
| 4383 | if (ObjCIvarDecl *Ivar = Class->lookupInstanceVariable(Name)) { |
| 4384 | Res.addDecl(Ivar); |
| 4385 | Res.resolveKind(); |
| 4386 | return; |
| 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | if (ObjCPropertyDecl *Prop = Class->FindPropertyDeclaration( |
| 4391 | Name, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { |
| 4392 | Res.addDecl(Prop); |
| 4393 | Res.resolveKind(); |
| 4394 | return; |
| 4395 | } |
| 4396 | } |
| 4397 | |
| 4398 | SemaRef.LookupQualifiedName(Res, MemberContext); |
| 4399 | return; |
| 4400 | } |
| 4401 | |
| 4402 | SemaRef.LookupParsedName(Res, S, SS, , |
| 4403 | EnteringContext); |
| 4404 | |
| 4405 | |
| 4406 | |
| 4407 | if (ObjCMethodDecl *Method = SemaRef.getCurMethodDecl()) { |
| 4408 | if (Method->isInstanceMethod() && Method->getClassInterface() && |
| 4409 | (Res.empty() || |
| 4410 | (Res.isSingleResult() && |
| 4411 | Res.getFoundDecl()->isDefinedOutsideFunctionOrMethod()))) { |
| 4412 | if (ObjCIvarDecl *IV |
| 4413 | = Method->getClassInterface()->lookupInstanceVariable(Name)) { |
| 4414 | Res.addDecl(IV); |
| 4415 | Res.resolveKind(); |
| 4416 | } |
| 4417 | } |
| 4418 | } |
| 4419 | } |
| 4420 | |
| 4421 | |
| 4422 | static void AddKeywordsToConsumer(Sema &SemaRef, |
| 4423 | TypoCorrectionConsumer &Consumer, |
| 4424 | Scope *S, CorrectionCandidateCallback &CCC, |
| 4425 | bool AfterNestedNameSpecifier) { |
| 4426 | if (AfterNestedNameSpecifier) { |
| 4427 | |
| 4428 | Consumer.addKeywordResult("template"); |
| 4429 | if (CCC.WantExpressionKeywords) |
| 4430 | Consumer.addKeywordResult("operator"); |
| 4431 | return; |
| 4432 | } |
| 4433 | |
| 4434 | if (CCC.WantObjCSuper) |
| 4435 | Consumer.addKeywordResult("super"); |
| 4436 | |
| 4437 | if (CCC.WantTypeSpecifiers) { |
| 4438 | |
| 4439 | static const char *const CTypeSpecs[] = { |
| 4440 | "char", "const", "double", "enum", "float", "int", "long", "short", |
| 4441 | "signed", "struct", "union", "unsigned", "void", "volatile", |
| 4442 | "_Complex", "_Imaginary", |
| 4443 | |
| 4444 | "extern", "inline", "static", "typedef" |
| 4445 | }; |
| 4446 | |
| 4447 | const unsigned NumCTypeSpecs = llvm::array_lengthof(CTypeSpecs); |
| 4448 | for (unsigned I = 0; I != NumCTypeSpecs; ++I) |
| 4449 | Consumer.addKeywordResult(CTypeSpecs[I]); |
| 4450 | |
| 4451 | if (SemaRef.getLangOpts().C99) |
| 4452 | Consumer.addKeywordResult("restrict"); |
| 4453 | if (SemaRef.getLangOpts().Bool || SemaRef.getLangOpts().CPlusPlus) |
| 4454 | Consumer.addKeywordResult("bool"); |
| 4455 | else if (SemaRef.getLangOpts().C99) |
| 4456 | Consumer.addKeywordResult("_Bool"); |
| 4457 | |
| 4458 | if (SemaRef.getLangOpts().CPlusPlus) { |
| 4459 | Consumer.addKeywordResult("class"); |
| 4460 | Consumer.addKeywordResult("typename"); |
| 4461 | Consumer.addKeywordResult("wchar_t"); |
| 4462 | |
| 4463 | if (SemaRef.getLangOpts().CPlusPlus11) { |
| 4464 | Consumer.addKeywordResult("char16_t"); |
| 4465 | Consumer.addKeywordResult("char32_t"); |
| 4466 | Consumer.addKeywordResult("constexpr"); |
| 4467 | Consumer.addKeywordResult("decltype"); |
| 4468 | Consumer.addKeywordResult("thread_local"); |
| 4469 | } |
| 4470 | } |
| 4471 | |
| 4472 | if (SemaRef.getLangOpts().GNUKeywords) |
| 4473 | Consumer.addKeywordResult("typeof"); |
| 4474 | } else if (CCC.WantFunctionLikeCasts) { |
| 4475 | static const char *const CastableTypeSpecs[] = { |
| 4476 | "char", "double", "float", "int", "long", "short", |
| 4477 | "signed", "unsigned", "void" |
| 4478 | }; |
| 4479 | for (auto *kw : CastableTypeSpecs) |
| 4480 | Consumer.addKeywordResult(kw); |
| 4481 | } |
| 4482 | |
| 4483 | if (CCC.WantCXXNamedCasts && SemaRef.getLangOpts().CPlusPlus) { |
| 4484 | Consumer.addKeywordResult("const_cast"); |
| 4485 | Consumer.addKeywordResult("dynamic_cast"); |
| 4486 | Consumer.addKeywordResult("reinterpret_cast"); |
| 4487 | Consumer.addKeywordResult("static_cast"); |
| 4488 | } |
| 4489 | |
| 4490 | if (CCC.WantExpressionKeywords) { |
| 4491 | Consumer.addKeywordResult("sizeof"); |
| 4492 | if (SemaRef.getLangOpts().Bool || SemaRef.getLangOpts().CPlusPlus) { |
| 4493 | Consumer.addKeywordResult("false"); |
| 4494 | Consumer.addKeywordResult("true"); |
| 4495 | } |
| 4496 | |
| 4497 | if (SemaRef.getLangOpts().CPlusPlus) { |
| 4498 | static const char *const CXXExprs[] = { |
| 4499 | "delete", "new", "operator", "throw", "typeid" |
| 4500 | }; |
| 4501 | const unsigned NumCXXExprs = llvm::array_lengthof(CXXExprs); |
| 4502 | for (unsigned I = 0; I != NumCXXExprs; ++I) |
| 4503 | Consumer.addKeywordResult(CXXExprs[I]); |
| 4504 | |
| 4505 | if (isa<CXXMethodDecl>(SemaRef.CurContext) && |
| 4506 | cast<CXXMethodDecl>(SemaRef.CurContext)->isInstance()) |
| 4507 | Consumer.addKeywordResult("this"); |
| 4508 | |
| 4509 | if (SemaRef.getLangOpts().CPlusPlus11) { |
| 4510 | Consumer.addKeywordResult("alignof"); |
| 4511 | Consumer.addKeywordResult("nullptr"); |
| 4512 | } |
| 4513 | } |
| 4514 | |
| 4515 | if (SemaRef.getLangOpts().C11) { |
| 4516 | |
| 4517 | |
| 4518 | Consumer.addKeywordResult("_Alignof"); |
| 4519 | } |
| 4520 | } |
| 4521 | |
| 4522 | if (CCC.WantRemainingKeywords) { |
| 4523 | if (SemaRef.getCurFunctionOrMethodDecl() || SemaRef.getCurBlock()) { |
| 4524 | |
| 4525 | static const char *const CStmts[] = { |
| 4526 | "do", "else", "for", "goto", "if", "return", "switch", "while" }; |
| 4527 | const unsigned NumCStmts = llvm::array_lengthof(CStmts); |
| 4528 | for (unsigned I = 0; I != NumCStmts; ++I) |
| 4529 | Consumer.addKeywordResult(CStmts[I]); |
| 4530 | |
| 4531 | if (SemaRef.getLangOpts().CPlusPlus) { |
| 4532 | Consumer.addKeywordResult("catch"); |
| 4533 | Consumer.addKeywordResult("try"); |
| 4534 | } |
| 4535 | |
| 4536 | if (S && S->getBreakParent()) |
| 4537 | Consumer.addKeywordResult("break"); |
| 4538 | |
| 4539 | if (S && S->getContinueParent()) |
| 4540 | Consumer.addKeywordResult("continue"); |
| 4541 | |
| 4542 | if (SemaRef.getCurFunction() && |
| 4543 | !SemaRef.getCurFunction()->SwitchStack.empty()) { |
| 4544 | Consumer.addKeywordResult("case"); |
| 4545 | Consumer.addKeywordResult("default"); |
| 4546 | } |
| 4547 | } else { |
| 4548 | if (SemaRef.getLangOpts().CPlusPlus) { |
| 4549 | Consumer.addKeywordResult("namespace"); |
| 4550 | Consumer.addKeywordResult("template"); |
| 4551 | } |
| 4552 | |
| 4553 | if (S && S->isClassScope()) { |
| 4554 | Consumer.addKeywordResult("explicit"); |
| 4555 | Consumer.addKeywordResult("friend"); |
| 4556 | Consumer.addKeywordResult("mutable"); |
| 4557 | Consumer.addKeywordResult("private"); |
| 4558 | Consumer.addKeywordResult("protected"); |
| 4559 | Consumer.addKeywordResult("public"); |
| 4560 | Consumer.addKeywordResult("virtual"); |
| 4561 | } |
| 4562 | } |
| 4563 | |
| 4564 | if (SemaRef.getLangOpts().CPlusPlus) { |
| 4565 | Consumer.addKeywordResult("using"); |
| 4566 | |
| 4567 | if (SemaRef.getLangOpts().CPlusPlus11) |
| 4568 | Consumer.addKeywordResult("static_assert"); |
| 4569 | } |
| 4570 | } |
| 4571 | } |
| 4572 | |
| 4573 | std::unique_ptr<TypoCorrectionConsumer> Sema::makeTypoCorrectionConsumer( |
| 4574 | const DeclarationNameInfo &TypoName, Sema::LookupNameKind LookupKind, |
| 4575 | Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, |
| 4576 | DeclContext *MemberContext, bool EnteringContext, |
| 4577 | const ObjCObjectPointerType *OPT, bool ErrorRecovery) { |
| 4578 | |
| 4579 | if (Diags.hasFatalErrorOccurred() || !getLangOpts().SpellChecking || |
| 4580 | DisableTypoCorrection) |
| 4581 | return nullptr; |
| 4582 | |
| 4583 | |
| 4584 | |
| 4585 | |
| 4586 | if (getLangOpts().MSVCCompat && CurContext->isDependentContext() && |
| 4587 | isa<CXXMethodDecl>(CurContext)) |
| 4588 | return nullptr; |
| 4589 | |
| 4590 | |
| 4591 | IdentifierInfo *Typo = TypoName.getName().getAsIdentifierInfo(); |
| 4592 | if (!Typo) |
| 4593 | return nullptr; |
| 4594 | |
| 4595 | |
| 4596 | |
| 4597 | if (SS && SS->isInvalid()) |
| 4598 | return nullptr; |
| 4599 | |
| 4600 | |
| 4601 | if (!CodeSynthesisContexts.empty()) |
| 4602 | return nullptr; |
| 4603 | |
| 4604 | |
| 4605 | if (S && S->isInObjcMethodScope() && Typo == getSuperIdentifier()) |
| 4606 | return nullptr; |
| 4607 | |
| 4608 | |
| 4609 | IdentifierSourceLocations::iterator locs = TypoCorrectionFailures.find(Typo); |
| 4610 | if (locs != TypoCorrectionFailures.end() && |
| 4611 | locs->second.count(TypoName.getLoc())) |
| 4612 | return nullptr; |
| 4613 | |
| 4614 | |
| 4615 | |
| 4616 | |
| 4617 | if ((getLangOpts().AltiVec || getLangOpts().ZVector) && Typo->isStr("vector")) |
| 4618 | return nullptr; |
| 4619 | |
| 4620 | |
| 4621 | |
| 4622 | |
| 4623 | unsigned Limit = getDiagnostics().getDiagnosticOptions().SpellCheckingLimit; |
| 4624 | if (Limit && TyposCorrected >= Limit) |
| 4625 | return nullptr; |
| 4626 | ++TyposCorrected; |
| 4627 | |
| 4628 | |
| 4629 | |
| 4630 | if (ErrorRecovery && getLangOpts().Modules && |
| 4631 | getLangOpts().ModulesSearchAll) { |
| 4632 | |
| 4633 | getModuleLoader().lookupMissingImports(Typo->getName(), |
| 4634 | TypoName.getBeginLoc()); |
| 4635 | } |
| 4636 | |
| 4637 | |
| 4638 | |
| 4639 | |
| 4640 | |
| 4641 | std::unique_ptr<CorrectionCandidateCallback> ClonedCCC = CCC.clone(); |
| 4642 | auto Consumer = llvm::make_unique<TypoCorrectionConsumer>( |
| 4643 | *this, TypoName, LookupKind, S, SS, std::move(ClonedCCC), MemberContext, |
| 4644 | EnteringContext); |
| 4645 | |
| 4646 | |
| 4647 | bool IsUnqualifiedLookup = false; |
| 4648 | DeclContext *QualifiedDC = MemberContext; |
| 4649 | if (MemberContext) { |
| 4650 | LookupVisibleDecls(MemberContext, LookupKind, *Consumer); |
| 4651 | |
| 4652 | |
| 4653 | if (OPT) { |
| 4654 | for (auto *I : OPT->quals()) |
| 4655 | LookupVisibleDecls(I, LookupKind, *Consumer); |
| 4656 | } |
| 4657 | } else if (SS && SS->isSet()) { |
| 4658 | QualifiedDC = computeDeclContext(*SS, EnteringContext); |
| 4659 | if (!QualifiedDC) |
| 4660 | return nullptr; |
| 4661 | |
| 4662 | LookupVisibleDecls(QualifiedDC, LookupKind, *Consumer); |
| 4663 | } else { |
| 4664 | IsUnqualifiedLookup = true; |
| 4665 | } |
| 4666 | |
| 4667 | |
| 4668 | |
| 4669 | bool SearchNamespaces |
| 4670 | = getLangOpts().CPlusPlus && |
| 4671 | (IsUnqualifiedLookup || (SS && SS->isSet())); |
| 4672 | |
| 4673 | if (IsUnqualifiedLookup || SearchNamespaces) { |
| 4674 | |
| 4675 | |
| 4676 | |
| 4677 | for (const auto &I : Context.Idents) |
| 4678 | Consumer->FoundName(I.getKey()); |
| 4679 | |
| 4680 | |
| 4681 | |
| 4682 | if (IdentifierInfoLookup *External |
| 4683 | = Context.Idents.getExternalIdentifierLookup()) { |
| 4684 | std::unique_ptr<IdentifierIterator> Iter(External->getIdentifiers()); |
| 4685 | do { |
| 4686 | StringRef Name = Iter->Next(); |
| 4687 | if (Name.empty()) |
| 4688 | break; |
| 4689 | |
| 4690 | Consumer->FoundName(Name); |
| 4691 | } while (true); |
| 4692 | } |
| 4693 | } |
| 4694 | |
| 4695 | AddKeywordsToConsumer(*this, *Consumer, S, |
| 4696 | *Consumer->getCorrectionValidator(), |
| 4697 | SS && SS->isNotEmpty()); |
| 4698 | |
| 4699 | |
| 4700 | |
| 4701 | if (SearchNamespaces) { |
| 4702 | |
| 4703 | if (ExternalSource && !LoadedExternalKnownNamespaces) { |
| 4704 | SmallVector<NamespaceDecl *, 4> ExternalKnownNamespaces; |
| 4705 | LoadedExternalKnownNamespaces = true; |
| 4706 | ExternalSource->ReadKnownNamespaces(ExternalKnownNamespaces); |
| 4707 | for (auto *N : ExternalKnownNamespaces) |
| 4708 | KnownNamespaces[N] = true; |
| 4709 | } |
| 4710 | |
| 4711 | Consumer->addNamespaces(KnownNamespaces); |
| 4712 | } |
| 4713 | |
| 4714 | return Consumer; |
| 4715 | } |
| 4716 | |
| 4717 | |
| 4718 | |
| 4719 | |
| 4720 | |
| 4721 | |
| 4722 | |
| 4723 | |
| 4724 | |
| 4725 | |
| 4726 | |
| 4727 | |
| 4728 | |
| 4729 | |
| 4730 | |
| 4731 | |
| 4732 | |
| 4733 | |
| 4734 | |
| 4735 | |
| 4736 | |
| 4737 | |
| 4738 | |
| 4739 | |
| 4740 | |
| 4741 | |
| 4742 | |
| 4743 | |
| 4744 | |
| 4745 | |
| 4746 | |
| 4747 | |
| 4748 | TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, |
| 4749 | Sema::LookupNameKind LookupKind, |
| 4750 | Scope *S, CXXScopeSpec *SS, |
| 4751 | CorrectionCandidateCallback &CCC, |
| 4752 | CorrectTypoKind Mode, |
| 4753 | DeclContext *MemberContext, |
| 4754 | bool EnteringContext, |
| 4755 | const ObjCObjectPointerType *OPT, |
| 4756 | bool RecordFailure) { |
| 4757 | |
| 4758 | |
| 4759 | if (ExternalSource) { |
| 4760 | if (TypoCorrection Correction = |
| 4761 | ExternalSource->CorrectTypo(TypoName, LookupKind, S, SS, CCC, |
| 4762 | MemberContext, EnteringContext, OPT)) |
| 4763 | return Correction; |
| 4764 | } |
| 4765 | |
| 4766 | |
| 4767 | |
| 4768 | |
| 4769 | |
| 4770 | bool ObjCMessageReceiver = CCC.WantObjCSuper && !CCC.WantRemainingKeywords; |
| 4771 | |
| 4772 | IdentifierInfo *Typo = TypoName.getName().getAsIdentifierInfo(); |
| 4773 | auto Consumer = makeTypoCorrectionConsumer(TypoName, LookupKind, S, SS, CCC, |
| 4774 | MemberContext, EnteringContext, |
| 4775 | OPT, Mode == CTK_ErrorRecovery); |
| 4776 | |
| 4777 | if (!Consumer) |
| 4778 | return TypoCorrection(); |
| 4779 | |
| 4780 | |
| 4781 | if (Consumer->empty()) |
| 4782 | return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure); |
| 4783 | |
| 4784 | |
| 4785 | |
| 4786 | unsigned ED = Consumer->getBestEditDistance(true); |
| 4787 | unsigned TypoLen = Typo->getName().size(); |
| 4788 | if (ED > 0 && TypoLen / ED < 3) |
| 4789 | return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure); |
| 4790 | |
| 4791 | TypoCorrection BestTC = Consumer->getNextCorrection(); |
| 4792 | TypoCorrection SecondBestTC = Consumer->getNextCorrection(); |
| 4793 | if (!BestTC) |
| 4794 | return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure); |
| 4795 | |
| 4796 | ED = BestTC.getEditDistance(); |
| 4797 | |
| 4798 | if (TypoLen >= 3 && ED > 0 && TypoLen / ED < 3) { |
| 4799 | |
| 4800 | |
| 4801 | |
| 4802 | return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure); |
| 4803 | } |
| 4804 | |
| 4805 | |
| 4806 | if (!SecondBestTC || |
| 4807 | SecondBestTC.getEditDistance(false) > BestTC.getEditDistance(false)) { |
| 4808 | const TypoCorrection &Result = BestTC; |
| 4809 | |
| 4810 | |
| 4811 | |
| 4812 | if (ED == 0 && Result.isKeyword()) |
| 4813 | return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure); |
| 4814 | |
| 4815 | TypoCorrection TC = Result; |
| 4816 | TC.setCorrectionRange(SS, TypoName); |
| 4817 | checkCorrectionVisibility(*this, TC); |
| 4818 | return TC; |
| 4819 | } else if (SecondBestTC && ObjCMessageReceiver) { |
| 4820 | |
| 4821 | |
| 4822 | |
| 4823 | if (BestTC.getCorrection().getAsString() != "super") { |
| 4824 | if (SecondBestTC.getCorrection().getAsString() == "super") |
| 4825 | BestTC = SecondBestTC; |
| 4826 | else if ((*Consumer)["super"].front().isKeyword()) |
| 4827 | BestTC = (*Consumer)["super"].front(); |
| 4828 | } |
| 4829 | |
| 4830 | |
| 4831 | if (BestTC.getEditDistance() == 0 || |
| 4832 | BestTC.getCorrection().getAsString() != "super") |
| 4833 | return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure); |
| 4834 | |
| 4835 | BestTC.setCorrectionRange(SS, TypoName); |
| 4836 | return BestTC; |
| 4837 | } |
| 4838 | |
| 4839 | |
| 4840 | |
| 4841 | |
| 4842 | return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure && !SecondBestTC); |
| 4843 | } |
| 4844 | |
| 4845 | |
| 4846 | |
| 4847 | |
| 4848 | |
| 4849 | |
| 4850 | |
| 4851 | |
| 4852 | |
| 4853 | |
| 4854 | |
| 4855 | |
| 4856 | |
| 4857 | |
| 4858 | |
| 4859 | |
| 4860 | |
| 4861 | |
| 4862 | |
| 4863 | |
| 4864 | |
| 4865 | |
| 4866 | |
| 4867 | |
| 4868 | |
| 4869 | |
| 4870 | |
| 4871 | |
| 4872 | |
| 4873 | |
| 4874 | |
| 4875 | |
| 4876 | |
| 4877 | |
| 4878 | |
| 4879 | |
| 4880 | |
| 4881 | |
| 4882 | |
| 4883 | TypoExpr *Sema::CorrectTypoDelayed( |
| 4884 | const DeclarationNameInfo &TypoName, Sema::LookupNameKind LookupKind, |
| 4885 | Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, |
| 4886 | TypoDiagnosticGenerator TDG, TypoRecoveryCallback TRC, CorrectTypoKind Mode, |
| 4887 | DeclContext *MemberContext, bool EnteringContext, |
| 4888 | const ObjCObjectPointerType *OPT) { |
| 4889 | auto Consumer = makeTypoCorrectionConsumer(TypoName, LookupKind, S, SS, CCC, |
| 4890 | MemberContext, EnteringContext, |
| 4891 | OPT, Mode == CTK_ErrorRecovery); |
| 4892 | |
| 4893 | |
| 4894 | TypoCorrection ExternalTypo; |
| 4895 | if (ExternalSource && Consumer) { |
| 4896 | ExternalTypo = ExternalSource->CorrectTypo( |
| 4897 | TypoName, LookupKind, S, SS, *Consumer->getCorrectionValidator(), |
| 4898 | MemberContext, EnteringContext, OPT); |
| 4899 | if (ExternalTypo) |
| 4900 | Consumer->addCorrection(ExternalTypo); |
| 4901 | } |
| 4902 | |
| 4903 | if (!Consumer || Consumer->empty()) |
| 4904 | return nullptr; |
| 4905 | |
| 4906 | |
| 4907 | |
| 4908 | unsigned ED = Consumer->getBestEditDistance(true); |
| 4909 | IdentifierInfo *Typo = TypoName.getName().getAsIdentifierInfo(); |
| 4910 | if (!ExternalTypo && ED > 0 && Typo->getName().size() / ED < 3) |
| 4911 | return nullptr; |
| 4912 | |
| 4913 | ExprEvalContexts.back().NumTypos++; |
| 4914 | return createDelayedTypo(std::move(Consumer), std::move(TDG), std::move(TRC)); |
| 4915 | } |
| 4916 | |
| 4917 | void TypoCorrection::addCorrectionDecl(NamedDecl *CDecl) { |
| 4918 | if (!CDecl) return; |
| 4919 | |
| 4920 | if (isKeyword()) |
| 4921 | CorrectionDecls.clear(); |
| 4922 | |
| 4923 | CorrectionDecls.push_back(CDecl); |
| 4924 | |
| 4925 | if (!CorrectionName) |
| 4926 | CorrectionName = CDecl->getDeclName(); |
| 4927 | } |
| 4928 | |
| 4929 | std::string TypoCorrection::getAsString(const LangOptions &LO) const { |
| 4930 | if (CorrectionNameSpec) { |
| 4931 | std::string tmpBuffer; |
| 4932 | llvm::raw_string_ostream PrefixOStream(tmpBuffer); |
| 4933 | CorrectionNameSpec->print(PrefixOStream, PrintingPolicy(LO)); |
| 4934 | PrefixOStream << CorrectionName; |
| 4935 | return PrefixOStream.str(); |
| 4936 | } |
| 4937 | |
| 4938 | return CorrectionName.getAsString(); |
| 4939 | } |
| 4940 | |
| 4941 | bool CorrectionCandidateCallback::ValidateCandidate( |
| 4942 | const TypoCorrection &candidate) { |
| 4943 | if (!candidate.isResolved()) |
| 4944 | return true; |
| 4945 | |
| 4946 | if (candidate.isKeyword()) |
| 4947 | return WantTypeSpecifiers || WantExpressionKeywords || WantCXXNamedCasts || |
| 4948 | WantRemainingKeywords || WantObjCSuper; |
| 4949 | |
| 4950 | bool HasNonType = false; |
| 4951 | bool HasStaticMethod = false; |
| 4952 | bool HasNonStaticMethod = false; |
| 4953 | for (Decl *D : candidate) { |
| 4954 | if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 4955 | D = FTD->getTemplatedDecl(); |
| 4956 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { |
| 4957 | if (Method->isStatic()) |
| 4958 | HasStaticMethod = true; |
| 4959 | else |
| 4960 | HasNonStaticMethod = true; |
| 4961 | } |
| 4962 | if (!isa<TypeDecl>(D)) |
| 4963 | HasNonType = true; |
| 4964 | } |
| 4965 | |
| 4966 | if (IsAddressOfOperand && HasNonStaticMethod && !HasStaticMethod && |
| 4967 | !candidate.getCorrectionSpecifier()) |
| 4968 | return false; |
| 4969 | |
| 4970 | return WantTypeSpecifiers || HasNonType; |
| 4971 | } |
| 4972 | |
| 4973 | FunctionCallFilterCCC::FunctionCallFilterCCC(Sema &SemaRef, unsigned NumArgs, |
| 4974 | bool HasExplicitTemplateArgs, |
| 4975 | MemberExpr *ME) |
| 4976 | : NumArgs(NumArgs), HasExplicitTemplateArgs(HasExplicitTemplateArgs), |
| 4977 | CurContext(SemaRef.CurContext), MemberFn(ME) { |
| 4978 | WantTypeSpecifiers = false; |
| 4979 | WantFunctionLikeCasts = SemaRef.getLangOpts().CPlusPlus && NumArgs == 1; |
| 4980 | WantRemainingKeywords = false; |
| 4981 | } |
| 4982 | |
| 4983 | bool FunctionCallFilterCCC::ValidateCandidate(const TypoCorrection &candidate) { |
| 4984 | if (!candidate.getCorrectionDecl()) |
| 4985 | return candidate.isKeyword(); |
| 4986 | |
| 4987 | for (auto *C : candidate) { |
| 4988 | FunctionDecl *FD = nullptr; |
| 4989 | NamedDecl *ND = C->getUnderlyingDecl(); |
| 4990 | if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(ND)) |
| 4991 | FD = FTD->getTemplatedDecl(); |
| 4992 | if (!HasExplicitTemplateArgs && !FD) { |
| 4993 | if (!(FD = dyn_cast<FunctionDecl>(ND)) && isa<ValueDecl>(ND)) { |
| 4994 | |
| 4995 | |
| 4996 | |
| 4997 | QualType ValType = cast<ValueDecl>(ND)->getType(); |
| 4998 | if (ValType.isNull()) |
| 4999 | continue; |
| 5000 | if (ValType->isAnyPointerType() || ValType->isReferenceType()) |
| 5001 | ValType = ValType->getPointeeType(); |
| 5002 | if (const FunctionProtoType *FPT = ValType->getAs<FunctionProtoType>()) |
| 5003 | if (FPT->getNumParams() == NumArgs) |
| 5004 | return true; |
| 5005 | } |
| 5006 | } |
| 5007 | |
| 5008 | |
| 5009 | |
| 5010 | if (!FD || !(FD->getNumParams() >= NumArgs && |
| 5011 | FD->getMinRequiredArguments() <= NumArgs)) |
| 5012 | continue; |
| 5013 | |
| 5014 | |
| 5015 | |
| 5016 | |
| 5017 | |
| 5018 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { |
| 5019 | if (MemberFn || !MD->isStatic()) { |
| 5020 | CXXMethodDecl *CurMD = |
| 5021 | MemberFn |
| 5022 | ? dyn_cast_or_null<CXXMethodDecl>(MemberFn->getMemberDecl()) |
| 5023 | : dyn_cast_or_null<CXXMethodDecl>(CurContext); |
| 5024 | CXXRecordDecl *CurRD = |
| 5025 | CurMD ? CurMD->getParent()->getCanonicalDecl() : nullptr; |
| 5026 | CXXRecordDecl *RD = MD->getParent()->getCanonicalDecl(); |
| 5027 | if (!CurRD || (CurRD != RD && !CurRD->isDerivedFrom(RD))) |
| 5028 | continue; |
| 5029 | } |
| 5030 | } |
| 5031 | return true; |
| 5032 | } |
| 5033 | return false; |
| 5034 | } |
| 5035 | |
| 5036 | void Sema::diagnoseTypo(const TypoCorrection &Correction, |
| 5037 | const PartialDiagnostic &TypoDiag, |
| 5038 | bool ErrorRecovery) { |
| 5039 | diagnoseTypo(Correction, TypoDiag, PDiag(diag::note_previous_decl), |
| 5040 | ErrorRecovery); |
| 5041 | } |
| 5042 | |
| 5043 | |
| 5044 | |
| 5045 | static NamedDecl *getDefinitionToImport(NamedDecl *D) { |
| 5046 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) |
| 5047 | return VD->getDefinition(); |
| 5048 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 5049 | return FD->getDefinition(); |
| 5050 | if (TagDecl *TD = dyn_cast<TagDecl>(D)) |
| 5051 | return TD->getDefinition(); |
| 5052 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) |
| 5053 | return ID->getDefinition(); |
| 5054 | if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) |
| 5055 | return PD->getDefinition(); |
| 5056 | if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D)) |
| 5057 | return getDefinitionToImport(TD->getTemplatedDecl()); |
| 5058 | return nullptr; |
| 5059 | } |
| 5060 | |
| 5061 | void Sema::diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, |
| 5062 | MissingImportKind MIK, bool Recover) { |
| 5063 | |
| 5064 | |
| 5065 | NamedDecl *Def = getDefinitionToImport(Decl); |
| 5066 | if (!Def) |
| 5067 | Def = Decl; |
| 5068 | |
| 5069 | Module *Owner = getOwningModule(Def); |
| 5070 | (0) . __assert_fail ("Owner && \"definition of hidden declaration is not in a module\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 5070, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Owner && "definition of hidden declaration is not in a module"); |
| 5071 | |
| 5072 | llvm::SmallVector<Module*, 8> OwningModules; |
| 5073 | OwningModules.push_back(Owner); |
| 5074 | auto Merged = Context.getModulesWithMergedDefinition(Def); |
| 5075 | OwningModules.insert(OwningModules.end(), Merged.begin(), Merged.end()); |
| 5076 | |
| 5077 | diagnoseMissingImport(Loc, Decl, Decl->getLocation(), OwningModules, MIK, |
| 5078 | Recover); |
| 5079 | } |
| 5080 | |
| 5081 | |
| 5082 | |
| 5083 | static std::string (Preprocessor &PP, |
| 5084 | const FileEntry *E) { |
| 5085 | bool IsSystem; |
| 5086 | auto Path = |
| 5087 | PP.getHeaderSearchInfo().suggestPathToFileForDiagnostics(E, &IsSystem); |
| 5088 | return (IsSystem ? '<' : '"') + Path + (IsSystem ? '>' : '"'); |
| 5089 | } |
| 5090 | |
| 5091 | void Sema::diagnoseMissingImport(SourceLocation UseLoc, NamedDecl *Decl, |
| 5092 | SourceLocation DeclLoc, |
| 5093 | ArrayRef<Module *> Modules, |
| 5094 | MissingImportKind MIK, bool Recover) { |
| 5095 | assert(!Modules.empty()); |
| 5096 | |
| 5097 | |
| 5098 | llvm::SmallVector<Module*, 8> UniqueModules; |
| 5099 | llvm::SmallDenseSet<Module*, 8> UniqueModuleSet; |
| 5100 | for (auto *M : Modules) |
| 5101 | if (UniqueModuleSet.insert(M).second) |
| 5102 | UniqueModules.push_back(M); |
| 5103 | Modules = UniqueModules; |
| 5104 | |
| 5105 | if (Modules.size() > 1) { |
| 5106 | std::string ModuleList; |
| 5107 | unsigned N = 0; |
| 5108 | for (Module *M : Modules) { |
| 5109 | ModuleList += "\n "; |
| 5110 | if (++N == 5 && N != Modules.size()) { |
| 5111 | ModuleList += "[...]"; |
| 5112 | break; |
| 5113 | } |
| 5114 | ModuleList += M->getFullModuleName(); |
| 5115 | } |
| 5116 | |
| 5117 | Diag(UseLoc, diag::err_module_unimported_use_multiple) |
| 5118 | << (int)MIK << Decl << ModuleList; |
| 5119 | } else if (const FileEntry *E = PP.getModuleHeaderToIncludeForDiagnostics( |
| 5120 | UseLoc, Modules[0], DeclLoc)) { |
| 5121 | |
| 5122 | |
| 5123 | |
| 5124 | |
| 5125 | |
| 5126 | Diag(UseLoc, diag::err_module_unimported_use_header) |
| 5127 | << (int)MIK << Decl << Modules[0]->getFullModuleName() |
| 5128 | << getIncludeStringForHeader(PP, E); |
| 5129 | } else { |
| 5130 | |
| 5131 | Diag(UseLoc, diag::err_module_unimported_use) |
| 5132 | << (int)MIK << Decl << Modules[0]->getFullModuleName(); |
| 5133 | } |
| 5134 | |
| 5135 | unsigned DiagID; |
| 5136 | switch (MIK) { |
| 5137 | case MissingImportKind::Declaration: |
| 5138 | DiagID = diag::note_previous_declaration; |
| 5139 | break; |
| 5140 | case MissingImportKind::Definition: |
| 5141 | DiagID = diag::note_previous_definition; |
| 5142 | break; |
| 5143 | case MissingImportKind::DefaultArgument: |
| 5144 | DiagID = diag::note_default_argument_declared_here; |
| 5145 | break; |
| 5146 | case MissingImportKind::ExplicitSpecialization: |
| 5147 | DiagID = diag::note_explicit_specialization_declared_here; |
| 5148 | break; |
| 5149 | case MissingImportKind::PartialSpecialization: |
| 5150 | DiagID = diag::note_partial_specialization_declared_here; |
| 5151 | break; |
| 5152 | } |
| 5153 | Diag(DeclLoc, DiagID); |
| 5154 | |
| 5155 | |
| 5156 | if (Recover) |
| 5157 | createImplicitModuleImportForErrorRecovery(UseLoc, Modules[0]); |
| 5158 | } |
| 5159 | |
| 5160 | |
| 5161 | |
| 5162 | |
| 5163 | |
| 5164 | |
| 5165 | |
| 5166 | |
| 5167 | |
| 5168 | |
| 5169 | |
| 5170 | |
| 5171 | |
| 5172 | void Sema::diagnoseTypo(const TypoCorrection &Correction, |
| 5173 | const PartialDiagnostic &TypoDiag, |
| 5174 | const PartialDiagnostic &PrevNote, |
| 5175 | bool ErrorRecovery) { |
| 5176 | std::string CorrectedStr = Correction.getAsString(getLangOpts()); |
| 5177 | std::string CorrectedQuotedStr = Correction.getQuoted(getLangOpts()); |
| 5178 | FixItHint FixTypo = FixItHint::CreateReplacement( |
| 5179 | Correction.getCorrectionRange(), CorrectedStr); |
| 5180 | |
| 5181 | |
| 5182 | if (Correction.requiresImport()) { |
| 5183 | NamedDecl *Decl = Correction.getFoundDecl(); |
| 5184 | (0) . __assert_fail ("Decl && \"import required but no declaration to import\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 5184, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Decl && "import required but no declaration to import"); |
| 5185 | |
| 5186 | diagnoseMissingImport(Correction.getCorrectionRange().getBegin(), Decl, |
| 5187 | MissingImportKind::Declaration, ErrorRecovery); |
| 5188 | return; |
| 5189 | } |
| 5190 | |
| 5191 | Diag(Correction.getCorrectionRange().getBegin(), TypoDiag) |
| 5192 | << CorrectedQuotedStr << (ErrorRecovery ? FixTypo : FixItHint()); |
| 5193 | |
| 5194 | NamedDecl *ChosenDecl = |
| 5195 | Correction.isKeyword() ? nullptr : Correction.getFoundDecl(); |
| 5196 | if (PrevNote.getDiagID() && ChosenDecl) |
| 5197 | Diag(ChosenDecl->getLocation(), PrevNote) |
| 5198 | << CorrectedQuotedStr << (ErrorRecovery ? FixItHint() : FixTypo); |
| 5199 | |
| 5200 | |
| 5201 | for (const PartialDiagnostic &PD : Correction.getExtraDiagnostics()) |
| 5202 | Diag(Correction.getCorrectionRange().getBegin(), PD); |
| 5203 | } |
| 5204 | |
| 5205 | TypoExpr *Sema::createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC, |
| 5206 | TypoDiagnosticGenerator TDG, |
| 5207 | TypoRecoveryCallback TRC) { |
| 5208 | (0) . __assert_fail ("TCC && \"createDelayedTypo requires a valid TypoCorrectionConsumer\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 5208, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(TCC && "createDelayedTypo requires a valid TypoCorrectionConsumer"); |
| 5209 | auto TE = new (Context) TypoExpr(Context.DependentTy); |
| 5210 | auto &State = DelayedTypos[TE]; |
| 5211 | State.Consumer = std::move(TCC); |
| 5212 | State.DiagHandler = std::move(TDG); |
| 5213 | State.RecoveryHandler = std::move(TRC); |
| 5214 | return TE; |
| 5215 | } |
| 5216 | |
| 5217 | const Sema::TypoExprState &Sema::getTypoExprState(TypoExpr *TE) const { |
| 5218 | auto Entry = DelayedTypos.find(TE); |
| 5219 | (0) . __assert_fail ("Entry != DelayedTypos.end() && \"Failed to get the state for a TypoExpr!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 5220, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Entry != DelayedTypos.end() && |
| 5220 | (0) . __assert_fail ("Entry != DelayedTypos.end() && \"Failed to get the state for a TypoExpr!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaLookup.cpp", 5220, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Failed to get the state for a TypoExpr!"); |
| 5221 | return Entry->second; |
| 5222 | } |
| 5223 | |
| 5224 | void Sema::clearDelayedTypo(TypoExpr *TE) { |
| 5225 | DelayedTypos.erase(TE); |
| 5226 | } |
| 5227 | |
| 5228 | void Sema::ActOnPragmaDump(Scope *S, SourceLocation IILoc, IdentifierInfo *II) { |
| 5229 | DeclarationNameInfo Name(II, IILoc); |
| 5230 | LookupResult R(*this, Name, LookupAnyName, Sema::NotForRedeclaration); |
| 5231 | R.suppressDiagnostics(); |
| 5232 | R.setHideTags(false); |
| 5233 | LookupName(R, S); |
| 5234 | R.dump(); |
| 5235 | } |
| 5236 | |