Changed how editor intellisense directives are handled for compoenents and dependencies

Didn't like the way I was processing them in scan_file.
This commit is contained in:
Edward R. Gonzalez 2023-08-28 23:46:50 -04:00
parent 7249a7317d
commit 0197afd543
40 changed files with 202 additions and 93 deletions

View File

@ -10,8 +10,9 @@
"UNICODE", "UNICODE",
"_UNICODE", "_UNICODE",
"GEN_TIME", "GEN_TIME",
"GEN_IMPLEMENTATION" "GEN_IMPLEMENTATION",
// "GEN_DONT_USE_NAMESPACE" // "GEN_DONT_USE_NAMESPACE"
"GEN_INTELLISENSE_DIRECTIVES"
], ],
"windowsSdkVersion": "10.0.19041.0", "windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe", "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
@ -28,8 +29,9 @@
"UNICODE", "UNICODE",
"_UNICODE", "_UNICODE",
"GEN_TIME", "GEN_TIME",
"GEN_IMPLEMENTATION" "GEN_IMPLEMENTATION",
// "GEN_DONT_USE_NAMESPACE" // "GEN_DONT_USE_NAMESPACE"
"GEN_INTELLISENSE_DIRECTIVES"
], ],
"windowsSdkVersion": "10.0.19041.0", "windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe", "compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",

View File

