/NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/CastExpression.cs

http://github.com/icsharpcode/ILSpy · C# · 95 lines · 64 code · 11 blank · 20 comment · 5 complexity · cb64d2b43d205411855c41217e001502 MD5 · raw file

  1. // Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. namespace ICSharpCode.NRefactory.VB.Ast
  20. {
  21. /// <summary>
  22. /// CastType(Expression, AstType)
  23. /// </summary>
  24. public class CastExpression : Expression
  25. {
  26. public CastType CastType { get; set; }
  27. public VBTokenNode CastTypeToken {
  28. get { return GetChildByRole (Roles.Keyword); }
  29. }
  30. public AstType Type {
  31. get { return GetChildByRole (Roles.Type); }
  32. set { SetChildByRole (Roles.Type, value); }
  33. }
  34. public Expression Expression {
  35. get { return GetChildByRole (Roles.Expression); }
  36. set { SetChildByRole (Roles.Expression, value); }
  37. }
  38. public CastExpression ()
  39. {
  40. }
  41. public CastExpression (CastType castType, AstType castToType, Expression expression)
  42. {
  43. CastType = castType;
  44. AddChild (castToType, Roles.Type);
  45. AddChild (expression, Roles.Expression);
  46. }
  47. public CastExpression (CastType castType, Expression expression)
  48. {
  49. CastType = castType;
  50. AddChild (expression, Roles.Expression);
  51. }
  52. public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
  53. {
  54. return visitor.VisitCastExpression (this, data);
  55. }
  56. protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
  57. {
  58. CastExpression o = other as CastExpression;
  59. return o != null && this.CastType == o.CastType && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match);
  60. }
  61. }
  62. public enum CastType
  63. {
  64. DirectCast,
  65. TryCast,
  66. CType,
  67. CBool,
  68. CByte,
  69. CChar,
  70. CDate,
  71. CDec,
  72. CDbl,
  73. CInt,
  74. CLng,
  75. CObj,
  76. CSByte,
  77. CShort,
  78. CSng,
  79. CStr,
  80. CUInt,
  81. CULng,
  82. CUShort
  83. }
  84. }