예제 #1
0
static bool verify_main_create(pass_opt_t* opt, ast_t* ast)
{
  if(ast_id(opt->check.frame->type) != TK_ACTOR)
    return true;

  ast_t* type_id = ast_child(opt->check.frame->type);

  if(strcmp(ast_name(type_id), "Main"))
    return true;

  AST_GET_CHILDREN(ast, cap, id, typeparams, params, result, can_error);
  ast_t* type = ast_parent(ast_parent(ast));

  if(strcmp(ast_name(id), "create"))
    return true;

  bool ok = true;

  if(ast_id(ast) != TK_NEW)
  {
    ast_error(opt->check.errors, ast,
      "the create method of the Main actor must be a constructor");
    ok = false;
  }

  if(ast_id(typeparams) != TK_NONE)
  {
    ast_error(opt->check.errors, typeparams,
      "the create constructor of the Main actor must not take type parameters");
    ok = false;
  }

  if(ast_childcount(params) != 1)
  {
    if(ast_pos(params) == ast_pos(type))
      ast_error(opt->check.errors, params,
        "The Main actor must have a create constructor which takes only a "
        "single Env parameter");
    else
      ast_error(opt->check.errors, params,
        "the create constructor of the Main actor must take only a single Env"
        "parameter");
    ok = false;
  }

  ast_t* param = ast_child(params);

  if(param != NULL)
  {
    ast_t* p_type = ast_childidx(param, 1);

    if(!is_env(p_type))
    {
      ast_error(opt->check.errors, p_type, "must be of type Env");
      ok = false;
    }
  }

  return ok;
}
예제 #2
0
void ft_replaceenv(t_env **env, char **split, char *newenv)
{
	int i;

	i = is_env(*env, split[0]);
	free((*env)->e[i]);
	(*env)->e[i] = NULL;
	(*env)->e[i] = ft_strdup(newenv);
}
예제 #3
0
void ft_unsetenv(t_env **env)
{
	int i;

	if (array_size((*env)->av) > 1)
	{
		if ((i = is_env(*env, (*env)->av[1])) != -1)
		{
			(*env)->e = ft_arrdel((*env)->e, i);
		}
	}
	else
		ft_putendl("error");
}
예제 #4
0
void ft_setenv(t_env **env)
{
	char **split;

	if (array_size((*env)->av) > 1)
		if (ft_strchr((*env)->av[1], '=') != NULL)
		{
			split = ft_strsplit((*env)->av[1], '=');
			if (is_env(*env, split[0]) != -1)
				ft_replaceenv(&(*env), split, (*env)->av[1]);
			else
				(*env)->e = ft_arradd((*env)->e, (*env)->av[1]);
		}
		else
		{
			if (is_env(*env, split[0]) == -1)
				{
					split[0] = ft_strjoin(split[0], "=");
					(*env)->e = ft_arradd((*env)->e, split[0]);
				}		
		}
	else
		ft_putendl("Usage : setenv KEY=VALUE");
}
예제 #5
0
파일: reference.c 프로젝트: Preetam/ponyc
static bool check_main_create(typecheck_t* t, ast_t* ast)
{
  if(ast_id(t->frame->type) != TK_ACTOR)
    return true;

  ast_t* type_id = ast_child(t->frame->type);

  if(strcmp(ast_name(type_id), "Main"))
    return true;

  AST_GET_CHILDREN(ast, cap, id, typeparams, params, result, can_error);

  if(strcmp(ast_name(id), "create"))
    return true;

  bool ok = true;

  if(ast_id(typeparams) != TK_NONE)
  {
    ast_error(typeparams,
      "the create constructor of a Main actor must not be polymorphic");
    ok = false;
  }

  if(ast_childcount(params) != 1)
  {
    ast_error(params,
      "the create constructor of a Main actor must take a single Env "
      "parameter");
    ok = false;
  }

  ast_t* param = ast_child(params);

  if(param != NULL)
  {
    ast_t* p_type = ast_childidx(param, 1);

    if(!is_env(p_type))
    {
      ast_error(p_type, "must be of type Env");
      ok = false;
    }
  }

  return ok;
}
예제 #6
0
파일: pre_exec.c 프로젝트: jmontija/21sh
void	define_arg_cmd(t_group *grp)
{
	int	i;

	i = 0;
	while (CMD(cmd_split) && CMD(cmd_split)[++i])
	{
		if (CMD(cmd_split)[i][0] == '-' &&
			grp->define_cmd[namenv] == false &&
			grp->define_cmd[utils] == false)
			grp->define_cmd[e_opt] = i;
		else if (is_env(CMD(cmd_split)[i]) > 0 &&
			grp->define_cmd[utils] == false)
			grp->define_cmd[namenv] = i;
		else
		{
			grp->define_cmd[utils] = i;
			break ;
		}
	}
}
예제 #7
0
파일: reference.c 프로젝트: Preetam/ponyc
static bool check_primitive_init(typecheck_t* t, ast_t* ast)
{
  if(ast_id(t->frame->type) != TK_PRIMITIVE)
    return true;

  AST_GET_CHILDREN(ast, cap, id, typeparams, params, result, can_error);

  if(strcmp(ast_name(id), "_init"))
    return true;

  bool ok = true;

  if(ast_id(ast_childidx(t->frame->type, 1)) != TK_NONE)
  {
    ast_error(ast, "a primitive with type parameters cannot have an _init");
    ok = false;
  }

  if(ast_id(ast) != TK_FUN)
  {
    ast_error(ast, "a primitive _init must be a function");
    ok = false;
  }

  if(ast_id(cap) != TK_BOX)
  {
    ast_error(cap, "a primitive _init must be box");
    ok = false;
  }

  if(ast_id(typeparams) != TK_NONE)
  {
    ast_error(typeparams, "a primitive _init must not be polymorphic");
    ok = false;
  }

  if(ast_childcount(params) != 1)
  {
    ast_error(params, "a primitive _init must take a single Env parameter");
    ok = false;
  }

  ast_t* param = ast_child(params);

  if(param != NULL)
  {
    ast_t* p_type = ast_childidx(param, 1);

    if(!is_env(p_type))
    {
      ast_error(p_type, "must be of type Env");
      ok = false;
    }
  }

  if(!is_none(result))
  {
    ast_error(result, "a primitive _init must return None");
    ok = false;
  }

  if(ast_id(can_error) != TK_NONE)
  {
    ast_error(can_error, "a primitive _init cannot raise an error");
    ok = false;
  }

  return ok;
}