6 Commits
bloat ... main

Author SHA1 Message Date
Ed_
50033cc819 Changed ignore precedence to fix some bugs. 2023-11-18 20:18:16 -05:00
Ed_
22f74f3dc6 Namespace fix (making sure a namespace is a prefix only) 2023-11-17 19:24:27 -05:00
Ed_
6395d022f1 Merge branch 'main' of https://github.com/Ed94/refactor 2023-07-20 01:09:18 -04:00
Ed_
4d5cbd3e8d Fix for namespace swapping 2023-07-20 01:09:00 -04:00
Ed_
b21e1bf603 Merge pull request #5 from Ed94/Ed94-patch-1
Update LICENSE
2023-07-11 01:19:35 -04:00
Ed_
12779449a4 Update LICENSE 2023-07-11 01:19:11 -04:00
11 changed files with 176 additions and 171 deletions

6
.vscode/launch.json vendored
View File

@ -47,10 +47,10 @@
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/build/refactor.exe", "program": "${workspaceFolder}/build/refactor.exe",
"args": [ "args": [
"-source=./refactor.cpp", "-src=./project/refactor.cpp",
"-destination=./Test/refactor.cpp", "-dst=./Test/refactor.cpp",
"-specification=./Test/zpl.refactor" "-spec=./Test/zpl.refactor"
], ],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",

View File

@ -1,6 +1,6 @@
BSD 3-Clause License BSD 3-Clause License
Copyright (c) 2023, Ed_ Copyright (c) 2023, Edward R. Gonzalez
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:

View File

