Skip to content

Commit

Permalink
Multiple contracts in eosio::contract, and support for typedefs #5
Browse files Browse the repository at this point in the history
  • Loading branch information
soft-bagel-93 committed Dec 27, 2019
1 parent f8865e2 commit 23ee920
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <cstdint>
#include <string>
#include <utility>
#include <set>

namespace clang {

Expand Down Expand Up @@ -2975,6 +2976,9 @@ class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
std::string getEosioTable() const;
bool hasEosioScopeType() const;
std::string getEosioScopeType() const;

bool isEosioContract() const;
std::set<std::string> getEosioContracts() const;
private:
bool isTransparentTagSlow() const;
};
Expand Down
4 changes: 2 additions & 2 deletions include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,8 @@ def EosioRicardian : InheritableAttr {

def EosioContract : InheritableAttr {
let Spellings = [CXX11<"eosio", "contract">, GNU<"eosio_contract">];
let Args = [StringArgument<"name", 1>];
let Subjects = SubjectList<[CXXRecord, CXXMethod]>;
let Args = [VariadicStringArgument<"names">];
let Subjects = SubjectList<[CXXRecord, CXXMethod, TypedefName]>;
let Documentation = [EosioContractDocs];
}

Expand Down
6 changes: 6 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4450,6 +4450,12 @@ std::string TypedefNameDecl::getEosioScopeType()const {
return getAttr<EosioScopeTypeAttr>()->getType();
}

bool TypedefNameDecl::isEosioContract()const { return hasAttr<EosioContractAttr>(); }
std::set<std::string> TypedefNameDecl::getEosioContracts()const {
const auto& names = getAttr<EosioContractAttr>()->names();
return std::set<std::string>(names.begin(), names.end());
}

bool TypedefNameDecl::isTransparentTagSlow() const {
auto determineIsTransparent = [&]() {
if (auto *TT = getUnderlyingType()->getAs<TagType>()) {
Expand Down
15 changes: 9 additions & 6 deletions lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,16 @@ static void handleEosioNotifyAttribute(Sema &S, Decl *D, const AttributeList &AL
}

static void handleEosioContractAttribute(Sema &S, Decl *D, const AttributeList &AL) {
// Handle the cases where the attribute has a text message.
StringRef Str, Replacement;
if (AL.isArgExpr(0) && AL.getArgAsExpr(0) &&
!S.checkStringLiteralArgumentAttr(AL, 0, Str))
return;
SmallVector<StringRef, 2> names;
for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
StringRef name;
if (!S.checkStringLiteralArgumentAttr(AL, I, name))
return;
names.push_back(name);
}

D->addAttr(::new (S.Context)
EosioContractAttr(AL.getRange(), S.Context, Str,
EosioContractAttr(AL.getRange(), S.Context, names.data(), names.size(),
AL.getAttributeSpellingListIndex()));
}

Expand Down

0 comments on commit 23ee920

Please sign in to comment.