etisserant@0: /* etisserant@0: * (c) 2003 Mario de Sousa etisserant@0: * etisserant@0: * Offered to the public under the terms of the GNU General Public License etisserant@0: * as published by the Free Software Foundation; either version 2 of the etisserant@0: * License, or (at your option) any later version. etisserant@0: * etisserant@0: * This program is distributed in the hope that it will be useful, but etisserant@0: * WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General etisserant@0: * Public License for more details. etisserant@0: * etisserant@0: * This code is made available on the understanding that it will not be etisserant@0: * used in safety-critical situations without a full and competent review. etisserant@0: */ etisserant@0: etisserant@0: /* etisserant@0: * An IEC 61131-3 IL and ST compiler. etisserant@0: * etisserant@0: * Based on the etisserant@0: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) etisserant@0: * etisserant@0: */ etisserant@0: etisserant@0: etisserant@0: etisserant@0: /* Determine the data type of a specific constant or variable. etisserant@0: * A reference to the relevant type definition is returned. etisserant@0: * etisserant@0: * For example: etisserant@0: * 22 -> returns reference to a int_type_name_c object. etisserant@0: * 22.2 -> returns reference to a real_type_name_c object. etisserant@0: * LREAL#22.2 -> returns reference to a lreal_type_name_c object. etisserant@0: * etc... etisserant@0: */ etisserant@0: class search_constant_type_c: public search_visitor_c { etisserant@0: etisserant@0: public: etisserant@0: /**********************/ etisserant@0: /* B.1.3 - Data types */ etisserant@0: /**********************/ etisserant@0: /***********************************/ etisserant@0: /* B 1.3.1 - Elementary Data Types */ etisserant@0: /***********************************/ etisserant@0: static real_type_name_c real_type_name; etisserant@0: static int_type_name_c int_type_name; etisserant@0: static string_type_name_c string_type_name; etisserant@0: static wstring_type_name_c wstring_type_name; etisserant@0: static time_type_name_c time_type_name; etisserant@0: static date_type_name_c date_type_name; etisserant@0: static dt_type_name_c dt_type_name; etisserant@0: static tod_type_name_c tod_type_name; etisserant@0: etisserant@0: etisserant@0: public: etisserant@0: symbol_c *get_type(symbol_c *constant) { etisserant@0: return (symbol_c *)constant->accept(*this); etisserant@0: } etisserant@0: etisserant@0: public: etisserant@0: /*********************/ etisserant@0: /* B 1.2 - Constants */ etisserant@0: /*********************/ etisserant@0: etisserant@0: /******************************/ etisserant@0: /* B 1.2.1 - Numeric Literals */ etisserant@0: /******************************/ etisserant@0: void *visit(real_c *symbol) {return (void *)&real_type_name;} etisserant@0: void *visit(integer_c *symbol) {return (void *)&int_type_name;} etisserant@0: void *visit(binary_integer_c *symbol) {return (void *)&int_type_name;} etisserant@0: void *visit(octal_integer_c *symbol) {return (void *)&int_type_name;} etisserant@0: void *visit(hex_integer_c *symbol) {return (void *)&int_type_name;} etisserant@0: etisserant@0: void *visit(numeric_literal_c *symbol) etisserant@0: {return (void *)((symbol->type!=NULL)?symbol->type:symbol->value->accept(*this));} etisserant@0: void *visit(integer_literal_c *symbol) etisserant@0: {return (void *)((symbol->type!=NULL)?symbol->type:symbol->value->accept(*this));} etisserant@0: void *visit(real_literal_c *symbol) etisserant@0: {return (void *)((symbol->type!=NULL)?symbol->type:symbol->value->accept(*this));} etisserant@0: void *visit(bit_string_literal_c *symbol) etisserant@0: {return (void *)((symbol->type!=NULL)?symbol->type:symbol->value->accept(*this));} etisserant@0: void *visit(boolean_literal_c *symbol) etisserant@0: {return (void *)((symbol->type!=NULL)?symbol->type:symbol->value->accept(*this));} etisserant@0: etisserant@0: /*******************************/ etisserant@0: /* B.1.2.2 Character Strings */ etisserant@0: /*******************************/ etisserant@0: void *visit(double_byte_character_string_c *symbol) {return (void *)&wstring_type_name;} etisserant@0: void *visit(single_byte_character_string_c *symbol) {return (void *)&string_type_name;} etisserant@0: etisserant@0: /***************************/ etisserant@0: /* B 1.2.3 - Time Literals */ etisserant@0: /***************************/ etisserant@0: /************************/ etisserant@0: /* B 1.2.3.1 - Duration */ etisserant@0: /************************/ etisserant@0: void *visit(neg_time_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ etisserant@0: void *visit(duration_c *symbol) {return (void *)&time_type_name;} etisserant@0: void *visit(fixed_point_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ etisserant@0: void *visit(days_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ etisserant@0: void *visit(hours_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ etisserant@0: void *visit(minutes_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ etisserant@0: void *visit(seconds_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ etisserant@0: void *visit(milliseconds_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ etisserant@0: etisserant@0: /************************************/ etisserant@0: /* B 1.2.3.2 - Time of day and Date */ etisserant@0: /************************************/ etisserant@0: void *visit(time_of_day_c *symbol) {return (void *)&tod_type_name;} etisserant@0: void *visit(daytime_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ etisserant@0: void *visit(date_c *symbol) {return (void *)&date_type_name;} etisserant@0: void *visit(date_literal_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ etisserant@0: void *visit(date_and_time_c *symbol) {return (void *)&dt_type_name;} etisserant@0: }; etisserant@0: etisserant@0: real_type_name_c search_constant_type_c::real_type_name; etisserant@0: int_type_name_c search_constant_type_c::int_type_name; etisserant@0: string_type_name_c search_constant_type_c::string_type_name; etisserant@0: wstring_type_name_c search_constant_type_c::wstring_type_name; etisserant@0: time_type_name_c search_constant_type_c::time_type_name; etisserant@0: date_type_name_c search_constant_type_c::date_type_name; etisserant@0: dt_type_name_c search_constant_type_c::dt_type_name; etisserant@0: tod_type_name_c search_constant_type_c::tod_type_name; etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: