1 /* intermediate representation of WebIDL and binding data 2 * 3 * This file is part of nsgenbind. 4 * Licensed under the MIT License, 5 * http://www.opensource.org/licenses/mit-license.php 6 * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> 7 */ 8 9 #ifndef nsgenbind_ir_h 10 #define nsgenbind_ir_h 11 12 struct genbind_node; 13 struct webidl_node; 14 15 /** 16 * map entry for each argument of an overload on an operation 17 */ 18 struct ir_operation_argument_entry { 19 const char *name; 20 21 int optionalc; /**< 1 if the argument is optional */ 22 int elipsisc; /**< 1 if the argument is an elipsis */ 23 24 struct webidl_node *node; 25 }; 26 27 /** 28 * map entry for each overload of an operation. 29 */ 30 struct ir_operation_overload_entry { 31 struct webidl_node *type; /**< The return type of this overload */ 32 33 int optionalc; /**< Number of parameters that are optional */ 34 int elipsisc; /**< Number of elipsis parameters */ 35 36 int argumentc; /**< the number of parameters */ 37 struct ir_operation_argument_entry *argumentv; 38 }; 39 40 /** map entry for operations on an interface */ 41 struct ir_operation_entry { 42 const char *name; /** operation name */ 43 struct webidl_node *node; /**< AST operation node */ 44 struct genbind_node *method; /**< method from binding */ 45 46 int overloadc; /**< Number of overloads of this operation */ 47 struct ir_operation_overload_entry *overloadv; 48 }; 49 50 /** 51 * ir entry for type of attributes or arguments. 52 */ 53 struct ir_type_entry { 54 enum webidl_type base; /**< base of the type (long, short, user etc.) */ 55 enum webidl_type_modifier modifier; /**< modifier for the type */ 56 bool nullable; /**< the type is nullable */ 57 const char *name; /**< name of type for user types */ 58 }; 59 60 /** 61 * ir entry for attributes on an interface 62 */ 63 struct ir_attribute_entry { 64 const char *name; /**< attribute name */ 65 struct webidl_node *node; /**< AST attribute node */ 66 67 int typec; /**< number of types for attribute */ 68 struct ir_type_entry *typev; /**< types on attribute */ 69 70 enum webidl_type_modifier modifier; /**< modifier for the attribute intself */ 71 const char *putforwards; /**< putforwards attribute */ 72 const char *treatnullas; /**< treatnullas attribute */ 73 74 struct genbind_node *getter; /**< getter from binding */ 75 struct genbind_node *setter; /**< getter from binding */ 76 77 char *property_name; /**< the attribute name converted to output 78 * appropriate value. e.g. generators targetting c 79 * might lowercase the name or add underscores 80 * instead of caps 81 */ 82 }; 83 84 /** 85 * map entry for constants on an interface 86 */ 87 struct ir_constant_entry { 88 const char *name; /** attribute name */ 89 struct webidl_node *node; /**< AST constant node */ 90 }; 91 92 93 /** map entry for an interface */ 94 struct ir_interface_entry { 95 bool noobject; /**< flag indicating if no interface object should eb 96 * generated. This allows for interfaces which do not 97 * generate code. For implements (mixin) interfaces 98 */ 99 bool primary_global; /**< flag indicating the interface is the primary 100 * global javascript object. 101 */ 102 103 int operationc; /**< number of operations on interface */ 104 struct ir_operation_entry *operationv; 105 106 int attributec; /**< number of attributes on interface */ 107 struct ir_attribute_entry *attributev; 108 109 int constantc; /**< number of constants on interface */ 110 struct ir_constant_entry *constantv; 111 }; 112 113 /** 114 * map entry for a dictionary 115 */ 116 struct ir_dictionary_entry { 117 int memberc; /**< the number of members */ 118 struct ir_operation_argument_entry *memberv; 119 }; 120 121 enum ir_entry_type { 122 IR_ENTRY_TYPE_INTERFACE, 123 IR_ENTRY_TYPE_DICTIONARY, 124 }; 125 126 enum ir_init_argtype { 127 IR_INIT_ARG_POINTER, 128 IR_INIT_ARG_UNSIGNED, 129 IR_INIT_ARG_INT, 130 IR_INIT_ARG_BOOL, 131 }; 132 133 /** top level entry info common to interfaces and dictionaries */ 134 struct ir_entry { 135 const char *name; /** IDL name */ 136 struct webidl_node *node; /**< AST node */ 137 const char *inherit_name; /**< Name of interface inhertited from */ 138 struct genbind_node *class; /**< class from binding (if any) */ 139 140 enum ir_entry_type type; 141 union { 142 struct ir_dictionary_entry dictionary; 143 struct ir_interface_entry interface; 144 } u; 145 146 int inherit_idx; /**< index into map of inherited interface or -1 for 147 * not in map 148 */ 149 int refcount; /**< number of interfacess in map that refer to this 150 * interface 151 */ 152 153 /* The variables are created and used by the output generation but 154 * rather than have another allocation and pointer the data they are 155 * just inline here. 156 */ 157 158 char *filename; /**< filename used for output */ 159 160 char *class_name; /**< the interface name converted to output 161 * appropriate value. e.g. generators targetting c 162 * might lowercase the name or add underscores 163 * instead of caps 164 */ 165 int class_init_argc; /**< The number of parameters on the class 166 * initializer. 167 */ 168 enum ir_init_argtype *class_init_argt; /**< The types of the initialiser parameters */ 169 }; 170 171 /** intermediate representation of WebIDL and binding data */ 172 struct ir { 173 int entryc; /**< count of entries */ 174 struct ir_entry *entries; /**< interface entries */ 175 176 /** The AST node of the binding information */ 177 struct genbind_node *binding_node; 178 179 /** Root AST node of the webIDL */ 180 struct webidl_node *webidl; 181 }; 182 183 /** 184 * Create a new interface map 185 */ 186 int ir_new(struct genbind_node *genbind, 187 struct webidl_node *webidl, 188 struct ir **map_out); 189 190 int ir_dump(struct ir *map); 191 192 int ir_dumpdot(struct ir *map); 193 194 /** 195 * interface map parent entry 196 * 197 * \return inherit entry or NULL if there is not one 198 */ 199 struct ir_entry *ir_inherit_entry(struct ir *map, struct ir_entry *entry); 200 201 #endif 202