Commit 8ad9ba03 authored by 4ast's avatar 4ast Committed by GitHub

Merge pull request #824 from palmtenor/exception_h

Clean up bcc_exception.h
parents 8ff670d9 259ff4e2
...@@ -61,15 +61,15 @@ int task_switch_event(struct pt_regs *ctx, struct task_struct *prev) { ...@@ -61,15 +61,15 @@ int task_switch_event(struct pt_regs *ctx, struct task_struct *prev) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
ebpf::BPF bpf; ebpf::BPF bpf;
auto init_res = bpf.init(BPF_PROGRAM); auto init_res = bpf.init(BPF_PROGRAM);
if (std::get<0>(init_res) != 0) { if (init_res.code() != 0) {
std::cerr << std::get<1>(init_res) << std::endl; std::cerr << init_res.msg() << std::endl;
return 1; return 1;
} }
auto attach_res = auto attach_res =
bpf.attach_kprobe("finish_task_switch", "task_switch_event"); bpf.attach_kprobe("finish_task_switch", "task_switch_event");
if (std::get<0>(attach_res) != 0) { if (attach_res.code() != 0) {
std::cerr << std::get<1>(attach_res) << std::endl; std::cerr << attach_res.msg() << std::endl;
return 1; return 1;
} }
...@@ -88,8 +88,8 @@ int main(int argc, char** argv) { ...@@ -88,8 +88,8 @@ int main(int argc, char** argv) {
} }
auto detach_res = bpf.detach_kprobe("finish_task_switch"); auto detach_res = bpf.detach_kprobe("finish_task_switch");
if (std::get<0>(detach_res) != 0) { if (detach_res.code() != 0) {
std::cerr << std::get<1>(detach_res) << std::endl; std::cerr << detach_res.msg() << std::endl;
return 1; return 1;
} }
......
...@@ -20,8 +20,8 @@ int on_sys_clone(void *ctx) { ...@@ -20,8 +20,8 @@ int on_sys_clone(void *ctx) {
int main() { int main() {
ebpf::BPF bpf; ebpf::BPF bpf;
auto init_res = bpf.init(BPF_PROGRAM); auto init_res = bpf.init(BPF_PROGRAM);
if (std::get<0>(init_res) != 0) { if (init_res.code() != 0) {
std::cerr << std::get<1>(init_res) << std::endl; std::cerr << init_res.msg() << std::endl;
return 1; return 1;
} }
...@@ -29,8 +29,8 @@ int main() { ...@@ -29,8 +29,8 @@ int main() {
std::string line; std::string line;
auto attach_res = bpf.attach_kprobe("sys_clone", "on_sys_clone"); auto attach_res = bpf.attach_kprobe("sys_clone", "on_sys_clone");
if (std::get<0>(attach_res) != 0) { if (attach_res.code() != 0) {
std::cerr << std::get<1>(attach_res) << std::endl; std::cerr << attach_res.msg() << std::endl;
return 1; return 1;
} }
...@@ -39,8 +39,8 @@ int main() { ...@@ -39,8 +39,8 @@ int main() {
std::cout << line << std::endl; std::cout << line << std::endl;
// Detach the probe if we got at least one line. // Detach the probe if we got at least one line.
auto detach_res = bpf.detach_kprobe("sys_clone"); auto detach_res = bpf.detach_kprobe("sys_clone");
if (std::get<0>(detach_res) != 0) { if (detach_res.code() != 0) {
std::cerr << std::get<1>(detach_res) << std::endl; std::cerr << detach_res.msg() << std::endl;
return 1; return 1;
} }
break; break;
......
...@@ -70,21 +70,21 @@ void signal_handler(int s) { ...@@ -70,21 +70,21 @@ void signal_handler(int s) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
bpf = new ebpf::BPF(); bpf = new ebpf::BPF();
auto init_res = bpf->init(BPF_PROGRAM); auto init_res = bpf->init(BPF_PROGRAM);
if (std::get<0>(init_res) != 0) { if (init_res.code() != 0) {
std::cerr << std::get<1>(init_res) << std::endl; std::cerr << init_res.msg() << std::endl;
return 1; return 1;
} }
auto attach_res = auto attach_res =
bpf->attach_tracepoint("random:urandom_read", "on_urandom_read"); bpf->attach_tracepoint("random:urandom_read", "on_urandom_read");
if (std::get<0>(attach_res) != 0) { if (attach_res.code() != 0) {
std::cerr << std::get<1>(attach_res) << std::endl; std::cerr << attach_res.msg() << std::endl;
return 1; return 1;
} }
auto open_res = bpf->open_perf_buffer("events", &handle_output); auto open_res = bpf->open_perf_buffer("events", &handle_output);
if (std::get<0>(open_res) != 0) { if (open_res.code() != 0) {
std::cerr << std::get<1>(open_res) << std::endl; std::cerr << open_res.msg() << std::endl;
return 1; return 1;
} }
......
...@@ -63,15 +63,15 @@ int main(int argc, char** argv) { ...@@ -63,15 +63,15 @@ int main(int argc, char** argv) {
ebpf::BPF bpf; ebpf::BPF bpf;
auto init_res = bpf.init(BPF_PROGRAM); auto init_res = bpf.init(BPF_PROGRAM);
if (std::get<0>(init_res) != 0) { if (init_res.code() != 0) {
std::cerr << std::get<1>(init_res) << std::endl; std::cerr << init_res.msg() << std::endl;
return 1; return 1;
} }
auto attach_res = auto attach_res =
bpf.attach_uprobe(mysql_path, ALLOC_QUERY_FUNC, "probe_mysql_query"); bpf.attach_uprobe(mysql_path, ALLOC_QUERY_FUNC, "probe_mysql_query");
if (std::get<0>(attach_res) != 0) { if (attach_res.code() != 0) {
std::cerr << std::get<1>(attach_res) << std::endl; std::cerr << attach_res.msg() << std::endl;
return 1; return 1;
} }
...@@ -94,8 +94,8 @@ int main(int argc, char** argv) { ...@@ -94,8 +94,8 @@ int main(int argc, char** argv) {
} }
auto detach_res = bpf.detach_uprobe(mysql_path, ALLOC_QUERY_FUNC); auto detach_res = bpf.detach_uprobe(mysql_path, ALLOC_QUERY_FUNC);
if (std::get<0>(detach_res) != 0) { if (detach_res.code() != 0) {
std::cerr << std::get<1>(detach_res) << std::endl; std::cerr << detach_res.msg() << std::endl;
return 1; return 1;
} }
......
...@@ -58,14 +58,14 @@ struct stack_key_t { ...@@ -58,14 +58,14 @@ struct stack_key_t {
int main(int argc, char** argv) { int main(int argc, char** argv) {
ebpf::BPF bpf; ebpf::BPF bpf;
auto init_res = bpf.init(BPF_PROGRAM); auto init_res = bpf.init(BPF_PROGRAM);
if (std::get<0>(init_res) != 0) { if (init_res.code() != 0) {
std::cerr << std::get<1>(init_res) << std::endl; std::cerr << init_res.msg() << std::endl;
return 1; return 1;
} }
auto attach_res = bpf.attach_kprobe("tcp_sendmsg", "on_tcp_send"); auto attach_res = bpf.attach_kprobe("tcp_sendmsg", "on_tcp_send");
if (std::get<0>(attach_res) != 0) { if (attach_res.code() != 0) {
std::cerr << std::get<1>(attach_res) << std::endl; std::cerr << attach_res.msg() << std::endl;
return 1; return 1;
} }
...@@ -105,8 +105,8 @@ int main(int argc, char** argv) { ...@@ -105,8 +105,8 @@ int main(int argc, char** argv) {
} }
auto detach_res = bpf.detach_kprobe("tcp_sendmsg"); auto detach_res = bpf.detach_kprobe("tcp_sendmsg");
if (std::get<0>(detach_res) != 0) { if (detach_res.code() != 0) {
std::cerr << std::get<1>(detach_res) << std::endl; std::cerr << detach_res.msg() << std::endl;
return 1; return 1;
} }
......
This diff is collapsed.
...@@ -68,36 +68,36 @@ std::vector<std::string> BPFStackTable::get_stack_symbol(int stack_id, ...@@ -68,36 +68,36 @@ std::vector<std::string> BPFStackTable::get_stack_symbol(int stack_id,
StatusTuple BPFPerfBuffer::open_on_cpu(perf_reader_raw_cb cb, int cpu, StatusTuple BPFPerfBuffer::open_on_cpu(perf_reader_raw_cb cb, int cpu,
void* cb_cookie) { void* cb_cookie) {
if (cpu_readers_.find(cpu) != cpu_readers_.end()) if (cpu_readers_.find(cpu) != cpu_readers_.end())
return mkstatus(-1, "Perf buffer already open on CPU %d", cpu); return StatusTuple(-1, "Perf buffer already open on CPU %d", cpu);
auto reader = auto reader =
static_cast<perf_reader*>(bpf_open_perf_buffer(cb, cb_cookie, -1, cpu)); static_cast<perf_reader*>(bpf_open_perf_buffer(cb, cb_cookie, -1, cpu));
if (reader == nullptr) if (reader == nullptr)
return mkstatus(-1, "Unable to construct perf reader"); return StatusTuple(-1, "Unable to construct perf reader");
int reader_fd = perf_reader_fd(reader); int reader_fd = perf_reader_fd(reader);
if (!update(&cpu, &reader_fd)) { if (!update(&cpu, &reader_fd)) {
perf_reader_free(static_cast<void*>(reader)); perf_reader_free(static_cast<void*>(reader));
return mkstatus(-1, "Unable to open perf buffer on CPU %d: %s", cpu, return StatusTuple(-1, "Unable to open perf buffer on CPU %d: %s", cpu,
strerror(errno)); strerror(errno));
} }
cpu_readers_[cpu] = static_cast<perf_reader*>(reader); cpu_readers_[cpu] = static_cast<perf_reader*>(reader);
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple BPFPerfBuffer::open(perf_reader_raw_cb cb, void* cb_cookie) { StatusTuple BPFPerfBuffer::open(perf_reader_raw_cb cb, void* cb_cookie) {
for (int i = 0; i < sysconf(_SC_NPROCESSORS_ONLN); i++) for (int i = 0; i < sysconf(_SC_NPROCESSORS_ONLN); i++)
TRY2(open_on_cpu(cb, i, cb_cookie)); TRY2(open_on_cpu(cb, i, cb_cookie));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple BPFPerfBuffer::close_on_cpu(int cpu) { StatusTuple BPFPerfBuffer::close_on_cpu(int cpu) {
auto it = cpu_readers_.find(cpu); auto it = cpu_readers_.find(cpu);
if (it == cpu_readers_.end()) if (it == cpu_readers_.end())
return mkstatus(0); return StatusTuple(0);
perf_reader_free(static_cast<void*>(it->second)); perf_reader_free(static_cast<void*>(it->second));
if (!remove(const_cast<int*>(&(it->first)))) if (!remove(const_cast<int*>(&(it->first))))
return mkstatus(-1, "Unable to close perf buffer on CPU %d", it->first); return StatusTuple(-1, "Unable to close perf buffer on CPU %d", it->first);
cpu_readers_.erase(it); cpu_readers_.erase(it);
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple BPFPerfBuffer::close() { StatusTuple BPFPerfBuffer::close() {
...@@ -105,15 +105,15 @@ StatusTuple BPFPerfBuffer::close() { ...@@ -105,15 +105,15 @@ StatusTuple BPFPerfBuffer::close() {
bool has_error = false; bool has_error = false;
for (int i = 0; i < sysconf(_SC_NPROCESSORS_ONLN); i++) { for (int i = 0; i < sysconf(_SC_NPROCESSORS_ONLN); i++) {
auto res = close_on_cpu(i); auto res = close_on_cpu(i);
if (std::get<0>(res) != 0) { if (res.code() != 0) {
errors += "Failed to close CPU" + std::to_string(i) + " perf buffer: "; errors += "Failed to close CPU" + std::to_string(i) + " perf buffer: ";
errors += std::get<1>(res) + "\n"; errors += res.msg() + "\n";
has_error = true; has_error = true;
} }
} }
if (has_error) if (has_error)
return mkstatus(-1, errors); return StatusTuple(-1, errors);
return mkstatus(0); return StatusTuple(0);
} }
void BPFPerfBuffer::poll(int timeout) { void BPFPerfBuffer::poll(int timeout) {
...@@ -126,9 +126,9 @@ void BPFPerfBuffer::poll(int timeout) { ...@@ -126,9 +126,9 @@ void BPFPerfBuffer::poll(int timeout) {
BPFPerfBuffer::~BPFPerfBuffer() { BPFPerfBuffer::~BPFPerfBuffer() {
auto res = close(); auto res = close();
if (std::get<0>(res) != 0) if (res.code() != 0)
std::cerr << "Failed to close all perf buffer on destruction: " std::cerr << "Failed to close all perf buffer on destruction: "
<< std::get<1>(res) << std::endl; << res.msg() << std::endl;
} }
} // namespace ebpf } // namespace ebpf
...@@ -16,53 +16,46 @@ ...@@ -16,53 +16,46 @@
#pragma once #pragma once
#include <exception> #include <cstdio>
#include <string> #include <string>
#include <tuple>
#include <cstring>
#include <cerrno>
#include <cstdlib>
#undef NDEBUG #undef NDEBUG
namespace ebpf { namespace ebpf {
typedef std::tuple<int, std::string> StatusTuple; class StatusTuple {
public:
StatusTuple(int ret) : ret_(ret) {}
template <typename... Args> StatusTuple(int ret, const char *msg) : ret_(ret), msg_(msg) {}
StatusTuple mkstatus(int ret, const char *fmt, Args... args) {
char buf[1024];
snprintf(buf, sizeof(buf), fmt, args...);
return std::make_tuple(ret, std::string(buf));
}
static inline StatusTuple mkstatus(int ret, const char *msg) { StatusTuple(int ret, const std::string &msg) : ret_(ret), msg_(msg) {}
return std::make_tuple(ret, std::string(msg));
}
static inline StatusTuple mkstatus( template <typename... Args>
int ret, const std::string& msg StatusTuple(int ret, const char *fmt, Args... args) : ret_(ret) {
) { char buf[2048];
return std::make_tuple(ret, msg); snprintf(buf, sizeof(buf), fmt, args...);
} msg_ = std::string(buf);
}
static inline StatusTuple mkstatus(int ret) { void append_msg(const std::string& msg) {
return std::make_tuple(ret, std::string()); msg_ += msg;
} }
#define TRY(CMD) \ int code() { return ret_; }
do { \
int __status = (CMD); \ std::string msg() { return msg_; }
if (__status != 0) { \
return __status; \ private:
} \ int ret_;
} while (0) std::string msg_;
};
#define TRY2(CMD) \ #define TRY2(CMD) \
do { \ do { \
StatusTuple __stp = (CMD); \ StatusTuple __stp = (CMD); \
if (std::get<0>(__stp) != 0) { \ if (__stp.code() != 0) { \
return __stp; \ return __stp; \
} \ } \
} while (0) } while (0)
} // namespace ebpf } // namespace ebpf
This diff is collapsed.
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "loader.h" #include "loader.h"
#include "table_desc.h" #include "table_desc.h"
using std::get;
using std::string; using std::string;
using std::unique_ptr; using std::unique_ptr;
using std::vector; using std::vector;
...@@ -57,8 +56,8 @@ int BLoader::parse(llvm::Module *mod, const string &filename, const string &prot ...@@ -57,8 +56,8 @@ int BLoader::parse(llvm::Module *mod, const string &filename, const string &prot
ebpf::cc::TypeCheck type_check(parser_->scopes_.get(), proto_parser_->scopes_.get()); ebpf::cc::TypeCheck type_check(parser_->scopes_.get(), proto_parser_->scopes_.get());
auto ret = type_check.visit(parser_->root_node_); auto ret = type_check.visit(parser_->root_node_);
if (get<0>(ret) != 0 || get<1>(ret).size()) { if (ret.code() != 0 || ret.msg().size()) {
fprintf(stderr, "Type error @line=%d: %s\n", get<0>(ret), get<1>(ret).c_str()); fprintf(stderr, "Type error @line=%d: %s\n", ret.code(), ret.msg().c_str());
return -1; return -1;
} }
...@@ -66,9 +65,9 @@ int BLoader::parse(llvm::Module *mod, const string &filename, const string &prot ...@@ -66,9 +65,9 @@ int BLoader::parse(llvm::Module *mod, const string &filename, const string &prot
codegen_ = ebpf::make_unique<ebpf::cc::CodegenLLVM>(mod, parser_->scopes_.get(), proto_parser_->scopes_.get()); codegen_ = ebpf::make_unique<ebpf::cc::CodegenLLVM>(mod, parser_->scopes_.get(), proto_parser_->scopes_.get());
ret = codegen_->visit(parser_->root_node_, **tables); ret = codegen_->visit(parser_->root_node_, **tables);
if (get<0>(ret) != 0 || get<1>(ret).size()) { if (ret.code() != 0 || ret.msg().size()) {
fprintf(stderr, "Codegen error @line=%d: %s\n", get<0>(ret), get<1>(ret).c_str()); fprintf(stderr, "Codegen error @line=%d: %s\n", ret.code(), ret.msg().c_str());
return get<0>(ret); return ret.code();
} }
return 0; return 0;
......
...@@ -114,20 +114,18 @@ class Node { ...@@ -114,20 +114,18 @@ class Node {
}; };
template <typename... Args> template <typename... Args>
std::tuple<int, std::string> mkstatus_(Node *n, const char *fmt, Args... args) { StatusTuple mkstatus_(Node *n, const char *fmt, Args... args) {
char buf[1024]; StatusTuple status = StatusTuple(n->line_ ? n->line_ : -1, fmt, args...);
snprintf(buf, sizeof(buf), fmt, args...);
string out_msg(buf);
if (n->line_ > 0) if (n->line_ > 0)
out_msg += "\n" + n->text_; status.append_msg("\n" + n->text_);
return std::make_tuple(n->line_ ? n->line_ : -1, out_msg); return status;
} }
static inline std::tuple<int, std::string> mkstatus_(Node *n, const char *msg) { static inline StatusTuple mkstatus_(Node *n, const char *msg) {
string out_msg(msg); StatusTuple status = StatusTuple(n->line_ ? n->line_ : -1, msg);
if (n->line_ > 0) if (n->line_ > 0)
out_msg += "\n" + n->text_; status.append_msg("\n" + n->text_);
return std::make_tuple(n->line_ ? n->line_ : -1, out_msg); return status;
} }
class StmtNode : public Node { class StmtNode : public Node {
......
...@@ -38,7 +38,7 @@ StatusTuple Printer::visit_block_stmt_node(BlockStmtNode* n) { ...@@ -38,7 +38,7 @@ StatusTuple Printer::visit_block_stmt_node(BlockStmtNode* n) {
--indent_; --indent_;
} }
fprintf(out_, "%*s}", indent_, ""); fprintf(out_, "%*s}", indent_, "");
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_if_stmt_node(IfStmtNode* n) { StatusTuple Printer::visit_if_stmt_node(IfStmtNode* n) {
...@@ -50,7 +50,7 @@ StatusTuple Printer::visit_if_stmt_node(IfStmtNode* n) { ...@@ -50,7 +50,7 @@ StatusTuple Printer::visit_if_stmt_node(IfStmtNode* n) {
fprintf(out_, " else "); fprintf(out_, " else ");
TRY2(n->false_block_->accept(this)); TRY2(n->false_block_->accept(this));
} }
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_onvalid_stmt_node(OnValidStmtNode* n) { StatusTuple Printer::visit_onvalid_stmt_node(OnValidStmtNode* n) {
...@@ -62,7 +62,7 @@ StatusTuple Printer::visit_onvalid_stmt_node(OnValidStmtNode* n) { ...@@ -62,7 +62,7 @@ StatusTuple Printer::visit_onvalid_stmt_node(OnValidStmtNode* n) {
fprintf(out_, " else "); fprintf(out_, " else ");
TRY2(n->else_block_->accept(this)); TRY2(n->else_block_->accept(this));
} }
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_switch_stmt_node(SwitchStmtNode* n) { StatusTuple Printer::visit_switch_stmt_node(SwitchStmtNode* n) {
...@@ -70,7 +70,7 @@ StatusTuple Printer::visit_switch_stmt_node(SwitchStmtNode* n) { ...@@ -70,7 +70,7 @@ StatusTuple Printer::visit_switch_stmt_node(SwitchStmtNode* n) {
TRY2(n->cond_->accept(this)); TRY2(n->cond_->accept(this));
fprintf(out_, ") "); fprintf(out_, ") ");
TRY2(n->block_->accept(this)); TRY2(n->block_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_case_stmt_node(CaseStmtNode* n) { StatusTuple Printer::visit_case_stmt_node(CaseStmtNode* n) {
...@@ -81,7 +81,7 @@ StatusTuple Printer::visit_case_stmt_node(CaseStmtNode* n) { ...@@ -81,7 +81,7 @@ StatusTuple Printer::visit_case_stmt_node(CaseStmtNode* n) {
fprintf(out_, "default"); fprintf(out_, "default");
} }
TRY2(n->block_->accept(this)); TRY2(n->block_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_ident_expr_node(IdentExprNode* n) { StatusTuple Printer::visit_ident_expr_node(IdentExprNode* n) {
...@@ -92,37 +92,37 @@ StatusTuple Printer::visit_ident_expr_node(IdentExprNode* n) { ...@@ -92,37 +92,37 @@ StatusTuple Printer::visit_ident_expr_node(IdentExprNode* n) {
if (n->sub_name_.size()) { if (n->sub_name_.size()) {
fprintf(out_, ".%s", n->sub_name_.c_str()); fprintf(out_, ".%s", n->sub_name_.c_str());
} }
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_assign_expr_node(AssignExprNode* n) { StatusTuple Printer::visit_assign_expr_node(AssignExprNode* n) {
TRY2(n->lhs_->accept(this)); TRY2(n->lhs_->accept(this));
fprintf(out_, " = "); fprintf(out_, " = ");
TRY2(n->rhs_->accept(this)); TRY2(n->rhs_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_packet_expr_node(PacketExprNode* n) { StatusTuple Printer::visit_packet_expr_node(PacketExprNode* n) {
fprintf(out_, "$"); fprintf(out_, "$");
TRY2(n->id_->accept(this)); TRY2(n->id_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_integer_expr_node(IntegerExprNode* n) { StatusTuple Printer::visit_integer_expr_node(IntegerExprNode* n) {
fprintf(out_, "%s:%zu", n->val_.c_str(), n->bits_); fprintf(out_, "%s:%zu", n->val_.c_str(), n->bits_);
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_string_expr_node(StringExprNode *n) { StatusTuple Printer::visit_string_expr_node(StringExprNode *n) {
fprintf(out_, "%s", n->val_.c_str()); fprintf(out_, "%s", n->val_.c_str());
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_binop_expr_node(BinopExprNode* n) { StatusTuple Printer::visit_binop_expr_node(BinopExprNode* n) {
TRY2(n->lhs_->accept(this)); TRY2(n->lhs_->accept(this));
fprintf(out_, "%d", n->op_); fprintf(out_, "%d", n->op_);
TRY2(n->rhs_->accept(this)); TRY2(n->rhs_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_unop_expr_node(UnopExprNode* n) { StatusTuple Printer::visit_unop_expr_node(UnopExprNode* n) {
...@@ -135,25 +135,25 @@ StatusTuple Printer::visit_unop_expr_node(UnopExprNode* n) { ...@@ -135,25 +135,25 @@ StatusTuple Printer::visit_unop_expr_node(UnopExprNode* n) {
} }
fprintf(out_, "%s", s); fprintf(out_, "%s", s);
TRY2(n->expr_->accept(this)); TRY2(n->expr_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_bitop_expr_node(BitopExprNode* n) { StatusTuple Printer::visit_bitop_expr_node(BitopExprNode* n) {
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_return_expr_node(ReturnExprNode* n) { StatusTuple Printer::visit_return_expr_node(ReturnExprNode* n) {
fprintf(out_, "return "); fprintf(out_, "return ");
TRY2(n->expr_->accept(this)); TRY2(n->expr_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_goto_expr_node(GotoExprNode* n) { StatusTuple Printer::visit_goto_expr_node(GotoExprNode* n) {
const char* s = n->is_continue_ ? "continue " : "goto "; const char* s = n->is_continue_ ? "continue " : "goto ";
fprintf(out_, "%s", s); fprintf(out_, "%s", s);
TRY2(n->id_->accept(this)); TRY2(n->id_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_method_call_expr_node(MethodCallExprNode* n) { StatusTuple Printer::visit_method_call_expr_node(MethodCallExprNode* n) {
...@@ -177,19 +177,19 @@ StatusTuple Printer::visit_method_call_expr_node(MethodCallExprNode* n) { ...@@ -177,19 +177,19 @@ StatusTuple Printer::visit_method_call_expr_node(MethodCallExprNode* n) {
--indent_; --indent_;
fprintf(out_, "%*s}", indent_, ""); fprintf(out_, "%*s}", indent_, "");
} }
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_table_index_expr_node(TableIndexExprNode *n) { StatusTuple Printer::visit_table_index_expr_node(TableIndexExprNode *n) {
fprintf(out_, "%s[", n->id_->c_str()); fprintf(out_, "%s[", n->id_->c_str());
TRY2(n->index_->accept(this)); TRY2(n->index_->accept(this));
fprintf(out_, "]"); fprintf(out_, "]");
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_expr_stmt_node(ExprStmtNode* n) { StatusTuple Printer::visit_expr_stmt_node(ExprStmtNode* n) {
TRY2(n->expr_->accept(this)); TRY2(n->expr_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_struct_variable_decl_stmt_node(StructVariableDeclStmtNode* n) { StatusTuple Printer::visit_struct_variable_decl_stmt_node(StructVariableDeclStmtNode* n) {
...@@ -207,7 +207,7 @@ StatusTuple Printer::visit_struct_variable_decl_stmt_node(StructVariableDeclStmt ...@@ -207,7 +207,7 @@ StatusTuple Printer::visit_struct_variable_decl_stmt_node(StructVariableDeclStmt
} }
fprintf(out_, "}"); fprintf(out_, "}");
} }
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_integer_variable_decl_stmt_node(IntegerVariableDeclStmtNode* n) { StatusTuple Printer::visit_integer_variable_decl_stmt_node(IntegerVariableDeclStmtNode* n) {
...@@ -218,7 +218,7 @@ StatusTuple Printer::visit_integer_variable_decl_stmt_node(IntegerVariableDeclSt ...@@ -218,7 +218,7 @@ StatusTuple Printer::visit_integer_variable_decl_stmt_node(IntegerVariableDeclSt
fprintf(out_, "; "); fprintf(out_, "; ");
TRY2(n->init_[0]->accept(this)); TRY2(n->init_[0]->accept(this));
} }
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_struct_decl_stmt_node(StructDeclStmtNode* n) { StatusTuple Printer::visit_struct_decl_stmt_node(StructDeclStmtNode* n) {
...@@ -233,12 +233,12 @@ StatusTuple Printer::visit_struct_decl_stmt_node(StructDeclStmtNode* n) { ...@@ -233,12 +233,12 @@ StatusTuple Printer::visit_struct_decl_stmt_node(StructDeclStmtNode* n) {
} }
--indent_; --indent_;
fprintf(out_, "%*s}", indent_, ""); fprintf(out_, "%*s}", indent_, "");
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_state_decl_stmt_node(StateDeclStmtNode* n) { StatusTuple Printer::visit_state_decl_stmt_node(StateDeclStmtNode* n) {
if (!n->id_) { if (!n->id_) {
return mkstatus(0); return StatusTuple(0);
} }
fprintf(out_, "state "); fprintf(out_, "state ");
TRY2(n->id_->accept(this)); TRY2(n->id_->accept(this));
...@@ -249,11 +249,11 @@ StatusTuple Printer::visit_state_decl_stmt_node(StateDeclStmtNode* n) { ...@@ -249,11 +249,11 @@ StatusTuple Printer::visit_state_decl_stmt_node(StateDeclStmtNode* n) {
// TRY2(n->id2_->accept(this)); // TRY2(n->id2_->accept(this));
//} //}
//TRY2(n->block_->accept(this)); //TRY2(n->block_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_parser_state_stmt_node(ParserStateStmtNode* n) { StatusTuple Printer::visit_parser_state_stmt_node(ParserStateStmtNode* n) {
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_match_decl_stmt_node(MatchDeclStmtNode* n) { StatusTuple Printer::visit_match_decl_stmt_node(MatchDeclStmtNode* n) {
...@@ -268,7 +268,7 @@ StatusTuple Printer::visit_match_decl_stmt_node(MatchDeclStmtNode* n) { ...@@ -268,7 +268,7 @@ StatusTuple Printer::visit_match_decl_stmt_node(MatchDeclStmtNode* n) {
} }
fprintf(out_, ") "); fprintf(out_, ") ");
TRY2(n->block_->accept(this)); TRY2(n->block_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_miss_decl_stmt_node(MissDeclStmtNode* n) { StatusTuple Printer::visit_miss_decl_stmt_node(MissDeclStmtNode* n) {
...@@ -283,7 +283,7 @@ StatusTuple Printer::visit_miss_decl_stmt_node(MissDeclStmtNode* n) { ...@@ -283,7 +283,7 @@ StatusTuple Printer::visit_miss_decl_stmt_node(MissDeclStmtNode* n) {
} }
fprintf(out_, ") "); fprintf(out_, ") ");
TRY2(n->block_->accept(this)); TRY2(n->block_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_failure_decl_stmt_node(FailureDeclStmtNode* n) { StatusTuple Printer::visit_failure_decl_stmt_node(FailureDeclStmtNode* n) {
...@@ -298,7 +298,7 @@ StatusTuple Printer::visit_failure_decl_stmt_node(FailureDeclStmtNode* n) { ...@@ -298,7 +298,7 @@ StatusTuple Printer::visit_failure_decl_stmt_node(FailureDeclStmtNode* n) {
} }
fprintf(out_, ") "); fprintf(out_, ") ");
TRY2(n->block_->accept(this)); TRY2(n->block_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_table_decl_stmt_node(TableDeclStmtNode* n) { StatusTuple Printer::visit_table_decl_stmt_node(TableDeclStmtNode* n) {
...@@ -313,7 +313,7 @@ StatusTuple Printer::visit_table_decl_stmt_node(TableDeclStmtNode* n) { ...@@ -313,7 +313,7 @@ StatusTuple Printer::visit_table_decl_stmt_node(TableDeclStmtNode* n) {
fprintf(out_, "> "); fprintf(out_, "> ");
TRY2(n->id_->accept(this)); TRY2(n->id_->accept(this));
fprintf(out_, "(%zu)", n->size_); fprintf(out_, "(%zu)", n->size_);
return mkstatus(0); return StatusTuple(0);
} }
StatusTuple Printer::visit_func_decl_stmt_node(FuncDeclStmtNode *n) { StatusTuple Printer::visit_func_decl_stmt_node(FuncDeclStmtNode *n) {
...@@ -328,7 +328,7 @@ StatusTuple Printer::visit_func_decl_stmt_node(FuncDeclStmtNode *n) { ...@@ -328,7 +328,7 @@ StatusTuple Printer::visit_func_decl_stmt_node(FuncDeclStmtNode *n) {
} }
fprintf(out_, ") "); fprintf(out_, ") ");
TRY2(n->block_->accept(this)); TRY2(n->block_->accept(this));
return mkstatus(0); return StatusTuple(0);
} }
} // namespace cc } // namespace cc
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment