Skip to content

Commit bda8dcd

Browse files
committed
Rename/format
1 parent 6b7ebeb commit bda8dcd

59 files changed

Lines changed: 408 additions & 559 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-tidy

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# clang-tidy config for cforge itself.
2+
# Project-only — does not propagate to user projects.
3+
#
4+
# Apply with:
5+
# cforge lint # report only
6+
# cforge lint --fix # rewrite source in place
7+
# cforge lint --checks='readability-identifier-naming' --fix # naming only
8+
#
9+
# Naming convention summary:
10+
# namespaces, classes, structs, enums, functions, methods,
11+
# variables, parameters, member variables → snake_case
12+
# non-static member variables → m_ prefix
13+
# static member variables → s_ prefix
14+
# constexpr variables (file/global scope) → k prefix
15+
# enum constants → UPPER_CASE
16+
# macros → UPPER_CASE
17+
# template parameters → CamelCase (convention even
18+
# in snake_case
19+
# codebases — TIdx,
20+
# T, U, etc.)
21+
#
22+
# Exceptions:
23+
# - C ABI types in core/types.h (cforge_int_t, cforge_size_t, etc.) are
24+
# "lower_case" by accident — they match snake_case rules naturally so
25+
# they're not renamed.
26+
# - extern "C" `cforge_cmd_*` / `cforge_print_*` / `cforge_main*` entry
27+
# points are likewise snake_case and require no exception.
28+
# - Macros from third-party headers (fmt, toml++) are filtered via
29+
# HeaderFilterRegex below.
30+
31+
---
32+
# Restrict checks to *our* source. Without this, every <vector>/<string>/fmt
33+
# header pulled in gets the same name-style audit and the output is unusable.
34+
HeaderFilterRegex: '^(src|include)/'
35+
36+
# Treat all enabled checks as warnings (not errors) by default. Build pipelines
37+
# that want to fail on lint can pass --warnings-as-errors=* themselves.
38+
WarningsAsErrors: ''
39+
40+
# ── Checks ────────────────────────────────────────────────────────────────
41+
# Phase 1 baseline: naming + the cheapest "almost always wrong" patterns.
42+
# Modernize/perf checks are deliberately OFF here; Phase 3 will enable them
43+
# one at a time so the diff stays reviewable.
44+
Checks: >
45+
-*,
46+
readability-identifier-naming,
47+
bugprone-*,
48+
-bugprone-easily-swappable-parameters,
49+
-bugprone-narrowing-conversions
50+
51+
# ── readability-identifier-naming options ─────────────────────────────────
52+
CheckOptions:
53+
# ── Types ──
54+
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
55+
- { key: readability-identifier-naming.ClassCase, value: lower_case }
56+
- { key: readability-identifier-naming.StructCase, value: lower_case }
57+
- { key: readability-identifier-naming.UnionCase, value: lower_case }
58+
- { key: readability-identifier-naming.EnumCase, value: lower_case }
59+
- { key: readability-identifier-naming.TypedefCase, value: lower_case }
60+
- { key: readability-identifier-naming.TypeAliasCase, value: lower_case }
61+
- { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
62+
- { key: readability-identifier-naming.TypeTemplateParameterCase, value: CamelCase }
63+
- { key: readability-identifier-naming.ValueTemplateParameterCase, value: CamelCase }
64+
- { key: readability-identifier-naming.TemplateTemplateParameterCase, value: CamelCase }
65+
66+
# ── Functions / methods ──
67+
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
68+
- { key: readability-identifier-naming.MethodCase, value: lower_case }
69+
- { key: readability-identifier-naming.VirtualMethodCase, value: lower_case }
70+
- { key: readability-identifier-naming.ClassMethodCase, value: lower_case }
71+
- { key: readability-identifier-naming.GlobalFunctionCase, value: lower_case }
72+
- { key: readability-identifier-naming.PrivateMethodCase, value: lower_case }
73+
- { key: readability-identifier-naming.ProtectedMethodCase, value: lower_case }
74+
- { key: readability-identifier-naming.PublicMethodCase, value: lower_case }
75+
76+
# ── Variables / parameters ──
77+
- { key: readability-identifier-naming.VariableCase, value: lower_case }
78+
- { key: readability-identifier-naming.ParameterCase, value: lower_case }
79+
- { key: readability-identifier-naming.LocalVariableCase, value: lower_case }
80+
- { key: readability-identifier-naming.LocalConstantCase, value: lower_case }
81+
- { key: readability-identifier-naming.LocalConstantPointerCase, value: lower_case }
82+
- { key: readability-identifier-naming.LocalPointerCase, value: lower_case }
83+
84+
# ── Class members ──
85+
- { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
86+
- { key: readability-identifier-naming.ClassConstantCase, value: UPPER_CASE }
87+
- { key: readability-identifier-naming.MemberCase, value: lower_case }
88+
- { key: readability-identifier-naming.PrivateMemberCase, value: lower_case }
89+
- { key: readability-identifier-naming.PrivateMemberPrefix, value: m_ }
90+
- { key: readability-identifier-naming.ProtectedMemberCase, value: lower_case }
91+
- { key: readability-identifier-naming.ProtectedMemberPrefix, value: m_ }
92+
- { key: readability-identifier-naming.PublicMemberCase, value: lower_case }
93+
# NB: PublicMemberPrefix intentionally NOT set — POD-style structs (token,
94+
# diagnostic, locked_dependency, etc.) have public bare members in
95+
# cforge, and prefixing them with m_ would just be noise.
96+
97+
# ── Static class members ──
98+
- { key: readability-identifier-naming.StaticVariableCase, value: lower_case }
99+
- { key: readability-identifier-naming.StaticVariablePrefix, value: s_ }
100+
- { key: readability-identifier-naming.ClassMethodCase, value: lower_case }
101+
102+
# ── Globals / constants ──
103+
# clang-tidy lumps file-scope `static T name;` and namespace-scope globals
104+
# under the same "GlobalVariable" rule, but cforge distinguishes them in
105+
# practice: `g_` for true globals visible across TUs (signal handlers like
106+
# g_should_exit, OS handles like g_host_proc_handle), `s_` for file-scope
107+
# statics (s_progress_initialized, regex caches). We can't enforce that
108+
# distinction without two separate clang-tidy passes, so the rule below
109+
# accepts either prefix (and demands lower_case for the rest).
110+
- { key: readability-identifier-naming.GlobalVariableCase, value: lower_case }
111+
- { key: readability-identifier-naming.GlobalVariableIgnoredRegexp,
112+
value: '^(WINAPI|APIENTRY|CALLBACK|[gs]_[a-z][a-z0-9_]*)$' }
113+
- { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
114+
- { key: readability-identifier-naming.GlobalConstantPointerCase, value: UPPER_CASE }
115+
- { key: readability-identifier-naming.GlobalPointerCase, value: lower_case }
116+
# Same dual-prefix tolerance for global pointers.
117+
- { key: readability-identifier-naming.GlobalPointerIgnoredRegexp,
118+
value: '^([gs]_[a-z][a-z0-9_]*)$' }
119+
120+
# ── Constexpr ──
121+
# File/class-scope constexpr: UPPER_CASE (matches cforge's existing
122+
# STATUS_WIDTH, FNV_PRIME, FNV_OFFSET_BASIS, etc. — they read as
123+
# compile-time constants alongside macros).
124+
# Function-local constexpr stays lower_case (it's just a `const` with
125+
# extra steps).
126+
- { key: readability-identifier-naming.ConstexprVariableCase, value: UPPER_CASE }
127+
- { key: readability-identifier-naming.ConstexprMethodCase, value: lower_case }
128+
- { key: readability-identifier-naming.ConstexprFunctionCase, value: lower_case }
129+
- { key: readability-identifier-naming.LocalConstantCase, value: lower_case }
130+
131+
# ── Enum constants ──
132+
- { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE }
133+
# Allow scoped-enum members to skip the UPPER_CASE rule if they're
134+
# already typed (e.g. `style::CARGO` vs `style::cargo`). cforge already
135+
# uses UPPER_CASE for scoped enums so this is fine; if you ever want
136+
# lower_case scoped enums, change ScopedEnumConstantCase below.
137+
- { key: readability-identifier-naming.ScopedEnumConstantCase, value: UPPER_CASE }
138+
139+
# ── Macros ──
140+
- { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }
141+
142+
# ── Length / numeric thresholds ──
143+
# Catch one-letter parameter names except a handful of allowed math ones.
144+
- { key: readability-identifier-naming.ParameterIgnoredRegexp,
145+
value: '^(i|j|k|n|x|y|z|p|t|r|c|s|e|a|b|f|m)$' }
146+
147+
# ── Win32 false positives ──
148+
# WINAPI/APIENTRY/CALLBACK are already excluded via GlobalVariableIgnoredRegexp
149+
# above. These keys catch Hungarian-notation parameter names from the
150+
# Windows SDK (dwMode, lpReserved, hInstance, etc.) — we don't rename
151+
# them because they're dictated by Microsoft headers.
152+
- { key: readability-identifier-naming.LocalVariableIgnoredRegexp,
153+
value: '^(dw|lp|cb|sz|wc|h|n)[A-Z].*$' }
154+
155+
# ── Allow our C ABI prefix as-is ──
156+
# cforge_X identifiers naturally match snake_case; no exception needed.

include/cforge/cforge_hot.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* }
1717
* cforge_hot_unload(ctx);
1818
*/
19+
#include "core/types.h"
1920

2021
#ifndef CFORGE_HOT_H
2122
#define CFORGE_HOT_H
@@ -44,7 +45,7 @@ typedef struct cforge_hot_ctx cforge_hot_ctx;
4445
* @return Pointer to a newly allocated cforge_hot_ctx, or NULL on failure.
4546
* Call cforge_hot_last_error() for a human-readable error string.
4647
*/
47-
cforge_hot_ctx *cforge_hot_load(const char *library_path);
48+
cforge_hot_ctx *cforge_hot_load(cforge_cstring_t library_path);
4849

4950
/**
5051
* @brief Check the signal file for a new build and reload if one is available.
@@ -58,7 +59,7 @@ cforge_hot_ctx *cforge_hot_load(const char *library_path);
5859
* 0 if nothing changed,
5960
* -1 on error (the old library remains loaded).
6061
*/
61-
int cforge_hot_reload(cforge_hot_ctx *ctx);
62+
cforge_int_t cforge_hot_reload(cforge_hot_ctx *ctx);
6263

6364
/**
6465
* @brief Look up a symbol in the currently loaded library.
@@ -71,15 +72,15 @@ int cforge_hot_reload(cforge_hot_ctx *ctx);
7172
* module).
7273
* @return Pointer to the symbol, or NULL if not found.
7374
*/
74-
void *cforge_hot_get_symbol(cforge_hot_ctx *ctx, const char *symbol_name);
75+
void *cforge_hot_get_symbol(cforge_hot_ctx *ctx, cforge_cstring_t symbol_name);
7576

7677
/**
7778
* @brief Return the number of times the library has been loaded (starts at 1).
7879
*
7980
* @param ctx Context returned by cforge_hot_load().
8081
* @return Reload counter (monotonically increasing).
8182
*/
82-
int cforge_hot_get_version(cforge_hot_ctx *ctx);
83+
cforge_int_t cforge_hot_get_version(cforge_hot_ctx *ctx);
8384

8485
/**
8586
* @brief Blocking helper: poll the signal file and reload automatically.
@@ -102,7 +103,7 @@ void cforge_hot_watch(cforge_hot_ctx *ctx, void (*on_reload)(cforge_hot_ctx *));
102103
*
103104
* @return Null-terminated error string (never NULL, may be empty).
104105
*/
105-
const char *cforge_hot_last_error(void);
106+
cforge_cstring_t cforge_hot_last_error(void);
106107

107108
/**
108109
* @brief Unload the library, delete versioned copies, and free the context.

include/cforge/log.hpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class logger {
148148
* @param command The command being run
149149
* @param elapsed_secs Elapsed time in seconds
150150
*/
151-
static void running_timer(const std::string &command, double elapsed_secs);
151+
static void running_timer(const std::string &command, cforge_double_t elapsed_secs);
152152

153153
/**
154154
* @brief Print "Finished {config} target(s) in {time}"
@@ -252,10 +252,10 @@ class logger {
252252
* @param action Right-aligned status word shown beside the bar
253253
* (default "Building"; pass "Formatting", "Linting", etc.)
254254
*/
255-
static void progress_bar(int current,
256-
int total,
255+
static void progress_bar(cforge_int_t current,
256+
cforge_int_t total,
257257
bool in_place = true,
258-
double elapsed_secs = -1.0,
258+
cforge_double_t elapsed_secs = -1.0,
259259
const std::string &action = "Building");
260260

261261
/**
@@ -322,8 +322,8 @@ class logger {
322322
*/
323323
static void print_kv(const std::string &key,
324324
const std::string &value,
325-
int key_width = 14,
326-
int indent = 2);
325+
cforge_int_t key_width = 14,
326+
cforge_int_t indent = 2);
327327

328328
/**
329329
* @brief Print a key-value pair with colored value
@@ -337,8 +337,8 @@ class logger {
337337
static void print_kv_colored(const std::string &key,
338338
const std::string &value,
339339
fmt::color value_color,
340-
int key_width = 14,
341-
int indent = 2);
340+
cforge_int_t key_width = 14,
341+
cforge_int_t indent = 2);
342342

343343
/**
344344
* @brief Print a list item with bullet or dash
@@ -351,22 +351,22 @@ class logger {
351351
*/
352352
static void print_list_item(const std::string &text,
353353
const std::string &bullet = "-",
354-
int indent = 2);
354+
cforge_int_t indent = 2);
355355

356356
/**
357357
* @brief Print a dimmed/secondary text line
358358
*
359359
* Used for hints, help text, secondary info
360360
*/
361-
static void print_dim(const std::string &message, int indent = 0);
361+
static void print_dim(const std::string &message, cforge_int_t indent = 0);
362362

363363
/**
364364
* @brief Print a horizontal rule/separator
365365
*
366366
* @param width Width of the rule (default 60)
367367
* @param ch Character to use (default '-')
368368
*/
369-
static void print_rule(int width = 60, char ch = '-');
369+
static void print_rule(cforge_int_t width = 60, char ch = '-');
370370

371371
/**
372372
* @brief Print emphasized/highlighted text
@@ -389,7 +389,7 @@ class logger {
389389
* @param help_lines Vector of help strings
390390
* @param indent Indentation for each line
391391
*/
392-
static void print_help_lines(const std::vector<std::string> &help_lines, int indent = 2);
392+
static void print_help_lines(const std::vector<std::string> &help_lines, cforge_int_t indent = 2);
393393

394394
/**
395395
* @brief Print a table row with aligned columns
@@ -400,14 +400,14 @@ class logger {
400400
*/
401401
static void print_table_row(const std::vector<std::string> &columns,
402402
const std::vector<int> &widths,
403-
int indent = 0);
403+
cforge_int_t indent = 0);
404404

