Compiler-Tests.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. smalltalk.addPackage('Compiler-Tests', {});
  2. smalltalk.addClass('CodeGeneratorTest', smalltalk.TestCase, ['receiver'], 'Compiler-Tests');
  3. smalltalk.addMethod(
  4. "_codeGeneratorClass",
  5. smalltalk.method({
  6. selector: "codeGeneratorClass",
  7. category: 'accessing',
  8. fn: function (){
  9. var self=this;
  10. return smalltalk.withContext(function($ctx) { return (smalltalk.CodeGenerator || CodeGenerator);
  11. }, self, "codeGeneratorClass", [], smalltalk.CodeGeneratorTest)},
  12. args: [],
  13. source: "codeGeneratorClass\x0a\x09^ CodeGenerator",
  14. messageSends: [],
  15. referencedClasses: ["CodeGenerator"]
  16. }),
  17. smalltalk.CodeGeneratorTest);
  18. smalltalk.addMethod(
  19. "_compiler",
  20. smalltalk.method({
  21. selector: "compiler",
  22. category: 'factory',
  23. fn: function (){
  24. var self=this;
  25. return smalltalk.withContext(function($ctx) { var $2,$3,$1;
  26. $2=_st((smalltalk.Compiler || Compiler))._new();
  27. _st($2)._codeGeneratorClass_(_st(self)._codeGeneratorClass());
  28. $3=_st($2)._yourself();
  29. $1=$3;
  30. return $1;
  31. }, self, "compiler", [], smalltalk.CodeGeneratorTest)},
  32. args: [],
  33. source: "compiler\x0a\x09^ Compiler new\x0a\x09\x09codeGeneratorClass: self codeGeneratorClass;\x0a\x09\x09yourself",
  34. messageSends: ["codeGeneratorClass:", "codeGeneratorClass", "new", "yourself"],
  35. referencedClasses: ["Compiler"]
  36. }),
  37. smalltalk.CodeGeneratorTest);
  38. smalltalk.addMethod(
  39. "_setUp",
  40. smalltalk.method({
  41. selector: "setUp",
  42. category: 'initialization',
  43. fn: function (){
  44. var self=this;
  45. return smalltalk.withContext(function($ctx) { self["@receiver"]=_st(_st(self)._targetClass())._new();
  46. return self}, self, "setUp", [], smalltalk.CodeGeneratorTest)},
  47. args: [],
  48. source: "setUp\x0a\x09receiver := self targetClass new",
  49. messageSends: ["new", "targetClass"],
  50. referencedClasses: []
  51. }),
  52. smalltalk.CodeGeneratorTest);
  53. smalltalk.addMethod(
  54. "_should_return_",
  55. smalltalk.method({
  56. selector: "should:return:",
  57. category: 'testing',
  58. fn: function (aString,anObject){
  59. var self=this;
  60. return smalltalk.withContext(function($ctx) { var method;
  61. var result;
  62. method=_st(_st(self)._compiler())._install_forClass_category_(aString,_st(self)._targetClass(),"tests");
  63. result=_st(self["@receiver"])._perform_(_st(method)._selector());
  64. _st(_st(self)._targetClass())._removeCompiledMethod_(method);
  65. _st(self)._assert_equals_(anObject,result);
  66. return self}, self, "should:return:", [aString,anObject], smalltalk.CodeGeneratorTest)},
  67. args: ["aString", "anObject"],
  68. source: "should: aString return: anObject\x0a\x09| method result |\x0a\x0a\x09method := self compiler install: aString forClass: self targetClass category: 'tests'.\x0a\x09result := receiver perform: method selector.\x0a\x09self targetClass removeCompiledMethod: method.\x0a\x09self assert: anObject equals: result",
  69. messageSends: ["install:forClass:category:", "targetClass", "compiler", "perform:", "selector", "removeCompiledMethod:", "assert:equals:"],
  70. referencedClasses: []
  71. }),
  72. smalltalk.CodeGeneratorTest);
  73. smalltalk.addMethod(
  74. "_targetClass",
  75. smalltalk.method({
  76. selector: "targetClass",
  77. category: 'accessing',
  78. fn: function (){
  79. var self=this;
  80. return smalltalk.withContext(function($ctx) { return (smalltalk.DoIt || DoIt);
  81. }, self, "targetClass", [], smalltalk.CodeGeneratorTest)},
  82. args: [],
  83. source: "targetClass\x0a\x09^ DoIt",
  84. messageSends: [],
  85. referencedClasses: ["DoIt"]
  86. }),
  87. smalltalk.CodeGeneratorTest);
  88. smalltalk.addMethod(
  89. "_tearDown",
  90. smalltalk.method({
  91. selector: "tearDown",
  92. category: 'initialization',
  93. fn: function (){
  94. var self=this;
  95. return smalltalk.withContext(function($ctx) { return self}, self, "tearDown", [], smalltalk.CodeGeneratorTest)},
  96. args: [],
  97. source: "tearDown\x0a\x09\x22receiver := nil\x22",
  98. messageSends: [],
  99. referencedClasses: []
  100. }),
  101. smalltalk.CodeGeneratorTest);
  102. smalltalk.addMethod(
  103. "_testAssignment",
  104. smalltalk.method({
  105. selector: "testAssignment",
  106. category: 'tests',
  107. fn: function (){
  108. var self=this;
  109. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo | a | a := true ifTrue: [ 1 ]. ^ a",(1));
  110. _st(self)._should_return_("foo | a | a := false ifTrue: [ 1 ]. ^ a",nil);
  111. _st(self)._should_return_("foo | a | ^ a := true ifTrue: [ 1 ]",(1));
  112. return self}, self, "testAssignment", [], smalltalk.CodeGeneratorTest)},
  113. args: [],
  114. source: "testAssignment\x0a\x09self should: 'foo | a | a := true ifTrue: [ 1 ]. ^ a' return: 1.\x0a\x09self should: 'foo | a | a := false ifTrue: [ 1 ]. ^ a' return: nil.\x0a\x0a\x09self should: 'foo | a | ^ a := true ifTrue: [ 1 ]' return: 1 ",
  115. messageSends: ["should:return:"],
  116. referencedClasses: []
  117. }),
  118. smalltalk.CodeGeneratorTest);
  119. smalltalk.addMethod(
  120. "_testBlockReturn",
  121. smalltalk.method({
  122. selector: "testBlockReturn",
  123. category: 'tests',
  124. fn: function (){
  125. var self=this;
  126. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]",[(2), (3), (4)]);
  127. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]",[(2), (3), (4)]);
  128. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]",[(2), (1), (4)]);
  129. return self}, self, "testBlockReturn", [], smalltalk.CodeGeneratorTest)},
  130. args: [],
  131. source: "testBlockReturn\x0a\x09self should: 'foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]' return: #(2 3 4).\x0a\x09self should: 'foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]' return: #(2 3 4).\x0a\x09self should: 'foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]' return: #(2 1 4).",
  132. messageSends: ["should:return:"],
  133. referencedClasses: []
  134. }),
  135. smalltalk.CodeGeneratorTest);
  136. smalltalk.addMethod(
  137. "_testCascades",
  138. smalltalk.method({
  139. selector: "testCascades",
  140. category: 'tests',
  141. fn: function (){
  142. var self=this;
  143. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo ^ Array new add: 3; add: 4; yourself",[(3), (4)]);
  144. return self}, self, "testCascades", [], smalltalk.CodeGeneratorTest)},
  145. args: [],
  146. source: "testCascades\x0a\x09\x0a\x09self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)",
  147. messageSends: ["should:return:"],
  148. referencedClasses: []
  149. }),
  150. smalltalk.CodeGeneratorTest);
  151. smalltalk.addMethod(
  152. "_testLiterals",
  153. smalltalk.method({
  154. selector: "testLiterals",
  155. category: 'tests',
  156. fn: function (){
  157. var self=this;
  158. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo ^ 1",(1));
  159. _st(self)._should_return_("foo ^ 'hello'","hello");
  160. _st(self)._should_return_("foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]);
  161. _st(self)._should_return_("foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]);
  162. _st(self)._should_return_("foo ^ true",true);
  163. _st(self)._should_return_("foo ^ false",false);
  164. _st(self)._should_return_("foo ^ #{1->2. 3->4}",smalltalk.HashedCollection._fromPairs_([_st((1)).__minus_gt((2)),_st((3)).__minus_gt((4))]));
  165. _st(self)._should_return_("foo ^ #hello",smalltalk.symbolFor("hello"));
  166. _st(self)._should_return_("foo ^ -123.456",(-123.456));
  167. return self}, self, "testLiterals", [], smalltalk.CodeGeneratorTest)},
  168. args: [],
  169. source: "testLiterals\x0a\x09self should: 'foo ^ 1' return: 1.\x0a\x09self should: 'foo ^ ''hello''' return: 'hello'.\x0a\x09self should: 'foo ^ #(1 2 3 4)' return: #(1 2 3 4).\x0a\x09self should: 'foo ^ {1. [:x | x ] value: 2. 3. [4] value}' return: #(1 2 3 4).\x0a\x09self should: 'foo ^ true' return: true.\x0a\x09self should: 'foo ^ false' return: false.\x0a\x09self should: 'foo ^ #{1->2. 3->4}' return: #{1->2. 3->4}.\x0a\x09self should: 'foo ^ #hello' return: #hello.\x0a\x09self should: 'foo ^ -123.456' return: -123.456",
  170. messageSends: ["should:return:", "->"],
  171. referencedClasses: []
  172. }),
  173. smalltalk.CodeGeneratorTest);
  174. smalltalk.addMethod(
  175. "_testLocalReturn",
  176. smalltalk.method({
  177. selector: "testLocalReturn",
  178. category: 'tests',
  179. fn: function (){
  180. var self=this;
  181. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo ^ 1",(1));
  182. _st(self)._should_return_("foo ^ 1 + 1",(2));
  183. _st(self)._should_return_("foo ",self["@receiver"]);
  184. _st(self)._should_return_("foo self asString",self["@receiver"]);
  185. _st(self)._should_return_("foo | a b | a := 1. b := 2. ^ a + b",(3));
  186. return self}, self, "testLocalReturn", [], smalltalk.CodeGeneratorTest)},
  187. args: [],
  188. source: "testLocalReturn\x0a\x09self should: 'foo ^ 1' return: 1.\x0a\x09self should: 'foo ^ 1 + 1' return: 2.\x0a\x09self should: 'foo ' return: receiver.\x0a\x09self should: 'foo self asString' return: receiver.\x0a\x09self should: 'foo | a b | a := 1. b := 2. ^ a + b' return: 3",
  189. messageSends: ["should:return:"],
  190. referencedClasses: []
  191. }),
  192. smalltalk.CodeGeneratorTest);
  193. smalltalk.addMethod(
  194. "_testMessageSends",
  195. smalltalk.method({
  196. selector: "testMessageSends",
  197. category: 'tests',
  198. fn: function (){
  199. var self=this;
  200. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo ^ 1 asString","1");
  201. _st(self)._should_return_("foo ^ 1 + 1",(2));
  202. _st(self)._should_return_("foo ^ 1 + 2 * 3",(9));
  203. _st(self)._should_return_("foo ^ 1 to: 3",[(1), (2), (3)]);
  204. _st(self)._should_return_("foo ^ 1 to: 5 by: 2",[(1), (3), (5)]);
  205. return self}, self, "testMessageSends", [], smalltalk.CodeGeneratorTest)},
  206. args: [],
  207. source: "testMessageSends\x0a\x09self should: 'foo ^ 1 asString' return: '1'.\x0a\x0a\x09self should: 'foo ^ 1 + 1' return: 2.\x0a\x09self should: 'foo ^ 1 + 2 * 3' return: 9.\x0a\x0a\x09self should: 'foo ^ 1 to: 3' return: #(1 2 3).\x0a\x09self should: 'foo ^ 1 to: 5 by: 2' return: #(1 3 5)",
  208. messageSends: ["should:return:"],
  209. referencedClasses: []
  210. }),
  211. smalltalk.CodeGeneratorTest);
  212. smalltalk.addMethod(
  213. "_testNestedIfTrue",
  214. smalltalk.method({
  215. selector: "testNestedIfTrue",
  216. category: 'tests',
  217. fn: function (){
  218. var self=this;
  219. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1));
  220. _st(self)._should_return_("foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil);
  221. _st(self)._should_return_("foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1));
  222. _st(self)._should_return_("foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]);
  223. return self}, self, "testNestedIfTrue", [], smalltalk.CodeGeneratorTest)},
  224. args: [],
  225. source: "testNestedIfTrue\x0a\x09self should: 'foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]' return: 1.\x0a\x09self should: 'foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]' return: nil.\x0a\x0a\x09self should: 'foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]' return: 1.\x0a\x09self should: 'foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]' return: receiver.",
  226. messageSends: ["should:return:"],
  227. referencedClasses: []
  228. }),
  229. smalltalk.CodeGeneratorTest);
  230. smalltalk.addMethod(
  231. "_testNonLocalReturn",
  232. smalltalk.method({
  233. selector: "testNonLocalReturn",
  234. category: 'tests',
  235. fn: function (){
  236. var self=this;
  237. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo [ ^ 1 ] value",(1));
  238. _st(self)._should_return_("foo [ ^ 1 + 1 ] value",(2));
  239. _st(self)._should_return_("foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3));
  240. _st(self)._should_return_("foo [ :x | ^ x + x ] value: 4. ^ 2",(8));
  241. return self}, self, "testNonLocalReturn", [], smalltalk.CodeGeneratorTest)},
  242. args: [],
  243. source: "testNonLocalReturn\x0a\x09self should: 'foo [ ^ 1 ] value' return: 1.\x0a\x09self should: 'foo [ ^ 1 + 1 ] value' return: 2.\x0a\x09self should: 'foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt' return: 3.\x0a\x09self should: 'foo [ :x | ^ x + x ] value: 4. ^ 2' return: 8",
  244. messageSends: ["should:return:"],
  245. referencedClasses: []
  246. }),
  247. smalltalk.CodeGeneratorTest);
  248. smalltalk.addMethod(
  249. "_testifFalse",
  250. smalltalk.method({
  251. selector: "testifFalse",
  252. category: 'tests',
  253. fn: function (){
  254. var self=this;
  255. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  256. _st(self)._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  257. _st(self)._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  258. _st(self)._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  259. return self}, self, "testifFalse", [], smalltalk.CodeGeneratorTest)},
  260. args: [],
  261. source: "testifFalse\x0a\x09self should: 'foo true ifFalse: [ ^ 1 ]' return: receiver.\x0a\x09self should: 'foo false ifFalse: [ ^ 2 ]' return: 2.\x0a\x09\x0a\x09self should: 'foo ^ true ifFalse: [ 1 ]' return: nil.\x0a\x09self should: 'foo ^ false ifFalse: [ 2 ]' return: 2.",
  262. messageSends: ["should:return:"],
  263. referencedClasses: []
  264. }),
  265. smalltalk.CodeGeneratorTest);
  266. smalltalk.addMethod(
  267. "_testifFalseIfTrue",
  268. smalltalk.method({
  269. selector: "testifFalseIfTrue",
  270. category: 'tests',
  271. fn: function (){
  272. var self=this;
  273. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  274. _st(self)._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  275. _st(self)._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  276. _st(self)._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  277. return self}, self, "testifFalseIfTrue", [], smalltalk.CodeGeneratorTest)},
  278. args: [],
  279. source: "testifFalseIfTrue\x0a\x09self should: 'foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]' return: 2.\x0a\x09self should: 'foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]' return: 2.\x0a\x09\x0a\x09self should: 'foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]' return: 2.\x0a\x09self should: 'foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]' return: 2.",
  280. messageSends: ["should:return:"],
  281. referencedClasses: []
  282. }),
  283. smalltalk.CodeGeneratorTest);
  284. smalltalk.addMethod(
  285. "_testifNil",
  286. smalltalk.method({
  287. selector: "testifNil",
  288. category: 'tests',
  289. fn: function (){
  290. var self=this;
  291. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  292. _st(self)._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  293. _st(self)._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  294. _st(self)._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  295. return self}, self, "testifNil", [], smalltalk.CodeGeneratorTest)},
  296. args: [],
  297. source: "testifNil\x0a\x09self should: 'foo ^ 1 ifNil: [ 2 ]' return: 1.\x0a\x09self should: 'foo ^ nil ifNil: [ 2 ]' return: 2.\x0a\x0a\x09self should: 'foo 1 ifNil: [ ^ 2 ]' return: receiver.\x0a\x09self should: 'foo nil ifNil: [ ^ 2 ]' return: 2.",
  298. messageSends: ["should:return:"],
  299. referencedClasses: []
  300. }),
  301. smalltalk.CodeGeneratorTest);
  302. smalltalk.addMethod(
  303. "_testifNilIfNotNil",
  304. smalltalk.method({
  305. selector: "testifNilIfNotNil",
  306. category: 'tests',
  307. fn: function (){
  308. var self=this;
  309. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  310. _st(self)._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  311. _st(self)._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  312. _st(self)._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  313. return self}, self, "testifNilIfNotNil", [], smalltalk.CodeGeneratorTest)},
  314. args: [],
  315. source: "testifNilIfNotNil\x0a\x09self should: 'foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]' return: 2.\x0a\x0a\x09self should: 'foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]' return: 3.\x0a\x09self should: 'foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]' return: 2.",
  316. messageSends: ["should:return:"],
  317. referencedClasses: []
  318. }),
  319. smalltalk.CodeGeneratorTest);
  320. smalltalk.addMethod(
  321. "_testifNotNil",
  322. smalltalk.method({
  323. selector: "testifNotNil",
  324. category: 'tests',
  325. fn: function (){
  326. var self=this;
  327. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  328. _st(self)._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  329. _st(self)._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  330. _st(self)._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  331. return self}, self, "testifNotNil", [], smalltalk.CodeGeneratorTest)},
  332. args: [],
  333. source: "testifNotNil\x0a\x09self should: 'foo ^ 1 ifNotNil: [ 2 ]' return: 2.\x0a\x09self should: 'foo ^ nil ifNotNil: [ 2 ]' return: nil.\x0a\x0a\x09self should: 'foo 1 ifNotNil: [ ^ 2 ]' return: 2.\x0a\x09self should: 'foo nil ifNotNil: [ ^ 2 ]' return: receiver.",
  334. messageSends: ["should:return:"],
  335. referencedClasses: []
  336. }),
  337. smalltalk.CodeGeneratorTest);
  338. smalltalk.addMethod(
  339. "_testifTrue",
  340. smalltalk.method({
  341. selector: "testifTrue",
  342. category: 'tests',
  343. fn: function (){
  344. var self=this;
  345. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  346. _st(self)._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  347. _st(self)._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  348. _st(self)._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  349. return self}, self, "testifTrue", [], smalltalk.CodeGeneratorTest)},
  350. args: [],
  351. source: "testifTrue\x0a\x09self should: 'foo false ifTrue: [ ^ 1 ]' return: receiver.\x0a\x09self should: 'foo true ifTrue: [ ^ 2 ]' return: 2.\x0a\x09\x0a\x09self should: 'foo ^ false ifTrue: [ 1 ]' return: nil.\x0a\x09self should: 'foo ^ true ifTrue: [ 2 ]' return: 2.",
  352. messageSends: ["should:return:"],
  353. referencedClasses: []
  354. }),
  355. smalltalk.CodeGeneratorTest);
  356. smalltalk.addMethod(
  357. "_testifTrueIfFalse",
  358. smalltalk.method({
  359. selector: "testifTrueIfFalse",
  360. category: 'tests',
  361. fn: function (){
  362. var self=this;
  363. return smalltalk.withContext(function($ctx) { _st(self)._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  364. _st(self)._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  365. _st(self)._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  366. _st(self)._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  367. return self}, self, "testifTrueIfFalse", [], smalltalk.CodeGeneratorTest)},
  368. args: [],
  369. source: "testifTrueIfFalse\x0a\x09self should: 'foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]' return: 2.\x0a\x09self should: 'foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]' return: 1.\x0a\x09\x0a\x09self should: 'foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]' return: 1.\x0a\x09self should: 'foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]' return: 2.",
  370. messageSends: ["should:return:"],
  371. referencedClasses: []
  372. }),
  373. smalltalk.CodeGeneratorTest);
  374. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  375. smalltalk.addMethod(
  376. "_codeGeneratorClass",
  377. smalltalk.method({
  378. selector: "codeGeneratorClass",
  379. category: 'accessing',
  380. fn: function (){
  381. var self=this;
  382. return smalltalk.withContext(function($ctx) { return (smalltalk.InliningCodeGenerator || InliningCodeGenerator);
  383. }, self, "codeGeneratorClass", [], smalltalk.InliningCodeGeneratorTest)},
  384. args: [],
  385. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  386. messageSends: [],
  387. referencedClasses: ["InliningCodeGenerator"]
  388. }),
  389. smalltalk.InliningCodeGeneratorTest);
  390. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  391. smalltalk.addMethod(
  392. "_testClassRefVar",
  393. smalltalk.method({
  394. selector: "testClassRefVar",
  395. category: 'tests',
  396. fn: function (){
  397. var self=this;
  398. return smalltalk.withContext(function($ctx) { var $1,$2;
  399. var node;
  400. $1=_st((smalltalk.ClassReferenceNode || ClassReferenceNode))._new();
  401. _st($1)._value_("Object");
  402. $2=_st($1)._yourself();
  403. node=$2;
  404. _st(_st((smalltalk.SemanticAnalyzer || SemanticAnalyzer))._new())._visit_(node);
  405. _st(self)._assert_(_st(_st(node)._binding())._isClassRefVar());
  406. return self}, self, "testClassRefVar", [], smalltalk.ScopeVarTest)},
  407. args: [],
  408. 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",
  409. messageSends: ["value:", "new", "yourself", "visit:", "assert:", "isClassRefVar", "binding"],
  410. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  411. }),
  412. smalltalk.ScopeVarTest);
  413. smalltalk.addMethod(
  414. "_testInstanceVar",
  415. smalltalk.method({
  416. selector: "testInstanceVar",
  417. category: 'tests',
  418. fn: function (){
  419. var self=this;
  420. return smalltalk.withContext(function($ctx) { var $1,$2;
  421. var node;
  422. var scope;
  423. $1=_st((smalltalk.VariableNode || VariableNode))._new();
  424. _st($1)._value_("bzzz");
  425. $2=_st($1)._yourself();
  426. node=$2;
  427. scope=_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new();
  428. _st(scope)._addIVar_("bzzz");
  429. _st(self)._assert_(_st(_st(scope)._bindingFor_(node))._isInstanceVar());
  430. return self}, self, "testInstanceVar", [], smalltalk.ScopeVarTest)},
  431. args: [],
  432. 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",
  433. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  434. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  435. }),
  436. smalltalk.ScopeVarTest);
  437. smalltalk.addMethod(
  438. "_testPseudoVar",
  439. smalltalk.method({
  440. selector: "testPseudoVar",
  441. category: 'tests',
  442. fn: function (){
  443. var self=this;
  444. return smalltalk.withContext(function($ctx) { var $1,$2;
  445. var node;
  446. var pseudoVars;
  447. pseudoVars=["self", "super", "true", "false", "nil"];
  448. _st(pseudoVars)._do_((function(each){
  449. $1=_st((smalltalk.VariableNode || VariableNode))._new();
  450. _st($1)._value_(each);
  451. $2=_st($1)._yourself();
  452. node=$2;
  453. node;
  454. return _st(self)._assert_(_st(_st(_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new())._bindingFor_(node))._isPseudoVar());
  455. }));
  456. return self}, self, "testPseudoVar", [], smalltalk.ScopeVarTest)},
  457. args: [],
  458. 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 ]",
  459. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  460. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  461. }),
  462. smalltalk.ScopeVarTest);
  463. smalltalk.addMethod(
  464. "_testTempVar",
  465. smalltalk.method({
  466. selector: "testTempVar",
  467. category: 'tests',
  468. fn: function (){
  469. var self=this;
  470. return smalltalk.withContext(function($ctx) { var $1,$2;
  471. var node;
  472. var scope;
  473. $1=_st((smalltalk.VariableNode || VariableNode))._new();
  474. _st($1)._value_("bzzz");
  475. $2=_st($1)._yourself();
  476. node=$2;
  477. scope=_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new();
  478. _st(scope)._addTemp_("bzzz");
  479. _st(self)._assert_(_st(_st(scope)._bindingFor_(node))._isTempVar());
  480. return self}, self, "testTempVar", [], smalltalk.ScopeVarTest)},
  481. args: [],
  482. 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",
  483. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  484. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  485. }),
  486. smalltalk.ScopeVarTest);
  487. smalltalk.addMethod(
  488. "_testUnknownVar",
  489. smalltalk.method({
  490. selector: "testUnknownVar",
  491. category: 'tests',
  492. fn: function (){
  493. var self=this;
  494. return smalltalk.withContext(function($ctx) { var $1,$2;
  495. var node;
  496. $1=_st((smalltalk.VariableNode || VariableNode))._new();
  497. _st($1)._value_("bzzz");
  498. $2=_st($1)._yourself();
  499. node=$2;
  500. _st(self)._assert_(_st(_st(_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new())._bindingFor_(node))._isNil());
  501. return self}, self, "testUnknownVar", [], smalltalk.ScopeVarTest)},
  502. args: [],
  503. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  504. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  505. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  506. }),
  507. smalltalk.ScopeVarTest);
  508. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  509. smalltalk.addMethod(
  510. "_setUp",
  511. smalltalk.method({
  512. selector: "setUp",
  513. category: 'running',
  514. fn: function (){
  515. var self=this;
  516. return smalltalk.withContext(function($ctx) { self["@analyzer"]=_st((smalltalk.SemanticAnalyzer || SemanticAnalyzer))._on_((smalltalk.Object || Object));
  517. return self}, self, "setUp", [], smalltalk.SemanticAnalyzerTest)},
  518. args: [],
  519. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  520. messageSends: ["on:"],
  521. referencedClasses: ["Object", "SemanticAnalyzer"]
  522. }),
  523. smalltalk.SemanticAnalyzerTest);
  524. smalltalk.addMethod(
  525. "_testAssignment",
  526. smalltalk.method({
  527. selector: "testAssignment",
  528. category: 'tests',
  529. fn: function (){
  530. var self=this;
  531. return smalltalk.withContext(function($ctx) { var src;
  532. var ast;
  533. src="foo self := 1";
  534. ast=_st(smalltalk)._parse_(src);
  535. _st(self)._should_raise_((function(){
  536. return _st(self["@analyzer"])._visit_(ast);
  537. }),(smalltalk.InvalidAssignmentError || InvalidAssignmentError));
  538. return self}, self, "testAssignment", [], smalltalk.SemanticAnalyzerTest)},
  539. args: [],
  540. 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",
  541. messageSends: ["parse:", "should:raise:", "visit:"],
  542. referencedClasses: ["InvalidAssignmentError"]
  543. }),
  544. smalltalk.SemanticAnalyzerTest);
  545. smalltalk.addMethod(
  546. "_testNonLocalReturn",
  547. smalltalk.method({
  548. selector: "testNonLocalReturn",
  549. category: 'tests',
  550. fn: function (){
  551. var self=this;
  552. return smalltalk.withContext(function($ctx) { var src;
  553. var ast;
  554. src="foo | a | a + 1. ^ a";
  555. ast=_st(smalltalk)._parse_(src);
  556. _st(self["@analyzer"])._visit_(ast);
  557. _st(self)._deny_(_st(_st(ast)._scope())._hasNonLocalReturn());
  558. return self}, self, "testNonLocalReturn", [], smalltalk.SemanticAnalyzerTest)},
  559. args: [],
  560. 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",
  561. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  562. referencedClasses: []
  563. }),
  564. smalltalk.SemanticAnalyzerTest);
  565. smalltalk.addMethod(
  566. "_testNonLocalReturn2",
  567. smalltalk.method({
  568. selector: "testNonLocalReturn2",
  569. category: 'tests',
  570. fn: function (){
  571. var self=this;
  572. return smalltalk.withContext(function($ctx) { var src;
  573. var ast;
  574. src="foo | a | a + 1. [ [ ^ a] ]";
  575. ast=_st(smalltalk)._parse_(src);
  576. _st(self["@analyzer"])._visit_(ast);
  577. _st(self)._assert_(_st(_st(ast)._scope())._hasNonLocalReturn());
  578. return self}, self, "testNonLocalReturn2", [], smalltalk.SemanticAnalyzerTest)},
  579. args: [],
  580. 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",
  581. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  582. referencedClasses: []
  583. }),
  584. smalltalk.SemanticAnalyzerTest);
  585. smalltalk.addMethod(
  586. "_testScope",
  587. smalltalk.method({
  588. selector: "testScope",
  589. category: 'tests',
  590. fn: function (){
  591. var self=this;
  592. return smalltalk.withContext(function($ctx) { var src;
  593. var ast;
  594. src="foo | a | a + 1. [ | b | b := a ]";
  595. ast=_st(smalltalk)._parse_(src);
  596. _st(self["@analyzer"])._visit_(ast);
  597. _st(self)._deny_(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._scope()).__eq_eq(_st(ast)._scope()));
  598. return self}, self, "testScope", [], smalltalk.SemanticAnalyzerTest)},
  599. args: [],
  600. 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.",
  601. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  602. referencedClasses: []
  603. }),
  604. smalltalk.SemanticAnalyzerTest);
  605. smalltalk.addMethod(
  606. "_testScope2",
  607. smalltalk.method({
  608. selector: "testScope2",
  609. category: 'tests',
  610. fn: function (){
  611. var self=this;
  612. return smalltalk.withContext(function($ctx) { var src;
  613. var ast;
  614. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  615. ast=_st(smalltalk)._parse_(src);
  616. _st(self["@analyzer"])._visit_(ast);
  617. _st(self)._deny_(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._nodes())._first())._nodes())._first())._scope()).__eq_eq(_st(ast)._scope()));
  618. return self}, self, "testScope2", [], smalltalk.SemanticAnalyzerTest)},
  619. args: [],
  620. 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.",
  621. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  622. referencedClasses: []
  623. }),
  624. smalltalk.SemanticAnalyzerTest);
  625. smalltalk.addMethod(
  626. "_testScopeLevel",
  627. smalltalk.method({
  628. selector: "testScopeLevel",
  629. category: 'tests',
  630. fn: function (){
  631. var self=this;
  632. return smalltalk.withContext(function($ctx) { var src;
  633. var ast;
  634. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  635. ast=_st(smalltalk)._parse_(src);
  636. _st(self["@analyzer"])._visit_(ast);
  637. _st(self)._assert_(_st(_st(_st(ast)._scope())._scopeLevel()).__eq((1)));
  638. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._nodes())._first())._nodes())._first())._scope())._scopeLevel()).__eq((3)));
  639. return self}, self, "testScopeLevel", [], smalltalk.SemanticAnalyzerTest)},
  640. args: [],
  641. 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",
  642. messageSends: ["parse:", "visit:", "assert:", "=", "scopeLevel", "scope", "first", "nodes", "last"],
  643. referencedClasses: []
  644. }),
  645. smalltalk.SemanticAnalyzerTest);
  646. smalltalk.addMethod(
  647. "_testUnknownVariables",
  648. smalltalk.method({
  649. selector: "testUnknownVariables",
  650. category: 'tests',
  651. fn: function (){
  652. var self=this;
  653. return smalltalk.withContext(function($ctx) { var src;
  654. var ast;
  655. src="foo | a | b + a";
  656. ast=_st(smalltalk)._parse_(src);
  657. _st(self)._should_raise_((function(){
  658. return _st(self["@analyzer"])._visit_(ast);
  659. }),(smalltalk.UnknownVariableError || UnknownVariableError));
  660. return self}, self, "testUnknownVariables", [], smalltalk.SemanticAnalyzerTest)},
  661. args: [],
  662. source: "testUnknownVariables\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | b + a'.\x0a\x09ast := smalltalk parse: src.\x0a\x0a\x09self should: [ analyzer visit: ast ] raise: UnknownVariableError",
  663. messageSends: ["parse:", "should:raise:", "visit:"],
  664. referencedClasses: ["UnknownVariableError"]
  665. }),
  666. smalltalk.SemanticAnalyzerTest);
  667. smalltalk.addMethod(
  668. "_testUnknownVariablesDefinedInJS",
  669. smalltalk.method({
  670. selector: "testUnknownVariablesDefinedInJS",
  671. category: 'tests',
  672. fn: function (){
  673. var self=this;
  674. return smalltalk.withContext(function($ctx) { var someVariable = 1 ;
  675. ;
  676. _st(self)._shouldnt_raise_((function(){
  677. return _st(smalltalk)._parse_("foo someVariable");
  678. }),(smalltalk.UnknownVariableError || UnknownVariableError));
  679. return self}, self, "testUnknownVariablesDefinedInJS", [], smalltalk.SemanticAnalyzerTest)},
  680. args: [],
  681. source: "testUnknownVariablesDefinedInJS\x0a\x0a\x09< var someVariable = 1 >.\x0a\x0a\x09self shouldnt: [ smalltalk parse: 'foo someVariable' ] raise: UnknownVariableError",
  682. messageSends: ["shouldnt:raise:", "parse:"],
  683. referencedClasses: ["UnknownVariableError"]
  684. }),
  685. smalltalk.SemanticAnalyzerTest);
  686. smalltalk.addMethod(
  687. "_testUnknownVariablesWithScope",
  688. smalltalk.method({
  689. selector: "testUnknownVariablesWithScope",
  690. category: 'tests',
  691. fn: function (){
  692. var self=this;
  693. return smalltalk.withContext(function($ctx) { var src;
  694. var ast;
  695. src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  696. ast=_st(smalltalk)._parse_(src);
  697. _st(self)._should_raise_((function(){
  698. return _st(self["@analyzer"])._visit_(ast);
  699. }),(smalltalk.UnknownVariableError || UnknownVariableError));
  700. return self}, self, "testUnknownVariablesWithScope", [], smalltalk.SemanticAnalyzerTest)},
  701. args: [],
  702. source: "testUnknownVariablesWithScope\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a b | [ c + 1. [ a + 1. d + 1 ]]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09\x0a\x09self should: [ analyzer visit: ast ] raise: UnknownVariableError",
  703. messageSends: ["parse:", "should:raise:", "visit:"],
  704. referencedClasses: ["UnknownVariableError"]
  705. }),
  706. smalltalk.SemanticAnalyzerTest);
  707. smalltalk.addMethod(
  708. "_testVariableShadowing",
  709. smalltalk.method({
  710. selector: "testVariableShadowing",
  711. category: 'tests',
  712. fn: function (){
  713. var self=this;
  714. return smalltalk.withContext(function($ctx) { var src;
  715. var ast;
  716. src="foo | a | a + 1";
  717. ast=_st(smalltalk)._parse_(src);
  718. _st(self["@analyzer"])._visit_(ast);
  719. return self}, self, "testVariableShadowing", [], smalltalk.SemanticAnalyzerTest)},
  720. args: [],
  721. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  722. messageSends: ["parse:", "visit:"],
  723. referencedClasses: []
  724. }),
  725. smalltalk.SemanticAnalyzerTest);
  726. smalltalk.addMethod(
  727. "_testVariableShadowing2",
  728. smalltalk.method({
  729. selector: "testVariableShadowing2",
  730. category: 'tests',
  731. fn: function (){
  732. var self=this;
  733. return smalltalk.withContext(function($ctx) { var src;
  734. var ast;
  735. src="foo | a | a + 1. [ | a | a := 2 ]";
  736. ast=_st(smalltalk)._parse_(src);
  737. _st(self)._should_raise_((function(){
  738. return _st(self["@analyzer"])._visit_(ast);
  739. }),(smalltalk.ShadowingVariableError || ShadowingVariableError));
  740. return self}, self, "testVariableShadowing2", [], smalltalk.SemanticAnalyzerTest)},
  741. args: [],
  742. 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",
  743. messageSends: ["parse:", "should:raise:", "visit:"],
  744. referencedClasses: ["ShadowingVariableError"]
  745. }),
  746. smalltalk.SemanticAnalyzerTest);
  747. smalltalk.addMethod(
  748. "_testVariableShadowing3",
  749. smalltalk.method({
  750. selector: "testVariableShadowing3",
  751. category: 'tests',
  752. fn: function (){
  753. var self=this;
  754. return smalltalk.withContext(function($ctx) { var src;
  755. var ast;
  756. src="foo | a | a + 1. [ | b | b := 2 ]";
  757. ast=_st(smalltalk)._parse_(src);
  758. _st(self["@analyzer"])._visit_(ast);
  759. return self}, self, "testVariableShadowing3", [], smalltalk.SemanticAnalyzerTest)},
  760. args: [],
  761. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  762. messageSends: ["parse:", "visit:"],
  763. referencedClasses: []
  764. }),
  765. smalltalk.SemanticAnalyzerTest);
  766. smalltalk.addMethod(
  767. "_testVariableShadowing4",
  768. smalltalk.method({
  769. selector: "testVariableShadowing4",
  770. category: 'tests',
  771. fn: function (){
  772. var self=this;
  773. return smalltalk.withContext(function($ctx) { var src;
  774. var ast;
  775. src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  776. ast=_st(smalltalk)._parse_(src);
  777. _st(self["@analyzer"])._visit_(ast);
  778. return self}, self, "testVariableShadowing4", [], smalltalk.SemanticAnalyzerTest)},
  779. args: [],
  780. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  781. messageSends: ["parse:", "visit:"],
  782. referencedClasses: []
  783. }),
  784. smalltalk.SemanticAnalyzerTest);
  785. smalltalk.addMethod(
  786. "_testVariableShadowing5",
  787. smalltalk.method({
  788. selector: "testVariableShadowing5",
  789. category: 'tests',
  790. fn: function (){
  791. var self=this;
  792. return smalltalk.withContext(function($ctx) { var src;
  793. var ast;
  794. src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  795. ast=_st(smalltalk)._parse_(src);
  796. _st(self)._should_raise_((function(){
  797. return _st(self["@analyzer"])._visit_(ast);
  798. }),(smalltalk.ShadowingVariableError || ShadowingVariableError));
  799. return self}, self, "testVariableShadowing5", [], smalltalk.SemanticAnalyzerTest)},
  800. args: [],
  801. 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",
  802. messageSends: ["parse:", "should:raise:", "visit:"],
  803. referencedClasses: ["ShadowingVariableError"]
  804. }),
  805. smalltalk.SemanticAnalyzerTest);
  806. smalltalk.addMethod(
  807. "_testVariablesLookup",
  808. smalltalk.method({
  809. selector: "testVariablesLookup",
  810. category: 'tests',
  811. fn: function (){
  812. var self=this;
  813. return smalltalk.withContext(function($ctx) { var src;
  814. var ast;
  815. src="foo | a | a + 1. [ | b | b := a ]";
  816. ast=_st(smalltalk)._parse_(src);
  817. _st(self["@analyzer"])._visit_(ast);
  818. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._isTempVar());
  819. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._scope()).__eq_eq(_st(ast)._scope()));
  820. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._nodes())._first())._nodes())._first())._left())._binding())._isTempVar());
  821. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._nodes())._first())._nodes())._first())._left())._binding())._scope()).__eq_eq(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._scope()));
  822. return self}, self, "testVariablesLookup", [], smalltalk.SemanticAnalyzerTest)},
  823. args: [],
  824. 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.",
  825. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  826. referencedClasses: []
  827. }),
  828. smalltalk.SemanticAnalyzerTest);