Lines Matching refs:node

44 struct cil_tree_node *cil_tree_get_next_path(struct cil_tree_node *node, char **info_kind, uint32_t *hll_line, char **path)
48 if (!node) {
52 node = node->parent;
54 while (node) {
55 if (node->flavor == CIL_NODE && node->data == NULL) {
56 if (node->cl_head && node->cl_head->data == CIL_KEY_SRC_INFO) {
57 if (!node->cl_head->next || !node->cl_head->next->next || !node->cl_head->next->next->next) {
61 *info_kind = node->cl_head->next->data;
62 rc = cil_string_to_uint32(node->cl_head->next->next->data, hll_line, 10);
66 *path = node->cl_head->next->next->next->data;
67 return node;
69 node = node->parent;
70 } else if (node->flavor == CIL_SRC_INFO) {
72 struct cil_src_info *info = node->data;
76 return node;
78 if (node->flavor == CIL_CALL) {
79 struct cil_call *call = node->data;
80 node = NODE(call->macro);
81 } else if (node->flavor == CIL_BLOCKINHERIT) {
82 struct cil_blockinherit *inherit = node->data;
83 node = NODE(inherit->block);
85 node = node->parent;
97 char *cil_tree_get_cil_path(struct cil_tree_node *node)
103 while (node) {
104 node = cil_tree_get_next_path(node, &info_kind, &hll_line, &path);
105 if (node && info_kind == CIL_KEY_SRC_CIL) {
113 __attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *node, enum cil_log_level lvl, const char* msg, ...)
121 if (node) {
123 uint32_t hll_offset = node->hll_offset;
125 path = cil_tree_get_cil_path(node);
128 cil_log(lvl, " at %s:%u", path, node->line);
131 while (node) {
136 node = cil_tree_get_next_path(node, &info_kind, &hll_line, &path);
137 if (!node || info_kind == CIL_KEY_SRC_CIL) {
141 hll_line += hll_offset - node->hll_offset - 1;
152 int cil_tree_subtree_has_decl(struct cil_tree_node *node)
154 while (node) {
155 if (node->flavor >= CIL_MIN_DECLARATIVE) {
158 if (node->cl_head != NULL) {
159 if (cil_tree_subtree_has_decl(node->cl_head))
162 node = node->next;
190 void cil_tree_subtree_destroy(struct cil_tree_node *node)
192 cil_tree_children_destroy(node);
193 cil_tree_node_destroy(&node);
196 void cil_tree_children_destroy(struct cil_tree_node *node)
200 if (!node) {
204 curr = node->cl_head;
211 node->cl_head = NULL;
212 node->cl_tail = NULL;
215 void cil_tree_node_init(struct cil_tree_node **node)
227 *node = new_node;
230 void cil_tree_node_destroy(struct cil_tree_node **node)
234 if (node == NULL || *node == NULL) {
238 if ((*node)->flavor >= CIL_MIN_DECLARATIVE) {
239 datum = (*node)->data;
240 cil_symtab_datum_remove_node(datum, *node);
242 cil_destroy_data(&(*node)->data, (*node)->flavor);
245 cil_destroy_data(&(*node)->data, (*node)->flavor);
247 free(*node);
248 *node = NULL;
253 start_node: root node to start walking from
254 process_node: function to call when visiting a node
256 node: node being visited
261 node: node of first child
263 last_child: Function to call when finished with the last child of a node's children
267 static int cil_tree_walk_core(struct cil_tree_node *node,
268 int (*process_node)(struct cil_tree_node *node, uint32_t *finished, void *extra_args),
269 int (*first_child)(struct cil_tree_node *node, void *extra_args),
270 int (*last_child)(struct cil_tree_node *node, void *extra_args),
275 while (node) {
279 rc = (*process_node)(node, &finished, extra_args);
281 cil_tree_log(node, CIL_INFO, "Problem");
290 if (node->cl_head != NULL && !(finished & CIL_TREE_SKIP_HEAD)) {
291 rc = cil_tree_walk(node, process_node, first_child, last_child, extra_args);
297 node = node->next;
303 int cil_tree_walk(struct cil_tree_node *node,
304 int (*process_node)(struct cil_tree_node *node, uint32_t *finished, void *extra_args),
305 int (*first_child)(struct cil_tree_node *node, void *extra_args),
306 int (*last_child)(struct cil_tree_node *node, void *extra_args),
311 if (!node || !node->cl_head) {
316 rc = (*first_child)(node->cl_head, extra_args);
318 cil_tree_log(node, CIL_INFO, "Problem");
323 rc = cil_tree_walk_core(node->cl_head, process_node, first_child, last_child, extra_args);
329 rc = (*last_child)(node->cl_tail, extra_args);
331 cil_tree_log(node, CIL_INFO, "Problem");