2
0

Compiler-Exceptions.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. define("amber/Compiler-Exceptions", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber/Kernel-Exceptions"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Compiler-Exceptions');
  3. smalltalk.packages["Compiler-Exceptions"].transport = {"type":"amd","amdNamespace":"amber"};
  4. smalltalk.addClass('CompilerError', smalltalk.Error, [], 'Compiler-Exceptions');
  5. smalltalk.CompilerError.comment="I am the common superclass of all compiling errors.";
  6. smalltalk.addClass('ParseError', smalltalk.CompilerError, [], 'Compiler-Exceptions');
  7. smalltalk.ParseError.comment="Instance of ParseError are signaled on any parsing error.\x0aSee `Smalltalk >> #parse:`";
  8. smalltalk.addClass('SemanticError', smalltalk.CompilerError, [], 'Compiler-Exceptions');
  9. smalltalk.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";
  10. smalltalk.addClass('InliningError', smalltalk.SemanticError, [], 'Compiler-Exceptions');
  11. smalltalk.InliningError.comment="Instances of InliningError are signaled when using an `InliningCodeGenerator`in a `Compiler`.";
  12. smalltalk.addClass('InvalidAssignmentError', smalltalk.SemanticError, ['variableName'], 'Compiler-Exceptions');
  13. smalltalk.InvalidAssignmentError.comment="I get signaled when a pseudo variable gets assigned.";
  14. smalltalk.addMethod(
  15. smalltalk.method({
  16. selector: "messageText",
  17. category: 'accessing',
  18. fn: function (){
  19. var self=this;
  20. return smalltalk.withContext(function($ctx1) {
  21. var $1;
  22. $1=" Invalid assignment to variable: ".__comma(self._variableName());
  23. return $1;
  24. }, function($ctx1) {$ctx1.fill(self,"messageText",{},smalltalk.InvalidAssignmentError)})},
  25. args: [],
  26. source: "messageText\x0a\x09^ ' Invalid assignment to variable: ', self variableName",
  27. messageSends: [",", "variableName"],
  28. referencedClasses: []
  29. }),
  30. smalltalk.InvalidAssignmentError);
  31. smalltalk.addMethod(
  32. smalltalk.method({
  33. selector: "variableName",
  34. category: 'accessing',
  35. fn: function (){
  36. var self=this;
  37. return smalltalk.withContext(function($ctx1) {
  38. var $1;
  39. $1=self["@variableName"];
  40. return $1;
  41. }, function($ctx1) {$ctx1.fill(self,"variableName",{},smalltalk.InvalidAssignmentError)})},
  42. args: [],
  43. source: "variableName\x0a\x09^ variableName",
  44. messageSends: [],
  45. referencedClasses: []
  46. }),
  47. smalltalk.InvalidAssignmentError);
  48. smalltalk.addMethod(
  49. smalltalk.method({
  50. selector: "variableName:",
  51. category: 'accessing',
  52. fn: function (aString){
  53. var self=this;
  54. return smalltalk.withContext(function($ctx1) {
  55. self["@variableName"]=aString;
  56. return self}, function($ctx1) {$ctx1.fill(self,"variableName:",{aString:aString},smalltalk.InvalidAssignmentError)})},
  57. args: ["aString"],
  58. source: "variableName: aString\x0a\x09variableName := aString",
  59. messageSends: [],
  60. referencedClasses: []
  61. }),
  62. smalltalk.InvalidAssignmentError);
  63. smalltalk.addClass('ShadowingVariableError', smalltalk.SemanticError, ['variableName'], 'Compiler-Exceptions');
  64. smalltalk.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.";
  65. smalltalk.addMethod(
  66. smalltalk.method({
  67. selector: "messageText",
  68. category: 'accessing',
  69. fn: function (){
  70. var self=this;
  71. return smalltalk.withContext(function($ctx1) {
  72. var $1;
  73. $1=_st("Variable shadowing error: ".__comma(self._variableName())).__comma(" is already defined");
  74. return $1;
  75. }, function($ctx1) {$ctx1.fill(self,"messageText",{},smalltalk.ShadowingVariableError)})},
  76. args: [],
  77. source: "messageText\x0a\x09^ 'Variable shadowing error: ', self variableName, ' is already defined'",
  78. messageSends: [",", "variableName"],
  79. referencedClasses: []
  80. }),
  81. smalltalk.ShadowingVariableError);
  82. smalltalk.addMethod(
  83. smalltalk.method({
  84. selector: "variableName",
  85. category: 'accessing',
  86. fn: function (){
  87. var self=this;
  88. return smalltalk.withContext(function($ctx1) {
  89. var $1;
  90. $1=self["@variableName"];
  91. return $1;
  92. }, function($ctx1) {$ctx1.fill(self,"variableName",{},smalltalk.ShadowingVariableError)})},
  93. args: [],
  94. source: "variableName\x0a\x09^ variableName",
  95. messageSends: [],
  96. referencedClasses: []
  97. }),
  98. smalltalk.ShadowingVariableError);
  99. smalltalk.addMethod(
  100. smalltalk.method({
  101. selector: "variableName:",
  102. category: 'accessing',
  103. fn: function (aString){
  104. var self=this;
  105. return smalltalk.withContext(function($ctx1) {
  106. self["@variableName"]=aString;
  107. return self}, function($ctx1) {$ctx1.fill(self,"variableName:",{aString:aString},smalltalk.ShadowingVariableError)})},
  108. args: ["aString"],
  109. source: "variableName: aString\x0a\x09variableName := aString",
  110. messageSends: [],
  111. referencedClasses: []
  112. }),
  113. smalltalk.ShadowingVariableError);
  114. smalltalk.addClass('UnknownVariableError', smalltalk.SemanticError, ['variableName'], 'Compiler-Exceptions');
  115. smalltalk.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.";
  116. smalltalk.addMethod(
  117. smalltalk.method({
  118. selector: "messageText",
  119. category: 'accessing',
  120. fn: function (){
  121. var self=this;
  122. return smalltalk.withContext(function($ctx1) {
  123. var $1;
  124. $1=_st("Unknown Variable error: ".__comma(self._variableName())).__comma(" is not defined");
  125. return $1;
  126. }, function($ctx1) {$ctx1.fill(self,"messageText",{},smalltalk.UnknownVariableError)})},
  127. args: [],
  128. source: "messageText\x0a\x09^ 'Unknown Variable error: ', self variableName, ' is not defined'",
  129. messageSends: [",", "variableName"],
  130. referencedClasses: []
  131. }),
  132. smalltalk.UnknownVariableError);
  133. smalltalk.addMethod(
  134. smalltalk.method({
  135. selector: "variableName",
  136. category: 'accessing',
  137. fn: function (){
  138. var self=this;
  139. return smalltalk.withContext(function($ctx1) {
  140. var $1;
  141. $1=self["@variableName"];
  142. return $1;
  143. }, function($ctx1) {$ctx1.fill(self,"variableName",{},smalltalk.UnknownVariableError)})},
  144. args: [],
  145. source: "variableName\x0a\x09^ variableName",
  146. messageSends: [],
  147. referencedClasses: []
  148. }),
  149. smalltalk.UnknownVariableError);
  150. smalltalk.addMethod(
  151. smalltalk.method({
  152. selector: "variableName:",
  153. category: 'accessing',
  154. fn: function (aString){
  155. var self=this;
  156. return smalltalk.withContext(function($ctx1) {
  157. self["@variableName"]=aString;
  158. return self}, function($ctx1) {$ctx1.fill(self,"variableName:",{aString:aString},smalltalk.UnknownVariableError)})},
  159. args: ["aString"],
  160. source: "variableName: aString\x0a\x09variableName := aString",
  161. messageSends: [],
  162. referencedClasses: []
  163. }),
  164. smalltalk.UnknownVariableError);
  165. smalltalk.addClass('RethrowErrorHandler', smalltalk.ErrorHandler, [], 'Compiler-Exceptions');
  166. smalltalk.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.";
  167. smalltalk.addMethod(
  168. smalltalk.method({
  169. selector: "basicSignal:",
  170. category: 'error handling',
  171. fn: function (anError){
  172. var self=this;
  173. return smalltalk.withContext(function($ctx1) {
  174. throw anError;
  175. return self}, function($ctx1) {$ctx1.fill(self,"basicSignal:",{anError:anError},smalltalk.RethrowErrorHandler)})},
  176. args: ["anError"],
  177. source: "basicSignal: anError\x0a\x09<throw anError>",
  178. messageSends: [],
  179. referencedClasses: []
  180. }),
  181. smalltalk.RethrowErrorHandler);
  182. smalltalk.addMethod(
  183. smalltalk.method({
  184. selector: "handleError:",
  185. category: 'error handling',
  186. fn: function (anError){
  187. var self=this;
  188. return smalltalk.withContext(function($ctx1) {
  189. smalltalk.RethrowErrorHandler.superclass.fn.prototype._handleError_.apply(_st(self), [anError]);
  190. self._basicSignal_(anError);
  191. return self}, function($ctx1) {$ctx1.fill(self,"handleError:",{anError:anError},smalltalk.RethrowErrorHandler)})},
  192. args: ["anError"],
  193. source: "handleError: anError\x0a\x09super handleError: anError.\x0a\x09self basicSignal: anError",
  194. messageSends: ["handleError:", "basicSignal:"],
  195. referencedClasses: []
  196. }),
  197. smalltalk.RethrowErrorHandler);
  198. });