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
|
/* binding file AST interface
*
* This file is part of nsnsgenbind.
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
*/
#ifndef nsgenbind_nsgenbind_ast_h
#define nsgenbind_nsgenbind_ast_h
enum genbind_node_type {
GENBIND_NODE_TYPE_ROOT = 0,
GENBIND_NODE_TYPE_IDENT, /**< generic identifier string */
GENBIND_NODE_TYPE_NAME, /**< generic type string */
GENBIND_NODE_TYPE_MODIFIER, /**< node modifier */
GENBIND_NODE_TYPE_CDATA, /**< verbatim block of character data */
GENBIND_NODE_TYPE_STRING, /**< text string */
GENBIND_NODE_TYPE_LINE, /**< linenumber */
GENBIND_NODE_TYPE_FILE, /**< file name */
GENBIND_NODE_TYPE_BINDING, /**< Binding */
GENBIND_NODE_TYPE_WEBIDL,
GENBIND_NODE_TYPE_CLASS, /**< class definition */
GENBIND_NODE_TYPE_PRIVATE,
GENBIND_NODE_TYPE_INTERNAL,
GENBIND_NODE_TYPE_PROPERTY,
GENBIND_NODE_TYPE_FLAGS,
GENBIND_NODE_TYPE_METHOD, /**< binding method */
GENBIND_NODE_TYPE_METHOD_TYPE, /**< binding method type */
GENBIND_NODE_TYPE_PARAMETER, /**< method parameter */
};
/* modifier flags */
enum genbind_type_modifier {
GENBIND_TYPE_NONE = 0,
GENBIND_TYPE_TYPE = 1, /**< identifies a type handler */
GENBIND_TYPE_UNSHARED = 2, /**< unshared item */
GENBIND_TYPE_TYPE_UNSHARED = 3, /**< identifies a unshared type handler */
};
/* binding method types */
enum genbind_method_type {
GENBIND_METHOD_TYPE_INIT = 0, /**< method is initialiser */
GENBIND_METHOD_TYPE_FINI, /**< method is finalizer */
GENBIND_METHOD_TYPE_METHOD, /**< method is a method */
GENBIND_METHOD_TYPE_GETTER, /**< method is a getter */
GENBIND_METHOD_TYPE_SETTER, /**< method is a setter */
GENBIND_METHOD_TYPE_PROTOTYPE, /**< method is a prototype */
GENBIND_METHOD_TYPE_PREFACE, /**< method is a preface */
GENBIND_METHOD_TYPE_PROLOGUE, /**< method is a prologue */
GENBIND_METHOD_TYPE_EPILOGUE, /**< method is a epilogue */
GENBIND_METHOD_TYPE_POSTFACE, /**< method is a postface */
};
struct genbind_node;
/** callback for search and iteration routines */
typedef int (genbind_callback_t)(struct genbind_node *node, void *ctx);
int genbind_fprintf(FILE *stream, const char *format, ...);
int genbind_cmp_node_type(struct genbind_node *node, void *ctx);
FILE *genbindopen(const char *filename);
int genbind_parsefile(char *infilename, struct genbind_node **ast);
char *genbind_strapp(char *a, char *b);
/**
* create a new node with value from pointer
*/
struct genbind_node *genbind_new_node(enum genbind_node_type type, struct genbind_node *l, void *r);
/**
* create a new number node
*
* Create a node with of number type
*/
struct genbind_node *genbind_new_number_node(enum genbind_node_type type, struct genbind_node *l, int number);
struct genbind_node *genbind_node_link(struct genbind_node *tgt, struct genbind_node *src);
struct genbind_node *genbind_node_prepend(struct genbind_node *list, struct genbind_node *inst);
struct genbind_node *genbind_node_add(struct genbind_node *node, struct genbind_node *list);
/**
* Dump the binding AST to file
*
* If the debug flag has been set this causes the binding AST to be written to
* a binding-ast output file
*
* \param node Node of the tree to start dumping from (usually tree root)
* \return 0 on sucess or non zero on faliure and error message printed.
*/
int genbind_dump_ast(struct genbind_node *node);
/**
*Depth first left hand search using user provided comparison
*
* @param node The node to start the search from
* @param prev The node at which to stop the search, either NULL to
* search the full tree depth (initial search) or the result
* of a previous search to continue.
* @param cb Comparison callback
* @param ctx Context for callback
*/
struct genbind_node *
genbind_node_find(struct genbind_node *node,
struct genbind_node *prev,
genbind_callback_t *cb,
void *ctx);
/**
* Depth first left hand search returning nodes of the specified type
*
* @param node The node to start the search from
* @param prev The node at which to stop the search, either NULL to
* search the full tree depth (initial search) or the result
* of a previous search to continue.
* @param nodetype The type of node to seach for
* @return The found node or NULL for no nodes.
*/
struct genbind_node *
genbind_node_find_type(struct genbind_node *node,
struct genbind_node *prev,
enum genbind_node_type nodetype);
/**
* count how many nodes of a specified type.
*
* Enumerate how many nodes of the specified type there are by
* performing a depth first search for nodes of the given type and
* counting the number of results.
*
* @param node The node to start the search from
* @param nodetype The type of node to count
* @return The number of nodes found.
*/
int
genbind_node_enumerate_type(struct genbind_node *node,
enum genbind_node_type type);
/**
* Depth first left hand search returning nodes of the specified type
* with an ident child node with matching text
*
* @param node The node to start the search from
* @param prev The node at which to stop the search, either NULL to
* search the full tree depth (initial search) or the result
* of a previous search to continue.
* @param nodetype The type of node to seach for
* @param ident The text to match the ident child node to
*/
struct genbind_node *
genbind_node_find_type_ident(struct genbind_node *node,
struct genbind_node *prev,
enum genbind_node_type nodetype,
const char *ident);
/**
* Find a method node of a given method type
*
* \param node A node of type GENBIND_NODE_TYPE_CLASS to search for methods.
* \param prev The node at which to stop the search, either NULL to
* search the full tree depth (initial search) or the result
* of a previous search to continue.
* \param methodtype The type of method to find.
* \return A node of type GENBIND_NODE_TYPE_METHOD on success or NULL on faliure
*/
struct genbind_node *
genbind_node_find_method(struct genbind_node *node,
struct genbind_node *prev,
enum genbind_method_type methodtype);
/**
* Find a method node of a given method type and identifier
*
* \param node A node of type GENBIND_NODE_TYPE_CLASS to search for methods.
* \param prev The node at which to stop the search, either NULL to
* search the full tree depth (initial search) or the result
* of a previous search to continue.
* \param methodtype The type of method to find.
* \param ident The identifier to search for
* \return A node of type GENBIND_NODE_TYPE_METHOD on success or NULL on faliure
*/
struct genbind_node *
genbind_node_find_method_ident(struct genbind_node *node,
struct genbind_node *prev,
enum genbind_method_type methodtype,
const char *ident);
/**
* Iterate all nodes of a certian type from a node with a callback.
*
* Depth first search for nodes of the given type calling the callback
* with context.
*
* @param node The node to start the search from.
*/
int genbind_node_foreach_type(struct genbind_node *node,
enum genbind_node_type type,
genbind_callback_t *cb,
void *ctx);
/** get a nodes node list content
*
* @param node The nodes to get node list from
* @return pointer to the node list or NULL if the node does not contain a list
*/
struct genbind_node *genbind_node_getnode(struct genbind_node *node);
/** get a nodes text content
*
* @param node The nodes to get text from
* @return pointer to the node text or NULL if the node is not of type
* text or is empty.
*/
char *genbind_node_gettext(struct genbind_node *node);
/** get a nodes integer value
*
* @param node The nodes to get integer from
* @return pointer to the node value or NULL if the node is not of type
* int or is empty.
*/
int *genbind_node_getint(struct genbind_node *node);
#endif
|