format main.cpp
This commit is contained in:
parent
3148127319
commit
3640da1cf2
44
src/main.cpp
44
src/main.cpp
@ -1,16 +1,16 @@
|
||||
#include <bits/stdc++.h>
|
||||
#include <argparse/argparse.hpp>
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
enum class TokenType {
|
||||
COMMA, // ,
|
||||
SEMI, // ;
|
||||
LB,
|
||||
RB,
|
||||
LP,
|
||||
RP,
|
||||
LT,
|
||||
RT, // { } ( ) < >
|
||||
LB, // {
|
||||
RB, // }
|
||||
LP, // (
|
||||
RP, // )
|
||||
LT, // <
|
||||
RT, // >
|
||||
ASSIGN, // =
|
||||
DOT, // .
|
||||
COLON, // :
|
||||
@ -21,7 +21,8 @@ enum class TokenType {
|
||||
RETURN, // return
|
||||
TYPEOF, // typeof
|
||||
PUBLIC, // public
|
||||
ID
|
||||
ID, // identifier
|
||||
EXCEED
|
||||
};
|
||||
|
||||
struct Token {
|
||||
@ -55,7 +56,8 @@ void printTokens() {
|
||||
"public",
|
||||
"ID"};
|
||||
for (auto u : tokens) {
|
||||
cout << mp[static_cast<int>(u.type)] << " " << u.line << " " << cvt.to_bytes(u.s) << endl;
|
||||
cout << mp[static_cast<int>(u.type)] << " " << u.line << " " << cvt.to_bytes(u.s)
|
||||
<< endl;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
@ -191,7 +193,8 @@ bool sameType(shared_ptr<ValType> a, shared_ptr<ValType> b) {
|
||||
return false;
|
||||
}
|
||||
if (a->type() == 0) {
|
||||
auto aa = static_pointer_cast<TemplateType>(a), bb = static_pointer_cast<TemplateType>(b);
|
||||
auto aa = static_pointer_cast<TemplateType>(a),
|
||||
bb = static_pointer_cast<TemplateType>(b);
|
||||
return aa == bb || eq.find({aa, bb}) != eq.end();
|
||||
}
|
||||
if (a->type() == 1) {
|
||||
@ -201,7 +204,8 @@ bool sameType(shared_ptr<ValType> a, shared_ptr<ValType> b) {
|
||||
return false;
|
||||
}
|
||||
assert(aa->mp.size() == bb->mp.size());
|
||||
for (auto ia = aa->mp.begin(), ib = bb->mp.begin(); ia != aa->mp.end(); ia++, ib++) {
|
||||
for (auto ia = aa->mp.begin(), ib = bb->mp.begin(); ia != aa->mp.end();
|
||||
ia++, ib++) {
|
||||
assert(ia->first == ib->first);
|
||||
if (!sameType(ia->second, ib->second)) {
|
||||
return false;
|
||||
@ -323,7 +327,8 @@ shared_ptr<ValType> struct_replace(shared_ptr<ValType> vt, shared_ptr<StructType
|
||||
for (auto u = vtt->str; u.get() != nullptr; u = u->fa.lock()) {
|
||||
vis.insert(u);
|
||||
}
|
||||
for (auto u = ut->str; u.get() != nullptr && vis.find(u) == vis.end(); u = u->fa.lock()) {
|
||||
for (auto u = ut->str; u.get() != nullptr && vis.find(u) == vis.end();
|
||||
u = u->fa.lock()) {
|
||||
for (auto tem : u->c1) {
|
||||
tt->mp.erase(tem);
|
||||
}
|
||||
@ -507,7 +512,8 @@ shared_ptr<ValType> createVal() {
|
||||
bool legal = vals.size() == tt->str->c2.size();
|
||||
if (legal) {
|
||||
for (size_t i = 0; i < vals.size(); i++) {
|
||||
if (!sameType(vals[i], struct_replace(tt->str->c2[i], tt))) {
|
||||
if (!sameType(vals[i],
|
||||
struct_replace(tt->str->c2[i], tt))) {
|
||||
legal = 0;
|
||||
break;
|
||||
}
|
||||
@ -817,15 +823,17 @@ void work() {
|
||||
createVar();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
argparse::ArgumentParser program("acpa", APP_VERSION
|
||||
, argparse::default_arguments::help, false);
|
||||
int main(int argc, char* argv[]) {
|
||||
argparse::ArgumentParser program("acpa",
|
||||
APP_VERSION,
|
||||
argparse::default_arguments::help,
|
||||
false);
|
||||
program.add_argument("input_file")
|
||||
.help("Source proof file")
|
||||
.action([](const std::string &value) { return value; });
|
||||
.action([](const std::string& value) { return value; });
|
||||
try {
|
||||
program.parse_args(argc, argv);
|
||||
} catch (const std::runtime_error &err) {
|
||||
} catch (const std::runtime_error& err) {
|
||||
cerr << err.what() << std::endl;
|
||||
cerr << program;
|
||||
return 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user