2023-08-28 21:03:08 -07:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
|
|
|
# pragma once
|
|
|
|
# include "gen.hpp"
|
|
|
|
#endif
|
2023-08-21 18:40:23 -07:00
|
|
|
|
2023-08-21 17:27:00 -07:00
|
|
|
// 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.
|
2023-08-28 20:46:50 -07:00
|
|
|
Code scan_file( char const* path )
|
2023-07-24 19:19:21 -07:00
|
|
|
{
|
|
|
|
FileInfo file;
|
|
|
|
|
|
|
|
FileError error = file_open_mode( & file, EFileMode_READ, path );
|
|
|
|
if ( error != EFileError_NONE )
|
|
|
|
{
|
2023-08-09 15:47:59 -07:00
|
|
|
GEN_FATAL( "scan_file: Could not open: %s", path );
|
2023-07-24 19:19:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
sw fsize = file_size( & file );
|
|
|
|
if ( fsize <= 0 )
|
|
|
|
{
|
2023-08-09 15:47:59 -07:00
|
|
|
GEN_FATAL("scan_file: %s is empty", path );
|
2023-07-24 19:19:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
String str = String::make_reserve( GlobalAllocator, fsize );
|
|
|
|
file_read( & file, str, fsize );
|
|
|
|
str.get_header().Length = fsize;
|
|
|
|
|
2023-08-28 20:46:50 -07:00
|
|
|
// 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.
|
2023-08-21 17:27:00 -07:00
|
|
|
{
|
|
|
|
#define current (*scanner)
|
2023-08-28 20:46:50 -07:00
|
|
|
#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" );
|
|
|
|
|
|
|
|
bool found_directive = false;
|
|
|
|
char const* scanner = str.Data;
|
|
|
|
s32 left = fsize;
|
|
|
|
while ( left )
|
2023-08-21 17:27:00 -07:00
|
|
|
{
|
2023-08-28 20:46:50 -07:00
|
|
|
// Processing directive.
|
|
|
|
if ( current == '#' )
|
2023-08-21 17:27:00 -07:00
|
|
|
{
|
2023-08-28 20:46:50 -07:00
|
|
|
move_fwd();
|
|
|
|
while ( left && char_is_space( current ) )
|
|
|
|
move_fwd();
|
2023-08-21 17:27:00 -07:00
|
|
|
|
2023-08-28 20:46:50 -07:00
|
|
|
if ( ! found_directive )
|
2023-08-21 17:27:00 -07:00
|
|
|
{
|
2023-08-28 20:46:50 -07:00
|
|
|
if ( left && str_compare( scanner, directive_start.Ptr, directive_start.Len ) == matched )
|
2023-08-21 17:27:00 -07:00
|
|
|
{
|
2023-08-28 20:46:50 -07:00
|
|
|
scanner += directive_start.Len;
|
|
|
|
left -= directive_start.Len;
|
2023-08-21 17:27:00 -07:00
|
|
|
|
2023-08-28 20:46:50 -07:00
|
|
|
while ( left && char_is_space( current ) )
|
|
|
|
move_fwd();
|
2023-08-21 19:48:05 -07:00
|
|
|
|
2023-08-28 20:46:50 -07:00
|
|
|
if ( left && str_compare( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
|
|
|
|
{
|
|
|
|
scanner += def_intellisense.Len;
|
|
|
|
left -= def_intellisense.Len;
|
|
|
|
|
|
|
|
found_directive = true;
|
|
|
|
}
|
2023-08-21 17:27:00 -07:00
|
|
|
}
|
2023-08-28 20:46:50 -07:00
|
|
|
|
|
|
|
// Skip to end of line
|
|
|
|
while ( left && current != '\r' && current != '\n' )
|
|
|
|
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 ) )
|
2023-08-21 17:27:00 -07:00
|
|
|
{
|
2023-08-28 20:46:50 -07:00
|
|
|
mem_move( str, scanner, left );
|
|
|
|
str.get_header().Length = left;
|
|
|
|
break;
|
2023-08-21 17:27:00 -07:00
|
|
|
}
|
|
|
|
|
2023-08-28 20:46:50 -07:00
|
|
|
mem_move( str, scanner, left );
|
|
|
|
str.get_header().Length = left;
|
2023-08-21 17:27:00 -07:00
|
|
|
|
2023-08-28 20:46:50 -07:00
|
|
|
break;
|
2023-08-21 17:27:00 -07:00
|
|
|
}
|
2023-08-28 20:46:50 -07:00
|
|
|
|
2023-08-21 17:27:00 -07:00
|
|
|
}
|
|
|
|
|
2023-08-28 20:46:50 -07:00
|
|
|
move_fwd();
|
2023-08-21 17:27:00 -07:00
|
|
|
}
|
2023-08-28 20:46:50 -07:00
|
|
|
#undef move_fwd
|
|
|
|
#undef matched
|
2023-08-21 17:27:00 -07:00
|
|
|
#undef current
|
|
|
|
}
|
2023-07-24 19:19:21 -07:00
|
|
|
|
2023-08-21 17:27:00 -07:00
|
|
|
file_close( & file );
|
2023-07-24 19:19:21 -07:00
|
|
|
return untyped_str( str );
|
|
|
|
}
|
|
|
|
|
2023-08-03 20:18:33 -07:00
|
|
|
#if 0
|
2023-07-24 19:19:21 -07:00
|
|
|
struct Policy
|
|
|
|
{
|
|
|
|
// Nothing for now.
|
|
|
|
};
|
2023-07-18 20:33:00 -07:00
|
|
|
|
|
|
|
struct SymbolInfo
|
|
|
|
{
|
|
|
|
StringCached File;
|
|
|
|
char const* Marker;
|
|
|
|
Code Signature;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Scanner
|
|
|
|
{
|
|
|
|
struct RequestEntry
|
|
|
|
{
|
|
|
|
SymbolInfo Info;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Receipt
|
|
|
|
{
|
|
|
|
StringCached File;
|
|
|
|
Code Defintion;
|
|
|
|
bool Result;
|
|
|
|
};
|
|
|
|
|
|
|
|
AllocatorInfo MemAlloc;
|
|
|
|
|
|
|
|
static void set_allocator( AllocatorInfo allocator );
|
|
|
|
|
2023-07-19 20:42:28 -07:00
|
|
|
Array<FileInfo> Files;
|
2023-07-18 20:33:00 -07:00
|
|
|
String Buffer;
|
2023-07-19 20:42:28 -07:00
|
|
|
Array<RequestEntry> Requests;
|
2023-07-18 20:33:00 -07:00
|
|
|
|
|
|
|
void add_files( s32 num, char const** files );
|
|
|
|
|
|
|
|
void add( SymbolInfo signature, Policy policy );
|
|
|
|
|
2023-07-19 20:42:28 -07:00
|
|
|
bool process_requests( Array<Receipt> out_receipts );
|
2023-07-18 20:33:00 -07:00
|
|
|
};
|
2023-08-03 20:18:33 -07:00
|
|
|
#endif
|
2023-07-19 20:42:28 -07:00
|
|
|
|