1.1 --- a/src/Scopes.h Mon Sep 17 00:10:01 2012 -0700
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,120 +0,0 @@
1.4 -/*
1.5 - * Copyright (C) 2012 David Anderson
1.6 - *
1.7 - * This file is part of JITCraft.
1.8 - *
1.9 - * JITCraft is free software: you can redistribute it and/or modify it under
1.10 - * the terms of the GNU General Public License as published by the Free
1.11 - * Software Foundation, either version 3 of the License, or (at your option)
1.12 - * any later version.
1.13 - *
1.14 - * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
1.15 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.16 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.17 - *
1.18 - * You should have received a copy of the GNU General Public License along with
1.19 - * JITCraft. If not, see http://www.gnu.org/licenses/.
1.20 - */
1.21 -#ifndef _include_jitcraft_scopes_h_
1.22 -#define _include_jitcraft_scopes_h_
1.23 -
1.24 -#include "PoolAllocator.h"
1.25 -#include "AST.h"
1.26 -#include "NameBinding.h"
1.27 -#include "Structures.h"
1.28 -
1.29 -namespace ke {
1.30 -
1.31 -class CompileContext;
1.32 -class EnvironmentMap;
1.33 -
1.34 -class Scope : public PoolObject
1.35 -{
1.36 - PoolAllocator &pool_;
1.37 - PoolList<BoundName *> names_;
1.38 - PoolList<Scope *> children_;
1.39 - PoolList<Variable *> parameters_;
1.40 - unsigned locals_;
1.41 - unsigned maxContainedLocals_;
1.42 - unsigned numFunctions_;
1.43 - unsigned numNatives_;
1.44 - PoolList<Variable *> envVars_;
1.45 - Variable *lifoSlot_;
1.46 -
1.47 - bool empty() const {
1.48 - return names_.length() == 0;
1.49 - }
1.50 - void unlink();
1.51 -
1.52 - public:
1.53 - enum Kind {
1.54 - GLOBAL,
1.55 - FUNCTION,
1.56 - BLOCK
1.57 - };
1.58 -
1.59 - public:
1.60 - Scope(PoolAllocator &pool, Kind kind, Scope *enclosing);
1.61 - bool initialize();
1.62 -
1.63 - Kind kind() const {
1.64 - return kind_;
1.65 - }
1.66 - Scope *enclosing() const {
1.67 - return enclosing_;
1.68 - }
1.69 - unsigned locals() const {
1.70 - return locals_;
1.71 - }
1.72 - unsigned maxContainedLocals() const {
1.73 - return maxContainedLocals_;
1.74 - }
1.75 - unsigned numFunctions() const {
1.76 - return numFunctions_;
1.77 - }
1.78 - unsigned numNatives() const {
1.79 - return numNatives_;
1.80 - }
1.81 - unsigned numArguments() const {
1.82 - return parameters_.length();
1.83 - }
1.84 - unsigned numEnvironmentVars() const {
1.85 - return envVars_.length();
1.86 - }
1.87 - Variable *getArgument(size_t index) {
1.88 - return parameters_[index];
1.89 - }
1.90 - Variable *lifoSlot() {
1.91 - return lifoSlot_;
1.92 - }
1.93 - void setUsesLifoHeap();
1.94 -
1.95 - Scope *unlinkIfEmpty();
1.96 - BoundName *localLookup(Handle<String> name);
1.97 - BoundName *lookup(Handle<String> name);
1.98 -
1.99 - NamedFunction *declareFunction(Handle<String> name, const SourcePosition &pos, TokenKind token);
1.100 - Variable *declareVariable(Handle<String> name, const SourcePosition &pos);
1.101 - Variable *declareArgument(Handle<String> name, const SourcePosition &pos);
1.102 - NamedConstant *declareConstant(Handle<String> name, const SourcePosition &pos);
1.103 - NamedType *declareType(Handle<String> name, const SourcePosition &pos);
1.104 - NamedType *declareType(Handle<String> name, Handle<Type> type);
1.105 -
1.106 - EnvironmentMap *createEnvironmentMap(Zone *zone);
1.107 -
1.108 - void allocate(Variable *var);
1.109 - void allocate();
1.110 - void allocateGlobals();
1.111 -
1.112 - public:
1.113 - static bool Bind(CompileContext &cc, ParseTree *tree);
1.114 - static void Allocate(ParseTree *tree);
1.115 -
1.116 - private:
1.117 - Kind kind_;
1.118 - Scope *enclosing_;
1.119 -};
1.120 -
1.121 -}
1.122 -
1.123 -#endif // _include_jitcraft_scopes_h_