diff options
| author | Ted Kremenek <kremenek@apple.com> | 2009-02-24 01:26:56 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2009-02-24 01:26:56 +0000 |
| commit | d6e190d899720736cb56d2a18596192cf8d15ad6 (patch) | |
| tree | 4aee5f5d12bf2e8eb7ae4081f07ba8846151cda4 | |
| parent | e62c0a45dd54045a523b6cf1c657d3bbc9a81404 (diff) | |
| download | bcm5719-llvm-d6e190d899720736cb56d2a18596192cf8d15ad6.tar.gz bcm5719-llvm-d6e190d899720736cb56d2a18596192cf8d15ad6.zip | |
PTH: Cache *un-cleaned* spellings for literals instead of cleaned spellings.
This allows the PTH file to stay 100% in fidelity with the source code and
defines away some weird cosmetic bugs for operations such as '-E' where
maintaining knowledge of the original literal representation is useful.
llvm-svn: 65361
| -rw-r--r-- | clang/Driver/CacheTokens.cpp | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/clang/Driver/CacheTokens.cpp b/clang/Driver/CacheTokens.cpp index 7813042c661..cf1ec5ac1a3 100644 --- a/clang/Driver/CacheTokens.cpp +++ b/clang/Driver/CacheTokens.cpp @@ -430,41 +430,31 @@ uint32_t PTHWriter::ResolveID(const IdentifierInfo* II) { } void PTHWriter::EmitToken(const Token& T) { - // We handle literals differently since their *cleaned* spellings are cached. + // Emit the token kind, flags, and length. + Emit32(((uint32_t) T.getKind()) | ((((uint32_t) T.getFlags())) << 8)| + (((uint32_t) T.getLength()) << 16)); + if (T.isLiteral()) { - // 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); - const char* s = spelling.c_str(); + // We cache *un-cleaned* spellings. This gives us 100% fidelity with the + // source code. + const char* s = T.getLiteralData(); + unsigned len = T.getLength(); // Get the string entry. - llvm::StringMapEntry<OffsetOpt> *E = - &CachedStrs.GetOrCreateValue(s, s+spelling.size()); + llvm::StringMapEntry<OffsetOpt> *E = &CachedStrs.GetOrCreateValue(s, s+len); + // If this is a new string entry, bump the PTH offset. if (!E->getValue().hasOffset()) { E->getValue().setOffset(CurStrOffset); StrEntries.push_back(E); - CurStrOffset += spelling.size() + 1; + CurStrOffset += len + 1; } - // Emit the token meta data with the cleaning bit reset and the - // length of the token equal to the cleaned spelling. - // Emit the token kind, flags, and length. - Emit32(((uint32_t) T.getKind()) | - ((((uint32_t) T.getFlags()) & ~((uint32_t)Token::NeedsCleaning)<<8))| - (((uint32_t) spelling.size()) << 16)); - // Emit the relative offset into the PTH file for the spelling string. Emit32(E->getValue().getOffset()); } - else { - // Emit the token kind, flags, and length. - Emit32(((uint32_t) T.getKind()) | - ((((uint32_t) T.getFlags())) << 8)| - (((uint32_t) T.getLength()) << 16)); - + else Emit32(ResolveID(T.getIdentifierInfo())); - } // Emit the offset into the original source file of this token so that we // can reconstruct its SourceLocation. |

