From 097541c9b728cb174b08c01344a0d57cdba4ec66 Mon Sep 17 00:00:00 2001 From: ryanfleury Date: Wed, 30 Jun 2021 12:16:06 -0600 Subject: [PATCH] fix build errors; remove dumb non-working printf annotations; move C++ user-defined-literal thing into the header --- .../static_site_generator.c | 3 +- source/md.h | 64 ++++++++----------- source/md_impl.c | 4 +- tests/cpp_build_test.cpp | 6 -- tests/grammar.c | 10 +-- tests/sanity_tests.c | 2 + 6 files changed, 37 insertions(+), 52 deletions(-) diff --git a/samples/static_site_generator/static_site_generator.c b/samples/static_site_generator/static_site_generator.c index a4772b8..61f3246 100644 --- a/samples/static_site_generator/static_site_generator.c +++ b/samples/static_site_generator/static_site_generator.c @@ -411,8 +411,7 @@ GeneratePageContent(MD_Map *index_table, SiteInfo *site_info, PageInfo *page_inf { if(strnode->string.str[i] == '@') { - MD_Node *root = MD_RootFromNode(node); - MD_ParseResult parse = MD_ParseOneNode(root->string, MD_StringSubstring(strnode->string, i, strnode->string.size)); + MD_ParseResult parse = MD_ParseOneNode(MD_StringSubstring(strnode->string, i, strnode->string.size), 0); if(!MD_NodeIsNil(parse.node)) { if(MD_NodeHasTag(node, MD_S8Lit("i"))) diff --git a/source/md.h b/source/md.h index 0065624..5735f5c 100644 --- a/source/md.h +++ b/source/md.h @@ -3,23 +3,20 @@ // TODO List // -// [ ] Freeing calls, allow hooking the allocator with an arena or -// something so that someone can use this for work at an application/game's -// runtime -// [ ] Outputting anything to MD or C code ideally would do something -// smart with auto-indentation, since some people have wanted readable -// layout (if they aren't using 4coder with virtual whitespace basically) -// [ ] Split out C-related stuff into helper language layers -// [ ] Helpers for parsing NodeFlags, figuring out which nodes in a set are -// separated by a semicolon, something like MD_SeekNodeWithFlags(node) -> node ? -// [ ] Escaping characters from strings -// [ ] Fill in more String -> Integer helpers -// [ ] Memory Management Strategy -// [ ] Gather map of current memory management situation -// [ ] Reset all memory operation? -// [ ] Thread context? -// [ ] Scratch memory? -// [ ] Reference Manual +// [ ] unify string literal token kinds +// [ ] simplify string literal flags (triple as a single flag) +// [ ] lexer detects broken comments +// [ ] lexer detects broken strings +// [ ] tests for legal tag syntaxes +// [ ] tests that ensure we don't accept labels when expecting symbols e.g. foo ":" b; foo: "(" ) +// [ ] pass all tests +// [ ] simplify error sorting and catastrophic error handling +// [ ] integer -> string helpers +// [ ] remove symbol digraphs (maybe a test for this or something) and remove from comments +// [ ] stb_snprintf included and modified for %S ~ MD_String8 +// [ ] naming pass +// [ ] get the branches/labels setup on Git for beta 0.1 and dev +// [ ] announcement // NOTE(allen): "Plugin" functionality // @@ -195,24 +192,6 @@ # define MD_C_LINKAGE_END } #endif -#if MD_COMPILER_CL_YEAR >= 2005 -# include -# if MD_COMPILER_CL_YEAR > 2005 -# define MD_FORMAT_STRING_ANNOTATION _Printf_format_string_ -# else -# define MD_FORMAT_STRING_ANNOTATION __format_string -# endif -#else -# define MD_FORMAT_STRING_ANNOTATION -#endif - -#if MD_COMPILER_CLANG || MD_COMPILER_GCC -#define MD_FORMAT_FUNCTION_ANNOTATION(str_idx, check_idx) \ -__attribute__((format(printf, str_idx, check_idx))) -#else -#define MD_FORMAT_FUNCTION_ANNOTATION(str_idx, check_idx) -#endif - //~ Common defines #define MD_FUNCTION @@ -666,6 +645,15 @@ MD_FUNCTION MD_String8 MD_S8(MD_u8 *str, MD_u64 size); # define MD_S8Lit(s) MD_S8((MD_u8*)(s), sizeof(s) - 1) #endif +#if MD_LANG_CPP +static inline MD_String8 +operator "" _md(const char *s, size_t size) +{ + MD_String8 str = MD_S8((MD_u8 *)s, (MD_u64)size); + return str; +} +#endif + MD_FUNCTION MD_String8 MD_S8Range(MD_u8 *str, MD_u8 *opl); MD_FUNCTION MD_String8 MD_StringSubstring(MD_String8 str, MD_u64 min, MD_u64 max); @@ -686,7 +674,7 @@ MD_FUNCTION MD_String8 MD_FolderFromPath(MD_String8 string); MD_FUNCTION MD_String8 MD_PushStringCopy(MD_String8 string); MD_FUNCTION MD_String8 MD_PushStringFV(char *fmt, va_list args); -MD_FUNCTION MD_String8 MD_PushStringF(MD_FORMAT_STRING_ANNOTATION char *fmt, ...) MD_FORMAT_FUNCTION_ANNOTATION(1, 2); +MD_FUNCTION MD_String8 MD_PushStringF(char *fmt, ...); #define MD_StringExpand(s) (int)(s).size, (s).str @@ -796,9 +784,9 @@ it##_r = it##_r->next, it = MD_Deref(it##_r) //~ Error/Warning Helpers 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, MD_FORMAT_STRING_ANNOTATION char *fmt, ...) MD_FORMAT_FUNCTION_ANNOTATION(4, 5); +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, MD_FORMAT_STRING_ANNOTATION char *fmt, ...) MD_FORMAT_FUNCTION_ANNOTATION(4, 5); +MD_FUNCTION void MD_NodeMessageF(FILE *out, MD_Node *node, MD_MessageKind kind, char *fmt, ...); //~ Tree Comparison/Verification diff --git a/source/md_impl.c b/source/md_impl.c index 2573be8..d81416d 100644 --- a/source/md_impl.c +++ b/source/md_impl.c @@ -2295,7 +2295,7 @@ MD_Message(FILE *out, MD_CodeLoc loc, MD_MessageKind kind, MD_String8 str) } MD_FUNCTION_IMPL void -MD_MessageF(FILE *out, MD_CodeLoc loc, MD_MessageKind kind, MD_FORMAT_STRING_ANNOTATION char *fmt, ...) MD_FORMAT_FUNCTION_ANNOTATION(4, 5) +MD_MessageF(FILE *out, MD_CodeLoc loc, MD_MessageKind kind, char *fmt, ...) { // TODO(allen): use scratch va_list args; @@ -2312,7 +2312,7 @@ MD_NodeMessage(FILE *out, MD_Node *node, MD_MessageKind kind, MD_String8 str) } MD_FUNCTION_IMPL void -MD_NodeMessageF(FILE *out, MD_Node *node, MD_MessageKind kind, MD_FORMAT_STRING_ANNOTATION char *fmt, ...) MD_FORMAT_FUNCTION_ANNOTATION(4, 5) +MD_NodeMessageF(FILE *out, MD_Node *node, MD_MessageKind kind, char *fmt, ...) { // TODO(allen): use scratch va_list args; diff --git a/tests/cpp_build_test.cpp b/tests/cpp_build_test.cpp index 805bda6..c9c8ad0 100644 --- a/tests/cpp_build_test.cpp +++ b/tests/cpp_build_test.cpp @@ -1,12 +1,6 @@ #include "md.h" #include "md.c" -MD_String8 operator "" _md(const char *s, size_t size) -{ - MD_String8 str = MD_S8((MD_u8 *)s, (MD_u64)size); - return str; -} - int main(void) { MD_String8 str = "foobar"_md; diff --git a/tests/grammar.c b/tests/grammar.c index e029fec..436e1f3 100644 --- a/tests/grammar.c +++ b/tests/grammar.c @@ -474,13 +474,15 @@ static MD_Node * FirstBadNodeAtPointer(MD_Node *node) { MD_Node *result = 0; + MD_Node *root = MD_RootFromNode(node); + MD_u8 *node_at = root->whole_string.str + node->offset; switch(node->kind){ case MD_NodeKind_File: { } break; case MD_NodeKind_Label: { - if(node->at != node->whole_string.str) + if(node_at != node->whole_string.str) { if(node->whole_string.size) { @@ -488,7 +490,7 @@ FirstBadNodeAtPointer(MD_Node *node) } else { - if(!node->at || (node->at[0] != '(' && node->at[0] != '[' && node->at[0] != '{')) + if(!node_at || (node_at[0] != '(' && node_at[0] != '[' && node_at[0] != '{')) { result = node; } @@ -503,7 +505,7 @@ FirstBadNodeAtPointer(MD_Node *node) case MD_NodeKind_List: case MD_NodeKind_Tag: { - if(node->at != node->whole_string.str) + if(node_at != node->whole_string.str) { result = node; goto end; @@ -537,7 +539,7 @@ int main(int argument_count, char **arguments) // 1) Tag []-style sets as optional MD_Node *optional_tag = 0; { - MD_ParseResult parse_result = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("@"OPTIONAL_TAG" is_a_tag")); + MD_ParseResult parse_result = MD_ParseOneNode(MD_S8Lit("@"OPTIONAL_TAG" is_a_tag"), 0); optional_tag = parse_result.node->first_tag; } TagSquareBracketSetsAsOptional(grammar, optional_tag); diff --git a/tests/sanity_tests.c b/tests/sanity_tests.c index 07cb8c5..d30e013 100644 --- a/tests/sanity_tests.c +++ b/tests/sanity_tests.c @@ -858,5 +858,7 @@ int main(void) } } + MD_String8 str = MD_PushStringF("%i", "foobar"); + return 0; } \ No newline at end of file