author | laurent |
Tue, 08 Dec 2009 16:26:06 +0100 | |
changeset 229 | ca7bc1324540 |
parent 202 | da1a8186f86f |
child 265 | 4d222f46f8cc |
permissions | -rw-r--r-- |
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); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
49 |
bool is_literal_integer_type(symbol_c *type_symbol); |
181 | 50 |
bool is_integer_type(symbol_c *type_symbol); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
51 |
bool is_literal_real_type(symbol_c *type_symbol); |
181 | 52 |
bool is_real_type(symbol_c *type_symbol); |
53 |
bool is_num_type(symbol_c *type_symbol); |
|
54 |
bool is_nbinary_type(symbol_c *type_symbol); |
|
55 |
bool is_binary_type(symbol_c *type_symbol); |
|
56 |
||
57 |
bool is_same_type(symbol_c *first_type, symbol_c *second_type); |
|
58 |
symbol_c* common_type(symbol_c *first_type, symbol_c *second_type); |
|
59 |
||
60 |
/* |
|
61 |
#include "search_type_code.c" |
|
62 |
*/ |
|
63 |
void *compute_standard_function_default(function_invocation_c *st_symbol, il_formal_funct_call_c *il_symbol); |
|
64 |
void *compute_standard_function_il(il_function_call_c *symbol, symbol_c *param_data_type); |
|
65 |
||
66 |
||
67 |
||
68 |
/*static bool_type_name_c bool_type_name;*/ |
|
69 |
||
70 |
/* A helper function... */ |
|
71 |
void *compute_boolean_expression(symbol_c *left_type, symbol_c *right_type); |
|
72 |
||
73 |
/* A helper function... */ |
|
74 |
void *compute_numeric_expression(symbol_c *left_type, symbol_c *right_type); |
|
75 |
||
76 |
/* a helper function... */ |
|
77 |
symbol_c *base_type(symbol_c *symbol); |
|
78 |
||
79 |
/*********************/ |
|
80 |
/* B 1.4 - Variables */ |
|
81 |
/*********************/ |
|
82 |
||
83 |
void *visit(symbolic_variable_c *symbol); |
|
84 |
||
85 |
/********************************************/ |
|
86 |
/* B 1.4.1 - Directly Represented Variables */ |
|
87 |
/********************************************/ |
|
88 |
void *visit(direct_variable_c *symbol); |
|
89 |
||
90 |
/*************************************/ |
|
91 |
/* B 1.4.2 - Multi-element variables */ |
|
92 |
/*************************************/ |
|
93 |
||
94 |
void *visit(array_variable_c *symbol); |
|
95 |
void *visit(structured_variable_c *symbol); |
|
96 |
||
97 |
/***************************************/ |
|
98 |
/* B.3 - Language ST (Structured Text) */ |
|
99 |
/***************************************/ |
|
100 |
/***********************/ |
|
101 |
/* B 3.1 - Expressions */ |
|
102 |
/***********************/ |
|
103 |
void *visit(or_expression_c *symbol); |
|
104 |
void *visit(xor_expression_c *symbol); |
|
105 |
void *visit(and_expression_c *symbol); |
|
106 |
void *visit(equ_expression_c *symbol); |
|
107 |
void *visit(notequ_expression_c *symbol); |
|
108 |
void *visit(lt_expression_c *symbol); |
|
109 |
void *visit(gt_expression_c *symbol); |
|
110 |
void *visit(le_expression_c *symbol); |
|
111 |
void *visit(ge_expression_c *symbol); |
|
112 |
||
113 |
void *visit(add_expression_c *symbol); |
|
114 |
void *visit(sub_expression_c *symbol); |
|
115 |
void *visit(mul_expression_c *symbol); |
|
116 |
void *visit(div_expression_c *symbol); |
|
117 |
void *visit(mod_expression_c *symbol); |
|
118 |
void *visit(power_expression_c *symbol); |
|
119 |
void *visit(neg_expression_c *symbol); |
|
120 |
void *visit(not_expression_c *symbol); |
|
121 |
void *visit(function_invocation_c *symbol); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
122 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
123 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
124 |
static integer_c integer; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
125 |
|
181 | 126 |
}; // search_expression_type_c |
127 |
||
128 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
129 |