Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing abi for singleton with non-table type #178

Merged
merged 2 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/toolchain/abigen-pass/singleton_contract_simple.abi
Original file line number Diff line number Diff line change
@@ -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": []
}
16 changes: 16 additions & 0 deletions tests/toolchain/abigen-pass/singleton_contract_simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <eosio/asset.hpp>
#include <eosio/eosio.hpp>
#include <eosio/name.hpp>
#include <eosio/singleton.hpp>

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;
};
10 changes: 10 additions & 0 deletions tests/toolchain/abigen-pass/singleton_contract_simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tests" : [
{
"expected" : {
"abi-file" : "singleton_contract_simple.abi"
}
}
]
}

20 changes: 10 additions & 10 deletions tools/include/eosio/abigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<std::string, std::string>>& clauses ) {
Expand Down Expand Up @@ -802,9 +801,10 @@ namespace eosio { namespace cdt {
}
virtual bool VisitDecl(clang::Decl* decl) {
if (const auto* d = dyn_cast<clang::ClassTemplateSpecializationDecl>(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;
Expand Down