stage3/fill_candidate_datatypes.cc
changeset 945 477393b00f95
parent 942 8739d8259932
child 958 7474d2cd1d6e
equal deleted inserted replaced
943:566414d7ba1f 945:477393b00f95
  1301 
  1301 
  1302 /******************************************/
  1302 /******************************************/
  1303 /* B 1.4.3 - Declaration & Initialisation */
  1303 /* B 1.4.3 - Declaration & Initialisation */
  1304 /******************************************/
  1304 /******************************************/
  1305 
  1305 
       
  1306 /* When handling the declaration of variables the fill/narrow algorithm will simply visit the objects
       
  1307  * in the abstract syntax tree defining the desired datatype for the variables. Tis is to set the 
       
  1308  * symbol->datatype to the basetype of that datatype.
       
  1309  *
       
  1310  * Note that we do not currently set the symbol->datatype annotation for the identifier_c objects naming the 
       
  1311  * variables inside the variable declaration. However, this is liable to change in the future, so do not write
       
  1312  * any code that depends on this!
       
  1313  * 
       
  1314  * example:
       
  1315  *    VAR  var1, var2, var3  :  my_type;  END_VAR
       
  1316  *   (*    ^^^^  ^^^^  ^^^^                -> will NOT have the symbol->datatype set (for now, may change in the future!) *)
       
  1317  *   (*                         ^^^^^^^    -> WILL     have the symbol->datatype set *)
       
  1318  * 
       
  1319  * (remeber too that the identifier_c objects identifying variables inside ST/IL/SFC code *will* have their 
       
  1320  *  symbol->datatype annotation filled by the fill/narrow algorithm)
       
  1321  */
       
  1322 void *fill_candidate_datatypes_c::fill_var_declaration(symbol_c *var_list, symbol_c *type) {
       
  1323   /* The type may be either a datatype object (e.g. array_spec_init_c, ...), or a derived_datatype_identifier_c
       
  1324    * naming a previously declared datatype.
       
  1325    * If it is a derived_datatype_identifier_c, we will search the list of all declared datatypes to determine 
       
  1326    * the requested datatype. This is done automatically by the search_base_type_c::get_basetype_decl() method, 
       
  1327    * so we do not need to do anything special here!
       
  1328    */
       
  1329   add_datatype_to_candidate_list(type, search_base_type_c::get_basetype_decl(type));  /* will only add if non NULL */
       
  1330   type->accept(*this);
       
  1331   // handle the extensible_input_parameter_c, etc...
       
  1332   /* The extensible_input_parameter_c will be visited since this class inherits from the iterator_visitor_c.
       
  1333    * It needs to be visited in order to handle the datatype of the first_index parameter of that class.
       
  1334    */
       
  1335   var_list->accept(*this);
       
  1336   return NULL;
       
  1337 }
       
  1338 
       
  1339 
       
  1340 void *fill_candidate_datatypes_c::visit(var1_init_decl_c             *symbol) {return fill_var_declaration(symbol->var1_list,       symbol->spec_init);}
       
  1341 void *fill_candidate_datatypes_c::visit(array_var_init_decl_c        *symbol) {return fill_var_declaration(symbol->var1_list,       symbol->array_spec_init);}
       
  1342 void *fill_candidate_datatypes_c::visit(structured_var_init_decl_c   *symbol) {return fill_var_declaration(symbol->var1_list,       symbol->initialized_structure);}
       
  1343 void *fill_candidate_datatypes_c::visit(fb_name_decl_c               *symbol) {return fill_var_declaration(symbol->fb_name_list,    symbol->fb_spec_init);}
       
  1344 void *fill_candidate_datatypes_c::visit(array_var_declaration_c      *symbol) {return fill_var_declaration(symbol->var1_list,       symbol->array_specification);}
       
  1345 void *fill_candidate_datatypes_c::visit(structured_var_declaration_c *symbol) {return fill_var_declaration(symbol->var1_list,       symbol->structure_type_name);}
       
  1346 void *fill_candidate_datatypes_c::visit(external_declaration_c       *symbol) {return fill_var_declaration(symbol->global_var_name, symbol->specification);}
       
  1347 void *fill_candidate_datatypes_c::visit(global_var_decl_c            *symbol) {return fill_var_declaration(symbol->global_var_spec, symbol->type_specification);}
       
  1348 void *fill_candidate_datatypes_c::visit(incompl_located_var_decl_c   *symbol) {return fill_var_declaration(symbol->variable_name,   symbol->var_spec);}
       
  1349 //void *fill_candidate_datatypes_c::visit(single_byte_string_var_declaration_c *symbol) {return handle_var_declaration(symbol->single_byte_string_spec);}
       
  1350 //void *fill_candidate_datatypes_c::visit(double_byte_string_var_declaration_c *symbol) {return handle_var_declaration(symbol->double_byte_string_spec);}
       
  1351 
       
  1352 
       
  1353 
       
  1354 // NOTE: this method is not required since fill_candidate_datatypes_c inherits from iterator_visitor_c. TODO: delete this method!
  1306 void *fill_candidate_datatypes_c::visit(var1_list_c *symbol) {
  1355 void *fill_candidate_datatypes_c::visit(var1_list_c *symbol) {
  1307   for(int i = 0; i < symbol->n; i++) {
  1356   for(int i = 0; i < symbol->n; i++) {symbol->elements[i]->accept(*this);}
  1308     symbol->elements[i]->accept(*this); // handle the extensible_input_parameter_c, etc...
       
  1309   }
       
  1310   return NULL;
  1357   return NULL;
  1311 }  
  1358 }  
  1312 
  1359 
  1313 
  1360 
  1314 /*  AT direct_variable */
  1361 /*  AT direct_variable */
  1507 
  1554 
  1508 /********************************/
  1555 /********************************/
  1509 /* B 1.7 Configuration elements */
  1556 /* B 1.7 Configuration elements */
  1510 /********************************/
  1557 /********************************/
  1511 void *fill_candidate_datatypes_c::visit(configuration_declaration_c *symbol) {
  1558 void *fill_candidate_datatypes_c::visit(configuration_declaration_c *symbol) {
  1512 	// TODO !!!
  1559 	if (debug) printf("Filling candidate data types list in configuration %s\n", ((token_c *)(symbol->configuration_name))->value);
  1513 	/* for the moment we must return NULL so semantic analysis of remaining code is not interrupted! */
  1560 	current_scope = symbol;
  1514 	return NULL;
  1561 //	local_enumerated_value_symtable.reset();  // TODO
  1515 }
  1562 //	symbol->global_var_declarations->accept(populate_enumvalue_symtable);  // TODO
       
  1563 	
       
  1564 	search_var_instance_decl = new search_var_instance_decl_c(symbol);
       
  1565 	symbol->global_var_declarations          ->accept(*this);
       
  1566 	symbol->resource_declarations            ->accept(*this); // points to a single_resource_declaration_c or a resource_declaration_list_c
       
  1567 //	symbol->access_declarations              ->accept(*this); // TODO
       
  1568 //	symbol->instance_specific_initializations->accept(*this); // TODO
       
  1569 
       
  1570 	delete search_var_instance_decl;
       
  1571 	search_var_instance_decl = NULL;
       
  1572 
       
  1573 	current_scope = NULL;	
       
  1574 //	local_enumerated_value_symtable.reset();  // TODO
       
  1575 	return NULL;
       
  1576 }
       
  1577 
       
  1578 
       
  1579 void *fill_candidate_datatypes_c::visit(resource_declaration_c *symbol) {
       
  1580 	if (debug) printf("Filling candidate data types list in resource %s\n", ((token_c *)(symbol->resource_name))->value);
       
  1581 //	local_enumerated_value_symtable.reset();  // TODO-> this must be replaced with local_enumerated_value_symtable.push(), which is not yet implemented for the dsyntable_c!
       
  1582 	symbol_c *prev_scope = current_scope;
       
  1583 	current_scope = symbol;
       
  1584 	/* TODO Enumeration constants may be defined inside a VAR_GLOBAL .. END_VAR variable declaration list. 
       
  1585 	 * We currently do not yet consider enumeration values defined in the var declarations inside a resource!
       
  1586 	 */
       
  1587 //	symbol->global_var_declarations->accept(populate_enumvalue_symtable);  // TODO!
       
  1588 	
       
  1589 	search_var_instance_decl_c *prev_search_var_instance_decl = search_var_instance_decl;
       
  1590 	search_var_instance_decl  = new  search_var_instance_decl_c(symbol);
       
  1591 	symbol->global_var_declarations->accept(*this);
       
  1592 	symbol->resource_declaration   ->accept(*this);  // points to a single_resource_declaration_c!
       
  1593 
       
  1594 	delete search_var_instance_decl;
       
  1595 	search_var_instance_decl = prev_search_var_instance_decl;
       
  1596 
       
  1597 	current_scope = prev_scope;	
       
  1598 //	local_enumerated_value_symtable.reset();  // TODO-> this must be replaced with local_enumerated_value_symtable.pop(), which is not yet implemented for the dsyntable_c!
       
  1599 	return NULL;
       
  1600 }
       
  1601 
       
  1602 
       
  1603 void *fill_candidate_datatypes_c::visit(single_resource_declaration_c *symbol) {
       
  1604 //	symbol->task_configuration_list    ->accept(*this);  // TODO
       
  1605 //	symbol->program_configuration_list ->accept(*this);  // TODO
       
  1606 	return NULL;
       
  1607 }
       
  1608 
  1516 
  1609 
  1517 /****************************************/
  1610 /****************************************/
  1518 /* B.2 - Language IL (Instruction List) */
  1611 /* B.2 - Language IL (Instruction List) */
  1519 /****************************************/
  1612 /****************************************/
  1520 /***********************************/
  1613 /***********************************/