mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-05 08:56:07 +00:00
Push twines deeper into SourceMgr's error handling methods.
llvm-svn: 114847
This commit is contained in:
parent
23cb3716df
commit
c758311025
@ -26,6 +26,7 @@ namespace llvm {
|
|||||||
class MemoryBuffer;
|
class MemoryBuffer;
|
||||||
class SourceMgr;
|
class SourceMgr;
|
||||||
class SMDiagnostic;
|
class SMDiagnostic;
|
||||||
|
class Twine;
|
||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
|
|
||||||
/// SourceMgr - This owns the files read by a parser, handles include stacks,
|
/// SourceMgr - This owns the files read by a parser, handles include stacks,
|
||||||
@ -125,7 +126,7 @@ public:
|
|||||||
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
||||||
/// prefixed to the message.
|
/// prefixed to the message.
|
||||||
/// @param ShowLine - Should the diagnostic show the source line.
|
/// @param ShowLine - Should the diagnostic show the source line.
|
||||||
void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type,
|
void PrintMessage(SMLoc Loc, const Twine &Msg, const char *Type,
|
||||||
bool ShowLine = true) const;
|
bool ShowLine = true) const;
|
||||||
|
|
||||||
|
|
||||||
@ -136,7 +137,7 @@ public:
|
|||||||
/// prefixed to the message.
|
/// prefixed to the message.
|
||||||
/// @param ShowLine - Should the diagnostic show the source line.
|
/// @param ShowLine - Should the diagnostic show the source line.
|
||||||
SMDiagnostic GetMessage(SMLoc Loc,
|
SMDiagnostic GetMessage(SMLoc Loc,
|
||||||
const std::string &Msg, const char *Type,
|
const Twine &Msg, const char *Type,
|
||||||
bool ShowLine = true) const;
|
bool ShowLine = true) const;
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,18 +15,19 @@
|
|||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Instruction.h"
|
#include "llvm/Instruction.h"
|
||||||
#include "llvm/LLVMContext.h"
|
#include "llvm/LLVMContext.h"
|
||||||
|
#include "llvm/ADT/Twine.h"
|
||||||
|
#include "llvm/Assembly/Parser.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
#include "llvm/Support/SourceMgr.h"
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Assembly/Parser.h"
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
bool LLLexer::Error(LocTy ErrorLoc, const std::string &Msg) const {
|
bool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const {
|
||||||
ErrorInfo = SM.GetMessage(ErrorLoc, Msg, "error");
|
ErrorInfo = SM.GetMessage(ErrorLoc, Msg, "error");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,8 @@ namespace llvm {
|
|||||||
const APFloat &getAPFloatVal() const { return APFloatVal; }
|
const APFloat &getAPFloatVal() const { return APFloatVal; }
|
||||||
|
|
||||||
|
|
||||||
bool Error(LocTy L, const std::string &Msg) const;
|
bool Error(LocTy L, const Twine &Msg) const;
|
||||||
bool Error(const std::string &Msg) const { return Error(getLoc(), Msg); }
|
bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); }
|
||||||
std::string getFilename() const;
|
std::string getFilename() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "llvm/Operator.h"
|
#include "llvm/Operator.h"
|
||||||
#include "llvm/ValueSymbolTable.h"
|
#include "llvm/ValueSymbolTable.h"
|
||||||
#include "llvm/ADT/SmallPtrSet.h"
|
#include "llvm/ADT/SmallPtrSet.h"
|
||||||
#include "llvm/ADT/StringExtras.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -52,7 +51,7 @@ bool LLParser::ValidateEndOfModule() {
|
|||||||
|
|
||||||
if (SlotNo >= NumberedMetadata.size() || NumberedMetadata[SlotNo] == 0)
|
if (SlotNo >= NumberedMetadata.size() || NumberedMetadata[SlotNo] == 0)
|
||||||
return Error(MDList[i].Loc, "use of undefined metadata '!" +
|
return Error(MDList[i].Loc, "use of undefined metadata '!" +
|
||||||
utostr(SlotNo) + "'");
|
Twine(SlotNo) + "'");
|
||||||
Inst->setMetadata(MDList[i].MDKind, NumberedMetadata[SlotNo]);
|
Inst->setMetadata(MDList[i].MDKind, NumberedMetadata[SlotNo]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,7 +108,7 @@ bool LLParser::ValidateEndOfModule() {
|
|||||||
if (!ForwardRefTypeIDs.empty())
|
if (!ForwardRefTypeIDs.empty())
|
||||||
return Error(ForwardRefTypeIDs.begin()->second.second,
|
return Error(ForwardRefTypeIDs.begin()->second.second,
|
||||||
"use of undefined type '%" +
|
"use of undefined type '%" +
|
||||||
utostr(ForwardRefTypeIDs.begin()->first) + "'");
|
Twine(ForwardRefTypeIDs.begin()->first) + "'");
|
||||||
|
|
||||||
if (!ForwardRefVals.empty())
|
if (!ForwardRefVals.empty())
|
||||||
return Error(ForwardRefVals.begin()->second.second,
|
return Error(ForwardRefVals.begin()->second.second,
|
||||||
@ -119,12 +118,12 @@ bool LLParser::ValidateEndOfModule() {
|
|||||||
if (!ForwardRefValIDs.empty())
|
if (!ForwardRefValIDs.empty())
|
||||||
return Error(ForwardRefValIDs.begin()->second.second,
|
return Error(ForwardRefValIDs.begin()->second.second,
|
||||||
"use of undefined value '@" +
|
"use of undefined value '@" +
|
||||||
utostr(ForwardRefValIDs.begin()->first) + "'");
|
Twine(ForwardRefValIDs.begin()->first) + "'");
|
||||||
|
|
||||||
if (!ForwardRefMDNodes.empty())
|
if (!ForwardRefMDNodes.empty())
|
||||||
return Error(ForwardRefMDNodes.begin()->second.second,
|
return Error(ForwardRefMDNodes.begin()->second.second,
|
||||||
"use of undefined metadata '!" +
|
"use of undefined metadata '!" +
|
||||||
utostr(ForwardRefMDNodes.begin()->first) + "'");
|
Twine(ForwardRefMDNodes.begin()->first) + "'");
|
||||||
|
|
||||||
|
|
||||||
// Look for intrinsic functions and CallInst that need to be upgraded
|
// Look for intrinsic functions and CallInst that need to be upgraded
|
||||||
@ -317,7 +316,7 @@ bool LLParser::ParseUnnamedType() {
|
|||||||
if (Lex.getKind() == lltok::LocalVarID) {
|
if (Lex.getKind() == lltok::LocalVarID) {
|
||||||
if (Lex.getUIntVal() != TypeID)
|
if (Lex.getUIntVal() != TypeID)
|
||||||
return Error(Lex.getLoc(), "type expected to be numbered '%" +
|
return Error(Lex.getLoc(), "type expected to be numbered '%" +
|
||||||
utostr(TypeID) + "'");
|
Twine(TypeID) + "'");
|
||||||
Lex.Lex(); // eat LocalVarID;
|
Lex.Lex(); // eat LocalVarID;
|
||||||
|
|
||||||
if (ParseToken(lltok::equal, "expected '=' after name"))
|
if (ParseToken(lltok::equal, "expected '=' after name"))
|
||||||
@ -444,7 +443,7 @@ bool LLParser::ParseUnnamedGlobal() {
|
|||||||
if (Lex.getKind() == lltok::GlobalID) {
|
if (Lex.getKind() == lltok::GlobalID) {
|
||||||
if (Lex.getUIntVal() != VarID)
|
if (Lex.getUIntVal() != VarID)
|
||||||
return Error(Lex.getLoc(), "variable expected to be numbered '%" +
|
return Error(Lex.getLoc(), "variable expected to be numbered '%" +
|
||||||
utostr(VarID) + "'");
|
Twine(VarID) + "'");
|
||||||
Lex.Lex(); // eat GlobalID;
|
Lex.Lex(); // eat GlobalID;
|
||||||
|
|
||||||
if (ParseToken(lltok::equal, "expected '=' after name"))
|
if (ParseToken(lltok::equal, "expected '=' after name"))
|
||||||
@ -855,7 +854,7 @@ GlobalValue *LLParser::GetGlobalVal(unsigned ID, const Type *Ty, LocTy Loc) {
|
|||||||
// If we have the value in the symbol table or fwd-ref table, return it.
|
// If we have the value in the symbol table or fwd-ref table, return it.
|
||||||
if (Val) {
|
if (Val) {
|
||||||
if (Val->getType() == Ty) return Val;
|
if (Val->getType() == Ty) return Val;
|
||||||
Error(Loc, "'@" + utostr(ID) + "' defined with type '" +
|
Error(Loc, "'@" + Twine(ID) + "' defined with type '" +
|
||||||
Val->getType()->getDescription() + "'");
|
Val->getType()->getDescription() + "'");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1782,7 +1781,7 @@ bool LLParser::PerFunctionState::FinishFunction() {
|
|||||||
if (!ForwardRefValIDs.empty())
|
if (!ForwardRefValIDs.empty())
|
||||||
return P.Error(ForwardRefValIDs.begin()->second.second,
|
return P.Error(ForwardRefValIDs.begin()->second.second,
|
||||||
"use of undefined value '%" +
|
"use of undefined value '%" +
|
||||||
utostr(ForwardRefValIDs.begin()->first) + "'");
|
Twine(ForwardRefValIDs.begin()->first) + "'");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1850,9 +1849,9 @@ Value *LLParser::PerFunctionState::GetVal(unsigned ID, const Type *Ty,
|
|||||||
if (Val) {
|
if (Val) {
|
||||||
if (Val->getType() == Ty) return Val;
|
if (Val->getType() == Ty) return Val;
|
||||||
if (Ty->isLabelTy())
|
if (Ty->isLabelTy())
|
||||||
P.Error(Loc, "'%" + utostr(ID) + "' is not a basic block");
|
P.Error(Loc, "'%" + Twine(ID) + "' is not a basic block");
|
||||||
else
|
else
|
||||||
P.Error(Loc, "'%" + utostr(ID) + "' defined with type '" +
|
P.Error(Loc, "'%" + Twine(ID) + "' defined with type '" +
|
||||||
Val->getType()->getDescription() + "'");
|
Val->getType()->getDescription() + "'");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1894,7 +1893,7 @@ bool LLParser::PerFunctionState::SetInstName(int NameID,
|
|||||||
|
|
||||||
if (unsigned(NameID) != NumberedVals.size())
|
if (unsigned(NameID) != NumberedVals.size())
|
||||||
return P.Error(NameLoc, "instruction expected to be numbered '%" +
|
return P.Error(NameLoc, "instruction expected to be numbered '%" +
|
||||||
utostr(NumberedVals.size()) + "'");
|
Twine(NumberedVals.size()) + "'");
|
||||||
|
|
||||||
std::map<unsigned, std::pair<Value*, LocTy> >::iterator FI =
|
std::map<unsigned, std::pair<Value*, LocTy> >::iterator FI =
|
||||||
ForwardRefValIDs.find(NameID);
|
ForwardRefValIDs.find(NameID);
|
||||||
@ -2072,7 +2071,7 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
|
|||||||
for (unsigned i = 1, e = Elts.size(); i != e; ++i)
|
for (unsigned i = 1, e = Elts.size(); i != e; ++i)
|
||||||
if (Elts[i]->getType() != Elts[0]->getType())
|
if (Elts[i]->getType() != Elts[0]->getType())
|
||||||
return Error(FirstEltLoc,
|
return Error(FirstEltLoc,
|
||||||
"vector element #" + utostr(i) +
|
"vector element #" + Twine(i) +
|
||||||
" is not of type '" + Elts[0]->getType()->getDescription());
|
" is not of type '" + Elts[0]->getType()->getDescription());
|
||||||
|
|
||||||
ID.ConstantVal = ConstantVector::get(Elts.data(), Elts.size());
|
ID.ConstantVal = ConstantVector::get(Elts.data(), Elts.size());
|
||||||
@ -2105,7 +2104,7 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
|
|||||||
for (unsigned i = 0, e = Elts.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Elts.size(); i != e; ++i) {
|
||||||
if (Elts[i]->getType() != Elts[0]->getType())
|
if (Elts[i]->getType() != Elts[0]->getType())
|
||||||
return Error(FirstEltLoc,
|
return Error(FirstEltLoc,
|
||||||
"array element #" + utostr(i) +
|
"array element #" + Twine(i) +
|
||||||
" is not of type '" +Elts[0]->getType()->getDescription());
|
" is not of type '" +Elts[0]->getType()->getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2718,7 +2717,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
|
|||||||
|
|
||||||
if (NameID != NumberedVals.size())
|
if (NameID != NumberedVals.size())
|
||||||
return TokError("function expected to be numbered '%" +
|
return TokError("function expected to be numbered '%" +
|
||||||
utostr(NumberedVals.size()) + "'");
|
Twine(NumberedVals.size()) + "'");
|
||||||
} else {
|
} else {
|
||||||
return TokError("expected function name");
|
return TokError("expected function name");
|
||||||
}
|
}
|
||||||
@ -2825,7 +2824,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
|
|||||||
Fn = cast<Function>(I->second.first);
|
Fn = cast<Function>(I->second.first);
|
||||||
if (Fn->getType() != PFT)
|
if (Fn->getType() != PFT)
|
||||||
return Error(NameLoc, "type of definition and forward reference of '@" +
|
return Error(NameLoc, "type of definition and forward reference of '@" +
|
||||||
utostr(NumberedVals.size()) +"' disagree");
|
Twine(NumberedVals.size()) + "' disagree");
|
||||||
ForwardRefValIDs.erase(I);
|
ForwardRefValIDs.erase(I);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,10 +142,10 @@ namespace llvm {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool Error(LocTy L, const std::string &Msg) const {
|
bool Error(LocTy L, const Twine &Msg) const {
|
||||||
return Lex.Error(L, Msg);
|
return Lex.Error(L, Msg);
|
||||||
}
|
}
|
||||||
bool TokError(const std::string &Msg) const {
|
bool TokError(const Twine &Msg) const {
|
||||||
return Error(Lex.getLoc(), Msg);
|
return Error(Lex.getLoc(), Msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,9 @@ private:
|
|||||||
void HandleMacroExit();
|
void HandleMacroExit();
|
||||||
|
|
||||||
void PrintMacroInstantiations();
|
void PrintMacroInstantiations();
|
||||||
void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
|
void PrintMessage(SMLoc Loc, const Twine &Msg, const char *Type) const {
|
||||||
|
SrcMgr.PrintMessage(Loc, Msg, Type);
|
||||||
|
}
|
||||||
|
|
||||||
/// EnterIncludeFile - Enter the specified file. This returns true on failure.
|
/// EnterIncludeFile - Enter the specified file. This returns true on failure.
|
||||||
bool EnterIncludeFile(const std::string &Filename);
|
bool EnterIncludeFile(const std::string &Filename);
|
||||||
@ -317,22 +319,17 @@ void AsmParser::PrintMacroInstantiations() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AsmParser::Warning(SMLoc L, const Twine &Msg) {
|
void AsmParser::Warning(SMLoc L, const Twine &Msg) {
|
||||||
PrintMessage(L, Msg.str(), "warning");
|
PrintMessage(L, Msg, "warning");
|
||||||
PrintMacroInstantiations();
|
PrintMacroInstantiations();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AsmParser::Error(SMLoc L, const Twine &Msg) {
|
bool AsmParser::Error(SMLoc L, const Twine &Msg) {
|
||||||
HadError = true;
|
HadError = true;
|
||||||
PrintMessage(L, Msg.str(), "error");
|
PrintMessage(L, Msg, "error");
|
||||||
PrintMacroInstantiations();
|
PrintMacroInstantiations();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsmParser::PrintMessage(SMLoc Loc, const std::string &Msg,
|
|
||||||
const char *Type) const {
|
|
||||||
SrcMgr.PrintMessage(Loc, Msg, Type);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AsmParser::EnterIncludeFile(const std::string &Filename) {
|
bool AsmParser::EnterIncludeFile(const std::string &Filename) {
|
||||||
int NewBuf = SrcMgr.AddIncludeFile(Filename, Lexer.getLoc());
|
int NewBuf = SrcMgr.AddIncludeFile(Filename, Lexer.getLoc());
|
||||||
if (NewBuf == -1)
|
if (NewBuf == -1)
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/ADT/Twine.h"
|
||||||
#include "llvm/Support/SourceMgr.h"
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
@ -135,7 +136,7 @@ void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const {
|
|||||||
///
|
///
|
||||||
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
||||||
/// prefixed to the message.
|
/// prefixed to the message.
|
||||||
SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const std::string &Msg,
|
SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const Twine &Msg,
|
||||||
const char *Type, bool ShowLine) const {
|
const char *Type, bool ShowLine) const {
|
||||||
|
|
||||||
// First thing to do: find the current buffer containing the specified
|
// First thing to do: find the current buffer containing the specified
|
||||||
@ -162,19 +163,18 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const std::string &Msg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string PrintedMsg;
|
std::string PrintedMsg;
|
||||||
if (Type) {
|
raw_string_ostream OS(PrintedMsg);
|
||||||
PrintedMsg = Type;
|
if (Type)
|
||||||
PrintedMsg += ": ";
|
OS << Type << ": ";
|
||||||
}
|
OS << Msg;
|
||||||
PrintedMsg += Msg;
|
|
||||||
|
|
||||||
return SMDiagnostic(*this, Loc,
|
return SMDiagnostic(*this, Loc,
|
||||||
CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
|
CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
|
||||||
Loc.getPointer()-LineStart, PrintedMsg,
|
Loc.getPointer()-LineStart, OS.str(),
|
||||||
LineStr, ShowLine);
|
LineStr, ShowLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SourceMgr::PrintMessage(SMLoc Loc, const std::string &Msg,
|
void SourceMgr::PrintMessage(SMLoc Loc, const Twine &Msg,
|
||||||
const char *Type, bool ShowLine) const {
|
const char *Type, bool ShowLine) const {
|
||||||
// Report the message with the diagnostic handler if present.
|
// Report the message with the diagnostic handler if present.
|
||||||
if (DiagHandler) {
|
if (DiagHandler) {
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
#include "llvm/ADT/OwningPtr.h"
|
#include "llvm/ADT/OwningPtr.h"
|
||||||
#include "llvm/ADT/Triple.h"
|
#include "llvm/ADT/Triple.h"
|
||||||
|
#include "llvm/ADT/Twine.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/MemoryObject.h"
|
#include "llvm/Support/MemoryObject.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
@ -1490,7 +1490,7 @@ raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
|
|||||||
|
|
||||||
extern RecordKeeper Records;
|
extern RecordKeeper Records;
|
||||||
|
|
||||||
void PrintError(SMLoc ErrorLoc, const std::string &Msg);
|
void PrintError(SMLoc ErrorLoc, const Twine &Msg);
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "TGLexer.h"
|
#include "TGLexer.h"
|
||||||
|
#include "llvm/ADT/Twine.h"
|
||||||
#include "llvm/Support/SourceMgr.h"
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Config/config.h"
|
#include "llvm/Config/config.h"
|
||||||
@ -36,17 +37,17 @@ SMLoc TGLexer::getLoc() const {
|
|||||||
|
|
||||||
/// ReturnError - Set the error to the specified string at the specified
|
/// ReturnError - Set the error to the specified string at the specified
|
||||||
/// location. This is defined to always return tgtok::Error.
|
/// location. This is defined to always return tgtok::Error.
|
||||||
tgtok::TokKind TGLexer::ReturnError(const char *Loc, const std::string &Msg) {
|
tgtok::TokKind TGLexer::ReturnError(const char *Loc, const Twine &Msg) {
|
||||||
PrintError(Loc, Msg);
|
PrintError(Loc, Msg);
|
||||||
return tgtok::Error;
|
return tgtok::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TGLexer::PrintError(const char *Loc, const std::string &Msg) const {
|
void TGLexer::PrintError(const char *Loc, const Twine &Msg) const {
|
||||||
SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
|
SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TGLexer::PrintError(SMLoc Loc, const std::string &Msg) const {
|
void TGLexer::PrintError(SMLoc Loc, const Twine &Msg) const {
|
||||||
SrcMgr.PrintMessage(Loc, Msg, "error");
|
SrcMgr.PrintMessage(Loc, Msg, "error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ namespace llvm {
|
|||||||
class MemoryBuffer;
|
class MemoryBuffer;
|
||||||
class SourceMgr;
|
class SourceMgr;
|
||||||
class SMLoc;
|
class SMLoc;
|
||||||
|
class Twine;
|
||||||
|
|
||||||
namespace tgtok {
|
namespace tgtok {
|
||||||
enum TokKind {
|
enum TokKind {
|
||||||
@ -95,14 +96,14 @@ public:
|
|||||||
|
|
||||||
SMLoc getLoc() const;
|
SMLoc getLoc() const;
|
||||||
|
|
||||||
void PrintError(const char *Loc, const std::string &Msg) const;
|
void PrintError(const char *Loc, const Twine &Msg) const;
|
||||||
void PrintError(SMLoc Loc, const std::string &Msg) const;
|
void PrintError(SMLoc Loc, const Twine &Msg) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// LexToken - Read the next token and return its code.
|
/// LexToken - Read the next token and return its code.
|
||||||
tgtok::TokKind LexToken();
|
tgtok::TokKind LexToken();
|
||||||
|
|
||||||
tgtok::TokKind ReturnError(const char *Loc, const std::string &Msg);
|
tgtok::TokKind ReturnError(const char *Loc, const Twine &Msg);
|
||||||
|
|
||||||
int getNextChar();
|
int getNextChar();
|
||||||
void SkipBCPLComment();
|
void SkipBCPLComment();
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#define TGPARSER_H
|
#define TGPARSER_H
|
||||||
|
|
||||||
#include "TGLexer.h"
|
#include "TGLexer.h"
|
||||||
|
#include "llvm/ADT/Twine.h"
|
||||||
#include "llvm/Support/SourceMgr.h"
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@ -53,11 +54,11 @@ public:
|
|||||||
/// routines return true on error, or false on success.
|
/// routines return true on error, or false on success.
|
||||||
bool ParseFile();
|
bool ParseFile();
|
||||||
|
|
||||||
bool Error(SMLoc L, const std::string &Msg) const {
|
bool Error(SMLoc L, const Twine &Msg) const {
|
||||||
Lex.PrintError(L, Msg);
|
Lex.PrintError(L, Msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool TokError(const std::string &Msg) const {
|
bool TokError(const Twine &Msg) const {
|
||||||
return Error(Lex.getLoc(), Msg);
|
return Error(Lex.getLoc(), Msg);
|
||||||
}
|
}
|
||||||
private: // Semantic analysis methods.
|
private: // Semantic analysis methods.
|
||||||
|
@ -174,7 +174,7 @@ RecordKeeper llvm::Records;
|
|||||||
|
|
||||||
static SourceMgr SrcMgr;
|
static SourceMgr SrcMgr;
|
||||||
|
|
||||||
void llvm::PrintError(SMLoc ErrorLoc, const std::string &Msg) {
|
void llvm::PrintError(SMLoc ErrorLoc, const Twine &Msg) {
|
||||||
SrcMgr.PrintMessage(ErrorLoc, Msg, "error");
|
SrcMgr.PrintMessage(ErrorLoc, Msg, "error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user