PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/JavaScript/while.cs

#
C# | 85 lines | 60 code | 8 blank | 17 comment | 18 complexity | 83c9d5de0984be4730a7d7079c3e32bc MD5 | raw file
  1. // while.cs
  2. //
  3. // Copyright 2010 Microsoft Corporation
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Text;
  19. namespace Microsoft.Ajax.Utilities
  20. {
  21. public sealed class WhileNode : AstNode
  22. {
  23. public AstNode Condition { get; private set; }
  24. public Block Body { get; private set; }
  25. public WhileNode(Context context, JSParser parser, AstNode condition, AstNode body)
  26. : base(context, parser)
  27. {
  28. Condition = condition;
  29. Body = ForceToBlock(body);
  30. if (Condition != null) Condition.Parent = this;
  31. if (Body != null) Body.Parent = this;
  32. }
  33. public override void Accept(IVisitor visitor)
  34. {
  35. if (visitor != null)
  36. {
  37. visitor.Visit(this);
  38. }
  39. }
  40. public override IEnumerable<AstNode> Children
  41. {
  42. get
  43. {
  44. return EnumerateNonNullNodes(Condition, Body);
  45. }
  46. }
  47. public override bool ReplaceChild(AstNode oldNode, AstNode newNode)
  48. {
  49. if (Condition == oldNode)
  50. {
  51. Condition = newNode;
  52. if (newNode != null) { newNode.Parent = this; }
  53. return true;
  54. }
  55. if (Body == oldNode)
  56. {
  57. Body = ForceToBlock(newNode);
  58. if (Body != null) { Body.Parent = this; }
  59. return true;
  60. }
  61. return false;
  62. }
  63. internal override bool RequiresSeparator
  64. {
  65. get
  66. {
  67. // requires a separator if the body does
  68. return Body == null || Body.Count == 0 ? false : Body.RequiresSeparator;
  69. }
  70. }
  71. internal override bool EncloseBlock(EncloseBlockType type)
  72. {
  73. // pass the query on to the body
  74. return Body == null ? false : Body.EncloseBlock(type);
  75. }
  76. }
  77. }