Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
syntax-tree.h
Go to the documentation of this file.
1 /*
2  * Wireshark - Network traffic analyzer
3  * By Gerald Combs <gerald@wireshark.org>
4  * Copyright 2001 Gerald Combs
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #ifndef SYNTAX_TREE_H
10 #define SYNTAX_TREE_H
11 
12 #include <glib.h>
13 #include "cppmagic.h"
14 
18 typedef enum {
19  STTYPE_UNINITIALIZED,
20  STTYPE_TEST,
21  STTYPE_UNPARSED,
22  STTYPE_STRING,
23  STTYPE_CHARCONST,
24  STTYPE_FIELD,
25  STTYPE_FVALUE,
26  STTYPE_INTEGER,
27  STTYPE_RANGE,
28  STTYPE_FUNCTION,
29  STTYPE_SET,
30  STTYPE_NUM_TYPES
31 } sttype_id_t;
32 
33 typedef gpointer (*STTypeNewFunc)(gpointer);
34 typedef gpointer (*STTypeDupFunc)(gconstpointer);
35 typedef void (*STTypeFreeFunc)(gpointer);
36 
37 
38 /* Type information */
39 typedef struct {
40  sttype_id_t id;
41  const char *name;
42  STTypeNewFunc func_new;
43  STTypeFreeFunc func_free;
44  STTypeDupFunc func_dup;
45 } sttype_t;
46 
48 typedef struct {
49  guint32 magic;
50  sttype_t *type;
51 
52  /* This could be made an enum, but I haven't
53  * set aside to time to do so. */
54  gpointer data;
55  gint32 value;
56  gboolean inside_brackets;
57  const char *deprecated_token;
58 } stnode_t;
59 
60 /* These are the sttype_t registration function prototypes. */
61 void sttype_register_function(void);
62 void sttype_register_integer(void);
63 void sttype_register_pointer(void);
64 void sttype_register_range(void);
65 void sttype_register_set(void);
66 void sttype_register_string(void);
67 void sttype_register_test(void);
68 
69 void
70 sttype_init(void);
71 
72 void
73 sttype_cleanup(void);
74 
75 void
76 sttype_register(sttype_t *type);
77 
78 stnode_t*
79 stnode_new(sttype_id_t type_id, gpointer data);
80 
81 void
82 stnode_set_bracket(stnode_t *node, gboolean bracket);
83 
84 stnode_t*
85 stnode_dup(const stnode_t *org);
86 
87 void
88 stnode_init(stnode_t *node, sttype_id_t type_id, gpointer data);
89 
90 void
91 stnode_init_int(stnode_t *node, sttype_id_t type_id, gint32 value);
92 
93 void
94 stnode_free(stnode_t *node);
95 
96 const char*
97 stnode_type_name(stnode_t *node);
98 
99 sttype_id_t
100 stnode_type_id(stnode_t *node);
101 
102 gpointer
103 stnode_data(stnode_t *node);
104 
105 gint32
106 stnode_value(stnode_t *node);
107 
108 const char *
109 stnode_deprecated(stnode_t *node);
110 
111 #define assert_magic(obj, mnum) \
112  g_assert((obj)); \
113  if ((obj)->magic != (mnum)) { \
114  g_print("\nMagic num is 0x%08x, but should be 0x%08x", \
115  (obj)->magic, (mnum)); \
116  g_assert((obj)->magic == (mnum)); \
117  }
118 
119 #define STTYPE_ACCESSOR(ret,type,attr,magicnum) \
120  ret \
121  CONCAT(CONCAT(CONCAT(sttype_,type),_),attr) (stnode_t *node) \
122 {\
123  CONCAT(type,_t) *value; \
124  value = (CONCAT(type,_t) *)stnode_data(node);\
125  assert_magic(value, magicnum); \
126  return value->attr; \
127 }
128 
129 #define STTYPE_ACCESSOR_PROTOTYPE(ret,type,attr) \
130  ret \
131  CONCAT(CONCAT(CONCAT(sttype_,type),_),attr) (stnode_t *node);
132 
133 
134 #endif
Definition: syntax-tree.h:48
Definition: syntax-tree.h:39