161 Commits

Author SHA1 Message Date
Ed_
81a0376c99 Need cstdlib for systems calls in generator files. update to package_release.ps1 2024-10-27 21:38:02 -04:00
Ed_
1417a68757 updates to test validations
They don't really work great right now...
2024-10-27 21:19:25 -04:00
Ed_
1e4d5ce630 touchup to singleheader.cpp 2024-10-27 21:18:58 -04:00
Ed_
0f2763a115 fixes for unreal use 2024-10-27 21:18:41 -04:00
Ed_
420f452d35 More fixes found by self-parsing 2024-10-27 20:22:36 -04:00
Ed_
908c385de5 Fix exp asts having bad union definitions.
They're not used yet but was causing self-parsing issues.
2024-10-27 20:22:24 -04:00
Ed_
c1878265c8 Minimizing reformatting of generated library files 2024-10-27 20:01:54 -04:00
Ed_
23742868c4 Delete auxillary/vis_ast
When I get to making this it will be with SectrPrototype
2024-10-27 18:59:17 -04:00
Ed_
2e5e31ed3b gencpp : General refactors to dependencies
Mostly just cleanup and renaming of certain stuff (mostly in dependencies).

* Changed uw and sw to usize and ssize.
* Removed zpl_cast usage throughout dependencies
* No longer using GEN_DEF_INLINE & GEN_IMPL_INLINE
* header_start.hpp renamed to platform.hpp for depdendencies header.
2024-10-27 18:58:37 -04:00
Ed_
00df336610 fix type on parser namespace in singleheader.cpp 2024-10-26 18:42:23 -04:00
Ed_
d89c9a6072 de-hardcode target_arch.psm1 import 2024-10-25 13:11:21 -04:00
Ed_
6aa99ac1d5 change how path_root is resolved so it works when cloned into another repository 2024-10-25 13:07:39 -04:00
Ed_
3989f5fa83 formatting and removing unused code 2024-10-25 12:54:55 -04:00
Ed_
f90c0a59b6 inital implemention of UE library variant generator completed 2024-10-25 05:01:37 -04:00
Ed_
33f992ef56 Updated generated ast_inlines.hpp so that operator defs have the inline explicit
* Added support for parsing/serializing specifiers for OpCast roughtly.. Doesn't have constraints on what specifiers beyond whats expected in global nspace scope..
* Minor adjustments to hashtable to avoid UE compile errors
* Make sure scanner.cpp is being made by bootstrap
2024-10-25 04:08:20 -04:00
Ed_
0542204b35 progress on unreal variant generator 2024-10-25 03:00:07 -04:00
Ed_
e5616c5879 generated code update + reverting some fixes for now... 2024-10-25 02:59:56 -04:00
Ed_
40a256f6c3 initial setup for generating a library compatible for usage as an Unreal thirdyparty module. 2024-10-25 01:04:48 -04:00
Ed_
b8e1aa6eb7 WIP : Fixes and other changes
* Number literals weren't getting properly lexed
* Fixes for compiler errors with Unreal Engine configuration.
* Support for "post-name" macros in parameters
* Support for variables initializing directly using constructor syntax.
* Explicitly added inline keyword to header inlines for compiling compile library in multiple translation units.
2024-10-25 01:04:17 -04:00
Ed_
e1592ba410 Bug fixes and updates to package_release.ps1
- Incrased size of the defines_map_arena to 256KB
- Various fixes for the parser
- Various fixes for code serialization
- Fix for is_equal member func in Code types
- Fixes for hasthable container
- Added are_equal static func to String type for use against StrC
- Added starts_with functions to String type
- package_release.ps1 now packages all docs (forgot to update it with last release)
2024-05-05 21:53:22 -04:00
Ed_
4a2a93d41b Updated docs 2024-04-17 18:29:30 -04:00
Ed_
36260f6edb Updated gencpp with latest fixes used in other projects.
This variant can support parsing some Unreal Engine files!!
2024-04-17 17:40:32 -04:00
Ed_
83d691c65c Pushing latest changes for gencpp 2024-04-17 16:55:22 -04:00
Ed_
626ab703a7 Fixed some compilation errors 2023-11-22 15:41:41 -05:00
Ed_
6b10cd2b3e Updated AST_Types.md doc 2023-11-22 15:03:24 -05:00
Ed_
91a3250d4c Finished current iteration of parser_algo docs and parser.cpp inline comment docs
Added some todos and prep for upcoming changes
2023-11-22 14:23:21 -05:00
Ed_
a667eb4afe Progress on parser documentation 2023-11-21 23:36:56 -05:00
Ed_
f67f9547df WIP: Improvements to parser, updated docs
Trying to get support for typename keyword soon
2023-11-21 21:27:33 -05:00
Ed_
772db608be Added support for predefining preprocessor defines before parsing strings of code.
This prevents issues for preprocessor defines not getting treated properly for specific circumstances (such as macro wrappers for specifiers).
2023-11-21 20:09:14 -05:00
Ed_
be023325a9 Added AST & Code definitions segemnted code defs to separate file
For upcoming statements & expression types, just beginning to lay things out for the future.
2023-11-21 20:07:49 -05:00
Ed_
a0ee683f82 Added new csvs for ECode & ETokType to keep track of upcoming additions 2023-11-21 20:06:05 -05:00
Ed_
6ad0ae97bc Added bool type keyword to ETokType, move volatile pos in ESpecifier
volatile can be applied to a function so I moved it there.
2023-11-21 20:05:38 -05:00
Ed_
3319bfcaa9 Updates to test and workspace
Added a more granular test using the original library files. Already helped me identify a bug.
2023-11-21 20:03:51 -05:00
Ed_
9d27c7d37e Lexer improvement prep, segmentation of lexer and parser. 2023-11-20 21:24:27 -05:00
Ed_
5c73fbee83 WIP : AST serialization improvements
Code untestd its an initial draft
2023-11-19 20:35:21 -05:00
Ed_
36ebbfe29b Got refactored raylib working in the vis_ast binary
Now to make that debugger...
2023-11-19 00:01:35 -05:00
Ed_
053daaf877 Merge branch 'main' into dev 2023-11-17 19:26:21 -05:00
Ed_
040ec00606 Raylib c refactor scripts complete 2023-11-17 19:25:54 -05:00
Ed_
919166efa1 fix for build script 2023-10-25 23:55:29 -04:00
Ed_
9bd6dac783 Merge pull request #51 from Ed94/dev 2023-10-25 23:47:29 -04:00
Ed_
212d907d73 Fixed bug with inline comments for variables not parsing correctly. 2023-10-25 23:44:25 -04:00
Ed_
c1ab233686 Fix for bug with comma separated declaration list vars
Known Bug: Inline comments are not printing now
2023-10-25 21:43:22 -04:00
Ed_
b42b224c0d Forgot to push some parser fixes 2023-10-25 03:33:35 -04:00
Ed_
041671762b Got through parsing raylib.h, started to do some major refactors. 2023-10-25 03:26:25 -04:00
Ed_
d0f3b6187e Added initial support for comma-separated variable declaration lists. 2023-10-25 00:25:35 -04:00
Ed_
b22f589203 Progress on preparing raylib for usage 2023-10-24 12:46:59 -04:00
Ed_
4af85f8612 update gitignore for exes 2023-10-24 06:02:07 -04:00
Ed_
e9c151f85d Deleting a sneaked in binary 2023-10-24 06:01:47 -04:00
Ed_
a900e86b65 Got raylib bootstrapped to compile
Still need to setup a refactor script among other things before using.
2023-10-24 06:00:28 -04:00
Ed_
d5a4b77033 Some initial boostrapping of new visual ast aux project 2023-10-24 03:14:20 -04:00
Ed_
eaba60f80b Updated build scripts to latest setup used with HandmadeHero repo 2023-10-24 01:40:21 -04:00
Ed_
912cc6b538 Bugfixes during hiatus
Found while doing some metaprogramming for day 42 of handmade hero.
2023-10-22 21:41:36 -04:00
Ed_
3dd5482a46 set ContinuationIndentWidth to 4 for clang format. 2023-10-01 20:19:16 -04:00
Ed_
632fa10027 Updated readme with partial hiatus notice. 2023-10-01 12:37:29 -04:00
Ed_
6498b13658 Fix for non-foreign include content not getting parsed correctly. 2023-10-01 12:16:15 -04:00
Ed_
7f562cd77f Merge branch 'dev' 2023-09-28 20:36:12 -04:00
Ed_
3a0e971ebf Bugfix for parse_variable, const check for prefix specifiers causing infinite loop. 2023-09-28 20:35:20 -04:00
Ed_
4997cb5878 Merge pull request #45 from Ed94/dev
Dev
2023-09-25 17:50:16 -04:00
Ed_
729c891cbd Last fixes before handmade hero hiatus 2023-09-25 17:48:16 -04:00
Ed_
754bcfb31e Fixes to get it back to where I was last at with the const specifier issue 2023-09-25 16:42:29 -04:00
Ed_
a8708abf8b WIP : Various changes to project before small hiatus. (Broken)
I need to manually review these as the changes have various errors that are difficult to diagnose why.

I took a break to do handmade hero and now a bit rusty.
2023-09-25 12:12:11 -04:00
Ed_
4b48b96a79 WIP : better AST::debug_str()
Now its more contexually rich to the ast type, however I need to hookup tokens from parsing to the AST. There needs to be a way for the debug string to lookup the token and provide the contexual line.
Can either pass it ( TokArray* toks ) from the parser on failure (or `CodeFile`)..
Technically there is more than enough room for another Token* ptr. I could add another and specifiers would still have at minimum 14 slots before needing to extended to next specs.
**************... yeah
2023-09-12 02:32:44 -04:00
Ed_
9495fc2985 Updates to documentation 2023-09-11 18:34:37 -04:00
Ed_
378de73a7d Merge branch 'main' of https://github.com/Ed94/gencpp 2023-09-08 15:15:13 -04:00
Ed_
35ac0c1048 Fix compile-error for singleheader found with scanner's scan_file. 2023-09-08 15:14:43 -04:00
Ed_
2c893d5e35 Merge pull request #34 from Ed94/dev
Dev
2023-09-07 23:06:02 -04:00
Ed_
6ea40094ee More fixes from clang warnings. Parser::lex prep for changes
parse_static_assert now properly adds new-line to end of statement.

I'm going to end up making a static_assert ast... that or when the statement ast is made it will handle adding that newline.
2023-09-07 22:52:51 -04:00
Ed_
0a8d3bfc6a Added fixed arenas (just ergonomics) 2023-09-07 22:29:04 -04:00
Ed_
212b4e6d16 Fixes for compiling with clang
Clang just had better errors and caught stuff msvc did not.
2023-09-07 21:11:57 -04:00
Ed_
d606c790ca Added a new AST member NextVar to be used for comma separated variable support.
Interface adding has been adjusted to use ParentType->Next.

Using the AST_Class->Next was bad since that breaks the linked list a body AST would have used for traversal.
2023-09-06 03:06:30 -04:00
Ed_
2bfbef1d0c strip_formatting : Remove code thats no longer needed.
Its everyting related to stripping a function body.
2023-09-06 02:09:26 -04:00
Ed_
f1fb75cc1c Progress on strip_formatting function, support for multi-dimentional array variables and typenames.
strip_formatting suffers from some edge failure with what looks to be escaped character literals (not entirely sure).

I've decided to not remove formatting from unvalidated function bodies since I plan to support parsing its content properly.
However expression values for a statement will fail to have their formatting removed with this.

Since I don't plan to parse those anytime soon, I'll have to fix any edge cases for those at least..
2023-09-06 02:07:09 -04:00
Ed_
2200bcde9a Improved singleheader test
Need to make the debug_str provided by the AST type aware to provide as much contextual information as possible (finally got to this point with validation).

Singleheader test now directly calls clang-format to cleanup the reconstructed copy of the singleheader. Its needed to remove any sort of formatting discrepancies found by the parser since its sensistive to that for new-lines, etc.
2023-09-05 13:36:59 -04:00
Ed_
3e249d9bc5 Reorganization of parser, refactor of parse_type( bool* ) and progression of parser docs
Wanted to make parser implementation easier to sift through, so I emphasized alphabetical order more.

Since I couldn't just strip whitespace from typenames I decided to make the parse_type more aware of the typename's components if it was a function signature.
This ofc lead to the dark & damp hell that is parsing typenames.

Also made initial implementation to support parsing decltype within a typename signature..

The test failure for the singleheader is still a thing, these changes have not addressed that.
2023-09-05 01:48:11 -04:00
Ed_
3868e1e811 Added cursed typedef 2023-09-04 12:32:31 -04:00
Ed_
543427dfe5 Fixes to parsing for validation
Removed whitespace stripping from parse_type, prepped for doing some major changes for function signature typenames

Moved template argument parsing to its own helper function since its used in more the one spot.

Latest failure is due to stack overflow when validating parameters. (Shouldn't be hard to debug)
2023-09-03 23:36:51 -04:00
Ed_
f2d4ec96f0 Dumb fix for name check on parameters
Its now spitting out actual validation failures.
2023-09-03 20:34:27 -04:00
Ed_
1076818250 Got whitepace stripping properly working (AFAICT) for parse_define()
Made debug for viewing whitespace in AST::is_equal with String::visualize_whitespace()

Format stripping code is currently confined within parse_define()

I plan to move it to its own function soon, I just want to make sure its finalized first.

Other unvalidated content will need to have an extra check for preprocessed lines.
Example: Function bodies can have a #define <identifier> <definition>. I cannot strip the last <new line> as it will break the semantic importance to distinguish that line.
So it needs to be:
<content before> <new line>
<preprocessed line> <new line>
<content after>

In the content string that is minimally preserved
2023-09-03 20:29:49 -04:00
Ed_
c4c308c8ba Fixes for auxilary code + typo fix in ast.cpp
Needed the intellisense directive ifdef wrap.
2023-08-29 00:03:08 -04:00
Ed_
a4d9a63d71 Updated single-header based on last cs and also docs 2023-08-28 23:52:44 -04:00
Ed_
0197afd543 Changed how editor intellisense directives are handled for compoenents and dependencies
Didn't like the way I was processing them in scan_file.
2023-08-28 23:46:50 -04:00
Ed_
7249a7317d Added space stripping during for content of various ASTs
* Typedef/Typename
* Function Names
* Pragmas
* Attributes
2023-08-26 11:55:05 -04:00
Ed_
abf51e4aa9 Adjustment to AST::is_equal based on issues found with last CS.
Defined check_member_content, will spit out the strings if they aren't equivalent so the user can verify for themselves if its correct.
2023-08-25 18:57:53 -04:00
Ed_
9b6dc3cbd8 Work on AST::is_equal.
The NumEntries checks need to be deferred until the end as a final unresolved check on valdiation. As if there really is a discrepancy of entires it should be revealed by the specific entry failing.

Right now the latest failure with the single header check involves a define directive specifically the define does omit whitespace properly and so the check interprets the different cached content to be non-equivalent.

This will happen with all unvalidated aspects of the AST ( expressions, function bodies, etc )

There are two ways to resolve, either make an AST that can tokenize all items (not realistic), or I need to strip non-syntax important whitespace and then cache the string. This would mean removing everything but a single whitespace for all content within a content string. Otherwise, I would have to somehow make sure the content of the string has the exact formatting between both files for the definitions that matter.

AST types with this issue:
* Define Directive
* Pragma Directive
* Comment
* Execution
* Platform Attributes
* Untyped

Comments can technically be left unverified as they do not matter semantically.
When the serialization is first emitted, the content these strings should for the most part be equivalent. However I do see some possible failures for that if a different style of bracket placment is used (between the serialization).

At that point what I could do is just leave those unverified and just emit the content to the user as warning that the ast and the other compared could not be verified.

Those technically can be handled on a per-eye basis, and worst case the tests with the compiler will in the determine if any critical defintions are missing for the user.
2023-08-25 18:40:13 -04:00
Ed_
9edcbad907 Fixes to parsing marco content, progress on validation test (single-header) 2023-08-23 21:19:31 -04:00
Ed_
a6766cf0b1 Singleheader validation test got through ast reconstruction, failed to validate the reconstructed AST. 2023-08-23 18:16:45 -04:00
Ed_
8635b0fd1b doc update for parampack typename 2023-08-23 13:18:32 -04:00
Ed_
30eec99628 Changes to include usage, starting to attempt singleheader automated verification 2023-08-23 13:17:22 -04:00
Ed_
f9117a2353 Added zpl's ivrtual memory to dependencies (unused for now) 2023-08-23 11:07:43 -04:00
Ed_
c81f4b34ee Cleanup and doc updates 2023-08-23 02:17:47 -04:00
Ed_
c97762ac16 Added support for inline comments
Also now doing comment serialization on def_comment directly as parse_comment doesn't need it.

Essentially comment ast types serialize the same way s untyped and execution ASTs
2023-08-23 00:25:14 -04:00
Ed_
5e79e8ba65 Started to setup for codebase validation tests.
Fleshed out initial version of AST::is_equal( AST* )

Setup the test directory with initial files for each major validation test.
2023-08-22 16:01:50 -04:00
Ed_
49a2cd7b2c Uncomment formatting comments in build script (forgot to after completing fixes) 2023-08-22 02:17:28 -04:00
Ed_
a6c6574390 More formatting fixes 2023-08-22 02:09:20 -04:00
Ed_
c4846dad26 Formatting fixes 2023-08-22 01:51:59 -04:00
Ed_
a61a28b778 Fixx to bitfield variables
Related to https://github.com/Ed94/gencpp/issues/25
2023-08-22 00:40:38 -04:00
Ed_
d0c995893d Lower inital memory allocation amounts. (Lower latency iteration for running generator)
I need to change it so that they all use one big arena allocation for the initial. This can be done when the global allocator is changed to a growable arena.
2023-08-21 23:49:23 -04:00
Ed_
a42e241afb Got rid of the temp compoonent files, they are now generated via bootstrapping.
This isn't the last step though everything in the main project directory that isn't md files needs to be generated only.
Can't do that till testing is robust enough...
2023-08-21 23:28:39 -04:00
Ed_
6d85dd8fe8 Update vcproj 2023-08-21 23:09:40 -04:00
Ed_
db6e8b33eb got intellisense working for the most part...
VScode works withs some issues.
VS2022 fails.
10xEditor works fine.
JetBrains Rider fails due to it not supporting <push/pop>_macro pragmas
2023-08-21 23:07:03 -04:00
Ed_
7be3617083 Runtime fixed 2023-08-21 22:48:05 -04:00
Ed_
5c47777972 compiles agian... 2023-08-21 21:40:23 -04:00
Ed_
4a2ed6de4e another vs code automated edit... 2023-08-21 21:40:05 -04:00
Ed_
9f64760b7a Commenting out includes to diagnose... 2023-08-21 21:20:29 -04:00
Ed_
68f34e6fab gitignore update for vc140.pdb
will remove after I figure out how its going rogue.
2023-08-21 21:12:52 -04:00
Ed_
1f9bbddbb7 vs setting update 2023-08-21 21:12:25 -04:00
Ed_
050b00f28a WIP - Broken Compile : Added pragma once and includes to all files + Parser fixes, and String improvements
Adding the pragma once and includes the files broke compilation, still diagnosing why.

- Some string functions were moved to the cpp, still need to do some more evaluation of it and the containers...
- Added support for forceinline and neverinline to parsing (untested)
- Added support for specifiers in operator cast such as explicit, inline/forceinline/neverinline, etc.
    - Before it only support const.
    - Still need to support volatile.
- Forceinline was not supported at all for tokenization, fixed that.
2023-08-21 20:30:13 -04:00
Ed_
1241f44fd4 scan_file function can auto skips pragma once and includes
Needed so that includes could be added to components so that intellisense would not fail since the parser (for most editors) doesn't properly parse the enviornment and cheats on a per-file basis.
2023-08-21 20:27:00 -04:00
Ed_
7d1c499e7b Build script improvements
Made sure devshell only loads up the msvc env once.
2023-08-20 22:39:46 -04:00
Ed_
b3f0c2734f Merge remote-tracking branch 'origin/main' into dev 2023-08-20 18:04:51 -04:00
Ed_
eaeb8acee4 Remove Some vcproj changes, removal of the rogue vc140.pdb 2023-08-20 18:04:35 -04:00
Ed_
12bf878cb3 Merge pull request #23 from Ed94/dev
dev pull - Build script updates and misc fixes
2023-08-20 17:55:35 -04:00
Ed_
52ae431ad6 Made clean script remove the gen dir now from test dir. 2023-08-20 15:51:51 -04:00
Ed_
05fa62eced Test building & generation fixed with altest scripts 2023-08-20 15:45:06 -04:00
Ed_
2f7836b191 Fixes to buildscript 2023-08-20 13:18:09 -04:00
Ed_
f574a9ba9a Further improvements to build script
test is failing to complete properly, need to debug...
2023-08-20 13:02:50 -04:00
Ed_
a6bf60a51e Simpilication of build script, added initial support for tests 2023-08-20 12:31:28 -04:00
Ed_
37d9782cf2 Singleheader now compiles with new build script on both clang & msvc 2023-08-20 10:17:55 -04:00
Ed_
11679ba8b4 New build script works for clang and msvc!
Need to update singleheader and test to use it.
2023-08-19 21:33:01 -04:00
Ed_
8985f0a4d9 MSVC in latest script works
Clang is having issues.
2023-08-19 17:08:13 -04:00
Ed_
32a910515e More refactoring, getting rid of meson in favor of just powershell scripts 2023-08-19 12:18:48 -04:00
Ed_
aa928ff446 Scripting updates, some refactors..
Made a package release script.

Did refactors based on some design considerations
Still need to make some major decisions...
2023-08-09 18:47:59 -04:00
Ed_
5aff89262b Fixes (Doc typos, pragma once worng type, non-debug fatal compile fail) 2023-08-09 09:50:12 -04:00
Ed_
b5fa864318 Fixes and improvements to serialization.
There were multiple issues with comment and newline lexing.

Extended printing functions to support Strings with %S flag (captial 'S').
Allows for length detection. Also made it so that precision for strings is the string length.
2023-08-08 22:14:58 -04:00
Ed_
bb35444be9 Fix for log_failure macro expansion in helper.hpp: CodeBody gen_ast_inlines() 2023-08-08 15:53:10 -04:00
Ed_
67d02c1f62 Fix for wrong tokens for GNU/MSVC attribute captures (parse_attributes)
Also a fix for a typo in the readme...
2023-08-08 15:35:06 -04:00
Ed_
c7647ab00f Updated docs 2023-08-08 11:56:42 -04:00
Ed_
d2fc1d0a56 Converted log_failure and fatal to macros (fixes GEN_PANIC not determining correct line or file) 2023-08-08 09:48:50 -04:00
Ed_
ed3246c6b0 Fixes for typedef serialization of functions..
Also fix for HashTable<>::rehash_fast not having finished implemenation...

The typedef fix is a sort of hack (like how parsing the rest of the language feels like tbh...).
I might make a def_typedef_fn to make it clearer how to define function typedefs using the upfront interface.
2023-08-07 20:16:04 -04:00
Ed_
c4d5637a64 Fixes to single header generation (bad parsing adt/csv injection in wrong place) 2023-08-07 14:52:26 -04:00
Ed_
c2f8c8aeb1 Added constructor and destructor supported (UNTESTED)
Just compiles and generates...

Also fixed a bug where parsing didn't have a token for virtual specifiers...
2023-08-07 03:10:45 -04:00
Ed_
c2319b9651 Fixes for test.singleheader_ast.cpp, also added a bench for it.
On a Ryzen R9 5950 it takes 11 ms to generate AST and 21 ms to serialize to file.
2023-08-06 17:46:17 -04:00
Ed_
a4f9596d3b Fixes to serialization, reduced Define_CodeType macro
Now the execution code is generated in bootstrap/singleheader gen.
2023-08-06 17:19:57 -04:00
Ed_
97750388ad No longer using components/temp/ast_inlines (switched to helper function to avoid macro usage)
Increased the arg count support of num_args to 100.
2023-08-06 14:58:43 -04:00
Ed_
00f6c45f15 Fixes for serializations found with last commit's test.
Should be fine to move on to next major feature....
2023-08-06 13:28:19 -04:00
Ed_
34f286d218 Library can now construct into AST and serialization itself (singleheader).
Still need to validate if they match.
2023-08-04 16:12:13 -04:00
Ed_
d36c3fa847 Single header generates again, some more cleanup.
Looking into properly dealing with empty lines...

I want to preserve the text's empty lines in the AST for serialization purposes (perserve formatting for gapes between definitions).
Don't want to introduce the possibility of it breaking though, so will have to ignore empty_lines in a general way (if they are in a bad spot).
Attempted to cover that by having TokArray::current() auto-skip empty lines and eat as well if the type doesn't match.
2023-08-03 23:18:33 -04:00
Ed_
5d7dfaf666 Heavy refactor..
Isolating large macros to their own directory (components/temp).
- Plan is to remove them soon with proper generation.

Added additional component files, separating the old data_structures header for a set of ast headers.
Header_end also had its inlines extracted out.
Necessary to complete the macro isolation.

ZPL parser dependencies were removed from the core library along with builder, its now generated in bootstrap as pare of making a gen_builder set of files.

Singleheader will be changed in next few commits to reflect this as well (By making builder deps and components a conditional option).

Tests are most likely all broken for now.
2023-08-03 11:01:43 -04:00
Ed_
114f678f1b Merge pull request #9 from Ed94/Preprocessor_support
Preprocessor support
2023-08-02 16:04:57 -04:00
Ed_
a8a9b681f0 test completes singleheader ast construction and serailizes with corruption 2023-08-02 14:01:56 -04:00
Ed_
b96b0821c1 Fixes towards parsing (getting to line 12575 now of the singleheader. 2023-08-02 12:39:35 -04:00
Ed_
4c8a0f0005 Iterations on serialization improvements. 2023-08-01 20:56:00 -04:00
Ed_
684569750d first serialization of singlehearder without asserts. (Still failing after around 4k lines. 2023-08-01 16:07:47 -04:00
Ed_
0f16d1131e Got past parsing, fixing serialization 2023-08-01 14:02:54 -04:00
Ed_
528ef72a51 More progress on parsing
Made it to line 2597 of self parsing its singleheader

Complex global or member defintions are now supported.
2023-08-01 05:17:24 -04:00
Ed_
21a8f3bb39 WIP: It can parse to around ~2k lines. Need to improve its ability to detect when a forward declare of a class/enum/struct/union..
This language truly is a mess.
2023-08-01 00:42:08 -04:00
Ed_
2b63fc27cd Progress toward preprocessor parsing, lexing works, parsing does not. 2023-07-30 18:55:57 -04:00
Ed_
bfbfae466f Naive preprocessor support initial implementation (compiles and runs, not heavily tested) 2023-07-30 01:21:04 -04:00
Ed_
3d7cb85e71 Merge pull request #8 from Ed94/parser_context_stack
Parser context stack
2023-07-29 17:16:04 -04:00
Ed_
03df940085 Improved parser scope errors.
Added the caret for indicating where the error is.
2023-07-29 17:14:02 -04:00
Ed_
b9064fba9d renamed parsed and upfront dirs to lowercase 2023-07-29 16:27:36 -04:00
Ed_
4e8d6456cb Merge branch 'parser_context_stack' of https://github.com/Ed94/gencpp into parser_context_stack 2023-07-29 16:25:50 -04:00
Ed_
d704f11c81 renamed Docs to lowercase 2023-07-29 16:25:38 -04:00
Ed_
50a10c901f renamed Docs to lowercase 2023-07-29 16:24:07 -04:00
Ed_
0a5885495f got old tests working (test.parsing.cpp and test.upfront.cpp) 2023-07-29 16:00:06 -04:00
Ed_
f09bb99fdf Fixes for test generation (sanity, soa). 2023-07-29 13:15:53 -04:00
Ed_
108b16739f bootstrap and singleheader compile and generate. 2023-07-29 12:25:38 -04:00
Ed_
689646c393 Finished iniital refactor pass. Comples, but has runtime issues. 2023-07-29 06:32:16 -04:00
Ed_
c5afede7b5 Reorganization of files, refactors, doc updates (WIP)
Removing the gen. namespace from the files for components, dependencies, and file_processors.
They are only necessary if the include directory is transparent, and in my case those are not.

Made a docs directory. I'm offloading information from the main readme to there along with additional informationn I end up elaborating on down the line.
Enum tables were moved to their own directory (project/enums).

Library will not compile for now. Major refactor occuring with parsing related components.
2023-07-29 05:52:06 -04:00
Ed_
31e1c38c18 Started to implement context stack for parser. 2023-07-28 21:44:31 -04:00
Ed_
3f0b7e7fc6 Update to scripts, readme
Offloaded todo to the issues on github.
2023-07-28 03:15:50 -04:00
177 changed files with 26415 additions and 10627 deletions

40
.gitignore vendored
View File

@ -1,29 +1,33 @@
.idea
build/*
**/build/*
.vs
**/*.gen.*
**/gen/gen.hpp
**/gen/gen.cpp
**/gen/gen_dep.hpp
**/gen/gen_dep.cpp
**/gen/gen.dep.hpp
**/gen/gen.dep.cpp
**/gen/gen.builder.hpp
**/gen/gen.builder.cpp
**/gen/gen.scanner.hpp
**/gen/gen.scanner.cpp
gencpp.hpp
gencpp.cpp
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
**/*.lib
**/*.pdb
**/*.exe
**/*.dll
release/**
# Unreal
**/Unreal/*.h
**/Unreal/*.cpp
! **/Unreal/validate.unreal.cpp
project/auxillary/vis_ast/dependencies/temp
test/gen/original
singleheader/gen/scratch.hpp
test/gen/scratch.cpp

14
.vscode/bookmarks.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
"files": [
{
"path": "project/auxillary/vis_ast/dependencies/temp/raylib-master/src/rcamera.h",
"bookmarks": [
{
"line": 140,
"column": 14,
"label": ""
}
]
}
]
}

View File

@ -1,7 +1,7 @@
{
"configurations": [
{
"name": "Win32",
"name": "Win32 msvc",
"includePath": [
"${workspaceFolder}/**"
],
@ -9,11 +9,36 @@
"_DEBUG",
"UNICODE",
"_UNICODE",
"GEN_TIME"
"GEN_TIME",
"GEN_IMPLEMENTATION",
// "GEN_DONT_USE_NAMESPACE"
"GEN_INTELLISENSE_DIRECTIVES",
"INTELLISENSE_DIRECTIVES"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
"intelliSenseMode": "msvc-x64",
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json"
},
{
"name": "Win32 clang",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"GEN_TIME",
"GEN_IMPLEMENTATION",
// "GEN_DONT_USE_NAMESPACE"
"GEN_INTELLISENSE_DIRECTIVES",
"INTELLISENSE_DIRECTIVES"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",
"intelliSenseMode": "windows-clang-x64",
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json"
}
],
"version": 4

37
.vscode/launch.json vendored
View File

@ -8,9 +8,9 @@
"type": "lldb",
"request": "launch",
"name": "Debug gentime lldb",
"program": "${workspaceFolder}/test/gen/build/gencpp.exe",
"program": "${workspaceFolder}/test/test.exe",
"args": [],
"cwd": "${workspaceFolder}/test/gen/",
"cwd": "${workspaceFolder}/test/",
"postRunCommands": [
]
},
@ -18,16 +18,16 @@
"type": "cppvsdbg",
"request": "launch",
"name": "Debug gentime vsdbg",
"program": "${workspaceFolder}/test/gen/build/gencpp.exe",
"program": "${workspaceFolder}/test/build/test.exe",
"args": [],
"cwd": "${workspaceFolder}/test/gen/",
"cwd": "${workspaceFolder}/test/",
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
},
{
"type": "cppvsdbg",
"request": "launch",
"name": "Debug bootstrap vsdbg",
"program": "${workspaceFolder}/project/build/gencpp_bootstrap.exe",
"program": "${workspaceFolder}/project/build/bootstrap.exe",
"args": [],
"cwd": "${workspaceFolder}/project/",
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
@ -40,6 +40,33 @@
"args": [],
"cwd": "${workspaceFolder}/singleheader/",
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
},
{
"type": "cppvsdbg",
"request": "launch",
"name": "Debug unreal vsdbg",
"program": "${workspaceFolder}/unreal_engine/build/unreal.exe",
"args": [],
"cwd": "${workspaceFolder}/unreal_engine/",
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
},
{
"type": "cppvsdbg",
"request": "launch",
"name": "Debug raylib refactor vsdbg",
"program": "${workspaceFolder}/project/auxillary/vis_ast/dependencies/raylib/build/raylib_refactor.exe",
"args": [],
"cwd": "${workspaceFolder}/project/auxillary/vis_ast/dependencies/temp/raylib-master/src/",
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
},
{
"type": "cppvsdbg",
"request": "launch",
"name": "Debug VIS AST",
"program": "${workspaceFolder}/project/auxillary/vis_ast/binaries/vis_ast.exe",
"args": [],
"cwd": "${workspaceFolder}/project/auxillary/vis_ast/binaries/",
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
}
]
}

25
.vscode/settings.json vendored
View File

@ -18,7 +18,26 @@
"algorithm": "cpp",
"limits": "cpp",
"concepts": "cpp",
"*.rh": "cpp"
"*.rh": "cpp",
"chrono": "cpp",
"string": "cpp",
"filesystem": "cpp",
"format": "cpp",
"ratio": "cpp",
"xstring": "cpp",
"functional": "cpp",
"vector": "cpp",
"list": "cpp",
"xhash": "cpp",
"glfw3.h": "c",
"stdbool.h": "c",
"objbase.h": "c",
"mmreg.h": "c",
"mmsystem.h": "c",
"propidl.h": "c",
"android_native_app_glue.h": "c",
"raylib.h": "c",
"*.m": "cpp"
},
"C_Cpp.intelliSenseEngineFallback": "disabled",
"mesonbuild.configureOnOpen": true,
@ -30,5 +49,7 @@
"**/.vscode": true,
"**/.vs": true,
"**/sanity.gen.hpp": true
}
},
"autoHide.autoHidePanel": false,
"autoHide.autoHideSideBar": false
}

663
Readme.md
View File

@ -5,64 +5,25 @@ An attempt at simple staged metaprogramming for c/c++.
The library API is a composition of code element constructors.
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 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),
its not meant to be a black box metaprogramming utility, its meant for the user to extend for their project domain.
### TOC
* [Notes](#notes)
* [Usage](#usage)
* [Building](#notes)
* [Outline](#outline)
* [What is not provided](#what-is-not-provided)
* [The three constructors ](#there-are-three-sets-of-interfaces-for-code-ast-generation-the-library-provides)
* [Predefined Codes](#predefined-codes)
* [Code generation and modification](#code-generation-and-modification)
* [On multithreading](#on-multi-threading)
* [Extending the library](#extending-the-library)
* [TODO](#todo)
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto).
Its not meant to be a black box metaprogramming utility, it should be easy to intergrate into a user's project domain.
## Notes
The project has reached an *alpha* state, all the current functionality works for the test cases but it will most likely break in many other cases.
**On Partial Hiatus: Life has got me tackling other issues..**
I will be passively updating the library with bug fixes and minor improvements as I use it for my personal projects.
There won't be any major reworks or features to this thing for a while.
The project has no external dependencies beyond:
This project is still in development (very much an alpha state), so expect bugs and missing features.
See [issues](https://github.com/Ed94/gencpp/issues) for a list of known bugs or todos.
* `errno.h` (gen.dep.cpp)
* `stat.h` (gen.dep.cpp)
* `stdarg.h` (gen.dep.hpp)
* `stddef.h` (gen.dep.hpp
* `stdio.h` (gen.dep.cpp)
* `copyfile.h` (Mac, gen.dep.cpp)
* `types.h` (Linux, gen.dep.cpp)
* `unistd.h` (Linux/Mac, gen.dep.cpp)
* `intrin.h` (Windows, gen.dep.hpp)
* `io.h` (Windows with gcc, gen.dep.cpp)
* `windows.h` (Windows, gen.dep.cpp)
The library can already be used to generate code just fine, but the parser is where the most work is needed. If your C++ isn't "down to earth" expect issues.
Dependencies for the project are wrapped within `GENCPP_ROLL_OWN_DEPENDENCIES` (Defining it will disable them).
The majority of the dependency's implementation was derived from the [c-zpl library](https://github.com/zpl-c/zpl).
This library was written a subset of C++ where the following are not used at all:
* RAII (Constructors/Destructors), lifetimes are managed using named static or regular functions.
* Language provide dynamic dispatch, RTTI
* Object-Oriented Inheritance
* Exceptions
Polymorphic & Member-functions are used as an ergonomic choice, along with a conserative use of operator overloads.
There are only 4 template definitions in the entire library. (`Array<Type>`, `Hashtable<Type>`, `swap<Type>`, and `AST/Code::cast<Type>`)
A `natvis` and `natstepfilter` are provided in the scripts directory.
A `natvis` and `natstepfilter` are provided in the scripts directory (its outdated, I'll update this readme when its not).
***The editor and scanner have not been implemented yet. The scanner will come first, then the editor.***
A C variant is hosted [here](https://github.com/Ed94/genc); I haven't gotten headwind on it, should be easier to make than this...
A C variant is hosted [here](https://github.com/Ed94/genc); I will complete it when this library is feature complete, it should be easier to make than this...
## Usage
@ -70,7 +31,7 @@ A metaprogram is built to generate files before the main program is built. We'll
`gen.cpp` \`s `main()` is defined as `gen_main()` which the user will have to define once for their program. There they will dictate everything that should be generated.
In order to keep the locality of this code within the same files the following pattern may be used:
In order to keep the locality of this code within the same files the following pattern may be used (although this pattern isn't required at all):
Within `program.cpp` :
@ -86,6 +47,8 @@ u32 gen_main()
}
#endif
// "Stage" agnostic code.
#ifndef GEN_TIME
#include "program.gen.cpp"
@ -95,15 +58,16 @@ u32 gen_main()
```
The design uses a constructive builder API for the code to generate.
The user is given `Code` objects that are used to build up the AST.
The user is provided `Code` objects that are used to build up the AST.
Example using each construction interface:
### Upfront
Validation and construction through a functional interface.
```cpp
Code t_uw = def_type( name(uw) );
Code t_uw = def_type( name(usize) );
Code t_allocator = def_type( name(allocator) );
Code t_string_const = def_type( name(char), def_specifiers( args( ESpecifier::Const, ESpecifier::Ptr ) ));
@ -120,12 +84,14 @@ Code header;
### Parse
Validation through ast construction.
```cpp
Code header = parse_struct( code(
struct ArrayHeader
{
uw Num;
uw Capacity;
usize Num;
usize Capacity;
allocator Allocator;
};
));
@ -134,12 +100,14 @@ Code header = parse_struct( code(
### Untyped
No validation, just glorified text injection.
```cpp
Code header = code_str(
struct ArrayHeader
{
uw Num;
uw Capacity;
usize Num;
usize Capacity;
allocator Allocator;
};
);
@ -155,590 +123,15 @@ All three constrcuton interfaces will generate the following C code:
```cpp
struct ArrayHeader
{
uw Num;
uw Capacity;
usize Num;
usize Capacity;
allocator Allocator;
};
```
**Note: The formatting shown here is not how it will look. For your desired formatting its recommended to run a pass through the files with an auto-formatter.**
*(The library currently uses clang-format for formatting, beware its pretty slow...)*
## Building
An example of building is provided within project, singleheader, and test.
(All generated files go to a corresponding `*/gen` directory)
**Project**
`gen.bootstrap.cpp` generates a segmented version of the library where code is divided into `gen.hpp`, `gen.cpp`, `gen_dep.hpp`, and `gen_dep.cpp`.
(Similar whats there already, but with the includes injected)
**Singleheader**
`gen.singleheader.cpp` generates 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.
Both of them build the same source file: `test.cpp`. The only differences are that gen needs a different relative path to the include directories and defines the macro definition: `GEN_TIME`.
This method is setup where all the metaprogram's code are the within the same files as the regular program's code.
## Outline
### *WHAT IS NOT PROVIDED*
* Exceptions
* Execution statement validation : Execution expressions are defined using the untyped API.
* Lambdas (This naturally means its unsupported)
* RAII : This needs support for constructors/destructor parsing
* Haven't gotten around to yet, only useful (to me) for third-party scanning
Keywords kept from "Modern C++":
* constexpr : Great to store compile-time constants.
* consteval : Technically fine, need to make sure to execute in moderation.
* constinit : Better than constexpr at doing its job, however, its only c++ 20.
* export : Useful if c++ modules ever come around to actually being usable.
* import : ^^
* module : ^^
When it comes to expressions:
**There is no support for validating expressions.**
Its difficult to parse without enough benefits (At the metaprogramming level).
When it comes to templates:
Only trivial template support is provided. the intention is for only simple, non-recursive substitution.
The parameters of the template are treated like regular parameter AST entries.
This means that the typename entry for the parameter AST would be either:
* `class`
* `typename`
* A fundamental type, function, or pointer type.
Anything beyond this usage is not supported by parse_template for arguments (at least not intentionally).
Use at your own mental peril.
*Concepts and Constraints are not supported, its usage is non-trivial substitution.*
### The Data & Interface
As mentioned in [Usage](#usage), the user is provided Code objects by calling the constructor's functions to generate them or find existing matches.
The AST is managed by the library and provided the user via its interface.
However, the user may specifiy memory configuration.
Data layout of AST struct:
```cpp
union {
struct
{
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
AST* Specs; // Function, Operator, Type symbol, Variable
union {
AST* ParentType; // Class, Struct
AST* ReturnType; // Function, Operator
AST* UnderlyingType; // Enum, Typedef
AST* ValueType; // Parameter, Variable
};
AST* Params; // Function, Operator, Template
union {
AST* ArrExpr; // Type Symbol
AST* Body; // Class, Enum, Function, Namespace, Struct, Union
AST* Declaration; // Friend, Template
AST* Value; // Parameter, Variable
};
};
StringCached Content; // Attributes, Comment, Execution, Include
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
};
union {
AST* Prev;
AST* Front; // Used by CodeBody
AST* Last; // Used by CodeParam
};
union {
AST* Next;
AST* Back; // Used by CodeBody
};
AST* Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
union {
OperatorT Op;
AccessSpec ParentAccess;
s32 NumEntries;
};
```
*`CodeT` is a typedef for `ECode::Type` which has an underlying type of `u32`*
*`OperatorT` is a typedef for `EOperator::Type` which has an underlying type of `u32`*
*`StringCahced` is a typedef for `String const`, to denote it is an interned string*
*`String` is the dynamically allocated string type for the library*
AST widths are setup to be AST_POD_Size.
The width dictates how much the static array can hold before it must give way to using an allocated array:
```cpp
constexpr static
uw ArrSpecs_Cap =
(
AST_POD_Size
- sizeof(AST*) * 3
- sizeof(StringCached)
- sizeof(CodeT)
- sizeof(ModuleFlag)
- sizeof(s32)
)
/ sizeof(SpecifierT) -1; // -1 for 4 extra bytes (Odd num of AST*)
```
*Ex: If the AST_POD_Size is 128 the capacity of the static array is 20.*
Data Notes:
* The allocator definitions used are exposed to the user incase they want to dictate memory usage
* You'll find the memory handling in `init`, `gen_string_allocator`, `get_cached_string`, `make_code`.
* ASTs are wrapped for the user in a Code struct which is a wrapper for a AST* type.
* Both AST and Code have member symbols but their data layout is enforced to be POD types.
* This library treats memory failures as fatal.
* Cached Strings are stored in their own set of arenas. AST constructors use cached strings for names, and content.
* `StringArenas`, `StringCache`, `Allocator_StringArena`, and `Allocator_StringTable` are the associated containers or allocators.
* Strings used for serialization and file buffers are not contained by those used for cached strings.
* They are currently using `GlobalAllocator`, which are tracked array of arenas that grows as needed (adds buckets when one runs out).
* Memory within the buckets is not reused, so its inherently wasteful.
* I will be augmenting the single arena with a simple slag allocator.
* Linked lists used children nodes on bodies, and parameters.
* Its intended to generate the AST in one go and serialize after. The constructors and serializer are designed to be a "one pass, front to back" setup.
* Allocations can be tuned by defining the folloiwng macros:
* `GEN_GLOBAL_BUCKET_SIZE` : Size of each bucket area for the global allocator
* `GEN_CODEPOOL_NUM_BLOCKS` : Number of blocks per code pool in the code allocator
* `GEN_SIZE_PER_STRING_ARENA` : Size per arena used with string caching.
* `GEN_MAX_COMMENT_LINE_LENGTH` : Longest length a comment can have per line.
* `GEN_MAX_NAME_LENGTH` : Max length of any identifier.
* `GEN_MAX_UNTYPED_STR_LENGTH` : Max content length for any untyped code.
* `GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE` : token_fmt_va uses local_persit memory of this size for the hashtable.
* `GEN_LEX_ALLOCATOR_SIZE`
* `GEN_BUILDER_STR_BUFFER_RESERVE`
Two generic templated containers are used throughout the library:
* `template< class Type> struct Array`
* `template< class Type> struct HashTable`
Both Code and AST definitions have a `template< class Type> Code/AST cast()`. Its just an alternative way to explicitly cast to each other.
`template< class Type> swap( Type& a, Type& b)` is used over a macro.
Otherwise the library is free of any templates.
The following CodeTypes are used which the user may optionally use strong typing with if they enable: `GEN_ENFORCE_STRONG_CODE_TYPES`
* CodeBody : Has support for `for-range` iterating across Code objects.
* CodeAttributes
* CodeComment
* CodeClass
* CodeEnum
* CodeExec
* CodeExtern
* CodeInclude
* CodeFriend
* CodeFn
* CodeModule
* CodeNamespace
* CodeOperator
* CodeOpCast
* CodeParam : Has support for `for-range` iterating across parameters.
* CodeSpecifiers : Has support for `for-range` iterating across specifiers.
* CodeStruct
* CodeTemplate
* CodeType
* CodeTypedef
* CodeUnion
* CodeUsing
* CodeUsingNamespace
* CodeVar
Each Code boy has an associated "filtered AST" with the naming convention: `AST_<CodeName>`
Unrelated fields of the AST for that node type are omitted and only necessary padding members are defined otherwise.
Retrieving a raw version of the ast can be done using the `raw()` function defined in each AST.
## There are three sets of interfaces for Code AST generation the library provides
* Upfront
* Parsing
* Untyped
### Upfront Construction
All component ASTs must be previously constructed, and provided on creation of the code AST.
The construction will fail and return Code::Invalid otherwise.
Interface :``
* def_attributes
* *This is pre-appended right before the function symbol, or placed after the class or struct keyword for any flavor of attributes used.*
* *Its up to the user to use the desired attribute formatting: `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU).*
* def_comment
* def_class
* def_enum
* def_execution
* *This is equivalent to untyped_str, except that its intended for use only in execution scopes.*
* def_extern_link
* def_friend
* def_function
* def_include
* def_module
* def_namespace
* def_operator
* def_operator_cast
* def_param
* def_params
* def_specifier
* def_specifiers
* def_struct
* def_template
* def_type
* def_typedef
* def_union
* def_using
* def_using_namespace
* def_variable
Bodies:
* def_body
* def_class_body
* def_enum_body
* def_export_body
* def_extern_link_body
* def_function_body
* *Use this for operator bodies as well*
* def_global_body
* def_namespace_body
* def_struct_body
* def_union_body
Usage:
```cpp
<name> = def_<function type>( ... );
Code <name>
{
...
<name> = def_<function name>( ... );
}
```
When using the body functions, its recommended to use the args macro to auto determine the number of arguments for the varadic:
```cpp
def_global_body( args( ht_entry, array_ht_entry, hashtable ));
// instead of:
def_global_body( 3, ht_entry, array_ht_entry, hashtable );
```
If a more incremental approach is desired for the body ASTs, `Code def_body( CodeT type )` can be used to create an empty body.
When the members have been populated use: `AST::validate_body` to verify that the members are valid entires for that type.
### Parse construction
A string provided to the API is parsed for the intended language construct.
Interface :
* parse_class
* parse_enum
* parse_export_body
* parse_extern_link
* parse_friend
* Purposefully are only support forward declares with this constructor.
* parse_function
* parse_global_body
* parse_namespace
* parse_operator
* parse_operator_cast
* parse_struct
* parse_template
* parse_type
* parse_typedef
* parse_union
* parse_using
* parse_variable
The lexing and parsing takes shortcuts from whats expected in the standard.
* Numeric literals are not check for validity.
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
* *This includes the assignment of variables.*
* Attributes ( `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU) )
* Assumed to *come before specifiers* (`const`, `constexpr`, `extern`, `static`, etc) for a function
* Or in the usual spot for class, structs, (*right after the declaration keyword*)
* typedefs have attributes with the type (`parse_type`)
* As a general rule; if its not available from the upfront constructors, its not available in the parsing constructors.
* *Upfront constructors are not necessarily used in the parsing constructors, this is just a good metric to know what can be parsed.*
* Parsing attributes can be extended to support user defined macros by defining `GEN_Define_Attribute_Tokens` (see `gen.hpp` for the formatting)
Usage:
```cpp
Code <name> = parse_<function name>( string with code );
Code <name> = def_<function name>( ..., parse_<function name>(
<string with code>
));
Code <name> = make_<function name>( ... )
{
<name>->add( parse_<function name>(
<string with code>
));
}
```
### Untyped constructions
Code ASTs are constructed using unvalidated strings.
Interface :
* token_fmt_va
* token_fmt
* untyped_str
* untyped_fmt
* untyped_token_fmt
During serialization any untyped Code AST has its string value directly injected inline of whatever context the content existed as an entry within.
Even though these are not validated from somewhat correct c/c++ syntax or components, it doesn't mean that Untyped code can be added as any component of a Code AST:
* Untyped code cannot have children, thus there cannot be recursive injection this way.
* Untyped code can only be a child of a parent of body AST, or for values of an assignment (ex: variable assignment).
These restrictions help prevent abuse of untyped code to some extent.
Usage Conventions:
```cpp
Code <name> = def_variable( <type>, <name>, untyped_<function name>(
<string with code>
));
Code <name> = untyped_str( code(
<some code without "" quotes>
));
```
Optionally, `code_str`, and `code_fmt` macros can be used so that the code macro doesn't have to be used:
```cpp
Code <name> = code_str( <some code without "" quotes > )
```
Template metaprogramming in the traditional sense becomes possible with the use of `token_fmt` and parse constructors:
```cpp
StrC value = txt_StrC("Something");
char const* template_str = txt(
Code with <key> to replace with token_values
...
);
char const* gen_code_str = token_fmt( "key", value, template_str );
Code <name> = parse_<function name>( gen_code_str );
```
## Predefined Codes
The following are provided predefined by the library as they are commonly used:
* `access_public`
* `access_protected`
* `access_private`
* `module_global_fragment`
* `module_private_fragment`
* `pragma_once`
* `spec_const`
* `spec_consteval`
* `spec_constexpr`
* `spec_constinit`
* `spec_extern_linkage` (extern)
* `spec_final`
* `spec_global` (global macro)
* `spec_inline`
* `spec_internal_linkage` (internal macro)
* `spec_local_persist` (local_persist macro)
* `spec_mutable`
* `spec_override`
* `spec_ptr`
* `spec_ref`
* `spec_register`
* `spec_rvalue`
* `spec_static_member` (static)
* `spec_thread_local`
* `spec_virtual`
* `spec_volatile`
* `spec_type_signed`
* `spec_type_unsigned`
* `spec_type_short`
* `spec_type_long`
* `t_auto`
* `t_void`
* `t_int`
* `t_bool`
* `t_char`
* `t_wchar_t`
* `t_class`
* `t_typename`
Optionally the following may be defined if `GEN_DEFINE_LIBRARY_CODE_CONSTANTS` is defined
* `t_b32`
* `t_s8`
* `t_s16`
* `t_s32`
* `t_s64`
* `t_u8`
* `t_u16`
* `t_u32`
* `t_u64`
* `t_sw`
* `t_uw`
* `t_f32`
* `t_f64`
## Extent of operator overload validation
The AST and constructors will be able to validate that the arguments provided for the operator type match the expected form:
* If return type must match a parameter
* If number of parameters is correct
* If added as a member symbol to a class or struct, that operator matches the requirements for the class (types match up)
The user is responsible for making sure the code types provided are correct
and have the desired specifiers assigned to them beforehand.
## Code generation and modification
There are three provided file interfaces:
* Builder
* Editor
* Scanner
Editor and Scanner are disabled by default, use `GEN_FEATURE_EDITOR` and `GEN_FEATURE_SCANNER` to enable them.
### Builder is a similar object to the jai language's string_builder
* The purpose of it is to generate a file.
* A file is specified and opened for writing using the open( file_path) ) function.
* The code is provided via print( code ) function will be serialized to its buffer.
* When all serialization is finished, use the write() command to write the buffer to the file.
### Editor is for editing a series of files based on a set of requests provided to it
**Note: Not implemented yet**
* The purpose is to overrite a specific file, it places its contents in a buffer to scan.
* Requests are populated using the following interface:
* add : Add code.
* remove : Remove code.
* replace: Replace code.
All three have the same parameters with exception to remove which only has SymbolInfo and Policy:
* SymbolInfo:
* File : The file the symbol resides in. Leave null to indicate to search all files. Leave null to indicated all-file search.
* Marker : #define symbol that indicates a location or following signature is valid to manipulate. Leave null to indicate the signature should only be used.
* Signature : Use a Code symbol to find a valid location to manipulate, can be further filtered with the marker. Leave null to indicate the marker should only be used.
* Policy : Additional policy info for completing the request (empty for now)
* Code : Code to inject if adding, or replace existing code with.
Additionally if `GEN_FEATURE_EDITOR_REFACTOR` is defined, refactor( file_path, specification_path ) wil be made available.
Refactor is based of the refactor library and uses its interface.
It will on call add a request to the queue to run the refactor script on the file.
### Scanner allows the user to generate Code ASTs by reading files
**Note: Not implemented yet**
* The purpose is to grab definitions to generate metadata or generate new code from these definitions.
* Requests are populated using the add( SymbolInfo, Policy ) function. The symbol info is the same as the one used for the editor. So is the case with Policy.
The file will only be read from, no writing supported.
One great use case is for example: generating the single-header library for gencpp!
### Additional Info (Editor and Scanner)
When all requests have been populated, call process_requests().
It will provide an output of receipt data of the results when it completes.
Files may be added to the Editor and Scanner additionally with add_files( num, files ).
This is intended for when you have requests that are for multiple files.
Request queue in both Editor and Scanner are cleared once process_requests completes.
## On multi-threading
Currently unsupported. The following changes would have to be made:
* Setup static data access with fences if more than one thread will generate ASTs ( or keep a different set for each thread)
* Make sure local persistent data of functions are also thread local.
* The builder should be done on a per-thread basis.
* Due to the design of the editor and scanner, it will most likely be best to make each file a job to process request entries on. Receipts should have an an array to store per thread. They can be combined to the final receipts array when all files have been processed.
## Extending the library
This library is relatively very small, and can be extended without much hassle.
The convention you'll see used throughout the API of the library is as follows:
1. Check name or parameters to make sure they are valid for the construction requested
2. Create a code object using `make_code`.
3. Populate immediate fields (Name, Type, ModuleFlags, etc)
4. Populate sub-entires using `add_entry`. If using the default serialization function `to_string`, follow the order at which entires are expected to appear (there is a strong ordering expected).
Names or Content fields are interned strings and thus showed be cached using `get_cached_string` if its desired to preserve that behavior.
`def_operator` is the most sophisticated constructor as it has multiple permutations of definitions that could be created that are not trivial to determine if valid.
The library has its code segmented into component files, use it to help create a derived version without needing to have to rewrite a generated file directly or build on top of the header via composition or inheritance.
When the scanner is implemented, this will be even easier to customize.
# TODO
* Implement a context stack for the parsing, allows for accurate scope validation for the AST types. (Better errors)
* Right now the parsing errors require a debugger in most cases.
* Make a more robust test suite.
* Generate a single-header library
* Componetize the library, make a metaprogram using gencpp to bootstrap itself.
* Implement the Scanner
* Implement the Editor
* Should the builder be an "extension" header?
* Technically the library doesn't require it and the user can use their own filesystem library.
* It would allow me to remove the filesystem dependencies and related functions outside of gen base headers. ( At least 1k loc reduced )
* ADT and the CSV parser depend on it as well. The `str_fmt_file` related functions do as well but they can be ommited.
* Scanner and editor will also depend on it so they would need to include w/e the depency header for all three file-interacting interfaces.
* `gen.files_handling.hpp`
* Convert GlobalAllocator to a slab allocator:
```md
Slab classes (for 100 mb arena)
1KB slab: 5MB ( 5MB / 1KB ~ 5,000 blocks )
4KB slab: 10MB ( 10MB / 4KB ~ 2,500 blocks )
16KB slab: 15MB ( 15MB / 16KB ~ 960 blocks )
64KB slab: 15MB ( 15MB / 64KB ~ 240 blocks )
256KB slab: 20MB ( 20MB / 256KB ~ 80 blocks )
512KB slab: 20MB ( 20MB / 512KB ~ 40 blocks )
1MB slab: 15MB ( 15MB / 1MB ~ 15 blocks )
```
See the [scripts directory](scripts/).

44
docs/AST_Design.md Normal file
View File

@ -0,0 +1,44 @@
## Current Design
`AST` is the actual managed node object for the library.
Its raw and really not meant to be used directly.
All user interaction must be with its pointer so the type they deal with is `AST*`.
For user-facing code, they should never be giveen a nullptr. Instead, they should be given a designated `Invalid` AST node.
In order to abstract away constant use of `AST*`, I wanted to provide a wrapper for it.
The simpliest being just a type alias.
```cpp
using Code = AST*;
```
This is what the genc library would have to use due to its constraints of a langauge.
The actual content per type of AST is covered within [AST_Types.md](AST_Types.md).
These are pure PODS that just have the lay members relevant to the type of AST node they represent.
Each of them has a Code type alias specific to it.
Again, the simpliest case for these would be a type alias.
```cpp
using struct AST_Typedef CodeTypedef;
```
As of November 21st, 2023, the AST has had a strict layout for how its content is laid out.
This will be abandoned during its redesign that will occur starting with support for statments & expressions for either execution and type declarations.
Having a strict layout is too resctrictive vs allowing each AST type to have maximum control over the layout.
The redesign will occur after the following todos are addressed:
* [Improvements Lexer & Token struct#27](https://github.com/Ed94/gencpp/issues/27)
* [Generalize AST Flags to a single 4-byte flag#42](https://github.com/Ed94/gencpp/issues/42)
* [AST-Code Object Redesign.#38](https://github.com/Ed94/gencpp/issues/38)
* [Code-AST Documentation#40](https://github.com/Ed94/gencpp/issues/40)
* [AST::debug_str() improvements#33](https://github.com/Ed94/gencpp/issues/33)
* [AST::is_equal implemented and works with singleheader-test#31](https://github.com/Ed94/gencpp/issues/31)
* [Parser : Add ability to have a parse failure and continue with errors recorded.#35](https://github.com/Ed94/gencpp/issues/35)
* [Scanner : Add CodeFile#29](https://github.com/Ed94/gencpp/issues/29)
* [Auxiliary : AST visual debugger#36](https://github.com/Ed94/gencpp/issues/36)

737
docs/AST_Types.md Normal file
View File

@ -0,0 +1,737 @@
# AST Types Documentation
While the Readme for docs covers the data layout per AST, this will focus on the AST types avaialble, and their nuances.
## Body
These are containers representing a scope body of a definition that can be of the following `ECode` type:
* Class_Body
* Enum_Body
* Export_Body
* Extern_Linkage_Body
* Function_Body
* Global_Body
* Namespace_Body
* Struct_Body
* Union_Body
Fields:
```cpp
Code Front;
Code Back;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
s32 NumEntries;
```
The `Front` member represents the start of the link list and `Back` the end.
NumEntries is the number of entries in the body.
Parent should have a compatible ECode type for the type of defintion used.
Serialization:
Will output only the entries, the braces are handled by the parent.
```cpp
<Front>...
<Back>
```
## Attributes
Represent standard or vendor specific C/C++ attributes.
Fields:
```cpp
StringCached Content;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
<Content>
```
While the parser supports the `__declspec` and `__attribute__` syntax, the upfront constructor ( def_attributes ) must have the user specify the entire attribute, including the `[[]]`, `__declspec` or `__attribute__` parts.
## Comment
Stores a comment.
Fields:
```cpp
StringCached Content;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
<Content>
```
The parser will perserve comments found if residing with a body or in accepted inline-to-definition locations.
Otherwise they will be skipped by the TokArray::__eat and TokArray::current( skip foramtting enabled ) functions.
The upfront constructor: `def_comment` expects to recieve a comment without the `//` or `/* */` parts. It will add them during construction.
## Class & Struct
Fields:
```cpp
CodeComment InlineCmt; // Only supported by forward declarations
CodeAttributes Attributes;
CodeType ParentType;
CodeBody Body;
CodeType Prev; // Used to store references to interfaces
CodeType Next; // Used to store references to interfaces
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
AccessSpec ParentAccess;
```
Serialization:
```cpp
// Class_Fwd
<ModuleFlags> <class/struct> <Name>; <InlineCmt>
// Class
<ModuleFlags> <class/struct> <Attributes> <Name> : <ParentAccess> <ParentType>, public <ParentType->Next>, ... <InlineCmt>
{
<Body>
};
```
You'll notice that only one parent type is supported only with parent access. This library only supports single inheritance, the rest must be done through interfaces.
## Constructor
Fields:
```cpp
CodeComment InlineCmt; // Only supported by forward declarations
Code InitializerList;
CodeParam Params;
Code Body;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
// Constructor_Fwd
<Specs> <Parent->Name>( <Params> ); <InlineCmt>
// Constructor
<Specs> <Parent->Name>( <Params> ) <InlineCmt>
: <InitializerList>
{
<Body>
}
// Constructor Source Implementation
<Specs> <Parent>::~<Parent->Name>( <Params> ) <Specs>
{
<Body>
}
```
## Define
Represents a preprocessor define
Fields:
```cpp
StringCached Content;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
#define <Name> <Content>
```
## Destructor
Fields:
```cpp
CodeComment InlineCmt;
CodeSpecifiers Specs;
Code Body;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
// Destructor_Fwd
<Specs> ~<Parent->Name>( <Params> ) <Specs>; <InlineCmt>
// Destructor
<Specs> ~<Parent->Name>( <Params> ) <Specs>
{
<Body>
}
// Destructor Source Implementation
<Specs> <Parent>::~<Parent->Name>( <Params> ) <Specs>
{
<Body>
}
```
## Enum
Fields:
```cpp
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeType UnderlyingType;
CodeBody Body;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
Serialization:
```cpp
// Enum_Fwd
<ModuleFlags> enum class <Name> : <UnderlyingType>; <InlineCmt>
// Enum
<ModuleFlags> <enum or enum class> <Name> : <UnderlyingType>
{
<Body>
};
```
## Execution
Just represents an execution body. Equivalent to an untyped body.
Will be obsolute when function body parsing is implemented.
Fields:
```cpp
StringCached Content;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
<Content>
```
## External Linkage
Fields:
```cpp
CodeBody Body;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
extern "<Name>"
{
<Body>
}
```
## Include
Fields:
```cpp
StringCached Content;
Code Prev;
Code Next;
Code Parent;
parser::Token* Tok;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
#include <Content>
```
## Friend
This library (until its necessary become some third-party library to do otherwise) does not support friend declarations with in-statment function definitions.
Fields:
```cpp
CodeComment InlineCmt;
Code Declaration;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
friend <Declaration>; <InlineCmt>
```
## Function
Fields:
```cpp
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeSpecifiers Specs;
CodeType ReturnType;
CodeParam Params;
CodeBody Body;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
Serialization:
```cpp
// Function_Fwd
<ModuleFlags> <Attributes> <Specs> <ReturnType> <Name>( <Params> ) <Specs>; <InlineCmt>
// Function
<ModuleFlags> <Attributes> <Specs> <ReturnType> <Name>( <Params> ) <Specs>
{
<Body>
}
```
## Module
Fields:
```cpp
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
Serialization:
```cpp
<ModuleFlags> module <Name>;
```
## Namespace
Fields:
```cpp
CodeBody Body;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
Serialization:
```cpp
<ModuleFlags> namespace <Name>
{
<Body>
}
```
## Operator Overload
Fields:
```cpp
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeSpecifiers Specs;
CodeType ReturnType;
CodeParam Params;
CodeBody Body;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
OperatorT Op;
```
Serialization:
```cpp
// Operator_Fwd
<ModuleFlags> <Attributes> <Specs> <ReturnType> operator <Op>( <Params> ) <Specs>; <InlineCmt>
// Operator
<ModuleFlags> <Attributes> <Specs> <ReturnType> <Name>operator <Op>( <Params> ) <Specs>
{
<Body>
}
```
## Operator Cast Overload ( User-Defined Type Conversion )
Fields:
```cpp
CodeComment InlineCmt;
CodeSpecifiers Specs;
CodeType ValueType;
CodeBody Body;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
// Operator_Cast_Fwd
<Specs> operator <ValueType>() <Specs>; <InlineCmt>
// Operator_Cast
<Specs> <Name>operator <ValueType>() <Specs>
{
<Body>
}
```
## Parameters (AST_Param)
Fields:
```cpp
CodeType ValueType;
Code Macro;
Code Value;
CodeParam Last;
CodeParam Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
s32 NumEntries;
```
Serialization:
```cpp
<Macro>, <Next> ... <Last>
<Macro> <ValueType> <Name>, <Next>... <Last>
```
## Pragma
Fields:
```cpp
StringCached Content;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
#pragma <Content>
```
## Preprocessor Conditional
Fields:
```cpp
StringCached Content;
Code Prev;
Code Next;
paser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
Serialization:
```cpp
#<based off Type> <Content>
```
## Specifiers
Fields:
```cpp
SpecifierT ArrSpecs[ AST::ArrSpecs_Cap ];
CodeSpecifiers NextSpecs;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
s32 NumEntries;
```
Serialization:
```cpp
<Spec>, ...
```
## Template
Fields:
```cpp
CodeParam Params;
Code Declaration;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
Serialization:
```cpp
<ModuleFlags>
template< <Params> >
<Declaration>
```
## Typename
Typenames represent the type "symbol".
Fields:
```cpp
CodeAttributes Attributes;
CodeSpecifiers Specs;
CodeReturnType ReturnType;
CodeParam Params;
Code ArrExpr;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
b32 IsParamPack;
```
Serialization:
```cpp
<Attributes> <Name> <Specs> <IsParamPack ?: ...>
```
## Typedef
Behave as usual except function or macro typedefs.
Those (macros) don't use the underlying type field as everything was serialized under the Name field.
Fields:
```cpp
CodeComment InlineCmt;
Code UnderlyingType;
Code Prev;
Code Next;
parse::Token* Tok
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
b32 IsFunction;
```
Serialization:
```cpp
// Regular
<ModuleFlags> typedef <UnderlyingType> <Name>; <InlineCmt>
// Functions
<ModuleFlags> typedef <ReturnType> <Name>( <Parameters> ); <InlineCmt>
<ModuleFlags> typedef <ReturnType> ( <Expression that yeilds an Identifier signature> )( <Parameters> ); <InlineCmt>
```
## Union
Fields:
```cpp
CodeAttributes Attributes;
CodeBody Body;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
Serialization:
```cpp
<ModuleFlags> union <Attributes> <Name>
{
<Body>
}
```
## Using
Fields:
```cpp
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeType UnderlyingType;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
Serialization:
```cpp
// Regular
<ModuleFlags> using <Attributes> <Name> = <UnderlyingType>; <InlineCmt>
// Namespace
<ModuleFlags> using namespace <Name>; <InlineCmt>
```
## Variable
[Algo](./Parser_Algo.md:)
Fields:
```cpp
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeSpecifiers Specs;
CodeType ValueType;
Code BitfieldSize;
Code Value;
CodeVar NextVar;
Code Prev;
Code Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
Serialization:
```cpp
// Regular
<ModuleFlags> <Attributes> <Specs> <ValueType> <Name> = <Value>, NextVar ...; <InlineCmt>
// Bitfield
<ModuleFlags> <Attributes> <Specs> <ValueType> <Name> : <BitfieldSize> = <Value>, NextVar ...; <InlineCmt>
```

702
docs/Parser_Algo.md Normal file
View File

@ -0,0 +1,702 @@
# Parser's Algorithim
gencpp uses a hand-written recursive descent parser. Both the lexer and parser currently handle a full C/C++ file in a single pass.
## Notable implementation background
### Lexer
The lex procedure does the lexical pass of content provided as a `StrC` type.
The tokens are stored (for now) in `gen::parser::Tokens`.
Fields:
```cpp
Array<Token> Arr;
s32 Idx;
```
What token types are supported can be found in [ETokType.csv](../project/enums/ETokType.csv) you can also find the token types in [ETokType.h](../project/components/gen/etoktype.cpp) , which is the generated enum from the csv file.
Tokens are defined with the struct `gen::parser::Token`:
Fields:
```cpp
char const* Text;
sptr Length;
TokType Type;
s32 Line;
s32 Column;
u32 Flags;
```
Flags is a bitfield made up of TokFlags (Token Flags):
* `TF_Operator` : Any operator token used in expressions
* `TF_Assign`
* Using statment assignment
* Parameter argument default value assignment
* Variable declaration initialization assignment
* `TF_Preprocess` : Related to a preprocessing directive
* `TF_Preprocess_Cond` : A preprocess conditional
* `TF_Attribute` : An attribute token
* `TF_AccessSpecifier` : An accesor operation token
* `TF_Specifier` : One of the specifier tokens
* `TF_EndDefinition` : Can be interpreted as an end definition for a scope.
* `TF_Formatting` : Considered a part of the formatting
* `TF_Literal` : Anything considered a literal by C++.
I plan to replace IsAssign with a general flags field and properly keep track of all operator types instead of abstracting it away to `ETokType::Operator`.
Traversing the tokens is done with the following interface macros:
| Macro | Description |
| --- | --- |
| `currtok_noskip` | Get the current token without skipping whitespace |
| `currtok` | Get the current token, skip any whitespace tokens |
| `prevtok` | Get the previous token (does not skip whitespace) |
| `nexttok` | Get the next token (does not skip whitespace) |
| `eat( Token Type )` | Check to see if the current token is of the given type, if so, advance Token's index to the next token |
| `left` | Get the number of tokens left in the token array |
| `check_noskip` | Check to see if the current token is of the given type, without skipping whitespace |
| `check` | Check to see if the current token is of the given type, skip any whitespace tokens |
### Parser
The parser has a limited user interface, only specific types of definitions or statements are expected to be provided by the user directly when using to construct an AST dynamically (See SOA for example). It however does attempt to provide capability to parse a full C/C++ from production codebases.
Each public user interface procedure has the following format:
```cpp
<code type> parse_<definition type>( StrC def )
{
check_parse_args( def );
using namespace Parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
// Parse the tokens and return a constructed AST using internal procedures
...
}
```
The most top-level parsing procedure used for C/C++ file parsing is `parse_global_body`:
It uses a helper procedure called `parse_global_nspace`.
Each internal procedure will have the following format:
```cpp
internal
<code type> parse_<definition_type>( <empty or contextual params> )
{
push_scope();
...
<code type> result = (<code type>) make_code();
...
Context.pop();
return result;
}
```
Below is an outline of the general alogirithim used for these internal procedures. The intention is to provide a basic briefing to aid the user in traversing the actual code definitions. These appear in the same order as they are in the `parser.cpp` file
***NOTE: This is still heavily in an alpha state. A large swaph of this can change, make sure these docs are up to date before considering them 1:1 with the repo commit your considering.***
## `parse_array_decl`
1. Check if its an array declaration with no expression.
1. Consume and return empty array declaration
2. Opening square bracket
3. Consume expression
4. Closing square bracket
5. If adjacent opening bracket
1. Repeat array declaration parse until no brackets remain
## `parse_assignment_expression`
1. Eat the assignment operator
2. Make sure there is content or at least an end statement after.
3. Flatten the assignment expression to an untyped Code string.
## `parse_attributes`
1. Check for standard attribute
2. Check for GNU attribute
3. Check for MSVC attribute
4. Check for a token registered as an attribute
a. Check and grab the arguments of a token registered of an attribute if it has any.
5. Repeat for chained attributes. Flatten them to a single attribute AST node.
## `parse_class_struct`
1. Check for export module specifier
2. class or struct keyword
3. `parse_attributes`
4. If identifier : `parse_identifier`
5. Parse inherited parent or interfaces
6. If opening curly brace : `parse_class_struct_body`
7. If not an inplace definition
1. End statement
2. Check for inline comment
## `parse_class_struct_body`
1. Opening curly brace
2. Parse the body (Possible options):
1. Ignore dangling end statements
2. Newline : ast constant
3. Comment : `parse_comment`
4. Access_Public : ast constant
5. Access_Protected : ast constant
6. Access_Private : ast constant
7. Decl_Class : `parse_complicated_definition`
8. Decl_Enum : `parse_complicated_definition`
9. Decl_Friend : `parse_friend`
10. Decl_Operator : `parse_operator_cast`
11. Decl_Struct : `parse_complicated_definition`
12. Decl_Template : `parse_template`
13. Decl_Typedef : `parse_typedef`
14. Decl_Union : `parse_complicated_definition`
15. Decl_Using : `parse_using`
16. Operator == '~'
1. `parse_destructor`
17. Preprocess_Define : `parse_define`
18. Preprocess_Include : `parse_include`
19. Preprocess_Conditional (if, ifdef, ifndef, elif, else, endif) : `parse_preprocess_cond` or else/endif ast constant
20. Preprocess_Macro : `parse_simple_preprocess`
21. Preprocess_Pragma : `parse_pragma`
22. Preprocess_Unsupported : `parse_simple_preprocess`
23. StaticAssert : `parse_static_assert`
24. The following compound into a resolved definition or declaration:
1. Attributes (Standard, GNU, MSVC) : `parse_attributes`
2. Specifiers (consteval, constexpr, constinit, explicit, forceinline, inline, mutable, neverinline, static, volatile, virtual)
3. Possible Destructor : `parse_destructor`
4. Possible User defined operator cast : `parse_operator_cast`
5. Possible Constructor : `parse_constructor`
6. Something that has the following: (identifier, const, unsigned, signed, short, long, bool, char, int, double)
1. Possible Constructor `parse_constructor`
2. Possible Operator, Function, or varaible : `parse_operator_function_or_variable`
25. Something completely unknown (will just make untyped...) : `parse_untyped`
## `parse_comment`
1. Just wrap the token into a cached string ( the lexer did the processing )
## `parse_compilcated_definition`
This is a helper function used by the following functions to help resolve a declaration or definition:
* `parse_class_struct_body`
* `parse_global_nspace`
* `parse_union`
A portion of the code in `parse_typedef` is very similar to this as both have to resolve a similar issue.
1. Look ahead to the termination token (End statement)
2. Check to see if it fits the pattern for a forward declare
3. If the previous token was an identifier ( `token[-1]` ):
1. Look back one more token : `[-2]`
2. If the token has a closing brace its an inplace definition
3. If the `token[-2]` is an identifier & `token[-3]` is the declaration type, its a variable using a namespaced type.
4. If the `token[-2]` is an indirection, then its a variable using a namespaced/forwarded type.
5. If the `token[-2]` is an assign classifier, and the starting tokens were the which type with possible `class` token after, its an enum forward declaration.
6. If any of the above is the case, `parse_operator_function_or_variable`
4. If the `token[2]` is a vendor fundamental type (builtin) then it is an enum forward declaration.
5. If the previous token was a closing curly brace, its a definition : `parse_forward_or_definition`
6. If the previous token was a closing square brace, its an array definition : `parse_operator_function_or_variable`
## `parse_define`
1. Define directive
2. Get identifier
3. Get Content (Optional)
## `parse_forward_or_definition`
* Parse any of the following for either a forward declaration or definition:
1. Decl_Class : `parse_class`
2. Decl_Enum : `parse_enum`
3. Decl_Struct : `parse_struct`
4. Decl_Union : `parse_union`
## `parse_function_after_name`
This is needed as a function defintion is not easily resolvable early on, as such this function handles resolving a function
after its been made ceratin that the type of declaration or definition is indeed for a function signature.
By the point this function is called the following are known : export module flag, attributes, specifiers, return type, & name
1. `parse_parameters`
2. parse postfix specifiers (we do not check if the specifier here is correct or not to be here... yet)
3. If there is a body : `parse_body`
4. Otherwise :
1. Statment end
2. Check for inline comment
## `parse_function_body`
Currently there is no actual parsing of the function body. Any content with the braces is shoved into an execution AST node.
In the future statements and expressions will be parsed.
1. Open curly brace
2. Grab all tokens between the brace and the closing brace, shove them in a execution AST node.
3. Closing curly brace
## `parse_global_nspace`
1. Make sure this is being called for a valid type (namespace, global body, export body, linkage body)
2. If its not a global body, consume the opening curly brace
3. Parse the body (Possible options):
1. Ignore dangling end statements
2. NewLine : ast constant
3. Comment : `parse_comment`
4. Decl_Cass : `parse_complicated_definition`
5. Decl_Enum : `parse_complicated_definition`
6. Decl_Extern_Linkage : `parse_extern_link`
7. Decl_Namespace : `parse_namespace`
8. Decl_Struct : `parse_complicated_definition`
9. Decl_Template : `parse_template`
10. Decl_Typedef : `parse_typedef`
11. Decl_Union : `parse_complicated_definition`
12. Decl_Using : `parse_using`
13. Preprocess_Define : `parse_define`
14. Preprocess_Include : `parse_include`
15. Preprocess_If, IfDef, IfNotDef, Elif : `parse_preprocess_cond`
16. Preprocess_Else : ast constant
17. Preprocess_Endif : ast constant
18. Preprocess_Macro : `parse_simple_preprocess`
19. Preprocess_Pragma : `parse_pragma`
20. Preprocess_Unsupported : `parse_simple_preprocess`
21. StaticAssert : `parse_static_assert`
22. Module_Export : `parse_export_body`
23. Module_Import : NOT_IMPLEMENTED
24. The following compound into a resolved definition or declaration:
1. Attributes ( Standard, GNU, MSVC, Macro ) : `parse_attributes`
2. Specifiers ( consteval, constexpr, constinit, extern, forceinline, global, inline, internal_linkage, neverinline, static )
3. Is either ( identifier, const specifier, long, short, signed, unsigned, bool, char, double, int)
1. Attempt to parse as constrcutor or destructor : `parse_global_nspace_constructor_destructor`
2. If its an operator cast (definition outside class) : `parse_operator_cast`
3. Its an operator, function, or varaible : `parse_operator_function_or_varaible`
4. If its not a global body, consume the closing curly brace
## `parse_global_nspace_constructor_destructor`
1. Look ahead for the start of the arguments for a possible constructor/destructor
2. Go back past the identifier
3. Check to see if its a destructor by checking for the `~`
4. Continue the next token should be a `::`
5. Determine if the next valid identifier (ignoring possible template parameters) is the same as the first identifier of the function.
6. If it is we have either a constructor or destructor so parse using their respective functions (`parse_constructor`, `parse_destructor`).
## `parse_identifier`
This is going to get heavily changed down the line to have a more broken down "identifier expression" so that the qualifier, template args, etc, can be distinguished between the targeted identifier.
The function can parse all of them, however the AST node compresses them all into a string.
1. Consume first identifier
2. `parse_template_args`
3. While there is a static symbol accessor ( `::` )
1. Consume `::`
2. Consume member identifier
3. `parse_template args` (for member identifier)
4. If a `~` is encounted and the scope is for a destructor's identifier, do not consume it and return with what parsed.
## `parse_include`
1. Consume include directive
2. Consume the path
## `parse_operator_after_ret_type`
This is needed as a operator defintion is not easily resolvable early on, as such this function handles resolving a operator after its been made ceratin that the type of declaration or definition is indeed for a operator signature.
By the point this function is called the following are known : export module flag, attributes, specifiers, return type
1. If there is any qualifiers for the operator, parse them
2. Consume operator keyword
3. Determine the operator type (This will be offloaded to the lexer moreso than how it is now) & consume
4. `parse_params`
5. If there is no parameters this is operator is a member of pointer if its symbols is a *.
6. Parse postfix specifiers
7. If there is a opening curly brace, `parse function_body`
8. Otherwise: consume end statement, check for inline comment.
## `parse_operator_function_or_variable`
When this function is called, attribute and specifiers may have been resolved, however what comes next can still be either an operator, function, or varaible.
1. Check for preprocessor macro, if there is one : `parse_simple_preprocess`
2. `parse_type` (Does the bulk of the work)
3. Begin lookahead to see if we get qualifiers or we eventually find the operator declaration
4. If we find an operator keyword : `parse_operator_after_ret_type`
5. otherwise :
1. `parse_identifier`
2. If we se a opening parenthesis (capture start), its a function : `parse_function_after_name`
3. Its a variable : `parse_variable_after_name`
## `parse_pragma`
1. Consume pragma directive
2. Process the token content into cached string
## `parse_params`
1. Consume either a `(` or `<` based on `use_template_capture` arg
2. If the we immdiately find a closing token, consume it and finish.
3. If we encounter a varadic argument, consume it and return a `param_varadic` ast constant
4. `parse_type`
5. If we have a macro, parse it (Unreal has macros as tags to parameters and or as entire arguments).
6. So long as next token isn't a comma
a. If we have an identifier
1. Consume it
2. Check for assignment:
a. Consume assign operator
b. Parse the expression
7. While we continue to encounter commas
a. Consume them
b. Repeat steps 3 to 6.2.b
8. Consume the closing token
## `parse_preprocess_cond`
1. Parse conditional directive
2. Process directive's content expression
## `parse_simple_preprocess`
There is still decent room for improvement in this setup. Right now the entire macro's relevant tokens are shoved into an untyped AST. It would be better to store it instead in an `AST_Macro` node instead down the line.
1. Consume the macro token
2. Check for an opening curly brace
1. Consume opening curly brace
2. Until the closing curly is encountered consume all tokens.
3. If the parent context is a typedef
1. Check for end stement
1. Consume it
2. Consume potential inline comment
3. Otherwise do steps 3 to 3.1.2
4. Shove it all in an untyped string
## `parse_static_assert`
1. Consume static assert and opening curly brace
2. Consume all tokens until the the closing brace is reached.
3. Consume curly brace and end statement
4. Place all tokens within braces into a content for the assert.
## `parse_template_args`
This will get changed heavily once we have better support for typename expressions
1. Consume opening angle bracket
2. Consume all tokens until closing angle bracket
3. Consme closing angle bracket
4. Return the currtok with the ammended length.
## `parse_variable_after_name`
This is needed as a variable defintion is not easily resolvable early on, it takes a long evaluation period before its known that the declaration or definition is a variable. As such this function handles resolving a variable.
By the point this function is called the following are known : export module flag, attributes, specifiers, value type, name
1. If its an assignment, parse the assignment expression (currently to an untyped string)
2. If its an opening curly brace, parse the expression within (currnelty to an untyped stirng).
1. Consume the closing curly brace
3. If its a `:`, we're dealing with bitfield definition:
1. Consume the assign classifier
2. Consume the expression (currently to an untyped string)
4. If a comma is encountered : `parse_variable declaration_list`
5. Consume statement end
6. Check for inline comment
## `parse_variable_declaration_list`
1. Consume the comma
2. Parse specifiers
3. `parse_variable_after_name`
## `parse_class`
1. `parse_class_struct`
## `parse_constructor`
This currently doesn't support postfix specifiers (planning to in the future)
1. `parse_identifier`
2. `parse_parameters`
3. If currtok is a `:`
1. Consume `:`
2. Parse the initializer list
3. `parse_function_body`
4. If currtok is an opening curly brace
1. `parse_function_body`
5. Otherwise:
1. Consume statement end
2. Check for inline comment
## `parse_destructor`
1. Check for and consume virtual specifier
2. Check for the `~` operator
3. `parse_identifier`
4. Consume opening and closing parenthesis
5. Check for assignment operator:
1. Consume assignment op
2. Consume pure specifier `0`
6. If not pure virtual & currtok is opening curly brace:
1. `parse_function_body`
7. Otherwise:
1. Consume end statement
2. If currtok is comment : `parse_comment`
## `parse_enum`
1. Consume enum token
2. Check for and consume class token
3. `parse_attributes`
4. If there is an identifier consume it
5. Check for a `:`
1. Consume `:`
2. `parse_type`
6. If there is a body parse it (Consume `{`):
1. Newline : ast constant
2. Comment : `parse_comment`
3. Preprocess_Define : `parse_define`
4. Preprocess_Conditional (if, ifdef, ifndef, elif ) : `parse_preprocess_cond`
5. Preprocess_Else : ast constant
6. Preprocess_Endif : ast constant
7. Preprocess_Macro : `parse_simple_preprocess`
8. Preprocess_Pragma : `parse_pragma`
9. Preprocess_Unsupported : `parse_smple_preprocess`
10. An actual enum entry
1. Consume identifier
2. If there is an assignment operator:
1. Consume operator
2. Consume the expression (assigned to untyped string for now)
3. If a macro is encountered consume it (Unreal UMETA macro support)
3. If there is a comma, consume it
## `parse_export_body`
1. `parse_global_nspace`
## `parse_extern_link_body`
1. `parse_global_nspace`
## `parse_extern_link`
1. Consume Decl_Extern_Linkage
2. Consume the linkage identifier
3. `parse_extern_link_body`
## `parse_friend`
1. Consume `friend`
2. `parse_type`
3. If the currok is an identifier its a function declaration or definition
1. `parse_function_after_name`
4. Consume end statement so long as its not a function definion
5. Check for inline comment, `parse_comment` if exists
## `parse_function`
1. Check and parse for `export`
2. `parse_attributes`
3. Parse specifiers
4. `parse_type`
5. `parse_identifier`
6. `parse_function_after_name`
## `parse_namespace`
1. Consume namespace declaration
2. Parse identifier
3. `parse_global_namespace`
## `parse_operator`
1. Check for and parse export declaration
2. `parse_attributes`
3. Parse specifiers
4. `parse_type`
5. `parse_operator_after_ret_type`
## `parse_operator_cast`
1. Look for and parse a qualifier namespace for the cast (in-case this is defined outside the class's scope)
2. Consume operator declaration
3. `parse_type`
4. Consume opening and closing parethesis
5. Check for a const qualifiying specifier
6. Check to see if this is a definition (`{`)
1. Consume `{`
2. Parse body to untyped string (parsing statement and expressions not supported yet)
3. Consume `}`
7. Otherwise:
1. Consume end statement
2. Check for and consume comment : `parse_comment`
## `parse_struct`
1. `parse_class_struct`
## `parse_template`
Note: This currently doesn't support templated operator casts (going to need to add support for it)
1. Check for and parse export declaration
2. Consume template declaration
3. `parse_params`
4. Parse for any of the following:
1. Decl_Class : `parse_class`
2. Decl_Struct : `parse_struct`
3. Decl_Union : `parse_union`
4. Decl_Using : `parse_using`
5. The following compound into a resolved definition or declaration:
1. `parse_attributes`
2. Parse specifiers
3. Attempt to parse as constructor or destructor: `parse_global_nspace_constructor_destructor`
4. Otherwise: `parse_operator_function_or_variable`
## `parse_type`
This function's implementation is awful and not done correctly. It will most likely be overhauled in the future as I plan to segement the AST_Type into several AST varaints along with sub-types to help produce robust type expressions.
Hopefully I won't need to make authentic type expressions as I was hopeing to avoid that...
### Current Algorithim
Anything that is in the qualifier capture of the function typename is treated as an expression abstracted as an untyped string
1. `parse_attributes`
2. Parse specifiers
3. If the `parse_type` was called from a template parse, check to see if class was used instead of typname and consume as name.
4. This is where things get ugly for each of these depend on what the next token is.
1. If its an in-place definition of a class, enum, struct, or union:
2. If its a decltype (Not supported yet but draft impl there)
3. If its a compound native type expression (unsigned, char, short, long, int, float, dobule, etc )
4. Ends up being a regular type alias of an identifier
5. Parse specifiers (postfix)
6. We need to now look ahead to see If we're dealing with a function typename
7. If wer're dealing with a function typename:
1. Shove the specifiers, and identifier code we have so far into a return type typename's Name (untyped string)
1. Reset the specifiers code for the top-level typeanme
2. Check to see if the next token is an identifier:
1. `parse_identifier`
3. Check to see if the next token is capture start and is not the last capture ("qualifier capture"):
1. Consume `(`
2. Consume expresssion between capture
3. Consume `)`
4. `parse_params`
5. Parse postfix specifiers
8. Check for varaidic argument (param pack) token:
1. Consume varadic argument token
### WIP - Alternative Algorithim
Currently wrapped up via macro: `GEN_USE_NEW_TYPENAME_PARSING`
Anything that is in the qualifier capture of the function typename is treated as an expression abstracted as an untyped string
1. `parse_attributes`
2. Parse specifiers (prefix)
3. This is where things get ugly for each of these depend on what the next token is.
1. If its an in-place definition of a class, enum, struct, or union:
2. If its a decltype (Not supported yet but draft impl there)
3. If its a compound native type expression (unsigned, char, short, long, int, float, dobule, etc )
4. Ends up being a regular type alias of an identifier
4. Parse specifiers (postfix)
1. If any specifiers are found populate specifiers code with them.
5. We need to now look ahead to see If we're dealing with a function typename
6. If wer're dealing with a function typename:
1. Shove the specifiers, and identifier code we have so far into a return type typename's Name (untyped string)
1. Reset the specifiers code for the top-level typename
2. Check to see if the next token is an identifier:
1. `parse_identifier`
3. Check to see if the next token is capture start and is not the last capture ("qualifier capture"):
1. Consume `(`
2. Parse binding specifiers
3. `parse_identifier`
4. `parse_parameters` -> params_nested
5. Consume `)`
6. Construct a nested function typename definition for the qualifier `Name`
4. `parse_params` - > params
5. Parse postfix specifiers
7. Check for varaidic argument (param pack) token:
1. Consume varadic argument token
### **Later: Algorithim based on typename expressions**
## `parse_typedef`
1. Check for export module specifier
2. typedef keyword
3. If its a preprocess macro: Get the macro name
4. Else:
1. Check to see if its a complicated definition (in-place enum, class, struct, union)
2. If its a complicated definition:
1. Perform the look ahead similar to `parse_complicated_definition`'s implementation
2. Check to see if its a forward declaration : `parse_forward_declaration`
3. If end[-1] is an identifier:
1. Its either an in-place, varaible type qualified identifier, or indirection type:
1. `parse_foward_or_definition`
4. else if end[-1] is a closing curly brace
1. Its a definition: `parse_forward_or_definition`
5. else if end[-1] is a closing square brace
2. Its an array definition: `parse_type`
3. Else : `parse-type`
4. Check for identifier : Consume the token
5. `parse_array_decl`
5. Consume end statement
6. Check for inline comment : `parse_comment`
## `parse_union`
1. Check for export module specifier
2. union keyword
3. `parse_attributes`
4. Check for identifier
5. Parse the body (Possible options):
1. Newline
2. Comment
3. Decl_Class
4. Decl_Enum
5. Decl_Struct
6. Decl_Union
7. Preprocess_Define
8. Preprocess_Conditional (if, ifdef, ifndef, elif, else, endif)
9. Preprocess_Macro
10. Preprocess_Pragma
11. Unsupported preprocess directive
12. Variable
6. If its not an inplace definiton: End Statement
## `parse_using`
1. Check for export module specifier
2. using keyword
3. Check to see if its a using namespace
4. Get the identifier
5. If its a regular using declaration:
1. `parse_attributes`
2. `parse_type`
3. `parse_array_decl`
6. End statement
7. Check for inline comment
## `parse_variable`
1. Check for export module specifier
2. `parse_attributes`
3. `parse specifiers`
4. `parse_type`
5. `parse_identifier`
6. `parse_variable_after_name`

81
docs/Parsing.md Normal file
View File

@ -0,0 +1,81 @@
# Parsing
The library features a naive parser tailored for only what the library needs to construct the supported syntax of C++ into its AST.
This parser does not, and should not do the compiler's job. By only supporting this minimal set of features, the parser is kept (so far) around ~5600 loc. I hope to keep it under 10k loc worst case.
You can think of this parser of a frontend parser vs a semantic parser. Its intuitively similar to WYSIWYG. What you precerive as the syntax from the user-side before the compiler gets a hold of it, is what you get.
User exposed interface:
```cpp
CodeClass parse_class ( StrC class_def );
CodeConstructor parse_constructor ( StrC constructor_def );
CodeDestructor parse_destructor ( StrC destructor_def );
CodeEnum parse_enum ( StrC enum_def );
CodeBody parse_export_body ( StrC export_def );
CodeExtern parse_extern_link ( StrC exten_link_def );
CodeFriend parse_friend ( StrC friend_def );
CodeFn parse_function ( StrC fn_def );
CodeBody parse_global_body ( StrC body_def );
CodeNS parse_namespace ( StrC namespace_def );
CodeOperator parse_operator ( StrC operator_def );
CodeOpCast parse_operator_cast( StrC operator_def );
CodeStruct parse_struct ( StrC struct_def );
CodeTemplate parse_template ( StrC template_def );
CodeType parse_type ( StrC type_def );
CodeTypedef parse_typedef ( StrC typedef_def );
CodeUnion parse_union ( StrC union_def );
CodeUsing parse_using ( StrC using_def );
CodeVar parse_variable ( StrC var_def );
```
To parse file buffers, use the `parse_global_body` function.
***Parsing will aggregate any tokens within a function body or expression statement to an untyped Code AST.***
Everything is done in one pass for both the preprocessor directives and the rest of the language.
The parser performs no macro expansion as the scope of gencpp feature-set is to only support the preprocessor for the goal of having rudimentary awareness of preprocessor ***conditionals***, ***defines***, ***includes***, and ***pragmas***.
The keywords supported for the preprocessor are:
* include
* define
* if
* ifdef
* elif
* endif
* pragma
Each directive `#` line is considered one preproecessor unit, and will be treated as one Preprocessor AST. *These ASTs will be considered members or entries of braced scope they reside within*.
If a directive is used with an unsupported keyword its will be processed as an untyped AST.
The preprocessor lines are stored as members of their associated scope they are parsed within. ( Global, Namespace, Class/Struct )
Any preprocessor definition abuse that changes the syntax of the core language is unsupported and will fail to parse if not kept within an execution scope (function body, or expression assignment).
Exceptions:
* function signatures are allowed for a preprocessed macro: `neverinline MACRO() { ... }`
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_FUNCTION_SIGNATURES`
* typedefs allow for a preprocessed macro: `typedef MACRO();`
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_TYPEDEF`
*(Exceptions are added on an on-demand basis)*
*(See functions `parse_operator_function_or_variable` and `parse_typedef` )*
Adding your own exceptions is possible by simply modifying the parser to allow for the syntax you need.
*Note: You could interpret this strictness as a feature. This would allow the user to see if their codebase or a third-party's codebase some some egregious preprocessor abuse.*
The lexing and parsing takes shortcuts from whats expected in the standard.
* Numeric literals are not checked for validity.
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
* *This includes the assignment of variables.*
* Attributes ( `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU) )
* Assumed to *come before specifiers* (`const`, `constexpr`, `extern`, `static`, etc) for a function or right afterthe return type.
* Or in the usual spot for class, structs, (*right after the declaration keyword*)
* typedefs have attributes with the type (`parse_type`)
* Parsing attributes can be extended to support user defined macros by defining `GEN_DEFINE_ATTRIBUTE_TOKENS` (see `gen.hpp` for the formatting)
Empty lines used throughout the file are preserved for formatting purposes during ast serialization.

489
docs/Readme.md Normal file
View File

@ -0,0 +1,489 @@
## Documentation
The project has no external dependencies beyond:
* `errno.h`
* `stat.h`
* `stdarg.h`
* `stddef.h`
* `stdio.h`
* `copyfile.h` (Mac)
* `types.h` (Linux)
* `unistd.h` (Linux/Mac)
* `intrin.h` (Windows)
* `io.h` (Windows with gcc)
* `windows.h` (Windows)
Dependencies for the project are wrapped within `GENCPP_ROLL_OWN_DEPENDENCIES` (Defining it will disable them).
The majority of the dependency's implementation was derived from the [c-zpl library](https://github.com/zpl-c/zpl).
This library was written in a subset of C++ where the following are not used at all:
* RAII (Constructors/Destructors), lifetimes are managed using named static or regular functions.
* Language provide dynamic dispatch, RTTI
* Object-Oriented Inheritance
* Exceptions
Polymorphic & Member-functions are used as an ergonomic choice, along with a conserative use of operator overloads.
There are only 4 template definitions in the entire library. (`Array<Type>`, `Hashtable<Type>`, `swap<Type>`, and `AST/Code::cast<Type>`)
Two generic templated containers are used throughout the library:
* `template< class Type> struct Array`
* `template< class Type> struct HashTable`
Both Code and AST definitions have a `template< class Type> Code/AST :: cast()`. Its just an alternative way to explicitly cast to each other.
`template< class Type> swap( Type& a, Type& b)` is used over a macro.
Otherwise the library is free of any templates.
### *WHAT IS NOT PROVIDED*
**There is no support for validating expressions.**
Its difficult to parse without enough benefits (At the metaprogramming level).
I plan to add this only at the tail of the project parsing milestone.
**Only trivial template support is provided.**
The intention is for only simple, non-recursive substitution.
The parameters of the template are treated like regular parameter AST entries.
This means that the typename entry for the parameter AST would be either:
* `class`
* `typename`
* A fundamental type, function, or pointer type.
Anything beyond this usage is not supported by parse_template for arguments (at least not intentionally).
Use at your own mental peril.
*Concepts and Constraints are not supported, its usage is non-trivial substitution.*
### The Data & Interface
As mentioned in root readme, the user is provided Code objects by calling the constructor's functions to generate them or find existing matches.
The AST is managed by the library and provided to the user via its interface.
However, the user may specifiy memory configuration.
Data layout of AST struct (Subject to heavily change with upcoming redesign):
```cpp
union {
struct
{
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
AST* Specs; // Destructor, Function, Operator, Typename, Variable
union {
AST* InitializerList; // Constructor
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
AST* ReturnType; // Function, Operator, Typename
AST* UnderlyingType; // Enum, Typedef
AST* ValueType; // Parameter, Variable
};
union {
AST* Macro; // Parameters
AST* BitfieldSize; // Variable (Class/Struct Data Member)
AST* Params; // Constructor, Function, Operator, Template, Typename
};
union {
AST* ArrExpr; // Typename
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union
AST* Declaration; // Friend, Template
AST* Value; // Parameter, Variable
};
union {
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
AST* SpecsFuncSuffix; // Only used with typenames, to store the function suffix if typename is function signature.
};
};
StringCached Content; // Attributes, Comment, Execution, Include
struct {
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers
};
};
union {
AST* Prev;
AST* Front;
AST* Last;
};
union {
AST* Next;
AST* Back;
};
AST* Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
union {
b32 IsFunction; // Used by typedef to not serialize the name field.
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
OperatorT Op;
AccessSpec ParentAccess;
s32 NumEntries;
};
s32 Token; // Handle to the token, stored in the CodeFile (Otherwise unretrivable)
```
*`CodeT` is a typedef for `ECode::Type` which has an underlying type of `u32`*
*`OperatorT` is a typedef for `EOperator::Type` which has an underlying type of `u32`*
*`StringCahced` is a typedef for `String const`, to denote it is an interned string*
*`String` is the dynamically allocated string type for the library*
AST widths are setup to be AST_POD_Size.
The width dictates how much the static array can hold before it must give way to using an allocated array:
```cpp
constexpr static
usize ArrSpecs_Cap =
(
AST_POD_Size
- sizeof(AST*) * 3
- sizeof(StringCached)
- sizeof(CodeT)
- sizeof(ModuleFlag)
- sizeof(u32)
)
/ sizeof(SpecifierT) -1; // -1 for 4 extra bytes (Odd num of AST*)
```
*Ex: If the AST_POD_Size is 128 the capacity of the static array is 20.*
Data Notes:
* The allocator definitions used are exposed to the user incase they want to dictate memory usage
* You'll find the memory handling in `init`, `deinit`, `reset`, `gen_string_allocator`, `get_cached_string`, `make_code`.
* Allocators are defined with the `AllocatorInfo` structure found in `dependencies\memory.hpp`
* Most of the work is just defining the allocation procedure:
```cpp
void* ( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags );
```
* ASTs are wrapped for the user in a Code struct which is a wrapper for a AST* type.
* Both AST and Code have member symbols but their data layout is enforced to be POD types.
* This library treats memory failures as fatal.
* Cached Strings are stored in their own set of arenas. AST constructors use cached strings for names, and content.
* `StringArenas`, `StringCache`, `Allocator_StringArena`, and `Allocator_StringTable` are the associated containers or allocators.
* Strings used for serialization and file buffers are not contained by those used for cached strings.
* They are currently using `GlobalAllocator`, which are tracked array of arenas that grows as needed (adds buckets when one runs out).
* Memory within the buckets is not reused, so its inherently wasteful.
* I will be augmenting the single arena with a simple slag allocator.
* Linked lists used children nodes on bodies, and parameters.
* Its intended to generate the AST in one go and serialize after. The constructors and serializer are designed to be a "one pass, front to back" setup.
* Allocations can be tuned by defining the folloiwng macros:
* `GEN_GLOBAL_BUCKET_SIZE` : Size of each bucket area for the global allocator
* `GEN_CODEPOOL_NUM_BLOCKS` : Number of blocks per code pool in the code allocator
* `GEN_SIZE_PER_STRING_ARENA` : Size per arena used with string caching.
* `GEN_MAX_COMMENT_LINE_LENGTH` : Longest length a comment can have per line.
* `GEN_MAX_NAME_LENGTH` : Max length of any identifier.
* `GEN_MAX_UNTYPED_STR_LENGTH` : Max content length for any untyped code.
* `GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE` : token_fmt_va uses local_persit memory of this size for the hashtable.
* `GEN_LEX_ALLOCATOR_SIZE`
* `GEN_BUILDER_STR_BUFFER_RESERVE`
The following CodeTypes are used which the user may optionally use strong typing with if they enable: `GEN_ENFORCE_STRONG_CODE_TYPES`
* CodeBody : Has support for `for-range` iterating across Code objects.
* CodeAttributes
* CodeComment
* CodeClass
* CodeConstructor
* CodeDefine
* CodeDestructor
* CodeEnum
* CodeExec
* CodeExtern
* CodeInclude
* CodeFriend
* CodeFn
* CodeModule
* CodeNS
* CodeOperator
* CodeOpCast
* CodeParam : Has support for `for-range` iterating across parameters.
* CodePreprocessCond
* CodePragma
* CodeSpecifiers : Has support for `for-range` iterating across specifiers.
* CodeStruct
* CodeTemplate
* CodeType
* CodeTypedef
* CodeUnion
* CodeUsing
* CodeVar
Each Code boy has an associated "filtered AST" with the naming convention: `AST_<CodeName>`
Unrelated fields of the AST for that node type are omitted and only necessary padding members are defined otherwise.
Retrieving a raw version of the ast can be done using the `raw()` function defined in each AST.
## There are three sets of interfaces for Code AST generation the library provides
* Upfront
* Parsing
* Untyped
### Upfront Construction
All component ASTs must be previously constructed, and provided on creation of the code AST.
The construction will fail and return CodeInvalid otherwise.
Interface :``
* def_attributes
* *This is pre-appended right before the function symbol, or placed after the class or struct keyword for any flavor of attributes used.*
* *Its up to the user to use the desired attribute formatting: `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU).*
* def_comment
* def_class
* def_constructor
* def_define
* def_destructor
* def_enum
* def_execution
* *This is equivalent to untyped_str, except that its intended for use only in execution scopes.*
* def_extern_link
* def_friend
* def_function
* def_include
* def_module
* def_namespace
* def_operator
* def_operator_cast
* def_param
* def_params
* def_pragma
* def_preprocess_cond
* def_specifier
* def_specifiers
* def_struct
* def_template
* def_type
* def_typedef
* def_union
* def_using
* def_using_namespace
* def_variable
Bodies:
* def_body
* def_class_body
* def_enum_body
* def_export_body
* def_extern_link_body
* def_function_body
* *Use this for operator bodies as well*
* def_global_body
* def_namespace_body
* def_struct_body
* def_union_body
Usage:
```cpp
<name> = def_<function type>( ... );
Code <name>
{
...
<name> = def_<function name>( ... );
}
```
When using the body functions, its recommended to use the args macro to auto determine the number of arguments for the varadic:
```cpp
def_global_body( args( ht_entry, array_ht_entry, hashtable ));
// instead of:
def_global_body( 3, ht_entry, array_ht_entry, hashtable );
```
If a more incremental approach is desired for the body ASTs, `Code def_body( CodeT type )` can be used to create an empty body.
When the members have been populated use: `AST::validate_body` to verify that the members are valid entires for that type.
### Parse construction
A string provided to the API is parsed for the intended language construct.
Interface :
* parse_class
* parse_constructor
* parse_destructor
* parse_enum
* parse_export_body
* parse_extern_link
* parse_friend
* Purposefully are only support forward declares with this constructor.
* parse_function
* parse_global_body
* parse_namespace
* parse_operator
* parse_operator_cast
* parse_struct
* parse_template
* parse_type
* parse_typedef
* parse_union
* parse_using
* parse_variable
Usage:
```cpp
Code <name> = parse_<function name>( string with code );
Code <name> = def_<function name>( ..., parse_<function name>(
<string with code>
));
```
### Untyped constructions
Code ASTs are constructed using unvalidated strings.
Interface :
* token_fmt_va
* token_fmt
* untyped_str
* untyped_fmt
* untyped_token_fmt
During serialization any untyped Code AST has its string value directly injected inline of whatever context the content existed as an entry within.
Even though these are not validated from somewhat correct c/c++ syntax or components, it doesn't mean that Untyped code can be added as any component of a Code AST:
* Untyped code cannot have children, thus there cannot be recursive injection this way.
* Untyped code can only be a child of a parent of body AST, or for values of an assignment (ex: variable assignment).
These restrictions help prevent abuse of untyped code to some extent.
Usage Conventions:
```cpp
Code <name> = def_variable( <type>, <name>, untyped_<function name>(
<string with code>
));
Code <name> = untyped_str( code(
<some code without "" quotes>
));
```
Optionally, `code_str`, and `code_fmt` macros can be used so that the code macro doesn't have to be used:
```cpp
Code <name> = code_str( <some code without "" quotes > )
```
Template metaprogramming in the traditional sense becomes possible with the use of `token_fmt` and parse constructors:
```cpp
StrC value = txt("Something");
char const* template_str = txt(
Code with <key> to replace with token_values
...
);
char const* gen_code_str = token_fmt( "key", value, template_str );
Code <name> = parse_<function name>( gen_code_str );
```
## Predefined Codes
The following are provided predefined by the library as they are commonly used:
* `access_public`
* `access_protected`
* `access_private`
* `attrib_api_export`
* `attrib_api_import`
* `module_global_fragment`
* `module_private_fragment`
* `fmt_newline`
* `param_varaidc` (Used for varadic definitions)
* `pragma_once`
* `preprocess_else`
* `preprocess_endif`
* `spec_const`
* `spec_consteval`
* `spec_constexpr`
* `spec_constinit`
* `spec_extern_linkage` (extern)
* `spec_final`
* `spec_forceinline`
* `spec_global` (global macro)
* `spec_inline`
* `spec_internal_linkage` (internal macro)
* `spec_local_persist` (local_persist macro)
* `spec_mutable`
* `spec_neverinline`
* `spec_override`
* `spec_ptr`
* `spec_pure`
* `spec_ref`
* `spec_register`
* `spec_rvalue`
* `spec_static_member` (static)
* `spec_thread_local`
* `spec_virtual`
* `spec_volatile`
* `t_empty` (Used for varaidc macros)
* `t_auto`
* `t_void`
* `t_int`
* `t_bool`
* `t_char`
* `t_wchar_t`
* `t_class`
* `t_typename`
Optionally the following may be defined if `GEN_DEFINE_LIBRARY_CODE_CONSTANTS` is defined
* `t_b32`
* `t_s8`
* `t_s16`
* `t_s32`
* `t_s64`
* `t_u8`
* `t_u16`
* `t_u32`
* `t_u64`
* `t_sw` (ssize_t)
* `t_uw` (size_t)
* `t_f32`
* `t_f64`
## Extent of operator overload validation
The AST and constructors will be able to validate that the arguments provided for the operator type match the expected form:
* If return type must match a parameter
* If number of parameters is correct
* If added as a member symbol to a class or struct, that operator matches the requirements for the class (types match up)
* There is no support for validating new & delete operations (yet)
The user is responsible for making sure the code types provided are correct
and have the desired specifiers assigned to them beforehand.
## Code generation and modification
There are three provided auxillary interfaces:
* Builder
* Editor
* Scanner
Editor and Scanner are disabled by default, use `GEN_FEATURE_EDITOR` and `GEN_FEATURE_SCANNER` to enable them.
### Builder is a similar object to the jai language's string_builder
* The purpose of it is to generate a file.
* A file is specified and opened for writing using the open( file_path) function.
* The code is provided via print( code ) function will be serialized to its buffer.
* When all serialization is finished, use the write() command to write the buffer to the file.
### Scanner Auxillary Interface
Provides *(eventually)* `scan_file` to automatically populate a CodeFile which contains a parsed AST (`Code`) of the file, with any contextual failures that are reported from the parser.

View File

@ -6,23 +6,26 @@
<SyncFiles>true</SyncFiles>
<Recursive>true</Recursive>
<ShowEmptyFolders>true</ShowEmptyFolders>
<IncludeFilesWithoutExt>false</IncludeFilesWithoutExt>
<IsVirtual>false</IsVirtual>
<IsFolder>false</IsFolder>
<BuildCommand>powershell ./scripts/build.ps1</BuildCommand>
<RebuildCommand>powershell ./scripts/rebuild.ps1</RebuildCommand>
<BuildCommand>pwsh ./scripts/build.ps1 msvc debug bootstrap</BuildCommand>
<RebuildCommand></RebuildCommand>
<BuildFileCommand></BuildFileCommand>
<CleanCommand>powershell ./scripts/clean.ps1</CleanCommand>
<CleanCommand>pwsh ./scripts/clean.ps1</CleanCommand>
<BuildWorkingDirectory></BuildWorkingDirectory>
<CancelBuild></CancelBuild>
<RunCommand>./test/gen/build/gencpp.exe</RunCommand>
<RunCommandWorkingDirectory></RunCommandWorkingDirectory>
<DebugCommand>powershell ./scripts/build.ps1</DebugCommand>
<ExePathCommand>./test/gen/build/gencpp.exe</ExePathCommand>
<DebugSln>gencpp.sln</DebugSln>
<UseVisualStudioEnvBat>false</UseVisualStudioEnvBat>
<Exe>./test/gen/build/gencpp.exe</Exe>
<Args></Args>
<WorkingDirectory></WorkingDirectory>
<DebugCommand>pwsh ./scripts/build.ps1</DebugCommand>
<DebugSln></DebugSln>
<UseVisualStudioEnvBat>true</UseVisualStudioEnvBat>
<CaptureExeOutput>false</CaptureExeOutput>
<Configurations>
<Configuration>Debug</Configuration>
<Configuration>Release</Configuration>
<Configuration>bootstrap debug</Configuration>
</Configurations>
<Platforms>
<Platform>x64</Platform>
@ -31,24 +34,40 @@
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\ATLMFC\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\VS\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</AdditionalIncludePath>
</AdditionalIncludePaths>
<Defines></Defines>
<Defines>
<Define>GEN_TIME</Define>
<Define>GEN_SYSTEM_WINDOWS</Define>
<Define>GEN_INTELLISENSE_DIRECTIVES</Define>
<Define>GEN_EXECUTION_EXPRESSION_SUPPORT</Define>
<Define>GEN_BENCHMARK</Define>
<Define>GEN_COMPILER_MSVC</Define>
</Defines>
<ConfigProperties>
<ConfigAndPlatform>
<Name>Debug:x64</Name>
<Defines></Defines>
<ForceIncludes></ForceIncludes>
</ConfigAndPlatform>
<ConfigAndPlatform>
<Name>bootstrap debug:x64</Name>
<Defines></Defines>
<ForceIncludes></ForceIncludes>
</ConfigAndPlatform>
<Config>
<Name>Debug</Name>
<Defines></Defines>
</Config>
<Config>
<Name>bootstrap debug</Name>
<Defines></Defines>
</Config>
<Platform>
<Name>x64</Name>
<Defines></Defines>

View File

@ -7,20 +7,37 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gencpp", "gencpp.vcxproj",
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
bootstrap debug|x64 = bootstrap debug|x64
bootstrap debug|x86 = bootstrap debug|x86
bootstrap release|x64 = bootstrap release|x64
bootstrap release|x86 = bootstrap release|x86
singleheader debug|x64 = singleheader debug|x64
singleheader debug|x86 = singleheader debug|x86
singleheader release|x64 = singleheader release|x64
singleheader release|x86 = singleheader release|x86
test debug|x64 = test debug|x64
test debug|x86 = test debug|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x64.ActiveCfg = Debug|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x64.Build.0 = Debug|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x86.ActiveCfg = Debug|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x86.Build.0 = Debug|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x64.ActiveCfg = Release|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x64.Build.0 = Release|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x86.ActiveCfg = Release|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x86.Build.0 = Release|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x64.ActiveCfg = bootstrap release|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x64.Build.0 = bootstrap release|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x86.ActiveCfg = bootstrap debug|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x86.Build.0 = bootstrap debug|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap release|x64.ActiveCfg = bootstrap release|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap release|x86.ActiveCfg = bootstrap release|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap release|x86.Build.0 = bootstrap release|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x64.ActiveCfg = singleheader debug|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x64.Build.0 = singleheader debug|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x86.ActiveCfg = singleheader debug|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x86.Build.0 = singleheader debug|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x64.ActiveCfg = bootstrap debug|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x64.Build.0 = bootstrap debug|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x86.ActiveCfg = singleheader release|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x86.Build.0 = singleheader release|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x64.ActiveCfg = test debug|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x64.Build.0 = test debug|x64
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x86.ActiveCfg = test debug|Win32
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x86.Build.0 = test debug|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,20 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<ProjectConfiguration Include="bootstrap debug|Win32">
<Configuration>bootstrap debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<ProjectConfiguration Include="bootstrap debug|x64">
<Configuration>bootstrap debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<ProjectConfiguration Include="bootstrap release|Win32">
<Configuration>bootstrap release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="bootstrap release|x64">
<Configuration>bootstrap release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="singleheader debug|Win32">
<Configuration>singleheader debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="singleheader debug|x64">
<Configuration>singleheader debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="singleheader release|Win32">
<Configuration>singleheader release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="singleheader release|x64">
<Configuration>singleheader release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="test debug|Win32">
<Configuration>test debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="test debug|x64">
<Configuration>test debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
@ -25,24 +49,54 @@
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
@ -50,100 +104,196 @@
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='test debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|Win32'">
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|Win32'">
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
<NMakePreprocessorDefinitions>WIN32;NDEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<NMakeBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeBuildCommandLine>
<NMakeReBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeReBuildCommandLine>
<NMakeCleanCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>GEN_TIME;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<IncludePath>$(ProjectDir)thirdparty;$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
<SourcePath>$(ProjectDir)project;$(ProjectDir)test;$(SourcePath)</SourcePath>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|Win32'">
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<NMakeBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeBuildCommandLine>
<NMakeReBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeReBuildCommandLine>
<NMakeCleanCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>GEN_TIME;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<IncludePath>$(ProjectDir)thirdparty;$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
<SourcePath>$(ProjectDir)project;$(ProjectDir)test;$(SourcePath)</SourcePath>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|Win32'">
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|Win32'">
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'">
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc debug bootstrap</NMakeBuildCommandLine>
<NMakeReBuildCommandLine>
</NMakeReBuildCommandLine>
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<IncludePath>$(ProjectDir)project;$(IncludePath)</IncludePath>
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'">
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc debug test</NMakeBuildCommandLine>
<NMakeReBuildCommandLine />
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'">
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc debug singleheader</NMakeBuildCommandLine>
<NMakeReBuildCommandLine>
</NMakeReBuildCommandLine>
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'">
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc release singleheader</NMakeBuildCommandLine>
<NMakeReBuildCommandLine>
</NMakeReBuildCommandLine>
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'">
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc release bootstrap</NMakeBuildCommandLine>
<NMakeReBuildCommandLine>
</NMakeReBuildCommandLine>
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'">
<ClCompile>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'">
<ClCompile>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'">
<ClCompile>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'">
<ClCompile>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'">
<ClCompile>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<None Include=".editorconfig" />
<None Include="project\enums\AttributeTokens.csv" />
<None Include="project\enums\ECode.csv" />
<None Include="project\enums\EOperator.csv" />
<None Include="project\enums\ESpecifier.csv" />
<None Include="project\enums\ETokType.csv" />
<None Include="Readme.md" />
<None Include="scripts\.clang-format" />
<None Include="scripts\build.ci.ps1" />
<None Include="scripts\build.ps1" />
<None Include="scripts\clean.ps1" />
<None Include="scripts\gen.ps1" />
<None Include="scripts\genccp.natstepfilter" />
<None Include="scripts\gencpp.refactor" />
<None Include="scripts\get_sources.ps1" />
<None Include="scripts\helpers\devshell.ps1" />
<None Include="scripts\helpers\target_arch.psm1" />
<None Include="scripts\package_release.ps1" />
<None Include="scripts\refactor.ps1" />
<None Include="test\gen\meson.build" />
<None Include="test\meson.build" />
<None Include="test\Readme.md" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="project\components\gen.data_structures.hpp" />
<ClInclude Include="project\components\gen.interface.hpp" />
<ClInclude Include="project\components\gen.types.hpp" />
<ClInclude Include="project\dependencies\gen.basic_types.hpp" />
<ClInclude Include="project\dependencies\gen.containers.hpp" />
<ClInclude Include="project\dependencies\gen.dep.hpp" />
<ClInclude Include="project\dependencies\gen.file_handling.hpp" />
<ClInclude Include="project\dependencies\gen.header_start.hpp" />
<ClInclude Include="project\dependencies\gen.macros.hpp" />
<ClInclude Include="project\dependencies\gen.memory.hpp" />
<ClInclude Include="project\dependencies\gen.parsing.hpp" />
<ClInclude Include="project\dependencies\gen.printing.hpp" />
<ClInclude Include="project\dependencies\gen.string.hpp" />
<ClInclude Include="project\dependencies\gen.string_ops.hpp" />
<ClInclude Include="project\filesystem\gen.builder.hpp" />
<ClInclude Include="project\filesystem\gen.editor.hpp" />
<ClInclude Include="project\filesystem\gen.scanner.hpp" />
<ClInclude Include="project\auxillary\builder.hpp" />
<ClInclude Include="project\auxillary\editor.hpp" />
<ClInclude Include="project\auxillary\scanner.hpp" />
<ClInclude Include="project\components\ast.hpp" />
<ClInclude Include="project\components\ast_types.hpp" />
<ClInclude Include="project\components\code_types.hpp" />
<ClInclude Include="project\components\gen\ast_inlines.hpp" />
<ClInclude Include="project\components\gen\ecode.hpp" />
<ClInclude Include="project\components\gen\eoperator.hpp" />
<ClInclude Include="project\components\gen\especifier.hpp" />
<ClInclude Include="project\components\header_end.hpp" />
<ClInclude Include="project\components\header_start.hpp" />
<ClInclude Include="project\components\inlines.hpp" />
<ClInclude Include="project\components\interface.hpp" />
<ClInclude Include="project\components\types.hpp" />
<ClInclude Include="project\dependencies\basic_types.hpp" />
<ClInclude Include="project\dependencies\containers.hpp" />
<ClInclude Include="project\dependencies\debug.hpp" />
<ClInclude Include="project\dependencies\filesystem.hpp" />
<ClInclude Include="project\dependencies\hashing.hpp" />
<ClInclude Include="project\dependencies\header_start.hpp" />
<ClInclude Include="project\dependencies\macros.hpp" />
<ClInclude Include="project\dependencies\memory.hpp" />
<ClInclude Include="project\dependencies\parsing.hpp" />
<ClInclude Include="project\dependencies\printing.hpp" />
<ClInclude Include="project\dependencies\strings.hpp" />
<ClInclude Include="project\dependencies\string_ops.hpp" />
<ClInclude Include="project\dependencies\timing.hpp" />
<ClInclude Include="project\gen.dep.hpp" />
<ClInclude Include="project\gen.editor.hpp" />
<ClInclude Include="project\gen.hpp" />
<ClInclude Include="project\gen.pop_ignores.inline.hpp" />
<ClInclude Include="project\gen.push_ignores.inline.hpp" />
<ClInclude Include="project\gen.scanner.hpp" />
<ClInclude Include="project\gen.undef.macros.hpp" />
<ClInclude Include="project\helpers\gen.pop_ignores.inline.hpp" />
<ClInclude Include="project\helpers\gen.push_ignores.inline.hpp" />
<ClInclude Include="project\helpers\gen.undef.macros.hpp" />
<ClInclude Include="project\helpers\helper.hpp" />
<ClInclude Include="project\helpers\pop_ignores.inline.hpp" />
<ClInclude Include="project\helpers\push_ignores.inline.hpp" />
<ClInclude Include="project\helpers\undef.macros.hpp" />
<ClInclude Include="singleheader\components\header_start.hpp" />
<ClInclude Include="test\CURSED_TYPEDEF.h" />
<ClInclude Include="test\DummyInclude.hpp" />
<ClInclude Include="test\gen\array.Upfront.gen.hpp" />
<ClInclude Include="test\gen\buffer.Upfront.gen.hpp" />
<ClInclude Include="test\gen\hashtable.Upfront.gen.hpp" />
<ClInclude Include="test\gen\ring.Upfront.gen.hpp" />
<ClInclude Include="test\gen\sanity.Upfront.gen.hpp" />
<ClInclude Include="test\Parsed\Buffer.Parsed.hpp" />
<ClInclude Include="test\Parsed\HashTable.Parsed.hpp" />
<ClInclude Include="test\Parsed\Ring.Parsed.hpp" />
@ -159,31 +309,66 @@
<ClInclude Include="test\Parsed\Sanity.Parsed.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="project\components\gen.ast.cpp" />
<ClCompile Include="project\components\gen.interface.parsing.cpp" />
<ClCompile Include="project\components\gen.interface.upfront.cpp" />
<ClCompile Include="project\dependencies\gen.dep.cpp" />
<ClCompile Include="project\dependencies\gen.file_handling.cpp" />
<ClCompile Include="project\dependencies\gen.memory.cpp" />
<ClCompile Include="project\dependencies\gen.parsing.cpp" />
<ClCompile Include="project\dependencies\gen.printing.cpp" />
<ClCompile Include="project\auxillary\builder.cpp" />
<ClCompile Include="project\auxillary\scanner.cpp" />
<ClCompile Include="project\bootstrap.cpp" />
<ClCompile Include="project\components\ast.cpp" />
<ClCompile Include="project\components\ast_case_macros.cpp" />
<ClCompile Include="project\components\code_serialization.cpp" />
<ClCompile Include="project\components\gen\etoktype.cpp" />
<ClCompile Include="project\components\interface.cpp" />
<ClCompile Include="project\components\interface.parsing.cpp" />
<ClCompile Include="project\components\interface.untyped.cpp" />
<ClCompile Include="project\components\interface.upfront.cpp" />
<ClCompile Include="project\components\lexer.cpp" />
<ClCompile Include="project\components\parser.cpp" />
<ClCompile Include="project\components\src_start.cpp" />
<ClCompile Include="project\components\static_data.cpp" />
<ClCompile Include="project\dependencies\debug.cpp" />
<ClCompile Include="project\dependencies\filesystem.cpp" />
<ClCompile Include="project\dependencies\hashing.cpp" />
<ClCompile Include="project\dependencies\memory.cpp" />
<ClCompile Include="project\dependencies\parsing.cpp" />
<ClCompile Include="project\dependencies\printing.cpp" />
<ClCompile Include="project\dependencies\src_start.cpp" />
<ClCompile Include="project\dependencies\strings.cpp" />
<ClCompile Include="project\dependencies\string_ops.cpp" />
<ClCompile Include="project\dependencies\timing.cpp" />
<ClCompile Include="project\Example.cpp" />
<ClCompile Include="project\gen.cpp" />
<ClCompile Include="project\gen.dep.cpp" />
<ClCompile Include="singleheader\gen\gen.singleheader.cpp" />
<ClCompile Include="test\gen\build\meson-private\sanitycheckc.c" />
<ClCompile Include="test\gen\build\meson-private\sanitycheckcpp.cc" />
<ClCompile Include="singleheader\singleheader.cpp" />
<ClCompile Include="test\parsed\test.parsing.cpp" />
<ClCompile Include="test\parsing.cpp" />
<ClCompile Include="test\sanity.cpp" />
<ClCompile Include="test\SOA.cpp" />
<ClCompile Include="test\test.cpp" />
<ClCompile Include="test\test.parsing.cpp" />
<ClCompile Include="test\test.singleheader_ast.cpp" />
<ClCompile Include="test\test.Upfront.cpp" />
<ClCompile Include="test\upfront.cpp" />
<ClCompile Include="test\upfront\test.upfront.cpp" />
<ClCompile Include="test\validate_bootstrap.cpp" />
<ClCompile Include="test\validate_singleheader.cpp" />
</ItemGroup>
<ItemGroup>
<Natvis Include=".vscode\gencpp.natvis" />
<Natvis Include="scripts\gencpp.natvis" />
</ItemGroup>
<ItemGroup>
<Content Include="project\enums\AttributeTokens.csv" />
<Content Include="project\enums\ECode.csv" />
<Content Include="project\enums\EOperator.csv" />
<Content Include="project\enums\ESpecifier.csv" />
<Content Include="project\enums\ETokType.csv" />
<Content Include="scripts\.clang-format" />
<Content Include="scripts\helpers\devshell.ps1" />
<Content Include="scripts\helpers\target_arch.psm1" />
<Content Include="scripts\refactor.ps1" />
</ItemGroup>
<ItemGroup>
<Folder Include="singleheader\gen\" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -18,18 +18,9 @@
<ClCompile Include="project\gen.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test\gen\build\meson-private\sanitycheckc.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test\gen\build\meson-private\sanitycheckcpp.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test\test.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="singleheader\gen\gen.singleheader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test\test.Upfront.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -51,28 +42,100 @@
<ClCompile Include="test\test.parsing.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\components\gen.ast.cpp">
<ClCompile Include="project\components\ast.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\components\gen.interface.parsing.cpp">
<ClCompile Include="project\components\ast_case_macros.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\components\gen.interface.upfront.cpp">
<ClCompile Include="project\components\interface.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\gen.dep.cpp">
<ClCompile Include="project\components\interface.parsing.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\gen.file_handling.cpp">
<ClCompile Include="project\components\interface.upfront.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\gen.memory.cpp">
<ClCompile Include="project\components\src_start.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\gen.parsing.cpp">
<ClCompile Include="project\components\static_data.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\gen.printing.cpp">
<ClCompile Include="project\bootstrap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\debug.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\filesystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\hashing.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\memory.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\parsing.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\printing.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\src_start.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\string_ops.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\strings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\dependencies\timing.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\auxillary\builder.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\auxillary\scanner.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="singleheader\singleheader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test\test.singleheader_ast.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test\parsed\test.parsing.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test\upfront\test.upfront.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test\validate_singleheader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test\validate_bootstrap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\components\interface.untyped.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\components\gen\etoktype.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\Example.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\components\parser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\components\lexer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="project\components\code_serialization.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
@ -80,27 +143,9 @@
<ClInclude Include="project\gen.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\gen.undef.macros.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\DummyInclude.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\gen\array.Upfront.gen.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\gen\buffer.Upfront.gen.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\gen\hashtable.Upfront.gen.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\gen\ring.Upfront.gen.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\gen\sanity.Upfront.gen.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\Parsed\Buffer.Parsed.hpp">
<Filter>Header Files</Filter>
</ClInclude>
@ -137,82 +182,112 @@
<ClInclude Include="project\gen.dep.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\gen.editor.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\gen.pop_ignores.inline.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\gen.push_ignores.inline.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\gen.scanner.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\parsing.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\upfront.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\components\gen.data_structures.hpp">
<ClInclude Include="project\components\ast.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\components\gen.interface.hpp">
<ClInclude Include="project\components\ast_types.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\components\gen.types.hpp">
<ClInclude Include="project\components\header_end.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\gen.basic_types.hpp">
<ClInclude Include="project\components\header_start.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\gen.containers.hpp">
<ClInclude Include="project\components\inlines.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\gen.dep.hpp">
<ClInclude Include="project\components\interface.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\gen.file_handling.hpp">
<ClInclude Include="project\components\types.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\gen.header_start.hpp">
<ClInclude Include="project\helpers\helper.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\gen.macros.hpp">
<ClInclude Include="project\helpers\pop_ignores.inline.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\gen.memory.hpp">
<ClInclude Include="project\helpers\push_ignores.inline.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\gen.parsing.hpp">
<ClInclude Include="project\helpers\undef.macros.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\gen.printing.hpp">
<ClInclude Include="project\dependencies\basic_types.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\gen.string.hpp">
<ClInclude Include="project\dependencies\containers.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\gen.string_ops.hpp">
<ClInclude Include="project\dependencies\debug.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\filesystem\gen.builder.hpp">
<ClInclude Include="project\dependencies\filesystem.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\filesystem\gen.editor.hpp">
<ClInclude Include="project\dependencies\hashing.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\filesystem\gen.scanner.hpp">
<ClInclude Include="project\dependencies\header_start.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\helpers\gen.pop_ignores.inline.hpp">
<ClInclude Include="project\dependencies\macros.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\helpers\gen.push_ignores.inline.hpp">
<ClInclude Include="project\dependencies\memory.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\helpers\gen.undef.macros.hpp">
<ClInclude Include="project\dependencies\parsing.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\printing.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\string_ops.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\strings.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\dependencies\timing.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\auxillary\builder.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\auxillary\editor.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\auxillary\scanner.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="singleheader\components\header_start.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\components\gen\ast_inlines.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\components\gen\ecode.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\components\gen\eoperator.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\components\gen\especifier.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="test\CURSED_TYPEDEF.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="project\components\code_types.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
@ -222,13 +297,21 @@
<None Include="scripts\build.ci.ps1" />
<None Include="scripts\build.ps1" />
<None Include="scripts\clean.ps1" />
<None Include="scripts\get_sources.ps1" />
<None Include="test\gen\meson.build" />
<None Include="test\meson.build" />
<None Include="test\Readme.md" />
<None Include="scripts\gen.ps1" />
<None Include="scripts\genccp.natstepfilter" />
<None Include="scripts\gencpp.refactor" />
<None Include="project\enums\AttributeTokens.csv" />
<None Include="project\enums\ECode.csv" />
<None Include="project\enums\EOperator.csv" />
<None Include="project\enums\ESpecifier.csv" />
<None Include="project\enums\ETokType.csv" />
<None Include="scripts\helpers\devshell.ps1" />
<None Include="scripts\helpers\target_arch.psm1" />
<None Include="scripts\package_release.ps1" />
<None Include="scripts\refactor.ps1" />
<None Include="scripts\.clang-format" />
</ItemGroup>
<ItemGroup>
<Natvis Include=".vscode\gencpp.natvis" />

View File

@ -3,14 +3,29 @@
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'">
<LocalDebuggerAttach>false</LocalDebuggerAttach>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommand>C:\projects\gencpp\test\gen\build\gencpp.exe</LocalDebuggerCommand>
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'">
<LocalDebuggerAttach>false</LocalDebuggerAttach>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommand>C:\projects\gencpp\test\gen\build\gencpp.exe</LocalDebuggerCommand>
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'">
<LocalDebuggerAttach>false</LocalDebuggerAttach>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'">
<LocalDebuggerAttach>false</LocalDebuggerAttach>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'">
<LocalDebuggerAttach>false</LocalDebuggerAttach>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
</PropertyGroup>
</Project>

View File

@ -1,34 +1,59 @@
# Documentation
The core library is contained within `gen.hpp` and `gen.cpp`.
Things related to the editor and scanner are in their own respective files. (Ex: `gen.scanner.<hpp/cpp>` )
The library is fragmented into a series of headers and source files meant to be scanned in and then generated to a tailored format for the target `gen` files.
Dependencies are within `gen.dep.<hpp/cpp>`
The principal (user) files are `gen.hpp` and `gen.cpp`.
They contain includes for its various components: `components/<component_name>.<hpp/cpp>`
The library is fragmented into a series of headers and sources files meant to be scanned in and then generated to a tailored format for the target
`gen` files.
Dependencies are bundled into `gen.dep.<hpp/cpp>`.
Just like the `gen.<hpp/cpp>` they include their components: `dependencies/<dependency_name>.<hpp/cpp>`
Both libraries use *pre-generated* (self-hosting I guess) version of the library to then generate the latest version of itself.
(sort of a verification that the generated version is equivalent)
Code not making up the core library is located in `auxiliary/<auxiliary_name>.<hpp/cpp>`. These are optional extensions or tools for the library.
The default `gen.bootstrap.cpp` located in the project folder is meant to be produce a standard segmeneted library (WIP), 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.
This will overwrite the existing library implementation in the immediate directory.
Both libraries use *pre-generated* (self-hosting I guess) version of the library to then generate the latest version of itself.
The default `gen.bootstrap.cpp` located in the project folder is meant to be produce a standard segmented library, where the components of the library
have relatively dedicated header and source files. Dependencies included at the top of the file and each header starting with a pragma once.
The output will be in the `project/gen` directory (if the directory does not exist, it will create it).
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]()
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.
* `GEN_DONT_ENFORCE_GEN_TIME_GUARD` : By default, the library ( gen.hpp/ gen.cpp ) expects the macro `GEN_TIME` to be defined, this disables that.
* `GEN_ROLL_OWN_DEPENDENCIES` : Optional override so that user may define the dependencies themselves.
* `GEN_DEFINE_ATTRIBUTE_TOKENS` : Allows user to define their own attribute macros for use in parsing.
* This is auto-generated if using the bootstrap or single-header generation
* *Note: The user will use the `AttributeTokens.csv` when the library is fully self-hosting.*
* `GEN_DEFINE_LIBRARY_CORE_CONSTANTS` : Optional typename codes as they are non-standard to C/C++ and not necessary to library usage
* `GEN_DONT_ENFORCE_GEN_TIME_GUARD` : By default, the library ( gen.hpp/ gen.cpp ) expects the macro `GEN_TIME` to be defined, this disables that.
* `GEN_ENFORCE_STRONG_CODE_TYPES` : Enforces casts to filtered code types.
* `GEN_EXPOSE_BACKEND` : Will expose symbols meant for internal use only.
* `GEN_Define_Attribute_Tokens` : Allows user to define their own attribute macros for use in parsing.
* `GEN_ROLL_OWN_DEPENDENCIES` : Optional override so that user may define the dependencies themselves.
* `GEN_DONT_ALLOW_INVALID_CODE` (Not implemented yet) : Will fail when an invalid code is constructed, parsed, or serialized.
`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...)
## On multi-threading
Currently unsupported. I want the library to be *stable* and *correct*, with the addition of exhausting all basic single-threaded optimizations before I consider multi-threading.
## Extending the library
This library is relatively very small, and can be extended without much hassle.
The convention you'll see used throughout the interface of the library is as follows:
1. Check name or parameters to make sure they are valid for the construction requested
2. Create a code object using `make_code`.
3. Populate immediate fields (Name, Type, ModuleFlags, etc)
4. Populate sub-entires using `add_entry`. If using the default serialization function `to_string`, follow the order at which entires are expected to appear (there is a strong ordering expected).
Names or Content fields are interned strings and thus showed be cached using `get_cached_string` if its desired to preserve that behavior.
`def_operator` is the most sophisticated constructor as it has multiple permutations of definitions that could be created that are not trivial to determine if valid.
The library has its code segmented into component files, use it to help create a derived version without needing to have to rewrite a generated file directly or build on top of the header via composition or inheritance.
The parser is documented under `docs/Parsing.md` and `docs/Parser_Algo.md`.
## A note on compilation and runtime generation speed
The library is designed to be fast to compile and generate code at runtime as fast as resonable possible on a debug build.
Its recommended that your metaprogam be compiled using a single translation unit (unity build).

View File

@ -0,0 +1,59 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# include "builder.hpp"
#endif
Builder Builder::open( char const* path )
{
Builder result;
FileError error = file_open_mode( & result.File, EFileMode_WRITE, path );
if ( error != EFileError_NONE )
{
log_failure( "gen::File::open - Could not open file: %s", path);
return result;
}
result.Buffer = String::make_reserve( GlobalAllocator, Builder_StrBufferReserve );
// log_fmt("$Builder - Opened file: %s\n", result.File.filename );
return result;
}
void Builder::pad_lines( s32 num )
{
Buffer.append( "\n" );
}
void Builder::print( Code code )
{
String str = code->to_string();
// const ssize len = str.length();
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
Buffer.append( str );
}
void Builder::print_fmt( char const* fmt, ... )
{
ssize res;
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
va_list va;
va_start( va, fmt );
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
va_end( va );
// log_fmt( "$%s - print_fmt: %.*s\n", File.filename, res > 80 ? 80 : res, buf );
Buffer.append( buf, res );
}
void Builder::write()
{
b32 result = file_write( & File, Buffer, Buffer.length() );
if ( result == false )
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & File ) );
log_fmt( "Generated: %s\n", File.filename );
file_close( & File );
Buffer.free();
}

View File

@ -0,0 +1,20 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "gen.hpp"
#endif
struct Builder
{
FileInfo File;
String Buffer;
static Builder open( char const* path );
void pad_lines( s32 num );
void print( Code );
void print_fmt( char const* fmt, ... );
void write();
};

View File

@ -0,0 +1,5 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# include "scanner.hpp"
#endif

View File

@ -0,0 +1,160 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "gen.hpp"
#endif
// This is a simple file reader that reads the entire file into memory.
// It has an extra option to skip the first few lines for undesired includes.
// This is done so that includes can be kept in dependency and component files so that intellisense works.
inline
Code scan_file( char const* path )
{
FileInfo file;
FileError error = file_open_mode( & file, EFileMode_READ, path );
if ( error != EFileError_NONE )
{
GEN_FATAL( "scan_file: Could not open: %s", path );
}
ssize fsize = file_size( & file );
if ( fsize <= 0 )
{
GEN_FATAL("scan_file: %s is empty", path );
}
String str = String::make_reserve( GlobalAllocator, fsize );
file_read( & file, str, fsize );
str.get_header().Length = fsize;
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
// Its designed so that the directive should be the first thing in the file.
// Anything that comes before it will also be omitted.
{
#define current (*scanner)
#define matched 0
#define move_fwd() do { ++ scanner; -- left; } while (0)
const StrC directive_start = txt( "ifdef" );
const StrC directive_end = txt( "endif" );
const StrC def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" );
bool found_directive = false;
char const* scanner = str.Data;
s32 left = fsize;
while ( left )
{
// Processing directive.
if ( current == '#' )
{
move_fwd();
while ( left && char_is_space( current ) )
move_fwd();
if ( ! found_directive )
{
if ( left && str_compare( scanner, directive_start.Ptr, directive_start.Len ) == matched )
{
scanner += directive_start.Len;
left -= directive_start.Len;
while ( left && char_is_space( current ) )
move_fwd();
if ( left && str_compare( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
{
scanner += def_intellisense.Len;
left -= def_intellisense.Len;
found_directive = true;
}
}
// Skip to end of line
while ( left && current != '\r' && current != '\n' )
move_fwd();
move_fwd();
if ( left && current == '\n' )
move_fwd();
continue;
}
if ( left && str_compare( scanner, directive_end.Ptr, directive_end.Len ) == matched )
{
scanner += directive_end.Len;
left -= directive_end.Len;
// Skip to end of line
while ( left && current != '\r' && current != '\n' )
move_fwd();
move_fwd();
if ( left && current == '\n' )
move_fwd();
// sptr skip_size = fsize - left;
if ( (scanner + 2) >= ( str.Data + fsize ) )
{
mem_move( str, scanner, left );
str.get_header().Length = left;
break;
}
mem_move( str, scanner, left );
str.get_header().Length = left;
break;
}
}
move_fwd();
}
#undef move_fwd
#undef matched
#undef current
}
file_close( & file );
return untyped_str( str );
}
#if 0
struct CodeFile
{
using namespace Parser;
String FilePath;
TokArray Tokens;
Array<ParseFailure> ParseFailures;
Code CodeRoot;
};
namespace Parser
{
struct ParseFailure
{
String Reason;
Code Node;
};
}
CodeFile scan_file( char const* path )
{
using namespace Parser;
CodeFile
result = {};
result.FilePath = String::make( GlobalAllocator, path );
Code code = scan_file( path );
result.CodeRoot = code;
ParseContext context = parser_get_last_context();
result.Tokens = context.Tokens;
result.ParseFailures = context.Failures;
return result;
}
#endif

346
project/bootstrap.cpp Normal file
View File

@ -0,0 +1,346 @@
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND
#include "gen.cpp"
#include "helpers/push_ignores.inline.hpp"
#include "helpers/helper.hpp"
GEN_NS_BEGIN
#include "dependencies/parsing.cpp"
GEN_NS_END
#include "auxillary/builder.hpp"
#include "auxillary/builder.cpp"
#include "auxillary/scanner.hpp"
using namespace gen;
constexpr char const* generation_notice =
"// This file was generated automatially by gencpp's bootstrap.cpp "
"(See: https://github.com/Ed94/gencpp)\n\n";
#include <cstdlib> // for system()
void format_file( char const* path )
{
String resolved_path = String::make(GlobalAllocator, to_str(path));
String style_arg = String::make(GlobalAllocator, txt("-style=file:"));
style_arg.append("../scripts/.clang-format ");
// Need to execute clang format on the generated file to get it to match the original.
#define clang_format "clang-format "
#define cf_format_inplace "-i "
#define cf_verbose "-verbose "
String command = String::make( GlobalAllocator, clang_format );
command.append( cf_format_inplace );
command.append( cf_verbose );
command.append( style_arg );
command.append( resolved_path );
log_fmt("\tRunning clang-format on file:\n");
system( command );
log_fmt("\tclang-format finished reformatting.\n");
#undef cf_cmd
#undef cf_format_inplace
#undef cf_style
#undef cf_verbse
}
Code dump_to_scratch_and_retireve( Code code )
{
Builder ecode_file_temp = Builder::open("gen/scratch.hpp");
ecode_file_temp.print(code);
ecode_file_temp.write();
format_file("gen/scratch.hpp");
Code result = scan_file( "gen/scratch.hpp" );
remove("gen/scratch.hpp");
return result;
}
int gen_main()
{
gen::init();
Code push_ignores = scan_file( "helpers/push_ignores.inline.hpp" );
Code pop_ignores = scan_file( "helpers/pop_ignores.inline.hpp" );
// gen_dep.hpp
{
Code platform = scan_file( "dependencies/platform.hpp" );
Code macros = scan_file( "dependencies/macros.hpp" );
Code basic_types = scan_file( "dependencies/basic_types.hpp" );
Code debug = scan_file( "dependencies/debug.hpp" );
Code memory = scan_file( "dependencies/memory.hpp" );
Code string_ops = scan_file( "dependencies/string_ops.hpp" );
Code printing = scan_file( "dependencies/printing.hpp" );
Code containers = scan_file( "dependencies/containers.hpp" );
Code hashing = scan_file( "dependencies/hashing.hpp" );
Code strings = scan_file( "dependencies/strings.hpp" );
Code filesystem = scan_file( "dependencies/filesystem.hpp" );
Code timing = scan_file( "dependencies/timing.hpp" );
Builder
header = Builder::open("gen/gen.dep.hpp");
header.print_fmt( generation_notice );
header.print_fmt( "// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)\n" );
header.print( platform );
header.print_fmt( "\nGEN_NS_BEGIN\n" );
header.print( macros );
header.print( basic_types );
header.print( debug );
header.print( memory );
header.print( string_ops );
header.print( printing );
header.print( containers );
header.print( hashing );
header.print( strings );
header.print( filesystem );
header.print( timing );
header.print_fmt( "\nGEN_NS_END\n" );
header.write();
}
// gen_dep.cpp
{
Code src_start = scan_file( "dependencies/src_start.cpp" );
Code debug = scan_file( "dependencies/debug.cpp" );
Code string_ops = scan_file( "dependencies/string_ops.cpp" );
Code printing = scan_file( "dependencies/printing.cpp" );
Code memory = scan_file( "dependencies/memory.cpp" );
Code hashing = scan_file( "dependencies/hashing.cpp" );
Code strings = scan_file( "dependencies/strings.cpp" );
Code filesystem = scan_file( "dependencies/filesystem.cpp" );
Code timing = scan_file( "dependencies/timing.cpp" );
Builder
src = Builder::open( "gen/gen.dep.cpp" );
src.print_fmt( generation_notice );
src.print_fmt( "// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)\n" );
src.print( src_start );
src.print_fmt( "\nGEN_NS_BEGIN\n" );
src.print( debug );
src.print( string_ops );
src.print( printing );
src.print( hashing );
src.print( memory );
src.print( strings );
src.print( filesystem );
src.print( timing );
src.print_fmt( "\nGEN_NS_END\n" );
src.write();
}
CodeBody gen_component_header = def_global_body( args(
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
pragma_once,
def_include(txt("components/types.hpp")),
preprocess_endif,
fmt_newline,
untyped_str( to_str(generation_notice) )
));
// gen.hpp
{
Code header_start = scan_file( "components/header_start.hpp" );
Code types = scan_file( "components/types.hpp" );
Code ast = scan_file( "components/ast.hpp" );
Code ast_types = scan_file( "components/ast_types.hpp" );
Code code_types = scan_file( "components/code_types.hpp" );
Code interface = scan_file( "components/interface.hpp" );
Code inlines = scan_file( "components/inlines.hpp" );
Code header_end = scan_file( "components/header_end.hpp" );
CodeBody ecode = gen_ecode ( "enums/ECode.csv" );
CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" );
CodeBody especifier = gen_especifier( "enums/ESpecifier.csv" );
CodeBody ast_inlines = gen_ast_inlines();
Builder
header = Builder::open( "gen/gen.hpp" );
header.print_fmt( generation_notice );
header.print_fmt( "#pragma once\n\n" );
header.print( push_ignores );
header.print( header_start );
header.print_fmt( "\nGEN_NS_BEGIN\n\n" );
header.print_fmt( "#pragma region Types\n" );
header.print( types );
header.print( fmt_newline);
header.print( dump_to_scratch_and_retireve(ecode) );
header.print( fmt_newline);
header.print( dump_to_scratch_and_retireve(eoperator) );
header.print( fmt_newline);
header.print( dump_to_scratch_and_retireve(especifier) );
header.print( fmt_newline);
header.print_fmt( "#pragma endregion Types\n\n" );
header.print_fmt( "#pragma region AST\n" );
header.print( ast );
header.print( code_types );
header.print( ast_types );
header.print_fmt( "\n#pragma endregion AST\n" );
header.print( interface );
header.print_fmt( "\n#pragma region Inlines\n" );
header.print( inlines );
header.print( fmt_newline );
header.print( dump_to_scratch_and_retireve(ast_inlines) );
header.print( fmt_newline );
header.print_fmt( "#pragma endregion Inlines\n" );
header.print( header_end );
header.print_fmt( "GEN_NS_END\n\n" );
header.print( pop_ignores );
header.write();
Builder
header_ecode = Builder::open( "components/gen/ecode.hpp" );
header_ecode.print( gen_component_header );
header_ecode.print( ecode );
header_ecode.write();
Builder
header_eoperator = Builder::open( "components/gen/eoperator.hpp" );
header_eoperator.print( gen_component_header );
header_eoperator.print( eoperator );
header_eoperator.write();
Builder
header_especifier = Builder::open( "components/gen/especifier.hpp" );
header_especifier.print( gen_component_header );
header_especifier.print( especifier );
header_especifier.write();
Builder
header_ast_inlines = Builder::open( "components/gen/ast_inlines.hpp" );
header_ast_inlines.print( gen_component_header );
header_ast_inlines.print( ast_inlines );
header_ast_inlines.write();
}
// gen.cpp
{
Code src_start = scan_file( "components/src_start.cpp" );
Code static_data = scan_file( "components/static_data.cpp" );
Code ast_case_macros = scan_file( "components/ast_case_macros.cpp" );
Code ast = scan_file( "components/ast.cpp" );
Code code_serialization = scan_file( "components/code_serialization.cpp" );
Code interface = scan_file( "components/interface.cpp" );
Code upfront = scan_file( "components/interface.upfront.cpp" );
Code lexer = scan_file( "components/lexer.cpp" );
Code parser = scan_file( "components/parser.cpp" );
Code parsing_interface = scan_file( "components/interface.parsing.cpp" );
Code untyped = scan_file( "components/interface.untyped.cpp" );
CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" );
CodeNS nspaced_etoktype = def_namespace( name(parser), def_namespace_body( args(etoktype)) );
Builder
src = Builder::open( "gen/gen.cpp" );
src.print_fmt( generation_notice );
src.print( push_ignores );
src.print( src_start );
src.print_fmt( "\nGEN_NS_BEGIN\n");
src.print( static_data );
src.print_fmt( "\n#pragma region AST\n\n" );
src.print( ast_case_macros );
src.print( ast );
src.print( code_serialization );
src.print_fmt( "\n#pragma endregion AST\n" );
src.print_fmt( "\n#pragma region Interface\n" );
src.print( interface );
src.print( upfront );
src.print_fmt( "\n#pragma region Parsing\n\n" );
src.print( dump_to_scratch_and_retireve(nspaced_etoktype) );
src.print( lexer );
src.print( parser );
src.print( parsing_interface );
src.print( untyped );
src.print_fmt( "\n#pragma endregion Parsing\n\n" );
src.print_fmt( "#pragma endregion Interface\n\n" );
src.print_fmt( "GEN_NS_END\n\n");
src.print( pop_ignores );
src.write();
Builder
src_etoktype = Builder::open( "components/gen/etoktype.cpp" );
src_etoktype.print( gen_component_header );
src_etoktype.print( nspaced_etoktype );
src_etoktype.write();
}
// gen_builder.hpp
{
Code builder = scan_file( "auxillary/builder.hpp" );
Builder
header = Builder::open( "gen/gen.builder.hpp" );
header.print_fmt( generation_notice );
header.print_fmt( "#pragma once\n\n" );
header.print( def_include( txt("gen.hpp") ));
header.print_fmt( "\nGEN_NS_BEGIN\n" );
header.print( builder );
header.print_fmt( "GEN_NS_END\n" );
header.write();
}
// gen_builder.cpp
{
Code builder = scan_file( "auxillary/builder.cpp" );
Builder
src = Builder::open( "gen/gen.builder.cpp" );
src.print_fmt( generation_notice );
src.print( def_include( txt("gen.builder.hpp") ) );
src.print_fmt( "\nGEN_NS_BEGIN\n" );
src.print( builder );
src.print_fmt( "\nGEN_NS_END\n" );
src.write();
}
// gen_scanner.hpp
{
Code parsing = scan_file( "dependencies/parsing.hpp" );
Code scanner = scan_file( "auxillary/scanner.hpp" );
Builder
header = Builder::open( "gen/gen.scanner.hpp" );
header.print_fmt( generation_notice );
header.print_fmt( "#pragma once\n\n" );
header.print( def_include( txt("gen.hpp") ) );
header.print_fmt( "\nGEN_NS_BEGIN\n" );
header.print( parsing );
header.print( scanner );
header.print_fmt( "\nGEN_NS_END\n" );
header.write();
}
// gen_scanner.cpp
{
Code parsing = scan_file( "dependencies/parsing.cpp" );
Code scanner = scan_file( "auxillary/scanner.cpp" );
Builder
src = Builder::open( "gen/gen.scanner.cpp" );
src.print_fmt( generation_notice );
src.print( def_include( txt("gen.scanner.hpp") ) );
src.print_fmt( "\nGEN_NS_BEGIN\n" );
src.print( parsing );
// src.print( scanner );
src.print_fmt( "GEN_NS_END\n" );
src.write();
}
gen::deinit();
return 0;
}

1248
project/components/ast.cpp Normal file

File diff suppressed because it is too large Load Diff

460
project/components/ast.hpp Normal file
View File

@ -0,0 +1,460 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "types.hpp"
#include "gen/ecode.hpp"
#include "gen/eoperator.hpp"
#include "gen/especifier.hpp"
#endif
struct AST;
struct AST_Body;
struct AST_Attributes;
struct AST_Comment;
struct AST_Constructor;
// struct AST_BaseClass;
struct AST_Class;
struct AST_Define;
struct AST_Destructor;
struct AST_Enum;
struct AST_Exec;
struct AST_Extern;
struct AST_Include;
struct AST_Friend;
struct AST_Fn;
struct AST_Module;
struct AST_NS;
struct AST_Operator;
struct AST_OpCast;
struct AST_Param;
struct AST_Pragma;
struct AST_PreprocessCond;
struct AST_Specifiers;
#if GEN_EXECUTION_EXPRESSION_SUPPORT
struct AST_Expr;
struct AST_Expr_Assign;
struct AST_Expr_Alignof;
struct AST_Expr_Binary;
struct AST_Expr_CStyleCast;
struct AST_Expr_FunctionalCast;
struct AST_Expr_CppCast;
struct AST_Expr_ProcCall;
struct AST_Expr_Decltype;
struct AST_Expr_Comma; // TODO(Ed) : This is a binary op not sure if it needs its own AST...
struct AST_Expr_AMS; // Access Member Symbol
struct AST_Expr_Sizeof;
struct AST_Expr_Subscript;
struct AST_Expr_Ternary;
struct AST_Expr_UnaryPrefix;
struct AST_Expr_UnaryPostfix;
struct AST_Expr_Element;
struct AST_Stmt;
struct AST_Stmt_Break;
struct AST_Stmt_Case;
struct AST_Stmt_Continue;
struct AST_Stmt_Decl;
struct AST_Stmt_Do;
struct AST_Stmt_Expr; // TODO(Ed) : Is this distinction needed? (Should it be a flag instead?)
struct AST_Stmt_Else;
struct AST_Stmt_If;
struct AST_Stmt_For;
struct AST_Stmt_Goto;
struct AST_Stmt_Label;
struct AST_Stmt_Switch;
struct AST_Stmt_While;
#endif
struct AST_Struct;
struct AST_Template;
struct AST_Type;
struct AST_Typedef;
struct AST_Union;
struct AST_Using;
struct AST_Var;
struct Code;
struct CodeBody;
// These are to offer ease of use and optionally strong type safety for the AST.
struct CodeAttributes;
// struct CodeBaseClass;
struct CodeComment;
struct CodeClass;
struct CodeConstructor;
struct CodeDefine;
struct CodeDestructor;
struct CodeEnum;
struct CodeExec;
struct CodeExtern;
struct CodeInclude;
struct CodeFriend;
struct CodeFn;
struct CodeModule;
struct CodeNS;
struct CodeOperator;
struct CodeOpCast;
struct CodeParam;
struct CodePreprocessCond;
struct CodePragma;
struct CodeSpecifiers;
#if GEN_EXECUTION_EXPRESSION_SUPPORT
struct CodeExpr;
struct CodeExpr_Assign;
struct CodeExpr_Alignof;
struct CodeExpr_Binary;
struct CodeExpr_CStyleCast;
struct CodeExpr_FunctionalCast;
struct CodeExpr_CppCast;
struct CodeExpr_Element;
struct CodeExpr_ProcCall;
struct CodeExpr_Decltype;
struct CodeExpr_Comma;
struct CodeExpr_AMS; // Access Member Symbol
struct CodeExpr_Sizeof;
struct CodeExpr_Subscript;
struct CodeExpr_Ternary;
struct CodeExpr_UnaryPrefix;
struct CodeExpr_UnaryPostfix;
struct CodeStmt;
struct CodeStmt_Break;
struct CodeStmt_Case;
struct CodeStmt_Continue;
struct CodeStmt_Decl;
struct CodeStmt_Do;
struct CodeStmt_Expr;
struct CodeStmt_Else;
struct CodeStmt_If;
struct CodeStmt_For;
struct CodeStmt_Goto;
struct CodeStmt_Label;
struct CodeStmt_Switch;
struct CodeStmt_While;
#endif
struct CodeStruct;
struct CodeTemplate;
struct CodeType;
struct CodeTypedef;
struct CodeUnion;
struct CodeUsing;
struct CodeVar;
namespace parser
{
struct Token;
}
/*
AST* wrapper
- Not constantly have to append the '*' as this is written often..
- Allows for implicit conversion to any of the ASTs (raw or filtered).
*/
struct Code
{
# pragma region Statics
// Used to identify ASTs that should always be duplicated. (Global constant ASTs)
static Code Global;
// Used to identify invalid generated code.
static Code Invalid;
# pragma endregion Statics
# define Using_Code( Typename ) \
char const* debug_str(); \
Code duplicate(); \
bool is_equal( Code other ); \
bool is_valid(); \
void set_global(); \
String to_string(); \
Typename& operator = ( AST* other ); \
Typename& operator = ( Code other ); \
bool operator ==( Code other ); \
bool operator !=( Code other ); \
operator bool();
Using_Code( Code );
template< class Type >
forceinline Type cast()
{
return * rcast( Type*, this );
}
AST* operator ->()
{
return ast;
}
Code& operator ++();
// TODO(Ed) : Remove this overload.
auto& operator*()
{
local_persist thread_local
Code NullRef = { nullptr };
if ( ast == nullptr )
return NullRef;
return *this;
}
AST* ast;
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES
# define operator explicit operator
#endif
operator CodeBody() const;
operator CodeAttributes() const;
// operator CodeBaseClass() const;
operator CodeComment() const;
operator CodeClass() const;
operator CodeConstructor() const;
operator CodeDefine() const;
operator CodeDestructor() const;
operator CodeExec() const;
operator CodeEnum() const;
operator CodeExtern() const;
operator CodeInclude() const;
operator CodeFriend() const;
operator CodeFn() const;
operator CodeModule() const;
operator CodeNS() const;
operator CodeOperator() const;
operator CodeOpCast() const;
operator CodeParam() const;
operator CodePragma() const;
operator CodePreprocessCond() const;
operator CodeSpecifiers() const;
operator CodeStruct() const;
operator CodeTemplate() const;
operator CodeType() const;
operator CodeTypedef() const;
operator CodeUnion() const;
operator CodeUsing() const;
operator CodeVar() const;
#undef operator
};
struct Code_POD
{
AST* ast;
};
static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" );
// Desired width of the AST data structure.
constexpr int const AST_POD_Size = 128;
/*
Simple AST POD with functionality to seralize into C++ syntax.
*/
struct AST
{
# pragma region Member Functions
void append ( AST* other );
char const* debug_str ();
AST* duplicate ();
Code& entry ( u32 idx );
bool has_entries();
bool is_equal ( AST* other );
char const* type_str();
bool validate_body();
String to_string();
neverinline
void to_string( String& result );
template< class Type >
forceinline Type cast()
{
return * this;
}
operator Code();
operator CodeBody();
operator CodeAttributes();
// operator CodeBaseClass();
operator CodeComment();
operator CodeConstructor();
operator CodeDestructor();
operator CodeClass();
operator CodeDefine();
operator CodeEnum();
operator CodeExec();
operator CodeExtern();
operator CodeInclude();
operator CodeFriend();
operator CodeFn();
operator CodeModule();
operator CodeNS();
operator CodeOperator();
operator CodeOpCast();
operator CodeParam();
operator CodePragma();
operator CodePreprocessCond();
operator CodeSpecifiers();
operator CodeStruct();
operator CodeTemplate();
operator CodeType();
operator CodeTypedef();
operator CodeUnion();
operator CodeUsing();
operator CodeVar();
# pragma endregion Member Functions
constexpr static
int ArrSpecs_Cap =
(
AST_POD_Size
- sizeof(AST*) * 3
- sizeof(parser::Token*)
- sizeof(AST*)
- sizeof(StringCached)
- sizeof(CodeT)
- sizeof(ModuleFlag)
- sizeof(int)
)
/ sizeof(int) - 1; // -1 for 4 extra bytes
union {
struct
{
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
AST* Specs; // Destructor, Function, Operator, Typename, Variable
union {
AST* InitializerList; // Constructor
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
AST* ReturnType; // Function, Operator, Typename
AST* UnderlyingType; // Enum, Typedef
AST* ValueType; // Parameter, Variable
};
union {
AST* Macro; // Parameter
AST* BitfieldSize; // Variable (Class/Struct Data Member)
AST* Params; // Constructor, Function, Operator, Template, Typename
};
union {
AST* ArrExpr; // Typename
AST* Body; // Class, Constructor, Destructor, Enum, Friend, Function, Namespace, Struct, Union
AST* Declaration; // Friend, Template
AST* Value; // Parameter, Variable
};
union {
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
AST* SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
AST* PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal)
};
};
StringCached Content; // Attributes, Comment, Execution, Include
struct {
SpecifierT ArrSpecs[ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
};
};
union {
AST* Prev;
AST* Front;
AST* Last;
};
union {
AST* Next;
AST* Back;
};
parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
AST* Parent;
StringCached Name;
CodeT Type;
// CodeFlag CodeFlags;
ModuleFlag ModuleFlags;
union {
b32 IsFunction; // Used by typedef to not serialize the name field.
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
OperatorT Op;
AccessSpec ParentAccess;
s32 NumEntries;
s32 VarConstructorInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression.
};
};
struct AST_POD
{
union {
struct
{
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
AST* Specs; // Destructor, Function, Operator, Typename, Variable
union {
AST* InitializerList; // Constructor
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
AST* ReturnType; // Function, Operator, Typename
AST* UnderlyingType; // Enum, Typedef
AST* ValueType; // Parameter, Variable
};
union {
AST* Macro; // Parameter
AST* BitfieldSize; // Variable (Class/Struct Data Member)
AST* Params; // Constructor, Function, Operator, Template, Typename
};
union {
AST* ArrExpr; // Typename
AST* Body; // Class, Constructr, Destructor, Enum, Friend, Function, Namespace, Struct, Union
AST* Declaration; // Friend, Template
AST* Value; // Parameter, Variable
};
union {
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
AST* SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
AST* PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal)
};
};
StringCached Content; // Attributes, Comment, Execution, Include
struct {
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
};
};
union {
AST* Prev;
AST* Front;
AST* Last;
};
union {
AST* Next;
AST* Back;
};
parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
AST* Parent;
StringCached Name;
CodeT Type;
CodeFlag CodeFlags;
ModuleFlag ModuleFlags;
union {
b32 IsFunction; // Used by typedef to not serialize the name field.
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
OperatorT Op;
AccessSpec ParentAccess;
s32 NumEntries;
s32 VarConstructorInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression.
};
};
struct test {
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
};
constexpr int pls = sizeof(test);
// Its intended for the AST to have equivalent size to its POD.
// All extra functionality within the AST namespace should just be syntatic sugar.
static_assert( sizeof(AST) == sizeof(AST_POD), "ERROR: AST IS NOT POD" );
static_assert( sizeof(AST_POD) == AST_POD_Size, "ERROR: AST POD is not size of AST_POD_Size" );
// Used when the its desired when omission is allowed in a definition.
#define NoCode { nullptr }
#define CodeInvalid (* Code::Invalid.ast) // Uses an implicitly overloaded cast from the AST to the desired code type.

View File

@ -0,0 +1,78 @@
# define GEN_AST_BODY_CLASS_UNALLOWED_TYPES \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Extern_Linkage: \
case Function_Body: \
case Function_Fwd: \
case Global_Body: \
case Namespace: \
case Namespace_Body: \
case Operator: \
case Operator_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:
# define GEN_AST_BODY_STRUCT_UNALLOWED_TYPES GEN_AST_BODY_CLASS_UNALLOWED_TYPES
# define GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES \
case Access_Public: \
case Access_Protected: \
case Access_Private: \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Extern_Linkage: \
case Friend: \
case Function_Body: \
case Function_Fwd: \
case Global_Body: \
case Namespace: \
case Namespace_Body: \
case Operator: \
case Operator_Fwd: \
case Operator_Member: \
case Operator_Member_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:
# define GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES \
case Access_Public: \
case Access_Protected: \
case Access_Private: \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Execution: \
case Friend: \
case Function_Body: \
case Namespace_Body: \
case Operator_Member: \
case Operator_Member_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:
# define GEN_AST_BODY_EXPORT_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
# define GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
# define GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES \
case Access_Public: \
case Access_Protected: \
case Access_Private: \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Execution: \
case Friend: \
case Function_Body: \
case Namespace_Body: \
case Operator_Member: \
case Operator_Member_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,881 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "ast.hpp"
#endif
#pragma region Code Types
struct CodeBody
{
Using_Code( CodeBody );
void append( Code other )
{
raw()->append( other.ast );
}
void append( CodeBody body )
{
for ( Code entry : body )
{
append( entry );
}
}
bool has_entries()
{
return rcast( AST*, ast )->has_entries();
}
void to_string( String& result );
void to_string_export( String& result );
AST* raw()
{
return rcast( AST*, ast );
}
AST_Body* operator->()
{
return ast;
}
operator Code()
{
return * rcast( Code*, this );
}
#pragma region Iterator
Code begin()
{
if ( ast )
return { rcast( AST*, ast)->Front };
return { nullptr };
}
Code end()
{
return { rcast(AST*, ast)->Back->Next };
}
#pragma endregion Iterator
AST_Body* ast;
};
struct CodeClass
{
Using_Code( CodeClass );
void add_interface( CodeType interface );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw()
{
return rcast( AST*, ast );
}
operator Code()
{
return * rcast( Code*, this );
}
AST_Class* operator->()
{
if ( ast == nullptr )
{
log_failure("Attempt to dereference a nullptr");
return nullptr;
}
return ast;
}
AST_Class* ast;
};
struct CodeParam
{
Using_Code( CodeParam );
void append( CodeParam other );
CodeParam get( s32 idx );
bool has_entries();
void to_string( String& result );
AST* raw()
{
return rcast( AST*, ast );
}
AST_Param* operator->()
{
if ( ast == nullptr )
{
log_failure("Attempt to dereference a nullptr!");
return nullptr;
}
return ast;
}
operator Code()
{
return { (AST*)ast };
}
#pragma region Iterator
CodeParam begin()
{
if ( ast )
return { ast };
return { nullptr };
}
CodeParam end()
{
// return { (AST_Param*) rcast( AST*, ast)->Last };
return { nullptr };
}
CodeParam& operator++();
CodeParam operator*()
{
return * this;
}
#pragma endregion Iterator
AST_Param* ast;
};
struct CodeSpecifiers
{
Using_Code( CodeSpecifiers );
bool append( SpecifierT spec )
{
if ( ast == nullptr )
{
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
return false;
}
if ( raw()->NumEntries == AST::ArrSpecs_Cap )
{
log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST::ArrSpecs_Cap );
return false;
}
raw()->ArrSpecs[ raw()->NumEntries ] = spec;
raw()->NumEntries++;
return true;
}
s32 has( SpecifierT spec )
{
for ( s32 idx = 0; idx < raw()->NumEntries; idx++ )
{
if ( raw()->ArrSpecs[ idx ] == spec )
return idx;
}
return -1;
}
void to_string( String& result );
AST* raw()
{
return rcast( AST*, ast );
}
AST_Specifiers* operator->()
{
if ( ast == nullptr )
{
log_failure("Attempt to dereference a nullptr!");
return nullptr;
}
return ast;
}
operator Code()
{
return { (AST*) ast };
}
#pragma region Iterator
SpecifierT* begin()
{
if ( ast )
return & raw()->ArrSpecs[0];
return nullptr;
}
SpecifierT* end()
{
return raw()->ArrSpecs + raw()->NumEntries;
}
#pragma endregion Iterator
AST_Specifiers* ast;
};
struct CodeStruct
{
Using_Code( CodeStruct );
void add_interface( CodeType interface );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw()
{
return rcast( AST*, ast );
}
operator Code()
{
return * rcast( Code*, this );
}
AST_Struct* operator->()
{
if ( ast == nullptr )
{
log_failure("Attempt to dereference a nullptr");
return nullptr;
}
return ast;
}
AST_Struct* ast;
};
#define Define_CodeType( Typename ) \
struct Code##Typename \
{ \
Using_Code( Code ## Typename ); \
AST* raw(); \
operator Code(); \
AST_##Typename* operator->(); \
AST_##Typename* ast; \
}
Define_CodeType( Attributes );
// Define_CodeType( BaseClass );
Define_CodeType( Comment );
struct CodeConstructor
{
Using_Code( CodeConstructor );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw();
operator Code();
AST_Constructor* operator->();
AST_Constructor* ast;
};
struct CodeDefine
{
Using_Code( CodeDefine );
void to_string( String& result );
AST* raw();
operator Code();
AST_Define* operator->();
AST_Define* ast;
};
struct CodeDestructor
{
Using_Code( CodeDestructor );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw();
operator Code();
AST_Destructor* operator->();
AST_Destructor* ast;
};
struct CodeEnum
{
Using_Code( CodeEnum );
void to_string_def( String& result );
void to_string_fwd( String& result );
void to_string_class_def( String& result );
void to_string_class_fwd( String& result );
AST* raw();
operator Code();
AST_Enum* operator->();
AST_Enum* ast;
};
Define_CodeType( Exec );
#if GEN_EXECUTION_EXPRESSION_SUPPORT
struct CodeExpr
{
Using_Code( CodeExpr );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr* operator->();
AST_Expr* ast;
};
struct CodeExpr_Assign
{
Using_Code( CodeExpr_Assign );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_Assign* operator->();
AST_Expr_Assign* ast;
};
struct CodeExpr_Alignof
{
Using_Code( CodeExpr_Alignof );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_Alignof* operator->();
AST_Expr_Alignof* ast;
};
struct CodeExpr_Binary
{
Using_Code( CodeExpr_Binary );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_Binary* operator->();
AST_Expr_Binary* ast;
};
struct CodeExpr_CStyleCast
{
Using_Code( CodeExpr_CStyleCast );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_CStyleCast* operator->();
AST_Expr_CStyleCast* ast;
};
struct CodeExpr_FunctionalCast
{
Using_Code( CodeExpr_FunctionalCast );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_FunctionalCast* operator->();
AST_Expr_FunctionalCast* ast;
};
struct CodeExpr_CppCast
{
Using_Code( CodeExpr_CppCast );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_CppCast* operator->();
AST_Expr_CppCast* ast;
};
struct CodeExpr_Element
{
Using_Code( CodeExpr_Element );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_Element* operator->();
AST_Expr_Element* ast;
};
struct CodeExpr_ProcCall
{
Using_Code( CodeExpr_ProcCall );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_ProcCall* operator->();
AST_Expr_ProcCall* ast;
};
struct CodeExpr_Decltype
{
Using_Code( CodeExpr_Decltype );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_Decltype* operator->();
AST_Expr_Decltype* ast;
};
struct CodeExpr_Comma
{
Using_Code( CodeExpr_Comma );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_Comma* operator->();
AST_Expr_Comma* ast;
};
struct CodeExpr_AMS
{
Using_Code( CodeExpr_AMS );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_AMS* operator->();
AST_Expr_AMS* ast;
};
struct CodeExpr_Sizeof
{
Using_Code( CodeExpr_Sizeof );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_Sizeof* operator->();
AST_Expr_Sizeof* ast;
};
struct CodeExpr_Subscript
{
Using_Code( CodeExpr_Subscript );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_Subscript* operator->();
AST_Expr_Subscript* ast;
};
struct CodeExpr_Ternary
{
Using_Code( CodeExpr_Ternary );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_Ternary* operator->();
AST_Expr_Ternary* ast;
};
struct CodeExpr_UnaryPrefix
{
Using_Code( CodeExpr_UnaryPrefix );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_UnaryPrefix* operator->();
AST_Expr_UnaryPrefix* ast;
};
struct CodeExpr_UnaryPostfix
{
Using_Code( CodeExpr_UnaryPostfix );
void to_string( String& result );
AST* raw();
operator Code();
AST_Expr_UnaryPostfix* operator->();
AST_Expr_UnaryPostfix* ast;
};
#endif
struct CodeExtern
{
Using_Code( CodeExtern );
void to_string( String& result );
AST* raw();
operator Code();
AST_Extern* operator->();
AST_Extern* ast;
};
struct CodeInclude
{
Using_Code( CodeInclude );
void to_string( String& result );
AST* raw();
operator Code();
AST_Include* operator->();
AST_Include* ast;
};
struct CodeFriend
{
Using_Code( CodeFriend );
void to_string( String& result );
AST* raw();
operator Code();
AST_Friend* operator->();
AST_Friend* ast;
};
struct CodeFn
{
Using_Code( CodeFn );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw();
operator Code();
AST_Fn* operator->();
AST_Fn* ast;
};
struct CodeModule
{
Using_Code( CodeModule );
void to_string( String& result );
AST* raw();
operator Code();
AST_Module* operator->();
AST_Module* ast;
};
struct CodeNS
{
Using_Code( CodeNS );
void to_string( String& result );
AST* raw();
operator Code();
AST_NS* operator->();
AST_NS* ast;
};
struct CodeOperator
{
Using_Code( CodeOperator );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw();
operator Code();
AST_Operator* operator->();
AST_Operator* ast;
};
struct CodeOpCast
{
Using_Code( CodeOpCast );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw();
operator Code();
AST_OpCast* operator->();
AST_OpCast* ast;
};
struct CodePragma
{
Using_Code( CodePragma );
void to_string( String& result );
AST* raw();
operator Code();
AST_Pragma* operator->();
AST_Pragma* ast;
};
struct CodePreprocessCond
{
Using_Code( CodePreprocessCond );
void to_string_if( String& result );
void to_string_ifdef( String& result );
void to_string_ifndef( String& result );
void to_string_elif( String& result );
void to_string_else( String& result );
void to_string_endif( String& result );
AST* raw();
operator Code();
AST_PreprocessCond* operator->();
AST_PreprocessCond* ast;
};
#if GEN_EXECUTION_EXPRESSION_SUPPORT
struct CodeStmt
{
Using_Code( CodeStmt );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt* operator->();
AST_Stmt* ast;
};
struct CodeStmt_Break
{
Using_Code( CodeStmt_Break );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_Break* operator->();
AST_Stmt_Break* ast;
};
struct CodeStmt_Case
{
Using_Code( CodeStmt_Case );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_Case* operator->();
AST_Stmt_Case* ast;
};
struct CodeStmt_Continue
{
Using_Code( CodeStmt_Continue );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_Continue* operator->();
AST_Stmt_Continue* ast;
};
struct CodeStmt_Decl
{
Using_Code( CodeStmt_Decl );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_Decl* operator->();
AST_Stmt_Decl* ast;
};
struct CodeStmt_Do
{
Using_Code( CodeStmt_Do );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_Do* operator->();
AST_Stmt_Do* ast;
};
struct CodeStmt_Expr
{
Using_Code( CodeStmt_Expr );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_Expr* operator->();
AST_Stmt_Expr* ast;
};
struct CodeStmt_Else
{
Using_Code( CodeStmt_Else );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_Else* operator->();
AST_Stmt_Else* ast;
};
struct CodeStmt_If
{
Using_Code( CodeStmt_If );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_If* operator->();
AST_Stmt_If* ast;
};
struct CodeStmt_For
{
Using_Code( CodeStmt_For );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_For* operator->();
AST_Stmt_For* ast;
};
struct CodeStmt_Goto
{
Using_Code( CodeStmt_Goto );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_Goto* operator->();
AST_Stmt_Goto* ast;
};
struct CodeStmt_Label
{
Using_Code( CodeStmt_Label );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_Label* operator->();
AST_Stmt_Label* ast;
};
struct CodeStmt_Switch
{
Using_Code( CodeStmt_Switch );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_Switch* operator->();
AST_Stmt_Switch* ast;
};
struct CodeStmt_While
{
Using_Code( CodeStmt_While );
void to_string( String& result );
AST* raw();
operator Code();
AST_Stmt_While* operator->();
AST_Stmt_While* ast;
};
#endif
struct CodeTemplate
{
Using_Code( CodeTemplate );
void to_string( String& result );
AST* raw();
operator Code();
AST_Template* operator->();
AST_Template* ast;
};
struct CodeType
{
Using_Code( CodeType );
void to_string( String& result );
AST* raw();
operator Code();
AST_Type* operator->();
AST_Type* ast;
};
struct CodeTypedef
{
Using_Code( CodeTypedef );
void to_string( String& result );
AST* raw();
operator Code();
AST_Typedef* operator->();
AST_Typedef* ast;
};
struct CodeUnion
{
Using_Code( CodeUnion );
void to_string( String& result );
AST* raw();
operator Code();
AST_Union* operator->();
AST_Union* ast;
};
struct CodeUsing
{
Using_Code( CodeUsing );
void to_string( String& result );
void to_string_ns( String& result );
AST* raw();
operator Code();
AST_Using* operator->();
AST_Using* ast;
};
struct CodeVar
{
Using_Code( CodeVar );
void to_string( String& result );
AST* raw();
operator Code();
AST_Var* operator->();
AST_Var* ast;
};
#undef Define_CodeType
#undef Using_Code
#pragma endregion Code Types

View File

@ -1,830 +0,0 @@
#pragma region AST
Code Code::Global;
Code Code::Invalid;
AST* AST::duplicate()
{
using namespace ECode;
AST* result = make_code().ast;
mem_copy( result, this, sizeof( AST ) );
result->Parent = nullptr;
return result;
}
String AST::to_string()
{
# define ProcessModuleFlags() \
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export )) \
result.append( "export " ); \
\
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Import )) \
result.append( "import " ); \
local_persist thread_local
char SerializationLevel = 0;
#if defined(GEN_BENCHMARK) && defined(GEN_BENCHMARK_SERIALIZATION)
u64 time_start = time_rel_ms();
#endif
// TODO : Need to refactor so that intermeidate strings are freed conviently.
String result = String::make( GlobalAllocator, "" );
switch ( Type )
{
using namespace ECode;
case Invalid:
log_failure("Attempted to serialize invalid code! - %s", Parent ? Parent->debug_str() : Name );
break;
case Untyped:
case Execution:
result.append( Content );
break;
case Comment:
{
static char line[MaxCommentLineLength];
s32 left = Content.length();
s32 index = 0;
do
{
s32 length = 0;
while ( left && Content[index] != '\n' )
{
length++;
left--;
}
str_copy( line, Content, length );
line[length] = '\0';
result.append_fmt( "// %s", line );
}
while ( left--, left > 0 );
}
break;
case Access_Private:
case Access_Protected:
case Access_Public:
result.append( Name );
break;
case PlatformAttributes:
result.append( Content );
case Class:
{
ProcessModuleFlags();
if ( Attributes || ParentType )
{
result.append( "class " );
if ( Attributes )
{
result.append_fmt( "%s ", Attributes->to_string() );
}
if ( ParentType )
{
char const* access_level = to_str( ParentAccess );
result.append_fmt( "%s : %s %s\n{\n%s\n};"
, Name
, access_level
, ParentType->to_string()
, Body->to_string()
);
CodeType interface = Next->cast<CodeType>();
if ( interface )
result.append("\n");
while ( interface )
{
result.append_fmt( ", %s", interface.to_string() );
interface = interface->Next->cast<CodeType>();
}
}
else
{
result.append_fmt( "%s \n{\n%s\n};", Name, Body->to_string() );
}
}
else
{
result.append_fmt( "class %s\n{\n%s\n};", Name, Body->to_string() );
}
}
break;
case Class_Fwd:
{
ProcessModuleFlags();
if ( Attributes )
result.append_fmt( "class %s %s;", Attributes->to_string(), Name );
else result.append_fmt( "class %s;", Name );
}
break;
case Enum:
{
ProcessModuleFlags();
if ( Attributes || UnderlyingType )
{
result.append( "enum " );
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
if ( UnderlyingType )
result.append_fmt( "%s : %s\n{\n%s\n};"
, Name
, UnderlyingType->to_string()
, Body->to_string()
);
else result.append_fmt( "%s\n{\n%s\n};"
, Name
, Body->to_string()
);
}
else result.append_fmt( "enum %s\n{\n%s\n};"
, Name
, Body->to_string()
);
}
break;
case Enum_Fwd:
{
ProcessModuleFlags();
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
result.append_fmt( "enum %s : %s;", Name, UnderlyingType->to_string() );
}
break;
case Enum_Class:
{
ProcessModuleFlags();
if ( Attributes || UnderlyingType )
{
result.append( "enum class " );
if ( Attributes )
{
result.append_fmt( "%s ", Attributes->to_string() );
}
if ( UnderlyingType )
{
result.append_fmt( "%s : %s\n{\n%s\n};"
, Name
, UnderlyingType->to_string()
, Body->to_string()
);
}
else
{
result.append_fmt( "%s\n{\n%s\n};"
, Name
, Body->to_string()
);
}
}
else
{
result.append_fmt( "enum class %s\n{\n%s\n};"
, Body->to_string()
);
}
}
break;
case Enum_Class_Fwd:
{
ProcessModuleFlags();
result.append( "enum class " );
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
result.append_fmt( "%s : %s;", Name, UnderlyingType->to_string() );
}
break;
case Export_Body:
{
result.append_fmt( "export\n{\n" );
Code curr = { this };
s32 left = NumEntries;
while ( left-- )
{
result.append_fmt( "%s\n", curr.to_string() );
++curr;
}
result.append_fmt( "};" );
}
break;
case Extern_Linkage:
result.append_fmt( "extern \"%s\"\n{\n%s\n}"
, Name
, Body->to_string()
);
break;
case Friend:
result.append_fmt( "friend %s", Declaration->to_string() );
if ( result[ result.length() -1 ] != ';' )
result.append( ";" );
break;
case Function:
{
ProcessModuleFlags();
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
if ( Specs )
result.append_fmt( "%s\n", Specs->to_string() );
if ( ReturnType )
result.append_fmt( "%s %s(", ReturnType->to_string(), Name );
else
result.append_fmt( "%s(", Name );
if ( Params )
result.append_fmt( "%s)", Params->to_string() );
else
result.append( "void)" );
if ( Specs )
{
CodeSpecifiers specs = cast<CodeSpecifiers>();
for ( SpecifierT spec : specs )
{
if ( ESpecifier::is_trailing( spec ) )
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
}
}
result.append_fmt( "\n{\n%s\n}"
, Body->to_string()
);
}
break;
case Function_Fwd:
{
ProcessModuleFlags();
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
if ( Specs )
result.append_fmt( "%s\n", Specs->to_string() );
if ( ReturnType )
result.append_fmt( "%s %s(", ReturnType->to_string(), Name );
else
result.append_fmt( "%s(", Name );
if ( Params )
result.append_fmt( "%s)", Params->to_string() );
else
result.append( "void)" );
if ( Specs )
{
CodeSpecifiers specs = cast<CodeSpecifiers>();
for ( SpecifierT spec : specs )
{
if ( ESpecifier::is_trailing( spec ) )
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
}
}
result.append( ";" );
}
break;
case Module:
if (((u32(ModuleFlag::Export) & u32(ModuleFlags)) == u32(ModuleFlag::Export)))
result.append("export ");
if (((u32(ModuleFlag::Import) & u32(ModuleFlags)) == u32(ModuleFlag::Import)))
result.append("import ");
result.append_fmt( "%s;", Name );
break;
case Namespace:
ProcessModuleFlags();
result.append_fmt( "namespace %s\n{\n%s}"
, Name
, Body->to_string()
);
break;
case Operator:
case Operator_Member:
{
ProcessModuleFlags();
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
if ( Attributes )
result.append_fmt( "%s\n", Attributes->to_string() );
if ( ReturnType )
result.append_fmt( "%s %s (", ReturnType->to_string(), Name );
if ( Params )
result.append_fmt( "%s)", Params->to_string() );
else
result.append( "void)" );
if ( Specs )
{
CodeSpecifiers specs = cast<CodeSpecifiers>();
for ( SpecifierT spec : specs )
{
if ( ESpecifier::is_trailing( spec ) )
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
}
}
result.append_fmt( "\n{\n%s\n}"
, Body->to_string()
);
}
break;
case Operator_Fwd:
case Operator_Member_Fwd:
{
ProcessModuleFlags();
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
if ( Specs )
result.append_fmt( "%s", Specs->to_string() );
result.append_fmt( "%s %s (", ReturnType->to_string(), Name );
if ( Params )
result.append_fmt( "%s)", Params->to_string() );
else
result.append_fmt( "void)" );
if ( Specs )
{
CodeSpecifiers specs = cast<CodeSpecifiers>();
for ( SpecifierT spec : specs )
{
if ( ESpecifier::is_trailing( spec ) )
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
}
}
result.append( ";" );
}
break;
case Operator_Cast:
{
if ( Specs )
{
result.append_fmt( "operator %s()" );
CodeSpecifiers specs = cast<CodeSpecifiers>();
for ( SpecifierT spec : specs )
{
if ( ESpecifier::is_trailing( spec ) )
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
}
result.append_fmt( "\n{\n%s\n}", Body->to_string() );
break;
}
result.append_fmt("operator %s()\n{\n%s\n}", ValueType->to_string(), Body->to_string() );
}
break;
case Operator_Cast_Fwd:
if ( Specs )
{
result.append_fmt( "operator %s()" );
CodeSpecifiers specs = cast<CodeSpecifiers>();
for ( SpecifierT spec : specs )
{
if ( ESpecifier::is_trailing( spec ) )
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
}
result.append_fmt( ";", Body->to_string() );
break;
}
result.append_fmt("operator %s();", ValueType->to_string() );
break;
case Parameters:
{
if ( Name )
result.append_fmt( "%s %s", ValueType->to_string(), Name );
else
result.append_fmt( "%s", ValueType->to_string() );
if ( Value )
result.append_fmt( "= %s", Value->to_string() );
if ( NumEntries - 1 > 0)
{
for ( CodeParam param : CodeParam { (AST_Param*) Next } )
{
result.append_fmt( ", %s", param.to_string() );
}
}
}
break;
case Preprocessor_Include:
result.append_fmt( "#include \"%s\"", Name );
break;
case Specifiers:
{
s32 idx = 0;
s32 left = NumEntries;
while ( left-- )
{
if ( ESpecifier::is_trailing( ArrSpecs[idx]) )
{
idx++;
continue;
}
result.append_fmt( "%s ", (char const*)ESpecifier::to_str( ArrSpecs[idx]) );
idx++;
}
}
break;
case Struct:
{
ProcessModuleFlags();
if ( Name == nullptr)
{
result.append( "struct\n{\n%s\n};", Body->to_string() );
break;
}
if ( Attributes || ParentType )
{
result.append( "struct " );
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
if ( ParentType )
{
char const* access_level = to_str( ParentAccess );
result.append_fmt( "%s : %s %s\n{\n%s\n};"
, Name
, access_level
, ParentType->to_string()
, Body->to_string()
);
CodeType interface = Next->cast<CodeType>();
if ( interface )
result.append("\n");
while ( interface )
{
result.append_fmt( ", public %s", interface.to_string() );
interface = interface->Next->cast<CodeType>();
}
}
else
{
if ( Name )
result.append_fmt( "%s \n{\n%s\n};", Name, Body->to_string() );
}
}
else
{
result.append_fmt( "struct %s\n{\n%s\n};", Name, Body->to_string() );
}
}
break;
case Struct_Fwd:
{
ProcessModuleFlags();
if ( Attributes )
result.append_fmt( "struct %s %s;", Attributes->to_string(), Name );
else result.append_fmt( "struct %s;", Name );
}
break;
case Template:
{
ProcessModuleFlags();
result.append_fmt( "template< %s >\n%s", Params->to_string(), Declaration->to_string() );
}
break;
case Typedef:
{
ProcessModuleFlags();
result.append( "typedef ");
result.append_fmt( "%s %s", UnderlyingType->to_string(), Name );
if ( UnderlyingType->Type == Typename && UnderlyingType->ArrExpr )
{
result.append_fmt( "[%s];", UnderlyingType->ArrExpr->to_string() );
}
else
{
result.append( ";" );
}
}
break;
case Typename:
{
if ( Attributes || Specs )
{
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
if ( Specs )
result.append_fmt( "%s %s", Name, Specs->to_string() );
else
result.append_fmt( "%s", Name );
}
else
{
result.append_fmt( "%s", Name );
}
}
break;
case Union:
{
ProcessModuleFlags();
result.append( "union " );
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
if ( Name )
{
result.append_fmt( "%s\n{\n%s\n};"
, Name
, Body->to_string()
);
}
else
{
// Anonymous union
result.append_fmt( "\n{\n%s\n};"
, Body->to_string()
);
}
}
break;
case Using:
{
ProcessModuleFlags();
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
if ( UnderlyingType )
{
result.append_fmt( "using %s = %s", Name, UnderlyingType->to_string() );
if ( UnderlyingType->ArrExpr )
result.append_fmt( "[%s]", UnderlyingType->ArrExpr->to_string() );
result.append( ";" );
}
else
result.append_fmt( "using %s;", Name );
}
break;
case Using_Namespace:
result.append_fmt( "using namespace %s;", Name );
break;
case Variable:
{
ProcessModuleFlags();
if ( Attributes || Specs )
{
if ( Attributes )
result.append_fmt( "%s ", Specs->to_string() );
if ( Specs )
result.append_fmt( "%s\n", Specs->to_string() );
result.append_fmt( "%s %s", ValueType->to_string(), Name );
if ( ValueType->ArrExpr )
result.append_fmt( "[%s]", ValueType->ArrExpr->to_string() );
if ( Value )
result.append_fmt( " = %s", Value->to_string() );
result.append( ";" );
break;
}
if ( UnderlyingType->ArrExpr )
result.append_fmt( "%s %s[%s];", UnderlyingType->to_string(), Name, UnderlyingType->ArrExpr->to_string() );
else
result.append_fmt( "%s %s;", UnderlyingType->to_string(), Name );
}
break;
case Class_Body:
case Enum_Body:
case Extern_Linkage_Body:
case Function_Body:
case Global_Body:
case Namespace_Body:
case Struct_Body:
case Union_Body:
{
Code curr = Front->cast<Code>();
s32 left = NumEntries;
while ( left -- )
{
result.append_fmt( "%s\n", curr.to_string() );
++curr;
}
}
break;
}
#if defined(GEN_BENCHMARK) && defined(GEN_BENCHMARK_SERIALIZATION)
log_fmt("AST::to_string() time taken: %llu for: %s\n", time_rel_ms() - time_start, result );
#endif
return result;
#undef ProcessModuleFlags
}
bool AST::is_equal( AST* other )
{
if ( Type != other->Type )
return false;
switch ( Type )
{
case ECode::Typedef:
case ECode::Typename:
{
if ( Name != other->Name )
return false;
return true;
}
}
if ( Name != other->Name )
return false;
return true;
}
bool AST::validate_body()
{
using namespace ECode;
#define CheckEntries( Unallowed_Types ) \
do \
{ \
for ( Code entry : cast<CodeBody>() ) \
{ \
switch ( entry->Type ) \
{ \
Unallowed_Types \
log_failure( "AST::validate_body: Invalid entry in body %s", entry.debug_str() ); \
return false; \
} \
} \
} \
while (0);
switch ( Type )
{
case Class_Body:
CheckEntries( AST_BODY_CLASS_UNALLOWED_TYPES );
break;
case Enum_Body:
for ( Code entry : cast<CodeBody>() )
{
if ( entry->Type != Untyped )
{
log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %s", entry.debug_str() );
return false;
}
}
break;
case Export_Body:
CheckEntries( AST_BODY_CLASS_UNALLOWED_TYPES );
break;
case Extern_Linkage:
CheckEntries( AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES );
break;
case Function_Body:
CheckEntries( AST_BODY_FUNCTION_UNALLOWED_TYPES );
break;
case Global_Body:
CheckEntries( AST_BODY_GLOBAL_UNALLOWED_TYPES );
break;
case Namespace_Body:
CheckEntries( AST_BODY_NAMESPACE_UNALLOWED_TYPES );
break;
case Struct_Body:
CheckEntries( AST_BODY_STRUCT_UNALLOWED_TYPES );
break;
case Union_Body:
for ( Code entry : Body->cast<CodeBody>() )
{
if ( entry->Type != Untyped )
{
log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %s", entry.debug_str() );
return false;
}
}
break;
default:
log_failure( "AST::validate_body: Invalid this AST does not have a body %s", debug_str() );
return false;
}
return false;
}
#pragma endregion AST

View File

@ -1,81 +0,0 @@
# define AST_BODY_CLASS_UNALLOWED_TYPES \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Extern_Linkage: \
case Function_Body: \
case Function_Fwd: \
case Global_Body: \
case Namespace: \
case Namespace_Body: \
case Operator: \
case Operator_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:
# define AST_BODY_FUNCTION_UNALLOWED_TYPES \
case Access_Public: \
case Access_Protected: \
case Access_Private: \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Extern_Linkage: \
case Friend: \
case Function_Body: \
case Function_Fwd: \
case Global_Body: \
case Namespace: \
case Namespace_Body: \
case Operator: \
case Operator_Fwd: \
case Operator_Member: \
case Operator_Member_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:
# define AST_BODY_GLOBAL_UNALLOWED_TYPES \
case Access_Public: \
case Access_Protected: \
case Access_Private: \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Execution: \
case Friend: \
case Function_Body: \
case Global_Body: \
case Namespace_Body: \
case Operator_Member: \
case Operator_Member_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:
# define AST_BODY_EXPORT_UNALLOWED_TYPES AST_BODY_GLOBAL_UNALLOWED_TYPES
# define AST_BODY_NAMESPACE_UNALLOWED_TYPES \
case Access_Public: \
case Access_Protected: \
case Access_Private: \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Execution: \
case Friend: \
case Function_Body: \
case Namespace_Body: \
case Operator_Member: \
case Operator_Member_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:
# define AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES AST_BODY_GLOBAL_UNALLOWED_TYPES
# define AST_BODY_STRUCT_UNALLOWED_TYPES AST_BODY_CLASS_UNALLOWED_TYPES

File diff suppressed because it is too large Load Diff

View File

@ -1,78 +0,0 @@
// This is the non-bootstraped version of the ECode. This will be obsolete once bootstrap is stress tested.
namespace ECode
{
# define Define_Types \
Entry( Invalid ) \
Entry( Untyped ) \
Entry( Comment ) \
Entry( Access_Private ) \
Entry( Access_Protected ) \
Entry( Access_Public ) \
Entry( PlatformAttributes ) \
Entry( Class ) \
Entry( Class_Fwd ) \
Entry( Class_Body ) \
Entry( Enum ) \
Entry( Enum_Fwd ) \
Entry( Enum_Body ) \
Entry( Enum_Class ) \
Entry( Enum_Class_Fwd ) \
Entry( Execution ) \
Entry( Export_Body ) \
Entry( Extern_Linkage ) \
Entry( Extern_Linkage_Body ) \
Entry( Friend ) \
Entry( Function ) \
Entry( Function_Fwd ) \
Entry( Function_Body ) \
Entry( Global_Body ) \
Entry( Module ) \
Entry( Namespace ) \
Entry( Namespace_Body ) \
Entry( Operator ) \
Entry( Operator_Fwd ) \
Entry( Operator_Member ) \
Entry( Operator_Member_Fwd ) \
Entry( Operator_Cast ) \
Entry( Operator_Cast_Fwd ) \
Entry( Parameters ) \
Entry( Preprocessor_Include ) \
Entry( Specifiers ) \
Entry( Struct ) \
Entry( Struct_Fwd ) \
Entry( Struct_Body ) \
Entry( Template ) \
Entry( Typedef ) \
Entry( Typename ) \
Entry( Union ) \
Entry( Union_Body) \
Entry( Using ) \
Entry( Using_Namespace ) \
Entry( Variable )
enum Type : u32
{
# define Entry( Type ) Type,
Define_Types
# undef Entry
Num_Types
};
inline
StrC to_str( Type type )
{
static
StrC lookup[Num_Types] = {
# define Entry( Type ) { sizeof(stringize(Type)), stringize(Type) },
Define_Types
# undef Entry
};
return lookup[ type ];
}
# undef Define_Types
}
using CodeT = ECode::Type;

View File

@ -1,75 +0,0 @@
// This is the non-bootstraped version of the EOperator. This will be obsolete once bootstrap is stress tested.
namespace EOperator
{
# define Define_Operators \
Entry( Invalid, INVALID ) \
Entry( Assign, = ) \
Entry( Assign_Add, += ) \
Entry( Assign_Subtract, -= ) \
Entry( Assign_Multiply, *= ) \
Entry( Assign_Divide, /= ) \
Entry( Assign_Modulo, %= ) \
Entry( Assign_BAnd, &= ) \
Entry( Assign_BOr, |= ) \
Entry( Assign_BXOr, ^= ) \
Entry( Assign_LShift, <<= ) \
Entry( Assign_RShift, >>= ) \
Entry( Increment, ++ ) \
Entry( Decrement, -- ) \
Entry( Unary_Plus, + ) \
Entry( Unary_Minus, - ) \
Entry( UnaryNot, ! ) \
Entry( Add, + ) \
Entry( Subtract, - ) \
Entry( Multiply, * ) \
Entry( Divide, / ) \
Entry( Modulo, % ) \
Entry( BNot, ~ ) \
Entry( BAnd, & ) \
Entry( BOr, | ) \
Entry( BXOr, ^ ) \
Entry( LShift, << ) \
Entry( RShift, >> ) \
Entry( LAnd, && ) \
Entry( LOr, || ) \
Entry( LEqual, == ) \
Entry( LNot, != ) \
Entry( Lesser, < ) \
Entry( Greater, > ) \
Entry( LesserEqual, <= ) \
Entry( GreaterEqual, >= ) \
Entry( Subscript, [] ) \
Entry( Indirection, * ) \
Entry( AddressOf, & ) \
Entry( MemberOfPointer, -> ) \
Entry( PtrToMemOfPtr, ->* ) \
Entry( FunctionCall, () )
enum Type : u32
{
# define Entry( Type_, Token_ ) Type_,
Define_Operators
# undef Entry
Comma,
Num_Ops,
};
inline
char const* to_str( Type op )
{
local_persist
char const* lookup[ Num_Ops ] = {
# define Entry( Type_, Token_ ) stringize(Token_),
Define_Operators
# undef Entry
","
};
return lookup[ op ];
}
# undef Define_Operators
}
using OperatorT = EOperator::Type;

View File

@ -1,105 +0,0 @@
// This is the non-bootstraped version of the ESpecifier. This will be obsolete once bootstrap is stress tested.
namespace ESpecifier
{
/*
Note: The following are handled separately:
attributes
alignas
*/
# define Define_Specifiers \
Entry( Invalid, INVALID ) \
Entry( Consteval, consteval ) \
Entry( Constexpr, constexpr ) \
Entry( Constinit, constinit ) \
Entry( Explicit, explicit ) \
Entry( External_Linkage, extern ) \
Entry( Global, global ) \
Entry( Inline, inline ) \
Entry( Internal_Linkage, internal ) \
Entry( Local_Persist, local_persist ) \
Entry( Mutable, mutable ) \
Entry( Ptr, * ) \
Entry( Ref, & ) \
Entry( Register, register ) \
Entry( RValue, && ) \
Entry( Static, static ) \
Entry( Thread_Local, thread_local ) \
Entry( Volatile, volatile ) \
Entry( Virtual, virtual ) \
Entry( Const, const ) \
Entry( Final, final ) \
Entry( Override, override )
enum Type : u32
{
# define Entry( Specifier, Code ) Specifier,
Define_Specifiers
# undef Entry
NumSpecifiers,
};
inline
bool is_trailing( Type specifier )
{
return specifier > Virtual;
}
// Specifier to string
inline
StrC to_str( Type specifier )
{
local_persist
StrC lookup[ NumSpecifiers ] = {
# pragma push_macro( "global" )
# pragma push_macro( "internal" )
# pragma push_macro( "local_persist" )
# undef global
# undef internal
# undef local_persist
# define Entry( Spec_, Code_ ) { sizeof(stringize(Code_)), stringize(Code_) },
Define_Specifiers
# undef Entry
# pragma pop_macro( "global" )
# pragma pop_macro( "internal" )
# pragma pop_macro( "local_persist" )
};
return lookup[ specifier ];
}
inline
Type to_type( StrC str )
{
local_persist
u32 keymap[ NumSpecifiers ];
do_once_start
for ( u32 index = 0; index < NumSpecifiers; index++ )
{
StrC enum_str = to_str( (Type)index );
// We subtract 1 to remove the null terminator
// This is because the tokens lexed are not null terminated.
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1);
}
do_once_end
u32 hash = crc32( str.Ptr, str.Len );
for ( u32 index = 0; index < NumSpecifiers; index++ )
{
if ( keymap[index] == hash )
return (Type)index;
}
return Invalid;
}
# undef Define_Specifiers
}
using SpecifierT = ESpecifier::Type;

View File

@ -1,141 +0,0 @@
namespace Parser
{
/*
This is a simple lexer that focuses on tokenizing only tokens relevant to the library.
It will not be capable of lexing C++ code with unsupported features.
For the sake of scanning files, it can scan preprocessor directives
Attributes_Start is only used to indicate the start of the user_defined attribute list.
*/
# define Define_TokType \
Entry( Invalid, "INVALID" ) \
Entry( Access_Private, "private" ) \
Entry( Access_Protected, "protected" ) \
Entry( Access_Public, "public" ) \
Entry( Access_MemberSymbol, "." ) \
Entry( Access_StaticSymbol, "::") \
Entry( Ampersand, "&" ) \
Entry( Ampersand_DBL, "&&" ) \
Entry( Assign_Classifer, ":" ) \
Entry( Attribute_Open, "[[" ) \
Entry( Attribute_Close, "]]" ) \
Entry( BraceCurly_Open, "{" ) \
Entry( BraceCurly_Close, "}" ) \
Entry( BraceSquare_Open, "[" ) \
Entry( BraceSquare_Close, "]" ) \
Entry( Capture_Start, "(" ) \
Entry( Capture_End, ")" ) \
Entry( Comment, "__comment__" ) \
Entry( Char, "__char__" ) \
Entry( Comma, "," ) \
Entry( Decl_Class, "class" ) \
Entry( Decl_GNU_Attribute, "__attribute__" ) \
Entry( Decl_MSVC_Attribute, "__declspec" ) \
Entry( Decl_Enum, "enum" ) \
Entry( Decl_Extern_Linkage, "extern" ) \
Entry( Decl_Friend, "friend" ) \
Entry( Decl_Module, "module" ) \
Entry( Decl_Namespace, "namespace" ) \
Entry( Decl_Operator, "operator" ) \
Entry( Decl_Struct, "struct" ) \
Entry( Decl_Template, "template" ) \
Entry( Decl_Typedef, "typedef" ) \
Entry( Decl_Using, "using" ) \
Entry( Decl_Union, "union" ) \
Entry( Identifier, "__identifier__" ) \
Entry( Module_Import, "import" ) \
Entry( Module_Export, "export" ) \
Entry( Number, "number" ) \
Entry( Operator, "operator" ) \
Entry( Preprocessor_Directive, "#") \
Entry( Preprocessor_Include, "include" ) \
Entry( Spec_Alignas, "alignas" ) \
Entry( Spec_Const, "const" ) \
Entry( Spec_Consteval, "consteval" ) \
Entry( Spec_Constexpr, "constexpr" ) \
Entry( Spec_Constinit, "constinit" ) \
Entry( Spec_Explicit, "explicit" ) \
Entry( Spec_Extern, "extern" ) \
Entry( Spec_Final, "final" ) \
Entry( Spec_Global, "global" ) \
Entry( Spec_Inline, "inline" ) \
Entry( Spec_Internal_Linkage, "internal" ) \
Entry( Spec_LocalPersist, "local_persist" ) \
Entry( Spec_Mutable, "mutable" ) \
Entry( Spec_Override, "override" ) \
Entry( Spec_Static, "static" ) \
Entry( Spec_ThreadLocal, "thread_local" ) \
Entry( Spec_Volatile, "volatile") \
Entry( Star, "*" ) \
Entry( Statement_End, ";" ) \
Entry( String, "__string__" ) \
Entry( Type_Unsigned, "unsigned" ) \
Entry( Type_Signed, "signed" ) \
Entry( Type_Short, "short" ) \
Entry( Type_Long, "long" ) \
Entry( Type_char, "char" ) \
Entry( Type_int, "int" ) \
Entry( Type_double, "double" ) \
Entry( Varadic_Argument, "..." ) \
Entry( Attributes_Start, "__attrib_start__" )
namespace ETokType
{
enum Type : u32
{
# define Entry( Name_, Str_ ) Name_,
Define_TokType
GEN_Define_Attribute_Tokens
# undef Entry
NumTokens,
};
internal inline
Type to_type( StrC str_tok )
{
local_persist
StrC lookup[(u32)NumTokens] =
{
# define Entry( Name_, Str_ ) { sizeof(Str_), Str_ },
Define_TokType
GEN_Define_Attribute_Tokens
# undef Entry
};
for ( u32 index = 0; index < (u32)NumTokens; index++ )
{
s32 lookup_len = lookup[index].Len - 1;
char const* lookup_str = lookup[index].Ptr;
if ( lookup_len != str_tok.Len )
continue;
if ( str_compare( str_tok.Ptr, lookup_str, lookup_len ) == 0 )
return scast(Type, index);
}
return Invalid;
}
internal inline
char const* to_str( Type type )
{
local_persist
char const* lookup[(u32)NumTokens] =
{
# define Entry( Name_, Str_ ) Str_,
Define_TokType
GEN_Define_Attribute_Tokens
# undef Entry
};
return lookup[(u32)type];
}
# undef Define_TokType
};
using TokType = ETokType::Type;
} // Parser

View File

@ -1,520 +0,0 @@
#pragma region Inlines
void AST::append( AST* other )
{
if ( other->Parent )
other = other->duplicate();
other->Parent = this;
if ( Front == nullptr )
{
Front = other;
Back = other;
NumEntries++;
return;
}
AST*
Current = Back;
Current->Next = other;
other->Prev = Current;
Back = other;
NumEntries++;
}
char const* AST::debug_str()
{
char const* fmt = stringize(
\nCode Debug:
\nType : %s
\nParent : %s
\nName : %s
\nComment : %s
);
// These should be used immediately in a log.
// Thus if its desired to keep the debug str
// for multiple calls to bprintf,
// allocate this to proper string.
return str_fmt_buf( fmt
, type_str()
, Parent ? Parent->Name : ""
, Name ? Name : ""
);
}
Code& AST::entry( u32 idx )
{
AST** current = & Front;
while ( idx >= 0 && current != nullptr )
{
if ( idx == 0 )
return * rcast( Code*, current);
current = & ( * current )->Next;
idx--;
}
return * rcast( Code*, current);
}
bool AST::has_entries()
{
return NumEntries;
}
char const* AST::type_str()
{
return ECode::to_str( Type );
}
AST::operator Code()
{
return { this };
}
Code& Code::operator ++()
{
if ( ast )
ast = ast->Next;
return *this;
}
#pragma region AST & Code Gen Common
#define Define_CodeImpl( Typename ) \
char const* Typename::debug_str() \
{ \
if ( ast == nullptr ) \
return "Code::debug_str: AST is null!"; \
\
return rcast(AST*, ast)->debug_str(); \
} \
Code Typename::duplicate() \
{ \
if ( ast == nullptr ) \
{ \
log_failure("Code::duplicate: Cannot duplicate code, AST is null!"); \
return Code::Invalid; \
} \
\
return { rcast(AST*, ast)->duplicate() }; \
} \
bool Typename::is_equal( Code other ) \
{ \
if ( ast == nullptr || other.ast == nullptr ) \
{ \
log_failure("Code::is_equal: Cannot compare code, AST is null!"); \
return false; \
} \
\
return rcast(AST*, ast)->is_equal( other.ast ); \
} \
bool Typename::is_valid() \
{ \
return (AST*) ast != nullptr && rcast( AST*, ast)->Type != CodeT::Invalid; \
} \
void Typename::set_global() \
{ \
if ( ast == nullptr ) \
{ \
log_failure("Code::set_global: Cannot set code as global, AST is null!"); \
return; \
} \
\
rcast(AST*, ast)->Parent = Code::Global.ast; \
} \
String Typename::to_string() \
{ \
if ( ast == nullptr ) \
{ \
log_failure("Code::to_string: Cannot convert code to string, AST is null!"); \
return { nullptr }; \
} \
\
return rcast(AST*, ast)->to_string(); \
} \
Typename& Typename::operator =( Code other ) \
{ \
if ( other.ast && other->Parent ) \
{ \
ast = rcast( decltype(ast), other.ast->duplicate() ); \
rcast( AST*, ast)->Parent = nullptr; \
} \
\
ast = rcast( decltype(ast), other.ast ); \
return *this; \
} \
bool Typename::operator ==( Code other ) \
{ \
return (AST*) ast == other.ast; \
} \
bool Typename::operator !=( Code other ) \
{ \
return (AST*) ast != other.ast; \
}
Define_CodeImpl( Code );
Define_CodeImpl( CodeBody );
Define_CodeImpl( CodeAttributes );
Define_CodeImpl( CodeComment );
Define_CodeImpl( CodeClass );
Define_CodeImpl( CodeEnum );
Define_CodeImpl( CodeExec );
Define_CodeImpl( CodeExtern );
Define_CodeImpl( CodeInclude );
Define_CodeImpl( CodeFriend );
Define_CodeImpl( CodeFn );
Define_CodeImpl( CodeModule );
Define_CodeImpl( CodeNamespace );
Define_CodeImpl( CodeOperator );
Define_CodeImpl( CodeOpCast );
Define_CodeImpl( CodeParam );
Define_CodeImpl( CodeSpecifiers );
Define_CodeImpl( CodeStruct );
Define_CodeImpl( CodeTemplate );
Define_CodeImpl( CodeType );
Define_CodeImpl( CodeTypedef );
Define_CodeImpl( CodeUnion );
Define_CodeImpl( CodeUsing );
Define_CodeImpl( CodeVar );
#undef Define_CodeImpl
#define Define_AST_Cast( typename ) \
AST::operator Code ## typename() \
{ \
return { rcast( AST_ ## typename*, this ) }; \
}
Define_AST_Cast( Body );
Define_AST_Cast( Attributes );
Define_AST_Cast( Comment );
Define_AST_Cast( Class );
Define_AST_Cast( Enum );
Define_AST_Cast( Exec );
Define_AST_Cast( Extern );
Define_AST_Cast( Include );
Define_AST_Cast( Friend );
Define_AST_Cast( Fn );
Define_AST_Cast( Module );
Define_AST_Cast( Namespace );
Define_AST_Cast( Operator );
Define_AST_Cast( OpCast );
Define_AST_Cast( Param );
Define_AST_Cast( Struct );
Define_AST_Cast( Specifiers );
Define_AST_Cast( Template );
Define_AST_Cast( Type );
Define_AST_Cast( Typedef );
Define_AST_Cast( Union );
Define_AST_Cast( Using );
Define_AST_Cast( Var );
#undef Define_AST_Cast
#define Define_CodeCast( type ) \
Code::operator Code ## type() const \
{ \
return { (AST_ ## type*) ast }; \
}
Define_CodeCast( Attributes );
Define_CodeCast( Comment );
Define_CodeCast( Class );
Define_CodeCast( Exec );
Define_CodeCast( Enum );
Define_CodeCast( Extern );
Define_CodeCast( Include );
Define_CodeCast( Friend );
Define_CodeCast( Fn );
Define_CodeCast( Module );
Define_CodeCast( Namespace );
Define_CodeCast( Operator );
Define_CodeCast( OpCast );
Define_CodeCast( Param );
Define_CodeCast( Specifiers );
Define_CodeCast( Struct );
Define_CodeCast( Template );
Define_CodeCast( Type );
Define_CodeCast( Typedef );
Define_CodeCast( Union );
Define_CodeCast( Using );
Define_CodeCast( Var );
Define_CodeCast( Body);
#undef Define_CodeCast
#pragma endregion AST & Code Gen Common
void CodeClass::add_interface( CodeType type )
{
if ( ! ast->Next )
{
ast->Next = type;
ast->Last = ast->Next;
return;
}
ast->Next->Next = type;
ast->Last = ast->Next->Next;
}
void CodeParam::append( CodeParam other )
{
AST* self = (AST*) ast;
AST* entry = (AST*) other.ast;
if ( entry->Parent )
entry = entry->duplicate();
entry->Parent = self;
if ( self->Last == nullptr )
{
self->Last = entry;
self->Next = entry;
self->NumEntries++;
return;
}
self->Last->Next = entry;
self->Last = entry;
self->NumEntries++;
}
CodeParam CodeParam::get( s32 idx )
{
CodeParam param = *this;
do
{
if ( ! ++ param )
return { nullptr };
return { (AST_Param*) param.raw()->Next };
}
while ( --idx );
return { nullptr };
}
bool CodeParam::has_entries()
{
return ast->NumEntries > 0;
}
CodeParam& CodeParam::operator ++()
{
ast = ast->Next.ast;
return * this;
}
void CodeStruct::add_interface( CodeType type )
{
if ( ! ast->Next )
{
ast->Next = type;
ast->Last = ast->Next;
}
ast->Next->Next = type;
ast->Last = ast->Next->Next;
}
CodeBody def_body( CodeT type )
{
switch ( type )
{
using namespace ECode;
case Class_Body:
case Enum_Body:
case Export_Body:
case Extern_Linkage:
case Function_Body:
case Global_Body:
case Namespace_Body:
case Struct_Body:
case Union_Body:
break;
default:
log_failure( "def_body: Invalid type %s", (char const*)ECode::to_str(type) );
return (CodeBody)Code::Invalid;
}
Code
result = make_code();
result->Type = type;
return (CodeBody)result;
}
//! Do not use directly. Use the token_fmt macro instead.
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
StrC token_fmt_impl( sw num, ... )
{
local_persist thread_local
char buf[GEN_PRINTF_MAXLEN] = { 0 };
mem_set( buf, 0, GEN_PRINTF_MAXLEN );
va_list va;
va_start(va, num );
sw result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
va_end(va);
return { result, buf };
}
#pragma endregion Inlines
#pragma region Constants
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
// Predefined typename codes. Are set to readonly and are setup during gen::init()
extern CodeType t_b32;
extern CodeType t_s8;
extern CodeType t_s16;
extern CodeType t_s32;
extern CodeType t_s64;
extern CodeType t_u8;
extern CodeType t_u16;
extern CodeType t_u32;
extern CodeType t_u64;
extern CodeType t_sw;
extern CodeType t_uw;
extern CodeType t_f32;
extern CodeType t_f64;
#endif
#ifndef GEN_GLOBAL_BUCKET_SIZE
# define GEN_GLOBAL_BUCKET_SIZE megabytes(10)
#endif
#ifndef GEN_CODEPOOL_NUM_BLOCKS
# define GEN_CODEPOOL_NUM_BLOCKS kilobytes(64)
#endif
#ifndef GEN_SIZE_PER_STRING_ARENA
# define GEN_SIZE_PER_STRING_ARENA megabytes(1)
#endif
#ifndef GEN_MAX_COMMENT_LINE_LENGTH
# define GEN_MAX_COMMENT_LINE_LENGTH 1024
#endif
#ifndef GEN_MAX_NAME_LENGTH
# define GEN_MAX_NAME_LENGTH 128
#endif
#ifndef GEN_MAX_UNTYPED_STR_LENGTH
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
#endif
#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(4)
#endif
#ifndef GEN_LEX_ALLOCATOR_SIZE
# define GEN_LEX_ALLOCATOR_SIZE megabytes(10)
#endif
#ifndef GEN_BUILDER_STR_BUFFER_RESERVE
# define GEN_BUILDER_STR_BUFFER_RESERVE megabytes(1)
#endif
// These constexprs are used for allocation behavior of data structures
// or string handling while constructing or serializing.
// Change them to suit your needs.
constexpr s32 InitSize_DataArrays = 16;
// NOTE: This limits the maximum size of an allocation
// If you are generating a string larger than this, increase the size of the bucket here.
constexpr uw Global_BucketSize = GEN_GLOBAL_BUCKET_SIZE;
constexpr s32 CodePool_NumBlocks = GEN_CODEPOOL_NUM_BLOCKS;
constexpr s32 SizePer_StringArena = GEN_SIZE_PER_STRING_ARENA;
constexpr s32 MaxCommentLineLength = GEN_MAX_COMMENT_LINE_LENGTH;
constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH;
constexpr s32 MaxUntypedStrLength = GEN_MAX_UNTYPED_STR_LENGTH;
constexpr s32 TokenFmt_TokenMap_MemSize = GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE;
constexpr s32 LexAllocator_Size = GEN_LEX_ALLOCATOR_SIZE;
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
extern CodeType t_empty; // Used with varaidc parameters. (Exposing just in case its useful for another circumstance)
extern CodeType t_auto;
extern CodeType t_void;
extern CodeType t_int;
extern CodeType t_bool;
extern CodeType t_char;
extern CodeType t_wchar_t;
extern CodeType t_class;
extern CodeType t_typename;
extern CodeParam param_varadic;
extern CodeAttributes attrib_api_export;
extern CodeAttributes attrib_api_import;
extern Code access_public;
extern Code access_protected;
extern Code access_private;
extern Code module_global_fragment;
extern Code module_private_fragment;
extern Code pragma_once;
extern CodeSpecifiers spec_const;
extern CodeSpecifiers spec_consteval;
extern CodeSpecifiers spec_constexpr;
extern CodeSpecifiers spec_constinit;
extern CodeSpecifiers spec_extern_linkage;
extern CodeSpecifiers spec_final;
extern CodeSpecifiers spec_global;
extern CodeSpecifiers spec_inline;
extern CodeSpecifiers spec_internal_linkage;
extern CodeSpecifiers spec_local_persist;
extern CodeSpecifiers spec_mutable;
extern CodeSpecifiers spec_override;
extern CodeSpecifiers spec_ptr;
extern CodeSpecifiers spec_ref;
extern CodeSpecifiers spec_register;
extern CodeSpecifiers spec_rvalue;
extern CodeSpecifiers spec_static_member;
extern CodeSpecifiers spec_thread_local;
extern CodeSpecifiers spec_virtual;
extern CodeSpecifiers spec_volatile;
#pragma endregion Constants
#pragma region Macros
# define gen_main main
# define __ NoCode
// Convienence for defining any name used with the gen api.
// Lets you provide the length and string literal to the functions without the need for the DSL.
# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
// Same as name just used to indicate intention of literal for code instead of names.
# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
# define code_str( ... ) gen::untyped_str( code( __VA_ARGS__ ) )
# define code_fmt( ... ) gen::untyped_str( token_fmt( __VA_ARGS__ ) )
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
# define token_fmt( ... ) gen::token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
#pragma endregion Macros
#ifdef GEN_EXPOSE_BACKEND
// Global allocator used for data with process lifetime.
extern AllocatorInfo GlobalAllocator;
extern Array< Arena > Global_AllocatorBuckets;
extern Array< Pool > CodePools;
extern Array< Arena > StringArenas;
extern StringTable StringCache;
extern Arena LexArena;
extern AllocatorInfo Allocator_DataArrays;
extern AllocatorInfo Allocator_CodePool;
extern AllocatorInfo Allocator_Lexer;
extern AllocatorInfo Allocator_StringArena;
extern AllocatorInfo Allocator_StringTable;
extern AllocatorInfo Allocator_TypeTable;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,109 +0,0 @@
using LogFailType = sw(*)(char const*, ...);
// By default this library will either crash or exit if an error is detected while generating codes.
// Even if set to not use fatal, fatal will still be used for memory failures as the library is unusable when they occur.
#ifdef GEN_DONT_USE_FATAL
constexpr LogFailType log_failure = log_fmt;
#else
constexpr LogFailType log_failure = fatal;
#endif
// Used to indicate if enum definitoin is an enum class or regular enum.
enum class EnumT : u8
{
Regular,
Class
};
constexpr EnumT EnumClass = EnumT::Class;
constexpr EnumT EnumRegular = EnumT::Regular;
enum class AccessSpec : u32
{
Default,
Public,
Protected,
Private,
Num_AccessSpec,
Invalid,
};
inline
char const* to_str( AccessSpec type )
{
local_persist
char const* lookup[ (u32)AccessSpec::Num_AccessSpec ] = {
"",
"public",
"protected",
"private",
};
if ( type > AccessSpec::Public )
return "Invalid";
return lookup[ (u32)type ];
}
enum class ModuleFlag : u32
{
None = 0,
Export = bit(0),
Import = bit(1),
// Private = bit(2),
Num_ModuleFlags,
Invalid,
};
ModuleFlag operator|( ModuleFlag A, ModuleFlag B)
{
return (ModuleFlag)( (u32)A | (u32)B );
}
/*
Predefined attributes
Used for the parser constructors to identify non-standard attributes
Override these to change the attribute to your own unique identifier convention.
The tokenizer identifies attribute defines with the GEN_Define_Attribute_Tokens macros.
See the example below and the Define_TokType macro used in gen.cpp to know the format.
While the library can parse raw attributes, most projects use defines to wrap them for compiler
platform indendence. The token define allows support for them without having to modify the library.
*/
#if defined(GEN_SYSTEM_WINDOWS) || defined( __CYGWIN__ )
#ifndef GEN_Attribute_Keyword
# define GEN_API_Export_Code __declspec(dllexport)
# define GEN_API_Import_Code __declspec(dllimport)
# define GEN_Attribute_Keyword __declspec
#endif
constexpr char const* Attribute_Keyword = stringize( GEN_Attribute_Keyword);
#elif GEN_HAS_ATTRIBUTE( visibility ) || GEN_GCC_VERSION_CHECK( 3, 3, 0 )
#ifndef GEN_Attribute_Keyword
# define GEN_API_Export_Code __attribute__ ((visibility ("default")))
# define GEN_API_Import_Code __attribute__ ((visibility ("default")))
# define GEN_Attribute_Keyword __attribute__
#endif
constexpr char const* Attribute_Keyword = stringize( GEN_Attribute_Keyword );
#else
#ifndef GEN_Attribute_Keyword
# define GEN_API_Export_Code
# define GEN_API_Import_Code
# define GEN_Attribute_Keyword
#endif
constexpr char const* Attribute_Keyword = "";
#endif
#ifndef GEN_Define_Attribute_Tokens
# define GEN_Define_Attribute_Tokens \
Entry( API_Export, "GEN_API_Export_Code" ) \
Entry( API_Import, "GEN_API_Import_Code" )
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,144 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "components/types.hpp"
#endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
namespace ECode
{
enum Type : u32
{
Invalid,
Untyped,
NewLine,
Comment,
Access_Private,
Access_Protected,
Access_Public,
PlatformAttributes,
Class,
Class_Fwd,
Class_Body,
Constructor,
Constructor_Fwd,
Destructor,
Destructor_Fwd,
Enum,
Enum_Fwd,
Enum_Body,
Enum_Class,
Enum_Class_Fwd,
Execution,
Export_Body,
Extern_Linkage,
Extern_Linkage_Body,
Friend,
Function,
Function_Fwd,
Function_Body,
Global_Body,
Module,
Namespace,
Namespace_Body,
Operator,
Operator_Fwd,
Operator_Member,
Operator_Member_Fwd,
Operator_Cast,
Operator_Cast_Fwd,
Parameters,
Preprocess_Define,
Preprocess_Include,
Preprocess_If,
Preprocess_IfDef,
Preprocess_IfNotDef,
Preprocess_ElIf,
Preprocess_Else,
Preprocess_EndIf,
Preprocess_Pragma,
Specifiers,
Struct,
Struct_Fwd,
Struct_Body,
Template,
Typedef,
Typename,
Union,
Union_Body,
Using,
Using_Namespace,
Variable,
NumTypes
};
inline StrC to_str( Type type )
{
local_persist StrC lookup[] {
{ sizeof( "Invalid" ), "Invalid" },
{ sizeof( "Untyped" ), "Untyped" },
{ sizeof( "NewLine" ), "NewLine" },
{ sizeof( "Comment" ), "Comment" },
{ sizeof( "Access_Private" ), "Access_Private" },
{ sizeof( "Access_Protected" ), "Access_Protected" },
{ sizeof( "Access_Public" ), "Access_Public" },
{ sizeof( "PlatformAttributes" ), "PlatformAttributes" },
{ sizeof( "Class" ), "Class" },
{ sizeof( "Class_Fwd" ), "Class_Fwd" },
{ sizeof( "Class_Body" ), "Class_Body" },
{ sizeof( "Constructor" ), "Constructor" },
{ sizeof( "Constructor_Fwd" ), "Constructor_Fwd" },
{ sizeof( "Destructor" ), "Destructor" },
{ sizeof( "Destructor_Fwd" ), "Destructor_Fwd" },
{ sizeof( "Enum" ), "Enum" },
{ sizeof( "Enum_Fwd" ), "Enum_Fwd" },
{ sizeof( "Enum_Body" ), "Enum_Body" },
{ sizeof( "Enum_Class" ), "Enum_Class" },
{ sizeof( "Enum_Class_Fwd" ), "Enum_Class_Fwd" },
{ sizeof( "Execution" ), "Execution" },
{ sizeof( "Export_Body" ), "Export_Body" },
{ sizeof( "Extern_Linkage" ), "Extern_Linkage" },
{ sizeof( "Extern_Linkage_Body" ), "Extern_Linkage_Body" },
{ sizeof( "Friend" ), "Friend" },
{ sizeof( "Function" ), "Function" },
{ sizeof( "Function_Fwd" ), "Function_Fwd" },
{ sizeof( "Function_Body" ), "Function_Body" },
{ sizeof( "Global_Body" ), "Global_Body" },
{ sizeof( "Module" ), "Module" },
{ sizeof( "Namespace" ), "Namespace" },
{ sizeof( "Namespace_Body" ), "Namespace_Body" },
{ sizeof( "Operator" ), "Operator" },
{ sizeof( "Operator_Fwd" ), "Operator_Fwd" },
{ sizeof( "Operator_Member" ), "Operator_Member" },
{ sizeof( "Operator_Member_Fwd" ), "Operator_Member_Fwd" },
{ sizeof( "Operator_Cast" ), "Operator_Cast" },
{ sizeof( "Operator_Cast_Fwd" ), "Operator_Cast_Fwd" },
{ sizeof( "Parameters" ), "Parameters" },
{ sizeof( "Preprocess_Define" ), "Preprocess_Define" },
{ sizeof( "Preprocess_Include" ), "Preprocess_Include" },
{ sizeof( "Preprocess_If" ), "Preprocess_If" },
{ sizeof( "Preprocess_IfDef" ), "Preprocess_IfDef" },
{ sizeof( "Preprocess_IfNotDef" ), "Preprocess_IfNotDef" },
{ sizeof( "Preprocess_ElIf" ), "Preprocess_ElIf" },
{ sizeof( "Preprocess_Else" ), "Preprocess_Else" },
{ sizeof( "Preprocess_EndIf" ), "Preprocess_EndIf" },
{ sizeof( "Preprocess_Pragma" ), "Preprocess_Pragma" },
{ sizeof( "Specifiers" ), "Specifiers" },
{ sizeof( "Struct" ), "Struct" },
{ sizeof( "Struct_Fwd" ), "Struct_Fwd" },
{ sizeof( "Struct_Body" ), "Struct_Body" },
{ sizeof( "Template" ), "Template" },
{ sizeof( "Typedef" ), "Typedef" },
{ sizeof( "Typename" ), "Typename" },
{ sizeof( "Union" ), "Union" },
{ sizeof( "Union_Body" ), "Union_Body" },
{ sizeof( "Using" ), "Using" },
{ sizeof( "Using_Namespace" ), "Using_Namespace" },
{ sizeof( "Variable" ), "Variable" },
};
return lookup[type];
}
} // namespace ECode
using CodeT = ECode::Type;

View File

@ -0,0 +1,118 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "components/types.hpp"
#endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
namespace EOperator
{
enum Type : u32
{
Invalid,
Assign,
Assign_Add,
Assign_Subtract,
Assign_Multiply,
Assign_Divide,
Assign_Modulo,
Assign_BAnd,
Assign_BOr,
Assign_BXOr,
Assign_LShift,
Assign_RShift,
Increment,
Decrement,
Unary_Plus,
Unary_Minus,
UnaryNot,
Add,
Subtract,
Multiply,
Divide,
Modulo,
BNot,
BAnd,
BOr,
BXOr,
LShift,
RShift,
LAnd,
LOr,
LEqual,
LNot,
Lesser,
Greater,
LesserEqual,
GreaterEqual,
Subscript,
Indirection,
AddressOf,
MemberOfPointer,
PtrToMemOfPtr,
FunctionCall,
Comma,
New,
NewArray,
Delete,
DeleteArray,
NumOps
};
inline StrC to_str( Type op )
{
local_persist StrC lookup[] {
{ sizeof( "INVALID" ), "INVALID" },
{ sizeof( "=" ), "=" },
{ sizeof( "+=" ), "+=" },
{ sizeof( "-=" ), "-=" },
{ sizeof( "*=" ), "*=" },
{ sizeof( "/=" ), "/=" },
{ sizeof( "%=" ), "%=" },
{ sizeof( "&=" ), "&=" },
{ sizeof( "|=" ), "|=" },
{ sizeof( "^=" ), "^=" },
{ sizeof( "<<=" ), "<<=" },
{ sizeof( ">>=" ), ">>=" },
{ sizeof( "++" ), "++" },
{ sizeof( "--" ), "--" },
{ sizeof( "+" ), "+" },
{ sizeof( "-" ), "-" },
{ sizeof( "!" ), "!" },
{ sizeof( "+" ), "+" },
{ sizeof( "-" ), "-" },
{ sizeof( "*" ), "*" },
{ sizeof( "/" ), "/" },
{ sizeof( "%" ), "%" },
{ sizeof( "~" ), "~" },
{ sizeof( "&" ), "&" },
{ sizeof( "|" ), "|" },
{ sizeof( "^" ), "^" },
{ sizeof( "<<" ), "<<" },
{ sizeof( ">>" ), ">>" },
{ sizeof( "&&" ), "&&" },
{ sizeof( "||" ), "||" },
{ sizeof( "==" ), "==" },
{ sizeof( "!=" ), "!=" },
{ sizeof( "<" ), "<" },
{ sizeof( ">" ), ">" },
{ sizeof( "<=" ), "<=" },
{ sizeof( ">=" ), ">=" },
{ sizeof( "[]" ), "[]" },
{ sizeof( "*" ), "*" },
{ sizeof( "&" ), "&" },
{ sizeof( "->" ), "->" },
{ sizeof( "->*" ), "->*" },
{ sizeof( "()" ), "()" },
{ sizeof( "," ), "," },
{ sizeof( "new" ), "new" },
{ sizeof( "new[]" ), "new[]" },
{ sizeof( "delete" ), "delete" },
{ sizeof( "delete[]" ), "delete[]" },
};
return lookup[op];
}
} // namespace EOperator
using OperatorT = EOperator::Type;

View File

@ -0,0 +1,98 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "components/types.hpp"
#endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
namespace ESpecifier
{
enum Type : u32
{
Invalid,
Consteval,
Constexpr,
Constinit,
Explicit,
External_Linkage,
ForceInline,
Global,
Inline,
Internal_Linkage,
Local_Persist,
Mutable,
NeverInline,
Ptr,
Ref,
Register,
RValue,
Static,
Thread_Local,
Virtual,
Const,
Final,
NoExceptions,
Override,
Pure,
Volatile,
NumSpecifiers
};
inline bool is_trailing( Type specifier )
{
return specifier > Virtual;
}
inline StrC to_str( Type type )
{
local_persist StrC lookup[] {
{ sizeof( "INVALID" ), "INVALID" },
{ sizeof( "consteval" ), "consteval" },
{ sizeof( "constexpr" ), "constexpr" },
{ sizeof( "constinit" ), "constinit" },
{ sizeof( "explicit" ), "explicit" },
{ sizeof( "extern" ), "extern" },
{ sizeof( "forceinline" ), "forceinline" },
{ sizeof( "global" ), "global" },
{ sizeof( "inline" ), "inline" },
{ sizeof( "internal" ), "internal" },
{ sizeof( "local_persist" ), "local_persist" },
{ sizeof( "mutable" ), "mutable" },
{ sizeof( "neverinline" ), "neverinline" },
{ sizeof( "*" ), "*" },
{ sizeof( "&" ), "&" },
{ sizeof( "register" ), "register" },
{ sizeof( "&&" ), "&&" },
{ sizeof( "static" ), "static" },
{ sizeof( "thread_local" ), "thread_local" },
{ sizeof( "virtual" ), "virtual" },
{ sizeof( "const" ), "const" },
{ sizeof( "final" ), "final" },
{ sizeof( "noexcept" ), "noexcept" },
{ sizeof( "override" ), "override" },
{ sizeof( "= 0" ), "= 0" },
{ sizeof( "volatile" ), "volatile" },
};
return lookup[type];
}
inline Type to_type( StrC str )
{
local_persist u32 keymap[NumSpecifiers];
do_once_start for ( u32 index = 0; index < NumSpecifiers; index++ )
{
StrC enum_str = to_str( (Type)index );
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
}
do_once_end u32 hash = crc32( str.Ptr, str.Len );
for ( u32 index = 0; index < NumSpecifiers; index++ )
{
if ( keymap[index] == hash )
return (Type)index;
}
return Invalid;
}
} // namespace ESpecifier
using SpecifierT = ESpecifier::Type;

View File

@ -0,0 +1,241 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "components/types.hpp"
#endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
namespace parser
{
namespace ETokType
{
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Attribute_API_Import, "GEN_API_Import_Code" )
enum Type : u32
{
Invalid,
Access_Private,
Access_Protected,
Access_Public,
Access_MemberSymbol,
Access_StaticSymbol,
Ampersand,
Ampersand_DBL,
Assign_Classifer,
Attribute_Open,
Attribute_Close,
BraceCurly_Open,
BraceCurly_Close,
BraceSquare_Open,
BraceSquare_Close,
Capture_Start,
Capture_End,
Comment,
Comment_End,
Comment_Start,
Char,
Comma,
Decl_Class,
Decl_GNU_Attribute,
Decl_MSVC_Attribute,
Decl_Enum,
Decl_Extern_Linkage,
Decl_Friend,
Decl_Module,
Decl_Namespace,
Decl_Operator,
Decl_Struct,
Decl_Template,
Decl_Typedef,
Decl_Using,
Decl_Union,
Identifier,
Module_Import,
Module_Export,
NewLine,
Number,
Operator,
Preprocess_Hash,
Preprocess_Define,
Preprocess_If,
Preprocess_IfDef,
Preprocess_IfNotDef,
Preprocess_ElIf,
Preprocess_Else,
Preprocess_EndIf,
Preprocess_Include,
Preprocess_Pragma,
Preprocess_Content,
Preprocess_Macro,
Preprocess_Unsupported,
Spec_Alignas,
Spec_Const,
Spec_Consteval,
Spec_Constexpr,
Spec_Constinit,
Spec_Explicit,
Spec_Extern,
Spec_Final,
Spec_ForceInline,
Spec_Global,
Spec_Inline,
Spec_Internal_Linkage,
Spec_LocalPersist,
Spec_Mutable,
Spec_NeverInline,
Spec_Override,
Spec_Static,
Spec_ThreadLocal,
Spec_Volatile,
Spec_Virtual,
Star,
Statement_End,
StaticAssert,
String,
Type_Typename,
Type_Unsigned,
Type_Signed,
Type_Short,
Type_Long,
Type_bool,
Type_char,
Type_int,
Type_double,
Type_MS_int8,
Type_MS_int16,
Type_MS_int32,
Type_MS_int64,
Type_MS_W64,
Varadic_Argument,
__Attributes_Start,
Attribute_API_Export,
Attribute_API_Import,
NumTokens
};
inline StrC to_str( Type type )
{
local_persist StrC lookup[] {
{ sizeof( "__invalid__" ), "__invalid__" },
{ sizeof( "private" ), "private" },
{ sizeof( "protected" ), "protected" },
{ sizeof( "public" ), "public" },
{ sizeof( "." ), "." },
{ sizeof( "::" ), "::" },
{ sizeof( "&" ), "&" },
{ sizeof( "&&" ), "&&" },
{ sizeof( ":" ), ":" },
{ sizeof( "[[" ), "[[" },
{ sizeof( "]]" ), "]]" },
{ sizeof( "{" ), "{" },
{ sizeof( "}" ), "}" },
{ sizeof( "[" ), "[" },
{ sizeof( "]" ), "]" },
{ sizeof( "(" ), "(" },
{ sizeof( ")" ), ")" },
{ sizeof( "__comment__" ), "__comment__" },
{ sizeof( "__comment_end__" ), "__comment_end__" },
{ sizeof( "__comment_start__" ), "__comment_start__" },
{ sizeof( "__character__" ), "__character__" },
{ sizeof( "," ), "," },
{ sizeof( "class" ), "class" },
{ sizeof( "__attribute__" ), "__attribute__" },
{ sizeof( "__declspec" ), "__declspec" },
{ sizeof( "enum" ), "enum" },
{ sizeof( "extern" ), "extern" },
{ sizeof( "friend" ), "friend" },
{ sizeof( "module" ), "module" },
{ sizeof( "namespace" ), "namespace" },
{ sizeof( "operator" ), "operator" },
{ sizeof( "struct" ), "struct" },
{ sizeof( "template" ), "template" },
{ sizeof( "typedef" ), "typedef" },
{ sizeof( "using" ), "using" },
{ sizeof( "union" ), "union" },
{ sizeof( "__identifier__" ), "__identifier__" },
{ sizeof( "import" ), "import" },
{ sizeof( "export" ), "export" },
{ sizeof( "__new_line__" ), "__new_line__" },
{ sizeof( "__number__" ), "__number__" },
{ sizeof( "__operator__" ), "__operator__" },
{ sizeof( "#" ), "#" },
{ sizeof( "define" ), "define" },
{ sizeof( "if" ), "if" },
{ sizeof( "ifdef" ), "ifdef" },
{ sizeof( "ifndef" ), "ifndef" },
{ sizeof( "elif" ), "elif" },
{ sizeof( "else" ), "else" },
{ sizeof( "endif" ), "endif" },
{ sizeof( "include" ), "include" },
{ sizeof( "pragma" ), "pragma" },
{ sizeof( "__macro_content__" ), "__macro_content__" },
{ sizeof( "__macro__" ), "__macro__" },
{ sizeof( "__unsupported__" ), "__unsupported__" },
{ sizeof( "alignas" ), "alignas" },
{ sizeof( "const" ), "const" },
{ sizeof( "consteval" ), "consteval" },
{ sizeof( "constexpr" ), "constexpr" },
{ sizeof( "constinit" ), "constinit" },
{ sizeof( "explicit" ), "explicit" },
{ sizeof( "extern" ), "extern" },
{ sizeof( "final" ), "final" },
{ sizeof( "forceinline" ), "forceinline" },
{ sizeof( "global" ), "global" },
{ sizeof( "inline" ), "inline" },
{ sizeof( "internal" ), "internal" },
{ sizeof( "local_persist" ), "local_persist" },
{ sizeof( "mutable" ), "mutable" },
{ sizeof( "neverinline" ), "neverinline" },
{ sizeof( "override" ), "override" },
{ sizeof( "static" ), "static" },
{ sizeof( "thread_local" ), "thread_local" },
{ sizeof( "volatile" ), "volatile" },
{ sizeof( "virtual" ), "virtual" },
{ sizeof( "*" ), "*" },
{ sizeof( ";" ), ";" },
{ sizeof( "static_assert" ), "static_assert" },
{ sizeof( "__string__" ), "__string__" },
{ sizeof( "typename" ), "typename" },
{ sizeof( "unsigned" ), "unsigned" },
{ sizeof( "signed" ), "signed" },
{ sizeof( "short" ), "short" },
{ sizeof( "long" ), "long" },
{ sizeof( "bool" ), "bool" },
{ sizeof( "char" ), "char" },
{ sizeof( "int" ), "int" },
{ sizeof( "double" ), "double" },
{ sizeof( "__int8" ), "__int8" },
{ sizeof( "__int16" ), "__int16" },
{ sizeof( "__int32" ), "__int32" },
{ sizeof( "__int64" ), "__int64" },
{ sizeof( "_W64" ), "_W64" },
{ sizeof( "..." ), "..." },
{ sizeof( "__attrib_start__" ), "__attrib_start__" },
{ sizeof( "GEN_API_Export_Code" ), "GEN_API_Export_Code" },
{ sizeof( "GEN_API_Import_Code" ), "GEN_API_Import_Code" },
};
return lookup[type];
}
inline Type to_type( StrC str )
{
local_persist u32 keymap[NumTokens];
do_once_start for ( u32 index = 0; index < NumTokens; index++ )
{
StrC enum_str = to_str( (Type)index );
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
}
do_once_end u32 hash = crc32( str.Ptr, str.Len );
for ( u32 index = 0; index < NumTokens; index++ )
{
if ( keymap[index] == hash )
return (Type)index;
}
return Invalid;
}
} // namespace ETokType
using TokType = ETokType::Type;
} // namespace parser

View File

@ -0,0 +1,182 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "inlines.hpp"
#include "gen/ast_inlines.hpp"
#endif
#pragma region Constants
#ifndef GEN_GLOBAL_BUCKET_SIZE
# define GEN_GLOBAL_BUCKET_SIZE megabytes(8)
#endif
#ifndef GEN_CODEPOOL_NUM_BLOCKS
# define GEN_CODEPOOL_NUM_BLOCKS kilobytes(16)
#endif
#ifndef GEN_SIZE_PER_STRING_ARENA
# define GEN_SIZE_PER_STRING_ARENA megabytes(1)
#endif
#ifndef GEN_MAX_COMMENT_LINE_LENGTH
# define GEN_MAX_COMMENT_LINE_LENGTH 1024
#endif
#ifndef GEN_MAX_NAME_LENGTH
# define GEN_MAX_NAME_LENGTH 128
#endif
#ifndef GEN_MAX_UNTYPED_STR_LENGTH
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
#endif
#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(4)
#endif
#ifndef GEN_LEX_ALLOCATOR_SIZE
# define GEN_LEX_ALLOCATOR_SIZE megabytes(4)
#endif
#ifndef GEN_BUILDER_STR_BUFFER_RESERVE
# define GEN_BUILDER_STR_BUFFER_RESERVE megabytes(2)
#endif
// These constexprs are used for allocation behavior of data structures
// or string handling while constructing or serializing.
// Change them to suit your needs.
constexpr s32 InitSize_DataArrays = 16;
// NOTE: This limits the maximum size of an allocation
// If you are generating a string larger than this, increase the size of the bucket here.
constexpr usize Global_BucketSize = GEN_GLOBAL_BUCKET_SIZE;
constexpr s32 CodePool_NumBlocks = GEN_CODEPOOL_NUM_BLOCKS;
constexpr s32 SizePer_StringArena = GEN_SIZE_PER_STRING_ARENA;
constexpr s32 MaxCommentLineLength = GEN_MAX_COMMENT_LINE_LENGTH;
constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH;
constexpr s32 MaxUntypedStrLength = GEN_MAX_UNTYPED_STR_LENGTH;
constexpr s32 TokenFmt_TokenMap_MemSize = GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE;
constexpr s32 LexAllocator_Size = GEN_LEX_ALLOCATOR_SIZE;
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
extern Code access_public;
extern Code access_protected;
extern Code access_private;
extern CodeAttributes attrib_api_export;
extern CodeAttributes attrib_api_import;
extern Code module_global_fragment;
extern Code module_private_fragment;
extern Code fmt_newline;
extern CodePragma pragma_once;
extern CodeParam param_varadic;
extern CodePreprocessCond preprocess_else;
extern CodePreprocessCond preprocess_endif;
extern CodeSpecifiers spec_const;
extern CodeSpecifiers spec_consteval;
extern CodeSpecifiers spec_constexpr;
extern CodeSpecifiers spec_constinit;
extern CodeSpecifiers spec_extern_linkage;
extern CodeSpecifiers spec_final;
extern CodeSpecifiers spec_forceinline;
extern CodeSpecifiers spec_global;
extern CodeSpecifiers spec_inline;
extern CodeSpecifiers spec_internal_linkage;
extern CodeSpecifiers spec_local_persist;
extern CodeSpecifiers spec_mutable;
extern CodeSpecifiers spec_neverinline;
extern CodeSpecifiers spec_noexcept;
extern CodeSpecifiers spec_override;
extern CodeSpecifiers spec_ptr;
extern CodeSpecifiers spec_pure;
extern CodeSpecifiers spec_ref;
extern CodeSpecifiers spec_register;
extern CodeSpecifiers spec_rvalue;
extern CodeSpecifiers spec_static_member;
extern CodeSpecifiers spec_thread_local;
extern CodeSpecifiers spec_virtual;
extern CodeSpecifiers spec_volatile;
extern CodeType t_empty; // Used with varaidc parameters. (Exposing just in case its useful for another circumstance)
extern CodeType t_auto;
extern CodeType t_void;
extern CodeType t_int;
extern CodeType t_bool;
extern CodeType t_char;
extern CodeType t_wchar_t;
extern CodeType t_class;
extern CodeType t_typename;
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
// Predefined typename codes. Are set to readonly and are setup during gen::init()
extern CodeType t_b32;
extern CodeType t_s8;
extern CodeType t_s16;
extern CodeType t_s32;
extern CodeType t_s64;
extern CodeType t_u8;
extern CodeType t_u16;
extern CodeType t_u32;
extern CodeType t_u64;
extern CodeType t_ssize;
extern CodeType t_usize;
extern CodeType t_f32;
extern CodeType t_f64;
#endif
#pragma endregion Constants
#pragma region Macros
# define gen_main main
# define __ NoCode
// Convienence for defining any name used with the gen api.
// Lets you provide the length and string literal to the functions without the need for the DSL.
# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
// Same as name just used to indicate intention of literal for code instead of names.
# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
# define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) )
# define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) )
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
# define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
#pragma endregion Macros
// Used by the lexer to persistently treat all these identifiers as preprocessor defines.
// Populate with strings via gen::get_cached_string.
// Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments.
extern Array< StringCached > PreprocessorDefines;
#ifdef GEN_EXPOSE_BACKEND
// Global allocator used for data with process lifetime.
extern AllocatorInfo GlobalAllocator;
extern Array< Arena > Global_AllocatorBuckets;
extern Array< Pool > CodePools;
extern Array< Arena > StringArenas;
extern StringTable StringCache;
extern Arena LexArena;
extern AllocatorInfo Allocator_DataArrays;
extern AllocatorInfo Allocator_CodePool;
extern AllocatorInfo Allocator_Lexer;
extern AllocatorInfo Allocator_StringArena;
extern AllocatorInfo Allocator_StringTable;
extern AllocatorInfo Allocator_TypeTable;
#endif

View File

@ -1,3 +1,5 @@
#pragma once
/*
gencpp: An attempt at "simple" staged metaprogramming for c/c++.
@ -15,3 +17,15 @@
#ifndef GEN_ROLL_OWN_DEPENDENCIES
# include "gen.dep.hpp"
#endif
#ifndef GEN_NS_BEGIN
# ifdef GEN_DONT_USE_NAMESPACE
# define GEN_NS
# define GEN_NS_BEGIN
# define GEN_NS_END
# else
# define GEN_NS gen::
# define GEN_NS_BEGIN namespace gen {
# define GEN_NS_END }
# endif
#endif

View File

@ -0,0 +1,208 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "interface.hpp"
#endif
inline
void AST::append( AST* other )
{
if ( other->Parent )
other = other->duplicate();
other->Parent = this;
if ( Front == nullptr )
{
Front = other;
Back = other;
NumEntries++;
return;
}
AST*
Current = Back;
Current->Next = other;
other->Prev = Current;
Back = other;
NumEntries++;
}
inline
Code& AST::entry( u32 idx )
{
AST** current = & Front;
while ( idx >= 0 && current != nullptr )
{
if ( idx == 0 )
return * rcast( Code*, current);
current = & ( * current )->Next;
idx--;
}
return * rcast( Code*, current);
}
inline
bool AST::has_entries()
{
return NumEntries > 0;
}
inline
char const* AST::type_str()
{
return ECode::to_str( Type );
}
inline
AST::operator Code()
{
return { this };
}
inline
Code& Code::operator ++()
{
if ( ast )
ast = ast->Next;
return *this;
}
inline
void CodeClass::add_interface( CodeType type )
{
CodeType possible_slot = ast->ParentType;
if ( possible_slot.ast )
{
// Were adding an interface to parent type, so we need to make sure the parent type is public.
ast->ParentAccess = AccessSpec::Public;
// If your planning on adding a proper parent,
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
}
while ( possible_slot.ast != nullptr )
{
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
}
possible_slot.ast = type.ast;
}
inline
void CodeParam::append( CodeParam other )
{
AST* self = (AST*) ast;
AST* entry = (AST*) other.ast;
if ( entry->Parent )
entry = entry->duplicate();
entry->Parent = self;
if ( self->Last == nullptr )
{
self->Last = entry;
self->Next = entry;
self->NumEntries++;
return;
}
self->Last->Next = entry;
self->Last = entry;
self->NumEntries++;
}
inline
CodeParam CodeParam::get( s32 idx )
{
CodeParam param = *this;
do
{
if ( ! ++ param )
return { nullptr };
param = { (AST_Param*) param.raw()->Next };
}
while ( --idx );
return param;
}
inline
bool CodeParam::has_entries()
{
return ast->NumEntries > 0;
}
inline
CodeParam& CodeParam::operator ++()
{
ast = ast->Next.ast;
return * this;
}
inline
void CodeStruct::add_interface( CodeType type )
{
CodeType possible_slot = ast->ParentType;
if ( possible_slot.ast )
{
// Were adding an interface to parent type, so we need to make sure the parent type is public.
ast->ParentAccess = AccessSpec::Public;
// If your planning on adding a proper parent,
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
}
while ( possible_slot.ast != nullptr )
{
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
}
possible_slot.ast = type.ast;
}
inline
CodeBody def_body( CodeT type )
{
switch ( type )
{
using namespace ECode;
case Class_Body:
case Enum_Body:
case Export_Body:
case Extern_Linkage:
case Function_Body:
case Global_Body:
case Namespace_Body:
case Struct_Body:
case Union_Body:
break;
default:
log_failure( "def_body: Invalid type %s", (char const*)ECode::to_str(type) );
return (CodeBody)Code::Invalid;
}
Code
result = make_code();
result->Type = type;
return (CodeBody)result;
}
inline
StrC token_fmt_impl( ssize num, ... )
{
local_persist thread_local
char buf[GEN_PRINTF_MAXLEN] = { 0 };
mem_set( buf, 0, GEN_PRINTF_MAXLEN );
va_list va;
va_start(va, num );
ssize result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
va_end(va);
return { result, buf };
}

View File

@ -1,5 +1,15 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "code_serialization.cpp"
#endif
namespace parser {
internal void init();
internal void deinit();
}
internal
void* Global_Allocator_Proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags )
void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
{
Arena* last = & Global_AllocatorBuckets.back();
@ -12,10 +22,10 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, sw size, sw a
Arena bucket = Arena::init_from_allocator( heap(), Global_BucketSize );
if ( bucket.PhysicalStart == nullptr )
fatal( "Failed to create bucket for Global_AllocatorBuckets");
GEN_FATAL( "Failed to create bucket for Global_AllocatorBuckets");
if ( ! Global_AllocatorBuckets.append( bucket ) )
fatal( "Failed to append bucket to Global_AllocatorBuckets");
GEN_FATAL( "Failed to append bucket to Global_AllocatorBuckets");
last = & Global_AllocatorBuckets.back();
}
@ -39,10 +49,10 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, sw size, sw a
Arena bucket = Arena::init_from_allocator( heap(), Global_BucketSize );
if ( bucket.PhysicalStart == nullptr )
fatal( "Failed to create bucket for Global_AllocatorBuckets");
GEN_FATAL( "Failed to create bucket for Global_AllocatorBuckets");
if ( ! Global_AllocatorBuckets.append( bucket ) )
fatal( "Failed to append bucket to Global_AllocatorBuckets");
GEN_FATAL( "Failed to append bucket to Global_AllocatorBuckets");
last = & Global_AllocatorBuckets.back();
}
@ -65,12 +75,74 @@ internal
void define_constants()
{
Code::Global = make_code();
Code::Global->Name = get_cached_string( txt_StrC("Global Code") );
Code::Global->Name = get_cached_string( txt("Global Code") );
Code::Global->Content = Code::Global->Name;
Code::Invalid = make_code();
Code::Invalid.set_global();
t_empty = (CodeType) make_code();
t_empty->Type = ECode::Typename;
t_empty->Name = get_cached_string( txt("") );
t_empty.set_global();
access_private = make_code();
access_private->Type = ECode::Access_Private;
access_private->Name = get_cached_string( txt("private:\n") );
access_private.set_global();
access_protected = make_code();
access_protected->Type = ECode::Access_Protected;
access_protected->Name = get_cached_string( txt("protected:\n") );
access_protected.set_global();
access_public = make_code();
access_public->Type = ECode::Access_Public;
access_public->Name = get_cached_string( txt("public:\n") );
access_public.set_global();
attrib_api_export = def_attributes( code(GEN_API_Export_Code));
attrib_api_export.set_global();
attrib_api_import = def_attributes( code(GEN_API_Import_Code));
attrib_api_import.set_global();
module_global_fragment = make_code();
module_global_fragment->Type = ECode::Untyped;
module_global_fragment->Name = get_cached_string( txt("module;") );
module_global_fragment->Content = module_global_fragment->Name;
module_global_fragment.set_global();
module_private_fragment = make_code();
module_private_fragment->Type = ECode::Untyped;
module_private_fragment->Name = get_cached_string( txt("module : private;") );
module_private_fragment->Content = module_private_fragment->Name;
module_private_fragment.set_global();
fmt_newline = make_code();
fmt_newline->Type = ECode::NewLine;
fmt_newline.set_global();
pragma_once = (CodePragma) make_code();
pragma_once->Type = ECode::Preprocess_Pragma;
pragma_once->Name = get_cached_string( txt("once") );
pragma_once->Content = pragma_once->Name;
pragma_once.set_global();
param_varadic = (CodeType) make_code();
param_varadic->Type = ECode::Parameters;
param_varadic->Name = get_cached_string( txt("...") );
param_varadic->ValueType = t_empty;
param_varadic.set_global();
preprocess_else = (CodePreprocessCond) make_code();
preprocess_else->Type = ECode::Preprocess_Else;
preprocess_else.set_global();
preprocess_endif = (CodePreprocessCond) make_code();
preprocess_endif->Type = ECode::Preprocess_EndIf;
preprocess_endif.set_global();
# define def_constant_code_type( Type_ ) \
t_##Type_ = def_type( name(Type_) ); \
t_##Type_.set_global();
@ -97,88 +169,46 @@ void define_constants()
def_constant_code_type( u32 );
def_constant_code_type( u64 );
def_constant_code_type( sw );
def_constant_code_type( uw );
def_constant_code_type( ssize );
def_constant_code_type( usize );
def_constant_code_type( f32 );
def_constant_code_type( f64 );
#endif
# undef def_constant_code_type
t_empty = (CodeType) make_code();
t_empty->Type = ECode::Typename;
t_empty->Name = get_cached_string( txt_StrC("") );
t_empty.set_global();
param_varadic = (CodeType) make_code();
param_varadic->Type = ECode::Parameters;
param_varadic->Name = get_cached_string( txt_StrC("...") );
param_varadic->ValueType = t_empty;
param_varadic.set_global();
attrib_api_export = def_attributes( code(GEN_API_Export_Code));
attrib_api_export.set_global();
attrib_api_import = def_attributes( code(GEN_API_Import_Code));
attrib_api_import.set_global();
access_private = make_code();
access_private->Type = ECode::Access_Private;
access_private->Name = get_cached_string( txt_StrC("private:") );
access_private.set_global();
access_protected = make_code();
access_protected->Type = ECode::Access_Protected;
access_protected->Name = get_cached_string( txt_StrC("protected:") );
access_protected.set_global();
access_public = make_code();
access_public->Type = ECode::Access_Public;
access_public->Name = get_cached_string( txt_StrC("public:") );
access_public.set_global();
module_global_fragment = make_code();
module_global_fragment->Type = ECode::Untyped;
module_global_fragment->Name = get_cached_string( txt_StrC("module;") );
module_global_fragment->Content = module_global_fragment->Name;
module_global_fragment.set_global();
module_private_fragment = make_code();
module_private_fragment->Type = ECode::Untyped;
module_private_fragment->Name = get_cached_string( txt_StrC("module : private;") );
module_private_fragment->Content = module_private_fragment->Name;
module_private_fragment.set_global();
pragma_once = make_code();
pragma_once->Type = ECode::Untyped;
pragma_once->Name = get_cached_string( txt_StrC("#pragma once") );
pragma_once->Content = pragma_once->Name;
pragma_once.set_global();
# pragma push_macro( "global" )
# pragma push_macro( "internal" )
# pragma push_macro( "local_persist" )
# undef global
# undef internal
# undef local_persist
# define def_constant_spec( Type_, ... ) \
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
spec_##Type_.set_global();
# pragma push_macro("forceinline")
# pragma push_macro("global")
# pragma push_macro("internal")
# pragma push_macro("local_persist")
# pragma push_macro("neverinline")
# undef forceinline
# undef global
# undef internal
# undef local_persist
# undef neverinline
def_constant_spec( const, ESpecifier::Const );
def_constant_spec( consteval, ESpecifier::Consteval );
def_constant_spec( constexpr, ESpecifier::Constexpr );
def_constant_spec( constinit, ESpecifier::Constinit );
def_constant_spec( extern_linkage, ESpecifier::External_Linkage );
def_constant_spec( final, ESpecifier::Final );
def_constant_spec( forceinline, ESpecifier::ForceInline );
def_constant_spec( global, ESpecifier::Global );
def_constant_spec( inline, ESpecifier::Inline );
def_constant_spec( internal_linkage, ESpecifier::Internal_Linkage );
def_constant_spec( local_persist, ESpecifier::Local_Persist );
def_constant_spec( mutable, ESpecifier::Mutable );
def_constant_spec( neverinline, ESpecifier::NeverInline );
def_constant_spec( noexcept, ESpecifier::NoExceptions );
def_constant_spec( override, ESpecifier::Override );
def_constant_spec( ptr, ESpecifier::Ptr );
def_constant_spec( pure, ESpecifier::Pure )
def_constant_spec( ref, ESpecifier::Ref );
def_constant_spec( register, ESpecifier::Register );
def_constant_spec( rvalue, ESpecifier::RValue );
@ -190,9 +220,11 @@ void define_constants()
spec_local_persist = def_specifiers( 1, ESpecifier::Local_Persist );
spec_local_persist.set_global();
# pragma pop_macro( "global" )
# pragma pop_macro( "internal" )
# pragma pop_macro( "local_persist" )
# pragma pop_macro("forceinline")
# pragma pop_macro("global")
# pragma pop_macro("internal")
# pragma pop_macro("local_persist")
# pragma pop_macro("neverinline")
# undef def_constant_spec
}
@ -206,12 +238,12 @@ void init()
Global_AllocatorBuckets = Array<Arena>::init_reserve( heap(), 128 );
if ( Global_AllocatorBuckets == nullptr )
fatal( "Failed to reserve memory for Global_AllocatorBuckets");
GEN_FATAL( "Failed to reserve memory for Global_AllocatorBuckets");
Arena bucket = Arena::init_from_allocator( heap(), Global_BucketSize );
if ( bucket.PhysicalStart == nullptr )
fatal( "Failed to create first bucket for Global_AllocatorBuckets");
GEN_FATAL( "Failed to create first bucket for Global_AllocatorBuckets");
Global_AllocatorBuckets.append( bucket );
@ -222,12 +254,12 @@ void init()
CodePools = Array<Pool>::init_reserve( Allocator_DataArrays, InitSize_DataArrays );
if ( CodePools == nullptr )
fatal( "gen::init: Failed to initialize the CodePools array" );
GEN_FATAL( "gen::init: Failed to initialize the CodePools array" );
StringArenas = Array<Arena>::init_reserve( Allocator_DataArrays, InitSize_DataArrays );
if ( StringArenas == nullptr )
fatal( "gen::init: Failed to initialize the StringArenas array" );
GEN_FATAL( "gen::init: Failed to initialize the StringArenas array" );
}
// Setup the code pool and code entries arena.
@ -235,7 +267,7 @@ void init()
Pool code_pool = Pool::init( Allocator_CodePool, CodePool_NumBlocks, sizeof(AST) );
if ( code_pool.PhysicalStart == nullptr )
fatal( "gen::init: Failed to initialize the code pool" );
GEN_FATAL( "gen::init: Failed to initialize the code pool" );
CodePools.append( code_pool );
@ -244,7 +276,7 @@ void init()
Arena string_arena = Arena::init_from_allocator( Allocator_StringArena, SizePer_StringArena );
if ( string_arena.PhysicalStart == nullptr )
fatal( "gen::init: Failed to initialize the string arena" );
GEN_FATAL( "gen::init: Failed to initialize the string arena" );
StringArenas.append( string_arena );
}
@ -254,16 +286,20 @@ void init()
StringCache = StringTable::init( Allocator_StringTable );
if ( StringCache.Entries == nullptr )
fatal( "gen::init: Failed to initialize the StringCache");
GEN_FATAL( "gen::init: Failed to initialize the StringCache");
}
// Preprocessor Defines
PreprocessorDefines = Array<StringCached>::init_reserve( GlobalAllocator, kilobytes(1) );
define_constants();
parser::init();
}
void deinit()
{
uw index = 0;
uw left = CodePools.num();
usize index = 0;
usize left = CodePools.num();
do
{
Pool* code_pool = & CodePools[index];
@ -289,6 +325,8 @@ void deinit()
LexArena.free();
PreprocessorDefines.free();
index = 0;
left = Global_AllocatorBuckets.num();
do
@ -300,6 +338,7 @@ void deinit()
while ( left--, left );
Global_AllocatorBuckets.free();
parser::deinit();
}
void reset()
@ -333,14 +372,14 @@ AllocatorInfo get_string_allocator( s32 str_length )
{
Arena* last = & StringArenas.back();
uw size_req = str_length + sizeof(String::Header) + sizeof(char*);
usize size_req = str_length + sizeof(String::Header) + sizeof(char*);
if ( last->TotalUsed + size_req > last->TotalSize )
if ( last->TotalUsed + ssize(size_req) > last->TotalSize )
{
Arena new_arena = Arena::init_from_allocator( Allocator_StringArena, SizePer_StringArena );
if ( ! StringArenas.append( new_arena ) )
fatal( "gen::get_string_allocator: Failed to allocate a new string arena" );
GEN_FATAL( "gen::get_string_allocator: Failed to allocate a new string arena" );
last = & StringArenas.back();
}
@ -366,9 +405,7 @@ StringCached get_cached_string( StrC str )
return result;
}
/*
Used internally to retireve a Code object form the CodePool.
*/
// Used internally to retireve a Code object form the CodePool.
Code make_code()
{
Pool* allocator = & CodePools.back();
@ -377,24 +414,27 @@ Code make_code()
Pool code_pool = Pool::init( Allocator_CodePool, CodePool_NumBlocks, sizeof(AST) );
if ( code_pool.PhysicalStart == nullptr )
fatal( "gen::make_code: Failed to allocate a new code pool - CodePool allcoator returned nullptr." );
GEN_FATAL( "gen::make_code: Failed to allocate a new code pool - CodePool allcoator returned nullptr." );
if ( ! CodePools.append( code_pool ) )
fatal( "gen::make_code: Failed to allocate a new code pool - CodePools failed to append new pool." );
GEN_FATAL( "gen::make_code: Failed to allocate a new code pool - CodePools failed to append new pool." );
allocator = & CodePools.back();
}
Code result { rcast( AST*, alloc( * allocator, sizeof(AST) )) };
mem_set( result.ast, 0, sizeof(AST) );
// result->Type = ECode::Invalid;
result->Content = { nullptr };
result->Prev = { nullptr };
result->Next = { nullptr };
result->Parent = { nullptr };
result->Name = { nullptr };
result->Type = ECode::Invalid;
result->ModuleFlags = ModuleFlag::Invalid;
result->NumEntries = 0;
// result->Content = { nullptr };
// result->Prev = { nullptr };
// result->Next = { nullptr };
// result->Token = nullptr;
// result->Parent = { nullptr };
// result->Name = { nullptr };
// result->Type = ECode::Invalid;
// result->ModuleFlags = ModuleFlag::Invalid;
// result->NumEntries = 0;
return result;
}

View File

@ -1,3 +1,8 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "ast_types.hpp"
#endif
#pragma region Gen Interface
// Initialize the library.
@ -24,7 +29,6 @@ StringCached get_cached_string( StrC str );
Code make_code();
// Set these before calling gen's init() procedure.
// Data
void set_allocator_data_arrays ( AllocatorInfo data_array_allocator );
void set_allocator_code_pool ( AllocatorInfo pool_allocator );
@ -45,6 +49,12 @@ CodeClass def_class( StrC name
, ModuleFlag mflags = ModuleFlag::None
, CodeType* interfaces = nullptr, s32 num_interfaces = 0 );
CodeConstructor def_constructor( CodeParam params = NoCode, Code initializer_list = NoCode, Code body = NoCode );
CodeDefine def_define( StrC name, StrC content );
CodeDestructor def_destructor( Code body = NoCode, CodeSpecifiers specifiers = NoCode );
CodeEnum def_enum( StrC name
, Code body = NoCode, CodeType type = NoCode
, EnumT specifier = EnumRegular, CodeAttributes attributes = NoCode
@ -59,18 +69,22 @@ CodeFn def_function( StrC name
, CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode
, ModuleFlag mflags = ModuleFlag::None );
CodeInclude def_include ( StrC content );
CodeInclude def_include ( StrC content, bool foreign = false );
CodeModule def_module ( StrC name, ModuleFlag mflags = ModuleFlag::None );
CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None );
CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None );
CodeOperator def_operator( OperatorT op
CodeOperator def_operator( OperatorT op, StrC nspace
, CodeParam params = NoCode, CodeType ret_type = NoCode, Code body = NoCode
, CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode
, ModuleFlag mflags = ModuleFlag::None );
CodeOpCast def_operator_cast( CodeType type, Code body = NoCode, CodeSpecifiers specs = NoCode );
CodeParam def_param ( CodeType type, StrC name, Code value = NoCode );
CodeParam def_param ( CodeType type, StrC name, Code value = NoCode );
CodePragma def_pragma( StrC directive );
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC content );
CodeSpecifiers def_specifier( SpecifierT specifier );
CodeStruct def_struct( StrC name
@ -130,30 +144,69 @@ CodeBody def_union_body ( s32 num, Code* codes );
#pragma region Parsing
CodeClass parse_class ( StrC class_def );
CodeEnum parse_enum ( StrC enum_def );
CodeBody parse_export_body ( StrC export_def );
CodeExtern parse_extern_link ( StrC exten_link_def);
CodeFriend parse_friend ( StrC friend_def );
CodeFn parse_function ( StrC fn_def );
CodeBody parse_global_body ( StrC body_def );
CodeNamespace parse_namespace ( StrC namespace_def );
CodeOperator parse_operator ( StrC operator_def );
CodeOpCast parse_operator_cast( StrC operator_def );
CodeStruct parse_struct ( StrC struct_def );
CodeTemplate parse_template ( StrC template_def );
CodeType parse_type ( StrC type_def );
CodeTypedef parse_typedef ( StrC typedef_def );
CodeUnion parse_union ( StrC union_def );
CodeUsing parse_using ( StrC using_def );
CodeVar parse_variable ( StrC var_def );
// TODO(Ed) : Implmeent the new parser API design.
#if 0
namespace parser {
struct StackNode
{
StackNode* Prev;
Token Start;
Token Name; // The name of the AST node (if parsed)
StrC FailedProc; // The name of the procedure that failed
};
// Stack nodes are allocated the error's allocator
struct Error
{
String message;
StackNode* context_stack;
};
}
struct ParseInfo
{
Arena FileMem;
Arena TokMem;
Arena CodeMem;
FileContents FileContent;
Array<parser::Token> Tokens;
Array<parser::Error> Errors;
// Errors are allocated to a dedicated general arena.
};
CodeBody parse_file( StrC path );
#endif
CodeClass parse_class ( StrC class_def );
CodeConstructor parse_constructor ( StrC constructor_def );
CodeDestructor parse_destructor ( StrC destructor_def );
CodeEnum parse_enum ( StrC enum_def );
CodeBody parse_export_body ( StrC export_def );
CodeExtern parse_extern_link ( StrC exten_link_def );
CodeFriend parse_friend ( StrC friend_def );
CodeFn parse_function ( StrC fn_def );
CodeBody parse_global_body ( StrC body_def );
CodeNS parse_namespace ( StrC namespace_def );
CodeOperator parse_operator ( StrC operator_def );
CodeOpCast parse_operator_cast( StrC operator_def );
CodeStruct parse_struct ( StrC struct_def );
CodeTemplate parse_template ( StrC template_def );
CodeType parse_type ( StrC type_def );
CodeTypedef parse_typedef ( StrC typedef_def );
CodeUnion parse_union ( StrC union_def );
CodeUsing parse_using ( StrC using_def );
CodeVar parse_variable ( StrC var_def );
#pragma endregion Parsing
#pragma region Untyped text
sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va );
StrC token_fmt_impl( sw, ... );
ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va );
//! Do not use directly. Use the token_fmt macro instead.
StrC token_fmt_impl( ssize, ... );
Code untyped_str ( StrC content);
Code untyped_fmt ( char const* fmt, ... );

View File

@ -0,0 +1,329 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "gen/etoktype.cpp"
#include "interface.upfront.cpp"
#include "lexer.cpp"
#include "parser.cpp"
#endif
// Publically Exposed Interface
CodeClass parse_class( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
push_scope();
CodeClass result = (CodeClass) parse_class_struct( TokType::Decl_Class );
Context.pop();
return result;
}
CodeConstructor parse_constructor( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
// TODO(Ed): Constructors can have prefix attributes
CodeSpecifiers specifiers;
SpecifierT specs_found[ 16 ] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0;
while ( left && currtok.is_specifier() )
{
SpecifierT spec = ESpecifier::to_type( currtok );
b32 ignore_spec = false;
switch ( spec )
{
case ESpecifier::Constexpr :
case ESpecifier::Explicit:
case ESpecifier::Inline :
case ESpecifier::ForceInline :
case ESpecifier::NeverInline :
break;
case ESpecifier::Const :
ignore_spec = true;
break;
default :
log_failure( "Invalid specifier %s for variable\n%s", ESpecifier::to_str( spec ), Context.to_string() );
Context.pop();
return CodeInvalid;
}
// Every specifier after would be considered part of the type type signature
if (ignore_spec)
break;
specs_found[ NumSpecifiers ] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
if ( NumSpecifiers )
{
specifiers = def_specifiers( NumSpecifiers, specs_found );
// <specifiers> ...
}
Context.Tokens = toks;
CodeConstructor result = parse_constructor( specifiers );
return result;
}
CodeDestructor parse_destructor( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
// TODO(Ed): Destructors can have prefix attributes
// TODO(Ed): Destructors can have virtual
Context.Tokens = toks;
CodeDestructor result = parse_destructor();
return result;
}
CodeEnum parse_enum( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
{
Context.pop();
return CodeInvalid;
}
Context.Tokens = toks;
return parse_enum();
}
CodeBody parse_export_body( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return parse_export_body();
}
CodeExtern parse_extern_link( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return parse_extern_link();
}
CodeFriend parse_friend( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return parse_friend();
}
CodeFn parse_function( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return (CodeFn) parse_function();
}
CodeBody parse_global_body( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
push_scope();
CodeBody result = parse_global_nspace( ECode::Global_Body );
Context.pop();
return result;
}
CodeNS parse_namespace( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return parse_namespace();
}
CodeOperator parse_operator( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return (CodeOperator) parse_operator();
}
CodeOpCast parse_operator_cast( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return parse_operator_cast();
}
CodeStruct parse_struct( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
push_scope();
CodeStruct result = (CodeStruct) parse_class_struct( TokType::Decl_Struct );
Context.pop();
return result;
}
CodeTemplate parse_template( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return parse_template();
}
CodeType parse_type( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return parse_type();
}
CodeTypedef parse_typedef( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return parse_typedef();
}
CodeUnion parse_union( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return parse_union();
}
CodeUsing parse_using( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return parse_using();
}
CodeVar parse_variable( StrC def )
{
check_parse_args( def );
using namespace parser;
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return CodeInvalid;
Context.Tokens = toks;
return parse_variable();
}
// Undef helper macros
# undef check_parse_args
# undef currtok
# undef prevtok
# undef nexttok
# undef eat
# undef left
# undef check
# undef push_scope

View File

@ -1,7 +1,12 @@
sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va )
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "interface.parsing.cpp"
#endif
ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
{
char const* buf_begin = buf;
sw remaining = buf_size;
ssize remaining = buf_size;
local_persist
Arena tok_map_arena;
@ -12,8 +17,7 @@ sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va )
char tok_map_mem[ TokenFmt_TokenMap_MemSize ];
tok_map_arena = Arena::init_from_memory( tok_map_mem, sizeof(tok_map_mem) );
tok_map = HashTable<StrC>::init( tok_map_arena );
tok_map = HashTable<StrC>::init( tok_map_arena );
s32 left = num_tokens - 1;
@ -33,7 +37,7 @@ sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va )
while ( current )
{
sw len = 0;
ssize len = 0;
while ( current && current != '<' && remaining )
{
@ -64,7 +68,7 @@ sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va )
if ( value )
{
sw left = value->Len;
ssize left = value->Len;
char const* str = value->Ptr;
while ( left-- )
@ -93,30 +97,48 @@ sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va )
tok_map.clear();
tok_map_arena.free();
sw result = buf_size - remaining;
ssize result = buf_size - remaining;
return result;
}
Code untyped_str( StrC content )
{
if ( content.Len == 0 )
{
log_failure( "untyped_str: empty string" );
return CodeInvalid;
}
Code
result = make_code();
result->Name = get_cached_string( content );
result->Type = ECode::Untyped;
result->Content = result->Name;
if ( result->Name == nullptr )
{
log_failure( "untyped_str: could not cache string" );
return CodeInvalid;
}
return result;
}
Code untyped_fmt( char const* fmt, ...)
{
if ( fmt == nullptr )
{
log_failure( "untyped_fmt: null format string" );
return CodeInvalid;
}
local_persist thread_local
char buf[GEN_PRINTF_MAXLEN] = { 0 };
va_list va;
va_start(va, fmt);
sw length = str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
ssize length = str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
va_end(va);
Code
@ -125,17 +147,29 @@ Code untyped_fmt( char const* fmt, ...)
result->Type = ECode::Untyped;
result->Content = get_cached_string( { length, buf } );
if ( result->Name == nullptr )
{
log_failure( "untyped_fmt: could not cache string" );
return CodeInvalid;
}
return result;
}
Code untyped_token_fmt( s32 num_tokens, ... )
{
if ( num_tokens == 0 )
{
log_failure( "untyped_token_fmt: zero tokens" );
return CodeInvalid;
}
local_persist thread_local
char buf[GEN_PRINTF_MAXLEN] = { 0 };
va_list va;
va_start(va, num_tokens);
sw length = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num_tokens, va);
ssize length = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num_tokens, va);
va_end(va);
Code
@ -144,5 +178,11 @@ Code untyped_token_fmt( s32 num_tokens, ... )
result->Type = ECode::Untyped;
result->Content = result->Name;
if ( result->Name == nullptr )
{
log_failure( "untyped_fmt: could not cache string" );
return CodeInvalid;
}
return result;
}

1271
project/components/lexer.cpp Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,8 @@
# error Gen.hpp : GEN_TIME not defined
#endif
#include "gen.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

View File

@ -1,8 +1,15 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "gen.hpp"
#endif
#pragma region StaticData
// TODO : Convert global allocation strategy to use a slab allocation strategy.
global AllocatorInfo GlobalAllocator;
global Array<Arena> Global_AllocatorBuckets;
// TODO(Ed) : Make the code pool a dynamic arena
global Array< Pool > CodePools = { nullptr };
global Array< Arena > StringArenas = { nullptr };
@ -16,9 +23,55 @@ global AllocatorInfo Allocator_Lexer = heap();
global AllocatorInfo Allocator_StringArena = heap();
global AllocatorInfo Allocator_StringTable = heap();
global AllocatorInfo Allocator_TypeTable = heap();
#pragma endregion StaticData
#pragma region Constants
global Code access_public;
global Code access_protected;
global Code access_private;
global CodeAttributes attrib_api_export;
global CodeAttributes attrib_api_import;
global Code module_global_fragment;
global Code module_private_fragment;
global Code fmt_newline;
global CodeParam param_varadic;
global CodePragma pragma_once;
global CodePreprocessCond preprocess_else;
global CodePreprocessCond preprocess_endif;
global CodeSpecifiers spec_const;
global CodeSpecifiers spec_consteval;
global CodeSpecifiers spec_constexpr;
global CodeSpecifiers spec_constinit;
global CodeSpecifiers spec_extern_linkage;
global CodeSpecifiers spec_final;
global CodeSpecifiers spec_forceinline;
global CodeSpecifiers spec_global;
global CodeSpecifiers spec_inline;
global CodeSpecifiers spec_internal_linkage;
global CodeSpecifiers spec_local_persist;
global CodeSpecifiers spec_mutable;
global CodeSpecifiers spec_noexcept;
global CodeSpecifiers spec_neverinline;
global CodeSpecifiers spec_override;
global CodeSpecifiers spec_ptr;
global CodeSpecifiers spec_pure;
global CodeSpecifiers spec_ref;
global CodeSpecifiers spec_register;
global CodeSpecifiers spec_rvalue;
global CodeSpecifiers spec_static_member;
global CodeSpecifiers spec_thread_local;
global CodeSpecifiers spec_virtual;
global CodeSpecifiers spec_volatile;
global CodeType t_empty;
global CodeType t_auto;
global CodeType t_void;
@ -29,6 +82,8 @@ global CodeType t_wchar_t;
global CodeType t_class;
global CodeType t_typename;
global Array< StringCached > PreprocessorDefines;
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
global CodeType t_b32;
@ -42,45 +97,11 @@ global CodeType t_u16;
global CodeType t_u32;
global CodeType t_u64;
global CodeType t_sw;
global CodeType t_uw;
global CodeType t_ssize;
global CodeType t_usize;
global CodeType t_f32;
global CodeType t_f64;
#endif
global CodeParam param_varadic;
global CodeAttributes attrib_api_export;
global CodeAttributes attrib_api_import;
global Code access_public;
global Code access_protected;
global Code access_private;
global Code module_global_fragment;
global Code module_private_fragment;
global Code pragma_once;
global CodeSpecifiers spec_const;
global CodeSpecifiers spec_consteval;
global CodeSpecifiers spec_constexpr;
global CodeSpecifiers spec_constinit;
global CodeSpecifiers spec_extern_linkage;
global CodeSpecifiers spec_final;
global CodeSpecifiers spec_global;
global CodeSpecifiers spec_inline;
global CodeSpecifiers spec_internal_linkage;
global CodeSpecifiers spec_local_persist;
global CodeSpecifiers spec_mutable;
global CodeSpecifiers spec_override;
global CodeSpecifiers spec_ptr;
global CodeSpecifiers spec_ref;
global CodeSpecifiers spec_register;
global CodeSpecifiers spec_rvalue;
global CodeSpecifiers spec_static_member;
global CodeSpecifiers spec_thread_local;
global CodeSpecifiers spec_virtual;
global CodeSpecifiers spec_volatile;
#pragma endregion Constants

View File

@ -0,0 +1,107 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "header_start.hpp"
#endif
using LogFailType = ssize(*)(char const*, ...);
// By default this library will either crash or exit if an error is detected while generating codes.
// Even if set to not use GEN_FATAL, GEN_FATAL will still be used for memory failures as the library is unusable when they occur.
#ifdef GEN_DONT_USE_FATAL
#define log_failure log_fmt
#else
#define log_failure GEN_FATAL
#endif
enum class AccessSpec : u32
{
Default,
Private,
Protected,
Public,
Num_AccessSpec,
Invalid,
};
inline
char const* to_str( AccessSpec type )
{
local_persist
char const* lookup[ (u32)AccessSpec::Num_AccessSpec ] = {
"",
"private",
"protected",
"public",
};
if ( type > AccessSpec::Public )
return "Invalid";
return lookup[ (u32)type ];
}
enum CodeFlag : u32
{
None = 0,
FunctionType = bit(0),
ParamPack = bit(1),
Module_Export = bit(2),
Module_Import = bit(3),
};
// Used to indicate if enum definitoin is an enum class or regular enum.
enum class EnumT : u8
{
Regular,
Class
};
constexpr EnumT EnumClass = EnumT::Class;
constexpr EnumT EnumRegular = EnumT::Regular;
enum class ModuleFlag : u32
{
None = 0,
Export = bit(0),
Import = bit(1),
Num_ModuleFlags,
Invalid,
};
inline
StrC to_str( ModuleFlag flag )
{
local_persist
StrC lookup[ (u32)ModuleFlag::Num_ModuleFlags ] = {
{ sizeof("__none__"), "__none__" },
{ sizeof("export"), "export" },
{ sizeof("import"), "import" },
};
if ( flag > ModuleFlag::Import )
return { sizeof("invalid"), "invalid" };
return lookup[ (u32)flag ];
}
inline
ModuleFlag operator|( ModuleFlag A, ModuleFlag B)
{
return (ModuleFlag)( (u32)A | (u32)B );
}
enum class EPreprocessCond : u32
{
If,
IfDef,
IfNotDef,
ElIf
};
constexpr EPreprocessCond PreprocessCond_If = EPreprocessCond::If;
constexpr EPreprocessCond PreprocessCond_IfDef = EPreprocessCond::IfDef;
constexpr EPreprocessCond PreprocessCond_IfNotDef = EPreprocessCond::IfNotDef;
constexpr EPreprocessCond PreprocessCond_ElIf = EPreprocessCond::ElIf;

View File

@ -1,3 +1,8 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "macros.hpp"
#endif
#pragma region Basic Types
#define GEN_U8_MIN 0u
@ -42,21 +47,21 @@
#if defined( GEN_COMPILER_MSVC )
# if _MSC_VER < 1300
typedef unsigned char u8;
typedef signed char s8;
typedef signed char s8;
typedef unsigned short u16;
typedef signed short s16;
typedef signed short s16;
typedef unsigned int u32;
typedef signed int s32;
typedef signed int s32;
# else
typedef unsigned __int8 u8;
typedef signed __int8 s8;
typedef signed __int8 s8;
typedef unsigned __int16 u16;
typedef signed __int16 s16;
typedef signed __int16 s16;
typedef unsigned __int32 u32;
typedef signed __int32 s32;
typedef signed __int32 s32;
# endif
typedef unsigned __int64 u64;
typedef signed __int64 s64;
typedef signed __int64 s64;
#else
# include <stdint.h>
@ -80,10 +85,10 @@ static_assert( sizeof( u16 ) == 2, "sizeof(u16) != 2" );
static_assert( sizeof( u32 ) == 4, "sizeof(u32) != 4" );
static_assert( sizeof( u64 ) == 8, "sizeof(u64) != 8" );
typedef size_t uw;
typedef ptrdiff_t sw;
typedef size_t usize;
typedef ptrdiff_t ssize;
static_assert( sizeof( uw ) == sizeof( sw ), "sizeof(uw) != sizeof(sw)" );
static_assert( sizeof( usize ) == sizeof( ssize ), "sizeof(usize) != sizeof(ssize)" );
// NOTE: (u)zpl_intptr is only here for semantic reasons really as this library will only support 32/64 bit OSes.
#if defined( _WIN64 )
@ -117,4 +122,13 @@ typedef s8 b8;
typedef s16 b16;
typedef s32 b32;
#pragma region Basic Types
using mem_ptr = void*;
using mem_ptr_const = void const*;
template<typename Type> uptr to_uptr( Type* ptr ) { return (uptr)ptr; }
template<typename Type> sptr to_sptr( Type* ptr ) { return (sptr)ptr; }
template<typename Type> mem_ptr to_mem_ptr ( Type ptr ) { return (mem_ptr) ptr; }
template<typename Type> mem_ptr_const to_mem_ptr_const( Type ptr ) { return (mem_ptr_const)ptr; }
#pragma endregion Basic Types

View File

@ -1,13 +1,26 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "printing.hpp"
#endif
#pragma region Containers
template<class TType> struct RemoveConst { typedef TType Type; };
template<class TType> struct RemoveConst<const TType> { typedef TType Type; };
template<class TType> struct RemoveConst<const TType[]> { typedef TType Type[]; };
template<class TType, usize Size> struct RemoveConst<const TType[Size]> { typedef TType Type[Size]; };
template<class TType>
using TRemoveConst = typename RemoveConst<TType>::Type;
template<class Type>
struct Array
{
struct Header
{
AllocatorInfo Allocator;
uw Capacity;
uw Num;
usize Capacity;
usize Num;
};
static
@ -17,7 +30,7 @@ struct Array
}
static
Array init_reserve( AllocatorInfo allocator, sw capacity )
Array init_reserve( AllocatorInfo allocator, ssize capacity )
{
Header* header = rcast( Header*, alloc( allocator, sizeof(Header) + sizeof(Type) * capacity ));
@ -32,11 +45,16 @@ struct Array
}
static
uw grow_formula( uw value )
usize grow_formula( usize value )
{
return 2 * value + 8;
}
bool append( Array other )
{
return append( other, other.num() );
}
bool append( Type value )
{
Header* header = get_header();
@ -55,7 +73,7 @@ struct Array
return true;
}
bool append( Type* items, uw item_num )
bool append( Type* items, usize item_num )
{
Header* header = get_header();
@ -73,7 +91,7 @@ struct Array
return true;
}
bool append_at( Type item, uw idx )
bool append_at( Type item, usize idx )
{
Header* header = get_header();
@ -99,7 +117,7 @@ struct Array
return true;
}
bool append_at( Type* items, uw item_num, uw idx )
bool append_at( Type* items, usize item_num, usize idx )
{
Header* header = get_header();
@ -138,14 +156,14 @@ struct Array
header.Num = 0;
}
bool fill( uw begin, uw end, Type value )
bool fill( usize begin, usize end, Type value )
{
Header& header = * get_header();
if ( begin < 0 || end >= header.Num )
if ( begin < 0 || end > header.Num )
return false;
for ( sw idx = begin; idx < end; idx++ )
for ( ssize idx = ssize(begin); idx < ssize(end); idx++ )
{
Data[ idx ] = value;
}
@ -162,13 +180,14 @@ struct Array
Header* get_header( void )
{
return rcast( Header*, Data ) - 1 ;
using NonConstType = TRemoveConst< Type >;
return rcast( Header*, const_cast<NonConstType*>(Data) ) - 1 ;
}
bool grow( uw min_capacity )
bool grow( usize min_capacity )
{
Header& header = * get_header();
uw new_capacity = grow_formula( header.Capacity );
usize new_capacity = grow_formula( header.Capacity );
if ( new_capacity < min_capacity )
new_capacity = min_capacity;
@ -176,12 +195,12 @@ struct Array
return set_capacity( new_capacity );
}
uw num( void )
usize num( void )
{
return get_header()->Num;
}
bool pop( void )
void pop( void )
{
Header& header = * get_header();
@ -189,7 +208,7 @@ struct Array
header.Num--;
}
void remove_at( uw idx )
void remove_at( usize idx )
{
Header* header = get_header();
GEN_ASSERT( idx < header->Num );
@ -198,7 +217,7 @@ struct Array
header->Num--;
}
bool reserve( uw new_capacity )
bool reserve( usize new_capacity )
{
Header& header = * get_header();
@ -208,7 +227,7 @@ struct Array
return true;
}
bool resize( uw num )
bool resize( usize num )
{
Header* header = get_header();
@ -224,7 +243,7 @@ struct Array
return true;
}
bool set_capacity( uw new_capacity )
bool set_capacity( usize new_capacity )
{
Header& header = * get_header();
@ -232,9 +251,13 @@ struct Array
return true;
if ( new_capacity < header.Num )
{
// Already have the memory, mine as well keep it.
header.Num = new_capacity;
return true;
}
sw size = sizeof( Header ) + sizeof( Type ) * new_capacity;
ssize size = sizeof( Header ) + sizeof( Type ) * new_capacity;
Header* new_header = rcast( Header*, alloc( header.Allocator, size ) );
if ( new_header == nullptr )
@ -275,54 +298,52 @@ struct Array
}
};
// TODO(Ed) : This thing needs ALOT of work.
template<typename Type>
struct HashTable
{
struct FindResult
{
sw HashIndex;
sw PrevIndex;
sw EntryIndex;
ssize HashIndex;
ssize PrevIndex;
ssize EntryIndex;
};
struct Entry
{
u64 Key;
sw Next;
ssize Next;
Type Value;
};
static constexpr f32 CriticalLoadScale = 0.7f;
static
HashTable init( AllocatorInfo allocator )
{
HashTable<Type> result = { { nullptr }, { nullptr } };
result.Hashes = Array<sw>::init( allocator );
result.Entries = Array<Entry>::init( allocator );
HashTable<Type> result = init_reserve(allocator, 8);
return result;
}
static
HashTable init_reserve( AllocatorInfo allocator, uw num )
HashTable init_reserve( AllocatorInfo allocator, usize num )
{
HashTable<Type> result = { { nullptr }, { nullptr } };
result.Hashes = Array<sw>::init_reserve( allocator, num );
result.Hashes = Array<ssize>::init_reserve( allocator, num );
result.Hashes.get_header()->Num = num;
result.Hashes.resize( num );
result.Hashes.fill( 0, num, -1);
result.Entries = Array<Entry>::init_reserve( allocator, num );
return result;
}
void clear( void )
{
for ( sw idx = 0; idx < Hashes.num(); idx++ )
Hashes[ idx ] = -1;
Hashes.clear();
Entries.clear();
Hashes.fill( 0, Hashes.num(), -1);
}
void destroy( void )
@ -336,7 +357,7 @@ struct HashTable
Type* get( u64 key )
{
sw idx = find( key ).EntryIndex;
ssize idx = find( key ).EntryIndex;
if ( idx >= 0 )
return & Entries[ idx ].Value;
@ -349,7 +370,7 @@ struct HashTable
{
GEN_ASSERT_NOT_NULL( map_proc );
for ( sw idx = 0; idx < Entries.num(); idx++ )
for ( ssize idx = 0; idx < ssize(Entries.num()); ++idx )
{
map_proc( Entries[ idx ].Key, Entries[ idx ].Value );
}
@ -361,7 +382,7 @@ struct HashTable
{
GEN_ASSERT_NOT_NULL( map_proc );
for ( sw idx = 0; idx < Entries.num(); idx++ )
for ( ssize idx = 0; idx < ssize(Entries.num()); ++idx )
{
map_proc( Entries[ idx ].Key, & Entries[ idx ].Value );
}
@ -369,38 +390,25 @@ struct HashTable
void grow()
{
sw new_num = Array<Entry>::grow_formula( Entries.num() );
ssize new_num = Array<Entry>::grow_formula( Entries.num() );
rehash( new_num );
}
void rehash( sw new_num )
void rehash( ssize new_num )
{
sw idx;
sw last_added_index;
ssize last_added_index;
HashTable<Type> new_ht = init_reserve( Hashes.get_header()->Allocator, new_num );
Array<sw>::Header* hash_header = new_ht.Hashes.get_header();
for ( idx = 0; idx < new_ht.Hashes.num(); ++idx )
new_ht.Hashes[ idx ] = -1;
for ( idx = 0; idx < Entries.num(); ++idx )
for ( ssize idx = 0; idx < ssize(Entries.num()); ++idx )
{
Entry& entry = Entries[ idx ];
FindResult find_result;
if ( new_ht.Hashes.num() == 0 )
new_ht.grow();
entry = Entries[ idx ];
Entry& entry = Entries[ idx ];
find_result = new_ht.find( entry.Key );
last_added_index = new_ht.add_entry( entry.Key );
if ( find_result.PrevIndex < 0 )
new_ht.Hashes[ find_result.HashIndex ] = last_added_index;
else
new_ht.Entries[ find_result.PrevIndex ].Next = last_added_index;
@ -414,19 +422,26 @@ struct HashTable
void rehash_fast()
{
sw idx;
ssize idx;
for ( idx = 0; idx < Entries.num(); idx++ )
for ( idx = 0; idx < ssize(Entries.num()); idx++ )
Entries[ idx ].Next = -1;
for ( idx = 0; idx < Hashes.num(); idx++ )
for ( idx = 0; idx < ssize(Hashes.num()); idx++ )
Hashes[ idx ] = -1;
for ( idx = 0; idx < Entries.num(); idx++ )
for ( idx = 0; idx < ssize(Entries.num()); idx++ )
{
Entry* entry;
Entry* entry;
FindResult find_result;
entry = & Entries[ idx ];
find_result = find( entry->Key );
if ( find_result.PrevIndex < 0 )
Hashes[ find_result.HashIndex ] = idx;
else
Entries[ find_result.PrevIndex ].Next = idx;
}
}
@ -441,21 +456,20 @@ struct HashTable
}
}
void remove_entry( sw idx )
void remove_entry( ssize idx )
{
Entries.remove_at( idx );
}
void set( u64 key, Type value )
{
sw idx;
ssize idx;
FindResult find_result;
if ( Hashes.num() == 0 )
if ( full() )
grow();
find_result = find( key );
if ( find_result.EntryIndex >= 0 )
{
idx = find_result.EntryIndex;
@ -480,23 +494,23 @@ struct HashTable
grow();
}
sw slot( u64 key )
ssize slot( u64 key )
{
for ( sw idx = 0; idx < Hashes.num(); ++idx )
for ( ssize idx = 0; idx < ssize(Hashes.num()); ++idx )
if ( Hashes[ idx ] == key )
return idx;
return -1;
}
Array< sw> Hashes;
Array< ssize> Hashes;
Array< Entry> Entries;
protected:
sw add_entry( u64 key )
ssize add_entry( u64 key )
{
sw idx;
ssize idx;
Entry entry = { key, -1 };
idx = Entries.num();
@ -528,7 +542,9 @@ protected:
b32 full()
{
return 0.75f * Hashes.num() < Entries.num();
usize critical_load = usize( CriticalLoadScale * f32(Hashes.num()) );
b32 result = Entries.num() > critical_load;
return result;
}
};

View File

@ -1,11 +1,18 @@
#pragma endregion Debug
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "debug.hpp"
# include "basic_types.hpp"
# include "src_start.cpp"
#endif
#pragma region Debug
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... )
{
_printf_err( "%s:(%d): Assert Failure: ", file, line );
if ( condition )
_printf_err( "`%s` ", condition );
_printf_err( "`%s` \n", condition );
if ( msg )
{

View File

@ -1,4 +1,9 @@
#pragma endregion Debug
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "basic_types.hpp"
#endif
#pragma region Debug
#if defined( _MSC_VER )
# if _MSC_VER < 1300
@ -19,7 +24,7 @@
{ \
if ( ! ( cond ) ) \
{ \
assert_handler( #cond, __FILE__, zpl_cast( s64 ) __LINE__, msg, ##__VA_ARGS__ ); \
assert_handler( #cond, __FILE__, scast( s64, __LINE__ ), msg, ##__VA_ARGS__ ); \
GEN_DEBUG_TRAP(); \
} \
} while ( 0 )
@ -29,6 +34,28 @@
// NOTE: Things that shouldn't happen with a message!
#define GEN_PANIC( msg, ... ) GEN_ASSERT_MSG( 0, msg, ##__VA_ARGS__ )
#if Build_Debug
#define GEN_FATAL( ... ) \
do \
{ \
local_persist thread_local \
char buf[GEN_PRINTF_MAXLEN] = { 0 }; \
\
str_fmt(buf, GEN_PRINTF_MAXLEN, __VA_ARGS__); \
GEN_PANIC(buf); \
} \
while (0)
#else
# define GEN_FATAL( ... ) \
do \
{ \
str_fmt_out_err( __VA_ARGS__ ); \
process_exit(1); \
} \
while (0)
#endif
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... );
s32 assert_crash( char const* condition );
void process_exit( u32 code );

View File

@ -1,11 +1,17 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "strings.cpp"
#endif
#pragma region File Handling
#if defined( GEN_SYSTEM_WINDOWS ) || defined( GEN_SYSTEM_CYGWIN )
internal wchar_t* _alloc_utf8_to_ucs2( AllocatorInfo a, char const* text, sw* w_len_ )
internal
wchar_t* _alloc_utf8_to_ucs2( AllocatorInfo a, char const* text, ssize* w_len_ )
{
wchar_t* w_text = NULL;
sw len = 0, w_len = 0, w_len1 = 0;
ssize len = 0, w_len = 0, w_len1 = 0;
if ( text == NULL )
{
if ( w_len_ )
@ -19,7 +25,7 @@ internal wchar_t* _alloc_utf8_to_ucs2( AllocatorInfo a, char const* text, sw* w_
*w_len_ = w_len;
return NULL;
}
w_len = MultiByteToWideChar( CP_UTF8, MB_ERR_INVALID_CHARS, text, zpl_cast( int ) len, NULL, 0 );
w_len = MultiByteToWideChar( CP_UTF8, MB_ERR_INVALID_CHARS, text, scast( int, len), NULL, 0 );
if ( w_len == 0 )
{
if ( w_len_ )
@ -27,7 +33,7 @@ internal wchar_t* _alloc_utf8_to_ucs2( AllocatorInfo a, char const* text, sw* w_
return NULL;
}
w_text = alloc_array( a, wchar_t, w_len + 1 );
w_len1 = MultiByteToWideChar( CP_UTF8, MB_ERR_INVALID_CHARS, text, zpl_cast( int ) len, w_text, zpl_cast( int ) w_len );
w_len1 = MultiByteToWideChar( CP_UTF8, MB_ERR_INVALID_CHARS, text, scast( int, len), w_text, scast( int, w_len) );
if ( w_len1 == 0 )
{
free( a, w_text );
@ -41,7 +47,8 @@ internal wchar_t* _alloc_utf8_to_ucs2( AllocatorInfo a, char const* text, sw* w_
return w_text;
}
internal GEN_FILE_SEEK_PROC( _win32_file_seek )
internal
GEN_FILE_SEEK_PROC( _win32_file_seek )
{
LARGE_INTEGER li_offset;
li_offset.QuadPart = offset;
@ -55,12 +62,13 @@ internal GEN_FILE_SEEK_PROC( _win32_file_seek )
return true;
}
internal GEN_FILE_READ_AT_PROC( _win32_file_read )
internal
GEN_FILE_READ_AT_PROC( _win32_file_read )
{
// unused( stop_at_newline );
b32 result = false;
_win32_file_seek( fd, offset, ESeekWhence_BEGIN, NULL );
DWORD size_ = zpl_cast( DWORD )( size > GEN_I32_MAX ? GEN_I32_MAX : size );
DWORD size_ = scast( DWORD, ( size > GEN_I32_MAX ? GEN_I32_MAX : size ));
DWORD bytes_read_;
if ( ReadFile( fd.p, buffer, size_, &bytes_read_, NULL ) )
{
@ -72,9 +80,10 @@ internal GEN_FILE_READ_AT_PROC( _win32_file_read )
return result;
}
internal GEN_FILE_WRITE_AT_PROC( _win32_file_write )
internal
GEN_FILE_WRITE_AT_PROC( _win32_file_write )
{
DWORD size_ = zpl_cast( DWORD )( size > GEN_I32_MAX ? GEN_I32_MAX : size );
DWORD size_ = scast( DWORD, ( size > GEN_I32_MAX ? GEN_I32_MAX : size ));
DWORD bytes_written_;
_win32_file_seek( fd, offset, ESeekWhence_BEGIN, NULL );
if ( WriteFile( fd.p, buffer, size_, &bytes_written_, NULL ) )
@ -86,14 +95,16 @@ internal GEN_FILE_WRITE_AT_PROC( _win32_file_write )
return false;
}
internal GEN_FILE_CLOSE_PROC( _win32_file_close )
internal
GEN_FILE_CLOSE_PROC( _win32_file_close )
{
CloseHandle( fd.p );
}
FileOperations const default_file_operations = { _win32_file_read, _win32_file_write, _win32_file_seek, _win32_file_close };
neverinline GEN_FILE_OPEN_PROC( _win32_file_open )
neverinline
GEN_FILE_OPEN_PROC( _win32_file_open )
{
DWORD desired_access;
DWORD creation_disposition;
@ -171,7 +182,8 @@ neverinline GEN_FILE_OPEN_PROC( _win32_file_open )
#else // POSIX
# include <fcntl.h>
internal GEN_FILE_SEEK_PROC( _posix_file_seek )
internal
GEN_FILE_SEEK_PROC( _posix_file_seek )
{
# if defined( GEN_SYSTEM_OSX )
s64 res = lseek( fd.i, offset, whence );
@ -185,10 +197,11 @@ internal GEN_FILE_SEEK_PROC( _posix_file_seek )
return true;
}
internal GEN_FILE_READ_AT_PROC( _posix_file_read )
internal
GEN_FILE_READ_AT_PROC( _posix_file_read )
{
unused( stop_at_newline );
sw res = pread( fd.i, buffer, size, offset );
ssize res = pread( fd.i, buffer, size, offset );
if ( res < 0 )
return false;
if ( bytes_read )
@ -196,19 +209,20 @@ internal GEN_FILE_READ_AT_PROC( _posix_file_read )
return true;
}
internal GEN_FILE_WRITE_AT_PROC( _posix_file_write )
internal
GEN_FILE_WRITE_AT_PROC( _posix_file_write )
{
sw res;
ssize res;
s64 curr_offset = 0;
_posix_file_seek( fd, 0, ESeekWhence_CURRENT, &curr_offset );
if ( curr_offset == offset )
{
// NOTE: Writing to stdout et al. doesn't like pwrite for numerous reasons
res = write( zpl_cast( int ) fd.i, buffer, size );
res = write( scast( int, fd.i), buffer, size );
}
else
{
res = pwrite( zpl_cast( int ) fd.i, buffer, size, offset );
res = pwrite( scast( int, fd.i), buffer, size, offset );
}
if ( res < 0 )
return false;
@ -217,14 +231,16 @@ internal GEN_FILE_WRITE_AT_PROC( _posix_file_write )
return true;
}
internal GEN_FILE_CLOSE_PROC( _posix_file_close )
internal
GEN_FILE_CLOSE_PROC( _posix_file_close )
{
close( fd.i );
}
FileOperations const default_file_operations = { _posix_file_read, _posix_file_write, _posix_file_seek, _posix_file_close };
GEN_NEVER_INLINE GEN_FILE_OPEN_PROC( _posix_file_open )
neverinline
GEN_FILE_OPEN_PROC( _posix_file_open )
{
s32 os_mode;
switch ( mode & GEN_FILE_MODES )
@ -287,7 +303,7 @@ FileInfo* file_get_standard( FileStandardType std )
if ( ! _std_file_set )
{
# define GEN__SET_STD_FILE( type, v ) \
_std_files[ type ].fd.p = v; \
_std_files[ type ].fd.p = v; \
_std_files[ type ].ops = default_file_operations
GEN__SET_STD_FILE( EFileStandard_INPUT, GetStdHandle( STD_INPUT_HANDLE ) );
GEN__SET_STD_FILE( EFileStandard_OUTPUT, GetStdHandle( STD_OUTPUT_HANDLE ) );
@ -324,7 +340,7 @@ FileError file_close( FileInfo* f )
return EFileError_INVALID;
if ( f->filename )
free( heap(), zpl_cast( char* ) f->filename );
free( heap(), ccast( char*, f->filename ));
#if defined( GEN_SYSTEM_WINDOWS )
if ( f->fd.p == INVALID_HANDLE_VALUE )
@ -359,14 +375,14 @@ FileError file_close( FileInfo* f )
FileError file_new( FileInfo* f, FileDescriptor fd, FileOperations ops, char const* filename )
{
FileError err = EFileError_NONE;
sw len = str_len( filename );
ssize len = str_len( filename );
f->ops = ops;
f->fd = fd;
f->dir = nullptr;
f->last_write_time = 0;
f->filename = alloc_array( heap(), char, len + 1 );
mem_copy( zpl_cast( char* ) f->filename, zpl_cast( char* ) filename, len + 1 );
mem_copy( ccast( char*, f->filename), ccast( char*, filename), len + 1 );
return err;
}
@ -425,7 +441,7 @@ FileContents file_read_contents( AllocatorInfo a, b32 zero_terminate, char const
if ( file_open( &file, filepath ) == EFileError_NONE )
{
sw fsize = zpl_cast( sw ) file_size( &file );
ssize fsize = scast( ssize , file_size( &file ));
if ( fsize > 0 )
{
result.data = alloc( a, zero_terminate ? fsize + 1 : fsize );
@ -433,7 +449,7 @@ FileContents file_read_contents( AllocatorInfo a, b32 zero_terminate, char const
file_read_at( &file, result.data, result.size, 0 );
if ( zero_terminate )
{
u8* str = zpl_cast( u8* ) result.data;
u8* str = rcast( u8*, result.data);
str[ fsize ] = '\0';
}
}
@ -447,26 +463,28 @@ struct _memory_fd
{
u8 magic;
u8* buf; //< zpl_array OR plain buffer if we can't write
sw cursor;
ssize cursor;
AllocatorInfo allocator;
FileStreamFlags flags;
sw cap;
ssize cap;
};
#define GEN__FILE_STREAM_FD_MAGIC 37
GEN_DEF_INLINE FileDescriptor _file_stream_fd_make( _memory_fd* d );
GEN_DEF_INLINE _memory_fd* _file_stream_from_fd( FileDescriptor fd );
FileDescriptor _file_stream_fd_make( _memory_fd* d );
_memory_fd* _file_stream_from_fd( FileDescriptor fd );
GEN_IMPL_INLINE FileDescriptor _file_stream_fd_make( _memory_fd* d )
inline
FileDescriptor _file_stream_fd_make( _memory_fd* d )
{
FileDescriptor fd = { 0 };
fd.p = ( void* )d;
return fd;
}
GEN_IMPL_INLINE _memory_fd* _file_stream_from_fd( FileDescriptor fd )
inline
_memory_fd* _file_stream_from_fd( FileDescriptor fd )
{
_memory_fd* d = ( _memory_fd* )fd.p;
GEN_ASSERT( d->magic == GEN__FILE_STREAM_FD_MAGIC );
@ -501,7 +519,7 @@ b8 file_stream_new( FileInfo* file, AllocatorInfo allocator )
return true;
}
b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, sw size, FileStreamFlags flags )
b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, ssize size, FileStreamFlags flags )
{
GEN_ASSERT_NOT_NULL( file );
_memory_fd* d = ( _memory_fd* )alloc( allocator, size_of( _memory_fd ) );
@ -538,7 +556,7 @@ b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, sw siz
return true;
}
u8* file_stream_buf( FileInfo* file, sw* size )
u8* file_stream_buf( FileInfo* file, ssize* size )
{
GEN_ASSERT_NOT_NULL( file );
_memory_fd* d = _file_stream_from_fd( file->fd );
@ -547,10 +565,11 @@ u8* file_stream_buf( FileInfo* file, sw* size )
return d->buf;
}
internal GEN_FILE_SEEK_PROC( _memory_file_seek )
internal
GEN_FILE_SEEK_PROC( _memory_file_seek )
{
_memory_fd* d = _file_stream_from_fd( fd );
sw buflen = d->cap;
ssize buflen = d->cap;
if ( whence == ESeekWhence_BEGIN )
d->cursor = 0;
@ -563,7 +582,8 @@ internal GEN_FILE_SEEK_PROC( _memory_file_seek )
return true;
}
internal GEN_FILE_READ_AT_PROC( _memory_file_read )
internal
GEN_FILE_READ_AT_PROC( _memory_file_read )
{
// unused( stop_at_newline );
_memory_fd* d = _file_stream_from_fd( fd );
@ -573,23 +593,24 @@ internal GEN_FILE_READ_AT_PROC( _memory_file_read )
return true;
}
internal GEN_FILE_WRITE_AT_PROC( _memory_file_write )
internal
GEN_FILE_WRITE_AT_PROC( _memory_file_write )
{
_memory_fd* d = _file_stream_from_fd( fd );
if ( ! ( d->flags & ( EFileStream_CLONE_WRITABLE | EFileStream_WRITABLE ) ) )
return false;
sw buflen = d->cap;
sw extralen = max( 0, size - ( buflen - offset ) );
sw rwlen = size - extralen;
sw new_cap = buflen + extralen;
ssize buflen = d->cap;
ssize extralen = max( 0, size - ( buflen - offset ) );
ssize rwlen = size - extralen;
ssize new_cap = buflen + extralen;
if ( d->flags & EFileStream_CLONE_WRITABLE )
{
Array<u8> arr = { d->buf };
if ( arr.get_header()->Capacity < new_cap )
if ( arr.get_header()->Capacity < usize(new_cap) )
{
if ( ! arr.grow( ( s64 )( new_cap ) ) )
return false;
@ -617,7 +638,8 @@ internal GEN_FILE_WRITE_AT_PROC( _memory_file_write )
return true;
}
internal GEN_FILE_CLOSE_PROC( _memory_file_close )
internal
GEN_FILE_CLOSE_PROC( _memory_file_close )
{
_memory_fd* d = _file_stream_from_fd( fd );
AllocatorInfo allocator = d->allocator;

View File

@ -1,3 +1,8 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "strings.hpp"
#endif
#pragma region File Handling
typedef u32 FileMode;
@ -43,8 +48,8 @@ union FileDescriptor
typedef struct FileOperations FileOperations;
#define GEN_FILE_OPEN_PROC( name ) FileError name( FileDescriptor* fd, FileOperations* ops, FileMode mode, char const* filename )
#define GEN_FILE_READ_AT_PROC( name ) b32 name( FileDescriptor fd, void* buffer, sw size, s64 offset, sw* bytes_read, b32 stop_at_newline )
#define GEN_FILE_WRITE_AT_PROC( name ) b32 name( FileDescriptor fd, void const* buffer, sw size, s64 offset, sw* bytes_written )
#define GEN_FILE_READ_AT_PROC( name ) b32 name( FileDescriptor fd, void* buffer, ssize size, s64 offset, ssize* bytes_read, b32 stop_at_newline )
#define GEN_FILE_WRITE_AT_PROC( name ) b32 name( FileDescriptor fd, void const* buffer, ssize size, s64 offset, ssize* bytes_written )
#define GEN_FILE_SEEK_PROC( name ) b32 name( FileDescriptor fd, s64 offset, SeekWhenceType whence, s64* new_offset )
#define GEN_FILE_CLOSE_PROC( name ) void name( FileDescriptor fd )
@ -156,7 +161,7 @@ FileError file_open_mode( FileInfo* file, FileMode mode, char const* filename );
* @param buffer Buffer to read to
* @param size Size to read
*/
GEN_DEF_INLINE b32 file_read( FileInfo* file, void* buffer, sw size );
b32 file_read( FileInfo* file, void* buffer, ssize size );
/**
* Reads file at a specific offset
@ -166,7 +171,7 @@ GEN_DEF_INLINE b32 file_read( FileInfo* file, void* buffer, sw size );
* @param offset Offset to read from
* @param bytes_read How much data we've actually read
*/
GEN_DEF_INLINE b32 file_read_at( FileInfo* file, void* buffer, sw size, s64 offset );
b32 file_read_at( FileInfo* file, void* buffer, ssize size, s64 offset );
/**
* Reads file safely
@ -176,13 +181,13 @@ GEN_DEF_INLINE b32 file_read_at( FileInfo* file, void* buffer, sw size, s64 offs
* @param offset Offset to read from
* @param bytes_read How much data we've actually read
*/
GEN_DEF_INLINE b32 file_read_at_check( FileInfo* file, void* buffer, sw size, s64 offset, sw* bytes_read );
b32 file_read_at_check( FileInfo* file, void* buffer, ssize size, s64 offset, ssize* bytes_read );
struct FileContents
{
AllocatorInfo allocator;
void* data;
sw size;
ssize size;
};
constexpr b32 zero_terminate = true;
@ -209,20 +214,20 @@ s64 file_size( FileInfo* file );
* @param file
* @param offset Offset to seek to
*/
GEN_DEF_INLINE s64 file_seek( FileInfo* file, s64 offset );
s64 file_seek( FileInfo* file, s64 offset );
/**
* Seeks the file cursor to the end of the file
* @param file
*/
GEN_DEF_INLINE s64 file_seek_to_end( FileInfo* file );
s64 file_seek_to_end( FileInfo* file );
/**
* Returns the length from the beginning of the file we've read so far
* @param file
* @return Our current position in file
*/
GEN_DEF_INLINE s64 file_tell( FileInfo* file );
s64 file_tell( FileInfo* file );
/**
* Writes to a file
@ -230,7 +235,7 @@ GEN_DEF_INLINE s64 file_tell( FileInfo* file );
* @param buffer Buffer to read from
* @param size Size to read
*/
GEN_DEF_INLINE b32 file_write( FileInfo* file, void const* buffer, sw size );
b32 file_write( FileInfo* file, void const* buffer, ssize size );
/**
* Writes to file at a specific offset
@ -240,7 +245,7 @@ GEN_DEF_INLINE b32 file_write( FileInfo* file, void const* buffer, sw size );
* @param offset Offset to write to
* @param bytes_written How much data we've actually written
*/
GEN_DEF_INLINE b32 file_write_at( FileInfo* file, void const* buffer, sw size, s64 offset );
b32 file_write_at( FileInfo* file, void const* buffer, ssize size, s64 offset );
/**
* Writes to file safely
@ -250,88 +255,7 @@ GEN_DEF_INLINE b32 file_write_at( FileInfo* file, void const* buffer, sw size, s
* @param offset Offset to write to
* @param bytes_written How much data we've actually written
*/
GEN_DEF_INLINE b32 file_write_at_check( FileInfo* file, void const* buffer, sw size, s64 offset, sw* bytes_written );
GEN_IMPL_INLINE s64 file_seek( FileInfo* f, s64 offset )
{
s64 new_offset = 0;
if ( ! f->ops.read_at )
f->ops = default_file_operations;
f->ops.seek( f->fd, offset, ESeekWhence_BEGIN, &new_offset );
return new_offset;
}
GEN_IMPL_INLINE s64 file_seek_to_end( FileInfo* f )
{
s64 new_offset = 0;
if ( ! f->ops.read_at )
f->ops = default_file_operations;
f->ops.seek( f->fd, 0, ESeekWhence_END, &new_offset );
return new_offset;
}
GEN_IMPL_INLINE s64 file_tell( FileInfo* f )
{
s64 new_offset = 0;
if ( ! f->ops.read_at )
f->ops = default_file_operations;
f->ops.seek( f->fd, 0, ESeekWhence_CURRENT, &new_offset );
return new_offset;
}
GEN_IMPL_INLINE b32 file_read( FileInfo* f, void* buffer, sw size )
{
s64 cur_offset = file_tell( f );
b32 result = file_read_at( f, buffer, size, file_tell( f ) );
file_seek( f, cur_offset + size );
return result;
}
GEN_IMPL_INLINE b32 file_read_at( FileInfo* f, void* buffer, sw size, s64 offset )
{
return file_read_at_check( f, buffer, size, offset, NULL );
}
GEN_IMPL_INLINE b32 file_read_at_check( FileInfo* f, void* buffer, sw size, s64 offset, sw* bytes_read )
{
if ( ! f->ops.read_at )
f->ops = default_file_operations;
return f->ops.read_at( f->fd, buffer, size, offset, bytes_read, false );
}
GEN_IMPL_INLINE b32 file_write( FileInfo* f, void const* buffer, sw size )
{
s64 cur_offset = file_tell( f );
b32 result = file_write_at( f, buffer, size, file_tell( f ) );
file_seek( f, cur_offset + size );
return result;
}
GEN_IMPL_INLINE b32 file_write_at( FileInfo* f, void const* buffer, sw size, s64 offset )
{
return file_write_at_check( f, buffer, size, offset, NULL );
}
GEN_IMPL_INLINE b32 file_write_at_check( FileInfo* f, void const* buffer, sw size, s64 offset, sw* bytes_written )
{
if ( ! f->ops.read_at )
f->ops = default_file_operations;
return f->ops.write_at( f->fd, buffer, size, offset, bytes_written );
}
b32 file_write_at_check( FileInfo* file, void const* buffer, ssize size, s64 offset, ssize* bytes_written );
enum FileStreamFlags : u32
{
@ -358,15 +282,103 @@ b8 file_stream_new( FileInfo* file, AllocatorInfo allocator );
* @param size Buffer's size
* @param flags
*/
b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, sw size, FileStreamFlags flags );
b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, ssize size, FileStreamFlags flags );
/**
* Retrieves the stream's underlying buffer and buffer size.
* @param file memory stream
* @param size (Optional) buffer size
*/
u8* file_stream_buf( FileInfo* file, sw* size );
u8* file_stream_buf( FileInfo* file, ssize* size );
extern FileOperations const memory_file_operations;
inline
s64 file_seek( FileInfo* f, s64 offset )
{
s64 new_offset = 0;
if ( ! f->ops.read_at )
f->ops = default_file_operations;
f->ops.seek( f->fd, offset, ESeekWhence_BEGIN, &new_offset );
return new_offset;
}
inline
s64 file_seek_to_end( FileInfo* f )
{
s64 new_offset = 0;
if ( ! f->ops.read_at )
f->ops = default_file_operations;
f->ops.seek( f->fd, 0, ESeekWhence_END, &new_offset );
return new_offset;
}
inline
s64 file_tell( FileInfo* f )
{
s64 new_offset = 0;
if ( ! f->ops.read_at )
f->ops = default_file_operations;
f->ops.seek( f->fd, 0, ESeekWhence_CURRENT, &new_offset );
return new_offset;
}
inline
b32 file_read( FileInfo* f, void* buffer, ssize size )
{
s64 cur_offset = file_tell( f );
b32 result = file_read_at( f, buffer, size, file_tell( f ) );
file_seek( f, cur_offset + size );
return result;
}
inline
b32 file_read_at( FileInfo* f, void* buffer, ssize size, s64 offset )
{
return file_read_at_check( f, buffer, size, offset, NULL );
}
inline
b32 file_read_at_check( FileInfo* f, void* buffer, ssize size, s64 offset, ssize* bytes_read )
{
if ( ! f->ops.read_at )
f->ops = default_file_operations;
return f->ops.read_at( f->fd, buffer, size, offset, bytes_read, false );
}
inline
b32 file_write( FileInfo* f, void const* buffer, ssize size )
{
s64 cur_offset = file_tell( f );
b32 result = file_write_at( f, buffer, size, file_tell( f ) );
file_seek( f, cur_offset + size );
return result;
}
inline
b32 file_write_at( FileInfo* f, void const* buffer, ssize size, s64 offset )
{
return file_write_at_check( f, buffer, size, offset, NULL );
}
inline
b32 file_write_at_check( FileInfo* f, void const* buffer, ssize size, s64 offset, ssize* bytes_written )
{
if ( ! f->ops.read_at )
f->ops = default_file_operations;
return f->ops.write_at( f->fd, buffer, size, offset, bytes_written );
}
#pragma endregion File Handling

View File

@ -1,6 +0,0 @@
#pragma region Hashing
u32 crc32( void const* data, sw len );
u64 crc64( void const* data, sw len );
#pragma endregion Hashing

View File

@ -1,104 +0,0 @@
#pragma region Macros
#define zpl_cast( Type ) ( Type )
// Keywords
#define global static // Global variables
#define internal static // Internal linkage
#define local_persist static // Local Persisting variables
// Bits
#define bit( Value ) ( 1 << Value )
#define bitfield_is_equal( Type, Field, Mask ) ( (Type(Mask) & Type(Field)) == Type(Mask) )
// Casting
#define ccast( Type, Value ) ( * const_cast< Type* >( & (Value) ) )
#define pcast( Type, Value ) ( * reinterpret_cast< Type* >( & ( Value ) ) )
#define rcast( Type, Value ) reinterpret_cast< Type >( Value )
#define scast( Type, Value ) static_cast< Type >( Value )
// Num Arguments (Varadics)
#if defined(__GNUC__) || defined(__clang__)
// Supports 0-10 arguments
#define num_args_impl( _0, \
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
N, ... \
) N
// _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
// _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
// _41, _42, _43, _44, _45, _46, _47, _48, _49, _50,
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang)
#define num_args(...) \
num_args_impl(_, ## __VA_ARGS__, \
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, \
0 \
)
// 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
// 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
// 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
#else
// Supports 1-10 arguments
#define num_args_impl( \
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
N, ... \
) N
#define num_args(...) \
num_args_impl( __VA_ARGS__, \
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \
)
#endif
// Stringizing
#define stringize_va( ... ) #__VA_ARGS__
#define stringize( ... ) stringize_va( __VA_ARGS__ )
// Function do once
#define do_once() \
do \
{ \
static \
bool Done = false; \
if ( Done ) \
return; \
Done = true; \
} \
while(0)
#define do_once_start \
do \
{ \
static \
bool Done = false; \
if ( Done ) \
break; \
Done = true;
#define do_once_end \
} \
while(0);
#define clamp( x, lower, upper ) min( max( ( x ), ( lower ) ), ( upper ) )
#define count_of( x ) ( ( size_of( x ) / size_of( 0 [ x ] ) ) / ( ( sw )( ! ( size_of( x ) % size_of( 0 [ x ] ) ) ) ) )
#define is_between( x, lower, upper ) ( ( ( lower ) <= ( x ) ) && ( ( x ) <= ( upper ) ) )
#define max( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) )
#define min( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) )
#define size_of( x ) ( sw )( sizeof( x ) )
template< class Type >
void swap( Type& a, Type& b )
{
Type tmp = a;
a = b;
b = tmp;
}
#pragma endregion Macros

View File

@ -1,486 +0,0 @@
#pragma region Memory
#define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) )
#define megabytes( x ) ( kilobytes( x ) * ( s64 )( 1024 ) )
#define gigabytes( x ) ( megabytes( x ) * ( s64 )( 1024 ) )
#define terabytes( x ) ( gigabytes( x ) * ( s64 )( 1024 ) )
#define GEN__ONES ( zpl_cast( uw ) - 1 / GEN_U8_MAX )
#define GEN__HIGHS ( GEN__ONES * ( GEN_U8_MAX / 2 + 1 ) )
#define GEN__HAS_ZERO( x ) ( ( ( x )-GEN__ONES ) & ~( x )&GEN__HIGHS )
//! Checks if value is power of 2.
GEN_DEF_INLINE b32 is_power_of_two( sw x );
//! Aligns address to specified alignment.
GEN_DEF_INLINE void* align_forward( void* ptr, sw alignment );
//! Aligns value to a specified alignment.
GEN_DEF_INLINE s64 align_forward_i64( s64 value, sw alignment );
//! Moves pointer forward by bytes.
GEN_DEF_INLINE void* pointer_add( void* ptr, sw bytes );
//! Moves pointer forward by bytes.
GEN_DEF_INLINE void const* pointer_add_const( void const* ptr, sw bytes );
//! Calculates difference between two addresses.
GEN_DEF_INLINE sw pointer_diff( void const* begin, void const* end );
//! Copy non-overlapping memory from source to destination.
void* mem_copy( void* dest, void const* source, sw size );
//! Search for a constant value within the size limit at memory location.
void const* mem_find( void const* data, u8 byte_value, sw size );
//! Copy memory from source to destination.
GEN_DEF_INLINE void* mem_move( void* dest, void const* source, sw size );
//! Set constant value at memory location with specified size.
GEN_DEF_INLINE void* mem_set( void* data, u8 byte_value, sw size );
//! @param ptr Memory location to clear up.
//! @param size The size to clear up with.
GEN_DEF_INLINE void zero_size( void* ptr, sw size );
//! Clears up an item.
#define zero_item( t ) zero_size( ( t ), size_of( *( t ) ) ) // NOTE: Pass pointer of struct
//! Clears up an array.
#define zero_array( a, count ) zero_size( ( a ), size_of( *( a ) ) * count )
enum AllocType : u8
{
EAllocation_ALLOC,
EAllocation_FREE,
EAllocation_FREE_ALL,
EAllocation_RESIZE,
};
using AllocatorProc = void* ( void* allocator_data, AllocType type
, sw size, sw alignment
, void* old_memory, sw old_size
, u64 flags );
struct AllocatorInfo
{
AllocatorProc* Proc;
void* Data;
};
enum AllocFlag
{
ALLOCATOR_FLAG_CLEAR_TO_ZERO = bit( 0 ),
};
#ifndef GEN_DEFAULT_MEMORY_ALIGNMENT
# define GEN_DEFAULT_MEMORY_ALIGNMENT ( 2 * size_of( void* ) )
#endif
#ifndef GEN_DEFAULT_ALLOCATOR_FLAGS
# define GEN_DEFAULT_ALLOCATOR_FLAGS ( ALLOCATOR_FLAG_CLEAR_TO_ZERO )
#endif
//! Allocate memory with default alignment.
GEN_DEF_INLINE void* alloc( AllocatorInfo a, sw size );
//! Allocate memory with specified alignment.
GEN_DEF_INLINE void* alloc_align( AllocatorInfo a, sw size, sw alignment );
//! Free allocated memory.
GEN_DEF_INLINE void free( AllocatorInfo a, void* ptr );
//! Free all memory allocated by an allocator.
GEN_DEF_INLINE void free_all( AllocatorInfo a );
//! Resize an allocated memory.
GEN_DEF_INLINE void* resize( AllocatorInfo a, void* ptr, sw old_size, sw new_size );
//! Resize an allocated memory with specified alignment.
GEN_DEF_INLINE void* resize_align( AllocatorInfo a, void* ptr, sw old_size, sw new_size, sw alignment );
//! Allocate memory for an item.
#define alloc_item( allocator_, Type ) ( Type* )alloc( allocator_, size_of( Type ) )
//! Allocate memory for an array of items.
#define alloc_array( allocator_, Type, count ) ( Type* )alloc( allocator_, size_of( Type ) * ( count ) )
/* heap memory analysis tools */
/* define GEN_HEAP_ANALYSIS to enable this feature */
/* call zpl_heap_stats_init at the beginning of the entry point */
/* you can call zpl_heap_stats_check near the end of the execution to validate any possible leaks */
void heap_stats_init( void );
sw heap_stats_used_memory( void );
sw heap_stats_alloc_count( void );
void heap_stats_check( void );
//! Allocate/Resize memory using default options.
//! Use this if you don't need a "fancy" resize allocation
GEN_DEF_INLINE void* default_resize_align( AllocatorInfo a, void* ptr, sw old_size, sw new_size, sw alignment );
void* heap_allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags );
//! The heap allocator backed by operating system's memory manager.
constexpr AllocatorInfo heap( void ) { return { heap_allocator_proc, nullptr }; }
//! Helper to allocate memory using heap allocator.
#define malloc( sz ) alloc( heap(), sz )
//! Helper to free memory allocated by heap allocator.
#define mfree( ptr ) free( heap(), ptr )
GEN_IMPL_INLINE b32 is_power_of_two( sw x )
{
if ( x <= 0 )
return false;
return ! ( x & ( x - 1 ) );
}
GEN_IMPL_INLINE void* align_forward( void* ptr, sw alignment )
{
uptr p;
GEN_ASSERT( is_power_of_two( alignment ) );
p = zpl_cast( uptr ) ptr;
return zpl_cast( void* )( ( p + ( alignment - 1 ) ) & ~( alignment - 1 ) );
}
GEN_IMPL_INLINE s64 align_forward_i64( s64 value, sw alignment )
{
return value + ( alignment - value % alignment ) % alignment;
}
GEN_IMPL_INLINE void* pointer_add( void* ptr, sw bytes )
{
return zpl_cast( void* )( zpl_cast( u8* ) ptr + bytes );
}
GEN_IMPL_INLINE void const* pointer_add_const( void const* ptr, sw bytes )
{
return zpl_cast( void const* )( zpl_cast( u8 const* ) ptr + bytes );
}
GEN_IMPL_INLINE sw pointer_diff( void const* begin, void const* end )
{
return zpl_cast( sw )( zpl_cast( u8 const* ) end - zpl_cast( u8 const* ) begin );
}
GEN_IMPL_INLINE void* mem_move( void* dest, void const* source, sw n )
{
if ( dest == NULL )
{
return NULL;
}
u8* d = zpl_cast( u8* ) dest;
u8 const* s = zpl_cast( u8 const* ) source;
if ( d == s )
return d;
if ( s + n <= d || d + n <= s ) // NOTE: Non-overlapping
return mem_copy( d, s, n );
if ( d < s )
{
if ( zpl_cast( uptr ) s % size_of( sw ) == zpl_cast( uptr ) d % size_of( sw ) )
{
while ( zpl_cast( uptr ) d % size_of( sw ) )
{
if ( ! n-- )
return dest;
*d++ = *s++;
}
while ( n >= size_of( sw ) )
{
*zpl_cast( sw* ) d = *zpl_cast( sw* ) s;
n -= size_of( sw );
d += size_of( sw );
s += size_of( sw );
}
}
for ( ; n; n-- )
*d++ = *s++;
}
else
{
if ( ( zpl_cast( uptr ) s % size_of( sw ) ) == ( zpl_cast( uptr ) d % size_of( sw ) ) )
{
while ( zpl_cast( uptr )( d + n ) % size_of( sw ) )
{
if ( ! n-- )
return dest;
d[ n ] = s[ n ];
}
while ( n >= size_of( sw ) )
{
n -= size_of( sw );
*zpl_cast( sw* )( d + n ) = *zpl_cast( sw* )( s + n );
}
}
while ( n )
n--, d[ n ] = s[ n ];
}
return dest;
}
GEN_IMPL_INLINE void* mem_set( void* dest, u8 c, sw n )
{
if ( dest == NULL )
{
return NULL;
}
u8* s = zpl_cast( u8* ) dest;
sw k;
u32 c32 = ( ( u32 )-1 ) / 255 * c;
if ( n == 0 )
return dest;
s[ 0 ] = s[ n - 1 ] = c;
if ( n < 3 )
return dest;
s[ 1 ] = s[ n - 2 ] = c;
s[ 2 ] = s[ n - 3 ] = c;
if ( n < 7 )
return dest;
s[ 3 ] = s[ n - 4 ] = c;
if ( n < 9 )
return dest;
k = -zpl_cast( sptr ) s & 3;
s += k;
n -= k;
n &= -4;
*zpl_cast( u32* )( s + 0 ) = c32;
*zpl_cast( u32* )( s + n - 4 ) = c32;
if ( n < 9 )
return dest;
*zpl_cast( u32* )( s + 4 ) = c32;
*zpl_cast( u32* )( s + 8 ) = c32;
*zpl_cast( u32* )( s + n - 12 ) = c32;
*zpl_cast( u32* )( s + n - 8 ) = c32;
if ( n < 25 )
return dest;
*zpl_cast( u32* )( s + 12 ) = c32;
*zpl_cast( u32* )( s + 16 ) = c32;
*zpl_cast( u32* )( s + 20 ) = c32;
*zpl_cast( u32* )( s + 24 ) = c32;
*zpl_cast( u32* )( s + n - 28 ) = c32;
*zpl_cast( u32* )( s + n - 24 ) = c32;
*zpl_cast( u32* )( s + n - 20 ) = c32;
*zpl_cast( u32* )( s + n - 16 ) = c32;
k = 24 + ( zpl_cast( uptr ) s & 4 );
s += k;
n -= k;
{
u64 c64 = ( zpl_cast( u64 ) c32 << 32 ) | c32;
while ( n > 31 )
{
*zpl_cast( u64* )( s + 0 ) = c64;
*zpl_cast( u64* )( s + 8 ) = c64;
*zpl_cast( u64* )( s + 16 ) = c64;
*zpl_cast( u64* )( s + 24 ) = c64;
n -= 32;
s += 32;
}
}
return dest;
}
GEN_IMPL_INLINE void* alloc_align( AllocatorInfo a, sw size, sw alignment )
{
return a.Proc( a.Data, EAllocation_ALLOC, size, alignment, nullptr, 0, GEN_DEFAULT_ALLOCATOR_FLAGS );
}
GEN_IMPL_INLINE void* alloc( AllocatorInfo a, sw size )
{
return alloc_align( a, size, GEN_DEFAULT_MEMORY_ALIGNMENT );
}
GEN_IMPL_INLINE void free( AllocatorInfo a, void* ptr )
{
if ( ptr != nullptr )
a.Proc( a.Data, EAllocation_FREE, 0, 0, ptr, 0, GEN_DEFAULT_ALLOCATOR_FLAGS );
}
GEN_IMPL_INLINE void free_all( AllocatorInfo a )
{
a.Proc( a.Data, EAllocation_FREE_ALL, 0, 0, nullptr, 0, GEN_DEFAULT_ALLOCATOR_FLAGS );
}
GEN_IMPL_INLINE void* resize( AllocatorInfo a, void* ptr, sw old_size, sw new_size )
{
return resize_align( a, ptr, old_size, new_size, GEN_DEFAULT_MEMORY_ALIGNMENT );
}
GEN_IMPL_INLINE void* resize_align( AllocatorInfo a, void* ptr, sw old_size, sw new_size, sw alignment )
{
return a.Proc( a.Data, EAllocation_RESIZE, new_size, alignment, ptr, old_size, GEN_DEFAULT_ALLOCATOR_FLAGS );
}
GEN_IMPL_INLINE void* default_resize_align( AllocatorInfo a, void* old_memory, sw old_size, sw new_size, sw alignment )
{
if ( ! old_memory )
return alloc_align( a, new_size, alignment );
if ( new_size == 0 )
{
free( a, old_memory );
return nullptr;
}
if ( new_size < old_size )
new_size = old_size;
if ( old_size == new_size )
{
return old_memory;
}
else
{
void* new_memory = alloc_align( a, new_size, alignment );
if ( ! new_memory )
return nullptr;
mem_move( new_memory, old_memory, min( new_size, old_size ) );
free( a, old_memory );
return new_memory;
}
}
GEN_IMPL_INLINE void zero_size( void* ptr, sw size )
{
mem_set( ptr, 0, size );
}
struct Arena
{
static
void* allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags );
static
Arena init_from_memory( void* start, sw size )
{
return
{
{ nullptr, nullptr },
start,
size,
0,
0
};
}
static
Arena init_from_allocator( AllocatorInfo backing, sw size )
{
Arena result =
{
backing,
alloc( backing, size),
size,
0,
0
};
return result;
}
static
Arena init_sub( Arena& parent, sw size )
{
return init_from_allocator( parent.Backing, size );
}
sw alignment_of( sw alignment )
{
sw alignment_offset, result_pointer, mask;
GEN_ASSERT( is_power_of_two( alignment ) );
alignment_offset = 0;
result_pointer = (sw) PhysicalStart + TotalUsed;
mask = alignment - 1;
if ( result_pointer & mask )
alignment_offset = alignment - ( result_pointer & mask );
return alignment_offset;
}
void check()
{
GEN_ASSERT( TempCount == 0 );
}
void free()
{
if ( Backing.Proc )
{
gen::free( Backing, PhysicalStart );
PhysicalStart = nullptr;
}
}
sw size_remaining( sw alignment )
{
sw result = TotalSize - ( TotalUsed + alignment_of( alignment ) );
return result;
}
AllocatorInfo Backing;
void* PhysicalStart;
sw TotalSize;
sw TotalUsed;
sw TempCount;
operator AllocatorInfo()
{
return { allocator_proc, this };
}
};
struct Pool
{
static
void* allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags );
static
Pool init( AllocatorInfo backing, sw num_blocks, sw block_size )
{
return init_align( backing, num_blocks, block_size, GEN_DEFAULT_MEMORY_ALIGNMENT );
}
static
Pool init_align( AllocatorInfo backing, sw num_blocks, sw block_size, sw block_align );
void clear();
void free()
{
if ( Backing.Proc )
{
gen::free( Backing, PhysicalStart );
}
}
AllocatorInfo Backing;
void* PhysicalStart;
void* FreeList;
sw BlockSize;
sw BlockAlign;
sw TotalSize;
sw NumBlocks;
operator AllocatorInfo()
{
return { allocator_proc, this };
}
};
#pragma endregion Memory

View File

@ -1,60 +0,0 @@
#pragma region Printing
struct FileInfo;
#ifndef GEN_PRINTF_MAXLEN
# define GEN_PRINTF_MAXLEN kilobytes(128)
#endif
// NOTE: A locally persisting buffer is used internally
char* str_fmt_buf ( char const* fmt, ... );
char* str_fmt_buf_va ( char const* fmt, va_list va );
sw str_fmt_va ( char* str, sw n, char const* fmt, va_list va );
sw str_fmt_file ( FileInfo* f, char const* fmt, ... );
sw str_fmt_file_va ( FileInfo* f, char const* fmt, va_list va );
sw str_fmt_out_va ( char const* fmt, va_list va );
sw str_fmt_out_err ( char const* fmt, ... );
sw str_fmt_out_err_va( char const* fmt, va_list va );
constexpr
char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED";
inline
sw log_fmt(char const* fmt, ...)
{
sw res;
va_list va;
va_start(va, fmt);
res = str_fmt_out_va(fmt, va);
va_end(va);
return res;
}
inline
sw fatal(char const* fmt, ...)
{
local_persist thread_local
char buf[GEN_PRINTF_MAXLEN] = { 0 };
va_list va;
#if Build_Debug
va_start(va, fmt);
str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
va_end(va);
assert_crash(buf);
return -1;
#else
va_start(va, fmt);
str_fmt_out_err_va( fmt, va);
va_end(va);
exit(1);
return -1;
#endif
}
#pragma endregion Printing

View File

@ -1,39 +0,0 @@
#pragma region String
String String::fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... )
{
va_list va;
va_start( va, fmt );
str_fmt_va( buf, buf_size, fmt, va );
va_end( va );
return make( allocator, buf );
}
String String::fmt_buf( AllocatorInfo allocator, char const* fmt, ... )
{
local_persist thread_local
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
va_list va;
va_start( va, fmt );
str_fmt_va( buf, GEN_PRINTF_MAXLEN, fmt, va );
va_end( va );
return make( allocator, buf );
}
bool String::append_fmt( char const* fmt, ... )
{
sw res;
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
va_list va;
va_start( va, fmt );
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
va_end( va );
return append( buf, res );
}
#pragma endregion String

View File

@ -1,375 +0,0 @@
#pragma region String
// Constant string with length.
struct StrC
{
sw Len;
char const* Ptr;
operator char const* () const
{
return Ptr;
}
};
#define txt_StrC( text ) StrC { sizeof( text ) - 1, text }
StrC to_StrC( char const* str )
{
return { str_len( str ), str };
}
sw StrC_len( char const* str )
{
return (sw) ( str - 1 );
}
// Dynamic String
// This is directly based off the ZPL string api.
// They used a header pattern
// I kept it for simplicty of porting but its not necessary to keep it that way.
struct String
{
struct Header
{
AllocatorInfo Allocator;
sw Length;
sw Capacity;
};
static
uw grow_formula( uw value )
{
// Using a very aggressive growth formula to reduce time mem_copying with recursive calls to append in this library.
return 4 * value + 8;
}
static
String make( AllocatorInfo allocator, char const* str )
{
sw length = str ? str_len( str ) : 0;
return make_length( allocator, str, length );
}
static
String make( AllocatorInfo allocator, StrC str )
{
return make_length( allocator, str.Ptr, str.Len );
}
static
String make_reserve( AllocatorInfo allocator, sw capacity )
{
constexpr sw header_size = sizeof( Header );
s32 alloc_size = header_size + capacity + 1;
void* allocation = alloc( allocator, alloc_size );
if ( allocation == nullptr )
return { nullptr };
mem_set( allocation, 0, alloc_size );
Header*
header = rcast(Header*, allocation);
header->Allocator = allocator;
header->Capacity = capacity;
header->Length = 0;
String result = { (char*)allocation + header_size };
return result;
}
static
String make_length( AllocatorInfo allocator, char const* str, sw length )
{
constexpr sw header_size = sizeof( Header );
s32 alloc_size = header_size + length + 1;
void* allocation = alloc( allocator, alloc_size );
if ( allocation == nullptr )
return { nullptr };
Header&
header = * rcast(Header*, allocation);
header = { allocator, length, length };
String result = { rcast( char*, allocation) + header_size };
if ( length && str )
mem_copy( result, str, length );
else
mem_set( result, 0, alloc_size - header_size );
result[ length ] = '\0';
return result;
}
static
String fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... );
static
String fmt_buf( AllocatorInfo allocator, char const* fmt, ... );
static
String join( AllocatorInfo allocator, char const** parts, sw num_parts, char const* glue )
{
String result = make( allocator, "" );
for ( sw idx = 0; idx < num_parts; ++idx )
{
result.append( parts[ idx ] );
if ( idx < num_parts - 1 )
result.append( glue );
}
return result;
}
static
bool are_equal( String lhs, String rhs )
{
if ( lhs.length() != rhs.length() )
return false;
for ( sw idx = 0; idx < lhs.length(); ++idx )
if ( lhs[ idx ] != rhs[ idx ] )
return false;
return true;
}
bool make_space_for( char const* str, sw add_len )
{
sw available = avail_space();
// NOTE: Return if there is enough space left
if ( available >= add_len )
{
return true;
}
else
{
sw new_len, old_size, new_size;
void* ptr;
void* new_ptr;
AllocatorInfo allocator = get_header().Allocator;
Header* header = nullptr;
new_len = grow_formula( length() + add_len );
ptr = & get_header();
old_size = size_of( Header ) + length() + 1;
new_size = size_of( Header ) + new_len + 1;
new_ptr = resize( allocator, ptr, old_size, new_size );
if ( new_ptr == nullptr )
return false;
header = zpl_cast( Header* ) new_ptr;
header->Allocator = allocator;
header->Capacity = new_len;
Data = rcast( char*, header + 1 );
return str;
}
}
bool append( char const* str )
{
return append( str, str_len( str ) );
}
bool append( char const* str, sw length )
{
if ( sptr(str) > 0 )
{
sw curr_len = this->length();
if ( ! make_space_for( str, length ) )
return false;
Header& header = get_header();
mem_copy( Data + curr_len, str, length );
Data[ curr_len + length ] = '\0';
header.Length = curr_len + length;
}
return str;
}
bool append( StrC str)
{
return append( str.Ptr, str.Len );
}
bool append( const String other )
{
return append( other.Data, other.length() );;
}
bool append_fmt( char const* fmt, ... );
sw avail_space() const
{
Header const&
header = * rcast( Header const*, Data - sizeof( Header ));
return header.Capacity - header.Length;
}
sw capacity() const
{
Header const&
header = * rcast( Header const*, Data - sizeof( Header ));
return header.Capacity;
}
void clear()
{
get_header().Length = 0;
}
String duplicate( AllocatorInfo allocator )
{
return make_length( allocator, Data, length() );
}
void free()
{
if ( ! Data )
return;
Header& header = get_header();
gen::free( header.Allocator, & header );
}
Header& get_header()
{
return *(Header*)(Data - sizeof(Header));
}
sw length() const
{
Header const&
header = * rcast( Header const*, Data - sizeof( Header ));
return header.Length;
}
void trim( char const* cut_set )
{
sw len = 0;
char* start_pos = Data;
char* end_pos = Data + length() - 1;
while ( start_pos <= end_pos && char_first_occurence( cut_set, *start_pos ) )
start_pos++;
while ( end_pos > start_pos && char_first_occurence( cut_set, *end_pos ) )
end_pos--;
len = scast( sw, ( start_pos > end_pos ) ? 0 : ( ( end_pos - start_pos ) + 1 ) );
if ( Data != start_pos )
mem_move( Data, start_pos, len );
Data[ len ] = '\0';
get_header().Length = len;
}
void trim_space()
{
return trim( " \t\r\n\v\f" );
}
// For-range support
char* begin()
{
return Data;
}
char* end()
{
Header const&
header = * rcast( Header const*, Data - sizeof( Header ));
return Data + header.Length;
}
operator bool()
{
return Data;
}
operator char* ()
{
return Data;
}
operator char const* () const
{
return Data;
}
operator StrC() const
{
return
{
length(),
Data
};
}
// Used with cached strings
// Essentially makes the string a string view.
String const& operator = ( String const& other ) const
{
if ( this == & other )
return *this;
String& this_ = ccast( String, *this );
this_.Data = other.Data;
return this_;
}
char& operator [] ( sw index )
{
return Data[ index ];
}
char const& operator [] ( sw index ) const
{
return Data[ index ];
}
char* Data = nullptr;
};
struct String_POD
{
char* Data;
operator String()
{
return * rcast(String*, this);
}
};
static_assert( sizeof( String_POD ) == sizeof( String ), "String is not a POD" );
#pragma endregion String

View File

@ -1,262 +0,0 @@
#pragma region String Ops
GEN_DEF_INLINE const char* char_first_occurence( const char* str, char c );
constexpr auto str_find = &char_first_occurence;
GEN_DEF_INLINE b32 char_is_alpha( char c );
GEN_DEF_INLINE b32 char_is_alphanumeric( char c );
GEN_DEF_INLINE b32 char_is_digit( char c );
GEN_DEF_INLINE b32 char_is_hex_digit( char c );
GEN_DEF_INLINE b32 char_is_space( char c );
GEN_DEF_INLINE char char_to_lower( char c );
GEN_DEF_INLINE char char_to_upper( char c );
GEN_DEF_INLINE s32 digit_to_int( char c );
GEN_DEF_INLINE s32 hex_digit_to_int( char c );
GEN_DEF_INLINE s32 str_compare( const char* s1, const char* s2 );
GEN_DEF_INLINE s32 str_compare( const char* s1, const char* s2, sw len );
GEN_DEF_INLINE char* str_copy( char* dest, const char* source, sw len );
GEN_DEF_INLINE sw str_copy_nulpad( char* dest, const char* source, sw len );
GEN_DEF_INLINE sw str_len( const char* str );
GEN_DEF_INLINE sw str_len( const char* str, sw max_len );
GEN_DEF_INLINE char* str_reverse( char* str ); // NOTE: ASCII only
GEN_DEF_INLINE char const* str_skip( char const* str, char c );
GEN_DEF_INLINE char const* str_skip_any( char const* str, char const* char_list );
GEN_DEF_INLINE char const* str_trim( char const* str, b32 catch_newline );
// NOTE: ASCII only
GEN_DEF_INLINE void str_to_lower( char* str );
GEN_DEF_INLINE void str_to_upper( char* str );
s64 str_to_i64( const char* str, char** end_ptr, s32 base );
void i64_to_str( s64 value, char* string, s32 base );
void u64_to_str( u64 value, char* string, s32 base );
f64 str_to_f64( const char* str, char** end_ptr );
GEN_IMPL_INLINE const char* char_first_occurence( const char* s, char c )
{
char ch = c;
for ( ; *s != ch; s++ )
{
if ( *s == '\0' )
return NULL;
}
return s;
}
GEN_IMPL_INLINE b32 char_is_alpha( char c )
{
if ( ( c >= 'A' && c <= 'Z' ) || ( c >= 'a' && c <= 'z' ) )
return true;
return false;
}
GEN_IMPL_INLINE b32 char_is_alphanumeric( char c )
{
return char_is_alpha( c ) || char_is_digit( c );
}
GEN_IMPL_INLINE b32 char_is_digit( char c )
{
if ( c >= '0' && c <= '9' )
return true;
return false;
}
GEN_IMPL_INLINE b32 char_is_hex_digit( char c )
{
if ( char_is_digit( c ) || ( c >= 'a' && c <= 'f' ) || ( c >= 'A' && c <= 'F' ) )
return true;
return false;
}
GEN_IMPL_INLINE b32 char_is_space( char c )
{
if ( c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v' )
return true;
return false;
}
GEN_IMPL_INLINE char char_to_lower( char c )
{
if ( c >= 'A' && c <= 'Z' )
return 'a' + ( c - 'A' );
return c;
}
GEN_IMPL_INLINE char char_to_upper( char c )
{
if ( c >= 'a' && c <= 'z' )
return 'A' + ( c - 'a' );
return c;
}
GEN_IMPL_INLINE s32 digit_to_int( char c )
{
return char_is_digit( c ) ? c - '0' : c - 'W';
}
GEN_IMPL_INLINE s32 hex_digit_to_int( char c )
{
if ( char_is_digit( c ) )
return digit_to_int( c );
else if ( is_between( c, 'a', 'f' ) )
return c - 'a' + 10;
else if ( is_between( c, 'A', 'F' ) )
return c - 'A' + 10;
return -1;
}
GEN_IMPL_INLINE s32 str_compare( const char* s1, const char* s2 )
{
while ( *s1 && ( *s1 == *s2 ) )
{
s1++, s2++;
}
return *( u8* )s1 - *( u8* )s2;
}
GEN_IMPL_INLINE s32 str_compare( const char* s1, const char* s2, sw len )
{
for ( ; len > 0; s1++, s2++, len-- )
{
if ( *s1 != *s2 )
return ( ( s1 < s2 ) ? -1 : +1 );
else if ( *s1 == '\0' )
return 0;
}
return 0;
}
GEN_IMPL_INLINE char* str_copy( char* dest, const char* source, sw len )
{
GEN_ASSERT_NOT_NULL( dest );
if ( source )
{
char* str = dest;
while ( len > 0 && *source )
{
*str++ = *source++;
len--;
}
while ( len > 0 )
{
*str++ = '\0';
len--;
}
}
return dest;
}
GEN_IMPL_INLINE sw str_copy_nulpad( char* dest, const char* source, sw len )
{
sw result = 0;
GEN_ASSERT_NOT_NULL( dest );
if ( source )
{
const char* source_start = source;
char* str = dest;
while ( len > 0 && *source )
{
*str++ = *source++;
len--;
}
while ( len > 0 )
{
*str++ = '\0';
len--;
}
result = source - source_start;
}
return result;
}
GEN_IMPL_INLINE sw str_len( const char* str )
{
if ( str == NULL )
{
return 0;
}
const char* p = str;
while ( *str )
str++;
return str - p;
}
GEN_IMPL_INLINE sw str_len( const char* str, sw max_len )
{
const char* end = zpl_cast( const char* ) mem_find( str, 0, max_len );
if ( end )
return end - str;
return max_len;
}
GEN_IMPL_INLINE char* str_reverse( char* str )
{
sw len = str_len( str );
char* a = str + 0;
char* b = str + len - 1;
len /= 2;
while ( len-- )
{
swap( *a, *b );
a++, b--;
}
return str;
}
GEN_IMPL_INLINE char const* str_skip( char const* str, char c )
{
while ( *str && *str != c )
{
++str;
}
return str;
}
GEN_IMPL_INLINE char const* str_skip_any( char const* str, char const* char_list )
{
char const* closest_ptr = zpl_cast( char const* ) pointer_add( ( void* )str, str_len( str ) );
sw char_list_count = str_len( char_list );
for ( sw i = 0; i < char_list_count; i++ )
{
char const* p = str_skip( str, char_list[ i ] );
closest_ptr = min( closest_ptr, p );
}
return closest_ptr;
}
GEN_IMPL_INLINE char const* str_trim( char const* str, b32 catch_newline )
{
while ( *str && char_is_space( *str ) && ( ! catch_newline || ( catch_newline && *str != '\n' ) ) )
{
++str;
}
return str;
}
GEN_IMPL_INLINE void str_to_lower( char* str )
{
if ( ! str )
return;
while ( *str )
{
*str = char_to_lower( *str );
str++;
}
}
GEN_IMPL_INLINE void str_to_upper( char* str )
{
if ( ! str )
return;
while ( *str )
{
*str = char_to_upper( *str );
str++;
}
}
#pragma endregion String Ops

View File

@ -1,3 +1,8 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "memory.cpp"
#endif
#pragma region Hashing
global u32 const _crc32_table[ 256 ] = {
@ -22,11 +27,11 @@ global u32 const _crc32_table[ 256 ] = {
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
u32 crc32( void const* data, sw len )
u32 crc32( void const* data, ssize len )
{
sw remaining;
u32 result = ~( zpl_cast( u32 ) 0 );
u8 const* c = zpl_cast( u8 const* ) data;
ssize remaining;
u32 result = ~( scast( u32, 0) );
u8 const* c = rcast( u8 const*, data);
for ( remaining = len; remaining--; c++ )
result = ( result >> 8 ) ^ ( _crc32_table[ ( result ^ *c ) & 0xff ] );
return ~result;
@ -72,14 +77,14 @@ global u64 const _crc64_table[ 256 ] = {
0xa6df411fbfb21ca3ull, 0xdc0731d78f8795daull, 0x536fa08fdfd90e51ull, 0x29b7d047efec8728ull,
};
u64 crc64( void const* data, sw len )
u64 crc64( void const* data, ssize len )
{
sw remaining;
u64 result = ( zpl_cast( u64 ) 0 );
u8 const* c = zpl_cast( u8 const* ) data;
ssize remaining;
u64 result = ( scast( u64, 0) );
u8 const* c = rcast( u8 const*, data);
for ( remaining = len; remaining--; c++ )
result = ( result >> 8 ) ^ ( _crc64_table[ ( result ^ *c ) & 0xff ] );
return result;
}
#pragma region Hashing
#pragma endregion Hashing

View File

@ -0,0 +1,11 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "containers.hpp"
#endif
#pragma region Hashing
u32 crc32( void const* data, ssize len );
u64 crc64( void const* data, ssize len );
#pragma endregion Hashing

View File

@ -0,0 +1,169 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
#endif
#pragma region Macros
#ifndef global
#define global static // Global variables
#endif
#ifndef internal
#define internal static // Internal linkage
#endif
#ifndef local_persist
#define local_persist static // Local Persisting variables
#endif
#ifndef api_c
#define api_c extern "C"
#endif
#ifndef bit
#define bit( Value ) ( 1 << Value )
#define bitfield_is_equal( Type, Field, Mask ) ( (Type(Mask) & Type(Field)) == Type(Mask) )
#endif
#ifndef ccast
#define ccast( type, value ) ( const_cast< type >( (value) ) )
#endif
#ifndef pcast
#define pcast( type, value ) ( * reinterpret_cast< type* >( & ( value ) ) )
#endif
#ifndef rcast
#define rcast( type, value ) reinterpret_cast< type >( value )
#endif
#ifndef scast
#define scast( type, value ) static_cast< type >( value )
#endif
#ifndef stringize
#define stringize_va( ... ) #__VA_ARGS__
#define stringize( ... ) stringize_va( __VA_ARGS__ )
#endif
#ifndef do_once
#define do_once( statement ) for ( local_persist b32 once = true; once; once = false, (statement) )
#define do_once_start \
do \
{ \
local_persist \
bool done = false; \
if ( done ) \
break; \
done = true;
#define do_once_end \
} \
while(0);
#endif
#ifndef labeled_scope_start
#define labeled_scope_start if ( false ) {
#define labeled_scope_end }
#endif
#ifndef compiler_decorated_func_name
# ifdef COMPILER_CLANG
# define compiler_decorated_func_name __PRETTY_NAME__
# elif defined(COMPILER_MSVC)
# define compiler_decorated_func_name __FUNCDNAME__
# endif
#endif
#ifndef num_args_impl
#define num_args_impl( _0, \
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
_31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
_41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
_51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
_61, _62, _63, _64, _65, _66, _67, _68, _69, _70, \
_71, _72, _73, _74, _75, _76, _77, _78, _79, _80, \
_81, _82, _83, _84, _85, _86, _87, _88, _89, _90, \
_91, _92, _93, _94, _95, _96, _97, _98, _99, _100, \
N, ... \
) N
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang)
#define num_args(...) \
num_args_impl(_, ## __VA_ARGS__, \
100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \
90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \
80, 79, 78, 77, 76, 75, 74, 73, 72, 71, \
70, 69, 68, 67, 66, 65, 64, 63, 62, 61, \
60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \
50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, \
0 \
)
#endif
#ifndef clamp
#define clamp( x, lower, upper ) min( max( ( x ), ( lower ) ), ( upper ) )
#endif
#ifndef count_of
#define count_of( x ) ( ( size_of( x ) / size_of( 0 [ x ] ) ) / ( ( ssize )( ! ( size_of( x ) % size_of( 0 [ x ] ) ) ) ) )
#endif
#ifndef is_between
#define is_between( x, lower, upper ) ( ( ( lower ) <= ( x ) ) && ( ( x ) <= ( upper ) ) )
#endif
#ifndef size_of
#define size_of( x ) ( ssize )( sizeof( x ) )
#endif
#ifndef max
#define max( a, b ) ( (a > b) ? (a) : (b) )
#endif
#ifndef min
#define min( a, b ) ( (a < b) ? (a) : (b) )
#endif
#if defined( _MSC_VER ) || defined( GEN_COMPILER_TINYC )
# define offset_of( Type, element ) ( ( GEN_NS( ssize ) ) & ( ( ( Type* )0 )->element ) )
#else
# define offset_of( Type, element ) __builtin_offsetof( Type, element )
#endif
#ifndef forceinline
# ifdef GEN_COMPILER_MSVC
# define forceinline __forceinline
# define neverinline __declspec( noinline )
# elif defined(GEN_COMPILER_GCC)
# define forceinline inline __attribute__((__always_inline__))
# define neverinline __attribute__( ( __noinline__ ) )
# elif defined(GEN_COMPILER_CLANG)
# if __has_attribute(__always_inline__)
# define forceinline inline __attribute__((__always_inline__))
# define neverinline __attribute__( ( __noinline__ ) )
# else
# define forceinline
# define neverinline
# endif
# else
# define forceinline
# define neverinline
# endif
#endif
#ifndef neverinline
# ifdef GEN_COMPILER_MSVC
# define neverinline __declspec( noinline )
# elif defined(GEN_COMPILER_GCC)
# define neverinline __attribute__( ( __noinline__ ) )
# elif defined(GEN_COMPILER_CLANG)
# if __has_attribute(__always_inline__)
# define neverinline __attribute__( ( __noinline__ ) )
# else
# define neverinline
# endif
# else
# define neverinline
# endif
#endif
#pragma endregion Macros

View File

@ -1,6 +1,11 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "printing.cpp"
#endif
#pragma region Memory
void* mem_copy( void* dest, void const* source, sw n )
void* mem_copy( void* dest, void const* source, ssize n )
{
if ( dest == NULL )
{
@ -10,25 +15,25 @@ void* mem_copy( void* dest, void const* source, sw n )
return memcpy( dest, source, n );
}
void const* mem_find( void const* data, u8 c, sw n )
void const* mem_find( void const* data, u8 c, ssize n )
{
u8 const* s = zpl_cast( u8 const* ) data;
while ( ( zpl_cast( uptr ) s & ( sizeof( uw ) - 1 ) ) && n && *s != c )
u8 const* s = rcast( u8 const*, data);
while ( ( rcast( uptr, s) & ( sizeof( usize ) - 1 ) ) && n && *s != c )
{
s++;
n--;
}
if ( n && *s != c )
{
sw const* w;
sw k = GEN__ONES * c;
w = zpl_cast( sw const* ) s;
while ( n >= size_of( sw ) && ! GEN__HAS_ZERO( *w ^ k ) )
ssize const* w;
ssize k = GEN__ONES * c;
w = rcast( ssize const*, s);
while ( n >= size_of( ssize ) && ! GEN__HAS_ZERO( *w ^ k ) )
{
w++;
n -= size_of( sw );
n -= size_of( ssize );
}
s = zpl_cast( u8 const* ) w;
s = rcast( u8 const*, w);
while ( n && *s != c )
{
s++;
@ -36,7 +41,7 @@ void const* mem_find( void const* data, u8 c, sw n )
}
}
return n ? zpl_cast( void const* ) s : NULL;
return n ? rcast( void const*, s ) : NULL;
}
#define GEN_HEAP_STATS_MAGIC 0xDEADC0DE
@ -44,8 +49,8 @@ void const* mem_find( void const* data, u8 c, sw n )
struct _heap_stats
{
u32 magic;
sw used_memory;
sw alloc_count;
ssize used_memory;
ssize alloc_count;
};
global _heap_stats _heap_stats_info;
@ -56,13 +61,13 @@ void heap_stats_init( void )
_heap_stats_info.magic = GEN_HEAP_STATS_MAGIC;
}
sw heap_stats_used_memory( void )
ssize heap_stats_used_memory( void )
{
GEN_ASSERT_MSG( _heap_stats_info.magic == GEN_HEAP_STATS_MAGIC, "heap_stats is not initialised yet, call heap_stats_init first!" );
return _heap_stats_info.used_memory;
}
sw heap_stats_alloc_count( void )
ssize heap_stats_alloc_count( void )
{
GEN_ASSERT_MSG( _heap_stats_info.magic == GEN_HEAP_STATS_MAGIC, "heap_stats is not initialised yet, call heap_stats_init first!" );
return _heap_stats_info.alloc_count;
@ -77,11 +82,11 @@ void heap_stats_check( void )
struct _heap_alloc_info
{
sw size;
ssize size;
void* physical_start;
};
void* heap_allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags )
void* heap_allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
{
void* ptr = NULL;
// unused( allocator_data );
@ -90,16 +95,16 @@ void* heap_allocator_proc( void* allocator_data, AllocType type, sw size, sw ali
alignment = GEN_DEFAULT_MEMORY_ALIGNMENT;
#ifdef GEN_HEAP_ANALYSIS
sw alloc_info_size = size_of( _heap_alloc_info );
sw alloc_info_remainder = ( alloc_info_size % alignment );
sw track_size = max( alloc_info_size, alignment ) + alloc_info_remainder;
ssize alloc_info_size = size_of( _heap_alloc_info );
ssize alloc_info_remainder = ( alloc_info_size % alignment );
ssize track_size = max( alloc_info_size, alignment ) + alloc_info_remainder;
switch ( type )
{
case EAllocation_FREE :
{
if ( ! old_memory )
break;
_heap_alloc_info* alloc_info = zpl_cast( _heap_alloc_info* ) old_memory - 1;
_heap_alloc_info* alloc_info = rcast( _heap_alloc_info*, old_memory) - 1;
_heap_stats_info.used_memory -= alloc_info->size;
_heap_stats_info.alloc_count--;
old_memory = alloc_info->physical_start;
@ -190,11 +195,11 @@ void* heap_allocator_proc( void* allocator_data, AllocType type, sw size, sw ali
#ifdef GEN_HEAP_ANALYSIS
if ( type == EAllocation_ALLOC )
{
_heap_alloc_info* alloc_info = zpl_cast( _heap_alloc_info* )( zpl_cast( char* ) ptr + alloc_info_remainder );
_heap_alloc_info* alloc_info = rcast( _heap_alloc_info*, rcast( char*, ptr) + alloc_info_remainder );
zero_item( alloc_info );
alloc_info->size = size - track_size;
alloc_info->physical_start = ptr;
ptr = zpl_cast( void* )( alloc_info + 1 );
ptr = rcast( void*, alloc_info + 1 );
_heap_stats_info.used_memory += alloc_info->size;
_heap_stats_info.alloc_count++;
}
@ -203,7 +208,133 @@ void* heap_allocator_proc( void* allocator_data, AllocType type, sw size, sw ali
return ptr;
}
void* Arena::allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags )
#pragma region VirtualMemory
VirtualMemory vm_from_memory( void* data, ssize size )
{
VirtualMemory vm;
vm.data = data;
vm.size = size;
return vm;
}
#if defined( GEN_SYSTEM_WINDOWS )
VirtualMemory vm_alloc( void* addr, ssize size )
{
VirtualMemory vm;
GEN_ASSERT( size > 0 );
vm.data = VirtualAlloc( addr, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE );
vm.size = size;
return vm;
}
b32 vm_free( VirtualMemory vm )
{
MEMORY_BASIC_INFORMATION info;
while ( vm.size > 0 )
{
if ( VirtualQuery( vm.data, &info, size_of( info ) ) == 0 )
return false;
if ( info.BaseAddress != vm.data || info.AllocationBase != vm.data || info.State != MEM_COMMIT || info.RegionSize > scast( usize, vm.size) )
{
return false;
}
if ( VirtualFree( vm.data, 0, MEM_RELEASE ) == 0 )
return false;
vm.data = pointer_add( vm.data, info.RegionSize );
vm.size -= info.RegionSize;
}
return true;
}
VirtualMemory vm_trim( VirtualMemory vm, ssize lead_size, ssize size )
{
VirtualMemory new_vm = { 0 };
void* ptr;
GEN_ASSERT( vm.size >= lead_size + size );
ptr = pointer_add( vm.data, lead_size );
vm_free( vm );
new_vm = vm_alloc( ptr, size );
if ( new_vm.data == ptr )
return new_vm;
if ( new_vm.data )
vm_free( new_vm );
return new_vm;
}
b32 vm_purge( VirtualMemory vm )
{
VirtualAlloc( vm.data, vm.size, MEM_RESET, PAGE_READWRITE );
// NOTE: Can this really fail?
return true;
}
ssize virtual_memory_page_size( ssize* alignment_out )
{
SYSTEM_INFO info;
GetSystemInfo( &info );
if ( alignment_out )
*alignment_out = info.dwAllocationGranularity;
return info.dwPageSize;
}
#else
# include <sys/mman.h>
# ifndef MAP_ANONYMOUS
# define MAP_ANONYMOUS MAP_ANON
# endif
VirtualMemory vm_alloc( void* addr, ssize size )
{
VirtualMemory vm;
GEN_ASSERT( size > 0 );
vm.data = mmap( addr, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0 );
vm.size = size;
return vm;
}
b32 vm_free( VirtualMemory vm )
{
munmap( vm.data, vm.size );
return true;
}
VirtualMemory vm_trim( VirtualMemory vm, ssize lead_size, ssize size )
{
void* ptr;
ssize trail_size;
GEN_ASSERT( vm.size >= lead_size + size );
ptr = pointer_add( vm.data, lead_size );
trail_size = vm.size - lead_size - size;
if ( lead_size != 0 )
vm_free( vm_from_memory(( vm.data, lead_size ) );
if ( trail_size != 0 )
vm_free( vm_from_memory( ptr, trail_size ) );
return vm_from_memory( ptr, size );
}
b32 vm_purge( VirtualMemory vm )
{
int err = madvise( vm.data, vm.size, MADV_DONTNEED );
return err != 0;
}
ssize virtual_memory_page_size( ssize* alignment_out )
{
// TODO: Is this always true?
ssize result = scast( ssize, sysconf( _SC_PAGE_SIZE ));
if ( alignment_out )
*alignment_out = result;
return result;
}
#endif
#pragma endregion VirtualMemory
void* Arena::allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
{
Arena* arena = rcast(Arena*, allocator_data);
void* ptr = NULL;
@ -215,13 +346,13 @@ void* Arena::allocator_proc( void* allocator_data, AllocType type, sw size, sw a
case EAllocation_ALLOC :
{
void* end = pointer_add( arena->PhysicalStart, arena->TotalUsed );
sw total_size = align_forward_i64( size, alignment );
ssize total_size = align_forward_i64( size, alignment );
// NOTE: Out of memory
if ( arena->TotalUsed + total_size > (sw) arena->TotalSize )
if ( arena->TotalUsed + total_size > (ssize) arena->TotalSize )
{
// zpl__printf_err("%s", "Arena out of memory\n");
fatal("Arena out of memory! (Possibly could not fit for the largest size Arena!!)");
GEN_FATAL("Arena out of memory! (Possibly could not fit for the largest size Arena!!)");
return nullptr;
}
@ -253,9 +384,9 @@ void* Arena::allocator_proc( void* allocator_data, AllocType type, sw size, sw a
return ptr;
}
void* Pool::allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags )
void* Pool::allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
{
Pool* pool = zpl_cast( Pool* ) allocator_data;
Pool* pool = rcast( Pool*, allocator_data);
void* ptr = NULL;
// unused( old_size );
@ -270,9 +401,9 @@ void* Pool::allocator_proc( void* allocator_data, AllocType type, sw size, sw al
GEN_ASSERT( alignment == pool->BlockAlign );
GEN_ASSERT( pool->FreeList != NULL );
next_free = *zpl_cast( uptr* ) pool->FreeList;
next_free = * rcast( uptr*, pool->FreeList);
ptr = pool->FreeList;
pool->FreeList = zpl_cast( void* ) next_free;
pool->FreeList = rcast( void*, next_free);
pool->TotalSize += pool->BlockSize;
if ( flags & ALLOCATOR_FLAG_CLEAR_TO_ZERO )
@ -286,8 +417,8 @@ void* Pool::allocator_proc( void* allocator_data, AllocType type, sw size, sw al
if ( old_memory == NULL )
return NULL;
next = zpl_cast( uptr* ) old_memory;
*next = zpl_cast( uptr ) pool->FreeList;
next = rcast( uptr*, old_memory);
*next = rcast( uptr, pool->FreeList);
pool->FreeList = old_memory;
pool->TotalSize -= pool->BlockSize;
}
@ -295,7 +426,7 @@ void* Pool::allocator_proc( void* allocator_data, AllocType type, sw size, sw al
case EAllocation_FREE_ALL :
{
sw actual_block_size, block_index;
ssize actual_block_size, block_index;
void* curr;
uptr* end;
@ -306,13 +437,13 @@ void* Pool::allocator_proc( void* allocator_data, AllocType type, sw size, sw al
curr = pool->PhysicalStart;
for ( block_index = 0; block_index < pool->NumBlocks - 1; block_index++ )
{
uptr* next = zpl_cast( uptr* ) curr;
*next = zpl_cast( uptr ) curr + actual_block_size;
uptr* next = rcast( uptr*, curr);
* next = rcast( uptr, curr) + actual_block_size;
curr = pointer_add( curr, actual_block_size );
}
end = zpl_cast( uptr* ) curr;
*end = zpl_cast( uptr ) NULL;
end = rcast( uptr*, curr);
* end = scast( uptr, NULL);
pool->FreeList = pool->PhysicalStart;
}
break;
@ -326,11 +457,11 @@ void* Pool::allocator_proc( void* allocator_data, AllocType type, sw size, sw al
return ptr;
}
Pool Pool::init_align( AllocatorInfo backing, sw num_blocks, sw block_size, sw block_align )
Pool Pool::init_align( AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align )
{
Pool pool = {};
sw actual_block_size, pool_size, block_index;
ssize actual_block_size, pool_size, block_index;
void *data, *curr;
uptr* end;
@ -366,7 +497,7 @@ Pool Pool::init_align( AllocatorInfo backing, sw num_blocks, sw block_size, sw b
void Pool::clear()
{
sw actual_block_size, block_index;
ssize actual_block_size, block_index;
void* curr;
uptr* end;

View File

@ -0,0 +1,571 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "debug.hpp"
#endif
#pragma region Memory
#define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) )
#define megabytes( x ) ( kilobytes( x ) * ( s64 )( 1024 ) )
#define gigabytes( x ) ( megabytes( x ) * ( s64 )( 1024 ) )
#define terabytes( x ) ( gigabytes( x ) * ( s64 )( 1024 ) )
#define GEN__ONES ( scast( GEN_NS usize, - 1) / GEN_U8_MAX )
#define GEN__HIGHS ( GEN__ONES * ( GEN_U8_MAX / 2 + 1 ) )
#define GEN__HAS_ZERO( x ) ( ( ( x ) - GEN__ONES ) & ~( x ) & GEN__HIGHS )
template< class Type >
void swap( Type& a, Type& b )
{
Type tmp = a;
a = b;
b = tmp;
}
//! Checks if value is power of 2.
b32 is_power_of_two( ssize x );
//! Aligns address to specified alignment.
void* align_forward( void* ptr, ssize alignment );
//! Aligns value to a specified alignment.
s64 align_forward_i64( s64 value, ssize alignment );
//! Moves pointer forward by bytes.
void* pointer_add( void* ptr, ssize bytes );
//! Moves pointer forward by bytes.
void const* pointer_add_const( void const* ptr, ssize bytes );
//! Calculates difference between two addresses.
ssize pointer_diff( void const* begin, void const* end );
//! Copy non-overlapping memory from source to destination.
void* mem_copy( void* dest, void const* source, ssize size );
//! Search for a constant value within the size limit at memory location.
void const* mem_find( void const* data, u8 byte_value, ssize size );
//! Copy memory from source to destination.
void* mem_move( void* dest, void const* source, ssize size );
//! Set constant value at memory location with specified size.
void* mem_set( void* data, u8 byte_value, ssize size );
//! @param ptr Memory location to clear up.
//! @param size The size to clear up with.
void zero_size( void* ptr, ssize size );
//! Clears up an item.
#define zero_item( t ) zero_size( ( t ), size_of( *( t ) ) ) // NOTE: Pass pointer of struct
//! Clears up an array.
#define zero_array( a, count ) zero_size( ( a ), size_of( *( a ) ) * count )
enum AllocType : u8
{
EAllocation_ALLOC,
EAllocation_FREE,
EAllocation_FREE_ALL,
EAllocation_RESIZE,
};
using AllocatorProc = void* ( void* allocator_data, AllocType type
, ssize size, ssize alignment
, void* old_memory, ssize old_size
, u64 flags );
struct AllocatorInfo
{
AllocatorProc* Proc;
void* Data;
};
enum AllocFlag
{
ALLOCATOR_FLAG_CLEAR_TO_ZERO = bit( 0 ),
};
#ifndef GEN_DEFAULT_MEMORY_ALIGNMENT
# define GEN_DEFAULT_MEMORY_ALIGNMENT ( 2 * size_of( void* ) )
#endif
#ifndef GEN_DEFAULT_ALLOCATOR_FLAGS
# define GEN_DEFAULT_ALLOCATOR_FLAGS ( ALLOCATOR_FLAG_CLEAR_TO_ZERO )
#endif
//! Allocate memory with default alignment.
void* alloc( AllocatorInfo a, ssize size );
//! Allocate memory with specified alignment.
void* alloc_align( AllocatorInfo a, ssize size, ssize alignment );
//! Free allocated memory.
void free( AllocatorInfo a, void* ptr );
//! Free all memory allocated by an allocator.
void free_all( AllocatorInfo a );
//! Resize an allocated memory.
void* resize( AllocatorInfo a, void* ptr, ssize old_size, ssize new_size );
//! Resize an allocated memory with specified alignment.
void* resize_align( AllocatorInfo a, void* ptr, ssize old_size, ssize new_size, ssize alignment );
//! Allocate memory for an item.
#define alloc_item( allocator_, Type ) ( Type* )alloc( allocator_, size_of( Type ) )
//! Allocate memory for an array of items.
#define alloc_array( allocator_, Type, count ) ( Type* )alloc( allocator_, size_of( Type ) * ( count ) )
/* heap memory analysis tools */
/* define GEN_HEAP_ANALYSIS to enable this feature */
/* call zpl_heap_stats_init at the beginning of the entry point */
/* you can call zpl_heap_stats_check near the end of the execution to validate any possible leaks */
void heap_stats_init( void );
ssize heap_stats_used_memory( void );
ssize heap_stats_alloc_count( void );
void heap_stats_check( void );
//! Allocate/Resize memory using default options.
//! Use this if you don't need a "fancy" resize allocation
void* default_resize_align( AllocatorInfo a, void* ptr, ssize old_size, ssize new_size, ssize alignment );
void* heap_allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags );
//! The heap allocator backed by operating system's memory manager.
constexpr AllocatorInfo heap( void ) { return { heap_allocator_proc, nullptr }; }
//! Helper to allocate memory using heap allocator.
#define malloc( sz ) alloc( heap(), sz )
//! Helper to free memory allocated by heap allocator.
#define mfree( ptr ) free( heap(), ptr )
struct VirtualMemory
{
void* data;
ssize size;
};
//! Initialize virtual memory from existing data.
VirtualMemory vm_from_memory( void* data, ssize size );
//! Allocate virtual memory at address with size.
//! @param addr The starting address of the region to reserve. If NULL, it lets operating system to decide where to allocate it.
//! @param size The size to serve.
VirtualMemory vm_alloc( void* addr, ssize size );
//! Release the virtual memory.
b32 vm_free( VirtualMemory vm );
//! Trim virtual memory.
VirtualMemory vm_trim( VirtualMemory vm, ssize lead_size, ssize size );
//! Purge virtual memory.
b32 gen_vm_purge( VirtualMemory vm );
//! Retrieve VM's page size and alignment.
ssize gen_virtual_memory_page_size( ssize* alignment_out );
struct Arena
{
static
void* allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags );
static
Arena init_from_memory( void* start, ssize size )
{
return
{
{ nullptr, nullptr },
start,
size,
0,
0
};
}
static
Arena init_from_allocator( AllocatorInfo backing, ssize size )
{
Arena result =
{
backing,
alloc( backing, size),
size,
0,
0
};
return result;
}
static
Arena init_sub( Arena& parent, ssize size )
{
return init_from_allocator( parent.Backing, size );
}
ssize alignment_of( ssize alignment )
{
ssize alignment_offset, result_pointer, mask;
GEN_ASSERT( is_power_of_two( alignment ) );
alignment_offset = 0;
result_pointer = (ssize) PhysicalStart + TotalUsed;
mask = alignment - 1;
if ( result_pointer & mask )
alignment_offset = alignment - ( result_pointer & mask );
return alignment_offset;
}
// This id is defined by Unreal for asserts
#pragma push_macro("check")
#undef check
void check()
{
GEN_ASSERT( TempCount == 0 );
}
#pragma pop_macro("check")
void free()
{
if ( Backing.Proc )
{
gen::free( Backing, PhysicalStart );
PhysicalStart = nullptr;
}
}
ssize size_remaining( ssize alignment )
{
ssize result = TotalSize - ( TotalUsed + alignment_of( alignment ) );
return result;
}
AllocatorInfo Backing;
void* PhysicalStart;
ssize TotalSize;
ssize TotalUsed;
ssize TempCount;
operator AllocatorInfo()
{
return { allocator_proc, this };
}
};
// Just a wrapper around using an arena with memory associated with its scope instead of from an allocator.
// Used for static segment or stack allocations.
template< s32 Size >
struct FixedArena
{
static
FixedArena init()
{
FixedArena result = { Arena::init_from_memory( result.memory, Size ), {0} };
return result;
}
ssize size_remaining( ssize alignment )
{
return arena.size_remaining( alignment );
}
operator AllocatorInfo()
{
return { Arena::allocator_proc, &arena };
}
Arena arena;
char memory[ Size ];
};
using Arena_1KB = FixedArena< kilobytes( 1 ) >;
using Arena_4KB = FixedArena< kilobytes( 4 ) >;
using Arena_8KB = FixedArena< kilobytes( 8 ) >;
using Arena_16KB = FixedArena< kilobytes( 16 ) >;
using Arena_32KB = FixedArena< kilobytes( 32 ) >;
using Arena_64KB = FixedArena< kilobytes( 64 ) >;
using Arena_128KB = FixedArena< kilobytes( 128 ) >;
using Arena_256KB = FixedArena< kilobytes( 256 ) >;
using Arena_512KB = FixedArena< kilobytes( 512 ) >;
using Arena_1MB = FixedArena< megabytes( 1 ) >;
using Arena_2MB = FixedArena< megabytes( 2 ) >;
using Arena_4MB = FixedArena< megabytes( 4 ) >;
struct Pool
{
static
void* allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags );
static
Pool init( AllocatorInfo backing, ssize num_blocks, ssize block_size )
{
return init_align( backing, num_blocks, block_size, GEN_DEFAULT_MEMORY_ALIGNMENT );
}
static
Pool init_align( AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align );
void clear();
void free()
{
if ( Backing.Proc )
{
gen::free( Backing, PhysicalStart );
}
}
AllocatorInfo Backing;
void* PhysicalStart;
void* FreeList;
ssize BlockSize;
ssize BlockAlign;
ssize TotalSize;
ssize NumBlocks;
operator AllocatorInfo()
{
return { allocator_proc, this };
}
};
inline
b32 is_power_of_two( ssize x ) {
if ( x <= 0 )
return false;
return ! ( x & ( x - 1 ) );
}
inline
mem_ptr align_forward( void* ptr, ssize alignment )
{
GEN_ASSERT( is_power_of_two( alignment ) );
uptr p = to_uptr(ptr);
uptr forward = (p + ( alignment - 1 ) ) & ~( alignment - 1 );
return to_mem_ptr(forward);
}
inline s64 align_forward_i64( s64 value, ssize alignment ) { return value + ( alignment - value % alignment ) % alignment; }
inline void* pointer_add ( void* ptr, ssize bytes ) { return rcast(void*, rcast( u8*, ptr) + bytes ); }
inline void const* pointer_add_const( void const* ptr, ssize bytes ) { return rcast(void const*, rcast( u8 const*, ptr) + bytes ); }
inline sptr pointer_diff( mem_ptr_const begin, mem_ptr_const end ) {
return scast( ssize, rcast( u8 const*, end) - rcast(u8 const*, begin) );
}
inline
void* mem_move( void* destination, void const* source, ssize byte_count )
{
if ( destination == NULL )
{
return NULL;
}
u8* dest_ptr = rcast( u8*, destination);
u8 const* src_ptr = rcast( u8 const*, source);
if ( dest_ptr == src_ptr )
return dest_ptr;
if ( src_ptr + byte_count <= dest_ptr || dest_ptr + byte_count <= src_ptr ) // NOTE: Non-overlapping
return mem_copy( dest_ptr, src_ptr, byte_count );
if ( dest_ptr < src_ptr )
{
if ( to_uptr(src_ptr) % size_of( ssize ) == to_uptr(dest_ptr) % size_of( ssize ) )
{
while ( pcast( uptr, dest_ptr) % size_of( ssize ) )
{
if ( ! byte_count-- )
return destination;
*dest_ptr++ = *src_ptr++;
}
while ( byte_count >= size_of( ssize ) )
{
* rcast(ssize*, dest_ptr) = * rcast(ssize const*, src_ptr);
byte_count -= size_of( ssize );
dest_ptr += size_of( ssize );
src_ptr += size_of( ssize );
}
}
for ( ; byte_count; byte_count-- )
*dest_ptr++ = *src_ptr++;
}
else
{
if ( ( to_uptr(src_ptr) % size_of( ssize ) ) == ( to_uptr(dest_ptr) % size_of( ssize ) ) )
{
while ( to_uptr( dest_ptr + byte_count ) % size_of( ssize ) )
{
if ( ! byte_count-- )
return destination;
dest_ptr[ byte_count ] = src_ptr[ byte_count ];
}
while ( byte_count >= size_of( ssize ) )
{
byte_count -= size_of( ssize );
* rcast(ssize*, dest_ptr + byte_count ) = * rcast( ssize const*, src_ptr + byte_count );
}
}
while ( byte_count )
byte_count--, dest_ptr[ byte_count ] = src_ptr[ byte_count ];
}
return destination;
}
inline
void* mem_set( void* destination, u8 fill_byte, ssize byte_count )
{
if ( destination == NULL )
{
return NULL;
}
ssize align_offset;
u8* dest_ptr = rcast( u8*, destination);
u32 fill_word = ( ( u32 )-1 ) / 255 * fill_byte;
if ( byte_count == 0 )
return destination;
dest_ptr[ 0 ] = dest_ptr[ byte_count - 1 ] = fill_byte;
if ( byte_count < 3 )
return destination;
dest_ptr[ 1 ] = dest_ptr[ byte_count - 2 ] = fill_byte;
dest_ptr[ 2 ] = dest_ptr[ byte_count - 3 ] = fill_byte;
if ( byte_count < 7 )
return destination;
dest_ptr[ 3 ] = dest_ptr[ byte_count - 4 ] = fill_byte;
if ( byte_count < 9 )
return destination;
align_offset = -to_sptr( dest_ptr ) & 3;
dest_ptr += align_offset;
byte_count -= align_offset;
byte_count &= -4;
* rcast( u32*, ( dest_ptr + 0 ) ) = fill_word;
* rcast( u32*, ( dest_ptr + byte_count - 4 ) ) = fill_word;
if ( byte_count < 9 )
return destination;
* rcast( u32*, dest_ptr + 4 ) = fill_word;
* rcast( u32*, dest_ptr + 8 ) = fill_word;
* rcast( u32*, dest_ptr + byte_count - 12 ) = fill_word;
* rcast( u32*, dest_ptr + byte_count - 8 ) = fill_word;
if ( byte_count < 25 )
return destination;
* rcast( u32*, dest_ptr + 12 ) = fill_word;
* rcast( u32*, dest_ptr + 16 ) = fill_word;
* rcast( u32*, dest_ptr + 20 ) = fill_word;
* rcast( u32*, dest_ptr + 24 ) = fill_word;
* rcast( u32*, dest_ptr + byte_count - 28 ) = fill_word;
* rcast( u32*, dest_ptr + byte_count - 24 ) = fill_word;
* rcast( u32*, dest_ptr + byte_count - 20 ) = fill_word;
* rcast( u32*, dest_ptr + byte_count - 16 ) = fill_word;
align_offset = 24 + to_uptr( dest_ptr ) & 4;
dest_ptr += align_offset;
byte_count -= align_offset;
{
u64 fill_doubleword = ( scast( u64, fill_word) << 32 ) | fill_word;
while ( byte_count > 31 )
{
* rcast( u64*, dest_ptr + 0 ) = fill_doubleword;
* rcast( u64*, dest_ptr + 8 ) = fill_doubleword;
* rcast( u64*, dest_ptr + 16 ) = fill_doubleword;
* rcast( u64*, dest_ptr + 24 ) = fill_doubleword;
byte_count -= 32;
dest_ptr += 32;
}
}
return destination;
}
inline
void* alloc_align( AllocatorInfo a, ssize size, ssize alignment ) {
return a.Proc( a.Data, EAllocation_ALLOC, size, alignment, nullptr, 0, GEN_DEFAULT_ALLOCATOR_FLAGS );
}
inline
void* alloc( AllocatorInfo a, ssize size ) {
return alloc_align( a, size, GEN_DEFAULT_MEMORY_ALIGNMENT );
}
inline
void free( AllocatorInfo a, void* ptr ) {
if ( ptr != nullptr )
a.Proc( a.Data, EAllocation_FREE, 0, 0, ptr, 0, GEN_DEFAULT_ALLOCATOR_FLAGS );
}
inline
void free_all( AllocatorInfo a ) {
a.Proc( a.Data, EAllocation_FREE_ALL, 0, 0, nullptr, 0, GEN_DEFAULT_ALLOCATOR_FLAGS );
}
inline
void* resize( AllocatorInfo a, void* ptr, ssize old_size, ssize new_size ) {
return resize_align( a, ptr, old_size, new_size, GEN_DEFAULT_MEMORY_ALIGNMENT );
}
inline
void* resize_align( AllocatorInfo a, void* ptr, ssize old_size, ssize new_size, ssize alignment ) {
return a.Proc( a.Data, EAllocation_RESIZE, new_size, alignment, ptr, old_size, GEN_DEFAULT_ALLOCATOR_FLAGS );
}
inline
void* default_resize_align( AllocatorInfo a, void* old_memory, ssize old_size, ssize new_size, ssize alignment )
{
if ( ! old_memory )
return alloc_align( a, new_size, alignment );
if ( new_size == 0 )
{
free( a, old_memory );
return nullptr;
}
if ( new_size < old_size )
new_size = old_size;
if ( old_size == new_size )
{
return old_memory;
}
else
{
void* new_memory = alloc_align( a, new_size, alignment );
if ( ! new_memory )
return nullptr;
mem_move( new_memory, old_memory, min( new_size, old_size ) );
free( a, old_memory );
return new_memory;
}
}
inline
void zero_size( void* ptr, ssize size ) {
mem_set( ptr, 0, size );
}
#pragma endregion Memory

View File

@ -1,3 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
#endif
#pragma region ADT
#define _adt_fprintf( s_, fmt_, ... ) \
@ -32,7 +36,7 @@ u8 adt_destroy_branch( ADT_Node* node )
GEN_ASSERT_NOT_NULL( node );
if ( ( node->type == EADT_TYPE_OBJECT || node->type == EADT_TYPE_ARRAY ) && node->nodes )
{
for ( sw i = 0; i < node->nodes.num(); ++i )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); ++i )
{
adt_destroy_branch( node->nodes + i );
}
@ -62,7 +66,7 @@ ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search )
return NULL;
}
for ( sw i = 0; i < node->nodes.num(); i++ )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
{
if ( ! str_compare( node->nodes[ i ].name, name ) )
{
@ -72,7 +76,7 @@ ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search )
if ( deep_search )
{
for ( sw i = 0; i < node->nodes.num(); i++ )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
{
ADT_Node* res = adt_find( node->nodes + i, name, deep_search );
@ -107,7 +111,7 @@ internal ADT_Node* _adt_get_value( ADT_Node* node, char const* value )
file_stream_open( &tmp, heap(), ( u8* )back, size_of( back ), EFileStream_WRITABLE );
adt_print_number( &tmp, node );
sw fsize = 0;
ssize fsize = 0;
u8* buf = file_stream_buf( &tmp, &fsize );
if ( ! str_compare( ( char const* )buf, value ) )
@ -128,7 +132,7 @@ internal ADT_Node* _adt_get_value( ADT_Node* node, char const* value )
internal ADT_Node* _adt_get_field( ADT_Node* node, char* name, char* value )
{
for ( sw i = 0; i < node->nodes.num(); i++ )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
{
if ( ! str_compare( node->nodes[ i ].name, name ) )
{
@ -203,7 +207,7 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
/* run a value comparison against any child that is an object node */
else if ( node->type == EADT_TYPE_ARRAY )
{
for ( sw i = 0; i < node->nodes.num(); i++ )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
{
ADT_Node* child = &node->nodes[ i ];
if ( child->type != EADT_TYPE_OBJECT )
@ -221,7 +225,7 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
/* [value] */
else
{
for ( sw i = 0; i < node->nodes.num(); i++ )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
{
ADT_Node* child = &node->nodes[ i ];
if ( _adt_get_value( child, l_b2 ) )
@ -252,8 +256,8 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
/* handle array index lookup */
else
{
sw idx = ( sw )str_to_i64( buf, NULL, 10 );
if ( idx >= 0 && idx < node->nodes.num() )
ssize idx = ( ssize )str_to_i64( buf, NULL, 10 );
if ( idx >= 0 && idx < scast(ssize, node->nodes.num()) )
{
found_node = &node->nodes[ idx ];
@ -268,7 +272,7 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
return found_node;
}
ADT_Node* adt_alloc_at( ADT_Node* parent, sw index )
ADT_Node* adt_alloc_at( ADT_Node* parent, ssize index )
{
if ( ! parent || ( parent->type != EADT_TYPE_OBJECT && parent->type != EADT_TYPE_ARRAY ) )
{
@ -278,7 +282,7 @@ ADT_Node* adt_alloc_at( ADT_Node* parent, sw index )
if ( ! parent->nodes )
return NULL;
if ( index < 0 || index > parent->nodes.num() )
if ( index < 0 || index > scast(ssize, parent->nodes.num()) )
return NULL;
ADT_Node o = { 0 };
@ -333,7 +337,7 @@ b8 adt_set_int( ADT_Node* obj, char const* name, s64 value )
return true;
}
ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, sw index )
ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, ssize index )
{
GEN_ASSERT_NOT_NULL( node );
GEN_ASSERT_NOT_NULL( new_parent );
@ -362,8 +366,8 @@ void adt_swap_nodes( ADT_Node* node, ADT_Node* other_node )
GEN_ASSERT_NOT_NULL( other_node );
ADT_Node* parent = node->parent;
ADT_Node* other_parent = other_node->parent;
sw index = ( pointer_diff( parent->nodes, node ) / size_of( ADT_Node ) );
sw index2 = ( pointer_diff( other_parent->nodes, other_node ) / size_of( ADT_Node ) );
ssize index = ( pointer_diff( parent->nodes, node ) / size_of( ADT_Node ) );
ssize index2 = ( pointer_diff( other_parent->nodes, other_node ) / size_of( ADT_Node ) );
ADT_Node temp = parent->nodes[ index ];
temp.parent = other_parent;
other_parent->nodes[ index2 ].parent = parent;
@ -376,7 +380,7 @@ void adt_remove_node( ADT_Node* node )
GEN_ASSERT_NOT_NULL( node );
GEN_ASSERT_NOT_NULL( node->parent );
ADT_Node* parent = node->parent;
sw index = ( pointer_diff( parent->nodes, node ) / size_of( ADT_Node ) );
ssize index = ( pointer_diff( parent->nodes, node ) / size_of( ADT_Node ) );
parent->nodes.remove_at( index );
}
@ -480,7 +484,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
node_type = EADT_TYPE_INTEGER;
neg_zero = false;
sw ib = 0;
ssize ib = 0;
char buf[ 48 ] = { 0 };
if ( *e == '+' )
@ -546,7 +550,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
f32 eb = 10;
char expbuf[ 6 ] = { 0 };
sw expi = 0;
ssize expi = 0;
if ( *e && ! ! str_find( "eE", *e ) )
{
@ -591,7 +595,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
#ifndef GEN_PARSER_DISABLE_ANALYSIS
char *q = buf, *base_string = q, *base_string2 = q;
base_string = zpl_cast( char* ) str_skip( base_string, '.' );
base_string = ccast( char*, str_skip( base_string, '.' ));
*base_string = '\0';
base_string2 = base_string + 1;
char* base_string_off = base_string2;
@ -799,7 +803,6 @@ ADT_Error adt_str_to_number_strict( ADT_Node* node )
# define GEN_CSV_ASSERT( msg )
#endif
u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim )
{
CSV_Error error = ECSV_Error__NONE;
@ -813,13 +816,13 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
char* beginChar;
char* endChar;
sw columnIndex = 0;
sw totalColumnIndex = 0;
ssize columnIndex = 0;
ssize totalColumnIndex = 0;
do
{
char delimiter = 0;
currentChar = zpl_cast( char* ) str_trim( currentChar, false );
currentChar = ccast( char*, str_trim( currentChar, false ));
if ( *currentChar == 0 )
break;
@ -843,7 +846,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
#endif
do
{
endChar = zpl_cast( char* ) str_skip( endChar, '"' );
endChar = ccast( char*, str_skip( endChar, '"' ));
if ( *endChar && *( endChar + 1 ) == '"' )
{
@ -862,7 +865,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
}
*endChar = 0;
currentChar = zpl_cast( char* ) str_trim( endChar + 1, true );
currentChar = ccast( char*, str_trim( endChar + 1, true ));
delimiter = * currentChar;
/* unescape escaped quotes (so that unescaped text escapes :) */
@ -899,7 +902,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
if ( * endChar )
{
currentChar = zpl_cast( char* ) str_trim( endChar, true );
currentChar = ccast( char*, str_trim( endChar, true ));
while ( char_is_space( *( endChar - 1 ) ) )
{
@ -943,7 +946,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
}
}
if ( columnIndex >= root->nodes.num() )
if ( columnIndex >= scast(ssize, root->nodes.num()) )
{
adt_append_arr( root, NULL );
}
@ -986,7 +989,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
/* consider first row as a header. */
if ( has_header )
{
for ( sw i = 0; i < root->nodes.num(); i++ )
for ( ssize i = 0; i < scast(ssize, root->nodes.num()); i++ )
{
CSV_Object* col = root->nodes + i;
CSV_Object* hdr = col->nodes;
@ -1054,11 +1057,11 @@ void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delimiter )
GEN_ASSERT_NOT_NULL( file );
GEN_ASSERT_NOT_NULL( obj );
GEN_ASSERT( obj->nodes );
sw cols = obj->nodes.num();
ssize cols = obj->nodes.num();
if ( cols == 0 )
return;
sw rows = obj->nodes[ 0 ].nodes.num();
ssize rows = obj->nodes[ 0 ].nodes.num();
if ( rows == 0 )
return;
@ -1066,7 +1069,7 @@ void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delimiter )
if ( has_headers )
{
for ( sw i = 0; i < cols; i++ )
for ( ssize i = 0; i < cols; i++ )
{
_csv_write_header( file, &obj->nodes[ i ] );
if ( i + 1 != cols )
@ -1077,9 +1080,9 @@ void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delimiter )
str_fmt_file( file, "\n" );
}
for ( sw r = 0; r < rows; r++ )
for ( ssize r = 0; r < rows; r++ )
{
for ( sw i = 0; i < cols; i++ )
for ( ssize i = 0; i < cols; i++ )
{
_csv_write_record( file, &obj->nodes[ i ].nodes[ r ] );
if ( i + 1 != cols )
@ -1096,7 +1099,8 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
FileInfo tmp;
file_stream_new( &tmp, a );
csv_write_delimiter( &tmp, obj, delimiter );
sw fsize;
ssize fsize;
u8* buf = file_stream_buf( &tmp, &fsize );
String output = String::make_length( a, ( char* )buf, fsize );
file_close( &tmp );
@ -1104,3 +1108,4 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
}
#pragma endregion CSV

View File

@ -1,3 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
#endif
#pragma region ADT
enum ADT_Type : u32
@ -174,7 +178,7 @@ ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search );
* @param index
* @return zpl_adt_node * node
*/
ADT_Node* adt_alloc_at( ADT_Node* parent, sw index );
ADT_Node* adt_alloc_at( ADT_Node* parent, ssize index );
/**
* @brief Allocate an unitialised node within a container.
@ -192,7 +196,7 @@ ADT_Node* adt_alloc( ADT_Node* parent );
* @param index
* @return zpl_adt_node * node
*/
ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, sw index );
ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, ssize index );
/**
* @brief Move an existing node to a new container.
@ -396,28 +400,31 @@ enum CSV_Error : u32
typedef ADT_Node CSV_Object;
GEN_DEF_INLINE u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header );
u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim );
void csv_free( CSV_Object* obj );
u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header );
u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim );
void csv_free( CSV_Object* obj );
GEN_DEF_INLINE void csv_write( FileInfo* file, CSV_Object* obj );
GEN_DEF_INLINE String csv_write_string( AllocatorInfo a, CSV_Object* obj );
void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delim );
String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delim );
void csv_write( FileInfo* file, CSV_Object* obj );
String csv_write_string( AllocatorInfo a, CSV_Object* obj );
void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delim );
String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delim );
/* inline */
GEN_IMPL_INLINE u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header )
inline
u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header )
{
return csv_parse_delimiter( root, text, allocator, has_header, ',' );
}
GEN_IMPL_INLINE void csv_write( FileInfo* file, CSV_Object* obj )
inline
void csv_write( FileInfo* file, CSV_Object* obj )
{
csv_write_delimiter( file, obj, ',' );
}
GEN_IMPL_INLINE String csv_write_string( AllocatorInfo a, CSV_Object* obj )
inline
String csv_write_string( AllocatorInfo a, CSV_Object* obj )
{
return csv_write_string_delimiter( a, obj, ',' );
}

View File

@ -1,3 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
#endif
#pragma region Platform Detection
/* Platform architecture */
@ -97,35 +101,25 @@
# define GEN_GCC_VERSION_CHECK(major,minor,patch) (0)
#endif
#define GEN_DEF_INLINE static
#define GEN_IMPL_INLINE static inline
#ifdef GEN_COMPILER_MSVC
# define forceinline __forceinline
# define neverinline __declspec( noinline )
#elif defined(GEN_COMPILER_GCC)
# define forceinline inline __attribute__((__always_inline__))
# define neverinline __attribute__( ( __noinline__ ) )
#elif defined(GEN_COMPILER_CLANG)
#if __has_attribute(__always_inline__)
# define forceinline inline __attribute__((__always_inline__))
# define neverinline __attribute__( ( __noinline__ ) )
#else
# define forceinline
# define neverinline
#endif
#else
# define forceinline
# define neverinline
#endif
#pragma endregion Platform Detection
#pragma region Mandatory Includes
# include <stdarg.h>
# include <stddef.h>
# if defined( GEN_SYSTEM_WINDOWS )
# include <intrin.h>
# endif
#pragma endregion Mandatory Includes
#ifdef GEN_DONT_USE_NAMESPACE
# define GEN_NS
# define GEN_NS_BEGIN
# define GEN_NS_END
#else
# define GEN_NS gen::
# define GEN_NS_BEGIN namespace gen {
# define GEN_NS_END }
#endif

View File

@ -1,3 +1,10 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "filesystem.hpp"
# include "strings.hpp"
# include "string_ops.cpp"
#endif
#pragma region Printing
enum
@ -34,10 +41,10 @@ struct _format_info
s32 precision;
};
internal sw _print_string( char* text, sw max_len, _format_info* info, char const* str )
internal ssize _print_string( char* text, ssize max_len, _format_info* info, char const* str )
{
sw res = 0, len = 0;
sw remaining = max_len;
ssize res = 0, len = 0;
ssize remaining = max_len;
char* begin = text;
if ( str == NULL && max_len >= 6 )
@ -47,7 +54,8 @@ internal sw _print_string( char* text, sw max_len, _format_info* info, char cons
}
if ( info && info->precision >= 0 )
len = str_len( str, info->precision );
// Made the design decision for this library that precision is the length of the string.
len = info->precision;
else
len = str_len( str );
@ -67,7 +75,7 @@ internal sw _print_string( char* text, sw max_len, _format_info* info, char cons
if ( info->width > res )
{
sw padding = info->width - len;
ssize padding = info->width - len;
char pad = ( info->flags & GEN_FMT_ZERO ) ? '0' : ' ';
while ( padding-- > 0 && remaining-- > 0 )
@ -78,7 +86,7 @@ internal sw _print_string( char* text, sw max_len, _format_info* info, char cons
{
if ( info && ( info->width > res ) )
{
sw padding = info->width - len;
ssize padding = info->width - len;
char pad = ( info->flags & GEN_FMT_ZERO ) ? '0' : ' ';
while ( padding-- > 0 && remaining-- > 0 )
*text++ = pad, res++;
@ -100,16 +108,16 @@ internal sw _print_string( char* text, sw max_len, _format_info* info, char cons
return res;
}
internal sw _print_char( char* text, sw max_len, _format_info* info, char arg )
internal ssize _print_char( char* text, ssize max_len, _format_info* info, char arg )
{
char str[ 2 ] = "";
str[ 0 ] = arg;
return _print_string( text, max_len, info, str );
}
internal sw _print_repeated_char( char* text, sw max_len, _format_info* info, char arg )
internal ssize _print_repeated_char( char* text, ssize max_len, _format_info* info, char arg )
{
sw res = 0;
ssize res = 0;
s32 rem = ( info ) ? ( info->width > 0 ) ? info->width : 1 : 1;
res = rem;
while ( rem-- > 0 )
@ -118,24 +126,24 @@ internal sw _print_repeated_char( char* text, sw max_len, _format_info* info, ch
return res;
}
internal sw _print_i64( char* text, sw max_len, _format_info* info, s64 value )
internal ssize _print_i64( char* text, ssize max_len, _format_info* info, s64 value )
{
char num[ 130 ];
i64_to_str( value, num, info ? info->base : 10 );
return _print_string( text, max_len, info, num );
}
internal sw _print_u64( char* text, sw max_len, _format_info* info, u64 value )
internal ssize _print_u64( char* text, ssize max_len, _format_info* info, u64 value )
{
char num[ 130 ];
u64_to_str( value, num, info ? info->base : 10 );
return _print_string( text, max_len, info, num );
}
internal sw _print_f64( char* text, sw max_len, _format_info* info, b32 is_hexadecimal, f64 arg )
internal ssize _print_f64( char* text, ssize max_len, _format_info* info, b32 is_hexadecimal, f64 arg )
{
// TODO: Handle exponent notation
sw width, len, remaining = max_len;
ssize width, len, remaining = max_len;
char* text_begin = text;
if ( arg )
@ -155,7 +163,7 @@ internal sw _print_f64( char* text, sw max_len, _format_info* info, b32 is_hexad
text++;
}
value = zpl_cast( u64 ) arg;
value = scast( u64, arg);
len = _print_u64( text, remaining, NULL, value );
text += len;
@ -176,14 +184,14 @@ internal sw _print_f64( char* text, sw max_len, _format_info* info, b32 is_hexad
text++;
while ( info->precision-- > 0 )
{
value = zpl_cast( u64 )( arg * mult );
value = scast( u64, arg * mult );
len = _print_u64( text, remaining, NULL, value );
text += len;
if ( len >= remaining )
remaining = min( remaining, 1 );
else
remaining -= len;
arg -= zpl_cast( f64 ) value / mult;
arg -= scast( f64, value / mult);
mult *= 10;
}
}
@ -231,15 +239,15 @@ internal sw _print_f64( char* text, sw max_len, _format_info* info, b32 is_hexad
return ( text - text_begin );
}
neverinline sw str_fmt_va( char* text, sw max_len, char const* fmt, va_list va )
neverinline ssize str_fmt_va( char* text, ssize max_len, char const* fmt, va_list va )
{
char const* text_begin = text;
sw remaining = max_len, res;
ssize remaining = max_len, res;
while ( *fmt )
{
_format_info info = { 0 };
sw len = 0;
ssize len = 0;
info.precision = -1;
while ( *fmt && *fmt != '%' && remaining )
@ -303,7 +311,7 @@ neverinline sw str_fmt_va( char* text, sw max_len, char const* fmt, va_list va )
}
else
{
info.width = zpl_cast( s32 ) str_to_i64( fmt, zpl_cast( char** ) & fmt, 10 );
info.width = scast( s32, str_to_i64( fmt, ccast( char**, & fmt), 10 ));
if ( info.width != 0 )
{
info.flags |= GEN_FMT_WIDTH;
@ -321,7 +329,7 @@ neverinline sw str_fmt_va( char* text, sw max_len, char const* fmt, va_list va )
}
else
{
info.precision = zpl_cast( s32 ) str_to_i64( fmt, zpl_cast( char** ) & fmt, 10 );
info.precision = scast( s32, str_to_i64( fmt, ccast( char**, & fmt), 10 ));
}
info.flags &= ~GEN_FMT_ZERO;
}
@ -403,13 +411,22 @@ neverinline sw str_fmt_va( char* text, sw max_len, char const* fmt, va_list va )
break;
case 'c' :
len = _print_char( text, remaining, &info, zpl_cast( char ) va_arg( va, int ) );
len = _print_char( text, remaining, &info, scast( char, va_arg( va, int ) ));
break;
case 's' :
len = _print_string( text, remaining, &info, va_arg( va, char* ) );
break;
case 'S':
{
String gen_str = String { va_arg( va, char*) };
info.precision = gen_str.length();
len = _print_string( text, remaining, &info, gen_str );
}
break;
case 'r' :
len = _print_repeated_char( text, remaining, &info, va_arg( va, int ) );
break;
@ -438,25 +455,25 @@ neverinline sw str_fmt_va( char* text, sw max_len, char const* fmt, va_list va )
switch ( info.flags & GEN_FMT_INTS )
{
case GEN_FMT_CHAR :
value = zpl_cast( u64 ) zpl_cast( u8 ) va_arg( va, int );
value = scast( u64, scast( u8, va_arg( va, int )));
break;
case GEN_FMT_SHORT :
value = zpl_cast( u64 ) zpl_cast( u16 ) va_arg( va, int );
value = scast( u64, scast( u16, va_arg( va, int )));
break;
case GEN_FMT_LONG :
value = zpl_cast( u64 ) va_arg( va, unsigned long );
case GEN_FMT_LONG:
value = scast( u64, va_arg( va, unsigned long ));
break;
case GEN_FMT_LLONG :
value = zpl_cast( u64 ) va_arg( va, unsigned long long );
value = scast( u64, va_arg( va, unsigned long long ));
break;
case GEN_FMT_SIZE :
value = zpl_cast( u64 ) va_arg( va, uw );
value = scast( u64, va_arg( va, usize ));
break;
case GEN_FMT_INTPTR :
value = zpl_cast( u64 ) va_arg( va, uptr );
value = scast( u64, va_arg( va, uptr ));
break;
default :
value = zpl_cast( u64 ) va_arg( va, unsigned int );
value = scast( u64, va_arg( va, unsigned int ));
break;
}
@ -468,25 +485,25 @@ neverinline sw str_fmt_va( char* text, sw max_len, char const* fmt, va_list va )
switch ( info.flags & GEN_FMT_INTS )
{
case GEN_FMT_CHAR :
value = zpl_cast( s64 ) zpl_cast( s8 ) va_arg( va, int );
value = scast( s64, scast( s8, va_arg( va, int )));
break;
case GEN_FMT_SHORT :
value = zpl_cast( s64 ) zpl_cast( s16 ) va_arg( va, int );
value = scast( s64, scast( s16, va_arg( va, int )));
break;
case GEN_FMT_LONG :
value = zpl_cast( s64 ) va_arg( va, long );
value = scast( s64, va_arg( va, long ));
break;
case GEN_FMT_LLONG :
value = zpl_cast( s64 ) va_arg( va, long long );
value = scast( s64, va_arg( va, long long ));
break;
case GEN_FMT_SIZE :
value = zpl_cast( s64 ) va_arg( va, uw );
value = scast( s64, va_arg( va, usize ));
break;
case GEN_FMT_INTPTR :
value = zpl_cast( s64 ) va_arg( va, uptr );
value = scast( s64, va_arg( va, uptr ));
break;
default :
value = zpl_cast( s64 ) va_arg( va, int );
value = scast( s64, va_arg( va, int ));
break;
}
@ -523,17 +540,17 @@ char* str_fmt_buf( char const* fmt, ... )
return str;
}
sw str_fmt_file_va( struct FileInfo* f, char const* fmt, va_list va )
ssize str_fmt_file_va( struct FileInfo* f, char const* fmt, va_list va )
{
local_persist thread_local char buf[ GEN_PRINTF_MAXLEN ];
sw len = str_fmt_va( buf, size_of( buf ), fmt, va );
ssize len = str_fmt_va( buf, size_of( buf ), fmt, va );
b32 res = file_write( f, buf, len - 1 ); // NOTE: prevent extra whitespace
return res ? len : -1;
}
sw str_fmt_file( struct FileInfo* f, char const* fmt, ... )
ssize str_fmt_file( struct FileInfo* f, char const* fmt, ... )
{
sw res;
ssize res;
va_list va;
va_start( va, fmt );
res = str_fmt_file_va( f, fmt, va );
@ -541,19 +558,29 @@ sw str_fmt_file( struct FileInfo* f, char const* fmt, ... )
return res;
}
sw str_fmt_out_va( char const* fmt, va_list va )
ssize str_fmt( char* str, ssize n, char const* fmt, ... )
{
ssize res;
va_list va;
va_start( va, fmt );
res = str_fmt_va( str, n, fmt, va );
va_end( va );
return res;
}
ssize str_fmt_out_va( char const* fmt, va_list va )
{
return str_fmt_file_va( file_get_standard( EFileStandard_OUTPUT ), fmt, va );
}
sw str_fmt_out_err_va( char const* fmt, va_list va )
ssize str_fmt_out_err_va( char const* fmt, va_list va )
{
return str_fmt_file_va( file_get_standard( EFileStandard_ERROR ), fmt, va );
}
sw str_fmt_out_err( char const* fmt, ... )
ssize str_fmt_out_err( char const* fmt, ... )
{
sw res;
ssize res;
va_list va;
va_start( va, fmt );
res = str_fmt_out_err_va( fmt, va );

View File

@ -0,0 +1,41 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "string_ops.hpp"
#endif
#pragma region Printing
struct FileInfo;
#ifndef GEN_PRINTF_MAXLEN
# define GEN_PRINTF_MAXLEN kilobytes(128)
#endif
// NOTE: A locally persisting buffer is used internally
char* str_fmt_buf ( char const* fmt, ... );
char* str_fmt_buf_va ( char const* fmt, va_list va );
ssize str_fmt ( char* str, ssize n, char const* fmt, ... );
ssize str_fmt_va ( char* str, ssize n, char const* fmt, va_list va );
ssize str_fmt_out_va ( char const* fmt, va_list va );
ssize str_fmt_out_err ( char const* fmt, ... );
ssize str_fmt_out_err_va( char const* fmt, va_list va );
ssize str_fmt_file ( FileInfo* f, char const* fmt, ... );
ssize str_fmt_file_va ( FileInfo* f, char const* fmt, va_list va );
constexpr
char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED";
inline
ssize log_fmt(char const* fmt, ...)
{
ssize res;
va_list va;
va_start(va, fmt);
res = str_fmt_out_va(fmt, va);
va_end(va);
return res;
}
#pragma endregion Printing

View File

@ -1,3 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# include "header_start.hpp"
#endif
#pragma region Macros and Includes
# include <stdio.h>

View File

@ -1,7 +1,13 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "string_ops.hpp"
# include "debug.cpp"
#endif
#pragma region String Ops
internal
sw _scan_zpl_i64( const char* text, s32 base, s64* value )
ssize _scan_zpl_i64( const char* text, s32 base, s64* value )
{
const char* text_begin = text;
s64 result = 0;
@ -50,7 +56,7 @@ global const char _num_to_char_table[] =
s64 str_to_i64( const char* str, char** end_ptr, s32 base )
{
sw len;
ssize len;
s64 value;
if ( ! base )
@ -79,7 +85,7 @@ void i64_to_str( s64 value, char* string, s32 base )
value = -value;
}
v = zpl_cast( u64 ) value;
v = scast( u64, value);
if ( v != 0 )
{
while ( v > 0 )
@ -201,7 +207,7 @@ f64 str_to_f64( const char* str, char** end_ptr )
result = sign * ( frac ? ( value / scale ) : ( value * scale ) );
if ( end_ptr )
*end_ptr = zpl_cast( char* ) str;
* end_ptr = rcast( char*, ccast(char*, str) );
return result;
}

View File

@ -0,0 +1,288 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "memory.hpp"
#endif
#pragma region String Ops
const char* char_first_occurence( const char* str, char c );
constexpr auto str_find = &char_first_occurence;
b32 char_is_alpha( char c );
b32 char_is_alphanumeric( char c );
b32 char_is_digit( char c );
b32 char_is_hex_digit( char c );
b32 char_is_space( char c );
char char_to_lower( char c );
char char_to_upper( char c );
s32 digit_to_int( char c );
s32 hex_digit_to_int( char c );
s32 str_compare( const char* s1, const char* s2 );
s32 str_compare( const char* s1, const char* s2, ssize len );
char* str_copy( char* dest, const char* source, ssize len );
ssize str_copy_nulpad( char* dest, const char* source, ssize len );
ssize str_len( const char* str );
ssize str_len( const char* str, ssize max_len );
char* str_reverse( char* str ); // NOTE: ASCII only
char const* str_skip( char const* str, char c );
char const* str_skip_any( char const* str, char const* char_list );
char const* str_trim( char const* str, b32 catch_newline );
// NOTE: ASCII only
void str_to_lower( char* str );
void str_to_upper( char* str );
s64 str_to_i64( const char* str, char** end_ptr, s32 base );
void i64_to_str( s64 value, char* string, s32 base );
void u64_to_str( u64 value, char* string, s32 base );
f64 str_to_f64( const char* str, char** end_ptr );
inline
const char* char_first_occurence( const char* s, char c )
{
char ch = c;
for ( ; *s != ch; s++ )
{
if ( *s == '\0' )
return NULL;
}
return s;
}
inline
b32 char_is_alpha( char c )
{
if ( ( c >= 'A' && c <= 'Z' ) || ( c >= 'a' && c <= 'z' ) )
return true;
return false;
}
inline
b32 char_is_alphanumeric( char c )
{
return char_is_alpha( c ) || char_is_digit( c );
}
inline
b32 char_is_digit( char c )
{
if ( c >= '0' && c <= '9' )
return true;
return false;
}
inline
b32 char_is_hex_digit( char c )
{
if ( char_is_digit( c ) || ( c >= 'a' && c <= 'f' ) || ( c >= 'A' && c <= 'F' ) )
return true;
return false;
}
inline
b32 char_is_space( char c )
{
if ( c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v' )
return true;
return false;
}
inline
char char_to_lower( char c )
{
if ( c >= 'A' && c <= 'Z' )
return 'a' + ( c - 'A' );
return c;
}
inline char char_to_upper( char c )
{
if ( c >= 'a' && c <= 'z' )
return 'A' + ( c - 'a' );
return c;
}
inline
s32 digit_to_int( char c )
{
return char_is_digit( c ) ? c - '0' : c - 'W';
}
inline
s32 hex_digit_to_int( char c )
{
if ( char_is_digit( c ) )
return digit_to_int( c );
else if ( is_between( c, 'a', 'f' ) )
return c - 'a' + 10;
else if ( is_between( c, 'A', 'F' ) )
return c - 'A' + 10;
return -1;
}
inline
s32 str_compare( const char* s1, const char* s2 )
{
while ( *s1 && ( *s1 == *s2 ) )
{
s1++, s2++;
}
return *( u8* )s1 - *( u8* )s2;
}
inline
s32 str_compare( const char* s1, const char* s2, ssize len )
{
for ( ; len > 0; s1++, s2++, len-- )
{
if ( *s1 != *s2 )
return ( ( s1 < s2 ) ? -1 : +1 );
else if ( *s1 == '\0' )
return 0;
}
return 0;
}
inline
char* str_copy( char* dest, const char* source, ssize len )
{
GEN_ASSERT_NOT_NULL( dest );
if ( source )
{
char* str = dest;
while ( len > 0 && *source )
{
*str++ = *source++;
len--;
}
while ( len > 0 )
{
*str++ = '\0';
len--;
}
}
return dest;
}
inline
ssize str_copy_nulpad( char* dest, const char* source, ssize len )
{
ssize result = 0;
GEN_ASSERT_NOT_NULL( dest );
if ( source )
{
const char* source_start = source;
char* str = dest;
while ( len > 0 && *source )
{
*str++ = *source++;
len--;
}
while ( len > 0 )
{
*str++ = '\0';
len--;
}
result = source - source_start;
}
return result;
}
inline
ssize str_len( const char* str )
{
if ( str == NULL )
{
return 0;
}
const char* p = str;
while ( *str )
str++;
return str - p;
}
inline
ssize str_len( const char* str, ssize max_len )
{
const char* end = rcast(const char*, mem_find( str, 0, max_len ));
if ( end )
return end - str;
return max_len;
}
inline
char* str_reverse( char* str )
{
ssize len = str_len( str );
char* a = str + 0;
char* b = str + len - 1;
len /= 2;
while ( len-- )
{
swap( *a, *b );
a++, b--;
}
return str;
}
inline
char const* str_skip( char const* str, char c )
{
while ( *str && *str != c )
{
++str;
}
return str;
}
inline
char const* str_skip_any( char const* str, char const* char_list )
{
char const* closest_ptr = rcast( char const*, pointer_add_const( rcast(void const*, str), str_len( str ) ));
ssize char_list_count = str_len( char_list );
for ( ssize i = 0; i < char_list_count; i++ )
{
char const* p = str_skip( str, char_list[ i ] );
closest_ptr = min( closest_ptr, p );
}
return closest_ptr;
}
inline
char const* str_trim( char const* str, b32 catch_newline )
{
while ( *str && char_is_space( *str ) && ( ! catch_newline || ( catch_newline && *str != '\n' ) ) )
{
++str;
}
return str;
}
inline
void str_to_lower( char* str )
{
if ( ! str )
return;
while ( *str )
{
*str = char_to_lower( *str );
str++;
}
}
inline
void str_to_upper( char* str )
{
if ( ! str )
return;
while ( *str )
{
*str = char_to_upper( *str );
str++;
}
}
#pragma endregion String Ops

View File

@ -0,0 +1,130 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "hashing.cpp"
#endif
#pragma region String
String String::fmt( AllocatorInfo allocator, char* buf, ssize buf_size, char const* fmt, ... )
{
va_list va;
va_start( va, fmt );
str_fmt_va( buf, buf_size, fmt, va );
va_end( va );
return make( allocator, buf );
}
String String::make_length( AllocatorInfo allocator, char const* str, ssize length )
{
constexpr ssize header_size = sizeof( Header );
s32 alloc_size = header_size + length + 1;
void* allocation = alloc( allocator, alloc_size );
if ( allocation == nullptr )
return { nullptr };
Header&
header = * rcast(Header*, allocation);
header = { allocator, length, length };
String result = { rcast( char*, allocation) + header_size };
if ( length && str )
mem_copy( result, str, length );
else
mem_set( result, 0, alloc_size - header_size );
result[ length ] = '\0';
return result;
}
String String::make_reserve( AllocatorInfo allocator, ssize capacity )
{
constexpr ssize header_size = sizeof( Header );
s32 alloc_size = header_size + capacity + 1;
void* allocation = alloc( allocator, alloc_size );
if ( allocation == nullptr )
return { nullptr };
mem_set( allocation, 0, alloc_size );
Header*
header = rcast(Header*, allocation);
header->Allocator = allocator;
header->Capacity = capacity;
header->Length = 0;
String result = { rcast(char*, allocation) + header_size };
return result;
}
String String::fmt_buf( AllocatorInfo allocator, char const* fmt, ... )
{
local_persist thread_local
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
va_list va;
va_start( va, fmt );
str_fmt_va( buf, GEN_PRINTF_MAXLEN, fmt, va );
va_end( va );
return make( allocator, buf );
}
bool String::append_fmt( char const* fmt, ... )
{
ssize res;
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
va_list va;
va_start( va, fmt );
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
va_end( va );
return append( buf, res );
}
bool String::make_space_for( char const* str, ssize add_len )
{
ssize available = avail_space();
// NOTE: Return if there is enough space left
if ( available >= add_len )
{
return true;
}
else
{
ssize new_len, old_size, new_size;
void* ptr;
void* new_ptr;
AllocatorInfo allocator = get_header().Allocator;
Header* header = nullptr;
new_len = grow_formula( length() + add_len );
ptr = & get_header();
old_size = size_of( Header ) + length() + 1;
new_size = size_of( Header ) + new_len + 1;
new_ptr = resize( allocator, ptr, old_size, new_size );
if ( new_ptr == nullptr )
return false;
header = rcast( Header*, new_ptr);
header->Allocator = allocator;
header->Capacity = new_len;
Data = rcast( char*, header + 1 );
return true;
}
}
#pragma endregion String

View File

@ -0,0 +1,415 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "hashing.hpp"
#endif
#pragma region Strings
// Constant string with length.
struct StrC
{
ssize Len;
char const* Ptr;
operator char const* () const { return Ptr; }
char const& operator[]( ssize index ) const { return Ptr[index]; }
};
#define cast_to_strc( str ) * rcast( StrC*, (str) - sizeof(ssize) )
#define txt( text ) StrC { sizeof( text ) - 1, ( text ) }
inline
StrC to_str( char const* str )
{
return { str_len( str ), str };
}
// Dynamic String
// This is directly based off the ZPL string api.
// They used a header pattern
// I kept it for simplicty of porting but its not necessary to keep it that way.
struct String
{
struct Header
{
AllocatorInfo Allocator;
ssize Capacity;
ssize Length;
};
static
usize grow_formula( usize value )
{
// Using a very aggressive growth formula to reduce time mem_copying with recursive calls to append in this library.
return 4 * value + 8;
}
static
String make( AllocatorInfo allocator, char const* str )
{
ssize length = str ? str_len( str ) : 0;
return make_length( allocator, str, length );
}
static
String make( AllocatorInfo allocator, StrC str )
{
return make_length( allocator, str.Ptr, str.Len );
}
static
String make_reserve( AllocatorInfo allocator, ssize capacity );
static
String make_length( AllocatorInfo allocator, char const* str, ssize length );
static
String fmt( AllocatorInfo allocator, char* buf, ssize buf_size, char const* fmt, ... );
static
String fmt_buf( AllocatorInfo allocator, char const* fmt, ... );
static
String join( AllocatorInfo allocator, char const** parts, ssize num_parts, char const* glue )
{
String result = make( allocator, "" );
for ( ssize idx = 0; idx < num_parts; ++idx )
{
result.append( parts[ idx ] );
if ( idx < num_parts - 1 )
result.append( glue );
}
return result;
}
static
bool are_equal( String lhs, String rhs )
{
if ( lhs.length() != rhs.length() )
return false;
for ( ssize idx = 0; idx < lhs.length(); ++idx )
if ( lhs[ idx ] != rhs[ idx ] )
return false;
return true;
}
static
bool are_equal( String lhs, StrC rhs )
{
if ( lhs.length() != (rhs.Len) )
return false;
for ( ssize idx = 0; idx < lhs.length(); ++idx )
if ( lhs[idx] != rhs[idx] )
return false;
return true;
}
bool make_space_for( char const* str, ssize add_len );
bool append( char c )
{
return append( & c, 1 );
}
bool append( char const* str )
{
return append( str, str_len( str ) );
}
bool append( char const* str, ssize length )
{
if ( sptr(str) > 0 )
{
ssize curr_len = this->length();
if ( ! make_space_for( str, length ) )
return false;
Header& header = get_header();
mem_copy( Data + curr_len, str, length );
Data[ curr_len + length ] = '\0';
header.Length = curr_len + length;
}
return str != nullptr;
}
bool append( StrC str)
{
return append( str.Ptr, str.Len );
}
bool append( const String other )
{
return append( other.Data, other.length() );
}
bool append_fmt( char const* fmt, ... );
ssize avail_space() const
{
Header const&
header = * rcast( Header const*, Data - sizeof( Header ));
return header.Capacity - header.Length;
}
char& back()
{
return Data[ length() - 1 ];
}
ssize capacity() const
{
Header const&
header = * rcast( Header const*, Data - sizeof( Header ));
return header.Capacity;
}
void clear()
{
get_header().Length = 0;
}
String duplicate( AllocatorInfo allocator ) const
{
return make_length( allocator, Data, length() );
}
void free()
{
if ( ! Data )
return;
Header& header = get_header();
gen::free( header.Allocator, & header );
}
Header& get_header()
{
return *(Header*)(Data - sizeof(Header));
}
ssize length() const
{
Header const&
header = * rcast( Header const*, Data - sizeof( Header ));
return header.Length;
}
b32 starts_with( StrC substring ) const
{
if (substring.Len > length())
return false;
b32 result = str_compare(Data, substring.Ptr, substring.Len ) == 0;
return result;
}
b32 starts_with( String substring ) const
{
if (substring.length() > length())
return false;
b32 result = str_compare(Data, substring, substring.length() - 1 ) == 0;
return result;
}
void skip_line()
{
#define current (*scanner)
char* scanner = Data;
while ( current != '\r' && current != '\n' )
{
++ scanner;
}
s32 new_length = scanner - Data;
if ( current == '\r' )
{
new_length += 1;
}
mem_move( Data, scanner, new_length );
Header* header = & get_header();
header->Length = new_length;
#undef current
}
void strip_space()
{
char* write_pos = Data;
char* read_pos = Data;
while ( * read_pos)
{
if ( ! char_is_space( *read_pos ))
{
*write_pos = *read_pos;
write_pos++;
}
read_pos++;
}
write_pos[0] = '\0'; // Null-terminate the modified string
// Update the length if needed
get_header().Length = write_pos - Data;
}
void trim( char const* cut_set )
{
ssize len = 0;
char* start_pos = Data;
char* end_pos = Data + length() - 1;
while ( start_pos <= end_pos && char_first_occurence( cut_set, *start_pos ) )
start_pos++;
while ( end_pos > start_pos && char_first_occurence( cut_set, *end_pos ) )
end_pos--;
len = scast( ssize, ( start_pos > end_pos ) ? 0 : ( ( end_pos - start_pos ) + 1 ) );
if ( Data != start_pos )
mem_move( Data, start_pos, len );
Data[ len ] = '\0';
get_header().Length = len;
}
void trim_space()
{
return trim( " \t\r\n\v\f" );
}
// Debug function that provides a copy of the string with whitespace characters visualized.
String visualize_whitespace() const
{
Header* header = (Header*)(Data - sizeof(Header));
String result = make_reserve(header->Allocator, length() * 2); // Assume worst case for space requirements.
for ( char c : *this )
{
switch ( c )
{
case ' ':
result.append( txt("·") );
break;
case '\t':
result.append( txt("") );
break;
case '\n':
result.append( txt("") );
break;
case '\r':
result.append( txt("") );
break;
case '\v':
result.append( txt("") );
break;
case '\f':
result.append( txt("") );
break;
default:
result.append(c);
break;
}
}
return result;
}
// For-range support
char* begin() const
{
return Data;
}
char* end() const
{
Header const&
header = * rcast( Header const*, Data - sizeof( Header ));
return Data + header.Length;
}
operator bool()
{
return Data != nullptr;
}
operator char* ()
{
return Data;
}
operator char const* () const
{
return Data;
}
operator StrC() const
{
return { length(), Data };
}
// Used with cached strings
// Essentially makes the string a string view.
String const& operator = ( String const& other ) const
{
if ( this == & other )
return *this;
String*
this_ = ccast(String*, this);
this_->Data = other.Data;
return *this;
}
char& operator [] ( ssize index )
{
return Data[ index ];
}
char const& operator [] ( ssize index ) const
{
return Data[ index ];
}
char* Data;
};
struct String_POD
{
char* Data;
};
static_assert( sizeof( String_POD ) == sizeof( String ), "String is not a POD" );
// Implements basic string interning. Data structure is based off the ZPL Hashtable.
using StringTable = HashTable<String const>;
// Represents strings cached with the string table.
// Should never be modified, if changed string is desired, cache_string( str ) another.
using StringCached = String const;
#pragma endregion Strings

View File

@ -1,3 +1,8 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "filesystem.cpp"
#endif
#pragma region Timing
#ifdef GEN_BENCHMARK
@ -18,7 +23,7 @@
{
u32 hi, lo;
__asm__ __volatile__( "rdtsc" : "=a"( lo ), "=d"( hi ) );
return ( zpl_cast( u64 ) lo ) | ( ( zpl_cast( u64 ) hi ) << 32 );
return scast( u64, lo ) | ( scast( u64, hi ) << 32 );
}
#elif defined( __powerpc__ )
u64 read_cpu_time_stamp_counter( void )

View File

@ -1,3 +1,8 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "filesystem.hpp"
#endif
#pragma region Timing
#ifdef GEN_BENCHMARK

View File

@ -1,5 +1,6 @@
Invalid
Untyped
NewLine
Comment
Access_Private
Access_Protected
@ -8,6 +9,10 @@ PlatformAttributes
Class
Class_Fwd
Class_Body
Constructor
Constructor_Fwd
Destructor
Destructor_Fwd
Enum
Enum_Fwd
Enum_Body
@ -32,7 +37,15 @@ Operator_Member_Fwd
Operator_Cast
Operator_Cast_Fwd
Parameters
Preprocessor_Include
Preprocess_Define
Preprocess_Include
Preprocess_If
Preprocess_IfDef
Preprocess_IfNotDef
Preprocess_ElIf
Preprocess_Else
Preprocess_EndIf
Preprocess_Pragma
Specifiers
Struct
Struct_Fwd
1 Invalid
2 Untyped
3 NewLine
4 Comment
5 Access_Private
6 Access_Protected
9 Class
10 Class_Fwd
11 Class_Body
12 Constructor
13 Constructor_Fwd
14 Destructor
15 Destructor_Fwd
16 Enum
17 Enum_Fwd
18 Enum_Body
37 Operator_Cast
38 Operator_Cast_Fwd
39 Parameters
40 Preprocessor_Include Preprocess_Define
41 Preprocess_Include
42 Preprocess_If
43 Preprocess_IfDef
44 Preprocess_IfNotDef
45 Preprocess_ElIf
46 Preprocess_Else
47 Preprocess_EndIf
48 Preprocess_Pragma
49 Specifiers
50 Struct
51 Struct_Fwd

View File

@ -0,0 +1,144 @@
Invalid
Untyped
NewLine
Comment
Access_Private
Access_Protected
Access_Public
PlatformAttributes
Class
Class_Fwd
Class_Body
Constructor
Constructor_Fwd
Destructor
Destructor_Fwd
Enum
Enum_Fwd
Enum_Body
Enum_Class
Enum_Class_Fwd
Execution
Expression
Expr_Identifier
Expr_NumericLiteral
Expr_StringLiteral
Expr_Alignof
Expr_ProcCall
Expr_Assign_Add
Expr_Assign_Subtract
Expr_Assign_Multiply
Expr_Assign_Divide
Expr_Assign_Modulo
Expr_Assign_Bitwise_And
Expr_Assign_Bitwise_Or
Expr_Assign_Bitwise_XOr
Expr_Assign_LeftShift
Expr_Assign_RightShift
Expr_CStyleCast
Expr_FunctionalCast
Expr_ConstCast
Expr_DynamicCast
Expr_ReinterpretCast
Expr_StaticCast
Expr_Unary_Add
Expr_Unary_Minus
Expr_Unary_Not
Expr_Unary_Increment
Expr_Unary_Decrement
Expr_Indirection
Expr_AddressOf,
Expr_UnaryPost_Increment
Expr_UnaryPost_Decrement
Expr_Subscript
Expr_Binary_Add
Expr_Binary_Subtract
Expr_Binary_Multiply
Expr_Binary_Divide
Expr_Binary_Modulo
Expr_Binary_Bitwise_And
Expr_Binary_Bitwise_Or
Expr_Binary_Bitwise_XOr
Expr_Binary_Bitwise_LeftShift
Expr_Binary_Bitwise_RightShift
Expr_Binary_Logical_Not
Expr_Binary_Logical_And
Expr_Binary_Logical_Or
Expr_Binary_Equal
Expr_Binary_NotEqual
Expr_Binary_Lesser
Expr_Binary_Greater
Expr_Binary_LesserEqual
Expr_Binary_GreaterEqual
Expr_MemberOfObject,
Expr_MemberOfPointer,
Expr_PointerToMemberOfObject,
Expr_PointerToMemberOfPointer,
Expr_Comma,
Expr_Tenary,
Export_Body
Extern_Linkage
Extern_Linkage_Body
Friend
Function
Function_Fwd
Function_Body
Global_Body
Module
Namespace
Namespace_Body
Operator
Operator_Fwd
Operator_Member
Operator_Member_Fwd
Operator_Cast
Operator_Cast_Fwd
Parameters
Preprocess_Define
Preprocess_Include
Preprocess_If
Preprocess_IfDef
Preprocess_IfNotDef
Preprocess_ElIf
Preprocess_Else
Preprocess_EndIf
Preprocess_Pragma
Specifiers
Statement
Stmt_Break
Stmt_Case
Stmt_Continue
Stmt_Declaration
Stmt_Do
Stmt_Expr
Stmt_Else
Stmt_If
Stmt_For
Stmt_Goto
Stmt_Label
Stmt_Switch
Stmt_Switch
Stmt_While
Struct
Struct_Fwd
Struct_Body
Template
Typedef
Typename
Union
Union_Body
Using
Using_Namespace
Variable
Can't render this file because it has a wrong number of fields in line 56.

View File

@ -41,3 +41,7 @@ MemberOfPointer, "->"
PtrToMemOfPtr, "->*"
FunctionCall, "()"
Comma, ","
New, "new"
NewArray, "new[]"
Delete, "delete"
DeleteArray, "delete[]"
1 Invalid INVALID
41 PtrToMemOfPtr ->*
42 FunctionCall ()
43 Comma ,
44 New new
45 NewArray new[]
46 Delete delete
47 DeleteArray delete[]

View File

@ -4,19 +4,23 @@ Constexpr, constexpr
Constinit, constinit
Explicit, explicit
External_Linkage, extern
ForceInline, forceinline
Global, global
Inline, inline
Internal_Linkage, internal
Local_Persist, local_persist
Mutable, mutable
NeverInline, neverinline
Ptr, *
Ref, &
Register, register
RValue, &&
Static, static
Thread_Local, thread_local
Volatile, volatile
Virtual, virtual
Const, const
Final, final
NoExceptions, noexcept
Override, override
Pure, = 0
Volatile, volatile
1 Invalid INVALID
4 Constinit constinit
5 Explicit explicit
6 External_Linkage extern
7 ForceInline forceinline
8 Global global
9 Inline inline
10 Internal_Linkage internal
11 Local_Persist local_persist
12 Mutable mutable
13 NeverInline neverinline
14 Ptr *
15 Ref &
16 Register register
17 RValue &&
18 Static static
19 Thread_Local thread_local
Volatile volatile
20 Virtual virtual
21 Const const
22 Final final
23 NoExceptions noexcept
24 Override override
25 Pure = 0
26 Volatile volatile

View File

@ -7,8 +7,8 @@ Access_StaticSymbol, "::"
Ampersand, "&"
Ampersand_DBL, "&&"
Assign_Classifer, ":"
Attribute_Open, "[["
Attribute_Close, "]]"
Attribute_Open, "[["
Attribute_Close, "]]"
BraceCurly_Open, "{"
BraceCurly_Close, "}"
BraceSquare_Open, "["
@ -16,7 +16,9 @@ BraceSquare_Close, "]"
Capture_Start, "("
Capture_End, ")"
Comment, "__comment__"
Char, "__char__"
Comment_End, "__comment_end__"
Comment_Start, "__comment_start__"
Char, "__character__"
Comma, ","
Decl_Class, "class"
Decl_GNU_Attribute, "__attribute__"
@ -35,36 +37,59 @@ Decl_Union, "union"
Identifier, "__identifier__"
Module_Import, "import"
Module_Export, "export"
Number, "number"
Operator, "operator"
Preprocessor_Directive, "#"
Preprocessor_Include, "include"
NewLine, "__new_line__"
Number, "__number__"
Operator, "__operator__"
Preprocess_Hash, "#"
Preprocess_Define, "define"
Preprocess_If, "if"
Preprocess_IfDef, "ifdef"
Preprocess_IfNotDef, "ifndef"
Preprocess_ElIf, "elif"
Preprocess_Else, "else"
Preprocess_EndIf, "endif"
Preprocess_Include, "include"
Preprocess_Pragma, "pragma"
Preprocess_Content, "__macro_content__"
Preprocess_Macro, "__macro__"
Preprocess_Unsupported, "__unsupported__"
Spec_Alignas, "alignas"
Spec_Const, "const"
Spec_Consteval, "consteval"
Spec_Constexpr, "constexpr"
Spec_Constinit, "constinit"
Spec_Explicit, "explicit"
Spec_Explicit, "explicit"
Spec_Extern, "extern"
Spec_Final, "final"
Spec_Global, "global"
Spec_Final, "final"
Spec_ForceInline, "forceinline"
Spec_Global, "global"
Spec_Inline, "inline"
Spec_Internal_Linkage, "internal"
Spec_LocalPersist, "local_persist"
Spec_Mutable, "mutable"
Spec_NeverInline, "neverinline"
Spec_Override, "override"
Spec_Static, "static"
Spec_ThreadLocal, "thread_local"
Spec_Volatile, "volatile"
Spec_Virtual, "virtual"
Star, "*"
Statement_End, ";"
StaticAssert, "static_assert"
String, "__string__"
Type_Unsigned, "unsigned"
Type_Typename, "typename"
Type_Unsigned, "unsigned"
Type_Signed, "signed"
Type_Short, "short"
Type_Long, "long"
Type_char, "char"
Type_int, "int"
Type_double, "double"
Type_bool, "bool"
Type_char, "char"
Type_int, "int"
Type_double, "double"
Type_MS_int8, "__int8"
Type_MS_int16, "__int16"
Type_MS_int32, "__int32"
Type_MS_int64, "__int64"
Type_MS_W64, "_W64"
Varadic_Argument, "..."
Attributes_Start, "__attrib_start__"
__Attributes_Start, "__attrib_start__"
1 Invalid __invalid__
7 Ampersand &
8 Ampersand_DBL &&
9 Assign_Classifer :
10 Attribute_Open [[
11 Attribute_Close ]]
12 BraceCurly_Open {
13 BraceCurly_Close }
14 BraceSquare_Open [
16 Capture_Start (
17 Capture_End )
18 Comment __comment__
19 Char Comment_End __char__ __comment_end__
20 Comment_Start __comment_start__
21 Char __character__
22 Comma ,
23 Decl_Class class
24 Decl_GNU_Attribute __attribute__
37 Identifier __identifier__
38 Module_Import import
39 Module_Export export
40 Number NewLine number __new_line__
41 Operator Number operator __number__
42 Preprocessor_Directive Operator # __operator__
43 Preprocessor_Include Preprocess_Hash include #
44 Preprocess_Define define
45 Preprocess_If if
46 Preprocess_IfDef ifdef
47 Preprocess_IfNotDef ifndef
48 Preprocess_ElIf elif
49 Preprocess_Else else
50 Preprocess_EndIf endif
51 Preprocess_Include include
52 Preprocess_Pragma pragma
53 Preprocess_Content __macro_content__
54 Preprocess_Macro __macro__
55 Preprocess_Unsupported __unsupported__
56 Spec_Alignas alignas
57 Spec_Const const
58 Spec_Consteval consteval
59 Spec_Constexpr constexpr
60 Spec_Constinit constinit
61 Spec_Explicit explicit
62 Spec_Extern extern
63 Spec_Final final
64 Spec_Global Spec_ForceInline global forceinline
65 Spec_Global global
66 Spec_Inline inline
67 Spec_Internal_Linkage internal
68 Spec_LocalPersist local_persist
69 Spec_Mutable mutable
70 Spec_NeverInline neverinline
71 Spec_Override override
72 Spec_Static static
73 Spec_ThreadLocal thread_local
74 Spec_Volatile volatile
75 Spec_Virtual virtual
76 Star *
77 Statement_End ;
78 StaticAssert static_assert
79 String __string__
80 Type_Unsigned Type_Typename unsigned typename
81 Type_Unsigned unsigned
82 Type_Signed signed
83 Type_Short short
84 Type_Long long
85 Type_char Type_bool char bool
86 Type_int Type_char int char
87 Type_double Type_int double int
88 Type_double double
89 Type_MS_int8 __int8
90 Type_MS_int16 __int16
91 Type_MS_int32 __int32
92 Type_MS_int64 __int64
93 Type_MS_W64 _W64
94 Varadic_Argument ...
95 Attributes_Start __Attributes_Start __attrib_start__

View File

@ -0,0 +1,183 @@
Invalid, "__invalid__"
Access_Private, "private"
Access_Protected, "protected"
Access_Public, "public"
Access_MemberSymbol, "."
Access_StaticSymbol, "::"
Ampersand, "&"
Ampersand_DBL, "&&"
Assign_Classifer, ":"
Attribute_Open, "[["
Attribute_Close, "]]"
BraceCurly_Open, "{"
BraceCurly_Close, "}"
BraceSquare_Open, "["
BraceSquare_Close, "]"
Capture_Start, "("
Capture_End, ")"
Comment, "__comment__"
Comment_End, "__comment_end__"
Comment_Start, "__comment_start__"
Char, "__character__"
Comma, ","
Decl_Class, "class"
Decl_Default "default"
Decl_GNU_Attribute, "__attribute__"
Decl_MSVC_Attribute, "__declspec"
Decl_Enum, "enum"
Decl_Extern_Linkage, "extern"
Decl_Friend, "friend"
Decl_Module, "module"
Decl_Namespace, "namespace"
Decl_Operator, "operator"
Decl_Struct, "struct"
Decl_Template, "template"
Decl_Type, "decltype"
Decl_Typedef, "typedef"
Decl_Using, "using"
Decl_Union, "union"
Expr_AlignOf, "alignof"
Identifier, "__identifier__"
Module_Import, "import"
Module_Export, "export"
NewLine, "__new_line__"
Number, "__number__"
Operator, "__operator__"
Op_Assign, "="
Op_Assign_Add, "+="
Op_Assign_Subtract, "-="
Op_Assign_Multiply, "*="
Op_Assign_Divide, "/="
Op_Assign_Modulo, "%="
Op_Assign_Bitwise_And, "&="
Op_Assign_Bitwise_Or, "|="
Op_Assign_Bitwise_XOr, "^="
Op_Assign_Bitwise_LeftShift, "<<="
Op_Assign_Bitwise_RightShift, ">>="
Op_Increment, "++"
Op_Decrement, "--"
Op_Add, "+"
Op_Subtract, "-"
Op_Multiply, "*"
Op_Divide, "/"
Op_Modulo, "%"
Op_Bitwise_And, "&"
Op_Bitwise_Or, "|"
Op_Bitwise_XOr, "^"
Op_Bitwise_LeftShitf, "<<"
Op_Bitwise_RightShift, ">>"
Op_UnaryAdd, "+"
Op_UnaryMinus, "-"
Op_UnaryNot, "~"
Op_Logical_Not, "!"
Op_Logical_And, "&&"
Op_Logical_Or, "||"
Op_Equal, "=="
Op_NotEqual, "!="
Op_Lesser, "<"
Op_Greater, ">"
Op_LesserEqual, "<="
Op_GreaterEqual", ">=
Op_Subscript, "[]"
Op_Indirection, "*"
Op_AddressOf, "&"
Op_MemberOfObject, "."
Op_MemberOfPointer", "->"
Op_PointerToMemberOfObject, ".*"
Op_PointerToMemberOfPointer, "->*"
Op_Comma, ","
Op_Ternary, "?"
Preprocess_Hash, "#"
Preprocess_Define, "define"
Preprocess_If, "if"
Preprocess_IfDef, "ifdef"
Preprocess_IfNotDef, "ifndef"
Preprocess_ElIf, "elif"
Preprocess_Else, "else"
Preprocess_EndIf, "endif"
Preprocess_Include, "include"
Preprocess_Pragma, "pragma"
Preprocess_Content, "__macro_content__"
Preprocess_Macro, "__macro__"
Preprocess_Generic, "_Generic"
Preprocess_Unsupported, "__unsupported__"
Spec_Alignof, "alignof"
Spec_Const, "const"
Spec_Consteval, "consteval"
Spec_Constexpr, "constexpr"
Spec_Constinit, "constinit"
Spec_Explicit, "explicit"
Spec_Extern, "extern"
Spec_Final, "final"
Spec_ForceInline, "forceinline"
Spec_Global, "global"
Spec_Inline, "inline"
Spec_Internal_Linkage, "internal"
Spec_LocalPersist, "local_persist"
Spec_Mutable, "mutable"
Spec_NeverInline, "neverinline"
Spec_Override, "override"
Spec_Static, "static"
Spec_ThreadLocal, "thread_local"
Spec_Volatile, "volatile"
Spec_Virtual, "virtual"
Star, "*"
Stmt_Break, "break"
Stmt_Case, "case"
Stmt_Continue, "continue"
Stmt_Default, "default"
Stmt_Do, "do"
Stmt_Else, "else"
Stmt_End, ";"
Stmt_If, "if"
Stmt_For, "for"
Stmt_Goto, "goto"
Stmt_Return, "return"
Stmt_Switch, "switch"
Stmt_While, "while"
StaticAssert, "static_assert"
String, "__string__"
Type_Auto, "auto"
Type_Unsigned, "unsigned"
Type_Signed, "signed"
Type_Short, "short"
Type_Long, "long"
Type_bool, "bool"
Type_char, "char"
Type_int, "int"
Type_float, "float"
Type_double, "double"
Type_MS_int8, "__int8"
Type_MS_int16, "__int16"
Type_MS_int32, "__int32"
Type_MS_int64, "__int64"
Type_MS_W64, "_W64"
Varadic_Argument, "..."
__Attributes_Start, "__attrib_start__"
Can't render this file because it contains an unexpected character in line 25 and column 25.

View File

@ -1,43 +0,0 @@
void Builder::print( Code code )
{
Buffer.append_fmt( "%s\n", code->to_string() );
}
void Builder::print_fmt( char const* fmt, ... )
{
sw res;
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
va_list va;
va_start( va, fmt );
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
va_end( va );
Buffer.append( buf, res );
}
bool Builder::open( char const* path )
{
FileError error = file_open_mode( & File, EFileMode_WRITE, path );
if ( error != EFileError_NONE )
{
log_failure( "gen::File::open - Could not open file: %s", path);
return false;
}
Buffer = String::make_reserve( GlobalAllocator, Builder_StrBufferReserve );
return true;
}
void Builder::write()
{
bool result = file_write( & File, Buffer, Buffer.length() );
if ( result == false )
log_failure("gen::File::write - Failed to write to file: %s", file_name( & File ) );
file_close( & File );
Buffer.free();
}

View File

@ -1,11 +0,0 @@
struct Builder
{
FileInfo File;
String Buffer;
void print( Code );
void print_fmt( char const* fmt, ... );
bool open( char const* path );
void write();
};

View File

@ -1,73 +0,0 @@
#pragma once
#include "gen.scanner.hpp"
namespace gen {
struct Policy
{
// Nothing for now.
};
enum class SymbolType : u32
{
Code,
Line,
Marker
};
struct Editor
{
enum RequestType : u32
{
Add,
Replace,
Remove
};
struct SymbolData
{
Policy Policy;
SymbolInfo Info;
};
struct RequestEntry
{
union {
SymbolData Symbol;
String Specification;
};
RequestType Type;
};
struct Receipt
{
StringCached File;
Code Found;
Code Written;
bool Result;
};
static AllocatorInfo Allocator;
static void set_allocator( AllocatorInfo allocator );
Array<FileInfo> Files;
String Buffer;
Array<RequestEntry> Requests;
void add_files( s32 num, char const** files );
void add ( SymbolInfo definition, Policy policy, Code to_inject );
void remove ( SymbolInfo definition, Policy policy );
void replace( SymbolInfo definition, Policy policy, Code to_replace);
# ifdef GEN_FEATURE_EDITOR_REFACTOR
void refactor( char const* file_path, char const* specification_path );
# endif
bool process_requests( Array<Receipt> out_receipts );
};
// namespace gen
};

View File

@ -1,73 +0,0 @@
#pragma once
#include "gen.hpp"
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: %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
{
StringCached File;
char const* Marker;
Code Signature;
};
struct Scanner
{
struct RequestEntry
{
SymbolInfo Info;
};
struct Receipt
{
StringCached File;
Code Defintion;
bool Result;
};
AllocatorInfo MemAlloc;
static void set_allocator( AllocatorInfo allocator );
Array<FileInfo> Files;
String Buffer;
Array<RequestEntry> Requests;
void add_files( s32 num, char const** files );
void add( SymbolInfo signature, Policy policy );
bool process_requests( Array<Receipt> out_receipts );
};
GEN_NS_END

View File

@ -1,200 +0,0 @@
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND
#include "gen.cpp"
#include "filesystem/gen.scanner.hpp"
#include "helpers/gen.helper.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" );
// gen_dep.hpp
{
Code header_start = scan_file( "dependencies/gen.header_start.hpp" );
Code nspace_macro = untyped_str( namespace_by_default ? nspace_default : nspace_non_default );
Code macros = scan_file( "dependencies/gen.macros.hpp" );
Code basic_types = scan_file( "dependencies/gen.basic_types.hpp" );
Code debug = scan_file( "dependencies/gen.debug.hpp" );
Code memory = scan_file( "dependencies/gen.memory.hpp" );
Code string_ops = scan_file( "dependencies/gen.string_ops.hpp" );
Code printing = scan_file( "dependencies/gen.printing.hpp" );
Code containers = scan_file( "dependencies/gen.containers.hpp" );
Code hashing = scan_file( "dependencies/gen.hashing.hpp" );
Code string = scan_file( "dependencies/gen.string.hpp" );
Code file_handling = scan_file( "dependencies/gen.file_handling.hpp" );
Code parsing = scan_file( "dependencies/gen.parsing.hpp" );
Code timing = scan_file( "dependencies/gen.timing.hpp" );
Builder
deps_header;
deps_header.open("gen/gen_dep.hpp");
deps_header.print_fmt("// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)\n\n");
deps_header.print_fmt("#pragma once\n\n");
deps_header.print( header_start );
deps_header.print( nspace_macro );
deps_header.print_fmt( "GEN_NS_BEGIN\n\n");
deps_header.print( macros );
deps_header.print( basic_types );
deps_header.print( debug );
deps_header.print( memory );
deps_header.print( string_ops );
deps_header.print( printing );
deps_header.print( containers );
deps_header.print( hashing );
deps_header.print( string );
deps_header.print( file_handling );
deps_header.print( parsing );
deps_header.print( timing );
deps_header.print_fmt( "GEN_NS_END\n\n");
deps_header.write();
}
// gen_dep.cpp
{
CodeInclude header = def_include( txt_StrC("gen_dep.hpp") );
Code impl_start = scan_file( "dependencies/gen.impl_start.cpp" );
Code debug = scan_file( "dependencies/gen.debug.cpp" );
Code string_ops = scan_file( "dependencies/gen.string_ops.cpp" );
Code printing = scan_file( "dependencies/gen.printing.cpp" );
Code memory = scan_file( "dependencies/gen.memory.cpp" );
Code parsing = scan_file( "dependencies/gen.parsing.cpp" );
Code hashing = scan_file( "dependencies/gen.hashing.cpp" );
Code string = scan_file( "dependencies/gen.string.cpp" );
Code timing = scan_file( "dependencies/gen.timing.cpp" );
Builder
deps_impl;
deps_impl.open("gen/gen_dep.cpp");
deps_impl.print_fmt("// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)\n\n");
deps_impl.print( impl_start );
deps_impl.print( header );
deps_impl.print_fmt( "\nGEN_NS_BEGIN\n");
deps_impl.print( debug );
deps_impl.print( string_ops );
deps_impl.print( printing );
deps_impl.print( hashing );
deps_impl.print( memory );
deps_impl.print( parsing );
deps_impl.print( string );
deps_impl.print( timing );
deps_impl.print_fmt( "GEN_NS_END\n\n");
deps_impl.write();
}
// gen.hpp
{
Code header_start = scan_file( "components/gen.header_start.hpp" );
Code nspace_macro = untyped_str( namespace_by_default ? nspace_default : nspace_non_default );
Code types = scan_file( "components/gen.types.hpp" );
Code data_structs = scan_file( "components/gen.data_structures.hpp" );
Code interface = scan_file( "components/gen.interface.hpp" );
Code header_end = scan_file( "components/gen.header_end.hpp" );
CodeBody ecode = gen_ecode( "./components/ECode.csv" );
CodeBody eoperator = gen_eoperator( "./components/EOperator.csv" );
CodeBody especifier = gen_especifier( "./components/ESpecifier.csv" );
Code builder = scan_file( "filesystem/gen.builder.hpp" );
Builder
header;
header.open( "gen/gen.hpp" );
header.print_fmt("#pragma once\n\n");
header.print( push_ignores );
header.print( header_start );
header.print( nspace_macro );
header.print_fmt( "GEN_NS_BEGIN\n\n");
header.print_fmt("#pragma region Types\n\n");
header.print( types );
header.print( ecode );
header.print( eoperator );
header.print( especifier );
header.print_fmt("#pragma endregion Types\n\n");
header.print( data_structs );
header.print( interface );
header.print( header_end );
header.print( builder );
header.print_fmt( "GEN_NS_END\n\n");
header.print( pop_ignores );
header.write();
}
// gen.cpp
{
Code impl_start = scan_file( "components/gen.impl_start.cpp" );
CodeInclude header = def_include( txt_StrC("gen.hpp") );
Code data = scan_file( "components/gen.data.cpp" );
Code ast_case_macros = scan_file( "components/gen.ast_case_macros.cpp" );
Code ast = scan_file( "components/gen.ast.cpp" );
Code interface = scan_file( "components/gen.interface.cpp" );
Code upfront = scan_file( "components/gen.interface.upfront.cpp" );
Code parsing = scan_file( "components/gen.interface.parsing.cpp" );
Code untyped = scan_file( "components/gen.untyped.cpp" );
CodeBody etoktype = gen_etoktype( "components/ETokType.csv", "components/AttributeTokens.csv" );
CodeNamespace parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) );
Code builder = scan_file( "filesystem/gen.builder.cpp" );
Builder
impl;
impl.open( "gen/gen.cpp" );
impl.print( push_ignores );
impl.print( impl_start );
impl.print( header );
impl.print_fmt( "\nGEN_NS_BEGIN\n\n");
impl.print( data );
impl.print( ast_case_macros );
impl.print( ast );
impl.print( interface );
impl.print( upfront );
impl.print( parser_nspace );
impl.print( parsing );
impl.print( untyped );
impl.print( builder );
impl.print_fmt( "GEN_NS_END\n\n");
impl.print( pop_ignores );
impl.write();
}
gen::deinit();
return 0;
}

View File

@ -1,4 +1,4 @@
#include "helpers/gen.push_ignores.inline.hpp"
#include "helpers/push_ignores.inline.hpp"
// ReSharper disable CppClangTidyClangDiagnosticSwitchEnum
@ -6,29 +6,30 @@
# error Gen.hpp : GEN_TIME not defined
#endif
#include "gen.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 "gen.dep.cpp"
#endif
#include "gen.hpp"
GEN_NS_BEGIN
#include "components/gen.data.cpp"
#include "components/static_data.cpp"
#include "components/gen.ast_case_macros.cpp"
#include "components/gen.ast.cpp"
#include "components/ast_case_macros.cpp"
#include "components/ast.cpp"
#include "components/code_serialization.cpp"
#include "components/gen.interface.cpp"
#include "components/gen.interface.upfront.cpp"
#include "components/gen.etoktype.cpp"
#include "components/gen.interface.parsing.cpp"
#include "components/gen.untyped.cpp"
#include "filesystem/gen.builder.cpp"
#include "components/interface.cpp"
#include "components/interface.upfront.cpp"
#include "components/gen/etoktype.cpp"
#include "components/lexer.cpp"
#include "components/parser.cpp"
#include "components/interface.parsing.cpp"
#include "components/interface.untyped.cpp"
GEN_NS_END
#include "helpers/gen.pop_ignores.inline.hpp"
#include "helpers/pop_ignores.inline.hpp"

View File

@ -1,19 +1,17 @@
// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)
#include "gen.dep.hpp"
#include "dependencies/gen.impl_start.cpp"
#include "dependencies/src_start.cpp"
GEN_NS_BEGIN
#include "dependencies/gen.debug.cpp"
#include "dependencies/gen.string_ops.cpp"
#include "dependencies/gen.printing.cpp"
#include "dependencies/gen.memory.cpp"
#include "dependencies/gen.parsing.cpp"
#include "dependencies/gen.hashing.cpp"
#include "dependencies/gen.string.cpp"
#include "dependencies/gen.timing.cpp"
#include "dependencies/gen.file_handling.cpp"
#include "dependencies/debug.cpp"
#include "dependencies/string_ops.cpp"
#include "dependencies/printing.cpp"
#include "dependencies/memory.cpp"
#include "dependencies/hashing.cpp"
#include "dependencies/strings.cpp"
#include "dependencies/filesystem.cpp"
#include "dependencies/timing.cpp"
GEN_NS_END

Some files were not shown because too many files have changed in this diff Show More