|
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 * A small helper visitor class, that will |
|
34 * return the name (tokn_c *) of a variable, as it will |
|
35 * appear in the variable declaration. |
|
36 */ |
|
37 |
|
38 /* For ex.: |
|
39 * VAR |
|
40 * A : int; |
|
41 * B : ARRAY [1..9] of int; |
|
42 * C : some_struct_t; |
|
43 * END_VAR |
|
44 * |
|
45 * A := 56; |
|
46 * B[8] := 99; |
|
47 * C.e := 77; |
|
48 * |
|
49 * Calling this visitor class with symbolic_variable_c instance referencing 'A' in |
|
50 * the line 'A := 56', will return the string "A". |
|
51 * |
|
52 * Calling this visitor class with array_variable_c instance referencing 'B[8]' in |
|
53 * the line 'B[8] := 99', will return the string "B". |
|
54 * |
|
55 * Calling this visitor class with array_variable_c instance referencing 'C.e' in |
|
56 * the line 'C.e := 77', will return the string "C". |
|
57 */ |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 class get_var_name_c : public search_visitor_c { |
|
63 public: |
|
64 get_var_name_c(void) {}; |
|
65 ~get_var_name_c(void) {}; |
|
66 static token_c *get_name(symbol_c *symbol); |
|
67 |
|
68 private: |
|
69 static get_var_name_c *singleton_instance_; |
|
70 |
|
71 private: |
|
72 /*************************/ |
|
73 /* B.1 - Common elements */ |
|
74 /*************************/ |
|
75 /*******************************************/ |
|
76 /* B 1.1 - Letters, digits and identifiers */ |
|
77 /*******************************************/ |
|
78 // SYM_TOKEN(identifier_c) |
|
79 void *visit(identifier_c *symbol); |
|
80 |
|
81 /*********************/ |
|
82 /* B 1.4 - Variables */ |
|
83 /*********************/ |
|
84 // SYM_REF2(symbolic_variable_c, var_name, unused) |
|
85 void *visit(symbolic_variable_c *symbol); |
|
86 |
|
87 /********************************************/ |
|
88 /* B.1.4.1 Directly Represented Variables */ |
|
89 /********************************************/ |
|
90 // SYM_TOKEN(direct_variable_c) |
|
91 // void *visit(direct_variable_c *symbol); |
|
92 |
|
93 /*************************************/ |
|
94 /* B.1.4.2 Multi-element Variables */ |
|
95 /*************************************/ |
|
96 /* subscripted_variable '[' subscript_list ']' */ |
|
97 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
98 void *visit(array_variable_c *symbol); |
|
99 |
|
100 /* subscript_list ',' subscript */ |
|
101 // SYM_LIST(subscript_list_c) |
|
102 // void *visit(subscript_list_c *symbol); |
|
103 |
|
104 /* record_variable '.' field_selector */ |
|
105 /* WARNING: input and/or output variables of function blocks |
|
106 * may be accessed as fields of a tructured variable! |
|
107 * Code handling a structured_variable_c must take |
|
108 * this into account! |
|
109 */ |
|
110 // SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
111 void *visit(structured_variable_c *symbol); |
|
112 }; |
|
113 |
|
114 |
|
115 |