absyntax_utils/type_initial_value.cc
changeset 945 477393b00f95
parent 925 a942c55fb769
child 958 7474d2cd1d6e
--- a/absyntax_utils/type_initial_value.cc	Sat Oct 25 13:20:10 2014 +0100
+++ b/absyntax_utils/type_initial_value.cc	Sun Nov 16 12:54:10 2014 +0000
@@ -117,8 +117,27 @@
 }
 
 
-
-void *type_initial_value_c::visit(identifier_c *type_name) {
+/* visitor for identifier_c is necessary because type_initial_value_c will be called to analyse PROGRAM identfiers,
+ * which are still transformed into identfier_c, instead of a derived_datatype_identifier_c
+ */
+void *type_initial_value_c::visit(                 identifier_c *type_name) {
+  /* look up the type declaration... */
+  symbol_c *type_decl = type_symtable.find_value(type_name);
+  if (type_decl == type_symtable.end_value())
+    /* Type declaration not found!! */
+    /* NOTE: Variables declared out of function block 'data types',
+     *    for eg:  VAR  timer: TON; END_VAR
+     * do not have a default value, so (TON) will never be found in the
+     * type symbol table. This means we cannot simply consider this
+     * an error and abort, but must rather return a NULL.
+     */
+     return NULL;
+
+  return type_decl->accept(*this);
+}
+
+  
+void *type_initial_value_c::visit(derived_datatype_identifier_c *type_name) {
   /* look up the type declaration... */
   symbol_c *type_decl = type_symtable.find_value(type_name);
   if (type_decl == type_symtable.end_value())