1 /* Web IDL AST interface 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_webidl_ast_h 10 #define nsgenbind_webidl_ast_h 11 12 enum webidl_node_type { 13 /* generic node types which define structure or attributes */ 14 WEBIDL_NODE_TYPE_ROOT = 0, 15 WEBIDL_NODE_TYPE_IDENT, 16 /** access modifier e.g. for attributes or types */ 17 WEBIDL_NODE_TYPE_MODIFIER, 18 /** a list of nodes (interface members, arguments) */ 19 WEBIDL_NODE_TYPE_LIST, 20 21 /* non structural node types */ 22 WEBIDL_NODE_TYPE_INTERFACE, /**< node is an interface*/ 23 WEBIDL_NODE_TYPE_INTERFACE_IMPLEMENTS, 24 25 WEBIDL_NODE_TYPE_ATTRIBUTE, 26 WEBIDL_NODE_TYPE_OPERATION, 27 WEBIDL_NODE_TYPE_CONST, 28 29 WEBIDL_NODE_TYPE_DICTIONARY, /**< node is a dictionary */ 30 31 WEBIDL_NODE_TYPE_INHERITANCE, /**< node has inheritance */ 32 WEBIDL_NODE_TYPE_SPECIAL, 33 WEBIDL_NODE_TYPE_ARGUMENT, 34 WEBIDL_NODE_TYPE_OPTIONAL, 35 WEBIDL_NODE_TYPE_ELLIPSIS, 36 WEBIDL_NODE_TYPE_TYPE, 37 WEBIDL_NODE_TYPE_TYPE_BASE, 38 WEBIDL_NODE_TYPE_TYPE_NULLABLE, 39 WEBIDL_NODE_TYPE_TYPE_ARRAY, 40 41 WEBIDL_NODE_TYPE_LITERAL_NULL, 42 WEBIDL_NODE_TYPE_LITERAL_INT, 43 WEBIDL_NODE_TYPE_LITERAL_BOOL, 44 WEBIDL_NODE_TYPE_LITERAL_FLOAT, 45 WEBIDL_NODE_TYPE_LITERAL_STRING, 46 47 WEBIDL_NODE_TYPE_EXTENDED_ATTRIBUTE, 48 49 }; 50 51 enum webidl_type { 52 WEBIDL_TYPE_ANY, /**< 0 - The type is unconstrained */ 53 WEBIDL_TYPE_USER, /**< 1 - The type is a dictionary or interface */ 54 WEBIDL_TYPE_BOOL, /**< 2 - The type is boolean */ 55 WEBIDL_TYPE_BYTE, /**< 3 - The type is a byte */ 56 WEBIDL_TYPE_OCTET, /**< 4 - The type is a octet */ 57 WEBIDL_TYPE_FLOAT, /**< 5 - The type is a float point number */ 58 WEBIDL_TYPE_DOUBLE, /**< 6 - The type is a double */ 59 WEBIDL_TYPE_SHORT, /**< 7 - The type is a signed 16bit */ 60 WEBIDL_TYPE_LONG, /**< 8 - The type is a signed 32bit */ 61 WEBIDL_TYPE_LONGLONG, /**< 9 - The type is a signed 64bit */ 62 WEBIDL_TYPE_STRING, /**< 10 - The type is a string */ 63 WEBIDL_TYPE_SEQUENCE, /**< 11 - The type is a sequence */ 64 WEBIDL_TYPE_OBJECT, /**< 12 - The type is a object */ 65 WEBIDL_TYPE_DATE, /**< 13 - The type is a date */ 66 WEBIDL_TYPE_VOID, /**< 14 - The type is void */ 67 }; 68 69 /** modifiers for operations, attributes and arguments */ 70 enum webidl_type_modifier { 71 WEBIDL_TYPE_MODIFIER_NONE, 72 WEBIDL_TYPE_MODIFIER_UNSIGNED, 73 WEBIDL_TYPE_MODIFIER_UNRESTRICTED, 74 WEBIDL_TYPE_MODIFIER_READONLY, 75 WEBIDL_TYPE_MODIFIER_STATIC, /**< operation or attribute is static */ 76 WEBIDL_TYPE_MODIFIER_INHERIT, /**< attribute inherits */ 77 }; 78 79 /* the type of special node */ 80 enum webidl_type_special { 81 WEBIDL_TYPE_SPECIAL_GETTER, 82 WEBIDL_TYPE_SPECIAL_SETTER, 83 WEBIDL_TYPE_SPECIAL_CREATOR, 84 WEBIDL_TYPE_SPECIAL_DELETER, 85 WEBIDL_TYPE_SPECIAL_LEGACYCALLER, 86 }; 87 88 struct webidl_node; 89 90 /** callback for search and iteration routines */ 91 typedef int (webidl_callback_t)(struct webidl_node *node, void *ctx); 92 93 int webidl_cmp_node_type(struct webidl_node *node, void *ctx); 94 95 /** 96 * create a new node with a pointer value 97 */ 98 struct webidl_node *webidl_node_new(enum webidl_node_type, struct webidl_node *l, void *r); 99 100 /** 101 * create a new node with an integer value 102 */ 103 struct webidl_node *webidl_new_number_node(enum webidl_node_type type, struct webidl_node *l, int number); 104 105 106 struct webidl_node *webidl_node_prepend(struct webidl_node *list, struct webidl_node *node); 107 struct webidl_node *webidl_node_append(struct webidl_node *list, struct webidl_node *node); 108 109 struct webidl_node *webidl_node_add(struct webidl_node *node, struct webidl_node *list); 110 111 /* node contents acessors */ 112 char *webidl_node_gettext(struct webidl_node *node); 113 struct webidl_node *webidl_node_getnode(struct webidl_node *node); 114 int *webidl_node_getint(struct webidl_node *node); 115 float *webidl_node_getfloat(struct webidl_node *node); 116 117 enum webidl_node_type webidl_node_gettype(struct webidl_node *node); 118 119 /* node searches */ 120 121 /** 122 * Iterate nodes children matching their type. 123 * 124 * For each child node where the type is matched the callback function is 125 * called with a context value. 126 */ 127 int webidl_node_for_each_type(struct webidl_node *node, 128 enum webidl_node_type type, 129 webidl_callback_t *cb, 130 void *ctx); 131 132 int webidl_node_enumerate_type(struct webidl_node *node, 133 enum webidl_node_type type); 134 135 struct webidl_node * 136 webidl_node_find(struct webidl_node *node, 137 struct webidl_node *prev, 138 webidl_callback_t *cb, 139 void *ctx); 140 141 struct webidl_node * 142 webidl_node_find_type(struct webidl_node *node, 143 struct webidl_node *prev, 144 enum webidl_node_type type); 145 146 struct webidl_node * 147 webidl_node_find_type_ident(struct webidl_node *root_node, 148 enum webidl_node_type type, 149 const char *ident); 150 151 152 153 /** 154 * parse web idl file into Abstract Syntax Tree 155 */ 156 int webidl_parsefile(char *filename, struct webidl_node **webidl_ast); 157 158 /** 159 * dump AST to file 160 */ 161 int webidl_dump_ast(struct webidl_node *node); 162 163 /** 164 * perform replacement of implements elements with copies of ast data 165 */ 166 int webidl_intercalate_implements(struct webidl_node *node); 167 168 /** 169 * formatted printf to allow webidl trace data to be written to file. 170 */ 171 int webidl_fprintf(FILE *stream, const char *format, ...); 172 173 /** 174 * get string of argument type 175 */ 176 const char *webidl_type_to_str(enum webidl_type_modifier m, enum webidl_type t); 177 178 #endif 179