Add wrapper macros for pset_first() and pset_next(), which have the return type as...
[libfirm] / ir / tr / type_finalization.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file    type_finalization.c
22  * @brief   Calculate finalization of classes and entities by
23  *          inspecting the class hierarchy.
24  * @author  Michael Beck
25  */
26 #include "config.h"
27
28 #include "typerep.h"
29 #include "irprog_t.h"
30 #include "irflag_t.h"
31 #include "entity_t.h"
32 #include "debug.h"
33
34 DEBUG_ONLY(static firm_dbg_module_t *dbg;)
35
36 static void do_finalization(type_or_ent tore, void *env)
37 {
38         ir_type *glob_tp = (ir_type*)env;
39
40         if (is_type(tore.typ)) {
41                 ir_type *cls = tore.typ;
42
43                 if (! is_Class_type(cls) || cls == glob_tp)
44                         return;
45
46                 if (is_class_final(cls))
47                         return;
48                 if (get_class_n_subtypes(cls) == 0) {
49                         /* Note that we set the final property even for the
50                            frame/global types this way. Should not made any problems. */
51                         set_class_final(cls, 1);
52                         DB((dbg, LEVEL_1, " made final Class %s\n",
53                                 get_class_name(cls)));
54                 }
55         } else {
56                 ir_entity *ent = tore.ent;
57                 ir_type *owner;
58
59                 if (is_entity_final(ent))
60                         return;
61
62                 owner = get_entity_owner(ent);
63                 /* beware of array entities */
64                 if (! is_Class_type(owner) || owner == glob_tp)
65                         return;
66
67                 if (is_class_final(owner)) {
68                         assert(get_entity_n_overwrittenby(ent) == 0);
69                         set_entity_final(ent, 1);
70                         DB((dbg, LEVEL_1, " made final %s::%s\n",
71                                 get_compound_name(owner), get_entity_name(ent)));
72                 } else if (get_entity_n_overwrittenby(ent) == 0) {
73                         set_entity_final(ent, 1);
74                         DB((dbg, LEVEL_1, " made final %s::%s\n",
75                                 get_compound_name(owner), get_entity_name(ent)));
76                 }
77         }
78 }
79
80 void types_calc_finalization(void)
81 {
82         if (! get_opt_closed_world())
83                 return;
84
85         FIRM_DBG_REGISTER(dbg, "firm.tr.finalization");
86
87         /* types must be visited before their entities */
88         type_walk(do_finalization, NULL, get_glob_type());
89 }