Compiler-Exceptions.js 7.7 KB

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