summaryrefslogtreecommitdiff
path: root/plugins/itanium/component.h
blob: a20272a565691dd73634a2bedfb28c1386614247 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

/* Chrysalide - Outil d'analyse de fichiers binaires
 * component.h - prototypes pour la représentation des composants extraits de l'ABI C++ Itanium
 *
 * Copyright (C) 2013-2017 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  Chrysalide is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Chrysalide is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Chrysalide.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef _PLUGINS_ITANIUM_COMPONENT_H
#define _PLUGINS_ITANIUM_COMPONENT_H


#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <sys/types.h>


#include <analysis/routine.h>
#include <analysis/type.h>



/* Type de composants */
typedef enum _ItaniumComponentType
{
    /**
     * Chaîne de caractère, terminée par un octet nul.
     */
    ICT_NAME,

    /**
     * Nom avec préfixe standard.
     * Le nom en question est placé dans le champ unary.
     */
    ICT_STD_UNSCOPED_NAME,

    /**
     * Noms imbriqués, en deux parties : 'binary'.
     * En cas de préfixe nul, le composant gauche peut être nul.
     */
    ICT_NESTED_NAME,

    /**
     * Noms imbriqués, en deux parties : 'binary'.
     * C'est normalement le seul réceptacle pour les composants issus
     * de itd_template_args (sur la branche droite).
     */
    ICT_TEMPLATE_NAME_ARGS,

    /**
     * Type avec préfixes : deux éléments, dans 'binary'
     */
    ICT_PREFIX_BINARY,

    /**
     * Préfixes à deux éléments.
     * En cas de préfixe nul, le composant gauche peut être nul.
     */
    ICT_TPREFIX_BINARY,

    /**
     * Encodage d'un nom d'opérateur, consigné dans 'operator'.
     */
    ICT_OPERATOR_NAME,

    /**
     * Particularité des notions d'objets. Les informations utiles
     * sont rassemblées dans le champ unary.
     */
    ICT_SPECIAL_NAME_VTABLE,
    ICT_SPECIAL_NAME_VSTRUCT,

    /**
     * Fonctions virtuelles.
     *  -> décalage : 'offset'.
     *  -> double décalage : 'binary'.
     *  -> fonctions simples : 'binary'.
     *  -> fonctions complexes : 'ternary'.
     */
    ICT_NON_VIRTUAL_OFFSET,
    ICT_VIRTUAL_OFFSET,
    ICT_DOUBLE_OFFSET,
    ICT_FUNCTION_THUNK,
    ICT_FUNCTION_COVARIANT_THUNK,

    /**
     * Constructeur ou destructeur, sans plus de détail.
     */
    ICT_CONSTRUCTOR,
    ICT_DESSTRUCTOR,

    /**
     * Type instanciable dans le programme.
     */
    ICT_TYPE,

    /**
     * Simple distinction de ICT_TYPE, pour la distinction lors des candidatures
     * aux substitutions.
     */
    ICT_VENDOR_TYPE,

    /**
     * Type qualifié ; les infos utilies sont explicitement
     * conservées dans le champ qualified.
     */
    ICT_QUALIFIED_TYPE,

    /**
     * Différentes références vers un sous-type.
     * Le champ impacté est 'unary'.
     */
    ICT_POINTER_TO,
    ICT_REFERENCE_TO,
    ICT_RVALUE_REFERENCE_TO,
    ICT_COMPLEX_PAIR,
    ICT_IMAGINARY,

    /**
     * Prototype de fonction.
     * Le champ impacté est 'function'.
     */
    ICT_FUNCTION_TYPE,

    /**
     * Fonction (nom + retour/paramètres), sous forme binaire :
     *  -> left = function name
     *  -> right = bare-function-type
     */
    ICT_FUNCTION_ENCODING,

    /**
     * Définition d'un tableau. Les indications de dimensions peuvent
     * prendre plusieurs formes, et sont rassemblées dans le champ array.
     */
    ICT_ARRAY,

    /**
     * Pointeur vers un membre. Comme l'espace de noms associé est encodé
     * de façon spéciale, un champ est dédié à ce composant : pmember.
     */
    ICT_POINTER_TO_MEMBER,

    /**
     * Argument de template. Utile pour les candidatures aux substitutions.
     * 'unary' renvoie vers le composant utile.
     */
    ICT_TEMPLATE_PARAM,

    /**
     * Liste d'arguments pour templates, à encadrer par des chevrons.
     * 'unary' pointe vers la liste des éléments.
     */
    ICT_TEMPLATE_ARGS,

    /**
     * Liste de types, sous forme binaire :
     *  -> left = élément de la liste de types.
     *  -> right = reste de la liste de types.
     */
    ICT_TYPES_LIST,

    /**
     * Liste d'expressions, sous forme binaire comme pour ICT_TYPES_LIST :
     *  -> left = élément de la liste de types.
     *  -> right = reste de la liste de types.
     */
    ICT_EXPR_LIST,

    /**
     * Liste de types, sous forme binaire :
     *  -> left = composant d'opérateur.
     *  -> right = liste d'expressions.
     */
    ICT_OPERATED_EXPRESSION,

    /**
     * Substitution avec préfixe standard. Le résultat est prêt dans le champ
     * dtype.
     */
    ICT_STD_SUBST,

    ICT_COUNT

} ItaniumComponentType;


