static struct demangle_component *
unqualified_name_from_comp (struct demangle_component *comp)
{
  struct demangle_component *ret_comp = comp, *last_template;
  int done;

  done = 0;
  last_template = NULL;
  while (!done)
    switch (ret_comp->type)
      {
      case DEMANGLE_COMPONENT_QUAL_NAME:
      case DEMANGLE_COMPONENT_LOCAL_NAME:
        ret_comp = d_right (ret_comp);
        break;
      case DEMANGLE_COMPONENT_TYPED_NAME:
        ret_comp = d_left (ret_comp);
        break;
      case DEMANGLE_COMPONENT_TEMPLATE:
	gdb_assert (last_template == NULL);
	last_template = ret_comp;
	ret_comp = d_left (ret_comp);
	break;
      case DEMANGLE_COMPONENT_CONST:
      case DEMANGLE_COMPONENT_RESTRICT:
      case DEMANGLE_COMPONENT_VOLATILE:
      case DEMANGLE_COMPONENT_CONST_THIS:
      case DEMANGLE_COMPONENT_RESTRICT_THIS:
      case DEMANGLE_COMPONENT_VOLATILE_THIS:
      case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
        ret_comp = d_left (ret_comp);
        break;
      case DEMANGLE_COMPONENT_NAME:
      case DEMANGLE_COMPONENT_CTOR:
      case DEMANGLE_COMPONENT_DTOR:
      case DEMANGLE_COMPONENT_OPERATOR:
      case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
	done = 1;
	break;
      default:
	return NULL;
	break;
      }

  if (last_template)
    {
      d_left (last_template) = ret_comp;
      return last_template;
    }

  return ret_comp;
}
Exemple #2
0
int main(int argc, char **argv) {
    FILE *fp = fopen("new.dat", "r");
    int xmax, ymax;
    int **data;
    
    load_max(fp, &xmax, &ymax);
    
    data = (int**) malloc(xmax * sizeof(int*));
    for (int x = 0; x < xmax; x++) {
        data[x] = calloc(ymax, sizeof(int));
    }

    load_data(fp, xmax, ymax, data);

    int max = 0;
    for (int x = 0; x < xmax; x++) {
        #pragma omp parallel for
        for (int y = 0; y < ymax; y++) {
            // check up, down, left, right, down_diag left, down_diag right
            int values[5];
            values[0] = up(data,x,y,xmax,ymax);
            values[1] = down(data,x,y,xmax,ymax);
            values[2] = left(data,x,y,xmax,ymax);
            values[3] = d_left(data,x,y,xmax,ymax);
            values[4] = d_right(data,x,y,xmax,ymax);
            int max_tmp = max_array(values, 5);
            if (max_tmp > max) { max = max_tmp; }
        }
    }
    
    printf("%d\n", max);
    free(data);
    return 0;
}
char *
cp_remove_params (const char *demangled_name)
{
  int done = 0;
  struct demangle_component *ret_comp;
  char *ret = NULL;

  if (demangled_name == NULL)
    return NULL;

  ret_comp = cp_demangled_name_to_comp (demangled_name, NULL);
  if (ret_comp == NULL)
    return NULL;

  /* First strip off any qualifiers, if we have a function or method.  */
  while (!done)
    switch (ret_comp->type)
      {
      case DEMANGLE_COMPONENT_CONST:
      case DEMANGLE_COMPONENT_RESTRICT:
      case DEMANGLE_COMPONENT_VOLATILE:
      case DEMANGLE_COMPONENT_CONST_THIS:
      case DEMANGLE_COMPONENT_RESTRICT_THIS:
      case DEMANGLE_COMPONENT_VOLATILE_THIS:
      case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
        ret_comp = d_left (ret_comp);
        break;
      default:
	done = 1;
	break;
      }

  /* What we have now should be a function.  Return its name.  */
  if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
    ret = cp_comp_to_string (d_left (ret_comp), 10);

  return ret;
}
char *
cp_class_name_from_physname (const char *physname)
{
  void *storage = NULL;
  char *demangled_name = NULL, *ret;
  struct demangle_component *ret_comp, *prev_comp, *cur_comp;
  int done;

  ret_comp = mangled_name_to_comp (physname, DMGL_ANSI, &storage,
				   &demangled_name);
  if (ret_comp == NULL)
    return NULL;

  done = 0;

  /* First strip off any qualifiers, if we have a function or method.  */
  while (!done)
    switch (ret_comp->type)
      {
      case DEMANGLE_COMPONENT_CONST:
      case DEMANGLE_COMPONENT_RESTRICT:
      case DEMANGLE_COMPONENT_VOLATILE:
      case DEMANGLE_COMPONENT_CONST_THIS:
      case DEMANGLE_COMPONENT_RESTRICT_THIS:
      case DEMANGLE_COMPONENT_VOLATILE_THIS:
      case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
        ret_comp = d_left (ret_comp);
        break;
      default:
	done = 1;
	break;
      }

  /* If what we have now is a function, discard the argument list.  */
  if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
    ret_comp = d_left (ret_comp);

  /* If what we have now is a template, strip off the template
     arguments.  The left subtree may be a qualified name.  */
  if (ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE)
    ret_comp = d_left (ret_comp);

  /* What we have now should be a name, possibly qualified.  Additional
     qualifiers could live in the left subtree or the right subtree.  Find
     the last piece.  */
  done = 0;
  prev_comp = NULL;
  cur_comp = ret_comp;
  while (!done)
    switch (cur_comp->type)
      {
      case DEMANGLE_COMPONENT_QUAL_NAME:
      case DEMANGLE_COMPONENT_LOCAL_NAME:
	prev_comp = cur_comp;
        cur_comp = d_right (cur_comp);
        break;
      case DEMANGLE_COMPONENT_TEMPLATE:
      case DEMANGLE_COMPONENT_NAME:
      case DEMANGLE_COMPONENT_CTOR:
      case DEMANGLE_COMPONENT_DTOR:
      case DEMANGLE_COMPONENT_OPERATOR:
      case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
	done = 1;
	break;
      default:
	done = 1;
	cur_comp = NULL;
	break;
      }

  ret = NULL;
  if (cur_comp != NULL && prev_comp != NULL)
    {
      /* We want to discard the rightmost child of PREV_COMP.  */
      *prev_comp = *d_left (prev_comp);
      /* The ten is completely arbitrary; we don't have a good estimate.  */
      ret = cp_comp_to_string (ret_comp, 10);
    }

  xfree (storage);
  if (demangled_name)
    xfree (demangled_name);
  return ret;
}
static int
is_ctor_or_dtor (const char *mangled,
                 enum gnu_v3_ctor_kinds *ctor_kind,
                 enum gnu_v3_dtor_kinds *dtor_kind)
{
  struct d_info di;
  struct demangle_component *dc;
  int ret;

