stage1_2/create_enumtype_conversion_functions.cc
author mjsousa
Sun, 13 Jul 2014 13:47:16 +0100
changeset 910 a0518971127d
parent 765 d15f13bff9c6
child 958 7474d2cd1d6e
permissions -rw-r--r--
Narrow array subscripts correctly, even in the presence of other datatype errors (so we do not generate error messages for array subscripts that do not contain errors).
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
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    79
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    80
void *create_enumtype_conversion_functions_c::visit(identifier_c *symbol) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    81
    currentToken = symbol->value;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    82
    return NULL;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    83
}
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    84
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
/* B 1.3 - Data types */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    87
/**********************/
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
/* B 1.3.3 - Derived data types */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    90
/********************************/
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    91
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
    92
    std::string enumerateName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    93
    std::string functionName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    94
    std::list <std::string> enumerateValues;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    95
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    96
    symbol->enumerated_type_name->accept(*this);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    97
    enumerateName = currentToken;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    98
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    99
    symbol->enumerated_spec_init->accept(*this);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   100
    enumerateValues = currentTokenList;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   101
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   102
    printStringToEnum  (enumerateName, enumerateValues);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   103
    printEnumToString  (enumerateName, enumerateValues);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   104
    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
   105
        printIntegerToEnum (enumerateName, enumerateValues, true , s);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   106
        printEnumToInteger (enumerateName, enumerateValues, true , s);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   107
        printIntegerToEnum (enumerateName, enumerateValues, false, s);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   108
        printEnumToInteger (enumerateName, enumerateValues, false, s);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   109
    }
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   110
    if (debug) std::cout << text << std::endl;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   111
    
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   112
    return NULL;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   113
}
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
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
   116
    list_c *list;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   117
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   118
    currentTokenList.clear();
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   119
    list = (list_c *)symbol;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   120
    for (int i = 0; i < list->n; i++) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   121
        list->elements[i]->accept(*this);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   122
        currentTokenList.push_back(currentToken);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   123
    }
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
    return NULL;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   126
}
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
 * 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
   130
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   131
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
   132
    std::string integerType = "";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   133
    if (! isSigned) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   134
        integerType = "U";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   135
    }
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   136
    switch(size) {
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   137
    case 8 : integerType += "S"; break;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   138
    case 16:                     break;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   139
    case 32: integerType += "D"; break;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   140
    case 64: integerType += "L"; break;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   141
    default:                     break;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   142
    }
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   143
    integerType +="INT";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   144
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   145
    return integerType;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   146
}
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
 * 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
   150
 * ST Output:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   151
 *
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
 FUNCTION STRING_TO_<ENUM> : <ENUM>
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   154
  VAR_INPUT
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   155
  IN: STRING;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   156
  END_VAR
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   157
  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
   158
   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
   159
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   160
  END_IF;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   161
  ...
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   162
  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
   163
   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
   164
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   165
  END_IF;
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   166
  ENO := FALSE;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   167
  END_FUNCTION
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   168
749
76c87fdb5fc8 Add some comments to argument new code.
Manuele Conti <conti.ma@alice.it>
parents: 748
diff changeset
   169
  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
   170
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   171
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
   172
    std::list <std::string>::const_iterator itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   173
    std::string functionName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   174
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   175
    functionName = "STRING_TO_" + enumerateName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   176
    text += "FUNCTION " + functionName + " : " + enumerateName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   177
    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
   178
    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
   179
       std::string value = *itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   180
       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
   181
       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
   182
       text += " RETURN;\n"; 
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   183
       text += "END_IF;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   184
    }
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   185
    text += "ENO := FALSE;\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   186
    text += "END_FUNCTION\n\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   187
}
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
 * 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
   191
 * ST Output:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   192
 *
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
 FUNCTION <ENUM>_TO_STRING : STRING
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   195
  VAR_INPUT
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   196
  IN: <ENUM>;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   197
  END_VAR
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   198
  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
   199
   <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
   200
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   201
  END_IF;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   202
  ...
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   203
  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
   204
   <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
   205
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   206
  END_IF;
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   207
  ENO := FALSE;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   208
  END_FUNCTION
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   209
749
76c87fdb5fc8 Add some comments to argument new code.
Manuele Conti <conti.ma@alice.it>
parents: 748
diff changeset
   210
  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
   211
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   212
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
   213
    std::list <std::string>::const_iterator itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   214
    std::string functionName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   215
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   216
    functionName = enumerateName + "_TO_STRING";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   217
    text += "FUNCTION " + functionName + " : STRING";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   218
    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
   219
    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
   220
        std::string value = *itr;
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   221
        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
   222
        text += " " + functionName + " := '" + enumerateName + "#" + value + "';\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   223
        text += " RETURN;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   224
        text += "END_IF;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   225
    }
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   226
    text += "ENO := FALSE;\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   227
    text += "END_FUNCTION\n\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   228
}
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
 * 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
   232
 * ST Output:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   233
 *
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
 FUNCTION <INTEGER>_TO_<ENUM> : <ENUM>
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   236
  VAR_INPUT
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   237
  IN: <INTEGER>;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   238
  END_VAR
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   239
  IF IN = 1 THEN
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   240
   <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
   241
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   242
  END_IF;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   243
  ...
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   244
  IF IN = N THEN
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   245
   <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
   246
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   247
  END_IF;
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   248
  ENO := FALSE;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   249
  END_FUNCTION
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   250
749
76c87fdb5fc8 Add some comments to argument new code.
Manuele Conti <conti.ma@alice.it>
parents: 748
diff changeset
   251
  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
   252
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   253
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
   254
    std::list <std::string>::const_iterator itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   255
    std::string functionName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   256
    std::string integerType;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   257
    int count;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   258
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   259
    integerType  = getIntegerName(isSigned, size);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   260
    functionName = integerType + "_TO_" + enumerateName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   261
    text += "FUNCTION " + functionName + " : " + enumerateName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   262
    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
   263
    count = 0;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   264
    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
   265
        std::string value = *itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   266
        std::stringstream out;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   267
        out << count;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   268
        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
   269
        text += " " + functionName + " := " + enumerateName + "#" + value + ";\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   270
        text += " RETURN;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   271
        text += "END_IF;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   272
        count++;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   273
    }
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   274
    text += "ENO := FALSE;\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   275
    text += "END_FUNCTION\n\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   276
}
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
 * 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
   280
 * ST Output:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   281
 *
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
 FUNCTION <ENUM>_TO_<INTEGER> : <INTEGER>
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   284
  VAR_INPUT
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   285
  IN: <INTEGER>;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   286
  END_VAR
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   287
  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
   288
   <ENUM>_TO_<INTEGER> := 1;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   289
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   290
  END_IF;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   291
  ...
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   292
  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
   293
   <ENUM>_TO_<INTEGER> := N;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   294
   RETURN;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   295
  END_IF;
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   296
  ENO := FALSE;
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   297
  END_FUNCTION
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   298
749
76c87fdb5fc8 Add some comments to argument new code.
Manuele Conti <conti.ma@alice.it>
parents: 748
diff changeset
   299
  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
   300
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   301
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
   302
    std::list <std::string>::const_iterator itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   303
    std::string functionName;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   304
    std::string integerType;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   305
    int count;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   306
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   307
    integerType  = getIntegerName(isSigned, size);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   308
    functionName = enumerateName + "_TO_" + integerType;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   309
    text += "FUNCTION " + functionName + " : " + integerType;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   310
    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
   311
    count = 0;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   312
    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
   313
        std::string value = *itr;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   314
        std::stringstream out;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   315
        out << count;
765
d15f13bff9c6 Remove Ambiguous enumerate value in enum conversion functions.
Manuele Conti <conti.ma@alice.it>
parents: 764
diff changeset
   316
        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
   317
        text += " " + functionName + " := " + out.str() + ";\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   318
        text += " RETURN;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   319
        text += "END_IF;\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   320
        count++;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   321
    }
754
36f91a5e4fc8 Set ENO to false when conversion function fails.
Manuele Conti <conti.ma@alice.it>
parents: 753
diff changeset
   322
    text += "ENO := FALSE;\n";
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   323
    text += "END_FUNCTION\n\n";
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   324
}
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