stage1_2/create_enumtype_conversion_functions.hh
author Mario de Sousa <msousa@fe.up.pt>
Thu, 21 Dec 2017 17:56:12 +0000
changeset 1065 0066fe31a034
parent 958 7474d2cd1d6e
permissions -rw-r--r--
fix bug: allow variables with names starting with 'var' to be used in the first line of POU body
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
/*
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    35
 * create_enumtype_conversion_functions_c generates ST conversion functions source code for
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    36
 * enumerate user defined data types.
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    37
 *
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    38
 */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    39
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    40
#ifndef _CREATE_ENUMTYPE_CONVERSION_FUNCTIONS_HH
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    41
#define _CREATE_ENUMTYPE_CONVERSION_FUNCTIONS_HH
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    42
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    43
#include <string>
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    44
#include <list>
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    45
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    46
#include "../absyntax_utils/absyntax_utils.hh"
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    47
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    48
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    49
class create_enumtype_conversion_functions_c: public iterator_visitor_c {
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: 748
diff changeset
    50
  private:
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: 748
diff changeset
    51
    static create_enumtype_conversion_functions_c *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: 748
diff changeset
    52
    
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    53
  public:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    54
    explicit create_enumtype_conversion_functions_c(symbol_c *ignore);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    55
    virtual ~create_enumtype_conversion_functions_c(void);
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: 748
diff changeset
    56
    static std::string &get_declaration(symbol_c *symbol);
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    57
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 756
diff changeset
    58
    void *visit(                 identifier_c *symbol);
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 756
diff changeset
    59
    void *visit(         poutype_identifier_c *symbol);
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 756
diff changeset
    60
    void *visit(derived_datatype_identifier_c *symbol);
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 756
diff changeset
    61
    
748
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    62
    /**********************/
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    63
    /* B 1.3 - Data types */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    64
    /**********************/
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    65
    /********************************/
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    66
    /* B 1.3.3 - Derived data types */
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    67
    /********************************/
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    68
    void *visit(enumerated_type_declaration_c *symbol);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    69
    void *visit(enumerated_value_list_c *symbol);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    70
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    71
  private:
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    72
    std::string text;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    73
    std::string currentToken;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    74
    std::list <std::string> currentTokenList;
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    75
    std::string getIntegerName(bool isSigned, size_t size);
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    76
    void 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
    77
    void 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
    78
    void 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
    79
    void 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
    80
};
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    81
ad4265253528 Start to change code like Mario suggestions.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    82
#endif /* _CREATE_ENUMTYPE_CONVERSION_FUNCTIONS_HH */