Preprocessor.cpp revision d6471f7c1921c7802804ce3ff6fe9768310f72b9
1//===--- Preprocess.cpp - C Language Family Preprocessor Implementation ---===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file implements the Preprocessor interface. 11// 12//===----------------------------------------------------------------------===// 13// 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. 18// -fpreprocessed 19// -dependency-file,-M,-MM,-MF,-MG,-MP,-MT,-MQ,-MD,-MMD 20// -W* 21// -w 22// 23// Messages to emit: 24// "Multiple include guards may be useful for:\n" 25// 26//===----------------------------------------------------------------------===// 27 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/SmallVector.h" 44#include "llvm/Support/MemoryBuffer.h" 45#include "llvm/Support/raw_ostream.h" 46#include "llvm/Support/Capacity.h" 47using namespace clang; 48 49//===----------------------------------------------------------------------===// 50ExternalPreprocessorSource::~ExternalPreprocessorSource() { } 51 52Preprocessor::Preprocessor(DiagnosticsEngine &diags, LangOptions &opts, 53 const TargetInfo *target, SourceManager &SM, 54 HeaderSearch &Headers, ModuleLoader &TheModuleLoader, 55 IdentifierInfoLookup* IILookup, 56 bool OwnsHeaders, 57 bool DelayInitialization) 58 : Diags(&diags), Features(opts), Target(target),FileMgr(Headers.getFileMgr()), 59 SourceMgr(SM), HeaderInfo(Headers), TheModuleLoader(TheModuleLoader), 60 ExternalSource(0), 61 Identifiers(opts, IILookup), CodeComplete(0), 62 CodeCompletionFile(0), CodeCompletionOffset(0), CodeCompletionReached(0), 63 SkipMainFilePreamble(0, true), CurPPLexer(0), 64 CurDirLookup(0), Callbacks(0), MacroArgCache(0), Record(0), MIChainHead(0), 65 MICache(0) 66{ 67 OwnsHeaderSearch = OwnsHeaders; 68 69 if (!DelayInitialization) { 70 assert(Target && "Must provide target information for PP initialization"); 71 Initialize(*Target); 72 } 73} 74 75Preprocessor::~Preprocessor() { 76 assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!"); 77 assert(((MacroExpandingLexersStack.empty() && MacroExpandedTokens.empty()) || 78 isCodeCompletionReached()) && 79 "Preprocessor::HandleEndOfTokenLexer should have cleared those"); 80 81 while (!IncludeMacroStack.empty()) { 82 delete IncludeMacroStack.back().TheLexer; 83 delete IncludeMacroStack.back().TheTokenLexer; 84 IncludeMacroStack.pop_back(); 85 } 86 87 // Free any macro definitions. 88 for (MacroInfoChain *I = MIChainHead ; I ; I = I->Next) 89 I->MI.Destroy(); 90 91 // Free any cached macro expanders. 92 for (unsigned i = 0, e = NumCachedTokenLexers; i != e; ++i) 93 delete TokenLexerCache[i]; 94 95 // Free any cached MacroArgs. 96 for (MacroArgs *ArgList = MacroArgCache; ArgList; ) 97 ArgList = ArgList->deallocate(); 98 99 // Release pragma information. 100 delete PragmaHandlers; 101 102 // Delete the scratch buffer info. 103 delete ScratchBuf; 104 105 // Delete the header search info, if we own it. 106 if (OwnsHeaderSearch) 107 delete &HeaderInfo; 108 109 delete Callbacks; 110} 111 112void Preprocessor::Initialize(const TargetInfo &Target) { 113 assert((!this->Target || this->Target == &Target) && 114 "Invalid override of target information"); 115 this->Target = &Target; 116 117 // Initialize information about built-ins. 118 BuiltinInfo.InitializeTarget(Target); 119 120 ScratchBuf = new ScratchBuffer(SourceMgr); 121 CounterValue = 0; // __COUNTER__ starts at 0. 122 123 // Clear stats. 124 NumDirectives = NumDefined = NumUndefined = NumPragma = 0; 125 NumIf = NumElse = NumEndif = 0; 126 NumEnteredSourceFiles = 0; 127 NumMacroExpanded = NumFnMacroExpanded = NumBuiltinMacroExpanded = 0; 128 NumFastMacroExpanded = NumTokenPaste = NumFastTokenPaste = 0; 129 MaxIncludeStackDepth = 0; 130 NumSkipped = 0; 131 132 // Default to discarding comments. 133 KeepComments = false; 134 KeepMacroComments = false; 135 SuppressIncludeNotFoundError = false; 136 AutoModuleImport = false; 137 138 // Macro expansion is enabled. 139 DisableMacroExpansion = false; 140 InMacroArgs = false; 141 NumCachedTokenLexers = 0; 142 143 CachedLexPos = 0; 144 145 // We haven't read anything from the external source. 146 ReadMacrosFromExternalSource = false; 147 148 // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro. 149 // This gets unpoisoned where it is allowed. 150 (Ident__VA_ARGS__ = getIdentifierInfo("__VA_ARGS__"))->setIsPoisoned(); 151 SetPoisonReason(Ident__VA_ARGS__,diag::ext_pp_bad_vaargs_use); 152 153 // Initialize the pragma handlers. 154 PragmaHandlers = new PragmaNamespace(StringRef()); 155 RegisterBuiltinPragmas(); 156 157 // Initialize builtin macros like __LINE__ and friends. 158 RegisterBuiltinMacros(); 159 160 if(Features.Borland) { 161 Ident__exception_info = getIdentifierInfo("_exception_info"); 162 Ident___exception_info = getIdentifierInfo("__exception_info"); 163 Ident_GetExceptionInfo = getIdentifierInfo("GetExceptionInformation"); 164 Ident__exception_code = getIdentifierInfo("_exception_code"); 165 Ident___exception_code = getIdentifierInfo("__exception_code"); 166 Ident_GetExceptionCode = getIdentifierInfo("GetExceptionCode"); 167 Ident__abnormal_termination = getIdentifierInfo("_abnormal_termination"); 168 Ident___abnormal_termination = getIdentifierInfo("__abnormal_termination"); 169 Ident_AbnormalTermination = getIdentifierInfo("AbnormalTermination"); 170 } else { 171 Ident__exception_info = Ident__exception_code = Ident__abnormal_termination = 0; 172 Ident___exception_info = Ident___exception_code = Ident___abnormal_termination = 0; 173 Ident_GetExceptionInfo = Ident_GetExceptionCode = Ident_AbnormalTermination = 0; 174 } 175} 176 177void Preprocessor::setPTHManager(PTHManager* pm) { 178 PTH.reset(pm); 179 FileMgr.addStatCache(PTH->createStatCache()); 180} 181 182void Preprocessor::DumpToken(const Token &Tok, bool DumpFlags) const { 183 llvm::errs() << tok::getTokenName(Tok.getKind()) << " '" 184 << getSpelling(Tok) << "'"; 185 186 if (!DumpFlags) return; 187 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()) 198 << "']"; 199 } 200 201 llvm::errs() << "\tLoc=<"; 202 DumpLocation(Tok.getLocation()); 203 llvm::errs() << ">"; 204} 205 206void Preprocessor::DumpLocation(SourceLocation Loc) const { 207 Loc.dump(SourceMgr); 208} 209 210void 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)); 214 llvm::errs() << " "; 215 } 216 llvm::errs() << "\n"; 217} 218 219void 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"; 232 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"; 239} 240 241Preprocessor::macro_iterator 242Preprocessor::macro_begin(bool IncludeExternalMacros) const { 243 if (IncludeExternalMacros && ExternalSource && 244 !ReadMacrosFromExternalSource) { 245 ReadMacrosFromExternalSource = true; 246 ExternalSource->ReadDefinedMacros(); 247 } 248 249 return Macros.begin(); 250} 251 252size_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); 260} 261 262Preprocessor::macro_iterator 263Preprocessor::macro_end(bool IncludeExternalMacros) const { 264 if (IncludeExternalMacros && ExternalSource && 265 !ReadMacrosFromExternalSource) { 266 ReadMacrosFromExternalSource = true; 267 ExternalSource->ReadDefinedMacros(); 268 } 269 270 return Macros.end(); 271} 272 273bool Preprocessor::SetCodeCompletionPoint(const FileEntry *File, 274 unsigned CompleteLine, 275 unsigned CompleteColumn) { 276 assert(File); 277 assert(CompleteLine && CompleteColumn && "Starts from 1:1"); 278 assert(!CodeCompletionFile && "Already set"); 279 280 using llvm::MemoryBuffer; 281 282 // Load the actual file's contents. 283 bool Invalid = false; 284 const MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File, &Invalid); 285 if (Invalid) 286 return true; 287 288 // Find the byte position of the truncation point. 289 const char *Position = Buffer->getBufferStart(); 290 for (unsigned Line = 1; Line < CompleteLine; ++Line) { 291 for (; *Position; ++Position) { 292 if (*Position != '\r' && *Position != '\n') 293 continue; 294 295 // Eat \r\n or \n\r as a single line. 296 if ((Position[1] == '\r' || Position[1] == '\n') && 297 Position[0] != Position[1]) 298 ++Position; 299 ++Position; 300 break; 301 } 302 } 303 304 Position += CompleteColumn - 1; 305 306 // Insert '\0' at the code-completion point. 307 if (Position < Buffer->getBufferEnd()) { 308 CodeCompletionFile = File; 309 CodeCompletionOffset = Position - Buffer->getBufferStart(); 310 311 MemoryBuffer *NewBuffer = 312 MemoryBuffer::getNewUninitMemBuffer(Buffer->getBufferSize() + 1, 313 Buffer->getBufferIdentifier()); 314 char *NewBuf = const_cast<char*>(NewBuffer->getBufferStart()); 315 char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf); 316 *NewPos = '\0'; 317 std::copy(Position, Buffer->getBufferEnd(), NewPos+1); 318 SourceMgr.overrideFileContents(File, NewBuffer); 319 } 320 321 return false; 322} 323 324void Preprocessor::CodeCompleteNaturalLanguage() { 325 if (CodeComplete) 326 CodeComplete->CodeCompleteNaturalLanguage(); 327 setCodeCompletionReached(); 328} 329 330/// getSpelling - This method is used to get the spelling of a token into a 331/// SmallVector. Note that the returned StringRef may not point to the 332/// supplied buffer if a copy can be avoided. 333StringRef Preprocessor::getSpelling(const Token &Tok, 334 SmallVectorImpl<char> &Buffer, 335 bool *Invalid) const { 336 // NOTE: this has to be checked *before* testing for an IdentifierInfo. 337 if (Tok.isNot(tok::raw_identifier)) { 338 // Try the fast path. 339 if (const IdentifierInfo *II = Tok.getIdentifierInfo()) 340 return II->getName(); 341 } 342 343 // Resize the buffer if we need to copy into it. 344 if (Tok.needsCleaning()) 345 Buffer.resize(Tok.getLength()); 346 347 const char *Ptr = Buffer.data(); 348 unsigned Len = getSpelling(Tok, Ptr, Invalid); 349 return StringRef(Ptr, Len); 350} 351 352/// CreateString - Plop the specified string into a scratch buffer and return a 353/// location for it. If specified, the source location provides a source 354/// location for the token. 355void Preprocessor::CreateString(const char *Buf, unsigned Len, Token &Tok, 356 SourceLocation ExpansionLoc) { 357 Tok.setLength(Len); 358 359 const char *DestPtr; 360 SourceLocation Loc = ScratchBuf->getToken(Buf, Len, DestPtr); 361 362 if (ExpansionLoc.isValid()) 363 Loc = SourceMgr.createExpansionLoc(Loc, ExpansionLoc, ExpansionLoc, Len); 364 Tok.setLocation(Loc); 365 366 // If this is a raw identifier or a literal token, set the pointer data. 367 if (Tok.is(tok::raw_identifier)) 368 Tok.setRawIdentifierData(DestPtr); 369 else if (Tok.isLiteral()) 370 Tok.setLiteralData(DestPtr); 371} 372 373 374 375//===----------------------------------------------------------------------===// 376// Preprocessor Initialization Methods 377//===----------------------------------------------------------------------===// 378 379 380/// EnterMainSourceFile - Enter the specified FileID as the main source file, 381/// which implicitly adds the builtin defines etc. 382void Preprocessor::EnterMainSourceFile() { 383 // We do not allow the preprocessor to reenter the main file. Doing so will 384 // cause FileID's to accumulate information from both runs (e.g. #line 385 // information) and predefined macros aren't guaranteed to be set properly. 386 assert(NumEnteredSourceFiles == 0 && "Cannot reenter the main file!"); 387 FileID MainFileID = SourceMgr.getMainFileID(); 388 389 // Enter the main file source buffer. 390 EnterSourceFile(MainFileID, 0, SourceLocation()); 391 392 // If we've been asked to skip bytes in the main file (e.g., as part of a 393 // precompiled preamble), do so now. 394 if (SkipMainFilePreamble.first > 0) 395 CurLexer->SkipBytes(SkipMainFilePreamble.first, 396 SkipMainFilePreamble.second); 397 398 // Tell the header info that the main file was entered. If the file is later 399 // #imported, it won't be re-entered. 400 if (const FileEntry *FE = SourceMgr.getFileEntryForID(MainFileID)) 401 HeaderInfo.IncrementIncludeCount(FE); 402 403 // Preprocess Predefines to populate the initial preprocessor state. 404 llvm::MemoryBuffer *SB = 405 llvm::MemoryBuffer::getMemBufferCopy(Predefines, "<built-in>"); 406 assert(SB && "Cannot create predefined source buffer"); 407 FileID FID = SourceMgr.createFileIDForMemBuffer(SB); 408 assert(!FID.isInvalid() && "Could not create FileID for predefines?"); 409 410 // Start parsing the predefines. 411 EnterSourceFile(FID, 0, SourceLocation()); 412} 413 414void Preprocessor::EndSourceFile() { 415 // Notify the client that we reached the end of the source file. 416 if (Callbacks) 417 Callbacks->EndOfMainFile(); 418} 419 420//===----------------------------------------------------------------------===// 421// Lexer Event Handling. 422//===----------------------------------------------------------------------===// 423 424/// LookUpIdentifierInfo - Given a tok::raw_identifier token, look up the 425/// identifier information for the token and install it into the token, 426/// updating the token kind accordingly. 427IdentifierInfo *Preprocessor::LookUpIdentifierInfo(Token &Identifier) const { 428 assert(Identifier.getRawIdentifierData() != 0 && "No raw identifier data!"); 429 430 // Look up this token, see if it is a macro, or if it is a language keyword. 431 IdentifierInfo *II; 432 if (!Identifier.needsCleaning()) { 433 // No cleaning needed, just use the characters from the lexed buffer. 434 II = getIdentifierInfo(StringRef(Identifier.getRawIdentifierData(), 435 Identifier.getLength())); 436 } else { 437 // Cleaning needed, alloca a buffer, clean into it, then use the buffer. 438 llvm::SmallString<64> IdentifierBuffer; 439 StringRef CleanedStr = getSpelling(Identifier, IdentifierBuffer); 440 II = getIdentifierInfo(CleanedStr); 441 } 442 443 // Update the token info (identifier info and appropriate token kind). 444 Identifier.setIdentifierInfo(II); 445 Identifier.setKind(II->getTokenID()); 446 447 return II; 448} 449 450void Preprocessor::SetPoisonReason(IdentifierInfo *II, unsigned DiagID) { 451 PoisonReasons[II] = DiagID; 452} 453 454void Preprocessor::PoisonSEHIdentifiers(bool Poison) { 455 assert(Ident__exception_code && Ident__exception_info); 456 assert(Ident___exception_code && Ident___exception_info); 457 Ident__exception_code->setIsPoisoned(Poison); 458 Ident___exception_code->setIsPoisoned(Poison); 459 Ident_GetExceptionCode->setIsPoisoned(Poison); 460 Ident__exception_info->setIsPoisoned(Poison); 461 Ident___exception_info->setIsPoisoned(Poison); 462 Ident_GetExceptionInfo->setIsPoisoned(Poison); 463 Ident__abnormal_termination->setIsPoisoned(Poison); 464 Ident___abnormal_termination->setIsPoisoned(Poison); 465 Ident_AbnormalTermination->setIsPoisoned(Poison); 466} 467 468void Preprocessor::HandlePoisonedIdentifier(Token & Identifier) { 469 assert(Identifier.getIdentifierInfo() && 470 "Can't handle identifiers without identifier info!"); 471 llvm::DenseMap<IdentifierInfo*,unsigned>::const_iterator it = 472 PoisonReasons.find(Identifier.getIdentifierInfo()); 473 if(it == PoisonReasons.end()) 474 Diag(Identifier, diag::err_pp_used_poisoned_id); 475 else 476 Diag(Identifier,it->second) << Identifier.getIdentifierInfo(); 477} 478 479/// HandleIdentifier - This callback is invoked when the lexer reads an 480/// identifier. This callback looks up the identifier in the map and/or 481/// potentially macro expands it or turns it into a named token (like 'for'). 482/// 483/// Note that callers of this method are guarded by checking the 484/// IdentifierInfo's 'isHandleIdentifierCase' bit. If this method changes, the 485/// IdentifierInfo methods that compute these properties will need to change to 486/// match. 487void Preprocessor::HandleIdentifier(Token &Identifier) { 488 assert(Identifier.getIdentifierInfo() && 489 "Can't handle identifiers without identifier info!"); 490 491 IdentifierInfo &II = *Identifier.getIdentifierInfo(); 492 493 // If this identifier was poisoned, and if it was not produced from a macro 494 // expansion, emit an error. 495 if (II.isPoisoned() && CurPPLexer) { 496 HandlePoisonedIdentifier(Identifier); 497 } 498 499 // If this is a macro to be expanded, do it. 500 if (MacroInfo *MI = getMacroInfo(&II)) { 501 if (!DisableMacroExpansion && !Identifier.isExpandDisabled()) { 502 if (MI->isEnabled()) { 503 if (!HandleMacroExpandedIdentifier(Identifier, MI)) 504 return; 505 } else { 506 // C99 6.10.3.4p2 says that a disabled macro may never again be 507 // expanded, even if it's in a context where it could be expanded in the 508 // future. 509 Identifier.setFlag(Token::DisableExpand); 510 } 511 } 512 } 513 514 // C++ 2.11p2: If this is an alternative representation of a C++ operator, 515 // then we act as if it is the actual operator and not the textual 516 // representation of it. 517 if (II.isCPlusPlusOperatorKeyword()) 518 Identifier.setIdentifierInfo(0); 519 520 // If this is an extension token, diagnose its use. 521 // We avoid diagnosing tokens that originate from macro definitions. 522 // FIXME: This warning is disabled in cases where it shouldn't be, 523 // like "#define TY typeof", "TY(1) x". 524 if (II.isExtensionToken() && !DisableMacroExpansion) 525 Diag(Identifier, diag::ext_token_used); 526 527 // If this is the '__import_module__' keyword, note that the next token 528 // indicates a module name. 529 if (II.getTokenID() == tok::kw___import_module__ && 530 !InMacroArgs && !DisableMacroExpansion) { 531 ModuleImportLoc = Identifier.getLocation(); 532 CurLexerKind = CLK_LexAfterModuleImport; 533 } 534} 535 536/// \brief Lex a token following the __import_module__ keyword. 537void Preprocessor::LexAfterModuleImport(Token &Result) { 538 // Figure out what kind of lexer we actually have. 539 if (CurLexer) 540 CurLexerKind = CLK_Lexer; 541 else if (CurPTHLexer) 542 CurLexerKind = CLK_PTHLexer; 543 else if (CurTokenLexer) 544 CurLexerKind = CLK_TokenLexer; 545 else 546 CurLexerKind = CLK_CachingLexer; 547 548 // Lex the next token. 549 Lex(Result); 550 551 // The token sequence 552 // 553 // __import_module__ identifier 554 // 555 // indicates a module import directive. We already saw the __import_module__ 556 // keyword, so now we're looking for the identifier. 557 if (Result.getKind() != tok::identifier) 558 return; 559 560 // Load the module. 561 (void)TheModuleLoader.loadModule(ModuleImportLoc, 562 *Result.getIdentifierInfo(), 563 Result.getLocation()); 564} 565 566void Preprocessor::AddCommentHandler(CommentHandler *Handler) { 567 assert(Handler && "NULL comment handler"); 568 assert(std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler) == 569 CommentHandlers.end() && "Comment handler already registered"); 570 CommentHandlers.push_back(Handler); 571} 572 573void Preprocessor::RemoveCommentHandler(CommentHandler *Handler) { 574 std::vector<CommentHandler *>::iterator Pos 575 = std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler); 576 assert(Pos != CommentHandlers.end() && "Comment handler not registered"); 577 CommentHandlers.erase(Pos); 578} 579 580bool Preprocessor::HandleComment(Token &result, SourceRange Comment) { 581 bool AnyPendingTokens = false; 582 for (std::vector<CommentHandler *>::iterator H = CommentHandlers.begin(), 583 HEnd = CommentHandlers.end(); 584 H != HEnd; ++H) { 585 if ((*H)->HandleComment(*this, Comment)) 586 AnyPendingTokens = true; 587 } 588 if (!AnyPendingTokens || getCommentRetentionState()) 589 return false; 590 Lex(result); 591 return true; 592} 593 594ModuleLoader::~ModuleLoader() { } 595 596CommentHandler::~CommentHandler() { } 597 598CodeCompletionHandler::~CodeCompletionHandler() { } 599 600void Preprocessor::createPreprocessingRecord( 601 bool IncludeNestedMacroExpansions) { 602 if (Record) 603 return; 604 605 Record = new PreprocessingRecord(getSourceManager(), 606 IncludeNestedMacroExpansions); 607 addPPCallbacks(Record); 608} 609