summaryrefslogtreecommitdiff
path: root/src/nsgenbind-ast.h
blob: d59aeba0e933f328546d9e92be722e7b10b0fcce (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
/* 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_TYPE, /**< generic type string */
	GENBIND_NODE_TYPE_MODIFIER, /**< node modifier */

	GENBIND_NODE_TYPE_CBLOCK,
	GENBIND_NODE_TYPE_WEBIDLFILE,
	GENBIND_NODE_TYPE_HDRCOMMENT,
	GENBIND_NODE_TYPE_STRING,
	GENBIND_NODE_TYPE_PREAMBLE,
	GENBIND_NODE_TYPE_PROLOGUE,
	GENBIND_NODE_TYPE_EPILOGUE,
	GENBIND_NODE_TYPE_BINDING,
	GENBIND_NODE_TYPE_BINDING_PRIVATE,
	GENBIND_NODE_TYPE_BINDING_INTERNAL,
	GENBIND_NODE_TYPE_BINDING_INTERFACE,
	GENBIND_NODE_TYPE_BINDING_INTERFACE_FLAGS,
	GENBIND_NODE_TYPE_BINDING_PROPERTY,
	GENBIND_NODE_TYPE_API,
	GENBIND_NODE_TYPE_OPERATION,
	GENBIND_NODE_TYPE_GETTER,
	GENBIND_NODE_TYPE_SETTER,
};

/* 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 */
};

/* interface flags */
enum genbind_interface_flags {
	GENBIND_INTERFACE_FLAG_NONE = 0,
	GENBIND_INTERFACE_FLAG_GLOBAL = 1, /**< interface is global */
};

struct genbind_node;

/** callback for search and iteration routines */
typedef int (genbind_callback_t)(struct genbind_node *node, void *ctx);

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);

struct genbind_node *genbind_new_node(enum genbind_node_type type, struct genbind_node *l, void *r);
struct genbind_node *genbind_node_link(struct genbind_node *tgt, struct genbind_node *src);

int genbind_ast_dump(struct genbind_node *ast, int indent);

/** 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
 */
struct genbind_node *
genbind_node_find_type(struct genbind_node *node,
		       struct genbind_node *prev,
		       enum genbind_node_type nodetype);

/** Depth first left hand search returning nodes of the specified type
 *    and a 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);

/** Depth first left hand search returning nodes of the specified type
 *    and a type 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 type The text to match the type child node to.
 */
struct genbind_node *
genbind_node_find_type_type(struct genbind_node *node,
			     struct genbind_node *prev,
			     enum genbind_node_type nodetype,
			     const char *type);

int genbind_node_for_each_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);

#ifdef _WIN32
#define NEED_STRNDUP 1
char *strndup(const char *s, size_t n);
#endif

#endif