35 #include "create_enumtype_conversion_functions.hh" |
35 #include "create_enumtype_conversion_functions.hh" |
36 |
36 |
37 /* set to 1 to see debug info during execution */ |
37 /* set to 1 to see debug info during execution */ |
38 static const int debug = 0; |
38 static const int debug = 0; |
39 |
39 |
40 /* |
40 |
41 * functionDataType array contains all supported data type conversion. |
41 /* |
42 */ |
42 * The create_enumtype_conversion_functions_c class generates ST source code! |
43 const char *create_enumtype_conversion_functions_c::functionDataType[] = { |
43 * This code is in actual fact datatype conversion functions between user defined |
44 "STRING", |
44 * enumerated datatypes, and some basic datatypes. |
45 "SINT" , |
45 * |
46 "INT" , |
46 * These conversion functions cannot be implemented the normal way (i.e. in the standard library) |
47 "DINT" , |
47 * since they convert from/to a datatype that is defined by the user. So, we generate these conversions |
48 "LINT" , |
48 * functions on the fly! |
49 "USINT" , |
49 * (to get an idea of what the generated code looks like, see the comments in create_enumtype_conversion_functions.cc) |
50 "UINT" , |
50 * |
51 "UDINT" , |
51 * Currently, we support conversion between the user defined enumerated datatype and STRING, |
52 "ULINT" , |
52 * SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT (basically the ANY_INT) |
53 NULL |
53 * |
54 }; |
54 * ST source code is generated when the method get_declaration() is called. since the |
55 |
55 * create_enumtype_conversion_functions_c inherits from the iterator visitor, this method may be |
56 create_enumtype_conversion_functions_c::create_enumtype_conversion_functions_c(symbol_c *ignore) { |
56 * passed either the root of an abstract syntax tree, or sub-tree of the AST. |
57 |
57 * |
58 } |
58 * This class will iterate through that AST, and for each enumerated type declaration, will |
59 |
59 * create the apropriate conversion functions. |
60 create_enumtype_conversion_functions_c::~create_enumtype_conversion_functions_c(void) { |
60 */ |
61 |
61 |
62 } |
62 create_enumtype_conversion_functions_c *create_enumtype_conversion_functions_c::singleton = NULL; |
63 |
63 |
64 std::string &create_enumtype_conversion_functions_c::get_declaration(symbol_c *root) { |
64 create_enumtype_conversion_functions_c:: create_enumtype_conversion_functions_c(symbol_c *ignore) {} |
65 text = ""; |
65 create_enumtype_conversion_functions_c::~create_enumtype_conversion_functions_c(void) {} |
66 if (NULL != root) { |
66 |
67 root->accept(*this); |
67 |
68 } |
68 std::string &create_enumtype_conversion_functions_c::get_declaration(symbol_c *symbol) { |
69 |
69 if (NULL == singleton) singleton = new create_enumtype_conversion_functions_c(NULL); |
70 return text; |
70 if (NULL == singleton) ERROR_MSG("Out of memory. Bailing out!\n"); |
71 } |
71 |
|
72 singleton->text = ""; |
|
73 if (NULL != symbol) |
|
74 symbol->accept(*singleton); |
|
75 |
|
76 return singleton->text; |
|
77 } |
|
78 |
72 |
79 |
73 void *create_enumtype_conversion_functions_c::visit(identifier_c *symbol) { |
80 void *create_enumtype_conversion_functions_c::visit(identifier_c *symbol) { |
74 currentToken = symbol->value; |
81 currentToken = symbol->value; |
75 |
|
76 return NULL; |
82 return NULL; |
77 } |
83 } |
78 |
84 |
79 /**********************/ |
85 /**********************/ |
80 /* B 1.3 - Data types */ |
86 /* B 1.3 - Data types */ |