summaryrefslogtreecommitdiff
path: root/src/format/mangling/dex/type_gram.y
blob: 1176bd298ef8d866073dd36fc7838aabd9aa2176 (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

%{

#include <stdbool.h>


#include "context.h"
#include "../context-int.h"



/* Affiche un message d'erreur concernant l'analyse. */
static int type_error(GDexDemangler *, char *);

/* Procède au décodage d'une chaîne de caractères. */
bool demangle_dex_type(GDexDemangler *, const char *);


%}


%code requires {

#include "../../../analysis/types/basic.h"
#include "../../../analysis/types/cse.h"

}

%union {

    GDataType *type;                        /* Type reconstruit            */
    size_t adeep;                           /* Dimension d'un tableau      */
    char *text;                             /* Chaîne de caractères        */

}


%parse-param { GDexDemangler *demangler }

%token V Z B S C I J F D
%token ARRAY
%token L SEMICOLON
%token SLASH DOLLAR
%token TEXT

%type <type> type_descriptor field_type_descriptor non_array_field_type_descriptor full_class_name

%type <text> TEXT


%{

/* Déclarations issues de l'analyseur syntaxique... */

typedef struct yy_buffer_state *YY_BUFFER_STATE;

extern YY_BUFFER_STATE type__scan_string(const char *);
extern void type__delete_buffer(YY_BUFFER_STATE);
extern int type_lex(void);

%}


%%


input:
    type_descriptor                     { G_DEMANGLING_CONTEXT(demangler)->type = $1; }

type_descriptor:
    V                                   { $$ = g_basic_type_new(BTP_VOID); }
    | field_type_descriptor             { $$ = $1; }

field_type_descriptor:
	non_array_field_type_descriptor             { $$ = $1; }
	| ARRAY non_array_field_type_descriptor     { $$ = $2; }

non_array_field_type_descriptor:
	Z                                   { $$ = g_basic_type_new(BTP_BOOL); }
	| B                                 { $$ = g_basic_type_new(BTP_UCHAR); }
	| S                                 { $$ = g_basic_type_new(BTP_SHORT); }
	| C                                 { $$ = g_basic_type_new(BTP_CHAR); }
	| I                                 { $$ = g_basic_type_new(BTP_INT); }
	| J                                 { $$ = g_basic_type_new(BTP_LONG); }
	| F                                 { $$ = g_basic_type_new(BTP_FLOAT); }
	| D                                 { $$ = g_basic_type_new(BTP_DOUBLE); }
	| L full_class_name SEMICOLON       { $$ = $2; }

full_class_name:
    TEXT                                { $$ = g_class_enum_type_new(CET_CLASS, $1); }
    | full_class_name SLASH TEXT        {
                                            $$ = g_class_enum_type_new(CET_CLASS, $3);
                                            g_data_type_set_namespace($$, $1);
                                            g_object_unref($1);
                                        }
    | full_class_name DOLLAR TEXT       {
                                            $$ = g_class_enum_type_new(CET_CLASS, $3);
                                            g_data_type_set_namespace($$, $1);
                                            g_object_unref($1);
                                        }


%%


/******************************************************************************
*                                                                             *
*  Paramètres  : demangler = contexte associé à la procédure de décodage.     *
*                msg       = indications humaines sur l'événement.            *
*                                                                             *
*  Description : Affiche un message d'erreur concernant l'analyse.            *
*                                                                             *
*  Retour      : Valeur historique, ignorée.                                  *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/
static int type_error(GDexDemangler *demangler, char *msg)
{
	return -1;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : demangler = contexte de décodage à utiliser.                 *
*                desc      = chaîne de caractères à décoder.                  *
*                                                                             *
*  Description : Procède au décodage d'une chaîne de caractères.              *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool demangle_dex_type(GDexDemangler *demangler, const char *desc)
{
	YY_BUFFER_STATE buffer;                 /* Tampon pour bison           */
	int ret;                                /* Bilan de l'appel            */

	buffer = type__scan_string(desc);
	ret = yyparse(demangler);
	type__delete_buffer(buffer);

    return (ret == 0);

}