Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
22a42c0b
Commit
22a42c0b
authored
Aug 04, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup compile implementation
parent
c63624ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
44 deletions
+34
-44
include/fmt/compile.h
include/fmt/compile.h
+34
-44
No files found.
include/fmt/compile.h
View file @
22a42c0b
...
@@ -100,19 +100,17 @@ template <typename Char> struct format_part {
...
@@ -100,19 +100,17 @@ template <typename Char> struct format_part {
template
<
typename
Char
,
typename
PartsContainer
>
template
<
typename
Char
,
typename
PartsContainer
>
class
format_preparation_handler
:
public
internal
::
error_handler
{
class
format_preparation_handler
:
public
internal
::
error_handler
{
private:
private:
typedef
format_part
<
Char
>
part
;
using
part
=
format_part
<
Char
>
;
public:
public:
typedef
typename
basic_string_view
<
Char
>::
iterator
iterator
;
using
iterator
=
typename
basic_string_view
<
Char
>::
iterator
;
FMT_CONSTEXPR
format_preparation_handler
(
basic_string_view
<
Char
>
format
,
FMT_CONSTEXPR
format_preparation_handler
(
basic_string_view
<
Char
>
format
,
PartsContainer
&
parts
)
PartsContainer
&
parts
)
:
parts_
(
parts
),
format_
(
format
),
parse_context_
(
format
)
{}
:
parts_
(
parts
),
format_
(
format
),
parse_context_
(
format
)
{}
FMT_CONSTEXPR
void
on_text
(
const
Char
*
begin
,
const
Char
*
end
)
{
FMT_CONSTEXPR
void
on_text
(
const
Char
*
begin
,
const
Char
*
end
)
{
if
(
begin
==
end
)
{
if
(
begin
==
end
)
return
;
return
;
}
const
auto
offset
=
begin
-
format_
.
data
();
const
auto
offset
=
begin
-
format_
.
data
();
const
auto
size
=
end
-
begin
;
const
auto
size
=
end
-
begin
;
parts_
.
add
(
part
(
string_view_metadata
(
offset
,
size
)));
parts_
.
add
(
part
(
string_view_metadata
(
offset
,
size
)));
...
@@ -143,14 +141,12 @@ class format_preparation_handler : public internal::error_handler {
...
@@ -143,14 +141,12 @@ class format_preparation_handler : public internal::error_handler {
const
Char
*
end
)
{
const
Char
*
end
)
{
const
auto
specs_offset
=
to_unsigned
(
begin
-
format_
.
begin
());
const
auto
specs_offset
=
to_unsigned
(
begin
-
format_
.
begin
());
typedef
basic_parse_context
<
Char
>
parse_context
;
using
parse_context
=
basic_parse_context
<
Char
>
;
internal
::
dynamic_format_specs
<
Char
>
parsed_specs
;
internal
::
dynamic_format_specs
<
Char
>
parsed_specs
;
dynamic_specs_handler
<
parse_context
>
handler
(
parsed_specs
,
parse_context_
);
dynamic_specs_handler
<
parse_context
>
handler
(
parsed_specs
,
parse_context_
);
begin
=
parse_format_specs
(
begin
,
end
,
handler
);
begin
=
parse_format_specs
(
begin
,
end
,
handler
);
if
(
*
begin
!=
'}'
)
{
if
(
*
begin
!=
'}'
)
on_error
(
"missing '}' in format string"
);
on_error
(
"missing '}' in format string"
);
}
const
auto
last_part
=
parts_
.
last
();
const
auto
last_part
=
parts_
.
last
();
...
@@ -185,7 +181,7 @@ class prepared_format {
...
@@ -185,7 +181,7 @@ class prepared_format {
prepared_format
()
=
delete
;
prepared_format
()
=
delete
;
typedef
buffer_context
<
char_type
>
context
;
using
context
=
buffer_context
<
char_type
>
;
template
<
typename
Range
,
typename
Context
>
template
<
typename
Range
,
typename
Context
>
auto
vformat_to
(
Range
out
,
basic_format_args
<
Context
>
args
)
const
->
auto
vformat_to
(
Range
out
,
basic_format_args
<
Context
>
args
)
const
->
...
@@ -288,9 +284,7 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
...
@@ -288,9 +284,7 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
FMT_CONSTEXPR
count_handler
()
:
counter_
(
0u
)
{}
FMT_CONSTEXPR
count_handler
()
:
counter_
(
0u
)
{}
FMT_CONSTEXPR
void
on_text
(
const
char_type
*
begin
,
const
char_type
*
end
)
{
FMT_CONSTEXPR
void
on_text
(
const
char_type
*
begin
,
const
char_type
*
end
)
{
if
(
begin
!=
end
)
{
if
(
begin
!=
end
)
++
counter_
;
++
counter_
;
}
}
}
FMT_CONSTEXPR
void
on_arg_id
()
{
++
counter_
;
}
FMT_CONSTEXPR
void
on_arg_id
()
{
++
counter_
;
}
...
@@ -316,13 +310,10 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
...
@@ -316,13 +310,10 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
if
(
*
begin
==
'{'
)
{
if
(
*
begin
==
'{'
)
{
++
braces_counter
;
++
braces_counter
;
}
else
if
(
*
begin
==
'}'
)
{
}
else
if
(
*
begin
==
'}'
)
{
if
(
braces_counter
==
0u
)
{
if
(
braces_counter
==
0u
)
break
;
break
;
}
--
braces_counter
;
--
braces_counter
;
}
}
}
}
return
begin
;
return
begin
;
}
}
...
@@ -348,7 +339,7 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
...
@@ -348,7 +339,7 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
public:
public:
template
<
unsigned
N
>
struct
format_parts_array
{
template
<
unsigned
N
>
struct
format_parts_array
{
typedef
format_part
<
char_type
>
value_type
;
using
value_type
=
format_part
<
char_type
>
;
FMT_CONSTEXPR
format_parts_array
()
:
arr
{}
{}
FMT_CONSTEXPR
format_parts_array
()
:
arr
{}
{}
...
@@ -364,7 +355,7 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
...
@@ -364,7 +355,7 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
struct
empty
{
struct
empty
{
// Parts preparator will search for it
// Parts preparator will search for it
typedef
format_part
<
char_type
>
value_type
;
using
value_type
=
format_part
<
char_type
>
;
};
};
using
type
=
conditional_t
<
static_cast
<
bool
>
(
number_of_format_parts
),
using
type
=
conditional_t
<
static_cast
<
bool
>
(
number_of_format_parts
),
...
@@ -373,7 +364,7 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
...
@@ -373,7 +364,7 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
template
<
typename
Parts
>
class
compiletime_prepared_parts_collector
{
template
<
typename
Parts
>
class
compiletime_prepared_parts_collector
{
private:
private:
typedef
typename
Parts
::
value_type
format_part
;
using
format_part
=
typename
Parts
::
value_type
;
public:
public:
FMT_CONSTEXPR
explicit
compiletime_prepared_parts_collector
(
Parts
&
parts
)
FMT_CONSTEXPR
explicit
compiletime_prepared_parts_collector
(
Parts
&
parts
)
...
@@ -403,7 +394,7 @@ FMT_CONSTEXPR PartsContainer prepare_parts(basic_string_view<Char> format) {
...
@@ -403,7 +394,7 @@ FMT_CONSTEXPR PartsContainer prepare_parts(basic_string_view<Char> format) {
template
<
typename
PartsContainer
,
typename
Char
>
template
<
typename
PartsContainer
,
typename
Char
>
FMT_CONSTEXPR
PartsContainer
FMT_CONSTEXPR
PartsContainer
prepare_compiletime_parts
(
basic_string_view
<
Char
>
format
)
{
prepare_compiletime_parts
(
basic_string_view
<
Char
>
format
)
{
typedef
compiletime_prepared_parts_collector
<
PartsContainer
>
collector
;
using
collector
=
compiletime_prepared_parts_collector
<
PartsContainer
>
;
PartsContainer
parts
;
PartsContainer
parts
;
collector
c
(
parts
);
collector
c
(
parts
);
...
@@ -454,7 +445,7 @@ struct parts_container_concept_check : std::true_type {
...
@@ -454,7 +445,7 @@ struct parts_container_concept_check : std::true_type {
:
std
::
true_type
{};
:
std
::
true_type
{};
static_assert
(
has_format_part_type
<
PartsContainer
>::
value
,
static_assert
(
has_format_part_type
<
PartsContainer
>::
value
,
"PartsContainer doesn't provide format_part_type
typedef
"
);
"PartsContainer doesn't provide format_part_type"
);
struct
check_second
{};
struct
check_second
{};
struct
check_first
:
check_second
{};
struct
check_first
:
check_second
{};
...
@@ -464,14 +455,14 @@ struct parts_container_concept_check : std::true_type {
...
@@ -464,14 +455,14 @@ struct parts_container_concept_check : std::true_type {
static
decltype
(
static
decltype
(
(
void
)
std
::
declval
<
T
>
().
add
(
std
::
declval
<
typename
T
::
format_part_type
>
()),
(
void
)
std
::
declval
<
T
>
().
add
(
std
::
declval
<
typename
T
::
format_part_type
>
()),
std
::
true_type
())
has_add_check
(
check_first
);
std
::
true_type
())
has_add_check
(
check_first
);
typedef
decltype
(
has_add_check
<
PartsContainer
>
(
check_first
()))
has_add
;
using
has_add
=
decltype
(
has_add_check
<
PartsContainer
>
(
check_first
()))
;
static_assert
(
has_add
::
value
,
"PartsContainer doesn't provide add() method"
);
static_assert
(
has_add
::
value
,
"PartsContainer doesn't provide add() method"
);
template
<
typename
T
>
static
std
::
false_type
has_last_check
(
check_second
);
template
<
typename
T
>
static
std
::
false_type
has_last_check
(
check_second
);
template
<
typename
T
>
template
<
typename
T
>
static
decltype
((
void
)
std
::
declval
<
T
>
().
last
(),
static
decltype
((
void
)
std
::
declval
<
T
>
().
last
(),
std
::
true_type
())
has_last_check
(
check_first
);
std
::
true_type
())
has_last_check
(
check_first
);
typedef
decltype
(
has_last_check
<
PartsContainer
>
(
check_first
()))
has_last
;
using
has_last
=
decltype
(
has_last_check
<
PartsContainer
>
(
check_first
()))
;
static_assert
(
has_last
::
value
,
static_assert
(
has_last
::
value
,
"PartsContainer doesn't provide last() method"
);
"PartsContainer doesn't provide last() method"
);
...
@@ -481,8 +472,8 @@ struct parts_container_concept_check : std::true_type {
...
@@ -481,8 +472,8 @@ struct parts_container_concept_check : std::true_type {
static
decltype
((
void
)
std
::
declval
<
T
>
().
substitute_last
(
static
decltype
((
void
)
std
::
declval
<
T
>
().
substitute_last
(
std
::
declval
<
typename
T
::
format_part_type
>
()),
std
::
declval
<
typename
T
::
format_part_type
>
()),
std
::
true_type
())
has_substitute_last_check
(
check_first
);
std
::
true_type
())
has_substitute_last_check
(
check_first
);
typedef
decltype
(
has_substitute_last_check
<
PartsContainer
>
(
using
has_substitute_last
=
check_first
()))
has_substitute_last
;
decltype
(
has_substitute_last_check
<
PartsContainer
>
(
check_first
()))
;
static_assert
(
has_substitute_last
::
value
,
static_assert
(
has_substitute_last
::
value
,
"PartsContainer doesn't provide substitute_last() method"
);
"PartsContainer doesn't provide substitute_last() method"
);
...
@@ -490,7 +481,7 @@ struct parts_container_concept_check : std::true_type {
...
@@ -490,7 +481,7 @@ struct parts_container_concept_check : std::true_type {
template
<
typename
T
>
template
<
typename
T
>
static
decltype
((
void
)
std
::
declval
<
T
>
().
begin
(),
static
decltype
((
void
)
std
::
declval
<
T
>
().
begin
(),
std
::
true_type
())
has_begin_check
(
check_first
);
std
::
true_type
())
has_begin_check
(
check_first
);
typedef
decltype
(
has_begin_check
<
PartsContainer
>
(
check_first
()))
has_begin
;
using
has_begin
=
decltype
(
has_begin_check
<
PartsContainer
>
(
check_first
()))
;
static_assert
(
has_begin
::
value
,
static_assert
(
has_begin
::
value
,
"PartsContainer doesn't provide begin() method"
);
"PartsContainer doesn't provide begin() method"
);
...
@@ -498,32 +489,31 @@ struct parts_container_concept_check : std::true_type {
...
@@ -498,32 +489,31 @@ struct parts_container_concept_check : std::true_type {
template
<
typename
T
>
template
<
typename
T
>
static
decltype
((
void
)
std
::
declval
<
T
>
().
end
(),
static
decltype
((
void
)
std
::
declval
<
T
>
().
end
(),
std
::
true_type
())
has_end_check
(
check_first
);
std
::
true_type
())
has_end_check
(
check_first
);
typedef
decltype
(
has_end_check
<
PartsContainer
>
(
check_first
()))
has_end
;
using
has_end
=
decltype
(
has_end_check
<
PartsContainer
>
(
check_first
()))
;
static_assert
(
has_end
::
value
,
"PartsContainer doesn't provide end() method"
);
static_assert
(
has_end
::
value
,
"PartsContainer doesn't provide end() method"
);
};
};
template
<
bool
IS_CONSTEXPR
,
typename
Format
,
typename
/*PartsContainer*/
>
template
<
bool
IS_CONSTEXPR
,
typename
Format
,
typename
/*PartsContainer*/
>
struct
parts_provider_type
{
struct
parts_provider_type
{
typedef
compiletime_parts_provider
<
using
type
=
compiletime_parts_provider
<
Format
,
typename
compiletime_prepared_parts_type_provider
<
Format
>::
type
>
Format
,
typename
compiletime_prepared_parts_type_provider
<
Format
>::
type
>
;
type
;
};
};
template
<
typename
Format
,
typename
PartsContainer
>
template
<
typename
Format
,
typename
PartsContainer
>
struct
parts_provider_type
<
/*IS_CONSTEXPR=*/
false
,
Format
,
PartsContainer
>
{
struct
parts_provider_type
<
/*IS_CONSTEXPR=*/
false
,
Format
,
PartsContainer
>
{
static_assert
(
parts_container_concept_check
<
PartsContainer
>::
value
,
static_assert
(
parts_container_concept_check
<
PartsContainer
>::
value
,
"Parts container doesn't meet the concept"
);
"Parts container doesn't meet the concept"
);
typedef
runtime_parts_provider
<
PartsContainer
>
type
;
using
type
=
runtime_parts_provider
<
PartsContainer
>
;
};
};
template
<
typename
Format
,
typename
PreparedPartsContainer
,
typename
...
Args
>
template
<
typename
Format
,
typename
PreparedPartsContainer
,
typename
...
Args
>
struct
basic_prepared_format
{
struct
basic_prepared_format
{
typedef
internal
::
prepared_format
<
Format
,
using
type
=
typename
internal
::
parts_provider_type
<
internal
::
prepared_format
<
Format
,
is_compile_string
<
Format
>::
value
,
typename
internal
::
parts_provider_type
<
Format
,
PreparedPartsContainer
>::
type
,
is_compile_string
<
Format
>::
value
,
Format
,
Args
...
>
PreparedPartsContainer
>::
type
,
type
;
Args
...
>
;
};
};
template
<
typename
Char
>
template
<
typename
Char
>
...
@@ -539,7 +529,7 @@ std::basic_string<Char> to_runtime_format(const Char* format) {
...
@@ -539,7 +529,7 @@ std::basic_string<Char> to_runtime_format(const Char* format) {
template
<
typename
Char
,
typename
Container
=
std
::
vector
<
format_part
<
Char
>
>>
template
<
typename
Char
,
typename
Container
=
std
::
vector
<
format_part
<
Char
>
>>
class
parts_container
{
class
parts_container
{
public:
public:
typedef
format_part
<
Char
>
format_part_type
;
using
format_part_type
=
format_part
<
Char
>
;
void
add
(
format_part_type
part
)
{
parts_
.
push_back
(
std
::
move
(
part
));
}
void
add
(
format_part_type
part
)
{
parts_
.
push_back
(
std
::
move
(
part
));
}
...
@@ -572,9 +562,9 @@ class parts_container {
...
@@ -572,9 +562,9 @@ class parts_container {
// Delegate preparing to preparator, to take advantage of a partial
// Delegate preparing to preparator, to take advantage of a partial
// specialization.
// specialization.
template
<
typename
Format
,
typename
...
Args
>
struct
preparator
{
template
<
typename
Format
,
typename
...
Args
>
struct
preparator
{
typedef
parts_container
<
char_t
<
Format
>>
container
;
using
container
=
parts_container
<
char_t
<
Format
>>
;
typedef
typename
basic_prepared_format
<
Format
,
container
,
Args
...
>::
type
using
prepared_format_type
=
prepared_format_
type
;
typename
basic_prepared_format
<
Format
,
container
,
Args
...
>::
type
;
static
auto
prepare
(
Format
format
)
->
prepared_format_type
{
static
auto
prepare
(
Format
format
)
->
prepared_format_type
{
return
prepared_format_type
(
std
::
move
(
format
));
return
prepared_format_type
(
std
::
move
(
format
));
...
@@ -585,8 +575,8 @@ template <typename PassedFormat, typename PreparedFormatFormat,
...
@@ -585,8 +575,8 @@ template <typename PassedFormat, typename PreparedFormatFormat,
typename
PartsContainer
,
typename
...
Args
>
typename
PartsContainer
,
typename
...
Args
>
struct
preparator
<
PassedFormat
,
prepared_format
<
PreparedFormatFormat
,
struct
preparator
<
PassedFormat
,
prepared_format
<
PreparedFormatFormat
,
PartsContainer
,
Args
...
>>
{
PartsContainer
,
Args
...
>>
{
typedef
prepared_format
<
PreparedFormatFormat
,
PartsContainer
,
Args
...
>
using
prepared_format_type
=
prepared_format
_type
;
prepared_format
<
PreparedFormatFormat
,
PartsContainer
,
Args
...
>
;
static
auto
prepare
(
PassedFormat
format
)
->
prepared_format_type
{
static
auto
prepare
(
PassedFormat
format
)
->
prepared_format_type
{
return
prepared_format_type
(
std
::
move
(
format
));
return
prepared_format_type
(
std
::
move
(
format
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment