From f32275b6b02e936409c7b4442db3a7a9331dfd66 Mon Sep 17 00:00:00 2001 From: Michal Lesiak Date: Wed, 5 Apr 2023 12:17:20 +0200 Subject: [PATCH] Fix getting wrong name of the table for singleton --- .../abigen-pass/singleton_contract.abi | 45 +++++++++++++++++++ .../abigen-pass/singleton_contract.cpp | 21 +++++++++ .../abigen-pass/singleton_contract.json | 10 +++++ tools/include/eosio/abigen.hpp | 2 +- 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 tests/toolchain/abigen-pass/singleton_contract.abi create mode 100644 tests/toolchain/abigen-pass/singleton_contract.cpp create mode 100644 tests/toolchain/abigen-pass/singleton_contract.json diff --git a/tests/toolchain/abigen-pass/singleton_contract.abi b/tests/toolchain/abigen-pass/singleton_contract.abi new file mode 100644 index 0000000000..4c6e9853a5 --- /dev/null +++ b/tests/toolchain/abigen-pass/singleton_contract.abi @@ -0,0 +1,45 @@ +{ + "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", + "version": "eosio::abi/1.2", + "types": [], + "structs": [ + { + "name": "tbl_config", + "base": "", + "fields": [ + { + "name": "y", + "type": "uint64" + }, + { + "name": "x", + "type": "uint64" + } + ] + }, + { + "name": "whatever", + "base": "", + "fields": [] + } + ], + "actions": [ + { + "name": "whatever", + "type": "whatever", + "ricardian_contract": "" + } + ], + "tables": [ + { + "name": "config", + "type": "tbl_config", + "index_type": "i64", + "key_names": [], + "key_types": [] + } + ], + "ricardian_clauses": [], + "variants": [], + "action_results": [] +} \ No newline at end of file diff --git a/tests/toolchain/abigen-pass/singleton_contract.cpp b/tests/toolchain/abigen-pass/singleton_contract.cpp new file mode 100644 index 0000000000..89831854c9 --- /dev/null +++ b/tests/toolchain/abigen-pass/singleton_contract.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +#include + +using namespace eosio; + +class [[eosio::contract("singleton_contract")]] singleton_contract : public contract { + public: + using contract::contract; + + [[eosio::action]] + void whatever() {}; + + struct [[eosio::table]] tbl_config { + uint64_t y; + uint64_t x; + }; + + typedef eosio::singleton<"config"_n, tbl_config> config; +}; diff --git a/tests/toolchain/abigen-pass/singleton_contract.json b/tests/toolchain/abigen-pass/singleton_contract.json new file mode 100644 index 0000000000..0374b1fd41 --- /dev/null +++ b/tests/toolchain/abigen-pass/singleton_contract.json @@ -0,0 +1,10 @@ +{ + "tests" : [ + { + "expected" : { + "abi-file" : "singleton_contract.abi" + } + } + ] + } + \ No newline at end of file diff --git a/tools/include/eosio/abigen.hpp b/tools/include/eosio/abigen.hpp index cf44e35c26..728c8f955f 100644 --- a/tools/include/eosio/abigen.hpp +++ b/tools/include/eosio/abigen.hpp @@ -802,7 +802,7 @@ namespace eosio { namespace cdt { } virtual bool VisitDecl(clang::Decl* decl) { if (const auto* d = dyn_cast(decl)) { - if (d->getName() == "multi_index") { + if (d->getName() == "multi_index" || d->getName() == "singleton") { ag.add_table(d->getTemplateArgs()[0].getAsIntegral().getExtValue(), (clang::CXXRecordDecl*)((clang::RecordType*)d->getTemplateArgs()[1].getAsType().getTypePtr())->getDecl()); }