PageRenderTime 73ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/orc/error/compiletime/ExceptionCompileLogger.scala

https://github.com/laurenyew/cOrcS
Scala | 92 lines | 37 code | 13 blank | 42 comment | 8 complexity | 83862576926f9c0d4e11b3dab54c9de4 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. //
  2. // ExceptionCompileLogger.scala -- Scala class ExceptionCompileLogger
  3. // Project OrcScala
  4. //
  5. // $Id: ExceptionCompileLogger.scala 2933 2011-12-15 16:26:02Z jthywissen $
  6. //
  7. // Created by jthywiss on Jun 8, 2010.
  8. //
  9. // Copyright (c) 2011 The University of Texas at Austin. All rights reserved.
  10. //
  11. // Use and redistribution of this file is governed by the license terms in
  12. // the LICENSE file found in the project's top-level directory and also found at
  13. // URL: http://orc.csres.utexas.edu/license.shtml .
  14. //
  15. package orc.error.compiletime
  16. import orc.error.compiletime.CompileLogger.Severity
  17. import orc.ast.AST
  18. import scala.util.parsing.input.Position
  19. /** A CompileMessageRecorder that throws an exception on a message of
  20. * severity WARNING or higher.
  21. *
  22. * @author jthywiss
  23. */
  24. class ExceptionCompileLogger extends CompileLogger {
  25. private var maxSeverity = Severity.UNKNOWN;
  26. /* (non-Javadoc)
  27. * @see orc.error.compiletime.CompileLogger#beginProcessing(java.lang.String)
  28. */
  29. def beginProcessing(filename: String) {
  30. maxSeverity = Severity.UNKNOWN;
  31. }
  32. /* (non-Javadoc)
  33. * @see orc.error.compiletime.CompileLogger#endProcessing(java.lang.String)
  34. */
  35. def endProcessing(filename: String) {
  36. // Nothing needed
  37. }
  38. class GenericCompilationException(message: String) extends CompilationException(message)
  39. /* (non-Javadoc)
  40. * @see orc.error.compiletime.CompileLogger#recordMessage(Severity, int, String, Position, AST, Throwable)
  41. */
  42. def recordMessage(severity: Severity, code: Int, message: String, location: Position, astNode: AST, exception: Throwable) {
  43. maxSeverity = if (severity.ordinal() > maxSeverity.ordinal()) severity else maxSeverity
  44. if (severity.ordinal() >= Severity.WARNING.ordinal()) {
  45. if (exception != null) {
  46. throw exception;
  47. } else {
  48. // We don't have an exception to throw -- use our "fake" one
  49. val e = new GenericCompilationException(message)
  50. if (location != null) {
  51. e.setPosition(location)
  52. }
  53. throw e
  54. }
  55. } // else disregard
  56. }
  57. /* (non-Javadoc)
  58. * @see orc.error.compiletime.CompileLogger#recordMessage(Severity, int, String, Position, Throwable)
  59. */
  60. def recordMessage(severity: Severity, code: Int, message: String, location: Position, exception: Throwable) {
  61. recordMessage(severity, code, message, location, null, exception)
  62. }
  63. /* (non-Javadoc)
  64. * @see orc.error.compiletime.CompileLogger#recordMessage(Severity, int, String, Position, AST)
  65. */
  66. def recordMessage(severity: Severity, code: Int, message: String, location: Position, astNode: AST) {
  67. recordMessage(severity, code, message, location, astNode, null)
  68. }
  69. /* (non-Javadoc)
  70. * @see orc.error.compiletime.CompileLogger#recordMessage(orc.error.compiletime.CompileLogger.Severity, int, java.lang.String)
  71. */
  72. def recordMessage(severity: Severity, code: Int, message: String) {
  73. recordMessage(severity, code, message, null, null, null)
  74. }
  75. /* (non-Javadoc)
  76. * @see orc.error.compiletime.CompileLogger#getMaxSeverity()
  77. */
  78. def getMaxSeverity(): Severity = maxSeverity
  79. }