2
0

Compiler-Exceptions.js 7.8 KB

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