Skip to content
This repository was archived by the owner on Jan 8, 2023. It is now read-only.

Commit 5f41601

Browse files
author
ApsarasX
committed
feat: update
1 parent 9a0563c commit 5f41601

12 files changed

Lines changed: 113 additions & 62 deletions

File tree

include/AST/AST.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
#include "AST/Module.h"
99
#include "AST/ASTVisitor.h"
1010

11-
#endif //STATICSCRIPT_AST_AST_H
11+
#endif // STATICSCRIPT_AST_AST_H

include/AST/ASTVisitor.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef STATICSCRIPT_AST_VISITOR_H
2-
#define STATICSCRIPT_AST_VISITOR_H
1+
#ifndef STATICSCRIPT_AST_ASTVISITOR_H
2+
#define STATICSCRIPT_AST_ASTVISITOR_H
33

44
#include <iostream>
55
#include "StaticScriptParserBaseVisitor.h"
@@ -10,9 +10,9 @@
1010
#include "AST/Module.h"
1111
#include "Util/Alias.h"
1212

13-
class Visitor : public StaticScriptParserVisitor {
13+
class ASTVisitor final : public StaticScriptParserVisitor {
1414
public:
15-
explicit Visitor(String filename);
15+
explicit ASTVisitor(String filename);
1616

1717
antlrcpp::Any visitModule(StaticScriptParser::ModuleContext *ctx) override;
1818

@@ -85,4 +85,4 @@ class Visitor : public StaticScriptParserVisitor {
8585
};
8686

8787

88-
#endif // STATICSCRIPT_AST_VISITOR_H
88+
#endif // STATICSCRIPT_AST_ASTVISITOR_H

include/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ class FunctionDecl : public Decl {
5454
SharedPtr<CompoundStmt> body;
5555
};
5656

57-
#endif //STATICSCRIPT_AST_DECL_H
57+
#endif // STATICSCRIPT_AST_DECL_H

include/AST/Expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ class BinaryOperatorExpr : public Expr {
103103
SharedPtr<Expr> lhs, rhs;
104104
};
105105

106-
#endif //STATICSCRIPT_AST_EXPR_H
106+
#endif // STATICSCRIPT_AST_EXPR_H

include/AST/Module.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33

44
#include "AST/Stmt.h"
55

6-
// 模块声明
6+
/// 一个文件就是一个模块, 即一个翻译单元
77
class Module final {
88
public:
99
virtual ~Module() = default;
1010

1111
explicit Module(String filename, SharedPtrVector<Stmt> childStmts);
1212

13-
[[nodiscard]] const String &getFilename() const;
13+
[[nodiscard]] virtual const String &getFilename() const;
1414

15-
[[nodiscard]] bool isEmpty() const;
15+
[[nodiscard]] virtual bool isEmpty() const;
1616

17-
private:
18-
const String filename;
17+
String filename;
1918
SharedPtrVector<Stmt> childStmts;
2019
};
2120

2221

23-
#endif //STATICSCRIPT_AST_MODULE_H
22+
#endif // STATICSCRIPT_AST_MODULE_H

include/AST/Stmt.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,34 @@ class ValueStmt : public Stmt {
2121
};
2222

2323
// 复合语句
24-
class CompoundStmt : public Stmt {
24+
class CompoundStmt final : public Stmt {
2525
public:
26-
2726
explicit CompoundStmt(const SharedPtrVector<Stmt> &childStmts);
2827

2928
~CompoundStmt() override = default;
3029

30+
[[nodiscard]] virtual bool isEmpty() const;
31+
3132
SharedPtrVector<Stmt> childStmts;
3233
};
3334

3435
// 变量声明语句
35-
class VarDeclStmt : public Stmt {
36+
class VarDeclStmt final : public Stmt {
3637
public:
3738
~VarDeclStmt() override = default;
3839

3940
virtual void pushVarDecl(const SharedPtr<VarDecl> &varDecl);
4041

41-
private:
4242
SharedPtrVector<VarDecl> childVarDecls;
4343
};
4444

4545
// 函数声明语句
46-
class FunctionDeclStmt : public Stmt {
46+
class FunctionDeclStmt final : public Stmt {
4747
public:
4848
explicit FunctionDeclStmt(const SharedPtr<FunctionDecl> &childFunctionDecl);
4949

5050
~FunctionDeclStmt() override = default;
5151

52-
private:
5352
SharedPtr<FunctionDecl> childFunctionDecl;
5453
};
5554

@@ -114,4 +113,4 @@ class ReturnStmt : public Stmt {
114113
};
115114

116115

117-
#endif //STATICSCRIPT_AST_STMT_H
116+
#endif // STATICSCRIPT_AST_STMT_H

include/AST/Type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ class BuiltinType : public Type {
2929
static inline const SharedPtr<BuiltinType> UNKNOWN_TYPE = makeShared<BuiltinType>(TypeKind::Unknown);
3030
};
3131

32-
#endif //STATICSCRIPT_AST_TYPE_H
32+
#endif // STATICSCRIPT_AST_TYPE_H

include/Util/Alias.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ using SharedPtr = std::shared_ptr<T>;
1313
template <typename T>
1414
using SharedPtrVector = std::vector<SharedPtr<T>>;
1515

16-
template <typename T, typename ...Args>
17-
SharedPtr<T> makeShared(Args&& ...args) {
16+
template<typename T, typename ...Args>
17+
inline SharedPtr<T> makeShared(Args &&...args) {
1818
return std::make_shared<T>(std::forward<Args>(args)...);
1919
}
2020

include/Util/Output.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef STATICSCRIPT_UTIL_OUTPUT_H
2+
#define STATICSCRIPT_UTIL_OUTPUT_H
3+
4+
#include <iostream>
5+
#include "Util/Alias.h"
6+
7+
template<typename T>
8+
static inline void print(std::ostream &outputStream, T &&content) {
9+
outputStream << content;
10+
}
11+
12+
template<typename T, typename ...U>
13+
static inline void print(std::ostream &outputStream, T &&content, U &&...restContent) {
14+
outputStream << content;
15+
print(outputStream, restContent...);
16+
}
17+
18+
template<typename ...T>
19+
inline void outPrint(T &&...content) {
20+
print(std::cout, content...);
21+
}
22+
23+
inline void outPrintln() {
24+
std::cout << std::endl;
25+
}
26+
27+
template<typename ...T>
28+
inline void outPrintln(T &&...content) {
29+
print(std::cout, content...);
30+
outPrintln();
31+
}
32+
33+
template<typename ...T>
34+
inline void errPrint(T &&...content) {
35+
print(std::cerr, content...);
36+
}
37+
38+
inline void errPrintln() {
39+
std::cerr << std::endl;
40+
}
41+
42+
template<typename ...T>
43+
inline void errPrintln(T &&...content) {
44+
print(std::cerr, content...);
45+
errPrintln();
46+
}
47+
48+
#endif // STATICSCRIPT_UTIL_OUTPUT_H

0 commit comments

Comments
 (0)