diff options
Diffstat (limited to 'include/clang/Sema/SemaInternal.h')
-rw-r--r-- | include/clang/Sema/SemaInternal.h | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/include/clang/Sema/SemaInternal.h b/include/clang/Sema/SemaInternal.h index 4dc215ba21cb..86ab703a5b3a 100644 --- a/include/clang/Sema/SemaInternal.h +++ b/include/clang/Sema/SemaInternal.h @@ -101,6 +101,27 @@ inline InheritableAttr *getDLLAttr(Decl *D) { return nullptr; } +/// Retrieve the depth and index of a template parameter. +inline std::pair<unsigned, unsigned> getDepthAndIndex(NamedDecl *ND) { + if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(ND)) + return std::make_pair(TTP->getDepth(), TTP->getIndex()); + + if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(ND)) + return std::make_pair(NTTP->getDepth(), NTTP->getIndex()); + + const auto *TTP = cast<TemplateTemplateParmDecl>(ND); + return std::make_pair(TTP->getDepth(), TTP->getIndex()); +} + +/// Retrieve the depth and index of an unexpanded parameter pack. +inline std::pair<unsigned, unsigned> +getDepthAndIndex(UnexpandedParameterPack UPP) { + if (const auto *TTP = UPP.first.dyn_cast<const TemplateTypeParmType *>()) + return std::make_pair(TTP->getDepth(), TTP->getIndex()); + + return getDepthAndIndex(UPP.first.get<NamedDecl *>()); +} + class TypoCorrectionConsumer : public VisibleDeclConsumer { typedef SmallVector<TypoCorrection, 1> TypoResultList; typedef llvm::StringMap<TypoResultList> TypoResultsMap; @@ -139,13 +160,13 @@ public: return CorrectionResults.empty() && ValidatedCorrections.size() == 1; } - /// \brief Return the list of TypoCorrections for the given identifier from + /// Return the list of TypoCorrections for the given identifier from /// the set of corrections that have the closest edit distance, if any. TypoResultList &operator[](StringRef Name) { return CorrectionResults.begin()->second[Name]; } - /// \brief Return the edit distance of the corrections that have the + /// Return the edit distance of the corrections that have the /// closest/best edit distance from the original typop. unsigned getBestEditDistance(bool Normalized) { if (CorrectionResults.empty()) @@ -155,28 +176,28 @@ public: return Normalized ? TypoCorrection::NormalizeEditDistance(BestED) : BestED; } - /// \brief Set-up method to add to the consumer the set of namespaces to use + /// Set-up method to add to the consumer the set of namespaces to use /// in performing corrections to nested name specifiers. This method also /// implicitly adds all of the known classes in the current AST context to the /// to the consumer for correcting nested name specifiers. void addNamespaces(const llvm::MapVector<NamespaceDecl *, bool> &KnownNamespaces); - /// \brief Return the next typo correction that passes all internal filters + /// Return the next typo correction that passes all internal filters /// and is deemed valid by the consumer's CorrectionCandidateCallback, /// starting with the corrections that have the closest edit distance. An /// empty TypoCorrection is returned once no more viable corrections remain /// in the consumer. const TypoCorrection &getNextCorrection(); - /// \brief Get the last correction returned by getNextCorrection(). + /// Get the last correction returned by getNextCorrection(). const TypoCorrection &getCurrentCorrection() { return CurrentTCIndex < ValidatedCorrections.size() ? ValidatedCorrections[CurrentTCIndex] : ValidatedCorrections[0]; // The empty correction. } - /// \brief Return the next typo correction like getNextCorrection, but keep + /// Return the next typo correction like getNextCorrection, but keep /// the internal state pointed to the current correction (i.e. the next time /// getNextCorrection is called, it will return the same correction returned /// by peekNextcorrection). @@ -187,27 +208,27 @@ public: return TC; } - /// \brief Reset the consumer's position in the stream of viable corrections + /// Reset the consumer's position in the stream of viable corrections /// (i.e. getNextCorrection() will return each of the previously returned /// corrections in order before returning any new corrections). void resetCorrectionStream() { CurrentTCIndex = 0; } - /// \brief Return whether the end of the stream of corrections has been + /// Return whether the end of the stream of corrections has been /// reached. bool finished() { return CorrectionResults.empty() && CurrentTCIndex >= ValidatedCorrections.size(); } - /// \brief Save the current position in the correction stream (overwriting any + /// Save the current position in the correction stream (overwriting any /// previously saved position). void saveCurrentPosition() { SavedTCIndex = CurrentTCIndex; } - /// \brief Restore the saved position in the correction stream. + /// Restore the saved position in the correction stream. void restoreSavedPosition() { CurrentTCIndex = SavedTCIndex; } @@ -241,7 +262,7 @@ private: std::map<unsigned, SpecifierInfoList> DistanceMap; - /// \brief Helper for building the list of DeclContexts between the current + /// Helper for building the list of DeclContexts between the current /// context and the top of the translation unit static DeclContextList buildContextChain(DeclContext *Start); @@ -252,11 +273,11 @@ private: NamespaceSpecifierSet(ASTContext &Context, DeclContext *CurContext, CXXScopeSpec *CurScopeSpec); - /// \brief Add the DeclContext (a namespace or record) to the set, computing + /// Add the DeclContext (a namespace or record) to the set, computing /// the corresponding NestedNameSpecifier and its distance in the process. void addNameSpecifier(DeclContext *Ctx); - /// \brief Provides flat iteration over specifiers, sorted by distance. + /// Provides flat iteration over specifiers, sorted by distance. class iterator : public llvm::iterator_facade_base<iterator, std::forward_iterator_tag, SpecifierInfo> { @@ -295,21 +316,21 @@ private: void addName(StringRef Name, NamedDecl *ND, NestedNameSpecifier *NNS = nullptr, bool isKeyword = false); - /// \brief Find any visible decls for the given typo correction candidate. + /// Find any visible decls for the given typo correction candidate. /// If none are found, it to the set of candidates for which qualified lookups /// will be performed to find possible nested name specifier changes. bool resolveCorrection(TypoCorrection &Candidate); - /// \brief Perform qualified lookups on the queued set of typo correction + /// Perform qualified lookups on the queued set of typo correction /// candidates and add the nested name specifier changes to each candidate if /// a lookup succeeds (at which point the candidate will be returned to the /// main pool of potential corrections). void performQualifiedLookups(); - /// \brief The name written that is a typo in the source. + /// The name written that is a typo in the source. IdentifierInfo *Typo; - /// \brief The results found that have the smallest edit distance + /// The results found that have the smallest edit distance /// found (so far) with the typo name. /// /// The pointer value being set to the current DeclContext indicates |