libyang MAINTENANCE cleanup header includes
Use iwyu tool and fix which headers are included
diff --git a/src/common.c b/src/common.c
index bc5de36..15595e5 100644
--- a/src/common.c
+++ b/src/common.c
@@ -28,7 +28,6 @@
#include <unistd.h>
#include "compat.h"
-#include "tree_schema.h"
#include "tree_schema_internal.h"
void *
diff --git a/src/common.h b/src/common.h
index a5005f7..3d52a67 100644
--- a/src/common.h
+++ b/src/common.h
@@ -20,16 +20,14 @@
#include <stdint.h>
#include "context.h"
-#include "dict.h"
#include "hash_table.h"
#include "log.h"
#include "set.h"
-#include "tree.h"
#include "tree_data.h"
struct ly_ctx;
struct ly_in;
-struct lys_module;
+struct lysc_node;
#if __STDC_VERSION__ >= 201112 && !defined __STDC_NO_THREADS__
# define THREAD_LOCAL _Thread_local
diff --git a/src/context.c b/src/context.c
index 46d9cbd..491e33e 100644
--- a/src/context.c
+++ b/src/context.c
@@ -16,7 +16,6 @@
#include "context.h"
-#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <stddef.h>
@@ -31,7 +30,6 @@
#include "hash_table.h"
#include "in.h"
#include "parser_data.h"
-#include "path.h"
#include "plugins_types.h"
#include "schema_compile.h"
#include "set.h"
@@ -39,7 +37,6 @@
#include "tree_data.h"
#include "tree_schema.h"
#include "tree_schema_internal.h"
-#include "xpath.h"
#include "../models/ietf-datastores@2018-02-14.h"
#include "../models/ietf-inet-types@2013-07-15.h"
diff --git a/src/context.h b/src/context.h
index ec55a29..ee48010 100644
--- a/src/context.h
+++ b/src/context.h
@@ -25,6 +25,7 @@
#endif
struct lyd_node;
+struct lys_module;
struct lysc_node;
/**
diff --git a/src/in.c b/src/in.c
index 58666d9..92003ff 100644
--- a/src/in.c
+++ b/src/in.c
@@ -38,6 +38,7 @@
#include "parser_data.h"
#include "parser_internal.h"
#include "set.h"
+#include "tree.h"
#include "tree_data.h"
#include "tree_data_internal.h"
#include "tree_schema.h"
diff --git a/src/log.c b/src/log.c
index 8551a3c..af28cdf 100644
--- a/src/log.c
+++ b/src/log.c
@@ -30,6 +30,7 @@
#include "compat.h"
#include "in_internal.h"
#include "plugins_exts.h"
+#include "set.h"
#include "tree_data.h"
#include "tree_schema.h"
diff --git a/src/out.c b/src/out.c
index 9b1772e..c368088 100644
--- a/src/out.c
+++ b/src/out.c
@@ -31,7 +31,6 @@
#include "compat.h"
#include "log.h"
#include "printer_data.h"
-#include "printer_internal.h"
#include "tree_data.h"
#include "tree_schema.h"
diff --git a/src/parser_json.c b/src/parser_json.c
index f811b74..24f6544 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -25,8 +25,8 @@
#include "in_internal.h"
#include "json.h"
#include "log.h"
+#include "parser_data.h"
#include "parser_internal.h"
-#include "plugins_exts.h"
#include "set.h"
#include "tree.h"
#include "tree_data.h"
diff --git a/src/parser_lyb.c b/src/parser_lyb.c
index b4abac3..9954377 100644
--- a/src/parser_lyb.c
+++ b/src/parser_lyb.c
@@ -30,6 +30,7 @@
#include "log.h"
#include "parser_data.h"
#include "parser_internal.h"
+#include "set.h"
#include "tree.h"
#include "tree_data.h"
#include "tree_data_internal.h"
diff --git a/src/parser_stmt.c b/src/parser_stmt.c
index a560ee5..ed459de 100644
--- a/src/parser_stmt.c
+++ b/src/parser_stmt.c
@@ -21,12 +21,11 @@
#include "common.h"
#include "dict.h"
-#include "in.h"
-#include "in_internal.h"
#include "log.h"
#include "parser_schema.h"
#include "path.h"
#include "schema_compile.h"
+#include "set.h"
#include "tree.h"
#include "tree_edit.h"
#include "tree_schema.h"
diff --git a/src/parser_xml.c b/src/parser_xml.c
index 8bed12f..f5bfc15 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -19,15 +19,17 @@
#include "common.h"
#include "context.h"
+#include "dict.h"
#include "in_internal.h"
#include "log.h"
#include "parser_data.h"
#include "parser_internal.h"
-#include "plugins_exts.h"
#include "set.h"
+#include "tree.h"
#include "tree_data.h"
#include "tree_data_internal.h"
#include "tree_schema.h"
+#include "tree_schema_internal.h"
#include "validation.h"
#include "xml.h"
diff --git a/src/parser_yang.c b/src/parser_yang.c
index e9e1a82..6e38e2c 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -30,11 +30,12 @@
#include "path.h"
#include "set.h"
#include "tree.h"
-#include "tree_data_internal.h"
#include "tree_edit.h"
#include "tree_schema.h"
#include "tree_schema_internal.h"
+struct lys_glob_unres;
+
/**
* @brief Insert WORD into the libyang context's dictionary and store as TARGET.
* @param[in] CTX yang parser context to access libyang context.
diff --git a/src/parser_yin.c b/src/parser_yin.c
index a467cf7..da1061d 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -41,6 +41,8 @@
#include "tree_schema_internal.h"
#include "xml.h"
+struct lys_glob_unres;
+
/**
* @brief check if given string is URI of yin namespace.
*
diff --git a/src/plugins_exts.c b/src/plugins_exts.c
index 11ada75..c21ebf2 100644
--- a/src/plugins_exts.c
+++ b/src/plugins_exts.c
@@ -13,7 +13,8 @@
*/
#include "plugins_exts.h"
-#include "plugins_exts_internal.h"
+#include "plugins_exts_compile.h"
+#include "plugins_exts_print.h"
#include <stdint.h>
#include <string.h>
@@ -24,6 +25,7 @@
/* internal libyang headers - do not make them accessible to the extension plugins in plugins_exts_*.c */
#include "common.h"
+#include "plugins_exts_internal.h"
#include "printer_internal.h"
#include "schema_compile.h"
diff --git a/src/plugins_exts.h b/src/plugins_exts.h
index 77950d3..0900fd2 100644
--- a/src/plugins_exts.h
+++ b/src/plugins_exts.h
@@ -24,6 +24,8 @@
struct ly_ctx;
struct lyd_node;
+struct lysc_ctx;
+struct lyspr_ctx;
#ifdef __cplusplus
extern "C" {
diff --git a/src/plugins_types.c b/src/plugins_types.c
index ff032ee..204b85e 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -33,6 +33,7 @@
#include "schema_compile.h"
#include "set.h"
#include "tree.h"
+#include "tree_data.h"
#include "tree_data_internal.h"
#include "tree_edit.h"
#include "tree_schema.h"
diff --git a/src/plugins_types.h b/src/plugins_types.h
index 457bd58..aaff4be 100644
--- a/src/plugins_types.h
+++ b/src/plugins_types.h
@@ -20,13 +20,14 @@
#include "log.h"
#include "tree.h"
-#include "tree_data.h"
#ifdef __cplusplus
extern "C" {
#endif
struct ly_ctx;
+struct lyd_node;
+struct lyd_value;
struct lys_module;
struct lys_glob_unres;
struct lysc_ident;
diff --git a/src/printer_data.c b/src/printer_data.c
index b66511d..a8e9f80 100644
--- a/src/printer_data.c
+++ b/src/printer_data.c
@@ -22,7 +22,6 @@
#include "out_internal.h"
#include "printer_internal.h"
#include "tree_data.h"
-#include "tree_schema.h"
static LY_ERR
lyd_print_(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
diff --git a/src/printer_tree.c b/src/printer_tree.c
index 7062d58..796370d 100644
--- a/src/printer_tree.c
+++ b/src/printer_tree.c
@@ -13,13 +13,22 @@
*/
#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
#include "compat.h"
+#include "log.h"
+#include "out.h"
#include "out_internal.h"
#include "printer_internal.h"
+#include "tree.h"
+#include "tree_schema.h"
#include "xpath.h"
+struct trt_tree_ctx;
+
/******************************************************************************
* Declarations start
*****************************************************************************/
diff --git a/src/printer_yang.c b/src/printer_yang.c
index e168396..95ba4f3 100644
--- a/src/printer_yang.c
+++ b/src/printer_yang.c
@@ -26,7 +26,7 @@
#include "log.h"
#include "out.h"
#include "out_internal.h"
-#include "plugins_exts_internal.h"
+#include "plugins_exts.h"
#include "plugins_exts_print.h"
#include "plugins_types.h"
#include "printer_internal.h"
diff --git a/src/schema_compile.c b/src/schema_compile.c
index d949b49..6d9c606 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -32,6 +32,7 @@
#include "parser_schema.h"
#include "path.h"
#include "plugins_exts.h"
+#include "plugins_exts_compile.h"
#include "plugins_exts_internal.h"
#include "plugins_types.h"
#include "schema_compile_amend.h"
diff --git a/src/schema_compile.h b/src/schema_compile.h
index 0f114f0..3252d5e 100644
--- a/src/schema_compile.h
+++ b/src/schema_compile.h
@@ -21,10 +21,8 @@
#include "common.h"
#include "dict.h"
#include "log.h"
-#include "plugins_exts_compile.h"
#include "set.h"
#include "tree.h"
-#include "tree_data.h"
#include "tree_edit.h"
#include "tree_schema.h"
diff --git a/src/schema_compile_amend.c b/src/schema_compile_amend.c
index a57930c..2888c4f 100644
--- a/src/schema_compile_amend.c
+++ b/src/schema_compile_amend.c
@@ -23,14 +23,14 @@
#include <string.h>
#include "common.h"
+#include "dict.h"
#include "log.h"
-#include "plugins_exts.h"
+#include "plugins_exts_compile.h"
#include "schema_compile.h"
#include "schema_compile_node.h"
#include "schema_features.h"
#include "set.h"
#include "tree.h"
-#include "tree_data.h"
#include "tree_edit.h"
#include "tree_schema.h"
#include "tree_schema_internal.h"
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index 67c73ae..1793d97 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -30,6 +30,7 @@
#include "dict.h"
#include "log.h"
#include "plugins_exts.h"
+#include "plugins_exts_compile.h"
#include "plugins_types.h"
#include "schema_compile.h"
#include "schema_compile_amend.h"
diff --git a/src/schema_compile_node.h b/src/schema_compile_node.h
index 83c3fc7..2d762fa 100644
--- a/src/schema_compile_node.h
+++ b/src/schema_compile_node.h
@@ -19,7 +19,7 @@
#include <stdint.h>
#include "log.h"
-#include "tree_data.h"
+#include "tree.h"
#include "tree_schema.h"
struct ly_ctx;
diff --git a/src/schema_features.c b/src/schema_features.c
index 6deb52c..3bdd8d4 100644
--- a/src/schema_features.c
+++ b/src/schema_features.c
@@ -27,7 +27,6 @@
#include "log.h"
#include "set.h"
#include "tree.h"
-#include "tree_data.h"
#include "tree_edit.h"
#include "tree_schema.h"
#include "tree_schema_internal.h"
diff --git a/src/tree_data.h b/src/tree_data.h
index c1ebd15..44f8aad 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -32,9 +32,6 @@
struct lyd_node;
struct lyd_node_opaq;
struct lyd_node_term;
-struct lys_module;
-struct lysc_node;
-struct lysc_type;
/**
* @page howtoData Data Instances
diff --git a/src/tree_data_free.c b/src/tree_data_free.c
index ffeb9d5..cf70bf7 100644
--- a/src/tree_data_free.c
+++ b/src/tree_data_free.c
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include "common.h"
+#include "dict.h"
#include "hash_table.h"
#include "log.h"
#include "plugins_types.h"
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index 168869a..41cfcb0 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -26,6 +26,7 @@
#include "log.h"
#include "lyb.h"
#include "parser_data.h"
+#include "plugins_types.h"
#include "printer_data.h"
#include "set.h"
#include "tree.h"
@@ -33,6 +34,7 @@
#include "tree_data_internal.h"
#include "tree_edit.h"
#include "tree_schema.h"
+#include "xml.h"
struct lyd_node *
lys_getnext_data(const struct lyd_node *last, const struct lyd_node *sibling, const struct lysc_node **slast,
diff --git a/src/tree_schema.c b/src/tree_schema.c
index 4e68d4b..f6ee17d 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -40,11 +40,9 @@
#include "path.h"
#include "plugins_exts.h"
#include "schema_compile.h"
-#include "schema_compile_amend.h"
#include "schema_features.h"
#include "set.h"
#include "tree.h"
-#include "tree_data.h"
#include "tree_edit.h"
#include "tree_schema_internal.h"
#include "xpath.h"
diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c
index 09ce99d..f823cf7 100644
--- a/src/tree_schema_free.c
+++ b/src/tree_schema_free.c
@@ -16,6 +16,7 @@
#include "common.h"
#include "compat.h"
+#include "dict.h"
#include "log.h"
#include "plugins_exts.h"
#include "plugins_types.h"
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index 2ed6344..9417d13 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -25,6 +25,7 @@
#include "common.h"
#include "compat.h"
#include "context.h"
+#include "dict.h"
#include "hash_table.h"
#include "in.h"
#include "in_internal.h"
@@ -34,7 +35,6 @@
#include "schema_features.h"
#include "set.h"
#include "tree.h"
-#include "tree_data.h"
#include "tree_edit.h"
#include "tree_schema.h"
#include "tree_schema_internal.h"
diff --git a/src/validation.c b/src/validation.c
index 66d745d..22f6c7c 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -16,6 +16,7 @@
#include "validation.h"
#include <assert.h>
+#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -27,6 +28,7 @@
#include "hash_table.h"
#include "log.h"
#include "parser_data.h"
+#include "parser_internal.h"
#include "plugins_exts.h"
#include "plugins_exts_metadata.h"
#include "plugins_types.h"
diff --git a/src/validation.h b/src/validation.h
index c255270..5264cc7 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -18,8 +18,8 @@
#include <stdint.h>
#include "log.h"
-#include "parser_data.h"
+struct ly_ctx;
struct ly_set;
struct lyd_node;
struct lys_module;
diff --git a/src/xml.c b/src/xml.c
index 48a11d6..1381b86 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -25,11 +25,10 @@
#include "common.h"
#include "compat.h"
-#include "dict.h"
#include "in_internal.h"
#include "out_internal.h"
#include "tree.h"
-#include "tree_data.h"
+#include "tree_schema_internal.h"
/* Move input p by s characters, if EOF log with lyxml_ctx c */
#define move_input(c, s) \
diff --git a/src/xml.h b/src/xml.h
index 8b8a756..84856e5 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -24,7 +24,6 @@
struct ly_ctx;
struct ly_in;
struct ly_out;
-struct ly_prefix;
/* Macro to test if character is whitespace */
#define is_xmlws(c) (c == 0x20 || c == 0x9 || c == 0xa || c == 0xd)
diff --git a/src/xpath.c b/src/xpath.c
index e54198a..d05107f 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -40,6 +40,7 @@
#include "printer_data.h"
#include "schema_compile_node.h"
#include "tree.h"
+#include "tree_data.h"
#include "tree_data_internal.h"
#include "tree_edit.h"
#include "tree_schema_internal.h"
diff --git a/src/xpath.h b/src/xpath.h
index 4f13699..8224dfe 100644
--- a/src/xpath.h
+++ b/src/xpath.h
@@ -20,10 +20,11 @@
#include "compat.h"
#include "log.h"
-#include "tree_data.h"
+#include "tree.h"
#include "tree_schema.h"
struct ly_ctx;
+struct lyd_node;
/*
* XPath evaluator fully compliant with http://www.w3.org/TR/1999/REC-xpath-19991116/