Exemplo n.º 1
0
Arquivo: scope.c Projeto: gvx/deja
V new_global_scope(void)
{
	V sc = create_scope();
	Scope* scope = toScope(sc);
	scope->is_func_scope = false;
	scope->parent = NULL;
	scope->func = NULL;
	scope->file = NULL;
	scope->callname = NULL;
	scope->pc = NULL;
	scope->env = new_sized_dict(256);
	return sc;
}
Exemplo n.º 2
0
Arquivo: scope.c Projeto: gvx/deja
V new_file_scope_env(V file, V env)
{
	V sc = create_scope();
	Scope* scope = toScope(sc);
	scope->is_func_scope = true;
	scope->is_error_handler = false;
	scope->parent = add_ref(toFile(file)->global);
	scope->func = NULL;
	scope->file = add_ref(file);
	scope->callname = NULL;
	scope->pc = toFile(file)->code - 1;
	scope->env = env;
	return sc;
}
Exemplo n.º 3
0
Arquivo: scope.c Projeto: gvx/deja
V new_function_scope(V function, V callname)
{
	V sc = create_scope();
	Scope* scope = toScope(sc);
	scope->is_func_scope = true;
	scope->is_error_handler = false;
	scope->parent = add_ref(toFunc(function)->defscope);
	scope->func = add_ref(function);
	scope->file = add_ref(toScope(scope->parent)->file);
	scope->callname = callname == NULL ? NULL : add_ref(callname);
	scope->pc = toFunc(function)->start;
	scope->env = NULL;
	return sc;
}
Exemplo n.º 4
0
Arquivo: scope.c Projeto: gvx/deja
V new_scope(V parent)
{
	V sc = create_scope();
	Scope* pscope = toScope(parent);
	Scope* scope = toScope(sc);
	scope->is_func_scope = false;
	scope->is_error_handler = false;
	scope->parent = add_ref(parent);
	scope->func = pscope->func == NULL ? NULL : add_ref(pscope->func);
	scope->file = pscope->file == NULL ? NULL : add_ref(pscope->file);
	scope->callname = pscope->callname == NULL ? NULL : add_ref(pscope->callname);
	scope->pc = pscope->pc;
	scope->linenr = pscope->linenr;
	scope->env = NULL;
	return sc;
}
Exemplo n.º 5
0
t_state *new_state(void)
{
	t_state *state;

	state = calloc(1, sizeof(*state));
	if (state == NULL)
	{
		return NULL;
	}

	state->environ = NULL;
	state->variables = create_scope(NULL, g_global_scope);
	state->last_exit_code = 0;
	state->exiting = NOT_EXITING;

	return state;
}
Exemplo n.º 6
0
TEST(ResolveField, empty) {
  g_redex = new RedexContext();
  create_scope();

  // different cases for int A.f1
  DexField* fdef = DexField::get_field(DexType::get_type("A"),
      DexString::get_string("f1"), DexType::get_type("I"));
  EXPECT_TRUE(fdef != nullptr && fdef->is_def());
  DexField* fref = make_field_ref(
      DexType::get_type("A"), "f1", DexType::get_type("I"));
  EXPECT_TRUE(fdef->is_def());
  EXPECT_TRUE(resolve_field(fref) == fdef);
  EXPECT_TRUE(resolve_field(fref, FieldSearch::Instance) == fdef);
  EXPECT_TRUE(resolve_field(DexType::get_type("A"),
      DexString::get_string("f1"),
      DexType::get_type("I"),
      FieldSearch::Static) == nullptr);
  EXPECT_TRUE(resolve_field(DexType::get_type("D"),
      DexString::get_string("f1"),
      DexType::get_type("I"),
      FieldSearch::Static) == nullptr);
  EXPECT_TRUE(resolve_field(DexType::get_type("B"),
      DexString::get_string("f1"),
      DexType::get_type("I"),
      FieldSearch::Instance) == fdef);
  EXPECT_TRUE(resolve_field(DexType::get_type("B"),
      DexString::get_string("f1"),
      DexType::get_type("I"),
      FieldSearch::Static) == nullptr);
  EXPECT_TRUE(resolve_field(DexType::get_type("C"),
      DexString::get_string("f1"),
      DexType::get_type("I")) == fdef);
  EXPECT_TRUE(resolve_field(DexType::get_type("C"),
      DexString::get_string("f1"),
      DexType::get_type("I"),
      FieldSearch::Static) == nullptr);
  fref = make_field_ref(
      DexType::get_type("B"), "f1", DexType::get_type("I"));
  EXPECT_FALSE(fref->is_def());
  EXPECT_TRUE(resolve_field(fref) == fdef);
  EXPECT_TRUE(resolve_field(fref, FieldSearch::Instance) == fdef);
  EXPECT_TRUE(resolve_field(fref, FieldSearch::Static) == nullptr);
  fref = make_field_ref(
      DexType::get_type("C"), "f1", DexType::get_type("I"));
  EXPECT_FALSE(fref->is_def());
  EXPECT_TRUE(resolve_field(fref) == fdef);
  EXPECT_TRUE(resolve_field(fref, FieldSearch::Instance) == fdef);
  EXPECT_TRUE(resolve_field(fref, FieldSearch::Static) == nullptr);

  // different cases for static String B.f2
  fdef = DexField::get_field(DexType::get_type("B"),
      DexString::get_string("f2"), DexType::get_type("Ljava/lang/String;"));
  EXPECT_TRUE(fdef != nullptr && fdef->is_def());
  fref = make_field_ref(
      DexType::get_type("A"), "f2", DexType::get_type("Ljava/lang/String;"));
  EXPECT_FALSE(fref->is_def());
  EXPECT_TRUE(resolve_field(fref) == nullptr);
  EXPECT_TRUE(resolve_field(fref, FieldSearch::Instance) == nullptr);
  EXPECT_TRUE(resolve_field(fref, FieldSearch::Static) == nullptr);
  fref = make_field_ref(
      DexType::get_type("B"), "f2", DexType::get_type("Ljava/lang/String;"));
  EXPECT_TRUE(fref->is_def());
  EXPECT_TRUE(resolve_field(fref) == fdef);
  EXPECT_TRUE(resolve_field(fref, FieldSearch::Instance) == fdef);
  fref = make_field_ref(
      DexType::get_type("C"), "f2", DexType::get_type("Ljava/lang/String;"));
  EXPECT_FALSE(fref->is_def());
  EXPECT_TRUE(resolve_field(fref) == fdef);
  EXPECT_TRUE(resolve_field(fref, FieldSearch::Static) == fdef);
  EXPECT_TRUE(resolve_field(fref, FieldSearch::Instance) == nullptr);

  // different cases for D.f
  fdef = DexField::get_field(DexType::get_type("D"),
      DexString::get_string("f"), DexType::get_type("A"));
  EXPECT_TRUE(fdef != nullptr && fdef->is_def());
  EXPECT_TRUE(resolve_field(fdef) == fdef);
  EXPECT_TRUE(resolve_field(fdef, FieldSearch::Instance) == fdef);

  // random non existent field
  fdef = DexField::make_field(DexType::get_type("U"),
      DexString::get_string("f"), DexType::get_type("I"));
  EXPECT_FALSE(fdef->is_def());
  EXPECT_TRUE(resolve_field(fdef) == nullptr);
  EXPECT_TRUE(resolve_field(fdef, FieldSearch::Instance) == nullptr);
  EXPECT_TRUE(resolve_field(fdef, FieldSearch::Static) == nullptr);
  EXPECT_TRUE(resolve_field(DexType::get_type("E"),
      DexString::get_string("f1"),
      DexType::get_type("I"),
      FieldSearch::Static) == nullptr);
  EXPECT_TRUE(resolve_field(DexType::get_type("E"),
      DexString::get_string("f1"),
      DexType::get_type("Ljava/lang/String;"),
      FieldSearch::Instance) == nullptr);
  EXPECT_TRUE(resolve_field(DexType::get_type("E"),
      DexString::get_string("f1"),
      DexType::get_type("I")) == nullptr);

  delete g_redex;
}