@ -79,8 +79,6 @@ With the refactors applied a meson configuraiton is setup (`meson.build` in test
* Can have a heavy memory cost, so most likely do not want on by default. * Can have a heavy memory cost, so most likely do not want on by default.
* Make comments ignored by default, and just have ability to specify custom comments. * Make comments ignored by default, and just have ability to specify custom comments.
* Would need a directive to add refactors to comments. * Would need a directive to add refactors to comments.
* Directive to add cpp namespaces on specific lines of a file, or near specific signatures.
* This can honestly be done also with placing words on specific lines..
* Provide a GUI build. * Provide a GUI build.
* Provide as a single-header library. * Provide as a single-header library.
* Could add a test case where this library is refactored into pure C (most likely c99 or c11). * Could add a test case where this library is refactored into pure C (most likely c99 or c11).

View File

@ -34,8 +34,8 @@ namespace zpl_random_, rng_
namespace zpl_pr, process_ namespace zpl_pr, process_
namespace zpl__, __ namespace zpl__, __
namespace ZPL_ADT_, EADT namespace ZPL_ADT_, EADT
namespace ZPL_ALLOCATION_, EAllocation namespace ZPL_ALLOCATION_, EAllocation_
namespace ZPL_CSV_ERROR, ECSV_Error namespace ZPL_CSV_ERROR, ECSV_Error_
namespace ZPL_FILE_MODE_, EFileMode_ namespace ZPL_FILE_MODE_, EFileMode_
namespace ZPL_FILE_ERROR_, EFileError_ namespace ZPL_FILE_ERROR_, EFileError_
namespace ZPL_SEEK_WHENCE_, ESeekWhence_ namespace ZPL_SEEK_WHENCE_, ESeekWhence_

View File

@ -2,8 +2,6 @@
#include "IO.cpp" #include "IO.cpp"
#include "Spec.cpp" #include "Spec.cpp"
void parse_options( int num, char** arguments ) void parse_options( int num, char** arguments )
{ {
zpl_opts opts; zpl_opts opts;
@ -280,7 +278,7 @@ void refactor()
{ {
Spec::Entry* ignore = Spec::Ignore_Includes; Spec::Entry* ignore = Spec::Ignore_Includes;
sw ignores_left = zpl_array_count( Spec::Ignore_Includes); sw ignores_left = zpl_array_count( Spec::Ignore_Includes);
Snapshot backup = { src, left, col, line }; Snapshot backup = { src, left, col, line };
if ( '#' != src[0] ) if ( '#' != src[0] )
break; break;
@ -339,81 +337,6 @@ void refactor()
} }
while (false); while (false);
// Word Ignores
{
Spec::Entry* ignore = Spec::Ignore_Words;
sw ignores_left = zpl_array_count( Spec::Ignore_Words);
for ( ; ignores_left; ignores_left--, ignore++ )
{
if ( ignore->Sig[0] != src[0] )
continue;
zpl_string_clear( current );
u32 sig_length = zpl_string_length( ignore->Sig );
current = zpl_string_append_length( current, src, sig_length );
if ( zpl_string_are_equal( ignore->Sig, current ) )
{
char before = src[-1];
char after = src[sig_length];
if ( zpl_char_is_alphanumeric( before ) || before == '_'
|| zpl_char_is_alphanumeric( after ) || after == '_' )
{
continue;
}
log_fmt("\nIgnored %-81s line %d, col %d", current, line, col );
move_forward( sig_length );
goto Skip;
}
}
}
// Namespace Ignores
{
Spec::Entry* ignore = Spec::Ignore_Namespaces;
sw ignores_left = zpl_array_count( Spec::Ignore_Namespaces);
for ( ; ignores_left; ignores_left--, ignore++ )
{
if ( ignore->Sig[0] != src[0] )
{
ignore++;
continue;
}
zpl_string_clear( current );
u32 sig_length = zpl_string_length( ignore->Sig );
current = zpl_string_append_length( current, src, sig_length );
if ( zpl_string_are_equal( ignore->Sig, current ) )
{
u32 length = sig_length;
char const* ns_content = src + sig_length;
while ( zpl_char_is_alphanumeric( ns_content[0] ) || ns_content[0] == '_' )
{
length++;
ns_content++;
}
#if Build_Debug
zpl_string_clear( preview );
preview = zpl_string_append_length( preview, src, length );
log_fmt("\nIgnored %-40s %-40s line %d, column %d", preview, ignore->Sig, line, col );
#endif
move_forward( length );
goto Skip;
}
}
}
// Includes to match // Includes to match
do do
{ {
@ -490,6 +413,40 @@ void refactor()
} }
while (false); while (false);
// Word Ignores
{
Spec::Entry* ignore = Spec::Ignore_Words;
sw ignores_left = zpl_array_count( Spec::Ignore_Words);
for ( ; ignores_left; ignores_left--, ignore++ )
{
if ( ignore->Sig[0] != src[0] )
continue;
zpl_string_clear( current );
u32 sig_length = zpl_string_length( ignore->Sig );
current = zpl_string_append_length( current, src, sig_length );
if ( zpl_string_are_equal( ignore->Sig, current ) )
{
char before = src[-1];
char after = src[sig_length];
if ( zpl_char_is_alphanumeric( before ) || before == '_'
|| zpl_char_is_alphanumeric( after ) || after == '_' )
{
continue;
}
log_fmt("\nIgnored %-81s line %d, col %d", current, line, col );
move_forward( sig_length );
goto Skip;
}
}
}
// Words to match // Words to match
{ {
Spec::Entry* word = Spec::Words; Spec::Entry* word = Spec::Words;
@ -538,6 +495,53 @@ void refactor()
} }
} }
// Namespace Ignores
{
Spec::Entry* ignore = Spec::Ignore_Namespaces;
sw ignores_left = zpl_array_count( Spec::Ignore_Namespaces);
for ( ; ignores_left; ignores_left--, ignore++ )
{
if ( ignore->Sig[0] != src[0] )
{
ignore++;
continue;
}
if (( zpl_char_is_alphanumeric( src[-1] ) || src[-1] == '_') )
{
ignore++;
continue;
}
zpl_string_clear( current );
u32 sig_length = zpl_string_length( ignore->Sig );
current = zpl_string_append_length( current, src, sig_length );
if ( zpl_string_are_equal( ignore->Sig, current ) )
{
u32 length = sig_length;
char const* ns_content = src + sig_length;
while ( zpl_char_is_alphanumeric( ns_content[0] ) || ns_content[0] == '_' )
{
length++;
ns_content++;
}
#if Build_Debug
zpl_string_clear( preview );
preview = zpl_string_append_length( preview, src, length );
log_fmt("\nIgnored %-40s %-40s line %d, column %d", preview, ignore->Sig, line, col );
#endif
move_forward( length );
goto Skip;
}
}
}
// Namespaces to match // Namespaces to match
{ {
Spec::Entry* nspace = Spec::Namespaces; Spec::Entry* nspace = Spec::Namespaces;
@ -549,6 +553,9 @@ void refactor()
if ( nspace->Sig[0] != src[0] ) if ( nspace->Sig[0] != src[0] )
continue; continue;
if (( zpl_char_is_alphanumeric( src[-1] ) || src[-1] == '_') )
continue;
zpl_string_clear( current ); zpl_string_clear( current );
u32 sig_length = zpl_string_length( nspace->Sig ); u32 sig_length = zpl_string_length( nspace->Sig );
@ -568,7 +575,7 @@ void refactor()
Token entry {}; Token entry {};
entry.Start = pos; entry.Start = pos;
entry.End = pos + length; entry.End = pos + sig_length;
entry.Sig = nspace->Sig; entry.Sig = nspace->Sig;
buffer_size += sig_length; buffer_size += sig_length;
@ -576,7 +583,7 @@ void refactor()
if ( nspace->Sub != nullptr ) if ( nspace->Sub != nullptr )
{ {
entry.Sub = nspace->Sub; entry.Sub = nspace->Sub;
buffer_size += zpl_string_length( entry.Sub ) - length; buffer_size += zpl_string_length( entry.Sub ) - sig_length;
} }
zpl_array_append( tokens, entry ); zpl_array_append( tokens, entry );