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" 47 using namespace clang; 48 49 //===----------------------------------------------------------------------===// 50 ExternalPreprocessorSource::~ExternalPreprocessorSource() { } 51 52 Preprocessor::Preprocessor(Diagnostic &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 75 Preprocessor::~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 112 void 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 137 // Macro expansion is enabled. 138 DisableMacroExpansion = false; 139 InMacroArgs = false; 140 NumCachedTokenLexers = 0; 141 142 CachedLexPos = 0; 143 144 // We haven't read anything from the external source. 145 ReadMacrosFromExternalSource = false; 146 147 // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro. 148 // This gets unpoisoned where it is allowed. 149 (Ident__VA_ARGS__ = getIdentifierInfo("__VA_ARGS__"))->setIsPoisoned(); 150 SetPoisonReason(Ident__VA_ARGS__,diag::ext_pp_bad_vaargs_use); 151 152 // Initialize the pragma handlers. 153 PragmaHandlers = new PragmaNamespace(StringRef()); 154 RegisterBuiltinPragmas(); 155 156 // Initialize builtin macros like __LINE__ and friends. 157 RegisterBuiltinMacros(); 158 159 if(Features.Borland) { 160 Ident__exception_info = getIdentifierInfo("_exception_info"); 161 Ident___exception_info = getIdentifierInfo("__exception_info"); 162 Ident_GetExceptionInfo = getIdentifierInfo("GetExceptionInformation"); 163 Ident__exception_code = getIdentifierInfo("_exception_code"); 164 Ident___exception_code = getIdentifierInfo("__exception_code"); 165 Ident_GetExceptionCode = getIdentifierInfo("GetExceptionCode"); 166 Ident__abnormal_termination = getIdentifierInfo("_abnormal_termination"); 167 Ident___abnormal_termination = getIdentifierInfo("__abnormal_termination"); 168 Ident_AbnormalTermination = getIdentifierInfo("AbnormalTermination"); 169 } else { 170 Ident__exception_info = Ident__exception_code = Ident__abnormal_termination = 0; 171 Ident___exception_info = Ident___exception_code = Ident___abnormal_termination = 0; 172 Ident_GetExceptionInfo = Ident_GetExceptionCode = Ident_AbnormalTermination = 0; 173 } 174 } 175 176 void Preprocessor::setPTHManager(PTHManager* pm) { 177 PTH.reset(pm); 178 FileMgr.addStatCache(PTH->createStatCache()); 179 } 180 181 void Preprocessor::DumpToken(const Token &Tok, bool DumpFlags) const { 182 llvm::errs() << tok::getTokenName(Tok.getKind()) << " '" 183 << getSpelling(Tok) << "'"; 184 185 if (!DumpFlags) return; 186 187 llvm::errs() << "\t"; 188 if (Tok.isAtStartOfLine()) 189 llvm::errs() << " [StartOfLine]"; 190 if (Tok.hasLeadingSpace()) 191 llvm::errs() << " [LeadingSpace]"; 192 if (Tok.isExpandDisabled()) 193 llvm::errs() << " [ExpandDisabled]"; 194 if (Tok.needsCleaning()) { 195 const char *Start = SourceMgr.getCharacterData(Tok.getLocation()); 196 llvm::errs() << " [UnClean='" << StringRef(Start, Tok.getLength()) 197 << "']"; 198 } 199 200 llvm::errs() << "\tLoc=<"; 201 DumpLocation(Tok.getLocation()); 202 llvm::errs() << ">"; 203 } 204 205 void Preprocessor::DumpLocation(SourceLocation Loc) const { 206 Loc.dump(SourceMgr); 207 } 208 209 void Preprocessor::DumpMacro(const MacroInfo &MI) const { 210 llvm::errs() << "MACRO: "; 211 for (unsigned i = 0, e = MI.getNumTokens(); i != e; ++i) { 212 DumpToken(MI.getReplacementToken(i)); 213 llvm::errs() << " "; 214 } 215 llvm::errs() << "\n"; 216 } 217 218 void Preprocessor::PrintStats() { 219 llvm::errs() << "\n*** Preprocessor Stats:\n"; 220 llvm::errs() << NumDirectives << " directives found:\n"; 221 llvm::errs() << " " << NumDefined << " #define.\n"; 222 llvm::errs() << " " << NumUndefined << " #undef.\n"; 223 llvm::errs() << " #include/#include_next/#import:\n"; 224 llvm::errs() << " " << NumEnteredSourceFiles << " source files entered.\n"; 225 llvm::errs() << " " << MaxIncludeStackDepth << " max include stack depth\n"; 226 llvm::errs() << " " << NumIf << " #if/#ifndef/#ifdef.\n"; 227 llvm::errs() << " " << NumElse << " #else/#elif.\n"; 228 llvm::errs() << " " << NumEndif << " #endif.\n"; 229 llvm::errs() << " " << NumPragma << " #pragma.\n"; 230 llvm::errs() << NumSkipped << " #if/#ifndef#ifdef regions skipped\n"; 231 232 llvm::errs() << NumMacroExpanded << "/" << NumFnMacroExpanded << "/" 233 << NumBuiltinMacroExpanded << " obj/fn/builtin macros expanded, " 234 << NumFastMacroExpanded << " on the fast path.\n"; 235 llvm::errs() << (NumFastTokenPaste+NumTokenPaste) 236 << " token paste (##) operations performed, " 237 << NumFastTokenPaste << " on the fast path.\n"; 238 } 239 240 Preprocessor::macro_iterator 241 Preprocessor::macro_begin(bool IncludeExternalMacros) const { 242 if (IncludeExternalMacros && ExternalSource && 243 !ReadMacrosFromExternalSource) { 244 ReadMacrosFromExternalSource = true; 245 ExternalSource->ReadDefinedMacros(); 246 } 247 248 return Macros.begin(); 249 } 250 251 size_t Preprocessor::getTotalMemory() const { 252 return BP.getTotalMemory() 253 + llvm::capacity_in_bytes(MacroExpandedTokens) 254 + Predefines.capacity() /* Predefines buffer. */ 255 + llvm::capacity_in_bytes(Macros) 256 + llvm::capacity_in_bytes(PragmaPushMacroInfo) 257 + llvm::capacity_in_bytes(PoisonReasons) 258 + llvm::capacity_in_bytes(CommentHandlers); 259 } 260 261 Preprocessor::macro_iterator 262 Preprocessor::macro_end(bool IncludeExternalMacros) const { 263 if (IncludeExternalMacros && ExternalSource && 264 !ReadMacrosFromExternalSource) { 265 ReadMacrosFromExternalSource = true; 266 ExternalSource->ReadDefinedMacros(); 267 } 268 269 return Macros.end(); 270 } 271 272 bool Preprocessor::SetCodeCompletionPoint(const FileEntry *File, 273 unsigned CompleteLine, 274 unsigned CompleteColumn) { 275 assert(File); 276 assert(CompleteLine && CompleteColumn && "Starts from 1:1"); 277 assert(!CodeCompletionFile && "Already set"); 278 279 using llvm::MemoryBuffer; 280 281 // Load the actual file's contents. 282 bool Invalid = false; 283 const MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File, &Invalid); 284 if (Invalid) 285 return true; 286 287 // Find the byte position of the truncation point. 288 const char *Position = Buffer->getBufferStart(); 289 for (unsigned Line = 1; Line < CompleteLine; ++Line) { 290 for (; *Position; ++Position) { 291 if (*Position != '\r' && *Position != '\n') 292 continue; 293 294 // Eat \r\n or \n\r as a single line. 295 if ((Position[1] == '\r' || Position[1] == '\n') && 296 Position[0] != Position[1]) 297 ++Position; 298 ++Position; 299 break; 300 } 301 } 302 303 Position += CompleteColumn - 1; 304 305 // Insert '\0' at the code-completion point. 306 if (Position < Buffer->getBufferEnd()) { 307 CodeCompletionFile = File; 308 CodeCompletionOffset = Position - Buffer->getBufferStart(); 309 310 MemoryBuffer *NewBuffer = 311 MemoryBuffer::getNewUninitMemBuffer(Buffer->getBufferSize() + 1, 312 Buffer->getBufferIdentifier()); 313 char *NewBuf = const_cast<char*>(NewBuffer->getBufferStart()); 314 char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf); 315 *NewPos = '\0'; 316 std::copy(Position, Buffer->getBufferEnd(), NewPos+1); 317 SourceMgr.overrideFileContents(File, NewBuffer); 318 } 319 320 return false; 321 } 322 323 void Preprocessor::CodeCompleteNaturalLanguage() { 324 if (CodeComplete) 325 CodeComplete->CodeCompleteNaturalLanguage(); 326 setCodeCompletionReached(); 327 } 328 329 /// getSpelling - This method is used to get the spelling of a token into a 330 /// SmallVector. Note that the returned StringRef may not point to the 331 /// supplied buffer if a copy can be avoided. 332 StringRef Preprocessor::getSpelling(const Token &Tok, 333 SmallVectorImpl<char> &Buffer, 334 bool *Invalid) const { 335 // NOTE: this has to be checked *before* testing for an IdentifierInfo. 336 if (Tok.isNot(tok::raw_identifier)) { 337 // Try the fast path. 338 if (const IdentifierInfo *II = Tok.getIdentifierInfo()) 339 return II->getName(); 340 } 341 342 // Resize the buffer if we need to copy into it. 343 if (Tok.needsCleaning()) 344 Buffer.resize(Tok.getLength()); 345 346 const char *Ptr = Buffer.data(); 347 unsigned Len = getSpelling(Tok, Ptr, Invalid); 348 return StringRef(Ptr, Len); 349 } 350 351 /// CreateString - Plop the specified string into a scratch buffer and return a 352 /// location for it. If specified, the source location provides a source 353 /// location for the token. 354 void Preprocessor::CreateString(const char *Buf, unsigned Len, Token &Tok, 355 SourceLocation ExpansionLoc) { 356 Tok.setLength(Len); 357 358 const char *DestPtr; 359 SourceLocation Loc = ScratchBuf->getToken(Buf, Len, DestPtr); 360 361 if (ExpansionLoc.isValid()) 362 Loc = SourceMgr.createExpansionLoc(Loc, ExpansionLoc, ExpansionLoc, Len); 363 Tok.setLocation(Loc); 364 365 // If this is a raw identifier or a literal token, set the pointer data. 366 if (Tok.is(tok::raw_identifier)) 367 Tok.setRawIdentifierData(DestPtr); 368 else if (Tok.isLiteral()) 369 Tok.setLiteralData(DestPtr); 370 } 371 372 373 374 //===----------------------------------------------------------------------===// 375 // Preprocessor Initialization Methods 376 //===----------------------------------------------------------------------===// 377 378 379 /// EnterMainSourceFile - Enter the specified FileID as the main source file, 380 /// which implicitly adds the builtin defines etc. 381 void Preprocessor::EnterMainSourceFile() { 382 // We do not allow the preprocessor to reenter the main file. Doing so will 383 // cause FileID's to accumulate information from both runs (e.g. #line 384 // information) and predefined macros aren't guaranteed to be set properly. 385 assert(NumEnteredSourceFiles == 0 && "Cannot reenter the main file!"); 386 FileID MainFileID = SourceMgr.getMainFileID(); 387 388 // Enter the main file source buffer. 389 EnterSourceFile(MainFileID, 0, SourceLocation()); 390 391 // If we've been asked to skip bytes in the main file (e.g., as part of a 392 // precompiled preamble), do so now. 393 if (SkipMainFilePreamble.first > 0) 394 CurLexer->SkipBytes(SkipMainFilePreamble.first, 395 SkipMainFilePreamble.second); 396 397 // Tell the header info that the main file was entered. If the file is later 398 // #imported, it won't be re-entered. 399 if (const FileEntry *FE = SourceMgr.getFileEntryForID(MainFileID)) 400 HeaderInfo.IncrementIncludeCount(FE); 401 402 // Preprocess Predefines to populate the initial preprocessor state. 403 llvm::MemoryBuffer *SB = 404 llvm::MemoryBuffer::getMemBufferCopy(Predefines, "<built-in>"); 405 assert(SB && "Cannot create predefined source buffer"); 406 FileID FID = SourceMgr.createFileIDForMemBuffer(SB); 407 assert(!FID.isInvalid() && "Could not create FileID for predefines?"); 408 409 // Start parsing the predefines. 410 EnterSourceFile(FID, 0, SourceLocation()); 411 } 412 413 void Preprocessor::EndSourceFile() { 414 // Notify the client that we reached the end of the source file. 415 if (Callbacks) 416 Callbacks->EndOfMainFile(); 417 } 418 419 //===----------------------------------------------------------------------===// 420 // Lexer Event Handling. 421 //===----------------------------------------------------------------------===// 422 423 /// LookUpIdentifierInfo - Given a tok::raw_identifier token, look up the 424 /// identifier information for the token and install it into the token, 425 /// updating the token kind accordingly. 426 IdentifierInfo *Preprocessor::LookUpIdentifierInfo(Token &Identifier) const { 427 assert(Identifier.getRawIdentifierData() != 0 && "No raw identifier data!"); 428 429 // Look up this token, see if it is a macro, or if it is a language keyword. 430 IdentifierInfo *II; 431 if (!Identifier.needsCleaning()) { 432 // No cleaning needed, just use the characters from the lexed buffer. 433 II = getIdentifierInfo(StringRef(Identifier.getRawIdentifierData(), 434 Identifier.getLength())); 435 } else { 436 // Cleaning needed, alloca a buffer, clean into it, then use the buffer. 437 llvm::SmallString<64> IdentifierBuffer; 438 StringRef CleanedStr = getSpelling(Identifier, IdentifierBuffer); 439 II = getIdentifierInfo(CleanedStr); 440 } 441 442 // Update the token info (identifier info and appropriate token kind). 443 Identifier.setIdentifierInfo(II); 444 Identifier.setKind(II->getTokenID()); 445 446 return II; 447 } 448 449 void Preprocessor::SetPoisonReason(IdentifierInfo *II, unsigned DiagID) { 450 PoisonReasons[II] = DiagID; 451 } 452 453 void Preprocessor::PoisonSEHIdentifiers(bool Poison) { 454 assert(Ident__exception_code && Ident__exception_info); 455 assert(Ident___exception_code && Ident___exception_info); 456 Ident__exception_code->setIsPoisoned(Poison); 457 Ident___exception_code->setIsPoisoned(Poison); 458 Ident_GetExceptionCode->setIsPoisoned(Poison); 459 Ident__exception_info->setIsPoisoned(Poison); 460 Ident___exception_info->setIsPoisoned(Poison); 461 Ident_GetExceptionInfo->setIsPoisoned(Poison); 462 Ident__abnormal_termination->setIsPoisoned(Poison); 463 Ident___abnormal_termination->setIsPoisoned(Poison); 464 Ident_AbnormalTermination->setIsPoisoned(Poison); 465 } 466 467 void Preprocessor::HandlePoisonedIdentifier(Token & Identifier) { 468 assert(Identifier.getIdentifierInfo() && 469 "Can't handle identifiers without identifier info!"); 470 llvm::DenseMap<IdentifierInfo*,unsigned>::const_iterator it = 471 PoisonReasons.find(Identifier.getIdentifierInfo()); 472 if(it == PoisonReasons.end()) 473 Diag(Identifier, diag::err_pp_used_poisoned_id); 474 else 475 Diag(Identifier,it->second) << Identifier.getIdentifierInfo(); 476 } 477 478 /// HandleIdentifier - This callback is invoked when the lexer reads an 479 /// identifier. This callback looks up the identifier in the map and/or 480 /// potentially macro expands it or turns it into a named token (like 'for'). 481 /// 482 /// Note that callers of this method are guarded by checking the 483 /// IdentifierInfo's 'isHandleIdentifierCase' bit. If this method changes, the 484 /// IdentifierInfo methods that compute these properties will need to change to 485 /// match. 486 void Preprocessor::HandleIdentifier(Token &Identifier) { 487 assert(Identifier.getIdentifierInfo() && 488 "Can't handle identifiers without identifier info!"); 489 490 IdentifierInfo &II = *Identifier.getIdentifierInfo(); 491 492 // If this identifier was poisoned, and if it was not produced from a macro 493 // expansion, emit an error. 494 if (II.isPoisoned() && CurPPLexer) { 495 HandlePoisonedIdentifier(Identifier); 496 } 497 498 // If this is a macro to be expanded, do it. 499 if (MacroInfo *MI = getMacroInfo(&II)) { 500 if (!DisableMacroExpansion && !Identifier.isExpandDisabled()) { 501 if (MI->isEnabled()) { 502 if (!HandleMacroExpandedIdentifier(Identifier, MI)) 503 return; 504 } else { 505 // C99 6.10.3.4p2 says that a disabled macro may never again be 506 // expanded, even if it's in a context where it could be expanded in the 507 // future. 508 Identifier.setFlag(Token::DisableExpand); 509 } 510 } 511 } 512 513 // C++ 2.11p2: If this is an alternative representation of a C++ operator, 514 // then we act as if it is the actual operator and not the textual 515 // representation of it. 516 if (II.isCPlusPlusOperatorKeyword()) 517 Identifier.setIdentifierInfo(0); 518 519 // If this is an extension token, diagnose its use. 520 // We avoid diagnosing tokens that originate from macro definitions. 521 // FIXME: This warning is disabled in cases where it shouldn't be, 522 // like "#define TY typeof", "TY(1) x". 523 if (II.isExtensionToken() && !DisableMacroExpansion) 524 Diag(Identifier, diag::ext_token_used); 525 526 // If this is the '__import_module__' keyword, note that the next token 527 // indicates a module name. 528 if (II.getTokenID() == tok::kw___import_module__ && 529 !InMacroArgs && !DisableMacroExpansion) { 530 ModuleImportLoc = Identifier.getLocation(); 531 CurLexerKind = CLK_LexAfterModuleImport; 532 } 533 } 534 535 /// \brief Lex a token following the __import_module__ keyword. 536 void Preprocessor::LexAfterModuleImport(Token &Result) { 537 // Figure out what kind of lexer we actually have. 538 if (CurLexer) 539 CurLexerKind = CLK_Lexer; 540 else if (CurPTHLexer) 541 CurLexerKind = CLK_PTHLexer; 542 else if (CurTokenLexer) 543 CurLexerKind = CLK_TokenLexer; 544 else 545 CurLexerKind = CLK_CachingLexer; 546 547 // Lex the next token. 548 Lex(Result); 549 550 // The token sequence 551 // 552 // __import_module__ identifier 553 // 554 // indicates a module import directive. We already saw the __import_module__ 555 // keyword, so now we're looking for the identifier. 556 if (Result.getKind() != tok::identifier) 557 return; 558 559 // Load the module. 560 (void)TheModuleLoader.loadModule(ModuleImportLoc, 561 *Result.getIdentifierInfo(), 562 Result.getLocation()); 563 } 564 565 void Preprocessor::AddCommentHandler(CommentHandler *Handler) { 566 assert(Handler && "NULL comment handler"); 567 assert(std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler) == 568 CommentHandlers.end() && "Comment handler already registered"); 569 CommentHandlers.push_back(Handler); 570 } 571 572 void Preprocessor::RemoveCommentHandler(CommentHandler *Handler) { 573 std::vector<CommentHandler *>::iterator Pos 574 = std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler); 575 assert(Pos != CommentHandlers.end() && "Comment handler not registered"); 576 CommentHandlers.erase(Pos); 577 } 578 579 bool Preprocessor::HandleComment(Token &result, SourceRange Comment) { 580 bool AnyPendingTokens = false; 581 for (std::vector<CommentHandler *>::iterator H = CommentHandlers.begin(), 582 HEnd = CommentHandlers.end(); 583 H != HEnd; ++H) { 584 if ((*H)->HandleComment(*this, Comment)) 585 AnyPendingTokens = true; 586 } 587 if (!AnyPendingTokens || getCommentRetentionState()) 588 return false; 589 Lex(result); 590 return true; 591 } 592 593 ModuleLoader::~ModuleLoader() { } 594 595 CommentHandler::~CommentHandler() { } 596 597 CodeCompletionHandler::~CodeCompletionHandler() { } 598 599 void Preprocessor::createPreprocessingRecord( 600 bool IncludeNestedMacroExpansions) { 601 if (Record) 602 return; 603 604 Record = new PreprocessingRecord(IncludeNestedMacroExpansions); 605 addPPCallbacks(Record); 606 } 607