summaryrefslogtreecommitdiff
path: root/src/ir.h
blob: ecedc95ced03b59b560e781a3e341c052ae1a8d6 (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
/* intermediate representation of WebIDL and binding data
 *
 * This file is part of nsgenbind.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
 */

#ifndef nsgenbind_ir_h
#define nsgenbind_ir_h

struct genbind_node;
struct webidl_node;

/**
 * map entry for each argument of an overload on an operation
 */
struct ir_operation_argument_entry {
        const char *name;

        int optionalc; /**< 1 if the argument is optional */
        int elipsisc; /**< 1 if the argument is an elipsis */

        struct webidl_node *node;
};

/**
 * map entry for each overload of an operation.
 */
struct ir_operation_overload_entry {
        struct webidl_node *type; /**< The return type of this overload */

        int optionalc; /**< Number of parameters that are optional */
        int elipsisc; /**< Number of elipsis parameters */

        int argumentc; /**< the number of parameters */
        struct ir_operation_argument_entry *argumentv;
};

/** map entry for operations on an interface */
struct ir_operation_entry {
        const char *name; /** operation name */
        struct webidl_node *node; /**< AST operation node */
        struct genbind_node *method; /**< method from binding */

        int overloadc; /**< Number of overloads of this operation */
        struct ir_operation_overload_entry *overloadv;
};

/** map entry for attributes on an interface */
struct ir_attribute_entry {
        const char *name; /** attribute name */
        struct webidl_node *node; /**< AST attribute node */

        enum webidl_type_modifier modifier;
        const char *putforwards;

        struct genbind_node *getter; /**< getter from binding */
        struct genbind_node *setter; /**< getter from binding */
};

/** map entry for constants on an interface */
struct ir_constant_entry {
        const char *name; /** attribute name */
        struct webidl_node *node; /**< AST constant node */
};


/** map entry for an interface */
struct ir_interface_entry {
        bool noobject; /**< flag indicating if no interface object should eb
                        * generated. This allows for interfaces which do not
                        * generate code. For implements (mixin) interfaces
                        */
        bool primary_global; /**< flag indicating the interface is the primary
                             * global javascript object.
                             */

        int operationc; /**< number of operations on interface */
        struct ir_operation_entry *operationv;

        int attributec; /**< number of attributes on interface */
        struct ir_attribute_entry *attributev;

        int constantc; /**< number of constants on interface */
        struct ir_constant_entry *constantv;
};

/**
 * map entry for a dictionary
 */
struct ir_dictionary_entry {
        int memberc; /**< the number of members */
        struct ir_operation_argument_entry *memberv;
};

enum ir_entry_type {
        IR_ENTRY_TYPE_INTERFACE,
        IR_ENTRY_TYPE_DICTIONARY,
};

/** top level entry info common to interfaces and dictionaries */
struct ir_entry {
        const char *name; /** dictionary name */
        struct webidl_node *node; /**< AST dictionary node */
        const char *inherit_name; /**< Name of interface inhertited from */
        struct genbind_node *class; /**< class from binding (if any) */

        enum ir_entry_type type;
        union {
                struct ir_dictionary_entry dictionary;
                struct ir_interface_entry interface;
        } u;

        int inherit_idx; /**< index into map of inherited interface or -1 for
			  * not in map
			  */
	int refcount; /**< number of interfacess in map that refer to this
		       * interface
		       */

        /* The variables are created and used by the output generation but
         * rather than have another allocation and pointer the data they are
         * just inline here.
         */

        char *filename; /**< filename used for output */

        char *class_name; /**< the interface name converted to output
                           * appropriate value. e.g. generators targetting c
                           * might lowercase the name or add underscores
                           * instead of caps
                           */
        int class_init_argc; /**< The number of parameters on the class
                              * initializer.
                              */
};

/** intermediate representation of WebIDL and binding data */
struct ir {
        int entryc; /**< count of entries */
        struct ir_entry *entries; /**< interface entries */

        /** The AST node of the binding information */
        struct genbind_node *binding_node;

        /** Root AST node of the webIDL */
        struct webidl_node *webidl;
};

/**
 * Create a new interface map
 */
int ir_new(struct genbind_node *genbind,
                      struct webidl_node *webidl,
                      struct ir **map_out);

int ir_dump(struct ir *map);

int ir_dumpdot(struct ir *map);

/**
 * interface map parent entry
 *
 * \return inherit entry or NULL if there is not one
 */
struct ir_entry *ir_inherit_entry(struct ir *map, struct ir_entry *entry);

#endif