diff options
-rw-r--r-- | include/clang/AST/ASTContext.h | 14 | ||||
-rw-r--r-- | include/clang/AST/ExternalASTSource.h | 8 | ||||
-rw-r--r-- | include/clang/Frontend/PCHBitCodes.h | 4 | ||||
-rw-r--r-- | include/clang/Frontend/PCHReader.h | 14 | ||||
-rw-r--r-- | include/clang/Frontend/PCHWriter.h | 1 | ||||
-rw-r--r-- | include/clang/Parse/Action.h | 4 | ||||
-rw-r--r-- | include/clang/Parse/Parser.h | 1 | ||||
-rw-r--r-- | lib/AST/ASTContext.cpp | 198 | ||||
-rw-r--r-- | lib/Frontend/PCHReader.cpp | 15 | ||||
-rw-r--r-- | lib/Frontend/PCHWriter.cpp | 20 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 18 | ||||
-rw-r--r-- | lib/Sema/Sema.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 2 |
13 files changed, 4 insertions, 300 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 78b808c144..e77dcf86cc 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -259,19 +259,11 @@ class ASTContext { /// this ASTContext object. LangOptions LangOpts; - /// \brief Whether we have already loaded comment source ranges from an - /// external source. - bool LoadedExternalComments; - /// MallocAlloc/BumpAlloc - The allocator objects used to create AST objects. bool FreeMemory; llvm::MallocAllocator MallocAlloc; llvm::BumpPtrAllocator BumpAlloc; - /// \brief Mapping from declarations to their comments, once we have - /// already looked up the comment associated with a given declaration. - llvm::DenseMap<const Decl *, std::string> DeclComments; - public: const TargetInfo &Target; IdentifierTable &Idents; @@ -287,10 +279,6 @@ public: QualType ObjCClassRedefinitionType; QualType ObjCSelRedefinitionType; - /// \brief Source ranges for all of the comments in the source file, - /// sorted in order of appearance in the translation unit. - std::vector<SourceRange> Comments; - SourceManager& getSourceManager() { return SourceMgr; } const SourceManager& getSourceManager() const { return SourceMgr; } void *Allocate(unsigned Size, unsigned Align = 8) { @@ -357,8 +345,6 @@ public: TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; } - const char *getCommentForDecl(const Decl *D); - // Builtin Types. CanQualType VoidTy; CanQualType BoolTy; diff --git a/include/clang/AST/ExternalASTSource.h b/include/clang/AST/ExternalASTSource.h index 0670d1a620..b8d80bc897 100644 --- a/include/clang/AST/ExternalASTSource.h +++ b/include/clang/AST/ExternalASTSource.h @@ -58,14 +58,6 @@ public: virtual ~ExternalASTSource(); - /// \brief Reads the source ranges that correspond to comments from - /// an external AST source. - /// - /// \param Comments the contents of this vector will be - /// replaced with the sorted set of source ranges corresponding to - /// comments in the source code. - virtual void ReadComments(std::vector<SourceRange> &Comments) = 0; - /// \brief Resolve a type ID into a type, potentially building a new /// type. virtual QualType GetType(uint32_t ID) = 0; diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h index de7888e797..f975c497be 100644 --- a/include/clang/Frontend/PCHBitCodes.h +++ b/include/clang/Frontend/PCHBitCodes.h @@ -215,9 +215,7 @@ namespace clang { /// generate the precompiled header. ORIGINAL_FILE_NAME = 19, - /// \brief Record code for the sorted array of source ranges where - /// comments were encountered in the source code. - COMMENT_RANGES = 20, + /// Record #20 intentionally left blank. /// \brief Record code for the version control branch and revision /// information of the compiler used to build this PCH file. diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h index 9ccd382dba..73c1bf4cce 100644 --- a/include/clang/Frontend/PCHReader.h +++ b/include/clang/Frontend/PCHReader.h @@ -310,12 +310,6 @@ private: /// preprocessing record. unsigned NumPreallocatedPreprocessingEntities; - /// \brief A sorted array of source ranges containing comments. - SourceRange *Comments; - - /// \brief The number of source ranges in the Comments array. - unsigned NumComments; - /// \brief The set of external definitions stored in the the PCH /// file. llvm::SmallVector<uint64_t, 16> ExternalDefinitions; @@ -566,14 +560,6 @@ public: /// \brief Read preprocessed entities into the virtual void ReadPreprocessedEntities(); - /// \brief Reads the source ranges that correspond to comments from - /// an external AST source. - /// - /// \param Comments the contents of this vector will be - /// replaced with the sorted set of source ranges corresponding to - /// comments in the source code. - virtual void ReadComments(std::vector<SourceRange> &Comments); - /// \brief Reads a TemplateArgumentLocInfo appropriate for the /// given TemplateArgument kind. TemplateArgumentLocInfo diff --git a/include/clang/Frontend/PCHWriter.h b/include/clang/Frontend/PCHWriter.h index df733b6cae..e006de524c 100644 --- a/include/clang/Frontend/PCHWriter.h +++ b/include/clang/Frontend/PCHWriter.h @@ -215,7 +215,6 @@ private: const Preprocessor &PP, const char* isysroot); void WritePreprocessor(const Preprocessor &PP); - void WriteComments(ASTContext &Context); void WriteType(QualType T); uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC); uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC); diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 2954b946b4..b79e698d50 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -153,10 +153,6 @@ public: /// an empty string if not. This is used for pretty crash reporting. virtual std::string getDeclName(DeclPtrTy D) { return ""; } - /// \brief Invoked for each comment in the source code, providing the source - /// range that contains the comment. - virtual void ActOnComment(SourceRange Comment) { } - //===--------------------------------------------------------------------===// // Declaration Tracking Callbacks. //===--------------------------------------------------------------------===// diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index f034aa10ce..411162b182 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -90,7 +90,6 @@ class Parser { llvm::OwningPtr<PragmaHandler> PackHandler; llvm::OwningPtr<PragmaHandler> UnusedHandler; llvm::OwningPtr<PragmaHandler> WeakHandler; - llvm::OwningPtr<clang::CommentHandler> CommentHandler; /// Whether the '>' token acts as an operator or not. This will be /// true except when we are parsing an expression within a C++ diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 2cf8ce7aa5..7f5c9b1ec1 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -43,8 +43,7 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM, GlobalNestedNameSpecifier(0), CFConstantStringTypeDecl(0), ObjCFastEnumerationStateTypeDecl(0), FILEDecl(0), jmp_bufDecl(0), sigjmp_bufDecl(0), BlockDescriptorType(0), BlockDescriptorExtendedType(0), - SourceMgr(SM), LangOpts(LOpts), - LoadedExternalComments(false), FreeMemory(FreeMem), Target(t), + SourceMgr(SM), LangOpts(LOpts), FreeMemory(FreeMem), Target(t), Idents(idents), Selectors(sels), BuiltinInfo(builtins), ExternalSource(0), PrintingPolicy(LOpts) { ObjCIdRedefinitionType = QualType(); @@ -413,201 +412,6 @@ namespace { }; } -/// \brief Determine whether the given comment is a Doxygen-style comment. -/// -/// \param Start the start of the comment text. -/// -/// \param End the end of the comment text. -/// -/// \param Member whether we want to check whether this is a member comment -/// (which requires a < after the Doxygen-comment delimiter). Otherwise, -/// we only return true when we find a non-member comment. -static bool -isDoxygenComment(SourceManager &SourceMgr, SourceRange Comment, - bool Member = false) { - bool Invalid = false; - const char *BufferStart - = SourceMgr.getBufferData(SourceMgr.getFileID(Comment.getBegin()), - &Invalid).data(); - if (Invalid) - return false; - - const char *Start = BufferStart + SourceMgr.getFileOffset(Comment.getBegin()); - const char* End = BufferStart + SourceMgr.getFileOffset(Comment.getEnd()); - - if (End - Start < 4) - return false; - - assert(Start[0] == '/' && "Not a comment?"); - if (Start[1] == '*' && !(Start[2] == '!' || Start[2] == '*')) - return false; - if (Start[1] == '/' && !(Start[2] == '!' || Start[2] == '/')) - return false; - - return (Start[3] == '<') == Member; -} - -/// \brief Retrieve the comment associated with the given declaration, if -/// it has one. -const char *ASTContext::getCommentForDecl(const Decl *D) { - if (!D) - return 0; - - // Check whether we have cached a comment string for this declaration - // already. - llvm::DenseMap<const Decl *, std::string>::iterator Pos - = DeclComments.find(D); - if (Pos != DeclComments.end()) - return Pos->second.c_str(); - - // If we have an external AST source and have not yet loaded comments from - // that source, do so now. - if (ExternalSource && !LoadedExternalComments) { - std::vector<SourceRange> LoadedComments; - ExternalSource->ReadComments(LoadedComments); - - if (!LoadedComments.empty()) - Comments.insert(Comments.begin(), LoadedComments.begin(), - LoadedComments.end()); - - LoadedExternalComments = true; - } - - // If there are no comments anywhere, we won't find anything. - if (Comments.empty()) - return 0; - - // If the declaration doesn't map directly to a location in a file, we - // can't find the comment. - SourceLocation DeclStartLoc = D->getLocStart(); - if (DeclStartLoc.isInvalid() || !DeclStartLoc.isFileID()) - return 0; - - // Find the comment that occurs just before this declaration. - std::vector<SourceRange>::iterator LastComment - = std::lower_bound(Comments.begin(), Comments.end(), - SourceRange(DeclStartLoc), - BeforeInTranslationUnit(&SourceMgr)); - - // Decompose the location for the start of the declaration and find the - // beginning of the file buffer. - std::pair<FileID, unsigned> DeclStartDecomp - = SourceMgr.getDecomposedLoc(DeclStartLoc); - bool Invalid = false; - const char *FileBufferStart - = SourceMgr.getBufferData(DeclStartDecomp.first, &Invalid).data(); - if (Invalid) - return 0; - - // First check whether we have a comment for a member. - if (LastComment != Comments.end() && - !isa<TagDecl>(D) && !isa<NamespaceDecl>(D) && - isDoxygenComment(SourceMgr, *LastComment, true)) { - std::pair<FileID, unsigned> LastCommentEndDecomp - = SourceMgr.getDecomposedLoc(LastComment->getEnd()); - if (DeclStartDecomp.first == LastCommentEndDecomp.first && - SourceMgr.getLineNumber(DeclStartDecomp.first, DeclStartDecomp.second) - == SourceMgr.getLineNumber(LastCommentEndDecomp.first, - LastCommentEndDecomp.second)) { - // The Doxygen member comment comes after the declaration starts and - // is on the same line and in the same file as the declaration. This - // is the comment we want. - std::string &Result = DeclComments[D]; - Result.append(FileBufferStart + - SourceMgr.getFileOffset(LastComment->getBegin()), - FileBufferStart + LastCommentEndDecomp.second + 1); - return Result.c_str(); - } - } - - if (LastComment == Comments.begin()) - return 0; - --LastComment; - - // Decompose the end of the comment. - std::pair<FileID, unsigned> LastCommentEndDecomp - = SourceMgr.getDecomposedLoc(LastComment->getEnd()); - - // If the comment and the declaration aren't in the same file, then they - // aren't related. - if (DeclStartDecomp.first != LastCommentEndDecomp.first) - return 0; - - // Check that we actually have a Doxygen comment. - if (!isDoxygenComment(SourceMgr, *LastComment)) - return 0; - - // Compute the starting line for the declaration and for the end of the - // comment (this is expensive). - unsigned DeclStartLine - = SourceMgr.getLineNumber(DeclStartDecomp.first, DeclStartDecomp.second); - unsigned CommentEndLine - = SourceMgr.getLineNumber(LastCommentEndDecomp.first, - LastCommentEndDecomp.second); - - // If the comment does not end on the line prior to the declaration, then - // the comment is not associated with the declaration at all. - if (CommentEndLine + 1 != DeclStartLine) - return 0; - - // We have a comment, but there may be more comments on the previous lines. - // Keep looking so long as the comments are still Doxygen comments and are - // still adjacent. - unsigned ExpectedLine - = SourceMgr.getSpellingLineNumber(LastComment->getBegin()) - 1; - std::vector<SourceRange>::iterator FirstComment = LastComment; - while (FirstComment != Comments.begin()) { - // Look at the previous comment - --FirstComment; - std::pair<FileID, unsigned> Decomp - = SourceMgr.getDecomposedLoc(FirstComment->getEnd()); - - // If this previous comment is in a different file, we're done. - if (Decomp.first != DeclStartDecomp.first) { - ++FirstComment; - break; - } - - // If this comment is not a Doxygen comment, we're done. - if (!isDoxygenComment(SourceMgr, *FirstComment)) { - ++FirstComment; - break; - } - - // If the line number is not what we expected, we're done. - unsigned Line = SourceMgr.getLineNumber(Decomp.first, Decomp.second); - if (Line != ExpectedLine) { - ++FirstComment; - break; - } - - // Set the next expected line number. - ExpectedLine - = SourceMgr.getSpellingLineNumber(FirstComment->getBegin()) - 1; - } - - // The iterator range [FirstComment, LastComment] contains all of the - // BCPL comments that, together, are associated with this declaration. - // Form a single comment block string for this declaration that concatenates - // all of these comments. - std::string &Result = DeclComments[D]; - while (FirstComment != LastComment) { - std::pair<FileID, unsigned> DecompStart - = SourceMgr.getDecomposedLoc(FirstComment->getBegin()); - std::pair<FileID, unsigned> DecompEnd - = SourceMgr.getDecomposedLoc(FirstComment->getEnd()); - Result.append(FileBufferStart + DecompStart.second, - FileBufferStart + DecompEnd.second + 1); - ++FirstComment; - } - - // Append the last comment line. - Result.append(FileBufferStart + - SourceMgr.getFileOffset(LastComment->getBegin()), - FileBufferStart + LastCommentEndDecomp.second + 1); - return Result.c_str(); -} - //===----------------------------------------------------------------------===// // Type Sizing and Analysis //===----------------------------------------------------------------------===// diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 7d8fee94f0..e659ff047d 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -328,7 +328,7 @@ PCHReader::PCHReader(Preprocessor &PP, ASTContext *Context, MethodPoolLookupTable(0), MethodPoolLookupTableData(0), TotalSelectorsInMethodPool(0), SelectorOffsets(0), TotalNumSelectors(0), MacroDefinitionOffsets(0), - NumPreallocatedPreprocessingEntities(0), Comments(0), NumComments(0), + NumPreallocatedPreprocessingEntities(0), isysroot(isysroot), NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), NumStatementsRead(0), NumMacrosRead(0), NumMethodPoolSelectorsRead(0), NumMethodPoolMisses(0), @@ -346,7 +346,7 @@ PCHReader::PCHReader(SourceManager &SourceMgr, FileManager &FileMgr, MethodPoolLookupTable(0), MethodPoolLookupTableData(0), TotalSelectorsInMethodPool(0), SelectorOffsets(0), TotalNumSelectors(0), MacroDefinitionOffsets(0), - NumPreallocatedPreprocessingEntities(0), Comments(0), NumComments(0), + NumPreallocatedPreprocessingEntities(0), isysroot(isysroot), NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), NumStatementsRead(0), NumMacrosRead(0), NumMethodPoolSelectorsRead(0), NumMethodPoolMisses(0), @@ -1503,11 +1503,6 @@ PCHReader::ReadPCHBlock() { MaybeAddSystemRootToFilename(OriginalFileName); break; - case pch::COMMENT_RANGES: - Comments = (SourceRange *)BlobStart; - NumComments = BlobLen / sizeof(SourceRange); - break; - case pch::VERSION_CONTROL_BRANCH_REVISION: { const std::string &CurBranch = getClangFullRepositoryVersion(); llvm::StringRef PCHBranch(BlobStart, BlobLen); @@ -1938,12 +1933,6 @@ void PCHReader::ReadPreprocessedEntities() { ReadDefinedMacros(); } -void PCHReader::ReadComments(std::vector<SourceRange> &Comments) { - Comments.resize(NumComments); - std::copy(this->Comments, this->Comments + NumComments, - Comments.begin()); -} - /// \brief Read and return the type at the given offset. /// /// This routine actually reads the record corresponding to the type diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index df41ca1e59..4752cd3ea6 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -564,7 +564,6 @@ void PCHWriter::WriteBlockInfoBlock() { RECORD(SOURCE_LOCATION_PRELOADS); RECORD(STAT_CACHE); RECORD(EXT_VECTOR_DECLS); - RECORD(COMMENT_RANGES); RECORD(VERSION_CONTROL_BRANCH_REVISION); RECORD(UNUSED_STATIC_FUNCS); RECORD(MACRO_DEFINITION_OFFSETS); @@ -1306,24 +1305,6 @@ void PCHWriter::WritePreprocessor(const Preprocessor &PP) { } } -void PCHWriter::WriteComments(ASTContext &Context) { - using namespace llvm; - - if (Context.Comments.empty()) - return; - - BitCodeAbbrev *CommentAbbrev = new BitCodeAbbrev(); - CommentAbbrev->Add(BitCodeAbbrevOp(pch::COMMENT_RANGES)); - CommentAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); - unsigned CommentCode = Stream.EmitAbbrev(CommentAbbrev); - - RecordData Record; - Record.push_back(pch::COMMENT_RANGES); - Stream.EmitRecordWithBlob(CommentCode, Record, - (const char*)&Context.Comments[0], - Context.Comments.size() * sizeof(SourceRange)); -} - //===----------------------------------------------------------------------===// // Type Serialization //===----------------------------------------------------------------------===// @@ -2088,7 +2069,6 @@ void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls, if (StatCalls && !isysroot) WriteStatCache(*StatCalls, isysroot); WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); - WriteComments(Context); // Write the record of special types. Record.clear(); diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index e7a771edda..d45aaed70e 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -21,20 +21,6 @@ #include "ParsePragma.h" using namespace clang; -/// \brief A comment handler that passes comments found by the preprocessor -/// to the parser action. -class ActionCommentHandler : public CommentHandler { - Action &Actions; - -public: - explicit ActionCommentHandler(Action &Actions) : Actions(Actions) { } - - virtual bool HandleComment(Preprocessor &PP, SourceRange Comment) { - Actions.ActOnComment(Comment); - return false; - } -}; - Parser::Parser(Preprocessor &pp, Action &actions) : CrashInfo(*this), PP(pp), Actions(actions), Diags(PP.getDiagnostics()), GreaterThanIsOperator(true), ColonIsSacred(false), @@ -59,9 +45,6 @@ Parser::Parser(Preprocessor &pp, Action &actions) WeakHandler.reset(new PragmaWeakHandler(&PP.getIdentifierTable().get("weak"), actions)); PP.AddPragmaHandler(0, WeakHandler.get()); - - CommentHandler.reset(new ActionCommentHandler(actions)); - PP.AddCommentHandler(CommentHandler.get()); } /// If a crash happens while the parser is active, print out a line indicating @@ -317,7 +300,6 @@ Parser::~Parser() { UnusedHandler.reset(); PP.RemovePragmaHandler(0, WeakHandler.get()); WeakHandler.reset(); - PP.RemoveCommentHandler(CommentHandler.get()); } /// Initialize - Warm up the parser. diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 3b4afef70b..7112687605 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -399,8 +399,3 @@ BlockScopeInfo *Sema::getCurBlock() { return dyn_cast<BlockScopeInfo>(FunctionScopes.back()); } - -void Sema::ActOnComment(SourceRange Comment) { - Context.Comments.push_back(Comment); -} - diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 747fd88978..aca4fdcb61 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -686,8 +686,6 @@ public: /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls llvm::SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; } - virtual void ActOnComment(SourceRange Comment); - //===--------------------------------------------------------------------===// // Type Analysis / Processing: SemaType.cpp. // |