From 68980f4793df4105ea8c89981502cbef3b1b0e8f Mon Sep 17 00:00:00 2001 From: Mihaela Chirea Date: Fri, 18 Sep 2020 19:55:57 +0300 Subject: [PATCH 1/2] Moved getAttributes from UserAttributeDeclaration to expressionsem.d --- src/dmd/attrib.d | 16 ---------------- src/dmd/attrib.h | 3 ++- src/dmd/expressionsem.d | 15 +++++++++++++++ src/dmd/frontend.h | 3 ++- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/dmd/attrib.d b/src/dmd/attrib.d index d4f1f7d9965b..2ab3f9884953 100644 --- a/src/dmd/attrib.d +++ b/src/dmd/attrib.d @@ -33,7 +33,6 @@ import dmd.dscope; import dmd.dsymbol; import dmd.dsymbolsem : dsymbolSemantic; import dmd.expression; -import dmd.expressionsem : arrayExpressionSemantic; import dmd.func; import dmd.globals; import dmd.hdrgen : protectionToBuffer; @@ -1407,21 +1406,6 @@ extern (C++) final class UserAttributeDeclaration : AttribDeclaration return udas; } - Expressions* getAttributes() - { - if (auto sc = _scope) - { - _scope = null; - arrayExpressionSemantic(atts, sc); - } - auto exps = new Expressions(); - if (userAttribDecl && userAttribDecl !is this) - exps.push(new TupleExp(Loc.initial, userAttribDecl.getAttributes())); - if (atts && atts.dim) - exps.push(new TupleExp(Loc.initial, atts)); - return exps; - } - override const(char)* kind() const { return "UserAttribute"; diff --git a/src/dmd/attrib.h b/src/dmd/attrib.h index 2795db270b1e..25cb8cc92fa2 100644 --- a/src/dmd/attrib.h +++ b/src/dmd/attrib.h @@ -248,7 +248,8 @@ class UserAttributeDeclaration : public AttribDeclaration Dsymbol *syntaxCopy(Dsymbol *s); Scope *newScope(Scope *sc); void setScope(Scope *sc); - Expressions *getAttributes(); const char *kind() const; void accept(Visitor *v) { v->visit(this); } }; + +Expressions *getAttributes(UserAttributeDeclaration *uad); diff --git a/src/dmd/expressionsem.d b/src/dmd/expressionsem.d index e10c08bfc490..81b4c2a77014 100644 --- a/src/dmd/expressionsem.d +++ b/src/dmd/expressionsem.d @@ -12337,6 +12337,21 @@ bool checkAddressVar(Scope* sc, Expression exp, VarDeclaration v) return true; } +extern (C++) Expressions* getAttributes(UserAttributeDeclaration uad) +{ + if (auto sc = uad._scope) + { + uad._scope = null; + arrayExpressionSemantic(uad.atts, sc); + } + auto exps = new Expressions(); + if (uad.userAttribDecl && uad.userAttribDecl !is uad) + exps.push(new TupleExp(Loc.initial, uad.userAttribDecl.getAttributes())); + if (uad.atts && uad.atts.dim) + exps.push(new TupleExp(Loc.initial, uad.atts)); + return exps; +} + /******************************* * Checks the attributes of a function. * Purity (`pure`), safety (`@safe`), no GC allocations(`@nogc`) diff --git a/src/dmd/frontend.h b/src/dmd/frontend.h index 142af85b03cb..6b9e8c7888ce 100644 --- a/src/dmd/frontend.h +++ b/src/dmd/frontend.h @@ -2119,7 +2119,6 @@ class UserAttributeDeclaration : public AttribDeclaration Dsymbol* syntaxCopy(Dsymbol* s); Scope* newScope(Scope* sc); void setScope(Scope* sc); - Array* getAttributes(); const char* kind() const; void accept(Visitor* v); static bool isGNUABITag(Expression* e); @@ -4615,6 +4614,8 @@ extern Expression* resolveProperties(Scope* sc, Expression* e); extern Expression* expressionSemantic(Expression* e, Scope* sc); +extern Array* getAttributes(UserAttributeDeclaration* uad); + enum class ILS { uninitialized = 0, From 59f8f79344a96cc5174969e616bd7b4f0d480932 Mon Sep 17 00:00:00 2001 From: Mihaela Chirea Date: Sun, 27 Sep 2020 21:12:36 +0300 Subject: [PATCH 2/2] Added getAttributes test --- src/tests/cxxfrontend.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/tests/cxxfrontend.c b/src/tests/cxxfrontend.c index b9bad0dc9bee..a4aba321099e 100644 --- a/src/tests/cxxfrontend.c +++ b/src/tests/cxxfrontend.c @@ -463,6 +463,16 @@ void test_outbuffer() /**********************************/ +void test_attributes() +{ + UserAttributeDeclaration *uad = (UserAttributeDeclaration*)Dsymbol::create(NULL); + assert(uad); + Expressions *e = getAttributes(uad); + assert(e); +} + +/**********************************/ + int main(int argc, char **argv) { frontend_init(); @@ -479,6 +489,7 @@ int main(int argc, char **argv) test_location(); test_array(); test_outbuffer(); + test_attributes(); frontend_term();