wrap the prev/next comment members for future upgrades

This commit is contained in:
Allen Webster
2021-09-10 13:20:26 -07:00
parent 28fc6e6799
commit aeaa8b1154
2 changed files with 45 additions and 30 deletions
+20 -9
View File
@@ -508,10 +508,10 @@ static MD_Node _md_nil_node =
MD_ZERO_STRUCT, // string MD_ZERO_STRUCT, // string
MD_ZERO_STRUCT, // raw_string MD_ZERO_STRUCT, // raw_string
0xdeadffffffffffull, // string_hash 0xdeadffffffffffull, // string_hash
MD_ZERO_STRUCT, // prev_comment
MD_ZERO_STRUCT, // next_comment
0, // at 0, // at
&_md_nil_node, // ref_target &_md_nil_node, // ref_target
MD_ZERO_STRUCT, // prev_comment
MD_ZERO_STRUCT, // next_comment
}; };
//~ Arena Functions //~ Arena Functions
@@ -2839,12 +2839,23 @@ MD_TagCountFromNode(MD_Node *node)
MD_FUNCTION_IMPL MD_Node * MD_FUNCTION_IMPL MD_Node *
MD_NodeFromReference(MD_Node *node) MD_NodeFromReference(MD_Node *node)
{ {
MD_u64 safety = 100;
for(; safety > 0 && node->kind == MD_NodeKind_Reference;
safety -= 1, node = node->ref_target);
MD_Node *result = node; MD_Node *result = node;
while(result->kind == MD_NodeKind_Reference) return(result);
{ }
result = result->ref_target;
} MD_FUNCTION_IMPL MD_String8
return result; MD_PrevCommentFromNode(MD_Node *node)
{
return(node->prev_comment);
}
MD_FUNCTION_IMPL MD_String8
MD_NextCommentFromNode(MD_Node *node)
{
return(node->next_comment);
} }
//~ Error/Warning Helpers //~ Error/Warning Helpers
@@ -3100,7 +3111,7 @@ MD_FUNCTION_IMPL MD_ExprParseResult
_MD_ExprParse_Ctx_MinPrecedence(MD_Arena *arena, _MD_ExprParseCtx *ctx, MD_u32 min_precedence); _MD_ExprParse_Ctx_MinPrecedence(MD_Arena *arena, _MD_ExprParseCtx *ctx, MD_u32 min_precedence);
MD_FUNCTION_IMPL MD_ExprNode * _MD_Expr_Make(MD_Arena *arena, MD_ExprOperator *op, MD_Node *op_node, MD_FUNCTION_IMPL MD_ExprNode * _MD_Expr_Make(MD_Arena *arena, MD_ExprOperator *op, MD_Node *op_node,
MD_ExprNode *left, MD_ExprNode *right) MD_ExprNode *left, MD_ExprNode *right)
{ {
MD_ExprNode *result = MD_PushArrayZero(arena, MD_ExprNode, 1); MD_ExprNode *result = MD_PushArrayZero(arena, MD_ExprNode, 1);
result->is_op = 1; result->is_op = 1;
@@ -3123,7 +3134,7 @@ MD_FUNCTION_IMPL void _MD_CtxAdvance(_MD_ExprParseCtx *ctx)
} }
MD_FUNCTION_IMPL MD_b32 _MD_ExprOperatorConsumed(_MD_ExprParseCtx *ctx, MD_ExprOperatorKind kind, MD_u32 min_precedence, MD_FUNCTION_IMPL MD_b32 _MD_ExprOperatorConsumed(_MD_ExprParseCtx *ctx, MD_ExprOperatorKind kind, MD_u32 min_precedence,
MD_ExprOperator **op_out) MD_ExprOperator **op_out)
{ {
MD_b32 result = 0; MD_b32 result = 0;
if(!MD_NodeIsNil(ctx->first)) if(!MD_NodeIsNil(ctx->first))
+11 -7
View File
@@ -605,18 +605,19 @@ struct MD_Node
MD_String8 raw_string; MD_String8 raw_string;
MD_u64 string_hash; MD_u64 string_hash;
// Comments.
// TODO(rjf): @node_comments these are pretty under-powered... should they
// just be nodes, maybe? Would that allow for some cool stuff, like comment
// hierarchies?
MD_String8 prev_comment;
MD_String8 next_comment;
// Source code location information. // Source code location information.
MD_u64 offset; MD_u64 offset;
// Reference. // Reference.
MD_Node *ref_target; MD_Node *ref_target;
// Comments.
// @usage prev_comment/next_comment should be considered "hidden". Rely on
// the functions MD_PrevCommentFromNode/MD_NextCommentFromNode to access
// these. Directly access to these is likely to break in a future version.
MD_String8 prev_comment;
MD_String8 next_comment;
}; };
//~ Code Location Info. //~ Code Location Info.
@@ -1091,6 +1092,9 @@ MD_FUNCTION MD_i64 MD_ChildCountFromNode(MD_Node *node);
MD_FUNCTION MD_i64 MD_TagCountFromNode(MD_Node *node); MD_FUNCTION MD_i64 MD_TagCountFromNode(MD_Node *node);
MD_FUNCTION MD_Node * MD_NodeFromReference(MD_Node *node); MD_FUNCTION MD_Node * MD_NodeFromReference(MD_Node *node);
MD_FUNCTION MD_String8 MD_PrevCommentFromNode(MD_Node *node);
MD_FUNCTION MD_String8 MD_NextCommentFromNode(MD_Node *node);
// NOTE(rjf): For-Loop Helpers // NOTE(rjf): For-Loop Helpers
#define MD_EachNode(it, first) MD_Node *it = (first); !MD_NodeIsNil(it); it = it->next #define MD_EachNode(it, first) MD_Node *it = (first); !MD_NodeIsNil(it); it = it->next
#define MD_EachNodeRef(it, first) MD_Node *it##_r = (first), *it = MD_NodeFromReference(it##_r); \ #define MD_EachNodeRef(it, first) MD_Node *it##_r = (first), *it = MD_NodeFromReference(it##_r); \