2024-11-30 20:38:27 -08:00
|
|
|
// #pragma once
|
|
|
|
// #include "../project/gen.hpp"
|
|
|
|
|
|
|
|
// using namespace gen;
|
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
|
|
|
|
|
2024-11-30 20:38:27 -08:00
|
|
|
b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& body )
|
|
|
|
{
|
2024-12-01 09:48:58 -08:00
|
|
|
b32 found = false;
|
2024-12-01 23:38:55 -08:00
|
|
|
CodePreprocessCond cond = cast(CodePreprocessCond, entry_iter);
|
2024-11-30 20:38:27 -08:00
|
|
|
if ( cond->Content.contains(cond_sig) )
|
|
|
|
{
|
2024-12-04 08:01:53 -08:00
|
|
|
log_fmt("Preprocess cond found: %SC\n", cond->Content);
|
2024-12-01 09:48:58 -08:00
|
|
|
found = true;
|
|
|
|
|
2024-11-30 20:38:27 -08:00
|
|
|
s32 depth = 1;
|
2024-12-04 08:01:53 -08:00
|
|
|
++ entry_iter;
|
|
|
|
for(b32 continue_for = true; continue_for && entry_iter != body.end(); ) switch
|
2024-11-30 20:38:27 -08:00
|
|
|
(entry_iter->Type) {
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Preprocess_If:
|
|
|
|
case CT_Preprocess_IfDef:
|
|
|
|
case CT_Preprocess_IfNotDef:
|
2024-12-04 08:01:53 -08:00
|
|
|
++ depth;
|
|
|
|
++ entry_iter;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CT_Preprocess_Else:
|
|
|
|
++ entry_iter;
|
|
|
|
for(; continue_for && entry_iter != body.end(); ++ entry_iter)
|
|
|
|
{
|
|
|
|
if (entry_iter->Type == CT_Preprocess_EndIf)
|
|
|
|
{
|
|
|
|
continue_for = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
body.append(entry_iter);
|
|
|
|
}
|
2024-11-30 20:38:27 -08:00
|
|
|
break;
|
|
|
|
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Preprocess_EndIf:
|
2024-11-30 20:38:27 -08:00
|
|
|
{
|
|
|
|
depth --;
|
|
|
|
if (depth == 0) {
|
|
|
|
continue_for = false;
|
2024-11-30 22:40:31 -08:00
|
|
|
break;
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|
2024-12-04 08:01:53 -08:00
|
|
|
++ entry_iter;
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|
|
|
|
break;
|
2024-11-30 22:40:31 -08:00
|
|
|
default:
|
|
|
|
++ entry_iter;
|
|
|
|
break;
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-01 09:48:58 -08:00
|
|
|
return found;
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
CodeFn rename_function_to_unique_symbol(CodeFn fn, StrC optional_prefix = txt(""))
|
|
|
|
{
|
|
|
|
// Get basic components for the name
|
|
|
|
StrC old_name = fn->Name;
|
|
|
|
String new_name;
|
|
|
|
|
|
|
|
// Add prefix if provided
|
|
|
|
if (optional_prefix.Len)
|
|
|
|
new_name = string_fmt_buf(GlobalAllocator, "%SC_%SC_", optional_prefix, old_name);
|
|
|
|
else
|
|
|
|
new_name = string_fmt_buf(GlobalAllocator, "%SC_", old_name);
|
|
|
|
|
|
|
|
// Add return type to the signature
|
|
|
|
if (fn->ReturnType)
|
|
|
|
new_name.append_fmt("_%SC", fn->ReturnType->Name);
|
|
|
|
|
|
|
|
// Add parameter types to create a unique signature
|
|
|
|
bool first_param = true;
|
|
|
|
for (CodeParam param = fn->Params; param.ast; param = param->Next)
|
|
|
|
{
|
|
|
|
if (param->ValueType)
|
|
|
|
{
|
|
|
|
// Add separator for readability
|
|
|
|
if (first_param)
|
|
|
|
{
|
|
|
|
new_name.append("_P_");
|
|
|
|
first_param = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
new_name.append("_");
|
|
|
|
|
|
|
|
// Add parameter type, handle any specifiers
|
|
|
|
if (param->ValueType->Specs && param->ValueType->Specs->NumEntries > 0)
|
|
|
|
{
|
|
|
|
// Add specifiers (const, volatile, etc)
|
|
|
|
for (Specifier spec : param->ValueType->Specs)
|
|
|
|
{
|
|
|
|
if (spec == Spec_Ptr) {
|
|
|
|
new_name.append("ptr_");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_name.append_fmt("%SC_", to_str(spec));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new_name.append_fmt("%SC", param->ValueType->Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle function specifiers if present
|
|
|
|
if (fn->Specs && fn->Specs->NumEntries > 0)
|
|
|
|
{
|
|
|
|
new_name.append("_S_");
|
|
|
|
for (Specifier* spec = begin(fn->Specs);
|
|
|
|
spec != end(fn->Specs);
|
|
|
|
++spec)
|
|
|
|
{
|
|
|
|
new_name.append_fmt("%SC_", to_str(*spec));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn->Name = new_name;
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
2024-12-04 21:40:51 -08:00
|
|
|
using SwapContentProc = CodeBody(void);
|
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 20:38:27 -08:00
|
|
|
{
|
2024-11-30 22:40:31 -08:00
|
|
|
bool found = false;
|
2024-12-01 23:38:55 -08:00
|
|
|
CodePragma possible_region = cast(CodePragma, entry_iter);
|
2024-11-30 20:38:27 -08:00
|
|
|
|
|
|
|
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);
|
2024-11-30 20:38:27 -08:00
|
|
|
body.append(swap_content());
|
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
++ entry_iter;
|
|
|
|
for(b32 continue_for = true; continue_for; ++entry_iter) switch
|
2024-11-30 20:38:27 -08:00
|
|
|
(entry_iter->Type) {
|
2024-12-03 17:21:08 -08:00
|
|
|
case CT_Preprocess_Pragma:
|
2024-11-30 20:38:27 -08:00
|
|
|
{
|
2024-12-01 23:38:55 -08:00
|
|
|
CodePragma possible_end_region = cast(CodePragma, entry_iter);
|
2024-11-30 20:38:27 -08:00
|
|
|
if ( possible_end_region->Content.contains(endregion_sig) ) {
|
2024-11-30 22:40:31 -08:00
|
|
|
// body.append(possible_end_region);
|
2024-11-30 20:38:27 -08:00
|
|
|
continue_for = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2024-11-30 22:40:31 -08:00
|
|
|
body.append(entry_iter);
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|
2024-11-30 22:40:31 -08:00
|
|
|
return found;
|
2024-11-30 20:38:27 -08:00
|
|
|
}
|