Tweak wuffs_base__token bitmask assignments again

This commit is contained in:
Nigel Tao committed 2020-02-26 11:36:30 +11:00
1 parent 1da8110462
commit 9d4eeb7b54
4 files changed
+218 -122

No files matched your search

+71 -30
View File
@@ -53,6 +53,8 @@ wuffs_base__make_token(uint64_t repr) {
return ret;
}
// --------
#define WUFFS_BASE__TOKEN__VALUE__MASK 0xFFFFFFFFFFFF
#define WUFFS_BASE__TOKEN__VALUE_MAJOR__MASK 0xFFFFFF
#define WUFFS_BASE__TOKEN__VALUE_MINOR__MASK 0xFFFFFF
@@ -67,54 +69,82 @@ wuffs_base__make_token(uint64_t repr) {
#define WUFFS_BASE__TOKEN__VALUE_BASE_DETAIL__SHIFT 16
#define WUFFS_BASE__TOKEN__LENGTH__SHIFT 0
// --------
#define WUFFS_BASE__TOKEN__VBC__FILLER 0
#define WUFFS_BASE__TOKEN__VBC__STRING 1
#define WUFFS_BASE__TOKEN__VBC__BYTES 2
#define WUFFS_BASE__TOKEN__VBC__STRUCTURE 3
#define WUFFS_BASE__TOKEN__VBC__NUMBER 4
#define WUFFS_BASE__TOKEN__VBC__UNICODE_CODE_POINT 5
#define WUFFS_BASE__TOKEN__VBC__UNICODE_CODE_POINT 2
#define WUFFS_BASE__TOKEN__VBC__NUMBER 3
#define WUFFS_BASE__TOKEN__VBC__STRUCTURE 4
// --------
// INCOMPLETE means that this token combines with the following token.
//
// For example, tokenizing a comment that is longer than the source buffer can
// result in multiple VBC__FILLER tokens. All but the last one is INCOMPLETE.
//
// By convention, whitespace is not marked incomplete. Two whitespace tokens of
// length 30 are equivalent to one whitespace token of length 60.
//
// Bits 0x2, 0x4 and 0x8 are reserved for flags that are common between
// VBD_FILLER, VBD_STRING and VBD_BYTES.
// VBD_FILLER and VBD_STRING.
#define WUFFS_BASE__TOKEN__VBD__FILLER__INCOMPLETE 0x00001
#define WUFFS_BASE__TOKEN__VBD__FILLER__END_OF_CONSECUTIVE_COMMENTS 0x00010
#define WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_LINE 0x00020
#define WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_BLOCK 0x00040
// --------
// INCOMPLETE means that this token combines with the following token.
//
// For example, tokenizing a string that is longer than the source buffer can
// result in multiple VBC__STRING tokens. All but the last one is INCOMPLETE.
//
// Bits 0x2, 0x4 and 0x8 are reserved for flags that are common between
// VBD_FILLER, VBD_STRING and VBD_BYTES.
// VBD_FILLER and VBD_STRING.
#define WUFFS_BASE__TOKEN__VBD__STRING__INCOMPLETE 0x00001
#define WUFFS_BASE__TOKEN__VBD__STRING__ALL_ASCII 0x00010
// Bits 0x2, 0x4 and 0x8 are reserved for flags that are common between
// VBD_FILLER, VBD_STRING and VBD_BYTES.
#define WUFFS_BASE__TOKEN__VBD__BYTES__INCOMPLETE 0x00001
// "D_DST_S_SRC" means that it takes S source bytes (possibly padded) to
// produce D destination bytes. For example,
// WUFFS_BASE__TOKEN__VBD__BYTES__1_DST_4_SRC_BACKSLASH_X means that the source
// looks like "\\x23\\x67\\xAB", where 12 src bytes encode 3 dst bytes.
#define WUFFS_BASE__TOKEN__VBD__BYTES__1_DST_1_SRC_RAW 0x00010
#define WUFFS_BASE__TOKEN__VBD__BYTES__1_DST_2_SRC_HEX 0x00020
#define WUFFS_BASE__TOKEN__VBD__BYTES__1_DST_4_SRC_BACKSLASH_X 0x00040
#define WUFFS_BASE__TOKEN__VBD__BYTES__1_DST_6_SRC_BACKSLASH_U 0x00080
#define WUFFS_BASE__TOKEN__VBD__BYTES__3_DST_4_SRC_BASE_64_STD 0x00100
#define WUFFS_BASE__TOKEN__VBD__BYTES__3_DST_4_SRC_BASE_64_URL 0x00200
#define WUFFS_BASE__TOKEN__VBD__BYTES__4_DST_5_SRC_ASCII_85 0x00400
// "DEFINITELY_FOO" means that the source bytes (and also the destination
// bytes, assuming 1_DST_1_SRC_COPY) are in the FOO format. Definitely means
// that the lack of the bit is conservative: it is valid for all-ASCII strings
// to have neither DEFINITELY_ASCII or DEFINITELY_UTF_8 bits set.
#define WUFFS_BASE__TOKEN__VBD__STRING__DEFINITELY_ASCII 0x00010
#define WUFFS_BASE__TOKEN__VBD__STRING__DEFINITELY_UTF_8 0x00020
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH 0x00001
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__POP 0x00002
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_NONE 0x00010
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_LIST 0x00020
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_DICT 0x00040
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_NONE 0x01000
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_LIST 0x02000
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_DICT 0x04000
// "CONVERT_D_DST_S_SRC" means that multiples of S source bytes (possibly
// padded) produces multiples of D destination bytes. For example,
// CONVERT_1_DST_4_SRC_BACKSLASH_X means a source like "\\x23\\x67\\xAB", where
// 12 src bytes encode 3 dst bytes.
//
// When src is the empty string, multiple conversion algorithms are applicable
// (so these bits are not necessarily mutually exclusive), all producing the
// same empty dst string.
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP 0x00100
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY 0x00200
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_2_SRC_HEXADECIMAL 0x00400
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_4_SRC_BACKSLASH_X 0x00800
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_3_DST_4_SRC_BASE_64_STD 0x01000
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_3_DST_4_SRC_BASE_64_URL 0x02000
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_4_DST_5_SRC_ASCII_85 0x04000
// --------
// UNICODE_CODE_POINT tokens have no room in their VBD for an INCOMPLETE bit.
// All 21 bits are used to hold the Unicode code point. Such tokens preserve
// the INCOMPLETEness of the previous token (if a FILLER or STRING).
#define WUFFS_BASE__TOKEN__VBD__UNICODE_CODE_POINT__MAX_INCL 0x10FFFF
// --------
#define WUFFS_BASE__TOKEN__VBD__NUMBER__LITERAL 0x00001
#define WUFFS_BASE__TOKEN__VBD__NUMBER__LITERAL__UNDEFINED 0x00101
#define WUFFS_BASE__TOKEN__VBD__NUMBER__LITERAL__NULL 0x00201
#define WUFFS_BASE__TOKEN__VBD__NUMBER__LITERAL__FALSE 0x00401
#define WUFFS_BASE__TOKEN__VBD__NUMBER__LITERAL__TRUE 0x00801
// For a source string of "123" or "0x9A", it is valid for a tokenizer to
// return any one of:
// - WUFFS_BASE__TOKEN__VBD__NUMBER__FLOATING_POINT.
@@ -128,7 +158,18 @@ wuffs_base__make_token(uint64_t repr) {
#define WUFFS_BASE__TOKEN__VBD__NUMBER__INTEGER_SIGNED 0x00004
#define WUFFS_BASE__TOKEN__VBD__NUMBER__INTEGER_UNSIGNED 0x00008
#define WUFFS_BASE__TOKEN__VBD__UNICODE_CODE_POINT__MAX_INCL 0x10FFFF
// --------
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH 0x00001
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__POP 0x00002
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_NONE 0x00010
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_LIST 0x00020
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_DICT 0x00040
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_NONE 0x01000
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_LIST 0x02000
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_DICT 0x04000
// --------
static inline uint64_t //
wuffs_base__token__value(const wuffs_base__token* t) {