msousa@460: /* msousa@460: * matiec - a compiler for the programming languages defined in IEC 61131-3 msousa@460: * msousa@460: * Copyright (C) 2012 Mario de Sousa (msousa@fe.up.pt) msousa@460: * msousa@460: * This program is free software: you can redistribute it and/or modify msousa@460: * it under the terms of the GNU General Public License as published by msousa@460: * the Free Software Foundation, either version 3 of the License, or msousa@460: * (at your option) any later version. msousa@460: * msousa@460: * This program is distributed in the hope that it will be useful, msousa@460: * but WITHOUT ANY WARRANTY; without even the implied warranty of msousa@460: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the msousa@460: * GNU General Public License for more details. msousa@460: * msousa@460: * You should have received a copy of the GNU General Public License msousa@460: * along with this program. If not, see . msousa@460: * msousa@460: * msousa@460: * This code is made available on the understanding that it will not be msousa@460: * used in safety-critical situations without a full and competent review. msousa@460: */ msousa@460: msousa@460: /* msousa@460: * An IEC 61131-3 compiler. msousa@460: * msousa@460: * Based on the msousa@460: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) msousa@460: * msousa@460: */ msousa@460: msousa@460: msousa@460: /* msousa@460: * Search for a specific label in an IL list. msousa@460: * msousa@460: * when instantiated, must be given a pointer to one of the following msousa@460: * - function_declaration_c msousa@460: * - function_block_declaration_c msousa@460: * - program_declaration_c msousa@460: * - instruction_list_c msousa@460: * msousa@460: * which is where all calls to search for a specific label will look for said label. msousa@460: */ msousa@460: msousa@460: msousa@460: msousa@460: #include "absyntax_utils.hh" msousa@460: msousa@460: msousa@460: msousa@460: /* set to 1 to see debug info during execution */ msousa@460: static int debug = 0; msousa@460: msousa@460: search_il_label_c::search_il_label_c(symbol_c *search_scope) { msousa@460: this->search_scope = search_scope; msousa@460: this->search_label = NULL; msousa@460: } msousa@460: msousa@460: search_il_label_c::~search_il_label_c(void) { msousa@460: } msousa@460: msousa@460: msousa@460: il_instruction_c *search_il_label_c::find_label(const char *label) { msousa@460: return find_label(new identifier_c(label)); msousa@460: } msousa@460: msousa@460: msousa@460: il_instruction_c *search_il_label_c::find_label(symbol_c *label) { msousa@460: search_label = label; msousa@460: il_instruction_c *res = (il_instruction_c *)search_scope->accept(*this); msousa@460: search_label = NULL; msousa@460: return res; msousa@460: } msousa@460: msousa@460: msousa@460: /****************************************/ msousa@460: /* B.2 - Language IL (Instruction List) */ msousa@460: /****************************************/ msousa@460: /***********************************/ msousa@460: /* B 2.1 Instructions and Operands */ msousa@460: /***********************************/ msousa@460: msousa@460: /* | label ':' [il_incomplete_instruction] eol_list */ msousa@460: // SYM_REF2(il_instruction_c, label, il_instruction) msousa@460: // void *visit(instruction_list_c *symbol); msousa@460: void *search_il_label_c::visit(il_instruction_c *symbol) { msousa@460: // printf("search_il_label_c::visit(il_instruction_c *symbol): searching for %s\n", ((identifier_c *)search_label)->value); msousa@460: if (NULL != symbol->label) msousa@460: if (compare_identifiers(search_label, symbol->label) == 0) msousa@460: return symbol; msousa@460: msousa@460: return NULL; msousa@460: } msousa@460: msousa@460: msousa@460: msousa@460: