1.1 --- a/src/compiler/CompileContext.h Sat Dec 29 00:12:27 2012 -0800
1.2 +++ b/src/compiler/CompileContext.h Sat Dec 29 00:55:38 2012 -0800
1.3 @@ -36,19 +36,38 @@
1.4 struct TranslationUnit;
1.5 class ImportStatement;
1.6
1.7 -struct TranslationUnit : public PoolObject
1.8 +struct CompileError
1.9 +{
1.10 + CompileError()
1.11 + : message(NULL)
1.12 + {
1.13 + }
1.14 + CompileError(unsigned line, unsigned col, const char *message)
1.15 + : line(line),
1.16 + col(col),
1.17 + message(message)
1.18 + {
1.19 + }
1.20 +
1.21 + unsigned line;
1.22 + unsigned col;
1.23 + const char *message;
1.24 +};
1.25 +
1.26 +struct TranslationUnit
1.27 {
1.28 TranslationUnit()
1.29 : tree_(NULL),
1.30 - failed_(false),
1.31 importScope_(NULL),
1.32 - globalScope_(NULL)
1.33 + globalScope_(NULL),
1.34 + oom_(false),
1.35 + dependencyFailed_(false)
1.36 {
1.37 }
1.38 + ~TranslationUnit();
1.39
1.40 ParseTree *tree_;
1.41 const char *path_;
1.42 - bool failed_;
1.43 PoolList<TranslationUnit *> dependents_;
1.44 ImportScope *importScope_;
1.45 GlobalScope *globalScope_;
1.46 @@ -61,7 +80,9 @@
1.47 return dependents_;
1.48 }
1.49 bool failed() const {
1.50 - return failed_;
1.51 + return errors_.length() ||
1.52 + oom_ ||
1.53 + dependencyFailed_;
1.54 }
1.55 void setImportScope(ImportScope *scope) {
1.56 assert(!importScope_);
1.57 @@ -77,20 +98,38 @@
1.58 GlobalScope *globalScope() const {
1.59 return globalScope_;
1.60 }
1.61 +
1.62 + void setDependencyFailed() {
1.63 + dependencyFailed_ = true;
1.64 + }
1.65 + void setOutOfMemory() {
1.66 + oom_ = true;
1.67 + }
1.68 + void appendError(const char *report, unsigned line, unsigned col) {
1.69 + oom_ |= errors_.append(CompileError(line, col, report));
1.70 + }
1.71 + const Vector<CompileError> *errors() {
1.72 + return &errors_;
1.73 + }
1.74 +
1.75 + private:
1.76 + bool oom_;
1.77 + bool dependencyFailed_;
1.78 + Vector<CompileError> errors_;
1.79 };
1.80
1.81 class CompileContext
1.82 {
1.83 Zone *zone_;
1.84 - unsigned failures_;
1.85 const char *file_;
1.86 Vector<TranslationUnit *> units_;
1.87 Vector<TranslationUnit *> unparsed_;
1.88 + TranslationUnit *active_;
1.89
1.90 private:
1.91 char *loadSource(const char *file, size_t *length);
1.92 bool parse(TranslationUnit *unit);
1.93 - bool evaluateImports(TranslationUnit *unit);
1.94 + void evaluateImports(TranslationUnit *unit);
1.95 bool propagateFailure();
1.96
1.97 public:
1.98 @@ -99,15 +138,28 @@
1.99
1.100 bool addTranslationUnit(TranslationUnit *unit);
1.101 bool compile();
1.102 + void enter(TranslationUnit *unit);
1.103 + void leave();
1.104
1.105 void reportErrorVa(const SourcePosition &pos, Message msg, va_list ap);
1.106 void reportError(const SourcePosition &pos, Message msg, ...);
1.107 +};
1.108
1.109 - unsigned failures() const {
1.110 - return failures_;
1.111 +class AutoEnterCompileContext
1.112 +{
1.113 + CompileContext &cc_;
1.114 +
1.115 + public:
1.116 + AutoEnterCompileContext(CompileContext &cc, TranslationUnit *unit)
1.117 + : cc_(cc)
1.118 + {
1.119 + cc_.enter(unit);
1.120 + }
1.121 + ~AutoEnterCompileContext() {
1.122 + cc_.leave();
1.123 }
1.124 };
1.125
1.126 -}
1.127 +} // namespace ke
1.128
1.129 #endif // _include_jitcraft_compile_context_h_