From b579674fcea87265dd44f524909f1f1c8f1d77af Mon Sep 17 00:00:00 2001
From: kristof <Kristof.Szabados@ericsson.com>
Date: Tue, 27 Jun 2017 08:23:06 +0200
Subject: [PATCH] Akos Buzas's implementation for leting constant being
 initialized from module parameters.

Signed-off-by: kristof <Kristof.Szabados@ericsson.com>
---
 compiler2/Code.cc            | 3 +++
 compiler2/ttcn3/AST_ttcn3.cc | 8 +++++++-
 compiler2/ttcn3/compiler.h   | 1 +
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/compiler2/Code.cc b/compiler2/Code.cc
index c7bc59d5e..46a5aa69b 100644
--- a/compiler2/Code.cc
+++ b/compiler2/Code.cc
@@ -182,6 +182,7 @@ namespace Common {
     cdef->def = NULL;
     //cdef->cdef = NULL;
     cdef->init = NULL;
+    cdef->post = NULL;
   }
 
   void Code::merge_cdef(output_struct *dest, const_def *cdef)
@@ -189,6 +190,7 @@ namespace Common {
     dest->header.global_vars = mputstr(dest->header.global_vars, cdef->decl);
     dest->source.global_vars = mputstr(dest->source.global_vars, cdef->def);
     dest->functions.pre_init = mputstr(dest->functions.pre_init, cdef->init);
+    dest->functions.post_init = mputstr(dest->functions.post_init, cdef->post);
   }
 
   void Code::free_cdef(const_def *cdef)
@@ -197,6 +199,7 @@ namespace Common {
     Free(cdef->def);
     //Free(cdef->cdef);
     Free(cdef->init);
+    Free(cdef->post);
   }
 
   void Code::init_expr(expression_struct *expr)
diff --git a/compiler2/ttcn3/AST_ttcn3.cc b/compiler2/ttcn3/AST_ttcn3.cc
index 313956251..a860ed078 100644
--- a/compiler2/ttcn3/AST_ttcn3.cc
+++ b/compiler2/ttcn3/AST_ttcn3.cc
@@ -3630,7 +3630,7 @@ namespace Ttcn {
       break;
     default:
       value_under_check = true;
-      type->chk_this_value(value, 0, Type::EXPECTED_CONSTANT, WARNING_FOR_INCOMPLETE,
+        type->chk_this_value(value, 0, Type::EXPECTED_STATIC_VALUE, WARNING_FOR_INCOMPLETE,
         OMIT_NOT_ALLOWED, SUB_CHK, has_implicit_omit_attr());
       value_under_check = false;
       erroneous_attrs = chk_erroneous_attr(w_attrib_path, type, get_my_scope(),
@@ -3688,9 +3688,15 @@ namespace Ttcn {
     const_def cdef;
     Code::init_cdef(&cdef);
     type->generate_code_object(&cdef, value);
+    if (value->is_unfoldable()) {
+    cdef.post = update_location_object(cdef.post);
+    cdef.post = value->generate_code_init(cdef.post,
+      value->get_lhs_name().c_str());
+    } else {
     cdef.init = update_location_object(cdef.init);
     cdef.init = value->generate_code_init(cdef.init,
       value->get_lhs_name().c_str());
+    }
     Code::merge_cdef(target, &cdef);
     Code::free_cdef(&cdef);
   }
diff --git a/compiler2/ttcn3/compiler.h b/compiler2/ttcn3/compiler.h
index f09eb99e8..6498fd5ac 100644
--- a/compiler2/ttcn3/compiler.h
+++ b/compiler2/ttcn3/compiler.h
@@ -96,6 +96,7 @@ extern "C" {
     char *def;
     /* char *cdef; */
     char *init;
+    char *post;
   } const_def;
 
   /* Commonly used functions and variables */
-- 
GitLab