welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
Loading...
Searching...
No Matches
naming.hpp File Reference

Language-agnostic name styling: reshape a C++ identifier into a target language's naming convention, and resolve the final bound name of an entity (honouring a verbatim [[=welder::weld_as]] override first). More...

#include <meta>
#include <stdexcept>
#include <string>
#include <string_view>
#include <vector>
#include <welder/concepts.hpp>
Include dependency graph for naming.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  welder::naming::none
 The identity style: bind every C++ identifier unchanged. More...
struct  welder::naming::uniform< Kind >
 A single-convention style: reshape every kind to convention Kind, whatever the source spelling. More...

Namespaces

namespace  welder
namespace  welder::naming

Typedefs

using welder::naming::snake_case = uniform<case_kind::snake>
 foo_bar everywhere
using welder::naming::screaming_snake_case = uniform<case_kind::screaming_snake>
 FOO_BAR everywhere
using welder::naming::kebab_case = uniform<case_kind::kebab>
 foo-bar everywhere
using welder::naming::camel_case = uniform<case_kind::camel>
 fooBar everywhere
using welder::naming::pascal_case = uniform<case_kind::pascal>
 FooBar everywhere

Enumerations

enum class  welder::naming::case_kind {
  welder::naming::snake , welder::naming::screaming_snake , welder::naming::kebab , welder::naming::camel ,
  welder::naming::pascal
}
 The naming convention a joiner emits. More...
enum class  welder::ent_kind {
  welder::class_ , welder::enum_ , welder::enumerator , welder::method ,
  welder::static_method , welder::function , welder::field , welder::variable ,
  welder::submodule
}
 The nameable entity kinds welder distinguishes, one per name-style hook — picked by the driver/rod so name_of calls the right transform. More...

Functions

consteval std::vector< std::string > welder::naming::split_words (std::string_view id)
 Split an identifier into lower-cased words, however it was spelled.
consteval std::string welder::naming::join_words (const std::vector< std::string > &words, case_kind kind)
 Join already-lower-cased words in convention kind.
consteval std::string welder::naming::restyle (std::string_view id, case_kind kind)
 Re-spell identifier id in convention kind, preserving any leading and trailing underscore run (_private / type_ keep their fixup underscores).
template<std::meta::info Ent, lang L>
consteval const char * welder::weld_as_of ()
 The verbatim weld_as name forced on Ent for language L, or nullptr.
template<std::meta::info Ent, lang L, class Style, ent_kind K>
consteval const char * welder::name_of ()
 The final bound name of Ent (a K-kind entity) for language L under name style Style.
template<std::meta::info Ent, lang L, class Style, ent_kind K>
constexpr const char * welder::name_of_or (const char *override_)
 Resolve a bound name with a call-site override: override_ wins verbatim, nullptr falls back to name_of.

Detailed Description

Language-agnostic name styling: reshape a C++ identifier into a target language's naming convention, and resolve the final bound name of an entity (honouring a verbatim [[=welder::weld_as]] override first).

C++ code follows one house style (processFile, HTTPServer, max_count); the language it is bound to usually wants another (PEP 8 asks for process_file and MaxCount). A name style is the pluggable customization point that does that reshaping — you hand one to welder::welder<Rod, Style> and every generated name flows through it.

The style is asked to name each entity through a per-kind hooktransform_class, transform_method, transform_field, transform_enumerator, … — because the driver already knows what it is binding, and the same identifier is styled differently by kind (PEP 8 PascalCases a class but snake_cases a method). A style therefore never has to inspect the reflection to discover the kind; it just implements the hooks it wants to reshape and inherits the rest.

The hard part each hook faces is that the input format is unknown: an identifier may arrive in snake_case, camelCase, PascalCase or SCREAMING_CASE. So the shared machinery here first splits an identifier into its constituent words (on underscores/hyphens, camel-case humps and acronym boundaries), then re-joins them in the requested convention — a round-trip stable regardless of the source spelling. welder::naming::none is the identity (bind the C++ identifier unchanged, the default); the single-convention styles (snake_case, pascal_case, …) apply one convention to every kind; a convention mix that depends on the kind (PEP 8) is built per language beside the rods (e.g. welder::rods::python::pep8).

Note
Like <welder/reflect.hpp>/<welder/doc.hpp>, this depends on the welder vocabulary (welder::detail::weld_as_spec, lang, lang_bit) but deliberately does NOT include <welder/annotations.hpp>: the vocabulary may instead arrive via import welder;. Provide the vocabulary first, then this header.

Definition in file naming.hpp.