33 * A small helper visitor class, that will |
33 * A small helper visitor class, that will |
34 * return the name (tokn_c *) of a variable, as it will |
34 * return the name (tokn_c *) of a variable, as it will |
35 * appear in the variable declaration. |
35 * appear in the variable declaration. |
36 */ |
36 */ |
37 |
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 |
38 |
59 |
39 |
60 #include "absyntax_utils.hh" |
40 #include "absyntax_utils.hh" |
61 |
41 |
62 |
42 |
66 |
46 |
67 get_var_name_c *get_var_name_c::singleton_instance_ = NULL; |
47 get_var_name_c *get_var_name_c::singleton_instance_ = NULL; |
68 |
48 |
69 |
49 |
70 |
50 |
|
51 /* For ex.: |
|
52 * VAR |
|
53 * A : int; |
|
54 * B : ARRAY [1..9] of int; |
|
55 * C : some_struct_t; |
|
56 * END_VAR |
|
57 * |
|
58 * A := 56; |
|
59 * B[8] := 99; |
|
60 * C.e := 77; |
|
61 * |
|
62 * Calling this method with symbolic_variable_c instance referencing 'A' in |
|
63 * the line 'A := 56', will return the string "A". |
|
64 * |
|
65 * Calling this method with array_variable_c instance referencing 'B[8]' in |
|
66 * the line 'B[8] := 99', will return the string "B". |
|
67 * |
|
68 * Calling this method with array_variable_c instance referencing 'C.e' in |
|
69 * the line 'C.e := 77', will return the string "C". |
|
70 */ |
71 |
71 |
72 token_c *get_var_name_c::get_name(symbol_c *symbol) { |
72 token_c *get_var_name_c::get_name(symbol_c *symbol) { |
73 if (NULL == singleton_instance_) singleton_instance_ = new get_var_name_c(); |
73 if (NULL == singleton_instance_) singleton_instance_ = new get_var_name_c(); |
74 if (NULL == singleton_instance_) ERROR; |
74 if (NULL == singleton_instance_) ERROR; |
75 |
75 |
76 return (token_c *)(symbol->accept(*singleton_instance_)); |
76 return (token_c *)(symbol->accept(*singleton_instance_)); |
77 } |
77 } |
|
78 |
|
79 |
|
80 /* Return the last field of a structured variable... |
|
81 * |
|
82 * A := 56; --> returns A |
|
83 * B[8] := 99; --> returns B |
|
84 * C.e := 77; --> returns e !!! |
|
85 */ |
|
86 symbol_c *get_var_name_c::get_last_field(symbol_c *symbol) { |
|
87 if (NULL == singleton_instance_) singleton_instance_ = new get_var_name_c(); |
|
88 if (NULL == singleton_instance_) ERROR; |
|
89 |
|
90 singleton_instance_->last_field = NULL; |
|
91 symbol_c *res = (symbol_c*)(symbol->accept(*singleton_instance_)); |
|
92 return (NULL != singleton_instance_->last_field)? singleton_instance_->last_field : res; |
|
93 } |
|
94 |
|
95 |
78 |
96 |
79 |
97 |
80 /*************************/ |
98 /*************************/ |
81 /* B.1 - Common elements */ |
99 /* B.1 - Common elements */ |
82 /*************************/ |
100 /*************************/ |
112 * may be accessed as fields of a tructured variable! |
130 * may be accessed as fields of a tructured variable! |
113 * Code handling a structured_variable_c must take |
131 * Code handling a structured_variable_c must take |
114 * this into account! |
132 * this into account! |
115 */ |
133 */ |
116 // SYM_REF2(structured_variable_c, record_variable, field_selector) |
134 // SYM_REF2(structured_variable_c, record_variable, field_selector) |
117 void *get_var_name_c::visit(structured_variable_c *symbol) {return symbol->record_variable->accept(*this);} |
135 void *get_var_name_c::visit(structured_variable_c *symbol) { |
|
136 void *res = symbol->record_variable->accept(*this); |
|
137 last_field = symbol->field_selector; |
|
138 return res; |
|
139 } |
118 |
140 |
119 |
141 |
120 |
142 |