blob: 6e0e28a1b85d02f25d35ac716dd9d25eb235d3ac [file] [log] [blame]
Douglas Gregor065f8d12010-03-18 17:52:52 +00001//===--- 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
18using namespace clang;
19
20void PreprocessingRecord::addPreprocessedEntity(PreprocessedEntity *Entity) {
21 PreprocessedEntities.push_back(Entity);
22}
23
Douglas Gregor7dc87222010-03-19 17:12:43 +000024MacroDefinition *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
33void 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
40void 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}