460
|
1 |
/*
|
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3
|
|
3 |
*
|
|
4 |
* Copyright (C) 2012 Mario de Sousa (msousa@fe.up.pt)
|
|
5 |
*
|
|
6 |
* This program is free software: you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18 |
*
|
|
19 |
*
|
|
20 |
* This code is made available on the understanding that it will not be
|
|
21 |
* used in safety-critical situations without a full and competent review.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* An IEC 61131-3 compiler.
|
|
26 |
*
|
|
27 |
* Based on the
|
|
28 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
|
|
29 |
*
|
|
30 |
*/
|
|
31 |
|
|
32 |
|
|
33 |
/*
|
|
34 |
* Search for a specific label in an IL list.
|
|
35 |
*
|
|
36 |
* when instantiated, must be given a pointer to one of the following
|
|
37 |
* - function_declaration_c
|
|
38 |
* - function_block_declaration_c
|
|
39 |
* - program_declaration_c
|
|
40 |
* - instruction_list_c
|
|
41 |
*
|
|
42 |
* which is where all calls to search for a specific label will look for said label.
|
|
43 |
*/
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
#include "absyntax_utils.hh"
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
/* set to 1 to see debug info during execution */
|
|
52 |
static int debug = 0;
|
|
53 |
|
|
54 |
search_il_label_c::search_il_label_c(symbol_c *search_scope) {
|
|
55 |
this->search_scope = search_scope;
|
|
56 |
this->search_label = NULL;
|
|
57 |
}
|
|
58 |
|
|
59 |
search_il_label_c::~search_il_label_c(void) {
|
|
60 |
}
|
|
61 |
|
|
62 |
|
|
63 |
il_instruction_c *search_il_label_c::find_label(const char *label) {
|
|
64 |
return find_label(new identifier_c(label));
|
|
65 |
}
|
|
66 |
|
|
67 |
|
|
68 |
il_instruction_c *search_il_label_c::find_label(symbol_c *label) {
|
|
69 |
search_label = label;
|
|
70 |
il_instruction_c *res = (il_instruction_c *)search_scope->accept(*this);
|
|
71 |
search_label = NULL;
|
|
72 |
return res;
|
|
73 |
}
|
|
74 |
|
|
75 |
|
|
76 |
/****************************************/
|
|
77 |
/* B.2 - Language IL (Instruction List) */
|
|
78 |
/****************************************/
|
|
79 |
/***********************************/
|
|
80 |
/* B 2.1 Instructions and Operands */
|
|
81 |
/***********************************/
|
|
82 |
|
|
83 |
/* | label ':' [il_incomplete_instruction] eol_list */
|
|
84 |
// SYM_REF2(il_instruction_c, label, il_instruction)
|
|
85 |
// void *visit(instruction_list_c *symbol);
|
|
86 |
void *search_il_label_c::visit(il_instruction_c *symbol) {
|
|
87 |
// printf("search_il_label_c::visit(il_instruction_c *symbol): searching for %s\n", ((identifier_c *)search_label)->value);
|
|
88 |
if (NULL != symbol->label)
|
|
89 |
if (compare_identifiers(search_label, symbol->label) == 0)
|
|
90 |
return symbol;
|
|
91 |
|
|
92 |
return NULL;
|
|
93 |
}
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|