stage3/declaration_check.cc
changeset 658 fe5e1f01a49e
parent 656 45a796bce487
child 660 9565d7d944ce
equal deleted inserted replaced
657:cac2973b6884 658:fe5e1f01a49e
     1 /*
     1 /*
     2  *  matiec - a compiler for the programming languages defined in IEC 61131-3
     2  *  matiec - a compiler for the programming languages defined in IEC 61131-3
     3  *
     3  *
     4  *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
     4  *  Copyright (C) 2003-2012  Mario de Sousa (msousa@fe.up.pt)
     5  *  Copyright (C) 2012       Manuele Conti (conti.ma@alice.it)
     5  *  Copyright (C) 2012       Manuele Conti (conti.ma@alice.it)
     6  *
     6  *
     7  *  This program is free software: you can redistribute it and/or modify
     7  *  This program is free software: you can redistribute it and/or modify
     8  *  it under the terms of the GNU General Public License as published by
     8  *  it under the terms of the GNU General Public License as published by
     9  *  the Free Software Foundation, either version 3 of the License, or
     9  *  the Free Software Foundation, either version 3 of the License, or
    84 
    84 
    85 void declaration_check_c::check_global_decl(symbol_c *p_decl) {
    85 void declaration_check_c::check_global_decl(symbol_c *p_decl) {
    86 	symbol_c *var_name;
    86 	symbol_c *var_name;
    87 	search_base_type_c search_base_type;
    87 	search_base_type_c search_base_type;
    88 
    88 
    89 	search_var_instance_decl_c search_var_instance_glo_decl(global_var_decls);
    89 	search_var_instance_decl_c search_var_instance_glo_decl(current_pou_decl);
    90 	search_var_instance_decl_c search_var_instance_ext_decl(p_decl);
    90 	search_var_instance_decl_c search_var_instance_ext_decl(p_decl);
    91 	function_param_iterator_c fpi(p_decl);
    91 	function_param_iterator_c fpi(p_decl);
    92 	while((var_name = fpi.next()) != NULL) {
    92 	while((var_name = fpi.next()) != NULL) {
    93       if (fpi.param_direction() == function_param_iterator_c::direction_extref) {
    93       if (fpi.param_direction() == function_param_iterator_c::direction_extref) {
    94      	 /* found an external reference parameter. */
    94      	 /* found an external reference parameter. */
    99 
    99 
   100         /* TODO: Check redefinition data type.
   100         /* TODO: Check redefinition data type.
   101          *       We need a new class (like search_base_type class) to get type id by variable declaration.
   101          *       We need a new class (like search_base_type class) to get type id by variable declaration.
   102          *  symbol_c *glo_type = ????;
   102          *  symbol_c *glo_type = ????;
   103          *  symbol_c *ext_type = fpi.param_type();
   103          *  symbol_c *ext_type = fpi.param_type();
   104          *  if (! is_type_equal(glo_type, ext_type))
   104 	 */
   105          *	 STAGE3_ERROR(0, glo_decl, glo_decl, "Declaration error an external redefinition data type.");
   105 	/* For the moment, we will just use search_base_type_c instead... */
   106          */
   106         symbol_c *glo_type = search_base_type.get_basetype_decl(glo_decl);
       
   107         symbol_c *ext_type = search_base_type.get_basetype_decl(ext_decl);
       
   108         if (! is_type_equal(glo_type, ext_type))
       
   109           STAGE3_ERROR(0, ext_decl, ext_decl, "Declaration error an external redefinition data type.");
   107       }
   110       }
   108 	}
   111 	}
   109 
   112 
   110 }
   113 }
   111 
   114 
   112 /******************************************/
   115 /******************************************/
   113 /* B 1.4.3 - Declaration & Initialisation */
   116 /* B 1.5.3 - Declaration & Initialisation */
   114 /******************************************/
   117 /******************************************/
   115 void *declaration_check_c::visit(global_var_declarations_c *symbol) {
   118 void *declaration_check_c::visit(program_declaration_c *symbol) {
   116   global_var_decls = dynamic_cast<list_c *>(symbol->global_var_decl_list);
   119   current_pou_decl = symbol;
   117   if (NULL == global_var_decls)
       
   118 	  ERROR;
       
   119   return NULL;
   120   return NULL;
   120 }
   121 }
   121 
   122 
   122 /********************************/
   123 /********************************/
   123 /* B 1.7 Configuration elements */
   124 /* B 1.7 Configuration elements */