stage1_2/create_enumtype_conversion_functions.cc
author Edouard Tisserant
Thu, 18 Jun 2020 14:32:20 +0200
changeset 1091 6f4e7a8387ae
parent 1041 56ebe2a31b5b
permissions -rw-r--r--
Fixed in standard function library: String comparison was retrurning wrong result whith strings of different sizes but starting the same, or with zero length strings.
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     1
/*
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     3
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     4
 *  Copyright (C) 2009-2012  Mario de Sousa (msousa@fe.up.pt)
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     5
 *  Copyright (C) 2012       Manuele Conti  (conti.ma@alice.it)
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     6
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     7
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     8
 *  This program is free software: you can redistribute it and/or modify
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     9
 *  it under the terms of the GNU General Public License as published by
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    10
 *  the Free Software Foundation, either version 3 of the License, or
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    11
 *  (at your option) any later version.
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    12
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    13
 *  This program is distributed in the hope that it will be useful,
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    16
 *  GNU General Public License for more details.
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    17
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    20
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    21
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    22
 * This code is made available on the understanding that it will not be
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    23
 * used in safety-critical situations without a full and competent review.
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    24
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    25
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    26
/*
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    27
 * An IEC 61131-3 compiler.
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    28
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    29
 * Based on the
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    30
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    31
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    32
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    33
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    34
#include <sstream>
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    35
#include "create_enumtype_conversion_functions.hh"
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    36
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    37
/* set to 1 to see debug info during execution */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    38
static const int debug = 0;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    39
756
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    40
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    41
/* 
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    42
 * The create_enumtype_conversion_functions_c class generates ST source code!
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    43
 * This code is in actual fact datatype conversion functions between user defined
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    44
 * enumerated datatypes, and some basic datatypes.
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    45
 *
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    46
 * These conversion functions cannot be implemented the normal way (i.e. in the standard library)
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    47
 * since they convert from/to a datatype that is defined by the user. So, we generate these conversions
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    48
 * functions on the fly! 
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    49
 * (to get an idea of what the generated code looks like, see the comments in create_enumtype_conversion_functions.cc)
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    50
 *
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    51
 * Currently, we support conversion between the user defined enumerated datatype and STRING,
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    52
 * SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT (basically the ANY_INT)
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    53
 *
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    54
 * ST source code is generated when the method get_declaration() is called. since the
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    55
 * create_enumtype_conversion_functions_c inherits from the iterator visitor, this method may be 
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    56
 * passed either the root of an abstract syntax tree, or sub-tree of the AST.
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    57
 *
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    58
 * This class will iterate through that AST, and for each enumerated type declaration, will 
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    59
 * create the apropriate conversion functions.
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    60
 */
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    61
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    62
create_enumtype_conversion_functions_c *create_enumtype_conversion_functions_c::singleton = NULL;
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    63
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    64
create_enumtype_conversion_functions_c:: create_enumtype_conversion_functions_c(symbol_c *ignore) {}
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    65
create_enumtype_conversion_functions_c::~create_enumtype_conversion_functions_c(void)             {}
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    66
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    67
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    68
std::string &create_enumtype_conversion_functions_c::get_declaration(symbol_c *symbol) {
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    69
    if (NULL == singleton)  singleton = new create_enumtype_conversion_functions_c(NULL);
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    70
    if (NULL == singleton)  ERROR_MSG("Out of memory. Bailing out!\n");
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    71
    
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    72
    singleton->text = "";
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    73
    if (NULL != symbol) 
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    74
      symbol->accept(*singleton);
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    75
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    76
    return singleton->text;
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    77
}
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 754
diff changeset
    78
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 765
diff changeset
    79
/* As the name of derived datatypes and POUs are still stored as identifiers in the respective datatype and POU declaration,  */
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 765
diff changeset
    80
/* only the indintifier_c visitor should be necessary!                                                                        */
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 765
diff changeset
    81
