Skip to content
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
2 changes: 1 addition & 1 deletion src/compiler/include/sourcemeta/blaze/compiler_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class SOURCEMETA_BLAZE_COMPILER_EXPORT TraceOutput {
TraceOutput(const ErrorOutput &) = delete;
auto operator=(const TraceOutput &) -> TraceOutput & = delete;

enum class EntryType { Push, Pass, Fail };
enum class EntryType { Push, Pass, Fail, Annotation };

struct Entry {
const EntryType type;
Expand Down
15 changes: 15 additions & 0 deletions src/evaluator/include/sourcemeta/blaze/evaluator_instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ constexpr std::string_view InstructionNames[] = {
"ControlJump",
"ControlDynamicAnchorJump"};

/// @ingroup evaluator
/// Check if a given instruction type corresponds to an annotation
inline auto is_annotation(const InstructionIndex type) noexcept -> bool {
switch (type) {
case InstructionIndex::AnnotationBasenameToParent:
return true;
case InstructionIndex::AnnotationToParent:
return true;
case InstructionIndex::AnnotationEmit:
return true;
default:
return false;
}
}

// Forward declaration for defining a circular structure
#ifndef DOXYGEN
struct Instruction;
Expand Down
11 changes: 11 additions & 0 deletions test/evaluator/evaluator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,14 @@ TEST(Evaluator, cross_2012_12_ref_2019_09_without_id) {
const sourcemeta::core::JSON instance{"test"};
EXPECT_TRUE(evaluator.validate(compiled_schema, instance));
}

TEST(Evaluator, is_annotation) {
EXPECT_TRUE(sourcemeta::blaze::is_annotation(
sourcemeta::blaze::InstructionIndex::AnnotationBasenameToParent));
EXPECT_TRUE(sourcemeta::blaze::is_annotation(
sourcemeta::blaze::InstructionIndex::AnnotationToParent));
EXPECT_TRUE(sourcemeta::blaze::is_annotation(
sourcemeta::blaze::InstructionIndex::AnnotationEmit));
EXPECT_FALSE(sourcemeta::blaze::is_annotation(
sourcemeta::blaze::InstructionIndex::AssertionFail));
}