summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-12-12 22:39:36 +0000
committerTed Kremenek <kremenek@apple.com>2007-12-12 22:39:36 +0000
commit1daa3cfbae60569c33a0c695f10fb4ccf243a173 (patch)
treeca998daf9a0daf346031c7619359511c22ef4bef
parentf44cb63859352415ea2a1b3a04b51131eacf1d1f (diff)
downloadbcm5719-llvm-1daa3cfbae60569c33a0c695f10fb4ccf243a173.tar.gz
bcm5719-llvm-1daa3cfbae60569c33a0c695f10fb4ccf243a173.zip
TargetInfo no longer includes a reference to SourceManager.
Moved all clients of Diagnostics to use FullSourceLoc instead of SourceLocation. Added many utility methods to FullSourceLoc to provide shorthand for: FullLoc.getManager().someMethod(FullLoc.getLocation()); instead we have: FullLoc.someMethod(); Modified TextDiagnostics (and related classes) to use this short-hand. llvm-svn: 44957
-rw-r--r--clang/AST/ASTContext.cpp43
-rw-r--r--clang/AST/Expr.cpp4
-rw-r--r--clang/Analysis/DeadStores.cpp8
-rw-r--r--clang/Analysis/UninitializedValues.cpp4
-rw-r--r--clang/Basic/Diagnostic.cpp7
-rw-r--r--clang/Basic/SourceLocation.cpp42
-rw-r--r--clang/Basic/TargetInfo.cpp13
-rw-r--r--clang/Basic/Targets.cpp5
-rw-r--r--clang/CodeGen/CodeGenModule.cpp4
-rw-r--r--clang/Driver/RewriteTest.cpp3
-rw-r--r--clang/Driver/TextDiagnosticBuffer.cpp13
-rw-r--r--clang/Driver/TextDiagnosticBuffer.h6
-rw-r--r--clang/Driver/TextDiagnosticPrinter.cpp43
-rw-r--r--clang/Driver/TextDiagnosticPrinter.h13
-rw-r--r--clang/Driver/TextDiagnostics.cpp5
-rw-r--r--clang/Driver/TextDiagnostics.h6
-rw-r--r--clang/Driver/TranslationUnit.cpp5
-rw-r--r--clang/Driver/clang.cpp3
-rw-r--r--clang/Lex/LiteralSupport.cpp24
-rw-r--r--clang/Lex/PPExpressions.cpp20
-rw-r--r--clang/Lex/Preprocessor.cpp18
-rw-r--r--clang/Parse/Parser.cpp2
-rw-r--r--clang/Sema/Sema.cpp22
-rw-r--r--clang/Sema/SemaDecl.cpp21
-rw-r--r--clang/Sema/SemaExpr.cpp13
-rw-r--r--clang/include/clang/AST/ASTContext.h4
-rw-r--r--clang/include/clang/Basic/Diagnostic.h31
-rw-r--r--clang/include/clang/Basic/SourceLocation.h42
-rw-r--r--clang/include/clang/Basic/TargetInfo.h50
-rw-r--r--clang/include/clang/Parse/DeclSpec.h4
30 files changed, 291 insertions, 187 deletions
diff --git a/clang/AST/ASTContext.cpp b/clang/AST/ASTContext.cpp
index f50929de935..322f34ccf2d 100644
--- a/clang/AST/ASTContext.cpp
+++ b/clang/AST/ASTContext.cpp
@@ -128,7 +128,7 @@ void ASTContext::InitBuiltinTypes() {
// C99 6.2.5p2.
InitBuiltinType(BoolTy, BuiltinType::Bool);
// C99 6.2.5p3.
- if (Target.isCharSigned(SourceLocation()))
+ if (Target.isCharSigned(FullSourceLoc()))
InitBuiltinType(CharTy, BuiltinType::Char_S);
else
InitBuiltinType(CharTy, BuiltinType::Char_U);
@@ -213,26 +213,47 @@ ASTContext::getTypeInfo(QualType T, SourceLocation L) {
default: assert(0 && "Unknown builtin type!");
case BuiltinType::Void:
assert(0 && "Incomplete types have no size!");
- case BuiltinType::Bool: Target.getBoolInfo(Size, Align, L); break;
+ case BuiltinType::Bool: Target.getBoolInfo(Size,Align,getFullLoc(L));
+ break;
+
case BuiltinType::Char_S:
case BuiltinType::Char_U:
case BuiltinType::UChar:
- case BuiltinType::SChar: Target.getCharInfo(Size, Align, L); break;
+ case BuiltinType::SChar: Target.getCharInfo(Size,Align,getFullLoc(L));
+ break;
+
case BuiltinType::UShort:
- case BuiltinType::Short: Target.getShortInfo(Size, Align, L); break;
+ case BuiltinType::Short: Target.getShortInfo(Size,Align,getFullLoc(L));
+ break;
+
case BuiltinType::UInt:
- case BuiltinType::Int: Target.getIntInfo(Size, Align, L); break;
+ case BuiltinType::Int: Target.getIntInfo(Size,Align,getFullLoc(L));
+ break;
+
case BuiltinType::ULong:
- case BuiltinType::Long: Target.getLongInfo(Size, Align, L); break;
+ case BuiltinType::Long: Target.getLongInfo(Size,Align,getFullLoc(L));
+ break;
+
case BuiltinType::ULongLong:
- case BuiltinType::LongLong: Target.getLongLongInfo(Size, Align, L); break;
- case BuiltinType::Float: Target.getFloatInfo(Size, Align, F, L); break;
- case BuiltinType::Double: Target.getDoubleInfo(Size, Align, F, L);break;
- case BuiltinType::LongDouble:Target.getLongDoubleInfo(Size,Align,F,L);break;
+ case BuiltinType::LongLong: Target.getLongLongInfo(Size,Align,
+ getFullLoc(L));
+ break;
+
+ case BuiltinType::Float: Target.getFloatInfo(Size,Align,F,
+ getFullLoc(L));
+ break;
+
+ case BuiltinType::Double: Target.getDoubleInfo(Size,Align,F,
+ getFullLoc(L));
+ break;
+
+ case BuiltinType::LongDouble: Target.getLongDoubleInfo(Size,Align,F,
+ getFullLoc(L));
+ break;
}
break;
}
- case Type::Pointer: Target.getPointerInfo(Size, Align, L); break;
+ case Type::Pointer: Target.getPointerInfo(Size, Align, getFullLoc(L)); break;
case Type::Reference:
// "When applied to a reference or a reference type, the result is the size
// of the referenced type." C++98 5.3.3p2: expr.sizeof.
diff --git a/clang/AST/Expr.cpp b/clang/AST/Expr.cpp
index c6a6ab36014..11aef7f7d04 100644
--- a/clang/AST/Expr.cpp
+++ b/clang/AST/Expr.cpp
@@ -625,7 +625,9 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType(),
Exp->getOperatorLoc());
} else {
- unsigned CharSize = Ctx.Target.getCharWidth(Exp->getOperatorLoc());
+ unsigned CharSize =
+ Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc()));
+
Result = Ctx.getTypeSize(Exp->getSubExpr()->getType(),
Exp->getOperatorLoc()) / CharSize;
}
diff --git a/clang/Analysis/DeadStores.cpp b/clang/Analysis/DeadStores.cpp
index 80e5ba7b48e..836701049fc 100644
--- a/clang/Analysis/DeadStores.cpp
+++ b/clang/Analysis/DeadStores.cpp
@@ -40,8 +40,8 @@ public:
if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl()))
if (VD->hasLocalStorage() && !Live(VD,AD)) {
SourceRange R = B->getRHS()->getSourceRange();
- Diags.Report(DR->getSourceRange().getBegin(), diag::warn_dead_store,
- Ctx.getSourceManager(), 0, 0, &R, 1);
+ Diags.Report(Ctx.getFullLoc(DR->getSourceRange().getBegin()),
+ diag::warn_dead_store, 0, 0, &R, 1);
}
}
else if(DeclStmt* DS = dyn_cast<DeclStmt>(S))
@@ -62,8 +62,8 @@ public:
if (!E->isConstantExpr(Ctx,NULL)) {
// Flag a warning.
SourceRange R = E->getSourceRange();
- Diags.Report(V->getLocation(), diag::warn_dead_store,
- Ctx.getSourceManager(), 0, 0, &R, 1);
+ Diags.Report(Ctx.getFullLoc(V->getLocation()),
+ diag::warn_dead_store, 0, 0, &R, 1);
}
}
}
diff --git a/clang/Analysis/UninitializedValues.cpp b/clang/Analysis/UninitializedValues.cpp
index 4e2969659d6..aec31972796 100644
--- a/clang/Analysis/UninitializedValues.cpp
+++ b/clang/Analysis/UninitializedValues.cpp
@@ -222,8 +222,8 @@ public:
if (V(VD,AD) == Uninitialized)
if (AlreadyWarned.insert(VD))
- Diags.Report(DR->getSourceRange().getBegin(), diag::warn_uninit_val,
- Ctx.getSourceManager());
+ Diags.Report(Ctx.getFullLoc(DR->getSourceRange().getBegin()),
+ diag::warn_uninit_val);
}
};
} // end anonymous namespace
diff --git a/clang/Basic/Diagnostic.cpp b/clang/Basic/Diagnostic.cpp
index 36da1e2c5c2..2d9981424a3 100644
--- a/clang/Basic/Diagnostic.cpp
+++ b/clang/Basic/Diagnostic.cpp
@@ -197,8 +197,7 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
/// Report - Issue the message to the client. If the client wants us to stop
/// compilation, return true, otherwise return false. DiagID is a member of
/// the diag::kind enum.
-void Diagnostic::Report(SourceLocation Pos, unsigned DiagID,
- SourceManager* SrcMgr,
+void Diagnostic::Report(FullSourceLoc Pos, unsigned DiagID,
const std::string *Strs, unsigned NumStrs,
const SourceRange *Ranges, unsigned NumRanges) {
// Figure out the diagnostic level of this message.
@@ -214,11 +213,11 @@ void Diagnostic::Report(SourceLocation Pos, unsigned DiagID,
}
// Are we going to ignore this diagnosic?
- if (Client.IgnoreDiagnostic(DiagLevel, Pos, SrcMgr))
+ if (Client.IgnoreDiagnostic(DiagLevel, Pos))
return;
// Finally, report it.
- Client.HandleDiagnostic(*this, DiagLevel, Pos, (diag::kind)DiagID, SrcMgr,
+ Client.HandleDiagnostic(*this, DiagLevel, Pos, (diag::kind)DiagID,
Strs, NumStrs, Ranges, NumRanges);
++NumDiagnostics;
}
diff --git a/clang/Basic/SourceLocation.cpp b/clang/Basic/SourceLocation.cpp
index 75b4a99d45b..d7f34567fb9 100644
--- a/clang/Basic/SourceLocation.cpp
+++ b/clang/Basic/SourceLocation.cpp
@@ -8,10 +8,12 @@
//===----------------------------------------------------------------------===//
//
// This file defines serialization methods for the SourceLocation class.
+// This file defines accessor methods for the FullSourceLoc class.
//
//===----------------------------------------------------------------------===//
#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
#include "llvm/Bitcode/Serialize.h"
#include "llvm/Bitcode/Deserialize.h"
@@ -35,3 +37,43 @@ SourceRange SourceRange::ReadVal(llvm::Deserializer& D) {
SourceLocation B = SourceLocation::ReadVal(D);
return SourceRange(A,B);
}
+
+FullSourceLoc FullSourceLoc::getLogicalLoc() {
+ assert (isValid());
+ return FullSourceLoc(SrcMgr->getLogicalLoc(Loc),*SrcMgr);
+}
+
+FullSourceLoc FullSourceLoc::getIncludeLoc() {
+ assert (isValid());
+ return FullSourceLoc(SrcMgr->getIncludeLoc(Loc),*SrcMgr);
+}
+
+unsigned FullSourceLoc::getLineNumber() {
+ assert (isValid());
+ return SrcMgr->getLineNumber(Loc);
+}
+
+unsigned FullSourceLoc::getColumnNumber() {
+ assert (isValid());
+ return SrcMgr->getColumnNumber(Loc);
+}
+
+const char* FullSourceLoc::getSourceName() const {
+ assert (isValid());
+ return SrcMgr->getSourceName(Loc);
+}
+
+const FileEntry* FullSourceLoc::getFileEntryForLoc() const {
+ assert (isValid());
+ return SrcMgr->getFileEntryForLoc(Loc);
+}
+
+const char * FullSourceLoc::getCharacterData() const {
+ assert (isValid());
+ return SrcMgr->getCharacterData(Loc);
+}
+
+const llvm::MemoryBuffer* FullSourceLoc::getBuffer() const {
+ assert (isValid());
+ return SrcMgr->getBuffer(Loc.getFileID());
+}
diff --git a/clang/Basic/TargetInfo.cpp b/clang/Basic/TargetInfo.cpp
index 63b3cf84624..4c9d1c8afe2 100644
--- a/clang/Basic/TargetInfo.cpp
+++ b/clang/Basic/TargetInfo.cpp
@@ -29,20 +29,20 @@ void TargetInfoImpl::ANCHOR() {} // out-of-line virtual method for class.
void TargetInfo::getFloatInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format,
- SourceLocation Loc) {
+ FullSourceLoc Loc) {
Align = 32; // FIXME: implement correctly.
Size = 32;
Format = &llvm::APFloat::IEEEsingle;
}
void TargetInfo::getDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format,
- SourceLocation Loc) {
+ FullSourceLoc Loc) {
Size = Align = 64; // FIXME: implement correctly.
Format = &llvm::APFloat::IEEEdouble;
}
void TargetInfo::getLongDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format,
- SourceLocation Loc) {
+ FullSourceLoc Loc) {
Size = Align = 64; // FIXME: implement correctly.
Format = &llvm::APFloat::IEEEdouble;
//Size = 80; Align = 32; // FIXME: implement correctly.
@@ -63,9 +63,10 @@ const char *TargetInfo::getTargetPrefix() const {
/// DiagnoseNonPortability - When a use of a non-portable target feature is
/// used, this method emits the diagnostic and marks the translation unit as
/// non-portable.
-void TargetInfo::DiagnoseNonPortability(SourceLocation Loc, unsigned DiagKind) {
+void TargetInfo::DiagnoseNonPortability(FullSourceLoc Loc,
+ unsigned DiagKind) {
NonPortable = true;
- if (Diag && Loc.isValid()) Diag->Report(Loc, DiagKind, SrcMgr);
+ if (Diag && Loc.isValid()) Diag->Report(Loc, DiagKind);
}
/// GetTargetDefineMap - Get the set of target #defines in an associative
@@ -196,7 +197,7 @@ void TargetInfo::getTargetDefines(std::vector<char> &Buffer) {
/// ComputeWCharWidth - Determine the width of the wchar_t type for the primary
/// target, diagnosing whether this is non-portable across the secondary
/// targets.
-void TargetInfo::ComputeWCharInfo(SourceLocation Loc) {
+void TargetInfo::ComputeWCharInfo(FullSourceLoc Loc) {
PrimaryTarget->getWCharInfo(WCharWidth, WCharAlign);
// Check whether this is portable across the secondary targets if the T-U is
diff --git a/clang/Basic/Targets.cpp b/clang/Basic/Targets.cpp
index ed29c9000a1..9b182901ca4 100644
--- a/clang/Basic/Targets.cpp
+++ b/clang/Basic/Targets.cpp
@@ -699,8 +699,7 @@ static TargetInfoImpl *CreateTarget(const std::string& T) {
/// CreateTargetInfo - Return the set of target info objects as specified by
/// the -arch command line option.
-TargetInfo* TargetInfo::CreateTargetInfo(SourceManager& SrcMgr,
- const std::string* TriplesStart,
+TargetInfo* TargetInfo::CreateTargetInfo(const std::string* TriplesStart,
const std::string* TriplesEnd,
Diagnostic *Diags) {
@@ -710,7 +709,7 @@ TargetInfo* TargetInfo::CreateTargetInfo(SourceManager& SrcMgr,
if (!PrimaryTarget)
return NULL;
- TargetInfo *TI = new TargetInfo(SrcMgr, PrimaryTarget, Diags);
+ TargetInfo *TI = new TargetInfo(PrimaryTarget, Diags);
// Add all secondary targets.
for (const std::string* I=TriplesStart+1; I != TriplesEnd; ++I) {
diff --git a/clang/CodeGen/CodeGenModule.cpp b/clang/CodeGen/CodeGenModule.cpp
index cc8ecd585b0..30e15475589 100644
--- a/clang/CodeGen/CodeGenModule.cpp
+++ b/clang/CodeGen/CodeGenModule.cpp
@@ -40,7 +40,7 @@ void CodeGenModule::WarnUnsupported(const Stmt *S, const char *Type) {
"cannot codegen this %0 yet");
SourceRange Range = S->getSourceRange();
std::string Msg = Type;
- getDiags().Report(S->getLocStart(), DiagID, Context.getSourceManager(),
+ getDiags().Report(Context.getFullLoc(S->getLocStart()), DiagID,
&Msg, 1, &Range, 1);
}
@@ -559,7 +559,7 @@ llvm::Function *CodeGenModule::getMemCpyFn() {
if (MemCpyFn) return MemCpyFn;
llvm::Intrinsic::ID IID;
uint64_t Size; unsigned Align;
- Context.Target.getPointerInfo(Size, Align, SourceLocation());
+ Context.Target.getPointerInfo(Size, Align, FullSourceLoc());
switch (Size) {
default: assert(0 && "Unknown ptr width");
case 32: IID = llvm::Intrinsic::memcpy_i32; break;
diff --git a/clang/Driver/RewriteTest.cpp b/clang/Driver/RewriteTest.cpp
index 6edfcb17d75..7392016021e 100644
--- a/clang/Driver/RewriteTest.cpp
+++ b/clang/Driver/RewriteTest.cpp
@@ -911,8 +911,7 @@ Stmt *RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) {
unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
"rewriter could not replace sub-expression due to macros");
SourceRange Range = Exp->getSourceRange();
- Diags.Report(Exp->getAtLoc(), DiagID, Context->getSourceManager(),
- 0, 0, &Range, 1);
+ Diags.Report(Context->getFullLoc(Exp->getAtLoc()), DiagID, 0, 0, &Range, 1);
delete Replacement;
return Exp;
}
diff --git a/clang/Driver/TextDiagnosticBuffer.cpp b/clang/Driver/TextDiagnosticBuffer.cpp
index f644c3f660d..9e7575242b7 100644
--- a/clang/Driver/TextDiagnosticBuffer.cpp
+++ b/clang/Driver/TextDiagnosticBuffer.cpp
@@ -19,9 +19,8 @@ using namespace clang;
///
void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic &Diags,
Diagnostic::Level Level,
- SourceLocation Pos,
+ FullSourceLoc Pos,
diag::kind ID,
- SourceManager* SrcMgr,
const std::string *Strs,
unsigned NumStrs,
const SourceRange *,
@@ -29,12 +28,14 @@ void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic &Diags,
switch (Level) {
default: assert(0 && "Diagnostic not handled during diagnostic buffering!");
case Diagnostic::Warning:
- Warnings.push_back(std::make_pair(Pos, FormatDiagnostic(Diags, Level, ID,
- Strs, NumStrs)));
+ Warnings.push_back(std::make_pair(Pos.getLocation(),
+ FormatDiagnostic(Diags, Level, ID,
+ Strs, NumStrs)));
break;
case Diagnostic::Error:
- Errors.push_back(std::make_pair(Pos, FormatDiagnostic(Diags, Level, ID,
- Strs, NumStrs)));
+ Errors.push_back(std::make_pair(Pos.getLocation(),
+ FormatDiagnostic(Diags, Level, ID,
+ Strs, NumStrs)));
break;
}
}
diff --git a/clang/Driver/TextDiagnosticBuffer.h b/clang/Driver/TextDiagnosticBuffer.h
index 53a6cb7e60d..60ad8c06b23 100644
--- a/clang/Driver/TextDiagnosticBuffer.h
+++ b/clang/Driver/TextDiagnosticBuffer.h
@@ -38,10 +38,10 @@ public:
const_iterator warn_begin() const { return Warnings.begin(); }
const_iterator warn_end() const { return Warnings.end(); }
- virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
- SourceLocation Pos,
+ virtual void HandleDiagnostic(Diagnostic &Diags,
+ Diagnostic::Level DiagLevel,
+ FullSourceLoc Pos,
diag::kind ID,
- SourceManager* SrcMgr,
const std::string *Strs,
unsigned NumStrs,
const SourceRange *Ranges,
diff --git a/clang/Driver/TextDiagnosticPrinter.cpp b/clang/Driver/TextDiagnosticPrinter.cpp
index 3df15158aee..598270b016b 100644
--- a/clang/Driver/TextDiagnosticPrinter.cpp
+++ b/clang/Driver/TextDiagnosticPrinter.cpp
@@ -31,23 +31,23 @@ NoCaretDiagnostics("fno-caret-diagnostics",
" diagnostics"));
void TextDiagnosticPrinter::
-PrintIncludeStack(SourceLocation Pos, SourceManager& SourceMgr) {
+PrintIncludeStack(FullSourceLoc Pos) {
if (Pos.isInvalid()) return;
- Pos = SourceMgr.getLogicalLoc(Pos);
+ Pos = Pos.getLogicalLoc();
// Print out the other include frames first.
- PrintIncludeStack(SourceMgr.getIncludeLoc(Pos),SourceMgr);
- unsigned LineNo = SourceMgr.getLineNumber(Pos);
+ PrintIncludeStack(Pos.getIncludeLoc());
+ unsigned LineNo = Pos.getLineNumber();
- std::cerr << "In file included from " << SourceMgr.getSourceName(Pos)
+ std::cerr << "In file included from " << Pos.getSourceName()
<< ":" << LineNo << ":\n";
}
/// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s)
/// any characters in LineNo that intersect the SourceRange.
void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
- SourceManager* SourceMgr,
+ SourceManager& SourceMgr,
unsigned LineNo,
std::string &CaratLine,
const std::string &SourceLine) {
@@ -55,16 +55,16 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
"Expect a correspondence between source and carat line!");
if (!R.isValid()) return;
- unsigned StartLineNo = SourceMgr->getLogicalLineNumber(R.getBegin());
+ unsigned StartLineNo = SourceMgr.getLogicalLineNumber(R.getBegin());
if (StartLineNo > LineNo) return; // No intersection.
- unsigned EndLineNo = SourceMgr->getLogicalLineNumber(R.getEnd());
+ unsigned EndLineNo = SourceMgr.getLogicalLineNumber(R.getEnd());
if (EndLineNo < LineNo) return; // No intersection.
// Compute the column number of the start.
unsigned StartColNo = 0;
if (StartLineNo == LineNo) {
- StartColNo = SourceMgr->getLogicalColumnNumber(R.getBegin());
+ StartColNo = SourceMgr.getLogicalColumnNumber(R.getBegin());
if (StartColNo) --StartColNo; // Zero base the col #.
}
@@ -76,12 +76,12 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
// Compute the column number of the end.
unsigned EndColNo = CaratLine.size();
if (EndLineNo == LineNo) {
- EndColNo = SourceMgr->getLogicalColumnNumber(R.getEnd());
+ EndColNo = SourceMgr.getLogicalColumnNumber(R.getEnd());
if (EndColNo) {
--EndColNo; // Zero base the col #.
// Add in the length of the token, so that we cover multi-char tokens.
- EndColNo += Lexer::MeasureTokenLength(R.getEnd(), *SourceMgr);
+ EndColNo += Lexer::MeasureTokenLength(R.getEnd(), SourceMgr);
} else {
EndColNo = CaratLine.size();
}
@@ -100,9 +100,8 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags,
Diagnostic::Level Level,
- SourceLocation Pos,
+ FullSourceLoc Pos,
diag::kind ID,
- SourceManager* SourceMgr,
const std::string *Strs,
unsigned NumStrs,
const SourceRange *Ranges,
@@ -111,25 +110,25 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags,
const char *LineStart = 0, *LineEnd = 0;
if (Pos.isValid()) {
- SourceLocation LPos = SourceMgr->getLogicalLoc(Pos);
- LineNo = SourceMgr->getLineNumber(LPos);
+ FullSourceLoc LPos = Pos.getLogicalLoc();
+ LineNo = LPos.getLineNumber();
// First, if this diagnostic is not in the main file, print out the
// "included from" lines.
- if (LastWarningLoc != SourceMgr->getIncludeLoc(LPos)) {
- LastWarningLoc = SourceMgr->getIncludeLoc(LPos);
- PrintIncludeStack(LastWarningLoc,*SourceMgr);
+ if (LastWarningLoc != LPos.getIncludeLoc()) {
+ LastWarningLoc = LPos.getIncludeLoc();
+ PrintIncludeStack(LastWarningLoc);
}
// Compute the column number. Rewind from the current position to the start
// of the line.
- ColNo = SourceMgr->getColumnNumber(LPos);
- const char *TokLogicalPtr = SourceMgr->getCharacterData(LPos);
+ ColNo = LPos.getColumnNumber();
+ const char *TokLogicalPtr = LPos.getCharacterData();
LineStart = TokLogicalPtr-ColNo+1; // Column # is 1-based
// Compute the line end. Scan forward from the error position to the end of
// the line.
- const llvm::MemoryBuffer *Buffer = SourceMgr->getBuffer(LPos.getFileID());
+ const llvm::MemoryBuffer *Buffer = LPos.getBuffer();
const char *BufEnd = Buffer->getBufferEnd();
LineEnd = TokLogicalPtr;
while (LineEnd != BufEnd &&
@@ -164,7 +163,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags,
// Highlight all of the characters covered by Ranges with ~ characters.
for (unsigned i = 0; i != NumRanges; ++i)
- HighlightRange(Ranges[i], SourceMgr, LineNo, CaratLine, SourceLine);
+ HighlightRange(Ranges[i], Pos.getManager(),LineNo, CaratLine, SourceLine);
// Next, insert the carat itself.
if (ColNo-1 < CaratLine.size())
diff --git a/clang/Driver/TextDiagnosticPrinter.h b/clang/Driver/TextDiagnosticPrinter.h
index 1f0a52ce715..4149c65acf6 100644
--- a/clang/Driver/TextDiagnosticPrinter.h
+++ b/clang/Driver/TextDiagnosticPrinter.h
@@ -22,21 +22,22 @@ namespace clang {
class SourceManager;
class TextDiagnosticPrinter : public TextDiagnostics {
- SourceLocation LastWarningLoc;
+ FullSourceLoc LastWarningLoc;
public:
TextDiagnosticPrinter() {}
- void PrintIncludeStack(SourceLocation Pos, SourceManager& SrcMgr);
+ void PrintIncludeStack(FullSourceLoc Pos);
+
void HighlightRange(const SourceRange &R,
- SourceManager* SrcMgr,
+ SourceManager& SrcMgr,
unsigned LineNo,
std::string &CaratLine,
const std::string &SourceLine);
- virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
- SourceLocation Pos,
+ virtual void HandleDiagnostic(Diagnostic &Diags,
+ Diagnostic::Level DiagLevel,
+ FullSourceLoc Pos,
diag::kind ID,
- SourceManager* SrcMgr,
const std::string *Strs,
unsigned NumStrs,
const SourceRange *Ranges,
diff --git a/clang/Driver/TextDiagnostics.cpp b/clang/Driver/TextDiagnostics.cpp
index 052ea6b98d1..d9928341dcd 100644
--- a/clang/Driver/TextDiagnostics.cpp
+++ b/clang/Driver/TextDiagnostics.cpp
@@ -40,13 +40,12 @@ std::string TextDiagnostics::FormatDiagnostic(Diagnostic &Diags,
}
bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level,
- SourceLocation Pos,
- SourceManager* SourceMgr) {
+ FullSourceLoc Pos) {
if (Pos.isValid()) {
// If this is a warning or note, and if it a system header, suppress the
// diagnostic.
if (Level == Diagnostic::Warning || Level == Diagnostic::Note) {
- if (const FileEntry *F = SourceMgr->getFileEntryForLoc(Pos)) {
+ if (const FileEntry *F = Pos.getFileEntryForLoc()) {
DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
if (DirInfo == DirectoryLookup::SystemHeaderDir ||
DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
diff --git a/clang/Driver/TextDiagnostics.h b/clang/Driver/TextDiagnostics.h
index 7741ab99b86..219f414a791 100644
--- a/clang/Driver/TextDiagnostics.h
+++ b/clang/Driver/TextDiagnostics.h
@@ -35,13 +35,11 @@ public:
void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; }
virtual bool IgnoreDiagnostic(Diagnostic::Level Level,
- SourceLocation Pos,
- SourceManager* SrcMgr);
+ FullSourceLoc Pos);
virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
- SourceLocation Pos,
+ FullSourceLoc Pos,
diag::kind ID,
- SourceManager* SrcMgr,
const std::string *Strs,
unsigned NumStrs,
const SourceRange *Ranges,
diff --git a/clang/Driver/TranslationUnit.cpp b/clang/Driver/TranslationUnit.cpp
index f5c6cfff20b..62a27f55ac3 100644
--- a/clang/Driver/TranslationUnit.cpp
+++ b/clang/Driver/TranslationUnit.cpp
@@ -184,7 +184,7 @@ TranslationUnit* TranslationUnit::Create(llvm::Deserializer& Dezr,
assert (FoundBlock);
// Read the SourceManager.
- SourceManager& SrcMgr = *SourceManager::CreateAndRegister(Dezr,FMgr);
+ SourceManager::CreateAndRegister(Dezr,FMgr);
// Read the LangOptions.
TU->LangOpts.Read(Dezr);
@@ -193,8 +193,7 @@ TranslationUnit* TranslationUnit::Create(llvm::Deserializer& Dezr,
llvm::SerializedPtrID PtrID = Dezr.ReadPtrID();
char* triple = Dezr.ReadCStr(NULL,0,true);
std::string Triple(triple);
- Dezr.RegisterPtr(PtrID,TargetInfo::CreateTargetInfo(SrcMgr,
- &Triple,
+ Dezr.RegisterPtr(PtrID,TargetInfo::CreateTargetInfo(&Triple,
&Triple+1));
delete [] triple;
}
diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp
index 316b93a64dc..e827c9e7481 100644
--- a/clang/Driver/clang.cpp
+++ b/clang/Driver/clang.cpp
@@ -1019,8 +1019,7 @@ int main(int argc, char **argv) {
// Create triples, and create the TargetInfo.
std::vector<std::string> triples;
CreateTargetTriples(triples);
- Target = TargetInfo::CreateTargetInfo(SourceMgr,
- &triples[0],
+ Target = TargetInfo::CreateTargetInfo(&triples[0],
&triples[0]+triples.size(),
&Diags);
diff --git a/clang/Lex/LiteralSupport.cpp b/clang/Lex/LiteralSupport.cpp
index d00d9c3b164..03138232dc8 100644
--- a/clang/Lex/LiteralSupport.cpp
+++ b/clang/Lex/LiteralSupport.cpp
@@ -93,8 +93,10 @@ static unsigned ProcessCharEscape(const char *&ThisTokBuf,
}
// See if any bits will be truncated when evaluated as a character.
- unsigned CharWidth = IsWide ? PP.getTargetInfo().getWCharWidth(Loc)
- : PP.getTargetInfo().getCharWidth(Loc);
+ unsigned CharWidth = IsWide
+ ? PP.getTargetInfo().getWCharWidth(PP.getFullLoc(Loc))
+ : PP.getTargetInfo().getCharWidth(PP.getFullLoc(Loc));
+
if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
Overflow = true;
ResultChar &= ~0U >> (32-CharWidth);
@@ -122,8 +124,10 @@ static unsigned ProcessCharEscape(const char *&ThisTokBuf,
ThisTokBuf[0] >= '0' && ThisTokBuf[0] <= '7');
// Check for overflow. Reject '\777', but not L'\777'.
- unsigned CharWidth = IsWide ? PP.getTargetInfo().getWCharWidth(Loc)
- : PP.getTargetInfo().getCharWidth(Loc);
+ unsigned CharWidth = IsWide
+ ? PP.getTargetInfo().getWCharWidth(PP.getFullLoc(Loc))
+ : PP.getTargetInfo().getCharWidth(PP.getFullLoc(Loc));
+
if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
PP.Diag(Loc, diag::warn_octal_escape_too_large);
ResultChar &= ~0U >> (32-CharWidth);
@@ -453,13 +457,13 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
// FIXME: This assumes that 'int' is 32-bits in overflow calculation, and the
// size of "value".
- assert(PP.getTargetInfo().getIntWidth(Loc) == 32 &&
+ assert(PP.getTargetInfo().getIntWidth(PP.getFullLoc(Loc)) == 32 &&
"Assumes sizeof(int) == 4 for now");
// FIXME: This assumes that wchar_t is 32-bits for now.
- assert(PP.getTargetInfo().getWCharWidth(Loc) == 32 &&
+ assert(PP.getTargetInfo().getWCharWidth(PP.getFullLoc(Loc)) == 32 &&
"Assumes sizeof(wchar_t) == 4 for now");
// FIXME: This extensively assumes that 'char' is 8-bits.
- assert(PP.getTargetInfo().getCharWidth(Loc) == 8 &&
+ assert(PP.getTargetInfo().getCharWidth(PP.getFullLoc(Loc)) == 8 &&
"Assumes char is 8 bits");
bool isFirstChar = true;
@@ -505,7 +509,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
// character constants are not sign extended in the this implementation:
// '\xFF\xFF' = 65536 and '\x0\xFF' = 255, which matches GCC.
if (!IsWide && !isMultiChar && (Value & 128) &&
- PP.getTargetInfo().isCharSigned(Loc))
+ PP.getTargetInfo().isCharSigned(PP.getFullLoc(Loc)))
Value = (signed char)Value;
}
@@ -583,7 +587,9 @@ StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
// query the target. As such, wchar_tByteWidth is only valid if AnyWide=true.
wchar_tByteWidth = ~0U;
if (AnyWide) {
- wchar_tByteWidth = Target.getWCharWidth(StringToks[0].getLocation());
+ wchar_tByteWidth =
+ Target.getWCharWidth(PP.getFullLoc(StringToks[0].getLocation()));
+
assert((wchar_tByteWidth & 7) == 0 && "Assumes wchar_t is byte multiple!");
wchar_tByteWidth /= 8;
}
diff --git a/clang/Lex/PPExpressions.cpp b/clang/Lex/PPExpressions.cpp
index ec20eb14c8e..ff0c36c2444 100644
--- a/clang/Lex/PPExpressions.cpp
+++ b/clang/Lex/PPExpressions.cpp
@@ -112,15 +112,17 @@ static bool EvaluateValue(llvm::APSInt &Result, Token &PeekTok,
if (Macro->isTargetSpecific()) {
// Don't warn on second use.
Macro->setIsTargetSpecific(false);
- PP.getTargetInfo().DiagnoseNonPortability(PeekTok.getLocation(),
- diag::port_target_macro_use);
+ PP.getTargetInfo().DiagnoseNonPortability(
+ PP.getFullLoc(PeekTok.getLocation()),
+ diag::port_target_macro_use);
}
} else if (ValueLive) {
// Use of a target-specific macro for some other target? If so, warn.
if (II->isOtherTargetMacro()) {
II->setIsOtherTargetMacro(false); // Don't warn on second use.
- PP.getTargetInfo().DiagnoseNonPortability(PeekTok.getLocation(),
- diag::port_target_macro_use);
+ PP.getTargetInfo().DiagnoseNonPortability(
+ PP.getFullLoc(PeekTok.getLocation()),
+ diag::port_target_macro_use);
}
}
@@ -211,16 +213,16 @@ static bool EvaluateValue(llvm::APSInt &Result, Token &PeekTok,
TargetInfo &TI = PP.getTargetInfo();
unsigned NumBits;
if (Literal.isWide())
- NumBits = TI.getWCharWidth(PeekTok.getLocation());
+ NumBits = TI.getWCharWidth(PP.getFullLoc(PeekTok.getLocation()));
else
- NumBits = TI.getCharWidth(PeekTok.getLocation());
+ NumBits = TI.getCharWidth(PP.getFullLoc(PeekTok.getLocation()));
// Set the width.
llvm::APSInt Val(NumBits);
// Set the value.
Val = Literal.getValue();
// Set the signedness.
- Val.setIsUnsigned(!TI.isCharSigned(PeekTok.getLocation()));
+ Val.setIsUnsigned(!TI.isCharSigned(PP.getFullLoc(PeekTok.getLocation())));
if (Result.getBitWidth() > Val.getBitWidth()) {
if (Val.isSigned())
@@ -617,7 +619,9 @@ EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) {
Lex(Tok);
// C99 6.10.1p3 - All expressions are evaluated as intmax_t or uintmax_t.
- unsigned BitWidth = getTargetInfo().getIntMaxTWidth(Tok.getLocation());
+ unsigned BitWidth =
+ getTargetInfo().getIntMaxTWidth(getFullLoc(Tok.getLocation()));
+
llvm::APSInt ResVal(BitWidth);
DefinedTracker DT;
if (EvaluateValue(ResVal, Tok, DT, true, *this)) {
diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp
index 51d8e5d4109..fb4628be712 100644
--- a/clang/Lex/Preprocessor.cpp
+++ b/clang/Lex/Preprocessor.cpp
@@ -120,12 +120,12 @@ PPCallbacks::~PPCallbacks() {
/// the specified Token's location, translating the token's start
/// position in the current buffer into a SourcePosition object for rendering.
void Preprocessor::Diag(SourceLocation Loc, unsigned DiagID) {
- Diags.Report(Loc, DiagID, SourceMgr);
+ Diags.Report(getFullLoc(Loc), DiagID);
}
void Preprocessor::Diag(SourceLocation Loc, unsigned DiagID,
const std::string &Msg) {
- Diags.Report(Loc, DiagID, SourceMgr, &Msg, 1);
+ Diags.Report(getFullLoc(Loc), DiagID, &Msg, 1);
}
void Preprocessor::DumpToken(const Token &Tok, bool DumpFlags) const {
@@ -791,7 +791,7 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,
// If this is the first use of a target-specific macro, warn about it.
if (MI->isTargetSpecific()) {
MI->setIsTargetSpecific(false); // Don't warn on second use.
- getTargetInfo().DiagnoseNonPortability(Identifier.getLocation(),
+ getTargetInfo().DiagnoseNonPortability(getFullLoc(Identifier.getLocation()),
diag::port_target_macro_use);
}
@@ -1227,7 +1227,7 @@ void Preprocessor::HandleIdentifier(Token &Identifier) {
// This diagnosic is only emitted when macro expansion is enabled, because
// the macro would not have been expanded for the other target either.
II.setIsOtherTargetMacro(false); // Don't warn on second use.
- getTargetInfo().DiagnoseNonPortability(Identifier.getLocation(),
+ getTargetInfo().DiagnoseNonPortability(getFullLoc(Identifier.getLocation()),
diag::port_target_macro_use);
}
@@ -2337,15 +2337,17 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef,
// If this is the first use of a target-specific macro, warn about it.
if (MI->isTargetSpecific()) {
MI->setIsTargetSpecific(false); // Don't warn on second use.
- getTargetInfo().DiagnoseNonPortability(MacroNameTok.getLocation(),
- diag::port_target_macro_use);
+ getTargetInfo().DiagnoseNonPortability(
+ getFullLoc(MacroNameTok.getLocation()),
+ diag::port_target_macro_use);
}
} else {
// Use of a target-specific macro for some other target? If so, warn.
if (MII->isOtherTargetMacro()) {
MII->setIsOtherTargetMacro(false); // Don't warn on second use.
- getTargetInfo().DiagnoseNonPortability(MacroNameTok.getLocation(),
- diag::port_target_macro_use);
+ getTargetInfo().DiagnoseNonPortability(
+ getFullLoc(MacroNameTok.getLocation()),
+ diag::port_target_macro_use);
}
}
diff --git a/clang/Parse/Parser.cpp b/clang/Parse/Parser.cpp
index f2f331ed697..732311d6c2d 100644
--- a/clang/Parse/Parser.cpp
+++ b/clang/Parse/Parser.cpp
@@ -31,7 +31,7 @@ Action::~Action() {}
void Parser::Diag(SourceLocation Loc, unsigned DiagID,
const std::string &Msg) {
- Diags.Report(Loc, DiagID, PP.getSourceManager(), &Msg, 1);
+ Diags.Report(FullSourceLoc(Loc,PP.getSourceManager()), DiagID, &Msg, 1);
}
/// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'),
diff --git a/clang/Sema/Sema.cpp b/clang/Sema/Sema.cpp
index 5ec5fa7ede4..3f5b24f37c1 100644
--- a/clang/Sema/Sema.cpp
+++ b/clang/Sema/Sema.cpp
@@ -118,54 +118,51 @@ void Sema::DeleteStmt(StmtTy *S) {
//===----------------------------------------------------------------------===//
bool Sema::Diag(SourceLocation Loc, unsigned DiagID) {
- PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager());
+ PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID);
return true;
}
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
- PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), &Msg, 1);
+ PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, &Msg, 1);
return true;
}
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
const std::string &Msg2) {
std::string MsgArr[] = { Msg1, Msg2 };
- PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), MsgArr, 2);
+ PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, MsgArr, 2);
return true;
}
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, SourceRange Range) {
- PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), 0,0, &Range,1);
+ PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, 0, 0, &Range,1);
return true;
}
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
SourceRange Range) {
- PP.getDiagnostics().Report(Loc,DiagID,PP.getSourceManager(),&Msg,1,&Range,1);
+ PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, &Msg, 1, &Range,1);
return true;
}
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
const std::string &Msg2, SourceRange Range) {
std::string MsgArr[] = { Msg1, Msg2 };
- PP.getDiagnostics().Report(Loc,DiagID,PP.getSourceManager(),
- MsgArr,2,&Range,1);
+ PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, MsgArr, 2, &Range, 1);
return true;
}
bool Sema::Diag(SourceLocation Loc, unsigned DiagID,
SourceRange R1, SourceRange R2) {
SourceRange RangeArr[] = { R1, R2 };
- PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(),
- 0, 0, RangeArr, 2);
+ PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, 0, 0, RangeArr, 2);
return true;
}
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
SourceRange R1, SourceRange R2) {
SourceRange RangeArr[] = { R1, R2 };
- PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), &Msg,
- 1, RangeArr, 2);
+ PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, &Msg, 1, RangeArr, 2);
return true;
}
@@ -173,8 +170,7 @@ bool Sema::Diag(SourceLocation Range, unsigned DiagID, const std::string &Msg1,
const std::string &Msg2, SourceRange R1, SourceRange R2) {
std::string MsgArr[] = { Msg1, Msg2 };
SourceRange RangeArr[] = { R1, R2 };
- PP.getDiagnostics().Report(Range, DiagID, PP.getSourceManager(), MsgArr, 2,
- RangeArr, 2);
+ PP.getDiagnostics().Report(PP.getFullLoc(Range),DiagID, MsgArr,2,RangeArr, 2);
return true;
}
diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp
index 92e1f844797..b0c86f5c50f 100644
--- a/clang/Sema/SemaDecl.cpp
+++ b/clang/Sema/SemaDecl.cpp
@@ -135,7 +135,7 @@ ScopedDecl *Sema::LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
if (II->isNonPortableBuiltin()) {
// Only emit this diagnostic once for this builtin.
II->setNonPortableBuiltin(false);
- Context.Target.DiagnoseNonPortability(IdLoc,
+ Context.Target.DiagnoseNonPortability(Context.getFullLoc(IdLoc),
diag::port_target_builtin_use);
}
// If this is a builtin on this (or all) targets, create the decl.
@@ -1506,7 +1506,8 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
// TODO: If the result value doesn't fit in an int, it must be a long or long
// long value. ISO C does not support this, but GCC does as an extension,
// emit a warning.
- unsigned IntWidth = Context.Target.getIntWidth(Enum->getLocation());
+ unsigned IntWidth =
+ Context.Target.getIntWidth(Context.getFullLoc(Enum->getLocation()));
// Verify that all the values are okay, compute the size of the values, and
@@ -1562,11 +1563,15 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
BestType = Context.IntTy;
BestWidth = IntWidth;
} else {
- BestWidth = Context.Target.getLongWidth(Enum->getLocation());
+ BestWidth =
+ Context.Target.getLongWidth(Context.getFullLoc(Enum->getLocation()));
+
if (NumNegativeBits <= BestWidth && NumPositiveBits < BestWidth)
BestType = Context.LongTy;
else {
- BestWidth = Context.Target.getLongLongWidth(Enum->getLocation());
+ BestWidth = Context.Target.getLongLongWidth(
+ Context.getFullLoc(Enum->getLocation()));
+
if (NumNegativeBits > BestWidth || NumPositiveBits >= BestWidth)
Diag(Enum->getLocation(), diag::warn_enum_too_large);
BestType = Context.LongLongTy;
@@ -1579,10 +1584,14 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
BestType = Context.UnsignedIntTy;
BestWidth = IntWidth;
} else if (NumPositiveBits <=
- (BestWidth = Context.Target.getLongWidth(Enum->getLocation())))
+ (BestWidth = Context.Target.getLongWidth(
+ Context.getFullLoc(Enum->getLocation()))))
+
BestType = Context.UnsignedLongTy;
else {
- BestWidth = Context.Target.getLongLongWidth(Enum->getLocation());
+ BestWidth =
+ Context.Target.getLongLongWidth(Context.getFullLoc(Enum->getLocation()));
+
assert(NumPositiveBits <= BestWidth &&
"How could an initializer get larger than ULL?");
BestType = Context.UnsignedLongLongTy;
diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp
index 444ea1c78ce..98ede439f68 100644
--- a/clang/Sema/SemaExpr.cpp
+++ b/clang/Sema/SemaExpr.cpp
@@ -181,13 +181,17 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
if (Literal.isFloat) {
Ty = Context.FloatTy;
- Context.Target.getFloatInfo(Size, Align, Format, Tok.getLocation());
+ Context.Target.getFloatInfo(Size, Align, Format,
+ Context.getFullLoc(Tok.getLocation()));
+
} else if (Literal.isLong) {
Ty = Context.LongDoubleTy;
- Context.Target.getLongDoubleInfo(Size, Align, Format, Tok.getLocation());
+ Context.Target.getLongDoubleInfo(Size, Align, Format,
+ Context.getFullLoc(Tok.getLocation()));
} else {
Ty = Context.DoubleTy;
- Context.Target.getDoubleInfo(Size, Align, Format, Tok.getLocation());
+ Context.Target.getDoubleInfo(Size, Align, Format,
+ Context.getFullLoc(Tok.getLocation()));
}
// isExact will be set by GetFloatValue().
@@ -207,7 +211,8 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
Diag(Tok.getLocation(), diag::ext_longlong);
// Get the value in the widest-possible width.
- llvm::APInt ResultVal(Context.Target.getIntMaxTWidth(Tok.getLocation()), 0);
+ llvm::APInt ResultVal(Context.Target.getIntMaxTWidth(
+ Context.getFullLoc(Tok.getLocation())), 0);
if (Literal.GetIntegerValue(ResultVal)) {
// If this value didn't fit into uintmax_t, warn and force to ull.
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index f77895074bb..f28ae3f4c2b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -77,6 +77,10 @@ public:
SelectorTable &Selectors;
SourceManager& getSourceManager() { return SourceMgr; }
+
+ FullSourceLoc getFullLoc(SourceLocation Loc) const {
+ return FullSourceLoc(Loc,SourceMgr);
+ }
/// This is intentionally not serialized. It is populated by the
/// ASTContext ctor, and there are no external pointers/references to
diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index d5ca1203fc6..11764936702 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -147,25 +147,17 @@ public:
/// Report - Issue the message to the client. DiagID is a member of the
/// diag::kind enum.
- void Report(SourceLocation Pos, unsigned DiagID, SourceManager& SrcMgr,
+ void Report(FullSourceLoc Pos, unsigned DiagID,
const std::string *Strs = 0, unsigned NumStrs = 0,
- const SourceRange *Ranges = 0, unsigned NumRanges = 0) {
- Report(Pos,DiagID,&SrcMgr,Strs,NumStrs,Ranges,NumRanges);
- }
-
+ const SourceRange *Ranges = 0, unsigned NumRanges = 0);
/// Report - Issue the message to the client. DiagID is a member of the
/// diag::kind enum.
- void Report(unsigned DiagID, const std::string *Strs = 0,
- unsigned NumStrs = 0, const SourceRange *Ranges = 0,
- unsigned NumRanges = 0) {
- Report(SourceLocation(),DiagID,NULL,Strs,NumStrs,Ranges,NumRanges);
+ void Report(unsigned DiagID,
+ const std::string *Strs = 0, unsigned NumStrs = 0,
+ const SourceRange *Ranges = 0, unsigned NumRanges = 0) {
+ Report(FullSourceLoc(),DiagID,Strs,NumStrs,Ranges,NumRanges);
}
-
-private:
- void Report(SourceLocation Pos, unsigned DiagID, SourceManager* SrcMgr,
- const std::string *Strs, unsigned NumStrs,
- const SourceRange *Ranges, unsigned NumRanges);
};
/// DiagnosticClient - This is an abstract interface implemented by clients of
@@ -177,16 +169,17 @@ public:
/// IgnoreDiagnostic - If the client wants to ignore this diagnostic, then
/// return true.
virtual bool IgnoreDiagnostic(Diagnostic::Level DiagLevel,
- SourceLocation Pos,
- SourceManager* SrcMgr) = 0;
+ FullSourceLoc Pos) = 0;
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
/// capturing it to a log as needed.
virtual void HandleDiagnostic(Diagnostic &Diags,
- Diagnostic::Level DiagLevel, SourceLocation Pos,
- diag::kind ID, SourceManager* SrcMgr,
+ Diagnostic::Level DiagLevel,
+ FullSourceLoc Pos,
+ diag::kind ID,
const std::string *Strs,
- unsigned NumStrs, const SourceRange *Ranges,
+ unsigned NumStrs,
+ const SourceRange *Ranges,
unsigned NumRanges) = 0;
};
diff --git a/clang/include/clang/Basic/SourceLocation.h b/clang/include/clang/Basic/SourceLocation.h
index 9ee1f308c5e..9d03b649ef6 100644
--- a/clang/include/clang/Basic/SourceLocation.h
+++ b/clang/include/clang/Basic/SourceLocation.h
@@ -17,9 +17,14 @@
#include <cassert>
#include "llvm/Bitcode/SerializationFwd.h"
+namespace llvm {
+class MemoryBuffer;
+}
+
namespace clang {
class SourceManager;
+class FileEntry;
/// SourceLocation - This is a carefully crafted 32-bit identifier that encodes
/// a full include stack, line and column number information for a position in
@@ -206,25 +211,50 @@ public:
/// that expect both objects.
class FullSourceLoc {
SourceLocation Loc;
- const SourceManager* SrcMgr;
+ SourceManager* SrcMgr;
public:
// Creates a FullSourceLoc where isValid() returns false.
explicit FullSourceLoc()
: Loc(SourceLocation()), SrcMgr((SourceManager*) 0) {}
- explicit FullSourceLoc(SourceLocation loc, const SourceManager& smgr)
- : Loc(loc), SrcMgr(&smgr) {
- assert (loc.isValid() && "SourceLocation must be valid!");
- }
+ explicit FullSourceLoc(SourceLocation loc, SourceManager& smgr)
+ : Loc(loc), SrcMgr(&smgr) {}
bool isValid() const { return Loc.isValid(); }
+ bool isInvalid() const { return Loc.isInvalid(); }
+
+ SourceLocation getLocation() const { return Loc; }
- SourceLocation getSourceLocation() const { return Loc; }
+ SourceManager& getManager() {
+ assert (SrcMgr && "SourceManager is NULL.");
+ return *SrcMgr;
+ }
const SourceManager& getManager() const {
assert (SrcMgr && "SourceManager is NULL.");
return *SrcMgr;
}
+
+ FullSourceLoc getLogicalLoc();
+ FullSourceLoc getIncludeLoc();
+
+ unsigned getLineNumber();
+ unsigned getColumnNumber();
+
+ const char *getCharacterData() const;
+
+ const llvm::MemoryBuffer* getBuffer() const;
+
+ const char* getSourceName() const;
+ const FileEntry* getFileEntryForLoc() const;
+
+ bool operator==(const FullSourceLoc& RHS) const {
+ return SrcMgr == RHS.SrcMgr && Loc == RHS.Loc;
+ }
+
+ bool operator!=(const FullSourceLoc& RHS) const {
+ return SrcMgr != RHS.SrcMgr || Loc != RHS.Loc;
+ }
};
} // end namespace clang
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 68bf0fd1aee..41842bdceac 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -42,9 +42,6 @@ namespace Builtin { struct Info; }
/// diagnostic info, but does expect them to be alive for as long as it is.
///
class TargetInfo {
- /// SrcMgr - The SourceManager associated with this TargetInfo.
- SourceManager& SrcMgr;
-
/// Primary - This tracks the primary target in the target set.
///
const TargetInfoImpl *PrimaryTarget;
@@ -69,8 +66,7 @@ class TargetInfo {
// TargetInfo Construction.
//==----------------------------------------------------------------==/
- TargetInfo(SourceManager& SMgr, const TargetInfoImpl *Primary,
- Diagnostic *D = 0) : SrcMgr(SMgr) {
+ TargetInfo(const TargetInfoImpl *Primary, Diagnostic *D = 0) {
PrimaryTarget = Primary;
Diag = D;
NonPortable = false;
@@ -83,8 +79,7 @@ public:
/// CreateTargetInfo - Create a TargetInfo object from a group of
/// target triples. The first target triple is considered the primary
/// target.
- static TargetInfo* CreateTargetInfo(SourceManager& SrcMgr,
- const std::string* TriplesBeg,
+ static TargetInfo* CreateTargetInfo(const std::string* TriplesBeg,
const std::string* TripledEnd,
Diagnostic* Diags = NULL);
@@ -114,7 +109,7 @@ public:
/// DiagnoseNonPortability - Emit a diagnostic indicating that the current
/// translation unit is non-portable due to a construct at the specified
/// location. DiagKind indicates what went wrong.
- void DiagnoseNonPortability(SourceLocation Loc, unsigned DiagKind);
+ void DiagnoseNonPortability(FullSourceLoc Loc, unsigned DiagKind);
/// getTargetDefines - Appends the target-specific #define values for this
/// target set to the specified buffer.
@@ -123,70 +118,71 @@ public:
/// isCharSigned - Return true if 'char' is 'signed char' or false if it is
/// treated as 'unsigned char'. This is implementation defined according to
/// C99 6.2.5p15. In our implementation, this is target-specific.
- bool isCharSigned(SourceLocation Loc) {
+ bool isCharSigned(FullSourceLoc Loc) {
// FIXME: implement correctly.
return true;
}
/// getPointerWidth - Return the width of pointers on this target, we
/// currently assume one pointer type.
- void getPointerInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+ void getPointerInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = 32; // FIXME: implement correctly.
Align = 32;
}
/// getBoolInfo - Return the size of '_Bool' and C++ 'bool' for this target,
/// in bits.
- void getBoolInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+ void getBoolInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = Align = 8; // FIXME: implement correctly: wrong for ppc32.
}
/// getCharInfo - Return the size of 'char', 'signed char' and
/// 'unsigned char' for this target, in bits.
- void getCharInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+ void getCharInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = Align = 8; // FIXME: implement correctly.
}
/// getShortInfo - Return the size of 'signed short' and 'unsigned short' for
/// this target, in bits.
- void getShortInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+ void getShortInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = Align = 16; // FIXME: implement correctly.
}
/// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this
/// target, in bits.
- void getIntInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+ void getIntInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = Align = 32; // FIXME: implement correctly.
}
/// getLongInfo - Return the size of 'signed long' and 'unsigned long' for
/// this target, in bits.
- void getLongInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+ void getLongInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = Align = 32; // FIXME: implement correctly: wrong for ppc64/x86-64
}
/// getLongLongInfo - Return the size of 'signed long long' and
/// 'unsigned long long' for this target, in bits.
void getLongLongInfo(uint64_t &Size, unsigned &Align,
- SourceLocation Loc) {
+ FullSourceLoc Loc) {
Size = Align = 64; // FIXME: implement correctly.
}
/// getFloatInfo - Characterize 'float' for this target.
void getFloatInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format, SourceLocation Loc);
+ const llvm::fltSemantics *&Format, FullSourceLoc Loc);
/// getDoubleInfo - Characterize 'double' for this target.
void getDoubleInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format, SourceLocation Loc);
+ const llvm::fltSemantics *&Format, FullSourceLoc Loc);
/// getLongDoubleInfo - Characterize 'long double' for this target.
void getLongDoubleInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format, SourceLocation Loc);
+ const llvm::fltSemantics *&Format, FullSourceLoc Loc);
/// getWCharInfo - Return the size of wchar_t in bits.
///
- void getWCharInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+ void getWCharInfo(uint64_t &Size, unsigned &Align,
+ FullSourceLoc Loc) {
if (!WCharWidth) ComputeWCharInfo(Loc);
Size = WCharWidth;
Align = WCharAlign;
@@ -194,7 +190,7 @@ public:
/// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
/// target, in bits.
- unsigned getIntMaxTWidth(SourceLocation Loc) {
+ unsigned getIntMaxTWidth(FullSourceLoc Loc) {
// FIXME: implement correctly.
return 64;
}
@@ -237,31 +233,31 @@ public:
///===---- Some helper methods ------------------------------------------===//
- unsigned getCharWidth(SourceLocation Loc) {
+ unsigned getCharWidth(FullSourceLoc Loc) {
uint64_t Size; unsigned Align;
getCharInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
}
- unsigned getWCharWidth(SourceLocation Loc) {
+ unsigned getWCharWidth(FullSourceLoc Loc) {
uint64_t Size; unsigned Align;
getWCharInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
}
- unsigned getIntWidth(SourceLocation Loc) {
+ unsigned getIntWidth(FullSourceLoc Loc) {
uint64_t Size; unsigned Align;
getIntInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
}
- unsigned getLongWidth(SourceLocation Loc) {
+ unsigned getLongWidth(FullSourceLoc Loc) {
uint64_t Size; unsigned Align;
getLongInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
}
- unsigned getLongLongWidth(SourceLocation Loc) {
+ unsigned getLongLongWidth(FullSourceLoc Loc) {
uint64_t Size; unsigned Align;
getLongLongInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
@@ -281,7 +277,7 @@ public:
32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128";
}
private:
- void ComputeWCharInfo(SourceLocation Loc);
+ void ComputeWCharInfo(FullSourceLoc Loc);
};
diff --git a/clang/include/clang/Parse/DeclSpec.h b/clang/include/clang/Parse/DeclSpec.h
index d55e716bc7d..7c4adf5de0a 100644
--- a/clang/include/clang/Parse/DeclSpec.h
+++ b/clang/include/clang/Parse/DeclSpec.h
@@ -271,12 +271,12 @@ public:
private:
void Diag(Diagnostic &D, SourceLocation Loc, SourceManager& SrcMgr,
unsigned DiagID) {
- D.Report(Loc, DiagID, SrcMgr);
+ D.Report(FullSourceLoc(Loc,SrcMgr), DiagID);
}
void Diag(Diagnostic &D, SourceLocation Loc, SourceManager& SrcMgr,
unsigned DiagID, const std::string &info) {
- D.Report(Loc, DiagID, SrcMgr, &info, 1);
+ D.Report(FullSourceLoc(Loc,SrcMgr), DiagID, &info, 1);
}
};
OpenPOWER on IntegriCloud