fixup docs to match this version of the code

This commit is contained in:
Allen Webster
2021-03-14 18:43:23 -07:00
parent b72a53e84c
commit 52fdfdbc38
3 changed files with 83 additions and 102 deletions
+78 -67
View File
@@ -55,8 +55,8 @@
@enum MD_NodeKind: { @enum MD_NodeKind: {
Nil, Nil,
File, File,
Namespace,
Label, Label,
UnnamedSet,
Tag, Tag,
MAX, MAX,
}; };
@@ -108,6 +108,10 @@
whole_string: MD_String8, whole_string: MD_String8,
string_hash: MD_u64, string_hash: MD_u64,
// Comments.
comment_before: MD_String8,
comment_after: MD_String8,
// Source code location information. // Source code location information.
filename: MD_String8, filename: MD_String8,
file_contents: *MD_u8, file_contents: *MD_u8,
@@ -118,36 +122,36 @@
//~ Code Location Info. //~ Code Location Info.
@struct MD_CodeLoc: { @struct MD_CodeLoc: {
filename: MD_String8, filename: MD_String8,
line: MD_u32, line: MD_u32,
column: MD_u32, column: MD_u32,
}; };
//////////////////////////////// ////////////////////////////////
//~ Warning Levels //~ Message Levels
@enum MD_MessageKind: { @enum MD_MessageKind: {
Error, Error,
Warning, Warning,
} }
//////////////////////////////// ////////////////////////////////
//~ String-To-Node table //~ String-To-Node table
@enum MD_NodeTableCollisionRule: { @enum MD_NodeTableCollisionRule: {
Chain, Chain,
Overwrite, Overwrite,
} }
@struct MD_NodeTableSlot: { @struct MD_NodeTableSlot: {
next: *MD_NodeTableSlot, next: *MD_NodeTableSlot,
hash: MD_u64, hash: MD_u64,
node: *MD_Node, node: *MD_Node,
}; };
@struct MD_NodeTable: { @struct MD_NodeTable: {
table_size: MD_u64, table_size: MD_u64,
table: **MD_NodeTableSlot, table: **MD_NodeTableSlot,
}; };
//////////////////////////////// ////////////////////////////////
@@ -194,6 +198,8 @@
Newline, Newline,
WhitespaceMax, WhitespaceMax,
MD_TokenKind_NonASCII,
MAX, MAX,
}; };
@@ -215,40 +221,40 @@
//~ Parsing State //~ Parsing State
@struct MD_Error: { @struct MD_Error: {
next: *MD_Error; next: *MD_Error,
string: MD_String8; string: MD_String8,
filename: MD_String8; filename: MD_String8,
node: *MD_Node; node: *MD_Node,
catastrophic: MD_b32,
location: MD_CodeLoc,
}; };
@struct MD_ParseCtx: { @struct MD_ParseCtx: {
first_root: *MD_Node, first_root: *MD_Node,
last_root: *MD_Node, last_root: *MD_Node,
first_error: *MD_Error, first_error: *MD_Error,
last-error: *MD_Error, last_error: *MD_Error,
at: *MD_u8, at: *MD_u8,
filename: MD_String8, filename: MD_String8,
file_contents: MD_String8, file_contents: MD_String8,
namespace_table: MD_NodeTable,
selected_namespace: *MD_Node,
catastrophic_error: MD_b32,
}; };
@struct MD_ParseResult: { @struct MD_ParseResult: {
node: *MD_Node; node: *MD_Node;
first_error: *MD_Error; first_error: *MD_Error;
bytes_parse: MD_u64; bytes_parse: MD_u64;
}; };
//////////////////////////////// ////////////////////////////////
//~ Expression and Type-Expression parser helper types. //~ Expression and Type-Expression parser helper types.
@enum MD_ExprKind: { // VERY_IMPORTANT_NOTE(rjf): If this enum is ever changed, ensure that
// VERY_IMPORTANT_NOTE(rjf): If this enum is ever changed, ensure that // it is kept in-sync with the MD_ExprPrecFromExprKind function.
// it is kept in-sync with the MD_ExprPrecFromExprKind and the following
// functions:
//
// MD_BinaryExprKindFromNode
// MD_PreUnaryExprKindFromNode
// MD_PostUnaryExprKindFromNode
@enum MD_ExprKind: {
Nil, Nil,
// NOTE(rjf): Atom // NOTE(rjf): Atom
@@ -296,9 +302,11 @@
// NOTE(rjf): Type // NOTE(rjf): Type
Pointer, Pointer,
Array, Array,
Volatile,
Const,
MAX, MAX,
} };
@typedef(MD_i32) MD_ExprPrec; @typedef(MD_i32) MD_ExprPrec;
@@ -326,16 +334,14 @@
Directory, Directory,
}; };
@struct MD_FileInfo: { @struct MD_FileInfo: {
flags: MD_FileFlags; flags: MD_FileFlags;
filename: MD_String8; filename: MD_String8;
file_size: MD_u64; file_size: MD_u64;
}; };
@struct MD_FileIter: { @opaque
state: MD_u64, @struct MD_FileIter: {};
};
//////////////////////////////// ////////////////////////////////
//~ Basic Utilities //~ Basic Utilities
@@ -344,6 +350,10 @@
c, c,
}; };
@macro MD_StaticAssert: {
c,
};
@macro MD_ArrayCount: { @macro MD_ArrayCount: {
a, a,
}; };
@@ -376,6 +386,11 @@
return: MD_b32, return: MD_b32,
}; };
@func MD_CharIsReservedSymbol: {
c: MD_u8,
return: MD_b32,
};
@func MD_CharIsSpace: { @func MD_CharIsSpace: {
c: MD_u8, c: MD_u8,
return: MD_b32, return: MD_b32,
@@ -493,18 +508,18 @@
}; };
@func MD_String8 MD_PushStringCopy: { @func MD_PushStringCopy: {
string: MD_String8, string: MD_String8,
return: MD_String8, return: MD_String8,
}; };
@func MD_String8 MD_PushStringFV: { @func MD_PushStringFV: {
fmt: *char, fmt: *char,
args: va_list, args: va_list,
return: MD_String8, return: MD_String8,
}; };
@func MD_String8 MD_PushStringF: { @func MD_PushStringF: {
fmt: *char, fmt: *char,
"...", "...",
return: MD_String8, return: MD_String8,
@@ -719,12 +734,12 @@
@func MD_ParseWholeString: { @func MD_ParseWholeString: {
filename: MD_String8, filename: MD_String8,
contents: MD_String8, contents: MD_String8,
return: *MD_Node, return: MD_ParseResult,
}; };
@func MD_ParseWholeFile: { @func MD_ParseWholeFile: {
filename: MD_String8, filename: MD_String8,
return: *MD_Node, return: MD_ParseResult,
}; };
//////////////////////////////// ////////////////////////////////
@@ -781,7 +796,7 @@
first: *MD_Node, first: *MD_Node,
last: *MD_Node, last: *MD_Node,
string: MD_String8, string: MD_String8,
return: MD_Node, return: *MD_Node,
}; };
@func MD_NodeFromIndex: { @func MD_NodeFromIndex: {
@@ -854,20 +869,6 @@
return: MD_i64, return: MD_i64,
}; };
@func MD_ChildCountFromNodeAndString: {
node: *MD_Node,
string: MD_String8,
flags: MD_StringMatchFlags,
return: MD_i64,
};
@func MD_TagCountFromNodeAndString: {
node: *MD_Node,
string: MD_String8,
flags: MD_StringMatchFlags,
return: MD_i64,
};
@macro MD_EachNode: { it, first, }; @macro MD_EachNode: { it, first, };
//////////////////////////////// ////////////////////////////////
@@ -984,11 +985,6 @@
node: *MD_Node, node: *MD_Node,
}; };
@func MD_OutputExpr: {
file: *FILE,
expr: *MD_Expr,
};
//////////////////////////////// ////////////////////////////////
//~ C Language Generation //~ C Language Generation
@@ -1013,6 +1009,21 @@
type: *MD_Expr, type: *MD_Expr,
}; };
@func MD_OutputExpr: {
file: *FILE,
expr: *MD_Expr,
};
@func MD_OutputExpr_C: {
file: *FILE,
expr: *MD_Expr,
};
@func MD_OutputType: {
file: *FILE,
type: *MD_Expr,
};
@func MD_OutputType_C_LHS: { @func MD_OutputType_C_LHS: {
file: *FILE, file: *FILE,
type: *MD_Expr, type: *MD_Expr,
+5 -6
View File
@@ -621,6 +621,8 @@ struct MD_FileIter
#define MD_Assert(c) if (!(c)) { *(volatile MD_u64 *)0 = 0; } #define MD_Assert(c) if (!(c)) { *(volatile MD_u64 *)0 = 0; }
#define MD_StaticAssert(c,label) MD_u8 MD_static_assert_##label[(c)?(1):(-1)] #define MD_StaticAssert(c,label) MD_u8 MD_static_assert_##label[(c)?(1):(-1)]
#define MD_ArrayCount(a) (sizeof(a) / sizeof((a)[0])) #define MD_ArrayCount(a) (sizeof(a) / sizeof((a)[0]))
//~ Characters
MD_FUNCTION MD_b32 MD_CharIsAlpha(MD_u8 c); MD_FUNCTION MD_b32 MD_CharIsAlpha(MD_u8 c);
MD_FUNCTION MD_b32 MD_CharIsAlphaUpper(MD_u8 c); MD_FUNCTION MD_b32 MD_CharIsAlphaUpper(MD_u8 c);
MD_FUNCTION MD_b32 MD_CharIsAlphaLower(MD_u8 c); MD_FUNCTION MD_b32 MD_CharIsAlphaLower(MD_u8 c);
@@ -698,7 +700,6 @@ MD_FUNCTION MD_NodeTableSlot *MD_NodeTable_Lookup(MD_NodeTable *table, MD_String
MD_FUNCTION MD_b32 MD_NodeTable_Insert(MD_NodeTable *table, MD_NodeTableCollisionRule collision_rule, MD_String8 string, MD_Node *node); MD_FUNCTION MD_b32 MD_NodeTable_Insert(MD_NodeTable *table, MD_NodeTableCollisionRule collision_rule, MD_String8 string, MD_Node *node);
//~ Parsing //~ Parsing
MD_FUNCTION MD_Token MD_ZeroToken(void);
MD_FUNCTION MD_b32 MD_TokenKindIsWhitespace(MD_TokenKind kind); MD_FUNCTION MD_b32 MD_TokenKindIsWhitespace(MD_TokenKind kind);
MD_FUNCTION MD_b32 MD_TokenKindIsComment(MD_TokenKind kind); MD_FUNCTION MD_b32 MD_TokenKindIsComment(MD_TokenKind kind);
MD_FUNCTION MD_b32 MD_TokenKindIsRegular(MD_TokenKind kind); MD_FUNCTION MD_b32 MD_TokenKindIsRegular(MD_TokenKind kind);
@@ -738,17 +739,12 @@ MD_FUNCTION MD_b32 MD_NodeHasTag(MD_Node *node, MD_String8 tag_string);
MD_FUNCTION MD_CodeLoc MD_CodeLocFromNode(MD_Node *node); MD_FUNCTION MD_CodeLoc MD_CodeLocFromNode(MD_Node *node);
MD_FUNCTION MD_i64 MD_ChildCountFromNode(MD_Node *node); 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_i64 MD_ChildCountFromNodeAndString(MD_Node *node, MD_String8 string, MD_StringMatchFlags flags);
MD_FUNCTION MD_i64 MD_TagCountFromNodeAndString(MD_Node *node, MD_String8 string, MD_StringMatchFlags flags);
// NOTE(rjf): For-Loop Helper // NOTE(rjf): For-Loop Helper
#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
//~ Error/Warning Helpers //~ Error/Warning Helpers
MD_FUNCTION void MD_NodeMessage(MD_Node *node, MD_MessageKind kind, MD_String8 str); MD_FUNCTION void MD_NodeMessage(MD_Node *node, MD_MessageKind kind, MD_String8 str);
MD_FUNCTION void MD_NodeError(MD_Node *node, MD_String8 str);
MD_FUNCTION void MD_NodeWarning(MD_Node *node, MD_String8 str);
MD_FUNCTION void MD_NodeMessageF(MD_Node *node, MD_MessageKind kind, char *fmt, ...); MD_FUNCTION void MD_NodeMessageF(MD_Node *node, MD_MessageKind kind, char *fmt, ...);
MD_FUNCTION void MD_NodeErrorF(MD_Node *node, char *fmt, ...);
//~ Tree Comparison/Verification //~ Tree Comparison/Verification
MD_FUNCTION MD_b32 MD_NodeMatch(MD_Node *a, MD_Node *b, MD_StringMatchFlags str_flags, MD_NodeMatchFlags node_flags); MD_FUNCTION MD_b32 MD_NodeMatch(MD_Node *a, MD_Node *b, MD_StringMatchFlags str_flags, MD_NodeMatchFlags node_flags);
@@ -770,6 +766,8 @@ MD_FUNCTION MD_b32 MD_ExprDeepMatch(MD_Expr *a, MD_Expr *b, MD_StringMatc
//~ Generation //~ Generation
MD_FUNCTION void MD_OutputTree(FILE *file, MD_Node *node); MD_FUNCTION void MD_OutputTree(FILE *file, MD_Node *node);
//~ C Language Generation
MD_FUNCTION void MD_OutputTree_C_String(FILE *file, MD_Node *node); MD_FUNCTION void MD_OutputTree_C_String(FILE *file, MD_Node *node);
MD_FUNCTION void MD_OutputTree_C_Struct(FILE *file, MD_Node *node); MD_FUNCTION void MD_OutputTree_C_Struct(FILE *file, MD_Node *node);
MD_FUNCTION void MD_OutputTree_C_Decl(FILE *file, MD_Node *node); MD_FUNCTION void MD_OutputTree_C_Decl(FILE *file, MD_Node *node);
@@ -780,6 +778,7 @@ MD_FUNCTION void MD_OutputType(FILE *file, MD_Expr *expr);
MD_FUNCTION void MD_OutputType_C_LHS(FILE *file, MD_Expr *type); MD_FUNCTION void MD_OutputType_C_LHS(FILE *file, MD_Expr *type);
MD_FUNCTION void MD_OutputType_C_RHS(FILE *file, MD_Expr *type); MD_FUNCTION void MD_OutputType_C_RHS(FILE *file, MD_Expr *type);
// TODO(allen): needs another pass
//~ Command Line Argument Helper //~ Command Line Argument Helper
MD_FUNCTION MD_CommandLine MD_CommandLine_Start(int argument_count, char **arguments); MD_FUNCTION MD_CommandLine MD_CommandLine_Start(int argument_count, char **arguments);
MD_FUNCTION MD_b32 MD_CommandLine_Flag(MD_CommandLine *cmdln, MD_String8 string); MD_FUNCTION MD_b32 MD_CommandLine_Flag(MD_CommandLine *cmdln, MD_String8 string);
-29
View File
@@ -1028,14 +1028,6 @@ MD_NodeTable_Insert(MD_NodeTable *table, MD_NodeTableCollisionRule collision_rul
return !!slot; return !!slot;
} }
MD_FUNCTION_IMPL MD_Token
MD_ZeroToken(void)
{
MD_Token token;
_MD_MemoryZero(&token, sizeof(token));
return token;
}
MD_FUNCTION_IMPL MD_b32 MD_FUNCTION_IMPL MD_b32
MD_TokenKindIsWhitespace(MD_TokenKind kind) MD_TokenKindIsWhitespace(MD_TokenKind kind)
{ {
@@ -2311,18 +2303,6 @@ MD_NodeMessage(MD_Node *node, MD_MessageKind kind, MD_String8 str)
MD_StringExpand(str)); MD_StringExpand(str));
} }
MD_FUNCTION_IMPL void
MD_NodeError(MD_Node *node, MD_String8 str)
{
MD_NodeMessage(node, MD_MessageKind_Error, str);
}
MD_FUNCTION_IMPL void
MD_NodeWarning(MD_Node *node, MD_String8 str)
{
MD_NodeMessage(node, MD_MessageKind_Warning, str);
}
MD_FUNCTION_IMPL void MD_FUNCTION_IMPL void
MD_NodeMessageF(MD_Node *node, MD_MessageKind kind, char *fmt, ...) MD_NodeMessageF(MD_Node *node, MD_MessageKind kind, char *fmt, ...)
{ {
@@ -2332,15 +2312,6 @@ MD_NodeMessageF(MD_Node *node, MD_MessageKind kind, char *fmt, ...)
va_end(args); va_end(args);
} }
MD_FUNCTION_IMPL void
MD_NodeErrorF(MD_Node *node, char *fmt, ...)
{
va_list args;
va_start(args, fmt);
MD_NodeError(node, MD_PushStringFV(fmt, args));
va_end(args);
}
MD_GLOBAL MD_Expr _md_nil_expr = MD_GLOBAL MD_Expr _md_nil_expr =
{ {
&_md_nil_node, &_md_nil_node,