aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-01-08 23:40:50 +0000
committerTed Kremenek <kremenek@apple.com>2009-01-08 23:40:50 +0000
commitf89f7f972320da3147a90108454fa231234d4557 (patch)
tree6700b030e8fb7f77fb940fea356bc2d05db46bbd
parentd4a5c9a3f8fe3512a0fbffb1b08c8048d1390cdf (diff)
PTH: For the cached spellings of literals, store one whitespace character after the spelling to accomodate sanity checking in LiteralSuppoert.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61956 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/CacheTokens.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/Driver/CacheTokens.cpp b/Driver/CacheTokens.cpp
index f1ab50ef98..6c0c5da7f1 100644
--- a/Driver/CacheTokens.cpp
+++ b/Driver/CacheTokens.cpp
@@ -29,7 +29,8 @@ using namespace clang;
typedef uint32_t Offset;
-typedef std::vector<std::pair<Offset, llvm::StringMapEntry<Offset>*> >
+typedef std::pair<Offset,bool> SpellingTy;
+typedef std::vector<std::pair<Offset, llvm::StringMapEntry<SpellingTy>*> >
SpellMapTy;
namespace {
@@ -55,7 +56,7 @@ public:
typedef llvm::DenseMap<const FileEntry*, PCHEntry> PCHMap;
typedef llvm::DenseMap<const IdentifierInfo*,uint32_t> IDMap;
-typedef llvm::StringMap<Offset, llvm::BumpPtrAllocator> CachedStrsTy;
+typedef llvm::StringMap< SpellingTy, llvm::BumpPtrAllocator> CachedStrsTy;
namespace {
class VISIBILITY_HIDDEN PTHWriter {
@@ -143,21 +144,31 @@ void PTHWriter::EmitToken(const Token& T) {
return;
switch (T.getKind()) {
- default:
- break;
- case tok::string_literal:
+ default: return;
+ case tok::numeric_constant:
+ case tok::string_literal:
case tok::wide_string_literal:
case tok::angle_string_literal:
- case tok::numeric_constant:
case tok::char_constant: {
// FIXME: This uses the slow getSpelling(). Perhaps we do better
// in the future? This only slows down PTH generation.
- const std::string& spelling = PP.getSpelling(T);
+ std::string spelling = PP.getSpelling(T);
+
+ // If the token is a numeric literal we add a space after the spelling.
+ // This is to handle a shortcoming in LiteralSupport.cpp where
+ // literals are assumed to have a "valid" character after them.
+ bool IsNumeric = T.getKind() == tok::numeric_constant;
+
+ if (IsNumeric)
+ spelling.push_back(' ');
+
const char* s = spelling.c_str();
// Get the string entry.
- llvm::StringMapEntry<Offset> *E =
- &CachedStrs.GetOrCreateValue(s, s+spelling.size());
+ llvm::StringMapEntry<std::pair<Offset,bool> > *E =
+ &CachedStrs.GetOrCreateValue(s, s + spelling.size());
+
+ E->getValue().second = IsNumeric;
// Store the address of the string entry in our spelling map.
(*CurSpellMap).push_back(std::make_pair(fpos, E));
@@ -405,14 +416,18 @@ void PTHWriter::EmitCachedSpellings() {
// Write out the length of the string before the string itself.
unsigned len = I->getKeyLength();
- Emit16(len);
+
+ // Adjust the length we write in the PTH file to accomodate for numeric
+ // literals. We implicitly have a space after them, but only want to later
+ // read the characters that are just part of the literal itself.
+ Emit16(I->getValue().second ? len - 1 : len);
// Write out the string data.
const char* data = I->getKeyData();
EmitBuf(data, data+len);
// Now patch the offset of the string in the PTH file into the string map.
- I->setValue(off);
+ I->getValue().first = off;
}
// Now emit the spelling tables.
@@ -429,7 +444,7 @@ void PTHWriter::EmitCachedSpellings() {
Emit32(spellings[i].first);
// Write out the offset of the spelling data within the PTH file.
- Emit32(spellings[i].second->getValue());
+ Emit32(spellings[i].second->getValue().first);
}
// Delete the spelling map for this source file.