Skip to content

Commit

Permalink
Merge pull request #125 from AntelopeIO/mikelik/singleton_fix
Browse files Browse the repository at this point in the history
Fix getting wrong name of the table for singleton
  • Loading branch information
mikelik authored Apr 6, 2023
2 parents 369119d + f32275b commit 84a514f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
45 changes: 45 additions & 0 deletions tests/toolchain/abigen-pass/singleton_contract.abi
Original file line number Diff line number Diff line change
@@ -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": []
}
21 changes: 21 additions & 0 deletions tests/toolchain/abigen-pass/singleton_contract.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <eosio/asset.hpp>
#include <eosio/eosio.hpp>
#include <eosio/name.hpp>
#include <eosio/singleton.hpp>

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

2 changes: 1 addition & 1 deletion tools/include/eosio/abigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ namespace eosio { namespace cdt {
}
virtual bool VisitDecl(clang::Decl* decl) {
if (const auto* d = dyn_cast<clang::ClassTemplateSpecializationDecl>(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());
}
Expand Down

0 comments on commit 84a514f

Please sign in to comment.