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 20, 2019
1 parent 0d93b29 commit f8865e2
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2863,6 +2863,13 @@ class TypeDecl : public NamedDecl {
static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
};

struct EosioOrder {
std::string field;
std::string order;
};

using EosioOrders = SmallVector<EosioOrder, 2>;

/// Base class for declarations which introduce a typedef-name.
class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
struct LLVM_ALIGNAS(8) ModedTInfo {
Expand Down Expand Up @@ -2960,6 +2967,14 @@ class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
return K >= firstTypedefName && K <= lastTypedefName;
}

bool hasEosioOrders() const;
EosioOrders getEosioOrders() const;
bool hasEosioNonUnique() const;

bool hasEosioTable() const;
std::string getEosioTable() const;
bool hasEosioScopeType() const;
std::string getEosioScopeType() const;
private:
bool isTransparentTagSlow() const;
};
Expand Down
23 changes: 23 additions & 0 deletions include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,21 @@ def EosioAction : InheritableAttr {
let Documentation = [EosioActionDocs];
}

def EosioOrder : InheritableAttr {
let Spellings = [CXX11<"eosio", "order">, GNU<"eosio_order">];
let Args = [StringArgument<"Field">, StringArgument<"Order", 1>];
let Subjects = SubjectList<[TypedefName]>;
let MeaningfulToClassTemplateDefinition = 1;
let Documentation = [EosioOrderDocs];
}

def EosioNonUnique : InheritableAttr {
let Spellings = [CXX11<"eosio", "non_unique">, GNU<"eosio_non_unique">];
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>];
Expand All @@ -1005,6 +1020,14 @@ def EosioTable : InheritableAttr {
let Documentation = [EosioTableDocs];
}

def EosioScopeType : InheritableAttr {
let Spellings = [CXX11<"eosio", "scope_type">, GNU<"eosio_scope_type">];
let Args = [StringArgument<"type">];
let Subjects = SubjectList<[TypedefName]>;
let MeaningfulToClassTemplateDefinition = 1;
let Documentation = [EosioScopeTypeDocs];
}

def EosioEvent : InheritableAttr {
let Spellings = [CXX11<"eosio", "event">, GNU<"eosio_event">];
let Args = [StringArgument<"name", 1>];
Expand Down
21 changes: 21 additions & 0 deletions include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -887,13 +887,34 @@ The ``eosio::action`` attribute marks a method as being an eosio action.
}];
}

def EosioOrderDocs : Documentation {
let Category = DocCatType;
let Content = [{
The ``eosio::order`` attribute adds an order to index of eosio table.
}];
}

def EosioNonUniqueDocs : Documentation {
let Category = DocCatType;
let Content = [{
The ``eosio::non_unique`` marks index of eosio table as non-unique.
}];
}

def EosioTableDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
The ``eosio::table`` attribute marks a record as being an eosio table.
}];
}

def EosioScopeTypeDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
The ``eosio::scope_type`` set custom scope type of eosio table.
}];
}

def EosioEventDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
Expand Down
25 changes: 25 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4425,6 +4425,31 @@ TagDecl *TypedefNameDecl::getAnonDeclWithTypedefName(bool AnyRedecl) const {
return nullptr;
}

bool TypedefNameDecl::hasEosioOrders()const { return hasAttr<EosioOrderAttr>(); }
EosioOrders TypedefNameDecl::getEosioOrders()const {
EosioOrders ret;
for (auto* attr: getAttrs()) {
if (auto order = dyn_cast<EosioOrderAttr>(attr)) {
EosioOrder ord;
ord.field = order->getField();
ord.order = order->getOrder();
ret.push_back(ord);
}
}
return ret;
}

bool TypedefNameDecl::hasEosioNonUnique()const { return hasAttr<EosioNonUniqueAttr>(); }

bool TypedefNameDecl::hasEosioTable()const { return hasAttr<EosioTableAttr>(); }
std::string TypedefNameDecl::getEosioTable()const {
return getAttr<EosioTableAttr>()->getName();
}
bool TypedefNameDecl::hasEosioScopeType()const { return hasAttr<EosioScopeTypeAttr>(); }
std::string TypedefNameDecl::getEosioScopeType()const {
return getAttr<EosioScopeTypeAttr>()->getType();
}

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

static void handleEosioOrderAttribute(Sema &S, Decl *D, const AttributeList &AL) {
StringRef Field, Order = "asc";
S.checkStringLiteralArgumentAttr(AL, 0, Field);

if (AL.getNumArgs() >= 2)
S.checkStringLiteralArgumentAttr(AL, 1, Order);

D->addAttr(::new (S.Context)
EosioOrderAttr(AL.getRange(), S.Context, Field, Order,
AL.getAttributeSpellingListIndex()));
}

static void handleEosioNonUniqueAttribute(Sema &S, Decl *D, const AttributeList &AL) {
D->addAttr(::new (S.Context)
EosioNonUniqueAttr(AL.getRange(), S.Context,
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 All @@ -481,6 +499,15 @@ static void handleEosioTableAttribute(Sema &S, Decl *D, const AttributeList &AL)
AL.getAttributeSpellingListIndex()));
}

static void handleEosioScopeTypeAttribute(Sema &S, Decl *D, const AttributeList &AL) {
StringRef Str;
S.checkStringLiteralArgumentAttr(AL, 0, Str);

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

static void handleEosioEventAttribute(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,9 +5967,18 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
case AttributeList::AT_EosioAction:
handleEosioActionAttribute(S, D, AL);
break;
case AttributeList::AT_EosioOrder:
handleEosioOrderAttribute(S, D, AL);
break;
case AttributeList::AT_EosioNonUnique:
handleEosioNonUniqueAttribute(S, D, AL);
break;
case AttributeList::AT_EosioTable:
handleEosioTableAttribute(S, D, AL);
break;
case AttributeList::AT_EosioScopeType:
handleEosioScopeTypeAttribute(S, D, AL);
break;
case AttributeList::AT_EosioEvent:
handleEosioEventAttribute(S, D, AL);
break;
Expand Down

0 comments on commit f8865e2

Please sign in to comment.