Skip to content

Commit

Permalink
style: add '_' before paras others
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <Zone.Niuzh@hotmail.com>
  • Loading branch information
MRNIU committed Oct 26, 2023
1 parent 0756f22 commit 57d2b9d
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 223 deletions.
10 changes: 5 additions & 5 deletions src/include/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Parser {
// 获取下一个 token
void next();
// 匹配指定 Token
bool match_token(Tag tag);
bool match_token(Tag _tag);

// 程序
ASTPtr program();
Expand All @@ -50,8 +50,8 @@ class Parser {
// 一元表达式
ASTPtr unary();
// 二元表达式
ASTPtr binary(const std::function<ASTPtr()> &parser,
std::initializer_list<Operator> ops);
ASTPtr binary(const std::function<ASTPtr()> &_parser,
std::initializer_list<Operator> _ops);
ASTPtr binary_add();
ASTPtr binary_mul();
ASTPtr binary_relation();
Expand All @@ -69,15 +69,15 @@ class Parser {
// var declare
ASTPtr var_decl();
// var definition
ASTPtr var_def(bool);
ASTPtr var_def(bool _isConst);
// initial value
ASTPtr init_val();

// function def
ASTPtr function_def();

public:
Parser(Lexer &lex);
Parser(Lexer &_lex);
~Parser();
// 进行解析
ASTPtr parsing();
Expand Down
2 changes: 1 addition & 1 deletion src/include/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Scanner {

public:
// 读一个文件
Scanner(const std::string &filename);
Scanner(const std::string &_filename);
~Scanner();
// 扫描并返回字符
char scan();
Expand Down
12 changes: 6 additions & 6 deletions src/include/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ enum Tag {
class Token {
public:
Tag tag;
Token(Tag t);
Token(Tag _t);
virtual std::string to_string();
virtual ~Token();
};
Expand All @@ -86,31 +86,31 @@ class Token {
class Id : public Token {
public:
std::string name;
Id(std::string n);
Id(std::string _n);
virtual std::string to_string();
};

// 数字
class Num : public Token {
public:
int val;
Num(int v);
Num(int _v);
virtual std::string to_string();
};

// 字符
class Char : public Token {
public:
char ch;
Char(char c);
Char(char _c);
virtual std::string to_string();
};

// 字符串
class Str : public Token {
public:
std::string str;
Str(std::string s);
Str(std::string _s);
virtual std::string to_string();
};

Expand All @@ -121,7 +121,7 @@ class Keywords {

public:
Keywords();
Tag get_tag(std::string name);
Tag get_tag(std::string _name);
};

#endif /* SIMPLECOMPILER_TOKEN_H */
8 changes: 4 additions & 4 deletions src/include/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ enum Operator {

enum Control { continue_c, break_c, return_c };

Operator tag_to_op(Tag t);
Operator tag_to_op(Tag _t);

std::string op_to_string(Operator p);
std::string op_to_string(Operator _p);

std::string type_to_string(Type t);
std::string type_to_string(Type _t);

std::string vartype_to_string(VarType t);
std::string vartype_to_string(VarType _t);

#endif /* SIMPLECOMPILER_TYPE_H */
50 changes: 25 additions & 25 deletions src/include/typechecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,54 +62,54 @@ class TypeCheck {

~TypeCheck() = default;

bool FillInValue(int *memory, InitValAST *init, std::vector<int> &dim,
size_t i);
bool FillInValue(int *_memory, InitValAST *_init, std::vector<int> &_dim,
size_t _i);

std::unique_ptr<VarDeclAST> EvalVarDecl(VarDeclAST &varDecl);
std::unique_ptr<VarDeclAST> EvalVarDecl(VarDeclAST &_varDecl);

std::unique_ptr<ProcessedIdAST> EvalId(IdAST &id);
std::unique_ptr<ProcessedIdAST> EvalId(IdAST &_id);

std::unique_ptr<VarDefAST> EvalVarDef(VarDefAST &varDef);
std::unique_ptr<VarDefAST> EvalVarDef(VarDefAST &_varDef);

std::unique_ptr<FuncCallAST> EvalFuncCall(FuncCallAST &func);
std::unique_ptr<FuncCallAST> EvalFuncCall(FuncCallAST &_func);

std::unique_ptr<BlockAST> EvalBlock(BlockAST &block);
std::unique_ptr<BlockAST> EvalBlock(BlockAST &_block);

std::unique_ptr<IfAST> EvalIfElse(IfAST &stmt);
std::unique_ptr<IfAST> EvalIfElse(IfAST &_stmt);

std::unique_ptr<WhileAST> EvalWhile(WhileAST &stmt);
std::unique_ptr<WhileAST> EvalWhile(WhileAST &_stmt);

std::unique_ptr<ControlAST> EvalControl(ControlAST &stmt);
std::unique_ptr<ControlAST> EvalControl(ControlAST &_stmt);

std::unique_ptr<AssignAST> EvalAssign(AssignAST &assign);
std::unique_ptr<AssignAST> EvalAssign(AssignAST &_assign);

ASTPtr EvalLVal(LValAST &lval);
ASTPtr EvalLVal(LValAST &_lval);

ASTPtr EvalAddExp(BinaryAST &exp);
ASTPtr EvalAddExp(BinaryAST &_exp);

ASTPtr EvalMulExp(BinaryAST &exp);
ASTPtr EvalMulExp(BinaryAST &_exp);

ASTPtr EvalUnaryExp(UnaryAST &exp);
ASTPtr EvalUnaryExp(UnaryAST &_exp);

std::unique_ptr<FuncDefAST> EvalFuncDef(FuncDefAST &funcDef);
std::unique_ptr<FuncDefAST> EvalFuncDef(FuncDefAST &_funcDef);

ASTPtr EvalRelExp(BinaryAST &exp);
ASTPtr EvalRelExp(BinaryAST &_exp);

ASTPtr EvalLAndExp(BinaryAST &exp);
ASTPtr EvalLAndExp(BinaryAST &_exp);

ASTPtr EvalLOrExp(BinaryAST &exp);
ASTPtr EvalLOrExp(BinaryAST &_exp);

std::unique_ptr<CompUnitAST> EvalCompUnit(CompUnitAST &unit);
std::unique_ptr<CompUnitAST> EvalCompUnit(CompUnitAST &_unit);

ASTPtr EvalEqExp(BinaryAST &exp);
ASTPtr EvalEqExp(BinaryAST &_exp);

std::unique_ptr<StmtAST> EvalStmt(StmtAST &stmt);
std::unique_ptr<StmtAST> EvalStmt(StmtAST &_stmt);

std::unique_ptr<InitValAST> EvalInitVal(InitValAST &init);
std::unique_ptr<InitValAST> EvalInitVal(InitValAST &_init);

std::unique_ptr<NumAST> EvalNumber(NumAST &num);
std::unique_ptr<NumAST> EvalNumber(NumAST &_num);

std::unique_ptr<ProcessedIdAST> EvalProcessedId(ProcessedIdAST &id);
std::unique_ptr<ProcessedIdAST> EvalProcessedId(ProcessedIdAST &_id);

std::unique_ptr<EmptyAST> EvalEmpty();
};
Expand Down
14 changes: 7 additions & 7 deletions src/lexical/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Keywords::Keywords() {
keywords["return"] = KW_RETURN;
}

Tag Keywords::get_tag(std::string name) {
return keywords.find(name) != keywords.end() ? keywords[name] : ID;
Tag Keywords::get_tag(std::string _name) {
return keywords.find(_name) != keywords.end() ? keywords[_name] : ID;
}

const char *tokenName[] = {
Expand All @@ -44,28 +44,28 @@ const char *tokenName[] = {
"LBRACE", "RBRACE", "LBRACKET", "RBRACKET", "COMMA", "COLON", "SEMICON",
};

Token::Token(Tag t) : tag(t) { return; }
Token::Token(Tag _t) : tag(_t) { return; }

std::string Token::to_string() { return tokenName[tag]; }

Token::~Token() { return; }

Id::Id(std::string n) : Token(ID), name(n) { return; }
Id::Id(std::string _n) : Token(ID), name(_n) { return; }

std::string Id::to_string() { return Token::to_string() + "(" + name + ")"; }

Num::Num(int v) : Token(NUM), val(v) { return; }
Num::Num(int _v) : Token(NUM), val(_v) { return; }

std::string Num::to_string() {
return Token::to_string() + "(" + std::to_string(val) + ")";
}

Char::Char(char c) : Token(CHAR), ch(c) { return; }
Char::Char(char _c) : Token(CHAR), ch(_c) { return; }

std::string Char::to_string() {
return Token::to_string() + "(" + std::to_string(ch) + ")";
}

Str::Str(std::string s) : Token(STR), str(s) { return; }
Str::Str(std::string _s) : Token(STR), str(_s) { return; }

std::string Str::to_string() { return Token::to_string() + "(" + str + ")"; }
30 changes: 15 additions & 15 deletions src/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "parser.h"

Parser::Parser(Lexer &lex) : lexer(lex) { return; }
Parser::Parser(Lexer &_lex) : lexer(_lex) { return; }

Parser::~Parser() { return; }

Expand All @@ -27,8 +27,8 @@ void Parser::next() {
}

// 匹配指定 Token
bool Parser::match_token(Tag tag) {
if (token->tag == tag) {
bool Parser::match_token(Tag _tag) {
if (token->tag == _tag) {
return true;
} else {
return false;
Expand Down Expand Up @@ -194,18 +194,18 @@ ASTPtr Parser::program() {
}

// 二元表达式
ASTPtr Parser::binary(const std::function<ASTPtr()> &parser,
std::initializer_list<Operator> ops) {
auto lhs = parser();
ASTPtr Parser::binary(const std::function<ASTPtr()> &_parser,
std::initializer_list<Operator> _ops) {
auto lhs = _parser();
if (!lhs) {
std::cout << "error 100" << std::endl;
exit(100);
}
while (std::find(ops.begin(), ops.end(), tag_to_op(token->tag)) !=
ops.end()) {
while (std::find(_ops.begin(), _ops.end(), tag_to_op(token->tag)) !=
_ops.end()) {
Operator op = tag_to_op(token->tag);
next();
auto rhs = parser();
auto rhs = _parser();
if (!rhs) {
std::cout << "error 101" << std::endl;
exit(101);
Expand Down Expand Up @@ -564,7 +564,7 @@ ASTPtr Parser::var_decl() {
return std::make_unique<VarDeclAST>(isConst, std::move(vars));
}

ASTPtr Parser::var_def(bool isConst) {
ASTPtr Parser::var_def(bool _isConst) {
if (!match_token(Tag::ID)) {
exit(452);
}
Expand All @@ -586,23 +586,23 @@ ASTPtr Parser::var_def(bool isConst) {
}
ASTPtr var;
if (dims.empty())
var = std::make_unique<IdAST>(id_name, VarType::var_t, isConst);
var = std::make_unique<IdAST>(id_name, VarType::var_t, _isConst);
else
var = std::make_unique<IdAST>(id_name, VarType::array_t, isConst,
var = std::make_unique<IdAST>(id_name, VarType::array_t, _isConst,
std::move(dims));
if (match_token(Tag::ASSIGN)) {
next(); // =
ASTPtr init = init_val();
if (!init) {
exit(456);
}
return std::make_unique<VarDefAST>(isConst, std::move(var),
return std::make_unique<VarDefAST>(_isConst, std::move(var),
std::move(init));
} else {
if (isConst) {
if (_isConst) {
exit(457);
}
return std::make_unique<VarDefAST>(isConst, std::move(var));
return std::make_unique<VarDefAST>(_isConst, std::move(var));
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/parser/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

// convert tag to operator

Operator tag_to_op(Tag t) {
switch (t) {
Operator tag_to_op(Tag _t) {
switch (_t) {
case Tag::ADD:
return add_op;
case Tag::SUB:
Expand Down Expand Up @@ -59,8 +59,8 @@ Operator tag_to_op(Tag t) {
}
}

std::string type_to_string(Type t) {
switch (t) {
std::string type_to_string(Type _t) {
switch (_t) {
case Type::int_t:
return "INT";
case Type::char_t:
Expand All @@ -72,8 +72,8 @@ std::string type_to_string(Type t) {
}
}

std::string vartype_to_string(VarType t) {
switch (t) {
std::string vartype_to_string(VarType _t) {
switch (_t) {
case VarType::var_t:
return "var";
case VarType::array_t:
Expand All @@ -83,8 +83,8 @@ std::string vartype_to_string(VarType t) {
}
}

std::string op_to_string(Operator p) {
switch (p) {
std::string op_to_string(Operator _p) {
switch (_p) {
case Operator::add_op:
return "add";
case Operator::sub_op:
Expand Down
4 changes: 2 additions & 2 deletions src/scanner/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#include "scanner.h"

Scanner::Scanner(const std::string &f) {
fin.open(f, std::ios::in);
Scanner::Scanner(const std::string &_filename) {
fin.open(_filename, std::ios::in);
if (fin.is_open() == false) {
std::cout << "File not open!" << std::endl;
}
Expand Down
Loading

0 comments on commit 57d2b9d

Please sign in to comment.