diff options
author | ed <ed@FreeBSD.org> | 2009-06-27 10:45:02 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2009-06-27 10:45:02 +0000 |
commit | c1ff020ff2d3e7ba86f7ab986ac7569c34f2ab1a (patch) | |
tree | 2c5a83521a20c02e7805581a174008aa9bc23579 /lib/Basic | |
parent | 14660dbe9881f68a6cc2b9f014e1fb7b7228bca4 (diff) | |
download | FreeBSD-src-c1ff020ff2d3e7ba86f7ab986ac7569c34f2ab1a.zip FreeBSD-src-c1ff020ff2d3e7ba86f7ab986ac7569c34f2ab1a.tar.gz |
Import Clang r74383.
Diffstat (limited to 'lib/Basic')
-rw-r--r-- | lib/Basic/IdentifierTable.cpp | 4 | ||||
-rw-r--r-- | lib/Basic/SourceManager.cpp | 103 | ||||
-rw-r--r-- | lib/Basic/Targets.cpp | 2 |
3 files changed, 106 insertions, 3 deletions
diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp index cf78da98..d13ffa3 100644 --- a/lib/Basic/IdentifierTable.cpp +++ b/lib/Basic/IdentifierTable.cpp @@ -66,7 +66,8 @@ namespace { KEYCXX = 4, KEYCXX0X = 8, KEYGNU = 16, - KEYMS = 32 + KEYMS = 32, + BOOLSUPPORT = 64 }; } @@ -88,6 +89,7 @@ static void AddKeyword(const char *Keyword, unsigned KWLen, else if (LangOpts.C99 && (Flags & KEYC99)) AddResult = 2; else if (LangOpts.GNUMode && (Flags & KEYGNU)) AddResult = 1; else if (LangOpts.Microsoft && (Flags & KEYMS)) AddResult = 1; + else if (LangOpts.OpenCL && (Flags & BOOLSUPPORT)) AddResult = 2; // Don't add this keyword if disabled in this language. if (AddResult == 0) return; diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 23a01c9..6640c61 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -943,7 +943,7 @@ SourceLocation SourceManager::getLocation(const FileEntry *SourceFile, return SourceLocation(); unsigned FilePos = Content->SourceLineCache[Line - 1]; - const char *Buf = Content->getBuffer()->getBufferStart(); + const char *Buf = Content->getBuffer()->getBufferStart() + FilePos; unsigned BufLength = Content->getBuffer()->getBufferEnd() - Buf; unsigned i = 0; @@ -957,6 +957,107 @@ SourceLocation SourceManager::getLocation(const FileEntry *SourceFile, getFileLocWithOffset(FilePos + Col - 1); } +/// \brief Determines the order of 2 source locations in the translation unit. +/// +/// \returns true if LHS source location comes before RHS, false otherwise. +bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, + SourceLocation RHS) const { + assert(LHS.isValid() && RHS.isValid() && "Passed invalid source location!"); + if (LHS == RHS) + return false; + + std::pair<FileID, unsigned> LOffs = getDecomposedLoc(LHS); + std::pair<FileID, unsigned> ROffs = getDecomposedLoc(RHS); + + // If the source locations are in the same file, just compare offsets. + if (LOffs.first == ROffs.first) + return LOffs.second < ROffs.second; + + // If we are comparing a source location with multiple locations in the same + // file, we get a big win by caching the result. + + if (LastLFIDForBeforeTUCheck == LOffs.first && + LastRFIDForBeforeTUCheck == ROffs.first) + return LastResForBeforeTUCheck; + + LastLFIDForBeforeTUCheck = LOffs.first; + LastRFIDForBeforeTUCheck = ROffs.first; + + // "Traverse" the include/instantiation stacks of both locations and try to + // find a common "ancestor". + // + // First we traverse the stack of the right location and check each level + // against the level of the left location, while collecting all levels in a + // "stack map". + + std::map<FileID, unsigned> ROffsMap; + ROffsMap[ROffs.first] = ROffs.second; + + while (1) { + SourceLocation UpperLoc; + const SrcMgr::SLocEntry &Entry = getSLocEntry(ROffs.first); + if (Entry.isInstantiation()) + UpperLoc = Entry.getInstantiation().getInstantiationLocStart(); + else + UpperLoc = Entry.getFile().getIncludeLoc(); + + if (UpperLoc.isInvalid()) + break; // We reached the top. + + ROffs = getDecomposedLoc(UpperLoc); + + if (LOffs.first == ROffs.first) + return LastResForBeforeTUCheck = LOffs.second < ROffs.second; + + ROffsMap[ROffs.first] = ROffs.second; + } + + // We didn't find a common ancestor. Now traverse the stack of the left + // location, checking against the stack map of the right location. + + while (1) { + SourceLocation UpperLoc; + const SrcMgr::SLocEntry &Entry = getSLocEntry(LOffs.first); + if (Entry.isInstantiation()) + UpperLoc = Entry.getInstantiation().getInstantiationLocStart(); + else + UpperLoc = Entry.getFile().getIncludeLoc(); + + if (UpperLoc.isInvalid()) + break; // We reached the top. + + LOffs = getDecomposedLoc(UpperLoc); + + std::map<FileID, unsigned>::iterator I = ROffsMap.find(LOffs.first); + if (I != ROffsMap.end()) + return LastResForBeforeTUCheck = LOffs.second < I->second; + } + + // No common ancestor. + // Now we are getting into murky waters. Most probably this is because one + // location is in the predefines buffer. + + const FileEntry *LEntry = + getSLocEntry(LOffs.first).getFile().getContentCache()->Entry; + const FileEntry *REntry = + getSLocEntry(ROffs.first).getFile().getContentCache()->Entry; + + // If the locations are in two memory buffers we give up, we can't answer + // which one should be considered first. + // FIXME: Should there be a way to "include" memory buffers in the translation + // unit ? + assert((LEntry != 0 || REntry != 0) && "Locations in memory buffers."); + (void) REntry; + + // Consider the memory buffer as coming before the file in the translation + // unit. + if (LEntry == 0) + return LastResForBeforeTUCheck = true; + else { + assert(REntry == 0 && "Locations in not #included files ?"); + return LastResForBeforeTUCheck = false; + } +} /// PrintStats - Print statistics to stderr. /// diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 1d69e4e..9910e28 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -930,7 +930,7 @@ public: WindowsX86_32TargetInfo(const std::string& triple) : X86_32TargetInfo(triple) { TLSSupported = false; - WCharType = SignedShort; + WCharType = UnsignedShort; WCharWidth = WCharAlign = 16; DoubleAlign = LongLongAlign = 64; DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |