summaryrefslogtreecommitdiff
path: root/gcc/d/dmd/declaration.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/d/dmd/declaration.h')
-rw-r--r--gcc/d/dmd/declaration.h582
1 files changed, 250 insertions, 332 deletions
diff --git a/gcc/d/dmd/declaration.h b/gcc/d/dmd/declaration.h
index 55c814288e0..1c56defd3ee 100644
--- a/gcc/d/dmd/declaration.h
+++ b/gcc/d/dmd/declaration.h
@@ -13,115 +13,98 @@
#include "dsymbol.h"
#include "mtype.h"
#include "objc.h"
+#include "tokens.h"
class Expression;
class Statement;
class LabelDsymbol;
class Initializer;
-class Module;
class ForeachStatement;
struct Ensure
{
Identifier *id;
Statement *ensure;
-
- Ensure();
- Ensure(Identifier *id, Statement *ensure);
- Ensure syntaxCopy();
- static Ensures *arraySyntaxCopy(Ensures *a);
};
-class AliasDeclaration;
class FuncDeclaration;
-class ExpInitializer;
class StructDeclaration;
-struct InterState;
-struct CompiledCtfeFunction;
-struct ObjcSelector;
struct IntRange;
-enum LINK;
-enum TOK;
-enum MATCH;
-enum PURE;
-enum PINLINE;
-
-#define STCundefined 0LL
-#define STCstatic 1LL
-#define STCextern 2LL
-#define STCconst 4LL
-#define STCfinal 8LL
-#define STCabstract 0x10LL
-#define STCparameter 0x20LL
-#define STCfield 0x40LL
-#define STCoverride 0x80LL
-#define STCauto 0x100LL
-#define STCsynchronized 0x200LL
-#define STCdeprecated 0x400LL
-#define STCin 0x800LL // in parameter
-#define STCout 0x1000LL // out parameter
-#define STClazy 0x2000LL // lazy parameter
-#define STCforeach 0x4000LL // variable for foreach loop
-#define STCvariadic 0x10000LL // the 'variadic' parameter in: T foo(T a, U b, V variadic...)
-#define STCctorinit 0x20000LL // can only be set inside constructor
-#define STCtemplateparameter 0x40000LL // template parameter
-#define STCscope 0x80000LL
-#define STCimmutable 0x100000LL
-#define STCref 0x200000LL
-#define STCinit 0x400000LL // has explicit initializer
-#define STCmanifest 0x800000LL // manifest constant
-#define STCnodtor 0x1000000LL // don't run destructor
-#define STCnothrow 0x2000000LL // never throws exceptions
-#define STCpure 0x4000000LL // pure function
-#define STCtls 0x8000000LL // thread local
-#define STCalias 0x10000000LL // alias parameter
-#define STCshared 0x20000000LL // accessible from multiple threads
-// accessible from multiple threads
-// but not typed as "shared"
-#define STCgshared 0x40000000LL
-#define STCwild 0x80000000LL // for "wild" type constructor
+//enum STC : ulong from astenums.d:
+
+ #define STCundefined 0ULL
+
+ #define STCstatic 1ULL /// `static`
+ #define STCextern 2ULL /// `extern`
+ #define STCconst 4ULL /// `const`
+ #define STCfinal 8ULL /// `final`
+
+ #define STCabstract 0x10ULL /// `abstract`
+ #define STCparameter 0x20ULL /// is function parameter
+ #define STCfield 0x40ULL /// is field of struct, union or class
+ #define STCoverride 0x80ULL /// `override`
+
+ #define STCauto 0x100ULL /// `auto`
+ #define STCsynchronized 0x200ULL /// `synchronized`
+ #define STCdeprecated 0x400ULL /// `deprecated`
+ #define STCin 0x800ULL /// `in` parameter
+
+ #define STCout 0x1000ULL /// `out` parameter
+ #define STClazy 0x2000ULL /// `lazy` parameter
+ #define STCforeach 0x4000ULL /// variable for foreach loop
+ #define STCvariadic 0x8000ULL /// the `variadic` parameter in: T foo(T a, U b, V variadic...)
+
+ #define STCctorinit 0x10000ULL /// can only be set inside constructor
+ #define STCtemplateparameter 0x20000ULL /// template parameter
+ #define STCref 0x40000ULL /// `ref`
+ #define STCscope 0x80000ULL /// `scope`
+
+ #define STCmaybescope 0x100000ULL /// parameter might be `scope`
+ #define STCscopeinferred 0x200000ULL /// `scope` has been inferred and should not be part of mangling, `scope` must also be set
+ #define STCreturn 0x400000ULL /// 'return ref' or 'return scope' for function parameters
+ #define STCreturnScope 0x800000ULL /// if `ref return scope` then resolve to `ref` and `return scope`
+
+ #define STCreturninferred 0x1000000ULL /// `return` has been inferred and should not be part of mangling, `return` must also be set
+ #define STCimmutable 0x2000000ULL /// `immutable`
+ #define STCinit 0x4000000ULL /// has explicit initializer
+ #define STCmanifest 0x8000000ULL /// manifest constant
+
+ #define STCnodtor 0x10000000ULL /// do not run destructor
+ #define STCnothrow 0x20000000ULL /// `nothrow` meaning never throws exceptions
+ #define STCpure 0x40000000ULL /// `pure` function
+ #define STCtls 0x80000000ULL /// thread local
+
+ #define STCalias 0x100000000ULL /// `alias` parameter
+ #define STCshared 0x200000000ULL /// accessible from multiple threads
+ #define STCgshared 0x400000000ULL /// accessible from multiple threads, but not typed as `shared`
+ #define STCwild 0x800000000ULL /// for wild type constructor
+
+ #define STCproperty 0x1000000000ULL /// `@property`
+ #define STCsafe 0x2000000000ULL /// `@safe`
+ #define STCtrusted 0x4000000000ULL /// `@trusted`
+ #define STCsystem 0x8000000000ULL /// `@system`
+
+ #define STCctfe 0x10000000000ULL /// can be used in CTFE, even if it is static
+ #define STCdisable 0x20000000000ULL /// for functions that are not callable
+ #define STCresult 0x40000000000ULL /// for result variables passed to out contracts
+ #define STCnodefaultctor 0x80000000000ULL /// must be set inside constructor
+
+ #define STCtemp 0x100000000000ULL /// temporary variable
+ #define STCrvalue 0x200000000000ULL /// force rvalue for variables
+ #define STCnogc 0x400000000000ULL /// `@nogc`
+ #define STCautoref 0x800000000000ULL /// Mark for the already deduced `auto ref` parameter
+
+ #define STCinference 0x1000000000000ULL /// do attribute inference
+ #define STCexptemp 0x2000000000000ULL /// temporary variable that has lifetime restricted to an expression
+ #define STCfuture 0x4000000000000ULL /// introducing new base class function
+ #define STClocal 0x8000000000000ULL /// do not forward (see dmd.dsymbol.ForwardingScopeDsymbol).
+
+ #define STClive 0x10000000000000ULL /// function `@live` attribute
+ #define STCregister 0x20000000000000ULL /// `register` storage class (ImportC)
+ #define STCvolatile 0x40000000000000ULL /// destined for volatile in the back end
+
#define STC_TYPECTOR (STCconst | STCimmutable | STCshared | STCwild)
#define STC_FUNCATTR (STCref | STCnothrow | STCnogc | STCpure | STCproperty | STCsafe | STCtrusted | STCsystem)
-#define STCproperty 0x100000000LL
-#define STCsafe 0x200000000LL
-#define STCtrusted 0x400000000LL
-#define STCsystem 0x800000000LL
-#define STCctfe 0x1000000000LL // can be used in CTFE, even if it is static
-#define STCdisable 0x2000000000LL // for functions that are not callable
-#define STCresult 0x4000000000LL // for result variables passed to out contracts
-#define STCnodefaultctor 0x8000000000LL // must be set inside constructor
-#define STCtemp 0x10000000000LL // temporary variable
-#define STCrvalue 0x20000000000LL // force rvalue for variables
-#define STCnogc 0x40000000000LL // @nogc
-#define STCvolatile 0x80000000000LL // destined for volatile in the back end
-#define STCreturn 0x100000000000LL // 'return ref' or 'return scope' for function parameters
-#define STCautoref 0x200000000000LL // Mark for the already deduced 'auto ref' parameter
-#define STCinference 0x400000000000LL // do attribute inference
-#define STCexptemp 0x800000000000LL // temporary variable that has lifetime restricted to an expression
-#define STCmaybescope 0x1000000000000LL // parameter might be 'scope'
-#define STCscopeinferred 0x2000000000000LL // 'scope' has been inferred and should not be part of mangling
-#define STCfuture 0x4000000000000LL // introducing new base class function
-#define STClocal 0x8000000000000LL // do not forward (see ddmd.dsymbol.ForwardingScopeDsymbol).
-
-const StorageClass STCStorageClass = (STCauto | STCscope | STCstatic | STCextern | STCconst | STCfinal |
- STCabstract | STCsynchronized | STCdeprecated | STCfuture | STCoverride | STClazy | STCalias |
- STCout | STCin |
- STCmanifest | STCimmutable | STCshared | STCwild | STCnothrow | STCnogc | STCpure | STCref | STCtls |
- STCgshared | STCproperty | STCsafe | STCtrusted | STCsystem | STCdisable | STClocal);
-
-struct Match
-{
- int count; // number of matches found
- MATCH last; // match level of lastf
- FuncDeclaration *lastf; // last matching function we found
- FuncDeclaration *nextf; // current matching function
- FuncDeclaration *anyf; // pick a func, any func, to use for error recovery
-};
-
-void functionResolve(Match *m, Dsymbol *fd, Loc loc, Scope *sc, Objects *tiargs, Type *tthis, Expressions *fargs, const char **pMessage = NULL);
-int overloadApply(Dsymbol *fstart, void *param, int (*fp)(void *, Dsymbol *));
-void aliasSemantic(AliasDeclaration *ds, Scope *sc);
-
void ObjectNotFound(Identifier *id);
/**************************************************************/
@@ -132,47 +115,45 @@ public:
Type *type;
Type *originalType; // before semantic analysis
StorageClass storage_class;
- Prot protection;
+ Visibility visibility;
LINK linkage;
- int inuse; // used to detect cycles
+ short inuse; // used to detect cycles
+ uint8_t adFlags;
DString mangleOverride; // overridden symbol with pragma(mangle, "...")
- Declaration(Identifier *id);
const char *kind() const;
- d_uns64 size(Loc loc);
- bool checkDisabled(Loc loc, Scope *sc, bool isAliasedDeclaration = false);
- int checkModify(Loc loc, Scope *sc, Type *t, Expression *e1, int flag);
+ d_uns64 size(const Loc &loc);
Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly);
- bool isStatic() { return (storage_class & STCstatic) != 0; }
+ bool isStatic() const { return (storage_class & STCstatic) != 0; }
virtual bool isDelete();
virtual bool isDataseg();
virtual bool isThreadlocal();
virtual bool isCodeseg() const;
- bool isCtorinit() { return (storage_class & STCctorinit) != 0; }
- bool isFinal() { return (storage_class & STCfinal) != 0; }
- bool isAbstract() { return (storage_class & STCabstract) != 0; }
- bool isConst() { return (storage_class & STCconst) != 0; }
- bool isImmutable() { return (storage_class & STCimmutable) != 0; }
- bool isWild() { return (storage_class & STCwild) != 0; }
- bool isAuto() { return (storage_class & STCauto) != 0; }
- bool isScope() { return (storage_class & STCscope) != 0; }
- bool isSynchronized() { return (storage_class & STCsynchronized) != 0; }
- bool isParameter() { return (storage_class & STCparameter) != 0; }
- bool isDeprecated() { return (storage_class & STCdeprecated) != 0; }
- bool isDisabled() { return (storage_class & STCdisable) != 0; }
- bool isOverride() { return (storage_class & STCoverride) != 0; }
- bool isResult() { return (storage_class & STCresult) != 0; }
- bool isField() { return (storage_class & STCfield) != 0; }
-
- bool isIn() { return (storage_class & STCin) != 0; }
- bool isOut() { return (storage_class & STCout) != 0; }
- bool isRef() { return (storage_class & STCref) != 0; }
-
- bool isFuture() { return (storage_class & STCfuture) != 0; }
-
- Prot prot();
+ bool isCtorinit() const { return (storage_class & STCctorinit) != 0; }
+ bool isFinal() const { return (storage_class & STCfinal) != 0; }
+ virtual bool isAbstract() { return (storage_class & STCabstract) != 0; }
+ bool isConst() const { return (storage_class & STCconst) != 0; }
+ bool isImmutable() const { return (storage_class & STCimmutable) != 0; }
+ bool isWild() const { return (storage_class & STCwild) != 0; }
+ bool isAuto() const { return (storage_class & STCauto) != 0; }
+ bool isScope() const { return (storage_class & STCscope) != 0; }
+ bool isSynchronized() const { return (storage_class & STCsynchronized) != 0; }
+ bool isParameter() const { return (storage_class & STCparameter) != 0; }
+ bool isDeprecated() const { return (storage_class & STCdeprecated) != 0; }
+ bool isOverride() const { return (storage_class & STCoverride) != 0; }
+ bool isResult() const { return (storage_class & STCresult) != 0; }
+ bool isField() const { return (storage_class & STCfield) != 0; }
+
+ bool isIn() const { return (storage_class & STCin) != 0; }
+ bool isOut() const { return (storage_class & STCout) != 0; }
+ bool isRef() const { return (storage_class & STCref) != 0; }
+ bool isReference() const { return (storage_class & (STCref | STCout)) != 0; }
+
+ bool isFuture() const { return (storage_class & STCfuture) != 0; }
+
+ Visibility visible();
Declaration *isDeclaration() { return this; }
void accept(Visitor *v) { v->visit(this); }
@@ -188,8 +169,7 @@ public:
TypeTuple *tupletype; // !=NULL if this is a type tuple
- TupleDeclaration(Loc loc, Identifier *ident, Objects *objects);
- Dsymbol *syntaxCopy(Dsymbol *);
+ TupleDeclaration *syntaxCopy(Dsymbol *);
const char *kind() const;
Type *getType();
Dsymbol *toAlias2();
@@ -208,16 +188,14 @@ public:
Dsymbol *overnext; // next in overload list
Dsymbol *_import; // !=NULL if unresolved internal alias for selective import
- AliasDeclaration(Loc loc, Identifier *ident, Type *type);
- AliasDeclaration(Loc loc, Identifier *ident, Dsymbol *s);
static AliasDeclaration *create(Loc loc, Identifier *id, Type *type);
- Dsymbol *syntaxCopy(Dsymbol *);
+ AliasDeclaration *syntaxCopy(Dsymbol *);
bool overloadInsert(Dsymbol *s);
const char *kind() const;
Type *getType();
Dsymbol *toAlias();
Dsymbol *toAlias2();
- bool isOverloadable();
+ bool isOverloadable() const;
AliasDeclaration *isAliasDeclaration() { return this; }
void accept(Visitor *v) { v->visit(this); }
@@ -230,16 +208,14 @@ class OverDeclaration : public Declaration
public:
Dsymbol *overnext; // next in overload list
Dsymbol *aliassym;
- bool hasOverloads;
- OverDeclaration(Identifier *ident, Dsymbol *s, bool hasOverloads = true);
const char *kind() const;
- bool equals(RootObject *o);
+ bool equals(const RootObject *o) const;
bool overloadInsert(Dsymbol *s);
Dsymbol *toAlias();
Dsymbol *isUnique();
- bool isOverloadable();
+ bool isOverloadable() const;
OverDeclaration *isOverDeclaration() { return this; }
void accept(Visitor *v) { v->visit(this); }
@@ -251,33 +227,40 @@ class VarDeclaration : public Declaration
{
public:
Initializer *_init;
+ FuncDeclarations nestedrefs; // referenced by these lexically nested functions
+ Dsymbol *aliassym; // if redone as alias to another symbol
+ VarDeclaration *lastVar; // Linked list of variables for goto-skips-init detection
+ Expression *edtor; // if !=NULL, does the destruction of the variable
+ IntRange *range; // if !NULL, the variable is known to be within the range
+ VarDeclarations *maybes; // STCmaybescope variables that are assigned to this STCmaybescope variable
+
+ unsigned endlinnum; // line number of end of scope that this var lives in
unsigned offset;
unsigned sequenceNumber; // order the variables are declared
- FuncDeclarations nestedrefs; // referenced by these lexically nested functions
- bool isargptr; // if parameter that _argptr points to
structalign_t alignment;
+
+ // When interpreting, these point to the value (NULL if value not determinable)
+ // The index of this variable on the CTFE stack, ~0u if not allocated
+ unsigned ctfeAdrOnStack;
+
+ bool isargptr; // if parameter that _argptr points to
bool ctorinit; // it has been initialized in a ctor
+ bool iscatchvar; // this is the exception object variable in catch() clause
+ bool isowner; // this is an Owner, despite it being `scope`
bool onstack; // it is a class that was allocated on the stack
bool mynew; // it is a class new'd with custom operator new
- int canassign; // it can be assigned to
+ char canassign; // it can be assigned to
bool overlapped; // if it is a field and has overlapping
bool overlapUnsafe; // if it is an overlapping field and the overlaps are unsafe
bool doNotInferScope; // do not infer 'scope' for this variable
+ bool doNotInferReturn; // do not infer 'return' for this variable
unsigned char isdataseg; // private data for isDataseg
- Dsymbol *aliassym; // if redone as alias to another symbol
- VarDeclaration *lastVar; // Linked list of variables for goto-skips-init detection
- unsigned endlinnum; // line number of end of scope that this var lives in
-
- // When interpreting, these point to the value (NULL if value not determinable)
- // The index of this variable on the CTFE stack, -1 if not allocated
- int ctfeAdrOnStack;
- Expression *edtor; // if !=NULL, does the destruction of the variable
- IntRange *range; // if !NULL, the variable is known to be within the range
+ bool isArgDtorVar; // temporary created to handle scope destruction of a function argument
- VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init);
- static VarDeclaration *create(Loc loc, Type *t, Identifier *id, Initializer *init);
- Dsymbol *syntaxCopy(Dsymbol *);
- void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion);
+public:
+ static VarDeclaration *create(const Loc &loc, Type *t, Identifier *id, Initializer *init, StorageClass storage_class = STCundefined);
+ VarDeclaration *syntaxCopy(Dsymbol *);
+ void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion);
const char *kind() const;
AggregateDeclaration *isThis();
bool needThis();
@@ -291,11 +274,7 @@ public:
bool canTakeAddressOf();
bool needsScopeDtor();
bool enclosesLifetimeOf(VarDeclaration *v) const;
- Expression *callScopeDtor(Scope *sc);
- Expression *getConstInitializer(bool needFullType = true);
- Expression *expandInitializer(Loc loc);
void checkCtorConstInit();
- bool checkNestedReference(Scope *sc, Loc loc);
Dsymbol *toAlias();
// Eliminate need for dynamic_cast
VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; }
@@ -304,6 +283,21 @@ public:
/**************************************************************/
+class BitFieldDeclaration : public VarDeclaration
+{
+public:
+ Expression *width;
+
+ unsigned fieldWidth;
+ unsigned bitOffset;
+
+ BitFieldDeclaration *syntaxCopy(Dsymbol*);
+ BitFieldDeclaration *isBitFieldDeclaration() { return this; }
+ void accept(Visitor *v) { v->visit(this); }
+};
+
+/**************************************************************/
+
// This is a shell around a back end symbol
class SymbolDeclaration : public Declaration
@@ -311,8 +305,6 @@ class SymbolDeclaration : public Declaration
public:
StructDeclaration *dsym;
- SymbolDeclaration(Loc loc, StructDeclaration *dsym);
-
// Eliminate need for dynamic_cast
SymbolDeclaration *isSymbolDeclaration() { return (SymbolDeclaration *)this; }
void accept(Visitor *v) { v->visit(this); }
@@ -323,10 +315,9 @@ class TypeInfoDeclaration : public VarDeclaration
public:
Type *tinfo;
- TypeInfoDeclaration(Type *tinfo);
static TypeInfoDeclaration *create(Type *tinfo);
- Dsymbol *syntaxCopy(Dsymbol *);
- const char *toChars();
+ TypeInfoDeclaration *syntaxCopy(Dsymbol *);
+ const char *toChars() const;
TypeInfoDeclaration *isTypeInfoDeclaration() { return this; }
void accept(Visitor *v) { v->visit(this); }
@@ -335,7 +326,6 @@ public:
class TypeInfoStructDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoStructDeclaration(Type *tinfo);
static TypeInfoStructDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -344,7 +334,6 @@ public:
class TypeInfoClassDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoClassDeclaration(Type *tinfo);
static TypeInfoClassDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -353,7 +342,6 @@ public:
class TypeInfoInterfaceDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoInterfaceDeclaration(Type *tinfo);
static TypeInfoInterfaceDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -362,7 +350,6 @@ public:
class TypeInfoPointerDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoPointerDeclaration(Type *tinfo);
static TypeInfoPointerDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -371,7 +358,6 @@ public:
class TypeInfoArrayDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoArrayDeclaration(Type *tinfo);
static TypeInfoArrayDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -380,7 +366,6 @@ public:
class TypeInfoStaticArrayDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoStaticArrayDeclaration(Type *tinfo);
static TypeInfoStaticArrayDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -389,7 +374,6 @@ public:
class TypeInfoAssociativeArrayDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoAssociativeArrayDeclaration(Type *tinfo);
static TypeInfoAssociativeArrayDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -398,7 +382,6 @@ public:
class TypeInfoEnumDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoEnumDeclaration(Type *tinfo);
static TypeInfoEnumDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -407,7 +390,6 @@ public:
class TypeInfoFunctionDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoFunctionDeclaration(Type *tinfo);
static TypeInfoFunctionDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -416,7 +398,6 @@ public:
class TypeInfoDelegateDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoDelegateDeclaration(Type *tinfo);
static TypeInfoDelegateDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -425,7 +406,6 @@ public:
class TypeInfoTupleDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoTupleDeclaration(Type *tinfo);
static TypeInfoTupleDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -434,7 +414,6 @@ public:
class TypeInfoConstDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoConstDeclaration(Type *tinfo);
static TypeInfoConstDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -443,7 +422,6 @@ public:
class TypeInfoInvariantDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoInvariantDeclaration(Type *tinfo);
static TypeInfoInvariantDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -452,7 +430,6 @@ public:
class TypeInfoSharedDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoSharedDeclaration(Type *tinfo);
static TypeInfoSharedDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -461,7 +438,6 @@ public:
class TypeInfoWildDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoWildDeclaration(Type *tinfo);
static TypeInfoWildDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -470,7 +446,6 @@ public:
class TypeInfoVectorDeclaration : public TypeInfoDeclaration
{
public:
- TypeInfoVectorDeclaration(Type *tinfo);
static TypeInfoVectorDeclaration *create(Type *tinfo);
void accept(Visitor *v) { v->visit(this); }
@@ -481,13 +456,12 @@ public:
class ThisDeclaration : public VarDeclaration
{
public:
- ThisDeclaration(Loc loc, Type *t);
- Dsymbol *syntaxCopy(Dsymbol *);
+ ThisDeclaration *syntaxCopy(Dsymbol *);
ThisDeclaration *isThisDeclaration() { return this; }
void accept(Visitor *v) { v->visit(this); }
};
-enum ILS
+enum class ILS : unsigned char
{
ILSuninitialized, // not computed yet
ILSno, // cannot inline
@@ -496,68 +470,53 @@ enum ILS
/**************************************************************/
-enum BUILTIN
-{
- BUILTINunknown = 255, /// not known if this is a builtin
- BUILTINunimp = 0, /// this is not a builtin
- BUILTINgcc, /// this is a GCC builtin
- BUILTINllvm, /// this is an LLVM builtin
- BUILTINsin,
- BUILTINcos,
- BUILTINtan,
- BUILTINsqrt,
- BUILTINfabs,
- BUILTINldexp,
- BUILTINlog,
- BUILTINlog2,
- BUILTINlog10,
- BUILTINexp,
- BUILTINexpm1,
- BUILTINexp2,
- BUILTINround,
- BUILTINfloor,
- BUILTINceil,
- BUILTINtrunc,
- BUILTINcopysign,
- BUILTINpow,
- BUILTINfmin,
- BUILTINfmax,
- BUILTINfma,
- BUILTINisnan,
- BUILTINisinfinity,
- BUILTINisfinite,
- BUILTINbsf,
- BUILTINbsr,
- BUILTINbswap,
- BUILTINpopcnt,
- BUILTINyl2x,
- BUILTINyl2xp1,
- BUILTINtoPrecFloat,
- BUILTINtoPrecDouble,
- BUILTINtoPrecReal
+enum class BUILTIN : unsigned char
+{
+ unknown = 255, /// not known if this is a builtin
+ unimp = 0, /// this is not a builtin
+ gcc, /// this is a GCC builtin
+ llvm, /// this is an LLVM builtin
+ sin,
+ cos,
+ tan,
+ sqrt,
+ fabs,
+ ldexp,
+ log,
+ log2,
+ log10,
+ exp,
+ expm1,
+ exp2,
+ round,
+ floor,
+ ceil,
+ trunc,
+ copysign,
+ pow,
+ fmin,
+ fmax,
+ fma,
+ isnan,
+ isinfinity,
+ isfinite,
+ bsf,
+ bsr,
+ bswap,
+ popcnt,
+ yl2x,
+ yl2xp1,
+ toPrecFloat,
+ toPrecDouble,
+ toPrecReal
};
Expression *eval_builtin(Loc loc, FuncDeclaration *fd, Expressions *arguments);
BUILTIN isBuiltin(FuncDeclaration *fd);
-typedef Expression *(*builtin_fp)(Loc loc, FuncDeclaration *fd, Expressions *arguments);
-void add_builtin(const char *mangle, builtin_fp fp);
-void builtin_init();
-
-#define FUNCFLAGpurityInprocess 1 // working on determining purity
-#define FUNCFLAGsafetyInprocess 2 // working on determining safety
-#define FUNCFLAGnothrowInprocess 4 // working on determining nothrow
-#define FUNCFLAGnogcInprocess 8 // working on determining @nogc
-#define FUNCFLAGreturnInprocess 0x10 // working on inferring 'return' for parameters
-#define FUNCFLAGinlineScanned 0x20 // function has been scanned for inline possibilities
-#define FUNCFLAGinferScope 0x40 // infer 'scope' for parameters
-#define FUNCFLAGprintf 0x200 // is a printf-like function
-#define FUNCFLAGscanf 0x400 // is a scanf-like function
-
class FuncDeclaration : public Declaration
{
public:
- Types *fthrows; // Array of Type's of exceptions (not used)
Statements *frequires; // in contracts
Ensures *fensures; // out contracts
Statement *frequire; // lowered in contract
@@ -568,6 +527,9 @@ public:
FuncDeclaration *fdrequire; // function that does the in contract
FuncDeclaration *fdensure; // function that does the out contract
+ Expressions *fdrequireParams; // argument list for __require
+ Expressions *fdensureParams; // argument list for __ensure
+
const char *mangleString; // mangled symbol created from mangleExact()
VarDeclaration *vresult; // result variable for out contracts
@@ -577,8 +539,9 @@ public:
// scopes from having the same name
DsymbolTable *localsymtab;
VarDeclaration *vthis; // 'this' parameter (member and nested)
+ bool isThis2; // has a dual-context 'this' parameter
VarDeclaration *v_arguments; // '_arguments' parameter
- ObjcSelector* selector; // Objective-C method selector (member function only)
+
VarDeclaration *v_argptr; // '_argptr' variable
VarDeclarations *parameters; // Array of VarDeclaration's for parameters
DsymbolTable *labtab; // statement label symbol table
@@ -589,13 +552,16 @@ public:
bool naked; // true if naked
bool generated; // true if function was generated by the compiler rather than
// supplied by the user
+ bool hasAlwaysInlines; // contains references to functions that must be inlined
+ unsigned char isCrtCtorDtor; // has attribute pragma(crt_constructor(1)/crt_destructor(2))
+ // not set before the glue layer
ILS inlineStatusStmt;
ILS inlineStatusExp;
PINLINE inlining;
- CompiledCtfeFunction *ctfeCode; // Compiled code for interpreter
int inlineNest; // !=0 if nested inline
- bool isArrayOp; // true if array operation
+ bool eh_none; /// true if no exception unwinding is needed
+
// true if errors in semantic3 this function's frame ptr
bool semantic3Errors;
ForeachStatement *fes; // if foreach body, this is the foreach
@@ -635,6 +601,12 @@ public:
// local variables in this function which are referenced by nested functions
VarDeclarations closureVars;
+
+ /** Outer variables which are referenced by this nested function
+ * (the inverse of closureVars)
+ */
+ VarDeclarations outerVars;
+
// Sibling nested functions which called this one
FuncDeclarations siblingCallers;
@@ -642,76 +614,62 @@ public:
unsigned flags; // FUNCFLAGxxxxx
- FuncDeclaration(Loc loc, Loc endloc, Identifier *id, StorageClass storage_class, Type *type);
- static FuncDeclaration *create(Loc loc, Loc endloc, Identifier *id, StorageClass storage_class, Type *type);
- Dsymbol *syntaxCopy(Dsymbol *);
+ // Data for a function declaration that is needed for the Objective-C
+ // integration.
+ ObjcFuncDeclaration objc;
+
+ static FuncDeclaration *create(const Loc &loc, const Loc &endloc, Identifier *id, StorageClass storage_class, Type *type, bool noreturn = false);
+ FuncDeclaration *syntaxCopy(Dsymbol *);
bool functionSemantic();
bool functionSemantic3();
- bool checkForwardRef(Loc loc);
- // called from semantic3
- VarDeclaration *declareThis(Scope *sc, AggregateDeclaration *ad);
- bool equals(RootObject *o);
+ bool equals(const RootObject *o) const;
int overrides(FuncDeclaration *fd);
- int findVtblIndex(Dsymbols *vtbl, int dim, bool fix17349 = true);
+ int findVtblIndex(Dsymbols *vtbl, int dim);
BaseClass *overrideInterface();
bool overloadInsert(Dsymbol *s);
- FuncDeclaration *overloadExactMatch(Type *t);
- FuncDeclaration *overloadModMatch(Loc loc, Type *tthis, bool &hasOverloads);
- TemplateDeclaration *findTemplateDeclRoot();
bool inUnittest();
MATCH leastAsSpecialized(FuncDeclaration *g);
- LabelDsymbol *searchLabel(Identifier *ident);
- int getLevel(Loc loc, Scope *sc, FuncDeclaration *fd); // lexical nesting level difference
+ LabelDsymbol *searchLabel(Identifier *ident, const Loc &loc);
+ int getLevel(FuncDeclaration *fd, int intypeof); // lexical nesting level difference
+ int getLevelAndCheck(const Loc &loc, Scope *sc, FuncDeclaration *fd);
const char *toPrettyChars(bool QualifyTypes = false);
const char *toFullSignature(); // for diagnostics, e.g. 'int foo(int x, int y) pure'
- bool isMain();
- bool isCMain();
- bool isWinMain();
- bool isDllMain();
+ bool isMain() const;
+ bool isCMain() const;
+ bool isWinMain() const;
+ bool isDllMain() const;
bool isExport() const;
bool isImportedSymbol() const;
bool isCodeseg() const;
- bool isOverloadable();
+ bool isOverloadable() const;
+ bool isAbstract();
PURE isPure();
PURE isPureBypassingInference();
- bool setImpure();
bool isSafe();
bool isSafeBypassingInference();
bool isTrusted();
- bool setUnsafe();
bool isNogc();
bool isNogcBypassingInference();
- bool setGC();
- void printGCUsage(Loc loc, const char *warn);
- bool isolateReturn();
- bool parametersIntersect(Type *t);
- virtual bool isNested();
+ virtual bool isNested() const;
AggregateDeclaration *isThis();
bool needThis();
bool isVirtualMethod();
- virtual bool isVirtual();
- virtual bool isFinalFunc();
+ virtual bool isVirtual() const;
+ bool isFinalFunc() const;
virtual bool addPreInvariant();
virtual bool addPostInvariant();
const char *kind() const;
- FuncDeclaration *isUnique();
- bool checkNestedReference(Scope *sc, Loc loc);
+ bool isUnique();
bool needsClosure();
- bool checkClosure();
bool hasNestedFrameRefs();
- void buildResultVar(Scope *sc, Type *tret);
- Statement *mergeFrequire(Statement *);
- static bool needsFensure(FuncDeclaration *fd);
- void buildEnsureRequire();
- Statement *mergeFensure(Statement *, Identifier *oid);
ParameterList getParameterList();
static FuncDeclaration *genCfunc(Parameters *args, Type *treturn, const char *name, StorageClass stc=0);
static FuncDeclaration *genCfunc(Parameters *args, Type *treturn, Identifier *id, StorageClass stc=0);
- void checkDmain();
+
bool checkNRVO();
FuncDeclaration *isFuncDeclaration() { return this; }
@@ -720,20 +678,12 @@ public:
void accept(Visitor *v) { v->visit(this); }
};
-FuncDeclaration *resolveFuncCall(Loc loc, Scope *sc, Dsymbol *s,
- Objects *tiargs,
- Type *tthis,
- Expressions *arguments,
- int flags = 0);
-
class FuncAliasDeclaration : public FuncDeclaration
{
public:
FuncDeclaration *funcalias;
bool hasOverloads;
- FuncAliasDeclaration(Identifier *ident, FuncDeclaration *funcalias, bool hasOverloads = true);
-
FuncAliasDeclaration *isFuncAliasDeclaration() { return this; }
const char *kind() const;
@@ -750,12 +700,10 @@ public:
// backend
bool deferToObj;
- FuncLiteralDeclaration(Loc loc, Loc endloc, Type *type, TOK tok,
- ForeachStatement *fes, Identifier *id = NULL);
- Dsymbol *syntaxCopy(Dsymbol *);
- bool isNested();
+ FuncLiteralDeclaration *syntaxCopy(Dsymbol *);
+ bool isNested() const;
AggregateDeclaration *isThis();
- bool isVirtual();
+ bool isVirtual() const;
bool addPreInvariant();
bool addPostInvariant();
@@ -770,11 +718,11 @@ public:
class CtorDeclaration : public FuncDeclaration
{
public:
- CtorDeclaration(Loc loc, Loc endloc, StorageClass stc, Type *type);
- Dsymbol *syntaxCopy(Dsymbol *);
+ bool isCpCtor;
+ CtorDeclaration *syntaxCopy(Dsymbol *);
const char *kind() const;
- const char *toChars();
- bool isVirtual();
+ const char *toChars() const;
+ bool isVirtual() const;
bool addPreInvariant();
bool addPostInvariant();
@@ -785,9 +733,8 @@ public:
class PostBlitDeclaration : public FuncDeclaration
{
public:
- PostBlitDeclaration(Loc loc, Loc endloc, StorageClass stc, Identifier *id);
- Dsymbol *syntaxCopy(Dsymbol *);
- bool isVirtual();
+ PostBlitDeclaration *syntaxCopy(Dsymbol *);
+ bool isVirtual() const;
bool addPreInvariant();
bool addPostInvariant();
bool overloadInsert(Dsymbol *s);
@@ -799,12 +746,10 @@ public:
class DtorDeclaration : public FuncDeclaration
{
public:
- DtorDeclaration(Loc loc, Loc endloc);
- DtorDeclaration(Loc loc, Loc endloc, StorageClass stc, Identifier *id);
- Dsymbol *syntaxCopy(Dsymbol *);
+ DtorDeclaration *syntaxCopy(Dsymbol *);
const char *kind() const;
- const char *toChars();
- bool isVirtual();
+ const char *toChars() const;
+ bool isVirtual() const;
bool addPreInvariant();
bool addPostInvariant();
bool overloadInsert(Dsymbol *s);
@@ -816,11 +761,9 @@ public:
class StaticCtorDeclaration : public FuncDeclaration
{
public:
- StaticCtorDeclaration(Loc loc, Loc endloc, StorageClass stc);
- StaticCtorDeclaration(Loc loc, Loc endloc, const char *name, StorageClass stc);
- Dsymbol *syntaxCopy(Dsymbol *);
+ StaticCtorDeclaration *syntaxCopy(Dsymbol *);
AggregateDeclaration *isThis();
- bool isVirtual();
+ bool isVirtual() const;
bool addPreInvariant();
bool addPostInvariant();
bool hasStaticCtorOrDtor();
@@ -832,8 +775,7 @@ public:
class SharedStaticCtorDeclaration : public StaticCtorDeclaration
{
public:
- SharedStaticCtorDeclaration(Loc loc, Loc endloc, StorageClass stc);
- Dsymbol *syntaxCopy(Dsymbol *);
+ SharedStaticCtorDeclaration *syntaxCopy(Dsymbol *);
SharedStaticCtorDeclaration *isSharedStaticCtorDeclaration() { return this; }
void accept(Visitor *v) { v->visit(this); }
@@ -844,11 +786,9 @@ class StaticDtorDeclaration : public FuncDeclaration
public:
VarDeclaration *vgate; // 'gate' variable
- StaticDtorDeclaration(Loc loc, Loc endloc, StorageClass stc);
- StaticDtorDeclaration(Loc loc, Loc endloc, const char *name, StorageClass stc);
- Dsymbol *syntaxCopy(Dsymbol *);
+ StaticDtorDeclaration *syntaxCopy(Dsymbol *);
AggregateDeclaration *isThis();
- bool isVirtual();
+ bool isVirtual() const;
bool hasStaticCtorOrDtor();
bool addPreInvariant();
bool addPostInvariant();
@@ -860,8 +800,7 @@ public:
class SharedStaticDtorDeclaration : public StaticDtorDeclaration
{
public:
- SharedStaticDtorDeclaration(Loc loc, Loc endloc, StorageClass stc);
- Dsymbol *syntaxCopy(Dsymbol *);
+ SharedStaticDtorDeclaration *syntaxCopy(Dsymbol *);
SharedStaticDtorDeclaration *isSharedStaticDtorDeclaration() { return this; }
void accept(Visitor *v) { v->visit(this); }
@@ -870,9 +809,8 @@ public:
class InvariantDeclaration : public FuncDeclaration
{
public:
- InvariantDeclaration(Loc loc, Loc endloc, StorageClass stc, Identifier *id = NULL);
- Dsymbol *syntaxCopy(Dsymbol *);
- bool isVirtual();
+ InvariantDeclaration *syntaxCopy(Dsymbol *);
+ bool isVirtual() const;
bool addPreInvariant();
bool addPostInvariant();
@@ -888,10 +826,9 @@ public:
// toObjFile() these nested functions after this one
FuncDeclarations deferredNested;
- UnitTestDeclaration(Loc loc, Loc endloc, StorageClass stc, char *codedoc);
- Dsymbol *syntaxCopy(Dsymbol *);
+ UnitTestDeclaration *syntaxCopy(Dsymbol *);
AggregateDeclaration *isThis();
- bool isVirtual();
+ bool isVirtual() const;
bool addPreInvariant();
bool addPostInvariant();
@@ -905,31 +842,12 @@ public:
Parameters *parameters;
VarArg varargs;
- NewDeclaration(Loc loc, Loc endloc, StorageClass stc, Parameters *arguments, VarArg varargs);
- Dsymbol *syntaxCopy(Dsymbol *);
+ NewDeclaration *syntaxCopy(Dsymbol *);
const char *kind() const;
- bool isVirtual();
+ bool isVirtual() const;
bool addPreInvariant();
bool addPostInvariant();
NewDeclaration *isNewDeclaration() { return this; }
void accept(Visitor *v) { v->visit(this); }
};
-
-
-class DeleteDeclaration : public FuncDeclaration
-{
-public:
- Parameters *parameters;
-
- DeleteDeclaration(Loc loc, Loc endloc, StorageClass stc, Parameters *arguments);
- Dsymbol *syntaxCopy(Dsymbol *);
- const char *kind() const;
- bool isDelete();
- bool isVirtual();
- bool addPreInvariant();
- bool addPostInvariant();
-
- DeleteDeclaration *isDeleteDeclaration() { return this; }
- void accept(Visitor *v) { v->visit(this); }
-};