int main ()
{
  char type_name[] = "ops";
  char field_name[] = "subtract";

  mr_td_t * td = mr_get_td_by_name (type_name);

  if (NULL == td)
    {
      fprintf (stderr,
	       "error: can't obtain type information for '%s'\n",
	       type_name);
      return (EXIT_FAILURE);
    }

  mr_fd_t const * fd = mr_get_fd_by_name (td, field_name);

  if (NULL == fd)
    {
      fprintf (stderr,
	       "error: can't obtain type information for '%s' in '%s'\n",
	       field_name, type_name);
      return (EXIT_FAILURE);
    }

  printf ("field '%s' has type name '%s'\n", field_name, fd->type);
  printf ("the actual type: ");
  return (print_func_field_signature (fd));
}
Exemplo n.º 2
0
int print_array_field_info (mr_td_t * td, char name[])
{
  mr_fd_t const * fd = mr_get_fd_by_name (td, name);

  if (NULL == fd)
    {
      fprintf (stderr,
	       "error: can't obtain type information for field '%s'\n",
	       name);
      return (EXIT_FAILURE);
    }

  if (fd->mr_type != MR_TYPE_ARRAY)
    {
      fprintf (stderr,
	       "error: the '%s' field is not an array\n",
	       name);
      return (EXIT_FAILURE);
    }

  size_t const total_items = fd->param.array_param.count;
  size_t const rows = fd->param.array_param.row_count;

  printf("field declaration: %s %s", fd->type, fd->name.str);

  if (rows == 1) // 1-dimensional
    printf("[%zd]\n", total_items);
  else  // 2- or more dimensional
    printf("[%zd][%zd]\n", total_items / rows, rows);

  return (EXIT_SUCCESS);
}