schema tree REFACTOR evaluate features during compilation

So that the compiled schema tree reflects the state
of all the features.
diff --git a/tests/utests/schema/test_schema_stmts.c b/tests/utests/schema/test_schema_stmts.c
index 11512ac..55400b4 100644
--- a/tests/utests/schema/test_schema_stmts.c
+++ b/tests/utests/schema/test_schema_stmts.c
@@ -116,11 +116,11 @@
     assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[1].derived));
     assert_ptr_equal(mod->identities[1].derived[0], &mod->identities[0]);
 
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1;identity i1;", "Duplicate identifier \"i1\" of identity statement. /inv:{identity='i1'}");
+    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1;identity i1;", "Duplicate identifier \"i1\" of identity statement. Line number 1.");
 
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} identity i1;}");
     TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "include inv_sub;identity i1;",
-                    "Duplicate identifier \"i1\" of identity statement. /inv:{identity='i1'}");
+                    "Duplicate identifier \"i1\" of identity statement. Line number 1.");
     TEST_SCHEMA_ERR(ctx, 0, 0,"inv", "identity i1 {base i2;}", "Unable to find base (i2) of identity \"i1\". /inv:{identity='i1'}");
     TEST_SCHEMA_ERR(ctx, 0, 0,"inv", "identity i1 {base i1;}", "Identity \"i1\" is derived from itself. /inv:{identity='i1'}");
     TEST_SCHEMA_ERR(ctx, 0, 0,"inv", "identity i1 {base i2;}identity i2 {base i3;}identity i3 {base i1;}",
@@ -160,7 +160,7 @@
 
     struct ly_ctx *ctx;
     const struct lys_module *mod;
-    const struct lysc_feature *f, *f1;
+    const struct lysp_feature *f;
 
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
@@ -223,144 +223,51 @@
                    "feature f7 {if-feature \"(f2 and f3) or (not f1)\";}\n"
                    "feature f8 {if-feature \"f1 or f2 or f3 or orfeature or andfeature\";}\n"
                    "feature f9 {if-feature \"not not f1\";}", mod);
-    assert_non_null(mod->features);
-    assert_int_equal(9, LY_ARRAY_COUNT(mod->features));
+    assert_non_null(mod->parsed->features);
+    assert_int_equal(9, LY_ARRAY_COUNT(mod->parsed->features));
 
     /* all features are disabled by default */
