mirror of
https://github.com/Ed94/refactor.git
synced 2024-12-21 22:44:45 -08:00
Got include ignores to work, comment ignores work
Not sure yet if include renames work just yet (need to test) Comment signatures are currently hardcoded for C/C++.
This commit is contained in:
parent
d0fad572bc
commit
87c939e2b6
@ -9,9 +9,17 @@ __VERSION 1
|
|||||||
// Precedence (highest to lowest):
|
// Precedence (highest to lowest):
|
||||||
// word, namespace, regex
|
// word, namespace, regex
|
||||||
|
|
||||||
|
// Comments
|
||||||
|
not comments
|
||||||
|
|
||||||
// Header files
|
// Header files
|
||||||
not include zpl_hedley
|
not include zpl_hedley.h
|
||||||
//not word zpl_hedley
|
not include allocator.h
|
||||||
|
not include array.h
|
||||||
|
not include header/essentials/collections/array.h
|
||||||
|
not include header/essentials/collections/list.h
|
||||||
|
not include header/core/file.h
|
||||||
|
not include header/opts.h
|
||||||
|
|
||||||
// Removes the namespace.
|
// Removes the namespace.
|
||||||
namespace zpl_
|
namespace zpl_
|
||||||
|
@ -11,6 +11,9 @@ namespace Spec
|
|||||||
|
|
||||||
namespace StaticData
|
namespace StaticData
|
||||||
{
|
{
|
||||||
|
// Custom comment signatures not supported yet (only C/C++ comments for now)
|
||||||
|
bool Ignore_Comments = false;
|
||||||
|
|
||||||
Array_Entry Ignore_Includes;
|
Array_Entry Ignore_Includes;
|
||||||
Array_Entry Ignore_Words;
|
Array_Entry Ignore_Words;
|
||||||
Array_Entry Ignore_Regexes;
|
Array_Entry Ignore_Regexes;
|
||||||
@ -49,7 +52,9 @@ namespace Spec
|
|||||||
// Allows for '.'
|
// Allows for '.'
|
||||||
while ( zpl_char_is_alphanumeric( current )
|
while ( zpl_char_is_alphanumeric( current )
|
||||||
|| current == '_'
|
|| current == '_'
|
||||||
|| current == '.' )
|
|| current == '.'
|
||||||
|
|| current == '/'
|
||||||
|
|| current == '\\' )
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
@ -161,7 +166,15 @@ namespace Spec
|
|||||||
find_next_token( type, token, line, length );
|
find_next_token( type, token, line, length );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_tok( Tok::Word, token, length ) )
|
if ( is_tok( Tok::Comment, token, length ) )
|
||||||
|
{
|
||||||
|
// Custom comment signatures not supported yet (only C/C++ comments for now)
|
||||||
|
Ignore_Comments = true;
|
||||||
|
|
||||||
|
lines++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if ( is_tok( Tok::Word, token, length ) )
|
||||||
{
|
{
|
||||||
type = Tok::Word;
|
type = Tok::Word;
|
||||||
}
|
}
|
||||||
@ -324,5 +337,15 @@ namespace Spec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
while ( --left );
|
while ( --left );
|
||||||
|
|
||||||
|
Spec::Entry* ignore = Spec::Ignore_Includes;
|
||||||
|
sw ignores_left = zpl_array_count( Spec::Ignore_Includes);
|
||||||
|
|
||||||
|
zpl_printf("\nIgnores: ");
|
||||||
|
for ( ; ignores_left; ignores_left--, ignore++ )
|
||||||
|
{
|
||||||
|
zpl_printf("\n%s", ignore->Sig);
|
||||||
|
}
|
||||||
|
zpl_printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ namespace Spec
|
|||||||
enum Tok
|
enum Tok
|
||||||
{
|
{
|
||||||
Not,
|
Not,
|
||||||
|
Comment,
|
||||||
Include,
|
Include,
|
||||||
Namespace,
|
Namespace,
|
||||||
Word,
|
Word,
|
||||||
@ -21,6 +22,7 @@ namespace Spec
|
|||||||
char const* tok_to_str[ Tok::Num_Tok ] =
|
char const* tok_to_str[ Tok::Num_Tok ] =
|
||||||
{
|
{
|
||||||
"not",
|
"not",
|
||||||
|
"comments",
|
||||||
"include",
|
"include",
|
||||||
"namespace",
|
"namespace",
|
||||||
"word",
|
"word",
|
||||||
@ -36,6 +38,7 @@ namespace Spec
|
|||||||
const u8 tok_to_len[ Tok::Num_Tok ] =
|
const u8 tok_to_len[ Tok::Num_Tok ] =
|
||||||
{
|
{
|
||||||
3,
|
3,
|
||||||
|
8,
|
||||||
7,
|
7,
|
||||||
9,
|
9,
|
||||||
4,
|
4,
|
||||||
|
@ -216,12 +216,41 @@ void refactor()
|
|||||||
#define pos (IO::Current_Size - left)
|
#define pos (IO::Current_Size - left)
|
||||||
|
|
||||||
#define move_forward( Amount_ ) \
|
#define move_forward( Amount_ ) \
|
||||||
|
if ( left - Amount_ <= 0 ) \
|
||||||
|
goto End_Search; \
|
||||||
|
\
|
||||||
left -= Amount_; \
|
left -= Amount_; \
|
||||||
col += Amount_; \
|
col += Amount_; \
|
||||||
src += Amount_ \
|
src += Amount_ \
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
if ( Spec::Ignore_Comments && src[0] == '/' && left - 2 > 0 )
|
||||||
|
{
|
||||||
|
if ( src[1] == '/' )
|
||||||
|
{
|
||||||
|
move_forward( 2 );
|
||||||
|
|
||||||
|
// Force end of line.
|
||||||
|
while ( src[0] != '\n' )
|
||||||
|
{
|
||||||
|
move_forward( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
goto Skip;
|
||||||
|
}
|
||||||
|
else if ( src[1] == '*' )
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
move_forward( 2 );
|
||||||
|
}
|
||||||
|
while ( (left - 2) > 0 && !( src[0] == '*' && src[1] == '/' ) );
|
||||||
|
|
||||||
|
move_forward( 2 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Includes to ignore
|
// Includes to ignore
|
||||||
{
|
{
|
||||||
Spec::Entry* ignore = Spec::Ignore_Includes;
|
Spec::Entry* ignore = Spec::Ignore_Includes;
|
||||||
@ -229,25 +258,33 @@ void refactor()
|
|||||||
|
|
||||||
for ( ; ignores_left; ignores_left--, ignore++ )
|
for ( ; ignores_left; ignores_left--, ignore++ )
|
||||||
{
|
{
|
||||||
if ( include_sig[0] != src[0] )
|
if ( '#' != src[0] )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
move_forward( 1 );
|
||||||
|
|
||||||
|
// Ignore whitespace
|
||||||
|
while ( zpl_char_is_space( src[0] ) )
|
||||||
|
{
|
||||||
|
move_forward( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
if ( zpl_strncmp( include_sig, src, sizeof(include_sig) - 1 ) != 0 )
|
if ( zpl_strncmp( include_sig, src, sizeof(include_sig) - 1 ) != 0 )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
src += sizeof(include_sig) - 1;
|
move_forward( sizeof(include_sig) - 1 );
|
||||||
|
|
||||||
// Ignore whitespace
|
// Ignore whitespace
|
||||||
while ( zpl_char_is_space( src[0] ) || src[0] == '\"' || src[0] == '<' )
|
while ( zpl_char_is_space( src[0] ) || src[0] == '\"' || src[0] == '<' )
|
||||||
{
|
{
|
||||||
src++;
|
move_forward(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 sig_length = zpl_string_length( ignore->Sig );
|
|
||||||
|
|
||||||
zpl_string_clear( current );
|
zpl_string_clear( current );
|
||||||
|
|
||||||
|
u32 sig_length = zpl_string_length( ignore->Sig );
|
||||||
current = zpl_string_append_length( current, ignore->Sig, sig_length );
|
current = zpl_string_append_length( current, ignore->Sig, sig_length );
|
||||||
|
|
||||||
if ( zpl_string_are_equal( ignore->Sig, current ) )
|
if ( zpl_string_are_equal( ignore->Sig, current ) )
|
||||||
@ -353,9 +390,17 @@ void refactor()
|
|||||||
|
|
||||||
for ( ; includes_left; includes_left--, include++ )
|
for ( ; includes_left; includes_left--, include++ )
|
||||||
{
|
{
|
||||||
if ( include_sig[0] != src[0] )
|
if ( '#' != src[0] )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
move_forward( 1 );
|
||||||
|
|
||||||
|
// Ignore whitespace
|
||||||
|
while ( zpl_char_is_space( src[0] ) )
|
||||||
|
{
|
||||||
|
move_forward( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
if ( zpl_strncmp( include_sig, src, sizeof(include_sig) - 1 ) != 0 )
|
if ( zpl_strncmp( include_sig, src, sizeof(include_sig) - 1 ) != 0 )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@ -366,12 +411,12 @@ void refactor()
|
|||||||
// Ignore whitespace
|
// Ignore whitespace
|
||||||
while ( zpl_char_is_space( src[0] ) || src[0] == '\"' || src[0] == '<' )
|
while ( zpl_char_is_space( src[0] ) || src[0] == '\"' || src[0] == '<' )
|
||||||
{
|
{
|
||||||
src++;
|
move_forward( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 sig_length = zpl_string_length( include->Sig );
|
|
||||||
|
|
||||||
zpl_string_clear( current );
|
zpl_string_clear( current );
|
||||||
|
|
||||||
|
u32 sig_length = zpl_string_length( include->Sig );
|
||||||
current = zpl_string_append_length( current, include->Sig, sig_length );
|
current = zpl_string_append_length( current, include->Sig, sig_length );
|
||||||
|
|
||||||
if ( zpl_string_are_equal( include->Sig, current ) )
|
if ( zpl_string_are_equal( include->Sig, current ) )
|
||||||
@ -392,7 +437,8 @@ void refactor()
|
|||||||
|
|
||||||
log_fmt("\nFound %-81s line %d, column %d", current, line, col );
|
log_fmt("\nFound %-81s line %d, column %d", current, line, col );
|
||||||
|
|
||||||
move_forward( sig_length );
|
// The + 1 is for the closing " or > of the include
|
||||||
|
move_forward( sig_length + 1 );
|
||||||
|
|
||||||
// Force end of line.
|
// Force end of line.
|
||||||
while ( src[0] != '\n' )
|
while ( src[0] != '\n' )
|
||||||
@ -515,9 +561,10 @@ void refactor()
|
|||||||
col = 0;
|
col = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
src++;
|
move_forward( 1 );
|
||||||
}
|
}
|
||||||
while ( --left );
|
while ( left );
|
||||||
|
End_Search:
|
||||||
|
|
||||||
if (zpl_array_count( tokens ) == 0)
|
if (zpl_array_count( tokens ) == 0)
|
||||||
{
|
{
|
||||||
@ -572,6 +619,9 @@ void refactor()
|
|||||||
IO::write( refactored );
|
IO::write( refactored );
|
||||||
|
|
||||||
zpl_free_all( zpl_arena_allocator( & Refactor_Buffer ));
|
zpl_free_all( zpl_arena_allocator( & Refactor_Buffer ));
|
||||||
|
|
||||||
|
#undef pos
|
||||||
|
#undef move_forward
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int num, char** arguments )
|
int main( int num, char** arguments )
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<N10X>
|
<N10X>
|
||||||
<Workspace>
|
<Workspace>
|
||||||
<IncludeFilter>*.*,</IncludeFilter>
|
<IncludeFilter>*.*,</IncludeFilter>
|
||||||
<ExcludeFilter>*.obj,*.lib,*.pch,*.dll,*.pdb,.vs,Debug,Release,x64,obj,*.user,Intermediate,</ExcludeFilter>
|
<ExcludeFilter>*.obj,*.lib,*.pch,*.dll,*.pdb,.vs,Debug,Release,x64,obj,*.user,Intermediate,.git,.idea,.vscode,</ExcludeFilter>
|
||||||
<SyncFiles>true</SyncFiles>
|
<SyncFiles>true</SyncFiles>
|
||||||
<Recursive>true</Recursive>
|
<Recursive>true</Recursive>
|
||||||
<ShowEmptyFolders>true</ShowEmptyFolders>
|
<ShowEmptyFolders>true</ShowEmptyFolders>
|
||||||
@ -36,17 +36,17 @@
|
|||||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt</AdditionalIncludePath>
|
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt</AdditionalIncludePath>
|
||||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt</AdditionalIncludePath>
|
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt</AdditionalIncludePath>
|
||||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</AdditionalIncludePath>
|
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</AdditionalIncludePath>
|
||||||
<AdditionalIncludePath>.\thirdparty</AdditionalIncludePath>
|
|
||||||
</AdditionalIncludePaths>
|
</AdditionalIncludePaths>
|
||||||
<Defines>
|
<Defines>
|
||||||
<Define>ZPL_IMPLEMENTATION</Define>
|
<Define></Define>
|
||||||
</Defines>
|
</Defines>
|
||||||
<ConfigProperties>
|
<ConfigProperties>
|
||||||
<ConfigAndPlatform>
|
<ConfigAndPlatform>
|
||||||
<Name>Debug:x64</Name>
|
<Name>Debug:x64</Name>
|
||||||
<Defines></Defines>
|
<Defines></Defines>
|
||||||
<ForceIncludes>
|
<ForceIncludes>
|
||||||
<ForceInclude>C:\projects\refactor\thirdparty</ForceInclude>
|
<ForceInclude>./project</ForceInclude>
|
||||||
|
<ForceInclude>./thirdparty</ForceInclude>
|
||||||
</ForceIncludes>
|
</ForceIncludes>
|
||||||
</ConfigAndPlatform>
|
</ConfigAndPlatform>
|
||||||
<Config>
|
<Config>
|
||||||
|
Loading…
Reference in New Issue
Block a user