Ejemplo n.º 1
0
//==================================================================
bool ParamsFindP(	ParamList &params,
					const SymbolList &globalSymbols,
					DVec<Float3> &out_vectorP,
					int fromIdx )
{
	bool	gotP = false;

	for (size_t i=fromIdx; i < params.size(); i += 2)
	{
		DASSERT( params[i].type == Param::STR );

		const Symbol* pSymbol = globalSymbols.FindSymbol( params[i] );
		if ( pSymbol && pSymbol->IsName( "P" ) )
		{
			DASSTHROW( (i+1) < params.size(), "Invalid number of arguments" );
			
			const FltVec	&fltVec = params[ i+1 ].NumVec();
			
			DASSTHROW( (fltVec.size() % 3) == 0, "Invalid number of arguments" );
			
			out_vectorP.resize( fltVec.size() / 3 );

			for (size_t iv=0, id=0; iv < fltVec.size(); iv += 3)
				out_vectorP[id++] = Float3( &fltVec[ iv ] );

			return true;
		}
	}
	
	return false;
}
Ejemplo n.º 2
0
void c_cg::write_params(const ParamList& params) {
  if (params.size()) {
    get_pipe()('(');
    for (uint i = 0; i < params.size() - 1; ++i) {
      write_type(params[i].type);
      get_pipe()(',');
    }
    write_type(params.back().type);
    get_pipe()(')');
  } else {
    get_pipe()("(void)");
  }
}
Ejemplo n.º 3
0
//------------------------------------------------------------------------------
// Test for parameter list handling, using RiOption as a proxy.
//
RtVoid MockRenderer::Option(RtConstToken name, const ParamList& pList)
{
    CheckParams() << Req("Option") << name << pList;
    // Check that the parameter list token count is correct.  Note that the
    // formula used below assumes there's only one Req in the token stream.
    BOOST_CHECK_EQUAL(2*pList.size(), g_fixture->tokens.size() - 2);
}
Ejemplo n.º 4
0
//==================================================================
bool ParamsFindP(	ParamList &params,
					const SymbolList &globalSymbols,
					Float3	*pOut_vectorP,
					int	expectedN,
					int fromIdx )
{
	bool	gotP = false;
	
	for (size_t i=fromIdx; i < params.size(); i += 2)
	{
		DASSERT( params[i].type == Param::STR );
		
		const Symbol* pSymbol = globalSymbols.FindSymbol( params[i] );
		if ( pSymbol && pSymbol->IsName( "P" ) )
		{
			DASSTHROW( (i+1) < params.size(), "Invalid number of arguments" );
			
			const FltVec	&fltVec = params[ i+1 ].NumVec();

			DASSTHROW( (int)fltVec.size() == 3 * expectedN,
							"Invalid number of arguments."
							 " Expecting %i but it's %u", 3 * expectedN, fltVec.size() );

			DASSTHROW( (int)(fltVec.size() % 3) == 0,
							"Invalid number of arguments."
							 " Should be multiple of 3 but it's %u", fltVec.size() );

			size_t	srcN = fltVec.size();

			for (size_t si=0, di=0; si < srcN; si += 3, di += 1)
				pOut_vectorP[ di ] = Float3( &fltVec[ si ] );
			
			return true;
		}
	}
	
	return false;
}
void RecursiveDescentParser::matchParameters(FunctionEntry* fEntry, ParamList* &callerParams, Token tk) {
	if(fEntry->getEntryType()!=TableEntry::FUNCTION) return;
	
	int paramCount = 1;
	ParamList* declParams = fEntry->getParamaterList();
	
	ParamList::iterator j=callerParams->begin();

	for(ParamList::iterator i=declParams->begin();
		i!=declParams->end();
		++i)
	{
		if(j==callerParams->end()) {
			std::stringstream errorMsg;
			errorMsg << "Function '" << fEntry->getName() << "' does not take " 
				<< paramCount-1 << " parameter(s)";
			errorHandler(errorMsg.str(), tk);
			return;
		}
		
		if((*i)->getType() != (*j)->getType()) {
			std::stringstream errorMsg;
			errorMsg << "Parameter " << paramCount << " should be of type " 
				<< (((*i)->getType()==T_INT)? "'int'" : "'char'");
			errorHandler(errorMsg.str(), tk);
		} 
		
		if((*i)->getAttribute() != (*j)->getAttribute()) {
			std::stringstream errorMsg;
			errorMsg << "Parameter " << paramCount << " should "
				<< (((*i)->getAttribute()==VA_SIMPLE)? "not " : "")
				<< "be an array";
			errorHandler(errorMsg.str(), tk);
		}
		
		++paramCount;
		++j;
	}
	
	if(j!=callerParams->end()) {
		std::stringstream errorMsg;
		errorMsg << "Function '" << fEntry->getName() << "' only takes " 
			<< declParams->size() << " parameter(s)";
		errorHandler(errorMsg.str(), tk);
	}
}
Ejemplo n.º 6
0
//==================================================================
int FindParam( const char *pFindName,
			   u_int expectedType,
			   u_int altExpectedType,
			   int fromIdx,
			   ParamList &params )
{
	int n = (int)params.size() - 1;

	for (int i=fromIdx; i < n; i += 2)
	{
		DASSERT( params[i].type == Param::STR );

		if ( 0 == strcasecmp( pFindName, params[i] ) )
		{
			if ( params[i+1].type == expectedType ||
				 params[i+1].type == altExpectedType )
				return i+1;
			else
				return -1;
		}
	}

	return -1;
}