added new licence header
[libfirm] / ir / tr / typewalk.h
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  * Project:     libFIRM
22  * File name:   ir/tr/typewalk.h
23  * Purpose:     Traverse the type information.
24  * Author:      Goetz Lindenmaier
25  * Modified by:
26  * Created:
27  * CVS-ID:      $Id$
28  * Copyright:   (c) 1999-2003 Universität Karlsruhe
29  */
30
31 /**
32  * @file typewalk.h
33  *
34  * Traverse the type information.
35  *
36  * @author Goetz Lindenmaier
37  *
38  * The walker walks the whole ir graph
39  * to find the distinct type trees in the type graph forest.
40  * - execute the pre() function before recursion
41  * - execute the post() function after recursion
42  */
43
44 #ifndef _TYPEWALK_H_
45 #define _TYPEWALK_H_
46
47 #include "type.h"
48 #include "type_or_entity.h"
49
50 #include "irgraph.h"
51
52 /** Type of argument functions for type walkers.
53  *
54  * @param tore    points to the visited type or entity
55  * @param env     free environment pointer
56  */
57 typedef void type_walk_func(type_or_ent *tore, void *env);
58
59 /**  The class walk function
60  *
61  * @param clss    points to the visited class
62  * @param env     free environment pointer
63  */
64 typedef void class_walk_func(ir_type *clss, void *env);
65
66 /** Touches every type and entity in unspecified order.  If new
67  *  types/entities are created during the traversal these will
68  *  be visited, too.
69  *  Does not touch frame types or types for value params ... */
70 void type_walk(type_walk_func *pre, type_walk_func *post, void *env);
71
72 /** Walks over all type information reachable from an ir graph.
73  *
74  *  Walks over all type information reachable from irg, i.e., starts a
75  *  type walk at the irgs entity, the irgs frame type and all types and
76  *  entities that are attributes to firm nodes. */
77 void type_walk_irg(ir_graph *irg,
78            type_walk_func *pre,
79            type_walk_func *post,
80            void *env);
81
82 /**
83     Touches every class in specified order:
84     - first the super class
85     - second the class itself
86     - third the sub classes.  If new classes are created
87     during the traversal these will be visited, too.
88
89     @todo should be named class-walk
90
91     @deprecated will be removed?
92 */
93 void type_walk_super2sub(type_walk_func *pre,
94              type_walk_func *post,
95              void *env);
96
97 /** Walker for class types in inheritance order.
98  *
99  *  Touches every class in specified order:
100  *   - first the super class
101  *   - second the class itself
102  *   If new classes are created during the traversal these
103  *   will be visited, too.
104  * Starts the walk at arbitrary classes.
105  * Executes pre when first visiting a class.  Executes post after
106  * visiting all superclasses.
107  *
108  * The arguments pre, post, env may be NULL. */
109 void type_walk_super(type_walk_func *pre,
110              type_walk_func *post,
111              void *env);
112
113 /** Same as type_walk_super2sub, but visits only class types.
114    Executes pre for a class if all superclasses have been visited.
115    Then iterates to subclasses.  Executes post after return from
116    subclass.
117    Does not visit global type, frame types.
118
119    @bug ?? something is wrong with this.
120 */
121 void class_walk_super2sub(class_walk_func *pre,
122                           class_walk_func *post,
123                           void *env);
124
125 /**
126  * the entity walk function.  A function type for entity walkers.
127  *
128  * @param ent     points to the visited entity
129  * @param env     free environment pointer
130  */
131 typedef void entity_walk_func(ir_entity *ent, void *env);
132
133 /**
134  * Walks over all entities in the type.
135  *
136  * @param tp    the type
137  * @param doit  the entity walker function
138  * @param env   environment, will be passed to the walker function
139  */
140 void walk_types_entities(ir_type *tp,
141              entity_walk_func *doit,
142              void *env);
143
144 #endif /* _TYPEWALK_H_ */