home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 5.ddi / PARSER.ZIP / NODE.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-23  |  1.8 KB  |  71 lines

  1. // the node class is central to date representation.
  2. // Everything it knows is in a node.
  3.  
  4. enum node_flavor {  //state the derived type from a node
  5.    nf_base, nf_type, nf_def
  6.    };
  7.  
  8. class node {
  9. protected:
  10.    node();
  11.    virtual ~node();
  12. public:
  13.    node_flavor flavor;
  14.    virtual void print();
  15.    };
  16.  
  17. enum primary_t { type_void, type_char, type_int, type_long, type_float, type_double, type_ldouble, type_enum, type_class, type_union, type_pointer, type_reference, type_array, type_function };
  18.  
  19. class def_node_list;  //forward ref
  20.  
  21. class type_node : public node {
  22. public:
  23.    type_node* to_what;
  24.    type_node ();
  25.    ~type_node();
  26.    void print();
  27.    unsigned flags;
  28.    primary_t primary;
  29.    node* secondary() { return to_what; }
  30.    atom tag;
  31.    def_node_list* aggr;
  32.    void stuff_primary (int x, atom tagname);
  33.    bool isConst() { return flags&1; }
  34.    bool isVol() { return flags&2; }
  35.    bool isNear() { return flags&4; }
  36.    bool isFar() { return flags&8; }
  37.    bool isUnsigned() { return flags&16; }
  38.    };
  39.  
  40. class def_node : public node {
  41. public:
  42.    atom name;
  43.    int storage_class;
  44.    type_node* type;
  45.    void print();
  46.    def_node (atom n, int store, type_node* t);
  47.    };
  48.  
  49. /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
  50. /*     lists of nodes                       */
  51. /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
  52.  
  53. class node_list {
  54.    node** list;
  55.    int capacity;
  56.    int count;
  57. public:
  58.    node_list();
  59.    ~node_list() { delete list; }
  60.    node** access (int x);
  61.    int size() { return count; }
  62.    void add(node* n) { *access(count++) = n; }
  63.    };
  64.  
  65. #define create_list(TYPE) class TYPE##_node_list : public node_list { \
  66. public:\
  67. TYPE##_node*& operator[] (int x) { return *(TYPE##_node **)access(x); } }
  68.  
  69. create_list (type);
  70. create_list (def);
  71.