当前位置: 首页>>代码示例>>C++>>正文


C++ NodeBase::GetType方法代码示例

本文整理汇总了C++中NodeBase::GetType方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeBase::GetType方法的具体用法?C++ NodeBase::GetType怎么用?C++ NodeBase::GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NodeBase的用法示例。


在下文中一共展示了NodeBase::GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Evaluate

void Runtime::Evaluate(NodeBase* node,WQState* state)
{
	if (node->GetType() == NT_EXPRESSION)
	{
		ExpressionNode* expnode = (ExpressionNode*)node;
		Evaluate(expnode->Expression, state);
	}
	else if (node->GetType() == NT_ASSIGNMENT)
	{
		AssignmentNode* assignment = (AssignmentNode*)node; 
		//Evaluate the right side
		Evaluate((NodeBase*)assignment->RightSide, state);
		CurrentLineNumber = assignment->GetLineNumber();
		
		if (assignment->TargetType == AT_VARIABLE)
		{
			VariableNode* var = assignment->LeftSideVariable;
			Evaluate(var, state);
			WQObject* left =state->GetReturnObject();
			Evaluate(assignment->RightSide, state);
			PerformAssignment(left, assignment->AssignmentOperator, state->GetReturnObject());
			environment->SetVariable(*var->Value,left );

		}
		else if (assignment->TargetType == AT_ELEMENT)
		{
			ElementNode* ele = assignment->LeftSideElement;
			Evaluate(ele->Variable, state);
			WQObject* lsobj = state->GetReturnObject();
			if (lsobj->Type == DT_LIST)
			{
				Evaluate(ele->key, state);
				//get the index
				long index = state->GetReturnObject()->GetIntValue();

				WQObject *left = lsobj->GetListElement(index);
				Evaluate(assignment->RightSide, state);
				PerformAssignment(left, assignment->AssignmentOperator, state->GetReturnObject());
				lsobj->SetListElement(index,*left);
			}
			else if (lsobj->Type == DT_DICTIONARY)
			{

				Evaluate(ele->key, state);
				//get the index
				string key = state->GetReturnObject()->ToString();

				WQObject *left = lsobj->GetDictionaryElement(key);
				Evaluate(assignment->RightSide, state);
				PerformAssignment(left, assignment->AssignmentOperator, state->GetReturnObject());
				
			}
			//environment->GetVariable()

		}
	}
	else if (node->GetType() == NT_VARIABLE)
	{
		VariableNode* varnode = (VariableNode*)node;
		//
		//printf(varnode->Value->c_str());
		WQObject* obj=environment->GetVariable(*varnode->Value);
		if (obj == NULL)
		{
			state->ReturnReference(environment->CreateVariable(*(varnode->Value)));
		}
		else
		{
			state->ReturnReference(obj);
		}
	}
	//else if (node->GetType() == NT_ELEMENT)
	//{
	//	ElementNode* elenode = (ElementNode*)node;
	//	Evaluate(elenode->key, state);
	//	int index = state->GetReturnObject()->GetIntValue();
	//	WQObject* obj = environment->GetVariable(*elenode->Variable->Value)->GetListElement(index);
	//	state->ReturnReference(obj);
	//}
	else if (node->GetType() == NT_STRING)
	{
		StringNode* strnode = (StringNode*)node;
		state->GetReturnObject()->SetStringValue( *strnode->Value);

	}
	else if (node->GetType() == NT_BOOLEAN)
	{
		BooleanNode * boolnode = (BooleanNode*)node;
		state->GetReturnObject()->SetBoolValue(boolnode->Value);

	}
	else if (node->GetType() == NT_OPERATION)
	{
		
		OperationNode* opnode = (OperationNode*)node;
		//
		list<ExpressionNode*>::iterator expit = opnode->Terms->begin();
		list<string*>::iterator opit = opnode->Operators->begin();
		stack<string*> lowops;
		stack<WQObject*> lowexps;
//.........这里部分代码省略.........
开发者ID:gavinz0228,项目名称:WebQuest-Interpreter,代码行数:101,代码来源:Runtime.cpp


注:本文中的NodeBase::GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。