[api] decompose the message printing API by one notch

This commit is contained in:
Allen Webster
2021-06-05 21:02:51 -07:00
parent d0c9167eb6
commit d1896fc74b
5 changed files with 52 additions and 17 deletions
+19
View File
@@ -1215,8 +1215,26 @@ main:
////////////////////////////////
//~ Error/Warning Helpers
@send(Nodes)
@func MD_Message: {
out: *FILE,
loc: MD_CodeLoc,
kind: MD_MessageKind,
str: MD_String8,
};
@send(Nodes)
@func MD_Message: {
out: *FILE,
loc: MD_CodeLoc,
kind: MD_MessageKind,
fmt: *char,
"..."
};
@send(Nodes)
@func MD_NodeMessage: {
out: *FILE,
node: *MD_Node,
kind: MD_MessageKind,
str: MD_String8,
@@ -1224,6 +1242,7 @@ main:
@send(Nodes)
@func MD_NodeMessageF: {
out: *FILE,
node: *MD_Node,
kind: MD_MessageKind,
fmt: *char,
+1 -1
View File
@@ -220,7 +220,7 @@ int main(int argument_count, char **arguments)
{
for(MD_Error *error = spec.first_error; error; error = error->next)
{
MD_NodeMessage(error->node, error->kind, error->string);
MD_NodeMessage(stderr, error->node, error->kind, error->string);
}
return -1;
}
+1 -1
View File
@@ -19,7 +19,7 @@ int main(int argument_count, char **arguments)
{
for(MD_EachNode(node, root->first_child))
{
MD_NodeMessageF(node, MD_MessageKind_Error, "This node has an error!");
MD_NodeMessageF(stderr, node, MD_MessageKind_Error, "This node has an error!");
}
}
+4 -2
View File
@@ -735,8 +735,10 @@ MD_FUNCTION MD_Node * MD_SeekNodeWithFlags(MD_Node *start, MD_NodeFlags one_pas
it##_r = it##_r->next, it = MD_Deref(it##_r)
//~ Error/Warning Helpers
MD_FUNCTION void MD_NodeMessage(MD_Node *node, MD_MessageKind kind, MD_String8 str);
MD_FUNCTION void MD_NodeMessageF(MD_Node *node, MD_MessageKind kind, char *fmt, ...);
MD_FUNCTION void MD_Message(FILE *out, MD_CodeLoc loc, MD_MessageKind kind, MD_String8 str);
MD_FUNCTION void MD_MessageF(FILE *out, MD_CodeLoc loc, MD_MessageKind kind, char *fmt, ...);
MD_FUNCTION void MD_NodeMessage(FILE *out, MD_Node *node, MD_MessageKind kind, MD_String8 str);
MD_FUNCTION void MD_NodeMessageF(FILE *out, MD_Node *node, MD_MessageKind kind, char *fmt, ...);
//~ Tree Comparison/Verification
MD_FUNCTION MD_b32 MD_NodeMatch(MD_Node *a, MD_Node *b, MD_MatchFlags flags);
+27 -13
View File
@@ -1168,8 +1168,7 @@ _MD_Error(MD_ParseCtx *ctx, MD_Node *node, MD_MessageKind kind, char *fmt, ...)
}
#define _MD_TokenError(ctx, token, kind, fmt, ...) \
_MD_Error(ctx, \
_MD_MakeNode_Ctx(ctx, MD_NodeKind_ErrorMarker,\
_MD_Error(ctx, _MD_MakeNode_Ctx(ctx, MD_NodeKind_ErrorMarker,\
token.string, token.outer_string,\
token.outer_string.str), \
kind, fmt, __VA_ARGS__)
@@ -2402,24 +2401,39 @@ MD_SeekNodeWithFlags(MD_Node *start, MD_NodeFlags one_past_last_flags)
//~ Error/Warning Helpers
MD_FUNCTION_IMPL void
MD_NodeMessage(MD_Node *node, MD_MessageKind kind, MD_String8 str)
MD_FUNCTION void
MD_Message(FILE *out, MD_CodeLoc loc, MD_MessageKind kind, MD_String8 str)
{
const char *kind_name = kind == MD_MessageKind_Error ? "error" : "warning";
MD_CodeLoc loc = MD_CodeLocFromNode(node);
fprintf(stderr, "%.*s:%i:%i: %s: %.*s\n",
MD_StringExpand(loc.filename),
loc.line, loc.column,
kind_name,
MD_StringExpand(str));
const char *kind_name = ((kind == MD_MessageKind_Error) ? "error" : "warning");
fprintf(out, "%.*s:%i:%i: %s: %.*s\n",
MD_StringExpand(loc.filename), loc.line, loc.column,
kind_name, MD_StringExpand(str));
}
MD_FUNCTION_IMPL void
MD_NodeMessageF(MD_Node *node, MD_MessageKind kind, char *fmt, ...)
MD_MessageF(FILE *out, MD_CodeLoc loc, MD_MessageKind kind, char *fmt, ...)
{
// TODO(allen): use scratch
va_list args;
va_start(args, fmt);
MD_NodeMessage(node, kind ,MD_PushStringFV(fmt, args));
MD_Message(out, loc, kind, MD_PushStringFV(fmt, args));
va_end(args);
}
MD_FUNCTION_IMPL void
MD_NodeMessage(FILE *out, MD_Node *node, MD_MessageKind kind, MD_String8 str)
{
MD_CodeLoc loc = MD_CodeLocFromNode(node);
MD_Message(out, loc, kind, str);
}
MD_FUNCTION_IMPL void
MD_NodeMessageF(FILE *out, MD_Node *node, MD_MessageKind kind, char *fmt, ...)
{
// TODO(allen): use scratch
va_list args;
va_start(args, fmt);
MD_NodeMessage(out, node, kind, MD_PushStringFV(fmt, args));
va_end(args);
}