32 * |
32 * |
33 */ |
33 */ |
34 |
34 |
35 #include "stage3.hh" |
35 #include "stage3.hh" |
36 |
36 |
|
37 #include "flow_control_analysis.hh" |
37 #include "fill_candidate_datatypes.hh" |
38 #include "fill_candidate_datatypes.hh" |
38 #include "narrow_candidate_datatypes.hh" |
39 #include "narrow_candidate_datatypes.hh" |
39 #include "print_datatypes_error.hh" |
40 #include "print_datatypes_error.hh" |
40 |
41 |
41 |
42 |
42 int type_safety(symbol_c *tree_root){ |
43 static int flow_control_analysis(symbol_c *tree_root){ |
|
44 flow_control_analysis_c flow_control_analysis(tree_root); |
|
45 tree_root->accept(flow_control_analysis); |
|
46 return 0; |
|
47 } |
|
48 |
|
49 /* Type safety analysis assumes that flow control analysis has already been completed, |
|
50 * so be sure to call flow_control_analysis() before calling this function |
|
51 */ |
|
52 static int type_safety(symbol_c *tree_root){ |
43 fill_candidate_datatypes_c fill_candidate_datatypes(tree_root); |
53 fill_candidate_datatypes_c fill_candidate_datatypes(tree_root); |
44 tree_root->accept(fill_candidate_datatypes); |
54 tree_root->accept(fill_candidate_datatypes); |
45 narrow_candidate_datatypes_c narrow_candidate_datatypes(tree_root); |
55 narrow_candidate_datatypes_c narrow_candidate_datatypes(tree_root); |
46 tree_root->accept(narrow_candidate_datatypes); |
56 tree_root->accept(narrow_candidate_datatypes); |
47 print_datatypes_error_c print_datatypes_error(tree_root); |
57 print_datatypes_error_c print_datatypes_error(tree_root); |
48 tree_root->accept(print_datatypes_error); |
58 tree_root->accept(print_datatypes_error); |
49 if (print_datatypes_error.get_error_found()) |
59 if (print_datatypes_error.get_error_found()) |
50 return -1; |
60 return -1; |
51 return 0; |
61 return 0; |
52 } |
62 } |
53 |
63 |
|
64 |
|
65 |
54 int stage3(symbol_c *tree_root){ |
66 int stage3(symbol_c *tree_root){ |
|
67 flow_control_analysis(tree_root); |
55 return type_safety(tree_root); |
68 return type_safety(tree_root); |
56 } |
69 } |