summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/PPDirectives.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-02-20 00:54:57 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-02-20 00:54:57 +0000
commit09c9e811de7696df87535d8a1d3e6c83e5316ee8 (patch)
tree0ff56079768b1ff1cdf038bf7892d36e5817197b /clang/lib/Lex/PPDirectives.cpp
parentcab3dfb65042d4abd552d14246e2778ffb66b02d (diff)
downloadbcm5719-llvm-09c9e811de7696df87535d8a1d3e6c83e5316ee8.tar.gz
bcm5719-llvm-09c9e811de7696df87535d8a1d3e6c83e5316ee8.zip
[preprocessor] Split the MacroInfo class into two separate concepts, MacroInfo class
for the data specific to a macro definition (e.g. what the tokens are), and MacroDirective class which encapsulates the changes to the "macro namespace" (e.g. the location where the macro name became active, the location where it was undefined, etc.) (A MacroDirective always points to a MacroInfo object.) Usually a macro definition (MacroInfo) is where a macro name becomes active (MacroDirective) but splitting the concepts allows us to better model the effect of modules to the macro namespace (also as a bonus it allows better modeling of push_macro/pop_macro #pragmas). Modules can have their own macro history, separate from the local (current translation unit) macro history; MacroDirectives will be used to model the macro history (changes to macro namespace). For example, if "@import A;" imports macro FOO, there will be a new local MacroDirective created to indicate that "FOO" became active at the import location. Module "A" itself will contain another MacroDirective in its macro history (at the point of the definition of FOO) and both MacroDirectives will point to the same MacroInfo object. Introducing the separation of macro concepts is the first part towards better modeling of module macros. llvm-svn: 175585
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp53
1 files changed, 28 insertions, 25 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index c8e1f4fc3e2..18250281c1d 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -57,10 +57,12 @@ MacroInfo *Preprocessor::AllocateMacroInfo(SourceLocation L) {
return MI;
}
-MacroInfo *Preprocessor::CloneMacroInfo(const MacroInfo &MacroToClone) {
- MacroInfo *MI = AllocateMacroInfo();
- new (MI) MacroInfo(MacroToClone, BP);
- return MI;
+MacroDirective *Preprocessor::AllocateMacroDirective(MacroInfo *MI,
+ SourceLocation Loc,
+ bool isImported) {
+ MacroDirective *MD = BP.Allocate<MacroDirective>();
+ new (MD) MacroDirective(MI, Loc, isImported);
+ return MD;
}
/// \brief Release the specified MacroInfo to be reused for allocating
@@ -1110,22 +1112,22 @@ void Preprocessor::HandleMacroPublicDirective(Token &Tok) {
CheckEndOfDirective("__public_macro");
// Okay, we finally have a valid identifier to undef.
- MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
+ MacroDirective *MD = getMacroDirective(MacroNameTok.getIdentifierInfo());
// If the macro is not defined, this is an error.
- if (MI == 0) {
+ if (MD == 0) {
Diag(MacroNameTok, diag::err_pp_visibility_non_macro)
<< MacroNameTok.getIdentifierInfo();
return;
}
// Note that this macro has now been exported.
- MI->setVisibility(/*IsPublic=*/true, MacroNameTok.getLocation());
-
+ MD->setVisibility(/*IsPublic=*/true, MacroNameTok.getLocation());
+
// If this macro definition came from a PCH file, mark it
// as having changed since serialization.
- if (MI->isFromAST())
- MI->setChangedAfterLoad();
+ if (MD->isImported())
+ MD->setChangedAfterLoad();
}
/// \brief Handle a #private directive.
@@ -1141,22 +1143,22 @@ void Preprocessor::HandleMacroPrivateDirective(Token &Tok) {
CheckEndOfDirective("__private_macro");
// Okay, we finally have a valid identifier to undef.
- MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
+ MacroDirective *MD = getMacroDirective(MacroNameTok.getIdentifierInfo());
// If the macro is not defined, this is an error.
- if (MI == 0) {
+ if (MD == 0) {
Diag(MacroNameTok, diag::err_pp_visibility_non_macro)
<< MacroNameTok.getIdentifierInfo();
return;
}
// Note that this macro has now been marked private.
- MI->setVisibility(/*IsPublic=*/false, MacroNameTok.getLocation());
-
+ MD->setVisibility(/*IsPublic=*/false, MacroNameTok.getLocation());
+
// If this macro definition came from a PCH file, mark it
// as having changed since serialization.
- if (MI->isFromAST())
- MI->setChangedAfterLoad();
+ if (MD->isImported())
+ MD->setChangedAfterLoad();
}
//===----------------------------------------------------------------------===//
@@ -1918,7 +1920,7 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
// Finally, if this identifier already had a macro defined for it, verify that
// the macro bodies are identical, and issue diagnostics if they are not.
- if (MacroInfo *OtherMI = getMacroInfo(MacroNameTok.getIdentifierInfo())) {
+ if (const MacroInfo *OtherMI=getMacroInfo(MacroNameTok.getIdentifierInfo())) {
// It is very common for system headers to have tons of macro redefinitions
// and for warnings to be disabled in system headers. If this is the case,
// then don't bother calling MacroInfo::isIdenticalTo.
@@ -1940,7 +1942,7 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
WarnUnusedMacroLocs.erase(OtherMI->getDefinitionLoc());
}
- setMacroInfo(MacroNameTok.getIdentifierInfo(), MI);
+ setMacroDirective(MacroNameTok.getIdentifierInfo(), MI);
assert(!MI->isUsed());
// If we need warning for not using the macro, add its location in the
@@ -1973,7 +1975,8 @@ void Preprocessor::HandleUndefDirective(Token &UndefTok) {
CheckEndOfDirective("undef");
// Okay, we finally have a valid identifier to undef.
- MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
+ MacroDirective *MD = getMacroDirective(MacroNameTok.getIdentifierInfo());
+ const MacroInfo *MI = MD ? MD->getInfo() : 0;
// If the callbacks want to know, tell them about the macro #undef.
// Note: no matter if the macro was defined or not.
@@ -1989,17 +1992,17 @@ void Preprocessor::HandleUndefDirective(Token &UndefTok) {
if (MI->isWarnIfUnused())
WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());
- UndefineMacro(MacroNameTok.getIdentifierInfo(), MI,
+ UndefineMacro(MacroNameTok.getIdentifierInfo(), MD,
MacroNameTok.getLocation());
}
-void Preprocessor::UndefineMacro(IdentifierInfo *II, MacroInfo *MI,
+void Preprocessor::UndefineMacro(IdentifierInfo *II, MacroDirective *MD,
SourceLocation UndefLoc) {
- MI->setUndefLoc(UndefLoc);
- if (MI->isFromAST()) {
- MI->setChangedAfterLoad();
+ MD->setUndefLoc(UndefLoc);
+ if (MD->isImported()) {
+ MD->setChangedAfterLoad();
if (Listener)
- Listener->UndefinedMacro(MI);
+ Listener->UndefinedMacro(MD);
}
clearMacroInfo(II);
OpenPOWER on IntegriCloud