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;
for ( StrC tok : toks ) while ( left )
{ {
// Processing directive.
if ( current == '#' ) if ( current == '#' )
{ {
++ scanner; move_fwd();
while ( left && char_is_space( current ) )
move_fwd();
if ( ! found_directive )
{
if ( left && str_compare( scanner, directive_start.Ptr, directive_start.Len ) == matched )
{
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;
}
} }
if ( strncmp( scanner, tok.Ptr, tok.Len ) == 0 ) // Skip to end of line
{ while ( left && current != '\r' && current != '\n' )
scanner += tok.Len; move_fwd();
while ( scanner < ( str.Data + str.length() ) && current != '\r' && current != '\n' ) move_fwd();
{
++ scanner; if ( left && current == '\n' )
move_fwd();
continue;
} }
// Skip the line if ( left && str_compare( scanner, directive_end.Ptr, directive_end.Len ) == matched )
sptr skip_size = sptr( scanner - str.Data );
if ( (scanner + 2) >= ( str.Data + str.length() ) )
{ {
sptr new_length = sptr( str.get_header().Length ) - skip_size; scanner += directive_end.Len;
mem_move( str, scanner, new_length ); left -= directive_end.Len;
str.get_header().Length = new_length;
// 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 ) )
{
mem_move( str, scanner, left );
str.get_header().Length = left;
break; break;
} }
if ( current == '\r' ) mem_move( str, scanner, left );
{ str.get_header().Length = left;
skip_size += 2;
scanner += 2; break;
}
else
{
skip_size += 1;
scanner += 1;
} }
sptr new_length = sptr( str.get_header().Length ) - skip_size;
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 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "ast.hpp" # 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 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "macros.hpp" # include "macros.hpp"
#endif
#pragma region Basic Types #pragma region Basic Types

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "memory.cpp" # 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 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "header_start.hpp" # include "header_start.hpp"
#endif
#pragma region Macros #pragma region Macros

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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