name.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. name_find
  2. name_append
  3. name_list_free
  4. name_set_decl
  5. name_set_def
  6. name_set_proc
  7. name_set_glo_var
  8. name_set_loc_var
  9. name_get_stat
  10. name_get_type
  11. name_set_id
  12. name_get_id
  13. name_get_str

   1 #include <stddef.h>
   2 #include <stdlib.h>
   3 #include <stdio.h>
   4 
   5 #include "name.h"
   6 
   7 struct name_info_ {
   8   char *str;
   9   name_stat stat;
  10   name_type type;
  11   int idnum;
  12 };
  13 
  14 struct name_list_ {
  15   name_info info;
  16   name_list *next;
  17 };
  18 
  19 name_info *
  20 name_find(name_list *p, char const s[])
     /* [<][>][^][v][top][bottom][index][help] */
  21 {
  22   name_list *index;
  23 
  24   index = p;
  25 
  26   while (index != 0)
  27     {
  28       if (strcmp(s, index->info.str) == 0)
  29         break;
  30 
  31       index = index->next;
  32     }
  33 
  34   return (index == 0) ? 0 : (&(index->info));
  35 }
  36 
  37 name_list *
  38 name_append(name_list *p, char *s)
     /* [<][>][^][v][top][bottom][index][help] */
  39 {
  40   name_list *newname;
  41 
  42   newname = malloc(sizeof(name_list));
  43   newname->info.str = s;
  44   newname->info.stat = NAME_UNKNOWN;
  45   newname->info.idnum = 0;
  46   newname->next = p;
  47 
  48   return newname;
  49 }
  50 
  51 void
  52 name_list_free(name_list *p)
     /* [<][>][^][v][top][bottom][index][help] */
  53 {
  54   name_list *next;
  55 
  56   while (p != 0)
  57     {
  58       next = p->next;;
  59       free(p->info.str);
  60       free(p);
  61       p = next;
  62     }
  63 }
  64 
  65 void
  66 name_set_decl(name_info *p)
     /* [<][>][^][v][top][bottom][index][help] */
  67 {
  68   p->stat = NAME_DECLARED;
  69 }
  70 
  71 void
  72 name_set_def(name_info *p)
     /* [<][>][^][v][top][bottom][index][help] */
  73 {
  74   p->stat = NAME_DEFINED;
  75 }
  76 
  77 void
  78 name_set_proc(name_info *p)
     /* [<][>][^][v][top][bottom][index][help] */
  79 {
  80   p->type = NAME_PROC;
  81 }
  82 
  83 void
  84 name_set_glo_var(name_info *p)
     /* [<][>][^][v][top][bottom][index][help] */
  85 {
  86   p->type = NAME_GLO_VAR;
  87 }
  88 
  89 void
  90 name_set_loc_var(name_info *p)
     /* [<][>][^][v][top][bottom][index][help] */
  91 {
  92   p->type = NAME_LOC_VAR;
  93 }
  94 
  95 name_stat
  96 name_get_stat(name_info const *p)
     /* [<][>][^][v][top][bottom][index][help] */
  97 {
  98   return p->stat;
  99 }
 100 
 101 name_type
 102 name_get_type(name_info const *p)
     /* [<][>][^][v][top][bottom][index][help] */
 103 {
 104   return p->type;
 105 }
 106 
 107 void
 108 name_set_id(name_info *p, int id)
     /* [<][>][^][v][top][bottom][index][help] */
 109 {
 110   p->idnum = id;
 111 }
 112 
 113 int
 114 name_get_id(name_info const *p)
     /* [<][>][^][v][top][bottom][index][help] */
 115 {
 116   return p->idnum;
 117 }
 118 
 119 char const *
 120 name_get_str(name_info const *p)
     /* [<][>][^][v][top][bottom][index][help] */
 121 {
 122   return p->str;
 123 }

/* [<][>][^][v][top][bottom][index][help] */