Esempio n. 1
0
int tree_add_right(tree* my_tree, tree* adding)
{
	assert(my_tree != NULL);
	assert(adding != NULL);

	PRECOND(tree_check(my_tree -> head -> root, NULL) != TREE_CHECK_OK, TREE_BAD, "ADD LEFT ERROR: PRECONDITION FAILED\n");
	int tr_counter = 0;
	VERIFY1(tree_check(my_tree, &tr_counter) == TREE_CHECK_BAD, TREE_INJURED,	"# ADD RIGHT ERROR: [%08x] element, tree is broken\n", my_tree);
	tr_counter = 0;
	VERIFY1(tree_check(adding,  &tr_counter) == TREE_CHECK_BAD, TREE_ADD_INJURED,"# ADD RIGHT ERROR: [%08x] adding element, tree is broken\n", adding);

	if (my_tree -> right != NULL) return TREE_ALREADY_THERE;
	my_tree -> right = adding;
	
	if (adding -> papa != NULL)
	{
		if (adding -> papa -> left  == adding) adding -> papa -> left  = NULL;
		if (adding -> papa -> right == adding) adding -> papa -> right = NULL;
	}
	adding -> papa = my_tree;
	adding -> head = my_tree -> head;
	adding -> head -> size += tr_counter;
	assert(my_tree -> head);
	tree_save_head(adding, my_tree -> head);
	POSTCOND(tree_check(my_tree -> head -> root, NULL) != TREE_CHECK_OK, TREE_BAD, "ADD LEFT ERROR: POSTCONDITION FAILED\n");
	return TREE_OK;
}
Esempio n. 2
0
int tree_check(tree* my_tree, int* size) /*and function pointer, that checks value of tree, general*/
{
	assert(my_tree);
	if (size == NULL)
	{
		int _size = 0; 
		size = &_size;
	}

	if (*size > MAXTREE) RETURN_BAD(TREE_CHECK_OVERFLOW, "TREE CHECK: Size is out of range");
	if ( !((TR_V <= my_tree -> type) && (my_tree -> type <= TR_NONE)) )    RETURN_BAD1(TREE_CHECK_BAD_TYPE, "TREE CHECK: Invalid type of tree, got [%d]", my_tree -> type);
	if ( ((my_tree -> type == TR_V) || (my_tree -> type == TR_F) || (my_tree -> type == TR_STR))&&(strlen((char*)(my_tree -> value)) >= MAXLINE))
		RETURN_BAD(TREE_CHECK_STR_BROKEN, "TREE CHECK: String is broken");
	
	if ((my_tree -> right != NULL)&&(my_tree -> right -> papa != my_tree)) RETURN_BAD(TREE_CHECK_BAD_LINK, "TREE CHECK: Invalid linking, right - papa");
	if ((my_tree -> left  != NULL)&&(my_tree -> left  -> papa != my_tree)) RETURN_BAD(TREE_CHECK_BAD_LINK,  "TREE CHECK: Invalid linking, left - papa");

	if (my_tree -> head == NULL)										   RETURN_BAD(TREE_CHECK_NO_HEAD,	"TREE CHECK: No head pointer");
	if (my_tree -> head -> root == NULL)								   RETURN_BAD(TREE_CHECK_NO_ROOT,   "TREE CHECK: No root pointer in the head");

	int ret = TREE_CHECK_OK;
	if (my_tree -> right != NULL) ret = tree_check(my_tree -> right, size);
	if (ret != TREE_CHECK_OK) return ret;
	if (my_tree -> left  != NULL) ret = tree_check(my_tree -> left , size);
	if (ret != TREE_CHECK_OK) return ret;
	
	if ((my_tree -> left != NULL)&&(my_tree -> left == my_tree -> right)) RETURN_BAD(TREE_CHECK_BAD_LINK, "TREE CHECK: left and right pointers are the same");
	if ((my_tree -> left != NULL)&&(my_tree -> left == my_tree -> papa )) RETURN_BAD(TREE_CHECK_BAD_LINK, "TREE CHECK: left and papa pointers are the same");
	if ((my_tree -> papa != NULL)&&(my_tree -> papa == my_tree -> right)) RETURN_BAD(TREE_CHECK_BAD_LINK, "TREE CHECK: right and papa pointers are the same");

	if (size != NULL) (*size)++;
	return ret;
}
Esempio n. 3
0
int tree_burn(tree* my_tree, int type, ...)
{
	PRECOND(my_tree == NULL,		TREE_ARG_TREE_NULL,	"TREE INIT: argumented head pointer is NULL\n");
	//PRECOND((my_tree -> type != TR_NONE)||(my_tree -> value != NULL), TREE_BAD, "TREE UNIT: tree has been already initialized");
	int _size = 0;
	VERIFY(tree_check(my_tree, &_size) != TREE_CHECK_OK, TREE_BAD, "TREE INIT: Initialization failed, tree is not ok");
	va_list vl;
	va_start(vl, type);
	char* str = NULL;
	double val = 0;
	int int_val = 0;
	if (my_tree -> value)
	{
		DBG_FREE fprintf(stdout, "[%08x] tree.cpp, tree_burn, my_tree -> value\n", my_tree -> value);
		free(my_tree -> value);
		my_tree -> value = NULL;
	}

	switch (type)
	{
	case TR_V:
	case TR_STR:
	case TR_F:
		str = va_arg(vl, char*);
		VERIFY(strlen(str) >= MAXLINE, TREE_BAD, "TREE INIT: Argumented string is out of range");
		my_tree -> value = (void*)calloc(strlen(str) + 2, sizeof(char));
		assert(my_tree -> value);
		strcpy((char*)(my_tree -> value), str);

		break;
	case TR_N:
		val = va_arg(vl, double);
		my_tree -> value = (void*) calloc(1, sizeof(double));
		assert(my_tree -> value);
		*((double*)(my_tree -> value)) = val;
		break;
	case TR_SIGN:
	case TR_ASSN:
	case TR_CMP:
		int_val = va_arg(vl, int);
		my_tree -> value = (void*) calloc(1, sizeof(int));
		assert(my_tree -> value);
		*((int*)(my_tree -> value)) = int_val;
		break;
	default:
		break;
	}

	my_tree -> type = type;

	_size = 0;
	
	va_end(vl);
	POSTCOND(tree_check(my_tree, &_size) != TREE_CHECK_OK, TREE_BAD, "TREE INIT: Initialization failed, tree is not ok in the end");
	return TREE_OK;
}
Esempio n. 4
0
static eh_region
input_eh_region (struct lto_input_block *ib, struct data_in *data_in, int ix)
{
  enum LTO_tags tag;
  eh_region r;
  tag = streamer_read_record_start (ib);
  if (tag == LTO_null)
    return __null;
  r = ((struct eh_region_d *)(ggc_internal_cleared_alloc_stat (sizeof (struct eh_region_d) )));
  r->index = streamer_read_hwi (ib);
  r->outer = (eh_region) (intptr_t) streamer_read_hwi (ib);
  r->inner = (eh_region) (intptr_t) streamer_read_hwi (ib);
  switch (tag)
    {
      case LTO_ert_cleanup:
 {
   struct eh_catch_d *last_catch;
   r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in,
            &last_catch);
 }
 {
   tree l;
     add_type_for_runtime (((tree_check ((l), "../../../gcc-4.8~svn195526/gcc/lto-streamer-in.c", 346, __FUNCTION__, (TREE_LIST)))->list.value));
 }
    }
}
Esempio n. 5
0
static struct eh_catch_d *
lto_input_eh_catch_list (struct lto_input_block *ib, struct data_in *data_in,
    eh_catch *last_p)
{
  eh_catch first;
  enum LTO_tags tag;
  *last_p = first = __null;
  tag = streamer_read_record_start (ib);
  while (tag)
    {
      tree list;
      eh_catch n;
      n = ((struct eh_catch_d *)(ggc_internal_cleared_alloc_stat (sizeof (struct eh_catch_d) )));
      n->type_list = streamer_hooks.read_tree(ib, data_in);
      n->filter_list = streamer_hooks.read_tree(ib, data_in);
      n->label = streamer_hooks.read_tree(ib, data_in);
      for (list = n->filter_list; list; list = ((contains_struct_check ((list), (TS_COMMON), "../../../gcc-4.8~svn195526/gcc/lto-streamer-in.c", 275, __FUNCTION__))->common.chain))
 add_type_for_runtime (((tree_check ((list), "../../../gcc-4.8~svn195526/gcc/lto-streamer-in.c", 276, __FUNCTION__, (TREE_LIST)))->list.value));
      if (*last_p)
 (*last_p)->next_catch = n;
      n->prev_catch = *last_p;
      *last_p = n;
      if (first == __null)
 first = n;
      tag = streamer_read_record_start (ib);
    }
  return first;
}
Esempio n. 6
0
static int
queue_ram_envelope_create(uint32_t msgid, const char *buf, size_t len,
    uint64_t *evpid)
{
	struct qr_envelope	*evp;
	struct qr_message	*msg;

	if ((msg = get_message(msgid)) == NULL)
		return (0);

	do {
		*evpid = queue_generate_evpid(msgid);
	} while (tree_check(&msg->envelopes, *evpid));
	evp = calloc(1, sizeof *evp);
	if (evp == NULL) {
		log_warn("warn: queue-ram: calloc");
		return (0);
	}
	evp->len = len;
	evp->buf = malloc(len);
	if (evp->buf == NULL) {
		log_warn("warn: queue-ram: malloc");
		free(evp);
		return (0);
	}
	memmove(evp->buf, buf, len);
	tree_xset(&msg->envelopes, *evpid, evp);
	stat_increment("queue.ram.envelope.size", len);
	return (1);
}
Esempio n. 7
0
int
main(int argc, char **argv)
{
   char *fnm1, *fnm2;
   const char *survey = NULL;

   msg_init(argv);

   cmdline_set_syntax_message(/*FILE1 FILE2 [THRESHOLD]*/218,
			      /*FILE1 and FILE2 can be .pos or .3d files\nTHRESHOLD is the max. ignorable change along any axis in metres (default %s)*/255,
			      STRING(DFLT_MAX_THRESHOLD));
   cmdline_init(argc, argv, short_opts, long_opts, NULL, help, 2, 3);
   while (1) {
      int opt = cmdline_getopt();
      if (opt == EOF) break;
      if (opt == 's') survey = optarg;
   }
   fnm1 = argv[optind++];
   fnm2 = argv[optind++];
   if (argv[optind]) {
      optarg = argv[optind];
      threshold = cmdline_double_arg();
   }

   tree_init();

   old_separator = parse_file(fnm1, survey, tree_insert);

   new_separator = parse_file(fnm2, survey, tree_remove);

   return tree_check() ? EXIT_FAILURE : EXIT_SUCCESS;
}
Esempio n. 8
0
static void set_lattice_value (tree var, prop_value_t new_val) {
  prop_value_t *old_val = &const_val[(tree_check ((var), "",
						  0, "",
						  (SSA_NAME)))->base.u.version];
  canonicalize_float_value (&new_val);
  canonicalize_float_value (old_val);
}
Esempio n. 9
0
int tree_print_elem_value(FILE* strout, tree* my_tree, char* extra_space)
{
	VERIFY(my_tree		== NULL, TREE_ARG_TREE_NULL,  "PRINT TREE ELEMENT: Argumented tree pointer is NULL");
	VERIFY(strout		== NULL, TREE_ARG_TREE_NULL,  "PRINT TREE ELEMENT: Argumented file stream is NULL" );
	VERIFY(extra_space	== NULL, TREE_ARG_TREE_NULL,  "PRINT TREE ELEMENT: Argumented space is NULL"       );
	int _size = 0;
	VERIFY(tree_check(my_tree, &_size) != TREE_CHECK_OK, TREE_INJURED, "PRINT TREE ELEMENT: Tree is not OK");
	
	fprintf(strout,"[%s", tree_types_strings[my_tree -> type - TR_V]);

	switch (my_tree -> type)
	{
	case TR_V:
	case TR_STR:
	case TR_F:
		fprintf(strout, " | %s", (char*)(my_tree -> value));
		break;
	case TR_SIGN:
		fprintf(strout, " | %c", (char)(*(int*)(my_tree -> value)));
		break;
	case TR_ASSN:
	case TR_CMP:
		fprintf(strout, " | %d", *(int*)(my_tree -> value));
		break;
	case TR_N:
		fprintf(strout, " | %lg", *((double*)(my_tree -> value)) );
		break;
	default:
		break;
	}
	fputc(']', strout);
	fprintf(strout, "%s", extra_space);
	return TREE_OK;
	
	/*
	switch (my_tree -> type)
	{
	case '8':
		fprintf(strout, "%lg%s", my_tree -> value, extra_space);
		break;
	case '+':
	case '-':
	case '*':
	case '/':
		fprintf(strout, "%c%s", my_tree -> type, extra_space);
		break;
	default:
		return TREE_UNEXPECTED_TYPE;
	}
	return TREE_OK;
	*/
}
Esempio n. 10
0
static void
input_function (tree fn_decl, struct data_in *data_in,
  struct lto_input_block *ib)
{
  struct function *fn;
  enum LTO_tags tag;
  fn = ((tree_check ((fn_decl), "../../../gcc-4.8~svn195526/gcc/lto-streamer-in.c", 807, __FUNCTION__, (FUNCTION_DECL)))->function_decl.f);
  tag = streamer_read_record_start (ib);
  input_struct_function_base (fn, data_in, ib);
  input_ssa_names (ib, data_in, fn);
  input_eh_regions (ib, data_in, fn);
  ((contains_struct_check ((fn_decl), (TS_DECL_COMMON), "../../../gcc-4.8~svn195526/gcc/lto-streamer-in.c", 823, __FUNCTION__))->decl_common.initial) = streamer_hooks.read_tree(ib, data_in);
}
Esempio n. 11
0
int tree_dump(FILE* strout, tree_head* my_head)
{
	if (strout == NULL) strout = strerr;
	assert(strout);
	VERIFY(my_head == NULL, TREE_BAD, "TREE HEAD ERROR: head pointer is NULL\n");

	fprintf(strout, "Dump of tree - [%08x], size - %d\n", my_head, my_head -> size);
	int tree_size = 0;
	fprintf(strout, "I'm %s\n", (tree_check(my_head -> root, &tree_size) == TREE_CHECK_OK && my_head -> size == tree_size)? "OK" : "BAD");
	fprintf(strout, "Counted size = %d\n", tree_size);
	fprintf(strout, "Calling recursive in-order dump of tree root...\n\n");

	tree_dump_in_order(strout, my_head -> root, "");

	fprintf(strout, "End of tree dump\n");
	
	return TREE_OK;
}
Esempio n. 12
0
static int
queue_ram_message_create(uint32_t *msgid)
{
	struct qr_message	*msg;

	msg = calloc(1, sizeof(*msg));
	if (msg == NULL) {
		log_warn("warn: queue-ram: calloc");
		return (0);
	}
	tree_init(&msg->envelopes);

	do {
		*msgid = queue_generate_msgid();
	} while (tree_check(&messages, *msgid));

	tree_xset(&messages, *msgid, msg);

	return (1);
}
Esempio n. 13
0
void
check_function_format (tree attrs, int nargs, tree * argarray)
{
  tree a;
  for (a = attrs;
       a;
       ((contains_struct_check
	 ((a), (TS_COMMON), "../../git-master/gcc/c-family/c-format.c", 1002,
	  __FUNCTION__))->common.chain))
    {
      if (is_attribute_p
	  ("format",
	   ((tree_check
	     ((a), "../../git-master/gcc/c-family/c-format.c", 1004,
	      __FUNCTION__, (TREE_LIST)))->list.purpose)))
	{
	  function_format_info info;
	  {
	    tree params = (tree) __null;
	    check_format_info (&info, params);
	  }
	}
    }
}
Esempio n. 14
0
int tree_optimize(FILE* strout, tree_head* syntax_tree)
{
	fprintf(strout, "\n\nOptimizing...........\n");
	bool is_optimized = false;
	int ret = tree_optimize(syntax_tree -> root, &is_optimized);
	int _size = 0;
	ret = tree_check(syntax_tree -> root, &_size);
	
	VERIFY(ret == SNTX_DIV_BY_ZERO, 0, "MAIN: There's division by zero");
	

	while (is_optimized == true)
	{
		is_optimized = false;
		ret = tree_optimize(syntax_tree -> root, &is_optimized);
		VERIFY(ret == SNTX_DIV_BY_ZERO, 0, "MAIN: There's division by zero");

	}
	fprintf(strout, "\n\nDONE!\n");
	
	tree_dump(strout, syntax_tree);

	return CPLR_OK;
}
Esempio n. 15
0
int tree_delete(tree* my_tree, int side)
{
	int _size = 0;
	VERIFY(my_tree == NULL,	TREE_BAD, "TREE DELETE: Argumented tree pointer is null");
	VERIFY(tree_check(my_tree -> head -> root, &_size) != TREE_CHECK_OK, TREE_BAD, "TREE DELETE: Tree is not ok");
	VERIFY(my_tree -> papa == NULL, TREE_BAD, "TREE DELETE: Argumented tree must have papa");
	
	int ret = 0;
	int temp_ret = TREE_OK;

	int type = my_tree -> type;

	if (type == TR_V || type == TR_F || type == TR_STR || type == TR_N || type == TR_ASSN || type == TR_SIGN || type == TR_CMP)
	{
		DBG_FREE fprintf(stdout, "[%08x] tree.cpp, tree_delete, my_tree -> value\n", my_tree -> value);
		free(my_tree -> value);
		my_tree -> value = NULL;
	}

	tree* _temp = NULL;
	tree* root = my_tree -> head -> root;


	if (side == LEFT  && my_tree -> left != NULL) 
	{
		_temp = my_tree -> left;
		my_tree -> left -> papa = my_tree -> papa;
	}
	if (side == RIGHT && my_tree -> left != NULL) 
	{
		_temp = my_tree -> right;
		my_tree -> right -> papa = my_tree -> papa;
	}
	

	if (my_tree -> papa -> right == my_tree) my_tree -> papa -> right = _temp;
	if (my_tree -> papa -> left  == my_tree) my_tree -> papa -> left  = _temp;


	if (my_tree -> left  == _temp) my_tree -> left  = NULL;
	if (my_tree -> right == _temp) my_tree -> right = NULL;

	if (my_tree -> left  != NULL) 
	{
		ret = tree_destr(my_tree -> left);
		my_tree -> left = NULL;
		VERIFY(ret != TREE_OK, ret, "TREE DELETE: Tree hasn't been destroyed");
	}

	if (my_tree -> right != NULL) 
	{
		ret = tree_destr(my_tree -> right);
		my_tree -> right = NULL;
		VERIFY(ret != TREE_OK, ret, "TREE DELETE: Tree hasn't been destroyed");
	}


	my_tree -> left  = NULL;
	my_tree -> right = NULL;
	my_tree -> papa  = NULL;
	my_tree -> value = NULL;
	my_tree -> type  = POISON;
	my_tree -> head -> size -= 1;

	DBG_FREE fprintf(stdout, "[%08x] tree.cpp, tree_delete, my_tree\n", my_tree);
	free(my_tree);
	my_tree = NULL;

	_size = 0;
	VERIFY(tree_check(root, &_size) != TREE_CHECK_OK, TREE_BAD, "TREE DELETE: Tree injured in the end");
	return TREE_OK;

}