1.1 --- a/src/compiler/Scopes.h Mon Jun 10 00:46:29 2013 +0100
1.2 +++ b/src/compiler/Scopes.h Mon Jun 10 01:04:43 2013 +0100
1.3 @@ -1,125 +1,125 @@
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 "../Structures.h"
1.26 -#include "AST.h"
1.27 -#include "NameBinding.h"
1.28 -
1.29 -namespace ke {
1.30 -
1.31 -class CompileContext;
1.32 -class EnvironmentMap;
1.33 -class Struct;
1.34 -
1.35 -class Scope : public PoolObject
1.36 -{
1.37 - protected:
1.38 - PoolAllocator &pool_;
1.39 - PoolList<Symbol *> names_;
1.40 - PoolList<Scope *> children_;
1.41 -
1.42 - bool empty() const {
1.43 - return names_.length() == 0;
1.44 - }
1.45 - void unlink();
1.46 -
1.47 - public:
1.48 - enum Kind {
1.49 - IMPORT,
1.50 - GLOBAL,
1.51 - FUNCTION,
1.52 - BLOCK
1.53 - };
1.54 -
1.55 - public:
1.56 - Scope(PoolAllocator &pool, Kind kind, Scope *enclosing);
1.57 - bool initialize();
1.58 -
1.59 - Kind kind() const {
1.60 - return kind_;
1.61 - }
1.62 - Scope *enclosing() const {
1.63 - return enclosing_;
1.64 - }
1.65 -
1.66 - bool addSymbol(Symbol *symbol);
1.67 -
1.68 - Scope *unlinkIfEmpty();
1.69 - Symbol *localLookup(Handle<String> name);
1.70 - Symbol *lookup(Handle<String> name);
1.71 -
1.72 - EnvironmentMap *createEnvironmentMap(Zone *zone);
1.73 -
1.74 - void setParent(Scope *parent) {
1.75 - assert(!enclosing_ || enclosing_ == parent);
1.76 - enclosing_ = parent;
1.77 - }
1.78 -
1.79 - private:
1.80 - Kind kind_;
1.81 - Scope *enclosing_;
1.82 -};
1.83 -
1.84 -class ArgumentScope : public Scope
1.85 -{
1.86 - public:
1.87 - static ArgumentScope *New(PoolAllocator &pool);
1.88 -
1.89 - private:
1.90 - ArgumentScope(PoolAllocator &pool);
1.91 -};
1.92 -
1.93 -class LocalScope : public Scope
1.94 -{
1.95 - public:
1.96 - static LocalScope *New(PoolAllocator &pool);
1.97 -
1.98 - private:
1.99 - LocalScope(PoolAllocator &pool);
1.100 -};
1.101 -
1.102 -class GlobalScope : public Scope
1.103 -{
1.104 - public:
1.105 - static GlobalScope *New(PoolAllocator &pool, ImportScope *parent);
1.106 -
1.107 - PoolList<Symbol *> *exported() {
1.108 - return &exported_;
1.109 - }
1.110 - Symbol *findExported(Handle<String> name);
1.111 -
1.112 - private:
1.113 - GlobalScope(PoolAllocator &pool, ImportScope *parent);
1.114 - PoolList<Symbol *> exported_;
1.115 -};
1.116 -
1.117 -class ImportScope : public Scope
1.118 -{
1.119 - public:
1.120 - static ImportScope *New(PoolAllocator &pool);
1.121 -
1.122 - private:
1.123 - ImportScope(PoolAllocator &pool);
1.124 -};
1.125 -
1.126 -}
1.127 -
1.128 -#endif // _include_jitcraft_scopes_h_
1.129 +/*
1.130 + * Copyright (C) 2012 David Anderson
1.131 + *
1.132 + * This file is part of JITCraft.
1.133 + *
1.134 + * JITCraft is free software: you can redistribute it and/or modify it under
1.135 + * the terms of the GNU General Public License as published by the Free
1.136 + * Software Foundation, either version 3 of the License, or (at your option)
1.137 + * any later version.
1.138 + *
1.139 + * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
1.140 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.141 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.142 + *
1.143 + * You should have received a copy of the GNU General Public License along with
1.144 + * JITCraft. If not, see http://www.gnu.org/licenses/.
1.145 + */
1.146 +#ifndef _include_jitcraft_scopes_h_
1.147 +#define _include_jitcraft_scopes_h_
1.148 +
1.149 +#include "../PoolAllocator.h"
1.150 +#include "../Structures.h"
1.151 +#include "AST.h"
1.152 +#include "NameBinding.h"
1.153 +
1.154 +namespace ke {
1.155 +
1.156 +class CompileContext;
1.157 +class EnvironmentMap;
1.158 +class Struct;
1.159 +
1.160 +class Scope : public PoolObject
1.161 +{
1.162 + protected:
1.163 + PoolAllocator &pool_;
1.164 + PoolList<Symbol *> names_;
1.165 + PoolList<Scope *> children_;
1.166 +
1.167 + bool empty() const {
1.168 + return names_.length() == 0;
1.169 + }
1.170 + void unlink();
1.171 +
1.172 + public:
1.173 + enum Kind {
1.174 + IMPORT,
1.175 + GLOBAL,
1.176 + FUNCTION,
1.177 + BLOCK
1.178 + };
1.179 +
1.180 + public:
1.181 + Scope(PoolAllocator &pool, Kind kind, Scope *enclosing);
1.182 + bool initialize();
1.183 +
1.184 + Kind kind() const {
1.185 + return kind_;
1.186 + }
1.187 + Scope *enclosing() const {
1.188 + return enclosing_;
1.189 + }
1.190 +
1.191 + bool addSymbol(Symbol *symbol);
1.192 +
1.193 + Scope *unlinkIfEmpty();
1.194 + Symbol *localLookup(Handle<String> name);
1.195 + Symbol *lookup(Handle<String> name);
1.196 +
1.197 + EnvironmentMap *createEnvironmentMap(Zone *zone);
1.198 +
1.199 + void setParent(Scope *parent) {
1.200 + assert(!enclosing_ || enclosing_ == parent);
1.201 + enclosing_ = parent;
1.202 + }
1.203 +
1.204 + private:
1.205 + Kind kind_;
1.206 + Scope *enclosing_;
1.207 +};
1.208 +
1.209 +class ArgumentScope : public Scope
1.210 +{
1.211 + public:
1.212 + static ArgumentScope *New(PoolAllocator &pool);
1.213 +
1.214 + private:
1.215 + ArgumentScope(PoolAllocator &pool);
1.216 +};
1.217 +
1.218 +class LocalScope : public Scope
1.219 +{
1.220 + public:
1.221 + static LocalScope *New(PoolAllocator &pool);
1.222 +
1.223 + private:
1.224 + LocalScope(PoolAllocator &pool);
1.225 +};
1.226 +
1.227 +class GlobalScope : public Scope
1.228 +{
1.229 + public:
1.230 + static GlobalScope *New(PoolAllocator &pool, ImportScope *parent);
1.231 +
1.232 + PoolList<Symbol *> *exported() {
1.233 + return &exported_;
1.234 + }
1.235 + Symbol *findExported(Handle<String> name);
1.236 +
1.237 + private:
1.238 + GlobalScope(PoolAllocator &pool, ImportScope *parent);
1.239 + PoolList<Symbol *> exported_;
1.240 +};
1.241 +
1.242 +class ImportScope : public Scope
1.243 +{
1.244 + public:
1.245 + static ImportScope *New(PoolAllocator &pool);
1.246 +
1.247 + private:
1.248 + ImportScope(PoolAllocator &pool);
1.249 +};
1.250 +
1.251 +}
1.252 +
1.253 +#endif // _include_jitcraft_scopes_h_