absyntax_utils/get_var_name.cc
author mjsousa
Sun, 01 Jun 2014 08:59:02 +0100
changeset 898 343989fb05fb
parent 889 5f380b99e95e
permissions -rw-r--r--
Change the name of the variable with the step state to stepname.X (in the generated VARIABLES.csv file)
511
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     1
/*
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     3
 *
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     4
 *  Copyright (C) 2012  Mario de Sousa (msousa@fe.up.pt)
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     5
 *
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     6
 *  This program is free software: you can redistribute it and/or modify
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     7
 *  it under the terms of the GNU General Public License as published by
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     8
 *  the Free Software Foundation, either version 3 of the License, or
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     9
 *  (at your option) any later version.
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    10
 *
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    11
 *  This program is distributed in the hope that it will be useful,
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    14
 *  GNU General Public License for more details.
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    15
 *
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    16
 *  You should have received a copy of the GNU General Public License
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    18
 *
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    19
 *
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    20
 * This code is made available on the understanding that it will not be
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    21
 * used in safety-critical situations without a full and competent review.
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    22
 */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    23
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    24
/*
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    25
 * An IEC 61131-3 compiler.
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    26
 *
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    27
 * Based on the
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    28
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    29
 *
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    30
 */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    31
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    32
/*
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    33
 *  A small helper visitor class, that will   
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    34
 *  return the name (tokn_c *) of a variable, as it will
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    35
 *  appear in the variable declaration.
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    36
 */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    37
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    38
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    39
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    40
#include "absyntax_utils.hh"
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    41
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    42
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    43
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    44
   
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    45
    
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    46
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    47
get_var_name_c *get_var_name_c::singleton_instance_ = NULL;
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    48
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    49
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    50
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    51
/*  For ex.:
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    52
 *       VAR
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    53
 *          A : int;
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    54
 *          B : ARRAY [1..9] of int;
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    55
 *          C : some_struct_t;
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    56
 *       END_VAR
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    57
 *
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    58
 *          A    := 56;
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    59
 *          B[8] := 99;
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    60
 *          C.e  := 77;
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    61
 *
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    62
 *       Calling this method with symbolic_variable_c instance referencing 'A' in
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    63
 *       the line 'A := 56', will return the string "A".
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    64
 *
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    65
 *       Calling this method with array_variable_c instance referencing 'B[8]' in
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    66
 *       the line 'B[8] := 99', will return the string "B".
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    67
 *
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    68
 *       Calling this method with array_variable_c instance referencing 'C.e' in
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    69
 *       the line 'C.e := 77', will return the string "C".
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    70
 */
511
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    71
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    72
token_c *get_var_name_c::get_name(symbol_c *symbol) {
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    73
  if (NULL == singleton_instance_) singleton_instance_ = new get_var_name_c(); 
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    74
  if (NULL == singleton_instance_) ERROR; 
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    75
  
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    76
  return (token_c *)(symbol->accept(*singleton_instance_));
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    77
}
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    78
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    79
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    80
/*  Return the last field of a structured variable...
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    81
 * 
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    82
 *          A    := 56;   --> returns A
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    83
 *          B[8] := 99;   --> returns B
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    84
 *          C.e  := 77;   --> returns e   !!!
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    85
 */
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    86
symbol_c *get_var_name_c::get_last_field(symbol_c *symbol) {
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    87
  if (NULL == singleton_instance_) singleton_instance_ = new get_var_name_c(); 
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    88
  if (NULL == singleton_instance_) ERROR; 
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    89
  
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    90
  singleton_instance_->last_field = NULL;
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    91
  symbol_c *res = (symbol_c*)(symbol->accept(*singleton_instance_));
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    92
  return (NULL != singleton_instance_->last_field)? singleton_instance_->last_field : res;
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    93
}
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    94
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    95
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    96
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
    97
511
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    98
/*************************/
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    99
/* B.1 - Common elements */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   100
/*************************/
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   101
/*******************************************/
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   102
/* B 1.1 - Letters, digits and identifiers */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   103
/*******************************************/
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   104
// SYM_TOKEN(identifier_c)
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   105
void *get_var_name_c::visit(identifier_c *symbol) {return (void *)symbol;}
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   106
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   107
/*********************/
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   108
/* B 1.4 - Variables */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   109
/*********************/
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   110
// SYM_REF2(symbolic_variable_c, var_name, unused)
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   111
void *get_var_name_c::visit(symbolic_variable_c *symbol) {return symbol->var_name->accept(*this);}
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   112
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   113
/********************************************/
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   114
/* B.1.4.1   Directly Represented Variables */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   115
/********************************************/
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   116
// SYM_TOKEN(direct_variable_c)
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   117
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   118
/*************************************/
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   119
/* B.1.4.2   Multi-element Variables */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   120
/*************************************/
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   121
/*  subscripted_variable '[' subscript_list ']' */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   122
// SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   123
void *get_var_name_c::visit(array_variable_c *symbol) {return symbol->subscripted_variable->accept(*this);}
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   124
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   125
/* subscript_list ',' subscript */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   126
// SYM_LIST(subscript_list_c)
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   127
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   128
/*  record_variable '.' field_selector */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   129
/*  WARNING: input and/or output variables of function blocks
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   130
 *           may be accessed as fields of a tructured variable!
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   131
 *           Code handling a structured_variable_c must take
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   132
 *           this into account!
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   133
 */
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   134
// SYM_REF2(structured_variable_c, record_variable, field_selector)
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
   135
void *get_var_name_c::visit(structured_variable_c *symbol) {
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
   136
  void *res = symbol->record_variable->accept(*this);
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
   137
  last_field = symbol->field_selector;
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
   138
  return res;
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 511
diff changeset
   139
}
511
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   140
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   141
b22ae67d8003 Moving get_var_name_c into its own file.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   142