gencpp/gen_c_library/components/misc.hpp

73 lines
1.8 KiB
C++
Raw Normal View History

// #pragma once
// #include "../project/gen.hpp"
// using namespace gen;
using SwapContentProc = CodeBody(void);
b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& body )
{
2024-12-01 09:48:58 -08:00
b32 found = false;
CodePreprocessCond cond = cast(CodePreprocessCond, entry_iter);
if ( cond->Content.contains(cond_sig) )
{
2024-12-01 09:48:58 -08:00
log_fmt("Preprocess cond found: %S\n", cond->Content);
found = true;
s32 depth = 1;
2024-11-30 22:40:31 -08:00
++ entry_iter; for(b32 continue_for = true; continue_for && entry_iter != body.end(); ) switch
(entry_iter->Type) {
case ECode::Preprocess_If:
case ECode::Preprocess_IfDef:
case ECode::Preprocess_IfNotDef:
depth ++;
break;
case ECode::Preprocess_EndIf:
{
depth --;
if (depth == 0) {
continue_for = false;
2024-11-30 22:40:31 -08:00
break;
}
}
break;
2024-11-30 22:40:31 -08:00
default:
++ entry_iter;
break;
}
}
2024-12-01 09:48:58 -08:00
return found;
}
2024-11-30 22:40:31 -08:00
bool swap_pragma_region_implementation( StrC region_name, SwapContentProc* swap_content, Code& entry_iter, CodeBody& body )
{
2024-11-30 22:40:31 -08:00
bool found = false;
CodePragma possible_region = cast(CodePragma, entry_iter);
String region_sig = string_fmt_buf(GlobalAllocator, "region %s", region_name.Ptr);
String endregion_sig = string_fmt_buf(GlobalAllocator, "endregion %s", region_name.Ptr);
if ( possible_region->Content.contains(region_sig))
{
2024-11-30 22:40:31 -08:00
found = true;
// body.append(possible_region);
body.append(swap_content());
++ entry_iter; for(b32 continue_for = true; continue_for; ++entry_iter) switch
(entry_iter->Type) {
case ECode::Preprocess_Pragma:
{
CodePragma possible_end_region = cast(CodePragma, entry_iter);
if ( possible_end_region->Content.contains(endregion_sig) ) {
2024-11-30 22:40:31 -08:00
// body.append(possible_end_region);
continue_for = false;
}
}
break;
}
2024-11-30 22:40:31 -08:00
body.append(entry_iter);
}
2024-11-30 22:40:31 -08:00
return found;
}