Collect error messages per-translation unit.
2 * Copyright (C) 2012 David Anderson
4 * This file is part of JITCraft.
6 * JITCraft is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * JITCraft. If not, see http://www.gnu.org/licenses/.
18 #ifndef _include_jitcraft_compile_context_h_
19 #define _include_jitcraft_compile_context_h_
23 #include "../Messages.h"
24 #include "../PoolAllocator.h"
25 #include "../Handles.h"
26 #include "../Modules.h"
35 struct SourcePosition;
36 struct TranslationUnit;
37 class ImportStatement;
45 CompileError(unsigned line, unsigned col, const char *message)
57 struct TranslationUnit
64 dependencyFailed_(false)
71 PoolList<TranslationUnit *> dependents_;
72 ImportScope *importScope_;
73 GlobalScope *globalScope_;
74 ScopedRoot<Module> module_;
76 ParseTree *tree() const {
79 PoolList<TranslationUnit *> &dependents() {
83 return errors_.length() ||
87 void setImportScope(ImportScope *scope) {
88 assert(!importScope_);
91 void setGlobalScope(GlobalScope *scope) {
92 assert(!globalScope_);
95 ImportScope *importScope() const {
98 GlobalScope *globalScope() const {
102 void setDependencyFailed() {
103 dependencyFailed_ = true;
105 void setOutOfMemory() {
108 void appendError(const char *report, unsigned line, unsigned col) {
109 oom_ |= errors_.append(CompileError(line, col, report));
111 const Vector<CompileError> *errors() {
117 bool dependencyFailed_;
118 Vector<CompileError> errors_;
125 Vector<TranslationUnit *> units_;
126 Vector<TranslationUnit *> unparsed_;
127 TranslationUnit *active_;
130 char *loadSource(const char *file, size_t *length);
131 bool parse(TranslationUnit *unit);
132 void evaluateImports(TranslationUnit *unit);
133 bool propagateFailure();
136 CompileContext(Zone *zone, const char *file);
139 bool addTranslationUnit(TranslationUnit *unit);
141 void enter(TranslationUnit *unit);
144 void reportErrorVa(const SourcePosition &pos, Message msg, va_list ap);
145 void reportError(const SourcePosition &pos, Message msg, ...);
148 class AutoEnterCompileContext
153 AutoEnterCompileContext(CompileContext &cc, TranslationUnit *unit)
158 ~AutoEnterCompileContext() {
165 #endif // _include_jitcraft_compile_context_h_