libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
printf_frontend_detail.hpp
1#pragma once
2
3#include <array>
4#include <limits>
5#include <string_view>
6
7#include "../format_compile.hpp"
9namespace LibXR::Print::Detail::PrintfCompile
17
18// These implementation headers form an ordered dependency chain.
19// clang-format off
20#include "printf_frontend_spec.hpp"
21
22#include "printf_frontend_source.hpp"
23// clang-format on
25namespace FieldSelection = SourceSyntax::FieldSelection;
26
35template <Text Source>
36[[nodiscard]] consteval auto Analyze()
40
50template <Text Source>
51[[nodiscard]] consteval Error WalkSourceAsFormatFields(auto& visitor)
52{
53 struct ResolvingVisitor
54 {
55 decltype(visitor)& inner;
56
57 [[nodiscard]] consteval Error Text(size_t offset, size_t text_size)
58 {
59 return inner.Text(offset, text_size);
60 }
62 [[nodiscard]] consteval Error Field(const Conversion& conversion)
63 {
64 return inner.Field(FieldSelection::BuildFormatField(conversion));
65 }
66 };
67
68 ResolvingVisitor resolving{visitor};
69 return SourceSyntax::WalkSource(std::string_view(Source.Data(), Source.Size()),
70 resolving);
71}
72} // namespace LibXR::Print::Detail::PrintfCompile
73
74namespace LibXR::Print
75{
81template <Text Source>
83{
84 public:
86
92 [[nodiscard]] static constexpr const char* SourceData() { return Source.Data(); }
98 [[nodiscard]] static constexpr size_t SourceSize() { return Source.Size(); }
99
108 [[nodiscard]] static consteval ErrorType Walk(auto& visitor)
109 {
110 return Detail::PrintfCompile::WalkSourceAsFormatFields<Source>(visitor);
111 }
112};
113} // namespace LibXR::Print
单个 printf 源字符串的编译期前端,负责解析并降为共享格式语义 / Compile-time printf frontend that parses and lowers one source s...
static consteval ErrorType Walk(auto &visitor)
按源串顺序遍历这条字面量,并产出文本片段和最终字段记录 / Walk the literal in source order and emit text spans plus final field r...
static constexpr size_t SourceSize()
返回去掉结尾零字节后的源字符串长度 / Return the source length without the terminating zero byte
static constexpr const char * SourceData()
返回去掉结尾零字节后的源字符串数据 / Return the underlying source bytes without the terminating zero byte
Length
归一化后的 printf 长度修饰符 / Supported printf length modifiers after normalization
Definition printf.hpp:65
Error
通过 static_assert 暴露的编译期解析或构建失败类别 / Compile-time parse or build failure categories surfaced through st...
Definition printf.hpp:82
consteval Error WalkSource(std::string_view source, auto &visitor)
遍历一个 printf 源字符串,并发射字面文本片段与已解析转换项 / Walk one printf source string and emit literal-text spans plus pa...
consteval auto Analyze()
对一个 printf 字面量执行仅源串分析,并返回按顺序整理的参数引用摘要 / Run source-only analysis for one printf literal and return th...
单个 printf 转换在降为共享格式前的解析结果 / One parsed printf conversion before lowering into the shared format
作为 printf 格式源的结构化字符串字面量包装 / Structural literal wrapper used as the NTTP source for printf formats
Definition printf.hpp:17
constexpr Text(const char(&text)[N])
将字符串字面量复制到结构化 NTTP 对象中 / Copy the string literal into the structural NTTP object
Definition printf.hpp:29