Esempio n. 1
0
void
sl_records_array_fprint (FILE * f, const char *msg)
{
  fprintf (f, "\n%s: ", msg);
  if (!records_array)
    {
      fprintf (f, "null\n");
      return;
    }
  fprintf (f, "[");
  uint_t length = sl_vector_size (records_array);
  for (uint_t i = 0; i < length; i++)
    {
      sl_record_t *ri = sl_vector_at (records_array, i);
      fprintf (f, " %s (", sl_record_name (i));
      if (!ri->flds)
	{
	  fprintf (f, "null),");
	  continue;
	}
      uint_t length_fld = sl_vector_size (ri->flds);
      for (uint_t j = 0; j < length_fld; j++)
	{
	  fprintf (f, "%s;", sl_field_name (sl_vector_at (ri->flds, j)));
	}
      fprintf (f, "),");
    }
  fprintf (f, " - ]");
}
Esempio n. 2
0
sl_type_t *
sl_field_register (const char *name, sl_type_t * ty)
{
  // type expression for the result is ty
  // extract informations about the field
  uid_t src = UNDEFINED_ID;
  uid_t dst = UNDEFINED_ID;
  if (!ty || ty->kind != SL_TYP_FIELD || ty->args == NULL
      || (sl_vector_size (ty->args) != 2))
    {
      // TODO: make error message
      printf ("Field declaration `%s': typing error.\n", name);
      return NULL;
    }
  // set src and dest
  src = sl_is_record (sl_vector_at (ty->args, 0));
  dst = sl_is_record (sl_vector_at (ty->args, 1));
  // create the field
  sl_field_t *f = sl_field_new (name, src, dst);
  // push the field
  sl_field_array_push (fields_array, f);
  f->fid = sl_vector_size (fields_array) - 1;
  // register the field in the src set of fields
  sl_record_t *r_src = sl_vector_at (records_array, src);
  sl_uid_array_push (r_src->flds, f->fid);
  // set order/pid to max
  f->order = UNDEFINED_ID;
  f->pid = UNDEFINED_ID;

  return ty;
}
Esempio n. 3
0
/**
 * Find a record using its name.
 * @return a type built with this record or NULL if not find
 */
sl_type_t *
sl_record_find (const char *name)
{
  sl_type_t *ty = NULL;
  for (uint_t i = 0; i < sl_vector_size (records_array); i++)
    {
      sl_record_t *r = sl_vector_at (records_array, i);
      if (strcmp (r->name, name) == 0)
	{
	  ty = sl_mk_type_record (UNDEFINED_ID);
	  sl_vector_at (ty->args, 0) = r->rid;
	}
    }
  return ty;
}
Esempio n. 4
0
/**
 * Ordering using the ordering of predicates.
 */
bool
sl_field_lt (uid_t lhs, uid_t rhs)
{

  assert (lhs < sl_vector_size (fields_array));
  assert (rhs < sl_vector_size (fields_array));

  sl_field_t *fl = sl_vector_at (fields_array, lhs);
  sl_field_t *fr = sl_vector_at (fields_array, rhs);

  assert (fl->order != UNDEFINED_ID);
  assert (fr->order != UNDEFINED_ID);
  assert (fl->order != fr->order);

  return (fl->order < fr->order);
}
Esempio n. 5
0
char *
sl_record_name (uid_t rid)
{
  if (rid >= sl_vector_size (records_array))
    {
      printf
	("sl_record_name: called with identifier %d not in the global environment.\n",
	 rid);
      return "unknown";
    }
  return sl_vector_at (records_array, rid)->name;
}
Esempio n. 6
0
char *
sl_field_name (uid_t fid)
{
  if (fid >= sl_vector_size (fields_array))
    {
      printf
	("sl_field_name: called with identifier %d not in the global environment.\n",
	 fid);
      return "unknown";
    }
  return sl_vector_at (fields_array, fid)->name;
}
Esempio n. 7
0
/**
 * Register a record.
 * Warning: does not test that the name already exists !
 */
sl_type_t *
sl_record_register (const char *name)
{
  // type expression for the result
  sl_type_t *ty = sl_mk_type_record (UNDEFINED_ID);
  // build the record
  sl_record_t *r = sl_record_new (name, NULL);
  // add to the global array
  sl_record_array_push (records_array, r);
  r->rid = sl_vector_size (records_array) - 1;
  // the index of the added record is last element of the array
  sl_vector_at (ty->args, 0) = r->rid;
  return ty;
}
Esempio n. 8
0
void
sl_fields_array_fprint (FILE * f, const char *msg)
{
  fprintf (f, "\n%s: ", msg);
  if (!fields_array)
    {
      fprintf (f, "null\n");
      return;
    }
  fprintf (f, "[");
  uint_t length = sl_vector_size (fields_array);
  for (uint_t i = 0; i < length; i++)
    {
      sl_field_t *fi = sl_vector_at (fields_array, i);
      fprintf (f, " %s:%s->%s,",
	       fi->name, sl_record_name (fi->src_r),
	       sl_record_name (fi->pto_r));
    }
  fprintf (f, " - ]");
}
Esempio n. 9
0
  CHECK(sl_clear_vector(NULL), BAD_ARG);
  CHECK(sl_clear_vector(vec), OK);
  CHECK(sl_vector_length(vec, &len), OK);
  CHECK(len, 0);

  CHECK(sl_vector_push_back(vec, (int[]){0}), OK);
  CHECK(sl_vector_push_back(vec, (int[]){1}), OK);
  CHECK(sl_vector_push_back(vec, (int[]){2}), OK);
  CHECK(sl_vector_push_back(vec, (int[]){3}), OK);
  CHECK(sl_vector_push_back(vec, (int[]){4}), OK);
  CHECK(sl_vector_push_back(vec, (int[]){5}), OK);
  CHECK(sl_vector_length(vec, &len), OK);
  CHECK(len, 6);

  CHECK(sl_vector_at(NULL, 0, NULL), BAD_ARG);
  CHECK(sl_vector_at(vec, 0, NULL), BAD_ARG);
  CHECK(sl_vector_at(NULL, 0, &data), BAD_ARG);
  CHECK(sl_vector_at(vec, 0, &data), OK);
  CHECK(*(int*)data, 0);
  CHECK(sl_vector_at(vec, 2, &data), OK);
  CHECK(*(int*)data, 2);
  CHECK(sl_vector_at(vec, 5, &data), OK);
  CHECK(*(int*)data, 5);
  CHECK(sl_vector_at(vec, 6, &data), BAD_ARG);

  CHECK(sl_vector_insert(NULL, 6, NULL), BAD_ARG);
  CHECK(sl_vector_insert(vec, 6, NULL), BAD_ARG);
  CHECK(sl_vector_insert(NULL, 2, NULL), BAD_ARG);
  CHECK(sl_vector_insert(vec, 2, NULL), BAD_ARG);
  CHECK(sl_vector_insert(NULL, 7, (int[]){6}), BAD_ARG);