author | Claus Gittinger <cg@exept.de> |
Fri, 21 Feb 2020 20:48:14 +0100 | |
changeset 1231 | b7d945ef967a |
parent 1198 | 4fc20702d5bf |
permissions | -rw-r--r-- |
155 | 1 |
" |
2 |
COPYRIGHT (c) 2005 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
39 | 12 |
"{ Package: 'stx:libjavascript' }" |
13 |
||
1198 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
39 | 16 |
ParseNode subclass:#JavaScriptClassNode |
502 | 17 |
instanceVariableNames:'className superClassName privateVariables environment |
753 | 18 |
staticVariables' |
39 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
47 | 21 |
category:'Languages-JavaScript-Compiling & Parsing' |
39 | 22 |
! |
23 |
||
155 | 24 |
!JavaScriptClassNode class methodsFor:'documentation'! |
25 |
||
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 2005 by eXept Software AG |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
! ! |
|
39 | 39 |
|
40 |
!JavaScriptClassNode methodsFor:'accessing'! |
|
41 |
||
388 | 42 |
_argVariables |
43 |
^ nil |
|
44 |
! |
|
45 |
||
83 | 46 |
_localVariables |
47 |
^ self _variables |
|
48 |
! |
|
49 |
||
50 |
_localVariables:aCollection |
|
51 |
self _variables:aCollection |
|
52 |
! |
|
53 |
||
39 | 54 |
_outerEnvironment |
55 |
^ environment |
|
56 |
||
57 |
"Created: / 17.5.1998 / 00:41:00 / cg" |
|
58 |
! |
|
59 |
||
60 |
_outerEnvironment:anEnvironment |
|
61 |
environment := anEnvironment |
|
62 |
||
63 |
"Created: / 17.5.1998 / 00:41:11 / cg" |
|
64 |
! |
|
65 |
||
66 |
_variables |
|
67 |
^ privateVariables |
|
68 |
! |
|
69 |
||
70 |
_variables:aVariablesEnvironment |
|
71 |
privateVariables := aVariablesEnvironment |
|
72 |
! |
|
73 |
||
74 |
className |
|
75 |
"return the value of the instance variable 'className' (automatically generated)" |
|
76 |
||
47 | 77 |
^ className |
78 |
! |
|
39 | 79 |
|
80 |
className:something |
|
81 |
"set the value of the instance variable 'className' (automatically generated)" |
|
82 |
||
47 | 83 |
className := something. |
84 |
! |
|
39 | 85 |
|
502 | 86 |
staticVariables |
87 |
^ staticVariables |
|
88 |
! |
|
89 |
||
90 |
staticVariables:something |
|
91 |
staticVariables := something. |
|
92 |
! |
|
93 |
||
39 | 94 |
superClassName |
95 |
"return the value of the instance variable 'superClassName' (automatically generated)" |
|
96 |
||
47 | 97 |
^ superClassName |
98 |
! |
|
39 | 99 |
|
100 |
superClassName:something |
|
101 |
"set the value of the instance variable 'superClassName' (automatically generated)" |
|
102 |
||
47 | 103 |
superClassName := something. |
104 |
! ! |
|
39 | 105 |
|
106 |
!JavaScriptClassNode methodsFor:'evaluation'! |
|
107 |
||
108 |
evaluate |
|
753 | 109 |
"evaluate (i.e. install) a class definition" |
110 |
||
111 |
|superClass oldClass newClass instVars instVarNames classVarNames category environment |
|
112 |
firstInitStatement lastInitStatement| |
|
39 | 113 |
|
114 |
superClass := Smalltalk at:superClassName asSymbol. |
|
753 | 115 |
instVars := OrderedCollection new. |
39 | 116 |
privateVariables size > 0 ifTrue:[ |
83 | 117 |
privateVariables keysAndValuesDo:[:varName :var | |
753 | 118 |
instVars add:varName. |
83 | 119 |
] |
39 | 120 |
]. |
753 | 121 |
instVarNames := instVars asStringWith:' '. |
502 | 122 |
classVarNames := ''. |
123 |
staticVariables size > 0 ifTrue:[ |
|
124 |
staticVariables keysAndValuesDo:[:varName :var | |
|
1198 | 125 |
classVarNames size ~~ 0 ifTrue:[ |
502 | 126 |
classVarNames := classVarNames , ' ' |
127 |
]. |
|
128 |
classVarNames := classVarNames , varName |
|
129 |
] |
|
130 |
]. |
|
104 | 131 |
environment := Class nameSpaceQuerySignal query. |
132 |
oldClass := environment classNamed:className. |
|
133 |
||
388 | 134 |
category := Class classCategoryQuerySignal query. |
135 |
"/ oldClass notNil ifTrue:[ |
|
136 |
"/ category := oldClass category. |
|
137 |
"/ ] ifFalse:[ |
|
138 |
"/ category := superClass category |
|
139 |
"/ ]. |
|
753 | 140 |
newClass := JavaScriptMetaclass new |
83 | 141 |
name:(className asSymbol) |
104 | 142 |
inEnvironment:environment |
83 | 143 |
subclassOf:superClass |
144 |
instanceVariableNames:instVarNames |
|
145 |
variable:false |
|
146 |
words:false |
|
147 |
pointers:false |
|
502 | 148 |
classVariableNames:classVarNames |
83 | 149 |
poolDictionaries:'' |
104 | 150 |
category:category |
83 | 151 |
comment:nil |
152 |
changed:true. |
|
529 | 153 |
|
154 |
"initialize static variables..." |
|
533 | 155 |
staticVariables notNil ifTrue:[ |
156 |
staticVariables keysAndValuesDo:[:varName :var | |
|
157 |
var expressionForSetup notNil ifTrue:[ |
|
158 |
newClass classVarAt: varName put: (var expressionForSetup evaluate). |
|
159 |
] |
|
160 |
]. |
|
529 | 161 |
]. |
753 | 162 |
|
163 |
"/ if any var has an init-expression, generate an initializer method |
|
164 |
firstInitStatement := lastInitStatement := nil. |
|
770 | 165 |
(privateVariables ? #()) keysAndValuesDo:[:varName :var | |
753 | 166 |
|varNode initStatement| |
167 |
||
168 |
var expressionForSetup notNil ifTrue:[ |
|
169 |
varNode := JavaScriptVariableNode |
|
170 |
type:#InstanceVariable |
|
171 |
name:var name |
|
172 |
token:var |
|
173 |
index:(instVars indexOf:var name). |
|
174 |
initStatement := JavaScriptParser::JavaScriptStatementNode new |
|
175 |
expression:(JavaScriptParser::JavaScriptAssignmentNode variable:varNode expression:var expressionForSetup). |
|
176 |
firstInitStatement isNil ifTrue:[ |
|
177 |
firstInitStatement := initStatement |
|
178 |
] ifFalse:[ |
|
179 |
lastInitStatement nextStatement:initStatement |
|
180 |
]. |
|
181 |
lastInitStatement := initStatement |
|
182 |
] |
|
183 |
]. |
|
184 |
firstInitStatement notNil ifTrue:[ |
|
185 |
|stat1 stat2 fn| |
|
186 |
||
187 |
fn := JavaScriptFunctionNode new. |
|
188 |
fn functionName:'__initialize__'. |
|
189 |
superClass == Object ifTrue:[ |
|
190 |
stat1 := firstInitStatement. |
|
191 |
] ifFalse:[ |
|
192 |
stat1 := JavaScriptParser::JavaScriptStatementNode new |
|
193 |
expression:((JavaScriptParser::FunctionCallNode |
|
194 |
receiver:(SuperNode new) |
|
195 |
selector:'__initialize__') |
|
196 |
javaScriptSelector:'__initialize__'). |
|
197 |
stat1 nextStatement:firstInitStatement. |
|
198 |
]. |
|
199 |
stat2 := JavaScriptParser::JavaScriptReturnNode new |
|
200 |
expression:(JavaScriptParser::ThisNode new). |
|
201 |
lastInitStatement nextStatement:stat2. |
|
202 |
fn statements:stat1. |
|
203 |
||
204 |
JavaScriptCompiler new |
|
205 |
compileTree:fn source:(fn printString) forClass:newClass inCategory:'initialization' notifying:nil |
|
206 |
install:true skipIfSame:false silent:true foldConstants:true |
|
207 |
ifFail:[ self halt ]. |
|
208 |
||
209 |
JavaScriptCompiler new |
|
210 |
compile:'function new() { |
|
211 |
return (this.basicNew().__initialize__().initialize()); |
|
212 |
}' |
|
213 |
forClass:newClass class inCategory:'instance creation' notifying:nil |
|
214 |
install:true skipIfSame:false silent:true foldConstants:true |
|
215 |
ifFail:[ self halt ]. |
|
216 |
]. |
|
217 |
||
39 | 218 |
^ newClass |
502 | 219 |
|
533 | 220 |
"Modified: / 17-07-2012 / 12:41:13 / cg" |
502 | 221 |
! ! |
222 |
||
223 |
!JavaScriptClassNode methodsFor:'testing'! |
|
224 |
||
225 |
_isFunctionEnvironment |
|
226 |
^ false |
|
227 |
||
228 |
"Created: / 30-01-2011 / 17:11:10 / cg" |
|
752 | 229 |
! |
230 |
||
231 |
isInnerFunction |
|
232 |
^ false |
|
233 |
! |
|
234 |
||
235 |
isJavaScriptClassNode |
|
236 |
^ true |
|
39 | 237 |
! ! |
238 |
||
656
21a4b2035a9e
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
643
diff
changeset
|
239 |
!JavaScriptClassNode methodsFor:'visiting'! |
21a4b2035a9e
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
643
diff
changeset
|
240 |
|
21a4b2035a9e
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
643
diff
changeset
|
241 |
acceptVisitor:visitor |
21a4b2035a9e
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
643
diff
changeset
|
242 |
"Double dispatch back to the visitor, passing my type encoded in |
21a4b2035a9e
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
643
diff
changeset
|
243 |
the selector (visitor pattern)" |
21a4b2035a9e
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
643
diff
changeset
|
244 |
|
21a4b2035a9e
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
643
diff
changeset
|
245 |
"stub code automatically generated - please change if required" |
21a4b2035a9e
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
643
diff
changeset
|
246 |
|
21a4b2035a9e
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
643
diff
changeset
|
247 |
^ visitor visitJavaScriptClassNode:self |
21a4b2035a9e
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
643
diff
changeset
|
248 |
! ! |
21a4b2035a9e
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
643
diff
changeset
|
249 |
|
39 | 250 |
!JavaScriptClassNode class methodsFor:'documentation'! |
251 |
||
252 |
version |
|
253 |
^ '$Header$' |
|
388 | 254 |
! |
255 |
||
256 |
version_CVS |
|
257 |
^ '$Header$' |
|
39 | 258 |
! ! |
643 | 259 |