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):
|
||||
// word, namespace, regex
|
||||
|
||||
// Comments
|
||||
not comments
|
||||
|
||||
// Header files
|
||||
not include zpl_hedley
|
||||
//not word zpl_hedley
|
||||
not include zpl_hedley.h
|
||||
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.
|
||||
namespace zpl_
|
||||
|
@ -11,6 +11,9 @@ namespace Spec
|
||||
|
||||
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_Words;
|
||||
Array_Entry Ignore_Regexes;
|
||||
@ -49,7 +52,9 @@ namespace Spec
|
||||
// Allows for '.'
|
||||
while ( zpl_char_is_alphanumeric( current )
|
||||
|| current == '_'
|
||||
|| current == '.' )
|
||||
|| current == '.'
|
||||
|| current == '/'
|
||||
|| current == '\\' )
|
||||
{
|
||||
length++;
|
||||
}
|
||||
@ -161,7 +166,15 @@ namespace Spec
|
||||
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;
|
||||
}
|
||||
@ -324,5 +337,15 @@ namespace Spec
|
||||
}
|
||||
}
|
||||
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
|
||||
{
|
||||
Not,
|
||||
Comment,
|
||||
Include,
|
||||
Namespace,
|
||||
Word,
|
||||
@ -21,6 +22,7 @@ namespace Spec
|
||||
char const* tok_to_str[ Tok::Num_Tok ] =
|
||||
{
|
||||
"not",
|
||||
"comments",
|
||||
"include",
|
||||
"namespace",
|
||||
"word",
|
||||
@ -36,6 +38,7 @@ namespace Spec
|
||||
const u8 tok_to_len[ Tok::Num_Tok ] =
|
||||
{
|
||||
3,
|
||||
8,
|
||||
7,
|
||||
9,
|
||||
4,
|
||||
|
@ -216,12 +216,41 @@ void refactor()
|
||||
#define pos (IO::Current_Size - left)
|
||||
|
||||
#define move_forward( Amount_ ) \
|
||||
if ( left - Amount_ <= 0 ) \
|
||||
goto End_Search; \
|
||||
\
|
||||
left -= Amount_; \
|
||||
col += Amount_; \
|
||||
src += Amount_ \
|
||||
|
||||
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
|
||||
{
|
||||
Spec::Entry* ignore = Spec::Ignore_Includes;
|
||||
@ -229,25 +258,33 @@ void refactor()
|
||||
|
||||
for ( ; ignores_left; ignores_left--, ignore++ )
|
||||
{
|
||||
if ( include_sig[0] != src[0] )
|
||||
if ( '#' != src[0] )
|
||||
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 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
src += sizeof(include_sig) - 1;
|
||||
move_forward( sizeof(include_sig) - 1 );
|
||||
|
||||
// Ignore whitespace
|
||||
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 );
|
||||
|
||||
u32 sig_length = zpl_string_length( ignore->Sig );
|
||||
current = zpl_string_append_length( current, ignore->Sig, sig_length );
|
||||
|
||||
if ( zpl_string_are_equal( ignore->Sig, current ) )
|
||||
@ -353,9 +390,17 @@ void refactor()
|
||||
|
||||
for ( ; includes_left; includes_left--, include++ )
|
||||
{
|
||||
if ( include_sig[0] != src[0] )
|
||||
if ( '#' != src[0] )
|
||||
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 )
|
||||
{
|
||||
break;
|
||||
@ -366,12 +411,12 @@ void refactor()
|
||||
// Ignore whitespace
|
||||
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 );
|
||||
|
||||
u32 sig_length = zpl_string_length( include->Sig );
|
||||
current = zpl_string_append_length( current, include->Sig, sig_length );
|
||||
|
||||
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 );
|
||||
|
||||
move_forward( sig_length );
|
||||
// The + 1 is for the closing " or > of the include
|
||||
move_forward( sig_length + 1 );
|
||||
|
||||
// Force end of line.
|
||||
while ( src[0] != '\n' )
|
||||
@ -515,9 +561,10 @@ void refactor()
|
||||
col = 0;
|
||||
}
|
||||
|
||||
src++;
|
||||
move_forward( 1 );
|
||||
}
|
||||
while ( --left );
|
||||
while ( left );
|
||||
End_Search:
|
||||
|
||||
if (zpl_array_count( tokens ) == 0)
|
||||
{
|
||||
@ -572,6 +619,9 @@ void refactor()
|
||||
IO::write( refactored );
|
||||
|
||||
zpl_free_all( zpl_arena_allocator( & Refactor_Buffer ));
|
||||
|
||||
#undef pos
|
||||
#undef move_forward
|
||||
}
|
||||
|
||||
int main( int num, char** arguments )
|
||||
|
@ -2,7 +2,7 @@
|
||||
<N10X>
|
||||
<Workspace>
|
||||
<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>
|
||||
<Recursive>true</Recursive>
|
||||
<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\\cppwinrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>.\thirdparty</AdditionalIncludePath>
|
||||
</AdditionalIncludePaths>
|
||||
<Defines>
|
||||
<Define>ZPL_IMPLEMENTATION</Define>
|
||||
<Define></Define>
|
||||
</Defines>
|
||||
<ConfigProperties>
|
||||
<ConfigAndPlatform>
|
||||
<Name>Debug:x64</Name>
|
||||
<Defines></Defines>
|
||||
<ForceIncludes>
|
||||
<ForceInclude>C:\projects\refactor\thirdparty</ForceInclude>
|
||||
<ForceInclude>./project</ForceInclude>
|
||||
<ForceInclude>./thirdparty</ForceInclude>
|
||||
</ForceIncludes>
|
||||
</ConfigAndPlatform>
|
||||
<Config>
|
||||
|
Loading…
Reference in New Issue
Block a user