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"
8
9
namespace
LibXR::Print::Detail::PrintfCompile
10
{
15
using
Error
=
Printf::Error
;
16
using
Length
=
Printf::Length
;
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
24
25
namespace
FieldSelection = SourceSyntax::FieldSelection;
26
35
template
<Text Source>
36
[[nodiscard]]
consteval
auto
Analyze()
37
{
38
return
SourceSyntax::Analyze<Source>
();
39
}
40
50
template
<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
}
61
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
74
namespace
LibXR::Print
75
{
81
template
<Text Source>
82
class
Printf::Compiler
83
{
84
public
:
85
using
ErrorType
=
Printf::Error
;
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
LibXR::Print::Printf::Compiler
单个 printf 源字符串的编译期前端,负责解析并降为共享格式语义 / Compile-time printf frontend that parses and lowers one source s...
Definition
printf_frontend_detail.hpp:83
LibXR::Print::Printf::Compiler::Walk
static consteval ErrorType Walk(auto &visitor)
按源串顺序遍历这条字面量,并产出文本片段和最终字段记录 / Walk the literal in source order and emit text spans plus final field r...
Definition
printf_frontend_detail.hpp:108
LibXR::Print::Printf::Compiler::SourceSize
static constexpr size_t SourceSize()
返回去掉结尾零字节后的源字符串长度 / Return the source length without the terminating zero byte
Definition
printf_frontend_detail.hpp:98
LibXR::Print::Printf::Compiler::SourceData
static constexpr const char * SourceData()
返回去掉结尾零字节后的源字符串数据 / Return the underlying source bytes without the terminating zero byte
Definition
printf_frontend_detail.hpp:92
LibXR::Print::Printf::Length
Length
归一化后的 printf 长度修饰符 / Supported printf length modifiers after normalization
Definition
printf.hpp:65
LibXR::Print::Printf::Error
Error
通过 static_assert 暴露的编译期解析或构建失败类别 / Compile-time parse or build failure categories surfaced through st...
Definition
printf.hpp:82
LibXR::Print::Detail::PrintfCompile::SourceSyntax::WalkSource
consteval Error WalkSource(std::string_view source, auto &visitor)
遍历一个 printf 源字符串,并发射字面文本片段与已解析转换项 / Walk one printf source string and emit literal-text spans plus pa...
Definition
printf_frontend_detail.hpp:97
LibXR::Print::Detail::PrintfCompile::SourceSyntax::Analyze
consteval auto Analyze()
对一个 printf 字面量执行仅源串分析,并返回按顺序整理的参数引用摘要 / Run source-only analysis for one printf literal and return th...
Definition
printf_frontend_detail.hpp:166
LibXR::Print::Detail::PrintfCompile::Conversion
单个 printf 转换在降为共享格式前的解析结果 / One parsed printf conversion before lowering into the shared format
Definition
printf_frontend_detail.hpp:36
LibXR::Print::Text
作为 printf 格式源的结构化字符串字面量包装 / Structural literal wrapper used as the NTTP source for printf formats
Definition
printf.hpp:17
LibXR::Print::Text::Text
constexpr Text(const char(&text)[N])
将字符串字面量复制到结构化 NTTP 对象中 / Copy the string literal into the structural NTTP object
Definition
printf.hpp:29
src
core
print
printf
printf_frontend_detail.hpp
Generated by
1.12.0