16cd6a6acSopenharmony_ci/*
26cd6a6acSopenharmony_ci * Copyright 2011 Tresys Technology, LLC. All rights reserved.
36cd6a6acSopenharmony_ci *
46cd6a6acSopenharmony_ci * Redistribution and use in source and binary forms, with or without
56cd6a6acSopenharmony_ci * modification, are permitted provided that the following conditions are met:
66cd6a6acSopenharmony_ci *
76cd6a6acSopenharmony_ci *    1. Redistributions of source code must retain the above copyright notice,
86cd6a6acSopenharmony_ci *       this list of conditions and the following disclaimer.
96cd6a6acSopenharmony_ci *
106cd6a6acSopenharmony_ci *    2. Redistributions in binary form must reproduce the above copyright notice,
116cd6a6acSopenharmony_ci *       this list of conditions and the following disclaimer in the documentation
126cd6a6acSopenharmony_ci *       and/or other materials provided with the distribution.
136cd6a6acSopenharmony_ci *
146cd6a6acSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
156cd6a6acSopenharmony_ci * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
166cd6a6acSopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
176cd6a6acSopenharmony_ci * EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
186cd6a6acSopenharmony_ci * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
196cd6a6acSopenharmony_ci * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
206cd6a6acSopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
216cd6a6acSopenharmony_ci * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
226cd6a6acSopenharmony_ci * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
236cd6a6acSopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
246cd6a6acSopenharmony_ci *
256cd6a6acSopenharmony_ci * The views and conclusions contained in the software and documentation are those
266cd6a6acSopenharmony_ci * of the authors and should not be interpreted as representing official policies,
276cd6a6acSopenharmony_ci * either expressed or implied, of Tresys Technology, LLC.
286cd6a6acSopenharmony_ci */
296cd6a6acSopenharmony_ci
306cd6a6acSopenharmony_ci#ifndef CIL_TREE_H_
316cd6a6acSopenharmony_ci#define CIL_TREE_H_
326cd6a6acSopenharmony_ci
336cd6a6acSopenharmony_ci#include <stdint.h>
346cd6a6acSopenharmony_ci
356cd6a6acSopenharmony_ci#include "cil_flavor.h"
366cd6a6acSopenharmony_ci#include "cil_list.h"
376cd6a6acSopenharmony_ci
386cd6a6acSopenharmony_cistruct cil_tree {
396cd6a6acSopenharmony_ci	struct cil_tree_node *root;
406cd6a6acSopenharmony_ci};
416cd6a6acSopenharmony_ci
426cd6a6acSopenharmony_cistruct cil_tree_node {
436cd6a6acSopenharmony_ci	struct cil_tree_node *parent;
446cd6a6acSopenharmony_ci	struct cil_tree_node *cl_head;		//Head of child_list
456cd6a6acSopenharmony_ci	struct cil_tree_node *cl_tail;		//Tail of child_list
466cd6a6acSopenharmony_ci	struct cil_tree_node *next;		//Each element in the list points to the next element
476cd6a6acSopenharmony_ci	enum cil_flavor flavor;
486cd6a6acSopenharmony_ci	uint32_t line;
496cd6a6acSopenharmony_ci	uint32_t hll_offset;
506cd6a6acSopenharmony_ci	void *data;
516cd6a6acSopenharmony_ci};
526cd6a6acSopenharmony_ci
536cd6a6acSopenharmony_cistruct cil_tree_node *cil_tree_get_next_path(struct cil_tree_node *node, char **info_kind, uint32_t *hll_line, char **path);
546cd6a6acSopenharmony_cichar *cil_tree_get_cil_path(struct cil_tree_node *node);
556cd6a6acSopenharmony_ci__attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *node, enum cil_log_level lvl, const char* msg, ...);
566cd6a6acSopenharmony_ci
576cd6a6acSopenharmony_ciint cil_tree_subtree_has_decl(struct cil_tree_node *node);
586cd6a6acSopenharmony_ci
596cd6a6acSopenharmony_ciint cil_tree_init(struct cil_tree **tree);
606cd6a6acSopenharmony_civoid cil_tree_destroy(struct cil_tree **tree);
616cd6a6acSopenharmony_civoid cil_tree_subtree_destroy(struct cil_tree_node *node);
626cd6a6acSopenharmony_civoid cil_tree_children_destroy(struct cil_tree_node *node);
636cd6a6acSopenharmony_ci
646cd6a6acSopenharmony_civoid cil_tree_node_init(struct cil_tree_node **node);
656cd6a6acSopenharmony_civoid cil_tree_node_destroy(struct cil_tree_node **node);
666cd6a6acSopenharmony_ci
676cd6a6acSopenharmony_ci//finished values
686cd6a6acSopenharmony_ci#define CIL_TREE_SKIP_NOTHING	0
696cd6a6acSopenharmony_ci#define CIL_TREE_SKIP_NEXT	1
706cd6a6acSopenharmony_ci#define CIL_TREE_SKIP_HEAD	2
716cd6a6acSopenharmony_ci#define CIL_TREE_SKIP_ALL	(CIL_TREE_SKIP_NOTHING | CIL_TREE_SKIP_NEXT | CIL_TREE_SKIP_HEAD)
726cd6a6acSopenharmony_ciint cil_tree_walk(struct cil_tree_node *start_node, int (*process_node)(struct cil_tree_node *node, uint32_t *finished, void *extra_args), int (*first_child)(struct cil_tree_node *node, void *extra_args), int (*last_child)(struct cil_tree_node *node, void *extra_args), void *extra_args);
736cd6a6acSopenharmony_ci
746cd6a6acSopenharmony_ci#endif /* CIL_TREE_H_ */
756cd6a6acSopenharmony_ci
76