stage4/generate_c/generate_c_inlinefcall.cc
changeset 690 6156ee2b4e32
parent 683 2d96a47a75b1
child 693 51a2fa6441b9
equal deleted inserted replaced
689:45c35d829db9 690:6156ee2b4e32
    35       complextype_base_vg,
    35       complextype_base_vg,
    36       complextype_suffix_vg
    36       complextype_suffix_vg
    37     } variablegeneration_t;
    37     } variablegeneration_t;
    38 
    38 
    39   private:
    39   private:
    40 
       
    41     /* The initial value that should be given to the IL default variable
       
    42 	 * imediately after a parenthesis is opened.
       
    43 	 * This variable is only used to pass data from the
       
    44 	 * il_expression_c visitor to the simple_instr_list_c visitor.
       
    45 	 *
       
    46 	 * e.g.:
       
    47 	 *         LD var1
       
    48 	 *         AND ( var2
       
    49 	 *         OR var3
       
    50 	 *         )
       
    51 	 *
       
    52 	 * In the above code sample, the line 'AND ( var2' constitutes
       
    53 	 * an il_expression_c, where var2 should be loaded into the
       
    54 	 * il default variable before continuing with the expression
       
    55 	 * inside the parenthesis.
       
    56 	 * Unfortunately, only the simple_instr_list_c may do the
       
    57 	 * initial laoding of the var2 bariable following the parenthesis,
       
    58 	 * so the il_expression_c visitor will have to pass 'var2' as a
       
    59 	 * parameter to the simple_instr_list_c visitor.
       
    60 	 * Ergo, the existance of the following parameter...!
       
    61 	 */
       
    62 	symbol_c *il_default_variable_init_value;
       
    63 
       
    64 	 /* The result of the comparison IL operations (GT, EQ, LT, ...)
    40 	 /* The result of the comparison IL operations (GT, EQ, LT, ...)
    65 	 * is a boolean variable.
    41 	 * is a boolean variable.
    66 	 * This class keeps track of the current data type stored in the
    42 	 * This class keeps track of the current data type stored in the
    67 	 * il default variable. This is usually done by keeping a reference
    43 	 * il default variable. This is usually done by keeping a reference
    68 	 * to the data type of the last operand. Nevertheless, in the case of
    44 	 * to the data type of the last operand. Nevertheless, in the case of
   107     {
    83     {
   108       search_varfb_instance_type = new search_varfb_instance_type_c(scope);
    84       search_varfb_instance_type = new search_varfb_instance_type_c(scope);
   109       search_var_instance_decl   = new search_var_instance_decl_c  (scope);
    85       search_var_instance_decl   = new search_var_instance_decl_c  (scope);
   110       
    86       
   111       this->set_variable_prefix(variable_prefix);
    87       this->set_variable_prefix(variable_prefix);
   112       il_default_variable_init_value = NULL;
       
   113       fcall_number = 0;
    88       fcall_number = 0;
   114       fbname = name;
    89       fbname = name;
   115       wanted_variablegeneration = expression_vg;
    90       wanted_variablegeneration = expression_vg;
   116       generating_inlinefunction = false;
    91       generating_inlinefunction = false;
   117     }
    92     }
   575     //SYM_REF4(il_expression_c, il_expr_operator, il_operand, simple_instr_list, unused)
   550     //SYM_REF4(il_expression_c, il_expr_operator, il_operand, simple_instr_list, unused)
   576     void *visit(il_expression_c *symbol) {
   551     void *visit(il_expression_c *symbol) {
   577       /* We will be recursevely interpreting an instruction list, so we store a backup of the implicit_variable_result/current.
   552       /* We will be recursevely interpreting an instruction list, so we store a backup of the implicit_variable_result/current.
   578        * Notice that they will be overwriten while processing the parenthsized instruction list.
   553        * Notice that they will be overwriten while processing the parenthsized instruction list.
   579        */
   554        */
   580       // il_default_variable_c old_implicit_variable_current = this->implicit_variable_current;      // no longer needed!
   555       // il_default_variable_c old_implicit_variable_current = this->implicit_variable_current;      // no longer needed as we do not call symbol->il_expr_operator->accept(*this);
   581       
   556       
   582 
   557       /* Stage2 will insert an artificial (and equivalent) LD <il_operand> to the simple_instr_list if necessary. We can therefore ignore the 'il_operand' entry! */
   583      /* Pass the symbol->il_operand to the simple_instr_list visitor
   558       //if (NULL != symbol->il_operand) { do nothing!! }
   584       * using the il_default_variable_init_value parameter...
       
   585       * Note that the simple_instr_list_c visitor will set this parameter
       
   586       * to NULL as soon as it does not require it any longer,
       
   587       * so we don't do it here again after the
       
   588       *   symbol->simple_instr_list->accept(*this);
       
   589       * returns...
       
   590       */
       
   591       this->il_default_variable_init_value = symbol->il_operand;
       
   592 
   559 
   593       /* Now do the parenthesised instructions... */
   560       /* Now do the parenthesised instructions... */
   594       /* NOTE: the following code line will get the variable this->implicit_variable_current.datatype updated!  */
   561       /* NOTE: the following code line will get the variable this->implicit_variable_current.datatype updated!  */
   595       symbol->simple_instr_list->accept(*this);
   562       symbol->simple_instr_list->accept(*this);
   596 
   563 
   737 
   704 
   738 
   705 
   739 
   706 
   740     /* | simple_instr_list il_simple_instruction */
   707     /* | simple_instr_list il_simple_instruction */
   741     // SYM_LIST(simple_instr_list_c)
   708     // SYM_LIST(simple_instr_list_c)
   742     void *visit(simple_instr_list_c *symbol) {
   709     void *visit(simple_instr_list_c *symbol) {return iterator_visitor_c::visit(symbol);}
   743       /* Check whether we should initiliase the il default variable... */
       
   744       // TODO: fix the way we handle this... It is currently not working!!
       
   745 //      if (NULL != this->il_default_variable_init_value)   implicit_variable_current = il_default_variable_init_value;
       
   746       this->il_default_variable_init_value = NULL;       // this parameter no longer required...
       
   747 
       
   748       iterator_visitor_c::visit(symbol);
       
   749       return NULL;
       
   750     }
       
   751 
   710 
   752 
   711 
   753     // SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;)
   712     // SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;)
   754     void *visit(il_simple_instruction_c *symbol)	{
   713     void *visit(il_simple_instruction_c *symbol)	{
   755       return symbol->il_simple_instruction->accept(*this);
   714       /* all previous IL instructions should have the same datatype (checked in stage3), so we get the datatype from the first previous IL instruction we find */
       
   715       implicit_variable_current.datatype = (symbol->prev_il_instruction.empty())? NULL : symbol->prev_il_instruction[0]->datatype;
       
   716       symbol->il_simple_instruction->accept(*this);
       
   717       implicit_variable_current.datatype = NULL;
       
   718       return NULL;      
   756     }
   719     }
   757 
   720 
   758 
   721 
   759 
   722 
   760     /***************************************/
   723     /***************************************/