mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-07-14 13:31:25 -07:00
eliminate very-poorly-thought-through idea of 'chained casts' - we need to recognize cast operators in the parser somehow, otherwise we are using the expr chain for way too many things in many cases...
This commit is contained in:
+22
-56
@@ -786,6 +786,7 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t
|
||||
//////////////////////////////
|
||||
//- rjf: parse chain of expressions
|
||||
//
|
||||
E_Expr *possible_cast = &e_expr_nil;
|
||||
for(U64 chain_count = 0; it < it_opl && chain_count < max_chain_count;)
|
||||
{
|
||||
////////////////////////////
|
||||
@@ -831,7 +832,6 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t
|
||||
{
|
||||
PrefixUnaryTask *next;
|
||||
E_ExprKind kind;
|
||||
E_Expr *cast_expr;
|
||||
void *location;
|
||||
};
|
||||
PrefixUnaryTask *first_prefix_unary = 0;
|
||||
@@ -844,7 +844,6 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t
|
||||
String8 token_string = str8_substr(text, token.range);
|
||||
S64 prefix_unary_precedence = 0;
|
||||
E_ExprKind prefix_unary_kind = 0;
|
||||
E_Expr *cast_expr = &e_expr_nil;
|
||||
void *location = 0;
|
||||
|
||||
// rjf: try op table
|
||||
@@ -873,50 +872,6 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t
|
||||
it += 1;
|
||||
}
|
||||
|
||||
// rjf: try casting expression
|
||||
#if 0
|
||||
if(prefix_unary_precedence == 0 && str8_match(token_string, str8_lit("("), 0))
|
||||
{
|
||||
E_Token some_type_identifier_maybe = e_token_at_it(it+1, &tokens);
|
||||
String8 some_type_identifier_maybe_string = str8_substr(text, some_type_identifier_maybe.range);
|
||||
if(some_type_identifier_maybe.kind == E_TokenKind_Identifier)
|
||||
{
|
||||
E_TypeKey type_key = e_leaf_type_from_name(some_type_identifier_maybe_string);
|
||||
if(!e_type_key_match(type_key, e_type_key_zero()) || str8_match(some_type_identifier_maybe_string, str8_lit("unsigned"), 0))
|
||||
{
|
||||
// rjf: move past open paren
|
||||
it += 1;
|
||||
|
||||
// rjf: parse type expr
|
||||
E_Parse type_parse = e_push_type_parse_from_text_tokens(arena, text, e_token_array_make_first_opl(it, it_opl));
|
||||
E_Expr *type = type_parse.expr;
|
||||
e_msg_list_concat_in_place(&result.msgs, &type_parse.msgs);
|
||||
it = type_parse.last_token;
|
||||
location = token_string.str;
|
||||
|
||||
// rjf: expect )
|
||||
E_Token close_paren_maybe = e_token_at_it(it, &tokens);
|
||||
String8 close_paren_maybe_string = str8_substr(text, close_paren_maybe.range);
|
||||
if(close_paren_maybe.kind != E_TokenKind_Symbol || !str8_match(close_paren_maybe_string, str8_lit(")"), 0))
|
||||
{
|
||||
e_msgf(arena, &result.msgs, E_MsgKind_MalformedInput, token_string.str, "Missing `)`.");
|
||||
}
|
||||
|
||||
// rjf: consume )
|
||||
else
|
||||
{
|
||||
it += 1;
|
||||
}
|
||||
|
||||
// rjf: fill
|
||||
prefix_unary_precedence = 2;
|
||||
prefix_unary_kind = E_ExprKind_Cast;
|
||||
cast_expr = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// rjf: break if we got no operators
|
||||
if(prefix_unary_precedence == 0)
|
||||
{
|
||||
@@ -933,7 +888,6 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t
|
||||
{
|
||||
PrefixUnaryTask *op_n = push_array(scratch.arena, PrefixUnaryTask, 1);
|
||||
op_n->kind = prefix_unary_kind;
|
||||
op_n->cast_expr = cast_expr;
|
||||
op_n->location = location;
|
||||
SLLQueuePushFront(first_prefix_unary, last_prefix_unary, op_n);
|
||||
}
|
||||
@@ -981,6 +935,9 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t
|
||||
atom = nested_parse.expr;
|
||||
it = nested_parse.last_token;
|
||||
|
||||
// rjf: this may have been a cast
|
||||
possible_cast = atom;
|
||||
|
||||
// rjf: expect )
|
||||
E_Token close_paren_maybe = e_token_at_it(it, &tokens);
|
||||
String8 close_paren_maybe_string = str8_substr(text, close_paren_maybe.range);
|
||||
@@ -1269,6 +1226,13 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: if this is a postfix unary, then we know the previous expression
|
||||
// could not have been a cast.
|
||||
if(is_postfix_unary)
|
||||
{
|
||||
possible_cast = &e_expr_nil;
|
||||
}
|
||||
|
||||
// rjf: quit if this doesn't look like any patterns of postfix unary we know
|
||||
if(!is_postfix_unary)
|
||||
{
|
||||
@@ -1277,12 +1241,16 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
//- rjf: no `atom`, but we have a cast expression? -> just evaluate the type as the atom
|
||||
//
|
||||
if(atom == &e_expr_nil && first_prefix_unary != 0 && first_prefix_unary->cast_expr != &e_expr_nil)
|
||||
//- rjf: if we have an atom, and we have a potential cast expression, then remove
|
||||
// the cast from the chain, and build a cast tree
|
||||
if(atom != &e_expr_nil && possible_cast != &e_expr_nil && atom != possible_cast)
|
||||
{
|
||||
atom = first_prefix_unary->cast_expr;
|
||||
first_prefix_unary = first_prefix_unary->next;
|
||||
E_Expr *casted = atom;
|
||||
DLLRemove_NPZ(&e_expr_nil, result.expr, result.last_expr, possible_cast, next, prev);
|
||||
atom = e_push_expr(arena, E_ExprKind_Cast, atom->location);
|
||||
e_expr_push_child(atom, possible_cast);
|
||||
e_expr_push_child(atom, casted);
|
||||
possible_cast = &e_expr_nil;
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
@@ -1296,10 +1264,6 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t
|
||||
{
|
||||
E_Expr *rhs = atom;
|
||||
atom = e_push_expr(arena, prefix_unary->kind, prefix_unary->location);
|
||||
if(prefix_unary->cast_expr != &e_expr_nil)
|
||||
{
|
||||
e_expr_push_child(atom, prefix_unary->cast_expr);
|
||||
}
|
||||
e_expr_push_child(atom, rhs);
|
||||
}
|
||||
}
|
||||
@@ -1338,6 +1302,7 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t
|
||||
// precedence
|
||||
if(binary_precedence != 0 && binary_precedence <= max_precedence)
|
||||
{
|
||||
possible_cast = &e_expr_nil;
|
||||
E_Parse rhs_expr_parse = e_push_parse_from_string_tokens__prec(arena, text, e_token_array_make_first_opl(it+1, it_opl), binary_precedence-1, 1);
|
||||
e_msg_list_concat_in_place(&result.msgs, &rhs_expr_parse.msgs);
|
||||
E_Expr *rhs = rhs_expr_parse.expr;
|
||||
@@ -1370,6 +1335,7 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t
|
||||
if(token.kind == E_TokenKind_Symbol && str8_match(token_string, str8_lit("?"), 0) && 13 <= max_precedence)
|
||||
{
|
||||
it += 1;
|
||||
possible_cast = &e_expr_nil;
|
||||
|
||||
// rjf: parse middle expression
|
||||
E_Parse middle_expr_parse = e_push_parse_from_string_tokens__prec(arena, text, e_token_array_make_first_opl(it, it_opl), e_max_precedence, 1);
|
||||
|
||||
Reference in New Issue
Block a user