/xbmc/visualizations/Vortex/angelscript/angelscript/source/as_scriptnode.cpp

http://github.com/xbmc/xbmc · C++ · 149 lines · 90 code · 23 blank · 36 comment · 19 complexity · b6401dffef34085fbd61fbe96ae962ac MD5 · raw file

  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2007 Andreas Jonsson
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any
  6. damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any
  8. purpose, including commercial applications, and to alter it and
  9. redistribute it freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you
  11. must not claim that you wrote the original software. If you use
  12. this software in a product, an acknowledgment in the product
  13. documentation would be appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and
  15. must not be misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. The original version of this library can be located at:
  19. http://www.angelcode.com/angelscript/
  20. Andreas Jonsson
  21. andreas@angelcode.com
  22. */
  23. //
  24. // as_scriptnode.cpp
  25. //
  26. // A node in the script tree built by the parser for compilation
  27. //
  28. #include "as_scriptnode.h"
  29. #include "as_scriptengine.h"
  30. BEGIN_AS_NAMESPACE
  31. asCScriptNode::asCScriptNode(eScriptNode type)
  32. {
  33. nodeType = type;
  34. tokenType = ttUnrecognizedToken;
  35. tokenPos = 0;
  36. tokenLength = 0;
  37. parent = 0;
  38. next = 0;
  39. prev = 0;
  40. firstChild = 0;
  41. lastChild = 0;
  42. }
  43. void asCScriptNode::Destroy(asCScriptEngine *engine)
  44. {
  45. // Destroy all children
  46. asCScriptNode *node = firstChild;
  47. asCScriptNode *next;
  48. while( node )
  49. {
  50. next = node->next;
  51. node->Destroy(engine);
  52. node = next;
  53. }
  54. // Return the memory to the memory manager
  55. engine->memoryMgr.FreeScriptNode(this);
  56. }
  57. void asCScriptNode::SetToken(sToken *token)
  58. {
  59. tokenType = token->type;
  60. }
  61. void asCScriptNode::UpdateSourcePos(size_t pos, size_t length)
  62. {
  63. if( pos == 0 && length == 0 ) return;
  64. if( tokenPos == 0 && tokenLength == 0 )
  65. {
  66. tokenPos = pos;
  67. tokenLength = length;
  68. }
  69. else
  70. {
  71. if( tokenPos > pos )
  72. {
  73. tokenLength = tokenPos + tokenLength - pos;
  74. tokenPos = pos;
  75. }
  76. if( pos + length > tokenPos + tokenLength )
  77. {
  78. tokenLength = pos + length - tokenPos;
  79. }
  80. }
  81. }
  82. void asCScriptNode::AddChildLast(asCScriptNode *node)
  83. {
  84. if( lastChild )
  85. {
  86. lastChild->next = node;
  87. node->next = 0;
  88. node->prev = lastChild;
  89. node->parent = this;
  90. lastChild = node;
  91. }
  92. else
  93. {
  94. firstChild = node;
  95. lastChild = node;
  96. node->next = 0;
  97. node->prev = 0;
  98. node->parent = this;
  99. }
  100. UpdateSourcePos(node->tokenPos, node->tokenLength);
  101. }
  102. void asCScriptNode::DisconnectParent()
  103. {
  104. if( parent )
  105. {
  106. if( parent->firstChild == this )
  107. parent->firstChild = next;
  108. if( parent->lastChild == this )
  109. parent->lastChild = prev;
  110. }
  111. if( next )
  112. next->prev = prev;
  113. if( prev )
  114. prev->next = next;
  115. parent = 0;
  116. next = 0;
  117. prev = 0;
  118. }
  119. END_AS_NAMESPACE