Exemplo n.º 1
0
static void incomplete_type_error(expression e, type t)
{
  /* Avoid duplicate error message.  */
  if (t == error_type)
    return;

  if (e && is_identifier(e))
    error("`%s' has an incomplete type", CAST(identifier, e)->cstring.data);
  else
    {
      while (type_array(t) && type_array_size(t))
	t = type_array_of(t);

      if (type_struct(t))
	error("invalid use of undefined type `struct %s'", type_tag(t)->name);
      else if (type_union(t))
	error("invalid use of undefined type `union %s'", type_tag(t)->name);
      else if (type_enum(t))
	error("invalid use of undefined type `enum %s'", type_tag(t)->name);
      else if (type_void(t))
	error("invalid use of void expression");
      else if (type_array(t))
	error("invalid use of array with unspecified bounds");
      else
	assert(0);
      /* XXX: Missing special message for typedef's */
    }
}
Exemplo n.º 2
0
type default_conversion_for_assignment(expression e)
{
  if (type_array(e->type) || type_function(e->type))
    return default_conversion(e);
  else
    return e->type;
}
Exemplo n.º 3
0
static inline address _KNI_GetRawArrayRegion_start_address(jarray src,
                                                           jsize offset) {
  TypeArray::Raw type_array = kni_read_handle(src);
  GUARANTEE(type_array.not_null(), "null arg to KNI_[Get|Set]RawArrayRegion");
  address ta_start =
      (address)&((char*)type_array.obj())[type_array().base_offset() + offset];
  return (ta_start);
}
Exemplo n.º 4
0
static bool check_writable_lvalue(expression e, char *context)
{
  if (!e->lvalue || type_array(e->type))
    {
      error("invalid lvalue in %s", context);
      return FALSE;
    }
  if (type_readonly(e->type))
    readonly_warning(e, context);
  return TRUE;
}
Exemplo n.º 5
0
type default_conversion(expression e)
{
  type from = e->type;

  if (type_enum(from))
    from = type_tag(from)->reptype;

  if (type_smallerthanint(from))
    {
      /* Traditionally, unsignedness is preserved in default promotions. */
      if (flag_traditional && type_unsigned(from))
	return unsigned_int_type;
      else
	return int_type;
    }

  if (flag_traditional && !flag_allow_single_precision && type_float(from))
    return double_type;

  if (type_void(from))
    {
      error("void value not ignored as it ought to be");
      return error_type;
    }

  if (type_function(from))
    {
      assert(!e->cst);
      e->cst = e->static_address;
      return make_pointer_type(from);
    }

  if (type_array(from))
    {
      if (!e->lvalue)
	{
	  error("invalid use of non-lvalue array");
	  return error_type;
	}
      assert(!e->cst);
      e->cst = e->static_address;
      /* It's being used as a pointer, so is not an lvalue */
      e->lvalue = FALSE;
      return make_pointer_type(type_array_of(from));
    }

  return from;
}
Exemplo n.º 6
0
// Callback
void objectDetect::imageCallback(const sensor_msgs::ImageConstPtr& img)
{
	// transform image
	cv_bridge::CvImagePtr cv_image = cv_bridge::toCvCopy(img, sensor_msgs::image_encodings::BGR8);
	cv::Mat image = cv_image->image;

	std::vector<cv::LatentSvmDetector::ObjectDetection> detections;

	// detection main
#if defined(HAS_GPU)
	if (use_gpu) {
		gpu_detector_->detect(image, detections, (float)overlap_threshold_, num_threads_,
			lambda_, num_cells_, (float)val_of_truncate_);
	} else {
#endif
		cpu_detector_->detect(image, detections, (float)overlap_threshold_, num_threads_,
			score_threshold_, lambda_, num_cells_, num_bins_);
#if defined(HAS_GPU)
	}
#endif

	int num = detections.size();
	std::vector<int> corner_point_array(num * 4.0);
	std::vector<int> type_array(num, 0);

	cv_tracker::image_obj msg;
	msg.header = img->header;
	msg.type = object_class;

	for(size_t i = 0; i < detections.size(); i++)
	{
		const cv::LatentSvmDetector::ObjectDetection& od = detections[i];
		cv_tracker::image_rect rect;

		type_array[i] = od.classID;
		rect.x = od.rect.x;
		rect.y = od.rect.y;
		rect.width = od.rect.width;
		rect.height = od.rect.height;
		rect.score = od.score;
		msg.obj.push_back(rect);
	}

	detect_pub_.publish(msg);
}
Exemplo n.º 7
0
expression make_comma(location loc, expression elist)
{
  expression result = CAST(expression, new_comma(parse_region, loc, elist));
  expression e;

  scan_expression (e, elist)
    if (e->next) /* Not last */
      {
#if 0
	if (!e->side_effects)
	  {
	    /* The left-hand operand of a comma expression is like an expression
	       statement: with -W or -Wunused, we should warn if it doesn't have
	       any side-effects, unless it was explicitly cast to (void).  */
	    if ((extra_warnings || warn_unused)
		&& !(TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
		      && TREE_TYPE (TREE_VALUE (list)) == void_type_node))
	      warning ("left-hand operand of comma expression has no effect");
	  }
	else if (warn_unused)
	  warn_if_unused_value(e);
#endif
      }
    else
      {
	if (type_array(e->type))
	  result->type = default_conversion(e);
	else
	  result->type = e->type;

	if (!pedantic)
	  {
	    /* XXX: I seemed to believe that , could be a constant expr in GCC,
	       but cst3.c seems to disagree. Check gcc code again ?
	       (It's a bad idea anyway) */
	    result->lvalue = e->lvalue;
	    result->isregister = e->isregister;
	    result->bitfield = e->bitfield;
	  }
      }

  return result;
}
Exemplo n.º 8
0
Arquivo: edit.c Projeto: albedium/nesc
/* Declare a new temporary that can be assigned a value of type t.
   Place the declaration at the start of block. 
   XXX: See discussion in types.c:tag2ast about the (lack of) correctness of
   this approach.
   Return it's declaration */