405405
/**
406406
* @brief Print a table header with separator
407407
*/
408408
static void print_table_header(const std::vector<std::string> &columns,
409409
const std::vector<int> &widths,
410-
int indent = 0);
410+
cforge_int_t indent = 0);
411411

412412
/**
413413
* @brief Print blank line
@@ -446,7 +446,7 @@ class logger {
446446
*/
447447
static void print_option(const std::string &flags,
448448
const std::string &description,
449-
int flag_width = 24);
449+
cforge_int_t flag_width = 24);
450450

451451
/**
452452
* @brief Print a positional argument
@@ -457,7 +457,7 @@ class logger {
457457
*/
458458
static void print_arg(const std::string &name,
459459
const std::string &description,
460-
int name_width = 18);
460+
cforge_int_t name_width = 18);
461461

462462
/**
463463
* @brief Print an example command
@@ -475,7 +475,7 @@ class logger {
475475
*/
476476
static void print_subcommand(const std::string &name,
477477
const std::string &description,
478-
int name_width = 14);
478+
cforge_int_t name_width = 14);
479479

480480
/**
481481
* @brief Print a help section header
@@ -531,7 +531,7 @@ class logger {
531531
* @param line Line number (0 to skip)
532532
* @param column Column number (0 to skip)
533533
*/
534-
static void print_location(const std::string &file_path, int line = 0, int column = 0);
534+
static void print_location(const std::string &file_path, cforge_int_t line = 0, int column = 0);
535535

