resolve & tree schema OPTIMIZE some refactoring

Functions and variables renamed to be obvious
what they do and removed a redundant flag.
diff --git a/src/resolve.c b/src/resolve.c
index 7e27daa..f4e16a0 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -3712,7 +3712,7 @@
 }
 
 static int
-resolve_path_arg_schema_valid_dep_flag(const struct lys_node *op_node, const struct lys_node *first_node, int abs_path)
+resolve_schema_leafref_valid_dep_flag(const struct lys_node *op_node, const struct lys_node *first_node, int abs_path)
 {
     int dep1, dep2;
     const struct lys_node *node;
@@ -3752,8 +3752,8 @@
  *         positive on success, negative on failure.
  */
 static int
-resolve_path_predicate_schema(const char *path, const struct lys_node *context_node,
-                              struct lys_node *parent, const struct lys_node *op_node)
+resolve_schema_leafref_predicate(const char *path, const struct lys_node *context_node,
+                                 struct lys_node *parent, const struct lys_node *op_node)
 {
     const struct lys_module *trg_mod;
     const struct lys_node *src_node, *dst_node;
@@ -3818,7 +3818,7 @@
             }
 
             if (first_iter) {
-                if (resolve_path_arg_schema_valid_dep_flag(op_node, dst_node, 0)) {
+                if (resolve_schema_leafref_valid_dep_flag(op_node, dst_node, 0)) {
                     parent->flags |= LYS_LEAFREF_DEP;
                 }
                 first_iter = 0;
@@ -3854,15 +3854,12 @@
  *
  * @param[in] path Path to use.
  * @param[in] parent_node Parent of the leafref.
- * @param[in] parent_tpdf Flag if the parent node is actually typedef, in that case the path
- *            has to contain absolute path
  * @param[out] ret Pointer to the resolved schema node. Can be NULL.
  *
  * @return EXIT_SUCCESS on success, EXIT_FAILURE on forward reference, -1 on error.
  */
 static int
-resolve_path_arg_schema(const char *path, struct lys_node *parent, int parent_tpdf,
-                        const struct lys_node **ret)
+resolve_schema_leafref(const char *path, struct lys_node *parent, const struct lys_node **ret)
 {
     const struct lys_node *node, *op_node = NULL;
     const struct lys_module *mod;
@@ -3875,17 +3872,15 @@
     parent_times = 0;
     id = path;
 
-    /* find operation schema we are in, if applicable */
-    if (!parent_tpdf) {
-        for (op_node = lys_parent(parent);
-             op_node && !(op_node->nodetype & (LYS_ACTION | LYS_NOTIF | LYS_RPC));
-             op_node = lys_parent(op_node));
-    }
+    /* find operation schema we are in */
+    for (op_node = lys_parent(parent);
+         op_node && !(op_node->nodetype & (LYS_ACTION | LYS_NOTIF | LYS_RPC));
+         op_node = lys_parent(op_node));
 
     mod_start = lys_node_module(parent);
     do {
         if ((i = parse_path_arg(mod_start, id, &prefix, &pref_len, &name, &nam_len, &parent_times, &has_predicate)) < 1) {
-            LOGVAL(LYE_INCHAR, parent_tpdf ? LY_VLOG_NONE : LY_VLOG_LYS, parent_tpdf ? NULL : parent, id[-i], &id[-i]);
+            LOGVAL(LYE_INCHAR, LY_VLOG_LYS, parent, id[-i], &id[-i]);
             return -1;
         }
         id += i;
@@ -3895,8 +3890,7 @@
                 /* resolve prefix of the module */
                 mod = prefix ? lys_get_import_module(mod_start, NULL, 0, prefix, pref_len) : mod_start;
                 if (!mod) {
-                    LOGVAL(LYE_NORESOLV, parent_tpdf ? LY_VLOG_NONE : LY_VLOG_LYS, parent_tpdf ? NULL : parent,
-                           "leafref", path);
+                    LOGVAL(LYE_NORESOLV, LY_VLOG_LYS, parent, "leafref", path);
                     return EXIT_FAILURE;
                 }
                 if (!mod->implemented) {
@@ -3910,19 +3904,12 @@
                 }
                 /* get start node */
                 if (!mod->data) {
-                    LOGVAL(LYE_NORESOLV, parent_tpdf ? LY_VLOG_NONE : LY_VLOG_LYS, parent_tpdf ? NULL : parent,
-                           "leafref", path);
+                    LOGVAL(LYE_NORESOLV, LY_VLOG_LYS, parent, "leafref", path);
                     return EXIT_FAILURE;
                 }
                 node = mod->data;
 
             } else if (parent_times > 0) {
-                if (parent_tpdf) {
-                    /* the path is not allowed to contain relative path since we are in top level typedef */
-                    LOGVAL(LYE_NORESOLV, 0, NULL, "leafref", path);
-                    return -1;
-                }
-
                 /* we are looking for a sibling of a node, node it's parent (that is why parent_times - 1) */
                 for (i = 0, node = parent; i < parent_times - 1; i++) {
                     /* path is supposed to be evaluated in data tree, so we have to skip
@@ -3976,13 +3963,12 @@
 
             /* move down the tree, if possible */
             if (node->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA)) {
-                LOGVAL(LYE_INCHAR, parent_tpdf ? LY_VLOG_NONE : LY_VLOG_LYS, parent_tpdf ? NULL : parent, name[0], name);
+                LOGVAL(LYE_INCHAR, LY_VLOG_LYS, parent, name[0], name);
                 return -1;
             }
             node = node->child;
             if (!node) {
-                LOGVAL(LYE_NORESOLV, parent_tpdf ? LY_VLOG_NONE : LY_VLOG_LYS, parent_tpdf ? NULL : parent,
-                       "leafref", path);
+                LOGVAL(LYE_NORESOLV, LY_VLOG_LYS, parent, "leafref", path);
                 return EXIT_FAILURE;
             }
         }
@@ -3990,14 +3976,14 @@
         rc = lys_get_data_sibling(mod, node, name, nam_len, LYS_LIST | LYS_CONTAINER | LYS_RPC | LYS_ACTION | LYS_NOTIF
                                   | LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA, &node);
         if (rc) {
-            LOGVAL(LYE_NORESOLV, parent_tpdf ? LY_VLOG_NONE : LY_VLOG_LYS, parent_tpdf ? NULL : parent, "leafref", path);
+            LOGVAL(LYE_NORESOLV, LY_VLOG_LYS, parent, "leafref", path);
             return EXIT_FAILURE;
         }
 
         if (first_iter) {
             /* set external dependency flag, we can decide based on the first found node */
-            if (!parent_tpdf && op_node && parent_times &&
-                    resolve_path_arg_schema_valid_dep_flag(op_node, node, (parent_times == -1 ? 1 : 0))) {
+            if (op_node && parent_times &&
+                    resolve_schema_leafref_valid_dep_flag(op_node, node, (parent_times == -1 ? 1 : 0))) {
                 parent->flags |= LYS_LEAFREF_DEP;
             }
             first_iter = 0;
@@ -4006,11 +3992,11 @@
         if (has_predicate) {
             /* we have predicate, so the current result must be list */
             if (node->nodetype != LYS_LIST) {
-                LOGVAL(LYE_NORESOLV, parent_tpdf ? LY_VLOG_NONE : LY_VLOG_LYS, parent_tpdf ? NULL : parent, "leafref", path);
+                LOGVAL(LYE_NORESOLV, LY_VLOG_LYS, parent, "leafref", path);
                 return -1;
             }
 
-            i = resolve_path_predicate_schema(id, node, parent, op_node);
+            i = resolve_schema_leafref_predicate(id, node, parent, op_node);
             if (i <= 0) {
                 if (i == 0) {
                     return EXIT_FAILURE;
@@ -4025,7 +4011,7 @@
 
     /* the target must be leaf or leaf-list (in YANG 1.1 only) */
     if ((node->nodetype != LYS_LEAF) && (node->nodetype != LYS_LEAFLIST)) {
-        LOGVAL(LYE_NORESOLV, parent_tpdf ? LY_VLOG_NONE : LY_VLOG_LYS, parent_tpdf ? NULL : parent, "leafref", path);
+        LOGVAL(LYE_NORESOLV, LY_VLOG_LYS, parent, "leafref", path);
         LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Leafref target \"%s\" is not a leaf nor a leaf-list.", path);
         return -1;
     }
@@ -4056,7 +4042,7 @@
  *         positive on success, negative on failure.
  */
 static int
-resolve_predicate(const char *pred, struct unres_data *node_match)
+resolve_instid_predicate(const char *pred, struct unres_data *node_match)
 {
     /* ... /node[target = value] ... */
     struct lyd_node *target;
@@ -6384,23 +6370,14 @@
         node = str_snode;
         stype = item;
 
-        /* HACK - when there is no parent, we are in top level typedef and in that
-         * case, the path has to contain absolute path, so we let the resolve_path_arg_schema()
-         * know it via tpdf_flag */
-        if (!node) {
-            parent_type = 1;
-            node = (struct lys_node *)stype->parent;
-        }
-
         if (!lys_node_module(node)->implemented) {
             /* not implemented module, don't bother with resolving the leafref
              * if the module is set to be implemented, the path will be resolved then */
             rc = 0;
             break;
         }
-        rc = resolve_path_arg_schema(stype->info.lref.path, node, parent_type,
-                                     (const struct lys_node **)&stype->info.lref.target);
-        if (!parent_type && !rc) {
+        rc = resolve_schema_leafref(stype->info.lref.path, node, (const struct lys_node **)&stype->info.lref.target);
+        if (!rc) {
             assert(stype->info.lref.target);
             /* check if leafref and its target are under a common if-features */
             rc = check_leafref_features(stype);
@@ -7400,7 +7377,7 @@
 
         if (has_predicate) {
             /* we have predicate, so the current results must be list or leaf-list */
-            j = resolve_predicate(&path[i], &node_match);
+            j = resolve_instid_predicate(&path[i], &node_match);
             if (j < 1) {
                 LOGVAL(LYE_INPRED, LY_VLOG_LYD, data, &path[i-j]);
                 goto error;