diff -r 49853bded539 -r 26cb3fa00d29 stage1_2/derived_conversion_functions.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stage1_2/derived_conversion_functions.hh Thu Nov 15 17:30:35 2012 +0100 @@ -0,0 +1,68 @@ +/* + * matiec - a compiler for the programming languages defined in IEC 61131-3 + * + * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt) + * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it) + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + * This code is made available on the understanding that it will not be + * used in safety-critical situations without a full and competent review. + */ + +/* + * An IEC 61131-3 compiler. + * + * Based on the + * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) + * + */ + +#ifndef _DERIVED_CONVERSION_FUNCTIONS_H +#define _DERIVED_CONVERSION_FUNCTIONS_H + +#include "../absyntax_utils/absyntax_utils.hh" +#include +#include + +class derived_conversion_functions_c: public iterator_visitor_c { + public: + explicit derived_conversion_functions_c(symbol_c *ignore); + virtual ~derived_conversion_functions_c(void); + std::string &get_declaration(symbol_c *root); + + void *visit(identifier_c *symbol); + /**********************/ + /* B 1.3 - Data types */ + /**********************/ + /********************************/ + /* B 1.3.3 - Derived data types */ + /********************************/ + void *visit(enumerated_type_declaration_c *symbol); + void *visit(enumerated_value_list_c *symbol); + + private: + std::string text; + std::string currentToken; + std::list< std::string> currentTokenList; + std::string getIntegerName(bool isSigned, size_t size); + void printStringToEnum (std::string &enumerateName, std::list &enumerateValues); + void printEnumToString (std::string &enumerateName, std::list &enumerateValues); + void printIntegerToEnum (std::string &enumerateName, std::list &enumerateValues, bool isSigned, size_t size); + void printEnumToInteger (std::string &enumerateName, std::list &enumerateValues, bool isSigned, size_t size); +}; + +#endif /* _DERIVED_CONVERSION_FUNCTIONS_H */