Skip to content

Commit 094e689

Browse files
authored
Elevate the logic to get an instruction name to Instruction itself (#452)
As we will use this for other things now, like JSON serialisation. Fixes: #451 Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent 019c1d7 commit 094e689

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

src/compiler/compile_output_trace.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
#include <utility> // std::move
66
#include <variant> // std::visit
77

8-
static auto step_name(const sourcemeta::blaze::Instruction &instruction)
9-
-> std::string_view {
10-
return sourcemeta::blaze::InstructionNames
11-
[static_cast<std::underlying_type_t<sourcemeta::blaze::InstructionIndex>>(
12-
instruction.type)];
13-
}
14-
158
static auto try_vocabulary(
169
const std::optional<
1710
std::reference_wrapper<const sourcemeta::core::SchemaFrame>> &frame,
@@ -64,7 +57,7 @@ auto TraceOutput::operator()(
6457
const sourcemeta::core::WeakPointer &instance_location,
6558
const sourcemeta::core::JSON &annotation) -> void {
6659

67-
const auto short_step_name{step_name(step)};
60+
const auto short_step_name{step.name()};
6861
auto effective_evaluate_path{evaluate_path.resolve_from(this->base_)};
6962

7063
// Attempt to get vocabulary information if we can get it

src/evaluator/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT blaze NAME evaluator
22
FOLDER "Blaze/Evaluator"
33
PRIVATE_HEADERS error.h value.h instruction.h string_set.h
44
SOURCES evaluator.cc dispatch.inc.h
5-
evaluator_string_set.cc
5+
evaluator_string_set.cc evaluator_instruction.cc
66
evaluator_complete.h evaluator_dynamic.h
77
evaluator_track.h evaluator_fast.h)
88

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <sourcemeta/blaze/evaluator_instruction.h>
2+
3+
#include <type_traits> // std::underlying_type_t
4+
5+
namespace sourcemeta::blaze {
6+
7+
auto Instruction::name() const -> std::string_view {
8+
return InstructionNames[static_cast<std::underlying_type_t<InstructionIndex>>(
9+
this->type)];
10+
}
11+
12+
} // namespace sourcemeta::blaze

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef SOURCEMETA_BLAZE_EVALUATOR_TEMPLATE_H
22
#define SOURCEMETA_BLAZE_EVALUATOR_TEMPLATE_H
33

4+
#ifndef SOURCEMETA_BLAZE_EVALUATOR_EXPORT
5+
#include <sourcemeta/blaze/evaluator_export.h>
6+
#endif
7+
48
#include <sourcemeta/blaze/evaluator_value.h>
59

610
#include <sourcemeta/core/jsonpointer.h>
@@ -245,6 +249,10 @@ struct Instruction {
245249
const std::size_t schema_resource;
246250
const Value value;
247251
const Instructions children;
252+
253+
/// Get the name of the instruction as a string
254+
SOURCEMETA_BLAZE_EVALUATOR_EXPORT
255+
auto name() const -> std::string_view;
248256
};
249257

250258
} // namespace sourcemeta::blaze

0 commit comments

Comments
 (0)