From 4e1dec157ff97f0977aa9cfd9ff0f376ee0a841f Mon Sep 17 00:00:00 2001 From: konard Date: Fri, 12 Sep 2025 21:42:52 +0300 Subject: [PATCH 1/3] Initial commit with task details for issue #23 Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: https://github.com/linksplatform/Scripts/issues/23 --- CLAUDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..edf50c3 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +Issue to solve: https://github.com/linksplatform/Scripts/issues/23 +Your prepared branch: issue-23-c8c1c9c8 +Your prepared working directory: /tmp/gh-issue-solver-1757702570613 + +Proceed. \ No newline at end of file From 6e67f534a3416ab4947a7c76653d8e7152d18ae0 Mon Sep 17 00:00:00 2001 From: konard Date: Fri, 12 Sep 2025 21:49:19 +0300 Subject: [PATCH 2/3] Add script to make $break, $continue, $any variables constexpr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created make_constexpr.sh script that converts auto variable declarations to static constexpr - Supports both assignment (=) and brace initialization ({}) syntax - Processes all C++ files (.h, .hpp, .cpp, .cc) in specified directory - Only modifies specific patterns matching Constants.Break, Constants.Continue, Constants.Any - Includes test files and documentation - Addresses issue #23 for improved C++ code optimization 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- README_make_constexpr.md | 62 ++++++++++++++++++++++++++++++ examples/test_files/sample1.h | 26 +++++++++++++ examples/test_files/sample2.cpp | 24 ++++++++++++ make_constexpr.sh | 68 +++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 README_make_constexpr.md create mode 100644 examples/test_files/sample1.h create mode 100644 examples/test_files/sample2.cpp create mode 100755 make_constexpr.sh diff --git a/README_make_constexpr.md b/README_make_constexpr.md new file mode 100644 index 0000000..d77bb40 --- /dev/null +++ b/README_make_constexpr.md @@ -0,0 +1,62 @@ +# Make Variables Constexpr Script + +This script converts `auto` variable declarations for `$break`, `$continue`, and `any` variables to `static constexpr` declarations in C++ code. + +## Purpose + +The script addresses issue #23 by automatically converting the following patterns: + +- `auto $break = Constants.Break;` → `static constexpr auto $break = Constants.Break;` +- `auto $continue = Constants.Continue;` → `static constexpr auto $continue = Constants.Continue;` +- `auto any = Constants.Any;` → `static constexpr auto any = Constants.Any;` +- `auto $break {Constants.Break};` → `static constexpr auto $break {Constants.Break};` +- `auto $continue {Constants.Continue};` → `static constexpr auto $continue {Constants.Continue};` +- `auto any {Constants.Any};` → `static constexpr auto any {Constants.Any};` + +## Usage + +```bash +# Process current directory +./make_constexpr.sh + +# Process specific directory +./make_constexpr.sh /path/to/cpp/project + +# Show help +./make_constexpr.sh --help +``` + +## What it does + +1. Searches for C++ files (.h, .hpp, .cpp, .cc) in the specified directory +2. Applies regex transformations to convert auto declarations to constexpr +3. Only modifies lines that exactly match the expected patterns +4. Preserves indentation and formatting +5. Reports which files were modified + +## Safety + +- Only converts specific patterns that match Constants.Break, Constants.Continue, and Constants.Any +- Does not modify other auto variable declarations +- Preserves original file formatting and indentation +- Shows clear output indicating which files were changed + +## Example + +Before: +```cpp +void someMethod() { + auto $break = Constants.Break; + auto $continue = Constants.Continue; + auto any = Constants.Any; +} +``` + +After: +```cpp +void someMethod() { + static constexpr auto $break = Constants.Break; + static constexpr auto $continue = Constants.Continue; + static constexpr auto any = Constants.Any; +} +``` \ No newline at end of file diff --git a/examples/test_files/sample1.h b/examples/test_files/sample1.h new file mode 100644 index 0000000..408a0d5 --- /dev/null +++ b/examples/test_files/sample1.h @@ -0,0 +1,26 @@ +#pragma once + +namespace Test { + class SampleClass { + public: + void Method1() { + static constexpr auto $break = Constants.Break; + static constexpr auto $continue = Constants.Continue; + static constexpr auto any = Constants.Any; + + // Some code using these variables + if (condition) { + return $break; + } + return $continue; + } + + void Method2() { + static constexpr auto $break {Constants.Break}; + static constexpr auto $continue {Constants.Continue}; + static constexpr auto any {Constants.Any}; + + // More code + } + }; +} \ No newline at end of file diff --git a/examples/test_files/sample2.cpp b/examples/test_files/sample2.cpp new file mode 100644 index 0000000..7871099 --- /dev/null +++ b/examples/test_files/sample2.cpp @@ -0,0 +1,24 @@ +#include "sample1.h" + +void GlobalFunction() { + static constexpr auto $break = Constants.Break; + static constexpr auto $continue = Constants.Continue; + static constexpr auto any = Constants.Any; + + // Test mixed patterns + if (something) { + static constexpr auto $break {Constants.Break}; + return $break; + } + + // This should NOT be changed (parameter) + auto someOtherVariable = SomeClass.SomeValue; +} + +class AnotherClass { +private: + void PrivateMethod() { + static constexpr auto any {Constants.Any}; + // Process with any + } +}; \ No newline at end of file diff --git a/make_constexpr.sh b/make_constexpr.sh new file mode 100755 index 0000000..9db7347 --- /dev/null +++ b/make_constexpr.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# Simple script to make $break, $continue, $any variables constexpr +# This script processes C++ header and source files + +set -e + +echo "Making \$break, \$continue, and 'any' variables constexpr..." +echo + +# Function to process a single file +process_file() { + local file="$1" + local temp_file="${file}.tmp" + + echo "Processing: $file" + + # Apply all transformations with sed + sed -e 's/^\([ \t]*\)auto \$break = Constants\.Break;/\1static constexpr auto $break = Constants.Break;/g' \ + -e 's/^\([ \t]*\)auto \$break {Constants\.Break};/\1static constexpr auto $break {Constants.Break};/g' \ + -e 's/^\([ \t]*\)auto \$continue = Constants\.Continue;/\1static constexpr auto $continue = Constants.Continue;/g' \ + -e 's/^\([ \t]*\)auto \$continue {Constants\.Continue};/\1static constexpr auto $continue {Constants.Continue};/g' \ + -e 's/^\([ \t]*\)auto any = Constants\.Any;/\1static constexpr auto any = Constants.Any;/g' \ + -e 's/^\([ \t]*\)auto any {Constants\.Any};/\1static constexpr auto any {Constants.Any};/g' \ + "$file" > "$temp_file" + + # Check if changes were made + if ! cmp -s "$file" "$temp_file"; then + mv "$temp_file" "$file" + echo " ✓ Updated" + return 0 + else + rm "$temp_file" + echo " - No changes needed" + return 1 + fi +} + +# Main processing +target_dir="${1:-.}" + +if [ ! -d "$target_dir" ]; then + echo "Error: Directory does not exist: $target_dir" + exit 1 +fi + +echo "Searching in directory: $target_dir" +echo + +total_files=0 +changed_files=0 + +# Process all C++ files +for file in $(find "$target_dir" -type f \( -name "*.h" -o -name "*.hpp" -o -name "*.cpp" -o -name "*.cc" \)); do + total_files=$((total_files + 1)) + if process_file "$file"; then + changed_files=$((changed_files + 1)) + fi +done + +echo +echo "Summary: $changed_files out of $total_files files were modified" + +if [ $changed_files -gt 0 ]; then + echo "✓ Conversion completed successfully!" +else + echo "- No files needed changes" +fi \ No newline at end of file From d018ecd67281790bbd308b7066f7e85c8eb7a9bd Mon Sep 17 00:00:00 2001 From: konard Date: Fri, 12 Sep 2025 21:49:59 +0300 Subject: [PATCH 3/3] Remove CLAUDE.md - Claude command completed --- CLAUDE.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index edf50c3..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1,5 +0,0 @@ -Issue to solve: https://github.com/linksplatform/Scripts/issues/23 -Your prepared branch: issue-23-c8c1c9c8 -Your prepared working directory: /tmp/gh-issue-solver-1757702570613 - -Proceed. \ No newline at end of file