@agoric/xsnap 0.14.3-u14.0 → 0.14.3-u16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/api.js +4 -2
- package/build.env +1 -1
- package/moddable/modules/data/base64/base64.js +28 -0
- package/moddable/modules/data/base64/manifest.json +11 -0
- package/moddable/modules/data/base64/modBase64.c +188 -0
- package/moddable/modules/data/binaryMessage/BinaryMessage.js +106 -0
- package/moddable/modules/data/crc/crc.c +205 -0
- package/moddable/modules/data/crc/crc.js +36 -0
- package/moddable/modules/data/crc/manifest.json +8 -0
- package/moddable/modules/data/hex/hex.js +28 -0
- package/moddable/modules/data/hex/manifest.json +11 -0
- package/moddable/modules/data/hex/modHex.c +139 -0
- package/moddable/modules/data/logical/logical.js +32 -0
- package/moddable/modules/data/logical/modLogical.c +98 -0
- package/moddable/modules/data/qrcode/manifest.json +9 -0
- package/moddable/modules/data/qrcode/qrcode.c +93 -0
- package/moddable/modules/data/qrcode/qrcode.js +23 -0
- package/moddable/modules/data/qrcode/qrcodegen.c +1025 -0
- package/moddable/modules/data/qrcode/qrcodegen.h +267 -0
- package/moddable/modules/data/text/decoder/manifest.json +8 -0
- package/moddable/modules/data/text/decoder/textdecoder.c +480 -0
- package/moddable/modules/data/text/decoder/textdecoder.js +27 -0
- package/moddable/modules/data/text/encoder/manifest.json +8 -0
- package/moddable/modules/data/text/encoder/textencoder.c +232 -0
- package/moddable/modules/data/text/encoder/textencoder.js +24 -0
- package/moddable/modules/data/tinyint/tinyint.c +150 -0
- package/moddable/modules/data/tinyint/tinyint.js +53 -0
- package/moddable/modules/data/url/manifest.json +17 -0
- package/moddable/modules/data/url/url.c +1959 -0
- package/moddable/modules/data/url/url.js +210 -0
- package/moddable/modules/data/wavreader/manifest.json +8 -0
- package/moddable/modules/data/wavreader/wavreader.js +128 -0
- package/moddable/modules/data/zlib/deflate.c +161 -0
- package/moddable/modules/data/zlib/deflate.js +63 -0
- package/moddable/modules/data/zlib/inflate.c +145 -0
- package/moddable/modules/data/zlib/inflate.js +66 -0
- package/moddable/modules/data/zlib/manifest_deflate.json +9 -0
- package/moddable/modules/data/zlib/manifest_inflate.json +9 -0
- package/moddable/modules/data/zlib/miniz.c +4924 -0
- package/moddable/xs/includes/xs.d.ts +73 -0
- package/moddable/xs/includes/xs.h +1533 -0
- package/moddable/xs/includes/xsmc.h +206 -0
- package/moddable/xs/makefiles/lin/makefile +33 -0
- package/moddable/xs/makefiles/lin/xsc.mk +118 -0
- package/moddable/xs/makefiles/lin/xsid.mk +90 -0
- package/moddable/xs/makefiles/lin/xsl.mk +168 -0
- package/moddable/xs/makefiles/lin/xst.mk +201 -0
- package/moddable/xs/makefiles/mac/makefile +33 -0
- package/moddable/xs/makefiles/mac/xsc.mk +130 -0
- package/moddable/xs/makefiles/mac/xsid.mk +102 -0
- package/moddable/xs/makefiles/mac/xsl.mk +177 -0
- package/moddable/xs/makefiles/mac/xst.mk +203 -0
- package/moddable/xs/makefiles/mac/xst_no_asan.txt +52 -0
- package/moddable/xs/makefiles/win/build.bat +26 -0
- package/moddable/xs/makefiles/win/xsc.mak +142 -0
- package/moddable/xs/makefiles/win/xsid.mak +113 -0
- package/moddable/xs/makefiles/win/xsl.mak +186 -0
- package/moddable/xs/makefiles/win/xst.mak +195 -0
- package/moddable/xs/platforms/lin_xs.h +99 -0
- package/moddable/xs/platforms/mac_xs.h +97 -0
- package/moddable/xs/platforms/wasm_xs.h +79 -0
- package/moddable/xs/platforms/win_xs.h +104 -0
- package/moddable/xs/platforms/xsHost.h +63 -0
- package/moddable/xs/platforms/xsPlatform.h +618 -0
- package/moddable/xs/sources/xsAPI.c +2555 -0
- package/moddable/xs/sources/xsAll.c +294 -0
- package/moddable/xs/sources/xsAll.h +2741 -0
- package/moddable/xs/sources/xsArguments.c +222 -0
- package/moddable/xs/sources/xsArray.c +2657 -0
- package/moddable/xs/sources/xsAtomics.c +844 -0
- package/moddable/xs/sources/xsBigInt.c +1859 -0
- package/moddable/xs/sources/xsBoolean.c +109 -0
- package/moddable/xs/sources/xsCode.c +4493 -0
- package/moddable/xs/sources/xsCommon.c +1710 -0
- package/moddable/xs/sources/xsCommon.h +1142 -0
- package/moddable/xs/sources/xsDataView.c +2890 -0
- package/moddable/xs/sources/xsDate.c +1541 -0
- package/moddable/xs/sources/xsDebug.c +2710 -0
- package/moddable/xs/sources/xsDefaults.c +134 -0
- package/moddable/xs/sources/xsError.c +353 -0
- package/moddable/xs/sources/xsFunction.c +776 -0
- package/moddable/xs/sources/xsGenerator.c +865 -0
- package/moddable/xs/sources/xsGlobal.c +839 -0
- package/moddable/xs/sources/xsJSON.c +1091 -0
- package/moddable/xs/sources/xsLexical.c +1969 -0
- package/moddable/xs/sources/xsLockdown.c +933 -0
- package/moddable/xs/sources/xsMapSet.c +1649 -0
- package/moddable/xs/sources/xsMarshall.c +1020 -0
- package/moddable/xs/sources/xsMath.c +624 -0
- package/moddable/xs/sources/xsMemory.c +1941 -0
- package/moddable/xs/sources/xsModule.c +3101 -0
- package/moddable/xs/sources/xsNumber.c +560 -0
- package/moddable/xs/sources/xsObject.c +1102 -0
- package/moddable/xs/sources/xsPlatforms.c +480 -0
- package/moddable/xs/sources/xsProfile.c +577 -0
- package/moddable/xs/sources/xsPromise.c +1199 -0
- package/moddable/xs/sources/xsProperty.c +636 -0
- package/moddable/xs/sources/xsProxy.c +1014 -0
- package/moddable/xs/sources/xsRegExp.c +1168 -0
- package/moddable/xs/sources/xsRun.c +4889 -0
- package/moddable/xs/sources/xsScope.c +1293 -0
- package/moddable/xs/sources/xsScript.c +288 -0
- package/moddable/xs/sources/xsScript.h +1186 -0
- package/moddable/xs/sources/xsSnapshot.c +2161 -0
- package/moddable/xs/sources/xsSnapshot.h +51 -0
- package/moddable/xs/sources/xsSourceMap.c +218 -0
- package/moddable/xs/sources/xsString.c +3332 -0
- package/moddable/xs/sources/xsSymbol.c +503 -0
- package/moddable/xs/sources/xsSyntaxical.c +4193 -0
- package/moddable/xs/sources/xsTree.c +1893 -0
- package/moddable/xs/sources/xsType.c +1488 -0
- package/moddable/xs/sources/xsdtoa.c +6672 -0
- package/moddable/xs/sources/xsmc.c +340 -0
- package/moddable/xs/sources/xsre.c +7578 -0
- package/package.json +37 -20
- package/scripts/get_xsnap_version.sh +14 -0
- package/scripts/test-package.sh +21 -0
- package/src/avaAssertXS.js +6 -2
- package/src/avaHandler.cjs +2 -5
- package/src/avaXS.js +7 -8
- package/src/build.js +161 -28
- package/src/replay.js +0 -3
- package/src/xsnap.js +105 -91
- package/src/xsrepl.js +2 -3
- package/xsnap-native/xsnap/makefiles/lin/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +156 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +144 -0
- package/xsnap-native/xsnap/makefiles/mac/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +165 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +153 -0
- package/xsnap-native/xsnap/sources/xsnap-worker.c +1008 -0
- package/xsnap-native/xsnap/sources/xsnap.c +717 -0
- package/xsnap-native/xsnap/sources/xsnap.h +142 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.c +1501 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.h +105 -0
- package/CHANGELOG.md +0 -654
|
@@ -0,0 +1,1293 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-2017 Moddable Tech, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of the Moddable SDK Runtime.
|
|
5
|
+
*
|
|
6
|
+
* The Moddable SDK Runtime is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* The Moddable SDK Runtime is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU Lesser General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
* along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*
|
|
19
|
+
* This file incorporates work covered by the following copyright and
|
|
20
|
+
* permission notice:
|
|
21
|
+
*
|
|
22
|
+
* Copyright (C) 2010-2016 Marvell International Ltd.
|
|
23
|
+
* Copyright (C) 2002-2010 Kinoma, Inc.
|
|
24
|
+
*
|
|
25
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
26
|
+
* you may not use this file except in compliance with the License.
|
|
27
|
+
* You may obtain a copy of the License at
|
|
28
|
+
*
|
|
29
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
30
|
+
*
|
|
31
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
32
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
33
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
34
|
+
* See the License for the specific language governing permissions and
|
|
35
|
+
* limitations under the License.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
#include "xsScript.h"
|
|
39
|
+
|
|
40
|
+
#define mxBindHoistPart\
|
|
41
|
+
txParser* parser;\
|
|
42
|
+
txScope* scope
|
|
43
|
+
|
|
44
|
+
typedef struct sxExportlink txExportLink;
|
|
45
|
+
|
|
46
|
+
typedef struct {
|
|
47
|
+
mxBindHoistPart;
|
|
48
|
+
txInteger scopeLevel;
|
|
49
|
+
txInteger scopeMaximum;
|
|
50
|
+
txClassNode* classNode;
|
|
51
|
+
} txBinder;
|
|
52
|
+
|
|
53
|
+
typedef struct {
|
|
54
|
+
mxBindHoistPart;
|
|
55
|
+
txScope* functionScope;
|
|
56
|
+
txScope* bodyScope;
|
|
57
|
+
txNode* environmentNode;
|
|
58
|
+
txExportLink* firstExportLink;
|
|
59
|
+
txClassNode* classNode;
|
|
60
|
+
} txHoister;
|
|
61
|
+
|
|
62
|
+
struct sxExportlink {
|
|
63
|
+
txExportLink* next;
|
|
64
|
+
txSymbol* symbol;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
static void fxHoisterAddExportLink(txHoister* self, txSpecifierNode* specifier);
|
|
68
|
+
static void fxBinderPopVariables(txBinder* self, txInteger count);
|
|
69
|
+
static void fxBinderPushVariables(txBinder* self, txInteger count);
|
|
70
|
+
static txScope* fxScopeNew(txHoister* hoister, txNode* node, txToken token);
|
|
71
|
+
static void fxScopeAddDeclareNode(txScope* self, txDeclareNode* node);
|
|
72
|
+
static void fxScopeAddDefineNode(txScope* self, txDefineNode* node);
|
|
73
|
+
static void fxScopeBindDefineNodes(txScope* self, void* param);
|
|
74
|
+
static void fxScopeBinding(txScope* self, txBinder* binder);
|
|
75
|
+
static void fxScopeBound(txScope* self, txBinder* binder);
|
|
76
|
+
static void fxScopeEval(txScope* self);
|
|
77
|
+
static txDeclareNode* fxScopeGetDeclareNode(txScope* self, txSymbol* symbol);
|
|
78
|
+
static void fxScopeHoisted(txScope* self, txHoister* hoister);
|
|
79
|
+
static void fxScopeLookup(txScope* self, txAccessNode* access, txBoolean closureFlag);
|
|
80
|
+
|
|
81
|
+
static void fxNodeDispatchBind(void* it, void* param);
|
|
82
|
+
static void fxNodeDispatchHoist(void* it, void* param);
|
|
83
|
+
static void fxFunctionNodeRename(void* it, txSymbol* symbol);
|
|
84
|
+
|
|
85
|
+
void fxParserBind(txParser* parser)
|
|
86
|
+
{
|
|
87
|
+
txBinder binder;
|
|
88
|
+
c_memset(&binder, 0, sizeof(txBinder));
|
|
89
|
+
binder.parser = parser;
|
|
90
|
+
if (parser->errorCount == 0) {
|
|
91
|
+
mxTryParser(parser) {
|
|
92
|
+
fxNodeDispatchBind(parser->root, &binder);
|
|
93
|
+
}
|
|
94
|
+
mxCatchParser(parser) {
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
void fxParserHoist(txParser* parser)
|
|
100
|
+
{
|
|
101
|
+
txHoister hoister;
|
|
102
|
+
c_memset(&hoister, 0, sizeof(txHoister));
|
|
103
|
+
hoister.parser = parser;
|
|
104
|
+
if (parser->errorCount == 0) {
|
|
105
|
+
mxTryParser(parser) {
|
|
106
|
+
fxNodeDispatchHoist(parser->root, &hoister);
|
|
107
|
+
}
|
|
108
|
+
mxCatchParser(parser) {
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void fxHoisterAddExportLink(txHoister* self, txSpecifierNode* specifier)
|
|
114
|
+
{
|
|
115
|
+
txExportLink* link = self->firstExportLink;
|
|
116
|
+
txSymbol* symbol = specifier->asSymbol ? specifier->asSymbol : specifier->symbol;
|
|
117
|
+
if (symbol) {
|
|
118
|
+
while (link) {
|
|
119
|
+
if (link->symbol == symbol) {
|
|
120
|
+
fxReportParserError(self->parser, specifier->line, "duplicate export %s", symbol->string);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
link = link->next;
|
|
124
|
+
}
|
|
125
|
+
link = fxNewParserChunk(self->parser, sizeof(txExportLink));
|
|
126
|
+
link->next = self->firstExportLink;
|
|
127
|
+
link->symbol = symbol;
|
|
128
|
+
self->firstExportLink = link;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
void fxBinderPopVariables(txBinder* self, txInteger count)
|
|
133
|
+
{
|
|
134
|
+
self->scopeLevel -= count;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
void fxBinderPushVariables(txBinder* self, txInteger count)
|
|
138
|
+
{
|
|
139
|
+
self->scopeLevel += count;
|
|
140
|
+
if (self->scopeMaximum < self->scopeLevel)
|
|
141
|
+
self->scopeMaximum = self->scopeLevel;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
txScope* fxScopeNew(txHoister* hoister, txNode* node, txToken token)
|
|
145
|
+
{
|
|
146
|
+
txScope* scope = fxNewParserChunkClear(hoister->parser, sizeof(txScope));
|
|
147
|
+
scope->parser = hoister->parser;
|
|
148
|
+
scope->scope = hoister->scope;
|
|
149
|
+
scope->token = token;
|
|
150
|
+
scope->flags = node->flags & mxStrictFlag;
|
|
151
|
+
scope->node = node;
|
|
152
|
+
hoister->scope = scope;
|
|
153
|
+
return scope;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
void fxScopeAddDeclareNode(txScope* self, txDeclareNode* node)
|
|
157
|
+
{
|
|
158
|
+
self->declareNodeCount++;
|
|
159
|
+
if (self->token == XS_TOKEN_EVAL) {
|
|
160
|
+
if (self->lastDeclareNode)
|
|
161
|
+
node->nextDeclareNode = self->firstDeclareNode;
|
|
162
|
+
else
|
|
163
|
+
self->lastDeclareNode = node;
|
|
164
|
+
self->firstDeclareNode = node;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
if (self->lastDeclareNode)
|
|
168
|
+
self->lastDeclareNode->nextDeclareNode = node;
|
|
169
|
+
else
|
|
170
|
+
self->firstDeclareNode = node;
|
|
171
|
+
self->lastDeclareNode = node;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
void fxScopeAddDefineNode(txScope* self, txDefineNode* node)
|
|
176
|
+
{
|
|
177
|
+
self->defineNodeCount++;
|
|
178
|
+
if (self->lastDefineNode)
|
|
179
|
+
self->lastDefineNode->nextDefineNode = node;
|
|
180
|
+
else
|
|
181
|
+
self->firstDefineNode = node;
|
|
182
|
+
self->lastDefineNode = node;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
void fxScopeBindDefineNodes(txScope* self, void* param)
|
|
186
|
+
{
|
|
187
|
+
txDefineNode* node = self->firstDefineNode;
|
|
188
|
+
while (node) {
|
|
189
|
+
fxNodeDispatchBind(node, param);
|
|
190
|
+
node = node->nextDefineNode;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
void fxScopeBinding(txScope* self, txBinder* binder)
|
|
195
|
+
{
|
|
196
|
+
self->scope = binder->scope;
|
|
197
|
+
binder->scope = self;
|
|
198
|
+
fxBinderPushVariables(binder, self->declareNodeCount);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
void fxScopeBound(txScope* self, txBinder* binder)
|
|
202
|
+
{
|
|
203
|
+
if (self->flags & mxEvalFlag) {
|
|
204
|
+
txDeclareNode* node = self->firstDeclareNode;
|
|
205
|
+
while (node) {
|
|
206
|
+
node->flags |= mxDeclareNodeClosureFlag;
|
|
207
|
+
node = node->nextDeclareNode;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (self->token == XS_TOKEN_MODULE) {
|
|
211
|
+
txDeclareNode* node = self->firstDeclareNode;
|
|
212
|
+
while (node) {
|
|
213
|
+
node->flags |= mxDeclareNodeClosureFlag | mxDeclareNodeUseClosureFlag;
|
|
214
|
+
node = node->nextDeclareNode;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else if (self->token == XS_TOKEN_PROGRAM) {
|
|
218
|
+
txDeclareNode* node = self->firstDeclareNode;
|
|
219
|
+
while (node) {
|
|
220
|
+
node->flags |= mxDeclareNodeClosureFlag | mxDeclareNodeUseClosureFlag;
|
|
221
|
+
node = node->nextDeclareNode;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
binder->scopeLevel += self->closureNodeCount;
|
|
225
|
+
binder->scopeMaximum += self->closureNodeCount;
|
|
226
|
+
fxBinderPopVariables(binder, self->declareNodeCount);
|
|
227
|
+
binder->scope = self->scope;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
void fxScopeEval(txScope* self)
|
|
231
|
+
{
|
|
232
|
+
while (self) {
|
|
233
|
+
self->flags |= mxEvalFlag;
|
|
234
|
+
self = self->scope;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
txDeclareNode* fxScopeGetDeclareNode(txScope* self, txSymbol* symbol)
|
|
239
|
+
{
|
|
240
|
+
txDeclareNode* node = self->firstDeclareNode;
|
|
241
|
+
while (node) {
|
|
242
|
+
if (node->symbol == symbol)
|
|
243
|
+
return node;
|
|
244
|
+
node = node->nextDeclareNode;
|
|
245
|
+
}
|
|
246
|
+
return NULL;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
void fxScopeHoisted(txScope* self, txHoister* hoister)
|
|
250
|
+
{
|
|
251
|
+
if (self->token == XS_TOKEN_BLOCK) {
|
|
252
|
+
txDeclareNode** address = &self->firstDeclareNode;
|
|
253
|
+
txDeclareNode* node;
|
|
254
|
+
txDeclareNode* last = C_NULL;
|
|
255
|
+
while ((node = *address)) {
|
|
256
|
+
if (node->description->token == XS_NO_TOKEN) {
|
|
257
|
+
self->declareNodeCount--;
|
|
258
|
+
*address = node->nextDeclareNode;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
address = &node->nextDeclareNode;
|
|
262
|
+
last = node;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
self->lastDeclareNode = last;
|
|
266
|
+
}
|
|
267
|
+
else if (self->token == XS_TOKEN_PROGRAM) {
|
|
268
|
+
txDeclareNode* node = self->firstDeclareNode;
|
|
269
|
+
while (node) {
|
|
270
|
+
if ((node->description->token == XS_TOKEN_DEFINE) || (node->description->token == XS_TOKEN_VAR))
|
|
271
|
+
self->declareNodeCount--;
|
|
272
|
+
node = node->nextDeclareNode;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else if (self->token == XS_TOKEN_EVAL) {
|
|
276
|
+
if (!(self->flags & mxStrictFlag)) {
|
|
277
|
+
txDeclareNode* node = self->firstDeclareNode;
|
|
278
|
+
while (node) {
|
|
279
|
+
if ((node->description->token == XS_TOKEN_DEFINE) || (node->description->token == XS_TOKEN_VAR))
|
|
280
|
+
self->declareNodeCount--;
|
|
281
|
+
node = node->nextDeclareNode;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
hoister->scope = self->scope;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
void fxScopeLookup(txScope* self, txAccessNode* access, txBoolean closureFlag)
|
|
289
|
+
{
|
|
290
|
+
txDeclareNode* declaration;
|
|
291
|
+
if (self->token == XS_TOKEN_EVAL) {
|
|
292
|
+
declaration = fxScopeGetDeclareNode(self, access->symbol);
|
|
293
|
+
if (declaration) {
|
|
294
|
+
if ((!(self->flags & mxStrictFlag)) && ((declaration->description->token == XS_TOKEN_VAR) || (declaration->description->token == XS_TOKEN_DEFINE))) {
|
|
295
|
+
declaration = C_NULL;
|
|
296
|
+
}
|
|
297
|
+
else if (closureFlag)
|
|
298
|
+
declaration->flags |= mxDeclareNodeClosureFlag;
|
|
299
|
+
}
|
|
300
|
+
else if ((self->flags & mxStrictFlag) && (access->description->token == XS_TOKEN_PRIVATE_MEMBER)) {
|
|
301
|
+
declaration = fxDeclareNodeNew(self->parser, XS_TOKEN_PRIVATE, access->symbol);
|
|
302
|
+
declaration->flags |= mxDeclareNodeClosureFlag;
|
|
303
|
+
declaration->line = access->line;
|
|
304
|
+
fxScopeAddDeclareNode(self, declaration);
|
|
305
|
+
self->closureNodeCount++;
|
|
306
|
+
}
|
|
307
|
+
access->declaration = declaration;
|
|
308
|
+
}
|
|
309
|
+
else if (self->token == XS_TOKEN_FUNCTION) {
|
|
310
|
+
declaration = fxScopeGetDeclareNode(self, access->symbol);
|
|
311
|
+
if (declaration) {
|
|
312
|
+
if (closureFlag)
|
|
313
|
+
declaration->flags |= mxDeclareNodeClosureFlag;
|
|
314
|
+
access->declaration = declaration;
|
|
315
|
+
}
|
|
316
|
+
else if ((self->node->flags & mxEvalFlag) && !(self->node->flags & mxStrictFlag)) {
|
|
317
|
+
// eval can create variables that override closures
|
|
318
|
+
access->declaration = C_NULL;
|
|
319
|
+
}
|
|
320
|
+
else if (self->scope) {
|
|
321
|
+
fxScopeLookup(self->scope, access, 1);
|
|
322
|
+
if (access->declaration) {
|
|
323
|
+
txDeclareNode* closureNode = fxDeclareNodeNew(self->parser, XS_NO_TOKEN, access->symbol);
|
|
324
|
+
closureNode->flags |= mxDeclareNodeClosureFlag | mxDeclareNodeUseClosureFlag;
|
|
325
|
+
closureNode->line = access->declaration->line;
|
|
326
|
+
closureNode->declaration = access->declaration;
|
|
327
|
+
fxScopeAddDeclareNode(self, closureNode);
|
|
328
|
+
self->closureNodeCount++;
|
|
329
|
+
access->declaration = closureNode;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
else if (self->token == XS_TOKEN_PROGRAM) {
|
|
334
|
+
declaration = fxScopeGetDeclareNode(self, access->symbol);
|
|
335
|
+
if (declaration && ((declaration->description->token == XS_TOKEN_VAR) || (declaration->description->token == XS_TOKEN_DEFINE))) {
|
|
336
|
+
declaration = C_NULL;
|
|
337
|
+
}
|
|
338
|
+
access->declaration = declaration;
|
|
339
|
+
}
|
|
340
|
+
else if (self->token == XS_TOKEN_WITH) {
|
|
341
|
+
// with object can have properties that override variables
|
|
342
|
+
access->declaration = C_NULL;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
declaration = fxScopeGetDeclareNode(self, access->symbol);
|
|
346
|
+
if (declaration) {
|
|
347
|
+
if (closureFlag)
|
|
348
|
+
declaration->flags |= mxDeclareNodeClosureFlag;
|
|
349
|
+
access->declaration = declaration;
|
|
350
|
+
}
|
|
351
|
+
else if (self->scope) {
|
|
352
|
+
fxScopeLookup(self->scope, access, closureFlag);
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
access->declaration = C_NULL;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
void fxNodeHoist(void* it, void* param)
|
|
361
|
+
{
|
|
362
|
+
txNode* node = it;
|
|
363
|
+
(*node->description->dispatch->distribute)(node, fxNodeDispatchHoist, param);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
void fxNodeDispatchHoist(void* it, void* param)
|
|
367
|
+
{
|
|
368
|
+
txNode* node = it;
|
|
369
|
+
fxCheckParserStack(((txHoister*)param)->parser, node->line);
|
|
370
|
+
(*node->description->dispatch->hoist)(it, param);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
void fxBlockNodeHoist(void* it, void* param)
|
|
374
|
+
{
|
|
375
|
+
txBlockNode* self = it;
|
|
376
|
+
self->scope = fxScopeNew(param, it, XS_TOKEN_BLOCK);
|
|
377
|
+
fxNodeDispatchHoist(self->statement, param);
|
|
378
|
+
fxScopeHoisted(self->scope, param);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
void fxBodyNodeHoist(void* it, void* param)
|
|
382
|
+
{
|
|
383
|
+
txBlockNode* self = it;
|
|
384
|
+
txHoister* hoister = param;
|
|
385
|
+
txNode* environmentNode = hoister->environmentNode;
|
|
386
|
+
hoister->bodyScope = self->scope = fxScopeNew(param, it, XS_TOKEN_BLOCK);
|
|
387
|
+
hoister->environmentNode = it;
|
|
388
|
+
fxNodeDispatchHoist(self->statement, param);
|
|
389
|
+
hoister->environmentNode = environmentNode;
|
|
390
|
+
fxScopeHoisted(self->scope, param);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
void fxCallNodeHoist(void* it, void* param)
|
|
394
|
+
{
|
|
395
|
+
txCallNewNode* self = it;
|
|
396
|
+
txHoister* hoister = param;
|
|
397
|
+
txParser* parser = hoister->parser;
|
|
398
|
+
if (self->reference->description->token == XS_TOKEN_ACCESS) {
|
|
399
|
+
txAccessNode* access = (txAccessNode*)self->reference;
|
|
400
|
+
if (access->symbol == parser->evalSymbol) {
|
|
401
|
+
fxScopeEval(hoister->scope);
|
|
402
|
+
hoister->functionScope->node->flags |= mxArgumentsFlag | mxEvalFlag;
|
|
403
|
+
hoister->environmentNode->flags |= mxEvalFlag;
|
|
404
|
+
self->params->flags |= mxEvalParametersFlag;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
fxNodeDispatchHoist(self->reference, param);
|
|
408
|
+
fxNodeDispatchHoist(self->params, param);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
void fxCatchNodeHoist(void* it, void* param)
|
|
412
|
+
{
|
|
413
|
+
txCatchNode* self = it;
|
|
414
|
+
txHoister* hoister = param;
|
|
415
|
+
txDeclareNode* node;
|
|
416
|
+
if (self->parameter) {
|
|
417
|
+
self->scope = fxScopeNew(param, it, XS_TOKEN_BLOCK);
|
|
418
|
+
fxNodeDispatchHoist(self->parameter, param);
|
|
419
|
+
self->statementScope = fxScopeNew(param, it, XS_TOKEN_BLOCK);
|
|
420
|
+
fxNodeDispatchHoist(self->statement, param);
|
|
421
|
+
fxScopeHoisted(self->statementScope, param);
|
|
422
|
+
fxScopeHoisted(self->scope, param);
|
|
423
|
+
node = self->statementScope->firstDeclareNode;
|
|
424
|
+
while (node) {
|
|
425
|
+
if (fxScopeGetDeclareNode(self->scope, node->symbol))
|
|
426
|
+
fxReportParserError(hoister->parser, node->line, "duplicate variable %s", node->symbol->string);
|
|
427
|
+
node = node->nextDeclareNode;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
self->statementScope = fxScopeNew(param, it, XS_TOKEN_BLOCK);
|
|
432
|
+
fxNodeDispatchHoist(self->statement, param);
|
|
433
|
+
fxScopeHoisted(self->statementScope, param);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
void fxClassNodeHoist(void* it, void* param)
|
|
438
|
+
{
|
|
439
|
+
txClassNode* self = it;
|
|
440
|
+
txHoister* hoister = param;
|
|
441
|
+
txClassNode* former = hoister->classNode;
|
|
442
|
+
txNode* item = self->items->first;
|
|
443
|
+
if (self->symbol) {
|
|
444
|
+
txDeclareNode* node = fxDeclareNodeNew(hoister->parser, XS_TOKEN_CONST, self->symbol);
|
|
445
|
+
node->flags |= mxDeclareNodeClosureFlag;
|
|
446
|
+
self->symbolScope = fxScopeNew(hoister, it, XS_TOKEN_BLOCK);
|
|
447
|
+
fxScopeAddDeclareNode(self->symbolScope, node);
|
|
448
|
+
}
|
|
449
|
+
if (self->heritage)
|
|
450
|
+
fxNodeDispatchHoist(self->heritage, param);
|
|
451
|
+
self->scope = fxScopeNew(hoister, it, XS_TOKEN_BLOCK);
|
|
452
|
+
while (item) {
|
|
453
|
+
if (item->description->token == XS_TOKEN_PROPERTY) {
|
|
454
|
+
}
|
|
455
|
+
else if (item->description->token == XS_TOKEN_PROPERTY_AT) {
|
|
456
|
+
if (item->flags & (mxMethodFlag | mxGetterFlag | mxSetterFlag)) {
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
txSymbol* symbol = fxNewParserChunkClear(hoister->parser, sizeof(txSymbol));
|
|
460
|
+
txDeclareNode* node = fxDeclareNodeNew(hoister->parser, XS_TOKEN_CONST, symbol);
|
|
461
|
+
symbol->ID = -1;
|
|
462
|
+
node->flags |= mxDeclareNodeClosureFlag;
|
|
463
|
+
fxScopeAddDeclareNode(self->scope, node);
|
|
464
|
+
((txPropertyAtNode*)item)->atAccess = fxAccessNodeNew(hoister->parser, XS_TOKEN_ACCESS, symbol);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
txSymbol* symbol = ((txPrivatePropertyNode*)item)->symbol;
|
|
469
|
+
txDeclareNode* node = fxScopeGetDeclareNode(self->scope, symbol);
|
|
470
|
+
if (node) {
|
|
471
|
+
txUnsigned flags = (node->flags & (mxStaticFlag | mxGetterFlag | mxSetterFlag)) ^ (item->flags & (mxStaticFlag | mxGetterFlag | mxSetterFlag));
|
|
472
|
+
if ((flags != (mxGetterFlag | mxSetterFlag)))
|
|
473
|
+
fxReportParserError(hoister->parser, item->line, "duplicate %s", symbol->string);
|
|
474
|
+
}
|
|
475
|
+
node = fxDeclareNodeNew(hoister->parser, XS_TOKEN_CONST, symbol);
|
|
476
|
+
node->flags |= mxDeclareNodeClosureFlag | (item->flags & (mxStaticFlag | mxGetterFlag | mxSetterFlag));
|
|
477
|
+
fxScopeAddDeclareNode(self->scope, node);
|
|
478
|
+
((txPrivatePropertyNode*)item)->symbolAccess = fxAccessNodeNew(hoister->parser, XS_TOKEN_ACCESS, symbol);
|
|
479
|
+
if (item->flags & (mxMethodFlag | mxGetterFlag | mxSetterFlag)) {
|
|
480
|
+
txSymbol* symbol = fxNewParserChunkClear(hoister->parser, sizeof(txSymbol));
|
|
481
|
+
txDeclareNode* node = fxDeclareNodeNew(hoister->parser, XS_TOKEN_CONST, symbol);
|
|
482
|
+
symbol->ID = -1;
|
|
483
|
+
node->flags |= mxDeclareNodeClosureFlag;
|
|
484
|
+
fxScopeAddDeclareNode(self->scope, node);
|
|
485
|
+
((txPrivatePropertyNode*)item)->valueAccess = fxAccessNodeNew(hoister->parser, XS_TOKEN_ACCESS, symbol);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
item = item->next;
|
|
489
|
+
}
|
|
490
|
+
if (self->instanceInit) {
|
|
491
|
+
txSymbol* symbol = fxNewParserChunkClear(hoister->parser, sizeof(txSymbol));
|
|
492
|
+
txDeclareNode* node = fxDeclareNodeNew(hoister->parser, XS_TOKEN_CONST, symbol);
|
|
493
|
+
symbol->ID = -1;
|
|
494
|
+
node->flags |= mxDeclareNodeClosureFlag;
|
|
495
|
+
fxScopeAddDeclareNode(self->scope, node);
|
|
496
|
+
self->instanceInitAccess = fxAccessNodeNew(hoister->parser, XS_TOKEN_ACCESS, symbol);
|
|
497
|
+
}
|
|
498
|
+
hoister->classNode = self;
|
|
499
|
+
fxNodeDispatchHoist(self->constructor, param);
|
|
500
|
+
fxNodeListDistribute(self->items, fxNodeDispatchHoist, param);
|
|
501
|
+
if (self->constructorInit)
|
|
502
|
+
fxNodeDispatchHoist(self->constructorInit, param);
|
|
503
|
+
if (self->instanceInit)
|
|
504
|
+
fxNodeDispatchHoist(self->instanceInit, param);
|
|
505
|
+
hoister->classNode = former;
|
|
506
|
+
fxScopeHoisted(self->scope, param);
|
|
507
|
+
if (self->symbol)
|
|
508
|
+
fxScopeHoisted(self->symbolScope, param);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
void fxCoalesceExpressionNodeHoist(void* it, void* param)
|
|
512
|
+
{
|
|
513
|
+
txBinaryExpressionNode* self = it;
|
|
514
|
+
txHoister* hoister = param;
|
|
515
|
+
txToken leftToken = self->left->description->token;
|
|
516
|
+
txToken rightToken = self->right->description->token;
|
|
517
|
+
if ((leftToken == XS_TOKEN_AND) || (rightToken == XS_TOKEN_AND))
|
|
518
|
+
fxReportParserError(hoister->parser, self->line, "missing () around &&");
|
|
519
|
+
else if ((leftToken == XS_TOKEN_OR) || (rightToken == XS_TOKEN_OR))
|
|
520
|
+
fxReportParserError(hoister->parser, self->line, "missing () around ||");
|
|
521
|
+
fxNodeDispatchHoist(self->left, param);
|
|
522
|
+
fxNodeDispatchHoist(self->right, param);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
void fxDeclareNodeHoist(void* it, void* param)
|
|
526
|
+
{
|
|
527
|
+
txDeclareNode* self = it;
|
|
528
|
+
txHoister* hoister = param;
|
|
529
|
+
txDeclareNode* node;
|
|
530
|
+
txScope* scope;
|
|
531
|
+
if (self->description->token == XS_TOKEN_ARG) {
|
|
532
|
+
node = fxScopeGetDeclareNode(hoister->functionScope, self->symbol);
|
|
533
|
+
if (node) {
|
|
534
|
+
if ((node->description->token == XS_TOKEN_ARG) && (hoister->functionScope->node->flags & (mxArrowFlag | mxAsyncFlag | mxMethodFlag | mxNotSimpleParametersFlag | mxStrictFlag)))
|
|
535
|
+
fxReportParserError(hoister->parser, self->line, "duplicate argument %s", self->symbol->string);
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
fxScopeAddDeclareNode(hoister->functionScope, self);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
else if ((self->description->token == XS_TOKEN_CONST) || (self->description->token == XS_TOKEN_LET)) {
|
|
542
|
+
node = fxScopeGetDeclareNode(hoister->scope, self->symbol);
|
|
543
|
+
if (!node && (hoister->scope == hoister->bodyScope)) {
|
|
544
|
+
node = fxScopeGetDeclareNode(hoister->functionScope, self->symbol);
|
|
545
|
+
if (node && (node->description->token != XS_TOKEN_ARG))
|
|
546
|
+
node = C_NULL;
|
|
547
|
+
}
|
|
548
|
+
if (node)
|
|
549
|
+
fxReportParserError(hoister->parser, self->line, "duplicate variable %s", self->symbol->string);
|
|
550
|
+
else
|
|
551
|
+
fxScopeAddDeclareNode(hoister->scope, self);
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
scope = hoister->scope;
|
|
555
|
+
node = C_NULL;
|
|
556
|
+
while (scope != hoister->bodyScope) {
|
|
557
|
+
node = fxScopeGetDeclareNode(scope, self->symbol);
|
|
558
|
+
if (node) {
|
|
559
|
+
if ((node->description->token == XS_TOKEN_CONST) || (node->description->token == XS_TOKEN_LET) || (node->description->token == XS_TOKEN_DEFINE))
|
|
560
|
+
break;
|
|
561
|
+
node = C_NULL;
|
|
562
|
+
}
|
|
563
|
+
scope = scope->scope;
|
|
564
|
+
}
|
|
565
|
+
if (!node) {
|
|
566
|
+
node = fxScopeGetDeclareNode(scope, self->symbol);
|
|
567
|
+
if (node) {
|
|
568
|
+
if ((node->description->token != XS_TOKEN_CONST) && (node->description->token != XS_TOKEN_LET))
|
|
569
|
+
node = C_NULL;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (node)
|
|
573
|
+
fxReportParserError(hoister->parser, self->line, "duplicate variable %s", self->symbol->string);
|
|
574
|
+
else {
|
|
575
|
+
node = fxScopeGetDeclareNode(hoister->functionScope, self->symbol);
|
|
576
|
+
if (!node || ((node->description->token != XS_TOKEN_ARG) && (node->description->token != XS_TOKEN_VAR)))
|
|
577
|
+
fxScopeAddDeclareNode(hoister->bodyScope, self);
|
|
578
|
+
scope = hoister->scope;
|
|
579
|
+
while (scope != hoister->bodyScope) {
|
|
580
|
+
fxScopeAddDeclareNode(scope, fxDeclareNodeNew(hoister->parser, XS_NO_TOKEN, self->symbol));
|
|
581
|
+
scope = scope->scope;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
void fxDefineNodeHoist(void* it, void* param)
|
|
588
|
+
{
|
|
589
|
+
txDefineNode* self = it;
|
|
590
|
+
txHoister* hoister = param;
|
|
591
|
+
txDeclareNode* node;
|
|
592
|
+
if (self->flags & mxStrictFlag) {
|
|
593
|
+
if ((self->symbol == hoister->parser->argumentsSymbol) || (self->symbol == hoister->parser->evalSymbol) || (self->symbol == hoister->parser->yieldSymbol))
|
|
594
|
+
fxReportParserError(hoister->parser, self->line, "invalid definition %s", self->symbol->string);
|
|
595
|
+
}
|
|
596
|
+
if ((hoister->scope == hoister->bodyScope) && (hoister->scope->token != XS_TOKEN_MODULE)) {
|
|
597
|
+
node = fxScopeGetDeclareNode(hoister->bodyScope, self->symbol);
|
|
598
|
+
if (node) {
|
|
599
|
+
if ((node->description->token == XS_TOKEN_CONST) || (node->description->token == XS_TOKEN_LET))
|
|
600
|
+
fxReportParserError(hoister->parser, self->line, "duplicate variable %s", self->symbol->string);
|
|
601
|
+
}
|
|
602
|
+
else {
|
|
603
|
+
if (hoister->functionScope != hoister->bodyScope)
|
|
604
|
+
node = fxScopeGetDeclareNode(hoister->functionScope, self->symbol);
|
|
605
|
+
if (!node)
|
|
606
|
+
fxScopeAddDeclareNode(hoister->bodyScope, (txDeclareNode*)self);
|
|
607
|
+
}
|
|
608
|
+
fxScopeAddDefineNode(hoister->bodyScope, self);
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
node = fxScopeGetDeclareNode(hoister->scope, self->symbol);
|
|
612
|
+
if (node)
|
|
613
|
+
fxReportParserError(hoister->parser, self->line, "duplicate variable %s", self->symbol->string);
|
|
614
|
+
else
|
|
615
|
+
fxScopeAddDeclareNode(hoister->scope, (txDeclareNode*)self);
|
|
616
|
+
fxScopeAddDefineNode(hoister->scope, self);
|
|
617
|
+
}
|
|
618
|
+
((txFunctionNode*)(self->initializer))->symbol = C_NULL;
|
|
619
|
+
fxNodeDispatchHoist(self->initializer, param);
|
|
620
|
+
((txFunctionNode*)(self->initializer))->symbol = self->symbol;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
void fxExportNodeHoist(void* it, void* param)
|
|
624
|
+
{
|
|
625
|
+
txExportNode* self = it;
|
|
626
|
+
txHoister* hoister = param;
|
|
627
|
+
if (self->from) {
|
|
628
|
+
if (self->specifiers && self->specifiers->length) {
|
|
629
|
+
txSpecifierNode* specifier = (txSpecifierNode*)self->specifiers->first;
|
|
630
|
+
while (specifier) {
|
|
631
|
+
txDeclareNode* node = fxDeclareNodeNew(hoister->parser, XS_TOKEN_LET, C_NULL);
|
|
632
|
+
specifier->from = self->from;
|
|
633
|
+
node->flags |= mxDeclareNodeClosureFlag | mxDeclareNodeUseClosureFlag;
|
|
634
|
+
node->line = self->line;
|
|
635
|
+
node->importSpecifier = specifier;
|
|
636
|
+
node->firstExportSpecifier = specifier;
|
|
637
|
+
fxScopeAddDeclareNode(hoister->scope, node);
|
|
638
|
+
specifier = (txSpecifierNode*)specifier->next;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
txSpecifierNode* specifier = fxSpecifierNodeNew(hoister->parser, XS_TOKEN_SPECIFIER);
|
|
643
|
+
txDeclareNode* node = fxDeclareNodeNew(hoister->parser, XS_TOKEN_LET, C_NULL);
|
|
644
|
+
specifier->from = self->from;
|
|
645
|
+
node->flags |= mxDeclareNodeClosureFlag | mxDeclareNodeUseClosureFlag;
|
|
646
|
+
node->line = self->line;
|
|
647
|
+
node->importSpecifier = specifier;
|
|
648
|
+
fxScopeAddDeclareNode(hoister->scope, node);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
if (self->specifiers && self->specifiers->length) {
|
|
652
|
+
txSpecifierNode* specifier = (txSpecifierNode*)self->specifiers->first;
|
|
653
|
+
while (specifier) {
|
|
654
|
+
fxHoisterAddExportLink(hoister, specifier);
|
|
655
|
+
fxNodeDispatchHoist(specifier, param);
|
|
656
|
+
specifier = (txSpecifierNode*)specifier->next;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
void fxForNodeHoist(void* it, void* param)
|
|
662
|
+
{
|
|
663
|
+
txForNode* self = it;
|
|
664
|
+
self->scope = fxScopeNew(param, it, XS_TOKEN_BLOCK);
|
|
665
|
+
if (self->initialization)
|
|
666
|
+
fxNodeDispatchHoist(self->initialization, param);
|
|
667
|
+
if (self->expression)
|
|
668
|
+
fxNodeDispatchHoist(self->expression, param);
|
|
669
|
+
if (self->iteration)
|
|
670
|
+
fxNodeDispatchHoist(self->iteration, param);
|
|
671
|
+
fxNodeDispatchHoist(self->statement, param);
|
|
672
|
+
fxScopeHoisted(self->scope, param);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
void fxForInForOfNodeHoist(void* it, void* param)
|
|
676
|
+
{
|
|
677
|
+
txForInForOfNode* self = it;
|
|
678
|
+
self->scope = fxScopeNew(param, it, XS_TOKEN_BLOCK);
|
|
679
|
+
fxNodeDispatchHoist(self->reference, param);
|
|
680
|
+
fxNodeDispatchHoist(self->expression, param);
|
|
681
|
+
fxNodeDispatchHoist(self->statement, param);
|
|
682
|
+
fxScopeHoisted(self->scope, param);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
void fxFunctionNodeHoist(void* it, void* param)
|
|
686
|
+
{
|
|
687
|
+
txFunctionNode* self = it;
|
|
688
|
+
txHoister* hoister = param;
|
|
689
|
+
txScope* functionScope = hoister->functionScope;
|
|
690
|
+
txScope* bodyScope = hoister->bodyScope;
|
|
691
|
+
hoister->functionScope = self->scope = fxScopeNew(param, it, XS_TOKEN_FUNCTION);
|
|
692
|
+
hoister->bodyScope = C_NULL;
|
|
693
|
+
if (self->symbol) {
|
|
694
|
+
txDefineNode* node = fxDefineNodeNew(hoister->parser, XS_TOKEN_CONST, self->symbol);
|
|
695
|
+
node->initializer = fxValueNodeNew(hoister->parser, XS_TOKEN_CURRENT);
|
|
696
|
+
fxScopeAddDeclareNode(hoister->functionScope, (txDeclareNode*)node);
|
|
697
|
+
fxScopeAddDefineNode(hoister->functionScope, node);
|
|
698
|
+
}
|
|
699
|
+
fxNodeDispatchHoist(self->params, param);
|
|
700
|
+
if ((self->flags & (mxArgumentsFlag | mxEvalFlag)) && !(self->flags & mxArrowFlag)) {
|
|
701
|
+
txDeclareNode* declaration = fxDeclareNodeNew(hoister->parser, XS_TOKEN_VAR, hoister->parser->argumentsSymbol);
|
|
702
|
+
fxScopeAddDeclareNode(hoister->functionScope, declaration);
|
|
703
|
+
}
|
|
704
|
+
fxNodeDispatchHoist(self->body, param);
|
|
705
|
+
fxScopeHoisted(self->scope, param);
|
|
706
|
+
hoister->bodyScope = bodyScope;
|
|
707
|
+
hoister->functionScope = functionScope;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
void fxHostNodeHoist(void* it, void* param)
|
|
711
|
+
{
|
|
712
|
+
txHostNode* self = it;
|
|
713
|
+
txHoister* hoister = param;
|
|
714
|
+
txScope* scope = hoister->bodyScope;
|
|
715
|
+
if ((scope->token != XS_TOKEN_MODULE) && (scope->token != XS_TOKEN_PROGRAM))
|
|
716
|
+
fxReportParserError(hoister->parser, self->line, "invalid host");
|
|
717
|
+
else {
|
|
718
|
+
// @@ check simple parameters
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
void fxImportNodeHoist(void* it, void* param)
|
|
723
|
+
{
|
|
724
|
+
txImportNode* self = it;
|
|
725
|
+
txHoister* hoister = param;
|
|
726
|
+
if (self->specifiers && self->specifiers->length) {
|
|
727
|
+
txSpecifierNode* specifier = (txSpecifierNode*)self->specifiers->first;
|
|
728
|
+
while (specifier) {
|
|
729
|
+
txDeclareNode* node;
|
|
730
|
+
txSymbol* symbol = specifier->asSymbol ? specifier->asSymbol : specifier->symbol;
|
|
731
|
+
if (self->flags & mxStrictFlag) {
|
|
732
|
+
if ((symbol == hoister->parser->argumentsSymbol) || (symbol == hoister->parser->evalSymbol))
|
|
733
|
+
fxReportParserError(hoister->parser, self->line, "invalid import %s", symbol->string);
|
|
734
|
+
}
|
|
735
|
+
node = fxScopeGetDeclareNode(hoister->scope, symbol);
|
|
736
|
+
if (node)
|
|
737
|
+
fxReportParserError(hoister->parser, self->line, "duplicate variable %s", symbol->string);
|
|
738
|
+
else {
|
|
739
|
+
specifier->declaration = node = fxDeclareNodeNew(hoister->parser, XS_TOKEN_LET, symbol);
|
|
740
|
+
specifier->from = self->from;
|
|
741
|
+
node->flags |= mxDeclareNodeClosureFlag | mxDeclareNodeUseClosureFlag;
|
|
742
|
+
node->line = self->line;
|
|
743
|
+
node->importSpecifier = specifier;
|
|
744
|
+
fxScopeAddDeclareNode(hoister->scope, node);
|
|
745
|
+
}
|
|
746
|
+
specifier = (txSpecifierNode*)specifier->next;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
else {
|
|
750
|
+
txSpecifierNode* specifier = fxSpecifierNodeNew(hoister->parser, XS_TOKEN_SPECIFIER);
|
|
751
|
+
txDeclareNode* node = fxDeclareNodeNew(hoister->parser, XS_TOKEN_LET, C_NULL);
|
|
752
|
+
specifier->from = self->from;
|
|
753
|
+
node->flags |= mxDeclareNodeClosureFlag | mxDeclareNodeUseClosureFlag;
|
|
754
|
+
node->line = self->line;
|
|
755
|
+
node->importSpecifier = specifier;
|
|
756
|
+
fxScopeAddDeclareNode(hoister->scope, node);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
void fxModuleNodeHoist(void* it, void* param)
|
|
761
|
+
{
|
|
762
|
+
txModuleNode* self = it;
|
|
763
|
+
txHoister* hoister = param;
|
|
764
|
+
hoister->functionScope = hoister->bodyScope = self->scope = fxScopeNew(param, it, XS_TOKEN_MODULE); // @@
|
|
765
|
+
hoister->environmentNode = it;
|
|
766
|
+
fxNodeDispatchHoist(self->body, param);
|
|
767
|
+
hoister->environmentNode = C_NULL;
|
|
768
|
+
fxScopeHoisted(self->scope, param);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
void fxParamsBindingNodeHoist(void* it, void* param)
|
|
772
|
+
{
|
|
773
|
+
txParamsNode* self = it;
|
|
774
|
+
txNode* item = self->items->first;
|
|
775
|
+
while (item) {
|
|
776
|
+
fxNodeDispatchHoist(item, param);
|
|
777
|
+
item = item->next;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
void fxProgramNodeHoist(void* it, void* param)
|
|
782
|
+
{
|
|
783
|
+
txProgramNode* self = it;
|
|
784
|
+
txHoister* hoister = param;
|
|
785
|
+
hoister->functionScope = hoister->bodyScope = self->scope = fxScopeNew(param, it, (hoister->parser->flags & mxEvalFlag) ? XS_TOKEN_EVAL : XS_TOKEN_PROGRAM);
|
|
786
|
+
hoister->environmentNode = it;
|
|
787
|
+
fxNodeDispatchHoist(self->body, param);
|
|
788
|
+
hoister->environmentNode = C_NULL;
|
|
789
|
+
self->variableCount = hoister->functionScope->declareNodeCount;
|
|
790
|
+
fxScopeHoisted(self->scope, param);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
void fxStatementNodeHoist(void* it, void* param)
|
|
794
|
+
{
|
|
795
|
+
txStatementNode* self = it;
|
|
796
|
+
fxNodeDispatchHoist(self->expression, param);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
void fxPropertyNodeHoist(void* it, void* param)
|
|
800
|
+
{
|
|
801
|
+
txPropertyNode* self = it;
|
|
802
|
+
if (self->value) {
|
|
803
|
+
if (self->value->description->token == XS_TOKEN_HOST)
|
|
804
|
+
((txHostNode*)(self->value))->symbol = self->symbol;
|
|
805
|
+
fxNodeDispatchHoist(self->value, param);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
void fxStringNodeHoist(void* it, void* param)
|
|
810
|
+
{
|
|
811
|
+
txStringNode* self = it;
|
|
812
|
+
txHoister* hoister = param;
|
|
813
|
+
if ((self->flags & mxStringLegacyFlag) && (hoister->scope->flags & mxStrictFlag))
|
|
814
|
+
self->flags |= mxStringErrorFlag;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
void fxSwitchNodeHoist(void* it, void* param)
|
|
818
|
+
{
|
|
819
|
+
txSwitchNode* self = it;
|
|
820
|
+
fxNodeDispatchHoist(self->expression, param);
|
|
821
|
+
self->scope = fxScopeNew(param, it, XS_TOKEN_BLOCK);
|
|
822
|
+
fxNodeListDistribute(self->items, fxNodeDispatchHoist, param);
|
|
823
|
+
fxScopeHoisted(self->scope, param);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
void fxWithNodeHoist(void* it, void* param)
|
|
827
|
+
{
|
|
828
|
+
txWithNode* self = it;
|
|
829
|
+
txHoister* hoister = param;
|
|
830
|
+
fxNodeDispatchHoist(self->expression, param);
|
|
831
|
+
self->scope = fxScopeNew(param, it, XS_TOKEN_WITH);
|
|
832
|
+
fxScopeEval(hoister->scope);
|
|
833
|
+
fxNodeDispatchHoist(self->statement, param);
|
|
834
|
+
fxScopeHoisted(self->scope, param);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
void fxNodeDispatchBind(void* it, void* param)
|
|
838
|
+
{
|
|
839
|
+
txNode* node = it;
|
|
840
|
+
fxCheckParserStack(((txBinder*)param)->parser, node->line);
|
|
841
|
+
(*node->description->dispatch->bind)(it, param);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
void fxNodeBind(void* it, void* param)
|
|
845
|
+
{
|
|
846
|
+
txNode* node = it;
|
|
847
|
+
(*node->description->dispatch->distribute)(node, fxNodeDispatchBind, param);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
void fxAccessNodeBind(void* it, void* param)
|
|
851
|
+
{
|
|
852
|
+
txAccessNode* self = it;
|
|
853
|
+
txBinder* binder = param;
|
|
854
|
+
fxScopeLookup(binder->scope, (txAccessNode*)self, 0);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
void fxArrayNodeBind(void* it, void* param)
|
|
858
|
+
{
|
|
859
|
+
txArrayNode* self = it;
|
|
860
|
+
fxBinderPushVariables(param, 1);
|
|
861
|
+
if (self->flags & mxSpreadFlag) {
|
|
862
|
+
fxBinderPushVariables(param, 2);
|
|
863
|
+
fxNodeListDistribute(self->items, fxNodeDispatchBind, param);
|
|
864
|
+
fxBinderPopVariables(param, 2);
|
|
865
|
+
}
|
|
866
|
+
else
|
|
867
|
+
fxNodeListDistribute(self->items, fxNodeDispatchBind, param);
|
|
868
|
+
fxBinderPopVariables(param, 1);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
void fxArrayBindingNodeBind(void* it, void* param)
|
|
872
|
+
{
|
|
873
|
+
txArrayBindingNode* self = it;
|
|
874
|
+
fxBinderPushVariables(param, 6);
|
|
875
|
+
fxNodeListDistribute(self->items, fxNodeDispatchBind, param);
|
|
876
|
+
fxBinderPopVariables(param, 6);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
void fxAssignNodeBind(void* it, void* param)
|
|
880
|
+
{
|
|
881
|
+
txAssignNode* self = it;
|
|
882
|
+
txToken token = self->reference->description->token;
|
|
883
|
+
fxNodeDispatchBind(self->reference, param);
|
|
884
|
+
if ((token == XS_TOKEN_ACCESS) || (token == XS_TOKEN_ARG) || (token == XS_TOKEN_CONST) || (token == XS_TOKEN_LET) || (token == XS_TOKEN_VAR))
|
|
885
|
+
fxFunctionNodeRename(self->value, ((txAccessNode*)self->reference)->symbol);
|
|
886
|
+
fxNodeDispatchBind(self->value, param);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
void fxBindingNodeBind(void* it, void* param)
|
|
890
|
+
{
|
|
891
|
+
txBindingNode* self = it;
|
|
892
|
+
txToken token = self->target->description->token;
|
|
893
|
+
fxNodeDispatchBind(self->target, param);
|
|
894
|
+
if ((token == XS_TOKEN_ACCESS) || (token == XS_TOKEN_ARG) || (token == XS_TOKEN_CONST) || (token == XS_TOKEN_LET) || (token == XS_TOKEN_VAR))
|
|
895
|
+
fxFunctionNodeRename(self->initializer, ((txAccessNode*)self->target)->symbol);
|
|
896
|
+
fxNodeDispatchBind(self->initializer, param);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
void fxBlockNodeBind(void* it, void* param)
|
|
900
|
+
{
|
|
901
|
+
txBlockNode* self = it;
|
|
902
|
+
fxScopeBinding(self->scope, param);
|
|
903
|
+
fxScopeBindDefineNodes(self->scope, param);
|
|
904
|
+
fxNodeDispatchBind(self->statement, param);
|
|
905
|
+
fxScopeBound(self->scope, param);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
void fxCatchNodeBind(void* it, void* param)
|
|
909
|
+
{
|
|
910
|
+
txCatchNode* self = it;
|
|
911
|
+
if (self->parameter) {
|
|
912
|
+
fxScopeBinding(self->scope, param);
|
|
913
|
+
fxNodeDispatchBind(self->parameter, param);
|
|
914
|
+
fxScopeBinding(self->statementScope, param);
|
|
915
|
+
fxScopeBindDefineNodes(self->statementScope, param);
|
|
916
|
+
fxNodeDispatchBind(self->statement, param);
|
|
917
|
+
fxScopeBound(self->statementScope, param);
|
|
918
|
+
fxScopeBound(self->scope, param);
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
fxScopeBinding(self->statementScope, param);
|
|
922
|
+
fxScopeBindDefineNodes(self->statementScope, param);
|
|
923
|
+
fxNodeDispatchBind(self->statement, param);
|
|
924
|
+
fxScopeBound(self->statementScope, param);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
void fxClassNodeBind(void* it, void* param)
|
|
929
|
+
{
|
|
930
|
+
txClassNode* self = it;
|
|
931
|
+
txBinder* binder = param;
|
|
932
|
+
txClassNode* former = binder->classNode;
|
|
933
|
+
fxBinderPushVariables(param, 2);
|
|
934
|
+
if (self->symbol)
|
|
935
|
+
fxScopeBinding(self->symbolScope, param);
|
|
936
|
+
if (self->heritage)
|
|
937
|
+
fxNodeDispatchBind(self->heritage, param);
|
|
938
|
+
fxScopeBinding(self->scope, param);
|
|
939
|
+
binder->classNode = self;
|
|
940
|
+
fxNodeDispatchBind(self->constructor, param);
|
|
941
|
+
fxNodeListDistribute(self->items, fxNodeDispatchBind, param);
|
|
942
|
+
if (self->constructorInit)
|
|
943
|
+
fxNodeDispatchBind(self->constructorInit, param);
|
|
944
|
+
if (self->instanceInit)
|
|
945
|
+
fxNodeDispatchBind(self->instanceInit, param);
|
|
946
|
+
binder->classNode = former;
|
|
947
|
+
fxScopeBound(self->scope, param);
|
|
948
|
+
if (self->symbol)
|
|
949
|
+
fxScopeBound(self->symbolScope, param);
|
|
950
|
+
fxBinderPopVariables(param, 2);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
void fxDeclareNodeBind(void* it, void* param)
|
|
954
|
+
{
|
|
955
|
+
txBindingNode* self = it;
|
|
956
|
+
txBinder* binder = param;
|
|
957
|
+
fxScopeLookup(binder->scope, (txAccessNode*)self, 0);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
void fxDefineNodeBind(void* it, void* param)
|
|
961
|
+
{
|
|
962
|
+
txDefineNode* self = it;
|
|
963
|
+
txBinder* binder = param;
|
|
964
|
+
if (self->flags & mxDefineNodeBoundFlag)
|
|
965
|
+
return;
|
|
966
|
+
self->flags |= mxDefineNodeBoundFlag;
|
|
967
|
+
fxScopeLookup(binder->scope, (txAccessNode*)self, 0);
|
|
968
|
+
fxNodeDispatchBind(self->initializer, param);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
void fxDelegateNodeBind(void* it, void* param)
|
|
972
|
+
{
|
|
973
|
+
txStatementNode* self = it;
|
|
974
|
+
fxBinderPushVariables(param, 5);
|
|
975
|
+
fxNodeDispatchBind(self->expression, param);
|
|
976
|
+
fxBinderPopVariables(param, 5);
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
void fxExportNodeBind(void* it, void* param)
|
|
980
|
+
{
|
|
981
|
+
txExportNode* self = it;
|
|
982
|
+
txBinder* binder = param;
|
|
983
|
+
if (self->from)
|
|
984
|
+
return;
|
|
985
|
+
if (self->specifiers) {
|
|
986
|
+
txSpecifierNode* specifier = (txSpecifierNode*)self->specifiers->first;
|
|
987
|
+
while (specifier) {
|
|
988
|
+
txAccessNode* node = fxAccessNodeNew(binder->parser, XS_TOKEN_ACCESS, specifier->symbol);
|
|
989
|
+
fxScopeLookup(binder->scope, node, 0);
|
|
990
|
+
if (node->declaration) {
|
|
991
|
+
specifier->declaration = node->declaration;
|
|
992
|
+
specifier->declaration->flags |= mxDeclareNodeClosureFlag | mxDeclareNodeUseClosureFlag;
|
|
993
|
+
specifier->nextSpecifier = specifier->declaration->firstExportSpecifier;
|
|
994
|
+
specifier->declaration->firstExportSpecifier = specifier;
|
|
995
|
+
}
|
|
996
|
+
else
|
|
997
|
+
fxReportParserError(binder->parser, specifier->line, "unknown variable %s", specifier->symbol->string);
|
|
998
|
+
specifier = (txSpecifierNode*)specifier->next;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
void fxFieldNodeBind(void* it, void* param)
|
|
1004
|
+
{
|
|
1005
|
+
txFieldNode* self = it;
|
|
1006
|
+
txBinder* binder = param;
|
|
1007
|
+
txNode* item = self->item;
|
|
1008
|
+
if (item->description->token == XS_TOKEN_PROPERTY_AT)
|
|
1009
|
+
fxScopeLookup(binder->scope, ((txPropertyAtNode*)item)->atAccess, 0);
|
|
1010
|
+
else if (item->description->token == XS_TOKEN_PRIVATE_PROPERTY) {
|
|
1011
|
+
if (item->flags & (mxMethodFlag | mxGetterFlag | mxSetterFlag))
|
|
1012
|
+
fxScopeLookup(binder->scope, ((txPrivatePropertyNode*)item)->valueAccess, 0);
|
|
1013
|
+
fxScopeLookup(binder->scope, ((txPrivatePropertyNode*)item)->symbolAccess, 0);
|
|
1014
|
+
}
|
|
1015
|
+
if (self->value)
|
|
1016
|
+
fxNodeDispatchBind(self->value, param);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
void fxForNodeBind(void* it, void* param)
|
|
1020
|
+
{
|
|
1021
|
+
txForNode* self = it;
|
|
1022
|
+
fxScopeBinding(self->scope, param);
|
|
1023
|
+
fxScopeBindDefineNodes(self->scope, param);
|
|
1024
|
+
if (self->initialization)
|
|
1025
|
+
fxNodeDispatchBind(self->initialization, param);
|
|
1026
|
+
if (self->expression)
|
|
1027
|
+
fxNodeDispatchBind(self->expression, param);
|
|
1028
|
+
if (self->iteration)
|
|
1029
|
+
fxNodeDispatchBind(self->iteration, param);
|
|
1030
|
+
fxNodeDispatchBind(self->statement, param);
|
|
1031
|
+
fxScopeBound(self->scope, param);
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
void fxForInForOfNodeBind(void* it, void* param)
|
|
1035
|
+
{
|
|
1036
|
+
txForInForOfNode* self = it;
|
|
1037
|
+
fxBinderPushVariables(param, 5);
|
|
1038
|
+
fxScopeBinding(self->scope, param);
|
|
1039
|
+
fxScopeBindDefineNodes(self->scope, param);
|
|
1040
|
+
fxNodeDispatchBind(self->reference, param);
|
|
1041
|
+
fxNodeDispatchBind(self->expression, param);
|
|
1042
|
+
fxNodeDispatchBind(self->statement, param);
|
|
1043
|
+
fxScopeBound(self->scope, param);
|
|
1044
|
+
fxBinderPopVariables(param, 5);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
void fxFunctionNodeBind(void* it, void* param)
|
|
1048
|
+
{
|
|
1049
|
+
txFunctionNode* self = it;
|
|
1050
|
+
txBinder* binder = param;
|
|
1051
|
+
txInteger scopeLevel = binder->scopeLevel;
|
|
1052
|
+
txInteger scopeMaximum = binder->scopeMaximum;
|
|
1053
|
+
scopeLevel = binder->scopeLevel;
|
|
1054
|
+
scopeMaximum = binder->scopeMaximum;
|
|
1055
|
+
binder->scopeLevel = 0;
|
|
1056
|
+
binder->scopeMaximum = 0;
|
|
1057
|
+
fxScopeBinding(self->scope, param);
|
|
1058
|
+
fxNodeDispatchBind(self->params, param);
|
|
1059
|
+
if (self->flags & mxBaseFlag) {
|
|
1060
|
+
if (binder->classNode->instanceInitAccess) {
|
|
1061
|
+
fxScopeLookup(binder->scope, binder->classNode->instanceInitAccess, 0);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
fxScopeBindDefineNodes(self->scope, param);
|
|
1065
|
+
fxNodeDispatchBind(self->body, param);
|
|
1066
|
+
fxScopeBound(self->scope, param);
|
|
1067
|
+
self->scopeCount = binder->scopeMaximum;
|
|
1068
|
+
binder->scopeMaximum = scopeMaximum;
|
|
1069
|
+
binder->scopeLevel = scopeLevel;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
void fxFunctionNodeRename(void* it, txSymbol* symbol)
|
|
1073
|
+
{
|
|
1074
|
+
txNode* self = it;
|
|
1075
|
+
txToken token = self->description->token;
|
|
1076
|
+
if (token == XS_TOKEN_EXPRESSIONS) {
|
|
1077
|
+
self = ((txExpressionsNode*)self)->items->first;
|
|
1078
|
+
if (self->next)
|
|
1079
|
+
return;
|
|
1080
|
+
token = self->description->token;
|
|
1081
|
+
}
|
|
1082
|
+
if (token == XS_TOKEN_CLASS) {
|
|
1083
|
+
txClassNode* node = (txClassNode*)self;
|
|
1084
|
+
if (!node->symbol)
|
|
1085
|
+
((txFunctionNode*)(node->constructor))->symbol = symbol;
|
|
1086
|
+
}
|
|
1087
|
+
else if ((token == XS_TOKEN_FUNCTION) || (token == XS_TOKEN_GENERATOR) || (token == XS_TOKEN_HOST)) {
|
|
1088
|
+
txFunctionNode* node = (txFunctionNode*)self;
|
|
1089
|
+
if (!node->symbol)
|
|
1090
|
+
node->symbol = symbol;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
void fxHostNodeBind(void* it, void* param)
|
|
1095
|
+
{
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
void fxModuleNodeBind(void* it, void* param)
|
|
1099
|
+
{
|
|
1100
|
+
txModuleNode* self = it;
|
|
1101
|
+
txBinder* binder = param;
|
|
1102
|
+
fxScopeBinding(self->scope, param);
|
|
1103
|
+
fxScopeBindDefineNodes(self->scope, param);
|
|
1104
|
+
fxNodeDispatchBind(self->body, param);
|
|
1105
|
+
fxScopeBound(self->scope, param);
|
|
1106
|
+
self->scopeCount = binder->scopeMaximum;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
void fxObjectNodeBind(void* it, void* param)
|
|
1110
|
+
{
|
|
1111
|
+
txObjectNode* self = it;
|
|
1112
|
+
txNode* item = self->items->first;
|
|
1113
|
+
fxBinderPushVariables(param, 1);
|
|
1114
|
+
while (item) {
|
|
1115
|
+
txNode* value;
|
|
1116
|
+
if (item->description->token == XS_TOKEN_SPREAD) {
|
|
1117
|
+
}
|
|
1118
|
+
else {
|
|
1119
|
+
if (item->description->token == XS_TOKEN_PROPERTY) {
|
|
1120
|
+
value = ((txPropertyNode*)item)->value;
|
|
1121
|
+
}
|
|
1122
|
+
else {
|
|
1123
|
+
value = ((txPropertyAtNode*)item)->value;
|
|
1124
|
+
}
|
|
1125
|
+
if ((value->description->token == XS_TOKEN_FUNCTION) || (value->description->token == XS_TOKEN_GENERATOR) || (value->description->token == XS_TOKEN_HOST)) {
|
|
1126
|
+
txFunctionNode* node = (txFunctionNode*)value;
|
|
1127
|
+
node->flags |= item->flags & (mxMethodFlag | mxGetterFlag | mxSetterFlag);
|
|
1128
|
+
}
|
|
1129
|
+
else if (value->description->token == XS_TOKEN_CLASS) {
|
|
1130
|
+
// txFunctionNode* node = (txFunctionNode*)(((txClassNode*)value)->constructor);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
fxNodeDispatchBind(item, param);
|
|
1134
|
+
item = item->next;
|
|
1135
|
+
}
|
|
1136
|
+
fxBinderPopVariables(param, 1);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
void fxObjectBindingNodeBind(void* it, void* param)
|
|
1140
|
+
{
|
|
1141
|
+
txObjectBindingNode* self = it;
|
|
1142
|
+
fxBinderPushVariables(param, 2);
|
|
1143
|
+
fxNodeListDistribute(self->items, fxNodeDispatchBind, param);
|
|
1144
|
+
fxBinderPopVariables(param, 2);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
void fxParamsNodeBind(void* it, void* param)
|
|
1148
|
+
{
|
|
1149
|
+
txParamsNode* self = it;
|
|
1150
|
+
if (self->flags & mxSpreadFlag) {
|
|
1151
|
+
fxBinderPushVariables(param, 1);
|
|
1152
|
+
fxNodeListDistribute(self->items, fxNodeDispatchBind, param);
|
|
1153
|
+
fxBinderPopVariables(param, 1);
|
|
1154
|
+
}
|
|
1155
|
+
else
|
|
1156
|
+
fxNodeListDistribute(self->items, fxNodeDispatchBind, param);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
void fxParamsBindingNodeBind(void* it, void* param)
|
|
1160
|
+
{
|
|
1161
|
+
txParamsBindingNode* self = it;
|
|
1162
|
+
txBinder* binder = param;
|
|
1163
|
+
txScope* functionScope = binder->scope;
|
|
1164
|
+
txFunctionNode* functionNode = (txFunctionNode*)(functionScope->node);
|
|
1165
|
+
txInteger count = self->items->length;
|
|
1166
|
+
if (functionNode->flags & mxGetterFlag) {
|
|
1167
|
+
if (count != 0)
|
|
1168
|
+
fxReportParserError(binder->parser, self->line, "invalid getter arguments");
|
|
1169
|
+
}
|
|
1170
|
+
else if (functionNode->flags & mxSetterFlag) {
|
|
1171
|
+
if ((count != 1) || (self->items->first->description->token == XS_TOKEN_REST_BINDING))
|
|
1172
|
+
fxReportParserError(binder->parser, self->line, "invalid setter arguments");
|
|
1173
|
+
}
|
|
1174
|
+
else {
|
|
1175
|
+
if (count > 255)
|
|
1176
|
+
fxReportParserError(binder->parser, self->line, "too many arguments");
|
|
1177
|
+
}
|
|
1178
|
+
if (functionNode->flags & mxArgumentsFlag) {
|
|
1179
|
+
txNode* item;
|
|
1180
|
+
self->declaration = fxScopeGetDeclareNode(functionScope, binder->parser->argumentsSymbol);
|
|
1181
|
+
if (functionNode->flags & mxStrictFlag)
|
|
1182
|
+
goto bail;
|
|
1183
|
+
item = self->items->first;
|
|
1184
|
+
while (item) {
|
|
1185
|
+
if (item->description->token != XS_TOKEN_ARG)
|
|
1186
|
+
goto bail;
|
|
1187
|
+
item = item->next;
|
|
1188
|
+
}
|
|
1189
|
+
item = self->items->first;
|
|
1190
|
+
while (item) {
|
|
1191
|
+
((txDeclareNode*)item)->flags |= mxDeclareNodeClosureFlag;
|
|
1192
|
+
item = item->next;
|
|
1193
|
+
}
|
|
1194
|
+
self->mapped = 1;
|
|
1195
|
+
}
|
|
1196
|
+
bail:
|
|
1197
|
+
fxNodeListDistribute(self->items, fxNodeDispatchBind, param);
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
void fxPostfixExpressionNodeBind(void* it, void* param)
|
|
1201
|
+
{
|
|
1202
|
+
txPostfixExpressionNode* self = it;
|
|
1203
|
+
fxNodeDispatchBind(self->left, param);
|
|
1204
|
+
fxBinderPushVariables(param, 1);
|
|
1205
|
+
fxBinderPopVariables(param, 1);
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
void fxPrivateMemberNodeBind(void* it, void* param)
|
|
1209
|
+
{
|
|
1210
|
+
txBinder* binder = param;
|
|
1211
|
+
txPrivateMemberNode* self = it;
|
|
1212
|
+
fxScopeLookup(binder->scope, (txAccessNode*)self, 0);
|
|
1213
|
+
if (!self->declaration)
|
|
1214
|
+
fxReportParserError(binder->parser, self->line, "invalid private identifier");
|
|
1215
|
+
fxNodeDispatchBind(self->reference, param);
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
void fxProgramNodeBind(void* it, void* param)
|
|
1219
|
+
{
|
|
1220
|
+
txProgramNode* self = it;
|
|
1221
|
+
txBinder* binder = param;
|
|
1222
|
+
fxScopeBinding(self->scope, param);
|
|
1223
|
+
fxScopeBindDefineNodes(self->scope, param);
|
|
1224
|
+
fxNodeDispatchBind(self->body, param);
|
|
1225
|
+
fxScopeBound(self->scope, param);
|
|
1226
|
+
self->scopeCount = binder->scopeMaximum;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
void fxSpreadNodeBind(void* it, void* param)
|
|
1230
|
+
{
|
|
1231
|
+
txSpreadNode* self = it;
|
|
1232
|
+
fxBinderPushVariables(param, 1);
|
|
1233
|
+
fxNodeDispatchBind(self->expression, param);
|
|
1234
|
+
fxBinderPopVariables(param, 1);
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
void fxSuperNodeBind(void* it, void* param)
|
|
1238
|
+
{
|
|
1239
|
+
txSuperNode* self = it;
|
|
1240
|
+
txBinder* binder = param;
|
|
1241
|
+
fxNodeDispatchBind(self->params, param);
|
|
1242
|
+
if (binder->classNode->instanceInitAccess) {
|
|
1243
|
+
fxScopeLookup(binder->scope, binder->classNode->instanceInitAccess, 0);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
void fxSwitchNodeBind(void* it, void* param)
|
|
1248
|
+
{
|
|
1249
|
+
txSwitchNode* self = it;
|
|
1250
|
+
fxNodeDispatchBind(self->expression, param);
|
|
1251
|
+
fxScopeBinding(self->scope, param);
|
|
1252
|
+
fxScopeBindDefineNodes(self->scope, param);
|
|
1253
|
+
fxNodeListDistribute(self->items, fxNodeDispatchBind, param);
|
|
1254
|
+
fxScopeBound(self->scope, param);
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
void fxTemplateNodeBind(void* it, void* param)
|
|
1258
|
+
{
|
|
1259
|
+
txTemplateNode* self = it;
|
|
1260
|
+
if (self->reference) {
|
|
1261
|
+
fxBinderPushVariables(param, 2);
|
|
1262
|
+
fxNodeDispatchBind(self->reference, param);
|
|
1263
|
+
fxNodeListDistribute(self->items, fxNodeDispatchBind, param);
|
|
1264
|
+
fxBinderPopVariables(param, 2);
|
|
1265
|
+
}
|
|
1266
|
+
else {
|
|
1267
|
+
fxNodeListDistribute(self->items, fxNodeDispatchBind, param);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
void fxTryNodeBind(void* it, void* param)
|
|
1272
|
+
{
|
|
1273
|
+
txTryNode* self = it;
|
|
1274
|
+
fxBinderPushVariables(param, 3);
|
|
1275
|
+
fxNodeDispatchBind(self->tryBlock, param);
|
|
1276
|
+
if (self->catchBlock)
|
|
1277
|
+
fxNodeDispatchBind(self->catchBlock, param);
|
|
1278
|
+
if (self->finallyBlock)
|
|
1279
|
+
fxNodeDispatchBind(self->finallyBlock, param);
|
|
1280
|
+
fxBinderPopVariables(param, 3);
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
void fxWithNodeBind(void* it, void* param)
|
|
1284
|
+
{
|
|
1285
|
+
txWithNode* self = it;
|
|
1286
|
+
fxNodeDispatchBind(self->expression, param);
|
|
1287
|
+
fxScopeBinding(self->scope, param);
|
|
1288
|
+
fxNodeDispatchBind(self->statement, param);
|
|
1289
|
+
fxScopeBound(self->scope, param);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
|
|
1293
|
+
|