536536
/**
537537
* @brief Print a code snippet line with gutter
@@ -540,7 +540,7 @@ class logger {
540540
* @param content Line content
541541
* @param gutter_width Width of the gutter
542542
*/
543-
static void print_code_line(int line_number, const std::string &content, int gutter_width = 4);
543+
static void print_code_line(cforge_int_t line_number, const std::string &content, int gutter_width = 4);
544544

545545
/**
546546
* @brief Print an error pointer line with carets
@@ -549,7 +549,7 @@ class logger {
549549
* @param length Length of the pointer (default 1)
550550
* @param gutter_width Width of the gutter
551551
*/
552-
static void print_error_pointer(int column_start, int length = 1, int gutter_width = 4);
552+
static void print_error_pointer(cforge_int_t column_start, int length = 1, int gutter_width = 4);
553553

554554
/**
555555
* @brief Print a diagnostic note line
@@ -582,7 +582,7 @@ class logger {
582582
* @param type Type description (e.g., "compiler error")
583583
* @param is_error True for error color, false for warning color
584584
*/
585-
static void print_error_count(int count, const std::string &type, bool is_error = true);
585+
static void print_error_count(cforge_int_t count, const std::string &type, bool is_error = true);
586586

587587
/**
588588
* @brief Print a gutter separator line
@@ -593,7 +593,7 @@ class logger {
593593
static log_verbosity s_verbosity;
594594

595595
// Status width for right-alignment (CARGO uses 12)
596-
static constexpr int STATUS_WIDTH = 12;
596+
static constexpr cforge_int_t STATUS_WIDTH = 12;
597597

598598
/**
599599
* @brief Internal helper to print formatted status line

0 commit comments

Comments
 (0)