Mercurial > projects > ldc
view dmd/attrib.h @ 1117:4c20fcc4252b
Fun with parameter attributes: For several of the "synthetic" parameters added
to D functions, we can apply noalias and nocapture. They are sret parameters,
'nest' pointers passed to nested functions, and _argptr:
Nocapture:
- Sret and nest are nocapture because they don't represent D-level variables,
and thus the callee can't (validly) obtain a pointer to them, let alone keep
it around after it returns.
- _argptr is nocapture because although the callee has access to it as a
pointer, that pointer is invalidated when it returns.
All three are noalias because they're function-local variables
- Sret and _argptr are noalias because they're freshly alloca'd memory only
used for a single function call that's not allowed to keep an aliasing
pointer to it around (since the parameter is nocapture).
- 'Nest' is noalias because the callee only ever has access to one such pointer
per parent function, and every parent function has a different one.
This commit also ensures attributes set on sret, _arguments and _argptr are
propagated to calls to such functions.
It also adds one exception to the general rule that attributes on function types
should propagate to calls: the type of a delegate's function pointer has a
'nest' parameter, but this can either be a true 'nest' (for delegates to nested
functions) or a 'this' (for delegates to member functions). Since 'this' is
neither noalias nor nocapture, and there's generally no way to tell which one it
is, we remove these attributes at the call site if the callee is a delegate.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sat, 14 Mar 2009 22:15:31 +0100 |
parents | 340acf1535d0 |
children | dbe4af57b240 |
line wrap: on
line source
// Compiler implementation of the D programming language // Copyright (c) 1999-2007 by Digital Mars // All Rights Reserved // written by Walter Bright // http://www.digitalmars.com // License for redistribution is by either the Artistic License // in artistic.txt, or the GNU General Public License in gnu.txt. // See the included readme.txt for details. #ifndef DMD_ATTRIB_H #define DMD_ATTRIB_H #ifdef __DMC__ #pragma once #endif /* __DMC__ */ #include "dsymbol.h" struct Expression; struct Statement; struct LabelDsymbol; struct Initializer; struct Module; struct Condition; #ifdef _DH struct HdrGenState; #endif /**************************************************************/ struct AttribDeclaration : Dsymbol { Array *decl; // array of Dsymbol's AttribDeclaration(Array *decl); virtual Array *include(Scope *sc, ScopeDsymbol *s); int addMember(Scope *sc, ScopeDsymbol *s, int memnum); void semantic(Scope *sc); void semantic2(Scope *sc); void semantic3(Scope *sc); void inlineScan(); void addComment(unsigned char *comment); void emitComment(Scope *sc); const char *kind(); int oneMember(Dsymbol **ps); int hasPointers(); void checkCtorConstInit(); void addLocalClass(ClassDeclarations *); void toCBuffer(OutBuffer *buf, HdrGenState *hgs); AttribDeclaration *isAttribDeclaration() { return this; } virtual void toObjFile(int multiobj); // compile to .obj file int cvMember(unsigned char *p); }; struct StorageClassDeclaration: AttribDeclaration { unsigned stc; StorageClassDeclaration(unsigned stc, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct LinkDeclaration : AttribDeclaration { enum LINK linkage; LinkDeclaration(enum LINK p, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void semantic3(Scope *sc); void toCBuffer(OutBuffer *buf, HdrGenState *hgs); char *toChars(); }; struct ProtDeclaration : AttribDeclaration { enum PROT protection; ProtDeclaration(enum PROT p, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct AlignDeclaration : AttribDeclaration { unsigned salign; AlignDeclaration(Loc loc, unsigned sa, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct AnonDeclaration : AttribDeclaration { int isunion; Scope *scope; // !=NULL means context to use int sem; // 1 if successful semantic() AnonDeclaration(Loc loc, int isunion, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf, HdrGenState *hgs); const char *kind(); // LDC void toObjFile(int multiobj); // compile to .obj file }; struct PragmaDeclaration : AttribDeclaration { Expressions *args; // array of Expression's PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); int oneMember(Dsymbol **ps); void toCBuffer(OutBuffer *buf, HdrGenState *hgs); const char *kind(); void toObjFile(int multiobj); // compile to .obj file }; struct ConditionalDeclaration : AttribDeclaration { Condition *condition; Array *elsedecl; // array of Dsymbol's for else block ConditionalDeclaration(Condition *condition, Array *decl, Array *elsedecl); Dsymbol *syntaxCopy(Dsymbol *s); int oneMember(Dsymbol **ps); void emitComment(Scope *sc); Array *include(Scope *sc, ScopeDsymbol *s); void addComment(unsigned char *comment); void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct StaticIfDeclaration : ConditionalDeclaration { ScopeDsymbol *sd; int addisdone; StaticIfDeclaration(Condition *condition, Array *decl, Array *elsedecl); Dsymbol *syntaxCopy(Dsymbol *s); int addMember(Scope *sc, ScopeDsymbol *s, int memnum); void semantic(Scope *sc); const char *kind(); }; // Mixin declarations struct CompileDeclaration : AttribDeclaration { Expression *exp; ScopeDsymbol *sd; int compiled; CompileDeclaration(Loc loc, Expression *exp); Dsymbol *syntaxCopy(Dsymbol *s); int addMember(Scope *sc, ScopeDsymbol *sd, int memnum); void compileIt(Scope *sc); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; #endif /* DMD_ATTRIB_H */