Douglas Gregor | 065f8d1 | 2010-03-18 17:52:52 +0000 | [diff] [blame] | 1 | //===--- PreprocessingRecord.cpp - Record of Preprocessing ------*- C++ -*-===// |
| 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 PreprocessingRecord class, which maintains a record |
| 11 | // of what occurred during preprocessing, and its helpers. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | #include "clang/Lex/PreprocessingRecord.h" |
| 15 | #include "clang/Lex/MacroInfo.h" |
| 16 | #include "clang/Lex/Token.h" |
| 17 | |
| 18 | using namespace clang; |
| 19 | |
| 20 | void PreprocessingRecord::addPreprocessedEntity(PreprocessedEntity *Entity) { |
| 21 | PreprocessedEntities.push_back(Entity); |
| 22 | } |
| 23 | |
Douglas Gregor | 7dc8722 | 2010-03-19 17:12:43 +0000 | [diff] [blame^] | 24 | MacroDefinition *PreprocessingRecord::findMacroDefinition(MacroInfo *MI) { |
| 25 | llvm::DenseMap<const MacroInfo *, MacroDefinition *>::iterator Pos |
| 26 | = MacroDefinitions.find(MI); |
| 27 | if (Pos == MacroDefinitions.end()) |
| 28 | return 0; |
| 29 | |
| 30 | return Pos->second; |
| 31 | } |
| 32 | |
| 33 | void PreprocessingRecord::MacroExpands(const Token &Id, const MacroInfo* MI) { |
| 34 | PreprocessedEntities.push_back( |
| 35 | new (*this) MacroInstantiation(Id.getIdentifierInfo(), |
| 36 | Id.getLocation(), |
| 37 | MacroDefinitions[MI])); |
| 38 | } |
| 39 | |
| 40 | void PreprocessingRecord::MacroDefined(const IdentifierInfo *II, |
| 41 | const MacroInfo *MI) { |
| 42 | SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc()); |
| 43 | MacroDefinition *Def |
| 44 | = new (*this) MacroDefinition(II, MI->getDefinitionLoc(), R); |
| 45 | MacroDefinitions[MI] = Def; |
| 46 | PreprocessedEntities.push_back(Def); |
| 47 | } |