aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/PreprocessingRecord.cpp
blob: 6e0e28a1b85d02f25d35ac716dd9d25eb235d3ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//===--- PreprocessingRecord.cpp - Record of Preprocessing ------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file implements the PreprocessingRecord class, which maintains a record
//  of what occurred during preprocessing, and its helpers.
//
//===----------------------------------------------------------------------===//
#include "clang/Lex/PreprocessingRecord.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/Token.h"

using namespace clang;

void PreprocessingRecord::addPreprocessedEntity(PreprocessedEntity *Entity) {
  PreprocessedEntities.push_back(Entity);
}

MacroDefinition *PreprocessingRecord::findMacroDefinition(MacroInfo *MI) {
  llvm::DenseMap<const MacroInfo *, MacroDefinition *>::iterator Pos
    = MacroDefinitions.find(MI);
  if (Pos == MacroDefinitions.end())
    return 0;
  
  return Pos->second;
}

void PreprocessingRecord::MacroExpands(const Token &Id, const MacroInfo* MI) {
  PreprocessedEntities.push_back(
                       new (*this) MacroInstantiation(Id.getIdentifierInfo(),
                                                      Id.getLocation(),
                                                      MacroDefinitions[MI]));
}

void PreprocessingRecord::MacroDefined(const IdentifierInfo *II, 
                                       const MacroInfo *MI) {
  SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc());
  MacroDefinition *Def
    = new (*this) MacroDefinition(II, MI->getDefinitionLoc(), R);
  MacroDefinitions[MI] = Def;
  PreprocessedEntities.push_back(Def);
}