231 * A single C datatype declaration will be generated for both arrays |
231 * A single C datatype declaration will be generated for both arrays |
232 * (the datatypes_already_defined keeps track of which datatypes have already been declared in C) |
232 * (the datatypes_already_defined keeps track of which datatypes have already been declared in C) |
233 * This method of handling arrays is needed when the relaxed datatype model is used |
233 * This method of handling arrays is needed when the relaxed datatype model is used |
234 * (see get_datatype_info_c for explanation on the relaxed datatype model). |
234 * (see get_datatype_info_c for explanation on the relaxed datatype model). |
235 */ |
235 */ |
236 /* Notice that this class inherits from generate_c_base_c, and not from generate_c_base_and_typeid_c. |
236 /* The generate_c_typedecl_c inherits from generate_c_base_and_typeid_c because it will need the visitor's() to |
237 * This is intentional! |
237 * identifier_c, derived_datatype_identifier_c, and enumerated_value_c |
238 * Whenever this class needs to print out the id of a datatype, it will explicitly use a private instance |
|
239 * (generate_c_typeid) of generate_c_base_and_typeid_c! |
|
240 */ |
238 */ |
241 class generate_c_typedecl_c: public generate_c_base_and_typeid_c { |
239 class generate_c_typedecl_c: public generate_c_base_and_typeid_c { |
242 |
240 |
243 protected: |
241 protected: |
|
242 /* The following member variable is completely useless - the s4o variable inherited from generate_c_base_and_typeid_c |
|
243 * could be used to the same effect. We keep it here merely because this generate_c_typedecl_c will typically be called |
|
244 * with s4o referencing an include file (typically POUS.h), and using s4o_incl throughout this code will help the reader |
|
245 * of the code to keep this fact in mind. |
|
246 */ |
244 stage4out_c &s4o_incl; |
247 stage4out_c &s4o_incl; |
245 |
248 |
246 private: |
249 private: |
247 symbol_c* current_type_name; |
250 symbol_c* current_type_name; |
|
251 std::map<std::string, int> datatypes_already_defined; |
|
252 /* Although this generate_c_typedecl_c inherits directly from generate_c_base_and_typeid_c, we still need an independent |
|
253 * instance of that base class. This is because generate_c_typedecl_c will overload some of the visitors in the base class |
|
254 * generate_c_base_and_typeid_c. |
|
255 * When we want the to use the version of these visitors() in generate_c_typedecl_c, we call accept(*this); |
|
256 * When we want the to use the version of these visitors() in generate_c_base_and_typeid_c, we call accept(*generate_c_typeid); |
|
257 */ |
248 generate_c_base_and_typeid_c *generate_c_typeid; |
258 generate_c_base_and_typeid_c *generate_c_typeid; |
249 std::map<std::string, int> datatypes_already_defined; |
259 |
250 |
260 |
251 public: |
261 public: |
252 generate_c_typedecl_c(stage4out_c *s4o_ptr): generate_c_base_and_typeid_c(s4o_ptr), s4o_incl(*s4o_ptr) /*, generate_c_print_typename(s4o_ptr) */{ |
262 generate_c_typedecl_c(stage4out_c *s4o_ptr): generate_c_base_and_typeid_c(s4o_ptr), s4o_incl(*s4o_ptr) /*, generate_c_print_typename(s4o_ptr) */{ |
253 current_typedefinition = none_td; |
263 current_typedefinition = none_td; |
254 current_basetypedeclaration = none_bd; |
264 current_basetypedeclaration = none_bd; |
893 // direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
903 // direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
894 void *visit(direct_variable_c *symbol) { |
904 void *visit(direct_variable_c *symbol) { |
895 TRACE("direct_variable_c"); |
905 TRACE("direct_variable_c"); |
896 /* Do not use print_token() as it will change everything into uppercase */ |
906 /* Do not use print_token() as it will change everything into uppercase */ |
897 if (strlen(symbol->value) == 0) ERROR; |
907 if (strlen(symbol->value) == 0) ERROR; |
898 return s4o.printlocation(symbol->value + 1); |
908 return s4o_incl.printlocation(symbol->value + 1); |
899 } |
909 } |
900 |
910 |
901 |
911 |
902 /*************************************/ |
912 /*************************************/ |
903 /* B.1.4.2 Multi-element Variables */ |
913 /* B.1.4.2 Multi-element Variables */ |