From aeda79aa931b7c99cc94dbee1cb1992c9502f0bf Mon Sep 17 00:00:00 2001 From: Venu Kailasa Date: Mon, 29 Mar 2021 15:13:32 -0500 Subject: [PATCH] Adding eosio structure attribute --- include/clang/AST/DeclCXX.h | 2 ++ include/clang/Basic/Attr.td | 8 ++++++++ include/clang/Basic/AttrDocs.td | 9 ++++++++- lib/Sema/SemaDeclAttr.cpp | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index e6abf8fd233f..0d9be10f9df6 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -730,10 +730,12 @@ class CXXRecordDecl : public RecordDecl { bool isEosioContract() const { return hasAttr(); } bool isEosioAction() const { return hasAttr(); } bool isEosioTable() const { return hasAttr(); } + bool isEosioStructure() const { return hasAttr(); } bool isEosioIgnore() const { return hasAttr(); } bool hasEosioRicardian() const { return hasAttr(); } EosioActionAttr* getEosioActionAttr() const { return getAttr(); } EosioTableAttr* getEosioTableAttr() const { return getAttr(); } + EosioStructureAttr* getEosioStructureAttr() const { return getAttr(); } EosioContractAttr* getEosioContractAttr() const { return getAttr(); } EosioRicardianAttr* getEosioRicardianAttr() const { return getAttr(); } diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index 7ff6e35f3c07..feec31b7a32b 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -1104,6 +1104,14 @@ def EosioTable : InheritableAttr { let Documentation = [EosioTableDocs]; } +def EosioStructure : InheritableAttr { + let Spellings = [CXX11<"eosio", "structure">, GNU<"eosio_structure">]; + let Args = [StringArgument<"name", 1>]; + let Subjects = SubjectList<[CXXRecord]>; + let MeaningfulToClassTemplateDefinition = 1; + let Documentation = [EosioStructureDocs]; +} + def CXX11NoReturn : InheritableAttr { let Spellings = [CXX11<"", "noreturn", 200809>]; let Subjects = SubjectList<[Function], ErrorDiag>; diff --git a/include/clang/Basic/AttrDocs.td b/include/clang/Basic/AttrDocs.td index c08addbe2714..dd1731e232b0 100644 --- a/include/clang/Basic/AttrDocs.td +++ b/include/clang/Basic/AttrDocs.td @@ -1043,6 +1043,13 @@ The ``eosio::table`` attribute marks a record as being an eosio table. }]; } +def EosioStructureDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``eosio::structure`` attribute marks a struct as being an eosio structure. + }]; +} + def NoSplitStackDocs : Documentation { let Category = DocCatFunction; let Content = [{ @@ -4237,4 +4244,4 @@ be accessed on both device side and host side. It has external linkage and is not initialized on device side. It has internal linkage and is initialized by the initializer on host side. }]; -} \ No newline at end of file +} diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 858752986617..e1ad27c4cebb 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -489,6 +489,18 @@ static void handleEosioTableAttribute(Sema &S, Decl *D, const ParsedAttr &AL) { AL.getAttributeSpellingListIndex())); } +static void handleEosioStructureAttribute(Sema &S, Decl *D, const ParsedAttr &AL) { + // Handle the cases where the attribute has a text message. + StringRef Str; + if (AL.isArgExpr(0) && AL.getArgAsExpr(0) && + !S.checkStringLiteralArgumentAttr(AL, 0, Str)) + return; + + D->addAttr(::new (S.Context) + EosioStructureAttr(AL.getRange(), S.Context, Str, + AL.getAttributeSpellingListIndex())); +} + /// Applies the given attribute to the Decl without performing any /// additional semantic checking. template @@ -6746,6 +6758,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, case ParsedAttr::AT_EosioTable: handleEosioTableAttribute(S, D, AL); break; + case ParsedAttr::AT_EosioStructure: + handleEosioStructureAttribute(S, D, AL); + break; case ParsedAttr::AT_EosioWasmABI: handleEosioABIAttribute(S, D, AL); break;