Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
authorlaurent
Sun, 13 Dec 2009 11:41:22 +0100
changeset 234 e4d31cd0e6d8
parent 233 3d23a68183d3
child 235 ed66dc50f31a
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
stage4/generate_c/generate_c.cc
stage4/generate_c/generate_c_inlinefcall.cc
--- a/stage4/generate_c/generate_c.cc	Sat Dec 12 20:41:32 2009 +0100
+++ b/stage4/generate_c/generate_c.cc	Sun Dec 13 11:41:22 2009 +0100
@@ -639,6 +639,7 @@
   generate_c_vardecl_c *vardecl;
   generate_c_sfcdecl_c *sfcdecl;
   generate_c_typedecl_c *typedecl;
+  generate_c_inlinefcall_c *inlinedecl;
   TRACE("function_block_declaration_c");
 
   /* (A) Function Block data structure declaration... */
@@ -686,8 +687,9 @@
   delete typedecl;
 
   /* (A.6) Function Block inline function declaration for function invocation */
-  generate_c_inlinefcall_c inline_decl(&s4o, symbol->fblock_name, symbol, FB_FUNCTION_PARAM"->");
-  symbol->fblock_body->accept(inline_decl);
+  inlinedecl = new generate_c_inlinefcall_c(&s4o, symbol->fblock_name, symbol, FB_FUNCTION_PARAM"->");
+  inlinedecl->print(symbol->fblock_body);
+  delete inlinedecl;
 
   /* (B) Constructor */
   /* (B.1) Constructor name... */
@@ -830,6 +832,7 @@
   generate_c_vardecl_c *vardecl;
   generate_c_sfcdecl_c *sfcdecl;
   generate_c_typedecl_c *typedecl;
+  generate_c_inlinefcall_c *inlinedecl;
   TRACE("program_declaration_c");
 
   /* (A) Program data structure declaration... */
@@ -874,8 +877,9 @@
   delete typedecl;
 
   /* (A.6) Function Block inline function declaration for function invocation */
-  generate_c_inlinefcall_c inline_decl(&s4o, symbol->program_type_name, symbol, FB_FUNCTION_PARAM"->");
-  symbol->function_block_body->accept(inline_decl);
+  inlinedecl = new generate_c_inlinefcall_c(&s4o, symbol->program_type_name, symbol, FB_FUNCTION_PARAM"->");
+  inlinedecl->print(symbol->function_block_body);
+  delete inlinedecl;
 
   /* (B) Constructor */
   /* (B.1) Constructor name... */
--- a/stage4/generate_c/generate_c_inlinefcall.cc	Sat Dec 12 20:41:32 2009 +0100
+++ b/stage4/generate_c/generate_c_inlinefcall.cc	Sun Dec 13 11:41:22 2009 +0100
@@ -32,7 +32,7 @@
 
 #define INLINE_RESULT_TEMP_VAR "__res"
 
-class generate_c_inline_c: public generate_c_typedecl_c {
+class generate_c_inlinefcall_c: public generate_c_typedecl_c {
 
   public:
     typedef enum {
@@ -66,7 +66,7 @@
     variablegeneration_t wanted_variablegeneration;
 
   public:
-    generate_c_inline_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL)
+    generate_c_inlinefcall_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL)
     : generate_c_typedecl_c(s4o_ptr),
       default_variable_name(IL_DEFVAR, NULL)
     {
@@ -78,14 +78,23 @@
       wanted_variablegeneration = expression_vg;
     }
 
-    virtual ~generate_c_inline_c(void) {
+    virtual ~generate_c_inlinefcall_c(void) {
+      delete search_expression_type;
       delete search_varfb_instance_type;
     }
 
-    void *generate_inline(symbol_c *function_name,
-    		symbol_c *return_data_type,
-    		std::list<FUNCTION_PARAM*> param_list) {
-      std::list<FUNCTION_PARAM*>::iterator pt;
+    void print(symbol_c* symbol) {
+      function_call_iterator_c fc_iterator(symbol);
+      symbol_c* function_call;
+      while ((function_call = fc_iterator.next()) != NULL) {
+    	function_call->accept(*this);
+      }
+    }
+
+    void generate_inline(symbol_c *function_name,
+            symbol_c *return_data_type,
+            std::list<FUNCTION_PARAM*> param_list) {
+            std::list<FUNCTION_PARAM*>::iterator pt;
 
       fcall_number++;
 
@@ -176,8 +185,6 @@
 
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n\n");
-
-      return NULL;
     }
 
   private:
@@ -581,43 +588,6 @@
 	  return NULL;
     }
 
-};  /* generate_c_inline_c */
-
-
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-
-
-class generate_c_inlinefcall_c: public iterator_visitor_c {
-
-  private:
-	generate_c_inline_c *generate_c_inline;
-
-  public:
-	generate_c_inlinefcall_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) {
-	  generate_c_inline = new generate_c_inline_c(s4o_ptr, name, scope, variable_prefix);
-	}
-
-	virtual ~generate_c_inlinefcall_c(void) {
-	  delete generate_c_inline;
-	}
-
-  private:
-
-	void *visit(function_invocation_c *symbol) {
-	  return symbol->accept(*generate_c_inline);
-	}
-
-	void *visit(il_function_call_c *symbol) {
-	  return symbol->accept(*generate_c_inline);
-	}
-
-	void *visit(il_formal_funct_call_c *symbol) {
-	  return symbol->accept(*generate_c_inline);
-	}
-}; /* generate_c_inlinefcall_c */
-
-
-
+};  /* generate_c_inlinefcall_c */
+
+