34 KiB
Navigation
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
File: lexer.cpp
The lex
procedure does the lexical pass of content provided as a Str
type.
The tokens are stored (for now) in Lexer_Tokens
.
Fields:
Array<Token> Arr;
s32 Idx;
What token types are supported can be found in ETokType.csv you can also find the token types in ETokType.h , which is the generated enum from the csv file.
struct Token
{
Str Text;
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 expressionsTF_Assign
- Using statment assignment
- Parameter argument default value assignment
- Variable declaration initialization assignment
TF_Preprocess
: Related to a preprocessing directiveTF_Preprocess_Cond
: A preprocess conditionalTF_Attribute
: An attribute tokenTF_AccessSpecifier
: An accesor operation tokenTF_Specifier
: One of the specifier tokensTF_EndDefinition
: Can be interpreted as an end definition for a scope.TF_Formatting
: Considered a part of the formattingTF_Literal
: Anything considered a literal by C++.TF_Macro_Functional
: Used to indicate macro token is flagged asMF_Functional
.TF_Macro_Expects_Body
: Used to indicate macro token is flagged asMF_Expects_Body
.
Parser
Files:
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. 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:
<code type> parse_<definition type>( Str 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:
internal
<code type> parse_<definition_type>( <empty or contextual params> )
{
push_scope();
...
<code type> result = (<code type>) make_code();
...
Context.pop();
return result;
}
The parsing implementation contains throughut the codeapths to indicate how far their contextual AST node has been resolved.
Example:
internal
CodeFn parser_parse_function()
{
push_scope();
Specifier specs_found[16] = { Spec_NumSpecifiers };
s32 NumSpecifiers = 0;
CodeAttributes attributes = { nullptr };
CodeSpecifiers specifiers = { nullptr };
ModuleFlag mflags = ModuleFlag_None;
if ( check(Tok_Module_Export) ) {
mflags = ModuleFlag_Export;
eat( Tok_Module_Export );
}
// <export>
attributes = parse_attributes();
// <export> <Attributes>
while ( left && tok_is_specifier(currtok) )
{
Specifier spec = str_to_specifier( tok_to_str(currtok) );
switch ( spec )
{
GEN_PARSER_FUNCTION_ALLOWED_SPECIFIER_CASES:
break;
default:
log_failure( "Invalid specifier %S for functon\n%SB", spec_to_str(spec), parser_to_strbuilder(_ctx->parser) );
parser_pop(& _ctx->parser);
return InvalidCode;
}
if ( spec == Spec_Const )
continue;
specs_found[NumSpecifiers] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
if ( NumSpecifiers ) {
specifiers = def_specifiers_arr( NumSpecifiers, specs_found );
}
// <export> <Attributes> <Specifiers>
CodeTypename ret_type = parser_parse_type(parser_not_from_template, nullptr);
if ( cast(Code, ret_type) == Code_Invalid ) {
parser_pop(& _ctx->parser);
return InvalidCode;
}
// <export> <Attributes> <Specifiers> <ReturnType>
Token name = parse_identifier(nullptr);
_ctx->parser.Scope->Name = name.Text;
if ( ! tok_is_valid(name) ) {
parser_pop(& _ctx->parser);
return InvalidCode;
}
// <export> <Attributes> <Specifiers> <ReturnType> <Name>
CodeFn result = parse_function_after_name( mflags, attributes, specifiers, ret_type, name );
// <export> <Attributes> <Specifiers> <ReturnType> <Name> ...
parser_pop(& _ctx->parser);
return result;
}
In the above parse_function
implementation:
// <intutive expression of AST component> ...
Will be conventionlly used where by that point in time for the codepath: <intutive expression of AST component>
should be resolved for the AST.
Outline of parsing codepaths
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
- Push parser scope
- Check for empty array
[]
- Return untyped string with single space if found
- Check for opening bracket
[
- Validate parser not at EOF
- Reject empty array expression
- Capture expression tokens until closing bracket
- Calculate expression span length
- Convert to untyped string
- Validate and consume closing bracket
]
- Handle multi-dimensional case
- If adjacent
[
detected, recursively parse - Link array expressions via Next pointer
- If adjacent
- Pop parser scope
- Return array expression or NullCode on failure
parse_attributes
- Push parser scope and initialize tracking
- Store initial token position
- Initialize length counter
- Process attributes while available
- Handle C++ style attributes
[[...]]
- Consume opening
[[
- Capture content until closing
]]
- Calculate attribute span length
- Consume opening
- Handle GNU style
__attribute__((...))
- Consume
__attribute__
keyword and opening((
- Capture content until closing
))
- Calculate attribute span length
- Consume
- Handle MSVC style
__declspec(...)
- Consume
__declspec
and opening(
- Capture content until closing
)
- Calculate attribute span length
- Consume
- Handle macro-style attributes
- Consume attribute token
- If followed by parentheses
- Handle nested parentheses tracking
- Capture content maintaining paren balance
- Calculate attribute span length
- Handle C++ style attributes
- Generate attribute code if content captured
- Create attribute text span from start position and length
- Strip formatting from attribute text
- Construct Code node
- Set type to
CT_PlatformAttributes
- Cache and set Name and Content fields
- Set type to
- Return as CodeAttributes
- Pop parser scope
- Return NullCode if no attributes found
parse_class_struct
- Validate token type is class or struct
- Return InvalidCode if validation fails
- Initialize class/struct metadata
- Access specifier (default)
- Parent class/struct reference
- Class/struct body
- Attributes
- Module flags
- Parse module export flag if present
- Set ModuleFlag_Export
- Consume export token
- Consume class/struct token
- Parse attributes via
parse_attributes()
- Parse class/struct identifier
- Update parser scope name
- Initialize interface array (4KB arena)
- Parse inheritance/implementation
- If classifier token (
:
) present- Parse access specifier if exists
- Parse parent class/struct name
- Parse additional interfaces
- Separated by commas
- Optional access specifiers
- Store in interface array
- If classifier token (
- Parse class body if present
- Triggered by opening brace
- Parse via
parse_class_struct_body
- Handle statement termination
- Skip for inplace definitions
- Consume semicolon
- Parse inline comment if present
- Construct result node
- Create class definition if Tok_Decl_Class
- Create struct definition if Tok_Decl_Struct
- Attach inline comment if exists
- Cleanup interface array and return result
parse_class_struct_body
- Initialize scope and body structure
- Push parser scope
- Consume opening brace
- Create code node with
CT_Class_Body
orCT_Struct_Body
type
- Parse body members while not at closing brace
- Initialize member parsing state
- Code member (InvalidCode)
- Attributes (null)
- Specifiers (null)
- Function expectation flag
- Handle preprocessor hash if present
- Process member by token type in switch statement
- Statement termination - warn and skip
- Newline - format member
- Comments - parse comment
- Access specifiers -
public/protected/private
- Declarations -
class/enum/struct/union/typedef/using
- Operators -
destructors/casts
- Preprocessor directives -
define/include/conditionals/pragmas
- Preprocessor statement macros
- Report naked preprocossor expression macros detected as an error.
- Static assertions
- Attributes and specifiers
- Parse attributes
- Parse valid member specifiers
- Handle
attribute-specifier-attribute
case
- Identifiers and types
- Check for constructors
- Parse
operator/function/variable
- Default - capture unknown content until closing brace
- Validate member parsing
- Return InvalidCode if member invalid
- Append valid member to body
- Initialize member parsing state
- Finalize body
- Consume closing brace
- Pop parser scope
- Return completed CodeBody
parse_comment
- Just wrap the token into a cached string ( the lexer did the processing )
parse_complicated_definition
- Initialize parsing context
- Push scope
- Set inplace flag false
- Get token array reference
- Scan ahead for statement termination
- Track brace nesting level
- Find first semicolon at level 0
- Handle declaration variants
- Forward declaration case
- Check if only 2 tokens before semicolon
- Parse via
parse_forward_or_definition
- Function with trailing specifiers
- Identify trailing specifiers
- Check for function pattern
- Parse as
operator/function/variable
- Return
InvalidCode
if pattern invalid
- Identifier-based declarations
- Check identifier patterns
- Inplace definition
{...} id;
- Namespace type variable
which id id;
- Enum with class qualifier
Pointer/reference
types
- Inplace definition
- Parse as
operator/function/variable
if valid - Return
InvalidCode
if pattern invalid
- Check identifier patterns
- Basic type declarations
- Validate enum class pattern
- Parse via
parser_parse_enum
- Return
InvalidCode
if invalid
- Direct definitions
- Handle closing brace -
parse_forward_or_definition
- Handle array definitions -
parse_operator_function_or_variable
- Return InvalidCode for unknown patterns
- Handle closing brace -
- Forward declaration case
parse_assignment_expression
- Initialize expression parsing
- Null expression pointer
- Consume assignment operator token
- Capture initial expression token
- Validate expression presence
- Check for immediate termination
- Return
InvalidCode
if missing expression
- Parse balanced expression
- Track nesting level for
- Curly braces
- Parentheses
- Continue until
- End of input, or
- Statement terminator, or
- Unnested comma
- Consume tokens sequentially
- Track nesting level for
- Generate expression code
- Calculate expression span length
- Convert to untyped string
- Return expression node
parse_forward_or_definition
- Declaration type routing
- Class (
Tok_Decl_Class
) ->parser_parse_class
- Enum (
Tok_Decl_Enum
) ->parser_parse_enum
- Struct (
Tok_Decl_Struct
) ->parser_parse_struct
- Union (
Tok_Decl_Union
) ->parser_parse_union
- Class (
- Error handling
- Return
InvalidCode
for unsupported token types - Log failure with parser context
- Return
is_inplace
flag propagates to specialized codepaths to maintain parsing context.
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
- Parameter parsing
- Push scope
- Parse parameter list with parentheses
- Post-parameter specifier processing
- Collect trailing specifiers
- Initialize or append to existing specifiers
- Parse function termination
- Function body case
- Parse body if open brace found
- Validate body type (
CT_Function_Body
orCT_Untyped
)
- Pure virtual case
- Handle "
= 0
" syntax - Append pure specifier
- Handle "
- Forward declaration case
- Consume statement terminator
- Handle inline comments for all cases
- Function body case
- Construct function node
- Strip whitespace from name
- Initialize
CodeFn
with base properties- Name (cached, stripped)
- Module flags
- Set node type
CT_Function
if body presentCT_Function_Fwd
if declaration only
- Attach components
- Attributes if present
- Specifiers if present
- Return type
- Parameters if present
- Inline comment if present
- Cleanup and return
- Pop scope
- Return completed function node
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.
- Initialize body parsing
- Push scope
- Consume opening brace
- Create CodeBody with CT_Function_Body type
- Capture function content
- Record start token position
- Track brace nesting level
- Consume tokens while
- Input remains AND
- Not at unmatched closing brace
- Update level counters
- Increment on open brace
- Decrement on closing brace when level > 0
- Process captured content
- Calculate content length via pointer arithmetic
- Create execution block if content exists
- Construct string span from start position and length
- Wrap in execution node
- Append to body
- Finalize
- Consume closing brace
- Pop scope
- Return cast body node
parse_global_nspace
- State initialization
- Push parser scope
- Validate namespace type (Global, Namespace, Export, Extern Linkage)
- Consume opening brace for non-global scopes
- Initialize
CodeBody
with specified body type:which
- Member parsing loop (while not at closing brace)
- Reset parse state
- Member code
- Attributes
- Specifiers
- Function expectation flag
- Member type handling
- Declarations
Class/Struct/Union/Enum
viaparse_complicated_definition
Template/Typedef/Using
via dedicated parsersNamespace/Export/Extern
declarations
- Preprocessor directivess
- Include/Define
- Conditionals
(if / ifdef / ifndef / elif / else / endif)
- Pragmas
- Preprocessor statement macros
- Report naked preprocossor expression macros detected as an error.
- Comments/Formatting
- Newlines
- Comments
- Static assertions
- Declarations
- Attributes and specifiers
- Parse attributes if present
- Collect valid specifiers (max 16)
- Handle
consteval
for function expectation
- Identifier resolution
- Check
constructor/destructor
implementation - Look ahead for user defined operator implementation outside of class
- Default to
operator/function/variable
parse
- Check
- Reset parse state
- Member validation/storage
- Validate parsed member
- Append to body if valid
- Return
InvalidCode
on parse failure
- Scope finalization
- Consume closing brace for non-global scopes
- Pop parser scope
- Return completed body
parse_global_nspace_constructor_destructor
- Forward Token Analysis
- Scan for parameter list opening parenthesis
- Template Expression Handling
- Track template nesting depth
- Account for nested parentheses within templates
- Skip until template closure or parameter start
// Valid patterns:
ClassName :: ClassName(...)
ClassName :: ~ClassName(...)
ClassName< T ... > :: ClassName(...)
- Constructor/Destructor Identification
- Token Validation Sequence
- Verify identifier preceding parameters
- Check for destructor indicator (
~
) - Validate scope resolution operator (
::
)
- Left-side Token Analysis
- Process nested template expressions
- Maintain template/capture level tracking
- Locate matching identifier token
- Token Validation Sequence
- Parser Resolution
- Name Pattern Validation
- Compare identifier tokens for exact match
- Specialized Parsing
- Route to
parser_parse_destructor
for '~' prefix - Route to
parser_parse_constructor
for direct match
- Route to
- Apply specifiers to resulting node
- Name Pattern Validation
- Return result (
NullCode
on pattern mismatch)
Implementation Constraints
- Cannot definitively distinguish nested namespaces with identical names
- Return type detection requires parser enhancement
- Template parameter validation is syntax-based only
- Future enhancement: Implement type parsing with rollback capability
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.
- Initialize identifier context
- Push parser scope
- Capture initial token as name
- Set scope name from token text
- Process initial identifier component
- Consume identifier token
- Parse template arguments if present
- Handle qualified identifiers (loop while
::
found)- Consume static access operator
- Validate token sequence:
- Handle destructor operator (
~
)- Validate destructor parsing context
- Update name span if valid
- Return invalid on context mismatch
- Process member function pointer (
*
)- Set possible_member_function flag if context allows
- Return invalid if pointer unexpected
- Verify identifier token follows
- Handle destructor operator (
- Update identifier span
- Extend name length to include new qualifier
- Consume identifier token
- Parse additional template arguments
- Return completed identifier token
Technical notes:
- Current implementation treats identifier as single token span
- TODO: Refactor to AST-based identifier representation for:
- Distinct qualifier/symbol tracking
- Improved semantic analysis capabilities
- Better support for nested symbol resolution
parse_include
- Consume include directive
- 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, and return type
- Initialize operator context
- Push scope
- Parse qualified namespace identifier
- Consume
operator
keyword
- Operator identification
- Validate operator token presence
- Set scope name from operator token
- Map operator token to internal operator enum:
- Arithmetic:
+, -, *, /, %
- Assignment:
+=, -=, *=, /=, %=, =
- Bitwise:
&, |, ^, ~, >>
- Logical:
&&, ||, !, ==
- Comparison:
<, >, <=, >=
- Member access:
->, ->*
- Special:
(), [], new, delete
- Arithmetic:
- Handle array variants for new/delete
- Parameter and specifier processing
- Parse parameter list
- Handle multiply/member-pointer ambiguity
- Collect trailing specifiers
- Merge with existing specifiers
- Function body handling
- Parse implementation if present
- Otherwise consume statement terminator
- Capture inline comments
- Result construction
- Create operator node with:
- Operator type
- Namespace qualification
- Parameters
- Return type
- Implementation body
- Specifiers
- Attributes
- Module flags
- Attach inline comments
- Create operator node with:
- Pop scope
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.
- Check for preprocessor macro, if there is one :
parse_simple_preprocess
parse_type
(Does the bulk of the work)- Begin lookahead to see if we get qualifiers or we eventually find the operator declaration
- If we find an operator keyword :
parse_operator_after_ret_type
- otherwise :
parse_identifier
- If we se a opening parenthesis (capture start), its a function :
parse_function_after_name
- Its a variable :
parse_variable_after_name
parse_pragma
- Consume pragma directive
- Process the token content into cached string
parse_params
- Consume either a
(
or<
based onuse_template_capture
arg - If the we immdiately find a closing token, consume it and finish.
- If we encounter a varadic argument, consume it and return a
param_varadic
ast constant parse_type
- If we have a macro, parse it (Unreal has macros as tags to parameters and or as entire arguments).
- So long as next token isn't a comma
a. If we have an identifier
- Consume it
- Check for assignment: a. Consume assign operator b. Parse the expression
- While we continue to encounter commas a. Consume them b. Repeat steps 3 to 6.2.b
- Consume the closing token
parse_preprocess_cond
- Parse conditional directive
- 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.
- Consume the macro token
- Check for an opening curly brace
- Consume opening curly brace
- Until the closing curly is encountered consume all tokens.
- If the parent context is a typedef
- Check for end stement
- Consume it
- Consume potential inline comment
- Check for end stement
- Otherwise do steps 3 to 3.1.2
- Shove it all in an untyped string
parse_static_assert
- Consume static assert and opening curly brace
- Consume all tokens until the the closing brace is reached.
- Consume curly brace and end statement
- 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
- Consume opening angle bracket
- Consume all tokens until closing angle bracket
- Consme closing angle bracket
- 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
- If its an assignment, parse the assignment expression (currently to an untyped string)
- If its an opening curly brace, parse the expression within (currnelty to an untyped stirng).
- Consume the closing curly brace
- If its a
:
, we're dealing with bitfield definition:- Consume the assign classifier
- Consume the expression (currently to an untyped string)
- If a comma is encountered :
parse_variable declaration_list
- Consume statement end
- Check for inline comment
parse_variable_declaration_list
- Consume the comma
- Parse specifiers
parse_variable_after_name
parse_class
parse_class_struct
parse_constructor
This currently doesn't support postfix specifiers (planning to in the future)
parse_identifier
parse_parameters
- If currtok is a
:
- Consume
:
- Parse the initializer list
parse_function_body
- Consume
- If currtok is an opening curly brace
parse_function_body
- Otherwise:
- Consume statement end
- Check for inline comment
parse_destructor
- Check for and consume virtual specifier
- Check for the
~
operator parse_identifier
- Consume opening and closing parenthesis
- Check for assignment operator:
- Consume assignment op
- Consume pure specifier
0
- If not pure virtual & currtok is opening curly brace:
parse_function_body
- Otherwise:
- Consume end statement
- If currtok is comment :
parse_comment
parse_enum
- Consume enum token
- Check for and consume class token
parse_attributes
- If there is an identifier consume it
- Check for a
:
- Consume
:
parse_type
- Consume
- If there is a body parse it (Consume
{
):- Newline : ast constant
- Comment :
parse_comment
- Preprocess_Define :
parse_define
- Preprocess_Conditional (if, ifdef, ifndef, elif ) :
parse_preprocess_cond
- Preprocess_Else : ast constant
- Preprocess_Endif : ast constant
- Preprocess_Macro :
parse_simple_preprocess
- Preprocess_Pragma :
parse_pragma
- Preprocess_Unsupported :
parse_smple_preprocess
- An actual enum entry
- Consume identifier
- If there is an assignment operator:
- Consume operator
- Consume the expression (assigned to untyped string for now)
- If a macro is encountered consume it (Unreal UMETA macro support)
- If there is a comma, consume it
parse_export_body
parse_global_nspace
parse_extern_link_body
parse_global_nspace
parse_extern_link
- Consume Decl_Extern_Linkage
- Consume the linkage identifier
parse_extern_link_body
parse_friend
- Consume
friend
parse_type
- If the currok is an identifier its a function declaration or definition
parse_function_after_name
- Consume end statement so long as its not a function definion
- Check for inline comment,
parse_comment
if exists
parse_function
- Check and parse for
export
parse_attributes
- Parse specifiers
parse_type
parse_identifier
parse_function_after_name
parse_namespace
- Consume namespace declaration
- Parse identifier
parse_global_namespace
parse_operator
- Check for and parse export declaration
parse_attributes
- Parse specifiers
parse_type
parse_operator_after_ret_type
parse_operator_cast
- Look for and parse a qualifier namespace for the cast (in-case this is defined outside the class's scope)
- Consume operator declaration
parse_type
- Consume opening and closing parethesis
- Check for a const qualifiying specifier
- Check to see if this is a definition (
{
)- Consume
{
- Parse body to untyped string (parsing statement and expressions not supported yet)
- Consume
}
- Consume
- Otherwise:
- Consume end statement
- Check for and consume comment :
parse_comment
parse_struct
parse_class_struct
parse_template
Note: This currently doesn't support templated operator casts (going to need to add support for it)
- Check for and parse export declaration
- Consume template declaration
parse_params
- Parse for any of the following:
- Decl_Class :
parse_class
- Decl_Struct :
parse_struct
- Decl_Union :
parse_union
- Decl_Using :
parse_using
- The following compound into a resolved definition or declaration:
parse_attributes
- Parse specifiers
- Attempt to parse as constructor or destructor:
parse_global_nspace_constructor_destructor
- Otherwise:
parse_operator_function_or_variable
- Decl_Class :
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
parse_attributes
- Parse specifiers
- If the
parse_type
was called from a template parse, check to see if class was used instead of typname and consume as name. - This is where things get ugly for each of these depend on what the next token is.
- If its an in-place definition of a class, enum, struct, or union:
- If its a decltype (Not supported yet but draft impl there)
- If its a compound native type expression (unsigned, char, short, long, int, float, dobule, etc )
- Ends up being a regular type alias of an identifier
- Parse specifiers (postfix)
- We need to now look ahead to see If we're dealing with a function typename
- If wer're dealing with a function typename:
- Shove the specifiers, and identifier code we have so far into a return type typename's Name (untyped string)
- Reset the specifiers code for the top-level typeanme
- Check to see if the next token is an identifier:
parse_identifier
- Check to see if the next token is capture start and is not the last capture ("qualifier capture"):
- Consume
(
- Consume expresssion between capture
- Consume
)
- Consume
parse_params
- Parse postfix specifiers
- Shove the specifiers, and identifier code we have so far into a return type typename's Name (untyped string)
- Check for varaidic argument (param pack) token:
- 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
parse_attributes
- Parse specifiers (prefix)
- This is where things get ugly for each of these depend on what the next token is.
- If its an in-place definition of a class, enum, struct, or union:
- If its a decltype (Not supported yet but draft impl there)
- If its a compound native type expression (unsigned, char, short, long, int, float, dobule, etc )
- Ends up being a regular type alias of an identifier
- Parse specifiers (postfix)
- If any specifiers are found populate specifiers code with them.
- We need to now look ahead to see If we're dealing with a function typename
- If wer're dealing with a function typename:
- Shove the specifiers, and identifier code we have so far into a return type typename's Name (untyped string)
- Reset the specifiers code for the top-level typename
- Check to see if the next token is an identifier:
parse_identifier
- Check to see if the next token is capture start and is not the last capture ("qualifier capture"):
- Consume
(
- Parse binding specifiers
parse_identifier
parse_parameters
-> params_nested- Consume
)
- Construct a nested function typename definition for the qualifier
Name
- Consume
parse_params
- > params- Parse postfix specifiers
- Shove the specifiers, and identifier code we have so far into a return type typename's Name (untyped string)
- Check for varaidic argument (param pack) token:
- Consume varadic argument token
Later: Algorithim based on typename expressions
parse_typedef
- Check for export module specifier
- typedef keyword
- If its a preprocess macro: Get the macro name
- Else:
- Check to see if its a complicated definition (in-place enum, class, struct, union)
- If its a complicated definition:
- Perform the look ahead similar to
parse_complicated_definition
's implementation - Check to see if its a forward declaration :
parse_forward_declaration
- If end[-1] is an identifier:
- Its either an in-place, varaible type qualified identifier, or indirection type:
parse_foward_or_definition
- Its either an in-place, varaible type qualified identifier, or indirection type:
- else if end[-1] is a closing curly brace
- Its a definition:
parse_forward_or_definition
- Its a definition:
- else if end[-1] is a closing square brace
2. Its an array definition:
parse_type
- Perform the look ahead similar to
- Else :
parse-type
- Check for identifier : Consume the token
parse_array_decl
- Consume end statement
- Check for inline comment :
parse_comment
parse_union
- Check for export module specifier
- union keyword
parse_attributes
- Check for identifier
- Parse the body (Possible options):
- Newline
- Comment
- Decl_Class
- Decl_Enum
- Decl_Struct
- Decl_Union
- Preprocess_Define
- Preprocess_Conditional (if, ifdef, ifndef, elif, else, endif)
- Preprocess_Macro
- Preprocess_Pragma
- Unsupported preprocess directive
- Variable
- If its not an inplace definiton: End Statement
parse_using
- Check for export module specifier
- using keyword
- Check to see if its a using namespace
- Get the identifier
- If its a regular using declaration:
parse_attributes
parse_type
parse_array_decl
- End statement
- Check for inline comment
parse_variable
- Check for export module specifier
parse_attributes
parse specifiers
parse_type
parse_identifier
parse_variable_after_name