mario@181: /* msousa@265: * matiec - a compiler for the programming languages defined in IEC 61131-3 msousa@265: * msousa@265: * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) Edouard@279: * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant msousa@265: * msousa@265: * This program is free software: you can redistribute it and/or modify msousa@265: * it under the terms of the GNU General Public License as published by msousa@265: * the Free Software Foundation, either version 3 of the License, or msousa@265: * (at your option) any later version. msousa@265: * msousa@265: * This program is distributed in the hope that it will be useful, msousa@265: * but WITHOUT ANY WARRANTY; without even the implied warranty of msousa@265: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the msousa@265: * GNU General Public License for more details. msousa@265: * msousa@265: * You should have received a copy of the GNU General Public License msousa@265: * along with this program. If not, see . msousa@265: * mario@181: * mario@181: * This code is made available on the understanding that it will not be mario@181: * used in safety-critical situations without a full and competent review. mario@181: */ mario@181: mario@181: /* msousa@265: * An IEC 61131-3 compiler. mario@181: * mario@181: * Based on the mario@181: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) mario@181: * mario@181: */ mario@181: mario@181: mario@181: /* mario@181: * Function parameter iterator. mario@181: * Iterate through the in/out parameters of a function declaration. mario@181: * Function blocks are also suported. mario@181: * mario@181: * This is part of the 4th stage that generates mario@181: * a c++ source program equivalent to the IL and ST mario@181: * code. mario@181: */ mario@181: mario@181: /* Given a function_declaration_c, iterate through each mario@181: * function in/out/inout parameter, returning the name mario@181: * of each parameter...function_param_iterator_c mario@181: */ mario@181: mario@181: msousa@595: #include "function_param_iterator.hh" /* no longer required, aready included by absyntax_utils.hh */ msousa@595: #include "spec_init_separator.hh" /* no longer required, aready included by absyntax_utils.hh */ msousa@350: #include /* required for strtol() */ msousa@350: #include mario@181: #include msousa@595: #include // required for std::numeric_limits< XXX >::max() msousa@595: #include // required for errno msousa@596: #include "../main.hh" // required for ERROR() and ERROR_MSG() macros. mario@181: mario@181: //#define DEBUG mario@181: #ifdef DEBUG mario@181: #define TRACE(classname) printf("\n____%s____\n",classname); mario@181: #else mario@181: #define TRACE(classname) mario@181: #endif mario@181: mario@181: mario@181: msousa@595: msousa@595: msousa@595: /* NOTE: The following function is not really needed, as we could get the value that constant_folding_c determined for this msousa@595: * integer. Remember that currently constant_folding_c runs before this class is ever used/called! msousa@595: * However, I (Mario) do not currently feel it would be a good idea to restrict the use of this msousa@595: * abstract syntax utility to only after the constant_folding_c has had a chance to fill in the constant value msousa@595: * of this symbol. msousa@595: * For this reason only, I have opted to let this abstract syntax utility have its own private copy of the msousa@595: * extract_integer() function. msousa@595: * Another aspect that makes this OK is that this function will only be used to extract the integer value of the msousa@595: * index for the first extensible paramater (examples follow shortly). Since this is an extension to IEC 61131-3 msousa@595: * that we created to allow us to handle extensible functions with very little hard coding, it is OK if we msousa@595: * impose extra/different limits on how an integer may be legally be formated in this case. This will also msousa@595: * only show up in code that describes the interface to the standard function of IEC 61131-3, which the user msousa@595: * will not ever get to see. We write that IEC 61131-3 code ourselves! msousa@595: * msousa@595: * Example of source code we will be parsing and analysing: msousa@595: * msousa@595: * FUNCTION ADD : REAL VAR_INPUT IN 1 .. : REAL; END_VAR RETURN; END_FUNCTION msousa@595: * ^^^ msousa@595: * msousa@595: * FUNCTION MUX : REAL VAR_INPUT K : USINT; IN 0 .. : REAL; END_VAR RETURN; END_FUNCTION msousa@595: * ^^^ msousa@595: * msousa@595: * Basically, currently this will only be either a '0' or a '1' !! msousa@595: */ msousa@595: msousa@595: /* NOTE: it must ignore underscores! */ msousa@595: static int extract_first_index_value(symbol_c *sym) { msousa@595: std::string str = ""; msousa@595: integer_c *integer; msousa@595: long int ret; msousa@595: msousa@595: if ((integer = dynamic_cast(sym)) == NULL) ERROR; msousa@595: for(unsigned int i = 0; i < strlen(integer->value); i++) msousa@595: if (integer->value[i] != '_') str += integer->value[i]; msousa@595: msousa@595: errno = 0; // since strtoXX() may legally return 0, we must set errno to 0 to detect errors correctly! msousa@595: ret = strtol(str.c_str(), NULL, 10); msousa@595: if (errno != 0) ERROR; msousa@595: if (ret < 0) ERROR; // the following code assumes that the first index will never be negative! msousa@595: if (ret > std::numeric_limits< int >::max()) ERROR; // output of this function is only an int!! msousa@595: msousa@595: return ret; msousa@595: } msousa@595: msousa@595: msousa@595: msousa@595: msousa@595: msousa@595: msousa@595: msousa@595: msousa@595: msousa@595: msousa@350: /* compare the name of two __extensible__ function parameters. msousa@350: * The usual use case is to have one of the parameters as used msousa@350: * in the function declaration, and another as used in a formal function call. msousa@350: * msousa@350: * Will return: msousa@350: * < 0 : if two parameters are not compatible, or one is invalid msousa@350: * >= 0 : if both parameters .......... msousa@350: */ msousa@350: /* msousa@350: * ("in", "i0") -> returns error (<0) msousa@350: * ("in1", "in") -> returns error (<0) msousa@350: * ("in", "in") -> returns error (<0) msousa@350: * ("in", "inw") -> returns error (<0) msousa@350: * ("in", "in10.4") -> returns error (<0) msousa@350: * ("in", "in10e") -> returns error (<0) msousa@350: * ("in", "") -> returns error (<0) msousa@350: * ("", "in10e") -> returns error (<0) msousa@350: * ("in", "in0") -> returns 0 msousa@350: * ("in", "in9") -> returns 9 msousa@350: * ("in", "in42") -> returns 42 msousa@350: * ("in", "in-42") -> returns -42 (error!) msousa@350: */ msousa@350: int function_param_iterator_c::cmp_extparam_names(const char* s1, const char* s2) { msousa@350: int res; msousa@350: char *endptr; msousa@350: int len; msousa@350: msousa@350: if ((s1 == NULL) || (s2 == NULL) || (*s1 == '\0') || (*s2 == '\0')) return -1; msousa@350: msousa@350: len = strlen(s1); msousa@350: if (strncasecmp(s1, s2, len)) return -2; msousa@350: msousa@350: s1 = &s2[len]; msousa@350: if (*s1 == '\0') return -3; msousa@350: msousa@350: res = strtol(s1, &endptr, 10); msousa@350: if (*endptr != '\0') return -4; msousa@350: msousa@350: return res; msousa@350: } msousa@350: msousa@350: msousa@350: mario@181: void* function_param_iterator_c::handle_param_list(list_c *list) { ccb@202: switch (current_operation) { ccb@202: case iterate_op: ccb@202: if (next_param <= param_count + list->n) ccb@202: return list->elements[next_param - param_count - 1]; ccb@202: ccb@202: /* the desired param is not on this list... */ ccb@202: param_count += list->n; ccb@202: break; ccb@202: ccb@202: case search_op: ccb@202: for(int i = 0; i < list->n; i++) { msousa@350: symbol_c *sym = list->elements[i]; msousa@350: extensible_input_parameter_c *extensible_parameter = dynamic_cast(sym); msousa@350: if (extensible_parameter != NULL) { msousa@350: sym = extensible_parameter->var_name; msousa@350: current_param_is_extensible = true; msousa@595: _first_extensible_param_index = extract_first_index_value(extensible_parameter->first_index); msousa@350: } msousa@350: identifier_c *variable_name = dynamic_cast(sym); ccb@202: if (variable_name == NULL) ERROR; msousa@350: msousa@350: if (!current_param_is_extensible) msousa@350: if (strcasecmp(search_param_name->value, variable_name->value) == 0) msousa@350: /* FOUND! This is the same parameter!! */ msousa@350: return (void *)variable_name; msousa@350: msousa@350: if (current_param_is_extensible) { msousa@350: current_extensible_param_index = cmp_extparam_names(variable_name->value, search_param_name->value); msousa@350: if (current_extensible_param_index >= 0) msousa@350: /* FOUND! This is a compatible extensible parameter!! */ msousa@350: return (void *)variable_name; msousa@350: } ccb@202: } ccb@202: break; ccb@202: } /* switch */ ccb@202: ccb@202: /* Not found! */ ccb@202: return NULL; mario@181: } mario@181: mario@181: void* function_param_iterator_c::handle_single_param(symbol_c *var_name) { ccb@202: switch (current_operation) { ccb@202: case iterate_op: ccb@202: param_count++; ccb@202: if (next_param == param_count) ccb@202: return var_name; ccb@202: break; ccb@202: ccb@202: case search_op: msousa@350: extensible_input_parameter_c *extensible_parameter = dynamic_cast(var_name); msousa@350: if (extensible_parameter != NULL) { msousa@350: var_name = extensible_parameter->var_name; msousa@350: current_param_is_extensible = true; msousa@595: _first_extensible_param_index = extract_first_index_value(extensible_parameter->first_index); msousa@350: } ccb@202: identifier_c *variable_name = dynamic_cast(var_name); ccb@202: if (variable_name == NULL) ERROR; msousa@350: msousa@350: if (!current_param_is_extensible) msousa@350: if (strcasecmp(search_param_name->value, variable_name->value) == 0) msousa@350: /* FOUND! This is the same parameter!! */ msousa@350: return (void *)variable_name; msousa@350: msousa@350: if (current_param_is_extensible) { msousa@350: current_extensible_param_index = cmp_extparam_names(variable_name->value, search_param_name->value); msousa@350: if (current_extensible_param_index >= 0) msousa@350: /* FOUND! This is a compatible extensible parameter!! */ msousa@350: return (void *)variable_name; msousa@350: } ccb@202: break; ccb@202: } /* switch */ ccb@202: ccb@202: /* Not found! */ ccb@202: return NULL; mario@181: } mario@181: mario@181: void* function_param_iterator_c::iterate_list(list_c *list) { mario@181: void *res; mario@181: for (int i = 0; i < list->n; i++) { mario@181: res = list->elements[i]->accept(*this); mario@181: if (res != NULL) mario@181: return res; mario@181: } mario@181: return NULL; mario@181: } mario@181: mario@181: /* start off at the first parameter once again... */ mario@181: void function_param_iterator_c::reset(void) { mario@181: next_param = param_count = 0; msousa@350: _first_extensible_param_index = -1; msousa@350: current_param_is_extensible = false; mario@181: current_param_name = NULL; msousa@424: current_param_type = NULL; msousa@424: current_param_default_value = NULL; msousa@424: last_returned_parameter = NULL; /* the last parameter returned by search() or next() */ ccb@202: } ccb@202: mario@181: mario@181: /* initialise the iterator object. ccb@202: * We must be given a reference to one of the following ccb@202: * - function_declaration_c ccb@202: * - function_block_declaration_c ccb@202: * - program_declaration_c mario@181: * that will be analysed... mario@181: */ ccb@202: function_param_iterator_c::function_param_iterator_c(symbol_c *pou_decl) { ccb@202: /* do some consistency checks... */ ccb@202: function_declaration_c * f_decl = dynamic_cast(pou_decl); ccb@202: function_block_declaration_c *fb_decl = dynamic_cast(pou_decl); ccb@202: program_declaration_c * p_decl = dynamic_cast(pou_decl); ccb@202: msousa@426: if ((NULL == f_decl) && (NULL == fb_decl) && (NULL == p_decl)) msousa@426: ERROR; ccb@202: ccb@202: /* OK. Now initialise this object... */ ccb@202: this->f_decl = pou_decl; mario@181: reset(); mario@181: } mario@181: ccb@202: mario@181: mario@181: /* Skip to the next parameter. After object creation, mario@181: * the object references on parameter _before_ the first, so mario@181: * this function must be called once to get the object to mario@181: * reference the first parameter... mario@181: * mario@181: * Returns the parameter's name! mario@181: */ mario@181: identifier_c *function_param_iterator_c::next(void) { mario@181: void *res; mario@181: identifier_c *identifier; ccb@202: msousa@350: if (current_param_is_extensible) { msousa@350: current_extensible_param_index++; msousa@350: return current_param_name; msousa@350: } msousa@350: msousa@424: last_returned_parameter = NULL; mario@181: param_count = 0; laurent@233: en_eno_param_implicit = false; mario@181: next_param++; ccb@202: current_operation = function_param_iterator_c::iterate_op; mario@181: res = f_decl->accept(*this); ccb@202: if (res == NULL) mario@181: return NULL; ccb@202: ccb@202: symbol_c *sym = (symbol_c *)res; msousa@350: extensible_input_parameter_c *extensible_parameter = dynamic_cast(sym); msousa@350: if (extensible_parameter != NULL) { msousa@350: sym = extensible_parameter->var_name; msousa@350: current_param_is_extensible = true; msousa@595: _first_extensible_param_index = extract_first_index_value(extensible_parameter->first_index); msousa@350: current_extensible_param_index = _first_extensible_param_index; msousa@350: } ccb@202: identifier = dynamic_cast(sym); ccb@202: if (identifier == NULL) ccb@202: ERROR; mario@181: current_param_name = identifier; msousa@424: last_returned_parameter = current_param_name; mario@181: return current_param_name; mario@181: } mario@181: ccb@202: /* Search for the value passed to the parameter named ... */ ccb@202: identifier_c *function_param_iterator_c::search(symbol_c *param_name) { ccb@202: if (NULL == param_name) ERROR; ccb@202: search_param_name = dynamic_cast(param_name); ccb@202: if (NULL == search_param_name) ERROR; msousa@350: en_eno_param_implicit = false; msousa@350: current_param_is_extensible = false; ccb@202: current_operation = function_param_iterator_c::search_op; ccb@202: void *res = f_decl->accept(*this); ccb@202: identifier_c *res_param_name = dynamic_cast((symbol_c *)res); msousa@424: last_returned_parameter = res_param_name; ccb@202: return res_param_name; mario@181: } mario@181: msousa@448: identifier_c *function_param_iterator_c::search(const char *param_name) { msousa@448: identifier_c param_name_id(param_name); msousa@448: return search(¶m_name_id); msousa@448: } msousa@448: msousa@448: msousa@448: mario@181: /* Returns the currently referenced parameter's default value, mario@181: * or NULL if none is specified in the function declrataion itself. mario@181: */ mario@181: symbol_c *function_param_iterator_c::default_value(void) { msousa@424: if (NULL == last_returned_parameter) msousa@424: return NULL; mario@181: return current_param_default_value; mario@181: } mario@181: mario@181: /* Returns the currently referenced parameter's type name. */ mario@181: symbol_c *function_param_iterator_c::param_type(void) { msousa@424: if (NULL == last_returned_parameter) msousa@424: return NULL; mario@181: return current_param_type; mario@181: } mario@181: laurent@233: /* Returns if currently referenced parameter is an implicit defined EN/ENO parameter. */ laurent@233: bool function_param_iterator_c::is_en_eno_param_implicit(void) { msousa@424: if (NULL == last_returned_parameter) msousa@424: ERROR; laurent@233: return en_eno_param_implicit; laurent@233: } laurent@233: msousa@350: /* Returns if currently referenced parameter is an extensible parameter. */ msousa@350: /* extensible paramters only occur in some standard functions, e.g. AND(word#34, word#44, word#65); */ msousa@350: bool function_param_iterator_c::is_extensible_param(void) { msousa@424: if (NULL == last_returned_parameter) msousa@424: ERROR; msousa@350: return current_param_is_extensible; msousa@350: } msousa@350: msousa@350: /* Returns the index of the current extensible parameter. */ msousa@350: /* If the current parameter is not an extensible paramter, returns -1 */ msousa@350: int function_param_iterator_c::extensible_param_index(void) { msousa@424: if (NULL == last_returned_parameter) msousa@424: ERROR; msousa@350: return (current_param_is_extensible? current_extensible_param_index : -1); msousa@350: } msousa@350: msousa@350: /* Returns the index of the first extensible parameter, or -1 if no extensible parameter found. */ msousa@350: /* WARNING: Will only return the correct value _after_ an extensible parameter has been found! */ msousa@350: int function_param_iterator_c::first_extensible_param_index(void) { msousa@350: return _first_extensible_param_index; msousa@350: } msousa@350: mario@181: /* Returns the currently referenced parameter's data passing direction. mario@181: * i.e. VAR_INPUT, VAR_OUTPUT or VAR_INOUT mario@181: */ mario@181: function_param_iterator_c::param_direction_t function_param_iterator_c::param_direction(void) { msousa@424: if (NULL == last_returned_parameter) msousa@424: ERROR; mario@181: return current_param_direction; mario@181: } mario@181: laurent@233: void *function_param_iterator_c::visit(implicit_definition_c *symbol) { msousa@350: en_eno_param_implicit = true; laurent@233: return NULL; laurent@233: } laurent@233: mario@181: /****************************************/ mario@181: /* 1.4.3 - Declaration & Initialisation */ mario@181: /****************************************/ mario@181: void *function_param_iterator_c::visit(input_declarations_c *symbol) { mario@181: TRACE("input_declarations_c"); mario@181: current_param_direction = direction_in; mario@181: return symbol->input_declaration_list->accept(*this); mario@181: } mario@181: mario@181: void *function_param_iterator_c::visit(input_declaration_list_c *symbol) {TRACE("input_declaration_list_c"); return iterate_list(symbol);} mario@181: mario@181: void *function_param_iterator_c::visit(edge_declaration_c *symbol) {TRACE("edge_declaration_c"); return symbol->var1_list->accept(*this);} mario@181: mario@181: void *function_param_iterator_c::visit(en_param_declaration_c *symbol) { mario@181: TRACE("en_param_declaration_c"); ccb@202: /* It is OK to store these values in the current_param_XXX ccb@202: * variables, because if the desired parameter is not in the ccb@202: * variable list we will be analysing, the current_param_XXXX ccb@202: * variables will get overwritten when we visit the next ccb@202: * var1_init_decl_c list! ccb@202: */ msousa@805: current_param_default_value = spec_init_sperator_c::get_init(symbol->type_decl); msousa@805: current_param_type = spec_init_sperator_c::get_spec(symbol->type_decl); msousa@805: msousa@350: void *res = handle_single_param(symbol->name); msousa@350: msousa@350: /* If we have found the parameter we will be returning, we set the en_eno_param_implicit to TRUE if implicitly defined */ msousa@350: if (res != NULL) symbol->method->accept(*this); msousa@350: msousa@350: return res; mario@181: } mario@181: mario@181: /* var1_list ':' array_spec_init */ mario@181: //SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) laurent@235: void *function_param_iterator_c::visit(array_var_init_decl_c *symbol) { laurent@235: TRACE("array_var_init_decl_c"); laurent@235: current_param_default_value = spec_init_sperator_c::get_init(symbol->array_spec_init); laurent@235: current_param_type = spec_init_sperator_c::get_spec(symbol->array_spec_init); laurent@235: laurent@235: return symbol->var1_list->accept(*this); laurent@235: } mario@181: mario@181: /* var1_list ':' initialized_structure */ mario@181: //SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) laurent@235: void *function_param_iterator_c::visit(structured_var_init_decl_c *symbol) { laurent@235: TRACE("structured_var_init_decl_c"); laurent@235: laurent@235: current_param_default_value = spec_init_sperator_c::get_init(symbol->initialized_structure); laurent@235: current_param_type = spec_init_sperator_c::get_spec(symbol->initialized_structure); laurent@235: laurent@235: return symbol->var1_list->accept(*this); laurent@235: } mario@181: msousa@662: msousa@662: msousa@662: msousa@662: /* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */ msousa@662: /* structure_initialization -> may be NULL ! */ msousa@662: // SYM_REF3(fb_name_decl_c, fb_name_list, function_block_type_name, structure_initialization) msousa@662: void *function_param_iterator_c::visit(fb_name_decl_c *symbol) { msousa@662: TRACE("structured_var_init_decl_c"); msousa@810: current_param_default_value = spec_init_sperator_c::get_init(symbol->fb_spec_init); msousa@810: current_param_type = spec_init_sperator_c::get_spec(symbol->fb_spec_init); msousa@662: msousa@662: return symbol->fb_name_list->accept(*this); msousa@662: } msousa@662: msousa@662: msousa@662: /* fb_name_list ',' fb_name */ msousa@662: // SYM_LIST(fb_name_list_c) msousa@662: void *function_param_iterator_c::visit(fb_name_list_c *symbol) {TRACE("fb_name_list_c"); return handle_param_list(symbol);} msousa@662: msousa@662: mario@181: void *function_param_iterator_c::visit(output_declarations_c *symbol) { mario@181: TRACE("output_declarations_c"); mario@181: current_param_direction = direction_out; mario@181: return symbol->var_init_decl_list->accept(*this); mario@181: } msousa@350: mario@181: void *function_param_iterator_c::visit(eno_param_declaration_c *symbol) { mario@181: TRACE("eno_param_declaration_c"); ccb@202: /* It is OK to store these values in the current_param_XXX ccb@202: * variables, because if the desired parameter is not in the ccb@202: * variable list we will be analysing, the current_param_XXXX ccb@202: * variables will get overwritten when we visit the next ccb@202: * var1_init_decl_c list! ccb@202: */ ccb@202: current_param_default_value = NULL; ccb@202: current_param_type = symbol->type; ccb@202: msousa@350: void *res = handle_single_param(symbol->name); msousa@350: msousa@350: /* If we have found the parameter we will be returning, we set the en_eno_param_implicit to TRUE if implicitly defined */ msousa@350: if (res != NULL) symbol->method->accept(*this); msousa@350: msousa@350: return res; msousa@350: } msousa@350: mario@181: void *function_param_iterator_c::visit(input_output_declarations_c *symbol) { mario@181: TRACE("input_output_declarations_c"); mario@181: current_param_direction = direction_inout; mario@181: return symbol->var_declaration_list->accept(*this); mario@181: } msousa@350: mario@181: void *function_param_iterator_c::visit(var_declaration_list_c *symbol) {TRACE("var_declaration_list_c"); return iterate_list(symbol);} mario@181: mario@181: /* var1_list ':' array_specification */ mario@181: //SYM_REF2(array_var_declaration_c, var1_list, array_specification) laurent@237: void *function_param_iterator_c::visit(array_var_declaration_c *symbol) { msousa@662: TRACE("array_var_declaration_c"); msousa@662: current_param_default_value = NULL; msousa@662: current_param_type = symbol->array_specification; msousa@662: return symbol->var1_list->accept(*this); laurent@237: } mario@181: mario@181: /* var1_list ':' structure_type_name */ mario@181: //SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) laurent@235: void *function_param_iterator_c::visit(structured_var_declaration_c *symbol) { laurent@235: TRACE("structured_var_declaration_c"); laurent@235: current_param_default_value = NULL; laurent@235: current_param_type = symbol->structure_type_name; laurent@235: return symbol->var1_list->accept(*this); laurent@235: } mario@181: mario@181: /* VAR [CONSTANT] var_init_decl_list END_VAR */ mario@181: void *function_param_iterator_c::visit(var_declarations_c *symbol) {TRACE("var_declarations_c"); return NULL;} mario@181: mario@181: /*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ mario@181: /* option -> may be NULL ! */ mario@181: // SYM_REF2(external_var_declarations_c, option, external_declaration_list) mario@181: void *function_param_iterator_c::visit(external_var_declarations_c *symbol) { mario@181: TRACE("external_var_declarations_c"); mario@181: current_param_direction = direction_extref; mario@181: return symbol->external_declaration_list->accept(*this); mario@181: } mario@181: mario@181: /* helper symbol for external_var_declarations */ mario@181: /*| external_declaration_list external_declaration';' */ mario@181: // SYM_LIST(external_declaration_list_c) mario@181: void *function_param_iterator_c::visit(external_declaration_list_c *symbol) {TRACE("external_declaration_list_c"); return iterate_list(symbol);} mario@181: mario@181: /* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ mario@181: //SYM_REF2(external_declaration_c, global_var_name, specification) mario@181: void *function_param_iterator_c::visit(external_declaration_c *symbol) { mario@181: TRACE("external_declaration_c"); mario@181: /* It is OK to store these values in the current_param_XXX mario@181: * variables, because if the desired parameter is not in the mario@181: * variable list we will be analysing, the current_param_XXXX mario@181: * variables will get overwritten when we visit the next mario@181: * var1_init_decl_c list! mario@181: */ mario@181: current_param_default_value = spec_init_sperator_c::get_init(symbol->specification); mario@181: current_param_type = spec_init_sperator_c::get_spec(symbol->specification); mario@181: mario@181: return handle_single_param(symbol->global_var_name); mario@181: } mario@181: mario@181: mario@181: #if 0 mario@181: /*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ mario@181: /* option -> may be NULL ! */ mario@181: SYM_REF2(global_var_declarations_c, option, global_var_decl_list) mario@181: mario@181: /* helper symbol for global_var_declarations */ mario@181: /*| global_var_decl_list global_var_decl ';' */ mario@181: SYM_LIST(global_var_decl_list_c) mario@181: mario@181: /*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ mario@181: /* type_specification ->may be NULL ! */ mario@181: SYM_REF2(global_var_decl_c, global_var_spec, type_specification) mario@181: mario@181: /*| global_var_name location */ mario@181: SYM_REF2(global_var_spec_c, global_var_name, location) mario@181: mario@181: /* AT direct_variable */ mario@181: SYM_REF2(location_c, direct_variable, unused) mario@181: mario@181: /*| global_var_list ',' global_var_name */ mario@181: SYM_LIST(global_var_list_c) mario@181: mario@181: /* var1_list ':' single_byte_string_spec */ mario@181: SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) mario@181: mario@181: /* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ mario@181: /* integer ->may be NULL ! */ mario@181: /* single_byte_character_string ->may be NULL ! */ mario@181: SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) mario@181: mario@181: /* var1_list ':' double_byte_string_spec */ mario@181: SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) mario@181: mario@181: /* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ mario@181: /* integer ->may be NULL ! */ mario@181: /* double_byte_character_string ->may be NULL ! */ mario@181: SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) mario@181: mario@181: /*| VAR [RETAIN|NON_RETAIN] incompl_located_var_decl_list END_VAR */ mario@181: /* option ->may be NULL ! */ mario@181: SYM_REF2(incompl_located_var_declarations_c, option, incompl_located_var_decl_list) mario@181: mario@181: /* helper symbol for incompl_located_var_declarations */ mario@181: /*| incompl_located_var_decl_list incompl_located_var_decl ';' */ mario@181: SYM_LIST(incompl_located_var_decl_list_c) mario@181: mario@181: /* variable_name incompl_location ':' var_spec */ mario@181: SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) mario@181: mario@181: /* AT incompl_location_token */ mario@181: SYM_TOKEN(incompl_location_c) mario@181: #endif mario@181: mario@181: mario@181: void *function_param_iterator_c::visit(var1_init_decl_c *symbol) { mario@181: TRACE("var1_init_decl_c"); mario@181: /* It is OK to store these values in the current_param_XXX mario@181: * variables, because if the desired parameter is not in the mario@181: * variable list we will be analysing, the current_param_XXXX mario@181: * variables will get overwritten when we visit the next mario@181: * var1_init_decl_c list! mario@181: */ mario@181: current_param_default_value = spec_init_sperator_c::get_init(symbol->spec_init); mario@181: current_param_type = spec_init_sperator_c::get_spec(symbol->spec_init); mario@181: mario@181: return symbol->var1_list->accept(*this); mario@181: } mario@181: mario@181: mario@181: void *function_param_iterator_c::visit(var1_list_c *symbol) { mario@181: TRACE("var1_list_c"); mario@181: return handle_param_list(symbol); mario@181: } mario@181: msousa@350: mario@181: void *function_param_iterator_c::visit(var_init_decl_list_c *symbol) {TRACE("var_init_decl_list_c"); return iterate_list(symbol);} mario@181: mario@181: mario@181: /***********************/ mario@181: /* B 1.5.1 - Functions */ mario@181: /***********************/ mario@181: void *function_param_iterator_c::visit(function_declaration_c *symbol) {TRACE("function_declaration_c"); return symbol->var_declarations_list->accept(*this);} mario@181: /* intermediate helper symbol for function_declaration */ mario@181: void *function_param_iterator_c::visit(var_declarations_list_c *symbol) {TRACE("var_declarations_list_c"); return iterate_list(symbol);} mario@181: void *function_param_iterator_c::visit(function_var_decls_c *symbol) {TRACE("function_var_decls_c"); /* ignore */ return NULL;} mario@181: mario@181: mario@181: /*****************************/ mario@181: /* B 1.5.2 - Function Blocks */ mario@181: /*****************************/ mario@181: /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ mario@181: void *function_param_iterator_c::visit(function_block_declaration_c *symbol) {TRACE("function_block_declaration_c"); return symbol->var_declarations->accept(*this);} mario@181: mario@181: /* intermediate helper symbol for function_declaration */ mario@181: /* { io_var_declarations | other_var_declarations } */ mario@181: /* mario@181: * NOTE: we re-use the var_declarations_list_c mario@181: */ mario@181: mario@181: /* VAR_TEMP temp_var_decl_list END_VAR */ mario@181: void *function_param_iterator_c::visit(temp_var_decls_c *symbol) {TRACE("temp_var_decls_c"); /* ignore */ return NULL;} mario@181: void *function_param_iterator_c::visit(temp_var_decls_list_c *symbol) {TRACE("temp_var_decls_list_c"); /* ignore */ return NULL;} mario@181: mario@181: /* VAR NON_RETAIN var_init_decl_list END_VAR */ mario@181: void *function_param_iterator_c::visit(non_retentive_var_decls_c *symbol) {TRACE("non_retentive_var_decls_c"); /* ignore */ return NULL;} mario@181: mario@181: mario@181: /**********************/ mario@181: /* B 1.5.3 - Programs */ mario@181: /**********************/ mario@181: /* PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */ mario@181: // SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused) mario@181: void *function_param_iterator_c::visit(program_declaration_c *symbol) {TRACE("program_declaration_c"); return symbol->var_declarations->accept(*this);} mario@181: mario@181: /* intermediate helper symbol for program_declaration_c */ mario@181: /* { io_var_declarations | other_var_declarations } */ mario@181: /* mario@181: * NOTE: we re-use the var_declarations_list_c mario@181: */ mario@181: mario@181: mario@181: mario@181: mario@181: mario@181: