You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+9-3Lines changed: 9 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,11 @@ The library API is a composition of code element constructors.
6
6
These build up a code AST to then serialize with a file builder.
7
7
8
8
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto),
9
-
its not meant to be a black box metaprogramming utility, its meant for the user to extend for their project domain.
9
+
its not meant to be a black box metaprogramming utility, it should be easy to intergrate into a user's their project domain.
10
10
11
11
## Notes
12
12
13
13
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.
14
-
The [issues](https://github.com/Ed94/gencpp/issues) marked with v1.0 Feature indicate whats left before the library is considered feature complete.
15
14
16
15
A `natvis` and `natstepfilter` are provided in the scripts directory.
17
16
@@ -25,7 +24,7 @@ A metaprogram is built to generate files before the main program is built. We'll
25
24
26
25
`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.
27
26
28
-
In order to keep the locality of this code within the same files the following pattern may be used:
27
+
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):
29
28
30
29
Within `program.cpp` :
31
30
@@ -41,6 +40,8 @@ u32 gen_main()
41
40
}
42
41
#endif
43
42
43
+
// "Stage" agnostic code.
44
+
44
45
#ifndef GEN_TIME
45
46
#include "program.gen.cpp"
46
47
@@ -56,6 +57,7 @@ Example using each construction interface:
56
57
57
58
### Upfront
58
59
60
+
Validation and construction through a functional interface.
The library features a naive parser tailored for only what the library needs to construct the supported syntax of C++ into its AST.
4
-
This parser does not, and should not do the compiler's job. By only supporting this minimal set of features, the parser is kept under 5000 loc.
4
+
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) under 5000 loc.
5
5
6
6
The parsing implementation supports the following for the user:
***Parsing will aggregate any tokens within a function body or expression statement to an untyped Code AST.***
29
31
30
32
Everything is done in one pass for both the preprocessor directives and the rest of the language.
31
-
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***, and ***includes***, and ***`pragmas`**.
33
+
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***, and ***includes***, and ***pragmas**.
32
34
33
35
The keywords supported for the preprocessor are:
34
36
@@ -41,12 +43,30 @@ The keywords supported for the preprocessor are:
41
43
* undef
42
44
* pragma
43
45
44
-
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*.
45
-
All keywords except *include* are suppported as members of a scope for a class/struct, global, or namespace body.
46
+
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*.
47
+
If a directive is used with an unsupported keyword its will be processed as an untyped AST.
46
48
47
-
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).
49
+
The preprocessor lines are stored as members of their associated scope they are parsed within. ( Global, Namespace, Class/Struct )
48
50
49
-
Exceptions to the above rule (If its too hard to keep track of just follow the above notion):
51
+
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).
52
+
Exceptions:
50
53
51
-
* Typedefs allow of a macro exansion to be defined after the keyword; Ex: `typedef GEN_FILE_OPEN_PROC( file_open_proc );`
54
+
* function signatures are allowed for a preprocessed macro: `neverinline MACRO() { ... }`
55
+
* typedefs allow for a preprocessed macro: `typedef MACRO();`
52
56
57
+
*(See functions `parse_operator_function_or_variable` and `parse_typedef` )*
58
+
59
+
The lexing and parsing takes shortcuts from whats expected in the standard.
60
+
61
+
* Numeric literals are not checked for validity.
62
+
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
b32 IsFunction; // Used by typedef to not serialize the name field.
125
120
OperatorT Op;
126
121
AccessSpec ParentAccess;
127
122
s32 NumEntries;
@@ -145,7 +140,7 @@ uw ArrSpecs_Cap =
145
140
- sizeof(StringCached)
146
141
- sizeof(CodeT)
147
142
- sizeof(ModuleFlag)
148
-
- sizeof(s32)
143
+
- sizeof(u32)
149
144
)
150
145
/ sizeof(SpecifierT) -1; // -1 for 4 extra bytes (Odd num of AST*)
151
146
```
@@ -155,7 +150,7 @@ uw ArrSpecs_Cap =
155
150
Data Notes:
156
151
157
152
* The allocator definitions used are exposed to the user incase they want to dictate memory usage
158
-
* You'll find the memory handling in `init`, `gen_string_allocator`, `get_cached_string`, `make_code`.
153
+
* You'll find the memory handling in `init`, `deinit`, `reset`, `gen_string_allocator`, `get_cached_string`, `make_code`.
159
154
* ASTs are wrapped for the user in a Code struct which is a wrapper for a AST* type.
160
155
* Both AST and Code have member symbols but their data layout is enforced to be POD types.
161
156
* This library treats memory failures as fatal.
@@ -168,15 +163,15 @@ Data Notes:
168
163
* Linked lists used children nodes on bodies, and parameters.
169
164
* 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.
170
165
* Allocations can be tuned by defining the folloiwng macros:
171
-
*`GEN_BUILDER_STR_BUFFER_RESERVE`
172
-
*`GEN_CODEPOOL_NUM_BLOCKS` : Number of blocks per code pool in the code allocator
173
166
*`GEN_GLOBAL_BUCKET_SIZE` : Size of each bucket area for the global allocator
174
-
*`GEN_LEX_ALLOCATOR_SIZE`
167
+
*`GEN_CODEPOOL_NUM_BLOCKS` : Number of blocks per code pool in the code allocator
168
+
*`GEN_SIZE_PER_STRING_ARENA` : Size per arena used with string caching.
175
169
*`GEN_MAX_COMMENT_LINE_LENGTH` : Longest length a comment can have per line.
176
170
*`GEN_MAX_NAME_LENGTH` : Max length of any identifier.
177
171
*`GEN_MAX_UNTYPED_STR_LENGTH` : Max content length for any untyped code.
178
-
*`GEN_SIZE_PER_STRING_ARENA` : Size per arena used with string caching.
179
172
*`GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE` : token_fmt_va uses local_persit memory of this size for the hashtable.
173
+
*`GEN_LEX_ALLOCATOR_SIZE`
174
+
*`GEN_BUILDER_STR_BUFFER_RESERVE`
180
175
181
176
The following CodeTypes are used which the user may optionally use strong typing with if they enable: `GEN_ENFORCE_STRONG_CODE_TYPES`
182
177
@@ -187,7 +182,6 @@ The following CodeTypes are used which the user may optionally use strong typing
187
182
* CodeConstructor
188
183
* CodeDefine
189
184
* CodeDestructor
190
-
* CodePreprocessCond
191
185
* CodeEnum
192
186
* CodeExec
193
187
* CodeExtern
@@ -199,6 +193,8 @@ The following CodeTypes are used which the user may optionally use strong typing
199
193
* CodeOperator
200
194
* CodeOpCast
201
195
* CodeParam : Has support for `for-range` iterating across parameters.
196
+
* CodePreprocessCond
197
+
* CodePragma
202
198
* CodeSpecifiers : Has support for `for-range` iterating across specifiers.
203
199
* CodeStruct
204
200
* CodeTemplate
@@ -221,7 +217,7 @@ Retrieving a raw version of the ast can be done using the `raw()` function defin
221
217
### Upfront Construction
222
218
223
219
All component ASTs must be previously constructed, and provided on creation of the code AST.
224
-
The construction will fail and return Code::Invalid otherwise.
220
+
The construction will fail and return CodeInvalid otherwise.
225
221
226
222
Interface :``
227
223
@@ -231,6 +227,7 @@ Interface :``
231
227
* def_comment
232
228
* def_class
233
229
* def_constructor
230
+
* def_define
234
231
* def_destructor
235
232
* def_enum
236
233
* def_execution
@@ -245,6 +242,7 @@ Interface :``
245
242
* def_operator_cast
246
243
* def_param
247
244
* def_params
245
+
* def_preprocess_cond
248
246
* def_specifier
249
247
* def_specifiers
250
248
* def_struct
@@ -321,19 +319,6 @@ Interface :
321
319
* parse_using
322
320
* parse_variable
323
321
324
-
The lexing and parsing takes shortcuts from whats expected in the standard.
325
-
326
-
* Numeric literals are not check for validity.
327
-
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
0 commit comments