diff -r b029d63565a2 -r c1ba166f3fc4 src/Scopes.h --- a/src/Scopes.h Mon Sep 17 00:10:01 2012 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2012 David Anderson - * - * This file is part of JITCraft. - * - * JITCraft 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. - * - * Foobar 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 - * JITCraft. If not, see http://www.gnu.org/licenses/. - */ -#ifndef _include_jitcraft_scopes_h_ -#define _include_jitcraft_scopes_h_ - -#include "PoolAllocator.h" -#include "AST.h" -#include "NameBinding.h" -#include "Structures.h" - -namespace ke { - -class CompileContext; -class EnvironmentMap; - -class Scope : public PoolObject -{ - PoolAllocator &pool_; - PoolList names_; - PoolList children_; - PoolList parameters_; - unsigned locals_; - unsigned maxContainedLocals_; - unsigned numFunctions_; - unsigned numNatives_; - PoolList envVars_; - Variable *lifoSlot_; - - bool empty() const { - return names_.length() == 0; - } - void unlink(); - - public: - enum Kind { - GLOBAL, - FUNCTION, - BLOCK - }; - - public: - Scope(PoolAllocator &pool, Kind kind, Scope *enclosing); - bool initialize(); - - Kind kind() const { - return kind_; - } - Scope *enclosing() const { - return enclosing_; - } - unsigned locals() const { - return locals_; - } - unsigned maxContainedLocals() const { - return maxContainedLocals_; - } - unsigned numFunctions() const { - return numFunctions_; - } - unsigned numNatives() const { - return numNatives_; - } - unsigned numArguments() const { - return parameters_.length(); - } - unsigned numEnvironmentVars() const { - return envVars_.length(); - } - Variable *getArgument(size_t index) { - return parameters_[index]; - } - Variable *lifoSlot() { - return lifoSlot_; - } - void setUsesLifoHeap(); - - Scope *unlinkIfEmpty(); - BoundName *localLookup(Handle name); - BoundName *lookup(Handle name); - - NamedFunction *declareFunction(Handle name, const SourcePosition &pos, TokenKind token); - Variable *declareVariable(Handle name, const SourcePosition &pos); - Variable *declareArgument(Handle name, const SourcePosition &pos); - NamedConstant *declareConstant(Handle name, const SourcePosition &pos); - NamedType *declareType(Handle name, const SourcePosition &pos); - NamedType *declareType(Handle name, Handle type); - - EnvironmentMap *createEnvironmentMap(Zone *zone); - - void allocate(Variable *var); - void allocate(); - void allocateGlobals(); - - public: - static bool Bind(CompileContext &cc, ParseTree *tree); - static void Allocate(ParseTree *tree); - - private: - Kind kind_; - Scope *enclosing_; -}; - -} - -#endif // _include_jitcraft_scopes_h_