@@ -729,71 +729,49 @@ class ASTContext : public RefCountedBase<ASTContext> {
729
729
// / True if comments are already loaded from ExternalASTSource.
730
730
mutable bool CommentsLoaded = false ;
731
731
732
- class RawCommentAndCacheFlags {
733
- public:
734
- enum Kind {
735
- // / We searched for a comment attached to the particular declaration, but
736
- // / didn't find any.
737
- // /
738
- // / getRaw() == 0.
739
- NoCommentInDecl = 0 ,
740
-
741
- // / We have found a comment attached to this particular declaration.
742
- // /
743
- // / getRaw() != 0.
744
- FromDecl,
745
-
746
- // / This declaration does not have an attached comment, and we have
747
- // / searched the redeclaration chain.
748
- // /
749
- // / If getRaw() == 0, the whole redeclaration chain does not have any
750
- // / comments.
751
- // /
752
- // / If getRaw() != 0, it is a comment propagated from other
753
- // / redeclaration.
754
- FromRedecl
755
- };
756
-
757
- Kind getKind () const LLVM_READONLY {
758
- return Data.getInt ();
759
- }
760
-
761
- void setKind (Kind K) {
762
- Data.setInt (K);
763
- }
764
-
765
- const RawComment *getRaw () const LLVM_READONLY {
766
- return Data.getPointer ();
767
- }
768
-
769
- void setRaw (const RawComment *RC) {
770
- Data.setPointer (RC);
771
- }
772
-
773
- const Decl *getOriginalDecl () const LLVM_READONLY {
774
- return OriginalDecl;
775
- }
776
-
777
- void setOriginalDecl (const Decl *Orig) {
778
- OriginalDecl = Orig;
779
- }
780
-
781
- private:
782
- llvm::PointerIntPair<const RawComment *, 2 , Kind> Data;
783
- const Decl *OriginalDecl;
784
- };
732
+ // / Mapping from declaration to directly attached comment.
733
+ // /
734
+ // / Raw comments are owned by Comments list. This mapping is populated
735
+ // / lazily.
736
+ mutable llvm::DenseMap<const Decl *, const RawComment *> DeclRawComments;
785
737
786
- // / Mapping from declarations to comments attached to any
787
- // / redeclaration .
738
+ // / Mapping from canonical declaration to the first redeclaration in chain
739
+ // / that has a comment attached .
788
740
// /
789
741
// / Raw comments are owned by Comments list. This mapping is populated
790
742
// / lazily.
791
- mutable llvm::DenseMap<const Decl *, RawCommentAndCacheFlags> RedeclComments;
743
+ mutable llvm::DenseMap<const Decl *, const Decl *> RedeclChainComments;
744
+
745
+ // / Keeps track of redeclaration chains that don't have any comment attached.
746
+ // / Mapping from canonical declaration to redeclaration chain that has no
747
+ // / comments attached to any redeclaration. Specifically it's mapping to
748
+ // / the last redeclaration we've checked.
749
+ // /
750
+ // / Shall not contain declarations that have comments attached to any
751
+ // / redeclaration in their chain.
752
+ mutable llvm::DenseMap<const Decl *, const Decl *> CommentlessRedeclChains;
792
753
793
754
// / Mapping from declarations to parsed comments attached to any
794
755
// / redeclaration.
795
756
mutable llvm::DenseMap<const Decl *, comments::FullComment *> ParsedComments;
796
757
758
+ // / Attaches \p Comment to \p OriginalD and to its redeclaration chain
759
+ // / and removes the redeclaration chain from the set of commentless chains.
760
+ // /
761
+ // / Don't do anything if a comment has already been attached to \p OriginalD
762
+ // / or its redeclaration chain.
763
+ void cacheRawCommentForDecl (const Decl &OriginalD,
764
+ const RawComment &Comment) const ;
765
+
766
+ // / \returns searches \p CommentsInFile for doc comment for \p D.
767
+ // /
768
+ // / \p RepresentativeLocForDecl is used as a location for searching doc
769
+ // / comments. \p CommentsInFile is a mapping offset -> comment of files in the
770
+ // / same file where \p RepresentativeLocForDecl is.
771
+ RawComment *getRawCommentForDeclNoCacheImpl (
772
+ const Decl *D, const SourceLocation RepresentativeLocForDecl,
773
+ const std::map<unsigned , RawComment *> &CommentsInFile) const ;
774
+
797
775
// / Return the documentation comment attached to a given declaration,
798
776
// / without looking into cache.
799
777
RawComment *getRawCommentForDeclNoCache (const Decl *D) const ;
@@ -818,6 +796,16 @@ class ASTContext : public RefCountedBase<ASTContext> {
818
796
getRawCommentForAnyRedecl (const Decl *D,
819
797
const Decl **OriginalDecl = nullptr ) const ;
820
798
799
+ // / Searches existing comments for doc comments that should be attached to \p
800
+ // / Decls. If any doc comment is found, it is parsed.
801
+ // /
802
+ // / Requirement: All \p Decls are in the same file.
803
+ // /
804
+ // / If the last comment in the file is already attached we assume
805
+ // / there are not comments left to be attached to \p Decls.
806
+ void attachCommentsToJustParsedDecls (ArrayRef<Decl *> Decls,
807
+ const Preprocessor *PP);
808
+
821
809
// / Return parsed documentation comment attached to a given declaration.
822
810
// / Returns nullptr if no comment is attached.
823
811
// /
0 commit comments