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 |
|
|
26 |
|
|
27 |
/* Returns the function block type declaration
|
|
28 |
* of a specific function block instance.
|
|
29 |
*/
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
/* Returns the type name of a specific function block
|
|
34 |
* instance. This class will search the variable
|
|
35 |
* declarations inside the scope given to it
|
|
36 |
* searching for the declaration of the function
|
|
37 |
* block instance.
|
|
38 |
*
|
|
39 |
* The class constructor must be given the search scope
|
|
40 |
* (function, function block or program within which
|
|
41 |
* the function block instance was declared).
|
|
42 |
*
|
|
43 |
* This class will search the tree from the root given to the
|
|
44 |
* constructor. Another option would be to build a symbol table,
|
|
45 |
* and search that instead. Building the symbol table would be done
|
|
46 |
* while visiting the variable declaration objects in the parse
|
|
47 |
* tree. Unfortuantely, generate_c_c does not visit these
|
|
48 |
* objects, delegating it to another class. This means that
|
|
49 |
* we would need another specialised class just to build the
|
|
50 |
* symbol table. We might just as well have a specialised class
|
|
51 |
* that searches the tree itself for the relevant info. This
|
|
52 |
* class is exactly that...!
|
|
53 |
*/
|
|
54 |
|
|
55 |
|
|
56 |
class search_fb_instance_decl_c: public search_visitor_c {
|
|
57 |
|
|
58 |
private:
|
|
59 |
symbol_c *search_scope;
|
|
60 |
|
|
61 |
symbol_c *search_name;
|
|
62 |
symbol_c *current_fb_type_name;
|
|
63 |
|
|
64 |
public:
|
|
65 |
search_fb_instance_decl_c(symbol_c *search_scope);
|
|
66 |
symbol_c *get_type_name(symbol_c *fb_instance_name);
|
|
67 |
|
|
68 |
public:
|
|
69 |
/***************************/
|
|
70 |
/* B 0 - Programming Model */
|
|
71 |
/***************************/
|
|
72 |
void *visit(library_c *symbol);
|
|
73 |
|
|
74 |
/******************************************/
|
|
75 |
/* B 1.4.3 - Declaration & Initialisation */
|
|
76 |
/******************************************/
|
|
77 |
|
|
78 |
/* name_list ':' function_block_type_name ASSIGN structure_initialization */
|
|
79 |
/* structure_initialization -> may be NULL ! */
|
|
80 |
void *visit(fb_name_decl_c *symbol);
|
|
81 |
/* name_list ',' fb_name */
|
|
82 |
void *visit(fb_name_list_c *symbol);
|
|
83 |
|
|
84 |
/**************************************/
|
|
85 |
/* B.1.5 - Program organization units */
|
|
86 |
/**************************************/
|
|
87 |
/***********************/
|
|
88 |
/* B 1.5.1 - Functions */
|
|
89 |
/***********************/
|
|
90 |
void *visit(function_declaration_c *symbol);
|
|
91 |
|
|
92 |
/*****************************/
|
|
93 |
/* B 1.5.2 - Function Blocks */
|
|
94 |
/*****************************/
|
|
95 |
void *visit(function_block_declaration_c *symbol);
|
|
96 |
|
|
97 |
/**********************/
|
|
98 |
/* B 1.5.3 - Programs */
|
|
99 |
/**********************/
|
|
100 |
void *visit(program_declaration_c *symbol);
|
|
101 |
}; // search_fb_instance_decl_c
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|