stage3/stage3.cc
changeset 959 8bfcc8e62bd6
parent 738 e47cc8c954db
child 984 634269b0f104
equal deleted inserted replaced
958:7474d2cd1d6e 959:8bfcc8e62bd6
    42 #include "lvalue_check.hh"
    42 #include "lvalue_check.hh"
    43 #include "array_range_check.hh"
    43 #include "array_range_check.hh"
    44 #include "constant_folding.hh"
    44 #include "constant_folding.hh"
    45 #include "declaration_check.hh"
    45 #include "declaration_check.hh"
    46 #include "enum_declaration_check.hh"
    46 #include "enum_declaration_check.hh"
       
    47 #include "remove_forward_dependencies.hh"
       
    48 
    47 
    49 
    48 
    50 
    49 static int enum_declaration_check(symbol_c *tree_root){
    51 static int enum_declaration_check(symbol_c *tree_root){
    50     enum_declaration_check_c enum_declaration_check(NULL);
    52     enum_declaration_check_c enum_declaration_check(NULL);
    51     tree_root->accept(enum_declaration_check);
    53     tree_root->accept(enum_declaration_check);
   112 	tree_root->accept(array_range_check);
   114 	tree_root->accept(array_range_check);
   113 	return array_range_check.get_error_count();
   115 	return array_range_check.get_error_count();
   114 }
   116 }
   115 
   117 
   116 
   118 
   117 int stage3(symbol_c *tree_root){
   119 
       
   120 /* Removing forward dependencies only makes sense when stage1_2 is run with the pre-parsing option.
       
   121  * This algorithm has no dependencies on other stage 3 algorithms.
       
   122  * Typically this is run last, just to show that the remaining algorithms also do not depend on the fact that 
       
   123  * the library_c (i.e. the source code) does not contain forward dependencies.
       
   124  */
       
   125 static int remove_forward_dependencies(symbol_c *tree_root, symbol_c **ordered_tree_root) {
       
   126 	if (NULL != ordered_tree_root)    *ordered_tree_root = tree_root; // by default, consider tree_root already ordered
       
   127 	if (!runtime_options.pre_parsing)  return 0;                      // No re-ordering necessary, just return
       
   128 	  
       
   129 	/* We need to re-order the elements in the library, to fix any forward references! */
       
   130 	remove_forward_dependencies_c remove_forward_dependencies;
       
   131 	symbol_c *new_tree_root = remove_forward_dependencies.create_new_tree(tree_root);
       
   132 	if (NULL ==     new_tree_root)   ERROR;
       
   133 	if (NULL != ordered_tree_root)   *ordered_tree_root = new_tree_root;
       
   134 	return remove_forward_dependencies.get_error_count();
       
   135 }
       
   136 
       
   137 
       
   138 int stage3(symbol_c *tree_root, symbol_c **ordered_tree_root) {
   118 	int error_count = 0;
   139 	int error_count = 0;
   119 	error_count += enum_declaration_check(tree_root);
   140 	error_count += enum_declaration_check(tree_root);
   120 	error_count += declaration_safety(tree_root);
   141 	error_count += declaration_safety(tree_root);
   121 	error_count += flow_control_analysis(tree_root);
   142 	error_count += flow_control_analysis(tree_root);
   122 	error_count += constant_folding(tree_root);
   143 	error_count += constant_folding(tree_root);
   123 	error_count += type_safety(tree_root);
   144 	error_count += type_safety(tree_root);
   124 	error_count += lvalue_check(tree_root);
   145 	error_count += lvalue_check(tree_root);
   125 	error_count += array_range_check(tree_root);
   146 	error_count += array_range_check(tree_root);
       
   147 	error_count += remove_forward_dependencies(tree_root, ordered_tree_root);
   126 	
   148 	
   127 	if (error_count > 0) {
   149 	if (error_count > 0) {
   128 		fprintf(stderr, "%d error(s) found. Bailing out!\n", error_count); 
   150 		fprintf(stderr, "%d error(s) found. Bailing out!\n", error_count); 
   129 		return -1;
   151 		return -1;
   130 	}
   152 	}