absyntax_utils/decompose_var_instance_name.hh
author Mario de Sousa <msousa@fe.up.pt>
Mon, 04 Apr 2011 15:26:13 +0100
changeset 276 1679f514f38a
parent 265 4d222f46f8cc
child 279 c0453b7f99df
permissions -rwxr-xr-x
Updating origin and license info of library fuctions.
Conclude missing counter FBs.
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
     1
/*
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
     3
 *
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
     4
 *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
     5
 *
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
     6
 *  This program is free software: you can redistribute it and/or modify
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
     7
 *  it under the terms of the GNU General Public License as published by
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
     8
 *  the Free Software Foundation, either version 3 of the License, or
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
     9
 *  (at your option) any later version.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
    10
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
    11
 *  This program is distributed in the hope that it will be useful,
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
    12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
    13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
    14
 *  GNU General Public License for more details.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
    15
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
    16
 *  You should have received a copy of the GNU General Public License
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
    17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
    18
 *
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    19
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    20
 * This code is made available on the understanding that it will not be
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    21
 * used in safety-critical situations without a full and competent review.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    22
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    23
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    24
/*
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 238
diff changeset
    25
 * An IEC 61131-3 compiler.
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    26
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    27
 * Based on the
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    28
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    29
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    30
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    31
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    32
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    33
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    34
/* Decomposes a variable instance name into its constituents,
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    35
 * example:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    36
 *    window.points[1].coordinate.x
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    37
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    38
 *  will succesfully return
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    39
 *        - window
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    40
 *        - points
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    41
 *        - coordinate
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    42
 *        - x
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    43
 * on succesive calls to decompose_var_instance_name_c::next_part()
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    44
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    45
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    46
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    47
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    48
#include "../absyntax/visitor.hh"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    49
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    50
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    51
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    52
class decompose_var_instance_name_c: null_visitor_c {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    53
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    54
  private:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    55
    symbol_c *variable_name;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    56
    symbol_c *next_variable_name;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    57
    symbol_c *current_recursive_variable_name;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    58
    symbol_c *previously_returned_variable_name;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    59
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    60
  public:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    61
    decompose_var_instance_name_c(symbol_c *variable_instance_name);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    62
238
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 202
diff changeset
    63
    symbol_c *next_part(bool increment = true);
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    64
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    65
  private:
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 181
diff changeset
    66
  /*************************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 181
diff changeset
    67
  /* B.1 - Common elements */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 181
diff changeset
    68
  /*************************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 181
diff changeset
    69
  /*******************************************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 181
diff changeset
    70
  /* B 1.1 - Letters, digits and identifiers */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 181
diff changeset
    71
  /*******************************************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 181
diff changeset
    72
    void *visit(identifier_c *symbol);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 181
diff changeset
    73
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    74
  /*********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    75
  /* B 1.4 - Variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    76
  /*********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    77
    void *visit(symbolic_variable_c *symbol);
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 181
diff changeset
    78
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    79
  /********************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    80
  /* B.1.4.1   Directly Represented Variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    81
  /********************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    82
    void *visit(direct_variable_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    83
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    84
  /*************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    85
  /* B.1.4.2   Multi-element Variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    86
  /*************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    87
  /*  subscripted_variable '[' subscript_list ']' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    88
  // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    89
    void *visit(array_variable_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    90
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    91
  /*  record_variable '.' field_selector */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    92
  /*  WARNING: input and/or output variables of function blocks
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    93
   *           may be accessed as fields of a tructured variable!
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    94
   *           Code handling a structured_variable_c must take
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    95
   *           this into account!
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    96
   */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    97
  //SYM_REF2(structured_variable_c, record_variable, field_selector)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    98
    void *visit(structured_variable_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    99
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   100
}; // decompose_var_instance_name_c
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   101
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   102
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   103
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   104