Fixed uninitialized member, plus recommit of 187736.

llvm-svn: 187757
This commit is contained in:
John Thompson 2013-08-05 23:55:14 +00:00
parent dc17270968
commit 48df096c3f
1 changed files with 27 additions and 12 deletions

View File

@ -799,7 +799,8 @@ ConditionalExpansionMapIter;
class PreprocessorTrackerImpl : public PreprocessorTracker {
public:
PreprocessorTrackerImpl()
: CurrentInclusionPathHandle(InclusionPathHandleInvalid) {}
: CurrentInclusionPathHandle(InclusionPathHandleInvalid),
InNestedHeader(false) {}
~PreprocessorTrackerImpl() {}
// Handle entering a preprocessing session.
@ -818,8 +819,12 @@ public:
if (HeaderPath.startswith("<"))
return;
HeaderHandle H = addHeader(HeaderPath);
if (H != getCurrentHeaderHandle())
if (H != getCurrentHeaderHandle()) {
// Check for nested header.
if (!InNestedHeader)
InNestedHeader = isHeaderHandleInStack(H);
pushHeaderHandle(H);
}
}
// Handle exiting a header source file.
void handleHeaderExit(llvm::StringRef HeaderPath) {
@ -831,6 +836,7 @@ public:
while ((H != getCurrentHeaderHandle()) && (HeaderStack.size() != 0))
popHeaderHandle();
}
InNestedHeader = false;
}
// Lookup/add string.
@ -839,11 +845,13 @@ public:
// Get the handle of a header file entry.
// Return HeaderHandleInvalid if not found.
HeaderHandle findHeaderHandle(llvm::StringRef HeaderPath) const {
std::string CanonicalPath(HeaderPath);
std::replace(CanonicalPath.begin(), CanonicalPath.end(), '\\', '/');
HeaderHandle H = 0;
for (std::vector<StringHandle>::const_iterator I = HeaderPaths.begin(),
E = HeaderPaths.end();
I != E; ++I, ++H) {
if (**I == HeaderPath)
if (**I == CanonicalPath)
return H;
}
return HeaderHandleInvalid;
@ -852,12 +860,12 @@ public:
// Add a new header file entry, or return existing handle.
// Return the header handle.
HeaderHandle addHeader(llvm::StringRef HeaderPath) {
std::string canonicalPath(HeaderPath);
std::replace(canonicalPath.begin(), canonicalPath.end(), '\\', '/');
HeaderHandle H = findHeaderHandle(canonicalPath);
std::string CanonicalPath(HeaderPath);
std::replace(CanonicalPath.begin(), CanonicalPath.end(), '\\', '/');
HeaderHandle H = findHeaderHandle(CanonicalPath);
if (H == HeaderHandleInvalid) {
H = HeaderPaths.size();
HeaderPaths.push_back(addString(canonicalPath));
HeaderPaths.push_back(addString(CanonicalPath));
}
return H;
}
@ -993,6 +1001,9 @@ public:
bool ConditionValue,
llvm::StringRef ConditionUnexpanded,
InclusionPathHandle InclusionPathHandle) {
// Ignore header guards, assuming the header guard is the only conditional.
if (InNestedHeader)
return;
StringHandle ConditionUnexpandedHandle(addString(ConditionUnexpanded));
PPItemKey InstanceKey(PP, ConditionUnexpandedHandle, H, InstanceLoc);
ConditionalExpansionMapIter I = ConditionalExpansions.find(InstanceKey);
@ -1002,7 +1013,8 @@ public:
getSourceLocationString(PP, InstanceLoc) + ":\n" +
getSourceLine(PP, InstanceLoc) + "\n";
ConditionalExpansions[InstanceKey] =
ConditionalTracker(DirectiveKind, ConditionValue, ConditionUnexpandedHandle,
ConditionalTracker(DirectiveKind, ConditionValue,
ConditionUnexpandedHandle,
InclusionPathHandle);
} else {
// We've seen the conditional before. Get its tracker.
@ -1157,6 +1169,7 @@ private:
InclusionPathHandle CurrentInclusionPathHandle;
MacroExpansionMap MacroExpansions;
ConditionalExpansionMap ConditionalExpansions;
bool InNestedHeader;
};
// PreprocessorTracker functions.
@ -1180,10 +1193,12 @@ void PreprocessorCallbacks::FileChanged(
PPTracker.handleHeaderEntry(PP, getSourceLocationFile(PP, Loc));
break;
case ExitFile:
if (PrevFID.isInvalid())
PPTracker.handleHeaderExit(RootHeaderFile);
else
PPTracker.handleHeaderExit(getSourceLocationFile(PP, Loc));
{
const clang::FileEntry *F =
PP.getSourceManager().getFileEntryForID(PrevFID);
if (F != NULL)
PPTracker.handleHeaderExit(F->getName());
}
break;
case SystemHeaderPragma:
case RenameFile: