|
1 /* |
|
2 * matiec - a compiler for the programming languages defined in IEC 61131-3 |
|
3 * |
|
4 * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt) |
|
5 * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it) |
|
6 * |
|
7 * |
|
8 * This program is free software: you can redistribute it and/or modify |
|
9 * it under the terms of the GNU General Public License as published by |
|
10 * the Free Software Foundation, either version 3 of the License, or |
|
11 * (at your option) any later version. |
|
12 * |
|
13 * This program is distributed in the hope that it will be useful, |
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 * GNU General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20 * |
|
21 * |
|
22 * This code is made available on the understanding that it will not be |
|
23 * used in safety-critical situations without a full and competent review. |
|
24 */ |
|
25 |
|
26 /* |
|
27 * An IEC 61131-3 compiler. |
|
28 * |
|
29 * Based on the |
|
30 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
31 * |
|
32 */ |
|
33 |
|
34 #include <vector> |
|
35 #include "../absyntax_utils/absyntax_utils.hh" |
|
36 #include "datatype_functions.hh" |
|
37 |
|
38 |
|
39 /* Expressions on the left hand side of assignment statements have aditional restrictions on their datatype. |
|
40 * For example, they cannot be literals, CONSTANT type variables, function invocations, etc... |
|
41 * This class wil do those checks. |
|
42 * |
|
43 * Note that assignment may also be done when passing variables to OUTPUT or IN_OUT function parameters,so we check those too. |
|
44 */ |
|
45 |
|
46 |
|
47 |
|
48 class lvalue_check_c: public iterator_visitor_c { |
|
49 |
|
50 private: |
|
51 search_varfb_instance_type_c *search_varfb_instance_type; |
|
52 search_var_instance_decl_c *search_var_instance_decl; |
|
53 search_base_type_c search_base_type; |
|
54 int error_count; |
|
55 int current_display_error_level; |
|
56 std::vector <token_c *> control_variables; |
|
57 symbol_c *current_il_operand; |
|
58 |
|
59 void verify_is_lvalue (symbol_c *lvalue); |
|
60 void check_assignment_to_controlvar(symbol_c *lvalue); |
|
61 void check_assignment_to_output (symbol_c *lvalue); |
|
62 void check_assignment_to_constant (symbol_c *lvalue); |
|
63 void check_assignment_to_expression(symbol_c *lvalue); |
|
64 void check_formal_call (symbol_c *f_call, symbol_c *f_decl); |
|
65 void check_nonformal_call(symbol_c *f_call, symbol_c *f_decl); |
|
66 |
|
67 |
|
68 public: |
|
69 lvalue_check_c(symbol_c *ignore); |
|
70 virtual ~lvalue_check_c(void); |
|
71 int get_error_count(); |
|
72 |
|
73 /**************************************/ |
|
74 /* B 1.5 - Program organisation units */ |
|
75 /**************************************/ |
|
76 /***********************/ |
|
77 /* B 1.5.1 - Functions */ |
|
78 /***********************/ |
|
79 void *visit(function_declaration_c *symbol); |
|
80 |
|
81 /*****************************/ |
|
82 /* B 1.5.2 - Function blocks */ |
|
83 /*****************************/ |
|
84 void *visit(function_block_declaration_c *symbol); |
|
85 |
|
86 /**********************/ |
|
87 /* B 1.5.3 - Programs */ |
|
88 /**********************/ |
|
89 void *visit(program_declaration_c *symbol); |
|
90 |
|
91 /****************************************/ |
|
92 /* B.2 - Language IL (Instruction List) */ |
|
93 /****************************************/ |
|
94 /***********************************/ |
|
95 /* B 2.1 Instructions and Operands */ |
|
96 /***********************************/ |
|
97 void *visit(il_instruction_c *symbol); |
|
98 void *visit(il_simple_operation_c *symbol); |
|
99 void *visit(il_function_call_c *symbol); |
|
100 void *visit(il_fb_call_c *symbol); |
|
101 void *visit(il_formal_funct_call_c *symbol); |
|
102 |
|
103 /*******************/ |
|
104 /* B 2.2 Operators */ |
|
105 /*******************/ |
|
106 void *visit(ST_operator_c *symbol); |
|
107 void *visit(STN_operator_c *symbol); |
|
108 void *visit(S_operator_c *symbol); |
|
109 void *visit(R_operator_c *symbol); |
|
110 |
|
111 /***************************************/ |
|
112 /* B.3 - Language ST (Structured Text) */ |
|
113 /***************************************/ |
|
114 /***********************/ |
|
115 /* B 3.1 - Expressions */ |
|
116 /***********************/ |
|
117 void *visit(function_invocation_c *symbol); |
|
118 |
|
119 /*********************************/ |
|
120 /* B 3.2.1 Assignment Statements */ |
|
121 /*********************************/ |
|
122 void *visit(assignment_statement_c *symbol); |
|
123 |
|
124 /*****************************************/ |
|
125 /* B 3.2.2 Subprogram Control Statements */ |
|
126 /*****************************************/ |
|
127 void *visit(fb_invocation_c *symbol); |
|
128 |
|
129 /********************************/ |
|
130 /* B 3.2.4 Iteration Statements */ |
|
131 /********************************/ |
|
132 void *visit(for_statement_c *symbol); |
|
133 |
|
134 }; /* lvalue_check_c */ |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |