stage3/constant_folding.hh
changeset 967 544ff4dff04f
parent 964 5f4dfe6670da
child 969 706a152731ab
equal deleted inserted replaced
966:cd7fa00ad774 967:544ff4dff04f
    66 	virtual ~constant_folding_c(void);
    66 	virtual ~constant_folding_c(void);
    67 	int get_error_count();
    67 	int get_error_count();
    68 	int handle_var_extern_global_pair(symbol_c *extern_var_name, symbol_c *extern_var_decl, symbol_c *global_var_name, symbol_c *global_var_decl);
    68 	int handle_var_extern_global_pair(symbol_c *extern_var_name, symbol_c *extern_var_decl, symbol_c *global_var_name, symbol_c *global_var_decl);
    69   private:
    69   private:
    70 	void *handle_var_list_decl(symbol_c *var_list, symbol_c *type_decl);
    70 	void *handle_var_list_decl(symbol_c *var_list, symbol_c *type_decl);
       
    71 	void *handle_var_decl     (symbol_c *var_list, bool fixed_init_value);
       
    72 	// Flag to indicate whether the variables in the variable declaration list will always have a fixed value when the POU is executed!
       
    73 	// VAR CONSTANT ... END_VAR will always be true
       
    74 	// VAR          ... END_VAR will always be true for functions (who initialise local variables every time they are called), but false for FBs and PROGRAMS
       
    75 	bool fixed_init_value_; 
       
    76 	bool function_pou_;
       
    77 	bool is_constant(symbol_c *option);
       
    78 	bool is_retain  (symbol_c *option);
       
    79 
       
    80 
    71   public:
    81   public:
    72 	#if 0
    82 	#if 0
    73 	// not currently needed, so comment it out!...
    83 	// not currently needed, so comment it out!...
    74 	/* utility functions for other stage3 algorithms to access the contant folded values */
    84 	/* utility functions for other stage3 algorithms to access the contant folded values */
    75 	/* written as static since we do not need to iteratively visit the symbols! */
    85 	/* written as static since we do not need to iteratively visit the symbols! */
   104     void *visit(fixed_point_c *symbol);
   114     void *visit(fixed_point_c *symbol);
   105 
   115 
   106     /*********************/
   116     /*********************/
   107     /* B 1.4 - Variables */
   117     /* B 1.4 - Variables */
   108     /*********************/
   118     /*********************/
   109     #if DO_CONSTANT_PROPAGATION__
   119 //     #if DO_CONSTANT_PROPAGATION__
   110     void *visit(symbolic_variable_c *symbol);
   120     void *visit(symbolic_variable_c *symbol);
   111     #endif // DO_CONSTANT_PROPAGATION__
   121 //     #endif // DO_CONSTANT_PROPAGATION__
   112     void *visit(symbolic_constant_c *symbol);
   122     void *visit(symbolic_constant_c *symbol);
   113                              
   123                              
   114     /******************************************/
   124     /******************************************/
   115     /* B 1.4.3 - Declaration & Initialisation */
   125     /* B 1.4.3 - Declaration & Initialisation */
   116     /******************************************/
   126     /******************************************/
   117     void *visit(    var1_init_decl_c         *symbol);
   127     void *visit(var1_init_decl_c             *symbol);
   118     void *visit(     external_declaration_c  *symbol);
   128     void *visit(        input_declarations_c *symbol);
       
   129     void *visit(       output_declarations_c *symbol);
       
   130     void *visit( input_output_declarations_c *symbol);
       
   131     void *visit(          var_declarations_c *symbol);
       
   132     void *visit(retentive_var_declarations_c *symbol);
       
   133     void *visit( external_var_declarations_c *symbol);
       
   134     void *visit(external_declaration_c       *symbol);
   119 
   135 
   120     /**************************************/
   136     /**************************************/
   121     /* B.1.5 - Program organization units */
   137     /* B.1.5 - Program organization units */
   122     /**************************************/
   138     /**************************************/
   123     /***********************/
   139     /***********************/
   124     /* B 1.5.1 - Functions */
   140     /* B 1.5.1 - Functions */
   125     /***********************/
   141     /***********************/
   126     void *visit(function_declaration_c *symbol);
   142     void *visit(function_declaration_c *symbol);
   127     
   143     void *visit(function_var_decls_c   *symbol);
       
   144 
   128     /*****************************/
   145     /*****************************/
   129     /* B 1.5.2 - Function Blocks */
   146     /* B 1.5.2 - Function Blocks */
   130     /*****************************/
   147     /*****************************/
   131     void *visit(function_block_declaration_c *symbol);
   148     void *visit(function_block_declaration_c *symbol);
       
   149     void *visit(            temp_var_decls_c *symbol);
       
   150     void *visit(   non_retentive_var_decls_c *symbol);
   132 
   151 
   133     /**********************/
   152     /**********************/
   134     /* B 1.5.3 - Programs */
   153     /* B 1.5.3 - Programs */
   135     /**********************/
   154     /**********************/
   136     void *visit(program_declaration_c *symbol);
   155     void *visit(program_declaration_c *symbol);
   228     void *visit(   neg_expression_c *symbol);
   247     void *visit(   neg_expression_c *symbol);
   229     void *visit(   not_expression_c *symbol);
   248     void *visit(   not_expression_c *symbol);
   230     //void *visit(function_invocation_c *symbol); /* TODO */
   249     //void *visit(function_invocation_c *symbol); /* TODO */
   231 
   250 
   232     
   251     
   233     #if DO_CONSTANT_PROPAGATION__
       
   234     /*********************************/
   252     /*********************************/
   235     /* B 3.2.1 Assignment Statements */
   253     /* B 3.2.1 Assignment Statements */
   236     /*********************************/
   254     /*********************************/
   237     void *visit(assignment_statement_c *symbol);
   255     void *visit(assignment_statement_c *symbol);
   238 
   256 
       
   257     #if DO_CONSTANT_PROPAGATION__
   239     /********************************/
   258     /********************************/
   240     /* B 3.2.3 Selection Statements */
   259     /* B 3.2.3 Selection Statements */
   241     /********************************/
   260     /********************************/
   242     void *visit(if_statement_c *symbol);
   261     void *visit(if_statement_c *symbol);
   243 
   262