From a580e28c0c2cc36481875c4d874bb4b8c956538f Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 9 Dec 2024 20:49:10 +0100 Subject: [PATCH] Format. --- util/grind/avl.cc | 316 +++++++++++++++-------------- util/grind/itemlist.cc | 439 ++++++++++++++++++++++------------------- util/grind/langdep.cc | 70 +++---- util/grind/scope.cc | 163 ++++++++------- 4 files changed, 518 insertions(+), 470 deletions(-) diff --git a/util/grind/avl.cc b/util/grind/avl.cc index ffef4ac9f..1407ead51 100644 --- a/util/grind/avl.cc +++ b/util/grind/avl.cc @@ -12,12 +12,11 @@ So, a node has the following structure: */ -struct avl_node { - struct avl_node - *left, - *right; /* the left and right branches */ - char *info; /* pointer to information in this node */ - char balance; /* balance information described above */ +struct avl_node +{ + struct avl_node *left, *right; /* the left and right branches */ + char* info; /* pointer to information in this node */ + char balance; /* balance information described above */ }; /* create definitions for new_avl_node() and free_avl_node() */ @@ -27,10 +26,10 @@ struct avl_node { the address of a user-supplied comparison routine: */ -struct avl_tree { - struct avl_node - *root; /* root of the avl tree */ - int (*cmp)(); /* address of comparison routine */ +struct avl_tree +{ + struct avl_node* root; /* root of the avl tree */ + int (*cmp)(); /* address of comparison routine */ }; /* create definitions for new_avl_tree() and free_avl_tree() */ /* STATICALLOCDEF "avl_tree" 2 */ @@ -38,208 +37,227 @@ struct avl_tree { /* The next routine adds a node to an avl tree. It returns 1 if the tree got deeper. */ -static int -balance_add(ppsc, n, cmp) - struct avl_node **ppsc; /* address of root */ - char *n; /* user-supplied information */ - int (*cmp)(); /* user-supplied comparison routine */ +static int balance_add(ppsc, n, cmp) +struct avl_node** ppsc; /* address of root */ +char* n; /* user-supplied information */ +int (*cmp)(); /* user-supplied comparison routine */ { - struct avl_node *psc = *ppsc, *qsc, *ssc; - - if (! psc) { - *ppsc = new_avl_node(); - (*ppsc)->balance = '.'; - (*ppsc)->info = n; - return 1; - } - if ((*cmp)(n, psc->info) < 0) { - if (balance_add(&(psc->left), n, cmp)) { - /* left hand side got deeper */ - if (psc->balance == '+') { - /* but the right hand side was deeper */ + struct avl_node *psc = *ppsc, *qsc, *ssc; + + if (!psc) + { + *ppsc = new_avl_node(); + (*ppsc)->balance = '.'; + (*ppsc)->info = n; + return 1; + } + if ((*cmp)(n, psc->info) < 0) + { + if (balance_add(&(psc->left), n, cmp)) + { + /* left hand side got deeper */ + if (psc->balance == '+') + { + /* but the right hand side was deeper */ + psc->balance = '.'; + return 0; + } + if (psc->balance == '.') + { + /* but the right hand side was as deep */ + psc->balance = '-'; + return 1; + } + /* left hand side already was one deeper; re-organize */ + qsc = psc->left; + if (qsc->balance == '-') + { + /* if left-hand side of left node was deeper, + this node becomes the new root + */ + psc->balance = '.'; + qsc->balance = '.'; + psc->left = qsc->right; + qsc->right = psc; + *ppsc = qsc; + return 0; + } + /* else the right node of the left node becomes the new root */ + ssc = qsc->right; + psc->left = ssc->right; + qsc->right = ssc->left; + ssc->left = qsc; + ssc->right = psc; + *ppsc = ssc; + if (ssc->balance == '.') + { + psc->balance = '.'; + qsc->balance = '.'; + return 0; + } + if (ssc->balance == '-') + { + psc->balance = '+'; + qsc->balance = '.'; + ssc->balance = '.'; + return 0; + } + psc->balance = '.'; + qsc->balance = '-'; + } + return 0; + } + if (balance_add(&(psc->right), n, cmp)) + { + /* right hand side got deeper */ + if (psc->balance == '-') + { + /* but the left hand side was deeper */ psc->balance = '.'; return 0; } - if (psc->balance == '.') { - /* but the right hand side was as deep */ - psc->balance = '-'; + if (psc->balance == '.') + { + /* but the left hand side as deep */ + psc->balance = '+'; return 1; } - /* left hand side already was one deeper; re-organize */ - qsc = psc->left; - if (qsc->balance == '-') { - /* if left-hand side of left node was deeper, + /* right hand side already was one deeper; re-organize */ + qsc = psc->right; + if (qsc->balance == '+') + { + /* if right-hand side of left node was deeper, this node becomes the new root */ psc->balance = '.'; qsc->balance = '.'; - psc->left = qsc->right; - qsc->right = psc; + psc->right = qsc->left; + qsc->left = psc; *ppsc = qsc; return 0; } - /* else the right node of the left node becomes the new root */ - ssc = qsc->right; - psc->left = ssc->right; - qsc->right = ssc->left; - ssc->left = qsc; - ssc->right = psc; + /* else the left node of the right node becomes the new root */ + ssc = qsc->left; + psc->right = ssc->left; + qsc->left = ssc->right; + ssc->right = qsc; + ssc->left = psc; *ppsc = ssc; - if (ssc->balance == '.') { + if (ssc->balance == '.') + { psc->balance = '.'; qsc->balance = '.'; return 0; } - if (ssc->balance == '-') { - psc->balance = '+'; + if (ssc->balance == '+') + { + psc->balance = '-'; qsc->balance = '.'; ssc->balance = '.'; return 0; } psc->balance = '.'; - qsc->balance = '-'; + qsc->balance = '+'; } return 0; - } - if (balance_add(&(psc->right), n, cmp)) { - /* right hand side got deeper */ - if (psc->balance == '-') { - /* but the left hand side was deeper */ - psc->balance = '.'; - return 0; - } - if (psc->balance == '.') { - /* but the left hand side as deep */ - psc->balance = '+'; - return 1; - } - /* right hand side already was one deeper; re-organize */ - qsc = psc->right; - if (qsc->balance == '+') { - /* if right-hand side of left node was deeper, - this node becomes the new root - */ - psc->balance = '.'; - qsc->balance = '.'; - psc->right = qsc->left; - qsc->left = psc; - *ppsc = qsc; - return 0; - } - /* else the left node of the right node becomes the new root */ - ssc = qsc->left; - psc->right = ssc->left; - qsc->left = ssc->right; - ssc->right = qsc; - ssc->left = psc; - *ppsc = ssc; - if (ssc->balance == '.') { - psc->balance = '.'; - qsc->balance = '.'; - return 0; - } - if (ssc->balance == '+') { - psc->balance = '-'; - qsc->balance = '.'; - ssc->balance = '.'; - return 0; - } - psc->balance = '.'; - qsc->balance = '+'; - } - return 0; } /* extern struct avl_tree *create_avl_tree(int (*cmp)()); Returns a fresh avl_tree structure. */ -struct avl_tree * -create_avl_tree(cmp) - int (*cmp)(); /* comparison routine */ +struct avl_tree* create_avl_tree(cmp) int (*cmp)(); /* comparison routine */ { - struct avl_tree *p = new_avl_tree(); + struct avl_tree* p = new_avl_tree(); - p->cmp = cmp; - return p; + p->cmp = cmp; + return p; } /* extern add_to_avl_tree(struct avl_tree *tree, char *n); Adds the information indicated by 'n' to the avl_tree indicated by 'tree' */ -add_to_avl_tree(tree, n) - struct avl_tree *tree; /* tree to be added to */ - char *n; /* information */ +add_to_avl_tree(tree, n) struct avl_tree* tree; /* tree to be added to */ +char* n; /* information */ { - (void) balance_add(&(tree->root), n, tree->cmp); + (void)balance_add(&(tree->root), n, tree->cmp); } /* extern char *find_ngt(struct avl_tree *tree, char *n); Returns the information in the largest node that still compares <= to 'n', or 0 if not present. */ -char * -find_ngt(tree, n) - struct avl_tree *tree; /* tree to be searched in */ - char *n; /* information to be compared with */ +char* find_ngt(tree, n) +struct avl_tree* tree; /* tree to be searched in */ +char* n; /* information to be compared with */ { - struct avl_node *nd = tree->root, *lastnd = 0; + struct avl_node *nd = tree->root, *lastnd = 0; - for (;;) { - while (nd && (*tree->cmp)(nd->info, n) > 0) { - nd = nd->left; - } - while (nd && (*tree->cmp)(nd->info, n) <= 0) { - lastnd = nd; - nd = nd->right; + for (;;) + { + while (nd && (*tree->cmp)(nd->info, n) > 0) + { + nd = nd->left; + } + while (nd && (*tree->cmp)(nd->info, n) <= 0) + { + lastnd = nd; + nd = nd->right; + } + if (!nd) + break; } - if (! nd) break; - } - return lastnd ? lastnd->info : (char *) 0; + return lastnd ? lastnd->info : (char*)0; } /* extern char *find_nlt(struct avl_tree *tree, char *n); Returns the information in the largest node that still compares >= to 'n', or 0 if not present. */ -char * -find_nlt(tree, n) - struct avl_tree *tree; /* tree to be searched in */ - char *n; /* information to be compared with */ +char* find_nlt(tree, n) +struct avl_tree* tree; /* tree to be searched in */ +char* n; /* information to be compared with */ { - struct avl_node *nd = tree->root, *lastnd = 0; + struct avl_node *nd = tree->root, *lastnd = 0; - for (;;) { - while (nd && (*tree->cmp)(nd->info, n) < 0) { - nd = nd->right; - } - while (nd && (*tree->cmp)(nd->info, n) >= 0) { - lastnd = nd; - nd = nd->left; + for (;;) + { + while (nd && (*tree->cmp)(nd->info, n) < 0) + { + nd = nd->right; + } + while (nd && (*tree->cmp)(nd->info, n) >= 0) + { + lastnd = nd; + nd = nd->left; + } + if (!nd) + break; } - if (! nd) break; - } - return lastnd ? lastnd->info : (char *) 0; + return lastnd ? lastnd->info : (char*)0; } /* extern char *find_eq(struct avl_tree *tree, char *n); Returns the information in the node that compares equal to 'n', or 0 if not present. */ -char * -find_eq(tree, n) - struct avl_tree *tree; /* tree to be searched in */ - char *n; /* information to be compared with */ +char* find_eq(tree, n) +struct avl_tree* tree; /* tree to be searched in */ +char* n; /* information to be compared with */ { - struct avl_node *nd = tree->root; + struct avl_node* nd = tree->root; - for (;;) { - while (nd && (*tree->cmp)(nd->info, n) < 0) { - nd = nd->right; - } - while (nd && (*tree->cmp)(nd->info, n) > 0) { - nd = nd->left; + for (;;) + { + while (nd && (*tree->cmp)(nd->info, n) < 0) + { + nd = nd->right; + } + while (nd && (*tree->cmp)(nd->info, n) > 0) + { + nd = nd->left; + } + if (!nd) + break; } - if (! nd) break; - } - return nd ? nd->info : (char *) 0; + return nd ? nd->info : (char*)0; } diff --git a/util/grind/itemlist.cc b/util/grind/itemlist.cc index e35238b0c..c6a0a41e3 100644 --- a/util/grind/itemlist.cc +++ b/util/grind/itemlist.cc @@ -9,267 +9,302 @@ #include "operator.h" #include "misc.h" -extern FILE *db_out; -extern int db_ss; +extern FILE* db_out; +extern int db_ss; -typedef struct item { - struct item *i_next; - struct tree *i_node; - int i_disabled; - int i_itemno; +typedef struct item +{ + struct item* i_next; + struct tree* i_node; + int i_disabled; + int i_itemno; } t_item, *p_item; /* STATICALLOCDEF "item" 10 */ -struct itemlist { - p_item il_first, il_last; +struct itemlist +{ + p_item il_first, il_last; }; -static struct itemlist item_list; -static int stop_reason; -int item_count; +static struct itemlist item_list; +static int stop_reason; +int item_count; -static int -in_item_list(p) - p_tree p; +static int in_item_list(p) +p_tree p; { - p_item i = item_list.il_first; + p_item i = item_list.il_first; - while (i) { - if (i->i_node == p) return 1; - i = i->i_next; - } - return 0; + while (i) + { + if (i->i_node == p) + return 1; + i = i->i_next; + } + return 0; } -static -pr_item(i) - p_item i; +static pr_item(i) p_item i; { - fprintf(db_out, "(%d)\t", i->i_itemno); - print_node(db_out, i->i_node, 0); - fputs(i->i_disabled ? " (disabled)\n": "\n", db_out); + fprintf(db_out, "(%d)\t", i->i_itemno); + print_node(db_out, i->i_node, 0); + fputs(i->i_disabled ? " (disabled)\n" : "\n", db_out); } -int -item_addr_actions(a, mess_type, may_stop) - t_addr a; - int mess_type; - int may_stop; +int item_addr_actions(a, mess_type, may_stop) +t_addr a; +int mess_type; +int may_stop; { - /* Perform actions associated with position 'a', and return stop_reason - if we must stop there, and 0 if not. - */ - p_item i = item_list.il_first; + /* Perform actions associated with position 'a', and return stop_reason + if we must stop there, and 0 if not. + */ + p_item i = item_list.il_first; - stop_reason = 0; - for (i = item_list.il_first; i != 0; i = i->i_next) { - register p_tree p = i->i_node; + stop_reason = 0; + for (i = item_list.il_first; i != 0; i = i->i_next) + { + register p_tree p = i->i_node; - if (! i->i_disabled - && (p->t_address == a || p->t_address == NO_ADDR)) { - switch(p->t_oper) { - case OP_STOP: - if (mess_type != 1) break; - if (! p->t_args[1] || eval_cond(p->t_args[1])) { - if (! stop_reason) stop_reason = i->i_itemno; + if (!i->i_disabled && (p->t_address == a || p->t_address == NO_ADDR)) + { + switch (p->t_oper) + { + case OP_STOP: + if (mess_type != 1) + break; + if (!p->t_args[1] || eval_cond(p->t_args[1])) + { + if (!stop_reason) + stop_reason = i->i_itemno; + } + break; + case OP_TRACE: + case OP_WHEN: + case OP_DUMP: + case OP_DISPLAY: + break; + default: + assert(0); } - break; - case OP_TRACE: - case OP_WHEN: - case OP_DUMP: - case OP_DISPLAY: - break; - default: - assert(0); } } - } - for (i = item_list.il_first; i != 0; i = i->i_next) { - register p_tree p = i->i_node; + for (i = item_list.il_first; i != 0; i = i->i_next) + { + register p_tree p = i->i_node; - if (! i->i_disabled - && (p->t_address == a || p->t_address == NO_ADDR)) { - switch(p->t_oper) { - case OP_TRACE: - if ((! stop_reason && mess_type != 0) - || p->t_args[2] || ! may_stop) { - perform(p, a); + if (!i->i_disabled && (p->t_address == a || p->t_address == NO_ADDR)) + { + switch (p->t_oper) + { + case OP_TRACE: + if ((!stop_reason && mess_type != 0) || p->t_args[2] || !may_stop) + { + perform(p, a); + } + break; + case OP_WHEN: + perform(p, a); + break; + case OP_STOP: + case OP_DUMP: + case OP_DISPLAY: + break; + default: + assert(0); } - break; - case OP_WHEN: - perform(p, a); - break; - case OP_STOP: - case OP_DUMP: - case OP_DISPLAY: - break; - default: - assert(0); } } - } - return stop_reason; + return stop_reason; } handle_displays() { - p_item i = item_list.il_first; + p_item i = item_list.il_first; - while (i) { - register p_tree p = i->i_node; + while (i) + { + register p_tree p = i->i_node; - if (! i->i_disabled && p->t_oper == OP_DISPLAY) do_print(p); - i = i->i_next; - } + if (!i->i_disabled && p->t_oper == OP_DISPLAY) + do_print(p); + i = i->i_next; + } } -add_to_item_list(p) - p_tree p; +add_to_item_list(p) p_tree p; { - p_item i; - - if (in_item_list(p)) return; + p_item i; - i = new_item(); - i->i_node = p; - if (p->t_address == NO_ADDR - && (p->t_oper != OP_TRACE || ! p->t_args[0])) db_ss++; - if (item_list.il_first == 0) { - item_list.il_first = i; - } - else { - item_list.il_last->i_next = i; - } - i->i_itemno = ++item_count; - item_list.il_last = i; - pr_item(i); + if (in_item_list(p)) + return; + + i = new_item(); + i->i_node = p; + if (p->t_address == NO_ADDR && (p->t_oper != OP_TRACE || !p->t_args[0])) + db_ss++; + if (item_list.il_first == 0) + { + item_list.il_first = i; + } + else + { + item_list.il_last->i_next = i; + } + i->i_itemno = ++item_count; + item_list.il_last = i; + pr_item(i); } -remove_from_item_list(n) - int n; +remove_from_item_list(n) int n; { - p_item i = item_list.il_first, prev = 0; - p_tree p; + p_item i = item_list.il_first, prev = 0; + p_tree p; - if (n == 0) { - n = stop_reason; - if (n == 0) { - error("no current stopping point"); + if (n == 0) + { + n = stop_reason; + if (n == 0) + { + error("no current stopping point"); + return; + } + stop_reason = 0; + } + if (n < 0) + n = item_count + n + 1; + while (i) + { + if (i->i_itemno == n) + break; + prev = i; + i = i->i_next; + } + if (!i) + { + error("no item %d in current status", n); return; } - stop_reason = 0; - } - if (n < 0) n = item_count + n + 1; - while (i) { - if (i->i_itemno == n) break; - prev = i; - i = i->i_next; - } - if (! i) { - error("no item %d in current status", n); - return; - } - if (i->i_itemno == stop_reason) stop_reason = 0; - if (prev) { - prev->i_next = i->i_next; - } - else item_list.il_first = i->i_next; - if (i == item_list.il_last) item_list.il_last = prev; - p = i->i_node; - if (p->t_address == NO_ADDR - && (p->t_oper != OP_TRACE || ! p->t_args[0])) db_ss--; - free_item(i); - switch(p->t_oper) { - case OP_STOP: - case OP_WHEN: - (void) setstop(p, 0); - break; - case OP_TRACE: - (void) settrace(p, 0); - break; - case OP_DUMP: - free_dump(p); - break; - } - freenode(p); + if (i->i_itemno == stop_reason) + stop_reason = 0; + if (prev) + { + prev->i_next = i->i_next; + } + else + item_list.il_first = i->i_next; + if (i == item_list.il_last) + item_list.il_last = prev; + p = i->i_node; + if (p->t_address == NO_ADDR && (p->t_oper != OP_TRACE || !p->t_args[0])) + db_ss--; + free_item(i); + switch (p->t_oper) + { + case OP_STOP: + case OP_WHEN: + (void)setstop(p, 0); + break; + case OP_TRACE: + (void)settrace(p, 0); + break; + case OP_DUMP: + free_dump(p); + break; + } + freenode(p); } -p_tree -get_from_item_list(n) - int n; +p_tree get_from_item_list(n) +int n; { - p_item i = item_list.il_first; + p_item i = item_list.il_first; - if (n == 0) { - n = stop_reason; - if (n == 0) return 0; - } - if (n < 0) n = item_count + n + 1; - while (i) { - if (i->i_itemno == n) return i->i_node; - i = i->i_next; - } - return 0; + if (n == 0) + { + n = stop_reason; + if (n == 0) + return 0; + } + if (n < 0) + n = item_count + n + 1; + while (i) + { + if (i->i_itemno == n) + return i->i_node; + i = i->i_next; + } + return 0; } -able_item(n, kind) - int n; +able_item(n, kind) int n; { - p_item i = item_list.il_first; - p_tree p; + p_item i = item_list.il_first; + p_tree p; - if (n == 0) { - n = stop_reason; - if (n == 0) { - error("no current stopping point"); + if (n == 0) + { + n = stop_reason; + if (n == 0) + { + error("no current stopping point"); + return; + } + } + if (n < 0) + n = item_count + n + 1; + while (i) + { + if (i->i_itemno == n) + break; + i = i->i_next; + } + if (!i) + { + error("no item %d in current status", n); + return; + } + p = i->i_node; + if (i->i_disabled == kind) + { + warning("item %d already %sabled", n, kind ? "dis" : "en"); return; } - } - if (n < 0) n = item_count + n + 1; - while (i) { - if (i->i_itemno == n) break; - i = i->i_next; - } - if (! i) { - error("no item %d in current status", n); - return; - } - p = i->i_node; - if (i->i_disabled == kind) { - warning("item %d already %sabled", n, kind ? "dis" : "en"); - return; - } - if (p->t_address == NO_ADDR - && (p->t_oper != OP_TRACE || ! p->t_args[0])) { - db_ss += kind == 1 ? (-1) : 1; - } - i->i_disabled = kind; - switch(p->t_oper) { - case OP_STOP: - case OP_WHEN: - (void) setstop(p, ! kind); - break; - case OP_TRACE: - (void) settrace(p, ! kind); - break; - } + if (p->t_address == NO_ADDR && (p->t_oper != OP_TRACE || !p->t_args[0])) + { + db_ss += kind == 1 ? (-1) : 1; + } + i->i_disabled = kind; + switch (p->t_oper) + { + case OP_STOP: + case OP_WHEN: + (void)setstop(p, !kind); + break; + case OP_TRACE: + (void)settrace(p, !kind); + break; + } } print_items() { - p_item i = item_list.il_first; + p_item i = item_list.il_first; - for (; i; i = i->i_next) { - pr_item(i); - } + for (; i; i = i->i_next) + { + pr_item(i); + } } perform_items() { - p_item i = item_list.il_first; + p_item i = item_list.il_first; - for (; i; i = i->i_next) { - if (! i->i_disabled && i->i_node->t_oper != OP_DUMP) eval(i->i_node); - } + for (; i; i = i->i_next) + { + if (!i->i_disabled && i->i_node->t_oper != OP_DUMP) + eval(i->i_node); + } } diff --git a/util/grind/langdep.cc b/util/grind/langdep.cc index 0721fc737..ff94f1cd4 100644 --- a/util/grind/langdep.cc +++ b/util/grind/langdep.cc @@ -2,53 +2,55 @@ #include "langdep.h" -struct langlist { - struct langlist *l_next; - struct langdep *l_lang; - char *l_suff; +struct langlist +{ + struct langlist* l_next; + struct langdep* l_lang; + char* l_suff; }; /* STATICALLOCDEF "langlist" 5 */ -static struct langlist *list; +static struct langlist* list; -struct langdep *currlang; +struct langdep* currlang; -static void -add_language(suff, lang) - char *suff; - struct langdep *lang; +static void add_language(suff, lang) char* suff; +struct langdep* lang; { - struct langlist *p = new_langlist(); + struct langlist* p = new_langlist(); - p->l_next = list; - p->l_suff = suff; - p->l_lang = lang; - list = p; + p->l_next = list; + p->l_suff = suff; + p->l_lang = lang; + list = p; } init_languages() { - add_language(".p", pascal_dep); - add_language(".mod", m2_dep); - add_language(".c", c_dep); + add_language(".p", pascal_dep); + add_language(".mod", m2_dep); + add_language(".c", c_dep); } -find_language(suff) - char *suff; +find_language(suff) char* suff; { - struct langlist *p = list; - - if (! suff) { - currlang = c_dep; - return; - } - while (p) { - currlang = p->l_lang; - if (! strcmp(p->l_suff, suff)) break; - p = p->l_next; - } - if (! currlang) { - currlang = c_dep; - } + struct langlist* p = list; + + if (!suff) + { + currlang = c_dep; + return; + } + while (p) + { + currlang = p->l_lang; + if (!strcmp(p->l_suff, suff)) + break; + p = p->l_next; + } + if (!currlang) + { + currlang = c_dep; + } } diff --git a/util/grind/scope.cc b/util/grind/scope.cc index e98f9d836..19ef70917 100644 --- a/util/grind/scope.cc +++ b/util/grind/scope.cc @@ -2,89 +2,81 @@ /* Scope mechanism */ -#include -#include -#include - -#include "position.h" -#include "file.h" -#include "idf.h" -#include "type.h" -#include "symbol.h" -#include "scope.h" -#include "avl.h" +#include +#include +#include + +#include "position.h" +#include "file.h" +#include "idf.h" +#include "type.h" +#include "symbol.h" +#include "scope.h" +#include "avl.h" p_scope PervasiveScope, CurrentScope, FileScope; /* STATICALLOCDEF "scope" 10 */ -static AVL_tree ScopeTree; +static AVL_tree ScopeTree; -static int -cmp_starts(s1, s2) - char *s1, *s2; +static int cmp_starts(s1, s2) +char *s1, *s2; { - p_scope c1 = (p_scope)s1, c2 = (p_scope)s2; + p_scope c1 = (p_scope)s1, c2 = (p_scope)s2; - return c1->sc_start < c2->sc_start - ? -1 - : c1->sc_start == c2->sc_start - ? 0 - : 1; + return c1->sc_start < c2->sc_start ? -1 : c1->sc_start == c2->sc_start ? 0 : 1; } /*ARGSUSED*/ -open_scope(name, has_activation) - p_symbol name; - int has_activation; +open_scope(name, has_activation) p_symbol name; +int has_activation; { - p_scope sc = new_scope(); - - sc->sc_has_activation_record = has_activation; - sc->sc_static_encl = CurrentScope; - sc->sc_definedby = name; - sc->sc_proclevel = CurrentScope->sc_proclevel; - /* sc_proclevel possibly reset by caller */ - CurrentScope = sc; + p_scope sc = new_scope(); + + sc->sc_has_activation_record = has_activation; + sc->sc_static_encl = CurrentScope; + sc->sc_definedby = name; + sc->sc_proclevel = CurrentScope->sc_proclevel; + /* sc_proclevel possibly reset by caller */ + CurrentScope = sc; } init_scope() { - p_scope sc = new_scope(); - - PervasiveScope = sc; - CurrentScope = sc; - open_scope((p_symbol) 0, 0); /* this one will be closed at the - first N_SO - */ - ScopeTree = create_avl_tree(cmp_starts); + p_scope sc = new_scope(); + + PervasiveScope = sc; + CurrentScope = sc; + open_scope((p_symbol)0, 0); /* this one will be closed at the + first N_SO + */ + ScopeTree = create_avl_tree(cmp_starts); } close_scope() { - p_scope sc = CurrentScope; + p_scope sc = CurrentScope; - assert(sc != 0); - CurrentScope = sc->sc_static_encl; + assert(sc != 0); + CurrentScope = sc->sc_static_encl; } -add_scope_addr(scope) - p_scope scope; +add_scope_addr(scope) p_scope scope; { - add_to_avl_tree(ScopeTree, (char *)scope); + add_to_avl_tree(ScopeTree, (char*)scope); } /* extern p_scope get_scope_from_addr(t_addr a); Returns the scope of the code at address 'a', or 0 if it could not be found. */ -p_scope -get_scope_from_addr(a) - t_addr a; +p_scope get_scope_from_addr(a) +t_addr a; { - t_scope sc; + t_scope sc; - sc.sc_start = a; - return (p_scope) find_ngt(ScopeTree, (char *) &sc); + sc.sc_start = a; + return (p_scope)find_ngt(ScopeTree, (char*)&sc); } /* extern p_scope get_next_scope_from_addr(t_addr a); @@ -92,56 +84,57 @@ get_scope_from_addr(a) and that has an activation record, or 0 if it could not be found. */ -p_scope -get_next_scope_from_addr(a) - t_addr a; +p_scope get_next_scope_from_addr(a) +t_addr a; { - t_scope sc; - - sc.sc_start = a; - for (;;) { - p_scope psc = (p_scope) find_nlt(ScopeTree, (char *) &sc); - if (! psc || psc->sc_has_activation_record) return psc; - sc.sc_start = psc->sc_start+1; - } - /*NOTREACHED*/ + t_scope sc; + + sc.sc_start = a; + for (;;) + { + p_scope psc = (p_scope)find_nlt(ScopeTree, (char*)&sc); + if (!psc || psc->sc_has_activation_record) + return psc; + sc.sc_start = psc->sc_start + 1; + } + /*NOTREACHED*/ } /* extern int has_static_link(p_scope sc); Returns 1 if the procedure of this scope takes a static link. */ -int -has_static_link(sc) - p_scope sc; +int has_static_link(sc) +p_scope sc; { - return sc->sc_proclevel > 1; + return sc->sc_proclevel > 1; } /* extern p_scope base_scope(p_scope sc); Returns the closest enclosing scope of 'sc' that has an activation record. */ -p_scope -base_scope(sc) - p_scope sc; +p_scope base_scope(sc) +p_scope sc; { - while (sc && ! sc->sc_has_activation_record) { - sc = sc->sc_static_encl; - } - return sc; + while (sc && !sc->sc_has_activation_record) + { + sc = sc->sc_static_encl; + } + return sc; } /* extern int scope_encloses(p_scope scope, from_scope); Returns 1 if scope encloses from from_scope, 0 otherwise. */ -int -scope_encloses(scope, from_scope) - p_scope scope, from_scope; +int scope_encloses(scope, from_scope) +p_scope scope, from_scope; { - p_scope sc = from_scope; - - while (sc) { - if (sc == scope) return 1; - sc = sc->sc_static_encl; - } - return 0; + p_scope sc = from_scope; + + while (sc) + { + if (sc == scope) + return 1; + sc = sc->sc_static_encl; + } + return 0; }