stage3/constant_folding.hh
changeset 774 979af2009d88
parent 667 bd1360f29f15
child 780 9fbdf8a7430e
equal deleted inserted replaced
773:d23c660361b1 774:979af2009d88
    41 
    41 
    42 #include <vector>
    42 #include <vector>
    43 #include "../absyntax_utils/absyntax_utils.hh"
    43 #include "../absyntax_utils/absyntax_utils.hh"
    44 
    44 
    45 
    45 
       
    46 class convert_c : public iterator_visitor_c {
       
    47 	std::string text;
       
    48 
       
    49 public:
       
    50 	convert_c(symbol_c *symbol = NULL) {
       
    51 		text = "";
       
    52 	}
       
    53 
       
    54 	std::string toString(symbol_c *symbol) {
       
    55 		symbol->accept(*this);
       
    56 		return text;
       
    57 	}
       
    58 
       
    59 	void *visit(identifier_c *symbol) {
       
    60 		text = symbol->value;
       
    61 		return NULL;
       
    62 	}
       
    63 
       
    64 	void *visit(symbolic_variable_c *symbol) {
       
    65 		symbol->var_name->accept(*this);
       
    66 		return NULL;
       
    67 	}
       
    68 };
    46 
    69 
    47 class constant_folding_c : public iterator_visitor_c {
    70 class constant_folding_c : public iterator_visitor_c {
    48   private:
       
    49     search_varfb_instance_type_c *search_varfb_instance_type;
    71     search_varfb_instance_type_c *search_varfb_instance_type;
    50     int error_count;
    72     int error_count;
    51     bool warning_found;
    73     bool warning_found;
    52     int current_display_error_level;
    74     int current_display_error_level;
    53     /* Pointer to the previous IL instruction, which contains the current cvalue of the data stored in the IL stack, i.e. the default variable, a.k.a. accumulator */
    75     /* Pointer to the previous IL instruction, which contains the current cvalue of the data stored in the IL stack, i.e. the default variable, a.k.a. accumulator */
    54     symbol_c *prev_il_instruction;
    76     symbol_c *prev_il_instruction;
    55     /* the current IL operand being analyzed */
    77     /* the current IL operand being analyzed */
    56     symbol_c *il_operand;
    78     symbol_c *il_operand;
       
    79     convert_c convert;
    57 
    80 
    58   public:
    81   public:
    59 	constant_folding_c(symbol_c *symbol = NULL);
    82 	constant_folding_c(symbol_c *symbol = NULL);
    60 	virtual ~constant_folding_c(void);
    83 	virtual ~constant_folding_c(void);
    61 	int get_error_count();
    84 	int get_error_count();
    83 
   106 
    84     /************************/
   107     /************************/
    85     /* B 1.2.3.1 - Duration */
   108     /* B 1.2.3.1 - Duration */
    86     /********* **************/
   109     /********* **************/
    87     void *visit(fixed_point_c *symbol);
   110     void *visit(fixed_point_c *symbol);
       
   111 
       
   112     /*********************/
       
   113     /* B 1.4 - Variables */
       
   114     /*********************/
       
   115     void *visit(symbolic_variable_c *symbol);
       
   116 
       
   117     /**********************/
       
   118     /* B 1.5.3 - Programs */
       
   119     /**********************/
       
   120     void *visit(program_declaration_c *symbol);
    88 
   121 
    89     /****************************************/
   122     /****************************************/
    90     /* B.2 - Language IL (Instruction List) */
   123     /* B.2 - Language IL (Instruction List) */
    91     /****************************************/
   124     /****************************************/
    92     /***********************************/
   125     /***********************************/
   176     void *visit(   mod_expression_c *symbol);
   209     void *visit(   mod_expression_c *symbol);
   177     void *visit( power_expression_c *symbol);
   210     void *visit( power_expression_c *symbol);
   178     void *visit(   neg_expression_c *symbol);
   211     void *visit(   neg_expression_c *symbol);
   179     void *visit(   not_expression_c *symbol);
   212     void *visit(   not_expression_c *symbol);
   180     //void *visit(function_invocation_c *symbol); /* TODO */
   213     //void *visit(function_invocation_c *symbol); /* TODO */
       
   214 
   181     
   215     
       
   216     /*********************************/
       
   217     /* B 3.2.1 Assignment Statements */
       
   218     /*********************************/
       
   219     void *visit(assignment_statement_c *symbol);
       
   220 
       
   221     /********************************/
       
   222     /* B 3.2.3 Selection Statements */
       
   223     /********************************/
       
   224     void *visit(if_statement_c *symbol);
   182 };
   225 };
   183 
   226