PageRenderTime 55ms CodeModel.GetById 38ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

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

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