Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 27 | char *sxerox (const char *s); |
| 28 | |
| 29 | enum 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, |
| 47 | NODE_UWORD, |
| 48 | NODE_N_TYPES, /* number of node types with VFT's */ |
| 49 | |
| 50 | /* pseudo-node(s) used in the lexer keyword table, but |
| 51 | NOT in need of a VFT... */ |
| 52 | NODE_TYPEONLY, |
| 53 | NODE_MANUAL_PRINT, |
| 54 | NODE_MANUAL_ENDIAN, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | NODE_DONT_TRACE, |
| 56 | }; |
| 57 | |
| 58 | enum passid { |
| 59 | TYPEDEF_PASS=1, |
| 60 | UNION_DEF_PASS, |
| 61 | ENDIANFUN_PASS, |
| 62 | PRINTFUN_PASS, |
Ole Troan | 6855f6c | 2016-04-09 03:16:30 +0200 | [diff] [blame] | 63 | PYTHON_PASS, |
Dave Barach | 557d128 | 2016-11-10 14:22:49 -0500 | [diff] [blame] | 64 | JSON_PASS, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | extern void *make_node (enum node_subclass type); |
| 68 | |
| 69 | typedef struct node_ { |
| 70 | enum node_subclass type; |
| 71 | struct node_ *peer; |
| 72 | struct node_ *deeper; |
| 73 | int flags; |
Dave Barach | 557d128 | 2016-11-10 14:22:49 -0500 | [diff] [blame] | 74 | void *data[4]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | } node_t; |
| 76 | |
| 77 | /* To shut up gcc-4.2.x warnings */ |
| 78 | #define CDATA0 ((char *)(this->data[0])) |
| 79 | #define IDATA1 ((int)(uword)(this->data[1])) |
Marek Gradzki | fa42e25 | 2016-06-15 16:38:33 +0200 | [diff] [blame] | 80 | #define CDATA2 ((char *)(this->data[2])) |
Dave Barach | 557d128 | 2016-11-10 14:22:49 -0500 | [diff] [blame] | 81 | #define CDATA3 ((char *)(this->data[3])) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 82 | |
| 83 | #define NODE_FLAG_MANUAL_PRINT (1<<0) |
| 84 | #define NODE_FLAG_MANUAL_ENDIAN (1<<1) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 85 | #define NODE_FLAG_TYPEONLY (1<<3) |
| 86 | #define NODE_FLAG_DONT_TRACE (1<<4) |
| 87 | |
| 88 | typedef struct node_vft_ { |
| 89 | void (*print)(struct node_ *); |
| 90 | void (*generate)(struct node_ *, enum passid id, FILE *ofp); |
| 91 | char *endian_converter; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 92 | } node_vft_t; |
| 93 | |
| 94 | #endif /* _node_h */ |