  *ctor_kind = (enum gnu_v3_ctor_kinds) 0;
  *dtor_kind = (enum gnu_v3_dtor_kinds) 0;

  cplus_demangle_init_info (mangled, DMGL_GNU_V3, strlen (mangled), &di);

  {
#ifdef CP_DYNAMIC_ARRAYS
    __extension__ struct demangle_component comps[di.num_comps];
    __extension__ struct demangle_component *subs[di.num_subs];

    di.comps = comps;
    di.subs = subs;
#else
    di.comps = alloca (di.num_comps * sizeof (*di.comps));
    di.subs = alloca (di.num_subs * sizeof (*di.subs));
#endif

    dc = cplus_demangle_mangled_name (&di, 1);

    /* Note that because we did not pass DMGL_PARAMS, we don't expect
       to demangle the entire string.  */

    ret = 0;
    while (dc != NULL)
      {
	switch (dc->type)
	  {
	  default:
	    dc = NULL;
	    break;
	  case DEMANGLE_COMPONENT_TYPED_NAME:
	  case DEMANGLE_COMPONENT_TEMPLATE:
	  case DEMANGLE_COMPONENT_RESTRICT_THIS:
	  case DEMANGLE_COMPONENT_VOLATILE_THIS:
	  case DEMANGLE_COMPONENT_CONST_THIS:
	    dc = d_left (dc);
	    break;
	  case DEMANGLE_COMPONENT_QUAL_NAME:
	  case DEMANGLE_COMPONENT_LOCAL_NAME:
	    dc = d_right (dc);
	    break;
	  case DEMANGLE_COMPONENT_CTOR:
	    *ctor_kind = dc->u.s_ctor.kind;
	    ret = 1;
	    dc = NULL;
	    break;
	  case DEMANGLE_COMPONENT_DTOR:
	    *dtor_kind = dc->u.s_dtor.kind;
	    ret = 1;
	    dc = NULL;
	    break;
	  }
      }
  }

