mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-12 16:38:08 +00:00
eval2: macro argument expression tree parsing
This commit is contained in:
@@ -1990,6 +1990,30 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rjf: try to resolve it as a macro argument
|
||||||
|
if(!identifier_mapped && state->top_task != 0 && state->top_task->expr_kind == E2_ExprKind_Macro)
|
||||||
|
{
|
||||||
|
U64 macro_arg_num = 0;
|
||||||
|
{
|
||||||
|
U64 num = 1;
|
||||||
|
for(String8Node *n = state->top_task->macro_arg_names.first; n != 0; n = n->next, num += 1)
|
||||||
|
{
|
||||||
|
if(str8_match(n->string, identifier, 0))
|
||||||
|
{
|
||||||
|
macro_arg_num = num;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(macro_arg_num != 0)
|
||||||
|
{
|
||||||
|
identifier_mapped = 1;
|
||||||
|
expr = e2_expr(arena, E2_ExprKind_MacroArg);
|
||||||
|
expr->macro_arg_num = (U32)macro_arg_num;
|
||||||
|
expr->string = identifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// rjf: build this as a leaf identifier expression - ask the caller if it's a type
|
// rjf: build this as a leaf identifier expression - ask the caller if it's a type
|
||||||
if(!identifier_mapped)
|
if(!identifier_mapped)
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -56,9 +56,8 @@ typedef enum E2_ParseStatus
|
|||||||
|
|
||||||
//- rjf: caller-provided info
|
//- rjf: caller-provided info
|
||||||
E2_ParseStatus_CheckIdentifierIsType,
|
E2_ParseStatus_CheckIdentifierIsType,
|
||||||
E2_ParseStatus_NewMacro,
|
|
||||||
E2_ParseStatus_FirstCallerRequest = E2_ParseStatus_CheckIdentifierIsType,
|
E2_ParseStatus_FirstCallerRequest = E2_ParseStatus_CheckIdentifierIsType,
|
||||||
E2_ParseStatus_LastCallerRequest = E2_ParseStatus_NewMacro,
|
E2_ParseStatus_LastCallerRequest = E2_ParseStatus_CheckIdentifierIsType,
|
||||||
}
|
}
|
||||||
E2_ParseStatus;
|
E2_ParseStatus;
|
||||||
|
|
||||||
@@ -328,6 +327,7 @@ struct E2_Expr
|
|||||||
E2_ExprNode *last_child;
|
E2_ExprNode *last_child;
|
||||||
U64 child_count;
|
U64 child_count;
|
||||||
E2_ExprKind kind;
|
E2_ExprKind kind;
|
||||||
|
U32 macro_arg_num;
|
||||||
Rng1U64 src_range;
|
Rng1U64 src_range;
|
||||||
String8 string;
|
String8 string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
E2_ExprKindTable:
|
E2_ExprKindTable:
|
||||||
{
|
{
|
||||||
{Identifier Null 0}
|
{Identifier Null 0}
|
||||||
|
{MacroArg Null 0}
|
||||||
{TypeIdentifier Null 0}
|
{TypeIdentifier Null 0}
|
||||||
{Numeric Null 0}
|
{Numeric Null 0}
|
||||||
{StringLiteral Null 0}
|
{StringLiteral Null 0}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
//- GENERATED CODE
|
//- GENERATED CODE
|
||||||
|
|
||||||
C_LINKAGE_BEGIN
|
C_LINKAGE_BEGIN
|
||||||
E2_ExprKindInfo e2_expr_kind_info_table[41] =
|
E2_ExprKindInfo e2_expr_kind_info_table[42] =
|
||||||
{
|
{
|
||||||
{0},
|
{0},
|
||||||
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
|
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
|
||||||
@@ -12,6 +12,7 @@ E2_ExprKindInfo e2_expr_kind_info_table[41] =
|
|||||||
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
|
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
|
||||||
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
|
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
|
||||||
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
|
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
|
||||||
|
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
|
||||||
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp("."), str8_lit_comp(""), str8_lit_comp("")},
|
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp("."), str8_lit_comp(""), str8_lit_comp("")},
|
||||||
{E2_ExprParseKind_Binary, 1, str8_lit_comp(""), str8_lit_comp("["), str8_lit_comp("]"), str8_lit_comp("")},
|
{E2_ExprParseKind_Binary, 1, str8_lit_comp(""), str8_lit_comp("["), str8_lit_comp("]"), str8_lit_comp("")},
|
||||||
{E2_ExprParseKind_Call, 1, str8_lit_comp(""), str8_lit_comp("("), str8_lit_comp(")"), str8_lit_comp(",")},
|
{E2_ExprParseKind_Call, 1, str8_lit_comp(""), str8_lit_comp("("), str8_lit_comp(")"), str8_lit_comp(",")},
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ typedef enum E2_ExprKind
|
|||||||
{
|
{
|
||||||
E2_ExprKind_Null,
|
E2_ExprKind_Null,
|
||||||
E2_ExprKind_Identifier,
|
E2_ExprKind_Identifier,
|
||||||
|
E2_ExprKind_MacroArg,
|
||||||
E2_ExprKind_TypeIdentifier,
|
E2_ExprKind_TypeIdentifier,
|
||||||
E2_ExprKind_Numeric,
|
E2_ExprKind_Numeric,
|
||||||
E2_ExprKind_StringLiteral,
|
E2_ExprKind_StringLiteral,
|
||||||
@@ -131,7 +132,7 @@ E2_TypeKind_LastMeta = E2_TypeKind_MetaDescription,
|
|||||||
} E2_TypeKind;
|
} E2_TypeKind;
|
||||||
|
|
||||||
C_LINKAGE_BEGIN
|
C_LINKAGE_BEGIN
|
||||||
extern E2_ExprKindInfo e2_expr_kind_info_table[41];
|
extern E2_ExprKindInfo e2_expr_kind_info_table[42];
|
||||||
extern U8 e2_type_kind_basic_byte_size_table[61];
|
extern U8 e2_type_kind_basic_byte_size_table[61];
|
||||||
extern String8 e2_type_kind_basic_string_table[61];
|
extern String8 e2_type_kind_basic_string_table[61];
|
||||||
|
|
||||||
|
|||||||
@@ -43,10 +43,10 @@ entry_point(CmdLine *cmdline)
|
|||||||
// (A)
|
// (A)
|
||||||
// int & B
|
// int & B
|
||||||
// (1 + (int)&B)
|
// (1 + (int)&B)
|
||||||
|
s("bar(a, b) = a + b"),
|
||||||
s("123, 456"),
|
s("123, 456"),
|
||||||
s("int32 == int32"),
|
s("int32 == int32"),
|
||||||
s("foo = 123"),
|
s("foo = 123"),
|
||||||
// s("bar(a, b) = a + b"),
|
|
||||||
s("1 > 2"),
|
s("1 > 2"),
|
||||||
s("1 ? \"Test\" : 888"),
|
s("1 ? \"Test\" : 888"),
|
||||||
s("'a'"),
|
s("'a'"),
|
||||||
@@ -98,6 +98,12 @@ entry_point(CmdLine *cmdline)
|
|||||||
{
|
{
|
||||||
str8_list_push(scratch.arena, &msgs, n->string);
|
str8_list_push(scratch.arena, &msgs, n->string);
|
||||||
}
|
}
|
||||||
|
if(parse.status == E2_ParseStatus_CheckIdentifierIsType)
|
||||||
|
{
|
||||||
|
identifier_is_type = identifier_is_type || str8_match(parse.identifier, s("int32"), 0);
|
||||||
|
identifier_is_type = identifier_is_type || str8_match(parse.identifier, s("float32"), 0);
|
||||||
|
identifier_is_type = identifier_is_type || str8_match(parse.identifier, s("float64"), 0);
|
||||||
|
}
|
||||||
if(e2_parse_status_is_terminal(parse.status))
|
if(e2_parse_status_is_terminal(parse.status))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user