data_decl build_declaration(region r, struct environment *e,
			    type t, const char *name, expression init,
			    data_declaration *oddecl)
{
  struct data_declaration tempdecl;
  identifier_declarator id;
  variable_decl vd;
  data_decl dd;
  declarator tdeclarator;
  type_element tmodifiers;

  /* Compute real type, name */
  if (type_array(t))
    t = make_pointer_type(type_array_of(t));
  else if (type_function(t))
    t = make_pointer_type(t);
  /* Qualifiers must not be present on the temp (the qualifiers of t apply
     to the original location we are building a temp) */
  t = make_qualified_type(t, no_qualifiers);

  /* Build AST for the declaration */
  id = new_identifier_declarator(r, dummy_location, str2cstring(r, name));
  type2ast(r, dummy_location, t, CAST(declarator, id), &tdeclarator, &tmodifiers);
  vd = new_variable_decl(r, dummy_location, tdeclarator, NULL, init, NULL, NULL);
  vd->declared_type = t;
  dd = new_data_decl(r, dummy_location, tmodifiers, CAST(declaration, vd));

  if (e) /* Declare the variable */
    {
      init_data_declaration(&tempdecl, CAST(declaration, vd), id->cstring.data, t);
      tempdecl.kind = decl_variable;
      tempdecl.vtype = variable_normal;
      tempdecl.islocal = TRUE;
      *oddecl = vd->ddecl = declare(e, &tempdecl, FALSE);
    }

  return dd;
}
Exemplo n.º 9
0
static void dump_fields(region r, const char *prefix, field_declaration fields)
{
  while (fields)
    {
      if (fields->name) /* skip anon fields */
	{
	  type t = fields->type;

	  printf("  %s%s ", prefix, fields->name);
	  while (type_array(t))
	    {
	      type base = type_array_of(t);
	      expression size = type_array_size(t);

	      printf("[%lu]", (unsigned long)constant_uint_value(size->cst));
	      t = base;
	    }
	  dump_type(t);

	  assert(cval_isinteger(fields->offset));
	  printf(" %lu %lu\n", (unsigned long)cval_uint_value(fields->offset),
		 (unsigned long)
		 (!cval_istop(fields->bitwidth) ?
		  cval_uint_value(fields->bitwidth) :
		  BITSPERBYTE * cval_uint_value(type_size(t))));

	  if (type_aggregate(t))
	    {
	      tag_declaration tdecl = type_tag(t);
	      char *newprefix = rarrayalloc(r, strlen(prefix) + strlen(fields->name) + 2, char);

	      sprintf(newprefix, "%s%s.", prefix, fields->name);
	      dump_fields(r, newprefix, tdecl->fieldlist);
	      printf("  %s%s AX\n", prefix, fields->name);
	    }
	}
      fields = fields->next;
    }
Exemplo n.º 10
0
KNIEXPORT void KNI_SetDoubleArrayElement(jdoubleArray arrayHandle,
                                         jsize index, jdouble value) {
  TypeArray::Raw type_array = kni_read_handle(arrayHandle);
  GUARANTEE(type_array.not_null(), "null arg to KNI_SetDoubleArrayElement");
  type_array().double_at_put(index, value);
}
Exemplo n.º 11
0
KNIEXPORT jdouble
KNI_GetDoubleArrayElement(jdoubleArray arrayHandle, jsize index) {
  TypeArray::Raw type_array = kni_read_handle(arrayHandle);
  GUARANTEE(type_array.not_null(), "null arg to KNI_GetDoubleArrayElement");
  return type_array().double_at(index);
}
Exemplo n.º 12
0
KNIEXPORT jboolean
KNI_GetBooleanArrayElement(jbooleanArray arrayHandle, jsize index) {
  TypeArray::Raw type_array = kni_read_handle(arrayHandle);
  GUARANTEE(type_array.not_null(), "null arg to KNI_GetBooleanArrayElement");
  return type_array().bool_at(index);
}
Exemplo n.º 13
0
void *LLVMFormula::emit (CallExprAST *expr)
{
	// Deal with the if-instruction first, specially
	if (expr->function == "if")
	{
		Value *cond = (Value *)expr->args[0]->generate (this);
		Value *t = (Value *)expr->args[1]->generate (this);
		Value *f = (Value *)expr->args[2]->generate (this);
		if (cond == NULL || t == NULL || f == NULL) return NULL;
		
		Value *one = ConstantFP::get (getGlobalContext (), APFloat (1.0));
		Value *cmp = builder->CreateFCmpOEQ (cond, one, "ifcmptmp");

		return builder->CreateSelect (cmp, t, f, "ifelsetmp");
	}

	// Sign isn't a standard-library function, implement it with a compare
	if (expr->function == "sign")
	{
		Value *v = (Value *)expr->args[0]->generate (this);
		if (!v) return NULL;
		
		Value *zero = ConstantFP::get (getGlobalContext (), APFloat (0.0));
		Value *one = ConstantFP::get (getGlobalContext (), APFloat (1.0));
		Value *none = ConstantFP::get (getGlobalContext (), APFloat (-1.0));

		Value *cmpgzero = builder->CreateFCmpOGT (v, zero, "sgncmpgzero");
		Value *cmplzero = builder->CreateFCmpOLT (v, zero, "sgncmplzero");

		Value *fselect = builder->CreateSelect (cmplzero, none, zero, "sgnsellzero");
		return builder->CreateSelect (cmpgzero, one, fselect, "sgnselgzero");
	}

	//
	// Map our function names to standard libm names
	//
	
	// If we're calling "log", we want "log10"
	if (expr->function == "log")
		expr->function = "log10";
	// If we're calling "ln", we want "log"
	if (expr->function == "ln")
		expr->function = "log";
	// If we're calling "abs", we want "fabs"
	if (expr->function == "abs")
		expr->function = "fabs";
	
	// The following are available as LLVM intrinsics, and we should emit them
	// specially without calling out to libm:
	Intrinsic::ID intrinsicID = Intrinsic::not_intrinsic;
		
	if (expr->function == "cos")
		intrinsicID = Intrinsic::cos;
	else if (expr->function == "exp")
		intrinsicID = Intrinsic::exp;
	else if (expr->function == "log")
		intrinsicID = Intrinsic::log;
	else if (expr->function == "log10")
		intrinsicID = Intrinsic::log10;
	else if (expr->function == "sin")
		intrinsicID = Intrinsic::sin;
	else if (expr->function == "sqrt")
		intrinsicID = Intrinsic::sqrt;

	if (intrinsicID != Intrinsic::not_intrinsic)
	{
		// Most of the floating-point intrinsics are overloaded for multiple types
		Type *types[1] = { Type::getDoubleTy (getGlobalContext ()) };
        ArrayRef<Type *> type_array(types, 1);
		
		Value *arg = (Value *)expr->args[0]->generate (this);
		if (!arg) return NULL;

		Value *func = Intrinsic::getDeclaration (module, intrinsicID, type_array);
		return builder->CreateCall (func, arg, expr->function);
	}
	
	// The rest of these are calls to stdlib floating point math
	// functions.
	
	// atan2 is special, because it has two arguments
	if (expr->function == "atan2")
	{
        Value *arg1 = (Value *)expr->args[0]->generate (this);
        Value *arg2 = (Value *)expr->args[1]->generate (this);
        if (!arg1 || !arg2) return NULL;
        
        Module *M = builder->GetInsertBlock ()->getParent ()->getParent ();
        Value *Callee = M->getOrInsertFunction (expr->function,
                                                Type::getDoubleTy (getGlobalContext ()),
    	                                        Type::getDoubleTy (getGlobalContext ()),
    	                                        Type::getDoubleTy (getGlobalContext ()),
                                                NULL);
        return builder->CreateCall2 (Callee, arg1, arg2, expr->function);
	}
	else
	{
    	// Emit a call to function (arg)
    	Value *arg = (Value *)expr->args[0]->generate (this);
    	if (!arg) return NULL;
	
    	Module *M = builder->GetInsertBlock ()->getParent ()->getParent ();
    	Value *Callee = M->getOrInsertFunction (expr->function,
    	                                        Type::getDoubleTy (getGlobalContext ()),
    	                                        Type::getDoubleTy (getGlobalContext ()),
    	                                        NULL);
    	return builder->CreateCall (Callee, arg, expr->function);
    }
}
Exemplo n.º 14
0
void *LLVMFormula::emit (BinaryExprAST *expr)
{
	if (expr->op == "=")
	{
		// The assign function has to be dealt with specially, we *do not*
		// want to emit the LHS code (the load-from-memory instruction)!
		VariableExprAST *var = dynamic_cast<VariableExprAST *>(expr->LHS);
		if (!var) return NULL;
				
		Value *val = (Value *)expr->RHS->generate (this);
		if (!val) return NULL;
		
		// Emit a store-to-pointer instruction
		builder->CreateStore (val, getGlobalVariableFor (var->pointer), "storetmp");
		return val;
	}

	// The rest of the operators function normally
	Value *L = (Value *)expr->LHS->generate (this);
	Value *R = (Value *)expr->RHS->generate (this);
	if (L == NULL || R == NULL) return NULL;

	if (expr->op == "<=")
	{
		L = builder->CreateFCmpULE (L, R, "letmp");
		return builder->CreateUIToFP (L, Type::getDoubleTy (getGlobalContext ()),
		                              "booltmp");
	}
	else if (expr->op == ">=")
	{
		L = builder->CreateFCmpUGE (L, R, "getmp");
		return builder->CreateUIToFP (L, Type::getDoubleTy (getGlobalContext ()),
		                              "booltmp");
	}
	else if (expr->op == "!=")
	{
		L = builder->CreateFCmpUNE (L, R, "neqtmp");
		return builder->CreateUIToFP (L, Type::getDoubleTy (getGlobalContext ()),
		                              "booltmp");
	}
	else if (expr->op == "==")
	{
		L = builder->CreateFCmpUEQ (L, R, "eqtmp");
		return builder->CreateUIToFP (L, Type::getDoubleTy (getGlobalContext ()),
		                              "booltmp");
	}
	else if (expr->op == "<")
	{
		L = builder->CreateFCmpULT (L, R, "lttmp");
		return builder->CreateUIToFP (L, Type::getDoubleTy (getGlobalContext ()),
		                              "booltmp");
	}
	else if (expr->op == ">")
	{
		L = builder->CreateFCmpUGT (L, R, "gttmp");
		return builder->CreateUIToFP (L, Type::getDoubleTy (getGlobalContext ()),
		                              "booltmp");
	}
	else if (expr->op == "+")
		return builder->CreateFAdd (L, R, "addtmp");
	else if (expr->op == "-")
		return builder->CreateFSub (L, R, "subtmp");
	else if (expr->op == "*")
		return builder->CreateFMul (L, R, "multmp");
	else if (expr->op == "/")
		return builder->CreateFDiv (L, R, "divtmp");
	else if (expr->op == "^")
	{
		// The floating-point intrinsics are overloaded for multiple types
		Type *types[1] = { Type::getDoubleTy (getGlobalContext ()) };
        ArrayRef<Type *> type_array(types, 1);
		
		Value *func = Intrinsic::getDeclaration (module, Intrinsic::pow, type_array);
		return builder->CreateCall2 (func, L, R, "pow");
	}
	else
		return NULL;
}
Exemplo n.º 15
0
expression make_cast(location loc, asttype t, expression e)
{
  expression result = CAST(expression, new_cast(parse_region, loc, e, t));
  type castto = t->type;
  
  if (castto == error_type || type_void(castto))
    ; /* Do nothing */
  else if (type_array(castto))
    {
      error("cast specifies array type");
      castto = error_type;
    }
  else if (type_function(castto))
    {
      error("cast specifies function type");
      castto = error_type;
    }
  else if (type_equal_unqualified(castto, e->type))
    {
      if (pedantic && type_aggregate(castto))
	pedwarn("ANSI C forbids casting nonscalar to the same type");
    }
  else
    {
      type etype = e->type;

      /* Convert functions and arrays to pointers,
	 but don't convert any other types.  */
      if (type_function(etype) || type_array(etype))
	etype = default_conversion(e);

      if (type_union(castto))
	{
	  tag_declaration utag = type_tag(castto);
	  field_declaration ufield;

	  /* Look for etype as a field of the union */
	  for (ufield = utag->fieldlist; ufield; ufield = ufield->next)
	    if (ufield->name && type_equal_unqualified(ufield->type, etype))
	      {
		if (pedantic)
		  pedwarn("ANSI C forbids casts to union type");
		break;
	      }
	  if (!ufield)
	    error("cast to union type from type not present in union");
	}
      else 
	{
	  /* Optionally warn about potentially worrisome casts.  */

	  if (warn_cast_qual && type_pointer(etype) && type_pointer(castto))
	    {
	      type ep = type_points_to(etype), cp = type_points_to(castto);

	      if (type_volatile(ep) && !type_volatile(cp))
		pedwarn("cast discards `volatile' from pointer target type");
	      if (type_const(ep) && !type_const(cp))
		pedwarn("cast discards `const' from pointer target type");
	    }

	  /* This warning is weird */
	  if (warn_bad_function_cast && is_function_call(e) &&
	      !type_equal_unqualified(castto, etype))
	    warning ("cast does not match function type");

#if 0
	  /* Warn about possible alignment problems.  */
	  if (STRICT_ALIGNMENT && warn_cast_align
	      && TREE_CODE (type) == POINTER_TYPE
	      && TREE_CODE (otype) == POINTER_TYPE
	      && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
	      && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
	      /* Don't warn about opaque types, where the actual alignment
		 restriction is unknown.  */
	      && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE
		    || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE)
		   && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
	      && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
	    warning ("cast increases required alignment of target type");

	  if (TREE_CODE (type) == INTEGER_TYPE
	      && TREE_CODE (otype) == POINTER_TYPE
	      && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
	      && !TREE_CONSTANT (value))
	    warning ("cast from pointer to integer of different size");

	  if (TREE_CODE (type) == POINTER_TYPE
	      && TREE_CODE (otype) == INTEGER_TYPE
	      && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
#if 0
	      /* Don't warn about converting 0 to pointer,
		 provided the 0 was explicit--not cast or made by folding.  */
	      && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value))
#endif
	      /* Don't warn about converting any constant.  */
	      && !TREE_CONSTANT (value))
	    warning ("cast to pointer from integer of different size");
#endif

	  check_conversion(castto, etype);
	}
    }

  result->lvalue = !pedantic && e->lvalue;
  result->isregister = e->isregister;
  result->bitfield = e->bitfield;
  result->static_address = e->static_address;
  result->type = castto;
  result->cst = fold_cast(result);

  return result;
}