Compare commits
4
Commits
050019c8c0
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca6f2eb83c | ||
|
|
b5b7b9ab4b | ||
|
|
8ba02de6ed | ||
|
|
ed755e34f1 |
No files matched your search
@@ -371,8 +371,7 @@ struct ParseStackNode
|
|||||||
// TODO(Ed): When an error occurs, the parse stack is not released and instead the scope is left dangling.
|
// TODO(Ed): When an error occurs, the parse stack is not released and instead the scope is left dangling.
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ParseOpts
|
struct ParseOpts {
|
||||||
{
|
|
||||||
AllocatorInfo backing_msgs;
|
AllocatorInfo backing_msgs;
|
||||||
AllocatorInfo backing_tokens;
|
AllocatorInfo backing_tokens;
|
||||||
AllocatorInfo backing_ast;
|
AllocatorInfo backing_ast;
|
||||||
@@ -380,34 +379,53 @@ struct ParseOpts
|
|||||||
|
|
||||||
ParseInfo wip_parse_str( LexedInfo lexed, ParseOpts* opts GEN_PARAM_DEFAULT );
|
ParseInfo wip_parse_str( LexedInfo lexed, ParseOpts* opts GEN_PARAM_DEFAULT );
|
||||||
|
|
||||||
GEN_API CodeClass parse_class ( Str class_def );
|
struct Opts_parse {
|
||||||
GEN_API CodeConstructor parse_constructor ( Str constructor_def );
|
|
||||||
GEN_API CodeDefine parse_define ( Str define_def );
|
|
||||||
GEN_API CodeDestructor parse_destructor ( Str destructor_def );
|
|
||||||
GEN_API CodeEnum parse_enum ( Str enum_def );
|
|
||||||
GEN_API CodeBody parse_export_body ( Str export_def );
|
|
||||||
GEN_API CodeExtern parse_extern_link ( Str exten_link_def );
|
|
||||||
GEN_API CodeFriend parse_friend ( Str friend_def );
|
|
||||||
GEN_API CodeFn parse_function ( Str fn_def );
|
|
||||||
|
|
||||||
struct Opts_parse_global_body
|
|
||||||
{
|
|
||||||
Context* ctx;
|
Context* ctx;
|
||||||
ParseInfo* info;
|
ParseInfo* info;
|
||||||
};
|
};
|
||||||
GEN_API void parse_global_body_base( Context* ctx, Str body_def, ParseInfo* info );
|
typedef Opts_parse Opts_parse_global_body;
|
||||||
GEN_API CodeBody parse_global_body( Str body_def, Opts_parse_global_body opts GEN_PARAM_DEFAULT );
|
|
||||||
|
|
||||||
GEN_API CodeNS parse_namespace ( Str namespace_def );
|
GEN_API void parse_class_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
GEN_API CodeOperator parse_operator ( Str operator_def );
|
GEN_API void parse_constructor_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
GEN_API CodeOpCast parse_operator_cast( Str operator_def );
|
GEN_API void parse_define_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
GEN_API CodeStruct parse_struct ( Str struct_def );
|
GEN_API void parse_destructor_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
GEN_API CodeTemplate parse_template ( Str template_def );
|
GEN_API void parse_enum_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
GEN_API CodeTypename parse_type ( Str type_def );
|
GEN_API void parse_export_body_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
GEN_API CodeTypedef parse_typedef ( Str typedef_def );
|
GEN_API void parse_extern_link_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
GEN_API CodeUnion parse_union ( Str union_def );
|
GEN_API void parse_friend_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
GEN_API CodeUsing parse_using ( Str using_def );
|
GEN_API void parse_function_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
GEN_API CodeVar parse_variable ( Str var_def );
|
GEN_API void parse_global_body_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
|
GEN_API void parse_namespace_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
|
GEN_API void parse_operator_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
|
GEN_API void parse_operator_cast_base(Context* ctx, Str def, ParseInfo* info);
|
||||||
|
GEN_API void parse_struct_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
|
GEN_API void parse_template_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
|
GEN_API void parse_type_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
|
GEN_API void parse_typedef_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
|
GEN_API void parse_union_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
|
GEN_API void parse_using_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
|
GEN_API void parse_variable_base (Context* ctx, Str def, ParseInfo* info);
|
||||||
|
|
||||||
|
GEN_API CodeClass parse_class (Str class_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeConstructor parse_constructor (Str constructor_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeDefine parse_define (Str define_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeDestructor parse_destructor (Str destructor_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeEnum parse_enum (Str enum_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeBody parse_export_body (Str export_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeExtern parse_extern_link (Str exten_link_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeFriend parse_friend (Str friend_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeFn parse_function (Str fn_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeBody parse_global_body (Str body_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeNS parse_namespace (Str namespace_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeOperator parse_operator (Str operator_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeOpCast parse_operator_cast(Str operator_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeStruct parse_struct (Str struct_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeTemplate parse_template (Str template_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeTypename parse_type (Str type_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeTypedef parse_typedef (Str typedef_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeUnion parse_union (Str union_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeUsing parse_using (Str using_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
GEN_API CodeVar parse_variable (Str var_def, Opts_parse opts GEN_PARAM_DEFAULT);
|
||||||
|
|
||||||
#pragma endregion Parsing
|
#pragma endregion Parsing
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,7 @@
|
|||||||
ParseInfo wip_parse_str(LexedInfo lexed, ParseOpts* opts)
|
ParseInfo wip_parse_str(LexedInfo lexed, ParseOpts* opts)
|
||||||
{
|
{
|
||||||
// TODO(Ed): Lift this.
|
// TODO(Ed): Lift this.
|
||||||
Context* ctx = _ctx;
|
Context* ctx = _ctx; ParseInfo info = struct_zero(ParseInfo);
|
||||||
ParseInfo info = struct_zero(ParseInfo);
|
|
||||||
|
|
||||||
if (lexed.tokens.num == 0 && lexed.tokens.ptr == nullptr) {
|
if (lexed.tokens.num == 0 && lexed.tokens.ptr == nullptr) {
|
||||||
ctx->parser = struct_zero(ParseContext);
|
ctx->parser = struct_zero(ParseContext);
|
||||||
@@ -27,91 +26,73 @@ ParseInfo wip_parse_str(LexedInfo lexed, ParseOpts* opts)
|
|||||||
// TODO(Ed): ParseInfo should be set to the parser context.
|
// TODO(Ed): ParseInfo should be set to the parser context.
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
ctx->parser = struct_zero(ParseContext);
|
||||||
ctx->parser.tokens = lexed.tokens;
|
ctx->parser.tokens = lexed.tokens; {
|
||||||
|
ctx->parser.lexed_messages = lexed.messages;
|
||||||
{
|
ParseStackNode scope = NullScope; parser_push(& ctx->parser, & scope);
|
||||||
ParseStackNode scope = NullScope;
|
CodeBody result = parse_global_nspace(ctx,CT_Global_Body); (void)result;
|
||||||
parser_push(& ctx->parser, & scope);
|
|
||||||
|
|
||||||
CodeBody result = parse_global_nspace(ctx,CT_Global_Body);
|
|
||||||
(void)result;
|
|
||||||
|
|
||||||
parser_pop(& ctx->parser);
|
parser_pop(& ctx->parser);
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeClass parse_class( Str def )
|
internal b32 parse_base_begin(Context* ctx, Str def, ParseInfo* info, char const* function_name) {
|
||||||
{
|
if (ctx == nullptr || info == nullptr) GEN_FATAL("parse base: null context or info");
|
||||||
// TODO(Ed): Lift this.
|
|
||||||
Context* ctx = _ctx;
|
|
||||||
CodeClass result = InvalidCode;
|
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
|
||||||
|
|
||||||
|
info[0] = struct_zero(ParseInfo);
|
||||||
|
info->result = Code_Invalid;
|
||||||
ctx->parser = struct_zero(ParseContext);
|
ctx->parser = struct_zero(ParseContext);
|
||||||
if (check_parse_args(def) == false)
|
if (_check_parse_args(ctx, def, function_name) == false) {
|
||||||
goto done;
|
info->messages = ctx->parser.messages;
|
||||||
|
return false;
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
info->lexed = lex(ctx, def);
|
||||||
ParseStackNode scope = NullScope;
|
ctx->parser.lexed_messages = info->lexed.messages;
|
||||||
parser_push(& ctx->parser, & scope);
|
if (info->lexed.tokens.num == 0) {
|
||||||
|
info->messages = ctx->parser.messages;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->parser.tokens = info->lexed.tokens;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_class_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
|
CodeClass result = InvalidCode;
|
||||||
|
if (parse_base_begin(ctx, def, info, "parse_class") == false) return;
|
||||||
|
/*Parse*/ {
|
||||||
|
ParseStackNode scope = NullScope; parser_push(& ctx->parser, & scope);
|
||||||
result = (CodeClass) parse_class_struct( ctx, Tok_Decl_Class, parser_not_inplace_def );
|
result = (CodeClass) parse_class_struct( ctx, Tok_Decl_Class, parser_not_inplace_def );
|
||||||
parser_pop(& ctx->parser);
|
parser_pop(& ctx->parser);
|
||||||
}
|
}
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeConstructor parse_constructor(Str def )
|
CodeClass parse_class(Str def, Opts_parse opts) {
|
||||||
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx;
|
||||||
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_class: no context");
|
||||||
|
ParseInfo* info = resolved.info; if (info == nullptr) info = & ctx->parse_info;
|
||||||
|
parse_class_base(ctx, def, info); return cast(CodeClass, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_constructor_base(Context* ctx, Str def, ParseInfo* info)
|
||||||
{
|
{
|
||||||
// TODO(Ed): Lift this.
|
|
||||||
Context* ctx = _ctx;
|
|
||||||
CodeConstructor result = InvalidCode;
|
CodeConstructor result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_constructor") == false) return;
|
||||||
|
/*Parse*/ {
|
||||||
ctx->parser = struct_zero(ParseContext);
|
ParseStackNode scope = NullScope; parser_push(& ctx->parser, & scope);
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
ParseStackNode scope = NullScope;
|
|
||||||
parser_push(& ctx->parser, & scope);
|
|
||||||
|
|
||||||
// TODO(Ed): Constructors can have prefix attributes
|
// TODO(Ed): Constructors can have prefix attributes
|
||||||
|
|
||||||
CodeSpecifiers specifiers = NullCode;
|
CodeSpecifiers specifiers = NullCode;
|
||||||
Specifier specs_found[ 16 ] = { Spec_NumSpecifiers };
|
Specifier specs_found[ 16 ] = { Spec_NumSpecifiers };
|
||||||
s32 NumSpecifiers = 0;
|
s32 NumSpecifiers = 0;
|
||||||
|
|
||||||
while ( left && tok_is_specifier(currtok) )
|
while ( left && tok_is_specifier(currtok) )
|
||||||
{
|
{
|
||||||
Specifier spec = str_to_specifier( currtok.Text );
|
|
||||||
|
|
||||||
b32 ignore_spec = false;
|
b32 ignore_spec = false;
|
||||||
|
Specifier spec = str_to_specifier( currtok.Text );
|
||||||
switch ( spec )
|
switch ( spec ) {
|
||||||
{
|
|
||||||
case Spec_Constexpr :
|
case Spec_Constexpr :
|
||||||
case Spec_Explicit:
|
case Spec_Explicit:
|
||||||
case Spec_Inline :
|
case Spec_Inline :
|
||||||
@@ -126,15 +107,16 @@ CodeConstructor parse_constructor(Str def )
|
|||||||
default :
|
default :
|
||||||
log_failure( "Invalid specifier %s for variable\n%S", spec_to_str( spec ), parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp) );
|
log_failure( "Invalid specifier %s for variable\n%S", spec_to_str( spec ), parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp) );
|
||||||
parser_pop(& ctx->parser);
|
parser_pop(& ctx->parser);
|
||||||
goto done;
|
info->result = cast(Code, result);
|
||||||
|
info->messages = ctx->parser.messages;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every specifier after would be considered part of the type type signature
|
// Every specifier after would be considered part of the type type signature
|
||||||
if (ignore_spec)
|
if (ignore_spec) break;
|
||||||
break;
|
|
||||||
|
|
||||||
specs_found[ NumSpecifiers ] = spec;
|
specs_found[ NumSpecifiers ] = spec;
|
||||||
NumSpecifiers++;
|
++ NumSpecifiers;
|
||||||
eat( currtok.Type );
|
eat( currtok.Type );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,211 +124,143 @@ CodeConstructor parse_constructor(Str def )
|
|||||||
specifiers = def_specifiers_arr( NumSpecifiers, specs_found );
|
specifiers = def_specifiers_arr( NumSpecifiers, specs_found );
|
||||||
// <specifiers> ...
|
// <specifiers> ...
|
||||||
}
|
}
|
||||||
|
|
||||||
result = parser_parse_constructor(ctx, specifiers);
|
result = parser_parse_constructor(ctx, specifiers);
|
||||||
parser_pop(& ctx->parser);
|
parser_pop(& ctx->parser);
|
||||||
}
|
}
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeDefine parse_define( Str def )
|
CodeConstructor parse_constructor(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_constructor: no context");
|
||||||
Context* ctx = _ctx;
|
ParseInfo* info = resolved.info; if (info == nullptr) info = & ctx->parse_info;
|
||||||
|
parse_constructor_base(ctx, def, info); return cast(CodeConstructor, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_define_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeDefine result = InvalidCode;
|
CodeDefine result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_define") == false) return;
|
||||||
|
/*Parse*/ {
|
||||||
ctx->parser = struct_zero(ParseContext);
|
ParseStackNode scope = NullScope; parser_push(& ctx->parser, & scope);
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
ParseStackNode scope = NullScope;
|
|
||||||
parser_push(& ctx->parser, & scope);
|
|
||||||
result = parser_parse_define(ctx);
|
result = parser_parse_define(ctx);
|
||||||
parser_pop(& ctx->parser);
|
parser_pop(& ctx->parser);
|
||||||
}
|
}
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeDestructor parse_destructor( Str def )
|
CodeDefine parse_define(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_define: no context");
|
||||||
Context* ctx = _ctx;
|
ParseInfo* info = resolved.info; if (info == nullptr) info = & ctx->parse_info;
|
||||||
|
parse_define_base(ctx, def, info); return cast(CodeDefine, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_destructor_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeDestructor result = InvalidCode;
|
CodeDestructor result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_destructor") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(Ed): Destructors can have prefix attributes
|
// TODO(Ed): Destructors can have prefix attributes
|
||||||
// TODO(Ed): Destructors can have virtual
|
// TODO(Ed): Destructors can have virtual
|
||||||
|
|
||||||
result = parser_parse_destructor(ctx, NullCode);
|
result = parser_parse_destructor(ctx, NullCode);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeEnum parse_enum( Str def )
|
CodeDestructor parse_destructor(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_destructor: no context");
|
||||||
Context* ctx = _ctx;
|
ParseInfo* info = resolved.info; if (info == nullptr) info = & ctx->parse_info;
|
||||||
|
parse_destructor_base(ctx, def, info); return cast(CodeDestructor, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_enum_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeEnum result = InvalidCode;
|
CodeEnum result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_enum") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = parser_parse_enum(ctx, parser_not_inplace_def);
|
result = parser_parse_enum(ctx, parser_not_inplace_def);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeBody parse_export_body( Str def )
|
CodeEnum parse_enum(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_enum: no context");
|
||||||
Context* ctx = _ctx;
|
ParseInfo* info = resolved.info; if (info == nullptr) info = & ctx->parse_info;
|
||||||
|
parse_enum_base(ctx, def, info); return cast(CodeEnum, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_export_body_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeBody result = InvalidCode;
|
CodeBody result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_export_body") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = parser_parse_export_body(ctx);
|
result = parser_parse_export_body(ctx);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeExtern parse_extern_link( Str def )
|
CodeBody parse_export_body(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_export_body: no context");
|
||||||
Context* ctx = _ctx;
|
ParseInfo* info = resolved.info; if (info == nullptr) info = & ctx->parse_info;
|
||||||
|
parse_export_body_base(ctx, def, info); return cast(CodeBody, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_extern_link_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeExtern result = InvalidCode;
|
CodeExtern result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_extern_link") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = parser_parse_extern_link(ctx);
|
result = parser_parse_extern_link(ctx);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeFriend parse_friend( Str def )
|
CodeExtern parse_extern_link(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_extern_link: no context");
|
||||||
Context* ctx = _ctx;
|
ParseInfo* info = resolved.info; if (info == nullptr) info = & ctx->parse_info;
|
||||||
|
parse_extern_link_base(ctx, def, info); return cast(CodeExtern, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_friend_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeFriend result = InvalidCode;
|
CodeFriend result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_friend") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = parser_parse_friend(ctx);
|
result = parser_parse_friend(ctx);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeFn parse_function( Str def )
|
CodeFriend parse_friend(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_friend: no context");
|
||||||
Context* ctx = _ctx;
|
ParseInfo* info = resolved.info; if (info == nullptr) info = & ctx->parse_info;
|
||||||
|
parse_friend_base(ctx, def, info); return cast(CodeFriend, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_function_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeFn result = InvalidCode;
|
CodeFn result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_function") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = (CodeFn) parser_parse_function(ctx);
|
result = (CodeFn) parser_parse_function(ctx);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeFn parse_function(Str def, Opts_parse opts) {
|
||||||
|
Opts_parse resolved = get_optional(opts);
|
||||||
|
Context* ctx = resolved.ctx;
|
||||||
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_function: no context");
|
||||||
|
ParseInfo* info = resolved.info; if (info == nullptr) info = & ctx->parse_info;
|
||||||
|
parse_function_base(ctx, def, info); return cast(CodeFn, info->result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_global_body_base( Context* ctx, Str def, ParseInfo* info )
|
void parse_global_body_base( Context* ctx, Str def, ParseInfo* info )
|
||||||
{
|
{
|
||||||
LexedInfo lexed;
|
LexedInfo lexed; CodeBody body;
|
||||||
CodeBody body;
|
if ( ctx == nullptr || info == nullptr ) GEN_FATAL( "parse_global_body_base: null context or info" );
|
||||||
|
|
||||||
if ( ctx == nullptr || info == nullptr )
|
|
||||||
GEN_FATAL( "parse_global_body_base: null context or info" );
|
|
||||||
|
|
||||||
info[0] = struct_zero( ParseInfo );
|
info[0] = struct_zero( ParseInfo );
|
||||||
lexed = struct_zero( LexedInfo );
|
lexed = struct_zero( LexedInfo );
|
||||||
@@ -362,6 +276,7 @@ void parse_global_body_base( Context* ctx, Str def, ParseInfo* info )
|
|||||||
|
|
||||||
lexed = lex( ctx, def );
|
lexed = lex( ctx, def );
|
||||||
info->lexed = lexed;
|
info->lexed = lexed;
|
||||||
|
ctx->parser.lexed_messages = lexed.messages;
|
||||||
if ( lexed.tokens.num == 0 ) {
|
if ( lexed.tokens.num == 0 ) {
|
||||||
info->result = cast( Code, body );
|
info->result = cast( Code, body );
|
||||||
info->messages = ctx->parser.messages;
|
info->messages = ctx->parser.messages;
|
||||||
@@ -378,286 +293,179 @@ void parse_global_body_base( Context* ctx, Str def, ParseInfo* info )
|
|||||||
info->messages = ctx->parser.messages;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeBody parse_global_body( Str def, Opts_parse_global_body opts ) {
|
CodeBody parse_global_body( Str def, Opts_parse opts ) {
|
||||||
Opts_parse_global_body resolved = get_optional( opts );
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx;
|
||||||
Context* ctx = resolved.ctx;
|
if ( ctx == nullptr ) ctx = _ctx; if ( ctx == nullptr ) GEN_FATAL( "parse_global_body: no context" );
|
||||||
ParseInfo* info;
|
ParseInfo* info = resolved.info; if ( info == nullptr ) info = & ctx->parse_info;
|
||||||
|
parse_global_body_base( ctx, def, info ); return cast( CodeBody, info->result );
|
||||||
if ( ctx == nullptr ) ctx = _ctx;
|
|
||||||
if ( ctx == nullptr ) GEN_FATAL( "parse_global_body: no context" );
|
|
||||||
info = resolved.info; if ( info == nullptr ) info = & ctx->parse_info;
|
|
||||||
|
|
||||||
parse_global_body_base( ctx, def, info );
|
|
||||||
return cast( CodeBody, info->result );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeNS parse_namespace( Str def )
|
void parse_namespace_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
{
|
|
||||||
// TODO(Ed): Lift this.
|
|
||||||
Context* ctx = _ctx;
|
|
||||||
CodeNS result = InvalidCode;
|
CodeNS result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_namespace") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = parser_parse_namespace(ctx);
|
result = parser_parse_namespace(ctx);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeOperator parse_operator( Str def )
|
CodeNS parse_namespace(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_namespace: no context");
|
||||||
Context* ctx = _ctx;
|
ParseInfo* info = resolved.info; if (info == nullptr) info = &ctx->parse_info;
|
||||||
|
parse_namespace_base(ctx, def, info); return cast(CodeNS, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_operator_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeOperator result = InvalidCode;
|
CodeOperator result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_operator") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = (CodeOperator) parser_parse_operator(ctx);
|
result = (CodeOperator) parser_parse_operator(ctx);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeOpCast parse_operator_cast( Str def )
|
CodeOperator parse_operator(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx; ParseInfo* info;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_operator: no context");
|
||||||
Context* ctx = _ctx;
|
info = resolved.info; if (info == nullptr) info = &ctx->parse_info;
|
||||||
|
parse_operator_base(ctx, def, info); return cast(CodeOperator, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_operator_cast_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeOpCast result = InvalidCode;
|
CodeOpCast result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_operator_cast") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = parser_parse_operator_cast(ctx, NullCode);
|
result = parser_parse_operator_cast(ctx, NullCode);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeStruct parse_struct( Str def )
|
CodeOpCast parse_operator_cast(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx; ParseInfo* info;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_operator_cast: no context");
|
||||||
Context* ctx = _ctx;
|
info = resolved.info; if (info == nullptr) info = &ctx->parse_info;
|
||||||
|
parse_operator_cast_base(ctx, def, info); return cast(CodeOpCast, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_struct_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeStruct result = InvalidCode;
|
CodeStruct result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_struct") == false) return;
|
||||||
|
/*Parse*/ {
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
ParseStackNode scope = NullScope;
|
ParseStackNode scope = NullScope;
|
||||||
parser_push(& ctx->parser, & scope);
|
parser_push(& ctx->parser, & scope);
|
||||||
result = (CodeStruct) parse_class_struct( ctx, Tok_Decl_Struct, parser_not_inplace_def );
|
result = (CodeStruct) parse_class_struct( ctx, Tok_Decl_Struct, parser_not_inplace_def );
|
||||||
parser_pop(& ctx->parser);
|
parser_pop(& ctx->parser);
|
||||||
}
|
}
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeTemplate parse_template( Str def )
|
CodeStruct parse_struct(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx; ParseInfo* info;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_struct: no context");
|
||||||
Context* ctx = _ctx;
|
info = resolved.info; if (info == nullptr) info = &ctx->parse_info;
|
||||||
|
parse_struct_base(ctx, def, info); return cast(CodeStruct, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_template_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeTemplate result = InvalidCode;
|
CodeTemplate result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_template") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = parser_parse_template(ctx);
|
result = parser_parse_template(ctx);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeTypename parse_type( Str def )
|
CodeTemplate parse_template(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx; ParseInfo* info;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_template: no context");
|
||||||
Context* ctx = _ctx;
|
info = resolved.info; if (info == nullptr) info = &ctx->parse_info;
|
||||||
|
parse_template_base(ctx, def, info); return cast(CodeTemplate, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_type_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeTypename result = InvalidCode;
|
CodeTypename result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_type") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = parser_parse_type(ctx, parser_not_from_template, nullptr);
|
result = parser_parse_type(ctx, parser_not_from_template, nullptr);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeTypedef parse_typedef( Str def )
|
CodeTypename parse_type(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx; ParseInfo* info;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_type: no context");
|
||||||
Context* ctx = _ctx;
|
info = resolved.info; if (info == nullptr) info = &ctx->parse_info;
|
||||||
|
parse_type_base(ctx, def, info); return cast(CodeTypename, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_typedef_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeTypedef result = InvalidCode;
|
CodeTypedef result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_typedef") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = parser_parse_typedef(ctx);
|
result = parser_parse_typedef(ctx);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeUnion parse_union( Str def )
|
CodeTypedef parse_typedef(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx; ParseInfo* info;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_typedef: no context");
|
||||||
Context* ctx = _ctx;
|
info = resolved.info; if (info == nullptr) info = &ctx->parse_info;
|
||||||
|
parse_typedef_base(ctx, def, info); return cast(CodeTypedef, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_union_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeUnion result = InvalidCode;
|
CodeUnion result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_union") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = parser_parse_union(ctx, parser_not_inplace_def);
|
result = parser_parse_union(ctx, parser_not_inplace_def);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeUsing parse_using( Str def )
|
CodeUnion parse_union(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx; ParseInfo* info;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_union: no context");
|
||||||
Context* ctx = _ctx;
|
info = resolved.info; if (info == nullptr) info = &ctx->parse_info;
|
||||||
|
parse_union_base(ctx, def, info); return cast(CodeUnion, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_using_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeUsing result = InvalidCode;
|
CodeUsing result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_using") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = parser_parse_using(ctx);
|
result = parser_parse_using(ctx);
|
||||||
done:
|
info->result = cast(Code, result);
|
||||||
return result;
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeVar parse_variable( Str def )
|
CodeUsing parse_using(Str def, Opts_parse opts) {
|
||||||
{
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx; ParseInfo* info;
|
||||||
// TODO(Ed): Lift this.
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_using: no context");
|
||||||
Context* ctx = _ctx;
|
info = resolved.info; if (info == nullptr) info = &ctx->parse_info;
|
||||||
|
parse_using_base(ctx, def, info); return cast(CodeUsing, info->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_variable_base(Context* ctx, Str def, ParseInfo* info) {
|
||||||
CodeVar result = InvalidCode;
|
CodeVar result = InvalidCode;
|
||||||
LexedInfo lexed = struct_zero(LexedInfo);
|
if (parse_base_begin(ctx, def, info, "parse_variable") == false) return;
|
||||||
|
|
||||||
ctx->parser = struct_zero(ParseContext);
|
|
||||||
if (check_parse_args(def) == false)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
lexed = lex(ctx, def);
|
|
||||||
ctx->parser.tokens = lexed.tokens;
|
|
||||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
|
||||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
|
||||||
parser_record_failure(ctx, lexed.messages->content);
|
|
||||||
else
|
|
||||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
if (parser_slice_is_formatting_only(& ctx->parser)) {
|
if (parser_slice_is_formatting_only(& ctx->parser)) {
|
||||||
parser_record_failure(ctx, txt("parse_variable: only formatting tokens"));
|
parser_record_failure(ctx, txt("parse_variable: only formatting tokens"));
|
||||||
goto done;
|
}
|
||||||
|
else {
|
||||||
|
result = parser_parse_variable(ctx);
|
||||||
|
}
|
||||||
|
info->result = cast(Code, result);
|
||||||
|
info->messages = ctx->parser.messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = parser_parse_variable(ctx);
|
CodeVar parse_variable(Str def, Opts_parse opts) {
|
||||||
done:
|
Opts_parse resolved = get_optional(opts); Context* ctx = resolved.ctx; ParseInfo* info;
|
||||||
return result;
|
if (ctx == nullptr) ctx = _ctx; if (ctx == nullptr) GEN_FATAL("parse_variable: no context");
|
||||||
|
info = resolved.info; if (info == nullptr) info = &ctx->parse_info;
|
||||||
|
parse_variable_base(ctx, def, info); return cast(CodeVar, info->result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Undef helper macros
|
// Undef helper macros
|
||||||
|
|||||||
+431
-21
@@ -104,14 +104,49 @@ void parser_record_failure(Context* ctx, Str text) {
|
|||||||
ctx->parser.messages = msg;
|
ctx->parser.messages = msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal b32 parser_is_recoverable_body(ParseContext* parser) {
|
||||||
|
ParseStackNode* scope = parser->scope;
|
||||||
|
b32 in_function_body = false;
|
||||||
|
while ( scope )
|
||||||
|
{
|
||||||
|
if ( scope->code_rel )
|
||||||
|
{
|
||||||
|
CodeType type = scope->code_rel->Type;
|
||||||
|
if ( type == CT_Function_Body ) {
|
||||||
|
in_function_body = true;
|
||||||
|
scope = scope->prev;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( in_function_body && type != CT_Global_Body )
|
||||||
|
return false;
|
||||||
|
return type == CT_Global_Body || type == CT_Namespace_Body || type == CT_Class_Body || type == CT_Struct_Body;
|
||||||
|
}
|
||||||
|
scope = scope->prev;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool lex__eat(Context* ctx, ParseContext* parser, TokType type)
|
bool lex__eat(Context* ctx, ParseContext* parser, TokType type)
|
||||||
{
|
{
|
||||||
b32 ate = false;
|
b32 ate = false;
|
||||||
Token at_idx;
|
Token at_idx;
|
||||||
b32 not_accepted;
|
b32 not_accepted;
|
||||||
b32 is_identifier;
|
b32 is_identifier;
|
||||||
if (parser->tokens.num - parser->token_id <= 0)
|
s32 start_id = parser->token_id;
|
||||||
|
if ( parser->token_mismatch )
|
||||||
goto done;
|
goto done;
|
||||||
|
if (parser->tokens.num - parser->token_id <= 0)
|
||||||
|
{
|
||||||
|
if ( parser_is_recoverable_body(parser) ) {
|
||||||
|
StrBuilder message = strbuilder_fmt_buf(ctx->Allocator_Temp, "Parse Error, TokArray::eat, Expected: ' %S ' at end of token slice\n%SB"
|
||||||
|
, toktype_to_str(type)
|
||||||
|
, parser_to_strbuilder(parser, ctx->Allocator_Temp)
|
||||||
|
);
|
||||||
|
parser_record_failure(ctx, strbuilder_to_str(message));
|
||||||
|
parser->token_mismatch = true;
|
||||||
|
}
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
at_idx = parser->tokens.ptr[ parser->token_id ];
|
at_idx = parser->tokens.ptr[ parser->token_id ];
|
||||||
if ( ( at_idx.Type == Tok_NewLine && type != Tok_NewLine )
|
if ( ( at_idx.Type == Tok_NewLine && type != Tok_NewLine )
|
||||||
@@ -129,15 +164,26 @@ bool lex__eat(Context* ctx, ParseContext* parser, TokType type)
|
|||||||
}
|
}
|
||||||
if ( not_accepted )
|
if ( not_accepted )
|
||||||
{
|
{
|
||||||
|
parser->token_id = start_id;
|
||||||
Token tok = * lex_current( parser, lex_skip_formatting );
|
Token tok = * lex_current( parser, lex_skip_formatting );
|
||||||
log_failure( "Parse Error, TokArray::eat, Expected: ' %S ' not ' %S ' (%d, %d)`\n%SB"
|
StrBuilder message = strbuilder_fmt_buf(ctx->Allocator_Temp, "Parse Error, TokArray::eat, Expected: ' %S ' not ' %S ' (%d, %d)`\n%SB"
|
||||||
, toktype_to_str(type)
|
, toktype_to_str(type)
|
||||||
, at_idx.Text
|
, at_idx.Text
|
||||||
, tok.Line
|
, tok.Line
|
||||||
, tok.Column
|
, tok.Column
|
||||||
, parser_to_strbuilder(parser, ctx->Allocator_Temp)
|
, parser_to_strbuilder(parser, ctx->Allocator_Temp)
|
||||||
);
|
);
|
||||||
|
Str message_text = strbuilder_to_str(message);
|
||||||
|
if ( parser_is_recoverable_body(parser) ) {
|
||||||
|
parser_record_failure(ctx, message_text);
|
||||||
|
parser->token_mismatch = true;
|
||||||
|
}
|
||||||
|
else if ( parser->lexed_messages )
|
||||||
|
parser_record_failure(ctx, message_text);
|
||||||
|
else {
|
||||||
|
log_failure("%S", message_text);
|
||||||
GEN_DEBUG_TRAP();
|
GEN_DEBUG_TRAP();
|
||||||
|
}
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +252,7 @@ done:
|
|||||||
# define nexttok (* lex_next( & ctx->parser, lex_skip_formatting ))
|
# define nexttok (* lex_next( & ctx->parser, lex_skip_formatting ))
|
||||||
# define nexttok_noskip (* lex_next( & ctx->parser, lex_dont_skip_formatting))
|
# define nexttok_noskip (* lex_next( & ctx->parser, lex_dont_skip_formatting))
|
||||||
# define eat( Type_ ) lex__eat(ctx, & ctx->parser, Type_ )
|
# define eat( Type_ ) lex__eat(ctx, & ctx->parser, Type_ )
|
||||||
# define left ( ctx->parser.tokens.num - ctx->parser.token_id )
|
# define left ( ! ctx->parser.token_mismatch && ctx->parser.tokens.num - ctx->parser.token_id )
|
||||||
|
|
||||||
#if GEN_COMPILER_CPP
|
#if GEN_COMPILER_CPP
|
||||||
# define def_assign( ... ) { __VA_ARGS__ }
|
# define def_assign( ... ) { __VA_ARGS__ }
|
||||||
@@ -233,6 +279,8 @@ done:
|
|||||||
|
|
||||||
// Procedure Forwards ( Entire parser internal parser interface )
|
// Procedure Forwards ( Entire parser internal parser interface )
|
||||||
|
|
||||||
|
internal void parser_recover_body_member(Context* ctx, CodeBody body, Token member_start_token, s32 member_start_id, b32 allow_comma);
|
||||||
|
|
||||||
internal Code parse_array_decl (Context* ctx);
|
internal Code parse_array_decl (Context* ctx);
|
||||||
internal CodeAttributes parse_attributes (Context* ctx);
|
internal CodeAttributes parse_attributes (Context* ctx);
|
||||||
internal CodeComment parse_comment (Context* ctx);
|
internal CodeComment parse_comment (Context* ctx);
|
||||||
@@ -533,8 +581,7 @@ StrBuilder parser_strip_formatting(Context* ctx, Str raw_text, bool preserve_new
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
StrBuilder parser_strip_formatting_2(TokenSlice tokens)
|
StrBuilder parser_strip_formatting_2(TokenSlice tokens) {
|
||||||
{
|
|
||||||
// TODO(Ed): Use this to produce strings for validation purposes. We shouldn't serialize down from tokens once we start storing token slices for content.
|
// TODO(Ed): Use this to produce strings for validation purposes. We shouldn't serialize down from tokens once we start storing token slices for content.
|
||||||
StrBuilder result = struct_zero(StrBuilder);
|
StrBuilder result = struct_zero(StrBuilder);
|
||||||
return result;
|
return result;
|
||||||
@@ -870,8 +917,14 @@ CodeBody parse_class_struct_body(Context* ctx, TokType which, Token name)
|
|||||||
else
|
else
|
||||||
result->Type = CT_Struct_Body;
|
result->Type = CT_Struct_Body;
|
||||||
|
|
||||||
|
scope.code_rel = cast(Code, result);
|
||||||
|
|
||||||
while ( left && currtok_noskip.Type != Tok_BraceCurly_Close )
|
while ( left && currtok_noskip.Type != Tok_BraceCurly_Close )
|
||||||
{
|
{
|
||||||
|
ParseMessage* messages_before_member = ctx->parser.messages;
|
||||||
|
s32 member_start_id = ctx->parser.token_id;
|
||||||
|
Token member_start_token = currtok_noskip;
|
||||||
|
|
||||||
Code member = Code_Invalid;
|
Code member = Code_Invalid;
|
||||||
CodeAttributes attributes = { nullptr };
|
CodeAttributes attributes = { nullptr };
|
||||||
CodeSpecifiers specifiers = { nullptr };
|
CodeSpecifiers specifiers = { nullptr };
|
||||||
@@ -1180,12 +1233,27 @@ CodeBody parse_class_struct_body(Context* ctx, TokType which, Token name)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b32 member_is_nested_scope = member != Code_Invalid && (member->Type == CT_Class || member->Type == CT_Struct);
|
||||||
|
b32 member_failed = ctx->parser.token_mismatch || (ctx->parser.messages != messages_before_member && member_is_nested_scope == false);
|
||||||
|
if (member_failed) {
|
||||||
|
if ( ctx->parser.messages != messages_before_member ) ctx->parser.messages->Next = messages_before_member;
|
||||||
|
ctx->parser.token_id = member_start_id;
|
||||||
|
ctx->parser.token_mismatch = false;
|
||||||
|
member = Code_Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
if (member == Code_Invalid)
|
if (member == Code_Invalid)
|
||||||
{
|
{
|
||||||
|
if ( member_failed == false ) {
|
||||||
log_failure( "Failed to parse member\n%SB", parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp) );
|
log_failure( "Failed to parse member\n%SB", parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp) );
|
||||||
parser_pop(& ctx->parser);
|
parser_pop(& ctx->parser);
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
}
|
}
|
||||||
|
ctx->parser.token_id = member_start_id;
|
||||||
|
ctx->parser.token_mismatch = false;
|
||||||
|
parser_recover_body_member(ctx, result, member_start_token, member_start_id, false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
body_append(result, member );
|
body_append(result, member );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1196,10 +1264,8 @@ CodeBody parse_class_struct_body(Context* ctx, TokType which, Token name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
CodeComment parse_comment(Context* ctx)
|
CodeComment parse_comment(Context* ctx) {
|
||||||
{
|
ParseStackNode scope = NullScope; parser_push(& ctx->parser, & scope );
|
||||||
ParseStackNode scope = NullScope;
|
|
||||||
parser_push(& ctx->parser, & scope );
|
|
||||||
|
|
||||||
CodeComment
|
CodeComment
|
||||||
result = (CodeComment) make_code();
|
result = (CodeComment) make_code();
|
||||||
@@ -1215,8 +1281,7 @@ CodeComment parse_comment(Context* ctx)
|
|||||||
internal
|
internal
|
||||||
Code parse_complicated_definition(Context* ctx, TokType which)
|
Code parse_complicated_definition(Context* ctx, TokType which)
|
||||||
{
|
{
|
||||||
ParseStackNode scope = NullScope;
|
ParseStackNode scope = NullScope; parser_push(& ctx->parser, & scope );
|
||||||
parser_push(& ctx->parser, & scope );
|
|
||||||
|
|
||||||
b32 is_inplace = false;
|
b32 is_inplace = false;
|
||||||
b32 is_fn_def = false;
|
b32 is_fn_def = false;
|
||||||
@@ -1399,8 +1464,7 @@ Code parse_complicated_definition(Context* ctx, TokType which)
|
|||||||
internal inline
|
internal inline
|
||||||
Code parse_assignment_expression(Context* ctx)
|
Code parse_assignment_expression(Context* ctx)
|
||||||
{
|
{
|
||||||
ParseStackNode scope = NullScope;
|
ParseStackNode scope = NullScope; parser_push(& ctx->parser, & scope );
|
||||||
parser_push(& ctx->parser, & scope );
|
|
||||||
|
|
||||||
Code expr = { nullptr };
|
Code expr = { nullptr };
|
||||||
|
|
||||||
@@ -1445,7 +1509,6 @@ internal inline
|
|||||||
Code parse_forward_or_definition(Context* ctx, TokType which, bool is_inplace )
|
Code parse_forward_or_definition(Context* ctx, TokType which, bool is_inplace )
|
||||||
{
|
{
|
||||||
Code result = InvalidCode;
|
Code result = InvalidCode;
|
||||||
|
|
||||||
switch ( which )
|
switch ( which )
|
||||||
{
|
{
|
||||||
case Tok_Decl_Class:
|
case Tok_Decl_Class:
|
||||||
@@ -1483,8 +1546,7 @@ CodeFn parse_function_after_name(Context* ctx
|
|||||||
, Token name
|
, Token name
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ParseStackNode scope = NullScope;
|
ParseStackNode scope = NullScope; parser_push(& ctx->parser, & scope );
|
||||||
parser_push(& ctx->parser, & scope );
|
|
||||||
|
|
||||||
CodeParams params = parse_params(ctx, parser_use_parenthesis);
|
CodeParams params = parse_params(ctx, parser_use_parenthesis);
|
||||||
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Parameters> )
|
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Parameters> )
|
||||||
@@ -1639,14 +1701,14 @@ CodeFn parse_function_after_name(Context* ctx
|
|||||||
internal
|
internal
|
||||||
Code parse_function_body(Context* ctx)
|
Code parse_function_body(Context* ctx)
|
||||||
{
|
{
|
||||||
ParseStackNode scope = NullScope;
|
ParseStackNode scope = NullScope; parser_push(& ctx->parser, & scope );
|
||||||
parser_push(& ctx->parser, & scope );
|
|
||||||
|
|
||||||
eat( Tok_BraceCurly_Open );
|
eat( Tok_BraceCurly_Open );
|
||||||
|
|
||||||
CodeBody
|
CodeBody
|
||||||
result = (CodeBody) make_code();
|
result = (CodeBody) make_code();
|
||||||
result->Type = CT_Function_Body;
|
result->Type = CT_Function_Body;
|
||||||
|
scope.code_rel = cast(Code, result);
|
||||||
|
|
||||||
// TODO : Support actual parsing of function body
|
// TODO : Support actual parsing of function body
|
||||||
Token start = currtok_noskip;
|
Token start = currtok_noskip;
|
||||||
@@ -1667,8 +1729,7 @@ Code parse_function_body(Context* ctx)
|
|||||||
|
|
||||||
s32 len = ( (sptr)prevtok.Text.Ptr + prevtok.Text.Len ) - (sptr)start.Text.Ptr;
|
s32 len = ( (sptr)prevtok.Text.Ptr + prevtok.Text.Len ) - (sptr)start.Text.Ptr;
|
||||||
|
|
||||||
if ( len > 0 )
|
if ( len > 0 ) {
|
||||||
{
|
|
||||||
Str str = { start.Text.Ptr, len };
|
Str str = { start.Text.Ptr, len };
|
||||||
body_append( result, cast(Code, def_execution( str )) );
|
body_append( result, cast(Code, def_execution( str )) );
|
||||||
}
|
}
|
||||||
@@ -1679,6 +1740,294 @@ Code parse_function_body(Context* ctx)
|
|||||||
return cast(Code, result);
|
return cast(Code, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal
|
||||||
|
s32 parser_recovery_scope_close_id(ParseContext const* parser, s32 member_start_id, b32* nested_body, b32* has_scope_close)
|
||||||
|
{
|
||||||
|
nested_body[0] = false;
|
||||||
|
has_scope_close[0] = false;
|
||||||
|
ParseStackNode* scope = parser->scope;
|
||||||
|
while ( scope != nullptr )
|
||||||
|
{
|
||||||
|
b32 scope_has_code = scope->code_rel != nullptr;
|
||||||
|
if (scope_has_code)
|
||||||
|
{
|
||||||
|
CodeType type = scope->code_rel->Type;
|
||||||
|
|
||||||
|
b32 is_nested_scope_body = false;
|
||||||
|
is_nested_scope_body |= type == CT_Namespace_Body;
|
||||||
|
is_nested_scope_body |= type == CT_Class_Body;
|
||||||
|
is_nested_scope_body |= type == CT_Struct_Body;
|
||||||
|
|
||||||
|
// Function-body frames have their own brace owner; inspect the enclosing body frame.
|
||||||
|
if ( type == CT_Function_Body ) { scope = scope->prev; continue; }
|
||||||
|
|
||||||
|
b32 nothing_to_recover = type == CT_Global_Body || is_nested_scope_body == false;
|
||||||
|
// Global recovery uses the full token slice. Other unsupported scope types have no nested boundary.
|
||||||
|
if (nothing_to_recover) return parser->tokens.num; // TODO(Ed): Drain to single return.
|
||||||
|
|
||||||
|
// Nested recovery needs the active body's closing brace as a hard delimiter boundary.
|
||||||
|
nested_body[0] = true;
|
||||||
|
|
||||||
|
s32 scope_start_id = parser->tokens.num;
|
||||||
|
b32 scope_has_start = scope->start != nullptr;
|
||||||
|
if (scope_has_start) scope_start_id = scast(s32, scope->start - parser->tokens.ptr);
|
||||||
|
|
||||||
|
// Scope start may point at formatting before the body's opening brace.
|
||||||
|
s32 body_open_id = scope_start_id;
|
||||||
|
while ( body_open_id < parser->tokens.num ) {
|
||||||
|
b32 token_opens_body = parser->tokens.ptr[body_open_id].Type == Tok_BraceCurly_Open;
|
||||||
|
if (token_opens_body == true) break;
|
||||||
|
++ body_open_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
b32 found_body_open = body_open_id < parser->tokens.num;
|
||||||
|
if (found_body_open == false) return parser->tokens.num;
|
||||||
|
|
||||||
|
// A depth-zero close belongs to this body; nested closes only reduce depth.
|
||||||
|
s32 body_depth = 0;
|
||||||
|
for (s32 idx = body_open_id; idx < parser->tokens.num; ++ idx)
|
||||||
|
{
|
||||||
|
TokType token_type = parser->tokens.ptr[idx].Type;
|
||||||
|
if (token_type == Tok_BraceCurly_Open)
|
||||||
|
++ body_depth;
|
||||||
|
else if (token_type == Tok_BraceCurly_Close)
|
||||||
|
{
|
||||||
|
if (body_depth > 0) // inside nested brace
|
||||||
|
{
|
||||||
|
-- body_depth;
|
||||||
|
if (body_depth == 0) { // found owner close
|
||||||
|
has_scope_close[0] = true;
|
||||||
|
// TODO(Ed): Drain to single return.
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s32 fallback_close_id = parser->tokens.num;
|
||||||
|
if (type == CT_Class_Body || type == CT_Struct_Body)
|
||||||
|
{
|
||||||
|
// A malformed member opener can keep the brace-depth scan from reaching the owner close.
|
||||||
|
// Direct typed entries scan to their last candidate; nested bodies stop at the first candidate.
|
||||||
|
b32 has_parent_body = false;
|
||||||
|
for (ParseStackNode* parent = scope->prev; parent != nullptr; parent = parent->prev)
|
||||||
|
{
|
||||||
|
b32 parent_has_code = parent->code_rel != nullptr;
|
||||||
|
if (parent_has_code == false) continue;
|
||||||
|
|
||||||
|
b32 parent_is_function_body = parent->code_rel->Type == CT_Function_Body;
|
||||||
|
if (parent_is_function_body) continue;
|
||||||
|
|
||||||
|
CodeType parent_type = parent->code_rel->Type;
|
||||||
|
b32 parent_owns_body = false;
|
||||||
|
parent_owns_body |= parent_type == CT_Global_Body;
|
||||||
|
parent_owns_body |= parent_type == CT_Namespace_Body;
|
||||||
|
parent_owns_body |= parent_type == CT_Class_Body;
|
||||||
|
parent_owns_body |= parent_type == CT_Struct_Body;
|
||||||
|
has_parent_body = parent_owns_body;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (s32 idx = member_start_id; idx < parser->tokens.num; ++ idx)
|
||||||
|
{
|
||||||
|
if (parser->tokens.ptr[idx].Type != Tok_BraceCurly_Close) continue;
|
||||||
|
|
||||||
|
s32 next_id = idx + 1;
|
||||||
|
while (next_id < parser->tokens.num) {
|
||||||
|
TokType next_type = parser->tokens.ptr[next_id].Type;
|
||||||
|
b32 next_is_formatting = next_type == Tok_NewLine || next_type == Tok_Comment;
|
||||||
|
if (next_is_formatting == false) break;
|
||||||
|
++ next_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
b32 next_ends_statement = false;
|
||||||
|
b32 close_ends_declaration = false;
|
||||||
|
b32 next_in_slice = next_id < parser->tokens.num;
|
||||||
|
if (next_in_slice) {
|
||||||
|
next_ends_statement = parser->tokens.ptr[next_id].Type == Tok_Statement_End;
|
||||||
|
close_ends_declaration = next_ends_statement;
|
||||||
|
}
|
||||||
|
if (close_ends_declaration) {
|
||||||
|
fallback_close_id = idx;
|
||||||
|
if (has_parent_body) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// A namespace close follows a member terminator, unlike a nested type close followed by `;`.
|
||||||
|
for (s32 idx = member_start_id; idx < parser->tokens.num; ++ idx)
|
||||||
|
{
|
||||||
|
if (parser->tokens.ptr[idx].Type != Tok_BraceCurly_Close) continue;
|
||||||
|
|
||||||
|
s32 prev_id = idx - 1;
|
||||||
|
while (prev_id >= body_open_id) {
|
||||||
|
TokType prev_type = parser->tokens.ptr[prev_id].Type;
|
||||||
|
b32 prev_is_formatting = prev_type == Tok_NewLine || prev_type == Tok_Comment;
|
||||||
|
if ( prev_is_formatting == false ) break;
|
||||||
|
-- prev_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
s32 next_id = idx + 1;
|
||||||
|
while (next_id < parser->tokens.num) {
|
||||||
|
TokType next_type = parser->tokens.ptr[next_id].Type;
|
||||||
|
b32 next_is_formatting = next_type == Tok_NewLine || next_type == Tok_Comment;
|
||||||
|
if ( next_is_formatting == false ) break;
|
||||||
|
++ next_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
b32 prev_in_body = prev_id >= body_open_id;
|
||||||
|
b32 prev_ends_member = false;
|
||||||
|
if (prev_in_body) prev_ends_member = parser->tokens.ptr[prev_id].Type == Tok_Statement_End;
|
||||||
|
|
||||||
|
b32 next_ends_declaration = false;
|
||||||
|
b32 next_past_slice = next_id >= parser->tokens.num;
|
||||||
|
if (next_past_slice == false) next_ends_declaration = parser->tokens.ptr[next_id].Type == Tok_Statement_End;
|
||||||
|
|
||||||
|
b32 member_ended_before_close = false;
|
||||||
|
b32 close_starts_next_declaration = false;
|
||||||
|
b32 namespace_owner_close = false;
|
||||||
|
if (prev_in_body && prev_ends_member) member_ended_before_close = true;
|
||||||
|
if (next_past_slice == false && next_ends_declaration) close_starts_next_declaration = true;
|
||||||
|
if (member_ended_before_close && close_starts_next_declaration == false) namespace_owner_close = true;
|
||||||
|
if (namespace_owner_close) {
|
||||||
|
fallback_close_id = idx;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fallback_close_id < parser->tokens.num) { // found fallback close
|
||||||
|
has_scope_close[0] = true;
|
||||||
|
return fallback_close_id;
|
||||||
|
}
|
||||||
|
return parser->tokens.num;
|
||||||
|
}
|
||||||
|
scope = scope->prev;
|
||||||
|
}
|
||||||
|
return parser->tokens.num;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal
|
||||||
|
b32 parser_recovery_delimiter_is_balanced(ParseContext const* parser
|
||||||
|
, s32 start_id
|
||||||
|
, TokType open_type
|
||||||
|
, TokType close_type
|
||||||
|
, s32 scope_close_id
|
||||||
|
, b32 nested_body
|
||||||
|
, b32 has_scope_close
|
||||||
|
){
|
||||||
|
// Inner delimiters shield semicolons only when their close precedes the owning body close.
|
||||||
|
if ( open_type == Tok_BraceCurly_Open && nested_body && has_scope_close == false ) return false;
|
||||||
|
s32 delimiter_depth = 0;
|
||||||
|
s32 curly_depth = 0;
|
||||||
|
for ( s32 idx = start_id; idx < scope_close_id; ++ idx )
|
||||||
|
{
|
||||||
|
TokType type = parser->tokens.ptr[idx].Type;
|
||||||
|
if ( type == Tok_BraceCurly_Open )
|
||||||
|
++ curly_depth;
|
||||||
|
else if ( type == Tok_BraceCurly_Close )
|
||||||
|
{
|
||||||
|
if ( curly_depth == 0 ) return false;
|
||||||
|
-- curly_depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( type == open_type )
|
||||||
|
++ delimiter_depth;
|
||||||
|
else if ( type == close_type && delimiter_depth > 0 )
|
||||||
|
{
|
||||||
|
-- delimiter_depth;
|
||||||
|
if ( delimiter_depth == 0 ) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal
|
||||||
|
void parser_recover_body_member(Context* ctx, CodeBody body, Token member_start_token, s32 member_start_id, b32 allow_comma)
|
||||||
|
{
|
||||||
|
// Keep the original member start for the untyped source span.
|
||||||
|
Token recovery_end_token = member_start_token;
|
||||||
|
b32 has_recovery_tokens = false;
|
||||||
|
s32 paren_depth = 0;
|
||||||
|
s32 square_depth = 0;
|
||||||
|
s32 curly_depth = 0;
|
||||||
|
b32 nested_body = false;
|
||||||
|
b32 has_scope_close = false;
|
||||||
|
// Bound delimiter matches before scanning the rejected member.
|
||||||
|
s32 scope_close_id = parser_recovery_scope_close_id(& ctx->parser, member_start_id, &nested_body, &has_scope_close);
|
||||||
|
while ( left )
|
||||||
|
{
|
||||||
|
Token token = currtok_noskip;
|
||||||
|
// Leave the active body's close for its owner.
|
||||||
|
b32 is_scope_close = token.Type == Tok_BraceCurly_Close && curly_depth == 0;
|
||||||
|
if (is_scope_close) break;
|
||||||
|
|
||||||
|
b32 at_member_start = ctx->parser.token_id == member_start_id;
|
||||||
|
b32 at_delimiter_depth_zero = paren_depth == 0 && square_depth == 0 && curly_depth == 0;
|
||||||
|
b32 sync_at_comma = allow_comma && at_member_start && at_delimiter_depth_zero && token.Type == Tok_Comma;
|
||||||
|
b32 sync_at_statement_end = token.Type == Tok_Statement_End && at_delimiter_depth_zero;
|
||||||
|
b32 sync_at_member_boundary = sync_at_comma || sync_at_statement_end;
|
||||||
|
// Semicolons sync at depth zero; only global recovery accepts a leading comma.
|
||||||
|
if (sync_at_member_boundary)
|
||||||
|
{
|
||||||
|
TokType sync_type = Tok_Statement_End;
|
||||||
|
if (sync_at_comma) sync_type = Tok_Comma;
|
||||||
|
if (eat( sync_type )) {
|
||||||
|
recovery_end_token = token;
|
||||||
|
has_recovery_tokens = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add delimiter depth only when its matching close precedes scope_close_id.
|
||||||
|
switch ( token.Type ) { default: break;
|
||||||
|
case Tok_Paren_Open: {
|
||||||
|
b32 res = parser_recovery_delimiter_is_balanced(& ctx->parser, ctx->parser.token_id
|
||||||
|
, Tok_Paren_Open, Tok_Paren_Close
|
||||||
|
, scope_close_id, nested_body, has_scope_close);
|
||||||
|
if (res) ++ paren_depth;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Tok_Paren_Close:
|
||||||
|
if ( paren_depth > 0 ) -- paren_depth;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Tok_BraceSquare_Open: {
|
||||||
|
b32 res = parser_recovery_delimiter_is_balanced(& ctx->parser, ctx->parser.token_id
|
||||||
|
, Tok_BraceSquare_Open, Tok_BraceSquare_Close
|
||||||
|
, scope_close_id, nested_body, has_scope_close);
|
||||||
|
if (res) ++ square_depth;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Tok_BraceSquare_Close:
|
||||||
|
if ( square_depth > 0 ) -- square_depth;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Tok_BraceCurly_Open: {
|
||||||
|
b32 res = parser_recovery_delimiter_is_balanced(& ctx->parser, ctx->parser.token_id
|
||||||
|
, Tok_BraceCurly_Open, Tok_BraceCurly_Close
|
||||||
|
, scope_close_id, nested_body, has_scope_close);
|
||||||
|
if (res) ++ curly_depth;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Tok_BraceCurly_Close:
|
||||||
|
if ( curly_depth > 0 ) -- curly_depth;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eat( token.Type )) {
|
||||||
|
recovery_end_token = token;
|
||||||
|
has_recovery_tokens = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retain the failed source through its synchronization token as untyped code.
|
||||||
|
if (has_recovery_tokens) body_append(body, untyped_str(token_range_to_str(member_start_token, recovery_end_token)));
|
||||||
|
}
|
||||||
|
|
||||||
internal neverinline
|
internal neverinline
|
||||||
CodeBody parse_global_nspace(Context* ctx, CodeType which)
|
CodeBody parse_global_nspace(Context* ctx, CodeType which)
|
||||||
{
|
{
|
||||||
@@ -1695,9 +2044,13 @@ CodeBody parse_global_nspace(Context* ctx, CodeType which)
|
|||||||
CodeBody
|
CodeBody
|
||||||
result = (CodeBody) make_code();
|
result = (CodeBody) make_code();
|
||||||
result->Type = which;
|
result->Type = which;
|
||||||
|
scope.code_rel = cast(Code, result);
|
||||||
|
|
||||||
while ( left && currtok_noskip.Type != Tok_BraceCurly_Close )
|
while ( left && currtok_noskip.Type != Tok_BraceCurly_Close )
|
||||||
{
|
{
|
||||||
|
ParseMessage* messages_before_member = ctx->parser.messages;
|
||||||
|
s32 member_start_id = ctx->parser.token_id;
|
||||||
|
Token member_start_token = currtok_noskip;
|
||||||
Code member = Code_Invalid;
|
Code member = Code_Invalid;
|
||||||
CodeAttributes attributes = { nullptr };
|
CodeAttributes attributes = { nullptr };
|
||||||
CodeSpecifiers specifiers = { nullptr };
|
CodeSpecifiers specifiers = { nullptr };
|
||||||
@@ -1716,9 +2069,13 @@ CodeBody parse_global_nspace(Context* ctx, CodeType which)
|
|||||||
case Tok_Comma:
|
case Tok_Comma:
|
||||||
{
|
{
|
||||||
parser_record_failure(ctx, txt("Dangling comma"));
|
parser_record_failure(ctx, txt("Dangling comma"));
|
||||||
|
if ( which != CT_Global_Body )
|
||||||
|
{
|
||||||
parser_pop( & ctx->parser);
|
parser_pop( & ctx->parser);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
member = Code_Invalid;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Tok_Statement_End:
|
case Tok_Statement_End:
|
||||||
{
|
{
|
||||||
@@ -1849,6 +2206,12 @@ CodeBody parse_global_nspace(Context* ctx, CodeType which)
|
|||||||
|
|
||||||
case Tok_Module_Import: {
|
case Tok_Module_Import: {
|
||||||
// import ...
|
// import ...
|
||||||
|
if ( which == CT_Global_Body )
|
||||||
|
{
|
||||||
|
parser_record_failure(ctx, txt("Module import parsing is not implemented"));
|
||||||
|
member = Code_Invalid;
|
||||||
|
break;
|
||||||
|
}
|
||||||
log_failure( "gen::%s: This function is not implemented" );
|
log_failure( "gen::%s: This function is not implemented" );
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
}
|
}
|
||||||
@@ -1858,6 +2221,12 @@ CodeBody parse_global_nspace(Context* ctx, CodeType which)
|
|||||||
{
|
{
|
||||||
if ( ! tok_is_attribute(currtok))
|
if ( ! tok_is_attribute(currtok))
|
||||||
{
|
{
|
||||||
|
if ( which == CT_Global_Body )
|
||||||
|
{
|
||||||
|
parser_record_failure(ctx, txt("Unbounded macro expression in global body"));
|
||||||
|
member = Code_Invalid;
|
||||||
|
break;
|
||||||
|
}
|
||||||
log_failure("Unbounded macro expression residing in class/struct body\n%SB", parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp));
|
log_failure("Unbounded macro expression residing in class/struct body\n%SB", parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp));
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
}
|
}
|
||||||
@@ -1878,6 +2247,7 @@ CodeBody parse_global_nspace(Context* ctx, CodeType which)
|
|||||||
{
|
{
|
||||||
Specifier specs_found[16] = { Spec_NumSpecifiers };
|
Specifier specs_found[16] = { Spec_NumSpecifiers };
|
||||||
s32 NumSpecifiers = 0;
|
s32 NumSpecifiers = 0;
|
||||||
|
b32 invalid_global_specifier = false;
|
||||||
|
|
||||||
while ( left && tok_is_specifier(currtok) )
|
while ( left && tok_is_specifier(currtok) )
|
||||||
{
|
{
|
||||||
@@ -1900,11 +2270,22 @@ CodeBody parse_global_nspace(Context* ctx, CodeType which)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
Str spec_str = spec_to_str(spec);
|
Str spec_str = spec_to_str(spec);
|
||||||
|
if ( which == CT_Global_Body )
|
||||||
|
{
|
||||||
|
StrBuilder message = strbuilder_fmt_buf(ctx->Allocator_Temp, "Invalid specifier %S for variable\n%SB"
|
||||||
|
, spec_str
|
||||||
|
, parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp)
|
||||||
|
);
|
||||||
|
parser_record_failure(ctx, strbuilder_to_str(message));
|
||||||
|
invalid_global_specifier = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
log_failure( "Invalid specifier %S for variable\n%S", spec_str, strbuilder_to_str( parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp)) );
|
log_failure( "Invalid specifier %S for variable\n%S", spec_str, strbuilder_to_str( parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp)) );
|
||||||
parser_pop(& ctx->parser);
|
parser_pop(& ctx->parser);
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
}
|
}
|
||||||
|
if ( invalid_global_specifier )
|
||||||
|
break;
|
||||||
|
|
||||||
if (ignore_spec)
|
if (ignore_spec)
|
||||||
break;
|
break;
|
||||||
@@ -1913,6 +2294,11 @@ CodeBody parse_global_nspace(Context* ctx, CodeType which)
|
|||||||
NumSpecifiers++;
|
NumSpecifiers++;
|
||||||
eat( currtok.Type );
|
eat( currtok.Type );
|
||||||
}
|
}
|
||||||
|
if ( invalid_global_specifier )
|
||||||
|
{
|
||||||
|
member = Code_Invalid;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if ( NumSpecifiers )
|
if ( NumSpecifiers )
|
||||||
{
|
{
|
||||||
@@ -1979,8 +2365,32 @@ CodeBody parse_global_nspace(Context* ctx, CodeType which)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b32 member_is_nested_scope = member != Code_Invalid && (member->Type == CT_Class || member->Type == CT_Struct || member->Type == CT_Namespace);
|
||||||
|
b32 member_failed = ctx->parser.token_mismatch || (ctx->parser.messages != messages_before_member && ! member_is_nested_scope);
|
||||||
|
b32 can_recover_member = which == CT_Global_Body || which == CT_Namespace_Body;
|
||||||
|
if (can_recover_member && member_failed) {
|
||||||
|
if (ctx->parser.messages != messages_before_member) ctx->parser.messages->Next = messages_before_member;
|
||||||
|
ctx->parser.token_id = member_start_id;
|
||||||
|
ctx->parser.token_mismatch = false;
|
||||||
|
member = Code_Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
if ( member == Code_Invalid )
|
if ( member == Code_Invalid )
|
||||||
{
|
{
|
||||||
|
if ( which == CT_Global_Body || (which == CT_Namespace_Body && member_failed) )
|
||||||
|
{
|
||||||
|
if ( ctx->parser.messages == messages_before_member )
|
||||||
|
{
|
||||||
|
StrBuilder message = strbuilder_fmt_buf(ctx->Allocator_Temp, "Failed to parse member\nToken: %SB\nContext:\n%SB"
|
||||||
|
, tok_to_strbuilder(ctx->Allocator_Temp, currtok_noskip)
|
||||||
|
, parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp)
|
||||||
|
);
|
||||||
|
parser_record_failure(ctx, strbuilder_to_str(message));
|
||||||
|
}
|
||||||
|
parser_recover_body_member(ctx, result, member_start_token, member_start_id, which == CT_Global_Body);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
log_failure( "Failed to parse member\nToken: %SB\nContext:\n%SB", tok_to_strbuilder(ctx->Allocator_Temp, currtok_noskip), parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp) );
|
log_failure( "Failed to parse member\nToken: %SB\nContext:\n%SB", tok_to_strbuilder(ctx->Allocator_Temp, currtok_noskip), parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp) );
|
||||||
parser_pop(& ctx->parser);
|
parser_pop(& ctx->parser);
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|||||||
@@ -162,6 +162,8 @@ struct ParseContext
|
|||||||
// TokArray Tokens;
|
// TokArray Tokens;
|
||||||
TokenSlice tokens;
|
TokenSlice tokens;
|
||||||
s32 token_id;
|
s32 token_id;
|
||||||
|
LexerMessage* lexed_messages;
|
||||||
|
b32 token_mismatch;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum MacroType : u16
|
enum MacroType : u16
|
||||||
|
|||||||
@@ -57,6 +57,11 @@
|
|||||||
#define bitfield_is_set( Type, Field, Mask ) ( (scast(Type, Mask) & scast(Type, Field)) == scast(Type, Mask) )
|
#define bitfield_is_set( Type, Field, Mask ) ( (scast(Type, Mask) & scast(Type, Field)) == scast(Type, Mask) )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef GEN_ASSERT_SLICE
|
||||||
|
#define GEN_ASSERT_SLICE( slice ) \
|
||||||
|
GEN_ASSERT( ((slice).Len >= 0) & (((slice).Len == 0) | ((slice).Ptr != nullptr)) )
|
||||||
|
#endif
|
||||||
|
|
||||||
// Mainly intended for forcing the base library to utilize only C-valid constructs or type coercion
|
// Mainly intended for forcing the base library to utilize only C-valid constructs or type coercion
|
||||||
#ifndef GEN_C_LIKE_CPP
|
#ifndef GEN_C_LIKE_CPP
|
||||||
#define GEN_C_LIKE_CPP 0
|
#define GEN_C_LIKE_CPP 0
|
||||||
@@ -350,4 +355,51 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef each_iter
|
||||||
|
#define each_iter( type, iter, end ) \
|
||||||
|
for ( type iter = 0; iter < (end); ++ iter )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef index_iter
|
||||||
|
#define index_iter( type, iter, begin, op, end ) \
|
||||||
|
for ( type iter = (begin); iter op (end); ( (begin) < (end) ? ++ iter : -- iter ) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef range_iter
|
||||||
|
#define range_iter( iter, op, range ) \
|
||||||
|
for ( typeof( (range).p0 ) iter = (range).p0; iter op (range).p1; ( (range).p0 < (range).p1 ? ++ iter : -- iter ) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef defer
|
||||||
|
#define defer( expr ) \
|
||||||
|
for ( u32 once = 0; once != 1; ++ once, (expr) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef defer_rewind
|
||||||
|
#define defer_rewind( cursor ) \
|
||||||
|
for ( struct { typeof( cursor ) sp; u32 once; } defer_state = { (cursor), 0 }; \
|
||||||
|
defer_state.once != 1; \
|
||||||
|
++ defer_state.once, (cursor) = defer_state.sp )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef defer_info
|
||||||
|
#define defer_info( type, expr, ... ) \
|
||||||
|
for ( type info = { __VA_ARGS__ }; info.once != 1; ++ info.once, (expr) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef scope
|
||||||
|
#define scope( begin, end ) \
|
||||||
|
for ( u32 once = ( (begin), 0 ); once != 1; ++ once, (end) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef scope_info
|
||||||
|
#define scope_info( type, begin, end ) \
|
||||||
|
for ( type info = (begin); info.once != 1; ++ info.once, (end) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef do_while
|
||||||
|
#define do_while( cond ) \
|
||||||
|
for ( u32 once = 0; once != 1 || (cond); once = 1 )
|
||||||
|
#endif
|
||||||
|
|
||||||
#pragma endregion Macros
|
#pragma endregion Macros
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
#ifdef INTELLISENSE_DIRECTIVES
|
||||||
|
#pragma once
|
||||||
|
#include "debug.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#pragma region SIMD
|
||||||
|
|
||||||
|
// Lane names use bit widths: sixteen unsigned 8-bit lanes or four unsigned 32-bit lanes.
|
||||||
|
// Vector operations are available on Windows x64.
|
||||||
|
#if defined(GEN_SYSTEM_WINDOWS) && (defined(_M_X64) || defined(__x86_64__))
|
||||||
|
typedef __m128i u8x16;
|
||||||
|
typedef __m128i u32x4;
|
||||||
|
|
||||||
|
// Unaligned loads require 16 or 8 readable bytes respectively. load8 zeros lanes 8 through 15.
|
||||||
|
internal forceinline u8x16 u8x16_load (void const* address) { return _mm_loadu_si128(rcast(__m128i const*, address)); }
|
||||||
|
internal forceinline u8x16 u8x16_load8(void const* address) { return _mm_loadl_epi64(rcast(__m128i const*, address)); }
|
||||||
|
|
||||||
|
internal forceinline u8x16 u8x16_splat(u8 value) { return _mm_set1_epi8(scast(char, value)); }
|
||||||
|
|
||||||
|
internal forceinline u8x16 u8x16_equal(u8x16 lhs, u8x16 rhs) { return _mm_cmpeq_epi8(lhs, rhs); }
|
||||||
|
|
||||||
|
// Extract each lane's high bit. Bit 0 represents lane 0 at the lowest address.
|
||||||
|
internal forceinline u16 u8x16_mask(u8x16 value) { return scast(u16, _mm_movemask_epi8(value)); }
|
||||||
|
|
||||||
|
// Reads 16 bytes without requiring alignment.
|
||||||
|
internal forceinline u32x4 u32x4_load(void const* address) { return _mm_loadu_si128(rcast(__m128i const*, address)); }
|
||||||
|
|
||||||
|
internal forceinline u32x4 u32x4_splat(u32 value) { return _mm_set1_epi32(scast(s32, value)); }
|
||||||
|
|
||||||
|
internal forceinline u32x4 u32x4_equal(u32x4 lhs, u32x4 rhs) { return _mm_cmpeq_epi32(lhs, rhs); }
|
||||||
|
|
||||||
|
// Extract each lane's high bit into bits 0 through 3. Higher result bits are zero.
|
||||||
|
internal forceinline u8 u32x4_mask(u32x4 value) { return scast(u8, _mm_movemask_ps(_mm_castsi128_ps(value))); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Requires a nonzero mask. Returns the lowest set-bit index, from 0 through 31.
|
||||||
|
s32 u32_mask_first_set(u32 mask);
|
||||||
|
|
||||||
|
#if defined(GEN_SYSTEM_WINDOWS)
|
||||||
|
internal forceinline
|
||||||
|
s32 u32_mask_first_set(u32 mask) {
|
||||||
|
GEN_ASSERT(mask != 0);
|
||||||
|
unsigned long bit_index = 0;
|
||||||
|
_BitScanForward(& bit_index, scast(unsigned long, mask));
|
||||||
|
return scast(s32, bit_index);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ! defined(GEN_SYSTEM_WINDOWS)
|
||||||
|
internal forceinline
|
||||||
|
s32 u32_mask_first_set(u32 mask) {
|
||||||
|
GEN_ASSERT(mask != 0);
|
||||||
|
s32 bit = 0;
|
||||||
|
u32 bits = mask;
|
||||||
|
while ((bits & 1u) == 0u) {
|
||||||
|
bits >>= 1;
|
||||||
|
bit += 1;
|
||||||
|
}
|
||||||
|
return bit;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#pragma endregion SIMD
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#ifdef INTELLISENSE_DIRECTIVES
|
#ifdef INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# pragma once
|
||||||
|
# include "simd.hpp"
|
||||||
# include "hashing.cpp"
|
# include "hashing.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -174,4 +175,153 @@ StrBuilder strbuilder_visualize_whitespace(StrBuilder const str)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(GEN_SYSTEM_WINDOWS) && (defined(_M_X64) || defined(__x86_64__))
|
||||||
|
internal
|
||||||
|
ssize strbuilder_find_template_byte(char const* text, ssize length, char needle)
|
||||||
|
{
|
||||||
|
ssize idx = 0;
|
||||||
|
for (; (length - idx) >= 16; )
|
||||||
|
{
|
||||||
|
char const* at = text + idx;
|
||||||
|
u8x16 chunk = u8x16_load(at);
|
||||||
|
u8x16 splat = u8x16_splat(scast(u8, needle));
|
||||||
|
u16 mask = u8x16_mask(u8x16_equal(chunk, splat));
|
||||||
|
if (mask != 0) {
|
||||||
|
s32 bit_index = u32_mask_first_set(mask);
|
||||||
|
return idx + scast(ssize, bit_index);
|
||||||
|
}
|
||||||
|
idx += 16;
|
||||||
|
}
|
||||||
|
for (; (length - idx) >= 8; )
|
||||||
|
{
|
||||||
|
char const* at = text + idx;
|
||||||
|
u8x16 chunk = u8x16_load8(at);
|
||||||
|
u8x16 splat = u8x16_splat(scast(u8, needle));
|
||||||
|
u16 mask = u8x16_mask(u8x16_equal(chunk, splat)) & 0xFF;
|
||||||
|
if (mask != 0) {
|
||||||
|
s32 bit_index = u32_mask_first_set(mask);
|
||||||
|
return idx + scast(ssize, bit_index);
|
||||||
|
}
|
||||||
|
idx += 8;
|
||||||
|
}
|
||||||
|
for (; idx < length; ++ idx) {
|
||||||
|
if (text[idx] == needle) return idx;
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
internal
|
||||||
|
ssize strbuilder_find_template_byte(char const* text, ssize length, char needle) {
|
||||||
|
for (ssize idx = 0; idx < length; ++ idx)
|
||||||
|
{
|
||||||
|
if (text[idx] == needle)
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(GEN_SYSTEM_WINDOWS) && (defined(_M_X64) || defined(__x86_64__))
|
||||||
|
internal
|
||||||
|
StrTemplateSlot* strbuilder_find_template_slot(Slice_StrTemplateSlot slots, Str key)
|
||||||
|
{
|
||||||
|
u32 key_hash = crc32(key.Ptr, key.Len);
|
||||||
|
ssize idx = 0;
|
||||||
|
for (; (slots.Len - idx) >= 4; idx += 4)
|
||||||
|
{
|
||||||
|
u32 packed[4];
|
||||||
|
packed[0] = crc32(slots.Ptr[idx + 0].Key.Ptr, slots.Ptr[idx + 0].Key.Len);
|
||||||
|
packed[1] = crc32(slots.Ptr[idx + 1].Key.Ptr, slots.Ptr[idx + 1].Key.Len);
|
||||||
|
packed[2] = crc32(slots.Ptr[idx + 2].Key.Ptr, slots.Ptr[idx + 2].Key.Len);
|
||||||
|
packed[3] = crc32(slots.Ptr[idx + 3].Key.Ptr, slots.Ptr[idx + 3].Key.Len);
|
||||||
|
|
||||||
|
u32x4 packed_vec = u32x4_load(packed);
|
||||||
|
u32x4 want_vec = u32x4_splat(key_hash);
|
||||||
|
u8 mask = u32x4_mask(u32x4_equal(packed_vec, want_vec));
|
||||||
|
|
||||||
|
for (s32 lane = 0; lane < 4; ++ lane)
|
||||||
|
{
|
||||||
|
if ((mask & (1u << lane)) != 0) {
|
||||||
|
StrTemplateSlot* slot = & slots.Ptr[idx + lane];
|
||||||
|
if (str_are_equal(slot[0].Key, key)) return slot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (; idx < slots.Len; ++ idx)
|
||||||
|
{
|
||||||
|
StrTemplateSlot* slot = & slots.Ptr[idx];
|
||||||
|
u32 slot_hash = crc32(slot[0].Key.Ptr, slot[0].Key.Len);
|
||||||
|
if (slot_hash == key_hash) {
|
||||||
|
if (str_are_equal(slot[0].Key, key)) return slot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
internal
|
||||||
|
StrTemplateSlot* strbuilder_find_template_slot(Slice_StrTemplateSlot slots, Str key) {
|
||||||
|
u32 key_hash = crc32(key.Ptr, key.Len);
|
||||||
|
for (ssize idx = 0; idx < slots.Len; ++ idx)
|
||||||
|
{
|
||||||
|
StrTemplateSlot* slot = & slots.Ptr[idx];
|
||||||
|
u32 slot_hash = crc32(slot[0].Key.Ptr, slot[0].Key.Len);
|
||||||
|
if (slot_hash == key_hash && str_are_equal(slot[0].Key, key))
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool strbuilder_append_template(StrBuilder* output, Slice_StrTemplateSlot slots, Str format)
|
||||||
|
{
|
||||||
|
GEN_ASSERT(output != nullptr && output[0] != nullptr);
|
||||||
|
StrBuilderHeader* header = strbuilder_get_header(output[0]);
|
||||||
|
GEN_ASSERT((header[0].Length >= 0) & (header[0].Capacity >= header[0].Length));
|
||||||
|
GEN_ASSERT_SLICE(format);
|
||||||
|
GEN_ASSERT_SLICE(slots);
|
||||||
|
for (ssize slot_idx = 0; slot_idx < slots.Len; ++ slot_idx) {
|
||||||
|
GEN_ASSERT_SLICE(slots.Ptr[slot_idx].Key);
|
||||||
|
GEN_ASSERT_SLICE(slots.Ptr[slot_idx].Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool result = false;
|
||||||
|
if (format.Len == 0) {
|
||||||
|
result = true;
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ssize cursor = 0; cursor < format.Len;)
|
||||||
|
{
|
||||||
|
if (format.Ptr[cursor] == '<')
|
||||||
|
{
|
||||||
|
ssize key_at = cursor + 1;
|
||||||
|
ssize key_max = format.Len - key_at;
|
||||||
|
ssize key_len = strbuilder_find_template_byte(format.Ptr + key_at, key_max, '>');
|
||||||
|
if (key_len == key_max) goto finish;
|
||||||
|
|
||||||
|
Str key = { format.Ptr + key_at, key_len };
|
||||||
|
StrTemplateSlot* slot = strbuilder_find_template_slot(slots, key);
|
||||||
|
if (slot == nullptr) goto finish;
|
||||||
|
|
||||||
|
if (slot[0].Value.Len > 0) {
|
||||||
|
bool appended = strbuilder_append_c_str_len(output, slot[0].Value.Ptr, slot[0].Value.Len);
|
||||||
|
if (appended == false) goto finish;
|
||||||
|
}
|
||||||
|
cursor = key_at + key_len + 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize literal_max = format.Len - cursor;
|
||||||
|
ssize literal_len = strbuilder_find_template_byte(format.Ptr + cursor, literal_max, '<');
|
||||||
|
if (literal_len > 0) {
|
||||||
|
bool appended = strbuilder_append_c_str_len(output, format.Ptr + cursor, literal_len);
|
||||||
|
if (appended == false) goto finish;
|
||||||
|
}
|
||||||
|
cursor += literal_len;
|
||||||
|
}
|
||||||
|
result = true;
|
||||||
|
finish:
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma endregion StrBuilder
|
#pragma endregion StrBuilder
|
||||||
@@ -113,6 +113,8 @@ Str to_str_from_c_str( char const* bad_str ) {
|
|||||||
// I kept it for simplicty of porting but its not necessary to keep it that way.
|
// I kept it for simplicty of porting but its not necessary to keep it that way.
|
||||||
#pragma region StrBuilder
|
#pragma region StrBuilder
|
||||||
struct StrBuilderHeader;
|
struct StrBuilderHeader;
|
||||||
|
struct StrTemplateSlot;
|
||||||
|
struct Slice_StrTemplateSlot;
|
||||||
|
|
||||||
#if GEN_COMPILER_C
|
#if GEN_COMPILER_C
|
||||||
typedef char* StrBuilder;
|
typedef char* StrBuilder;
|
||||||
@@ -126,6 +128,33 @@ GEN_API StrBuilder strbuilder_make_reserve (AllocatorInfo allocato
|
|||||||
GEN_API StrBuilder strbuilder_make_length (AllocatorInfo allocator, char const* str, ssize length);
|
GEN_API StrBuilder strbuilder_make_length (AllocatorInfo allocator, char const* str, ssize length);
|
||||||
GEN_API bool strbuilder_make_space_for (StrBuilder* str, char const* to_append, ssize add_len);
|
GEN_API bool strbuilder_make_space_for (StrBuilder* str, char const* to_append, ssize add_len);
|
||||||
GEN_API bool strbuilder_append_c_str_len(StrBuilder* str, char const* c_str_to_append, ssize length);
|
GEN_API bool strbuilder_append_c_str_len(StrBuilder* str, char const* c_str_to_append, ssize length);
|
||||||
|
|
||||||
|
struct StrTemplateSlot { Str Key; Str Value; };
|
||||||
|
struct Slice_StrTemplateSlot { StrTemplateSlot* Ptr; ssize Len; };
|
||||||
|
|
||||||
|
// format and slot slices must not alias output. output may reallocate.
|
||||||
|
GEN_API bool strbuilder_append_template(StrBuilder* output, Slice_StrTemplateSlot slots, Str format);
|
||||||
|
|
||||||
|
#ifndef strtmpl_slot
|
||||||
|
# if GEN_COMPILER_C
|
||||||
|
# define strtmpl_slot(key, value) (GEN_NS StrTemplateSlot){ txt(key), (value) }
|
||||||
|
# else
|
||||||
|
# define strtmpl_slot(key, value) GEN_NS StrTemplateSlot{ txt(key), (value) }
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef strtmpl_slots
|
||||||
|
# define strtmpl_slots( ... ) __VA_ARGS__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef strtmpl_append
|
||||||
|
#define strtmpl_append( output, result, entries, format ) do { \
|
||||||
|
GEN_NS StrTemplateSlot gencpp_tmpl_slot_array[] = { entries }; \
|
||||||
|
GEN_NS Slice_StrTemplateSlot gencpp_tmpl_slot_slice = { gencpp_tmpl_slot_array, count_of(gencpp_tmpl_slot_array) }; \
|
||||||
|
(result) = GEN_NS strbuilder_append_template((output), gencpp_tmpl_slot_slice, (format)); \
|
||||||
|
} while ( 0 )
|
||||||
|
#endif
|
||||||
|
|
||||||
GEN_API void strbuilder_trim (StrBuilder str, char const* cut_set);
|
GEN_API void strbuilder_trim (StrBuilder str, char const* cut_set);
|
||||||
GEN_API StrBuilder strbuilder_visualize_whitespace(StrBuilder const str);
|
GEN_API StrBuilder strbuilder_visualize_whitespace(StrBuilder const str);
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ GEN_NS_BEGIN
|
|||||||
#include "dependencies/printing.hpp"
|
#include "dependencies/printing.hpp"
|
||||||
#include "dependencies/containers.hpp"
|
#include "dependencies/containers.hpp"
|
||||||
#include "dependencies/hashing.hpp"
|
#include "dependencies/hashing.hpp"
|
||||||
|
#include "dependencies/simd.hpp"
|
||||||
#include "dependencies/strings.hpp"
|
#include "dependencies/strings.hpp"
|
||||||
#include "dependencies/filesystem.hpp"
|
#include "dependencies/filesystem.hpp"
|
||||||
#include "dependencies/timing.hpp"
|
#include "dependencies/timing.hpp"
|
||||||
|
|||||||
@@ -141,6 +141,7 @@
|
|||||||
#undef GEN_ASSERT
|
#undef GEN_ASSERT
|
||||||
#undef GEN_ASSERT_MSG
|
#undef GEN_ASSERT_MSG
|
||||||
#undef GEN_ASSERT_NOT_NULL
|
#undef GEN_ASSERT_NOT_NULL
|
||||||
|
#undef GEN_ASSERT_SLICE
|
||||||
#undef GEN_PANIC
|
#undef GEN_PANIC
|
||||||
#undef GEN_FATAL
|
#undef GEN_FATAL
|
||||||
|
|
||||||
@@ -165,6 +166,9 @@
|
|||||||
#undef get_hashtable_underlying_type
|
#undef get_hashtable_underlying_type
|
||||||
|
|
||||||
#undef txt
|
#undef txt
|
||||||
|
#undef strtmpl_slot
|
||||||
|
#undef strtmpl_slots
|
||||||
|
#undef strtmpl_append
|
||||||
|
|
||||||
#undef NOMINMAX
|
#undef NOMINMAX
|
||||||
#undef VC_EXTRALEAN
|
#undef VC_EXTRALEAN
|
||||||
|
|||||||
+146
-31
@@ -57,6 +57,68 @@ Code refactor_and_format( Code code ) {
|
|||||||
return code_refactor_and_format(code, scratch_file, path_refactor_script, path_format_style );
|
return code_refactor_and_format(code, scratch_file, path_refactor_script, path_format_style );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal Code rewrite_parse_wrapper_signature(Code source, Str function_name)
|
||||||
|
{
|
||||||
|
Str scanned = source->Content;
|
||||||
|
Str needle = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S(", function_name).to_str();
|
||||||
|
Str option_param = txt("Opts_parse opts");
|
||||||
|
ssize function_at = -1;
|
||||||
|
ssize option_at = -1;
|
||||||
|
ssize last_offset = scanned.Len - needle.Len;
|
||||||
|
for (ssize scan_offset = 0; scan_offset <= last_offset; ++ scan_offset) {
|
||||||
|
char const* scan_at = scanned.Ptr + scan_offset;
|
||||||
|
if (c_str_compare_len(scan_at, needle.Ptr, needle.Len) == 0) {
|
||||||
|
if (scan_offset > 0) {
|
||||||
|
ssize prev_at = scan_offset - 1;
|
||||||
|
if (scanned.Ptr[prev_at] == '_') continue;
|
||||||
|
}
|
||||||
|
function_at = scan_offset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (function_at < 0) GEN_FATAL("c_library: parser wrapper signature missing");
|
||||||
|
|
||||||
|
for (ssize params_end = function_at + needle.Len;
|
||||||
|
params_end < scanned.Len && scanned.Ptr[params_end] != ')';
|
||||||
|
++ params_end
|
||||||
|
) {
|
||||||
|
ssize option_fit_end = params_end + option_param.Len;
|
||||||
|
if (option_fit_end > scanned.Len) break;
|
||||||
|
char const* params_at = scanned.Ptr + params_end;
|
||||||
|
if (c_str_compare_len(params_at, option_param.Ptr, option_param.Len) == 0) {
|
||||||
|
option_at = params_end;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (option_at < 0) GEN_FATAL("c_library: parser wrapper options parameter missing for %S", function_name);
|
||||||
|
|
||||||
|
Str new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S_opts", function_name).to_str();
|
||||||
|
Str pointer_param = txt("Opts_parse* opts");
|
||||||
|
|
||||||
|
ssize name_end = function_at + function_name.Len;
|
||||||
|
char const* before_opts_ptr = scanned.Ptr + name_end;
|
||||||
|
ssize before_opts_len = option_at - name_end;
|
||||||
|
Str before_name = { scanned.Ptr, function_at };
|
||||||
|
Str before_opts = { before_opts_ptr, before_opts_len };
|
||||||
|
|
||||||
|
ssize after_opts_at = option_at + option_param.Len;
|
||||||
|
char const* after_opts_ptr = scanned.Ptr + after_opts_at;
|
||||||
|
ssize after_opts_len = scanned.Len - after_opts_at;
|
||||||
|
Str after_opts = { after_opts_ptr, after_opts_len };
|
||||||
|
|
||||||
|
ssize opts_star_len = 1;
|
||||||
|
ssize rebuilt_cap = scanned.Len;
|
||||||
|
rebuilt_cap += new_name.Len;
|
||||||
|
rebuilt_cap += opts_star_len;
|
||||||
|
StrBuilder rebuilt = StrBuilder::make_reserve(_ctx->Allocator_Temp, rebuilt_cap);
|
||||||
|
strbuilder_append_str(& rebuilt, before_name);
|
||||||
|
strbuilder_append_str(& rebuilt, new_name);
|
||||||
|
strbuilder_append_str(& rebuilt, before_opts);
|
||||||
|
strbuilder_append_str(& rebuilt, pointer_param);
|
||||||
|
strbuilder_append_str(& rebuilt, after_opts);
|
||||||
|
return untyped_str(strbuilder_to_str(rebuilt));
|
||||||
|
}
|
||||||
|
|
||||||
constexpr bool helper_use_c_definition = true;
|
constexpr bool helper_use_c_definition = true;
|
||||||
|
|
||||||
int gen_main()
|
int gen_main()
|
||||||
@@ -79,6 +141,15 @@ int gen_main()
|
|||||||
(Macro { txt("do_once_defer"), MT_Expression, MF_Functional }),
|
(Macro { txt("do_once_defer"), MT_Expression, MF_Functional }),
|
||||||
(Macro { txt("do_once_start"), MT_Statement, MF_Null }),
|
(Macro { txt("do_once_start"), MT_Statement, MF_Null }),
|
||||||
(Macro { txt("do_once_end"), MT_Statement, MF_Null }),
|
(Macro { txt("do_once_end"), MT_Statement, MF_Null }),
|
||||||
|
(Macro { txt("each_iter"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||||
|
(Macro { txt("index_iter"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||||
|
(Macro { txt("range_iter"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||||
|
(Macro { txt("defer"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||||
|
(Macro { txt("defer_rewind"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||||
|
(Macro { txt("defer_info"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||||
|
(Macro { txt("scope"), MT_Statement, MF_Functional | MF_Expects_Body | MF_Allow_As_Identifier }),
|
||||||
|
(Macro { txt("scope_info"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||||
|
(Macro { txt("do_while"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||||
(Macro { txt("labeled_scope_start"), MT_Statement, MF_Null }),
|
(Macro { txt("labeled_scope_start"), MT_Statement, MF_Null }),
|
||||||
(Macro { txt("labeled_scope_end"), MT_Statement, MF_Null }),
|
(Macro { txt("labeled_scope_end"), MT_Statement, MF_Null }),
|
||||||
(Macro { txt("compiler_decorated_func_name"), MT_Expression, MF_Null }),
|
(Macro { txt("compiler_decorated_func_name"), MT_Expression, MF_Null }),
|
||||||
@@ -124,6 +195,9 @@ int gen_main()
|
|||||||
(Macro { txt("cast_to_str"), MT_Expression, MF_Functional }),
|
(Macro { txt("cast_to_str"), MT_Expression, MF_Functional }),
|
||||||
(Macro { txt("current"), MT_Expression, MF_Null }),
|
(Macro { txt("current"), MT_Expression, MF_Null }),
|
||||||
(Macro { txt("txt"), MT_Expression, MF_Functional }),
|
(Macro { txt("txt"), MT_Expression, MF_Functional }),
|
||||||
|
(Macro { txt("strtmpl_slot"), MT_Expression, MF_Functional }),
|
||||||
|
(Macro { txt("strtmpl_slots"), MT_Expression, MF_Functional }),
|
||||||
|
(Macro { txt("strtmpl_append"), MT_Statement, MF_Functional }),
|
||||||
(Macro { txt("GEN_FILE_OPEN_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
(Macro { txt("GEN_FILE_OPEN_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||||
(Macro { txt("GEN_FILE_READ_AT_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
(Macro { txt("GEN_FILE_READ_AT_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||||
(Macro { txt("GEN_FILE_WRITE_AT_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
(Macro { txt("GEN_FILE_WRITE_AT_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||||
@@ -197,6 +271,7 @@ int gen_main()
|
|||||||
Code header_debug = scan_file( path_base "dependencies/debug.hpp" );
|
Code header_debug = scan_file( path_base "dependencies/debug.hpp" );
|
||||||
Code header_string_ops = scan_file( path_base "dependencies/string_ops.hpp" );
|
Code header_string_ops = scan_file( path_base "dependencies/string_ops.hpp" );
|
||||||
Code header_hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
Code header_hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
||||||
|
Code header_simd = scan_file( path_base "dependencies/simd.hpp" );
|
||||||
Code header_timing = scan_file( path_base "dependencies/timing.hpp" );
|
Code header_timing = scan_file( path_base "dependencies/timing.hpp" );
|
||||||
|
|
||||||
CodeBody parsed_header_memory = parse_file( path_base "dependencies/memory.hpp" );
|
CodeBody parsed_header_memory = parse_file( path_base "dependencies/memory.hpp" );
|
||||||
@@ -953,6 +1028,18 @@ R"(#define AST_ArrSpecs_Cap \
|
|||||||
txt("CodeUsing"),
|
txt("CodeUsing"),
|
||||||
txt("CodeVar"),
|
txt("CodeVar"),
|
||||||
};
|
};
|
||||||
|
// append, entry, and validate_body. Code is the untyped handle. CodeBody is the list / body pod.
|
||||||
|
Str code_body_slots[] = {
|
||||||
|
txt("Code"),
|
||||||
|
txt("CodeBody"),
|
||||||
|
};
|
||||||
|
// has_entries reads NumEntries. These pods keep that word as an entry count.
|
||||||
|
Str code_has_entries_slots[] = {
|
||||||
|
txt("Code"),
|
||||||
|
txt("CodeBody"),
|
||||||
|
txt("CodeParams"),
|
||||||
|
txt("CodeDefineParams"),
|
||||||
|
};
|
||||||
|
|
||||||
CodeBody parsed_code_types = parse_file( path_base "components/code_types.hpp" );
|
CodeBody parsed_code_types = parse_file( path_base "components/code_types.hpp" );
|
||||||
CodeBody code_types = def_body(CT_Global_Body);
|
CodeBody code_types = def_body(CT_Global_Body);
|
||||||
@@ -1025,8 +1112,17 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
|||||||
, tmpl_def_start
|
, tmpl_def_start
|
||||||
));
|
));
|
||||||
|
|
||||||
// Append slots
|
// Append slots. Restricted procedures omit static types that cannot call them.
|
||||||
for(Str type : code_typenames ) {
|
if (actual_name.is_equal(txt("append")) || actual_name.is_equal(txt("entry")) || actual_name.is_equal(txt("validate_body"))) {
|
||||||
|
for (Str type : code_body_slots)
|
||||||
|
generic_selector.append_fmt("%S : %S,\\\n", type, fn->Name);
|
||||||
|
}
|
||||||
|
else if (actual_name.is_equal(txt("has_entries"))) {
|
||||||
|
for (Str type : code_has_entries_slots)
|
||||||
|
generic_selector.append_fmt("%S : %S,\\\n", type, fn->Name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (Str type : code_typenames)
|
||||||
generic_selector.append_fmt("%S : %S,\\\n", type, fn->Name);
|
generic_selector.append_fmt("%S : %S,\\\n", type, fn->Name);
|
||||||
}
|
}
|
||||||
generic_selector.append(txt("default: gen_generic_selection_fail \\\n"));
|
generic_selector.append(txt("default: gen_generic_selection_fail \\\n"));
|
||||||
@@ -1143,19 +1239,22 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
|||||||
for ( CodeParams opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_")))
|
for ( CodeParams opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_")))
|
||||||
{
|
{
|
||||||
// Convert the definition to use a default struct: https://vxtwitter.com/vkrajacic/status/1749816169736073295
|
// Convert the definition to use a default struct: https://vxtwitter.com/vkrajacic/status/1749816169736073295
|
||||||
if ( fn->Name.is_equal( txt("parse_global_body") ) )
|
if (fn->Name.starts_with(txt("parse_")))
|
||||||
{
|
{
|
||||||
Str new_name = txt("parse_global_body_opts");
|
Str new_name = StrBuilder::fmt_buf (_ctx->Allocator_Temp, "%S_opts", fn->Name).to_str();
|
||||||
char const* tmpl_fn_macro = "#define <def_name>( <params> ... ) <def__name>( <params> & (<opts_type>) { __VA_ARGS__ } )\n";
|
StrBuilder params_str = StrBuilder::make_reserve(_ctx->Allocator_Temp, 32);
|
||||||
Code fn_macro;
|
for (CodeParams other_param : fn->Params) {
|
||||||
|
if (other_param == opt_param) break;
|
||||||
|
params_str.append_fmt("%S, ", other_param->Name);
|
||||||
|
}
|
||||||
|
|
||||||
opt_param->ValueType->Specs = def_specifier( Spec_Ptr );
|
opt_param->ValueType->Specs = def_specifier( Spec_Ptr );
|
||||||
fn_macro = untyped_str( token_fmt(
|
Code fn_macro = untyped_str( token_fmt(
|
||||||
"def_name", fn->Name
|
"def_name", fn->Name
|
||||||
, "def__name", new_name
|
, "def__name", new_name
|
||||||
, "params", txt("def, ")
|
, "params", params_str.to_str()
|
||||||
, "opts_type", opt_param->ValueType->Name
|
, "opts_type", opt_param->ValueType->Name
|
||||||
, tmpl_fn_macro
|
, "#define <def_name>( <params> ... ) <def__name>( <params> & (<opts_type>) { __VA_ARGS__ } )\n"
|
||||||
));
|
));
|
||||||
fn->Name = cache_str( new_name );
|
fn->Name = cache_str( new_name );
|
||||||
interface.append( fn );
|
interface.append( fn );
|
||||||
@@ -1348,7 +1447,17 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
|||||||
);
|
);
|
||||||
// Append slots
|
// Append slots
|
||||||
for(Str type : code_typenames ) {
|
for(Str type : code_typenames ) {
|
||||||
generic_selector.append_fmt("%S : %S,\\\n", type, fn->Name );
|
bool appended = false;
|
||||||
|
strtmpl_append(& generic_selector, appended, strtmpl_slots(
|
||||||
|
strtmpl_slot("type", type),
|
||||||
|
strtmpl_slot("fn", fn->Name)
|
||||||
|
),
|
||||||
|
code(<type> : <fn>,\\\n)
|
||||||
|
);
|
||||||
|
if (appended == false) {
|
||||||
|
GEN_FATAL("builder_print selector template failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
generic_selector.append(txt("default: gen_generic_selection_fail \\\n"));
|
generic_selector.append(txt("default: gen_generic_selection_fail \\\n"));
|
||||||
generic_selector.append(txt("\t)\tGEN_RESOLVED_FUNCTION_CALL( builder, (Code)code )"));
|
generic_selector.append(txt("\t)\tGEN_RESOLVED_FUNCTION_CALL( builder, (Code)code )"));
|
||||||
@@ -1432,27 +1541,30 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
|||||||
|
|
||||||
Code src_parsing_interface = scan_file( path_base "components/interface.parsing.cpp" );
|
Code src_parsing_interface = scan_file( path_base "components/interface.parsing.cpp" );
|
||||||
{
|
{
|
||||||
Str needle = txt("CodeBody parse_global_body( Str def, Opts_parse_global_body opts )");
|
Str parser_names[] = {
|
||||||
Str scanned = src_parsing_interface->Content;
|
txt("parse_class"),
|
||||||
ssize signature_at = -1;
|
txt("parse_constructor"),
|
||||||
ssize scan_offset;
|
txt("parse_define"),
|
||||||
ssize last_offset = scanned.Len - needle.Len;
|
txt("parse_destructor"),
|
||||||
for ( scan_offset = 0; scan_offset <= last_offset; ++ scan_offset )
|
txt("parse_enum"),
|
||||||
{
|
txt("parse_export_body"),
|
||||||
if ( c_str_compare_len( scanned.Ptr + scan_offset, needle.Ptr, needle.Len ) == 0 ) {
|
txt("parse_extern_link"),
|
||||||
signature_at = scan_offset;
|
txt("parse_friend"),
|
||||||
break;
|
txt("parse_function"),
|
||||||
}
|
txt("parse_global_body"),
|
||||||
}
|
txt("parse_namespace"),
|
||||||
if ( signature_at < 0 ) GEN_FATAL( "c_library: parse_global_body signature missing from scanned interface.parsing.cpp" );
|
txt("parse_operator"),
|
||||||
/*Resolved replacement*/ {
|
txt("parse_operator_cast"),
|
||||||
Str replacement = txt("CodeBody parse_global_body_opts( Str def, Opts_parse_global_body* opts )");
|
txt("parse_struct"),
|
||||||
StrBuilder rebuilt = strbuilder_make_reserve( _ctx->Allocator_Temp, scanned.Len + replacement.Len );
|
txt("parse_template"),
|
||||||
strbuilder_append_str( & rebuilt, Str { scanned.Ptr, signature_at } );
|
txt("parse_type"),
|
||||||
strbuilder_append_str( & rebuilt, replacement );
|
txt("parse_typedef"),
|
||||||
strbuilder_append_str( & rebuilt, Str { scanned.Ptr + signature_at + needle.Len, scanned.Len - signature_at - needle.Len } );
|
txt("parse_union"),
|
||||||
src_parsing_interface = untyped_str( strbuilder_to_str( rebuilt ) );
|
txt("parse_using"),
|
||||||
}
|
txt("parse_variable"),
|
||||||
|
};
|
||||||
|
for (s32 idx = 0; idx < (s32)(sizeof(parser_names) / sizeof(parser_names[0])); ++idx)
|
||||||
|
src_parsing_interface = rewrite_parse_wrapper_signature(src_parsing_interface, parser_names[idx]);
|
||||||
}
|
}
|
||||||
Code src_untyped = scan_file( path_base "components/interface.untyped.cpp" );
|
Code src_untyped = scan_file( path_base "components/interface.untyped.cpp" );
|
||||||
Code src_parser_case_macros = scan_file( path_base "components/parser_case_macros.cpp" );
|
Code src_parser_case_macros = scan_file( path_base "components/parser_case_macros.cpp" );
|
||||||
@@ -1693,6 +1805,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
|||||||
Code r_header_string_ops = refactor(header_string_ops);
|
Code r_header_string_ops = refactor(header_string_ops);
|
||||||
Code rf_containers = refactor_and_format(containers);
|
Code rf_containers = refactor_and_format(containers);
|
||||||
Code r_header_hashing = refactor(header_hashing);
|
Code r_header_hashing = refactor(header_hashing);
|
||||||
|
Code r_header_simd = refactor(header_simd);
|
||||||
Code rf_header_strings = refactor_and_format(header_strings);
|
Code rf_header_strings = refactor_and_format(header_strings);
|
||||||
Code rf_header_filesystem = refactor_and_format(header_filesystem);
|
Code rf_header_filesystem = refactor_and_format(header_filesystem);
|
||||||
Code r_header_timing = refactor(header_timing);
|
Code r_header_timing = refactor(header_timing);
|
||||||
@@ -1779,6 +1892,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
|||||||
header.print( fmt_newline);
|
header.print( fmt_newline);
|
||||||
header.print( rf_containers);
|
header.print( rf_containers);
|
||||||
header.print( r_header_hashing );
|
header.print( r_header_hashing );
|
||||||
|
header.print( r_header_simd );
|
||||||
header.print( rf_header_strings);
|
header.print( rf_header_strings);
|
||||||
header.print( rf_header_filesystem);
|
header.print( rf_header_filesystem);
|
||||||
header.print( r_header_timing );
|
header.print( r_header_timing );
|
||||||
@@ -1928,6 +2042,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
|||||||
header.print( fmt_newline);
|
header.print( fmt_newline);
|
||||||
header.print( rf_containers);
|
header.print( rf_containers);
|
||||||
header.print( r_header_hashing );
|
header.print( r_header_hashing );
|
||||||
|
header.print( r_header_simd );
|
||||||
header.print( rf_header_strings);
|
header.print( rf_header_strings);
|
||||||
header.print( rf_header_filesystem);
|
header.print( rf_header_filesystem);
|
||||||
header.print( r_header_timing );
|
header.print( r_header_timing );
|
||||||
|
|||||||
@@ -33,6 +33,15 @@ word stringize, gen_stringize
|
|||||||
word do_once, gen_do_once
|
word do_once, gen_do_once
|
||||||
word do_once_start, gen_do_once_start
|
word do_once_start, gen_do_once_start
|
||||||
word do_once_end, gen_do_once_end
|
word do_once_end, gen_do_once_end
|
||||||
|
word each_iter, gen_each_iter
|
||||||
|
word index_iter, gen_index_iter
|
||||||
|
word range_iter, gen_range_iter
|
||||||
|
word defer, gen_defer
|
||||||
|
word defer_rewind, gen_defer_rewind
|
||||||
|
word defer_info, gen_defer_info
|
||||||
|
word scope, gen_scope
|
||||||
|
word scope_info, gen_scope_info
|
||||||
|
word do_while, gen_do_while
|
||||||
word labeled_scope_start, gen_labeled_scope_start
|
word labeled_scope_start, gen_labeled_scope_start
|
||||||
word labeled_scope_end, gen_labeled_scope_end
|
word labeled_scope_end, gen_labeled_scope_end
|
||||||
word compiler_decorated_func_name, gen_compiler_decorated_func_name
|
word compiler_decorated_func_name, gen_compiler_decorated_func_name
|
||||||
@@ -59,10 +68,12 @@ word txt, gen_txt
|
|||||||
// Basic Types
|
// Basic Types
|
||||||
|
|
||||||
word u8, gen_u8
|
word u8, gen_u8
|
||||||
|
word u8x16, gen_u8x16
|
||||||
word s8, gen_s8
|
word s8, gen_s8
|
||||||
word u16, gen_u16
|
word u16, gen_u16
|
||||||
word s16, gen_s16
|
word s16, gen_s16
|
||||||
word u32, gen_u32
|
word u32, gen_u32
|
||||||
|
word u32x4, gen_u32x4
|
||||||
word s32, gen_s32
|
word s32, gen_s32
|
||||||
word u64, gen_u64
|
word u64, gen_u64
|
||||||
word s64, gen_s64
|
word s64, gen_s64
|
||||||
@@ -82,6 +93,13 @@ word to_sptr, gen_to_sptr
|
|||||||
word to_mem_ptr, gen_to_mem_ptr
|
word to_mem_ptr, gen_to_mem_ptr
|
||||||
word to_mem_ptr_const, gen_to_mem_ptr_const
|
word to_mem_ptr_const, gen_to_mem_ptr_const
|
||||||
|
|
||||||
|
// SIMD
|
||||||
|
|
||||||
|
namespace u8x16_, gen_u8x16_
|
||||||
|
namespace u32x4_, gen_u32x4_
|
||||||
|
|
||||||
|
word u32_mask_first_set, gen_u32_mask_first_set
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
|
|
||||||
word assert_handler, gen_assert_handler
|
word assert_handler, gen_assert_handler
|
||||||
@@ -223,8 +241,11 @@ word cast_to_str, gen_cast_to_str
|
|||||||
|
|
||||||
word StrBuilderHeader, gen_StrBuilderHeader
|
word StrBuilderHeader, gen_StrBuilderHeader
|
||||||
word StrBuilder, gen_StrBuilder
|
word StrBuilder, gen_StrBuilder
|
||||||
|
word StrTemplateSlot, gen_StrTemplateSlot
|
||||||
|
word Slice_StrTemplateSlot, gen_Slice_StrTemplateSlot
|
||||||
|
|
||||||
namespace strbuilder_, gen_strbuilder_
|
namespace strbuilder_, gen_strbuilder_
|
||||||
|
namespace strtmpl_, gen_strtmpl_
|
||||||
|
|
||||||
word StrCached, gen_StrCached
|
word StrCached, gen_StrCached
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ int gen_main()
|
|||||||
Code printing = scan_file( path_base "dependencies/printing.hpp" );
|
Code printing = scan_file( path_base "dependencies/printing.hpp" );
|
||||||
Code containers = scan_file( path_base "dependencies/containers.hpp" );
|
Code containers = scan_file( path_base "dependencies/containers.hpp" );
|
||||||
Code hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
Code hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
||||||
|
Code simd = scan_file( path_base "dependencies/simd.hpp" );
|
||||||
Code strings = scan_file( path_base "dependencies/strings.hpp" );
|
Code strings = scan_file( path_base "dependencies/strings.hpp" );
|
||||||
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
|
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
|
||||||
Code timing = scan_file( path_base "dependencies/timing.hpp" );
|
Code timing = scan_file( path_base "dependencies/timing.hpp" );
|
||||||
@@ -70,6 +71,7 @@ int gen_main()
|
|||||||
builder_print( header, printing );
|
builder_print( header, printing );
|
||||||
builder_print( header, containers );
|
builder_print( header, containers );
|
||||||
builder_print( header, hashing );
|
builder_print( header, hashing );
|
||||||
|
builder_print( header, simd );
|
||||||
builder_print( header, strings );
|
builder_print( header, strings );
|
||||||
builder_print( header, filesystem );
|
builder_print( header, filesystem );
|
||||||
builder_print( header, timing );
|
builder_print( header, timing );
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ int gen_main()
|
|||||||
Code printing = scan_file( path_base "dependencies/printing.hpp" );
|
Code printing = scan_file( path_base "dependencies/printing.hpp" );
|
||||||
Code containers = scan_file( path_base "dependencies/containers.hpp" );
|
Code containers = scan_file( path_base "dependencies/containers.hpp" );
|
||||||
Code hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
Code hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
||||||
|
Code simd = scan_file( path_base "dependencies/simd.hpp" );
|
||||||
Code strings = scan_file( path_base "dependencies/strings.hpp" );
|
Code strings = scan_file( path_base "dependencies/strings.hpp" );
|
||||||
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
|
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
|
||||||
Code timing = scan_file( path_base "dependencies/timing.hpp" );
|
Code timing = scan_file( path_base "dependencies/timing.hpp" );
|
||||||
@@ -97,6 +98,7 @@ int gen_main()
|
|||||||
header.print( printing );
|
header.print( printing );
|
||||||
header.print( containers );
|
header.print( containers );
|
||||||
header.print( hashing );
|
header.print( hashing );
|
||||||
|
header.print( simd );
|
||||||
header.print( strings );
|
header.print( strings );
|
||||||
header.print( filesystem );
|
header.print( filesystem );
|
||||||
header.print( timing );
|
header.print( timing );
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ int gen_main()
|
|||||||
Code printing = scan_file( path_base "dependencies/printing.hpp" );
|
Code printing = scan_file( path_base "dependencies/printing.hpp" );
|
||||||
Code containers = scan_file( path_base "dependencies/containers.hpp" );
|
Code containers = scan_file( path_base "dependencies/containers.hpp" );
|
||||||
Code hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
Code hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
||||||
|
Code simd = scan_file( path_base "dependencies/simd.hpp" );
|
||||||
Code strings = scan_file( path_base "dependencies/strings.hpp" );
|
Code strings = scan_file( path_base "dependencies/strings.hpp" );
|
||||||
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
|
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
|
||||||
Code timing = scan_file( path_base "dependencies/timing.hpp" );
|
Code timing = scan_file( path_base "dependencies/timing.hpp" );
|
||||||
@@ -166,6 +167,7 @@ int gen_main()
|
|||||||
header.print( printing );
|
header.print( printing );
|
||||||
header.print( containers );
|
header.print( containers );
|
||||||
header.print( hashing );
|
header.print( hashing );
|
||||||
|
header.print( simd );
|
||||||
header.print( strings );
|
header.print( strings );
|
||||||
header.print( filesystem );
|
header.print( filesystem );
|
||||||
header.print( timing );
|
header.print( timing );
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
gen_internal void expect_simd_lanes()
|
||||||
|
{
|
||||||
|
#if defined(GEN_SYSTEM_WINDOWS) && (defined(_M_X64) || defined(__x86_64__))
|
||||||
|
gen_u8 storage[32];
|
||||||
|
gen_mem_set(storage, 0x11, 32);
|
||||||
|
gen_u8 pattern[16] = {
|
||||||
|
0x00, 0x80, 0xFF, 0x01,
|
||||||
|
0x02, 0x03, 0x04, 0x05,
|
||||||
|
0x06, 0x07, 0x08, 0x09,
|
||||||
|
0x0A, 0x0B, 0x0C, 0x0D
|
||||||
|
};
|
||||||
|
gen_mem_copy(storage + 1, pattern, 16);
|
||||||
|
gen_u8x16 loaded = gen_u8x16_load(storage + 1);
|
||||||
|
gen_u8x16 again = gen_u8x16_load(storage + 1);
|
||||||
|
gen_u16 same = gen_u8x16_mask(gen_u8x16_equal(loaded, again));
|
||||||
|
gen_u16 zero_mask = gen_u8x16_mask(gen_u8x16_equal(loaded, gen_u8x16_splat(0x00)));
|
||||||
|
gen_u16 high_bit = gen_u8x16_mask(gen_u8x16_equal(loaded, gen_u8x16_splat(0x80)));
|
||||||
|
gen_u16 top = gen_u8x16_mask(gen_u8x16_equal(loaded, gen_u8x16_splat(0xFF)));
|
||||||
|
expect(same == 0xFFFF, gen_txt("simd u8 equal load"));
|
||||||
|
expect(zero_mask == 0x0001, gen_txt("simd byte 0"));
|
||||||
|
expect(high_bit == 0x0002, gen_txt("simd byte 0x80"));
|
||||||
|
expect(top == 0x0004, gen_txt("simd byte 0xFF"));
|
||||||
|
|
||||||
|
gen_u8 high_lane[16];
|
||||||
|
gen_mem_set(high_lane, 0x22, 16);
|
||||||
|
high_lane[15] = 0xFF;
|
||||||
|
gen_u8x16 high_loaded = gen_u8x16_load(high_lane);
|
||||||
|
gen_u16 lane15 = gen_u8x16_mask(gen_u8x16_equal(high_loaded, gen_u8x16_splat(0xFF)));
|
||||||
|
expect(lane15 == 0x8000, gen_txt("simd lane 15"));
|
||||||
|
expect(gen_u32_mask_first_set(lane15) == 15, gen_txt("simd first set lane 15"));
|
||||||
|
|
||||||
|
gen_u8 window[24];
|
||||||
|
gen_mem_set(window, 0xEE, 24);
|
||||||
|
window[1] = 0x00;
|
||||||
|
window[2] = 0x80;
|
||||||
|
window[3] = 0xFF;
|
||||||
|
window[4] = 0x11;
|
||||||
|
window[5] = 0x22;
|
||||||
|
window[6] = 0x33;
|
||||||
|
window[7] = 0x44;
|
||||||
|
window[8] = 0x55;
|
||||||
|
gen_u8x16 loaded8 = gen_u8x16_load8(window + 1);
|
||||||
|
gen_u16 upper = gen_u8x16_mask(gen_u8x16_equal(loaded8, gen_u8x16_splat(0x00)));
|
||||||
|
gen_u16 low_ff = gen_u8x16_mask(gen_u8x16_equal(loaded8, gen_u8x16_splat(0xFF)));
|
||||||
|
gen_u16 low_80 = gen_u8x16_mask(gen_u8x16_equal(loaded8, gen_u8x16_splat(0x80)));
|
||||||
|
gen_u16 byte7 = gen_u8x16_mask(gen_u8x16_equal(loaded8, gen_u8x16_splat(0x55)));
|
||||||
|
expect((upper & 0xFF00) == 0xFF00, gen_txt("simd load8 upper zero"));
|
||||||
|
expect((upper & 0x0001) == 0x0001, gen_txt("simd load8 low zero"));
|
||||||
|
expect(low_ff == 0x0004, gen_txt("simd load8 low 0xFF"));
|
||||||
|
expect(low_80 == 0x0002, gen_txt("simd load8 low 0x80"));
|
||||||
|
expect(byte7 == 0x0080, gen_txt("simd load8 byte 7"));
|
||||||
|
gen_u16 sentinel = gen_u8x16_mask(gen_u8x16_equal(loaded8, gen_u8x16_splat(0xEE)));
|
||||||
|
expect(sentinel == 0, gen_txt("simd load8 ignores tail"));
|
||||||
|
gen_u8x16 loaded16 = gen_u8x16_load(window + 1);
|
||||||
|
gen_u16 tail = gen_u8x16_mask(gen_u8x16_equal(loaded16, gen_u8x16_splat(0xEE)));
|
||||||
|
expect(tail == 0xFF00, gen_txt("simd load16 sees load8 tail"));
|
||||||
|
|
||||||
|
gen_u32 hashes[4] = { 0x00000000u, 0x7FFFFFFFu, 0x80000000u, 0xFFFFFFFFu };
|
||||||
|
gen_u32x4 hash_loaded = gen_u32x4_load(hashes);
|
||||||
|
gen_u8 lane0 = gen_u32x4_mask(gen_u32x4_equal(hash_loaded, gen_u32x4_splat(0x00000000u)));
|
||||||
|
gen_u8 lane1 = gen_u32x4_mask(gen_u32x4_equal(hash_loaded, gen_u32x4_splat(0x7FFFFFFFu)));
|
||||||
|
gen_u8 lane2 = gen_u32x4_mask(gen_u32x4_equal(hash_loaded, gen_u32x4_splat(0x80000000u)));
|
||||||
|
gen_u8 lane3 = gen_u32x4_mask(gen_u32x4_equal(hash_loaded, gen_u32x4_splat(0xFFFFFFFFu)));
|
||||||
|
expect(lane0 == 0x01, gen_txt("simd u32 lane 0"));
|
||||||
|
expect(lane1 == 0x02, gen_txt("simd u32 lane 1"));
|
||||||
|
expect(lane2 == 0x04, gen_txt("simd u32 bit31 lane"));
|
||||||
|
expect(lane3 == 0x08, gen_txt("simd u32 lane 3"));
|
||||||
|
expect((lane2 & 0xF0) == 0, gen_txt("simd u32 mask low bits"));
|
||||||
|
|
||||||
|
gen_u32 all_values[4] = { 0x80000000u, 0x80000000u, 0x80000000u, 0x80000000u };
|
||||||
|
gen_u32x4 all_loaded = gen_u32x4_load(all_values);
|
||||||
|
gen_u8 all_mask = gen_u32x4_mask(gen_u32x4_equal(all_loaded, gen_u32x4_splat(0x80000000u)));
|
||||||
|
expect(all_mask == 0x0F, gen_txt("simd u32 all bit31"));
|
||||||
|
gen_u8 none_mask = gen_u32x4_mask(gen_u32x4_equal(all_loaded, gen_u32x4_splat(0x7FFFFFFFu)));
|
||||||
|
expect(none_mask == 0x00, gen_txt("simd u32 none"));
|
||||||
|
|
||||||
|
gen_u8 hash_storage[20];
|
||||||
|
gen_mem_set (hash_storage, 0xA5, 20);
|
||||||
|
gen_mem_copy(hash_storage + 1, hashes, 16);
|
||||||
|
gen_u32x4 unaligned = gen_u32x4_load(hash_storage + 1);
|
||||||
|
gen_u8 unaligned_mask = gen_u32x4_mask(gen_u32x4_equal(unaligned, gen_u32x4_splat(0x80000000u)));
|
||||||
|
expect(unaligned_mask == 0x04, gen_txt("simd u32 unaligned bit31"));
|
||||||
|
|
||||||
|
expect(gen_u32_mask_first_set(0x1u) == 0, gen_txt("simd first set bit 0"));
|
||||||
|
expect(gen_u32_mask_first_set(0x14u) == 2, gen_txt("simd first set lowest"));
|
||||||
|
expect(gen_u32_mask_first_set(0x8000u) == 15, gen_txt("simd first set bit 15"));
|
||||||
|
expect(gen_u32_mask_first_set(0x80000000u) == 31, gen_txt("simd first set bit 31"));
|
||||||
|
expect(gen_u32_mask_first_set(0xFFFFFFFFu) == 0, gen_txt("simd first set all bits"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -0,0 +1,631 @@
|
|||||||
|
gen_internal gen_Str bounded_format(char* storage, gen_ssize storage_len, char const* bytes, gen_ssize len) {
|
||||||
|
gen_mem_set(storage, '!', storage_len);
|
||||||
|
if (len > 0)
|
||||||
|
gen_mem_copy(storage, bytes, len);
|
||||||
|
storage[storage_len - 1] = '\0';
|
||||||
|
gen_Str result = { storage, len };
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_expansion(gen_Str label, gen_Str format, gen_StrTemplateSlot* slots, gen_ssize slot_count, gen_Str expansion) {
|
||||||
|
gen_StrBuilder output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
expect(gen_strbuilder_append_str(& output, gen_txt("KEEP")), label);
|
||||||
|
gen_Slice_StrTemplateSlot slice = { 0, 0 };
|
||||||
|
if (slot_count != 0) {
|
||||||
|
slice.Ptr = slots;
|
||||||
|
slice.Len = slot_count;
|
||||||
|
}
|
||||||
|
bool appended = gen_strbuilder_append_template(& output, slice, format);
|
||||||
|
expect(appended, label);
|
||||||
|
gen_Str got = gen_strbuilder_to_str(output);
|
||||||
|
expect(got.Len == 4 + expansion.Len, label);
|
||||||
|
expect(gen_str_starts_with(got, gen_txt("KEEP")), label);
|
||||||
|
if (got.Len >= 4 + expansion.Len) {
|
||||||
|
gen_Str tail = { got.Ptr + 4, expansion.Len };
|
||||||
|
expect(gen_str_are_equal(tail, expansion), label);
|
||||||
|
}
|
||||||
|
gen_StrBuilderHeader* header = gen_strbuilder_get_header(output);
|
||||||
|
expect(header->Allocator.Proc == gen_heap_allocator_proc, label);
|
||||||
|
gen_strbuilder_free(& output);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_text(gen_Str label, gen_Str format, gen_StrTemplateSlot* slots, gen_ssize slot_count, gen_Str expansion) {
|
||||||
|
expect_template_expansion(label, format, slots, slot_count, expansion);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_literal_boundary(gen_ssize mark) {
|
||||||
|
char format_storage[64];
|
||||||
|
char format_bytes [40];
|
||||||
|
for (gen_ssize idx = 0; idx < mark; ++ idx) format_bytes[idx] = 'L';
|
||||||
|
gen_Str format = bounded_format(format_storage, 64, format_bytes, mark);
|
||||||
|
gen_Str expansion = { format_bytes, mark };
|
||||||
|
expect(format_storage[mark] == '!', gen_txt("literal boundary"));
|
||||||
|
expect_template_expansion(gen_txt("literal boundary"), format, 0, 0, expansion);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_open_boundary(gen_ssize mark) {
|
||||||
|
char format_storage [64];
|
||||||
|
char format_bytes [48];
|
||||||
|
char expansion_bytes[48];
|
||||||
|
gen_ssize format_len = 0;
|
||||||
|
for (gen_ssize idx = 0; idx < mark; ++ idx)
|
||||||
|
format_bytes[format_len ++] = 'L';
|
||||||
|
format_bytes[format_len ++] = '<';
|
||||||
|
format_bytes[format_len ++] = 'k';
|
||||||
|
format_bytes[format_len ++] = '>';
|
||||||
|
format_bytes[format_len ++] = 'Z';
|
||||||
|
gen_Str format = bounded_format(format_storage, 64, format_bytes, format_len);
|
||||||
|
gen_StrTemplateSlot slot = {0};
|
||||||
|
slot.Key = gen_txt("k");
|
||||||
|
slot.Value = gen_txt("V");
|
||||||
|
gen_ssize expansion_len = 0;
|
||||||
|
for (gen_ssize idx = 0; idx < mark; ++ idx)
|
||||||
|
expansion_bytes[expansion_len ++] = 'L';
|
||||||
|
expansion_bytes[expansion_len ++] = 'V';
|
||||||
|
expansion_bytes[expansion_len ++] = 'Z';
|
||||||
|
gen_Str expansion = { expansion_bytes, expansion_len };
|
||||||
|
expect(format.Ptr[mark] == '<', gen_txt("open boundary"));
|
||||||
|
expect(format_storage[format_len] == '!', gen_txt("open boundary"));
|
||||||
|
expect_template_expansion(gen_txt("open boundary"), format, & slot, 1, expansion);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_close_boundary(gen_ssize mark) {
|
||||||
|
char format_storage[64];
|
||||||
|
char format_bytes [48];
|
||||||
|
char key_storage [40];
|
||||||
|
gen_ssize key_len = mark - 1;
|
||||||
|
gen_mem_set(key_storage, '!', 40);
|
||||||
|
for (gen_ssize idx = 0; idx < key_len; ++ idx)
|
||||||
|
key_storage[idx] = 'k';
|
||||||
|
key_storage[39] = '\0';
|
||||||
|
gen_Str key = { key_storage, key_len };
|
||||||
|
gen_ssize format_len = 0;
|
||||||
|
format_bytes[format_len ++] = '<';
|
||||||
|
for (gen_ssize idx = 0; idx < key_len; ++ idx)
|
||||||
|
format_bytes[format_len ++] = 'k';
|
||||||
|
format_bytes[format_len ++] = '>';
|
||||||
|
format_bytes[format_len ++] = 'Z';
|
||||||
|
gen_Str format = bounded_format(format_storage, 64, format_bytes, format_len);
|
||||||
|
gen_StrTemplateSlot slot = {0};
|
||||||
|
slot.Key = key;
|
||||||
|
slot.Value = gen_txt("V");
|
||||||
|
expect(format.Ptr [mark] == '>', gen_txt("close boundary"));
|
||||||
|
expect(key.Ptr [key.Len] == '!', gen_txt("close boundary"));
|
||||||
|
expect(format_storage[format_len] == '!', gen_txt("close boundary"));
|
||||||
|
expect_template_expansion(gen_txt("close boundary"), format, & slot, 1, gen_txt("VZ"));
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_shapes()
|
||||||
|
{
|
||||||
|
char literal_storage[8];
|
||||||
|
char literal_bytes [6] = { 'a', 'b', 'c', 'D', 'E', 'F' };
|
||||||
|
gen_Str literal = bounded_format(literal_storage, 8, literal_bytes, 3);
|
||||||
|
expect(literal_storage[3] == '!', gen_txt("literal sentinel"));
|
||||||
|
expect_template_expansion(gen_txt("literal bounded"), literal, 0, 0, gen_txt("abc"));
|
||||||
|
|
||||||
|
char empty_storage[4];
|
||||||
|
gen_Str empty_format = bounded_format(empty_storage, 4, empty_storage, 0);
|
||||||
|
expect(empty_storage[0] == '!', gen_txt("empty sentinel"));
|
||||||
|
expect_template_expansion(gen_txt("empty format"), empty_format, 0, 0, gen_txt(""));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot name_slot = {0};
|
||||||
|
name_slot.Key = gen_txt("name");
|
||||||
|
name_slot.Value = gen_txt("world");
|
||||||
|
expect_template_text(gen_txt("one slot"), gen_txt("hello <name>!"), & name_slot, 1, gen_txt("hello world!"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot repeat_slot = {0};
|
||||||
|
repeat_slot.Key = gen_txt("w");
|
||||||
|
repeat_slot.Value = gen_txt("v");
|
||||||
|
expect_template_text(gen_txt("repeated slot"), gen_txt("<w>-<w>-<w>"), & repeat_slot, 1, gen_txt("v-v-v"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot adjacent[2] = {0};
|
||||||
|
adjacent[0].Key = gen_txt("a");
|
||||||
|
adjacent[0].Value = gen_txt("X");
|
||||||
|
adjacent[1].Key = gen_txt("b");
|
||||||
|
adjacent[1].Value = gen_txt("Y");
|
||||||
|
expect_template_text(gen_txt("adjacent slots"), gen_txt("<a><b><a>"), adjacent, 2, gen_txt("XYX"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot raw_slots[3] = {0};
|
||||||
|
raw_slots[0].Key = gen_txt("raw");
|
||||||
|
raw_slots[0].Value = gen_txt("a<b>c");
|
||||||
|
raw_slots[1].Key = gen_txt("angles");
|
||||||
|
raw_slots[1].Value = gen_txt("<>");
|
||||||
|
raw_slots[2].Key = gen_txt("b");
|
||||||
|
raw_slots[2].Value = gen_txt("SHOULD_NOT");
|
||||||
|
expect_template_text(gen_txt("value angles literal"), gen_txt("<raw><angles>"), raw_slots, 3, gen_txt("a<b>c<>"));
|
||||||
|
|
||||||
|
char empty_value_storage[2] = { '!', '!' };
|
||||||
|
gen_StrTemplateSlot empty_slot = {0};
|
||||||
|
empty_slot.Key = gen_txt("e");
|
||||||
|
empty_slot.Value = (gen_Str){ empty_value_storage, 0 };
|
||||||
|
expect_template_text(gen_txt("empty value"), gen_txt("A<e>B"), & empty_slot, 1, gen_txt("AB"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot empty_key = {0};
|
||||||
|
empty_key.Key = (gen_Str){ 0, 0 };
|
||||||
|
empty_key.Value = gen_txt("Z");
|
||||||
|
expect_template_text(gen_txt("empty key"), gen_txt("<>"), & empty_key, 1, gen_txt("Z"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot null_value = {0};
|
||||||
|
null_value.Key = gen_txt("e");
|
||||||
|
null_value.Value = (gen_Str){ 0, 0 };
|
||||||
|
expect(null_value.Value.Ptr == 0, gen_txt("null empty value pointer"));
|
||||||
|
expect(null_value.Value.Len == 0, gen_txt("null empty value length"));
|
||||||
|
expect_template_text(gen_txt("null empty value"), gen_txt("A<e>B"), & null_value, 1, gen_txt("AB"));
|
||||||
|
|
||||||
|
char nul_value_bytes[4] = { 'a', '\0', 'b', '!' };
|
||||||
|
char nul_expected [5] = { '[', 'a', '\0', 'b', ']' };
|
||||||
|
gen_StrTemplateSlot nul_slot = {0};
|
||||||
|
nul_slot.Key = gen_txt("n");
|
||||||
|
nul_slot.Value = (gen_Str){ nul_value_bytes, 3 };
|
||||||
|
gen_Str nul_expansion = { nul_expected, 5 };
|
||||||
|
expect_template_text(gen_txt("embedded nul"), gen_txt("[<n>]"), & nul_slot, 1, nul_expansion);
|
||||||
|
|
||||||
|
gen_StrTemplateSlot duffle[2] = {0};
|
||||||
|
duffle[0].Key = gen_txt("operands[0]");
|
||||||
|
duffle[0].Value = gen_txt("eax");
|
||||||
|
duffle[1].Key = gen_txt("mod_rm.bits");
|
||||||
|
duffle[1].Value = gen_txt("11");
|
||||||
|
expect_template_text(gen_txt("duffle keys"), gen_txt("mov <operands[0]>, <mod_rm.bits>;"), duffle, 2, gen_txt("mov eax, 11;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void fill_lookup_slots(gen_StrTemplateSlot* slots, gen_ssize slot_count) {
|
||||||
|
gen_Str keys[9] = {
|
||||||
|
gen_txt("k0"), gen_txt("k1"), gen_txt("k2"), gen_txt("k3"), gen_txt("k4"),
|
||||||
|
gen_txt("k5"), gen_txt("k6"), gen_txt("k7"), gen_txt("k8")
|
||||||
|
};
|
||||||
|
gen_Str values[9] = {
|
||||||
|
gen_txt("V0"), gen_txt("V1"), gen_txt("V2"), gen_txt("V3"), gen_txt("V4"),
|
||||||
|
gen_txt("V5"), gen_txt("V6"), gen_txt("V7"), gen_txt("V8")
|
||||||
|
};
|
||||||
|
for (gen_ssize idx = 0; idx < slot_count; ++ idx) {
|
||||||
|
slots[idx].Key = keys[idx];
|
||||||
|
slots[idx].Value = values[idx];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_lookup()
|
||||||
|
{
|
||||||
|
gen_StrTemplateSlot slots[9] = {0};
|
||||||
|
expect_template_text(gen_txt("lookup 0"), gen_txt("none"), 0, 0, gen_txt("none"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 1);
|
||||||
|
expect_template_text(gen_txt("lookup 1"), gen_txt("<k0>"), slots, 1, gen_txt("V0"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 2);
|
||||||
|
expect_template_text(gen_txt("lookup 2"), gen_txt("<k1><k0>"), slots, 2, gen_txt("V1V0"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 3);
|
||||||
|
expect_template_text(gen_txt("lookup 3"), gen_txt("<k2>-<k0>-<k1>"), slots, 3, gen_txt("V2-V0-V1"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 4);
|
||||||
|
expect_template_text(gen_txt("lookup 4"), gen_txt("<k3><k0><k2><k1>"), slots, 4, gen_txt("V3V0V2V1"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 5);
|
||||||
|
expect_template_text(gen_txt("lookup 5 tail"), gen_txt("<k4><k0><k3>"), slots, 5, gen_txt("V4V0V3"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 8);
|
||||||
|
expect_template_text(gen_txt("lookup 8 lanes"), gen_txt("<k7><k4><k3><k0>"), slots, 8, gen_txt("V7V4V3V0"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 9);
|
||||||
|
expect_template_text(gen_txt("lookup 9 tail"), gen_txt("<k8><k5><k6><k4>"), slots, 9, gen_txt("V8V5V6V4"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot dup_small[3] = {0};
|
||||||
|
dup_small[0].Key = gen_txt("dup"); dup_small[0].Value = gen_txt("FIRST");
|
||||||
|
dup_small[1].Key = gen_txt("other"); dup_small[1].Value = gen_txt("X");
|
||||||
|
dup_small[2].Key = gen_txt("dup"); dup_small[2].Value = gen_txt("SECOND");
|
||||||
|
expect_template_text(gen_txt("duplicate first wins"), gen_txt("<dup><other>"), dup_small, 3, gen_txt("FIRSTX"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot dup_lanes[4] = {0};
|
||||||
|
dup_lanes[0].Key = gen_txt("same"); dup_lanes[0].Value = gen_txt("A");
|
||||||
|
dup_lanes[1].Key = gen_txt("same"); dup_lanes[1].Value = gen_txt("B");
|
||||||
|
dup_lanes[2].Key = gen_txt("other"); dup_lanes[2].Value = gen_txt("C");
|
||||||
|
dup_lanes[3].Key = gen_txt("same"); dup_lanes[3].Value = gen_txt("D");
|
||||||
|
expect_template_text(gen_txt("duplicate lane first wins"), gen_txt("<same><other>"), dup_lanes, 4, gen_txt("AC"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot dup_tail[5] = {0};
|
||||||
|
dup_tail[0].Key = gen_txt("dup"); dup_tail[0].Value = gen_txt("FIRST");
|
||||||
|
dup_tail[1].Key = gen_txt("k1"); dup_tail[1].Value = gen_txt("V1");
|
||||||
|
dup_tail[2].Key = gen_txt("k2"); dup_tail[2].Value = gen_txt("V2");
|
||||||
|
dup_tail[3].Key = gen_txt("k3"); dup_tail[3].Value = gen_txt("V3");
|
||||||
|
dup_tail[4].Key = gen_txt("dup"); dup_tail[4].Value = gen_txt("TAIL");
|
||||||
|
expect_template_text(gen_txt("duplicate tail first wins"), gen_txt("<dup>"), dup_tail, 5, gen_txt("FIRST"));
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_boundaries() {
|
||||||
|
gen_ssize marks[12] = { 7, 8, 9, 15, 16, 17, 23, 24, 25, 31, 32, 33 };
|
||||||
|
for (gen_ssize idx = 0; idx < gen_count_of(marks); ++ idx) {
|
||||||
|
expect_literal_boundary(marks[idx]);
|
||||||
|
expect_open_boundary(marks[idx]);
|
||||||
|
expect_close_boundary(marks[idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_growth(gen_ssize printf_maxlen)
|
||||||
|
{
|
||||||
|
gen_ssize huge_len = printf_maxlen + 64;
|
||||||
|
char* huge = gen_rcast(char*, gen_alloc(gen_heap(), huge_len + 1));
|
||||||
|
expect(huge != 0, gen_txt("growth alloc"));
|
||||||
|
if (huge == 0) return;
|
||||||
|
gen_mem_set(huge, 'Q', huge_len);
|
||||||
|
huge[huge_len] = '!';
|
||||||
|
|
||||||
|
gen_Str value = { huge, huge_len };
|
||||||
|
gen_StrTemplateSlot slot = {0};
|
||||||
|
slot.Key = gen_txt("blob");
|
||||||
|
slot.Value = value;
|
||||||
|
|
||||||
|
char format_storage[16];
|
||||||
|
gen_Str format = gen_txt("<blob>");
|
||||||
|
gen_StrBuilder output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
expect(gen_strbuilder_capacity(output) == 1, gen_txt("growth initial capacity"));
|
||||||
|
expect(gen_strbuilder_append_str(& output, gen_txt("KEEP")), gen_txt("growth prefix"));
|
||||||
|
|
||||||
|
gen_Slice_StrTemplateSlot slice = { & slot, 1 };
|
||||||
|
bool appended = gen_strbuilder_append_template(& output, slice, format);
|
||||||
|
expect(appended, gen_txt("growth append"));
|
||||||
|
|
||||||
|
gen_Str got = gen_strbuilder_to_str(output);
|
||||||
|
expect(got.Len == 4 + huge_len, gen_txt("growth length"));
|
||||||
|
expect(got.Len > printf_maxlen, gen_txt("growth beyond printf max"));
|
||||||
|
expect(gen_str_starts_with(got, gen_txt("KEEP")), gen_txt("growth keeps prefix"));
|
||||||
|
|
||||||
|
gen_ssize capacity = gen_strbuilder_capacity(output);
|
||||||
|
expect(capacity >= got.Len, gen_txt("growth capacity"));
|
||||||
|
if (got.Len == 4 + huge_len && capacity >= got.Len) {
|
||||||
|
gen_b32 payload_matches = true;
|
||||||
|
for (gen_ssize idx = 0; idx < got.Len - 4; ++ idx) {
|
||||||
|
if (got.Ptr[4 + idx] != 'Q') payload_matches = false;
|
||||||
|
}
|
||||||
|
expect(payload_matches, gen_txt("growth bytes"));
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_StrBuilderHeader* header = gen_strbuilder_get_header(output);
|
||||||
|
expect(header->Allocator.Proc == gen_heap_allocator_proc, gen_txt("growth allocator"));
|
||||||
|
expect(huge[huge_len] == '!', gen_txt("growth sentinel"));
|
||||||
|
gen_strbuilder_free(& output);
|
||||||
|
gen_allocator_free(gen_heap(), huge);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_crc_collision() {
|
||||||
|
gen_Str plumless = gen_txt("plumless");
|
||||||
|
gen_Str buckeroo = gen_txt("buckeroo");
|
||||||
|
gen_u32 plum_hash = gen_crc32(plumless.Ptr, plumless.Len);
|
||||||
|
gen_u32 buck_hash = gen_crc32(buckeroo.Ptr, buckeroo.Len);
|
||||||
|
expect(plum_hash == buck_hash, gen_txt("crc collision equal"));
|
||||||
|
expect(plum_hash == 0x4ddb0c25, gen_txt("crc collision value"));
|
||||||
|
expect(gen_str_are_equal(plumless, buckeroo) == false, gen_txt("crc collision keys differ"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot scalar[2] = {0};
|
||||||
|
scalar[0].Key = plumless; scalar[0].Value = gen_txt("WRONG");
|
||||||
|
scalar[1].Key = buckeroo; scalar[1].Value = gen_txt("RIGHT");
|
||||||
|
expect_template_text(gen_txt("crc scalar 2"), gen_txt("<buckeroo>"), scalar, 2, gen_txt("RIGHT"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot lanes[4] = {0};
|
||||||
|
lanes[0].Key = plumless; lanes[0].Value = gen_txt("WRONG");
|
||||||
|
lanes[1].Key = gen_txt("k1"); lanes[1].Value = gen_txt("V1");
|
||||||
|
lanes[2].Key = buckeroo; lanes[2].Value = gen_txt("RIGHT");
|
||||||
|
lanes[3].Key = gen_txt("k3"); lanes[3].Value = gen_txt("V3");
|
||||||
|
expect_template_text(gen_txt("crc lane reject"), gen_txt("<buckeroo>"), lanes, 4, gen_txt("RIGHT"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot tail[5] = {0};
|
||||||
|
tail[0].Key = plumless; tail[0].Value = gen_txt("WRONG");
|
||||||
|
tail[1].Key = gen_txt("k1"); tail[1].Value = gen_txt("V1");
|
||||||
|
tail[2].Key = gen_txt("k2"); tail[2].Value = gen_txt("V2");
|
||||||
|
tail[3].Key = gen_txt("k3"); tail[3].Value = gen_txt("V3");
|
||||||
|
tail[4].Key = buckeroo; tail[4].Value = gen_txt("TAIL");
|
||||||
|
expect_template_text(gen_txt("crc tail after false hit"), gen_txt("<buckeroo>"), tail, 5, gen_txt("TAIL"));
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void* resize_fail_allocator_proc(void* allocator_data, gen_AllocType type, gen_ssize size, gen_ssize alignment
|
||||||
|
, void* old_memory, gen_ssize old_size
|
||||||
|
, gen_u64 flags
|
||||||
|
){
|
||||||
|
if (type == EAllocation_RESIZE) {
|
||||||
|
gen_s32* attempts = gen_rcast(gen_s32*, allocator_data);
|
||||||
|
attempts[0] = attempts[0] + 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return gen_heap_allocator_proc(0, type, size, alignment, old_memory, old_size, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_resize_fail(gen_ssize printf_maxlen)
|
||||||
|
{
|
||||||
|
gen_ssize huge_len = printf_maxlen + 64;
|
||||||
|
char* huge = gen_rcast(char*, gen_alloc(gen_heap(), huge_len + 1));
|
||||||
|
expect(huge != 0, gen_txt("resize fail alloc"));
|
||||||
|
if (huge == 0) return;
|
||||||
|
gen_mem_set(huge, 'L', huge_len);
|
||||||
|
huge[huge_len] = '!';
|
||||||
|
gen_Str huge_text = { huge, huge_len };
|
||||||
|
|
||||||
|
gen_s32 literal_attempts = 0;
|
||||||
|
gen_AllocatorInfo literal_alloc = {0};
|
||||||
|
literal_alloc.Proc = resize_fail_allocator_proc;
|
||||||
|
literal_alloc.Data = & literal_attempts;
|
||||||
|
gen_StrBuilder literal_output = gen_strbuilder_make_reserve(literal_alloc, 4);
|
||||||
|
expect(gen_strbuilder_append_str(& literal_output, gen_txt("KEEP")), gen_txt("resize fail literal prefix"));
|
||||||
|
|
||||||
|
gen_Slice_StrTemplateSlot literal_slots = { 0, 0 };
|
||||||
|
bool literal_appended = gen_strbuilder_append_template(& literal_output, literal_slots, huge_text);
|
||||||
|
expect(literal_appended == false, gen_txt("resize fail literal"));
|
||||||
|
|
||||||
|
gen_Str literal_got = gen_strbuilder_to_str(literal_output);
|
||||||
|
expect(literal_got.Len == 4, gen_txt("resize fail literal length"));
|
||||||
|
expect(gen_str_are_equal(literal_got, gen_txt("KEEP")), gen_txt("resize fail literal keep"));
|
||||||
|
expect(literal_attempts > 0, gen_txt("resize fail literal attempts"));
|
||||||
|
gen_strbuilder_free(& literal_output);
|
||||||
|
|
||||||
|
gen_s32 value_attempts = 0;
|
||||||
|
gen_AllocatorInfo value_alloc = {0};
|
||||||
|
value_alloc.Proc = resize_fail_allocator_proc;
|
||||||
|
value_alloc.Data = & value_attempts;
|
||||||
|
|
||||||
|
gen_StrTemplateSlot slot = {0};
|
||||||
|
slot.Key = gen_txt("blob");
|
||||||
|
slot.Value = huge_text;
|
||||||
|
char format_storage[16];
|
||||||
|
|
||||||
|
gen_Str format = gen_txt("<blob>");
|
||||||
|
gen_StrBuilder value_output = gen_strbuilder_make_reserve(value_alloc, 4);
|
||||||
|
expect(gen_strbuilder_append_str(& value_output, gen_txt("KEEP")), gen_txt("resize fail value prefix"));
|
||||||
|
|
||||||
|
gen_Slice_StrTemplateSlot value_slots = { & slot, 1 };
|
||||||
|
bool value_appended = gen_strbuilder_append_template(& value_output, value_slots, format);
|
||||||
|
expect(value_appended == false, gen_txt("resize fail value"));
|
||||||
|
|
||||||
|
gen_Str value_got = gen_strbuilder_to_str(value_output);
|
||||||
|
expect(value_got.Len == 4, gen_txt("resize fail value length"));
|
||||||
|
expect(gen_str_are_equal(value_got, gen_txt("KEEP")), gen_txt("resize fail value keep"));
|
||||||
|
expect(value_attempts > 0, gen_txt("resize fail value attempts"));
|
||||||
|
|
||||||
|
gen_strbuilder_free(& value_output);
|
||||||
|
gen_allocator_free(gen_heap(), huge);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal gen_Str counted_template_value (gen_s32* reads) { reads[0] = reads[0] + 1; return gen_txt("ONCE"); }
|
||||||
|
gen_internal gen_Str counted_template_format(gen_s32* reads) { reads[0] = reads[0] + 1; return gen_txt("<k>:<k>"); }
|
||||||
|
gen_internal gen_StrBuilder* counted_template_output(gen_StrBuilder* output, gen_s32* reads) { reads[0] = reads[0] + 1; return output; }
|
||||||
|
gen_internal bool* counted_template_result(bool* result, gen_s32* reads) { reads[0] = reads[0] + 1; return result; }
|
||||||
|
|
||||||
|
gen_internal void expect_template_slice()
|
||||||
|
{
|
||||||
|
gen_StrTemplateSlot slots[2] = {
|
||||||
|
gen_strtmpl_slot("a", gen_txt("X")),
|
||||||
|
gen_strtmpl_slot("b", gen_txt("Y"))
|
||||||
|
};
|
||||||
|
gen_Slice_StrTemplateSlot slice = { slots, 2 };
|
||||||
|
gen_StrBuilder output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
expect(gen_strbuilder_append_str(& output, gen_txt("KEEP")), gen_txt("slice prefix"));
|
||||||
|
|
||||||
|
bool appended = gen_strbuilder_append_template(& output, slice, gen_txt("<b><a><b>"));
|
||||||
|
expect(appended, gen_txt("slice append"));
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(output), gen_txt("KEEPYXY")), gen_txt("slice text"));
|
||||||
|
expect(gen_str_are_equal(slots[0].Key, gen_txt("a")), gen_txt("slice key"));
|
||||||
|
expect(gen_str_are_equal(slots[0].Value, gen_txt("X")), gen_txt("slice value"));
|
||||||
|
gen_strbuilder_free(& output);
|
||||||
|
|
||||||
|
slice.Ptr[0].Value = gen_txt("Z");
|
||||||
|
gen_StrBuilder mutated_output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
bool mutated_appended = gen_strbuilder_append_template(& mutated_output, slice, gen_txt("<b><a><b>"));
|
||||||
|
expect(mutated_appended, gen_txt("slice mutate append"));
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(mutated_output), gen_txt("YZY")), gen_txt("slice mutate text"));
|
||||||
|
gen_strbuilder_free(& mutated_output);
|
||||||
|
|
||||||
|
gen_Slice_StrTemplateSlot empty_slice = { 0, 0 };
|
||||||
|
gen_StrBuilder empty_output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
expect(gen_strbuilder_append_str(& empty_output, gen_txt("KEEP")), gen_txt("zero slice prefix"));
|
||||||
|
|
||||||
|
bool empty_appended = gen_strbuilder_append_template(& empty_output, empty_slice, gen_txt("none"));
|
||||||
|
expect(empty_appended, gen_txt("zero slice append"));
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(empty_output), gen_txt("KEEPnone")), gen_txt("zero slice text"));
|
||||||
|
expect(empty_slice.Ptr == 0, gen_txt("zero slice pointer"));
|
||||||
|
expect(empty_slice.Len == 0, gen_txt("zero slice length"));
|
||||||
|
gen_strbuilder_free(& empty_output);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_wrapper() {
|
||||||
|
gen_StrBuilder output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
expect(gen_strbuilder_append_str(& output, gen_txt("KEEP")), gen_txt("wrapper prefix"));
|
||||||
|
bool appended = false;
|
||||||
|
gen_strtmpl_append(& output, appended, gen_strtmpl_slots(
|
||||||
|
gen_strtmpl_slot("name", gen_txt("world")),
|
||||||
|
gen_strtmpl_slot("tail", gen_txt("!"))
|
||||||
|
),
|
||||||
|
gen_txt(
|
||||||
|
"hello <name>\n"
|
||||||
|
"<name><tail>"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
expect(appended, gen_txt("wrapper multiline result"));
|
||||||
|
gen_Str got = gen_strbuilder_to_str(output);
|
||||||
|
expect(gen_str_starts_with(got, gen_txt("KEEP")), gen_txt("wrapper prefix kept"));
|
||||||
|
expect(gen_str_are_equal (got, gen_txt("KEEPhello world\nworld!")), gen_txt("wrapper multiline text"));
|
||||||
|
gen_strbuilder_free(& output);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_wrapper_scope()
|
||||||
|
{
|
||||||
|
gen_StrBuilder then_output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
gen_StrBuilder else_output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
expect(gen_strbuilder_append_str(& then_output, gen_txt("KEEP")), gen_txt("wrapper then prefix"));
|
||||||
|
expect(gen_strbuilder_append_str(& else_output, gen_txt("KEEP")), gen_txt("wrapper else prefix"));
|
||||||
|
|
||||||
|
bool then_result = false;
|
||||||
|
bool else_result = false;
|
||||||
|
gen_s32 selector = 1;
|
||||||
|
gen_s32 after_branch = 0;
|
||||||
|
if (selector == 1)
|
||||||
|
gen_strtmpl_append(& then_output, then_result, gen_strtmpl_slots(gen_strtmpl_slot("arm", gen_txt("THEN"))),
|
||||||
|
gen_txt("<arm>")
|
||||||
|
);
|
||||||
|
else
|
||||||
|
gen_strtmpl_append(& else_output, else_result, gen_strtmpl_slots(gen_strtmpl_slot("arm", gen_txt("ELSE"))),
|
||||||
|
gen_txt("<arm>")
|
||||||
|
);
|
||||||
|
after_branch = 1;
|
||||||
|
expect(after_branch == 1, gen_txt("wrapper then continues"));
|
||||||
|
expect(then_result, gen_txt("wrapper then assigned"));
|
||||||
|
expect(else_result == false, gen_txt("wrapper else skipped"));
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(then_output), gen_txt("KEEPTHEN")), gen_txt("wrapper then text"));
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(else_output), gen_txt("KEEP")), gen_txt("wrapper else untouched"));
|
||||||
|
gen_strbuilder_free(& then_output);
|
||||||
|
gen_strbuilder_free(& else_output);
|
||||||
|
|
||||||
|
then_output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
else_output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
expect(gen_strbuilder_append_str(& then_output, gen_txt("KEEP")), gen_txt("wrapper skipped then prefix"));
|
||||||
|
expect(gen_strbuilder_append_str(& else_output, gen_txt("KEEP")), gen_txt("wrapper taken else prefix"));
|
||||||
|
|
||||||
|
then_result = false;
|
||||||
|
else_result = false;
|
||||||
|
selector = 0;
|
||||||
|
after_branch = 0;
|
||||||
|
if (selector == 1) gen_strtmpl_append(& then_output, then_result, gen_strtmpl_slots(gen_strtmpl_slot("arm", gen_txt("THEN"))), gen_txt("<arm>"));
|
||||||
|
else gen_strtmpl_append(& else_output, else_result, gen_strtmpl_slots(gen_strtmpl_slot("arm", gen_txt("ELSE"))), gen_txt("<arm>"));
|
||||||
|
after_branch = 1;
|
||||||
|
expect(after_branch == 1, gen_txt("wrapper else continues"));
|
||||||
|
expect(then_result == false, gen_txt("wrapper then skipped"));
|
||||||
|
expect(else_result, gen_txt("wrapper else assigned"));
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(then_output), gen_txt("KEEP")), gen_txt("wrapper then untouched"));
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(else_output), gen_txt("KEEPELSE")), gen_txt("wrapper else text"));
|
||||||
|
gen_strbuilder_free(& then_output);
|
||||||
|
gen_strbuilder_free(& else_output);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_wrapper_once() {
|
||||||
|
gen_s32 value_reads = 0;
|
||||||
|
gen_s32 format_reads = 0;
|
||||||
|
gen_s32 output_reads = 0;
|
||||||
|
gen_s32 result_reads = 0;
|
||||||
|
gen_StrBuilder output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
expect(gen_strbuilder_append_str(& output, gen_txt("KEEP")), gen_txt("wrapper once prefix"));
|
||||||
|
bool appended = false;
|
||||||
|
gen_strtmpl_append(
|
||||||
|
counted_template_output(& output, & output_reads),
|
||||||
|
counted_template_result(& appended, & result_reads)[0],
|
||||||
|
gen_strtmpl_slots(
|
||||||
|
gen_strtmpl_slot("k", counted_template_value(& value_reads)),
|
||||||
|
gen_strtmpl_slot("tail", gen_txt("Z"))
|
||||||
|
),
|
||||||
|
counted_template_format(& format_reads)
|
||||||
|
);
|
||||||
|
expect(appended, gen_txt("wrapper once result"));
|
||||||
|
expect(value_reads == 1, gen_txt("wrapper value once"));
|
||||||
|
expect(format_reads == 1, gen_txt("wrapper format once"));
|
||||||
|
expect(output_reads == 1, gen_txt("wrapper output once"));
|
||||||
|
expect(result_reads == 1, gen_txt("wrapper result once"));
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(output), gen_txt("KEEPONCE:ONCE")), gen_txt("wrapper once text"));
|
||||||
|
gen_strbuilder_free(& output);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_wrapper_resize_fail() {
|
||||||
|
gen_s32 attempts = 0;
|
||||||
|
gen_AllocatorInfo alloc = {0};
|
||||||
|
alloc.Proc = resize_fail_allocator_proc;
|
||||||
|
alloc.Data = & attempts;
|
||||||
|
gen_StrBuilder output = gen_strbuilder_make_reserve(alloc, 4);
|
||||||
|
expect(gen_strbuilder_capacity(output) == 4, gen_txt("wrapper resize capacity"));
|
||||||
|
expect(gen_strbuilder_append_str(& output, gen_txt("KEEP")), gen_txt("wrapper resize prefix"));
|
||||||
|
|
||||||
|
bool appended = true;
|
||||||
|
gen_strtmpl_append(& output, appended,
|
||||||
|
gen_strtmpl_slots(gen_strtmpl_slot("blob", gen_txt("X"))),
|
||||||
|
gen_txt("<blob>")
|
||||||
|
);
|
||||||
|
expect(appended == false, gen_txt("wrapper resize assigned false"));
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(output), gen_txt("KEEP")), gen_txt("wrapper resize keep"));
|
||||||
|
expect(attempts > 0, gen_txt("wrapper resize attempts"));
|
||||||
|
gen_strbuilder_free(& output);
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_template_slot_literal()
|
||||||
|
{
|
||||||
|
gen_Str value = gen_txt("V");
|
||||||
|
gen_StrTemplateSlot slot = gen_strtmpl_slot("k", value);
|
||||||
|
expect(gen_str_are_equal(slot.Key, gen_txt("k")), gen_txt("slot literal key slice"));
|
||||||
|
expect(slot.Key.Ptr[slot.Key.Len] == '\0', gen_txt("slot literal key terminator"));
|
||||||
|
expect(slot.Value.Ptr == value.Ptr, gen_txt("slot literal value pointer"));
|
||||||
|
expect(slot.Value.Len == value.Len, gen_txt("slot literal value length"));
|
||||||
|
|
||||||
|
gen_Str assigned = gen_txt("W");
|
||||||
|
slot = gen_strtmpl_slot("key", assigned);
|
||||||
|
expect(gen_str_are_equal(slot.Key, gen_txt("key")), gen_txt("slot assign key slice"));
|
||||||
|
expect(slot.Value.Ptr == assigned.Ptr, gen_txt("slot assign value pointer"));
|
||||||
|
expect(slot.Value.Len == assigned.Len, gen_txt("slot assign value length"));
|
||||||
|
expect_template_text(gen_txt("slot assign expansion"), gen_txt("<key>"), & slot, 1, gen_txt("W"));
|
||||||
|
|
||||||
|
gen_StrTemplateSlot row[2] = {
|
||||||
|
gen_strtmpl_slot("a", gen_txt("X")),
|
||||||
|
gen_strtmpl_slot("b", gen_txt("Y"))
|
||||||
|
};
|
||||||
|
expect(gen_str_are_equal(row[0].Value, gen_txt("X")), gen_txt("slot array value slice"));
|
||||||
|
expect(gen_str_are_equal(row[1].Key, gen_txt("b")), gen_txt("slot array key slice"));
|
||||||
|
expect_template_text(gen_txt("slot array entry"), gen_txt("<b><a>"), row, 2, gen_txt("YX"));
|
||||||
|
|
||||||
|
gen_StrBuilder output = gen_strbuilder_make_reserve(gen_heap(), 1);
|
||||||
|
expect(gen_strbuilder_append_str(& output, gen_txt("KEEP")), gen_txt("slot wrapper prefix"));
|
||||||
|
bool appended = false;
|
||||||
|
gen_strtmpl_append(& output, appended, gen_strtmpl_slots(
|
||||||
|
gen_strtmpl_slot("name", gen_txt("world")),
|
||||||
|
gen_strtmpl_slot("tail", gen_txt("!"))
|
||||||
|
),
|
||||||
|
gen_txt("<name><tail>")
|
||||||
|
);
|
||||||
|
expect(appended, gen_txt("slot wrapper result"));
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(output), gen_txt("KEEPworld!")), gen_txt("slot wrapper text"));
|
||||||
|
gen_strbuilder_free(& output);
|
||||||
|
|
||||||
|
gen_StrTemplateSlot long_key = gen_strtmpl_slot("operands[0]", gen_txt("eax"));
|
||||||
|
expect(gen_str_are_equal(long_key.Key, gen_txt("operands[0]")), gen_txt("slot literal key slice"));
|
||||||
|
expect(long_key.Key.Ptr[long_key.Key.Len] == '\0', gen_txt("slot literal key excludes nul"));
|
||||||
|
expect(gen_str_are_equal(long_key.Value, gen_txt("eax")), gen_txt("slot literal value slice"));
|
||||||
|
|
||||||
|
gen_s32 value_reads = 0;
|
||||||
|
gen_StrTemplateSlot once = gen_strtmpl_slot("k", counted_template_value(& value_reads));
|
||||||
|
expect(value_reads == 1, gen_txt("slot value once"));
|
||||||
|
expect(gen_str_are_equal(once.Value, gen_txt("ONCE")), gen_txt("slot value once text"));
|
||||||
|
expect(once.Key.Len == 1, gen_txt("slot value once key"));
|
||||||
|
|
||||||
|
char nul_bytes[4] = { 'a', '\0', 'b', '!' };
|
||||||
|
gen_Str nul_value = { nul_bytes, 3 };
|
||||||
|
gen_StrTemplateSlot nul_slot = gen_strtmpl_slot("n", nul_value);
|
||||||
|
expect(nul_slot.Value.Ptr == nul_bytes, gen_txt("slot nul pointer"));
|
||||||
|
expect(nul_slot.Value.Len == 3, gen_txt("slot nul length"));
|
||||||
|
expect(nul_slot.Value.Ptr[1] == '\0', gen_txt("slot nul byte"));
|
||||||
|
char nul_expected[5] = { '[', 'a', '\0', 'b', ']' };
|
||||||
|
gen_Str nul_expansion = { nul_expected, 5 };
|
||||||
|
expect_template_text(gen_txt("slot nul expansion"), gen_txt("[<n>]"), & nul_slot, 1, nul_expansion);
|
||||||
|
|
||||||
|
gen_Str angle_value = gen_txt("a<b>c");
|
||||||
|
gen_StrTemplateSlot angle_slot = gen_strtmpl_slot("raw", angle_value);
|
||||||
|
expect(angle_slot.Value.Ptr == angle_value.Ptr, gen_txt("slot angle pointer"));
|
||||||
|
expect(angle_slot.Value.Len == angle_value.Len, gen_txt("slot angle length"));
|
||||||
|
expect_template_text(gen_txt("slot angle expansion"), gen_txt("<raw>"), & angle_slot, 1, gen_txt("a<b>c"));
|
||||||
|
|
||||||
|
gen_Str empty_value = { 0, 0 };
|
||||||
|
gen_StrTemplateSlot empty_slot = gen_strtmpl_slot("e", empty_value);
|
||||||
|
expect(empty_slot.Value.Ptr == 0, gen_txt("slot null value pointer"));
|
||||||
|
expect(empty_slot.Value.Len == 0, gen_txt("slot null value length"));
|
||||||
|
expect_template_text(gen_txt("slot null value expansion"), gen_txt("A<e>B"), & empty_slot, 1, gen_txt("AB"));
|
||||||
|
|
||||||
|
gen_Str percent_value = gen_txt("%d:%S");
|
||||||
|
gen_StrTemplateSlot percent_slot = gen_strtmpl_slot("fmt", percent_value);
|
||||||
|
expect(percent_slot.Value.Ptr == percent_value.Ptr, gen_txt("slot percent value pointer"));
|
||||||
|
expect(gen_str_are_equal(percent_slot.Value, gen_txt("%d:%S")), gen_txt("slot percent value text"));
|
||||||
|
expect_template_text(gen_txt("slot percent literal"), gen_txt("pre %d:%S <fmt>"), & percent_slot, 1, gen_txt("pre %d:%S %d:%S"));
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_internal void expect_text_template(gen_ssize printf_maxlen) {
|
||||||
|
expect_template_shapes();
|
||||||
|
expect_template_lookup();
|
||||||
|
expect_template_crc_collision();
|
||||||
|
expect_template_boundaries();
|
||||||
|
expect_template_growth(printf_maxlen);
|
||||||
|
expect_template_resize_fail(printf_maxlen);
|
||||||
|
expect_template_slice();
|
||||||
|
expect_template_wrapper();
|
||||||
|
expect_template_wrapper_scope();
|
||||||
|
expect_template_wrapper_once();
|
||||||
|
expect_template_wrapper_resize_fail();
|
||||||
|
expect_template_slot_literal();
|
||||||
|
}
|
||||||
+563
-3
@@ -29,14 +29,24 @@ gen_internal void expect_variable(gen_CodeVar var, gen_Str label) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gen_internal gen_Code_POD code_pod(gen_Code code) {
|
gen_internal gen_Code_POD code_pod(gen_Code code) { gen_Code_POD result = { (gen_AST*)code }; return result; }
|
||||||
gen_Code_POD result = { (gen_AST*)code };
|
|
||||||
return result;
|
gen_internal void expect_parse_info(void* result, ParseInfo* info, gen_Str label) {
|
||||||
|
expect(result != 0, label);
|
||||||
|
void* info_result = info->result;
|
||||||
|
expect(info_result == result, label);
|
||||||
|
expect(info->lexed.tokens.num > 0, label);
|
||||||
|
expect(info->lexed.messages == 0 && info->messages == 0, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "dependencies/strings.c"
|
||||||
|
#include "dependencies/simd.c"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
gen_Context ctx = {0}; gen_init(&ctx);
|
gen_Context ctx = {0}; gen_init(&ctx);
|
||||||
|
expect_text_template(GEN_PRINTF_MAXLEN);
|
||||||
|
expect_simd_lanes();
|
||||||
|
|
||||||
gen_CodeTypename type = gen_def_type(name(char), .specifiers = gen_def_specifiers(2, Spec_Const, Spec_Ptr) );
|
gen_CodeTypename type = gen_def_type(name(char), .specifiers = gen_def_specifiers(2, Spec_Const, Spec_Ptr) );
|
||||||
gen_CodeVar upfront = gen_def_variable(type, name(baseline_message),
|
gen_CodeVar upfront = gen_def_variable(type, name(baseline_message),
|
||||||
@@ -482,6 +492,556 @@ int main()
|
|||||||
expect_variable(parsed, gen_txt("c11 parsed"));
|
expect_variable(parsed, gen_txt("c11 parsed"));
|
||||||
expect_fragments(gen_strbuilder_to_str(gen_code_to_strbuilder(parsed)), gen_txt("c11 parsed serialized"));
|
expect_fragments(gen_strbuilder_to_str(gen_code_to_strbuilder(parsed)), gen_txt("c11 parsed serialized"));
|
||||||
|
|
||||||
|
gen_CodeClass parser_class = gen_parse_class(gen_txt("class ParseClass {};"));
|
||||||
|
gen_CodeConstructor parser_constructor = gen_parse_constructor(gen_txt("ParseClass() {}"));
|
||||||
|
gen_CodeDefine parser_define = gen_parse_define(gen_txt("#define PARSE_DEFINE 1"));
|
||||||
|
gen_CodeDestructor parser_destructor = gen_parse_destructor(gen_txt("~ParseClass();"));
|
||||||
|
gen_CodeEnum parser_enum = gen_parse_enum(gen_txt("enum ParseEnum { ParseValue };"));
|
||||||
|
gen_CodeBody parser_export_body = gen_parse_export_body(gen_txt("{ int export_value; }"));
|
||||||
|
gen_CodeExtern parser_extern = gen_parse_extern_link(gen_txt("extern \"C\" { int extern_value; }"));
|
||||||
|
gen_CodeFriend parser_friend = gen_parse_friend(gen_txt("friend int parse_friend_function();"));
|
||||||
|
gen_CodeFn parser_function = gen_parse_function(gen_txt("int parse_function();"));
|
||||||
|
gen_CodeBody parser_global_body = gen_parse_global_body(gen_txt("struct ParseGlobal { int value; };"));
|
||||||
|
gen_CodeNS parser_namespace = gen_parse_namespace(gen_txt("namespace ParseNamespace {}"));
|
||||||
|
gen_CodeOperator parser_operator = gen_parse_operator(gen_txt("s32 operator +(s32 lhs, s32 rhs);"));
|
||||||
|
gen_CodeOpCast parser_operator_cast = gen_parse_operator_cast(gen_txt("operator s32() const;"));
|
||||||
|
gen_CodeStruct parser_struct = gen_parse_struct(gen_txt("struct ParseStruct {};"));
|
||||||
|
gen_CodeTemplate parser_template = gen_parse_template(gen_txt("template<class T> struct ParseTemplate {};"));
|
||||||
|
gen_CodeTypename parser_type = gen_parse_type(gen_txt("const s32*"));
|
||||||
|
gen_CodeTypedef parser_typedef = gen_parse_typedef(gen_txt("typedef s32 ParseTypedef;"));
|
||||||
|
gen_CodeUnion parser_union = gen_parse_union(gen_txt("union ParseUnion { s32 value; };"));
|
||||||
|
gen_CodeUsing parser_using = gen_parse_using(gen_txt("using ParseUsing = s32;"));
|
||||||
|
gen_CodeVar parser_variable = gen_parse_variable(gen_txt("s32 parse_variable;"));
|
||||||
|
|
||||||
|
expect(parser_class != 0 && parser_class->Type == CT_Class, gen_txt("c11 parse class fixture"));
|
||||||
|
expect(parser_constructor != 0 && parser_constructor->Type == CT_Constructor, gen_txt("c11 parse constructor fixture"));
|
||||||
|
expect(parser_define != 0 && parser_define->Type == CT_Preprocess_Define, gen_txt("c11 parse define fixture"));
|
||||||
|
expect(parser_destructor != 0 && parser_destructor->Type == CT_Destructor_Fwd, gen_txt("c11 parse destructor fixture"));
|
||||||
|
expect(parser_enum != 0 && parser_enum->Type == CT_Enum, gen_txt("c11 parse enum fixture"));
|
||||||
|
expect(parser_export_body != 0 && parser_export_body->Type == CT_Export_Body, gen_txt("c11 parse export body fixture"));
|
||||||
|
expect(parser_extern != 0 && parser_extern->Type == CT_Extern_Linkage, gen_txt("c11 parse extern fixture"));
|
||||||
|
expect(parser_friend != 0 && parser_friend->Type == CT_Friend, gen_txt("c11 parse friend fixture"));
|
||||||
|
expect(parser_function != 0 && parser_function->Type == CT_Function_Fwd, gen_txt("c11 parse function fixture"));
|
||||||
|
expect(parser_global_body != 0 && parser_global_body->Type == CT_Global_Body, gen_txt("c11 parse global body fixture"));
|
||||||
|
expect(parser_namespace != 0 && parser_namespace->Type == CT_Namespace, gen_txt("c11 parse namespace fixture"));
|
||||||
|
expect(parser_operator != 0 && parser_operator->Type == CT_Operator_Fwd, gen_txt("c11 parse operator fixture"));
|
||||||
|
expect(parser_operator_cast != 0 && parser_operator_cast->Type == CT_Operator_Cast_Fwd, gen_txt("c11 parse operator cast fixture"));
|
||||||
|
expect(parser_struct != 0 && parser_struct->Type == CT_Struct, gen_txt("c11 parse struct fixture"));
|
||||||
|
expect(parser_template != 0 && parser_template->Type == CT_Template, gen_txt("c11 parse template fixture"));
|
||||||
|
expect(parser_type != 0 && parser_type->Type == CT_Typename, gen_txt("c11 parse type fixture"));
|
||||||
|
expect(parser_typedef != 0 && parser_typedef->Type == CT_Typedef, gen_txt("c11 parse typedef fixture"));
|
||||||
|
expect(parser_union != 0 && parser_union->Type == CT_Union, gen_txt("c11 parse union fixture"));
|
||||||
|
expect(parser_using != 0 && parser_using->Type == CT_Using, gen_txt("c11 parse using fixture"));
|
||||||
|
expect(parser_variable != 0 && parser_variable->Type == CT_Variable, gen_txt("c11 parse variable fixture"));
|
||||||
|
|
||||||
|
gen_CodeBody parsed_global_options = gen_parse_global_body(gen_txt("struct ParseGlobalOptions { s32 value; };"));
|
||||||
|
expect(parsed_global_options != 0, gen_txt("c11 default parse global body options"));
|
||||||
|
void* default_result = parsed_global_options;
|
||||||
|
void* default_info_result = ctx.gen_parse_info.result;
|
||||||
|
expect(default_info_result == default_result, gen_txt("c11 default parse info result"));
|
||||||
|
expect(ctx.gen_parse_info.lexed.tokens.num > 0, gen_txt("c11 default parse info tokens"));
|
||||||
|
expect(ctx.gen_parse_info.lexed.messages == 0 && ctx.gen_parse_info.messages == 0, gen_txt("c11 default parse info messages"));
|
||||||
|
|
||||||
|
ParseInfo caller_info = {0};
|
||||||
|
gen_CodeBody parsed_explicit_global = gen_parse_global_body(gen_txt("struct ParseExplicitOptions { s32 value; };"), .ctx = & ctx, .info = & caller_info);
|
||||||
|
expect(parsed_explicit_global != 0, gen_txt("c11 explicit parse global body options"));
|
||||||
|
void* explicit_result = parsed_explicit_global;
|
||||||
|
void* explicit_info_result = caller_info.result;
|
||||||
|
expect(explicit_info_result == explicit_result, gen_txt("c11 explicit parse info result"));
|
||||||
|
expect(caller_info.lexed.tokens.num > 0, gen_txt("c11 explicit parse info tokens"));
|
||||||
|
|
||||||
|
ParseInfo variable_info = {0};
|
||||||
|
gen_CodeVar parsed_option_variable = gen_parse_variable(gen_txt("s32 parsed_option_variable;"), .ctx = & ctx, .info = & variable_info);
|
||||||
|
expect(parsed_option_variable != 0 && parsed_option_variable->Type == CT_Variable, gen_txt("c11 explicit parse variable options"));
|
||||||
|
expect(gen_str_contains(parsed_option_variable->Name, gen_txt("parsed_option_variable")), gen_txt("c11 explicit parse variable name"));
|
||||||
|
void* variable_result = parsed_option_variable;
|
||||||
|
void* variable_info_result = variable_info.result;
|
||||||
|
expect(variable_info_result == variable_result, gen_txt("c11 explicit parse variable info result"));
|
||||||
|
|
||||||
|
ParseInfo lexer_info = {0};
|
||||||
|
gen_CodeVar parsed_lexer_prefix = gen_parse_variable(gen_txt("s32 parsed_lexer_prefix;@"), .ctx = & ctx, .info = & lexer_info);
|
||||||
|
expect(parsed_lexer_prefix != 0 && parsed_lexer_prefix->Type == CT_Variable, gen_txt("c11 parse lexer prefix result"));
|
||||||
|
void* lexer_result = parsed_lexer_prefix;
|
||||||
|
void* lexer_info_result = lexer_info.result;
|
||||||
|
expect(lexer_info_result == lexer_result, gen_txt("c11 parse lexer prefix info result"));
|
||||||
|
expect(lexer_info.lexed.tokens.num > 0, gen_txt("c11 parse lexer prefix retained tokens"));
|
||||||
|
expect(lexer_info.lexed.messages != 0, gen_txt("c11 parse lexer prefix diagnostic"));
|
||||||
|
|
||||||
|
ParseInfo matrix_info = {0};
|
||||||
|
gen_Opts_parse_global_body legacy_parse_options = { .ctx = & ctx, .info = & matrix_info };
|
||||||
|
gen_CodeBody matrix_global_body = gen_parse_global_body(gen_txt("struct ParseGlobal { int value; };"), .ctx = legacy_parse_options.ctx, .info = legacy_parse_options.info);
|
||||||
|
expect(matrix_global_body != 0 && matrix_global_body->Type == CT_Global_Body, gen_txt("c11 global body options matrix"));
|
||||||
|
expect_parse_info(matrix_global_body, & matrix_info, gen_txt("c11 global body ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeClass matrix_class = gen_parse_class(gen_txt("class ParseClass {};"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_class != 0 && matrix_class->Type == CT_Class, gen_txt("c11 class options matrix"));
|
||||||
|
expect_parse_info(matrix_class, & matrix_info, gen_txt("c11 class ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeConstructor matrix_constructor = gen_parse_constructor(gen_txt("ParseClass() {}"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_constructor != 0 && matrix_constructor->Type == CT_Constructor, gen_txt("c11 constructor options matrix"));
|
||||||
|
expect_parse_info(matrix_constructor, & matrix_info, gen_txt("c11 constructor ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeDefine matrix_define = gen_parse_define(gen_txt("#define PARSE_DEFINE 1"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_define != 0 && matrix_define->Type == CT_Preprocess_Define, gen_txt("c11 define options matrix"));
|
||||||
|
expect_parse_info(matrix_define, & matrix_info, gen_txt("c11 define ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeDestructor matrix_destructor = gen_parse_destructor(gen_txt("~ParseClass();"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_destructor != 0 && matrix_destructor->Type == CT_Destructor_Fwd, gen_txt("c11 destructor options matrix"));
|
||||||
|
expect_parse_info(matrix_destructor, & matrix_info, gen_txt("c11 destructor ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeEnum matrix_enum = gen_parse_enum(gen_txt("enum ParseEnum { ParseValue };"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_enum != 0 && matrix_enum->Type == CT_Enum, gen_txt("c11 enum options matrix"));
|
||||||
|
expect_parse_info(matrix_enum, & matrix_info, gen_txt("c11 enum ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeBody matrix_export_body = gen_parse_export_body(gen_txt("{ int export_value; }"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_export_body != 0 && matrix_export_body->Type == CT_Export_Body, gen_txt("c11 export body options matrix"));
|
||||||
|
expect_parse_info(matrix_export_body, & matrix_info, gen_txt("c11 export body ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeExtern matrix_extern = gen_parse_extern_link(gen_txt("extern \"C\" { int extern_value; }"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_extern != 0 && matrix_extern->Type == CT_Extern_Linkage, gen_txt("c11 extern options matrix"));
|
||||||
|
expect_parse_info(matrix_extern, & matrix_info, gen_txt("c11 extern ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeFriend matrix_friend = gen_parse_friend(gen_txt("friend int parse_friend_function();"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_friend != 0 && matrix_friend->Type == CT_Friend, gen_txt("c11 friend options matrix"));
|
||||||
|
expect_parse_info(matrix_friend, & matrix_info, gen_txt("c11 friend ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeFn matrix_function = gen_parse_function(gen_txt("int parse_function();"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_function != 0 && matrix_function->Type == CT_Function_Fwd, gen_txt("c11 function options matrix"));
|
||||||
|
expect_parse_info(matrix_function, & matrix_info, gen_txt("c11 function ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeNS matrix_namespace = gen_parse_namespace(gen_txt("namespace ParseNamespace {}"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_namespace != 0 && matrix_namespace->Type == CT_Namespace, gen_txt("c11 namespace options matrix"));
|
||||||
|
expect_parse_info(matrix_namespace, & matrix_info, gen_txt("c11 namespace ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeOperator matrix_operator = gen_parse_operator(gen_txt("s32 operator +(s32 lhs, s32 rhs);"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_operator != 0 && matrix_operator->Type == CT_Operator_Fwd, gen_txt("c11 operator options matrix"));
|
||||||
|
expect_parse_info(matrix_operator, & matrix_info, gen_txt("c11 operator ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeOpCast matrix_operator_cast = gen_parse_operator_cast(gen_txt("operator s32() const;"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_operator_cast != 0 && matrix_operator_cast->Type == CT_Operator_Cast_Fwd, gen_txt("c11 operator cast options matrix"));
|
||||||
|
expect_parse_info(matrix_operator_cast, & matrix_info, gen_txt("c11 operator cast ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeStruct matrix_struct = gen_parse_struct(gen_txt("struct ParseStruct {};"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_struct != 0 && matrix_struct->Type == CT_Struct, gen_txt("c11 struct options matrix"));
|
||||||
|
expect_parse_info(matrix_struct, & matrix_info, gen_txt("c11 struct ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeTemplate matrix_template = gen_parse_template(gen_txt("template<class T> struct ParseTemplate {};"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_template != 0 && matrix_template->Type == CT_Template, gen_txt("c11 template options matrix"));
|
||||||
|
expect_parse_info(matrix_template, & matrix_info, gen_txt("c11 template ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeTypename matrix_type = gen_parse_type(gen_txt("const s32*"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_type != 0 && matrix_type->Type == CT_Typename, gen_txt("c11 type options matrix"));
|
||||||
|
expect_parse_info(matrix_type, & matrix_info, gen_txt("c11 type ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeTypedef matrix_typedef = gen_parse_typedef(gen_txt("typedef s32 ParseTypedef;"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_typedef != 0 && matrix_typedef->Type == CT_Typedef, gen_txt("c11 typedef options matrix"));
|
||||||
|
expect_parse_info(matrix_typedef, & matrix_info, gen_txt("c11 typedef ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeUnion matrix_union = gen_parse_union(gen_txt("union ParseUnion { s32 value; };"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_union != 0 && matrix_union->Type == CT_Union, gen_txt("c11 union options matrix"));
|
||||||
|
expect_parse_info(matrix_union, & matrix_info, gen_txt("c11 union ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeUsing matrix_using = gen_parse_using(gen_txt("using ParseUsing = s32;"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_using != 0 && matrix_using->Type == CT_Using, gen_txt("c11 using options matrix"));
|
||||||
|
expect_parse_info(matrix_using, & matrix_info, gen_txt("c11 using ParseInfo matrix"));
|
||||||
|
|
||||||
|
gen_CodeVar matrix_variable = gen_parse_variable(gen_txt("s32 parse_variable;"), .ctx = & ctx, .info = & matrix_info);
|
||||||
|
expect(matrix_variable != 0 && matrix_variable->Type == CT_Variable, gen_txt("c11 variable options matrix"));
|
||||||
|
expect_parse_info(matrix_variable, & matrix_info, gen_txt("c11 variable ParseInfo matrix"));
|
||||||
|
|
||||||
|
ParseInfo comma_info = {0};
|
||||||
|
gen_CodeBody parsed_comma_body = gen_parse_global_body(gen_txt("struct ParseComma { s32 value; };\n,"), .ctx = & ctx, .info = & comma_info);
|
||||||
|
expect(parsed_comma_body != 0 && parsed_comma_body->Type == CT_Global_Body, gen_txt("c11 comma parser result"));
|
||||||
|
void* comma_result = parsed_comma_body;
|
||||||
|
void* comma_info_result = comma_info.result;
|
||||||
|
expect(comma_info_result == comma_result, gen_txt("c11 comma ParseInfo result"));
|
||||||
|
expect(comma_info.lexed.tokens.num > 0 && comma_info.lexed.messages == 0, gen_txt("c11 comma retained tokens"));
|
||||||
|
expect(comma_info.messages != 0, gen_txt("c11 comma parser diagnostic"));
|
||||||
|
if (comma_info.messages != 0)
|
||||||
|
expect(gen_str_contains(comma_info.messages->Content, gen_txt("Dangling comma")), gen_txt("c11 comma diagnostic content"));
|
||||||
|
|
||||||
|
ParseInfo recovery_info = {0};
|
||||||
|
gen_CodeBody recovered_body = gen_parse_global_body(gen_txt("s32 before; s32 broken(s32 value; s32 after;"), .ctx = &ctx, .info = &recovery_info);
|
||||||
|
gen_Str recovery_text = {0};
|
||||||
|
if (recovered_body != 0) recovery_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)recovered_body));
|
||||||
|
expect(recovered_body != 0 && recovered_body->Type == CT_Global_Body, gen_txt("c11 file-scope recovery body"));
|
||||||
|
|
||||||
|
void* recovered_result = recovered_body;
|
||||||
|
expect(recovery_info.result == recovered_result, gen_txt("c11 file-scope recovery ParseInfo result"));
|
||||||
|
expect(recovery_info.messages != 0, gen_txt("c11 file-scope recovery diagnostic"));
|
||||||
|
if (recovery_info.messages != 0) {
|
||||||
|
expect(gen_str_contains(recovery_info.messages->Content, gen_txt("Expected")), gen_txt("c11 file-scope recovery mismatch text"));
|
||||||
|
expect(recovery_info.messages->Next == 0, gen_txt("c11 file-scope recovery single diagnostic"));
|
||||||
|
}
|
||||||
|
expect(gen_str_contains(recovery_text, gen_txt("before")), gen_txt("c11 file-scope recovery keeps preceding member"));
|
||||||
|
expect(gen_str_contains(recovery_text, gen_txt("after")), gen_txt("c11 file-scope recovery keeps following member"));
|
||||||
|
gen_Code recovered_member = 0;
|
||||||
|
if (recovered_body != 0) recovered_member = recovered_body->Front;
|
||||||
|
gen_Code recovered_before = recovered_member;
|
||||||
|
expect(recovered_before != 0 && recovered_before->Type == CT_Variable, gen_txt("c11 mismatch recovery keeps preceding member typed"));
|
||||||
|
if (recovered_before != 0)
|
||||||
|
expect(gen_str_are_equal(recovered_before->Name, gen_txt("before")), gen_txt("c11 mismatch recovery preceding member name"));
|
||||||
|
if (recovered_member != 0) recovered_member = recovered_member->Next;
|
||||||
|
expect(recovered_member != 0 && recovered_member->Type == CT_Untyped, gen_txt("c11 file-scope recovery stores malformed member as untyped"));
|
||||||
|
if (recovered_member != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(recovered_member)), gen_txt("s32 broken(s32 value;")), gen_txt("c11 file-scope recovery retains exact mismatch span"));
|
||||||
|
gen_Code recovered_after = recovered_member != 0 ? recovered_member->Next : 0;
|
||||||
|
expect(recovered_after != 0 && recovered_after->Type == CT_Variable, gen_txt("c11 file-scope recovery keeps following member typed"));
|
||||||
|
if (recovered_after != 0)
|
||||||
|
expect(gen_str_are_equal(recovered_after->Name, gen_txt("after")), gen_txt("c11 file-scope recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo invalid_member_info = {0};
|
||||||
|
gen_CodeBody invalid_member_body = gen_parse_global_body(gen_txt("s32 before; = { 1; 2 }; s32 after;"), .ctx = &ctx, .info = &invalid_member_info);
|
||||||
|
gen_Str invalid_member_text = {0};
|
||||||
|
if (invalid_member_body != 0)
|
||||||
|
invalid_member_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)invalid_member_body));
|
||||||
|
expect(invalid_member_body != 0 && invalid_member_body->Type == CT_Global_Body, gen_txt("c11 invalid member recovery body"));
|
||||||
|
void* invalid_member_result = invalid_member_body;
|
||||||
|
expect(invalid_member_info.result == invalid_member_result, gen_txt("c11 invalid member recovery ParseInfo result"));
|
||||||
|
expect(invalid_member_info.messages != 0, gen_txt("c11 invalid member recovery diagnostic"));
|
||||||
|
if (invalid_member_info.messages != 0) {
|
||||||
|
expect(gen_str_contains(invalid_member_info.messages->Content, gen_txt("Failed to parse member")), gen_txt("c11 invalid member recovery diagnostic text"));
|
||||||
|
expect(invalid_member_info.messages->Next == 0, gen_txt("c11 invalid member recovery single diagnostic"));
|
||||||
|
}
|
||||||
|
expect(gen_str_contains(invalid_member_text, gen_txt("before")), gen_txt("c11 invalid member recovery keeps preceding member"));
|
||||||
|
expect(gen_str_contains(invalid_member_text, gen_txt("after")), gen_txt("c11 invalid member recovery keeps following member"));
|
||||||
|
gen_Code invalid_member_node = 0;
|
||||||
|
if (invalid_member_body != 0) invalid_member_node = invalid_member_body->Front;
|
||||||
|
gen_Code invalid_member_before = invalid_member_node;
|
||||||
|
expect(invalid_member_before != 0 && invalid_member_before->Type == CT_Variable, gen_txt("c11 invalid member keeps preceding member typed"));
|
||||||
|
if (invalid_member_before != 0)
|
||||||
|
expect(gen_str_are_equal(invalid_member_before->Name, gen_txt("before")), gen_txt("c11 invalid member preceding member name"));
|
||||||
|
if (invalid_member_node != 0) invalid_member_node = invalid_member_node->Next;
|
||||||
|
expect(invalid_member_node != 0 && invalid_member_node->Type == CT_Untyped, gen_txt("c11 invalid member recovery stores member as untyped"));
|
||||||
|
if (invalid_member_node != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(invalid_member_node)), gen_txt("= { 1; 2 };")), gen_txt("c11 invalid member recovery retains exact source span"));
|
||||||
|
gen_Code invalid_member_after = invalid_member_node != 0 ? invalid_member_node->Next : 0;
|
||||||
|
expect(invalid_member_after != 0 && invalid_member_after->Type == CT_Variable, gen_txt("c11 invalid member recovery keeps following member typed"));
|
||||||
|
if (invalid_member_after != 0)
|
||||||
|
expect(gen_str_are_equal(invalid_member_after->Name, gen_txt("after")), gen_txt("c11 invalid member recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo import_recovery_info = {0};
|
||||||
|
gen_Opts_parse import_recovery_options = { .ctx = &ctx, .info = &import_recovery_info };
|
||||||
|
gen_CodeBody import_recovery_body = gen_parse_global_body(gen_txt("s32 before; import foo; s32 after;"), .ctx = import_recovery_options.ctx, .info = import_recovery_options.info);
|
||||||
|
gen_Code import_recovery_node = 0;
|
||||||
|
if (import_recovery_body != 0) import_recovery_node = import_recovery_body->Front;
|
||||||
|
gen_Code import_recovery_before = import_recovery_node;
|
||||||
|
expect(import_recovery_before != 0 && import_recovery_before->Type == CT_Variable, gen_txt("c11 import recovery keeps preceding member typed"));
|
||||||
|
if (import_recovery_before != 0)
|
||||||
|
expect(gen_str_are_equal(import_recovery_before->Name, gen_txt("before")), gen_txt("c11 import recovery preceding member name"));
|
||||||
|
if (import_recovery_node != 0) import_recovery_node = import_recovery_node->Next;
|
||||||
|
expect(import_recovery_body != 0 && import_recovery_body->Type == CT_Global_Body, gen_txt("c11 import recovery body"));
|
||||||
|
expect(import_recovery_info.messages != 0, gen_txt("c11 import recovery diagnostic"));
|
||||||
|
if (import_recovery_info.messages != 0)
|
||||||
|
expect(import_recovery_info.messages->Next == 0, gen_txt("c11 import recovery single diagnostic"));
|
||||||
|
expect(import_recovery_node != 0 && import_recovery_node->Type == CT_Untyped, gen_txt("c11 import recovery preserves member as untyped"));
|
||||||
|
if (import_recovery_node != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(import_recovery_node)), gen_txt("import foo;")), gen_txt("c11 import recovery exact source span"));
|
||||||
|
gen_Code import_recovery_after = import_recovery_node != 0 ? import_recovery_node->Next : 0;
|
||||||
|
expect(import_recovery_after != 0 && import_recovery_after->Type == CT_Variable, gen_txt("c11 import recovery keeps following member typed"));
|
||||||
|
if (import_recovery_after != 0)
|
||||||
|
expect(gen_str_are_equal(import_recovery_after->Name, gen_txt("after")), gen_txt("c11 import recovery following member name"));
|
||||||
|
|
||||||
|
gen_Macro unbounded_macro = { gen_txt("UnboundedRecoveryMacro"), MT_Expression, MF_Null };
|
||||||
|
gen_register_macro(unbounded_macro);
|
||||||
|
ParseInfo macro_recovery_info = {0};
|
||||||
|
gen_Opts_parse macro_recovery_options = { .ctx = &ctx, .info = ¯o_recovery_info };
|
||||||
|
gen_CodeBody macro_recovery_body = gen_parse_global_body(gen_txt("s32 before; UnboundedRecoveryMacro; s32 after;"), .ctx = macro_recovery_options.ctx, .info = macro_recovery_options.info);
|
||||||
|
gen_Code macro_recovery_node = 0;
|
||||||
|
if (macro_recovery_body != 0) macro_recovery_node = macro_recovery_body->Front;
|
||||||
|
gen_Code macro_recovery_before = macro_recovery_node;
|
||||||
|
expect(macro_recovery_before != 0 && macro_recovery_before->Type == CT_Variable, gen_txt("c11 macro recovery keeps preceding member typed"));
|
||||||
|
if (macro_recovery_before != 0)
|
||||||
|
expect(gen_str_are_equal(macro_recovery_before->Name, gen_txt("before")), gen_txt("c11 macro recovery preceding member name"));
|
||||||
|
if (macro_recovery_node != 0) macro_recovery_node = macro_recovery_node->Next;
|
||||||
|
expect(macro_recovery_body != 0 && macro_recovery_body->Type == CT_Global_Body, gen_txt("c11 unbounded macro recovery body"));
|
||||||
|
expect(macro_recovery_info.messages != 0, gen_txt("c11 unbounded macro recovery diagnostic"));
|
||||||
|
if (macro_recovery_info.messages != 0)
|
||||||
|
expect(macro_recovery_info.messages->Next == 0, gen_txt("c11 unbounded macro recovery single diagnostic"));
|
||||||
|
expect(macro_recovery_node != 0 && macro_recovery_node->Type == CT_Untyped, gen_txt("c11 unbounded macro recovery preserves member as untyped"));
|
||||||
|
if (macro_recovery_node != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(macro_recovery_node)), gen_txt("UnboundedRecoveryMacro;")), gen_txt("c11 unbounded macro recovery exact source span"));
|
||||||
|
gen_Code macro_recovery_after = macro_recovery_node != 0 ? macro_recovery_node->Next : 0;
|
||||||
|
expect(macro_recovery_after != 0 && macro_recovery_after->Type == CT_Variable, gen_txt("c11 unbounded macro recovery keeps following member typed"));
|
||||||
|
if (macro_recovery_after != 0)
|
||||||
|
expect(gen_str_are_equal(macro_recovery_after->Name, gen_txt("after")), gen_txt("c11 unbounded macro recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo eof_recovery_info = {0};
|
||||||
|
gen_CodeBody eof_recovery_body = gen_parse_global_body(gen_txt("s32 before; s32 broken(s32 value"), .ctx = &ctx, .info = &eof_recovery_info);
|
||||||
|
gen_Code eof_recovery_node = 0;
|
||||||
|
if (eof_recovery_body != 0) eof_recovery_node = eof_recovery_body->Front;
|
||||||
|
gen_Code eof_recovery_before = eof_recovery_node;
|
||||||
|
expect(eof_recovery_before != 0 && eof_recovery_before->Type == CT_Variable, gen_txt("c11 EOF recovery keeps preceding member typed"));
|
||||||
|
if (eof_recovery_before != 0)
|
||||||
|
expect(gen_str_are_equal(eof_recovery_before->Name, gen_txt("before")), gen_txt("c11 EOF recovery preceding member name"));
|
||||||
|
if (eof_recovery_node != 0) eof_recovery_node = eof_recovery_node->Next;
|
||||||
|
expect(eof_recovery_body != 0 && eof_recovery_body->Type == CT_Global_Body, gen_txt("c11 end-of-slice recovery body"));
|
||||||
|
expect(eof_recovery_info.messages != 0, gen_txt("c11 end-of-slice recovery diagnostic"));
|
||||||
|
if (eof_recovery_info.messages != 0)
|
||||||
|
expect(eof_recovery_info.messages->Next == 0, gen_txt("c11 end-of-slice recovery single diagnostic"));
|
||||||
|
expect(eof_recovery_node != 0 && eof_recovery_node->Type == CT_Untyped, gen_txt("c11 end-of-slice member is untyped"));
|
||||||
|
if (eof_recovery_node != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(eof_recovery_node)), gen_txt("s32 broken(s32 value")), gen_txt("c11 end-of-slice recovery exact source span"));
|
||||||
|
if (eof_recovery_node != 0)
|
||||||
|
expect(eof_recovery_node->Next == 0, gen_txt("c11 end-of-slice recovery has no following node"));
|
||||||
|
|
||||||
|
ParseInfo comma_recovery_info = {0};
|
||||||
|
gen_CodeBody comma_recovery_body = gen_parse_global_body(gen_txt("s32 before; , s32 after;"), .ctx = &ctx, .info = &comma_recovery_info);
|
||||||
|
gen_Code comma_recovery_node = 0;
|
||||||
|
if (comma_recovery_body != 0) comma_recovery_node = comma_recovery_body->Front;
|
||||||
|
gen_Code comma_recovery_before = comma_recovery_node;
|
||||||
|
expect(comma_recovery_before != 0 && comma_recovery_before->Type == CT_Variable, gen_txt("c11 comma recovery keeps preceding member typed"));
|
||||||
|
if (comma_recovery_before != 0)
|
||||||
|
expect(gen_str_are_equal(comma_recovery_before->Name, gen_txt("before")), gen_txt("c11 comma recovery preceding member name"));
|
||||||
|
if (comma_recovery_node != 0) comma_recovery_node = comma_recovery_node->Next;
|
||||||
|
expect(comma_recovery_body != 0 && comma_recovery_body->Type == CT_Global_Body, gen_txt("c11 comma recovery body"));
|
||||||
|
expect(comma_recovery_info.messages != 0, gen_txt("c11 comma recovery diagnostic"));
|
||||||
|
if (comma_recovery_info.messages != 0) {
|
||||||
|
expect(gen_str_contains(comma_recovery_info.messages->Content, gen_txt("Dangling comma")), gen_txt("c11 comma recovery diagnostic text"));
|
||||||
|
expect(comma_recovery_info.messages->Next == 0, gen_txt("c11 comma recovery single diagnostic"));
|
||||||
|
}
|
||||||
|
expect(comma_recovery_node != 0 && comma_recovery_node->Type == CT_Untyped, gen_txt("c11 comma recovery preserves token as untyped"));
|
||||||
|
if (comma_recovery_node != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(comma_recovery_node)), gen_txt(",")), gen_txt("c11 comma recovery exact source span"));
|
||||||
|
gen_Code comma_recovery_after = comma_recovery_node != 0 ? comma_recovery_node->Next : 0;
|
||||||
|
expect(comma_recovery_after != 0 && comma_recovery_after->Type == CT_Variable, gen_txt("c11 comma recovery keeps following member typed"));
|
||||||
|
if (comma_recovery_after != 0)
|
||||||
|
expect(gen_str_are_equal(comma_recovery_after->Name, gen_txt("after")), gen_txt("c11 comma recovery following member name"));
|
||||||
|
|
||||||
|
gen_CodeBody recovery_reuse = gen_parse_global_body(gen_txt("s32 reused_after_recovery;"), .ctx = &ctx, .info = &recovery_info);
|
||||||
|
gen_Str recovery_reuse_text = {0};
|
||||||
|
if (recovery_reuse != 0)
|
||||||
|
recovery_reuse_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)recovery_reuse));
|
||||||
|
expect(recovery_reuse != 0 && recovery_reuse->Type == CT_Global_Body, gen_txt("c11 parser context reuse after recovery"));
|
||||||
|
expect(recovery_info.messages == 0, gen_txt("c11 parser context reuse clears prior diagnostics"));
|
||||||
|
expect(gen_str_contains(recovery_reuse_text, gen_txt("reused_after_recovery")), gen_txt("c11 parser context reuse parses later input"));
|
||||||
|
|
||||||
|
ParseInfo nested_struct_info = {0};
|
||||||
|
gen_Opts_parse nested_struct_options = { .ctx = &ctx, .info = &nested_struct_info };
|
||||||
|
gen_CodeStruct nested_struct = gen_parse_struct(gen_txt("struct NestedRecovery { s32 before; s32 broken(s32 value; s32 after; };"), .ctx = nested_struct_options.ctx, .info = nested_struct_options.info);
|
||||||
|
expect(nested_struct != 0 && nested_struct->Type == CT_Struct, gen_txt("c11 nested struct recovery result"));
|
||||||
|
void* nested_struct_result = nested_struct;
|
||||||
|
void* nested_struct_info_result = nested_struct_info.result;
|
||||||
|
expect(nested_struct_info_result == nested_struct_result, gen_txt("c11 nested struct recovery ParseInfo result"));
|
||||||
|
expect(nested_struct_info.messages != 0, gen_txt("c11 nested struct recovery diagnostic"));
|
||||||
|
if (nested_struct_info.messages != 0)
|
||||||
|
expect(gen_str_contains(nested_struct_info.messages->Content, gen_txt("Expected")), gen_txt("c11 nested struct recovery diagnostic text"));
|
||||||
|
gen_Code nested_struct_member = nested_struct != 0 && nested_struct->Body != 0 ? nested_struct->Body->Front : 0;
|
||||||
|
expect(nested_struct_member != 0 && nested_struct_member->Type == CT_Variable, gen_txt("c11 nested struct recovery keeps preceding member typed"));
|
||||||
|
if (nested_struct_member != 0)
|
||||||
|
expect(gen_str_are_equal(nested_struct_member->Name, gen_txt("before")), gen_txt("c11 nested struct recovery preceding member name"));
|
||||||
|
if (nested_struct_member != 0) nested_struct_member = nested_struct_member->Next;
|
||||||
|
expect(nested_struct_member != 0 && nested_struct_member->Type == CT_Untyped, gen_txt("c11 nested struct recovery retains failed member"));
|
||||||
|
if (nested_struct_member != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(nested_struct_member)), gen_txt("s32 broken(s32 value;")), gen_txt("c11 nested struct recovery exact failed span"));
|
||||||
|
gen_Code nested_struct_after = nested_struct_member != 0 ? nested_struct_member->Next : 0;
|
||||||
|
expect(nested_struct_after != 0 && nested_struct_after->Type == CT_Variable, gen_txt("c11 nested struct recovery keeps following member typed"));
|
||||||
|
if (nested_struct_after != 0)
|
||||||
|
expect(gen_str_are_equal(nested_struct_after->Name, gen_txt("after")), gen_txt("c11 nested struct recovery following member name"));
|
||||||
|
gen_Str nested_struct_text = {0};
|
||||||
|
if (nested_struct != 0)
|
||||||
|
nested_struct_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)nested_struct));
|
||||||
|
expect(gen_str_contains(nested_struct_text, gen_txt("s32 after")), gen_txt("c11 nested struct recovery serializes following member"));
|
||||||
|
|
||||||
|
ParseInfo nested_namespace_info = {0};
|
||||||
|
gen_Opts_parse nested_namespace_options = { .ctx = &ctx, .info = &nested_namespace_info };
|
||||||
|
gen_CodeNS nested_namespace = gen_parse_namespace(gen_txt("namespace NestedRecovery { s32 before; s32 broken(s32 value; s32 after; }"), .ctx = nested_namespace_options.ctx, .info = nested_namespace_options.info);
|
||||||
|
expect(nested_namespace != 0 && nested_namespace->Type == CT_Namespace, gen_txt("c11 nested namespace recovery result"));
|
||||||
|
void* nested_namespace_result = nested_namespace;
|
||||||
|
void* nested_namespace_info_result = nested_namespace_info.result;
|
||||||
|
expect(nested_namespace_info_result == nested_namespace_result, gen_txt("c11 nested namespace recovery ParseInfo result"));
|
||||||
|
expect(nested_namespace_info.messages != 0, gen_txt("c11 nested namespace recovery diagnostic"));
|
||||||
|
if (nested_namespace_info.messages != 0)
|
||||||
|
expect(gen_str_contains(nested_namespace_info.messages->Content, gen_txt("Expected")), gen_txt("c11 nested namespace recovery diagnostic text"));
|
||||||
|
gen_Code nested_namespace_member = nested_namespace != 0 && nested_namespace->Body != 0 ? nested_namespace->Body->Front : 0;
|
||||||
|
expect(nested_namespace_member != 0 && nested_namespace_member->Type == CT_Variable, gen_txt("c11 nested namespace recovery keeps preceding member typed"));
|
||||||
|
if (nested_namespace_member != 0)
|
||||||
|
expect(gen_str_are_equal(nested_namespace_member->Name, gen_txt("before")), gen_txt("c11 nested namespace recovery preceding member name"));
|
||||||
|
if (nested_namespace_member != 0) nested_namespace_member = nested_namespace_member->Next;
|
||||||
|
expect(nested_namespace_member != 0 && nested_namespace_member->Type == CT_Untyped, gen_txt("c11 nested namespace recovery retains failed member"));
|
||||||
|
if (nested_namespace_member != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(nested_namespace_member)), gen_txt("s32 broken(s32 value;")), gen_txt("c11 nested namespace recovery exact failed span"));
|
||||||
|
gen_Code nested_namespace_after = nested_namespace_member != 0 ? nested_namespace_member->Next : 0;
|
||||||
|
expect(nested_namespace_after != 0 && nested_namespace_after->Type == CT_Variable, gen_txt("c11 nested namespace recovery keeps following member typed"));
|
||||||
|
if (nested_namespace_after != 0)
|
||||||
|
expect(gen_str_are_equal(nested_namespace_after->Name, gen_txt("after")), gen_txt("c11 nested namespace recovery following member name"));
|
||||||
|
gen_Str nested_namespace_text = {0};
|
||||||
|
if (nested_namespace != 0)
|
||||||
|
nested_namespace_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)nested_namespace));
|
||||||
|
expect(gen_str_contains(nested_namespace_text, gen_txt("s32 after")), gen_txt("c11 nested namespace recovery serializes following member"));
|
||||||
|
|
||||||
|
ParseInfo nested_brace_info = {0};
|
||||||
|
gen_Opts_parse nested_brace_options = { .ctx = &ctx, .info = &nested_brace_info };
|
||||||
|
gen_CodeStruct nested_brace_struct = gen_parse_struct(gen_txt("struct NestedBraceRecovery { s32 before; s32 broken(s32 { 1; s32 after; };"), .ctx = nested_brace_options.ctx, .info = nested_brace_options.info);
|
||||||
|
expect(nested_brace_struct != 0 && nested_brace_struct->Type == CT_Struct, gen_txt("c11 nested brace recovery result"));
|
||||||
|
void* nested_brace_result = nested_brace_struct;
|
||||||
|
void* nested_brace_info_result = nested_brace_info.result;
|
||||||
|
expect(nested_brace_info_result == nested_brace_result, gen_txt("c11 nested brace recovery ParseInfo result"));
|
||||||
|
expect(nested_brace_info.messages != 0, gen_txt("c11 nested brace recovery diagnostic"));
|
||||||
|
gen_Code nested_brace_member = nested_brace_struct != 0 && nested_brace_struct->Body != 0 ? nested_brace_struct->Body->Front : 0;
|
||||||
|
expect(nested_brace_member != 0 && nested_brace_member->Type == CT_Variable, gen_txt("c11 nested brace recovery keeps preceding member typed"));
|
||||||
|
if (nested_brace_member != 0) nested_brace_member = nested_brace_member->Next;
|
||||||
|
expect(nested_brace_member != 0 && nested_brace_member->Type == CT_Untyped, gen_txt("c11 nested brace recovery retains failed member"));
|
||||||
|
if (nested_brace_member != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(nested_brace_member)), gen_txt("s32 broken(s32 { 1;")), gen_txt("c11 nested brace recovery exact failed span"));
|
||||||
|
gen_Code nested_brace_after = nested_brace_member != 0 ? nested_brace_member->Next : 0;
|
||||||
|
expect(nested_brace_after != 0 && nested_brace_after->Type == CT_Variable, gen_txt("c11 nested brace recovery keeps following member typed"));
|
||||||
|
if (nested_brace_after != 0)
|
||||||
|
expect(gen_str_are_equal(nested_brace_after->Name, gen_txt("after")), gen_txt("c11 nested brace recovery following member name"));
|
||||||
|
gen_Str nested_brace_text = {0};
|
||||||
|
if (nested_brace_struct != 0)
|
||||||
|
nested_brace_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)nested_brace_struct));
|
||||||
|
expect(gen_str_contains(nested_brace_text, gen_txt("s32 after")), gen_txt("c11 nested brace recovery serializes following member"));
|
||||||
|
|
||||||
|
ParseInfo nested_namespace_brace_info = {0};
|
||||||
|
gen_Opts_parse nested_namespace_brace_options = { .ctx = &ctx, .info = &nested_namespace_brace_info };
|
||||||
|
gen_CodeNS nested_namespace_brace = gen_parse_namespace(gen_txt("namespace NestedBraceRecovery { s32 before; s32 broken(s32 { 1; s32 after; }"), .ctx = nested_namespace_brace_options.ctx, .info = nested_namespace_brace_options.info);
|
||||||
|
expect(nested_namespace_brace != 0 && nested_namespace_brace->Type == CT_Namespace, gen_txt("c11 nested namespace brace recovery result"));
|
||||||
|
void* nested_namespace_brace_result = nested_namespace_brace;
|
||||||
|
void* nested_namespace_brace_info_result = nested_namespace_brace_info.result;
|
||||||
|
expect(nested_namespace_brace_info_result == nested_namespace_brace_result, gen_txt("c11 nested namespace brace recovery ParseInfo result"));
|
||||||
|
gen_Code nested_namespace_brace_member = nested_namespace_brace != 0 && nested_namespace_brace->Body != 0 ? nested_namespace_brace->Body->Front : 0;
|
||||||
|
expect(nested_namespace_brace_member != 0 && nested_namespace_brace_member->Type == CT_Variable, gen_txt("c11 nested namespace brace recovery keeps preceding member typed"));
|
||||||
|
if (nested_namespace_brace_member != 0) nested_namespace_brace_member = nested_namespace_brace_member->Next;
|
||||||
|
expect(nested_namespace_brace_member != 0 && nested_namespace_brace_member->Type == CT_Untyped, gen_txt("c11 nested namespace brace recovery retains failed member"));
|
||||||
|
if (nested_namespace_brace_member != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(nested_namespace_brace_member)), gen_txt("s32 broken(s32 { 1;")), gen_txt("c11 nested namespace brace recovery exact failed span"));
|
||||||
|
gen_Code nested_namespace_brace_after = nested_namespace_brace_member != 0 ? nested_namespace_brace_member->Next : 0;
|
||||||
|
expect(nested_namespace_brace_after != 0 && nested_namespace_brace_after->Type == CT_Variable, gen_txt("c11 nested namespace brace recovery keeps following member typed"));
|
||||||
|
if (nested_namespace_brace_after != 0)
|
||||||
|
expect(gen_str_are_equal(nested_namespace_brace_after->Name, gen_txt("after")), gen_txt("c11 nested namespace brace recovery following member name"));
|
||||||
|
gen_Str nested_namespace_brace_text = {0};
|
||||||
|
if (nested_namespace_brace != 0)
|
||||||
|
nested_namespace_brace_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)nested_namespace_brace));
|
||||||
|
expect(gen_str_contains(nested_namespace_brace_text, gen_txt("s32 after")), gen_txt("c11 nested namespace brace recovery serializes following member"));
|
||||||
|
|
||||||
|
ParseInfo nested_brace_tail_info = {0};
|
||||||
|
gen_Opts_parse nested_brace_tail_options = { .ctx = &ctx, .info = &nested_brace_tail_info };
|
||||||
|
gen_CodeStruct nested_brace_tail_struct = gen_parse_struct(gen_txt("struct NestedBraceTailRecovery { s32 before; s32 broken(s32 { 1; 2 } foo{ 3; s32 after; };"), .ctx = nested_brace_tail_options.ctx, .info = nested_brace_tail_options.info);
|
||||||
|
expect(nested_brace_tail_struct != 0 && nested_brace_tail_struct->Type == CT_Struct, gen_txt("c11 nested brace tail recovery result"));
|
||||||
|
gen_Code nested_brace_tail_member = nested_brace_tail_struct != 0 && nested_brace_tail_struct->Body != 0 ? nested_brace_tail_struct->Body->Front : 0;
|
||||||
|
if (nested_brace_tail_member != 0) nested_brace_tail_member = nested_brace_tail_member->Next;
|
||||||
|
expect(nested_brace_tail_member != 0 && nested_brace_tail_member->Type == CT_Untyped, gen_txt("c11 nested brace tail recovery retains failed member"));
|
||||||
|
if (nested_brace_tail_member != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(nested_brace_tail_member)), gen_txt("s32 broken(s32 { 1; 2 } foo{ 3;")), gen_txt("c11 nested brace tail recovery exact failed span"));
|
||||||
|
gen_Code nested_brace_tail_after = nested_brace_tail_member != 0 ? nested_brace_tail_member->Next : 0;
|
||||||
|
expect(nested_brace_tail_after != 0 && nested_brace_tail_after->Type == CT_Variable, gen_txt("c11 nested brace tail recovery keeps following member typed"));
|
||||||
|
if (nested_brace_tail_after != 0)
|
||||||
|
expect(gen_str_are_equal(nested_brace_tail_after->Name, gen_txt("after")), gen_txt("c11 nested brace tail recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo nested_namespace_tail_info = {0};
|
||||||
|
gen_Opts_parse nested_namespace_tail_options = { .ctx = &ctx, .info = &nested_namespace_tail_info };
|
||||||
|
gen_CodeNS nested_namespace_tail = gen_parse_namespace(gen_txt("namespace NestedBraceTailRecovery { s32 before; s32 broken(s32 { 1; 2 } foo{ 3; s32 after; }"), .ctx = nested_namespace_tail_options.ctx, .info = nested_namespace_tail_options.info);
|
||||||
|
expect(nested_namespace_tail != 0 && nested_namespace_tail->Type == CT_Namespace, gen_txt("c11 nested namespace brace tail recovery result"));
|
||||||
|
void* nested_namespace_tail_result = nested_namespace_tail;
|
||||||
|
void* nested_namespace_tail_info_result = nested_namespace_tail_info.result;
|
||||||
|
expect(nested_namespace_tail_info_result == nested_namespace_tail_result, gen_txt("c11 nested namespace brace tail recovery ParseInfo result"));
|
||||||
|
gen_Code nested_namespace_tail_member = nested_namespace_tail != 0 && nested_namespace_tail->Body != 0 ? nested_namespace_tail->Body->Front : 0;
|
||||||
|
if (nested_namespace_tail_member != 0) nested_namespace_tail_member = nested_namespace_tail_member->Next;
|
||||||
|
expect(nested_namespace_tail_member != 0 && nested_namespace_tail_member->Type == CT_Untyped, gen_txt("c11 nested namespace brace tail recovery retains failed member"));
|
||||||
|
if (nested_namespace_tail_member != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(nested_namespace_tail_member)), gen_txt("s32 broken(s32 { 1; 2 } foo{ 3;")), gen_txt("c11 nested namespace brace tail recovery exact failed span"));
|
||||||
|
gen_Code nested_namespace_tail_after = nested_namespace_tail_member != 0 ? nested_namespace_tail_member->Next : 0;
|
||||||
|
expect(nested_namespace_tail_after != 0 && nested_namespace_tail_after->Type == CT_Variable, gen_txt("c11 nested namespace brace tail recovery keeps following member typed"));
|
||||||
|
if (nested_namespace_tail_after != 0)
|
||||||
|
expect(gen_str_are_equal(nested_namespace_tail_after->Name, gen_txt("after")), gen_txt("c11 nested namespace brace tail recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo nested_inner_close_info = {0};
|
||||||
|
gen_Opts_parse nested_inner_close_options = { .ctx = &ctx, .info = &nested_inner_close_info };
|
||||||
|
gen_CodeStruct nested_inner_close_struct = gen_parse_struct(gen_txt("struct NestedInnerCloseRecovery { s32 before; s32 broken(s32 { 1; 2 } foo{ 3; s32 after; struct Inner { s32 x; }; s32 tail; };"), .ctx = nested_inner_close_options.ctx, .info = nested_inner_close_options.info);
|
||||||
|
expect(nested_inner_close_struct != 0 && nested_inner_close_struct->Type == CT_Struct, gen_txt("c11 nested inner-close recovery result"));
|
||||||
|
gen_Code nested_inner_close_member = nested_inner_close_struct != 0 && nested_inner_close_struct->Body != 0 ? nested_inner_close_struct->Body->Front : 0;
|
||||||
|
if (nested_inner_close_member != 0) nested_inner_close_member = nested_inner_close_member->Next;
|
||||||
|
expect(nested_inner_close_member != 0 && nested_inner_close_member->Type == CT_Untyped, gen_txt("c11 nested inner-close recovery retains failed member"));
|
||||||
|
if (nested_inner_close_member != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(nested_inner_close_member)), gen_txt("s32 broken(s32 { 1; 2 } foo{ 3;")), gen_txt("c11 nested inner-close recovery exact failed span"));
|
||||||
|
gen_Code nested_inner_close_after = nested_inner_close_member != 0 ? nested_inner_close_member->Next : 0;
|
||||||
|
expect(nested_inner_close_after != 0 && nested_inner_close_after->Type == CT_Variable, gen_txt("c11 nested inner-close recovery keeps following member typed"));
|
||||||
|
if (nested_inner_close_after != 0)
|
||||||
|
expect(gen_str_are_equal(nested_inner_close_after->Name, gen_txt("after")), gen_txt("c11 nested inner-close recovery following member name"));
|
||||||
|
gen_Code nested_inner_close_inner = nested_inner_close_after != 0 ? nested_inner_close_after->Next : 0;
|
||||||
|
expect(nested_inner_close_inner != 0 && nested_inner_close_inner->Type == CT_Struct, gen_txt("c11 nested inner-close recovery parses nested struct"));
|
||||||
|
gen_Code nested_inner_close_tail = nested_inner_close_inner != 0 ? nested_inner_close_inner->Next : 0;
|
||||||
|
expect(nested_inner_close_tail != 0 && nested_inner_close_tail->Type == CT_Variable, gen_txt("c11 nested inner-close recovery parses trailing member"));
|
||||||
|
|
||||||
|
ParseInfo inner_before_sync_info = {0};
|
||||||
|
gen_Opts_parse inner_before_sync_options = { .ctx = &ctx, .info = &inner_before_sync_info };
|
||||||
|
gen_CodeStruct inner_before_sync = gen_parse_struct(gen_txt("struct NestedInnerBeforeSync { s32 before; s32 broken(foo{ struct Inner { s32 x; }; s32 after; };"), .ctx = inner_before_sync_options.ctx, .info = inner_before_sync_options.info);
|
||||||
|
expect(inner_before_sync != 0 && inner_before_sync->Type == CT_Struct, gen_txt("c11 inner-before-sync recovery result"));
|
||||||
|
gen_Code inner_before_sync_member = inner_before_sync != 0 && inner_before_sync->Body != 0 ? inner_before_sync->Body->Front : 0;
|
||||||
|
expect(inner_before_sync_member != 0 && inner_before_sync_member->Type == CT_Variable, gen_txt("c11 inner-before-sync recovery keeps preceding member typed"));
|
||||||
|
if (inner_before_sync_member != 0) inner_before_sync_member = inner_before_sync_member->Next;
|
||||||
|
expect(inner_before_sync_member != 0 && inner_before_sync_member->Type == CT_Untyped, gen_txt("c11 inner-before-sync recovery retains failed member"));
|
||||||
|
if (inner_before_sync_member != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(inner_before_sync_member)), gen_txt("s32 broken(foo{ struct Inner { s32 x; };")), gen_txt("c11 inner-before-sync recovery exact failed span"));
|
||||||
|
gen_Code inner_before_sync_after = inner_before_sync_member != 0 ? inner_before_sync_member->Next : 0;
|
||||||
|
expect(inner_before_sync_after != 0 && inner_before_sync_after->Type == CT_Variable, gen_txt("c11 inner-before-sync recovery keeps following member typed"));
|
||||||
|
if (inner_before_sync_after != 0)
|
||||||
|
expect(gen_str_are_equal(inner_before_sync_after->Name, gen_txt("after")), gen_txt("c11 inner-before-sync recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo global_namespace_recovery_info = {0};
|
||||||
|
gen_Opts_parse global_namespace_recovery_options = { .ctx = &ctx, .info = &global_namespace_recovery_info };
|
||||||
|
gen_CodeBody global_namespace_recovery = gen_parse_global_body(gen_txt("namespace NestedScopeInGlobal { s32 before; s32 broken(s32 { 1; 2 } foo{ 3; s32 after; } struct Later { s32 value; };"), .ctx = global_namespace_recovery_options.ctx, .info = global_namespace_recovery_options.info);
|
||||||
|
expect(global_namespace_recovery != 0 && global_namespace_recovery->Type == CT_Global_Body, gen_txt("c11 global namespace recovery body"));
|
||||||
|
void* global_namespace_recovery_result = global_namespace_recovery;
|
||||||
|
void* global_namespace_recovery_info_result = global_namespace_recovery_info.result;
|
||||||
|
expect(global_namespace_recovery_info_result == global_namespace_recovery_result, gen_txt("c11 global namespace recovery ParseInfo result"));
|
||||||
|
gen_Code global_namespace_node = global_namespace_recovery != 0 ? global_namespace_recovery->Front : 0;
|
||||||
|
expect(global_namespace_node != 0 && global_namespace_node->Type == CT_Namespace, gen_txt("c11 global namespace recovery preserves namespace"));
|
||||||
|
gen_Code global_namespace_member = global_namespace_node != 0 && global_namespace_node->Body != 0 ? global_namespace_node->Body->Front : 0;
|
||||||
|
if (global_namespace_member != 0) global_namespace_member = global_namespace_member->Next;
|
||||||
|
expect(global_namespace_member != 0 && global_namespace_member->Type == CT_Untyped, gen_txt("c11 global namespace recovery retains failed member"));
|
||||||
|
if (global_namespace_member != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(global_namespace_member)), gen_txt("s32 broken(s32 { 1; 2 } foo{ 3;")), gen_txt("c11 global namespace recovery exact failed span"));
|
||||||
|
gen_Code global_namespace_after = global_namespace_member != 0 ? global_namespace_member->Next : 0;
|
||||||
|
expect(global_namespace_after != 0 && global_namespace_after->Type == CT_Variable, gen_txt("c11 global namespace recovery keeps following member typed"));
|
||||||
|
if (global_namespace_after != 0)
|
||||||
|
expect(gen_str_are_equal(global_namespace_after->Name, gen_txt("after")), gen_txt("c11 global namespace recovery following member name"));
|
||||||
|
gen_Code global_later_struct = global_namespace_node != 0 ? global_namespace_node->Next : 0;
|
||||||
|
expect(global_later_struct != 0 && global_later_struct->Type == CT_Struct, gen_txt("c11 global namespace recovery preserves following global struct"));
|
||||||
|
if (global_later_struct != 0)
|
||||||
|
expect(gen_str_are_equal(global_later_struct->Name, gen_txt("Later")), gen_txt("c11 global namespace recovery following global name"));
|
||||||
|
|
||||||
|
ParseInfo global_struct_recovery_info = {0};
|
||||||
|
gen_Opts_parse global_struct_recovery_options = { .ctx = &ctx, .info = &global_struct_recovery_info };
|
||||||
|
gen_CodeBody global_struct_recovery = gen_parse_global_body(gen_txt("struct GlobalNestedRecovery { s32 before; s32 broken(s32 value; s32 after; }; struct LaterGlobal { s32 value; };"), .ctx = global_struct_recovery_options.ctx, .info = global_struct_recovery_options.info);
|
||||||
|
expect(global_struct_recovery != 0 && global_struct_recovery->Type == CT_Global_Body, gen_txt("c11 global struct recovery body"));
|
||||||
|
gen_Code global_struct_node = global_struct_recovery != 0 ? global_struct_recovery->Front : 0;
|
||||||
|
gen_Code global_struct_before = global_struct_node != 0 && global_struct_node->Body != 0 ? global_struct_node->Body->Front : 0;
|
||||||
|
gen_Code global_struct_member = global_struct_before != 0 ? global_struct_before->Next : 0;
|
||||||
|
gen_Code global_struct_after = global_struct_member != 0 ? global_struct_member->Next : 0;
|
||||||
|
gen_Code global_later_class = global_struct_node != 0 ? global_struct_node->Next : 0;
|
||||||
|
expect(global_struct_node != 0 && global_struct_node->Type == CT_Struct, gen_txt("c11 global struct recovery preserves partial struct"));
|
||||||
|
expect(global_struct_member != 0 && global_struct_member->Type == CT_Untyped, gen_txt("c11 global struct recovery retains failed member"));
|
||||||
|
if (global_struct_member != 0)
|
||||||
|
expect(gen_str_are_equal(gen_strbuilder_to_str(gen_code_to_strbuilder(global_struct_member)), gen_txt("s32 broken(s32 value;")), gen_txt("c11 global struct recovery exact failed span"));
|
||||||
|
expect(global_struct_after != 0 && global_struct_after->Type == CT_Variable, gen_txt("c11 global struct recovery keeps following member"));
|
||||||
|
if (global_struct_after != 0)
|
||||||
|
expect(gen_str_are_equal(global_struct_after->Name, gen_txt("after")), gen_txt("c11 global struct recovery following member name"));
|
||||||
|
expect(global_later_class != 0 && global_later_class->Type == CT_Struct, gen_txt("c11 global struct recovery keeps following global struct"));
|
||||||
|
|
||||||
|
ParseInfo nested_owner_info = {0};
|
||||||
|
gen_Opts_parse nested_owner_options = { .ctx = & ctx, .info = & nested_owner_info };
|
||||||
|
gen_CodeStruct nested_owner = gen_parse_struct(gen_txt("struct NestedOwner { s32 before; struct InnerRecovery { s32 inner_before; s32 broken(s32 value; s32 inner_after; }; s32 after; };"), .ctx = nested_owner_options.ctx, .info = nested_owner_options.info);
|
||||||
|
expect(nested_owner != 0 && nested_owner->Type == CT_Struct, gen_txt("c11 nested owner recovery result"));
|
||||||
|
void* nested_owner_result = nested_owner;
|
||||||
|
void* nested_owner_info_result = nested_owner_info.result;
|
||||||
|
expect(nested_owner_info_result == nested_owner_result, gen_txt("c11 nested owner recovery ParseInfo result"));
|
||||||
|
expect(nested_owner_info.messages != 0, gen_txt("c11 nested owner recovery diagnostic"));
|
||||||
|
|
||||||
|
gen_Code nested_owner_before = nested_owner != 0 && nested_owner->Body != 0 ? nested_owner->Body->Front : 0;
|
||||||
|
gen_Code nested_owner_inner = nested_owner_before != 0 ? nested_owner_before->Next : 0;
|
||||||
|
gen_Code nested_owner_after = nested_owner_inner != 0 ? nested_owner_inner->Next : 0;
|
||||||
|
gen_Code nested_owner_inner_before = nested_owner_inner != 0 && nested_owner_inner->Body != 0 ? nested_owner_inner->Body->Front : 0;
|
||||||
|
gen_Code nested_owner_inner_failed = nested_owner_inner_before != 0 ? nested_owner_inner_before->Next : 0;
|
||||||
|
gen_Code nested_owner_inner_after = nested_owner_inner_failed != 0 ? nested_owner_inner_failed->Next : 0;
|
||||||
|
expect(nested_owner_before != 0 && nested_owner_before->Type == CT_Variable, gen_txt("c11 nested owner keeps preceding member typed"));
|
||||||
|
expect(nested_owner_inner != 0 && nested_owner_inner->Type == CT_Struct, gen_txt("c11 nested owner retains inner struct AST"));
|
||||||
|
expect(nested_owner_inner_before != 0 && nested_owner_inner_before->Type == CT_Variable, gen_txt("c11 nested inner recovery keeps preceding member typed"));
|
||||||
|
expect(nested_owner_inner_failed != 0 && nested_owner_inner_failed->Type == CT_Untyped, gen_txt("c11 nested inner recovery retains failed member"));
|
||||||
|
expect(nested_owner_inner_after != 0 && nested_owner_inner_after->Type == CT_Variable, gen_txt("c11 nested inner recovery keeps following member typed"));
|
||||||
|
expect(nested_owner_after != 0 && nested_owner_after->Type == CT_Variable, gen_txt("c11 nested owner keeps following member typed"));
|
||||||
|
|
||||||
#if ! GEN_BUILD_DEBUG
|
#if ! GEN_BUILD_DEBUG
|
||||||
gen_CodeVar wrong_array_value = gen_def_variable(gen_def_type(name(u32)), name(invalid_array_expr));
|
gen_CodeVar wrong_array_value = gen_def_variable(gen_def_type(name(u32)), name(invalid_array_expr));
|
||||||
gen_CodeTypename invalid_array_type = gen_def_type(name(InvalidArrayOption), .gen_array_expr = (gen_Code)wrong_array_value);
|
gen_CodeTypename invalid_array_type = gen_def_type(name(InvalidArrayOption), .gen_array_expr = (gen_Code)wrong_array_value);
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
internal void expect_simd_lanes()
|
||||||
|
{
|
||||||
|
#if defined(GEN_SYSTEM_WINDOWS) && (defined(_M_X64) || defined(__x86_64__))
|
||||||
|
using namespace gen;
|
||||||
|
u8 storage[32];
|
||||||
|
mem_set(storage, 0x11, 32);
|
||||||
|
u8 pattern[16] = {
|
||||||
|
0x00, 0x80, 0xFF, 0x01,
|
||||||
|
0x02, 0x03, 0x04, 0x05,
|
||||||
|
0x06, 0x07, 0x08, 0x09,
|
||||||
|
0x0A, 0x0B, 0x0C, 0x0D
|
||||||
|
};
|
||||||
|
mem_copy(storage + 1, pattern, 16);
|
||||||
|
u8x16 loaded = u8x16_load(storage + 1);
|
||||||
|
u8x16 again = u8x16_load(storage + 1);
|
||||||
|
u16 same = u8x16_mask(u8x16_equal(loaded, again));
|
||||||
|
expect(same == 0xFFFF, txt("simd u8 equal load"));
|
||||||
|
u16 zero_mask = u8x16_mask(u8x16_equal(loaded, u8x16_splat(0x00)));
|
||||||
|
expect(zero_mask == 0x0001, txt("simd byte 0"));
|
||||||
|
u16 high_bit = u8x16_mask(u8x16_equal(loaded, u8x16_splat(0x80)));
|
||||||
|
expect(high_bit == 0x0002, txt("simd byte 0x80"));
|
||||||
|
u16 top = u8x16_mask(u8x16_equal(loaded, u8x16_splat(0xFF)));
|
||||||
|
expect(top == 0x0004, txt("simd byte 0xFF"));
|
||||||
|
|
||||||
|
u8 high_lane[16];
|
||||||
|
mem_set(high_lane, 0x22, 16);
|
||||||
|
high_lane[15] = 0xFF;
|
||||||
|
u8x16 high_loaded = u8x16_load(high_lane);
|
||||||
|
u16 lane15 = u8x16_mask(u8x16_equal(high_loaded, u8x16_splat(0xFF)));
|
||||||
|
expect(lane15 == 0x8000, txt("simd lane 15"));
|
||||||
|
expect(u32_mask_first_set(lane15) == 15, txt("simd first set lane 15"));
|
||||||
|
|
||||||
|
u8 window[24];
|
||||||
|
mem_set(window, 0xEE, 24);
|
||||||
|
window[1] = 0x00;
|
||||||
|
window[2] = 0x80;
|
||||||
|
window[3] = 0xFF;
|
||||||
|
window[4] = 0x11;
|
||||||
|
window[5] = 0x22;
|
||||||
|
window[6] = 0x33;
|
||||||
|
window[7] = 0x44;
|
||||||
|
window[8] = 0x55;
|
||||||
|
u8x16 loaded8 = u8x16_load8(window + 1);
|
||||||
|
u16 upper = u8x16_mask(u8x16_equal(loaded8, u8x16_splat(0x00)));
|
||||||
|
expect((upper & 0xFF00) == 0xFF00, txt("simd load8 upper zero"));
|
||||||
|
expect((upper & 0x0001) == 0x0001, txt("simd load8 low zero"));
|
||||||
|
u16 low_ff = u8x16_mask(u8x16_equal(loaded8, u8x16_splat(0xFF)));
|
||||||
|
expect(low_ff == 0x0004, txt("simd load8 low 0xFF"));
|
||||||
|
u16 low_80 = u8x16_mask(u8x16_equal(loaded8, u8x16_splat(0x80)));
|
||||||
|
expect(low_80 == 0x0002, txt("simd load8 low 0x80"));
|
||||||
|
u16 byte7 = u8x16_mask(u8x16_equal(loaded8, u8x16_splat(0x55)));
|
||||||
|
expect(byte7 == 0x0080, txt("simd load8 byte 7"));
|
||||||
|
u16 sentinel = u8x16_mask(u8x16_equal(loaded8, u8x16_splat(0xEE)));
|
||||||
|
expect(sentinel == 0, txt("simd load8 ignores tail"));
|
||||||
|
u8x16 loaded16 = u8x16_load(window + 1);
|
||||||
|
u16 tail = u8x16_mask(u8x16_equal(loaded16, u8x16_splat(0xEE)));
|
||||||
|
expect(tail == 0xFF00, txt("simd load16 sees load8 tail"));
|
||||||
|
|
||||||
|
u32 hashes[4] = { 0x00000000u, 0x7FFFFFFFu, 0x80000000u, 0xFFFFFFFFu };
|
||||||
|
u32x4 hash_loaded = u32x4_load(hashes);
|
||||||
|
u8 lane0 = u32x4_mask(u32x4_equal(hash_loaded, u32x4_splat(0x00000000u)));
|
||||||
|
u8 lane1 = u32x4_mask(u32x4_equal(hash_loaded, u32x4_splat(0x7FFFFFFFu)));
|
||||||
|
u8 lane2 = u32x4_mask(u32x4_equal(hash_loaded, u32x4_splat(0x80000000u)));
|
||||||
|
u8 lane3 = u32x4_mask(u32x4_equal(hash_loaded, u32x4_splat(0xFFFFFFFFu)));
|
||||||
|
expect(lane0 == 0x01, txt("simd u32 lane 0"));
|
||||||
|
expect(lane1 == 0x02, txt("simd u32 lane 1"));
|
||||||
|
expect(lane2 == 0x04, txt("simd u32 bit31 lane"));
|
||||||
|
expect(lane3 == 0x08, txt("simd u32 lane 3"));
|
||||||
|
expect((lane2 & 0xF0) == 0, txt("simd u32 mask low bits"));
|
||||||
|
|
||||||
|
u32 all_values[4] = { 0x80000000u, 0x80000000u, 0x80000000u, 0x80000000u };
|
||||||
|
u32x4 all_loaded = u32x4_load(all_values);
|
||||||
|
u8 all_mask = u32x4_mask(u32x4_equal(all_loaded, u32x4_splat(0x80000000u)));
|
||||||
|
expect(all_mask == 0x0F, txt("simd u32 all bit31"));
|
||||||
|
u8 none_mask = u32x4_mask(u32x4_equal(all_loaded, u32x4_splat(0x7FFFFFFFu)));
|
||||||
|
expect(none_mask == 0x00, txt("simd u32 none"));
|
||||||
|
|
||||||
|
u8 hash_storage[20];
|
||||||
|
mem_set(hash_storage, 0xA5, 20);
|
||||||
|
mem_copy(hash_storage + 1, hashes, 16);
|
||||||
|
u32x4 unaligned = u32x4_load(hash_storage + 1);
|
||||||
|
u8 unaligned_mask = u32x4_mask(u32x4_equal(unaligned, u32x4_splat(0x80000000u)));
|
||||||
|
expect(unaligned_mask == 0x04, txt("simd u32 unaligned bit31"));
|
||||||
|
|
||||||
|
expect(u32_mask_first_set(0x1u) == 0, txt("simd first set bit 0"));
|
||||||
|
expect(u32_mask_first_set(0x14u) == 2, txt("simd first set lowest"));
|
||||||
|
expect(u32_mask_first_set(0x8000u) == 15, txt("simd first set bit 15"));
|
||||||
|
expect(u32_mask_first_set(0x80000000u) == 31, txt("simd first set bit 31"));
|
||||||
|
expect(u32_mask_first_set(0xFFFFFFFFu) == 0, txt("simd first set all bits"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -0,0 +1,651 @@
|
|||||||
|
internal gen::Str bounded_format(char* storage, gen::ssize storage_len, char const* bytes, gen::ssize len)
|
||||||
|
{
|
||||||
|
gen::mem_set(storage, '!', storage_len);
|
||||||
|
if (len > 0)
|
||||||
|
gen::mem_copy(storage, bytes, len);
|
||||||
|
storage[storage_len - 1] = '\0';
|
||||||
|
gen::Str result = { storage, len };
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_expansion(gen::Str label, gen::Str format, gen::StrTemplateSlot* slots, gen::ssize slot_count, gen::Str expansion)
|
||||||
|
{
|
||||||
|
using namespace gen;
|
||||||
|
StrBuilder output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
expect(strbuilder_append_str(& output, txt("KEEP")), label);
|
||||||
|
Slice_StrTemplateSlot slice = { nullptr, 0 };
|
||||||
|
if (slot_count != 0) {
|
||||||
|
slice.Ptr = slots;
|
||||||
|
slice.Len = slot_count;
|
||||||
|
}
|
||||||
|
bool appended = strbuilder_append_template(& output, slice, format);
|
||||||
|
expect(appended, label);
|
||||||
|
Str got = strbuilder_to_str(output);
|
||||||
|
expect(got.Len == 4 + expansion.Len, label);
|
||||||
|
expect(str_starts_with(got, txt("KEEP")), label);
|
||||||
|
if (got.Len >= 4 + expansion.Len) {
|
||||||
|
Str tail = { got.Ptr + 4, expansion.Len };
|
||||||
|
expect(str_are_equal(tail, expansion), label);
|
||||||
|
}
|
||||||
|
StrBuilderHeader* header = strbuilder_get_header(output);
|
||||||
|
expect(header->Allocator.Proc == heap_allocator_proc, label);
|
||||||
|
strbuilder_free(& output);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_text(gen::Str label, gen::Str format, gen::StrTemplateSlot* slots, gen::ssize slot_count, gen::Str expansion)
|
||||||
|
{
|
||||||
|
expect_template_expansion(label, format, slots, slot_count, expansion);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_literal_boundary(gen::ssize mark) {
|
||||||
|
using namespace gen;
|
||||||
|
char format_storage[64];
|
||||||
|
char format_bytes[40];
|
||||||
|
for (ssize idx = 0; idx < mark; ++ idx)
|
||||||
|
format_bytes[idx] = 'L';
|
||||||
|
Str format = bounded_format(format_storage, 64, format_bytes, mark);
|
||||||
|
Str expansion = { format_bytes, mark };
|
||||||
|
expect(format_storage[mark] == '!', txt("literal boundary"));
|
||||||
|
expect_template_expansion(txt("literal boundary"), format, nullptr, 0, expansion);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_open_boundary(gen::ssize mark)
|
||||||
|
{
|
||||||
|
using namespace gen;
|
||||||
|
char format_storage[64];
|
||||||
|
char format_bytes[48];
|
||||||
|
char expansion_bytes[48];
|
||||||
|
ssize format_len = 0;
|
||||||
|
for (ssize idx = 0; idx < mark; ++ idx)
|
||||||
|
format_bytes[format_len ++] = 'L';
|
||||||
|
format_bytes[format_len ++] = '<';
|
||||||
|
format_bytes[format_len ++] = 'k';
|
||||||
|
format_bytes[format_len ++] = '>';
|
||||||
|
format_bytes[format_len ++] = 'Z';
|
||||||
|
Str format = bounded_format(format_storage, 64, format_bytes, format_len);
|
||||||
|
StrTemplateSlot slot = {};
|
||||||
|
slot.Key = txt("k");
|
||||||
|
slot.Value = txt("V");
|
||||||
|
ssize expansion_len = 0;
|
||||||
|
for (ssize idx = 0; idx < mark; ++ idx)
|
||||||
|
expansion_bytes[expansion_len ++] = 'L';
|
||||||
|
expansion_bytes[expansion_len ++] = 'V';
|
||||||
|
expansion_bytes[expansion_len ++] = 'Z';
|
||||||
|
Str expansion = { expansion_bytes, expansion_len };
|
||||||
|
expect(format.Ptr[mark] == '<', txt("open boundary"));
|
||||||
|
expect(format_storage[format_len] == '!', txt("open boundary"));
|
||||||
|
expect_template_expansion(txt("open boundary"), format, & slot, 1, expansion);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_close_boundary(gen::ssize mark) {
|
||||||
|
using namespace gen;
|
||||||
|
char format_storage[64];
|
||||||
|
char format_bytes[48];
|
||||||
|
char key_storage[40];
|
||||||
|
ssize key_len = mark - 1;
|
||||||
|
mem_set(key_storage, '!', 40);
|
||||||
|
for (ssize idx = 0; idx < key_len; ++ idx)
|
||||||
|
key_storage[idx] = 'k';
|
||||||
|
key_storage[39] = '\0';
|
||||||
|
Str key = { key_storage, key_len };
|
||||||
|
ssize format_len = 0;
|
||||||
|
format_bytes[format_len ++] = '<';
|
||||||
|
for (ssize idx = 0; idx < key_len; ++ idx)
|
||||||
|
format_bytes[format_len ++] = 'k';
|
||||||
|
format_bytes[format_len ++] = '>';
|
||||||
|
format_bytes[format_len ++] = 'Z';
|
||||||
|
Str format = bounded_format(format_storage, 64, format_bytes, format_len);
|
||||||
|
StrTemplateSlot slot = {};
|
||||||
|
slot.Key = key;
|
||||||
|
slot.Value = txt("V");
|
||||||
|
expect(format.Ptr[mark] == '>', txt("close boundary"));
|
||||||
|
expect(key.Ptr[key.Len] == '!', txt("close boundary"));
|
||||||
|
expect(format_storage[format_len] == '!', txt("close boundary"));
|
||||||
|
expect_template_expansion(txt("close boundary"), format, & slot, 1, txt("VZ"));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_shapes()
|
||||||
|
{
|
||||||
|
using namespace gen;
|
||||||
|
char literal_storage[8];
|
||||||
|
char literal_bytes[6] = { 'a', 'b', 'c', 'D', 'E', 'F' };
|
||||||
|
Str literal = bounded_format(literal_storage, 8, literal_bytes, 3);
|
||||||
|
expect(literal_storage[3] == '!', txt("literal sentinel"));
|
||||||
|
expect_template_expansion(txt("literal bounded"), literal, nullptr, 0, txt("abc"));
|
||||||
|
|
||||||
|
char empty_storage[4];
|
||||||
|
Str empty_format = bounded_format(empty_storage, 4, empty_storage, 0);
|
||||||
|
expect(empty_storage[0] == '!', txt("empty sentinel"));
|
||||||
|
expect_template_expansion(txt("empty format"), empty_format, nullptr, 0, txt(""));
|
||||||
|
|
||||||
|
StrTemplateSlot name_slot = {};
|
||||||
|
name_slot.Key = txt("name");
|
||||||
|
name_slot.Value = txt("world");
|
||||||
|
expect_template_text(txt("one slot"), txt("hello <name>!"), & name_slot, 1, txt("hello world!"));
|
||||||
|
|
||||||
|
StrTemplateSlot repeat_slot = {};
|
||||||
|
repeat_slot.Key = txt("w");
|
||||||
|
repeat_slot.Value = txt("v");
|
||||||
|
expect_template_text(txt("repeated slot"), txt("<w>-<w>-<w>"), & repeat_slot, 1, txt("v-v-v"));
|
||||||
|
|
||||||
|
StrTemplateSlot adjacent[2] = {};
|
||||||
|
adjacent[0].Key = txt("a");
|
||||||
|
adjacent[0].Value = txt("X");
|
||||||
|
adjacent[1].Key = txt("b");
|
||||||
|
adjacent[1].Value = txt("Y");
|
||||||
|
expect_template_text(txt("adjacent slots"), txt("<a><b><a>"), adjacent, 2, txt("XYX"));
|
||||||
|
|
||||||
|
StrTemplateSlot raw_slots[3] = {};
|
||||||
|
raw_slots[0].Key = txt("raw");
|
||||||
|
raw_slots[0].Value = txt("a<b>c");
|
||||||
|
raw_slots[1].Key = txt("angles");
|
||||||
|
raw_slots[1].Value = txt("<>");
|
||||||
|
raw_slots[2].Key = txt("b");
|
||||||
|
raw_slots[2].Value = txt("SHOULD_NOT");
|
||||||
|
expect_template_text(txt("value angles literal"), txt("<raw><angles>"), raw_slots, 3, txt("a<b>c<>"));
|
||||||
|
|
||||||
|
char empty_value_storage[2] = { '!', '!' };
|
||||||
|
StrTemplateSlot empty_slot = {};
|
||||||
|
empty_slot.Key = txt("e");
|
||||||
|
empty_slot.Value = { empty_value_storage, 0 };
|
||||||
|
expect_template_text(txt("empty value"), txt("A<e>B"), & empty_slot, 1, txt("AB"));
|
||||||
|
|
||||||
|
StrTemplateSlot empty_key = {};
|
||||||
|
empty_key.Key = { nullptr, 0 };
|
||||||
|
empty_key.Value = txt("Z");
|
||||||
|
expect_template_text(txt("empty key"), txt("<>"), & empty_key, 1, txt("Z"));
|
||||||
|
|
||||||
|
StrTemplateSlot null_value = {};
|
||||||
|
null_value.Key = txt("e");
|
||||||
|
null_value.Value = { nullptr, 0 };
|
||||||
|
expect(null_value.Value.Ptr == nullptr, txt("null empty value pointer"));
|
||||||
|
expect(null_value.Value.Len == 0, txt("null empty value length"));
|
||||||
|
expect_template_text(txt("null empty value"), txt("A<e>B"), & null_value, 1, txt("AB"));
|
||||||
|
|
||||||
|
char nul_value_bytes[4] = { 'a', '\0', 'b', '!' };
|
||||||
|
char nul_expected[5] = { '[', 'a', '\0', 'b', ']' };
|
||||||
|
StrTemplateSlot nul_slot = {};
|
||||||
|
nul_slot.Key = txt("n");
|
||||||
|
nul_slot.Value = { nul_value_bytes, 3 };
|
||||||
|
gen::Str nul_expansion = { nul_expected, 5 };
|
||||||
|
expect_template_text(txt("embedded nul"), txt("[<n>]"), & nul_slot, 1, nul_expansion);
|
||||||
|
|
||||||
|
StrTemplateSlot duffle[2] = {};
|
||||||
|
duffle[0].Key = txt("operands[0]");
|
||||||
|
duffle[0].Value = txt("eax");
|
||||||
|
duffle[1].Key = txt("mod_rm.bits");
|
||||||
|
duffle[1].Value = txt("11");
|
||||||
|
expect_template_text(txt("duffle keys"), txt("mov <operands[0]>, <mod_rm.bits>;"), duffle, 2, txt("mov eax, 11;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void fill_lookup_slots(gen::StrTemplateSlot* slots, gen::ssize slot_count) {
|
||||||
|
gen::Str keys[9] = {
|
||||||
|
txt("k0"), txt("k1"), txt("k2"), txt("k3"), txt("k4"),
|
||||||
|
txt("k5"), txt("k6"), txt("k7"), txt("k8")
|
||||||
|
};
|
||||||
|
gen::Str values[9] = {
|
||||||
|
txt("V0"), txt("V1"), txt("V2"), txt("V3"), txt("V4"),
|
||||||
|
txt("V5"), txt("V6"), txt("V7"), txt("V8")
|
||||||
|
};
|
||||||
|
for (gen::ssize idx = 0; idx < slot_count; ++ idx) {
|
||||||
|
slots[idx].Key = keys[idx];
|
||||||
|
slots[idx].Value = values[idx];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_lookup()
|
||||||
|
{
|
||||||
|
using namespace gen;
|
||||||
|
StrTemplateSlot slots[9] = {};
|
||||||
|
expect_template_text(txt("lookup 0"), txt("none"), nullptr, 0, txt("none"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 1);
|
||||||
|
expect_template_text(txt("lookup 1"), txt("<k0>"), slots, 1, txt("V0"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 2);
|
||||||
|
expect_template_text(txt("lookup 2"), txt("<k1><k0>"), slots, 2, txt("V1V0"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 3);
|
||||||
|
expect_template_text(txt("lookup 3"), txt("<k2>-<k0>-<k1>"), slots, 3, txt("V2-V0-V1"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 4);
|
||||||
|
expect_template_text(txt("lookup 4"), txt("<k3><k0><k2><k1>"), slots, 4, txt("V3V0V2V1"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 5);
|
||||||
|
expect_template_text(txt("lookup 5 tail"), txt("<k4><k0><k3>"), slots, 5, txt("V4V0V3"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 8);
|
||||||
|
expect_template_text(txt("lookup 8 lanes"), txt("<k7><k4><k3><k0>"), slots, 8, txt("V7V4V3V0"));
|
||||||
|
|
||||||
|
fill_lookup_slots(slots, 9);
|
||||||
|
expect_template_text(txt("lookup 9 tail"), txt("<k8><k5><k6><k4>"), slots, 9, txt("V8V5V6V4"));
|
||||||
|
|
||||||
|
StrTemplateSlot dup_small[3] = {};
|
||||||
|
dup_small[0].Key = txt("dup"); dup_small[0].Value = txt("FIRST");
|
||||||
|
dup_small[1].Key = txt("other"); dup_small[1].Value = txt("X");
|
||||||
|
dup_small[2].Key = txt("dup"); dup_small[2].Value = txt("SECOND");
|
||||||
|
expect_template_text(txt("duplicate first wins"), txt("<dup><other>"), dup_small, 3, txt("FIRSTX"));
|
||||||
|
|
||||||
|
StrTemplateSlot dup_lanes[4] = {};
|
||||||
|
dup_lanes[0].Key = txt("same"); dup_lanes[0].Value = txt("A");
|
||||||
|
dup_lanes[1].Key = txt("same"); dup_lanes[1].Value = txt("B");
|
||||||
|
dup_lanes[2].Key = txt("other"); dup_lanes[2].Value = txt("C");
|
||||||
|
dup_lanes[3].Key = txt("same"); dup_lanes[3].Value = txt("D");
|
||||||
|
expect_template_text(txt("duplicate lane first wins"), txt("<same><other>"), dup_lanes, 4, txt("AC"));
|
||||||
|
|
||||||
|
StrTemplateSlot dup_tail[5] = {};
|
||||||
|
dup_tail[0].Key = txt("dup"); dup_tail[0].Value = txt("FIRST");
|
||||||
|
dup_tail[1].Key = txt("k1"); dup_tail[1].Value = txt("V1");
|
||||||
|
dup_tail[2].Key = txt("k2"); dup_tail[2].Value = txt("V2");
|
||||||
|
dup_tail[3].Key = txt("k3"); dup_tail[3].Value = txt("V3");
|
||||||
|
dup_tail[4].Key = txt("dup"); dup_tail[4].Value = txt("TAIL");
|
||||||
|
expect_template_text(txt("duplicate tail first wins"), txt("<dup>"), dup_tail, 5, txt("FIRST"));
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace gen {
|
||||||
|
internal void expect_template_boundaries() {
|
||||||
|
ssize marks[12] = { 7, 8, 9, 15, 16, 17, 23, 24, 25, 31, 32, 33 };
|
||||||
|
for (ssize idx = 0; idx < count_of(marks); ++ idx) {
|
||||||
|
expect_literal_boundary(marks[idx]);
|
||||||
|
expect_open_boundary(marks[idx]);
|
||||||
|
expect_close_boundary(marks[idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_growth(gen::ssize printf_maxlen)
|
||||||
|
{
|
||||||
|
using namespace gen;
|
||||||
|
ssize huge_len = printf_maxlen + 64;
|
||||||
|
char* huge = rcast(char*, alloc(heap(), huge_len + 1));
|
||||||
|
expect(huge != nullptr, txt("growth alloc"));
|
||||||
|
if (huge == nullptr) return;
|
||||||
|
mem_set(huge, 'Q', huge_len);
|
||||||
|
huge[huge_len] = '!';
|
||||||
|
|
||||||
|
Str value = { huge, huge_len };
|
||||||
|
StrTemplateSlot slot = {};
|
||||||
|
slot.Key = txt("blob");
|
||||||
|
slot.Value = value;
|
||||||
|
Str format = txt("<blob>");
|
||||||
|
StrBuilder output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
expect(strbuilder_capacity(output) == 1, txt("growth initial capacity"));
|
||||||
|
expect(strbuilder_append_str(& output, txt("KEEP")), txt("growth prefix"));
|
||||||
|
|
||||||
|
Slice_StrTemplateSlot slice = { & slot, 1 };
|
||||||
|
bool appended = strbuilder_append_template(& output, slice, format);
|
||||||
|
expect(appended, txt("growth append"));
|
||||||
|
|
||||||
|
Str got = strbuilder_to_str(output);
|
||||||
|
expect(got.Len == 4 + huge_len, txt("growth length"));
|
||||||
|
expect(got.Len > printf_maxlen, txt("growth beyond printf max"));
|
||||||
|
expect(str_starts_with(got, txt("KEEP")), txt("growth keeps prefix"));
|
||||||
|
|
||||||
|
ssize capacity = strbuilder_capacity(output);
|
||||||
|
expect(capacity >= got.Len, txt("growth capacity"));
|
||||||
|
|
||||||
|
if (got.Len == 4 + huge_len && capacity >= got.Len) {
|
||||||
|
b32 payload_matches = true;
|
||||||
|
for (ssize idx = 0; idx < got.Len - 4; ++ idx) {
|
||||||
|
if (got.Ptr[4 + idx] != 'Q') payload_matches = false;
|
||||||
|
}
|
||||||
|
expect(payload_matches, txt("growth bytes"));
|
||||||
|
}
|
||||||
|
|
||||||
|
StrBuilderHeader* header = strbuilder_get_header(output);
|
||||||
|
expect(header->Allocator.Proc == heap_allocator_proc, txt("growth allocator"));
|
||||||
|
expect(huge[huge_len] == '!', txt("growth sentinel"));
|
||||||
|
strbuilder_free(& output);
|
||||||
|
allocator_free(heap(), huge);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_crc_collision()
|
||||||
|
{
|
||||||
|
using namespace gen;
|
||||||
|
Str plumless = txt("plumless");
|
||||||
|
Str buckeroo = txt("buckeroo");
|
||||||
|
u32 plum_hash = crc32(plumless.Ptr, plumless.Len);
|
||||||
|
u32 buck_hash = crc32(buckeroo.Ptr, buckeroo.Len);
|
||||||
|
expect(plum_hash == buck_hash, txt("crc collision equal"));
|
||||||
|
expect(plum_hash == 0x4ddb0c25, txt("crc collision value"));
|
||||||
|
expect(str_are_equal(plumless, buckeroo) == false, txt("crc collision keys differ"));
|
||||||
|
|
||||||
|
StrTemplateSlot scalar[2] = {};
|
||||||
|
scalar[0].Key = plumless; scalar[0].Value = txt("WRONG");
|
||||||
|
scalar[1].Key = buckeroo; scalar[1].Value = txt("RIGHT");
|
||||||
|
expect_template_text(txt("crc scalar 2"), txt("<buckeroo>"), scalar, 2, txt("RIGHT"));
|
||||||
|
|
||||||
|
StrTemplateSlot lanes[4] = {};
|
||||||
|
lanes[0].Key = plumless; lanes[0].Value = txt("WRONG");
|
||||||
|
lanes[1].Key = txt("k1"); lanes[1].Value = txt("V1");
|
||||||
|
lanes[2].Key = buckeroo; lanes[2].Value = txt("RIGHT");
|
||||||
|
lanes[3].Key = txt("k3"); lanes[3].Value = txt("V3");
|
||||||
|
expect_template_text(txt("crc lane reject"), txt("<buckeroo>"), lanes, 4, txt("RIGHT"));
|
||||||
|
|
||||||
|
StrTemplateSlot tail[5] = {};
|
||||||
|
tail[0].Key = plumless; tail[0].Value = txt("WRONG");
|
||||||
|
tail[1].Key = txt("k1"); tail[1].Value = txt("V1");
|
||||||
|
tail[2].Key = txt("k2"); tail[2].Value = txt("V2");
|
||||||
|
tail[3].Key = txt("k3"); tail[3].Value = txt("V3");
|
||||||
|
tail[4].Key = buckeroo; tail[4].Value = txt("TAIL");
|
||||||
|
expect_template_text(txt("crc tail after false hit"), txt("<buckeroo>"), tail, 5, txt("TAIL"));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal
|
||||||
|
void* resize_fail_allocator_proc(void* allocator_data, gen::AllocType type, gen::ssize size, gen::ssize alignment
|
||||||
|
, void* old_memory, gen::ssize old_size
|
||||||
|
, gen::u64 flags
|
||||||
|
){
|
||||||
|
if (type == gen::EAllocation_RESIZE) {
|
||||||
|
gen::s32* attempts = rcast(gen::s32*, allocator_data);
|
||||||
|
attempts[0] = attempts[0] + 1;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return gen::heap_allocator_proc(nullptr, type, size, alignment, old_memory, old_size, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_resize_fail(gen::ssize printf_maxlen)
|
||||||
|
{
|
||||||
|
using namespace gen;
|
||||||
|
ssize huge_len = printf_maxlen + 64;
|
||||||
|
char* huge = rcast(char*, alloc(heap(), huge_len + 1));
|
||||||
|
expect(huge != nullptr, txt("resize fail alloc"));
|
||||||
|
if (huge == nullptr) return;
|
||||||
|
mem_set(huge, 'L', huge_len);
|
||||||
|
huge[huge_len] = '!';
|
||||||
|
Str huge_text = { huge, huge_len };
|
||||||
|
|
||||||
|
s32 literal_attempts = 0;
|
||||||
|
AllocatorInfo literal_alloc = {};
|
||||||
|
literal_alloc.Proc = resize_fail_allocator_proc;
|
||||||
|
literal_alloc.Data = & literal_attempts;
|
||||||
|
StrBuilder literal_output = strbuilder_make_reserve(literal_alloc, 4);
|
||||||
|
expect(strbuilder_append_str(& literal_output, txt("KEEP")), txt("resize fail literal prefix"));
|
||||||
|
|
||||||
|
Slice_StrTemplateSlot literal_slots = { nullptr, 0 };
|
||||||
|
bool literal_appended = strbuilder_append_template(& literal_output, literal_slots, huge_text);
|
||||||
|
expect(literal_appended == false, txt("resize fail literal"));
|
||||||
|
|
||||||
|
Str literal_got = strbuilder_to_str(literal_output);
|
||||||
|
expect(literal_got.Len == 4, txt("resize fail literal length"));
|
||||||
|
expect(str_are_equal(literal_got, txt("KEEP")), txt("resize fail literal keep"));
|
||||||
|
expect(literal_attempts > 0, txt("resize fail literal attempts"));
|
||||||
|
strbuilder_free(& literal_output);
|
||||||
|
|
||||||
|
s32 value_attempts = 0;
|
||||||
|
AllocatorInfo value_alloc = {};
|
||||||
|
value_alloc.Proc = resize_fail_allocator_proc;
|
||||||
|
value_alloc.Data = & value_attempts;
|
||||||
|
|
||||||
|
StrTemplateSlot slot = {};
|
||||||
|
slot.Key = txt("blob");
|
||||||
|
slot.Value = huge_text;
|
||||||
|
Str format = txt("<blob>");
|
||||||
|
StrBuilder value_output = strbuilder_make_reserve(value_alloc, 4);
|
||||||
|
expect(strbuilder_append_str(& value_output, txt("KEEP")), txt("resize fail value prefix"));
|
||||||
|
|
||||||
|
Slice_StrTemplateSlot value_slots = { & slot, 1 };
|
||||||
|
bool value_appended = strbuilder_append_template(& value_output, value_slots, format);
|
||||||
|
expect(value_appended == false, txt("resize fail value"));
|
||||||
|
|
||||||
|
Str value_got = strbuilder_to_str(value_output);
|
||||||
|
expect(value_got.Len == 4, txt("resize fail value length"));
|
||||||
|
expect(str_are_equal(value_got, txt("KEEP")), txt("resize fail value keep"));
|
||||||
|
expect(value_attempts > 0, txt("resize fail value attempts"));
|
||||||
|
strbuilder_free(& value_output);
|
||||||
|
allocator_free(heap(), huge);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal gen::Str counted_template_value (gen::s32* reads) { reads[0] = reads[0] + 1; return txt("ONCE"); }
|
||||||
|
internal gen::Str counted_template_format(gen::s32* reads) { reads[0] = reads[0] + 1; return txt("<k>:<k>"); }
|
||||||
|
internal gen::StrBuilder* counted_template_output(gen::StrBuilder* output, gen::s32* reads) { reads[0] = reads[0] + 1; return output; }
|
||||||
|
internal bool* counted_template_result(bool* result, gen::s32* reads) { reads[0] = reads[0] + 1; return result; }
|
||||||
|
|
||||||
|
internal void expect_template_slice() {
|
||||||
|
using namespace gen;
|
||||||
|
StrTemplateSlot slots[2] = {
|
||||||
|
strtmpl_slot("a", txt("X")),
|
||||||
|
strtmpl_slot("b", txt("Y"))
|
||||||
|
};
|
||||||
|
Slice_StrTemplateSlot slice = { slots, 2 };
|
||||||
|
StrBuilder output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
expect(strbuilder_append_str(& output, txt("KEEP")), txt("slice prefix"));
|
||||||
|
|
||||||
|
bool appended = strbuilder_append_template(& output, slice, txt("<b><a><b>"));
|
||||||
|
expect(appended, txt("slice append"));
|
||||||
|
expect(str_are_equal(strbuilder_to_str(output), txt("KEEPYXY")), txt("slice text"));
|
||||||
|
expect(str_are_equal(slots[0].Key, txt("a")), txt("slice key"));
|
||||||
|
expect(str_are_equal(slots[0].Value, txt("X")), txt("slice value"));
|
||||||
|
strbuilder_free(& output);
|
||||||
|
|
||||||
|
slice.Ptr[0].Value = txt("Z");
|
||||||
|
StrBuilder mutated_output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
bool mutated_appended = strbuilder_append_template(& mutated_output, slice, txt("<b><a><b>"));
|
||||||
|
expect(mutated_appended, txt("slice mutate append"));
|
||||||
|
expect(str_are_equal(strbuilder_to_str(mutated_output), txt("YZY")), txt("slice mutate text"));
|
||||||
|
strbuilder_free(& mutated_output);
|
||||||
|
|
||||||
|
Slice_StrTemplateSlot empty_slice = { nullptr, 0 };
|
||||||
|
StrBuilder empty_output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
expect(strbuilder_append_str(& empty_output, txt("KEEP")), txt("zero slice prefix"));
|
||||||
|
bool empty_appended = strbuilder_append_template(& empty_output, empty_slice, txt("none"));
|
||||||
|
expect(empty_appended, txt("zero slice append"));
|
||||||
|
expect(str_are_equal(strbuilder_to_str(empty_output), txt("KEEPnone")), txt("zero slice text"));
|
||||||
|
expect(empty_slice.Ptr == nullptr, txt("zero slice pointer"));
|
||||||
|
expect(empty_slice.Len == 0, txt("zero slice length"));
|
||||||
|
strbuilder_free(& empty_output);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_wrapper() {
|
||||||
|
using namespace gen;
|
||||||
|
StrBuilder output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
expect(strbuilder_append_str(& output, txt("KEEP")), txt("wrapper prefix"));
|
||||||
|
|
||||||
|
bool appended = false;
|
||||||
|
strtmpl_append(& output, appended,
|
||||||
|
strtmpl_slots(
|
||||||
|
strtmpl_slot("name", txt("world")),
|
||||||
|
strtmpl_slot("tail", txt("!"))
|
||||||
|
),
|
||||||
|
txt("hello <name>\n<name><tail>")
|
||||||
|
);
|
||||||
|
expect(appended, txt("wrapper multiline result"));
|
||||||
|
|
||||||
|
Str got = strbuilder_to_str(output);
|
||||||
|
expect(str_starts_with(got, txt("KEEP")), txt("wrapper prefix kept"));
|
||||||
|
expect(str_are_equal (got, txt("KEEPhello world\nworld!")), txt("wrapper multiline text"));
|
||||||
|
strbuilder_free(& output);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_wrapper_scope()
|
||||||
|
{
|
||||||
|
using namespace gen;
|
||||||
|
StrBuilder then_output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
StrBuilder else_output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
expect(strbuilder_append_str(& then_output, txt("KEEP")), txt("wrapper then prefix"));
|
||||||
|
expect(strbuilder_append_str(& else_output, txt("KEEP")), txt("wrapper else prefix"));
|
||||||
|
bool then_result = false;
|
||||||
|
bool else_result = false;
|
||||||
|
s32 selector = 1;
|
||||||
|
s32 after_branch = 0;
|
||||||
|
if (selector == 1) strtmpl_append(& then_output, then_result, strtmpl_slots(strtmpl_slot("arm", txt("THEN"))), txt("<arm>"));
|
||||||
|
else strtmpl_append(& else_output, else_result, strtmpl_slots(strtmpl_slot("arm", txt("ELSE"))), txt("<arm>"));
|
||||||
|
|
||||||
|
after_branch = 1;
|
||||||
|
expect(after_branch == 1, txt("wrapper then continues"));
|
||||||
|
expect(then_result, txt("wrapper then assigned"));
|
||||||
|
expect(else_result == false, txt("wrapper else skipped"));
|
||||||
|
expect(str_are_equal(strbuilder_to_str(then_output), txt("KEEPTHEN")), txt("wrapper then text"));
|
||||||
|
expect(str_are_equal(strbuilder_to_str(else_output), txt("KEEP")), txt("wrapper else untouched"));
|
||||||
|
strbuilder_free(& then_output);
|
||||||
|
strbuilder_free(& else_output);
|
||||||
|
|
||||||
|
then_output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
else_output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
expect(strbuilder_append_str(& then_output, txt("KEEP")), txt("wrapper skipped then prefix"));
|
||||||
|
expect(strbuilder_append_str(& else_output, txt("KEEP")), txt("wrapper taken else prefix"));
|
||||||
|
|
||||||
|
then_result = false;
|
||||||
|
else_result = false;
|
||||||
|
selector = 0;
|
||||||
|
after_branch = 0;
|
||||||
|
if (selector == 1) strtmpl_append(& then_output, then_result, strtmpl_slots(strtmpl_slot("arm", txt("THEN"))), txt("<arm>"));
|
||||||
|
else strtmpl_append(& else_output, else_result, strtmpl_slots(strtmpl_slot("arm", txt("ELSE"))), txt("<arm>"));
|
||||||
|
|
||||||
|
after_branch = 1;
|
||||||
|
expect(after_branch == 1, txt("wrapper else continues"));
|
||||||
|
expect(then_result == false, txt("wrapper then skipped"));
|
||||||
|
expect(else_result, txt("wrapper else assigned"));
|
||||||
|
expect(str_are_equal(strbuilder_to_str(then_output), txt("KEEP")), txt("wrapper then untouched"));
|
||||||
|
expect(str_are_equal(strbuilder_to_str(else_output), txt("KEEPELSE")), txt("wrapper else text"));
|
||||||
|
strbuilder_free(& then_output);
|
||||||
|
strbuilder_free(& else_output);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_wrapper_once() {
|
||||||
|
using namespace gen;
|
||||||
|
s32 value_reads = 0;
|
||||||
|
s32 format_reads = 0;
|
||||||
|
s32 output_reads = 0;
|
||||||
|
s32 result_reads = 0;
|
||||||
|
StrBuilder output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
expect(strbuilder_append_str(& output, txt("KEEP")), txt("wrapper once prefix"));
|
||||||
|
|
||||||
|
bool appended = false;
|
||||||
|
strtmpl_append(
|
||||||
|
counted_template_output(& output, & output_reads),
|
||||||
|
counted_template_result(& appended, & result_reads)[0],
|
||||||
|
strtmpl_slots(
|
||||||
|
strtmpl_slot("k", counted_template_value(& value_reads)),
|
||||||
|
strtmpl_slot("tail", txt("Z"))
|
||||||
|
),
|
||||||
|
counted_template_format(& format_reads)
|
||||||
|
);
|
||||||
|
expect(appended, txt("wrapper once result"));
|
||||||
|
expect(value_reads == 1, txt("wrapper value once"));
|
||||||
|
expect(format_reads == 1, txt("wrapper format once"));
|
||||||
|
expect(output_reads == 1, txt("wrapper output once"));
|
||||||
|
expect(result_reads == 1, txt("wrapper result once"));
|
||||||
|
expect(str_are_equal(strbuilder_to_str(output), txt("KEEPONCE:ONCE")), txt("wrapper once text"));
|
||||||
|
strbuilder_free(& output);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_wrapper_resize_fail() {
|
||||||
|
using namespace gen;
|
||||||
|
s32 attempts = 0;
|
||||||
|
AllocatorInfo alloc = {};
|
||||||
|
alloc.Proc = resize_fail_allocator_proc;
|
||||||
|
alloc.Data = & attempts;
|
||||||
|
|
||||||
|
StrBuilder output = strbuilder_make_reserve(alloc, 4);
|
||||||
|
expect(strbuilder_capacity(output) == 4, txt("wrapper resize capacity"));
|
||||||
|
expect(strbuilder_append_str(& output, txt("KEEP")), txt("wrapper resize prefix"));
|
||||||
|
bool appended = true;
|
||||||
|
strtmpl_append(
|
||||||
|
& output,
|
||||||
|
appended,
|
||||||
|
strtmpl_slots(strtmpl_slot("blob", txt("X"))),
|
||||||
|
txt("<blob>")
|
||||||
|
);
|
||||||
|
expect(appended == false, txt("wrapper resize assigned false"));
|
||||||
|
expect(str_are_equal(strbuilder_to_str(output), txt("KEEP")), txt("wrapper resize keep"));
|
||||||
|
expect(attempts > 0, txt("wrapper resize attempts"));
|
||||||
|
strbuilder_free(& output);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_template_slot_literal()
|
||||||
|
{
|
||||||
|
using namespace gen;
|
||||||
|
Str value = txt("V");
|
||||||
|
StrTemplateSlot slot = strtmpl_slot("k", value);
|
||||||
|
expect(str_are_equal(slot.Key, txt("k")), txt("slot literal key text"));
|
||||||
|
expect(slot.Key.Ptr[slot.Key.Len] == '\0', txt("slot literal key terminator"));
|
||||||
|
expect(slot.Value.Ptr == value.Ptr, txt("slot literal value pointer"));
|
||||||
|
expect(slot.Value.Len == value.Len, txt("slot literal value length"));
|
||||||
|
|
||||||
|
Str assigned = txt("W");
|
||||||
|
slot = strtmpl_slot("key", assigned);
|
||||||
|
expect(str_are_equal(slot.Key, txt("key")), txt("slot assign key"));
|
||||||
|
expect(slot.Value.Ptr == assigned.Ptr, txt("slot assign value pointer"));
|
||||||
|
expect(slot.Value.Len == assigned.Len, txt("slot assign value length"));
|
||||||
|
expect_template_text(txt("slot assign expansion"), txt("<key>"), & slot, 1, txt("W"));
|
||||||
|
|
||||||
|
StrTemplateSlot row[2] = {
|
||||||
|
strtmpl_slot("a", txt("X")),
|
||||||
|
strtmpl_slot("b", txt("Y"))
|
||||||
|
};
|
||||||
|
expect(str_are_equal(row[0].Value, txt("X")), txt("slot array value"));
|
||||||
|
expect(str_are_equal(row[1].Key, txt("b")), txt("slot array key"));
|
||||||
|
expect_template_text(txt("slot array entry"), txt("<b><a>"), row, 2, txt("YX"));
|
||||||
|
|
||||||
|
StrBuilder output = strbuilder_make_reserve(heap(), 1);
|
||||||
|
expect(strbuilder_append_str(& output, txt("KEEP")), txt("slot wrapper prefix"));
|
||||||
|
bool appended = false;
|
||||||
|
strtmpl_append(
|
||||||
|
& output,
|
||||||
|
appended,
|
||||||
|
strtmpl_slots(
|
||||||
|
strtmpl_slot("name", txt("world")),
|
||||||
|
strtmpl_slot("tail", txt("!"))
|
||||||
|
),
|
||||||
|
txt("<name><tail>")
|
||||||
|
);
|
||||||
|
expect(appended, txt("slot wrapper result"));
|
||||||
|
expect(str_are_equal(strbuilder_to_str(output), txt("KEEPworld!")), txt("slot wrapper text"));
|
||||||
|
strbuilder_free(& output);
|
||||||
|
|
||||||
|
StrTemplateSlot long_key = strtmpl_slot("operands[0]", txt("eax"));
|
||||||
|
expect(str_are_equal(long_key.Key, txt("operands[0]")), txt("slot literal key equal"));
|
||||||
|
expect(long_key.Key.Ptr[long_key.Key.Len] == '\0', txt("slot literal key excludes nul"));
|
||||||
|
expect(str_are_equal(long_key.Value, txt("eax")), txt("slot literal value"));
|
||||||
|
|
||||||
|
s32 value_reads = 0;
|
||||||
|
StrTemplateSlot once = strtmpl_slot("k", counted_template_value(& value_reads));
|
||||||
|
expect(value_reads == 1, txt("slot value once"));
|
||||||
|
expect(str_are_equal(once.Value, txt("ONCE")), txt("slot value once text"));
|
||||||
|
expect(once.Key.Len == 1, txt("slot value once key"));
|
||||||
|
|
||||||
|
char nul_bytes[4] = { 'a', '\0', 'b', '!' };
|
||||||
|
Str nul_value = { nul_bytes, 3 };
|
||||||
|
StrTemplateSlot nul_slot = strtmpl_slot("n", nul_value);
|
||||||
|
expect(nul_slot.Value.Ptr == nul_bytes, txt("slot nul pointer"));
|
||||||
|
expect(nul_slot.Value.Len == 3, txt("slot nul length"));
|
||||||
|
expect(nul_slot.Value.Ptr[1] == '\0', txt("slot nul byte"));
|
||||||
|
|
||||||
|
char nul_expected[5] = { '[', 'a', '\0', 'b', ']' };
|
||||||
|
Str nul_expansion = { nul_expected, 5 };
|
||||||
|
expect_template_text(txt("slot nul expansion"), txt("[<n>]"), & nul_slot, 1, nul_expansion);
|
||||||
|
|
||||||
|
Str angle_value = txt("a<b>c");
|
||||||
|
StrTemplateSlot angle_slot = strtmpl_slot("raw", angle_value);
|
||||||
|
expect(angle_slot.Value.Ptr == angle_value.Ptr, txt("slot angle pointer"));
|
||||||
|
expect(angle_slot.Value.Len == angle_value.Len, txt("slot angle length"));
|
||||||
|
expect_template_text(txt("slot angle expansion"), txt("<raw>"), & angle_slot, 1, txt("a<b>c"));
|
||||||
|
|
||||||
|
Str empty_value = { nullptr, 0 };
|
||||||
|
StrTemplateSlot empty_slot = strtmpl_slot("e", empty_value);
|
||||||
|
expect(empty_slot.Value.Ptr == nullptr, txt("slot null value pointer"));
|
||||||
|
expect(empty_slot.Value.Len == 0, txt("slot null value length"));
|
||||||
|
expect_template_text(txt("slot null value expansion"), txt("A<e>B"), & empty_slot, 1, txt("AB"));
|
||||||
|
|
||||||
|
Str percent_value = txt("%d:%S");
|
||||||
|
StrTemplateSlot percent_slot = strtmpl_slot("fmt", percent_value);
|
||||||
|
expect(percent_slot.Value.Ptr == percent_value.Ptr, txt("slot percent value pointer"));
|
||||||
|
expect(str_are_equal(percent_slot.Value, txt("%d:%S")), txt("slot percent value text"));
|
||||||
|
expect_template_text(txt("slot percent literal"), txt("pre %d:%S <fmt>"), & percent_slot, 1, txt("pre %d:%S %d:%S"));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void expect_text_template(gen::ssize printf_maxlen) {
|
||||||
|
expect_template_shapes();
|
||||||
|
expect_template_lookup();
|
||||||
|
expect_template_crc_collision();
|
||||||
|
gen::expect_template_boundaries();
|
||||||
|
expect_template_growth(printf_maxlen);
|
||||||
|
expect_template_resize_fail(printf_maxlen);
|
||||||
|
expect_template_slice();
|
||||||
|
expect_template_wrapper();
|
||||||
|
expect_template_wrapper_scope();
|
||||||
|
expect_template_wrapper_once();
|
||||||
|
expect_template_wrapper_resize_fail();
|
||||||
|
expect_template_slot_literal();
|
||||||
|
}
|
||||||
+488
-3
@@ -30,10 +30,23 @@ internal void expect_variable(gen::CodeVar var, gen::Str label) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void expect_parse_result(gen::Code result, gen::ParseInfo* info, gen::CodeType expected, gen::Str label) {
|
||||||
|
expect(result.ast != nullptr, label);
|
||||||
|
if (result.ast != nullptr) expect(result->Type == expected, label);
|
||||||
|
expect(info->result.ast == result.ast, label);
|
||||||
|
expect(info->lexed.tokens.num > 0, label);
|
||||||
|
expect(info->lexed.messages == nullptr && info->messages == nullptr, label);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "dependencies/strings.cpp"
|
||||||
|
#include "dependencies/simd.cpp"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
using namespace gen;
|
using namespace gen;
|
||||||
Context ctx = {}; init(&ctx);
|
Context ctx = {}; init(&ctx);
|
||||||
|
expect_text_template(GEN_PRINTF_MAXLEN);
|
||||||
|
expect_simd_lanes();
|
||||||
|
|
||||||
Opts_def_type type_opts = {};
|
Opts_def_type type_opts = {};
|
||||||
type_opts.specifiers = def_specifiers(args(Spec_Const, Spec_Ptr));
|
type_opts.specifiers = def_specifiers(args(Spec_Const, Spec_Ptr));
|
||||||
@@ -452,14 +465,486 @@ int main()
|
|||||||
expect(str_contains(cast_text, txt("return 0")), txt("cpp operator cast body serialization"));
|
expect(str_contains(cast_text, txt("return 0")), txt("cpp operator cast body serialization"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Code untyped = code_str(char const* baseline_message = "GENCPP_BASELINE";); expect(untyped.ast != nullptr, txt("cpp untyped"));
|
Code untyped = code_str(char const* baseline_message = "GENCPP_BASELINE";);
|
||||||
Str untyped_text = strbuilder_to_str(code_to_strbuilder(untyped)); expect_fragments(untyped_text, txt("cpp untyped content"));
|
Str untyped_text = strbuilder_to_str(code_to_strbuilder(untyped));
|
||||||
CodeVar parsed_untyped = parse_variable(untyped_text); expect_variable(parsed_untyped, txt("cpp untyped reparsed"));
|
CodeVar parsed_untyped = parse_variable(untyped_text);
|
||||||
|
expect(untyped.ast != nullptr, txt("cpp untyped"));
|
||||||
|
expect_fragments(untyped_text, txt("cpp untyped content"));
|
||||||
|
expect_variable(parsed_untyped, txt("cpp untyped reparsed"));
|
||||||
|
|
||||||
CodeVar parsed = parse_variable(code(char const* baseline_message = "GENCPP_BASELINE"; ));
|
CodeVar parsed = parse_variable(code(char const* baseline_message = "GENCPP_BASELINE"; ));
|
||||||
expect_variable(parsed, txt("cpp parsed"));
|
expect_variable(parsed, txt("cpp parsed"));
|
||||||
expect_fragments(strbuilder_to_str(code_to_strbuilder((Code)parsed)), txt("cpp parsed serialized"));
|
expect_fragments(strbuilder_to_str(code_to_strbuilder((Code)parsed)), txt("cpp parsed serialized"));
|
||||||
|
|
||||||
|
CodeClass parser_class = parse_class(txt("class ParseClass {};"));
|
||||||
|
CodeConstructor parser_constructor = parse_constructor(txt("ParseClass() {}"));
|
||||||
|
CodeDefine parser_define = parse_define(txt("#define PARSE_DEFINE 1"));
|
||||||
|
CodeDestructor parser_destructor = parse_destructor(txt("~ParseClass();"));
|
||||||
|
CodeEnum parser_enum = parse_enum(txt("enum ParseEnum { ParseValue };"));
|
||||||
|
CodeBody parser_export_body = parse_export_body(txt("{ int export_value; }"));
|
||||||
|
CodeExtern parser_extern = parse_extern_link(txt("extern \"C\" { int extern_value; }"));
|
||||||
|
CodeFriend parser_friend = parse_friend(txt("friend int parse_friend_function();"));
|
||||||
|
CodeFn parser_function = parse_function(txt("int parse_function();"));
|
||||||
|
CodeBody parser_global_body = parse_global_body(txt("struct ParseGlobal { int value; };"));
|
||||||
|
CodeNS parser_namespace = parse_namespace(txt("namespace ParseNamespace {}"));
|
||||||
|
CodeOperator parser_operator = parse_operator(txt("s32 operator +(s32 lhs, s32 rhs);"));
|
||||||
|
CodeOpCast parser_operator_cast = parse_operator_cast(txt("operator s32() const;"));
|
||||||
|
CodeStruct parser_struct = parse_struct(txt("struct ParseStruct {};"));
|
||||||
|
CodeTemplate parser_template = parse_template(txt("template<class T> struct ParseTemplate {};"));
|
||||||
|
CodeTypename parser_type = parse_type(txt("const s32*"));
|
||||||
|
CodeTypedef parser_typedef = parse_typedef(txt("typedef s32 ParseTypedef;"));
|
||||||
|
CodeUnion parser_union = parse_union(txt("union ParseUnion { s32 value; };"));
|
||||||
|
CodeUsing parser_using = parse_using(txt("using ParseUsing = s32;"));
|
||||||
|
CodeVar parser_variable = parse_variable(txt("s32 parse_variable;"));
|
||||||
|
|
||||||
|
expect(parser_class.ast != nullptr && parser_class->Type == CT_Class, txt("cpp parse class fixture"));
|
||||||
|
expect(parser_constructor.ast != nullptr && parser_constructor->Type == CT_Constructor, txt("cpp parse constructor fixture"));
|
||||||
|
expect(parser_define.ast != nullptr && parser_define->Type == CT_Preprocess_Define, txt("cpp parse define fixture"));
|
||||||
|
expect(parser_destructor.ast != nullptr && parser_destructor->Type == CT_Destructor_Fwd, txt("cpp parse destructor fixture"));
|
||||||
|
expect(parser_enum.ast != nullptr && parser_enum->Type == CT_Enum, txt("cpp parse enum fixture"));
|
||||||
|
expect(parser_export_body.ast != nullptr && parser_export_body->Type == CT_Export_Body, txt("cpp parse export body fixture"));
|
||||||
|
expect(parser_extern.ast != nullptr && parser_extern->Type == CT_Extern_Linkage, txt("cpp parse extern fixture"));
|
||||||
|
expect(parser_friend.ast != nullptr && parser_friend->Type == CT_Friend, txt("cpp parse friend fixture"));
|
||||||
|
expect(parser_function.ast != nullptr && parser_function->Type == CT_Function_Fwd, txt("cpp parse function fixture"));
|
||||||
|
expect(parser_global_body.ast != nullptr && parser_global_body->Type == CT_Global_Body, txt("cpp parse global body fixture"));
|
||||||
|
expect(parser_namespace.ast != nullptr && parser_namespace->Type == CT_Namespace, txt("cpp parse namespace fixture"));
|
||||||
|
expect(parser_operator.ast != nullptr && parser_operator->Type == CT_Operator_Fwd, txt("cpp parse operator fixture"));
|
||||||
|
expect(parser_operator_cast.ast != nullptr && parser_operator_cast->Type == CT_Operator_Cast_Fwd, txt("cpp parse operator cast fixture"));
|
||||||
|
expect(parser_struct.ast != nullptr && parser_struct->Type == CT_Struct, txt("cpp parse struct fixture"));
|
||||||
|
expect(parser_template.ast != nullptr && parser_template->Type == CT_Template, txt("cpp parse template fixture"));
|
||||||
|
expect(parser_type.ast != nullptr && parser_type->Type == CT_Typename, txt("cpp parse type fixture"));
|
||||||
|
expect(parser_typedef.ast != nullptr && parser_typedef->Type == CT_Typedef, txt("cpp parse typedef fixture"));
|
||||||
|
expect(parser_union.ast != nullptr && parser_union->Type == CT_Union, txt("cpp parse union fixture"));
|
||||||
|
expect(parser_using.ast != nullptr && parser_using->Type == CT_Using, txt("cpp parse using fixture"));
|
||||||
|
expect(parser_variable.ast != nullptr && parser_variable->Type == CT_Variable, txt("cpp parse variable fixture"));
|
||||||
|
|
||||||
|
CodeBody parsed_global_options = parse_global_body(txt("struct ParseGlobalOptions { s32 value; };"));
|
||||||
|
Code global_options_code = parsed_global_options;
|
||||||
|
expect(parsed_global_options.ast != nullptr, txt("cpp parse global body options"));
|
||||||
|
expect(ctx.parse_info.result.ast == global_options_code.ast, txt("cpp default parse info result"));
|
||||||
|
expect(ctx.parse_info.lexed.tokens.num > 0, txt("cpp default parse info tokens"));
|
||||||
|
expect(ctx.parse_info.lexed.messages == nullptr && ctx.parse_info.messages == nullptr, txt("cpp default parse info messages"));
|
||||||
|
|
||||||
|
ParseInfo caller_info = {};
|
||||||
|
Opts_parse parse_options = { & ctx, & caller_info };
|
||||||
|
CodeVar parsed_option_variable = parse_variable(txt("s32 parsed_option_variable;"), parse_options);
|
||||||
|
Code parsed_option_code = parsed_option_variable;
|
||||||
|
expect(parsed_option_variable.ast != nullptr && parsed_option_variable->Type == CT_Variable, txt("cpp explicit parse variable options"));
|
||||||
|
expect(str_contains(parsed_option_variable->Name, txt("parsed_option_variable")), txt("cpp explicit parse variable name"));
|
||||||
|
expect(caller_info.result.ast == parsed_option_code.ast, txt("cpp explicit parse info result"));
|
||||||
|
expect(caller_info.lexed.tokens.num > 0, txt("cpp explicit parse info tokens"));
|
||||||
|
|
||||||
|
ParseInfo lexer_info = {};
|
||||||
|
Opts_parse lexer_options = { & ctx, & lexer_info };
|
||||||
|
CodeVar parsed_lexer_prefix = parse_variable(txt("s32 parsed_lexer_prefix;@"), lexer_options);
|
||||||
|
Code parsed_lexer_code = parsed_lexer_prefix;
|
||||||
|
expect(parsed_lexer_prefix.ast != nullptr && parsed_lexer_prefix->Type == CT_Variable, txt("cpp parse lexer prefix result"));
|
||||||
|
expect(lexer_info.result.ast == parsed_lexer_code.ast, txt("cpp parse lexer prefix info result"));
|
||||||
|
expect(lexer_info.lexed.tokens.num > 0, txt("cpp parse lexer prefix retained tokens"));
|
||||||
|
expect(lexer_info.lexed.messages != nullptr, txt("cpp parse lexer prefix diagnostic"));
|
||||||
|
|
||||||
|
expect_parse_result(parse_class (txt("class ParseClass {};"), parse_options), & caller_info, CT_Class, txt("cpp class options matrix"));
|
||||||
|
expect_parse_result(parse_constructor (txt("ParseClass() {}"), parse_options), & caller_info, CT_Constructor, txt("cpp constructor options matrix"));
|
||||||
|
expect_parse_result(parse_define (txt("#define PARSE_DEFINE 1"), parse_options), & caller_info, CT_Preprocess_Define, txt("cpp define options matrix"));
|
||||||
|
expect_parse_result(parse_destructor (txt("~ParseClass();"), parse_options), & caller_info, CT_Destructor_Fwd, txt("cpp destructor options matrix"));
|
||||||
|
expect_parse_result(parse_enum (txt("enum ParseEnum { ParseValue };"), parse_options), & caller_info, CT_Enum, txt("cpp enum options matrix"));
|
||||||
|
expect_parse_result(parse_export_body (txt("{ int export_value; }"), parse_options), & caller_info, CT_Export_Body, txt("cpp export body options matrix"));
|
||||||
|
expect_parse_result(parse_extern_link (txt("extern \"C\" { int extern_value; }"), parse_options), & caller_info, CT_Extern_Linkage, txt("cpp extern options matrix"));
|
||||||
|
expect_parse_result(parse_friend (txt("friend int parse_friend_function();"), parse_options), & caller_info, CT_Friend, txt("cpp friend options matrix"));
|
||||||
|
expect_parse_result(parse_function (txt("int parse_function();"), parse_options), & caller_info, CT_Function_Fwd, txt("cpp function options matrix"));
|
||||||
|
expect_parse_result(parse_global_body (txt("struct ParseGlobal { int value; };"), parse_options), & caller_info, CT_Global_Body, txt("cpp global body options matrix"));
|
||||||
|
expect_parse_result(parse_namespace (txt("namespace ParseNamespace {}"), parse_options), & caller_info, CT_Namespace, txt("cpp namespace options matrix"));
|
||||||
|
expect_parse_result(parse_operator (txt("s32 operator +(s32 lhs, s32 rhs);"), parse_options), & caller_info, CT_Operator_Fwd, txt("cpp operator options matrix"));
|
||||||
|
expect_parse_result(parse_operator_cast(txt("operator s32() const;"), parse_options), & caller_info, CT_Operator_Cast_Fwd, txt("cpp operator cast options matrix"));
|
||||||
|
expect_parse_result(parse_struct (txt("struct ParseStruct {};"), parse_options), & caller_info, CT_Struct, txt("cpp struct options matrix"));
|
||||||
|
expect_parse_result(parse_template (txt("template<class T> struct ParseTemplate {};"), parse_options), & caller_info, CT_Template, txt("cpp template options matrix"));
|
||||||
|
expect_parse_result(parse_type (txt("const s32*"), parse_options), & caller_info, CT_Typename, txt("cpp type options matrix"));
|
||||||
|
expect_parse_result(parse_typedef (txt("typedef s32 ParseTypedef;"), parse_options), & caller_info, CT_Typedef, txt("cpp typedef options matrix"));
|
||||||
|
expect_parse_result(parse_union (txt("union ParseUnion { s32 value; };"), parse_options), & caller_info, CT_Union, txt("cpp union options matrix"));
|
||||||
|
expect_parse_result(parse_using (txt("using ParseUsing = s32;"), parse_options), & caller_info, CT_Using, txt("cpp using options matrix"));
|
||||||
|
expect_parse_result(parse_variable (txt("s32 parse_variable;"), parse_options), & caller_info, CT_Variable, txt("cpp variable options matrix"));
|
||||||
|
|
||||||
|
ParseInfo comma_info = {};
|
||||||
|
Opts_parse comma_options = { &ctx, &comma_info };
|
||||||
|
CodeBody parsed_comma_body = parse_global_body(txt("struct ParseComma { s32 value; };\n,"), comma_options);
|
||||||
|
Code parsed_comma_code = parsed_comma_body;
|
||||||
|
expect(parsed_comma_body.ast != nullptr && parsed_comma_body->Type == CT_Global_Body, txt("cpp comma parser result"));
|
||||||
|
expect(comma_info.result.ast == parsed_comma_code.ast, txt("cpp comma ParseInfo result"));
|
||||||
|
expect(comma_info.lexed.tokens.num > 0 && comma_info.lexed.messages == nullptr, txt("cpp comma retained tokens"));
|
||||||
|
expect(comma_info.messages != nullptr, txt("cpp comma parser diagnostic"));
|
||||||
|
if (comma_info.messages != nullptr)
|
||||||
|
expect(str_contains(comma_info.messages->Content, txt("Dangling comma")), txt("cpp comma diagnostic content"));
|
||||||
|
|
||||||
|
ParseInfo recovery_info = {};
|
||||||
|
Opts_parse recovery_options = { &ctx, &recovery_info };
|
||||||
|
CodeBody recovered_body = parse_global_body(txt("s32 before; s32 broken(s32 value; s32 after;"), recovery_options);
|
||||||
|
Str recovery_text = { nullptr, 0 };
|
||||||
|
if (recovered_body.ast != nullptr)
|
||||||
|
recovery_text = strbuilder_to_str(code_to_strbuilder((Code)recovered_body));
|
||||||
|
expect(recovered_body.ast != nullptr && recovered_body->Type == CT_Global_Body, txt("cpp file-scope recovery body"));
|
||||||
|
expect(recovery_info.result.ast == ((Code)recovered_body).ast, txt("cpp file-scope recovery ParseInfo result"));
|
||||||
|
expect(recovery_info.messages != nullptr, txt("cpp file-scope recovery diagnostic"));
|
||||||
|
if (recovery_info.messages != nullptr)
|
||||||
|
expect(str_contains(recovery_info.messages->Content, txt("Expected")), txt("cpp file-scope recovery mismatch text"));
|
||||||
|
if (recovery_info.messages != nullptr)
|
||||||
|
expect(recovery_info.messages->Next == nullptr, txt("cpp file-scope recovery single diagnostic"));
|
||||||
|
expect(str_contains(recovery_text, txt("before")), txt("cpp file-scope recovery keeps preceding member"));
|
||||||
|
expect(str_contains(recovery_text, txt("after")), txt("cpp file-scope recovery keeps following member"));
|
||||||
|
Code recovered_member = { nullptr };
|
||||||
|
if (recovered_body.ast != nullptr) recovered_member = recovered_body->Front;
|
||||||
|
Code recovered_before = recovered_member;
|
||||||
|
expect(recovered_before != nullptr && recovered_before->Type == CT_Variable, txt("cpp mismatch recovery keeps preceding member typed"));
|
||||||
|
if (recovered_before)
|
||||||
|
expect(str_are_equal(recovered_before->Name, txt("before")), txt("cpp mismatch recovery preceding member name"));
|
||||||
|
if (recovered_member) recovered_member = recovered_member->Next;
|
||||||
|
expect(recovered_member != nullptr && recovered_member->Type == CT_Untyped, txt("cpp file-scope recovery stores malformed member as untyped"));
|
||||||
|
if (recovered_member)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(recovered_member)), txt("s32 broken(s32 value;")), txt("cpp file-scope recovery retains exact mismatch span"));
|
||||||
|
Code recovered_after = recovered_member ? recovered_member->Next : Code{ nullptr };
|
||||||
|
expect(recovered_after != nullptr && recovered_after->Type == CT_Variable, txt("cpp file-scope recovery keeps following member typed"));
|
||||||
|
if (recovered_after)
|
||||||
|
expect(str_are_equal(recovered_after->Name, txt("after")), txt("cpp file-scope recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo invalid_member_info = {};
|
||||||
|
Opts_parse invalid_member_options = { &ctx, &invalid_member_info };
|
||||||
|
CodeBody invalid_member_body = parse_global_body(txt("s32 before; = { 1; 2 }; s32 after;"), invalid_member_options);
|
||||||
|
Str invalid_member_text = { nullptr, 0 };
|
||||||
|
if (invalid_member_body.ast != nullptr)
|
||||||
|
invalid_member_text = strbuilder_to_str(code_to_strbuilder((Code)invalid_member_body));
|
||||||
|
expect(invalid_member_body.ast != nullptr && invalid_member_body->Type == CT_Global_Body, txt("cpp invalid member recovery body"));
|
||||||
|
expect(invalid_member_info.result.ast == ((Code)invalid_member_body).ast, txt("cpp invalid member recovery ParseInfo result"));
|
||||||
|
expect(invalid_member_info.messages != nullptr, txt("cpp invalid member recovery diagnostic"));
|
||||||
|
if (invalid_member_info.messages != nullptr) {
|
||||||
|
expect(str_contains(invalid_member_info.messages->Content, txt("Failed to parse member")), txt("cpp invalid member recovery diagnostic text"));
|
||||||
|
expect(invalid_member_info.messages->Next == nullptr, txt("cpp invalid member recovery single diagnostic"));
|
||||||
|
}
|
||||||
|
expect(str_contains(invalid_member_text, txt("before")), txt("cpp invalid member recovery keeps preceding member"));
|
||||||
|
expect(str_contains(invalid_member_text, txt("after")), txt("cpp invalid member recovery keeps following member"));
|
||||||
|
Code invalid_member_node = { nullptr };
|
||||||
|
if (invalid_member_body.ast != nullptr) invalid_member_node = invalid_member_body->Front;
|
||||||
|
Code invalid_member_before = invalid_member_node;
|
||||||
|
expect(invalid_member_before != nullptr && invalid_member_before->Type == CT_Variable, txt("cpp invalid member keeps preceding member typed"));
|
||||||
|
if (invalid_member_before)
|
||||||
|
expect(str_are_equal(invalid_member_before->Name, txt("before")), txt("cpp invalid member preceding member name"));
|
||||||
|
if (invalid_member_node) invalid_member_node = invalid_member_node->Next;
|
||||||
|
expect(invalid_member_node != nullptr && invalid_member_node->Type == CT_Untyped, txt("cpp invalid member recovery stores member as untyped"));
|
||||||
|
if (invalid_member_node)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(invalid_member_node)), txt("= { 1; 2 };")), txt("cpp invalid member recovery retains exact source span"));
|
||||||
|
Code invalid_member_after = invalid_member_node ? invalid_member_node->Next : Code{ nullptr };
|
||||||
|
expect(invalid_member_after != nullptr && invalid_member_after->Type == CT_Variable, txt("cpp invalid member recovery keeps following member typed"));
|
||||||
|
if (invalid_member_after)
|
||||||
|
expect(str_are_equal(invalid_member_after->Name, txt("after")), txt("cpp invalid member recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo import_recovery_info = {};
|
||||||
|
Opts_parse import_recovery_options = { &ctx, &import_recovery_info };
|
||||||
|
CodeBody import_recovery_body = parse_global_body(txt("s32 before; import foo; s32 after;"), import_recovery_options);
|
||||||
|
Code import_recovery_node = { nullptr };
|
||||||
|
if (import_recovery_body.ast != nullptr) import_recovery_node = import_recovery_body->Front;
|
||||||
|
Code import_recovery_before = import_recovery_node;
|
||||||
|
expect(import_recovery_before != nullptr && import_recovery_before->Type == CT_Variable, txt("cpp import recovery keeps preceding member typed"));
|
||||||
|
if (import_recovery_before)
|
||||||
|
expect(str_are_equal(import_recovery_before->Name, txt("before")), txt("cpp import recovery preceding member name"));
|
||||||
|
if (import_recovery_node) import_recovery_node = import_recovery_node->Next;
|
||||||
|
expect(import_recovery_body.ast != nullptr && import_recovery_body->Type == CT_Global_Body, txt("cpp import recovery body"));
|
||||||
|
expect(import_recovery_info.messages != nullptr, txt("cpp import recovery diagnostic"));
|
||||||
|
if (import_recovery_info.messages != nullptr)
|
||||||
|
expect(import_recovery_info.messages->Next == nullptr, txt("cpp import recovery single diagnostic"));
|
||||||
|
expect(import_recovery_node != nullptr && import_recovery_node->Type == CT_Untyped, txt("cpp import recovery preserves member as untyped"));
|
||||||
|
if (import_recovery_node)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(import_recovery_node)), txt("import foo;")), txt("cpp import recovery exact source span"));
|
||||||
|
Code import_recovery_after = import_recovery_node ? import_recovery_node->Next : Code{ nullptr };
|
||||||
|
expect(import_recovery_after != nullptr && import_recovery_after->Type == CT_Variable, txt("cpp import recovery keeps following member typed"));
|
||||||
|
if (import_recovery_after)
|
||||||
|
expect(str_are_equal(import_recovery_after->Name, txt("after")), txt("cpp import recovery following member name"));
|
||||||
|
|
||||||
|
Macro unbounded_macro = { txt("UnboundedRecoveryMacro"), MT_Expression, MF_Null };
|
||||||
|
register_macro(unbounded_macro);
|
||||||
|
ParseInfo macro_recovery_info = {};
|
||||||
|
Opts_parse macro_recovery_options = { &ctx, ¯o_recovery_info };
|
||||||
|
CodeBody macro_recovery_body = parse_global_body(txt("s32 before; UnboundedRecoveryMacro; s32 after;"), macro_recovery_options);
|
||||||
|
Code macro_recovery_node = { nullptr };
|
||||||
|
if (macro_recovery_body.ast != nullptr) macro_recovery_node = macro_recovery_body->Front;
|
||||||
|
Code macro_recovery_before = macro_recovery_node;
|
||||||
|
expect(macro_recovery_before != nullptr && macro_recovery_before->Type == CT_Variable, txt("cpp macro recovery keeps preceding member typed"));
|
||||||
|
if (macro_recovery_before)
|
||||||
|
expect(str_are_equal(macro_recovery_before->Name, txt("before")), txt("cpp macro recovery preceding member name"));
|
||||||
|
if (macro_recovery_node) macro_recovery_node = macro_recovery_node->Next;
|
||||||
|
expect(macro_recovery_body.ast != nullptr && macro_recovery_body->Type == CT_Global_Body, txt("cpp unbounded macro recovery body"));
|
||||||
|
expect(macro_recovery_info.messages != nullptr, txt("cpp unbounded macro recovery diagnostic"));
|
||||||
|
if (macro_recovery_info.messages != nullptr)
|
||||||
|
expect(macro_recovery_info.messages->Next == nullptr, txt("cpp unbounded macro recovery single diagnostic"));
|
||||||
|
expect(macro_recovery_node != nullptr && macro_recovery_node->Type == CT_Untyped, txt("cpp unbounded macro recovery preserves member as untyped"));
|
||||||
|
if (macro_recovery_node)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(macro_recovery_node)), txt("UnboundedRecoveryMacro;")), txt("cpp unbounded macro recovery exact source span"));
|
||||||
|
Code macro_recovery_after = macro_recovery_node ? macro_recovery_node->Next : Code{ nullptr };
|
||||||
|
expect(macro_recovery_after != nullptr && macro_recovery_after->Type == CT_Variable, txt("cpp unbounded macro recovery keeps following member typed"));
|
||||||
|
if (macro_recovery_after)
|
||||||
|
expect(str_are_equal(macro_recovery_after->Name, txt("after")), txt("cpp unbounded macro recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo eof_recovery_info = {};
|
||||||
|
Opts_parse eof_recovery_options = { &ctx, &eof_recovery_info };
|
||||||
|
CodeBody eof_recovery_body = parse_global_body(txt("s32 before; s32 broken(s32 value"), eof_recovery_options);
|
||||||
|
Code eof_recovery_node = { nullptr };
|
||||||
|
if (eof_recovery_body.ast != nullptr) eof_recovery_node = eof_recovery_body->Front;
|
||||||
|
Code eof_recovery_before = eof_recovery_node;
|
||||||
|
expect(eof_recovery_before != nullptr && eof_recovery_before->Type == CT_Variable, txt("cpp EOF recovery keeps preceding member typed"));
|
||||||
|
if (eof_recovery_before)
|
||||||
|
expect(str_are_equal(eof_recovery_before->Name, txt("before")), txt("cpp EOF recovery preceding member name"));
|
||||||
|
if (eof_recovery_node) eof_recovery_node = eof_recovery_node->Next;
|
||||||
|
expect(eof_recovery_body.ast != nullptr && eof_recovery_body->Type == CT_Global_Body, txt("cpp end-of-slice recovery body"));
|
||||||
|
expect(eof_recovery_info.messages != nullptr, txt("cpp end-of-slice recovery diagnostic"));
|
||||||
|
if (eof_recovery_info.messages != nullptr)
|
||||||
|
expect(eof_recovery_info.messages->Next == nullptr, txt("cpp end-of-slice recovery single diagnostic"));
|
||||||
|
expect(eof_recovery_node != nullptr && eof_recovery_node->Type == CT_Untyped, txt("cpp end-of-slice member is untyped"));
|
||||||
|
if (eof_recovery_node)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(eof_recovery_node)), txt("s32 broken(s32 value")), txt("cpp end-of-slice recovery exact source span"));
|
||||||
|
if (eof_recovery_node)
|
||||||
|
expect(eof_recovery_node->Next == nullptr, txt("cpp end-of-slice recovery has no following node"));
|
||||||
|
|
||||||
|
ParseInfo comma_recovery_info = {};
|
||||||
|
Opts_parse comma_recovery_options = { &ctx, &comma_recovery_info };
|
||||||
|
CodeBody comma_recovery_body = parse_global_body(txt("s32 before; , s32 after;"), comma_recovery_options);
|
||||||
|
Code comma_recovery_node = { nullptr };
|
||||||
|
if (comma_recovery_body.ast != nullptr) comma_recovery_node = comma_recovery_body->Front;
|
||||||
|
Code comma_recovery_before = comma_recovery_node;
|
||||||
|
expect(comma_recovery_before != nullptr && comma_recovery_before->Type == CT_Variable, txt("cpp comma recovery keeps preceding member typed"));
|
||||||
|
if (comma_recovery_before)
|
||||||
|
expect(str_are_equal(comma_recovery_before->Name, txt("before")), txt("cpp comma recovery preceding member name"));
|
||||||
|
if (comma_recovery_node) comma_recovery_node = comma_recovery_node->Next;
|
||||||
|
expect(comma_recovery_body.ast != nullptr && comma_recovery_body->Type == CT_Global_Body, txt("cpp comma recovery body"));
|
||||||
|
expect(comma_recovery_info.messages != nullptr, txt("cpp comma recovery diagnostic"));
|
||||||
|
if (comma_recovery_info.messages != nullptr) {
|
||||||
|
expect(str_contains(comma_recovery_info.messages->Content, txt("Dangling comma")), txt("cpp comma recovery diagnostic text"));
|
||||||
|
expect(comma_recovery_info.messages->Next == nullptr, txt("cpp comma recovery single diagnostic"));
|
||||||
|
}
|
||||||
|
expect(comma_recovery_node != nullptr && comma_recovery_node->Type == CT_Untyped, txt("cpp comma recovery preserves token as untyped"));
|
||||||
|
if (comma_recovery_node)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(comma_recovery_node)), txt(",")), txt("cpp comma recovery exact source span"));
|
||||||
|
Code comma_recovery_after = comma_recovery_node ? comma_recovery_node->Next : Code{ nullptr };
|
||||||
|
expect(comma_recovery_after != nullptr && comma_recovery_after->Type == CT_Variable, txt("cpp comma recovery keeps following member typed"));
|
||||||
|
if (comma_recovery_after)
|
||||||
|
expect(str_are_equal(comma_recovery_after->Name, txt("after")), txt("cpp comma recovery following member name"));
|
||||||
|
|
||||||
|
CodeBody recovery_reuse = parse_global_body(txt("s32 reused_after_recovery;"), recovery_options);
|
||||||
|
Str recovery_reuse_text = { nullptr, 0 };
|
||||||
|
if (recovery_reuse.ast != nullptr)
|
||||||
|
recovery_reuse_text = strbuilder_to_str(code_to_strbuilder((Code)recovery_reuse));
|
||||||
|
expect(recovery_reuse.ast != nullptr && recovery_reuse->Type == CT_Global_Body, txt("cpp parser context reuse after recovery"));
|
||||||
|
expect(recovery_info.messages == nullptr, txt("cpp parser context reuse clears prior diagnostics"));
|
||||||
|
expect(str_contains(recovery_reuse_text, txt("reused_after_recovery")), txt("cpp parser context reuse parses later input"));
|
||||||
|
|
||||||
|
ParseInfo nested_struct_info = {};
|
||||||
|
Opts_parse nested_struct_options = { &ctx, &nested_struct_info };
|
||||||
|
CodeStruct nested_struct = parse_struct(txt("struct NestedRecovery { s32 before; s32 broken(s32 value; s32 after; };"), nested_struct_options);
|
||||||
|
expect(nested_struct.ast != nullptr && nested_struct->Type == CT_Struct, txt("cpp nested struct recovery result"));
|
||||||
|
expect(nested_struct_info.result.ast == ((Code)nested_struct).ast, txt("cpp nested struct recovery ParseInfo result"));
|
||||||
|
expect(nested_struct_info.messages != nullptr, txt("cpp nested struct recovery diagnostic"));
|
||||||
|
if (nested_struct_info.messages != nullptr)
|
||||||
|
expect(str_contains(nested_struct_info.messages->Content, txt("Expected")), txt("cpp nested struct recovery diagnostic text"));
|
||||||
|
Code nested_struct_member = nested_struct.ast != nullptr && nested_struct->Body.ast != nullptr ? nested_struct->Body->Front : Code{ nullptr };
|
||||||
|
expect(nested_struct_member != nullptr && nested_struct_member->Type == CT_Variable, txt("cpp nested struct recovery keeps preceding member typed"));
|
||||||
|
if (nested_struct_member != nullptr)
|
||||||
|
expect(str_are_equal(nested_struct_member->Name, txt("before")), txt("cpp nested struct recovery preceding member name"));
|
||||||
|
if (nested_struct_member != nullptr) nested_struct_member = nested_struct_member->Next;
|
||||||
|
expect(nested_struct_member != nullptr && nested_struct_member->Type == CT_Untyped, txt("cpp nested struct recovery retains failed member"));
|
||||||
|
if (nested_struct_member != nullptr)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(nested_struct_member)), txt("s32 broken(s32 value;")), txt("cpp nested struct recovery exact failed span"));
|
||||||
|
Code nested_struct_after = nested_struct_member != nullptr ? nested_struct_member->Next : Code{ nullptr };
|
||||||
|
expect(nested_struct_after != nullptr && nested_struct_after->Type == CT_Variable, txt("cpp nested struct recovery keeps following member typed"));
|
||||||
|
if (nested_struct_after != nullptr)
|
||||||
|
expect(str_are_equal(nested_struct_after->Name, txt("after")), txt("cpp nested struct recovery following member name"));
|
||||||
|
Str nested_struct_text = { nullptr, 0 };
|
||||||
|
if (nested_struct.ast != nullptr)
|
||||||
|
nested_struct_text = strbuilder_to_str(code_to_strbuilder((Code)nested_struct));
|
||||||
|
expect(str_contains(nested_struct_text, txt("s32 after")), txt("cpp nested struct recovery serializes following member"));
|
||||||
|
|
||||||
|
ParseInfo nested_namespace_info = {};
|
||||||
|
Opts_parse nested_namespace_options = { &ctx, &nested_namespace_info };
|
||||||
|
CodeNS nested_namespace = parse_namespace(txt("namespace NestedRecovery { s32 before; s32 broken(s32 value; s32 after; }"), nested_namespace_options);
|
||||||
|
expect(nested_namespace.ast != nullptr && nested_namespace->Type == CT_Namespace, txt("cpp nested namespace recovery result"));
|
||||||
|
expect(nested_namespace_info.result.ast == ((Code)nested_namespace).ast, txt("cpp nested namespace recovery ParseInfo result"));
|
||||||
|
expect(nested_namespace_info.messages != nullptr, txt("cpp nested namespace recovery diagnostic"));
|
||||||
|
if (nested_namespace_info.messages != nullptr)
|
||||||
|
expect(str_contains(nested_namespace_info.messages->Content, txt("Expected")), txt("cpp nested namespace recovery diagnostic text"));
|
||||||
|
Code nested_namespace_member = nested_namespace.ast != nullptr && nested_namespace->Body.ast != nullptr ? nested_namespace->Body->Front : Code{ nullptr };
|
||||||
|
expect(nested_namespace_member != nullptr && nested_namespace_member->Type == CT_Variable, txt("cpp nested namespace recovery keeps preceding member typed"));
|
||||||
|
if (nested_namespace_member != nullptr)
|
||||||
|
expect(str_are_equal(nested_namespace_member->Name, txt("before")), txt("cpp nested namespace recovery preceding member name"));
|
||||||
|
if (nested_namespace_member != nullptr) nested_namespace_member = nested_namespace_member->Next;
|
||||||
|
expect(nested_namespace_member != nullptr && nested_namespace_member->Type == CT_Untyped, txt("cpp nested namespace recovery retains failed member"));
|
||||||
|
if (nested_namespace_member != nullptr)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(nested_namespace_member)), txt("s32 broken(s32 value;")), txt("cpp nested namespace recovery exact failed span"));
|
||||||
|
Code nested_namespace_after = nested_namespace_member != nullptr ? nested_namespace_member->Next : Code{ nullptr };
|
||||||
|
expect(nested_namespace_after != nullptr && nested_namespace_after->Type == CT_Variable, txt("cpp nested namespace recovery keeps following member typed"));
|
||||||
|
if (nested_namespace_after != nullptr)
|
||||||
|
expect(str_are_equal(nested_namespace_after->Name, txt("after")), txt("cpp nested namespace recovery following member name"));
|
||||||
|
Str nested_namespace_text = { nullptr, 0 };
|
||||||
|
if (nested_namespace.ast != nullptr)
|
||||||
|
nested_namespace_text = strbuilder_to_str(code_to_strbuilder((Code)nested_namespace));
|
||||||
|
expect(str_contains(nested_namespace_text, txt("s32 after")), txt("cpp nested namespace recovery serializes following member"));
|
||||||
|
|
||||||
|
ParseInfo nested_brace_info = {};
|
||||||
|
Opts_parse nested_brace_options = { &ctx, &nested_brace_info };
|
||||||
|
CodeStruct nested_brace_struct = parse_struct(txt("struct NestedBraceRecovery { s32 before; s32 broken(s32 { 1; s32 after; };"), nested_brace_options);
|
||||||
|
expect(nested_brace_struct.ast != nullptr && nested_brace_struct->Type == CT_Struct, txt("cpp nested brace recovery result"));
|
||||||
|
expect(nested_brace_info.result.ast == ((Code)nested_brace_struct).ast, txt("cpp nested brace recovery ParseInfo result"));
|
||||||
|
expect(nested_brace_info.messages != nullptr, txt("cpp nested brace recovery diagnostic"));
|
||||||
|
Code nested_brace_member = nested_brace_struct.ast != nullptr && nested_brace_struct->Body.ast != nullptr ? nested_brace_struct->Body->Front : Code{ nullptr };
|
||||||
|
expect(nested_brace_member != nullptr && nested_brace_member->Type == CT_Variable, txt("cpp nested brace recovery keeps preceding member typed"));
|
||||||
|
if (nested_brace_member != nullptr) nested_brace_member = nested_brace_member->Next;
|
||||||
|
expect(nested_brace_member != nullptr && nested_brace_member->Type == CT_Untyped, txt("cpp nested brace recovery retains failed member"));
|
||||||
|
if (nested_brace_member != nullptr)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(nested_brace_member)), txt("s32 broken(s32 { 1;")), txt("cpp nested brace recovery exact failed span"));
|
||||||
|
Code nested_brace_after = nested_brace_member != nullptr ? nested_brace_member->Next : Code{ nullptr };
|
||||||
|
expect(nested_brace_after != nullptr && nested_brace_after->Type == CT_Variable, txt("cpp nested brace recovery keeps following member typed"));
|
||||||
|
if (nested_brace_after != nullptr)
|
||||||
|
expect(str_are_equal(nested_brace_after->Name, txt("after")), txt("cpp nested brace recovery following member name"));
|
||||||
|
Str nested_brace_text = { nullptr, 0 };
|
||||||
|
if (nested_brace_struct.ast != nullptr)
|
||||||
|
nested_brace_text = strbuilder_to_str(code_to_strbuilder((Code)nested_brace_struct));
|
||||||
|
expect(str_contains(nested_brace_text, txt("s32 after")), txt("cpp nested brace recovery serializes following member"));
|
||||||
|
|
||||||
|
ParseInfo nested_namespace_brace_info = {};
|
||||||
|
Opts_parse nested_namespace_brace_options = { &ctx, &nested_namespace_brace_info };
|
||||||
|
CodeNS nested_namespace_brace = parse_namespace(txt("namespace NestedBraceRecovery { s32 before; s32 broken(s32 { 1; s32 after; }"), nested_namespace_brace_options);
|
||||||
|
expect(nested_namespace_brace.ast != nullptr && nested_namespace_brace->Type == CT_Namespace, txt("cpp nested namespace brace recovery result"));
|
||||||
|
expect(nested_namespace_brace_info.result.ast == ((Code)nested_namespace_brace).ast, txt("cpp nested namespace brace recovery ParseInfo result"));
|
||||||
|
Code nested_namespace_brace_member = nested_namespace_brace.ast != nullptr && nested_namespace_brace->Body.ast != nullptr ? nested_namespace_brace->Body->Front : Code{ nullptr };
|
||||||
|
expect(nested_namespace_brace_member != nullptr && nested_namespace_brace_member->Type == CT_Variable, txt("cpp nested namespace brace recovery keeps preceding member typed"));
|
||||||
|
if (nested_namespace_brace_member != nullptr) nested_namespace_brace_member = nested_namespace_brace_member->Next;
|
||||||
|
expect(nested_namespace_brace_member != nullptr && nested_namespace_brace_member->Type == CT_Untyped, txt("cpp nested namespace brace recovery retains failed member"));
|
||||||
|
if (nested_namespace_brace_member != nullptr)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(nested_namespace_brace_member)), txt("s32 broken(s32 { 1;")), txt("cpp nested namespace brace recovery exact failed span"));
|
||||||
|
Code nested_namespace_brace_after = nested_namespace_brace_member != nullptr ? nested_namespace_brace_member->Next : Code{ nullptr };
|
||||||
|
expect(nested_namespace_brace_after != nullptr && nested_namespace_brace_after->Type == CT_Variable, txt("cpp nested namespace brace recovery keeps following member typed"));
|
||||||
|
if (nested_namespace_brace_after != nullptr)
|
||||||
|
expect(str_are_equal(nested_namespace_brace_after->Name, txt("after")), txt("cpp nested namespace brace recovery following member name"));
|
||||||
|
Str nested_namespace_brace_text = { nullptr, 0 };
|
||||||
|
if (nested_namespace_brace.ast != nullptr)
|
||||||
|
nested_namespace_brace_text = strbuilder_to_str(code_to_strbuilder((Code)nested_namespace_brace));
|
||||||
|
expect(str_contains(nested_namespace_brace_text, txt("s32 after")), txt("cpp nested namespace brace recovery serializes following member"));
|
||||||
|
|
||||||
|
ParseInfo nested_brace_tail_info = {};
|
||||||
|
Opts_parse nested_brace_tail_options = { &ctx, &nested_brace_tail_info };
|
||||||
|
CodeStruct nested_brace_tail_struct = parse_struct(txt("struct NestedBraceTailRecovery { s32 before; s32 broken(s32 { 1; 2 } foo{ 3; s32 after; };"), nested_brace_tail_options);
|
||||||
|
expect(nested_brace_tail_struct.ast != nullptr && nested_brace_tail_struct->Type == CT_Struct, txt("cpp nested brace tail recovery result"));
|
||||||
|
expect(nested_brace_tail_info.result.ast == ((Code)nested_brace_tail_struct).ast, txt("cpp nested brace tail recovery ParseInfo result"));
|
||||||
|
expect(nested_brace_tail_info.messages != nullptr, txt("cpp nested brace tail recovery diagnostic"));
|
||||||
|
Code nested_brace_tail_member = nested_brace_tail_struct.ast != nullptr && nested_brace_tail_struct->Body.ast != nullptr ? nested_brace_tail_struct->Body->Front : Code{ nullptr };
|
||||||
|
if (nested_brace_tail_member != nullptr) nested_brace_tail_member = nested_brace_tail_member->Next;
|
||||||
|
expect(nested_brace_tail_member != nullptr && nested_brace_tail_member->Type == CT_Untyped, txt("cpp nested brace tail recovery retains failed member"));
|
||||||
|
if (nested_brace_tail_member != nullptr)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(nested_brace_tail_member)), txt("s32 broken(s32 { 1; 2 } foo{ 3;")), txt("cpp nested brace tail recovery exact failed span"));
|
||||||
|
Code nested_brace_tail_after = nested_brace_tail_member != nullptr ? nested_brace_tail_member->Next : Code{ nullptr };
|
||||||
|
expect(nested_brace_tail_after != nullptr && nested_brace_tail_after->Type == CT_Variable, txt("cpp nested brace tail recovery keeps following member typed"));
|
||||||
|
if (nested_brace_tail_after != nullptr)
|
||||||
|
expect(str_are_equal(nested_brace_tail_after->Name, txt("after")), txt("cpp nested brace tail recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo nested_namespace_tail_info = {};
|
||||||
|
Opts_parse nested_namespace_tail_options = { &ctx, &nested_namespace_tail_info };
|
||||||
|
CodeNS nested_namespace_tail = parse_namespace(txt("namespace NestedBraceTailRecovery { s32 before; s32 broken(s32 { 1; 2 } foo{ 3; s32 after; }"), nested_namespace_tail_options);
|
||||||
|
expect(nested_namespace_tail.ast != nullptr && nested_namespace_tail->Type == CT_Namespace, txt("cpp nested namespace brace tail recovery result"));
|
||||||
|
expect(nested_namespace_tail_info.result.ast == ((Code)nested_namespace_tail).ast, txt("cpp nested namespace brace tail recovery ParseInfo result"));
|
||||||
|
Code nested_namespace_tail_member = nested_namespace_tail.ast != nullptr && nested_namespace_tail->Body.ast != nullptr ? nested_namespace_tail->Body->Front : Code{ nullptr };
|
||||||
|
if (nested_namespace_tail_member != nullptr) nested_namespace_tail_member = nested_namespace_tail_member->Next;
|
||||||
|
expect(nested_namespace_tail_member != nullptr && nested_namespace_tail_member->Type == CT_Untyped, txt("cpp nested namespace brace tail recovery retains failed member"));
|
||||||
|
if (nested_namespace_tail_member != nullptr)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(nested_namespace_tail_member)), txt("s32 broken(s32 { 1; 2 } foo{ 3;")), txt("cpp nested namespace brace tail recovery exact failed span"));
|
||||||
|
Code nested_namespace_tail_after = nested_namespace_tail_member != nullptr ? nested_namespace_tail_member->Next : Code{ nullptr };
|
||||||
|
expect(nested_namespace_tail_after != nullptr && nested_namespace_tail_after->Type == CT_Variable, txt("cpp nested namespace brace tail recovery keeps following member typed"));
|
||||||
|
if (nested_namespace_tail_after != nullptr)
|
||||||
|
expect(str_are_equal(nested_namespace_tail_after->Name, txt("after")), txt("cpp nested namespace brace tail recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo nested_inner_close_info = {};
|
||||||
|
Opts_parse nested_inner_close_options = { &ctx, &nested_inner_close_info };
|
||||||
|
CodeStruct nested_inner_close_struct = parse_struct(txt("struct NestedInnerCloseRecovery { s32 before; s32 broken(s32 { 1; 2 } foo{ 3; s32 after; struct Inner { s32 x; }; s32 tail; };"), nested_inner_close_options);
|
||||||
|
expect(nested_inner_close_struct.ast != nullptr && nested_inner_close_struct->Type == CT_Struct, txt("cpp nested inner-close recovery result"));
|
||||||
|
Code nested_inner_close_member = nested_inner_close_struct.ast != nullptr && nested_inner_close_struct->Body.ast != nullptr ? nested_inner_close_struct->Body->Front : Code{ nullptr };
|
||||||
|
if (nested_inner_close_member != nullptr) nested_inner_close_member = nested_inner_close_member->Next;
|
||||||
|
expect(nested_inner_close_member != nullptr && nested_inner_close_member->Type == CT_Untyped, txt("cpp nested inner-close recovery retains failed member"));
|
||||||
|
if (nested_inner_close_member != nullptr)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(nested_inner_close_member)), txt("s32 broken(s32 { 1; 2 } foo{ 3;")), txt("cpp nested inner-close recovery exact failed span"));
|
||||||
|
Code nested_inner_close_after = nested_inner_close_member != nullptr ? nested_inner_close_member->Next : Code{ nullptr };
|
||||||
|
expect(nested_inner_close_after != nullptr && nested_inner_close_after->Type == CT_Variable, txt("cpp nested inner-close recovery keeps following member typed"));
|
||||||
|
if (nested_inner_close_after != nullptr)
|
||||||
|
expect(str_are_equal(nested_inner_close_after->Name, txt("after")), txt("cpp nested inner-close recovery following member name"));
|
||||||
|
Code nested_inner_close_inner = nested_inner_close_after != nullptr ? nested_inner_close_after->Next : Code{ nullptr };
|
||||||
|
expect(nested_inner_close_inner != nullptr && nested_inner_close_inner->Type == CT_Struct, txt("cpp nested inner-close recovery parses nested struct"));
|
||||||
|
Code nested_inner_close_tail = nested_inner_close_inner != nullptr ? nested_inner_close_inner->Next : Code{ nullptr };
|
||||||
|
expect(nested_inner_close_tail != nullptr && nested_inner_close_tail->Type == CT_Variable, txt("cpp nested inner-close recovery parses trailing member"));
|
||||||
|
|
||||||
|
ParseInfo inner_before_sync_info = {};
|
||||||
|
Opts_parse inner_before_sync_options = { &ctx, &inner_before_sync_info };
|
||||||
|
CodeStruct inner_before_sync = parse_struct(txt("struct NestedInnerBeforeSync { s32 before; s32 broken(foo{ struct Inner { s32 x; }; s32 after; };"), inner_before_sync_options);
|
||||||
|
expect(inner_before_sync.ast != nullptr && inner_before_sync->Type == CT_Struct, txt("cpp inner-before-sync recovery result"));
|
||||||
|
Code inner_before_sync_member = inner_before_sync.ast != nullptr && inner_before_sync->Body.ast != nullptr ? inner_before_sync->Body->Front : Code{ nullptr };
|
||||||
|
if (inner_before_sync_member != nullptr) inner_before_sync_member = inner_before_sync_member->Next;
|
||||||
|
expect(inner_before_sync_member != nullptr && inner_before_sync_member->Type == CT_Untyped, txt("cpp inner-before-sync recovery retains failed member"));
|
||||||
|
if (inner_before_sync_member != nullptr)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(inner_before_sync_member)), txt("s32 broken(foo{ struct Inner { s32 x; };")), txt("cpp inner-before-sync recovery exact failed span"));
|
||||||
|
Code inner_before_sync_after = inner_before_sync_member != nullptr ? inner_before_sync_member->Next : Code{ nullptr };
|
||||||
|
expect(inner_before_sync_after != nullptr && inner_before_sync_after->Type == CT_Variable, txt("cpp inner-before-sync recovery keeps following member typed"));
|
||||||
|
if (inner_before_sync_after != nullptr)
|
||||||
|
expect(str_are_equal(inner_before_sync_after->Name, txt("after")), txt("cpp inner-before-sync recovery following member name"));
|
||||||
|
|
||||||
|
ParseInfo global_namespace_recovery_info = {};
|
||||||
|
Opts_parse global_namespace_recovery_options = { &ctx, &global_namespace_recovery_info };
|
||||||
|
CodeBody global_namespace_recovery = parse_global_body(txt("namespace NestedScopeInGlobal { s32 before; s32 broken(s32 { 1; 2 } foo{ 3; s32 after; } struct Later { s32 value; };"), global_namespace_recovery_options);
|
||||||
|
expect(global_namespace_recovery.ast != nullptr && global_namespace_recovery->Type == CT_Global_Body, txt("cpp global namespace recovery body"));
|
||||||
|
expect(global_namespace_recovery_info.result.ast == ((Code)global_namespace_recovery).ast, txt("cpp global namespace recovery ParseInfo result"));
|
||||||
|
Code global_namespace_node = global_namespace_recovery.ast != nullptr ? global_namespace_recovery->Front : Code{ nullptr };
|
||||||
|
expect(global_namespace_node != nullptr && global_namespace_node->Type == CT_Namespace, txt("cpp global namespace recovery preserves namespace"));
|
||||||
|
Code global_namespace_member = global_namespace_node != nullptr && global_namespace_node->Body.ast != nullptr ? global_namespace_node->Body->Front : Code{ nullptr };
|
||||||
|
if (global_namespace_member != nullptr) global_namespace_member = global_namespace_member->Next;
|
||||||
|
expect(global_namespace_member != nullptr && global_namespace_member->Type == CT_Untyped, txt("cpp global namespace recovery retains failed member"));
|
||||||
|
if (global_namespace_member != nullptr)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(global_namespace_member)), txt("s32 broken(s32 { 1; 2 } foo{ 3;")), txt("cpp global namespace recovery exact failed span"));
|
||||||
|
Code global_namespace_after = global_namespace_member != nullptr ? global_namespace_member->Next : Code{ nullptr };
|
||||||
|
expect(global_namespace_after != nullptr && global_namespace_after->Type == CT_Variable, txt("cpp global namespace recovery keeps following member typed"));
|
||||||
|
if (global_namespace_after != nullptr)
|
||||||
|
expect(str_are_equal(global_namespace_after->Name, txt("after")), txt("cpp global namespace recovery following member name"));
|
||||||
|
Code global_later_struct = global_namespace_node != nullptr ? global_namespace_node->Next : Code{ nullptr };
|
||||||
|
expect(global_later_struct != nullptr && global_later_struct->Type == CT_Struct, txt("cpp global namespace recovery preserves following global struct"));
|
||||||
|
if (global_later_struct != nullptr)
|
||||||
|
expect(str_are_equal(global_later_struct->Name, txt("Later")), txt("cpp global namespace recovery following global name"));
|
||||||
|
|
||||||
|
ParseInfo global_struct_recovery_info = {};
|
||||||
|
Opts_parse global_struct_recovery_options = { &ctx, &global_struct_recovery_info };
|
||||||
|
CodeBody global_struct_recovery = parse_global_body(txt("struct GlobalNestedRecovery { s32 before; s32 broken(s32 value; s32 after; }; struct LaterGlobal { s32 value; };"), global_struct_recovery_options);
|
||||||
|
expect(global_struct_recovery.ast != nullptr && global_struct_recovery->Type == CT_Global_Body, txt("cpp global struct recovery body"));
|
||||||
|
Code global_struct_node = global_struct_recovery.ast != nullptr ? global_struct_recovery->Front : Code{ nullptr };
|
||||||
|
Code global_struct_before = global_struct_node != nullptr && global_struct_node->Body.ast != nullptr ? global_struct_node->Body->Front : Code{ nullptr };
|
||||||
|
Code global_struct_member = global_struct_before != nullptr ? global_struct_before->Next : Code{ nullptr };
|
||||||
|
Code global_struct_after = global_struct_member != nullptr ? global_struct_member->Next : Code{ nullptr };
|
||||||
|
Code global_later_class = global_struct_node != nullptr ? global_struct_node->Next : Code{ nullptr };
|
||||||
|
expect(global_struct_node != nullptr && global_struct_node->Type == CT_Struct, txt("cpp global struct recovery preserves partial struct"));
|
||||||
|
expect(global_struct_member != nullptr && global_struct_member->Type == CT_Untyped, txt("cpp global struct recovery retains failed member"));
|
||||||
|
if (global_struct_member != nullptr)
|
||||||
|
expect(str_are_equal(strbuilder_to_str(code_to_strbuilder(global_struct_member)), txt("s32 broken(s32 value;")), txt("cpp global struct recovery exact failed span"));
|
||||||
|
expect(global_struct_after != nullptr && global_struct_after->Type == CT_Variable, txt("cpp global struct recovery keeps following member"));
|
||||||
|
if (global_struct_after != nullptr)
|
||||||
|
expect(str_are_equal(global_struct_after->Name, txt("after")), txt("cpp global struct recovery following member name"));
|
||||||
|
expect(global_later_class != nullptr && global_later_class->Type == CT_Struct, txt("cpp global struct recovery keeps following global struct"));
|
||||||
|
|
||||||
|
ParseInfo nested_owner_info = {};
|
||||||
|
Opts_parse nested_owner_options = { &ctx, &nested_owner_info };
|
||||||
|
CodeStruct nested_owner = parse_struct(txt("struct NestedOwner { s32 before; struct InnerRecovery { s32 inner_before; s32 broken(s32 value; s32 inner_after; }; s32 after; };"), nested_owner_options);
|
||||||
|
expect(nested_owner.ast != nullptr && nested_owner->Type == CT_Struct, txt("cpp nested owner recovery result"));
|
||||||
|
expect(nested_owner_info.result.ast == ((Code)nested_owner).ast, txt("cpp nested owner recovery ParseInfo result"));
|
||||||
|
expect(nested_owner_info.messages != nullptr, txt("cpp nested owner recovery diagnostic"));
|
||||||
|
Code nested_owner_before = nested_owner.ast != nullptr && nested_owner->Body.ast != nullptr ? nested_owner->Body->Front : Code{ nullptr };
|
||||||
|
Code nested_owner_inner = nested_owner_before != nullptr ? nested_owner_before->Next : Code{ nullptr };
|
||||||
|
Code nested_owner_after = nested_owner_inner != nullptr ? nested_owner_inner->Next : Code{ nullptr };
|
||||||
|
Code nested_owner_inner_before = nested_owner_inner != nullptr && nested_owner_inner->Body.ast != nullptr ? nested_owner_inner->Body->Front : Code{ nullptr };
|
||||||
|
Code nested_owner_inner_failed = nested_owner_inner_before != nullptr ? nested_owner_inner_before->Next : Code{ nullptr };
|
||||||
|
Code nested_owner_inner_after = nested_owner_inner_failed != nullptr ? nested_owner_inner_failed->Next : Code{ nullptr };
|
||||||
|
expect(nested_owner_before != nullptr && nested_owner_before->Type == CT_Variable, txt("cpp nested owner keeps preceding member typed"));
|
||||||
|
expect(nested_owner_inner != nullptr && nested_owner_inner->Type == CT_Struct, txt("cpp nested owner retains inner struct AST"));
|
||||||
|
expect(nested_owner_inner_before != nullptr && nested_owner_inner_before->Type == CT_Variable, txt("cpp nested inner recovery keeps preceding member typed"));
|
||||||
|
expect(nested_owner_inner_failed != nullptr && nested_owner_inner_failed->Type == CT_Untyped, txt("cpp nested inner recovery retains failed member"));
|
||||||
|
expect(nested_owner_inner_after != nullptr && nested_owner_inner_after->Type == CT_Variable, txt("cpp nested inner recovery keeps following member typed"));
|
||||||
|
expect(nested_owner_after != nullptr && nested_owner_after->Type == CT_Variable, txt("cpp nested owner keeps following member typed"));
|
||||||
|
|
||||||
#if ! GEN_BUILD_DEBUG
|
#if ! GEN_BUILD_DEBUG
|
||||||
CodeVar wrong_array_value = def_variable(def_type(name(u32)), name(invalid_array_expr));
|
CodeVar wrong_array_value = def_variable(def_type(name(u32)), name(invalid_array_expr));
|
||||||
Opts_def_type wrong_array_options = {};
|
Opts_def_type wrong_array_options = {};
|
||||||
|
|||||||
@@ -13,13 +13,15 @@ internal void expect(int condition, Str label) {
|
|||||||
|
|
||||||
internal void expect_public(Str def, Str needle, Str label) {
|
internal void expect_public(Str def, Str needle, Str label) {
|
||||||
Context ctx = {}; init(& ctx);
|
Context ctx = {}; init(& ctx);
|
||||||
CodeVar parsed = parse_variable(def); expect(cast(Code, parsed) == Code_Invalid, label);
|
ParseInfo info = {}; Opts_parse options = { & ctx, & info };
|
||||||
expect(_ctx->parser.messages != nullptr, label);
|
Code parsed = parse_variable(def, options);
|
||||||
expect(_ctx->parser.messages->Scope == nullptr, label);
|
expect(info.result.ast == parsed.ast, label);
|
||||||
expect(_ctx->parser.messages->Content.Ptr != nullptr, label);
|
expect(info.lexed.messages != nullptr, label);
|
||||||
expect(str_contains(_ctx->parser.messages->Content, needle), label);
|
if (info.lexed.messages != nullptr) expect(str_contains(info.lexed.messages->content, needle), label);
|
||||||
|
if (info.lexed.tokens.num == 0) expect(parsed == Code_Invalid, label);
|
||||||
|
|
||||||
CodeVar again = parse_variable(txt("char const* baseline_message = \"GENCPP_BASELINE\";")); expect(again.ast != nullptr, label);
|
CodeVar again = parse_variable(txt("char const* baseline_message = \"GENCPP_BASELINE\";"), options); expect(again.ast != nullptr, label);
|
||||||
|
expect(info.lexed.messages == nullptr && info.messages == nullptr, label);
|
||||||
if (again.ast != nullptr) {
|
if (again.ast != nullptr) {
|
||||||
expect(again->Type == CT_Variable, label);
|
expect(again->Type == CT_Variable, label);
|
||||||
expect(str_contains(again->Name, txt("baseline_message")), label);
|
expect(str_contains(again->Name, txt("baseline_message")), label);
|
||||||
|
|||||||
+23
-12
@@ -146,15 +146,26 @@ internal void expect_skip_end(Str label)
|
|||||||
expect(points_at_canary(got, storage, 1) == false, label);
|
expect(points_at_canary(got, storage, 1) == false, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void expect_boundary(Str def, Str label, Str mark) {
|
internal void expect_boundary(Str def, Str label, Str mark, b32 expect_lexer_message) {
|
||||||
Context ctx = {};
|
Context ctx = {}; init(& ctx);
|
||||||
init(&ctx);
|
|
||||||
CodeVar parsed = parse_variable(def);
|
CodeVar parsed = parse_variable(def);
|
||||||
expect(cast(Code, parsed) == Code_Invalid, label);
|
expect(cast(Code, parsed) == Code_Invalid, label);
|
||||||
expect(_ctx->parser.messages != nullptr, label);
|
ParseMessage* parse_message = _ctx->parse_info.messages;
|
||||||
expect(_ctx->parser.messages->Scope == nullptr, label);
|
LexerMessage* lexer_message = _ctx->parse_info.lexed.messages;
|
||||||
expect(_ctx->parser.messages->Content.Ptr != nullptr && _ctx->parser.messages->Content.Len > 0, label);
|
if (expect_lexer_message) {
|
||||||
expect(str_contains(_ctx->parser.messages->Content, mark), label);
|
expect(lexer_message != nullptr, label);
|
||||||
|
expect(parse_message == nullptr, label);
|
||||||
|
if (lexer_message != nullptr) expect(str_contains(lexer_message->content, mark), label);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
expect(parse_message != nullptr, label);
|
||||||
|
expect(lexer_message == nullptr, label);
|
||||||
|
}
|
||||||
|
if (expect_lexer_message == false && parse_message != nullptr) {
|
||||||
|
expect(parse_message->Scope == nullptr, label);
|
||||||
|
expect(parse_message->Content.Ptr != nullptr && parse_message->Content.Len > 0, label);
|
||||||
|
expect(str_contains(parse_message->Content, mark), label);
|
||||||
|
}
|
||||||
CodeVar again = parse_variable(txt("char const* baseline_message = \"GENCPP_BASELINE\";"));
|
CodeVar again = parse_variable(txt("char const* baseline_message = \"GENCPP_BASELINE\";"));
|
||||||
expect(again.ast != nullptr, label);
|
expect(again.ast != nullptr, label);
|
||||||
if (again.ast != nullptr) {
|
if (again.ast != nullptr) {
|
||||||
@@ -222,11 +233,11 @@ int main()
|
|||||||
|
|
||||||
Str null_def = { nullptr, 0 };
|
Str null_def = { nullptr, 0 };
|
||||||
Str null_ptr = { nullptr, 4 };
|
Str null_ptr = { nullptr, 4 };
|
||||||
expect_boundary(null_def, txt("null-len"), txt("gen::parse_variable: length must greater than 0"));
|
expect_boundary(null_def, txt("null-len"), txt("gen::parse_variable: length must greater than 0"), false);
|
||||||
expect_boundary(null_ptr, txt("null-ptr"), txt("gen::parse_variable: def was null"));
|
expect_boundary(null_ptr, txt("null-ptr"), txt("gen::parse_variable: def was null"), false);
|
||||||
expect_boundary(txt(""), txt("zero-len"), txt("gen::parse_variable: length must greater than 0"));
|
expect_boundary(txt(""), txt("zero-len"), txt("gen::parse_variable: length must greater than 0"), false);
|
||||||
expect_boundary(txt(" \n\t"), txt("whitespace"), txt("no tokens found"));
|
expect_boundary(txt(" \n\t"), txt("whitespace"), txt("no tokens found"), true);
|
||||||
expect_boundary(txt("// note\n"), txt("comment"), txt("only formatting tokens"));
|
expect_boundary(txt("// note\n"), txt("comment"), txt("only formatting tokens"), false);
|
||||||
expect_eat_end (txt("eat"));
|
expect_eat_end (txt("eat"));
|
||||||
expect_direct (txt("direct"));
|
expect_direct (txt("direct"));
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user