From 9c815041788a26b4325daf00dd92c4df7fb012e6 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Mon, 24 Jul 2023 22:19:21 -0400 Subject: [PATCH] Progress towards bootstrap/singleheader generation I will most likely need to refactor some of the components & dependencies files to get the desired gneration implementation the way I want. Specficially I want to be able to eliminate macros I'm using for enums and common patterns for implmeentation of the data structures. When it comes to the cpp files, I may leave those alone as the macros largely help ith readability. Replacing those macros is expensive and most likely not worth it. The macros under consideration with replacing using the library bootstrap are: * Define_Types * Define_Operators * Define_Specifiers * GEN_Define_Attribute_Tokens * Define_CodeType * Using_Code * Define_TokType * def_constant_spec ? * Helper Macros for def_**_body functions ? * AST unallowed types case macros? (The last three I'm unsure about as they work fine, and neeeding the debugger steps there is a rare scenario...) The enums could be manually generated and have its fields derived from a CSV (which is what genc is currently doing). This would allow the user to specify custom attribute macros as well with greater ease. I may maually inline ProcessModuleFlags, as its not even necessary as any specific symbol with a module flag will only use the export value. Import is only used on modules themselves (from what I can tell). The Parser::lex function could be offloaded to its own file in case the user wants to swap the entire thing out. (Most likely may want to for various purposes) The problem with extracting any definitions out of a component file currently is that will lead to splintering that componnet to multiple other components. This is necessary as the proper scanner is not implemented yet (only a reduimentary scan_file proc is made so far). --- .gitignore | 3 + .vscode/launch.json | 9 + Readme.md | 15 +- project/Readme.md | 72 -------- project/components/gen.header_start.hpp | 17 ++ project/filesystem/gen.scanner.hpp | 35 +++- project/gen.bootstrap.cpp | 58 +++++++ project/gen.cpp | 3 +- project/gen.hpp | 19 +-- scripts/.clang-format | 163 +++++++++++++++++++ scripts/bootstrap.ci.ps1 | 24 +++ scripts/clean.ps1 | 20 ++- scripts/singleheader.ci.ps1 | 24 +++ singleheader/Readme.md | 6 + singleheader/components/gen.header_start.hpp | 11 ++ singleheader/gen.singleheader.cpp | 68 +++++++- singleheader/gen/Readme.md | 5 - singleheader/gen/gen.singleheader.cpp | 0 singleheader/meson.build | 4 +- 19 files changed, 450 insertions(+), 106 deletions(-) create mode 100644 project/components/gen.header_start.hpp create mode 100644 scripts/.clang-format create mode 100644 singleheader/Readme.md create mode 100644 singleheader/components/gen.header_start.hpp delete mode 100644 singleheader/gen/Readme.md delete mode 100644 singleheader/gen/gen.singleheader.cpp diff --git a/.gitignore b/.gitignore index 0e0089d..92a34a8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ build/* **/*.gen.* +gencpp.hpp +gencpp.cpp + # Build results [Dd]ebug/ [Dd]ebugPublic/ diff --git a/.vscode/launch.json b/.vscode/launch.json index 1de23bb..7b1d7c6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -22,6 +22,15 @@ "args": [], "cwd": "${workspaceFolder}/test/gen/", "visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis" + }, + { + "type": "cppvsdbg", + "request": "launch", + "name": "Debug bootstrap vsdbg", + "program": "${workspaceFolder}/project/build/gencpp_bootstrap.exe", + "args": [], + "cwd": "${workspaceFolder}/project/", + "visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis" } ] } diff --git a/Readme.md b/Readme.md index 77b4080..6e10d65 100644 --- a/Readme.md +++ b/Readme.md @@ -7,7 +7,7 @@ These build up a code AST to then serialize with a file builder. General goal is to have a less than 15k sloc library that takes at most a couple of hours to learn and make use of. -*Why 15?* Assuming a seasoned coder of C++ can read and understand around 1000-2000 lines of code per hour, 15,000 could be understood in under 16-18 hours +*Why 15k ?* Assuming a seasoned coder of C++ can read and understand around 1000-2000 lines of code per hour, 15,000 could be understood in under 16-18 hours and have confidence in modifying for their use case. This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto), @@ -162,7 +162,18 @@ struct ArrayHeader ## Building -An example of building is provided in the test directory. +An example of building is provided within project, singleheader, and test. + +**Project** + +`gen.bootstrap.cpp` generates a segmented version of the library following a more traditional cpp convention. +With the exception that: *The component hpp and cpp files are all included into their respective header and source* + +**Singleheader** + +`gen.singleheader.cpp` generated a single-header version of the library following the convention shown in popular libraries such as: gb, stb, and zpl. + +**Test** There are two meson build files the one within test is the program's build specification. The other one in the gen directory within test is the metaprogram's build specification. diff --git a/project/Readme.md b/project/Readme.md index 1f8287c..44800ab 100644 --- a/project/Readme.md +++ b/project/Readme.md @@ -14,15 +14,10 @@ Both libraries use *pre-generated* (self-hosting I guess) version of the library The default `gen.bootstrap.cpp` located in the project folder is meant to be produce a standard segmeneted library, where the components of the library have relatively dedicated header and source files. With dependencies included at the top of the file and each header starting with a pragma once. -`gen.singleheader.cpp` in the single header folder with its own `meson.build` generates the library as a single header `gen.hpp`. -Following the same convention seen in the gb, stb, and zpl libraries. - Use those to get a general idea of how to make your own tailored version. If the naming convention is undesired, the `gencpp.refactor` script can be used with the [refactor]() -## gen.hpp - Feature Macros: * `GEN_DONT_USE_NAMESPACE` : By default, the library is wrapped in a `gen` namespace, this will disable that expose it to the global scope. @@ -36,70 +31,3 @@ Feature Macros: `GEN_USE_RECURSIVE_AST_DUPLICATION` is available but its not well tested and should not need to be used. If constructing ASTs properly. There should be no modification of ASTs, and thus this would never become an issue. (I will probably remove down the line...) - -Due to the design of `gen.hpp` to support being written alongside runtime intended code (in the same file), all the code is wrapped in a `GEN_TIME` `#ifdef` and then wrapped further in a `gen` namespace to avoid pollution of the global scope. - -*Note: Its possible with the scanner feature to support parsing runtime files that use "generic" macros or identifiers with certain patterns. -This can be used to auto-queue generation of dependent definitions for the symbols used.* - -### Organization - -Dependencies : Mostly from the c-zpl library. - -log_failure definition : based on whether to always use fatal on all errors - -Major enum definitions and their associated functions used with the AST data - -* `ECode` : Used to tag ASTs by their type -* `EOperator` : Used to tag operator overloads with their op type -* `ESpecifier` : Used with specifier ASTs for all specifiers the user may tag an associated -AST with. -* `AccessSpec` : Used with class and struct ASTs to denote the public, protected, or private fields. -* `EnumT` : Used with def_enum to determine if constructing a regular enum or an enum class. -* `ModuleFlag` : Used with any valid definition that can have export or import related keywords associated with it. - -#### Data Structures - -`StringCache` : Hash table for cached strings. (`StringCached` typedef used to denote strings managed by it) - -`Code` : Wrapper for `AST` with functionality for handling it appropriately. -`AST` : The node data structure for the code. -`Code Types` : Codes with typed ASTs. Body, Param, and Specifier have unique implementation, the rest use `Define_CodeType` -`AST Types` : Filtered AST definitions. - -#### Gen Interface - -First set of forwards are either backend functions used for various aspects of AST generation or configurations allocators used for different containers. - -Interface forwards defined in order of: Upfront, Parsing, Untyped. - -From there forwards for the File handlers are defined: Builder, Editor, Scanner. - -#### Macros - -General helper macros are defined along with the optional DSL macros. - -#### Constants - -Constants including optional ones are defined. - -#### Inlines - -Inlined functions related to the AST datatype that required forwards for gen interface functions are defined. - -## gen.cpp - -* Dependencies -* Static data -* AST Body case macros are next. -* AST implementation -* Gen interface begins with its `init`, `deinit`, etc.. Until `make_code_entires` -* operator__validate defined, which will be used to verify if an operator definition is constructible. -* Allocator interface for data arrays, code pool, code entries, string arenas, and string table. -* Helper macros used throughout the constructor API -* Upfront constructors, following the same order as shown in the header. -* Parsing constructors, it defines its own lexer, and has many helper functions for parsing not exposed through the header. -* Untyped constructors -* Builder -* Editor -* Scanner diff --git a/project/components/gen.header_start.hpp b/project/components/gen.header_start.hpp new file mode 100644 index 0000000..4639849 --- /dev/null +++ b/project/components/gen.header_start.hpp @@ -0,0 +1,17 @@ +/* + gencpp: An attempt at "simple" staged metaprogramming for c/c++. + + See Readme.md for more information from the project repository. + + Public Address: + https://github.com/Ed94/gencpp +*/ +#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME) +# error Gen.hpp : GEN_TIME not defined +#endif + +//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file. +// Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl +#ifndef GEN_ROLL_OWN_DEPENDENCIES +# include "dependencies/gen.dep.hpp" +#endif diff --git a/project/filesystem/gen.scanner.hpp b/project/filesystem/gen.scanner.hpp index e7e3f23..342f062 100644 --- a/project/filesystem/gen.scanner.hpp +++ b/project/filesystem/gen.scanner.hpp @@ -1,7 +1,37 @@ #pragma once #include "gen.hpp" -namespace gen { +GEN_NS_BEGIN + +Code scan_file( char const* path ) +{ + FileInfo file; + + FileError error = file_open_mode( & file, EFileMode_READ, path ); + if ( error != EFileError_NONE ) + { + fatal( "scan_file: Could not open genc.macro.h: %s", path ); + } + + sw fsize = file_size( & file ); + if ( fsize <= 0 ) + { + fatal("scan_file: %s is empty", path ); + } + + String str = String::make_reserve( GlobalAllocator, fsize ); + file_read( & file, str, fsize ); + str.get_header().Length = fsize; + + file_close( & file ); + + return untyped_str( str ); +} + +struct Policy +{ + // Nothing for now. +}; struct SymbolInfo { @@ -40,5 +70,4 @@ struct Scanner bool process_requests( Array out_receipts ); }; -// namespace gen -} +GEN_NS_END diff --git a/project/gen.bootstrap.cpp b/project/gen.bootstrap.cpp index fd912eb..a784e37 100644 --- a/project/gen.bootstrap.cpp +++ b/project/gen.bootstrap.cpp @@ -2,13 +2,71 @@ #define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_EXPOSE_BACKEND #include "gen.cpp" +#include "filesystem/gen.scanner.hpp" using namespace gen; +bool namespace_by_default = true; + +constexpr StrC nspace_default = txt_StrC(R"( +#if defined(GEN_DONT_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN) +# define GEN_NS_BEGIN +# define GEN_NS_END +#elif ! defined(GEN_NS_BEGIN) +# define GEN_NS_BEGIN namespace gen { +# define GEN_NS_END } +#endif +)"); + +constexpr StrC nspace_non_default = txt_StrC(R"( +#if ! defined(GEN_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN) +# define GEN_NS_BEGIN +# define GEN_NS_END +#elif ! defined(GEN_NS_BEGIN) +# define GEN_NS_BEGIN namespace gen { +# define GEN_NS_END } +#endif +)"); + int gen_main() { + gen::init(); + Code push_ignores = scan_file( "helpers/gen.push_ignores.inline.hpp" ); + Code pop_ignores = scan_file( "helpers/gen.pop_ignores.inline.hpp" ); + Builder gen_deps_header; + { + } + + Builder gen_deps_impl; + { + + } + + Builder gen_header; + { + Code header_start = scan_file( "components/gen.header_start.hpp" ); + Code nspace_macro = untyped_str( namespace_by_default ? nspace_default : nspace_non_default ); + + gen_header.open( "gencpp.hpp" ); + gen_header.print_fmt("#pragma once\n\n"); + gen_header.print( push_ignores ); + gen_header.print( header_start ); + gen_header.print( nspace_macro ); + gen_header.print_fmt( "GEN_NS_BEGIN\n"); + + gen_header.print_fmt( "\nGEN_NS_END\n\n"); + gen_header.print( pop_ignores ); + gen_header.write(); + } + + Builder gen_impl; + { + + } + + gen::deinit(); return 0; } diff --git a/project/gen.cpp b/project/gen.cpp index 07c0229..bd3aead 100644 --- a/project/gen.cpp +++ b/project/gen.cpp @@ -1,10 +1,11 @@ +#include "helpers/gen.push_ignores.inline.hpp" + // ReSharper disable CppClangTidyClangDiagnosticSwitchEnum #if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME) #error Gen.hpp : GEN_TIME not defined #endif -#include "helpers/gen.push_ignores.inline.hpp" //! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file. //! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl diff --git a/project/gen.hpp b/project/gen.hpp index dac2c40..158f9f9 100644 --- a/project/gen.hpp +++ b/project/gen.hpp @@ -8,25 +8,8 @@ */ #pragma once -#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME) -#error Gen.hpp : GEN_TIME not defined -#endif - #include "helpers/gen.push_ignores.inline.hpp" - -//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file. -// Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl -#ifndef GEN_ROLL_OWN_DEPENDENCIES -# include "dependencies/gen.dep.hpp" -#endif - -#if defined(GEN_DONT_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN) -# define GEN_NS_BEGIN -# define GEN_NS_END -#elif ! defined(GEN_NS_BEGIN) -# define GEN_NS_BEGIN namespace gen { -# define GEN_NS_END } -#endif +#include "components/gen.header_start.hpp" GEN_NS_BEGIN diff --git a/scripts/.clang-format b/scripts/.clang-format new file mode 100644 index 0000000..83822bb --- /dev/null +++ b/scripts/.clang-format @@ -0,0 +1,163 @@ +# Format Style Options - Created with Clang Power Tools +--- +AccessModifierOffset: -4 + +AlignAfterOpenBracket: BlockIndent +AlignArrayOfStructures: Right +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: false + AcrossComments: true + AlignCompound: true + PadOperators: true +AlignConsecutiveBitFields: AcrossComments +AlignConsecutiveDeclarations: AcrossComments +AlignConsecutiveMacros: AcrossComments +AlignEscapedNewlines: Right +AlignOperands: DontAlign + +AlignTrailingComments: true + +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortLambdasOnASingleLine: None +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false + +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes + +BinPackArguments: false +BinPackParameters: false + +BitFieldColonSpacing: Both + +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false + BeforeLambdaBody: false + BeforeWhile: false + +# BreakAfterAttributes: Always +# BreakArrays: false +# BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Allman +BreakBeforeInheritanceComma: true +BreakInheritanceList: BeforeComma +BreakBeforeConceptDeclarations: true +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +BreakStringLiterals: true + +ColumnLimit: 180 + +CompactNamespaces: true + +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth : 4 + +ContinuationIndentWidth: 4 + +Cpp11BracedListStyle: false + +DeriveLineEnding: true + +ExperimentalAutoDetectBinPacking: false + +FixNamespaceComments: true + +IncludeBlocks: Preserve + + +IndentCaseBlocks: true +IndentCaseLabels: true +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: AfterHash +IndentRequires: true +IndentWidth: 4 +IndentWrappedFunctionNames: false + +# InsertNewlineAtEOF: true +InsertTrailingCommas: Wrapped + +LambdaBodyIndentation: OuterScope + +Language: Cpp + +MaxEmptyLinesToKeep: 4 + +NamespaceIndentation: All + +PointerAlignment: Left + +QualifierAlignment: Leave + +ReferenceAlignment: Left + +ReflowComments: true + +# RequiresExpressionIndentation: OuterScope + +SeparateDefinitionBlocks: Always + +ShortNamespaceLines: 40 + +SortIncludes: true +SortUsingDeclarations: true + +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: true +SpaceAfterTemplateKeyword: false + +SpaceAroundPointerQualifiers: Default + +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: true +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatementsExceptControlMacros +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpacesBeforeTrailingComments: 4 + +SpaceInEmptyBlock: true +SpaceInEmptyParentheses: false +SpacesInAngles: true +SpacesInCStyleCastParentheses: true +SpacesInConditionalStatement: true +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: 20 +SpacesInParentheses: true +SpacesInSquareBrackets: true + +Standard: c++17 + +TabWidth: 4 + +UseTab: ForIndentation +... diff --git a/scripts/bootstrap.ci.ps1 b/scripts/bootstrap.ci.ps1 index 5f586d3..f10c4e1 100644 --- a/scripts/bootstrap.ci.ps1 +++ b/scripts/bootstrap.ci.ps1 @@ -39,3 +39,27 @@ Push-Location $path_root & ninja $args_ninja Pop-Location + +Push-location $path_project +# Run meta-program +$gencpp_bootstrap = Join-Path $path_project_build gencpp_bootstrap.exe + +Write-Host `nRunning gencpp bootstrap... +& $gencpp_bootstrap + +# Format generated files +Write-Host `nBeginning format... +$formatParams = @( + '-i' # In-place + '-style=file:../scripts/.clang-format' + '-verbose' +) + +$include = @('gencpp.hpp', 'gencpp.cpp') +$exclude = $null + +$targetFiles = @(Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName) + +clang-format $formatParams $targetFiles +Write-Host "`nFormatting complete" +Pop-Location diff --git a/scripts/clean.ps1 b/scripts/clean.ps1 index 52d7ed4..1477f01 100644 --- a/scripts/clean.ps1 +++ b/scripts/clean.ps1 @@ -28,13 +28,29 @@ if ( Test-Path $path_gen_build ) Remove-Item $path_gen_build -Recurse } -[string[]] $include = '*.h', '*.hpp', '*.cpp' +[string[]] $include = 'gencpp.hpp', 'gencpp.cpp' [string[]] $exclude = +$files = Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude + +if ( $files ) +{ + Remove-Item $files +} + +$files = Get-ChildItem -Recurse -Path $path_singleheader -Include $include -Exclude $exclude + +if ( $files ) +{ + Remove-Item $files +} + +$include = '*.h', '*.hpp', '*.cpp' +$exclude = + $files = Get-ChildItem -Recurse -Path $path_gen -Include $include -Exclude $exclude if ( $files ) { Remove-Item $files } - diff --git a/scripts/singleheader.ci.ps1 b/scripts/singleheader.ci.ps1 index 4ce19ca..628d2d9 100644 --- a/scripts/singleheader.ci.ps1 +++ b/scripts/singleheader.ci.ps1 @@ -39,3 +39,27 @@ Push-Location $path_root & ninja $args_ninja Pop-Location + +Push-location $path_singleheader +# Run meta-program +$gencpp_singleheader = Join-Path $path_singleheader_build gencpp_singleheader.exe + +Write-Host `nRunning gencpp bootstrap... +& $gencpp_singleheader + +# Format generated files +Write-Host `nBeginning format... +$formatParams = @( + '-i' # In-place + '-style=file:../scripts/.clang-format' + '-verbose' +) + +$include = @('gencpp.hpp') +$exclude = $null + +$targetFiles = @(Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName) + +clang-format $formatParams $targetFiles +Write-Host "`nFormatting complete" +Pop-Location diff --git a/singleheader/Readme.md b/singleheader/Readme.md new file mode 100644 index 0000000..7cfb66c --- /dev/null +++ b/singleheader/Readme.md @@ -0,0 +1,6 @@ +# Singleheader + +`gen.singleheader.cpp` with its own `meson.build` generates the library as a single header `gen.hpp`. +Following the same convention seen in the gb, stb, and zpl libraries. + +( Currently WIP ) diff --git a/singleheader/components/gen.header_start.hpp b/singleheader/components/gen.header_start.hpp new file mode 100644 index 0000000..3c607b6 --- /dev/null +++ b/singleheader/components/gen.header_start.hpp @@ -0,0 +1,11 @@ +/* + gencpp: An attempt at "simple" staged metaprogramming for c/c++. + + See Readme.md for more information from the project repository. + + Public Address: + https://github.com/Ed94/gencpp +*/ +#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME) +# error Gen.hpp : GEN_TIME not defined +#endif diff --git a/singleheader/gen.singleheader.cpp b/singleheader/gen.singleheader.cpp index da4af22..9af9306 100644 --- a/singleheader/gen.singleheader.cpp +++ b/singleheader/gen.singleheader.cpp @@ -2,10 +2,76 @@ #define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_EXPOSE_BACKEND #include "gen.cpp" +#include "filesystem/gen.scanner.hpp" using namespace gen; +bool namespace_by_default = true; + +constexpr StrC nspace_default = txt_StrC(R"( +#if defined(GEN_DONT_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN) +# define GEN_NS_BEGIN +# define GEN_NS_END +#elif ! defined(GEN_NS_BEGIN) +# define GEN_NS_BEGIN namespace gen { +# define GEN_NS_END } +#endif +)"); + +constexpr StrC nspace_non_default = txt_StrC(R"( +#if ! defined(GEN_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN) +# define GEN_NS_BEGIN +# define GEN_NS_END +#elif ! defined(GEN_NS_BEGIN) +# define GEN_NS_BEGIN namespace gen { +# define GEN_NS_END } +#endif +)"); + +constexpr StrC gen_implementation_guard = txt_StrC(R"( +#pragma region GENCPP IMPLEMENTATION GUARD +#if ! defined(GEN_IMPLEMENTATION) +# define GEN_IMPLEMENTATION +)"); + +constexpr StrC gen_implementation_end = txt_StrC(R"( +#endif +#pragma endregion GENCPP IMPLEMENTATION GUARD +)"); + int gen_main() { + gen::init(); + + Code push_ignores = scan_file( "../project/helpers/gen.push_ignores.inline.hpp" ); + Code pop_ignores = scan_file( "../project/helpers/gen.pop_ignores.inline.hpp" ); + + Code header_start = scan_file( "components/gen.header_start.hpp" ); + Code nspace_macro = untyped_str( namespace_by_default ? nspace_default : nspace_non_default ); + + Builder gen_header; + gen_header.open( "gencpp.hpp" ); + gen_header.print( push_ignores ); + + // Headers + gen_header.print_fmt("#pragma once\n\n"); + gen_header.print( header_start ); + gen_header.print( nspace_macro ); + gen_header.print_fmt( "GEN_NS_BEGIN\n"); + + gen_header.print_fmt( "\nGEN_NS_END\n"); + + // Implementation + + gen_header.print_fmt( "%s\n\n", (char const*) gen_implementation_guard ); + gen_header.print_fmt( "GEN_NS_BEGIN\n"); + + gen_header.print_fmt( "\nGEN_NS_END\n"); + gen_header.print_fmt( "%s\n", (char const*) gen_implementation_end ); + + gen_header.print( pop_ignores ); + gen_header.write(); + + gen::deinit(); return 0; -} \ No newline at end of file +} diff --git a/singleheader/gen/Readme.md b/singleheader/gen/Readme.md deleted file mode 100644 index 565f337..0000000 --- a/singleheader/gen/Readme.md +++ /dev/null @@ -1,5 +0,0 @@ -# Singleheader generator - -This will require the scanner to be implemented before it can be done properly. - - diff --git a/singleheader/gen/gen.singleheader.cpp b/singleheader/gen/gen.singleheader.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/singleheader/meson.build b/singleheader/meson.build index 14e71fc..828f1ae 100644 --- a/singleheader/meson.build +++ b/singleheader/meson.build @@ -1,4 +1,4 @@ -project( 'gen_singleheader', 'c', 'cpp', default_options : ['buildtype=debug'] ) +project( 'gencpp_singleheader', 'c', 'cpp', default_options : ['buildtype=debug'] ) includes = include_directories( [ @@ -15,4 +15,4 @@ endif add_project_arguments('-DGEN_TIME', language : ['c', 'cpp']) -executable( 'gen_singlehader', sources, include_directories : includes ) +executable( 'gencpp_singleheader', sources, include_directories : includes )