diff -r 82b1f8bc93a9 -r 0998a43cc155 src/compiler/CompileContext.h --- a/src/compiler/CompileContext.h Sat Dec 29 00:12:27 2012 -0800 +++ b/src/compiler/CompileContext.h Sat Dec 29 00:55:38 2012 -0800 @@ -36,19 +36,38 @@ struct TranslationUnit; class ImportStatement; -struct TranslationUnit : public PoolObject +struct CompileError +{ + CompileError() + : message(NULL) + { + } + CompileError(unsigned line, unsigned col, const char *message) + : line(line), + col(col), + message(message) + { + } + + unsigned line; + unsigned col; + const char *message; +}; + +struct TranslationUnit { TranslationUnit() : tree_(NULL), - failed_(false), importScope_(NULL), - globalScope_(NULL) + globalScope_(NULL), + oom_(false), + dependencyFailed_(false) { } + ~TranslationUnit(); ParseTree *tree_; const char *path_; - bool failed_; PoolList dependents_; ImportScope *importScope_; GlobalScope *globalScope_; @@ -61,7 +80,9 @@ return dependents_; } bool failed() const { - return failed_; + return errors_.length() || + oom_ || + dependencyFailed_; } void setImportScope(ImportScope *scope) { assert(!importScope_); @@ -77,20 +98,38 @@ GlobalScope *globalScope() const { return globalScope_; } + + void setDependencyFailed() { + dependencyFailed_ = true; + } + void setOutOfMemory() { + oom_ = true; + } + void appendError(const char *report, unsigned line, unsigned col) { + oom_ |= errors_.append(CompileError(line, col, report)); + } + const Vector *errors() { + return &errors_; + } + + private: + bool oom_; + bool dependencyFailed_; + Vector errors_; }; class CompileContext { Zone *zone_; - unsigned failures_; const char *file_; Vector units_; Vector unparsed_; + TranslationUnit *active_; private: char *loadSource(const char *file, size_t *length); bool parse(TranslationUnit *unit); - bool evaluateImports(TranslationUnit *unit); + void evaluateImports(TranslationUnit *unit); bool propagateFailure(); public: @@ -99,15 +138,28 @@ bool addTranslationUnit(TranslationUnit *unit); bool compile(); + void enter(TranslationUnit *unit); + void leave(); void reportErrorVa(const SourcePosition &pos, Message msg, va_list ap); void reportError(const SourcePosition &pos, Message msg, ...); +}; - unsigned failures() const { - return failures_; +class AutoEnterCompileContext +{ + CompileContext &cc_; + + public: + AutoEnterCompileContext(CompileContext &cc, TranslationUnit *unit) + : cc_(cc) + { + cc_.enter(unit); + } + ~AutoEnterCompileContext() { + cc_.leave(); } }; -} +} // namespace ke #endif // _include_jitcraft_compile_context_h_