|
1 /* |
|
2 * matiec - a compiler for the programming languages defined in IEC 61131-3 |
|
3 * |
|
4 * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt) |
|
5 * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it) |
|
6 * |
|
7 * |
|
8 * This program is free software: you can redistribute it and/or modify |
|
9 * it under the terms of the GNU General Public License as published by |
|
10 * the Free Software Foundation, either version 3 of the License, or |
|
11 * (at your option) any later version. |
|
12 * |
|
13 * This program is distributed in the hope that it will be useful, |
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 * GNU General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20 * |
|
21 * |
|
22 * This code is made available on the understanding that it will not be |
|
23 * used in safety-critical situations without a full and competent review. |
|
24 */ |
|
25 |
|
26 /* |
|
27 * An IEC 61131-3 compiler. |
|
28 * |
|
29 * Based on the |
|
30 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
31 * |
|
32 */ |
|
33 |
|
34 /* |
|
35 * create_enumtype_conversion_functions_c generates ST conversion functions source code for |
|
36 * enumerate user defined data types. |
|
37 * |
|
38 */ |
|
39 |
|
40 #ifndef _CREATE_ENUMTYPE_CONVERSION_FUNCTIONS_HH |
|
41 #define _CREATE_ENUMTYPE_CONVERSION_FUNCTIONS_HH |
|
42 |
|
43 #include <string> |
|
44 #include <list> |
|
45 |
|
46 #include "../absyntax_utils/absyntax_utils.hh" |
|
47 |
|
48 |
|
49 class create_enumtype_conversion_functions_c: public iterator_visitor_c { |
|
50 public: |
|
51 explicit create_enumtype_conversion_functions_c(symbol_c *ignore); |
|
52 virtual ~create_enumtype_conversion_functions_c(void); |
|
53 std::string &get_declaration(symbol_c *root); |
|
54 |
|
55 const static char *functionDataType []; |
|
56 |
|
57 void *visit(identifier_c *symbol); |
|
58 /**********************/ |
|
59 /* B 1.3 - Data types */ |
|
60 /**********************/ |
|
61 /********************************/ |
|
62 /* B 1.3.3 - Derived data types */ |
|
63 /********************************/ |
|
64 void *visit(enumerated_type_declaration_c *symbol); |
|
65 void *visit(enumerated_value_list_c *symbol); |
|
66 |
|
67 private: |
|
68 std::string text; |
|
69 std::string currentToken; |
|
70 std::list <std::string> currentTokenList; |
|
71 std::string getIntegerName(bool isSigned, size_t size); |
|
72 void printStringToEnum (std::string &enumerateName, std::list <std::string> &enumerateValues); |
|
73 void printEnumToString (std::string &enumerateName, std::list <std::string> &enumerateValues); |
|
74 void printIntegerToEnum (std::string &enumerateName, std::list <std::string> &enumerateValues, bool isSigned, size_t size); |
|
75 void printEnumToInteger (std::string &enumerateName, std::list <std::string> &enumerateValues, bool isSigned, size_t size); |
|
76 }; |
|
77 |
|
78 #endif /* _CREATE_ENUMTYPE_CONVERSION_FUNCTIONS_HH */ |