1 /*
2   ***** BEGIN LICENSE BLOCK *****
3 
4   Copyright (C) 2001-2020 Olof Hagsand
5 
6   This file is part of CLIgen.
7 
8   Licensed under the Apache License, Version 2.0 (the "License");
9   you may not use this file except in compliance with the License.
10   You may obtain a copy of the License at
11 
12     http://www.apache.org/licenses/LICENSE-2.0
13 
14   Unless required by applicable law or agreed to in writing, software
15   distributed under the License is distributed on an "AS IS" BASIS,
16   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   See the License for the specific language governing permissions and
18   limitations under the License.
19 
20   Alternatively, the contents of this file may be used under the terms of
21   the GNU General Public License Version 2 or later (the "GPL"),
22   in which case the provisions of the GPL are applicable instead
23   of those above. If you wish to allow use of your version of this file only
24   under the terms of the GPL, and not to allow others to
25   use your version of this file under the terms of Apache License version 2, indicate
26   your decision by deleting the provisions above and replace them with the
27   notice and other provisions required by the GPL. If you do not delete
28   the provisions above, a recipient may use your version of this file under
29   the terms of any one of the Apache License version 2 or the GPL.
30 
31   ***** END LICENSE BLOCK *****
32 
33 */
34 
35 #ifndef _CLIGEN_PARSETREE_H_
36 #define _CLIGEN_PARSETREE_H_
37 
38 /*
39  * Types
40  */
41 /*! A parse tree is a top object containing a vector of parse-tree nodes
42  *
43  * @code
44  *   [0 1..n]
45  *    | |  |
46  *    v v  v
47  *    o o  o  cg_obj:s
48  * @endcode
49  */
50 /* Forward declarations for cg_obj declared in cligen_object.h */
51 typedef struct cg_obj cg_obj;
52 
53 typedef struct parse_tree parse_tree; /* struct defined internally in cligen_parsetree.c */
54 
55 /* Callback for pt_apply() */
56 typedef int (cg_applyfn_t)(cg_obj *co, void *arg);
57 
58 /*
59  * Prototypes
60  * Note: pt_ vs cligen_parsetree_
61 vec_ */
62 cg_obj     *pt_vec_i_get(parse_tree *pt, int i);
63 int         pt_vec_i_clear(parse_tree *pt, int i);
64 int         pt_vec_i_insert(parse_tree *pt, int i, cg_obj *co);
65 int         pt_vec_append(parse_tree *pt, cg_obj *co);
66 int         pt_vec_i_delete(parse_tree *pt, int i);
67 int         pt_len_get(parse_tree *pt);
68 char       *pt_name_get(parse_tree *pt);
69 int         pt_name_set(parse_tree *pt, char *name);
70 int         pt_sets_get(parse_tree *pt);
71 int         pt_sets_set(parse_tree *pt, int sets);
72 void        cligen_parsetree_sort(parse_tree *pt, int recursive);
73 int         pt_realloc(parse_tree *pt);
74 int         pt_copy(parse_tree *pt, cg_obj *parent, parse_tree *ptn);
75 parse_tree *pt_dup(parse_tree *pt, cg_obj *cop);
76 int         cligen_parsetree_merge(parse_tree *pt0, cg_obj *parent0, parse_tree *pt1);
77 int         pt_free(parse_tree *pt, int recurse);
78 int         cligen_parsetree_free(parse_tree *pt, int recurse);
79 parse_tree *pt_new(void);
80 int         pt_apply(parse_tree *pt, cg_applyfn_t fn, void *arg);
81 
82 #endif /* _CLIGEN_PARSETREE_H_ */
83 
84