2
0

Compiler-Exceptions.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. define("amber_core/Compiler-Exceptions", ["amber/boot", "amber_core/Kernel-Exceptions", "amber_core/Kernel-Objects"], function($boot){
  2. var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. var smalltalk=$core,_st=$recv,globals=$globals;
  4. $core.addPackage('Compiler-Exceptions');
  5. $core.packages["Compiler-Exceptions"].transport = {"type":"amd","amdNamespace":"amber_core"};
  6. $core.addClass('CompilerError', $globals.Error, [], 'Compiler-Exceptions');
  7. //>>excludeStart("ide", pragmas.excludeIdeData);
  8. $globals.CompilerError.comment="I am the common superclass of all compiling errors.";
  9. //>>excludeEnd("ide");
  10. $core.addClass('ParseError', $globals.CompilerError, [], 'Compiler-Exceptions');
  11. //>>excludeStart("ide", pragmas.excludeIdeData);
  12. $globals.ParseError.comment="Instance of ParseError are signaled on any parsing error.\x0aSee `Smalltalk >> #parse:`";
  13. //>>excludeEnd("ide");
  14. $core.addClass('SemanticError', $globals.CompilerError, [], 'Compiler-Exceptions');
  15. //>>excludeStart("ide", pragmas.excludeIdeData);
  16. $globals.SemanticError.comment="I represent an abstract semantic error thrown by the SemanticAnalyzer.\x0aSemantic errors can be unknown variable errors, etc.\x0aSee my subclasses for concrete errors.\x0a\x0aThe IDE should catch instances of Semantic error to deal with them when compiling";
  17. //>>excludeEnd("ide");
  18. $core.addClass('InliningError', $globals.SemanticError, [], 'Compiler-Exceptions');
  19. //>>excludeStart("ide", pragmas.excludeIdeData);
  20. $globals.InliningError.comment="Instances of InliningError are signaled when using an `InliningCodeGenerator`in a `Compiler`.";
  21. //>>excludeEnd("ide");
  22. $core.addClass('InvalidAssignmentError', $globals.SemanticError, ['variableName'], 'Compiler-Exceptions');
  23. //>>excludeStart("ide", pragmas.excludeIdeData);
  24. $globals.InvalidAssignmentError.comment="I get signaled when a pseudo variable gets assigned.";
  25. //>>excludeEnd("ide");
  26. $core.addMethod(
  27. $core.method({
  28. selector: "messageText",
  29. protocol: 'accessing',
  30. fn: function (){
  31. var self=this;
  32. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  33. return $core.withContext(function($ctx1) {
  34. //>>excludeEnd("ctx");
  35. var $1;
  36. $1=" Invalid assignment to variable: ".__comma(self._variableName());
  37. return $1;
  38. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  39. }, function($ctx1) {$ctx1.fill(self,"messageText",{},$globals.InvalidAssignmentError)});
  40. //>>excludeEnd("ctx");
  41. },
  42. //>>excludeStart("ide", pragmas.excludeIdeData);
  43. args: [],
  44. source: "messageText\x0a\x09^ ' Invalid assignment to variable: ', self variableName",
  45. referencedClasses: [],
  46. //>>excludeEnd("ide");
  47. messageSends: [",", "variableName"]
  48. }),
  49. $globals.InvalidAssignmentError);
  50. $core.addMethod(
  51. $core.method({
  52. selector: "variableName",
  53. protocol: 'accessing',
  54. fn: function (){
  55. var self=this;
  56. var $1;
  57. $1=self["@variableName"];
  58. return $1;
  59. },
  60. //>>excludeStart("ide", pragmas.excludeIdeData);
  61. args: [],
  62. source: "variableName\x0a\x09^ variableName",
  63. referencedClasses: [],
  64. //>>excludeEnd("ide");
  65. messageSends: []
  66. }),
  67. $globals.InvalidAssignmentError);
  68. $core.addMethod(
  69. $core.method({
  70. selector: "variableName:",
  71. protocol: 'accessing',
  72. fn: function (aString){
  73. var self=this;
  74. self["@variableName"]=aString;
  75. return self;
  76. },
  77. //>>excludeStart("ide", pragmas.excludeIdeData);
  78. args: ["aString"],
  79. source: "variableName: aString\x0a\x09variableName := aString",
  80. referencedClasses: [],
  81. //>>excludeEnd("ide");
  82. messageSends: []
  83. }),
  84. $globals.InvalidAssignmentError);
  85. $core.addClass('ShadowingVariableError', $globals.SemanticError, ['variableName'], 'Compiler-Exceptions');
  86. //>>excludeStart("ide", pragmas.excludeIdeData);
  87. $globals.ShadowingVariableError.comment="I get signaled when a variable in a block or method scope shadows a variable of the same name in an outer scope.";
  88. //>>excludeEnd("ide");
  89. $core.addMethod(
  90. $core.method({
  91. selector: "messageText",
  92. protocol: 'accessing',
  93. fn: function (){
  94. var self=this;
  95. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  96. return $core.withContext(function($ctx1) {
  97. //>>excludeEnd("ctx");
  98. var $1;
  99. $1=$recv("Variable shadowing error: ".__comma(self._variableName())).__comma(" is already defined");
  100. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  101. $ctx1.sendIdx[","]=1;
  102. //>>excludeEnd("ctx");
  103. return $1;
  104. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  105. }, function($ctx1) {$ctx1.fill(self,"messageText",{},$globals.ShadowingVariableError)});
  106. //>>excludeEnd("ctx");
  107. },
  108. //>>excludeStart("ide", pragmas.excludeIdeData);
  109. args: [],
  110. source: "messageText\x0a\x09^ 'Variable shadowing error: ', self variableName, ' is already defined'",
  111. referencedClasses: [],
  112. //>>excludeEnd("ide");
  113. messageSends: [",", "variableName"]
  114. }),
  115. $globals.ShadowingVariableError);
  116. $core.addMethod(
  117. $core.method({
  118. selector: "variableName",
  119. protocol: 'accessing',
  120. fn: function (){
  121. var self=this;
  122. var $1;
  123. $1=self["@variableName"];
  124. return $1;
  125. },
  126. //>>excludeStart("ide", pragmas.excludeIdeData);
  127. args: [],
  128. source: "variableName\x0a\x09^ variableName",
  129. referencedClasses: [],
  130. //>>excludeEnd("ide");
  131. messageSends: []
  132. }),
  133. $globals.ShadowingVariableError);
  134. $core.addMethod(
  135. $core.method({
  136. selector: "variableName:",
  137. protocol: 'accessing',
  138. fn: function (aString){
  139. var self=this;
  140. self["@variableName"]=aString;
  141. return self;
  142. },
  143. //>>excludeStart("ide", pragmas.excludeIdeData);
  144. args: ["aString"],
  145. source: "variableName: aString\x0a\x09variableName := aString",
  146. referencedClasses: [],
  147. //>>excludeEnd("ide");
  148. messageSends: []
  149. }),
  150. $globals.ShadowingVariableError);
  151. $core.addClass('UnknownVariableError', $globals.SemanticError, ['variableName'], 'Compiler-Exceptions');
  152. //>>excludeStart("ide", pragmas.excludeIdeData);
  153. $globals.UnknownVariableError.comment="I get signaled when a variable is not defined.\x0aThe default behavior is to allow it, as this is how Amber currently is able to seamlessly send messages to JavaScript objects.";
  154. //>>excludeEnd("ide");
  155. $core.addMethod(
  156. $core.method({
  157. selector: "messageText",
  158. protocol: 'accessing',
  159. fn: function (){
  160. var self=this;
  161. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  162. return $core.withContext(function($ctx1) {
  163. //>>excludeEnd("ctx");
  164. var $1;
  165. $1=$recv("Unknown Variable error: ".__comma(self._variableName())).__comma(" is not defined");
  166. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  167. $ctx1.sendIdx[","]=1;
  168. //>>excludeEnd("ctx");
  169. return $1;
  170. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  171. }, function($ctx1) {$ctx1.fill(self,"messageText",{},$globals.UnknownVariableError)});
  172. //>>excludeEnd("ctx");
  173. },
  174. //>>excludeStart("ide", pragmas.excludeIdeData);
  175. args: [],
  176. source: "messageText\x0a\x09^ 'Unknown Variable error: ', self variableName, ' is not defined'",
  177. referencedClasses: [],
  178. //>>excludeEnd("ide");
  179. messageSends: [",", "variableName"]
  180. }),
  181. $globals.UnknownVariableError);
  182. $core.addMethod(
  183. $core.method({
  184. selector: "variableName",
  185. protocol: 'accessing',
  186. fn: function (){
  187. var self=this;
  188. var $1;
  189. $1=self["@variableName"];
  190. return $1;
  191. },
  192. //>>excludeStart("ide", pragmas.excludeIdeData);
  193. args: [],
  194. source: "variableName\x0a\x09^ variableName",
  195. referencedClasses: [],
  196. //>>excludeEnd("ide");
  197. messageSends: []
  198. }),
  199. $globals.UnknownVariableError);
  200. $core.addMethod(
  201. $core.method({
  202. selector: "variableName:",
  203. protocol: 'accessing',
  204. fn: function (aString){
  205. var self=this;
  206. self["@variableName"]=aString;
  207. return self;
  208. },
  209. //>>excludeStart("ide", pragmas.excludeIdeData);
  210. args: ["aString"],
  211. source: "variableName: aString\x0a\x09variableName := aString",
  212. referencedClasses: [],
  213. //>>excludeEnd("ide");
  214. messageSends: []
  215. }),
  216. $globals.UnknownVariableError);
  217. $core.addClass('RethrowErrorHandler', $globals.Object, [], 'Compiler-Exceptions');
  218. //>>excludeStart("ide", pragmas.excludeIdeData);
  219. $globals.RethrowErrorHandler.comment="This class is used in the commandline version of the compiler.\x0aIt uses the handleError: message of ErrorHandler for printing the stacktrace and throws the error again as JS exception.\x0aAs a result Smalltalk errors are not swallowd by the Amber runtime and compilation can be aborted.";
  220. //>>excludeEnd("ide");
  221. $core.addMethod(
  222. $core.method({
  223. selector: "basicSignal:",
  224. protocol: 'error handling',
  225. fn: function (anError){
  226. var self=this;
  227. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  228. return $core.withContext(function($ctx1) {
  229. //>>excludeEnd("ctx");
  230. throw anError;
  231. return self;
  232. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  233. }, function($ctx1) {$ctx1.fill(self,"basicSignal:",{anError:anError},$globals.RethrowErrorHandler)});
  234. //>>excludeEnd("ctx");
  235. },
  236. //>>excludeStart("ide", pragmas.excludeIdeData);
  237. args: ["anError"],
  238. source: "basicSignal: anError\x0a <throw anError>",
  239. referencedClasses: [],
  240. //>>excludeEnd("ide");
  241. messageSends: []
  242. }),
  243. $globals.RethrowErrorHandler);
  244. $core.addMethod(
  245. $core.method({
  246. selector: "handleError:",
  247. protocol: 'error handling',
  248. fn: function (anError){
  249. var self=this;
  250. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  251. return $core.withContext(function($ctx1) {
  252. //>>excludeEnd("ctx");
  253. self._basicSignal_(anError);
  254. return self;
  255. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  256. }, function($ctx1) {$ctx1.fill(self,"handleError:",{anError:anError},$globals.RethrowErrorHandler)});
  257. //>>excludeEnd("ctx");
  258. },
  259. //>>excludeStart("ide", pragmas.excludeIdeData);
  260. args: ["anError"],
  261. source: "handleError: anError\x0a self basicSignal: anError",
  262. referencedClasses: [],
  263. //>>excludeEnd("ide");
  264. messageSends: ["basicSignal:"]
  265. }),
  266. $globals.RethrowErrorHandler);
  267. });