Adjust coding style.
authorMario de Sousa <msousa@fe.up.pt>
Thu, 13 Sep 2012 17:12:40 +0100
changeset 655 a77514dd0040
parent 654 7421cb63defa
child 656 45a796bce487
Adjust coding style.
absyntax/absyntax.cc
absyntax/absyntax.hh
--- a/absyntax/absyntax.cc	Sat Sep 08 10:44:04 2012 +0100
+++ b/absyntax/absyntax.cc	Thu Sep 13 17:12:40 2012 +0100
@@ -82,21 +82,33 @@
 list_c::list_c(
                int fl, int fc, const char *ffile, long int forder,
                int ll, int lc, const char *lfile, long int lorder)
-  :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*))) {}
+  :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*));
+  if (NULL == elements) ERROR_MSG("out of memory");
+}
+
 
 list_c::list_c(symbol_c *elem, 
                int fl, int fc, const char *ffile, long int forder,
                int ll, int lc, const char *lfile, long int lorder)
-  :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*))) 
-  { add_element(elem); }
+  :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*));
+  if (NULL == elements) ERROR_MSG("out of memory");
+  add_element(elem); 
+}
+
 
 /* append a new element to the end of the list */
 void list_c::add_element(symbol_c *elem) {
   // printf("list_c::add_element()\n");
-  if((c <= n) && !(elements=(symbol_c**)realloc(elements,(c+=LIST_CAP_INCR)*sizeof(symbol_c *)))) ERROR_MSG("out of memory");
+  if (c <= n)
+    if (!(elements=(symbol_c**)realloc(elements,(c+=LIST_CAP_INCR)*sizeof(symbol_c *))))
+      ERROR_MSG("out of memory");
   elements[n++] = elem;
  
-  if(elem == NULL) return;
+  if (NULL == elem) return;
 
   /* adjust the location parameters, taking into account the new element. */
   if ((first_line == elem->first_line) &&
--- a/absyntax/absyntax.hh	Sat Sep 08 10:44:04 2012 +0100
+++ b/absyntax/absyntax.hh	Thu Sep 13 17:12:40 2012 +0100
@@ -166,7 +166,7 @@
  /* a list of symbols... */
 class list_c: public symbol_c {
   public:
-    int c,n;
+    int c,n; /* c: current capacity of list (malloc'd memory);  n: current number of elements in list */
     symbol_c **elements;
 
   public: