181
|
1 |
/*
|
|
2 |
* (c) 2003 Mario de Sousa
|
|
3 |
*
|
|
4 |
* Offered to the public under the terms of the GNU General Public License
|
|
5 |
* as published by the Free Software Foundation; either version 2 of the
|
|
6 |
* License, or (at your option) any later version.
|
|
7 |
*
|
|
8 |
* This program is distributed in the hope that it will be useful, but
|
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
11 |
* Public License for more details.
|
|
12 |
*
|
|
13 |
* This code is made available on the understanding that it will not be
|
|
14 |
* used in safety-critical situations without a full and competent review.
|
|
15 |
*/
|
|
16 |
|
|
17 |
/*
|
|
18 |
* An IEC 61131-3 IL and ST compiler.
|
|
19 |
*
|
|
20 |
* Based on the
|
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
/* Determine the data type of an ST expression.
|
|
26 |
* A reference to the relevant type definition is returned.
|
|
27 |
*
|
|
28 |
* For example:
|
|
29 |
* 2 + 3 -> returns reference to a int_type_name_c object.
|
|
30 |
* 22.2 - 5 -> returns reference to a real_type_name_c object.
|
|
31 |
* etc...
|
|
32 |
*/
|
|
33 |
|
|
34 |
class search_expression_type_c: public search_constant_type_c {
|
|
35 |
|
|
36 |
private:
|
|
37 |
search_varfb_instance_type_c *search_varfb_instance_type;
|
|
38 |
search_base_type_c search_base_type;
|
|
39 |
|
|
40 |
|
|
41 |
public:
|
|
42 |
search_expression_type_c(symbol_c *search_scope);
|
|
43 |
virtual ~search_expression_type_c(void);
|
|
44 |
|
|
45 |
/* A helper function... */
|
|
46 |
bool is_bool_type(symbol_c *type_symbol);
|
|
47 |
bool is_time_type(symbol_c *type_symbol);
|
|
48 |
bool is_string_type(symbol_c *type_symbol);
|
|
49 |
bool is_integer_type(symbol_c *type_symbol);
|
|
50 |
bool is_real_type(symbol_c *type_symbol);
|
|
51 |
bool is_num_type(symbol_c *type_symbol);
|
|
52 |
bool is_nbinary_type(symbol_c *type_symbol);
|
|
53 |
bool is_binary_type(symbol_c *type_symbol);
|
|
54 |
|
|
55 |
bool is_same_type(symbol_c *first_type, symbol_c *second_type);
|
|
56 |
symbol_c* common_type(symbol_c *first_type, symbol_c *second_type);
|
|
57 |
|
|
58 |
/*
|
|
59 |
#include "search_type_code.c"
|
|
60 |
*/
|
|
61 |
void *compute_standard_function_default(function_invocation_c *st_symbol, il_formal_funct_call_c *il_symbol);
|
|
62 |
/*
|
|
63 |
void *compute_standard_function_default(function_invocation_c *st_symbol = NULL, il_formal_funct_call_c *il_symbol = NULL);
|
|
64 |
*/
|
|
65 |
void *compute_standard_function_il(il_function_call_c *symbol, symbol_c *param_data_type);
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
/*static bool_type_name_c bool_type_name;*/
|
|
70 |
|
|
71 |
/* A helper function... */
|
|
72 |
void *compute_boolean_expression(symbol_c *left_type, symbol_c *right_type);
|
|
73 |
|
|
74 |
/* A helper function... */
|
|
75 |
void *compute_numeric_expression(symbol_c *left_type, symbol_c *right_type);
|
|
76 |
|
|
77 |
/* a helper function... */
|
|
78 |
symbol_c *base_type(symbol_c *symbol);
|
|
79 |
|
|
80 |
/*********************/
|
|
81 |
/* B 1.4 - Variables */
|
|
82 |
/*********************/
|
|
83 |
|
|
84 |
void *visit(symbolic_variable_c *symbol);
|
|
85 |
|
|
86 |
/********************************************/
|
|
87 |
/* B 1.4.1 - Directly Represented Variables */
|
|
88 |
/********************************************/
|
|
89 |
void *visit(direct_variable_c *symbol);
|
|
90 |
|
|
91 |
/*************************************/
|
|
92 |
/* B 1.4.2 - Multi-element variables */
|
|
93 |
/*************************************/
|
|
94 |
|
|
95 |
void *visit(array_variable_c *symbol);
|
|
96 |
void *visit(structured_variable_c *symbol);
|
|
97 |
|
|
98 |
/***************************************/
|
|
99 |
/* B.3 - Language ST (Structured Text) */
|
|
100 |
/***************************************/
|
|
101 |
/***********************/
|
|
102 |
/* B 3.1 - Expressions */
|
|
103 |
/***********************/
|
|
104 |
void *visit(or_expression_c *symbol);
|
|
105 |
void *visit(xor_expression_c *symbol);
|
|
106 |
void *visit(and_expression_c *symbol);
|
|
107 |
void *visit(equ_expression_c *symbol);
|
|
108 |
void *visit(notequ_expression_c *symbol);
|
|
109 |
void *visit(lt_expression_c *symbol);
|
|
110 |
void *visit(gt_expression_c *symbol);
|
|
111 |
void *visit(le_expression_c *symbol);
|
|
112 |
void *visit(ge_expression_c *symbol);
|
|
113 |
|
|
114 |
void *visit(add_expression_c *symbol);
|
|
115 |
void *visit(sub_expression_c *symbol);
|
|
116 |
void *visit(mul_expression_c *symbol);
|
|
117 |
void *visit(div_expression_c *symbol);
|
|
118 |
void *visit(mod_expression_c *symbol);
|
|
119 |
void *visit(power_expression_c *symbol);
|
|
120 |
void *visit(neg_expression_c *symbol);
|
|
121 |
void *visit(not_expression_c *symbol);
|
|
122 |
void *visit(function_invocation_c *symbol);
|
|
123 |
}; // search_expression_type_c
|
|
124 |
|
|
125 |
/*bool_type_name_c search_expression_type_c::bool_type_name;*/
|
|
126 |
|