author | greg |
Wed, 28 Oct 2009 13:50:56 +0100 | |
changeset 213 | f386d870e8e4 |
parent 202 | da1a8186f86f |
child 265 | 4d222f46f8cc |
permissions | -rw-r--r-- |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
1 |
/* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
2 |
* (c) 2009 Mario de Sousa |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
3 |
* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
4 |
* Offered to the public under the terms of the GNU General Public License |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
6 |
* License, or (at your option) any later version. |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
7 |
* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
8 |
* This program is distributed in the hope that it will be useful, but |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
11 |
* Public License for more details. |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
12 |
* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
13 |
* This code is made available on the understanding that it will not be |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
14 |
* used in safety-critical situations without a full and competent review. |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
15 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
16 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
17 |
/* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
18 |
* An IEC 61131-3 IL and ST compiler. |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
19 |
* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
20 |
* Based on the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
22 |
* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
23 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
24 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
25 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
26 |
/* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
27 |
* Iterate through all declared functions and Function Blocks, |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
28 |
* and, for each function/FB, add a declaration of the EN and ENO |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
29 |
* parameters, if they have not already been explicitly declared. |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
30 |
* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
31 |
* EN and ENO parameters declared explicitly (by the user in the source code) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
32 |
* and implicitly (by the comnpiler, i.e. by this visitor class) may be |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
33 |
* distinguished later on by the 'method' flag in the en_param_declaration_c |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
34 |
* and eno_param_declaration_c objects. |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
35 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
36 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
37 |
#include "../absyntax/visitor.hh" |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
38 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
39 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
40 |
class add_en_eno_param_decl_c : public null_visitor_c { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
41 |
public: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
42 |
static symbol_c *add_to(symbol_c *tree_root); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
43 |
~add_en_eno_param_decl_c(void); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
44 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
45 |
private: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
46 |
/* this class is a singleton. So we need a pointer to the single instance... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
47 |
static add_en_eno_param_decl_c *singleton; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
48 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
49 |
/* flags to remember whether the EN and/or ENO parameters have already |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
50 |
* been explicitly declared by the user in the IEC 61131-3 source code we are parsing... |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
51 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
52 |
bool en_declared; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
53 |
bool eno_declared; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
54 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
55 |
private: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
56 |
void* iterate_list(list_c *list); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
57 |
input_declarations_c *build_en_param (void); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
58 |
output_declarations_c *build_eno_param(void); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
59 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
60 |
private: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
61 |
/***************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
62 |
/* B 0 - Programming Model */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
63 |
/***************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
64 |
void *visit(library_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
65 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
66 |
/***********************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
67 |
/* B 1.5.1 - Functions */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
68 |
/***********************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
69 |
void *visit(function_declaration_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
70 |
/* intermediate helper symbol for function_declaration */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
71 |
void *visit(var_declarations_list_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
72 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
73 |
/******************************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
74 |
/* B 1.4.3 - Declaration & Initialisation */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
75 |
/******************************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
76 |
void *visit(input_declarations_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
77 |
void *visit(input_declaration_list_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
78 |
void *visit(en_param_declaration_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
79 |
void *visit(eno_param_declaration_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
80 |
void *visit(output_declarations_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
81 |
void *visit(var_init_decl_list_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
82 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
83 |
/*****************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
84 |
/* B 1.5.2 - Function Blocks */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
85 |
/*****************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
86 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
87 |
void *visit(function_block_declaration_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
88 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
89 |
}; // function_param_iterator_c |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
90 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
91 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
92 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
93 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
94 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
95 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff
changeset
|
96 |