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 |
#include "absyntax_utils.hh"
|
|
26 |
|
|
27 |
|
|
28 |
/* Returns the function block type declaration
|
|
29 |
* of a specific function block instance.
|
|
30 |
*/
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
/* Returns the type name of a specific function block
|
|
35 |
* instance. This class will search the variable
|
|
36 |
* declarations inside the scope given to it
|
|
37 |
* searching for the declaration of the function
|
|
38 |
* block instance.
|
|
39 |
*
|
|
40 |
* The class constructor must be given the search scope
|
|
41 |
* (function, function block or program within which
|
|
42 |
* the function block instance was declared).
|
|
43 |
*
|
|
44 |
* This class will search the tree from the root given to the
|
|
45 |
* constructor. Another option would be to build a symbol table,
|
|
46 |
* and search that instead. Building the symbol table would be done
|
|
47 |
* while visiting the variable declaration objects in the parse
|
|
48 |
* tree. Unfortuantely, generate_c_c does not visit these
|
|
49 |
* objects, delegating it to another class. This means that
|
|
50 |
* we would need another specialised class just to build the
|
|
51 |
* symbol table. We might just as well have a specialised class
|
|
52 |
* that searches the tree itself for the relevant info. This
|
|
53 |
* class is exactly that...!
|
|
54 |
*/
|
|
55 |
search_fb_instance_decl_c::search_fb_instance_decl_c(symbol_c *search_scope) {
|
|
56 |
this->search_scope = search_scope;
|
|
57 |
this->current_fb_type_name = NULL;
|
|
58 |
}
|
|
59 |
|
|
60 |
symbol_c *search_fb_instance_decl_c::get_type_name(symbol_c *fb_instance_name) {
|
|
61 |
this->search_name = fb_instance_name;
|
|
62 |
return (symbol_c *)search_scope->accept(*this);
|
|
63 |
}
|
|
64 |
|
|
65 |
/***************************/
|
|
66 |
/* B 0 - Programming Model */
|
|
67 |
/***************************/
|
|
68 |
void *search_fb_instance_decl_c::visit(library_c *symbol) {
|
|
69 |
/* we do not want to search multiple declaration scopes,
|
|
70 |
* so we do not visit all the functions, fucntion blocks, etc...
|
|
71 |
*/
|
|
72 |
return NULL;
|
|
73 |
}
|
|
74 |
|
|
75 |
/******************************************/
|
|
76 |
/* B 1.4.3 - Declaration & Initialisation */
|
|
77 |
/******************************************/
|
|
78 |
|
|
79 |
/* name_list ':' function_block_type_name ASSIGN structure_initialization */
|
|
80 |
/* structure_initialization -> may be NULL ! */
|
|
81 |
void *search_fb_instance_decl_c::visit(fb_name_decl_c *symbol) {
|
|
82 |
current_fb_type_name = symbol->function_block_type_name;
|
|
83 |
return symbol->fb_name_list->accept(*this);
|
|
84 |
}
|
|
85 |
|
|
86 |
/* name_list ',' fb_name */
|
|
87 |
void *search_fb_instance_decl_c::visit(fb_name_list_c *symbol) {
|
|
88 |
list_c *list = symbol;
|
|
89 |
for(int i = 0; i < list->n; i++) {
|
|
90 |
if (compare_identifiers(list->elements[i], search_name) == 0)
|
|
91 |
/* by now, current_fb_declaration should be != NULL */
|
|
92 |
return current_fb_type_name;
|
|
93 |
}
|
|
94 |
return NULL;
|
|
95 |
}
|
|
96 |
|
|
97 |
/**************************************/
|
|
98 |
/* B.1.5 - Program organization units */
|
|
99 |
/**************************************/
|
|
100 |
/***********************/
|
|
101 |
/* B 1.5.1 - Functions */
|
|
102 |
/***********************/
|
|
103 |
void *search_fb_instance_decl_c::visit(function_declaration_c *symbol) {
|
|
104 |
/* no need to search through all the body, so we only
|
|
105 |
* visit the variable declarations...!
|
|
106 |
*/
|
|
107 |
return symbol->var_declarations_list->accept(*this);
|
|
108 |
}
|
|
109 |
|
|
110 |
/*****************************/
|
|
111 |
/* B 1.5.2 - Function Blocks */
|
|
112 |
/*****************************/
|
|
113 |
void *search_fb_instance_decl_c::visit(function_block_declaration_c *symbol) {
|
|
114 |
/* no need to search through all the body, so we only
|
|
115 |
* visit the variable declarations...!
|
|
116 |
*/
|
|
117 |
return symbol->var_declarations->accept(*this);
|
|
118 |
}
|
|
119 |
|
|
120 |
/**********************/
|
|
121 |
/* B 1.5.3 - Programs */
|
|
122 |
/**********************/
|
|
123 |
void *search_fb_instance_decl_c::visit(program_declaration_c *symbol) {
|
|
124 |
/* no need to search through all the body, so we only
|
|
125 |
* visit the variable declarations...!
|
|
126 |
*/
|
|
127 |
return symbol->var_declarations->accept(*this);
|
|
128 |
}
|