Ejemplo n.º 1
0
bool c_decfunc::analyze()
{
	/// Analyze the function "m_funcName"
	if( c_compiler::existsFunction(m_funcName.c_str(), "") == true || g_functions.find(m_funcName) != g_functions.end() )
	{
		cout << "Compilation error: The function \'" << m_funcName << "\' does already exists!" << endl;
		return false;
	}
	// Check if the parameters are of a legal type
	for(uint i = 0; i < m_paramName.size(); i++)
	{
		// Check that the parameter has a unique name
		if(c_compiler::getVariable(m_paramName[i].c_str(), "") || customVariables(m_paramName[i].c_str(), 1) != -1)
		{
			cout << "Compilation error: Parameter " << i+1 << " in function \'" << m_funcName << "\': \'" << m_paramName[i] << "\' does exists as a variable or parameter!" << endl;
			return false;
		}
		// Put the parameter name temporarily into the list
		if(m_paramType[i] == E_KW_INT) g_integers[1][m_paramName[i]] = 0;
		else if(m_paramType[i] == E_KW_FLOAT) g_floats[1][m_paramName[i]] = 0.0;
		else if(m_paramType[i] == E_KW_STRING) g_strings[1][m_paramName[i]] = "";
		else
		{
			// Check if the class the pointer points to exists
			if(c_compiler::existsClass(m_paramObjT[i].c_str()) != true)
			{
				cout << "Compilation error: Parameter " << i+1 << " of type \'" << m_paramObjT[i] << "\' in function \'" << m_funcName << "\' is illegal!" << endl;
				return false;
			}
			g_pointers[1][m_paramName[i]].m_class = m_paramObjT[i];
			g_pointers[1][m_paramName[i]].m_data  = NULL;
		}
	}
	// Analyze the function's statement sequence
	g_scope++;
	if(m_sequence->analyze() == false)
		return false;
	g_scope--;
	ast_erase(1);

	// Put the function temporary into the list
	g_functions.insert(pair<string, c_decfunc*>(m_funcName, this));
	return true;
}
Ejemplo n.º 2
0
// Resolve the default body to use for the given method, if any.
// Return the body to use, NULL if none found or BODY_ERROR on error.
static ast_t* resolve_default_body(ast_t* entity, ast_t* method,
  method_t* info, const char* name, bool concrete)
{
  assert(entity != NULL);
  assert(method != NULL);
  assert(info != NULL);
  assert(name != NULL);

  if(info->default_body_src_2 != NULL)
  {
    // Ambiguous body, store info for use by any types that provide this one
    assert(info->default_body_src_1 != NULL);

    ast_t* err = ast_childidx(method, 5);
    ast_t* body = ast_childidx(method, 6);

    // Ditch whatever body we have, if any
    ast_erase(body);

    ast_setdata(body, info->default_body_src_1);
    ast_setdata(err, info->default_body_src_2);

    if(!concrete)
      return NULL;

    ast_error(entity, "multiple possible bodies for method %s, local "
      "disambiguation required", name);
    ast_error(info->default_body_src_1, "one possible body here");
    ast_error(info->default_body_src_2, "another possible body here");
    return BODY_ERROR;
  }

  if(info->default_body_src_1 == NULL)  // No default body found
    return NULL;

  // We have a default body, use it
  assert(info->reified_default != NULL);
  info->body_donor = (ast_t*)ast_data(info->default_body_src_1);
  return ast_childidx(info->reified_default, 6);
}
Ejemplo n.º 3
0
void c_decfunc::call(vector<c_expression*> *params)
{
	/// Call the custom function
	/// (Note: Because there can be declared global variables AFTER this function's declaration, the function will take care of variables in this order: Built-in > global > local)
	g_scope++;

	// Add all the arguments for the call
	for(uint i = 0; i < params->size(); i++)
	{
		if(m_paramType[i] == E_KW_INT) g_integers[g_scope][m_paramName[i]] = params->at(i)->getReal();
		else if(m_paramType[i] == E_KW_FLOAT) g_floats[g_scope][m_paramName[i]] = params->at(i)->getReal();
		else if(m_paramType[i] == E_KW_STRING) g_strings[g_scope][m_paramName[i]] = params->at(i)->getText();
		else
		{
			g_pointers[g_scope][m_paramName[i]].m_class = "";
			g_pointers[g_scope][m_paramName[i]].m_data = NULL;
		}
	}
	// Call the function's statement sequence
	m_sequence->generate();
	ast_erase(g_scope);
	g_scope--;
}
Ejemplo n.º 4
0
static int 
astioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
{
    struct ast_softc *stp = dev->si_drv1;
    int error = 0;

    switch (cmd) {
    case MTIOCGET:
	{
	    struct mtget *g = (struct mtget *) addr;

	    bzero(g, sizeof(struct mtget));
	    g->mt_type = 7;
	    g->mt_density = 1;
	    g->mt_blksiz = stp->blksize;
	    g->mt_comp = stp->cap.compress;
	    g->mt_density0 = 0; g->mt_density1 = 0;
	    g->mt_density2 = 0; g->mt_density3 = 0;
	    g->mt_blksiz0 = 0; g->mt_blksiz1 = 0;
	    g->mt_blksiz2 = 0; g->mt_blksiz3 = 0;
	    g->mt_comp0 = 0; g->mt_comp1 = 0;
	    g->mt_comp2 = 0; g->mt_comp3 = 0;
	    break;	 
	}
    case MTIOCTOP:
	{	
	    int i;
	    struct mtop *mt = (struct mtop *)addr;

	    switch ((int16_t) (mt->mt_op)) {

	    case MTWEOF:
		for (i=0; i < mt->mt_count && !error; i++)
		    error = ast_write_filemark(stp, WF_WRITE);
		break;

	    case MTFSF:
		if (mt->mt_count)
		    error = ast_space(stp, SP_FM, mt->mt_count);
		break;

	    case MTBSF:
		if (mt->mt_count)
		    error = ast_space(stp, SP_FM, -(mt->mt_count));
		break;

	    case MTREW:
		error = ast_rewind(stp);
		break;

	    case MTOFFL:
		error = ast_load_unload(stp, SS_EJECT);
		break;

	    case MTNOP:
		error = ast_write_filemark(stp, 0);
		break;

	    case MTERASE:
		error = ast_erase(stp);
		break;

	    case MTEOD:
		error = ast_space(stp, SP_EOD, 0);
		break;

	    case MTRETENS:
		error = ast_load_unload(stp, SS_RETENSION | SS_LOAD);
		break;

	    case MTFSR:		
	    case MTBSR:
	    case MTCACHE:
	    case MTNOCACHE:
	    case MTSETBSIZ:
	    case MTSETDNSTY:
	    case MTCOMP:
	    default:
		error = EINVAL;
	    }
	    break;
	}
    case MTIOCRDSPOS:
	{
	    struct ast_readposition position;

	    if ((error = ast_read_position(stp, 0, &position)))
		break;
	    *(u_int32_t *)addr = position.tape;
	    break;
	}
    case MTIOCRDHPOS:
	{
	    struct ast_readposition position;

	    if ((error = ast_read_position(stp, 1, &position)))
		break;
	    *(u_int32_t *)addr = position.tape;
	    break;
	}
    case MTIOCSLOCATE:
	error = ast_locate(stp, 0, *(u_int32_t *)addr);
	break;
    case MTIOCHLOCATE:
	error = ast_locate(stp, 1, *(u_int32_t *)addr);
	break;
    default:
	error = ENOTTY;
    }
    return error;
}