Example #1
0
/*
 * pp_new_ptr_vec() - Create a new counted vector, and initialize it as empty.
 * return : PTR_VEC *
 * vec(in): The address of a PTR_VEC structure to be initialized, or NULL.
 */
PTR_VEC *
pp_new_ptr_vec (PTR_VEC * vec)
{
  if (vec == NULL)
    {
      vec = malloc (sizeof (PTR_VEC));
      if (vec == NULL)
	{
	  esql_yyverror (pp_get_msg (EX_MISC_SET, MSG_OUT_OF_MEMORY));
	  exit (1);
	  return NULL;
	}

      vec->heap_allocated = TRUE;
    }
  else
    {
      vec->heap_allocated = FALSE;
    }

  vec->n_elems = 0;
  vec->max_elems = DIM (vec->inline_elems);
  vec->elems = vec->inline_elems;
  vec->chunk_size = PTR_VEC_CHUNK_SIZE;

  return vec;
}
Example #2
0
static void
grow_ptr_vec (PTR_VEC * vec)
{
  int new_max_elems;
  void **new_elems;

  new_max_elems = vec->max_elems + vec->chunk_size;
  if (vec->elems == vec->inline_elems)
    {
      new_elems =
	(void **) pp_malloc (sizeof (vec->elems[0]) * new_max_elems);
      memcpy ((char *) new_elems, (char *) vec->elems,
	      sizeof (vec->elems[0]) * vec->n_elems);
    }
  else
    {
      new_elems = (void **)
	realloc (vec->elems, sizeof (vec->elems[0]) * new_max_elems);
    }

  if (new_elems == NULL)
    {
      esql_yyverror (pp_get_msg (EX_MISC_SET, MSG_OUT_OF_MEMORY));
      exit (1);
    }

  vec->elems = new_elems;
  vec->max_elems = new_max_elems;
}
Example #3
0
/*
 * pp_new_cursor() - Allocate (and enter in pp_cursor_table) a new CURSOR
 *    struct, initializing it with the given name and initialize the static
 *    and dynamic fields accordingly.
 * return : CURSOR *
 * name(in): A character string.
 * static_stmt(in): A prepared SQL/X SELECT statement, or NULL.
 * length(in) :
 * dynamic_stmt(in): A STMT pointer, or NULL.
 * host_refs(in):
 */
CURSOR *
pp_new_cursor (char *name, char *static_stmt, int length, STMT * dynamic_stmt, HOST_LOD * host_refs)
{
  CURSOR *cursor;

  cursor = pp_lookup_cursor (name);
  if (cursor && cursor->level >= pp_nesting_level)
    {
      esql_yyverror (pp_get_msg (EX_CURSOR_SET, MSG_REDEFINITION), cursor->name);
      return NULL;
    }

  cursor = es_ht_alloc_new_symbol (sizeof (CURSOR));

  cursor->name = (unsigned char *) strdup (name);
  cursor->cid = next_cid++;
  cursor->level = pp_nesting_level;
  cursor->next = NULL;
  cursor->host_refs = host_refs;
  cursor->static_stmt = (unsigned char *) (static_stmt ? strdup (static_stmt) : NULL);
  cursor->stmtLength = length;
  cursor->dynamic_stmt = dynamic_stmt;

  pp_cursor_table->add_symbol (pp_cursor_table, cursor);
  pp_add_cursor_to_scope (cursor);

  return cursor;
}
Example #4
0
/*
 * pp_set_class_bit() - Change the class of the specifier pointed to by p
 *    as indicated by storage_class.
 * return : void
 * storage_class(in): The new storage class for the specifier p.
 * p(out): The specifier to be changed.
 * note :The TYPEDEF class is used here only to remember that the input
 *    storage class was a typedef.
 */
