Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename LogicalNot to AnnotationNot #1307

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/evaluator/evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -637,21 +637,6 @@ auto evaluate_step(
EVALUATE_END(logical, SchemaCompilerLogicalCondition);
}

case IS_STEP(SchemaCompilerLogicalNot): {
EVALUATE_BEGIN_NO_PRECONDITION(logical, SchemaCompilerLogicalNot);
// Ignore annotations produced inside "not"
context.mask();
result = false;
for (const auto &child : logical.children) {
if (!evaluate_step(child, callback, context)) {
result = true;
break;
}
}

EVALUATE_END(logical, SchemaCompilerLogicalNot);
}

case IS_STEP(SchemaCompilerControlLabel): {
EVALUATE_BEGIN_NO_PRECONDITION(control, SchemaCompilerControlLabel);
context.mark(control.value, control.children);
Expand Down Expand Up @@ -847,6 +832,20 @@ auto evaluate_step(
EVALUATE_END(loop, SchemaCompilerAnnotationLoopItemsUnevaluated);
}

case IS_STEP(SchemaCompilerAnnotationNot): {
EVALUATE_BEGIN_NO_PRECONDITION(logical, SchemaCompilerAnnotationNot);
// Ignore annotations produced inside "not"
context.mask();
for (const auto &child : logical.children) {
if (!evaluate_step(child, callback, context)) {
result = true;
break;
}
}

EVALUATE_END(logical, SchemaCompilerAnnotationNot);
}

case IS_STEP(SchemaCompilerLoopPropertiesMatch): {
EVALUATE_BEGIN(loop, SchemaCompilerLoopPropertiesMatch,
target.is_object());
Expand Down
21 changes: 10 additions & 11 deletions src/evaluator/include/sourcemeta/jsontoolkit/evaluator_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ struct SchemaCompilerAnnotationBasenameToParent;
struct SchemaCompilerAnnotationLoopPropertiesUnevaluated;
struct SchemaCompilerAnnotationLoopItemsUnmarked;
struct SchemaCompilerAnnotationLoopItemsUnevaluated;
struct SchemaCompilerAnnotationNot;
struct SchemaCompilerLogicalOr;
struct SchemaCompilerLogicalAnd;
struct SchemaCompilerLogicalXor;
struct SchemaCompilerLogicalCondition;
struct SchemaCompilerLogicalNot;
struct SchemaCompilerLogicalWhenType;
struct SchemaCompilerLogicalWhenDefines;
struct SchemaCompilerLogicalWhenArraySizeGreater;
Expand Down Expand Up @@ -103,11 +103,10 @@ using SchemaCompilerTemplate = std::vector<std::variant<
SchemaCompilerAnnotationToParent, SchemaCompilerAnnotationBasenameToParent,
SchemaCompilerAnnotationLoopPropertiesUnevaluated,
SchemaCompilerAnnotationLoopItemsUnmarked,
SchemaCompilerAnnotationLoopItemsUnevaluated, SchemaCompilerLogicalOr,
SchemaCompilerLogicalAnd, SchemaCompilerLogicalXor,
SchemaCompilerLogicalCondition, SchemaCompilerLogicalNot,
SchemaCompilerLogicalWhenType, SchemaCompilerLogicalWhenDefines,
SchemaCompilerLogicalWhenArraySizeGreater,
SchemaCompilerAnnotationLoopItemsUnevaluated, SchemaCompilerAnnotationNot,
SchemaCompilerLogicalOr, SchemaCompilerLogicalAnd, SchemaCompilerLogicalXor,
SchemaCompilerLogicalCondition, SchemaCompilerLogicalWhenType,
SchemaCompilerLogicalWhenDefines, SchemaCompilerLogicalWhenArraySizeGreater,
SchemaCompilerLogicalWhenArraySizeEqual, SchemaCompilerLoopPropertiesMatch,
SchemaCompilerLoopProperties, SchemaCompilerLoopPropertiesRegex,
SchemaCompilerLoopPropertiesExcept, SchemaCompilerLoopPropertiesType,
Expand Down Expand Up @@ -157,11 +156,11 @@ enum class SchemaCompilerTemplateIndex : std::uint8_t {
SchemaCompilerAnnotationLoopPropertiesUnevaluated,
SchemaCompilerAnnotationLoopItemsUnmarked,
SchemaCompilerAnnotationLoopItemsUnevaluated,
SchemaCompilerAnnotationNot,
SchemaCompilerLogicalOr,
SchemaCompilerLogicalAnd,
SchemaCompilerLogicalXor,
SchemaCompilerLogicalCondition,
SchemaCompilerLogicalNot,
SchemaCompilerLogicalWhenType,
SchemaCompilerLogicalWhenDefines,
SchemaCompilerLogicalWhenArraySizeGreater,
Expand Down Expand Up @@ -405,6 +404,10 @@ DEFINE_STEP_APPLICATOR(Annotation, LoopItemsUnmarked, SchemaCompilerValueString)
DEFINE_STEP_APPLICATOR(Annotation, LoopItemsUnevaluated,
SchemaCompilerValueItemsAnnotationKeywords)

/// @ingroup evaluator_instructions
/// @brief Represents a compiler logical step that represents a negation
DEFINE_STEP_APPLICATOR(Annotation, Not, SchemaCompilerValueNone)

/// @ingroup evaluator_instructions
/// @brief Represents a compiler logical step that represents a disjunction
DEFINE_STEP_APPLICATOR(Logical, Or, SchemaCompilerValueBoolean)
Expand All @@ -422,10 +425,6 @@ DEFINE_STEP_APPLICATOR(Logical, Xor, SchemaCompilerValueBoolean)
/// @brief Represents an imperative conditional compiler logical step
DEFINE_STEP_APPLICATOR(Logical, Condition, SchemaCompilerValueIndexPair)

/// @ingroup evaluator_instructions
/// @brief Represents a compiler logical step that represents a negation
DEFINE_STEP_APPLICATOR(Logical, Not, SchemaCompilerValueNone)

/// @ingroup evaluator_instructions
/// @brief Represents a compiler logical step that represents a conjunction when
/// the instance is of a given type
Expand Down
2 changes: 1 addition & 1 deletion src/jsonschema/compile_describe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ struct DescribeVisitor {
return unknown();
}

auto operator()(const SchemaCompilerLogicalNot &) const -> std::string {
auto operator()(const SchemaCompilerAnnotationNot &) const -> std::string {
std::ostringstream message;
message
<< "The " << to_string(this->target.type())
Expand Down
2 changes: 1 addition & 1 deletion src/jsonschema/compile_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ struct StepVisitor {
SchemaCompilerAnnotationLoopItemsUnmarked)
HANDLE_STEP("annotation", "loop-items-unevaluated",
SchemaCompilerAnnotationLoopItemsUnevaluated)
HANDLE_STEP("annotation", "not", SchemaCompilerAnnotationNot)
HANDLE_STEP("logical", "or", SchemaCompilerLogicalOr)
HANDLE_STEP("logical", "and", SchemaCompilerLogicalAnd)
HANDLE_STEP("logical", "xor", SchemaCompilerLogicalXor)
HANDLE_STEP("logical", "condition", SchemaCompilerLogicalCondition)
HANDLE_STEP("logical", "not", SchemaCompilerLogicalNot)
HANDLE_STEP("logical", "when-type", SchemaCompilerLogicalWhenType)
HANDLE_STEP("logical", "when-defines", SchemaCompilerLogicalWhenDefines)
HANDLE_STEP("logical", "when-array-size-greater",
Expand Down
3 changes: 2 additions & 1 deletion src/jsonschema/default_compiler_draft4.h
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,8 @@ auto compiler_draft4_applicator_not(
const SchemaCompilerSchemaContext &schema_context,
const SchemaCompilerDynamicContext &dynamic_context)
-> SchemaCompilerTemplate {
return {make<SchemaCompilerLogicalNot>(
// TODO: Don't mask annotations if annotations are not needed
return {make<SchemaCompilerAnnotationNot>(
true, context, schema_context, dynamic_context, SchemaCompilerValueNone{},
compile(context, schema_context, relative_dynamic_context, empty_pointer,
empty_pointer))};
Expand Down
12 changes: 6 additions & 6 deletions test/evaluator/evaluator_draft4_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2207,12 +2207,12 @@ TEST(JSONSchema_evaluator_draft4, not_1) {
const sourcemeta::jsontoolkit::JSON instance{5};
EVALUATE_WITH_TRACE_FAST_SUCCESS(schema, instance, 2);

EVALUATE_TRACE_PRE(0, LogicalNot, "/not", "#/not", "");
EVALUATE_TRACE_PRE(0, AnnotationNot, "/not", "#/not", "");
EVALUATE_TRACE_PRE(1, AssertionTypeStrict, "/not/type", "#/not/type", "");

EVALUATE_TRACE_POST_FAILURE(0, AssertionTypeStrict, "/not/type", "#/not/type",
"");
EVALUATE_TRACE_POST_SUCCESS(1, LogicalNot, "/not", "#/not", "");
EVALUATE_TRACE_POST_SUCCESS(1, AnnotationNot, "/not", "#/not", "");

EVALUATE_TRACE_POST_DESCRIBE(
instance, 0,
Expand All @@ -2234,12 +2234,12 @@ TEST(JSONSchema_evaluator_draft4, not_2) {
const sourcemeta::jsontoolkit::JSON instance{"foo"};
EVALUATE_WITH_TRACE_FAST_FAILURE(schema, instance, 2);

EVALUATE_TRACE_PRE(0, LogicalNot, "/not", "#/not", "");
EVALUATE_TRACE_PRE(0, AnnotationNot, "/not", "#/not", "");
EVALUATE_TRACE_PRE(1, AssertionTypeStrict, "/not/type", "#/not/type", "");

EVALUATE_TRACE_POST_SUCCESS(0, AssertionTypeStrict, "/not/type", "#/not/type",
"");
EVALUATE_TRACE_POST_FAILURE(1, LogicalNot, "/not", "#/not", "");
EVALUATE_TRACE_POST_FAILURE(1, AnnotationNot, "/not", "#/not", "");

EVALUATE_TRACE_POST_DESCRIBE(instance, 0,
"The value was expected to be of type string");
Expand Down Expand Up @@ -2269,7 +2269,7 @@ TEST(JSONSchema_evaluator_draft4, not_3) {

EVALUATE_WITH_TRACE_FAST_SUCCESS(schema, instance, 4);

EVALUATE_TRACE_PRE(0, LogicalNot, "/not", "#/not", "");
EVALUATE_TRACE_PRE(0, AnnotationNot, "/not", "#/not", "");
EVALUATE_TRACE_PRE(1, AssertionPropertyTypeStrict, "/not/properties/foo/type",
"#/not/properties/foo/type", "/foo");
EVALUATE_TRACE_PRE(2, LoopPropertiesExcept, "/not/additionalProperties",
Expand All @@ -2286,7 +2286,7 @@ TEST(JSONSchema_evaluator_draft4, not_3) {
EVALUATE_TRACE_POST_FAILURE(2, LoopPropertiesExcept,
"/not/additionalProperties",
"#/not/additionalProperties", "");
EVALUATE_TRACE_POST_SUCCESS(3, LogicalNot, "/not", "#/not", "");
EVALUATE_TRACE_POST_SUCCESS(3, AnnotationNot, "/not", "#/not", "");

EVALUATE_TRACE_POST_DESCRIBE(instance, 0,
"The value was expected to be of type boolean");
Expand Down