Ver código fonte

style: 修正代码风格

整理了include的顺序
整理了typedef
SongZihuan 4 anos atrás
pai
commit
69821b4885

+ 3 - 0
CMakeLists.txt

@@ -3,6 +3,9 @@ PROJECT(VirtualMath C)
 SET(CMAKE_C_STANDARD 11)
 
 INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/parser/include)
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/include)
+
 AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/memory MEM_LIST)
 AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/parser PASER_LIST)
 AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/src SRC_LIST)

+ 7 - 3
include/__macro.h

@@ -7,28 +7,32 @@
 #include <stdarg.h>
 #include <getopt.h>
 
+// 布尔逻辑的定义
 #define bool int
 #define true 1
 #define false 0
 
+// PASS语句的定义
 #define PASS do{}while(0)
 
 #define NUMBER_TYPE long int
 #define HASH_INDEX unsigned int
+
 #define INTER_FUNCTIONSIG_CORE struct Inter *inter, struct VarList *var_list
 #define INTER_FUNCTIONSIG Statement *st, INTER_FUNCTIONSIG_CORE
 #define CALL_INTER_FUNCTIONSIG_CORE(var_list) inter, var_list
 #define CALL_INTER_FUNCTIONSIG(st, var_list) st, CALL_INTER_FUNCTIONSIG_CORE(var_list)
 
+#define run_continue(result) (result.type == not_return || result.type == operation_return)
+#define run_continue_(result) (result->type == not_return || result->type == operation_return)
+#define is_error(result) (result.type == error_return)
+
 #define freeBase(element, return_) do{ \
 if (element == NULL){ \
 goto return_; \
 } \
 }while(0) \
 
