stage3/declaration_check.cc
author Mario de Sousa <msousa@fe.up.pt>
Wed, 14 Nov 2012 18:37:42 +0000
changeset 731 151f0b57b4e4
parent 718 a9f8cc778444
child 812 6679b6b21214
permissions -rw-r--r--
Print const values of symbol.
656
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     1
/*
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     3
 *
658
fe5e1f01a49e store POU reference to POU declaration instead of global var declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 656
diff changeset
     4
 *  Copyright (C) 2003-2012  Mario de Sousa (msousa@fe.up.pt)
656
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     5
 *  Copyright (C) 2012       Manuele Conti (conti.ma@alice.it)
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     6
 *
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     7
 *  This program is free software: you can redistribute it and/or modify
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     8
 *  it under the terms of the GNU General Public License as published by
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     9
 *  the Free Software Foundation, either version 3 of the License, or
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    10
 *  (at your option) any later version.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    11
 *
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    12
 *  This program is distributed in the hope that it will be useful,
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    15
 *  GNU General Public License for more details.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    16
 *
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    17
 *  You should have received a copy of the GNU General Public License
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    19
 *
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    20
 *
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    21
 * This code is made available on the understanding that it will not be
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    22
 * used in safety-critical situations without a full and competent review.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    23
 */
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    24
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    25
/*
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    26
 * An IEC 61131-3 compiler.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    27
 *
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    28
 * Based on the
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    29
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    30
 *
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    31
 */
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    32
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    33
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    34
/* Declaration sequence is a source code part needed to declare variables.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    35
 * There are some checks we need to do before start with other analysis:
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    36
 *
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    37
 *   - Check external option redefinition.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    38
 *   - Check external data type redefinition.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    39
 *   - Check initial values consistently with the data types of the variables/data types being declared.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    40
 *   - Check whether a function block uses a CONSTANT qualifier as described in 2.5.2.1.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    41
 *
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    42
 */
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    43
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    44
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    45
#include "declaration_check.hh"
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    46
#include "datatype_functions.hh"
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    47
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    48
#define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order)   ? (symbol1) : (symbol2))
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    49
#define  LAST_(symbol1, symbol2) (((symbol1)->last_order  > (symbol2)->last_order)    ? (symbol1) : (symbol2))
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    50
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    51
#define STAGE3_ERROR(error_level, symbol1, symbol2, ...) {                                                                  \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    52
  if (current_display_error_level >= error_level) {                                                                         \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    53
    fprintf(stderr, "%s:%d-%d..%d-%d: error: ",                                                                             \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    54
            FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    55
                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column);\
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    56
    fprintf(stderr, __VA_ARGS__);                                                                                           \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    57
    fprintf(stderr, "\n");                                                                                                  \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    58
    error_count++;                                                                                                     \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    59
  }                                                                                                                         \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    60
}
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    61
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    62
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    63
#define STAGE3_WARNING(symbol1, symbol2, ...) {                                                                             \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    64
    fprintf(stderr, "%s:%d-%d..%d-%d: warning: ",                                                                           \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    65
            FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    66
                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column);\
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    67
    fprintf(stderr, __VA_ARGS__);                                                                                           \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    68
    fprintf(stderr, "\n");                                                                                                  \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    69
    warning_found = true;                                                                                                   \
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    70
}
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    71
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    72
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    73
declaration_check_c::declaration_check_c(symbol_c *ignore) {
661
f537c3315f83 Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents: 660
diff changeset
    74
  current_display_error_level = 0;
f537c3315f83 Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents: 660
diff changeset
    75
  current_pou_decl = NULL;
656
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    76
  error_count = 0;
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    77
}
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    78
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    79
declaration_check_c::~declaration_check_c(void) {
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    80
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    81
}
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    82
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    83
int declaration_check_c::get_error_count() {
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    84
  return error_count;
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    85
}
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    86
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    87
void declaration_check_c::check_global_decl(symbol_c *p_decl) {
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    88
	symbol_c *var_name;
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    89
658
fe5e1f01a49e store POU reference to POU declaration instead of global var declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 656
diff changeset
    90
	search_var_instance_decl_c search_var_instance_glo_decl(current_pou_decl);
656
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    91
	search_var_instance_decl_c search_var_instance_ext_decl(p_decl);
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    92
	function_param_iterator_c fpi(p_decl);
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    93
	while((var_name = fpi.next()) != NULL) {
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    94
      if (fpi.param_direction() == function_param_iterator_c::direction_extref) {
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    95
     	 /* found an external reference parameter. */
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    96
     	symbol_c *glo_decl = search_var_instance_glo_decl.get_decl(var_name);
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    97
        symbol_c *ext_decl = search_var_instance_ext_decl.get_decl(var_name);
663
6ad7de83d22c Add check whether external var matches to global var.
Manuele Conti <conti.ma@alice.it>
parents: 661
diff changeset
    98
    	if (glo_decl == NULL) {
6ad7de83d22c Add check whether external var matches to global var.
Manuele Conti <conti.ma@alice.it>
parents: 661
diff changeset
    99
    	  STAGE3_ERROR(0, ext_decl, ext_decl, "Declaration error an external doesn't mach with any global var.");
6ad7de83d22c Add check whether external var matches to global var.
Manuele Conti <conti.ma@alice.it>
parents: 661
diff changeset
   100
    	  continue;
6ad7de83d22c Add check whether external var matches to global var.
Manuele Conti <conti.ma@alice.it>
parents: 661
diff changeset
   101
    	}
6ad7de83d22c Add check whether external var matches to global var.
Manuele Conti <conti.ma@alice.it>
parents: 661
diff changeset
   102
        if (search_var_instance_glo_decl.get_option(var_name) != search_var_instance_ext_decl.get_option(var_name))
656
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   103
          STAGE3_ERROR(0, glo_decl, glo_decl, "Declaration error an external redefinition option.");
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   104
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   105
        /* TODO: Check redefinition data type.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   106
         *       We need a new class (like search_base_type class) to get type id by variable declaration.
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   107
         *  symbol_c *glo_type = ????;
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   108
         *  symbol_c *ext_type = fpi.param_type();
658
fe5e1f01a49e store POU reference to POU declaration instead of global var declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 656
diff changeset
   109
	 */
fe5e1f01a49e store POU reference to POU declaration instead of global var declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 656
diff changeset
   110
	/* For the moment, we will just use search_base_type_c instead... */
718
a9f8cc778444 Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   111
        symbol_c *glo_type = search_base_type_c::get_basetype_decl(glo_decl);
a9f8cc778444 Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   112
        symbol_c *ext_type = search_base_type_c::get_basetype_decl(ext_decl);
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 663
diff changeset
   113
        if (! get_datatype_info_c::is_type_equal(glo_type, ext_type))
658
fe5e1f01a49e store POU reference to POU declaration instead of global var declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 656
diff changeset
   114
          STAGE3_ERROR(0, ext_decl, ext_decl, "Declaration error an external redefinition data type.");
656
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   115
      }
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   116
	}
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   117
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   118
}
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   119
660
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   120
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   121
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   122
/*****************************/
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   123
/* B 1.5.2 - Function Blocks */
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   124
/*****************************/
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   125
/*  FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   126
// SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body)
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   127
void *declaration_check_c::visit(function_block_declaration_c *symbol) {
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   128
  current_pou_decl = symbol;
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   129
  /* check if any FB declared as a VAR has any incompatible VAR_EXTERNAL declarations */
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   130
  if (NULL != symbol->var_declarations)
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   131
    symbol->var_declarations->accept(*this);
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   132
  return NULL;
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   133
}
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   134
656
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   135
/******************************************/
658
fe5e1f01a49e store POU reference to POU declaration instead of global var declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 656
diff changeset
   136