  return ret;
}
Exemple #6
0
// Dimentionless Dichotomy solver
Real Law2_ScGeom_ElectrostaticPhys::DL_DichoAdimExp_integrate_u(Real const& un, Real const& eps, Real const& alpha, Real const& Z, Real const& K, Real & prevDotU, Real const& dt, Real const& prev_d, Real const& undot)
{
	Real F = 0.;
	Real d_left(prev_d-1.), d_right(prev_d+1.);
	Real F_left(ObjF(un, eps, alpha, prevDotU, dt, prev_d, undot, Z, K, d_left));
	Real F_right(ObjF(un, eps, alpha, prevDotU, dt, prev_d, undot, Z, K, d_right));
	Real d;
	
	// Init: search for interval that contain sign change
	Real inc = (F_left < 0.) ? 1. : -1;
	inc = (F_left < F_right) ? inc : -inc;
	while(F_left*F_right >= 0. && std::isfinite(F_left) && std::isfinite(F_right)) {
		d_left += inc;
		d_right += inc;
		F_left = ObjF(un, eps, alpha, prevDotU, dt, prev_d, undot, Z, K, d_left);
		F_right = ObjF(un, eps, alpha, prevDotU, dt, prev_d, undot, Z, K, d_right);
	}
	
	if((!std::isfinite(F_left) || !std::isfinite(F_right))) {
		if(debug) LOG_WARN("Wrong direction");
		inc = -inc; // RE-INIT
		d_left = prev_d-1.;
		d_right = prev_d+1.;
		
		while(F_left*F_right >= 0. && std::isfinite(F_left) && std::isfinite(F_right)) {
			d_left += inc;
			d_right += inc;
			F_left = ObjF(un, eps, alpha, prevDotU, dt, prev_d, undot, Z, K, d_left);
			F_right = ObjF(un, eps, alpha, prevDotU, dt, prev_d, undot, Z, K, d_right);
		}
	}
	
	if((!std::isfinite(F_left) || !std::isfinite(F_right)))
		LOG_ERROR("Initial point problem!! d_left=" << d_left << " F_left=" << F_left << " d_right=" << d_right << " F_right=" << F_right);
	
	// Iterate to find the zero.
	int i;
	for(i=0;i<MaxIter;i++) {
		if(F_left*F_right > 0.)
			LOG_ERROR("Both function have same sign!! d_left=" << d_left << " F_left=" << F_left << " d_right=" << d_right << " F_right=" << F_right);
		
		//d = (d_left + d_right)/2.; // Dichotomy
		d = d_left - F_left*(d_right - d_left)/(F_right - F_left); // Regula Falsi
		F = ObjF(un, eps, alpha, prevDotU, dt, prev_d, undot, Z, K, d);
		
		if(std::abs(F) < SolutionTol)
			break;
		
		if(F*F_left < 0.) {
			F_right = F;
			d_right = d;
		} else {
			F_left = F;
			d_left = d;
		}
	}
	
	if(i == MaxIter)
		LOG_WARN("Max iteration reach: d_left=" << d_left << " F_left=" << F_left << " d_right=" << d_right << " F_right=" << F_right);
	
	Real a = (std::exp(d) < eps) ? alpha : 0.;
	prevDotU = -(1.+a)*std::exp(d) + a*eps + un + Z*K*std::exp(-K*std::exp(d));
	
	return d;
}