diff --git a/4coder_API.html b/4coder_API.html index 7ea0eeb6..9ac39eda 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -1170,6 +1170,12 @@ Coming Soon
  • terminate_with_null
  • append_padding
  • replace_char
  • +
  • to_lower_cc
  • +
  • to_lower_ss
  • +
  • to_lower_s
  • +
  • to_upper_cc
  • +
  • to_upper_ss
  • +
  • to_upper_s
  • int_to_str_size
  • int_to_str
  • append_int_to_str
  • @@ -1907,153 +1913,238 @@ void replace_char(
    The with character specifies what to write into the positions where replacement occurs.
    Description
    This call replaces all occurances of character in str with another character.

    -

    §4.3.80: int_to_str_size

    +

    §4.3.80: to_lower_cc

    +
    +void to_lower_cc( +
    char *src,
    char *dst
    ) +
    +
    Parameters
    +
    src
    +
    The source string to conver to lowercase. This string must be null terminated.
    +
    +
    +
    dst
    +
    The destination buffer to receive the converted string. This must be large +enough to contain all of src and a null terminator.
    +
    +
    Description
    Rewrites the string in src into dst with all letters lowercased. src and dst should not +overlap with the exception that src and dst may be exactly equal in order to convert the +string in place.

    +

    §4.3.81: to_lower_ss

    +
    +void to_lower_ss( +
    String *src,
    String *dst
    ) +
    +
    Parameters
    +
    src
    +
    The source string to conver to lowercase.
    +
    +
    +
    dst
    +
    The destination buffer to receive the converted string. +This must have a capacity of at least the size of src.
    +
    +
    Description
    Rewrites the string in src into dst. src and dst should not overlap with the exception +that src and dst may be exactly equal in order to convert the string in place.

    +

    §4.3.82: to_lower_s

    +
    +void to_lower_s( +
    String *str
    ) +
    +
    Parameters
    +
    str
    +
    The string to be converted to all lowercase.
    +
    +
    Description
    This version of to_lower converts str to lowercase in place.

    +

    §4.3.83: to_upper_cc

    +
    +void to_upper_cc( +
    char *src,
    char *dst
    ) +
    +
    Parameters
    +
    src
    +
    The source string to convert to uppercase. This string must be null terminated.
    +
    +
    +
    dst
    +
    The destination buffer to receive the converted string. This must be large +enough to contain all of src and a null terminator.
    +
    +
    Description
    Rewrites the string in src into dst. src and dst should not overlap with the exception +that src and dst may be exactly equal in order to convert the string in place.

    +

    §4.3.84: to_upper_ss

    +
    +void to_upper_ss( +
    String *src,
    String *dst
    ) +
    +
    Parameters
    +
    src
    +
    The source string to conver to uppercase.
    +
    +
    +
    dst
    +
    The destination buffer to receive the converted string. +This must have a capacity of at least the size of src.
    +
    +
    Description
    Rewrites the string in src into dst. src and dst should not overlap with the exception +that src and dst may be exactly equal in order to convert the string in place.

    +

    §4.3.85: to_upper_s

    +
    +void to_upper_s( +
    String *str
    ) +
    +
    Parameters
    +
    str
    +
    The string to be converted to all uppercase.
    +
    +
    Description
    This version of to_upper converts str to uppercase in place.

    +

    §4.3.86: int_to_str_size

    int32_t int_to_str_size(
    int32_t x
    )
    Description
    This call returns the number of bytes required to represent x as a string.

    -

    §4.3.81: int_to_str

    +

    §4.3.87: int_to_str

    fstr_bool int_to_str(
    String *dest,
    int32_t x
    )
    Description
    This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.

    -

    §4.3.82: append_int_to_str

    +

    §4.3.88: append_int_to_str

    fstr_bool append_int_to_str(
    String *dest,
    int32_t x
    )
    Description
    This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.

    -

    §4.3.83: u64_to_str_size

    +

    §4.3.89: u64_to_str_size

    int32_t u64_to_str_size(
    uint64_t x
    )
    Description
    This call returns the number of bytes required to represent x as a string.

    -

    §4.3.84: u64_to_str

    +

    §4.3.90: u64_to_str

    fstr_bool u64_to_str(
    String *dest,
    uint64_t x
    )
    Description
    This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.

    -

    §4.3.85: append_u64_to_str

    +

    §4.3.91: append_u64_to_str

    fstr_bool append_u64_to_str(
    String *dest,
    uint64_t x
    )
    Description
    This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.

    -

    §4.3.86: float_to_str_size

    +

    §4.3.92: float_to_str_size

    int32_t float_to_str_size(
    float x
    )
    Description
    This call returns the number of bytes required to represent x as a string.

    -

    §4.3.87: append_float_to_str

    +

    §4.3.93: append_float_to_str

    fstr_bool append_float_to_str(
    String *dest,
    float x
    )
    Description
    This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.

    -

    §4.3.88: float_to_str

    +

    §4.3.94: float_to_str

    fstr_bool float_to_str(
    String *dest,
    float x
    )
    Description
    This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.

    -

    §4.3.89: str_is_int_c

    +

    §4.3.95: str_is_int_c

    int32_t str_is_int_c(
    char *str
    )
    Description
    If str is a valid string representation of an integer, this call returns non-zero

    -

    §4.3.90: str_is_int_s

    +

    §4.3.96: str_is_int_s

    fstr_bool str_is_int_s(
    String str
    )
    Description
    If str is a valid string representation of an integer, this call returns non-zero.

    -

    §4.3.91: str_to_int_c

    +

    §4.3.97: str_to_int_c

    int32_t str_to_int_c(
    char *str
    )
    Description
    If str is a valid string representation of an integer, this call will return the integer represented by the string. Otherwise this call returns zero.

    -

    §4.3.92: str_to_int_s

    +

    §4.3.98: str_to_int_s

    int32_t str_to_int_s(
    String str
    )
    Description
    If str represents a valid string representation of an integer, this call will return the integer represented by the string. Otherwise this call returns zero.

    -

    §4.3.93: hexchar_to_int

    +

    §4.3.99: hexchar_to_int

    int32_t hexchar_to_int(
    char c
    )
    Description
    If c is a valid hexadecimal digit [0-9a-fA-F] this call returns the value of the integer value of the digit. Otherwise the return is some nonsense value.

    -

    §4.3.94: int_to_hexchar

    +

    §4.3.100: int_to_hexchar

    char int_to_hexchar(
    int32_t x
    )
    Description
    If x is in the range [0,15] this call returns the equivalent lowercase hexadecimal digit. Otherwise the return is some nonsense value.

    -

    §4.3.95: hexstr_to_int

    +

    §4.3.101: hexstr_to_int

    uint32_t hexstr_to_int(
    String str
    )
    Description
    This call interprets str has a hexadecimal representation of an integer and returns the represented integer value.

    -

    §4.3.96: color_to_hexstr

    +

    §4.3.102: color_to_hexstr

    fstr_bool color_to_hexstr(
    String *s,
    uint32_t color
    )
    Description
    This call fills s with the hexadecimal representation of the color. If there is enough memory in s to represent the color this call returns non-zero.

    -

    §4.3.97: hexstr_to_color

    +

    §4.3.103: hexstr_to_color

    fstr_bool hexstr_to_color(
    String s,
    uint32_t *out
    )
    Description
    This call interprets s as a color and writes the 32-bit integer representation into out.

    -

    §4.3.98: reverse_seek_slash_pos

    +

    §4.3.104: reverse_seek_slash_pos

    int32_t reverse_seek_slash_pos(
    String str,
    int32_t pos
    )
    Description
    This call searches for a slash in str by starting pos bytes from the end and going backwards.

    -

    §4.3.99: reverse_seek_slash

    +

    §4.3.105: reverse_seek_slash

    int32_t reverse_seek_slash(
    String str
    )
    Description
    This call searches for a slash in str by starting at the end and going backwards.

    -

    §4.3.100: front_of_directory

    +

    §4.3.106: front_of_directory

    String front_of_directory(
    String dir
    )
    Description
    This call returns a substring of dir containing only the file name or folder name furthest to the right in the directory.
    See Also

    -

    §4.3.101: path_of_directory

    +

    §4.3.107: path_of_directory

    String path_of_directory(
    String dir
    )
    Description
    This call returns a substring of dir containing the whole path except for the final file or folder name.
    See Also

    -

    §4.3.102: set_last_folder_sc

    +

    §4.3.108: set_last_folder_sc

    fstr_bool set_last_folder_sc(
    String *dir,
    char *folder_name,
    char slash
    ) @@ -2073,7 +2164,7 @@ at the end of the directory.
    Description
    This call deletes the last file name or folder name in the dir string and appends the new provided one. If there is enough memory in dir this call returns non-zero.

    -

    §4.3.103: set_last_folder_ss

    +

    §4.3.109: set_last_folder_ss

    fstr_bool set_last_folder_ss(
    String *dir,
    String folder_name,
    char slash
    ) @@ -2092,27 +2183,27 @@ fstr_bool set_last_folder_ss(
    Description
    This call deletes the last file name or folder name in the dir string and appends the new provided one. If there is enough memory in dir this call returns non-zero.

    -

    §4.3.104: file_extension

    +

    §4.3.110: file_extension

    String file_extension(
    String str
    )
    Description
    This call returns a substring containing only the file extension of the provided filename.
    See Also

    -

    §4.3.105: remove_extension

    +

    §4.3.111: remove_extension

    fstr_bool remove_extension(
    String *str
    )
    Description
    This call attemps to delete a file extension off the end of a filename. This call returns non-zero on success.

    -

    §4.3.106: remove_last_folder

    +

    §4.3.112: remove_last_folder

    fstr_bool remove_last_folder(
    String *str
    )
    Description
    This call attemps to delete a folder or filename off the end of a path string. This call returns non-zero on success.

    -

    §4.3.107: string_set_match

    +

    §4.3.113: string_set_match

    fstr_bool string_set_match(
    String *str_set,
    int32_t count,
    String str,
    int32_t *match_index
    ) diff --git a/4coder_string.h b/4coder_string.h index c6bbdfc9..daf69684 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -132,6 +132,12 @@ FSTRING_INLINE fstr_bool append_sc(String *dest, char *src); FSTRING_LINK fstr_bool terminate_with_null(String *str); FSTRING_LINK fstr_bool append_padding(String *dest, char c, int32_t target_size); FSTRING_LINK void replace_char(String *str, char replace, char with); +FSTRING_LINK void to_lower_cc(char *src, char *dst); +FSTRING_LINK void to_lower_ss(String *src, String *dst); +FSTRING_LINK void to_lower_s(String *str); +FSTRING_LINK void to_upper_cc(char *src, char *dst); +FSTRING_LINK void to_upper_ss(String *src, String *dst); +FSTRING_LINK void to_upper_s(String *str); FSTRING_LINK int32_t int_to_str_size(int32_t x); FSTRING_LINK fstr_bool int_to_str(String *dest, int32_t x); FSTRING_LINK fstr_bool append_int_to_str(String *dest, int32_t x); @@ -220,6 +226,12 @@ FSTRING_INLINE fstr_bool append_partial(String *dest, String src); FSTRING_INLINE fstr_bool append(String *dest, char c); FSTRING_INLINE fstr_bool append(String *dest, String src); FSTRING_INLINE fstr_bool append(String *dest, char *src); +FSTRING_INLINE void to_lower(char *src, char *dst); +FSTRING_INLINE void to_lower(String *src, String *dst); +FSTRING_INLINE void to_lower(String *str); +FSTRING_INLINE void to_upper(char *src, char *dst); +FSTRING_INLINE void to_upper(String *src, String *dst); +FSTRING_INLINE void to_upper(String *str); FSTRING_INLINE int32_t str_is_int(char *str); FSTRING_INLINE fstr_bool str_is_int(String str); FSTRING_INLINE int32_t str_to_int(char *str); @@ -342,6 +354,18 @@ FSTRING_INLINE fstr_bool append(String *dest, String src){return(append_ss(dest,src));} FSTRING_INLINE fstr_bool append(String *dest, char *src){return(append_sc(dest,src));} +FSTRING_INLINE void +to_lower(char *src, char *dst){(to_lower_cc(src,dst));} +FSTRING_INLINE void +to_lower(String *src, String *dst){(to_lower_ss(src,dst));} +FSTRING_INLINE void +to_lower(String *str){(to_lower_s(str));} +FSTRING_INLINE void +to_upper(char *src, char *dst){(to_upper_cc(src,dst));} +FSTRING_INLINE void +to_upper(String *src, String *dst){(to_upper_ss(src,dst));} +FSTRING_INLINE void +to_upper(String *str){(to_upper_s(str));} FSTRING_INLINE int32_t str_is_int(char *str){return(str_is_int_c(str));} FSTRING_INLINE fstr_bool @@ -1397,6 +1421,88 @@ replace_char(String *str, char replace, char with){ } #endif + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK void +to_lower_cc(char *src, char *dst){ + for (; *src != 0; ++src){ + *dst++ = char_to_lower(*src); + } + *dst++ = 0; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK void +to_lower_ss(String *src, String *dst){ + int32_t i = 0; + int32_t size = src->size; + char *c = src->str; + char *d = dst->str; + + if (dst->memory_size >= size){ + for (; i < size; ++i){ + *d++ = char_to_lower(*c++); + } + } +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK void +to_lower_s(String *str){ + int32_t i = 0; + int32_t size = str->size; + char *c = str->str; + for (; i < size; ++c, ++i){ + *c = char_to_lower(*c); + } +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK void +to_upper_cc(char *src, char *dst){ + for (; *src != 0; ++src){ + *dst++ = char_to_upper(*src); + } + *dst++ = 0; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK void +to_upper_ss(String *src, String *dst){ + int32_t i = 0; + int32_t size = src->size; + char *c = src->str; + char *d = dst->str; + + if (dst->memory_size >= size){ + for (; i < size; ++i){ + *d++ = char_to_upper(*c++); + } + } +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK void +to_upper_s(String *str){ + int32_t i = 0; + int32_t size = str->size; + char *c = str->str; + for (; i < size; ++c, ++i){ + *c = char_to_upper(*c); + } +} +#endif + // // String <-> Number Conversions // diff --git a/4coder_types.h b/4coder_types.h index 8d226a84..f04cf17f 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -706,3 +706,5 @@ struct Theme_Color{ int_color color; }; + + diff --git a/4cpp_lexer_types.h b/4cpp_lexer_types.h index 8adb033a..a7954c2c 100644 --- a/4cpp_lexer_types.h +++ b/4cpp_lexer_types.h @@ -4,7 +4,12 @@ #ifndef FCPP_LEXER_TYPES_INC #define FCPP_LEXER_TYPES_INC -enum Cpp_Token_Type{ +#if 0 + +/* DOC(A Cpp_Token_Type classifies a token to make parsing easier. Some types are not +actually output by the lexer, but exist because parsers will also make use of token +types in their own output.) */ +ENUM(int32_t, Cpp_Token_Type){ CPP_TOKEN_JUNK, CPP_TOKEN_COMMENT, @@ -29,7 +34,8 @@ enum Cpp_Token_Type{ CPP_TOKEN_KEY_TYPE, CPP_TOKEN_KEY_MODIFIER, CPP_TOKEN_KEY_QUALIFIER, - CPP_TOKEN_KEY_OPERATOR, // NOTE(allen): This type is not actually stored in tokens + /* DOC(This type is not stored in token output from the lexer.) */ + CPP_TOKEN_KEY_OPERATOR, CPP_TOKEN_KEY_CONTROL_FLOW, CPP_TOKEN_KEY_CAST, CPP_TOKEN_KEY_TYPE_DECLARATION, @@ -55,62 +61,106 @@ enum Cpp_Token_Type{ CPP_TOKEN_SEMICOLON, CPP_TOKEN_ELLIPSIS, - // NOTE(allen): Ambiguous tokens, lexer only, - // parser figures out the real meaning + /* DOC(This is an 'ambiguous' token type because it requires + parsing to determine the full nature of the token.) */ CPP_TOKEN_STAR, + + /* DOC(This is an 'ambiguous' token type because it requires + parsing to determine the full nature of the token.) */ CPP_TOKEN_AMPERSAND, + + /* DOC(This is an 'ambiguous' token type because it requires + parsing to determine the full nature of the token.) */ CPP_TOKEN_TILDE, + + /* DOC(This is an 'ambiguous' token type because it requires + parsing to determine the full nature of the token.) */ CPP_TOKEN_PLUS, + + /* DOC(This is an 'ambiguous' token type because it requires + parsing to determine the full nature of the token.) */ CPP_TOKEN_MINUS, + + /* DOC(This is an 'ambiguous' token type because it requires + parsing to determine the full nature of the token.) */ CPP_TOKEN_INCREMENT, + + /* DOC(This is an 'ambiguous' token type because it requires + parsing to determine the full nature of the token.) */ CPP_TOKEN_DECREMENT, // NOTE(allen): Precedence 1, LtoR CPP_TOKEN_SCOPE, // NOTE(allen): Precedence 2, LtoR - CPP_TOKEN_POSTINC, // from increment, parser only - CPP_TOKEN_POSTDEC, // from decrement, parser only - CPP_TOKEN_FUNC_STYLE_CAST, // parser only + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_POSTINC, + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_POSTDEC, + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_FUNC_STYLE_CAST, CPP_TOKEN_CPP_STYLE_CAST, - CPP_TOKEN_CALL, // from open paren, parser only - CPP_TOKEN_INDEX, // from bracket open, parser only + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_CALL, + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_INDEX, CPP_TOKEN_DOT, CPP_TOKEN_ARROW, // NOTE(allen): Precedence 3, RtoL - CPP_TOKEN_PREINC, // from increment, parser only - CPP_TOKEN_PREDEC, // from decrement, parser only - CPP_TOKEN_POSITIVE, // from plus, parser only - CPP_TOKEN_NEGAITVE, // from minus, parser only + + /* DOC(This token is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_PREINC, + /* DOC(This token is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_PREDEC, + /* DOC(This token is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_POSITIVE, + /* DOC(This token is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_NEGAITVE, CPP_TOKEN_NOT, - CPP_TOKEN_BIT_NOT, // from tilde, direct from 'compl' - CPP_TOKEN_CAST, // from open paren, parser only - CPP_TOKEN_DEREF, // from star, parser only - CPP_TOKEN_TYPE_PTR, // from star, parser only - CPP_TOKEN_ADDRESS, // from ampersand, parser only - CPP_TOKEN_TYPE_REF, // from ampersand, parser only + + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_BIT_NOT, + + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_CAST, + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_DEREF, + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_TYPE_PTR, + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_ADDRESS, + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_TYPE_REF, CPP_TOKEN_SIZEOF, CPP_TOKEN_ALIGNOF, CPP_TOKEN_DECLTYPE, CPP_TOKEN_TYPEID, CPP_TOKEN_NEW, CPP_TOKEN_DELETE, - CPP_TOKEN_NEW_ARRAY, // from new and bracket open, parser only - CPP_TOKEN_DELETE_ARRAY, // from delete and bracket open, parser only + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_NEW_ARRAY, + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_DELETE_ARRAY, // NOTE(allen): Precedence 4, LtoR CPP_TOKEN_PTRDOT, CPP_TOKEN_PTRARROW, // NOTE(allen): Precedence 5, LtoR - CPP_TOKEN_MUL, // from start, parser only + + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_MUL, CPP_TOKEN_DIV, CPP_TOKEN_MOD, // NOTE(allen): Precedence 6, LtoR - CPP_TOKEN_ADD, // from plus, parser only - CPP_TOKEN_SUB, // from minus, parser only + + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_ADD, + + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_SUB, // NOTE(allen): Precedence 7, LtoR CPP_TOKEN_LSHIFT, @@ -127,7 +177,9 @@ enum Cpp_Token_Type{ CPP_TOKEN_NOTEQ, // NOTE(allen): Precedence 10, LtoR - CPP_TOKEN_BIT_AND, // from ampersand, direct from 'bitand' + + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_BIT_AND, // NOTE(allen): Precedence 11, LtoR CPP_TOKEN_BIT_XOR, @@ -164,11 +216,182 @@ enum Cpp_Token_Type{ CPP_TOKEN_INCLUDE_FILE, CPP_TOKEN_ERROR_MESSAGE, + /* DOC(This type is for parser use, it is not output by the lexer.) */ + CPP_TOKEN_EOF, + + CPP_TOKEN_TYPE_COUNT +}; + +#endif + + +#if 1 +enum Cpp_Token_Type{ + CPP_TOKEN_JUNK, + CPP_TOKEN_COMMENT, + + CPP_PP_INCLUDE, + CPP_PP_DEFINE, + CPP_PP_UNDEF, + CPP_PP_IF, + CPP_PP_IFDEF, + CPP_PP_IFNDEF, + CPP_PP_ELSE, + CPP_PP_ELIF, + CPP_PP_ENDIF, + CPP_PP_ERROR, + CPP_PP_IMPORT, + CPP_PP_USING, + CPP_PP_LINE, + CPP_PP_PRAGMA, + CPP_PP_STRINGIFY, + CPP_PP_CONCAT, + CPP_PP_UNKNOWN, + + CPP_TOKEN_KEY_TYPE, + CPP_TOKEN_KEY_MODIFIER, + CPP_TOKEN_KEY_QUALIFIER, + CPP_TOKEN_KEY_OPERATOR, // NOTE(allen): This type is not actually stored in tokens + CPP_TOKEN_KEY_CONTROL_FLOW, + CPP_TOKEN_KEY_CAST, + CPP_TOKEN_KEY_TYPE_DECLARATION, + CPP_TOKEN_KEY_ACCESS, + CPP_TOKEN_KEY_LINKAGE, + CPP_TOKEN_KEY_OTHER, + + CPP_TOKEN_IDENTIFIER, + CPP_TOKEN_INTEGER_CONSTANT, + CPP_TOKEN_CHARACTER_CONSTANT, + CPP_TOKEN_FLOATING_CONSTANT, + CPP_TOKEN_STRING_CONSTANT, + CPP_TOKEN_BOOLEAN_CONSTANT, + + CPP_TOKEN_STATIC_ASSERT, + + CPP_TOKEN_BRACKET_OPEN, + CPP_TOKEN_BRACKET_CLOSE, + CPP_TOKEN_PARENTHESE_OPEN, + CPP_TOKEN_PARENTHESE_CLOSE, + CPP_TOKEN_BRACE_OPEN, + CPP_TOKEN_BRACE_CLOSE, + CPP_TOKEN_SEMICOLON, + CPP_TOKEN_ELLIPSIS, + + // NOTE(allen): Ambiguous tokens, lexer only, + // parser figures out the real meaning + CPP_TOKEN_STAR, + CPP_TOKEN_AMPERSAND, + CPP_TOKEN_TILDE, + CPP_TOKEN_PLUS, + CPP_TOKEN_MINUS, + CPP_TOKEN_INCREMENT, + CPP_TOKEN_DECREMENT, + + // NOTE(allen): Precedence 1, LtoR + CPP_TOKEN_SCOPE, + + // NOTE(allen): Precedence 2, LtoR + CPP_TOKEN_POSTINC, // from increment, parser only + CPP_TOKEN_POSTDEC, // from decrement, parser only + CPP_TOKEN_FUNC_STYLE_CAST, // parser only + CPP_TOKEN_CPP_STYLE_CAST, + CPP_TOKEN_CALL, // from open paren, parser only + CPP_TOKEN_INDEX, // from bracket open, parser only + CPP_TOKEN_DOT, + CPP_TOKEN_ARROW, + + // NOTE(allen): Precedence 3, RtoL + CPP_TOKEN_PREINC, // from increment, parser only + CPP_TOKEN_PREDEC, // from decrement, parser only + CPP_TOKEN_POSITIVE, // from plus, parser only + CPP_TOKEN_NEGAITVE, // from minus, parser only + CPP_TOKEN_NOT, + CPP_TOKEN_BIT_NOT, // from tilde, direct from 'compl' + CPP_TOKEN_CAST, // from open paren, parser only + CPP_TOKEN_DEREF, // from star, parser only + CPP_TOKEN_TYPE_PTR, // from star, parser only + CPP_TOKEN_ADDRESS, // from ampersand, parser only + CPP_TOKEN_TYPE_REF, // from ampersand, parser only + CPP_TOKEN_SIZEOF, + CPP_TOKEN_ALIGNOF, + CPP_TOKEN_DECLTYPE, + CPP_TOKEN_TYPEID, + CPP_TOKEN_NEW, + CPP_TOKEN_DELETE, + CPP_TOKEN_NEW_ARRAY, // from new and bracket open, parser only + CPP_TOKEN_DELETE_ARRAY, // from delete and bracket open, parser only + + // NOTE(allen): Precedence 4, LtoR + CPP_TOKEN_PTRDOT, + CPP_TOKEN_PTRARROW, + + // NOTE(allen): Precedence 5, LtoR + CPP_TOKEN_MUL, // from start, parser only + CPP_TOKEN_DIV, + CPP_TOKEN_MOD, + + // NOTE(allen): Precedence 6, LtoR + CPP_TOKEN_ADD, // from plus, parser only + CPP_TOKEN_SUB, // from minus, parser only + + // NOTE(allen): Precedence 7, LtoR + CPP_TOKEN_LSHIFT, + CPP_TOKEN_RSHIFT, + + // NOTE(allen): Precedence 8, LtoR + CPP_TOKEN_LESS, + CPP_TOKEN_GRTR, + CPP_TOKEN_GRTREQ, + CPP_TOKEN_LESSEQ, + + // NOTE(allen): Precedence 9, LtoR + CPP_TOKEN_EQEQ, + CPP_TOKEN_NOTEQ, + + // NOTE(allen): Precedence 10, LtoR + CPP_TOKEN_BIT_AND, // from ampersand, direct from 'bitand' + + // NOTE(allen): Precedence 11, LtoR + CPP_TOKEN_BIT_XOR, + + // NOTE(allen): Precedence 12, LtoR + CPP_TOKEN_BIT_OR, + + // NOTE(allen): Precedence 13, LtoR + CPP_TOKEN_AND, + + // NOTE(allen): Precedence 14, LtoR + CPP_TOKEN_OR, + + // NOTE(allen): Precedence 15, RtoL + CPP_TOKEN_TERNARY_QMARK, + CPP_TOKEN_COLON, + CPP_TOKEN_THROW, + CPP_TOKEN_EQ, + CPP_TOKEN_ADDEQ, + CPP_TOKEN_SUBEQ, + CPP_TOKEN_MULEQ, + CPP_TOKEN_DIVEQ, + CPP_TOKEN_MODEQ, + CPP_TOKEN_LSHIFTEQ, + CPP_TOKEN_RSHIFTEQ, + CPP_TOKEN_ANDEQ, + CPP_TOKEN_OREQ, + CPP_TOKEN_XOREQ, + + // NOTE(allen): Precedence 16, LtoR + CPP_TOKEN_COMMA, + + CPP_TOKEN_DEFINED, + CPP_TOKEN_INCLUDE_FILE, + CPP_TOKEN_ERROR_MESSAGE, + // NOTE(allen): used in the parser CPP_TOKEN_EOF, CPP_TOKEN_TYPE_COUNT }; +#endif struct Cpp_Token{ Cpp_Token_Type type; diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index 9ba21eb6..7223b286 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -28,42 +28,6 @@ struct Struct_Field{ char *name; }; -void to_lower(char *src, char *dst){ - char *c, ch; - for (c = src; *c != 0; ++c){ - ch = char_to_lower(*c); - *dst++ = ch; - } - *dst = 0; -} - -void to_lower(String *str){ - char *c; - int32_t i = 0; - int32_t size = str->size; - for (c = str->str; i < size; ++c, ++i){ - *c = char_to_lower(*c); - } -} - -void to_upper(char *src, char *dst){ - char *c, ch; - for (c = src; *c != 0; ++c){ - ch = char_to_upper(*c); - *dst++ = ch; - } - *dst = 0; -} - -void to_upper(String *str){ - char *c; - int32_t i = 0; - int32_t size = str->size; - for (c = str->str; i < size; ++c, ++i){ - *c = char_to_upper(*c); - } -} - void to_camel(char *src, char *dst){ char *c, ch; int32_t is_first = 1; @@ -1950,7 +1914,7 @@ generate_custom_headers(){ macro->str = (char*)malloc(macro->memory_size); copy_ss(macro, name_string); - to_upper(macro); + to_upper_s(macro); append_ss(macro, make_lit_string("_SIG")); @@ -1959,7 +1923,7 @@ generate_custom_headers(){ public_name->str = (char*)malloc(public_name->memory_size); copy_ss(public_name, name_string); - to_lower(public_name); + to_lower_s(public_name); } // NOTE(allen): Header diff --git a/TODO.txt b/TODO.txt index aa4940a8..ddf3763e 100644 --- a/TODO.txt +++ b/TODO.txt @@ -89,7 +89,7 @@ ; [X] exit command ; [X] full screen option ; [X] add to APIs -; [] try to make win32 version better +; [X] try to make win32 version better ; ; [] tokens in the custom API ; [] auto indent on the custom side diff --git a/fsm_table_generator.cpp b/fsm_table_generator.cpp index 7b29a998..c682d033 100644 --- a/fsm_table_generator.cpp +++ b/fsm_table_generator.cpp @@ -110,81 +110,6 @@ main_fsm(Lex_FSM fsm, unsigned char pp_state, unsigned char c){ if (c == '\n') fsm.emit_token = 1; break; -#if 0 - case LSPP_include: - switch (fsm.state){ - case LSINC_default: - switch (c){ - case '"': fsm.state = LSINC_quotes; break; - case '<': fsm.state = LSINC_pointy; break; - case '/': fsm.state = LSINC_def_comment_pre; break; - default: fsm.state = LSINC_junk; break; - } - break; - - case LSINC_quotes: - if (c == '"') fsm.emit_token = 1; - else if (c == '\n'){ - fsm.emit_token = 1; - fsm.state = LSINC_junk; - } - break; - - case LSINC_pointy: - if (c == '>') fsm.emit_token = 1; - else if (c == '\n'){ - fsm.emit_token = 1; - fsm.state = LSINC_junk; - } - break; - - case LSINC_junk: - switch (c){ - case '/': fsm.state = LSINC_junk_comment_pre; break; - case '\n': fsm.emit_token = 1; break; - } - break; - - case LSINC_def_comment_pre: - switch (c){ - case '/': fsm.state = LSINC_def_comment; break; - case '*': fsm.state = LSINC_def_comment_block; break; - case '\n': fsm.state = LSINC_junk; fsm.emit_token = 1; break; - default: fsm.state = LSINC_junk; break; - } - break; - - case LSINC_junk_comment_pre: - switch (c){ - case '/': fsm.state = LSINC_junk_comment; break; - case '*': fsm.state = LSINC_junk_comment_block; break; - case '\n': fsm.state = LSINC_junk; fsm.emit_token = 1; break; - default: fsm.state = LSINC_junk; break; - } - break; - - case LSINC_def_comment: - case LSINC_junk_comment: - switch (c){ - - } - break; - - case LSINC_def_comment_slashed: - case LSINC_junk_comment_slashed: - break; - - case LSINC_def_comment_block: - case LSINC_junk_comment_block: - break; - - case LSINC_def_comment_block_ending: - case LSINC_junk_comment_block_ending: - break; - } - break; -#endif - default: switch (fsm.state){ case LS_default: @@ -322,9 +247,6 @@ main_fsm(Lex_FSM fsm, unsigned char pp_state, unsigned char c){ if (pp_state == LSPP_include){ fsm.emit_token = 1; } - else{ - fsm.state = LS_string_slashed; - } break; case '\\': fsm.state = LS_string_slashed; break; } diff --git a/internal_4coder_string.cpp b/internal_4coder_string.cpp index 54294541..aaf681e2 100644 --- a/internal_4coder_string.cpp +++ b/internal_4coder_string.cpp @@ -1123,6 +1123,107 @@ DOC(This call replaces all occurances of character in str with another character } } +CPP_NAME(to_lower) +FSTRING_LINK void +to_lower_cc(char *src, char *dst)/* +DOC_PARAM(src, The source string to conver to lowercase. This string must be null terminated.) +DOC_PARAM(dst, The destination buffer to receive the converted string. This must be large +enough to contain all of src and a null terminator.) +DOC(Rewrites the string in src into dst with all letters lowercased. src and dst should not +overlap with the exception that src and dst may be exactly equal in order to convert the +string in place.) +*/{ + for (; *src != 0; ++src){ + *dst++ = char_to_lower(*src); + } + *dst++ = 0; +} + +CPP_NAME(to_lower) +FSTRING_LINK void +to_lower_ss(String *src, String *dst)/* +DOC_PARAM(src, The source string to conver to lowercase.) +DOC_PARAM(dst, The destination buffer to receive the converted string. +This must have a capacity of at least the size of src.) +DOC(Rewrites the string in src into dst. src and dst should not overlap with the exception +that src and dst may be exactly equal in order to convert the string in place.) +*/{ + int32_t i = 0; + int32_t size = src->size; + char *c = src->str; + char *d = dst->str; + + if (dst->memory_size >= size){ + for (; i < size; ++i){ + *d++ = char_to_lower(*c++); + } + } +} + +CPP_NAME(to_lower) +FSTRING_LINK void +to_lower_s(String *str)/* +DOC_PARAM(str, The string to be converted to all lowercase.) +DOC(This version of to_lower converts str to lowercase in place.) +*/{ + int32_t i = 0; + int32_t size = str->size; + char *c = str->str; + for (; i < size; ++c, ++i){ + *c = char_to_lower(*c); + } +} + +CPP_NAME(to_upper) +FSTRING_LINK void +to_upper_cc(char *src, char *dst)/* +DOC_PARAM(src, The source string to convert to uppercase. This string must be null terminated.) +DOC_PARAM(dst, The destination buffer to receive the converted string. This must be large +enough to contain all of src and a null terminator.) +DOC(Rewrites the string in src into dst. src and dst should not overlap with the exception +that src and dst may be exactly equal in order to convert the string in place.) +*/{ + for (; *src != 0; ++src){ + *dst++ = char_to_upper(*src); + } + *dst++ = 0; +} + +CPP_NAME(to_upper) +FSTRING_LINK void +to_upper_ss(String *src, String *dst)/* +DOC_PARAM(src, The source string to conver to uppercase.) +DOC_PARAM(dst, The destination buffer to receive the converted string. +This must have a capacity of at least the size of src.) +DOC(Rewrites the string in src into dst. src and dst should not overlap with the exception +that src and dst may be exactly equal in order to convert the string in place.) +*/{ + int32_t i = 0; + int32_t size = src->size; + char *c = src->str; + char *d = dst->str; + + if (dst->memory_size >= size){ + for (; i < size; ++i){ + *d++ = char_to_upper(*c++); + } + } +} + +CPP_NAME(to_upper) +FSTRING_LINK void +to_upper_s(String *str)/* +DOC_PARAM(str, The string to be converted to all uppercase.) +DOC(This version of to_upper converts str to uppercase in place.) +*/{ + int32_t i = 0; + int32_t size = str->size; + char *c = str->str; + for (; i < size; ++c, ++i){ + *c = char_to_upper(*c); + } +} + // // String <-> Number Conversions //