Compiler-Semantic.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. smalltalk.addPackage('Compiler-Semantic', {});
  2. smalltalk.addClass('LexicalScope', smalltalk.Object, ['node', 'temps', 'args', 'outerScope'], 'Compiler-Semantic');
  3. smalltalk.LexicalScope.comment="I represent a lexical scope where variable names are associated with ScopeVars\x0aInstances are used for block scopes. Method scopes are instances of MethodLexicalScope.\x0a\x0aI am attached to a ScopeVar and method/block nodes.\x0aEach context (method/closure) get a fresh scope that inherits from its outer scope."
  4. smalltalk.addMethod(
  5. "_addArg_",
  6. smalltalk.method({
  7. selector: "addArg:",
  8. category: 'adding',
  9. fn: function (aString) {
  10. var self=this;
  11. smalltalk.send(smalltalk.send(self, "_args", []), "_at_put_", [aString, smalltalk.send((smalltalk.ArgVar || ArgVar), "_on_", [aString])]);
  12. smalltalk.send(smalltalk.send(smalltalk.send(self, "_args", []), "_at_", [aString]), "_scope_", [self]);
  13. return self;},
  14. args: ["aString"],
  15. source: "addArg: aString\x0a\x09self args at: aString put: (ArgVar on: aString).\x0a\x09(self args at: aString) scope: self",
  16. messageSends: ["at:put:", "args", "on:", "scope:", "at:"],
  17. referencedClasses: ["ArgVar"]
  18. }),
  19. smalltalk.LexicalScope);
  20. smalltalk.addMethod(
  21. "_addTemp_",
  22. smalltalk.method({
  23. selector: "addTemp:",
  24. category: 'adding',
  25. fn: function (aString) {
  26. var self=this;
  27. smalltalk.send(smalltalk.send(self, "_temps", []), "_at_put_", [aString, smalltalk.send((smalltalk.TempVar || TempVar), "_on_", [aString])]);
  28. smalltalk.send(smalltalk.send(smalltalk.send(self, "_temps", []), "_at_", [aString]), "_scope_", [self]);
  29. return self;},
  30. args: ["aString"],
  31. source: "addTemp: aString\x0a\x09self temps at: aString put: (TempVar on: aString).\x0a\x09(self temps at: aString) scope: self",
  32. messageSends: ["at:put:", "temps", "on:", "scope:", "at:"],
  33. referencedClasses: ["TempVar"]
  34. }),
  35. smalltalk.LexicalScope);
  36. smalltalk.addMethod(
  37. "_allVariableNames",
  38. smalltalk.method({
  39. selector: "allVariableNames",
  40. category: 'accessing',
  41. fn: function () {
  42. var self=this;
  43. return smalltalk.send(smalltalk.send(smalltalk.send(self, "_args", []), "_keys", []), "__comma", [smalltalk.send(smalltalk.send(self, "_temps", []), "_keys", [])]);
  44. return self;},
  45. args: [],
  46. source: "allVariableNames\x0a\x09^ self args keys, self temps keys",
  47. messageSends: [",", "keys", "args", "temps"],
  48. referencedClasses: []
  49. }),
  50. smalltalk.LexicalScope);
  51. smalltalk.addMethod(
  52. "_args",
  53. smalltalk.method({
  54. selector: "args",
  55. category: 'accessing',
  56. fn: function () {
  57. var self=this;
  58. return (($receiver = self['@args']) == nil || $receiver == undefined) ? (function(){return (self['@args']=smalltalk.send((smalltalk.Dictionary || Dictionary), "_new", []));})() : $receiver;
  59. return self;},
  60. args: [],
  61. source: "args\x0a\x09^ args ifNil: [ args := Dictionary new ]",
  62. messageSends: ["ifNil:", "new"],
  63. referencedClasses: ["Dictionary"]
  64. }),
  65. smalltalk.LexicalScope);
  66. smalltalk.addMethod(
  67. "_bindingFor_",
  68. smalltalk.method({
  69. selector: "bindingFor:",
  70. category: 'accessing',
  71. fn: function (aStringOrNode) {
  72. var self=this;
  73. return smalltalk.send(smalltalk.send(self, "_args", []), "_at_ifAbsent_", [smalltalk.send(aStringOrNode, "_value", []), (function(){return smalltalk.send(smalltalk.send(self, "_temps", []), "_at_ifAbsent_", [smalltalk.send(aStringOrNode, "_value", []), (function(){return nil;})]);})]);
  74. return self;},
  75. args: ["aStringOrNode"],
  76. source: "bindingFor: aStringOrNode\x0a\x09^ self args at: aStringOrNode value ifAbsent: [\x0a\x09\x09self temps at: aStringOrNode value ifAbsent: [ nil ]]",
  77. messageSends: ["at:ifAbsent:", "args", "value", "temps"],
  78. referencedClasses: []
  79. }),
  80. smalltalk.LexicalScope);
  81. smalltalk.addMethod(
  82. "_isMethodScope",
  83. smalltalk.method({
  84. selector: "isMethodScope",
  85. category: 'testing',
  86. fn: function () {
  87. var self=this;
  88. return false;
  89. return self;},
  90. args: [],
  91. source: "isMethodScope\x0a\x09^ false",
  92. messageSends: [],
  93. referencedClasses: []
  94. }),
  95. smalltalk.LexicalScope);
  96. smalltalk.addMethod(
  97. "_lookupVariable_",
  98. smalltalk.method({
  99. selector: "lookupVariable:",
  100. category: 'accessing',
  101. fn: function (aNode) {
  102. var self=this;
  103. var lookup=nil;
  104. (lookup=smalltalk.send(self, "_bindingFor_", [aNode]));
  105. (($receiver = lookup) == nil || $receiver == undefined) ? (function(){return (lookup=(($receiver = smalltalk.send(self, "_outerScope", [])) != nil && $receiver != undefined) ? (function(){return smalltalk.send(smalltalk.send(self, "_outerScope", []), "_lookupVariable_", [aNode]);})() : nil);})() : $receiver;
  106. return lookup;
  107. return self;},
  108. args: ["aNode"],
  109. source: "lookupVariable: aNode\x0a\x09| lookup |\x0a\x09lookup := (self bindingFor: aNode).\x0a\x09lookup ifNil: [\x0a\x09\x09lookup := self outerScope ifNotNil: [ \x0a\x09\x09\x09(self outerScope lookupVariable: aNode) ]].\x0a\x09^ lookup",
  110. messageSends: ["bindingFor:", "ifNil:", "ifNotNil:", "outerScope", "lookupVariable:"],
  111. referencedClasses: []
  112. }),
  113. smalltalk.LexicalScope);
  114. smalltalk.addMethod(
  115. "_methodScope",
  116. smalltalk.method({
  117. selector: "methodScope",
  118. category: 'accessing',
  119. fn: function () {
  120. var self=this;
  121. return (($receiver = smalltalk.send(self, "_outerScope", [])) != nil && $receiver != undefined) ? (function(){return smalltalk.send(smalltalk.send(self, "_outerScope", []), "_methodScope", []);})() : nil;
  122. return self;},
  123. args: [],
  124. source: "methodScope\x0a\x09^ self outerScope ifNotNil: [\x0a\x09\x09self outerScope methodScope ]",
  125. messageSends: ["ifNotNil:", "outerScope", "methodScope"],
  126. referencedClasses: []
  127. }),
  128. smalltalk.LexicalScope);
  129. smalltalk.addMethod(
  130. "_node",
  131. smalltalk.method({
  132. selector: "node",
  133. category: 'accessing',
  134. fn: function () {
  135. var self=this;
  136. return self['@node'];
  137. return self;},
  138. args: [],
  139. source: "node\x0a\x09\x22Answer the node in which I am defined\x22\x0a\x09\x0a\x09^ node",
  140. messageSends: [],
  141. referencedClasses: []
  142. }),
  143. smalltalk.LexicalScope);
  144. smalltalk.addMethod(
  145. "_node_",
  146. smalltalk.method({
  147. selector: "node:",
  148. category: 'accessing',
  149. fn: function (aNode) {
  150. var self=this;
  151. (self['@node']=aNode);
  152. return self;},
  153. args: ["aNode"],
  154. source: "node: aNode\x0a\x09node := aNode",
  155. messageSends: [],
  156. referencedClasses: []
  157. }),
  158. smalltalk.LexicalScope);
  159. smalltalk.addMethod(
  160. "_outerScope",
  161. smalltalk.method({
  162. selector: "outerScope",
  163. category: 'accessing',
  164. fn: function () {
  165. var self=this;
  166. return self['@outerScope'];
  167. return self;},
  168. args: [],
  169. source: "outerScope\x0a\x09^ outerScope",
  170. messageSends: [],
  171. referencedClasses: []
  172. }),
  173. smalltalk.LexicalScope);
  174. smalltalk.addMethod(
  175. "_outerScope_",
  176. smalltalk.method({
  177. selector: "outerScope:",
  178. category: 'accessing',
  179. fn: function (aLexicalScope) {
  180. var self=this;
  181. (self['@outerScope']=aLexicalScope);
  182. return self;},
  183. args: ["aLexicalScope"],
  184. source: "outerScope: aLexicalScope\x0a\x09outerScope := aLexicalScope",
  185. messageSends: [],
  186. referencedClasses: []
  187. }),
  188. smalltalk.LexicalScope);
  189. smalltalk.addMethod(
  190. "_scopeLevel",
  191. smalltalk.method({
  192. selector: "scopeLevel",
  193. category: 'accessing',
  194. fn: function () {
  195. var self=this;
  196. return ((($receiver = (($receiver = smalltalk.send(self, "_outerScope", [])) == nil || $receiver == undefined) ? (function(){return (0);})() : (function(){return smalltalk.send(smalltalk.send(self, "_outerScope", []), "_scopeLevel", []);})()).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)]));
  197. return self;},
  198. args: [],
  199. source: "scopeLevel\x0a\x09^ (self outerScope \x0a\x09\x09ifNil: [ 0 ]\x0a\x09\x09ifNotNil: [ self outerScope scopeLevel ]) + 1",
  200. messageSends: ["+", "ifNil:ifNotNil:", "outerScope", "scopeLevel"],
  201. referencedClasses: []
  202. }),
  203. smalltalk.LexicalScope);
  204. smalltalk.addMethod(
  205. "_temps",
  206. smalltalk.method({
  207. selector: "temps",
  208. category: 'accessing',
  209. fn: function () {
  210. var self=this;
  211. return (($receiver = self['@temps']) == nil || $receiver == undefined) ? (function(){return (self['@temps']=smalltalk.send((smalltalk.Dictionary || Dictionary), "_new", []));})() : $receiver;
  212. return self;},
  213. args: [],
  214. source: "temps\x0a\x09^ temps ifNil: [ temps := Dictionary new ]",
  215. messageSends: ["ifNil:", "new"],
  216. referencedClasses: ["Dictionary"]
  217. }),
  218. smalltalk.LexicalScope);
  219. smalltalk.addClass('MethodLexicalScope', smalltalk.LexicalScope, ['iVars', 'unknownVariables', 'nonLocalReturn'], 'Compiler-Semantic');
  220. smalltalk.MethodLexicalScope.comment="I represent a method scope."
  221. smalltalk.addMethod(
  222. "_addIvar_",
  223. smalltalk.method({
  224. selector: "addIvar:",
  225. category: 'adding',
  226. fn: function (aString) {
  227. var self=this;
  228. smalltalk.send(smalltalk.send(self, "_iVars", []), "_at_put_", [aString, smalltalk.send((smalltalk.InstanceVar || InstanceVar), "_on_", [aString])]);
  229. smalltalk.send(smalltalk.send(smalltalk.send(self, "_iVars", []), "_at_", [aString]), "_scope_", [self]);
  230. return self;},
  231. args: ["aString"],
  232. source: "addIvar: aString\x0a\x09self iVars at: aString put: (InstanceVar on: aString).\x0a\x09(self iVars at: aString) scope: self",
  233. messageSends: ["at:put:", "iVars", "on:", "scope:", "at:"],
  234. referencedClasses: ["InstanceVar"]
  235. }),
  236. smalltalk.MethodLexicalScope);
  237. smalltalk.addMethod(
  238. "_allVariableNames",
  239. smalltalk.method({
  240. selector: "allVariableNames",
  241. category: 'accessing',
  242. fn: function () {
  243. var self=this;
  244. return smalltalk.send(smalltalk.send(self, "_allVariableNames", [], smalltalk.MethodLexicalScope.superclass || nil), "__comma", [smalltalk.send(smalltalk.send(self, "_iVars", []), "_keys", [])]);
  245. return self;},
  246. args: [],
  247. source: "allVariableNames\x0a\x09^ super allVariableNames, self iVars keys",
  248. messageSends: [",", "allVariableNames", "keys", "iVars"],
  249. referencedClasses: []
  250. }),
  251. smalltalk.MethodLexicalScope);
  252. smalltalk.addMethod(
  253. "_bindingFor_",
  254. smalltalk.method({
  255. selector: "bindingFor:",
  256. category: 'accessing',
  257. fn: function (aNode) {
  258. var self=this;
  259. return (($receiver = smalltalk.send(self, "_bindingFor_", [aNode], smalltalk.MethodLexicalScope.superclass || nil)) == nil || $receiver == undefined) ? (function(){return smalltalk.send(smalltalk.send(self, "_iVars", []), "_at_ifAbsent_", [smalltalk.send(aNode, "_value", []), (function(){return nil;})]);})() : $receiver;
  260. return self;},
  261. args: ["aNode"],
  262. source: "bindingFor: aNode\x0a\x09^ (super bindingFor: aNode) ifNil: [\x0a\x09\x09self iVars at: aNode value ifAbsent: [ nil ]]",
  263. messageSends: ["ifNil:", "bindingFor:", "at:ifAbsent:", "iVars", "value"],
  264. referencedClasses: []
  265. }),
  266. smalltalk.MethodLexicalScope);
  267. smalltalk.addMethod(
  268. "_hasNonLocalReturn",
  269. smalltalk.method({
  270. selector: "hasNonLocalReturn",
  271. category: 'testing',
  272. fn: function () {
  273. var self=this;
  274. return smalltalk.send(self, "_nonLocalReturn", []);
  275. return self;},
  276. args: [],
  277. source: "hasNonLocalReturn\x0a\x09^ self nonLocalReturn",
  278. messageSends: ["nonLocalReturn"],
  279. referencedClasses: []
  280. }),
  281. smalltalk.MethodLexicalScope);
  282. smalltalk.addMethod(
  283. "_iVars",
  284. smalltalk.method({
  285. selector: "iVars",
  286. category: 'accessing',
  287. fn: function () {
  288. var self=this;
  289. return (($receiver = self['@iVars']) == nil || $receiver == undefined) ? (function(){return (self['@iVars']=smalltalk.send((smalltalk.Dictionary || Dictionary), "_new", []));})() : $receiver;
  290. return self;},
  291. args: [],
  292. source: "iVars\x0a\x09^ iVars ifNil: [ iVars := Dictionary new ]",
  293. messageSends: ["ifNil:", "new"],
  294. referencedClasses: ["Dictionary"]
  295. }),
  296. smalltalk.MethodLexicalScope);
  297. smalltalk.addMethod(
  298. "_isMethodScope",
  299. smalltalk.method({
  300. selector: "isMethodScope",
  301. category: 'testing',
  302. fn: function () {
  303. var self=this;
  304. return true;
  305. return self;},
  306. args: [],
  307. source: "isMethodScope\x0a\x09^ true",
  308. messageSends: [],
  309. referencedClasses: []
  310. }),
  311. smalltalk.MethodLexicalScope);
  312. smalltalk.addMethod(
  313. "_methodScope",
  314. smalltalk.method({
  315. selector: "methodScope",
  316. category: 'accessing',
  317. fn: function () {
  318. var self=this;
  319. return self;
  320. return self;},
  321. args: [],
  322. source: "methodScope\x0a\x09^ self",
  323. messageSends: [],
  324. referencedClasses: []
  325. }),
  326. smalltalk.MethodLexicalScope);
  327. smalltalk.addMethod(
  328. "_nonLocalReturn",
  329. smalltalk.method({
  330. selector: "nonLocalReturn",
  331. category: 'accessing',
  332. fn: function () {
  333. var self=this;
  334. return (($receiver = self['@nonLocalReturn']) == nil || $receiver == undefined) ? (function(){return false;})() : $receiver;
  335. return self;},
  336. args: [],
  337. source: "nonLocalReturn\x0a\x09^ nonLocalReturn ifNil: [ false ]",
  338. messageSends: ["ifNil:"],
  339. referencedClasses: []
  340. }),
  341. smalltalk.MethodLexicalScope);
  342. smalltalk.addMethod(
  343. "_nonLocalReturn_",
  344. smalltalk.method({
  345. selector: "nonLocalReturn:",
  346. category: 'accessing',
  347. fn: function (aBoolean) {
  348. var self=this;
  349. (self['@nonLocalReturn']=aBoolean);
  350. return self;},
  351. args: ["aBoolean"],
  352. source: "nonLocalReturn: aBoolean\x0a\x09nonLocalReturn := aBoolean",
  353. messageSends: [],
  354. referencedClasses: []
  355. }),
  356. smalltalk.MethodLexicalScope);
  357. smalltalk.addMethod(
  358. "_unknownVariables",
  359. smalltalk.method({
  360. selector: "unknownVariables",
  361. category: 'accessing',
  362. fn: function () {
  363. var self=this;
  364. return (($receiver = self['@unknownVariables']) == nil || $receiver == undefined) ? (function(){return (self['@unknownVariables']=smalltalk.send((smalltalk.OrderedCollection || OrderedCollection), "_new", []));})() : $receiver;
  365. return self;},
  366. args: [],
  367. source: "unknownVariables\x0a\x09^ unknownVariables ifNil: [ unknownVariables := OrderedCollection new ]",
  368. messageSends: ["ifNil:", "new"],
  369. referencedClasses: ["OrderedCollection"]
  370. }),
  371. smalltalk.MethodLexicalScope);
  372. smalltalk.addClass('ScopeVar', smalltalk.Object, ['scope', 'name'], 'Compiler-Semantic');
  373. smalltalk.ScopeVar.comment="I am an entry in a LexicalScope that gets associated with variable nodes of the same name. \x0aThere are 4 different subclasses of vars: temp vars, local vars, args, and unknown/global vars."
  374. smalltalk.addMethod(
  375. "_alias",
  376. smalltalk.method({
  377. selector: "alias",
  378. category: 'accessing',
  379. fn: function () {
  380. var self=this;
  381. return smalltalk.send(smalltalk.send(self, "_name", []), "_asVariableName", []);
  382. return self;},
  383. args: [],
  384. source: "alias\x0a\x09^ self name asVariableName",
  385. messageSends: ["asVariableName", "name"],
  386. referencedClasses: []
  387. }),
  388. smalltalk.ScopeVar);
  389. smalltalk.addMethod(
  390. "_isArgVar",
  391. smalltalk.method({
  392. selector: "isArgVar",
  393. category: 'testing',
  394. fn: function () {
  395. var self=this;
  396. return false;
  397. return self;},
  398. args: [],
  399. source: "isArgVar\x0a\x09^ false",
  400. messageSends: [],
  401. referencedClasses: []
  402. }),
  403. smalltalk.ScopeVar);
  404. smalltalk.addMethod(
  405. "_isInstanceVar",
  406. smalltalk.method({
  407. selector: "isInstanceVar",
  408. category: 'testing',
  409. fn: function () {
  410. var self=this;
  411. return false;
  412. return self;},
  413. args: [],
  414. source: "isInstanceVar\x0a\x09^ false",
  415. messageSends: [],
  416. referencedClasses: []
  417. }),
  418. smalltalk.ScopeVar);
  419. smalltalk.addMethod(
  420. "_isTempVar",
  421. smalltalk.method({
  422. selector: "isTempVar",
  423. category: 'testing',
  424. fn: function () {
  425. var self=this;
  426. return false;
  427. return self;},
  428. args: [],
  429. source: "isTempVar\x0a\x09^ false",
  430. messageSends: [],
  431. referencedClasses: []
  432. }),
  433. smalltalk.ScopeVar);
  434. smalltalk.addMethod(
  435. "_isUnknownVar",
  436. smalltalk.method({
  437. selector: "isUnknownVar",
  438. category: 'testing',
  439. fn: function () {
  440. var self=this;
  441. return false;
  442. return self;},
  443. args: [],
  444. source: "isUnknownVar\x0a\x09^ false",
  445. messageSends: [],
  446. referencedClasses: []
  447. }),
  448. smalltalk.ScopeVar);
  449. smalltalk.addMethod(
  450. "_name",
  451. smalltalk.method({
  452. selector: "name",
  453. category: 'accessing',
  454. fn: function () {
  455. var self=this;
  456. return self['@name'];
  457. return self;},
  458. args: [],
  459. source: "name\x0a\x09^ name",
  460. messageSends: [],
  461. referencedClasses: []
  462. }),
  463. smalltalk.ScopeVar);
  464. smalltalk.addMethod(
  465. "_name_",
  466. smalltalk.method({
  467. selector: "name:",
  468. category: 'accessing',
  469. fn: function (aString) {
  470. var self=this;
  471. (self['@name']=aString);
  472. return self;},
  473. args: ["aString"],
  474. source: "name: aString\x0a\x09name := aString",
  475. messageSends: [],
  476. referencedClasses: []
  477. }),
  478. smalltalk.ScopeVar);
  479. smalltalk.addMethod(
  480. "_scope",
  481. smalltalk.method({
  482. selector: "scope",
  483. category: 'accessing',
  484. fn: function () {
  485. var self=this;
  486. return self['@scope'];
  487. return self;},
  488. args: [],
  489. source: "scope\x0a\x09^ scope",
  490. messageSends: [],
  491. referencedClasses: []
  492. }),
  493. smalltalk.ScopeVar);
  494. smalltalk.addMethod(
  495. "_scope_",
  496. smalltalk.method({
  497. selector: "scope:",
  498. category: 'accessing',
  499. fn: function (aScope) {
  500. var self=this;
  501. (self['@scope']=aScope);
  502. return self;},
  503. args: ["aScope"],
  504. source: "scope: aScope\x0a\x09scope := aScope",
  505. messageSends: [],
  506. referencedClasses: []
  507. }),
  508. smalltalk.ScopeVar);
  509. smalltalk.addMethod(
  510. "_on_",
  511. smalltalk.method({
  512. selector: "on:",
  513. category: 'instance creation',
  514. fn: function (aString) {
  515. var self=this;
  516. return (function($rec){smalltalk.send($rec, "_name_", [aString]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send(self, "_new", []));
  517. return self;},
  518. args: ["aString"],
  519. source: "on: aString\x0a\x09^ self new \x0a\x09\x09name: aString;\x0a\x09\x09yourself",
  520. messageSends: ["name:", "yourself", "new"],
  521. referencedClasses: []
  522. }),
  523. smalltalk.ScopeVar.klass);
  524. smalltalk.addClass('AliasVar', smalltalk.ScopeVar, ['node'], 'Compiler-Semantic');
  525. smalltalk.AliasVar.comment="I am an internally defined variable by the compiler"
  526. smalltalk.addMethod(
  527. "_node",
  528. smalltalk.method({
  529. selector: "node",
  530. category: 'accessing',
  531. fn: function () {
  532. var self=this;
  533. return self['@node'];
  534. return self;},
  535. args: [],
  536. source: "node\x0a\x09^ node",
  537. messageSends: [],
  538. referencedClasses: []
  539. }),
  540. smalltalk.AliasVar);
  541. smalltalk.addMethod(
  542. "_node_",
  543. smalltalk.method({
  544. selector: "node:",
  545. category: 'accessing',
  546. fn: function (aNode) {
  547. var self=this;
  548. (self['@node']=aNode);
  549. return self;},
  550. args: ["aNode"],
  551. source: "node: aNode\x0a\x09node := aNode",
  552. messageSends: [],
  553. referencedClasses: []
  554. }),
  555. smalltalk.AliasVar);
  556. smalltalk.addClass('ArgVar', smalltalk.ScopeVar, [], 'Compiler-Semantic');
  557. smalltalk.ArgVar.comment="I am an argument of a method or block."
  558. smalltalk.addMethod(
  559. "_isArgVar",
  560. smalltalk.method({
  561. selector: "isArgVar",
  562. category: 'testing',
  563. fn: function () {
  564. var self=this;
  565. return true;
  566. return self;},
  567. args: [],
  568. source: "isArgVar\x0a\x09^ true",
  569. messageSends: [],
  570. referencedClasses: []
  571. }),
  572. smalltalk.ArgVar);
  573. smalltalk.addClass('ClassRefVar', smalltalk.ScopeVar, [], 'Compiler-Semantic');
  574. smalltalk.ClassRefVar.comment="I am an class reference variable"
  575. smalltalk.addMethod(
  576. "_alias",
  577. smalltalk.method({
  578. selector: "alias",
  579. category: 'accessing',
  580. fn: function () {
  581. var self=this;
  582. return smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send("(Smalltalk.", "__comma", [smalltalk.send(self, "_name", [])]), "__comma", [" || "]), "__comma", [smalltalk.send(self, "_name", [])]), "__comma", [")"]);
  583. return self;},
  584. args: [],
  585. source: "alias\x0a\x09^ '(Smalltalk.', self name, ' || ', self name, ')'",
  586. messageSends: [",", "name"],
  587. referencedClasses: []
  588. }),
  589. smalltalk.ClassRefVar);
  590. smalltalk.addClass('InstanceVar', smalltalk.ScopeVar, [], 'Compiler-Semantic');
  591. smalltalk.InstanceVar.comment="I am an instance variable of a method or block."
  592. smalltalk.addMethod(
  593. "_alias",
  594. smalltalk.method({
  595. selector: "alias",
  596. category: 'testing',
  597. fn: function () {
  598. var self=this;
  599. return smalltalk.send(smalltalk.send("self[\x22@", "__comma", [smalltalk.send(self, "_name", [])]), "__comma", ["]"]);
  600. return self;},
  601. args: [],
  602. source: "alias\x0a\x09^ 'self[\x22@', self name, ']'",
  603. messageSends: [",", "name"],
  604. referencedClasses: []
  605. }),
  606. smalltalk.InstanceVar);
  607. smalltalk.addMethod(
  608. "_isInstanceVar",
  609. smalltalk.method({
  610. selector: "isInstanceVar",
  611. category: 'testing',
  612. fn: function () {
  613. var self=this;
  614. return true;
  615. return self;},
  616. args: [],
  617. source: "isInstanceVar\x0a\x09^ true",
  618. messageSends: [],
  619. referencedClasses: []
  620. }),
  621. smalltalk.InstanceVar);
  622. smalltalk.addClass('TempVar', smalltalk.ScopeVar, [], 'Compiler-Semantic');
  623. smalltalk.TempVar.comment="I am an temporary variable of a method or block."
  624. smalltalk.addMethod(
  625. "_isTempVar",
  626. smalltalk.method({
  627. selector: "isTempVar",
  628. category: 'testing',
  629. fn: function () {
  630. var self=this;
  631. return true;
  632. return self;},
  633. args: [],
  634. source: "isTempVar\x0a\x09^ true",
  635. messageSends: [],
  636. referencedClasses: []
  637. }),
  638. smalltalk.TempVar);
  639. smalltalk.addClass('UnknownVar', smalltalk.ScopeVar, [], 'Compiler-Semantic');
  640. smalltalk.UnknownVar.comment="I am an unknown variable. Amber uses unknown variables as JavaScript globals"
  641. smalltalk.addMethod(
  642. "_isUnknownVar",
  643. smalltalk.method({
  644. selector: "isUnknownVar",
  645. category: 'testing',
  646. fn: function () {
  647. var self=this;
  648. return true;
  649. return self;},
  650. args: [],
  651. source: "isUnknownVar\x0a\x09^ true",
  652. messageSends: [],
  653. referencedClasses: []
  654. }),
  655. smalltalk.UnknownVar);
  656. smalltalk.addClass('SemanticAnalyzer', smalltalk.NodeVisitor, ['currentScope', 'theClass', 'classReferences', 'messageSends'], 'Compiler-Semantic');
  657. smalltalk.SemanticAnalyzer.comment="I semantically analyze the abstract syntax tree and annotate it with informations such as non local returns and variable scopes."
  658. smalltalk.addMethod(
  659. "_allowUnknownVariables",
  660. smalltalk.method({
  661. selector: "allowUnknownVariables",
  662. category: 'testing',
  663. fn: function () {
  664. var self=this;
  665. return true;
  666. return self;},
  667. args: [],
  668. source: "allowUnknownVariables\x0a\x09^ true",
  669. messageSends: [],
  670. referencedClasses: []
  671. }),
  672. smalltalk.SemanticAnalyzer);
  673. smalltalk.addMethod(
  674. "_classReferences",
  675. smalltalk.method({
  676. selector: "classReferences",
  677. category: 'accessing',
  678. fn: function () {
  679. var self=this;
  680. return (($receiver = self['@classReferences']) == nil || $receiver == undefined) ? (function(){return (self['@classReferences']=smalltalk.send((smalltalk.Set || Set), "_new", []));})() : $receiver;
  681. return self;},
  682. args: [],
  683. source: "classReferences\x0a\x09^ classReferences ifNil: [ classReferences := Set new ]",
  684. messageSends: ["ifNil:", "new"],
  685. referencedClasses: ["Set"]
  686. }),
  687. smalltalk.SemanticAnalyzer);
  688. smalltalk.addMethod(
  689. "_errorInvalidAssignment_",
  690. smalltalk.method({
  691. selector: "errorInvalidAssignment:",
  692. category: 'error handling',
  693. fn: function (aString) {
  694. var self=this;
  695. (function($rec){smalltalk.send($rec, "_variableName_", [aString]);return smalltalk.send($rec, "_signal", []);})(smalltalk.send((smalltalk.InvalidAssignmentError || InvalidAssignmentError), "_new", []));
  696. return self;},
  697. args: ["aString"],
  698. source: "errorInvalidAssignment: aString\x0a\x09InvalidAssignmentError new\x0a\x09\x09variableName: aString;\x0a\x09\x09signal",
  699. messageSends: ["variableName:", "signal", "new"],
  700. referencedClasses: ["InvalidAssignmentError"]
  701. }),
  702. smalltalk.SemanticAnalyzer);
  703. smalltalk.addMethod(
  704. "_errorShadowingVariable_",
  705. smalltalk.method({
  706. selector: "errorShadowingVariable:",
  707. category: 'error handling',
  708. fn: function (aString) {
  709. var self=this;
  710. (function($rec){smalltalk.send($rec, "_variableName_", [aString]);return smalltalk.send($rec, "_signal", []);})(smalltalk.send((smalltalk.ShadowingVariableError || ShadowingVariableError), "_new", []));
  711. return self;},
  712. args: ["aString"],
  713. source: "errorShadowingVariable: aString\x0a\x09ShadowingVariableError new\x0a\x09\x09variableName: aString;\x0a\x09\x09signal",
  714. messageSends: ["variableName:", "signal", "new"],
  715. referencedClasses: ["ShadowingVariableError"]
  716. }),
  717. smalltalk.SemanticAnalyzer);
  718. smalltalk.addMethod(
  719. "_errorUnknownVariable_",
  720. smalltalk.method({
  721. selector: "errorUnknownVariable:",
  722. category: 'error handling',
  723. fn: function (aNode) {
  724. var self=this;
  725. ((($receiver = smalltalk.send(self, "_allowUnknownVariables", [])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return smalltalk.send(smalltalk.send(smalltalk.send(self['@currentScope'], "_methodScope", []), "_unknownVariables", []), "_add_", [smalltalk.send(aNode, "_value", [])]);})() : (function(){return (function($rec){smalltalk.send($rec, "_variableName_", [smalltalk.send(aNode, "_value", [])]);return smalltalk.send($rec, "_signal", []);})(smalltalk.send((smalltalk.UnknownVariableError || UnknownVariableError), "_new", []));})()) : smalltalk.send($receiver, "_ifTrue_ifFalse_", [(function(){return smalltalk.send(smalltalk.send(smalltalk.send(self['@currentScope'], "_methodScope", []), "_unknownVariables", []), "_add_", [smalltalk.send(aNode, "_value", [])]);}), (function(){return (function($rec){smalltalk.send($rec, "_variableName_", [smalltalk.send(aNode, "_value", [])]);return smalltalk.send($rec, "_signal", []);})(smalltalk.send((smalltalk.UnknownVariableError || UnknownVariableError), "_new", []));})]));
  726. return self;},
  727. args: ["aNode"],
  728. source: "errorUnknownVariable: aNode\x0a\x09self allowUnknownVariables \x0a\x09\x09ifTrue: [ currentScope methodScope unknownVariables add: aNode value ]\x0a\x09\x09ifFalse: [ \x0a\x09\x09\x09UnknownVariableError new\x0a\x09\x09\x09\x09variableName: aNode value;\x0a\x09\x09\x09\x09signal ]",
  729. messageSends: ["ifTrue:ifFalse:", "allowUnknownVariables", "add:", "unknownVariables", "methodScope", "value", "variableName:", "signal", "new"],
  730. referencedClasses: ["UnknownVariableError"]
  731. }),
  732. smalltalk.SemanticAnalyzer);
  733. smalltalk.addMethod(
  734. "_messageSends",
  735. smalltalk.method({
  736. selector: "messageSends",
  737. category: 'accessing',
  738. fn: function () {
  739. var self=this;
  740. return (($receiver = self['@messageSends']) == nil || $receiver == undefined) ? (function(){return (self['@messageSends']=smalltalk.send((smalltalk.Set || Set), "_new", []));})() : $receiver;
  741. return self;},
  742. args: [],
  743. source: "messageSends\x0a\x09^ messageSends ifNil: [ messageSends := Set new ]",
  744. messageSends: ["ifNil:", "new"],
  745. referencedClasses: ["Set"]
  746. }),
  747. smalltalk.SemanticAnalyzer);
  748. smalltalk.addMethod(
  749. "_newBlockScope",
  750. smalltalk.method({
  751. selector: "newBlockScope",
  752. category: 'factory',
  753. fn: function () {
  754. var self=this;
  755. return smalltalk.send(self, "_newScopeOfClass_", [(smalltalk.LexicalScope || LexicalScope)]);
  756. return self;},
  757. args: [],
  758. source: "newBlockScope\x0a\x09^ self newScopeOfClass: LexicalScope",
  759. messageSends: ["newScopeOfClass:"],
  760. referencedClasses: ["LexicalScope"]
  761. }),
  762. smalltalk.SemanticAnalyzer);
  763. smalltalk.addMethod(
  764. "_newMethodScope",
  765. smalltalk.method({
  766. selector: "newMethodScope",
  767. category: 'factory',
  768. fn: function () {
  769. var self=this;
  770. return smalltalk.send(self, "_newScopeOfClass_", [(smalltalk.MethodLexicalScope || MethodLexicalScope)]);
  771. return self;},
  772. args: [],
  773. source: "newMethodScope\x0a\x09^ self newScopeOfClass: MethodLexicalScope",
  774. messageSends: ["newScopeOfClass:"],
  775. referencedClasses: ["MethodLexicalScope"]
  776. }),
  777. smalltalk.SemanticAnalyzer);
  778. smalltalk.addMethod(
  779. "_newScopeOfClass_",
  780. smalltalk.method({
  781. selector: "newScopeOfClass:",
  782. category: 'factory',
  783. fn: function (aLexicalScopeClass) {
  784. var self=this;
  785. return (function($rec){smalltalk.send($rec, "_outerScope_", [self['@currentScope']]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send(aLexicalScopeClass, "_new", []));
  786. return self;},
  787. args: ["aLexicalScopeClass"],
  788. source: "newScopeOfClass: aLexicalScopeClass\x0a\x09^ aLexicalScopeClass new \x0a\x09\x09outerScope: currentScope;\x0a\x09\x09yourself",
  789. messageSends: ["outerScope:", "yourself", "new"],
  790. referencedClasses: []
  791. }),
  792. smalltalk.SemanticAnalyzer);
  793. smalltalk.addMethod(
  794. "_popScope",
  795. smalltalk.method({
  796. selector: "popScope",
  797. category: 'scope',
  798. fn: function () {
  799. var self=this;
  800. (($receiver = self['@currentScope']) != nil && $receiver != undefined) ? (function(){return (self['@currentScope']=smalltalk.send(self['@currentScope'], "_outerScope", []));})() : nil;
  801. return self;},
  802. args: [],
  803. source: "popScope\x0a\x09currentScope ifNotNil: [\x0a\x09\x09currentScope := currentScope outerScope ]",
  804. messageSends: ["ifNotNil:", "outerScope"],
  805. referencedClasses: []
  806. }),
  807. smalltalk.SemanticAnalyzer);
  808. smalltalk.addMethod(
  809. "_pseudoVariables",
  810. smalltalk.method({
  811. selector: "pseudoVariables",
  812. category: 'accessing',
  813. fn: function () {
  814. var self=this;
  815. return ["self", "super", "true", "false", "nil", "thisContext"];
  816. return self;},
  817. args: [],
  818. source: "pseudoVariables\x0a\x09^#('self' 'super' 'true' 'false' 'nil' 'thisContext')",
  819. messageSends: [],
  820. referencedClasses: []
  821. }),
  822. smalltalk.SemanticAnalyzer);
  823. smalltalk.addMethod(
  824. "_pushScope_",
  825. smalltalk.method({
  826. selector: "pushScope:",
  827. category: 'scope',
  828. fn: function (aScope) {
  829. var self=this;
  830. smalltalk.send(aScope, "_outerScope_", [self['@currentScope']]);
  831. (self['@currentScope']=aScope);
  832. return self;},
  833. args: ["aScope"],
  834. source: "pushScope: aScope\x0a\x09aScope outerScope: currentScope.\x0a\x09currentScope := aScope",
  835. messageSends: ["outerScope:"],
  836. referencedClasses: []
  837. }),
  838. smalltalk.SemanticAnalyzer);
  839. smalltalk.addMethod(
  840. "_theClass",
  841. smalltalk.method({
  842. selector: "theClass",
  843. category: 'accessing',
  844. fn: function () {
  845. var self=this;
  846. return self['@theClass'];
  847. return self;},
  848. args: [],
  849. source: "theClass\x0a\x09^ theClass",
  850. messageSends: [],
  851. referencedClasses: []
  852. }),
  853. smalltalk.SemanticAnalyzer);
  854. smalltalk.addMethod(
  855. "_theClass_",
  856. smalltalk.method({
  857. selector: "theClass:",
  858. category: 'accessing',
  859. fn: function (aClass) {
  860. var self=this;
  861. (self['@theClass']=aClass);
  862. return self;},
  863. args: ["aClass"],
  864. source: "theClass: aClass\x0a\x09theClass := aClass",
  865. messageSends: [],
  866. referencedClasses: []
  867. }),
  868. smalltalk.SemanticAnalyzer);
  869. smalltalk.addMethod(
  870. "_validateVariableScope_",
  871. smalltalk.method({
  872. selector: "validateVariableScope:",
  873. category: 'scope',
  874. fn: function (aString) {
  875. var self=this;
  876. (($receiver = smalltalk.send(self['@currentScope'], "_lookupVariable_", [aString])) != nil && $receiver != undefined) ? (function(){return smalltalk.send(self, "_errorShadowingVariable_", [aString]);})() : nil;
  877. return self;},
  878. args: ["aString"],
  879. source: "validateVariableScope: aString\x0a\x09\x22Validate the variable scope in by doing a recursive lookup, up to the method scope\x22\x0a\x0a\x09(currentScope lookupVariable: aString) ifNotNil: [\x0a\x09\x09self errorShadowingVariable: aString ]",
  880. messageSends: ["ifNotNil:", "lookupVariable:", "errorShadowingVariable:"],
  881. referencedClasses: []
  882. }),
  883. smalltalk.SemanticAnalyzer);
  884. smalltalk.addMethod(
  885. "_visitAssignmentNode_",
  886. smalltalk.method({
  887. selector: "visitAssignmentNode:",
  888. category: 'visiting',
  889. fn: function (aNode) {
  890. var self=this;
  891. smalltalk.send(self, "_visitAssignmentNode_", [aNode], smalltalk.SemanticAnalyzer.superclass || nil);
  892. ((($receiver = smalltalk.send(smalltalk.send(self, "_pseudoVariables", []), "_includes_", [smalltalk.send(smalltalk.send(aNode, "_left", []), "_value", [])])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return smalltalk.send(self, "_errorInvalidAssignment_", [smalltalk.send(smalltalk.send(aNode, "_left", []), "_value", [])]);})() : nil) : smalltalk.send($receiver, "_ifTrue_", [(function(){return smalltalk.send(self, "_errorInvalidAssignment_", [smalltalk.send(smalltalk.send(aNode, "_left", []), "_value", [])]);})]));
  893. ((($receiver = smalltalk.send(smalltalk.send(smalltalk.send(aNode, "_left", []), "_binding", []), "_isArgVar", [])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return smalltalk.send(self, "_errorInvalidAssignment_", [smalltalk.send(smalltalk.send(aNode, "_left", []), "_value", [])]);})() : nil) : smalltalk.send($receiver, "_ifTrue_", [(function(){return smalltalk.send(self, "_errorInvalidAssignment_", [smalltalk.send(smalltalk.send(aNode, "_left", []), "_value", [])]);})]));
  894. smalltalk.send(smalltalk.send(aNode, "_left", []), "_beAssigned", []);
  895. smalltalk.send(smalltalk.send(aNode, "_right", []), "_beUsed", []);
  896. return self;},
  897. args: ["aNode"],
  898. source: "visitAssignmentNode: aNode\x0a\x09super visitAssignmentNode: aNode.\x0a\x09(self pseudoVariables includes: aNode left value) ifTrue: [\x0a\x09\x09self errorInvalidAssignment: aNode left value ].\x0a\x09aNode left binding isArgVar ifTrue: [\x0a\x09\x09self errorInvalidAssignment: aNode left value ].\x0a\x09aNode left beAssigned.\x0a\x09aNode right beUsed.",
  899. messageSends: ["visitAssignmentNode:", "ifTrue:", "includes:", "pseudoVariables", "value", "left", "errorInvalidAssignment:", "isArgVar", "binding", "beAssigned", "beUsed", "right"],
  900. referencedClasses: []
  901. }),
  902. smalltalk.SemanticAnalyzer);
  903. smalltalk.addMethod(
  904. "_visitBlockNode_",
  905. smalltalk.method({
  906. selector: "visitBlockNode:",
  907. category: 'visiting',
  908. fn: function (aNode) {
  909. var self=this;
  910. smalltalk.send(self, "_pushScope_", [smalltalk.send(self, "_newBlockScope", [])]);
  911. smalltalk.send(aNode, "_scope_", [self['@currentScope']]);
  912. smalltalk.send(smalltalk.send(aNode, "_parameters", []), "_do_", [(function(each){smalltalk.send(self, "_validateVariableScope_", [each]);return smalltalk.send(self['@currentScope'], "_addArg_", [each]);})]);
  913. smalltalk.send(self, "_visitBlockNode_", [aNode], smalltalk.SemanticAnalyzer.superclass || nil);
  914. smalltalk.send(self, "_popScope", []);
  915. return self;},
  916. args: ["aNode"],
  917. source: "visitBlockNode: aNode\x0a\x09self pushScope: self newBlockScope.\x0a\x09aNode scope: currentScope.\x0a\x09\x0a\x09aNode parameters do: [ :each | \x0a\x09\x09self validateVariableScope: each.\x0a\x09\x09currentScope addArg: each ].\x0a\x0a\x09super visitBlockNode: aNode.\x0a\x09self popScope",
  918. messageSends: ["pushScope:", "newBlockScope", "scope:", "do:", "parameters", "validateVariableScope:", "addArg:", "visitBlockNode:", "popScope"],
  919. referencedClasses: []
  920. }),
  921. smalltalk.SemanticAnalyzer);
  922. smalltalk.addMethod(
  923. "_visitCascadeNode_",
  924. smalltalk.method({
  925. selector: "visitCascadeNode:",
  926. category: 'visiting',
  927. fn: function (aNode) {
  928. var self=this;
  929. smalltalk.send(smalltalk.send(aNode, "_nodes", []), "_do_", [(function(each){return smalltalk.send(each, "_receiver_", [smalltalk.send(aNode, "_receiver", [])]);})]);
  930. smalltalk.send(self, "_visitCascadeNode_", [aNode], smalltalk.SemanticAnalyzer.superclass || nil);
  931. return self;},
  932. args: ["aNode"],
  933. source: "visitCascadeNode: aNode\x0a\x09\x22Populate the receiver into all children\x22\x0a\x09aNode nodes do: [ :each | each receiver: aNode receiver ].\x0a\x09super visitCascadeNode: aNode",
  934. messageSends: ["do:", "nodes", "receiver:", "receiver", "visitCascadeNode:"],
  935. referencedClasses: []
  936. }),
  937. smalltalk.SemanticAnalyzer);
  938. smalltalk.addMethod(
  939. "_visitClassReferenceNode_",
  940. smalltalk.method({
  941. selector: "visitClassReferenceNode:",
  942. category: 'visiting',
  943. fn: function (aNode) {
  944. var self=this;
  945. smalltalk.send(smalltalk.send(self, "_classReferences", []), "_add_", [smalltalk.send(aNode, "_value", [])]);
  946. smalltalk.send(aNode, "_binding_", [(function($rec){smalltalk.send($rec, "_name_", [smalltalk.send(aNode, "_value", [])]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send((smalltalk.ClassRefVar || ClassRefVar), "_new", []))]);
  947. return self;},
  948. args: ["aNode"],
  949. source: "visitClassReferenceNode: aNode\x0a\x09self classReferences add: aNode value.\x0a\x09aNode binding: (ClassRefVar new name: aNode value; yourself)",
  950. messageSends: ["add:", "classReferences", "value", "binding:", "name:", "yourself", "new"],
  951. referencedClasses: ["ClassRefVar"]
  952. }),
  953. smalltalk.SemanticAnalyzer);
  954. smalltalk.addMethod(
  955. "_visitMethodNode_",
  956. smalltalk.method({
  957. selector: "visitMethodNode:",
  958. category: 'visiting',
  959. fn: function (aNode) {
  960. var self=this;
  961. smalltalk.send(self, "_pushScope_", [smalltalk.send(self, "_newMethodScope", [])]);
  962. smalltalk.send(aNode, "_scope_", [self['@currentScope']]);
  963. smalltalk.send(smalltalk.send(smalltalk.send(self, "_theClass", []), "_allInstanceVariableNames", []), "_do_", [(function(each){return smalltalk.send(self['@currentScope'], "_addIVar_", [each]);})]);
  964. smalltalk.send(smalltalk.send(aNode, "_arguments", []), "_do_", [(function(each){smalltalk.send(self, "_validateVariableScope_", [each]);return smalltalk.send(self['@currentScope'], "_addArg_", [each]);})]);
  965. smalltalk.send(self, "_visitMethodNode_", [aNode], smalltalk.SemanticAnalyzer.superclass || nil);
  966. (function($rec){smalltalk.send($rec, "_classReferences_", [smalltalk.send(self, "_classReferences", [])]);return smalltalk.send($rec, "_messageSends_", [smalltalk.send(self, "_messageSends", [])]);})(aNode);
  967. smalltalk.send(self, "_popScope", []);
  968. return self;},
  969. args: ["aNode"],
  970. source: "visitMethodNode: aNode\x0a\x09self pushScope: self newMethodScope.\x0a\x09aNode scope: currentScope.\x0a\x0a\x09self theClass allInstanceVariableNames do: [:each | \x0a\x09\x09currentScope addIVar: each ].\x0a\x09aNode arguments do: [ :each | \x0a\x09\x09self validateVariableScope: each.\x0a\x09\x09currentScope addArg: each ].\x0a\x0a\x09super visitMethodNode: aNode.\x0a\x0a\x09aNode \x0a\x09\x09classReferences: self classReferences;\x0a\x09\x09messageSends: self messageSends.\x0a\x09self popScope",
  971. messageSends: ["pushScope:", "newMethodScope", "scope:", "do:", "allInstanceVariableNames", "theClass", "addIVar:", "arguments", "validateVariableScope:", "addArg:", "visitMethodNode:", "classReferences:", "classReferences", "messageSends:", "messageSends", "popScope"],
  972. referencedClasses: []
  973. }),
  974. smalltalk.SemanticAnalyzer);
  975. smalltalk.addMethod(
  976. "_visitReturnNode_",
  977. smalltalk.method({
  978. selector: "visitReturnNode:",
  979. category: 'visiting',
  980. fn: function (aNode) {
  981. var self=this;
  982. ((($receiver = smalltalk.send(self['@currentScope'], "_isMethodScope", [])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){smalltalk.send(smalltalk.send(self['@currentScope'], "_methodScope", []), "_nonLocalReturn_", [true]);return smalltalk.send(aNode, "_nonLocalReturn_", [true]);})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){smalltalk.send(smalltalk.send(self['@currentScope'], "_methodScope", []), "_nonLocalReturn_", [true]);return smalltalk.send(aNode, "_nonLocalReturn_", [true]);})]));
  983. smalltalk.send(smalltalk.send(smalltalk.send(aNode, "_nodes", []), "_first", []), "_beUsed", []);
  984. smalltalk.send(self, "_visitReturnNode_", [aNode], smalltalk.SemanticAnalyzer.superclass || nil);
  985. return self;},
  986. args: ["aNode"],
  987. source: "visitReturnNode: aNode\x0a\x09currentScope isMethodScope ifFalse: [\x0a\x09\x09currentScope methodScope nonLocalReturn: true.\x0a\x09\x09aNode nonLocalReturn: true ].\x0a\x09aNode nodes first beUsed.\x0a\x09super visitReturnNode: aNode",
  988. messageSends: ["ifFalse:", "isMethodScope", "nonLocalReturn:", "methodScope", "beUsed", "first", "nodes", "visitReturnNode:"],
  989. referencedClasses: []
  990. }),
  991. smalltalk.SemanticAnalyzer);
  992. smalltalk.addMethod(
  993. "_visitSendNode_",
  994. smalltalk.method({
  995. selector: "visitSendNode:",
  996. category: 'visiting',
  997. fn: function (aNode) {
  998. var self=this;
  999. ((($receiver = smalltalk.send(smalltalk.send(smalltalk.send(aNode, "_receiver", []), "_value", []), "__eq", ["super"])).klass === smalltalk.Boolean) ? ($receiver ? (function(){smalltalk.send(aNode, "_superSend_", [true]);return smalltalk.send(smalltalk.send(aNode, "_receiver", []), "_value_", ["self"]);})() : nil) : smalltalk.send($receiver, "_ifTrue_", [(function(){smalltalk.send(aNode, "_superSend_", [true]);return smalltalk.send(smalltalk.send(aNode, "_receiver", []), "_value_", ["self"]);})]));
  1000. smalltalk.send(smalltalk.send(self, "_messageSends", []), "_add_", [smalltalk.send(aNode, "_selector", [])]);
  1001. (($receiver = smalltalk.send(aNode, "_receiver", [])) != nil && $receiver != undefined) ? (function(){return smalltalk.send(smalltalk.send(aNode, "_receiver", []), "_beUsed", []);})() : nil;
  1002. smalltalk.send(smalltalk.send(aNode, "_arguments", []), "_do_", [(function(each){return smalltalk.send(each, "_beUsed", []);})]);
  1003. smalltalk.send(self, "_visitSendNode_", [aNode], smalltalk.SemanticAnalyzer.superclass || nil);
  1004. return self;},
  1005. args: ["aNode"],
  1006. source: "visitSendNode: aNode\x0a\x0a\x09aNode receiver value = 'super' ifTrue: [\x0a\x09\x09aNode superSend: true.\x0a\x09\x09aNode receiver value: 'self'].\x0a\x0a\x09self messageSends add: aNode selector.\x0a\x09aNode receiver ifNotNil: [\x0a\x09\x09aNode receiver beUsed ].\x0a\x09aNode arguments do: [ :each |\x0a\x09\x09each beUsed ].\x0a\x09super visitSendNode: aNode",
  1007. messageSends: ["ifTrue:", "=", "value", "receiver", "superSend:", "value:", "add:", "messageSends", "selector", "ifNotNil:", "beUsed", "do:", "arguments", "visitSendNode:"],
  1008. referencedClasses: []
  1009. }),
  1010. smalltalk.SemanticAnalyzer);
  1011. smalltalk.addMethod(
  1012. "_visitSequenceNode_",
  1013. smalltalk.method({
  1014. selector: "visitSequenceNode:",
  1015. category: 'visiting',
  1016. fn: function (aNode) {
  1017. var self=this;
  1018. smalltalk.send(smalltalk.send(aNode, "_temps", []), "_do_", [(function(each){smalltalk.send(self, "_validateVariableScope_", [each]);return smalltalk.send(self['@currentScope'], "_addTemp_", [each]);})]);
  1019. smalltalk.send(self, "_visitSequenceNode_", [aNode], smalltalk.SemanticAnalyzer.superclass || nil);
  1020. return self;},
  1021. args: ["aNode"],
  1022. source: "visitSequenceNode: aNode\x0a\x09aNode temps do: [ :each | \x0a\x09\x09self validateVariableScope: each.\x0a\x09\x09currentScope addTemp: each ].\x0a\x0a\x09super visitSequenceNode: aNode",
  1023. messageSends: ["do:", "temps", "validateVariableScope:", "addTemp:", "visitSequenceNode:"],
  1024. referencedClasses: []
  1025. }),
  1026. smalltalk.SemanticAnalyzer);
  1027. smalltalk.addMethod(
  1028. "_visitVariableNode_",
  1029. smalltalk.method({
  1030. selector: "visitVariableNode:",
  1031. category: 'visiting',
  1032. fn: function (aNode) {
  1033. var self=this;
  1034. smalltalk.send(aNode, "_binding_", [(($receiver = smalltalk.send(self['@currentScope'], "_lookupVariable_", [aNode])) == nil || $receiver == undefined) ? (function(){smalltalk.send(self, "_errorUnknownVariable_", [aNode]);return (function($rec){smalltalk.send($rec, "_name_", [smalltalk.send(aNode, "_value", [])]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send((smalltalk.UnknownVar || UnknownVar), "_new", []));})() : $receiver]);
  1035. return self;},
  1036. args: ["aNode"],
  1037. source: "visitVariableNode: aNode\x0a\x09\x22Bind a ScopeVar to aNode by doing a lookup in the current scope.\x0a\x09If no ScopeVar is found, bind a UnknowVar and throw an error\x22\x0a\x0a\x09aNode binding: ((currentScope lookupVariable: aNode) ifNil: [ \x0a\x09\x09self errorUnknownVariable: aNode.\x0a\x09\x09UnknownVar new name: aNode value; yourself ])",
  1038. messageSends: ["binding:", "ifNil:", "lookupVariable:", "errorUnknownVariable:", "name:", "value", "yourself", "new"],
  1039. referencedClasses: ["UnknownVar"]
  1040. }),
  1041. smalltalk.SemanticAnalyzer);
  1042. smalltalk.addMethod(
  1043. "_on_",
  1044. smalltalk.method({
  1045. selector: "on:",
  1046. category: 'instance creation',
  1047. fn: function (aClass) {
  1048. var self=this;
  1049. return (function($rec){smalltalk.send($rec, "_theClass_", [aClass]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send(self, "_new", []));
  1050. return self;},
  1051. args: ["aClass"],
  1052. source: "on: aClass\x0a\x09^ self new\x0a\x09\x09theClass: aClass;\x0a\x09\x09yourself",
  1053. messageSends: ["theClass:", "yourself", "new"],
  1054. referencedClasses: []
  1055. }),
  1056. smalltalk.SemanticAnalyzer.klass);