lbessard@70: /* Edouard@279: * matiec - a compiler for the programming languages defined in IEC 61131-3 lbessard@70: * Edouard@279: * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) Edouard@279: * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant lbessard@70: * Edouard@279: * This program is free software: you can redistribute it and/or modify Edouard@279: * it under the terms of the GNU General Public License as published by Edouard@279: * the Free Software Foundation, either version 3 of the License, or Edouard@279: * (at your option) any later version. Edouard@279: * Edouard@279: * This program is distributed in the hope that it will be useful, Edouard@279: * but WITHOUT ANY WARRANTY; without even the implied warranty of Edouard@279: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Edouard@279: * GNU General Public License for more details. Edouard@279: * Edouard@279: * You should have received a copy of the GNU General Public License Edouard@279: * along with this program. If not, see . Edouard@279: * lbessard@70: * lbessard@70: * This code is made available on the understanding that it will not be lbessard@70: * used in safety-critical situations without a full and competent review. lbessard@70: */ lbessard@70: etisserant@139: #include lbessard@70: lbessard@70: lbessard@70: lbessard@70: lbessard@149: typedef struct lbessard@149: { laurent@217: symbol_c *param_name; lbessard@149: symbol_c *param_value; lbessard@149: symbol_c *param_type; lbessard@149: function_param_iterator_c::param_direction_t param_direction; lbessard@149: } FUNCTION_PARAM; lbessard@149: laurent@217: #define DECLARE_PARAM_LIST()\ laurent@217: std::list param_list;\ laurent@217: std::list::iterator pt;\ laurent@217: FUNCTION_PARAM *param; laurent@217: laurent@217: #define ADD_PARAM_LIST(name, value, type, direction)\ lbessard@149: param = new FUNCTION_PARAM;\ laurent@217: param->param_name = name;\ lbessard@149: param->param_value = value;\ lbessard@149: param->param_type = type;\ lbessard@149: param->param_direction = direction;\ laurent@217: param_list.push_back(param); laurent@217: laurent@217: #define PARAM_LIST_ITERATOR() for(pt = param_list.begin(); pt != param_list.end(); pt++) laurent@217: laurent@217: #define PARAM_NAME (*pt)->param_name laurent@217: #define PARAM_VALUE (*pt)->param_value laurent@217: #define PARAM_TYPE (*pt)->param_type laurent@217: #define PARAM_DIRECTION (*pt)->param_direction laurent@217: laurent@217: #define CLEAR_PARAM_LIST()\ laurent@217: PARAM_LIST_ITERATOR()\ laurent@217: delete *pt;\ laurent@217: param_list.clear(); lbessard@70: lbessard@70: lbessard@70: class generate_c_base_c: public iterator_visitor_c { lbessard@70: lbessard@70: protected: lbessard@70: stage4out_c &s4o; lbessard@70: lbessard@70: private: lbessard@70: /* Unlike programs that are mapped onto C++ classes, Function Blocks are mapped onto a data structure type laurent@217: * and a separate function containing the code. This function is passed a pointer to an instance of the data lbessard@70: * structure. This means that the code inside the functions must insert a pointer to the data structure whenever lbessard@70: * it wishes to access a Function Block variable. lbessard@70: * The variable_prefix_ variable will contain the correct string which needs to be prefixed to all variable accesses. lbessard@70: * This string is set with the set_variable_prefix() member function. lbessard@70: */ lbessard@70: const char *variable_prefix_; lbessard@70: lbessard@70: public: laurent@217: generate_c_base_c(stage4out_c *s4o_ptr): s4o(*s4o_ptr) { laurent@217: variable_prefix_ = NULL; laurent@217: } lbessard@70: ~generate_c_base_c(void) {} lbessard@70: lbessard@70: void set_variable_prefix(const char *variable_prefix) {variable_prefix_ = variable_prefix;} lbessard@160: const char *get_variable_prefix(void) {return variable_prefix_;} lbessard@146: bool is_variable_prefix_null(void) {return variable_prefix_ == NULL;} lbessard@70: void print_variable_prefix(void) { lbessard@70: if (variable_prefix_ != NULL) lbessard@70: s4o.print(variable_prefix_); lbessard@70: } lbessard@70: lbessard@70: void *print_token(token_c *token, int offset = 0) { lbessard@70: return s4o.printupper((token->value)+offset); lbessard@70: } lbessard@70: lbessard@70: void *print_literal(symbol_c *type, symbol_c *value) { lbessard@70: s4o.print("__"); lbessard@70: type->accept(*this); lbessard@70: s4o.print("_LITERAL("); lbessard@70: value->accept(*this); lbessard@70: s4o.print(")"); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: void *print_striped_token(token_c *token, int offset = 0) { lbessard@70: std::string str = ""; laurent@312: bool leading_zero = true; laurent@312: for (unsigned int i = offset; i < strlen(token->value); i++) { laurent@312: if (leading_zero && laurent@312: (token->value[i] != '0' || laurent@312: i == strlen(token->value) - 1 || laurent@312: token->value[i + 1] == '.' laurent@312: )) laurent@312: leading_zero = false; laurent@312: if (!leading_zero && token->value[i] != '_') lbessard@70: str += token->value[i]; laurent@312: } lbessard@70: return s4o.printupper(str); lbessard@70: } lbessard@70: lbessard@70: void *print_striped_binary_token(token_c *token, unsigned int offset = 0) { lbessard@70: /* convert the binary value to hexadecimal format... */ lbessard@70: unsigned char value, bit_mult; lbessard@70: unsigned int i; lbessard@70: int total_bits; lbessard@70: char str[2] = {'A', '\0'}; /* since the s4o object is not prepared to print out one character at a time... */ lbessard@70: lbessard@70: s4o.print("0x"); lbessard@70: lbessard@70: total_bits = 0; lbessard@70: for (i = offset; i < strlen(token->value); i++) lbessard@70: if (token->value[i] != '_') lbessard@70: total_bits++; lbessard@70: lbessard@70: value = 0; lbessard@70: bit_mult = (unsigned char)1 << (((total_bits+3)%4)+1); lbessard@70: for (i = offset; i < strlen(token->value); i++) { lbessard@70: if (token->value[i] != '_') { lbessard@70: bit_mult /= 2; lbessard@70: value += bit_mult * ((token->value[i] == '0')? 0:1); lbessard@70: if (bit_mult == 1) { msousa@308: str[0] = (value <= 9)? (char)'0' + value : (char)'A' + value - 10; lbessard@70: s4o.print(str); lbessard@70: bit_mult = 0x10; lbessard@70: value = 0; lbessard@70: } lbessard@70: } lbessard@70: } lbessard@70: lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: void *print_list(list_c *list, lbessard@70: std::string pre_elem_str = "", lbessard@70: std::string inter_elem_str = "", lbessard@70: std::string post_elem_str = "", lbessard@70: visitor_c *visitor = NULL) { lbessard@70: if (visitor == NULL) visitor = this; lbessard@70: lbessard@70: if (list->n > 0) { lbessard@70: //std::cout << "generate_c_base_c::print_list(n = " << list->n << ") 000\n"; lbessard@70: s4o.print(pre_elem_str); lbessard@70: list->elements[0]->accept(*visitor); lbessard@70: } lbessard@70: lbessard@70: for(int i = 1; i < list->n; i++) { lbessard@70: //std::cout << "generate_c_base_c::print_list " << i << "\n"; lbessard@70: s4o.print(inter_elem_str); lbessard@70: list->elements[i]->accept(*visitor); lbessard@70: } lbessard@70: lbessard@70: if (list->n > 0) lbessard@70: s4o.print(post_elem_str); lbessard@70: lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: lbessard@70: void *print_binary_expression(symbol_c *l_exp, lbessard@70: symbol_c *r_exp, lbessard@70: const char *operation) { lbessard@70: s4o.print("("); lbessard@70: l_exp->accept(*this); lbessard@70: s4o.print(operation); lbessard@70: r_exp->accept(*this); lbessard@70: s4o.print(")"); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: void *print_unary_expression(symbol_c *exp, lbessard@70: const char *operation) { lbessard@70: s4o.print(operation); lbessard@70: s4o.print("("); lbessard@70: exp->accept(*this); lbessard@70: s4o.print(")"); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: void *print_binary_function(const char *function, lbessard@70: symbol_c *l_exp, lbessard@70: symbol_c *r_exp) { lbessard@70: s4o.print(function); lbessard@70: s4o.print("("); lbessard@70: l_exp->accept(*this); lbessard@70: s4o.print(", "); lbessard@70: r_exp->accept(*this); lbessard@70: s4o.print(")"); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: void *print_compare_function(const char *function, lbessard@70: symbol_c *compare_type, lbessard@70: symbol_c *l_exp, lbessard@70: symbol_c *r_exp) { lbessard@70: s4o.print(function); lbessard@70: compare_type->accept(*this); lbessard@149: s4o.print("(__BOOL_LITERAL(TRUE), NULL, 2, "); lbessard@70: l_exp->accept(*this); lbessard@70: s4o.print(", "); lbessard@70: r_exp->accept(*this); lbessard@70: s4o.print(")"); lbessard@70: return NULL; lbessard@70: } lbessard@70: laurent@217: void *print_check_function(symbol_c *type, laurent@217: symbol_c *value, laurent@217: symbol_c *fb_name = NULL, laurent@217: bool temp = false) { msousa@854: if (!get_datatype_info_c::is_type_valid(type)) ERROR; msousa@854: bool is_subrange = get_datatype_info_c::is_subrange(type); laurent@217: if (is_subrange) { laurent@217: s4o.print("__CHECK_"); laurent@217: type->accept(*this); laurent@217: s4o.print("("); laurent@217: } laurent@217: if (fb_name != NULL) { laurent@240: s4o.print(GET_VAR); laurent@240: s4o.print("("); laurent@217: print_variable_prefix(); laurent@217: fb_name->accept(*this); laurent@217: s4o.print("."); laurent@240: value->accept(*this); laurent@240: s4o.print(")"); laurent@217: } laurent@240: else { laurent@240: if (temp) laurent@240: s4o.print(TEMP_VAR); laurent@240: value->accept(*this); laurent@240: } laurent@217: if (is_subrange) laurent@240: s4o.print(")"); laurent@217: return NULL; laurent@217: } laurent@217: msousa@267: /********************/ msousa@267: /* 2.1.6 - Pragmas */ msousa@267: /********************/ msousa@267: void *visit(enable_code_generation_pragma_c * symbol) {s4o.enable_output(); return NULL;} msousa@267: void *visit(disable_code_generation_pragma_c * symbol) {s4o.disable_output(); return NULL;} msousa@267: lbessard@70: /* Do not use print_token() as it will change everything into uppercase */ Edouard@634: void *visit(pragma_c *symbol) { Edouard@634: s4o.print(s4o.indent_spaces); Edouard@634: s4o.print("#define GetFbVar(var,...) __GET_VAR(data__->var,__VA_ARGS__)\n"); Edouard@634: s4o.print(s4o.indent_spaces); Edouard@634: s4o.print("#define SetFbVar(var,val,...) __SET_VAR(data__->,var,val,__VA_ARGS__)\n"); Edouard@634: s4o.print(symbol->value); Edouard@634: s4o.print("\n"); Edouard@634: s4o.print(s4o.indent_spaces); Edouard@634: s4o.print("#undef GetFbVar\n"); Edouard@634: s4o.print(s4o.indent_spaces); Edouard@634: s4o.print("#undef SetFbVar\n"); Edouard@634: return NULL; Edouard@634: } lbessard@70: lbessard@70: lbessard@70: /***************************/ lbessard@70: /* B 0 - Programming Model */ lbessard@70: /***************************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: lbessard@70: lbessard@70: /*************************/ lbessard@70: /* B.1 - Common elements */ lbessard@70: /*************************/ lbessard@70: /*******************************************/ lbessard@70: /* B 1.1 - Letters, digits and identifiers */ lbessard@70: /*******************************************/ lbessard@70: void *visit(identifier_c *symbol) {return print_token(symbol);} lbessard@70: lbessard@70: /*********************/ lbessard@70: /* B 1.2 - Constants */ lbessard@70: /*********************/ lbessard@70: /* originally empty... */ lbessard@70: lbessard@70: /******************************/ lbessard@70: /* B 1.2.1 - Numeric Literals */ lbessard@70: /******************************/ lbessard@70: void *visit(real_c *symbol) {return print_striped_token(symbol);} lbessard@70: void *visit(integer_c *symbol) {return print_striped_token(symbol);} lbessard@70: void *visit(binary_integer_c *symbol) {return print_striped_binary_token(symbol, 2);} lbessard@70: void *visit(octal_integer_c *symbol) {s4o.print("0"); return print_striped_token(symbol, 2);} lbessard@70: void *visit(hex_integer_c *symbol) {s4o.print("0x"); return print_striped_token(symbol, 3);} lbessard@70: msousa@257: void *visit(neg_real_c *symbol) { msousa@257: s4o.print("-"); msousa@257: symbol->exp->accept(*this); msousa@257: return NULL; msousa@257: } msousa@257: msousa@257: void *visit(neg_integer_c *symbol) { msousa@257: s4o.print("-"); msousa@257: symbol->exp->accept(*this); msousa@257: return NULL; msousa@257: } msousa@257: lbessard@70: void *visit(integer_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} lbessard@70: void *visit(real_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} lbessard@70: void *visit(bit_string_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} msousa@257: void *visit(boolean_literal_c *symbol) { msousa@257: if (NULL != symbol->type) msousa@257: return print_literal(symbol->type, symbol->value); msousa@257: else { msousa@257: bool_type_name_c bool_type; msousa@257: return print_literal(&bool_type, symbol->value); msousa@257: } msousa@257: } lbessard@70: lbessard@70: /* helper class for boolean_literal_c */ lbessard@70: void *visit(boolean_true_c *symbol) {s4o.print("TRUE"); return NULL;} lbessard@70: void *visit(boolean_false_c *symbol) {s4o.print("FALSE"); return NULL;} lbessard@70: lbessard@98: void *visit(neg_expression_c *symbol) { lbessard@98: s4o.print("-"); lbessard@98: symbol->exp->accept(*this); lbessard@98: return NULL; lbessard@98: } lbessard@98: lbessard@70: /*******************************/ lbessard@70: /* B.1.2.2 Character Strings */ lbessard@70: /*******************************/ lbessard@70: void *visit(double_byte_character_string_c *symbol) { lbessard@70: // TO DO ... lbessard@70: ERROR; lbessard@70: return print_token(symbol); lbessard@70: } lbessard@70: lbessard@70: void *visit(single_byte_character_string_c *symbol) { lbessard@70: std::string str = ""; lbessard@70: unsigned int count = 0; lbessard@70: str += '"'; lbessard@70: /* we ignore the first and last bytes, they will be the character ' */ lbessard@70: for (unsigned int i = 1; i < strlen(symbol->value) - 1; i++) { lbessard@70: char c = symbol->value[i]; lbessard@70: if ((c == '\\') || (c == '"')) lbessard@70: {str += '\\'; str += c; count ++; continue;} lbessard@70: if (c != '$') lbessard@70: {str += c; count++; continue;} lbessard@70: /* this should be safe, since the code has passed the syntax parser!! */ lbessard@70: c = symbol->value[++i]; lbessard@70: switch (c) { lbessard@70: case '$': lbessard@70: case '\'': lbessard@70: {str += c; count++; continue;} lbessard@70: case 'L': lbessard@70: case 'l': lbessard@70: {str += "\x0A"; /* LF */; count++; continue;} lbessard@70: case 'N': lbessard@70: case 'n': lbessard@70: {str += "\\x0A"; /* NL */; count++; continue;} lbessard@70: case 'P': lbessard@70: case 'p': lbessard@70: {str += "\\f"; /* FF */; count++; continue;} lbessard@70: case 'R': lbessard@70: case 'r': lbessard@70: {str += "\\r"; /* CR */; count++; continue;} lbessard@70: case 'T': lbessard@70: case 't': lbessard@70: {str += "\\t"; /* tab */; count++; continue;} lbessard@70: default: { lbessard@70: if (isxdigit(c)) { lbessard@70: /* this should be safe, since the code has passed the syntax parser!! */ lbessard@70: char c2 = symbol->value[++i]; lbessard@70: if (isxdigit(c2)) { lbessard@70: str += '\\'; str += 'x'; str += c; str += c2; lbessard@70: count++; continue; lbessard@70: } lbessard@70: } lbessard@70: } lbessard@70: /* otherwise we have an invalid string!! */ lbessard@70: /* This should not have got through the syntax parser! */ lbessard@70: ERROR; lbessard@70: } /* switch() */ lbessard@70: } /* for() */ lbessard@70: lbessard@70: str += '"'; laurent@217: s4o.print("__STRING_LITERAL("); msousa@594: s4o.print(count); lbessard@70: s4o.print(","); lbessard@70: s4o.print(str); laurent@217: s4o.print(")"); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: lbessard@70: /***************************/ lbessard@70: /* B 1.2.3 - Time Literals */ lbessard@70: /***************************/ lbessard@70: lbessard@70: /************************/ lbessard@70: /* B 1.2.3.1 - Duration */ lbessard@70: /************************/ lbessard@70: /* The following output is actually the parameters to the constructor of the TIME class! */ lbessard@70: lbessard@70: /* SYM_REF0(neg_time_c) */ lbessard@70: void *visit(neg_time_c *symbol) {s4o.print("-1"); /* negative time value */; return NULL;} lbessard@70: lbessard@70: lbessard@70: /* SYM_REF2(duration_c, neg, interval) */ lbessard@70: void *visit(duration_c *symbol) { lbessard@70: TRACE("duration_c"); lbessard@70: s4o.print("__time_to_timespec("); msousa@547: msousa@547: if (NULL == symbol->neg) s4o.print("1"); /* positive time value */ msousa@547: else symbol->neg->accept(*this); /* this will print '-1' :-) */ msousa@547: msousa@547: s4o.print(", "); lbessard@70: symbol->interval->accept(*this); lbessard@70: s4o.print(")"); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: lbessard@70: /* SYM_TOKEN(fixed_point_c) */ laurent@312: void *visit(fixed_point_c *symbol) {return print_striped_token(symbol);} lbessard@70: msousa@547: /* SYM_REF5(interval_c, days, hours, minutes, seconds, milliseconds) */ msousa@547: void *visit(interval_c *symbol) { msousa@547: TRACE("interval_c"); msousa@547: /* s4o.print("0, 0, 0, 0, 0"); // milliseconds, seconds, minutes, hours, days */ msousa@547: if (NULL == symbol->milliseconds) s4o.print("0"); /* milliseconds */ msousa@547: else symbol->milliseconds->accept(*this); msousa@547: s4o.print(", "); msousa@547: msousa@547: if (NULL == symbol->seconds) s4o.print("0"); /* seconds */ msousa@547: else symbol->seconds->accept(*this); msousa@547: s4o.print(", "); msousa@547: msousa@547: if (NULL == symbol->minutes) s4o.print("0"); /* minutes */ msousa@547: else symbol->minutes->accept(*this); msousa@547: s4o.print(", "); msousa@547: msousa@547: if (NULL == symbol->hours) s4o.print("0"); /* hours */ msousa@547: else symbol->hours->accept(*this); msousa@547: s4o.print(", "); msousa@547: msousa@547: if (NULL == symbol->days) s4o.print("0"); /* days */ msousa@547: else symbol->days->accept(*this); msousa@547: msousa@547: return NULL; msousa@547: } msousa@547: lbessard@70: lbessard@70: /************************************/ lbessard@70: /* B 1.2.3.2 - Time of day and Date */ lbessard@70: /************************************/ lbessard@70: lbessard@70: /* SYM_REF2(time_of_day_c, daytime, unused) */ lbessard@70: void *visit(time_of_day_c *symbol) { lbessard@70: TRACE("time_of_day_c"); lbessard@70: s4o.print("__tod_to_timespec("); lbessard@70: symbol->daytime->accept(*this); lbessard@70: s4o.print(")"); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: lbessard@70: /* SYM_REF4(daytime_c, day_hour, day_minute, day_second, unused) */ lbessard@70: void *visit(daytime_c *symbol) { lbessard@70: TRACE("daytime_c"); lbessard@70: symbol->day_second->accept(*this); lbessard@70: s4o.print(", "); lbessard@70: symbol->day_minute->accept(*this); lbessard@70: s4o.print(", "); lbessard@70: symbol->day_hour->accept(*this); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: lbessard@70: /* SYM_REF2(date_c, date_literal, unused) */ lbessard@70: void *visit(date_c *symbol) { lbessard@70: TRACE("date_c"); lbessard@70: s4o.print("__date_to_timespec("); lbessard@70: symbol->date_literal->accept(*this); lbessard@70: s4o.print(")"); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: lbessard@70: /* SYM_REF4(date_literal_c, year, month, day, unused) */ lbessard@70: void *visit(date_literal_c *symbol) { lbessard@70: TRACE("date_literal_c"); lbessard@70: symbol->day->accept(*this); lbessard@70: s4o.print(", "); lbessard@70: symbol->month->accept(*this); lbessard@70: s4o.print(", "); lbessard@70: symbol->year->accept(*this); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: lbessard@70: /* SYM_REF2(date_and_time_c, date_literal, daytime) */ lbessard@70: void *visit(date_and_time_c *symbol) { lbessard@70: TRACE("date_and_time_c"); lbessard@70: s4o.print("__dt_to_timespec("); lbessard@70: symbol->daytime->accept(*this); lbessard@70: s4o.print(", "); lbessard@70: symbol->date_literal->accept(*this); lbessard@70: s4o.print(")"); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: lbessard@70: /**********************/ lbessard@70: /* B.1.3 - Data types */ lbessard@70: /**********************/ lbessard@70: /***********************************/ lbessard@70: /* B 1.3.1 - Elementary Data Types */ lbessard@70: /***********************************/ msousa@257: void *visit(time_type_name_c *symbol) {s4o.print("TIME"); return NULL;} msousa@257: void *visit(bool_type_name_c *symbol) {s4o.print("BOOL"); return NULL;} msousa@257: void *visit(sint_type_name_c *symbol) {s4o.print("SINT"); return NULL;} msousa@257: void *visit(int_type_name_c *symbol) {s4o.print("INT"); return NULL;} msousa@257: void *visit(dint_type_name_c *symbol) {s4o.print("DINT"); return NULL;} msousa@257: void *visit(lint_type_name_c *symbol) {s4o.print("LINT"); return NULL;} msousa@257: void *visit(usint_type_name_c *symbol) {s4o.print("USINT"); return NULL;} msousa@257: void *visit(uint_type_name_c *symbol) {s4o.print("UINT"); return NULL;} msousa@257: void *visit(udint_type_name_c *symbol) {s4o.print("UDINT"); return NULL;} msousa@257: void *visit(ulint_type_name_c *symbol) {s4o.print("ULINT"); return NULL;} msousa@257: void *visit(real_type_name_c *symbol) {s4o.print("REAL"); return NULL;} msousa@257: void *visit(lreal_type_name_c *symbol) {s4o.print("LREAL"); return NULL;} msousa@257: void *visit(date_type_name_c *symbol) {s4o.print("DATE"); return NULL;} msousa@257: void *visit(tod_type_name_c *symbol) {s4o.print("TOD"); return NULL;} msousa@257: void *visit(dt_type_name_c *symbol) {s4o.print("DT"); return NULL;} msousa@257: void *visit(byte_type_name_c *symbol) {s4o.print("BYTE"); return NULL;} msousa@257: void *visit(word_type_name_c *symbol) {s4o.print("WORD"); return NULL;} msousa@257: void *visit(lword_type_name_c *symbol) {s4o.print("LWORD"); return NULL;} msousa@257: void *visit(dword_type_name_c *symbol) {s4o.print("DWORD"); return NULL;} msousa@257: void *visit(string_type_name_c *symbol) {s4o.print("STRING"); return NULL;} msousa@257: void *visit(wstring_type_name_c *symbol) {s4o.print("WSTRING"); return NULL;} msousa@257: msousa@257: void *visit(safetime_type_name_c *symbol) {s4o.print("TIME"); return NULL;} msousa@257: void *visit(safebool_type_name_c *symbol) {s4o.print("BOOL"); return NULL;} msousa@257: void *visit(safesint_type_name_c *symbol) {s4o.print("SINT"); return NULL;} msousa@257: void *visit(safeint_type_name_c *symbol) {s4o.print("INT"); return NULL;} msousa@257: void *visit(safedint_type_name_c *symbol) {s4o.print("DINT"); return NULL;} msousa@257: void *visit(safelint_type_name_c *symbol) {s4o.print("LINT"); return NULL;} msousa@257: void *visit(safeusint_type_name_c *symbol) {s4o.print("USINT"); return NULL;} msousa@257: void *visit(safeuint_type_name_c *symbol) {s4o.print("UINT"); return NULL;} msousa@257: void *visit(safeudint_type_name_c *symbol) {s4o.print("UDINT"); return NULL;} msousa@257: void *visit(safeulint_type_name_c *symbol) {s4o.print("ULINT"); return NULL;} msousa@257: void *visit(safereal_type_name_c *symbol) {s4o.print("REAL"); return NULL;} msousa@257: void *visit(safelreal_type_name_c *symbol) {s4o.print("LREAL"); return NULL;} msousa@257: void *visit(safedate_type_name_c *symbol) {s4o.print("DATE"); return NULL;} msousa@257: void *visit(safetod_type_name_c *symbol) {s4o.print("TOD"); return NULL;} msousa@257: void *visit(safedt_type_name_c *symbol) {s4o.print("DT"); return NULL;} msousa@257: void *visit(safebyte_type_name_c *symbol) {s4o.print("BYTE"); return NULL;} msousa@257: void *visit(safeword_type_name_c *symbol) {s4o.print("WORD"); return NULL;} msousa@257: void *visit(safelword_type_name_c *symbol) {s4o.print("LWORD"); return NULL;} msousa@257: void *visit(safedword_type_name_c *symbol) {s4o.print("DWORD"); return NULL;} msousa@257: void *visit(safestring_type_name_c *symbol) {s4o.print("STRING"); return NULL;} msousa@257: void *visit(safewstring_type_name_c *symbol) {s4o.print("WSTRING"); return NULL;} lbessard@70: lbessard@70: /********************************/ lbessard@70: /* B.1.3.2 - Generic data types */ lbessard@70: /********************************/ lbessard@70: /* originally empty... */ lbessard@70: lbessard@70: /********************************/ lbessard@70: /* B 1.3.3 - Derived data types */ lbessard@70: /********************************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /*********************/ lbessard@70: /* B 1.4 - Variables */ lbessard@70: /*********************/ lbessard@70: void *visit(symbolic_variable_c *symbol) { lbessard@70: TRACE("symbolic_variable_c"); lbessard@70: this->print_variable_prefix(); lbessard@70: symbol->var_name->accept(*this); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: /********************************************/ lbessard@70: /* B.1.4.1 Directly Represented Variables */ lbessard@70: /********************************************/ lbessard@70: void *visit(direct_variable_c *symbol) { lbessard@70: TRACE("direct_variable_c"); lbessard@70: /* Do not use print_token() as it will change everything into uppercase */ lbessard@70: return s4o.printlocation(symbol->value); lbessard@70: } lbessard@70: lbessard@70: lbessard@70: lbessard@70: /*************************************/ lbessard@70: /* B.1.4.2 Multi-element Variables */ lbessard@70: /*************************************/ lbessard@70: #if 0 lbessard@70: /* subscripted_variable '[' subscript_list ']' */ lbessard@70: SYM_REF2(array_variable_c, subscripted_variable, subscript_list) lbessard@70: lbessard@70: #endif lbessard@70: lbessard@70: /* record_variable '.' field_selector */ lbessard@70: /* WARNING: input and/or output variables of function blocks lbessard@70: * may be accessed as fields of a structured variable! lbessard@70: * Code handling a structured_variable_c must take lbessard@70: * this into account! lbessard@70: */ lbessard@70: // SYM_REF2(structured_variable_c, record_variable, field_selector) lbessard@70: void *visit(structured_variable_c *symbol) { lbessard@70: TRACE("structured_variable_c"); lbessard@70: lbessard@70: symbol->record_variable->accept(*this); lbessard@70: s4o.print("."); lbessard@70: symbol->field_selector->accept(*this); lbessard@70: return NULL; lbessard@70: } lbessard@70: lbessard@70: /******************************************/ lbessard@70: /* B 1.4.3 - Declaration & Initialisation */ lbessard@70: /******************************************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /**************************************/ lbessard@70: /* B.1.5 - Program organization units */ lbessard@70: /**************************************/ lbessard@70: /***********************/ lbessard@70: /* B 1.5.1 - Functions */ lbessard@70: /***********************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /*****************************/ lbessard@70: /* B 1.5.2 - Function Blocks */ lbessard@70: /*****************************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /**********************/ lbessard@70: /* B 1.5.3 - Programs */ lbessard@70: /**********************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /*********************************************/ lbessard@70: /* B.1.6 Sequential function chart elements */ lbessard@70: /*********************************************/ lbessard@70: lbessard@70: /********************************/ lbessard@70: /* B 1.7 Configuration elements */ lbessard@70: /********************************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /****************************************/ lbessard@70: /* B.2 - Language IL (Instruction List) */ lbessard@70: /****************************************/ lbessard@70: /***********************************/ lbessard@70: /* B 2.1 Instructions and Operands */ lbessard@70: /***********************************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /*******************/ lbessard@70: /* B 2.2 Operators */ lbessard@70: /*******************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: lbessard@70: /***************************************/ lbessard@70: /* B.3 - Language ST (Structured Text) */ lbessard@70: /***************************************/ lbessard@70: /***********************/ lbessard@70: /* B 3.1 - Expressions */ lbessard@70: /***********************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /********************/ lbessard@70: /* B 3.2 Statements */ lbessard@70: /********************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /*********************************/ lbessard@70: /* B 3.2.1 Assignment Statements */ lbessard@70: /*********************************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /*****************************************/ lbessard@70: /* B 3.2.2 Subprogram Control Statements */ lbessard@70: /*****************************************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /********************************/ lbessard@70: /* B 3.2.3 Selection Statements */ lbessard@70: /********************************/ lbessard@70: /* leave for derived classes... */ lbessard@70: lbessard@70: /********************************/ lbessard@70: /* B 3.2.4 Iteration Statements */ lbessard@70: /********************************/ lbessard@70: /* leave for derived classes... */ lbessard@70: mario@177: lbessard@70: }; /* class generate_c_basic_c */ lbessard@70: lbessard@70: lbessard@70: lbessard@70: lbessard@70: lbessard@70: lbessard@70: lbessard@70: lbessard@70: lbessard@70: lbessard@70: lbessard@70: lbessard@70: lbessard@70: