summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/modularize/PreprocessorTracker.cpp
diff options
context:
space:
mode:
authorJohn Thompson <John.Thompson.JTSoftware@gmail.com>2015-02-11 16:58:36 +0000
committerJohn Thompson <John.Thompson.JTSoftware@gmail.com>2015-02-11 16:58:36 +0000
commitecd3b04cd7588b7789038f0756c6cdef810c64c4 (patch)
tree788e9d25f98c59002f33ebd234a34092a53353d4 /clang-tools-extra/modularize/PreprocessorTracker.cpp
parent9724431c77b7faeeaf0e2db3144e49cab8f36d8d (diff)
downloadbcm5719-llvm-ecd3b04cd7588b7789038f0756c6cdef810c64c4.tar.gz
bcm5719-llvm-ecd3b04cd7588b7789038f0756c6cdef810c64c4.zip
Added -block-check-header-list-only option. This is a work-around for private includes that purposefully get included inside blocks.
llvm-svn: 228846
Diffstat (limited to 'clang-tools-extra/modularize/PreprocessorTracker.cpp')
-rw-r--r--clang-tools-extra/modularize/PreprocessorTracker.cpp42
1 files changed, 37 insertions, 5 deletions
diff --git a/clang-tools-extra/modularize/PreprocessorTracker.cpp b/clang-tools-extra/modularize/PreprocessorTracker.cpp
index 685e242032c..2a41921cb46 100644
--- a/clang-tools-extra/modularize/PreprocessorTracker.cpp
+++ b/clang-tools-extra/modularize/PreprocessorTracker.cpp
@@ -866,9 +866,19 @@ ConditionalExpansionMapIter;
// course of running modularize.
class PreprocessorTrackerImpl : public PreprocessorTracker {
public:
- PreprocessorTrackerImpl()
- : CurrentInclusionPathHandle(InclusionPathHandleInvalid),
- InNestedHeader(false) {}
+ PreprocessorTrackerImpl(llvm::SmallVector<std::string, 32> &Headers,
+ bool DoBlockCheckHeaderListOnly)
+ : BlockCheckHeaderListOnly(DoBlockCheckHeaderListOnly),
+ CurrentInclusionPathHandle(InclusionPathHandleInvalid),
+ InNestedHeader(false) {
+ // Use canonical header path representation.
+ for (llvm::ArrayRef<std::string>::iterator I = Headers.begin(),
+ E = Headers.end();
+ I != E; ++I) {
+ HeaderList.push_back(getCanonicalPath(*I));
+ }
+ }
+
~PreprocessorTrackerImpl() {}
// Handle entering a preprocessing session.
@@ -889,6 +899,10 @@ public:
// "namespace {}" blocks containing #include directives.
void handleIncludeDirective(llvm::StringRef DirectivePath, int DirectiveLine,
int DirectiveColumn, llvm::StringRef TargetPath) {
+ // If it's not a header in the header list, ignore it with respect to
+ // the check.
+ if (BlockCheckHeaderListOnly && !isHeaderListHeader(DirectivePath))
+ return;
HeaderHandle CurrentHeaderHandle = findHeaderHandle(DirectivePath);
StringHandle IncludeHeaderHandle = addString(TargetPath);
for (std::vector<PPItemKey>::const_iterator I = IncludeDirectives.begin(),
@@ -959,6 +973,7 @@ public:
if (!InNestedHeader)
InNestedHeader = !HeadersInThisCompile.insert(H).second;
}
+
// Handle exiting a header source file.
void handleHeaderExit(llvm::StringRef HeaderPath) {
// Ignore <built-in> and <command-line> to reduce message clutter.
@@ -982,6 +997,18 @@ public:
return CanonicalPath;
}
+ // Return true if the given header is in the header list.
+ bool isHeaderListHeader(llvm::StringRef HeaderPath) const {
+ std::string CanonicalPath = getCanonicalPath(HeaderPath);
+ for (llvm::ArrayRef<std::string>::iterator I = HeaderList.begin(),
+ E = HeaderList.end();
+ I != E; ++I) {
+ if (*I == CanonicalPath)
+ return true;
+ }
+ return false;
+ }
+
// Get the handle of a header file entry.
// Return HeaderHandleInvalid if not found.
HeaderHandle findHeaderHandle(llvm::StringRef HeaderPath) const {
@@ -1301,6 +1328,9 @@ public:
}
private:
+ llvm::SmallVector<std::string, 32> HeaderList;
+ // Only do extern, namespace check for headers in HeaderList.
+ bool BlockCheckHeaderListOnly;
llvm::StringPool Strings;
std::vector<StringHandle> HeaderPaths;
std::vector<HeaderHandle> HeaderStack;
@@ -1319,8 +1349,10 @@ private:
PreprocessorTracker::~PreprocessorTracker() {}
// Create instance of PreprocessorTracker.
-PreprocessorTracker *PreprocessorTracker::create() {
- return new PreprocessorTrackerImpl();
+PreprocessorTracker *PreprocessorTracker::create(
+ llvm::SmallVector<std::string, 32> &Headers,
+ bool DoBlockCheckHeaderListOnly) {
+ return new PreprocessorTrackerImpl(Headers, DoBlockCheckHeaderListOnly);
}
// Preprocessor callbacks for modularize.
OpenPOWER on IntegriCloud