108 |
108 |
109 |
109 |
110 void *type_initial_value_c::handle_type_spec(symbol_c *base_type_name, symbol_c *type_spec_init) { |
110 void *type_initial_value_c::handle_type_spec(symbol_c *base_type_name, symbol_c *type_spec_init) { |
111 if (type_spec_init != NULL) |
111 if (type_spec_init != NULL) |
112 return type_spec_init; |
112 return type_spec_init; |
113 /* no initial value specified, so we return |
113 /* no initial value specified, so we return the initial value of the type this type is based on... */ |
114 * the initial value of the type this type is based on... |
|
115 */ |
|
116 return base_type_name->accept(*this); |
114 return base_type_name->accept(*this); |
117 } |
115 } |
118 |
116 |
119 |
117 |
120 /* visitor for identifier_c is necessary because type_initial_value_c will be called to analyse PROGRAM identfiers, |
118 void *type_initial_value_c::handle_type_name(symbol_c *type_name) { |
121 * which are still transformed into identfier_c, instead of a derived_datatype_identifier_c |
|
122 */ |
|
123 void *type_initial_value_c::visit( identifier_c *type_name) { |
|
124 /* look up the type declaration... */ |
119 /* look up the type declaration... */ |
125 symbol_c *type_decl = type_symtable.find_value(type_name); |
120 symbol_c *type_decl = type_symtable.find_value(type_name); |
126 if (type_decl == type_symtable.end_value()) |
|
127 /* Type declaration not found!! */ |
121 /* Type declaration not found!! */ |
128 /* NOTE: Variables declared out of function block 'data types', |
122 /* NOTE: Variables declared out of function block 'data types',for eg: VAR timer: TON; END_VAR |
129 * for eg: VAR timer: TON; END_VAR |
123 * do not have a default value, so (TON) will never be found in the type symbol table. This means |
130 * do not have a default value, so (TON) will never be found in the |
124 * we cannot simply consider this an error and abort, but must rather return a NULL. |
131 * type symbol table. This means we cannot simply consider this |
|
132 * an error and abort, but must rather return a NULL. |
|
133 */ |
125 */ |
134 return NULL; |
126 if (type_decl == type_symtable.end_value()) return NULL; |
135 |
127 |
136 return type_decl->accept(*this); |
128 return type_decl->accept(*this); |
137 } |
129 } |
138 |
130 |
139 |
131 /* visitor for identifier_c should no longer be necessary. All references to derived datatypes are now stored in then */ |
140 void *type_initial_value_c::visit(derived_datatype_identifier_c *type_name) { |
132 /* AST using either poutype_identifier_c or derived_datatype_identifier_c. In principe, the following should not be necesasry */ |
141 /* look up the type declaration... */ |
133 void *type_initial_value_c::visit( identifier_c *symbol) {return handle_type_name(symbol);} /* should never occur */ |
142 symbol_c *type_decl = type_symtable.find_value(type_name); |
134 void *type_initial_value_c::visit( poutype_identifier_c *symbol) {return handle_type_name(symbol);} /* in practice it might never get called, as FB, Functions and Programs do not have initial value */ |
143 if (type_decl == type_symtable.end_value()) |
135 void *type_initial_value_c::visit(derived_datatype_identifier_c *symbol) {return handle_type_name(symbol);} |
144 /* Type declaration not found!! */ |
|
145 /* NOTE: Variables declared out of function block 'data types', |
|
146 * for eg: VAR timer: TON; END_VAR |
|
147 * do not have a default value, so (TON) will never be found in the |
|
148 * type symbol table. This means we cannot simply consider this |
|
149 * an error and abort, but must rather return a NULL. |
|
150 */ |
|
151 return NULL; |
|
152 |
|
153 return type_decl->accept(*this); |
|
154 } |
|
155 |
136 |
156 /***********************************/ |
137 /***********************************/ |
157 /* B 1.3.1 - Elementary Data Types */ |
138 /* B 1.3.1 - Elementary Data Types */ |
158 /***********************************/ |
139 /***********************************/ |
159 void *type_initial_value_c::visit(time_type_name_c *symbol) {return (void *)time_0;} |
140 void *type_initial_value_c::visit(time_type_name_c *symbol) {return (void *)time_0;} |