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",
"GEN_TIME",
"GEN_IMPLEMENTATION"
"GEN_IMPLEMENTATION",
// "GEN_DONT_USE_NAMESPACE"
"GEN_INTELLISENSE_DIRECTIVES"
],
"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",
@ -28,8 +29,9 @@
"UNICODE",
"_UNICODE",
"GEN_TIME",
"GEN_IMPLEMENTATION"
"GEN_IMPLEMENTATION",
// "GEN_DONT_USE_NAMESPACE"
"GEN_INTELLISENSE_DIRECTIVES"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",

View File

@ -1,10 +1,11 @@
#pragma once
#include "gen.hpp"
// 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.
// 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;
@ -24,63 +25,92 @@ Code scan_file( char const* path, bool skip_initial_directives = true )
file_read( & file, str, 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)
StrC toks[] {
txt( "pragma once" ),
txt( "include" )
};
#define matched 0
#define move_fwd() do { ++ scanner; -- left; } while (0)
const StrC directive_start = txt( "ifdef" );
const StrC directive_end = txt( "endif" );
const StrC def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" );
char* scanner = str;
while ( current != '\r' && current != '\n' )
{
for ( StrC tok : toks )
bool found_directive = false;
char const* scanner = str.Data;
s32 left = fsize;
while ( left )
{
// Processing directive.
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 )
{
scanner += tok.Len;
while ( scanner < ( str.Data + str.length() ) && current != '\r' && current != '\n' )
{
++ scanner;
// Skip to end of line
while ( left && current != '\r' && current != '\n' )
move_fwd();
move_fwd();
if ( left && current == '\n' )
move_fwd();
continue;
}
// Skip the line
sptr skip_size = sptr( scanner - str.Data );
if ( (scanner + 2) >= ( str.Data + str.length() ) )
if ( left && str_compare( scanner, directive_end.Ptr, directive_end.Len ) == matched )
{
sptr new_length = sptr( str.get_header().Length ) - skip_size;
mem_move( str, scanner, new_length );
str.get_header().Length = new_length;
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 ) )
{
mem_move( str, scanner, left );
str.get_header().Length = left;
break;
}
if ( current == '\r' )
{
skip_size += 2;
scanner += 2;
}
else
{
skip_size += 1;
scanner += 1;
mem_move( str, scanner, left );
str.get_header().Length = left;
break;
}
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
}

View File

@ -20,18 +20,16 @@ constexpr char const* generation_notice =
"// This file was generated automatially by gencpp's bootstrap.cpp "
"(See: https://github.com/Ed94/gencpp)\n\n";
constexpr bool DontSkipInitialDirectives = false;
int gen_main()
{
gen::init();
Code push_ignores = scan_file( "helpers/push_ignores.inline.hpp", DontSkipInitialDirectives );
Code pop_ignores = scan_file( "helpers/pop_ignores.inline.hpp", DontSkipInitialDirectives );
Code push_ignores = scan_file( "helpers/push_ignores.inline.hpp" );
Code pop_ignores = scan_file( "helpers/pop_ignores.inline.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 basic_types = scan_file( "dependencies/basic_types.hpp" );
Code debug = scan_file( "dependencies/debug.hpp" );
@ -147,31 +145,35 @@ int gen_main()
header.print( pop_ignores );
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
header_ecode = Builder::open( "components/gen/ecode.hpp" );
header_ecode.print( pragma_once );
header_ecode.print_fmt( generation_notice );
header_ecode.print( gen_component_header );
header_ecode.print( ecode );
header_ecode.write();
Builder
header_eoperator = Builder::open( "components/gen/eoperator.hpp" );
header_eoperator.print( pragma_once );
header_eoperator.print_fmt( generation_notice );
header_eoperator.print( gen_component_header );
header_eoperator.print( eoperator );
header_eoperator.write();
Builder
header_especifier = Builder::open( "components/gen/especifier.hpp" );
header_especifier.print( pragma_once );
header_especifier.print_fmt( generation_notice );
header_especifier.print( gen_component_header );
header_especifier.print( especifier );
header_especifier.write();
Builder
header_ast_inlines = Builder::open( "components/gen/ast_inlines.hpp" );
header_ast_inlines.print( pragma_once );
header_ast_inlines.print_fmt( generation_notice );
header_ast_inlines.print( gen_component_header );
header_ast_inlines.print( ast_inlines );
header_ast_inlines.write();
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#endif
// 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
#endif
// 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
#endif
// 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
#include "inlines.hpp"
#include "gen/ast_inlines.hpp"
#endif
#pragma region Constants

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "interface.parsing.cpp"
#endif
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
#include "interface.cpp"
#endif
#pragma region Upfront

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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