mirror of
https://github.com/Ed94/refactor.git
synced 2025-06-30 19:01:04 -07:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
50033cc819 | |||
22f74f3dc6 | |||
6395d022f1 | |||
4d5cbd3e8d | |||
b21e1bf603 | |||
12779449a4 |
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
@ -47,10 +47,10 @@
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/refactor.exe",
|
||||
"args": [
|
||||
"-source=./refactor.cpp",
|
||||
"-destination=./Test/refactor.cpp",
|
||||
"-src=./project/refactor.cpp",
|
||||
"-dst=./Test/refactor.cpp",
|
||||
|
||||
"-specification=./Test/zpl.refactor"
|
||||
"-spec=./Test/zpl.refactor"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceRoot}",
|
||||
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
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
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
@ -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.
|
||||
* Make comments ignored by default, and just have ability to specify custom 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 as a single-header library.
|
||||
* Could add a test case where this library is refactored into pure C (most likely c99 or c11).
|
||||
|
@ -34,8 +34,8 @@ namespace zpl_random_, rng_
|
||||
namespace zpl_pr, process_
|
||||
namespace zpl__, __
|
||||
namespace ZPL_ADT_, EADT
|
||||
namespace ZPL_ALLOCATION_, EAllocation
|
||||
namespace ZPL_CSV_ERROR, ECSV_Error
|
||||
namespace ZPL_ALLOCATION_, EAllocation_
|
||||
namespace ZPL_CSV_ERROR, ECSV_Error_
|
||||
namespace ZPL_FILE_MODE_, EFileMode_
|
||||
namespace ZPL_FILE_ERROR_, EFileError_
|
||||
namespace ZPL_SEEK_WHENCE_, ESeekWhence_
|
||||
|
@ -2,8 +2,6 @@
|
||||
#include "IO.cpp"
|
||||
#include "Spec.cpp"
|
||||
|
||||
|
||||
|
||||
void parse_options( int num, char** arguments )
|
||||
{
|
||||
zpl_opts opts;
|
||||
@ -280,7 +278,7 @@ void refactor()
|
||||
{
|
||||
Spec::Entry* ignore = 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] )
|
||||
break;
|
||||
@ -339,81 +337,6 @@ void refactor()
|
||||
}
|
||||
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
|
||||
do
|
||||
{
|
||||
@ -490,6 +413,40 @@ void refactor()
|
||||
}
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
Spec::Entry* nspace = Spec::Namespaces;
|
||||
@ -549,6 +553,9 @@ void refactor()
|
||||
if ( nspace->Sig[0] != src[0] )
|
||||
continue;
|
||||
|
||||
if (( zpl_char_is_alphanumeric( src[-1] ) || src[-1] == '_') )
|
||||
continue;
|
||||
|
||||
zpl_string_clear( current );
|
||||
|
||||
u32 sig_length = zpl_string_length( nspace->Sig );
|
||||
@ -568,7 +575,7 @@ void refactor()
|
||||
Token entry {};
|
||||
|
||||
entry.Start = pos;
|
||||
entry.End = pos + length;
|
||||
entry.End = pos + sig_length;
|
||||
entry.Sig = nspace->Sig;
|
||||
|
||||
buffer_size += sig_length;
|
||||
@ -576,7 +583,7 @@ void refactor()
|
||||
if ( nspace->Sub != nullptr )
|
||||
{
|
||||
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 );
|
||||
|
Reference in New Issue
Block a user