diff -r c4b1341297e5 -r ba85a47ee414 src/compiler/CompileContext.h --- a/src/compiler/CompileContext.h Mon Jun 10 00:46:29 2013 +0100 +++ b/src/compiler/CompileContext.h Mon Jun 10 01:04:43 2013 +0100 @@ -1,170 +1,170 @@ -/* - * Copyright (C) 2012 David Anderson - * - * This file is part of SourcePawn. - * - * SourcePawn is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) - * any later version. - * - * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * SourcePawn. If not, see http://www.gnu.org/licenses/. - */ -#ifndef _include_jitcraft_compile_context_h_ -#define _include_jitcraft_compile_context_h_ - -#include -#include -#include "../Messages.h" -#include "../PoolAllocator.h" -#include "../Handles.h" -#include "../Modules.h" -#include "../Packages.h" - -namespace ke { - -class Zone; -class ParseTree; -class String; -class ImportScope; -class GlobalScope; -struct SourcePosition; -struct TranslationUnit; -class ImportStatement; - -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 : public PoolObject -{ - TranslationUnit(Handle module) - : tree_(NULL), - importScope_(NULL), - globalScope_(NULL), - module_(module), - enoughMemory_(true), - dependencyFailed_(false) - { - } - - void destroy(); - - ParseTree *tree_; - PoolList dependents_; - ImportScope *importScope_; - GlobalScope *globalScope_; - ScopedRoot module_; - - ParseTree *tree() const { - return tree_; - } - PoolList &dependents() { - return dependents_; - } - bool failed() const { - return errors_.length() || - !enoughMemory_ || - dependencyFailed_; - } - void setImportScope(ImportScope *scope) { - assert(!importScope_); - importScope_ = scope; - } - void setGlobalScope(GlobalScope *scope) { - assert(!globalScope_); - globalScope_ = scope; - } - ImportScope *importScope() const { - return importScope_; - } - GlobalScope *globalScope() const { - return globalScope_; - } - Handle module() { - return module_; - } - - void setDependencyFailed() { - dependencyFailed_ = true; - } - void setOutOfMemory() { - enoughMemory_ = false; - } - void appendError(const char *report, unsigned line, unsigned col) { - enoughMemory_ |= errors_.append(CompileError(line, col, report)); - } - const Vector *errors() { - return &errors_; - } - - private: - bool enoughMemory_; - bool dependencyFailed_; - Vector errors_; -}; - -class CompileContext -{ - Zone *zone_; - Vector units_; - Vector unparsed_; - TranslationUnit *active_; - - private: - char *loadSource(Handle module, size_t *length); - bool parse(TranslationUnit *unit); - bool evaluateImports(TranslationUnit *unit); - bool propagateFailure(); - bool add(Handle module); - - public: - CompileContext(Zone *zone); - ~CompileContext(); - - bool initialize(Handle package, const char *name); - 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, ...); -}; - -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_ +/* + * Copyright (C) 2012 David Anderson + * + * This file is part of SourcePawn. + * + * SourcePawn is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * SourcePawn. If not, see http://www.gnu.org/licenses/. + */ +#ifndef _include_jitcraft_compile_context_h_ +#define _include_jitcraft_compile_context_h_ + +#include +#include +#include "../Messages.h" +#include "../PoolAllocator.h" +#include "../Handles.h" +#include "../Modules.h" +#include "../Packages.h" + +namespace ke { + +class Zone; +class ParseTree; +class String; +class ImportScope; +class GlobalScope; +struct SourcePosition; +struct TranslationUnit; +class ImportStatement; + +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 : public PoolObject +{ + TranslationUnit(Handle module) + : tree_(NULL), + importScope_(NULL), + globalScope_(NULL), + module_(module), + enoughMemory_(true), + dependencyFailed_(false) + { + } + + void destroy(); + + ParseTree *tree_; + PoolList dependents_; + ImportScope *importScope_; + GlobalScope *globalScope_; + ScopedRoot module_; + + ParseTree *tree() const { + return tree_; + } + PoolList &dependents() { + return dependents_; + } + bool failed() const { + return errors_.length() || + !enoughMemory_ || + dependencyFailed_; + } + void setImportScope(ImportScope *scope) { + assert(!importScope_); + importScope_ = scope; + } + void setGlobalScope(GlobalScope *scope) { + assert(!globalScope_); + globalScope_ = scope; + } + ImportScope *importScope() const { + return importScope_; + } + GlobalScope *globalScope() const { + return globalScope_; + } + Handle module() { + return module_; + } + + void setDependencyFailed() { + dependencyFailed_ = true; + } + void setOutOfMemory() { + enoughMemory_ = false; + } + void appendError(const char *report, unsigned line, unsigned col) { + enoughMemory_ |= errors_.append(CompileError(line, col, report)); + } + const Vector *errors() { + return &errors_; + } + + private: + bool enoughMemory_; + bool dependencyFailed_; + Vector errors_; +}; + +class CompileContext +{ + Zone *zone_; + Vector units_; + Vector unparsed_; + TranslationUnit *active_; + + private: + char *loadSource(Handle module, size_t *length); + bool parse(TranslationUnit *unit); + bool evaluateImports(TranslationUnit *unit); + bool propagateFailure(); + bool add(Handle module); + + public: + CompileContext(Zone *zone); + ~CompileContext(); + + bool initialize(Handle package, const char *name); + 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, ...); +}; + +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_