update according to compiler's complain
Signed-off-by: szdytom <szdytom@qq.com>
This commit is contained in:
parent
a9666c9857
commit
b05b91a7ff
@ -2,15 +2,15 @@
|
|||||||
#define ACPA_ELEMENT_H
|
#define ACPA_ELEMENT_H
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::vector;
|
|
||||||
using std::string;
|
|
||||||
using std::weak_ptr;
|
|
||||||
using std::shared_ptr;
|
using std::shared_ptr;
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::weak_ptr;
|
||||||
|
|
||||||
struct Struct;
|
struct Struct;
|
||||||
struct ValType;
|
struct ValType;
|
||||||
@ -27,27 +27,22 @@ struct Struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ValType {
|
struct ValType {
|
||||||
virtual const int type() = 0;
|
virtual int type() const = 0;
|
||||||
|
virtual ~ValType() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TemplateType : ValType {
|
struct TemplateType : ValType {
|
||||||
const int type() override {
|
int type() const override;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StructType : ValType {
|
struct StructType : ValType {
|
||||||
const int type() override {
|
int type() const override;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
shared_ptr<Struct> str;
|
shared_ptr<Struct> str;
|
||||||
map<shared_ptr<TemplateType>, shared_ptr<ValType>> mp;
|
map<shared_ptr<TemplateType>, shared_ptr<ValType>> mp;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FunctionType : ValType {
|
struct FunctionType : ValType {
|
||||||
const int type() override {
|
int type() const override;
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
vector<shared_ptr<TemplateType>> c1;
|
vector<shared_ptr<TemplateType>> c1;
|
||||||
vector<shared_ptr<ValType>> c2;
|
vector<shared_ptr<ValType>> c2;
|
||||||
shared_ptr<ValType> c3;
|
shared_ptr<ValType> c3;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef ACPA_TOKEN_H
|
#ifndef ACPA_TOKEN_H
|
||||||
#define ACPA_TOKEN_H
|
#define ACPA_TOKEN_H
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
enum class TokenType {
|
enum class TokenType {
|
||||||
COMMA, // ,
|
COMMA, // ,
|
||||||
@ -27,25 +27,7 @@ enum class TokenType {
|
|||||||
EXCEED
|
EXCEED
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string token_mp[] = {",",
|
extern std::string token_mp[];
|
||||||
";",
|
|
||||||
"{",
|
|
||||||
"}",
|
|
||||||
"(",
|
|
||||||
")",
|
|
||||||
"<",
|
|
||||||
">",
|
|
||||||
"=",
|
|
||||||
".",
|
|
||||||
":",
|
|
||||||
"::",
|
|
||||||
"->",
|
|
||||||
"struct",
|
|
||||||
"Fn",
|
|
||||||
"return",
|
|
||||||
"typeof",
|
|
||||||
"public",
|
|
||||||
"ID"};
|
|
||||||
|
|
||||||
struct Token {
|
struct Token {
|
||||||
int line;
|
int line;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef ACPA_WORK_H
|
#ifndef ACPA_WORK_H
|
||||||
#define ACPA_WORK_H
|
#define ACPA_WORK_H
|
||||||
|
|
||||||
#include "token.h"
|
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
|
#include "token.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void work(std::vector<Token>);
|
void work(std::vector<Token>);
|
||||||
|
@ -1,9 +1,21 @@
|
|||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include <set>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
using namespace std;
|
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<ValType> a, shared_ptr<ValType> b) {
|
bool sameType(shared_ptr<ValType> a, shared_ptr<ValType> b) {
|
||||||
static set<pair<shared_ptr<TemplateType>, shared_ptr<TemplateType>>> eq;
|
static set<pair<shared_ptr<TemplateType>, shared_ptr<TemplateType>>> eq;
|
||||||
if (a->type() != b->type()) {
|
if (a->type() != b->type()) {
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
|
#include "element.h"
|
||||||
#include "read.h"
|
#include "read.h"
|
||||||
#include "scan.h"
|
#include "scan.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
#include "element.h"
|
|
||||||
#include "work.h"
|
#include "work.h"
|
||||||
#include <argparse/argparse.hpp>
|
#include <argparse/argparse.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
#define AS_STR(x) #x
|
|
||||||
argparse::ArgumentParser program("acpa",
|
argparse::ArgumentParser program("acpa",
|
||||||
AS_STR(APP_VERSION),
|
"0.1a0",
|
||||||
argparse::default_arguments::help,
|
argparse::default_arguments::help,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
@ -33,4 +32,3 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
src/read.cpp
11
src/read.cpp
@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
string read()
|
string read() {
|
||||||
{
|
string s;
|
||||||
string s;
|
for (char ch = getchar(); ch != EOF; ch = getchar()) {
|
||||||
for(char ch=getchar();ch!=EOF;ch=getchar()) s+=ch;
|
s += ch;
|
||||||
return s;
|
}
|
||||||
|
return s;
|
||||||
}
|
}
|
@ -5,7 +5,7 @@ using namespace std;
|
|||||||
vector<Token> scan(string s) {
|
vector<Token> scan(string s) {
|
||||||
size_t pt = 0;
|
size_t pt = 0;
|
||||||
int line = 1;
|
int line = 1;
|
||||||
vector<Token> tokens;
|
vector<Token> tokens;
|
||||||
auto skipSpace = [&]() {
|
auto skipSpace = [&]() {
|
||||||
while (pt < s.size() && isspace(s[pt])) {
|
while (pt < s.size() && isspace(s[pt])) {
|
||||||
if (s[pt] == '\n') {
|
if (s[pt] == '\n') {
|
||||||
@ -74,5 +74,5 @@ vector<Token> scan(string s) {
|
|||||||
}
|
}
|
||||||
tokens.push_back({line, type, t});
|
tokens.push_back({line, type, t});
|
||||||
}
|
}
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::string token_mp[] = {",",
|
||||||
|
";",
|
||||||
|
"{",
|
||||||
|
"}",
|
||||||
|
"(",
|
||||||
|
")",
|
||||||
|
"<",
|
||||||
|
">",
|
||||||
|
"=",
|
||||||
|
".",
|
||||||
|
":",
|
||||||
|
"::",
|
||||||
|
"->",
|
||||||
|
"struct",
|
||||||
|
"Fn",
|
||||||
|
"return",
|
||||||
|
"typeof",
|
||||||
|
"public",
|
||||||
|
"ID"};
|
16
src/work.cpp
16
src/work.cpp
@ -1,6 +1,6 @@
|
|||||||
#include "work.h"
|
#include "work.h"
|
||||||
#include <set>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -10,32 +10,34 @@ vector<Token> tokens;
|
|||||||
// void printTokens() {
|
// void printTokens() {
|
||||||
// wstring_convert<codecvt_utf8<wchar_t>> cvt;
|
// wstring_convert<codecvt_utf8<wchar_t>> cvt;
|
||||||
// for (auto u : tokens) {
|
// for (auto u : tokens) {
|
||||||
// cout << token_mp[static_cast<int>(u.type)] << " " << u.line << " " << cvt.to_bytes(u.s)
|
// cout << token_mp[static_cast<int>(u.type)] << " " << u.line << " " <<
|
||||||
|
// cvt.to_bytes(u.s)
|
||||||
// << endl;
|
// << endl;
|
||||||
// }
|
// }
|
||||||
// cout << endl;
|
// cout << endl;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
struct Def {
|
struct Def {
|
||||||
virtual const int type() = 0;
|
virtual int type() const = 0;
|
||||||
|
virtual ~Def() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DefTemplate : Def {
|
struct DefTemplate : Def {
|
||||||
const int type() override {
|
int type() const override {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
shared_ptr<TemplateType> def_template;
|
shared_ptr<TemplateType> def_template;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DefStruct : Def {
|
struct DefStruct : Def {
|
||||||
const int type() override {
|
int type() const override {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
shared_ptr<Struct> def_struct;
|
shared_ptr<Struct> def_struct;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DefVar : Def {
|
struct DefVar : Def {
|
||||||
const int type() override {
|
int type() const override {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
shared_ptr<ValType> def_var;
|
shared_ptr<ValType> def_var;
|
||||||
@ -596,6 +598,6 @@ pair<string, shared_ptr<ValType>> createVar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void work(vector<Token> _tokens) {
|
void work(vector<Token> _tokens) {
|
||||||
tokens=_tokens;
|
tokens = _tokens;
|
||||||
createVar();
|
createVar();
|
||||||
}
|
}
|
@ -12,7 +12,7 @@ target("build")
|
|||||||
set_default(true)
|
set_default(true)
|
||||||
set_warnings("allextra")
|
set_warnings("allextra")
|
||||||
add_files("src/**.cpp")
|
add_files("src/**.cpp")
|
||||||
-- add_includedirs("include/")
|
add_includedirs("include/")
|
||||||
add_includedirs("third-party/")
|
add_includedirs("third-party/")
|
||||||
add_defines("APP_VERSION=" .. app_version)
|
add_defines("APP_VERSION=" .. app_version)
|
||||||
if is_mode("release") then
|
if is_mode("release") then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user