author | Mario de Sousa <msousa@fe.up.pt> |
Wed, 25 Apr 2012 16:56:25 +0100 | |
changeset 536 | 563b013ec670 |
parent 535 | 70140bd7fe67 |
child 553 | b654ca7a031a |
permissions | -rw-r--r-- |
508 | 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 |
* In this class we implemented all lvalue check. |
|
40 |
* With lvalue check we mean all semantic error about |
|
41 |
* assignment with wrong access |
|
42 |
*/ |
|
43 |
||
44 |
class lvalue_check_c: public iterator_visitor_c { |
|
45 |
||
46 |
private: |
|
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
47 |
search_varfb_instance_type_c *search_varfb_instance_type; |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
48 |
search_var_instance_decl_c *search_var_instance_decl; |
508 | 49 |
search_base_type_c search_base_type; |
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
50 |
int error_count; |
508 | 51 |
int current_display_error_level; |
512
f915ab676d7e
Fixing check for assingment to FOR control variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
510
diff
changeset
|
52 |
std::vector <token_c *> control_variables; |
528
6510ee2eaab9
Remove erroneous check for S1 and R1, and add missing declrataion.
Mario de Sousa <msousa@fe.up.pt>
parents:
527
diff
changeset
|
53 |
symbol_c *current_il_operand; |
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
54 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
55 |
void verify_is_lvalue (symbol_c *lvalue); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
56 |
void check_assignment_to_controlvar(symbol_c *lvalue); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
57 |
void check_assignment_to_output (symbol_c *lvalue); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
58 |
void check_assignment_to_constant (symbol_c *lvalue); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
59 |
void check_assignment_to_expression(symbol_c *lvalue); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
60 |
void check_formal_call (symbol_c *f_call, symbol_c *f_decl); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
61 |
void check_nonformal_call(symbol_c *f_call, symbol_c *f_decl); |
508 | 62 |
|
63 |
||
64 |
public: |
|
65 |
lvalue_check_c(symbol_c *ignore); |
|
66 |
virtual ~lvalue_check_c(void); |
|
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
67 |
int get_error_count(); |
508 | 68 |
|
69 |
/**************************************/ |
|
70 |
/* B 1.5 - Program organisation units */ |
|
71 |
/**************************************/ |
|
72 |
/***********************/ |
|
73 |
/* B 1.5.1 - Functions */ |
|
74 |
/***********************/ |
|
75 |
void *visit(function_declaration_c *symbol); |
|
76 |
||
77 |
/*****************************/ |
|
78 |
/* B 1.5.2 - Function blocks */ |
|
79 |
/*****************************/ |
|
80 |
void *visit(function_block_declaration_c *symbol); |
|
81 |
||
82 |
/**********************/ |
|
83 |
/* B 1.5.3 - Programs */ |
|
84 |
/**********************/ |
|
85 |
void *visit(program_declaration_c *symbol); |
|
86 |
||
527
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
87 |
/****************************************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
88 |
/* B.2 - Language IL (Instruction List) */ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
89 |
/****************************************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
90 |
/***********************************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
91 |
/* B 2.1 Instructions and Operands */ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
92 |
/***********************************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
93 |
void *visit(il_instruction_c *symbol); |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
94 |
void *visit(il_simple_operation_c *symbol); |
535
70140bd7fe67
Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
528
diff
changeset
|
95 |
void *visit(il_function_call_c *symbol); |
70140bd7fe67
Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
528
diff
changeset
|
96 |
void *visit(il_fb_call_c *symbol); |
70140bd7fe67
Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
528
diff
changeset
|
97 |
void *visit(il_formal_funct_call_c *symbol); |
527
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
98 |
|
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
99 |
/*******************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
100 |
/* B 2.2 Operators */ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
101 |
/*******************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
102 |
void *visit(ST_operator_c *symbol); |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
103 |
void *visit(STN_operator_c *symbol); |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
104 |
void *visit(S_operator_c *symbol); |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
105 |
void *visit(R_operator_c *symbol); |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
106 |
|
508 | 107 |
/***************************************/ |
108 |
/* B.3 - Language ST (Structured Text) */ |
|
109 |
/***************************************/ |
|
110 |
/***********************/ |
|
111 |
/* B 3.1 - Expressions */ |
|
112 |
/***********************/ |
|
113 |
void *visit(function_invocation_c *symbol); |
|
114 |
||
115 |
/*********************************/ |
|
116 |
/* B 3.2.1 Assignment Statements */ |
|
117 |
/*********************************/ |
|
118 |
void *visit(assignment_statement_c *symbol); |
|
119 |
||
526
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
512
diff
changeset
|
120 |
/*****************************************/ |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
512
diff
changeset
|
121 |
/* B 3.2.2 Subprogram Control Statements */ |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
512
diff
changeset
|
122 |
/*****************************************/ |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
512
diff
changeset
|
123 |
void *visit(fb_invocation_c *symbol); |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
512
diff
changeset
|
124 |
|
508 | 125 |
/********************************/ |
126 |
/* B 3.2.4 Iteration Statements */ |
|
127 |
/********************************/ |
|
128 |
void *visit(for_statement_c *symbol); |
|
129 |
||
130 |
}; /* lvalue_check_c */ |
|
131 |
||
132 |
||
133 |
||
134 |
||
135 |
||
136 |
||
137 |