-#define run_continue(result) (result.type == not_return || result.type == operation_return)
-#define run_continue_(result) (result->type == not_return || result->type == operation_return)
-#define is_error(result) (result.type == error_return)
 
 #define checkResult(check_result) do{ \
 if (is_error(check_result)){ \

+ 4 - 2
include/__virtualmath.h

@@ -9,9 +9,9 @@
 #include "parameter.h"
 #include "statement.h"
 #include "run.h"
-#include "syntax.h"
-#include "token.h"
 #include "lexical.h"
+#include "token.h"
+#include "syntax.h"
 #include "grammar.h"
 #include "log.h"
 
@@ -22,4 +22,6 @@ struct Args{
     bool stdout_inter;
 } args;
 
+typedef struct Args Args;
+
 #endif //VIRTUALMATH___VIRTUALMATH_H

+ 4 - 5
include/grammar.h

@@ -2,10 +2,7 @@
 #define VIRTUALMATH_GRAMMAR_H
 #include "__macro.h"
 
-#define PASERSSIGNATURE ParserMessage *pm, Inter *inter /*pasers函数的统一签名*/
-#define CALLPASERSSIGNATURE pm, inter /*pasers函数调用的统一实参*/
-
-typedef struct ParserMessage{
+struct ParserMessage{
     struct TokenMessage *tm;
     FILE *paser_debug;
     FILE *grammar_debug;
@@ -17,7 +14,9 @@ typedef struct ParserMessage{
         lexical_error,
     } status;
     char *status_message;
-} ParserMessage;
+};
+
+typedef struct ParserMessage ParserMessage;
 
 ParserMessage *makeParserMessage(char *file_dir, char *debug);
 void freeParserMessage(ParserMessage *pm, bool self);

+ 4 - 2
include/inter.h

@@ -1,7 +1,7 @@
 #ifndef VIRTUALMATH_INTER_H
 #define VIRTUALMATH_INTER_H
 
-typedef struct Inter{
+struct Inter{
     struct Value *base;
     struct LinkValue *link_base;
     struct HashTable *hash_base;
@@ -9,7 +9,9 @@ typedef struct Inter{
     struct VarList *var_list;
     char *log_dir;  // 记录log文件夹的位置
     FILE *debug;
-} Inter;
+};
+
+typedef struct Inter Inter;
 
 Inter *makeInter(char *debug);
 void freeInter(Inter *inter, bool self);

+ 10 - 7
include/lexical.h

@@ -1,18 +1,17 @@
 #ifndef VIRTUALMATH_LEXICAL_H
 #define VIRTUALMATH_LEXICAL_H
 #include "__macro.h"
-#include "stdio.h"
 
-typedef struct LexFile{
+struct LexFile{
     FILE *file;
     struct LexFileBack{
         bool is_back;
         signed char p;
     } back;
     int count;
-} LexFile;
+};
 
-typedef struct LexMather{
+struct LexMather{
     int len;
     signed char string_type;
     char *str;
@@ -27,12 +26,16 @@ typedef struct LexMather{
         LEXMATHER_END_SECOND,
         LEXMATHER_MISTAKE,
     } status;
-} LexMather;
+};
 
-typedef struct LexMathers{
+struct LexMathers{
     int size;
     struct LexMather **mathers;
-} LexMathers;
+};
+
+typedef struct LexFile LexFile;
+typedef struct LexMather LexMather;
+typedef struct LexMathers LexMathers;
 
 signed char readChar(LexFile *file);
 void backChar(LexFile *file);

+ 7 - 4
include/parameter.h

@@ -2,7 +2,7 @@
 #define VIRTUALMATH_PARAMETER_H
 #include "__macro.h"
 
-typedef struct Parameter{
+struct Parameter{
     enum ParameterType{
         value_par,
         name_par,
@@ -13,9 +13,9 @@ typedef struct Parameter{
         struct Statement *name;  // 仅在name-value模式生效
     } data;
     struct Parameter *next;
-} Parameter;
+};
 
-typedef struct Argument{
+struct Argument{
     enum ArgumentType{
         value_arg,
         name_arg,
@@ -25,7 +25,10 @@ typedef struct Argument{
         struct Statement *name;  // 仅在name-value模式生效
     } data;
     struct Argument *next;
-} Argument;
+};
+
+typedef struct Parameter Parameter;
+typedef struct Argument Argument;
 
 Argument *makeArgument();
 Argument *makeOnlyValueArgument(LinkValue *value);

+ 0 - 2
include/run.h

@@ -1,8 +1,6 @@
 #ifndef VIRTUALMATH_RUN_H
 #define VIRTUALMATH_RUN_H
 #include "__macro.h"
-#include "value.h"
-#include "var.h"
 
 Result operationStatement(INTER_FUNCTIONSIG);
 Result assCore(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_CORE);

+ 7 - 4
include/statement.h

@@ -2,7 +2,7 @@
 #define VIRTUALMATH_STATEMENT_H
 #include "__macro.h"
 
-typedef struct Statement{
+struct Statement{
     enum StatementType{
         start = 1,
         base_value,
@@ -112,9 +112,9 @@ typedef struct Statement{
         } raise_code;
     }u;
     struct Statement *next;
-} Statement;
+};
 
-typedef struct StatementList{
+struct StatementList{
     enum {
         if_b,
         do_b,
@@ -125,7 +125,10 @@ typedef struct StatementList{
     struct Statement *var;
     struct Statement *code;
     struct StatementList *next;
-} StatementList;
+};
+
+typedef struct Statement Statement;
+typedef struct StatementList StatementList;
 
 Statement *makeStatement();
 Statement *makeOperationStatement(int type);

+ 0 - 3
include/syntax.h

@@ -1,9 +1,6 @@
 #ifndef VIRTUALMATH_SYNTAX_H
 #define VIRTUALMATH_SYNTAX_H
 
-#include "lexical.h"
-#include "token.h"
-
 void numberMather(signed char p, LexMather *mather);
 void varMather(signed char p, LexMather *mather);
 void stringMather(signed char p, LexMather *mather);

+ 12 - 8
include/token.h

@@ -109,7 +109,7 @@
 #define RAISE -23
 #define TUPLE -24
 
-typedef struct Token{
+struct Token{
     int token_type;  // 记录token的类型,大于0的数字均为lex匹配器所匹配,小于0的为syntax解析器所匹配
     struct TokenData{
         char *str;
@@ -118,19 +118,23 @@ typedef struct Token{
     } data;
     struct Token *last;
     struct Token *next;
-} Token;
+};
 
-typedef struct TokenStream{
-    Token *token_list;  // 提前存储token的列表
+struct TokenStream{
+    struct Token *token_list;  // 提前存储token的列表
     int size;
-} TokenStream;
+};
 
-typedef struct TokenMessage{
-    TokenStream *ts;
+struct TokenMessage{
+    struct TokenStream *ts;
     struct LexFile *file;
     struct LexMathers *mathers;
     FILE *debug;
-} TokenMessage;
+};
+
+typedef struct Token Token;
+typedef struct TokenStream TokenStream;
+typedef struct TokenMessage TokenMessage;
 
 Token *makeToken();
 Token *makeLexToken(int type, char *str, char *second_str);

+ 12 - 8
include/value.h

@@ -1,7 +1,10 @@
 #ifndef VIRTUALMATH_VALUE_H
 #define VIRTUALMATH_VALUE_H
 
-typedef struct Value{
+struct VarList;
+struct Argument;
+
+struct Value{
     enum ValueType{
         none=0,
         number=1,
@@ -32,16 +35,16 @@ typedef struct Value{
     }data;
     struct Value *next;
     struct Value *last;
-} Value;
+};
 
-typedef struct LinkValue{
+struct LinkValue{
     struct Value *value;
     struct LinkValue *father;
     struct LinkValue *next;
     struct LinkValue *last;
-} LinkValue;
+};
 
-typedef struct Result{
+struct Result{
     enum ResultType{
         not_return = 1,  // 无返回值
         function_return,  // 函数返回值
@@ -54,10 +57,11 @@ typedef struct Result{
     } type;
     struct LinkValue *value;
     int times;
-} Result;
+};
 
-struct VarList;
-struct Argument;
+typedef struct Value Value;
+typedef struct LinkValue LinkValue;
+typedef struct Result Result;
 
 Value *makeValue(Inter *inter);
 void freeValue(Value *value, Inter *inter);

+ 10 - 8
include/var.h

@@ -1,28 +1,30 @@
 #ifndef VIRTUALMATH_VAR_H
 #define VIRTUALMATH_VAR_H
-#include "inter.h"
 
 #define MAX_SIZE (1024)
+#define VARSTR_PREFIX "str_"
 
-typedef struct Var{
+struct Var{
     char *name;
     struct LinkValue *value;
     struct Var *next;
-} Var;
+};
 
-typedef struct HashTable{
+struct HashTable{
     struct Var **hashtable;
     int count;
     struct HashTable *next;
     struct HashTable *last;
-} HashTable;
+};
 
-typedef struct VarList{
+struct VarList{
     struct HashTable *hashtable;
     struct VarList *next;
-} VarList;
+};
 
-#define VARSTR_PREFIX "str_"
+typedef struct Var Var;
+typedef struct HashTable HashTable;
+typedef struct VarList VarList;
 
 VarList *makeVarList(Inter *inter);
 VarList *freeVarList(VarList *vl, bool self);

+ 7 - 4
include/__grammar.h → parser/include/__grammar.h

@@ -2,10 +2,8 @@
 #define VIRTUALMATH___GRAMMAR_H
 #include "__virtualmath.h"
 
-typedef void (*PasersFunction)(PASERSSIGNATURE);
-typedef int (*GetSymbolFunction)(PASERSSIGNATURE, int, Statement **);
-typedef Statement *(*MakeControlFunction)(Statement *);
-typedef int (*TailFunction)(PASERSSIGNATURE, Token *, Statement **);
+#define PASERSSIGNATURE ParserMessage *pm, Inter *inter /*pasers函数的统一签名*/
+#define CALLPASERSSIGNATURE pm, inter /*pasers函数调用的统一实参*/
 
 #if OUT_LOG && OUT_PASERS_LOG
 #define doubleLog(pm, grammar_level, pasers_level, message, ...) do{ \
@@ -29,6 +27,11 @@ writeLog(pm->paser_debug, pasers_level, "\n"message, __VA_ARGS__); \
 #define addToken_ backToken_
 #define call_success(pm) (pm->status == success)
 
+typedef void (*PasersFunction)(PASERSSIGNATURE);
+typedef int (*GetSymbolFunction)(PASERSSIGNATURE, int, Statement **);
+typedef Statement *(*MakeControlFunction)(Statement *);
+typedef int (*TailFunction)(PASERSSIGNATURE, Token *, Statement **);
+
 void parserCommand(PASERSSIGNATURE);
 void parserControl(PASERSSIGNATURE, Statement *(*callBack)(Statement *), int type);
 void parserDef(PASERSSIGNATURE);

+ 0 - 0
include/__lexical.h → parser/include/__lexical.h


+ 0 - 0
include/__syntax.h → parser/include/__syntax.h


+ 0 - 0
include/__token.h → parser/include/__token.h


+ 0 - 0
include/__run.h → src/include/__run.h