30 #include "esql_grammar.h" 109 if (symbol_free_list ==
NULL)
116 symbol_free_list = symbol_free_list->
next;
167 symbol_free_list = sym;
205 if (link_free_list ==
NULL)
208 if (new_chunk ==
NULL)
216 link_chunks = new_chunk;
217 link_free_list = new_chunk->
link;
220 for (p = link_free_list, i =
LCHUNK; --i > 0; ++
p)
229 link_free_list = link_free_list->
next;
233 memset ((
char *) p, 0,
sizeof (
LINK));
298 static int anon_tag = 0;
303 if (struct_free_list ==
NULL)
310 struct_free_list = struct_free_list->
next;
317 sprintf (buf,
"$%d", anon_tag);
322 sdef->
tag = (
unsigned char *)
strdup (tag);
354 struct_free_list = sdef;
373 for (sdef = sdef_chain; sdef; sdef =
next)
398 SYMBOL *length_field, *array_field, *db_int32;
414 vs_sprintf (&new_subscript,
"((%s)+7)/8", subscript);
422 db_int32 =
pp_findsym (pp_Symbol_table, (
unsigned char *)
"int");
433 length_field->
next = array_field;
436 sdef->
fields = length_field;
437 pp_Struct_table->
add_symbol (pp_Struct_table, sdef);
520 LINK *last =
nullptr, *head =
nullptr;
522 for (; tchain; tchain = tchain->
next)
524 if (head ==
nullptr && last ==
nullptr)
538 memcpy ((
char *) last, (
char *) tchain,
sizeof (*last));
554 lastsym = &(*lastsym)->
next;
584 for (; p1 && p2; p1 = p1->
next, p2 = p2->
next)
586 if (p1->
class_ != p2->class_)
633 strcpy (str,
"unsigned ");
640 strcpy (str,
"unsigned ");
649 strcpy (str,
"long ");
669 static char target[80];
670 static char buf[256];
682 strcpy (target,
"tdef ");
692 strncpy (buf,
"array of ",
sizeof (buf));
695 strncpy (buf,
"ptr to ",
sizeof (buf));
698 strncpy (buf,
"function returning ",
sizeof (buf));
701 strncpy (buf,
"BAD DECL",
sizeof (buf));
708 const char *noun_str;
733 noun_str =
"varchar";
739 noun_str =
"bit varying";
742 noun_str =
"BAD NOUN";
745 strncat (buf, noun_str,
sizeof (buf) - strnlen (buf,
sizeof (buf)));
749 strncat (target, buf,
sizeof (target) - strnlen (target,
sizeof (target)));
750 snprintf (buf,
sizeof (buf),
" %s",
752 tag : ((
unsigned char *)
"untagged")));
756 strncat (target, buf,
sizeof (target) - strnlen (target,
sizeof (target)));
785 fprintf (fp,
" * %s %s:\n", sdef->
type_string, (sdef->
tag ? sdef->
tag : ((
unsigned char *)
"<anon>")));
787 for (field = sdef->
fields; field; field = field->
next)
810 fprintf (fp,
" *\n * Symbol table:\n *\n");
817 fprintf (fp,
" *\n * Structure table:\n *\n");
849 symbol_free_list =
NULL;
850 struct_free_list =
NULL;
851 link_free_list =
NULL;
884 for (sym = symbol_free_list; sym; sym =
next)
889 symbol_free_list =
NULL;
895 for (sdef = struct_free_list; sdef; sdef =
next)
900 struct_free_list =
NULL;
906 for (chunk = link_chunks; chunk; chunk =
next)
940 fputs (
"\n/*\n", fp);
HASH_TAB * es_ht_make_table(unsigned maxsym, HT_HASH_FN hash_function, HT_CMP_FN cmp_function)
static STRUCTDEF * struct_free_list
void pp_discard_symbol(SYMBOL *sym)
void *(* add_symbol)(HASH_TAB *tbl, void *sym)
static int links_deallocated
static int sdefs_allocated
STRUCTDEF * pp_new_pseudo_def(SPECIFIER_NOUN type, const char *subscript)
unsigned char is_unsigned
void pp_free_symtab(SYMTAB *symtab, HT_FREE_FN free_fn)
char * pp_strdup(const char *str)
varstring * vs_new(varstring *vstr)
STRUCTDEF * pp_new_structdef(const char *tag)
void *(* find_symbol)(HASH_TAB *tbl, void *sym)
void pp_discard_structdef(STRUCTDEF *sdef)
SYMBOL * pp_findsym(SYMTAB *symtab, unsigned char *name)
int pp_generic_cmp(void *p1, void *p2)
int(* get_symbol_count)(HASH_TAB *tbl)
LINK * pp_current_type_spec(void)
int(* print_table)(HASH_TAB *tbl, void(*prnt)(), void *par, int srt)
void esql_yyverror(const char *,...)
static SYMBOL * symbol_free_list
const char * pp_get_msg(int msg_set, int msg_num)
static int syms_allocated
static void es_print_struct(STRUCTDEF *sdef, FILE *fp)
int vs_sprintf(varstring *vstr, const char *fmt,...)
SYMTAB * pp_new_symtab(void)
char * vs_str(varstring *vstr)
void(* HT_FREE_FN)(void *)
void es_ht_free_symbol(void *sym)
struct linkchunk LINKCHUNK
void vs_free(varstring *vstr)
void esql_yyerror(const char *)
SYMBOL * pp_clone_symbol(SYMBOL *sym)
enum specifier_noun SPECIFIER_NOUN
void pp_add_declarator(SYMBOL *sym, int type)
int pp_the_same_type(LINK *p1, LINK *p2, int relax)
void pp_discard_link(LINK *p)
const char * VARCHAR_ARRAY_NAME
static int links_allocated
static int syms_deallocated
#define strncpy_bufsize(buf, str)
static int sdefs_deallocated
void pp_push_spec_scope(void)
void pp_discard_structdef_chain(STRUCTDEF *sdef_chain)
void pp_print_syms(FILE *fp)
static const unsigned int SYMTAB_SIZE
void pp_reset_current_type_spec(void)
void pp_symbol_finish(void)
unsigned int pp_generic_hash(void *p)
void pp_symbol_init(void)
SYMBOL * pp_new_symbol(const char *name, int scope)
static LINK * link_free_list
LINK * pp_clone_type(LINK *tchain, LINK **endp)
void pp_add_spec_to_decl(LINK *p_spec, SYMBOL *decl_chain)
void pp_add_typedefed_spec(LINK *spec)
const char * pp_type_str(LINK *link)
const char * VARCHAR_LENGTH_NAME
void pp_symbol_stats(FILE *fp)
#define free_and_init(ptr)
void pp_add_type_noun(int type)
void pp_pop_spec_scope(void)
static int syms_to_free_lists
char * strdup(const char *str)
void * es_ht_alloc_new_symbol(int size)
void pp_discard_link_chain(LINK *p)
void(* free_table)(HASH_TAB *tbl, HT_FREE_FN free)
static LINKCHUNK * link_chunks
static void es_print_symbol(SYMBOL *sym, FILE *fp)
char * pp_attr_str(LINK *type)
void pp_discard_symbol_chain(SYMBOL *sym)
const unsigned char * type_string