Beispiel #1
0
IResource *ResourceSet::GetOpResource(vm::OpCode op, IValueType &vt) {
  // Remap.
  switch (op) {
  case vm::OP_LT:
  case vm::OP_LTE:
  case vm::OP_GTE:
    op = vm::OP_GT;
    break;
  case vm::OP_NE:
    op = vm::OP_EQ;
    break;
  default:
    break;
  }
  // Use default type value as the key.
  IValueType key_vt;
  if (!(op == vm::OP_CONCAT || op == vm::OP_BIT_RANGE ||
	op == vm::OP_LSHIFT || op == vm::OP_RSHIFT)) {
    key_vt = vt;
  }
  for (auto &res : resources_) {
    if (res.op == op && key_vt.GetWidth() == res.vt.GetWidth()) {
      return res.resource;
    }
  }
  ResourceEntry res;
  string rcn = GetResourceClassName(op);
  IResourceClass *rc =
    DesignUtil::FindResourceClass(tab_->GetModule()->GetDesign(), rcn);
  IResource *ires = new IResource(tab_, rc);
  tab_->resources_.push_back(ires);
  PopulateResourceDataType(op, vt, ires);
  res.op = op;
  res.vt = key_vt;
  return ires;
}
Beispiel #2
0
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CEffect
//  - prototype : bool Parse(CAdvancedParser* pParser)
//
//  - Purpose   : Parses an effect. The parser has only the text data of
//                the effect, not of the whole script.
//
// -----------------------------------------------------------------------------
bool CEffect::Parse(CAdvancedParser* pParser)
{
	assert(pParser);
	assert(pParser->Ready());

	// General info

	pParser->ResetPos();

	if(!pParser->ReadKeyFloat("#Begin", '=', &m_fBegin, CParser::SEARCH_WHOLEDATA)) return false;
	if(!pParser->ReadKeyFloat("#End",   '=', &m_fEnd,   CParser::SEARCH_WHOLEDATA)) return false;
	if(!pParser->ReadKeyInt  ("#Layer", '=', &m_nLayer, CParser::SEARCH_WHOLEDATA)) return false;

	// Resources

	int nError = 0;

	pParser->ResetPos();

	while(-1 != pParser->Find("#Resource", CParser::SEARCH_FROMCURPOS))
	{
		std::string strClass, strName, strValue;

		if(!pParser->ReadKeyString("#Name",  '=', &strName,  CParser::SEARCH_INCURLINE)) nError++;
		if(!pParser->ReadKeyString("#Class", '=', &strClass, CParser::SEARCH_INCURLINE)) nError++;
		if(!pParser->ReadKeyString("#Value", '=', &strValue, CParser::SEARCH_INCURLINE)) nError++;

		if(nError)
		{
			LOG.Write("\nERROR - CEffect::Parse(): Error parsing resource.");
			return false;
		}

		int i = GetResourceIndex(strName);

		if(i == -1)
		{
			LOG.Write("\nERROR - CEffect::Parse(): Resource \"%s\" doesn't belong to this effect.", strName.data());
			return false;
		}

		std::string strClassAux;
		GetResourceClassName(i, &strClassAux);

		if(strClassAux != strClass)
		{
			LOG.Write("\nERROR - CEffect::Parse(): Error parsing resource \"%s\". Class=%s (expected %s)", strName.data(), strClass.data(), strClassAux.data());
			return false;
		}

		if(!SetResourceValue(i, strValue))
		{
			LOG.Write("\nERROR - CEffect::Parse(): Error setting resource \"%s\" value.", strName.data());
			return false;
		}
	}

	// Variables

	pParser->ResetPos();

	while(-1 != pParser->Find("#Var", CParser::SEARCH_FROMCURPOS))
	{
		std::string strClass, strName;

		if(!pParser->ReadKeyString("#Name",  '=', &strName,  CParser::SEARCH_INCURLINE)) nError++;
		if(!pParser->ReadKeyString("#Class", '=', &strClass, CParser::SEARCH_INCURLINE)) nError++;
		
		if(nError)
		{
			LOG.Write("\nERROR - CEffect::Parse(): Error parsing var.");
			return false;
		}

		CVar* pVar = GetVar(strName);

		if(!pVar)
		{
			LOG.Write("\nERROR - CEffect::Parse(): Error parsing var. \"%s\" doesn't belong to this effect", strName.data());
			return false;
		}

		if(pVar->GetClassName() != strClass)
		{
			LOG.Write("\nERROR - CEffect::Parse(): Error parsing var \"%s\". Class=%s (expected %s)", strName.data(), strClass.data(), pVar->GetClassName().data());
			return false;
		}

		if(!pVar->Parse(pParser))
		{
			LOG.Write("\nERROR - CEffect::Parse(): Error parsing var \"%s\" (CVar::Parse() failed).", strName.data());
			return false;
		}
	}

	// Commands

	pParser->ResetPos();

	while(-1 != pParser->Find("#Command", CParser::SEARCH_FROMCURPOS))
	{
		std::string strCommand;
		float       fTime;

		if(!pParser->ReadStringBetweenChars('<', '>', &strCommand, CParser::SEARCH_INCURLINE, true)) nError++;
		if(!pParser->ReadKeyFloat ("#Time", '=', &fTime, CParser::SEARCH_INCURLINE)) nError++;

		if(nError)
		{
			LOG.Write("\nERROR - CEffect::Parse(): Error parsing command.");
			return false;
		}

		AddCommand(fTime, strCommand);
	}

	return true;
}