Compiler-Tests.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. smalltalk.addPackage('Compiler-Tests', {});
  2. smalltalk.addClass('IRASTTranslatorTest', smalltalk.TestCase, [], 'Compiler-Tests');
  3. smalltalk.addMethod(
  4. "_testIRMethod",
  5. smalltalk.method({
  6. selector: "testIRMethod",
  7. category: 'tests',
  8. fn: function (){
  9. var self=this;
  10. return self;},
  11. args: [],
  12. source: "testIRMethod",
  13. messageSends: [],
  14. referencedClasses: []
  15. }),
  16. smalltalk.IRASTTranslatorTest);
  17. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  18. smalltalk.addMethod(
  19. "_testClassRefVar",
  20. smalltalk.method({
  21. selector: "testClassRefVar",
  22. category: 'tests',
  23. fn: function (){
  24. var self=this;
  25. var node=nil;
  26. (node=(function($rec){smalltalk.send($rec, "_value_", ["Object"]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send((smalltalk.ClassReferenceNode || ClassReferenceNode), "_new", [])));
  27. smalltalk.send(smalltalk.send((smalltalk.SemanticAnalyzer || SemanticAnalyzer), "_new", []), "_visit_", [node]);
  28. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(node, "_binding", []), "_isClassRefVar", [])]);
  29. return self;},
  30. args: [],
  31. source: "testClassRefVar\x0a\x09| node |\x0a\x09node := ClassReferenceNode new\x0a\x09\x09value: 'Object';\x0a\x09\x09yourself.\x0a\x09SemanticAnalyzer new visit: node.\x0a\x09self assert: node binding isClassRefVar",
  32. messageSends: ["value:", "yourself", "new", "visit:", "assert:", "isClassRefVar", "binding"],
  33. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  34. }),
  35. smalltalk.ScopeVarTest);
  36. smalltalk.addMethod(
  37. "_testInstanceVar",
  38. smalltalk.method({
  39. selector: "testInstanceVar",
  40. category: 'tests',
  41. fn: function (){
  42. var self=this;
  43. var node=nil;
  44. var scope=nil;
  45. (node=(function($rec){smalltalk.send($rec, "_value_", ["bzzz"]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send((smalltalk.VariableNode || VariableNode), "_new", [])));
  46. (scope=smalltalk.send((smalltalk.MethodLexicalScope || MethodLexicalScope), "_new", []));
  47. smalltalk.send(scope, "_addIVar_", ["bzzz"]);
  48. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(scope, "_bindingFor_", [node]), "_isInstanceVar", [])]);
  49. return self;},
  50. args: [],
  51. source: "testInstanceVar\x0a\x09| node scope |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09scope := MethodLexicalScope new.\x0a\x09scope addIVar: 'bzzz'.\x0a\x09self assert: (scope bindingFor: node) isInstanceVar",
  52. messageSends: ["value:", "yourself", "new", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  53. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  54. }),
  55. smalltalk.ScopeVarTest);
  56. smalltalk.addMethod(
  57. "_testPseudoVar",
  58. smalltalk.method({
  59. selector: "testPseudoVar",
  60. category: 'tests',
  61. fn: function (){
  62. var self=this;
  63. var node=nil;
  64. var pseudoVars=nil;
  65. (pseudoVars=["self", "super", "true", "false", "nil"]);
  66. smalltalk.send(pseudoVars, "_do_", [(function(each){(node=(function($rec){smalltalk.send($rec, "_value_", [each]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send((smalltalk.VariableNode || VariableNode), "_new", [])));return smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.MethodLexicalScope || MethodLexicalScope), "_new", []), "_bindingFor_", [node]), "_isPseudoVar", [])]);})]);
  67. return self;},
  68. args: [],
  69. source: "testPseudoVar\x0a\x09| node pseudoVars |\x0a\x09pseudoVars := #('self' 'super' 'true' 'false' 'nil').\x0a\x09pseudoVars do: [:each |\x0a\x09\x09node := VariableNode new\x0a\x09\x09value: each;\x0a\x09\x09yourself.\x0a\x09\x09self assert: (MethodLexicalScope new bindingFor: node) isPseudoVar ]",
  70. messageSends: ["do:", "value:", "yourself", "new", "assert:", "isPseudoVar", "bindingFor:"],
  71. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  72. }),
  73. smalltalk.ScopeVarTest);
  74. smalltalk.addMethod(
  75. "_testTempVar",
  76. smalltalk.method({
  77. selector: "testTempVar",
  78. category: 'tests',
  79. fn: function (){
  80. var self=this;
  81. var node=nil;
  82. var scope=nil;
  83. (node=(function($rec){smalltalk.send($rec, "_value_", ["bzzz"]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send((smalltalk.VariableNode || VariableNode), "_new", [])));
  84. (scope=smalltalk.send((smalltalk.MethodLexicalScope || MethodLexicalScope), "_new", []));
  85. smalltalk.send(scope, "_addTemp_", ["bzzz"]);
  86. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(scope, "_bindingFor_", [node]), "_isTempVar", [])]);
  87. return self;},
  88. args: [],
  89. source: "testTempVar\x0a\x09| node scope |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09scope := MethodLexicalScope new.\x0a\x09scope addTemp: 'bzzz'.\x0a\x09self assert: (scope bindingFor: node) isTempVar",
  90. messageSends: ["value:", "yourself", "new", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  91. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  92. }),
  93. smalltalk.ScopeVarTest);
  94. smalltalk.addMethod(
  95. "_testUnknownVar",
  96. smalltalk.method({
  97. selector: "testUnknownVar",
  98. category: 'tests',
  99. fn: function (){
  100. var self=this;
  101. var node=nil;
  102. (node=(function($rec){smalltalk.send($rec, "_value_", ["bzzz"]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send((smalltalk.VariableNode || VariableNode), "_new", [])));
  103. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.MethodLexicalScope || MethodLexicalScope), "_new", []), "_bindingFor_", [node]), "_isNil", [])]);
  104. return self;},
  105. args: [],
  106. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  107. messageSends: ["value:", "yourself", "new", "assert:", "isNil", "bindingFor:"],
  108. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  109. }),
  110. smalltalk.ScopeVarTest);
  111. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  112. smalltalk.addMethod(
  113. "_setUp",
  114. smalltalk.method({
  115. selector: "setUp",
  116. category: 'running',
  117. fn: function () {
  118. var self=this;
  119. (self['@analyzer']=smalltalk.send((smalltalk.SemanticAnalyzer || SemanticAnalyzer), "_on_", [(smalltalk.Object || Object)]));
  120. return self;},
  121. args: [],
  122. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  123. messageSends: ["on:"],
  124. referencedClasses: ["SemanticAnalyzer", "Object"]
  125. }),
  126. smalltalk.SemanticAnalyzerTest);
  127. smalltalk.addMethod(
  128. "_testAssignment",
  129. smalltalk.method({
  130. selector: "testAssignment",
  131. category: 'tests',
  132. fn: function () {
  133. var self=this;
  134. var src=nil;
  135. var ast=nil;
  136. (src="foo self := 1");
  137. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  138. smalltalk.send(self, "_should_raise_", [(function(){return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}), (smalltalk.InvalidAssignmentError || InvalidAssignmentError)]);
  139. return self;},
  140. args: [],
  141. source: "testAssignment\x0a\x09| src ast |\x0a\x0a\x09src := 'foo self := 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09self should: [analyzer visit: ast] raise: InvalidAssignmentError",
  142. messageSends: ["parse:", "should:raise:", "visit:"],
  143. referencedClasses: ["InvalidAssignmentError"]
  144. }),
  145. smalltalk.SemanticAnalyzerTest);
  146. smalltalk.addMethod(
  147. "_testNonLocalReturn",
  148. smalltalk.method({
  149. selector: "testNonLocalReturn",
  150. category: 'tests',
  151. fn: function (){
  152. var self=this;
  153. var src=nil;
  154. var ast=nil;
  155. (src="foo | a | a + 1. ^ a");
  156. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  157. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  158. smalltalk.send(self, "_deny_", [smalltalk.send(smalltalk.send(ast, "_scope", []), "_hasNonLocalReturn", [])]);
  159. return self;},
  160. args: [],
  161. source: "testNonLocalReturn\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. ^ a'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast scope hasNonLocalReturn",
  162. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  163. referencedClasses: []
  164. }),
  165. smalltalk.SemanticAnalyzerTest);
  166. smalltalk.addMethod(
  167. "_testNonLocalReturn2",
  168. smalltalk.method({
  169. selector: "testNonLocalReturn2",
  170. category: 'tests',
  171. fn: function (){
  172. var self=this;
  173. var src=nil;
  174. var ast=nil;
  175. (src="foo | a | a + 1. [ [ ^ a] ]");
  176. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  177. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  178. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(ast, "_scope", []), "_hasNonLocalReturn", [])]);
  179. return self;},
  180. args: [],
  181. source: "testNonLocalReturn2\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ ^ a] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self assert: ast scope hasNonLocalReturn",
  182. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  183. referencedClasses: []
  184. }),
  185. smalltalk.SemanticAnalyzerTest);
  186. smalltalk.addMethod(
  187. "_testScope",
  188. smalltalk.method({
  189. selector: "testScope",
  190. category: 'tests',
  191. fn: function () {
  192. var self=this;
  193. var src=nil;
  194. var ast=nil;
  195. (src="foo | a | a + 1. [ | b | b := a ]");
  196. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  197. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  198. smalltalk.send(self, "_deny_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast, "_nodes", []), "_first", []), "_nodes", []), "_last", []), "_scope", []), "__eq_eq", [smalltalk.send(ast, "_scope", [])])]);
  199. return self;},
  200. args: [],
  201. source: "testScope\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ | b | b := a ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast nodes first nodes last scope == ast scope.",
  202. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  203. referencedClasses: []
  204. }),
  205. smalltalk.SemanticAnalyzerTest);
  206. smalltalk.addMethod(
  207. "_testScope2",
  208. smalltalk.method({
  209. selector: "testScope2",
  210. category: 'tests',
  211. fn: function () {
  212. var self=this;
  213. var src=nil;
  214. var ast=nil;
  215. (src="foo | a | a + 1. [ [ | b | b := a ] ]");
  216. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  217. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  218. smalltalk.send(self, "_deny_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast, "_nodes", []), "_first", []), "_nodes", []), "_last", []), "_nodes", []), "_first", []), "_nodes", []), "_first", []), "_scope", []), "__eq_eq", [smalltalk.send(ast, "_scope", [])])]);
  219. return self;},
  220. args: [],
  221. source: "testScope2\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast nodes first nodes last nodes first nodes first scope == ast scope.",
  222. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  223. referencedClasses: []
  224. }),
  225. smalltalk.SemanticAnalyzerTest);
  226. smalltalk.addMethod(
  227. "_testScopeLevel",
  228. smalltalk.method({
  229. selector: "testScopeLevel",
  230. category: 'tests',
  231. fn: function () {
  232. var self=this;
  233. var src=nil;
  234. var ast=nil;
  235. (src="foo | a | a + 1. [ [ | b | b := a ] ]");
  236. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  237. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  238. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(ast, "_scope", []), "_scopeLevel", []), "__eq", [(1)])]);
  239. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast, "_nodes", []), "_first", []), "_nodes", []), "_last", []), "_nodes", []), "_first", []), "_nodes", []), "_first", []), "_scope", []), "_scopeLevel", []), "__eq", [(3)])]);
  240. return self;},
  241. args: [],
  242. source: "testScopeLevel\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self assert: ast scope scopeLevel = 1.\x0a\x09self assert: ast nodes first nodes last nodes first nodes first scope scopeLevel = 3",
  243. messageSends: ["parse:", "visit:", "assert:", "=", "scopeLevel", "scope", "first", "nodes", "last"],
  244. referencedClasses: []
  245. }),
  246. smalltalk.SemanticAnalyzerTest);
  247. smalltalk.addMethod(
  248. "_testUnknownVariables",
  249. smalltalk.method({
  250. selector: "testUnknownVariables",
  251. category: 'tests',
  252. fn: function () {
  253. var self=this;
  254. var src=nil;
  255. var ast=nil;
  256. (src="foo | a | b + a");
  257. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  258. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  259. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(ast, "_scope", []), "_unknownVariables", []), "__eq", [["b"]])]);
  260. return self;},
  261. args: [],
  262. source: "testUnknownVariables\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | b + a'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self assert: ast scope unknownVariables = #('b')",
  263. messageSends: ["parse:", "visit:", "assert:", "=", "unknownVariables", "scope"],
  264. referencedClasses: []
  265. }),
  266. smalltalk.SemanticAnalyzerTest);
  267. smalltalk.addMethod(
  268. "_testUnknownVariablesWithScope",
  269. smalltalk.method({
  270. selector: "testUnknownVariablesWithScope",
  271. category: 'tests',
  272. fn: function () {
  273. var self=this;
  274. var src=nil;
  275. var ast=nil;
  276. (src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]");
  277. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  278. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  279. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(ast, "_scope", []), "_unknownVariables", []), "__eq", [["c", "d"]])]);
  280. return self;},
  281. args: [],
  282. source: "testUnknownVariablesWithScope\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a b | [ c + 1. [ a + 1. d + 1 ]]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self assert: ast scope unknownVariables = #('c' 'd' )",
  283. messageSends: ["parse:", "visit:", "assert:", "=", "unknownVariables", "scope"],
  284. referencedClasses: []
  285. }),
  286. smalltalk.SemanticAnalyzerTest);
  287. smalltalk.addMethod(
  288. "_testVariableShadowing",
  289. smalltalk.method({
  290. selector: "testVariableShadowing",
  291. category: 'tests',
  292. fn: function () {
  293. var self=this;
  294. var src=nil;
  295. var ast=nil;
  296. (src="foo | a | a + 1");
  297. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  298. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  299. return self;},
  300. args: [],
  301. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  302. messageSends: ["parse:", "visit:"],
  303. referencedClasses: []
  304. }),
  305. smalltalk.SemanticAnalyzerTest);
  306. smalltalk.addMethod(
  307. "_testVariableShadowing2",
  308. smalltalk.method({
  309. selector: "testVariableShadowing2",
  310. category: 'tests',
  311. fn: function () {
  312. var self=this;
  313. var src=nil;
  314. var ast=nil;
  315. (src="foo | a | a + 1. [ | a | a := 2 ]");
  316. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  317. smalltalk.send(self, "_should_raise_", [(function(){return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}), (smalltalk.ShadowingVariableError || ShadowingVariableError)]);
  318. return self;},
  319. args: [],
  320. source: "testVariableShadowing2\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | a | a := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09self should: [analyzer visit: ast] raise: ShadowingVariableError",
  321. messageSends: ["parse:", "should:raise:", "visit:"],
  322. referencedClasses: ["ShadowingVariableError"]
  323. }),
  324. smalltalk.SemanticAnalyzerTest);
  325. smalltalk.addMethod(
  326. "_testVariableShadowing3",
  327. smalltalk.method({
  328. selector: "testVariableShadowing3",
  329. category: 'tests',
  330. fn: function () {
  331. var self=this;
  332. var src=nil;
  333. var ast=nil;
  334. (src="foo | a | a + 1. [ | b | b := 2 ]");
  335. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  336. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  337. return self;},
  338. args: [],
  339. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  340. messageSends: ["parse:", "visit:"],
  341. referencedClasses: []
  342. }),
  343. smalltalk.SemanticAnalyzerTest);
  344. smalltalk.addMethod(
  345. "_testVariableShadowing4",
  346. smalltalk.method({
  347. selector: "testVariableShadowing4",
  348. category: 'tests',
  349. fn: function () {
  350. var self=this;
  351. var src=nil;
  352. var ast=nil;
  353. (src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]");
  354. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  355. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  356. return self;},
  357. args: [],
  358. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  359. messageSends: ["parse:", "visit:"],
  360. referencedClasses: []
  361. }),
  362. smalltalk.SemanticAnalyzerTest);
  363. smalltalk.addMethod(
  364. "_testVariableShadowing5",
  365. smalltalk.method({
  366. selector: "testVariableShadowing5",
  367. category: 'tests',
  368. fn: function () {
  369. var self=this;
  370. var src=nil;
  371. var ast=nil;
  372. (src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]");
  373. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  374. smalltalk.send(self, "_should_raise_", [(function(){return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}), (smalltalk.ShadowingVariableError || ShadowingVariableError)]);
  375. return self;},
  376. args: [],
  377. source: "testVariableShadowing5\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09self should: [analyzer visit: ast] raise: ShadowingVariableError",
  378. messageSends: ["parse:", "should:raise:", "visit:"],
  379. referencedClasses: ["ShadowingVariableError"]
  380. }),
  381. smalltalk.SemanticAnalyzerTest);
  382. smalltalk.addMethod(
  383. "_testVariablesLookup",
  384. smalltalk.method({
  385. selector: "testVariablesLookup",
  386. category: 'tests',
  387. fn: function () {
  388. var self=this;
  389. var src=nil;
  390. var ast=nil;
  391. (src="foo | a | a + 1. [ | b | b := a ]");
  392. (ast=smalltalk.send((typeof smalltalk == 'undefined' ? nil : smalltalk), "_parse_", [src]));
  393. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  394. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast, "_nodes", []), "_first", []), "_nodes", []), "_first", []), "_receiver", []), "_binding", []), "_isTempVar", [])]);
  395. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast, "_nodes", []), "_first", []), "_nodes", []), "_first", []), "_receiver", []), "_binding", []), "_scope", []), "__eq_eq", [smalltalk.send(ast, "_scope", [])])]);
  396. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast, "_nodes", []), "_first", []), "_nodes", []), "_last", []), "_nodes", []), "_first", []), "_nodes", []), "_first", []), "_left", []), "_binding", []), "_isTempVar", [])]);
  397. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast, "_nodes", []), "_first", []), "_nodes", []), "_last", []), "_nodes", []), "_first", []), "_nodes", []), "_first", []), "_left", []), "_binding", []), "_scope", []), "__eq_eq", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast, "_nodes", []), "_first", []), "_nodes", []), "_last", []), "_scope", [])])]);
  398. return self;},
  399. args: [],
  400. source: "testVariablesLookup\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ | b | b := a ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09\x22Binding for `a` in the message send\x22\x0a\x09self assert: ast nodes first nodes first receiver binding isTempVar.\x0a\x09self assert: ast nodes first nodes first receiver binding scope == ast scope.\x0a\x0a\x09\x22Binding for `b`\x22\x0a\x09self assert: ast nodes first nodes last nodes first nodes first left binding isTempVar.\x0a\x09self assert: ast nodes first nodes last nodes first nodes first left binding scope == ast nodes first nodes last scope.",
  401. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  402. referencedClasses: []
  403. }),
  404. smalltalk.SemanticAnalyzerTest);