Example #1
0
	~CInstructions()
	{
		for(CArray<CInstruction *>::CIterator i = m_apList.GetIterator(); i.Exists(); i.Next())
			MEM_DELETE(i.Get());
	}
Example #2
0
void CElement::ExecInstructions(const CArray<CInstruction *> *papInstructions, const CParameters *paParameters,
								bool *pReturned, int *pReturnValue)
{
	*pReturned = false;
	for(CArray<CInstruction *>::CIterator i = papInstructions->GetIterator(); i.Exists(); i.Next())
	{
		if(m_Removed)
			break;

		CInstruction *pBaseInstr = i.Get();
		m_pDatabase->SetCurrentInstruction(pBaseInstr->m_LineCount, pBaseInstr->m_Filename);

		if(pBaseInstr->m_Type == INSTRUCTION_TYPE_SET_ATTRIBUTE)
		{
			CSetAttributeInstruction *pInstr = (CSetAttributeInstruction *)pBaseInstr;
			CAttribute *pAttribute = FindAttribute(pInstr->m_AttributeName);
			if(!pAttribute)
			{
				printf("error: unknown attribute '%s'\n", pInstr->m_AttributeName.GetString());
				m_pDatabase->PrintCallstack();
				continue;
			}
			if(pAttribute->m_Const && pAttribute->m_Defined)
			{
				printf("error: attribute const '%s' is already defined\n", pAttribute->m_pName);
				m_pDatabase->PrintCallstack();
			}
			else
			{
				pAttribute->m_Value = ComputeValue(pInstr->m_Value, paParameters);
				pAttribute->m_Defined = true;
#ifdef SPB_DEBUG
				printf("success: attribute '%s' set to %d\n", pAttribute->m_pName, pAttribute->m_Value);
#endif
			}
		}
		else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_RETURN)
		{
			CReturnInstruction *pInstr = (CReturnInstruction *)pBaseInstr;
			*pReturned = true;
			*pReturnValue = ComputeValue(pInstr->m_Value, paParameters);
#ifdef SPB_DEBUG
			printf("success: returned %d\n", *pReturnValue);
#endif
			return;
		}
		else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_IF)
		{
			CIfInstruction *pInstr = (CIfInstruction *)pBaseInstr;
			bool True = CheckIf(&pInstr->m_IfData, paParameters);
			if(True)
				ExecInstructions(&pInstr->m_IfData.m_Instructions.m_apList, paParameters, pReturned, pReturnValue);
			else
			{
				for(CArray<CIfData>::CIterator i = pInstr->m_aElsifDatas.GetIterator(); i.Exists(); i.Next())
				{
					CIfData *pElsifData = &i.Get();
					m_pDatabase->SetCurrentInstruction(pElsifData->m_LineCount, pBaseInstr->m_Filename);
					True = CheckIf(pElsifData, paParameters);
					if(True)
					{
						ExecInstructions(&pElsifData->m_Instructions.m_apList, paParameters, pReturned, pReturnValue);
						break;
					}
				}
				if(!True)
					ExecInstructions(&pInstr->m_InstructionsElse.m_apList, paParameters, pReturned, pReturnValue);
			}
			if(*pReturned)
				return;
		}
		else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_FROM)
		{
			CFromInstruction *pInstr = (CFromInstruction *)pBaseInstr;
			int StartVal = ComputeValue(pInstr->m_StartValue, paParameters);
			int EndVal = ComputeValue(pInstr->m_EndValue, paParameters);
#ifdef SPB_DEBUG
			printf("success: from %d to %d (reverse %d)\n", StartVal, EndVal, pInstr->m_Reverse);
#endif
			CParameters aFromParameters;
			paParameters->GetCopy(&aFromParameters);
			int *pNewParameter = &aFromParameters.Add();
			if(pInstr->m_Reverse)
			{
				for(int v = StartVal; v >= EndVal; v--)
				{
					*pNewParameter = v;
					ExecInstructions(&pInstr->m_Instructions.m_apList, &aFromParameters, pReturned, pReturnValue);
					if(*pReturned)
						return;
				}
			}
			else
			{
				for(int v = StartVal; v <= EndVal; v++)
				{
					*pNewParameter = v;
					ExecInstructions(&pInstr->m_Instructions.m_apList, &aFromParameters, pReturned, pReturnValue);
					if(*pReturned)
						return;
				}
			}
		}
		else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_CALL_FUNCTION)
		{
			CCallFunctionInstruction *pInstr = (CCallFunctionInstruction *)pBaseInstr;

			CParameters aFunctionParameters;
			for(CArray<CExpression>::CIterator p = pInstr->m_aFunctionParameters.GetIterator(); p.Exists(); p.Next())
				aFunctionParameters.Add(ComputeValue(p.Get(), paParameters));

			if(pInstr->m_This)
				CallFunction(pInstr->m_FunctionName, &aFunctionParameters);
			else if(pInstr->m_Super)
				CallFunction(pInstr->m_FunctionName, &aFunctionParameters, true, pInstr->m_Superclass);
			else
			{
				CParameters aSearchParameters;
				for(CArray<CExpression>::CIterator p = pInstr->m_aSearchParameters.GetIterator(); p.Exists(); p.Next())
					aSearchParameters.Add(ComputeValue(p.Get(), paParameters));

				CArray<CElement *> apElements;
				m_pDatabase->SearchElements(pInstr->m_ElementType, pInstr->m_ElementModelName, pInstr->m_SearchFunction, &aSearchParameters, &apElements);

				for(CArray<CElement *>::CIterator e = apElements.GetIterator(); e.Exists(); e.Next())
				{
					if(!e.Get()->m_Removed)
						e.Get()->CallFunction(pInstr->m_FunctionName, &aFunctionParameters);
				}
			}
		}
		else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_REMOVE)
		{
			CRemoveInstruction *pInstr = (CRemoveInstruction *)pBaseInstr;
			if(pInstr->m_This)
				m_pDatabase->RemoveElement(this);
			else
			{
				CParameters aSearchParameters;
				for(CArray<CExpression>::CIterator p = pInstr->m_aSearchParameters.GetIterator(); p.Exists(); p.Next())
					aSearchParameters.Add(ComputeValue(p.Get(), paParameters));

				CArray<CElement *> apElements;
				m_pDatabase->SearchElements(pInstr->m_ElementType, pInstr->m_ElementModelName, pInstr->m_SearchFunction, &aSearchParameters, &apElements);

				bool DeleteThis = false;
				for(CArray<CElement *>::CIterator e = apElements.GetIterator(); e.Exists(); e.Next())
				{
					CElement *pElement = e.Get();
					if(pElement->m_Removed)
						continue;
					if(pElement == this)
						DeleteThis = true;
					else
						m_pDatabase->RemoveElement(pElement);
				}
				if(DeleteThis)
					m_pDatabase->RemoveElement(this);
			}
		}
		else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_ADD)
		{
			CAddInstruction *pInstr = (CAddInstruction *)pBaseInstr;
			CParameters aAddParameters;
			for(CArray<CExpression>::CIterator p = pInstr->m_aAddParameters.GetIterator(); p.Exists(); p.Next())
				aAddParameters.Add(ComputeValue(p.Get(), paParameters));
			m_pDatabase->AddElement(pInstr->m_ElementType, pInstr->m_ElementModelName, &aAddParameters);
		}
		else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_CALL_SYS)
		{
			CCallSysInstruction *pInstr = (CCallSysInstruction *)pBaseInstr;

			CParameters aFunctionParameters;
			for(CArray<CExpression>::CIterator p = pInstr->m_aFunctionParameters.GetIterator(); p.Exists(); p.Next())
				aFunctionParameters.Add(ComputeValue(p.Get(), paParameters));

			m_pDatabase->CallSysFunction(pInstr->m_FunctionName, &aFunctionParameters);
		}
	}
}
Example #3
0
	~CElementModelsGroup()
	{
		for(CArray<CElementModel *>::CIterator e = m_apList.GetIterator(); e.Exists(); e.Next())
			MEM_DELETE(e.Get());
	}