fixed svn properties
[libfirm] / ir / tr / type_finalization.c
1 /*
2  * Copyright (C) 1995-2007 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  * @version $Id$
26  */
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "typerep.h"
32 #include "irprog_t.h"
33 #include "irflag_t.h"
34 #include "entity_t.h"
35 #include "debug.h"
36
37 DEBUG_ONLY(static firm_dbg_module_t *dbg;)
38
39 static void do_finalization(type_or_ent *tore, void *env) {
40         ir_type *glob_tp = env;
41
42         if (is_type(tore)) {
43                 ir_type *cls = (ir_type *)tore;
44
45                 if (! is_Class_type(cls) || cls == glob_tp)
46                         return;
47
48                 if (is_class_final(cls))
49                         return;
50                 if (get_class_n_subtypes(cls) == 0) {
51                         /* Note that we set the final property even for the
52                            frame/tls types this way. Should not made any problems. */
53                         set_class_final(cls, 1);
54                         DB((dbg, LEVEL_1, " made final Class %s\n",
55                                 get_type_name(cls)));
56                 }
57         } else {
58                 ir_entity *ent = (ir_entity *)tore;
59                 ir_type *owner;
60
61                 if (is_entity_final(ent))
62                         return;
63
64                 owner = get_entity_owner(ent);
65                 /* beware of array entities */
66                 if (! is_Class_type(owner) || owner == glob_tp)
67                         return;
68
69                 if (is_class_final(owner)) {
70                         assert(get_entity_n_overwrittenby(ent) == 0);
71                         set_entity_final(ent, 1);
72                         DB((dbg, LEVEL_1, " made final %s::%s\n",
73                                 get_type_name(owner), get_entity_name(ent)));
74                 } else if (get_entity_n_overwrittenby(ent) == 0) {
75                         set_entity_final(ent, 1);
76                         DB((dbg, LEVEL_1, " made final %s::%s\n",
77                                 get_type_name(owner), get_entity_name(ent)));
78                 }
79         }
80 }  /* do_finalization */
81
82 /**
83  * If we have the closed world assumption, we can calculate the
84  * finalization of classes and entities by inspecting the class hierarchy.
85  * After this is done, all classes and entities that are not overridden
86  * anymore have the final property set.
87  */
88 void types_calc_finalization(void) {
89         if (! get_opt_closed_world())
90                 return;
91
92         FIRM_DBG_REGISTER(dbg, "firm.tr.finalization");
93 //      firm_dbg_set_mask(dbg, SET_LEVEL_1);
94
95         /* types must be visited before it's entities */
96         type_walk(do_finalization, NULL, get_glob_type());
97 }