-    LY_ARRAY_FOR(mod->features, struct lysc_feature, f) {
-        assert_int_equal(LY_ENOT, lysc_feature_value(f));
+    LY_ARRAY_FOR(mod->parsed->features, struct lysp_feature, f) {
+        assert_false(f->flags & LYS_FENABLED);
     }
-    /* enable f1 */
-    assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f1"));
-    f1 = &mod->features[0];
-    assert_int_equal(LY_SUCCESS, lysc_feature_value(f1));
-
-    /* enable orfeature */
-    f = &mod->features[3];
-    assert_int_equal(LY_ENOT, lysc_feature_value(f));
-    assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "orfeature"));
-    assert_int_equal(LY_SUCCESS, lysc_feature_value(f));
-
-    /* enable andfeature - no possible since f2 is disabled */
-    f = &mod->features[4];
-    assert_int_equal(LY_ENOT, lysc_feature_value(f));
-    assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "andfeature"));
-    logbuf_assert("Feature \"andfeature\" cannot be enabled since it is disabled by its if-feature condition(s).");
-    assert_int_equal(LY_ENOT, lysc_feature_value(f));
-
-    /* first enable f2, so f5 can be enabled then */
-    assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f2"));
-    assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "andfeature"));
-    assert_int_equal(LY_SUCCESS, lysc_feature_value(f));
-
-    /* f1 is enabled, so f6 cannot be enabled */
-    f = &mod->features[5];
-    assert_int_equal(LY_ENOT, lysc_feature_value(f));
-    assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "f6"));
-    logbuf_assert("Feature \"f6\" cannot be enabled since it is disabled by its if-feature condition(s).");
-    assert_int_equal(LY_ENOT, lysc_feature_value(f));
-
-    /* so disable f1 - andfeature will became also disabled */
-    assert_int_equal(LY_SUCCESS, lysc_feature_value(f1));
-    assert_int_equal(LY_SUCCESS, lys_feature_disable(mod, "f1"));
-    assert_int_equal(LY_ENOT, lysc_feature_value(f1));
-    assert_int_equal(LY_ENOT, lysc_feature_value(&mod->features[4]));
-    /* while orfeature is stille enabled */
-    assert_int_equal(LY_SUCCESS, lysc_feature_value(&mod->features[3]));
-    /* and finally f6 can be enabled */
-    assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f6"));
-    assert_int_equal(LY_SUCCESS, lysc_feature_value(&mod->features[5]));
-
-    /* complex evaluation of f7: f1 and f3 are disabled, while f2 is enabled */
-    assert_int_equal(LY_SUCCESS, lysc_iffeature_value(&mod->features[6].iffeatures[0]));
-    /* long evaluation of f8 to need to reallocate internal stack for operators */
-    assert_int_equal(LY_SUCCESS, lysc_iffeature_value(&mod->features[7].iffeatures[0]));
-
-    /* double negation of disabled f1 -> disabled */
-    assert_int_equal(LY_ENOT, lysc_iffeature_value(&mod->features[8].iffeatures[0]));
-
-    /* disable all features */
-    assert_int_equal(LY_SUCCESS, lys_feature_disable(mod, "*"));
-    LY_ARRAY_FOR(mod->features, struct lysc_feature, f) {
-        assert_int_equal(LY_ENOT, lys_feature_value(mod, f->name));
-    }
-    /* re-setting already set feature */
-    assert_int_equal(LY_SUCCESS, lys_feature_disable(mod, "f1"));
-    assert_int_equal(LY_ENOT, lys_feature_value(mod, "f1"));
-
-    /* enabling feature that cannot be enabled due to its if-features */
-    assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f1"));
-    assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "andfeature"));
-    logbuf_assert("Feature \"andfeature\" cannot be enabled since it is disabled by its if-feature condition(s).");
-    assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "*"));
-    logbuf_assert("Feature \"f6\" cannot be enabled since it is disabled by its if-feature condition(s).");
-    /* test if not changed */
-    assert_int_equal(LY_SUCCESS, lys_feature_value(mod, "f1"));
-    assert_int_equal(LY_ENOT, lys_feature_value(mod, "f2"));
-
-    TEST_SCHEMA_OK(ctx, 0, 0, "b", "feature f1 {if-feature f2;}feature f2;", mod);
-    assert_non_null(mod->features);
-    assert_int_equal(2, LY_ARRAY_COUNT(mod->features));
-    assert_non_null(mod->features[0].iffeatures);
-    assert_int_equal(1, LY_ARRAY_COUNT(mod->features[0].iffeatures));
-    assert_non_null(mod->features[0].iffeatures[0].features);
-    assert_int_equal(1, LY_ARRAY_COUNT(mod->features[0].iffeatures[0].features));
-    assert_ptr_equal(&mod->features[1], mod->features[0].iffeatures[0].features[0]);
-    assert_non_null(mod->features);
-    assert_int_equal(2, LY_ARRAY_COUNT(mod->features));
-    assert_non_null(mod->features[1].depfeatures);
-    assert_int_equal(1, LY_ARRAY_COUNT(mod->features[1].depfeatures));
-    assert_ptr_equal(&mod->features[0], mod->features[1].depfeatures[0]);
-
-    /* invalid reference */
-    assert_int_equal(LY_ENOTFOUND, lys_feature_enable(mod, "xxx"));
-    logbuf_assert("Feature \"xxx\" not found in module \"b\".");
 
     /* some invalid expressions */
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature f1;}",
-                    "Invalid value \"f1\" of if-feature - unable to find feature \"f1\". /inv:{feature='f'}");
+                    "Invalid value \"f1\" of if-feature - unable to find feature \"f1\".");
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f and';}",
-                    "Invalid value \"f and\" of if-feature - unexpected end of expression. /inv:{feature='f2'}");
+                    "Invalid value \"f and\" of if-feature - unexpected end of expression.");
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature 'or';}",
-                    "Invalid value \"or\" of if-feature - unexpected end of expression. /inv:{feature='f'}");
+                    "Invalid value \"or\" of if-feature - unexpected end of expression.");
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature '(f1';}",
-                    "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses. /inv:{feature='f2'}");
+                    "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses.");
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f1)';}",
-                    "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses. /inv:{feature='f2'}");
+                    "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses.");
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature ---;}",
-                    "Invalid value \"---\" of if-feature - unable to find feature \"---\". /inv:{feature='f2'}");
+                    "Invalid value \"---\" of if-feature - unable to find feature \"---\".");
     TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f2{if-feature 'not f1';}",
-                    "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module. /inv:{feature='f2'}");
+                    "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module.");
     TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f1;",
-                    "Duplicate identifier \"f1\" of feature statement. /inv:{feature='f1'}");
+                    "Duplicate identifier \"f1\" of feature statement. Line number 1.");
 
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} feature f1;}");
     TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "include inv_sub;feature f1;",
-                    "Duplicate identifier \"f1\" of feature statement. /inv:{feature='f1'}");
+                    "Duplicate identifier \"f1\" of feature statement. Line number 1.");
     TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f2;} feature f2 {if-feature f1;}",
-                    "Feature \"f1\" is indirectly referenced from itself. /inv:{feature='f2'}");
+                    "Feature \"f1\" is indirectly referenced from itself.");
     TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f1;}",
-                    "Feature \"f1\" is referenced from itself. /inv:{feature='f1'}");
+                    "Feature \"f1\" is referenced from itself.");
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f {if-feature ();}",
-                    "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations. /inv:{feature='f'}");
+                    "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations.");
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1(';}",
-                    "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses. /inv:{feature='f'}");
+                    "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses.");
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'and f1';}",
-                    "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation. /inv:{feature='f'}");
+                    "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation.");
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not ';}",
-                    "Invalid value \"f1 not \" of if-feature - unexpected end of expression. /inv:{feature='f'}");
+                    "Invalid value \"f1 not \" of if-feature - unexpected end of expression.");
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not not ';}",
-                    "Invalid value \"f1 not not \" of if-feature - unexpected end of expression. /inv:{feature='f'}");
+                    "Invalid value \"f1 not not \" of if-feature - unexpected end of expression.");
     TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2; feature f {if-feature 'or f1 f2';}",
-                    "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation. /inv:{feature='f'}");
-
-    /* import reference */
-    assert_non_null(mod = ly_ctx_get_module(ctx, "a", NULL));
-    assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f1"));
-    TEST_SCHEMA_OK(ctx, 0, 0, "c", "import a {prefix a;} feature f1; feature f2{if-feature 'a:f1';}", mod);
-    assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f2"));
-    assert_int_equal(LY_ENOT, lys_feature_value(mod, "f1"));
-    assert_int_equal(LY_SUCCESS, lys_feature_value(mod, "f2"));
+                    "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation.");
 
     /*
      * printing