1
0

Compiler-Tests.js 36 KB

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