summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-10-16 05:43:57 +0000
committerChris Lattner <sabre@nondot.org>2011-10-16 05:43:57 +0000
commit3f2d5f60b31fd057c10f77b2e607b23a8c94f6d3 (patch)
treee7c36aeb6ce5e3a57764d841e5a0f603b9e12bef /include
parentd8b7aa26134d2abee777f745c32005e63dea2455 (diff)
downloadllvm-3f2d5f60b31fd057c10f77b2e607b23a8c94f6d3.tar.gz
llvm-3f2d5f60b31fd057c10f77b2e607b23a8c94f6d3.tar.bz2
llvm-3f2d5f60b31fd057c10f77b2e607b23a8c94f6d3.tar.xz
Make SMDiagnostic a little more sane. Instead of passing around note/warning/error as a
string, pass it around as an enum. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142107 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Support/IRReader.h10
-rw-r--r--include/llvm/Support/SourceMgr.h28
2 files changed, 23 insertions, 15 deletions
diff --git a/include/llvm/Support/IRReader.h b/include/llvm/Support/IRReader.h
index 292c001e09..6d8a9b30ae 100644
--- a/include/llvm/Support/IRReader.h
+++ b/include/llvm/Support/IRReader.h
@@ -40,7 +40,8 @@ namespace llvm {
std::string ErrMsg;
Module *M = getLazyBitcodeModule(Buffer, Context, &ErrMsg);
if (M == 0) {
- Err = SMDiagnostic(Buffer->getBufferIdentifier(), ErrMsg);
+ Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
+ ErrMsg);
// ParseBitcodeFile does not take ownership of the Buffer in the
// case of an error.
delete Buffer;
@@ -60,7 +61,7 @@ namespace llvm {
LLVMContext &Context) {
OwningPtr<MemoryBuffer> File;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) {
- Err = SMDiagnostic(Filename,
+ Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
"Could not open input file: " + ec.message());
return 0;
}
@@ -80,7 +81,8 @@ namespace llvm {
std::string ErrMsg;
Module *M = ParseBitcodeFile(Buffer, Context, &ErrMsg);
if (M == 0)
- Err = SMDiagnostic(Buffer->getBufferIdentifier(), ErrMsg);
+ Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
+ ErrMsg);
// ParseBitcodeFile does not take ownership of the Buffer.
delete Buffer;
return M;
@@ -97,7 +99,7 @@ namespace llvm {
LLVMContext &Context) {
OwningPtr<MemoryBuffer> File;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) {
- Err = SMDiagnostic(Filename,
+ Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
"Could not open input file: " + ec.message());
return 0;
}
diff --git a/include/llvm/Support/SourceMgr.h b/include/llvm/Support/SourceMgr.h
index 17d1df5aa7..9203e67779 100644
--- a/include/llvm/Support/SourceMgr.h
+++ b/include/llvm/Support/SourceMgr.h
@@ -31,10 +31,16 @@ namespace llvm {
/// and handles diagnostic wrangling.
class SourceMgr {
public:
+ enum DiagKind {
+ DK_Error,
+ DK_Warning,
+ DK_Note
+ };
+
/// DiagHandlerTy - Clients that want to handle their own diagnostics in a
/// custom way can register a function pointer+context as a diagnostic
/// handler. It gets called each time PrintMessage is invoked.
- typedef void (*DiagHandlerTy)(const SMDiagnostic&, void *Context);
+ typedef void (*DiagHandlerTy)(const SMDiagnostic &, void *Context);
private:
struct SrcBuffer {
/// Buffer - The memory buffer for the file.
@@ -119,10 +125,7 @@ public:
/// PrintMessage - Emit a message about the specified location with the
/// specified string.
///
- /// @param Type - If non-null, the kind of message (e.g., "error") which is
- /// prefixed to the message.
- /// @param ShowLine - Should the diagnostic show the source line.
- void PrintMessage(SMLoc Loc, const Twine &Msg, const char *Type,
+ void PrintMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg,
ArrayRef<SMRange> Ranges = ArrayRef<SMRange>(),
bool ShowLine = true) const;
@@ -133,8 +136,7 @@ public:
/// @param Type - If non-null, the kind of message (e.g., "error") which is
/// prefixed to the message.
/// @param ShowLine - Should the diagnostic show the source line.
- SMDiagnostic GetMessage(SMLoc Loc,
- const Twine &Msg, const char *Type,
+ SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg,
ArrayRef<SMRange> Ranges = ArrayRef<SMRange>(),
bool ShowLine = true) const;
@@ -155,21 +157,24 @@ class SMDiagnostic {
SMLoc Loc;
std::string Filename;
int LineNo, ColumnNo;
+ SourceMgr::DiagKind Kind;
std::string Message, LineContents;
unsigned ShowLine : 1;
std::vector<std::pair<unsigned, unsigned> > Ranges;
public:
// Null diagnostic.
- SMDiagnostic() : SM(0), LineNo(0), ColumnNo(0), ShowLine(0) {}
+ SMDiagnostic()
+ : SM(0), LineNo(0), ColumnNo(0), Kind(SourceMgr::DK_Error), ShowLine(0) {}
// Diagnostic with no location (e.g. file not found, command line arg error).
- SMDiagnostic(const std::string &filename, const std::string &Msg)
- : SM(0), Filename(filename), LineNo(-1), ColumnNo(-1),
+ SMDiagnostic(const std::string &filename, SourceMgr::DiagKind Kind,
+ const std::string &Msg)
+ : SM(0), Filename(filename), LineNo(-1), ColumnNo(-1), Kind(Kind),
Message(Msg), ShowLine(false) {}
// Diagnostic with a location.
SMDiagnostic(const SourceMgr &sm, SMLoc L, const std::string &FN,
- int Line, int Col,
+ int Line, int Col, SourceMgr::DiagKind Kind,
const std::string &Msg, const std::string &LineStr,
ArrayRef<std::pair<unsigned,unsigned> > Ranges, bool showline);
@@ -178,6 +183,7 @@ public:
const std::string &getFilename() const { return Filename; }
int getLineNo() const { return LineNo; }
int getColumnNo() const { return ColumnNo; }
+ SourceMgr::DiagKind getKind() const { return Kind; }
const std::string &getMessage() const { return Message; }
const std::string &getLineContents() const { return LineContents; }
bool getShowLine() const { return ShowLine; }