absyntax/absyntax.cc
changeset 655 a77514dd0040
parent 654 7421cb63defa
child 779 2ed03e0e0e41
equal deleted inserted replaced
654:7421cb63defa 655:a77514dd0040
    80 # define LIST_CAP_INCR 8
    80 # define LIST_CAP_INCR 8
    81 
    81 
    82 list_c::list_c(
    82 list_c::list_c(
    83                int fl, int fc, const char *ffile, long int forder,
    83                int fl, int fc, const char *ffile, long int forder,
    84                int ll, int lc, const char *lfile, long int lorder)
    84                int ll, int lc, const char *lfile, long int lorder)
    85   :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder),c(LIST_CAP_INIT),n(0),elements((symbol_c**)malloc(LIST_CAP_INIT*sizeof(symbol_c*))) {}
    85   :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder),c(LIST_CAP_INIT) {
       
    86   n = 0;
       
    87   elements = (symbol_c**)malloc(LIST_CAP_INIT*sizeof(symbol_c*));
       
    88   if (NULL == elements) ERROR_MSG("out of memory");
       
    89 }
       
    90 
    86 
    91 
    87 list_c::list_c(symbol_c *elem, 
    92 list_c::list_c(symbol_c *elem, 
    88                int fl, int fc, const char *ffile, long int forder,
    93                int fl, int fc, const char *ffile, long int forder,
    89                int ll, int lc, const char *lfile, long int lorder)
    94                int ll, int lc, const char *lfile, long int lorder)
    90   :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder),c(LIST_CAP_INIT),n(0),elements((symbol_c**)malloc(LIST_CAP_INIT*sizeof(symbol_c*))) 
    95   :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder),c(LIST_CAP_INIT) { 
    91   { add_element(elem); }
    96   n = 0;
       
    97   elements = (symbol_c**)malloc(LIST_CAP_INIT*sizeof(symbol_c*));
       
    98   if (NULL == elements) ERROR_MSG("out of memory");
       
    99   add_element(elem); 
       
   100 }
       
   101 
    92 
   102 
    93 /* append a new element to the end of the list */
   103 /* append a new element to the end of the list */
    94 void list_c::add_element(symbol_c *elem) {
   104 void list_c::add_element(symbol_c *elem) {
    95   // printf("list_c::add_element()\n");
   105   // printf("list_c::add_element()\n");
    96   if((c <= n) && !(elements=(symbol_c**)realloc(elements,(c+=LIST_CAP_INCR)*sizeof(symbol_c *)))) ERROR_MSG("out of memory");
   106   if (c <= n)
       
   107     if (!(elements=(symbol_c**)realloc(elements,(c+=LIST_CAP_INCR)*sizeof(symbol_c *))))
       
   108       ERROR_MSG("out of memory");
    97   elements[n++] = elem;
   109   elements[n++] = elem;
    98  
   110  
    99   if(elem == NULL) return;
   111   if (NULL == elem) return;
   100 
   112 
   101   /* adjust the location parameters, taking into account the new element. */
   113   /* adjust the location parameters, taking into account the new element. */
   102   if ((first_line == elem->first_line) &&
   114   if ((first_line == elem->first_line) &&
   103       (first_column > elem->first_column)) {
   115       (first_column > elem->first_column)) {
   104     first_column = elem->first_column;
   116     first_column = elem->first_column;