2023-08-28 20:46:50 -07:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
2023-08-21 17:30:13 -07:00
|
|
|
#pragma once
|
2023-08-21 20:28:39 -07:00
|
|
|
#include "gen/etoktype.cpp"
|
2023-08-21 20:02:20 -07:00
|
|
|
#include "interface.upfront.cpp"
|
2023-11-20 12:09:01 -08:00
|
|
|
#include "lexer.cpp"
|
|
|
|
#include "parser.cpp"
|
2023-08-28 20:46:50 -07:00
|
|
|
#endif
|
2023-08-21 17:30:13 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
// Publically Exposed Interface
|
2023-09-03 20:36:51 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeClass parse_class( StrC def )
|
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2024-12-09 13:45:18 -08:00
|
|
|
|
2024-12-03 06:31:27 -08:00
|
|
|
TokArray toks = lex( def );
|
2023-11-20 12:09:01 -08:00
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-09-03 20:36:51 -07:00
|
|
|
|
2024-12-03 06:31:27 -08:00
|
|
|
Context.Tokens = toks;
|
2023-11-20 12:09:01 -08:00
|
|
|
push_scope();
|
2024-12-09 19:51:24 -08:00
|
|
|
CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class, parser_not_inplace_def );
|
2024-12-09 13:45:18 -08:00
|
|
|
parser_pop(& Context);
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeConstructor parse_constructor( StrC def )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-07-29 03:32:16 -07:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-04-17 14:40:32 -07:00
|
|
|
// TODO(Ed): Constructors can have prefix attributes
|
|
|
|
|
2024-12-09 20:19:19 -08:00
|
|
|
CodeSpecifiers specifiers = NullCode;
|
|
|
|
Specifier specs_found[ 16 ] = { Spec_NumSpecifiers };
|
2024-04-17 14:40:32 -07:00
|
|
|
s32 NumSpecifiers = 0;
|
|
|
|
|
2024-12-09 13:45:18 -08:00
|
|
|
while ( left && tok_is_specifier(currtok) )
|
2024-04-17 14:40:32 -07:00
|
|
|
{
|
2024-12-09 13:45:18 -08:00
|
|
|
Specifier spec = strc_to_specifier( tok_to_str(currtok) );
|
2024-04-17 14:40:32 -07:00
|
|
|
|
|
|
|
b32 ignore_spec = false;
|
|
|
|
|
|
|
|
switch ( spec )
|
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
case Spec_Constexpr :
|
|
|
|
case Spec_Explicit:
|
|
|
|
case Spec_Inline :
|
|
|
|
case Spec_ForceInline :
|
|
|
|
case Spec_NeverInline :
|
2024-04-17 14:40:32 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 10:14:14 -08:00
|
|
|
case Spec_Const :
|
2024-04-17 14:40:32 -07:00
|
|
|
ignore_spec = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
2024-12-09 13:45:18 -08:00
|
|
|
log_failure( "Invalid specifier %s for variable\n%s", spec_to_str( spec ), parser_to_string(Context) );
|
|
|
|
parser_pop(& Context);
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2024-12-09 19:51:24 -08:00
|
|
|
CodeConstructor result = parser_parse_constructor( specifiers );
|
2023-11-20 12:09:01 -08:00
|
|
|
return result;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeDestructor parse_destructor( StrC def )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-04-17 14:40:32 -07:00
|
|
|
// TODO(Ed): Destructors can have prefix attributes
|
|
|
|
// TODO(Ed): Destructors can have virtual
|
|
|
|
|
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
CodeDestructor result = parser_parse_destructor(NullCode);
|
2023-11-20 12:09:01 -08:00
|
|
|
return result;
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeEnum parse_enum( StrC def )
|
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-08-07 17:16:04 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2023-10-24 21:25:35 -07:00
|
|
|
{
|
2024-12-09 13:45:18 -08:00
|
|
|
parser_pop(& Context);
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-10-24 21:25:35 -07:00
|
|
|
}
|
2023-08-22 23:17:47 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_enum( parser_not_inplace_def);
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeBody parse_export_body( StrC def )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-07-29 03:32:16 -07:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-07-29 09:25:38 -07:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_export_body();
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeExtern parse_extern_link( StrC def )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-08-01 11:02:54 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-08-01 11:02:54 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_extern_link();
|
2023-11-20 12:09:01 -08:00
|
|
|
}
|
2023-08-01 13:07:47 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeFriend parse_friend( StrC def )
|
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_friend();
|
2023-11-20 12:09:01 -08:00
|
|
|
}
|
2023-07-31 21:42:08 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeFn parse_function( StrC def )
|
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return (CodeFn) parser_parse_function();
|
2023-11-20 12:09:01 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeBody parse_global_body( StrC def )
|
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
|
|
|
push_scope();
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeBody result = parse_global_nspace( CT_Global_Body );
|
2024-12-09 13:45:18 -08:00
|
|
|
parser_pop(& Context);
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeNS parse_namespace( StrC def )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-07-29 03:32:16 -07:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-07-29 09:25:38 -07:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_namespace();
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeOperator parse_operator( StrC def )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return (CodeOperator) parser_parse_operator();
|
2023-11-20 12:09:01 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeOpCast parse_operator_cast( StrC def )
|
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_operator_cast(NullCode);
|
2023-11-20 12:09:01 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeStruct parse_struct( StrC def )
|
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-08-26 08:55:05 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-29 02:52:06 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
|
|
|
push_scope();
|
2024-12-09 19:51:24 -08:00
|
|
|
CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct, parser_not_inplace_def );
|
2024-12-09 13:45:18 -08:00
|
|
|
parser_pop(& Context);
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeTemplate parse_template( StrC def )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-07-29 03:32:16 -07:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-07-29 09:25:38 -07:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_template();
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeTypename parse_type( StrC def )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_type( parser_not_from_template, nullptr);
|
2023-11-20 12:09:01 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeTypedef parse_typedef( StrC def )
|
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_typedef();
|
2023-11-20 12:09:01 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeUnion parse_union( StrC def )
|
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_union( parser_not_inplace_def);
|
2023-11-20 12:09:01 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
CodeUsing parse_using( StrC def )
|
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-11-20 12:09:01 -08:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_using();
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeVar parse_variable( StrC def )
|
|
|
|
{
|
2024-12-03 06:31:27 -08:00
|
|
|
GEN_USING_NS_PARSER;
|
2023-07-29 03:32:16 -07:00
|
|
|
check_parse_args( def );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
TokArray toks = lex( def );
|
|
|
|
if ( toks.Arr == nullptr )
|
2024-12-01 21:03:38 -08:00
|
|
|
return InvalidCode;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-07-29 09:25:38 -07:00
|
|
|
Context.Tokens = toks;
|
2024-12-09 19:51:24 -08:00
|
|
|
return parser_parse_variable();
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Undef helper macros
|
2024-12-10 10:56:56 -08:00
|
|
|
#undef check_parse_args
|
|
|
|
#undef currtok_noskip
|
|
|
|
#undef currtok
|
|
|
|
#undef peektok
|
|
|
|
#undef prevtok
|
|
|
|
#undef nexttok
|
|
|
|
#undef nexttok_noskip
|
|
|
|
#undef eat
|
|
|
|
#undef left
|
|
|
|
#undef check
|
|
|
|
#undef push_scope
|
|
|
|
#undef def_assign
|
|
|
|
|
|
|
|
// Here for C Variant
|
|
|
|
#undef lex_dont_skip_formatting
|
|
|
|
#undef lex_skip_formatting
|
|
|
|
|
|
|
|
#undef parser_inplace_def
|
|
|
|
#undef parser_not_inplace_def
|
|
|
|
#undef parser_dont_consume_braces
|
|
|
|
#undef parser_consume_braces
|
|
|
|
#undef parser_not_from_template
|
|
|
|
#undef parser_use_parenthesis
|
|
|
|
#undef parser_strip_formatting_dont_preserve_newlines
|