/* B 1.5.3 - Declaration & Initialisation */
656
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   137
/******************************************/
660
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   138
/*  PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   139
// SYM_REF3(program_declaration_c, program_type_name, var_declarations, function_block_body)
658
fe5e1f01a49e store POU reference to POU declaration instead of global var declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 656
diff changeset
   140
void *declaration_check_c::visit(program_declaration_c *symbol) {
fe5e1f01a49e store POU reference to POU declaration instead of global var declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 656
diff changeset
   141
  current_pou_decl = symbol;
660
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   142
  /* check if any FB declared as a VAR has any incompatible VAR_EXTERNAL declarations */
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   143
  if (NULL != symbol->var_declarations)
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   144
    symbol->var_declarations->accept(*this);
656
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   145
  return NULL;
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   146
}
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   147
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   148
/********************************/
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   149
/* B 1.7 Configuration elements */
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   150
/********************************/
660
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   151
/*
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   152
 * CONFIGURATION configuration_name
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   153
 *    optional_global_var_declarations
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   154
 *    (resource_declaration_list | single_resource_declaration)
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   155
 *    optional_access_declarations
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   156
 *    optional_instance_specific_initializations
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   157
 * END_CONFIGURATION
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   158
 */
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   159
//SYM_REF5(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations)
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   160
void *declaration_check_c::visit(configuration_declaration_c *symbol) {
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   161
  current_pou_decl = symbol;
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   162
  /* check if any FB declared as a VAR has any incompatible VAR_EXTERNAL declarations */
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   163
  if (NULL != symbol->resource_declarations)
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   164
    symbol->resource_declarations->accept(*this);
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   165
  return NULL;
656
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   166
}
45a796bce487 Start declaration check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   167
660
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   168
void *declaration_check_c::visit(program_configuration_c *symbol) {
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   169
  symbol_c *p_decl = program_type_symtable.find_value(symbol->program_type_name);
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   170
  if (p_decl == program_type_symtable.end_value())
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   171
    p_decl = function_block_type_symtable.find_value(symbol->program_type_name);
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   172
  /* stage1_2 guarantees that we are sure to find a declaration in FB or Program symtable. */
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   173
  if (p_decl == function_block_type_symtable.end_value())
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   174
    ERROR;
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   175
  check_global_decl(p_decl);
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   176
  return NULL;
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   177
}
9565d7d944ce Also check external/global variable consistency in configurations and FBs.
Mario de Sousa <msousa@fe.up.pt>
parents: 658
diff changeset
   178