Fix bug in function calls with literal parameters
authorlaurent
Fri, 08 Jul 2011 11:06:27 +0200
changeset 336 229eb3e29216
parent 335 96d2efda3d8d
child 337 9a2262fb7994
child 341 ba80c3ceb6fb
Fix bug in function calls with literal parameters
absyntax_utils/search_expression_type.cc
absyntax_utils/search_expression_type.hh
stage4/generate_c/generate_c_il.cc
stage4/generate_c/generate_c_inlinefcall.cc
stage4/generate_c/generate_c_st.cc
--- a/absyntax_utils/search_expression_type.cc	Thu Jul 07 10:49:08 2011 +0200
+++ b/absyntax_utils/search_expression_type.cc	Fri Jul 08 11:06:27 2011 +0200
@@ -191,6 +191,16 @@
   return NULL;
 }
 
+symbol_c *search_expression_type_c::default_literal_type(symbol_c* symbol) {
+  if (is_literal_integer_type(symbol)) {
+    return (symbol_c *)&search_constant_type_c::lint_type_name;
+  }
+  else if (is_literal_real_type(symbol)) {
+    return (symbol_c *)&search_constant_type_c::lreal_type_name;
+  }
+  return symbol;
+}
+
 
 integer_c search_expression_type_c::integer("1"); // what default value should we use here ???
 #include "search_type_code.c"
--- a/absyntax_utils/search_expression_type.hh	Thu Jul 07 10:49:08 2011 +0200
+++ b/absyntax_utils/search_expression_type.hh	Fri Jul 08 11:06:27 2011 +0200
@@ -64,6 +64,7 @@
 
     bool is_same_type(symbol_c *first_type, symbol_c *second_type);
     symbol_c* common_type(symbol_c *first_type, symbol_c *second_type);
+    symbol_c* default_literal_type(symbol_c *symbol);
 
     /*
     #include "search_type_code.c"
--- a/stage4/generate_c/generate_c_il.cc	Thu Jul 07 10:49:08 2011 +0200
+++ b/stage4/generate_c/generate_c_il.cc	Fri Jul 08 11:06:27 2011 +0200
@@ -893,9 +893,12 @@
     
   if (function_type_prefix != NULL) {
     s4o.print("(");
-    function_type_prefix->accept(*this);
+    search_expression_type->default_literal_type(function_type_prefix)->accept(*this);
     s4o.print(")");
   }
+  if (function_type_suffix != NULL) {
+  	function_type_suffix = search_expression_type->default_literal_type(function_type_prefix);
+  }
   if (has_output_params) {
   	fcall_number++;
   	s4o.print("__");
@@ -1258,9 +1261,12 @@
   
   if (function_type_prefix != NULL) {
     s4o.print("(");
-    function_type_prefix->accept(*this);
+    search_expression_type->default_literal_type(function_type_prefix)->accept(*this);
     s4o.print(")");
   }
+  if (function_type_suffix != NULL) {
+  	function_type_suffix = search_expression_type->default_literal_type(function_type_prefix);
+  }
   if (has_output_params) {
 	fcall_number++;
 	s4o.print("__");
--- a/stage4/generate_c/generate_c_inlinefcall.cc	Thu Jul 07 10:49:08 2011 +0200
+++ b/stage4/generate_c/generate_c_inlinefcall.cc	Fri Jul 08 11:06:27 2011 +0200
@@ -91,11 +91,9 @@
             std::list<FUNCTION_PARAM*>::iterator pt;
 
       fcall_number++;
-      if (search_expression_type->is_literal_integer_type(function_type_prefix)) {
-    	function_type_prefix = (symbol_c *)&search_constant_type_c::lint_type_name;
-      }
-      else if (search_expression_type->is_literal_real_type(function_type_prefix)) {
-    	function_type_prefix = (symbol_c *)&search_constant_type_c::lreal_type_name;
+      function_type_prefix = search_expression_type->default_literal_type(function_type_prefix);
+      if (function_type_suffix) {
+        function_type_suffix = search_expression_type->default_literal_type(function_type_suffix);
       }
 
       s4o.print(s4o.indent_spaces);
@@ -105,23 +103,16 @@
       fbname->accept(*this);
       s4o.print("_");
       function_name->accept(*this);
-      if (function_type_suffix)
-        function_type_suffix->accept(*this);
+      if (function_type_suffix) {
+    	function_type_suffix->accept(*this);
+      }
       s4o.print_integer(fcall_number);
       s4o.print("(");
       s4o.indent_right();
 
       PARAM_LIST_ITERATOR() {
         if (PARAM_DIRECTION == function_param_iterator_c::direction_in) {
-          if (search_expression_type->is_literal_integer_type(PARAM_TYPE)) {
-        	((symbol_c *)&search_constant_type_c::lint_type_name)->accept(*this);
-          }
-          else if (search_expression_type->is_literal_real_type(PARAM_TYPE)) {
-        	((symbol_c *)&search_constant_type_c::lreal_type_name)->accept(*this);
-          }
-          else {
-        	PARAM_TYPE->accept(*this);
-          }
+          search_expression_type->default_literal_type(PARAM_TYPE)->accept(*this);
           s4o.print(" ");
           PARAM_NAME->accept(*this);
           s4o.print(",\n" + s4o.indent_spaces);
--- a/stage4/generate_c/generate_c_st.cc	Thu Jul 07 10:49:08 2011 +0200
+++ b/stage4/generate_c/generate_c_st.cc	Fri Jul 08 11:06:27 2011 +0200
@@ -698,9 +698,12 @@
 
   if (function_type_prefix != NULL) {
     s4o.print("(");
-    function_type_prefix->accept(*this);
+    search_expression_type->default_literal_type(function_type_prefix)->accept(*this);
     s4o.print(")");
   }
+  if (function_type_suffix != NULL) {
+	function_type_suffix = search_expression_type->default_literal_type(function_type_prefix);
+  }
   if (has_output_params) {
 	fcall_number++;
 	s4o.print("__");