1 //===--- Preprocess.cpp - C Language Family Preprocessor Implementation ---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Preprocessor interface.
12 //===----------------------------------------------------------------------===//
14 // Options to support:
15 // -H - Print the name of each header file used.
16 // -d[DNI] - Dump various things.
17 // -fworking-directory - #line's with preprocessor's working dir.
19 // -dependency-file,-M,-MM,-MF,-MG,-MP,-MT,-MQ,-MD,-MMD
24 // "Multiple include guards may be useful for:\n"
26 //===----------------------------------------------------------------------===//
28 #include "clang/Lex/Preprocessor.h"
29 #include "MacroArgs.h"
30 #include "clang/Lex/ExternalPreprocessorSource.h"
31 #include "clang/Lex/HeaderSearch.h"
32 #include "clang/Lex/MacroInfo.h"
33 #include "clang/Lex/Pragma.h"
34 #include "clang/Lex/PreprocessingRecord.h"
35 #include "clang/Lex/ScratchBuffer.h"
36 #include "clang/Lex/LexDiagnostic.h"
37 #include "clang/Lex/CodeCompletionHandler.h"
38 #include "clang/Lex/ModuleLoader.h"
39 #include "clang/Basic/SourceManager.h"
40 #include "clang/Basic/FileManager.h"
41 #include "clang/Basic/TargetInfo.h"
42 #include "llvm/ADT/APFloat.h"
43 #include "llvm/ADT/SmallString.h"
44 #include "llvm/Support/MemoryBuffer.h"
45 #include "llvm/Support/raw_ostream.h"
46 #include "llvm/Support/Capacity.h"
47 using namespace clang;
49 //===----------------------------------------------------------------------===//
50 ExternalPreprocessorSource::~ExternalPreprocessorSource() { }
52 Preprocessor::Preprocessor(DiagnosticsEngine &diags, LangOptions &opts,
53 const TargetInfo *target, SourceManager &SM,
54 HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
55 IdentifierInfoLookup* IILookup,
57 bool DelayInitialization,
59 : Diags(&diags), LangOpts(opts), Target(target),FileMgr(Headers.getFileMgr()),
60 SourceMgr(SM), HeaderInfo(Headers), TheModuleLoader(TheModuleLoader),
61 ExternalSource(0), Identifiers(opts, IILookup),
62 IncrementalProcessing(IncrProcessing), CodeComplete(0),
63 CodeCompletionFile(0), CodeCompletionOffset(0), CodeCompletionReached(0),
64 SkipMainFilePreamble(0, true), CurPPLexer(0),
65 CurDirLookup(0), CurLexerKind(CLK_Lexer), Callbacks(0), MacroArgCache(0),
66 Record(0), MIChainHead(0), MICache(0)
68 OwnsHeaderSearch = OwnsHeaders;
70 if (!DelayInitialization) {
71 assert(Target && "Must provide target information for PP initialization");
76 Preprocessor::~Preprocessor() {
77 assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!");
79 while (!IncludeMacroStack.empty()) {
80 delete IncludeMacroStack.back().TheLexer;
81 delete IncludeMacroStack.back().TheTokenLexer;
82 IncludeMacroStack.pop_back();
85 // Free any macro definitions.
86 for (MacroInfoChain *I = MIChainHead ; I ; I = I->Next)
89 // Free any cached macro expanders.
90 for (unsigned i = 0, e = NumCachedTokenLexers; i != e; ++i)
91 delete TokenLexerCache[i];
93 // Free any cached MacroArgs.
94 for (MacroArgs *ArgList = MacroArgCache; ArgList; )
95 ArgList = ArgList->deallocate();
97 // Release pragma information.
98 delete PragmaHandlers;
100 // Delete the scratch buffer info.
103 // Delete the header search info, if we own it.
104 if (OwnsHeaderSearch)
110 void Preprocessor::Initialize(const TargetInfo &Target) {
111 assert((!this->Target || this->Target == &Target) &&
112 "Invalid override of target information");
113 this->Target = &Target;
115 // Initialize information about built-ins.
116 BuiltinInfo.InitializeTarget(Target);
118 ScratchBuf = new ScratchBuffer(SourceMgr);
119 CounterValue = 0; // __COUNTER__ starts at 0.
122 NumDirectives = NumDefined = NumUndefined = NumPragma = 0;
123 NumIf = NumElse = NumEndif = 0;
124 NumEnteredSourceFiles = 0;
125 NumMacroExpanded = NumFnMacroExpanded = NumBuiltinMacroExpanded = 0;
126 NumFastMacroExpanded = NumTokenPaste = NumFastTokenPaste = 0;
127 MaxIncludeStackDepth = 0;
130 // Default to discarding comments.
131 KeepComments = false;
132 KeepMacroComments = false;
133 SuppressIncludeNotFoundError = false;
135 // Macro expansion is enabled.
136 DisableMacroExpansion = false;
138 InMacroArgPreExpansion = false;
139 NumCachedTokenLexers = 0;
143 // We haven't read anything from the external source.
144 ReadMacrosFromExternalSource = false;
146 // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro.
147 // This gets unpoisoned where it is allowed.
148 (Ident__VA_ARGS__ = getIdentifierInfo("__VA_ARGS__"))->setIsPoisoned();
149 SetPoisonReason(Ident__VA_ARGS__,diag::ext_pp_bad_vaargs_use);
151 // Initialize the pragma handlers.
152 PragmaHandlers = new PragmaNamespace(StringRef());
153 RegisterBuiltinPragmas();
155 // Initialize builtin macros like __LINE__ and friends.
156 RegisterBuiltinMacros();
158 if(LangOpts.Borland) {
159 Ident__exception_info = getIdentifierInfo("_exception_info");
160 Ident___exception_info = getIdentifierInfo("__exception_info");
161 Ident_GetExceptionInfo = getIdentifierInfo("GetExceptionInformation");
162 Ident__exception_code = getIdentifierInfo("_exception_code");
163 Ident___exception_code = getIdentifierInfo("__exception_code");
164 Ident_GetExceptionCode = getIdentifierInfo("GetExceptionCode");
165 Ident__abnormal_termination = getIdentifierInfo("_abnormal_termination");
166 Ident___abnormal_termination = getIdentifierInfo("__abnormal_termination");
167 Ident_AbnormalTermination = getIdentifierInfo("AbnormalTermination");
169 Ident__exception_info = Ident__exception_code = Ident__abnormal_termination = 0;
170 Ident___exception_info = Ident___exception_code = Ident___abnormal_termination = 0;
171 Ident_GetExceptionInfo = Ident_GetExceptionCode = Ident_AbnormalTermination = 0;
174 HeaderInfo.setTarget(Target);
177 void Preprocessor::setPTHManager(PTHManager* pm) {
179 FileMgr.addStatCache(PTH->createStatCache());
182 void Preprocessor::DumpToken(const Token &Tok, bool DumpFlags) const {
183 llvm::errs() << tok::getTokenName(Tok.getKind()) << " '"
184 << getSpelling(Tok) << "'";
186 if (!DumpFlags) return;
188 llvm::errs() << "\t";
189 if (Tok.isAtStartOfLine())
190 llvm::errs() << " [StartOfLine]";
191 if (Tok.hasLeadingSpace())
192 llvm::errs() << " [LeadingSpace]";
193 if (Tok.isExpandDisabled())
194 llvm::errs() << " [ExpandDisabled]";
195 if (Tok.needsCleaning()) {
196 const char *Start = SourceMgr.getCharacterData(Tok.getLocation());
197 llvm::errs() << " [UnClean='" << StringRef(Start, Tok.getLength())
201 llvm::errs() << "\tLoc=<";
202 DumpLocation(Tok.getLocation());
206 void Preprocessor::DumpLocation(SourceLocation Loc) const {
210 void Preprocessor::DumpMacro(const MacroInfo &MI) const {
211 llvm::errs() << "MACRO: ";
212 for (unsigned i = 0, e = MI.getNumTokens(); i != e; ++i) {
213 DumpToken(MI.getReplacementToken(i));
216 llvm::errs() << "\n";
219 void Preprocessor::PrintStats() {
220 llvm::errs() << "\n*** Preprocessor Stats:\n";
221 llvm::errs() << NumDirectives << " directives found:\n";
222 llvm::errs() << " " << NumDefined << " #define.\n";
223 llvm::errs() << " " << NumUndefined << " #undef.\n";
224 llvm::errs() << " #include/#include_next/#import:\n";
225 llvm::errs() << " " << NumEnteredSourceFiles << " source files entered.\n";
226 llvm::errs() << " " << MaxIncludeStackDepth << " max include stack depth\n";
227 llvm::errs() << " " << NumIf << " #if/#ifndef/#ifdef.\n";
228 llvm::errs() << " " << NumElse << " #else/#elif.\n";
229 llvm::errs() << " " << NumEndif << " #endif.\n";
230 llvm::errs() << " " << NumPragma << " #pragma.\n";
231 llvm::errs() << NumSkipped << " #if/#ifndef#ifdef regions skipped\n";
233 llvm::errs() << NumMacroExpanded << "/" << NumFnMacroExpanded << "/"
234 << NumBuiltinMacroExpanded << " obj/fn/builtin macros expanded, "
235 << NumFastMacroExpanded << " on the fast path.\n";
236 llvm::errs() << (NumFastTokenPaste+NumTokenPaste)
237 << " token paste (##) operations performed, "
238 << NumFastTokenPaste << " on the fast path.\n";
241 Preprocessor::macro_iterator
242 Preprocessor::macro_begin(bool IncludeExternalMacros) const {
243 if (IncludeExternalMacros && ExternalSource &&
244 !ReadMacrosFromExternalSource) {
245 ReadMacrosFromExternalSource = true;
246 ExternalSource->ReadDefinedMacros();
249 return Macros.begin();
252 size_t Preprocessor::getTotalMemory() const {
253 return BP.getTotalMemory()
254 + llvm::capacity_in_bytes(MacroExpandedTokens)
255 + Predefines.capacity() /* Predefines buffer. */
256 + llvm::capacity_in_bytes(Macros)
257 + llvm::capacity_in_bytes(PragmaPushMacroInfo)
258 + llvm::capacity_in_bytes(PoisonReasons)
259 + llvm::capacity_in_bytes(CommentHandlers);
262 Preprocessor::macro_iterator
263 Preprocessor::macro_end(bool IncludeExternalMacros) const {
264 if (IncludeExternalMacros && ExternalSource &&
265 !ReadMacrosFromExternalSource) {
266 ReadMacrosFromExternalSource = true;
267 ExternalSource->ReadDefinedMacros();
273 void Preprocessor::recomputeCurLexerKind() {
275 CurLexerKind = CLK_Lexer;
276 else if (CurPTHLexer)
277 CurLexerKind = CLK_PTHLexer;
278 else if (CurTokenLexer)
279 CurLexerKind = CLK_TokenLexer;
281 CurLexerKind = CLK_CachingLexer;
284 bool Preprocessor::SetCodeCompletionPoint(const FileEntry *File,
285 unsigned CompleteLine,
286 unsigned CompleteColumn) {
288 assert(CompleteLine && CompleteColumn && "Starts from 1:1");
289 assert(!CodeCompletionFile && "Already set");
291 using llvm::MemoryBuffer;
293 // Load the actual file's contents.
294 bool Invalid = false;
295 const MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File, &Invalid);
299 // Find the byte position of the truncation point.
300 const char *Position = Buffer->getBufferStart();
301 for (unsigned Line = 1; Line < CompleteLine; ++Line) {
302 for (; *Position; ++Position) {
303 if (*Position != '\r' && *Position != '\n')
306 // Eat \r\n or \n\r as a single line.
307 if ((Position[1] == '\r' || Position[1] == '\n') &&
308 Position[0] != Position[1])
315 Position += CompleteColumn - 1;
317 // Insert '\0' at the code-completion point.
318 if (Position < Buffer->getBufferEnd()) {
319 CodeCompletionFile = File;
320 CodeCompletionOffset = Position - Buffer->getBufferStart();
322 MemoryBuffer *NewBuffer =
323 MemoryBuffer::getNewUninitMemBuffer(Buffer->getBufferSize() + 1,
324 Buffer->getBufferIdentifier());
325 char *NewBuf = const_cast<char*>(NewBuffer->getBufferStart());
326 char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf);
328 std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
329 SourceMgr.overrideFileContents(File, NewBuffer);
335 void Preprocessor::CodeCompleteNaturalLanguage() {
337 CodeComplete->CodeCompleteNaturalLanguage();
338 setCodeCompletionReached();
341 /// getSpelling - This method is used to get the spelling of a token into a
342 /// SmallVector. Note that the returned StringRef may not point to the
343 /// supplied buffer if a copy can be avoided.
344 StringRef Preprocessor::getSpelling(const Token &Tok,
345 SmallVectorImpl<char> &Buffer,
346 bool *Invalid) const {
347 // NOTE: this has to be checked *before* testing for an IdentifierInfo.
348 if (Tok.isNot(tok::raw_identifier)) {
349 // Try the fast path.
350 if (const IdentifierInfo *II = Tok.getIdentifierInfo())
351 return II->getName();
354 // Resize the buffer if we need to copy into it.
355 if (Tok.needsCleaning())
356 Buffer.resize(Tok.getLength());
358 const char *Ptr = Buffer.data();
359 unsigned Len = getSpelling(Tok, Ptr, Invalid);
360 return StringRef(Ptr, Len);
363 /// CreateString - Plop the specified string into a scratch buffer and return a
364 /// location for it. If specified, the source location provides a source
365 /// location for the token.
366 void Preprocessor::CreateString(const char *Buf, unsigned Len, Token &Tok,
367 SourceLocation ExpansionLocStart,
368 SourceLocation ExpansionLocEnd) {
372 SourceLocation Loc = ScratchBuf->getToken(Buf, Len, DestPtr);
374 if (ExpansionLocStart.isValid())
375 Loc = SourceMgr.createExpansionLoc(Loc, ExpansionLocStart,
376 ExpansionLocEnd, Len);
377 Tok.setLocation(Loc);
379 // If this is a raw identifier or a literal token, set the pointer data.
380 if (Tok.is(tok::raw_identifier))
381 Tok.setRawIdentifierData(DestPtr);
382 else if (Tok.isLiteral())
383 Tok.setLiteralData(DestPtr);
386 Module *Preprocessor::getCurrentModule() {
387 if (getLangOpts().CurrentModule.empty())
390 return getHeaderSearchInfo().lookupModule(getLangOpts().CurrentModule);
393 //===----------------------------------------------------------------------===//
394 // Preprocessor Initialization Methods
395 //===----------------------------------------------------------------------===//
398 /// EnterMainSourceFile - Enter the specified FileID as the main source file,
399 /// which implicitly adds the builtin defines etc.
400 void Preprocessor::EnterMainSourceFile() {
401 // We do not allow the preprocessor to reenter the main file. Doing so will
402 // cause FileID's to accumulate information from both runs (e.g. #line
403 // information) and predefined macros aren't guaranteed to be set properly.
404 assert(NumEnteredSourceFiles == 0 && "Cannot reenter the main file!");
405 FileID MainFileID = SourceMgr.getMainFileID();
407 // If MainFileID is loaded it means we loaded an AST file, no need to enter
409 if (!SourceMgr.isLoadedFileID(MainFileID)) {
410 // Enter the main file source buffer.
411 EnterSourceFile(MainFileID, 0, SourceLocation());
413 // If we've been asked to skip bytes in the main file (e.g., as part of a
414 // precompiled preamble), do so now.
415 if (SkipMainFilePreamble.first > 0)
416 CurLexer->SkipBytes(SkipMainFilePreamble.first,
417 SkipMainFilePreamble.second);
419 // Tell the header info that the main file was entered. If the file is later
420 // #imported, it won't be re-entered.
421 if (const FileEntry *FE = SourceMgr.getFileEntryForID(MainFileID))
422 HeaderInfo.IncrementIncludeCount(FE);
425 // Preprocess Predefines to populate the initial preprocessor state.
426 llvm::MemoryBuffer *SB =
427 llvm::MemoryBuffer::getMemBufferCopy(Predefines, "<built-in>");
428 assert(SB && "Cannot create predefined source buffer");
429 FileID FID = SourceMgr.createFileIDForMemBuffer(SB);
430 assert(!FID.isInvalid() && "Could not create FileID for predefines?");
432 // Start parsing the predefines.
433 EnterSourceFile(FID, 0, SourceLocation());
436 void Preprocessor::EndSourceFile() {
437 // Notify the client that we reached the end of the source file.
439 Callbacks->EndOfMainFile();
442 //===----------------------------------------------------------------------===//
443 // Lexer Event Handling.
444 //===----------------------------------------------------------------------===//
446 /// LookUpIdentifierInfo - Given a tok::raw_identifier token, look up the
447 /// identifier information for the token and install it into the token,
448 /// updating the token kind accordingly.
449 IdentifierInfo *Preprocessor::LookUpIdentifierInfo(Token &Identifier) const {
450 assert(Identifier.getRawIdentifierData() != 0 && "No raw identifier data!");
452 // Look up this token, see if it is a macro, or if it is a language keyword.
454 if (!Identifier.needsCleaning()) {
455 // No cleaning needed, just use the characters from the lexed buffer.
456 II = getIdentifierInfo(StringRef(Identifier.getRawIdentifierData(),
457 Identifier.getLength()));
459 // Cleaning needed, alloca a buffer, clean into it, then use the buffer.
460 SmallString<64> IdentifierBuffer;
461 StringRef CleanedStr = getSpelling(Identifier, IdentifierBuffer);
462 II = getIdentifierInfo(CleanedStr);
465 // Update the token info (identifier info and appropriate token kind).
466 Identifier.setIdentifierInfo(II);
467 Identifier.setKind(II->getTokenID());
472 void Preprocessor::SetPoisonReason(IdentifierInfo *II, unsigned DiagID) {
473 PoisonReasons[II] = DiagID;
476 void Preprocessor::PoisonSEHIdentifiers(bool Poison) {
477 assert(Ident__exception_code && Ident__exception_info);
478 assert(Ident___exception_code && Ident___exception_info);
479 Ident__exception_code->setIsPoisoned(Poison);
480 Ident___exception_code->setIsPoisoned(Poison);
481 Ident_GetExceptionCode->setIsPoisoned(Poison);
482 Ident__exception_info->setIsPoisoned(Poison);
483 Ident___exception_info->setIsPoisoned(Poison);
484 Ident_GetExceptionInfo->setIsPoisoned(Poison);
485 Ident__abnormal_termination->setIsPoisoned(Poison);
486 Ident___abnormal_termination->setIsPoisoned(Poison);
487 Ident_AbnormalTermination->setIsPoisoned(Poison);
490 void Preprocessor::HandlePoisonedIdentifier(Token & Identifier) {
491 assert(Identifier.getIdentifierInfo() &&
492 "Can't handle identifiers without identifier info!");
493 llvm::DenseMap<IdentifierInfo*,unsigned>::const_iterator it =
494 PoisonReasons.find(Identifier.getIdentifierInfo());
495 if(it == PoisonReasons.end())
496 Diag(Identifier, diag::err_pp_used_poisoned_id);
498 Diag(Identifier,it->second) << Identifier.getIdentifierInfo();
501 /// HandleIdentifier - This callback is invoked when the lexer reads an
502 /// identifier. This callback looks up the identifier in the map and/or
503 /// potentially macro expands it or turns it into a named token (like 'for').
505 /// Note that callers of this method are guarded by checking the
506 /// IdentifierInfo's 'isHandleIdentifierCase' bit. If this method changes, the
507 /// IdentifierInfo methods that compute these properties will need to change to
509 void Preprocessor::HandleIdentifier(Token &Identifier) {
510 assert(Identifier.getIdentifierInfo() &&
511 "Can't handle identifiers without identifier info!");
513 IdentifierInfo &II = *Identifier.getIdentifierInfo();
515 // If the information about this identifier is out of date, update it from
516 // the external source.
517 if (II.isOutOfDate()) {
518 ExternalSource->updateOutOfDateIdentifier(II);
519 Identifier.setKind(II.getTokenID());
522 // If this identifier was poisoned, and if it was not produced from a macro
523 // expansion, emit an error.
524 if (II.isPoisoned() && CurPPLexer) {
525 HandlePoisonedIdentifier(Identifier);
528 // If this is a macro to be expanded, do it.
529 if (MacroInfo *MI = getMacroInfo(&II)) {
530 if (!DisableMacroExpansion) {
531 if (Identifier.isExpandDisabled()) {
532 Diag(Identifier, diag::pp_disabled_macro_expansion);
533 } else if (MI->isEnabled()) {
534 if (!HandleMacroExpandedIdentifier(Identifier, MI))
537 // C99 6.10.3.4p2 says that a disabled macro may never again be
538 // expanded, even if it's in a context where it could be expanded in the
540 Identifier.setFlag(Token::DisableExpand);
541 Diag(Identifier, diag::pp_disabled_macro_expansion);
546 // If this identifier is a keyword in C++11, produce a warning. Don't warn if
547 // we're not considering macro expansion, since this identifier might be the
549 // FIXME: This warning is disabled in cases where it shouldn't be, like
550 // "#define constexpr constexpr", "int constexpr;"
551 if (II.isCXX11CompatKeyword() & !DisableMacroExpansion) {
552 Diag(Identifier, diag::warn_cxx11_keyword) << II.getName();
553 // Don't diagnose this keyword again in this translation unit.
554 II.setIsCXX11CompatKeyword(false);
557 // C++ 2.11p2: If this is an alternative representation of a C++ operator,
558 // then we act as if it is the actual operator and not the textual
559 // representation of it.
560 if (II.isCPlusPlusOperatorKeyword())
561 Identifier.setIdentifierInfo(0);
563 // If this is an extension token, diagnose its use.
564 // We avoid diagnosing tokens that originate from macro definitions.
565 // FIXME: This warning is disabled in cases where it shouldn't be,
566 // like "#define TY typeof", "TY(1) x".
567 if (II.isExtensionToken() && !DisableMacroExpansion)
568 Diag(Identifier, diag::ext_token_used);
570 // If this is the '__experimental_modules_import' contextual keyword, note
571 // that the next token indicates a module name.
573 // Note that we do not treat '__experimental_modules_import' as a contextual
574 // keyword when we're in a caching lexer, because caching lexers only get
575 // used in contexts where import declarations are disallowed.
576 if (II.isModulesImport() && !InMacroArgs && !DisableMacroExpansion &&
577 getLangOpts().Modules && CurLexerKind != CLK_CachingLexer) {
578 ModuleImportLoc = Identifier.getLocation();
579 ModuleImportPath.clear();
580 ModuleImportExpectsIdentifier = true;
581 CurLexerKind = CLK_LexAfterModuleImport;
585 /// \brief Lex a token following the 'import' contextual keyword.
587 void Preprocessor::LexAfterModuleImport(Token &Result) {
588 // Figure out what kind of lexer we actually have.
589 recomputeCurLexerKind();
591 // Lex the next token.
594 // The token sequence
596 // import identifier (. identifier)*
598 // indicates a module import directive. We already saw the 'import'
599 // contextual keyword, so now we're looking for the identifiers.
600 if (ModuleImportExpectsIdentifier && Result.getKind() == tok::identifier) {
601 // We expected to see an identifier here, and we did; continue handling
603 ModuleImportPath.push_back(std::make_pair(Result.getIdentifierInfo(),
604 Result.getLocation()));
605 ModuleImportExpectsIdentifier = false;
606 CurLexerKind = CLK_LexAfterModuleImport;
610 // If we're expecting a '.' or a ';', and we got a '.', then wait until we
611 // see the next identifier.
612 if (!ModuleImportExpectsIdentifier && Result.getKind() == tok::period) {
613 ModuleImportExpectsIdentifier = true;
614 CurLexerKind = CLK_LexAfterModuleImport;
618 // If we have a non-empty module path, load the named module.
619 if (!ModuleImportPath.empty())
620 (void)TheModuleLoader.loadModule(ModuleImportLoc, ModuleImportPath,
621 Module::MacrosVisible,
622 /*IsIncludeDirective=*/false);
625 void Preprocessor::AddCommentHandler(CommentHandler *Handler) {
626 assert(Handler && "NULL comment handler");
627 assert(std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler) ==
628 CommentHandlers.end() && "Comment handler already registered");
629 CommentHandlers.push_back(Handler);
632 void Preprocessor::RemoveCommentHandler(CommentHandler *Handler) {
633 std::vector<CommentHandler *>::iterator Pos
634 = std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler);
635 assert(Pos != CommentHandlers.end() && "Comment handler not registered");
636 CommentHandlers.erase(Pos);
639 bool Preprocessor::HandleComment(Token &result, SourceRange Comment) {
640 bool AnyPendingTokens = false;
641 for (std::vector<CommentHandler *>::iterator H = CommentHandlers.begin(),
642 HEnd = CommentHandlers.end();
644 if ((*H)->HandleComment(*this, Comment))
645 AnyPendingTokens = true;
647 if (!AnyPendingTokens || getCommentRetentionState())
653 ModuleLoader::~ModuleLoader() { }
655 CommentHandler::~CommentHandler() { }
657 CodeCompletionHandler::~CodeCompletionHandler() { }
659 void Preprocessor::createPreprocessingRecord(bool RecordConditionalDirectives) {
663 Record = new PreprocessingRecord(getSourceManager(),
664 RecordConditionalDirectives);
665 addPPCallbacks(Record);