Skip to content

Commit b67a045

Browse files
authored
Introduce a new is_annotation helper for InstructionIndex (#398)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 33575d3 commit b67a045

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/compiler/include/sourcemeta/blaze/compiler_output.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class SOURCEMETA_BLAZE_COMPILER_EXPORT TraceOutput {
169169
TraceOutput(const ErrorOutput &) = delete;
170170
auto operator=(const TraceOutput &) -> TraceOutput & = delete;
171171

172-
enum class EntryType { Push, Pass, Fail };
172+
enum class EntryType { Push, Pass, Fail, Annotation };
173173

174174
struct Entry {
175175
const EntryType type;

src/evaluator/include/sourcemeta/blaze/evaluator_instruction.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,21 @@ constexpr std::string_view InstructionNames[] = {
207207
"ControlJump",
208208
"ControlDynamicAnchorJump"};
209209

210+
/// @ingroup evaluator
211+
/// Check if a given instruction type corresponds to an annotation
212+
inline auto is_annotation(const InstructionIndex type) noexcept -> bool {
213+
switch (type) {
214+
case InstructionIndex::AnnotationBasenameToParent:
215+
return true;
216+
case InstructionIndex::AnnotationToParent:
217+
return true;
218+
case InstructionIndex::AnnotationEmit:
219+
return true;
220+
default:
221+
return false;
222+
}
223+
}
224+
210225
// Forward declaration for defining a circular structure
211226
#ifndef DOXYGEN
212227
struct Instruction;

test/evaluator/evaluator_test.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,14 @@ TEST(Evaluator, cross_2012_12_ref_2019_09_without_id) {
125125
const sourcemeta::core::JSON instance{"test"};
126126
EXPECT_TRUE(evaluator.validate(compiled_schema, instance));
127127
}
128+
129+
TEST(Evaluator, is_annotation) {
130+
EXPECT_TRUE(sourcemeta::blaze::is_annotation(
131+
sourcemeta::blaze::InstructionIndex::AnnotationBasenameToParent));
132+
EXPECT_TRUE(sourcemeta::blaze::is_annotation(
133+
sourcemeta::blaze::InstructionIndex::AnnotationToParent));
134+
EXPECT_TRUE(sourcemeta::blaze::is_annotation(
135+
sourcemeta::blaze::InstructionIndex::AnnotationEmit));
136+
EXPECT_FALSE(sourcemeta::blaze::is_annotation(
137+
sourcemeta::blaze::InstructionIndex::AssertionFail));
138+
}

0 commit comments

Comments
 (0)