1
0

Compiler-Exceptions.st 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. Smalltalk createPackage: 'Compiler-Exceptions'!
  2. Error subclass: #CompilerError
  3. instanceVariableNames: ''
  4. package: 'Compiler-Exceptions'!
  5. !CompilerError commentStamp!
  6. I am the common superclass of all compiling errors.!
  7. CompilerError subclass: #ParseError
  8. instanceVariableNames: ''
  9. package: 'Compiler-Exceptions'!
  10. !ParseError commentStamp!
  11. Instance of ParseError are signaled on any parsing error.
  12. See `Smalltalk >> #parse:`!
  13. CompilerError subclass: #SemanticError
  14. instanceVariableNames: ''
  15. package: 'Compiler-Exceptions'!
  16. !SemanticError commentStamp!
  17. I represent an abstract semantic error thrown by the SemanticAnalyzer.
  18. Semantic errors can be unknown variable errors, etc.
  19. See my subclasses for concrete errors.
  20. The IDE should catch instances of Semantic error to deal with them when compiling!
  21. SemanticError subclass: #InliningError
  22. instanceVariableNames: ''
  23. package: 'Compiler-Exceptions'!
  24. !InliningError commentStamp!
  25. Instances of InliningError are signaled when using an `InliningCodeGenerator`in a `Compiler`.!
  26. SemanticError subclass: #InvalidAssignmentError
  27. instanceVariableNames: 'variableName'
  28. package: 'Compiler-Exceptions'!
  29. !InvalidAssignmentError commentStamp!
  30. I get signaled when a pseudo variable gets assigned.!
  31. !InvalidAssignmentError methodsFor: 'accessing'!
  32. messageText
  33. ^ ' Invalid assignment to variable: ', self variableName
  34. !
  35. variableName
  36. ^ variableName
  37. !
  38. variableName: aString
  39. variableName := aString
  40. ! !
  41. SemanticError subclass: #ShadowingVariableError
  42. instanceVariableNames: 'variableName'
  43. package: 'Compiler-Exceptions'!
  44. !ShadowingVariableError commentStamp!
  45. I get signaled when a variable in a block or method scope shadows a variable of the same name in an outer scope.!
  46. !ShadowingVariableError methodsFor: 'accessing'!
  47. messageText
  48. ^ 'Variable shadowing error: ', self variableName, ' is already defined'
  49. !
  50. variableName
  51. ^ variableName
  52. !
  53. variableName: aString
  54. variableName := aString
  55. ! !
  56. SemanticError subclass: #UnknownVariableError
  57. instanceVariableNames: 'variableName'
  58. package: 'Compiler-Exceptions'!
  59. !UnknownVariableError commentStamp!
  60. I get signaled when a variable is not defined.
  61. The default behavior is to allow it, as this is how Amber currently is able to seamlessly send messages to JavaScript objects.!
  62. !UnknownVariableError methodsFor: 'accessing'!
  63. messageText
  64. ^ 'Unknown Variable error: ', self variableName, ' is not defined'
  65. !
  66. variableName
  67. ^ variableName
  68. !
  69. variableName: aString
  70. variableName := aString
  71. ! !
  72. Object subclass: #RethrowErrorHandler
  73. instanceVariableNames: ''
  74. package: 'Compiler-Exceptions'!
  75. !RethrowErrorHandler commentStamp!
  76. This class is used in the commandline version of the compiler.
  77. It uses the handleError: message of ErrorHandler for printing the stacktrace and throws the error again as JS exception.
  78. As a result Smalltalk errors are not swallowd by the Amber runtime and compilation can be aborted.!
  79. !RethrowErrorHandler methodsFor: 'error handling'!
  80. basicSignal: anError
  81. <throw anError>
  82. !
  83. handleError: anError
  84. super handleError: anError.
  85. self basicSignal: anError
  86. ! !