2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
21 * @file type_finalization.c
22 * @brief Calculate finalization of classes and entities by
23 * inspecting the class hierarchy.
24 * @author Michael Beck
35 DEBUG_ONLY(static firm_dbg_module_t *dbg;)
37 static void do_finalization(type_or_ent tore, void *env)
39 ir_type *glob_tp = (ir_type*)env;
41 if (is_type(tore.typ)) {
42 ir_type *cls = tore.typ;
44 if (! is_Class_type(cls) || cls == glob_tp)
47 if (is_class_final(cls))
49 if (get_class_n_subtypes(cls) == 0) {
50 /* Note that we set the final property even for the
51 frame/global types this way. Should not made any problems. */
52 set_class_final(cls, 1);
53 DB((dbg, LEVEL_1, " made final Class %s\n",
54 get_class_name(cls)));
57 ir_entity *ent = tore.ent;
60 if (is_entity_final(ent))
63 owner = get_entity_owner(ent);
64 /* beware of array entities */
65 if (! is_Class_type(owner) || owner == glob_tp)
68 if (is_class_final(owner)) {
69 assert(get_entity_n_overwrittenby(ent) == 0);
70 set_entity_final(ent, 1);
71 DB((dbg, LEVEL_1, " made final %s::%s\n",
72 get_compound_name(owner), get_entity_name(ent)));
73 } else if (get_entity_n_overwrittenby(ent) == 0) {
74 set_entity_final(ent, 1);
75 DB((dbg, LEVEL_1, " made final %s::%s\n",
76 get_compound_name(owner), get_entity_name(ent)));
79 } /* do_finalization */
82 * If we have the closed world assumption, we can calculate the
83 * finalization of classes and entities by inspecting the class hierarchy.
84 * After this is done, all classes and entities that are not overridden
85 * anymore have the final property set.
87 void types_calc_finalization(void)
89 if (! get_opt_closed_world())
92 FIRM_DBG_REGISTER(dbg, "firm.tr.finalization");
94 /* types must be visited before it's entities */
95 type_walk(do_finalization, NULL, get_glob_type());