2020-01-19 08:14:14 +00:00
|
|
|
//
|
2020-01-21 05:11:07 +00:00
|
|
|
// File: foldhaus_meta.cpp
|
|
|
|
// Author: Peter Slattery
|
|
|
|
// Creation Date: 2020-01-19
|
2020-01-19 08:14:14 +00:00
|
|
|
//
|
2020-01-21 05:11:07 +00:00
|
|
|
#ifndef FOLDHAUS_META_CPP
|
2019-12-31 21:15:28 +00:00
|
|
|
|
2020-01-20 01:48:57 +00:00
|
|
|
#include "gs_meta.cpp"
|
|
|
|
#include "gs_meta_typeinfo_generator.h"
|
2020-01-20 01:34:49 +00:00
|
|
|
|
2020-02-02 03:15:04 +00:00
|
|
|
internal void
|
|
|
|
GenerateNodeMetaInfo (gsm_code_generator* NodeTypeGen, string_builder* CallNodeProcGen, gs_meta_preprocessor Meta)
|
2020-01-20 01:34:49 +00:00
|
|
|
{
|
2020-01-21 05:11:07 +00:00
|
|
|
// TODO(Peter): Create a FilterTypesByTag function to create a contiguous array
|
|
|
|
// of type_definition**
|
2020-02-02 03:15:04 +00:00
|
|
|
|
|
|
|
WriteF(CallNodeProcGen, "void CallNodeProc(node_type Type, u8* NodeData)\n{\n");
|
|
|
|
WriteF(CallNodeProcGen, " switch(Type) { \n");
|
2020-01-21 06:56:36 +00:00
|
|
|
for (u32 b = 0; b < Meta.TypeTable.TypeBucketsCount; b++)
|
2020-01-21 05:11:07 +00:00
|
|
|
{
|
2020-01-21 06:56:36 +00:00
|
|
|
type_table_hash_bucket Bucket = Meta.TypeTable.Types[b];
|
|
|
|
for (u32 i = 0; i < TYPE_TABLE_BUCKET_MAX; i++)
|
2020-01-21 05:11:07 +00:00
|
|
|
{
|
2020-02-02 03:15:04 +00:00
|
|
|
if (Bucket.Keys[i] == 0) { continue; }
|
2020-01-21 05:11:07 +00:00
|
|
|
|
2020-01-21 06:56:36 +00:00
|
|
|
type_definition* Decl = Bucket.Values + i;
|
|
|
|
if (HasTag(MakeStringLiteral("node_proc"), Decl->MetaTags) &&
|
|
|
|
Decl->Type == TypeDef_Function)
|
2020-01-21 05:11:07 +00:00
|
|
|
{
|
2020-02-02 03:15:04 +00:00
|
|
|
if (Decl->Function.Parameters.Used > 1)
|
|
|
|
{
|
|
|
|
WriteF(CallNodeProcGen, "ERROR: Procedure tagged with node_proc has more than one parameter\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddEnumElement(NodeTypeGen, Decl->Identifier);
|
2020-01-21 06:56:36 +00:00
|
|
|
|
|
|
|
type_table_handle ReturnTypeHandle = Decl->Function.ReturnTypeHandle;
|
|
|
|
type_definition* ReturnType = GetTypeDefinition(ReturnTypeHandle, Meta.TypeTable);
|
2020-02-02 03:15:04 +00:00
|
|
|
|
|
|
|
WriteF(CallNodeProcGen, " case NodeType_%.*s:\n", StringExpand(Decl->Identifier));
|
|
|
|
WriteF(CallNodeProcGen, " {\n");
|
|
|
|
WriteF(CallNodeProcGen, " %.*s(", StringExpand(Decl->Identifier));
|
|
|
|
|
2020-01-21 06:56:36 +00:00
|
|
|
for (u32 j = 0; j < Decl->Function.Parameters.Used; j++)
|
|
|
|
{
|
|
|
|
variable_decl* Param = Decl->Function.Parameters.GetElementAtIndex(j);
|
|
|
|
type_table_handle ParamTypeHandle = Param->TypeHandle;
|
|
|
|
type_definition* ParamType = GetTypeDefinition(ParamTypeHandle, Meta.TypeTable);
|
2020-02-02 03:15:04 +00:00
|
|
|
WriteF(CallNodeProcGen, "(%.*s*)NodeData", StringExpand(ParamType->Identifier));
|
|
|
|
if (j + 1 < Decl->Function.Parameters.Used)
|
|
|
|
{
|
|
|
|
WriteF(CallNodeProcGen, ", ");
|
|
|
|
}
|
2020-01-21 06:56:36 +00:00
|
|
|
}
|
2020-02-02 03:15:04 +00:00
|
|
|
WriteF(CallNodeProcGen, ");\n");
|
|
|
|
WriteF(CallNodeProcGen, " } break;\n");
|
2020-01-21 05:11:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-02 03:15:04 +00:00
|
|
|
WriteF(CallNodeProcGen, " }\n");
|
|
|
|
WriteF(CallNodeProcGen, "}\n\n");
|
2020-01-21 05:11:07 +00:00
|
|
|
|
2020-02-02 03:15:04 +00:00
|
|
|
FinishEnumGeneration(NodeTypeGen);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int ArgCount, char* Args[])
|
|
|
|
{
|
|
|
|
if (ArgCount <= 1)
|
|
|
|
{
|
|
|
|
printf("Please supply at least one source directory to analyze.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
gs_meta_preprocessor Meta = PreprocessProgram(Args[1]);
|
|
|
|
|
|
|
|
typeinfo_generator TypeGenerator = InitTypeInfoGenerator(Meta.TypeTable);
|
|
|
|
GenerateFilteredTypeInfo(MakeStringLiteral("node_struct"), Meta.TypeTable, &TypeGenerator);
|
|
|
|
GenerateFilteredTypeInfo(MakeStringLiteral("gen_type_info"), Meta.TypeTable, &TypeGenerator);
|
|
|
|
FinishGeneratingTypes(&TypeGenerator);
|
|
|
|
|
|
|
|
gsm_code_generator NodeTypeGen = BeginEnumGeneration("node_type", "NodeType", false, true);
|
|
|
|
string_builder CallNodeProcGen = {0};
|
|
|
|
GenerateNodeMetaInfo(&NodeTypeGen, &CallNodeProcGen, Meta);
|
|
|
|
|
|
|
|
string_builder PanelInfoGen = {0};
|
2020-01-21 05:11:07 +00:00
|
|
|
|
2020-01-19 12:03:07 +00:00
|
|
|
FILE* TypeInfoH = fopen("C:\\projects\\foldhaus\\src\\generated\\gs_meta_generated_typeinfo.h", "w");
|
|
|
|
if (TypeInfoH)
|
|
|
|
{
|
2020-01-21 05:11:07 +00:00
|
|
|
WriteStringBuilderToFile(*TypeGenerator.TypeList.Builder, TypeInfoH);
|
2020-01-19 12:03:07 +00:00
|
|
|
WriteStringBuilderToFile(TypeGenerator.StructMembers, TypeInfoH);
|
|
|
|
WriteStringBuilderToFile(TypeGenerator.TypeDefinitions, TypeInfoH);
|
2020-01-20 01:03:19 +00:00
|
|
|
fclose(TypeInfoH);
|
2020-01-19 12:03:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 05:11:07 +00:00
|
|
|
FILE* NodeInfoH = fopen("C:\\projects\\foldhaus\\src\\generated\\foldhaus_nodes_generated.h", "w");
|
|
|
|
if (NodeInfoH)
|
|
|
|
{
|
|
|
|
WriteStringBuilderToFile(*NodeTypeGen.Builder, NodeInfoH);
|
2020-02-02 03:15:04 +00:00
|
|
|
WriteStringBuilderToFile(CallNodeProcGen, NodeInfoH);
|
2020-01-21 05:11:07 +00:00
|
|
|
fclose(NodeInfoH);
|
|
|
|
}
|
|
|
|
|
2020-01-20 01:34:49 +00:00
|
|
|
FinishMetaprogram(&Meta);
|
2020-02-02 03:15:04 +00:00
|
|
|
|
2020-01-19 12:03:07 +00:00
|
|
|
//__debugbreak();
|
2019-10-30 14:28:02 +00:00
|
|
|
return 0;
|
2020-01-21 05:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FOLDHAUS_META_CPP
|
|
|
|
#endif // FOLDHAUS_META_CPP
|