stage4/generate_c/generate_c_base.cc
changeset 1011 76175defb87b
parent 966 cd7fa00ad774
child 1016 91bef6704b44
equal deleted inserted replaced
1010:242907849850 1011:76175defb87b
   247       r_exp->accept(*this);
   247       r_exp->accept(*this);
   248       s4o.print(")");
   248       s4o.print(")");
   249       return NULL;
   249       return NULL;
   250     }
   250     }
   251 
   251 
       
   252     /* Call a standard library function that does a comparison (GT, NE, EQ, LT, ...)
       
   253      * NOTE: Typically, the function will have the following parameters: 
       
   254      *         1st parameter: EN  (enable)
       
   255      *         2nd parameter: ENO (enable output)
       
   256      *         3rd parameter: number of operands we will be passing (required because we are calling an extensible standard function!)
       
   257      *         4th parameter: the left  hand side of the comparison expression (in out case, the IL implicit variable)
       
   258      *         4th parameter: the right hand side of the comparison expression (in out case, current operand)
       
   259      *       
       
   260      *         The 1st and 2nd parameter may not be present, only issue them if NE and ENO are being generated!
       
   261      *         The 3rd parameter must not be generated when the 'NE' function is called (it is not an extensible function!)
       
   262      * 
       
   263      *  NOTE: To implement this correctly, this function should really instantiate a 
       
   264      *   function_invocation_c and have the generate_c visitor generate the code automatically for this
       
   265      *   function invocation. However, the code for function invocations is currently duplicated 
       
   266      *   for IL and ST. Until this code is not re-formulated into a single piece of general code, for now
       
   267      *   we generate the function call directly here in print_compare_function()
       
   268      */ 
   252     void *print_compare_function(const char *function,
   269     void *print_compare_function(const char *function,
   253           symbol_c *compare_type,
   270           symbol_c *compare_type,
   254           symbol_c *l_exp,
   271           symbol_c *l_exp,
   255           symbol_c *r_exp) {
   272           symbol_c *r_exp) {
   256       s4o.print(function);
   273       // Print out the name of the function we will call.
   257       compare_type->accept(*this);
   274       // It will be something like LE_TIME, LE_DATE, GT_DATE, ...
   258       s4o.print("(__BOOL_LITERAL(TRUE), NULL, 2, ");
   275       //    (in other words, we are calling an overloaded function!)
       
   276       s4o.print(function); // the GT, LE, ... part
       
   277       s4o.print("_");  // the '_' part...
       
   278       compare_type->accept(*this); // the TIME, DATE, ... part.
       
   279       s4o.print("(");  // start of parameters to function call...
       
   280       // Determine whether this function has the EN parameter
       
   281       //    (we just check the base LE, GT, .. function, as it should have
       
   282       //     the same parameters as the overloaded function!)
       
   283       function_symtable_t::iterator lower = function_symtable.lower_bound(function);
       
   284       if (lower == function_symtable.end()) ERROR;  // We want to call a function that does not exist!!?? Hmm...
       
   285       search_var_instance_decl_c search_var(function_symtable.get_value(lower));
       
   286       identifier_c  en_var("EN");
       
   287       identifier_c eno_var("ENO");
       
   288       if (search_var.get_vartype(& en_var) == search_var_instance_decl_c::input_vt)
       
   289         s4o.print("__BOOL_LITERAL(TRUE), "); // function has EN parameter, pass TRUE
       
   290       if (search_var.get_vartype(&eno_var) == search_var_instance_decl_c::output_vt)
       
   291         s4o.print("NULL, "); // function has ENO parameter, pass NULL
       
   292       if (strcmp(function, "NE") != 0) // All comparison library functions are extensible, except for 'NE'!!
       
   293         s4o.print("2, "); // function is extensible, so must first pass the number of parameters that follow
   259       l_exp->accept(*this);
   294       l_exp->accept(*this);
   260       s4o.print(", ");
   295       s4o.print(", ");
   261       r_exp->accept(*this);
   296       r_exp->accept(*this);
   262       s4o.print(")");
   297       s4o.print(")");
   263       return NULL;
   298       return NULL;