Naive preprocessor support initial implementation (compiles and runs, not heavily tested)

This commit is contained in:
2023-07-30 01:21:04 -04:00
parent 3d7cb85e71
commit bfbfae466f
19 changed files with 641 additions and 199 deletions

View File

@ -489,6 +489,26 @@ CodeClass def_class( StrC name
return result;
}
CodeDefine def_define( StrC name, StrC content )
{
using namespace ECode;
name_check( def_define, name );
if ( content.Len <= 0 || content.Ptr == nullptr )
{
log_failure( "gen::def_define: Invalid value provided" );
return CodeInvalid;
}
CodeDefine
result = (CodeDefine) make_code();
result->Name = get_cached_string( name );
result->Content = get_cached_string( content );
return result;
}
CodeEnum def_enum( StrC name
, Code body, CodeType type
, EnumT specifier, CodeAttributes attributes
@ -719,7 +739,7 @@ CodeInclude def_include ( StrC path )
Code
result = make_code();
result->Type = ECode::Preprocessor_Include;
result->Type = ECode::Preprocess_Include;
result->Name = get_cached_string( path );
result->Content = result->Name;
@ -910,6 +930,53 @@ CodeParam def_param( CodeType type, StrC name, Code value )
return result;
}
CodePragma def_pragma( StrC directive )
{
using namespace ECode;
if ( directive.Len <= 0 || directive.Ptr == nullptr )
{
log_failure( "gen::def_comment: Invalid comment provided:" );
return CodeInvalid;
}
CodePragma
result = (CodePragma) make_code();
result->Type = Preprocess_Pragma;
result->Content = get_cached_string( directive );
return result;
}
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC expr )
{
using namespace ECode;
if ( expr.Len <= 0 || expr.Ptr == nullptr )
{
log_failure( "gen::def_comment: Invalid comment provided:" );
return CodeInvalid;
}
CodePreprocessCond
result = (CodePreprocessCond) make_code();
result->Content = get_cached_string( expr );
switch (type)
{
case EPreprocessCond::If:
result->Type = ECode::Preprocess_If;
case EPreprocessCond::IfDef:
result->Type = Preprocess_IfDef;
case EPreprocessCond::IfNotDef:
result->Type = Preprocess_IfNotDef;
case EPreprocessCond::ElIf:
result->Type = Preprocess_ElIf;
}
return result;
}
CodeSpecifiers def_specifier( SpecifierT spec )
{
CodeSpecifiers