Ejemplo n.º 1
0
static void loadVarImpl(const AstVar* var, uint16_t localId, uint16_t context, Bytecode* bc, AstNode* at) {
  VarType type = var->type();

  if (!isNumeric(type)) {
    throw TranslationException(at, "Wrong var reference type (only numbers are supported)");
  }

  loadVar(type, localId, context, bc);
}
Ejemplo n.º 2
0
AstVar* findVariable(const std::string& name, Scope* scope, AstNode* at) {
  AstVar* var = scope->lookupVariable(name);

  if (!var) {
    throw TranslationException(at, "Variable '%s' is not defined", name.c_str());
  }

  return var;
}
Ejemplo n.º 3
0
AstFunction* findFunction(const std::string& name, Scope* scope, AstNode* at) {
  AstFunction* function = scope->lookupFunction(name);

  if (!function) {
    throw TranslationException(at, "Function '%s' is not defined", name.c_str());
  }

  return function;
}
Ejemplo n.º 4
0
void castImpl(VarType from, VarType to, Bytecode* bc, AstNode* node) {
  if (from == VT_DOUBLE && to == VT_INT) {
    bc->addInsn(BC_D2I);
  } else if (from == VT_INT && to == VT_DOUBLE) {
    bc->addInsn(BC_I2D);
  } else if (from != to) {
    throw TranslationException(node, "Illegal type: expected -- %s, actual -- %s", 
                               typeToName(to), typeToName(from));
  }
}
Ejemplo n.º 5
0
size_t Translator::ReadFirstElement( const char* pszelem, 
		const tinyxml2::XMLElement& container, 
		bool bRequired,  size_t iDefault)
{
	const XMLElement* pchild = container.FirstChildElement(pszelem);
	if( pchild == NULL)
	{
		if( !bRequired)
			return iDefault;
		else
		{
			char buff[256];
			sprintf( "Cannot find required unsigned integer element %s in container %s", pszelem, container.Name());
			throw TranslationException(buff);
		}
	}
	else
	{
		return atol( pchild->GetText());
	}
}
Ejemplo n.º 6
0
bool Translator::ReadFirstElement( const char* pszelem, 
	const tinyxml2::XMLElement& container,  
	bool bRequired, bool bDefault)
{
	const XMLElement* pchild = container.FirstChildElement(pszelem);
	if( pchild == NULL)
	{
		if( !bRequired)
			return bDefault;
		else
		{
			char buff[256];
			sprintf( "Cannot find required boolean element %s in container %s", pszelem, container.Name());
			throw TranslationException(buff);
		}
	}
	else
	{
		return (strcmp( pchild->GetText(),"false")==0);
	}
}