summaryrefslogtreecommitdiff
path: root/lib/Lex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Lex')
-rw-r--r--lib/Lex/Lexer.cpp8
-rw-r--r--lib/Lex/PPCaching.cpp2
-rw-r--r--lib/Lex/PPExpressions.cpp2
-rw-r--r--lib/Lex/PTHLexer.cpp40
-rw-r--r--lib/Lex/Preprocessor.cpp24
5 files changed, 40 insertions, 36 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index c8b9a5d5420a..f4a44324106a 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -384,10 +384,10 @@ static inline bool isNumberBody(unsigned char c) {
/// lexer buffer was all instantiated at a single point, perform the mapping.
/// This is currently only used for _Pragma implementation, so it is the slow
/// path of the hot getSourceLocation method. Do not allow it to be inlined.
-static SourceLocation GetMappedTokenLoc(Preprocessor &PP,
- SourceLocation FileLoc,
- unsigned CharNo,
- unsigned TokLen) DISABLE_INLINE;
+static DISABLE_INLINE SourceLocation GetMappedTokenLoc(Preprocessor &PP,
+ SourceLocation FileLoc,
+ unsigned CharNo,
+ unsigned TokLen);
static SourceLocation GetMappedTokenLoc(Preprocessor &PP,
SourceLocation FileLoc,
unsigned CharNo, unsigned TokLen) {
diff --git a/lib/Lex/PPCaching.cpp b/lib/Lex/PPCaching.cpp
index c3f0eeab5848..7c3780ffc0ac 100644
--- a/lib/Lex/PPCaching.cpp
+++ b/lib/Lex/PPCaching.cpp
@@ -109,6 +109,4 @@ void Preprocessor::AnnotatePreviousCachedTokens(const Token &Tok) {
return;
}
}
-
- assert(0&&"Didn't find the first token represented by the annotation token!");
}
diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp
index a74396c3146c..b54dfe093b2c 100644
--- a/lib/Lex/PPExpressions.cpp
+++ b/lib/Lex/PPExpressions.cpp
@@ -228,7 +228,7 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
return true; // A diagnostic was already emitted.
// Character literals are always int or wchar_t, expand to intmax_t.
- TargetInfo &TI = PP.getTargetInfo();
+ const TargetInfo &TI = PP.getTargetInfo();
unsigned NumBits;
if (Literal.isMultiChar())
NumBits = TI.getIntWidth();
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp
index f17a5d93a91a..d6a73cc74f6a 100644
--- a/lib/Lex/PTHLexer.cpp
+++ b/lib/Lex/PTHLexer.cpp
@@ -15,6 +15,7 @@
#include "clang/Basic/FileManager.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/OnDiskHashTable.h"
+#include "clang/Lex/LexDiagnostic.h"
#include "clang/Lex/PTHLexer.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PTHManager.h"
@@ -407,27 +408,17 @@ PTHManager::~PTHManager() {
free(PerIDCache);
}
-static void InvalidPTH(Diagnostic *Diags, Diagnostic::Level level,
- const char* Msg = 0) {
- if (!Diags) return;
- if (!Msg) Msg = "Invalid or corrupted PTH file";
- unsigned DiagID = Diags->getCustomDiagID(level, Msg);
- Diags->Report(FullSourceLoc(), DiagID);
+static void InvalidPTH(Diagnostic &Diags, const char *Msg) {
+ Diags.Report(Diags.getCustomDiagID(Diagnostic::Error, Msg));
}
-PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
- Diagnostic::Level level) {
+PTHManager* PTHManager::Create(const std::string& file, Diagnostic &Diags) {
// Memory map the PTH file.
llvm::OwningPtr<llvm::MemoryBuffer>
File(llvm::MemoryBuffer::getFile(file.c_str()));
if (!File) {
- if (Diags) {
- unsigned DiagID = Diags->getCustomDiagID(level,
- "PTH file %0 could not be read");
- Diags->Report(FullSourceLoc(), DiagID) << file;
- }
-
+ Diags.Report(diag::err_invalid_pth_file) << file;
return 0;
}
@@ -439,7 +430,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
// Check the prologue of the file.
if ((BufEnd - BufBeg) < (signed) (sizeof("cfe-pth") + 3 + 4) ||
memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth") - 1) != 0) {
- InvalidPTH(Diags, level);
+ Diags.Report(diag::err_invalid_pth_file) << file;
return 0;
}
@@ -447,8 +438,8 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
const unsigned char *p = BufBeg + (sizeof("cfe-pth") - 1);
unsigned Version = ReadLE32(p);
- if (Version != PTHManager::Version) {
- InvalidPTH(Diags, level,
+ if (Version < PTHManager::Version) {
+ InvalidPTH(Diags,
Version < PTHManager::Version
? "PTH file uses an older PTH format that is no longer supported"
: "PTH file uses a newer PTH format that cannot be read");
@@ -459,7 +450,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
const unsigned char *PrologueOffset = p;
if (PrologueOffset >= BufEnd) {
- InvalidPTH(Diags, level);
+ Diags.Report(diag::err_invalid_pth_file) << file;
return 0;
}
@@ -469,7 +460,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
const unsigned char* FileTable = BufBeg + ReadLE32(FileTableOffset);
if (!(FileTable > BufBeg && FileTable < BufEnd)) {
- InvalidPTH(Diags, level);
+ Diags.Report(diag::err_invalid_pth_file) << file;
return 0; // FIXME: Proper error diagnostic?
}
@@ -478,7 +469,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
// Warn if the PTH file is empty. We still want to create a PTHManager
// as the PTH could be used with -include-pth.
if (FL->isEmpty())
- InvalidPTH(Diags, level, "PTH file contains no cached source data");
+ InvalidPTH(Diags, "PTH file contains no cached source data");
// Get the location of the table mapping from persistent ids to the
// data needed to reconstruct identifiers.
@@ -486,7 +477,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
const unsigned char* IData = BufBeg + ReadLE32(IDTableOffset);
if (!(IData >= BufBeg && IData < BufEnd)) {
- InvalidPTH(Diags, level);
+ Diags.Report(diag::err_invalid_pth_file) << file;
return 0;
}
@@ -495,7 +486,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
const unsigned char* StringIdTableOffset = PrologueOffset + sizeof(uint32_t)*1;
const unsigned char* StringIdTable = BufBeg + ReadLE32(StringIdTableOffset);
if (!(StringIdTable >= BufBeg && StringIdTable < BufEnd)) {
- InvalidPTH(Diags, level);
+ Diags.Report(diag::err_invalid_pth_file) << file;
return 0;
}
@@ -506,7 +497,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
const unsigned char* spellingBaseOffset = PrologueOffset + sizeof(uint32_t)*3;
const unsigned char* spellingBase = BufBeg + ReadLE32(spellingBaseOffset);
if (!(spellingBase >= BufBeg && spellingBase < BufEnd)) {
- InvalidPTH(Diags, level);
+ Diags.Report(diag::err_invalid_pth_file) << file;
return 0;
}
@@ -521,8 +512,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
if (NumIds) {
PerIDCache = (IdentifierInfo**)calloc(NumIds, sizeof(*PerIDCache));
if (!PerIDCache) {
- InvalidPTH(Diags, level,
- "Could not allocate memory for processing PTH file");
+ InvalidPTH(Diags, "Could not allocate memory for processing PTH file");
return 0;
}
}
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 487b9d63c169..066909475fe3 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -44,14 +44,16 @@ using namespace clang;
//===----------------------------------------------------------------------===//
Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts,
- TargetInfo &target, SourceManager &SM,
+ const TargetInfo &target, SourceManager &SM,
HeaderSearch &Headers,
- IdentifierInfoLookup* IILookup)
+ IdentifierInfoLookup* IILookup,
+ bool OwnsHeaders)
: Diags(&diags), Features(opts), Target(target),FileMgr(Headers.getFileMgr()),
SourceMgr(SM), HeaderInfo(Headers), Identifiers(opts, IILookup),
BuiltinInfo(Target), CurPPLexer(0), CurDirLookup(0), Callbacks(0) {
ScratchBuf = new ScratchBuffer(SourceMgr);
CounterValue = 0; // __COUNTER__ starts at 0.
+ OwnsHeaderSearch = OwnsHeaders;
// Clear stats.
NumDirectives = NumDefined = NumUndefined = NumPragma = 0;
@@ -115,6 +117,10 @@ Preprocessor::~Preprocessor() {
// Delete the scratch buffer info.
delete ScratchBuf;
+ // Delete the header search info, if we own it.
+ if (OwnsHeaderSearch)
+ delete &HeaderInfo;
+
delete Callbacks;
}
@@ -186,13 +192,14 @@ void Preprocessor::PrintStats() {
// Token Spelling
//===----------------------------------------------------------------------===//
-
/// getSpelling() - Return the 'spelling' of this token. The spelling of a
/// token are the characters used to represent the token in the source file
/// after trigraph expansion and escaped-newline folding. In particular, this
/// wants to get the true, uncanonicalized, spelling of things like digraphs
/// UCNs, etc.
-std::string Preprocessor::getSpelling(const Token &Tok) const {
+std::string Preprocessor::getSpelling(const Token &Tok,
+ const SourceManager &SourceMgr,
+ const LangOptions &Features) {
assert((int)Tok.getLength() >= 0 && "Token character range is bogus!");
// If this token contains nothing interesting, return it directly.
@@ -215,6 +222,15 @@ std::string Preprocessor::getSpelling(const Token &Tok) const {
return Result;
}
+/// getSpelling() - Return the 'spelling' of this token. The spelling of a
+/// token are the characters used to represent the token in the source file
+/// after trigraph expansion and escaped-newline folding. In particular, this
+/// wants to get the true, uncanonicalized, spelling of things like digraphs
+/// UCNs, etc.
+std::string Preprocessor::getSpelling(const Token &Tok) const {
+ return getSpelling(Tok, SourceMgr, Features);
+}
+
/// getSpelling - This method is used to get the spelling of a token into a
/// preallocated buffer, instead of as an std::string. The caller is required
/// to allocate enough space for the token, which is guaranteed to be at least