db: rename "callbacks" "select_caller_info_callbacks"
[smatch.git] / ast-model.h
blob650053d291dbd155e845922c00de928e9d861067
2 /*
3 * ast-model.h
5 * Copyright (C) 2010 Christopher Li.
7 */
9 #ifndef _ast_model_h_
10 #define _ast_model_h_
12 #include <stdint.h>
13 #include <gtk/gtk.h>
14 #include "lib.h"
16 #define AST_TYPE_NODE (ast_get_type ())
17 #define AST_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AST_TYPE_NODE, AstNode))
18 #define AST_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AST_TYPE_NODE, AstNodeClass))
19 #define AST_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AST_TYPE_NODE))
20 #define AST_IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AST_TYPE_NODE))
21 #define AST_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AST_TYPE_NODE, AstNodeClass))
23 enum
25 AST_COL_RECORD = 0,
26 AST_COL_NAME,
27 AST_N_COLUMNS,
28 } ;
31 typedef struct AstNode AstNode;
32 typedef struct AstNodeClass AstNodeClass;
36 /* AstNode: this structure contains everything we need for our
37 * model implementation. You can add extra fields to
38 * this structure, e.g. hashtables to quickly lookup
39 * rows or whatever else you might need, but it is
40 * crucial that 'parent' is the first member of the
41 * structure. */
43 struct AstNode
45 GObject base; /* this MUST be the first member */
47 AstNode *parent;
48 int index;
49 const gchar *text;
50 void (*inspect)(struct AstNode* node);
51 void *ptr;
52 GArray *childnodes;
53 gint stamp;
58 /* AstNodeClass: more boilerplate GObject stuff */
60 struct AstNodeClass
62 GObjectClass base_class;
66 GType ast_get_type(void);
67 AstNode* ast_new(AstNode *parent, int index, const char *prefix, void *ptr, void (*expand)(AstNode*));
70 static inline
71 AstNode* ast_append_child(AstNode *parent, const char *text,
72 void *ptr, void (*inspect)(AstNode*))
74 if (ptr) {
75 AstNode *child = ast_new(parent, parent->childnodes->len,
76 text, ptr, inspect);
77 g_array_append_val(parent->childnodes, child);
78 return child;
80 return NULL;
83 static inline
84 void ast_append_attribute(AstNode *parent, const char *text)
86 AstNode *child = ast_new(parent, parent->childnodes->len, text, NULL, NULL);
87 g_array_append_val(parent->childnodes, child);
90 #endif /* _ast_h_*/