summaryrefslogtreecommitdiff
path: root/src/nsgenbind-ast.h
blob: 6513f7f8372457abb90cadc4ebaa16c5df66c269 (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
/* 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_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 */
};


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

char *genbind_node_gettext(struct genbind_node *node);
struct genbind_node *genbind_node_getnode(struct genbind_node *node);
int genbind_node_getint(struct genbind_node *node);

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

#endif