format using clang-format to formate code
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
#ifndef __SMCC_CC_LEXER_H__
|
||||
#define __SMCC_CC_LEXER_H__
|
||||
|
||||
#include <libcore.h>
|
||||
#include "lexer_token.h"
|
||||
#include <libcore.h>
|
||||
|
||||
typedef struct lexer_loc {
|
||||
const char *name;
|
||||
@@ -25,11 +25,11 @@ typedef struct lexer_token {
|
||||
|
||||
/**
|
||||
* @brief 词法分析器核心结构体
|
||||
*
|
||||
*
|
||||
* 封装词法分析所需的状态信息和缓冲区管理
|
||||
*/
|
||||
typedef struct cc_lexer {
|
||||
core_stream_t* stream;
|
||||
core_stream_t *stream;
|
||||
lexer_loc_t pos;
|
||||
} smcc_lexer_t;
|
||||
|
||||
@@ -38,24 +38,24 @@ typedef struct cc_lexer {
|
||||
* @param[out] lexer 要初始化的词法分析器实例
|
||||
* @param[in] stream 输入流对象指针
|
||||
*/
|
||||
void lexer_init(smcc_lexer_t* lexer, core_stream_t* stream);
|
||||
void lexer_init(smcc_lexer_t *lexer, core_stream_t *stream);
|
||||
|
||||
/**
|
||||
* @brief 获取原始token
|
||||
* @param[in] lexer 词法分析器实例
|
||||
* @param[out] token 输出token存储位置
|
||||
*
|
||||
*
|
||||
* 此函数会返回所有类型的token,包括空白符等无效token
|
||||
*/
|
||||
void lexer_get_token(smcc_lexer_t* lexer, lexer_tok_t* token);
|
||||
void lexer_get_token(smcc_lexer_t *lexer, lexer_tok_t *token);
|
||||
|
||||
/**
|
||||
* @brief 获取有效token
|
||||
* @param[in] lexer 词法分析器实例
|
||||
* @param[out] token 输出token存储位置
|
||||
*
|
||||
*
|
||||
* 此函数会自动跳过空白符等无效token,返回对语法分析有意义的token
|
||||
*/
|
||||
void lexer_get_valid_token(smcc_lexer_t* lexer, lexer_tok_t* token);
|
||||
void lexer_get_valid_token(smcc_lexer_t *lexer, lexer_tok_t *token);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,39 +8,39 @@
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 1
|
||||
#define LEX_NOTSET( fmt, ...) MLOG_NOTSET(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#define LEX_NOTSET(fmt, ...) MLOG_NOTSET(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_NOTSET( fmt, ...)
|
||||
#define LEX_NOTSET(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 2
|
||||
#define LEX_DEBUG( fmt, ...) MLOG_DEBUG(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#define LEX_DEBUG(fmt, ...) MLOG_DEBUG(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_DEBUG( fmt, ...)
|
||||
#define LEX_DEBUG(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 3
|
||||
#define LEX_INFO( fmt, ...) MLOG_INFO(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#define LEX_INFO(fmt, ...) MLOG_INFO(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_INFO( fmt, ...)
|
||||
#define LEX_INFO(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 4
|
||||
#define LEX_WARN( fmt, ...) MLOG_WARN(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#define LEX_WARN(fmt, ...) MLOG_WARN(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_WARN( fmt, ...)
|
||||
#define LEX_WARN(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 5
|
||||
#define LEX_ERROR( fmt, ...) MLOG_ERROR(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#define LEX_ERROR(fmt, ...) MLOG_ERROR(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_ERROR( fmt, ...)
|
||||
#define LEX_ERROR(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 6
|
||||
#define LEX_FATAL( fmt, ...) MLOG_FATAL(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#define LEX_FATAL(fmt, ...) MLOG_FATAL(&__smcc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_FATAL( fmt, ...)
|
||||
#define LEX_FATAL(fmt, ...)
|
||||
#endif
|
||||
|
||||
extern logger_t __smcc_lexer_log;
|
||||
|
||||
@@ -10,6 +10,7 @@ typedef enum ckeyword {
|
||||
} ckeyword_t;
|
||||
|
||||
// Using Binary Search To Fast Find Keyword
|
||||
/* clang-format off */
|
||||
#define KEYWORD_TABLE \
|
||||
X(asm , TK_BASIC_KEYWORD , TOKEN_ASM , CEXT_ASM) \
|
||||
X(break , TK_BASIC_KEYWORD , TOKEN_BREAK , CSTD_C89) \
|
||||
@@ -105,33 +106,34 @@ typedef enum ckeyword {
|
||||
X(char_literal , TK_BASIC_LITERAL, TOKEN_CHAR_LITERAL ) \
|
||||
X(string_literal , TK_BASIC_LITERAL, TOKEN_STRING_LITERAL ) \
|
||||
// END
|
||||
/* clang-format on */
|
||||
|
||||
// 定义TokenType枚举
|
||||
typedef enum cc_tktype {
|
||||
// 处理普通token
|
||||
#define X(str, subtype, tok) tok,
|
||||
// 处理普通token
|
||||
#define X(str, subtype, tok) tok,
|
||||
TOKEN_TABLE
|
||||
#undef X
|
||||
|
||||
// 处理关键字(保持原有格式)
|
||||
#define X(name, subtype, tok, std) tok,
|
||||
KEYWORD_TABLE
|
||||
#undef X
|
||||
#undef X
|
||||
|
||||
// 处理关键字(保持原有格式)
|
||||
#define X(name, subtype, tok, std) tok,
|
||||
KEYWORD_TABLE
|
||||
#undef X
|
||||
} token_type_t;
|
||||
|
||||
typedef enum token_subtype {
|
||||
TK_BASIC_INVALID, // 错误占位
|
||||
TK_BASIC_KEYWORD, // 关键字
|
||||
TK_BASIC_OPERATOR, // 操作符
|
||||
TK_BASIC_IDENTIFIER, // 标识符
|
||||
TK_BASIC_LITERAL, // 字面量
|
||||
TK_BASIC_INVALID, // 错误占位
|
||||
TK_BASIC_KEYWORD, // 关键字
|
||||
TK_BASIC_OPERATOR, // 操作符
|
||||
TK_BASIC_IDENTIFIER, // 标识符
|
||||
TK_BASIC_LITERAL, // 字面量
|
||||
|
||||
TK_BASIC_EMPTYSPACE, // 空白
|
||||
TK_BASIC_COMMENT, // 注释
|
||||
TK_BASIC_EOF // 结束标记
|
||||
TK_BASIC_EMPTYSPACE, // 空白
|
||||
TK_BASIC_COMMENT, // 注释
|
||||
TK_BASIC_EOF // 结束标记
|
||||
} token_subtype_t;
|
||||
|
||||
token_subtype_t get_tok_subtype(token_type_t type);
|
||||
const char* get_tok_name(token_type_t type);
|
||||
const char *get_tok_name(token_type_t type);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user