stage4/generate_c/search_base_type.cc
changeset 98 d0cdf1d00b74
parent 70 e1f0ebd2d9ec
child 123 a9b4af71cfa4
equal deleted inserted replaced
97:55ffcf693d6d 98:d0cdf1d00b74
    36  *    new_subr_t is also really an INT!!
    36  *    new_subr_t is also really an INT!!
    37  */
    37  */
    38 class search_base_type_c: public null_visitor_c {
    38 class search_base_type_c: public null_visitor_c {
    39   private:
    39   private:
    40     symbol_c *current_type_name;
    40     symbol_c *current_type_name;
       
    41     bool is_subrange;
    41 
    42 
    42   public:
    43   public:
    43     search_base_type_c(void) {current_type_name = NULL;}
    44     search_base_type_c(void) {current_type_name = NULL;}
       
    45     bool base_is_subrange() {return this->is_subrange;}
    44 
    46 
    45   public:
    47   public:
    46     void *visit(identifier_c *type_name) {
    48     void *visit(identifier_c *type_name) {
    47       this->current_type_name = type_name;
    49       this->current_type_name = type_name;
    48       /* look up the type declaration... */
    50       /* look up the type declaration... */
    49       symbol_c *type_decl = type_symtable.find_value(type_name);
    51       symbol_c *type_decl = type_symtable.find_value(type_name);
    50       if (type_decl == type_symtable.end_value())
    52       if (type_decl == type_symtable.end_value())
    51         /* Type declaration not found!! */
    53         /* Type declaration not found!! */
    52         ERROR;
    54         ERROR;
    53 
    55 
       
    56       return type_decl->accept(*this);
       
    57     }
       
    58     
       
    59     void *explore_type(symbol_c* type_decl) {
       
    60       this->is_subrange = false;
    54       return type_decl->accept(*this);
    61       return type_decl->accept(*this);
    55     }
    62     }
    56 
    63 
    57 /***********************************/
    64 /***********************************/
    58 /* B 1.3.1 - Elementary Data Types */
    65 /* B 1.3.1 - Elementary Data Types */
    98       return symbol->subrange_spec_init->accept(*this);
   105       return symbol->subrange_spec_init->accept(*this);
    99     }
   106     }
   100 
   107 
   101 /* subrange_specification ASSIGN signed_integer */
   108 /* subrange_specification ASSIGN signed_integer */
   102     void *visit(subrange_spec_init_c *symbol) {
   109     void *visit(subrange_spec_init_c *symbol) {
       
   110       this->is_subrange = true;
   103       return symbol->subrange_specification->accept(*this);
   111       return symbol->subrange_specification->accept(*this);
   104     }
   112     }
   105 
   113 
   106 /*  integer_type_name '(' subrange')' */
   114 /*  integer_type_name '(' subrange')' */
   107     void *visit(subrange_specification_c *symbol) {
   115     void *visit(subrange_specification_c *symbol) {
   146     }
   154     }
   147 
   155 
   148 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
   156 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
   149     void *visit(array_specification_c *symbol)	{
   157     void *visit(array_specification_c *symbol)	{
   150       if (NULL == this->current_type_name) ERROR;
   158       if (NULL == this->current_type_name) ERROR;
   151       return (void *)this->current_type_name;
   159       return symbol->non_generic_type_name->accept(*this);
   152     }
   160     }
   153 
   161 
   154 /* helper symbol for array_specification */
   162 /* helper symbol for array_specification */
   155 /* array_subrange_list ',' subrange */
   163 /* array_subrange_list ',' subrange */
   156     void *visit(array_subrange_list_c *symbol)	{ERROR; return NULL;} /* should never get called... */
   164     void *visit(array_subrange_list_c *symbol)	{ERROR; return NULL;} /* should never get called... */