Skip to content

Commit

Permalink
Add Cyberway tables support #3
Browse files Browse the repository at this point in the history
  • Loading branch information
soft-bagel-93 committed Dec 17, 2019
1 parent 0d93b29 commit a081b8b
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/Visibility.h"
#include "clang/Basic/EosioAttrs.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
Expand Down Expand Up @@ -2960,6 +2961,10 @@ class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
return K >= firstTypedefName && K <= lastTypedefName;
}

bool hasEosioIndex() const;
EosioIndex getEosioIndex() const;
bool hasEosioTable() const;
EosioTable getEosioTable() const;
private:
bool isTransparentTagSlow() const;
};
Expand Down
20 changes: 18 additions & 2 deletions include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -997,10 +997,26 @@ def EosioAction : InheritableAttr {
let Documentation = [EosioActionDocs];
}

def EosioUnique : InheritableAttr {
let Spellings = [CXX11<"eosio", "unique">, GNU<"eosio_unique">];
let Args = [StringArgument<"Orders", 1>];
let Subjects = SubjectList<[TypedefName]>;
let MeaningfulToClassTemplateDefinition = 1;
let Documentation = [EosioUniqueDocs];
}

def EosioNonUnique : InheritableAttr {
let Spellings = [CXX11<"eosio", "non_unique">, GNU<"eosio_non_unique">];
let Args = [StringArgument<"Orders", 1>];
let Subjects = SubjectList<[TypedefName]>;
let MeaningfulToClassTemplateDefinition = 1;
let Documentation = [EosioNonUniqueDocs];
}

def EosioTable : InheritableAttr {
let Spellings = [CXX11<"eosio", "table">, GNU<"eosio_table">];
let Args = [StringArgument<"name", 1>];
let Subjects = SubjectList<[CXXRecord]>;
let Args = [StringArgument<"name", 1>]; // Cyberway: name is scope_type
let Subjects = SubjectList<[CXXRecord, TypedefName]>;
let MeaningfulToClassTemplateDefinition = 1;
let Documentation = [EosioTableDocs];
}
Expand Down
14 changes: 14 additions & 0 deletions include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,20 @@ The ``eosio::action`` attribute marks a method as being an eosio action.
}];
}

def EosioUniqueDocs : Documentation {
let Category = DocCatType;
let Content = [{
The ``eosio::unique`` attribute marks a type definition as being an unique index in eosio table.
}];
}

def EosioNonUniqueDocs : Documentation {
let Category = DocCatType;
let Content = [{
The ``eosio::non_unique`` attribute marks a type definition as being an non-unique index in eosio table.
}];
}

def EosioTableDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
Expand Down
17 changes: 17 additions & 0 deletions include/clang/Basic/EosioAttrs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef LLVM_CLANG_BASIC_EOSIO_ATTRS_H
#define LLVM_CLANG_BASIC_EOSIO_ATTRS_H

namespace clang {

struct EosioIndex {
bool unique;
std::string orders;
};

struct EosioTable {
std::string scope_type;
};

}

#endif // LLVM_CLANG_BASIC_EOSIO_ATTRS_H
21 changes: 21 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4425,6 +4425,27 @@ TagDecl *TypedefNameDecl::getAnonDeclWithTypedefName(bool AnyRedecl) const {
return nullptr;
}

bool TypedefNameDecl::hasEosioIndex()const { return hasAttr<EosioUniqueAttr>() || hasAttr<EosioNonUniqueAttr>(); }
EosioIndex TypedefNameDecl::getEosioIndex()const {
EosioIndex ret;
const auto* idx = getAttr<EosioUniqueAttr>();
ret.unique = (idx != nullptr);
if (idx) {
ret.orders = idx->getOrders();
} else {
ret.orders = getAttr<EosioNonUniqueAttr>()->getOrders();
}
return ret;
}

bool TypedefNameDecl::hasEosioTable()const { return hasAttr<EosioTableAttr>(); }
EosioTable TypedefNameDecl::getEosioTable()const {
EosioTable ret;
const auto* idx = getAttr<EosioTableAttr>();
ret.scope_type = idx->getName();
return ret;
}

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

static void handleEosioUniqueAttribute(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;

D->addAttr(::new (S.Context)
EosioUniqueAttr(AL.getRange(), S.Context, Str,
AL.getAttributeSpellingListIndex()));
}

static void handleEosioNonUniqueAttribute(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;

D->addAttr(::new (S.Context)
EosioNonUniqueAttr(AL.getRange(), S.Context, Str,
AL.getAttributeSpellingListIndex()));
}

static void handleEosioTableAttribute(Sema &S, Decl *D, const AttributeList &AL) {
// Handle the cases where the attribute has a text message.
StringRef Str, Replacement;
Expand Down Expand Up @@ -5940,6 +5964,12 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
case AttributeList::AT_EosioAction:
handleEosioActionAttribute(S, D, AL);
break;
case AttributeList::AT_EosioUnique:
handleEosioUniqueAttribute(S, D, AL);
break;
case AttributeList::AT_EosioNonUnique:
handleEosioNonUniqueAttribute(S, D, AL);
break;
case AttributeList::AT_EosioTable:
handleEosioTableAttribute(S, D, AL);
break;
Expand Down

0 comments on commit a081b8b

Please sign in to comment.