[api] cut subtle wrapper node constructors

This commit is contained in:
Allen Webster
2021-06-05 22:56:35 -07:00
parent 6450cd703c
commit c3ec42c70c
5 changed files with 11 additions and 39 deletions
-20
View File
@@ -1117,26 +1117,6 @@ main:
return: *MD_Node,
};
@send(Nodes)
@func MD_MakeNodeFromToken: {
kind: MD_NodeKind,
filename: MD_String8,
file: *MD_u8,
at: *MD_u8,
token: MD_Token,
return: *MD_Node,
};
@send(Nodes)
@func MD_MakeNodeFromString: {
kind: MD_NodeKind,
filename: MD_String8,
file: *MD_u8,
at: *MD_u8,
string: MD_String8
return: *MD_Node,
};
@send(Nodes)
@func MD_PushSibling: {
first: **MD_Node,
-1
View File
@@ -708,7 +708,6 @@ MD_FUNCTION MD_Node *MD_NilNode(void);
MD_FUNCTION MD_Node *MD_MakeNode(MD_NodeKind kind, MD_String8 string,
MD_String8 whole_string, MD_String8 filename,
MD_u8 *file_contents, MD_u8 *at);
MD_FUNCTION MD_Node *MD_MakeNodeFromToken(MD_NodeKind kind, MD_String8 filename, MD_u8 *file, MD_u8 *at, MD_Token token);
MD_FUNCTION MD_Node *MD_MakeNodeFromString(MD_NodeKind kind, MD_String8 filename, MD_u8 *file, MD_u8 *at, MD_String8 string);
MD_FUNCTION MD_Node *MD_MakeNodeReference(MD_Node *target);
MD_FUNCTION void MD_PushSibling(MD_Node **first, MD_Node **last, MD_Node *new_sibling);
+9 -16
View File
@@ -1887,8 +1887,8 @@ MD_ParseOneNodeFromCtx(MD_ParseCtx *ctx)
MD_Parse_RequireKind(ctx, MD_TokenKind_CharLiteral, &token) ||
MD_Parse_RequireKind(ctx, MD_TokenKind_Symbol, &token))
{
result.node = MD_MakeNodeFromToken(MD_NodeKind_Label, ctx->filename, ctx->file_contents.str,
token.outer_string.str, token);
result.node = _MD_MakeNode_Ctx(ctx, MD_NodeKind_Label,
token.string, token.outer_string, token.outer_string.str);
result.node->flags |= _MD_NodeFlagsFromTokenKind(token.kind);
if(token.kind == MD_TokenKind_CharLiteral || token.kind == MD_TokenKind_StringLiteral)
@@ -2018,7 +2018,11 @@ MD_FUNCTION_IMPL MD_ParseResult
MD_ParseWholeString(MD_String8 filename, MD_String8 contents)
{
MD_ParseResult result = MD_ZERO_STRUCT;
MD_Node *root = MD_MakeNodeFromString(MD_NodeKind_File, filename, contents.str, contents.str, MD_PushStringF("`DD Parsed From \"%.*s\"`", MD_StringExpand(filename)));
// TODO(allen): we want to make the string for this actually just
// be the filename in the root/file idea.
MD_String8 root_string = MD_PushStringF("`DD Parsed From \"%.*s\"`", MD_StringExpand(filename));
MD_Node *root = MD_MakeNode(MD_NodeKind_File, root_string, root_string,
filename, contents.str, contents.str);
if(contents.size > 0)
{
// NOTE(allen): setup parse context
@@ -2211,22 +2215,11 @@ MD_MakeNode(MD_NodeKind kind, MD_String8 string,
return node;
}
MD_FUNCTION_IMPL MD_Node *
MD_MakeNodeFromToken(MD_NodeKind kind, MD_String8 filename, MD_u8 *file, MD_u8 *at, MD_Token token)
{
return MD_MakeNode(kind, token.string, token.outer_string, filename, file, at);
}
MD_FUNCTION_IMPL MD_Node *
MD_MakeNodeFromString(MD_NodeKind kind, MD_String8 filename, MD_u8 *file, MD_u8 *at, MD_String8 string)
{
return MD_MakeNode(kind, string, string, filename, file, at);
}
MD_FUNCTION_IMPL MD_Node *
MD_MakeNodeReference(MD_Node *target)
{
MD_Node *n = MD_MakeNodeFromString(MD_NodeKind_Reference, MD_S8Lit("`reference node`"), 0, 0, MD_S8Lit("`reference node`"));
MD_String8 string = MD_S8Lit("`reference node`");
MD_Node *n = MD_MakeNode(MD_NodeKind_Reference, string, string, string, 0, 0);
n->ref_target = target;
return n;
}
+1 -1
View File
@@ -66,7 +66,7 @@ static MD_Node * NewChildLabel(MD_Node *parent, MD_String8 label)
{
MD_Node *result = 0;
result = MD_MakeNodeFromString(MD_NodeKind_Label, MD_S8Lit(""), 0, 0, label);
result = MD_MakeNode(MD_NodeKind_Label, label, label, MD_S8Lit(""), 0, 0);
if(parent)
{
MD_PushChild(parent, result);
+1 -1
View File
@@ -58,7 +58,7 @@ EndTest(void)
static MD_Node *
MakeTestNode(MD_NodeKind kind, MD_String8 string)
{
return MD_MakeNodeFromString(kind, MD_S8Lit("`TEST_NODE`"), 0, 0, string);
return MD_MakeNode(kind, string, string, MD_S8Lit("`TEST_NODE`"), 0, 0);
}
static MD_C_Expr *