From b05b91a7ff782194f22fbb6f21b7f98edc49aa7c Mon Sep 17 00:00:00 2001 From: szdytom Date: Tue, 29 Aug 2023 20:29:32 +0800 Subject: [PATCH] update according to compiler's complain Signed-off-by: szdytom --- include/element.h | 25 ++++++++++--------------- include/token.h | 22 ++-------------------- include/work.h | 2 +- src/element.cpp | 14 +++++++++++++- src/main.cpp | 8 +++----- src/read.cpp | 11 ++++++----- src/scan.cpp | 4 ++-- src/token.cpp | 22 ++++++++++++++++++++++ src/work.cpp | 16 +++++++++------- xmake.lua | 2 +- 10 files changed, 69 insertions(+), 57 deletions(-) diff --git a/include/element.h b/include/element.h index 11a5427..ce110f6 100644 --- a/include/element.h +++ b/include/element.h @@ -2,15 +2,15 @@ #define ACPA_ELEMENT_H #include -#include -#include #include +#include +#include using std::map; -using std::vector; -using std::string; -using std::weak_ptr; using std::shared_ptr; +using std::string; +using std::vector; +using std::weak_ptr; struct Struct; struct ValType; @@ -27,27 +27,22 @@ struct Struct { }; struct ValType { - virtual const int type() = 0; + virtual int type() const = 0; + virtual ~ValType() = default; }; struct TemplateType : ValType { - const int type() override { - return 0; - } + int type() const override; }; struct StructType : ValType { - const int type() override { - return 1; - } + int type() const override; shared_ptr str; map, shared_ptr> mp; }; struct FunctionType : ValType { - const int type() override { - return 2; - } + int type() const override; vector> c1; vector> c2; shared_ptr c3; diff --git a/include/token.h b/include/token.h index 0481395..89e489e 100644 --- a/include/token.h +++ b/include/token.h @@ -1,8 +1,8 @@ #ifndef ACPA_TOKEN_H #define ACPA_TOKEN_H -#include #include +#include enum class TokenType { COMMA, // , @@ -27,25 +27,7 @@ enum class TokenType { EXCEED }; -std::string token_mp[] = {",", - ";", - "{", - "}", - "(", - ")", - "<", - ">", - "=", - ".", - ":", - "::", - "->", - "struct", - "Fn", - "return", - "typeof", - "public", - "ID"}; +extern std::string token_mp[]; struct Token { int line; diff --git a/include/work.h b/include/work.h index 7ded275..eec1a53 100644 --- a/include/work.h +++ b/include/work.h @@ -1,8 +1,8 @@ #ifndef ACPA_WORK_H #define ACPA_WORK_H -#include "token.h" #include "element.h" +#include "token.h" #include void work(std::vector); diff --git a/src/element.cpp b/src/element.cpp index 8ca8c37..d82b7c1 100644 --- a/src/element.cpp +++ b/src/element.cpp @@ -1,9 +1,21 @@ #include "element.h" -#include #include +#include using namespace std; +int TemplateType::type() const { + return 0; +} + +int StructType::type() const { + return 1; +} + +int FunctionType::type() const { + return 2; +} + bool sameType(shared_ptr a, shared_ptr b) { static set, shared_ptr>> eq; if (a->type() != b->type()) { diff --git a/src/main.cpp b/src/main.cpp index d416886..89eaf39 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,16 +1,15 @@ +#include "element.h" #include "read.h" #include "scan.h" #include "token.h" -#include "element.h" #include "work.h" #include using namespace std; int main(int argc, char* argv[]) { - #define AS_STR(x) #x argparse::ArgumentParser program("acpa", - AS_STR(APP_VERSION), + "0.1a0", argparse::default_arguments::help, false); @@ -30,7 +29,6 @@ int main(int argc, char* argv[]) { freopen(input_file.c_str(), "r", stdin); work(scan(read())); - + return 0; } - diff --git a/src/read.cpp b/src/read.cpp index bb258ca..765a502 100644 --- a/src/read.cpp +++ b/src/read.cpp @@ -2,9 +2,10 @@ using namespace std; -string read() -{ - string s; - for(char ch=getchar();ch!=EOF;ch=getchar()) s+=ch; - return s; +string read() { + string s; + for (char ch = getchar(); ch != EOF; ch = getchar()) { + s += ch; + } + return s; } \ No newline at end of file diff --git a/src/scan.cpp b/src/scan.cpp index 978d2af..bd74ca8 100644 --- a/src/scan.cpp +++ b/src/scan.cpp @@ -5,7 +5,7 @@ using namespace std; vector scan(string s) { size_t pt = 0; int line = 1; - vector tokens; + vector tokens; auto skipSpace = [&]() { while (pt < s.size() && isspace(s[pt])) { if (s[pt] == '\n') { @@ -74,5 +74,5 @@ vector scan(string s) { } tokens.push_back({line, type, t}); } - return tokens; + return tokens; } \ No newline at end of file diff --git a/src/token.cpp b/src/token.cpp index e69de29..873a0cd 100644 --- a/src/token.cpp +++ b/src/token.cpp @@ -0,0 +1,22 @@ + +#include + +std::string token_mp[] = {",", + ";", + "{", + "}", + "(", + ")", + "<", + ">", + "=", + ".", + ":", + "::", + "->", + "struct", + "Fn", + "return", + "typeof", + "public", + "ID"}; diff --git a/src/work.cpp b/src/work.cpp index 51a7ad8..56f995e 100644 --- a/src/work.cpp +++ b/src/work.cpp @@ -1,6 +1,6 @@ #include "work.h" -#include #include +#include using namespace std; @@ -10,32 +10,34 @@ vector tokens; // void printTokens() { // wstring_convert> cvt; // for (auto u : tokens) { -// cout << token_mp[static_cast(u.type)] << " " << u.line << " " << cvt.to_bytes(u.s) +// cout << token_mp[static_cast(u.type)] << " " << u.line << " " << +// cvt.to_bytes(u.s) // << endl; // } // cout << endl; // } struct Def { - virtual const int type() = 0; + virtual int type() const = 0; + virtual ~Def() = default; }; struct DefTemplate : Def { - const int type() override { + int type() const override { return 0; } shared_ptr def_template; }; struct DefStruct : Def { - const int type() override { + int type() const override { return 1; } shared_ptr def_struct; }; struct DefVar : Def { - const int type() override { + int type() const override { return 2; } shared_ptr def_var; @@ -596,6 +598,6 @@ pair> createVar() { } void work(vector _tokens) { - tokens=_tokens; + tokens = _tokens; createVar(); } \ No newline at end of file diff --git a/xmake.lua b/xmake.lua index 3ac57d1..06e25ee 100644 --- a/xmake.lua +++ b/xmake.lua @@ -12,7 +12,7 @@ target("build") set_default(true) set_warnings("allextra") add_files("src/**.cpp") - -- add_includedirs("include/") + add_includedirs("include/") add_includedirs("third-party/") add_defines("APP_VERSION=" .. app_version) if is_mode("release") then