/* Catégories d'opérateurs */
typedef enum _ItaniumOperatorType
{
    IOT_SIMPLE,                             /* Présent dans la liste       */
    IOT_CAST,                               /* Conversion forcée           */
    IOT_VENDOR                              /* Défini par un vendeur       */

} ItaniumOperatorType;


/* Enregistrement des opérateurs */
typedef struct _itanium_operator_info
{
    const char *code;                       /* Nom encodé                  */
    const char *name;                       /* Désignation humaine         */
    size_t name_len;                        /* Taille du nom humain        */
    int args;                               /* Nombre d'arguments          */

} itanium_operator_info;


/* Composant extrait de l'encodage */
typedef struct _itanium_component itanium_component;



/* Incrémente le nombre d'utilisation du composant. */
void itd_ref_comp(itanium_component *);

/* Décrémente le nombre d'utilisation du composant. */
void itd_unref_comp(itanium_component *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_with_type(ItaniumComponentType);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_name(const char *, size_t);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_operator(const itanium_operator_info *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_cast_operator(itanium_component *);

/* Donne des indications quant à un opérateur Itanium. */
const void *itd_get_operator_info(const itanium_component *, ItaniumOperatorType *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_offset(ItaniumComponentType, ssize_t);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_type(GDataType *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_qualified_type(itanium_component *, TypeQualifier);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_function_type(bool, itanium_component *);

/* Indique si une fonction est externalisée en C. */
bool itd_is_external_function(const itanium_component *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_array_with_dim_number(ssize_t, itanium_component *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_array_with_dim_expr(itanium_component *, itanium_component *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_pointer_to_memeber_type(itanium_component *, itanium_component *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_unary(ItaniumComponentType, itanium_component *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_binary(ItaniumComponentType, itanium_component *, itanium_component *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_append_right_to_binary(ItaniumComponentType, itanium_component *, itanium_component *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_ternary(ItaniumComponentType, itanium_component *, itanium_component *, itanium_component *);

/* Modifie légèrement le type d'un composant donné. */
void itd_set_type(itanium_component *, ItaniumComponentType);

/* Fournit le type d'un composant issu d'un contexte Itanium. */
ItaniumComponentType itd_get_component_type(const itanium_component *);

/* Traduit les composants de contexte Itanium. */
char *itd_translate_component(const itanium_component *, char *);

/* Traduit les composants de contexte Itanium en type. */
GDataType *itd_translate_component_to_type(const itanium_component *);

/* Traduit les composants de contexte Itanium en routine. */
GBinRoutine *itd_translate_component_to_routine(const itanium_component *);



#endif  /* _PLUGINS_ITANIUM_COMPONENT_H */