summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-03-18 17:52:52 +0000
committerDouglas Gregor <dgregor@apple.com>2010-03-18 17:52:52 +0000
commit065f8d11caf73d75fbdedbe3a0fc0cddf56cb8a9 (patch)
treedff6501bcf881cd09ff08dba336dd158ab03fa19 /clang/lib/Lex
parenteaceb9fd392f8e4b80477055003e833c5642f9ca (diff)
downloadbcm5719-llvm-065f8d11caf73d75fbdedbe3a0fc0cddf56cb8a9.tar.gz
bcm5719-llvm-065f8d11caf73d75fbdedbe3a0fc0cddf56cb8a9.zip
Introduce the notion of a "preprocessing record", which keeps track of
the macro definitions and macro instantiations that are found during preprocessing. Preprocessing records are *not* generated by default; rather, we provide a PPCallbacks subclass that hooks into the existing callback mechanism to record this activity. The only client of preprocessing records is CIndex, which keeps track of macro definitions and instantations so that they can be exposed via cursors. At present, only token annotation uses these facilities, and only for macro instantiations; both will change in the near future. However, with this change, token annotation properly annotates macro instantiations that do not produce any tokens and instantiations of macros that are later undef'd, improving our consistency. Preprocessing directives that are not macro definitions are still handled by clang_annotateTokens() via re-lexing, so that we don't have to track every preprocessing directive in the preprocessing record. Performance impact of preprocessing records is still TBD, although it is limited to CIndex and therefore out of the path of the main compiler. llvm-svn: 98836
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r--clang/lib/Lex/CMakeLists.txt1
-rw-r--r--clang/lib/Lex/PreprocessingRecord.cpp37
2 files changed, 38 insertions, 0 deletions
diff --git a/clang/lib/Lex/CMakeLists.txt b/clang/lib/Lex/CMakeLists.txt
index 81a1e01f964..632fbc6340c 100644
--- a/clang/lib/Lex/CMakeLists.txt
+++ b/clang/lib/Lex/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangLex
PPMacroExpansion.cpp
PTHLexer.cpp
Pragma.cpp
+ PreprocessingRecord.cpp
Preprocessor.cpp
PreprocessorLexer.cpp
ScratchBuffer.cpp
diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp
new file mode 100644
index 00000000000..fe081b69bbb
--- /dev/null
+++ b/clang/lib/Lex/PreprocessingRecord.cpp
@@ -0,0 +1,37 @@
+//===--- 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);
+}
+
+void PopulatePreprocessingRecord::MacroExpands(const Token &Id,
+ const MacroInfo* MI) {
+ Record.addPreprocessedEntity(
+ new (Record) MacroInstantiation(Id.getIdentifierInfo(),
+ Id.getLocation(),
+ MI->getDefinitionLoc()));
+}
+
+void PopulatePreprocessingRecord::MacroDefined(const IdentifierInfo *II,
+ const MacroInfo *MI) {
+ SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc());
+ Record.addPreprocessedEntity(
+ new (Record) MacroDefinition(II, MI->getDefinitionLoc(), R));
+}
OpenPOWER on IntegriCloud