give ASTContext a SourceMgr reference, add diagnostic hooks to SemaBase.

Swift SVN r39
This commit is contained in:
Chris Lattner
2010-07-19 05:13:55 +00:00
parent c5e54442b4
commit 2eeee5faca
6 changed files with 26 additions and 7 deletions

View File

@@ -19,6 +19,7 @@
namespace llvm { namespace llvm {
class BumpPtrAllocator; class BumpPtrAllocator;
class SourceMgr;
} }
namespace swift { namespace swift {
@@ -30,9 +31,12 @@ class ASTContext {
void operator=(const ASTContext&); // DO NOT IMPLEMENT void operator=(const ASTContext&); // DO NOT IMPLEMENT
llvm::BumpPtrAllocator *Allocator; llvm::BumpPtrAllocator *Allocator;
public: public:
ASTContext(); ASTContext(llvm::SourceMgr &SourceMgr);
~ASTContext(); ~ASTContext();
/// SourceMgr - The source manager object.
llvm::SourceMgr &SourceMgr;
Type * const VoidType; /// VoidType - This is 'void'. Type * const VoidType; /// VoidType - This is 'void'.
Type * const IntType; /// IntType - This is 'int'. Type * const IntType; /// IntType - This is 'int'.

View File

@@ -42,7 +42,7 @@ class Parser {
Parser(const Parser&); // DO NOT IMPLEMENT Parser(const Parser&); // DO NOT IMPLEMENT
void operator=(const Parser&); // DO NOT IMPLEMENT void operator=(const Parser&); // DO NOT IMPLEMENT
public: public:
Parser(unsigned BufferID, llvm::SourceMgr &SM, ASTContext &Context); Parser(unsigned BufferID, ASTContext &Context);
~Parser(); ~Parser();
void ParseTranslationUnit(); void ParseTranslationUnit();

View File

@@ -37,7 +37,9 @@ protected:
public: public:
SemaBase(Sema &s); 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 } // end namespace swift

View File

@@ -19,8 +19,9 @@
#include "llvm/Support/Allocator.h" #include "llvm/Support/Allocator.h"
using namespace swift; using namespace swift;
ASTContext::ASTContext() ASTContext::ASTContext(llvm::SourceMgr &sourcemgr)
: Allocator(new llvm::BumpPtrAllocator()), : Allocator(new llvm::BumpPtrAllocator()),
SourceMgr(sourcemgr),
VoidType(new (*this) BuiltinType(BuiltinVoidKind)), VoidType(new (*this) BuiltinType(BuiltinVoidKind)),
IntType(new (*this) BuiltinType(BuiltinIntKind)) { IntType(new (*this) BuiltinType(BuiltinIntKind)) {
} }

View File

@@ -27,9 +27,9 @@ using llvm::SMLoc;
// Setup and Helper Methods // Setup and Helper Methods
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
Parser::Parser(unsigned BufferID, llvm::SourceMgr &SM, ASTContext &Context) Parser::Parser(unsigned BufferID, ASTContext &Context)
: SourceMgr(SM), : SourceMgr(Context.SourceMgr),
L(*new Lexer(BufferID, SM)), L(*new Lexer(BufferID, SourceMgr)),
S(*new Sema(Context)) { S(*new Sema(Context)) {
} }

View File

@@ -15,7 +15,19 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "swift/Sema/SemaBase.h" #include "swift/Sema/SemaBase.h"
#include "swift/Sema/Sema.h"
#include "llvm/Support/SourceMgr.h"
using namespace swift; using namespace swift;
SemaBase::SemaBase(Sema &s) : S(s) { 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");
}