[cfe-commits] r69099 - in /cfe/trunk: include/clang/Frontend/ include/clang/Lex/ include/clang/Rewrite/ lib/Frontend/ lib/Lex/ lib/Rewrite/ tools/clang-cc/
Chris Lattner
sabre at nondot.org
Tue Apr 14 16:22:57 PDT 2009
Author: lattner
Date: Tue Apr 14 18:22:57 2009
New Revision: 69099
URL: http://llvm.org/viewvc/llvm-project?rev=69099&view=rev
Log:
Change Lexer::MeasureTokenLength to take a LangOptions reference.
This allows it to accurately measure tokens, so that we get:
t.cpp:8:13: error: unknown type name 'X'
static foo::X P;
~~~~~^
instead of the woefully inferior:
t.cpp:8:13: error: unknown type name 'X'
static foo::X P;
~~~~ ^
Most of this is just plumbing to push the reference around.
Modified:
cfe/trunk/include/clang/Frontend/FixItRewriter.h
cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
cfe/trunk/include/clang/Lex/Lexer.h
cfe/trunk/include/clang/Rewrite/Rewriter.h
cfe/trunk/lib/Frontend/FixItRewriter.cpp
cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PlistDiagnostics.cpp
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
cfe/trunk/lib/Rewrite/Rewriter.cpp
cfe/trunk/tools/clang-cc/HTMLPrint.cpp
cfe/trunk/tools/clang-cc/RewriteBlocks.cpp
cfe/trunk/tools/clang-cc/RewriteMacros.cpp
cfe/trunk/tools/clang-cc/RewriteObjC.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/include/clang/Frontend/FixItRewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FixItRewriter.h?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FixItRewriter.h (original)
+++ cfe/trunk/include/clang/Frontend/FixItRewriter.h Tue Apr 14 18:22:57 2009
@@ -57,7 +57,8 @@
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();
Modified: cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h Tue Apr 14 18:22:57 2009
@@ -24,28 +24,37 @@
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);
Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Tue Apr 14 18:22:57 2009
@@ -211,7 +211,8 @@
/// 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.
Modified: cfe/trunk/include/clang/Rewrite/Rewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/Rewriter.h?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/include/clang/Rewrite/Rewriter.h (original)
+++ cfe/trunk/include/clang/Rewrite/Rewriter.h Tue Apr 14 18:22:57 2009
@@ -25,6 +25,7 @@
namespace clang {
class SourceManager;
+ class LangOptions;
class Rewriter;
class Stmt;
@@ -117,14 +118,19 @@
/// 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) {}
-
- void setSourceMgr(SourceManager &SM) { SourceMgr = &SM; }
- SourceManager& getSourceMgr() { return *SourceMgr; }
+ explicit Rewriter(SourceManager &SM, const LangOptions &LO)
+ : SourceMgr(&SM), LangOpts(&LO) {}
+ explicit Rewriter() : SourceMgr(0), LangOpts(0) {}
+
+ 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.
Modified: cfe/trunk/lib/Frontend/FixItRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FixItRewriter.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FixItRewriter.cpp (original)
+++ cfe/trunk/lib/Frontend/FixItRewriter.cpp Tue Apr 14 18:22:57 2009
@@ -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);
}
Modified: cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp Tue Apr 14 18:22:57 2009
@@ -163,7 +163,7 @@
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 @@
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 @@
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
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Tue Apr 14 18:22:57 2009
@@ -482,14 +482,15 @@
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;
}
}
}
Modified: cfe/trunk/lib/Frontend/PlistDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PlistDiagnostics.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PlistDiagnostics.cpp (original)
+++ cfe/trunk/lib/Frontend/PlistDiagnostics.cpp Tue Apr 14 18:22:57 2009
@@ -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 @@
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 @@
};
} // 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 @@
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 @@
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 @@
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 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 @@
// 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 @@
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 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 @@
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 @@
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 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 @@
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 @@
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 @@
// 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";
Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Tue Apr 14 18:22:57 2009
@@ -82,7 +82,7 @@
--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 @@
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) << '-'
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Tue Apr 14 18:22:57 2009
@@ -216,7 +216,8 @@
/// 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 @@
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;
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Tue Apr 14 18:22:57 2009
@@ -336,7 +336,7 @@
if (Loc.isInvalid() || !Loc.isFileID())
return SourceLocation();
- unsigned Len = Lexer::MeasureTokenLength(Loc, getSourceManager());
+ unsigned Len = Lexer::MeasureTokenLength(Loc, getSourceManager(), Features);
return AdvanceToTokenCharacter(Loc, Len);
}
Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Tue Apr 14 18:22:57 2009
@@ -41,7 +41,7 @@
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);
Modified: cfe/trunk/lib/Rewrite/Rewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Rewriter.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Rewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Rewriter.cpp Tue Apr 14 18:22:57 2009
@@ -93,7 +93,7 @@
// 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 @@
// 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 @@
// 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();
Modified: cfe/trunk/tools/clang-cc/HTMLPrint.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/HTMLPrint.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/HTMLPrint.cpp (original)
+++ cfe/trunk/tools/clang-cc/HTMLPrint.cpp Tue Apr 14 18:22:57 2009
@@ -52,7 +52,7 @@
}
void HTMLPrinter::Initialize(ASTContext &context) {
- R.setSourceMgr(context.getSourceManager());
+ R.setSourceMgr(context.getSourceManager(), context.getLangOptions());
}
HTMLPrinter::~HTMLPrinter() {
Modified: cfe/trunk/tools/clang-cc/RewriteBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/RewriteBlocks.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/RewriteBlocks.cpp (original)
+++ cfe/trunk/tools/clang-cc/RewriteBlocks.cpp Tue Apr 14 18:22:57 2009
@@ -198,7 +198,7 @@
MainFileStart = MainBuf->getBufferStart();
MainFileEnd = MainBuf->getBufferEnd();
- Rewrite.setSourceMgr(Context->getSourceManager());
+ Rewrite.setSourceMgr(Context->getSourceManager(), LangOpts);
if (IsHeader)
Preamble = "#pragma once\n";
Modified: cfe/trunk/tools/clang-cc/RewriteMacros.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/RewriteMacros.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/RewriteMacros.cpp (original)
+++ cfe/trunk/tools/clang-cc/RewriteMacros.cpp Tue Apr 14 18:22:57 2009
@@ -90,7 +90,7 @@
SourceManager &SM = PP.getSourceManager();
Rewriter Rewrite;
- Rewrite.setSourceMgr(SM);
+ Rewrite.setSourceMgr(SM, PP.getLangOptions());
RewriteBuffer &RB = Rewrite.getEditBuffer(SM.getMainFileID());
std::vector<Token> RawTokens;
Modified: cfe/trunk/tools/clang-cc/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/RewriteObjC.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/RewriteObjC.cpp (original)
+++ cfe/trunk/tools/clang-cc/RewriteObjC.cpp Tue Apr 14 18:22:57 2009
@@ -455,7 +455,7 @@
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 @@
// 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 @@
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 @@
// 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 ";
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=69099&r1=69098&r2=69099&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Tue Apr 14 18:22:57 2009
@@ -387,6 +387,33 @@
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 @@
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 @@
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 @@
llvm::TimeRegion Timer(ClangFrontendTimer);
Consumer.reset(new ASTConsumer());
FixItRewrite = new FixItRewriter(PP.getDiagnostics(),
- PP.getSourceManager());
+ PP.getSourceManager(),
+ PP.getLangOptions());
break;
}
@@ -2034,7 +2037,8 @@
// 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 @@
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 @@
llvm::OwningPtr<SourceManager> SourceMgr;
+ // Create a file manager object to provide access to and cache the filesystem.
+ FileManager FileMgr;
+
for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
const std::string &InFile = InputFilenames[i];
@@ -2286,17 +2290,21 @@
// Initialize language options, inferring file types from input filenames.
LangOptions LangInfo;
+
+ if (!VerifyDiagnostics)
+ static_cast<TextDiagnosticPrinter*>(TextDiagClient)
+ ->SetLangOpts(LangInfo);
+
+
InitializeBaseLanguage();
LangKind LK = GetLanguage(InFile);
InitializeLangOptions(LangInfo, LK);
- InitializeGCMode(LangInfo);
- LangInfo.setVisibilityMode(SymbolVisibility);
- LangInfo.OverflowChecking = OverflowChecking;
InitializeLanguageStandard(LangInfo, LK, Target.get());
// Process the -I options and set them in the HeaderInfo.
HeaderSearch HeaderInfo(FileMgr);
+
InitializeIncludePaths(argv[0], HeaderInfo, FileMgr, LangInfo);
// Set up the preprocessor with these options.
More information about the cfe-commits
mailing list