void *create_enumtype_conversion_functions_c::visit(                 identifier_c *symbol) {currentToken = symbol->value; return NULL;}
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 765
diff changeset
    82
void *create_enumtype_conversion_functions_c::visit(         poutype_identifier_c *symbol) {ERROR; return NULL;}
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 765
diff changeset
    83
void *create_enumtype_conversion_functions_c::visit(derived_datatype_identifier_c *symbol) {ERROR; return NULL;}
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 765
diff changeset
    84
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    85
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    86
/**********************/
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    87
/* B 1.3 - Data types */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    88
/**********************/
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    89
/********************************/
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    90
/* B 1.3.3 - Derived data types */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    91
/********************************/
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    92
void *create_enumtype_conversion_functions_c::visit(enumerated_type_declaration_c *symbol) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    93
    std::string enumerateName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    94
    std::string functionName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    95
    std::list <std::string> enumerateValues;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    96
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    97
    symbol->enumerated_type_name->accept(*this);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    98
    enumerateName = currentToken;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    99
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   100
    symbol->enumerated_spec_init->accept(*this);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   101
    enumerateValues = currentTokenList;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   102
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   103
    printStringToEnum  (enumerateName, enumerateValues);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   104
    printEnumToString  (enumerateName, enumerateValues);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   105
    for (size_t s = 8; s <= 64; s*= 2) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   106
        printIntegerToEnum (enumerateName, enumerateValues, true , s);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   107
        printEnumToInteger (enumerateName, enumerateValues, true , s);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   108
        printIntegerToEnum (enumerateName, enumerateValues, false, s);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   109
        printEnumToInteger (enumerateName, enumerateValues, false, s);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   110
    }
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   111
    if (debug) std::cout << text << std::endl;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   112
    
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   113
    return NULL;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   114
}
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   115
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   116
void *create_enumtype_conversion_functions_c::visit(enumerated_value_list_c *symbol) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   117
    list_c *list;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   118
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   119
    currentTokenList.clear();
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   120
    list = (list_c *)symbol;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   121
    for (int i = 0; i < list->n; i++) {
1041
56ebe2a31b5b Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents: 958
diff changeset
   122
        list->get_element(i)->accept(*this);
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   123
        currentTokenList.push_back(currentToken);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   124
    }
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   125
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   126
    return NULL;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   127
}
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   128
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   129
/*
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   130
 * getIntegerName function generate a integer data name from signed and size.
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   131
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   132
std::string create_enumtype_conversion_functions_c::getIntegerName(bool isSigned, size_t size) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   133
    std::string integerType = "";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   134
    if (! isSigned) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   135
        integerType = "U";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   136
    }
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   137
    switch(size) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   138
    case 8 : integerType += "S"; break;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   139
    case 16:                     break;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   140
    case 32: integerType += "D"; break;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   141
    case 64: integerType += "L"; break;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   142
    default:                     break;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   143
    }
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   144
    integerType +="INT";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   145
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   146
    return integerType;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   147
}
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   148
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   149
/*
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   150
 * printStringToEnum function print conversion function from STRING to <ENUM>:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   151
 * ST Output:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   152
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   153
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   154
 FUNCTION STRING_TO_<ENUM> : <ENUM>
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   155
  VAR_INPUT
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   156
  IN: STRING;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   157
  END_VAR
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   158
  IF IN = '<ENUM.VALUE_1>' THEN
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   159
   STRING_TO_<ENUM> := <ENUM>#<ENUM.VALUE_1>;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   160
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   161
  END_IF;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   162
  ...
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   163
  IF IN = '<ENUM.VALU_N>' THEN
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   164
   STRING_TO_<ENUM> := <ENUM>#<ENUM.VALUE_N>;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   165
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   166
  END_IF;
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   167
  ENO := FALSE;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   168
  END_FUNCTION
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   169
749
76c87fdb5fc8 Add some comments to argument new code.
Manuele Conti <conti.ma@alice.it>
parents: 748
diff changeset
   170
  Note: if you change code below remember to update this comment.
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   171
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   172
void create_enumtype_conversion_functions_c::printStringToEnum  (std::string &enumerateName, std::list<std::string> &enumerateValues) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   173
    std::list <std::string>::const_iterator itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   174
    std::string functionName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   175
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   176
    functionName = "STRING_TO_" + enumerateName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   177
    text += "FUNCTION " + functionName + " : " + enumerateName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   178
    text += "\nVAR_INPUT\nIN : STRING;\nEND_VAR\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   179
    for (itr = enumerateValues.begin(); itr != enumerateValues.end(); ++itr) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   180
       std::string value = *itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   181
       text += "IF IN = '" + value + "' THEN\n";
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   182
       text += " " + functionName + " := " + enumerateName + "#" + value + ";\n";
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   183
       text += " RETURN;\n"; 
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   184
       text += "END_IF;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   185
    }
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   186
    text += "ENO := FALSE;\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   187
    text += "END_FUNCTION\n\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   188
}
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   189
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   190
/*
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   191
 * printEnumToString function print conversion function from <ENUM> to STRING:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   192
 * ST Output:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   193
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   194
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   195
 FUNCTION <ENUM>_TO_STRING : STRING
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   196
  VAR_INPUT
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   197
  IN: <ENUM>;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   198
  END_VAR
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   199
  IF IN = <ENUM>#<ENUM.VALUE_1> THEN
764
d699d54d181a Fix enum conversion function to string.
Manuele Conti <conti.ma@alice.it>
parents: 756
diff changeset
   200
   <ENUM>_TO_STRING := '<ENUM>#<ENUM.VALUE_1>';
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   201
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   202
  END_IF;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   203
  ...
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   204
  IF IN = <ENUM>#<ENUM.VALUE_N> THEN
764
d699d54d181a Fix enum conversion function to string.
Manuele Conti <conti.ma@alice.it>
parents: 756
diff changeset
   205
   <ENUM>_TO_STRING := '<ENUM>#<ENUM.VALUE_N>';
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   206
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   207
  END_IF;
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   208
  ENO := FALSE;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   209
  END_FUNCTION
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   210
749
76c87fdb5fc8 Add some comments to argument new code.
Manuele Conti <conti.ma@alice.it>
parents: 748
diff changeset
   211
  Note: if you change code below remember to update this comment.
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   212
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   213
void create_enumtype_conversion_functions_c::printEnumToString  (std::string &enumerateName, std::list<std::string> &enumerateValues) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   214
    std::list <std::string>::const_iterator itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   215
    std::string functionName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   216
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   217
    functionName = enumerateName + "_TO_STRING";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   218
    text += "FUNCTION " + functionName + " : STRING";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   219
    text += "\nVAR_INPUT\nIN : " + enumerateName + ";\nEND_VAR\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   220
    for (itr = enumerateValues.begin(); itr != enumerateValues.end(); ++itr) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   221
        std::string value = *itr;
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   222
        text += "IF IN = " + enumerateName + "#" + value + " THEN\n";
764
d699d54d181a Fix enum conversion function to string.
Manuele Conti <conti.ma@alice.it>
parents: 756
diff changeset
   223
        text += " " + functionName + " := '" + enumerateName + "#" + value + "';\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   224
        text += " RETURN;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   225
        text += "END_IF;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   226
    }
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   227
    text += "ENO := FALSE;\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   228
    text += "END_FUNCTION\n\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   229
}
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   230
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   231
/*
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   232
 * printIntegerToEnum function print conversion function from <INTEGER> to <ENUM>:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   233
 * ST Output:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   234
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   235
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   236
 FUNCTION <INTEGER>_TO_<ENUM> : <ENUM>
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   237
  VAR_INPUT
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   238
  IN: <INTEGER>;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   239
  END_VAR
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   240
  IF IN = 1 THEN
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   241
   <INTEGER>_TO_<ENUM> := <ENUM>#<ENUM.VALUE_1>;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   242
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   243
  END_IF;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   244
  ...
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   245
  IF IN = N THEN
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   246
   <INTEGER>_TO_<ENUM> := <ENUM>#<ENUM.VALUE_N>;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   247
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   248
  END_IF;
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   249
  ENO := FALSE;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   250
  END_FUNCTION
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   251
749
76c87fdb5fc8 Add some comments to argument new code.
Manuele Conti <conti.ma@alice.it>
parents: 748
diff changeset
   252
  Note: if you change code below remember to update this comment.
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   253
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   254
void create_enumtype_conversion_functions_c::printIntegerToEnum (std::string &enumerateName, std::list<std::string> &enumerateValues, bool isSigned, size_t size) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   255
    std::list <std::string>::const_iterator itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   256
    std::string functionName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   257
    std::string integerType;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   258
    int count;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   259
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   260
    integerType  = getIntegerName(isSigned, size);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   261
    functionName = integerType + "_TO_" + enumerateName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   262
    text += "FUNCTION " + functionName + " : " + enumerateName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   263
    text += "\nVAR_INPUT\nIN : " + integerType + ";\nEND_VAR\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   264
    count = 0;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   265
    for (itr = enumerateValues.begin(); itr != enumerateValues.end(); ++itr) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   266
        std::string value = *itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   267
        std::stringstream out;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   268
        out << count;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   269
        text += "IF IN = " + out.str() + " THEN\n";
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   270
        text += " " + functionName + " := " + enumerateName + "#" + value + ";\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   271
        text += " RETURN;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   272
        text += "END_IF;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   273
        count++;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   274
    }
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   275
    text += "ENO := FALSE;\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   276
    text += "END_FUNCTION\n\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   277
}
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   278
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   279
/*
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   280
 * printEnumToInteger function print conversion function from <ENUM> to <INTEGER>:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   281
 * ST Output:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   282
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   283
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   284
 FUNCTION <ENUM>_TO_<INTEGER> : <INTEGER>
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   285
  VAR_INPUT
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   286
  IN: <INTEGER>;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   287
  END_VAR
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   288
  IF IN = <ENUM>#<ENUM.VALUE_1> THEN
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   289
   <ENUM>_TO_<INTEGER> := 1;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   290
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   291
  END_IF;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   292
  ...
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   293
  IF IN = <ENUM>#<ENUM.VALUE_N> THEN
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   294
   <ENUM>_TO_<INTEGER> := N;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   295
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   296
  END_IF;
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   297
  ENO := FALSE;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   298
  END_FUNCTION
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   299
749
76c87fdb5fc8 Add some comments to argument new code.
Manuele Conti <conti.ma@alice.it>
parents: 748
diff changeset
   300
  Note: if you change code below remember to update this comment.
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   301
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   302
void create_enumtype_conversion_functions_c::printEnumToInteger (std::string &enumerateName, std::list<std::string> &enumerateValues, bool isSigned, size_t size) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   303
    std::list <std::string>::const_iterator itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   304
    std::string functionName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   305
    std::string integerType;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   306
    int count;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   307
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   308
    integerType  = getIntegerName(isSigned, size);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   309
    functionName = enumerateName + "_TO_" + integerType;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   310
    text += "FUNCTION " + functionName + " : " + integerType;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   311
    text += "\nVAR_INPUT\nIN : " + enumerateName + ";\nEND_VAR\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   312
    count = 0;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   313
    for (itr = enumerateValues.begin(); itr != enumerateValues.end(); ++itr) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   314
        std::string value = *itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   315
        std::stringstream out;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   316
        out << count;
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   317
        text += "IF IN = " + enumerateName + "#" + value + " THEN\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   318
        text += " " + functionName + " := " + out.str() + ";\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   319
        text += " RETURN;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   320
        text += "END_IF;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   321
        count++;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   322
    }
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   323
    text += "ENO := FALSE;\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   324
    text += "END_FUNCTION\n\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   325
}
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   326
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   327
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   328