blob: 58570d8d0968070fe8b1286390ea3cf1a59ddffb [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 *------------------------------------------------------------------
3 * node.h - definitions for an API generator
4 *
5 * Copyright (c) 2004-2009 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
18 */
19
20#ifndef _node_h_
21#define _node_h_
22
23/*
24 * Global prototypes
25 */
26
27char *sxerox (const char *s);
28
29enum node_subclass { /* WARNING: indices must match the vft... */
30 NODE_ILLEGAL=0,
31 NODE_U8,
32 NODE_U16,
33 NODE_U32,
34 NODE_U64,
35 NODE_I8,
36 NODE_I16,
37 NODE_I32,
38 NODE_I64,
39 NODE_F64,
40 NODE_PACKED,
41 NODE_DEFINE,
42 NODE_UNION,
43 NODE_SCALAR,
44 NODE_VECTOR,
45 NODE_COMPLEX,
46 NODE_NOVERSION,
Dave Barach0d056e52017-09-28 15:11:16 -040047 NODE_VERSION,
Ed Warnickecb9cada2015-12-08 15:45:58 -070048 NODE_UWORD,
49 NODE_N_TYPES, /* number of node types with VFT's */
50
51 /* pseudo-node(s) used in the lexer keyword table, but
52 NOT in need of a VFT... */
53 NODE_TYPEONLY,
54 NODE_MANUAL_PRINT,
55 NODE_MANUAL_ENDIAN,
Ed Warnickecb9cada2015-12-08 15:45:58 -070056 NODE_DONT_TRACE,
Dave Barach11b8dbf2017-04-24 10:46:54 -040057 NODE_AUTOREPLY,
Ed Warnickecb9cada2015-12-08 15:45:58 -070058};
59
60enum passid {
61 TYPEDEF_PASS=1,
62 UNION_DEF_PASS,
63 ENDIANFUN_PASS,
64 PRINTFUN_PASS,
Ole Troan6855f6c2016-04-09 03:16:30 +020065 PYTHON_PASS,
Dave Barach557d1282016-11-10 14:22:49 -050066 JSON_PASS,
Ed Warnickecb9cada2015-12-08 15:45:58 -070067};
68
69extern void *make_node (enum node_subclass type);
70
71typedef struct node_ {
72 enum node_subclass type;
73 struct node_ *peer;
74 struct node_ *deeper;
75 int flags;
Dave Barach557d1282016-11-10 14:22:49 -050076 void *data[4];
Ed Warnickecb9cada2015-12-08 15:45:58 -070077} node_t;
78
79/* To shut up gcc-4.2.x warnings */
80#define CDATA0 ((char *)(this->data[0]))
Dave Barach0d056e52017-09-28 15:11:16 -040081#define CDATA1 ((char *)(this->data[0]))
Marek Gradzkifa42e252016-06-15 16:38:33 +020082#define CDATA2 ((char *)(this->data[2]))
Dave Barach557d1282016-11-10 14:22:49 -050083#define CDATA3 ((char *)(this->data[3]))
Ed Warnickecb9cada2015-12-08 15:45:58 -070084
Dave Barach0d056e52017-09-28 15:11:16 -040085#define IDATA0 ((int)(uword)(this->data[0]))
86#define IDATA1 ((int)(uword)(this->data[1]))
87#define IDATA2 ((int)(uword)(this->data[2]))
88#define IDATA3 ((int)(uword)(this->data[3]))
89
Ed Warnickecb9cada2015-12-08 15:45:58 -070090#define NODE_FLAG_MANUAL_PRINT (1<<0)
91#define NODE_FLAG_MANUAL_ENDIAN (1<<1)
Ed Warnickecb9cada2015-12-08 15:45:58 -070092#define NODE_FLAG_TYPEONLY (1<<3)
93#define NODE_FLAG_DONT_TRACE (1<<4)
Dave Barach11b8dbf2017-04-24 10:46:54 -040094#define NODE_FLAG_AUTOREPLY (1<<5)
Ed Warnickecb9cada2015-12-08 15:45:58 -070095
96typedef struct node_vft_ {
97 void (*print)(struct node_ *);
98 void (*generate)(struct node_ *, enum passid id, FILE *ofp);
99 char *endian_converter;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100} node_vft_t;
101
102#endif /* _node_h */