PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/Dependencies/boo/src/Boo.Lang.Compiler/CompilerWarning.cs

https://github.com/w4x/boolangstudio
C# | 115 lines | 76 code | 11 blank | 28 comment | 7 complexity | 28b2558203a364ede522de0ebc769389 MD5 | raw file
Possible License(s): GPL-2.0
  1. #region license
  2. // Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org)
  3. // All rights reserved.
  4. //
  5. // Redistribution and use in source and binary forms, with or without modification,
  6. // are permitted provided that the following conditions are met:
  7. //
  8. // * Redistributions of source code must retain the above copyright notice,
  9. // this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above copyright notice,
  11. // this list of conditions and the following disclaimer in the documentation
  12. // and/or other materials provided with the distribution.
  13. // * Neither the name of Rodrigo B. de Oliveira nor the names of its
  14. // contributors may be used to endorse or promote products derived from this
  15. // software without specific prior written permission.
  16. //
  17. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  21. // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. #endregion
  28. using System;
  29. using System.Text;
  30. using Boo.Lang.Compiler.Ast;
  31. namespace Boo.Lang.Compiler
  32. {
  33. /// <summary>
  34. /// A compilation error.
  35. /// </summary>
  36. [Serializable]
  37. public class CompilerWarning
  38. {
  39. string _code;
  40. string _message;
  41. LexicalInfo _lexicalInfo;
  42. public CompilerWarning(LexicalInfo lexicalInfo, string message)
  43. {
  44. if (null == message)
  45. {
  46. throw new ArgumentNullException("message");
  47. }
  48. _code = "BCW0000";
  49. _lexicalInfo = lexicalInfo;
  50. _message = Boo.Lang.ResourceManager.Format(_code, message);
  51. }
  52. public CompilerWarning(string message) : this(LexicalInfo.Empty, message)
  53. {
  54. }
  55. public CompilerWarning(string code, LexicalInfo lexicalInfo, params object[] args)
  56. {
  57. if (null == code)
  58. {
  59. throw new ArgumentNullException("code");
  60. }
  61. if (null == lexicalInfo)
  62. {
  63. throw new ArgumentNullException("lexicalInfo");
  64. }
  65. _code = code;
  66. _lexicalInfo = lexicalInfo;
  67. _message = Boo.Lang.ResourceManager.Format(code, args);
  68. }
  69. public string Message
  70. {
  71. get
  72. {
  73. return _message;
  74. }
  75. }
  76. public LexicalInfo LexicalInfo
  77. {
  78. get
  79. {
  80. return _lexicalInfo;
  81. }
  82. }
  83. public string Code
  84. {
  85. get
  86. {
  87. return _code;
  88. }
  89. }
  90. override public string ToString()
  91. {
  92. StringBuilder writer = new StringBuilder();
  93. if (_lexicalInfo.Line > 0)
  94. {
  95. writer.Append(_lexicalInfo);
  96. writer.Append(": ");
  97. }
  98. writer.Append(_code);
  99. writer.Append(": ");
  100. writer.Append(_message);
  101. return writer.ToString();
  102. }
  103. }
  104. }