stage4/generate_c/generate_c_il.cc
changeset 870 9c6c588fd708
parent 861 443e8243f289
child 877 c25346eac788
--- a/stage4/generate_c/generate_c_il.cc	Wed Feb 19 22:25:10 2014 +0100
+++ b/stage4/generate_c/generate_c_il.cc	Wed Feb 19 22:27:11 2014 +0100
@@ -126,7 +126,7 @@
 
 
 
-class generate_c_il_c: public generate_c_typedecl_c, il_default_variable_visitor_c {
+class generate_c_il_c: public generate_c_base_c, il_default_variable_visitor_c {
 
   public:
     typedef enum {
@@ -197,7 +197,7 @@
 
   public:
     generate_c_il_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL)
-    : generate_c_typedecl_c(s4o_ptr),
+    : generate_c_base_c(s4o_ptr),
       implicit_variable_current    (IL_DEFVAR,      NULL),
       implicit_variable_result     (IL_DEFVAR,      NULL),
       implicit_variable_result_back(IL_DEFVAR_BACK, NULL)
@@ -367,7 +367,8 @@
       unsigned int vartype = search_var_instance_decl->get_vartype(symbol);
       if (wanted_variablegeneration == fparam_output_vg) {
         if (vartype == search_var_instance_decl_c::external_vt) {
-          if (search_var_instance_decl->type_is_fb(symbol))
+          if (!get_datatype_info_c::is_type_valid    (symbol->datatype)) ERROR;
+          if ( get_datatype_info_c::is_function_block(symbol->datatype))
             s4o.print(GET_EXTERNAL_FB_BY_REF);
           else
             s4o.print(GET_EXTERNAL_BY_REF);
@@ -379,7 +380,8 @@
       }
       else {
         if (vartype == search_var_instance_decl_c::external_vt) {
-          if (search_var_instance_decl->type_is_fb(symbol))
+          if (!get_datatype_info_c::is_type_valid    (symbol->datatype)) ERROR;
+          if ( get_datatype_info_c::is_function_block(symbol->datatype))
             s4o.print(GET_EXTERNAL_FB);
           else
             s4o.print(GET_EXTERNAL);
@@ -394,8 +396,7 @@
       variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration;
       wanted_variablegeneration = complextype_base_vg;
       symbol->accept(*this);
-      if (search_var_instance_decl->type_is_complex(symbol))
-        s4o.print(",");
+      s4o.print(",");
       wanted_variablegeneration = complextype_suffix_vg;
       symbol->accept(*this);
       s4o.print(")");
@@ -410,11 +411,13 @@
             symbol_c* fb_value = NULL,
             bool negative = false) {
 
-      bool type_is_complex = search_var_instance_decl->type_is_complex(symbol);
+      bool type_is_complex = false;
       if (fb_symbol == NULL) {
         unsigned int vartype = search_var_instance_decl->get_vartype(symbol);
+        type_is_complex = analyse_variable_c::contains_complex_type(symbol);
         if (vartype == search_var_instance_decl_c::external_vt) {
-          if (search_var_instance_decl->type_is_fb(symbol))
+          if (!get_datatype_info_c::is_type_valid    (symbol->datatype)) ERROR;
+          if ( get_datatype_info_c::is_function_block(symbol->datatype))
             s4o.print(SET_EXTERNAL_FB);
           else
             s4o.print(SET_EXTERNAL);
@@ -446,7 +449,7 @@
       symbol->accept(*this);
       s4o.print(",");
       if (negative) {
-	    if (get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype))
+        if (get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype))
           s4o.print("!");
         else
           s4o.print("~");
@@ -572,7 +575,7 @@
 // SYM_REF2(structured_variable_c, record_variable, field_selector)
 void *visit(structured_variable_c *symbol) {
   TRACE("structured_variable_c");
-  bool type_is_complex = search_var_instance_decl->type_is_complex(symbol->record_variable);
+  bool type_is_complex = analyse_variable_c::is_complex_type(symbol->record_variable);
   switch (wanted_variablegeneration) {
     case complextype_base_vg:
     case complextype_base_assignment_vg:
@@ -839,6 +842,14 @@
       break;
     }
     
+    /* We do not yet support embedded IL lists, so we abort the compiler if we find one */
+    /* Note that in IL function calls the syntax does not allow embeded IL lists, so this check is not necessary here! */
+    /*
+    {simple_instr_list_c *instruction_list = dynamic_cast<simple_instr_list_c *>(param_value);
+     if (NULL != instruction_list) STAGE4_ERROR(param_value, param_value, "The compiler does not yet support formal invocations in IL that contain embedded IL lists. Aborting!");
+    }
+    */
+    
     if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) {
       /* No value given for parameter, so we must use the default... */
       /* First check whether default value specified in function declaration...*/
@@ -1060,6 +1071,11 @@
     if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit())
       param_value = function_call_param_iterator.next_nf();
 
+    /* We do not yet support embedded IL lists, so we abort the compiler if we find one */
+    {simple_instr_list_c *instruction_list = dynamic_cast<simple_instr_list_c *>(param_value);
+     if (NULL != instruction_list) STAGE4_ERROR(param_value, param_value, "The compiler does not yet support formal invocations in IL that contain embedded IL lists. Aborting!");
+    }
+    
     symbol_c *param_type = fp_iterator.param_type();
     if (param_type == NULL) ERROR;
     
@@ -1228,6 +1244,11 @@
       break;
     }
     
+    /* We do not yet support embedded IL lists, so we abort the compiler if we find one */
+    {simple_instr_list_c *instruction_list = dynamic_cast<simple_instr_list_c *>(param_value);
+     if (NULL != instruction_list) STAGE4_ERROR(param_value, param_value, "The compiler does not yet support formal invocations in IL that contain embedded IL lists. Aborting!");
+    }
+    
     if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) {
       /* No value given for parameter, so we must use the default... */
       /* First check whether default value specified in function declaration...*/
@@ -1530,6 +1551,16 @@
 
 
 void *visit(S_operator_c *symbol) {
+  /* This operator must implement one of two possible semantics: 
+   *     - FB call
+   *     - Set all the bits of an ANY_BIT type variable to 1
+   */
+  
+  /* Check whether we must implement the FB call semantics... */
+  if (NULL != symbol->called_fb_declaration)
+    return XXX_CAL_operator( "S", this->current_operand);
+  
+  /* Implement the bit setting semantics... */
   if (wanted_variablegeneration != expression_vg) {
     s4o.print("LD");
     return NULL;
@@ -1552,6 +1583,16 @@
 
 
 void *visit(R_operator_c *symbol) {
+  /* This operator must implement one of two possible semantics: 
+   *     - FB call
+   *     - Set all the bits of an ANY_BIT type variable to 0
+   */
+  
+  /* Check whether we must implement the FB call semantics... */
+  if (NULL != symbol->called_fb_declaration)
+    return XXX_CAL_operator( "R", this->current_operand);
+  
+  /* Implement the bit setting semantics... */
   if (wanted_variablegeneration != expression_vg) {
     s4o.print("LD");
     return NULL;