@ -1,10 +1,11 @@
#pragma once #pragma once
#include "gen.hpp" #include "gen.hpp"
// This is a simple file reader that reads the entire file into memory. // This is a simple file reader that reads the entire file into memory.
// It has an extra option to skip the first few lines for undesired includes. // It has an extra option to skip the first few lines for undesired includes.
// This is done so that includes can be kept in dependency and component files so that intellisense works. // This is done so that includes can be kept in dependency and component files so that intellisense works.
Code scan_file( char const* path, bool skip_initial_directives = true ) Code scan_file( char const* path )
{ {
FileInfo file; FileInfo file;
@ -24,63 +25,92 @@ Code scan_file( char const* path, bool skip_initial_directives = true )
file_read( & file, str, fsize ); file_read( & file, str, fsize );
str.get_header().Length = fsize; str.get_header().Length = fsize;
if ( skip_initial_directives ) // Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
// Its designed so that the directive should be the first thing in the file.
// Anything that comes before it will also be omitted.
{ {
#define current (*scanner) #define current (*scanner)
StrC toks[] { #define matched 0
txt( "pragma once" ), #define move_fwd() do { ++ scanner; -- left; } while (0)
txt( "include" ) const StrC directive_start = txt( "ifdef" );
}; const StrC directive_end = txt( "endif" );
const StrC def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" );
char* scanner = str; bool found_directive = false;
while ( current != '\r' && current != '\n' ) char const* scanner = str.Data;
s32 left = fsize;
while ( left )
{ {
for ( StrC tok : toks ) // Processing directive.
if ( current == '#' )
{ {
if ( current == '#' ) move_fwd();
{ while ( left && char_is_space( current ) )
++ scanner; move_fwd();
}
if ( strncmp( scanner, tok.Ptr, tok.Len ) == 0 ) if ( ! found_directive )
{ {
scanner += tok.Len; if ( left && str_compare( scanner, directive_start.Ptr, directive_start.Len ) == matched )
while ( scanner < ( str.Data + str.length() ) && current != '\r' && current != '\n' )
{ {
++ scanner; scanner += directive_start.Len;
left -= directive_start.Len;
while ( left && char_is_space( current ) )
move_fwd();
if ( left && str_compare( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
{
scanner += def_intellisense.Len;
left -= def_intellisense.Len;
found_directive = true;
}
} }
// Skip the line // Skip to end of line
sptr skip_size = sptr( scanner - str.Data ); while ( left && current != '\r' && current != '\n' )
if ( (scanner + 2) >= ( str.Data + str.length() ) ) move_fwd();
move_fwd();
if ( left && current == '\n' )
move_fwd();
continue;
}
if ( left && str_compare( scanner, directive_end.Ptr, directive_end.Len ) == matched )
{
scanner += directive_end.Len;
left -= directive_end.Len;
// Skip to end of line
while ( left && current != '\r' && current != '\n' )
move_fwd();
move_fwd();
if ( left && current == '\n' )
move_fwd();
sptr skip_size = fsize - left;
if ( (scanner + 2) >= ( str.Data + fsize ) )
{ {
sptr new_length = sptr( str.get_header().Length ) - skip_size; mem_move( str, scanner, left );
mem_move( str, scanner, new_length ); str.get_header().Length = left;
str.get_header().Length = new_length;
break; break;
} }
if ( current == '\r' ) mem_move( str, scanner, left );
{ str.get_header().Length = left;
skip_size += 2;
scanner += 2;
}
else
{
skip_size += 1;
scanner += 1;
}
sptr new_length = sptr( str.get_header().Length ) - skip_size; break;
mem_move( str, scanner, new_length );
str.get_header().Length = new_length;
scanner = str;
} }
} }
++ scanner; move_fwd();
} }
#undef move_fwd
#undef matched
#undef current #undef current
} }

View File

@ -20,18 +20,16 @@ constexpr char const* generation_notice =
"// This file was generated automatially by gencpp's bootstrap.cpp " "// This file was generated automatially by gencpp's bootstrap.cpp "
"(See: https://github.com/Ed94/gencpp)\n\n"; "(See: https://github.com/Ed94/gencpp)\n\n";
constexpr bool DontSkipInitialDirectives = false;
int gen_main() int gen_main()
{ {
gen::init(); gen::init();
Code push_ignores = scan_file( "helpers/push_ignores.inline.hpp", DontSkipInitialDirectives ); Code push_ignores = scan_file( "helpers/push_ignores.inline.hpp" );
Code pop_ignores = scan_file( "helpers/pop_ignores.inline.hpp", DontSkipInitialDirectives ); Code pop_ignores = scan_file( "helpers/pop_ignores.inline.hpp" );
// gen_dep.hpp // gen_dep.hpp
{ {
Code header_start = scan_file( "dependencies/header_start.hpp", DontSkipInitialDirectives ); Code header_start = scan_file( "dependencies/header_start.hpp" );
Code macros = scan_file( "dependencies/macros.hpp" ); Code macros = scan_file( "dependencies/macros.hpp" );
Code basic_types = scan_file( "dependencies/basic_types.hpp" ); Code basic_types = scan_file( "dependencies/basic_types.hpp" );
Code debug = scan_file( "dependencies/debug.hpp" ); Code debug = scan_file( "dependencies/debug.hpp" );
@ -147,31 +145,35 @@ int gen_main()
header.print( pop_ignores ); header.print( pop_ignores );
header.write(); header.write();
CodeBody gen_component_header = def_global_body( args(
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
pragma_once,
preprocess_endif,
fmt_newline,
untyped_str( to_str(generation_notice) )
));
Builder Builder
header_ecode = Builder::open( "components/gen/ecode.hpp" ); header_ecode = Builder::open( "components/gen/ecode.hpp" );
header_ecode.print( pragma_once ); header_ecode.print( gen_component_header );
header_ecode.print_fmt( generation_notice );
header_ecode.print( ecode ); header_ecode.print( ecode );
header_ecode.write(); header_ecode.write();
Builder Builder
header_eoperator = Builder::open( "components/gen/eoperator.hpp" ); header_eoperator = Builder::open( "components/gen/eoperator.hpp" );
header_eoperator.print( pragma_once ); header_eoperator.print( gen_component_header );
header_eoperator.print_fmt( generation_notice );
header_eoperator.print( eoperator ); header_eoperator.print( eoperator );
header_eoperator.write(); header_eoperator.write();
Builder Builder
header_especifier = Builder::open( "components/gen/especifier.hpp" ); header_especifier = Builder::open( "components/gen/especifier.hpp" );
header_especifier.print( pragma_once ); header_especifier.print( gen_component_header );
header_especifier.print_fmt( generation_notice );
header_especifier.print( especifier ); header_especifier.print( especifier );
header_especifier.write(); header_especifier.write();
Builder Builder
header_ast_inlines = Builder::open( "components/gen/ast_inlines.hpp" ); header_ast_inlines = Builder::open( "components/gen/ast_inlines.hpp" );
header_ast_inlines.print( pragma_once ); header_ast_inlines.print( gen_component_header );
header_ast_inlines.print_fmt( generation_notice );
header_ast_inlines.print( ast_inlines ); header_ast_inlines.print( ast_inlines );
header_ast_inlines.write(); header_ast_inlines.write();
} }

View File

@ -1,5 +1,7 @@
#if GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "static_data.cpp" #include "static_data.cpp"
#endif
Code Code::Global; Code Code::Global;
Code Code::Invalid; Code Code::Invalid;

View File

@ -1,8 +1,10 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "types.hpp" #include "types.hpp"
#include "gen/ecode.hpp" #include "gen/ecode.hpp"
#include "gen/eoperator.hpp" #include "gen/eoperator.hpp"
#include "gen/especifier.hpp" #include "gen/especifier.hpp"
#endif
namespace Parser namespace Parser
{ {

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "ast.hpp" # pragma once
# include "ast.hpp"
#endif
#pragma region AST Types #pragma region AST Types
/* /*

View File

@ -1,4 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
#pragma region generated code inline implementation #pragma region generated code inline implementation

View File

@ -1,4 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)

View File

@ -1,4 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)

View File

@ -1,4 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)

View File

@ -1,6 +1,8 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "inlines.hpp" #include "inlines.hpp"
#include "gen/ast_inlines.hpp" #include "gen/ast_inlines.hpp"
#endif
#pragma region Constants #pragma region Constants

View File

@ -1,5 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "interface.hpp" #include "interface.hpp"
#endif
void AST::append( AST* other ) void AST::append( AST* other )
{ {

View File

@ -1,5 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "ast.cpp" #include "ast.cpp"
#endif
internal void init_parser(); internal void init_parser();
internal void deinit_parser(); internal void deinit_parser();

View File

@ -1,5 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "ast_types.hpp" #include "ast_types.hpp"
#endif
#pragma region Gen Interface #pragma region Gen Interface

View File

@ -1,6 +1,8 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "gen/etoktype.cpp" #include "gen/etoktype.cpp"
#include "interface.upfront.cpp" #include "interface.upfront.cpp"
#endif
namespace Parser namespace Parser
{ {

View File

@ -1,5 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "interface.parsing.cpp" #include "interface.parsing.cpp"
#endif
sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va ) sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va )
{ {

View File

@ -1,5 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "interface.cpp" #include "interface.cpp"
#endif
#pragma region Upfront #pragma region Upfront

View File

@ -1,5 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "gen.hpp" #include "gen.hpp"
#endif
#pragma region StaticData #pragma region StaticData

View File

@ -1,5 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "header_start.hpp" #include "header_start.hpp"
#endif
using LogFailType = sw(*)(char const*, ...); using LogFailType = sw(*)(char const*, ...);

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "macros.hpp" # pragma once
# include "macros.hpp"
#endif
#pragma region Basic Types #pragma region Basic Types

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "printing.hpp" # pragma once
# include "printing.hpp"
#endif
#pragma region Containers #pragma region Containers

View File

@ -1,4 +1,6 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
#endif
#pragma region Debug #pragma region Debug

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVESj
#include "basic_types.hpp" # pragma once
# include "basic_types.hpp"
#endif
#pragma region Debug #pragma region Debug

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "strings.cpp" # pragma once
# include "strings.cpp"
#endif
#pragma region File Handling #pragma region File Handling

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "strings.hpp" # pragma once
# include "strings.hpp"
#endif
#pragma region File Handling #pragma region File Handling

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "memory.cpp" # pragma once
# include "memory.cpp"
#endif
#pragma region Hashing #pragma region Hashing

View File

@ -1,5 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "containers.hpp" #include "containers.hpp"
#endif
#pragma region Hashing #pragma region Hashing

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "header_start.hpp" # pragma once
# include "header_start.hpp"
#endif
#pragma region Macros #pragma region Macros

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "printing.cpp" # pragma once
# include "printing.cpp"
#endif
#pragma region Memory #pragma region Memory

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "debug.hpp" # pragma once
# include "debug.hpp"
#endif
#pragma region Memory #pragma region Memory

View File

@ -1,4 +1,6 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
#endif
#pragma region ADT #pragma region ADT

View File

@ -1,4 +1,6 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
#endif
#pragma region ADT #pragma region ADT

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "string_ops.cpp" # pragma once
# include "string_ops.cpp"
#endif
#pragma region Printing #pragma region Printing

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "string_ops.hpp" # pragma once
# include "string_ops.hpp"
#endif
#pragma region Printing #pragma region Printing

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "debug.cpp" # pragma once
# include "debug.cpp"
#endif
#pragma region String Ops #pragma region String Ops

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "memory.hpp" # pragma once
# include "memory.hpp"
#endif
#pragma region String Ops #pragma region String Ops

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "hashing.cpp" # pragma once
# include "hashing.cpp"
#endif
#pragma region String #pragma region String

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "hashing.hpp" # pragma once
# include "hashing.hpp"
#endif
#pragma region Strings #pragma region Strings

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "filesystem.cpp" # pragma once
# include "filesystem.cpp"
#endif
#pragma region Timing #pragma region Timing

View File

@ -1,5 +1,7 @@
#pragma once #ifdef GEN_INTELLISENSE_DIRECTIVES
#include "filesystem.hpp" # pragma once
# include "filesystem.hpp"
#endif
#pragma region Timing #pragma region Timing