@@ -33,55 +33,66 @@ import dmd.expressionsem;
3333import dmd.location;
3434import dmd.root.array; // for each
3535
36-
36+ /**
37+ * Retrieves the attributes associated with a UserAttributeDeclaration.
38+ * Returns:
39+ * A pointer to Expressions containing the attributes, or null if none exist.
40+ */
3741Expressions* getAttributes (UserAttributeDeclaration a)
3842{
43+ if (! a.userAttribDecl && (! a.atts || ! a.atts.length))
44+ return null ;
45+
3946 if (auto sc = a._scope)
4047 {
4148 a._scope = null ;
42- arrayExpressionSemantic(a.atts.peekSlice(), sc);
49+ if (a.atts)
50+ arrayExpressionSemantic(a.atts.peekSlice(), sc);
4351 }
52+
4453 auto exps = new Expressions();
54+
4555 if (a.userAttribDecl && a.userAttribDecl ! is a)
46- exps.push(new TupleExp (Loc.initial, a.userAttribDecl.getAttributes()));
56+ {
57+ if (auto parentAtts = a.userAttribDecl.getAttributes())
58+ exps.push(new TupleExp (Loc.initial, parentAtts));
59+ }
60+
4761 if (a.atts && a.atts.length)
4862 exps.push(new TupleExp (Loc.initial, a.atts));
63+
4964 return exps;
5065}
5166
5267/**
5368 * Iterates the UDAs attached to the given symbol.
5469 *
5570 * Params:
56- * sym = the symbol to get the UDAs from
57- * sc = scope to use for semantic analysis of UDAs
58- * dg = called once for each UDA
71+ * sym = the symbol to get the UDAs from
72+ * sc = scope to use for semantic analysis of UDAs
73+ * dg = called once for each UDA
5974 *
6075 * Returns:
61- * If `dg` returns `!= 0`, stops the iteration and returns that value.
62- * Otherwise, returns 0.
76+ * If `dg` returns `!= 0`, stops the iteration and returns that value.
77+ * Otherwise, returns 0.
6378 */
6479int foreachUda (Dsymbol sym, Scope* sc, int delegate (Expression) dg)
6580{
6681 if (! sym.userAttribDecl)
6782 return 0 ;
6883
6984 auto udas = sym.userAttribDecl.getAttributes();
85+ if (! udas)
86+ return 0 ;
87+
7088 arrayExpressionSemantic(udas.peekSlice(), sc, true );
7189
7290 return udas.each! ((uda) {
73- if (! uda.isTupleExp())
74- return 0 ;
75-
76- auto exps = uda.isTupleExp().exps;
77-
78- return exps.each! ((e) {
79- assert (e);
80-
81- if (auto result = dg(e))
82- return result;
91+ if (! uda) return 0 ;
8392
84- return 0 ;
85- });
93+ if (auto te = uda.isTupleExp())
94+ return te.exps.each! ((e) => dg(e));
95+ else
96+ return dg (uda);
8697 });
8798}
0 commit comments