diff --git a/tests/toolchain/abigen-pass/singleton_contract_simple.abi b/tests/toolchain/abigen-pass/singleton_contract_simple.abi new file mode 100644 index 0000000000..8600eb2f76 --- /dev/null +++ b/tests/toolchain/abigen-pass/singleton_contract_simple.abi @@ -0,0 +1,31 @@ +{ + "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", + "version": "eosio::abi/1.2", + "types": [], + "structs": [ + { + "name": "whatever", + "base": "", + "fields": [] + } + ], + "actions": [ + { + "name": "whatever", + "type": "whatever", + "ricardian_contract": "" + } + ], + "tables": [ + { + "name": "smpl.config", + "type": "name", + "index_type": "i64", + "key_names": [], + "key_types": [] + } + ], + "ricardian_clauses": [], + "variants": [], + "action_results": [] +} diff --git a/tests/toolchain/abigen-pass/singleton_contract_simple.cpp b/tests/toolchain/abigen-pass/singleton_contract_simple.cpp new file mode 100644 index 0000000000..2afdc7c332 --- /dev/null +++ b/tests/toolchain/abigen-pass/singleton_contract_simple.cpp @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +using namespace eosio; + +class [[eosio::contract("singleton_contract_simple")]] singleton_contract_simple : public contract { + public: + using contract::contract; + + [[eosio::action]] + void whatever() {}; + + typedef eosio::singleton<"smpl.config"_n, name> config; +}; diff --git a/tests/toolchain/abigen-pass/singleton_contract_simple.json b/tests/toolchain/abigen-pass/singleton_contract_simple.json new file mode 100644 index 0000000000..0bf81acc1e --- /dev/null +++ b/tests/toolchain/abigen-pass/singleton_contract_simple.json @@ -0,0 +1,10 @@ +{ + "tests" : [ + { + "expected" : { + "abi-file" : "singleton_contract_simple.abi" + } + } + ] + } + \ No newline at end of file diff --git a/tools/include/eosio/abigen.hpp b/tools/include/eosio/abigen.hpp index 728c8f955f..479c9fec73 100644 --- a/tools/include/eosio/abigen.hpp +++ b/tools/include/eosio/abigen.hpp @@ -243,14 +243,13 @@ namespace eosio { namespace cdt { ctables.insert(t); } - void add_table( uint64_t name, const clang::CXXRecordDecl* decl ) { - if (!(decl->isEosioTable() && abigen::is_eosio_contract(decl, get_contract_name()))) - return; - - abi_table t; - t.type = decl->getNameAsString(); - t.name = name_to_string(name); - _abi.tables.insert(t); + void add_table( uint64_t name, const clang::CXXRecordDecl* decl, bool force=false ) { + if (force || decl->isEosioTable() && abigen::is_eosio_contract(decl, get_contract_name())) { + abi_table t; + t.type = decl->getNameAsString(); + t.name = name_to_string(name); + _abi.tables.insert(t); + } } void add_clauses( const std::vector>& clauses ) { @@ -802,9 +801,10 @@ namespace eosio { namespace cdt { } virtual bool VisitDecl(clang::Decl* decl) { if (const auto* d = dyn_cast(decl)) { - if (d->getName() == "multi_index" || d->getName() == "singleton") { + bool is_singleton = d->getName() == "singleton"; + if (d->getName() == "multi_index" || is_singleton) { ag.add_table(d->getTemplateArgs()[0].getAsIntegral().getExtValue(), - (clang::CXXRecordDecl*)((clang::RecordType*)d->getTemplateArgs()[1].getAsType().getTypePtr())->getDecl()); + d->getTemplateArgs()[1].getAsType().getTypePtr()->getAsCXXRecordDecl(), is_singleton); } } return true;