absyntax_utils/absyntax_utils.cc
changeset 719 19595fce59f0
parent 596 4efb11e44065
child 726 9b61eb4f00dc
equal deleted inserted replaced
718:a9f8cc778444 719:19595fce59f0
   121  *
   121  *
   122  * The symbol_c * associated to the value will point to the data type declaration.
   122  * The symbol_c * associated to the value will point to the data type declaration.
   123  */
   123  */
   124 symbol_c null_symbol4;
   124 symbol_c null_symbol4;
   125 symtable_c<symbol_c *, &null_symbol4> type_symtable;
   125 symtable_c<symbol_c *, &null_symbol4> type_symtable;
   126 
       
   127 /* A symbol table with all values declared for enumerated type... */
       
   128 /* Notes:
       
   129  * - if the value is defined multiple times the value
       
   130  * is the null pointer.
       
   131  *
       
   132  * - The stored symbol_c * associated to the value points to the enumerated_type_name
       
   133  * (i.e. the name of the enumerated data type) in which the the value/identifier
       
   134  * is used/declared.
       
   135  *
       
   136  * - We could re-use the null_symbol4 object, but it is safer to use a distinct object
       
   137  *   (i.e. it might make it easier to find strange bugs).
       
   138  */
       
   139 symbol_c null_symbol5;
       
   140 symtable_c<symbol_c *, &null_symbol5> enumerated_value_symtable;
       
   141 
   126 
   142 
   127 
   143 /***********************************************************************/
   128 /***********************************************************************/
   144 /***********************************************************************/
   129 /***********************************************************************/
   145 /***********************************************************************/
   130 /***********************************************************************/
   218   /* enumerated_specification ASSIGN enumerated_value */
   203   /* enumerated_specification ASSIGN enumerated_value */
   219   void *visit(enumerated_spec_init_c *symbol) {
   204   void *visit(enumerated_spec_init_c *symbol) {
   220     return symbol->enumerated_specification->accept(*this);
   205     return symbol->enumerated_specification->accept(*this);
   221   }
   206   }
   222 
   207 
   223   /* [enumerated_type_name '#'] identifier */
       
   224   void *visit(enumerated_value_c *symbol) {
       
   225     if (current_enumerated_type != NULL) {
       
   226       if (symbol->type != NULL) ERROR;
       
   227 
       
   228       symbol_c *value_type = enumerated_value_symtable.find_value(symbol->value);
       
   229       /* NOTE: The following condition checks whether the same identifier is used more than once
       
   230        *       when defining the enumerated values of the type declaration of the new enumerated type.
       
   231        *       If this occurs, then the program beeing compiled contains a semantic error, which
       
   232        *       must be caught and reported by the semantic analyser. However, since
       
   233        *       this code is run before the semantic analyser, we must not yet raise the ERROR (internal
       
   234        *       compiler error message).
       
   235        *       For this reason, the follosing check is commented out.
       
   236        */
       
   237       /* if (value_type == current_enumerated_type) ERROR; */
       
   238 
       
   239       if (value_type == enumerated_value_symtable.end_value())
       
   240 	/* This identifier has not yet been used in any previous declaration of an enumeration data type.
       
   241 	 * so we add it to the symbol table.
       
   242 	 */
       
   243         enumerated_value_symtable.insert(symbol->value, current_enumerated_type);
       
   244       else if (value_type != NULL)
       
   245 	/* This identifier has already been used in a previous declaration of an enumeration data type.
       
   246 	 * so we set the symbol in symbol table pointing to NULL.
       
   247 	 */
       
   248         enumerated_value_symtable.set(symbol->value, NULL);
       
   249     }
       
   250     return NULL;
       
   251   }
       
   252 
   208 
   253   /*  identifier ':' array_spec_init */
   209   /*  identifier ':' array_spec_init */
   254   void *visit(array_type_declaration_c *symbol) {
   210   void *visit(array_type_declaration_c *symbol) {
   255     TRACE("array_type_declaration_c");
   211     TRACE("array_type_declaration_c");
   256     type_symtable.insert(symbol->identifier, symbol->array_spec_init);
   212     type_symtable.insert(symbol->identifier, symbol->array_spec_init);