msousa@417: /*
msousa@417: * matiec - a compiler for the programming languages defined in IEC 61131-3
msousa@417: *
msousa@417: * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt)
msousa@417: * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it)
msousa@417: *
msousa@417: * This program is free software: you can redistribute it and/or modify
msousa@417: * it under the terms of the GNU General Public License as published by
msousa@417: * the Free Software Foundation, either version 3 of the License, or
msousa@417: * (at your option) any later version.
msousa@417: *
msousa@417: * This program is distributed in the hope that it will be useful,
msousa@417: * but WITHOUT ANY WARRANTY; without even the implied warranty of
msousa@417: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
msousa@417: * GNU General Public License for more details.
msousa@417: *
msousa@417: * You should have received a copy of the GNU General Public License
msousa@417: * along with this program. If not, see .
msousa@417: *
msousa@417: *
msousa@417: * This code is made available on the understanding that it will not be
msousa@417: * used in safety-critical situations without a full and competent review.
msousa@417: */
msousa@417:
msousa@417: #ifndef _HELPER_FUNCTIONS_HH_
msousa@417: #define _HELPER_FUNCTIONS_HH_
msousa@417:
msousa@417: #include "../absyntax/visitor.hh"
msousa@417: #include
msousa@417:
msousa@434:
msousa@434:
msousa@434:
msousa@438:
msousa@438: typedef struct {
msousa@438: symbol_c *function_name;
msousa@438: symbol_c *nonformal_operand_list;
msousa@438: symbol_c * formal_operand_list;
msousa@438:
msousa@441: enum {POU_FB, POU_function} POU_type;
msousa@438: //symbol_c &*datatype;
msousa@438: //std::vector &candidate_datatypes;
msousa@438: std::vector &candidate_functions;
msousa@438: symbol_c *&called_function_declaration;
msousa@438: int &extensible_param_count;
msousa@438: } generic_function_call_t;
msousa@438:
msousa@438:
msousa@438:
msousa@434:
msousa@434:
msousa@434:
msousa@434:
msousa@417:
msousa@417: /* Widening Primitive Conversion */
msousa@417: struct widen_entry {
msousa@417: symbol_c *left;
msousa@417: symbol_c *right;
msousa@417: symbol_c *result;
conti@458: enum {ok, deprecated} status;
msousa@417: };
msousa@417: /*
msousa@417: * 2.5.1.5.6 Functions of time data types
msousa@417: * Table 30 - page 64
msousa@417: */
msousa@417: extern const struct widen_entry widen_ADD_table[];
msousa@417: extern const struct widen_entry widen_SUB_table[];
msousa@417: extern const struct widen_entry widen_MUL_table[];
msousa@417: extern const struct widen_entry widen_DIV_table[];
msousa@480: extern const struct widen_entry widen_MOD_table[];
msousa@490: extern const struct widen_entry widen_EXPT_table[];
msousa@481: extern const struct widen_entry widen_AND_table[];
msousa@481: extern const struct widen_entry widen_OR_table[];
msousa@481: extern const struct widen_entry widen_XOR_table[];
msousa@484: extern const struct widen_entry widen_CMP_table[];
msousa@417:
msousa@425: /* Search for a datatype inside a candidate_datatypes list.
msousa@425: * Returns: position of datatype in the list, or -1 if not found.
msousa@425: */
msousa@606: int search_in_candidate_datatype_list(symbol_c *datatype, const std::vector &candidate_datatypes);
msousa@425:
conti@603: /* Remove a datatype inside a candidate_datatypes list.
conti@603: * Returns: If successful it returns true, false otherwise.
conti@603: */
conti@603: bool remove_from_candidate_datatype_list(symbol_c *datatype, std::vector &candidate_datatypes);
conti@603:
msousa@457: /* Intersect two candidate_datatype_lists.
msousa@457: * Remove from list1 (origin, dest.) all elements that are not found in list2 (with).
msousa@457: * In essence, list1 will contain the result of the intersection of list1 with list2.
msousa@457: * In other words, modify list1 so it only contains the elelements that are simultaneously in list1 and list2!
msousa@457: */
msousa@457: void intersect_candidate_datatype_list(symbol_c *list1 /*origin, dest.*/, symbol_c *list2 /*with*/);
msousa@457:
msousa@459: /* intersect the candidate_datatype lists of all prev_il_intructions, and set the local candidate_datatype list to the result! */
msousa@459: void intersect_prev_candidate_datatype_lists(il_instruction_c *symbol);
msousa@459:
msousa@459:
msousa@443:
msousa@417:
msousa@425:
msousa@417: #endif /* _HELPER_FUNCTIONS_HH_ */