aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Frontend/FixItRewriter.h3
-rw-r--r--include/clang/Frontend/TextDiagnosticPrinter.h17
-rw-r--r--include/clang/Lex/Lexer.h3
-rw-r--r--include/clang/Rewrite/Rewriter.h16
-rw-r--r--lib/Frontend/FixItRewriter.cpp5
-rw-r--r--lib/Frontend/HTMLDiagnostics.cpp8
-rw-r--r--lib/Frontend/PCHReader.cpp7
-rw-r--r--lib/Frontend/PlistDiagnostics.cpp94
-rw-r--r--lib/Frontend/TextDiagnosticPrinter.cpp4
-rw-r--r--lib/Lex/Lexer.cpp8
-rw-r--r--lib/Lex/Preprocessor.cpp2
-rw-r--r--lib/Rewrite/HTMLRewrite.cpp2
-rw-r--r--lib/Rewrite/Rewriter.cpp6
-rw-r--r--tools/clang-cc/HTMLPrint.cpp2
-rw-r--r--tools/clang-cc/RewriteBlocks.cpp2
-rw-r--r--tools/clang-cc/RewriteMacros.cpp2
-rw-r--r--tools/clang-cc/RewriteObjC.cpp8
-rw-r--r--tools/clang-cc/clang-cc.cpp90
18 files changed, 159 insertions, 120 deletions
diff --git a/include/clang/Frontend/FixItRewriter.h b/include/clang/Frontend/FixItRewriter.h
index 363b9ad9a3..7fcd682bf6 100644
--- a/include/clang/Frontend/FixItRewriter.h
+++ b/include/clang/Frontend/FixItRewriter.h
@@ -57,7 +57,8 @@ class FixItRewriter : public DiagnosticClient {
public:
/// \brief Initialize a new fix-it rewriter.
- FixItRewriter(Diagnostic &Diags, SourceManager &SourceMgr);
+ FixItRewriter(Diagnostic &Diags, SourceManager &SourceMgr,
+ const LangOptions &LangOpts);
/// \brief Destroy the fix-it rewriter.
~FixItRewriter();
diff --git a/include/clang/Frontend/TextDiagnosticPrinter.h b/include/clang/Frontend/TextDiagnosticPrinter.h
index 0f08a95283..f0cc4a0ca0 100644
--- a/include/clang/Frontend/TextDiagnosticPrinter.h
+++ b/include/clang/Frontend/TextDiagnosticPrinter.h
@@ -24,28 +24,37 @@ namespace llvm {
namespace clang {
class SourceManager;
+class LangOptions;
class TextDiagnosticPrinter : public DiagnosticClient {
+ llvm::raw_ostream &OS;
+ const LangOptions *LangOpts;
SourceLocation LastWarningLoc;
FullSourceLoc LastLoc;
bool LastCaretDiagnosticWasNote;
- llvm::raw_ostream &OS;
+
bool ShowColumn;
bool CaretDiagnostics;
bool ShowLocation;
bool PrintRangeInfo;
public:
- TextDiagnosticPrinter(llvm::raw_ostream &os, bool showColumn = true,
+ TextDiagnosticPrinter(llvm::raw_ostream &os,
+ bool showColumn = true,
bool caretDiagnistics = true, bool showLocation = true,
bool printRangeInfo = true)
- : LastCaretDiagnosticWasNote(false), OS(os), ShowColumn(showColumn),
+ : OS(os), LangOpts(0),
+ LastCaretDiagnosticWasNote(false), ShowColumn(showColumn),
CaretDiagnostics(caretDiagnistics), ShowLocation(showLocation),
PrintRangeInfo(printRangeInfo) {}
+ void SetLangOpts(const LangOptions &LO) {
+ LangOpts = &LO;
+ }
+
void PrintIncludeStack(SourceLocation Loc, const SourceManager &SM);
void HighlightRange(const SourceRange &R,
- const SourceManager& SrcMgr,
+ const SourceManager &SrcMgr,
unsigned LineNo, FileID FID,
std::string &CaretLine,
const std::string &SourceLine);
diff --git a/include/clang/Lex/Lexer.h b/include/clang/Lex/Lexer.h
index 8077934a61..61a532ac53 100644
--- a/include/clang/Lex/Lexer.h
+++ b/include/clang/Lex/Lexer.h
@@ -211,7 +211,8 @@ public:
/// includes a trigraph or an escaped newline) then this count includes bytes
/// that are part of that.
static unsigned MeasureTokenLength(SourceLocation Loc,
- const SourceManager &SM);
+ const SourceManager &SM,
+ const LangOptions &LangOpts);
//===--------------------------------------------------------------------===//
// Internal implementation interfaces.
diff --git a/include/clang/Rewrite/Rewriter.h b/include/clang/Rewrite/Rewriter.h
index b05770b2aa..afa018d9cb 100644
--- a/include/clang/Rewrite/Rewriter.h
+++ b/include/clang/Rewrite/Rewriter.h
@@ -25,6 +25,7 @@
namespace clang {
class SourceManager;
+ class LangOptions;
class Rewriter;
class Stmt;
@@ -117,14 +118,19 @@ private: // Methods only usable by Rewriter.
/// are involved.
class Rewriter {
SourceManager *SourceMgr;
-
+ const LangOptions *LangOpts;
std::map<FileID, RewriteBuffer> RewriteBuffers;
public:
- explicit Rewriter(SourceManager &SM) : SourceMgr(&SM) {}
- explicit Rewriter() : SourceMgr(0) {}
+ explicit Rewriter(SourceManager &SM, const LangOptions &LO)
+ : SourceMgr(&SM), LangOpts(&LO) {}
+ explicit Rewriter() : SourceMgr(0), LangOpts(0) {}
- void setSourceMgr(SourceManager &SM) { SourceMgr = &SM; }
- SourceManager& getSourceMgr() { return *SourceMgr; }
+ void setSourceMgr(SourceManager &SM, const LangOptions &LO) {
+ SourceMgr = &SM;
+ LangOpts = &LO;
+ }
+ SourceManager &getSourceMgr() { return *SourceMgr; }
+ const LangOptions &getLangOpts() { return *LangOpts; }
/// isRewritable - Return true if this location is a raw file location, which
/// is rewritable. Locations from macros, etc are not rewritable.
diff --git a/lib/Frontend/FixItRewriter.cpp b/lib/Frontend/FixItRewriter.cpp
index 6fde5dae75..1ed89d75a9 100644
--- a/lib/Frontend/FixItRewriter.cpp
+++ b/lib/Frontend/FixItRewriter.cpp
@@ -22,8 +22,9 @@
#include "llvm/System/Path.h"
using namespace clang;
-FixItRewriter::FixItRewriter(Diagnostic &Diags, SourceManager &SourceMgr)
- : Diags(Diags), Rewrite(SourceMgr), NumFailures(0) {
+FixItRewriter::FixItRewriter(Diagnostic &Diags, SourceManager &SourceMgr,
+ const LangOptions &LangOpts)
+ : Diags(Diags), Rewrite(SourceMgr, LangOpts), NumFailures(0) {
Client = Diags.getClient();
Diags.setClient(this);
}
diff --git a/lib/Frontend/HTMLDiagnostics.cpp b/lib/Frontend/HTMLDiagnostics.cpp
index 83c2ac56a7..752d41fb4c 100644
--- a/lib/Frontend/HTMLDiagnostics.cpp
+++ b/lib/Frontend/HTMLDiagnostics.cpp
@@ -163,7 +163,7 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) {
return; // FIXME: Emit a warning?
// Create a new rewriter to generate HTML.
- Rewriter R(const_cast<SourceManager&>(SMgr));
+ Rewriter R(const_cast<SourceManager&>(SMgr), PP->getLangOptions());
// Process the path.
unsigned n = D.size();
@@ -574,8 +574,8 @@ void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID,
SourceRange Range,
const char *HighlightStart,
const char *HighlightEnd) {
-
- SourceManager& SM = R.getSourceMgr();
+ SourceManager &SM = R.getSourceMgr();
+ const LangOptions &LangOpts = R.getLangOpts();
SourceLocation InstantiationStart = SM.getInstantiationLoc(Range.getBegin());
unsigned StartLineNo = SM.getInstantiationLineNumber(InstantiationStart);
@@ -596,7 +596,7 @@ void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID,
if (EndColNo) {
// Add in the length of the token, so that we cover multi-char tokens.
- EndColNo += Lexer::MeasureTokenLength(Range.getEnd(), SM) - 1;
+ EndColNo += Lexer::MeasureTokenLength(Range.getEnd(), SM, LangOpts)-1;
}
// Highlight the range. Make the span tag the outermost tag for the
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index bc754cb845..b0b35e491b 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -482,14 +482,15 @@ PCHReader::PCHReadResult PCHReader::ReadSourceManagerBlock() {
SourceLocation::getFromRawEncoding(Record[2]),
SourceLocation::getFromRawEncoding(Record[3]),
Lexer::MeasureTokenLength(SpellingLoc,
- SourceMgr));
+ SourceMgr,
+ PP.getLangOptions()));
break;
}
- case pch::SM_LINE_TABLE: {
+ case pch::SM_LINE_TABLE:
if (ParseLineTable(SourceMgr, Record))
return Failure;
- }
+ break;
}
}
}
diff --git a/lib/Frontend/PlistDiagnostics.cpp b/lib/Frontend/PlistDiagnostics.cpp
index d87a8f189f..726248431f 100644
--- a/lib/Frontend/PlistDiagnostics.cpp
+++ b/lib/Frontend/PlistDiagnostics.cpp
@@ -15,7 +15,7 @@
#include "clang/Analysis/PathDiagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/FileManager.h"
-#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Casting.h"
@@ -36,8 +36,9 @@ namespace {
class VISIBILITY_HIDDEN PlistDiagnostics : public PathDiagnosticClient {
std::vector<const PathDiagnostic*> BatchedDiags;
const std::string OutputFile;
+ const LangOptions &LangOpts;
public:
- PlistDiagnostics(const std::string& prefix);
+ PlistDiagnostics(const std::string& prefix, const LangOptions &LangOpts);
~PlistDiagnostics();
void HandlePathDiagnostic(const PathDiagnostic* D);
@@ -47,13 +48,14 @@ namespace {
};
} // end anonymous namespace
-PlistDiagnostics::PlistDiagnostics(const std::string& output)
- : OutputFile(output) {}
+PlistDiagnostics::PlistDiagnostics(const std::string& output,
+ const LangOptions &LO)
+ : OutputFile(output), LangOpts(LO) {}
PathDiagnosticClient*
clang::CreatePlistDiagnosticClient(const std::string& s,
- Preprocessor*, PreprocessorFactory*) {
- return new PlistDiagnostics(s);
+ Preprocessor *PP, PreprocessorFactory*) {
+ return new PlistDiagnostics(s, PP->getLangOptions());
}
static void AddFID(FIDMap &FIDs, llvm::SmallVectorImpl<FileID> &V,
@@ -66,9 +68,9 @@ static void AddFID(FIDMap &FIDs, llvm::SmallVectorImpl<FileID> &V,
V.push_back(FID);
}
-static unsigned GetFID(const FIDMap& FIDs, const SourceManager* SM,
+static unsigned GetFID(const FIDMap& FIDs, const SourceManager &SM,
SourceLocation L) {
- FileID FID = SM->getFileID(SM->getInstantiationLoc(L));
+ FileID FID = SM.getFileID(SM.getInstantiationLoc(L));
FIDMap::const_iterator I = FIDs.find(FID);
assert(I != FIDs.end());
return I->second;
@@ -79,14 +81,16 @@ static llvm::raw_ostream& Indent(llvm::raw_ostream& o, const unsigned indent) {
return o;
}
-static void EmitLocation(llvm::raw_ostream& o, const SourceManager* SM,
- SourceLocation L, const FIDMap& FM,
- const unsigned indent, bool extend = false) {
+static void EmitLocation(llvm::raw_ostream& o, const SourceManager &SM,
+ const LangOptions &LangOpts,
+ SourceLocation L, const FIDMap &FM,
+ unsigned indent, bool extend = false) {
- FullSourceLoc Loc(SM->getInstantiationLoc(L), const_cast<SourceManager&>(*SM));
+ FullSourceLoc Loc(SM.getInstantiationLoc(L), const_cast<SourceManager&>(SM));
// Add in the length of the token, so that we cover multi-char tokens.
- unsigned offset = extend ? Lexer::MeasureTokenLength(Loc, *SM) - 1 : 0;
+ unsigned offset =
+ extend ? Lexer::MeasureTokenLength(Loc, SM, LangOpts) - 1 : 0;
Indent(o, indent) << "<dict>\n";
Indent(o, indent) << " <key>line</key><integer>"
@@ -98,19 +102,20 @@ static void EmitLocation(llvm::raw_ostream& o, const SourceManager* SM,
Indent(o, indent) << "</dict>\n";
}
-static void EmitLocation(llvm::raw_ostream& o, const SourceManager* SM,
+static void EmitLocation(llvm::raw_ostream& o, const SourceManager &SM,
+ const LangOptions &LangOpts,
const PathDiagnosticLocation &L, const FIDMap& FM,
- const unsigned indent, bool extend = false) {
- EmitLocation(o, SM, L.asLocation(), FM, indent, extend);
+ unsigned indent, bool extend = false) {
+ EmitLocation(o, SM, LangOpts, L.asLocation(), FM, indent, extend);
}
-static void EmitRange(llvm::raw_ostream& o, const SourceManager* SM,
- SourceRange R, const FIDMap& FM,
- const unsigned indent) {
-
+static void EmitRange(llvm::raw_ostream& o, const SourceManager &SM,
+ const LangOptions &LangOpts,
+ SourceRange R, const FIDMap &FM,
+ unsigned indent) {
Indent(o, indent) << "<array>\n";
- EmitLocation(o, SM, R.getBegin(), FM, indent+1);
- EmitLocation(o, SM, R.getEnd(), FM, indent+1, true);
+ EmitLocation(o, SM, LangOpts, R.getBegin(), FM, indent+1);
+ EmitLocation(o, SM, LangOpts, R.getEnd(), FM, indent+1, true);
Indent(o, indent) << "</array>\n";
}
@@ -134,7 +139,9 @@ static llvm::raw_ostream& EmitString(llvm::raw_ostream& o,
static void ReportControlFlow(llvm::raw_ostream& o,
const PathDiagnosticControlFlowPiece& P,
- const FIDMap& FM, const SourceManager *SM,
+ const FIDMap& FM,
+ const SourceManager &SM,
+ const LangOptions &LangOpts,
unsigned indent) {
Indent(o, indent) << "<dict>\n";
@@ -145,9 +152,9 @@ static void ReportControlFlow(llvm::raw_ostream& o,
// FIXME: Eventually remove (DEPRECATED)
// Output the start and end locations.
Indent(o, indent) << "<key>start</key>\n";
- EmitLocation(o, SM, P.getStartLocation(), FM, indent);
+ EmitLocation(o, SM, LangOpts, P.getStartLocation(), FM, indent);
Indent(o, indent) << "<key>end</key>\n";
- EmitLocation(o, SM, P.getEndLocation(), FM, indent);
+ EmitLocation(o, SM, LangOpts, P.getEndLocation(), FM, indent);
// Emit edges.
Indent(o, indent) << "<key>edges</key>\n";
@@ -159,9 +166,9 @@ static void ReportControlFlow(llvm::raw_ostream& o,
Indent(o, indent) << "<dict>\n";
++indent;
Indent(o, indent) << "<key>start</key>\n";
- EmitRange(o, SM, I->getStart().asRange(), FM, indent+1);
+ EmitRange(o, SM, LangOpts, I->getStart().asRange(), FM, indent+1);
Indent(o, indent) << "<key>end</key>\n";
- EmitRange(o, SM, I->getEnd().asRange(), FM, indent+1);
+ EmitRange(o, SM, LangOpts, I->getEnd().asRange(), FM, indent+1);
--indent;
Indent(o, indent) << "</dict>\n";
}
@@ -181,7 +188,9 @@ static void ReportControlFlow(llvm::raw_ostream& o,
}
static void ReportEvent(llvm::raw_ostream& o, const PathDiagnosticPiece& P,
- const FIDMap& FM, const SourceManager* SM,
+ const FIDMap& FM,
+ const SourceManager &SM,
+ const LangOptions &LangOpts,
unsigned indent) {
Indent(o, indent) << "<dict>\n";
@@ -193,7 +202,7 @@ static void ReportEvent(llvm::raw_ostream& o, const PathDiagnosticPiece& P,
FullSourceLoc L = P.getLocation().asLocation();
Indent(o, indent) << "<key>location</key>\n";
- EmitLocation(o, SM, L, FM, indent);
+ EmitLocation(o, SM, LangOpts, L, FM, indent);
// Output the ranges (if any).
PathDiagnosticPiece::range_iterator RI = P.ranges_begin(),
@@ -203,7 +212,8 @@ static void ReportEvent(llvm::raw_ostream& o, const PathDiagnosticPiece& P,
Indent(o, indent) << "<key>ranges</key>\n";
Indent(o, indent) << "<array>\n";
++indent;
- for ( ; RI != RE; ++RI ) EmitRange(o, SM, *RI, FM, indent+1);
+ for (; RI != RE; ++RI)
+ EmitRange(o, SM, LangOpts, *RI, FM, indent+1);
--indent;
Indent(o, indent) << "</array>\n";
}
@@ -226,7 +236,8 @@ static void ReportEvent(llvm::raw_ostream& o, const PathDiagnosticPiece& P,
static void ReportMacro(llvm::raw_ostream& o,
const PathDiagnosticMacroPiece& P,
- const FIDMap& FM, const SourceManager *SM,
+ const FIDMap& FM, const SourceManager &SM,
+ const LangOptions &LangOpts,
unsigned indent) {
for (PathDiagnosticMacroPiece::const_iterator I=P.begin(), E=P.end();
@@ -236,30 +247,35 @@ static void ReportMacro(llvm::raw_ostream& o,
default:
break;
case PathDiagnosticPiece::Event:
- ReportEvent(o, cast<PathDiagnosticEventPiece>(**I), FM, SM, indent);
+ ReportEvent(o, cast<PathDiagnosticEventPiece>(**I), FM, SM, LangOpts,
+ indent);
break;
case PathDiagnosticPiece::Macro:
- ReportMacro(o, cast<PathDiagnosticMacroPiece>(**I), FM, SM, indent);
+ ReportMacro(o, cast<PathDiagnosticMacroPiece>(**I), FM, SM, LangOpts,
+ indent);
break;
}
}
}
static void ReportDiag(llvm::raw_ostream& o, const PathDiagnosticPiece& P,
- const FIDMap& FM, const SourceManager* SM) {
+ const FIDMap& FM, const SourceManager &SM,
+ const LangOptions &LangOpts) {
unsigned indent = 4;
switch (P.getKind()) {
case PathDiagnosticPiece::ControlFlow:
ReportControlFlow(o, cast<PathDiagnosticControlFlowPiece>(P), FM, SM,
- indent);
+ LangOpts, indent);
break;
case PathDiagnosticPiece::Event:
- ReportEvent(o, cast<PathDiagnosticEventPiece>(P), FM, SM, indent);
+ ReportEvent(o, cast<PathDiagnosticEventPiece>(P), FM, SM, LangOpts,
+ indent);
break;
case PathDiagnosticPiece::Macro:
- ReportMacro(o, cast<PathDiagnosticMacroPiece>(P), FM, SM, indent);
+ ReportMacro(o, cast<PathDiagnosticMacroPiece>(P), FM, SM, LangOpts,
+ indent);
break;
}
}
@@ -352,7 +368,7 @@ PlistDiagnostics::~PlistDiagnostics() {
o << " <array>\n";
for (PathDiagnostic::const_iterator I=D->begin(), E=D->end(); I != E; ++I)
- ReportDiag(o, *I, FM, SM);
+ ReportDiag(o, *I, FM, *SM, LangOpts);
o << " </array>\n";
@@ -366,7 +382,7 @@ PlistDiagnostics::~PlistDiagnostics() {
// Output the location of the bug.
o << " <key>location</key>\n";
- EmitLocation(o, SM, D->getLocation(), FM, 2);
+ EmitLocation(o, *SM, LangOpts, D->getLocation(), FM, 2);
// Close up the entry.
o << " </dict>\n";
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index f1555dbff3..c472a140cb 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -82,7 +82,7 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
--EndColNo; // Zero base the col #.
// Add in the length of the token, so that we cover multi-char tokens.
- EndColNo += Lexer::MeasureTokenLength(End, SM);
+ EndColNo += Lexer::MeasureTokenLength(End, SM, *LangOpts);
} else {
EndColNo = CaretLine.size();
}
@@ -281,7 +281,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
continue;
// Add in the length of the token, so that we cover multi-char tokens.
- unsigned TokSize = Lexer::MeasureTokenLength(E, SM);
+ unsigned TokSize = Lexer::MeasureTokenLength(E, SM, *LangOpts);
OS << '{' << SM.getLineNumber(BInfo.first, BInfo.second) << ':'
<< SM.getColumnNumber(BInfo.first, BInfo.second) << '-'
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index 059afe2182..d04b1c2b69 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -216,7 +216,8 @@ void Lexer::Stringify(llvm::SmallVectorImpl<char> &Str) {
/// includes a trigraph or an escaped newline) then this count includes bytes
/// that are part of that.
unsigned Lexer::MeasureTokenLength(SourceLocation Loc,
- const SourceManager &SM) {
+ const SourceManager &SM,
+ const LangOptions &LangOpts) {
// TODO: this could be special cased for common tokens like identifiers, ')',
// etc to make this faster, if it mattered. Just look at StrData[0] to handle
// all obviously single-char tokens. This could use
@@ -230,11 +231,6 @@ unsigned Lexer::MeasureTokenLength(SourceLocation Loc,
std::pair<const char *,const char *> Buffer = SM.getBufferData(LocInfo.first);
const char *StrData = Buffer.first+LocInfo.second;
- // Create a langops struct and enable trigraphs. This is sufficient for
- // measuring tokens.
- LangOptions LangOpts;
- LangOpts.Trigraphs = true;
-
// Create a lexer starting at the beginning of this token.
Lexer TheLexer(Loc, LangOpts, Buffer.first, StrData, Buffer.second);
Token TheTok;
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 2c9b0b937a..111409ff78 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -336,7 +336,7 @@ SourceLocation Preprocessor::getLocForEndOfToken(SourceLocation Loc) {
if (Loc.isInvalid() || !Loc.isFileID())
return SourceLocation();
- unsigned Len = Lexer::MeasureTokenLength(Loc, getSourceManager());
+ unsigned Len = Lexer::MeasureTokenLength(Loc, getSourceManager(), Features);
return AdvanceToTokenCharacter(Loc, Len);
}
diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp
index 9bb5d7cfd3..69dd03ad3f 100644
--- a/lib/Rewrite/HTMLRewrite.cpp
+++ b/lib/Rewrite/HTMLRewrite.cpp
@@ -41,7 +41,7 @@ void html::HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E,
unsigned EOffset = SM.getFileOffset(E);
// Include the whole end token in the range.
- EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr());
+ EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts());
HighlightRange(R.getEditBuffer(FID), BOffset, EOffset,
SM.getBufferData(FID).first, StartTag, EndTag);
diff --git a/lib/Rewrite/Rewriter.cpp b/lib/Rewrite/Rewriter.cpp
index 551fa1d491..805c61baed 100644
--- a/lib/Rewrite/Rewriter.cpp
+++ b/lib/Rewrite/Rewriter.cpp
@@ -93,7 +93,7 @@ int Rewriter::getRangeSize(SourceRange Range) const {
// Adjust the end offset to the end of the last token, instead of being the
// start of the last token.
- EndOff += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr);
+ EndOff += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr, *LangOpts);
return EndOff-StartOff;
}
@@ -127,7 +127,7 @@ std::string Rewriter::getRewritenText(SourceRange Range) const {
// Adjust the end offset to the end of the last token, instead of being the
// start of the last token.
- EndOff += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr);
+ EndOff += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr, *LangOpts);
return std::string(Ptr, Ptr+EndOff-StartOff);
}
@@ -137,7 +137,7 @@ std::string Rewriter::getRewritenText(SourceRange Range) const {
// Adjust the end offset to the end of the last token, instead of being the
// start of the last token.
- EndOff += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr);
+ EndOff += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr, *LangOpts);
// Advance the iterators to the right spot, yay for linear time algorithms.
RewriteBuffer::iterator Start = RB.begin();
diff --git a/tools/clang-cc/HTMLPrint.cpp b/tools/clang-cc/HTMLPrint.cpp
index b2bb29c9eb..0e15973939 100644
--- a/tools/clang-cc/HTMLPrint.cpp
+++ b/tools/clang-cc/HTMLPrint.cpp
@@ -52,7 +52,7 @@ ASTConsumer* clang::CreateHTMLPrinter(const std::string &OutFile,
}
void HTMLPrinter::Initialize(ASTContext &context) {
- R.setSourceMgr(context.getSourceManager());
+ R.setSourceMgr(context.getSourceManager(), context.getLangOptions());
}
HTMLPrinter::~HTMLPrinter() {
diff --git a/tools/clang-cc/RewriteBlocks.cpp b/tools/clang-cc/RewriteBlocks.cpp
index 3610da63c5..f1f53e41c5 100644
--- a/tools/clang-cc/RewriteBlocks.cpp
+++ b/tools/clang-cc/RewriteBlocks.cpp
@@ -198,7 +198,7 @@ void RewriteBlocks::Initialize(ASTContext &context) {
MainFileStart = MainBuf->getBufferStart();
MainFileEnd = MainBuf->getBufferEnd();
- Rewrite.setSourceMgr(Context->getSourceManager());
+ Rewrite.setSourceMgr(Context->getSourceManager(), LangOpts);
if (IsHeader)
Preamble = "#pragma once\n";
diff --git a/tools/clang-cc/RewriteMacros.cpp b/tools/clang-cc/RewriteMacros.cpp
index 149a73c44b..d601f865b6 100644
--- a/tools/clang-cc/RewriteMacros.cpp
+++ b/tools/clang-cc/RewriteMacros.cpp
@@ -90,7 +90,7 @@ void clang::RewriteMacrosInInput(Preprocessor &PP,const std::string &InFileName,
SourceManager &SM = PP.getSourceManager();
Rewriter Rewrite;
- Rewrite.setSourceMgr(SM);
+ Rewrite.setSourceMgr(SM, PP.getLangOptions());
RewriteBuffer &RB = Rewrite.getEditBuffer(SM.getMainFileID());
std::vector<Token> RawTokens;
diff --git a/tools/clang-cc/RewriteObjC.cpp b/tools/clang-cc/RewriteObjC.cpp
index 44c0eb3d98..41f532b287 100644
--- a/tools/clang-cc/RewriteObjC.cpp
+++ b/tools/clang-cc/RewriteObjC.cpp
@@ -455,7 +455,7 @@ void RewriteObjC::Initialize(ASTContext &context) {
MainFileStart = MainBuf->getBufferStart();
MainFileEnd = MainBuf->getBufferEnd();
- Rewrite.setSourceMgr(Context->getSourceManager());
+ Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOptions());
// declaring objc_selector outside the parameter list removes a silly
// scope related warning...
@@ -2673,7 +2673,7 @@ void RewriteObjC::SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl,
// have no ivars (thus not synthesized) then no need to synthesize this class.
if ((CDecl->isForwardDecl() || NumIvars == 0) &&
(!RCDecl || !ObjCSynthesizedStructs.count(RCDecl))) {
- endBuf += Lexer::MeasureTokenLength(LocEnd, *SM);
+ endBuf += Lexer::MeasureTokenLength(LocEnd, *SM, LangOpts);
ReplaceText(LocStart, endBuf-startBuf, Result.c_str(), Result.size());
return;
}
@@ -2708,7 +2708,7 @@ void RewriteObjC::SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl,
SourceLocation L = RCDecl ? CDecl->getSuperClassLoc() :
CDecl->getClassLoc();
const char *endHeader = SM->getCharacterData(L);
- endHeader += Lexer::MeasureTokenLength(L, *SM);
+ endHeader += Lexer::MeasureTokenLength(L, *SM, LangOpts);
if (CDecl->protocol_begin() != CDecl->protocol_end()) {
// advance to the end of the referenced protocols.
@@ -2770,7 +2770,7 @@ void RewriteObjC::SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl,
// Don't forget to add a ';'!!
InsertText(LocEnd.getFileLocWithOffset(1), ";", 1);
} else { // we don't have any instance variables - insert super struct.
- endBuf += Lexer::MeasureTokenLength(LocEnd, *SM);
+ endBuf += Lexer::MeasureTokenLength(LocEnd, *SM, LangOpts);
Result += " {\n struct ";
Result += RCDecl->getNameAsString();
Result += "_IMPL ";
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 3360649475..345a421585 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -387,6 +387,33 @@ static llvm::cl::opt<bool>
LangObjCXX("ObjC++", llvm::cl::desc("Set base language to Objective-C++"),
llvm::cl::Hidden);
+static llvm::cl::opt<bool>
+ObjCExclusiveGC("fobjc-gc-only",
+ llvm::cl::desc("Use GC exclusively for Objective-C related "
+ "memory management"));
+
+static llvm::cl::opt<bool>
+ObjCEnableGC("fobjc-gc",
+ llvm::cl::desc("Enable Objective-C garbage collection"));
+
+static llvm::cl::opt<LangOptions::VisibilityMode>
+SymbolVisibility("fvisibility",
+ llvm::cl::desc("Set the default symbol visibility:"),
+ llvm::cl::init(LangOptions::Default),
+ llvm::cl::values(clEnumValN(LangOptions::Default, "default",
+ "Use default symbol visibility"),
+ clEnumValN(LangOptions::Hidden, "hidden",
+ "Use hidden symbol visibility"),
+ clEnumValN(LangOptions::Protected,"protected",
+ "Use protected symbol visibility"),
+ clEnumValEnd));
+
+static llvm::cl::opt<bool>
+OverflowChecking("ftrapv",
+ llvm::cl::desc("Trap on integer overflow"),
+ llvm::cl::init(false));
+
+
/// InitializeBaseLanguage - Handle the -x foo options.
static void InitializeBaseLanguage() {
if (LangObjC)
@@ -481,6 +508,14 @@ static void InitializeLangOptions(LangOptions &Options, LangKind LK){
Options.CPlusPlus = 1;
break;
}
+
+ if (ObjCExclusiveGC)
+ Options.setGCMode(LangOptions::GCOnly);
+ else if (ObjCEnableGC)
+ Options.setGCMode(LangOptions::HybridGC);
+
+ Options.setVisibilityMode(SymbolVisibility);
+ Options.OverflowChecking = OverflowChecking;
}
/// LangStds - Language standards we support.
@@ -796,39 +831,6 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
Options.setMainFileName(MainFileName.c_str());
}
-static llvm::cl::opt<bool>
-ObjCExclusiveGC("fobjc-gc-only",
- llvm::cl::desc("Use GC exclusively for Objective-C related "
- "memory management"));
-
-static llvm::cl::opt<bool>
-ObjCEnableGC("fobjc-gc",
- llvm::cl::desc("Enable Objective-C garbage collection"));
-
-void InitializeGCMode(LangOptions &Options) {
- if (ObjCExclusiveGC)
- Options.setGCMode(LangOptions::GCOnly);
- else if (ObjCEnableGC)
- Options.setGCMode(LangOptions::HybridGC);
-}
-
-static llvm::cl::opt<LangOptions::VisibilityMode>
-SymbolVisibility("fvisibility",
- llvm::cl::desc("Set the default symbol visibility:"),
- llvm::cl::init(LangOptions::Default),
- llvm::cl::values(clEnumValN(LangOptions::Default, "default",
- "Use default symbol visibility"),
- clEnumValN(LangOptions::Hidden, "hidden",
- "Use hidden symbol visibility"),
- clEnumValN(LangOptions::Protected,"protected",
- "Use protected symbol visibility"),
- clEnumValEnd));
-
-static llvm::cl::opt<bool>
-OverflowChecking("ftrapv",
- llvm::cl::desc("Trap on integer overflow"),
- llvm::cl::init(false));
-
//===----------------------------------------------------------------------===//
// Target Triple Processing.
//===----------------------------------------------------------------------===//
@@ -2021,7 +2023,8 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
llvm::TimeRegion Timer(ClangFrontendTimer);
Consumer.reset(new ASTConsumer());
FixItRewrite = new FixItRewriter(PP.getDiagnostics(),
- PP.getSourceManager());
+ PP.getSourceManager(),
+ PP.getLangOptions());
break;
}
@@ -2034,7 +2037,8 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
// locations now.
if (!FixItRewrite)
FixItRewrite = new FixItRewriter(PP.getDiagnostics(),
- PP.getSourceManager());
+ PP.getSourceManager(),
+ PP.getLangOptions());
bool AddedFixitLocation = false;
for (unsigned Idx = 0, Last = FixItAtLocations.size();
@@ -2213,9 +2217,6 @@ int main(int argc, char **argv) {
if (InputFilenames.empty())
InputFilenames.push_back("-");
- // Create a file manager object to provide access to and cache the filesystem.
- FileManager FileMgr;
-
// Create the diagnostic client for reporting errors or for
// implementing -verify.
DiagnosticClient* TextDiagClient = 0;
@@ -2268,6 +2269,9 @@ int main(int argc, char **argv) {
llvm::OwningPtr<SourceManager> SourceMgr;
+ // Create a file manager object to provide access to and cache the filesystem.
+ FileManager FileMgr;
+