From 2eeee5facafcc50c199db4911c53d24f1b14b404 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 19 Jul 2010 05:13:55 +0000 Subject: [PATCH] give ASTContext a SourceMgr reference, add diagnostic hooks to SemaBase. Swift SVN r39 --- include/swift/AST/ASTContext.h | 6 +++++- include/swift/Parse/Parser.h | 2 +- include/swift/Sema/SemaBase.h | 4 +++- lib/AST/ASTContext.cpp | 3 ++- lib/Parse/Parser.cpp | 6 +++--- lib/Sema/SemaBase.cpp | 12 ++++++++++++ 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h index 31296b8ad1d..0ed403c53b1 100644 --- a/include/swift/AST/ASTContext.h +++ b/include/swift/AST/ASTContext.h @@ -19,6 +19,7 @@ namespace llvm { class BumpPtrAllocator; + class SourceMgr; } namespace swift { @@ -30,9 +31,12 @@ class ASTContext { void operator=(const ASTContext&); // DO NOT IMPLEMENT llvm::BumpPtrAllocator *Allocator; public: - ASTContext(); + ASTContext(llvm::SourceMgr &SourceMgr); ~ASTContext(); + /// SourceMgr - The source manager object. + llvm::SourceMgr &SourceMgr; + Type * const VoidType; /// VoidType - This is 'void'. Type * const IntType; /// IntType - This is 'int'. diff --git a/include/swift/Parse/Parser.h b/include/swift/Parse/Parser.h index cd9700e530d..c389a7de623 100644 --- a/include/swift/Parse/Parser.h +++ b/include/swift/Parse/Parser.h @@ -42,7 +42,7 @@ class Parser { Parser(const Parser&); // DO NOT IMPLEMENT void operator=(const Parser&); // DO NOT IMPLEMENT public: - Parser(unsigned BufferID, llvm::SourceMgr &SM, ASTContext &Context); + Parser(unsigned BufferID, ASTContext &Context); ~Parser(); void ParseTranslationUnit(); diff --git a/include/swift/Sema/SemaBase.h b/include/swift/Sema/SemaBase.h index a8296ad961e..0408c8e2dcf 100644 --- a/include/swift/Sema/SemaBase.h +++ b/include/swift/Sema/SemaBase.h @@ -37,7 +37,9 @@ protected: public: SemaBase(Sema &s); - // TODO: Diagnostics stuff. + void Note(llvm::SMLoc Loc, const char *Message); + void Warning(llvm::SMLoc Loc, const char *Message); + void Error(llvm::SMLoc Loc, const char *Message); }; } // end namespace swift diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 5870741fe99..dbed02611ab 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -19,8 +19,9 @@ #include "llvm/Support/Allocator.h" using namespace swift; -ASTContext::ASTContext() +ASTContext::ASTContext(llvm::SourceMgr &sourcemgr) : Allocator(new llvm::BumpPtrAllocator()), + SourceMgr(sourcemgr), VoidType(new (*this) BuiltinType(BuiltinVoidKind)), IntType(new (*this) BuiltinType(BuiltinIntKind)) { } diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index a3c2d621929..fc11bb9732f 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -27,9 +27,9 @@ using llvm::SMLoc; // Setup and Helper Methods //===----------------------------------------------------------------------===// -Parser::Parser(unsigned BufferID, llvm::SourceMgr &SM, ASTContext &Context) - : SourceMgr(SM), - L(*new Lexer(BufferID, SM)), +Parser::Parser(unsigned BufferID, ASTContext &Context) + : SourceMgr(Context.SourceMgr), + L(*new Lexer(BufferID, SourceMgr)), S(*new Sema(Context)) { } diff --git a/lib/Sema/SemaBase.cpp b/lib/Sema/SemaBase.cpp index e87681ce67c..be926616bb0 100644 --- a/lib/Sema/SemaBase.cpp +++ b/lib/Sema/SemaBase.cpp @@ -15,7 +15,19 @@ //===----------------------------------------------------------------------===// #include "swift/Sema/SemaBase.h" +#include "swift/Sema/Sema.h" +#include "llvm/Support/SourceMgr.h" using namespace swift; SemaBase::SemaBase(Sema &s) : S(s) { } + +void SemaBase::Note(llvm::SMLoc Loc, const char *Message) { + S.Context.SourceMgr.PrintMessage(Loc, Message, "note"); +} +void SemaBase::Warning(llvm::SMLoc Loc, const char *Message) { + S.Context.SourceMgr.PrintMessage(Loc, Message, "warning"); +} +void SemaBase::Error(llvm::SMLoc Loc, const char *Message) { + S.Context.SourceMgr.PrintMessage(Loc, Message, "error"); +}