static void
pp_set_class_bit (int storage_class, LINK * p)
{
  switch (storage_class)
    {
    case 0:
      {
	p->decl.s.sclass = C_FIXED;
	p->decl.s.is_static = 0;
	p->decl.s.is_extern = 0;
	p->decl.s.is_const = 0;
	p->decl.s.is_volatile = 0;
      }
      break;

    case TYPEDEF_:
      p->decl.s.sclass = C_TYPEDEF;
      break;

    case REGISTER_:
      p->decl.s.is_register = 1;
      break;

    case AUTO_:
      p->decl.s.is_auto = 1;
      break;

    case EXTERN_:
      p->decl.s.is_extern = 1;
      break;

    case STATIC_:
      p->decl.s.is_static = 1;
      break;

    default:
      {
	esql_yyverror (pp_get_msg (EX_DECL_SET, MSG_BAD_STORAGE_CLASS),
		       storage_class);
	exit (1);
      }
      break;
    }
}
Example #5
0
/*
 * pp_add_spec_to_decl() - Add the specifier to each of the declarators in
 *    decl_chain. This is accomplished by cloning p_spec and then tacking it
 *    onto the end of every declaration chain in decl_chain.
 * return : void
 * p_spec(in): A pointer to a specifier/declarator chain created by a previous
 *    typedef, or to a single specifier.  It is cloned and then tacked onto
 *    the end of every declaration chain in the list pointed to by decl_chain.
 * decl_chain(out): A chain of declarators, each of which is to receive the
 *    p_spec specifier.
 */
void
pp_add_spec_to_decl (LINK * p_spec, SYMBOL * decl_chain)
{
  LINK *clone_start, *clone_end;

  for (; decl_chain; decl_chain = decl_chain->next)
    {
      clone_start = pp_clone_type (p_spec, &clone_end);
      if (clone_start == NULL)
	{
	  esql_yyverror (pp_get_msg (EX_DECL_SET, MSG_MALFORMED_CHAIN));
	  exit (1);
	}

      if (IS_PSEUDO_TYPE (clone_start)
	  && clone_start->decl.s.val.v_struct == NULL)
	{
	  LINK *old_etype;
	  char tmp[32];

	  old_etype = decl_chain->etype;
	  if (old_etype == NULL
	      || (IS_VAR_TYPE (clone_start) && IS_ARRAY (old_etype) == 0))
	    {
	      esql_yyverror (pp_get_msg (EX_DECL_SET, MSG_BAD_PSEUDO_DECL),
			     pp_type_str (clone_start));
	      exit (1);
	    }

	  clone_start->decl.s.val.v_struct =
	    pp_new_pseudo_def (clone_start->decl.s.noun,
			       old_etype->decl.d.num_ele);
	  if (clone_start->decl.s.noun == N_VARCHAR)
	    {
	      sprintf (tmp, " = { %s, \"\" }", old_etype->decl.d.num_ele);
	    }
	  else
	    {
	      sprintf (tmp, " = { ((%s)+7)/8, \"\" }",
		       old_etype->decl.d.num_ele);
	    }
	  decl_chain->args = pp_new_symbol (tmp, decl_chain->level);
	  pp_discard_link (old_etype);

	  if (decl_chain->type == old_etype)
	    {
	      decl_chain->type = NULL;
	    }
	  else
	    {
	      LINK *parent;
	      for (parent = decl_chain->type;
		   parent->next != old_etype; parent = parent->next)
		{
		  ;
		}
	      parent->next = NULL;
	      decl_chain->etype = parent;
	    }
	}

      if (decl_chain->type == NULL)	/* No declarators */
	{
	  decl_chain->type = clone_start;
	}
      else
	{
	  decl_chain->etype->next = clone_start;
	}

      decl_chain->etype = clone_end;

      /*
       * If the declaration we're looking at is really a typedef,
       * record the symbol itself within the specifier.  This will
       * make it easier to point back to the symbol from other
       * declarations, which will make it easier to print out
       * later declarations using the typedef name rather than its
       * expansion.
       */
      if (IS_TYPEDEF (clone_end))
	{
	  pp_set_class_bit (0, clone_end);
	  decl_chain->type->tdef = decl_chain;
	  decl_chain->type->from_tdef = decl_chain;
	}
    }
}