diff --git a/dmd/access.c b/dmd/access.c
index da61b973..1c360951 100644
--- a/dmd/access.c
+++ b/dmd/access.c
@@ -49,15 +49,15 @@ enum PROT StructDeclaration::getAccess(Dsymbol *smember)
#if LOG
printf("+StructDeclaration::getAccess(this = '%s', smember = '%s')\n",
- toChars(), smember->toChars());
+ toChars(), smember->toChars());
#endif
if (smember->toParent() == this)
{
- access_ret = smember->prot();
+ access_ret = smember->prot();
}
else if (smember->isDeclaration()->isStatic())
{
- access_ret = smember->prot();
+ access_ret = smember->prot();
}
return access_ret;
}
@@ -68,56 +68,56 @@ enum PROT ClassDeclaration::getAccess(Dsymbol *smember)
#if LOG
printf("+ClassDeclaration::getAccess(this = '%s', smember = '%s')\n",
- toChars(), smember->toChars());
+ toChars(), smember->toChars());
#endif
if (smember->toParent() == this)
{
- access_ret = smember->prot();
+ access_ret = smember->prot();
}
else
{
- enum PROT access;
- int i;
+ enum PROT access;
+ int i;
- if (smember->isDeclaration()->isStatic())
- {
- access_ret = smember->prot();
- }
+ if (smember->isDeclaration()->isStatic())
+ {
+ access_ret = smember->prot();
+ }
- for (i = 0; i < baseclasses.dim; i++)
- { BaseClass *b = (BaseClass *)baseclasses.data[i];
+ for (i = 0; i < baseclasses.dim; i++)
+ { BaseClass *b = (BaseClass *)baseclasses.data[i];
- access = b->base->getAccess(smember);
- switch (access)
- {
- case PROTnone:
- break;
+ access = b->base->getAccess(smember);
+ switch (access)
+ {
+ case PROTnone:
+ break;
- case PROTprivate:
- access = PROTnone; // private members of base class not accessible
- break;
+ case PROTprivate:
+ access = PROTnone; // private members of base class not accessible
+ break;
- case PROTpackage:
- case PROTprotected:
- case PROTpublic:
- case PROTexport:
- // If access is to be tightened
- if (b->protection < access)
- access = b->protection;
+ case PROTpackage:
+ case PROTprotected:
+ case PROTpublic:
+ case PROTexport:
+ // If access is to be tightened
+ if (b->protection < access)
+ access = b->protection;
- // Pick path with loosest access
- if (access > access_ret)
- access_ret = access;
- break;
+ // Pick path with loosest access
+ if (access > access_ret)
+ access_ret = access;
+ break;
- default:
- assert(0);
- }
- }
+ default:
+ assert(0);
+ }
+ }
}
#if LOG
printf("-ClassDeclaration::getAccess(this = '%s', smember = '%s') = %d\n",
- toChars(), smember->toChars(), access_ret);
+ toChars(), smember->toChars(), access_ret);
#endif
return access_ret;
}
@@ -125,63 +125,63 @@ enum PROT ClassDeclaration::getAccess(Dsymbol *smember)
/********************************************************
* Helper function for ClassDeclaration::accessCheck()
* Returns:
- * 0 no access
- * 1 access
+ * 0 no access
+ * 1 access
*/
static int accessCheckX(
- Dsymbol *smember,
- Dsymbol *sfunc,
- AggregateDeclaration *dthis,
- AggregateDeclaration *cdscope)
+ Dsymbol *smember,
+ Dsymbol *sfunc,
+ AggregateDeclaration *dthis,
+ AggregateDeclaration *cdscope)
{
assert(dthis);
#if 0
printf("accessCheckX for %s.%s in function %s() in scope %s\n",
- dthis->toChars(), smember->toChars(),
- sfunc ? sfunc->toChars() : "NULL",
- cdscope ? cdscope->toChars() : "NULL");
+ dthis->toChars(), smember->toChars(),
+ sfunc ? sfunc->toChars() : "NULL",
+ cdscope ? cdscope->toChars() : "NULL");
#endif
if (dthis->hasPrivateAccess(sfunc) ||
- dthis->isFriendOf(cdscope))
+ dthis->isFriendOf(cdscope))
{
- if (smember->toParent() == dthis)
- return 1;
- else
- {
- ClassDeclaration *cdthis = dthis->isClassDeclaration();
- if (cdthis)
- {
- for (int i = 0; i < cdthis->baseclasses.dim; i++)
- { BaseClass *b = (BaseClass *)cdthis->baseclasses.data[i];
- enum PROT access;
+ if (smember->toParent() == dthis)
+ return 1;
+ else
+ {
+ ClassDeclaration *cdthis = dthis->isClassDeclaration();
+ if (cdthis)
+ {
+ for (int i = 0; i < cdthis->baseclasses.dim; i++)
+ { BaseClass *b = (BaseClass *)cdthis->baseclasses.data[i];
+ enum PROT access;
- access = b->base->getAccess(smember);
- if (access >= PROTprotected ||
- accessCheckX(smember, sfunc, b->base, cdscope)
- )
- return 1;
+ access = b->base->getAccess(smember);
+ if (access >= PROTprotected ||
+ accessCheckX(smember, sfunc, b->base, cdscope)
+ )
+ return 1;
- }
- }
- }
+ }
+ }
+ }
}
else
{
- if (smember->toParent() != dthis)
- {
- ClassDeclaration *cdthis = dthis->isClassDeclaration();
- if (cdthis)
- {
- for (int i = 0; i < cdthis->baseclasses.dim; i++)
- { BaseClass *b = (BaseClass *)cdthis->baseclasses.data[i];
+ if (smember->toParent() != dthis)
+ {
+ ClassDeclaration *cdthis = dthis->isClassDeclaration();
+ if (cdthis)
+ {
+ for (int i = 0; i < cdthis->baseclasses.dim; i++)
+ { BaseClass *b = (BaseClass *)cdthis->baseclasses.data[i];
- if (accessCheckX(smember, sfunc, b->base, cdscope))
- return 1;
- }
- }
- }
+ if (accessCheckX(smember, sfunc, b->base, cdscope))
+ return 1;
+ }
+ }
+ }
}
return 0;
}
@@ -201,58 +201,58 @@ void AggregateDeclaration::accessCheck(Loc loc, Scope *sc, Dsymbol *smember)
#if LOG
printf("AggregateDeclaration::accessCheck() for %s.%s in function %s() in scope %s\n",
- toChars(), smember->toChars(),
- f ? f->toChars() : NULL,
- cdscope ? cdscope->toChars() : NULL);
+ toChars(), smember->toChars(),
+ f ? f->toChars() : NULL,
+ cdscope ? cdscope->toChars() : NULL);
#endif
Dsymbol *smemberparent = smember->toParent();
if (!smemberparent || !smemberparent->isAggregateDeclaration())
{
#if LOG
- printf("not an aggregate member\n");
+ printf("not an aggregate member\n");
#endif
- return; // then it is accessible
+ return; // then it is accessible
}
// BUG: should enable this check
//assert(smember->parent->isBaseOf(this, NULL));
if (smemberparent == this)
- { enum PROT access = smember->prot();
+ { enum PROT access = smember->prot();
- result = access >= PROTpublic ||
- hasPrivateAccess(f) ||
- isFriendOf(cdscope) ||
- (access == PROTpackage && hasPackageAccess(sc, this));
+ result = access >= PROTpublic ||
+ hasPrivateAccess(f) ||
+ isFriendOf(cdscope) ||
+ (access == PROTpackage && hasPackageAccess(sc, this));
#if LOG
- printf("result1 = %d\n", result);
+ printf("result1 = %d\n", result);
#endif
}
else if ((access = this->getAccess(smember)) >= PROTpublic)
{
- result = 1;
+ result = 1;
#if LOG
- printf("result2 = %d\n", result);
+ printf("result2 = %d\n", result);
#endif
}
else if (access == PROTpackage && hasPackageAccess(sc, this))
{
- result = 1;
+ result = 1;
#if LOG
- printf("result3 = %d\n", result);
+ printf("result3 = %d\n", result);
#endif
}
else
{
- result = accessCheckX(smember, f, this, cdscope);
+ result = accessCheckX(smember, f, this, cdscope);
#if LOG
- printf("result4 = %d\n", result);
+ printf("result4 = %d\n", result);
#endif
}
if (!result)
{
- error(loc, "member %s is not accessible", smember->toChars());
+ error(loc, "member %s is not accessible", smember->toChars());
halt();
}
}
@@ -267,16 +267,16 @@ int AggregateDeclaration::isFriendOf(AggregateDeclaration *cd)
printf("AggregateDeclaration::isFriendOf(this = '%s', cd = '%s')\n", toChars(), cd ? cd->toChars() : "null");
#endif
if (this == cd)
- return 1;
+ return 1;
// Friends if both are in the same module
//if (toParent() == cd->toParent())
if (cd && getModule() == cd->getModule())
{
#if LOG
- printf("\tin same module\n");
+ printf("\tin same module\n");
#endif
- return 1;
+ return 1;
}
#if LOG
@@ -297,20 +297,20 @@ int hasPackageAccess(Scope *sc, Dsymbol *s)
for (; s; s = s->parent)
{
- if (s->isPackage() && !s->isModule())
- break;
+ if (s->isPackage() && !s->isModule())
+ break;
}
#if LOG
if (s)
- printf("\tthis is in package '%s'\n", s->toChars());
+ printf("\tthis is in package '%s'\n", s->toChars());
#endif
if (s && s == sc->module->parent)
{
#if LOG
- printf("\ts is in same package as sc\n");
+ printf("\ts is in same package as sc\n");
#endif
- return 1;
+ return 1;
}
@@ -327,46 +327,46 @@ int hasPackageAccess(Scope *sc, Dsymbol *s)
int AggregateDeclaration::hasPrivateAccess(Dsymbol *smember)
{
if (smember)
- { AggregateDeclaration *cd = NULL;
- Dsymbol *smemberparent = smember->toParent();
- if (smemberparent)
- cd = smemberparent->isAggregateDeclaration();
+ { AggregateDeclaration *cd = NULL;
+ Dsymbol *smemberparent = smember->toParent();
+ if (smemberparent)
+ cd = smemberparent->isAggregateDeclaration();
#if LOG
- printf("AggregateDeclaration::hasPrivateAccess(class %s, member %s)\n",
- toChars(), smember->toChars());
+ printf("AggregateDeclaration::hasPrivateAccess(class %s, member %s)\n",
+ toChars(), smember->toChars());
#endif
- if (this == cd) // smember is a member of this class
- {
+ if (this == cd) // smember is a member of this class
+ {
#if LOG
- printf("\tyes 1\n");
+ printf("\tyes 1\n");
#endif
- return 1; // so we get private access
- }
+ return 1; // so we get private access
+ }
- // If both are members of the same module, grant access
- while (1)
- { Dsymbol *sp = smember->toParent();
- if (sp->isFuncDeclaration() && smember->isFuncDeclaration())
- smember = sp;
- else
- break;
- }
- if (!cd && toParent() == smember->toParent())
- {
+ // If both are members of the same module, grant access
+ while (1)
+ { Dsymbol *sp = smember->toParent();
+ if (sp->isFuncDeclaration() && smember->isFuncDeclaration())
+ smember = sp;
+ else
+ break;
+ }
+ if (!cd && toParent() == smember->toParent())
+ {
#if LOG
- printf("\tyes 2\n");
+ printf("\tyes 2\n");
#endif
- return 1;
- }
- if (!cd && getModule() == smember->getModule())
- {
+ return 1;
+ }
+ if (!cd && getModule() == smember->getModule())
+ {
#if LOG
- printf("\tyes 3\n");
+ printf("\tyes 3\n");
#endif
- return 1;
- }
+ return 1;
+ }
}
#if LOG
printf("\tno\n");
@@ -382,43 +382,43 @@ void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d)
{
#if LOG
if (e)
- { printf("accessCheck(%s . %s)\n", e->toChars(), d->toChars());
- printf("\te->type = %s\n", e->type->toChars());
+ { printf("accessCheck(%s . %s)\n", e->toChars(), d->toChars());
+ printf("\te->type = %s\n", e->type->toChars());
}
else
{
- //printf("accessCheck(%s)\n", d->toChars());
+ //printf("accessCheck(%s)\n", d->toChars());
}
#endif
if (!e)
{
- if (d->prot() == PROTprivate && d->getModule() != sc->module ||
- d->prot() == PROTpackage && !hasPackageAccess(sc, d))
+ if (d->prot() == PROTprivate && d->getModule() != sc->module ||
+ d->prot() == PROTpackage && !hasPackageAccess(sc, d))
- error(loc, "%s %s.%s is not accessible from %s",
- d->kind(), d->getModule()->toChars(), d->toChars(), sc->module->toChars());
+ error(loc, "%s %s.%s is not accessible from %s",
+ d->kind(), d->getModule()->toChars(), d->toChars(), sc->module->toChars());
}
else if (e->type->ty == Tclass)
{ // Do access check
- ClassDeclaration *cd;
+ ClassDeclaration *cd;
- cd = (ClassDeclaration *)(((TypeClass *)e->type)->sym);
+ cd = (ClassDeclaration *)(((TypeClass *)e->type)->sym);
#if 1
- if (e->op == TOKsuper)
- { ClassDeclaration *cd2;
+ if (e->op == TOKsuper)
+ { ClassDeclaration *cd2;
- cd2 = sc->func->toParent()->isClassDeclaration();
- if (cd2)
- cd = cd2;
- }
+ cd2 = sc->func->toParent()->isClassDeclaration();
+ if (cd2)
+ cd = cd2;
+ }
#endif
- cd->accessCheck(loc, sc, d);
+ cd->accessCheck(loc, sc, d);
}
else if (e->type->ty == Tstruct)
{ // Do access check
- StructDeclaration *cd;
+ StructDeclaration *cd;
- cd = (StructDeclaration *)(((TypeStruct *)e->type)->sym);
- cd->accessCheck(loc, sc, d);
+ cd = (StructDeclaration *)(((TypeStruct *)e->type)->sym);
+ cd->accessCheck(loc, sc, d);
}
}
diff --git a/dmd/aggregate.h b/dmd/aggregate.h
index 09e472d7..f1fb5aff 100644
--- a/dmd/aggregate.h
+++ b/dmd/aggregate.h
@@ -56,36 +56,36 @@ struct AggregateDeclaration : ScopeDsymbol
Type *type;
StorageClass storage_class;
enum PROT protection;
- Type *handle; // 'this' type
- unsigned structsize; // size of struct
- unsigned alignsize; // size of struct for alignment purposes
- unsigned structalign; // struct member alignment in effect
- int hasUnions; // set if aggregate has overlapping fields
- Array fields; // VarDeclaration fields
- unsigned sizeok; // set when structsize contains valid data
- // 0: no size
- // 1: size is correct
- // 2: cannot determine size; fwd referenced
- int isdeprecated; // !=0 if deprecated
+ Type *handle; // 'this' type
+ unsigned structsize; // size of struct
+ unsigned alignsize; // size of struct for alignment purposes
+ unsigned structalign; // struct member alignment in effect
+ int hasUnions; // set if aggregate has overlapping fields
+ Array fields; // VarDeclaration fields
+ unsigned sizeok; // set when structsize contains valid data
+ // 0: no size
+ // 1: size is correct
+ // 2: cannot determine size; fwd referenced
+ int isdeprecated; // !=0 if deprecated
#if DMDV2
- int isnested; // !=0 if is nested
- VarDeclaration *vthis; // 'this' parameter if this aggregate is nested
+ int isnested; // !=0 if is nested
+ VarDeclaration *vthis; // 'this' parameter if this aggregate is nested
#endif
// Special member functions
- InvariantDeclaration *inv; // invariant
- NewDeclaration *aggNew; // allocator
- DeleteDeclaration *aggDelete; // deallocator
+ InvariantDeclaration *inv; // invariant
+ NewDeclaration *aggNew; // allocator
+ DeleteDeclaration *aggDelete; // deallocator
#if DMDV2
//CtorDeclaration *ctor;
- Dsymbol *ctor; // CtorDeclaration or TemplateDeclaration
- CtorDeclaration *defaultCtor; // default constructor
- Dsymbol *aliasthis; // forward unresolved lookups to aliasthis
+ Dsymbol *ctor; // CtorDeclaration or TemplateDeclaration
+ CtorDeclaration *defaultCtor; // default constructor
+ Dsymbol *aliasthis; // forward unresolved lookups to aliasthis
#endif
- FuncDeclarations dtors; // Array of destructors
- FuncDeclaration *dtor; // aggregate destructor
+ FuncDeclarations dtors; // Array of destructors
+ FuncDeclaration *dtor; // aggregate destructor
#ifdef IN_GCC
Array methods; // flat list of all methods for debug information
@@ -99,7 +99,7 @@ struct AggregateDeclaration : ScopeDsymbol
static void alignmember(unsigned salign, unsigned size, unsigned *poffset);
Type *getType();
void addField(Scope *sc, VarDeclaration *v);
- int isDeprecated(); // is aggregate deprecated?
+ int isDeprecated(); // is aggregate deprecated?
FuncDeclaration *buildDtor(Scope *sc);
int isNested();
@@ -108,16 +108,16 @@ struct AggregateDeclaration : ScopeDsymbol
void toDocBuffer(OutBuffer *buf);
// For access checking
- virtual PROT getAccess(Dsymbol *smember); // determine access to smember
+ virtual PROT getAccess(Dsymbol *smember); // determine access to smember
int isFriendOf(AggregateDeclaration *cd);
- int hasPrivateAccess(Dsymbol *smember); // does smember have private access to members of this class?
+ int hasPrivateAccess(Dsymbol *smember); // does smember have private access to members of this class?
void accessCheck(Loc loc, Scope *sc, Dsymbol *smember);
enum PROT prot();
#if IN_DMD
// Back end
- Symbol *stag; // tag symbol for debug data
+ Symbol *stag; // tag symbol for debug data
Symbol *sinit;
Symbol *toInitializer();
#endif
@@ -133,7 +133,7 @@ struct AggregateDeclaration : ScopeDsymbol
struct AnonymousAggregateDeclaration : AggregateDeclaration
{
AnonymousAggregateDeclaration()
- : AggregateDeclaration(0, NULL)
+ : AggregateDeclaration(0, NULL)
{
}
@@ -142,13 +142,13 @@ struct AnonymousAggregateDeclaration : AggregateDeclaration
struct StructDeclaration : AggregateDeclaration
{
- int zeroInit; // !=0 if initialize with 0 fill
+ int zeroInit; // !=0 if initialize with 0 fill
#if DMDV2
- int hasIdentityAssign; // !=0 if has identity opAssign
- FuncDeclaration *cpctor; // generated copy-constructor, if any
+ int hasIdentityAssign; // !=0 if has identity opAssign
+ FuncDeclaration *cpctor; // generated copy-constructor, if any
- FuncDeclarations postblits; // Array of postblit functions
- FuncDeclaration *postblit; // aggregate postblit
+ FuncDeclarations postblits; // Array of postblit functions
+ FuncDeclaration *postblit; // aggregate postblit
#endif
StructDeclaration(Loc loc, Identifier *id);
@@ -169,12 +169,12 @@ struct StructDeclaration : AggregateDeclaration
#endif
void toDocBuffer(OutBuffer *buf);
- PROT getAccess(Dsymbol *smember); // determine access to smember
+ PROT getAccess(Dsymbol *smember); // determine access to smember
#if IN_DMD
- void toObjFile(int multiobj); // compile to .obj file
+ void toObjFile(int multiobj); // compile to .obj file
void toDt(dt_t **pdt);
- void toDebug(); // to symbolic debug info
+ void toDebug(); // to symbolic debug info
#endif
StructDeclaration *isStructDeclaration() { return this; }
@@ -197,17 +197,17 @@ struct UnionDeclaration : StructDeclaration
// BaseClass instance.
struct BaseClass
{
- Type *type; // (before semantic processing)
- enum PROT protection; // protection for the base interface
+ Type *type; // (before semantic processing)
+ enum PROT protection; // protection for the base interface
ClassDeclaration *base;
- int offset; // 'this' pointer offset
- Array vtbl; // for interfaces: Array of FuncDeclaration's
- // making up the vtbl[]
+ int offset; // 'this' pointer offset
+ Array vtbl; // for interfaces: Array of FuncDeclaration's
+ // making up the vtbl[]
int baseInterfaces_dim;
- BaseClass *baseInterfaces; // if BaseClass is an interface, these
- // are a copy of the InterfaceDeclaration::interfaces
+ BaseClass *baseInterfaces; // if BaseClass is an interface, these
+ // are a copy of the InterfaceDeclaration::interfaces
BaseClass();
BaseClass(Type *type, enum PROT protection);
@@ -217,9 +217,9 @@ struct BaseClass
};
#if DMDV2
-#define CLASSINFO_SIZE (0x3C+16+4) // value of ClassInfo.size
+#define CLASSINFO_SIZE (0x3C+16+4) // value of ClassInfo.size
#else
-#define CLASSINFO_SIZE (0x3C+12+4) // value of ClassInfo.size
+#define CLASSINFO_SIZE (0x3C+12+4) // value of ClassInfo.size
#endif
struct ClassDeclaration : AggregateDeclaration
@@ -227,36 +227,36 @@ struct ClassDeclaration : AggregateDeclaration
static ClassDeclaration *object;
static ClassDeclaration *classinfo;
- ClassDeclaration *baseClass; // NULL only if this is Object
+ ClassDeclaration *baseClass; // NULL only if this is Object
#if DMDV1
CtorDeclaration *ctor;
- CtorDeclaration *defaultCtor; // default constructor
+ CtorDeclaration *defaultCtor; // default constructor
#endif
FuncDeclaration *staticCtor;
FuncDeclaration *staticDtor;
- Array vtbl; // Array of FuncDeclaration's making up the vtbl[]
- Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[]
+ Array vtbl; // Array of FuncDeclaration's making up the vtbl[]
+ Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[]
- BaseClasses baseclasses; // Array of BaseClass's; first is super,
- // rest are Interface's
+ BaseClasses baseclasses; // Array of BaseClass's; first is super,
+ // rest are Interface's
int interfaces_dim;
- BaseClass **interfaces; // interfaces[interfaces_dim] for this class
- // (does not include baseClass)
+ BaseClass **interfaces; // interfaces[interfaces_dim] for this class
+ // (does not include baseClass)
- BaseClasses *vtblInterfaces; // array of base interfaces that have
- // their own vtbl[]
+ BaseClasses *vtblInterfaces; // array of base interfaces that have
+ // their own vtbl[]
- ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration
- int com; // !=0 if this is a COM class (meaning
- // it derives from IUnknown)
- int isscope; // !=0 if this is a scope class
- int isabstract; // !=0 if abstract class
+ ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration
+ int com; // !=0 if this is a COM class (meaning
+ // it derives from IUnknown)
+ int isscope; // !=0 if this is a scope class
+ int isabstract; // !=0 if abstract class
#if DMDV1
- int isnested; // !=0 if is nested
- VarDeclaration *vthis; // 'this' parameter if this class is nested
+ int isnested; // !=0 if is nested
+ VarDeclaration *vthis; // 'this' parameter if this class is nested
#endif
- int inuse; // to prevent recursive attempts
+ int inuse; // to prevent recursive attempts
ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
Dsymbol *syntaxCopy(Dsymbol *s);
@@ -287,13 +287,13 @@ struct ClassDeclaration : AggregateDeclaration
char *mangle();
void toDocBuffer(OutBuffer *buf);
- PROT getAccess(Dsymbol *smember); // determine access to smember
+ PROT getAccess(Dsymbol *smember); // determine access to smember
void addLocalClass(ClassDeclarations *);
#if IN_DMD
// Back end
- void toObjFile(int multiobj); // compile to .obj file
+ void toObjFile(int multiobj); // compile to .obj file
void toDebug();
unsigned baseVtblOffset(BaseClass *bc);
Symbol *toSymbol();
@@ -314,7 +314,7 @@ struct ClassDeclaration : AggregateDeclaration
struct InterfaceDeclaration : ClassDeclaration
{
#if DMDV2
- int cpp; // !=0 if this is a C++ interface
+ int cpp; // !=0 if this is a C++ interface
#endif
InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
Dsymbol *syntaxCopy(Dsymbol *s);
@@ -329,7 +329,7 @@ struct InterfaceDeclaration : ClassDeclaration
virtual int isCOMinterface();
#if IN_DMD
- void toObjFile(int multiobj); // compile to .obj file
+ void toObjFile(int multiobj); // compile to .obj file
Symbol *toSymbol();
#endif
diff --git a/dmd/arrayop.c b/dmd/arrayop.c
index 11175a9d..bab96c9e 100644
--- a/dmd/arrayop.c
+++ b/dmd/arrayop.c
@@ -94,10 +94,10 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arrayExpSliceAddass_t",
// "_arrayExpSliceAddass_u",
// "_arrayExpSliceAddass_w",
-//
+//
// "_arrayExpSliceDivass_d", // T[]/=T
// "_arrayExpSliceDivass_f", // T[]/=T
-//
+//
// "_arrayExpSliceMinSliceAssign_a",
// "_arrayExpSliceMinSliceAssign_d", // T[]=T-T[]
// "_arrayExpSliceMinSliceAssign_f", // T[]=T-T[]
@@ -109,7 +109,7 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arrayExpSliceMinSliceAssign_t",
// "_arrayExpSliceMinSliceAssign_u",
// "_arrayExpSliceMinSliceAssign_w",
-//
+//
// "_arrayExpSliceMinass_a",
// "_arrayExpSliceMinass_d", // T[]-=T
// "_arrayExpSliceMinass_f", // T[]-=T
@@ -121,7 +121,7 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arrayExpSliceMinass_t",
// "_arrayExpSliceMinass_u",
// "_arrayExpSliceMinass_w",
-//
+//
// "_arrayExpSliceMulass_d", // T[]*=T
// "_arrayExpSliceMulass_f", // T[]*=T
// "_arrayExpSliceMulass_i",
@@ -130,7 +130,7 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arrayExpSliceMulass_t",
// "_arrayExpSliceMulass_u",
// "_arrayExpSliceMulass_w",
-//
+//
// "_arraySliceExpAddSliceAssign_a",
// "_arraySliceExpAddSliceAssign_d", // T[]=T[]+T
// "_arraySliceExpAddSliceAssign_f", // T[]=T[]+T
@@ -142,10 +142,10 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arraySliceExpAddSliceAssign_t",
// "_arraySliceExpAddSliceAssign_u",
// "_arraySliceExpAddSliceAssign_w",
-//
+//
// "_arraySliceExpDivSliceAssign_d", // T[]=T[]/T
// "_arraySliceExpDivSliceAssign_f", // T[]=T[]/T
-//
+//
// "_arraySliceExpMinSliceAssign_a",
// "_arraySliceExpMinSliceAssign_d", // T[]=T[]-T
// "_arraySliceExpMinSliceAssign_f", // T[]=T[]-T
@@ -157,11 +157,11 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arraySliceExpMinSliceAssign_t",
// "_arraySliceExpMinSliceAssign_u",
// "_arraySliceExpMinSliceAssign_w",
-//
+//
// "_arraySliceExpMulSliceAddass_d", // T[] += T[]*T
// "_arraySliceExpMulSliceAddass_f",
// "_arraySliceExpMulSliceAddass_r",
-//
+//
// "_arraySliceExpMulSliceAssign_d", // T[]=T[]*T
// "_arraySliceExpMulSliceAssign_f", // T[]=T[]*T
// "_arraySliceExpMulSliceAssign_i",
@@ -170,11 +170,11 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arraySliceExpMulSliceAssign_t",
// "_arraySliceExpMulSliceAssign_u",
// "_arraySliceExpMulSliceAssign_w",
-//
+//
// "_arraySliceExpMulSliceMinass_d", // T[] -= T[]*T
// "_arraySliceExpMulSliceMinass_f",
// "_arraySliceExpMulSliceMinass_r",
-//
+//
// "_arraySliceSliceAddSliceAssign_a",
// "_arraySliceSliceAddSliceAssign_d", // T[]=T[]+T[]
// "_arraySliceSliceAddSliceAssign_f", // T[]=T[]+T[]
@@ -187,7 +187,7 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arraySliceSliceAddSliceAssign_t",
// "_arraySliceSliceAddSliceAssign_u",
// "_arraySliceSliceAddSliceAssign_w",
-//
+//
// "_arraySliceSliceAddass_a",
// "_arraySliceSliceAddass_d", // T[]+=T[]
// "_arraySliceSliceAddass_f", // T[]+=T[]
@@ -199,7 +199,7 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arraySliceSliceAddass_t",
// "_arraySliceSliceAddass_u",
// "_arraySliceSliceAddass_w",
-//
+//
// "_arraySliceSliceMinSliceAssign_a",
// "_arraySliceSliceMinSliceAssign_d", // T[]=T[]-T[]
// "_arraySliceSliceMinSliceAssign_f", // T[]=T[]-T[]
@@ -212,7 +212,7 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arraySliceSliceMinSliceAssign_t",
// "_arraySliceSliceMinSliceAssign_u",
// "_arraySliceSliceMinSliceAssign_w",
-//
+//
// "_arraySliceSliceMinass_a",
// "_arraySliceSliceMinass_d", // T[]-=T[]
// "_arraySliceSliceMinass_f", // T[]-=T[]
@@ -224,7 +224,7 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arraySliceSliceMinass_t",
// "_arraySliceSliceMinass_u",
// "_arraySliceSliceMinass_w",
-//
+//
// "_arraySliceSliceMulSliceAssign_d", // T[]=T[]*T[]
// "_arraySliceSliceMulSliceAssign_f", // T[]=T[]*T[]
// "_arraySliceSliceMulSliceAssign_i",
@@ -233,7 +233,7 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arraySliceSliceMulSliceAssign_t",
// "_arraySliceSliceMulSliceAssign_u",
// "_arraySliceSliceMulSliceAssign_w",
-//
+//
// "_arraySliceSliceMulass_d", // T[]*=T[]
// "_arraySliceSliceMulass_f", // T[]*=T[]
// "_arraySliceSliceMulass_i",
@@ -243,7 +243,7 @@ Expression *BinExp::arrayOp(Scope *sc)
// "_arraySliceSliceMulass_u",
// "_arraySliceSliceMulass_w",
// };
-//
+//
// int i = binary(name, libArrayopFuncs, sizeof(libArrayopFuncs) / sizeof(char *));
// if (i == -1)
// {
@@ -305,8 +305,8 @@ Expression *BinExp::arrayOp(Scope *sc)
sc->stc = 0;
sc->linkage = LINKd;
fd->semantic(sc);
- fd->semantic2(sc);
- fd->semantic3(sc);
+ fd->semantic2(sc);
+ fd->semantic3(sc);
sc->pop();
// }
// else
@@ -342,10 +342,10 @@ void CastExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
Type *tb = type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
{
- e1->buildArrayIdent(buf, arguments);
+ e1->buildArrayIdent(buf, arguments);
}
else
- Expression::buildArrayIdent(buf, arguments);
+ Expression::buildArrayIdent(buf, arguments);
}
void SliceExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
@@ -365,13 +365,13 @@ void AssignExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
#define X(Str) \
void Str##AssignExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments) \
-{ \
- /* Evaluate assign expressions right to left \
- */ \
- e2->buildArrayIdent(buf, arguments); \
- e1->buildArrayIdent(buf, arguments); \
- buf->writestring(#Str); \
- buf->writestring("ass"); \
+{ \
+ /* Evaluate assign expressions right to left \
+ */ \
+ e2->buildArrayIdent(buf, arguments); \
+ e1->buildArrayIdent(buf, arguments); \
+ buf->writestring(#Str); \
+ buf->writestring("ass"); \
}
X(Add)
@@ -398,13 +398,13 @@ void ComExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
}
#define X(Str) \
-void Str##Exp::buildArrayIdent(OutBuffer *buf, Expressions *arguments) \
-{ \
- /* Evaluate assign expressions left to right \
- */ \
- e1->buildArrayIdent(buf, arguments); \
- e2->buildArrayIdent(buf, arguments); \
- buf->writestring(#Str); \
+void Str##Exp::buildArrayIdent(OutBuffer *buf, Expressions *arguments) \
+{ \
+ /* Evaluate assign expressions left to right \
+ */ \
+ e1->buildArrayIdent(buf, arguments); \
+ e2->buildArrayIdent(buf, arguments); \
+ buf->writestring(#Str); \
}
X(Add)
@@ -437,10 +437,10 @@ Expression *CastExp::buildArrayLoop(Parameters *fparams)
Type *tb = type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
{
- return e1->buildArrayLoop(fparams);
+ return e1->buildArrayLoop(fparams);
}
else
- return Expression::buildArrayLoop(fparams);
+ return Expression::buildArrayLoop(fparams);
}
Expression *SliceExp::buildArrayLoop(Parameters *fparams)
@@ -477,16 +477,16 @@ Expression *AssignExp::buildArrayLoop(Parameters *fparams)
}
#define X(Str) \
-Expression *Str##AssignExp::buildArrayLoop(Parameters *fparams) \
-{ \
- /* Evaluate assign expressions right to left \
- */ \
- Expression *ex2 = e2->buildArrayLoop(fparams); \
- Expression *ex1 = e1->buildArrayLoop(fparams); \
- Parameter *param = (Parameter *)fparams->data[0]; \
- param->storageClass = 0; \
- Expression *e = new Str##AssignExp(0, ex1, ex2); \
- return e; \
+Expression *Str##AssignExp::buildArrayLoop(Parameters *fparams) \
+{ \
+ /* Evaluate assign expressions right to left \
+ */ \
+ Expression *ex2 = e2->buildArrayLoop(fparams); \
+ Expression *ex1 = e1->buildArrayLoop(fparams); \
+ Parameter *param = (Parameter *)fparams->data[0]; \
+ param->storageClass = 0; \
+ Expression *e = new Str##AssignExp(0, ex1, ex2); \
+ return e; \
}
X(Add)
@@ -515,14 +515,14 @@ Expression *ComExp::buildArrayLoop(Parameters *fparams)
}
#define X(Str) \
-Expression *Str##Exp::buildArrayLoop(Parameters *fparams) \
-{ \
- /* Evaluate assign expressions left to right \
- */ \
- Expression *ex1 = e1->buildArrayLoop(fparams); \
- Expression *ex2 = e2->buildArrayLoop(fparams); \
- Expression *e = new Str##Exp(0, ex1, ex2); \
- return e; \
+Expression *Str##Exp::buildArrayLoop(Parameters *fparams) \
+{ \
+ /* Evaluate assign expressions left to right \
+ */ \
+ Expression *ex1 = e1->buildArrayLoop(fparams); \
+ Expression *ex2 = e2->buildArrayLoop(fparams); \
+ Expression *e = new Str##Exp(0, ex1, ex2); \
+ return e; \
}
X(Add)
@@ -545,26 +545,26 @@ int Expression::isArrayOperand()
{
//printf("Expression::isArrayOperand() %s\n", toChars());
if (op == TOKslice)
- return 1;
+ return 1;
if (type->toBasetype()->ty == Tarray)
{
- switch (op)
- {
- case TOKadd:
- case TOKmin:
- case TOKmul:
- case TOKdiv:
- case TOKmod:
- case TOKxor:
- case TOKand:
- case TOKor:
- case TOKneg:
- case TOKtilde:
- return 1;
+ switch (op)
+ {
+ case TOKadd:
+ case TOKmin:
+ case TOKmul:
+ case TOKdiv:
+ case TOKmod:
+ case TOKxor:
+ case TOKand:
+ case TOKor:
+ case TOKneg:
+ case TOKtilde:
+ return 1;
- default:
- break;
- }
+ default:
+ break;
+ }
}
return 0;
}
diff --git a/dmd/attrib.c b/dmd/attrib.c
index c5a392bc..7799fab7 100644
--- a/dmd/attrib.c
+++ b/dmd/attrib.c
@@ -52,7 +52,7 @@ void obj_startaddress(Symbol *s);
/********************************* AttribDeclaration ****************************/
AttribDeclaration::AttribDeclaration(Array *decl)
- : Dsymbol()
+ : Dsymbol()
{
this->decl = decl;
}
@@ -69,81 +69,81 @@ int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- m |= s->addMember(sc, sd, m | memnum);
- }
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ m |= s->addMember(sc, sd, m | memnum);
+ }
}
return m;
}
void AttribDeclaration::setScopeNewSc(Scope *sc,
- StorageClass stc, enum LINK linkage, enum PROT protection, int explicitProtection,
- unsigned structalign)
+ StorageClass stc, enum LINK linkage, enum PROT protection, int explicitProtection,
+ unsigned structalign)
{
if (decl)
{
- Scope *newsc = sc;
- if (stc != sc->stc ||
- linkage != sc->linkage ||
- protection != sc->protection ||
- explicitProtection != sc->explicitProtection ||
- structalign != sc->structalign)
- {
- // create new one for changes
- newsc = new Scope(*sc);
- newsc->flags &= ~SCOPEfree;
- newsc->stc = stc;
- newsc->linkage = linkage;
- newsc->protection = protection;
- newsc->explicitProtection = explicitProtection;
- newsc->structalign = structalign;
- }
- for (unsigned i = 0; i < decl->dim; i++)
- { Dsymbol *s = (Dsymbol *)decl->data[i];
+ Scope *newsc = sc;
+ if (stc != sc->stc ||
+ linkage != sc->linkage ||
+ protection != sc->protection ||
+ explicitProtection != sc->explicitProtection ||
+ structalign != sc->structalign)
+ {
+ // create new one for changes
+ newsc = new Scope(*sc);
+ newsc->flags &= ~SCOPEfree;
+ newsc->stc = stc;
+ newsc->linkage = linkage;
+ newsc->protection = protection;
+ newsc->explicitProtection = explicitProtection;
+ newsc->structalign = structalign;
+ }
+ for (unsigned i = 0; i < decl->dim; i++)
+ { Dsymbol *s = (Dsymbol *)decl->data[i];
- s->setScope(newsc); // yes, the only difference from semanticNewSc()
- }
- if (newsc != sc)
- {
- sc->offset = newsc->offset;
- newsc->pop();
- }
+ s->setScope(newsc); // yes, the only difference from semanticNewSc()
+ }
+ if (newsc != sc)
+ {
+ sc->offset = newsc->offset;
+ newsc->pop();
+ }
}
}
void AttribDeclaration::semanticNewSc(Scope *sc,
- StorageClass stc, enum LINK linkage, enum PROT protection, int explicitProtection,
- unsigned structalign)
+ StorageClass stc, enum LINK linkage, enum PROT protection, int explicitProtection,
+ unsigned structalign)
{
if (decl)
{
- Scope *newsc = sc;
- if (stc != sc->stc ||
- linkage != sc->linkage ||
- protection != sc->protection ||
- explicitProtection != sc->explicitProtection ||
- structalign != sc->structalign)
- {
- // create new one for changes
- newsc = new Scope(*sc);
- newsc->flags &= ~SCOPEfree;
- newsc->stc = stc;
- newsc->linkage = linkage;
- newsc->protection = protection;
- newsc->explicitProtection = explicitProtection;
- newsc->structalign = structalign;
- }
- for (unsigned i = 0; i < decl->dim; i++)
- { Dsymbol *s = (Dsymbol *)decl->data[i];
+ Scope *newsc = sc;
+ if (stc != sc->stc ||
+ linkage != sc->linkage ||
+ protection != sc->protection ||
+ explicitProtection != sc->explicitProtection ||
+ structalign != sc->structalign)
+ {
+ // create new one for changes
+ newsc = new Scope(*sc);
+ newsc->flags &= ~SCOPEfree;
+ newsc->stc = stc;
+ newsc->linkage = linkage;
+ newsc->protection = protection;
+ newsc->explicitProtection = explicitProtection;
+ newsc->structalign = structalign;
+ }
+ for (unsigned i = 0; i < decl->dim; i++)
+ { Dsymbol *s = (Dsymbol *)decl->data[i];
- s->semantic(newsc);
- }
- if (newsc != sc)
- {
- sc->offset = newsc->offset;
- newsc->pop();
- }
+ s->semantic(newsc);
+ }
+ if (newsc != sc)
+ {
+ sc->offset = newsc->offset;
+ newsc->pop();
+ }
}
}
@@ -154,12 +154,12 @@ void AttribDeclaration::semantic(Scope *sc)
//printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d);
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)d->data[i];
+ for (unsigned i = 0; i < d->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)d->data[i];
- s->semantic(sc);
- }
+ s->semantic(sc);
+ }
}
}
@@ -169,10 +169,10 @@ void AttribDeclaration::semantic2(Scope *sc)
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- s->semantic2(sc);
- }
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ s->semantic2(sc);
+ }
}
}
@@ -182,10 +182,10 @@ void AttribDeclaration::semantic3(Scope *sc)
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- s->semantic3(sc);
- }
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ s->semantic3(sc);
+ }
}
}
@@ -195,11 +195,11 @@ void AttribDeclaration::inlineScan()
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- //printf("AttribDeclaration::inlineScan %s\n", s->toChars());
- s->inlineScan();
- }
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ //printf("AttribDeclaration::inlineScan %s\n", s->toChars());
+ s->inlineScan();
+ }
}
}
@@ -207,16 +207,16 @@ void AttribDeclaration::addComment(unsigned char *comment)
{
if (comment)
{
- Array *d = include(NULL, NULL);
+ Array *d = include(NULL, NULL);
- if (d)
- {
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- //printf("AttribDeclaration::addComment %s\n", s->toChars());
- s->addComment(comment);
- }
- }
+ if (d)
+ {
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ //printf("AttribDeclaration::addComment %s\n", s->toChars());
+ s->addComment(comment);
+ }
+ }
}
}
@@ -236,11 +236,11 @@ void AttribDeclaration::emitComment(Scope *sc)
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- //printf("AttribDeclaration::emitComment %s\n", s->toChars());
- s->emitComment(sc);
- }
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ //printf("AttribDeclaration::emitComment %s\n", s->toChars());
+ s->emitComment(sc);
+ }
}
}
@@ -252,10 +252,10 @@ void AttribDeclaration::toObjFile(int multiobj)
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- s->toObjFile(multiobj);
- }
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ s->toObjFile(multiobj);
+ }
}
}
@@ -267,13 +267,13 @@ int AttribDeclaration::cvMember(unsigned char *p)
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- n = s->cvMember(p);
- if (p)
- p += n;
- nwritten += n;
- }
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ n = s->cvMember(p);
+ if (p)
+ p += n;
+ nwritten += n;
+ }
}
return nwritten;
}
@@ -285,12 +285,12 @@ int AttribDeclaration::hasPointers()
if (d)
{
- for (size_t i = 0; i < d->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)d->data[i];
- if (s->hasPointers())
- return 1;
- }
+ for (size_t i = 0; i < d->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)d->data[i];
+ if (s->hasPointers())
+ return 1;
+ }
}
return 0;
}
@@ -313,10 +313,10 @@ void AttribDeclaration::checkCtorConstInit()
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- s->checkCtorConstInit();
- }
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ s->checkCtorConstInit();
+ }
}
}
@@ -329,10 +329,10 @@ void AttribDeclaration::addLocalClass(ClassDeclarations *aclasses)
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- s->addLocalClass(aclasses);
- }
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ s->addLocalClass(aclasses);
+ }
}
}
@@ -341,27 +341,27 @@ void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (decl)
{
- buf->writenl();
- buf->writeByte('{');
- buf->writenl();
- for (unsigned i = 0; i < decl->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ buf->writenl();
+ buf->writeByte('{');
+ buf->writenl();
+ for (unsigned i = 0; i < decl->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)decl->data[i];
- buf->writestring(" ");
- s->toCBuffer(buf, hgs);
- }
- buf->writeByte('}');
+ buf->writestring(" ");
+ s->toCBuffer(buf, hgs);
+ }
+ buf->writeByte('}');
}
else
- buf->writeByte(';');
+ buf->writeByte(';');
buf->writenl();
}
/************************* StorageClassDeclaration ****************************/
StorageClassDeclaration::StorageClassDeclaration(StorageClass stc, Array *decl)
- : AttribDeclaration(decl)
+ : AttribDeclaration(decl)
{
this->stc = stc;
}
@@ -379,24 +379,24 @@ void StorageClassDeclaration::setScope(Scope *sc)
{
if (decl)
{
- StorageClass scstc = sc->stc;
+ StorageClass scstc = sc->stc;
- /* These sets of storage classes are mutually exclusive,
- * so choose the innermost or most recent one.
- */
- if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest))
- scstc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest);
- if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared))
- scstc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared);
- if (stc & (STCconst | STCimmutable | STCmanifest))
- scstc &= ~(STCconst | STCimmutable | STCmanifest);
- if (stc & (STCgshared | STCshared | STCtls))
- scstc &= ~(STCgshared | STCshared | STCtls);
- if (stc & (STCsafe | STCtrusted | STCsystem))
- scstc &= ~(STCsafe | STCtrusted | STCsystem);
- scstc |= stc;
+ /* These sets of storage classes are mutually exclusive,
+ * so choose the innermost or most recent one.
+ */
+ if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest))
+ scstc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest);
+ if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared))
+ scstc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared);
+ if (stc & (STCconst | STCimmutable | STCmanifest))
+ scstc &= ~(STCconst | STCimmutable | STCmanifest);
+ if (stc & (STCgshared | STCshared | STCtls))
+ scstc &= ~(STCgshared | STCshared | STCtls);
+ if (stc & (STCsafe | STCtrusted | STCsystem))
+ scstc &= ~(STCsafe | STCtrusted | STCsystem);
+ scstc |= stc;
- setScopeNewSc(sc, scstc, sc->linkage, sc->protection, sc->explicitProtection, sc->structalign);
+ setScopeNewSc(sc, scstc, sc->linkage, sc->protection, sc->explicitProtection, sc->structalign);
}
}
@@ -404,24 +404,24 @@ void StorageClassDeclaration::semantic(Scope *sc)
{
if (decl)
{
- StorageClass scstc = sc->stc;
+ StorageClass scstc = sc->stc;
- /* These sets of storage classes are mutually exclusive,
- * so choose the innermost or most recent one.
- */
- if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest))
- scstc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest);
- if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared))
- scstc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared);
- if (stc & (STCconst | STCimmutable | STCmanifest))
- scstc &= ~(STCconst | STCimmutable | STCmanifest);
- if (stc & (STCgshared | STCshared | STCtls))
- scstc &= ~(STCgshared | STCshared | STCtls);
- if (stc & (STCsafe | STCtrusted | STCsystem))
- scstc &= ~(STCsafe | STCtrusted | STCsystem);
- scstc |= stc;
+ /* These sets of storage classes are mutually exclusive,
+ * so choose the innermost or most recent one.
+ */
+ if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest))
+ scstc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest);
+ if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared))
+ scstc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared);
+ if (stc & (STCconst | STCimmutable | STCmanifest))
+ scstc &= ~(STCconst | STCimmutable | STCmanifest);
+ if (stc & (STCgshared | STCshared | STCtls))
+ scstc &= ~(STCgshared | STCshared | STCtls);
+ if (stc & (STCsafe | STCtrusted | STCsystem))
+ scstc &= ~(STCsafe | STCtrusted | STCsystem);
+ scstc |= stc;
- semanticNewSc(sc, scstc, sc->linkage, sc->protection, sc->explicitProtection, sc->structalign);
+ semanticNewSc(sc, scstc, sc->linkage, sc->protection, sc->explicitProtection, sc->structalign);
}
}
@@ -429,48 +429,48 @@ void StorageClassDeclaration::stcToCBuffer(OutBuffer *buf, StorageClass stc)
{
struct SCstring
{
- StorageClass stc;
- enum TOK tok;
+ StorageClass stc;
+ enum TOK tok;
};
static SCstring table[] =
{
- { STCauto, TOKauto },
- { STCscope, TOKscope },
- { STCstatic, TOKstatic },
- { STCextern, TOKextern },
- { STCconst, TOKconst },
- { STCfinal, TOKfinal },
- { STCabstract, TOKabstract },
- { STCsynchronized, TOKsynchronized },
- { STCdeprecated, TOKdeprecated },
- { STCoverride, TOKoverride },
- { STClazy, TOKlazy },
- { STCalias, TOKalias },
- { STCout, TOKout },
- { STCin, TOKin },
+ { STCauto, TOKauto },
+ { STCscope, TOKscope },
+ { STCstatic, TOKstatic },
+ { STCextern, TOKextern },
+ { STCconst, TOKconst },
+ { STCfinal, TOKfinal },
+ { STCabstract, TOKabstract },
+ { STCsynchronized, TOKsynchronized },
+ { STCdeprecated, TOKdeprecated },
+ { STCoverride, TOKoverride },
+ { STClazy, TOKlazy },
+ { STCalias, TOKalias },
+ { STCout, TOKout },
+ { STCin, TOKin },
#if DMDV2
- { STCimmutable, TOKimmutable },
- { STCshared, TOKshared },
- { STCnothrow, TOKnothrow },
- { STCpure, TOKpure },
- { STCref, TOKref },
- { STCtls, TOKtls },
- { STCgshared, TOKgshared },
- { STCproperty, TOKat },
- { STCsafe, TOKat },
- { STCtrusted, TOKat },
- { STCdisable, TOKat },
+ { STCimmutable, TOKimmutable },
+ { STCshared, TOKshared },
+ { STCnothrow, TOKnothrow },
+ { STCpure, TOKpure },
+ { STCref, TOKref },
+ { STCtls, TOKtls },
+ { STCgshared, TOKgshared },
+ { STCproperty, TOKat },
+ { STCsafe, TOKat },
+ { STCtrusted, TOKat },
+ { STCdisable, TOKat },
#endif
};
for (int i = 0; i < sizeof(table)/sizeof(table[0]); i++)
{
- if (stc & table[i].stc)
- {
- buf->writestring(Token::toChars(table[i].tok));
- buf->writeByte(' ');
- }
+ if (stc & table[i].stc)
+ {
+ buf->writestring(Token::toChars(table[i].tok));
+ buf->writeByte(' ');
+ }
}
}
@@ -483,7 +483,7 @@ void StorageClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* LinkDeclaration ****************************/
LinkDeclaration::LinkDeclaration(enum LINK p, Array *decl)
- : AttribDeclaration(decl)
+ : AttribDeclaration(decl)
{
//printf("LinkDeclaration(linkage = %d, decl = %p)\n", p, decl);
linkage = p;
@@ -503,7 +503,7 @@ void LinkDeclaration::setScope(Scope *sc)
//printf("LinkDeclaration::setScope(linkage = %d, decl = %p)\n", linkage, decl);
if (decl)
{
- setScopeNewSc(sc, sc->stc, linkage, sc->protection, sc->explicitProtection, sc->structalign);
+ setScopeNewSc(sc, sc->stc, linkage, sc->protection, sc->explicitProtection, sc->structalign);
}
}
@@ -512,7 +512,7 @@ void LinkDeclaration::semantic(Scope *sc)
//printf("LinkDeclaration::semantic(linkage = %d, decl = %p)\n", linkage, decl);
if (decl)
{
- semanticNewSc(sc, sc->stc, linkage, sc->protection, sc->explicitProtection, sc->structalign);
+ semanticNewSc(sc, sc->stc, linkage, sc->protection, sc->explicitProtection, sc->structalign);
}
}
@@ -520,20 +520,20 @@ void LinkDeclaration::semantic3(Scope *sc)
{
//printf("LinkDeclaration::semantic3(linkage = %d, decl = %p)\n", linkage, decl);
if (decl)
- { enum LINK linkage_save = sc->linkage;
+ { enum LINK linkage_save = sc->linkage;
- sc->linkage = linkage;
- for (unsigned i = 0; i < decl->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ sc->linkage = linkage;
+ for (unsigned i = 0; i < decl->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)decl->data[i];
- s->semantic3(sc);
- }
- sc->linkage = linkage_save;
+ s->semantic3(sc);
+ }
+ sc->linkage = linkage_save;
}
else
{
- sc->linkage = linkage;
+ sc->linkage = linkage;
}
}
@@ -542,18 +542,18 @@ void LinkDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
switch (linkage)
{
- case LINKd: p = "D"; break;
- case LINKc: p = "C"; break;
- case LINKcpp: p = "C++"; break;
- case LINKwindows: p = "Windows"; break;
- case LINKpascal: p = "Pascal"; break;
+ case LINKd: p = "D"; break;
+ case LINKc: p = "C"; break;
+ case LINKcpp: p = "C++"; break;
+ case LINKwindows: p = "Windows"; break;
+ case LINKpascal: p = "Pascal"; break;
// LDC
case LINKintrinsic: p = "Intrinsic"; break;
- default:
- assert(0);
- break;
+ default:
+ assert(0);
+ break;
}
buf->writestring("extern (");
buf->writestring(p);
@@ -569,7 +569,7 @@ char *LinkDeclaration::toChars()
/********************************* ProtDeclaration ****************************/
ProtDeclaration::ProtDeclaration(enum PROT p, Array *decl)
- : AttribDeclaration(decl)
+ : AttribDeclaration(decl)
{
protection = p;
//printf("decl = %p\n", decl);
@@ -588,7 +588,7 @@ void ProtDeclaration::setScope(Scope *sc)
{
if (decl)
{
- setScopeNewSc(sc, sc->stc, sc->linkage, protection, 1, sc->structalign);
+ setScopeNewSc(sc, sc->stc, sc->linkage, protection, 1, sc->structalign);
}
}
@@ -619,7 +619,7 @@ void ProtDeclaration::semantic(Scope *sc)
{
if (decl)
{
- semanticNewSc(sc, sc->stc, sc->linkage, protection, 1, sc->structalign);
+ semanticNewSc(sc, sc->stc, sc->linkage, protection, 1, sc->structalign);
}
}
@@ -629,14 +629,14 @@ void ProtDeclaration::protectionToCBuffer(OutBuffer *buf, enum PROT protection)
switch (protection)
{
- case PROTprivate: p = "private"; break;
- case PROTpackage: p = "package"; break;
- case PROTprotected: p = "protected"; break;
- case PROTpublic: p = "public"; break;
- case PROTexport: p = "export"; break;
- default:
- assert(0);
- break;
+ case PROTprivate: p = "private"; break;
+ case PROTpackage: p = "package"; break;
+ case PROTprotected: p = "protected"; break;
+ case PROTpublic: p = "public"; break;
+ case PROTexport: p = "export"; break;
+ default:
+ assert(0);
+ break;
}
buf->writestring(p);
buf->writeByte(' ');
@@ -651,7 +651,7 @@ void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* AlignDeclaration ****************************/
AlignDeclaration::AlignDeclaration(Loc loc, unsigned sa, Array *decl)
- : AttribDeclaration(decl)
+ : AttribDeclaration(decl)
{
this->loc = loc;
salign = sa;
@@ -671,7 +671,7 @@ void AlignDeclaration::setScope(Scope *sc)
//printf("\tAlignDeclaration::setScope '%s'\n",toChars());
if (decl)
{
- setScopeNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign);
+ setScopeNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign);
}
}
@@ -681,7 +681,7 @@ void AlignDeclaration::semantic(Scope *sc)
// we only support packed structs, as from the spec: align(1) struct Packed { ... }
// other alignments are simply ignored. my tests show this is what llvm-gcc does too ...
{
- semanticNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign);
+ semanticNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign);
}
}
@@ -695,7 +695,7 @@ void AlignDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* AnonDeclaration ****************************/
AnonDeclaration::AnonDeclaration(Loc loc, int isunion, Array *decl)
- : AttribDeclaration(decl)
+ : AttribDeclaration(decl)
{
this->loc = loc;
this->isunion = isunion;
@@ -718,8 +718,8 @@ void AnonDeclaration::semantic(Scope *sc)
Scope *scx = NULL;
if (scope)
{ sc = scope;
- scx = scope;
- scope = NULL;
+ scx = scope;
+ scope = NULL;
}
unsigned dprogress_save = Module::dprogress;
@@ -731,118 +731,118 @@ void AnonDeclaration::semantic(Scope *sc)
if (!ad || (!ad->isStructDeclaration() && !ad->isClassDeclaration()))
{
- error("can only be a part of an aggregate");
- return;
+ error("can only be a part of an aggregate");
+ return;
}
if (decl)
{
- AnonymousAggregateDeclaration aad;
- int adisunion;
+ AnonymousAggregateDeclaration aad;
+ int adisunion;
- if (sc->anonAgg)
- { ad = sc->anonAgg;
- adisunion = sc->inunion;
- }
- else
- adisunion = ad->isUnionDeclaration() != NULL;
+ if (sc->anonAgg)
+ { ad = sc->anonAgg;
+ adisunion = sc->inunion;
+ }
+ else
+ adisunion = ad->isUnionDeclaration() != NULL;
-// printf("\tsc->anonAgg = %p\n", sc->anonAgg);
-// printf("\tad = %p\n", ad);
-// printf("\taad = %p\n", &aad);
+// printf("\tsc->anonAgg = %p\n", sc->anonAgg);
+// printf("\tad = %p\n", ad);
+// printf("\taad = %p\n", &aad);
- sc = sc->push();
- sc->anonAgg = &aad;
- sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCgshared);
- sc->inunion = isunion;
- sc->offset = 0;
- sc->flags = 0;
- aad.structalign = sc->structalign;
- aad.parent = ad;
+ sc = sc->push();
+ sc->anonAgg = &aad;
+ sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCgshared);
+ sc->inunion = isunion;
+ sc->offset = 0;
+ sc->flags = 0;
+ aad.structalign = sc->structalign;
+ aad.parent = ad;
- for (unsigned i = 0; i < decl->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ for (unsigned i = 0; i < decl->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)decl->data[i];
- s->semantic(sc);
- if (isunion)
- sc->offset = 0;
- if (aad.sizeok == 2)
- {
- break;
- }
- }
- sc = sc->pop();
+ s->semantic(sc);
+ if (isunion)
+ sc->offset = 0;
+ if (aad.sizeok == 2)
+ {
+ break;
+ }
+ }
+ sc = sc->pop();
- // If failed due to forward references, unwind and try again later
- if (aad.sizeok == 2)
- {
- ad->sizeok = 2;
- //printf("\tsetting ad->sizeok %p to 2\n", ad);
- if (!sc->anonAgg)
- {
- scope = scx ? scx : new Scope(*sc);
- scope->setNoFree();
- scope->module->addDeferredSemantic(this);
- }
- Module::dprogress = dprogress_save;
- //printf("\tforward reference %p\n", this);
- return;
- }
- if (sem == 0)
- { Module::dprogress++;
- sem = 1;
- //printf("\tcompleted %p\n", this);
- }
- else
- ;//printf("\talready completed %p\n", this);
+ // If failed due to forward references, unwind and try again later
+ if (aad.sizeok == 2)
+ {
+ ad->sizeok = 2;
+ //printf("\tsetting ad->sizeok %p to 2\n", ad);
+ if (!sc->anonAgg)
+ {
+ scope = scx ? scx : new Scope(*sc);
+ scope->setNoFree();
+ scope->module->addDeferredSemantic(this);
+ }
+ Module::dprogress = dprogress_save;
+ //printf("\tforward reference %p\n", this);
+ return;
+ }
+ if (sem == 0)
+ { Module::dprogress++;
+ sem = 1;
+ //printf("\tcompleted %p\n", this);
+ }
+ else
+ ;//printf("\talready completed %p\n", this);
- // 0 sized structs are set to 1 byte
- if (aad.structsize == 0)
- {
- aad.structsize = 1;
- aad.alignsize = 1;
- }
+ // 0 sized structs are set to 1 byte
+ if (aad.structsize == 0)
+ {
+ aad.structsize = 1;
+ aad.alignsize = 1;
+ }
- // Align size of anonymous aggregate
+ // Align size of anonymous aggregate
//printf("aad.structalign = %d, aad.alignsize = %d, sc->offset = %d\n", aad.structalign, aad.alignsize, sc->offset);
- ad->alignmember(aad.structalign, aad.alignsize, &sc->offset);
- //ad->structsize = sc->offset;
+ ad->alignmember(aad.structalign, aad.alignsize, &sc->offset);
+ //ad->structsize = sc->offset;
//printf("sc->offset = %d\n", sc->offset);
- // Add members of aad to ad
- //printf("\tadding members of aad (%p) to '%s'\n", &aad, ad->toChars());
- for (unsigned i = 0; i < aad.fields.dim; i++)
- {
- VarDeclaration *v = (VarDeclaration *)aad.fields.data[i];
+ // Add members of aad to ad
+ //printf("\tadding members of aad (%p) to '%s'\n", &aad, ad->toChars());
+ for (unsigned i = 0; i < aad.fields.dim; i++)
+ {
+ VarDeclaration *v = (VarDeclaration *)aad.fields.data[i];
#if IN_LLVM
v->offset2 = sc->offset;
#endif
- v->offset += sc->offset;
+ v->offset += sc->offset;
#if IN_LLVM
if (!v->anonDecl)
v->anonDecl = this;
#endif
- ad->fields.push(v);
- }
+ ad->fields.push(v);
+ }
- // Add size of aad to ad
- if (adisunion)
- {
- if (aad.structsize > ad->structsize)
- ad->structsize = aad.structsize;
- sc->offset = 0;
- }
- else
- {
- ad->structsize = sc->offset + aad.structsize;
- sc->offset = ad->structsize;
- }
+ // Add size of aad to ad
+ if (adisunion)
+ {
+ if (aad.structsize > ad->structsize)
+ ad->structsize = aad.structsize;
+ sc->offset = 0;
+ }
+ else
+ {
+ ad->structsize = sc->offset + aad.structsize;
+ sc->offset = ad->structsize;
+ }
- if (ad->alignsize < aad.alignsize)
- ad->alignsize = aad.alignsize;
+ if (ad->alignsize < aad.alignsize)
+ ad->alignsize = aad.alignsize;
}
}
@@ -853,13 +853,13 @@ void AnonDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring("\n{\n");
if (decl)
{
- for (unsigned i = 0; i < decl->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ for (unsigned i = 0; i < decl->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)decl->data[i];
- //buf->writestring(" ");
- s->toCBuffer(buf, hgs);
- }
+ //buf->writestring(" ");
+ s->toCBuffer(buf, hgs);
+ }
}
buf->writestring("}\n");
}
@@ -886,7 +886,7 @@ static bool parseStringExp(Expression* e, std::string& res)
}
PragmaDeclaration::PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl)
- : AttribDeclaration(decl)
+ : AttribDeclaration(decl)
{
this->loc = loc;
this->ident = ident;
@@ -900,7 +900,7 @@ Dsymbol *PragmaDeclaration::syntaxCopy(Dsymbol *s)
assert(!s);
pd = new PragmaDeclaration(loc, ident,
- Expression::arraySyntaxCopy(args), Dsymbol::arraySyntaxCopy(decl));
+ Expression::arraySyntaxCopy(args), Dsymbol::arraySyntaxCopy(decl));
return pd;
}
@@ -949,103 +949,103 @@ void PragmaDeclaration::semantic(Scope *sc)
//printf("\tPragmaDeclaration::semantic '%s'\n",toChars());
if (ident == Id::msg)
{
- if (args)
- {
- for (size_t i = 0; i < args->dim; i++)
- {
- Expression *e = (Expression *)args->data[i];
+ if (args)
+ {
+ for (size_t i = 0; i < args->dim; i++)
+ {
+ Expression *e = (Expression *)args->data[i];
- e = e->semantic(sc);
- e = e->optimize(WANTvalue | WANTinterpret);
- if (e->op == TOKstring)
- {
- StringExp *se = (StringExp *)e;
- fprintf(stdmsg, "%.*s", (int)se->len, (char *)se->string);
- }
- else
- fprintf(stdmsg, e->toChars());
- }
- fprintf(stdmsg, "\n");
- }
- goto Lnodecl;
+ e = e->semantic(sc);
+ e = e->optimize(WANTvalue | WANTinterpret);
+ if (e->op == TOKstring)
+ {
+ StringExp *se = (StringExp *)e;
+ fprintf(stdmsg, "%.*s", (int)se->len, (char *)se->string);
+ }
+ else
+ fprintf(stdmsg, e->toChars());
+ }
+ fprintf(stdmsg, "\n");
+ }
+ goto Lnodecl;
}
else if (ident == Id::lib)
{
- if (!args || args->dim != 1)
- error("string expected for library name");
- else
- {
- Expression *e = (Expression *)args->data[0];
+ if (!args || args->dim != 1)
+ error("string expected for library name");
+ else
+ {
+ Expression *e = (Expression *)args->data[0];
- e = e->semantic(sc);
- e = e->optimize(WANTvalue | WANTinterpret);
- args->data[0] = (void *)e;
- if (e->op != TOKstring)
- error("string expected for library name, not '%s'", e->toChars());
- else if (global.params.verbose)
- {
- StringExp *se = (StringExp *)e;
- char *name = (char *)mem.malloc(se->len + 1);
- memcpy(name, se->string, se->len);
- name[se->len] = 0;
- printf("library %s\n", name);
- mem.free(name);
- }
- }
- goto Lnodecl;
+ e = e->semantic(sc);
+ e = e->optimize(WANTvalue | WANTinterpret);
+ args->data[0] = (void *)e;
+ if (e->op != TOKstring)
+ error("string expected for library name, not '%s'", e->toChars());
+ else if (global.params.verbose)
+ {
+ StringExp *se = (StringExp *)e;
+ char *name = (char *)mem.malloc(se->len + 1);
+ memcpy(name, se->string, se->len);
+ name[se->len] = 0;
+ printf("library %s\n", name);
+ mem.free(name);
+ }
+ }
+ goto Lnodecl;
}
#if IN_GCC
else if (ident == Id::GNU_asm)
{
- if (! args || args->dim != 2)
- error("identifier and string expected for asm name");
- else
- {
- Expression *e;
- Declaration *d = NULL;
- StringExp *s = NULL;
+ if (! args || args->dim != 2)
+ error("identifier and string expected for asm name");
+ else
+ {
+ Expression *e;
+ Declaration *d = NULL;
+ StringExp *s = NULL;
- e = (Expression *)args->data[0];
- e = e->semantic(sc);
- if (e->op == TOKvar)
- {
- d = ((VarExp *)e)->var;
- if (! d->isFuncDeclaration() && ! d->isVarDeclaration())
- d = NULL;
- }
- if (!d)
- error("first argument of GNU_asm must be a function or variable declaration");
+ e = (Expression *)args->data[0];
+ e = e->semantic(sc);
+ if (e->op == TOKvar)
+ {
+ d = ((VarExp *)e)->var;
+ if (! d->isFuncDeclaration() && ! d->isVarDeclaration())
+ d = NULL;
+ }
+ if (!d)
+ error("first argument of GNU_asm must be a function or variable declaration");
- e = (Expression *)args->data[1];
- e = e->semantic(sc);
- e = e->optimize(WANTvalue);
- if (e->op == TOKstring && ((StringExp *)e)->sz == 1)
- s = ((StringExp *)e);
- else
- error("second argument of GNU_asm must be a char string");
+ e = (Expression *)args->data[1];
+ e = e->semantic(sc);
+ e = e->optimize(WANTvalue);
+ if (e->op == TOKstring && ((StringExp *)e)->sz == 1)
+ s = ((StringExp *)e);
+ else
+ error("second argument of GNU_asm must be a char string");
- if (d && s)
- d->c_ident = Lexer::idPool((char*) s->string);
- }
- goto Lnodecl;
+ if (d && s)
+ d->c_ident = Lexer::idPool((char*) s->string);
+ }
+ goto Lnodecl;
}
#endif
#if DMDV2
else if (ident == Id::startaddress)
{
- if (!args || args->dim != 1)
- error("function name expected for start address");
- else
- {
- Expression *e = (Expression *)args->data[0];
- e = e->semantic(sc);
- e = e->optimize(WANTvalue | WANTinterpret);
- args->data[0] = (void *)e;
- Dsymbol *sa = getDsymbol(e);
- if (!sa || !sa->isFuncDeclaration())
- error("function name expected for start address, not '%s'", e->toChars());
- }
- goto Lnodecl;
+ if (!args || args->dim != 1)
+ error("function name expected for start address");
+ else
+ {
+ Expression *e = (Expression *)args->data[0];
+ e = e->semantic(sc);
+ e = e->optimize(WANTvalue | WANTinterpret);
+ args->data[0] = (void *)e;
+ Dsymbol *sa = getDsymbol(e);
+ if (!sa || !sa->isFuncDeclaration())
+ error("function name expected for start address, not '%s'", e->toChars());
+ }
+ goto Lnodecl;
}
#endif
#if TARGET_NET
@@ -1146,7 +1146,7 @@ void PragmaDeclaration::semantic(Scope *sc)
}
llvm_internal = LLVMva_arg;
}
-
+
// pragma(ldc, "string") { templdecl(s) }
else if (ident == Id::ldc)
{
@@ -1184,48 +1184,48 @@ void PragmaDeclaration::semantic(Scope *sc)
else if (ignoreUnsupportedPragmas)
{
- if (global.params.verbose)
- {
- /* Print unrecognized pragmas
- */
- printf("pragma %s", ident->toChars());
- if (args)
- {
- for (size_t i = 0; i < args->dim; i++)
- {
+ if (global.params.verbose)
+ {
+ /* Print unrecognized pragmas
+ */
+ printf("pragma %s", ident->toChars());
+ if (args)
+ {
+ for (size_t i = 0; i < args->dim; i++)
+ {
// ignore errors in ignored pragmas.
global.gag++;
unsigned errors_save = global.errors;
- Expression *e = (Expression *)args->data[i];
- e = e->semantic(sc);
- e = e->optimize(WANTvalue | WANTinterpret);
- if (i == 0)
- printf(" (");
- else
- printf(",");
- printf("%s", e->toChars());
+ Expression *e = (Expression *)args->data[i];
+ e = e->semantic(sc);
+ e = e->optimize(WANTvalue | WANTinterpret);
+ if (i == 0)
+ printf(" (");
+ else
+ printf(",");
+ printf("%s", e->toChars());
// restore error state.
global.gag--;
global.errors = errors_save;
- }
- if (args->dim)
- printf(")");
- }
- printf("\n");
- }
+ }
+ if (args->dim)
+ printf(")");
+ }
+ printf("\n");
+ }
}
else
- error("unrecognized pragma(%s)", ident->toChars());
+ error("unrecognized pragma(%s)", ident->toChars());
if (decl)
{
- for (unsigned i = 0; i < decl->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ for (unsigned i = 0; i < decl->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)decl->data[i];
- s->semantic(sc);
+ s->semantic(sc);
// LDC
#if IN_LLVM
@@ -1351,7 +1351,7 @@ void PragmaDeclaration::semantic(Scope *sc)
Lnodecl:
if (decl)
- error("pragma is missing closing ';'");
+ error("pragma is missing closing ';'");
}
int PragmaDeclaration::oneMember(Dsymbol **ps)
@@ -1370,42 +1370,42 @@ void PragmaDeclaration::toObjFile(int multiobj)
{
if (ident == Id::lib)
{
- assert(args && args->dim == 1);
+ assert(args && args->dim == 1);
- Expression *e = (Expression *)args->data[0];
+ Expression *e = (Expression *)args->data[0];
- assert(e->op == TOKstring);
+ assert(e->op == TOKstring);
- StringExp *se = (StringExp *)e;
- char *name = (char *)mem.malloc(se->len + 1);
- memcpy(name, se->string, se->len);
- name[se->len] = 0;
+ StringExp *se = (StringExp *)e;
+ char *name = (char *)mem.malloc(se->len + 1);
+ memcpy(name, se->string, se->len);
+ name[se->len] = 0;
#if OMFOBJ
- /* The OMF format allows library names to be inserted
- * into the object file. The linker will then automatically
- * search that library, too.
- */
- obj_includelib(name);
+ /* The OMF format allows library names to be inserted
+ * into the object file. The linker will then automatically
+ * search that library, too.
+ */
+ obj_includelib(name);
#elif ELFOBJ || MACHOBJ
- /* The format does not allow embedded library names,
- * so instead append the library name to the list to be passed
- * to the linker.
- */
- global.params.libfiles->push((void *) name);
+ /* The format does not allow embedded library names,
+ * so instead append the library name to the list to be passed
+ * to the linker.
+ */
+ global.params.libfiles->push((void *) name);
#else
- error("pragma lib not supported");
+ error("pragma lib not supported");
#endif
}
#if DMDV2
else if (ident == Id::startaddress)
{
- assert(args && args->dim == 1);
- Expression *e = (Expression *)args->data[0];
- Dsymbol *sa = getDsymbol(e);
- FuncDeclaration *f = sa->isFuncDeclaration();
- assert(f);
- Symbol *s = f->toSymbol();
- obj_startaddress(s);
+ assert(args && args->dim == 1);
+ Expression *e = (Expression *)args->data[0];
+ Dsymbol *sa = getDsymbol(e);
+ FuncDeclaration *f = sa->isFuncDeclaration();
+ assert(f);
+ Symbol *s = f->toSymbol();
+ obj_startaddress(s);
}
#endif
AttribDeclaration::toObjFile(multiobj);
@@ -1417,13 +1417,13 @@ void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->printf("pragma(%s", ident->toChars());
if (args)
{
- for (size_t i = 0; i < args->dim; i++)
- {
- Expression *e = (Expression *)args->data[i];
+ for (size_t i = 0; i < args->dim; i++)
+ {
+ Expression *e = (Expression *)args->data[i];
- buf->writestring(", ");
- e->toCBuffer(buf, hgs);
- }
+ buf->writestring(", ");
+ e->toCBuffer(buf, hgs);
+ }
}
buf->writeByte(')');
AttribDeclaration::toCBuffer(buf, hgs);
@@ -1433,7 +1433,7 @@ void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* ConditionalDeclaration ****************************/
ConditionalDeclaration::ConditionalDeclaration(Condition *condition, Array *decl, Array *elsedecl)
- : AttribDeclaration(decl)
+ : AttribDeclaration(decl)
{
//printf("ConditionalDeclaration::ConditionalDeclaration()\n");
this->condition = condition;
@@ -1446,8 +1446,8 @@ Dsymbol *ConditionalDeclaration::syntaxCopy(Dsymbol *s)
assert(!s);
dd = new ConditionalDeclaration(condition->syntaxCopy(),
- Dsymbol::arraySyntaxCopy(decl),
- Dsymbol::arraySyntaxCopy(elsedecl));
+ Dsymbol::arraySyntaxCopy(decl),
+ Dsymbol::arraySyntaxCopy(elsedecl));
return dd;
}
@@ -1457,8 +1457,8 @@ int ConditionalDeclaration::oneMember(Dsymbol **ps)
//printf("ConditionalDeclaration::oneMember(), inc = %d\n", condition->inc);
if (condition->inc)
{
- Array *d = condition->include(NULL, NULL) ? decl : elsedecl;
- return Dsymbol::oneMembers(d, ps);
+ Array *d = condition->include(NULL, NULL) ? decl : elsedecl;
+ return Dsymbol::oneMembers(d, ps);
}
*ps = NULL;
return TRUE;
@@ -1469,18 +1469,18 @@ void ConditionalDeclaration::emitComment(Scope *sc)
//printf("ConditionalDeclaration::emitComment(sc = %p)\n", sc);
if (condition->inc)
{
- AttribDeclaration::emitComment(sc);
+ AttribDeclaration::emitComment(sc);
}
else if (sc->docbuf)
{
- /* If generating doc comment, be careful because if we're inside
- * a template, then include(NULL, NULL) will fail.
- */
- Array *d = decl ? decl : elsedecl;
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- s->emitComment(sc);
- }
+ /* If generating doc comment, be careful because if we're inside
+ * a template, then include(NULL, NULL) will fail.
+ */
+ Array *d = decl ? decl : elsedecl;
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ s->emitComment(sc);
+ }
}
}
@@ -1535,22 +1535,22 @@ void ConditionalDeclaration::addComment(unsigned char *comment)
if (comment)
{
- Array *d = decl;
+ Array *d = decl;
- for (int j = 0; j < 2; j++)
- {
- if (d)
- {
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s;
+ for (int j = 0; j < 2; j++)
+ {
+ if (d)
+ {
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s;
- s = (Dsymbol *)d->data[i];
- //printf("ConditionalDeclaration::addComment %s\n", s->toChars());
- s->addComment(comment);
- }
- }
- d = elsedecl;
- }
+ s = (Dsymbol *)d->data[i];
+ //printf("ConditionalDeclaration::addComment %s\n", s->toChars());
+ s->addComment(comment);
+ }
+ }
+ d = elsedecl;
+ }
}
}
@@ -1559,47 +1559,47 @@ void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
condition->toCBuffer(buf, hgs);
if (decl || elsedecl)
{
- buf->writenl();
- buf->writeByte('{');
- buf->writenl();
- if (decl)
- {
- for (unsigned i = 0; i < decl->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ buf->writenl();
+ buf->writeByte('{');
+ buf->writenl();
+ if (decl)
+ {
+ for (unsigned i = 0; i < decl->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)decl->data[i];
- buf->writestring(" ");
- s->toCBuffer(buf, hgs);
- }
- }
- buf->writeByte('}');
- if (elsedecl)
- {
- buf->writenl();
- buf->writestring("else");
- buf->writenl();
- buf->writeByte('{');
- buf->writenl();
- for (unsigned i = 0; i < elsedecl->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)elsedecl->data[i];
+ buf->writestring(" ");
+ s->toCBuffer(buf, hgs);
+ }
+ }
+ buf->writeByte('}');
+ if (elsedecl)
+ {
+ buf->writenl();
+ buf->writestring("else");
+ buf->writenl();
+ buf->writeByte('{');
+ buf->writenl();
+ for (unsigned i = 0; i < elsedecl->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)elsedecl->data[i];
- buf->writestring(" ");
- s->toCBuffer(buf, hgs);
- }
- buf->writeByte('}');
- }
+ buf->writestring(" ");
+ s->toCBuffer(buf, hgs);
+ }
+ buf->writeByte('}');
+ }
}
else
- buf->writeByte(':');
+ buf->writeByte(':');
buf->writenl();
}
/***************************** StaticIfDeclaration ****************************/
StaticIfDeclaration::StaticIfDeclaration(Condition *condition,
- Array *decl, Array *elsedecl)
- : ConditionalDeclaration(condition, decl, elsedecl)
+ Array *decl, Array *elsedecl)
+ : ConditionalDeclaration(condition, decl, elsedecl)
{
//printf("StaticIfDeclaration::StaticIfDeclaration()\n");
sd = NULL;
@@ -1613,8 +1613,8 @@ Dsymbol *StaticIfDeclaration::syntaxCopy(Dsymbol *s)
assert(!s);
dd = new StaticIfDeclaration(condition->syntaxCopy(),
- Dsymbol::arraySyntaxCopy(decl),
- Dsymbol::arraySyntaxCopy(elsedecl));
+ Dsymbol::arraySyntaxCopy(decl),
+ Dsymbol::arraySyntaxCopy(elsedecl));
return dd;
}
@@ -1637,8 +1637,8 @@ int StaticIfDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
int m = 0;
if (memnum == 0)
- { m = AttribDeclaration::addMember(sc, sd, memnum);
- addisdone = 1;
+ { m = AttribDeclaration::addMember(sc, sd, memnum);
+ addisdone = 1;
}
return m;
}
@@ -1661,17 +1661,17 @@ void StaticIfDeclaration::semantic(Scope *sc)
//printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d);
if (d)
{
- if (!addisdone)
- { AttribDeclaration::addMember(sc, sd, 1);
- addisdone = 1;
- }
+ if (!addisdone)
+ { AttribDeclaration::addMember(sc, sd, 1);
+ addisdone = 1;
+ }
- for (unsigned i = 0; i < d->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)d->data[i];
+ for (unsigned i = 0; i < d->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)d->data[i];
- s->semantic(sc);
- }
+ s->semantic(sc);
+ }
}
}
@@ -1705,11 +1705,11 @@ int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
//printf("CompileDeclaration::addMember(sc = %p, memnum = %d)\n", sc, memnum);
this->sd = sd;
if (memnum == 0)
- { /* No members yet, so parse the mixin now
- */
- compileIt(sc);
- memnum |= AttribDeclaration::addMember(sc, sd, memnum);
- compiled = 1;
+ { /* No members yet, so parse the mixin now
+ */
+ compileIt(sc);
+ memnum |= AttribDeclaration::addMember(sc, sd, memnum);
+ compiled = 1;
}
return memnum;
}
@@ -1721,18 +1721,18 @@ void CompileDeclaration::compileIt(Scope *sc)
exp = resolveProperties(sc, exp);
exp = exp->optimize(WANTvalue | WANTinterpret);
if (exp->op != TOKstring)
- { exp->error("argument to mixin must be a string, not (%s)", exp->toChars());
+ { exp->error("argument to mixin must be a string, not (%s)", exp->toChars());
}
else
{
- StringExp *se = (StringExp *)exp;
- se = se->toUTF8(sc);
- Parser p(sc->module, (unsigned char *)se->string, se->len, 0);
- p.loc = loc;
- p.nextToken();
- decl = p.parseDeclDefs(0);
- if (p.token.value != TOKeof)
- exp->error("incomplete mixin declaration (%s)", se->toChars());
+ StringExp *se = (StringExp *)exp;
+ se = se->toUTF8(sc);
+ Parser p(sc->module, (unsigned char *)se->string, se->len, 0);
+ p.loc = loc;
+ p.nextToken();
+ decl = p.parseDeclDefs(0);
+ if (p.token.value != TOKeof)
+ exp->error("incomplete mixin declaration (%s)", se->toChars());
}
}
@@ -1742,9 +1742,9 @@ void CompileDeclaration::semantic(Scope *sc)
if (!compiled)
{
- compileIt(sc);
- AttribDeclaration::addMember(sc, sd, 0);
- compiled = 1;
+ compileIt(sc);
+ AttribDeclaration::addMember(sc, sd, 0);
+ compiled = 1;
}
AttribDeclaration::semantic(sc);
}
diff --git a/dmd/attrib.h b/dmd/attrib.h
index 6b7f43b8..365a0936 100644
--- a/dmd/attrib.h
+++ b/dmd/attrib.h
@@ -31,17 +31,17 @@ struct HdrGenState;
struct AttribDeclaration : Dsymbol
{
- Array *decl; // array of Dsymbol's
+ 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 setScopeNewSc(Scope *sc,
- StorageClass newstc, enum LINK linkage, enum PROT protection, int explictProtection,
- unsigned structalign);
+ StorageClass newstc, enum LINK linkage, enum PROT protection, int explictProtection,
+ unsigned structalign);
void semanticNewSc(Scope *sc,
- StorageClass newstc, enum LINK linkage, enum PROT protection, int explictProtection,
- unsigned structalign);
+ StorageClass newstc, enum LINK linkage, enum PROT protection, int explictProtection,
+ unsigned structalign);
void semantic(Scope *sc);
void semantic2(Scope *sc);
void semantic3(Scope *sc);
@@ -58,7 +58,7 @@ struct AttribDeclaration : Dsymbol
AttribDeclaration *isAttribDeclaration() { return this; }
#if IN_DMD
- virtual void toObjFile(int multiobj); // compile to .obj file
+ virtual void toObjFile(int multiobj); // compile to .obj file
int cvMember(unsigned char *p);
#endif
@@ -121,7 +121,7 @@ struct AlignDeclaration : AttribDeclaration
struct AnonDeclaration : AttribDeclaration
{
int isunion;
- int sem; // 1 if successful semantic()
+ int sem; // 1 if successful semantic()
AnonDeclaration(Loc loc, int isunion, Array *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
@@ -132,7 +132,7 @@ struct AnonDeclaration : AttribDeclaration
struct PragmaDeclaration : AttribDeclaration
{
- Expressions *args; // array of Expression's
+ Expressions *args; // array of Expression's
PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
@@ -143,7 +143,7 @@ struct PragmaDeclaration : AttribDeclaration
const char *kind();
#if IN_DMD
- void toObjFile(int multiobj); // compile to .obj file
+ void toObjFile(int multiobj); // compile to .obj file
#endif
#if IN_LLVM
@@ -154,7 +154,7 @@ struct PragmaDeclaration : AttribDeclaration
struct ConditionalDeclaration : AttribDeclaration
{
Condition *condition;
- Array *elsedecl; // array of Dsymbol's for else block
+ Array *elsedecl; // array of Dsymbol's for else block
ConditionalDeclaration(Condition *condition, Array *decl, Array *elsedecl);
Dsymbol *syntaxCopy(Dsymbol *s);
diff --git a/dmd/cast.c b/dmd/cast.c
index d6b87822..6b187326 100644
--- a/dmd/cast.c
+++ b/dmd/cast.c
@@ -29,50 +29,50 @@ Expression *Expression::implicitCastTo(Scope *sc, Type *t)
{
//printf("implicitCastTo(%s) => %s\n", type->toChars(), t->toChars());
if (implicitConvTo(t))
- { TY tyfrom = type->toBasetype()->ty;
- TY tyto = t->toBasetype()->ty;
- if (global.params.warnings &&
- Type::impcnvWarn[tyfrom][tyto] &&
- op != TOKint64)
- {
- Expression *e = optimize(WANTflags | WANTvalue);
+ { TY tyfrom = type->toBasetype()->ty;
+ TY tyto = t->toBasetype()->ty;
+ if (global.params.warnings &&
+ Type::impcnvWarn[tyfrom][tyto] &&
+ op != TOKint64)
+ {
+ Expression *e = optimize(WANTflags | WANTvalue);
- if (e->op == TOKint64)
- return e->implicitCastTo(sc, t);
+ if (e->op == TOKint64)
+ return e->implicitCastTo(sc, t);
- if (tyfrom == Tint32 &&
- (op == TOKadd || op == TOKmin ||
- op == TOKand || op == TOKor || op == TOKxor)
- )
- {
- /* This is really only a semi-kludge fix,
- * we really should look at the operands of op
- * and see if they are narrower types.
- * For example, b=b|b and b=b|7 and s=b+b should be allowed,
- * but b=b|i should be an error.
- */
- ;
- }
- else
- {
- warning("implicit conversion of expression (%s) of type %s to %s can cause loss of data",
- toChars(), type->toChars(), t->toChars());
- }
- }
+ if (tyfrom == Tint32 &&
+ (op == TOKadd || op == TOKmin ||
+ op == TOKand || op == TOKor || op == TOKxor)
+ )
+ {
+ /* This is really only a semi-kludge fix,
+ * we really should look at the operands of op
+ * and see if they are narrower types.
+ * For example, b=b|b and b=b|7 and s=b+b should be allowed,
+ * but b=b|i should be an error.
+ */
+ ;
+ }
+ else
+ {
+ warning("implicit conversion of expression (%s) of type %s to %s can cause loss of data",
+ toChars(), type->toChars(), t->toChars());
+ }
+ }
#if DMDV2
- if (match == MATCHconst && t == type->constOf())
- {
- Expression *e = copy();
- e->type = t;
- return e;
- }
+ if (match == MATCHconst && t == type->constOf())
+ {
+ Expression *e = copy();
+ e->type = t;
+ return e;
+ }
#endif
- return castTo(sc, t);
+ return castTo(sc, t);
}
Expression *e = optimize(WANTflags | WANTvalue);
if (e != this)
- return e->implicitCastTo(sc, t);
+ return e->implicitCastTo(sc, t);
#if 0
printf("ty = %d\n", type->ty);
@@ -85,21 +85,21 @@ printf("%p %p type: %s to: %s\n", type->deco, t->deco, type->deco, t->deco);
fflush(stdout);
#endif
if (!t->deco)
- { /* Can happen with:
- * enum E { One }
- * class A
- * { static void fork(EDG dg) { dg(E.One); }
- * alias void delegate(E) EDG;
- * }
- * Should eventually make it work.
- */
- error("forward reference to type %s", t->toChars());
+ { /* Can happen with:
+ * enum E { One }
+ * class A
+ * { static void fork(EDG dg) { dg(E.One); }
+ * alias void delegate(E) EDG;
+ * }
+ * Should eventually make it work.
+ */
+ error("forward reference to type %s", t->toChars());
}
else if (t->reliesOnTident())
- error("forward reference to type %s", t->reliesOnTident()->toChars());
+ error("forward reference to type %s", t->reliesOnTident()->toChars());
error("cannot implicitly convert expression (%s) of type %s to %s",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
return castTo(sc, t);
}
@@ -112,39 +112,39 @@ MATCH Expression::implicitConvTo(Type *t)
{
#if 0
printf("Expression::implicitConvTo(this=%s, type=%s, t=%s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
//static int nest; if (++nest == 10) halt();
if (!type)
- { error("%s is not an expression", toChars());
- type = Type::terror;
+ { error("%s is not an expression", toChars());
+ type = Type::terror;
}
if (t->ty == Tbit && isBit())
- return MATCHconvert;
+ return MATCHconvert;
Expression *e = optimize(WANTvalue | WANTflags);
if (e != this)
- { //printf("optimzed to %s\n", e->toChars());
- return e->implicitConvTo(t);
+ { //printf("optimzed to %s\n", e->toChars());
+ return e->implicitConvTo(t);
}
MATCH match = type->implicitConvTo(t);
if (match)
- return match;
+ return match;
#if 0
Type *tb = t->toBasetype();
if (tb->ty == Tdelegate)
- { TypeDelegate *td = (TypeDelegate *)tb;
- TypeFunction *tf = (TypeFunction *)td->nextOf();
+ { TypeDelegate *td = (TypeDelegate *)tb;
+ TypeFunction *tf = (TypeFunction *)td->nextOf();
- if (!tf->varargs &&
- !(tf->arguments && tf->arguments->dim)
- )
- {
- match = type->implicitConvTo(tf->nextOf());
- if (match)
- return match;
- if (tf->nextOf()->toBasetype()->ty == Tvoid)
- return MATCHconvert;
- }
+ if (!tf->varargs &&
+ !(tf->arguments && tf->arguments->dim)
+ )
+ {
+ match = type->implicitConvTo(tf->nextOf());
+ if (match)
+ return match;
+ if (tf->nextOf()->toBasetype()->ty == Tvoid)
+ return MATCHconvert;
+ }
}
#endif
return MATCHnomatch;
@@ -155,173 +155,173 @@ MATCH IntegerExp::implicitConvTo(Type *t)
{
#if 0
printf("IntegerExp::implicitConvTo(this=%s, type=%s, t=%s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
if (type->equals(t))
- return MATCHexact;
+ return MATCHexact;
enum TY ty = type->toBasetype()->ty;
enum TY toty = t->toBasetype()->ty;
if (type->implicitConvTo(t) == MATCHnomatch && t->ty == Tenum)
{
- return MATCHnomatch;
+ return MATCHnomatch;
}
switch (ty)
{
- case Tbit:
- case Tbool:
- value &= 1;
- ty = Tint32;
- break;
+ case Tbit:
+ case Tbool:
+ value &= 1;
+ ty = Tint32;
+ break;
- case Tint8:
- value = (signed char)value;
- ty = Tint32;
- break;
+ case Tint8:
+ value = (signed char)value;
+ ty = Tint32;
+ break;
- case Tchar:
- case Tuns8:
- value &= 0xFF;
- ty = Tint32;
- break;
+ case Tchar:
+ case Tuns8:
+ value &= 0xFF;
+ ty = Tint32;
+ break;
- case Tint16:
- value = (short)value;
- ty = Tint32;
- break;
+ case Tint16:
+ value = (short)value;
+ ty = Tint32;
+ break;
- case Tuns16:
- case Twchar:
- value &= 0xFFFF;
- ty = Tint32;
- break;
+ case Tuns16:
+ case Twchar:
+ value &= 0xFFFF;
+ ty = Tint32;
+ break;
- case Tint32:
- value = (int)value;
- break;
+ case Tint32:
+ value = (int)value;
+ break;
- case Tuns32:
- case Tdchar:
- value &= 0xFFFFFFFF;
- ty = Tuns32;
- break;
+ case Tuns32:
+ case Tdchar:
+ value &= 0xFFFFFFFF;
+ ty = Tuns32;
+ break;
- default:
- break;
+ default:
+ break;
}
// Only allow conversion if no change in value
switch (toty)
{
- case Tbit:
- case Tbool:
- if ((value & 1) != value)
- goto Lno;
- goto Lyes;
+ case Tbit:
+ case Tbool:
+ if ((value & 1) != value)
+ goto Lno;
+ goto Lyes;
- case Tint8:
- if ((signed char)value != value)
- goto Lno;
- goto Lyes;
+ case Tint8:
+ if ((signed char)value != value)
+ goto Lno;
+ goto Lyes;
- case Tchar:
- case Tuns8:
- //printf("value = %llu %llu\n", (dinteger_t)(unsigned char)value, value);
- if ((unsigned char)value != value)
- goto Lno;
- goto Lyes;
+ case Tchar:
+ case Tuns8:
+ //printf("value = %llu %llu\n", (dinteger_t)(unsigned char)value, value);
+ if ((unsigned char)value != value)
+ goto Lno;
+ goto Lyes;
- case Tint16:
- if ((short)value != value)
- goto Lno;
- goto Lyes;
+ case Tint16:
+ if ((short)value != value)
+ goto Lno;
+ goto Lyes;
- case Tuns16:
- if ((unsigned short)value != value)
- goto Lno;
- goto Lyes;
+ case Tuns16:
+ if ((unsigned short)value != value)
+ goto Lno;
+ goto Lyes;
- case Tint32:
- if (ty == Tuns32)
- {
- }
- else if ((int)value != value)
- goto Lno;
- goto Lyes;
+ case Tint32:
+ if (ty == Tuns32)
+ {
+ }
+ else if ((int)value != value)
+ goto Lno;
+ goto Lyes;
- case Tuns32:
- if (ty == Tint32)
- {
- }
- else if ((unsigned)value != value)
- goto Lno;
- goto Lyes;
+ case Tuns32:
+ if (ty == Tint32)
+ {
+ }
+ else if ((unsigned)value != value)
+ goto Lno;
+ goto Lyes;
- case Tdchar:
- if (value > 0x10FFFFUL)
- goto Lno;
- goto Lyes;
+ case Tdchar:
+ if (value > 0x10FFFFUL)
+ goto Lno;
+ goto Lyes;
- case Twchar:
- if ((unsigned short)value != value)
- goto Lno;
- goto Lyes;
+ case Twchar:
+ if ((unsigned short)value != value)
+ goto Lno;
+ goto Lyes;
- case Tfloat32:
- {
- volatile float f;
- if (type->isunsigned())
- {
- f = (float)value;
- if (f != value)
- goto Lno;
- }
- else
- {
- f = (float)(long long)value;
- if (f != (long long)value)
- goto Lno;
- }
- goto Lyes;
- }
+ case Tfloat32:
+ {
+ volatile float f;
+ if (type->isunsigned())
+ {
+ f = (float)value;
+ if (f != value)
+ goto Lno;
+ }
+ else
+ {
+ f = (float)(long long)value;
+ if (f != (long long)value)
+ goto Lno;
+ }
+ goto Lyes;
+ }
- case Tfloat64:
- {
- volatile double f;
- if (type->isunsigned())
- {
- f = (double)value;
- if (f != value)
- goto Lno;
- }
- else
- {
- f = (double)(long long)value;
- if (f != (long long)value)
- goto Lno;
- }
- goto Lyes;
- }
+ case Tfloat64:
+ {
+ volatile double f;
+ if (type->isunsigned())
+ {
+ f = (double)value;
+ if (f != value)
+ goto Lno;
+ }
+ else
+ {
+ f = (double)(long long)value;
+ if (f != (long long)value)
+ goto Lno;
+ }
+ goto Lyes;
+ }
- case Tfloat80:
- {
- volatile long double f;
- if (type->isunsigned())
- {
- f = (long double)value;
- if (f != value)
- goto Lno;
- }
- else
- {
- f = (long double)(long long)value;
- if (f != (long long)value)
- goto Lno;
- }
- goto Lyes;
- }
+ case Tfloat80:
+ {
+ volatile long double f;
+ if (type->isunsigned())
+ {
+ f = (long double)value;
+ if (f != value)
+ goto Lno;
+ }
+ else
+ {
+ f = (long double)(long long)value;
+ if (f != (long long)value)
+ goto Lno;
+ }
+ goto Lyes;
+ }
}
return Expression::implicitConvTo(t);
@@ -338,19 +338,19 @@ MATCH NullExp::implicitConvTo(Type *t)
{
#if 0
printf("NullExp::implicitConvTo(this=%s, type=%s, t=%s, committed = %d)\n",
- toChars(), type->toChars(), t->toChars(), committed);
+ toChars(), type->toChars(), t->toChars(), committed);
#endif
if (this->type->equals(t))
- return MATCHexact;
+ return MATCHexact;
// NULL implicitly converts to any pointer type or dynamic array
if (type->ty == Tpointer && type->next->ty == Tvoid)
{
- if (t->ty == Ttypedef)
- t = ((TypeTypedef *)t)->sym->basetype;
- if (t->ty == Tpointer || t->ty == Tarray ||
- t->ty == Taarray || t->ty == Tclass ||
- t->ty == Tdelegate)
- return committed ? MATCHconvert : MATCHexact;
+ if (t->ty == Ttypedef)
+ t = ((TypeTypedef *)t)->sym->basetype;
+ if (t->ty == Tpointer || t->ty == Tarray ||
+ t->ty == Taarray || t->ty == Tclass ||
+ t->ty == Tdelegate)
+ return committed ? MATCHconvert : MATCHexact;
}
return Expression::implicitConvTo(t);
}
@@ -360,29 +360,29 @@ MATCH StructLiteralExp::implicitConvTo(Type *t)
{
#if 0
printf("StructLiteralExp::implicitConvTo(this=%s, type=%s, t=%s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
MATCH m = Expression::implicitConvTo(t);
if (m != MATCHnomatch)
- return m;
+ return m;
if (type->ty == t->ty && type->ty == Tstruct &&
- ((TypeStruct *)type)->sym == ((TypeStruct *)t)->sym)
+ ((TypeStruct *)type)->sym == ((TypeStruct *)t)->sym)
{
- m = MATCHconst;
- for (int i = 0; i < elements->dim; i++)
- { Expression *e = (Expression *)elements->data[i];
- Type *te = e->type;
- if (t->mod == 0)
- te = te->mutableOf();
- else
- { assert(t->mod == MODimmutable);
- te = te->invariantOf();
- }
- MATCH m2 = e->implicitConvTo(te);
- //printf("\t%s => %s, match = %d\n", e->toChars(), te->toChars(), m2);
- if (m2 < m)
- m = m2;
- }
+ m = MATCHconst;
+ for (int i = 0; i < elements->dim; i++)
+ { Expression *e = (Expression *)elements->data[i];
+ Type *te = e->type;
+ if (t->mod == 0)
+ te = te->mutableOf();
+ else
+ { assert(t->mod == MODimmutable);
+ te = te->invariantOf();
+ }
+ MATCH m2 = e->implicitConvTo(te);
+ //printf("\t%s => %s, match = %d\n", e->toChars(), te->toChars(), m2);
+ if (m2 < m)
+ m = m2;
+ }
}
return m;
}
@@ -393,39 +393,39 @@ MATCH StringExp::implicitConvTo(Type *t)
#if 0
printf("StringExp::implicitConvTo(this=%s, committed=%d, type=%s, t=%s)\n",
- toChars(), committed, type->toChars(), t->toChars());
+ toChars(), committed, type->toChars(), t->toChars());
#endif
if (!committed)
{
if (!committed && t->ty == Tpointer && t->next->ty == Tvoid)
{
- return MATCHnomatch;
+ return MATCHnomatch;
}
if (type->ty == Tsarray || type->ty == Tarray || type->ty == Tpointer)
{
- if (type->next->ty == Tchar)
- {
- switch (t->ty)
- {
- case Tsarray:
- if (type->ty == Tsarray &&
- ((TypeSArray *)type)->dim->toInteger() !=
- ((TypeSArray *)t)->dim->toInteger())
- return MATCHnomatch;
- goto L1;
- case Tarray:
- goto L1;
- case Tpointer:
- L1:
- if (t->next->ty == Tchar)
- return MATCHexact;
- else if (t->next->ty == Twchar)
- return MATCHexact;
- else if (t->next->ty == Tdchar)
- return MATCHexact;
- break;
- }
- }
+ if (type->next->ty == Tchar)
+ {
+ switch (t->ty)
+ {
+ case Tsarray:
+ if (type->ty == Tsarray &&
+ ((TypeSArray *)type)->dim->toInteger() !=
+ ((TypeSArray *)t)->dim->toInteger())
+ return MATCHnomatch;
+ goto L1;
+ case Tarray:
+ goto L1;
+ case Tpointer:
+ L1:
+ if (t->next->ty == Tchar)
+ return MATCHexact;
+ else if (t->next->ty == Twchar)
+ return MATCHexact;
+ else if (t->next->ty == Tdchar)
+ return MATCHexact;
+ break;
+ }
+ }
}
}
return Expression::implicitConvTo(t);
@@ -433,7 +433,7 @@ MATCH StringExp::implicitConvTo(Type *t)
m = (MATCH)type->implicitConvTo(t);
if (m)
{
- return m;
+ return m;
}
return MATCHnomatch;
@@ -445,31 +445,31 @@ MATCH ArrayLiteralExp::implicitConvTo(Type *t)
#if 0
printf("ArrayLiteralExp::implicitConvTo(this=%s, type=%s, t=%s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
Type *typeb = type->toBasetype();
Type *tb = t->toBasetype();
if ((tb->ty == Tarray || tb->ty == Tsarray) &&
- (typeb->ty == Tarray || typeb->ty == Tsarray))
+ (typeb->ty == Tarray || typeb->ty == Tsarray))
{
- if (tb->ty == Tsarray)
- { TypeSArray *tsa = (TypeSArray *)tb;
- if (elements->dim != tsa->dim->toInteger())
- result = MATCHnomatch;
- }
+ if (tb->ty == Tsarray)
+ { TypeSArray *tsa = (TypeSArray *)tb;
+ if (elements->dim != tsa->dim->toInteger())
+ result = MATCHnomatch;
+ }
- for (int i = 0; i < elements->dim; i++)
- { Expression *e = (Expression *)elements->data[i];
- MATCH m = (MATCH)e->implicitConvTo(tb->nextOf());
- if (m < result)
- result = m; // remember worst match
- if (result == MATCHnomatch)
- break; // no need to check for worse
- }
- return result;
+ for (int i = 0; i < elements->dim; i++)
+ { Expression *e = (Expression *)elements->data[i];
+ MATCH m = (MATCH)e->implicitConvTo(tb->nextOf());
+ if (m < result)
+ result = m; // remember worst match
+ if (result == MATCHnomatch)
+ break; // no need to check for worse
+ }
+ return result;
}
else
- return Expression::implicitConvTo(t);
+ return Expression::implicitConvTo(t);
}
MATCH AssocArrayLiteralExp::implicitConvTo(Type *t)
@@ -479,31 +479,31 @@ MATCH AssocArrayLiteralExp::implicitConvTo(Type *t)
Type *tb = t->toBasetype();
if (tb->ty == Taarray && typeb->ty == Taarray)
{
- for (size_t i = 0; i < keys->dim; i++)
- { Expression *e = (Expression *)keys->data[i];
- MATCH m = (MATCH)e->implicitConvTo(((TypeAArray *)tb)->key);
- if (m < result)
- result = m; // remember worst match
- if (result == MATCHnomatch)
- break; // no need to check for worse
- e = (Expression *)values->data[i];
- m = (MATCH)e->implicitConvTo(tb->nextOf());
- if (m < result)
- result = m; // remember worst match
- if (result == MATCHnomatch)
- break; // no need to check for worse
- }
- return result;
+ for (size_t i = 0; i < keys->dim; i++)
+ { Expression *e = (Expression *)keys->data[i];
+ MATCH m = (MATCH)e->implicitConvTo(((TypeAArray *)tb)->key);
+ if (m < result)
+ result = m; // remember worst match
+ if (result == MATCHnomatch)
+ break; // no need to check for worse
+ e = (Expression *)values->data[i];
+ m = (MATCH)e->implicitConvTo(tb->nextOf());
+ if (m < result)
+ result = m; // remember worst match
+ if (result == MATCHnomatch)
+ break; // no need to check for worse
+ }
+ return result;
}
else
- return Expression::implicitConvTo(t);
+ return Expression::implicitConvTo(t);
}
MATCH AddrExp::implicitConvTo(Type *t)
{
#if 0
printf("AddrExp::implicitConvTo(this=%s, type=%s, t=%s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
MATCH result;
@@ -512,20 +512,20 @@ MATCH AddrExp::implicitConvTo(Type *t)
if (result == MATCHnomatch)
{
- // Look for pointers to functions where the functions are overloaded.
- VarExp *ve;
- FuncDeclaration *f;
+ // Look for pointers to functions where the functions are overloaded.
+ VarExp *ve;
+ FuncDeclaration *f;
- t = t->toBasetype();
- if (type->ty == Tpointer && type->next->ty == Tfunction &&
- t->ty == Tpointer && t->next->ty == Tfunction &&
- e1->op == TOKvar)
- {
- ve = (VarExp *)e1;
- f = ve->var->isFuncDeclaration();
- if (f && f->overloadExactMatch(t->next, m))
- result = MATCHexact;
- }
+ t = t->toBasetype();
+ if (type->ty == Tpointer && type->next->ty == Tfunction &&
+ t->ty == Tpointer && t->next->ty == Tfunction &&
+ e1->op == TOKvar)
+ {
+ ve = (VarExp *)e1;
+ f = ve->var->isFuncDeclaration();
+ if (f && f->overloadExactMatch(t->next, m))
+ result = MATCHexact;
+ }
}
//printf("\tresult = %d\n", result);
return result;
@@ -535,7 +535,7 @@ MATCH SymOffExp::implicitConvTo(Type *t)
{
#if 0
printf("SymOffExp::implicitConvTo(this=%s, type=%s, t=%s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
MATCH result;
@@ -544,17 +544,17 @@ MATCH SymOffExp::implicitConvTo(Type *t)
if (result == MATCHnomatch)
{
- // Look for pointers to functions where the functions are overloaded.
- FuncDeclaration *f;
+ // Look for pointers to functions where the functions are overloaded.
+ FuncDeclaration *f;
- t = t->toBasetype();
- if (type->ty == Tpointer && type->next->ty == Tfunction &&
- t->ty == Tpointer && t->next->ty == Tfunction)
- {
- f = var->isFuncDeclaration();
- if (f && f->overloadExactMatch(t->next, m))
- result = MATCHexact;
- }
+ t = t->toBasetype();
+ if (type->ty == Tpointer && type->next->ty == Tfunction &&
+ t->ty == Tpointer && t->next->ty == Tfunction)
+ {
+ f = var->isFuncDeclaration();
+ if (f && f->overloadExactMatch(t->next, m))
+ result = MATCHexact;
+ }
}
//printf("\tresult = %d\n", result);
return result;
@@ -564,7 +564,7 @@ MATCH DelegateExp::implicitConvTo(Type *t)
{
#if 0
printf("DelegateExp::implicitConvTo(this=%s, type=%s, t=%s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
MATCH result;
@@ -572,16 +572,16 @@ MATCH DelegateExp::implicitConvTo(Type *t)
if (result == 0)
{
- // Look for pointers to functions where the functions are overloaded.
- FuncDeclaration *f;
+ // Look for pointers to functions where the functions are overloaded.
+ FuncDeclaration *f;
- t = t->toBasetype();
- if (type->ty == Tdelegate && type->nextOf()->ty == Tfunction &&
- t->ty == Tdelegate && t->nextOf()->ty == Tfunction)
- {
- if (func && func->overloadExactMatch(t->nextOf(), m))
- result = MATCHexact;
- }
+ t = t->toBasetype();
+ if (type->ty == Tdelegate && type->nextOf()->ty == Tfunction &&
+ t->ty == Tdelegate && t->nextOf()->ty == Tfunction)
+ {
+ if (func && func->overloadExactMatch(t->nextOf(), m))
+ result = MATCHexact;
+ }
}
return result;
}
@@ -610,43 +610,43 @@ Expression *Expression::castTo(Scope *sc, Type *t)
//printf("Expression::castTo(this=%s, t=%s)\n", toChars(), t->toChars());
#if 0
printf("Expression::castTo(this=%s, type=%s, t=%s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
if (type == t)
- return this;
+ return this;
Expression *e = this;
Type *tb = t->toBasetype();
Type *typeb = type->toBasetype();
if (tb != typeb)
{
- // Do (type *) cast of (type [dim])
- if (tb->ty == Tpointer &&
- typeb->ty == Tsarray
- )
- {
- //printf("Converting [dim] to *\n");
+ // Do (type *) cast of (type [dim])
+ if (tb->ty == Tpointer &&
+ typeb->ty == Tsarray
+ )
+ {
+ //printf("Converting [dim] to *\n");
- if (typeb->size(loc) == 0)
- e = new NullExp(loc);
- else
- e = new AddrExp(loc, e);
- }
+ if (typeb->size(loc) == 0)
+ e = new NullExp(loc);
+ else
+ e = new AddrExp(loc, e);
+ }
#if 0
- else if (tb->ty == Tdelegate && type->ty != Tdelegate)
- {
- TypeDelegate *td = (TypeDelegate *)tb;
- TypeFunction *tf = (TypeFunction *)td->nextOf();
- return toDelegate(sc, tf->nextOf());
- }
+ else if (tb->ty == Tdelegate && type->ty != Tdelegate)
+ {
+ TypeDelegate *td = (TypeDelegate *)tb;
+ TypeFunction *tf = (TypeFunction *)td->nextOf();
+ return toDelegate(sc, tf->nextOf());
+ }
#endif
- else
- {
- e = new CastExp(loc, e, tb);
- }
+ else
+ {
+ e = new CastExp(loc, e, tb);
+ }
}
else
{
- e = e->copy(); // because of COW for assignment to e->type
+ e = e->copy(); // because of COW for assignment to e->type
}
assert(e != this);
e->type = t;
@@ -659,14 +659,14 @@ Expression *RealExp::castTo(Scope *sc, Type *t)
{ Expression *e = this;
if (type != t)
{
- if ((type->isreal() && t->isreal()) ||
- (type->isimaginary() && t->isimaginary())
- )
- { e = copy();
- e->type = t;
- }
- else
- e = Expression::castTo(sc, t);
+ if ((type->isreal() && t->isreal()) ||
+ (type->isimaginary() && t->isimaginary())
+ )
+ { e = copy();
+ e->type = t;
+ }
+ else
+ e = Expression::castTo(sc, t);
}
return e;
}
@@ -676,12 +676,12 @@ Expression *ComplexExp::castTo(Scope *sc, Type *t)
{ Expression *e = this;
if (type != t)
{
- if (type->iscomplex() && t->iscomplex())
- { e = copy();
- e->type = t;
- }
- else
- e = Expression::castTo(sc, t);
+ if (type->iscomplex() && t->iscomplex())
+ { e = copy();
+ e->type = t;
+ }
+ else
+ e = Expression::castTo(sc, t);
}
return e;
}
@@ -694,8 +694,8 @@ Expression *NullExp::castTo(Scope *sc, Type *t)
//printf("NullExp::castTo(t = %p)\n", t);
if (type == t)
{
- committed = 1;
- return this;
+ committed = 1;
+ return this;
}
e = (NullExp *)copy();
e->committed = 1;
@@ -703,29 +703,29 @@ Expression *NullExp::castTo(Scope *sc, Type *t)
e->type = type->toBasetype();
if (tb != e->type)
{
- // NULL implicitly converts to any pointer type or dynamic array
- if (e->type->ty == Tpointer && e->type->nextOf()->ty == Tvoid &&
- (tb->ty == Tpointer || tb->ty == Tarray || tb->ty == Taarray ||
- tb->ty == Tdelegate))
- {
+ // NULL implicitly converts to any pointer type or dynamic array
+ if (e->type->ty == Tpointer && e->type->nextOf()->ty == Tvoid &&
+ (tb->ty == Tpointer || tb->ty == Tarray || tb->ty == Taarray ||
+ tb->ty == Tdelegate))
+ {
#if 0
- if (tb->ty == Tdelegate)
- { TypeDelegate *td = (TypeDelegate *)tb;
- TypeFunction *tf = (TypeFunction *)td->nextOf();
+ if (tb->ty == Tdelegate)
+ { TypeDelegate *td = (TypeDelegate *)tb;
+ TypeFunction *tf = (TypeFunction *)td->nextOf();
- if (!tf->varargs &&
- !(tf->arguments && tf->arguments->dim)
- )
- {
- return Expression::castTo(sc, t);
- }
- }
+ if (!tf->varargs &&
+ !(tf->arguments && tf->arguments->dim)
+ )
+ {
+ return Expression::castTo(sc, t);
+ }
+ }
#endif
- }
- else
- {
- return e->Expression::castTo(sc, t);
- }
+ }
+ else
+ {
+ return e->Expression::castTo(sc, t);
+ }
}
e->type = t;
return e;
@@ -745,68 +745,68 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
if (!committed && t->ty == Tpointer && t->nextOf()->ty == Tvoid)
{
- error("cannot convert string literal to void*");
+ error("cannot convert string literal to void*");
}
se = this;
if (!committed)
{ se = (StringExp *)copy();
- se->committed = 1;
- copied = 1;
+ se->committed = 1;
+ copied = 1;
}
if (type == t)
{
- return se;
+ return se;
}
tb = t->toBasetype();
//printf("\ttype = %s\n", type->toChars());
if (tb->ty == Tdelegate && type->toBasetype()->ty != Tdelegate)
- return Expression::castTo(sc, t);
+ return Expression::castTo(sc, t);
Type *typeb = type->toBasetype();
if (typeb == tb)
{
- if (!copied)
- { se = (StringExp *)copy();
- copied = 1;
- }
- se->type = t;
- return se;
+ if (!copied)
+ { se = (StringExp *)copy();
+ copied = 1;
+ }
+ se->type = t;
+ return se;
}
if (tb->ty != Tsarray && tb->ty != Tarray && tb->ty != Tpointer)
- { if (!copied)
- { se = (StringExp *)copy();
- copied = 1;
- }
- goto Lcast;
+ { if (!copied)
+ { se = (StringExp *)copy();
+ copied = 1;
+ }
+ goto Lcast;
}
if (typeb->ty != Tsarray && typeb->ty != Tarray && typeb->ty != Tpointer)
- { if (!copied)
- { se = (StringExp *)copy();
- copied = 1;
- }
- goto Lcast;
+ { if (!copied)
+ { se = (StringExp *)copy();
+ copied = 1;
+ }
+ goto Lcast;
}
if (typeb->nextOf()->size() == tb->nextOf()->size())
{
- if (!copied)
- { se = (StringExp *)copy();
- copied = 1;
- }
- if (tb->ty == Tsarray)
- goto L2; // handle possible change in static array dimension
- se->type = t;
- return se;
+ if (!copied)
+ { se = (StringExp *)copy();
+ copied = 1;
+ }
+ if (tb->ty == Tsarray)
+ goto L2; // handle possible change in static array dimension
+ se->type = t;
+ return se;
}
if (committed)
- goto Lcast;
+ goto Lcast;
-#define X(tf,tt) ((tf) * 256 + (tt))
+#define X(tf,tt) ((tf) * 256 + (tt))
{
OutBuffer buffer;
size_t newlen = 0;
@@ -814,102 +814,102 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
int ttty = tb->nextOf()->toBasetype()->ty;
switch (X(tfty, ttty))
{
- case X(Tchar, Tchar):
- case X(Twchar,Twchar):
- case X(Tdchar,Tdchar):
- break;
+ case X(Tchar, Tchar):
+ case X(Twchar,Twchar):
+ case X(Tdchar,Tdchar):
+ break;
- case X(Tchar, Twchar):
- for (size_t u = 0; u < len;)
- { unsigned c;
- char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c);
- if (p)
- error("%s", p);
- else
- buffer.writeUTF16(c);
- }
- newlen = buffer.offset / 2;
- buffer.writeUTF16(0);
- goto L1;
+ case X(Tchar, Twchar):
+ for (size_t u = 0; u < len;)
+ { unsigned c;
+ char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c);
+ if (p)
+ error("%s", p);
+ else
+ buffer.writeUTF16(c);
+ }
+ newlen = buffer.offset / 2;
+ buffer.writeUTF16(0);
+ goto L1;
- case X(Tchar, Tdchar):
- for (size_t u = 0; u < len;)
- { unsigned c;
- char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c);
- if (p)
- error("%s", p);
- buffer.write4(c);
- newlen++;
- }
- buffer.write4(0);
- goto L1;
+ case X(Tchar, Tdchar):
+ for (size_t u = 0; u < len;)
+ { unsigned c;
+ char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c);
+ if (p)
+ error("%s", p);
+ buffer.write4(c);
+ newlen++;
+ }
+ buffer.write4(0);
+ goto L1;
- case X(Twchar,Tchar):
- for (size_t u = 0; u < len;)
- { unsigned c;
- char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c);
- if (p)
- error("%s", p);
- else
- buffer.writeUTF8(c);
- }
- newlen = buffer.offset;
- buffer.writeUTF8(0);
- goto L1;
+ case X(Twchar,Tchar):
+ for (size_t u = 0; u < len;)
+ { unsigned c;
+ char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c);
+ if (p)
+ error("%s", p);
+ else
+ buffer.writeUTF8(c);
+ }
+ newlen = buffer.offset;
+ buffer.writeUTF8(0);
+ goto L1;
- case X(Twchar,Tdchar):
- for (size_t u = 0; u < len;)
- { unsigned c;
- char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c);
- if (p)
- error("%s", p);
- buffer.write4(c);
- newlen++;
- }
- buffer.write4(0);
- goto L1;
+ case X(Twchar,Tdchar):
+ for (size_t u = 0; u < len;)
+ { unsigned c;
+ char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c);
+ if (p)
+ error("%s", p);
+ buffer.write4(c);
+ newlen++;
+ }
+ buffer.write4(0);
+ goto L1;
- case X(Tdchar,Tchar):
- for (size_t u = 0; u < len; u++)
- {
- unsigned c = ((unsigned *)se->string)[u];
- if (!utf_isValidDchar(c))
- error("invalid UCS-32 char \\U%08x", c);
- else
- buffer.writeUTF8(c);
- newlen++;
- }
- newlen = buffer.offset;
- buffer.writeUTF8(0);
- goto L1;
+ case X(Tdchar,Tchar):
+ for (size_t u = 0; u < len; u++)
+ {
+ unsigned c = ((unsigned *)se->string)[u];
+ if (!utf_isValidDchar(c))
+ error("invalid UCS-32 char \\U%08x", c);
+ else
+ buffer.writeUTF8(c);
+ newlen++;
+ }
+ newlen = buffer.offset;
+ buffer.writeUTF8(0);
+ goto L1;
- case X(Tdchar,Twchar):
- for (size_t u = 0; u < len; u++)
- {
- unsigned c = ((unsigned *)se->string)[u];
- if (!utf_isValidDchar(c))
- error("invalid UCS-32 char \\U%08x", c);
- else
- buffer.writeUTF16(c);
- newlen++;
- }
- newlen = buffer.offset / 2;
- buffer.writeUTF16(0);
- goto L1;
+ case X(Tdchar,Twchar):
+ for (size_t u = 0; u < len; u++)
+ {
+ unsigned c = ((unsigned *)se->string)[u];
+ if (!utf_isValidDchar(c))
+ error("invalid UCS-32 char \\U%08x", c);
+ else
+ buffer.writeUTF16(c);
+ newlen++;
+ }
+ newlen = buffer.offset / 2;
+ buffer.writeUTF16(0);
+ goto L1;
- L1:
- if (!copied)
- { se = (StringExp *)copy();
- copied = 1;
- }
- se->string = buffer.extractData();
- se->len = newlen;
- se->sz = tb->nextOf()->size();
- break;
+ L1:
+ if (!copied)
+ { se = (StringExp *)copy();
+ copied = 1;
+ }
+ se->string = buffer.extractData();
+ se->len = newlen;
+ se->sz = tb->nextOf()->size();
+ break;
- default:
- assert(typeb->nextOf()->size() != tb->nextOf()->size());
- goto Lcast;
+ default:
+ assert(typeb->nextOf()->size() != tb->nextOf()->size());
+ goto Lcast;
}
}
#undef X
@@ -919,33 +919,33 @@ L2:
// See if need to truncate or extend the literal
if (tb->ty == Tsarray)
{
- int dim2 = ((TypeSArray *)tb)->dim->toInteger();
+ int dim2 = ((TypeSArray *)tb)->dim->toInteger();
- //printf("dim from = %d, to = %d\n", se->len, dim2);
+ //printf("dim from = %d, to = %d\n", se->len, dim2);
- // Changing dimensions
- if (dim2 != se->len)
- {
- // Copy when changing the string literal
- unsigned newsz = se->sz;
- void *s;
- int d;
+ // Changing dimensions
+ if (dim2 != se->len)
+ {
+ // Copy when changing the string literal
+ unsigned newsz = se->sz;
+ void *s;
+ int d;
- d = (dim2 < se->len) ? dim2 : se->len;
- s = (unsigned char *)mem.malloc((dim2 + 1) * newsz);
- memcpy(s, se->string, d * newsz);
- // Extend with 0, add terminating 0
- memset((char *)s + d * newsz, 0, (dim2 + 1 - d) * newsz);
- se->string = s;
- se->len = dim2;
- }
+ d = (dim2 < se->len) ? dim2 : se->len;
+ s = (unsigned char *)mem.malloc((dim2 + 1) * newsz);
+ memcpy(s, se->string, d * newsz);
+ // Extend with 0, add terminating 0
+ memset((char *)s + d * newsz, 0, (dim2 + 1 - d) * newsz);
+ se->string = s;
+ se->len = dim2;
+ }
}
se->type = t;
return se;
Lcast:
Expression *e = new CastExp(loc, se, t);
- e->type = t; // so semantic() won't be run on e
+ e->type = t; // so semantic() won't be run on e
return e;
}
@@ -955,7 +955,7 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
#if 0
printf("AddrExp::castTo(this=%s, type=%s, t=%s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
Expression *e = this;
@@ -963,30 +963,30 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
type = type->toBasetype();
if (tb != type)
{
- // Look for pointers to functions where the functions are overloaded.
- VarExp *ve;
- FuncDeclaration *f;
+ // Look for pointers to functions where the functions are overloaded.
+ VarExp *ve;
+ FuncDeclaration *f;
- if (type->ty == Tpointer && type->next->ty == Tfunction &&
- tb->ty == Tpointer && tb->next->ty == Tfunction &&
- e1->op == TOKvar)
- {
- ve = (VarExp *)e1;
- f = ve->var->isFuncDeclaration();
- if (f)
- {
- f = f->overloadExactMatch(tb->next, m);
- if (f)
- {
- e = new VarExp(loc, f);
- e->type = f->type;
- e = new AddrExp(loc, e);
- e->type = t;
- return e;
- }
- }
- }
- e = Expression::castTo(sc, t);
+ if (type->ty == Tpointer && type->next->ty == Tfunction &&
+ tb->ty == Tpointer && tb->next->ty == Tfunction &&
+ e1->op == TOKvar)
+ {
+ ve = (VarExp *)e1;
+ f = ve->var->isFuncDeclaration();
+ if (f)
+ {
+ f = f->overloadExactMatch(tb->next, m);
+ if (f)
+ {
+ e = new VarExp(loc, f);
+ e->type = f->type;
+ e = new AddrExp(loc, e);
+ e->type = t;
+ return e;
+ }
+ }
+ }
+ e = Expression::castTo(sc, t);
}
e->type = t;
return e;
@@ -998,8 +998,8 @@ Expression *TupleExp::castTo(Scope *sc, Type *t)
e->exps = (Expressions *)exps->copy();
for (size_t i = 0; i < e->exps->dim; i++)
{ Expression *ex = (Expression *)e->exps->data[i];
- ex = ex->castTo(sc, t);
- e->exps->data[i] = (void *)ex;
+ ex = ex->castTo(sc, t);
+ e->exps->data[i] = (void *)ex;
}
return e;
}
@@ -1009,38 +1009,38 @@ Expression *ArrayLiteralExp::castTo(Scope *sc, Type *t)
{
#if 0
printf("ArrayLiteralExp::castTo(this=%s, type=%s, => %s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
if (type == t)
- return this;
+ return this;
ArrayLiteralExp *e = this;
Type *typeb = type->toBasetype();
Type *tb = t->toBasetype();
if ((tb->ty == Tarray || tb->ty == Tsarray) &&
- (typeb->ty == Tarray || typeb->ty == Tsarray) &&
- // Not trying to convert non-void[] to void[]
- !(tb->nextOf()->toBasetype()->ty == Tvoid && typeb->nextOf()->toBasetype()->ty != Tvoid))
+ (typeb->ty == Tarray || typeb->ty == Tsarray) &&
+ // Not trying to convert non-void[] to void[]
+ !(tb->nextOf()->toBasetype()->ty == Tvoid && typeb->nextOf()->toBasetype()->ty != Tvoid))
{
- if (tb->ty == Tsarray)
- { TypeSArray *tsa = (TypeSArray *)tb;
- if (elements->dim != tsa->dim->toInteger())
- goto L1;
- }
+ if (tb->ty == Tsarray)
+ { TypeSArray *tsa = (TypeSArray *)tb;
+ if (elements->dim != tsa->dim->toInteger())
+ goto L1;
+ }
- e = (ArrayLiteralExp *)copy();
- e->elements = (Expressions *)elements->copy();
- for (int i = 0; i < elements->dim; i++)
- { Expression *ex = (Expression *)elements->data[i];
- ex = ex->castTo(sc, tb->nextOf());
- e->elements->data[i] = (void *)ex;
- }
- e->type = t;
- return e;
+ e = (ArrayLiteralExp *)copy();
+ e->elements = (Expressions *)elements->copy();
+ for (int i = 0; i < elements->dim; i++)
+ { Expression *ex = (Expression *)elements->data[i];
+ ex = ex->castTo(sc, tb->nextOf());
+ e->elements->data[i] = (void *)ex;
+ }
+ e->type = t;
+ return e;
}
if (tb->ty == Tpointer && typeb->ty == Tsarray)
{
- e = (ArrayLiteralExp *)copy();
- e->type = typeb->nextOf()->pointerTo();
+ e = (ArrayLiteralExp *)copy();
+ e->type = typeb->nextOf()->pointerTo();
}
L1:
return e->Expression::castTo(sc, t);
@@ -1049,28 +1049,28 @@ L1:
Expression *AssocArrayLiteralExp::castTo(Scope *sc, Type *t)
{
if (type == t)
- return this;
+ return this;
AssocArrayLiteralExp *e = this;
Type *typeb = type->toBasetype();
Type *tb = t->toBasetype();
if (tb->ty == Taarray && typeb->ty == Taarray &&
- tb->nextOf()->toBasetype()->ty != Tvoid)
+ tb->nextOf()->toBasetype()->ty != Tvoid)
{
- e = (AssocArrayLiteralExp *)copy();
- e->keys = (Expressions *)keys->copy();
- e->values = (Expressions *)values->copy();
- assert(keys->dim == values->dim);
- for (size_t i = 0; i < keys->dim; i++)
- { Expression *ex = (Expression *)values->data[i];
- ex = ex->castTo(sc, tb->nextOf());
- e->values->data[i] = (void *)ex;
+ e = (AssocArrayLiteralExp *)copy();
+ e->keys = (Expressions *)keys->copy();
+ e->values = (Expressions *)values->copy();
+ assert(keys->dim == values->dim);
+ for (size_t i = 0; i < keys->dim; i++)
+ { Expression *ex = (Expression *)values->data[i];
+ ex = ex->castTo(sc, tb->nextOf());
+ e->values->data[i] = (void *)ex;
- ex = (Expression *)keys->data[i];
- ex = ex->castTo(sc, ((TypeAArray *)tb)->index);
- e->keys->data[i] = (void *)ex;
- }
- e->type = t;
- return e;
+ ex = (Expression *)keys->data[i];
+ ex = ex->castTo(sc, ((TypeAArray *)tb)->index);
+ e->keys->data[i] = (void *)ex;
+ }
+ e->type = t;
+ return e;
}
L1:
return e->Expression::castTo(sc, t);
@@ -1080,7 +1080,7 @@ Expression *SymOffExp::castTo(Scope *sc, Type *t)
{
#if 0
printf("SymOffExp::castTo(this=%s, type=%s, t=%s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
Expression *e = this;
@@ -1088,58 +1088,58 @@ Expression *SymOffExp::castTo(Scope *sc, Type *t)
Type *typeb = type->toBasetype();
if (tb != typeb)
{
- // Look for pointers to functions where the functions are overloaded.
- FuncDeclaration *f;
+ // Look for pointers to functions where the functions are overloaded.
+ FuncDeclaration *f;
- if (typeb->ty == Tpointer && typeb->next->ty == Tfunction &&
- tb->ty == Tpointer && tb->next->ty == Tfunction)
- {
- f = var->isFuncDeclaration();
- if (f)
- {
- f = f->overloadExactMatch(tb->next, m);
- if (f)
- {
+ if (typeb->ty == Tpointer && typeb->next->ty == Tfunction &&
+ tb->ty == Tpointer && tb->next->ty == Tfunction)
+ {
+ f = var->isFuncDeclaration();
+ if (f)
+ {
+ f = f->overloadExactMatch(tb->next, m);
+ if (f)
+ {
#if DMDV2
- if (tb->ty == Tdelegate)
- {
- if (f->needThis() && hasThis(sc))
- {
- e = new DelegateExp(loc, new ThisExp(loc), f);
- e = e->semantic(sc);
- }
- else if (f->isNested())
- {
- e = new DelegateExp(loc, new IntegerExp(0), f);
- e = e->semantic(sc);
- }
- else if (f->needThis())
- { error("no 'this' to create delegate for %s", f->toChars());
- e = new ErrorExp();
- }
- else
- { error("cannot cast from function pointer to delegate");
- e = new ErrorExp();
- }
- }
- else
+ if (tb->ty == Tdelegate)
+ {
+ if (f->needThis() && hasThis(sc))
+ {
+ e = new DelegateExp(loc, new ThisExp(loc), f);
+ e = e->semantic(sc);
+ }
+ else if (f->isNested())
+ {
+ e = new DelegateExp(loc, new IntegerExp(0), f);
+ e = e->semantic(sc);
+ }
+ else if (f->needThis())
+ { error("no 'this' to create delegate for %s", f->toChars());
+ e = new ErrorExp();
+ }
+ else
+ { error("cannot cast from function pointer to delegate");
+ e = new ErrorExp();
+ }
+ }
+ else
#endif
- {
- e = new SymOffExp(loc, f, 0);
- e->type = t;
- }
+ {
+ e = new SymOffExp(loc, f, 0);
+ e->type = t;
+ }
#if DMDV2
- f->tookAddressOf++;
+ f->tookAddressOf++;
#endif
- return e;
- }
- }
- }
- e = Expression::castTo(sc, t);
+ return e;
+ }
+ }
+ }
+ e = Expression::castTo(sc, t);
}
else
{
- e->type = t;
+ e->type = t;
}
return e;
}
@@ -1149,7 +1149,7 @@ Expression *DelegateExp::castTo(Scope *sc, Type *t)
Type *tb;
#if 0
printf("DelegateExp::castTo(this=%s, type=%s, t=%s)\n",
- toChars(), type->toChars(), t->toChars());
+ toChars(), type->toChars(), t->toChars());
#endif
Expression *e = this;
static char msg[] = "cannot form delegate due to covariant return type";
@@ -1158,34 +1158,34 @@ Expression *DelegateExp::castTo(Scope *sc, Type *t)
type = type->toBasetype();
if (tb != type)
{
- // Look for delegates to functions where the functions are overloaded.
- FuncDeclaration *f;
+ // Look for delegates to functions where the functions are overloaded.
+ FuncDeclaration *f;
- if (type->ty == Tdelegate && type->next->ty == Tfunction &&
- tb->ty == Tdelegate && tb->next->ty == Tfunction)
- {
- if (func)
- {
- f = func->overloadExactMatch(tb->next, m);
- if (f)
- { int offset;
- if (f->tintro && f->tintro->next->isBaseOf(f->type->next, &offset) && offset)
- error("%s", msg);
- e = new DelegateExp(loc, e1, f);
- e->type = t;
- return e;
- }
- if (func->tintro)
- error("%s", msg);
- }
- }
- e = Expression::castTo(sc, t);
+ if (type->ty == Tdelegate && type->next->ty == Tfunction &&
+ tb->ty == Tdelegate && tb->next->ty == Tfunction)
+ {
+ if (func)
+ {
+ f = func->overloadExactMatch(tb->next, m);
+ if (f)
+ { int offset;
+ if (f->tintro && f->tintro->next->isBaseOf(f->type->next, &offset) && offset)
+ error("%s", msg);
+ e = new DelegateExp(loc, e1, f);
+ e->type = t;
+ return e;
+ }
+ if (func->tintro)
+ error("%s", msg);
+ }
+ }
+ e = Expression::castTo(sc, t);
}
else
- { int offset;
+ { int offset;
- if (func->tintro && func->tintro->next->isBaseOf(func->type->next, &offset) && offset)
- error("%s", msg);
+ if (func->tintro && func->tintro->next->isBaseOf(func->type->next, &offset) && offset)
+ error("%s", msg);
}
e->type = t;
return e;
@@ -1197,12 +1197,12 @@ Expression *CondExp::castTo(Scope *sc, Type *t)
if (type != t)
{
- if (1 || e1->op == TOKstring || e2->op == TOKstring)
- { e = new CondExp(loc, econd, e1->castTo(sc, t), e2->castTo(sc, t));
- e->type = t;
- }
- else
- e = Expression::castTo(sc, t);
+ if (1 || e1->op == TOKstring || e2->op == TOKstring)
+ { e = new CondExp(loc, econd, e1->castTo(sc, t), e2->castTo(sc, t));
+ e->type = t;
+ }
+ else
+ e = Expression::castTo(sc, t);
}
return e;
}
@@ -1220,47 +1220,47 @@ Expression *BinExp::scaleFactor(Scope *sc)
if (t1b->ty == Tpointer && t2b->isintegral())
{ // Need to adjust operator by the stride
- // Replace (ptr + int) with (ptr + (int * stride))
- Type *t = Type::tptrdiff_t;
+ // Replace (ptr + int) with (ptr + (int * stride))
+ Type *t = Type::tptrdiff_t;
- stride = t1b->nextOf()->size(loc);
- if (!t->equals(t2b))
- e2 = e2->castTo(sc, t);
+ stride = t1b->nextOf()->size(loc);
+ if (!t->equals(t2b))
+ e2 = e2->castTo(sc, t);
// LDC: llvm uses typesafe pointer arithmetic
#if !IN_LLVM
- if (t1b->next->isbit())
- // BUG: should add runtime check for misaligned offsets
- // This perhaps should be done by rewriting as &p[i]
- // and letting back end do it.
- e2 = new UshrExp(loc, e2, new IntegerExp(0, 3, t));
- else
- e2 = new MulExp(loc, e2, new IntegerExp(0, stride, t));
+ if (t1b->next->isbit())
+ // BUG: should add runtime check for misaligned offsets
+ // This perhaps should be done by rewriting as &p[i]
+ // and letting back end do it.
+ e2 = new UshrExp(loc, e2, new IntegerExp(0, 3, t));
+ else
+ e2 = new MulExp(loc, e2, new IntegerExp(0, stride, t));
#endif
- e2->type = t;
- type = e1->type;
+ e2->type = t;
+ type = e1->type;
}
else if (t2b->ty == Tpointer && t1b->isintegral())
{ // Need to adjust operator by the stride
- // Replace (int + ptr) with (ptr + (int * stride))
- Type *t = Type::tptrdiff_t;
- Expression *e;
+ // Replace (int + ptr) with (ptr + (int * stride))
+ Type *t = Type::tptrdiff_t;
+ Expression *e;
- stride = t2b->nextOf()->size(loc);
- if (!t->equals(t1b))
- e = e1->castTo(sc, t);
- else
- e = e1;
+ stride = t2b->nextOf()->size(loc);
+ if (!t->equals(t1b))
+ e = e1->castTo(sc, t);
+ else
+ e = e1;
#if !IN_LLVM
- if (t2b->next->isbit())
- // BUG: should add runtime check for misaligned offsets
- e = new UshrExp(loc, e, new IntegerExp(0, 3, t));
- else
- e = new MulExp(loc, e, new IntegerExp(0, stride, t));
+ if (t2b->next->isbit())
+ // BUG: should add runtime check for misaligned offsets
+ e = new UshrExp(loc, e, new IntegerExp(0, 3, t));
+ else
+ e = new MulExp(loc, e, new IntegerExp(0, stride, t));
#endif
- e->type = t;
- type = e2->type;
- e1 = e2;
- e2 = e;
+ e->type = t;
+ type = e2->type;
+ e1 = e2;
+ e2 = e;
}
return this;
}
@@ -1299,255 +1299,255 @@ Expression *BinExp::typeCombine(Scope *sc)
ty = (TY)Type::impcnvResult[t1b->ty][t2b->ty];
if (ty != Terror)
- { TY ty1;
- TY ty2;
+ { TY ty1;
+ TY ty2;
- ty1 = (TY)Type::impcnvType1[t1b->ty][t2b->ty];
- ty2 = (TY)Type::impcnvType2[t1b->ty][t2b->ty];
+ ty1 = (TY)Type::impcnvType1[t1b->ty][t2b->ty];
+ ty2 = (TY)Type::impcnvType2[t1b->ty][t2b->ty];
- if (t1b->ty == ty1) // if no promotions
- {
- if (t1 == t2)
- {
- if (!type)
- type = t1;
- return this;
- }
+ if (t1b->ty == ty1) // if no promotions
+ {
+ if (t1 == t2)
+ {
+ if (!type)
+ type = t1;
+ return this;
+ }
- if (t1b == t2b)
- {
- if (!type)
- type = t1b;
- return this;
- }
- }
+ if (t1b == t2b)
+ {
+ if (!type)
+ type = t1b;
+ return this;
+ }
+ }
- if (!type)
- type = Type::basic[ty];
+ if (!type)
+ type = Type::basic[ty];
- t1 = Type::basic[ty1];
- t2 = Type::basic[ty2];
- e1 = e1->castTo(sc, t1);
- e2 = e2->castTo(sc, t2);
+ t1 = Type::basic[ty1];
+ t2 = Type::basic[ty2];
+ e1 = e1->castTo(sc, t1);
+ e2 = e2->castTo(sc, t2);
#if 0
- if (type != Type::basic[ty])
- { t = type;
- type = Type::basic[ty];
- return castTo(sc, t);
- }
+ if (type != Type::basic[ty])
+ { t = type;
+ type = Type::basic[ty];
+ return castTo(sc, t);
+ }
#endif
- //printf("after typeCombine():\n");
- //dump(0);
- //printf("ty = %d, ty1 = %d, ty2 = %d\n", ty, ty1, ty2);
- return this;
+ //printf("after typeCombine():\n");
+ //dump(0);
+ //printf("ty = %d, ty1 = %d, ty2 = %d\n", ty, ty1, ty2);
+ return this;
}
t = t1;
if (t1 == t2)
{
- if ((t1->ty == Tstruct || t1->ty == Tclass) &&
- (op == TOKmin || op == TOKadd))
- goto Lincompatible;
+ if ((t1->ty == Tstruct || t1->ty == Tclass) &&
+ (op == TOKmin || op == TOKadd))
+ goto Lincompatible;
}
else if (t1->isintegral() && t2->isintegral())
{
- printf("t1 = %s, t2 = %s\n", t1->toChars(), t2->toChars());
- int sz1 = t1->size();
- int sz2 = t2->size();
- int sign1 = t1->isunsigned() == 0;
- int sign2 = t2->isunsigned() == 0;
+ printf("t1 = %s, t2 = %s\n", t1->toChars(), t2->toChars());
+ int sz1 = t1->size();
+ int sz2 = t2->size();
+ int sign1 = t1->isunsigned() == 0;
+ int sign2 = t2->isunsigned() == 0;
- if (sign1 == sign2)
- {
- if (sz1 < sz2)
- goto Lt2;
- else
- goto Lt1;
- }
- if (!sign1)
- {
- if (sz1 >= sz2)
- goto Lt1;
- else
- goto Lt2;
- }
- else
- {
- if (sz2 >= sz1)
- goto Lt2;
- else
- goto Lt1;
- }
+ if (sign1 == sign2)
+ {
+ if (sz1 < sz2)
+ goto Lt2;
+ else
+ goto Lt1;
+ }
+ if (!sign1)
+ {
+ if (sz1 >= sz2)
+ goto Lt1;
+ else
+ goto Lt2;
+ }
+ else
+ {
+ if (sz2 >= sz1)
+ goto Lt2;
+ else
+ goto Lt1;
+ }
}
else if (t1->ty == Tpointer && t2->ty == Tpointer)
{
- // Bring pointers to compatible type
- Type *t1n = t1->next;
- Type *t2n = t2->next;
+ // Bring pointers to compatible type
+ Type *t1n = t1->next;
+ Type *t2n = t2->next;
//t1->print();
//t2->print();
//if (t1n == t2n) *(char *)0 = 0;
- assert(t1n != t2n);
- if (t1n->ty == Tvoid) // pointers to void are always compatible
- t = t2;
- else if (t2n->ty == Tvoid)
- ;
- else if (t1n->ty == Tclass && t2n->ty == Tclass)
- { ClassDeclaration *cd1 = t1n->isClassHandle();
- ClassDeclaration *cd2 = t2n->isClassHandle();
- int offset;
+ assert(t1n != t2n);
+ if (t1n->ty == Tvoid) // pointers to void are always compatible
+ t = t2;
+ else if (t2n->ty == Tvoid)
+ ;
+ else if (t1n->ty == Tclass && t2n->ty == Tclass)
+ { ClassDeclaration *cd1 = t1n->isClassHandle();
+ ClassDeclaration *cd2 = t2n->isClassHandle();
+ int offset;
- if (cd1->isBaseOf(cd2, &offset))
- {
- if (offset)
- e2 = e2->castTo(sc, t);
- }
- else if (cd2->isBaseOf(cd1, &offset))
- {
- t = t2;
- if (offset)
- e1 = e1->castTo(sc, t);
- }
- else
- goto Lincompatible;
- }
- else
- goto Lincompatible;
+ if (cd1->isBaseOf(cd2, &offset))
+ {
+ if (offset)
+ e2 = e2->castTo(sc, t);
+ }
+ else if (cd2->isBaseOf(cd1, &offset))
+ {
+ t = t2;
+ if (offset)
+ e1 = e1->castTo(sc, t);
+ }
+ else
+ goto Lincompatible;
+ }
+ else
+ goto Lincompatible;
}
else if ((t1->ty == Tsarray || t1->ty == Tarray) &&
- e2->op == TOKnull && t2->ty == Tpointer && t2->nextOf()->ty == Tvoid)
- { /* (T[n] op void*)
- * (T[] op void*)
- */
- goto Lx1;
+ e2->op == TOKnull && t2->ty == Tpointer && t2->nextOf()->ty == Tvoid)
+ { /* (T[n] op void*)
+ * (T[] op void*)
+ */
+ goto Lx1;
}
else if ((t2->ty == Tsarray || t2->ty == Tarray) &&
- e1->op == TOKnull && t1->ty == Tpointer && t1->nextOf()->ty == Tvoid)
- { /* (void* op T[n])
- * (void* op T[])
- */
- goto Lx2;
+ e1->op == TOKnull && t1->ty == Tpointer && t1->nextOf()->ty == Tvoid)
+ { /* (void* op T[n])
+ * (void* op T[])
+ */
+ goto Lx2;
}
else if ((t1->ty == Tsarray || t1->ty == Tarray) && t1->implicitConvTo(t2))
{
- goto Lt2;
+ goto Lt2;
}
else if ((t2->ty == Tsarray || t2->ty == Tarray) && t2->implicitConvTo(t1))
{
- goto Lt1;
+ goto Lt1;
}
else if (t1->ty == Tclass || t2->ty == Tclass)
{
- while (1)
- {
- int i1 = e2->implicitConvTo(t1);
- int i2 = e1->implicitConvTo(t2);
+ while (1)
+ {
+ int i1 = e2->implicitConvTo(t1);
+ int i2 = e1->implicitConvTo(t2);
- if (i1 && i2)
- {
- // We have the case of class vs. void*, so pick class
- if (t1->ty == Tpointer)
- i1 = 0;
- else if (t2->ty == Tpointer)
- i2 = 0;
- }
+ if (i1 && i2)
+ {
+ // We have the case of class vs. void*, so pick class
+ if (t1->ty == Tpointer)
+ i1 = 0;
+ else if (t2->ty == Tpointer)
+ i2 = 0;
+ }
- if (i2)
- {
- goto Lt2;
- }
- else if (i1)
- {
- goto Lt1;
- }
- else if (t1->ty == Tclass && t2->ty == Tclass)
- { TypeClass *tc1 = (TypeClass *)t1;
- TypeClass *tc2 = (TypeClass *)t2;
+ if (i2)
+ {
+ goto Lt2;
+ }
+ else if (i1)
+ {
+ goto Lt1;
+ }
+ else if (t1->ty == Tclass && t2->ty == Tclass)
+ { TypeClass *tc1 = (TypeClass *)t1;
+ TypeClass *tc2 = (TypeClass *)t2;
- /* Pick 'tightest' type
- */
- ClassDeclaration *cd1 = tc1->sym->baseClass;
- ClassDeclaration *cd2 = tc2->sym->baseClass;
+ /* Pick 'tightest' type
+ */
+ ClassDeclaration *cd1 = tc1->sym->baseClass;
+ ClassDeclaration *cd2 = tc2->sym->baseClass;
- if (cd1 && cd2)
- { t1 = cd1->type;
- t2 = cd2->type;
- }
- else if (cd1)
- t1 = cd1->type;
- else if (cd2)
- t2 = cd2->type;
- else
- goto Lincompatible;
- }
- else
- goto Lincompatible;
- }
+ if (cd1 && cd2)
+ { t1 = cd1->type;
+ t2 = cd2->type;
+ }
+ else if (cd1)
+ t1 = cd1->type;
+ else if (cd2)
+ t2 = cd2->type;
+ else
+ goto Lincompatible;
+ }
+ else
+ goto Lincompatible;
+ }
}
else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2))
{
- goto Lt2;
+ goto Lt2;
}
//else if (e2->op == TOKstring) { printf("test2\n"); }
else if ((e2->op == TOKstring || e2->op == TOKnull) && e2->implicitConvTo(t1))
{
- goto Lt1;
+ goto Lt1;
}
else if (t1->ty == Tsarray && t2->ty == Tsarray &&
- e2->implicitConvTo(t1->nextOf()->arrayOf()))
+ e2->implicitConvTo(t1->nextOf()->arrayOf()))
{
Lx1:
- t = t1->nextOf()->arrayOf();
- e1 = e1->castTo(sc, t);
- e2 = e2->castTo(sc, t);
+ t = t1->nextOf()->arrayOf();
+ e1 = e1->castTo(sc, t);
+ e2 = e2->castTo(sc, t);
}
else if (t1->ty == Tsarray && t2->ty == Tsarray &&
- e1->implicitConvTo(t2->nextOf()->arrayOf()))
+ e1->implicitConvTo(t2->nextOf()->arrayOf()))
{
Lx2:
- t = t2->nextOf()->arrayOf();
- e1 = e1->castTo(sc, t);
- e2 = e2->castTo(sc, t);
+ t = t2->nextOf()->arrayOf();
+ e1 = e1->castTo(sc, t);
+ e2 = e2->castTo(sc, t);
}
else if (t1->isintegral() && t2->isintegral())
{
- assert(0);
+ assert(0);
}
else if (e1->isArrayOperand() && t1->ty == Tarray &&
- e2->implicitConvTo(t1->nextOf()))
- { // T[] op T
- e2 = e2->castTo(sc, t1->nextOf());
- t = t1->nextOf()->arrayOf();
+ e2->implicitConvTo(t1->nextOf()))
+ { // T[] op T
+ e2 = e2->castTo(sc, t1->nextOf());
+ t = t1->nextOf()->arrayOf();
}
else if (e2->isArrayOperand() && t2->ty == Tarray &&
- e1->implicitConvTo(t2->nextOf()))
- { // T op T[]
- e1 = e1->castTo(sc, t2->nextOf());
- t = t2->nextOf()->arrayOf();
+ e1->implicitConvTo(t2->nextOf()))
+ { // T op T[]
+ e1 = e1->castTo(sc, t2->nextOf());
+ t = t2->nextOf()->arrayOf();
- //printf("test %s\n", e->toChars());
- e1 = e1->optimize(WANTvalue);
- if (isCommutative() && e1->isConst())
- { /* Swap operands to minimize number of functions generated
- */
- //printf("swap %s\n", e->toChars());
- Expression *tmp = e1;
- e1 = e2;
- e2 = tmp;
- }
+ //printf("test %s\n", e->toChars());
+ e1 = e1->optimize(WANTvalue);
+ if (isCommutative() && e1->isConst())
+ { /* Swap operands to minimize number of functions generated
+ */
+ //printf("swap %s\n", e->toChars());
+ Expression *tmp = e1;
+ e1 = e2;
+ e2 = tmp;
+ }
}
else
{
Lincompatible:
- incompatibleTypes();
- type = Type::terror;
- e1 = new ErrorExp();
- e2 = new ErrorExp();
+ incompatibleTypes();
+ type = Type::terror;
+ e1 = new ErrorExp();
+ e2 = new ErrorExp();
}
Lret:
if (!type)
- type = t;
+ type = t;
//dump(0);
return this;
@@ -1575,24 +1575,24 @@ Expression *Expression::integralPromotions(Scope *sc)
//printf("integralPromotions %s %s\n", e->toChars(), e->type->toChars());
switch (type->toBasetype()->ty)
{
- case Tvoid:
- error("void has no value");
- break;
+ case Tvoid:
+ error("void has no value");
+ break;
- case Tint8:
- case Tuns8:
- case Tint16:
- case Tuns16:
- case Tbit:
- case Tbool:
- case Tchar:
- case Twchar:
- e = e->castTo(sc, Type::tint32);
- break;
+ case Tint8:
+ case Tuns8:
+ case Tint16:
+ case Tuns16:
+ case Tbit:
+ case Tbool:
+ case Tchar:
+ case Twchar:
+ e = e->castTo(sc, Type::tint32);
+ break;
- case Tdchar:
- e = e->castTo(sc, Type::tuns32);
- break;
+ case Tdchar:
+ e = e->castTo(sc, Type::tuns32);
+ break;
}
return e;
}
diff --git a/dmd/class.c b/dmd/class.c
index 877095a6..3b71a743 100644
--- a/dmd/class.c
+++ b/dmd/class.c
@@ -38,7 +38,7 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
static char msg[] = "only object.d can define this reserved class name";
if (baseclasses)
- this->baseclasses = *baseclasses;
+ this->baseclasses = *baseclasses;
baseClass = NULL;
interfaces_dim = 0;
@@ -63,130 +63,130 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
vclassinfo = NULL;
if (id)
- { // Look for special class names
+ { // Look for special class names
- if (id == Id::__sizeof || id == Id::alignof || id == Id::mangleof)
- error("illegal class name");
+ if (id == Id::__sizeof || id == Id::alignof || id == Id::mangleof)
+ error("illegal class name");
- // BUG: What if this is the wrong TypeInfo, i.e. it is nested?
- if (id->toChars()[0] == 'T')
- {
- if (id == Id::TypeInfo)
- { if (Type::typeinfo)
- Type::typeinfo->error("%s", msg);
- Type::typeinfo = this;
- }
+ // BUG: What if this is the wrong TypeInfo, i.e. it is nested?
+ if (id->toChars()[0] == 'T')
+ {
+ if (id == Id::TypeInfo)
+ { if (Type::typeinfo)
+ Type::typeinfo->error("%s", msg);
+ Type::typeinfo = this;
+ }
- if (id == Id::TypeInfo_Class)
- { if (Type::typeinfoclass)
- Type::typeinfoclass->error("%s", msg);
- Type::typeinfoclass = this;
- }
+ if (id == Id::TypeInfo_Class)
+ { if (Type::typeinfoclass)
+ Type::typeinfoclass->error("%s", msg);
+ Type::typeinfoclass = this;
+ }
- if (id == Id::TypeInfo_Interface)
- { if (Type::typeinfointerface)
- Type::typeinfointerface->error("%s", msg);
- Type::typeinfointerface = this;
- }
+ if (id == Id::TypeInfo_Interface)
+ { if (Type::typeinfointerface)
+ Type::typeinfointerface->error("%s", msg);
+ Type::typeinfointerface = this;
+ }
- if (id == Id::TypeInfo_Struct)
- { if (Type::typeinfostruct)
- Type::typeinfostruct->error("%s", msg);
- Type::typeinfostruct = this;
- }
+ if (id == Id::TypeInfo_Struct)
+ { if (Type::typeinfostruct)
+ Type::typeinfostruct->error("%s", msg);
+ Type::typeinfostruct = this;
+ }
- if (id == Id::TypeInfo_Typedef)
- { if (Type::typeinfotypedef)
- Type::typeinfotypedef->error("%s", msg);
- Type::typeinfotypedef = this;
- }
+ if (id == Id::TypeInfo_Typedef)
+ { if (Type::typeinfotypedef)
+ Type::typeinfotypedef->error("%s", msg);
+ Type::typeinfotypedef = this;
+ }
- if (id == Id::TypeInfo_Pointer)
- { if (Type::typeinfopointer)
- Type::typeinfopointer->error("%s", msg);
- Type::typeinfopointer = this;
- }
+ if (id == Id::TypeInfo_Pointer)
+ { if (Type::typeinfopointer)
+ Type::typeinfopointer->error("%s", msg);
+ Type::typeinfopointer = this;
+ }
- if (id == Id::TypeInfo_Array)
- { if (Type::typeinfoarray)
- Type::typeinfoarray->error("%s", msg);
- Type::typeinfoarray = this;
- }
+ if (id == Id::TypeInfo_Array)
+ { if (Type::typeinfoarray)
+ Type::typeinfoarray->error("%s", msg);
+ Type::typeinfoarray = this;
+ }
- if (id == Id::TypeInfo_StaticArray)
- { //if (Type::typeinfostaticarray)
- //Type::typeinfostaticarray->error("%s", msg);
- Type::typeinfostaticarray = this;
- }
+ if (id == Id::TypeInfo_StaticArray)
+ { //if (Type::typeinfostaticarray)
+ //Type::typeinfostaticarray->error("%s", msg);
+ Type::typeinfostaticarray = this;
+ }
- if (id == Id::TypeInfo_AssociativeArray)
- { if (Type::typeinfoassociativearray)
- Type::typeinfoassociativearray->error("%s", msg);
- Type::typeinfoassociativearray = this;
- }
+ if (id == Id::TypeInfo_AssociativeArray)
+ { if (Type::typeinfoassociativearray)
+ Type::typeinfoassociativearray->error("%s", msg);
+ Type::typeinfoassociativearray = this;
+ }
- if (id == Id::TypeInfo_Enum)
- { if (Type::typeinfoenum)
- Type::typeinfoenum->error("%s", msg);
- Type::typeinfoenum = this;
- }
+ if (id == Id::TypeInfo_Enum)
+ { if (Type::typeinfoenum)
+ Type::typeinfoenum->error("%s", msg);
+ Type::typeinfoenum = this;
+ }
- if (id == Id::TypeInfo_Function)
- { if (Type::typeinfofunction)
- Type::typeinfofunction->error("%s", msg);
- Type::typeinfofunction = this;
- }
+ if (id == Id::TypeInfo_Function)
+ { if (Type::typeinfofunction)
+ Type::typeinfofunction->error("%s", msg);
+ Type::typeinfofunction = this;
+ }
- if (id == Id::TypeInfo_Delegate)
- { if (Type::typeinfodelegate)
- Type::typeinfodelegate->error("%s", msg);
- Type::typeinfodelegate = this;
- }
+ if (id == Id::TypeInfo_Delegate)
+ { if (Type::typeinfodelegate)
+ Type::typeinfodelegate->error("%s", msg);
+ Type::typeinfodelegate = this;
+ }
- if (id == Id::TypeInfo_Tuple)
- { if (Type::typeinfotypelist)
- Type::typeinfotypelist->error("%s", msg);
- Type::typeinfotypelist = this;
- }
+ if (id == Id::TypeInfo_Tuple)
+ { if (Type::typeinfotypelist)
+ Type::typeinfotypelist->error("%s", msg);
+ Type::typeinfotypelist = this;
+ }
#if DMDV2
- if (id == Id::TypeInfo_Const)
- { if (Type::typeinfoconst)
- Type::typeinfoconst->error("%s", msg);
- Type::typeinfoconst = this;
- }
+ if (id == Id::TypeInfo_Const)
+ { if (Type::typeinfoconst)
+ Type::typeinfoconst->error("%s", msg);
+ Type::typeinfoconst = this;
+ }
- if (id == Id::TypeInfo_Invariant)
- { if (Type::typeinfoinvariant)
- Type::typeinfoinvariant->error("%s", msg);
- Type::typeinfoinvariant = this;
- }
+ if (id == Id::TypeInfo_Invariant)
+ { if (Type::typeinfoinvariant)
+ Type::typeinfoinvariant->error("%s", msg);
+ Type::typeinfoinvariant = this;
+ }
- if (id == Id::TypeInfo_Shared)
- { if (Type::typeinfoshared)
- Type::typeinfoshared->error("%s", msg);
- Type::typeinfoshared = this;
- }
+ if (id == Id::TypeInfo_Shared)
+ { if (Type::typeinfoshared)
+ Type::typeinfoshared->error("%s", msg);
+ Type::typeinfoshared = this;
+ }
#endif
- }
+ }
- if (id == Id::Object)
- { if (object)
- object->error("%s", msg);
- object = this;
- }
+ if (id == Id::Object)
+ { if (object)
+ object->error("%s", msg);
+ object = this;
+ }
- if (id == Id::ClassInfo)
- { if (classinfo)
- classinfo->error("%s", msg);
- classinfo = this;
- }
+ if (id == Id::ClassInfo)
+ { if (classinfo)
+ classinfo->error("%s", msg);
+ classinfo = this;
+ }
- if (id == Id::ModuleInfo)
- { if (Module::moduleinfo)
- Module::moduleinfo->error("%s", msg);
- Module::moduleinfo = this;
- }
+ if (id == Id::ModuleInfo)
+ { if (Module::moduleinfo)
+ Module::moduleinfo->error("%s", msg);
+ Module::moduleinfo = this;
+ }
}
com = 0;
@@ -203,18 +203,18 @@ Dsymbol *ClassDeclaration::syntaxCopy(Dsymbol *s)
//printf("ClassDeclaration::syntaxCopy('%s')\n", toChars());
if (s)
- cd = (ClassDeclaration *)s;
+ cd = (ClassDeclaration *)s;
else
- cd = new ClassDeclaration(loc, ident, NULL);
+ cd = new ClassDeclaration(loc, ident, NULL);
cd->storage_class |= storage_class;
cd->baseclasses.setDim(this->baseclasses.dim);
for (int i = 0; i < cd->baseclasses.dim; i++)
{
- BaseClass *b = (BaseClass *)this->baseclasses.data[i];
- BaseClass *b2 = new BaseClass(b->type->syntaxCopy(), b->protection);
- cd->baseclasses.data[i] = b2;
+ BaseClass *b = (BaseClass *)this->baseclasses.data[i];
+ BaseClass *b2 = new BaseClass(b->type->syntaxCopy(), b->protection);
+ cd->baseclasses.data[i] = b2;
}
ScopeDsymbol::syntaxCopy(cd);
@@ -231,38 +231,38 @@ void ClassDeclaration::semantic(Scope *sc)
//{ static int n; if (++n == 20) *(char*)0=0; }
- if (!ident) // if anonymous class
- { const char *id = "__anonclass";
+ if (!ident) // if anonymous class
+ { const char *id = "__anonclass";
- ident = Identifier::generateId(id);
+ ident = Identifier::generateId(id);
}
if (!sc)
- sc = scope;
+ sc = scope;
if (!parent && sc->parent && !sc->parent->isModule())
- parent = sc->parent;
+ parent = sc->parent;
type = type->semantic(loc, sc);
handle = type;
- if (!members) // if forward reference
- { //printf("\tclass '%s' is forward referenced\n", toChars());
- return;
+ if (!members) // if forward reference
+ { //printf("\tclass '%s' is forward referenced\n", toChars());
+ return;
}
if (symtab)
- { if (sizeok == 1 || !scope)
- { //printf("\tsemantic for '%s' is already completed\n", toChars());
- return; // semantic() already completed
- }
+ { if (sizeok == 1 || !scope)
+ { //printf("\tsemantic for '%s' is already completed\n", toChars());
+ return; // semantic() already completed
+ }
}
else
- symtab = new DsymbolTable();
+ symtab = new DsymbolTable();
Scope *scx = NULL;
if (scope)
- { sc = scope;
- scx = scope; // save so we don't make redundant copies
- scope = NULL;
+ { sc = scope;
+ scx = scope; // save so we don't make redundant copies
+ scope = NULL;
}
unsigned dprogress_save = Module::dprogress;
#ifdef IN_GCC
@@ -271,185 +271,185 @@ void ClassDeclaration::semantic(Scope *sc)
if (sc->stc & STCdeprecated)
{
- isdeprecated = 1;
+ isdeprecated = 1;
}
// Expand any tuples in baseclasses[]
for (i = 0; i < baseclasses.dim; )
- { BaseClass *b = (BaseClass *)baseclasses.data[i];
- b->type = b->type->semantic(loc, sc);
- Type *tb = b->type->toBasetype();
+ { BaseClass *b = (BaseClass *)baseclasses.data[i];
+ b->type = b->type->semantic(loc, sc);
+ Type *tb = b->type->toBasetype();
- if (tb->ty == Ttuple)
- { TypeTuple *tup = (TypeTuple *)tb;
- enum PROT protection = b->protection;
- baseclasses.remove(i);
- size_t dim = Parameter::dim(tup->arguments);
- for (size_t j = 0; j < dim; j++)
- { Parameter *arg = Parameter::getNth(tup->arguments, j);
- b = new BaseClass(arg->type, protection);
- baseclasses.insert(i + j, b);
- }
- }
- else
- i++;
+ if (tb->ty == Ttuple)
+ { TypeTuple *tup = (TypeTuple *)tb;
+ enum PROT protection = b->protection;
+ baseclasses.remove(i);
+ size_t dim = Parameter::dim(tup->arguments);
+ for (size_t j = 0; j < dim; j++)
+ { Parameter *arg = Parameter::getNth(tup->arguments, j);
+ b = new BaseClass(arg->type, protection);
+ baseclasses.insert(i + j, b);
+ }
+ }
+ else
+ i++;
}
// See if there's a base class as first in baseclasses[]
if (baseclasses.dim)
- { TypeClass *tc;
- BaseClass *b;
- Type *tb;
+ { TypeClass *tc;
+ BaseClass *b;
+ Type *tb;
- b = (BaseClass *)baseclasses.data[0];
- //b->type = b->type->semantic(loc, sc);
- tb = b->type->toBasetype();
- if (tb->ty != Tclass)
- { error("base type must be class or interface, not %s", b->type->toChars());
- baseclasses.remove(0);
- }
- else
- {
- tc = (TypeClass *)(tb);
+ b = (BaseClass *)baseclasses.data[0];
+ //b->type = b->type->semantic(loc, sc);
+ tb = b->type->toBasetype();
+ if (tb->ty != Tclass)
+ { error("base type must be class or interface, not %s", b->type->toChars());
+ baseclasses.remove(0);
+ }
+ else
+ {
+ tc = (TypeClass *)(tb);
- if (tc->sym->isDeprecated())
- {
- if (!isDeprecated())
- {
- // Deriving from deprecated class makes this one deprecated too
- isdeprecated = 1;
+ if (tc->sym->isDeprecated())
+ {
+ if (!isDeprecated())
+ {
+ // Deriving from deprecated class makes this one deprecated too
+ isdeprecated = 1;
- tc->checkDeprecated(loc, sc);
- }
- }
+ tc->checkDeprecated(loc, sc);
+ }
+ }
- if (tc->sym->isInterfaceDeclaration())
- ;
- else
- {
- for (ClassDeclaration *cdb = tc->sym; cdb; cdb = cdb->baseClass)
- {
- if (cdb == this)
- {
- error("circular inheritance");
- baseclasses.remove(0);
- goto L7;
- }
- }
- if (!tc->sym->symtab || tc->sym->sizeok == 0)
- { // Try to resolve forward reference
- if (sc->mustsemantic && tc->sym->scope)
- tc->sym->semantic(NULL);
- }
- if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0)
- {
- //printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars());
- //error("forward reference of base class %s", baseClass->toChars());
- // Forward reference of base class, try again later
- //printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars());
- scope = scx ? scx : new Scope(*sc);
- scope->setNoFree();
- if (tc->sym->scope)
- tc->sym->scope->module->addDeferredSemantic(tc->sym);
- scope->module->addDeferredSemantic(this);
- return;
- }
- else
- { baseClass = tc->sym;
- b->base = baseClass;
- }
- L7: ;
- }
- }
+ if (tc->sym->isInterfaceDeclaration())
+ ;
+ else
+ {
+ for (ClassDeclaration *cdb = tc->sym; cdb; cdb = cdb->baseClass)
+ {
+ if (cdb == this)
+ {
+ error("circular inheritance");
+ baseclasses.remove(0);
+ goto L7;
+ }
+ }
+ if (!tc->sym->symtab || tc->sym->sizeok == 0)
+ { // Try to resolve forward reference
+ if (sc->mustsemantic && tc->sym->scope)
+ tc->sym->semantic(NULL);
+ }
+ if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0)
+ {
+ //printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars());
+ //error("forward reference of base class %s", baseClass->toChars());
+ // Forward reference of base class, try again later
+ //printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars());
+ scope = scx ? scx : new Scope(*sc);
+ scope->setNoFree();
+ if (tc->sym->scope)
+ tc->sym->scope->module->addDeferredSemantic(tc->sym);
+ scope->module->addDeferredSemantic(this);
+ return;
+ }
+ else
+ { baseClass = tc->sym;
+ b->base = baseClass;
+ }
+ L7: ;
+ }
+ }
}
// Treat the remaining entries in baseclasses as interfaces
// Check for errors, handle forward references
for (i = (baseClass ? 1 : 0); i < baseclasses.dim; )
- { TypeClass *tc;
- BaseClass *b;
- Type *tb;
+ { TypeClass *tc;
+ BaseClass *b;
+ Type *tb;
- b = (BaseClass *)baseclasses.data[i];
- b->type = b->type->semantic(loc, sc);
- tb = b->type->toBasetype();
- if (tb->ty == Tclass)
- tc = (TypeClass *)tb;
- else
- tc = NULL;
- if (!tc || !tc->sym->isInterfaceDeclaration())
- {
- error("base type must be interface, not %s", b->type->toChars());
- baseclasses.remove(i);
- continue;
- }
- else
- {
- if (tc->sym->isDeprecated())
- {
- if (!isDeprecated())
- {
- // Deriving from deprecated class makes this one deprecated too
- isdeprecated = 1;
+ b = (BaseClass *)baseclasses.data[i];
+ b->type = b->type->semantic(loc, sc);
+ tb = b->type->toBasetype();
+ if (tb->ty == Tclass)
+ tc = (TypeClass *)tb;
+ else
+ tc = NULL;
+ if (!tc || !tc->sym->isInterfaceDeclaration())
+ {
+ error("base type must be interface, not %s", b->type->toChars());
+ baseclasses.remove(i);
+ continue;
+ }
+ else
+ {
+ if (tc->sym->isDeprecated())
+ {
+ if (!isDeprecated())
+ {
+ // Deriving from deprecated class makes this one deprecated too
+ isdeprecated = 1;
- tc->checkDeprecated(loc, sc);
- }
- }
+ tc->checkDeprecated(loc, sc);
+ }
+ }
- // Check for duplicate interfaces
- for (size_t j = (baseClass ? 1 : 0); j < i; j++)
- {
- BaseClass *b2 = (BaseClass *)baseclasses.data[j];
- if (b2->base == tc->sym)
- error("inherits from duplicate interface %s", b2->base->toChars());
- }
+ // Check for duplicate interfaces
+ for (size_t j = (baseClass ? 1 : 0); j < i; j++)
+ {
+ BaseClass *b2 = (BaseClass *)baseclasses.data[j];
+ if (b2->base == tc->sym)
+ error("inherits from duplicate interface %s", b2->base->toChars());
+ }
- if (!tc->sym->symtab)
- { // Try to resolve forward reference
- if (sc->mustsemantic && tc->sym->scope)
- tc->sym->semantic(NULL);
- }
+ if (!tc->sym->symtab)
+ { // Try to resolve forward reference
+ if (sc->mustsemantic && tc->sym->scope)
+ tc->sym->semantic(NULL);
+ }
- b->base = tc->sym;
- if (!b->base->symtab || b->base->scope)
- {
- //error("forward reference of base class %s", baseClass->toChars());
- // Forward reference of base, try again later
- //printf("\ttry later, forward reference of base %s\n", baseClass->toChars());
- scope = scx ? scx : new Scope(*sc);
- scope->setNoFree();
- if (tc->sym->scope)
- tc->sym->scope->module->addDeferredSemantic(tc->sym);
- scope->module->addDeferredSemantic(this);
- return;
- }
- }
- i++;
+ b->base = tc->sym;
+ if (!b->base->symtab || b->base->scope)
+ {
+ //error("forward reference of base class %s", baseClass->toChars());
+ // Forward reference of base, try again later
+ //printf("\ttry later, forward reference of base %s\n", baseClass->toChars());
+ scope = scx ? scx : new Scope(*sc);
+ scope->setNoFree();
+ if (tc->sym->scope)
+ tc->sym->scope->module->addDeferredSemantic(tc->sym);
+ scope->module->addDeferredSemantic(this);
+ return;
+ }
+ }
+ i++;
}
// If no base class, and this is not an Object, use Object as base class
if (!baseClass && ident != Id::Object)
{
- // BUG: what if Object is redefined in an inner scope?
- Type *tbase = new TypeIdentifier(0, Id::Object);
- BaseClass *b;
- TypeClass *tc;
- Type *bt;
+ // BUG: what if Object is redefined in an inner scope?
+ Type *tbase = new TypeIdentifier(0, Id::Object);
+ BaseClass *b;
+ TypeClass *tc;
+ Type *bt;
- if (!object)
- {
- error("missing or corrupt object.d");
- fatal();
- }
- bt = tbase->semantic(loc, sc)->toBasetype();
- b = new BaseClass(bt, PROTpublic);
- baseclasses.shift(b);
- assert(b->type->ty == Tclass);
- tc = (TypeClass *)(b->type);
- baseClass = tc->sym;
- assert(!baseClass->isInterfaceDeclaration());
- b->base = baseClass;
+ if (!object)
+ {
+ error("missing or corrupt object.d");
+ fatal();
+ }
+ bt = tbase->semantic(loc, sc)->toBasetype();
+ b = new BaseClass(bt, PROTpublic);
+ baseclasses.shift(b);
+ assert(b->type->ty == Tclass);
+ tc = (TypeClass *)(b->type);
+ baseClass = tc->sym;
+ assert(!baseClass->isInterfaceDeclaration());
+ b->base = baseClass;
}
interfaces_dim = baseclasses.dim;
@@ -458,26 +458,26 @@ void ClassDeclaration::semantic(Scope *sc)
if (baseClass)
{
- if (baseClass->storage_class & STCfinal)
- error("cannot inherit from final class %s", baseClass->toChars());
+ if (baseClass->storage_class & STCfinal)
+ error("cannot inherit from final class %s", baseClass->toChars());
- interfaces_dim--;
- interfaces++;
+ interfaces_dim--;
+ interfaces++;
- // Copy vtbl[] from base class
- vtbl.setDim(baseClass->vtbl.dim);
- memcpy(vtbl.data, baseClass->vtbl.data, sizeof(void *) * vtbl.dim);
+ // Copy vtbl[] from base class
+ vtbl.setDim(baseClass->vtbl.dim);
+ memcpy(vtbl.data, baseClass->vtbl.data, sizeof(void *) * vtbl.dim);
- // Inherit properties from base class
- com = baseClass->isCOMclass();
- isscope = baseClass->isscope;
- vthis = baseClass->vthis;
+ // Inherit properties from base class
+ com = baseClass->isCOMclass();
+ isscope = baseClass->isscope;
+ vthis = baseClass->vthis;
}
else
{
- // No base class, so this is the root of the class hierarchy
- vtbl.setDim(0);
- vtbl.push(this); // leave room for classinfo as first member
+ // No base class, so this is the root of the class hierarchy
+ vtbl.setDim(0);
+ vtbl.push(this); // leave room for classinfo as first member
}
protection = sc->protection;
@@ -485,95 +485,95 @@ void ClassDeclaration::semantic(Scope *sc)
if (sizeok == 0)
{
- interfaceSemantic(sc);
+ interfaceSemantic(sc);
- for (i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->addMember(sc, this, 1);
- }
+ for (i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->addMember(sc, this, 1);
+ }
- /* If this is a nested class, add the hidden 'this'
- * member which is a pointer to the enclosing scope.
- */
- if (vthis) // if inheriting from nested class
- { // Use the base class's 'this' member
- isnested = 1;
- if (storage_class & STCstatic)
- error("static class cannot inherit from nested class %s", baseClass->toChars());
- if (toParent2() != baseClass->toParent2())
- {
- if (toParent2())
- {
- error("is nested within %s, but super class %s is nested within %s",
- toParent2()->toChars(),
- baseClass->toChars(),
- baseClass->toParent2()->toChars());
- }
- else
- {
- error("is not nested, but super class %s is nested within %s",
- baseClass->toChars(),
- baseClass->toParent2()->toChars());
- }
- isnested = 0;
- }
- }
- else if (!(storage_class & STCstatic))
- { Dsymbol *s = toParent2();
- if (s)
- {
- AggregateDeclaration *ad = s->isClassDeclaration();
- FuncDeclaration *fd = s->isFuncDeclaration();
+ /* If this is a nested class, add the hidden 'this'
+ * member which is a pointer to the enclosing scope.
+ */
+ if (vthis) // if inheriting from nested class
+ { // Use the base class's 'this' member
+ isnested = 1;
+ if (storage_class & STCstatic)
+ error("static class cannot inherit from nested class %s", baseClass->toChars());
+ if (toParent2() != baseClass->toParent2())
+ {
+ if (toParent2())
+ {
+ error("is nested within %s, but super class %s is nested within %s",
+ toParent2()->toChars(),
+ baseClass->toChars(),
+ baseClass->toParent2()->toChars());
+ }
+ else
+ {
+ error("is not nested, but super class %s is nested within %s",
+ baseClass->toChars(),
+ baseClass->toParent2()->toChars());
+ }
+ isnested = 0;
+ }
+ }
+ else if (!(storage_class & STCstatic))
+ { Dsymbol *s = toParent2();
+ if (s)
+ {
+ AggregateDeclaration *ad = s->isClassDeclaration();
+ FuncDeclaration *fd = s->isFuncDeclaration();
- if (ad || fd)
- { isnested = 1;
- Type *t;
- if (ad)
- t = ad->handle;
- else if (fd)
- { AggregateDeclaration *ad = fd->isMember2();
- if (ad)
- t = ad->handle;
- else
- {
- t = new TypePointer(Type::tvoid);
- t = t->semantic(0, sc);
- }
- }
- else
- assert(0);
- assert(!vthis);
- vthis = new ThisDeclaration(loc, t);
- members->push(vthis);
- }
- }
- }
+ if (ad || fd)
+ { isnested = 1;
+ Type *t;
+ if (ad)
+ t = ad->handle;
+ else if (fd)
+ { AggregateDeclaration *ad = fd->isMember2();
+ if (ad)
+ t = ad->handle;
+ else
+ {
+ t = new TypePointer(Type::tvoid);
+ t = t->semantic(0, sc);
+ }
+ }
+ else
+ assert(0);
+ assert(!vthis);
+ vthis = new ThisDeclaration(loc, t);
+ members->push(vthis);
+ }
+ }
+ }
}
if (storage_class & STCauto)
- error("storage class has no effect: auto");
+ error("storage class has no effect: auto");
if (storage_class & STCscope)
- isscope = 1;
+ isscope = 1;
if (storage_class & STCabstract)
- isabstract = 1;
+ isabstract = 1;
sc = sc->push(this);
sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic |
- STCabstract | STCdeprecated);
+ STCabstract | STCdeprecated);
sc->parent = this;
sc->inunion = 0;
if (isCOMclass())
{
#if _WIN32
- sc->linkage = LINKwindows;
+ sc->linkage = LINKwindows;
#else
- /* This enables us to use COM objects under Linux and
- * work with things like XPCOM
- */
- sc->linkage = LINKc;
+ /* This enables us to use COM objects under Linux and
+ * work with things like XPCOM
+ */
+ sc->linkage = LINKc;
#endif
}
sc->protection = PROTpublic;
@@ -581,14 +581,14 @@ void ClassDeclaration::semantic(Scope *sc)
sc->structalign = 8;
structalign = sc->structalign;
if (baseClass)
- { sc->offset = baseClass->structsize;
- alignsize = baseClass->alignsize;
-// if (isnested)
-// sc->offset += PTRSIZE; // room for uplevel context pointer
+ { sc->offset = baseClass->structsize;
+ alignsize = baseClass->alignsize;
+// if (isnested)
+// sc->offset += PTRSIZE; // room for uplevel context pointer
}
else
- { sc->offset = PTRSIZE * 2; // allow room for __vptr and __monitor
- alignsize = PTRSIZE;
+ { sc->offset = PTRSIZE * 2; // allow room for __vptr and __monitor
+ alignsize = PTRSIZE;
}
structsize = sc->offset;
Scope scsave = *sc;
@@ -599,40 +599,40 @@ void ClassDeclaration::semantic(Scope *sc)
* resolve individual members like enums.
*/
for (i = 0; i < members_dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- /* There are problems doing this in the general case because
- * Scope keeps track of things like 'offset'
- */
- if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident))
- {
- //printf("setScope %s %s\n", s->kind(), s->toChars());
- s->setScope(sc);
- }
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ /* There are problems doing this in the general case because
+ * Scope keeps track of things like 'offset'
+ */
+ if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident))
+ {
+ //printf("setScope %s %s\n", s->kind(), s->toChars());
+ s->setScope(sc);
+ }
}
for (i = 0; i < members_dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- s->semantic(sc);
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ s->semantic(sc);
}
if (sizeok == 2)
- { // semantic() failed because of forward references.
- // Unwind what we did, and defer it for later
- fields.setDim(0);
- structsize = 0;
- alignsize = 0;
- structalign = 0;
+ { // semantic() failed because of forward references.
+ // Unwind what we did, and defer it for later
+ fields.setDim(0);
+ structsize = 0;
+ alignsize = 0;
+ structalign = 0;
- sc = sc->pop();
+ sc = sc->pop();
- scope = scx ? scx : new Scope(*sc);
- scope->setNoFree();
- scope->module->addDeferredSemantic(this);
+ scope = scx ? scx : new Scope(*sc);
+ scope->setNoFree();
+ scope->module->addDeferredSemantic(this);
- Module::dprogress = dprogress_save;
+ Module::dprogress = dprogress_save;
- //printf("\tsemantic('%s') failed due to forward references\n", toChars());
- return;
+ //printf("\tsemantic('%s') failed due to forward references\n", toChars());
+ return;
}
//printf("\tsemantic('%s') successful\n", toChars());
@@ -645,15 +645,15 @@ void ClassDeclaration::semantic(Scope *sc)
*/
ctor = (CtorDeclaration *)search(0, Id::ctor, 0);
if (ctor && (ctor->toParent() != this || !ctor->isCtorDeclaration()))
- ctor = NULL;
+ ctor = NULL;
// dtor = (DtorDeclaration *)search(Id::dtor, 0);
// if (dtor && dtor->toParent() != this)
-// dtor = NULL;
+// dtor = NULL;
// inv = (InvariantDeclaration *)search(Id::classInvariant, 0);
// if (inv && inv->toParent() != this)
-// inv = NULL;
+// inv = NULL;
// Can be in base class
aggNew = (NewDeclaration *)search(0, Id::classNew, 0);
@@ -664,46 +664,46 @@ void ClassDeclaration::semantic(Scope *sc)
// this() { }
if (!ctor && baseClass && baseClass->ctor)
{
- //printf("Creating default this(){} for class %s\n", toChars());
- ctor = new CtorDeclaration(loc, 0, NULL, 0);
- ctor->fbody = new CompoundStatement(0, new Statements());
- members->push(ctor);
- ctor->addMember(sc, this, 1);
- *sc = scsave; // why? What about sc->nofree?
- sc->offset = structsize;
- ctor->semantic(sc);
- defaultCtor = ctor;
+ //printf("Creating default this(){} for class %s\n", toChars());
+ ctor = new CtorDeclaration(loc, 0, NULL, 0);
+ ctor->fbody = new CompoundStatement(0, new Statements());
+ members->push(ctor);
+ ctor->addMember(sc, this, 1);
+ *sc = scsave; // why? What about sc->nofree?
+ sc->offset = structsize;
+ ctor->semantic(sc);
+ defaultCtor = ctor;
}
#if 0
if (baseClass)
- { if (!aggDelete)
- aggDelete = baseClass->aggDelete;
- if (!aggNew)
- aggNew = baseClass->aggNew;
+ { if (!aggDelete)
+ aggDelete = baseClass->aggDelete;
+ if (!aggNew)
+ aggNew = baseClass->aggNew;
}
#endif
// Allocate instance of each new interface
for (i = 0; i < vtblInterfaces->dim; i++)
{
- BaseClass *b = (BaseClass *)vtblInterfaces->data[i];
- unsigned thissize = PTRSIZE;
+ BaseClass *b = (BaseClass *)vtblInterfaces->data[i];
+ unsigned thissize = PTRSIZE;
- alignmember(structalign, thissize, &sc->offset);
- assert(b->offset == 0);
- b->offset = sc->offset;
+ alignmember(structalign, thissize, &sc->offset);
+ assert(b->offset == 0);
+ b->offset = sc->offset;
- // Take care of single inheritance offsets
- while (b->baseInterfaces_dim)
- {
- b = &b->baseInterfaces[0];
- b->offset = sc->offset;
- }
+ // Take care of single inheritance offsets
+ while (b->baseInterfaces_dim)
+ {
+ b = &b->baseInterfaces[0];
+ b->offset = sc->offset;
+ }
- sc->offset += thissize;
- if (alignsize < thissize)
- alignsize = thissize;
+ sc->offset += thissize;
+ if (alignsize < thissize)
+ alignsize = thissize;
}
structsize = sc->offset;
sizeok = 1;
@@ -717,9 +717,9 @@ void ClassDeclaration::semantic(Scope *sc)
// Fill in base class vtbl[]s
for (i = 0; i < vtblInterfaces->dim; i++)
{
- BaseClass *b = (BaseClass *)vtblInterfaces->data[i];
+ BaseClass *b = (BaseClass *)vtblInterfaces->data[i];
- //b->fillVtbl(this, &b->vtbl, 1);
+ //b->fillVtbl(this, &b->vtbl, 1);
}
#endif
//printf("-ClassDeclaration::semantic(%s), type = %p\n", toChars(), type);
@@ -729,36 +729,36 @@ void ClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (!isAnonymous())
{
- buf->printf("%s ", kind());
- buf->writestring(toChars());
- if (baseclasses.dim)
- buf->writestring(" : ");
+ buf->printf("%s ", kind());
+ buf->writestring(toChars());
+ if (baseclasses.dim)
+ buf->writestring(" : ");
}
for (int i = 0; i < baseclasses.dim; i++)
{
- BaseClass *b = (BaseClass *)baseclasses.data[i];
+ BaseClass *b = (BaseClass *)baseclasses.data[i];
- if (i)
- buf->writeByte(',');
- //buf->writestring(b->base->ident->toChars());
- b->type->toCBuffer(buf, NULL, hgs);
+ if (i)
+ buf->writeByte(',');
+ //buf->writestring(b->base->ident->toChars());
+ b->type->toCBuffer(buf, NULL, hgs);
}
if (members)
{
- buf->writenl();
- buf->writeByte('{');
- buf->writenl();
- for (int i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
+ buf->writenl();
+ buf->writeByte('{');
+ buf->writenl();
+ for (int i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
- buf->writestring(" ");
- s->toCBuffer(buf, hgs);
- }
- buf->writestring("}");
+ buf->writestring(" ");
+ s->toCBuffer(buf, hgs);
+ }
+ buf->writestring("}");
}
else
- buf->writeByte(';');
+ buf->writeByte(';');
buf->writenl();
}
@@ -782,13 +782,13 @@ void ClassDeclaration::defineRef(Dsymbol *s)
int ClassDeclaration::isBaseOf2(ClassDeclaration *cd)
{
if (!cd)
- return 0;
+ return 0;
//printf("ClassDeclaration::isBaseOf2(this = '%s', cd = '%s')\n", toChars(), cd->toChars());
for (int i = 0; i < cd->baseclasses.dim; i++)
- { BaseClass *b = (BaseClass *)cd->baseclasses.data[i];
+ { BaseClass *b = (BaseClass *)cd->baseclasses.data[i];
- if (b->base == this || isBaseOf2(b->base))
- return 1;
+ if (b->base == this || isBaseOf2(b->base))
+ return 1;
}
return 0;
}
@@ -801,20 +801,20 @@ int ClassDeclaration::isBaseOf(ClassDeclaration *cd, int *poffset)
{
//printf("ClassDeclaration::isBaseOf(this = '%s', cd = '%s')\n", toChars(), cd->toChars());
if (poffset)
- *poffset = 0;
+ *poffset = 0;
while (cd)
{
- if (this == cd->baseClass)
- return 1;
+ if (this == cd->baseClass)
+ return 1;
- /* cd->baseClass might not be set if cd is forward referenced.
- */
- if (!cd->baseClass && cd->baseclasses.dim && !cd->isInterfaceDeclaration())
- {
- cd->error("base class is forward referenced by %s", toChars());
- }
+ /* cd->baseClass might not be set if cd is forward referenced.
+ */
+ if (!cd->baseClass && cd->baseclasses.dim && !cd->isInterfaceDeclaration())
+ {
+ cd->error("base class is forward referenced by %s", toChars());
+ }
- cd = cd->baseClass;
+ cd = cd->baseClass;
}
return 0;
}
@@ -825,44 +825,44 @@ Dsymbol *ClassDeclaration::search(Loc loc, Identifier *ident, int flags)
//printf("%s.ClassDeclaration::search('%s')\n", toChars(), ident->toChars());
if (scope)
- { Scope *sc = scope;
- sc->mustsemantic++;
- semantic(sc);
- sc->mustsemantic--;
+ { Scope *sc = scope;
+ sc->mustsemantic++;
+ semantic(sc);
+ sc->mustsemantic--;
}
if (!members || !symtab || scope)
{
- error("is forward referenced when looking for '%s'", ident->toChars());
- //*(char*)0=0;
- return NULL;
+ error("is forward referenced when looking for '%s'", ident->toChars());
+ //*(char*)0=0;
+ return NULL;
}
s = ScopeDsymbol::search(loc, ident, flags);
if (!s)
{
- // Search bases classes in depth-first, left to right order
+ // Search bases classes in depth-first, left to right order
- int i;
+ int i;
- for (i = 0; i < baseclasses.dim; i++)
- {
- BaseClass *b = (BaseClass *)baseclasses.data[i];
+ for (i = 0; i < baseclasses.dim; i++)
+ {
+ BaseClass *b = (BaseClass *)baseclasses.data[i];
- if (b->base)
- {
- if (!b->base->symtab)
- error("base %s is forward referenced", b->base->ident->toChars());
- else
- {
- s = b->base->search(loc, ident, flags);
- if (s == this) // happens if s is nested in this and derives from this
- s = NULL;
- else if (s)
- break;
- }
- }
- }
+ if (b->base)
+ {
+ if (!b->base->symtab)
+ error("base %s is forward referenced", b->base->ident->toChars());
+ else
+ {
+ s = b->base->search(loc, ident, flags);
+ if (s == this) // happens if s is nested in this and derives from this
+ s = NULL;
+ else if (s)
+ break;
+ }
+ }
+ }
}
return s;
}
@@ -884,11 +884,11 @@ int ClassDeclaration::isFuncHidden(FuncDeclaration *fd)
//printf("ClassDeclaration::isFuncHidden(class = %s, fd = %s)\n", toChars(), fd->toChars());
Dsymbol *s = search(0, fd->ident, 4|2);
if (!s)
- { //printf("not found\n");
- /* Because, due to a hack, if there are multiple definitions
- * of fd->ident, NULL is returned.
- */
- return 0;
+ { //printf("not found\n");
+ /* Because, due to a hack, if there are multiple definitions
+ * of fd->ident, NULL is returned.
+ */
+ return 0;
}
FuncDeclaration *fdstart = s->toAlias()->isFuncDeclaration();
//printf("%s fdstart = %p\n", s->kind(), fdstart);
@@ -909,26 +909,26 @@ FuncDeclaration *ClassDeclaration::findFunc(Identifier *ident, TypeFunction *tf)
Array *vtbl = &cd->vtbl;
while (1)
{
- for (size_t i = 0; i < vtbl->dim; i++)
- {
- FuncDeclaration *fd = ((Dsymbol*)vtbl->data[i])->isFuncDeclaration();
- if (!fd)
- continue; // the first entry might be a ClassInfo
+ for (size_t i = 0; i < vtbl->dim; i++)
+ {
+ FuncDeclaration *fd = ((Dsymbol*)vtbl->data[i])->isFuncDeclaration();
+ if (!fd)
+ continue; // the first entry might be a ClassInfo
- //printf("\t[%d] = %s\n", i, fd->toChars());
- if (ident == fd->ident &&
- //tf->equals(fd->type)
- fd->type->covariant(tf) == 1
- )
- { //printf("\t\tfound\n");
- return fd;
- }
- //else printf("\t\t%d\n", fd->type->covariant(tf));
- }
- if (!cd)
- break;
- vtbl = &cd->vtblFinal;
- cd = cd->baseClass;
+ //printf("\t[%d] = %s\n", i, fd->toChars());
+ if (ident == fd->ident &&
+ //tf->equals(fd->type)
+ fd->type->covariant(tf) == 1
+ )
+ { //printf("\t\tfound\n");
+ return fd;
+ }
+ //else printf("\t\t%d\n", fd->type->covariant(tf));
+ }
+ if (!cd)
+ break;
+ vtbl = &cd->vtblFinal;
+ cd = cd->baseClass;
}
return NULL;
@@ -941,15 +941,15 @@ void ClassDeclaration::interfaceSemantic(Scope *sc)
for (size_t i = 0; i < interfaces_dim; i++)
{
- BaseClass *b = interfaces[i];
+ BaseClass *b = interfaces[i];
- // If this is an interface, and it derives from a COM interface,
- // then this is a COM interface too.
- if (b->base->isCOMinterface())
- com = 1;
+ // If this is an interface, and it derives from a COM interface,
+ // then this is a COM interface too.
+ if (b->base->isCOMinterface())
+ com = 1;
- vtblInterfaces->push(b);
- b->copyBaseInterfaces(vtblInterfaces);
+ vtblInterfaces->push(b);
+ b->copyBaseInterfaces(vtblInterfaces);
}
}
@@ -980,17 +980,17 @@ int ClassDeclaration::isCPPinterface()
int ClassDeclaration::isAbstract()
{
if (isabstract)
- return TRUE;
+ return TRUE;
for (int i = 1; i < vtbl.dim; i++)
{
- FuncDeclaration *fd = ((Dsymbol *)vtbl.data[i])->isFuncDeclaration();
+ FuncDeclaration *fd = ((Dsymbol *)vtbl.data[i])->isFuncDeclaration();
- //printf("\tvtbl[%d] = %p\n", i, fd);
- if (!fd || fd->isAbstract())
- {
- isabstract |= 1;
- return TRUE;
- }
+ //printf("\tvtbl[%d] = %p\n", i, fd);
+ if (!fd || fd->isAbstract())
+ {
+ isabstract |= 1;
+ return TRUE;
+ }
}
return FALSE;
}
@@ -1040,8 +1040,8 @@ InterfaceDeclaration::InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses
: ClassDeclaration(loc, id, baseclasses)
{
com = 0;
- if (id == Id::IUnknown) // IUnknown is the root of all COM objects
- com = 1;
+ if (id == Id::IUnknown) // IUnknown is the root of all COM objects
+ com = 1;
}
Dsymbol *InterfaceDeclaration::syntaxCopy(Dsymbol *s)
@@ -1049,9 +1049,9 @@ Dsymbol *InterfaceDeclaration::syntaxCopy(Dsymbol *s)
InterfaceDeclaration *id;
if (s)
- id = (InterfaceDeclaration *)s;
+ id = (InterfaceDeclaration *)s;
else
- id = new InterfaceDeclaration(loc, ident, NULL);
+ id = new InterfaceDeclaration(loc, ident, NULL);
ClassDeclaration::syntaxCopy(id);
return id;
@@ -1062,113 +1062,113 @@ void InterfaceDeclaration::semantic(Scope *sc)
//printf("InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type);
if (inuse)
- return;
+ return;
if (!sc)
- sc = scope;
+ sc = scope;
if (!parent && sc->parent && !sc->parent->isModule())
- parent = sc->parent;
+ parent = sc->parent;
type = type->semantic(loc, sc);
handle = type;
- if (!members) // if forward reference
- { //printf("\tinterface '%s' is forward referenced\n", toChars());
- return;
+ if (!members) // if forward reference
+ { //printf("\tinterface '%s' is forward referenced\n", toChars());
+ return;
}
- if (symtab) // if already done
- { if (!scope)
- return;
+ if (symtab) // if already done
+ { if (!scope)
+ return;
}
else
- symtab = new DsymbolTable();
+ symtab = new DsymbolTable();
Scope *scx = NULL;
if (scope)
- { sc = scope;
- scx = scope; // save so we don't make redundant copies
- scope = NULL;
+ { sc = scope;
+ scx = scope; // save so we don't make redundant copies
+ scope = NULL;
}
if (sc->stc & STCdeprecated)
{
- isdeprecated = 1;
+ isdeprecated = 1;
}
// Expand any tuples in baseclasses[]
for (i = 0; i < baseclasses.dim; )
- { BaseClass *b = (BaseClass *)baseclasses.data[0];
- b->type = b->type->semantic(loc, sc);
- Type *tb = b->type->toBasetype();
+ { BaseClass *b = (BaseClass *)baseclasses.data[0];
+ b->type = b->type->semantic(loc, sc);
+ Type *tb = b->type->toBasetype();
- if (tb->ty == Ttuple)
- { TypeTuple *tup = (TypeTuple *)tb;
- enum PROT protection = b->protection;
- baseclasses.remove(i);
- size_t dim = Parameter::dim(tup->arguments);
- for (size_t j = 0; j < dim; j++)
- { Parameter *arg = Parameter::getNth(tup->arguments, j);
- b = new BaseClass(arg->type, protection);
- baseclasses.insert(i + j, b);
- }
- }
- else
- i++;
+ if (tb->ty == Ttuple)
+ { TypeTuple *tup = (TypeTuple *)tb;
+ enum PROT protection = b->protection;
+ baseclasses.remove(i);
+ size_t dim = Parameter::dim(tup->arguments);
+ for (size_t j = 0; j < dim; j++)
+ { Parameter *arg = Parameter::getNth(tup->arguments, j);
+ b = new BaseClass(arg->type, protection);
+ baseclasses.insert(i + j, b);
+ }
+ }
+ else
+ i++;
}
// Check for errors, handle forward references
for (i = 0; i < baseclasses.dim; )
- { TypeClass *tc;
- BaseClass *b;
- Type *tb;
+ { TypeClass *tc;
+ BaseClass *b;
+ Type *tb;
- b = (BaseClass *)baseclasses.data[i];
- b->type = b->type->semantic(loc, sc);
- tb = b->type->toBasetype();
- if (tb->ty == Tclass)
- tc = (TypeClass *)tb;
- else
- tc = NULL;
- if (!tc || !tc->sym->isInterfaceDeclaration())
- {
- error("base type must be interface, not %s", b->type->toChars());
- baseclasses.remove(i);
- continue;
- }
- else
- {
- // Check for duplicate interfaces
- for (size_t j = 0; j < i; j++)
- {
- BaseClass *b2 = (BaseClass *)baseclasses.data[j];
- if (b2->base == tc->sym)
- error("inherits from duplicate interface %s", b2->base->toChars());
- }
+ b = (BaseClass *)baseclasses.data[i];
+ b->type = b->type->semantic(loc, sc);
+ tb = b->type->toBasetype();
+ if (tb->ty == Tclass)
+ tc = (TypeClass *)tb;
+ else
+ tc = NULL;
+ if (!tc || !tc->sym->isInterfaceDeclaration())
+ {
+ error("base type must be interface, not %s", b->type->toChars());
+ baseclasses.remove(i);
+ continue;
+ }
+ else
+ {
+ // Check for duplicate interfaces
+ for (size_t j = 0; j < i; j++)
+ {
+ BaseClass *b2 = (BaseClass *)baseclasses.data[j];
+ if (b2->base == tc->sym)
+ error("inherits from duplicate interface %s", b2->base->toChars());
+ }
- b->base = tc->sym;
- if (b->base == this || isBaseOf2(b->base))
- {
- error("circular inheritance of interface");
- baseclasses.remove(i);
- continue;
- }
- if (!b->base->symtab)
- { // Try to resolve forward reference
- if (sc->mustsemantic && b->base->scope)
- b->base->semantic(NULL);
- }
- if (!b->base->symtab || b->base->scope || b->base->inuse)
- {
- //error("forward reference of base class %s", baseClass->toChars());
- // Forward reference of base, try again later
- //printf("\ttry later, forward reference of base %s\n", b->base->toChars());
- scope = scx ? scx : new Scope(*sc);
- scope->setNoFree();
- scope->module->addDeferredSemantic(this);
- return;
- }
- }
- i++;
+ b->base = tc->sym;
+ if (b->base == this || isBaseOf2(b->base))
+ {
+ error("circular inheritance of interface");
+ baseclasses.remove(i);
+ continue;
+ }
+ if (!b->base->symtab)
+ { // Try to resolve forward reference
+ if (sc->mustsemantic && b->base->scope)
+ b->base->semantic(NULL);
+ }
+ if (!b->base->symtab || b->base->scope || b->base->inuse)
+ {
+ //error("forward reference of base class %s", baseClass->toChars());
+ // Forward reference of base, try again later
+ //printf("\ttry later, forward reference of base %s\n", b->base->toChars());
+ scope = scx ? scx : new Scope(*sc);
+ scope->setNoFree();
+ scope->module->addDeferredSemantic(this);
+ return;
+ }
+ }
+ i++;
}
interfaces_dim = baseclasses.dim;
@@ -1177,56 +1177,56 @@ void InterfaceDeclaration::semantic(Scope *sc)
interfaceSemantic(sc);
if (vtblOffset())
- vtbl.push(this); // leave room at vtbl[0] for classinfo
+ vtbl.push(this); // leave room at vtbl[0] for classinfo
// Cat together the vtbl[]'s from base interfaces
for (i = 0; i < interfaces_dim; i++)
- { BaseClass *b = interfaces[i];
+ { BaseClass *b = interfaces[i];
- // Skip if b has already appeared
- for (int k = 0; k < i; k++)
- {
- if (b == interfaces[k])
- goto Lcontinue;
- }
+ // Skip if b has already appeared
+ for (int k = 0; k < i; k++)
+ {
+ if (b == interfaces[k])
+ goto Lcontinue;
+ }
- // Copy vtbl[] from base class
- if (b->base->vtblOffset())
- { int d = b->base->vtbl.dim;
- if (d > 1)
- {
- vtbl.reserve(d - 1);
- for (int j = 1; j < d; j++)
- vtbl.push(b->base->vtbl.data[j]);
- }
- }
- else
- {
- vtbl.append(&b->base->vtbl);
- }
+ // Copy vtbl[] from base class
+ if (b->base->vtblOffset())
+ { int d = b->base->vtbl.dim;
+ if (d > 1)
+ {
+ vtbl.reserve(d - 1);
+ for (int j = 1; j < d; j++)
+ vtbl.push(b->base->vtbl.data[j]);
+ }
+ }
+ else
+ {
+ vtbl.append(&b->base->vtbl);
+ }
Lcontinue:
- ;
+ ;
}
for (i = 0; i < members->dim; i++)
{
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->addMember(sc, this, 1);
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->addMember(sc, this, 1);
}
sc = sc->push(this);
sc->parent = this;
if (isCOMinterface())
- sc->linkage = LINKwindows;
+ sc->linkage = LINKwindows;
sc->structalign = 8;
structalign = sc->structalign;
sc->offset = PTRSIZE * 2;
inuse++;
for (i = 0; i < members->dim; i++)
{
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->semantic(sc);
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->semantic(sc);
}
inuse--;
//members->print();
@@ -1239,11 +1239,11 @@ void InterfaceDeclaration::semantic(Scope *sc)
* Determine if 'this' is a base class of cd.
* (Actually, if it is an interface supported by cd)
* Output:
- * *poffset offset to start of class
- * OFFSET_RUNTIME must determine offset at runtime
+ * *poffset offset to start of class
+ * OFFSET_RUNTIME must determine offset at runtime
* Returns:
- * 0 not a base
- * 1 is a base
+ * 0 not a base
+ * 1 is a base
*/
int InterfaceDeclaration::isBaseOf(ClassDeclaration *cd, int *poffset)
@@ -1254,31 +1254,31 @@ int InterfaceDeclaration::isBaseOf(ClassDeclaration *cd, int *poffset)
assert(!baseClass);
for (j = 0; j < cd->interfaces_dim; j++)
{
- BaseClass *b = cd->interfaces[j];
+ BaseClass *b = cd->interfaces[j];
- //printf("\tbase %s\n", b->base->toChars());
- if (this == b->base)
- {
- //printf("\tfound at offset %d\n", b->offset);
- if (poffset)
- { *poffset = b->offset;
- if (j && cd->isInterfaceDeclaration())
- *poffset = OFFSET_RUNTIME;
- }
- return 1;
- }
- if (isBaseOf(b, poffset))
- { if (j && poffset && cd->isInterfaceDeclaration())
- *poffset = OFFSET_RUNTIME;
- return 1;
- }
+ //printf("\tbase %s\n", b->base->toChars());
+ if (this == b->base)
+ {
+ //printf("\tfound at offset %d\n", b->offset);
+ if (poffset)
+ { *poffset = b->offset;
+ if (j && cd->isInterfaceDeclaration())
+ *poffset = OFFSET_RUNTIME;
+ }
+ return 1;
+ }
+ if (isBaseOf(b, poffset))
+ { if (j && poffset && cd->isInterfaceDeclaration())
+ *poffset = OFFSET_RUNTIME;
+ return 1;
+ }
}
if (cd->baseClass && isBaseOf(cd->baseClass, poffset))
- return 1;
+ return 1;
if (poffset)
- *poffset = 0;
+ *poffset = 0;
return 0;
}
@@ -1288,25 +1288,25 @@ int InterfaceDeclaration::isBaseOf(BaseClass *bc, int *poffset)
//printf("%s.InterfaceDeclaration::isBaseOf(bc = '%s')\n", toChars(), bc->base->toChars());
for (unsigned j = 0; j < bc->baseInterfaces_dim; j++)
{
- BaseClass *b = &bc->baseInterfaces[j];
+ BaseClass *b = &bc->baseInterfaces[j];
- if (this == b->base)
- {
- if (poffset)
- { *poffset = b->offset;
- if (j && bc->base->isInterfaceDeclaration())
- *poffset = OFFSET_RUNTIME;
- }
- return 1;
- }
- if (isBaseOf(b, poffset))
- { if (j && poffset && bc->base->isInterfaceDeclaration())
- *poffset = OFFSET_RUNTIME;
- return 1;
- }
+ if (this == b->base)
+ {
+ if (poffset)
+ { *poffset = b->offset;
+ if (j && bc->base->isInterfaceDeclaration())
+ *poffset = OFFSET_RUNTIME;
+ }
+ return 1;
+ }
+ if (isBaseOf(b, poffset))
+ { if (j && poffset && bc->base->isInterfaceDeclaration())
+ *poffset = OFFSET_RUNTIME;
+ return 1;
+ }
}
if (poffset)
- *poffset = 0;
+ *poffset = 0;
return 0;
}
@@ -1320,7 +1320,7 @@ int InterfaceDeclaration::isBaseOf(BaseClass *bc, int *poffset)
int InterfaceDeclaration::vtblOffset()
{
if (isCOMinterface())
- return 0;
+ return 0;
return 1;
}
@@ -1367,12 +1367,12 @@ BaseClass::BaseClass(Type *type, enum PROT protection)
/****************************************
* Fill in vtbl[] for base class based on member functions of class cd.
* Input:
- * vtbl if !=NULL, fill it in
- * newinstance !=0 means all entries must be filled in by members
- * of cd, not members of any base classes of cd.
+ * vtbl if !=NULL, fill it in
+ * newinstance !=0 means all entries must be filled in by members
+ * of cd, not members of any base classes of cd.
* Returns:
- * !=0 if any entries were filled in by members of cd (not exclusively
- * by base classes)
+ * !=0 if any entries were filled in by members of cd (not exclusively
+ * by base classes)
*/
int BaseClass::fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance)
@@ -1383,49 +1383,49 @@ int BaseClass::fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance)
//printf("BaseClass::fillVtbl(this='%s', cd='%s')\n", base->toChars(), cd->toChars());
if (vtbl)
- vtbl->setDim(base->vtbl.dim);
+ vtbl->setDim(base->vtbl.dim);
// first entry is ClassInfo reference
for (j = base->vtblOffset(); j < base->vtbl.dim; j++)
{
- FuncDeclaration *ifd = ((Dsymbol *)base->vtbl.data[j])->isFuncDeclaration();
- FuncDeclaration *fd;
- TypeFunction *tf;
+ FuncDeclaration *ifd = ((Dsymbol *)base->vtbl.data[j])->isFuncDeclaration();
+ FuncDeclaration *fd;
+ TypeFunction *tf;
- //printf(" vtbl[%d] is '%s'\n", j, ifd ? ifd->toChars() : "null");
+ //printf(" vtbl[%d] is '%s'\n", j, ifd ? ifd->toChars() : "null");
- assert(ifd);
- // Find corresponding function in this class
- tf = (ifd->type->ty == Tfunction) ? (TypeFunction *)(ifd->type) : NULL;
- fd = cd->findFunc(ifd->ident, tf);
- if (fd && !fd->isAbstract())
- {
- //printf(" found\n");
- // Check that calling conventions match
- if (fd->linkage != ifd->linkage)
- fd->error("linkage doesn't match interface function");
+ assert(ifd);
+ // Find corresponding function in this class
+ tf = (ifd->type->ty == Tfunction) ? (TypeFunction *)(ifd->type) : NULL;
+ fd = cd->findFunc(ifd->ident, tf);
+ if (fd && !fd->isAbstract())
+ {
+ //printf(" found\n");
+ // Check that calling conventions match
+ if (fd->linkage != ifd->linkage)
+ fd->error("linkage doesn't match interface function");
- // Check that it is current
- if (newinstance &&
- fd->toParent() != cd &&
- ifd->toParent() == base)
- cd->error("interface function %s.%s is not implemented",
- id->toChars(), ifd->ident->toChars());
+ // Check that it is current
+ if (newinstance &&
+ fd->toParent() != cd &&
+ ifd->toParent() == base)
+ cd->error("interface function %s.%s is not implemented",
+ id->toChars(), ifd->ident->toChars());
- if (fd->toParent() == cd)
- result = 1;
- }
- else
- {
- //printf(" not found\n");
- // BUG: should mark this class as abstract?
- if (!cd->isAbstract())
- cd->error("interface function %s.%s isn't implemented",
- id->toChars(), ifd->ident->toChars());
- fd = NULL;
- }
- if (vtbl)
- vtbl->data[j] = fd;
+ if (fd->toParent() == cd)
+ result = 1;
+ }
+ else
+ {
+ //printf(" not found\n");
+ // BUG: should mark this class as abstract?
+ if (!cd->isAbstract())
+ cd->error("interface function %s.%s isn't implemented",
+ id->toChars(), ifd->ident->toChars());
+ fd = NULL;
+ }
+ if (vtbl)
+ vtbl->data[j] = fd;
}
return result;
@@ -1435,7 +1435,7 @@ void BaseClass::copyBaseInterfaces(BaseClasses *vtblInterfaces)
{
//printf("+copyBaseInterfaces(), %s\n", base->toChars());
// if (baseInterfaces_dim)
-// return;
+// return;
baseInterfaces_dim = base->interfaces_dim;
baseInterfaces = (BaseClass *)mem.calloc(baseInterfaces_dim, sizeof(BaseClass));
@@ -1443,15 +1443,15 @@ void BaseClass::copyBaseInterfaces(BaseClasses *vtblInterfaces)
//printf("%s.copyBaseInterfaces()\n", base->toChars());
for (int i = 0; i < baseInterfaces_dim; i++)
{
- BaseClass *b = &baseInterfaces[i];
- BaseClass *b2 = base->interfaces[i];
+ BaseClass *b = &baseInterfaces[i];
+ BaseClass *b2 = base->interfaces[i];
- assert(b2->vtbl.dim == 0); // should not be filled yet
- memcpy(b, b2, sizeof(BaseClass));
+ assert(b2->vtbl.dim == 0); // should not be filled yet
+ memcpy(b, b2, sizeof(BaseClass));
- if (i) // single inheritance is i==0
- vtblInterfaces->push(b); // only need for M.I.
- b->copyBaseInterfaces(vtblInterfaces);
+ if (i) // single inheritance is i==0
+ vtblInterfaces->push(b); // only need for M.I.
+ b->copyBaseInterfaces(vtblInterfaces);
}
//printf("-copyBaseInterfaces\n");
}
diff --git a/dmd/clone.c b/dmd/clone.c
index 1f65a477..05aede20 100644
--- a/dmd/clone.c
+++ b/dmd/clone.c
@@ -35,44 +35,44 @@ Expression *StructDeclaration::cloneMembers()
for (size_t i = 0; i < fields.dim; i++)
{
- Dsymbol *s = (Dsymbol *)fields.data[i];
- VarDeclaration *v = s->isVarDeclaration();
- assert(v && v->storage_class & STCfield);
- Type *tv = v->type->toBasetype();
- size_t dim = 1;
- while (tv->ty == Tsarray)
- { TypeSArray *ta = (TypeSArray *)tv;
- dim *= ((TypeSArray *)tv)->dim->toInteger();
- tv = tv->nextOf()->toBasetype();
- }
- if (tv->ty == Tstruct)
- { TypeStruct *ts = (TypeStruct *)tv;
- StructDeclaration *sd = ts->sym;
- if (sd->opclone)
- { Expression *ex;
+ Dsymbol *s = (Dsymbol *)fields.data[i];
+ VarDeclaration *v = s->isVarDeclaration();
+ assert(v && v->storage_class & STCfield);
+ Type *tv = v->type->toBasetype();
+ size_t dim = 1;
+ while (tv->ty == Tsarray)
+ { TypeSArray *ta = (TypeSArray *)tv;
+ dim *= ((TypeSArray *)tv)->dim->toInteger();
+ tv = tv->nextOf()->toBasetype();
+ }
+ if (tv->ty == Tstruct)
+ { TypeStruct *ts = (TypeStruct *)tv;
+ StructDeclaration *sd = ts->sym;
+ if (sd->opclone)
+ { Expression *ex;
- // this.v
- ex = new ThisExp(0);
- ex = new DotVarExp(0, ex, v, 0);
+ // this.v
+ ex = new ThisExp(0);
+ ex = new DotVarExp(0, ex, v, 0);
- if (dim == 1)
- { // this.v.opClone()
- ex = new DotVarExp(0, ex, sd->opclone, 0);
- ex = new CallExp(0, ex);
- }
- else
- {
- // _callOpClones(&this.v, opclone, dim)
- Expressions *args = new Expressions();
- args->push(new AddrExp(0, ex));
- args->push(new SymOffExp(0, sd->opclone, 0));
- args->push(new IntegerExp(dim));
- FuncDeclaration *ec = FuncDeclaration::genCfunc(Type::tvoid, "_callOpClones");
- ex = new CallExp(0, new VarExp(0, ec), args);
- }
- e = Expression::combine(e, ex);
- }
- }
+ if (dim == 1)
+ { // this.v.opClone()
+ ex = new DotVarExp(0, ex, sd->opclone, 0);
+ ex = new CallExp(0, ex);
+ }
+ else
+ {
+ // _callOpClones(&this.v, opclone, dim)
+ Expressions *args = new Expressions();
+ args->push(new AddrExp(0, ex));
+ args->push(new SymOffExp(0, sd->opclone, 0));
+ args->push(new IntegerExp(dim));
+ FuncDeclaration *ec = FuncDeclaration::genCfunc(Type::tvoid, "_callOpClones");
+ ex = new CallExp(0, new VarExp(0, ec), args);
+ }
+ e = Expression::combine(e, ex);
+ }
+ }
}
return e;
}
@@ -92,83 +92,83 @@ FuncDeclaration *AggregateDeclaration::buildDtor(Scope *sc)
#if DMDV2
for (size_t i = 0; i < fields.dim; i++)
{
- Dsymbol *s = (Dsymbol *)fields.data[i];
- VarDeclaration *v = s->isVarDeclaration();
- assert(v && v->storage_class & STCfield);
- Type *tv = v->type->toBasetype();
- size_t dim = 1;
- while (tv->ty == Tsarray)
- { TypeSArray *ta = (TypeSArray *)tv;
- dim *= ((TypeSArray *)tv)->dim->toInteger();
- tv = tv->nextOf()->toBasetype();
- }
- if (tv->ty == Tstruct)
- { TypeStruct *ts = (TypeStruct *)tv;
- StructDeclaration *sd = ts->sym;
- if (sd->dtor)
- { Expression *ex;
+ Dsymbol *s = (Dsymbol *)fields.data[i];
+ VarDeclaration *v = s->isVarDeclaration();
+ assert(v && v->storage_class & STCfield);
+ Type *tv = v->type->toBasetype();
+ size_t dim = 1;
+ while (tv->ty == Tsarray)
+ { TypeSArray *ta = (TypeSArray *)tv;
+ dim *= ((TypeSArray *)tv)->dim->toInteger();
+ tv = tv->nextOf()->toBasetype();
+ }
+ if (tv->ty == Tstruct)
+ { TypeStruct *ts = (TypeStruct *)tv;
+ StructDeclaration *sd = ts->sym;
+ if (sd->dtor)
+ { Expression *ex;
- // this.v
- ex = new ThisExp(0);
- ex = new DotVarExp(0, ex, v, 0);
+ // this.v
+ ex = new ThisExp(0);
+ ex = new DotVarExp(0, ex, v, 0);
- if (dim == 1)
- { // this.v.dtor()
- ex = new DotVarExp(0, ex, sd->dtor, 0);
- ex = new CallExp(0, ex);
- }
- else
- {
- // Typeinfo.destroy(cast(void*)&this.v);
- Expression *ea = new AddrExp(0, ex);
- ea = new CastExp(0, ea, Type::tvoid->pointerTo());
- Expressions *args = new Expressions();
- args->push(ea);
+ if (dim == 1)
+ { // this.v.dtor()
+ ex = new DotVarExp(0, ex, sd->dtor, 0);
+ ex = new CallExp(0, ex);
+ }
+ else
+ {
+ // Typeinfo.destroy(cast(void*)&this.v);
+ Expression *ea = new AddrExp(0, ex);
+ ea = new CastExp(0, ea, Type::tvoid->pointerTo());
+ Expressions *args = new Expressions();
+ args->push(ea);
- Expression *et = v->type->getTypeInfo(sc);
- et = new DotIdExp(0, et, Id::destroy);
+ Expression *et = v->type->getTypeInfo(sc);
+ et = new DotIdExp(0, et, Id::destroy);
- ex = new CallExp(0, et, args);
- }
- e = Expression::combine(ex, e); // combine in reverse order
- }
- }
+ ex = new CallExp(0, et, args);
+ }
+ e = Expression::combine(ex, e); // combine in reverse order
+ }
+ }
}
/* Build our own "destructor" which executes e
*/
if (e)
- { //printf("Building __fieldDtor()\n");
- DtorDeclaration *dd = new DtorDeclaration(0, 0, Lexer::idPool("__fieldDtor"));
- dd->fbody = new ExpStatement(0, e);
- dtors.shift(dd);
- members->push(dd);
- dd->semantic(sc);
+ { //printf("Building __fieldDtor()\n");
+ DtorDeclaration *dd = new DtorDeclaration(0, 0, Lexer::idPool("__fieldDtor"));
+ dd->fbody = new ExpStatement(0, e);
+ dtors.shift(dd);
+ members->push(dd);
+ dd->semantic(sc);
}
#endif
switch (dtors.dim)
{
- case 0:
- return NULL;
+ case 0:
+ return NULL;
- case 1:
- return (FuncDeclaration *)dtors.data[0];
+ case 1:
+ return (FuncDeclaration *)dtors.data[0];
- default:
- e = NULL;
- for (size_t i = 0; i < dtors.dim; i++)
- { FuncDeclaration *fd = (FuncDeclaration *)dtors.data[i];
- Expression *ex = new ThisExp(0);
- ex = new DotVarExp(0, ex, fd);
- ex = new CallExp(0, ex);
- e = Expression::combine(ex, e);
- }
- DtorDeclaration *dd = new DtorDeclaration(0, 0, Lexer::idPool("__aggrDtor"));
- dd->fbody = new ExpStatement(0, e);
- members->push(dd);
- dd->semantic(sc);
- return dd;
+ default:
+ e = NULL;
+ for (size_t i = 0; i < dtors.dim; i++)
+ { FuncDeclaration *fd = (FuncDeclaration *)dtors.data[i];
+ Expression *ex = new ThisExp(0);
+ ex = new DotVarExp(0, ex, fd);
+ ex = new CallExp(0, ex);
+ e = Expression::combine(ex, e);
+ }
+ DtorDeclaration *dd = new DtorDeclaration(0, 0, Lexer::idPool("__aggrDtor"));
+ dd->fbody = new ExpStatement(0, e);
+ members->push(dd);
+ dd->semantic(sc);
+ return dd;
}
}
diff --git a/dmd/complex_t.h b/dmd/complex_t.h
index ad895b8a..132b952b 100644
--- a/dmd/complex_t.h
+++ b/dmd/complex_t.h
@@ -17,7 +17,7 @@
struct complex_t
{
long double re;
- long double im;
+ long double im;
complex_t() { this->re = 0; this->im = 0; }
complex_t(long double re) { this->re = re; this->im = 0; }
@@ -27,27 +27,27 @@ struct complex_t
complex_t operator - (complex_t y) { complex_t r; r.re = re - y.re; r.im = im - y.im; return r; }
complex_t operator - () { complex_t r; r.re = -re; r.im = -im; return r; }
complex_t operator * (complex_t y) { return complex_t(re * y.re - im * y.im, im * y.re + re * y.im); }
-
+
complex_t operator / (complex_t y)
{
- long double abs_y_re = y.re < 0 ? -y.re : y.re;
- long double abs_y_im = y.im < 0 ? -y.im : y.im;
- long double r, den;
+ long double abs_y_re = y.re < 0 ? -y.re : y.re;
+ long double abs_y_im = y.im < 0 ? -y.im : y.im;
+ long double r, den;
- if (abs_y_re < abs_y_im)
- {
- r = y.re / y.im;
- den = y.im + r * y.re;
- return complex_t((re * r + im) / den,
- (im * r - re) / den);
- }
- else
- {
- r = y.im / y.re;
- den = y.re + r * y.im;
- return complex_t((re + r * im) / den,
- (im - r * re) / den);
- }
+ if (abs_y_re < abs_y_im)
+ {
+ r = y.re / y.im;
+ den = y.im + r * y.re;
+ return complex_t((re * r + im) / den,
+ (im * r - re) / den);
+ }
+ else
+ {
+ r = y.im / y.re;
+ den = y.re + r * y.im;
+ return complex_t((re + r * im) / den,
+ (im - r * re) / den);
+ }
}
operator bool () { return re || im; }
diff --git a/dmd/cond.c b/dmd/cond.c
index 342b21fe..4f0ac8da 100644
--- a/dmd/cond.c
+++ b/dmd/cond.c
@@ -29,13 +29,13 @@ int findCondition(Array *ids, Identifier *ident)
{
if (ids)
{
- for (int i = 0; i < ids->dim; i++)
- {
- const char *id = (const char *)ids->data[i];
+ for (int i = 0; i < ids->dim; i++)
+ {
+ const char *id = (const char *)ids->data[i];
- if (strcmp(id, ident->toChars()) == 0)
- return TRUE;
- }
+ if (strcmp(id, ident->toChars()) == 0)
+ return TRUE;
+ }
}
return FALSE;
@@ -52,7 +52,7 @@ Condition::Condition(Loc loc)
/* ============================================================ */
DVCondition::DVCondition(Module *mod, unsigned level, Identifier *ident)
- : Condition(0)
+ : Condition(0)
{
this->mod = mod;
this->level = level;
@@ -61,7 +61,7 @@ DVCondition::DVCondition(Module *mod, unsigned level, Identifier *ident)
Condition *DVCondition::syntaxCopy()
{
- return this; // don't need to copy
+ return this; // don't need to copy
}
/* ============================================================ */
@@ -74,7 +74,7 @@ void DebugCondition::setGlobalLevel(unsigned level)
void DebugCondition::addGlobalIdent(const char *ident)
{
if (!global.params.debugids)
- global.params.debugids = new Array();
+ global.params.debugids = new Array();
global.params.debugids->push((void *)ident);
}
@@ -89,21 +89,21 @@ int DebugCondition::include(Scope *sc, ScopeDsymbol *s)
//printf("DebugCondition::include() level = %d, debuglevel = %d\n", level, global.params.debuglevel);
if (inc == 0)
{
- inc = 2;
- if (ident)
- {
- if (findCondition(mod->debugids, ident))
- inc = 1;
- else if (findCondition(global.params.debugids, ident))
- inc = 1;
- else
- { if (!mod->debugidsNot)
- mod->debugidsNot = new Array();
- mod->debugidsNot->push(ident->toChars());
- }
- }
- else if (level <= global.params.debuglevel || level <= mod->debuglevel)
- inc = 1;
+ inc = 2;
+ if (ident)
+ {
+ if (findCondition(mod->debugids, ident))
+ inc = 1;
+ else if (findCondition(global.params.debugids, ident))
+ inc = 1;
+ else
+ { if (!mod->debugidsNot)
+ mod->debugidsNot = new Array();
+ mod->debugidsNot->push(ident->toChars());
+ }
+ }
+ else if (level <= global.params.debuglevel || level <= mod->debuglevel)
+ inc = 1;
}
return (inc == 1);
}
@@ -111,9 +111,9 @@ int DebugCondition::include(Scope *sc, ScopeDsymbol *s)
void DebugCondition::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (ident)
- buf->printf("debug (%s)", ident->toChars());
+ buf->printf("debug (%s)", ident->toChars());
else
- buf->printf("debug (%u)", level);
+ buf->printf("debug (%u)", level);
}
/* ============================================================ */
@@ -127,20 +127,20 @@ void VersionCondition::checkPredefined(Loc loc, const char *ident)
{
static const char* reserved[] =
{
- "DigitalMars", "X86", "X86_64",
- "Windows", "Win32", "Win64",
- "linux",
+ "DigitalMars", "X86", "X86_64",
+ "Windows", "Win32", "Win64",
+ "linux",
#if DMDV2
- /* Although Posix is predefined by D1, disallowing its
- * redefinition breaks makefiles and older builds.
- */
- "Posix",
+ /* Although Posix is predefined by D1, disallowing its
+ * redefinition breaks makefiles and older builds.
+ */
+ "Posix",
#endif
- "OSX", "FreeBSD",
- "Solaris",
- "LittleEndian", "BigEndian",
- "all",
- "none",
+ "OSX", "FreeBSD",
+ "Solaris",
+ "LittleEndian", "BigEndian",
+ "all",
+ "none",
#if IN_LLVM
"LLVM", "LDC", "LLVM64",
@@ -151,12 +151,12 @@ void VersionCondition::checkPredefined(Loc loc, const char *ident)
for (unsigned i = 0; i < sizeof(reserved) / sizeof(reserved[0]); i++)
{
- if (strcmp(ident, reserved[i]) == 0)
- goto Lerror;
+ if (strcmp(ident, reserved[i]) == 0)
+ goto Lerror;
}
if (ident[0] == 'D' && ident[1] == '_')
- goto Lerror;
+ goto Lerror;
return;
@@ -173,7 +173,7 @@ void VersionCondition::addGlobalIdent(const char *ident)
void VersionCondition::addPredefinedGlobalIdent(const char *ident)
{
if (!global.params.versionids)
- global.params.versionids = new Array();
+ global.params.versionids = new Array();
global.params.versionids->push((void *)ident);
}
@@ -189,22 +189,22 @@ int VersionCondition::include(Scope *sc, ScopeDsymbol *s)
//if (ident) printf("\tident = '%s'\n", ident->toChars());
if (inc == 0)
{
- inc = 2;
- if (ident)
- {
- if (findCondition(mod->versionids, ident))
- inc = 1;
- else if (findCondition(global.params.versionids, ident))
- inc = 1;
- else
- {
- if (!mod->versionidsNot)
- mod->versionidsNot = new Array();
- mod->versionidsNot->push(ident->toChars());
- }
- }
- else if (level <= global.params.versionlevel || level <= mod->versionlevel)
- inc = 1;
+ inc = 2;
+ if (ident)
+ {
+ if (findCondition(mod->versionids, ident))
+ inc = 1;
+ else if (findCondition(global.params.versionids, ident))
+ inc = 1;
+ else
+ {
+ if (!mod->versionidsNot)
+ mod->versionidsNot = new Array();
+ mod->versionidsNot->push(ident->toChars());
+ }
+ }
+ else if (level <= global.params.versionlevel || level <= mod->versionlevel)
+ inc = 1;
}
return (inc == 1);
}
@@ -212,9 +212,9 @@ int VersionCondition::include(Scope *sc, ScopeDsymbol *s)
void VersionCondition::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (ident)
- buf->printf("version (%s)", ident->toChars());
+ buf->printf("version (%s)", ident->toChars());
else
- buf->printf("version (%u)", level);
+ buf->printf("version (%u)", level);
}
@@ -237,33 +237,33 @@ int StaticIfCondition::include(Scope *sc, ScopeDsymbol *s)
printf("StaticIfCondition::include(sc = %p, s = %p)\n", sc, s);
if (s)
{
- printf("\ts = '%s', kind = %s\n", s->toChars(), s->kind());
+ printf("\ts = '%s', kind = %s\n", s->toChars(), s->kind());
}
#endif
if (inc == 0)
{
- if (!sc)
- {
- error(loc, "static if conditional cannot be at global scope");
- inc = 2;
- return 0;
- }
+ if (!sc)
+ {
+ error(loc, "static if conditional cannot be at global scope");
+ inc = 2;
+ return 0;
+ }
- sc = sc->push(sc->scopesym);
- sc->sd = s; // s gets any addMember()
- sc->flags |= SCOPEstaticif;
- Expression *e = exp->semantic(sc);
- sc->pop();
- e = e->optimize(WANTvalue | WANTinterpret);
- if (e->isBool(TRUE))
- inc = 1;
- else if (e->isBool(FALSE))
- inc = 2;
- else
- {
- e->error("expression %s is not constant or does not evaluate to a bool", e->toChars());
- inc = 2;
- }
+ sc = sc->push(sc->scopesym);
+ sc->sd = s; // s gets any addMember()
+ sc->flags |= SCOPEstaticif;
+ Expression *e = exp->semantic(sc);
+ sc->pop();
+ e = e->optimize(WANTvalue | WANTinterpret);
+ if (e->isBool(TRUE))
+ inc = 1;
+ else if (e->isBool(FALSE))
+ inc = 2;
+ else
+ {
+ e->error("expression %s is not constant or does not evaluate to a bool", e->toChars());
+ inc = 2;
+ }
}
return (inc == 1);
}
@@ -290,10 +290,10 @@ IftypeCondition::IftypeCondition(Loc loc, Type *targ, Identifier *id, enum TOK t
Condition *IftypeCondition::syntaxCopy()
{
return new IftypeCondition(loc,
- targ->syntaxCopy(),
- id,
- tok,
- tspec ? tspec->syntaxCopy() : NULL);
+ targ->syntaxCopy(),
+ id,
+ tok,
+ tspec ? tspec->syntaxCopy() : NULL);
}
int IftypeCondition::include(Scope *sc, ScopeDsymbol *sd)
@@ -301,87 +301,87 @@ int IftypeCondition::include(Scope *sc, ScopeDsymbol *sd)
//printf("IftypeCondition::include()\n");
if (inc == 0)
{
- if (!sc)
- {
- error(loc, "iftype conditional cannot be at global scope");
- inc = 2;
- return 0;
- }
- unsigned errors = global.errors;
- global.gag++; // suppress printing of error messages
- targ = targ->semantic(loc, sc);
- global.gag--;
- if (errors != global.errors) // if any errors happened
- { inc = 2; // then condition is false
- global.errors = errors;
- }
- else if (id && tspec)
- {
- /* Evaluate to TRUE if targ matches tspec.
- * If TRUE, declare id as an alias for the specialized type.
- */
+ if (!sc)
+ {
+ error(loc, "iftype conditional cannot be at global scope");
+ inc = 2;
+ return 0;
+ }
+ unsigned errors = global.errors;
+ global.gag++; // suppress printing of error messages
+ targ = targ->semantic(loc, sc);
+ global.gag--;
+ if (errors != global.errors) // if any errors happened
+ { inc = 2; // then condition is false
+ global.errors = errors;
+ }
+ else if (id && tspec)
+ {
+ /* Evaluate to TRUE if targ matches tspec.
+ * If TRUE, declare id as an alias for the specialized type.
+ */
- MATCH m;
- TemplateTypeParameter tp(loc, id, NULL, NULL);
+ MATCH m;
+ TemplateTypeParameter tp(loc, id, NULL, NULL);
- TemplateParameters parameters;
- parameters.setDim(1);
- parameters.data[0] = (void *)&tp;
+ TemplateParameters parameters;
+ parameters.setDim(1);
+ parameters.data[0] = (void *)&tp;
- Objects dedtypes;
- dedtypes.setDim(1);
+ Objects dedtypes;
+ dedtypes.setDim(1);
- m = targ->deduceType(NULL, tspec, ¶meters, &dedtypes);
- if (m == MATCHnomatch ||
- (m != MATCHexact && tok == TOKequal))
- inc = 2;
- else
- {
- inc = 1;
- Type *tded = (Type *)dedtypes.data[0];
- if (!tded)
- tded = targ;
- Dsymbol *s = new AliasDeclaration(loc, id, tded);
- s->semantic(sc);
- sc->insert(s);
- if (sd)
- s->addMember(sc, sd, 1);
- }
- }
- else if (id)
- {
- /* Declare id as an alias for type targ. Evaluate to TRUE
- */
- Dsymbol *s = new AliasDeclaration(loc, id, targ);
- s->semantic(sc);
- sc->insert(s);
- if (sd)
- s->addMember(sc, sd, 1);
- inc = 1;
- }
- else if (tspec)
- {
- /* Evaluate to TRUE if targ matches tspec
- */
- tspec = tspec->semantic(loc, sc);
- //printf("targ = %s\n", targ->toChars());
- //printf("tspec = %s\n", tspec->toChars());
- if (tok == TOKcolon)
- { if (targ->implicitConvTo(tspec))
- inc = 1;
- else
- inc = 2;
- }
- else /* == */
- { if (targ->equals(tspec))
- inc = 1;
- else
- inc = 2;
- }
- }
- else
- inc = 1;
- //printf("inc = %d\n", inc);
+ m = targ->deduceType(NULL, tspec, ¶meters, &dedtypes);
+ if (m == MATCHnomatch ||
+ (m != MATCHexact && tok == TOKequal))
+ inc = 2;
+ else
+ {
+ inc = 1;
+ Type *tded = (Type *)dedtypes.data[0];
+ if (!tded)
+ tded = targ;
+ Dsymbol *s = new AliasDeclaration(loc, id, tded);
+ s->semantic(sc);
+ sc->insert(s);
+ if (sd)
+ s->addMember(sc, sd, 1);
+ }
+ }
+ else if (id)
+ {
+ /* Declare id as an alias for type targ. Evaluate to TRUE
+ */
+ Dsymbol *s = new AliasDeclaration(loc, id, targ);
+ s->semantic(sc);
+ sc->insert(s);
+ if (sd)
+ s->addMember(sc, sd, 1);
+ inc = 1;
+ }
+ else if (tspec)
+ {
+ /* Evaluate to TRUE if targ matches tspec
+ */
+ tspec = tspec->semantic(loc, sc);
+ //printf("targ = %s\n", targ->toChars());
+ //printf("tspec = %s\n", tspec->toChars());
+ if (tok == TOKcolon)
+ { if (targ->implicitConvTo(tspec))
+ inc = 1;
+ else
+ inc = 2;
+ }
+ else /* == */
+ { if (targ->equals(tspec))
+ inc = 1;
+ else
+ inc = 2;
+ }
+ }
+ else
+ inc = 1;
+ //printf("inc = %d\n", inc);
}
return (inc == 1);
}
@@ -392,11 +392,11 @@ void IftypeCondition::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
targ->toCBuffer(buf, id, hgs);
if (tspec)
{
- if (tok == TOKcolon)
- buf->writestring(" : ");
- else
- buf->writestring(" == ");
- tspec->toCBuffer(buf, NULL, hgs);
+ if (tok == TOKcolon)
+ buf->writestring(" : ");
+ else
+ buf->writestring(" == ");
+ tspec->toCBuffer(buf, NULL, hgs);
}
buf->writeByte(')');
}
diff --git a/dmd/cond.h b/dmd/cond.h
index d340b0aa..12eb5068 100644
--- a/dmd/cond.h
+++ b/dmd/cond.h
@@ -30,9 +30,9 @@ int findCondition(Array *ids, Identifier *ident);
struct Condition
{
Loc loc;
- int inc; // 0: not computed yet
- // 1: include
- // 2: do not include
+ int inc; // 0: not computed yet
+ // 1: include
+ // 2: do not include
Condition(Loc loc);
@@ -92,9 +92,9 @@ struct IftypeCondition : Condition
/* iftype (targ id tok tspec)
*/
Type *targ;
- Identifier *id; // can be NULL
- enum TOK tok; // ':' or '=='
- Type *tspec; // can be NULL
+ Identifier *id; // can be NULL
+ enum TOK tok; // ':' or '=='
+ Type *tspec; // can be NULL
IftypeCondition(Loc loc, Type *targ, Identifier *id, enum TOK tok, Type *tspec);
Condition *syntaxCopy();
diff --git a/dmd/constfold.c b/dmd/constfold.c
index 12f928ce..af6f496c 100644
--- a/dmd/constfold.c
+++ b/dmd/constfold.c
@@ -33,10 +33,10 @@
extern "C" bool real_isnan (const real_t *);
#endif
-static real_t zero; // work around DMC bug for now
+static real_t zero; // work around DMC bug for now
#if __FreeBSD__
-#define fmodl fmod // hack for now, fix later
+#define fmodl fmod // hack for now, fix later
#endif
#define LOG 0
@@ -45,8 +45,8 @@ Expression *expType(Type *type, Expression *e)
{
if (type != e->type)
{
- e = e->copy();
- e->type = type;
+ e = e->copy();
+ e->type = type;
}
return e;
}
@@ -98,18 +98,18 @@ Expression *Neg(Type *type, Expression *e1)
if (e1->type->isreal())
{
- e = new RealExp(loc, -e1->toReal(), type);
+ e = new RealExp(loc, -e1->toReal(), type);
}
else if (e1->type->isimaginary())
{
- e = new RealExp(loc, -e1->toImaginary(), type);
+ e = new RealExp(loc, -e1->toImaginary(), type);
}
else if (e1->type->iscomplex())
{
- e = new ComplexExp(loc, -e1->toComplex(), type);
+ e = new ComplexExp(loc, -e1->toComplex(), type);
}
else
- e = new IntegerExp(loc, -e1->toInteger(), type);
+ e = new IntegerExp(loc, -e1->toInteger(), type);
return e;
}
@@ -146,93 +146,93 @@ Expression *Add(Type *type, Expression *e1, Expression *e2)
#endif
if (type->isreal())
{
- e = new RealExp(loc, e1->toReal() + e2->toReal(), type);
+ e = new RealExp(loc, e1->toReal() + e2->toReal(), type);
}
else if (type->isimaginary())
{
- e = new RealExp(loc, e1->toImaginary() + e2->toImaginary(), type);
+ e = new RealExp(loc, e1->toImaginary() + e2->toImaginary(), type);
}
else if (type->iscomplex())
{
- // This rigamarole is necessary so that -0.0 doesn't get
- // converted to +0.0 by doing an extraneous add with +0.0
- complex_t c1;
- real_t r1;
- real_t i1;
+ // This rigamarole is necessary so that -0.0 doesn't get
+ // converted to +0.0 by doing an extraneous add with +0.0
+ complex_t c1;
+ real_t r1;
+ real_t i1;
- complex_t c2;
- real_t r2;
- real_t i2;
+ complex_t c2;
+ real_t r2;
+ real_t i2;
- complex_t v;
- int x;
+ complex_t v;
+ int x;
- if (e1->type->isreal())
- { r1 = e1->toReal();
- x = 0;
- }
- else if (e1->type->isimaginary())
- { i1 = e1->toImaginary();
- x = 3;
- }
- else
- { c1 = e1->toComplex();
- x = 6;
- }
+ if (e1->type->isreal())
+ { r1 = e1->toReal();
+ x = 0;
+ }
+ else if (e1->type->isimaginary())
+ { i1 = e1->toImaginary();
+ x = 3;
+ }
+ else
+ { c1 = e1->toComplex();
+ x = 6;
+ }
- if (e2->type->isreal())
- { r2 = e2->toReal();
- }
- else if (e2->type->isimaginary())
- { i2 = e2->toImaginary();
- x += 1;
- }
- else
- { c2 = e2->toComplex();
- x += 2;
- }
+ if (e2->type->isreal())
+ { r2 = e2->toReal();
+ }
+ else if (e2->type->isimaginary())
+ { i2 = e2->toImaginary();
+ x += 1;
+ }
+ else
+ { c2 = e2->toComplex();
+ x += 2;
+ }
- switch (x)
- {
+ switch (x)
+ {
#if __DMC__
- case 0+0: v = (complex_t) (r1 + r2); break;
- case 0+1: v = r1 + i2 * I; break;
- case 0+2: v = r1 + c2; break;
- case 3+0: v = i1 * I + r2; break;
- case 3+1: v = (complex_t) ((i1 + i2) * I); break;
- case 3+2: v = i1 * I + c2; break;
- case 6+0: v = c1 + r2; break;
- case 6+1: v = c1 + i2 * I; break;
- case 6+2: v = c1 + c2; break;
+ case 0+0: v = (complex_t) (r1 + r2); break;
+ case 0+1: v = r1 + i2 * I; break;
+ case 0+2: v = r1 + c2; break;
+ case 3+0: v = i1 * I + r2; break;
+ case 3+1: v = (complex_t) ((i1 + i2) * I); break;
+ case 3+2: v = i1 * I + c2; break;
+ case 6+0: v = c1 + r2; break;
+ case 6+1: v = c1 + i2 * I; break;
+ case 6+2: v = c1 + c2; break;
#else
- case 0+0: v = complex_t(r1 + r2, 0); break;
- case 0+1: v = complex_t(r1, i2); break;
- case 0+2: v = complex_t(r1 + creall(c2), cimagl(c2)); break;
- case 3+0: v = complex_t(r2, i1); break;
- case 3+1: v = complex_t(0, i1 + i2); break;
- case 3+2: v = complex_t(creall(c2), i1 + cimagl(c2)); break;
- case 6+0: v = complex_t(creall(c1) + r2, cimagl(c2)); break;
- case 6+1: v = complex_t(creall(c1), cimagl(c1) + i2); break;
- case 6+2: v = c1 + c2; break;
+ case 0+0: v = complex_t(r1 + r2, 0); break;
+ case 0+1: v = complex_t(r1, i2); break;
+ case 0+2: v = complex_t(r1 + creall(c2), cimagl(c2)); break;
+ case 3+0: v = complex_t(r2, i1); break;
+ case 3+1: v = complex_t(0, i1 + i2); break;
+ case 3+2: v = complex_t(creall(c2), i1 + cimagl(c2)); break;
+ case 6+0: v = complex_t(creall(c1) + r2, cimagl(c2)); break;
+ case 6+1: v = complex_t(creall(c1), cimagl(c1) + i2); break;
+ case 6+2: v = c1 + c2; break;
#endif
- default: assert(0);
- }
- e = new ComplexExp(loc, v, type);
+ default: assert(0);
+ }
+ e = new ComplexExp(loc, v, type);
}
else if (e1->op == TOKsymoff)
{
- SymOffExp *soe = (SymOffExp *)e1;
- e = new SymOffExp(loc, soe->var, soe->offset + e2->toInteger());
- e->type = type;
+ SymOffExp *soe = (SymOffExp *)e1;
+ e = new SymOffExp(loc, soe->var, soe->offset + e2->toInteger());
+ e->type = type;
}
else if (e2->op == TOKsymoff)
{
- SymOffExp *soe = (SymOffExp *)e2;
- e = new SymOffExp(loc, soe->var, soe->offset + e1->toInteger());
- e->type = type;
+ SymOffExp *soe = (SymOffExp *)e2;
+ e = new SymOffExp(loc, soe->var, soe->offset + e1->toInteger());
+ e->type = type;
}
else
- e = new IntegerExp(loc, e1->toInteger() + e2->toInteger(), type);
+ e = new IntegerExp(loc, e1->toInteger() + e2->toInteger(), type);
return e;
}
@@ -243,88 +243,88 @@ Expression *Min(Type *type, Expression *e1, Expression *e2)
if (type->isreal())
{
- e = new RealExp(loc, e1->toReal() - e2->toReal(), type);
+ e = new RealExp(loc, e1->toReal() - e2->toReal(), type);
}
else if (type->isimaginary())
{
- e = new RealExp(loc, e1->toImaginary() - e2->toImaginary(), type);
+ e = new RealExp(loc, e1->toImaginary() - e2->toImaginary(), type);
}
else if (type->iscomplex())
{
- // This rigamarole is necessary so that -0.0 doesn't get
- // converted to +0.0 by doing an extraneous add with +0.0
- complex_t c1;
- real_t r1;
- real_t i1;
+ // This rigamarole is necessary so that -0.0 doesn't get
+ // converted to +0.0 by doing an extraneous add with +0.0
+ complex_t c1;
+ real_t r1;
+ real_t i1;
- complex_t c2;
- real_t r2;
- real_t i2;
+ complex_t c2;
+ real_t r2;
+ real_t i2;
- complex_t v;
- int x;
+ complex_t v;
+ int x;
- if (e1->type->isreal())
- { r1 = e1->toReal();
- x = 0;
- }
- else if (e1->type->isimaginary())
- { i1 = e1->toImaginary();
- x = 3;
- }
- else
- { c1 = e1->toComplex();
- x = 6;
- }
+ if (e1->type->isreal())
+ { r1 = e1->toReal();
+ x = 0;
+ }
+ else if (e1->type->isimaginary())
+ { i1 = e1->toImaginary();
+ x = 3;
+ }
+ else
+ { c1 = e1->toComplex();
+ x = 6;
+ }
- if (e2->type->isreal())
- { r2 = e2->toReal();
- }
- else if (e2->type->isimaginary())
- { i2 = e2->toImaginary();
- x += 1;
- }
- else
- { c2 = e2->toComplex();
- x += 2;
- }
+ if (e2->type->isreal())
+ { r2 = e2->toReal();
+ }
+ else if (e2->type->isimaginary())
+ { i2 = e2->toImaginary();
+ x += 1;
+ }
+ else
+ { c2 = e2->toComplex();
+ x += 2;
+ }
- switch (x)
- {
+ switch (x)
+ {
#if __DMC__
- case 0+0: v = (complex_t) (r1 - r2); break;
- case 0+1: v = r1 - i2 * I; break;
- case 0+2: v = r1 - c2; break;
- case 3+0: v = i1 * I - r2; break;
- case 3+1: v = (complex_t) ((i1 - i2) * I); break;
- case 3+2: v = i1 * I - c2; break;
- case 6+0: v = c1 - r2; break;
- case 6+1: v = c1 - i2 * I; break;
- case 6+2: v = c1 - c2; break;
+ case 0+0: v = (complex_t) (r1 - r2); break;
+ case 0+1: v = r1 - i2 * I; break;
+ case 0+2: v = r1 - c2; break;
+ case 3+0: v = i1 * I - r2; break;
+ case 3+1: v = (complex_t) ((i1 - i2) * I); break;
+ case 3+2: v = i1 * I - c2; break;
+ case 6+0: v = c1 - r2; break;
+ case 6+1: v = c1 - i2 * I; break;
+ case 6+2: v = c1 - c2; break;
#else
- case 0+0: v = complex_t(r1 - r2, 0); break;
- case 0+1: v = complex_t(r1, -i2); break;
- case 0+2: v = complex_t(r1 - creall(c2), -cimagl(c2)); break;
- case 3+0: v = complex_t(-r2, i1); break;
- case 3+1: v = complex_t(0, i1 - i2); break;
- case 3+2: v = complex_t(-creall(c2), i1 - cimagl(c2)); break;
- case 6+0: v = complex_t(creall(c1) - r2, cimagl(c1)); break;
- case 6+1: v = complex_t(creall(c1), cimagl(c1) - i2); break;
- case 6+2: v = c1 - c2; break;
+ case 0+0: v = complex_t(r1 - r2, 0); break;
+ case 0+1: v = complex_t(r1, -i2); break;
+ case 0+2: v = complex_t(r1 - creall(c2), -cimagl(c2)); break;
+ case 3+0: v = complex_t(-r2, i1); break;
+ case 3+1: v = complex_t(0, i1 - i2); break;
+ case 3+2: v = complex_t(-creall(c2), i1 - cimagl(c2)); break;
+ case 6+0: v = complex_t(creall(c1) - r2, cimagl(c1)); break;
+ case 6+1: v = complex_t(creall(c1), cimagl(c1) - i2); break;
+ case 6+2: v = c1 - c2; break;
#endif
- default: assert(0);
- }
- e = new ComplexExp(loc, v, type);
+ default: assert(0);
+ }
+ e = new ComplexExp(loc, v, type);
}
else if (e1->op == TOKsymoff)
{
- SymOffExp *soe = (SymOffExp *)e1;
- e = new SymOffExp(loc, soe->var, soe->offset - e2->toInteger());
- e->type = type;
+ SymOffExp *soe = (SymOffExp *)e1;
+ e = new SymOffExp(loc, soe->var, soe->offset - e2->toInteger());
+ e->type = type;
}
else
{
- e = new IntegerExp(loc, e1->toInteger() - e2->toInteger(), type);
+ e = new IntegerExp(loc, e1->toInteger() - e2->toInteger(), type);
}
return e;
}
@@ -336,66 +336,66 @@ Expression *Mul(Type *type, Expression *e1, Expression *e2)
if (type->isfloating())
{ complex_t c;
#ifdef IN_GCC
- real_t r;
+ real_t r;
#else
- d_float80 r;
+ d_float80 r;
#endif
- if (e1->type->isreal())
- {
+ if (e1->type->isreal())
+ {
#if __DMC__
- c = e1->toReal() * e2->toComplex();
+ c = e1->toReal() * e2->toComplex();
#else
- r = e1->toReal();
- c = e2->toComplex();
- c = complex_t(r * creall(c), r * cimagl(c));
+ r = e1->toReal();
+ c = e2->toComplex();
+ c = complex_t(r * creall(c), r * cimagl(c));
#endif
- }
- else if (e1->type->isimaginary())
- {
+ }
+ else if (e1->type->isimaginary())
+ {
#if __DMC__
- c = e1->toImaginary() * I * e2->toComplex();
+ c = e1->toImaginary() * I * e2->toComplex();
#else
- r = e1->toImaginary();
- c = e2->toComplex();
- c = complex_t(-r * cimagl(c), r * creall(c));
+ r = e1->toImaginary();
+ c = e2->toComplex();
+ c = complex_t(-r * cimagl(c), r * creall(c));
#endif
- }
- else if (e2->type->isreal())
- {
+ }
+ else if (e2->type->isreal())
+ {
#if __DMC__
- c = e2->toReal() * e1->toComplex();
+ c = e2->toReal() * e1->toComplex();
#else
- r = e2->toReal();
- c = e1->toComplex();
- c = complex_t(r * creall(c), r * cimagl(c));
+ r = e2->toReal();
+ c = e1->toComplex();
+ c = complex_t(r * creall(c), r * cimagl(c));
#endif
- }
- else if (e2->type->isimaginary())
- {
+ }
+ else if (e2->type->isimaginary())
+ {
#if __DMC__
- c = e1->toComplex() * e2->toImaginary() * I;
+ c = e1->toComplex() * e2->toImaginary() * I;
#else
- r = e2->toImaginary();
- c = e1->toComplex();
- c = complex_t(-r * cimagl(c), r * creall(c));
+ r = e2->toImaginary();
+ c = e1->toComplex();
+ c = complex_t(-r * cimagl(c), r * creall(c));
#endif
- }
- else
- c = e1->toComplex() * e2->toComplex();
+ }
+ else
+ c = e1->toComplex() * e2->toComplex();
- if (type->isreal())
- e = new RealExp(loc, creall(c), type);
- else if (type->isimaginary())
- e = new RealExp(loc, cimagl(c), type);
- else if (type->iscomplex())
- e = new ComplexExp(loc, c, type);
- else
- assert(0);
+ if (type->isreal())
+ e = new RealExp(loc, creall(c), type);
+ else if (type->isimaginary())
+ e = new RealExp(loc, cimagl(c), type);
+ else if (type->iscomplex())
+ e = new ComplexExp(loc, c, type);
+ else
+ assert(0);
}
else
{
- e = new IntegerExp(loc, e1->toInteger() * e2->toInteger(), type);
+ e = new IntegerExp(loc, e1->toInteger() * e2->toInteger(), type);
}
return e;
}
@@ -407,77 +407,77 @@ Expression *Div(Type *type, Expression *e1, Expression *e2)
if (type->isfloating())
{ complex_t c;
#ifdef IN_GCC
- real_t r;
+ real_t r;
#else
- d_float80 r;
+ d_float80 r;
#endif
- //e1->type->print();
- //e2->type->print();
- if (e2->type->isreal())
- {
- if (e1->type->isreal())
- {
- e = new RealExp(loc, e1->toReal() / e2->toReal(), type);
- return e;
- }
+ //e1->type->print();
+ //e2->type->print();
+ if (e2->type->isreal())
+ {
+ if (e1->type->isreal())
+ {
+ e = new RealExp(loc, e1->toReal() / e2->toReal(), type);
+ return e;
+ }
#if __DMC__
- //r = e2->toReal();
- //c = e1->toComplex();
- //printf("(%Lg + %Lgi) / %Lg\n", creall(c), cimagl(c), r);
+ //r = e2->toReal();
+ //c = e1->toComplex();
+ //printf("(%Lg + %Lgi) / %Lg\n", creall(c), cimagl(c), r);
- c = e1->toComplex() / e2->toReal();
+ c = e1->toComplex() / e2->toReal();
#else
- r = e2->toReal();
- c = e1->toComplex();
- c = complex_t(creall(c) / r, cimagl(c) / r);
+ r = e2->toReal();
+ c = e1->toComplex();
+ c = complex_t(creall(c) / r, cimagl(c) / r);
#endif
- }
- else if (e2->type->isimaginary())
- {
+ }
+ else if (e2->type->isimaginary())
+ {
#if __DMC__
- //r = e2->toImaginary();
- //c = e1->toComplex();
- //printf("(%Lg + %Lgi) / %Lgi\n", creall(c), cimagl(c), r);
+ //r = e2->toImaginary();
+ //c = e1->toComplex();
+ //printf("(%Lg + %Lgi) / %Lgi\n", creall(c), cimagl(c), r);
- c = e1->toComplex() / (e2->toImaginary() * I);
+ c = e1->toComplex() / (e2->toImaginary() * I);
#else
- r = e2->toImaginary();
- c = e1->toComplex();
- c = complex_t(cimagl(c) / r, -creall(c) / r);
+ r = e2->toImaginary();
+ c = e1->toComplex();
+ c = complex_t(cimagl(c) / r, -creall(c) / r);
#endif
- }
- else
- {
- c = e1->toComplex() / e2->toComplex();
- }
+ }
+ else
+ {
+ c = e1->toComplex() / e2->toComplex();
+ }
- if (type->isreal())
- e = new RealExp(loc, creall(c), type);
- else if (type->isimaginary())
- e = new RealExp(loc, cimagl(c), type);
- else if (type->iscomplex())
- e = new ComplexExp(loc, c, type);
- else
- assert(0);
+ if (type->isreal())
+ e = new RealExp(loc, creall(c), type);
+ else if (type->isimaginary())
+ e = new RealExp(loc, cimagl(c), type);
+ else if (type->iscomplex())
+ e = new ComplexExp(loc, c, type);
+ else
+ assert(0);
}
else
{ sinteger_t n1;
- sinteger_t n2;
- sinteger_t n;
+ sinteger_t n2;
+ sinteger_t n;
- n1 = e1->toInteger();
- n2 = e2->toInteger();
- if (n2 == 0)
- { e2->error("divide by 0");
- e2 = new IntegerExp(loc, 1, e2->type);
- n2 = 1;
- }
- if (e1->type->isunsigned() || e2->type->isunsigned())
- n = ((d_uns64) n1) / ((d_uns64) n2);
- else
- n = n1 / n2;
- e = new IntegerExp(loc, n, type);
+ n1 = e1->toInteger();
+ n2 = e2->toInteger();
+ if (n2 == 0)
+ { e2->error("divide by 0");
+ e2 = new IntegerExp(loc, 1, e2->type);
+ n2 = 1;
+ }
+ if (e1->type->isunsigned() || e2->type->isunsigned())
+ n = ((d_uns64) n1) / ((d_uns64) n2);
+ else
+ n = n1 / n2;
+ e = new IntegerExp(loc, n, type);
}
return e;
}
@@ -488,67 +488,67 @@ Expression *Mod(Type *type, Expression *e1, Expression *e2)
if (type->isfloating())
{
- complex_t c;
+ complex_t c;
- if (e2->type->isreal())
- { real_t r2 = e2->toReal();
+ if (e2->type->isreal())
+ { real_t r2 = e2->toReal();
#ifdef __DMC__
- c = fmodl(e1->toReal(), r2) + fmodl(e1->toImaginary(), r2) * I;
+ c = fmodl(e1->toReal(), r2) + fmodl(e1->toImaginary(), r2) * I;
#elif defined(IN_GCC)
- c = complex_t(e1->toReal() % r2, e1->toImaginary() % r2);
-#elif (defined(__FreeBSD__) && __FreeBSD_version < 800000) || defined(__arm__) || defined(__thumb__)
- // freebsd is kinda messed up. the STABLE branch doesn't support C99's fmodl !?!
- // arm also doesn't like fmodl
- c = complex_t(fmod(e1->toReal(), r2), fmod(e1->toImaginary(), r2));
-#else
- c = complex_t(fmodl(e1->toReal(), r2), fmodl(e1->toImaginary(), r2));
-#endif
- }
- else if (e2->type->isimaginary())
- { real_t i2 = e2->toImaginary();
-
-#ifdef __DMC__
- c = fmodl(e1->toReal(), i2) + fmodl(e1->toImaginary(), i2) * I;
-#elif defined(IN_GCC)
- c = complex_t(e1->toReal() % i2, e1->toImaginary() % i2);
+ c = complex_t(e1->toReal() % r2, e1->toImaginary() % r2);
#elif (defined(__FreeBSD__) && __FreeBSD_version < 800000) || defined(__arm__) || defined(__thumb__)
// freebsd is kinda messed up. the STABLE branch doesn't support C99's fmodl !?!
- // arm also doesn't like fmodl
- c = complex_t(fmod(e1->toReal(), i2), fmod(e1->toImaginary(), i2));
+ // arm also doesn't like fmodl
+ c = complex_t(fmod(e1->toReal(), r2), fmod(e1->toImaginary(), r2));
#else
- c = complex_t(fmodl(e1->toReal(), i2), fmodl(e1->toImaginary(), i2));
+ c = complex_t(fmodl(e1->toReal(), r2), fmodl(e1->toImaginary(), r2));
#endif
- }
- else
- assert(0);
+ }
+ else if (e2->type->isimaginary())
+ { real_t i2 = e2->toImaginary();
- if (type->isreal())
- e = new RealExp(loc, creall(c), type);
- else if (type->isimaginary())
- e = new RealExp(loc, cimagl(c), type);
- else if (type->iscomplex())
- e = new ComplexExp(loc, c, type);
- else
- assert(0);
+#ifdef __DMC__
+ c = fmodl(e1->toReal(), i2) + fmodl(e1->toImaginary(), i2) * I;
+#elif defined(IN_GCC)
+ c = complex_t(e1->toReal() % i2, e1->toImaginary() % i2);
+#elif (defined(__FreeBSD__) && __FreeBSD_version < 800000) || defined(__arm__) || defined(__thumb__)
+ // freebsd is kinda messed up. the STABLE branch doesn't support C99's fmodl !?!
+ // arm also doesn't like fmodl
+ c = complex_t(fmod(e1->toReal(), i2), fmod(e1->toImaginary(), i2));
+#else
+ c = complex_t(fmodl(e1->toReal(), i2), fmodl(e1->toImaginary(), i2));
+#endif
+ }
+ else
+ assert(0);
+
+ if (type->isreal())
+ e = new RealExp(loc, creall(c), type);
+ else if (type->isimaginary())
+ e = new RealExp(loc, cimagl(c), type);
+ else if (type->iscomplex())
+ e = new ComplexExp(loc, c, type);
+ else
+ assert(0);
}
else
{ sinteger_t n1;
- sinteger_t n2;
- sinteger_t n;
+ sinteger_t n2;
+ sinteger_t n;
- n1 = e1->toInteger();
- n2 = e2->toInteger();
- if (n2 == 0)
- { e2->error("divide by 0");
- e2 = new IntegerExp(loc, 1, e2->type);
- n2 = 1;
- }
- if (e1->type->isunsigned() || e2->type->isunsigned())
- n = ((d_uns64) n1) % ((d_uns64) n2);
- else
- n = n1 % n2;
- e = new IntegerExp(loc, n, type);
+ n1 = e1->toInteger();
+ n2 = e2->toInteger();
+ if (n2 == 0)
+ { e2->error("divide by 0");
+ e2 = new IntegerExp(loc, 1, e2->type);
+ n2 = 1;
+ }
+ if (e1->type->isunsigned() || e2->type->isunsigned())
+ n = ((d_uns64) n1) % ((d_uns64) n2);
+ else
+ n = n1 % n2;
+ e = new IntegerExp(loc, n, type);
}
return e;
}
@@ -571,40 +571,40 @@ Expression *Shr(Type *type, Expression *e1, Expression *e2)
count = e2->toInteger();
switch (e1->type->toBasetype()->ty)
{
- case Tint8:
- value = (d_int8)(value) >> count;
- break;
+ case Tint8:
+ value = (d_int8)(value) >> count;
+ break;
- case Tuns8:
- value = (d_uns8)(value) >> count;
- break;
+ case Tuns8:
+ value = (d_uns8)(value) >> count;
+ break;
- case Tint16:
- value = (d_int16)(value) >> count;
- break;
+ case Tint16:
+ value = (d_int16)(value) >> count;
+ break;
- case Tuns16:
- value = (d_uns16)(value) >> count;
- break;
+ case Tuns16:
+ value = (d_uns16)(value) >> count;
+ break;
- case Tint32:
- value = (d_int32)(value) >> count;
- break;
+ case Tint32:
+ value = (d_int32)(value) >> count;
+ break;
- case Tuns32:
- value = (d_uns32)(value) >> count;
- break;
+ case Tuns32:
+ value = (d_uns32)(value) >> count;
+ break;
- case Tint64:
- value = (d_int64)(value) >> count;
- break;
+ case Tint64:
+ value = (d_int64)(value) >> count;
+ break;
- case Tuns64:
- value = (d_uns64)(value) >> count;
- break;
+ case Tuns64:
+ value = (d_uns64)(value) >> count;
+ break;
- default:
- assert(0);
+ default:
+ assert(0);
}
e = new IntegerExp(loc, value, type);
return e;
@@ -620,30 +620,30 @@ Expression *Ushr(Type *type, Expression *e1, Expression *e2)
count = e2->toInteger();
switch (e1->type->toBasetype()->ty)
{
- case Tint8:
- case Tuns8:
- assert(0); // no way to trigger this
- value = (value & 0xFF) >> count;
- break;
+ case Tint8:
+ case Tuns8:
+ assert(0); // no way to trigger this
+ value = (value & 0xFF) >> count;
+ break;
- case Tint16:
- case Tuns16:
- assert(0); // no way to trigger this
- value = (value & 0xFFFF) >> count;
- break;
+ case Tint16:
+ case Tuns16:
+ assert(0); // no way to trigger this
+ value = (value & 0xFFFF) >> count;
+ break;
- case Tint32:
- case Tuns32:
- value = (value & 0xFFFFFFFF) >> count;
- break;
+ case Tint32:
+ case Tuns32:
+ value = (value & 0xFFFFFFFF) >> count;
+ break;
- case Tint64:
- case Tuns64:
- value = (d_uns64)(value) >> count;
- break;
+ case Tint64:
+ case Tuns64:
+ value = (d_uns64)(value) >> count;
+ break;
- default:
- assert(0);
+ default:
+ assert(0);
}
e = new IntegerExp(loc, value, type);
return e;
@@ -683,137 +683,137 @@ Expression *Equal(enum TOK op, Type *type, Expression *e1, Expression *e2)
if (e1->op == TOKnull)
{
- if (e2->op == TOKnull)
- cmp = 1;
- else if (e2->op == TOKstring)
- { StringExp *es2 = (StringExp *)e2;
- cmp = (0 == es2->len);
- }
- else if (e2->op == TOKarrayliteral)
- { ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
- cmp = !es2->elements || (0 == es2->elements->dim);
- }
- else
- return EXP_CANT_INTERPRET;
+ if (e2->op == TOKnull)
+ cmp = 1;
+ else if (e2->op == TOKstring)
+ { StringExp *es2 = (StringExp *)e2;
+ cmp = (0 == es2->len);
+ }
+ else if (e2->op == TOKarrayliteral)
+ { ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
+ cmp = !es2->elements || (0 == es2->elements->dim);
+ }
+ else
+ return EXP_CANT_INTERPRET;
}
else if (e2->op == TOKnull)
{
- if (e1->op == TOKstring)
- { StringExp *es1 = (StringExp *)e1;
- cmp = (0 == es1->len);
- }
- else if (e1->op == TOKarrayliteral)
- { ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1;
- cmp = !es1->elements || (0 == es1->elements->dim);
- }
- else
- return EXP_CANT_INTERPRET;
+ if (e1->op == TOKstring)
+ { StringExp *es1 = (StringExp *)e1;
+ cmp = (0 == es1->len);
+ }
+ else if (e1->op == TOKarrayliteral)
+ { ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1;
+ cmp = !es1->elements || (0 == es1->elements->dim);
+ }
+ else
+ return EXP_CANT_INTERPRET;
}
else if (e1->op == TOKstring && e2->op == TOKstring)
- { StringExp *es1 = (StringExp *)e1;
- StringExp *es2 = (StringExp *)e2;
+ { StringExp *es1 = (StringExp *)e1;
+ StringExp *es2 = (StringExp *)e2;
- if (es1->sz != es2->sz)
- {
- assert(global.errors);
- return EXP_CANT_INTERPRET;
- }
- if (es1->len == es2->len &&
- memcmp(es1->string, es2->string, es1->sz * es1->len) == 0)
- cmp = 1;
- else
- cmp = 0;
+ if (es1->sz != es2->sz)
+ {
+ assert(global.errors);
+ return EXP_CANT_INTERPRET;
+ }
+ if (es1->len == es2->len &&
+ memcmp(es1->string, es2->string, es1->sz * es1->len) == 0)
+ cmp = 1;
+ else
+ cmp = 0;
}
else if (e1->op == TOKarrayliteral && e2->op == TOKarrayliteral)
{ ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1;
- ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
+ ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
- if ((!es1->elements || !es1->elements->dim) &&
- (!es2->elements || !es2->elements->dim))
- cmp = 1; // both arrays are empty
- else if (!es1->elements || !es2->elements)
- cmp = 0;
- else if (es1->elements->dim != es2->elements->dim)
- cmp = 0;
- else
- {
- for (size_t i = 0; i < es1->elements->dim; i++)
- { Expression *ee1 = (Expression *)es1->elements->data[i];
- Expression *ee2 = (Expression *)es2->elements->data[i];
+ if ((!es1->elements || !es1->elements->dim) &&
+ (!es2->elements || !es2->elements->dim))
+ cmp = 1; // both arrays are empty
+ else if (!es1->elements || !es2->elements)
+ cmp = 0;
+ else if (es1->elements->dim != es2->elements->dim)
+ cmp = 0;
+ else
+ {
+ for (size_t i = 0; i < es1->elements->dim; i++)
+ { Expression *ee1 = (Expression *)es1->elements->data[i];
+ Expression *ee2 = (Expression *)es2->elements->data[i];
- Expression *v = Equal(TOKequal, Type::tint32, ee1, ee2);
- if (v == EXP_CANT_INTERPRET)
- return EXP_CANT_INTERPRET;
- cmp = v->toInteger();
- if (cmp == 0)
- break;
- }
- }
+ Expression *v = Equal(TOKequal, Type::tint32, ee1, ee2);
+ if (v == EXP_CANT_INTERPRET)
+ return EXP_CANT_INTERPRET;
+ cmp = v->toInteger();
+ if (cmp == 0)
+ break;
+ }
+ }
}
else if (e1->op == TOKarrayliteral && e2->op == TOKstring)
- { // Swap operands and use common code
- Expression *e = e1;
- e1 = e2;
- e2 = e;
- goto Lsa;
+ { // Swap operands and use common code
+ Expression *e = e1;
+ e1 = e2;
+ e2 = e;
+ goto Lsa;
}
else if (e1->op == TOKstring && e2->op == TOKarrayliteral)
{
Lsa:
- StringExp *es1 = (StringExp *)e1;
- ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
- size_t dim1 = es1->len;
- size_t dim2 = es2->elements ? es2->elements->dim : 0;
- if (dim1 != dim2)
- cmp = 0;
- else
- {
- for (size_t i = 0; i < dim1; i++)
- {
- uinteger_t c = es1->charAt(i);
- Expression *ee2 = (Expression *)es2->elements->data[i];
- if (ee2->isConst() != 1)
- return EXP_CANT_INTERPRET;
- cmp = (c == ee2->toInteger());
- if (cmp == 0)
- break;
- }
- }
+ StringExp *es1 = (StringExp *)e1;
+ ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
+ size_t dim1 = es1->len;
+ size_t dim2 = es2->elements ? es2->elements->dim : 0;
+ if (dim1 != dim2)
+ cmp = 0;
+ else
+ {
+ for (size_t i = 0; i < dim1; i++)
+ {
+ uinteger_t c = es1->charAt(i);
+ Expression *ee2 = (Expression *)es2->elements->data[i];
+ if (ee2->isConst() != 1)
+ return EXP_CANT_INTERPRET;
+ cmp = (c == ee2->toInteger());
+ if (cmp == 0)
+ break;
+ }
+ }
}
else if (e1->op == TOKstructliteral && e2->op == TOKstructliteral)
{ StructLiteralExp *es1 = (StructLiteralExp *)e1;
- StructLiteralExp *es2 = (StructLiteralExp *)e2;
+ StructLiteralExp *es2 = (StructLiteralExp *)e2;
- if (es1->sd != es2->sd)
- cmp = 0;
- else if ((!es1->elements || !es1->elements->dim) &&
- (!es2->elements || !es2->elements->dim))
- cmp = 1; // both arrays are empty
- else if (!es1->elements || !es2->elements)
- cmp = 0;
- else if (es1->elements->dim != es2->elements->dim)
- cmp = 0;
- else
- {
- cmp = 1;
- for (size_t i = 0; i < es1->elements->dim; i++)
- { Expression *ee1 = (Expression *)es1->elements->data[i];
- Expression *ee2 = (Expression *)es2->elements->data[i];
+ if (es1->sd != es2->sd)
+ cmp = 0;
+ else if ((!es1->elements || !es1->elements->dim) &&
+ (!es2->elements || !es2->elements->dim))
+ cmp = 1; // both arrays are empty
+ else if (!es1->elements || !es2->elements)
+ cmp = 0;
+ else if (es1->elements->dim != es2->elements->dim)
+ cmp = 0;
+ else
+ {
+ cmp = 1;
+ for (size_t i = 0; i < es1->elements->dim; i++)
+ { Expression *ee1 = (Expression *)es1->elements->data[i];
+ Expression *ee2 = (Expression *)es2->elements->data[i];
- if (ee1 == ee2)
- continue;
- if (!ee1 || !ee2)
- { cmp = 0;
- break;
- }
- Expression *v = Equal(TOKequal, Type::tint32, ee1, ee2);
- if (v == EXP_CANT_INTERPRET)
- return EXP_CANT_INTERPRET;
- cmp = v->toInteger();
- if (cmp == 0)
- break;
- }
- }
+ if (ee1 == ee2)
+ continue;
+ if (!ee1 || !ee2)
+ { cmp = 0;
+ break;
+ }
+ Expression *v = Equal(TOKequal, Type::tint32, ee1, ee2);
+ if (v == EXP_CANT_INTERPRET)
+ return EXP_CANT_INTERPRET;
+ cmp = v->toInteger();
+ if (cmp == 0)
+ break;
+ }
+ }
}
#if 0 // Should handle this
else if (e1->op == TOKarrayliteral && e2->op == TOKstring)
@@ -821,43 +821,43 @@ Expression *Equal(enum TOK op, Type *type, Expression *e1, Expression *e2)
}
#endif
else if (e1->isConst() != 1 || e2->isConst() != 1)
- return EXP_CANT_INTERPRET;
+ return EXP_CANT_INTERPRET;
else if (e1->type->isreal())
{
- r1 = e1->toReal();
- r2 = e2->toReal();
- goto L1;
+ r1 = e1->toReal();
+ r2 = e2->toReal();
+ goto L1;
}
else if (e1->type->isimaginary())
{
- r1 = e1->toImaginary();
- r2 = e2->toImaginary();
+ r1 = e1->toImaginary();
+ r2 = e2->toImaginary();
L1:
#if __DMC__
- cmp = (r1 == r2);
+ cmp = (r1 == r2);
#else
- if (Port::isNan(r1) || Port::isNan(r2)) // if unordered
- {
- cmp = 0;
- }
- else
- {
- cmp = (r1 == r2);
- }
+ if (Port::isNan(r1) || Port::isNan(r2)) // if unordered
+ {
+ cmp = 0;
+ }
+ else
+ {
+ cmp = (r1 == r2);
+ }
#endif
}
else if (e1->type->iscomplex())
{
- cmp = e1->toComplex() == e2->toComplex();
+ cmp = e1->toComplex() == e2->toComplex();
}
else if (e1->type->isintegral() || e1->type->toBasetype()->ty == Tpointer)
{
- cmp = (e1->toInteger() == e2->toInteger());
+ cmp = (e1->toInteger() == e2->toInteger());
}
else
- return EXP_CANT_INTERPRET;
+ return EXP_CANT_INTERPRET;
if (op == TOKnotequal)
- cmp ^= 1;
+ cmp ^= 1;
e = new IntegerExp(loc, cmp, type);
return e;
}
@@ -869,26 +869,26 @@ Expression *Identity(enum TOK op, Type *type, Expression *e1, Expression *e2)
if (e1->op == TOKnull)
{
- cmp = (e2->op == TOKnull);
+ cmp = (e2->op == TOKnull);
}
else if (e2->op == TOKnull)
{
- cmp = 0;
+ cmp = 0;
}
else if (e1->op == TOKsymoff && e2->op == TOKsymoff)
{
- SymOffExp *es1 = (SymOffExp *)e1;
- SymOffExp *es2 = (SymOffExp *)e2;
+ SymOffExp *es1 = (SymOffExp *)e1;
+ SymOffExp *es2 = (SymOffExp *)e2;
- cmp = (es1->var == es2->var && es1->offset == es2->offset);
+ cmp = (es1->var == es2->var && es1->offset == es2->offset);
}
else if (e1->isConst() == 1 && e2->isConst() == 1)
- return Equal((op == TOKidentity) ? TOKequal : TOKnotequal,
- type, e1, e2);
+ return Equal((op == TOKidentity) ? TOKequal : TOKnotequal,
+ type, e1, e2);
else
- assert(0);
+ assert(0);
if (op == TOKnotidentity)
- cmp ^= 1;
+ cmp ^= 1;
return new IntegerExp(loc, cmp, type);
}
@@ -902,146 +902,146 @@ Expression *Cmp(enum TOK op, Type *type, Expression *e1, Expression *e2)
if (e1->type->isreal())
{
- r1 = e1->toReal();
- r2 = e2->toReal();
- goto L1;
+ r1 = e1->toReal();
+ r2 = e2->toReal();
+ goto L1;
}
else if (e1->type->isimaginary())
{
- r1 = e1->toImaginary();
- r2 = e2->toImaginary();
+ r1 = e1->toImaginary();
+ r2 = e2->toImaginary();
L1:
#if __DMC__
- // DMC is the only compiler I know of that handles NAN arguments
- // correctly in comparisons.
- switch (op)
- {
- case TOKlt: n = r1 < r2; break;
- case TOKle: n = r1 <= r2; break;
- case TOKgt: n = r1 > r2; break;
- case TOKge: n = r1 >= r2; break;
+ // DMC is the only compiler I know of that handles NAN arguments
+ // correctly in comparisons.
+ switch (op)
+ {
+ case TOKlt: n = r1 < r2; break;
+ case TOKle: n = r1 <= r2; break;
+ case TOKgt: n = r1 > r2; break;
+ case TOKge: n = r1 >= r2; break;
- case TOKleg: n = r1 <>= r2; break;
- case TOKlg: n = r1 <> r2; break;
- case TOKunord: n = r1 !<>= r2; break;
- case TOKue: n = r1 !<> r2; break;
- case TOKug: n = r1 !<= r2; break;
- case TOKuge: n = r1 !< r2; break;
- case TOKul: n = r1 !>= r2; break;
- case TOKule: n = r1 !> r2; break;
+ case TOKleg: n = r1 <>= r2; break;
+ case TOKlg: n = r1 <> r2; break;
+ case TOKunord: n = r1 !<>= r2; break;
+ case TOKue: n = r1 !<> r2; break;
+ case TOKug: n = r1 !<= r2; break;
+ case TOKuge: n = r1 !< r2; break;
+ case TOKul: n = r1 !>= r2; break;
+ case TOKule: n = r1 !> r2; break;
- default:
- assert(0);
- }
+ default:
+ assert(0);
+ }
#else
- // Don't rely on compiler, handle NAN arguments separately
- if (Port::isNan(r1) || Port::isNan(r2)) // if unordered
- {
- switch (op)
- {
- case TOKlt: n = 0; break;
- case TOKle: n = 0; break;
- case TOKgt: n = 0; break;
- case TOKge: n = 0; break;
+ // Don't rely on compiler, handle NAN arguments separately
+ if (Port::isNan(r1) || Port::isNan(r2)) // if unordered
+ {
+ switch (op)
+ {
+ case TOKlt: n = 0; break;
+ case TOKle: n = 0; break;
+ case TOKgt: n = 0; break;
+ case TOKge: n = 0; break;
- case TOKleg: n = 0; break;
- case TOKlg: n = 0; break;
- case TOKunord: n = 1; break;
- case TOKue: n = 1; break;
- case TOKug: n = 1; break;
- case TOKuge: n = 1; break;
- case TOKul: n = 1; break;
- case TOKule: n = 1; break;
+ case TOKleg: n = 0; break;
+ case TOKlg: n = 0; break;
+ case TOKunord: n = 1; break;
+ case TOKue: n = 1; break;
+ case TOKug: n = 1; break;
+ case TOKuge: n = 1; break;
+ case TOKul: n = 1; break;
+ case TOKule: n = 1; break;
- default:
- assert(0);
- }
- }
- else
- {
- switch (op)
- {
- case TOKlt: n = r1 < r2; break;
- case TOKle: n = r1 <= r2; break;
- case TOKgt: n = r1 > r2; break;
- case TOKge: n = r1 >= r2; break;
+ default:
+ assert(0);
+ }
+ }
+ else
+ {
+ switch (op)
+ {
+ case TOKlt: n = r1 < r2; break;
+ case TOKle: n = r1 <= r2; break;
+ case TOKgt: n = r1 > r2; break;
+ case TOKge: n = r1 >= r2; break;
- case TOKleg: n = 1; break;
- case TOKlg: n = r1 != r2; break;
- case TOKunord: n = 0; break;
- case TOKue: n = r1 == r2; break;
- case TOKug: n = r1 > r2; break;
- case TOKuge: n = r1 >= r2; break;
- case TOKul: n = r1 < r2; break;
- case TOKule: n = r1 <= r2; break;
+ case TOKleg: n = 1; break;
+ case TOKlg: n = r1 != r2; break;
+ case TOKunord: n = 0; break;
+ case TOKue: n = r1 == r2; break;
+ case TOKug: n = r1 > r2; break;
+ case TOKuge: n = r1 >= r2; break;
+ case TOKul: n = r1 < r2; break;
+ case TOKule: n = r1 <= r2; break;
- default:
- assert(0);
- }
- }
+ default:
+ assert(0);
+ }
+ }
#endif
}
else if (e1->type->iscomplex())
{
- assert(0);
+ assert(0);
}
else
{ sinteger_t n1;
- sinteger_t n2;
+ sinteger_t n2;
- n1 = e1->toInteger();
- n2 = e2->toInteger();
- if (e1->type->isunsigned() || e2->type->isunsigned())
- {
- switch (op)
- {
- case TOKlt: n = ((d_uns64) n1) < ((d_uns64) n2); break;
- case TOKle: n = ((d_uns64) n1) <= ((d_uns64) n2); break;
- case TOKgt: n = ((d_uns64) n1) > ((d_uns64) n2); break;
- case TOKge: n = ((d_uns64) n1) >= ((d_uns64) n2); break;
+ n1 = e1->toInteger();
+ n2 = e2->toInteger();
+ if (e1->type->isunsigned() || e2->type->isunsigned())
+ {
+ switch (op)
+ {
+ case TOKlt: n = ((d_uns64) n1) < ((d_uns64) n2); break;
+ case TOKle: n = ((d_uns64) n1) <= ((d_uns64) n2); break;
+ case TOKgt: n = ((d_uns64) n1) > ((d_uns64) n2); break;
+ case TOKge: n = ((d_uns64) n1) >= ((d_uns64) n2); break;
- case TOKleg: n = 1; break;
- case TOKlg: n = ((d_uns64) n1) != ((d_uns64) n2); break;
- case TOKunord: n = 0; break;
- case TOKue: n = ((d_uns64) n1) == ((d_uns64) n2); break;
- case TOKug: n = ((d_uns64) n1) > ((d_uns64) n2); break;
- case TOKuge: n = ((d_uns64) n1) >= ((d_uns64) n2); break;
- case TOKul: n = ((d_uns64) n1) < ((d_uns64) n2); break;
- case TOKule: n = ((d_uns64) n1) <= ((d_uns64) n2); break;
+ case TOKleg: n = 1; break;
+ case TOKlg: n = ((d_uns64) n1) != ((d_uns64) n2); break;
+ case TOKunord: n = 0; break;
+ case TOKue: n = ((d_uns64) n1) == ((d_uns64) n2); break;
+ case TOKug: n = ((d_uns64) n1) > ((d_uns64) n2); break;
+ case TOKuge: n = ((d_uns64) n1) >= ((d_uns64) n2); break;
+ case TOKul: n = ((d_uns64) n1) < ((d_uns64) n2); break;
+ case TOKule: n = ((d_uns64) n1) <= ((d_uns64) n2); break;
- default:
- assert(0);
- }
- }
- else
- {
- switch (op)
- {
- case TOKlt: n = n1 < n2; break;
- case TOKle: n = n1 <= n2; break;
- case TOKgt: n = n1 > n2; break;
- case TOKge: n = n1 >= n2; break;
+ default:
+ assert(0);
+ }
+ }
+ else
+ {
+ switch (op)
+ {
+ case TOKlt: n = n1 < n2; break;
+ case TOKle: n = n1 <= n2; break;
+ case TOKgt: n = n1 > n2; break;
+ case TOKge: n = n1 >= n2; break;
- case TOKleg: n = 1; break;
- case TOKlg: n = n1 != n2; break;
- case TOKunord: n = 0; break;
- case TOKue: n = n1 == n2; break;
- case TOKug: n = n1 > n2; break;
- case TOKuge: n = n1 >= n2; break;
- case TOKul: n = n1 < n2; break;
- case TOKule: n = n1 <= n2; break;
+ case TOKleg: n = 1; break;
+ case TOKlg: n = n1 != n2; break;
+ case TOKunord: n = 0; break;
+ case TOKue: n = n1 == n2; break;
+ case TOKug: n = n1 > n2; break;
+ case TOKuge: n = n1 >= n2; break;
+ case TOKul: n = n1 < n2; break;
+ case TOKule: n = n1 <= n2; break;
- default:
- assert(0);
- }
- }
+ default:
+ assert(0);
+ }
+ }
}
e = new IntegerExp(loc, n, type);
return e;
}
/* Also returns EXP_CANT_INTERPRET if cannot be computed.
- * to: type to cast to
+ * to: type to cast to
* type: type to paint the result
*/
@@ -1052,7 +1052,7 @@ Expression *Cast(Type *type, Type *to, Expression *e1)
//printf("Cast(type = %s, to = %s, e1 = %s)\n", type->toChars(), to->toChars(), e1->toChars());
//printf("e1->type = %s\n", e1->type->toChars());
if (type->equals(e1->type) && to->equals(type))
- return e1;
+ return e1;
Type *tb = to->toBasetype();
Type *typeb = type->toBasetype();
@@ -1061,11 +1061,11 @@ Expression *Cast(Type *type, Type *to, Expression *e1)
*/
if (e1->op == TOKstring)
{
- if (tb->ty == Tarray && typeb->ty == Tarray &&
- tb->nextOf()->size() == typeb->nextOf()->size())
- {
- return expType(to, e1);
- }
+ if (tb->ty == Tarray && typeb->ty == Tarray &&
+ tb->nextOf()->size() == typeb->nextOf()->size())
+ {
+ return expType(to, e1);
+ }
}
if (e1->op == TOKarrayliteral && typeb == tb)
@@ -1075,83 +1075,83 @@ Expression *Cast(Type *type, Type *to, Expression *e1)
if (e1->isConst() != 1)
{
- return EXP_CANT_INTERPRET;
+ return EXP_CANT_INTERPRET;
}
if (tb->ty == Tbool)
- e = new IntegerExp(loc, e1->toInteger() != 0, type);
+ e = new IntegerExp(loc, e1->toInteger() != 0, type);
else if (type->isintegral())
{
- if (e1->type->isfloating())
- { dinteger_t result;
- real_t r = e1->toReal();
+ if (e1->type->isfloating())
+ { dinteger_t result;
+ real_t r = e1->toReal();
- switch (type->toBasetype()->ty)
- {
- case Tint8: result = (d_int8)r; break;
- case Tchar:
- case Tuns8: result = (d_uns8)r; break;
- case Tint16: result = (d_int16)r; break;
- case Twchar:
- case Tuns16: result = (d_uns16)r; break;
- case Tint32: result = (d_int32)r; break;
- case Tdchar:
- case Tuns32: result = (d_uns32)r; break;
- case Tint64: result = (d_int64)r; break;
- case Tuns64: result = (d_uns64)r; break;
- default:
- assert(0);
- }
+ switch (type->toBasetype()->ty)
+ {
+ case Tint8: result = (d_int8)r; break;
+ case Tchar:
+ case Tuns8: result = (d_uns8)r; break;
+ case Tint16: result = (d_int16)r; break;
+ case Twchar:
+ case Tuns16: result = (d_uns16)r; break;
+ case Tint32: result = (d_int32)r; break;
+ case Tdchar:
+ case Tuns32: result = (d_uns32)r; break;
+ case Tint64: result = (d_int64)r; break;
+ case Tuns64: result = (d_uns64)r; break;
+ default:
+ assert(0);
+ }
- e = new IntegerExp(loc, result, type);
- }
- else if (type->isunsigned())
- e = new IntegerExp(loc, e1->toUInteger(), type);
- else
- e = new IntegerExp(loc, e1->toInteger(), type);
+ e = new IntegerExp(loc, result, type);
+ }
+ else if (type->isunsigned())
+ e = new IntegerExp(loc, e1->toUInteger(), type);
+ else
+ e = new IntegerExp(loc, e1->toInteger(), type);
}
else if (tb->isreal())
{ real_t value = e1->toReal();
- e = new RealExp(loc, value, type);
+ e = new RealExp(loc, value, type);
}
else if (tb->isimaginary())
{ real_t value = e1->toImaginary();
- e = new RealExp(loc, value, type);
+ e = new RealExp(loc, value, type);
}
else if (tb->iscomplex())
{ complex_t value = e1->toComplex();
- e = new ComplexExp(loc, value, type);
+ e = new ComplexExp(loc, value, type);
}
else if (tb->isscalar())
- e = new IntegerExp(loc, e1->toInteger(), type);
+ e = new IntegerExp(loc, e1->toInteger(), type);
else if (tb->ty == Tvoid)
- e = EXP_CANT_INTERPRET;
+ e = EXP_CANT_INTERPRET;
else if (tb->ty == Tstruct && e1->op == TOKint64)
- { // Struct = 0;
- StructDeclaration *sd = tb->toDsymbol(NULL)->isStructDeclaration();
- assert(sd);
- Expressions *elements = new Expressions;
- for (size_t i = 0; i < sd->fields.dim; i++)
- { Dsymbol *s = (Dsymbol *)sd->fields.data[i];
- VarDeclaration *v = s->isVarDeclaration();
- assert(v);
+ { // Struct = 0;
+ StructDeclaration *sd = tb->toDsymbol(NULL)->isStructDeclaration();
+ assert(sd);
+ Expressions *elements = new Expressions;
+ for (size_t i = 0; i < sd->fields.dim; i++)
+ { Dsymbol *s = (Dsymbol *)sd->fields.data[i];
+ VarDeclaration *v = s->isVarDeclaration();
+ assert(v);
- Expression *exp = new IntegerExp(0);
- exp = Cast(v->type, v->type, exp);
- if (exp == EXP_CANT_INTERPRET)
- return exp;
- elements->push(exp);
- }
- e = new StructLiteralExp(loc, sd, elements);
- e->type = type;
+ Expression *exp = new IntegerExp(0);
+ exp = Cast(v->type, v->type, exp);
+ if (exp == EXP_CANT_INTERPRET)
+ return exp;
+ elements->push(exp);
+ }
+ e = new StructLiteralExp(loc, sd, elements);
+ e->type = type;
}
else
{
- error(loc, "cannot cast %s to %s", e1->type->toChars(), type->toChars());
- e = new IntegerExp(loc, 0, Type::tint32);
+ error(loc, "cannot cast %s to %s", e1->type->toChars(), type->toChars());
+ e = new IntegerExp(loc, 0, Type::tint32);
}
return e;
}
@@ -1162,25 +1162,25 @@ Expression *ArrayLength(Type *type, Expression *e1)
Loc loc = e1->loc;
if (e1->op == TOKstring)
- { StringExp *es1 = (StringExp *)e1;
+ { StringExp *es1 = (StringExp *)e1;
- e = new IntegerExp(loc, es1->len, type);
+ e = new IntegerExp(loc, es1->len, type);
}
else if (e1->op == TOKarrayliteral)
- { ArrayLiteralExp *ale = (ArrayLiteralExp *)e1;
- size_t dim;
+ { ArrayLiteralExp *ale = (ArrayLiteralExp *)e1;
+ size_t dim;
- dim = ale->elements ? ale->elements->dim : 0;
- e = new IntegerExp(loc, dim, type);
+ dim = ale->elements ? ale->elements->dim : 0;
+ e = new IntegerExp(loc, dim, type);
}
else if (e1->op == TOKassocarrayliteral)
- { AssocArrayLiteralExp *ale = (AssocArrayLiteralExp *)e1;
- size_t dim = ale->keys->dim;
+ { AssocArrayLiteralExp *ale = (AssocArrayLiteralExp *)e1;
+ size_t dim = ale->keys->dim;
- e = new IntegerExp(loc, dim, type);
+ e = new IntegerExp(loc, dim, type);
}
else
- e = EXP_CANT_INTERPRET;
+ e = EXP_CANT_INTERPRET;
return e;
}
@@ -1193,63 +1193,63 @@ Expression *Index(Type *type, Expression *e1, Expression *e2)
//printf("Index(e1 = %s, e2 = %s)\n", e1->toChars(), e2->toChars());
assert(e1->type);
if (e1->op == TOKstring && e2->op == TOKint64)
- { StringExp *es1 = (StringExp *)e1;
- uinteger_t i = e2->toInteger();
+ { StringExp *es1 = (StringExp *)e1;
+ uinteger_t i = e2->toInteger();
- if (i >= es1->len)
- e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len);
- else
- { unsigned value = es1->charAt(i);
- e = new IntegerExp(loc, value, type);
- }
+ if (i >= es1->len)
+ e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len);
+ else
+ { unsigned value = es1->charAt(i);
+ e = new IntegerExp(loc, value, type);
+ }
}
else if (e1->type->toBasetype()->ty == Tsarray && e2->op == TOKint64)
- { TypeSArray *tsa = (TypeSArray *)e1->type->toBasetype();
- uinteger_t length = tsa->dim->toInteger();
- uinteger_t i = e2->toInteger();
+ { TypeSArray *tsa = (TypeSArray *)e1->type->toBasetype();
+ uinteger_t length = tsa->dim->toInteger();
+ uinteger_t i = e2->toInteger();
- if (i >= length)
- { e2->error("array index %ju is out of bounds %s[0 .. %ju]", i, e1->toChars(), length);
- }
- else if (e1->op == TOKarrayliteral && !e1->checkSideEffect(2))
- { ArrayLiteralExp *ale = (ArrayLiteralExp *)e1;
- e = (Expression *)ale->elements->data[i];
- e->type = type;
- }
+ if (i >= length)
+ { e2->error("array index %ju is out of bounds %s[0 .. %ju]", i, e1->toChars(), length);
+ }
+ else if (e1->op == TOKarrayliteral && !e1->checkSideEffect(2))
+ { ArrayLiteralExp *ale = (ArrayLiteralExp *)e1;
+ e = (Expression *)ale->elements->data[i];
+ e->type = type;
+ }
}
else if (e1->type->toBasetype()->ty == Tarray && e2->op == TOKint64)
{
- uinteger_t i = e2->toInteger();
+ uinteger_t i = e2->toInteger();
- if (e1->op == TOKarrayliteral && !e1->checkSideEffect(2))
- { ArrayLiteralExp *ale = (ArrayLiteralExp *)e1;
- if (i >= ale->elements->dim)
- { e2->error("array index %ju is out of bounds %s[0 .. %u]", i, e1->toChars(), ale->elements->dim);
- }
- else
- { e = (Expression *)ale->elements->data[i];
- e->type = type;
- }
- }
+ if (e1->op == TOKarrayliteral && !e1->checkSideEffect(2))
+ { ArrayLiteralExp *ale = (ArrayLiteralExp *)e1;
+ if (i >= ale->elements->dim)
+ { e2->error("array index %ju is out of bounds %s[0 .. %u]", i, e1->toChars(), ale->elements->dim);
+ }
+ else
+ { e = (Expression *)ale->elements->data[i];
+ e->type = type;
+ }
+ }
}
else if (e1->op == TOKassocarrayliteral && !e1->checkSideEffect(2))
{
- AssocArrayLiteralExp *ae = (AssocArrayLiteralExp *)e1;
- /* Search the keys backwards, in case there are duplicate keys
- */
- for (size_t i = ae->keys->dim; i;)
- {
- i--;
- Expression *ekey = (Expression *)ae->keys->data[i];
- Expression *ex = Equal(TOKequal, Type::tbool, ekey, e2);
- if (ex == EXP_CANT_INTERPRET)
- return ex;
- if (ex->isBool(TRUE))
- { e = (Expression *)ae->values->data[i];
- e->type = type;
- break;
- }
- }
+ AssocArrayLiteralExp *ae = (AssocArrayLiteralExp *)e1;
+ /* Search the keys backwards, in case there are duplicate keys
+ */
+ for (size_t i = ae->keys->dim; i;)
+ {
+ i--;
+ Expression *ekey = (Expression *)ae->keys->data[i];
+ Expression *ex = Equal(TOKequal, Type::tbool, ekey, e2);
+ if (ex == EXP_CANT_INTERPRET)
+ return ex;
+ if (ex->isBool(TRUE))
+ { e = (Expression *)ae->values->data[i];
+ e->type = type;
+ break;
+ }
+ }
}
return e;
}
@@ -1263,55 +1263,55 @@ Expression *Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr)
#if LOG
printf("Slice()\n");
if (lwr)
- { printf("\te1 = %s\n", e1->toChars());
- printf("\tlwr = %s\n", lwr->toChars());
- printf("\tupr = %s\n", upr->toChars());
+ { printf("\te1 = %s\n", e1->toChars());
+ printf("\tlwr = %s\n", lwr->toChars());
+ printf("\tupr = %s\n", upr->toChars());
}
#endif
if (e1->op == TOKstring && lwr->op == TOKint64 && upr->op == TOKint64)
- { StringExp *es1 = (StringExp *)e1;
- uinteger_t ilwr = lwr->toInteger();
- uinteger_t iupr = upr->toInteger();
+ { StringExp *es1 = (StringExp *)e1;
+ uinteger_t ilwr = lwr->toInteger();
+ uinteger_t iupr = upr->toInteger();
- if (iupr > es1->len || ilwr > iupr)
- e1->error("string slice [%ju .. %ju] is out of bounds", ilwr, iupr);
- else
- { dinteger_t value;
- void *s;
- size_t len = iupr - ilwr;
- int sz = es1->sz;
- StringExp *es;
+ if (iupr > es1->len || ilwr > iupr)
+ e1->error("string slice [%ju .. %ju] is out of bounds", ilwr, iupr);
+ else
+ { dinteger_t value;
+ void *s;
+ size_t len = iupr - ilwr;
+ int sz = es1->sz;
+ StringExp *es;
- s = mem.malloc((len + 1) * sz);
- memcpy((unsigned char *)s, (unsigned char *)es1->string + ilwr * sz, len * sz);
- memset((unsigned char *)s + len * sz, 0, sz);
+ s = mem.malloc((len + 1) * sz);
+ memcpy((unsigned char *)s, (unsigned char *)es1->string + ilwr * sz, len * sz);
+ memset((unsigned char *)s + len * sz, 0, sz);
- es = new StringExp(loc, s, len, es1->postfix);
- es->sz = sz;
- es->committed = 1;
- es->type = type;
- e = es;
- }
+ es = new StringExp(loc, s, len, es1->postfix);
+ es->sz = sz;
+ es->committed = 1;
+ es->type = type;
+ e = es;
+ }
}
else if (e1->op == TOKarrayliteral &&
- lwr->op == TOKint64 && upr->op == TOKint64 &&
- !e1->checkSideEffect(2))
- { ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1;
- uinteger_t ilwr = lwr->toInteger();
- uinteger_t iupr = upr->toInteger();
+ lwr->op == TOKint64 && upr->op == TOKint64 &&
+ !e1->checkSideEffect(2))
+ { ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1;
+ uinteger_t ilwr = lwr->toInteger();
+ uinteger_t iupr = upr->toInteger();
- if (iupr > es1->elements->dim || ilwr > iupr)
- e1->error("array slice [%ju .. %ju] is out of bounds", ilwr, iupr);
- else
- {
- Expressions *elements = new Expressions();
- elements->setDim(iupr - ilwr);
- memcpy(elements->data,
- es1->elements->data + ilwr,
- (iupr - ilwr) * sizeof(es1->elements->data[0]));
- e = new ArrayLiteralExp(e1->loc, elements);
- e->type = type;
- }
+ if (iupr > es1->elements->dim || ilwr > iupr)
+ e1->error("array slice [%ju .. %ju] is out of bounds", ilwr, iupr);
+ else
+ {
+ Expressions *elements = new Expressions();
+ elements->setDim(iupr - ilwr);
+ memcpy(elements->data,
+ es1->elements->data + ilwr,
+ (iupr - ilwr) * sizeof(es1->elements->data[0]));
+ e = new ArrayLiteralExp(e1->loc, elements);
+ e->type = type;
+ }
}
return e;
}
@@ -1329,233 +1329,233 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
//printf("\tt1 = %s, t2 = %s\n", t1->toChars(), t2->toChars());
if (e1->op == TOKnull && (e2->op == TOKint64 || e2->op == TOKstructliteral))
- { e = e2;
- goto L2;
+ { e = e2;
+ goto L2;
}
else if ((e1->op == TOKint64 || e1->op == TOKstructliteral) && e2->op == TOKnull)
- { e = e1;
+ { e = e1;
L2:
- Type *tn = e->type->toBasetype();
- if (tn->ty == Tchar || tn->ty == Twchar || tn->ty == Tdchar)
- {
- // Create a StringExp
- void *s;
- StringExp *es;
- size_t len = 1;
- int sz = tn->size();
- dinteger_t v = e->toInteger();
+ Type *tn = e->type->toBasetype();
+ if (tn->ty == Tchar || tn->ty == Twchar || tn->ty == Tdchar)
+ {
+ // Create a StringExp
+ void *s;
+ StringExp *es;
+ size_t len = 1;
+ int sz = tn->size();
+ dinteger_t v = e->toInteger();
- s = mem.malloc((len + 1) * sz);
- memcpy((unsigned char *)s, &v, sz);
+ s = mem.malloc((len + 1) * sz);
+ memcpy((unsigned char *)s, &v, sz);
- // Add terminating 0
- memset((unsigned char *)s + len * sz, 0, sz);
+ // Add terminating 0
+ memset((unsigned char *)s + len * sz, 0, sz);
- es = new StringExp(loc, s, len);
- es->sz = sz;
- es->committed = 1;
- e = es;
- }
- else
- { // Create an ArrayLiteralExp
- Expressions *elements = new Expressions();
- elements->push(e);
- e = new ArrayLiteralExp(e->loc, elements);
- }
- e->type = type;
- return e;
+ es = new StringExp(loc, s, len);
+ es->sz = sz;
+ es->committed = 1;
+ e = es;
+ }
+ else
+ { // Create an ArrayLiteralExp
+ Expressions *elements = new Expressions();
+ elements->push(e);
+ e = new ArrayLiteralExp(e->loc, elements);
+ }
+ e->type = type;
+ return e;
}
else if (e1->op == TOKstring && e2->op == TOKstring)
{
- // Concatenate the strings
- void *s;
- StringExp *es1 = (StringExp *)e1;
- StringExp *es2 = (StringExp *)e2;
- StringExp *es;
- Type *t;
- size_t len = es1->len + es2->len;
- int sz = es1->sz;
+ // Concatenate the strings
+ void *s;
+ StringExp *es1 = (StringExp *)e1;
+ StringExp *es2 = (StringExp *)e2;
+ StringExp *es;
+ Type *t;
+ size_t len = es1->len + es2->len;
+ int sz = es1->sz;
- if (sz != es2->sz)
- {
- /* Can happen with:
- * auto s = "foo"d ~ "bar"c;
- */
- assert(global.errors);
- return e;
- }
- s = mem.malloc((len + 1) * sz);
- memcpy(s, es1->string, es1->len * sz);
- memcpy((unsigned char *)s + es1->len * sz, es2->string, es2->len * sz);
+ if (sz != es2->sz)
+ {
+ /* Can happen with:
+ * auto s = "foo"d ~ "bar"c;
+ */
+ assert(global.errors);
+ return e;
+ }
+ s = mem.malloc((len + 1) * sz);
+ memcpy(s, es1->string, es1->len * sz);
+ memcpy((unsigned char *)s + es1->len * sz, es2->string, es2->len * sz);
- // Add terminating 0
- memset((unsigned char *)s + len * sz, 0, sz);
+ // Add terminating 0
+ memset((unsigned char *)s + len * sz, 0, sz);
- es = new StringExp(loc, s, len);
- es->sz = sz;
- es->committed = es1->committed | es2->committed;
- if (es1->committed)
- t = es1->type;
- else
- t = es2->type;
- es->type = type;
- e = es;
+ es = new StringExp(loc, s, len);
+ es->sz = sz;
+ es->committed = es1->committed | es2->committed;
+ if (es1->committed)
+ t = es1->type;
+ else
+ t = es2->type;
+ es->type = type;
+ e = es;
}
else if (e1->op == TOKstring && e2->op == TOKint64)
{
- // Concatenate the strings
- void *s;
- StringExp *es1 = (StringExp *)e1;
- StringExp *es;
- Type *t;
- size_t len = es1->len + 1;
- int sz = es1->sz;
- dinteger_t v = e2->toInteger();
+ // Concatenate the strings
+ void *s;
+ StringExp *es1 = (StringExp *)e1;
+ StringExp *es;
+ Type *t;
+ size_t len = es1->len + 1;
+ int sz = es1->sz;
+ dinteger_t v = e2->toInteger();
- s = mem.malloc((len + 1) * sz);
- memcpy(s, es1->string, es1->len * sz);
- memcpy((unsigned char *)s + es1->len * sz, &v, sz);
+ s = mem.malloc((len + 1) * sz);
+ memcpy(s, es1->string, es1->len * sz);
+ memcpy((unsigned char *)s + es1->len * sz, &v, sz);
- // Add terminating 0
- memset((unsigned char *)s + len * sz, 0, sz);
+ // Add terminating 0
+ memset((unsigned char *)s + len * sz, 0, sz);
- es = new StringExp(loc, s, len);
- es->sz = sz;
- es->committed = es1->committed;
- t = es1->type;
- es->type = type;
- e = es;
+ es = new StringExp(loc, s, len);
+ es->sz = sz;
+ es->committed = es1->committed;
+ t = es1->type;
+ es->type = type;
+ e = es;
}
else if (e1->op == TOKint64 && e2->op == TOKstring)
{
- // Concatenate the strings
- void *s;
- StringExp *es2 = (StringExp *)e2;
- StringExp *es;
- Type *t;
- size_t len = 1 + es2->len;
- int sz = es2->sz;
- dinteger_t v = e1->toInteger();
+ // Concatenate the strings
+ void *s;
+ StringExp *es2 = (StringExp *)e2;
+ StringExp *es;
+ Type *t;
+ size_t len = 1 + es2->len;
+ int sz = es2->sz;
+ dinteger_t v = e1->toInteger();
- s = mem.malloc((len + 1) * sz);
- memcpy((unsigned char *)s, &v, sz);
- memcpy((unsigned char *)s + sz, es2->string, es2->len * sz);
+ s = mem.malloc((len + 1) * sz);
+ memcpy((unsigned char *)s, &v, sz);
+ memcpy((unsigned char *)s + sz, es2->string, es2->len * sz);
- // Add terminating 0
- memset((unsigned char *)s + len * sz, 0, sz);
+ // Add terminating 0
+ memset((unsigned char *)s + len * sz, 0, sz);
- es = new StringExp(loc, s, len);
- es->sz = sz;
- es->committed = es2->committed;
- t = es2->type;
- es->type = type;
- e = es;
+ es = new StringExp(loc, s, len);
+ es->sz = sz;
+ es->committed = es2->committed;
+ t = es2->type;
+ es->type = type;
+ e = es;
}
else if (e1->op == TOKarrayliteral && e2->op == TOKarrayliteral &&
- e1->type->equals(e2->type))
+ e1->type->equals(e2->type))
{
- // Concatenate the arrays
- ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1;
- ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
+ // Concatenate the arrays
+ ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1;
+ ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
- es1 = new ArrayLiteralExp(es1->loc, (Expressions *)es1->elements->copy());
- es1->elements->insert(es1->elements->dim, es2->elements);
- e = es1;
+ es1 = new ArrayLiteralExp(es1->loc, (Expressions *)es1->elements->copy());
+ es1->elements->insert(es1->elements->dim, es2->elements);
+ e = es1;
- if (type->toBasetype()->ty == Tsarray)
- {
- e->type = new TypeSArray(e1->type->toBasetype()->next, new IntegerExp(0, es1->elements->dim, Type::tindex));
- e->type = e->type->semantic(loc, NULL);
- }
- else
- e->type = type;
+ if (type->toBasetype()->ty == Tsarray)
+ {
+ e->type = new TypeSArray(e1->type->toBasetype()->next, new IntegerExp(0, es1->elements->dim, Type::tindex));
+ e->type = e->type->semantic(loc, NULL);
+ }
+ else
+ e->type = type;
}
else if (e1->op == TOKarrayliteral && e2->op == TOKnull &&
- t1->nextOf()->equals(t2->nextOf()))
+ t1->nextOf()->equals(t2->nextOf()))
{
- e = e1;
- goto L3;
+ e = e1;
+ goto L3;
}
else if (e1->op == TOKnull && e2->op == TOKarrayliteral &&
- t1->nextOf()->equals(t2->nextOf()))
+ t1->nextOf()->equals(t2->nextOf()))
{
- e = e2;
+ e = e2;
L3:
- // Concatenate the array with null
- ArrayLiteralExp *es = (ArrayLiteralExp *)e;
+ // Concatenate the array with null
+ ArrayLiteralExp *es = (ArrayLiteralExp *)e;
- es = new ArrayLiteralExp(es->loc, (Expressions *)es->elements->copy());
- e = es;
+ es = new ArrayLiteralExp(es->loc, (Expressions *)es->elements->copy());
+ e = es;
- if (type->toBasetype()->ty == Tsarray)
- {
- e->type = new TypeSArray(t1->nextOf(), new IntegerExp(loc, es->elements->dim, Type::tindex));
- e->type = e->type->semantic(loc, NULL);
- }
- else
- e->type = type;
+ if (type->toBasetype()->ty == Tsarray)
+ {
+ e->type = new TypeSArray(t1->nextOf(), new IntegerExp(loc, es->elements->dim, Type::tindex));
+ e->type = e->type->semantic(loc, NULL);
+ }
+ else
+ e->type = type;
}
else if ((e1->op == TOKarrayliteral || e1->op == TOKnull) &&
- e1->type->toBasetype()->nextOf()->equals(e2->type))
+ e1->type->toBasetype()->nextOf()->equals(e2->type))
{
- ArrayLiteralExp *es1;
- if (e1->op == TOKarrayliteral)
- { es1 = (ArrayLiteralExp *)e1;
- es1 = new ArrayLiteralExp(es1->loc, (Expressions *)es1->elements->copy());
- es1->elements->push(e2);
- }
- else
- {
- es1 = new ArrayLiteralExp(e1->loc, e2);
- }
- e = es1;
+ ArrayLiteralExp *es1;
+ if (e1->op == TOKarrayliteral)
+ { es1 = (ArrayLiteralExp *)e1;
+ es1 = new ArrayLiteralExp(es1->loc, (Expressions *)es1->elements->copy());
+ es1->elements->push(e2);
+ }
+ else
+ {
+ es1 = new ArrayLiteralExp(e1->loc, e2);
+ }
+ e = es1;
- if (type->toBasetype()->ty == Tsarray)
- {
- e->type = new TypeSArray(e2->type, new IntegerExp(loc, es1->elements->dim, Type::tindex));
- e->type = e->type->semantic(loc, NULL);
- }
- else
- e->type = type;
+ if (type->toBasetype()->ty == Tsarray)
+ {
+ e->type = new TypeSArray(e2->type, new IntegerExp(loc, es1->elements->dim, Type::tindex));
+ e->type = e->type->semantic(loc, NULL);
+ }
+ else
+ e->type = type;
}
else if (e2->op == TOKarrayliteral &&
- e2->type->toBasetype()->nextOf()->equals(e1->type))
+ e2->type->toBasetype()->nextOf()->equals(e1->type))
{
- ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
+ ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
- es2 = new ArrayLiteralExp(es2->loc, (Expressions *)es2->elements->copy());
- es2->elements->shift(e1);
- e = es2;
+ es2 = new ArrayLiteralExp(es2->loc, (Expressions *)es2->elements->copy());
+ es2->elements->shift(e1);
+ e = es2;
- if (type->toBasetype()->ty == Tsarray)
- {
- e->type = new TypeSArray(e1->type, new IntegerExp(loc, es2->elements->dim, Type::tindex));
- e->type = e->type->semantic(loc, NULL);
- }
- else
- e->type = type;
+ if (type->toBasetype()->ty == Tsarray)
+ {
+ e->type = new TypeSArray(e1->type, new IntegerExp(loc, es2->elements->dim, Type::tindex));
+ e->type = e->type->semantic(loc, NULL);
+ }
+ else
+ e->type = type;
}
else if (e1->op == TOKnull && e2->op == TOKstring)
{
- t = e1->type;
- e = e2;
- goto L1;
+ t = e1->type;
+ e = e2;
+ goto L1;
}
else if (e1->op == TOKstring && e2->op == TOKnull)
- { e = e1;
- t = e2->type;
+ { e = e1;
+ t = e2->type;
L1:
- Type *tb = t->toBasetype();
- if (tb->ty == Tarray && tb->nextOf()->equals(e->type))
- { Expressions *expressions = new Expressions();
- expressions->push(e);
- e = new ArrayLiteralExp(loc, expressions);
- e->type = t;
- }
- if (!e->type->equals(type))
- { StringExp *se = (StringExp *)e->copy();
- e = se->castTo(NULL, type);
- }
+ Type *tb = t->toBasetype();
+ if (tb->ty == Tarray && tb->nextOf()->equals(e->type))
+ { Expressions *expressions = new Expressions();
+ expressions->push(e);
+ e = new ArrayLiteralExp(loc, expressions);
+ e->type = t;
+ }
+ if (!e->type->equals(type))
+ { StringExp *se = (StringExp *)e->copy();
+ e = se->castTo(NULL, type);
+ }
}
return e;
}
@@ -1564,18 +1564,18 @@ Expression *Ptr(Type *type, Expression *e1)
{
//printf("Ptr(e1 = %s)\n", e1->toChars());
if (e1->op == TOKadd)
- { AddExp *ae = (AddExp *)e1;
- if (ae->e1->op == TOKaddress && ae->e2->op == TOKint64)
- { AddrExp *ade = (AddrExp *)ae->e1;
- if (ade->e1->op == TOKstructliteral)
- { StructLiteralExp *se = (StructLiteralExp *)ade->e1;
- unsigned offset = ae->e2->toInteger();
- Expression *e = se->getField(type, offset);
- if (!e)
- e = EXP_CANT_INTERPRET;
- return e;
- }
- }
+ { AddExp *ae = (AddExp *)e1;
+ if (ae->e1->op == TOKaddress && ae->e2->op == TOKint64)
+ { AddrExp *ade = (AddrExp *)ae->e1;
+ if (ade->e1->op == TOKstructliteral)
+ { StructLiteralExp *se = (StructLiteralExp *)ade->e1;
+ unsigned offset = ae->e2->toInteger();
+ Expression *e = se->getField(type, offset);
+ if (!e)
+ e = EXP_CANT_INTERPRET;
+ return e;
+ }
+ }
}
return EXP_CANT_INTERPRET;
}
diff --git a/dmd/declaration.c b/dmd/declaration.c
index e0d51ef4..46874823 100644
--- a/dmd/declaration.c
+++ b/dmd/declaration.c
@@ -95,61 +95,61 @@ enum PROT Declaration::prot()
void Declaration::checkModify(Loc loc, Scope *sc, Type *t)
{
if (sc->incontract && isParameter())
- error(loc, "cannot modify parameter '%s' in contract", toChars());
+ error(loc, "cannot modify parameter '%s' in contract", toChars());
if (isCtorinit())
- { // It's only modifiable if inside the right constructor
- Dsymbol *s = sc->func;
- while (1)
- {
- FuncDeclaration *fd = NULL;
- if (s)
- fd = s->isFuncDeclaration();
- if (fd &&
- ((fd->isCtorDeclaration() && storage_class & STCfield) ||
- (fd->isStaticCtorDeclaration() && !(storage_class & STCfield))) &&
- fd->toParent() == toParent()
- )
- {
- VarDeclaration *v = isVarDeclaration();
- assert(v);
- v->ctorinit = 1;
- //printf("setting ctorinit\n");
- }
- else
- {
- if (s)
- { s = s->toParent2();
- continue;
- }
- else
- {
- const char *p = isStatic() ? "static " : "";
- error(loc, "can only initialize %sconst %s inside %sconstructor",
- p, toChars(), p);
- }
- }
- break;
- }
+ { // It's only modifiable if inside the right constructor
+ Dsymbol *s = sc->func;
+ while (1)
+ {
+ FuncDeclaration *fd = NULL;
+ if (s)
+ fd = s->isFuncDeclaration();
+ if (fd &&
+ ((fd->isCtorDeclaration() && storage_class & STCfield) ||
+ (fd->isStaticCtorDeclaration() && !(storage_class & STCfield))) &&
+ fd->toParent() == toParent()
+ )
+ {
+ VarDeclaration *v = isVarDeclaration();
+ assert(v);
+ v->ctorinit = 1;
+ //printf("setting ctorinit\n");
+ }
+ else
+ {
+ if (s)
+ { s = s->toParent2();
+ continue;
+ }
+ else
+ {
+ const char *p = isStatic() ? "static " : "";
+ error(loc, "can only initialize %sconst %s inside %sconstructor",
+ p, toChars(), p);
+ }
+ }
+ break;
+ }
}
else
{
- VarDeclaration *v = isVarDeclaration();
- if (v && v->canassign == 0)
- {
- const char *p = NULL;
- if (isConst())
- p = "const";
- else if (isImmutable())
- p = "immutable";
- else if (storage_class & STCmanifest)
- p = "enum";
- else if (!t->isAssignable())
- p = "struct with immutable members";
- if (p)
- { error(loc, "cannot modify %s", p);
- }
- }
+ VarDeclaration *v = isVarDeclaration();
+ if (v && v->canassign == 0)
+ {
+ const char *p = NULL;
+ if (isConst())
+ p = "const";
+ else if (isImmutable())
+ p = "immutable";
+ else if (storage_class & STCmanifest)
+ p = "enum";
+ else if (!t->isAssignable())
+ p = "struct with immutable members";
+ if (p)
+ { error(loc, "cannot modify %s", p);
+ }
+ }
}
}
#endif
@@ -184,47 +184,47 @@ Type *TupleDeclaration::getType()
//printf("TupleDeclaration::getType() %s\n", toChars());
if (isexp)
- return NULL;
+ return NULL;
if (!tupletype)
{
- /* It's only a type tuple if all the Object's are types
- */
- for (size_t i = 0; i < objects->dim; i++)
- { Object *o = (Object *)objects->data[i];
+ /* It's only a type tuple if all the Object's are types
+ */
+ for (size_t i = 0; i < objects->dim; i++)
+ { Object *o = (Object *)objects->data[i];
- if (o->dyncast() != DYNCAST_TYPE)
- {
- //printf("\tnot[%d], %p, %d\n", i, o, o->dyncast());
- return NULL;
- }
- }
+ if (o->dyncast() != DYNCAST_TYPE)
+ {
+ //printf("\tnot[%d], %p, %d\n", i, o, o->dyncast());
+ return NULL;
+ }
+ }
- /* We know it's a type tuple, so build the TypeTuple
- */
- Parameters *args = new Parameters();
- args->setDim(objects->dim);
- OutBuffer buf;
- int hasdeco = 1;
- for (size_t i = 0; i < objects->dim; i++)
- { Type *t = (Type *)objects->data[i];
+ /* We know it's a type tuple, so build the TypeTuple
+ */
+ Parameters *args = new Parameters();
+ args->setDim(objects->dim);
+ OutBuffer buf;
+ int hasdeco = 1;
+ for (size_t i = 0; i < objects->dim; i++)
+ { Type *t = (Type *)objects->data[i];
- //printf("type = %s\n", t->toChars());
+ //printf("type = %s\n", t->toChars());
#if 0
- buf.printf("_%s_%d", ident->toChars(), i);
- char *name = (char *)buf.extractData();
- Identifier *id = new Identifier(name, TOKidentifier);
- Parameter *arg = new Parameter(STCin, t, id, NULL);
+ buf.printf("_%s_%d", ident->toChars(), i);
+ char *name = (char *)buf.extractData();
+ Identifier *id = new Identifier(name, TOKidentifier);
+ Parameter *arg = new Parameter(STCin, t, id, NULL);
#else
- Parameter *arg = new Parameter(STCin, t, NULL, NULL);
+ Parameter *arg = new Parameter(STCin, t, NULL, NULL);
#endif
- args->data[i] = (void *)arg;
- if (!t->deco)
- hasdeco = 0;
- }
+ args->data[i] = (void *)arg;
+ if (!t->deco)
+ hasdeco = 0;
+ }
- tupletype = new TypeTuple(args);
- if (hasdeco)
- return tupletype->semantic(0, NULL);
+ tupletype = new TypeTuple(args);
+ if (hasdeco)
+ return tupletype->semantic(0, NULL);
}
return tupletype;
@@ -235,17 +235,17 @@ int TupleDeclaration::needThis()
//printf("TupleDeclaration::needThis(%s)\n", toChars());
for (size_t i = 0; i < objects->dim; i++)
{ Object *o = (Object *)objects->data[i];
- if (o->dyncast() == DYNCAST_EXPRESSION)
- { Expression *e = (Expression *)o;
- if (e->op == TOKdsymbol)
- { DsymbolExp *ve = (DsymbolExp *)e;
- Declaration *d = ve->s->isDeclaration();
- if (d && d->needThis())
- {
- return 1;
- }
- }
- }
+ if (o->dyncast() == DYNCAST_EXPRESSION)
+ { Expression *e = (Expression *)o;
+ if (e->op == TOKdsymbol)
+ { DsymbolExp *ve = (DsymbolExp *)e;
+ Declaration *d = ve->s->isDeclaration();
+ if (d && d->needThis())
+ {
+ return 1;
+ }
+ }
+ }
}
return 0;
}
@@ -275,7 +275,7 @@ Dsymbol *TypedefDeclaration::syntaxCopy(Dsymbol *s)
Initializer *init = NULL;
if (this->init)
- init = this->init->syntaxCopy();
+ init = this->init->syntaxCopy();
assert(!s);
TypedefDeclaration *st;
@@ -283,18 +283,18 @@ Dsymbol *TypedefDeclaration::syntaxCopy(Dsymbol *s)
#ifdef _DH
// Syntax copy for header file
if (!htype) // Don't overwrite original
- { if (type) // Make copy for both old and new instances
- { htype = type->syntaxCopy();
- st->htype = type->syntaxCopy();
- }
+ { if (type) // Make copy for both old and new instances
+ { htype = type->syntaxCopy();
+ st->htype = type->syntaxCopy();
+ }
}
else // Make copy of original for new instance
st->htype = htype->syntaxCopy();
if (!hbasetype)
- { if (basetype)
- { hbasetype = basetype->syntaxCopy();
- st->hbasetype = basetype->syntaxCopy();
- }
+ { if (basetype)
+ { hbasetype = basetype->syntaxCopy();
+ st->hbasetype = basetype->syntaxCopy();
+ }
}
else
st->hbasetype = hbasetype->syntaxCopy();
@@ -306,20 +306,20 @@ void TypedefDeclaration::semantic(Scope *sc)
{
//printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem);
if (sem == 0)
- { sem = 1;
- basetype = basetype->semantic(loc, sc);
- sem = 2;
+ { sem = 1;
+ basetype = basetype->semantic(loc, sc);
+ sem = 2;
#if DMDV2
- type = type->addStorageClass(storage_class);
+ type = type->addStorageClass(storage_class);
#endif
- type = type->semantic(loc, sc);
- if (sc->parent->isFuncDeclaration() && init)
- semantic2(sc);
- storage_class |= sc->stc & STCdeprecated;
+ type = type->semantic(loc, sc);
+ if (sc->parent->isFuncDeclaration() && init)
+ semantic2(sc);
+ storage_class |= sc->stc & STCdeprecated;
}
else if (sem == 1)
{
- error("circular definition");
+ error("circular definition");
}
}
@@ -327,18 +327,18 @@ void TypedefDeclaration::semantic2(Scope *sc)
{
//printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem);
if (sem == 2)
- { sem = 3;
- if (init)
- {
- init = init->semantic(sc, basetype);
+ { sem = 3;
+ if (init)
+ {
+ init = init->semantic(sc, basetype);
- ExpInitializer *ie = init->isExpInitializer();
- if (ie)
- {
- if (ie->exp->type == basetype)
- ie->exp->type = type;
- }
- }
+ ExpInitializer *ie = init->isExpInitializer();
+ if (ie)
+ {
+ if (ie->exp->type == basetype)
+ ie->exp->type = type;
+ }
+ }
}
}
@@ -358,8 +358,8 @@ void TypedefDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
basetype->toCBuffer(buf, ident, hgs);
if (init)
{
- buf->writestring(" = ");
- init->toCBuffer(buf, hgs);
+ buf->writestring(" = ");
+ init->toCBuffer(buf, hgs);
}
buf->writeByte(';');
buf->writenl();
@@ -408,27 +408,27 @@ Dsymbol *AliasDeclaration::syntaxCopy(Dsymbol *s)
assert(!s);
AliasDeclaration *sa;
if (type)
- sa = new AliasDeclaration(loc, ident, type->syntaxCopy());
+ sa = new AliasDeclaration(loc, ident, type->syntaxCopy());
else
- sa = new AliasDeclaration(loc, ident, aliassym->syntaxCopy(NULL));
+ sa = new AliasDeclaration(loc, ident, aliassym->syntaxCopy(NULL));
#ifdef _DH
// Syntax copy for header file
- if (!htype) // Don't overwrite original
- { if (type) // Make copy for both old and new instances
- { htype = type->syntaxCopy();
- sa->htype = type->syntaxCopy();
- }
+ if (!htype) // Don't overwrite original
+ { if (type) // Make copy for both old and new instances
+ { htype = type->syntaxCopy();
+ sa->htype = type->syntaxCopy();
+ }
}
- else // Make copy of original for new instance
- sa->htype = htype->syntaxCopy();
+ else // Make copy of original for new instance
+ sa->htype = htype->syntaxCopy();
if (!haliassym)
- { if (aliassym)
- { haliassym = aliassym->syntaxCopy(s);
- sa->haliassym = aliassym->syntaxCopy(s);
- }
+ { if (aliassym)
+ { haliassym = aliassym->syntaxCopy(s);
+ sa->haliassym = aliassym->syntaxCopy(s);
+ }
}
else
- sa->haliassym = haliassym->syntaxCopy(s);
+ sa->haliassym = haliassym->syntaxCopy(s);
#endif
return sa;
}
@@ -438,21 +438,21 @@ void AliasDeclaration::semantic(Scope *sc)
//printf("AliasDeclaration::semantic() %s\n", toChars());
if (aliassym)
{
- if (aliassym->isTemplateInstance())
- aliassym->semantic(sc);
- return;
+ if (aliassym->isTemplateInstance())
+ aliassym->semantic(sc);
+ return;
}
this->inSemantic = 1;
#if DMDV1 // don't really know why this is here
if (storage_class & STCconst)
- error("cannot be const");
+ error("cannot be const");
#endif
storage_class |= sc->stc & STCdeprecated;
// Given:
- // alias foo.bar.abc def;
+ // alias foo.bar.abc def;
// it is not knowable from the syntax whether this is an alias
// for a type or an alias for a symbol. It is up to the semantic()
// pass to distinguish.
@@ -472,50 +472,50 @@ void AliasDeclaration::semantic(Scope *sc)
s = type->toDsymbol(sc);
if (s
#if DMDV2
-` && ((s->getType() && type->equals(s->getType())) || s->isEnumMember())
+` && ((s->getType() && type->equals(s->getType())) || s->isEnumMember())
#endif
- )
- goto L2; // it's a symbolic alias
+ )
+ goto L2; // it's a symbolic alias
#if DMDV2
type = type->addStorageClass(storage_class);
if (storage_class & (STCref | STCnothrow | STCpure))
- { // For 'ref' to be attached to function types, and picked
- // up by Type::resolve(), it has to go into sc.
- sc = sc->push();
- sc->stc |= storage_class & (STCref | STCnothrow | STCpure | STCshared);
- type->resolve(loc, sc, &e, &t, &s);
- sc = sc->pop();
+ { // For 'ref' to be attached to function types, and picked
+ // up by Type::resolve(), it has to go into sc.
+ sc = sc->push();
+ sc->stc |= storage_class & (STCref | STCnothrow | STCpure | STCshared);
+ type->resolve(loc, sc, &e, &t, &s);
+ sc = sc->pop();
}
else
#endif
- type->resolve(loc, sc, &e, &t, &s);
+ type->resolve(loc, sc, &e, &t, &s);
if (s)
{
- goto L2;
+ goto L2;
}
else if (e)
{
- // Try to convert Expression to Dsymbol
+ // Try to convert Expression to Dsymbol
if (e->op == TOKvar)
- { s = ((VarExp *)e)->var;
- goto L2;
- }
+ { s = ((VarExp *)e)->var;
+ goto L2;
+ }
else if (e->op == TOKfunction)
- { s = ((FuncExp *)e)->fd;
- goto L2;
- }
+ { s = ((FuncExp *)e)->fd;
+ goto L2;
+ }
else
- { error("cannot alias an expression %s", e->toChars());
- t = e->type;
- }
+ { error("cannot alias an expression %s", e->toChars());
+ t = e->type;
+ }
}
else if (t)
{
- type = t;
+ type = t;
}
if (overnext)
- ScopeDsymbol::multiplyDefined(0, this, overnext);
+ ScopeDsymbol::multiplyDefined(0, this, overnext);
this->inSemantic = 0;
return;
@@ -525,35 +525,35 @@ void AliasDeclaration::semantic(Scope *sc)
VarDeclaration *v = s->isVarDeclaration();
if (v && v->linkage == LINKdefault)
{
- error("forward reference of %s", v->toChars());
- s = NULL;
+ error("forward reference of %s", v->toChars());
+ s = NULL;
}
else
{
- FuncDeclaration *f = s->toAlias()->isFuncDeclaration();
- if (f)
- {
- if (overnext)
- {
- FuncAliasDeclaration *fa = new FuncAliasDeclaration(f);
- fa->importprot = importprot;
- if (!fa->overloadInsert(overnext))
- ScopeDsymbol::multiplyDefined(0, f, overnext);
- overnext = NULL;
- s = fa;
- s->parent = sc->parent;
- }
- }
- if (overnext)
- ScopeDsymbol::multiplyDefined(0, s, overnext);
- if (s == this)
- {
- assert(global.errors);
- s = NULL;
- }
+ FuncDeclaration *f = s->toAlias()->isFuncDeclaration();
+ if (f)
+ {
+ if (overnext)
+ {
+ FuncAliasDeclaration *fa = new FuncAliasDeclaration(f);
+ fa->importprot = importprot;
+ if (!fa->overloadInsert(overnext))
+ ScopeDsymbol::multiplyDefined(0, f, overnext);
+ overnext = NULL;
+ s = fa;
+ s->parent = sc->parent;
+ }
+ }
+ if (overnext)
+ ScopeDsymbol::multiplyDefined(0, s, overnext);
+ if (s == this)
+ {
+ assert(global.errors);
+ s = NULL;
+ }
}
if (!aliassym)
- aliassym = s;
+ aliassym = s;
this->inSemantic = 0;
}
@@ -575,19 +575,19 @@ int AliasDeclaration::overloadInsert(Dsymbol *s)
return fa->overloadInsert(s);
}
}
-
+
if (overnext == NULL)
{
- if (s == this)
- {
- return TRUE;
- }
- overnext = s;
- return TRUE;
+ if (s == this)
+ {
+ return TRUE;
+ }
+ overnext = s;
+ return TRUE;
}
else
{
- return overnext->overloadInsert(s);
+ return overnext->overloadInsert(s);
}
}
@@ -601,9 +601,9 @@ Type *AliasDeclaration::getType()
//printf("AliasDeclaration::getType() %s\n", type->toChars());
#if 0
if (!type->deco && scope)
- semantic(scope);
+ semantic(scope);
if (type && !type->deco)
- error("forward reference to alias %s\n", toChars());
+ error("forward reference to alias %s\n", toChars());
#endif
return type;
}
@@ -614,8 +614,8 @@ Dsymbol *AliasDeclaration::toAlias()
assert(this != aliassym);
//static int count; if (++count == 75) exit(0); //*(char*)0=0;
if (inSemantic)
- { error("recursive alias declaration");
- aliassym = new TypedefDeclaration(loc, ident, Type::terror, NULL);
+ { error("recursive alias declaration");
+ aliassym = new TypedefDeclaration(loc, ident, Type::terror, NULL);
}
Dsymbol *s = aliassym ? aliassym->toAlias() : this;
return s;
@@ -627,26 +627,26 @@ void AliasDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
#if 0 && _DH
if (hgs->hdrgen)
{
- if (haliassym)
- {
- buf->writestring(haliassym->toChars());
- buf->writeByte(' ');
- buf->writestring(ident->toChars());
- }
- else
- htype->toCBuffer(buf, ident, hgs);
+ if (haliassym)
+ {
+ buf->writestring(haliassym->toChars());
+ buf->writeByte(' ');
+ buf->writestring(ident->toChars());
+ }
+ else
+ htype->toCBuffer(buf, ident, hgs);
}
else
#endif
{
- if (aliassym)
- {
- buf->writestring(aliassym->toChars());
- buf->writeByte(' ');
- buf->writestring(ident->toChars());
- }
- else
- type->toCBuffer(buf, ident, hgs);
+ if (aliassym)
+ {
+ buf->writestring(aliassym->toChars());
+ buf->writeByte(' ');
+ buf->writestring(ident->toChars());
+ }
+ else
+ type->toCBuffer(buf, ident, hgs);
}
buf->writeByte(';');
buf->writenl();
@@ -660,8 +660,8 @@ VarDeclaration::VarDeclaration(Loc loc, Type *type, Identifier *id, Initializer
//printf("VarDeclaration('%s')\n", id->toChars());
#ifdef DEBUG
if (!type && !init)
- { printf("VarDeclaration('%s')\n", id->toChars());
- //*(char*)0=0;
+ { printf("VarDeclaration('%s')\n", id->toChars());
+ //*(char*)0=0;
}
#endif
assert(type || init);
@@ -702,35 +702,35 @@ Dsymbol *VarDeclaration::syntaxCopy(Dsymbol *s)
VarDeclaration *sv;
if (s)
- { sv = (VarDeclaration *)s;
+ { sv = (VarDeclaration *)s;
}
else
{
- Initializer *init = NULL;
- if (this->init)
- { init = this->init->syntaxCopy();
- //init->isExpInitializer()->exp->print();
- //init->isExpInitializer()->exp->dump(0);
- }
+ Initializer *init = NULL;
+ if (this->init)
+ { init = this->init->syntaxCopy();
+ //init->isExpInitializer()->exp->print();
+ //init->isExpInitializer()->exp->dump(0);
+ }
- sv = new VarDeclaration(loc, type ? type->syntaxCopy() : NULL, ident, init);
- sv->storage_class = storage_class;
+ sv = new VarDeclaration(loc, type ? type->syntaxCopy() : NULL, ident, init);
+ sv->storage_class = storage_class;
}
#ifdef _DH
// Syntax copy for header file
if (!htype) // Don't overwrite original
- { if (type) // Make copy for both old and new instances
- { htype = type->syntaxCopy();
- sv->htype = type->syntaxCopy();
- }
+ { if (type) // Make copy for both old and new instances
+ { htype = type->syntaxCopy();
+ sv->htype = type->syntaxCopy();
+ }
}
else // Make copy of original for new instance
sv->htype = htype->syntaxCopy();
if (!hinit)
- { if (init)
- { hinit = init->syntaxCopy();
- sv->hinit = init->syntaxCopy();
- }
+ { if (init)
+ { hinit = init->syntaxCopy();
+ sv->hinit = init->syntaxCopy();
+ }
}
else
sv->hinit = hinit->syntaxCopy();
@@ -751,27 +751,27 @@ void VarDeclaration::semantic(Scope *sc)
storage_class |= sc->stc;
if (storage_class & STCextern && init)
- error("extern symbols cannot have initializers");
+ error("extern symbols cannot have initializers");
/* If auto type inference, do the inference
*/
int inferred = 0;
if (!type)
- { inuse++;
- type = init->inferType(sc);
- inuse--;
- inferred = 1;
+ { inuse++;
+ type = init->inferType(sc);
+ inuse--;
+ inferred = 1;
- /* This is a kludge to support the existing syntax for RAII
- * declarations.
- */
- storage_class &= ~STCauto;
- originalType = type;
+ /* This is a kludge to support the existing syntax for RAII
+ * declarations.
+ */
+ storage_class &= ~STCauto;
+ originalType = type;
}
else
- { if (!originalType)
- originalType = type;
- type = type->semantic(loc, sc);
+ { if (!originalType)
+ originalType = type;
+ type = type->semantic(loc, sc);
}
//printf(" semantic type = %s\n", type ? type->toChars() : "null");
@@ -786,7 +786,7 @@ void VarDeclaration::semantic(Scope *sc)
#if DMDV2
if (storage_class & STCgshared && global.params.safe && !sc->module->safe)
{
- error("__gshared not allowed in safe mode; use shared");
+ error("__gshared not allowed in safe mode; use shared");
}
#endif
@@ -795,80 +795,80 @@ void VarDeclaration::semantic(Scope *sc)
Type *tb = type->toBasetype();
if (tb->ty == Tvoid && !(storage_class & STClazy))
- { error("voids have no value");
- type = Type::terror;
- tb = type;
+ { error("voids have no value");
+ type = Type::terror;
+ tb = type;
}
if (tb->ty == Tfunction)
- { error("cannot be declared to be a function");
- type = Type::terror;
- tb = type;
+ { error("cannot be declared to be a function");
+ type = Type::terror;
+ tb = type;
}
if (tb->ty == Tstruct)
- { TypeStruct *ts = (TypeStruct *)tb;
+ { TypeStruct *ts = (TypeStruct *)tb;
- if (!ts->sym->members)
- {
- error("no definition of struct %s", ts->toChars());
- }
+ if (!ts->sym->members)
+ {
+ error("no definition of struct %s", ts->toChars());
+ }
}
if ((storage_class & STCauto) && !inferred)
- error("both auto and explicit type given");
+ error("both auto and explicit type given");
if (tb->ty == Ttuple)
{ /* Instead, declare variables for each of the tuple elements
- * and add those.
- */
- TypeTuple *tt = (TypeTuple *)tb;
- size_t nelems = Parameter::dim(tt->arguments);
- Objects *exps = new Objects();
- exps->setDim(nelems);
- Expression *ie = init ? init->toExpression() : NULL;
+ * and add those.
+ */
+ TypeTuple *tt = (TypeTuple *)tb;
+ size_t nelems = Parameter::dim(tt->arguments);
+ Objects *exps = new Objects();
+ exps->setDim(nelems);
+ Expression *ie = init ? init->toExpression() : NULL;
- for (size_t i = 0; i < nelems; i++)
- { Parameter *arg = Parameter::getNth(tt->arguments, i);
+ for (size_t i = 0; i < nelems; i++)
+ { Parameter *arg = Parameter::getNth(tt->arguments, i);
- OutBuffer buf;
- buf.printf("_%s_field_%zu", ident->toChars(), i);
- buf.writeByte(0);
- char *name = (char *)buf.extractData();
- Identifier *id = new Identifier(name, TOKidentifier);
+ OutBuffer buf;
+ buf.printf("_%s_field_%zu", ident->toChars(), i);
+ buf.writeByte(0);
+ char *name = (char *)buf.extractData();
+ Identifier *id = new Identifier(name, TOKidentifier);
- Expression *einit = ie;
- if (ie && ie->op == TOKtuple)
- { einit = (Expression *)((TupleExp *)ie)->exps->data[i];
- }
- Initializer *ti = init;
- if (einit)
- { ti = new ExpInitializer(einit->loc, einit);
- }
+ Expression *einit = ie;
+ if (ie && ie->op == TOKtuple)
+ { einit = (Expression *)((TupleExp *)ie)->exps->data[i];
+ }
+ Initializer *ti = init;
+ if (einit)
+ { ti = new ExpInitializer(einit->loc, einit);
+ }
+
+ VarDeclaration *v = new VarDeclaration(loc, arg->type, id, ti);
+ //printf("declaring field %s of type %s\n", v->toChars(), v->type->toChars());
+ v->semantic(sc);
- VarDeclaration *v = new VarDeclaration(loc, arg->type, id, ti);
- //printf("declaring field %s of type %s\n", v->toChars(), v->type->toChars());
- v->semantic(sc);
-
#if !IN_LLVM
// removed for LDC since TupleDeclaration::toObj already creates the fields;
// adding them to the scope again leads to duplicates
- if (sc->scopesym)
- { //printf("adding %s to %s\n", v->toChars(), sc->scopesym->toChars());
- if (sc->scopesym->members)
- sc->scopesym->members->push(v);
- }
+ if (sc->scopesym)
+ { //printf("adding %s to %s\n", v->toChars(), sc->scopesym->toChars());
+ if (sc->scopesym->members)
+ sc->scopesym->members->push(v);
+ }
#endif
- Expression *e = new DsymbolExp(loc, v);
- exps->data[i] = e;
- }
- TupleDeclaration *v2 = new TupleDeclaration(loc, ident, exps);
- v2->isexp = 1;
- aliassym = v2;
- return;
+ Expression *e = new DsymbolExp(loc, v);
+ exps->data[i] = e;
+ }
+ TupleDeclaration *v2 = new TupleDeclaration(loc, ident, exps);
+ v2->isexp = 1;
+ aliassym = v2;
+ return;
}
if (storage_class & STCconst && !init && !fd)
- // Initialize by constructor only
- storage_class = (storage_class & ~STCconst) | STCctorinit;
+ // Initialize by constructor only
+ storage_class = (storage_class & ~STCconst) | STCctorinit;
if (isConst())
{
@@ -878,343 +878,343 @@ void VarDeclaration::semantic(Scope *sc)
}
else if (isSynchronized())
{
- error("variable %s cannot be synchronized", toChars());
+ error("variable %s cannot be synchronized", toChars());
}
else if (isOverride())
{
- error("override cannot be applied to variable");
+ error("override cannot be applied to variable");
}
else if (isAbstract())
{
- error("abstract cannot be applied to variable");
+ error("abstract cannot be applied to variable");
}
else if (storage_class & STCtemplateparameter)
{
}
else
{
- AggregateDeclaration *aad = sc->anonAgg;
- if (!aad)
- aad = parent->isAggregateDeclaration();
- if (aad)
- {
+ AggregateDeclaration *aad = sc->anonAgg;
+ if (!aad)
+ aad = parent->isAggregateDeclaration();
+ if (aad)
+ {
#if DMDV2
- assert(!(storage_class & (STCextern | STCstatic | STCtls | STCgshared)));
+ assert(!(storage_class & (STCextern | STCstatic | STCtls | STCgshared)));
- if (storage_class & (STCconst | STCimmutable) && init)
- {
- if (!type->toBasetype()->isTypeBasic())
- storage_class |= STCstatic;
- }
- else
+ if (storage_class & (STCconst | STCimmutable) && init)
+ {
+ if (!type->toBasetype()->isTypeBasic())
+ storage_class |= STCstatic;
+ }
+ else
#endif
- aad->addField(sc, this);
- }
+ aad->addField(sc, this);
+ }
- InterfaceDeclaration *id = parent->isInterfaceDeclaration();
- if (id)
- {
- error("field not allowed in interface");
- }
+ InterfaceDeclaration *id = parent->isInterfaceDeclaration();
+ if (id)
+ {
+ error("field not allowed in interface");
+ }
- /* Templates cannot add fields to aggregates
- */
- TemplateInstance *ti = parent->isTemplateInstance();
- if (ti)
- {
- // Take care of nested templates
- while (1)
- {
- TemplateInstance *ti2 = ti->tempdecl->parent->isTemplateInstance();
- if (!ti2)
- break;
- ti = ti2;
- }
+ /* Templates cannot add fields to aggregates
+ */
+ TemplateInstance *ti = parent->isTemplateInstance();
+ if (ti)
+ {
+ // Take care of nested templates
+ while (1)
+ {
+ TemplateInstance *ti2 = ti->tempdecl->parent->isTemplateInstance();
+ if (!ti2)
+ break;
+ ti = ti2;
+ }
- // If it's a member template
- AggregateDeclaration *ad = ti->tempdecl->isMember();
- if (ad && storage_class != STCundefined)
- {
- error("cannot use template to add field to aggregate '%s'", ad->toChars());
- }
- }
+ // If it's a member template
+ AggregateDeclaration *ad = ti->tempdecl->isMember();
+ if (ad && storage_class != STCundefined)
+ {
+ error("cannot use template to add field to aggregate '%s'", ad->toChars());
+ }
+ }
}
#if DMDV2
if ((storage_class & (STCref | STCparameter | STCforeach)) == STCref &&
- ident != Id::This)
+ ident != Id::This)
{
- error("only parameters or foreach declarations can be ref");
+ error("only parameters or foreach declarations can be ref");
}
#endif
if (type->isscope() && !noscope)
{
- if (storage_class & (STCfield | STCout | STCref | STCstatic) || !fd)
- {
- error("globals, statics, fields, ref and out parameters cannot be scope");
- }
+ if (storage_class & (STCfield | STCout | STCref | STCstatic) || !fd)
+ {
+ error("globals, statics, fields, ref and out parameters cannot be scope");
+ }
- if (!(storage_class & STCscope))
- {
- if (!(storage_class & STCparameter) && ident != Id::withSym)
- error("reference to scope class must be scope");
- }
+ if (!(storage_class & STCscope))
+ {
+ if (!(storage_class & STCparameter) && ident != Id::withSym)
+ error("reference to scope class must be scope");
+ }
}
enum TOK op = TOKconstruct;
if (!init && !sc->inunion && !isStatic() && !isConst() && fd &&
- !(storage_class & (STCfield | STCin | STCforeach)) &&
- type->size() != 0)
+ !(storage_class & (STCfield | STCin | STCforeach)) &&
+ type->size() != 0)
{
- // Provide a default initializer
- //printf("Providing default initializer for '%s'\n", toChars());
- if (type->ty == Tstruct &&
- ((TypeStruct *)type)->sym->zeroInit == 1)
- { /* If a struct is all zeros, as a special case
- * set it's initializer to the integer 0.
- * In AssignExp::toElem(), we check for this and issue
- * a memset() to initialize the struct.
- * Must do same check in interpreter.
- */
- Expression *e = new IntegerExp(loc, 0, Type::tint32);
- Expression *e1;
- e1 = new VarExp(loc, this);
- e = new AssignExp(loc, e1, e);
- e->op = TOKconstruct;
- e->type = e1->type; // don't type check this, it would fail
- init = new ExpInitializer(loc, e);
- return;
- }
- else if (type->ty == Ttypedef)
- { TypeTypedef *td = (TypeTypedef *)type;
- if (td->sym->init)
- { init = td->sym->init;
- ExpInitializer *ie = init->isExpInitializer();
- if (ie)
- // Make copy so we can modify it
- init = new ExpInitializer(ie->loc, ie->exp);
- }
- else
- init = getExpInitializer();
- }
- else
- {
- init = getExpInitializer();
- }
- // Default initializer is always a blit
- op = TOKblit;
+ // Provide a default initializer
+ //printf("Providing default initializer for '%s'\n", toChars());
+ if (type->ty == Tstruct &&
+ ((TypeStruct *)type)->sym->zeroInit == 1)
+ { /* If a struct is all zeros, as a special case
+ * set it's initializer to the integer 0.
+ * In AssignExp::toElem(), we check for this and issue
+ * a memset() to initialize the struct.
+ * Must do same check in interpreter.
+ */
+ Expression *e = new IntegerExp(loc, 0, Type::tint32);
+ Expression *e1;
+ e1 = new VarExp(loc, this);
+ e = new AssignExp(loc, e1, e);
+ e->op = TOKconstruct;
+ e->type = e1->type; // don't type check this, it would fail
+ init = new ExpInitializer(loc, e);
+ return;
+ }
+ else if (type->ty == Ttypedef)
+ { TypeTypedef *td = (TypeTypedef *)type;
+ if (td->sym->init)
+ { init = td->sym->init;
+ ExpInitializer *ie = init->isExpInitializer();
+ if (ie)
+ // Make copy so we can modify it
+ init = new ExpInitializer(ie->loc, ie->exp);
+ }
+ else
+ init = getExpInitializer();
+ }
+ else
+ {
+ init = getExpInitializer();
+ }
+ // Default initializer is always a blit
+ op = TOKblit;
}
if (init)
{
- sc = sc->push();
- sc->stc &= ~(STC_TYPECTOR | STCpure | STCnothrow | STCref);
+ sc = sc->push();
+ sc->stc &= ~(STC_TYPECTOR | STCpure | STCnothrow | STCref);
- ArrayInitializer *ai = init->isArrayInitializer();
- if (ai && tb->ty == Taarray)
- {
- init = ai->toAssocArrayInitializer();
- }
+ ArrayInitializer *ai = init->isArrayInitializer();
+ if (ai && tb->ty == Taarray)
+ {
+ init = ai->toAssocArrayInitializer();
+ }
- StructInitializer *si = init->isStructInitializer();
- ExpInitializer *ei = init->isExpInitializer();
+ StructInitializer *si = init->isStructInitializer();
+ ExpInitializer *ei = init->isExpInitializer();
- // See if initializer is a NewExp that can be allocated on the stack
- if (ei && isScope() && ei->exp->op == TOKnew)
- { NewExp *ne = (NewExp *)ei->exp;
- if (!(ne->newargs && ne->newargs->dim))
- { ne->onstack = 1;
- onstack = 1;
- if (type->isBaseOf(ne->newtype->semantic(loc, sc), NULL))
- onstack = 2;
- }
- }
+ // See if initializer is a NewExp that can be allocated on the stack
+ if (ei && isScope() && ei->exp->op == TOKnew)
+ { NewExp *ne = (NewExp *)ei->exp;
+ if (!(ne->newargs && ne->newargs->dim))
+ { ne->onstack = 1;
+ onstack = 1;
+ if (type->isBaseOf(ne->newtype->semantic(loc, sc), NULL))
+ onstack = 2;
+ }
+ }
- // If inside function, there is no semantic3() call
- if (sc->func)
- {
- // If local variable, use AssignExp to handle all the various
- // possibilities.
- if (fd && !isStatic() && !isConst() && !init->isVoidInitializer())
- {
- //printf("fd = '%s', var = '%s'\n", fd->toChars(), toChars());
- if (!ei)
- {
- Expression *e = init->toExpression();
- if (!e)
- {
- init = init->semantic(sc, type);
- e = init->toExpression();
- if (!e)
- { error("is not a static and cannot have static initializer");
- return;
- }
- }
- ei = new ExpInitializer(init->loc, e);
- init = ei;
- }
+ // If inside function, there is no semantic3() call
+ if (sc->func)
+ {
+ // If local variable, use AssignExp to handle all the various
+ // possibilities.
+ if (fd && !isStatic() && !isConst() && !init->isVoidInitializer())
+ {
+ //printf("fd = '%s', var = '%s'\n", fd->toChars(), toChars());
+ if (!ei)
+ {
+ Expression *e = init->toExpression();
+ if (!e)
+ {
+ init = init->semantic(sc, type);
+ e = init->toExpression();
+ if (!e)
+ { error("is not a static and cannot have static initializer");
+ return;
+ }
+ }
+ ei = new ExpInitializer(init->loc, e);
+ init = ei;
+ }
- Expression *e1 = new VarExp(loc, this);
+ Expression *e1 = new VarExp(loc, this);
- Type *t = type->toBasetype();
- if (t->ty == Tsarray && !(storage_class & (STCref | STCout)))
- {
- ei->exp = ei->exp->semantic(sc);
- if (!ei->exp->implicitConvTo(type))
- {
- int dim = ((TypeSArray *)t)->dim->toInteger();
- // If multidimensional static array, treat as one large array
- while (1)
- {
- t = t->nextOf()->toBasetype();
- if (t->ty != Tsarray)
- break;
- dim *= ((TypeSArray *)t)->dim->toInteger();
- e1->type = new TypeSArray(t->nextOf(), new IntegerExp(0, dim, Type::tindex));
- }
- }
- e1 = new SliceExp(loc, e1, NULL, NULL);
- }
- else if (t->ty == Tstruct)
- {
- ei->exp = ei->exp->semantic(sc);
- ei->exp = resolveProperties(sc, ei->exp);
- StructDeclaration *sd = ((TypeStruct *)t)->sym;
+ Type *t = type->toBasetype();
+ if (t->ty == Tsarray && !(storage_class & (STCref | STCout)))
+ {
+ ei->exp = ei->exp->semantic(sc);
+ if (!ei->exp->implicitConvTo(type))
+ {
+ int dim = ((TypeSArray *)t)->dim->toInteger();
+ // If multidimensional static array, treat as one large array
+ while (1)
+ {
+ t = t->nextOf()->toBasetype();
+ if (t->ty != Tsarray)
+ break;
+ dim *= ((TypeSArray *)t)->dim->toInteger();
+ e1->type = new TypeSArray(t->nextOf(), new IntegerExp(0, dim, Type::tindex));
+ }
+ }
+ e1 = new SliceExp(loc, e1, NULL, NULL);
+ }
+ else if (t->ty == Tstruct)
+ {
+ ei->exp = ei->exp->semantic(sc);
+ ei->exp = resolveProperties(sc, ei->exp);
+ StructDeclaration *sd = ((TypeStruct *)t)->sym;
#if DMDV2
- /* Look to see if initializer is a call to the constructor
- */
- if (sd->ctor && // there are constructors
- ei->exp->type->ty == Tstruct && // rvalue is the same struct
- ((TypeStruct *)ei->exp->type)->sym == sd &&
- ei->exp->op == TOKstar)
- {
- /* Look for form of constructor call which is:
- * *__ctmp.ctor(arguments...)
- */
- PtrExp *pe = (PtrExp *)ei->exp;
- if (pe->e1->op == TOKcall)
- { CallExp *ce = (CallExp *)pe->e1;
- if (ce->e1->op == TOKdotvar)
- { DotVarExp *dve = (DotVarExp *)ce->e1;
- if (dve->var->isCtorDeclaration())
- { /* It's a constructor call, currently constructing
- * a temporary __ctmp.
- */
- /* Before calling the constructor, initialize
- * variable with a bit copy of the default
- * initializer
- */
- Expression *e = new AssignExp(loc, new VarExp(loc, this), t->defaultInit(loc));
- e->op = TOKblit;
- e->type = t;
- ei->exp = new CommaExp(loc, e, ei->exp);
+ /* Look to see if initializer is a call to the constructor
+ */
+ if (sd->ctor && // there are constructors
+ ei->exp->type->ty == Tstruct && // rvalue is the same struct
+ ((TypeStruct *)ei->exp->type)->sym == sd &&
+ ei->exp->op == TOKstar)
+ {
+ /* Look for form of constructor call which is:
+ * *__ctmp.ctor(arguments...)
+ */
+ PtrExp *pe = (PtrExp *)ei->exp;
+ if (pe->e1->op == TOKcall)
+ { CallExp *ce = (CallExp *)pe->e1;
+ if (ce->e1->op == TOKdotvar)
+ { DotVarExp *dve = (DotVarExp *)ce->e1;
+ if (dve->var->isCtorDeclaration())
+ { /* It's a constructor call, currently constructing
+ * a temporary __ctmp.
+ */
+ /* Before calling the constructor, initialize
+ * variable with a bit copy of the default
+ * initializer
+ */
+ Expression *e = new AssignExp(loc, new VarExp(loc, this), t->defaultInit(loc));
+ e->op = TOKblit;
+ e->type = t;
+ ei->exp = new CommaExp(loc, e, ei->exp);
- /* Replace __ctmp being constructed with e1
- */
- dve->e1 = e1;
- return;
- }
- }
- }
- }
+ /* Replace __ctmp being constructed with e1
+ */
+ dve->e1 = e1;
+ return;
+ }
+ }
+ }
+ }
#endif
- if (!ei->exp->implicitConvTo(type))
- {
- /* Look for opCall
- * See bugzilla 2702 for more discussion
- */
- Type *ti = ei->exp->type->toBasetype();
- // Don't cast away invariant or mutability in initializer
- if (search_function(sd, Id::call) &&
- /* Initializing with the same type is done differently
- */
- !(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc)))
- { // Rewrite as e1.call(arguments)
- Expression * eCall = new DotIdExp(loc, e1, Id::call);
- ei->exp = new CallExp(loc, eCall, ei->exp);
- }
- }
- }
- ei->exp = new AssignExp(loc, e1, ei->exp);
- ei->exp->op = TOKconstruct;
- canassign++;
- ei->exp = ei->exp->semantic(sc);
- canassign--;
- ei->exp->optimize(WANTvalue);
- }
- else
- {
- init = init->semantic(sc, type);
- if (fd && isConst() && !isStatic())
- { // Make it static
- storage_class |= STCstatic;
- }
- }
- }
- else if (isConst() || isFinal() ||
- parent->isAggregateDeclaration())
- {
- /* Because we may need the results of a const declaration in a
- * subsequent type, such as an array dimension, before semantic2()
- * gets ordinarily run, try to run semantic2() now.
- * Ignore failure.
- */
+ if (!ei->exp->implicitConvTo(type))
+ {
+ /* Look for opCall
+ * See bugzilla 2702 for more discussion
+ */
+ Type *ti = ei->exp->type->toBasetype();
+ // Don't cast away invariant or mutability in initializer
+ if (search_function(sd, Id::call) &&
+ /* Initializing with the same type is done differently
+ */
+ !(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc)))
+ { // Rewrite as e1.call(arguments)
+ Expression * eCall = new DotIdExp(loc, e1, Id::call);
+ ei->exp = new CallExp(loc, eCall, ei->exp);
+ }
+ }
+ }
+ ei->exp = new AssignExp(loc, e1, ei->exp);
+ ei->exp->op = TOKconstruct;
+ canassign++;
+ ei->exp = ei->exp->semantic(sc);
+ canassign--;
+ ei->exp->optimize(WANTvalue);
+ }
+ else
+ {
+ init = init->semantic(sc, type);
+ if (fd && isConst() && !isStatic())
+ { // Make it static
+ storage_class |= STCstatic;
+ }
+ }
+ }
+ else if (isConst() || isFinal() ||
+ parent->isAggregateDeclaration())
+ {
+ /* Because we may need the results of a const declaration in a
+ * subsequent type, such as an array dimension, before semantic2()
+ * gets ordinarily run, try to run semantic2() now.
+ * Ignore failure.
+ */
- if (!global.errors && !inferred)
- {
- unsigned errors = global.errors;
- global.gag++;
- //printf("+gag\n");
- Expression *e;
- Initializer *i2 = init;
- inuse++;
- if (ei)
- {
- e = ei->exp->syntaxCopy();
- e = e->semantic(sc);
- e = e->implicitCastTo(sc, type);
- }
- else if (si || ai)
- { i2 = init->syntaxCopy();
- i2 = i2->semantic(sc, type);
- }
- inuse--;
- global.gag--;
- //printf("-gag\n");
- if (errors != global.errors) // if errors happened
- {
- if (global.gag == 0)
- global.errors = errors; // act as if nothing happened
+ if (!global.errors && !inferred)
+ {
+ unsigned errors = global.errors;
+ global.gag++;
+ //printf("+gag\n");
+ Expression *e;
+ Initializer *i2 = init;
+ inuse++;
+ if (ei)
+ {
+ e = ei->exp->syntaxCopy();
+ e = e->semantic(sc);
+ e = e->implicitCastTo(sc, type);
+ }
+ else if (si || ai)
+ { i2 = init->syntaxCopy();
+ i2 = i2->semantic(sc, type);
+ }
+ inuse--;
+ global.gag--;
+ //printf("-gag\n");
+ if (errors != global.errors) // if errors happened
+ {
+ if (global.gag == 0)
+ global.errors = errors; // act as if nothing happened
#if DMDV2
- /* Save scope for later use, to try again
- */
- scope = new Scope(*sc);
- scope->setNoFree();
+ /* Save scope for later use, to try again
+ */
+ scope = new Scope(*sc);
+ scope->setNoFree();
#endif
- }
- else if (ei)
- {
- e = e->optimize(WANTvalue | WANTinterpret);
- if (e->op == TOKint64 || e->op == TOKstring || e->op == TOKfloat64)
- {
- ei->exp = e; // no errors, keep result
- }
+ }
+ else if (ei)
+ {
+ e = e->optimize(WANTvalue | WANTinterpret);
+ if (e->op == TOKint64 || e->op == TOKstring || e->op == TOKfloat64)
+ {
+ ei->exp = e; // no errors, keep result
+ }
#if DMDV2
- else
- {
- /* Save scope for later use, to try again
- */
- scope = new Scope(*sc);
- scope->setNoFree();
- }
+ else
+ {
+ /* Save scope for later use, to try again
+ */
+ scope = new Scope(*sc);
+ scope->setNoFree();
+ }
#endif
- }
- else
- init = i2; // no errors, keep result
- }
- }
- sc = sc->pop();
+ }
+ else
+ init = i2; // no errors, keep result
+ }
+ }
+ sc = sc->pop();
}
}
@@ -1223,14 +1223,14 @@ ExpInitializer *VarDeclaration::getExpInitializer()
ExpInitializer *ei;
if (init)
- ei = init->isExpInitializer();
+ ei = init->isExpInitializer();
else
{
- Expression *e = type->defaultInit(loc);
- if (e)
- ei = new ExpInitializer(loc, e);
- else
- ei = NULL;
+ Expression *e = type->defaultInit(loc);
+ if (e)
+ ei = new ExpInitializer(loc, e);
+ else
+ ei = NULL;
}
return ei;
}
@@ -1239,17 +1239,17 @@ void VarDeclaration::semantic2(Scope *sc)
{
//printf("VarDeclaration::semantic2('%s')\n", toChars());
if (init && !toParent()->isFuncDeclaration())
- { inuse++;
+ { inuse++;
#if 0
- ExpInitializer *ei = init->isExpInitializer();
- if (ei)
- {
- ei->exp->dump(0);
- printf("type = %p\n", ei->exp->type);
- }
+ ExpInitializer *ei = init->isExpInitializer();
+ if (ei)
+ {
+ ei->exp->dump(0);
+ printf("type = %p\n", ei->exp->type);
+ }
#endif
- init = init->semantic(sc, type);
- inuse--;
+ init = init->semantic(sc, type);
+ inuse--;
}
}
@@ -1284,18 +1284,18 @@ void VarDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
* too.
*/
if (type)
- type->toCBuffer(buf, ident, hgs);
+ type->toCBuffer(buf, ident, hgs);
else
- buf->writestring(ident->toChars());
+ buf->writestring(ident->toChars());
if (init)
- { buf->writestring(" = ");
+ { buf->writestring(" = ");
#if DMDV2
- ExpInitializer *ie = init->isExpInitializer();
- if (ie && (ie->exp->op == TOKconstruct || ie->exp->op == TOKblit))
- ((AssignExp *)ie->exp)->e2->toCBuffer(buf, hgs);
- else
+ ExpInitializer *ie = init->isExpInitializer();
+ if (ie && (ie->exp->op == TOKconstruct || ie->exp->op == TOKblit))
+ ((AssignExp *)ie->exp)->e2->toCBuffer(buf, hgs);
+ else
#endif
- init->toCBuffer(buf, hgs);
+ init->toCBuffer(buf, hgs);
}
buf->writeByte(';');
buf->writenl();
@@ -1310,14 +1310,14 @@ int VarDeclaration::needThis()
int VarDeclaration::isImportedSymbol()
{
if (protection == PROTexport && !init && (isStatic() || isConst() || parent->isModule()))
- return TRUE;
+ return TRUE;
return FALSE;
}
void VarDeclaration::checkCtorConstInit()
{
if (ctorinit == 0 && isCtorinit() && !(storage_class & STCfield))
- error("missing initializer in static constructor for const variable");
+ error("missing initializer in static constructor for const variable");
}
/************************************
@@ -1330,24 +1330,24 @@ void VarDeclaration::checkNestedReference(Scope *sc, Loc loc)
//printf("VarDeclaration::checkNestedReference() %s\n", toChars());
if (parent && !isDataseg() && parent != sc->parent)
{
- // The function that this variable is in
- FuncDeclaration *fdv = toParent()->isFuncDeclaration();
- // The current function
- FuncDeclaration *fdthis = sc->parent->isFuncDeclaration();
+ // The function that this variable is in
+ FuncDeclaration *fdv = toParent()->isFuncDeclaration();
+ // The current function
+ FuncDeclaration *fdthis = sc->parent->isFuncDeclaration();
- if (fdv && fdthis)
- {
- if (loc.filename)
- fdthis->getLevel(loc, fdv);
- nestedref = 1;
- fdv->nestedFrameRef = 1;
+ if (fdv && fdthis)
+ {
+ if (loc.filename)
+ fdthis->getLevel(loc, fdv);
+ nestedref = 1;
+ fdv->nestedFrameRef = 1;
#if IN_LLVM
#if DMDV1
fdv->nestedVars.insert(this);
#endif
#endif
- //printf("var %s in function %s is nested ref\n", toChars(), fdv->toChars());
- }
+ //printf("var %s in function %s is nested ref\n", toChars(), fdv->toChars());
+ }
}
}
@@ -1365,13 +1365,13 @@ int VarDeclaration::isDataseg()
#endif
Dsymbol *parent = this->toParent();
if (!parent && !(storage_class & (STCstatic | STCconst)))
- { error("forward referenced");
- type = Type::terror;
- return 0;
+ { error("forward referenced");
+ type = Type::terror;
+ return 0;
}
return (storage_class & (STCstatic | STCconst) ||
- parent->isModule() ||
- parent->isTemplateInstance());
+ parent->isModule() ||
+ parent->isTemplateInstance());
}
/************************************
@@ -1402,7 +1402,7 @@ int VarDeclaration::hasPointers()
int VarDeclaration::isSameAsInitializer()
{
- if (init && init->isExpInitializer() &&
+ if (init && init->isExpInitializer() &&
init->isExpInitializer()->exp->op == TOKstructliteral)
return 0;
return isConst();
@@ -1419,27 +1419,27 @@ Expression *VarDeclaration::callScopeDtor(Scope *sc)
//printf("VarDeclaration::callScopeDtor() %s\n", toChars());
if (storage_class & STCscope && !noscope)
{
- for (ClassDeclaration *cd = type->isClassHandle();
- cd;
- cd = cd->baseClass)
- {
- /* We can do better if there's a way with onstack
- * classes to determine if there's no way the monitor
- * could be set.
- */
- //if (cd->isInterfaceDeclaration())
- //error("interface %s cannot be scope", cd->toChars());
- if (1 || onstack || cd->dtors.dim) // if any destructors
- {
- // delete this;
- Expression *ec;
+ for (ClassDeclaration *cd = type->isClassHandle();
+ cd;
+ cd = cd->baseClass)
+ {
+ /* We can do better if there's a way with onstack
+ * classes to determine if there's no way the monitor
+ * could be set.
+ */
+ //if (cd->isInterfaceDeclaration())
+ //error("interface %s cannot be scope", cd->toChars());
+ if (1 || onstack || cd->dtors.dim) // if any destructors
+ {
+ // delete this;
+ Expression *ec;
- ec = new VarExp(loc, this);
- e = new DeleteExp(loc, ec);
- e->type = Type::tvoid;
- break;
- }
- }
+ ec = new VarExp(loc, this);
+ e = new DeleteExp(loc, ec);
+ e->type = Type::tvoid;
+ break;
+ }
+ }
}
return e;
}
@@ -1456,7 +1456,7 @@ ClassInfoDeclaration::ClassInfoDeclaration(ClassDeclaration *cd)
Dsymbol *ClassInfoDeclaration::syntaxCopy(Dsymbol *s)
{
- assert(0); // should never be produced by syntax
+ assert(0); // should never be produced by syntax
return NULL;
}
@@ -1475,7 +1475,7 @@ ModuleInfoDeclaration::ModuleInfoDeclaration(Module *mod)
Dsymbol *ModuleInfoDeclaration::syntaxCopy(Dsymbol *s)
{
- assert(0); // should never be produced by syntax
+ assert(0); // should never be produced by syntax
return NULL;
}
@@ -1496,7 +1496,7 @@ TypeInfoDeclaration::TypeInfoDeclaration(Type *tinfo, int internal)
Dsymbol *TypeInfoDeclaration::syntaxCopy(Dsymbol *s)
{
- assert(0); // should never be produced by syntax
+ assert(0); // should never be produced by syntax
return NULL;
}
@@ -1632,7 +1632,7 @@ ThisDeclaration::ThisDeclaration(Loc loc, Type *t)
Dsymbol *ThisDeclaration::syntaxCopy(Dsymbol *s)
{
- assert(0); // should never be produced by syntax
+ assert(0); // should never be produced by syntax
return NULL;
}
diff --git a/dmd/declaration.h b/dmd/declaration.h
index 74b0d135..43ad8e94 100644
--- a/dmd/declaration.h
+++ b/dmd/declaration.h
@@ -49,73 +49,73 @@ enum MATCH;
enum STC
{
STCundefined = 0,
- STCstatic = 1,
- STCextern = 2,
- STCconst = 4,
- STCfinal = 8,
+ STCstatic = 1,
+ STCextern = 2,
+ STCconst = 4,
+ STCfinal = 8,
STCabstract = 0x10,
STCparameter = 0x20,
- STCfield = 0x40,
- STCoverride = 0x80,
+ STCfield = 0x40,
+ STCoverride = 0x80,
STCauto = 0x100,
STCsynchronized = 0x200,
STCdeprecated = 0x400,
- STCin = 0x800, // in parameter
- STCout = 0x1000, // out parameter
- STClazy = 0x2000, // lazy parameter
- STCforeach = 0x4000, // variable for foreach loop
- STCcomdat = 0x8000, // should go into COMDAT record
- STCvariadic = 0x10000, // variadic function argument
- STCctorinit = 0x20000, // can only be set inside constructor
- STCtemplateparameter = 0x40000, // template parameter
- STCscope = 0x80000, // template parameter
+ STCin = 0x800, // in parameter
+ STCout = 0x1000, // out parameter
+ STClazy = 0x2000, // lazy parameter
+ STCforeach = 0x4000, // variable for foreach loop
+ STCcomdat = 0x8000, // should go into COMDAT record
+ STCvariadic = 0x10000, // variadic function argument
+ STCctorinit = 0x20000, // can only be set inside constructor
+ STCtemplateparameter = 0x40000, // template parameter
+ STCscope = 0x80000, // template parameter
STCimmutable = 0x100000,
- STCref = 0x200000,
- STCinit = 0x400000, // has explicit initializer
- STCmanifest = 0x800000, // manifest constant
- STCnodtor = 0x1000000, // don't run destructor
- STCnothrow = 0x2000000, // never throws exceptions
- STCpure = 0x4000000, // pure function
- STCtls = 0x8000000, // thread local
- STCalias = 0x10000000, // alias parameter
- STCshared = 0x20000000, // accessible from multiple threads
- STCgshared = 0x40000000, // accessible from multiple threads
- // but not typed as "shared"
- STCwild = 0x80000000, // for "wild" type constructor
+ STCref = 0x200000,
+ STCinit = 0x400000, // has explicit initializer
+ STCmanifest = 0x800000, // manifest constant
+ STCnodtor = 0x1000000, // don't run destructor
+ STCnothrow = 0x2000000, // never throws exceptions
+ STCpure = 0x4000000, // pure function
+ STCtls = 0x8000000, // thread local
+ STCalias = 0x10000000, // alias parameter
+ STCshared = 0x20000000, // accessible from multiple threads
+ STCgshared = 0x40000000, // accessible from multiple threads
+ // but not typed as "shared"
+ STCwild = 0x80000000, // for "wild" type constructor
STC_TYPECTOR = (STCconst | STCimmutable | STCshared | STCwild),
};
-#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 STCproperty 0x100000000LL
+#define STCsafe 0x200000000LL
+#define STCtrusted 0x400000000LL
+#define STCsystem 0x800000000LL
+#define STCctfe 0x1000000000LL // can be used in CTFE, even if it is static
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
+ 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 overloadResolveX(Match *m, FuncDeclaration *f,
- Expression *ethis, Expressions *arguments, Module *from);
+ Expression *ethis, Expressions *arguments, Module *from);
int overloadApply(Module* from, FuncDeclaration *fstart,
- int (*fp)(void *, FuncDeclaration *),
- void *param);
+ int (*fp)(void *, FuncDeclaration *),
+ void *param);
/**************************************************************/
struct Declaration : Dsymbol
{
Type *type;
- Type *originalType; // before semantic analysis
+ Type *originalType; // before semantic analysis
StorageClass storage_class;
enum PROT protection;
enum LINK linkage;
- int inuse; // used to detect cycles
+ int inuse; // used to detect cycles
Declaration(Identifier *id);
void semantic(Scope *sc);
@@ -146,7 +146,7 @@ struct Declaration : Dsymbol
int isParameter() { return storage_class & STCparameter; }
int isDeprecated() { return storage_class & STCdeprecated; }
int isOverride() { return storage_class & STCoverride; }
-
+
virtual int isSameAsInitializer() { return isConst(); };
int isIn() { return storage_class & STCin; }
@@ -168,9 +168,9 @@ struct Declaration : Dsymbol
struct TupleDeclaration : Declaration
{
Objects *objects;
- int isexp; // 1: expression tuple
+ int isexp; // 1: expression tuple
- TypeTuple *tupletype; // !=NULL if this is a type tuple
+ TypeTuple *tupletype; // !=NULL if this is a type tuple
TupleDeclaration(Loc loc, Identifier *ident, Objects *objects);
Dsymbol *syntaxCopy(Dsymbol *);
@@ -192,10 +192,10 @@ struct TypedefDeclaration : Declaration
{
Type *basetype;
Initializer *init;
- int sem; // 0: semantic() has not been run
- // 1: semantic() is in progress
- // 2: semantic() has been run
- // 3: semantic2() has been run
+ int sem; // 0: semantic() has not been run
+ // 1: semantic() is in progress
+ // 2: semantic() has been run
+ // 3: semantic2() has been run
TypedefDeclaration(Loc loc, Identifier *ident, Type *basetype, Initializer *init);
Dsymbol *syntaxCopy(Dsymbol *);
@@ -213,7 +213,7 @@ struct TypedefDeclaration : Declaration
void toDocBuffer(OutBuffer *buf);
#if IN_DMD
- void toObjFile(int multiobj); // compile to .obj file
+ void toObjFile(int multiobj); // compile to .obj file
void toDebug();
int cvMember(unsigned char *p);
#endif
@@ -236,9 +236,9 @@ struct TypedefDeclaration : Declaration
struct AliasDeclaration : Declaration
{
Dsymbol *aliassym;
- Dsymbol *overnext; // next in overload list
+ Dsymbol *overnext; // next in overload list
int inSemantic;
- PROT importprot; // if generated by import, store its protection
+ PROT importprot; // if generated by import, store its protection
AliasDeclaration(Loc loc, Identifier *ident, Type *type);
AliasDeclaration(Loc loc, Identifier *ident, Dsymbol *s);
@@ -265,24 +265,24 @@ struct VarDeclaration : Declaration
{
Initializer *init;
unsigned offset;
- int noscope; // no scope semantics
+ int noscope; // no scope semantics
#if DMDV2
FuncDeclarations nestedrefs; // referenced by these lexically nested functions
- bool isargptr; // if parameter that _argptr points to
+ bool isargptr; // if parameter that _argptr points to
#else
- int nestedref; // referenced by a lexically nested function
+ int nestedref; // referenced by a lexically nested function
#endif
- int ctorinit; // it has been initialized in a ctor
- int onstack; // 1: it has been allocated on the stack
- // 2: on stack, run destructor anyway
- int canassign; // it can be assigned to
- Dsymbol *aliassym; // if redone as alias to another symbol
- Expression *value; // when interpreting, this is the value
- // (NULL if value not determinable)
+ int ctorinit; // it has been initialized in a ctor
+ int onstack; // 1: it has been allocated on the stack
+ // 2: on stack, run destructor anyway
+ int canassign; // it can be assigned to
+ Dsymbol *aliassym; // if redone as alias to another symbol
+ Expression *value; // when interpreting, this is the value
+ // (NULL if value not determinable)
#if DMDV2
- VarDeclaration *rundtor; // if !NULL, rundtor is tested at runtime to see
- // if the destructor should be run. Used to prevent
- // dtor calls on postblitted vars
+ VarDeclaration *rundtor; // if !NULL, rundtor is tested at runtime to see
+ // if the destructor should be run. Used to prevent
+ // dtor calls on postblitted vars
#endif
VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init);
@@ -311,11 +311,11 @@ struct VarDeclaration : Declaration
void checkCtorConstInit();
void checkNestedReference(Scope *sc, Loc loc);
Dsymbol *toAlias();
-
+
virtual int isSameAsInitializer();
#if IN_DMD
- void toObjFile(int multiobj); // compile to .obj file
+ void toObjFile(int multiobj); // compile to .obj file
Symbol *toSymbol();
int cvMember(unsigned char *p);
#endif
@@ -409,7 +409,7 @@ struct TypeInfoDeclaration : VarDeclaration
void toJsonBuffer(OutBuffer *buf);
#if IN_DMD
- void toObjFile(int multiobj); // compile to .obj file
+ void toObjFile(int multiobj); // compile to .obj file
Symbol *toSymbol();
virtual void toDt(dt_t **pdt);
#endif
@@ -625,9 +625,9 @@ struct ThisDeclaration : VarDeclaration
enum ILS
{
- ILSuninitialized, // not computed yet
- ILSno, // cannot inline
- ILSyes, // can inline
+ ILSuninitialized, // not computed yet
+ ILSno, // cannot inline
+ ILSyes, // can inline
};
/**************************************************************/
@@ -635,13 +635,13 @@ enum ILS
enum BUILTIN
{
- BUILTINunknown = -1, // not known if this is a builtin
- BUILTINnot, // this is not a builtin
- BUILTINsin, // std.math.sin
- BUILTINcos, // std.math.cos
- BUILTINtan, // std.math.tan
- BUILTINsqrt, // std.math.sqrt
- BUILTINfabs, // std.math.fabs
+ BUILTINunknown = -1, // not known if this is a builtin
+ BUILTINnot, // this is not a builtin
+ BUILTINsin, // std.math.sin
+ BUILTINcos, // std.math.cos
+ BUILTINtan, // std.math.tan
+ BUILTINsqrt, // std.math.sqrt
+ BUILTINfabs, // std.math.fabs
};
Expression *eval_builtin(enum BUILTIN builtin, Expressions *arguments);
@@ -652,74 +652,74 @@ enum BUILTIN { };
struct FuncDeclaration : Declaration
{
- Array *fthrows; // Array of Type's of exceptions (not used)
+ Array *fthrows; // Array of Type's of exceptions (not used)
Statement *frequire;
Statement *fensure;
Statement *fbody;
- FuncDeclarations foverrides; // functions this function overrides
- FuncDeclaration *fdrequire; // function that does the in contract
- FuncDeclaration *fdensure; // function that does the out contract
+ FuncDeclarations foverrides; // functions this function overrides
+ FuncDeclaration *fdrequire; // function that does the in contract
+ FuncDeclaration *fdensure; // function that does the out contract
- Identifier *outId; // identifier for out statement
- VarDeclaration *vresult; // variable corresponding to outId
- LabelDsymbol *returnLabel; // where the return goes
+ Identifier *outId; // identifier for out statement
+ VarDeclaration *vresult; // variable corresponding to outId
+ LabelDsymbol *returnLabel; // where the return goes
- DsymbolTable *localsymtab; // used to prevent symbols in different
- // scopes from having the same name
- VarDeclaration *vthis; // 'this' parameter (member and nested)
- VarDeclaration *v_arguments; // '_arguments' parameter
+ DsymbolTable *localsymtab; // used to prevent symbols in different
+ // scopes from having the same name
+ VarDeclaration *vthis; // 'this' parameter (member and nested)
+ VarDeclaration *v_arguments; // '_arguments' parameter
#if IN_GCC
- VarDeclaration *v_argptr; // '_argptr' variable
+ VarDeclaration *v_argptr; // '_argptr' variable
#endif
- Dsymbols *parameters; // Array of VarDeclaration's for parameters
- DsymbolTable *labtab; // statement label symbol table
- Declaration *overnext; // next in overload list
- Loc endloc; // location of closing curly bracket
- int vtblIndex; // for member functions, index into vtbl[]
- int naked; // !=0 if naked
- int inlineAsm; // !=0 if has inline assembler
+ Dsymbols *parameters; // Array of VarDeclaration's for parameters
+ DsymbolTable *labtab; // statement label symbol table
+ Declaration *overnext; // next in overload list
+ Loc endloc; // location of closing curly bracket
+ int vtblIndex; // for member functions, index into vtbl[]
+ int naked; // !=0 if naked
+ int inlineAsm; // !=0 if has inline assembler
ILS inlineStatus;
- int inlineNest; // !=0 if nested inline
- int cantInterpret; // !=0 if cannot interpret function
- int semanticRun; // 1 semantic() run
- // 2 semantic2() run
- // 3 semantic3() started
- // 4 semantic3() done
- // 5 toObjFile() run
- // this function's frame ptr
- ForeachStatement *fes; // if foreach body, this is the foreach
- int introducing; // !=0 if 'introducing' function
- Type *tintro; // if !=NULL, then this is the type
- // of the 'introducing' function
- // this one is overriding
- int inferRetType; // !=0 if return type is to be inferred
+ int inlineNest; // !=0 if nested inline
+ int cantInterpret; // !=0 if cannot interpret function
+ int semanticRun; // 1 semantic() run
+ // 2 semantic2() run
+ // 3 semantic3() started
+ // 4 semantic3() done
+ // 5 toObjFile() run
+ // this function's frame ptr
+ ForeachStatement *fes; // if foreach body, this is the foreach
+ int introducing; // !=0 if 'introducing' function
+ Type *tintro; // if !=NULL, then this is the type
+ // of the 'introducing' function
+ // this one is overriding
+ int inferRetType; // !=0 if return type is to be inferred
// Things that should really go into Scope
- int hasReturnExp; // 1 if there's a return exp; statement
- // 2 if there's a throw statement
- // 4 if there's an assert(0)
- // 8 if there's inline asm
+ int hasReturnExp; // 1 if there's a return exp; statement
+ // 2 if there's a throw statement
+ // 4 if there's an assert(0)
+ // 8 if there's inline asm
// Support for NRVO (named return value optimization)
- int nrvo_can; // !=0 means we can do it
- VarDeclaration *nrvo_var; // variable to replace with shidden
+ int nrvo_can; // !=0 means we can do it
+ VarDeclaration *nrvo_var; // variable to replace with shidden
#if IN_DMD
- Symbol *shidden; // hidden pointer passed to function
+ Symbol *shidden; // hidden pointer passed to function
#endif
#if DMDV2
- enum BUILTIN builtin; // set if this is a known, builtin
- // function we can evaluate at compile
- // time
+ enum BUILTIN builtin; // set if this is a known, builtin
+ // function we can evaluate at compile
+ // time
- int tookAddressOf; // set if someone took the address of
- // this function
- Dsymbols closureVars; // local variables in this function
- // which are referenced by nested
- // functions
+ int tookAddressOf; // set if someone took the address of
+ // this function
+ Dsymbols closureVars; // local variables in this function
+ // which are referenced by nested
+ // functions
#else
- int nestedFrameRef; // !=0 if nested variables referenced
+ int nestedFrameRef; // !=0 if nested variables referenced
#endif
FuncDeclaration(Loc loc, Loc endloc, Identifier *id, StorageClass storage_class, Type *type);
@@ -741,7 +741,7 @@ struct FuncDeclaration : Declaration
LabelDsymbol *searchLabel(Identifier *ident);
AggregateDeclaration *isThis();
AggregateDeclaration *isMember2();
- int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference
+ int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference
void appendExp(Expression *e);
void appendState(Statement *s);
char *mangle();
@@ -780,8 +780,8 @@ struct FuncDeclaration : Declaration
#if IN_DMD
Symbol *toSymbol();
- Symbol *toThunkSymbol(int offset); // thunk version
- void toObjFile(int multiobj); // compile to .obj file
+ Symbol *toThunkSymbol(int offset); // thunk version
+ void toObjFile(int multiobj); // compile to .obj file
int cvMember(unsigned char *p);
void buildClosure(IRState *irs);
#endif
@@ -822,17 +822,17 @@ struct FuncDeclaration : Declaration
#if DMDV2
FuncDeclaration *resolveFuncCall(Scope *sc, Loc loc, Dsymbol *s,
- Objects *tiargs,
- Expression *ethis,
- Expressions *arguments,
- int flags);
+ Objects *tiargs,
+ Expression *ethis,
+ Expressions *arguments,
+ int flags);
#endif
struct FuncAliasDeclaration : FuncDeclaration
{
FuncDeclaration *funcalias;
- PROT importprot; // if generated by import, store its protection
-
+ PROT importprot; // if generated by import, store its protection
+
FuncAliasDeclaration(FuncDeclaration *funcalias);
FuncAliasDeclaration *isFuncAliasDeclaration() { return this; }
@@ -844,10 +844,10 @@ struct FuncAliasDeclaration : FuncDeclaration
struct FuncLiteralDeclaration : FuncDeclaration
{
- enum TOK tok; // TOKfunction or TOKdelegate
+ enum TOK tok; // TOKfunction or TOKdelegate
FuncLiteralDeclaration(Loc loc, Loc endloc, Type *type, enum TOK tok,
- ForeachStatement *fes);
+ ForeachStatement *fes);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Dsymbol *syntaxCopy(Dsymbol *);
int isNested();
@@ -931,7 +931,7 @@ struct StaticCtorDeclaration : FuncDeclaration
};
struct StaticDtorDeclaration : FuncDeclaration
-{ VarDeclaration *vgate; // 'gate' variable
+{ VarDeclaration *vgate; // 'gate' variable
StaticDtorDeclaration(Loc loc, Loc endloc);
Dsymbol *syntaxCopy(Dsymbol *);
diff --git a/dmd/delegatize.c b/dmd/delegatize.c
index da38f2a7..dde4046d 100644
--- a/dmd/delegatize.c
+++ b/dmd/delegatize.c
@@ -23,9 +23,9 @@
/********************************************
* Convert from expression to delegate that returns the expression,
* i.e. convert:
- * expr
+ * expr
* to:
- * t delegate() { return expr; }
+ * t delegate() { return expr; }
*/
Expression *Expression::toDelegate(Scope *sc, Type *t)
@@ -33,11 +33,11 @@ Expression *Expression::toDelegate(Scope *sc, Type *t)
//printf("Expression::toDelegate(t = %s) %s\n", t->toChars(), toChars());
TypeFunction *tf = new TypeFunction(NULL, t, 0, LINKd);
FuncLiteralDeclaration *fld =
- new FuncLiteralDeclaration(loc, loc, tf, TOKdelegate, NULL);
+ new FuncLiteralDeclaration(loc, loc, tf, TOKdelegate, NULL);
Expression *e;
#if 1
sc = sc->push();
- sc->parent = fld; // set current function to be the delegate
+ sc->parent = fld; // set current function to be the delegate
e = this;
e->scanForNestedRef(sc);
sc = sc->pop();
@@ -60,14 +60,14 @@ void arrayExpressionScanForNestedRef(Scope *sc, Expressions *a)
//printf("arrayExpressionScanForNestedRef(%p)\n", a);
if (a)
{
- for (int i = 0; i < a->dim; i++)
- { Expression *e = (Expression *)a->data[i];
+ for (int i = 0; i < a->dim; i++)
+ { Expression *e = (Expression *)a->data[i];
- if (e)
- {
- e->scanForNestedRef(sc);
- }
- }
+ if (e)
+ {
+ e->scanForNestedRef(sc);
+ }
+ }
}
}
@@ -81,7 +81,7 @@ void SymOffExp::scanForNestedRef(Scope *sc)
//printf("SymOffExp::scanForNestedRef(%s)\n", toChars());
VarDeclaration *v = var->isVarDeclaration();
if (v)
- v->checkNestedReference(sc, 0);
+ v->checkNestedReference(sc, 0);
}
void VarExp::scanForNestedRef(Scope *sc)
@@ -89,7 +89,7 @@ void VarExp::scanForNestedRef(Scope *sc)
//printf("VarExp::scanForNestedRef(%s)\n", toChars());
VarDeclaration *v = var->isVarDeclaration();
if (v)
- v->checkNestedReference(sc, 0);
+ v->checkNestedReference(sc, 0);
}
void ThisExp::scanForNestedRef(Scope *sc)
@@ -120,7 +120,7 @@ void NewExp::scanForNestedRef(Scope *sc)
//printf("NewExp::scanForNestedRef(Scope *sc): %s\n", toChars());
if (thisexp)
- thisexp->scanForNestedRef(sc);
+ thisexp->scanForNestedRef(sc);
arrayExpressionScanForNestedRef(sc, newargs);
arrayExpressionScanForNestedRef(sc, arguments);
}
@@ -149,8 +149,8 @@ void IndexExp::scanForNestedRef(Scope *sc)
e1->scanForNestedRef(sc);
if (lengthVar)
- { //printf("lengthVar\n");
- lengthVar->parent = sc->parent;
+ { //printf("lengthVar\n");
+ lengthVar->parent = sc->parent;
}
e2->scanForNestedRef(sc);
}
@@ -161,13 +161,13 @@ void SliceExp::scanForNestedRef(Scope *sc)
e1->scanForNestedRef(sc);
if (lengthVar)
- { //printf("lengthVar\n");
- lengthVar->parent = sc->parent;
+ { //printf("lengthVar\n");
+ lengthVar->parent = sc->parent;
}
if (lwr)
- lwr->scanForNestedRef(sc);
+ lwr->scanForNestedRef(sc);
if (upr)
- upr->scanForNestedRef(sc);
+ upr->scanForNestedRef(sc);
}
diff --git a/dmd/doc.c b/dmd/doc.c
index 243e1596..a22f506d 100644
--- a/dmd/doc.c
+++ b/dmd/doc.c
@@ -67,7 +67,7 @@ struct MacroSection : Section
struct DocComment
{
- Array sections; // Section*[]
+ Array sections; // Section*[]
Section *summary;
Section *copyright;
@@ -103,48 +103,48 @@ int isIdTail(unsigned char *p);
int utfStride(unsigned char *p);
static unsigned char ddoc_default[] = "\
-DDOC =
\n\
- \n\
- $(TITLE)\n\
- \n\
- $(TITLE)
\n\
- $(BODY)\n\
-
$(SMALL Page generated by $(LINK2 http://www.digitalmars.com/d/1.0/ddoc.html, Ddoc). $(COPYRIGHT))\n\
- \n\
+DDOC = \n\
+ \n\
+ $(TITLE)\n\
+ \n\
+ $(TITLE)
\n\
+ $(BODY)\n\
+
$(SMALL Page generated by $(LINK2 http://www.digitalmars.com/d/1.0/ddoc.html, Ddoc). $(COPYRIGHT))\n\
+ \n\
\n\
-B = $0\n\
-I = $0\n\
-U = $0\n\
-P = $0
\n\
-DL = $0
\n\
-DT = $0\n\
-DD = $0\n\
-TABLE = \n\
-TR = $0
\n\
-TH = $0 | \n\
-TD = $0 | \n\
-OL = $0
\n\
-UL = \n\
-LI = $0\n\
-BIG = $0\n\
-SMALL = $0\n\
-BR =
\n\
-LINK = $0\n\
-LINK2 = $+\n\
+B = $0\n\
+I = $0\n\
+U = $0\n\
+P = $0
\n\
+DL = $0
\n\
+DT = $0\n\
+DD = $0\n\
+TABLE = \n\
+TR = $0
\n\
+TH = $0 | \n\
+TD = $0 | \n\
+OL = $0
\n\
+UL = \n\
+LI = $0\n\
+BIG = $0\n\
+SMALL = $0\n\
+BR =
\n\
+LINK = $0\n\
+LINK2 = $+\n\
\n\
-RED = $0\n\
-BLUE = $0\n\
-GREEN = $0\n\
+RED = $0\n\
+BLUE = $0\n\
+GREEN = $0\n\
YELLOW =$0\n\
-BLACK = $0\n\
-WHITE = $0\n\
+BLACK = $0\n\
+WHITE = $0\n\
\n\
D_CODE = $0
\n\
D_COMMENT = $(GREEN $0)\n\
D_STRING = $(RED $0)\n\
D_KEYWORD = $(BLUE $0)\n\
D_PSYMBOL = $(U $0)\n\
-D_PARAM = $(I $0)\n\
+D_PARAM = $(I $0)\n\
\n\
DDOC_COMMENT = \n\
DDOC_DECL = $(DT $(BIG $0))\n\
@@ -178,15 +178,15 @@ DDOC_PARAMS = $(B Params:)$(BR)\n$(TABLE $0)$(BR)\n\
DDOC_PARAM_ROW = $(TR $0)\n\
DDOC_PARAM_ID = $(TD $0)\n\
DDOC_PARAM_DESC = $(TD $0)\n\
-DDOC_BLANKLINE = $(BR)$(BR)\n\
+DDOC_BLANKLINE = $(BR)$(BR)\n\
\n\
-DDOC_PSYMBOL = $(U $0)\n\
-DDOC_KEYWORD = $(B $0)\n\
-DDOC_PARAM = $(I $0)\n\
+DDOC_PSYMBOL = $(U $0)\n\
+DDOC_KEYWORD = $(B $0)\n\
+DDOC_PARAM = $(I $0)\n\
\n\
ESCAPES = /</\n\
- />/>/\n\
- /&/&/\n\
+ />/>/\n\
+ /&/&/\n\
";
static char ddoc_decl_s[] = "$(DDOC_DECL ";
@@ -208,32 +208,32 @@ void Module::gendocfile()
//printf("Module::gendocfile()\n");
- if (!mbuf_done) // if not already read the ddoc files
- { mbuf_done = 1;
+ if (!mbuf_done) // if not already read the ddoc files
+ { mbuf_done = 1;
- // Use our internal default
- mbuf.write(ddoc_default, sizeof(ddoc_default) - 1);
+ // Use our internal default
+ mbuf.write(ddoc_default, sizeof(ddoc_default) - 1);
- // Override with DDOCFILE specified in the sc.ini file
- char *p = getenv("DDOCFILE");
- if (p)
- global.params.ddocfiles->shift(p);
+ // Override with DDOCFILE specified in the sc.ini file
+ char *p = getenv("DDOCFILE");
+ if (p)
+ global.params.ddocfiles->shift(p);
- // Override with the ddoc macro files from the command line
- for (int i = 0; i < global.params.ddocfiles->dim; i++)
- {
- FileName f((char *)global.params.ddocfiles->data[i], 0);
- File file(&f);
- file.readv();
- // BUG: convert file contents to UTF-8 before use
+ // Override with the ddoc macro files from the command line
+ for (int i = 0; i < global.params.ddocfiles->dim; i++)
+ {
+ FileName f((char *)global.params.ddocfiles->data[i], 0);
+ File file(&f);
+ file.readv();
+ // BUG: convert file contents to UTF-8 before use
- //printf("file: '%.*s'\n", file.len, file.buffer);
- mbuf.write(file.buffer, file.len);
- }
+ //printf("file: '%.*s'\n", file.len, file.buffer);
+ mbuf.write(file.buffer, file.len);
+ }
}
DocComment::parseMacros(&escapetable, ¯otable, mbuf.data, mbuf.offset);
- Scope *sc = Scope::createGlobal(this); // create root scope
+ Scope *sc = Scope::createGlobal(this); // create root scope
sc->docbuf = &buf;
DocComment *dc = DocComment::parse(sc, this, comment);
@@ -243,8 +243,8 @@ void Module::gendocfile()
// Generate predefined macros
// Set the title to be the name of the module
- { const char *p = toPrettyChars();
- Macro::define(¯otable, (unsigned char *)"TITLE", 5, (unsigned char *)p, strlen(p));
+ { const char *p = toPrettyChars();
+ Macro::define(¯otable, (unsigned char *)"TITLE", 5, (unsigned char *)p, strlen(p));
}
time_t t;
@@ -259,26 +259,26 @@ void Module::gendocfile()
if (dc->copyright)
{
- dc->copyright->nooutput = 1;
- Macro::define(¯otable, (unsigned char *)"COPYRIGHT", 9, dc->copyright->body, dc->copyright->bodylen);
+ dc->copyright->nooutput = 1;
+ Macro::define(¯otable, (unsigned char *)"COPYRIGHT", 9, dc->copyright->body, dc->copyright->bodylen);
}
buf.printf("$(DDOC_COMMENT Generated by Ddoc from %s)\n", srcfile->toChars());
if (isDocFile)
{
- size_t commentlen = strlen((char *)comment);
- if (dc->macros)
- {
- commentlen = dc->macros->name - comment;
- dc->macros->write(dc, sc, this, sc->docbuf);
- }
- sc->docbuf->write(comment, commentlen);
- highlightText(NULL, this, sc->docbuf, 0);
+ size_t commentlen = strlen((char *)comment);
+ if (dc->macros)
+ {
+ commentlen = dc->macros->name - comment;
+ dc->macros->write(dc, sc, this, sc->docbuf);
+ }
+ sc->docbuf->write(comment, commentlen);
+ highlightText(NULL, this, sc->docbuf, 0);
}
else
{
- dc->writeSections(sc, this, sc->docbuf);
- emitMemberComments(sc);
+ dc->writeSections(sc, this, sc->docbuf);
+ emitMemberComments(sc);
}
//printf("BODY= '%.*s'\n", buf.offset, buf.data);
@@ -294,30 +294,30 @@ void Module::gendocfile()
* and make CR-LF the newline.
*/
{
- buf.setsize(0);
- buf.reserve(buf2.offset);
- unsigned char *p = buf2.data;
- for (unsigned j = 0; j < buf2.offset; j++)
- {
- unsigned char c = p[j];
- if (c == 0xFF && j + 1 < buf2.offset)
- {
- j++;
- continue;
- }
- if (c == '\n')
- buf.writeByte('\r');
- else if (c == '\r')
- {
- buf.writestring("\r\n");
- if (j + 1 < buf2.offset && p[j + 1] == '\n')
- {
- j++;
- }
- continue;
- }
- buf.writeByte(c);
- }
+ buf.setsize(0);
+ buf.reserve(buf2.offset);
+ unsigned char *p = buf2.data;
+ for (unsigned j = 0; j < buf2.offset; j++)
+ {
+ unsigned char c = p[j];
+ if (c == 0xFF && j + 1 < buf2.offset)
+ {
+ j++;
+ continue;
+ }
+ if (c == '\n')
+ buf.writeByte('\r');
+ else if (c == '\r')
+ {
+ buf.writestring("\r\n");
+ if (j + 1 < buf2.offset && p[j + 1] == '\n')
+ {
+ j++;
+ }
+ continue;
+ }
+ buf.writeByte(c);
+ }
}
// Transfer image to file
@@ -326,25 +326,25 @@ void Module::gendocfile()
docfile->ref = 1;
char *pt = FileName::path(docfile->toChars());
if (*pt)
- FileName::ensurePathExists(pt);
+ FileName::ensurePathExists(pt);
mem.free(pt);
docfile->writev();
#else
/* Remove all the escape sequences from buf2
*/
- { unsigned i = 0;
- unsigned char *p = buf2.data;
- for (unsigned j = 0; j < buf2.offset; j++)
- {
- if (p[j] == 0xFF && j + 1 < buf2.offset)
- {
- j++;
- continue;
- }
- p[i] = p[j];
- i++;
- }
- buf2.setsize(i);
+ { unsigned i = 0;
+ unsigned char *p = buf2.data;
+ for (unsigned j = 0; j < buf2.offset; j++)
+ {
+ if (p[j] == 0xFF && j + 1 < buf2.offset)
+ {
+ j++;
+ continue;
+ }
+ p[i] = p[j];
+ i++;
+ }
+ buf2.setsize(i);
}
// Transfer image to file
@@ -352,7 +352,7 @@ void Module::gendocfile()
docfile->ref = 1;
char *pt = FileName::path(docfile->toChars());
if (*pt)
- FileName::ensurePathExists(pt);
+ FileName::ensurePathExists(pt);
mem.free(pt);
docfile->writev();
#endif
@@ -372,20 +372,20 @@ void Dsymbol::emitDitto(Scope *sc)
OutBuffer b;
b.writestring("$(DDOC_DITTO ");
- o = b.offset;
- toDocBuffer(&b);
- //printf("b: '%.*s'\n", b.offset, b.data);
- /* If 'this' is a function template, then highlightCode() was
- * already run by FuncDeclaration::toDocbuffer().
- */
- TemplateDeclaration *td;
- if (parent &&
- (td = parent->isTemplateDeclaration()) != NULL &&
- td->onemember == this)
- {
- }
- else
- highlightCode(sc, this, &b, o);
+ o = b.offset;
+ toDocBuffer(&b);
+ //printf("b: '%.*s'\n", b.offset, b.data);
+ /* If 'this' is a function template, then highlightCode() was
+ * already run by FuncDeclaration::toDocbuffer().
+ */
+ TemplateDeclaration *td;
+ if (parent &&
+ (td = parent->isTemplateDeclaration()) != NULL &&
+ td->onemember == this)
+ {
+ }
+ else
+ highlightCode(sc, this, &b, o);
b.writeByte(')');
buf->spread(sc->lastoffset, b.offset);
memcpy(buf->data + sc->lastoffset, b.data, b.offset);
@@ -398,38 +398,38 @@ void ScopeDsymbol::emitMemberComments(Scope *sc)
OutBuffer *buf = sc->docbuf;
if (members)
- { const char *m = "$(DDOC_MEMBERS \n";
+ { const char *m = "$(DDOC_MEMBERS \n";
- if (isModule())
- m = "$(DDOC_MODULE_MEMBERS \n";
- else if (isClassDeclaration())
- m = "$(DDOC_CLASS_MEMBERS \n";
- else if (isStructDeclaration())
- m = "$(DDOC_STRUCT_MEMBERS \n";
- else if (isEnumDeclaration())
- m = "$(DDOC_ENUM_MEMBERS \n";
- else if (isTemplateDeclaration())
- m = "$(DDOC_TEMPLATE_MEMBERS \n";
+ if (isModule())
+ m = "$(DDOC_MODULE_MEMBERS \n";
+ else if (isClassDeclaration())
+ m = "$(DDOC_CLASS_MEMBERS \n";
+ else if (isStructDeclaration())
+ m = "$(DDOC_STRUCT_MEMBERS \n";
+ else if (isEnumDeclaration())
+ m = "$(DDOC_ENUM_MEMBERS \n";
+ else if (isTemplateDeclaration())
+ m = "$(DDOC_TEMPLATE_MEMBERS \n";
- unsigned offset1 = buf->offset; // save starting offset
- buf->writestring(m);
- unsigned offset2 = buf->offset; // to see if we write anything
- sc = sc->push(this);
- for (int i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- //printf("\ts = '%s'\n", s->toChars());
- s->emitComment(sc);
- }
- sc->pop();
- if (buf->offset == offset2)
- {
- /* Didn't write out any members, so back out last write
- */
- buf->offset = offset1;
- }
- else
- buf->writestring(")\n");
+ unsigned offset1 = buf->offset; // save starting offset
+ buf->writestring(m);
+ unsigned offset2 = buf->offset; // to see if we write anything
+ sc = sc->push(this);
+ for (int i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ //printf("\ts = '%s'\n", s->toChars());
+ s->emitComment(sc);
+ }
+ sc->pop();
+ if (buf->offset == offset2)
+ {
+ /* Didn't write out any members, so back out last write
+ */
+ buf->offset = offset1;
+ }
+ else
+ buf->writestring(")\n");
}
}
@@ -439,21 +439,21 @@ void emitProtection(OutBuffer *buf, PROT prot)
switch (prot)
{
- case PROTpackage: p = "package"; break;
- case PROTprotected: p = "protected"; break;
- case PROTexport: p = "export"; break;
- default: p = NULL; break;
+ case PROTpackage: p = "package"; break;
+ case PROTprotected: p = "protected"; break;
+ case PROTexport: p = "export"; break;
+ default: p = NULL; break;
}
if (p)
- buf->printf("%s ", p);
+ buf->printf("%s ", p);
}
-void Dsymbol::emitComment(Scope *sc) { }
+void Dsymbol::emitComment(Scope *sc) { }
void InvariantDeclaration::emitComment(Scope *sc) { }
#if DMDV2
void PostBlitDeclaration::emitComment(Scope *sc) { }
#endif
-void DtorDeclaration::emitComment(Scope *sc) { }
+void DtorDeclaration::emitComment(Scope *sc) { }
void StaticCtorDeclaration::emitComment(Scope *sc) { }
void StaticDtorDeclaration::emitComment(Scope *sc) { }
void ClassInfoDeclaration::emitComment(Scope *sc) { }
@@ -467,10 +467,10 @@ void Declaration::emitComment(Scope *sc)
//printf("type = %p\n", type);
if (protection == PROTprivate || !ident ||
- (!type && !isCtorDeclaration() && !isAliasDeclaration()))
- return;
+ (!type && !isCtorDeclaration() && !isAliasDeclaration()))
+ return;
if (!comment)
- return;
+ return;
OutBuffer *buf = sc->docbuf;
DocComment *dc = DocComment::parse(sc, this, comment);
@@ -478,16 +478,16 @@ void Declaration::emitComment(Scope *sc)
if (!dc)
{
- emitDitto(sc);
- return;
+ emitDitto(sc);
+ return;
}
dc->pmacrotable = &sc->module->macrotable;
buf->writestring(ddoc_decl_s);
- o = buf->offset;
- toDocBuffer(buf);
- highlightCode(sc, this, buf, o);
- sc->lastoffset = buf->offset;
+ o = buf->offset;
+ toDocBuffer(buf);
+ highlightCode(sc, this, buf, o);
+ sc->lastoffset = buf->offset;
buf->writestring(ddoc_decl_e);
buf->writestring(ddoc_decl_dd_s);
@@ -499,17 +499,17 @@ void AggregateDeclaration::emitComment(Scope *sc)
{
//printf("AggregateDeclaration::emitComment() '%s'\n", toChars());
if (prot() == PROTprivate)
- return;
+ return;
if (!comment)
- return;
+ return;
OutBuffer *buf = sc->docbuf;
DocComment *dc = DocComment::parse(sc, this, comment);
if (!dc)
{
- emitDitto(sc);
- return;
+ emitDitto(sc);
+ return;
}
dc->pmacrotable = &sc->module->macrotable;
@@ -528,7 +528,7 @@ void TemplateDeclaration::emitComment(Scope *sc)
{
//printf("TemplateDeclaration::emitComment() '%s', kind = %s\n", toChars(), kind());
if (prot() == PROTprivate)
- return;
+ return;
unsigned char *com = comment;
int hasmembers = 1;
@@ -537,22 +537,22 @@ void TemplateDeclaration::emitComment(Scope *sc)
if (onemember)
{
- ss = onemember->isAggregateDeclaration();
- if (!ss)
- {
- ss = onemember->isFuncDeclaration();
- if (ss)
- { hasmembers = 0;
- if (com != ss->comment)
- com = Lexer::combineComments(com, ss->comment);
- }
- else
- ss = this;
- }
+ ss = onemember->isAggregateDeclaration();
+ if (!ss)
+ {
+ ss = onemember->isFuncDeclaration();
+ if (ss)
+ { hasmembers = 0;
+ if (com != ss->comment)
+ com = Lexer::combineComments(com, ss->comment);
+ }
+ else
+ ss = this;
+ }
}
if (!com)
- return;
+ return;
OutBuffer *buf = sc->docbuf;
DocComment *dc = DocComment::parse(sc, this, com);
@@ -560,59 +560,59 @@ void TemplateDeclaration::emitComment(Scope *sc)
if (!dc)
{
- ss->emitDitto(sc);
- return;
+ ss->emitDitto(sc);
+ return;
}
dc->pmacrotable = &sc->module->macrotable;
buf->writestring(ddoc_decl_s);
- o = buf->offset;
- ss->toDocBuffer(buf);
- if (ss == this)
- highlightCode(sc, this, buf, o);
- sc->lastoffset = buf->offset;
+ o = buf->offset;
+ ss->toDocBuffer(buf);
+ if (ss == this)
+ highlightCode(sc, this, buf, o);
+ sc->lastoffset = buf->offset;
buf->writestring(ddoc_decl_e);
buf->writestring(ddoc_decl_dd_s);
dc->writeSections(sc, this, buf);
if (hasmembers)
- ((ScopeDsymbol *)ss)->emitMemberComments(sc);
+ ((ScopeDsymbol *)ss)->emitMemberComments(sc);
buf->writestring(ddoc_decl_dd_e);
}
void EnumDeclaration::emitComment(Scope *sc)
{
if (prot() == PROTprivate)
- return;
+ return;
// if (!comment)
- { if (isAnonymous() && members)
- {
- for (int i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->emitComment(sc);
- }
- return;
- }
+ { if (isAnonymous() && members)
+ {
+ for (int i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->emitComment(sc);
+ }
+ return;
+ }
}
if (!comment)
- return;
+ return;
if (isAnonymous())
- return;
+ return;
OutBuffer *buf = sc->docbuf;
DocComment *dc = DocComment::parse(sc, this, comment);
if (!dc)
{
- emitDitto(sc);
- return;
+ emitDitto(sc);
+ return;
}
dc->pmacrotable = &sc->module->macrotable;
buf->writestring(ddoc_decl_s);
- toDocBuffer(buf);
- sc->lastoffset = buf->offset;
+ toDocBuffer(buf);
+ sc->lastoffset = buf->offset;
buf->writestring(ddoc_decl_e);
buf->writestring(ddoc_decl_dd_s);
@@ -625,9 +625,9 @@ void EnumMember::emitComment(Scope *sc)
{
//printf("EnumMember::emitComment(%p '%s'), comment = '%s'\n", this, toChars(), comment);
if (prot() == PROTprivate)
- return;
+ return;
if (!comment)
- return;
+ return;
OutBuffer *buf = sc->docbuf;
DocComment *dc = DocComment::parse(sc, this, comment);
@@ -635,16 +635,16 @@ void EnumMember::emitComment(Scope *sc)
if (!dc)
{
- emitDitto(sc);
- return;
+ emitDitto(sc);
+ return;
}
dc->pmacrotable = &sc->module->macrotable;
buf->writestring(ddoc_decl_s);
- o = buf->offset;
- toDocBuffer(buf);
- highlightCode(sc, this, buf, o);
- sc->lastoffset = buf->offset;
+ o = buf->offset;
+ toDocBuffer(buf);
+ highlightCode(sc, this, buf, o);
+ sc->lastoffset = buf->offset;
buf->writestring(ddoc_decl_e);
buf->writestring(ddoc_decl_dd_s);
@@ -666,25 +666,25 @@ void Dsymbol::toDocBuffer(OutBuffer *buf)
void prefix(OutBuffer *buf, Dsymbol *s)
{
if (s->isDeprecated())
- buf->writestring("deprecated ");
+ buf->writestring("deprecated ");
Declaration *d = s->isDeclaration();
if (d)
{
- emitProtection(buf, d->protection);
- if (d->isAbstract())
- buf->writestring("abstract ");
- if (d->isStatic())
- buf->writestring("static ");
- if (d->isConst())
- buf->writestring("const ");
+ emitProtection(buf, d->protection);
+ if (d->isAbstract())
+ buf->writestring("abstract ");
+ if (d->isStatic())
+ buf->writestring("static ");
+ if (d->isConst())
+ buf->writestring("const ");
#if DMDV2
- if (d->isImmutable())
- buf->writestring("immutable ");
+ if (d->isImmutable())
+ buf->writestring("immutable ");
#endif
- if (d->isFinal())
- buf->writestring("final ");
- if (d->isSynchronized())
- buf->writestring("synchronized ");
+ if (d->isFinal())
+ buf->writestring("final ");
+ if (d->isSynchronized())
+ buf->writestring("synchronized ");
}
}
@@ -693,21 +693,21 @@ void Declaration::toDocBuffer(OutBuffer *buf)
//printf("Declaration::toDocbuffer() %s, originalType = %p\n", toChars(), originalType);
if (ident)
{
- prefix(buf, this);
+ prefix(buf, this);
- if (type)
- { HdrGenState hgs;
- hgs.ddoc = 1;
- if (originalType)
- { //originalType->print();
- originalType->toCBuffer(buf, ident, &hgs);
- }
- else
- type->toCBuffer(buf, ident, &hgs);
- }
- else
- buf->writestring(ident->toChars());
- buf->writestring(";\n");
+ if (type)
+ { HdrGenState hgs;
+ hgs.ddoc = 1;
+ if (originalType)
+ { //originalType->print();
+ originalType->toCBuffer(buf, ident, &hgs);
+ }
+ else
+ type->toCBuffer(buf, ident, &hgs);
+ }
+ else
+ buf->writestring(ident->toChars());
+ buf->writestring(";\n");
}
}
@@ -717,13 +717,13 @@ void AliasDeclaration::toDocBuffer(OutBuffer *buf)
//printf("AliasDeclaration::toDocbuffer() %s\n", toChars());
if (ident)
{
- if (isDeprecated())
- buf->writestring("deprecated ");
+ if (isDeprecated())
+ buf->writestring("deprecated ");
- emitProtection(buf, protection);
- buf->writestring("alias ");
- buf->writestring(toChars());
- buf->writestring(";\n");
+ emitProtection(buf, protection);
+ buf->writestring("alias ");
+ buf->writestring(toChars());
+ buf->writestring(";\n");
}
}
@@ -732,13 +732,13 @@ void TypedefDeclaration::toDocBuffer(OutBuffer *buf)
{
if (ident)
{
- if (isDeprecated())
- buf->writestring("deprecated ");
+ if (isDeprecated())
+ buf->writestring("deprecated ");
- emitProtection(buf, protection);
- buf->writestring("typedef ");
- buf->writestring(toChars());
- buf->writestring(";\n");
+ emitProtection(buf, protection);
+ buf->writestring("typedef ");
+ buf->writestring(toChars());
+ buf->writestring(";\n");
}
}
@@ -748,40 +748,40 @@ void FuncDeclaration::toDocBuffer(OutBuffer *buf)
//printf("FuncDeclaration::toDocbuffer() %s\n", toChars());
if (ident)
{
- TemplateDeclaration *td;
+ TemplateDeclaration *td;
- if (parent &&
- (td = parent->isTemplateDeclaration()) != NULL &&
- td->onemember == this)
- { /* It's a function template
- */
- HdrGenState hgs;
- unsigned o = buf->offset;
- TypeFunction *tf = (TypeFunction *)type;
+ if (parent &&
+ (td = parent->isTemplateDeclaration()) != NULL &&
+ td->onemember == this)
+ { /* It's a function template
+ */
+ HdrGenState hgs;
+ unsigned o = buf->offset;
+ TypeFunction *tf = (TypeFunction *)type;
- hgs.ddoc = 1;
- prefix(buf, td);
- tf->next->toCBuffer(buf, NULL, &hgs);
- buf->writeByte(' ');
- buf->writestring(ident->toChars());
- buf->writeByte('(');
- for (int i = 0; i < td->origParameters->dim; i++)
- {
- TemplateParameter *tp = (TemplateParameter *)td->origParameters->data[i];
- if (i)
- buf->writestring(", ");
- tp->toCBuffer(buf, &hgs);
- }
- buf->writeByte(')');
- Parameter::argsToCBuffer(buf, &hgs, tf->parameters, tf->varargs);
- buf->writestring(";\n");
+ hgs.ddoc = 1;
+ prefix(buf, td);
+ tf->next->toCBuffer(buf, NULL, &hgs);
+ buf->writeByte(' ');
+ buf->writestring(ident->toChars());
+ buf->writeByte('(');
+ for (int i = 0; i < td->origParameters->dim; i++)
+ {
+ TemplateParameter *tp = (TemplateParameter *)td->origParameters->data[i];
+ if (i)
+ buf->writestring(", ");
+ tp->toCBuffer(buf, &hgs);
+ }
+ buf->writeByte(')');
+ Parameter::argsToCBuffer(buf, &hgs, tf->parameters, tf->varargs);
+ buf->writestring(";\n");
- highlightCode(NULL, this, buf, o);
- }
- else
- {
- Declaration::toDocBuffer(buf);
- }
+ highlightCode(NULL, this, buf, o);
+ }
+ else
+ {
+ Declaration::toDocBuffer(buf);
+ }
}
}
@@ -800,10 +800,10 @@ void AggregateDeclaration::toDocBuffer(OutBuffer *buf)
if (ident)
{
#if 0
- emitProtection(buf, protection);
+ emitProtection(buf, protection);
#endif
- buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
- buf->writestring(";\n");
+ buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
+ buf->writestring(";\n");
}
}
@@ -813,22 +813,22 @@ void StructDeclaration::toDocBuffer(OutBuffer *buf)
if (ident)
{
#if 0
- emitProtection(buf, protection);
+ emitProtection(buf, protection);
#endif
- TemplateDeclaration *td;
+ TemplateDeclaration *td;
- if (parent &&
- (td = parent->isTemplateDeclaration()) != NULL &&
- td->onemember == this)
- { unsigned o = buf->offset;
- td->toDocBuffer(buf);
- highlightCode(NULL, this, buf, o);
- }
- else
- {
- buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
- }
- buf->writestring(";\n");
+ if (parent &&
+ (td = parent->isTemplateDeclaration()) != NULL &&
+ td->onemember == this)
+ { unsigned o = buf->offset;
+ td->toDocBuffer(buf);
+ highlightCode(NULL, this, buf, o);
+ }
+ else
+ {
+ buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
+ }
+ buf->writestring(";\n");
}
}
@@ -838,50 +838,50 @@ void ClassDeclaration::toDocBuffer(OutBuffer *buf)
if (ident)
{
#if 0
- emitProtection(buf, protection);
+ emitProtection(buf, protection);
#endif
- TemplateDeclaration *td;
+ TemplateDeclaration *td;
- if (parent &&
- (td = parent->isTemplateDeclaration()) != NULL &&
- td->onemember == this)
- { unsigned o = buf->offset;
- td->toDocBuffer(buf);
- highlightCode(NULL, this, buf, o);
- }
- else
- {
- if (isAbstract())
- buf->writestring("abstract ");
- buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
- }
- int any = 0;
- for (int i = 0; i < baseclasses.dim; i++)
- { BaseClass *bc = (BaseClass *)baseclasses.data[i];
+ if (parent &&
+ (td = parent->isTemplateDeclaration()) != NULL &&
+ td->onemember == this)
+ { unsigned o = buf->offset;
+ td->toDocBuffer(buf);
+ highlightCode(NULL, this, buf, o);
+ }
+ else
+ {
+ if (isAbstract())
+ buf->writestring("abstract ");
+ buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
+ }
+ int any = 0;
+ for (int i = 0; i < baseclasses.dim; i++)
+ { BaseClass *bc = (BaseClass *)baseclasses.data[i];
- if (bc->protection == PROTprivate)
- continue;
- if (bc->base && bc->base->ident == Id::Object)
- continue;
+ if (bc->protection == PROTprivate)
+ continue;
+ if (bc->base && bc->base->ident == Id::Object)
+ continue;
- if (any)
- buf->writestring(", ");
- else
- { buf->writestring(": ");
- any = 1;
- }
- emitProtection(buf, bc->protection);
- if (bc->base)
- {
- buf->writestring(bc->base->toPrettyChars());
- }
- else
- {
- HdrGenState hgs;
- bc->type->toCBuffer(buf, NULL, &hgs);
- }
- }
- buf->writestring(";\n");
+ if (any)
+ buf->writestring(", ");
+ else
+ { buf->writestring(": ");
+ any = 1;
+ }
+ emitProtection(buf, bc->protection);
+ if (bc->base)
+ {
+ buf->writestring(bc->base->toPrettyChars());
+ }
+ else
+ {
+ HdrGenState hgs;
+ bc->type->toCBuffer(buf, NULL, &hgs);
+ }
+ }
+ buf->writestring(";\n");
}
}
@@ -890,8 +890,8 @@ void EnumDeclaration::toDocBuffer(OutBuffer *buf)
{
if (ident)
{
- buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
- buf->writestring(";\n");
+ buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
+ buf->writestring(";\n");
}
}
@@ -899,7 +899,7 @@ void EnumMember::toDocBuffer(OutBuffer *buf)
{
if (ident)
{
- buf->writestring(toChars());
+ buf->writestring(toChars());
}
}
@@ -916,25 +916,25 @@ DocComment *DocComment::parse(Scope *sc, Dsymbol *s, unsigned char *comment)
//printf("parse(%s): '%s'\n", s->toChars(), comment);
if (sc->lastdc && isDitto(comment))
- return NULL;
+ return NULL;
DocComment *dc = new DocComment();
if (!comment)
- return dc;
+ return dc;
dc->parseSections(comment);
for (int i = 0; i < dc->sections.dim; i++)
- { Section *s = (Section *)dc->sections.data[i];
+ { Section *s = (Section *)dc->sections.data[i];
- if (icmp("copyright", s->name, s->namelen) == 0)
- {
- dc->copyright = s;
- }
- if (icmp("macros", s->name, s->namelen) == 0)
- {
- dc->macros = s;
- }
+ if (icmp("copyright", s->name, s->namelen) == 0)
+ {
+ dc->copyright = s;
+ }
+ if (icmp("macros", s->name, s->namelen) == 0)
+ {
+ dc->macros = s;
+ }
}
sc->lastdc = dc;
@@ -963,103 +963,103 @@ void DocComment::parseSections(unsigned char *comment)
p = comment;
while (*p)
{
- p = skipwhitespace(p);
- pstart = p;
- pend = p;
+ p = skipwhitespace(p);
+ pstart = p;
+ pend = p;
- /* Find end of section, which is ended by one of:
- * 'identifier:' (but not inside a code section)
- * '\0'
- */
- idlen = 0;
- int inCode = 0;
- while (1)
- {
- // Check for start/end of a code section
- if (*p == '-')
- {
- int numdash = 0;
- while (*p == '-')
- {
- ++numdash;
- p++;
- }
- // BUG: handle UTF PS and LS too
- if (!*p || *p == '\r' || *p == '\n' && numdash >= 3)
- inCode ^= 1;
- pend = p;
- }
+ /* Find end of section, which is ended by one of:
+ * 'identifier:' (but not inside a code section)
+ * '\0'
+ */
+ idlen = 0;
+ int inCode = 0;
+ while (1)
+ {
+ // Check for start/end of a code section
+ if (*p == '-')
+ {
+ int numdash = 0;
+ while (*p == '-')
+ {
+ ++numdash;
+ p++;
+ }
+ // BUG: handle UTF PS and LS too
+ if (!*p || *p == '\r' || *p == '\n' && numdash >= 3)
+ inCode ^= 1;
+ pend = p;
+ }
- if (!inCode && isIdStart(p))
- {
- unsigned char *q = p + utfStride(p);
- while (isIdTail(q))
- q += utfStride(q);
- if (*q == ':') // identifier: ends it
- { idlen = q - p;
- idstart = p;
- for (pend = p; pend > pstart; pend--)
- { if (pend[-1] == '\n')
- break;
- }
- p = q + 1;
- break;
- }
- }
- while (1)
- {
- if (!*p)
- goto L1;
- if (*p == '\n')
- { p++;
- if (*p == '\n' && !summary && !namelen)
- {
- pend = p;
- p++;
- goto L1;
- }
- break;
- }
- p++;
- pend = p;
- }
- p = skipwhitespace(p);
- }
+ if (!inCode && isIdStart(p))
+ {
+ unsigned char *q = p + utfStride(p);
+ while (isIdTail(q))
+ q += utfStride(q);
+ if (*q == ':') // identifier: ends it
+ { idlen = q - p;
+ idstart = p;
+ for (pend = p; pend > pstart; pend--)
+ { if (pend[-1] == '\n')
+ break;
+ }
+ p = q + 1;
+ break;
+ }
+ }
+ while (1)
+ {
+ if (!*p)
+ goto L1;
+ if (*p == '\n')
+ { p++;
+ if (*p == '\n' && !summary && !namelen)
+ {
+ pend = p;
+ p++;
+ goto L1;
+ }
+ break;
+ }
+ p++;
+ pend = p;
+ }
+ p = skipwhitespace(p);
+ }
L1:
- if (namelen || pstart < pend)
- {
- Section *s;
- if (icmp("Params", name, namelen) == 0)
- s = new ParamSection();
- else if (icmp("Macros", name, namelen) == 0)
- s = new MacroSection();
- else
- s = new Section();
- s->name = name;
- s->namelen = namelen;
- s->body = pstart;
- s->bodylen = pend - pstart;
- s->nooutput = 0;
+ if (namelen || pstart < pend)
+ {
+ Section *s;
+ if (icmp("Params", name, namelen) == 0)
+ s = new ParamSection();
+ else if (icmp("Macros", name, namelen) == 0)
+ s = new MacroSection();
+ else
+ s = new Section();
+ s->name = name;
+ s->namelen = namelen;
+ s->body = pstart;
+ s->bodylen = pend - pstart;
+ s->nooutput = 0;
- //printf("Section: '%.*s' = '%.*s'\n", s->namelen, s->name, s->bodylen, s->body);
+ //printf("Section: '%.*s' = '%.*s'\n", s->namelen, s->name, s->bodylen, s->body);
- sections.push(s);
+ sections.push(s);
- if (!summary && !namelen)
- summary = s;
- }
+ if (!summary && !namelen)
+ summary = s;
+ }
- if (idlen)
- { name = idstart;
- namelen = idlen;
- }
- else
- { name = NULL;
- namelen = 0;
- if (!*p)
- break;
- }
+ if (idlen)
+ { name = idstart;
+ namelen = idlen;
+ }
+ else
+ { name = NULL;
+ namelen = 0;
+ if (!*p)
+ break;
+ }
}
}
@@ -1068,29 +1068,29 @@ void DocComment::writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf)
//printf("DocComment::writeSections()\n");
if (sections.dim)
{
- buf->writestring("$(DDOC_SECTIONS \n");
- for (int i = 0; i < sections.dim; i++)
- { Section *sec = (Section *)sections.data[i];
+ buf->writestring("$(DDOC_SECTIONS \n");
+ for (int i = 0; i < sections.dim; i++)
+ { Section *sec = (Section *)sections.data[i];
- if (sec->nooutput)
- continue;
- //printf("Section: '%.*s' = '%.*s'\n", sec->namelen, sec->name, sec->bodylen, sec->body);
- if (sec->namelen || i)
- sec->write(this, sc, s, buf);
- else
- {
- buf->writestring("$(DDOC_SUMMARY ");
- unsigned o = buf->offset;
- buf->write(sec->body, sec->bodylen);
- highlightText(sc, s, buf, o);
- buf->writestring(")\n");
- }
- }
- buf->writestring(")\n");
+ if (sec->nooutput)
+ continue;
+ //printf("Section: '%.*s' = '%.*s'\n", sec->namelen, sec->name, sec->bodylen, sec->body);
+ if (sec->namelen || i)
+ sec->write(this, sc, s, buf);
+ else
+ {
+ buf->writestring("$(DDOC_SUMMARY ");
+ unsigned o = buf->offset;
+ buf->write(sec->body, sec->bodylen);
+ highlightText(sc, s, buf, o);
+ buf->writestring(")\n");
+ }
+ }
+ buf->writestring(")\n");
}
else
{
- buf->writestring("$(DDOC_BLANKLINE)\n");
+ buf->writestring("$(DDOC_BLANKLINE)\n");
}
}
@@ -1101,33 +1101,33 @@ void Section::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
{
if (namelen)
{
- static const char *table[] =
- { "AUTHORS", "BUGS", "COPYRIGHT", "DATE",
- "DEPRECATED", "EXAMPLES", "HISTORY", "LICENSE",
- "RETURNS", "SEE_ALSO", "STANDARDS", "THROWS",
- "VERSION" };
+ static const char *table[] =
+ { "AUTHORS", "BUGS", "COPYRIGHT", "DATE",
+ "DEPRECATED", "EXAMPLES", "HISTORY", "LICENSE",
+ "RETURNS", "SEE_ALSO", "STANDARDS", "THROWS",
+ "VERSION" };
- for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++)
- {
- if (icmp(table[i], name, namelen) == 0)
- {
- buf->printf("$(DDOC_%s ", table[i]);
- goto L1;
- }
- }
+ for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++)
+ {
+ if (icmp(table[i], name, namelen) == 0)
+ {
+ buf->printf("$(DDOC_%s ", table[i]);
+ goto L1;
+ }
+ }
- buf->writestring("$(DDOC_SECTION ");
- // Replace _ characters with spaces
- buf->writestring("$(DDOC_SECTION_H ");
- for (unsigned u = 0; u < namelen; u++)
- { unsigned char c = name[u];
- buf->writeByte((c == '_') ? ' ' : c);
- }
- buf->writestring(":)\n");
+ buf->writestring("$(DDOC_SECTION ");
+ // Replace _ characters with spaces
+ buf->writestring("$(DDOC_SECTION_H ");
+ for (unsigned u = 0; u < namelen; u++)
+ { unsigned char c = name[u];
+ buf->writeByte((c == '_') ? ' ' : c);
+ }
+ buf->writestring(":)\n");
}
else
{
- buf->writestring("$(DDOC_DESCRIPTION ");
+ buf->writestring("$(DDOC_DESCRIPTION ");
}
L1:
unsigned o = buf->offset;
@@ -1149,7 +1149,7 @@ void ParamSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
unsigned templen;
unsigned char *namestart;
- unsigned namelen = 0; // !=0 if line continuation
+ unsigned namelen = 0; // !=0 if line continuation
unsigned char *textstart;
unsigned textlen;
@@ -1160,96 +1160,96 @@ void ParamSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
buf->writestring("$(DDOC_PARAMS \n");
while (p < pend)
{
- // Skip to start of macro
- while (1)
- {
- switch (*p)
- {
- case ' ':
- case '\t':
- p++;
- continue;
+ // Skip to start of macro
+ while (1)
+ {
+ switch (*p)
+ {
+ case ' ':
+ case '\t':
+ p++;
+ continue;
- case '\n':
- p++;
- goto Lcont;
+ case '\n':
+ p++;
+ goto Lcont;
- default:
- if (isIdStart(p))
- break;
- if (namelen)
- goto Ltext; // continuation of prev macro
- goto Lskipline;
- }
- break;
- }
- tempstart = p;
+ default:
+ if (isIdStart(p))
+ break;
+ if (namelen)
+ goto Ltext; // continuation of prev macro
+ goto Lskipline;
+ }
+ break;
+ }
+ tempstart = p;
- while (isIdTail(p))
- p += utfStride(p);
- templen = p - tempstart;
+ while (isIdTail(p))
+ p += utfStride(p);
+ templen = p - tempstart;
- while (*p == ' ' || *p == '\t')
- p++;
+ while (*p == ' ' || *p == '\t')
+ p++;
- if (*p != '=')
- { if (namelen)
- goto Ltext; // continuation of prev macro
- goto Lskipline;
- }
- p++;
+ if (*p != '=')
+ { if (namelen)
+ goto Ltext; // continuation of prev macro
+ goto Lskipline;
+ }
+ p++;
- if (namelen)
- { // Output existing param
+ if (namelen)
+ { // Output existing param
- L1:
- //printf("param '%.*s' = '%.*s'\n", namelen, namestart, textlen, textstart);
- HdrGenState hgs;
- buf->writestring("$(DDOC_PARAM_ROW ");
- buf->writestring("$(DDOC_PARAM_ID ");
- o = buf->offset;
- arg = isFunctionParameter(s, namestart, namelen);
- if (arg && arg->type && arg->ident)
- arg->type->toCBuffer(buf, arg->ident, &hgs);
- else
- buf->write(namestart, namelen);
- highlightCode(sc, s, buf, o);
- buf->writestring(")\n");
+ L1:
+ //printf("param '%.*s' = '%.*s'\n", namelen, namestart, textlen, textstart);
+ HdrGenState hgs;
+ buf->writestring("$(DDOC_PARAM_ROW ");
+ buf->writestring("$(DDOC_PARAM_ID ");
+ o = buf->offset;
+ arg = isFunctionParameter(s, namestart, namelen);
+ if (arg && arg->type && arg->ident)
+ arg->type->toCBuffer(buf, arg->ident, &hgs);
+ else
+ buf->write(namestart, namelen);
+ highlightCode(sc, s, buf, o);
+ buf->writestring(")\n");
- buf->writestring("$(DDOC_PARAM_DESC ");
- o = buf->offset;
- buf->write(textstart, textlen);
- highlightText(sc, s, buf, o);
- buf->writestring(")");
- buf->writestring(")\n");
- namelen = 0;
- if (p >= pend)
- break;
- }
+ buf->writestring("$(DDOC_PARAM_DESC ");
+ o = buf->offset;
+ buf->write(textstart, textlen);
+ highlightText(sc, s, buf, o);
+ buf->writestring(")");
+ buf->writestring(")\n");
+ namelen = 0;
+ if (p >= pend)
+ break;
+ }
- namestart = tempstart;
- namelen = templen;
+ namestart = tempstart;
+ namelen = templen;
- while (*p == ' ' || *p == '\t')
- p++;
- textstart = p;
+ while (*p == ' ' || *p == '\t')
+ p++;
+ textstart = p;
Ltext:
- while (*p != '\n')
- p++;
- textlen = p - textstart;
- p++;
+ while (*p != '\n')
+ p++;
+ textlen = p - textstart;
+ p++;
Lcont:
- continue;
+ continue;
Lskipline:
- // Ignore this line
- while (*p++ != '\n')
- ;
+ // Ignore this line
+ while (*p++ != '\n')
+ ;
}
if (namelen)
- goto L1; // write out last one
+ goto L1; // write out last one
buf->writestring(")\n");
}
@@ -1265,9 +1265,9 @@ void MacroSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
/************************************************
* Parse macros out of Macros: section.
* Macros are of the form:
- * name1 = value1
+ * name1 = value1
*
- * name2 = value2
+ * name2 = value2
*/
void DocComment::parseMacros(Escape **pescapetable, Macro **pmacrotable, unsigned char *m, unsigned mlen)
@@ -1280,116 +1280,116 @@ void DocComment::parseMacros(Escape **pescapetable, Macro **pmacrotable, unsigne
unsigned templen;
unsigned char *namestart;
- unsigned namelen = 0; // !=0 if line continuation
+ unsigned namelen = 0; // !=0 if line continuation
unsigned char *textstart;
unsigned textlen;
while (p < pend)
{
- // Skip to start of macro
- while (1)
- {
- if (p >= pend)
- goto Ldone;
- switch (*p)
- {
- case ' ':
- case '\t':
- p++;
- continue;
+ // Skip to start of macro
+ while (1)
+ {
+ if (p >= pend)
+ goto Ldone;
+ switch (*p)
+ {
+ case ' ':
+ case '\t':
+ p++;
+ continue;
- case '\n':
- p++;
- goto Lcont;
+ case '\n':
+ p++;
+ goto Lcont;
- default:
- if (isIdStart(p))
- break;
- if (namelen)
- goto Ltext; // continuation of prev macro
- goto Lskipline;
- }
- break;
- }
- tempstart = p;
+ default:
+ if (isIdStart(p))
+ break;
+ if (namelen)
+ goto Ltext; // continuation of prev macro
+ goto Lskipline;
+ }
+ break;
+ }
+ tempstart = p;
- while (1)
- {
- if (p >= pend)
- goto Ldone;
- if (!isIdTail(p))
- break;
- p += utfStride(p);
- }
- templen = p - tempstart;
+ while (1)
+ {
+ if (p >= pend)
+ goto Ldone;
+ if (!isIdTail(p))
+ break;
+ p += utfStride(p);
+ }
+ templen = p - tempstart;
- while (1)
- {
- if (p >= pend)
- goto Ldone;
- if (!(*p == ' ' || *p == '\t'))
- break;
- p++;
- }
+ while (1)
+ {
+ if (p >= pend)
+ goto Ldone;
+ if (!(*p == ' ' || *p == '\t'))
+ break;
+ p++;
+ }
- if (*p != '=')
- { if (namelen)
- goto Ltext; // continuation of prev macro
- goto Lskipline;
- }
- p++;
- if (p >= pend)
- goto Ldone;
+ if (*p != '=')
+ { if (namelen)
+ goto Ltext; // continuation of prev macro
+ goto Lskipline;
+ }
+ p++;
+ if (p >= pend)
+ goto Ldone;
- if (namelen)
- { // Output existing macro
- L1:
- //printf("macro '%.*s' = '%.*s'\n", namelen, namestart, textlen, textstart);
- if (icmp("ESCAPES", namestart, namelen) == 0)
- parseEscapes(pescapetable, textstart, textlen);
- else
- Macro::define(pmacrotable, namestart, namelen, textstart, textlen);
- namelen = 0;
- if (p >= pend)
- break;
- }
+ if (namelen)
+ { // Output existing macro
+ L1:
+ //printf("macro '%.*s' = '%.*s'\n", namelen, namestart, textlen, textstart);
+ if (icmp("ESCAPES", namestart, namelen) == 0)
+ parseEscapes(pescapetable, textstart, textlen);
+ else
+ Macro::define(pmacrotable, namestart, namelen, textstart, textlen);
+ namelen = 0;
+ if (p >= pend)
+ break;
+ }
- namestart = tempstart;
- namelen = templen;
+ namestart = tempstart;
+ namelen = templen;
- while (p < pend && (*p == ' ' || *p == '\t'))
- p++;
- textstart = p;
+ while (p < pend && (*p == ' ' || *p == '\t'))
+ p++;
+ textstart = p;
Ltext:
- while (p < pend && *p != '\n')
- p++;
- textlen = p - textstart;
+ while (p < pend && *p != '\n')
+ p++;
+ textlen = p - textstart;
- // Remove trailing \r if there is one
- if (p > m && p[-1] == '\r')
- textlen--;
+ // Remove trailing \r if there is one
+ if (p > m && p[-1] == '\r')
+ textlen--;
- p++;
- //printf("p = %p, pend = %p\n", p, pend);
+ p++;
+ //printf("p = %p, pend = %p\n", p, pend);
Lcont:
- continue;
+ continue;
Lskipline:
- // Ignore this line
- while (p < pend && *p++ != '\n')
- ;
+ // Ignore this line
+ while (p < pend && *p++ != '\n')
+ ;
}
Ldone:
if (namelen)
- goto L1; // write out last one
+ goto L1; // write out last one
}
/**************************************
* Parse escapes of the form:
- * /c/string/
+ * /c/string/
* where c is a single character.
* Multiple escapes can be separated
* by whitespace and/or commas.
@@ -1399,41 +1399,41 @@ void DocComment::parseEscapes(Escape **pescapetable, unsigned char *textstart, u
{ Escape *escapetable = *pescapetable;
if (!escapetable)
- { escapetable = new Escape;
- *pescapetable = escapetable;
+ { escapetable = new Escape;
+ *pescapetable = escapetable;
}
unsigned char *p = textstart;
unsigned char *pend = p + textlen;
while (1)
{
- while (1)
- {
- if (p + 4 >= pend)
- return;
- if (!(*p == ' ' || *p == '\t' || *p == '\n' || *p == ','))
- break;
- p++;
- }
- if (p[0] != '/' || p[2] != '/')
- return;
- unsigned char c = p[1];
- p += 3;
- unsigned char *start = p;
- while (1)
- {
- if (p >= pend)
- return;
- if (*p == '/')
- break;
- p++;
- }
- size_t len = p - start;
- char *s = (char *)memcpy(mem.malloc(len + 1), start, len);
- s[len] = 0;
- escapetable->strings[c] = s;
- //printf("%c = '%s'\n", c, s);
- p++;
+ while (1)
+ {
+ if (p + 4 >= pend)
+ return;
+ if (!(*p == ' ' || *p == '\t' || *p == '\n' || *p == ','))
+ break;
+ p++;
+ }
+ if (p[0] != '/' || p[2] != '/')
+ return;
+ unsigned char c = p[1];
+ p += 3;
+ unsigned char *start = p;
+ while (1)
+ {
+ if (p >= pend)
+ return;
+ if (*p == '/')
+ break;
+ p++;
+ }
+ size_t len = p - start;
+ char *s = (char *)memcpy(mem.malloc(len + 1), start, len);
+ s[len] = 0;
+ escapetable->strings[c] = s;
+ //printf("%c = '%s'\n", c, s);
+ p++;
}
}
@@ -1448,7 +1448,7 @@ int cmp(const char *stringz, void *s, size_t slen)
size_t len1 = strlen(stringz);
if (len1 != slen)
- return len1 - slen;
+ return len1 - slen;
return memcmp(stringz, s, slen);
}
@@ -1457,7 +1457,7 @@ int icmp(const char *stringz, void *s, size_t slen)
size_t len1 = strlen(stringz);
if (len1 != slen)
- return len1 - slen;
+ return len1 - slen;
return memicmp(stringz, (char *)s, slen);
}
@@ -1469,10 +1469,10 @@ int isDitto(unsigned char *comment)
{
if (comment)
{
- unsigned char *p = skipwhitespace(comment);
+ unsigned char *p = skipwhitespace(comment);
- if (memicmp((char *)p, "ditto", 5) == 0 && *skipwhitespace(p + 5) == 0)
- return 1;
+ if (memicmp((char *)p, "ditto", 5) == 0 && *skipwhitespace(p + 5) == 0)
+ return 1;
}
return 0;
}
@@ -1484,14 +1484,14 @@ int isDitto(unsigned char *comment)
unsigned char *skipwhitespace(unsigned char *p)
{
for (; 1; p++)
- { switch (*p)
- {
- case ' ':
- case '\t':
- case '\n':
- continue;
- }
- break;
+ { switch (*p)
+ {
+ case ' ':
+ case '\t':
+ case '\n':
+ continue;
+ }
+ break;
}
return p;
}
@@ -1499,30 +1499,30 @@ unsigned char *skipwhitespace(unsigned char *p)
/************************************************
* Scan forward to one of:
- * start of identifier
- * beginning of next line
- * end of buf
+ * start of identifier
+ * beginning of next line
+ * end of buf
*/
unsigned skiptoident(OutBuffer *buf, size_t i)
{
while (i < buf->offset)
- { dchar_t c;
+ { dchar_t c;
- size_t oi = i;
- if (utf_decodeChar((unsigned char *)buf->data, buf->offset, &i, &c))
- /* Ignore UTF errors, but still consume input
- */
- break;
- if (c >= 0x80)
- {
- if (!isUniAlpha(c))
- continue;
- }
- else if (!(isalpha(c) || c == '_' || c == '\n'))
- continue;
- i = oi;
- break;
+ size_t oi = i;
+ if (utf_decodeChar((unsigned char *)buf->data, buf->offset, &i, &c))
+ /* Ignore UTF errors, but still consume input
+ */
+ break;
+ if (c >= 0x80)
+ {
+ if (!isUniAlpha(c))
+ continue;
+ }
+ else if (!(isalpha(c) || c == '_' || c == '\n'))
+ continue;
+ i = oi;
+ break;
}
return i;
}
@@ -1534,22 +1534,22 @@ unsigned skiptoident(OutBuffer *buf, size_t i)
unsigned skippastident(OutBuffer *buf, size_t i)
{
while (i < buf->offset)
- { dchar_t c;
+ { dchar_t c;
- size_t oi = i;
- if (utf_decodeChar((unsigned char *)buf->data, buf->offset, &i, &c))
- /* Ignore UTF errors, but still consume input
- */
- break;
- if (c >= 0x80)
- {
- if (isUniAlpha(c))
- continue;
- }
- else if (isalnum(c) || c == '_')
- continue;
- i = oi;
- break;
+ size_t oi = i;
+ if (utf_decodeChar((unsigned char *)buf->data, buf->offset, &i, &c))
+ /* Ignore UTF errors, but still consume input
+ */
+ break;
+ if (c >= 0x80)
+ {
+ if (isUniAlpha(c))
+ continue;
+ }
+ else if (isalnum(c) || c == '_')
+ continue;
+ i = oi;
+ break;
}
return i;
}
@@ -1559,8 +1559,8 @@ unsigned skippastident(OutBuffer *buf, size_t i)
* Scan forward past URL starting at i.
* We don't want to highlight parts of a URL.
* Returns:
- * i if not a URL
- * index just past it if it is a URL
+ * i if not a URL
+ * index just past it if it is a URL
*/
unsigned skippastURL(OutBuffer *buf, size_t i)
@@ -1571,19 +1571,19 @@ unsigned skippastURL(OutBuffer *buf, size_t i)
if (length > 7 && memicmp((char *)p, "http://", 7) == 0)
{
- j = 7;
+ j = 7;
}
else if (length > 8 && memicmp((char *)p, "https://", 8) == 0)
{
- j = 8;
+ j = 8;
}
else
- goto Lno;
+ goto Lno;
for (; j < length; j++)
- { unsigned char c = p[j];
- if (isalnum(c))
- continue;
+ { unsigned char c = p[j];
+ if (isalnum(c))
+ continue;
if (c == '-' || c == '_' || c == '?' ||
c == '=' || c == '%' || c == '&' ||
c == '/' || c == '+' || c == '#' ||
@@ -1597,7 +1597,7 @@ unsigned skippastURL(OutBuffer *buf, size_t i)
break;
}
if (sawdot)
- return i + j;
+ return i + j;
Lno:
return i;
@@ -1613,8 +1613,8 @@ int isKeyword(unsigned char *p, unsigned len)
for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++)
{
- if (cmp(table[i], p, len) == 0)
- return 1;
+ if (cmp(table[i], p, len) == 0)
+ return 1;
}
return 0;
}
@@ -1630,25 +1630,25 @@ Parameter *isFunctionParameter(Dsymbol *s, unsigned char *p, unsigned len)
*/
if (f && f->type)
{
- TypeFunction *tf;
- if (f->originalType)
- {
- tf = (TypeFunction *)f->originalType;
- }
- else
- tf = (TypeFunction *)f->type;
+ TypeFunction *tf;
+ if (f->originalType)
+ {
+ tf = (TypeFunction *)f->originalType;
+ }
+ else
+ tf = (TypeFunction *)f->type;
- if (tf->parameters)
- {
- for (size_t k = 0; k < tf->parameters->dim; k++)
- { Parameter *arg = (Parameter *)tf->parameters->data[k];
+ if (tf->parameters)
+ {
+ for (size_t k = 0; k < tf->parameters->dim; k++)
+ { Parameter *arg = (Parameter *)tf->parameters->data[k];
- if (arg->ident && cmp(arg->ident->toChars(), p, len) == 0)
- {
- return arg;
- }
- }
- }
+ if (arg->ident && cmp(arg->ident->toChars(), p, len) == 0)
+ {
+ return arg;
+ }
+ }
+ }
}
return NULL;
}
@@ -1667,238 +1667,238 @@ void highlightText(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
int leadingBlank = 1;
int inCode = 0;
- int inComment = 0; // in comment
- unsigned iCodeStart; // start of code section
+ int inComment = 0; // in comment
+ unsigned iCodeStart; // start of code section
unsigned iLineStart = offset;
for (unsigned i = offset; i < buf->offset; i++)
- { unsigned char c = buf->data[i];
+ { unsigned char c = buf->data[i];
Lcont:
- switch (c)
- {
- case ' ':
- case '\t':
- break;
+ switch (c)
+ {
+ case ' ':
+ case '\t':
+ break;
- case '\n':
- if (sc && !inCode && i == iLineStart && i + 1 < buf->offset) // if "\n\n"
- {
- static char blankline[] = "$(DDOC_BLANKLINE)\n";
+ case '\n':
+ if (sc && !inCode && i == iLineStart && i + 1 < buf->offset) // if "\n\n"
+ {
+ static char blankline[] = "$(DDOC_BLANKLINE)\n";
- i = buf->insert(i, blankline, sizeof(blankline) - 1);
- }
- leadingBlank = 1;
- iLineStart = i + 1;
- break;
+ i = buf->insert(i, blankline, sizeof(blankline) - 1);
+ }
+ leadingBlank = 1;
+ iLineStart = i + 1;
+ break;
- case '<':
- leadingBlank = 0;
- if (inCode)
- break;
- p = &buf->data[i];
+ case '<':
+ leadingBlank = 0;
+ if (inCode)
+ break;
+ p = &buf->data[i];
- // Skip over comments
- if (p[1] == '!' && p[2] == '-' && p[3] == '-')
- { unsigned j = i + 4;
- p += 4;
- while (1)
- {
- if (j == buf->offset)
- goto L1;
- if (p[0] == '-' && p[1] == '-' && p[2] == '>')
- {
- i = j + 2; // place on closing '>'
- break;
- }
- j++;
- p++;
- }
- break;
- }
+ // Skip over comments
+ if (p[1] == '!' && p[2] == '-' && p[3] == '-')
+ { unsigned j = i + 4;
+ p += 4;
+ while (1)
+ {
+ if (j == buf->offset)
+ goto L1;
+ if (p[0] == '-' && p[1] == '-' && p[2] == '>')
+ {
+ i = j + 2; // place on closing '>'
+ break;
+ }
+ j++;
+ p++;
+ }
+ break;
+ }
- // Skip over HTML tag
- if (isalpha(p[1]) || (p[1] == '/' && isalpha(p[2])))
- { unsigned j = i + 2;
- p += 2;
- while (1)
- {
- if (j == buf->offset)
- goto L1;
- if (p[0] == '>')
- {
- i = j; // place on closing '>'
- break;
- }
- j++;
- p++;
- }
- break;
- }
+ // Skip over HTML tag
+ if (isalpha(p[1]) || (p[1] == '/' && isalpha(p[2])))
+ { unsigned j = i + 2;
+ p += 2;
+ while (1)
+ {
+ if (j == buf->offset)
+ goto L1;
+ if (p[0] == '>')
+ {
+ i = j; // place on closing '>'
+ break;
+ }
+ j++;
+ p++;
+ }
+ break;
+ }
- L1:
- // Replace '<' with '<' character entity
- se = Escape::escapeChar('<');
- if (se)
- { size_t len = strlen(se);
- buf->remove(i, 1);
- i = buf->insert(i, se, len);
- i--; // point to ';'
- }
- break;
+ L1:
+ // Replace '<' with '<' character entity
+ se = Escape::escapeChar('<');
+ if (se)
+ { size_t len = strlen(se);
+ buf->remove(i, 1);
+ i = buf->insert(i, se, len);
+ i--; // point to ';'
+ }
+ break;
- case '>':
- leadingBlank = 0;
- if (inCode)
- break;
- // Replace '>' with '>' character entity
- se = Escape::escapeChar('>');
- if (se)
- { size_t len = strlen(se);
- buf->remove(i, 1);
- i = buf->insert(i, se, len);
- i--; // point to ';'
- }
- break;
+ case '>':
+ leadingBlank = 0;
+ if (inCode)
+ break;
+ // Replace '>' with '>' character entity
+ se = Escape::escapeChar('>');
+ if (se)
+ { size_t len = strlen(se);
+ buf->remove(i, 1);
+ i = buf->insert(i, se, len);
+ i--; // point to ';'
+ }
+ break;
- case '&':
- leadingBlank = 0;
- if (inCode)
- break;
- p = &buf->data[i];
- if (p[1] == '#' || isalpha(p[1]))
- break; // already a character entity
- // Replace '&' with '&' character entity
- se = Escape::escapeChar('&');
- if (se)
- { size_t len = strlen(se);
- buf->remove(i, 1);
- i = buf->insert(i, se, len);
- i--; // point to ';'
- }
- break;
+ case '&':
+ leadingBlank = 0;
+ if (inCode)
+ break;
+ p = &buf->data[i];
+ if (p[1] == '#' || isalpha(p[1]))
+ break; // already a character entity
+ // Replace '&' with '&' character entity
+ se = Escape::escapeChar('&');
+ if (se)
+ { size_t len = strlen(se);
+ buf->remove(i, 1);
+ i = buf->insert(i, se, len);
+ i--; // point to ';'
+ }
+ break;
- case '-':
- /* A line beginning with --- delimits a code section.
- * inCode tells us if it is start or end of a code section.
- */
- if (leadingBlank)
- { int istart = i;
- int eollen = 0;
+ case '-':
+ /* A line beginning with --- delimits a code section.
+ * inCode tells us if it is start or end of a code section.
+ */
+ if (leadingBlank)
+ { int istart = i;
+ int eollen = 0;
- leadingBlank = 0;
- while (1)
- {
- ++i;
- if (i >= buf->offset)
- break;
- c = buf->data[i];
- if (c == '\n')
- { eollen = 1;
- break;
- }
- if (c == '\r')
- {
- eollen = 1;
- if (i + 1 >= buf->offset)
- break;
- if (buf->data[i + 1] == '\n')
- { eollen = 2;
- break;
- }
- }
- // BUG: handle UTF PS and LS too
- if (c != '-')
- goto Lcont;
- }
- if (i - istart < 3)
- goto Lcont;
+ leadingBlank = 0;
+ while (1)
+ {
+ ++i;
+ if (i >= buf->offset)
+ break;
+ c = buf->data[i];
+ if (c == '\n')
+ { eollen = 1;
+ break;
+ }
+ if (c == '\r')
+ {
+ eollen = 1;
+ if (i + 1 >= buf->offset)
+ break;
+ if (buf->data[i + 1] == '\n')
+ { eollen = 2;
+ break;
+ }
+ }
+ // BUG: handle UTF PS and LS too
+ if (c != '-')
+ goto Lcont;
+ }
+ if (i - istart < 3)
+ goto Lcont;
- // We have the start/end of a code section
+ // We have the start/end of a code section
+
+ // Remove the entire --- line, including blanks and \n
+ buf->remove(iLineStart, i - iLineStart + eollen);
+ i = iLineStart;
- // Remove the entire --- line, including blanks and \n
- buf->remove(iLineStart, i - iLineStart + eollen);
- i = iLineStart;
-
if (inCode && (i <= iCodeStart))
{ // Empty code section, just remove it completely.
inCode = 0;
break;
}
-
- if (inCode)
- {
- inCode = 0;
- // The code section is from iCodeStart to i
- OutBuffer codebuf;
- codebuf.write(buf->data + iCodeStart, i - iCodeStart);
- codebuf.writeByte(0);
- highlightCode2(sc, s, &codebuf, 0);
- buf->remove(iCodeStart, i - iCodeStart);
- i = buf->insert(iCodeStart, codebuf.data, codebuf.offset);
- i = buf->insert(i, ")\n", 2);
- i--;
- }
- else
- { static char pre[] = "$(D_CODE \n";
+ if (inCode)
+ {
+ inCode = 0;
+ // The code section is from iCodeStart to i
+ OutBuffer codebuf;
- inCode = 1;
- i = buf->insert(i, pre, sizeof(pre) - 1);
- iCodeStart = i;
- i--; // place i on >
- leadingBlank = true;
- }
- }
- break;
+ codebuf.write(buf->data + iCodeStart, i - iCodeStart);
+ codebuf.writeByte(0);
+ highlightCode2(sc, s, &codebuf, 0);
+ buf->remove(iCodeStart, i - iCodeStart);
+ i = buf->insert(iCodeStart, codebuf.data, codebuf.offset);
+ i = buf->insert(i, ")\n", 2);
+ i--;
+ }
+ else
+ { static char pre[] = "$(D_CODE \n";
- default:
- leadingBlank = 0;
- if (sc && !inCode && isIdStart(&buf->data[i]))
- { unsigned j;
+ inCode = 1;
+ i = buf->insert(i, pre, sizeof(pre) - 1);
+ iCodeStart = i;
+ i--; // place i on >
+ leadingBlank = true;
+ }
+ }
+ break;
- j = skippastident(buf, i);
- if (j > i)
- {
- unsigned k = skippastURL(buf, i);
- if (k > i)
- { i = k - 1;
- break;
- }
+ default:
+ leadingBlank = 0;
+ if (sc && !inCode && isIdStart(&buf->data[i]))
+ { unsigned j;
- if (buf->data[i] == '_') // leading '_' means no highlight
- {
- buf->remove(i, 1);
- i = j - 1;
- }
- else
- {
- if (cmp(sid, buf->data + i, j - i) == 0)
- {
- i = buf->bracket(i, "$(DDOC_PSYMBOL ", j, ")") - 1;
- break;
- }
- else if (isKeyword(buf->data + i, j - i))
- {
- i = buf->bracket(i, "$(DDOC_KEYWORD ", j, ")") - 1;
- break;
- }
- else
- {
- if (f && isFunctionParameter(f, buf->data + i, j - i))
- {
- //printf("highlighting arg '%s', i = %d, j = %d\n", arg->ident->toChars(), i, j);
- i = buf->bracket(i, "$(DDOC_PARAM ", j, ")") - 1;
- break;
- }
- }
- i = j - 1;
- }
- }
- }
- break;
- }
+ j = skippastident(buf, i);
+ if (j > i)
+ {
+ unsigned k = skippastURL(buf, i);
+ if (k > i)
+ { i = k - 1;
+ break;
+ }
+
+ if (buf->data[i] == '_') // leading '_' means no highlight
+ {
+ buf->remove(i, 1);
+ i = j - 1;
+ }
+ else
+ {
+ if (cmp(sid, buf->data + i, j - i) == 0)
+ {
+ i = buf->bracket(i, "$(DDOC_PSYMBOL ", j, ")") - 1;
+ break;
+ }
+ else if (isKeyword(buf->data + i, j - i))
+ {
+ i = buf->bracket(i, "$(DDOC_KEYWORD ", j, ")") - 1;
+ break;
+ }
+ else
+ {
+ if (f && isFunctionParameter(f, buf->data + i, j - i))
+ {
+ //printf("highlighting arg '%s', i = %d, j = %d\n", arg->ident->toChars(), i, j);
+ i = buf->bracket(i, "$(DDOC_PARAM ", j, ")") - 1;
+ break;
+ }
+ }
+ i = j - 1;
+ }
+ }
+ }
+ break;
+ }
}
Ldone:
if (inCode)
@@ -1917,40 +1917,40 @@ void highlightCode(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
//printf("highlightCode(s = '%s', kind = %s)\n", sid, s->kind());
for (unsigned i = offset; i < buf->offset; i++)
- { unsigned char c = buf->data[i];
- const char *se;
+ { unsigned char c = buf->data[i];
+ const char *se;
- se = Escape::escapeChar(c);
- if (se)
- {
- size_t len = strlen(se);
- buf->remove(i, 1);
- i = buf->insert(i, se, len);
- i--; // point to ';'
- }
- else if (isIdStart(&buf->data[i]))
- { unsigned j;
+ se = Escape::escapeChar(c);
+ if (se)
+ {
+ size_t len = strlen(se);
+ buf->remove(i, 1);
+ i = buf->insert(i, se, len);
+ i--; // point to ';'
+ }
+ else if (isIdStart(&buf->data[i]))
+ { unsigned j;
- j = skippastident(buf, i);
- if (j > i)
- {
- if (cmp(sid, buf->data + i, j - i) == 0)
- {
- i = buf->bracket(i, "$(DDOC_PSYMBOL ", j, ")") - 1;
- continue;
- }
- else if (f)
- {
- if (isFunctionParameter(f, buf->data + i, j - i))
- {
- //printf("highlighting arg '%s', i = %d, j = %d\n", arg->ident->toChars(), i, j);
- i = buf->bracket(i, "$(DDOC_PARAM ", j, ")") - 1;
- continue;
- }
- }
- i = j - 1;
- }
- }
+ j = skippastident(buf, i);
+ if (j > i)
+ {
+ if (cmp(sid, buf->data + i, j - i) == 0)
+ {
+ i = buf->bracket(i, "$(DDOC_PSYMBOL ", j, ")") - 1;
+ continue;
+ }
+ else if (f)
+ {
+ if (isFunctionParameter(f, buf->data + i, j - i))
+ {
+ //printf("highlighting arg '%s', i = %d, j = %d\n", arg->ident->toChars(), i, j);
+ i = buf->bracket(i, "$(DDOC_PARAM ", j, ")") - 1;
+ continue;
+ }
+ }
+ i = j - 1;
+ }
+ }
}
}
@@ -1960,11 +1960,11 @@ void highlightCode(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
void highlightCode3(OutBuffer *buf, unsigned char *p, unsigned char *pend)
{
for (; p < pend; p++)
- { const char *s = Escape::escapeChar(*p);
- if (s)
- buf->writestring(s);
- else
- buf->writeByte(*p);
+ { const char *s = Escape::escapeChar(*p);
+ if (s)
+ buf->writestring(s);
+ else
+ buf->writeByte(*p);
}
}
@@ -1988,51 +1988,51 @@ void highlightCode2(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
res.reserve(buf->offset);
while (1)
{
- lex.scan(&tok);
- highlightCode3(&res, lastp, tok.ptr);
- highlight = NULL;
- switch (tok.value)
- {
- case TOKidentifier:
- if (!sc)
- break;
- if (cmp(sid, tok.ptr, lex.p - tok.ptr) == 0)
- {
- highlight = "$(D_PSYMBOL ";
- break;
- }
- else if (f)
- {
- if (isFunctionParameter(f, tok.ptr, lex.p - tok.ptr))
- {
- //printf("highlighting arg '%s', i = %d, j = %d\n", arg->ident->toChars(), i, j);
- highlight = "$(D_PARAM ";
- break;
- }
- }
- break;
+ lex.scan(&tok);
+ highlightCode3(&res, lastp, tok.ptr);
+ highlight = NULL;
+ switch (tok.value)
+ {
+ case TOKidentifier:
+ if (!sc)
+ break;
+ if (cmp(sid, tok.ptr, lex.p - tok.ptr) == 0)
+ {
+ highlight = "$(D_PSYMBOL ";
+ break;
+ }
+ else if (f)
+ {
+ if (isFunctionParameter(f, tok.ptr, lex.p - tok.ptr))
+ {
+ //printf("highlighting arg '%s', i = %d, j = %d\n", arg->ident->toChars(), i, j);
+ highlight = "$(D_PARAM ";
+ break;
+ }
+ }
+ break;
- case TOKcomment:
- highlight = "$(D_COMMENT ";
- break;
+ case TOKcomment:
+ highlight = "$(D_COMMENT ";
+ break;
- case TOKstring:
- highlight = "$(D_STRING ";
- break;
+ case TOKstring:
+ highlight = "$(D_STRING ";
+ break;
- default:
- if (tok.isKeyword())
- highlight = "$(D_KEYWORD ";
- break;
- }
- if (highlight)
- res.writestring(highlight);
- highlightCode3(&res, tok.ptr, lex.p);
- if (highlight)
- res.writeByte(')');
- if (tok.value == TOKeof)
- break;
- lastp = lex.p;
+ default:
+ if (tok.isKeyword())
+ highlight = "$(D_KEYWORD ";
+ break;
+ }
+ if (highlight)
+ res.writestring(highlight);
+ highlightCode3(&res, tok.ptr, lex.p);
+ if (highlight)
+ res.writeByte(')');
+ if (tok.value == TOKeof)
+ break;
+ lastp = lex.p;
}
buf->setsize(offset);
buf->write(&res);
@@ -2048,18 +2048,18 @@ const char *Escape::escapeChar(unsigned c)
switch (c)
{
- case '<':
- s = "<";
- break;
- case '>':
- s = ">";
- break;
- case '&':
- s = "&";
- break;
- default:
- s = NULL;
- break;
+ case '<':
+ s = "<";
+ break;
+ case '>':
+ s = ">";
+ break;
+ case '&':
+ s = "&";
+ break;
+ default:
+ s = NULL;
+ break;
}
return s;
}
@@ -2072,13 +2072,13 @@ int isIdStart(unsigned char *p)
{
unsigned c = *p;
if (isalpha(c) || c == '_')
- return 1;
+ return 1;
if (c >= 0x80)
- { size_t i = 0;
- if (utf_decodeChar(p, 4, &i, &c))
- return 0; // ignore errors
- if (isUniAlpha(c))
- return 1;
+ { size_t i = 0;
+ if (utf_decodeChar(p, 4, &i, &c))
+ return 0; // ignore errors
+ if (isUniAlpha(c))
+ return 1;
}
return 0;
}
@@ -2091,13 +2091,13 @@ int isIdTail(unsigned char *p)
{
unsigned c = *p;
if (isalnum(c) || c == '_')
- return 1;
+ return 1;
if (c >= 0x80)
- { size_t i = 0;
- if (utf_decodeChar(p, 4, &i, &c))
- return 0; // ignore errors
- if (isUniAlpha(c))
- return 1;
+ { size_t i = 0;
+ if (utf_decodeChar(p, 4, &i, &c))
+ return 0; // ignore errors
+ if (isUniAlpha(c))
+ return 1;
}
return 0;
}
@@ -2110,8 +2110,8 @@ int utfStride(unsigned char *p)
{
unsigned c = *p;
if (c < 0x80)
- return 1;
+ return 1;
size_t i = 0;
- utf_decodeChar(p, 4, &i, &c); // ignore errors, but still consume input
+ utf_decodeChar(p, 4, &i, &c); // ignore errors, but still consume input
return i;
}
diff --git a/dmd/dsymbol.c b/dmd/dsymbol.c
index a89bc985..9b813112 100644
--- a/dmd/dsymbol.c
+++ b/dmd/dsymbol.c
@@ -78,10 +78,10 @@ int Dsymbol::equals(Object *o)
{ Dsymbol *s;
if (this == o)
- return TRUE;
+ return TRUE;
s = (Dsymbol *)(o);
if (s && ident->equals(s->ident))
- return TRUE;
+ return TRUE;
return FALSE;
}
@@ -102,9 +102,9 @@ Dsymbol *Dsymbol::syntaxCopy(Dsymbol *s)
/**************************************
* Determine if this symbol is only one.
* Returns:
- * FALSE, *ps = NULL: There are 2 or more symbols
- * TRUE, *ps = NULL: There are zero symbols
- * TRUE, *ps = symbol: The one and only one symbol
+ * FALSE, *ps = NULL: There are 2 or more symbols
+ * TRUE, *ps = NULL: There are zero symbols
+ * TRUE, *ps = symbol: The one and only one symbol
*/
int Dsymbol::oneMember(Dsymbol **ps)
@@ -125,29 +125,29 @@ int Dsymbol::oneMembers(Array *members, Dsymbol **ps)
if (members)
{
- for (int i = 0; i < members->dim; i++)
- { Dsymbol *sx = (Dsymbol *)members->data[i];
+ for (int i = 0; i < members->dim; i++)
+ { Dsymbol *sx = (Dsymbol *)members->data[i];
- int x = sx->oneMember(ps);
- //printf("\t[%d] kind %s = %d, s = %p\n", i, sx->kind(), x, *ps);
- if (!x)
- {
- //printf("\tfalse 1\n");
- assert(*ps == NULL);
- return FALSE;
- }
- if (*ps)
- {
- if (s) // more than one symbol
- { *ps = NULL;
- //printf("\tfalse 2\n");
- return FALSE;
- }
- s = *ps;
- }
- }
+ int x = sx->oneMember(ps);
+ //printf("\t[%d] kind %s = %d, s = %p\n", i, sx->kind(), x, *ps);
+ if (!x)
+ {
+ //printf("\tfalse 1\n");
+ assert(*ps == NULL);
+ return FALSE;
+ }
+ if (*ps)
+ {
+ if (s) // more than one symbol
+ { *ps = NULL;
+ //printf("\tfalse 2\n");
+ return FALSE;
+ }
+ s = *ps;
+ }
+ }
}
- *ps = s; // s is the one symbol, NULL if none
+ *ps = s; // s is the one symbol, NULL if none
//printf("\ttrue\n");
return TRUE;
}
@@ -175,24 +175,24 @@ const char *Dsymbol::toPrettyChars()
//printf("Dsymbol::toPrettyChars() '%s'\n", toChars());
if (!parent)
- return toChars();
+ return toChars();
len = 0;
for (p = this; p; p = p->parent)
- len += strlen(p->toChars()) + 1;
+ len += strlen(p->toChars()) + 1;
s = (char *)mem.malloc(len);
q = s + len - 1;
*q = 0;
for (p = this; p; p = p->parent)
{
- char *t = p->toChars();
- len = strlen(t);
- q -= len;
- memcpy(q, t, len);
- if (q == s)
- break;
- q--;
+ char *t = p->toChars();
+ len = strlen(t);
+ q -= len;
+ memcpy(q, t, len);
+ if (q == s)
+ break;
+ q--;
#if TARGET_NET
if (AggregateDeclaration* ad = p->isAggregateDeclaration())
{
@@ -203,7 +203,7 @@ const char *Dsymbol::toPrettyChars()
}
}
#endif
- *q = '.';
+ *q = '.';
}
return s;
}
@@ -216,7 +216,7 @@ char *Dsymbol::locToChars()
Module *m = getModule();
if (m && m->srcfile)
- loc.filename = m->srcfile->toChars();
+ loc.filename = m->srcfile->toChars();
return loc.toChars();
}
@@ -246,7 +246,7 @@ Dsymbol *Dsymbol::pastMixin()
//printf("Dsymbol::pastMixin() %s\n", toChars());
while (s && s->isTemplateMixin())
- s = s->parent;
+ s = s->parent;
return s;
}
@@ -259,7 +259,7 @@ Dsymbol *Dsymbol::toParent2()
{
Dsymbol *s = parent;
while (s && s->isTemplateInstance())
- s = s->parent;
+ s = s->parent;
return s;
}
@@ -267,9 +267,9 @@ TemplateInstance *Dsymbol::inTemplateInstance()
{
for (Dsymbol *parent = this->parent; parent; parent = parent->parent)
{
- TemplateInstance *ti = parent->isTemplateInstance();
- if (ti)
- return ti;
+ TemplateInstance *ti = parent->isTemplateInstance();
+ if (ti)
+ return ti;
}
return NULL;
}
@@ -288,7 +288,7 @@ void Dsymbol::setScope(Scope *sc)
{
//printf("Dsymbol::setScope() %p %s\n", this, toChars());
if (!sc->nofree)
- sc->setNoFree(); // may need it even after semantic() finishes
+ sc->setNoFree(); // may need it even after semantic() finishes
scope = sc;
}
@@ -335,11 +335,11 @@ void Dsymbol::inlineScan()
/*********************************************
* Search for ident as member of s.
* Input:
- * flags: 1 don't find private members
- * 2 don't give error messages
- * 4 return NULL if ambiguous
+ * flags: 1 don't find private members
+ * 2 don't give error messages
+ * 4 return NULL if ambiguous
* Returns:
- * NULL if not found
+ * NULL if not found
*/
Dsymbol *Dsymbol::search(Loc loc, Identifier *ident, int flags)
@@ -364,7 +364,7 @@ void *symbol_search_fp(void *arg, const char *seed)
Dsymbol *Dsymbol::search_correct(Identifier *ident)
{
if (global.gag)
- return NULL; // don't do it for speculative compiles; too time consuming
+ return NULL; // don't do it for speculative compiles; too time consuming
return (Dsymbol *)speller(ident->toChars(), &symbol_search_fp, this, idchars);
}
@@ -373,7 +373,7 @@ Dsymbol *Dsymbol::search_correct(Identifier *ident)
* Search for identifier id as a member of 'this'.
* id may be a template instance.
* Returns:
- * symbol found, NULL if not
+ * symbol found, NULL if not
*/
Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id)
@@ -384,38 +384,38 @@ Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id)
switch (id->dyncast())
{
- case DYNCAST_IDENTIFIER:
- sm = s->search(loc, id, 0);
- break;
+ case DYNCAST_IDENTIFIER:
+ sm = s->search(loc, id, 0);
+ break;
- case DYNCAST_DSYMBOL:
- { // It's a template instance
- //printf("\ttemplate instance id\n");
- Dsymbol *st = (Dsymbol *)id;
- TemplateInstance *ti = st->isTemplateInstance();
- id = ti->name;
- sm = s->search(loc, id, 0);
- if (!sm)
- { error("template identifier %s is not a member of %s %s",
- id->toChars(), s->kind(), s->toChars());
- return NULL;
- }
- sm = sm->toAlias();
- TemplateDeclaration *td = sm->isTemplateDeclaration();
- if (!td)
- {
- error("%s is not a template, it is a %s", id->toChars(), sm->kind());
- return NULL;
- }
- ti->tempdecl = td;
- if (!ti->semanticRun)
- ti->semantic(sc);
- sm = ti->toAlias();
- break;
- }
+ case DYNCAST_DSYMBOL:
+ { // It's a template instance
+ //printf("\ttemplate instance id\n");
+ Dsymbol *st = (Dsymbol *)id;
+ TemplateInstance *ti = st->isTemplateInstance();
+ id = ti->name;
+ sm = s->search(loc, id, 0);
+ if (!sm)
+ { error("template identifier %s is not a member of %s %s",
+ id->toChars(), s->kind(), s->toChars());
+ return NULL;
+ }
+ sm = sm->toAlias();
+ TemplateDeclaration *td = sm->isTemplateDeclaration();
+ if (!td)
+ {
+ error("%s is not a template, it is a %s", id->toChars(), sm->kind());
+ return NULL;
+ }
+ ti->tempdecl = td;
+ if (!ti->semanticRun)
+ ti->semantic(sc);
+ sm = ti->toAlias();
+ break;
+ }
- default:
- assert(0);
+ default:
+ assert(0);
}
return sm;
}
@@ -447,11 +447,11 @@ AggregateDeclaration *Dsymbol::isThis()
return NULL;
}
-ClassDeclaration *Dsymbol::isClassMember() // are we a member of a class?
+ClassDeclaration *Dsymbol::isClassMember() // are we a member of a class?
{
Dsymbol *parent = toParent();
if (parent && parent->isClassDeclaration())
- return (ClassDeclaration *)parent;
+ return (ClassDeclaration *)parent;
return NULL;
}
@@ -482,12 +482,12 @@ int Dsymbol::isOverloadable()
}
#endif
-LabelDsymbol *Dsymbol::isLabel() // is this a LabelDsymbol()?
+LabelDsymbol *Dsymbol::isLabel() // is this a LabelDsymbol()?
{
return NULL;
}
-AggregateDeclaration *Dsymbol::isMember() // is this a member of an AggregateDeclaration?
+AggregateDeclaration *Dsymbol::isMember() // is this a member of an AggregateDeclaration?
{
//printf("Dsymbol::isMember() %s\n", toChars());
Dsymbol *parent = toParent();
@@ -511,24 +511,24 @@ int Dsymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
//printf("Dsymbol::addMember(this = %p, '%s' scopesym = '%s')\n", this, toChars(), sd->toChars());
//printf("Dsymbol::addMember(this = %p, '%s' sd = %p, sd->symtab = %p)\n", this, toChars(), sd, sd->symtab);
parent = sd;
- if (!isAnonymous()) // no name, so can't add it to symbol table
+ if (!isAnonymous()) // no name, so can't add it to symbol table
{
- if (!sd->symtabInsert(this)) // if name is already defined
- {
- Dsymbol *s2;
+ if (!sd->symtabInsert(this)) // if name is already defined
+ {
+ Dsymbol *s2;
- s2 = sd->symtab->lookup(ident);
- if (!s2->overloadInsert(this))
- {
- sd->multiplyDefined(0, this, s2);
- }
- }
- if (sd->isAggregateDeclaration() || sd->isEnumDeclaration())
- {
- if (ident == Id::__sizeof || ident == Id::alignof || ident == Id::mangleof)
- error(".%s property cannot be redefined", ident->toChars());
- }
- return 1;
+ s2 = sd->symtab->lookup(ident);
+ if (!s2->overloadInsert(this))
+ {
+ sd->multiplyDefined(0, this, s2);
+ }
+ }
+ if (sd->isAggregateDeclaration() || sd->isEnumDeclaration())
+ {
+ if (ident == Id::__sizeof || ident == Id::alignof || ident == Id::mangleof)
+ error(".%s property cannot be redefined", ident->toChars());
+ }
+ return 1;
}
return 0;
}
@@ -538,25 +538,25 @@ void Dsymbol::error(const char *format, ...)
//printf("Dsymbol::error()\n");
if (!global.gag)
{
- char *p = locToChars();
+ char *p = locToChars();
- if (*p)
- fprintf(stdmsg, "%s: ", p);
- mem.free(p);
+ if (*p)
+ fprintf(stdmsg, "%s: ", p);
+ mem.free(p);
- fprintf(stdmsg, "Error: ");
- if (isAnonymous())
- fprintf(stdmsg, "%s ", kind());
- else
- fprintf(stdmsg, "%s %s ", kind(), toPrettyChars());
+ fprintf(stdmsg, "Error: ");
+ if (isAnonymous())
+ fprintf(stdmsg, "%s ", kind());
+ else
+ fprintf(stdmsg, "%s %s ", kind(), toPrettyChars());
- va_list ap;
- va_start(ap, format);
- vfprintf(stdmsg, format, ap);
- va_end(ap);
+ va_list ap;
+ va_start(ap, format);
+ vfprintf(stdmsg, format, ap);
+ va_end(ap);
- fprintf(stdmsg, "\n");
- fflush(stdmsg);
+ fprintf(stdmsg, "\n");
+ fflush(stdmsg);
}
global.errors++;
@@ -567,24 +567,24 @@ void Dsymbol::error(Loc loc, const char *format, ...)
{
if (!global.gag)
{
- char *p = loc.toChars();
- if (!*p)
- p = locToChars();
+ char *p = loc.toChars();
+ if (!*p)
+ p = locToChars();
- if (*p)
- fprintf(stdmsg, "%s: ", p);
- mem.free(p);
+ if (*p)
+ fprintf(stdmsg, "%s: ", p);
+ mem.free(p);
- fprintf(stdmsg, "Error: ");
- fprintf(stdmsg, "%s %s ", kind(), toPrettyChars());
+ fprintf(stdmsg, "Error: ");
+ fprintf(stdmsg, "%s %s ", kind(), toPrettyChars());
- va_list ap;
- va_start(ap, format);
- vfprintf(stdmsg, format, ap);
- va_end(ap);
+ va_list ap;
+ va_start(ap, format);
+ vfprintf(stdmsg, format, ap);
+ va_end(ap);
- fprintf(stdmsg, "\n");
- fflush(stdmsg);
+ fprintf(stdmsg, "\n");
+ fflush(stdmsg);
}
global.errors++;
@@ -596,23 +596,23 @@ void Dsymbol::checkDeprecated(Loc loc, Scope *sc)
{
if (!global.params.useDeprecated && isDeprecated())
{
- // Don't complain if we're inside a deprecated symbol's scope
- for (Dsymbol *sp = sc->parent; sp; sp = sp->parent)
- { if (sp->isDeprecated())
- return;
- }
+ // Don't complain if we're inside a deprecated symbol's scope
+ for (Dsymbol *sp = sc->parent; sp; sp = sp->parent)
+ { if (sp->isDeprecated())
+ return;
+ }
- for (; sc; sc = sc->enclosing)
- {
- if (sc->scopesym && sc->scopesym->isDeprecated())
- return;
+ for (; sc; sc = sc->enclosing)
+ {
+ if (sc->scopesym && sc->scopesym->isDeprecated())
+ return;
- // If inside a StorageClassDeclaration that is deprecated
- if (sc->stc & STCdeprecated)
- return;
- }
+ // If inside a StorageClassDeclaration that is deprecated
+ if (sc->stc & STCdeprecated)
+ return;
+ }
- error(loc, "is deprecated");
+ error(loc, "is deprecated");
}
}
@@ -629,11 +629,11 @@ Module *Dsymbol::getModule()
s = this;
while (s)
{
- //printf("\ts = '%s'\n", s->toChars());
- m = s->isModule();
- if (m)
- return m;
- s = s->parent;
+ //printf("\ts = '%s'\n", s->toChars());
+ m = s->isModule();
+ if (m)
+ return m;
+ s = s->parent;
}
return NULL;
}
@@ -654,14 +654,14 @@ Module *Dsymbol::getCompilationModule()
s = this;
while (s)
{
- //printf("\ts = '%s'\n", s->toChars());
- m = s->isModule();
- if (m)
- return m;
- ti = s->isTemplateInstance();
- if (ti && ti->tmodule)
- return ti->tmodule;
- s = s->parent;
+ //printf("\ts = '%s'\n", s->toChars());
+ m = s->isModule();
+ if (m)
+ return m;
+ ti = s->isTemplateInstance();
+ if (ti && ti->tmodule)
+ return ti->tmodule;
+ s = s->parent;
}
return NULL;
}
@@ -685,14 +685,14 @@ Array *Dsymbol::arraySyntaxCopy(Array *a)
Array *b = NULL;
if (a)
{
- b = a->copy();
- for (int i = 0; i < b->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)b->data[i];
+ b = a->copy();
+ for (int i = 0; i < b->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)b->data[i];
- s = s->syntaxCopy(NULL);
- b->data[i] = (void *)s;
- }
+ s = s->syntaxCopy(NULL);
+ b->data[i] = (void *)s;
+ }
}
return b;
}
@@ -706,14 +706,14 @@ Array *Dsymbol::arraySyntaxCopy(Array *a)
void Dsymbol::addComment(unsigned char *comment)
{
//if (comment)
- //printf("adding comment '%s' to symbol %p '%s'\n", comment, this, toChars());
+ //printf("adding comment '%s' to symbol %p '%s'\n", comment, this, toChars());
if (!this->comment)
- this->comment = comment;
+ this->comment = comment;
#if 1
else if (comment && strcmp((char *)comment, (char *)this->comment))
- { // Concatenate the two
- this->comment = Lexer::combineComments(this->comment, comment);
+ { // Concatenate the two
+ this->comment = Lexer::combineComments(this->comment, comment);
}
#endif
}
@@ -764,9 +764,9 @@ Dsymbol *ScopeDsymbol::syntaxCopy(Dsymbol *s)
ScopeDsymbol *sd;
if (s)
- sd = (ScopeDsymbol *)s;
+ sd = (ScopeDsymbol *)s;
else
- sd = new ScopeDsymbol(ident);
+ sd = new ScopeDsymbol(ident);
sd->members = arraySyntaxCopy(members);
return sd;
}
@@ -782,70 +782,70 @@ Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)
// hide the aliases generated by selective or renamed private imports
if (s && flags & 1)
if (AliasDeclaration* ad = s->isAliasDeclaration())
- // may be a private alias to a function that is overloaded. these
- // are sorted out during overload resolution, accept them here
- if (ad->importprot == PROTprivate && !ad->aliassym->isFuncAliasDeclaration())
- s = NULL;
+ // may be a private alias to a function that is overloaded. these
+ // are sorted out during overload resolution, accept them here
+ if (ad->importprot == PROTprivate && !ad->aliassym->isFuncAliasDeclaration())
+ s = NULL;
if (s)
{
- //printf("\ts = '%s.%s'\n",toChars(),s->toChars());
+ //printf("\ts = '%s.%s'\n",toChars(),s->toChars());
}
else if (imports)
{
- // Look in imported modules
- for (int i = 0; i < imports->dim; i++)
- { ScopeDsymbol *ss = (ScopeDsymbol *)imports->data[i];
- Dsymbol *s2;
+ // Look in imported modules
+ for (int i = 0; i < imports->dim; i++)
+ { ScopeDsymbol *ss = (ScopeDsymbol *)imports->data[i];
+ Dsymbol *s2;
- // If private import, don't search it
- if (flags & 1 && prots[i] == PROTprivate)
- continue;
+ // If private import, don't search it
+ if (flags & 1 && prots[i] == PROTprivate)
+ continue;
- //printf("\tscanning import '%s', prots = %d, isModule = %p, isImport = %p\n", ss->toChars(), prots[i], ss->isModule(), ss->isImport());
- /* Don't find private members if ss is a module
- */
- s2 = ss->search(loc, ident, ss->isModule() ? 1 : 0);
- if (!s)
- s = s2;
- else if (s2 && s != s2)
- {
- if (s->toAlias() == s2->toAlias())
- {
- /* After following aliases, we found the same symbol,
- * so it's not an ambiguity.
- * But if one alias is deprecated, prefer the other.
- */
- if (s->isDeprecated())
- s = s2;
- }
- else
- {
- /* Two imports of the same module should be regarded as
- * the same.
- */
- Import *i1 = s->isImport();
- Import *i2 = s2->isImport();
- if (!(i1 && i2 &&
- (i1->mod == i2->mod ||
- (!i1->parent->isImport() && !i2->parent->isImport() &&
- i1->ident->equals(i2->ident))
- )
- )
- )
- {
- ss->multiplyDefined(loc, s, s2);
- break;
- }
- }
- }
- }
- if (s)
- {
- Declaration *d = s->isDeclaration();
- if (d && d->protection == PROTprivate && !d->parent->isTemplateMixin())
- error("%s is private", d->toPrettyChars());
- }
+ //printf("\tscanning import '%s', prots = %d, isModule = %p, isImport = %p\n", ss->toChars(), prots[i], ss->isModule(), ss->isImport());
+ /* Don't find private members if ss is a module
+ */
+ s2 = ss->search(loc, ident, ss->isModule() ? 1 : 0);
+ if (!s)
+ s = s2;
+ else if (s2 && s != s2)
+ {
+ if (s->toAlias() == s2->toAlias())
+ {
+ /* After following aliases, we found the same symbol,
+ * so it's not an ambiguity.
+ * But if one alias is deprecated, prefer the other.
+ */
+ if (s->isDeprecated())
+ s = s2;
+ }
+ else
+ {
+ /* Two imports of the same module should be regarded as
+ * the same.
+ */
+ Import *i1 = s->isImport();
+ Import *i2 = s2->isImport();
+ if (!(i1 && i2 &&
+ (i1->mod == i2->mod ||
+ (!i1->parent->isImport() && !i2->parent->isImport() &&
+ i1->ident->equals(i2->ident))
+ )
+ )
+ )
+ {
+ ss->multiplyDefined(loc, s, s2);
+ break;
+ }
+ }
+ }
+ }
+ if (s)
+ {
+ Declaration *d = s->isDeclaration();
+ if (d && d->protection == PROTprivate && !d->parent->isTemplateMixin())
+ error("%s is private", d->toPrettyChars());
+ }
}
return s;
}
@@ -857,25 +857,25 @@ void ScopeDsymbol::importScope(ScopeDsymbol *s, enum PROT protection)
// No circular or redundant import's
if (s != this)
{
- if (!imports)
- imports = new Array();
- else
- {
- for (int i = 0; i < imports->dim; i++)
- { ScopeDsymbol *ss;
+ if (!imports)
+ imports = new Array();
+ else
+ {
+ for (int i = 0; i < imports->dim; i++)
+ { ScopeDsymbol *ss;
- ss = (ScopeDsymbol *) imports->data[i];
- if (ss == s) // if already imported
- {
- if (protection > prots[i])
- prots[i] = protection; // upgrade access
- return;
- }
- }
- }
- imports->push(s);
- prots = (unsigned char *)mem.realloc(prots, imports->dim * sizeof(prots[0]));
- prots[imports->dim - 1] = protection;
+ ss = (ScopeDsymbol *) imports->data[i];
+ if (ss == s) // if already imported
+ {
+ if (protection > prots[i])
+ prots[i] = protection; // upgrade access
+ return;
+ }
+ }
+ }
+ imports->push(s);
+ prots = (unsigned char *)mem.realloc(prots, imports->dim * sizeof(prots[0]));
+ prots[imports->dim - 1] = protection;
}
}
@@ -901,18 +901,18 @@ void ScopeDsymbol::multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2)
printf("s2 = %p, '%s' kind = '%s', parent = %s\n", s2, s2->toChars(), s2->kind(), s2->parent ? s2->parent->toChars() : "");
#endif
if (loc.filename)
- { ::error(loc, "%s at %s conflicts with %s at %s",
- s1->toPrettyChars(),
- s1->locToChars(),
- s2->toPrettyChars(),
- s2->locToChars());
+ { ::error(loc, "%s at %s conflicts with %s at %s",
+ s1->toPrettyChars(),
+ s1->locToChars(),
+ s2->toPrettyChars(),
+ s2->locToChars());
}
else
{
- s1->error(loc, "conflicts with %s %s at %s",
- s2->kind(),
- s2->toPrettyChars(),
- s2->locToChars());
+ s1->error(loc, "conflicts with %s %s at %s",
+ s2->kind(),
+ s2->toPrettyChars(),
+ s2->locToChars());
}
}
@@ -924,15 +924,15 @@ Dsymbol *ScopeDsymbol::nameCollision(Dsymbol *s)
sprev = symtab->lookup(s->ident);
assert(sprev);
- if (s->equals(sprev)) // if the same symbol
+ if (s->equals(sprev)) // if the same symbol
{
- if (s->isforwardRef()) // if second declaration is a forward reference
- return sprev;
- if (sprev->isforwardRef())
- {
- sprev->defineRef(s); // copy data from s into sprev
- return sprev;
- }
+ if (s->isforwardRef()) // if second declaration is a forward reference
+ return sprev;
+ if (sprev->isforwardRef())
+ {
+ sprev->defineRef(s); // copy data from s into sprev
+ return sprev;
+ }
}
multiplyDefined(0, s, sprev);
return sprev;
@@ -958,17 +958,17 @@ size_t ScopeDsymbol::dim(Array *members)
size_t n = 0;
if (members)
{
- for (size_t i = 0; i < members->dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- AttribDeclaration *a = s->isAttribDeclaration();
+ for (size_t i = 0; i < members->dim; i++)
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ AttribDeclaration *a = s->isAttribDeclaration();
- if (a)
- {
- n += dim(a->decl);
- }
- else
- n++;
- }
+ if (a)
+ {
+ n += dim(a->decl);
+ }
+ else
+ n++;
+ }
}
return n;
}
@@ -977,43 +977,43 @@ size_t ScopeDsymbol::dim(Array *members)
/***************************************
* Get nth Dsymbol, folding in AttribDeclaration members.
* Returns:
- * Dsymbol* nth Dsymbol
- * NULL not found, *pn gets incremented by the number
- * of Dsymbols
+ * Dsymbol* nth Dsymbol
+ * NULL not found, *pn gets incremented by the number
+ * of Dsymbols
*/
#if DMDV2
Dsymbol *ScopeDsymbol::getNth(Array *members, size_t nth, size_t *pn)
{
if (!members)
- return NULL;
+ return NULL;
size_t n = 0;
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
- AttribDeclaration *a = s->isAttribDeclaration();
+ AttribDeclaration *a = s->isAttribDeclaration();
- if (a)
- {
- s = getNth(a->decl, nth - n, &n);
- if (s)
- return s;
- }
- else if (n == nth)
- return s;
- else
- n++;
+ if (a)
+ {
+ s = getNth(a->decl, nth - n, &n);
+ if (s)
+ return s;
+ }
+ else if (n == nth)
+ return s;
+ else
+ n++;
}
if (pn)
- *pn += n;
+ *pn += n;
return NULL;
}
#endif
/*******************************************
* Look for member of the form:
- * const(MemberInfo)[] getMembers(string);
+ * const(MemberInfo)[] getMembers(string);
* Returns NULL if not found
*/
@@ -1028,20 +1028,20 @@ FuncDeclaration *ScopeDsymbol::findGetMembers()
if (!tfgetmembers)
{
- Scope sc;
- Parameters *arguments = new Parameters;
- Parameters *arg = new Parameter(STCin, Type::tchar->constOf()->arrayOf(), NULL, NULL);
- arguments->push(arg);
+ Scope sc;
+ Parameters *arguments = new Parameters;
+ Parameters *arg = new Parameter(STCin, Type::tchar->constOf()->arrayOf(), NULL, NULL);
+ arguments->push(arg);
- Type *tret = NULL;
- tfgetmembers = new TypeFunction(arguments, tret, 0, LINKd);
- tfgetmembers = (TypeFunction *)tfgetmembers->semantic(0, &sc);
+ Type *tret = NULL;
+ tfgetmembers = new TypeFunction(arguments, tret, 0, LINKd);
+ tfgetmembers = (TypeFunction *)tfgetmembers->semantic(0, &sc);
}
if (fdx)
- fdx = fdx->overloadExactMatch(tfgetmembers);
+ fdx = fdx->overloadExactMatch(tfgetmembers);
#endif
if (fdx && fdx->isVirtual())
- fdx = NULL;
+ fdx = NULL;
return fdx;
}
@@ -1093,101 +1093,101 @@ Dsymbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags)
{
//printf("ArrayScopeSymbol::search('%s', flags = %d)\n", ident->toChars(), flags);
if (ident == Id::length || ident == Id::dollar)
- { VarDeclaration **pvar;
- Expression *ce;
+ { VarDeclaration **pvar;
+ Expression *ce;
L1:
- if (td)
- { /* $ gives the number of elements in the tuple
- */
- VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL);
- Expression *e = new IntegerExp(0, td->objects->dim, Type::tsize_t);
- v->init = new ExpInitializer(0, e);
- v->storage_class |= STCconst;
- return v;
- }
+ if (td)
+ { /* $ gives the number of elements in the tuple
+ */
+ VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL);
+ Expression *e = new IntegerExp(0, td->objects->dim, Type::tsize_t);
+ v->init = new ExpInitializer(0, e);
+ v->storage_class |= STCconst;
+ return v;
+ }
- if (type)
- { /* $ gives the number of type entries in the type tuple
- */
- VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL);
- Expression *e = new IntegerExp(0, type->arguments->dim, Type::tsize_t);
- v->init = new ExpInitializer(0, e);
- v->storage_class |= STCconst;
- return v;
- }
+ if (type)
+ { /* $ gives the number of type entries in the type tuple
+ */
+ VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL);
+ Expression *e = new IntegerExp(0, type->arguments->dim, Type::tsize_t);
+ v->init = new ExpInitializer(0, e);
+ v->storage_class |= STCconst;
+ return v;
+ }
- if (exp->op == TOKindex)
- { /* array[index] where index is some function of $
- */
- IndexExp *ie = (IndexExp *)exp;
+ if (exp->op == TOKindex)
+ { /* array[index] where index is some function of $
+ */
+ IndexExp *ie = (IndexExp *)exp;
- pvar = &ie->lengthVar;
- ce = ie->e1;
- }
- else if (exp->op == TOKslice)
- { /* array[lwr .. upr] where lwr or upr is some function of $
- */
- SliceExp *se = (SliceExp *)exp;
+ pvar = &ie->lengthVar;
+ ce = ie->e1;
+ }
+ else if (exp->op == TOKslice)
+ { /* array[lwr .. upr] where lwr or upr is some function of $
+ */
+ SliceExp *se = (SliceExp *)exp;
- pvar = &se->lengthVar;
- ce = se->e1;
- }
- else
- /* Didn't find $, look in enclosing scope(s).
- */
- return NULL;
+ pvar = &se->lengthVar;
+ ce = se->e1;
+ }
+ else
+ /* Didn't find $, look in enclosing scope(s).
+ */
+ return NULL;
- /* If we are indexing into an array that is really a type
- * tuple, rewrite this as an index into a type tuple and
- * try again.
- */
- if (ce->op == TOKtype)
- {
- Type *t = ((TypeExp *)ce)->type;
- if (t->ty == Ttuple)
- { type = (TypeTuple *)t;
- goto L1;
- }
- }
+ /* If we are indexing into an array that is really a type
+ * tuple, rewrite this as an index into a type tuple and
+ * try again.
+ */
+ if (ce->op == TOKtype)
+ {
+ Type *t = ((TypeExp *)ce)->type;
+ if (t->ty == Ttuple)
+ { type = (TypeTuple *)t;
+ goto L1;
+ }
+ }
- /* *pvar is lazily initialized, so if we refer to $
- * multiple times, it gets set only once.
- */
- if (!*pvar) // if not already initialized
- { /* Create variable v and set it to the value of $,
- * which will be a constant.
- */
- VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL);
+ /* *pvar is lazily initialized, so if we refer to $
+ * multiple times, it gets set only once.
+ */
+ if (!*pvar) // if not already initialized
+ { /* Create variable v and set it to the value of $,
+ * which will be a constant.
+ */
+ VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL);
- if (ce->op == TOKstring)
- { /* It is for a string literal, so the
- * length will be a const.
- */
- Expression *e = new IntegerExp(0, ((StringExp *)ce)->len, Type::tsize_t);
- v->init = new ExpInitializer(0, e);
- v->storage_class |= STCconst;
- }
- else if (ce->op == TOKarrayliteral)
- { /* It is for an array literal, so the
- * length will be a const.
- */
- Expression *e = new IntegerExp(0, ((ArrayLiteralExp *)ce)->elements->dim, Type::tsize_t);
- v->init = new ExpInitializer(0, e);
- v->storage_class |= STCconst;
- }
- else if (ce->op == TOKtuple)
- { /* It is for an expression tuple, so the
- * length will be a const.
- */
- Expression *e = new IntegerExp(0, ((TupleExp *)ce)->exps->dim, Type::tsize_t);
- v->init = new ExpInitializer(0, e);
- v->storage_class |= STCconst;
- }
- *pvar = v;
- }
- return (*pvar);
+ if (ce->op == TOKstring)
+ { /* It is for a string literal, so the
+ * length will be a const.
+ */
+ Expression *e = new IntegerExp(0, ((StringExp *)ce)->len, Type::tsize_t);
+ v->init = new ExpInitializer(0, e);
+ v->storage_class |= STCconst;
+ }
+ else if (ce->op == TOKarrayliteral)
+ { /* It is for an array literal, so the
+ * length will be a const.
+ */
+ Expression *e = new IntegerExp(0, ((ArrayLiteralExp *)ce)->elements->dim, Type::tsize_t);
+ v->init = new ExpInitializer(0, e);
+ v->storage_class |= STCconst;
+ }
+ else if (ce->op == TOKtuple)
+ { /* It is for an expression tuple, so the
+ * length will be a const.
+ */
+ Expression *e = new IntegerExp(0, ((TupleExp *)ce)->exps->dim, Type::tsize_t);
+ v->init = new ExpInitializer(0, e);
+ v->storage_class |= STCconst;
+ }
+ *pvar = v;
+ }
+ return (*pvar);
}
return NULL;
}
@@ -1227,7 +1227,7 @@ Dsymbol *DsymbolTable::insert(Dsymbol *s)
#endif
sv = tab->insert(ident->toChars(), ident->len);
if (!sv)
- return NULL; // already in table
+ return NULL; // already in table
sv->ptrvalue = s;
return s;
}
@@ -1238,7 +1238,7 @@ Dsymbol *DsymbolTable::insert(Identifier *ident, Dsymbol *s)
//printf("DsymbolTable::insert()\n");
sv = tab->insert(ident->toChars(), ident->len);
if (!sv)
- return NULL; // already in table
+ return NULL; // already in table
sv->ptrvalue = s;
return s;
}
diff --git a/dmd/dsymbol.h b/dmd/dsymbol.h
index 77e93cd1..c41f533f 100644
--- a/dmd/dsymbol.h
+++ b/dmd/dsymbol.h
@@ -102,7 +102,7 @@ namespace llvm
enum PROT
{
PROTundefined,
- PROTnone, // no access
+ PROTnone, // no access
PROTprivate,
PROTpackage,
PROTprotected,
@@ -114,13 +114,13 @@ enum PROT
*/
enum PASS
{
- PASSinit, // initial state
- PASSsemantic, // semantic() started
- PASSsemanticdone, // semantic() done
- PASSsemantic2, // semantic2() run
- PASSsemantic3, // semantic3() started
- PASSsemantic3done, // semantic3() done
- PASSobj, // toObjFile() run
+ PASSinit, // initial state
+ PASSsemantic, // semantic() started
+ PASSsemanticdone, // semantic() done
+ PASSsemantic2, // semantic2() run
+ PASSsemantic3, // semantic3() started
+ PASSsemantic3done, // semantic3() done
+ PASSobj, // toObjFile() run
};
struct Dsymbol : Object
@@ -129,12 +129,12 @@ struct Dsymbol : Object
Identifier *c_ident;
Dsymbol *parent;
#if IN_DMD
- Symbol *csym; // symbol for code generator
- Symbol *isym; // import version of csym
+ Symbol *csym; // symbol for code generator
+ Symbol *isym; // import version of csym
#endif
- unsigned char *comment; // documentation comment for this Dsymbol
- Loc loc; // where defined
- Scope *scope; // !=NULL means context to use for semantic()
+ unsigned char *comment; // documentation comment for this Dsymbol
+ Loc loc; // where defined
+ Scope *scope; // !=NULL means context to use for semantic()
Dsymbol();
Dsymbol(Identifier *);
@@ -152,13 +152,13 @@ struct Dsymbol : Object
Dsymbol *toParent2();
TemplateInstance *inTemplateInstance();
- int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol()
+ int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol()
static Array *arraySyntaxCopy(Array *a);
virtual const char *toPrettyChars();
virtual const char *kind();
- virtual Dsymbol *toAlias(); // resolve real symbol
+ virtual Dsymbol *toAlias(); // resolve real symbol
virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum);
virtual void setScope(Scope *sc);
virtual void importAll(Scope *sc);
@@ -180,21 +180,21 @@ struct Dsymbol : Object
virtual unsigned size(Loc loc);
virtual int isforwardRef();
virtual void defineRef(Dsymbol *s);
- virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member
- virtual ClassDeclaration *isClassMember(); // are we a member of a class?
- virtual int isExport(); // is Dsymbol exported?
- virtual int isImportedSymbol(); // is Dsymbol imported?
- virtual int isDeprecated(); // is Dsymbol deprecated?
+ virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member
+ virtual ClassDeclaration *isClassMember(); // are we a member of a class?
+ virtual int isExport(); // is Dsymbol exported?
+ virtual int isImportedSymbol(); // is Dsymbol imported?
+ virtual int isDeprecated(); // is Dsymbol deprecated?
#if DMDV2
virtual int isOverloadable();
#endif
- virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol?
- virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration?
- virtual Type *getType(); // is this a type?
+ virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol?
+ virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration?
+ virtual Type *getType(); // is this a type?
virtual char *mangle();
- virtual int needThis(); // need a 'this' pointer?
+ virtual int needThis(); // need a 'this' pointer?
virtual enum PROT prot();
- virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
+ virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
virtual int oneMember(Dsymbol **ps);
static int oneMembers(Array *members, Dsymbol **ps);
virtual int hasPointers();
@@ -208,14 +208,14 @@ struct Dsymbol : Object
#if IN_DMD
// Backend
- virtual Symbol *toSymbol(); // to backend symbol
- virtual void toObjFile(int multiobj); // compile to .obj file
- virtual int cvMember(unsigned char *p); // emit cv debug info for member
+ virtual Symbol *toSymbol(); // to backend symbol
+ virtual void toObjFile(int multiobj); // compile to .obj file
+ virtual int cvMember(unsigned char *p); // emit cv debug info for member
- Symbol *toImport(); // to backend import symbol
- static Symbol *toImport(Symbol *s); // to backend import symbol
+ Symbol *toImport(); // to backend import symbol
+ static Symbol *toImport(Symbol *s); // to backend import symbol
- Symbol *toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix); // helper
+ Symbol *toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix); // helper
#endif
// Eliminate need for dynamic_cast
@@ -281,11 +281,11 @@ struct Dsymbol : Object
struct ScopeDsymbol : Dsymbol
{
- Array *members; // all Dsymbol's in this scope
- DsymbolTable *symtab; // members[] sorted into table
+ Array *members; // all Dsymbol's in this scope
+ DsymbolTable *symtab; // members[] sorted into table
- Array *imports; // imported ScopeDsymbol's
- unsigned char *prots; // array of PROT, one for each import
+ Array *imports; // imported ScopeDsymbol's
+ unsigned char *prots; // array of PROT, one for each import
ScopeDsymbol();
ScopeDsymbol(Identifier *id);
@@ -324,9 +324,9 @@ struct WithScopeSymbol : ScopeDsymbol
struct ArrayScopeSymbol : ScopeDsymbol
{
- Expression *exp; // IndexExp or SliceExp
- TypeTuple *type; // for tuple[length]
- TupleDeclaration *td; // for tuples of objects
+ Expression *exp; // IndexExp or SliceExp
+ TypeTuple *type; // for tuple[length]
+ TupleDeclaration *td; // for tuples of objects
Scope *sc;
ArrayScopeSymbol(Expression *e);
@@ -342,7 +342,7 @@ struct ArrayScopeSymbol : ScopeDsymbol
#if DMDV2
struct OverloadSet : Dsymbol
{
- Dsymbols a; // array of Dsymbols
+ Dsymbols a; // array of Dsymbols
OverloadSet();
void push(Dsymbol *s);
@@ -368,7 +368,7 @@ struct DsymbolTable : Object
// Look for Dsymbol in table. If there, return it. If not, insert s and return that.
Dsymbol *update(Dsymbol *s);
- Dsymbol *insert(Identifier *ident, Dsymbol *s); // when ident and s are not the same
+ Dsymbol *insert(Identifier *ident, Dsymbol *s); // when ident and s are not the same
};
#endif /* DMD_DSYMBOL_H */
diff --git a/dmd/dump.c b/dmd/dump.c
index 1f6fecd1..c5647dd8 100644
--- a/dmd/dump.c
+++ b/dmd/dump.c
@@ -23,7 +23,7 @@ static void indent(int indent)
int i;
for (i = 0; i < indent; i++)
- printf(" ");
+ printf(" ");
}
static char *type_print(Type *type)
@@ -34,12 +34,12 @@ static char *type_print(Type *type)
void dumpExpressions(int i, Expressions *exps)
{
for (size_t j = 0; j < exps->dim; j++)
- { Expression *e = (Expression *)exps->data[j];
- indent(i);
- printf("(\n");
- e->dump(i + 2);
- indent(i);
- printf(")\n");
+ { Expression *e = (Expression *)exps->data[j];
+ indent(i);
+ printf("(\n");
+ e->dump(i + 2);
+ indent(i);
+ printf(")\n");
}
}
@@ -78,7 +78,7 @@ void UnaExp::dump(int i)
indent(i);
printf("%p %s type=%s e1=%p\n", this, Token::toChars(op), type_print(type), e1);
if (e1)
- e1->dump(i + 2);
+ e1->dump(i + 2);
}
void CallExp::dump(int i)
@@ -92,11 +92,11 @@ void SliceExp::dump(int i)
indent(i);
printf("%p %s type=%s e1=%p\n", this, Token::toChars(op), type_print(type), e1);
if (e1)
- e1->dump(i + 2);
+ e1->dump(i + 2);
if (lwr)
- lwr->dump(i + 2);
+ lwr->dump(i + 2);
if (upr)
- upr->dump(i + 2);
+ upr->dump(i + 2);
}
void DotIdExp::dump(int i)
@@ -104,7 +104,7 @@ void DotIdExp::dump(int i)
indent(i);
printf("%p %s type=%s ident=%s e1=%p\n", this, Token::toChars(op), type_print(type), ident->toChars(), e1);
if (e1)
- e1->dump(i + 2);
+ e1->dump(i + 2);
}
void DotVarExp::dump(int i)
@@ -112,7 +112,7 @@ void DotVarExp::dump(int i)
indent(i);
printf("%p %s type=%s var='%s' e1=%p\n", this, Token::toChars(op), type_print(type), var->toChars(), e1);
if (e1)
- e1->dump(i + 2);
+ e1->dump(i + 2);
}
void DotTemplateInstanceExp::dump(int i)
@@ -120,7 +120,7 @@ void DotTemplateInstanceExp::dump(int i)
indent(i);
printf("%p %s type=%s ti='%s' e1=%p\n", this, Token::toChars(op), type_print(type), ti->toChars(), e1);
if (e1)
- e1->dump(i + 2);
+ e1->dump(i + 2);
}
void DelegateExp::dump(int i)
@@ -128,7 +128,7 @@ void DelegateExp::dump(int i)
indent(i);
printf("%p %s func=%s type=%s e1=%p\n", this, Token::toChars(op), func->toChars(), type_print(type), e1);
if (e1)
- e1->dump(i + 2);
+ e1->dump(i + 2);
}
void BinExp::dump(int i)
@@ -136,9 +136,9 @@ void BinExp::dump(int i)
indent(i);
printf("%p %s type=%s e1=%p e2=%p\n", this, Token::toChars(op), type_print(type), e1, e2);
if (e1)
- e1->dump(i + 2);
+ e1->dump(i + 2);
if (e2)
- e2->dump(i + 2);
+ e2->dump(i + 2);
}
diff --git a/dmd/entity.c b/dmd/entity.c
index 69da150d..cc5b0bc6 100644
--- a/dmd/entity.c
+++ b/dmd/entity.c
@@ -13,8 +13,8 @@
/*********************************************
* Convert from named entity to its encoding.
* For reference:
- * http://www.htmlhelp.com/reference/html40/entities/
- * http://www.w3.org/TR/1999/REC-html401-19991224/sgml/entities.html
+ * http://www.htmlhelp.com/reference/html40/entities/
+ * http://www.w3.org/TR/1999/REC-html401-19991224/sgml/entities.html
*/
struct NameId
@@ -25,1060 +25,1060 @@ struct NameId
#if IN_GCC
static NameId namesA[]={
- "Aacgr", 0x0386,
- "aacgr", 0x03AC,
- "Aacute", 0x00C1,
- "aacute", 0x00E1,
- "Abreve", 0x0102,
- "abreve", 0x0103,
- "Acirc", 0x00C2,
- "acirc", 0x00E2,
- "acute", 0x00B4,
- "Acy", 0x0410,
- "acy", 0x0430,
- "AElig", 0x00C6,
- "aelig", 0x00E6,
- "Agr", 0x0391,
- "agr", 0x03B1,
- "Agrave", 0x00C0,
- "agrave", 0x00E0,
- "aleph", 0x2135,
- "alpha", 0x03B1,
- "Amacr", 0x0100,
- "amacr", 0x0101,
- "amalg", 0x2210,
- "amp", 0x0026,
- "and", 0x2227,
- "ang", 0x2220,
- "ang90", 0x221F,
- "angmsd", 0x2221,
- "angsph", 0x2222,
- "angst", 0x212B,
- "Aogon", 0x0104,
- "aogon", 0x0105,
- "ap", 0x2248,
- "ape", 0x224A,
- "apos", 0x0027,
- "Aring", 0x00C5,
- "aring", 0x00E5,
- "ast", 0x002A,
- "asymp", 0x224D,
- "Atilde", 0x00C3,
- "atilde", 0x00E3,
- "Auml", 0x00C4,
- "auml", 0x00E4,
- NULL, 0
+ "Aacgr", 0x0386,
+ "aacgr", 0x03AC,
+ "Aacute", 0x00C1,
+ "aacute", 0x00E1,
+ "Abreve", 0x0102,
+ "abreve", 0x0103,
+ "Acirc", 0x00C2,
+ "acirc", 0x00E2,
+ "acute", 0x00B4,
+ "Acy", 0x0410,
+ "acy", 0x0430,
+ "AElig", 0x00C6,
+ "aelig", 0x00E6,
+ "Agr", 0x0391,
+ "agr", 0x03B1,
+ "Agrave", 0x00C0,
+ "agrave", 0x00E0,
+ "aleph", 0x2135,
+ "alpha", 0x03B1,
+ "Amacr", 0x0100,
+ "amacr", 0x0101,
+ "amalg", 0x2210,
+ "amp", 0x0026,
+ "and", 0x2227,
+ "ang", 0x2220,
+ "ang90", 0x221F,
+ "angmsd", 0x2221,
+ "angsph", 0x2222,
+ "angst", 0x212B,
+ "Aogon", 0x0104,
+ "aogon", 0x0105,
+ "ap", 0x2248,
+ "ape", 0x224A,
+ "apos", 0x0027,
+ "Aring", 0x00C5,
+ "aring", 0x00E5,
+ "ast", 0x002A,
+ "asymp", 0x224D,
+ "Atilde", 0x00C3,
+ "atilde", 0x00E3,
+ "Auml", 0x00C4,
+ "auml", 0x00E4,
+ NULL, 0
};
static NameId namesB[]={
- "barwed", 0x22BC,
- "Barwed", 0x2306,
- "bcong", 0x224C,
- "Bcy", 0x0411,
- "bcy", 0x0431,
- "becaus", 0x2235,
- "bepsi", 0x220D,
- "bernou", 0x212C,
- "beta", 0x03B2,
- "beth", 0x2136,
- "Bgr", 0x0392,
- "bgr", 0x03B2,
- "blank", 0x2423,
- "blk12", 0x2592,
- "blk14", 0x2591,
- "blk34", 0x2593,
- "block", 0x2588,
- "bottom", 0x22A5,
- "bowtie", 0x22C8,
- "boxdl", 0x2510,
- "boxDL", 0x2555,
- "boxdL", 0x2556,
- "boxDl", 0x2557,
- "boxdr", 0x250C,
- "boxDR", 0x2552,
- "boxDr", 0x2553,
- "boxdR", 0x2554,
- "boxh", 0x2500,
- "boxH", 0x2550,
- "boxhd", 0x252C,
- "boxhD", 0x2564,
- "boxHD", 0x2565,
- "boxHd", 0x2566,
- "boxhu", 0x2534,
- "boxhU", 0x2567,
- "boxHU", 0x2568,
- "boxHu", 0x2569,
- "boxul", 0x2518,
- "boxUL", 0x255B,
- "boxUl", 0x255C,
- "boxuL", 0x255D,
- "boxur", 0x2514,
- "boxUR", 0x2558,
- "boxuR", 0x2559,
- "boxUr", 0x255A,
- "boxv", 0x2502,
- "boxV", 0x2551,
- "boxvh", 0x253C,
- "boxvH", 0x256A,
- "boxVH", 0x256B,
- "boxVh", 0x256C,
- "boxvl", 0x2524,
- "boxvL", 0x2561,
- "boxVL", 0x2562,
- "boxVl", 0x2563,
- "boxvr", 0x251C,
- "boxvR", 0x255E,
- "boxVR", 0x255F,
- "boxVr", 0x2560,
- "bprime", 0x2035,
- "breve", 0x02D8,
- "brvbar", 0x00A6,
- "bsim", 0x223D,
- "bsime", 0x22CD,
- "bsol", 0x005C,
- "bull", 0x2022,
- "bump", 0x224E,
- "bumpe", 0x224F,
- NULL, 0
+ "barwed", 0x22BC,
+ "Barwed", 0x2306,
+ "bcong", 0x224C,
+ "Bcy", 0x0411,
+ "bcy", 0x0431,
+ "becaus", 0x2235,
+ "bepsi", 0x220D,
+ "bernou", 0x212C,
+ "beta", 0x03B2,
+ "beth", 0x2136,
+ "Bgr", 0x0392,
+ "bgr", 0x03B2,
+ "blank", 0x2423,
+ "blk12", 0x2592,
+ "blk14", 0x2591,
+ "blk34", 0x2593,
+ "block", 0x2588,
+ "bottom", 0x22A5,
+ "bowtie", 0x22C8,
+ "boxdl", 0x2510,
+ "boxDL", 0x2555,
+ "boxdL", 0x2556,
+ "boxDl", 0x2557,
+ "boxdr", 0x250C,
+ "boxDR", 0x2552,
+ "boxDr", 0x2553,
+ "boxdR", 0x2554,
+ "boxh", 0x2500,
+ "boxH", 0x2550,
+ "boxhd", 0x252C,
+ "boxhD", 0x2564,
+ "boxHD", 0x2565,
+ "boxHd", 0x2566,
+ "boxhu", 0x2534,
+ "boxhU", 0x2567,
+ "boxHU", 0x2568,
+ "boxHu", 0x2569,
+ "boxul", 0x2518,
+ "boxUL", 0x255B,
+ "boxUl", 0x255C,
+ "boxuL", 0x255D,
+ "boxur", 0x2514,
+ "boxUR", 0x2558,
+ "boxuR", 0x2559,
+ "boxUr", 0x255A,
+ "boxv", 0x2502,
+ "boxV", 0x2551,
+ "boxvh", 0x253C,
+ "boxvH", 0x256A,
+ "boxVH", 0x256B,
+ "boxVh", 0x256C,
+ "boxvl", 0x2524,
+ "boxvL", 0x2561,
+ "boxVL", 0x2562,
+ "boxVl", 0x2563,
+ "boxvr", 0x251C,
+ "boxvR", 0x255E,
+ "boxVR", 0x255F,
+ "boxVr", 0x2560,
+ "bprime", 0x2035,
+ "breve", 0x02D8,
+ "brvbar", 0x00A6,
+ "bsim", 0x223D,
+ "bsime", 0x22CD,
+ "bsol", 0x005C,
+ "bull", 0x2022,
+ "bump", 0x224E,
+ "bumpe", 0x224F,
+ NULL, 0
};
static NameId namesC[]={
- "Cacute", 0x0106,
- "cacute", 0x0107,
- "cap", 0x2229,
- "Cap", 0x22D2,
- "caret", 0x2041,
- "caron", 0x02C7,
- "Ccaron", 0x010C,
- "ccaron", 0x010D,
- "Ccedil", 0x00C7,
- "ccedil", 0x00E7,
- "Ccirc", 0x0108,
- "ccirc", 0x0109,
- "Cdot", 0x010A,
- "cdot", 0x010B,
- "cedil", 0x00B8,
- "cent", 0x00A2,
- "CHcy", 0x0427,
- "chcy", 0x0447,
- "check", 0x2713,
- "chi", 0x03C7,
- "cir", 0x25CB,
- "circ", 0x005E,
- "cire", 0x2257,
- "clubs", 0x2663,
- "colon", 0x003A,
- "colone", 0x2254,
- "comma", 0x002C,
- "commat", 0x0040,
- "comp", 0x2201,
- "compfn", 0x2218,
- "cong", 0x2245,
- "conint", 0x222E,
- "coprod", 0x2210,
- "copy", 0x00A9,
- "copysr", 0x2117,
- "cross", 0x2717,
- "cuepr", 0x22DE,
- "cuesc", 0x22DF,
- "cularr", 0x21B6,
- "cup", 0x222A,
- "Cup", 0x22D3,
- "cupre", 0x227C,
- "curarr", 0x21B7,
- "curren", 0x00A4,
- "cuvee", 0x22CE,
- "cuwed", 0x22CF,
- NULL, 0
+ "Cacute", 0x0106,
+ "cacute", 0x0107,
+ "cap", 0x2229,
+ "Cap", 0x22D2,
+ "caret", 0x2041,
+ "caron", 0x02C7,
+ "Ccaron", 0x010C,
+ "ccaron", 0x010D,
+ "Ccedil", 0x00C7,
+ "ccedil", 0x00E7,
+ "Ccirc", 0x0108,
+ "ccirc", 0x0109,
+ "Cdot", 0x010A,
+ "cdot", 0x010B,
+ "cedil", 0x00B8,
+ "cent", 0x00A2,
+ "CHcy", 0x0427,
+ "chcy", 0x0447,
+ "check", 0x2713,
+ "chi", 0x03C7,
+ "cir", 0x25CB,
+ "circ", 0x005E,
+ "cire", 0x2257,
+ "clubs", 0x2663,
+ "colon", 0x003A,
+ "colone", 0x2254,
+ "comma", 0x002C,
+ "commat", 0x0040,
+ "comp", 0x2201,
+ "compfn", 0x2218,
+ "cong", 0x2245,
+ "conint", 0x222E,
+ "coprod", 0x2210,
+ "copy", 0x00A9,
+ "copysr", 0x2117,
+ "cross", 0x2717,
+ "cuepr", 0x22DE,
+ "cuesc", 0x22DF,
+ "cularr", 0x21B6,
+ "cup", 0x222A,
+ "Cup", 0x22D3,
+ "cupre", 0x227C,
+ "curarr", 0x21B7,
+ "curren", 0x00A4,
+ "cuvee", 0x22CE,
+ "cuwed", 0x22CF,
+ NULL, 0
};
static NameId namesD[]={
- "dagger", 0x2020,
- "Dagger", 0x2021,
- "daleth", 0x2138,
- "darr", 0x2193,
- "dArr", 0x21D3,
- "darr2", 0x21CA,
- "dash", 0x2010,
- "dashv", 0x22A3,
- "dblac", 0x02DD,
- "Dcaron", 0x010E,
- "dcaron", 0x010F,
- "Dcy", 0x0414,
- "dcy", 0x0434,
- "deg", 0x00B0,
- "Delta", 0x0394,
- "delta", 0x03B4,
- "Dgr", 0x0394,
- "dgr", 0x03B4,
- "dharl", 0x21C3,
- "dharr", 0x21C2,
- "diam", 0x22C4,
- "diams", 0x2666,
- "die", 0x00A8,
- "divide", 0x00F7,
- "divonx", 0x22C7,
- "DJcy", 0x0402,
- "djcy", 0x0452,
- "dlarr", 0x2199,
- "dlcorn", 0x231E,
- "dlcrop", 0x230D,
- "dollar", 0x0024,
- "Dot", 0x00A8,
- "dot", 0x02D9,
- "DotDot", 0x20DC,
- "drarr", 0x2198,
- "drcorn", 0x231F,
- "drcrop", 0x230C,
- "DScy", 0x0405,
- "dscy", 0x0455,
- "Dstrok", 0x0110,
- "dstrok", 0x0111,
- "dtri", 0x25BF,
- "dtrif", 0x25BE,
- "DZcy", 0x040F,
- "dzcy", 0x045F,
- NULL, 0
+ "dagger", 0x2020,
+ "Dagger", 0x2021,
+ "daleth", 0x2138,
+ "darr", 0x2193,
+ "dArr", 0x21D3,
+ "darr2", 0x21CA,
+ "dash", 0x2010,
+ "dashv", 0x22A3,
+ "dblac", 0x02DD,
+ "Dcaron", 0x010E,
+ "dcaron", 0x010F,
+ "Dcy", 0x0414,
+ "dcy", 0x0434,
+ "deg", 0x00B0,
+ "Delta", 0x0394,
+ "delta", 0x03B4,
+ "Dgr", 0x0394,
+ "dgr", 0x03B4,
+ "dharl", 0x21C3,
+ "dharr", 0x21C2,
+ "diam", 0x22C4,
+ "diams", 0x2666,
+ "die", 0x00A8,
+ "divide", 0x00F7,
+ "divonx", 0x22C7,
+ "DJcy", 0x0402,
+ "djcy", 0x0452,
+ "dlarr", 0x2199,
+ "dlcorn", 0x231E,
+ "dlcrop", 0x230D,
+ "dollar", 0x0024,
+ "Dot", 0x00A8,
+ "dot", 0x02D9,
+ "DotDot", 0x20DC,
+ "drarr", 0x2198,
+ "drcorn", 0x231F,
+ "drcrop", 0x230C,
+ "DScy", 0x0405,
+ "dscy", 0x0455,
+ "Dstrok", 0x0110,
+ "dstrok", 0x0111,
+ "dtri", 0x25BF,
+ "dtrif", 0x25BE,
+ "DZcy", 0x040F,
+ "dzcy", 0x045F,
+ NULL, 0
};
static NameId namesE[]={
- "Eacgr", 0x0388,
- "eacgr", 0x03AD,
- "Eacute", 0x00C9,
- "eacute", 0x00E9,
- "Ecaron", 0x011A,
- "ecaron", 0x011B,
- "ecir", 0x2256,
- "Ecirc", 0x00CA,
- "ecirc", 0x00EA,
- "ecolon", 0x2255,
- "Ecy", 0x042D,
- "ecy", 0x044D,
- "Edot", 0x0116,
- "edot", 0x0117,
- "eDot", 0x2251,
- "EEacgr", 0x0389,
- "eeacgr", 0x03AE,
- "EEgr", 0x0397,
- "eegr", 0x03B7,
- "efDot", 0x2252,
- "Egr", 0x0395,
- "egr", 0x03B5,
- "Egrave", 0x00C8,
- "egrave", 0x00E8,
- "egs", 0x22DD,
- "ell", 0x2113,
- "els", 0x22DC,
- "Emacr", 0x0112,
- "emacr", 0x0113,
- "empty", 0x2205,
- "emsp", 0x2003,
- "emsp13", 0x2004,
- "emsp14", 0x2005,
- "ENG", 0x014A,
- "eng", 0x014B,
- "ensp", 0x2002,
- "Eogon", 0x0118,
- "eogon", 0x0119,
- "epsi", 0x220A,
- "epsis", 0x220A,
- "epsiv", 0x03B5,
- "equals", 0x003D,
- "equiv", 0x2261,
- "erDot", 0x2253,
- "esdot", 0x2250,
- "eta", 0x03B7,
- "ETH", 0x00D0,
- "eth", 0x00F0,
- "Euml", 0x00CB,
- "euml", 0x00EB,
- "excl", 0x0021,
- "exist", 0x2203,
- NULL, 0
+ "Eacgr", 0x0388,
+ "eacgr", 0x03AD,
+ "Eacute", 0x00C9,
+ "eacute", 0x00E9,
+ "Ecaron", 0x011A,
+ "ecaron", 0x011B,
+ "ecir", 0x2256,
+ "Ecirc", 0x00CA,
+ "ecirc", 0x00EA,
+ "ecolon", 0x2255,
+ "Ecy", 0x042D,
+ "ecy", 0x044D,
+ "Edot", 0x0116,
+ "edot", 0x0117,
+ "eDot", 0x2251,
+ "EEacgr", 0x0389,
+ "eeacgr", 0x03AE,
+ "EEgr", 0x0397,
+ "eegr", 0x03B7,
+ "efDot", 0x2252,
+ "Egr", 0x0395,
+ "egr", 0x03B5,
+ "Egrave", 0x00C8,
+ "egrave", 0x00E8,
+ "egs", 0x22DD,
+ "ell", 0x2113,
+ "els", 0x22DC,
+ "Emacr", 0x0112,
+ "emacr", 0x0113,
+ "empty", 0x2205,
+ "emsp", 0x2003,
+ "emsp13", 0x2004,
+ "emsp14", 0x2005,
+ "ENG", 0x014A,
+ "eng", 0x014B,
+ "ensp", 0x2002,
+ "Eogon", 0x0118,
+ "eogon", 0x0119,
+ "epsi", 0x220A,
+ "epsis", 0x220A,
+ "epsiv", 0x03B5,
+ "equals", 0x003D,
+ "equiv", 0x2261,
+ "erDot", 0x2253,
+ "esdot", 0x2250,
+ "eta", 0x03B7,
+ "ETH", 0x00D0,
+ "eth", 0x00F0,
+ "Euml", 0x00CB,
+ "euml", 0x00EB,
+ "excl", 0x0021,
+ "exist", 0x2203,
+ NULL, 0
};
static NameId namesF[]={
- "Fcy", 0x0424,
- "fcy", 0x0444,
- "female", 0x2640,
- "ffilig", 0xFB03,
- "fflig", 0xFB00,
- "ffllig", 0xFB04,
- "filig", 0xFB01,
- "flat", 0x266D,
- "fllig", 0xFB02,
- "fnof", 0x0192,
- "forall", 0x2200,
- "fork", 0x22D4,
- "frac12", 0x00BD,
- "frac13", 0x2153,
- "frac14", 0x00BC,
- "frac15", 0x2155,
- "frac16", 0x2159,
- "frac18", 0x215B,
- "frac23", 0x2154,
- "frac25", 0x2156,
- "frac34", 0x00BE,
- "frac35", 0x2157,
- "frac38", 0x215C,
- "frac45", 0x2158,
- "frac56", 0x215A,
- "frac58", 0x215D,
- "frac78", 0x215E,
- "frown", 0x2322,
- NULL, 0
+ "Fcy", 0x0424,
+ "fcy", 0x0444,
+ "female", 0x2640,
+ "ffilig", 0xFB03,
+ "fflig", 0xFB00,
+ "ffllig", 0xFB04,
+ "filig", 0xFB01,
+ "flat", 0x266D,
+ "fllig", 0xFB02,
+ "fnof", 0x0192,
+ "forall", 0x2200,
+ "fork", 0x22D4,
+ "frac12", 0x00BD,
+ "frac13", 0x2153,
+ "frac14", 0x00BC,
+ "frac15", 0x2155,
+ "frac16", 0x2159,
+ "frac18", 0x215B,
+ "frac23", 0x2154,
+ "frac25", 0x2156,
+ "frac34", 0x00BE,
+ "frac35", 0x2157,
+ "frac38", 0x215C,
+ "frac45", 0x2158,
+ "frac56", 0x215A,
+ "frac58", 0x215D,
+ "frac78", 0x215E,
+ "frown", 0x2322,
+ NULL, 0
};
static NameId namesG[]={
- "gacute", 0x01F5,
- "Gamma", 0x0393,
- "gamma", 0x03B3,
- "gammad", 0x03DC,
- "gap", 0x2273,
- "Gbreve", 0x011E,
- "gbreve", 0x011F,
- "Gcedil", 0x0122,
- "Gcirc", 0x011C,
- "gcirc", 0x011D,
- "Gcy", 0x0413,
- "gcy", 0x0433,
- "Gdot", 0x0120,
- "gdot", 0x0121,
- "ge", 0x2265,
- "gE", 0x2267,
- "gel", 0x22DB,
- "gEl", 0x22DB,
- "ges", 0x2265,
- "Gg", 0x22D9,
- "Ggr", 0x0393,
- "ggr", 0x03B3,
- "gimel", 0x2137,
- "GJcy", 0x0403,
- "gjcy", 0x0453,
- "gl", 0x2277,
- "gnap", 0xE411,
- "gne", 0x2269,
- "gnE", 0x2269,
- "gnsim", 0x22E7,
- "grave", 0x0060,
- "gsdot", 0x22D7,
- "gsim", 0x2273,
- "gt", 0x003E,
- "Gt", 0x226B,
- "gvnE", 0x2269,
- NULL, 0
+ "gacute", 0x01F5,
+ "Gamma", 0x0393,
+ "gamma", 0x03B3,
+ "gammad", 0x03DC,
+ "gap", 0x2273,
+ "Gbreve", 0x011E,
+ "gbreve", 0x011F,
+ "Gcedil", 0x0122,
+ "Gcirc", 0x011C,
+ "gcirc", 0x011D,
+ "Gcy", 0x0413,
+ "gcy", 0x0433,
+ "Gdot", 0x0120,
+ "gdot", 0x0121,
+ "ge", 0x2265,
+ "gE", 0x2267,
+ "gel", 0x22DB,
+ "gEl", 0x22DB,
+ "ges", 0x2265,
+ "Gg", 0x22D9,
+ "Ggr", 0x0393,
+ "ggr", 0x03B3,
+ "gimel", 0x2137,
+ "GJcy", 0x0403,
+ "gjcy", 0x0453,
+ "gl", 0x2277,
+ "gnap", 0xE411,
+ "gne", 0x2269,
+ "gnE", 0x2269,
+ "gnsim", 0x22E7,
+ "grave", 0x0060,
+ "gsdot", 0x22D7,
+ "gsim", 0x2273,
+ "gt", 0x003E,
+ "Gt", 0x226B,
+ "gvnE", 0x2269,
+ NULL, 0
};
static NameId namesH[]={
- "hairsp", 0x200A,
- "half", 0x00BD,
- "hamilt", 0x210B,
- "HARDcy", 0x042A,
- "hardcy", 0x044A,
- "harr", 0x2194,
- "hArr", 0x21D4,
- "harrw", 0x21AD,
- "Hcirc", 0x0124,
- "hcirc", 0x0125,
- "hearts", 0x2665,
- "hellip", 0x2026,
- "horbar", 0x2015,
- "Hstrok", 0x0126,
- "hstrok", 0x0127,
- "hybull", 0x2043,
- "hyphen", 0x002D,
- NULL, 0
+ "hairsp", 0x200A,
+ "half", 0x00BD,
+ "hamilt", 0x210B,
+ "HARDcy", 0x042A,
+ "hardcy", 0x044A,
+ "harr", 0x2194,
+ "hArr", 0x21D4,
+ "harrw", 0x21AD,
+ "Hcirc", 0x0124,
+ "hcirc", 0x0125,
+ "hearts", 0x2665,
+ "hellip", 0x2026,
+ "horbar", 0x2015,
+ "Hstrok", 0x0126,
+ "hstrok", 0x0127,
+ "hybull", 0x2043,
+ "hyphen", 0x002D,
+ NULL, 0
};
static NameId namesI[]={
- "Iacgr", 0x038A,
- "iacgr", 0x03AF,
- "Iacute", 0x00CD,
- "iacute", 0x00ED,
- "Icirc", 0x00CE,
- "icirc", 0x00EE,
- "Icy", 0x0418,
- "icy", 0x0438,
- "idiagr", 0x0390,
- "Idigr", 0x03AA,
- "idigr", 0x03CA,
- "Idot", 0x0130,
- "IEcy", 0x0415,
- "iecy", 0x0435,
- "iexcl", 0x00A1,
- "iff", 0x21D4,
- "Igr", 0x0399,
- "igr", 0x03B9,
- "Igrave", 0x00CC,
- "igrave", 0x00EC,
- "IJlig", 0x0132,
- "ijlig", 0x0133,
- "Imacr", 0x012A,
- "imacr", 0x012B,
- "image", 0x2111,
- "incare", 0x2105,
- "infin", 0x221E,
- "inodot", 0x0131,
- "int", 0x222B,
- "intcal", 0x22BA,
- "IOcy", 0x0401,
- "iocy", 0x0451,
- "Iogon", 0x012E,
- "iogon", 0x012F,
- "iota", 0x03B9,
- "iquest", 0x00BF,
- "isin", 0x220A,
- "Itilde", 0x0128,
- "itilde", 0x0129,
- "Iukcy", 0x0406,
- "iukcy", 0x0456,
- "Iuml", 0x00CF,
- "iuml", 0x00EF,
- NULL, 0
+ "Iacgr", 0x038A,
+ "iacgr", 0x03AF,
+ "Iacute", 0x00CD,
+ "iacute", 0x00ED,
+ "Icirc", 0x00CE,
+ "icirc", 0x00EE,
+ "Icy", 0x0418,
+ "icy", 0x0438,
+ "idiagr", 0x0390,
+ "Idigr", 0x03AA,
+ "idigr", 0x03CA,
+ "Idot", 0x0130,
+ "IEcy", 0x0415,
+ "iecy", 0x0435,
+ "iexcl", 0x00A1,
+ "iff", 0x21D4,
+ "Igr", 0x0399,
+ "igr", 0x03B9,
+ "Igrave", 0x00CC,
+ "igrave", 0x00EC,
+ "IJlig", 0x0132,
+ "ijlig", 0x0133,
+ "Imacr", 0x012A,
+ "imacr", 0x012B,
+ "image", 0x2111,
+ "incare", 0x2105,
+ "infin", 0x221E,
+ "inodot", 0x0131,
+ "int", 0x222B,
+ "intcal", 0x22BA,
+ "IOcy", 0x0401,
+ "iocy", 0x0451,
+ "Iogon", 0x012E,
+ "iogon", 0x012F,
+ "iota", 0x03B9,
+ "iquest", 0x00BF,
+ "isin", 0x220A,
+ "Itilde", 0x0128,
+ "itilde", 0x0129,
+ "Iukcy", 0x0406,
+ "iukcy", 0x0456,
+ "Iuml", 0x00CF,
+ "iuml", 0x00EF,
+ NULL, 0
};
static NameId namesJ[]={
- "Jcirc", 0x0134,
- "jcirc", 0x0135,
- "Jcy", 0x0419,
- "jcy", 0x0439,
- "Jsercy", 0x0408,
- "jsercy", 0x0458,
- "Jukcy", 0x0404,
- "jukcy", 0x0454,
- NULL, 0
+ "Jcirc", 0x0134,
+ "jcirc", 0x0135,
+ "Jcy", 0x0419,
+ "jcy", 0x0439,
+ "Jsercy", 0x0408,
+ "jsercy", 0x0458,
+ "Jukcy", 0x0404,
+ "jukcy", 0x0454,
+ NULL, 0
};
static NameId namesK[]={
- "kappa", 0x03BA,
- "kappav", 0x03F0,
- "Kcedil", 0x0136,
- "kcedil", 0x0137,
- "Kcy", 0x041A,
- "kcy", 0x043A,
- "Kgr", 0x039A,
- "kgr", 0x03BA,
- "kgreen", 0x0138,
- "KHcy", 0x0425,
- "khcy", 0x0445,
- "KHgr", 0x03A7,
- "khgr", 0x03C7,
- "KJcy", 0x040C,
- "kjcy", 0x045C,
- NULL, 0
+ "kappa", 0x03BA,
+ "kappav", 0x03F0,
+ "Kcedil", 0x0136,
+ "kcedil", 0x0137,
+ "Kcy", 0x041A,
+ "kcy", 0x043A,
+ "Kgr", 0x039A,
+ "kgr", 0x03BA,
+ "kgreen", 0x0138,
+ "KHcy", 0x0425,
+ "khcy", 0x0445,
+ "KHgr", 0x03A7,
+ "khgr", 0x03C7,
+ "KJcy", 0x040C,
+ "kjcy", 0x045C,
+ NULL, 0
};
static NameId namesL[]={
- "lAarr", 0x21DA,
- "Lacute", 0x0139,
- "lacute", 0x013A,
- "lagran", 0x2112,
- "Lambda", 0x039B,
- "lambda", 0x03BB,
- "lang", 0x3008,
- "lap", 0x2272,
- "laquo", 0x00AB,
- "larr", 0x2190,
- "Larr", 0x219E,
- "lArr", 0x21D0,
- "larr2", 0x21C7,
- "larrhk", 0x21A9,
- "larrlp", 0x21AB,
- "larrtl", 0x21A2,
- "Lcaron", 0x013D,
- "lcaron", 0x013E,
- "Lcedil", 0x013B,
- "lcedil", 0x013C,
- "lceil", 0x2308,
- "lcub", 0x007B,
- "Lcy", 0x041B,
- "lcy", 0x043B,
- "ldot", 0x22D6,
- "ldquo", 0x201C,
- "ldquor", 0x201E,
- "le", 0x2264,
- "lE", 0x2266,
- "leg", 0x22DA,
- "lEg", 0x22DA,
- "les", 0x2264,
- "lfloor", 0x230A,
- "lg", 0x2276,
- "Lgr", 0x039B,
- "lgr", 0x03BB,
- "lhard", 0x21BD,
- "lharu", 0x21BC,
- "lhblk", 0x2584,
- "LJcy", 0x0409,
- "ljcy", 0x0459,
- "Ll", 0x22D8,
- "Lmidot", 0x013F,
- "lmidot", 0x0140,
- "lnap", 0xE2A2,
- "lne", 0x2268,
- "lnE", 0x2268,
- "lnsim", 0x22E6,
- "lowast", 0x2217,
- "lowbar", 0x005F,
- "loz", 0x25CA,
- "lozf", 0x2726,
- "lpar", 0x0028,
- "lrarr2", 0x21C6,
- "lrhar2", 0x21CB,
- "lsh", 0x21B0,
- "lsim", 0x2272,
- "lsqb", 0x005B,
- "lsquo", 0x2018,
- "lsquor", 0x201A,
- "Lstrok", 0x0141,
- "lstrok", 0x0142,
- "lt", 0x003C,
- "Lt", 0x226A,
- "lthree", 0x22CB,
- "ltimes", 0x22C9,
- "ltri", 0x25C3,
- "ltrie", 0x22B4,
- "ltrif", 0x25C2,
- "lvnE", 0x2268,
- NULL, 0
+ "lAarr", 0x21DA,
+ "Lacute", 0x0139,
+ "lacute", 0x013A,
+ "lagran", 0x2112,
+ "Lambda", 0x039B,
+ "lambda", 0x03BB,
+ "lang", 0x3008,
+ "lap", 0x2272,
+ "laquo", 0x00AB,
+ "larr", 0x2190,
+ "Larr", 0x219E,
+ "lArr", 0x21D0,
+ "larr2", 0x21C7,
+ "larrhk", 0x21A9,
+ "larrlp", 0x21AB,
+ "larrtl", 0x21A2,
+ "Lcaron", 0x013D,
+ "lcaron", 0x013E,
+ "Lcedil", 0x013B,
+ "lcedil", 0x013C,
+ "lceil", 0x2308,
+ "lcub", 0x007B,
+ "Lcy", 0x041B,
+ "lcy", 0x043B,
+ "ldot", 0x22D6,
+ "ldquo", 0x201C,
+ "ldquor", 0x201E,
+ "le", 0x2264,
+ "lE", 0x2266,
+ "leg", 0x22DA,
+ "lEg", 0x22DA,
+ "les", 0x2264,
+ "lfloor", 0x230A,
+ "lg", 0x2276,
+ "Lgr", 0x039B,
+ "lgr", 0x03BB,
+ "lhard", 0x21BD,
+ "lharu", 0x21BC,
+ "lhblk", 0x2584,
+ "LJcy", 0x0409,
+ "ljcy", 0x0459,
+ "Ll", 0x22D8,
+ "Lmidot", 0x013F,
+ "lmidot", 0x0140,
+ "lnap", 0xE2A2,
+ "lne", 0x2268,
+ "lnE", 0x2268,
+ "lnsim", 0x22E6,
+ "lowast", 0x2217,
+ "lowbar", 0x005F,
+ "loz", 0x25CA,
+ "lozf", 0x2726,
+ "lpar", 0x0028,
+ "lrarr2", 0x21C6,
+ "lrhar2", 0x21CB,
+ "lsh", 0x21B0,
+ "lsim", 0x2272,
+ "lsqb", 0x005B,
+ "lsquo", 0x2018,
+ "lsquor", 0x201A,
+ "Lstrok", 0x0141,
+ "lstrok", 0x0142,
+ "lt", 0x003C,
+ "Lt", 0x226A,
+ "lthree", 0x22CB,
+ "ltimes", 0x22C9,
+ "ltri", 0x25C3,
+ "ltrie", 0x22B4,
+ "ltrif", 0x25C2,
+ "lvnE", 0x2268,
+ NULL, 0
};
static NameId namesM[]={
- "macr", 0x00AF,
- "male", 0x2642,
- "malt", 0x2720,
- "map", 0x21A6,
- "marker", 0x25AE,
- "Mcy", 0x041C,
- "mcy", 0x043C,
- "mdash", 0x2014,
- "Mgr", 0x039C,
- "mgr", 0x03BC,
- "micro", 0x00B5,
- "mid", 0x2223,
- "middot", 0x00B7,
- "minus", 0x2212,
- "minusb", 0x229F,
- "mldr", 0x2026,
- "mnplus", 0x2213,
- "models", 0x22A7,
- "mu", 0x03BC,
- "mumap", 0x22B8,
- NULL, 0
+ "macr", 0x00AF,
+ "male", 0x2642,
+ "malt", 0x2720,
+ "map", 0x21A6,
+ "marker", 0x25AE,
+ "Mcy", 0x041C,
+ "mcy", 0x043C,
+ "mdash", 0x2014,
+ "Mgr", 0x039C,
+ "mgr", 0x03BC,
+ "micro", 0x00B5,
+ "mid", 0x2223,
+ "middot", 0x00B7,
+ "minus", 0x2212,
+ "minusb", 0x229F,
+ "mldr", 0x2026,
+ "mnplus", 0x2213,
+ "models", 0x22A7,
+ "mu", 0x03BC,
+ "mumap", 0x22B8,
+ NULL, 0
};
static NameId namesN[]={
- "nabla", 0x2207,
- "Nacute", 0x0143,
- "nacute", 0x0144,
- "nap", 0x2249,
- "napos", 0x0149,
- "natur", 0x266E,
-// "nbsp", 0x00A0,
- "nbsp", 32, // make non-breaking space appear as space
- "Ncaron", 0x0147,
- "ncaron", 0x0148,
- "Ncedil", 0x0145,
- "ncedil", 0x0146,
- "ncong", 0x2247,
- "Ncy", 0x041D,
- "ncy", 0x043D,
- "ndash", 0x2013,
- "ne", 0x2260,
- "nearr", 0x2197,
- "nequiv", 0x2262,
- "nexist", 0x2204,
- "nge", 0x2271,
- "ngE", 0x2271,
- "nges", 0x2271,
- "Ngr", 0x039D,
- "ngr", 0x03BD,
- "ngt", 0x226F,
- "nharr", 0x21AE,
- "nhArr", 0x21CE,
- "ni", 0x220D,
- "NJcy", 0x040A,
- "njcy", 0x045A,
- "nlarr", 0x219A,
- "nlArr", 0x21CD,
- "nldr", 0x2025,
- "nle", 0x2270,
- "nlE", 0x2270,
- "nles", 0x2270,
- "nlt", 0x226E,
- "nltri", 0x22EA,
- "nltrie", 0x22EC,
- "nmid", 0x2224,
- "not", 0x00AC,
- "notin", 0x2209,
- "npar", 0x2226,
- "npr", 0x2280,
- "npre", 0x22E0,
- "nrarr", 0x219B,
- "nrArr", 0x21CF,
- "nrtri", 0x22EB,
- "nrtrie", 0x22ED,
- "nsc", 0x2281,
- "nsce", 0x22E1,
- "nsim", 0x2241,
- "nsime", 0x2244,
- "nsmid", 0xE2AA,
- "nspar", 0x2226,
- "nsub", 0x2284,
- "nsube", 0x2288,
- "nsubE", 0x2288,
- "nsup", 0x2285,
- "nsupe", 0x2289,
- "nsupE", 0x2289,
- "Ntilde", 0x00D1,
- "ntilde", 0x00F1,
- "nu", 0x03BD,
- "num", 0x0023,
- "numero", 0x2116,
- "numsp", 0x2007,
- "nvdash", 0x22AC,
- "nvDash", 0x22AD,
- "nVdash", 0x22AE,
- "nVDash", 0x22AF,
- "nwarr", 0x2196,
- NULL, 0
+ "nabla", 0x2207,
+ "Nacute", 0x0143,
+ "nacute", 0x0144,
+ "nap", 0x2249,
+ "napos", 0x0149,
+ "natur", 0x266E,
+// "nbsp", 0x00A0,
+ "nbsp", 32, // make non-breaking space appear as space
+ "Ncaron", 0x0147,
+ "ncaron", 0x0148,
+ "Ncedil", 0x0145,
+ "ncedil", 0x0146,
+ "ncong", 0x2247,
+ "Ncy", 0x041D,
+ "ncy", 0x043D,
+ "ndash", 0x2013,
+ "ne", 0x2260,
+ "nearr", 0x2197,
+ "nequiv", 0x2262,
+ "nexist", 0x2204,
+ "nge", 0x2271,
+ "ngE", 0x2271,
+ "nges", 0x2271,
+ "Ngr", 0x039D,
+ "ngr", 0x03BD,
+ "ngt", 0x226F,
+ "nharr", 0x21AE,
+ "nhArr", 0x21CE,
+ "ni", 0x220D,
+ "NJcy", 0x040A,
+ "njcy", 0x045A,
+ "nlarr", 0x219A,
+ "nlArr", 0x21CD,
+ "nldr", 0x2025,
+ "nle", 0x2270,
+ "nlE", 0x2270,
+ "nles", 0x2270,
+ "nlt", 0x226E,
+ "nltri", 0x22EA,
+ "nltrie", 0x22EC,
+ "nmid", 0x2224,
+ "not", 0x00AC,
+ "notin", 0x2209,
+ "npar", 0x2226,
+ "npr", 0x2280,
+ "npre", 0x22E0,
+ "nrarr", 0x219B,
+ "nrArr", 0x21CF,
+ "nrtri", 0x22EB,
+ "nrtrie", 0x22ED,
+ "nsc", 0x2281,
+ "nsce", 0x22E1,
+ "nsim", 0x2241,
+ "nsime", 0x2244,
+ "nsmid", 0xE2AA,
+ "nspar", 0x2226,
+ "nsub", 0x2284,
+ "nsube", 0x2288,
+ "nsubE", 0x2288,
+ "nsup", 0x2285,
+ "nsupe", 0x2289,
+ "nsupE", 0x2289,
+ "Ntilde", 0x00D1,
+ "ntilde", 0x00F1,
+ "nu", 0x03BD,
+ "num", 0x0023,
+ "numero", 0x2116,
+ "numsp", 0x2007,
+ "nvdash", 0x22AC,
+ "nvDash", 0x22AD,
+ "nVdash", 0x22AE,
+ "nVDash", 0x22AF,
+ "nwarr", 0x2196,
+ NULL, 0
};
static NameId namesO[]={
- "Oacgr", 0x038C,
- "oacgr", 0x03CC,
- "Oacute", 0x00D3,
- "oacute", 0x00F3,
- "oast", 0x229B,
- "ocir", 0x229A,
- "Ocirc", 0x00D4,
- "ocirc", 0x00F4,
- "Ocy", 0x041E,
- "ocy", 0x043E,
- "odash", 0x229D,
- "Odblac", 0x0150,
- "odblac", 0x0151,
- "odot", 0x2299,
- "OElig", 0x0152,
- "oelig", 0x0153,
- "ogon", 0x02DB,
- "Ogr", 0x039F,
- "ogr", 0x03BF,
- "Ograve", 0x00D2,
- "ograve", 0x00F2,
- "OHacgr", 0x038F,
- "ohacgr", 0x03CE,
- "OHgr", 0x03A9,
- "ohgr", 0x03C9,
- "ohm", 0x2126,
- "olarr", 0x21BA,
- "Omacr", 0x014C,
- "omacr", 0x014D,
- "Omega", 0x03A9,
- "omega", 0x03C9,
- "ominus", 0x2296,
- "oplus", 0x2295,
- "or", 0x2228,
- "orarr", 0x21BB,
- "order", 0x2134,
- "ordf", 0x00AA,
- "ordm", 0x00BA,
- "oS", 0x24C8,
- "Oslash", 0x00D8,
- "oslash", 0x00F8,
- "osol", 0x2298,
- "Otilde", 0x00D5,
- "otilde", 0x00F5,
- "otimes", 0x2297,
- "Ouml", 0x00D6,
- "ouml", 0x00F6,
- NULL, 0
+ "Oacgr", 0x038C,
+ "oacgr", 0x03CC,
+ "Oacute", 0x00D3,
+ "oacute", 0x00F3,
+ "oast", 0x229B,
+ "ocir", 0x229A,
+ "Ocirc", 0x00D4,
+ "ocirc", 0x00F4,
+ "Ocy", 0x041E,
+ "ocy", 0x043E,
+ "odash", 0x229D,
+ "Odblac", 0x0150,
+ "odblac", 0x0151,
+ "odot", 0x2299,
+ "OElig", 0x0152,
+ "oelig", 0x0153,
+ "ogon", 0x02DB,
+ "Ogr", 0x039F,
+ "ogr", 0x03BF,
+ "Ograve", 0x00D2,
+ "ograve", 0x00F2,
+ "OHacgr", 0x038F,
+ "ohacgr", 0x03CE,
+ "OHgr", 0x03A9,
+ "ohgr", 0x03C9,
+ "ohm", 0x2126,
+ "olarr", 0x21BA,
+ "Omacr", 0x014C,
+ "omacr", 0x014D,
+ "Omega", 0x03A9,
+ "omega", 0x03C9,
+ "ominus", 0x2296,
+ "oplus", 0x2295,
+ "or", 0x2228,
+ "orarr", 0x21BB,
+ "order", 0x2134,
+ "ordf", 0x00AA,
+ "ordm", 0x00BA,
+ "oS", 0x24C8,
+ "Oslash", 0x00D8,
+ "oslash", 0x00F8,
+ "osol", 0x2298,
+ "Otilde", 0x00D5,
+ "otilde", 0x00F5,
+ "otimes", 0x2297,
+ "Ouml", 0x00D6,
+ "ouml", 0x00F6,
+ NULL, 0
};
static NameId namesP[]={
- "par", 0x2225,
- "para", 0x00B6,
- "part", 0x2202,
- "Pcy", 0x041F,
- "pcy", 0x043F,
- "percnt", 0x0025,
- "period", 0x002E,
- "permil", 0x2030,
- "perp", 0x22A5,
- "Pgr", 0x03A0,
- "pgr", 0x03C0,
- "PHgr", 0x03A6,
- "phgr", 0x03C6,
- "Phi", 0x03A6,
- "phis", 0x03C6,
- "phiv", 0x03D5,
- "phmmat", 0x2133,
- "phone", 0x260E,
- "Pi", 0x03A0,
- "pi", 0x03C0,
- "piv", 0x03D6,
- "planck", 0x210F,
- "plus", 0x002B,
- "plusb", 0x229E,
- "plusdo", 0x2214,
- "plusmn", 0x00B1,
- "pound", 0x00A3,
- "pr", 0x227A,
- "prap", 0x227E,
- "pre", 0x227C,
- "prime", 0x2032,
- "Prime", 0x2033,
- "prnap", 0x22E8,
- "prnE", 0xE2B3,
- "prnsim", 0x22E8,
- "prod", 0x220F,
- "prop", 0x221D,
- "prsim", 0x227E,
- "PSgr", 0x03A8,
- "psgr", 0x03C8,
- "Psi", 0x03A8,
- "psi", 0x03C8,
- "puncsp", 0x2008,
- NULL, 0
+ "par", 0x2225,
+ "para", 0x00B6,
+ "part", 0x2202,
+ "Pcy", 0x041F,
+ "pcy", 0x043F,
+ "percnt", 0x0025,
+ "period", 0x002E,
+ "permil", 0x2030,
+ "perp", 0x22A5,
+ "Pgr", 0x03A0,
+ "pgr", 0x03C0,
+ "PHgr", 0x03A6,
+ "phgr", 0x03C6,
+ "Phi", 0x03A6,
+ "phis", 0x03C6,
+ "phiv", 0x03D5,
+ "phmmat", 0x2133,
+ "phone", 0x260E,
+ "Pi", 0x03A0,
+ "pi", 0x03C0,
+ "piv", 0x03D6,
+ "planck", 0x210F,
+ "plus", 0x002B,
+ "plusb", 0x229E,
+ "plusdo", 0x2214,
+ "plusmn", 0x00B1,
+ "pound", 0x00A3,
+ "pr", 0x227A,
+ "prap", 0x227E,
+ "pre", 0x227C,
+ "prime", 0x2032,
+ "Prime", 0x2033,
+ "prnap", 0x22E8,
+ "prnE", 0xE2B3,
+ "prnsim", 0x22E8,
+ "prod", 0x220F,
+ "prop", 0x221D,
+ "prsim", 0x227E,
+ "PSgr", 0x03A8,
+ "psgr", 0x03C8,
+ "Psi", 0x03A8,
+ "psi", 0x03C8,
+ "puncsp", 0x2008,
+ NULL, 0
};
static NameId namesQ[]={
- "quest", 0x003F,
- "quot", 0x0022,
- NULL, 0
+ "quest", 0x003F,
+ "quot", 0x0022,
+ NULL, 0
};
static NameId namesR[]={
- "rAarr", 0x21DB,
- "Racute", 0x0154,
- "racute", 0x0155,
- "radic", 0x221A,
- "rang", 0x3009,
- "raquo", 0x00BB,
- "rarr", 0x2192,
- "Rarr", 0x21A0,
- "rArr", 0x21D2,
- "rarr2", 0x21C9,
- "rarrhk", 0x21AA,
- "rarrlp", 0x21AC,
- "rarrtl", 0x21A3,
- "rarrw", 0x219D,
- "Rcaron", 0x0158,
- "rcaron", 0x0159,
- "Rcedil", 0x0156,
- "rcedil", 0x0157,
- "rceil", 0x2309,
- "rcub", 0x007D,
- "Rcy", 0x0420,
- "rcy", 0x0440,
- "rdquo", 0x201D,
- "rdquor", 0x201C,
- "real", 0x211C,
- "rect", 0x25AD,
- "reg", 0x00AE,
- "rfloor", 0x230B,
- "Rgr", 0x03A1,
- "rgr", 0x03C1,
- "rhard", 0x21C1,
- "rharu", 0x21C0,
- "rho", 0x03C1,
- "rhov", 0x03F1,
- "ring", 0x02DA,
- "rlarr2", 0x21C4,
- "rlhar2", 0x21CC,
- "rpar", 0x0029,
- "rpargt", 0xE291,
- "rsh", 0x21B1,
- "rsqb", 0x005D,
- "rsquo", 0x2019,
- "rsquor", 0x2018,
- "rthree", 0x22CC,
- "rtimes", 0x22CA,
- "rtri", 0x25B9,
- "rtrie", 0x22B5,
- "rtrif", 0x25B8,
- "rx", 0x211E,
- NULL, 0
+ "rAarr", 0x21DB,
+ "Racute", 0x0154,
+ "racute", 0x0155,
+ "radic", 0x221A,
+ "rang", 0x3009,
+ "raquo", 0x00BB,
+ "rarr", 0x2192,
+ "Rarr", 0x21A0,
+ "rArr", 0x21D2,
+ "rarr2", 0x21C9,
+ "rarrhk", 0x21AA,
+ "rarrlp", 0x21AC,
+ "rarrtl", 0x21A3,
+ "rarrw", 0x219D,
+ "Rcaron", 0x0158,
+ "rcaron", 0x0159,
+ "Rcedil", 0x0156,
+ "rcedil", 0x0157,
+ "rceil", 0x2309,
+ "rcub", 0x007D,
+ "Rcy", 0x0420,
+ "rcy", 0x0440,
+ "rdquo", 0x201D,
+ "rdquor", 0x201C,
+ "real", 0x211C,
+ "rect", 0x25AD,
+ "reg", 0x00AE,
+ "rfloor", 0x230B,
+ "Rgr", 0x03A1,
+ "rgr", 0x03C1,
+ "rhard", 0x21C1,
+ "rharu", 0x21C0,
+ "rho", 0x03C1,
+ "rhov", 0x03F1,
+ "ring", 0x02DA,
+ "rlarr2", 0x21C4,
+ "rlhar2", 0x21CC,
+ "rpar", 0x0029,
+ "rpargt", 0xE291,
+ "rsh", 0x21B1,
+ "rsqb", 0x005D,
+ "rsquo", 0x2019,
+ "rsquor", 0x2018,
+ "rthree", 0x22CC,
+ "rtimes", 0x22CA,
+ "rtri", 0x25B9,
+ "rtrie", 0x22B5,
+ "rtrif", 0x25B8,
+ "rx", 0x211E,
+ NULL, 0
};
static NameId namesS[]={
- "Sacute", 0x015A,
- "sacute", 0x015B,
- "samalg", 0x2210,
- "sbsol", 0xFE68,
- "sc", 0x227B,
- "scap", 0x227F,
- "Scaron", 0x0160,
- "scaron", 0x0161,
- "sccue", 0x227D,
- "sce", 0x227D,
- "Scedil", 0x015E,
- "scedil", 0x015F,
- "Scirc", 0x015C,
- "scirc", 0x015D,
- "scnap", 0x22E9,
- "scnE", 0xE2B5,
- "scnsim", 0x22E9,
- "scsim", 0x227F,
- "Scy", 0x0421,
- "scy", 0x0441,
- "sdot", 0x22C5,
- "sdotb", 0x22A1,
- "sect", 0x00A7,
- "semi", 0x003B,
- "setmn", 0x2216,
- "sext", 0x2736,
- "sfgr", 0x03C2,
- "sfrown", 0x2322,
- "Sgr", 0x03A3,
- "sgr", 0x03C3,
- "sharp", 0x266F,
- "SHCHcy", 0x0429,
- "shchcy", 0x0449,
- "SHcy", 0x0428,
- "shcy", 0x0448,
- "shy", 0x00AD,
- "Sigma", 0x03A3,
- "sigma", 0x03C3,
- "sigmav", 0x03C2,
- "sim", 0x223C,
- "sime", 0x2243,
- "smid", 0xE301,
- "smile", 0x2323,
- "SOFTcy", 0x042C,
- "softcy", 0x044C,
- "sol", 0x002F,
- "spades", 0x2660,
- "spar", 0x2225,
- "sqcap", 0x2293,
- "sqcup", 0x2294,
- "sqsub", 0x228F,
- "sqsube", 0x2291,
- "sqsup", 0x2290,
- "sqsupe", 0x2292,
- "squ", 0x25A1,
- "square", 0x25A1,
- "squf", 0x25AA,
- "ssetmn", 0x2216,
- "ssmile", 0x2323,
- "sstarf", 0x22C6,
- "star", 0x22C6,
- "starf", 0x2605,
- "sub", 0x2282,
- "Sub", 0x22D0,
- "sube", 0x2286,
- "subE", 0x2286,
- "subne", 0x228A,
- "subnE", 0x228A,
- "sum", 0x2211,
- "sung", 0x2669,
- "sup", 0x2283,
- "Sup", 0x22D1,
- "sup1", 0x00B9,
- "sup2", 0x00B2,
- "sup3", 0x00B3,
- "supe", 0x2287,
- "supE", 0x2287,
- "supne", 0x228B,
- "supnE", 0x228B,
- "szlig", 0x00DF,
- NULL, 0
+ "Sacute", 0x015A,
+ "sacute", 0x015B,
+ "samalg", 0x2210,
+ "sbsol", 0xFE68,
+ "sc", 0x227B,
+ "scap", 0x227F,
+ "Scaron", 0x0160,
+ "scaron", 0x0161,
+ "sccue", 0x227D,
+ "sce", 0x227D,
+ "Scedil", 0x015E,
+ "scedil", 0x015F,
+ "Scirc", 0x015C,
+ "scirc", 0x015D,
+ "scnap", 0x22E9,
+ "scnE", 0xE2B5,
+ "scnsim", 0x22E9,
+ "scsim", 0x227F,
+ "Scy", 0x0421,
+ "scy", 0x0441,
+ "sdot", 0x22C5,
+ "sdotb", 0x22A1,
+ "sect", 0x00A7,
+ "semi", 0x003B,
+ "setmn", 0x2216,
+ "sext", 0x2736,
+ "sfgr", 0x03C2,
+ "sfrown", 0x2322,
+ "Sgr", 0x03A3,
+ "sgr", 0x03C3,
+ "sharp", 0x266F,
+ "SHCHcy", 0x0429,
+ "shchcy", 0x0449,
+ "SHcy", 0x0428,
+ "shcy", 0x0448,
+ "shy", 0x00AD,
+ "Sigma", 0x03A3,
+ "sigma", 0x03C3,
+ "sigmav", 0x03C2,
+ "sim", 0x223C,
+ "sime", 0x2243,
+ "smid", 0xE301,
+ "smile", 0x2323,
+ "SOFTcy", 0x042C,
+ "softcy", 0x044C,
+ "sol", 0x002F,
+ "spades", 0x2660,
+ "spar", 0x2225,
+ "sqcap", 0x2293,
+ "sqcup", 0x2294,
+ "sqsub", 0x228F,
+ "sqsube", 0x2291,
+ "sqsup", 0x2290,
+ "sqsupe", 0x2292,
+ "squ", 0x25A1,
+ "square", 0x25A1,
+ "squf", 0x25AA,
+ "ssetmn", 0x2216,
+ "ssmile", 0x2323,
+ "sstarf", 0x22C6,
+ "star", 0x22C6,
+ "starf", 0x2605,
+ "sub", 0x2282,
+ "Sub", 0x22D0,
+ "sube", 0x2286,
+ "subE", 0x2286,
+ "subne", 0x228A,
+ "subnE", 0x228A,
+ "sum", 0x2211,
+ "sung", 0x2669,
+ "sup", 0x2283,
+ "Sup", 0x22D1,
+ "sup1", 0x00B9,
+ "sup2", 0x00B2,
+ "sup3", 0x00B3,
+ "supe", 0x2287,
+ "supE", 0x2287,
+ "supne", 0x228B,
+ "supnE", 0x228B,
+ "szlig", 0x00DF,
+ NULL, 0
};
static NameId namesT[]={
- "target", 0x2316,
- "tau", 0x03C4,
- "Tcaron", 0x0164,
- "tcaron", 0x0165,
- "Tcedil", 0x0162,
- "tcedil", 0x0163,
- "Tcy", 0x0422,
- "tcy", 0x0442,
- "tdot", 0x20DB,
- "telrec", 0x2315,
- "Tgr", 0x03A4,
- "tgr", 0x03C4,
- "there4", 0x2234,
- "Theta", 0x0398,
- "thetas", 0x03B8,
- "thetav", 0x03D1,
- "THgr", 0x0398,
- "thgr", 0x03B8,
- "thinsp", 0x2009,
- "thkap", 0x2248,
- "thksim", 0x223C,
- "THORN", 0x00DE,
- "thorn", 0x00FE,
- "tilde", 0x02DC,
- "times", 0x00D7,
- "timesb", 0x22A0,
- "top", 0x22A4,
- "tprime", 0x2034,
- "trade", 0x2122,
- "trie", 0x225C,
- "TScy", 0x0426,
- "tscy", 0x0446,
- "TSHcy", 0x040B,
- "tshcy", 0x045B,
- "Tstrok", 0x0166,
- "tstrok", 0x0167,
- "twixt", 0x226C,
- NULL, 0
+ "target", 0x2316,
+ "tau", 0x03C4,
+ "Tcaron", 0x0164,
+ "tcaron", 0x0165,
+ "Tcedil", 0x0162,
+ "tcedil", 0x0163,
+ "Tcy", 0x0422,
+ "tcy", 0x0442,
+ "tdot", 0x20DB,
+ "telrec", 0x2315,
+ "Tgr", 0x03A4,
+ "tgr", 0x03C4,
+ "there4", 0x2234,
+ "Theta", 0x0398,
+ "thetas", 0x03B8,
+ "thetav", 0x03D1,
+ "THgr", 0x0398,
+ "thgr", 0x03B8,
+ "thinsp", 0x2009,
+ "thkap", 0x2248,
+ "thksim", 0x223C,
+ "THORN", 0x00DE,
+ "thorn", 0x00FE,
+ "tilde", 0x02DC,
+ "times", 0x00D7,
+ "timesb", 0x22A0,
+ "top", 0x22A4,
+ "tprime", 0x2034,
+ "trade", 0x2122,
+ "trie", 0x225C,
+ "TScy", 0x0426,
+ "tscy", 0x0446,
+ "TSHcy", 0x040B,
+ "tshcy", 0x045B,
+ "Tstrok", 0x0166,
+ "tstrok", 0x0167,
+ "twixt", 0x226C,
+ NULL, 0
};
static NameId namesU[]={
- "Uacgr", 0x038E,
- "uacgr", 0x03CD,
- "Uacute", 0x00DA,
- "uacute", 0x00FA,
- "uarr", 0x2191,
- "uArr", 0x21D1,
- "uarr2", 0x21C8,
- "Ubrcy", 0x040E,
- "ubrcy", 0x045E,
- "Ubreve", 0x016C,
- "ubreve", 0x016D,
- "Ucirc", 0x00DB,
- "ucirc", 0x00FB,
- "Ucy", 0x0423,
- "ucy", 0x0443,
- "Udblac", 0x0170,
- "udblac", 0x0171,
- "udiagr", 0x03B0,
- "Udigr", 0x03AB,
- "udigr", 0x03CB,
- "Ugr", 0x03A5,
- "ugr", 0x03C5,
- "Ugrave", 0x00D9,
- "ugrave", 0x00F9,
- "uharl", 0x21BF,
- "uharr", 0x21BE,
- "uhblk", 0x2580,
- "ulcorn", 0x231C,
- "ulcrop", 0x230F,
- "Umacr", 0x016A,
- "umacr", 0x016B,
- "uml", 0x00A8,
- "Uogon", 0x0172,
- "uogon", 0x0173,
- "uplus", 0x228E,
- "upsi", 0x03C5,
- "Upsi", 0x03D2,
- "urcorn", 0x231D,
- "urcrop", 0x230E,
- "Uring", 0x016E,
- "uring", 0x016F,
- "Utilde", 0x0168,
- "utilde", 0x0169,
- "utri", 0x25B5,
- "utrif", 0x25B4,
- "Uuml", 0x00DC,
- "uuml", 0x00FC,
- NULL, 0
+ "Uacgr", 0x038E,
+ "uacgr", 0x03CD,
+ "Uacute", 0x00DA,
+ "uacute", 0x00FA,
+ "uarr", 0x2191,
+ "uArr", 0x21D1,
+ "uarr2", 0x21C8,
+ "Ubrcy", 0x040E,
+ "ubrcy", 0x045E,
+ "Ubreve", 0x016C,
+ "ubreve", 0x016D,
+ "Ucirc", 0x00DB,
+ "ucirc", 0x00FB,
+ "Ucy", 0x0423,
+ "ucy", 0x0443,
+ "Udblac", 0x0170,
+ "udblac", 0x0171,
+ "udiagr", 0x03B0,
+ "Udigr", 0x03AB,
+ "udigr", 0x03CB,
+ "Ugr", 0x03A5,
+ "ugr", 0x03C5,
+ "Ugrave", 0x00D9,
+ "ugrave", 0x00F9,
+ "uharl", 0x21BF,
+ "uharr", 0x21BE,
+ "uhblk", 0x2580,
+ "ulcorn", 0x231C,
+ "ulcrop", 0x230F,
+ "Umacr", 0x016A,
+ "umacr", 0x016B,
+ "uml", 0x00A8,
+ "Uogon", 0x0172,
+ "uogon", 0x0173,
+ "uplus", 0x228E,
+ "upsi", 0x03C5,
+ "Upsi", 0x03D2,
+ "urcorn", 0x231D,
+ "urcrop", 0x230E,
+ "Uring", 0x016E,
+ "uring", 0x016F,
+ "Utilde", 0x0168,
+ "utilde", 0x0169,
+ "utri", 0x25B5,
+ "utrif", 0x25B4,
+ "Uuml", 0x00DC,
+ "uuml", 0x00FC,
+ NULL, 0
};
static NameId namesV[]={
- "varr", 0x2195,
- "vArr", 0x21D5,
- "Vcy", 0x0412,
- "vcy", 0x0432,
- "vdash", 0x22A2,
- "vDash", 0x22A8,
- "Vdash", 0x22A9,
- "veebar", 0x22BB,
- "vellip", 0x22EE,
- "verbar", 0x007C,
- "Verbar", 0x2016,
- "vltri", 0x22B2,
- "vprime", 0x2032,
- "vprop", 0x221D,
- "vrtri", 0x22B3,
- "vsubne", 0x228A,
- "vsubnE", 0xE2B8,
- "vsupne", 0x228B,
- "vsupnE", 0x228B,
- "Vvdash", 0x22AA,
- NULL, 0
+ "varr", 0x2195,
+ "vArr", 0x21D5,
+ "Vcy", 0x0412,
+ "vcy", 0x0432,
+ "vdash", 0x22A2,
+ "vDash", 0x22A8,
+ "Vdash", 0x22A9,
+ "veebar", 0x22BB,
+ "vellip", 0x22EE,
+ "verbar", 0x007C,
+ "Verbar", 0x2016,
+ "vltri", 0x22B2,
+ "vprime", 0x2032,
+ "vprop", 0x221D,
+ "vrtri", 0x22B3,
+ "vsubne", 0x228A,
+ "vsubnE", 0xE2B8,
+ "vsupne", 0x228B,
+ "vsupnE", 0x228B,
+ "Vvdash", 0x22AA,
+ NULL, 0
};
static NameId namesW[]={
- "Wcirc", 0x0174,
- "wcirc", 0x0175,
- "wedgeq", 0x2259,
- "weierp", 0x2118,
- "wreath", 0x2240,
- NULL, 0
+ "Wcirc", 0x0174,
+ "wcirc", 0x0175,
+ "wedgeq", 0x2259,
+ "weierp", 0x2118,
+ "wreath", 0x2240,
+ NULL, 0
};
static NameId namesX[]={
- "xcirc", 0x25CB,
- "xdtri", 0x25BD,
- "Xgr", 0x039E,
- "xgr", 0x03BE,
- "xharr", 0x2194,
- "xhArr", 0x2194,
- "Xi", 0x039E,
- "xi", 0x03BE,
- "xlArr", 0x21D0,
- "xrArr", 0x21D2,
- "xutri", 0x25B3,
- NULL, 0
+ "xcirc", 0x25CB,
+ "xdtri", 0x25BD,
+ "Xgr", 0x039E,
+ "xgr", 0x03BE,
+ "xharr", 0x2194,
+ "xhArr", 0x2194,
+ "Xi", 0x039E,
+ "xi", 0x03BE,
+ "xlArr", 0x21D0,
+ "xrArr", 0x21D2,
+ "xutri", 0x25B3,
+ NULL, 0
};
static NameId namesY[]={
- "Yacute", 0x00DD,
- "yacute", 0x00FD,
- "YAcy", 0x042F,
- "yacy", 0x044F,
- "Ycirc", 0x0176,
- "ycirc", 0x0177,
- "Ycy", 0x042B,
- "ycy", 0x044B,
- "yen", 0x00A5,
- "YIcy", 0x0407,
- "yicy", 0x0457,
- "YUcy", 0x042E,
- "yucy", 0x044E,
- "yuml", 0x00FF,
- "Yuml", 0x0178,
- NULL, 0
+ "Yacute", 0x00DD,
+ "yacute", 0x00FD,
+ "YAcy", 0x042F,
+ "yacy", 0x044F,
+ "Ycirc", 0x0176,
+ "ycirc", 0x0177,
+ "Ycy", 0x042B,
+ "ycy", 0x044B,
+ "yen", 0x00A5,
+ "YIcy", 0x0407,
+ "yicy", 0x0457,
+ "YUcy", 0x042E,
+ "yucy", 0x044E,
+ "yuml", 0x00FF,
+ "Yuml", 0x0178,
+ NULL, 0
};
static NameId namesZ[]={
- "Zacute", 0x0179,
- "zacute", 0x017A,
- "Zcaron", 0x017D,
- "zcaron", 0x017E,
- "Zcy", 0x0417,
- "zcy", 0x0437,
- "Zdot", 0x017B,
- "zdot", 0x017C,
- "zeta", 0x03B6,
- "Zgr", 0x0396,
- "zgr", 0x03B6,
- "ZHcy", 0x0416,
- "zhcy", 0x0436,
- NULL, 0
+ "Zacute", 0x0179,
+ "zacute", 0x017A,
+ "Zcaron", 0x017D,
+ "zcaron", 0x017E,
+ "Zcy", 0x0417,
+ "zcy", 0x0437,
+ "Zdot", 0x017B,
+ "zdot", 0x017C,
+ "zeta", 0x03B6,
+ "Zgr", 0x0396,
+ "zgr", 0x03B6,
+ "ZHcy", 0x0416,
+ "zhcy", 0x0436,
+ NULL, 0
};
// @todo@ order namesTable and names? by frequency
-static NameId* namesTable[] = {
- namesA, namesB, namesC, namesD, namesE, namesF, namesG, namesH, namesI,
- namesJ, namesK, namesL, namesM, namesN, namesO, namesP, namesQ, namesR,
- namesS, namesT, namesU, namesV, namesW, namesX, namesY, namesZ, NULL
+static NameId* namesTable[] = {
+ namesA, namesB, namesC, namesD, namesE, namesF, namesG, namesH, namesI,
+ namesJ, namesK, namesL, namesM, namesN, namesO, namesP, namesQ, namesR,
+ namesS, namesT, namesU, namesV, namesW, namesX, namesY, namesZ, NULL
};
int HtmlNamedEntity(unsigned char *p, int length)
{
int tableIndex = tolower(*p) - 'a';
if (tableIndex >= 0 && tableIndex < 26) {
- NameId* names = namesTable[tableIndex];
- int i;
+ NameId* names = namesTable[tableIndex];
+ int i;
- for (i = 0; names[i].name; i++){
- if (strncmp(names[i].name, (char *)p, length) == 0){
- return names[i].value;
- }
- }
+ for (i = 0; names[i].name; i++){
+ if (strncmp(names[i].name, (char *)p, length) == 0){
+ return names[i].value;
+ }
+ }
}
error("unrecognized character entity \"%.*s\"", length, p);
return -1;
@@ -1089,263 +1089,263 @@ int HtmlNamedEntity(unsigned char *p, int length)
static NameId names[] =
{
// Entities
- "quot", 34,
- "amp", 38,
- "lt", 60,
- "gt", 62,
+ "quot", 34,
+ "amp", 38,
+ "lt", 60,
+ "gt", 62,
- "OElig", 338,
- "oelig", 339,
- "Scaron", 352,
- "scaron", 353,
- "Yuml", 376,
- "circ", 710,
- "tilde", 732,
- "ensp", 8194,
- "emsp", 8195,
- "thinsp", 8201,
- "zwnj", 8204,
- "zwj", 8205,
- "lrm", 8206,
- "rlm", 8207,
- "ndash", 8211,
- "mdash", 8212,
- "lsquo", 8216,
- "rsquo", 8217,
- "sbquo", 8218,
- "ldquo", 8220,
- "rdquo", 8221,
- "bdquo", 8222,
- "dagger", 8224,
- "Dagger", 8225,
- "permil", 8240,
- "lsaquo", 8249,
- "rsaquo", 8250,
- "euro", 8364,
+ "OElig", 338,
+ "oelig", 339,
+ "Scaron", 352,
+ "scaron", 353,
+ "Yuml", 376,
+ "circ", 710,
+ "tilde", 732,
+ "ensp", 8194,
+ "emsp", 8195,
+ "thinsp", 8201,
+ "zwnj", 8204,
+ "zwj", 8205,
+ "lrm", 8206,
+ "rlm", 8207,
+ "ndash", 8211,
+ "mdash", 8212,
+ "lsquo", 8216,
+ "rsquo", 8217,
+ "sbquo", 8218,
+ "ldquo", 8220,
+ "rdquo", 8221,
+ "bdquo", 8222,
+ "dagger", 8224,
+ "Dagger", 8225,
+ "permil", 8240,
+ "lsaquo", 8249,
+ "rsaquo", 8250,
+ "euro", 8364,
// Latin-1 (ISO-8859-1) Entities
- "nbsp", 160,
- "iexcl", 161,
- "cent", 162,
- "pound", 163,
- "curren", 164,
- "yen", 165,
- "brvbar", 166,
- "sect", 167,
- "uml", 168,
- "copy", 169,
- "ordf", 170,
- "laquo", 171,
- "not", 172,
- "shy", 173,
- "reg", 174,
- "macr", 175,
- "deg", 176,
- "plusmn", 177,
- "sup2", 178,
- "sup3", 179,
- "acute", 180,
- "micro", 181,
- "para", 182,
- "middot", 183,
- "cedil", 184,
- "sup1", 185,
- "ordm", 186,
- "raquo", 187,
- "frac14", 188,
- "frac12", 189,
- "frac34", 190,
- "iquest", 191,
- "Agrave", 192,
- "Aacute", 193,
- "Acirc", 194,
- "Atilde", 195,
- "Auml", 196,
- "Aring", 197,
- "AElig", 198,
- "Ccedil", 199,
- "Egrave", 200,
- "Eacute", 201,
- "Ecirc", 202,
- "Euml", 203,
- "Igrave", 204,
- "Iacute", 205,
- "Icirc", 206,
- "Iuml", 207,
- "ETH", 208,
- "Ntilde", 209,
- "Ograve", 210,
- "Oacute", 211,
- "Ocirc", 212,
- "Otilde", 213,
- "Ouml", 214,
- "times", 215,
- "Oslash", 216,
- "Ugrave", 217,
- "Uacute", 218,
- "Ucirc", 219,
- "Uuml", 220,
- "Yacute", 221,
- "THORN", 222,
- "szlig", 223,
- "agrave", 224,
- "aacute", 225,
- "acirc", 226,
- "atilde", 227,
- "auml", 228,
- "aring", 229,
- "aelig", 230,
- "ccedil", 231,
- "egrave", 232,
- "eacute", 233,
- "ecirc", 234,
- "euml", 235,
- "igrave", 236,
- "iacute", 237,
- "icirc", 238,
- "iuml", 239,
- "eth", 240,
- "ntilde", 241,
- "ograve", 242,
- "oacute", 243,
- "ocirc", 244,
- "otilde", 245,
- "ouml", 246,
- "divide", 247,
- "oslash", 248,
- "ugrave", 249,
- "uacute", 250,
- "ucirc", 251,
- "uuml", 252,
- "yacute", 253,
- "thorn", 254,
- "yuml", 255,
+ "nbsp", 160,
+ "iexcl", 161,
+ "cent", 162,
+ "pound", 163,
+ "curren", 164,
+ "yen", 165,
+ "brvbar", 166,
+ "sect", 167,
+ "uml", 168,
+ "copy", 169,
+ "ordf", 170,
+ "laquo", 171,
+ "not", 172,
+ "shy", 173,
+ "reg", 174,
+ "macr", 175,
+ "deg", 176,
+ "plusmn", 177,
+ "sup2", 178,
+ "sup3", 179,
+ "acute", 180,
+ "micro", 181,
+ "para", 182,
+ "middot", 183,
+ "cedil", 184,
+ "sup1", 185,
+ "ordm", 186,
+ "raquo", 187,
+ "frac14", 188,
+ "frac12", 189,
+ "frac34", 190,
+ "iquest", 191,
+ "Agrave", 192,
+ "Aacute", 193,
+ "Acirc", 194,
+ "Atilde", 195,
+ "Auml", 196,
+ "Aring", 197,
+ "AElig", 198,
+ "Ccedil", 199,
+ "Egrave", 200,
+ "Eacute", 201,
+ "Ecirc", 202,
+ "Euml", 203,
+ "Igrave", 204,
+ "Iacute", 205,
+ "Icirc", 206,
+ "Iuml", 207,
+ "ETH", 208,
+ "Ntilde", 209,
+ "Ograve", 210,
+ "Oacute", 211,
+ "Ocirc", 212,
+ "Otilde", 213,
+ "Ouml", 214,
+ "times", 215,
+ "Oslash", 216,
+ "Ugrave", 217,
+ "Uacute", 218,
+ "Ucirc", 219,
+ "Uuml", 220,
+ "Yacute", 221,
+ "THORN", 222,
+ "szlig", 223,
+ "agrave", 224,
+ "aacute", 225,
+ "acirc", 226,
+ "atilde", 227,
+ "auml", 228,
+ "aring", 229,
+ "aelig", 230,
+ "ccedil", 231,
+ "egrave", 232,
+ "eacute", 233,
+ "ecirc", 234,
+ "euml", 235,
+ "igrave", 236,
+ "iacute", 237,
+ "icirc", 238,
+ "iuml", 239,
+ "eth", 240,
+ "ntilde", 241,
+ "ograve", 242,
+ "oacute", 243,
+ "ocirc", 244,
+ "otilde", 245,
+ "ouml", 246,
+ "divide", 247,
+ "oslash", 248,
+ "ugrave", 249,
+ "uacute", 250,
+ "ucirc", 251,
+ "uuml", 252,
+ "yacute", 253,
+ "thorn", 254,
+ "yuml", 255,
- // Symbols and Greek letter entities
- "fnof", 402,
- "Alpha", 913,
- "Beta", 914,
- "Gamma", 915,
- "Delta", 916,
- "Epsilon", 917,
- "Zeta", 918,
- "Eta", 919,
- "Theta", 920,
- "Iota", 921,
- "Kappa", 922,
- "Lambda", 923,
- "Mu", 924,
- "Nu", 925,
- "Xi", 926,
- "Omicron", 927,
- "Pi", 928,
- "Rho", 929,
- "Sigma", 931,
- "Tau", 932,
- "Upsilon", 933,
- "Phi", 934,
- "Chi", 935,
- "Psi", 936,
- "Omega", 937,
- "alpha", 945,
- "beta", 946,
- "gamma", 947,
- "delta", 948,
- "epsilon", 949,
- "zeta", 950,
- "eta", 951,
- "theta", 952,
- "iota", 953,
- "kappa", 954,
- "lambda", 955,
- "mu", 956,
- "nu", 957,
- "xi", 958,
- "omicron", 959,
- "pi", 960,
- "rho", 961,
- "sigmaf", 962,
- "sigma", 963,
- "tau", 964,
- "upsilon", 965,
- "phi", 966,
- "chi", 967,
- "psi", 968,
- "omega", 969,
- "thetasym", 977,
- "upsih", 978,
- "piv", 982,
- "bull", 8226,
- "hellip", 8230,
- "prime", 8242,
- "Prime", 8243,
- "oline", 8254,
- "frasl", 8260,
- "weierp", 8472,
- "image", 8465,
- "real", 8476,
- "trade", 8482,
- "alefsym", 8501,
- "larr", 8592,
- "uarr", 8593,
- "rarr", 8594,
- "darr", 8595,
- "harr", 8596,
- "crarr", 8629,
- "lArr", 8656,
- "uArr", 8657,
- "rArr", 8658,
- "dArr", 8659,
- "hArr", 8660,
- "forall", 8704,
- "part", 8706,
- "exist", 8707,
- "empty", 8709,
- "nabla", 8711,
- "isin", 8712,
- "notin", 8713,
- "ni", 8715,
- "prod", 8719,
- "sum", 8721,
- "minus", 8722,
- "lowast", 8727,
- "radic", 8730,
- "prop", 8733,
- "infin", 8734,
- "ang", 8736,
- "and", 8743,
- "or", 8744,
- "cap", 8745,
- "cup", 8746,
- "int", 8747,
- "there4", 8756,
- "sim", 8764,
- "cong", 8773,
- "asymp", 8776,
- "ne", 8800,
- "equiv", 8801,
- "le", 8804,
- "ge", 8805,
- "sub", 8834,
- "sup", 8835,
- "nsub", 8836,
- "sube", 8838,
- "supe", 8839,
- "oplus", 8853,
- "otimes", 8855,
- "perp", 8869,
- "sdot", 8901,
- "lceil", 8968,
- "rceil", 8969,
- "lfloor", 8970,
- "rfloor", 8971,
- "lang", 9001,
- "rang", 9002,
- "loz", 9674,
- "spades", 9824,
- "clubs", 9827,
- "hearts", 9829,
- "diams", 9830,
+ // Symbols and Greek letter entities
+ "fnof", 402,
+ "Alpha", 913,
+ "Beta", 914,
+ "Gamma", 915,
+ "Delta", 916,
+ "Epsilon", 917,
+ "Zeta", 918,
+ "Eta", 919,
+ "Theta", 920,
+ "Iota", 921,
+ "Kappa", 922,
+ "Lambda", 923,
+ "Mu", 924,
+ "Nu", 925,
+ "Xi", 926,
+ "Omicron", 927,
+ "Pi", 928,
+ "Rho", 929,
+ "Sigma", 931,
+ "Tau", 932,
+ "Upsilon", 933,
+ "Phi", 934,
+ "Chi", 935,
+ "Psi", 936,
+ "Omega", 937,
+ "alpha", 945,
+ "beta", 946,
+ "gamma", 947,
+ "delta", 948,
+ "epsilon", 949,
+ "zeta", 950,
+ "eta", 951,
+ "theta", 952,
+ "iota", 953,
+ "kappa", 954,
+ "lambda", 955,
+ "mu", 956,
+ "nu", 957,
+ "xi", 958,
+ "omicron", 959,
+ "pi", 960,
+ "rho", 961,
+ "sigmaf", 962,
+ "sigma", 963,
+ "tau", 964,
+ "upsilon", 965,
+ "phi", 966,
+ "chi", 967,
+ "psi", 968,
+ "omega", 969,
+ "thetasym", 977,
+ "upsih", 978,
+ "piv", 982,
+ "bull", 8226,
+ "hellip", 8230,
+ "prime", 8242,
+ "Prime", 8243,
+ "oline", 8254,
+ "frasl", 8260,
+ "weierp", 8472,
+ "image", 8465,
+ "real", 8476,
+ "trade", 8482,
+ "alefsym", 8501,
+ "larr", 8592,
+ "uarr", 8593,
+ "rarr", 8594,
+ "darr", 8595,
+ "harr", 8596,
+ "crarr", 8629,
+ "lArr", 8656,
+ "uArr", 8657,
+ "rArr", 8658,
+ "dArr", 8659,
+ "hArr", 8660,
+ "forall", 8704,
+ "part", 8706,
+ "exist", 8707,
+ "empty", 8709,
+ "nabla", 8711,
+ "isin", 8712,
+ "notin", 8713,
+ "ni", 8715,
+ "prod", 8719,
+ "sum", 8721,
+ "minus", 8722,
+ "lowast", 8727,
+ "radic", 8730,
+ "prop", 8733,
+ "infin", 8734,
+ "ang", 8736,
+ "and", 8743,
+ "or", 8744,
+ "cap", 8745,
+ "cup", 8746,
+ "int", 8747,
+ "there4", 8756,
+ "sim", 8764,
+ "cong", 8773,
+ "asymp", 8776,
+ "ne", 8800,
+ "equiv", 8801,
+ "le", 8804,
+ "ge", 8805,
+ "sub", 8834,
+ "sup", 8835,
+ "nsub", 8836,
+ "sube", 8838,
+ "supe", 8839,
+ "oplus", 8853,
+ "otimes", 8855,
+ "perp", 8869,
+ "sdot", 8901,
+ "lceil", 8968,
+ "rceil", 8969,
+ "lfloor", 8970,
+ "rfloor", 8971,
+ "lang", 9001,
+ "rang", 9002,
+ "loz", 9674,
+ "spades", 9824,
+ "clubs", 9827,
+ "hearts", 9829,
+ "diams", 9830,
};
int HtmlNamedEntity(unsigned char *p, int length)
@@ -1355,10 +1355,10 @@ int HtmlNamedEntity(unsigned char *p, int length)
// BUG: this is a dumb, slow linear search
for (i = 0; i < sizeof(names) / sizeof(names[0]); i++)
{
- // Entries are case sensitive
- if (memcmp(names[i].name, (char *)p, length) == 0 &&
- !names[i].name[length])
- return names[i].value;
+ // Entries are case sensitive
+ if (memcmp(names[i].name, (char *)p, length) == 0 &&
+ !names[i].name[length])
+ return names[i].value;
}
return -1;
}
diff --git a/dmd/enum.c b/dmd/enum.c
index 08768192..23b9ddcd 100644
--- a/dmd/enum.c
+++ b/dmd/enum.c
@@ -38,15 +38,15 @@ Dsymbol *EnumDeclaration::syntaxCopy(Dsymbol *s)
{
Type *t = NULL;
if (memtype)
- t = memtype->syntaxCopy();
+ t = memtype->syntaxCopy();
EnumDeclaration *ed;
if (s)
- { ed = (EnumDeclaration *)s;
- ed->memtype = t;
+ { ed = (EnumDeclaration *)s;
+ ed->memtype = t;
}
else
- ed = new EnumDeclaration(loc, ident, t);
+ ed = new EnumDeclaration(loc, ident, t);
ScopeDsymbol::syntaxCopy(ed);
return ed;
}
@@ -59,14 +59,14 @@ void EnumDeclaration::semantic(Scope *sc)
//printf("EnumDeclaration::semantic(sd = %p, '%s')\n", sc->scopesym, sc->scopesym->toChars());
if (!memtype)
- memtype = Type::tint32;
+ memtype = Type::tint32;
- if (symtab) // if already done
- { if (isdone || !scope)
- return; // semantic() already completed
+ if (symtab) // if already done
+ { if (isdone || !scope)
+ return; // semantic() already completed
}
else
- symtab = new DsymbolTable();
+ symtab = new DsymbolTable();
Scope *scx = NULL;
if (scope)
@@ -78,7 +78,7 @@ void EnumDeclaration::semantic(Scope *sc)
unsigned dprogress_save = Module::dprogress;
if (sc->stc & STCdeprecated)
- isdeprecated = 1;
+ isdeprecated = 1;
parent = sc->scopesym;
memtype = memtype->semantic(loc, sc);
@@ -86,17 +86,17 @@ void EnumDeclaration::semantic(Scope *sc)
/* Check to see if memtype is forward referenced
*/
if (memtype->ty == Tenum)
- { EnumDeclaration *sym = (EnumDeclaration *)memtype->toDsymbol(sc);
- if (!sym->memtype)
- {
- error("base enum %s is forward referenced", sym->toChars());
- memtype = Type::tint32;
- }
+ { EnumDeclaration *sym = (EnumDeclaration *)memtype->toDsymbol(sc);
+ if (!sym->memtype)
+ {
+ error("base enum %s is forward referenced", sym->toChars());
+ memtype = Type::tint32;
+ }
}
if (!memtype->isintegral())
- { error("base type must be of integral type, not %s", memtype->toChars());
- memtype = Type::tint32;
+ { error("base type must be of integral type, not %s", memtype->toChars());
+ memtype = Type::tint32;
}
isdone = 1;
@@ -107,135 +107,135 @@ void EnumDeclaration::semantic(Scope *sc)
sce = sc->push(this);
sce->parent = this;
number = 0;
- if (!members) // enum ident;
- return;
+ if (!members) // enum ident;
+ return;
if (members->dim == 0)
- error("enum %s must have at least one member", toChars());
+ error("enum %s must have at least one member", toChars());
int first = 1;
for (i = 0; i < members->dim; i++)
{
- EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember();
- Expression *e;
+ EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember();
+ Expression *e;
- if (!em)
- /* The e->semantic(sce) can insert other symbols, such as
- * template instances and function literals.
- */
- continue;
+ if (!em)
+ /* The e->semantic(sce) can insert other symbols, such as
+ * template instances and function literals.
+ */
+ continue;
- //printf("Enum member '%s'\n",em->toChars());
- e = em->value;
- if (e)
- {
- assert(e->dyncast() == DYNCAST_EXPRESSION);
- e = e->semantic(sce);
- e = e->optimize(WANTvalue);
- // Need to copy it because we're going to change the type
- e = e->copy();
- e = e->implicitCastTo(sc, memtype);
- e = e->optimize(WANTvalue);
- number = e->toInteger();
- e->type = t;
- }
- else
- { // Default is the previous number plus 1
+ //printf("Enum member '%s'\n",em->toChars());
+ e = em->value;
+ if (e)
+ {
+ assert(e->dyncast() == DYNCAST_EXPRESSION);
+ e = e->semantic(sce);
+ e = e->optimize(WANTvalue);
+ // Need to copy it because we're going to change the type
+ e = e->copy();
+ e = e->implicitCastTo(sc, memtype);
+ e = e->optimize(WANTvalue);
+ number = e->toInteger();
+ e->type = t;
+ }
+ else
+ { // Default is the previous number plus 1
- // Check for overflow
- if (!first)
- {
- switch (t->toBasetype()->ty)
- {
- case Tbool:
- if (number == 2) goto Loverflow;
- break;
+ // Check for overflow
+ if (!first)
+ {
+ switch (t->toBasetype()->ty)
+ {
+ case Tbool:
+ if (number == 2) goto Loverflow;
+ break;
- case Tint8:
- if (number == 128) goto Loverflow;
- break;
+ case Tint8:
+ if (number == 128) goto Loverflow;
+ break;
- case Tchar:
- case Tuns8:
- if (number == 256) goto Loverflow;
- break;
+ case Tchar:
+ case Tuns8:
+ if (number == 256) goto Loverflow;
+ break;
- case Tint16:
- if (number == 0x8000) goto Loverflow;
- break;
+ case Tint16:
+ if (number == 0x8000) goto Loverflow;
+ break;
- case Twchar:
- case Tuns16:
- if (number == 0x10000) goto Loverflow;
- break;
+ case Twchar:
+ case Tuns16:
+ if (number == 0x10000) goto Loverflow;
+ break;
- case Tint32:
- if (number == 0x80000000) goto Loverflow;
- break;
+ case Tint32:
+ if (number == 0x80000000) goto Loverflow;
+ break;
- case Tdchar:
- case Tuns32:
- if (number == 0x100000000LL) goto Loverflow;
- break;
+ case Tdchar:
+ case Tuns32:
+ if (number == 0x100000000LL) goto Loverflow;
+ break;
- case Tint64:
- if (number == 0x8000000000000000LL) goto Loverflow;
- break;
+ case Tint64:
+ if (number == 0x8000000000000000LL) goto Loverflow;
+ break;
- case Tuns64:
- if (number == 0) goto Loverflow;
- break;
+ case Tuns64:
+ if (number == 0) goto Loverflow;
+ break;
- Loverflow:
- error("overflow of enum value");
- break;
+ Loverflow:
+ error("overflow of enum value");
+ break;
- default:
- assert(0);
- }
- }
- e = new IntegerExp(em->loc, number, t);
- }
- em->value = e;
+ default:
+ assert(0);
+ }
+ }
+ e = new IntegerExp(em->loc, number, t);
+ }
+ em->value = e;
- // Add to symbol table only after evaluating 'value'
- if (isAnonymous())
- {
- //sce->enclosing->insert(em);
- for (Scope *scx = sce->enclosing; scx; scx = scx->enclosing)
- {
- if (scx->scopesym)
- {
- if (!scx->scopesym->symtab)
- scx->scopesym->symtab = new DsymbolTable();
- em->addMember(sce, scx->scopesym, 1);
- break;
- }
- }
- }
- else
- em->addMember(sc, this, 1);
+ // Add to symbol table only after evaluating 'value'
+ if (isAnonymous())
+ {
+ //sce->enclosing->insert(em);
+ for (Scope *scx = sce->enclosing; scx; scx = scx->enclosing)
+ {
+ if (scx->scopesym)
+ {
+ if (!scx->scopesym->symtab)
+ scx->scopesym->symtab = new DsymbolTable();
+ em->addMember(sce, scx->scopesym, 1);
+ break;
+ }
+ }
+ }
+ else
+ em->addMember(sc, this, 1);
- if (first)
- { first = 0;
- defaultval = number;
- minval = number;
- maxval = number;
- }
- else if (memtype->isunsigned())
- {
- if (number < minval)
- minval = number;
- if (number > maxval)
- maxval = number;
- }
- else
- {
- if ((sinteger_t)number < (sinteger_t)minval)
- minval = number;
- if ((sinteger_t)number > (sinteger_t)maxval)
- maxval = number;
- }
+ if (first)
+ { first = 0;
+ defaultval = number;
+ minval = number;
+ maxval = number;
+ }
+ else if (memtype->isunsigned())
+ {
+ if (number < minval)
+ minval = number;
+ if (number > maxval)
+ maxval = number;
+ }
+ else
+ {
+ if ((sinteger_t)number < (sinteger_t)minval)
+ minval = number;
+ if ((sinteger_t)number > (sinteger_t)maxval)
+ maxval = number;
+ }
- number++;
+ number++;
}
//printf("defaultval = %lld\n", defaultval);
@@ -246,7 +246,7 @@ void EnumDeclaration::semantic(Scope *sc)
int EnumDeclaration::oneMember(Dsymbol **ps)
{
if (isAnonymous())
- return Dsymbol::oneMembers(members, ps);
+ return Dsymbol::oneMembers(members, ps);
return Dsymbol::oneMember(ps);
}
@@ -255,32 +255,32 @@ void EnumDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring("enum ");
if (ident)
- { buf->writestring(ident->toChars());
- buf->writeByte(' ');
+ { buf->writestring(ident->toChars());
+ buf->writeByte(' ');
}
if (memtype)
{
- buf->writestring(": ");
- memtype->toCBuffer(buf, NULL, hgs);
+ buf->writestring(": ");
+ memtype->toCBuffer(buf, NULL, hgs);
}
if (!members)
{
- buf->writeByte(';');
- buf->writenl();
- return;
+ buf->writeByte(';');
+ buf->writenl();
+ return;
}
buf->writenl();
buf->writeByte('{');
buf->writenl();
for (i = 0; i < members->dim; i++)
{
- EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember();
- if (!em)
- continue;
- //buf->writestring(" ");
- em->toCBuffer(buf, hgs);
- buf->writeByte(',');
- buf->writenl();
+ EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember();
+ if (!em)
+ continue;
+ //buf->writestring(" ");
+ em->toCBuffer(buf, hgs);
+ buf->writeByte(',');
+ buf->writenl();
}
buf->writeByte('}');
buf->writenl();
@@ -314,16 +314,16 @@ Dsymbol *EnumMember::syntaxCopy(Dsymbol *s)
{
Expression *e = NULL;
if (value)
- e = value->syntaxCopy();
+ e = value->syntaxCopy();
EnumMember *em;
if (s)
- { em = (EnumMember *)s;
- em->loc = loc;
- em->value = e;
+ { em = (EnumMember *)s;
+ em->loc = loc;
+ em->value = e;
}
else
- em = new EnumMember(loc, ident, e);
+ em = new EnumMember(loc, ident, e);
return em;
}
@@ -332,8 +332,8 @@ void EnumMember::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring(ident->toChars());
if (value)
{
- buf->writestring(" = ");
- value->toCBuffer(buf, hgs);
+ buf->writestring(" = ");
+ value->toCBuffer(buf, hgs);
}
}
diff --git a/dmd/enum.h b/dmd/enum.h
index a08c01fe..5c316301 100644
--- a/dmd/enum.h
+++ b/dmd/enum.h
@@ -29,21 +29,21 @@ struct HdrGenState;
struct EnumDeclaration : ScopeDsymbol
{ /* enum ident : memtype { ... }
*/
- Type *type; // the TypeEnum
- Type *memtype; // type of the members
+ Type *type; // the TypeEnum
+ Type *memtype; // type of the members
#if DMDV1
dinteger_t maxval;
dinteger_t minval;
- dinteger_t defaultval; // default initializer
+ dinteger_t defaultval; // default initializer
#else
Expression *maxval;
Expression *minval;
- Expression *defaultval; // default initializer
+ Expression *defaultval; // default initializer
#endif
int isdeprecated;
- int isdone; // 0: not done
- // 1: semantic() successfully completed
+ int isdone; // 0: not done
+ // 1: semantic() successfully completed
EnumDeclaration(Loc loc, Identifier *id, Type *memtype);
Dsymbol *syntaxCopy(Dsymbol *s);
@@ -55,7 +55,7 @@ struct EnumDeclaration : ScopeDsymbol
#if DMDV2
Dsymbol *search(Loc, Identifier *ident, int flags);
#endif
- int isDeprecated(); // is Dsymbol deprecated?
+ int isDeprecated(); // is Dsymbol deprecated?
void emitComment(Scope *sc);
void toJsonBuffer(OutBuffer *buf);
@@ -64,7 +64,7 @@ struct EnumDeclaration : ScopeDsymbol
EnumDeclaration *isEnumDeclaration() { return this; }
#if IN_DMD
- void toObjFile(int multiobj); // compile to .obj file
+ void toObjFile(int multiobj); // compile to .obj file
void toDebug();
int cvMember(unsigned char *p);
diff --git a/dmd/expression.c b/dmd/expression.c
index c96e0ec4..58a1c1b6 100644
--- a/dmd/expression.c
+++ b/dmd/expression.c
@@ -58,7 +58,7 @@ int isnan(double);
Expression *expandVar(int result, VarDeclaration *v);
-#define LOGSEMANTIC 0
+#define LOGSEMANTIC 0
/**********************************
* Set operator precedence for each operator.
@@ -207,13 +207,13 @@ void initPrecedence()
* right 'this' pointer if var is in an outer class, but our
* existing 'this' pointer is in an inner class.
* Input:
- * e1 existing 'this'
- * ad struct or class we need the correct 'this' for
- * var the specific member of ad we're accessing
+ * e1 existing 'this'
+ * ad struct or class we need the correct 'this' for
+ * var the specific member of ad we're accessing
*/
Expression *getRightThis(Loc loc, Scope *sc, AggregateDeclaration *ad,
- Expression *e1, Declaration *var)
+ Expression *e1, Declaration *var)
{
//printf("\ngetRightThis(e1 = %s, ad = %s, var = %s)\n", e1->toChars(), ad->toChars(), var->toChars());
L1:
@@ -223,68 +223,68 @@ Expression *getRightThis(Loc loc, Scope *sc, AggregateDeclaration *ad,
/* If e1 is not the 'this' pointer for ad
*/
if (ad &&
- !(t->ty == Tpointer && t->nextOf()->ty == Tstruct &&
- ((TypeStruct *)t->nextOf())->sym == ad)
- &&
- !(t->ty == Tstruct &&
- ((TypeStruct *)t)->sym == ad)
+ !(t->ty == Tpointer && t->nextOf()->ty == Tstruct &&
+ ((TypeStruct *)t->nextOf())->sym == ad)
+ &&
+ !(t->ty == Tstruct &&
+ ((TypeStruct *)t)->sym == ad)
)
{
- ClassDeclaration *cd = ad->isClassDeclaration();
- ClassDeclaration *tcd = t->isClassHandle();
+ ClassDeclaration *cd = ad->isClassDeclaration();
+ ClassDeclaration *tcd = t->isClassHandle();
- /* e1 is the right this if ad is a base class of e1
- */
- if (!cd || !tcd ||
- !(tcd == cd || cd->isBaseOf(tcd, NULL))
- )
- {
- /* Only classes can be inner classes with an 'outer'
- * member pointing to the enclosing class instance
- */
- if (tcd && tcd->isNested())
- { /* e1 is the 'this' pointer for an inner class: tcd.
- * Rewrite it as the 'this' pointer for the outer class.
- */
+ /* e1 is the right this if ad is a base class of e1
+ */
+ if (!cd || !tcd ||
+ !(tcd == cd || cd->isBaseOf(tcd, NULL))
+ )
+ {
+ /* Only classes can be inner classes with an 'outer'
+ * member pointing to the enclosing class instance
+ */
+ if (tcd && tcd->isNested())
+ { /* e1 is the 'this' pointer for an inner class: tcd.
+ * Rewrite it as the 'this' pointer for the outer class.
+ */
- e1 = new DotVarExp(loc, e1, tcd->vthis);
- e1->type = tcd->vthis->type;
- // Do not call checkNestedRef()
- //e1 = e1->semantic(sc);
+ e1 = new DotVarExp(loc, e1, tcd->vthis);
+ e1->type = tcd->vthis->type;
+ // Do not call checkNestedRef()
+ //e1 = e1->semantic(sc);
- // Skip up over nested functions, and get the enclosing
- // class type.
- int n = 0;
- Dsymbol *s;
- for (s = tcd->toParent();
- s && s->isFuncDeclaration();
- s = s->toParent())
- { FuncDeclaration *f = s->isFuncDeclaration();
- if (f->vthis)
- {
- //printf("rewriting e1 to %s's this\n", f->toChars());
- n++;
+ // Skip up over nested functions, and get the enclosing
+ // class type.
+ int n = 0;
+ Dsymbol *s;
+ for (s = tcd->toParent();
+ s && s->isFuncDeclaration();
+ s = s->toParent())
+ { FuncDeclaration *f = s->isFuncDeclaration();
+ if (f->vthis)
+ {
+ //printf("rewriting e1 to %s's this\n", f->toChars());
+ n++;
// LDC seems dmd misses it sometimes here :/
f->vthis->nestedref = 1;
- e1 = new VarExp(loc, f->vthis);
- }
- }
- if (s && s->isClassDeclaration())
- { e1->type = s->isClassDeclaration()->type;
- if (n > 1)
- e1 = e1->semantic(sc);
- }
- else
- e1 = e1->semantic(sc);
- goto L1;
- }
- /* Can't find a path from e1 to ad
- */
- e1->error("this for %s needs to be type %s not type %s",
- var->toChars(), ad->toChars(), t->toChars());
- }
+ e1 = new VarExp(loc, f->vthis);
+ }
+ }
+ if (s && s->isClassDeclaration())
+ { e1->type = s->isClassDeclaration()->type;
+ if (n > 1)
+ e1 = e1->semantic(sc);
+ }
+ else
+ e1 = e1->semantic(sc);
+ goto L1;
+ }
+ /* Can't find a path from e1 to ad
+ */
+ e1->error("this for %s needs to be type %s not type %s",
+ var->toChars(), ad->toChars(), t->toChars());
+ }
}
return e1;
}
@@ -306,36 +306,36 @@ FuncDeclaration *hasThis(Scope *sc)
fd = fdthis;
while (1)
{
- if (!fd)
- {
- goto Lno;
- }
- if (!fd->isNested())
- break;
+ if (!fd)
+ {
+ goto Lno;
+ }
+ if (!fd->isNested())
+ break;
- Dsymbol *parent = fd->parent;
- while (parent)
- {
- TemplateInstance *ti = parent->isTemplateInstance();
- if (ti)
- parent = ti->parent;
- else
- break;
- }
+ Dsymbol *parent = fd->parent;
+ while (parent)
+ {
+ TemplateInstance *ti = parent->isTemplateInstance();
+ if (ti)
+ parent = ti->parent;
+ else
+ break;
+ }
- fd = fd->parent->isFuncDeclaration();
+ fd = fd->parent->isFuncDeclaration();
}
if (!fd->isThis())
{ //printf("test '%s'\n", fd->toChars());
- goto Lno;
+ goto Lno;
}
assert(fd->vthis);
return fd;
Lno:
- return NULL; // don't have 'this' available
+ return NULL; // don't have 'this' available
}
@@ -348,36 +348,36 @@ Expression *resolveProperties(Scope *sc, Expression *e)
//printf("resolveProperties(%s)\n", e->toChars());
if (e->type)
{
- Type *t = e->type->toBasetype();
+ Type *t = e->type->toBasetype();
- if (t->ty == Tfunction /*|| e->op == TOKoverloadset*/)
- {
- e = new CallExp(e->loc, e);
- e = e->semantic(sc);
- }
+ if (t->ty == Tfunction /*|| e->op == TOKoverloadset*/)
+ {
+ e = new CallExp(e->loc, e);
+ e = e->semantic(sc);
+ }
- /* Look for e being a lazy parameter; rewrite as delegate call
- */
- else if (e->op == TOKvar)
- { VarExp *ve = (VarExp *)e;
+ /* Look for e being a lazy parameter; rewrite as delegate call
+ */
+ else if (e->op == TOKvar)
+ { VarExp *ve = (VarExp *)e;
- if (ve->var->storage_class & STClazy)
- {
- e = new CallExp(e->loc, e);
- e = e->semantic(sc);
- }
- }
+ if (ve->var->storage_class & STClazy)
+ {
+ e = new CallExp(e->loc, e);
+ e = e->semantic(sc);
+ }
+ }
- else if (e->op == TOKdotexp)
- {
- e->error("expression has no value");
- }
+ else if (e->op == TOKdotexp)
+ {
+ e->error("expression has no value");
+ }
}
else if (e->op == TOKdottd)
{
- e = new CallExp(e->loc, e);
- e = e->semantic(sc);
+ e = new CallExp(e->loc, e);
+ e = e->semantic(sc);
}
return e;
}
@@ -390,12 +390,12 @@ void arrayExpressionSemantic(Expressions *exps, Scope *sc)
{
if (exps)
{
- for (size_t i = 0; i < exps->dim; i++)
- { Expression *e = (Expression *)exps->data[i];
+ for (size_t i = 0; i < exps->dim; i++)
+ { Expression *e = (Expression *)exps->data[i];
- e = e->semantic(sc);
- exps->data[i] = (void *)e;
- }
+ e = e->semantic(sc);
+ exps->data[i] = (void *)e;
+ }
}
}
@@ -409,11 +409,11 @@ int arrayExpressionCanThrow(Expressions *exps)
{
if (exps)
{
- for (size_t i = 0; i < exps->dim; i++)
- { Expression *e = (Expression *)exps->data[i];
- if (e && e->canThrow())
- return 1;
- }
+ for (size_t i = 0; i < exps->dim; i++)
+ { Expression *e = (Expression *)exps->data[i];
+ if (e && e->canThrow())
+ return 1;
+ }
}
return 0;
}
@@ -428,39 +428,39 @@ void expandTuples(Expressions *exps)
//printf("expandTuples()\n");
if (exps)
{
- for (size_t i = 0; i < exps->dim; i++)
- { Expression *arg = (Expression *)exps->data[i];
- if (!arg)
- continue;
+ for (size_t i = 0; i < exps->dim; i++)
+ { Expression *arg = (Expression *)exps->data[i];
+ if (!arg)
+ continue;
- // Look for tuple with 0 members
- if (arg->op == TOKtype)
- { TypeExp *e = (TypeExp *)arg;
- if (e->type->toBasetype()->ty == Ttuple)
- { TypeTuple *tt = (TypeTuple *)e->type->toBasetype();
+ // Look for tuple with 0 members
+ if (arg->op == TOKtype)
+ { TypeExp *e = (TypeExp *)arg;
+ if (e->type->toBasetype()->ty == Ttuple)
+ { TypeTuple *tt = (TypeTuple *)e->type->toBasetype();
- if (!tt->arguments || tt->arguments->dim == 0)
- {
- exps->remove(i);
- if (i == exps->dim)
- return;
- i--;
- continue;
- }
- }
- }
+ if (!tt->arguments || tt->arguments->dim == 0)
+ {
+ exps->remove(i);
+ if (i == exps->dim)
+ return;
+ i--;
+ continue;
+ }
+ }
+ }
- // Inline expand all the tuples
- while (arg->op == TOKtuple)
- { TupleExp *te = (TupleExp *)arg;
+ // Inline expand all the tuples
+ while (arg->op == TOKtuple)
+ { TupleExp *te = (TupleExp *)arg;
- exps->remove(i); // remove arg
- exps->insert(i, te->exps); // replace with tuple contents
- if (i == exps->dim)
- return; // empty tuple, no more arguments
- arg = (Expression *)exps->data[i];
- }
- }
+ exps->remove(i); // remove arg
+ exps->insert(i, te->exps); // replace with tuple contents
+ if (i == exps->dim)
+ return; // empty tuple, no more arguments
+ arg = (Expression *)exps->data[i];
+ }
+ }
}
}
@@ -471,25 +471,25 @@ Expressions *arrayExpressionToCommonType(Scope *sc, Expressions *exps, Type **pt
*/
Type *t0 = NULL;
for (size_t i = 0; i < exps->dim; i++)
- { Expression *e = (Expression *)exps->data[i];
+ { Expression *e = (Expression *)exps->data[i];
- if (!e->type)
- { error("%s has no value", e->toChars());
- e = new ErrorExp();
- }
- e = resolveProperties(sc, e);
+ if (!e->type)
+ { error("%s has no value", e->toChars());
+ e = new ErrorExp();
+ }
+ e = resolveProperties(sc, e);
- if (!t0)
- t0 = e->type;
- else
- e = e->implicitCastTo(sc, t0);
- exps->data[i] = (void *)e;
+ if (!t0)
+ t0 = e->type;
+ else
+ e = e->implicitCastTo(sc, t0);
+ exps->data[i] = (void *)e;
}
if (!t0)
- t0 = Type::tvoid;
+ t0 = Type::tvoid;
if (pt)
- *pt = t0;
+ *pt = t0;
// Eventually, we want to make this copy-on-write
return exps;
@@ -506,47 +506,47 @@ Expressions *arrayExpressionToCommonType(Scope *sc, Expressions *exps, Type **pt
for (size_t i = 0; i < exps->dim; i++)
{ Expression *e = (Expression *)exps->data[i];
- e = resolveProperties(sc, e);
- if (!e->type)
- { error("%s has no value", e->toChars());
- e = new ErrorExp();
- }
+ e = resolveProperties(sc, e);
+ if (!e->type)
+ { error("%s has no value", e->toChars());
+ e = new ErrorExp();
+ }
- if (t0)
- { if (t0 != e->type)
- {
- /* This applies ?: to merge the types. It's backwards;
- * ?: should call this function to merge types.
- */
- condexp.type = NULL;
- condexp.e1 = e0;
- condexp.e2 = e;
- condexp.semantic(sc);
- exps->data[j0] = (void *)condexp.e1;
- e = condexp.e2;
- t0 = e->type;
- }
- }
- else
- { j0 = i;
- e0 = e;
- t0 = e->type;
- }
- exps->data[i] = (void *)e;
+ if (t0)
+ { if (t0 != e->type)
+ {
+ /* This applies ?: to merge the types. It's backwards;
+ * ?: should call this function to merge types.
+ */
+ condexp.type = NULL;
+ condexp.e1 = e0;
+ condexp.e2 = e;
+ condexp.semantic(sc);
+ exps->data[j0] = (void *)condexp.e1;
+ e = condexp.e2;
+ t0 = e->type;
+ }
+ }
+ else
+ { j0 = i;
+ e0 = e;
+ t0 = e->type;
+ }
+ exps->data[i] = (void *)e;
}
if (t0)
{
- for (size_t i = 0; i < exps->dim; i++)
- { Expression *e = (Expression *)exps->data[i];
- e = e->implicitCastTo(sc, t0);
- exps->data[i] = (void *)e;
- }
+ for (size_t i = 0; i < exps->dim; i++)
+ { Expression *e = (Expression *)exps->data[i];
+ e = e->implicitCastTo(sc, t0);
+ exps->data[i] = (void *)e;
+ }
}
else
- t0 = Type::tvoid; // [] is typed as void[]
+ t0 = Type::tvoid; // [] is typed as void[]
if (pt)
- *pt = t0;
+ *pt = t0;
// Eventually, we want to make this copy-on-write
return exps;
@@ -561,34 +561,34 @@ void preFunctionParameters(Loc loc, Scope *sc, Expressions *exps)
{
if (exps)
{
- expandTuples(exps);
+ expandTuples(exps);
- for (size_t i = 0; i < exps->dim; i++)
- { Expression *arg = (Expression *)exps->data[i];
+ for (size_t i = 0; i < exps->dim; i++)
+ { Expression *arg = (Expression *)exps->data[i];
- if (!arg->type)
- {
+ if (!arg->type)
+ {
#ifdef DEBUG
- if (!global.gag)
- printf("1: \n");
+ if (!global.gag)
+ printf("1: \n");
#endif
- arg->error("%s is not an expression", arg->toChars());
- arg = new IntegerExp(arg->loc, 0, Type::tint32);
- }
+ arg->error("%s is not an expression", arg->toChars());
+ arg = new IntegerExp(arg->loc, 0, Type::tint32);
+ }
- arg = resolveProperties(sc, arg);
- exps->data[i] = (void *) arg;
+ arg = resolveProperties(sc, arg);
+ exps->data[i] = (void *) arg;
- //arg->rvalue();
+ //arg->rvalue();
#if 0
- if (arg->type->ty == Tfunction)
- {
- arg = new AddrExp(arg->loc, arg);
- arg = arg->semantic(sc);
- exps->data[i] = (void *) arg;
- }
+ if (arg->type->ty == Tfunction)
+ {
+ arg = new AddrExp(arg->loc, arg);
+ arg = arg->semantic(sc);
+ exps->data[i] = (void *) arg;
+ }
#endif
- }
+ }
}
}
@@ -603,17 +603,17 @@ Expression *callCpCtor(Loc loc, Scope *sc, Expression *e)
StructDeclaration *sd = ((TypeStruct *)tb)->sym;
if (sd->cpctor)
{
- /* Create a variable tmp, and replace the argument e with:
- * (tmp = e),tmp
- * and let AssignExp() handle the construction.
- * This is not the most efficent, ideally tmp would be constructed
- * directly onto the stack.
- */
- Identifier *idtmp = Lexer::uniqueId("__tmp");
- VarDeclaration *tmp = new VarDeclaration(loc, tb, idtmp, new ExpInitializer(0, e));
- Expression *ae = new DeclarationExp(loc, tmp);
- e = new CommaExp(loc, ae, new VarExp(loc, tmp));
- e = e->semantic(sc);
+ /* Create a variable tmp, and replace the argument e with:
+ * (tmp = e),tmp
+ * and let AssignExp() handle the construction.
+ * This is not the most efficent, ideally tmp would be constructed
+ * directly onto the stack.
+ */
+ Identifier *idtmp = Lexer::uniqueId("__tmp");
+ VarDeclaration *tmp = new VarDeclaration(loc, tb, idtmp, new ExpInitializer(0, e));
+ Expression *ae = new DeclarationExp(loc, tmp);
+ e = new CommaExp(loc, ae, new VarExp(loc, tmp));
+ e = e->semantic(sc);
}
return e;
}
@@ -622,10 +622,10 @@ Expression *callCpCtor(Loc loc, Scope *sc, Expression *e)
/****************************************
* Now that we know the exact type of the function we're calling,
* the arguments[] need to be adjusted:
- * 1. implicitly convert argument to the corresponding parameter type
- * 2. add default arguments for any missing arguments
- * 3. do default promotions on arguments corresponding to ...
- * 4. add hidden _arguments[] argument
+ * 1. implicitly convert argument to the corresponding parameter type
+ * 2. add default arguments for any missing arguments
+ * 3. do default promotions on arguments corresponding to ...
+ * 4. add hidden _arguments[] argument
*/
void functionParameters(Loc loc, Scope *sc, TypeFunction *tf, Expressions *arguments)
@@ -638,274 +638,274 @@ void functionParameters(Loc loc, Scope *sc, TypeFunction *tf, Expressions *argum
size_t nparams = Parameter::dim(tf->parameters);
if (nargs > nparams && tf->varargs == 0)
- error(loc, "expected %zu arguments, not %zu for non-variadic function type %s", nparams, nargs, tf->toChars());
+ error(loc, "expected %zu arguments, not %zu for non-variadic function type %s", nparams, nargs, tf->toChars());
- n = (nargs > nparams) ? nargs : nparams; // n = max(nargs, nparams)
+ n = (nargs > nparams) ? nargs : nparams; // n = max(nargs, nparams)
int done = 0;
for (size_t i = 0; i < n; i++)
{
- Expression *arg;
+ Expression *arg;
- if (i < nargs)
- arg = (Expression *)arguments->data[i];
- else
- arg = NULL;
- Type *tb;
+ if (i < nargs)
+ arg = (Expression *)arguments->data[i];
+ else
+ arg = NULL;
+ Type *tb;
- if (i < nparams)
- {
- Parameter *p = Parameter::getNth(tf->parameters, i);
+ if (i < nparams)
+ {
+ Parameter *p = Parameter::getNth(tf->parameters, i);
- if (!arg)
- {
- if (!p->defaultArg)
- {
- if (tf->varargs == 2 && i + 1 == nparams)
- goto L2;
- error(loc, "expected %zu function arguments, not %zu", nparams, nargs);
- return;
- }
- arg = p->defaultArg;
+ if (!arg)
+ {
+ if (!p->defaultArg)
+ {
+ if (tf->varargs == 2 && i + 1 == nparams)
+ goto L2;
+ error(loc, "expected %zu function arguments, not %zu", nparams, nargs);
+ return;
+ }
+ arg = p->defaultArg;
#if DMDV2
- if (arg->op == TOKdefault)
- { DefaultInitExp *de = (DefaultInitExp *)arg;
- arg = de->resolve(loc, sc);
- }
- else
+ if (arg->op == TOKdefault)
+ { DefaultInitExp *de = (DefaultInitExp *)arg;
+ arg = de->resolve(loc, sc);
+ }
+ else
#endif
- arg = arg->copy();
- arguments->push(arg);
- nargs++;
- }
+ arg = arg->copy();
+ arguments->push(arg);
+ nargs++;
+ }
- if (tf->varargs == 2 && i + 1 == nparams)
- {
- //printf("\t\tvarargs == 2, p->type = '%s'\n", p->type->toChars());
- if (arg->implicitConvTo(p->type))
- {
- if (nargs != nparams)
- { error(loc, "expected %zu function arguments, not %zu", nparams, nargs);
- return;
- }
- goto L1;
- }
- L2:
- Type *tb = p->type->toBasetype();
- Type *tret = p->isLazyArray();
- switch (tb->ty)
- {
- case Tsarray:
- case Tarray:
- { // Create a static array variable v of type arg->type
+ if (tf->varargs == 2 && i + 1 == nparams)
+ {
+ //printf("\t\tvarargs == 2, p->type = '%s'\n", p->type->toChars());
+ if (arg->implicitConvTo(p->type))
+ {
+ if (nargs != nparams)
+ { error(loc, "expected %zu function arguments, not %zu", nparams, nargs);
+ return;
+ }
+ goto L1;
+ }
+ L2:
+ Type *tb = p->type->toBasetype();
+ Type *tret = p->isLazyArray();
+ switch (tb->ty)
+ {
+ case Tsarray:
+ case Tarray:
+ { // Create a static array variable v of type arg->type
#ifdef IN_GCC
- /* GCC 4.0 does not like zero length arrays used like
- this; pass a null array value instead. Could also
- just make a one-element array. */
- if (nargs - i == 0)
- {
- arg = new NullExp(loc);
- break;
- }
+ /* GCC 4.0 does not like zero length arrays used like
+ this; pass a null array value instead. Could also
+ just make a one-element array. */
+ if (nargs - i == 0)
+ {
+ arg = new NullExp(loc);
+ break;
+ }
#endif
- Identifier *id = Lexer::uniqueId("__arrayArg");
- Type *t = new TypeSArray(((TypeArray *)tb)->next, new IntegerExp(nargs - i));
- t = t->semantic(loc, sc);
- VarDeclaration *v = new VarDeclaration(loc, t, id, new VoidInitializer(loc));
- v->storage_class |= STCctfe;
- v->semantic(sc);
- v->parent = sc->parent;
- //sc->insert(v);
+ Identifier *id = Lexer::uniqueId("__arrayArg");
+ Type *t = new TypeSArray(((TypeArray *)tb)->next, new IntegerExp(nargs - i));
+ t = t->semantic(loc, sc);
+ VarDeclaration *v = new VarDeclaration(loc, t, id, new VoidInitializer(loc));
+ v->storage_class |= STCctfe;
+ v->semantic(sc);
+ v->parent = sc->parent;
+ //sc->insert(v);
- Expression *c = new DeclarationExp(0, v);
- c->type = v->type;
+ Expression *c = new DeclarationExp(0, v);
+ c->type = v->type;
- for (size_t u = i; u < nargs; u++)
- { Expression *a = (Expression *)arguments->data[u];
- if (tret && !((TypeArray *)tb)->next->equals(a->type))
- a = a->toDelegate(sc, tret);
+ for (size_t u = i; u < nargs; u++)
+ { Expression *a = (Expression *)arguments->data[u];
+ if (tret && !((TypeArray *)tb)->next->equals(a->type))
+ a = a->toDelegate(sc, tret);
- Expression *e = new VarExp(loc, v);
- e = new IndexExp(loc, e, new IntegerExp(u + 1 - nparams));
- AssignExp *ae = new AssignExp(loc, e, a);
+ Expression *e = new VarExp(loc, v);
+ e = new IndexExp(loc, e, new IntegerExp(u + 1 - nparams));
+ AssignExp *ae = new AssignExp(loc, e, a);
#if DMDV2
- ae->op = TOKconstruct;
+ ae->op = TOKconstruct;
#endif
- if (c)
- c = new CommaExp(loc, c, ae);
- else
- c = ae;
- }
- arg = new VarExp(loc, v);
- if (c)
- arg = new CommaExp(loc, c, arg);
- break;
- }
- case Tclass:
- { /* Set arg to be:
- * new Tclass(arg0, arg1, ..., argn)
- */
- Expressions *args = new Expressions();
- args->setDim(nargs - i);
- for (size_t u = i; u < nargs; u++)
- args->data[u - i] = arguments->data[u];
- arg = new NewExp(loc, NULL, NULL, p->type, args);
- break;
- }
- default:
- if (!arg)
- { error(loc, "not enough arguments");
- return;
- }
- break;
- }
- arg = arg->semantic(sc);
- //printf("\targ = '%s'\n", arg->toChars());
- arguments->setDim(i + 1);
- done = 1;
- }
+ if (c)
+ c = new CommaExp(loc, c, ae);
+ else
+ c = ae;
+ }
+ arg = new VarExp(loc, v);
+ if (c)
+ arg = new CommaExp(loc, c, arg);
+ break;
+ }
+ case Tclass:
+ { /* Set arg to be:
+ * new Tclass(arg0, arg1, ..., argn)
+ */
+ Expressions *args = new Expressions();
+ args->setDim(nargs - i);
+ for (size_t u = i; u < nargs; u++)
+ args->data[u - i] = arguments->data[u];
+ arg = new NewExp(loc, NULL, NULL, p->type, args);
+ break;
+ }
+ default:
+ if (!arg)
+ { error(loc, "not enough arguments");
+ return;
+ }
+ break;
+ }
+ arg = arg->semantic(sc);
+ //printf("\targ = '%s'\n", arg->toChars());
+ arguments->setDim(i + 1);
+ done = 1;
+ }
- L1:
- if (!(p->storageClass & STClazy && p->type->ty == Tvoid))
- {
- if (p->type != arg->type)
- {
- //printf("arg->type = %s, p->type = %s\n", arg->type->toChars(), p->type->toChars());
- if (arg->op == TOKtype)
- arg->error("cannot pass type %s as function argument", arg->toChars());
- arg = arg->implicitCastTo(sc, p->type);
- arg = arg->optimize(WANTvalue);
- }
- }
- if (p->storageClass & (STCout | STCref))
- {
- // BUG: should check that argument to ref is type 'invariant'
- // BUG: assignments to ref should also be type 'invariant'
- arg = arg->modifiableLvalue(sc, arg);
+ L1:
+ if (!(p->storageClass & STClazy && p->type->ty == Tvoid))
+ {
+ if (p->type != arg->type)
+ {
+ //printf("arg->type = %s, p->type = %s\n", arg->type->toChars(), p->type->toChars());
+ if (arg->op == TOKtype)
+ arg->error("cannot pass type %s as function argument", arg->toChars());
+ arg = arg->implicitCastTo(sc, p->type);
+ arg = arg->optimize(WANTvalue);
+ }
+ }
+ if (p->storageClass & (STCout | STCref))
+ {
+ // BUG: should check that argument to ref is type 'invariant'
+ // BUG: assignments to ref should also be type 'invariant'
+ arg = arg->modifiableLvalue(sc, arg);
- //if (arg->op == TOKslice)
- //arg->error("cannot modify slice %s", arg->toChars());
- }
+ //if (arg->op == TOKslice)
+ //arg->error("cannot modify slice %s", arg->toChars());
+ }
// LDC we don't want this!
#if !IN_LLVM
- // Convert static arrays to pointers
- tb = arg->type->toBasetype();
- if (tb->ty == Tsarray)
- {
- arg = arg->checkToPointer();
- }
+ // Convert static arrays to pointers
+ tb = arg->type->toBasetype();
+ if (tb->ty == Tsarray)
+ {
+ arg = arg->checkToPointer();
+ }
#endif
#if DMDV2
- if (tb->ty == Tstruct && !(p->storageClass & (STCref | STCout)))
- {
- arg = callCpCtor(loc, sc, arg);
- }
+ if (tb->ty == Tstruct && !(p->storageClass & (STCref | STCout)))
+ {
+ arg = callCpCtor(loc, sc, arg);
+ }
#endif
- // Convert lazy argument to a delegate
- if (p->storageClass & STClazy)
- {
- arg = arg->toDelegate(sc, p->type);
- }
+ // Convert lazy argument to a delegate
+ if (p->storageClass & STClazy)
+ {
+ arg = arg->toDelegate(sc, p->type);
+ }
#if DMDV2
- /* Look for arguments that cannot 'escape' from the called
- * function.
- */
- if (!tf->parameterEscapes(p))
- {
- /* Function literals can only appear once, so if this
- * appearance was scoped, there cannot be any others.
- */
- if (arg->op == TOKfunction)
- { FuncExp *fe = (FuncExp *)arg;
- fe->fd->tookAddressOf = 0;
- }
+ /* Look for arguments that cannot 'escape' from the called
+ * function.
+ */
+ if (!tf->parameterEscapes(p))
+ {
+ /* Function literals can only appear once, so if this
+ * appearance was scoped, there cannot be any others.
+ */
+ if (arg->op == TOKfunction)
+ { FuncExp *fe = (FuncExp *)arg;
+ fe->fd->tookAddressOf = 0;
+ }
- /* For passing a delegate to a scoped parameter,
- * this doesn't count as taking the address of it.
- * We only worry about 'escaping' references to the function.
- */
- else if (arg->op == TOKdelegate)
- { DelegateExp *de = (DelegateExp *)arg;
- if (de->e1->op == TOKvar)
- { VarExp *ve = (VarExp *)de->e1;
- FuncDeclaration *f = ve->var->isFuncDeclaration();
- if (f)
- { f->tookAddressOf--;
- //printf("tookAddressOf = %d\n", f->tookAddressOf);
- }
- }
- }
- }
+ /* For passing a delegate to a scoped parameter,
+ * this doesn't count as taking the address of it.
+ * We only worry about 'escaping' references to the function.
+ */
+ else if (arg->op == TOKdelegate)
+ { DelegateExp *de = (DelegateExp *)arg;
+ if (de->e1->op == TOKvar)
+ { VarExp *ve = (VarExp *)de->e1;
+ FuncDeclaration *f = ve->var->isFuncDeclaration();
+ if (f)
+ { f->tookAddressOf--;
+ //printf("tookAddressOf = %d\n", f->tookAddressOf);
+ }
+ }
+ }
+ }
#endif
- }
- else
- {
+ }
+ else
+ {
- // If not D linkage, do promotions
+ // If not D linkage, do promotions
// LDC: don't do promotions on intrinsics
- if (tf->linkage != LINKd && tf->linkage != LINKintrinsic)
- {
- // Promote bytes, words, etc., to ints
- arg = arg->integralPromotions(sc);
+ if (tf->linkage != LINKd && tf->linkage != LINKintrinsic)
+ {
+ // Promote bytes, words, etc., to ints
+ arg = arg->integralPromotions(sc);
- // Promote floats to doubles
- switch (arg->type->ty)
- {
- case Tfloat32:
- arg = arg->castTo(sc, Type::tfloat64);
- break;
+ // Promote floats to doubles
+ switch (arg->type->ty)
+ {
+ case Tfloat32:
+ arg = arg->castTo(sc, Type::tfloat64);
+ break;
- case Timaginary32:
- arg = arg->castTo(sc, Type::timaginary64);
- break;
- }
- }
+ case Timaginary32:
+ arg = arg->castTo(sc, Type::timaginary64);
+ break;
+ }
+ }
- // Convert static arrays to dynamic arrays
- tb = arg->type->toBasetype();
- if (tb->ty == Tsarray)
- { TypeSArray *ts = (TypeSArray *)tb;
- Type *ta = ts->next->arrayOf();
- if (ts->size(arg->loc) == 0)
- arg = new NullExp(arg->loc, ta);
- else
- arg = arg->castTo(sc, ta);
- }
+ // Convert static arrays to dynamic arrays
+ tb = arg->type->toBasetype();
+ if (tb->ty == Tsarray)
+ { TypeSArray *ts = (TypeSArray *)tb;
+ Type *ta = ts->next->arrayOf();
+ if (ts->size(arg->loc) == 0)
+ arg = new NullExp(arg->loc, ta);
+ else
+ arg = arg->castTo(sc, ta);
+ }
#if DMDV2
- if (tb->ty == Tstruct)
- {
- arg = callCpCtor(loc, sc, arg);
- }
+ if (tb->ty == Tstruct)
+ {
+ arg = callCpCtor(loc, sc, arg);
+ }
#endif
- // Give error for overloaded function addresses
+ // Give error for overloaded function addresses
#if DMDV2
- if (arg->op == TOKsymoff)
- { SymOffExp *se = (SymOffExp *)arg;
- if (
- se->hasOverloads &&
- !se->var->isFuncDeclaration()->isUnique())
- arg->error("function %s is overloaded", arg->toChars());
- }
+ if (arg->op == TOKsymoff)
+ { SymOffExp *se = (SymOffExp *)arg;
+ if (
+ se->hasOverloads &&
+ !se->var->isFuncDeclaration()->isUnique())
+ arg->error("function %s is overloaded", arg->toChars());
+ }
#endif
- arg->rvalue();
- }
- arg = arg->optimize(WANTvalue);
- arguments->data[i] = (void *) arg;
- if (done)
- break;
+ arg->rvalue();
+ }
+ arg = arg->optimize(WANTvalue);
+ arguments->data[i] = (void *) arg;
+ if (done)
+ break;
}
#if !IN_LLVM
// If D linkage and variadic, add _arguments[] as first argument
if (tf->linkage == LINKd && tf->varargs == 1)
{
- assert(arguments->dim >= nparams);
- Expression *e = createTypeInfoArray(sc, (Expression **)&arguments->data[nparams],
- arguments->dim - nparams);
- arguments->insert(0, e);
+ assert(arguments->dim >= nparams);
+ Expression *e = createTypeInfoArray(sc, (Expression **)&arguments->data[nparams],
+ arguments->dim - nparams);
+ arguments->insert(0, e);
}
#endif
}
@@ -919,17 +919,17 @@ void expToCBuffer(OutBuffer *buf, HdrGenState *hgs, Expression *e, enum PREC pr)
{
//if (precedence[e->op] == 0) e->dump(0);
if (precedence[e->op] < pr ||
- /* Despite precedence, we don't allow aop] == pr))
+ /* Despite precedence, we don't allow aop] == pr))
{
- buf->writeByte('(');
- e->toCBuffer(buf, hgs);
- buf->writeByte(')');
+ buf->writeByte('(');
+ e->toCBuffer(buf, hgs);
+ buf->writeByte(')');
}
else
- e->toCBuffer(buf, hgs);
+ e->toCBuffer(buf, hgs);
}
/**************************************************
@@ -940,15 +940,15 @@ void argsToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs)
{
if (arguments)
{
- for (size_t i = 0; i < arguments->dim; i++)
- { Expression *arg = (Expression *)arguments->data[i];
+ for (size_t i = 0; i < arguments->dim; i++)
+ { Expression *arg = (Expression *)arguments->data[i];
- if (arg)
- { if (i)
- buf->writeByte(',');
- expToCBuffer(buf, hgs, arg, PREC_assign);
- }
- }
+ if (arg)
+ { if (i)
+ buf->writeByte(',');
+ expToCBuffer(buf, hgs, arg, PREC_assign);
+ }
+ }
}
}
@@ -959,17 +959,17 @@ void argsToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs)
void argExpTypesToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs)
{
if (arguments)
- { OutBuffer argbuf;
+ { OutBuffer argbuf;
- for (size_t i = 0; i < arguments->dim; i++)
- { Expression *arg = (Expression *)arguments->data[i];
+ for (size_t i = 0; i < arguments->dim; i++)
+ { Expression *arg = (Expression *)arguments->data[i];
- if (i)
- buf->writeByte(',');
- argbuf.reset();
- arg->type->toCBuffer2(&argbuf, hgs, 0);
- buf->write(&argbuf);
- }
+ if (i)
+ buf->writeByte(',');
+ argbuf.reset();
+ arg->type->toCBuffer2(&argbuf, hgs, 0);
+ buf->write(&argbuf);
+ }
}
}
@@ -1006,11 +1006,11 @@ Expression *Expression::copy()
if (!size)
{
#ifdef DEBUG
- fprintf(stdmsg, "No expression copy for: %s\n", toChars());
- printf("op = %d\n", op);
- dump(0);
+ fprintf(stdmsg, "No expression copy for: %s\n", toChars());
+ printf("op = %d\n", op);
+ dump(0);
#endif
- assert(0);
+ assert(0);
}
e = (Expression *)mem.malloc(size);
//printf("Expression::copy(op = %d) e = %p\n", op, e);
@@ -1028,9 +1028,9 @@ Expression *Expression::semantic(Scope *sc)
printf("Expression::semantic() %s\n", toChars());
#endif
if (type)
- type = type->semantic(loc, sc);
+ type = type->semantic(loc, sc);
else
- type = Type::tvoid;
+ type = Type::tvoid;
return this;
}
@@ -1069,12 +1069,12 @@ void Expression::warning(const char *format, ...)
void Expression::rvalue()
{
if (type && type->toBasetype()->ty == Tvoid)
- { error("expression %s is void and has no value", toChars());
+ { error("expression %s is void and has no value", toChars());
#if 0
- dump(0);
- halt();
+ dump(0);
+ halt();
#endif
- type = Type::terror;
+ type = Type::terror;
}
}
@@ -1082,14 +1082,14 @@ Expression *Expression::combine(Expression *e1, Expression *e2)
{
if (e1)
{
- if (e2)
- {
- e1 = new CommaExp(e1->loc, e1, e2);
- e1->type = e2->type;
- }
+ if (e2)
+ {
+ e1 = new CommaExp(e1->loc, e1, e2);
+ e1->type = e2->type;
+ }
}
else
- e1 = e2;
+ e1 = e2;
return e1;
}
@@ -1159,9 +1159,9 @@ int Expression::isLvalue()
Expression *Expression::toLvalue(Scope *sc, Expression *e)
{
if (!e)
- e = this;
+ e = this;
else if (!loc.filename)
- loc = e->loc;
+ loc = e->loc;
error("%s is not an lvalue", e->toChars());
return this;
}
@@ -1173,7 +1173,7 @@ Expression *Expression::modifiableLvalue(Scope *sc, Expression *e)
// See if this expression is a modifiable lvalue (i.e. not const)
#if DMDV2
if (type && (!type->isMutable() || !type->isAssignable()))
- error("%s is not mutable", e->toChars());
+ error("%s is not mutable", e->toChars());
#endif
return toLvalue(sc, e);
}
@@ -1194,20 +1194,20 @@ void Expression::checkEscapeRef()
void Expression::checkScalar()
{
if (!type->isscalar())
- error("'%s' is not a scalar, it is a %s", toChars(), type->toChars());
+ error("'%s' is not a scalar, it is a %s", toChars(), type->toChars());
}
void Expression::checkNoBool()
{
if (type->toBasetype()->ty == Tbool)
- error("operation not allowed on bool '%s'", toChars());
+ error("operation not allowed on bool '%s'", toChars());
}
Expression *Expression::checkIntegral()
{
if (!type->isintegral())
- { error("'%s' is not of integral type, it is a %s", toChars(), type->toChars());
- return new ErrorExp();
+ { error("'%s' is not of integral type, it is a %s", toChars(), type->toChars());
+ return new ErrorExp();
}
return this;
}
@@ -1215,8 +1215,8 @@ Expression *Expression::checkIntegral()
Expression *Expression::checkArithmetic()
{
if (!type->isintegral() && !type->isfloating())
- { error("'%s' is not of arithmetic type, it is a %s", toChars(), type->toChars());
- return new ErrorExp();
+ { error("'%s' is not of arithmetic type, it is a %s", toChars(), type->toChars());
+ return new ErrorExp();
}
return this;
}
@@ -1230,32 +1230,32 @@ void Expression::checkDeprecated(Scope *sc, Dsymbol *s)
void Expression::checkPurity(Scope *sc, FuncDeclaration *f)
{
if (sc->func && sc->func->isPure() && !sc->intypeof && !f->isPure())
- error("pure function '%s' cannot call impure function '%s'\n",
- sc->func->toChars(), f->toChars());
+ error("pure function '%s' cannot call impure function '%s'\n",
+ sc->func->toChars(), f->toChars());
}
#endif
/********************************
* Check for expressions that have no use.
* Input:
- * flag 0 not going to use the result, so issue error message if no
- * side effects
- * 1 the result of the expression is used, but still check
- * for useless subexpressions
- * 2 do not issue error messages, just return !=0 if expression
- * has side effects
+ * flag 0 not going to use the result, so issue error message if no
+ * side effects
+ * 1 the result of the expression is used, but still check
+ * for useless subexpressions
+ * 2 do not issue error messages, just return !=0 if expression
+ * has side effects
*/
int Expression::checkSideEffect(int flag)
{
if (flag == 0)
- { if (op == TOKimport)
- {
- error("%s has no effect", toChars());
- }
- else
- error("%s has no effect in expression (%s)",
- Token::toChars(op), toChars());
+ { if (op == TOKimport)
+ {
+ error("%s has no effect", toChars());
+ }
+ else
+ error("%s has no effect in expression (%s)",
+ Token::toChars(op), toChars());
}
return 0;
}
@@ -1270,12 +1270,12 @@ Expression *Expression::checkToBoolean()
#ifdef DEBUG
if (!type)
- dump(0);
+ dump(0);
#endif
if (!type->checkBoolean())
{
- error("expression %s of type %s does not have a boolean value", toChars(), type->toChars());
+ error("expression %s of type %s does not have a boolean value", toChars(), type->toChars());
}
return this;
}
@@ -1294,12 +1294,12 @@ Expression *Expression::checkToPointer()
// If C static array, convert to pointer
tb = type->toBasetype();
if (tb->ty == Tsarray)
- { TypeSArray *ts = (TypeSArray *)tb;
- if (ts->size(loc) == 0)
- e = new NullExp(loc);
- else
- e = new AddrExp(loc, this);
- e->type = ts->next->pointerTo();
+ { TypeSArray *ts = (TypeSArray *)tb;
+ if (ts->size(loc) == 0)
+ e = new NullExp(loc);
+ else
+ e = new AddrExp(loc, this);
+ e->type = ts->next->pointerTo();
}
return e;
}
@@ -1329,9 +1329,9 @@ Expression *Expression::deref()
// type could be null if forward referencing an 'auto' variable
if (type && type->ty == Treference)
{
- Expression *e = new PtrExp(loc, this);
- e->type = ((TypeReference *)type)->next;
- return e;
+ Expression *e = new PtrExp(loc, this);
+ e->type = ((TypeReference *)type)->next;
+ return e;
}
return this;
}
@@ -1375,14 +1375,14 @@ Expressions *Expression::arraySyntaxCopy(Expressions *exps)
if (exps)
{
- a = new Expressions();
- a->setDim(exps->dim);
- for (int i = 0; i < a->dim; i++)
- { Expression *e = (Expression *)exps->data[i];
+ a = new Expressions();
+ a->setDim(exps->dim);
+ for (int i = 0; i < a->dim; i++)
+ { Expression *e = (Expression *)exps->data[i];
- e = e->syntaxCopy();
- a->data[i] = e;
- }
+ e = e->syntaxCopy();
+ a->data[i] = e;
+ }
}
return a;
}
@@ -1390,21 +1390,21 @@ Expressions *Expression::arraySyntaxCopy(Expressions *exps)
/******************************** IntegerExp **************************/
IntegerExp::IntegerExp(Loc loc, dinteger_t value, Type *type)
- : Expression(loc, TOKint64, sizeof(IntegerExp))
+ : Expression(loc, TOKint64, sizeof(IntegerExp))
{
//printf("IntegerExp(value = %lld, type = '%s')\n", value, type ? type->toChars() : "");
if (type && !type->isscalar())
{
- //printf("%s, loc = %d\n", toChars(), loc.linnum);
- error("integral constant must be scalar type, not %s", type->toChars());
- type = Type::terror;
+ //printf("%s, loc = %d\n", toChars(), loc.linnum);
+ error("integral constant must be scalar type, not %s", type->toChars());
+ type = Type::terror;
}
this->type = type;
this->value = value;
}
IntegerExp::IntegerExp(dinteger_t value)
- : Expression(0, TOKint64, sizeof(IntegerExp))
+ : Expression(0, TOKint64, sizeof(IntegerExp))
{
this->type = Type::tint32;
this->value = value;
@@ -1414,10 +1414,10 @@ int IntegerExp::equals(Object *o)
{ IntegerExp *ne;
if (this == o ||
- (((Expression *)o)->op == TOKint64 &&
- ((ne = (IntegerExp *)o), type->equals(ne->type)) &&
- value == ne->value))
- return 1;
+ (((Expression *)o)->op == TOKint64 &&
+ ((ne = (IntegerExp *)o), type->equals(ne->type)) &&
+ value == ne->value))
+ return 1;
return 0;
}
@@ -1439,55 +1439,55 @@ dinteger_t IntegerExp::toInteger()
t = type;
while (t)
{
- switch (t->ty)
- {
- case Tbit:
- case Tbool: value = (value != 0); break;
- case Tint8: value = (d_int8) value; break;
- case Tchar:
- case Tuns8: value = (d_uns8) value; break;
- case Tint16: value = (d_int16) value; break;
- case Twchar:
- case Tuns16: value = (d_uns16) value; break;
- case Tint32: value = (d_int32) value; break;
- case Tdchar:
- case Tuns32: value = (d_uns32) value; break;
- case Tint64: value = (d_int64) value; break;
- case Tuns64: value = (d_uns64) value; break;
- case Tpointer:
+ switch (t->ty)
+ {
+ case Tbit:
+ case Tbool: value = (value != 0); break;
+ case Tint8: value = (d_int8) value; break;
+ case Tchar:
+ case Tuns8: value = (d_uns8) value; break;
+ case Tint16: value = (d_int16) value; break;
+ case Twchar:
+ case Tuns16: value = (d_uns16) value; break;
+ case Tint32: value = (d_int32) value; break;
+ case Tdchar:
+ case Tuns32: value = (d_uns32) value; break;
+ case Tint64: value = (d_int64) value; break;
+ case Tuns64: value = (d_uns64) value; break;
+ case Tpointer:
if (PTRSIZE == 4)
value = (d_uns32) value;
else if (PTRSIZE == 8)
value = (d_uns64) value;
- else
- assert(0);
+ else
+ assert(0);
break;
- case Tenum:
- {
- TypeEnum *te = (TypeEnum *)t;
- t = te->sym->memtype;
- continue;
- }
+ case Tenum:
+ {
+ TypeEnum *te = (TypeEnum *)t;
+ t = te->sym->memtype;
+ continue;
+ }
- case Ttypedef:
- {
- TypeTypedef *tt = (TypeTypedef *)t;
- t = tt->sym->basetype;
- continue;
- }
+ case Ttypedef:
+ {
+ TypeTypedef *tt = (TypeTypedef *)t;
+ t = tt->sym->basetype;
+ continue;
+ }
- default:
- /* This can happen if errors, such as
- * the type is painted on like in fromConstInitializer().
- */
- if (!global.errors)
- { type->print();
- assert(0);
- }
- break;
- }
- break;
+ default:
+ /* This can happen if errors, such as
+ * the type is painted on like in fromConstInitializer().
+ */
+ if (!global.errors)
+ { type->print();
+ assert(0);
+ }
+ break;
+ }
+ break;
}
return value;
}
@@ -1499,9 +1499,9 @@ real_t IntegerExp::toReal()
toInteger();
t = type->toBasetype();
if (t->ty == Tuns64)
- return (real_t)(d_uns64)value;
+ return (real_t)(d_uns64)value;
else
- return (real_t)(d_int64)value;
+ return (real_t)(d_int64)value;
}
real_t IntegerExp::toImaginary()
@@ -1524,19 +1524,19 @@ Expression *IntegerExp::semantic(Scope *sc)
{
if (!type)
{
- // Determine what the type of this number is
- dinteger_t number = value;
+ // Determine what the type of this number is
+ dinteger_t number = value;
- if (number & 0x8000000000000000LL)
- type = Type::tuns64;
- else if (number & 0xFFFFFFFF80000000LL)
- type = Type::tint64;
- else
- type = Type::tint32;
+ if (number & 0x8000000000000000LL)
+ type = Type::tuns64;
+ else if (number & 0xFFFFFFFF80000000LL)
+ type = Type::tint64;
+ else
+ type = Type::tint32;
}
else
- { if (!type->deco)
- type = type->semantic(loc, sc);
+ { if (!type->deco)
+ type = type->semantic(loc, sc);
}
return this;
}
@@ -1544,9 +1544,9 @@ Expression *IntegerExp::semantic(Scope *sc)
Expression *IntegerExp::toLvalue(Scope *sc, Expression *e)
{
if (!e)
- e = this;
+ e = this;
else if (!loc.filename)
- loc = e->loc;
+ loc = e->loc;
e->error("constant %s is not an lvalue", e->toChars());
return this;
}
@@ -1556,128 +1556,128 @@ void IntegerExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
dinteger_t v = toInteger();
if (type)
- { Type *t = type;
+ { Type *t = type;
L1:
- switch (t->ty)
- {
- case Tenum:
- { TypeEnum *te = (TypeEnum *)t;
- buf->printf("cast(%s)", te->sym->toChars());
- t = te->sym->memtype;
- goto L1;
- }
+ switch (t->ty)
+ {
+ case Tenum:
+ { TypeEnum *te = (TypeEnum *)t;
+ buf->printf("cast(%s)", te->sym->toChars());
+ t = te->sym->memtype;
+ goto L1;
+ }
- case Ttypedef:
- { TypeTypedef *tt = (TypeTypedef *)t;
- buf->printf("cast(%s)", tt->sym->toChars());
- t = tt->sym->basetype;
- goto L1;
- }
+ case Ttypedef:
+ { TypeTypedef *tt = (TypeTypedef *)t;
+ buf->printf("cast(%s)", tt->sym->toChars());
+ t = tt->sym->basetype;
+ goto L1;
+ }
- case Twchar: // BUG: need to cast(wchar)
- case Tdchar: // BUG: need to cast(dchar)
- if ((uinteger_t)v > 0xFF)
- {
- buf->printf("'\\U%08x'", (unsigned)v);
- break;
- }
- case Tchar:
- if (v == '\'')
- buf->writestring("'\\''");
- else if (isprint(v) && v != '\\')
- buf->printf("'%c'", (int)v);
- else
- buf->printf("'\\x%02x'", (int)v);
- break;
+ case Twchar: // BUG: need to cast(wchar)
+ case Tdchar: // BUG: need to cast(dchar)
+ if ((uinteger_t)v > 0xFF)
+ {
+ buf->printf("'\\U%08x'", (unsigned)v);
+ break;
+ }
+ case Tchar:
+ if (v == '\'')
+ buf->writestring("'\\''");
+ else if (isprint(v) && v != '\\')
+ buf->printf("'%c'", (int)v);
+ else
+ buf->printf("'\\x%02x'", (int)v);
+ break;
- case Tint8:
- buf->writestring("cast(byte)");
- goto L2;
+ case Tint8:
+ buf->writestring("cast(byte)");
+ goto L2;
- case Tint16:
- buf->writestring("cast(short)");
- goto L2;
+ case Tint16:
+ buf->writestring("cast(short)");
+ goto L2;
- case Tint32:
- L2:
- buf->printf("%d", (int)v);
- break;
+ case Tint32:
+ L2:
+ buf->printf("%d", (int)v);
+ break;
- case Tuns8:
- buf->writestring("cast(ubyte)");
- goto L3;
+ case Tuns8:
+ buf->writestring("cast(ubyte)");
+ goto L3;
- case Tuns16:
- buf->writestring("cast(ushort)");
- goto L3;
+ case Tuns16:
+ buf->writestring("cast(ushort)");
+ goto L3;
- case Tuns32:
- L3:
- buf->printf("%du", (unsigned)v);
- break;
+ case Tuns32:
+ L3:
+ buf->printf("%du", (unsigned)v);
+ break;
- case Tint64:
- buf->printf("%jdL", v);
- break;
+ case Tint64:
+ buf->printf("%jdL", v);
+ break;
- case Tuns64:
- L4:
- buf->printf("%juLU", v);
- break;
+ case Tuns64:
+ L4:
+ buf->printf("%juLU", v);
+ break;
- case Tbit:
- case Tbool:
- buf->writestring((char *)(v ? "true" : "false"));
- break;
+ case Tbit:
+ case Tbool:
+ buf->writestring((char *)(v ? "true" : "false"));
+ break;
- case Tpointer:
- buf->writestring("cast(");
- buf->writestring(t->toChars());
- buf->writeByte(')');
+ case Tpointer:
+ buf->writestring("cast(");
+ buf->writestring(t->toChars());
+ buf->writeByte(')');
if (PTRSIZE == 4)
goto L3;
else if (PTRSIZE == 8)
goto L4;
- else
- assert(0);
+ else
+ assert(0);
- default:
- /* This can happen if errors, such as
- * the type is painted on like in fromConstInitializer().
- */
- if (!global.errors)
- {
+ default:
+ /* This can happen if errors, such as
+ * the type is painted on like in fromConstInitializer().
+ */
+ if (!global.errors)
+ {
#ifdef DEBUG
- t->print();
+ t->print();
#endif
- assert(0);
- }
- break;
- }
+ assert(0);
+ }
+ break;
+ }
}
else if (v & 0x8000000000000000LL)
- buf->printf("0x%jx", v);
+ buf->printf("0x%jx", v);
else
- buf->printf("%jd", v);
+ buf->printf("%jd", v);
}
void IntegerExp::toMangleBuffer(OutBuffer *buf)
{
if ((sinteger_t)value < 0)
- buf->printf("N%jd", -value);
+ buf->printf("N%jd", -value);
else
{
- /* This is an awful hack to maintain backwards compatibility.
- * There really always should be an 'i' before a number, but
- * there wasn't in earlier implementations, so to maintain
- * backwards compatibility it is only done if necessary to disambiguate.
- * See bugzilla 3029
- */
- if (buf->offset > 0 && isdigit(buf->data[buf->offset - 1]))
- buf->writeByte('i');
+ /* This is an awful hack to maintain backwards compatibility.
+ * There really always should be an 'i' before a number, but
+ * there wasn't in earlier implementations, so to maintain
+ * backwards compatibility it is only done if necessary to disambiguate.
+ * See bugzilla 3029
+ */
+ if (buf->offset > 0 && isdigit(buf->data[buf->offset - 1]))
+ buf->writeByte('i');
- buf->printf("%jd", value);
+ buf->printf("%jd", value);
}
}
@@ -1700,7 +1700,7 @@ void ErrorExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/******************************** RealExp **************************/
RealExp::RealExp(Loc loc, real_t value, Type *type)
- : Expression(loc, TOKfloat64, sizeof(RealExp))
+ : Expression(loc, TOKfloat64, sizeof(RealExp))
{
//printf("RealExp::RealExp(%Lg)\n", value);
this->value = value;
@@ -1714,7 +1714,7 @@ char *RealExp::toChars()
#ifdef IN_GCC
value.format(buffer, sizeof(buffer));
if (type->isimaginary())
- strcat(buffer, "i");
+ strcat(buffer, "i");
#else
sprintf(buffer, type->isimaginary() ? "%Lgi" : "%Lg", value);
#endif
@@ -1771,33 +1771,33 @@ int RealEquals(real_t x1, real_t x2)
return (__inline_isnan(x1) && __inline_isnan(x2)) ||
#else
return // special case nans
- (isnan(x1) && isnan(x2)) ||
+ (isnan(x1) && isnan(x2)) ||
#endif
- // and zero, in order to distinguish +0 from -0
- (x1 == 0 && x2 == 0 && 1./x1 == 1./x2) ||
- // otherwise just compare
- (x1 != 0. && x1 == x2);
+ // and zero, in order to distinguish +0 from -0
+ (x1 == 0 && x2 == 0 && 1./x1 == 1./x2) ||
+ // otherwise just compare
+ (x1 != 0. && x1 == x2);
}
int RealExp::equals(Object *o)
{ RealExp *ne;
if (this == o ||
- (((Expression *)o)->op == TOKfloat64 &&
- ((ne = (RealExp *)o), type->equals(ne->type)) &&
- RealEquals(value, ne->value)
+ (((Expression *)o)->op == TOKfloat64 &&
+ ((ne = (RealExp *)o), type->equals(ne->type)) &&
+ RealEquals(value, ne->value)
)
)
- return 1;
+ return 1;
return 0;
}
Expression *RealExp::semantic(Scope *sc)
{
if (!type)
- type = Type::tfloat64;
+ type = Type::tfloat64;
else
- type = type->semantic(loc, sc);
+ type = type->semantic(loc, sc);
return this;
}
@@ -1807,7 +1807,7 @@ int RealExp::isBool(int result)
return result ? (! value.isZero()) : (value.isZero());
#else
return result ? (value != 0)
- : (value == 0);
+ : (value == 0);
#endif
}
@@ -1829,33 +1829,33 @@ void floatToBuffer(OutBuffer *buf, Type *type, real_t value)
#else
real_t r = strtold(buffer, NULL);
#endif
- if (r == value) // if exact duplication
- buf->writestring(buffer);
+ if (r == value) // if exact duplication
+ buf->writestring(buffer);
else
- buf->printf("%La", value); // ensure exact duplication
+ buf->printf("%La", value); // ensure exact duplication
if (type)
{
- Type *t = type->toBasetype();
- switch (t->ty)
- {
- case Tfloat32:
- case Timaginary32:
- case Tcomplex32:
- buf->writeByte('F');
- break;
+ Type *t = type->toBasetype();
+ switch (t->ty)
+ {
+ case Tfloat32:
+ case Timaginary32:
+ case Tcomplex32:
+ buf->writeByte('F');
+ break;
- case Tfloat80:
- case Timaginary80:
- case Tcomplex80:
- buf->writeByte('L');
- break;
+ case Tfloat80:
+ case Timaginary80:
+ case Tcomplex80:
+ buf->writeByte('L');
+ break;
- default:
- break;
- }
- if (t->isimaginary())
- buf->writeByte('i');
+ default:
+ break;
+ }
+ if (t->isimaginary())
+ buf->writeByte('i');
}
}
@@ -1869,12 +1869,12 @@ void realToMangleBuffer(OutBuffer *buf, real_t value)
/* Rely on %A to get portable mangling.
* Must munge result to get only identifier characters.
*
- * Possible values from %A => mangled result
- * NAN => NAN
- * -INF => NINF
- * INF => INF
- * -0X1.1BC18BA997B95P+79 => N11BC18BA997B95P79
- * 0X1.9P+2 => 19P2
+ * Possible values from %A => mangled result
+ * NAN => NAN
+ * -INF => NINF
+ * INF => INF
+ * -0X1.1BC18BA997B95P+79 => N11BC18BA997B95P79
+ * 0X1.9P+2 => 19P2
*/
#if __APPLE__
@@ -1882,34 +1882,34 @@ void realToMangleBuffer(OutBuffer *buf, real_t value)
#else
if (isnan(value))
#endif
- buf->writestring("NAN"); // no -NAN bugs
+ buf->writestring("NAN"); // no -NAN bugs
else
{
- char buffer[32];
- int n = sprintf(buffer, "%LA", value);
- assert(n > 0 && n < sizeof(buffer));
- for (int i = 0; i < n; i++)
- { char c = buffer[i];
+ char buffer[32];
+ int n = sprintf(buffer, "%LA", value);
+ assert(n > 0 && n < sizeof(buffer));
+ for (int i = 0; i < n; i++)
+ { char c = buffer[i];
- switch (c)
- {
- case '-':
- buf->writeByte('N');
- break;
+ switch (c)
+ {
+ case '-':
+ buf->writeByte('N');
+ break;
- case '+':
- case 'X':
- case '.':
- break;
+ case '+':
+ case 'X':
+ case '.':
+ break;
- case '0':
- if (i < 2)
- break; // skip leading 0X
- default:
- buf->writeByte(c);
- break;
- }
- }
+ case '0':
+ if (i < 2)
+ break; // skip leading 0X
+ default:
+ buf->writeByte(c);
+ break;
+ }
+ }
}
}
@@ -1923,7 +1923,7 @@ void RealExp::toMangleBuffer(OutBuffer *buf)
/******************************** ComplexExp **************************/
ComplexExp::ComplexExp(Loc loc, complex_t value, Type *type)
- : Expression(loc, TOKcomplex80, sizeof(ComplexExp))
+ : Expression(loc, TOKcomplex80, sizeof(ComplexExp))
{
this->value = value;
this->type = type;
@@ -1984,31 +1984,31 @@ int ComplexExp::equals(Object *o)
{ ComplexExp *ne;
if (this == o ||
- (((Expression *)o)->op == TOKcomplex80 &&
- ((ne = (ComplexExp *)o), type->equals(ne->type)) &&
- RealEquals(creall(value), creall(ne->value)) &&
- RealEquals(cimagl(value), cimagl(ne->value))
- )
+ (((Expression *)o)->op == TOKcomplex80 &&
+ ((ne = (ComplexExp *)o), type->equals(ne->type)) &&
+ RealEquals(creall(value), creall(ne->value)) &&
+ RealEquals(cimagl(value), cimagl(ne->value))
+ )
)
- return 1;
+ return 1;
return 0;
}
Expression *ComplexExp::semantic(Scope *sc)
{
if (!type)
- type = Type::tcomplex80;
+ type = Type::tcomplex80;
else
- type = type->semantic(loc, sc);
+ type = type->semantic(loc, sc);
return this;
}
int ComplexExp::isBool(int result)
{
if (result)
- return (bool)(value);
+ return (bool)(value);
else
- return !value;
+ return !value;
}
void ComplexExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
@@ -2036,7 +2036,7 @@ void ComplexExp::toMangleBuffer(OutBuffer *buf)
buf->writeByte('c');
real_t r = toReal();
realToMangleBuffer(buf, r);
- buf->writeByte('c'); // separate the two
+ buf->writeByte('c'); // separate the two
r = toImaginary();
realToMangleBuffer(buf, r);
}
@@ -2044,7 +2044,7 @@ void ComplexExp::toMangleBuffer(OutBuffer *buf)
/******************************** IdentifierExp **************************/
IdentifierExp::IdentifierExp(Loc loc, Identifier *ident)
- : Expression(loc, TOKidentifier, sizeof(IdentifierExp))
+ : Expression(loc, TOKidentifier, sizeof(IdentifierExp))
{
this->ident = ident;
}
@@ -2059,61 +2059,61 @@ Expression *IdentifierExp::semantic(Scope *sc)
#endif
s = sc->search(loc, ident, &scopesym);
if (s)
- { Expression *e;
- WithScopeSymbol *withsym;
+ { Expression *e;
+ WithScopeSymbol *withsym;
- /* See if the symbol was a member of an enclosing 'with'
- */
- withsym = scopesym->isWithScopeSymbol();
- if (withsym)
- {
- s = s->toAlias();
+ /* See if the symbol was a member of an enclosing 'with'
+ */
+ withsym = scopesym->isWithScopeSymbol();
+ if (withsym)
+ {
+ s = s->toAlias();
- // Same as wthis.ident
- if (s->needThis() || s->isTemplateDeclaration())
- {
- e = new VarExp(loc, withsym->withstate->wthis);
- e = new DotIdExp(loc, e, ident);
- }
- else
- { Type *t = withsym->withstate->wthis->type;
- if (t->ty == Tpointer)
- t = ((TypePointer *)t)->next;
- e = typeDotIdExp(loc, t, ident);
- }
- }
- else
- {
- if (!s->parent && scopesym->isArrayScopeSymbol())
- { // Kludge to run semantic() here because
- // ArrayScopeSymbol::search() doesn't have access to sc.
- s->semantic(sc);
- }
- /* If f is really a function template,
- * then replace f with the function template declaration.
- */
- FuncDeclaration *f = s->isFuncDeclaration();
- if (f && f->parent)
- { TemplateInstance *ti = f->parent->isTemplateInstance();
+ // Same as wthis.ident
+ if (s->needThis() || s->isTemplateDeclaration())
+ {
+ e = new VarExp(loc, withsym->withstate->wthis);
+ e = new DotIdExp(loc, e, ident);
+ }
+ else
+ { Type *t = withsym->withstate->wthis->type;
+ if (t->ty == Tpointer)
+ t = ((TypePointer *)t)->next;
+ e = typeDotIdExp(loc, t, ident);
+ }
+ }
+ else
+ {
+ if (!s->parent && scopesym->isArrayScopeSymbol())
+ { // Kludge to run semantic() here because
+ // ArrayScopeSymbol::search() doesn't have access to sc.
+ s->semantic(sc);
+ }
+ /* If f is really a function template,
+ * then replace f with the function template declaration.
+ */
+ FuncDeclaration *f = s->isFuncDeclaration();
+ if (f && f->parent)
+ { TemplateInstance *ti = f->parent->isTemplateInstance();
- if (ti &&
- !ti->isTemplateMixin() &&
- (ti->name == f->ident ||
- ti->toAlias()->ident == f->ident)
- &&
- ti->tempdecl && ti->tempdecl->onemember)
- {
- TemplateDeclaration *tempdecl = ti->tempdecl;
- if (tempdecl->overroot) // if not start of overloaded list of TemplateDeclaration's
- tempdecl = tempdecl->overroot; // then get the start
- e = new TemplateExp(loc, tempdecl);
- e = e->semantic(sc);
- return e;
- }
- }
- e = new DsymbolExp(loc, s);
- }
- return e->semantic(sc);
+ if (ti &&
+ !ti->isTemplateMixin() &&
+ (ti->name == f->ident ||
+ ti->toAlias()->ident == f->ident)
+ &&
+ ti->tempdecl && ti->tempdecl->onemember)
+ {
+ TemplateDeclaration *tempdecl = ti->tempdecl;
+ if (tempdecl->overroot) // if not start of overloaded list of TemplateDeclaration's
+ tempdecl = tempdecl->overroot; // then get the start
+ e = new TemplateExp(loc, tempdecl);
+ e = e->semantic(sc);
+ return e;
+ }
+ }
+ e = new DsymbolExp(loc, s);
+ }
+ return e->semantic(sc);
}
#if DMDV2
if (ident == Id::ctfe)
@@ -2127,9 +2127,9 @@ Expression *IdentifierExp::semantic(Scope *sc)
s = sc->search_correct(ident);
if (s)
- error("undefined identifier %s, did you mean %s %s?", ident->toChars(), s->kind(), s->toChars());
+ error("undefined identifier %s, did you mean %s %s?", ident->toChars(), s->kind(), s->toChars());
else
- error("undefined identifier %s", ident->toChars());
+ error("undefined identifier %s", ident->toChars());
type = Type::terror;
return this;
}
@@ -2142,9 +2142,9 @@ char *IdentifierExp::toChars()
void IdentifierExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (hgs->hdrgen)
- buf->writestring(ident->toHChars2());
+ buf->writestring(ident->toHChars2());
else
- buf->writestring(ident->toChars());
+ buf->writestring(ident->toChars());
}
#if DMDV2
@@ -2159,9 +2159,9 @@ Expression *IdentifierExp::toLvalue(Scope *sc, Expression *e)
#if 0
tym = tybasic(e1->ET->Tty);
if (!(tyscalar(tym) ||
- tym == TYstruct ||
- tym == TYarray && e->Eoper == TOKaddr))
- synerr(EM_lvalue); // lvalue expected
+ tym == TYstruct ||
+ tym == TYarray && e->Eoper == TOKaddr))
+ synerr(EM_lvalue); // lvalue expected
#endif
return this;
}
@@ -2169,14 +2169,14 @@ Expression *IdentifierExp::toLvalue(Scope *sc, Expression *e)
/******************************** DollarExp **************************/
DollarExp::DollarExp(Loc loc)
- : IdentifierExp(loc, Id::dollar)
+ : IdentifierExp(loc, Id::dollar)
{
}
/******************************** DsymbolExp **************************/
DsymbolExp::DsymbolExp(Loc loc, Dsymbol *s)
- : Expression(loc, TOKdsymbol, sizeof(DsymbolExp))
+ : Expression(loc, TOKdsymbol, sizeof(DsymbolExp))
{
this->s = s;
}
@@ -2203,171 +2203,171 @@ Lagain:
//printf("DsymbolExp:: %p '%s' is a symbol\n", this, toChars());
//printf("s = '%s', s->kind = '%s'\n", s->toChars(), s->kind());
if (type)
- return this;
- if (!s->isFuncDeclaration()) // functions are checked after overloading
- checkDeprecated(sc, s);
+ return this;
+ if (!s->isFuncDeclaration()) // functions are checked after overloading
+ checkDeprecated(sc, s);
s = s->toAlias();
//printf("s = '%s', s->kind = '%s', s->needThis() = %p\n", s->toChars(), s->kind(), s->needThis());
if (!s->isFuncDeclaration())
- checkDeprecated(sc, s);
+ checkDeprecated(sc, s);
if (sc->func)
- thiscd = sc->func->parent->isClassDeclaration();
+ thiscd = sc->func->parent->isClassDeclaration();
// BUG: This should happen after overload resolution for functions, not before
if (s->needThis())
{
- if (hasThis(sc)
+ if (hasThis(sc)
#if DMDV2
- && !s->isFuncDeclaration()
+ && !s->isFuncDeclaration()
#endif
- )
- {
- // Supply an implicit 'this', as in
- // this.ident
+ )
+ {
+ // Supply an implicit 'this', as in
+ // this.ident
- DotVarExp *de;
+ DotVarExp *de;
- de = new DotVarExp(loc, new ThisExp(loc), s->isDeclaration());
- return de->semantic(sc);
- }
+ de = new DotVarExp(loc, new ThisExp(loc), s->isDeclaration());
+ return de->semantic(sc);
+ }
}
em = s->isEnumMember();
if (em)
{
- e = em->value->copy();
- e = e->semantic(sc);
- return e;
+ e = em->value->copy();
+ e = e->semantic(sc);
+ return e;
}
v = s->isVarDeclaration();
if (v)
{
- //printf("Identifier '%s' is a variable, type '%s'\n", toChars(), v->type->toChars());
- if (!type)
- { type = v->type;
- if (!v->type)
- { error("forward reference of %s", v->toChars());
- type = Type::terror;
- }
- }
- if (v->isSameAsInitializer() && type->toBasetype()->ty != Tsarray)
- {
- if (v->init)
- {
- if (v->inuse)
- {
- error("circular reference to '%s'", v->toChars());
- type = Type::tint32;
- return this;
- }
- ExpInitializer *ei = v->init->isExpInitializer();
- if (ei)
- {
- e = ei->exp->copy(); // make copy so we can change loc
- if (e->op == TOKstring || !e->type)
- e = e->semantic(sc);
- e = e->implicitCastTo(sc, type);
- e->loc = loc;
- return e;
- }
- }
- else
- {
- e = type->defaultInit();
- e->loc = loc;
- return e;
- }
- }
- e = new VarExp(loc, v);
- e->type = type;
- e = e->semantic(sc);
- return e->deref();
+ //printf("Identifier '%s' is a variable, type '%s'\n", toChars(), v->type->toChars());
+ if (!type)
+ { type = v->type;
+ if (!v->type)
+ { error("forward reference of %s", v->toChars());
+ type = Type::terror;
+ }
+ }
+ if (v->isSameAsInitializer() && type->toBasetype()->ty != Tsarray)
+ {
+ if (v->init)
+ {
+ if (v->inuse)
+ {
+ error("circular reference to '%s'", v->toChars());
+ type = Type::tint32;
+ return this;
+ }
+ ExpInitializer *ei = v->init->isExpInitializer();
+ if (ei)
+ {
+ e = ei->exp->copy(); // make copy so we can change loc
+ if (e->op == TOKstring || !e->type)
+ e = e->semantic(sc);
+ e = e->implicitCastTo(sc, type);
+ e->loc = loc;
+ return e;
+ }
+ }
+ else
+ {
+ e = type->defaultInit();
+ e->loc = loc;
+ return e;
+ }
+ }
+ e = new VarExp(loc, v);
+ e->type = type;
+ e = e->semantic(sc);
+ return e->deref();
}
fld = s->isFuncLiteralDeclaration();
if (fld)
- { //printf("'%s' is a function literal\n", fld->toChars());
- e = new FuncExp(loc, fld);
- return e->semantic(sc);
+ { //printf("'%s' is a function literal\n", fld->toChars());
+ e = new FuncExp(loc, fld);
+ return e->semantic(sc);
}
f = s->isFuncDeclaration();
if (f)
- { //printf("'%s' is a function\n", f->toChars());
- if (!f->type->deco)
- {
- error("forward reference to %s", toChars());
- return new ErrorExp();
- }
- return new VarExp(loc, f);
+ { //printf("'%s' is a function\n", f->toChars());
+ if (!f->type->deco)
+ {
+ error("forward reference to %s", toChars());
+ return new ErrorExp();
+ }
+ return new VarExp(loc, f);
}
cd = s->isClassDeclaration();
if (cd && thiscd && cd->isBaseOf(thiscd, NULL) && sc->func->needThis())
{
- // We need to add an implicit 'this' if cd is this class or a base class.
- DotTypeExp *dte;
+ // We need to add an implicit 'this' if cd is this class or a base class.
+ DotTypeExp *dte;
- dte = new DotTypeExp(loc, new ThisExp(loc), s);
- return dte->semantic(sc);
+ dte = new DotTypeExp(loc, new ThisExp(loc), s);
+ return dte->semantic(sc);
}
imp = s->isImport();
if (imp)
{
- if (!imp->pkg)
- { error("forward reference of import %s", imp->toChars());
- return this;
- }
- ScopeExp *ie = new ScopeExp(loc, imp->pkg);
- return ie->semantic(sc);
+ if (!imp->pkg)
+ { error("forward reference of import %s", imp->toChars());
+ return this;
+ }
+ ScopeExp *ie = new ScopeExp(loc, imp->pkg);
+ return ie->semantic(sc);
}
pkg = s->isPackage();
if (pkg)
{
- ScopeExp *ie;
+ ScopeExp *ie;
- ie = new ScopeExp(loc, pkg);
- return ie->semantic(sc);
+ ie = new ScopeExp(loc, pkg);
+ return ie->semantic(sc);
}
Module *mod = s->isModule();
if (mod)
{
- ScopeExp *ie;
+ ScopeExp *ie;
- ie = new ScopeExp(loc, mod);
- return ie->semantic(sc);
+ ie = new ScopeExp(loc, mod);
+ return ie->semantic(sc);
}
t = s->getType();
if (t)
{
- return new TypeExp(loc, t);
+ return new TypeExp(loc, t);
}
TupleDeclaration *tup = s->isTupleDeclaration();
if (tup)
{
- e = new TupleExp(loc, tup);
- e = e->semantic(sc);
- return e;
+ e = new TupleExp(loc, tup);
+ e = e->semantic(sc);
+ return e;
}
TemplateInstance *ti = s->isTemplateInstance();
if (ti && !global.errors)
{ if (!ti->semanticRun)
- ti->semantic(sc);
- s = ti->inst->toAlias();
- if (!s->isTemplateInstance())
- goto Lagain;
- e = new ScopeExp(loc, ti);
- e = e->semantic(sc);
- return e;
+ ti->semantic(sc);
+ s = ti->inst->toAlias();
+ if (!s->isTemplateInstance())
+ goto Lagain;
+ e = new ScopeExp(loc, ti);
+ e = e->semantic(sc);
+ return e;
}
TemplateDeclaration *td = s->isTemplateDeclaration();
if (td)
{
- e = new TemplateExp(loc, td);
- e = e->semantic(sc);
- return e;
+ e = new TemplateExp(loc, td);
+ e = e->semantic(sc);
+ return e;
}
Lerr:
@@ -2398,9 +2398,9 @@ Expression *DsymbolExp::toLvalue(Scope *sc, Expression *e)
#if 0
tym = tybasic(e1->ET->Tty);
if (!(tyscalar(tym) ||
- tym == TYstruct ||
- tym == TYarray && e->Eoper == TOKaddr))
- synerr(EM_lvalue); // lvalue expected
+ tym == TYstruct ||
+ tym == TYarray && e->Eoper == TOKaddr))
+ synerr(EM_lvalue); // lvalue expected
#endif
return this;
}
@@ -2408,7 +2408,7 @@ Expression *DsymbolExp::toLvalue(Scope *sc, Expression *e)
/******************************** ThisExp **************************/
ThisExp::ThisExp(Loc loc)
- : Expression(loc, TOKthis, sizeof(ThisExp))
+ : Expression(loc, TOKthis, sizeof(ThisExp))
{
var = NULL;
}
@@ -2422,8 +2422,8 @@ Expression *ThisExp::semantic(Scope *sc)
printf("ThisExp::semantic()\n");
#endif
if (type)
- { //assert(global.errors || var);
- return this;
+ { //assert(global.errors || var);
+ return this;
}
/* Special case for typeof(this) and typeof(super) since both
@@ -2431,36 +2431,36 @@ Expression *ThisExp::semantic(Scope *sc)
*/
if (sc->intypeof)
{
- // Find enclosing struct or class
- for (Dsymbol *s = sc->parent; 1; s = s->parent)
- {
- ClassDeclaration *cd;
- StructDeclaration *sd;
+ // Find enclosing struct or class
+ for (Dsymbol *s = sc->parent; 1; s = s->parent)
+ {
+ ClassDeclaration *cd;
+ StructDeclaration *sd;
- if (!s)
- {
- error("%s is not in a struct or class scope", toChars());
- goto Lerr;
- }
- cd = s->isClassDeclaration();
- if (cd)
- {
- type = cd->type;
- return this;
- }
- sd = s->isStructDeclaration();
- if (sd)
- {
- type = sd->type->pointerTo();
- return this;
- }
- }
+ if (!s)
+ {
+ error("%s is not in a struct or class scope", toChars());
+ goto Lerr;
+ }
+ cd = s->isClassDeclaration();
+ if (cd)
+ {
+ type = cd->type;
+ return this;
+ }
+ sd = s->isStructDeclaration();
+ if (sd)
+ {
+ type = sd->type->pointerTo();
+ return this;
+ }
+ }
}
fdthis = sc->parent->isFuncDeclaration();
- fd = hasThis(sc); // fd is the uplevel function with the 'this' variable
+ fd = hasThis(sc); // fd is the uplevel function with the 'this' variable
if (!fd)
- goto Lerr;
+ goto Lerr;
assert(fd->vthis);
var = fd->vthis;
@@ -2468,15 +2468,15 @@ Expression *ThisExp::semantic(Scope *sc)
type = var->type;
var->isVarDeclaration()->checkNestedReference(sc, loc);
#if 0
- if (fd != fdthis) // if nested
+ if (fd != fdthis) // if nested
{
- fdthis->getLevel(loc, fd);
- fd->vthis->nestedref = 1;
- fd->nestedFrameRef = 1;
+ fdthis->getLevel(loc, fd);
+ fd->vthis->nestedref = 1;
+ fd->nestedFrameRef = 1;
}
#endif
if (!sc->intypeof)
- sc->callSuper |= CSXthis;
+ sc->callSuper |= CSXthis;
return this;
Lerr:
@@ -2510,7 +2510,7 @@ Expression *ThisExp::toLvalue(Scope *sc, Expression *e)
/******************************** SuperExp **************************/
SuperExp::SuperExp(Loc loc)
- : ThisExp(loc)
+ : ThisExp(loc)
{
op = TOKsuper;
}
@@ -2525,75 +2525,75 @@ Expression *SuperExp::semantic(Scope *sc)
printf("SuperExp::semantic('%s')\n", toChars());
#endif
if (type)
- return this;
+ return this;
/* Special case for typeof(this) and typeof(super) since both
* should work even if they are not inside a non-static member function
*/
if (sc->intypeof)
{
- // Find enclosing class
- for (Dsymbol *s = sc->parent; 1; s = s->parent)
- {
- ClassDeclaration *cd;
+ // Find enclosing class
+ for (Dsymbol *s = sc->parent; 1; s = s->parent)
+ {
+ ClassDeclaration *cd;
- if (!s)
- {
- error("%s is not in a class scope", toChars());
- goto Lerr;
- }
- cd = s->isClassDeclaration();
- if (cd)
- {
- cd = cd->baseClass;
- if (!cd)
- { error("class %s has no 'super'", s->toChars());
- goto Lerr;
- }
- type = cd->type;
- return this;
- }
- }
+ if (!s)
+ {
+ error("%s is not in a class scope", toChars());
+ goto Lerr;
+ }
+ cd = s->isClassDeclaration();
+ if (cd)
+ {
+ cd = cd->baseClass;
+ if (!cd)
+ { error("class %s has no 'super'", s->toChars());
+ goto Lerr;
+ }
+ type = cd->type;
+ return this;
+ }
+ }
}
fdthis = sc->parent->isFuncDeclaration();
fd = hasThis(sc);
if (!fd)
- goto Lerr;
+ goto Lerr;
assert(fd->vthis);
var = fd->vthis;
assert(var->parent);
s = fd->toParent();
while (s && s->isTemplateInstance())
- s = s->toParent();
+ s = s->toParent();
assert(s);
cd = s->isClassDeclaration();
//printf("parent is %s %s\n", fd->toParent()->kind(), fd->toParent()->toChars());
if (!cd)
- goto Lerr;
+ goto Lerr;
if (!cd->baseClass)
{
- error("no base class for %s", cd->toChars());
- type = fd->vthis->type;
+ error("no base class for %s", cd->toChars());
+ type = fd->vthis->type;
}
else
{
- type = cd->baseClass->type;
+ type = cd->baseClass->type;
}
var->isVarDeclaration()->checkNestedReference(sc, loc);
#if 0
if (fd != fdthis)
{
- fdthis->getLevel(loc, fd);
- fd->vthis->nestedref = 1;
- fd->nestedFrameRef = 1;
+ fdthis->getLevel(loc, fd);
+ fd->vthis->nestedref = 1;
+ fd->nestedFrameRef = 1;
}
#endif
if (!sc->intypeof)
- sc->callSuper |= CSXsuper;
+ sc->callSuper |= CSXsuper;
return this;
@@ -2612,7 +2612,7 @@ void SuperExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/******************************** NullExp **************************/
NullExp::NullExp(Loc loc, Type *type)
- : Expression(loc, TOKnull, sizeof(NullExp))
+ : Expression(loc, TOKnull, sizeof(NullExp))
{
committed = 0;
this->type = type;
@@ -2625,7 +2625,7 @@ Expression *NullExp::semantic(Scope *sc)
#endif
// NULL is the same as (void *)0
if (!type)
- type = Type::tvoid->pointerTo();
+ type = Type::tvoid->pointerTo();
return this;
}
@@ -2647,7 +2647,7 @@ void NullExp::toMangleBuffer(OutBuffer *buf)
/******************************** StringExp **************************/
StringExp::StringExp(Loc loc, char *string)
- : Expression(loc, TOKstring, sizeof(StringExp))
+ : Expression(loc, TOKstring, sizeof(StringExp))
{
this->string = string;
this->len = strlen(string);
@@ -2657,7 +2657,7 @@ StringExp::StringExp(Loc loc, char *string)
}
StringExp::StringExp(Loc loc, void *string, size_t len)
- : Expression(loc, TOKstring, sizeof(StringExp))
+ : Expression(loc, TOKstring, sizeof(StringExp))
{
this->string = string;
this->len = len;
@@ -2667,7 +2667,7 @@ StringExp::StringExp(Loc loc, void *string, size_t len)
}
StringExp::StringExp(Loc loc, void *string, size_t len, unsigned char postfix)
- : Expression(loc, TOKstring, sizeof(StringExp))
+ : Expression(loc, TOKstring, sizeof(StringExp))
{
this->string = string;
this->len = len;
@@ -2688,12 +2688,12 @@ int StringExp::equals(Object *o)
{
//printf("StringExp::equals('%s')\n", o->toChars());
if (o && o->dyncast() == DYNCAST_EXPRESSION)
- { Expression *e = (Expression *)o;
+ { Expression *e = (Expression *)o;
- if (e->op == TOKstring)
- {
- return compare(o) == 0;
- }
+ if (e->op == TOKstring)
+ {
+ return compare(o) == 0;
+ }
}
return FALSE;
}
@@ -2718,65 +2718,65 @@ Expression *StringExp::semantic(Scope *sc)
printf("StringExp::semantic() %s\n", toChars());
#endif
if (!type)
- { OutBuffer buffer;
- size_t newlen = 0;
- const char *p;
- size_t u;
- unsigned c;
+ { OutBuffer buffer;
+ size_t newlen = 0;
+ const char *p;
+ size_t u;
+ unsigned c;
- switch (postfix)
- {
- case 'd':
- for (u = 0; u < len;)
- {
- p = utf_decodeChar((unsigned char *)string, len, &u, &c);
- if (p)
- { error("%s", p);
- break;
- }
- else
- { buffer.write4(c);
- newlen++;
- }
- }
- buffer.write4(0);
- string = buffer.extractData();
- len = newlen;
- sz = 4;
- type = new TypeSArray(Type::tdchar, new IntegerExp(loc, len, Type::tindex));
- committed = 1;
- break;
+ switch (postfix)
+ {
+ case 'd':
+ for (u = 0; u < len;)
+ {
+ p = utf_decodeChar((unsigned char *)string, len, &u, &c);
+ if (p)
+ { error("%s", p);
+ break;
+ }
+ else
+ { buffer.write4(c);
+ newlen++;
+ }
+ }
+ buffer.write4(0);
+ string = buffer.extractData();
+ len = newlen;
+ sz = 4;
+ type = new TypeSArray(Type::tdchar, new IntegerExp(loc, len, Type::tindex));
+ committed = 1;
+ break;
- case 'w':
- for (u = 0; u < len;)
- {
- p = utf_decodeChar((unsigned char *)string, len, &u, &c);
- if (p)
- { error("%s", p);
- break;
- }
- else
- { buffer.writeUTF16(c);
- newlen++;
- if (c >= 0x10000)
- newlen++;
- }
- }
- buffer.writeUTF16(0);
- string = buffer.extractData();
- len = newlen;
- sz = 2;
- type = new TypeSArray(Type::twchar, new IntegerExp(loc, len, Type::tindex));
- committed = 1;
- break;
+ case 'w':
+ for (u = 0; u < len;)
+ {
+ p = utf_decodeChar((unsigned char *)string, len, &u, &c);
+ if (p)
+ { error("%s", p);
+ break;
+ }
+ else
+ { buffer.writeUTF16(c);
+ newlen++;
+ if (c >= 0x10000)
+ newlen++;
+ }
+ }
+ buffer.writeUTF16(0);
+ string = buffer.extractData();
+ len = newlen;
+ sz = 2;
+ type = new TypeSArray(Type::twchar, new IntegerExp(loc, len, Type::tindex));
+ committed = 1;
+ break;
- case 'c':
- committed = 1;
- default:
- type = new TypeSArray(Type::tchar, new IntegerExp(loc, len, Type::tindex));
- break;
- }
- type = type->semantic(loc, sc);
+ case 'c':
+ committed = 1;
+ default:
+ type = new TypeSArray(Type::tchar, new IntegerExp(loc, len, Type::tindex));
+ break;
+ }
+ type = type->semantic(loc, sc);
}
return this;
}
@@ -2788,14 +2788,14 @@ Expression *StringExp::semantic(Scope *sc)
StringExp *StringExp::toUTF8(Scope *sc)
{
if (sz != 1)
- { // Convert to UTF-8 string
- committed = 0;
- Expression *e = castTo(sc, Type::tchar->arrayOf());
- e = e->optimize(WANTvalue);
- assert(e->op == TOKstring);
- StringExp *se = (StringExp *)e;
- assert(se->sz == 1);
- return se;
+ { // Convert to UTF-8 string
+ committed = 0;
+ Expression *e = castTo(sc, Type::tchar->arrayOf());
+ e = e->optimize(WANTvalue);
+ assert(e->op == TOKstring);
+ StringExp *se = (StringExp *)e;
+ assert(se->sz == 1);
+ return se;
}
return this;
}
@@ -2808,7 +2808,7 @@ int StringExp::compare(Object *obj)
// This is a kludge so isExpression() in template.c will return 5
// for StringExp's.
if (!se2)
- return 5;
+ return 5;
assert(se2->op == TOKstring);
@@ -2817,39 +2817,39 @@ int StringExp::compare(Object *obj)
if (len1 == len2)
{
- switch (sz)
- {
- case 1:
- return strcmp((char *)string, (char *)se2->string);
+ switch (sz)
+ {
+ case 1:
+ return strcmp((char *)string, (char *)se2->string);
- case 2:
- { unsigned u;
- d_wchar *s1 = (d_wchar *)string;
- d_wchar *s2 = (d_wchar *)se2->string;
+ case 2:
+ { unsigned u;
+ d_wchar *s1 = (d_wchar *)string;
+ d_wchar *s2 = (d_wchar *)se2->string;
- for (u = 0; u < len; u++)
- {
- if (s1[u] != s2[u])
- return s1[u] - s2[u];
- }
- }
+ for (u = 0; u < len; u++)
+ {
+ if (s1[u] != s2[u])
+ return s1[u] - s2[u];
+ }
+ }
- case 4:
- { unsigned u;
- d_dchar *s1 = (d_dchar *)string;
- d_dchar *s2 = (d_dchar *)se2->string;
+ case 4:
+ { unsigned u;
+ d_dchar *s1 = (d_dchar *)string;
+ d_dchar *s2 = (d_dchar *)se2->string;
- for (u = 0; u < len; u++)
- {
- if (s1[u] != s2[u])
- return s1[u] - s2[u];
- }
- }
- break;
+ for (u = 0; u < len; u++)
+ {
+ if (s1[u] != s2[u])
+ return s1[u] - s2[u];
+ }
+ }
+ break;
- default:
- assert(0);
- }
+ default:
+ assert(0);
+ }
}
return len1 - len2;
}
@@ -2864,21 +2864,21 @@ unsigned StringExp::charAt(size_t i)
switch (sz)
{
- case 1:
- value = ((unsigned char *)string)[i];
- break;
+ case 1:
+ value = ((unsigned char *)string)[i];
+ break;
- case 2:
- value = ((unsigned short *)string)[i];
- break;
+ case 2:
+ value = ((unsigned short *)string)[i];
+ break;
- case 4:
- value = ((unsigned int *)string)[i];
- break;
+ case 4:
+ value = ((unsigned int *)string)[i];
+ break;
- default:
- assert(0);
- break;
+ default:
+ assert(0);
+ break;
}
return value;
}
@@ -2887,32 +2887,32 @@ void StringExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writeByte('"');
for (size_t i = 0; i < len; i++)
- { unsigned c = charAt(i);
+ { unsigned c = charAt(i);
- switch (c)
- {
- case '"':
- case '\\':
- if (!hgs->console)
- buf->writeByte('\\');
- default:
- if (c <= 0xFF)
- { if (c <= 0x7F && (isprint(c) || hgs->console))
- buf->writeByte(c);
- else
- buf->printf("\\x%02x", c);
- }
- else if (c <= 0xFFFF)
- buf->printf("\\x%02x\\x%02x", c & 0xFF, c >> 8);
- else
- buf->printf("\\x%02x\\x%02x\\x%02x\\x%02x",
- c & 0xFF, (c >> 8) & 0xFF, (c >> 16) & 0xFF, c >> 24);
- break;
- }
+ switch (c)
+ {
+ case '"':
+ case '\\':
+ if (!hgs->console)
+ buf->writeByte('\\');
+ default:
+ if (c <= 0xFF)
+ { if (c <= 0x7F && (isprint(c) || hgs->console))
+ buf->writeByte(c);
+ else
+ buf->printf("\\x%02x", c);
+ }
+ else if (c <= 0xFFFF)
+ buf->printf("\\x%02x\\x%02x", c & 0xFF, c >> 8);
+ else
+ buf->printf("\\x%02x\\x%02x\\x%02x\\x%02x",
+ c & 0xFF, (c >> 8) & 0xFF, (c >> 16) & 0xFF, c >> 24);
+ break;
+ }
}
buf->writeByte('"');
if (postfix)
- buf->writeByte(postfix);
+ buf->writeByte(postfix);
}
void StringExp::toMangleBuffer(OutBuffer *buf)
@@ -2927,26 +2927,26 @@ void StringExp::toMangleBuffer(OutBuffer *buf)
/* Write string in UTF-8 format
*/
switch (sz)
- { case 1:
- m = 'a';
- q = (unsigned char *)string;
- qlen = len;
- break;
- case 2:
- m = 'w';
- for (u = 0; u < len; )
- {
+ { case 1:
+ m = 'a';
+ q = (unsigned char *)string;
+ qlen = len;
+ break;
+ case 2:
+ m = 'w';
+ for (u = 0; u < len; )
+ {
p = utf_decodeWchar((unsigned short *)string, len, &u, &c);
if (p)
error("%s", p);
else
tmp.writeUTF8(c);
- }
- q = tmp.data;
- qlen = tmp.offset;
- break;
- case 4:
- m = 'd';
+ }
+ q = tmp.data;
+ qlen = tmp.offset;
+ break;
+ case 4:
+ m = 'd';
for (u = 0; u < len; u++)
{
c = ((unsigned *)string)[u];
@@ -2955,16 +2955,16 @@ void StringExp::toMangleBuffer(OutBuffer *buf)
else
tmp.writeUTF8(c);
}
- q = tmp.data;
- qlen = tmp.offset;
- break;
- default:
- assert(0);
+ q = tmp.data;
+ qlen = tmp.offset;
+ break;
+ default:
+ assert(0);
}
buf->writeByte(m);
buf->printf("%d_", qlen);
for (size_t i = 0; i < qlen; i++)
- buf->printf("%02x", q[i]);
+ buf->printf("%02x", q[i]);
}
/************************ ArrayLiteralExp ************************************/
@@ -2997,46 +2997,46 @@ Expression *ArrayLiteralExp::semantic(Scope *sc)
printf("ArrayLiteralExp::semantic('%s')\n", toChars());
#endif
if (type)
- return this;
+ return this;
// Run semantic() on each element
for (int i = 0; i < elements->dim; i++)
- { e = (Expression *)elements->data[i];
- e = e->semantic(sc);
- elements->data[i] = (void *)e;
+ { e = (Expression *)elements->data[i];
+ e = e->semantic(sc);
+ elements->data[i] = (void *)e;
}
expandTuples(elements);
for (int i = 0; i < elements->dim; i++)
- { e = (Expression *)elements->data[i];
+ { e = (Expression *)elements->data[i];
- if (!e->type)
- error("%s has no value", e->toChars());
- e = resolveProperties(sc, e);
+ if (!e->type)
+ error("%s has no value", e->toChars());
+ e = resolveProperties(sc, e);
- unsigned char committed = 1;
- if (e->op == TOKstring)
- committed = ((StringExp *)e)->committed;
+ unsigned char committed = 1;
+ if (e->op == TOKstring)
+ committed = ((StringExp *)e)->committed;
- if (!t0)
- { t0 = e->type;
- // Convert any static arrays to dynamic arrays
- if (t0->ty == Tsarray)
- {
- t0 = ((TypeSArray *)t0)->next->arrayOf();
- e = e->implicitCastTo(sc, t0);
- }
- }
- else
- e = e->implicitCastTo(sc, t0);
- if (!committed && e->op == TOKstring)
- { StringExp *se = (StringExp *)e;
- se->committed = 0;
- }
- elements->data[i] = (void *)e;
+ if (!t0)
+ { t0 = e->type;
+ // Convert any static arrays to dynamic arrays
+ if (t0->ty == Tsarray)
+ {
+ t0 = ((TypeSArray *)t0)->next->arrayOf();
+ e = e->implicitCastTo(sc, t0);
+ }
+ }
+ else
+ e = e->implicitCastTo(sc, t0);
+ if (!committed && e->op == TOKstring)
+ { StringExp *se = (StringExp *)e;
+ se->committed = 0;
+ }
+ elements->data[i] = (void *)e;
}
if (!t0)
- t0 = Type::tvoid;
+ t0 = Type::tvoid;
type = new TypeSArray(t0, new IntegerExp(elements->dim));
type = type->semantic(loc, sc);
return this;
@@ -3046,12 +3046,12 @@ int ArrayLiteralExp::checkSideEffect(int flag)
{ int f = 0;
for (size_t i = 0; i < elements->dim; i++)
- { Expression *e = (Expression *)elements->data[i];
+ { Expression *e = (Expression *)elements->data[i];
- f |= e->checkSideEffect(2);
+ f |= e->checkSideEffect(2);
}
if (flag == 0 && f == 0)
- Expression::checkSideEffect(0);
+ Expression::checkSideEffect(0);
return f;
}
@@ -3064,7 +3064,7 @@ int ArrayLiteralExp::isBool(int result)
#if DMDV2
int ArrayLiteralExp::canThrow()
{
- return 1; // because it can fail allocating memory
+ return 1; // because it can fail allocating memory
}
#endif
@@ -3080,8 +3080,8 @@ void ArrayLiteralExp::toMangleBuffer(OutBuffer *buf)
size_t dim = elements ? elements->dim : 0;
buf->printf("A%zu", dim);
for (size_t i = 0; i < dim; i++)
- { Expression *e = (Expression *)elements->data[i];
- e->toMangleBuffer(buf);
+ { Expression *e = (Expression *)elements->data[i];
+ e->toMangleBuffer(buf);
}
}
@@ -3090,7 +3090,7 @@ void ArrayLiteralExp::toMangleBuffer(OutBuffer *buf)
// [ key0 : value0, key1 : value1, ... ]
AssocArrayLiteralExp::AssocArrayLiteralExp(Loc loc,
- Expressions *keys, Expressions *values)
+ Expressions *keys, Expressions *values)
: Expression(loc, TOKassocarrayliteral, sizeof(AssocArrayLiteralExp))
{
assert(keys->dim == values->dim);
@@ -3101,7 +3101,7 @@ AssocArrayLiteralExp::AssocArrayLiteralExp(Loc loc,
Expression *AssocArrayLiteralExp::syntaxCopy()
{
return new AssocArrayLiteralExp(loc,
- arraySyntaxCopy(keys), arraySyntaxCopy(values));
+ arraySyntaxCopy(keys), arraySyntaxCopy(values));
}
Expression *AssocArrayLiteralExp::semantic(Scope *sc)
@@ -3118,9 +3118,9 @@ Expression *AssocArrayLiteralExp::semantic(Scope *sc)
expandTuples(values);
if (keys->dim != values->dim)
{
- error("number of keys is %u, must match number of values %u", keys->dim, values->dim);
- keys->setDim(0);
- values->setDim(0);
+ error("number of keys is %u, must match number of values %u", keys->dim, values->dim);
+ keys->setDim(0);
+ values->setDim(0);
}
Type *tkey = NULL;
@@ -3137,14 +3137,14 @@ int AssocArrayLiteralExp::checkSideEffect(int flag)
{ int f = 0;
for (size_t i = 0; i < keys->dim; i++)
- { Expression *key = (Expression *)keys->data[i];
- Expression *value = (Expression *)values->data[i];
+ { Expression *key = (Expression *)keys->data[i];
+ Expression *value = (Expression *)values->data[i];
- f |= key->checkSideEffect(2);
- f |= value->checkSideEffect(2);
+ f |= key->checkSideEffect(2);
+ f |= value->checkSideEffect(2);
}
if (flag == 0 && f == 0)
- Expression::checkSideEffect(0);
+ Expression::checkSideEffect(0);
return f;
}
@@ -3165,14 +3165,14 @@ void AssocArrayLiteralExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writeByte('[');
for (size_t i = 0; i < keys->dim; i++)
- { Expression *key = (Expression *)keys->data[i];
- Expression *value = (Expression *)values->data[i];
+ { Expression *key = (Expression *)keys->data[i];
+ Expression *value = (Expression *)values->data[i];
- if (i)
- buf->writeByte(',');
- expToCBuffer(buf, hgs, key, PREC_assign);
- buf->writeByte(':');
- expToCBuffer(buf, hgs, value, PREC_assign);
+ if (i)
+ buf->writeByte(',');
+ expToCBuffer(buf, hgs, key, PREC_assign);
+ buf->writeByte(':');
+ expToCBuffer(buf, hgs, value, PREC_assign);
}
buf->writeByte(']');
}
@@ -3182,11 +3182,11 @@ void AssocArrayLiteralExp::toMangleBuffer(OutBuffer *buf)
size_t dim = keys->dim;
buf->printf("A%zu", dim);
for (size_t i = 0; i < dim; i++)
- { Expression *key = (Expression *)keys->data[i];
- Expression *value = (Expression *)values->data[i];
+ { Expression *key = (Expression *)keys->data[i];
+ Expression *value = (Expression *)values->data[i];
- key->toMangleBuffer(buf);
- value->toMangleBuffer(buf);
+ key->toMangleBuffer(buf);
+ value->toMangleBuffer(buf);
}
}
@@ -3218,82 +3218,82 @@ Expression *StructLiteralExp::semantic(Scope *sc)
printf("StructLiteralExp::semantic('%s')\n", toChars());
#endif
if (type)
- return this;
+ return this;
// Run semantic() on each element
for (size_t i = 0; i < elements->dim; i++)
- { e = (Expression *)elements->data[i];
- if (!e)
- continue;
- e = e->semantic(sc);
- elements->data[i] = (void *)e;
+ { e = (Expression *)elements->data[i];
+ if (!e)
+ continue;
+ e = e->semantic(sc);
+ elements->data[i] = (void *)e;
}
expandTuples(elements);
size_t offset = 0;
for (size_t i = 0; i < elements->dim; i++)
- { e = (Expression *)elements->data[i];
- if (!e)
- continue;
+ { e = (Expression *)elements->data[i];
+ if (!e)
+ continue;
- if (!e->type)
- error("%s has no value", e->toChars());
- e = resolveProperties(sc, e);
- if (i >= sd->fields.dim)
- { error("more initializers than fields of %s", sd->toChars());
- break;
- }
- Dsymbol *s = (Dsymbol *)sd->fields.data[i];
- VarDeclaration *v = s->isVarDeclaration();
- assert(v);
- if (v->offset < offset)
- error("overlapping initialization for %s", v->toChars());
- offset = v->offset + v->type->size();
+ if (!e->type)
+ error("%s has no value", e->toChars());
+ e = resolveProperties(sc, e);
+ if (i >= sd->fields.dim)
+ { error("more initializers than fields of %s", sd->toChars());
+ break;
+ }
+ Dsymbol *s = (Dsymbol *)sd->fields.data[i];
+ VarDeclaration *v = s->isVarDeclaration();
+ assert(v);
+ if (v->offset < offset)
+ error("overlapping initialization for %s", v->toChars());
+ offset = v->offset + v->type->size();
- Type *telem = v->type;
- while (!e->implicitConvTo(telem) && telem->toBasetype()->ty == Tsarray)
- { /* Static array initialization, as in:
- * T[3][5] = e;
- */
- telem = telem->toBasetype()->nextOf();
- }
+ Type *telem = v->type;
+ while (!e->implicitConvTo(telem) && telem->toBasetype()->ty == Tsarray)
+ { /* Static array initialization, as in:
+ * T[3][5] = e;
+ */
+ telem = telem->toBasetype()->nextOf();
+ }
- e = e->implicitCastTo(sc, telem);
+ e = e->implicitCastTo(sc, telem);
- elements->data[i] = (void *)e;
+ elements->data[i] = (void *)e;
}
/* Fill out remainder of elements[] with default initializers for fields[]
*/
for (size_t i = elements->dim; i < sd->fields.dim; i++)
- { Dsymbol *s = (Dsymbol *)sd->fields.data[i];
- VarDeclaration *v = s->isVarDeclaration();
- assert(v);
+ { Dsymbol *s = (Dsymbol *)sd->fields.data[i];
+ VarDeclaration *v = s->isVarDeclaration();
+ assert(v);
- if (v->offset < offset)
- { e = NULL;
- sd->hasUnions = 1;
- }
- else
- {
- if (v->init)
- { e = v->init->toExpression();
- if (!e)
- { error("cannot make expression out of initializer for %s", v->toChars());
- e = new ErrorExp();
- }
- else if (v->scope)
- { // Do deferred semantic anaylsis
- Initializer *i2 = v->init->syntaxCopy();
- i2 = i2->semantic(v->scope, v->type);
- e = i2->toExpression();
- v->scope = NULL;
- }
- }
- else
- e = v->type->defaultInitLiteral(loc);
- offset = v->offset + v->type->size();
- }
- elements->push(e);
+ if (v->offset < offset)
+ { e = NULL;
+ sd->hasUnions = 1;
+ }
+ else
+ {
+ if (v->init)
+ { e = v->init->toExpression();
+ if (!e)
+ { error("cannot make expression out of initializer for %s", v->toChars());
+ e = new ErrorExp();
+ }
+ else if (v->scope)
+ { // Do deferred semantic anaylsis
+ Initializer *i2 = v->init->syntaxCopy();
+ i2 = i2->semantic(v->scope, v->type);
+ e = i2->toExpression();
+ v->scope = NULL;
+ }
+ }
+ else
+ e = v->type->defaultInitLiteral(loc);
+ offset = v->offset + v->type->size();
+ }
+ elements->push(e);
}
type = sd->type;
@@ -3308,45 +3308,45 @@ Expression *StructLiteralExp::semantic(Scope *sc)
Expression *StructLiteralExp::getField(Type *type, unsigned offset)
{
//printf("StructLiteralExp::getField(this = %s, type = %s, offset = %u)\n",
-// /*toChars()*/"", type->toChars(), offset);
+// /*toChars()*/"", type->toChars(), offset);
Expression *e = NULL;
int i = getFieldIndex(type, offset);
if (i != -1)
{
- //printf("\ti = %d\n", i);
- assert(i < elements->dim);
- e = (Expression *)elements->data[i];
- if (e)
- {
- //printf("e = %s, e->type = %s\n", e->toChars(), e->type->toChars());
+ //printf("\ti = %d\n", i);
+ assert(i < elements->dim);
+ e = (Expression *)elements->data[i];
+ if (e)
+ {
+ //printf("e = %s, e->type = %s\n", e->toChars(), e->type->toChars());
- /* If type is a static array, and e is an initializer for that array,
- * then the field initializer should be an array literal of e.
- */
- if (e->type != type && type->ty == Tsarray)
- { TypeSArray *tsa = (TypeSArray *)type;
- uinteger_t length = tsa->dim->toInteger();
- Expressions *z = new Expressions;
- z->setDim(length);
- for (int q = 0; q < length; ++q)
- z->data[q] = e->copy();
- e = new ArrayLiteralExp(loc, z);
- e->type = type;
- }
- else
- {
- e = e->copy();
- e->type = type;
- }
- }
+ /* If type is a static array, and e is an initializer for that array,
+ * then the field initializer should be an array literal of e.
+ */
+ if (e->type != type && type->ty == Tsarray)
+ { TypeSArray *tsa = (TypeSArray *)type;
+ uinteger_t length = tsa->dim->toInteger();
+ Expressions *z = new Expressions;
+ z->setDim(length);
+ for (int q = 0; q < length; ++q)
+ z->data[q] = e->copy();
+ e = new ArrayLiteralExp(loc, z);
+ e->type = type;
+ }
+ else
+ {
+ e = e->copy();
+ e->type = type;
+ }
+ }
}
return e;
}
/************************************
* Get index of field.
- * Returns -1 if not found.
+ * Returns -1 if not found.
*/
int StructLiteralExp::getFieldIndex(Type *type, unsigned offset)
@@ -3355,22 +3355,22 @@ int StructLiteralExp::getFieldIndex(Type *type, unsigned offset)
*/
if (elements->dim)
{
- for (size_t i = 0; i < sd->fields.dim; i++)
- {
- Dsymbol *s = (Dsymbol *)sd->fields.data[i];
- VarDeclaration *v = s->isVarDeclaration();
- assert(v);
+ for (size_t i = 0; i < sd->fields.dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)sd->fields.data[i];
+ VarDeclaration *v = s->isVarDeclaration();
+ assert(v);
- if (offset == v->offset &&
- type->size() == v->type->size())
- { Expression *e = (Expression *)elements->data[i];
- if (e)
- {
- return i;
- }
- break;
- }
- }
+ if (offset == v->offset &&
+ type->size() == v->type->size())
+ { Expression *e = (Expression *)elements->data[i];
+ if (e)
+ {
+ return i;
+ }
+ break;
+ }
+ }
}
return -1;
}
@@ -3392,14 +3392,14 @@ int StructLiteralExp::checkSideEffect(int flag)
{ int f = 0;
for (size_t i = 0; i < elements->dim; i++)
- { Expression *e = (Expression *)elements->data[i];
- if (!e)
- continue;
+ { Expression *e = (Expression *)elements->data[i];
+ if (!e)
+ continue;
- f |= e->checkSideEffect(2);
+ f |= e->checkSideEffect(2);
}
if (flag == 0 && f == 0)
- Expression::checkSideEffect(0);
+ Expression::checkSideEffect(0);
return f;
}
@@ -3423,21 +3423,21 @@ void StructLiteralExp::toMangleBuffer(OutBuffer *buf)
size_t dim = elements ? elements->dim : 0;
buf->printf("S%zu", dim);
for (size_t i = 0; i < dim; i++)
- { Expression *e = (Expression *)elements->data[i];
- if (e)
- e->toMangleBuffer(buf);
- else
- buf->writeByte('v'); // 'v' for void
+ { Expression *e = (Expression *)elements->data[i];
+ if (e)
+ e->toMangleBuffer(buf);
+ else
+ buf->writeByte('v'); // 'v' for void
}
}
/************************ TypeDotIdExp ************************************/
/* Things like:
- * int.size
- * foo.size
- * (foo).size
- * cast(foo).size
+ * int.size
+ * foo.size
+ * (foo).size
+ * cast(foo).size
*/
Expression *typeDotIdExp(Loc loc, Type *type, Identifier *ident)
@@ -3504,39 +3504,39 @@ Expression *ScopeExp::semantic(Scope *sc)
Lagain:
ti = sds->isTemplateInstance();
if (ti && !global.errors)
- { Dsymbol *s;
- if (!ti->semanticRun)
- ti->semantic(sc);
- s = ti->inst->toAlias();
- sds2 = s->isScopeDsymbol();
- if (!sds2)
- { Expression *e;
+ { Dsymbol *s;
+ if (!ti->semanticRun)
+ ti->semantic(sc);
+ s = ti->inst->toAlias();
+ sds2 = s->isScopeDsymbol();
+ if (!sds2)
+ { Expression *e;
- //printf("s = %s, '%s'\n", s->kind(), s->toChars());
- if (ti->withsym)
- {
- // Same as wthis.s
- e = new VarExp(loc, ti->withsym->withstate->wthis);
- e = new DotVarExp(loc, e, s->isDeclaration());
- }
- else
- e = new DsymbolExp(loc, s);
- e = e->semantic(sc);
- //printf("-1ScopeExp::semantic()\n");
- return e;
- }
- if (sds2 != sds)
- {
- sds = sds2;
- goto Lagain;
- }
- //printf("sds = %s, '%s'\n", sds->kind(), sds->toChars());
+ //printf("s = %s, '%s'\n", s->kind(), s->toChars());
+ if (ti->withsym)
+ {
+ // Same as wthis.s
+ e = new VarExp(loc, ti->withsym->withstate->wthis);
+ e = new DotVarExp(loc, e, s->isDeclaration());
+ }
+ else
+ e = new DsymbolExp(loc, s);
+ e = e->semantic(sc);
+ //printf("-1ScopeExp::semantic()\n");
+ return e;
+ }
+ if (sds2 != sds)
+ {
+ sds = sds2;
+ goto Lagain;
+ }
+ //printf("sds = %s, '%s'\n", sds->kind(), sds->toChars());
}
else
{
- //printf("sds = %s, '%s'\n", sds->kind(), sds->toChars());
- //printf("\tparent = '%s'\n", sds->parent->toChars());
- sds->semantic(sc);
+ //printf("sds = %s, '%s'\n", sds->kind(), sds->toChars());
+ //printf("\tparent = '%s'\n", sds->parent->toChars());
+ sds->semantic(sc);
}
type = Type::tvoid;
//printf("-2ScopeExp::semantic() %s\n", toChars());
@@ -3551,9 +3551,9 @@ void ScopeExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
}
else
{
- buf->writestring(sds->kind());
- buf->writestring(" ");
- buf->writestring(sds->toChars());
+ buf->writestring(sds->kind());
+ buf->writestring(" ");
+ buf->writestring(sds->toChars());
}
}
@@ -3583,7 +3583,7 @@ void TemplateExp::rvalue()
/* thisexp.new(newargs) newtype(arguments) */
NewExp::NewExp(Loc loc, Expression *thisexp, Expressions *newargs,
- Type *newtype, Expressions *arguments)
+ Type *newtype, Expressions *arguments)
: Expression(loc, TOKnew, sizeof(NewExp))
{
this->thisexp = thisexp;
@@ -3598,9 +3598,9 @@ NewExp::NewExp(Loc loc, Expression *thisexp, Expressions *newargs,
Expression *NewExp::syntaxCopy()
{
return new NewExp(loc,
- thisexp ? thisexp->syntaxCopy() : NULL,
- arraySyntaxCopy(newargs),
- newtype->syntaxCopy(), arraySyntaxCopy(arguments));
+ thisexp ? thisexp->syntaxCopy() : NULL,
+ arraySyntaxCopy(newargs),
+ newtype->syntaxCopy(), arraySyntaxCopy(arguments));
}
@@ -3612,31 +3612,31 @@ Expression *NewExp::semantic(Scope *sc)
#if LOGSEMANTIC
printf("NewExp::semantic() %s\n", toChars());
if (thisexp)
- printf("\tthisexp = %s\n", thisexp->toChars());
+ printf("\tthisexp = %s\n", thisexp->toChars());
printf("\tnewtype: %s\n", newtype->toChars());
#endif
- if (type) // if semantic() already run
- return this;
+ if (type) // if semantic() already run
+ return this;
Lagain:
if (thisexp)
- { thisexp = thisexp->semantic(sc);
- cdthis = thisexp->type->isClassHandle();
- if (cdthis)
- {
- sc = sc->push(cdthis);
- type = newtype->semantic(loc, sc);
- sc = sc->pop();
- }
- else
- {
- error("'this' for nested class must be a class type, not %s", thisexp->type->toChars());
- type = newtype->semantic(loc, sc);
- }
+ { thisexp = thisexp->semantic(sc);
+ cdthis = thisexp->type->isClassHandle();
+ if (cdthis)
+ {
+ sc = sc->push(cdthis);
+ type = newtype->semantic(loc, sc);
+ sc = sc->pop();
+ }
+ else
+ {
+ error("'this' for nested class must be a class type, not %s", thisexp->type->toChars());
+ type = newtype->semantic(loc, sc);
+ }
}
else
- type = newtype->semantic(loc, sc);
- newtype = type; // in case type gets cast to something else
+ type = newtype->semantic(loc, sc);
+ newtype = type; // in case type gets cast to something else
tb = type->toBasetype();
//printf("tb: %s, deco = %s\n", tb->toChars(), tb->deco);
@@ -3646,212 +3646,212 @@ Lagain:
preFunctionParameters(loc, sc, arguments);
if (thisexp && tb->ty != Tclass)
- error("e.new is only for allocating nested classes, not %s", tb->toChars());
+ error("e.new is only for allocating nested classes, not %s", tb->toChars());
if (tb->ty == Tclass)
- { TypeFunction *tf;
+ { TypeFunction *tf;
- TypeClass *tc = (TypeClass *)(tb);
- ClassDeclaration *cd = tc->sym->isClassDeclaration();
- if (cd->isInterfaceDeclaration())
- error("cannot create instance of interface %s", cd->toChars());
- else if (cd->isAbstract())
- { error("cannot create instance of abstract class %s", cd->toChars());
- for (int i = 0; i < cd->vtbl.dim; i++)
- { FuncDeclaration *fd = ((Dsymbol *)cd->vtbl.data[i])->isFuncDeclaration();
- if (fd && fd->isAbstract())
- error("function %s is abstract", fd->toChars());
- }
- }
- checkDeprecated(sc, cd);
- if (cd->isNested())
- { /* We need a 'this' pointer for the nested class.
- * Ensure we have the right one.
- */
- Dsymbol *s = cd->toParent2();
- ClassDeclaration *cdn = s->isClassDeclaration();
- FuncDeclaration *fdn = s->isFuncDeclaration();
+ TypeClass *tc = (TypeClass *)(tb);
+ ClassDeclaration *cd = tc->sym->isClassDeclaration();
+ if (cd->isInterfaceDeclaration())
+ error("cannot create instance of interface %s", cd->toChars());
+ else if (cd->isAbstract())
+ { error("cannot create instance of abstract class %s", cd->toChars());
+ for (int i = 0; i < cd->vtbl.dim; i++)
+ { FuncDeclaration *fd = ((Dsymbol *)cd->vtbl.data[i])->isFuncDeclaration();
+ if (fd && fd->isAbstract())
+ error("function %s is abstract", fd->toChars());
+ }
+ }
+ checkDeprecated(sc, cd);
+ if (cd->isNested())
+ { /* We need a 'this' pointer for the nested class.
+ * Ensure we have the right one.
+ */
+ Dsymbol *s = cd->toParent2();
+ ClassDeclaration *cdn = s->isClassDeclaration();
+ FuncDeclaration *fdn = s->isFuncDeclaration();
- //printf("cd isNested, cdn = %s\n", cdn ? cdn->toChars() : "null");
- if (cdn)
- {
- if (!cdthis)
- {
- // Supply an implicit 'this' and try again
- thisexp = new ThisExp(loc);
- for (Dsymbol *sp = sc->parent; 1; sp = sp->parent)
- { if (!sp)
- {
- error("outer class %s 'this' needed to 'new' nested class %s", cdn->toChars(), cd->toChars());
- break;
- }
- ClassDeclaration *cdp = sp->isClassDeclaration();
- if (!cdp)
- continue;
- if (cdp == cdn || cdn->isBaseOf(cdp, NULL))
- break;
- // Add a '.outer' and try again
- thisexp = new DotIdExp(loc, thisexp, Id::outer);
- }
- if (!global.errors)
- goto Lagain;
- }
- if (cdthis)
- {
- //printf("cdthis = %s\n", cdthis->toChars());
- if (cdthis != cdn && !cdn->isBaseOf(cdthis, NULL))
- error("'this' for nested class must be of type %s, not %s", cdn->toChars(), thisexp->type->toChars());
- }
+ //printf("cd isNested, cdn = %s\n", cdn ? cdn->toChars() : "null");
+ if (cdn)
+ {
+ if (!cdthis)
+ {
+ // Supply an implicit 'this' and try again
+ thisexp = new ThisExp(loc);
+ for (Dsymbol *sp = sc->parent; 1; sp = sp->parent)
+ { if (!sp)
+ {
+ error("outer class %s 'this' needed to 'new' nested class %s", cdn->toChars(), cd->toChars());
+ break;
+ }
+ ClassDeclaration *cdp = sp->isClassDeclaration();
+ if (!cdp)
+ continue;
+ if (cdp == cdn || cdn->isBaseOf(cdp, NULL))
+ break;
+ // Add a '.outer' and try again
+ thisexp = new DotIdExp(loc, thisexp, Id::outer);
+ }
+ if (!global.errors)
+ goto Lagain;
+ }
+ if (cdthis)
+ {
+ //printf("cdthis = %s\n", cdthis->toChars());
+ if (cdthis != cdn && !cdn->isBaseOf(cdthis, NULL))
+ error("'this' for nested class must be of type %s, not %s", cdn->toChars(), thisexp->type->toChars());
+ }
#if 0
- else
- {
- for (Dsymbol *sf = sc->func; 1; sf= sf->toParent2()->isFuncDeclaration())
- {
- if (!sf)
- {
- error("outer class %s 'this' needed to 'new' nested class %s", cdn->toChars(), cd->toChars());
- break;
- }
- printf("sf = %s\n", sf->toChars());
- AggregateDeclaration *ad = sf->isThis();
- if (ad && (ad == cdn || cdn->isBaseOf(ad->isClassDeclaration(), NULL)))
- break;
- }
- }
+ else
+ {
+ for (Dsymbol *sf = sc->func; 1; sf= sf->toParent2()->isFuncDeclaration())
+ {
+ if (!sf)
+ {
+ error("outer class %s 'this' needed to 'new' nested class %s", cdn->toChars(), cd->toChars());
+ break;
+ }
+ printf("sf = %s\n", sf->toChars());
+ AggregateDeclaration *ad = sf->isThis();
+ if (ad && (ad == cdn || cdn->isBaseOf(ad->isClassDeclaration(), NULL)))
+ break;
+ }
+ }
#endif
- }
- else if (thisexp)
- error("e.new is only for allocating nested classes");
- else if (fdn)
- {
- // make sure the parent context fdn of cd is reachable from sc
- for (Dsymbol *sp = sc->parent; 1; sp = sp->parent)
- {
- if (fdn == sp)
- break;
- FuncDeclaration *fsp = sp ? sp->isFuncDeclaration() : NULL;
- if (!sp || (fsp && fsp->isStatic()))
- {
- error("outer function context of %s is needed to 'new' nested class %s", fdn->toPrettyChars(), cd->toPrettyChars());
- break;
- }
- }
- }
- }
- else if (thisexp)
- error("e.new is only for allocating nested classes");
+ }
+ else if (thisexp)
+ error("e.new is only for allocating nested classes");
+ else if (fdn)
+ {
+ // make sure the parent context fdn of cd is reachable from sc
+ for (Dsymbol *sp = sc->parent; 1; sp = sp->parent)
+ {
+ if (fdn == sp)
+ break;
+ FuncDeclaration *fsp = sp ? sp->isFuncDeclaration() : NULL;
+ if (!sp || (fsp && fsp->isStatic()))
+ {
+ error("outer function context of %s is needed to 'new' nested class %s", fdn->toPrettyChars(), cd->toPrettyChars());
+ break;
+ }
+ }
+ }
+ }
+ else if (thisexp)
+ error("e.new is only for allocating nested classes");
- FuncDeclaration *f = cd->ctor;
- if (f)
- {
- assert(f);
- f = f->overloadResolve(loc, NULL, arguments, sc->module);
- checkDeprecated(sc, f);
- member = f->isCtorDeclaration();
- assert(member);
+ FuncDeclaration *f = cd->ctor;
+ if (f)
+ {
+ assert(f);
+ f = f->overloadResolve(loc, NULL, arguments, sc->module);
+ checkDeprecated(sc, f);
+ member = f->isCtorDeclaration();
+ assert(member);
- cd->accessCheck(loc, sc, member);
+ cd->accessCheck(loc, sc, member);
- tf = (TypeFunction *)f->type;
- type = tf->next;
+ tf = (TypeFunction *)f->type;
+ type = tf->next;
- if (!arguments)
- arguments = new Expressions();
- functionParameters(loc, sc, tf, arguments);
- }
- else
- {
- if (arguments && arguments->dim)
- error("no constructor for %s", cd->toChars());
- }
+ if (!arguments)
+ arguments = new Expressions();
+ functionParameters(loc, sc, tf, arguments);
+ }
+ else
+ {
+ if (arguments && arguments->dim)
+ error("no constructor for %s", cd->toChars());
+ }
- if (cd->aggNew)
- {
- // Prepend the size argument to newargs[]
- Expression *e = new IntegerExp(loc, cd->size(loc), Type::tsize_t);
- if (!newargs)
- newargs = new Expressions();
- newargs->shift(e);
+ if (cd->aggNew)
+ {
+ // Prepend the size argument to newargs[]
+ Expression *e = new IntegerExp(loc, cd->size(loc), Type::tsize_t);
+ if (!newargs)
+ newargs = new Expressions();
+ newargs->shift(e);
- f = cd->aggNew->overloadResolve(loc, NULL, newargs, sc->module);
- allocator = f->isNewDeclaration();
- assert(allocator);
+ f = cd->aggNew->overloadResolve(loc, NULL, newargs, sc->module);
+ allocator = f->isNewDeclaration();
+ assert(allocator);
- tf = (TypeFunction *)f->type;
- functionParameters(loc, sc, tf, newargs);
- }
- else
- {
- if (newargs && newargs->dim)
- error("no allocator for %s", cd->toChars());
- }
+ tf = (TypeFunction *)f->type;
+ functionParameters(loc, sc, tf, newargs);
+ }
+ else
+ {
+ if (newargs && newargs->dim)
+ error("no allocator for %s", cd->toChars());
+ }
}
else if (tb->ty == Tstruct)
{
- TypeStruct *ts = (TypeStruct *)tb;
- StructDeclaration *sd = ts->sym;
- FuncDeclaration *f = sd->aggNew;
- TypeFunction *tf;
+ TypeStruct *ts = (TypeStruct *)tb;
+ StructDeclaration *sd = ts->sym;
+ FuncDeclaration *f = sd->aggNew;
+ TypeFunction *tf;
- if (arguments && arguments->dim)
- error("no constructor for %s", type->toChars());
+ if (arguments && arguments->dim)
+ error("no constructor for %s", type->toChars());
- if (f)
- {
- Expression *e;
+ if (f)
+ {
+ Expression *e;
- // Prepend the uint size argument to newargs[]
- e = new IntegerExp(loc, sd->size(loc), Type::tuns32);
- if (!newargs)
- newargs = new Expressions();
- newargs->shift(e);
+ // Prepend the uint size argument to newargs[]
+ e = new IntegerExp(loc, sd->size(loc), Type::tuns32);
+ if (!newargs)
+ newargs = new Expressions();
+ newargs->shift(e);
- f = f->overloadResolve(loc, NULL, newargs, sc->module);
- allocator = f->isNewDeclaration();
- assert(allocator);
+ f = f->overloadResolve(loc, NULL, newargs, sc->module);
+ allocator = f->isNewDeclaration();
+ assert(allocator);
- tf = (TypeFunction *)f->type;
- functionParameters(loc, sc, tf, newargs);
+ tf = (TypeFunction *)f->type;
+ functionParameters(loc, sc, tf, newargs);
- e = new VarExp(loc, f);
- e = new CallExp(loc, e, newargs);
- e = e->semantic(sc);
- e->type = type->pointerTo();
- return e;
- }
+ e = new VarExp(loc, f);
+ e = new CallExp(loc, e, newargs);
+ e = e->semantic(sc);
+ e->type = type->pointerTo();
+ return e;
+ }
- type = type->pointerTo();
+ type = type->pointerTo();
}
else if (tb->ty == Tarray && (arguments && arguments->dim))
{
- for (size_t i = 0; i < arguments->dim; i++)
- {
- if (tb->ty != Tarray)
- { error("too many arguments for array");
- arguments->dim = i;
- break;
- }
+ for (size_t i = 0; i < arguments->dim; i++)
+ {
+ if (tb->ty != Tarray)
+ { error("too many arguments for array");
+ arguments->dim = i;
+ break;
+ }
- Expression *arg = (Expression *)arguments->data[i];
- arg = resolveProperties(sc, arg);
- arg = arg->implicitCastTo(sc, Type::tsize_t);
- if (arg->op == TOKint64 && (long long)arg->toInteger() < 0)
- error("negative array index %s", arg->toChars());
- arguments->data[i] = (void *) arg;
- tb = ((TypeDArray *)tb)->next->toBasetype();
- }
+ Expression *arg = (Expression *)arguments->data[i];
+ arg = resolveProperties(sc, arg);
+ arg = arg->implicitCastTo(sc, Type::tsize_t);
+ if (arg->op == TOKint64 && (long long)arg->toInteger() < 0)
+ error("negative array index %s", arg->toChars());
+ arguments->data[i] = (void *) arg;
+ tb = ((TypeDArray *)tb)->next->toBasetype();
+ }
}
else if (tb->isscalar())
{
- if (arguments && arguments->dim)
- error("no constructor for %s", type->toChars());
+ if (arguments && arguments->dim)
+ error("no constructor for %s", type->toChars());
- type = type->pointerTo();
+ type = type->pointerTo();
}
else
{
- error("new can only create structs, dynamic arrays or class objects, not %s's", type->toChars());
- type = type->pointerTo();
+ error("new can only create structs, dynamic arrays or class objects, not %s's", type->toChars());
+ type = type->pointerTo();
}
//printf("NewExp: '%s'\n", toChars());
@@ -3876,29 +3876,29 @@ void NewExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{ int i;
if (thisexp)
- { expToCBuffer(buf, hgs, thisexp, PREC_primary);
- buf->writeByte('.');
+ { expToCBuffer(buf, hgs, thisexp, PREC_primary);
+ buf->writeByte('.');
}
buf->writestring("new ");
if (newargs && newargs->dim)
{
- buf->writeByte('(');
- argsToCBuffer(buf, newargs, hgs);
- buf->writeByte(')');
+ buf->writeByte('(');
+ argsToCBuffer(buf, newargs, hgs);
+ buf->writeByte(')');
}
newtype->toCBuffer(buf, NULL, hgs);
if (arguments && arguments->dim)
{
- buf->writeByte('(');
- argsToCBuffer(buf, arguments, hgs);
- buf->writeByte(')');
+ buf->writeByte('(');
+ argsToCBuffer(buf, arguments, hgs);
+ buf->writeByte(')');
}
}
/********************** NewAnonClassExp **************************************/
NewAnonClassExp::NewAnonClassExp(Loc loc, Expression *thisexp,
- Expressions *newargs, ClassDeclaration *cd, Expressions *arguments)
+ Expressions *newargs, ClassDeclaration *cd, Expressions *arguments)
: Expression(loc, TOKnewanonclass, sizeof(NewAnonClassExp))
{
this->thisexp = thisexp;
@@ -3910,10 +3910,10 @@ NewAnonClassExp::NewAnonClassExp(Loc loc, Expression *thisexp,
Expression *NewAnonClassExp::syntaxCopy()
{
return new NewAnonClassExp(loc,
- thisexp ? thisexp->syntaxCopy() : NULL,
- arraySyntaxCopy(newargs),
- (ClassDeclaration *)cd->syntaxCopy(NULL),
- arraySyntaxCopy(arguments));
+ thisexp ? thisexp->syntaxCopy() : NULL,
+ arraySyntaxCopy(newargs),
+ (ClassDeclaration *)cd->syntaxCopy(NULL),
+ arraySyntaxCopy(arguments));
}
@@ -3950,22 +3950,22 @@ void NewAnonClassExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{ int i;
if (thisexp)
- { expToCBuffer(buf, hgs, thisexp, PREC_primary);
- buf->writeByte('.');
+ { expToCBuffer(buf, hgs, thisexp, PREC_primary);
+ buf->writeByte('.');
}
buf->writestring("new");
if (newargs && newargs->dim)
{
- buf->writeByte('(');
- argsToCBuffer(buf, newargs, hgs);
- buf->writeByte(')');
+ buf->writeByte('(');
+ argsToCBuffer(buf, newargs, hgs);
+ buf->writeByte(')');
}
buf->writestring(" class ");
if (arguments && arguments->dim)
{
- buf->writeByte('(');
- argsToCBuffer(buf, arguments, hgs);
- buf->writeByte(')');
+ buf->writeByte('(');
+ argsToCBuffer(buf, arguments, hgs);
+ buf->writeByte(')');
}
//buf->writestring(" { }");
if (cd)
@@ -3997,7 +3997,7 @@ SymOffExp::SymOffExp(Loc loc, Declaration *var, unsigned offset)
m = NULL;
VarDeclaration *v = var->isVarDeclaration();
if (v && v->needThis())
- error("need 'this' for address of %s", v->toChars());
+ error("need 'this' for address of %s", v->toChars());
}
Expression *SymOffExp::semantic(Scope *sc)
@@ -4008,10 +4008,10 @@ Expression *SymOffExp::semantic(Scope *sc)
//var->semantic(sc);
m = sc->module;
if (!type)
- type = var->type->pointerTo();
+ type = var->type->pointerTo();
VarDeclaration *v = var->isVarDeclaration();
if (v)
- v->checkNestedReference(sc, loc);
+ v->checkNestedReference(sc, loc);
return this;
}
@@ -4025,30 +4025,30 @@ void SymOffExp::checkEscape()
VarDeclaration *v = var->isVarDeclaration();
if (v)
{
- if (!v->isDataseg() && !(v->storage_class & (STCref | STCout)))
- { /* BUG: This should be allowed:
- * void foo()
- * { int a;
- * int* bar() { return &a; }
- * }
- */
- error("escaping reference to local %s", v->toChars());
- }
+ if (!v->isDataseg() && !(v->storage_class & (STCref | STCout)))
+ { /* BUG: This should be allowed:
+ * void foo()
+ * { int a;
+ * int* bar() { return &a; }
+ * }
+ */
+ error("escaping reference to local %s", v->toChars());
+ }
}
}
void SymOffExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (offset)
- buf->printf("(& %s+%u)", var->toChars(), offset);
+ buf->printf("(& %s+%u)", var->toChars(), offset);
else
- buf->printf("& %s", var->toChars());
+ buf->printf("& %s", var->toChars());
}
/******************************** VarExp **************************/
VarExp::VarExp(Loc loc, Declaration *var)
- : Expression(loc, TOKvar, sizeof(VarExp))
+ : Expression(loc, TOKvar, sizeof(VarExp))
{
//printf("VarExp(this = %p, '%s')\n", this, var->toChars());
this->var = var;
@@ -4059,10 +4059,10 @@ int VarExp::equals(Object *o)
{ VarExp *ne;
if (this == o ||
- (((Expression *)o)->op == TOKvar &&
- ((ne = (VarExp *)o), type->equals(ne->type)) &&
- var == ne->var))
- return 1;
+ (((Expression *)o)->op == TOKvar &&
+ ((ne = (VarExp *)o), type->equals(ne->type)) &&
+ var == ne->var))
+ return 1;
return 0;
}
@@ -4073,14 +4073,14 @@ Expression *VarExp::semantic(Scope *sc)
printf("VarExp::semantic(%s)\n", toChars());
#endif
if (!type)
- { type = var->type;
+ { type = var->type;
#if 0
- if (var->storage_class & STClazy)
- {
- TypeFunction *tf = new TypeFunction(NULL, type, 0, LINKd);
- type = new TypeDelegate(tf);
- type = type->semantic(loc, sc);
- }
+ if (var->storage_class & STClazy)
+ {
+ TypeFunction *tf = new TypeFunction(NULL, type, 0, LINKd);
+ type = new TypeDelegate(tf);
+ type = type->semantic(loc, sc);
+ }
#endif
}
@@ -4093,30 +4093,30 @@ Expression *VarExp::semantic(Scope *sc)
VarDeclaration *v = var->isVarDeclaration();
if (v)
{
- if (v->isSameAsInitializer() && type->toBasetype()->ty != Tsarray && v->init)
- {
- ExpInitializer *ei = v->init->isExpInitializer();
- if (ei)
- {
- //ei->exp->implicitCastTo(sc, type)->print();
- return ei->exp->implicitCastTo(sc, type);
- }
- }
- v->checkNestedReference(sc, loc);
+ if (v->isSameAsInitializer() && type->toBasetype()->ty != Tsarray && v->init)
+ {
+ ExpInitializer *ei = v->init->isExpInitializer();
+ if (ei)
+ {
+ //ei->exp->implicitCastTo(sc, type)->print();
+ return ei->exp->implicitCastTo(sc, type);
+ }
+ }
+ v->checkNestedReference(sc, loc);
#if DMDV2
- if (sc->func && sc->func->isPure() && !sc->intypeof)
- {
- if (v->isDataseg() && !v->isImmutable())
- error("pure function '%s' cannot access mutable static data '%s'", sc->func->toChars(), v->toChars());
- }
+ if (sc->func && sc->func->isPure() && !sc->intypeof)
+ {
+ if (v->isDataseg() && !v->isImmutable())
+ error("pure function '%s' cannot access mutable static data '%s'", sc->func->toChars(), v->toChars());
+ }
#endif
}
#if 0
else if ((fd = var->isFuncLiteralDeclaration()) != NULL)
- { Expression *e;
- e = new FuncExp(loc, fd);
- e->type = type;
- return e;
+ { Expression *e;
+ e = new FuncExp(loc, fd);
+ e->type = type;
+ return e;
}
#endif
@@ -4137,15 +4137,15 @@ void VarExp::checkEscape()
{
VarDeclaration *v = var->isVarDeclaration();
if (v)
- { Type *tb = v->type->toBasetype();
- // if reference type
- if (tb->ty == Tarray || tb->ty == Tsarray || tb->ty == Tclass)
- {
- if (v->isScope() && !v->noscope)
- error("escaping reference to scope local %s", v->toChars());
- else if (v->storage_class & STCvariadic)
- error("escaping reference to variadic parameter %s", v->toChars());
- }
+ { Type *tb = v->type->toBasetype();
+ // if reference type
+ if (tb->ty == Tarray || tb->ty == Tsarray || tb->ty == Tclass)
+ {
+ if (v->isScope() && !v->noscope)
+ error("escaping reference to scope local %s", v->toChars());
+ else if (v->storage_class & STCvariadic)
+ error("escaping reference to variadic parameter %s", v->toChars());
+ }
}
}
@@ -4154,8 +4154,8 @@ void VarExp::checkEscapeRef()
VarDeclaration *v = var->isVarDeclaration();
if (v)
{
- if (!v->isDataseg() && !(v->storage_class & (STCref | STCout)))
- error("escaping reference to local variable %s", v->toChars());
+ if (!v->isDataseg() && !(v->storage_class & (STCref | STCout)))
+ error("escaping reference to local variable %s", v->toChars());
}
}
@@ -4163,7 +4163,7 @@ void VarExp::checkEscapeRef()
int VarExp::isLvalue()
{
if (var->storage_class & STClazy)
- return 0;
+ return 0;
return 1;
}
#endif
@@ -4173,12 +4173,12 @@ Expression *VarExp::toLvalue(Scope *sc, Expression *e)
#if 0
tym = tybasic(e1->ET->Tty);
if (!(tyscalar(tym) ||
- tym == TYstruct ||
- tym == TYarray && e->Eoper == TOKaddr))
- synerr(EM_lvalue); // lvalue expected
+ tym == TYstruct ||
+ tym == TYarray && e->Eoper == TOKaddr))
+ synerr(EM_lvalue); // lvalue expected
#endif
if (var->storage_class & STClazy)
- error("lazy variables cannot be lvalues");
+ error("lazy variables cannot be lvalues");
return this;
}
@@ -4186,50 +4186,50 @@ Expression *VarExp::modifiableLvalue(Scope *sc, Expression *e)
{
//printf("VarExp::modifiableLvalue('%s')\n", var->toChars());
if (sc->incontract && var->isParameter())
- error("cannot modify parameter '%s' in contract", var->toChars());
+ error("cannot modify parameter '%s' in contract", var->toChars());
if (type && type->toBasetype()->ty == Tsarray)
- error("cannot change reference to static array '%s'", var->toChars());
+ error("cannot change reference to static array '%s'", var->toChars());
VarDeclaration *v = var->isVarDeclaration();
if (v && v->canassign == 0 &&
(var->isConst() || (global.params.Dversion > 1 && var->isFinal())))
- error("cannot modify final variable '%s'", var->toChars());
+ error("cannot modify final variable '%s'", var->toChars());
if (var->isCtorinit())
- { // It's only modifiable if inside the right constructor
- Dsymbol *s = sc->func;
- while (1)
- {
- FuncDeclaration *fd = NULL;
- if (s)
- fd = s->isFuncDeclaration();
- if (fd &&
- ((fd->isCtorDeclaration() && var->storage_class & STCfield) ||
- (fd->isStaticCtorDeclaration() && !(var->storage_class & STCfield))) &&
- fd->toParent() == var->toParent()
- )
- {
- VarDeclaration *v = var->isVarDeclaration();
- assert(v);
- v->ctorinit = 1;
- //printf("setting ctorinit\n");
- }
- else
- {
- if (s)
- { s = s->toParent2();
- continue;
- }
- else
- {
- const char *p = var->isStatic() ? "static " : "";
- error("can only initialize %sconst %s inside %sconstructor",
- p, var->toChars(), p);
- }
- }
- break;
- }
+ { // It's only modifiable if inside the right constructor
+ Dsymbol *s = sc->func;
+ while (1)
+ {
+ FuncDeclaration *fd = NULL;
+ if (s)
+ fd = s->isFuncDeclaration();
+ if (fd &&
+ ((fd->isCtorDeclaration() && var->storage_class & STCfield) ||
+ (fd->isStaticCtorDeclaration() && !(var->storage_class & STCfield))) &&
+ fd->toParent() == var->toParent()
+ )
+ {
+ VarDeclaration *v = var->isVarDeclaration();
+ assert(v);
+ v->ctorinit = 1;
+ //printf("setting ctorinit\n");
+ }
+ else
+ {
+ if (s)
+ { s = s->toParent2();
+ continue;
+ }
+ else
+ {
+ const char *p = var->isStatic() ? "static " : "";
+ error("can only initialize %sconst %s inside %sconstructor",
+ p, var->toChars(), p);
+ }
+ }
+ break;
+ }
}
// See if this expression is a modifiable lvalue (i.e. not const)
@@ -4241,7 +4241,7 @@ Expression *VarExp::modifiableLvalue(Scope *sc, Expression *e)
#if DMDV2
OverExp::OverExp(OverloadSet *s)
- : Expression(loc, TOKoverloadset, sizeof(OverExp))
+ : Expression(loc, TOKoverloadset, sizeof(OverExp))
{
//printf("OverExp(this = %p, '%s')\n", this, var->toChars());
vars = s;
@@ -4263,7 +4263,7 @@ Expression *OverExp::toLvalue(Scope *sc, Expression *e)
/******************************** TupleExp **************************/
TupleExp::TupleExp(Loc loc, Expressions *exps)
- : Expression(loc, TOKtuple, sizeof(TupleExp))
+ : Expression(loc, TOKtuple, sizeof(TupleExp))
{
//printf("TupleExp(this = %p)\n", this);
this->exps = exps;
@@ -4272,7 +4272,7 @@ TupleExp::TupleExp(Loc loc, Expressions *exps)
TupleExp::TupleExp(Loc loc, TupleDeclaration *tup)
- : Expression(loc, TOKtuple, sizeof(TupleExp))
+ : Expression(loc, TOKtuple, sizeof(TupleExp))
{
exps = new Expressions();
type = NULL;
@@ -4280,28 +4280,28 @@ TupleExp::TupleExp(Loc loc, TupleDeclaration *tup)
exps->reserve(tup->objects->dim);
for (size_t i = 0; i < tup->objects->dim; i++)
{ Object *o = (Object *)tup->objects->data[i];
- if (o->dyncast() == DYNCAST_EXPRESSION)
- {
- Expression *e = (Expression *)o;
- e = e->syntaxCopy();
- exps->push(e);
- }
- else if (o->dyncast() == DYNCAST_DSYMBOL)
- {
- Dsymbol *s = (Dsymbol *)o;
- Expression *e = new DsymbolExp(loc, s);
- exps->push(e);
- }
- else if (o->dyncast() == DYNCAST_TYPE)
- {
- Type *t = (Type *)o;
- Expression *e = new TypeExp(loc, t);
- exps->push(e);
- }
- else
- {
- error("%s is not an expression", o->toChars());
- }
+ if (o->dyncast() == DYNCAST_EXPRESSION)
+ {
+ Expression *e = (Expression *)o;
+ e = e->syntaxCopy();
+ exps->push(e);
+ }
+ else if (o->dyncast() == DYNCAST_DSYMBOL)
+ {
+ Dsymbol *s = (Dsymbol *)o;
+ Expression *e = new DsymbolExp(loc, s);
+ exps->push(e);
+ }
+ else if (o->dyncast() == DYNCAST_TYPE)
+ {
+ Type *t = (Type *)o;
+ Expression *e = new TypeExp(loc, t);
+ exps->push(e);
+ }
+ else
+ {
+ error("%s is not an expression", o->toChars());
+ }
}
}
@@ -4309,20 +4309,20 @@ int TupleExp::equals(Object *o)
{ TupleExp *ne;
if (this == o)
- return 1;
+ return 1;
if (((Expression *)o)->op == TOKtuple)
{
- TupleExp *te = (TupleExp *)o;
- if (exps->dim != te->exps->dim)
- return 0;
- for (size_t i = 0; i < exps->dim; i++)
- { Expression *e1 = (Expression *)exps->data[i];
- Expression *e2 = (Expression *)te->exps->data[i];
+ TupleExp *te = (TupleExp *)o;
+ if (exps->dim != te->exps->dim)
+ return 0;
+ for (size_t i = 0; i < exps->dim; i++)
+ { Expression *e1 = (Expression *)exps->data[i];
+ Expression *e2 = (Expression *)te->exps->data[i];
- if (!e1->equals(e2))
- return 0;
- }
- return 1;
+ if (!e1->equals(e2))
+ return 0;
+ }
+ return 1;
}
return 0;
}
@@ -4338,24 +4338,24 @@ Expression *TupleExp::semantic(Scope *sc)
printf("+TupleExp::semantic(%s)\n", toChars());
#endif
if (type)
- return this;
+ return this;
// Run semantic() on each argument
for (size_t i = 0; i < exps->dim; i++)
- { Expression *e = (Expression *)exps->data[i];
+ { Expression *e = (Expression *)exps->data[i];
- e = e->semantic(sc);
- if (!e->type)
- { error("%s has no value", e->toChars());
- e->type = Type::terror;
- }
- exps->data[i] = (void *)e;
+ e = e->semantic(sc);
+ if (!e->type)
+ { error("%s has no value", e->toChars());
+ e->type = Type::terror;
+ }
+ exps->data[i] = (void *)e;
}
expandTuples(exps);
if (0 && exps->dim == 1)
{
- return (Expression *)exps->data[0];
+ return (Expression *)exps->data[0];
}
type = new TypeTuple(exps);
type = type->semantic(loc, sc);
@@ -4374,12 +4374,12 @@ int TupleExp::checkSideEffect(int flag)
{ int f = 0;
for (int i = 0; i < exps->dim; i++)
- { Expression *e = (Expression *)exps->data[i];
+ { Expression *e = (Expression *)exps->data[i];
- f |= e->checkSideEffect(2);
+ f |= e->checkSideEffect(2);
}
if (flag == 0 && f == 0)
- Expression::checkSideEffect(0);
+ Expression::checkSideEffect(0);
return f;
}
@@ -4394,14 +4394,14 @@ void TupleExp::checkEscape()
{
for (size_t i = 0; i < exps->dim; i++)
{ Expression *e = (Expression *)exps->data[i];
- e->checkEscape();
+ e->checkEscape();
}
}
/******************************** FuncExp *********************************/
FuncExp::FuncExp(Loc loc, FuncLiteralDeclaration *fd)
- : Expression(loc, TOKfunction, sizeof(FuncExp))
+ : Expression(loc, TOKfunction, sizeof(FuncExp))
{
this->fd = fd;
}
@@ -4418,39 +4418,39 @@ Expression *FuncExp::semantic(Scope *sc)
#endif
if (!type)
{
- fd->semantic(sc);
- fd->parent = sc->parent;
- if (global.errors)
- {
- }
- else
- {
- fd->semantic2(sc);
- if (!global.errors ||
- // need to infer return type
- (fd->type && fd->type->ty == Tfunction && !fd->type->nextOf()))
- {
- fd->semantic3(sc);
+ fd->semantic(sc);
+ fd->parent = sc->parent;
+ if (global.errors)
+ {
+ }
+ else
+ {
+ fd->semantic2(sc);
+ if (!global.errors ||
+ // need to infer return type
+ (fd->type && fd->type->ty == Tfunction && !fd->type->nextOf()))
+ {
+ fd->semantic3(sc);
- if (!global.errors && global.params.useInline)
- fd->inlineScan();
- }
- }
+ if (!global.errors && global.params.useInline)
+ fd->inlineScan();
+ }
+ }
- // need to infer return type
- if (global.errors && fd->type && fd->type->ty == Tfunction && !fd->type->nextOf())
- ((TypeFunction *)fd->type)->next = Type::terror;
+ // need to infer return type
+ if (global.errors && fd->type && fd->type->ty == Tfunction && !fd->type->nextOf())
+ ((TypeFunction *)fd->type)->next = Type::terror;
- // Type is a "delegate to" or "pointer to" the function literal
- if (fd->isNested())
- {
- type = new TypeDelegate(fd->type);
- type = type->semantic(loc, sc);
- }
- else
- {
- type = fd->type->pointerTo();
- }
+ // Type is a "delegate to" or "pointer to" the function literal
+ if (fd->isNested())
+ {
+ type = new TypeDelegate(fd->type);
+ type = type->semantic(loc, sc);
+ }
+ else
+ {
+ type = fd->type->pointerTo();
+ }
}
return this;
}
@@ -4470,7 +4470,7 @@ void FuncExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/******************************** DeclarationExp **************************/
DeclarationExp::DeclarationExp(Loc loc, Dsymbol *declaration)
- : Expression(loc, TOKdeclaration, sizeof(DeclarationExp))
+ : Expression(loc, TOKdeclaration, sizeof(DeclarationExp))
{
this->declaration = declaration;
}
@@ -4483,7 +4483,7 @@ Expression *DeclarationExp::syntaxCopy()
Expression *DeclarationExp::semantic(Scope *sc)
{
if (type)
- return this;
+ return this;
#if LOGSEMANTIC
printf("DeclarationExp::semantic() %s\n", toChars());
@@ -4498,16 +4498,16 @@ Expression *DeclarationExp::semantic(Scope *sc)
AttribDeclaration *ad = declaration->isAttribDeclaration();
if (ad)
{
- if (ad->decl && ad->decl->dim == 1)
- s = (Dsymbol *)ad->decl->data[0];
+ if (ad->decl && ad->decl->dim == 1)
+ s = (Dsymbol *)ad->decl->data[0];
}
if (s->isVarDeclaration())
- { // Do semantic() on initializer first, so:
- // int a = a;
- // will be illegal.
- declaration->semantic(sc);
- s->parent = sc->parent;
+ { // Do semantic() on initializer first, so:
+ // int a = a;
+ // will be illegal.
+ declaration->semantic(sc);
+ s->parent = sc->parent;
}
//printf("inserting '%s' %p into sc = %p\n", s->toChars(), s, sc);
@@ -4515,50 +4515,50 @@ Expression *DeclarationExp::semantic(Scope *sc)
// Must be unique in both.
if (s->ident)
{
- if (!sc->insert(s))
- error("declaration %s is already defined", s->toPrettyChars());
- else if (sc->func)
- { VarDeclaration *v = s->isVarDeclaration();
- if ((s->isFuncDeclaration() /*|| v && v->storage_class & STCstatic*/) &&
- !sc->func->localsymtab->insert(s))
- error("declaration %s is already defined in another scope in %s", s->toPrettyChars(), sc->func->toChars());
- else if (!global.params.useDeprecated)
- { // Disallow shadowing
+ if (!sc->insert(s))
+ error("declaration %s is already defined", s->toPrettyChars());
+ else if (sc->func)
+ { VarDeclaration *v = s->isVarDeclaration();
+ if ((s->isFuncDeclaration() /*|| v && v->storage_class & STCstatic*/) &&
+ !sc->func->localsymtab->insert(s))
+ error("declaration %s is already defined in another scope in %s", s->toPrettyChars(), sc->func->toChars());
+ else if (!global.params.useDeprecated)
+ { // Disallow shadowing
- for (Scope *scx = sc->enclosing; scx && scx->func == sc->func; scx = scx->enclosing)
- { Dsymbol *s2;
+ for (Scope *scx = sc->enclosing; scx && scx->func == sc->func; scx = scx->enclosing)
+ { Dsymbol *s2;
- if (scx->scopesym && scx->scopesym->symtab &&
- (s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL &&
- s != s2)
- {
- error("shadowing declaration %s is deprecated", s->toPrettyChars());
- }
- }
- }
- }
+ if (scx->scopesym && scx->scopesym->symtab &&
+ (s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL &&
+ s != s2)
+ {
+ error("shadowing declaration %s is deprecated", s->toPrettyChars());
+ }
+ }
+ }
+ }
}
if (!s->isVarDeclaration())
{
- Scope *sc2 = sc;
- if (sc2->stc & (STCpure | STCnothrow))
- sc2 = sc->push();
- sc2->stc &= ~(STCpure | STCnothrow);
- declaration->semantic(sc2);
- if (sc2 != sc)
- sc2->pop();
- s->parent = sc->parent;
+ Scope *sc2 = sc;
+ if (sc2->stc & (STCpure | STCnothrow))
+ sc2 = sc->push();
+ sc2->stc &= ~(STCpure | STCnothrow);
+ declaration->semantic(sc2);
+ if (sc2 != sc)
+ sc2->pop();
+ s->parent = sc->parent;
}
if (!global.errors)
{
- declaration->semantic2(sc);
- if (!global.errors)
- {
- declaration->semantic3(sc);
+ declaration->semantic2(sc);
+ if (!global.errors)
+ {
+ declaration->semantic3(sc);
- if (!global.errors && global.params.useInline)
- declaration->inlineScan();
- }
+ if (!global.errors && global.params.useInline)
+ declaration->inlineScan();
+ }
}
type = Type::tvoid;
@@ -4575,8 +4575,8 @@ int DeclarationExp::canThrow()
{
VarDeclaration *v = declaration->isVarDeclaration();
if (v && v->init)
- { ExpInitializer *ie = v->init->isExpInitializer();
- return ie && ie->exp->canThrow();
+ { ExpInitializer *ie = v->init->isExpInitializer();
+ return ie && ie->exp->canThrow();
}
return 0;
}
@@ -4591,7 +4591,7 @@ void DeclarationExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************ TypeidExp ************************************/
/*
- * typeid(int)
+ * typeid(int)
*/
TypeidExp::TypeidExp(Loc loc, Type *typeidType)
@@ -4616,7 +4616,7 @@ Expression *TypeidExp::semantic(Scope *sc)
typeidType = typeidType->semantic(loc, sc);
e = typeidType->getTypeInfo(sc);
if (e->loc.linnum == 0)
- e->loc = loc; // so there's at least some line number info
+ e->loc = loc; // so there's at least some line number info
return e;
}
@@ -4630,7 +4630,7 @@ void TypeidExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************ TraitsExp ************************************/
#if DMDV2
/*
- * __traits(identifier, args...)
+ * __traits(identifier, args...)
*/
TraitsExp::TraitsExp(Loc loc, Identifier *ident, Objects *args)
@@ -4653,12 +4653,12 @@ void TraitsExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring(ident->toChars());
if (args)
{
- for (int i = 0; i < args->dim; i++)
- {
- buf->writeByte(',');
- Object *oarg = (Object *)args->data[i];
- ObjectToCBuffer(buf, hgs, oarg);
- }
+ for (int i = 0; i < args->dim; i++)
+ {
+ buf->writeByte(',');
+ Object *oarg = (Object *)args->data[i];
+ ObjectToCBuffer(buf, hgs, oarg);
+ }
}
buf->writeByte(')');
}
@@ -4667,7 +4667,7 @@ void TraitsExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
HaltExp::HaltExp(Loc loc)
- : Expression(loc, TOKhalt, sizeof(HaltExp))
+ : Expression(loc, TOKhalt, sizeof(HaltExp))
{
}
@@ -4693,8 +4693,8 @@ void HaltExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
IsExp::IsExp(Loc loc, Type *targ, Identifier *id, enum TOK tok,
- Type *tspec, enum TOK tok2)
- : Expression(loc, TOKis, sizeof(IsExp))
+ Type *tspec, enum TOK tok2)
+ : Expression(loc, TOKis, sizeof(IsExp))
{
this->targ = targ;
this->id = id;
@@ -4706,11 +4706,11 @@ IsExp::IsExp(Loc loc, Type *targ, Identifier *id, enum TOK tok,
Expression *IsExp::syntaxCopy()
{
return new IsExp(loc,
- targ->syntaxCopy(),
- id,
- tok,
- tspec ? tspec->syntaxCopy() : NULL,
- tok2);
+ targ->syntaxCopy(),
+ id,
+ tok,
+ tspec ? tspec->syntaxCopy() : NULL,
+ tok2);
}
Expression *IsExp::semantic(Scope *sc)
@@ -4722,220 +4722,220 @@ Expression *IsExp::semantic(Scope *sc)
//printf("IsExp::semantic(%s)\n", toChars());
if (id && !(sc->flags & SCOPEstaticif))
- error("can only declare type aliases within static if conditionals");
+ error("can only declare type aliases within static if conditionals");
unsigned errors_save = global.errors;
global.errors = 0;
- global.gag++; // suppress printing of error messages
+ global.gag++; // suppress printing of error messages
targ = targ->semantic(loc, sc);
global.gag--;
unsigned gerrors = global.errors;
global.errors = errors_save;
- if (gerrors) // if any errors happened
- { // then condition is false
- goto Lno;
+ if (gerrors) // if any errors happened
+ { // then condition is false
+ goto Lno;
}
else if (tok2 != TOKreserved)
{
- switch (tok2)
- {
- case TOKtypedef:
- if (targ->ty != Ttypedef)
- goto Lno;
- tded = ((TypeTypedef *)targ)->sym->basetype;
- break;
+ switch (tok2)
+ {
+ case TOKtypedef:
+ if (targ->ty != Ttypedef)
+ goto Lno;
+ tded = ((TypeTypedef *)targ)->sym->basetype;
+ break;
- case TOKstruct:
- if (targ->ty != Tstruct)
- goto Lno;
- if (((TypeStruct *)targ)->sym->isUnionDeclaration())
- goto Lno;
- tded = targ;
- break;
+ case TOKstruct:
+ if (targ->ty != Tstruct)
+ goto Lno;
+ if (((TypeStruct *)targ)->sym->isUnionDeclaration())
+ goto Lno;
+ tded = targ;
+ break;
- case TOKunion:
- if (targ->ty != Tstruct)
- goto Lno;
- if (!((TypeStruct *)targ)->sym->isUnionDeclaration())
- goto Lno;
- tded = targ;
- break;
+ case TOKunion:
+ if (targ->ty != Tstruct)
+ goto Lno;
+ if (!((TypeStruct *)targ)->sym->isUnionDeclaration())
+ goto Lno;
+ tded = targ;
+ break;
- case TOKclass:
- if (targ->ty != Tclass)
- goto Lno;
- if (((TypeClass *)targ)->sym->isInterfaceDeclaration())
- goto Lno;
- tded = targ;
- break;
+ case TOKclass:
+ if (targ->ty != Tclass)
+ goto Lno;
+ if (((TypeClass *)targ)->sym->isInterfaceDeclaration())
+ goto Lno;
+ tded = targ;
+ break;
- case TOKinterface:
- if (targ->ty != Tclass)
- goto Lno;
- if (!((TypeClass *)targ)->sym->isInterfaceDeclaration())
- goto Lno;
- tded = targ;
- break;
+ case TOKinterface:
+ if (targ->ty != Tclass)
+ goto Lno;
+ if (!((TypeClass *)targ)->sym->isInterfaceDeclaration())
+ goto Lno;
+ tded = targ;
+ break;
#if DMDV2
- case TOKconst:
- if (!targ->isConst())
- goto Lno;
- tded = targ;
- break;
+ case TOKconst:
+ if (!targ->isConst())
+ goto Lno;
+ tded = targ;
+ break;
- case TOKinvariant:
- case TOKimmutable:
- if (!targ->isImmutable())
- goto Lno;
- tded = targ;
- break;
+ case TOKinvariant:
+ case TOKimmutable:
+ if (!targ->isImmutable())
+ goto Lno;
+ tded = targ;
+ break;
- case TOKshared:
- if (!targ->isShared())
- goto Lno;
- tded = targ;
- break;
+ case TOKshared:
+ if (!targ->isShared())
+ goto Lno;
+ tded = targ;
+ break;
#endif
- case TOKsuper:
- // If class or interface, get the base class and interfaces
- if (targ->ty != Tclass)
- goto Lno;
- else
- { ClassDeclaration *cd = ((TypeClass *)targ)->sym;
- Parameters *args = new Parameters;
- args->reserve(cd->baseclasses.dim);
- for (size_t i = 0; i < cd->baseclasses.dim; i++)
- { BaseClass *b = (BaseClass *)cd->baseclasses.data[i];
- args->push(new Parameter(STCin, b->type, NULL, NULL));
- }
- tded = new TypeTuple(args);
- }
- break;
+ case TOKsuper:
+ // If class or interface, get the base class and interfaces
+ if (targ->ty != Tclass)
+ goto Lno;
+ else
+ { ClassDeclaration *cd = ((TypeClass *)targ)->sym;
+ Parameters *args = new Parameters;
+ args->reserve(cd->baseclasses.dim);
+ for (size_t i = 0; i < cd->baseclasses.dim; i++)
+ { BaseClass *b = (BaseClass *)cd->baseclasses.data[i];
+ args->push(new Parameter(STCin, b->type, NULL, NULL));
+ }
+ tded = new TypeTuple(args);
+ }
+ break;
- case TOKenum:
- if (targ->ty != Tenum)
- goto Lno;
- tded = ((TypeEnum *)targ)->sym->memtype;
- break;
+ case TOKenum:
+ if (targ->ty != Tenum)
+ goto Lno;
+ tded = ((TypeEnum *)targ)->sym->memtype;
+ break;
- case TOKdelegate:
- if (targ->ty != Tdelegate)
- goto Lno;
- tded = ((TypeDelegate *)targ)->next; // the underlying function type
- break;
+ case TOKdelegate:
+ if (targ->ty != Tdelegate)
+ goto Lno;
+ tded = ((TypeDelegate *)targ)->next; // the underlying function type
+ break;
- case TOKfunction:
- {
- if (targ->ty != Tfunction)
- goto Lno;
- tded = targ;
+ case TOKfunction:
+ {
+ if (targ->ty != Tfunction)
+ goto Lno;
+ tded = targ;
- /* Generate tuple from function parameter types.
- */
- assert(tded->ty == Tfunction);
- Parameters *params = ((TypeFunction *)tded)->parameters;
- size_t dim = Parameter::dim(params);
- Parameters *args = new Parameters;
- args->reserve(dim);
- for (size_t i = 0; i < dim; i++)
- { Parameter *arg = Parameter::getNth(params, i);
- assert(arg && arg->type);
- args->push(new Parameter(arg->storageClass, arg->type, NULL, NULL));
- }
- tded = new TypeTuple(args);
- break;
- }
- case TOKreturn:
- /* Get the 'return type' for the function,
- * delegate, or pointer to function.
- */
- if (targ->ty == Tfunction)
- tded = ((TypeFunction *)targ)->next;
- else if (targ->ty == Tdelegate)
- tded = targ->next->next;
- else if (targ->ty == Tpointer && targ->next->ty == Tfunction)
- tded = targ->next->next;
- else
- goto Lno;
- break;
+ /* Generate tuple from function parameter types.
+ */
+ assert(tded->ty == Tfunction);
+ Parameters *params = ((TypeFunction *)tded)->parameters;
+ size_t dim = Parameter::dim(params);
+ Parameters *args = new Parameters;
+ args->reserve(dim);
+ for (size_t i = 0; i < dim; i++)
+ { Parameter *arg = Parameter::getNth(params, i);
+ assert(arg && arg->type);
+ args->push(new Parameter(arg->storageClass, arg->type, NULL, NULL));
+ }
+ tded = new TypeTuple(args);
+ break;
+ }
+ case TOKreturn:
+ /* Get the 'return type' for the function,
+ * delegate, or pointer to function.
+ */
+ if (targ->ty == Tfunction)
+ tded = ((TypeFunction *)targ)->next;
+ else if (targ->ty == Tdelegate)
+ tded = targ->next->next;
+ else if (targ->ty == Tpointer && targ->next->ty == Tfunction)
+ tded = targ->next->next;
+ else
+ goto Lno;
+ break;
- default:
- assert(0);
- }
- goto Lyes;
+ default:
+ assert(0);
+ }
+ goto Lyes;
}
else if (id && tspec)
{
- /* Evaluate to TRUE if targ matches tspec.
- * If TRUE, declare id as an alias for the specialized type.
- */
+ /* Evaluate to TRUE if targ matches tspec.
+ * If TRUE, declare id as an alias for the specialized type.
+ */
- MATCH m;
- TemplateTypeParameter tp(loc, id, NULL, NULL);
+ MATCH m;
+ TemplateTypeParameter tp(loc, id, NULL, NULL);
- TemplateParameters parameters;
- parameters.setDim(1);
- parameters.data[0] = (void *)&tp;
+ TemplateParameters parameters;
+ parameters.setDim(1);
+ parameters.data[0] = (void *)&tp;
- Objects dedtypes;
- dedtypes.setDim(1);
- dedtypes.data[0] = NULL;
+ Objects dedtypes;
+ dedtypes.setDim(1);
+ dedtypes.data[0] = NULL;
- m = targ->deduceType(NULL, tspec, ¶meters, &dedtypes);
- if (m == MATCHnomatch ||
- (m != MATCHexact && tok == TOKequal))
- {
- goto Lno;
- }
- else
- {
- assert(dedtypes.dim == 1);
- tded = (Type *)dedtypes.data[0];
- if (!tded)
- tded = targ;
- goto Lyes;
- }
+ m = targ->deduceType(NULL, tspec, ¶meters, &dedtypes);
+ if (m == MATCHnomatch ||
+ (m != MATCHexact && tok == TOKequal))
+ {
+ goto Lno;
+ }
+ else
+ {
+ assert(dedtypes.dim == 1);
+ tded = (Type *)dedtypes.data[0];
+ if (!tded)
+ tded = targ;
+ goto Lyes;
+ }
}
else if (id)
{
- /* Declare id as an alias for type targ. Evaluate to TRUE
- */
- tded = targ;
- goto Lyes;
+ /* Declare id as an alias for type targ. Evaluate to TRUE
+ */
+ tded = targ;
+ goto Lyes;
}
else if (tspec)
{
- /* Evaluate to TRUE if targ matches tspec
- * is(targ == tspec)
- * is(targ : tspec)
- */
- tspec = tspec->semantic(loc, sc);
- //printf("targ = %s\n", targ->toChars());
- //printf("tspec = %s\n", tspec->toChars());
- if (tok == TOKcolon)
- { if (targ->implicitConvTo(tspec))
- goto Lyes;
- else
- goto Lno;
- }
- else /* == */
- { if (targ->equals(tspec))
- goto Lyes;
- else
- goto Lno;
- }
+ /* Evaluate to TRUE if targ matches tspec
+ * is(targ == tspec)
+ * is(targ : tspec)
+ */
+ tspec = tspec->semantic(loc, sc);
+ //printf("targ = %s\n", targ->toChars());
+ //printf("tspec = %s\n", tspec->toChars());
+ if (tok == TOKcolon)
+ { if (targ->implicitConvTo(tspec))
+ goto Lyes;
+ else
+ goto Lno;
+ }
+ else /* == */
+ { if (targ->equals(tspec))
+ goto Lyes;
+ else
+ goto Lno;
+ }
}
Lyes:
if (id)
{
- Dsymbol *s = new AliasDeclaration(loc, id, tded);
- s->semantic(sc);
- sc->insert(s);
- if (sc->sd)
- s->addMember(sc, sc->sd, 1);
+ Dsymbol *s = new AliasDeclaration(loc, id, tded);
+ s->semantic(sc);
+ sc->insert(s);
+ if (sc->sd)
+ s->addMember(sc, sc->sd, 1);
}
return new IntegerExp(1);
@@ -4949,25 +4949,25 @@ void IsExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
targ->toCBuffer(buf, id, hgs);
if (tok2 != TOKreserved)
{
- buf->printf(" %s %s", Token::toChars(tok), Token::toChars(tok2));
+ buf->printf(" %s %s", Token::toChars(tok), Token::toChars(tok2));
}
else if (tspec)
{
- if (tok == TOKcolon)
- buf->writestring(" : ");
- else
- buf->writestring(" == ");
- tspec->toCBuffer(buf, NULL, hgs);
+ if (tok == TOKcolon)
+ buf->writestring(" : ");
+ else
+ buf->writestring(" == ");
+ tspec->toCBuffer(buf, NULL, hgs);
}
#if DMDV2
if (parameters)
- { // First parameter is already output, so start with second
- for (int i = 1; i < parameters->dim; i++)
- {
- buf->writeByte(',');
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- tp->toCBuffer(buf, hgs);
- }
+ { // First parameter is already output, so start with second
+ for (int i = 1; i < parameters->dim; i++)
+ {
+ buf->writeByte(',');
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ tp->toCBuffer(buf, hgs);
+ }
}
#endif
buf->writeByte(')');
@@ -4977,7 +4977,7 @@ void IsExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
UnaExp::UnaExp(Loc loc, enum TOK op, int size, Expression *e1)
- : Expression(loc, op, size)
+ : Expression(loc, op, size)
{
this->e1 = e1;
}
@@ -4998,7 +4998,7 @@ Expression *UnaExp::semantic(Scope *sc)
#endif
e1 = e1->semantic(sc);
// if (!e1->type)
-// error("%s has no value", e1->toChars());
+// error("%s has no value", e1->toChars());
return this;
}
@@ -5018,7 +5018,7 @@ void UnaExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
BinExp::BinExp(Loc loc, enum TOK op, int size, Expression *e1, Expression *e2)
- : Expression(loc, op, size)
+ : Expression(loc, op, size)
{
this->e1 = e1;
this->e2 = e2;
@@ -5041,16 +5041,16 @@ Expression *BinExp::semantic(Scope *sc)
#endif
e1 = e1->semantic(sc);
if (!e1->type &&
- !(op == TOKassign && e1->op == TOKdottd)) // a.template = e2
+ !(op == TOKassign && e1->op == TOKdottd)) // a.template = e2
{
- error("%s has no value", e1->toChars());
- e1->type = Type::terror;
+ error("%s has no value", e1->toChars());
+ e1->type = Type::terror;
}
e2 = e2->semantic(sc);
if (!e2->type)
{
- error("%s has no value", e2->toChars());
- e2->type = Type::terror;
+ error("%s has no value", e2->toChars());
+ e2->type = Type::terror;
}
return this;
}
@@ -5072,35 +5072,35 @@ Expression *BinExp::commonSemanticAssign(Scope *sc)
if (!type)
{
- BinExp::semantic(sc);
- e2 = resolveProperties(sc, e2);
+ BinExp::semantic(sc);
+ e2 = resolveProperties(sc, e2);
- e = op_overload(sc);
- if (e)
- return e;
+ e = op_overload(sc);
+ if (e)
+ return e;
- if (e1->op == TOKslice)
- { // T[] op= ...
- typeCombine(sc);
- type = e1->type;
- return arrayOp(sc);
- }
+ if (e1->op == TOKslice)
+ { // T[] op= ...
+ typeCombine(sc);
+ type = e1->type;
+ return arrayOp(sc);
+ }
- e1 = e1->modifiableLvalue(sc, e1);
- e1->checkScalar();
- type = e1->type;
- if (type->toBasetype()->ty == Tbool)
- {
- error("operator not allowed on bool expression %s", toChars());
- }
- typeCombine(sc);
- e1->checkArithmetic();
- e2->checkArithmetic();
+ e1 = e1->modifiableLvalue(sc, e1);
+ e1->checkScalar();
+ type = e1->type;
+ if (type->toBasetype()->ty == Tbool)
+ {
+ error("operator not allowed on bool expression %s", toChars());
+ }
+ typeCombine(sc);
+ e1->checkArithmetic();
+ e2->checkArithmetic();
- if (op == TOKmodass && e2->type->iscomplex())
- { error("cannot perform modulo complex arithmetic");
- return new ErrorExp();
- }
+ if (op == TOKmodass && e2->type->iscomplex())
+ { error("cannot perform modulo complex arithmetic");
+ return new ErrorExp();
+ }
}
return this;
}
@@ -5110,31 +5110,31 @@ Expression *BinExp::commonSemanticAssignIntegral(Scope *sc)
if (!type)
{
- BinExp::semantic(sc);
- e2 = resolveProperties(sc, e2);
+ BinExp::semantic(sc);
+ e2 = resolveProperties(sc, e2);
- e = op_overload(sc);
- if (e)
- return e;
+ e = op_overload(sc);
+ if (e)
+ return e;
- if (e1->op == TOKslice)
- { // T[] op= ...
- typeCombine(sc);
- type = e1->type;
- return arrayOp(sc);
- }
+ if (e1->op == TOKslice)
+ { // T[] op= ...
+ typeCombine(sc);
+ type = e1->type;
+ return arrayOp(sc);
+ }
- e1 = e1->modifiableLvalue(sc, e1);
- e1->checkScalar();
- type = e1->type;
- if (type->toBasetype()->ty == Tbool)
- {
- e2 = e2->implicitCastTo(sc, type);
- }
+ e1 = e1->modifiableLvalue(sc, e1);
+ e1->checkScalar();
+ type = e1->type;
+ if (type->toBasetype()->ty == Tbool)
+ {
+ e2 = e2->implicitCastTo(sc, type);
+ }
- typeCombine(sc);
- e1->checkIntegral();
- e2->checkIntegral();
+ typeCombine(sc);
+ e1->checkIntegral();
+ e2->checkIntegral();
}
return this;
}
@@ -5142,25 +5142,25 @@ Expression *BinExp::commonSemanticAssignIntegral(Scope *sc)
int BinExp::checkSideEffect(int flag)
{
if (op == TOKplusplus ||
- op == TOKminusminus ||
- op == TOKassign ||
- op == TOKconstruct ||
- op == TOKblit ||
- op == TOKaddass ||
- op == TOKminass ||
- op == TOKcatass ||
- op == TOKmulass ||
- op == TOKdivass ||
- op == TOKmodass ||
- op == TOKshlass ||
- op == TOKshrass ||
- op == TOKushrass ||
- op == TOKandass ||
- op == TOKorass ||
- op == TOKxorass ||
- op == TOKin ||
- op == TOKremove)
- return 1;
+ op == TOKminusminus ||
+ op == TOKassign ||
+ op == TOKconstruct ||
+ op == TOKblit ||
+ op == TOKaddass ||
+ op == TOKminass ||
+ op == TOKcatass ||
+ op == TOKmulass ||
+ op == TOKdivass ||
+ op == TOKmodass ||
+ op == TOKshlass ||
+ op == TOKshrass ||
+ op == TOKushrass ||
+ op == TOKandass ||
+ op == TOKorass ||
+ op == TOKxorass ||
+ op == TOKin ||
+ op == TOKremove)
+ return 1;
return Expression::checkSideEffect(flag);
}
@@ -5173,7 +5173,7 @@ void BinExp::checkComplexMulAssign()
if ( e1->type->isreal() && e2->type->iscomplex())
{
error("%s %s %s is undefined. Did you mean %s %s %s.re ?",
- e1->type->toChars(), opstr, e2->type->toChars(),
+ e1->type->toChars(), opstr, e2->type->toChars(),
e1->type->toChars(), opstr, e2->type->toChars());
}
else if (e1->type->isimaginary() && e2->type->iscomplex())
@@ -5183,10 +5183,10 @@ void BinExp::checkComplexMulAssign()
e1->type->toChars(), opstr, e2->type->toChars());
}
else if ((e1->type->isreal() || e1->type->isimaginary()) &&
- e2->type->isimaginary())
+ e2->type->isimaginary())
{
error("%s %s %s is an undefined operation", e1->type->toChars(),
- opstr, e2->type->toChars());
+ opstr, e2->type->toChars());
}
}
@@ -5196,11 +5196,11 @@ void BinExp::checkComplexAddAssign()
// Addition or subtraction of a real and an imaginary is a complex result.
// Thus, r+=i, r+=c, i+=r, i+=c are all forbidden operations.
if ( (e1->type->isreal() && (e2->type->isimaginary() || e2->type->iscomplex())) ||
- (e1->type->isimaginary() && (e2->type->isreal() || e2->type->iscomplex()))
+ (e1->type->isimaginary() && (e2->type->isreal() || e2->type->iscomplex()))
)
{
error("%s %s %s is undefined (result is complex)",
- e1->type->toChars(), Token::toChars(op), e2->type->toChars());
+ e1->type->toChars(), Token::toChars(op), e2->type->toChars());
}
}
@@ -5235,7 +5235,7 @@ void BinExp::incompatibleTypes()
/************************************************************/
CompileExp::CompileExp(Loc loc, Expression *e)
- : UnaExp(loc, TOKmixin, sizeof(CompileExp), e)
+ : UnaExp(loc, TOKmixin, sizeof(CompileExp), e)
{
}
@@ -5248,9 +5248,9 @@ Expression *CompileExp::semantic(Scope *sc)
e1 = resolveProperties(sc, e1);
e1 = e1->optimize(WANTvalue | WANTinterpret);
if (e1->op != TOKstring)
- { error("argument to mixin must be a string, not (%s)", e1->toChars());
- type = Type::terror;
- return this;
+ { error("argument to mixin must be a string, not (%s)", e1->toChars());
+ type = Type::terror;
+ return this;
}
StringExp *se = (StringExp *)e1;
se = se->toUTF8(sc);
@@ -5260,7 +5260,7 @@ Expression *CompileExp::semantic(Scope *sc)
//printf("p.loc.linnum = %d\n", p.loc.linnum);
Expression *e = p.parseExpression();
if (p.token.value != TOKeof)
- error("incomplete mixin expression (%s)", se->toChars());
+ error("incomplete mixin expression (%s)", se->toChars());
return e->semantic(sc);
}
@@ -5274,7 +5274,7 @@ void CompileExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
FileExp::FileExp(Loc loc, Expression *e)
- : UnaExp(loc, TOKmixin, sizeof(FileExp), e)
+ : UnaExp(loc, TOKmixin, sizeof(FileExp), e)
{
}
@@ -5289,16 +5289,16 @@ Expression *FileExp::semantic(Scope *sc)
e1 = resolveProperties(sc, e1);
e1 = e1->optimize(WANTvalue);
if (e1->op != TOKstring)
- { error("file name argument must be a string, not (%s)", e1->toChars());
- goto Lerror;
+ { error("file name argument must be a string, not (%s)", e1->toChars());
+ goto Lerror;
}
se = (StringExp *)e1;
se = se->toUTF8(sc);
name = (char *)se->string;
if (!global.params.fileImppath)
- { error("need -Jpath switch to import text file %s", name);
- goto Lerror;
+ { error("need -Jpath switch to import text file %s", name);
+ goto Lerror;
}
/* Be wary of CWE-22: Improper Limitation of a Pathname to a Restricted Directory
@@ -5308,23 +5308,23 @@ Expression *FileExp::semantic(Scope *sc)
name = FileName::safeSearchPath(global.filePath, name);
if (!name)
- { error("file %s cannot be found or not in a path specified with -J", se->toChars());
- goto Lerror;
+ { error("file %s cannot be found or not in a path specified with -J", se->toChars());
+ goto Lerror;
}
if (global.params.verbose)
- printf("file %s\t(%s)\n", (char *)se->string, name);
+ printf("file %s\t(%s)\n", (char *)se->string, name);
- { File f(name);
- if (f.read())
- { error("cannot read file %s", f.toChars());
- goto Lerror;
- }
- else
- {
- f.ref = 1;
- se = new StringExp(loc, f.buffer, f.len);
- }
+ { File f(name);
+ if (f.read())
+ { error("cannot read file %s", f.toChars());
+ goto Lerror;
+ }
+ else
+ {
+ f.ref = 1;
+ se = new StringExp(loc, f.buffer, f.len);
+ }
}
Lret:
return se->semantic(sc);
@@ -5344,7 +5344,7 @@ void FileExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
AssertExp::AssertExp(Loc loc, Expression *e, Expression *msg)
- : UnaExp(loc, TOKassert, sizeof(AssertExp), e)
+ : UnaExp(loc, TOKassert, sizeof(AssertExp), e)
{
this->msg = msg;
}
@@ -5352,7 +5352,7 @@ AssertExp::AssertExp(Loc loc, Expression *e, Expression *msg)
Expression *AssertExp::syntaxCopy()
{
AssertExp *ae = new AssertExp(loc, e1->syntaxCopy(),
- msg ? msg->syntaxCopy() : NULL);
+ msg ? msg->syntaxCopy() : NULL);
return ae;
}
@@ -5368,21 +5368,21 @@ Expression *AssertExp::semantic(Scope *sc)
e1 = e1->checkToBoolean();
if (msg)
{
- msg = msg->semantic(sc);
- msg = resolveProperties(sc, msg);
- msg = msg->implicitCastTo(sc, Type::tchar->arrayOf());
- msg = msg->optimize(WANTvalue);
+ msg = msg->semantic(sc);
+ msg = resolveProperties(sc, msg);
+ msg = msg->implicitCastTo(sc, Type::tchar->arrayOf());
+ msg = msg->optimize(WANTvalue);
}
if (e1->isBool(FALSE))
{
- FuncDeclaration *fd = sc->parent->isFuncDeclaration();
- fd->hasReturnExp |= 4;
+ FuncDeclaration *fd = sc->parent->isFuncDeclaration();
+ fd->hasReturnExp |= 4;
- if (!global.params.useAssert)
- { Expression *e = new HaltExp(loc);
- e = e->semantic(sc);
- return e;
- }
+ if (!global.params.useAssert)
+ { Expression *e = new HaltExp(loc);
+ e = e->semantic(sc);
+ return e;
+ }
}
type = Type::tvoid;
return this;
@@ -5409,8 +5409,8 @@ void AssertExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
expToCBuffer(buf, hgs, e1, PREC_assign);
if (msg)
{
- buf->writeByte(',');
- expToCBuffer(buf, hgs, msg, PREC_assign);
+ buf->writeByte(',');
+ expToCBuffer(buf, hgs, msg, PREC_assign);
}
buf->writeByte(')');
}
@@ -5418,7 +5418,7 @@ void AssertExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
DotIdExp::DotIdExp(Loc loc, Expression *e, Identifier *ident)
- : UnaExp(loc, TOKdot, sizeof(DotIdExp), e)
+ : UnaExp(loc, TOKdot, sizeof(DotIdExp), e)
{
this->ident = ident;
}
@@ -5440,10 +5440,10 @@ Expression *DotIdExp::semantic(Scope *sc)
* it to a string.
*/
if (ident == Id::stringof)
- { char *s = e1->toChars();
- e = new StringExp(loc, s, strlen(s), 'c');
- e = e->semantic(sc);
- return e;
+ { char *s = e1->toChars();
+ e = new StringExp(loc, s, strlen(s), 'c');
+ e = e->semantic(sc);
+ return e;
}
#endif
@@ -5452,294 +5452,294 @@ Expression *DotIdExp::semantic(Scope *sc)
* if we have no this pointer.
*/
if ((e1->op == TOKthis || e1->op == TOKsuper) && !hasThis(sc))
- { ClassDeclaration *cd;
- StructDeclaration *sd;
- AggregateDeclaration *ad;
+ { ClassDeclaration *cd;
+ StructDeclaration *sd;
+ AggregateDeclaration *ad;
- ad = sc->getStructClassScope();
- if (ad)
- {
- cd = ad->isClassDeclaration();
- if (cd)
- {
- if (e1->op == TOKthis)
- {
- e = typeDotIdExp(loc, cd->type, ident);
- return e->semantic(sc);
- }
- else if (cd->baseClass && e1->op == TOKsuper)
- {
- e = typeDotIdExp(loc, cd->baseClass->type, ident);
- return e->semantic(sc);
- }
- }
- else
- {
- sd = ad->isStructDeclaration();
- if (sd)
- {
- if (e1->op == TOKthis)
- {
- e = typeDotIdExp(loc, sd->type, ident);
- return e->semantic(sc);
- }
- }
- }
- }
+ ad = sc->getStructClassScope();
+ if (ad)
+ {
+ cd = ad->isClassDeclaration();
+ if (cd)
+ {
+ if (e1->op == TOKthis)
+ {
+ e = typeDotIdExp(loc, cd->type, ident);
+ return e->semantic(sc);
+ }
+ else if (cd->baseClass && e1->op == TOKsuper)
+ {
+ e = typeDotIdExp(loc, cd->baseClass->type, ident);
+ return e->semantic(sc);
+ }
+ }
+ else
+ {
+ sd = ad->isStructDeclaration();
+ if (sd)
+ {
+ if (e1->op == TOKthis)
+ {
+ e = typeDotIdExp(loc, sd->type, ident);
+ return e->semantic(sc);
+ }
+ }
+ }
+ }
}
UnaExp::semantic(sc);
if (e1->op == TOKdotexp)
{
- DotExp *de = (DotExp *)e1;
- eleft = de->e1;
- eright = de->e2;
+ DotExp *de = (DotExp *)e1;
+ eleft = de->e1;
+ eright = de->e2;
}
else
{
- e1 = resolveProperties(sc, e1);
- eleft = NULL;
- eright = e1;
+ e1 = resolveProperties(sc, e1);
+ eleft = NULL;
+ eright = e1;
}
#if DMDV2
if (e1->op == TOKtuple && ident == Id::offsetof)
- { /* 'distribute' the .offsetof to each of the tuple elements.
- */
- TupleExp *te = (TupleExp *)e1;
- Expressions *exps = new Expressions();
- exps->setDim(te->exps->dim);
- for (int i = 0; i < exps->dim; i++)
- { Expression *e = (Expression *)te->exps->data[i];
- e = e->semantic(sc);
- e = new DotIdExp(e->loc, e, Id::offsetof);
- exps->data[i] = (void *)e;
- }
- e = new TupleExp(loc, exps);
- e = e->semantic(sc);
- return e;
+ { /* 'distribute' the .offsetof to each of the tuple elements.
+ */
+ TupleExp *te = (TupleExp *)e1;
+ Expressions *exps = new Expressions();
+ exps->setDim(te->exps->dim);
+ for (int i = 0; i < exps->dim; i++)
+ { Expression *e = (Expression *)te->exps->data[i];
+ e = e->semantic(sc);
+ e = new DotIdExp(e->loc, e, Id::offsetof);
+ exps->data[i] = (void *)e;
+ }
+ e = new TupleExp(loc, exps);
+ e = e->semantic(sc);
+ return e;
}
#endif
if (e1->op == TOKtuple && ident == Id::length)
{
- TupleExp *te = (TupleExp *)e1;
- e = new IntegerExp(loc, te->exps->dim, Type::tsize_t);
- return e;
+ TupleExp *te = (TupleExp *)e1;
+ e = new IntegerExp(loc, te->exps->dim, Type::tsize_t);
+ return e;
}
if (e1->op == TOKdottd)
{
- error("template %s does not have property %s", e1->toChars(), ident->toChars());
- return e1;
+ error("template %s does not have property %s", e1->toChars(), ident->toChars());
+ return e1;
}
if (!e1->type)
{
- error("expression %s does not have property %s", e1->toChars(), ident->toChars());
- return e1;
+ error("expression %s does not have property %s", e1->toChars(), ident->toChars());
+ return e1;
}
- if (eright->op == TOKimport) // also used for template alias's
+ if (eright->op == TOKimport) // also used for template alias's
{
- ScopeExp *ie = (ScopeExp *)eright;
+ ScopeExp *ie = (ScopeExp *)eright;
- /* Disable access to another module's private imports.
- * The check for 'is sds our current module' is because
- * the current module should have access to its own imports.
- */
- Dsymbol *s = ie->sds->search(loc, ident,
- (ie->sds->isModule() && ie->sds != sc->module) ? 1 : 0);
- if (s)
- {
- s = s->toAlias();
- checkDeprecated(sc, s);
+ /* Disable access to another module's private imports.
+ * The check for 'is sds our current module' is because
+ * the current module should have access to its own imports.
+ */
+ Dsymbol *s = ie->sds->search(loc, ident,
+ (ie->sds->isModule() && ie->sds != sc->module) ? 1 : 0);
+ if (s)
+ {
+ s = s->toAlias();
+ checkDeprecated(sc, s);
- EnumMember *em = s->isEnumMember();
- if (em)
- {
- e = em->value;
- e = e->semantic(sc);
- return e;
- }
+ EnumMember *em = s->isEnumMember();
+ if (em)
+ {
+ e = em->value;
+ e = e->semantic(sc);
+ return e;
+ }
- VarDeclaration *v = s->isVarDeclaration();
- if (v)
- {
- //printf("DotIdExp:: Identifier '%s' is a variable, type '%s'\n", toChars(), v->type->toChars());
- if (v->inuse)
- {
- error("circular reference to '%s'", v->toChars());
- type = Type::tint32;
- return this;
- }
- type = v->type;
- if (v->isSameAsInitializer())
- {
- if (v->init)
- {
- ExpInitializer *ei = v->init->isExpInitializer();
- if (ei)
- {
+ VarDeclaration *v = s->isVarDeclaration();
+ if (v)
+ {
+ //printf("DotIdExp:: Identifier '%s' is a variable, type '%s'\n", toChars(), v->type->toChars());
+ if (v->inuse)
+ {
+ error("circular reference to '%s'", v->toChars());
+ type = Type::tint32;
+ return this;
+ }
+ type = v->type;
+ if (v->isSameAsInitializer())
+ {
+ if (v->init)
+ {
+ ExpInitializer *ei = v->init->isExpInitializer();
+ if (ei)
+ {
//printf("\tei: %p (%s)\n", ei->exp, ei->exp->toChars());
//ei->exp = ei->exp->semantic(sc);
- if (ei->exp->type == type)
- {
- e = ei->exp->copy(); // make copy so we can change loc
- e->loc = loc;
- return e;
- }
- }
- }
- else if (type->isscalar())
- {
- e = type->defaultInit();
- e->loc = loc;
- return e;
- }
- }
- if (v->needThis())
- {
- if (!eleft)
- eleft = new ThisExp(loc);
- e = new DotVarExp(loc, eleft, v);
- e = e->semantic(sc);
- }
- else
- {
- e = new VarExp(loc, v);
- if (eleft)
- { e = new CommaExp(loc, eleft, e);
- e->type = v->type;
- }
- }
- return e->deref();
- }
+ if (ei->exp->type == type)
+ {
+ e = ei->exp->copy(); // make copy so we can change loc
+ e->loc = loc;
+ return e;
+ }
+ }
+ }
+ else if (type->isscalar())
+ {
+ e = type->defaultInit();
+ e->loc = loc;
+ return e;
+ }
+ }
+ if (v->needThis())
+ {
+ if (!eleft)
+ eleft = new ThisExp(loc);
+ e = new DotVarExp(loc, eleft, v);
+ e = e->semantic(sc);
+ }
+ else
+ {
+ e = new VarExp(loc, v);
+ if (eleft)
+ { e = new CommaExp(loc, eleft, e);
+ e->type = v->type;
+ }
+ }
+ return e->deref();
+ }
- FuncDeclaration *f = s->isFuncDeclaration();
- if (f)
- {
- //printf("it's a function\n");
- if (f->needThis())
- {
- if (!eleft)
- eleft = new ThisExp(loc);
- e = new DotVarExp(loc, eleft, f);
- e = e->semantic(sc);
- }
- else
- {
- e = new VarExp(loc, f);
- if (eleft)
- { e = new CommaExp(loc, eleft, e);
- e->type = f->type;
- }
- }
- return e;
- }
+ FuncDeclaration *f = s->isFuncDeclaration();
+ if (f)
+ {
+ //printf("it's a function\n");
+ if (f->needThis())
+ {
+ if (!eleft)
+ eleft = new ThisExp(loc);
+ e = new DotVarExp(loc, eleft, f);
+ e = e->semantic(sc);
+ }
+ else
+ {
+ e = new VarExp(loc, f);
+ if (eleft)
+ { e = new CommaExp(loc, eleft, e);
+ e->type = f->type;
+ }
+ }
+ return e;
+ }
#if DMDV2
- OverloadSet *o = s->isOverloadSet();
- if (o)
- { //printf("'%s' is an overload set\n", o->toChars());
- return new OverExp(o);
- }
+ OverloadSet *o = s->isOverloadSet();
+ if (o)
+ { //printf("'%s' is an overload set\n", o->toChars());
+ return new OverExp(o);
+ }
#endif
- Type *t = s->getType();
- if (t)
- {
- return new TypeExp(loc, t);
- }
+ Type *t = s->getType();
+ if (t)
+ {
+ return new TypeExp(loc, t);
+ }
- TupleDeclaration *tup = s->isTupleDeclaration();
- if (tup)
- {
- if (eleft)
- error("cannot have e.tuple");
- e = new TupleExp(loc, tup);
- e = e->semantic(sc);
- return e;
- }
+ TupleDeclaration *tup = s->isTupleDeclaration();
+ if (tup)
+ {
+ if (eleft)
+ error("cannot have e.tuple");
+ e = new TupleExp(loc, tup);
+ e = e->semantic(sc);
+ return e;
+ }
- ScopeDsymbol *sds = s->isScopeDsymbol();
- if (sds)
- {
- //printf("it's a ScopeDsymbol\n");
- e = new ScopeExp(loc, sds);
- e = e->semantic(sc);
- if (eleft)
- e = new DotExp(loc, eleft, e);
- return e;
- }
+ ScopeDsymbol *sds = s->isScopeDsymbol();
+ if (sds)
+ {
+ //printf("it's a ScopeDsymbol\n");
+ e = new ScopeExp(loc, sds);
+ e = e->semantic(sc);
+ if (eleft)
+ e = new DotExp(loc, eleft, e);
+ return e;
+ }
- Import *imp = s->isImport();
- if (imp)
- {
- ScopeExp *ie;
+ Import *imp = s->isImport();
+ if (imp)
+ {
+ ScopeExp *ie;
- ie = new ScopeExp(loc, imp->pkg);
- return ie->semantic(sc);
- }
+ ie = new ScopeExp(loc, imp->pkg);
+ return ie->semantic(sc);
+ }
- // BUG: handle other cases like in IdentifierExp::semantic()
+ // BUG: handle other cases like in IdentifierExp::semantic()
#ifdef DEBUG
- printf("s = '%s', kind = '%s'\n", s->toChars(), s->kind());
+ printf("s = '%s', kind = '%s'\n", s->toChars(), s->kind());
#endif
- assert(0);
- }
- else if (ident == Id::stringof)
- { char *s = ie->toChars();
- e = new StringExp(loc, s, strlen(s), 'c');
- e = e->semantic(sc);
- return e;
- }
- error("undefined identifier %s", toChars());
- type = Type::tvoid;
- return this;
+ assert(0);
+ }
+ else if (ident == Id::stringof)
+ { char *s = ie->toChars();
+ e = new StringExp(loc, s, strlen(s), 'c');
+ e = e->semantic(sc);
+ return e;
+ }
+ error("undefined identifier %s", toChars());
+ type = Type::tvoid;
+ return this;
}
else if (e1->type->ty == Tpointer &&
- ident != Id::init && ident != Id::__sizeof &&
- ident != Id::alignof && ident != Id::offsetof &&
- ident != Id::mangleof && ident != Id::stringof)
- { /* Rewrite:
+ ident != Id::init && ident != Id::__sizeof &&
+ ident != Id::alignof && ident != Id::offsetof &&
+ ident != Id::mangleof && ident != Id::stringof)
+ { /* Rewrite:
* p.ident
* as:
* (*p).ident
*/
- e = new PtrExp(loc, e1);
- e->type = ((TypePointer *)e1->type)->next;
- return e->type->dotExp(sc, e, ident);
+ e = new PtrExp(loc, e1);
+ e->type = ((TypePointer *)e1->type)->next;
+ return e->type->dotExp(sc, e, ident);
}
#if DMDV2
else if (t1b->ty == Tarray ||
t1b->ty == Tsarray ||
- t1b->ty == Taarray)
- { /* If ident is not a valid property, rewrite:
- * e1.ident
+ t1b->ty == Taarray)
+ { /* If ident is not a valid property, rewrite:
+ * e1.ident
* as:
* .ident(e1)
*/
- unsigned errors = global.errors;
- global.gag++;
- Type *t1 = e1->type;
- e = e1->type->dotExp(sc, e1, ident);
- global.gag--;
- if (errors != global.errors) // if failed to find the property
- {
- global.errors = errors;
- e1->type = t1; // kludge to restore type
- e = new DotIdExp(loc, new IdentifierExp(loc, Id::empty), ident);
- e = new CallExp(loc, e, e1);
- }
- e = e->semantic(sc);
- return e;
+ unsigned errors = global.errors;
+ global.gag++;
+ Type *t1 = e1->type;
+ e = e1->type->dotExp(sc, e1, ident);
+ global.gag--;
+ if (errors != global.errors) // if failed to find the property
+ {
+ global.errors = errors;
+ e1->type = t1; // kludge to restore type
+ e = new DotIdExp(loc, new IdentifierExp(loc, Id::empty), ident);
+ e = new CallExp(loc, e, e1);
+ }
+ e = e->semantic(sc);
+ return e;
}
#endif
else
{
- e = e1->type->dotExp(sc, e1, ident);
- e = e->semantic(sc);
- return e;
+ e = e1->type->dotExp(sc, e1, ident);
+ e = e->semantic(sc);
+ return e;
}
}
@@ -5756,8 +5756,8 @@ void DotIdExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
// Mainly just a placeholder
DotTemplateExp::DotTemplateExp(Loc loc, Expression *e, TemplateDeclaration *td)
- : UnaExp(loc, TOKdottd, sizeof(DotTemplateExp), e)
-
+ : UnaExp(loc, TOKdottd, sizeof(DotTemplateExp), e)
+
{
this->td = td;
}
@@ -5773,7 +5773,7 @@ void DotTemplateExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
DotVarExp::DotVarExp(Loc loc, Expression *e, Declaration *v)
- : UnaExp(loc, TOKdotvar, sizeof(DotVarExp), e)
+ : UnaExp(loc, TOKdotvar, sizeof(DotVarExp), e)
{
//printf("DotVarExp()\n");
this->var = v;
@@ -5786,76 +5786,76 @@ Expression *DotVarExp::semantic(Scope *sc)
#endif
if (!type)
{
- var = var->toAlias()->isDeclaration();
+ var = var->toAlias()->isDeclaration();
- TupleDeclaration *tup = var->isTupleDeclaration();
- if (tup)
- { /* Replace:
- * e1.tuple(a, b, c)
- * with:
- * tuple(e1.a, e1.b, e1.c)
- */
- Expressions *exps = new Expressions;
+ TupleDeclaration *tup = var->isTupleDeclaration();
+ if (tup)
+ { /* Replace:
+ * e1.tuple(a, b, c)
+ * with:
+ * tuple(e1.a, e1.b, e1.c)
+ */
+ Expressions *exps = new Expressions;
- exps->reserve(tup->objects->dim);
- for (size_t i = 0; i < tup->objects->dim; i++)
- { Object *o = (Object *)tup->objects->data[i];
- if (o->dyncast() != DYNCAST_EXPRESSION)
- {
- error("%s is not an expression", o->toChars());
- }
- else
- {
- Expression *e = (Expression *)o;
- if (e->op != TOKdsymbol)
- error("%s is not a member", e->toChars());
- else
- { DsymbolExp *ve = (DsymbolExp *)e;
+ exps->reserve(tup->objects->dim);
+ for (size_t i = 0; i < tup->objects->dim; i++)
+ { Object *o = (Object *)tup->objects->data[i];
+ if (o->dyncast() != DYNCAST_EXPRESSION)
+ {
+ error("%s is not an expression", o->toChars());
+ }
+ else
+ {
+ Expression *e = (Expression *)o;
+ if (e->op != TOKdsymbol)
+ error("%s is not a member", e->toChars());
+ else
+ { DsymbolExp *ve = (DsymbolExp *)e;
- e = new DotVarExp(loc, e1, ve->s->isDeclaration());
- exps->push(e);
- }
- }
- }
- Expression *e = new TupleExp(loc, exps);
- e = e->semantic(sc);
- return e;
- }
+ e = new DotVarExp(loc, e1, ve->s->isDeclaration());
+ exps->push(e);
+ }
+ }
+ }
+ Expression *e = new TupleExp(loc, exps);
+ e = e->semantic(sc);
+ return e;
+ }
- e1 = e1->semantic(sc);
- type = var->type;
- if (!type && global.errors)
- { // var is goofed up, just return 0
- return new ErrorExp();
- }
- assert(type);
+ e1 = e1->semantic(sc);
+ type = var->type;
+ if (!type && global.errors)
+ { // var is goofed up, just return 0
+ return new ErrorExp();
+ }
+ assert(type);
- if (!var->isFuncDeclaration()) // for functions, do checks after overload resolution
- {
- Dsymbol *vparent = var->toParent();
- AggregateDeclaration *ad = vparent ? vparent->isAggregateDeclaration() : NULL;
- e1 = getRightThis(loc, sc, ad, e1, var);
- if (!sc->noaccesscheck)
- accessCheck(loc, sc, e1, var);
+ if (!var->isFuncDeclaration()) // for functions, do checks after overload resolution
+ {
+ Dsymbol *vparent = var->toParent();
+ AggregateDeclaration *ad = vparent ? vparent->isAggregateDeclaration() : NULL;
+ e1 = getRightThis(loc, sc, ad, e1, var);
+ if (!sc->noaccesscheck)
+ accessCheck(loc, sc, e1, var);
- VarDeclaration *v = var->isVarDeclaration();
- if (v && v->isSameAsInitializer())
- { ExpInitializer *ei = v->getExpInitializer();
- if (ei)
- { Expression *e = ei->exp->copy();
- e = e->semantic(sc);
- return e;
- }
- if (v->init)
- { Expression *e = v->init->toExpression();
- if (e)
- { e = e->copy();
- e = e->semantic(sc);
- return e;
- }
- }
- }
- }
+ VarDeclaration *v = var->isVarDeclaration();
+ if (v && v->isSameAsInitializer())
+ { ExpInitializer *ei = v->getExpInitializer();
+ if (ei)
+ { Expression *e = ei->exp->copy();
+ e = e->semantic(sc);
+ return e;
+ }
+ if (v->init)
+ { Expression *e = v->init->toExpression();
+ if (e)
+ { e = e->copy();
+ e = e->semantic(sc);
+ return e;
+ }
+ }
+ }
+ }
}
//printf("-DotVarExp::semantic('%s')\n", toChars());
return this;
@@ -5883,53 +5883,53 @@ Expression *DotVarExp::modifiableLvalue(Scope *sc, Expression *e)
#endif
if (var->isCtorinit())
- { // It's only modifiable if inside the right constructor
- Dsymbol *s = sc->func;
- while (1)
- {
- FuncDeclaration *fd = NULL;
- if (s)
- fd = s->isFuncDeclaration();
- if (fd &&
- ((fd->isCtorDeclaration() && var->storage_class & STCfield) ||
- (fd->isStaticCtorDeclaration() && !(var->storage_class & STCfield))) &&
- fd->toParent() == var->toParent() &&
- e1->op == TOKthis
- )
- {
- VarDeclaration *v = var->isVarDeclaration();
- assert(v);
- v->ctorinit = 1;
- //printf("setting ctorinit\n");
- }
- else
- {
- if (s)
- { s = s->toParent2();
- continue;
- }
- else
- {
- const char *p = var->isStatic() ? "static " : "";
- error("can only initialize %sconst member %s inside %sconstructor",
- p, var->toChars(), p);
- }
- }
- break;
- }
+ { // It's only modifiable if inside the right constructor
+ Dsymbol *s = sc->func;
+ while (1)
+ {
+ FuncDeclaration *fd = NULL;
+ if (s)
+ fd = s->isFuncDeclaration();
+ if (fd &&
+ ((fd->isCtorDeclaration() && var->storage_class & STCfield) ||
+ (fd->isStaticCtorDeclaration() && !(var->storage_class & STCfield))) &&
+ fd->toParent() == var->toParent() &&
+ e1->op == TOKthis
+ )
+ {
+ VarDeclaration *v = var->isVarDeclaration();
+ assert(v);
+ v->ctorinit = 1;
+ //printf("setting ctorinit\n");
+ }
+ else
+ {
+ if (s)
+ { s = s->toParent2();
+ continue;
+ }
+ else
+ {
+ const char *p = var->isStatic() ? "static " : "";
+ error("can only initialize %sconst member %s inside %sconstructor",
+ p, var->toChars(), p);
+ }
+ }
+ break;
+ }
}
#if DMDV2
else
{
- Type *t1 = e1->type->toBasetype();
+ Type *t1 = e1->type->toBasetype();
- if (!t1->isMutable() ||
- (t1->ty == Tpointer && !t1->nextOf()->isMutable()) ||
- !var->type->isMutable() ||
- !var->type->isAssignable() ||
- var->storage_class & STCmanifest
- )
- error("cannot modify const/immutable expression %s", toChars());
+ if (!t1->isMutable() ||
+ (t1->ty == Tpointer && !t1->nextOf()->isMutable()) ||
+ !var->type->isMutable() ||
+ !var->type->isAssignable() ||
+ var->storage_class & STCmanifest
+ )
+ error("cannot modify const/immutable expression %s", toChars());
}
#endif
return this;
@@ -5945,11 +5945,11 @@ void DotVarExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
/* Things like:
- * foo.bar!(args)
+ * foo.bar!(args)
*/
DotTemplateInstanceExp::DotTemplateInstanceExp(Loc loc, Expression *e, TemplateInstance *ti)
- : UnaExp(loc, TOKdotti, sizeof(DotTemplateInstanceExp), e)
+ : UnaExp(loc, TOKdotti, sizeof(DotTemplateInstanceExp), e)
{
//printf("DotTemplateInstanceExp()\n");
this->ti = ti;
@@ -5958,8 +5958,8 @@ DotTemplateInstanceExp::DotTemplateInstanceExp(Loc loc, Expression *e, TemplateI
Expression *DotTemplateInstanceExp::syntaxCopy()
{
DotTemplateInstanceExp *de = new DotTemplateInstanceExp(loc,
- e1->syntaxCopy(),
- (TemplateInstance *)ti->syntaxCopy(NULL));
+ e1->syntaxCopy(),
+ (TemplateInstance *)ti->syntaxCopy(NULL));
return de;
}
@@ -5975,54 +5975,54 @@ L1:
e = e->semantic(sc);
if (e->op == TOKdottd)
{
- if (global.errors)
- return new ErrorExp(); // TemplateInstance::semantic() will fail anyway
- DotTemplateExp *dte = (DotTemplateExp *)e;
- TemplateDeclaration *td = dte->td;
- eleft = dte->e1;
- ti->tempdecl = td;
- ti->semantic(sc);
- if (!ti->inst) // if template failed to expand
- return new ErrorExp();
- Dsymbol *s = ti->inst->toAlias();
- Declaration *v = s->isDeclaration();
- if (v)
- { e = new DotVarExp(loc, eleft, v);
- e = e->semantic(sc);
- return e;
- }
- e = new ScopeExp(loc, ti);
- e = new DotExp(loc, eleft, e);
- e = e->semantic(sc);
- return e;
+ if (global.errors)
+ return new ErrorExp(); // TemplateInstance::semantic() will fail anyway
+ DotTemplateExp *dte = (DotTemplateExp *)e;
+ TemplateDeclaration *td = dte->td;
+ eleft = dte->e1;
+ ti->tempdecl = td;
+ ti->semantic(sc);
+ if (!ti->inst) // if template failed to expand
+ return new ErrorExp();
+ Dsymbol *s = ti->inst->toAlias();
+ Declaration *v = s->isDeclaration();
+ if (v)
+ { e = new DotVarExp(loc, eleft, v);
+ e = e->semantic(sc);
+ return e;
+ }
+ e = new ScopeExp(loc, ti);
+ e = new DotExp(loc, eleft, e);
+ e = e->semantic(sc);
+ return e;
}
else if (e->op == TOKimport)
{ ScopeExp *se = (ScopeExp *)e;
- TemplateDeclaration *td = se->sds->isTemplateDeclaration();
- if (!td)
- { error("%s is not a template", e->toChars());
- return new ErrorExp();
- }
- ti->tempdecl = td;
- e = new ScopeExp(loc, ti);
- e = e->semantic(sc);
- return e;
+ TemplateDeclaration *td = se->sds->isTemplateDeclaration();
+ if (!td)
+ { error("%s is not a template", e->toChars());
+ return new ErrorExp();
+ }
+ ti->tempdecl = td;
+ e = new ScopeExp(loc, ti);
+ e = e->semantic(sc);
+ return e;
}
else if (e->op == TOKdotexp)
- { DotExp *de = (DotExp *)e;
+ { DotExp *de = (DotExp *)e;
if (de->e2->op == TOKimport)
{ // This should *really* be moved to ScopeExp::semantic()
- ScopeExp *se = (ScopeExp *)de->e2;
- de->e2 = new DsymbolExp(loc, se->sds);
- de->e2 = de->e2->semantic(sc);
+ ScopeExp *se = (ScopeExp *)de->e2;
+ de->e2 = new DsymbolExp(loc, se->sds);
+ de->e2 = de->e2->semantic(sc);
}
if (de->e2->op == TOKtemplate)
{ TemplateExp *te = (TemplateExp *) de->e2;
- e = new DotTemplateExp(loc,de->e1,te->td);
+ e = new DotTemplateExp(loc,de->e1,te->td);
}
- goto L1;
+ goto L1;
}
error("%s isn't a template", e->toChars());
return new ErrorExp();
@@ -6044,55 +6044,55 @@ L1:
e1 = e1->semantic(sc);
t1 = e1->type;
if (t1)
- t1 = t1->toBasetype();
+ t1 = t1->toBasetype();
//t1->print();
/* Extract the following from e1:
- * s: the symbol which ti should be a member of
- * eleft: if not NULL, it is the 'this' pointer for ti
+ * s: the symbol which ti should be a member of
+ * eleft: if not NULL, it is the 'this' pointer for ti
*/
if (e1->op == TOKdotexp)
- { DotExp *de = (DotExp *)e1;
- eleft = de->e1;
- eright = de->e2;
+ { DotExp *de = (DotExp *)e1;
+ eleft = de->e1;
+ eright = de->e2;
}
else
- { eleft = NULL;
- eright = e1;
+ { eleft = NULL;
+ eright = e1;
}
if (eright->op == TOKimport)
{
- s = ((ScopeExp *)eright)->sds;
+ s = ((ScopeExp *)eright)->sds;
}
else if (e1->op == TOKtype)
{
- s = t1->isClassHandle();
- if (!s)
- { if (t1->ty == Tstruct)
- s = ((TypeStruct *)t1)->sym;
- else
- goto L1;
- }
+ s = t1->isClassHandle();
+ if (!s)
+ { if (t1->ty == Tstruct)
+ s = ((TypeStruct *)t1)->sym;
+ else
+ goto L1;
+ }
}
else if (t1 && (t1->ty == Tstruct || t1->ty == Tclass))
{
- s = t1->toDsymbol(sc);
- eleft = e1;
+ s = t1->toDsymbol(sc);
+ eleft = e1;
}
else if (t1 && t1->ty == Tpointer)
{
- t1 = ((TypePointer *)t1)->next->toBasetype();
- if (t1->ty != Tstruct)
- goto L1;
- s = t1->toDsymbol(sc);
- eleft = e1;
+ t1 = ((TypePointer *)t1)->next->toBasetype();
+ if (t1->ty != Tstruct)
+ goto L1;
+ s = t1->toDsymbol(sc);
+ eleft = e1;
}
else
{
L1:
- error("template %s is not a member of %s", ti->toChars(), e1->toChars());
- goto Lerr;
+ error("template %s is not a member of %s", ti->toChars(), e1->toChars());
+ goto Lerr;
}
assert(s);
@@ -6100,11 +6100,11 @@ L1:
s2 = s->search(loc, id, 0);
if (!s2)
{
- if (!s->ident)
- error("template identifier %s is not a member of undefined %s", id->toChars(), s->kind());
- else
- error("template identifier %s is not a member of %s %s", id->toChars(), s->kind(), s->ident->toChars());
- goto Lerr;
+ if (!s->ident)
+ error("template identifier %s is not a member of undefined %s", id->toChars(), s->kind());
+ else
+ error("template identifier %s is not a member of %s %s", id->toChars(), s->kind(), s->ident->toChars());
+ goto Lerr;
}
s = s2;
s->semantic(sc);
@@ -6112,31 +6112,31 @@ L1:
td = s->isTemplateDeclaration();
if (!td)
{
- error("%s is not a template", id->toChars());
- goto Lerr;
+ error("%s is not a template", id->toChars());
+ goto Lerr;
}
if (global.errors)
- goto Lerr;
+ goto Lerr;
ti->tempdecl = td;
if (eleft)
- { Declaration *v;
+ { Declaration *v;
- ti->semantic(sc);
- s = ti->inst->toAlias();
- v = s->isDeclaration();
- if (v)
- { e = new DotVarExp(loc, eleft, v);
- e = e->semantic(sc);
- return e;
- }
+ ti->semantic(sc);
+ s = ti->inst->toAlias();
+ v = s->isDeclaration();
+ if (v)
+ { e = new DotVarExp(loc, eleft, v);
+ e = e->semantic(sc);
+ return e;
+ }
}
e = new ScopeExp(loc, ti);
if (eleft)
{
- e = new DotExp(loc, eleft, e);
+ e = new DotExp(loc, eleft, e);
}
e = e->semantic(sc);
return e;
@@ -6156,7 +6156,7 @@ void DotTemplateInstanceExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
DelegateExp::DelegateExp(Loc loc, Expression *e, FuncDeclaration *f)
- : UnaExp(loc, TOKdelegate, sizeof(DelegateExp), e)
+ : UnaExp(loc, TOKdelegate, sizeof(DelegateExp), e)
{
this->func = f;
m = NULL;
@@ -6169,14 +6169,14 @@ Expression *DelegateExp::semantic(Scope *sc)
#endif
if (!type)
{
- m = sc->module;
- e1 = e1->semantic(sc);
+ m = sc->module;
+ e1 = e1->semantic(sc);
// LDC we need a copy as we store the LLVM tpye in TypeFunction, and delegate/members have different types for 'this'
- type = new TypeDelegate(func->type->syntaxCopy());
- type = type->semantic(loc, sc);
- AggregateDeclaration *ad = func->toParent()->isAggregateDeclaration();
- if (func->needThis())
- e1 = getRightThis(loc, sc, ad, e1, func);
+ type = new TypeDelegate(func->type->syntaxCopy());
+ type = type->semantic(loc, sc);
+ AggregateDeclaration *ad = func->toParent()->isAggregateDeclaration();
+ if (func->needThis())
+ e1 = getRightThis(loc, sc, ad, e1, func);
}
return this;
}
@@ -6186,8 +6186,8 @@ void DelegateExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writeByte('&');
if (!func->isNested())
{
- expToCBuffer(buf, hgs, e1, PREC_primary);
- buf->writeByte('.');
+ expToCBuffer(buf, hgs, e1, PREC_primary);
+ buf->writeByte('.');
}
buf->writestring(func->toChars());
}
@@ -6195,7 +6195,7 @@ void DelegateExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
DotTypeExp::DotTypeExp(Loc loc, Expression *e, Dsymbol *s)
- : UnaExp(loc, TOKdottype, sizeof(DotTypeExp), e)
+ : UnaExp(loc, TOKdottype, sizeof(DotTypeExp), e)
{
this->sym = s;
this->type = s->getType();
@@ -6220,30 +6220,30 @@ void DotTypeExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
CallExp::CallExp(Loc loc, Expression *e, Expressions *exps)
- : UnaExp(loc, TOKcall, sizeof(CallExp), e)
+ : UnaExp(loc, TOKcall, sizeof(CallExp), e)
{
this->arguments = exps;
}
CallExp::CallExp(Loc loc, Expression *e)
- : UnaExp(loc, TOKcall, sizeof(CallExp), e)
+ : UnaExp(loc, TOKcall, sizeof(CallExp), e)
{
this->arguments = NULL;
}
CallExp::CallExp(Loc loc, Expression *e, Expression *earg1)
- : UnaExp(loc, TOKcall, sizeof(CallExp), e)
+ : UnaExp(loc, TOKcall, sizeof(CallExp), e)
{
Expressions *arguments = new Expressions();
if (earg1)
- { arguments->setDim(1);
- arguments->data[0] = (void *)earg1;
+ { arguments->setDim(1);
+ arguments->data[0] = (void *)earg1;
}
this->arguments = arguments;
}
CallExp::CallExp(Loc loc, Expression *e, Expression *earg1, Expression *earg2)
- : UnaExp(loc, TOKcall, sizeof(CallExp), e)
+ : UnaExp(loc, TOKcall, sizeof(CallExp), e)
{
Expressions *arguments = new Expressions();
arguments->setDim(2);
@@ -6266,128 +6266,128 @@ Expression *CallExp::semantic(Scope *sc)
int i;
Type *t1;
int istemp;
- Objects *targsi = NULL; // initial list of template arguments
+ Objects *targsi = NULL; // initial list of template arguments
#if LOGSEMANTIC
printf("CallExp::semantic() %s\n", toChars());
#endif
if (type)
- return this; // semantic() already run
+ return this; // semantic() already run
#if 0
if (arguments && arguments->dim)
{
- Expression *earg = (Expression *)arguments->data[0];
- earg->print();
- if (earg->type) earg->type->print();
+ Expression *earg = (Expression *)arguments->data[0];
+ earg->print();
+ if (earg->type) earg->type->print();
}
#endif
if (e1->op == TOKdelegate)
- { DelegateExp *de = (DelegateExp *)e1;
+ { DelegateExp *de = (DelegateExp *)e1;
- e1 = new DotVarExp(de->loc, de->e1, de->func);
- return semantic(sc);
+ e1 = new DotVarExp(de->loc, de->e1, de->func);
+ return semantic(sc);
}
/* Transform:
- * array.id(args) into id(array,args)
- * aa.remove(arg) into delete aa[arg]
+ * array.id(args) into id(array,args)
+ * aa.remove(arg) into delete aa[arg]
*/
if (e1->op == TOKdot)
{
- // BUG: we should handle array.a.b.c.e(args) too
+ // BUG: we should handle array.a.b.c.e(args) too
- DotIdExp *dotid = (DotIdExp *)(e1);
- dotid->e1 = dotid->e1->semantic(sc);
- assert(dotid->e1);
- if (dotid->e1->type)
- {
- TY e1ty = dotid->e1->type->toBasetype()->ty;
- if (e1ty == Taarray && dotid->ident == Id::remove)
- {
- if (!arguments || arguments->dim != 1)
- { error("expected key as argument to aa.remove()");
- goto Lagain;
- }
- Expression *key = (Expression *)arguments->data[0];
- key = key->semantic(sc);
- key = resolveProperties(sc, key);
- key->rvalue();
+ DotIdExp *dotid = (DotIdExp *)(e1);
+ dotid->e1 = dotid->e1->semantic(sc);
+ assert(dotid->e1);
+ if (dotid->e1->type)
+ {
+ TY e1ty = dotid->e1->type->toBasetype()->ty;
+ if (e1ty == Taarray && dotid->ident == Id::remove)
+ {
+ if (!arguments || arguments->dim != 1)
+ { error("expected key as argument to aa.remove()");
+ goto Lagain;
+ }
+ Expression *key = (Expression *)arguments->data[0];
+ key = key->semantic(sc);
+ key = resolveProperties(sc, key);
+ key->rvalue();
- TypeAArray *taa = (TypeAArray *)dotid->e1->type->toBasetype();
- key = key->implicitCastTo(sc, taa->index);
- key = key->implicitCastTo(sc, taa->key);
+ TypeAArray *taa = (TypeAArray *)dotid->e1->type->toBasetype();
+ key = key->implicitCastTo(sc, taa->index);
+ key = key->implicitCastTo(sc, taa->key);
- return new RemoveExp(loc, dotid->e1, key);
- }
- else if (e1ty == Tarray || e1ty == Tsarray || e1ty == Taarray)
- {
- if (!arguments)
- arguments = new Expressions();
- arguments->shift(dotid->e1);
+ return new RemoveExp(loc, dotid->e1, key);
+ }
+ else if (e1ty == Tarray || e1ty == Tsarray || e1ty == Taarray)
+ {
+ if (!arguments)
+ arguments = new Expressions();
+ arguments->shift(dotid->e1);
#if DMDV2
- e1 = new DotIdExp(dotid->loc, new IdentifierExp(dotid->loc, Id::empty), dotid->ident);
+ e1 = new DotIdExp(dotid->loc, new IdentifierExp(dotid->loc, Id::empty), dotid->ident);
#else
- e1 = new IdentifierExp(dotid->loc, dotid->ident);
+ e1 = new IdentifierExp(dotid->loc, dotid->ident);
#endif
- }
- }
+ }
+ }
}
#if 1
/* This recognizes:
- * foo!(tiargs)(funcargs)
+ * foo!(tiargs)(funcargs)
*/
if (e1->op == TOKimport && !e1->type)
- { ScopeExp *se = (ScopeExp *)e1;
- TemplateInstance *ti = se->sds->isTemplateInstance();
- if (ti && !ti->semanticRun)
- {
- /* Attempt to instantiate ti. If that works, go with it.
- * If not, go with partial explicit specialization.
- */
- ti->semanticTiargs(sc);
- unsigned errors = global.errors;
- global.gag++;
- ti->semantic(sc);
- global.gag--;
- if (errors != global.errors)
- {
- /* Didn't work, go with partial explicit specialization
- */
- global.errors = errors;
- targsi = ti->tiargs;
- e1 = new IdentifierExp(loc, ti->name);
- }
- }
+ { ScopeExp *se = (ScopeExp *)e1;
+ TemplateInstance *ti = se->sds->isTemplateInstance();
+ if (ti && !ti->semanticRun)
+ {
+ /* Attempt to instantiate ti. If that works, go with it.
+ * If not, go with partial explicit specialization.
+ */
+ ti->semanticTiargs(sc);
+ unsigned errors = global.errors;
+ global.gag++;
+ ti->semantic(sc);
+ global.gag--;
+ if (errors != global.errors)
+ {
+ /* Didn't work, go with partial explicit specialization
+ */
+ global.errors = errors;
+ targsi = ti->tiargs;
+ e1 = new IdentifierExp(loc, ti->name);
+ }
+ }
}
/* This recognizes:
- * expr.foo!(tiargs)(funcargs)
+ * expr.foo!(tiargs)(funcargs)
*/
if (e1->op == TOKdotti && !e1->type)
- { DotTemplateInstanceExp *se = (DotTemplateInstanceExp *)e1;
- TemplateInstance *ti = se->ti;
- if (!ti->semanticRun)
- {
- /* Attempt to instantiate ti. If that works, go with it.
- * If not, go with partial explicit specialization.
- */
- ti->semanticTiargs(sc);
- Expression *etmp;
- unsigned errors = global.errors;
- global.gag++;
- etmp = e1->semantic(sc);
- global.gag--;
- if (errors != global.errors)
- {
- global.errors = errors;
- targsi = ti->tiargs;
- e1 = new DotIdExp(loc, se->e1, ti->name);
- }
- else
- e1 = etmp;
- }
+ { DotTemplateInstanceExp *se = (DotTemplateInstanceExp *)e1;
+ TemplateInstance *ti = se->ti;
+ if (!ti->semanticRun)
+ {
+ /* Attempt to instantiate ti. If that works, go with it.
+ * If not, go with partial explicit specialization.
+ */
+ ti->semanticTiargs(sc);
+ Expression *etmp;
+ unsigned errors = global.errors;
+ global.gag++;
+ etmp = e1->semantic(sc);
+ global.gag--;
+ if (errors != global.errors)
+ {
+ global.errors = errors;
+ targsi = ti->tiargs;
+ e1 = new DotIdExp(loc, se->e1, ti->name);
+ }
+ else
+ e1 = etmp;
+ }
}
#endif
@@ -6397,126 +6397,126 @@ Lagain:
f = NULL;
if (e1->op == TOKthis || e1->op == TOKsuper)
{
- // semantic() run later for these
+ // semantic() run later for these
}
else
{
- UnaExp::semantic(sc);
+ UnaExp::semantic(sc);
- /* Look for e1 being a lazy parameter
- */
- if (e1->op == TOKvar)
- { VarExp *ve = (VarExp *)e1;
+ /* Look for e1 being a lazy parameter
+ */
+ if (e1->op == TOKvar)
+ { VarExp *ve = (VarExp *)e1;
- if (ve->var->storage_class & STClazy)
- {
- TypeFunction *tf = new TypeFunction(NULL, ve->var->type, 0, LINKd);
- TypeDelegate *t = new TypeDelegate(tf);
- ve->type = t->semantic(loc, sc);
- }
- }
+ if (ve->var->storage_class & STClazy)
+ {
+ TypeFunction *tf = new TypeFunction(NULL, ve->var->type, 0, LINKd);
+ TypeDelegate *t = new TypeDelegate(tf);
+ ve->type = t->semantic(loc, sc);
+ }
+ }
- if (e1->op == TOKimport)
- { // Perhaps this should be moved to ScopeExp::semantic()
- ScopeExp *se = (ScopeExp *)e1;
- e1 = new DsymbolExp(loc, se->sds);
- e1 = e1->semantic(sc);
- }
-#if 1 // patch for #540 by Oskar Linde
- else if (e1->op == TOKdotexp)
- {
- DotExp *de = (DotExp *) e1;
+ if (e1->op == TOKimport)
+ { // Perhaps this should be moved to ScopeExp::semantic()
+ ScopeExp *se = (ScopeExp *)e1;
+ e1 = new DsymbolExp(loc, se->sds);
+ e1 = e1->semantic(sc);
+ }
+#if 1 // patch for #540 by Oskar Linde
+ else if (e1->op == TOKdotexp)
+ {
+ DotExp *de = (DotExp *) e1;
- if (de->e2->op == TOKimport)
- { // This should *really* be moved to ScopeExp::semantic()
- ScopeExp *se = (ScopeExp *)de->e2;
- de->e2 = new DsymbolExp(loc, se->sds);
- de->e2 = de->e2->semantic(sc);
- }
+ if (de->e2->op == TOKimport)
+ { // This should *really* be moved to ScopeExp::semantic()
+ ScopeExp *se = (ScopeExp *)de->e2;
+ de->e2 = new DsymbolExp(loc, se->sds);
+ de->e2 = de->e2->semantic(sc);
+ }
- if (de->e2->op == TOKtemplate)
- { TemplateExp *te = (TemplateExp *) de->e2;
- e1 = new DotTemplateExp(loc,de->e1,te->td);
- }
- }
+ if (de->e2->op == TOKtemplate)
+ { TemplateExp *te = (TemplateExp *) de->e2;
+ e1 = new DotTemplateExp(loc,de->e1,te->td);
+ }
+ }
#endif
}
if (e1->op == TOKcomma)
{
- CommaExp *ce = (CommaExp *)e1;
+ CommaExp *ce = (CommaExp *)e1;
- e1 = ce->e2;
- e1->type = ce->type;
- ce->e2 = this;
- ce->type = NULL;
- return ce->semantic(sc);
+ e1 = ce->e2;
+ e1->type = ce->type;
+ ce->e2 = this;
+ ce->type = NULL;
+ return ce->semantic(sc);
}
t1 = NULL;
if (e1->type)
- t1 = e1->type->toBasetype();
+ t1 = e1->type->toBasetype();
// Check for call operator overload
if (t1)
- { AggregateDeclaration *ad;
+ { AggregateDeclaration *ad;
- if (t1->ty == Tstruct)
- {
- ad = ((TypeStruct *)t1)->sym;
+ if (t1->ty == Tstruct)
+ {
+ ad = ((TypeStruct *)t1)->sym;
#if DMDV2
- // First look for constructor
- if (ad->ctor && arguments && arguments->dim)
- {
- // Create variable that will get constructed
- Identifier *idtmp = Lexer::uniqueId("__ctmp");
- VarDeclaration *tmp = new VarDeclaration(loc, t1, idtmp, NULL);
- Expression *av = new DeclarationExp(loc, tmp);
- av = new CommaExp(loc, av, new VarExp(loc, tmp));
+ // First look for constructor
+ if (ad->ctor && arguments && arguments->dim)
+ {
+ // Create variable that will get constructed
+ Identifier *idtmp = Lexer::uniqueId("__ctmp");
+ VarDeclaration *tmp = new VarDeclaration(loc, t1, idtmp, NULL);
+ Expression *av = new DeclarationExp(loc, tmp);
+ av = new CommaExp(loc, av, new VarExp(loc, tmp));
- Expression *e;
- CtorDeclaration *cf = ad->ctor->isCtorDeclaration();
- if (cf)
- e = new DotVarExp(loc, av, cf, 1);
- else
- { TemplateDeclaration *td = ad->ctor->isTemplateDeclaration();
- assert(td);
- e = new DotTemplateExp(loc, av, td);
- }
- e = new CallExp(loc, e, arguments);
+ Expression *e;
+ CtorDeclaration *cf = ad->ctor->isCtorDeclaration();
+ if (cf)
+ e = new DotVarExp(loc, av, cf, 1);
+ else
+ { TemplateDeclaration *td = ad->ctor->isTemplateDeclaration();
+ assert(td);
+ e = new DotTemplateExp(loc, av, td);
+ }
+ e = new CallExp(loc, e, arguments);
#if !STRUCTTHISREF
- /* Constructors return a pointer to the instance
- */
- e = new PtrExp(loc, e);
+ /* Constructors return a pointer to the instance
+ */
+ e = new PtrExp(loc, e);
#endif
- e = e->semantic(sc);
- return e;
- }
+ e = e->semantic(sc);
+ return e;
+ }
#endif
- // No constructor, look for overload of opCall
- if (search_function(ad, Id::call))
- goto L1; // overload of opCall, therefore it's a call
+ // No constructor, look for overload of opCall
+ if (search_function(ad, Id::call))
+ goto L1; // overload of opCall, therefore it's a call
- if (e1->op != TOKtype)
- error("%s %s does not overload ()", ad->kind(), ad->toChars());
- /* It's a struct literal
- */
- Expression *e = new StructLiteralExp(loc, (StructDeclaration *)ad, arguments);
- e = e->semantic(sc);
- e->type = e1->type; // in case e1->type was a typedef
- return e;
- }
- else if (t1->ty == Tclass)
- {
- ad = ((TypeClass *)t1)->sym;
- goto L1;
- L1:
- // Rewrite as e1.call(arguments)
- Expression *e = new DotIdExp(loc, e1, Id::call);
- e = new CallExp(loc, e, arguments);
- e = e->semantic(sc);
- return e;
- }
+ if (e1->op != TOKtype)
+ error("%s %s does not overload ()", ad->kind(), ad->toChars());
+ /* It's a struct literal
+ */
+ Expression *e = new StructLiteralExp(loc, (StructDeclaration *)ad, arguments);
+ e = e->semantic(sc);
+ e->type = e1->type; // in case e1->type was a typedef
+ return e;
+ }
+ else if (t1->ty == Tclass)
+ {
+ ad = ((TypeClass *)t1)->sym;
+ goto L1;
+ L1:
+ // Rewrite as e1.call(arguments)
+ Expression *e = new DotIdExp(loc, e1, Id::call);
+ e = new CallExp(loc, e, arguments);
+ e = e->semantic(sc);
+ return e;
+ }
}
arrayExpressionSemantic(arguments, sc);
@@ -6525,272 +6525,272 @@ Lagain:
if (e1->op == TOKdotvar && t1->ty == Tfunction ||
e1->op == TOKdottd)
{
- DotVarExp *dve;
- DotTemplateExp *dte;
- AggregateDeclaration *ad;
- UnaExp *ue = (UnaExp *)(e1);
+ DotVarExp *dve;
+ DotTemplateExp *dte;
+ AggregateDeclaration *ad;
+ UnaExp *ue = (UnaExp *)(e1);
- if (e1->op == TOKdotvar)
+ if (e1->op == TOKdotvar)
{ // Do overload resolution
- dve = (DotVarExp *)(e1);
+ dve = (DotVarExp *)(e1);
- f = dve->var->isFuncDeclaration();
- assert(f);
- f = f->overloadResolve(loc, NULL, arguments, sc->module);
+ f = dve->var->isFuncDeclaration();
+ assert(f);
+ f = f->overloadResolve(loc, NULL, arguments, sc->module);
- ad = f->toParent()->isAggregateDeclaration();
- }
+ ad = f->toParent()->isAggregateDeclaration();
+ }
else
{ dte = (DotTemplateExp *)(e1);
- TemplateDeclaration *td = dte->td;
- assert(td);
- if (!arguments)
- // Should fix deduceFunctionTemplate() so it works on NULL argument
- arguments = new Expressions();
- f = td->deduceFunctionTemplate(sc, loc, targsi, NULL, arguments);
- if (!f)
- { type = Type::terror;
- return this;
- }
- ad = td->toParent()->isAggregateDeclaration();
- }
- if (f->needThis())
- {
- ue->e1 = getRightThis(loc, sc, ad, ue->e1, f);
- }
+ TemplateDeclaration *td = dte->td;
+ assert(td);
+ if (!arguments)
+ // Should fix deduceFunctionTemplate() so it works on NULL argument
+ arguments = new Expressions();
+ f = td->deduceFunctionTemplate(sc, loc, targsi, NULL, arguments);
+ if (!f)
+ { type = Type::terror;
+ return this;
+ }
+ ad = td->toParent()->isAggregateDeclaration();
+ }
+ if (f->needThis())
+ {
+ ue->e1 = getRightThis(loc, sc, ad, ue->e1, f);
+ }
- /* Cannot call public functions from inside invariant
- * (because then the invariant would have infinite recursion)
- */
- if (sc->func && sc->func->isInvariantDeclaration() &&
- ue->e1->op == TOKthis &&
- f->addPostInvariant()
- )
- {
- error("cannot call public/export function %s from invariant", f->toChars());
- }
+ /* Cannot call public functions from inside invariant
+ * (because then the invariant would have infinite recursion)
+ */
+ if (sc->func && sc->func->isInvariantDeclaration() &&
+ ue->e1->op == TOKthis &&
+ f->addPostInvariant()
+ )
+ {
+ error("cannot call public/export function %s from invariant", f->toChars());
+ }
- checkDeprecated(sc, f);
+ checkDeprecated(sc, f);
#if DMDV2
- checkPurity(sc, f);
+ checkPurity(sc, f);
#endif
- accessCheck(loc, sc, ue->e1, f);
- if (!f->needThis())
- {
- VarExp *ve = new VarExp(loc, f);
- e1 = new CommaExp(loc, ue->e1, ve);
- e1->type = f->type;
- }
- else
- {
- if (e1->op == TOKdotvar)
- dve->var = f;
- else
- e1 = new DotVarExp(loc, dte->e1, f);
- e1->type = f->type;
+ accessCheck(loc, sc, ue->e1, f);
+ if (!f->needThis())
+ {
+ VarExp *ve = new VarExp(loc, f);
+ e1 = new CommaExp(loc, ue->e1, ve);
+ e1->type = f->type;
+ }
+ else
+ {
+ if (e1->op == TOKdotvar)
+ dve->var = f;
+ else
+ e1 = new DotVarExp(loc, dte->e1, f);
+ e1->type = f->type;
- // See if we need to adjust the 'this' pointer
- AggregateDeclaration *ad = f->isThis();
- ClassDeclaration *cd = ue->e1->type->isClassHandle();
- if (ad && cd && ad->isClassDeclaration() && ad != cd &&
- ue->e1->op != TOKsuper)
- {
- ue->e1 = ue->e1->castTo(sc, ad->type); //new CastExp(loc, ue->e1, ad->type);
- ue->e1 = ue->e1->semantic(sc);
- }
- }
- t1 = e1->type;
+ // See if we need to adjust the 'this' pointer
+ AggregateDeclaration *ad = f->isThis();
+ ClassDeclaration *cd = ue->e1->type->isClassHandle();
+ if (ad && cd && ad->isClassDeclaration() && ad != cd &&
+ ue->e1->op != TOKsuper)
+ {
+ ue->e1 = ue->e1->castTo(sc, ad->type); //new CastExp(loc, ue->e1, ad->type);
+ ue->e1 = ue->e1->semantic(sc);
+ }
+ }
+ t1 = e1->type;
}
else if (e1->op == TOKsuper)
{
- // Base class constructor call
- ClassDeclaration *cd = NULL;
+ // Base class constructor call
+ ClassDeclaration *cd = NULL;
- if (sc->func)
- cd = sc->func->toParent()->isClassDeclaration();
- if (!cd || !cd->baseClass || !sc->func->isCtorDeclaration())
- {
- error("super class constructor call must be in a constructor");
- type = Type::terror;
- return this;
- }
- else
- {
- f = cd->baseClass->ctor;
- if (!f)
- { error("no super class constructor for %s", cd->baseClass->toChars());
- type = Type::terror;
- return this;
- }
- else
- {
- if (!sc->intypeof)
- {
+ if (sc->func)
+ cd = sc->func->toParent()->isClassDeclaration();
+ if (!cd || !cd->baseClass || !sc->func->isCtorDeclaration())
+ {
+ error("super class constructor call must be in a constructor");
+ type = Type::terror;
+ return this;
+ }
+ else
+ {
+ f = cd->baseClass->ctor;
+ if (!f)
+ { error("no super class constructor for %s", cd->baseClass->toChars());
+ type = Type::terror;
+ return this;
+ }
+ else
+ {
+ if (!sc->intypeof)
+ {
#if 0
- if (sc->callSuper & (CSXthis | CSXsuper))
- error("reference to this before super()");
+ if (sc->callSuper & (CSXthis | CSXsuper))
+ error("reference to this before super()");
#endif
- if (sc->noctor || sc->callSuper & CSXlabel)
- error("constructor calls not allowed in loops or after labels");
- if (sc->callSuper & (CSXsuper_ctor | CSXthis_ctor))
- error("multiple constructor calls");
- sc->callSuper |= CSXany_ctor | CSXsuper_ctor;
- }
+ if (sc->noctor || sc->callSuper & CSXlabel)
+ error("constructor calls not allowed in loops or after labels");
+ if (sc->callSuper & (CSXsuper_ctor | CSXthis_ctor))
+ error("multiple constructor calls");
+ sc->callSuper |= CSXany_ctor | CSXsuper_ctor;
+ }
- f = f->overloadResolve(loc, NULL, arguments, sc->module);
- checkDeprecated(sc, f);
+ f = f->overloadResolve(loc, NULL, arguments, sc->module);
+ checkDeprecated(sc, f);
#if DMDV2
- checkPurity(sc, f);
+ checkPurity(sc, f);
#endif
- e1 = new DotVarExp(e1->loc, e1, f);
- e1 = e1->semantic(sc);
- t1 = e1->type;
- }
- }
+ e1 = new DotVarExp(e1->loc, e1, f);
+ e1 = e1->semantic(sc);
+ t1 = e1->type;
+ }
+ }
}
else if (e1->op == TOKthis)
{
- // same class constructor call
- ClassDeclaration *cd = NULL;
+ // same class constructor call
+ ClassDeclaration *cd = NULL;
- if (sc->func)
- cd = sc->func->toParent()->isClassDeclaration();
- if (!cd || !sc->func->isCtorDeclaration())
- {
- error("class constructor call must be in a constructor");
- type = Type::terror;
- return this;
- }
- else
- {
- if (!sc->intypeof)
- {
+ if (sc->func)
+ cd = sc->func->toParent()->isClassDeclaration();
+ if (!cd || !sc->func->isCtorDeclaration())
+ {
+ error("class constructor call must be in a constructor");
+ type = Type::terror;
+ return this;
+ }
+ else
+ {
+ if (!sc->intypeof)
+ {
#if 0
- if (sc->callSuper & (CSXthis | CSXsuper))
- error("reference to this before super()");
+ if (sc->callSuper & (CSXthis | CSXsuper))
+ error("reference to this before super()");
#endif
- if (sc->noctor || sc->callSuper & CSXlabel)
- error("constructor calls not allowed in loops or after labels");
- if (sc->callSuper & (CSXsuper_ctor | CSXthis_ctor))
- error("multiple constructor calls");
- sc->callSuper |= CSXany_ctor | CSXthis_ctor;
- }
+ if (sc->noctor || sc->callSuper & CSXlabel)
+ error("constructor calls not allowed in loops or after labels");
+ if (sc->callSuper & (CSXsuper_ctor | CSXthis_ctor))
+ error("multiple constructor calls");
+ sc->callSuper |= CSXany_ctor | CSXthis_ctor;
+ }
- f = cd->ctor;
- f = f->overloadResolve(loc, NULL, arguments, sc->module);
- checkDeprecated(sc, f);
+ f = cd->ctor;
+ f = f->overloadResolve(loc, NULL, arguments, sc->module);
+ checkDeprecated(sc, f);
#if DMDV2
- checkPurity(sc, f);
+ checkPurity(sc, f);
#endif
- e1 = new DotVarExp(e1->loc, e1, f);
- e1 = e1->semantic(sc);
- t1 = e1->type;
+ e1 = new DotVarExp(e1->loc, e1, f);
+ e1 = e1->semantic(sc);
+ t1 = e1->type;
- // BUG: this should really be done by checking the static
- // call graph
- if (f == sc->func)
- error("cyclic constructor call");
- }
+ // BUG: this should really be done by checking the static
+ // call graph
+ if (f == sc->func)
+ error("cyclic constructor call");
+ }
}
else if (!t1)
{
- error("function expected before (), not '%s'", e1->toChars());
- type = Type::terror;
- return this;
+ error("function expected before (), not '%s'", e1->toChars());
+ type = Type::terror;
+ return this;
}
else if (t1->ty != Tfunction)
{
- if (t1->ty == Tdelegate)
- { TypeDelegate *td = (TypeDelegate *)t1;
- assert(td->next->ty == Tfunction);
- tf = (TypeFunction *)(td->next);
- goto Lcheckargs;
- }
- else if (t1->ty == Tpointer && ((TypePointer *)t1)->next->ty == Tfunction)
- { Expression *e;
+ if (t1->ty == Tdelegate)
+ { TypeDelegate *td = (TypeDelegate *)t1;
+ assert(td->next->ty == Tfunction);
+ tf = (TypeFunction *)(td->next);
+ goto Lcheckargs;
+ }
+ else if (t1->ty == Tpointer && ((TypePointer *)t1)->next->ty == Tfunction)
+ { Expression *e;
- e = new PtrExp(loc, e1);
- t1 = ((TypePointer *)t1)->next;
- e->type = t1;
- e1 = e;
- }
- else if (e1->op == TOKtemplate)
- {
- TemplateExp *te = (TemplateExp *)e1;
- f = te->td->deduceFunctionTemplate(sc, loc, targsi, NULL, arguments);
- if (!f)
- { type = Type::terror;
- return this;
- }
- if (f->needThis() && hasThis(sc))
- {
- // Supply an implicit 'this', as in
- // this.ident
+ e = new PtrExp(loc, e1);
+ t1 = ((TypePointer *)t1)->next;
+ e->type = t1;
+ e1 = e;
+ }
+ else if (e1->op == TOKtemplate)
+ {
+ TemplateExp *te = (TemplateExp *)e1;
+ f = te->td->deduceFunctionTemplate(sc, loc, targsi, NULL, arguments);
+ if (!f)
+ { type = Type::terror;
+ return this;
+ }
+ if (f->needThis() && hasThis(sc))
+ {
+ // Supply an implicit 'this', as in
+ // this.ident
- e1 = new DotTemplateExp(loc, (new ThisExp(loc))->semantic(sc), te->td);
- goto Lagain;
- }
+ e1 = new DotTemplateExp(loc, (new ThisExp(loc))->semantic(sc), te->td);
+ goto Lagain;
+ }
- e1 = new VarExp(loc, f);
- goto Lagain;
- }
- else
- { error("function expected before (), not %s of type %s", e1->toChars(), e1->type->toChars());
- type = Type::terror;
- return this;
- }
+ e1 = new VarExp(loc, f);
+ goto Lagain;
+ }
+ else
+ { error("function expected before (), not %s of type %s", e1->toChars(), e1->type->toChars());
+ type = Type::terror;
+ return this;
+ }
}
else if (e1->op == TOKvar)
{
- // Do overload resolution
- VarExp *ve = (VarExp *)e1;
+ // Do overload resolution
+ VarExp *ve = (VarExp *)e1;
- f = ve->var->isFuncDeclaration();
- assert(f);
+ f = ve->var->isFuncDeclaration();
+ assert(f);
- // Look to see if f is really a function template
- if (0 && !istemp && f->parent)
- { TemplateInstance *ti = f->parent->isTemplateInstance();
+ // Look to see if f is really a function template
+ if (0 && !istemp && f->parent)
+ { TemplateInstance *ti = f->parent->isTemplateInstance();
- if (ti &&
- (ti->name == f->ident ||
- ti->toAlias()->ident == f->ident)
- &&
- ti->tempdecl)
- {
- /* This is so that one can refer to the enclosing
- * template, even if it has the same name as a member
- * of the template, if it has a !(arguments)
- */
- TemplateDeclaration *tempdecl = ti->tempdecl;
- if (tempdecl->overroot) // if not start of overloaded list of TemplateDeclaration's
- tempdecl = tempdecl->overroot; // then get the start
- e1 = new TemplateExp(loc, tempdecl);
- istemp = 1;
- goto Lagain;
- }
- }
+ if (ti &&
+ (ti->name == f->ident ||
+ ti->toAlias()->ident == f->ident)
+ &&
+ ti->tempdecl)
+ {
+ /* This is so that one can refer to the enclosing
+ * template, even if it has the same name as a member
+ * of the template, if it has a !(arguments)
+ */
+ TemplateDeclaration *tempdecl = ti->tempdecl;
+ if (tempdecl->overroot) // if not start of overloaded list of TemplateDeclaration's
+ tempdecl = tempdecl->overroot; // then get the start
+ e1 = new TemplateExp(loc, tempdecl);
+ istemp = 1;
+ goto Lagain;
+ }
+ }
- f = f->overloadResolve(loc, NULL, arguments, sc->module);
- checkDeprecated(sc, f);
+ f = f->overloadResolve(loc, NULL, arguments, sc->module);
+ checkDeprecated(sc, f);
#if DMDV2
- checkPurity(sc, f);
+ checkPurity(sc, f);
#endif
- if (f->needThis() && hasThis(sc))
- {
- // Supply an implicit 'this', as in
- // this.ident
+ if (f->needThis() && hasThis(sc))
+ {
+ // Supply an implicit 'this', as in
+ // this.ident
- e1 = new DotVarExp(loc, new ThisExp(loc), f);
- goto Lagain;
- }
+ e1 = new DotVarExp(loc, new ThisExp(loc), f);
+ goto Lagain;
+ }
- accessCheck(loc, sc, NULL, f);
+ accessCheck(loc, sc, NULL, f);
- ve->var = f;
- ve->type = f->type;
- t1 = f->type;
+ ve->var = f;
+ ve->type = f->type;
+ t1 = f->type;
}
assert(t1->ty == Tfunction);
tf = (TypeFunction *)(t1);
@@ -6800,22 +6800,22 @@ Lcheckargs:
type = tf->next;
if (!arguments)
- arguments = new Expressions();
+ arguments = new Expressions();
functionParameters(loc, sc, tf, arguments);
assert(type);
if (f && f->tintro)
{
- Type *t = type;
- int offset = 0;
- TypeFunction *tf = (TypeFunction *)f->tintro;
+ Type *t = type;
+ int offset = 0;
+ TypeFunction *tf = (TypeFunction *)f->tintro;
- if (tf->next->isBaseOf(t, &offset) && offset)
- {
- type = tf->next;
- return castTo(sc, t);
- }
+ if (tf->next->isBaseOf(t, &offset) && offset)
+ {
+ type = tf->next;
+ return castTo(sc, t);
+ }
}
return this;
@@ -6825,18 +6825,18 @@ int CallExp::checkSideEffect(int flag)
{
#if DMDV2
if (flag != 2)
- return 1;
+ return 1;
if (e1->checkSideEffect(2))
- return 1;
+ return 1;
/* If any of the arguments have side effects, this expression does
*/
for (size_t i = 0; i < arguments->dim; i++)
{ Expression *e = (Expression *)arguments->data[i];
- if (e->checkSideEffect(2))
- return 1;
+ if (e->checkSideEffect(2))
+ return 1;
}
/* If calling a function or delegate that is typed as pure,
@@ -6844,9 +6844,9 @@ int CallExp::checkSideEffect(int flag)
*/
Type *t = e1->type->toBasetype();
if (t->ty == Tfunction && ((TypeFunction *)t)->ispure)
- return 0;
+ return 0;
if (t->ty == Tdelegate && ((TypeFunction *)((TypeDelegate *)t)->next)->ispure)
- return 0;
+ return 0;
#endif
return 1;
}
@@ -6856,19 +6856,19 @@ int CallExp::canThrow()
{
//printf("CallExp::canThrow() %s\n", toChars());
if (e1->canThrow())
- return 1;
+ return 1;
/* If any of the arguments can throw, then this expression can throw
*/
for (size_t i = 0; i < arguments->dim; i++)
{ Expression *e = (Expression *)arguments->data[i];
- if (e && e->canThrow())
- return 1;
+ if (e && e->canThrow())
+ return 1;
}
if (global.errors && !e1->type)
- return 0; // error recovery
+ return 0; // error recovery
/* If calling a function or delegate that is typed as nothrow,
* then this expression cannot throw.
@@ -6876,9 +6876,9 @@ int CallExp::canThrow()
*/
Type *t = e1->type->toBasetype();
if (t->ty == Tfunction && ((TypeFunction *)t)->isnothrow)
- return 0;
+ return 0;
if (t->ty == Tdelegate && ((TypeFunction *)((TypeDelegate *)t)->next)->isnothrow)
- return 0;
+ return 0;
return 1;
}
@@ -6888,10 +6888,10 @@ int CallExp::canThrow()
int CallExp::isLvalue()
{
// if (type->toBasetype()->ty == Tstruct)
-// return 1;
+// return 1;
Type *tb = e1->type->toBasetype();
if (tb->ty == Tfunction && ((TypeFunction *)tb)->isref)
- return 1; // function returns a reference
+ return 1; // function returns a reference
return 0;
}
#endif
@@ -6900,10 +6900,10 @@ Expression *CallExp::toLvalue(Scope *sc, Expression *e)
{
#if 1
if (type->toBasetype()->ty == Tstruct)
- return this;
+ return this;
else
#endif
- return Expression::toLvalue(sc, e);
+ return Expression::toLvalue(sc, e);
}
Expression *CallExp::modifiableLvalue(Scope *sc, Expression *e)
@@ -6933,7 +6933,7 @@ void CallExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
AddrExp::AddrExp(Loc loc, Expression *e)
- : UnaExp(loc, TOKaddress, sizeof(AddrExp), e)
+ : UnaExp(loc, TOKaddress, sizeof(AddrExp), e)
{
m = NULL;
}
@@ -6945,44 +6945,44 @@ Expression *AddrExp::semantic(Scope *sc)
#endif
if (!type)
{
- m = sc->module;
- UnaExp::semantic(sc);
- e1 = e1->toLvalue(sc, NULL);
- if (!e1->type)
- {
- error("cannot take address of %s", e1->toChars());
- return new ErrorExp();
- }
- if (!e1->type->deco)
- {
- /* No deco means semantic() was not run on the type.
- * We have to run semantic() on the symbol to get the right type:
- * auto x = &bar;
- * pure: int bar() { return 1;}
- * otherwise the 'pure' is missing from the type assigned to x.
- */
+ m = sc->module;
+ UnaExp::semantic(sc);
+ e1 = e1->toLvalue(sc, NULL);
+ if (!e1->type)
+ {
+ error("cannot take address of %s", e1->toChars());
+ return new ErrorExp();
+ }
+ if (!e1->type->deco)
+ {
+ /* No deco means semantic() was not run on the type.
+ * We have to run semantic() on the symbol to get the right type:
+ * auto x = &bar;
+ * pure: int bar() { return 1;}
+ * otherwise the 'pure' is missing from the type assigned to x.
+ */
- error("forward reference to %s", e1->toChars());
- return new ErrorExp();
- }
- type = e1->type->pointerTo();
+ error("forward reference to %s", e1->toChars());
+ return new ErrorExp();
+ }
+ type = e1->type->pointerTo();
- // See if this should really be a delegate
- if (e1->op == TOKdotvar)
- {
- DotVarExp *dve = (DotVarExp *)e1;
- FuncDeclaration *f = dve->var->isFuncDeclaration();
+ // See if this should really be a delegate
+ if (e1->op == TOKdotvar)
+ {
+ DotVarExp *dve = (DotVarExp *)e1;
+ FuncDeclaration *f = dve->var->isFuncDeclaration();
- if (f)
- { Expression *e = new DelegateExp(loc, dve->e1, f);
- e = e->semantic(sc);
- return e;
- }
- }
- else if (e1->op == TOKvar)
- {
- VarExp *dve = (VarExp *)e1;
- FuncDeclaration *f = dve->var->isFuncDeclaration();
+ if (f)
+ { Expression *e = new DelegateExp(loc, dve->e1, f);
+ e = e->semantic(sc);
+ return e;
+ }
+ }
+ else if (e1->op == TOKvar)
+ {
+ VarExp *dve = (VarExp *)e1;
+ FuncDeclaration *f = dve->var->isFuncDeclaration();
VarDeclaration *v = dve->var->isVarDeclaration();
// LDC
@@ -6992,20 +6992,20 @@ Expression *AddrExp::semantic(Scope *sc)
return this;
}
- if (f && f->isNested())
- { Expression *e;
+ if (f && f->isNested())
+ { Expression *e;
- e = new DelegateExp(loc, e1, f);
- e = e->semantic(sc);
- return e;
- }
- }
- else if (e1->op == TOKarray)
- {
- if (e1->type->toBasetype()->ty == Tbit)
- error("cannot take address of bit in array");
- }
- return optimize(WANTvalue);
+ e = new DelegateExp(loc, e1, f);
+ e = e->semantic(sc);
+ return e;
+ }
+ }
+ else if (e1->op == TOKarray)
+ {
+ if (e1->type->toBasetype()->ty == Tbit)
+ error("cannot take address of bit in array");
+ }
+ return optimize(WANTvalue);
}
return this;
}
@@ -7018,14 +7018,14 @@ void AddrExp::checkEscape()
/************************************************************/
PtrExp::PtrExp(Loc loc, Expression *e)
- : UnaExp(loc, TOKstar, sizeof(PtrExp), e)
+ : UnaExp(loc, TOKstar, sizeof(PtrExp), e)
{
// if (e->type)
-// type = ((TypePointer *)e->type)->next;
+// type = ((TypePointer *)e->type)->next;
}
PtrExp::PtrExp(Loc loc, Expression *e, Type *t)
- : UnaExp(loc, TOKstar, sizeof(PtrExp), e)
+ : UnaExp(loc, TOKstar, sizeof(PtrExp), e)
{
type = t;
}
@@ -7037,28 +7037,28 @@ Expression *PtrExp::semantic(Scope *sc)
#endif
if (!type)
{
- UnaExp::semantic(sc);
- e1 = resolveProperties(sc, e1);
- if (!e1->type)
- printf("PtrExp::semantic('%s')\n", toChars());
- Type *tb = e1->type->toBasetype();
- switch (tb->ty)
- {
- case Tpointer:
- type = tb->next;
- break;
+ UnaExp::semantic(sc);
+ e1 = resolveProperties(sc, e1);
+ if (!e1->type)
+ printf("PtrExp::semantic('%s')\n", toChars());
+ Type *tb = e1->type->toBasetype();
+ switch (tb->ty)
+ {
+ case Tpointer:
+ type = tb->next;
+ break;
- case Tsarray:
- case Tarray:
- type = tb->next;
- e1 = e1->castTo(sc, type->pointerTo());
- break;
+ case Tsarray:
+ case Tarray:
+ type = tb->next;
+ e1 = e1->castTo(sc, type->pointerTo());
+ break;
- default:
- error("can only * a pointer, not a '%s'", e1->type->toChars());
- return new ErrorExp();
- }
- rvalue();
+ default:
+ error("can only * a pointer, not a '%s'", e1->type->toChars());
+ return new ErrorExp();
+ }
+ rvalue();
}
return this;
}
@@ -7080,9 +7080,9 @@ Expression *PtrExp::toLvalue(Scope *sc, Expression *e)
#if 0
tym = tybasic(e1->ET->Tty);
if (!(tyscalar(tym) ||
- tym == TYstruct ||
- tym == TYarray && e->Eoper == TOKaddr))
- synerr(EM_lvalue); // lvalue expected
+ tym == TYstruct ||
+ tym == TYarray && e->Eoper == TOKaddr))
+ synerr(EM_lvalue); // lvalue expected
#endif
return this;
}
@@ -7093,9 +7093,9 @@ Expression *PtrExp::modifiableLvalue(Scope *sc, Expression *e)
//printf("PtrExp::modifiableLvalue() %s, type %s\n", toChars(), type->toChars());
if (e1->op == TOKsymoff)
- { SymOffExp *se = (SymOffExp *)e1;
- se->var->checkModify(loc, sc, type);
- //return toLvalue(sc, e);
+ { SymOffExp *se = (SymOffExp *)e1;
+ se->var->checkModify(loc, sc, type);
+ //return toLvalue(sc, e);
}
return Expression::modifiableLvalue(sc, e);
@@ -7111,7 +7111,7 @@ void PtrExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
NegExp::NegExp(Loc loc, Expression *e)
- : UnaExp(loc, TOKneg, sizeof(NegExp), e)
+ : UnaExp(loc, TOKneg, sizeof(NegExp), e)
{
}
@@ -7123,16 +7123,16 @@ Expression *NegExp::semantic(Scope *sc)
#endif
if (!type)
{
- UnaExp::semantic(sc);
- e1 = resolveProperties(sc, e1);
- e = op_overload(sc);
- if (e)
- return e;
+ UnaExp::semantic(sc);
+ e1 = resolveProperties(sc, e1);
+ e = op_overload(sc);
+ if (e)
+ return e;
- e1->checkNoBool();
- if (!e1->isArrayOperand())
- e1->checkArithmetic();
- type = e1->type;
+ e1->checkNoBool();
+ if (!e1->isArrayOperand())
+ e1->checkArithmetic();
+ type = e1->type;
}
return this;
}
@@ -7140,7 +7140,7 @@ Expression *NegExp::semantic(Scope *sc)
/************************************************************/
UAddExp::UAddExp(Loc loc, Expression *e)
- : UnaExp(loc, TOKuadd, sizeof(UAddExp), e)
+ : UnaExp(loc, TOKuadd, sizeof(UAddExp), e)
{
}
@@ -7155,7 +7155,7 @@ Expression *UAddExp::semantic(Scope *sc)
e1 = resolveProperties(sc, e1);
e = op_overload(sc);
if (e)
- return e;
+ return e;
e1->checkNoBool();
e1->checkArithmetic();
return e1;
@@ -7164,7 +7164,7 @@ Expression *UAddExp::semantic(Scope *sc)
/************************************************************/
ComExp::ComExp(Loc loc, Expression *e)
- : UnaExp(loc, TOKtilde, sizeof(ComExp), e)
+ : UnaExp(loc, TOKtilde, sizeof(ComExp), e)
{
}
@@ -7173,16 +7173,16 @@ Expression *ComExp::semantic(Scope *sc)
if (!type)
{
- UnaExp::semantic(sc);
- e1 = resolveProperties(sc, e1);
- e = op_overload(sc);
- if (e)
- return e;
+ UnaExp::semantic(sc);
+ e1 = resolveProperties(sc, e1);
+ e = op_overload(sc);
+ if (e)
+ return e;
- e1->checkNoBool();
- if (!e1->isArrayOperand())
- e1 = e1->checkIntegral();
- type = e1->type;
+ e1->checkNoBool();
+ if (!e1->isArrayOperand())
+ e1 = e1->checkIntegral();
+ type = e1->type;
}
return this;
}
@@ -7190,7 +7190,7 @@ Expression *ComExp::semantic(Scope *sc)
/************************************************************/
NotExp::NotExp(Loc loc, Expression *e)
- : UnaExp(loc, TOKnot, sizeof(NotExp), e)
+ : UnaExp(loc, TOKnot, sizeof(NotExp), e)
{
}
@@ -7213,7 +7213,7 @@ int NotExp::isBit()
/************************************************************/
BoolExp::BoolExp(Loc loc, Expression *e, Type *t)
- : UnaExp(loc, TOKtobool, sizeof(BoolExp), e)
+ : UnaExp(loc, TOKtobool, sizeof(BoolExp), e)
{
type = t;
}
@@ -7235,7 +7235,7 @@ int BoolExp::isBit()
/************************************************************/
DeleteExp::DeleteExp(Loc loc, Expression *e)
- : UnaExp(loc, TOKdelete, sizeof(DeleteExp), e)
+ : UnaExp(loc, TOKdelete, sizeof(DeleteExp), e)
{
}
@@ -7250,60 +7250,60 @@ Expression *DeleteExp::semantic(Scope *sc)
tb = e1->type->toBasetype();
switch (tb->ty)
- { case Tclass:
- { TypeClass *tc = (TypeClass *)tb;
- ClassDeclaration *cd = tc->sym;
+ { case Tclass:
+ { TypeClass *tc = (TypeClass *)tb;
+ ClassDeclaration *cd = tc->sym;
- if (cd->isCOMinterface())
- { /* Because COM classes are deleted by IUnknown.Release()
- */
- error("cannot delete instance of COM interface %s", cd->toChars());
- }
- break;
- }
- case Tpointer:
- tb = ((TypePointer *)tb)->next->toBasetype();
- if (tb->ty == Tstruct)
- {
- TypeStruct *ts = (TypeStruct *)tb;
- StructDeclaration *sd = ts->sym;
- FuncDeclaration *f = sd->aggDelete;
+ if (cd->isCOMinterface())
+ { /* Because COM classes are deleted by IUnknown.Release()
+ */
+ error("cannot delete instance of COM interface %s", cd->toChars());
+ }
+ break;
+ }
+ case Tpointer:
+ tb = ((TypePointer *)tb)->next->toBasetype();
+ if (tb->ty == Tstruct)
+ {
+ TypeStruct *ts = (TypeStruct *)tb;
+ StructDeclaration *sd = ts->sym;
+ FuncDeclaration *f = sd->aggDelete;
- if (f)
- {
- Type *tpv = Type::tvoid->pointerTo();
+ if (f)
+ {
+ Type *tpv = Type::tvoid->pointerTo();
- Expression *e = e1->castTo(sc, tpv);
- Expression *ec = new VarExp(loc, f);
- e = new CallExp(loc, ec, e);
- return e->semantic(sc);
- }
- }
- break;
+ Expression *e = e1->castTo(sc, tpv);
+ Expression *ec = new VarExp(loc, f);
+ e = new CallExp(loc, ec, e);
+ return e->semantic(sc);
+ }
+ }
+ break;
- case Tarray:
- break;
+ case Tarray:
+ break;
- default:
- if (e1->op == TOKindex)
- {
- IndexExp *ae = (IndexExp *)(e1);
- Type *tb1 = ae->e1->type->toBasetype();
- if (tb1->ty == Taarray)
- break;
- }
- error("cannot delete type %s", e1->type->toChars());
- break;
+ default:
+ if (e1->op == TOKindex)
+ {
+ IndexExp *ae = (IndexExp *)(e1);
+ Type *tb1 = ae->e1->type->toBasetype();
+ if (tb1->ty == Taarray)
+ break;
+ }
+ error("cannot delete type %s", e1->type->toChars());
+ break;
}
if (e1->op == TOKindex)
{
- IndexExp *ae = (IndexExp *)(e1);
- Type *tb1 = ae->e1->type->toBasetype();
- if (tb1->ty == Taarray)
- { if (!global.params.useDeprecated)
- error("delete aa[key] deprecated, use aa.remove(key)");
- }
+ IndexExp *ae = (IndexExp *)(e1);
+ Type *tb1 = ae->e1->type->toBasetype();
+ if (tb1->ty == Taarray)
+ { if (!global.params.useDeprecated)
+ error("delete aa[key] deprecated, use aa.remove(key)");
+ }
}
return this;
@@ -7329,7 +7329,7 @@ void DeleteExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
CastExp::CastExp(Loc loc, Expression *e, Type *t)
- : UnaExp(loc, TOKcast, sizeof(CastExp), e)
+ : UnaExp(loc, TOKcast, sizeof(CastExp), e)
{
to = t;
}
@@ -7338,7 +7338,7 @@ CastExp::CastExp(Loc loc, Expression *e, Type *t)
/* For cast(const) and cast(immutable)
*/
CastExp::CastExp(Loc loc, Expression *e, unsigned mod)
- : UnaExp(loc, TOKcast, sizeof(CastExp), e)
+ : UnaExp(loc, TOKcast, sizeof(CastExp), e)
{
to = NULL;
this->mod = mod;
@@ -7363,62 +7363,62 @@ Expression *CastExp::semantic(Scope *sc)
//static int x; assert(++x < 10);
if (type)
- return this;
+ return this;
UnaExp::semantic(sc);
- if (e1->type) // if not a tuple
+ if (e1->type) // if not a tuple
{
- e1 = resolveProperties(sc, e1);
- to = to->semantic(loc, sc);
+ e1 = resolveProperties(sc, e1);
+ to = to->semantic(loc, sc);
- e = op_overload(sc);
- if (e)
- {
- return e->implicitCastTo(sc, to);
- }
+ e = op_overload(sc);
+ if (e)
+ {
+ return e->implicitCastTo(sc, to);
+ }
- if (e1->op == TOKtemplate)
- {
- error("cannot cast template %s to type %s", e1->toChars(), to->toChars());
- return new ErrorExp();
- }
+ if (e1->op == TOKtemplate)
+ {
+ error("cannot cast template %s to type %s", e1->toChars(), to->toChars());
+ return new ErrorExp();
+ }
- Type *t1b = e1->type->toBasetype();
- Type *tob = to->toBasetype();
- if (tob->ty == Tstruct &&
- !tob->equals(t1b) &&
- ((TypeStruct *)to)->sym->search(0, Id::call, 0)
- )
- {
- /* Look to replace:
- * cast(S)t
- * with:
- * S(t)
- */
+ Type *t1b = e1->type->toBasetype();
+ Type *tob = to->toBasetype();
+ if (tob->ty == Tstruct &&
+ !tob->equals(t1b) &&
+ ((TypeStruct *)to)->sym->search(0, Id::call, 0)
+ )
+ {
+ /* Look to replace:
+ * cast(S)t
+ * with:
+ * S(t)
+ */
- // Rewrite as to.call(e1)
- e = new TypeExp(loc, to);
- e = new DotIdExp(loc, e, Id::call);
- e = new CallExp(loc, e, e1);
- e = e->semantic(sc);
- return e;
- }
+ // Rewrite as to.call(e1)
+ e = new TypeExp(loc, to);
+ e = new DotIdExp(loc, e, Id::call);
+ e = new CallExp(loc, e, e1);
+ e = e->semantic(sc);
+ return e;
+ }
- // Struct casts are possible only when the sizes match
- if (tob->ty == Tstruct || t1b->ty == Tstruct)
- {
- size_t fromsize = t1b->size(loc);
- size_t tosize = tob->size(loc);
- if (fromsize != tosize)
- {
- error("cannot cast from %s to %s", e1->type->toChars(), to->toChars());
- return new ErrorExp();
- }
- }
+ // Struct casts are possible only when the sizes match
+ if (tob->ty == Tstruct || t1b->ty == Tstruct)
+ {
+ size_t fromsize = t1b->size(loc);
+ size_t tosize = tob->size(loc);
+ if (fromsize != tosize)
+ {
+ error("cannot cast from %s to %s", e1->type->toChars(), to->toChars());
+ return new ErrorExp();
+ }
+ }
}
if (!e1->type)
- { error("cannot cast %s", e1->toChars());
- return new ErrorExp();
+ { error("cannot cast %s", e1->toChars());
+ return new ErrorExp();
}
e = e1->castTo(sc, to);
@@ -7432,22 +7432,22 @@ int CastExp::checkSideEffect(int flag)
* cast(classtype)func()
*/
if (!to->equals(Type::tvoid) &&
- !(to->ty == Tclass && e1->op == TOKcall && e1->type->ty == Tclass))
- return Expression::checkSideEffect(flag);
+ !(to->ty == Tclass && e1->op == TOKcall && e1->type->ty == Tclass))
+ return Expression::checkSideEffect(flag);
return 1;
}
void CastExp::checkEscape()
{ Type *tb = type->toBasetype();
if (tb->ty == Tarray && e1->op == TOKvar &&
- e1->type->toBasetype()->ty == Tsarray)
- { VarExp *ve = (VarExp *)e1;
- VarDeclaration *v = ve->var->isVarDeclaration();
- if (v)
- {
- if (!v->isDataseg() && !v->isParameter())
- error("escaping reference to local %s", v->toChars());
- }
+ e1->type->toBasetype()->ty == Tsarray)
+ { VarExp *ve = (VarExp *)e1;
+ VarDeclaration *v = ve->var->isVarDeclaration();
+ if (v)
+ {
+ if (!v->isDataseg() && !v->isParameter())
+ error("escaping reference to local %s", v->toChars());
+ }
}
}
@@ -7458,29 +7458,29 @@ void CastExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
to->toCBuffer(buf, NULL, hgs);
#else
if (to)
- to->toCBuffer(buf, NULL, hgs);
+ to->toCBuffer(buf, NULL, hgs);
else
{
- switch (mod)
- { case 0:
- break;
- case MODconst:
- buf->writestring(Token::tochars[TOKconst]);
- break;
- case MODimmutable:
- buf->writestring(Token::tochars[TOKimmutable]);
- break;
- case MODshared:
- buf->writestring(Token::tochars[TOKshared]);
- break;
- case MODshared | MODconst:
- buf->writestring(Token::tochars[TOKshared]);
- buf->writeByte(' ');
- buf->writestring(Token::tochars[TOKconst]);
- break;
- default:
- assert(0);
- }
+ switch (mod)
+ { case 0:
+ break;
+ case MODconst:
+ buf->writestring(Token::tochars[TOKconst]);
+ break;
+ case MODimmutable:
+ buf->writestring(Token::tochars[TOKimmutable]);
+ break;
+ case MODshared:
+ buf->writestring(Token::tochars[TOKshared]);
+ break;
+ case MODshared | MODconst:
+ buf->writestring(Token::tochars[TOKshared]);
+ buf->writeByte(' ');
+ buf->writestring(Token::tochars[TOKconst]);
+ break;
+ default:
+ assert(0);
+ }
}
#endif
buf->writeByte(')');
@@ -7491,7 +7491,7 @@ void CastExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************************************************/
SliceExp::SliceExp(Loc loc, Expression *e1, Expression *lwr, Expression *upr)
- : UnaExp(loc, TOKslice, sizeof(SliceExp), e1)
+ : UnaExp(loc, TOKslice, sizeof(SliceExp), e1)
{
this->upr = upr;
this->lwr = lwr;
@@ -7502,11 +7502,11 @@ Expression *SliceExp::syntaxCopy()
{
Expression *lwr = NULL;
if (this->lwr)
- lwr = this->lwr->syntaxCopy();
+ lwr = this->lwr->syntaxCopy();
Expression *upr = NULL;
if (this->upr)
- upr = this->upr->syntaxCopy();
+ upr = this->upr->syntaxCopy();
return new SliceExp(loc, e1->syntaxCopy(), lwr, upr);
}
@@ -7521,7 +7521,7 @@ Expression *SliceExp::semantic(Scope *sc)
printf("SliceExp::semantic('%s')\n", toChars());
#endif
if (type)
- return this;
+ return this;
UnaExp::semantic(sc);
e1 = resolveProperties(sc, e1);
@@ -7531,8 +7531,8 @@ Expression *SliceExp::semantic(Scope *sc)
Type *t = e1->type->toBasetype();
if (t->ty == Tpointer)
{
- if (!lwr || !upr)
- error("need upper and lower bound to slice pointer");
+ if (!lwr || !upr)
+ error("need upper and lower bound to slice pointer");
}
else if (t->ty == Tarray)
{
@@ -7550,127 +7550,127 @@ Expression *SliceExp::semantic(Scope *sc)
ad = ((TypeStruct *)t)->sym;
L1:
- if (search_function(ad, Id::slice))
+ if (search_function(ad, Id::slice))
{
// Rewrite as e1.slice(lwr, upr)
- e = new DotIdExp(loc, e1, Id::slice);
+ e = new DotIdExp(loc, e1, Id::slice);
- if (lwr)
- {
- assert(upr);
- e = new CallExp(loc, e, lwr, upr);
- }
- else
- { assert(!upr);
- e = new CallExp(loc, e);
- }
- e = e->semantic(sc);
- return e;
+ if (lwr)
+ {
+ assert(upr);
+ e = new CallExp(loc, e, lwr, upr);
+ }
+ else
+ { assert(!upr);
+ e = new CallExp(loc, e);
+ }
+ e = e->semantic(sc);
+ return e;
}
- goto Lerror;
+ goto Lerror;
}
else if (t->ty == Ttuple)
{
- if (!lwr && !upr)
- return e1;
- if (!lwr || !upr)
- { error("need upper and lower bound to slice tuple");
- goto Lerror;
- }
+ if (!lwr && !upr)
+ return e1;
+ if (!lwr || !upr)
+ { error("need upper and lower bound to slice tuple");
+ goto Lerror;
+ }
}
else
- goto Lerror;
+ goto Lerror;
if (t->ty == Tsarray || t->ty == Tarray || t->ty == Ttuple)
{
- sym = new ArrayScopeSymbol(this);
- sym->loc = loc;
- sym->parent = sc->scopesym;
- sc = sc->push(sym);
+ sym = new ArrayScopeSymbol(this);
+ sym->loc = loc;
+ sym->parent = sc->scopesym;
+ sc = sc->push(sym);
}
if (lwr)
- { lwr = lwr->semantic(sc);
- lwr = resolveProperties(sc, lwr);
- lwr = lwr->implicitCastTo(sc, Type::tsize_t);
+ { lwr = lwr->semantic(sc);
+ lwr = resolveProperties(sc, lwr);
+ lwr = lwr->implicitCastTo(sc, Type::tsize_t);
}
if (upr)
- { upr = upr->semantic(sc);
- upr = resolveProperties(sc, upr);
- upr = upr->implicitCastTo(sc, Type::tsize_t);
+ { upr = upr->semantic(sc);
+ upr = resolveProperties(sc, upr);
+ upr = upr->implicitCastTo(sc, Type::tsize_t);
}
if (t->ty == Tsarray || t->ty == Tarray || t->ty == Ttuple)
- sc->pop();
+ sc->pop();
if (t->ty == Ttuple)
{
- lwr = lwr->optimize(WANTvalue);
- upr = upr->optimize(WANTvalue);
- uinteger_t i1 = lwr->toUInteger();
- uinteger_t i2 = upr->toUInteger();
+ lwr = lwr->optimize(WANTvalue);
+ upr = upr->optimize(WANTvalue);
+ uinteger_t i1 = lwr->toUInteger();
+ uinteger_t i2 = upr->toUInteger();
- size_t length;
- TupleExp *te;
- TypeTuple *tup;
+ size_t length;
+ TupleExp *te;
+ TypeTuple *tup;
- if (e1->op == TOKtuple) // slicing an expression tuple
- { te = (TupleExp *)e1;
- length = te->exps->dim;
- }
- else if (e1->op == TOKtype) // slicing a type tuple
- { tup = (TypeTuple *)t;
- length = Parameter::dim(tup->arguments);
- }
- else
- assert(0);
+ if (e1->op == TOKtuple) // slicing an expression tuple
+ { te = (TupleExp *)e1;
+ length = te->exps->dim;
+ }
+ else if (e1->op == TOKtype) // slicing a type tuple
+ { tup = (TypeTuple *)t;
+ length = Parameter::dim(tup->arguments);
+ }
+ else
+ assert(0);
- if (i1 <= i2 && i2 <= length)
- { size_t j1 = (size_t) i1;
- size_t j2 = (size_t) i2;
+ if (i1 <= i2 && i2 <= length)
+ { size_t j1 = (size_t) i1;
+ size_t j2 = (size_t) i2;
- if (e1->op == TOKtuple)
- { Expressions *exps = new Expressions;
- exps->setDim(j2 - j1);
- for (size_t i = 0; i < j2 - j1; i++)
- { Expression *e = (Expression *)te->exps->data[j1 + i];
- exps->data[i] = (void *)e;
- }
- e = new TupleExp(loc, exps);
- }
- else
- { Parameters *args = new Parameters;
- args->reserve(j2 - j1);
- for (size_t i = j1; i < j2; i++)
- { Parameter *arg = Parameter::getNth(tup->arguments, i);
- args->push(arg);
- }
- e = new TypeExp(e1->loc, new TypeTuple(args));
- }
- e = e->semantic(sc);
- }
- else
- {
- error("string slice [%ju .. %ju] is out of bounds", i1, i2);
- e = new IntegerExp(0);
- }
- return e;
+ if (e1->op == TOKtuple)
+ { Expressions *exps = new Expressions;
+ exps->setDim(j2 - j1);
+ for (size_t i = 0; i < j2 - j1; i++)
+ { Expression *e = (Expression *)te->exps->data[j1 + i];
+ exps->data[i] = (void *)e;
+ }
+ e = new TupleExp(loc, exps);
+ }
+ else
+ { Parameters *args = new Parameters;
+ args->reserve(j2 - j1);
+ for (size_t i = j1; i < j2; i++)
+ { Parameter *arg = Parameter::getNth(tup->arguments, i);
+ args->push(arg);
+ }
+ e = new TypeExp(e1->loc, new TypeTuple(args));
+ }
+ e = e->semantic(sc);
+ }
+ else
+ {
+ error("string slice [%ju .. %ju] is out of bounds", i1, i2);
+ e = new IntegerExp(0);
+ }
+ return e;
}
if (t->ty == Tarray)
{
- type = e1->type;
+ type = e1->type;
}
else
- type = t->nextOf()->arrayOf();
+ type = t->nextOf()->arrayOf();
return e;
Lerror:
char *s;
if (t->ty == Tvoid)
- s = e1->toChars();
+ s = e1->toChars();
else
- s = t->toChars();
+ s = t->toChars();
error("%s cannot be sliced with []", s);
e = new ErrorExp();
return e;
@@ -7710,15 +7710,15 @@ void SliceExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writeByte('[');
if (upr || lwr)
{
- if (lwr)
- expToCBuffer(buf, hgs, lwr, PREC_assign);
- else
- buf->writeByte('0');
- buf->writestring("..");
- if (upr)
- expToCBuffer(buf, hgs, upr, PREC_assign);
- else
- buf->writestring("length"); // BUG: should be array.length
+ if (lwr)
+ expToCBuffer(buf, hgs, lwr, PREC_assign);
+ else
+ buf->writeByte('0');
+ buf->writestring("..");
+ if (upr)
+ expToCBuffer(buf, hgs, upr, PREC_assign);
+ else
+ buf->writestring("length"); // BUG: should be array.length
}
buf->writeByte(']');
}
@@ -7726,7 +7726,7 @@ void SliceExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************** ArrayLength **************************************/
ArrayLengthExp::ArrayLengthExp(Loc loc, Expression *e1)
- : UnaExp(loc, TOKarraylength, sizeof(ArrayLengthExp), e1)
+ : UnaExp(loc, TOKarraylength, sizeof(ArrayLengthExp), e1)
{
}
@@ -7737,10 +7737,10 @@ Expression *ArrayLengthExp::semantic(Scope *sc)
#endif
if (!type)
{
- UnaExp::semantic(sc);
- e1 = resolveProperties(sc, e1);
+ UnaExp::semantic(sc);
+ e1 = resolveProperties(sc, e1);
- type = Type::tsize_t;
+ type = Type::tsize_t;
}
return this;
}
@@ -7756,7 +7756,7 @@ void ArrayLengthExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
// e1 [ i1, i2, i3, ... ]
ArrayExp::ArrayExp(Loc loc, Expression *e1, Expressions *args)
- : UnaExp(loc, TOKarray, sizeof(ArrayExp), e1)
+ : UnaExp(loc, TOKarray, sizeof(ArrayExp), e1)
{
arguments = args;
}
@@ -7778,21 +7778,21 @@ Expression *ArrayExp::semantic(Scope *sc)
t1 = e1->type->toBasetype();
if (t1->ty != Tclass && t1->ty != Tstruct)
- { // Convert to IndexExp
- if (arguments->dim != 1)
- error("only one index allowed to index %s", t1->toChars());
- e = new IndexExp(loc, e1, (Expression *)arguments->data[0]);
- return e->semantic(sc);
+ { // Convert to IndexExp
+ if (arguments->dim != 1)
+ error("only one index allowed to index %s", t1->toChars());
+ e = new IndexExp(loc, e1, (Expression *)arguments->data[0]);
+ return e->semantic(sc);
}
// Run semantic() on each argument
for (size_t i = 0; i < arguments->dim; i++)
- { e = (Expression *)arguments->data[i];
+ { e = (Expression *)arguments->data[i];
- e = e->semantic(sc);
- if (!e->type)
- error("%s has no value", e->toChars());
- arguments->data[i] = (void *)e;
+ e = e->semantic(sc);
+ if (!e->type)
+ error("%s has no value", e->toChars());
+ arguments->data[i] = (void *)e;
}
expandTuples(arguments);
@@ -7800,8 +7800,8 @@ Expression *ArrayExp::semantic(Scope *sc)
e = op_overload(sc);
if (!e)
- { error("no [] operator overload for type %s", e1->type->toChars());
- e = e1;
+ { error("no [] operator overload for type %s", e1->type->toChars());
+ e = e1;
}
return e;
}
@@ -7810,7 +7810,7 @@ Expression *ArrayExp::semantic(Scope *sc)
int ArrayExp::isLvalue()
{
if (type && type->toBasetype()->ty == Tvoid)
- return 0;
+ return 0;
return 1;
}
#endif
@@ -7818,7 +7818,7 @@ int ArrayExp::isLvalue()
Expression *ArrayExp::toLvalue(Scope *sc, Expression *e)
{
if (type && type->toBasetype()->ty == Tvoid)
- error("voids have no value");
+ error("voids have no value");
return this;
}
@@ -7835,7 +7835,7 @@ void ArrayExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************* DotExp ***********************************/
DotExp::DotExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKdotexp, sizeof(DotExp), e1, e2)
+ : BinExp(loc, TOKdotexp, sizeof(DotExp), e1, e2)
{
}
@@ -7849,16 +7849,16 @@ Expression *DotExp::semantic(Scope *sc)
e2 = e2->semantic(sc);
if (e2->op == TOKimport)
{
- ScopeExp *se = (ScopeExp *)e2;
- TemplateDeclaration *td = se->sds->isTemplateDeclaration();
- if (td)
- { Expression *e = new DotTemplateExp(loc, e1, td);
- e = e->semantic(sc);
- return e;
- }
+ ScopeExp *se = (ScopeExp *)e2;
+ TemplateDeclaration *td = se->sds->isTemplateDeclaration();
+ if (td)
+ { Expression *e = new DotTemplateExp(loc, e1, td);
+ e = e->semantic(sc);
+ return e;
+ }
}
if (!type)
- type = e2->type;
+ type = e2->type;
return this;
}
@@ -7866,15 +7866,15 @@ Expression *DotExp::semantic(Scope *sc)
/************************* CommaExp ***********************************/
CommaExp::CommaExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKcomma, sizeof(CommaExp), e1, e2)
+ : BinExp(loc, TOKcomma, sizeof(CommaExp), e1, e2)
{
}
Expression *CommaExp::semantic(Scope *sc)
{
if (!type)
- { BinExp::semanticp(sc);
- type = e2->type;
+ { BinExp::semanticp(sc);
+ type = e2->type;
}
return this;
}
@@ -7916,11 +7916,11 @@ int CommaExp::isBool(int result)
int CommaExp::checkSideEffect(int flag)
{
if (flag == 2)
- return e1->checkSideEffect(2) || e2->checkSideEffect(2);
+ return e1->checkSideEffect(2) || e2->checkSideEffect(2);
else
{
- // Don't check e1 until we cast(void) the a,b code generation
- return e2->checkSideEffect(flag);
+ // Don't check e1 until we cast(void) the a,b code generation
+ return e2->checkSideEffect(flag);
}
}
@@ -7929,11 +7929,11 @@ int CommaExp::checkSideEffect(int flag)
// e1 [ e2 ]
IndexExp::IndexExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKindex, sizeof(IndexExp), e1, e2)
+ : BinExp(loc, TOKindex, sizeof(IndexExp), e1, e2)
{
//printf("IndexExp::IndexExp('%s')\n", toChars());
lengthVar = NULL;
- modifiable = 0; // assume it is an rvalue
+ modifiable = 0; // assume it is an rvalue
}
Expression *IndexExp::semantic(Scope *sc)
@@ -7947,10 +7947,10 @@ Expression *IndexExp::semantic(Scope *sc)
printf("IndexExp::semantic('%s')\n", toChars());
#endif
if (type)
- return this;
+ return this;
if (!e1->type)
- e1 = e1->semantic(sc);
- assert(e1->type); // semantic() should already be run on it
+ e1 = e1->semantic(sc);
+ assert(e1->type); // semantic() should already be run on it
e = this;
// Note that unlike C we do not implement the int[ptr]
@@ -7958,106 +7958,106 @@ Expression *IndexExp::semantic(Scope *sc)
t1 = e1->type->toBasetype();
if (t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Ttuple)
- { // Create scope for 'length' variable
- sym = new ArrayScopeSymbol(this);
- sym->loc = loc;
- sym->parent = sc->scopesym;
- sc = sc->push(sym);
+ { // Create scope for 'length' variable
+ sym = new ArrayScopeSymbol(this);
+ sym->loc = loc;
+ sym->parent = sc->scopesym;
+ sc = sc->push(sym);
}
e2 = e2->semantic(sc);
if (!e2->type)
{
- error("%s has no value", e2->toChars());
- e2->type = Type::terror;
+ error("%s has no value", e2->toChars());
+ e2->type = Type::terror;
}
e2 = resolveProperties(sc, e2);
if (t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Ttuple)
- sc = sc->pop();
+ sc = sc->pop();
switch (t1->ty)
{
- case Tpointer:
- case Tarray:
- e2 = e2->implicitCastTo(sc, Type::tsize_t);
- e->type = t1->next;
- break;
+ case Tpointer:
+ case Tarray:
+ e2 = e2->implicitCastTo(sc, Type::tsize_t);
+ e->type = t1->next;
+ break;
- case Tsarray:
- {
- e2 = e2->implicitCastTo(sc, Type::tsize_t);
+ case Tsarray:
+ {
+ e2 = e2->implicitCastTo(sc, Type::tsize_t);
- TypeSArray *tsa = (TypeSArray *)t1;
+ TypeSArray *tsa = (TypeSArray *)t1;
-#if 0 // Don't do now, because it might be short-circuit evaluated
- // Do compile time array bounds checking if possible
- e2 = e2->optimize(WANTvalue);
- if (e2->op == TOKint64)
- {
- dinteger_t index = e2->toInteger();
- dinteger_t length = tsa->dim->toInteger();
- if (index < 0 || index >= length)
- error("array index [%lld] is outside array bounds [0 .. %lld]",
- index, length);
- }
+#if 0 // Don't do now, because it might be short-circuit evaluated
+ // Do compile time array bounds checking if possible
+ e2 = e2->optimize(WANTvalue);
+ if (e2->op == TOKint64)
+ {
+ dinteger_t index = e2->toInteger();
+ dinteger_t length = tsa->dim->toInteger();
+ if (index < 0 || index >= length)
+ error("array index [%lld] is outside array bounds [0 .. %lld]",
+ index, length);
+ }
#endif
- e->type = t1->nextOf();
- break;
- }
+ e->type = t1->nextOf();
+ break;
+ }
- case Taarray:
- { TypeAArray *taa = (TypeAArray *)t1;
+ case Taarray:
+ { TypeAArray *taa = (TypeAArray *)t1;
- e2 = e2->implicitCastTo(sc, taa->index); // type checking
- e2 = e2->implicitCastTo(sc, taa->key); // actual argument type
- type = taa->next;
- break;
- }
+ e2 = e2->implicitCastTo(sc, taa->index); // type checking
+ e2 = e2->implicitCastTo(sc, taa->key); // actual argument type
+ type = taa->next;
+ break;
+ }
- case Ttuple:
- {
- e2 = e2->implicitCastTo(sc, Type::tsize_t);
- e2 = e2->optimize(WANTvalue);
- uinteger_t index = e2->toUInteger();
- size_t length;
- TupleExp *te;
- TypeTuple *tup;
+ case Ttuple:
+ {
+ e2 = e2->implicitCastTo(sc, Type::tsize_t);
+ e2 = e2->optimize(WANTvalue);
+ uinteger_t index = e2->toUInteger();
+ size_t length;
+ TupleExp *te;
+ TypeTuple *tup;
- if (e1->op == TOKtuple)
- { te = (TupleExp *)e1;
- length = te->exps->dim;
- }
- else if (e1->op == TOKtype)
- {
- tup = (TypeTuple *)t1;
- length = Parameter::dim(tup->arguments);
- }
- else
- assert(0);
+ if (e1->op == TOKtuple)
+ { te = (TupleExp *)e1;
+ length = te->exps->dim;
+ }
+ else if (e1->op == TOKtype)
+ {
+ tup = (TypeTuple *)t1;
+ length = Parameter::dim(tup->arguments);
+ }
+ else
+ assert(0);
- if (index < length)
- {
+ if (index < length)
+ {
- if (e1->op == TOKtuple)
- e = (Expression *)te->exps->data[(size_t)index];
- else
- e = new TypeExp(e1->loc, Parameter::getNth(tup->arguments, (size_t)index)->type);
- }
- else
- {
- error("array index [%ju] is outside array bounds [0 .. %zu]",
- index, length);
- e = e1;
- }
- break;
- }
+ if (e1->op == TOKtuple)
+ e = (Expression *)te->exps->data[(size_t)index];
+ else
+ e = new TypeExp(e1->loc, Parameter::getNth(tup->arguments, (size_t)index)->type);
+ }
+ else
+ {
+ error("array index [%ju] is outside array bounds [0 .. %zu]",
+ index, length);
+ e = e1;
+ }
+ break;
+ }
- default:
- error("%s must be an array or pointer type, not %s",
- e1->toChars(), e1->type->toChars());
- type = Type::tint32;
- break;
+ default:
+ error("%s must be an array or pointer type, not %s",
+ e1->toChars(), e1->type->toChars());
+ type = Type::tint32;
+ break;
}
return e;
}
@@ -8072,7 +8072,7 @@ int IndexExp::isLvalue()
Expression *IndexExp::toLvalue(Scope *sc, Expression *e)
{
// if (type && type->toBasetype()->ty == Tvoid)
-// error("voids have no value");
+// error("voids have no value");
return this;
}
@@ -8081,9 +8081,9 @@ Expression *IndexExp::modifiableLvalue(Scope *sc, Expression *e)
//printf("IndexExp::modifiableLvalue(%s)\n", toChars());
modifiable = 1;
if (e1->op == TOKstring)
- error("string literals are immutable");
+ error("string literals are immutable");
if (e1->type->toBasetype()->ty == Taarray)
- e1 = e1->modifiableLvalue(sc, e1);
+ e1 = e1->modifiableLvalue(sc, e1);
return toLvalue(sc, e);
}
@@ -8099,8 +8099,8 @@ void IndexExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************* PostExp ***********************************/
PostExp::PostExp(enum TOK op, Loc loc, Expression *e)
- : BinExp(loc, op, sizeof(PostExp), e,
- new IntegerExp(loc, 1, Type::tint32))
+ : BinExp(loc, op, sizeof(PostExp), e,
+ new IntegerExp(loc, 1, Type::tint32))
{
}
@@ -8109,22 +8109,22 @@ Expression *PostExp::semantic(Scope *sc)
if (!type)
{
- BinExp::semantic(sc);
- e2 = resolveProperties(sc, e2);
+ BinExp::semantic(sc);
+ e2 = resolveProperties(sc, e2);
- e = op_overload(sc);
- if (e)
- return e;
+ e = op_overload(sc);
+ if (e)
+ return e;
- e = this;
- e1 = e1->modifiableLvalue(sc, e1);
- e1->checkScalar();
- e1->checkNoBool();
- if (e1->type->ty == Tpointer)
- e = scaleFactor(sc);
- else
- e2 = e2->castTo(sc, e1->type);
- e->type = e1->type;
+ e = this;
+ e1 = e1->modifiableLvalue(sc, e1);
+ e1->checkScalar();
+ e1->checkNoBool();
+ if (e1->type->ty == Tpointer)
+ e = scaleFactor(sc);
+ else
+ e2 = e2->castTo(sc, e1->type);
+ e->type = e1->type;
}
return e;
}
@@ -8140,7 +8140,7 @@ void PostExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/* op can be TOKassign, TOKconstruct, or TOKblit */
AssignExp::AssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKassign, sizeof(AssignExp), e1, e2)
+ : BinExp(loc, TOKassign, sizeof(AssignExp), e1, e2)
{
ismemset = 0;
}
@@ -8156,15 +8156,15 @@ Expression *AssignExp::semantic(Scope *sc)
//printf("e2->op = %d, '%s'\n", e2->op, Token::toChars(e2->op));
if (type)
- return this;
+ return this;
if (e2->op == TOKcomma)
- { /* Rewrite to get rid of the comma from rvalue
- */
- AssignExp *ea = new AssignExp(loc, e1, ((CommaExp *)e2)->e2);
- ea->op = op;
- Expression *e = new CommaExp(loc, ((CommaExp *)e2)->e1, ea);
- return e->semantic(sc);
+ { /* Rewrite to get rid of the comma from rvalue
+ */
+ AssignExp *ea = new AssignExp(loc, e1, ((CommaExp *)e2)->e2);
+ ea->op = op;
+ Expression *e = new CommaExp(loc, ((CommaExp *)e2)->e1, ea);
+ return e->semantic(sc);
}
/* Look for operator overloading of a[i]=value.
@@ -8173,96 +8173,96 @@ Expression *AssignExp::semantic(Scope *sc)
*/
if (e1->op == TOKarray)
{
- ArrayExp *ae = (ArrayExp *)e1;
- AggregateDeclaration *ad;
- Identifier *id = Id::index;
+ ArrayExp *ae = (ArrayExp *)e1;
+ AggregateDeclaration *ad;
+ Identifier *id = Id::index;
- ae->e1 = ae->e1->semantic(sc);
- Type *t1 = ae->e1->type->toBasetype();
- if (t1->ty == Tstruct)
- {
- ad = ((TypeStruct *)t1)->sym;
- goto L1;
- }
- else if (t1->ty == Tclass)
- {
- ad = ((TypeClass *)t1)->sym;
- L1:
- // Rewrite (a[i] = value) to (a.opIndexAssign(value, i))
- if (search_function(ad, Id::indexass))
- { Expression *e = new DotIdExp(loc, ae->e1, Id::indexass);
- Expressions *a = (Expressions *)ae->arguments->copy();
+ ae->e1 = ae->e1->semantic(sc);
+ Type *t1 = ae->e1->type->toBasetype();
+ if (t1->ty == Tstruct)
+ {
+ ad = ((TypeStruct *)t1)->sym;
+ goto L1;
+ }
+ else if (t1->ty == Tclass)
+ {
+ ad = ((TypeClass *)t1)->sym;
+ L1:
+ // Rewrite (a[i] = value) to (a.opIndexAssign(value, i))
+ if (search_function(ad, Id::indexass))
+ { Expression *e = new DotIdExp(loc, ae->e1, Id::indexass);
+ Expressions *a = (Expressions *)ae->arguments->copy();
- a->insert(0, e2);
- e = new CallExp(loc, e, a);
- e = e->semantic(sc);
- return e;
- }
- else
- {
- // Rewrite (a[i] = value) to (a.opIndex(i, value))
- if (search_function(ad, id))
- { Expression *e = new DotIdExp(loc, ae->e1, id);
+ a->insert(0, e2);
+ e = new CallExp(loc, e, a);
+ e = e->semantic(sc);
+ return e;
+ }
+ else
+ {
+ // Rewrite (a[i] = value) to (a.opIndex(i, value))
+ if (search_function(ad, id))
+ { Expression *e = new DotIdExp(loc, ae->e1, id);
- if (1 || !global.params.useDeprecated)
- error("operator [] assignment overload with opIndex(i, value) illegal, use opIndexAssign(value, i)");
+ if (1 || !global.params.useDeprecated)
+ error("operator [] assignment overload with opIndex(i, value) illegal, use opIndexAssign(value, i)");
- e = new CallExp(loc, e, (Expression *)ae->arguments->data[0], e2);
- e = e->semantic(sc);
- return e;
- }
- }
- }
+ e = new CallExp(loc, e, (Expression *)ae->arguments->data[0], e2);
+ e = e->semantic(sc);
+ return e;
+ }
+ }
+ }
}
/* Look for operator overloading of a[i..j]=value.
* Do it before semantic() otherwise the a[i..j] will have been
* converted to a.opSlice() already.
*/
if (e1->op == TOKslice)
- { Type *t1;
- SliceExp *ae = (SliceExp *)e1;
- AggregateDeclaration *ad;
- Identifier *id = Id::index;
+ { Type *t1;
+ SliceExp *ae = (SliceExp *)e1;
+ AggregateDeclaration *ad;
+ Identifier *id = Id::index;
- ae->e1 = ae->e1->semantic(sc);
- ae->e1 = resolveProperties(sc, ae->e1);
- t1 = ae->e1->type->toBasetype();
- if (t1->ty == Tstruct)
- {
- ad = ((TypeStruct *)t1)->sym;
- goto L2;
- }
- else if (t1->ty == Tclass)
- {
- ad = ((TypeClass *)t1)->sym;
- L2:
- // Rewrite (a[i..j] = value) to (a.opIndexAssign(value, i, j))
- if (search_function(ad, Id::sliceass))
- { Expression *e = new DotIdExp(loc, ae->e1, Id::sliceass);
- Expressions *a = new Expressions();
+ ae->e1 = ae->e1->semantic(sc);
+ ae->e1 = resolveProperties(sc, ae->e1);
+ t1 = ae->e1->type->toBasetype();
+ if (t1->ty == Tstruct)
+ {
+ ad = ((TypeStruct *)t1)->sym;
+ goto L2;
+ }
+ else if (t1->ty == Tclass)
+ {
+ ad = ((TypeClass *)t1)->sym;
+ L2:
+ // Rewrite (a[i..j] = value) to (a.opIndexAssign(value, i, j))
+ if (search_function(ad, Id::sliceass))
+ { Expression *e = new DotIdExp(loc, ae->e1, Id::sliceass);
+ Expressions *a = new Expressions();
- a->push(e2);
- if (ae->lwr)
- { a->push(ae->lwr);
- assert(ae->upr);
- a->push(ae->upr);
- }
- else
- assert(!ae->upr);
- e = new CallExp(loc, e, a);
- e = e->semantic(sc);
- return e;
- }
- }
+ a->push(e2);
+ if (ae->lwr)
+ { a->push(ae->lwr);
+ assert(ae->upr);
+ a->push(ae->upr);
+ }
+ else
+ assert(!ae->upr);
+ e = new CallExp(loc, e, a);
+ e = e->semantic(sc);
+ return e;
+ }
+ }
}
BinExp::semantic(sc);
if (e1->op == TOKdottd)
- { // Rewrite a.b=e2, when b is a template, as a.b(e2)
- Expression *e = new CallExp(loc, e1, e2);
- e = e->semantic(sc);
- return e;
+ { // Rewrite a.b=e2, when b is a template, as a.b(e2)
+ Expression *e = new CallExp(loc, e1, e2);
+ e = e->semantic(sc);
+ return e;
}
e2 = resolveProperties(sc, e2);
@@ -8271,44 +8271,44 @@ Expression *AssignExp::semantic(Scope *sc)
/* Rewrite tuple assignment as a tuple of assignments.
*/
if (e1->op == TOKtuple && e2->op == TOKtuple)
- { TupleExp *tup1 = (TupleExp *)e1;
- TupleExp *tup2 = (TupleExp *)e2;
- size_t dim = tup1->exps->dim;
- if (dim != tup2->exps->dim)
- {
- error("mismatched tuple lengths, %d and %d", (int)dim, (int)tup2->exps->dim);
- }
- else
- { Expressions *exps = new Expressions;
- exps->setDim(dim);
+ { TupleExp *tup1 = (TupleExp *)e1;
+ TupleExp *tup2 = (TupleExp *)e2;
+ size_t dim = tup1->exps->dim;
+ if (dim != tup2->exps->dim)
+ {
+ error("mismatched tuple lengths, %d and %d", (int)dim, (int)tup2->exps->dim);
+ }
+ else
+ { Expressions *exps = new Expressions;
+ exps->setDim(dim);
- for (int i = 0; i < dim; i++)
- { Expression *ex1 = (Expression *)tup1->exps->data[i];
- Expression *ex2 = (Expression *)tup2->exps->data[i];
- exps->data[i] = (void *) new AssignExp(loc, ex1, ex2);
- }
- Expression *e = new TupleExp(loc, exps);
- e = e->semantic(sc);
- return e;
- }
+ for (int i = 0; i < dim; i++)
+ { Expression *ex1 = (Expression *)tup1->exps->data[i];
+ Expression *ex2 = (Expression *)tup2->exps->data[i];
+ exps->data[i] = (void *) new AssignExp(loc, ex1, ex2);
+ }
+ Expression *e = new TupleExp(loc, exps);
+ e = e->semantic(sc);
+ return e;
+ }
}
// Determine if this is an initialization of a reference
int refinit = 0;
if (op == TOKconstruct && e1->op == TOKvar)
- { VarExp *ve = (VarExp *)e1;
- VarDeclaration *v = ve->var->isVarDeclaration();
- if (v->storage_class & (STCout | STCref))
- refinit = 1;
+ { VarExp *ve = (VarExp *)e1;
+ VarDeclaration *v = ve->var->isVarDeclaration();
+ if (v->storage_class & (STCout | STCref))
+ refinit = 1;
}
Type *t1 = e1->type->toBasetype();
if (t1->ty == Tfunction)
- { // Rewrite f=value to f(value)
- Expression *e = new CallExp(loc, e1, e2);
- e = e->semantic(sc);
- return e;
+ { // Rewrite f=value to f(value)
+ Expression *e = new CallExp(loc, e1, e2);
+ e = e->semantic(sc);
+ return e;
}
/* If it is an assignment from a 'foreign' type,
@@ -8316,61 +8316,61 @@ Expression *AssignExp::semantic(Scope *sc)
*/
if (t1->ty == Tclass || t1->ty == Tstruct)
{
- if (!e2->type->implicitConvTo(e1->type))
- {
- Expression *e = op_overload(sc);
- if (e)
- return e;
- }
+ if (!e2->type->implicitConvTo(e1->type))
+ {
+ Expression *e = op_overload(sc);
+ if (e)
+ return e;
+ }
}
e2->rvalue();
if (e1->op == TOKarraylength)
{
- // e1 is not an lvalue, but we let code generator handle it
- ArrayLengthExp *ale = (ArrayLengthExp *)e1;
+ // e1 is not an lvalue, but we let code generator handle it
+ ArrayLengthExp *ale = (ArrayLengthExp *)e1;
- ale->e1 = ale->e1->modifiableLvalue(sc, e1);
+ ale->e1 = ale->e1->modifiableLvalue(sc, e1);
}
else if (e1->op == TOKslice)
- ;
+ ;
else
- { // Try to do a decent error message with the expression
- // before it got constant folded
- if (op != TOKconstruct)
- e1 = e1->modifiableLvalue(sc, e1old);
+ { // Try to do a decent error message with the expression
+ // before it got constant folded
+ if (op != TOKconstruct)
+ e1 = e1->modifiableLvalue(sc, e1old);
}
if (e1->op == TOKslice &&
- t1->nextOf() &&
- e2->implicitConvTo(t1->nextOf())
-// !(t1->nextOf()->equals(e2->type->nextOf()))
+ t1->nextOf() &&
+ e2->implicitConvTo(t1->nextOf())
+// !(t1->nextOf()->equals(e2->type->nextOf()))
)
- { // memset
- ismemset = 1; // make it easy for back end to tell what this is
- e2 = e2->implicitCastTo(sc, t1->next);
+ { // memset
+ ismemset = 1; // make it easy for back end to tell what this is
+ e2 = e2->implicitCastTo(sc, t1->next);
}
else if (t1->ty == Tsarray && !refinit)
{
- error("cannot assign to static array %s", e1->toChars());
+ error("cannot assign to static array %s", e1->toChars());
}
else
{
- e2 = e2->implicitCastTo(sc, e1->type);
+ e2 = e2->implicitCastTo(sc, e1->type);
}
/* Look for array operations
*/
if (e1->op == TOKslice && !ismemset &&
- (e2->op == TOKadd || e2->op == TOKmin ||
- e2->op == TOKmul || e2->op == TOKdiv ||
- e2->op == TOKmod || e2->op == TOKxor ||
- e2->op == TOKand || e2->op == TOKor ||
- e2->op == TOKtilde || e2->op == TOKneg))
+ (e2->op == TOKadd || e2->op == TOKmin ||
+ e2->op == TOKmul || e2->op == TOKdiv ||
+ e2->op == TOKmod || e2->op == TOKxor ||
+ e2->op == TOKand || e2->op == TOKor ||
+ e2->op == TOKtilde || e2->op == TOKneg))
{
- type = e1->type;
- return arrayOp(sc);
+ type = e1->type;
+ return arrayOp(sc);
}
type = e1->type;
@@ -8381,7 +8381,7 @@ Expression *AssignExp::semantic(Scope *sc)
Expression *AssignExp::checkToBoolean()
{
// Things like:
- // if (a = b) ...
+ // if (a = b) ...
// are usually mistakes.
error("'=' does not give a boolean result");
@@ -8391,7 +8391,7 @@ Expression *AssignExp::checkToBoolean()
/************************************************************/
AddAssignExp::AddAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKaddass, sizeof(AddAssignExp), e1, e2)
+ : BinExp(loc, TOKaddass, sizeof(AddAssignExp), e1, e2)
{
}
@@ -8399,100 +8399,100 @@ Expression *AddAssignExp::semantic(Scope *sc)
{ Expression *e;
if (type)
- return this;
+ return this;
BinExp::semantic(sc);
e2 = resolveProperties(sc, e2);
e = op_overload(sc);
if (e)
- return e;
+ return e;
Type *tb1 = e1->type->toBasetype();
Type *tb2 = e2->type->toBasetype();
if (e1->op == TOKslice)
{
- typeCombine(sc);
- type = e1->type;
- return arrayOp(sc);
+ typeCombine(sc);
+ type = e1->type;
+ return arrayOp(sc);
}
else
{
- e1 = e1->modifiableLvalue(sc, e1);
+ e1 = e1->modifiableLvalue(sc, e1);
}
if ((tb1->ty == Tarray || tb1->ty == Tsarray) &&
- (tb2->ty == Tarray || tb2->ty == Tsarray) &&
- tb1->nextOf()->equals(tb2->nextOf())
+ (tb2->ty == Tarray || tb2->ty == Tsarray) &&
+ tb1->nextOf()->equals(tb2->nextOf())
)
{
- type = e1->type;
- e = this;
+ type = e1->type;
+ e = this;
}
else
{
- e1->checkScalar();
- e1->checkNoBool();
- if (tb1->ty == Tpointer && tb2->isintegral())
- e = scaleFactor(sc);
- else if (tb1->ty == Tbit || tb1->ty == Tbool)
- {
+ e1->checkScalar();
+ e1->checkNoBool();
+ if (tb1->ty == Tpointer && tb2->isintegral())
+ e = scaleFactor(sc);
+ else if (tb1->ty == Tbit || tb1->ty == Tbool)
+ {
#if 0
- // Need to rethink this
- if (e1->op != TOKvar)
- { // Rewrite e1+=e2 to (v=&e1),*v=*v+e2
- VarDeclaration *v;
- Expression *ea;
- Expression *ex;
+ // Need to rethink this
+ if (e1->op != TOKvar)
+ { // Rewrite e1+=e2 to (v=&e1),*v=*v+e2
+ VarDeclaration *v;
+ Expression *ea;
+ Expression *ex;
- Identifier *id = Lexer::uniqueId("__name");
+ Identifier *id = Lexer::uniqueId("__name");
- v = new VarDeclaration(loc, tb1->pointerTo(), id, NULL);
- v->semantic(sc);
- if (!sc->insert(v))
- assert(0);
- v->parent = sc->func;
+ v = new VarDeclaration(loc, tb1->pointerTo(), id, NULL);
+ v->semantic(sc);
+ if (!sc->insert(v))
+ assert(0);
+ v->parent = sc->func;
- ea = new AddrExp(loc, e1);
- ea = new AssignExp(loc, new VarExp(loc, v), ea);
+ ea = new AddrExp(loc, e1);
+ ea = new AssignExp(loc, new VarExp(loc, v), ea);
- ex = new VarExp(loc, v);
- ex = new PtrExp(loc, ex);
- e = new AddExp(loc, ex, e2);
- e = new CastExp(loc, e, e1->type);
- e = new AssignExp(loc, ex->syntaxCopy(), e);
+ ex = new VarExp(loc, v);
+ ex = new PtrExp(loc, ex);
+ e = new AddExp(loc, ex, e2);
+ e = new CastExp(loc, e, e1->type);
+ e = new AssignExp(loc, ex->syntaxCopy(), e);
- e = new CommaExp(loc, ea, e);
- }
- else
+ e = new CommaExp(loc, ea, e);
+ }
+ else
#endif
- { // Rewrite e1+=e2 to e1=e1+e2
- // BUG: doesn't account for side effects in e1
- // BUG: other assignment operators for bits aren't handled at all
- e = new AddExp(loc, e1, e2);
- e = new CastExp(loc, e, e1->type);
- e = new AssignExp(loc, e1->syntaxCopy(), e);
- }
- e = e->semantic(sc);
- }
- else
- {
- type = e1->type;
- typeCombine(sc);
- e1->checkArithmetic();
- e2->checkArithmetic();
- checkComplexAddAssign();
- if (type->isreal() || type->isimaginary())
- {
- assert(global.errors || e2->type->isfloating());
- e2 = e2->castTo(sc, e1->type);
- }
- e = this;
+ { // Rewrite e1+=e2 to e1=e1+e2
+ // BUG: doesn't account for side effects in e1
+ // BUG: other assignment operators for bits aren't handled at all
+ e = new AddExp(loc, e1, e2);
+ e = new CastExp(loc, e, e1->type);
+ e = new AssignExp(loc, e1->syntaxCopy(), e);
+ }
+ e = e->semantic(sc);
+ }
+ else
+ {
+ type = e1->type;
+ typeCombine(sc);
+ e1->checkArithmetic();
+ e2->checkArithmetic();
+ checkComplexAddAssign();
+ if (type->isreal() || type->isimaginary())
+ {
+ assert(global.errors || e2->type->isfloating());
+ e2 = e2->castTo(sc, e1->type);
+ }
+ e = this;
- if (e2->type->iscomplex() && !type->iscomplex())
- error("Cannot assign %s to %s", e2->type->toChars(), type->toChars());
- }
+ if (e2->type->iscomplex() && !type->iscomplex())
+ error("Cannot assign %s to %s", e2->type->toChars(), type->toChars());
+ }
}
return e;
}
@@ -8500,7 +8500,7 @@ Expression *AddAssignExp::semantic(Scope *sc)
/************************************************************/
MinAssignExp::MinAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKminass, sizeof(MinAssignExp), e1, e2)
+ : BinExp(loc, TOKminass, sizeof(MinAssignExp), e1, e2)
{
}
@@ -8508,43 +8508,43 @@ Expression *MinAssignExp::semantic(Scope *sc)
{ Expression *e;
if (type)
- return this;
+ return this;
BinExp::semantic(sc);
e2 = resolveProperties(sc, e2);
e = op_overload(sc);
if (e)
- return e;
+ return e;
if (e1->op == TOKslice)
- { // T[] -= ...
- typeCombine(sc);
- type = e1->type;
- return arrayOp(sc);
+ { // T[] -= ...
+ typeCombine(sc);
+ type = e1->type;
+ return arrayOp(sc);
}
e1 = e1->modifiableLvalue(sc, e1);
e1->checkScalar();
e1->checkNoBool();
if (e1->type->ty == Tpointer && e2->type->isintegral())
- e = scaleFactor(sc);
+ e = scaleFactor(sc);
else
{
- e1 = e1->checkArithmetic();
- e2 = e2->checkArithmetic();
- checkComplexAddAssign();
- type = e1->type;
- typeCombine(sc);
- if (type->isreal() || type->isimaginary())
- {
- assert(e2->type->isfloating());
- e2 = e2->castTo(sc, e1->type);
- }
- e = this;
+ e1 = e1->checkArithmetic();
+ e2 = e2->checkArithmetic();
+ checkComplexAddAssign();
+ type = e1->type;
+ typeCombine(sc);
+ if (type->isreal() || type->isimaginary())
+ {
+ assert(e2->type->isfloating());
+ e2 = e2->castTo(sc, e1->type);
+ }
+ e = this;
- if (e2->type->iscomplex() && !type->iscomplex())
- error("Cannot assign %s to %s", e2->type->toChars(), type->toChars());
+ if (e2->type->iscomplex() && !type->iscomplex())
+ error("Cannot assign %s to %s", e2->type->toChars(), type->toChars());
}
return e;
}
@@ -8552,7 +8552,7 @@ Expression *MinAssignExp::semantic(Scope *sc)
/************************************************************/
CatAssignExp::CatAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKcatass, sizeof(CatAssignExp), e1, e2)
+ : BinExp(loc, TOKcatass, sizeof(CatAssignExp), e1, e2)
{
}
@@ -8564,13 +8564,13 @@ Expression *CatAssignExp::semantic(Scope *sc)
e = op_overload(sc);
if (e)
- return e;
+ return e;
if (e1->op == TOKslice)
- { SliceExp *se = (SliceExp *)e1;
+ { SliceExp *se = (SliceExp *)e1;
- if (se->e1->type->toBasetype()->ty == Tsarray)
- error("cannot append to static array %s", se->e1->type->toChars());
+ if (se->e1->type->toBasetype()->ty == Tsarray)
+ error("cannot append to static array %s", se->e1->type->toChars());
}
e1 = e1->modifiableLvalue(sc, e1);
@@ -8583,45 +8583,45 @@ Expression *CatAssignExp::semantic(Scope *sc)
Type *tb1next = tb1->nextOf();
if ((tb1->ty == Tarray) &&
- (tb2->ty == Tarray || tb2->ty == Tsarray) &&
- (e2->implicitConvTo(e1->type)
+ (tb2->ty == Tarray || tb2->ty == Tsarray) &&
+ (e2->implicitConvTo(e1->type)
#if DMDV2
- || tb2->nextOf()->implicitConvTo(tb1next)
+ || tb2->nextOf()->implicitConvTo(tb1next)
#endif
- )
+ )
)
- { // Append array
- e2 = e2->castTo(sc, e1->type);
- type = e1->type;
- e = this;
+ { // Append array
+ e2 = e2->castTo(sc, e1->type);
+ type = e1->type;
+ e = this;
}
else if ((tb1->ty == Tarray) &&
- e2->implicitConvTo(tb1next)
+ e2->implicitConvTo(tb1next)
)
- { // Append element
- e2 = e2->castTo(sc, tb1next);
- type = e1->type;
- e = this;
+ { // Append element
+ e2 = e2->castTo(sc, tb1next);
+ type = e1->type;
+ e = this;
// Reenable when _d_arrayappendwd and cd are in the runtime.
/* }
else if (tb1->ty == Tarray &&
- (tb1next->ty == Tchar || tb1next->ty == Twchar) &&
- e2->implicitConvTo(Type::tdchar)
+ (tb1next->ty == Tchar || tb1next->ty == Twchar) &&
+ e2->implicitConvTo(Type::tdchar)
)
- { // Append dchar to char[] or wchar[]
- e2 = e2->castTo(sc, Type::tdchar);
- type = e1->type;
- e = this;
+ { // Append dchar to char[] or wchar[]
+ e2 = e2->castTo(sc, Type::tdchar);
+ type = e1->type;
+ e = this;
- /* Do not allow appending wchar to char[] because if wchar happens
- * to be a surrogate pair, nothing good can result.
- */
+ /* Do not allow appending wchar to char[] because if wchar happens
+ * to be a surrogate pair, nothing good can result.
+ */
}
else
{
- error("cannot append type %s to type %s", tb2->toChars(), tb1->toChars());
- e = new ErrorExp();
+ error("cannot append type %s to type %s", tb2->toChars(), tb1->toChars());
+ e = new ErrorExp();
}
return e;
}
@@ -8629,7 +8629,7 @@ Expression *CatAssignExp::semantic(Scope *sc)
/************************************************************/
MulAssignExp::MulAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKmulass, sizeof(MulAssignExp), e1, e2)
+ : BinExp(loc, TOKmulass, sizeof(MulAssignExp), e1, e2)
{
}
@@ -8641,22 +8641,22 @@ Expression *MulAssignExp::semantic(Scope *sc)
e = op_overload(sc);
if (e)
- return e;
+ return e;
#if DMDV2
if (e1->op == TOKarraylength)
{
- e = ArrayLengthExp::rewriteOpAssign(this);
- e = e->semantic(sc);
- return e;
+ e = ArrayLengthExp::rewriteOpAssign(this);
+ e = e->semantic(sc);
+ return e;
}
#endif
if (e1->op == TOKslice)
- { // T[] -= ...
- typeCombine(sc);
- type = e1->type;
- return arrayOp(sc);
+ { // T[] -= ...
+ typeCombine(sc);
+ type = e1->type;
+ return arrayOp(sc);
}
e1 = e1->modifiableLvalue(sc, e1);
@@ -8668,36 +8668,36 @@ Expression *MulAssignExp::semantic(Scope *sc)
e2->checkArithmetic();
checkComplexMulAssign();
if (e2->type->isfloating())
- { Type *t1;
- Type *t2;
+ { Type *t1;
+ Type *t2;
- t1 = e1->type;
- t2 = e2->type;
- if (t1->isreal())
- {
- if (t2->isimaginary() || t2->iscomplex())
- {
- e2 = e2->castTo(sc, t1);
- }
- }
- else if (t1->isimaginary())
- {
- if (t2->isimaginary() || t2->iscomplex())
- {
- switch (t1->ty)
- {
- case Timaginary32: t2 = Type::tfloat32; break;
- case Timaginary64: t2 = Type::tfloat64; break;
- case Timaginary80: t2 = Type::tfloat80; break;
- default:
- assert(0);
- }
- e2 = e2->castTo(sc, t2);
- }
- }
+ t1 = e1->type;
+ t2 = e2->type;
+ if (t1->isreal())
+ {
+ if (t2->isimaginary() || t2->iscomplex())
+ {
+ e2 = e2->castTo(sc, t1);
+ }
+ }
+ else if (t1->isimaginary())
+ {
+ if (t2->isimaginary() || t2->iscomplex())
+ {
+ switch (t1->ty)
+ {
+ case Timaginary32: t2 = Type::tfloat32; break;
+ case Timaginary64: t2 = Type::tfloat64; break;
+ case Timaginary80: t2 = Type::tfloat80; break;
+ default:
+ assert(0);
+ }
+ e2 = e2->castTo(sc, t2);
+ }
+ }
- if (e2->type->iscomplex() && !type->iscomplex())
- error("Cannot assign %s to %s", e2->type->toChars(), type->toChars());
+ if (e2->type->iscomplex() && !type->iscomplex())
+ error("Cannot assign %s to %s", e2->type->toChars(), type->toChars());
}
return this;
}
@@ -8705,7 +8705,7 @@ Expression *MulAssignExp::semantic(Scope *sc)
/************************************************************/
DivAssignExp::DivAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKdivass, sizeof(DivAssignExp), e1, e2)
+ : BinExp(loc, TOKdivass, sizeof(DivAssignExp), e1, e2)
{
}
@@ -8717,22 +8717,22 @@ Expression *DivAssignExp::semantic(Scope *sc)
e = op_overload(sc);
if (e)
- return e;
+ return e;
#if DMDV2
if (e1->op == TOKarraylength)
{
- e = ArrayLengthExp::rewriteOpAssign(this);
- e = e->semantic(sc);
- return e;
+ e = ArrayLengthExp::rewriteOpAssign(this);
+ e = e->semantic(sc);
+ return e;
}
#endif
if (e1->op == TOKslice)
- { // T[] -= ...
- typeCombine(sc);
- type = e1->type;
- return arrayOp(sc);
+ { // T[] -= ...
+ typeCombine(sc);
+ type = e1->type;
+ return arrayOp(sc);
}
e1 = e1->modifiableLvalue(sc, e1);
@@ -8744,39 +8744,39 @@ Expression *DivAssignExp::semantic(Scope *sc)
e2->checkArithmetic();
checkComplexMulAssign();
if (e2->type->isimaginary())
- { Type *t1;
- Type *t2;
+ { Type *t1;
+ Type *t2;
- t1 = e1->type;
- if (t1->isreal())
- { // x/iv = i(-x/v)
- // Therefore, the result is 0
- e2 = new CommaExp(loc, e2, new RealExp(loc, 0, t1));
- e2->type = t1;
- e = new AssignExp(loc, e1, e2);
- e->type = t1;
- return e;
- }
- else if (t1->isimaginary())
- { Expression *e;
+ t1 = e1->type;
+ if (t1->isreal())
+ { // x/iv = i(-x/v)
+ // Therefore, the result is 0
+ e2 = new CommaExp(loc, e2, new RealExp(loc, 0, t1));
+ e2->type = t1;
+ e = new AssignExp(loc, e1, e2);
+ e->type = t1;
+ return e;
+ }
+ else if (t1->isimaginary())
+ { Expression *e;
- switch (t1->ty)
- {
- case Timaginary32: t2 = Type::tfloat32; break;
- case Timaginary64: t2 = Type::tfloat64; break;
- case Timaginary80: t2 = Type::tfloat80; break;
- default:
- assert(0);
- }
- e2 = e2->castTo(sc, t2);
- e = new AssignExp(loc, e1, e2);
- e->type = t1;
- return e;
- }
+ switch (t1->ty)
+ {
+ case Timaginary32: t2 = Type::tfloat32; break;
+ case Timaginary64: t2 = Type::tfloat64; break;
+ case Timaginary80: t2 = Type::tfloat80; break;
+ default:
+ assert(0);
+ }
+ e2 = e2->castTo(sc, t2);
+ e = new AssignExp(loc, e1, e2);
+ e->type = t1;
+ return e;
+ }
}
if (e2->type->iscomplex() && !type->iscomplex())
- error("Cannot assign %s to %s", e2->type->toChars(), type->toChars());
+ error("Cannot assign %s to %s", e2->type->toChars(), type->toChars());
return this;
}
@@ -8784,7 +8784,7 @@ Expression *DivAssignExp::semantic(Scope *sc)
/************************************************************/
ModAssignExp::ModAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKmodass, sizeof(ModAssignExp), e1, e2)
+ : BinExp(loc, TOKmodass, sizeof(ModAssignExp), e1, e2)
{
}
@@ -8798,7 +8798,7 @@ Expression *ModAssignExp::semantic(Scope *sc)
/************************************************************/
ShlAssignExp::ShlAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKshlass, sizeof(ShlAssignExp), e1, e2)
+ : BinExp(loc, TOKshlass, sizeof(ShlAssignExp), e1, e2)
{
}
@@ -8811,7 +8811,7 @@ Expression *ShlAssignExp::semantic(Scope *sc)
e = op_overload(sc);
if (e)
- return e;
+ return e;
e1 = e1->modifiableLvalue(sc, e1);
e1->checkScalar();
@@ -8831,7 +8831,7 @@ Expression *ShlAssignExp::semantic(Scope *sc)
/************************************************************/
ShrAssignExp::ShrAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKshrass, sizeof(ShrAssignExp), e1, e2)
+ : BinExp(loc, TOKshrass, sizeof(ShrAssignExp), e1, e2)
{
}
@@ -8843,7 +8843,7 @@ Expression *ShrAssignExp::semantic(Scope *sc)
e = op_overload(sc);
if (e)
- return e;
+ return e;
e1 = e1->modifiableLvalue(sc, e1);
e1->checkScalar();
@@ -8863,7 +8863,7 @@ Expression *ShrAssignExp::semantic(Scope *sc)
/************************************************************/
UshrAssignExp::UshrAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKushrass, sizeof(UshrAssignExp), e1, e2)
+ : BinExp(loc, TOKushrass, sizeof(UshrAssignExp), e1, e2)
{
}
@@ -8875,7 +8875,7 @@ Expression *UshrAssignExp::semantic(Scope *sc)
e = op_overload(sc);
if (e)
- return e;
+ return e;
e1 = e1->modifiableLvalue(sc, e1);
e1->checkScalar();
@@ -8895,7 +8895,7 @@ Expression *UshrAssignExp::semantic(Scope *sc)
/************************************************************/
AndAssignExp::AndAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKandass, sizeof(AndAssignExp), e1, e2)
+ : BinExp(loc, TOKandass, sizeof(AndAssignExp), e1, e2)
{
}
@@ -8907,7 +8907,7 @@ Expression *AndAssignExp::semantic(Scope *sc)
/************************************************************/
OrAssignExp::OrAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKorass, sizeof(OrAssignExp), e1, e2)
+ : BinExp(loc, TOKorass, sizeof(OrAssignExp), e1, e2)
{
}
@@ -8919,7 +8919,7 @@ Expression *OrAssignExp::semantic(Scope *sc)
/************************************************************/
XorAssignExp::XorAssignExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKxorass, sizeof(XorAssignExp), e1, e2)
+ : BinExp(loc, TOKxorass, sizeof(XorAssignExp), e1, e2)
{
}
@@ -8931,7 +8931,7 @@ Expression *XorAssignExp::semantic(Scope *sc)
/************************* AddExp *****************************/
AddExp::AddExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKadd, sizeof(AddExp), e1, e2)
+ : BinExp(loc, TOKadd, sizeof(AddExp), e1, e2)
{
}
@@ -8943,14 +8943,14 @@ Expression *AddExp::semantic(Scope *sc)
#endif
if (!type)
{
- BinExp::semanticp(sc);
+ BinExp::semanticp(sc);
- e = op_overload(sc);
- if (e)
- return e;
+ e = op_overload(sc);
+ if (e)
+ return e;
- Type *tb1 = e1->type->toBasetype();
- Type *tb2 = e2->type->toBasetype();
+ Type *tb1 = e1->type->toBasetype();
+ Type *tb2 = e2->type->toBasetype();
if ((tb1->ty == Tarray || tb1->ty == Tsarray) &&
(tb2->ty == Tarray || tb2->ty == Tsarray) &&
@@ -8960,45 +8960,45 @@ Expression *AddExp::semantic(Scope *sc)
type = e1->type;
e = this;
}
- else if (tb1->ty == Tpointer && e2->type->isintegral() ||
- tb2->ty == Tpointer && e1->type->isintegral())
- e = scaleFactor(sc);
- else if (tb1->ty == Tpointer && tb2->ty == Tpointer)
- {
- incompatibleTypes();
- type = e1->type;
- e = this;
- }
- else
- {
- typeCombine(sc);
- if ((e1->type->isreal() && e2->type->isimaginary()) ||
- (e1->type->isimaginary() && e2->type->isreal()))
- {
- switch (type->toBasetype()->ty)
- {
- case Tfloat32:
- case Timaginary32:
- type = Type::tcomplex32;
- break;
+ else if (tb1->ty == Tpointer && e2->type->isintegral() ||
+ tb2->ty == Tpointer && e1->type->isintegral())
+ e = scaleFactor(sc);
+ else if (tb1->ty == Tpointer && tb2->ty == Tpointer)
+ {
+ incompatibleTypes();
+ type = e1->type;
+ e = this;
+ }
+ else
+ {
+ typeCombine(sc);
+ if ((e1->type->isreal() && e2->type->isimaginary()) ||
+ (e1->type->isimaginary() && e2->type->isreal()))
+ {
+ switch (type->toBasetype()->ty)
+ {
+ case Tfloat32:
+ case Timaginary32:
+ type = Type::tcomplex32;
+ break;
- case Tfloat64:
- case Timaginary64:
- type = Type::tcomplex64;
- break;
+ case Tfloat64:
+ case Timaginary64:
+ type = Type::tcomplex64;
+ break;
- case Tfloat80:
- case Timaginary80:
- type = Type::tcomplex80;
- break;
+ case Tfloat80:
+ case Timaginary80:
+ type = Type::tcomplex80;
+ break;
- default:
- assert(0);
- }
- }
- e = this;
- }
- return e;
+ default:
+ assert(0);
+ }
+ }
+ e = this;
+ }
+ return e;
}
return this;
}
@@ -9006,7 +9006,7 @@ Expression *AddExp::semantic(Scope *sc)
/************************************************************/
MinExp::MinExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKmin, sizeof(MinExp), e1, e2)
+ : BinExp(loc, TOKmin, sizeof(MinExp), e1, e2)
{
}
@@ -9019,81 +9019,81 @@ Expression *MinExp::semantic(Scope *sc)
printf("MinExp::semantic('%s')\n", toChars());
#endif
if (type)
- return this;
+ return this;
BinExp::semanticp(sc);
e = op_overload(sc);
if (e)
- return e;
+ return e;
e = this;
t1 = e1->type->toBasetype();
t2 = e2->type->toBasetype();
if (t1->ty == Tpointer)
{
- if (t2->ty == Tpointer)
- { // Need to divide the result by the stride
- // Replace (ptr - ptr) with (ptr - ptr) / stride
- d_int64 stride;
- Expression *e;
+ if (t2->ty == Tpointer)
+ { // Need to divide the result by the stride
+ // Replace (ptr - ptr) with (ptr - ptr) / stride
+ d_int64 stride;
+ Expression *e;
- typeCombine(sc); // make sure pointer types are compatible
- type = Type::tptrdiff_t;
- stride = t2->nextOf()->size();
- if (stride == 0)
- {
- e = new IntegerExp(loc, 0, Type::tptrdiff_t);
- }
- else
- {
- e = new DivExp(loc, this, new IntegerExp(0, stride, Type::tptrdiff_t));
- e->type = Type::tptrdiff_t;
- }
- return e;
- }
- else if (t2->isintegral())
- e = scaleFactor(sc);
- else
- { error("incompatible types for minus");
- return new IntegerExp(0);
- }
+ typeCombine(sc); // make sure pointer types are compatible
+ type = Type::tptrdiff_t;
+ stride = t2->nextOf()->size();
+ if (stride == 0)
+ {
+ e = new IntegerExp(loc, 0, Type::tptrdiff_t);
+ }
+ else
+ {
+ e = new DivExp(loc, this, new IntegerExp(0, stride, Type::tptrdiff_t));
+ e->type = Type::tptrdiff_t;
+ }
+ return e;
+ }
+ else if (t2->isintegral())
+ e = scaleFactor(sc);
+ else
+ { error("incompatible types for minus");
+ return new IntegerExp(0);
+ }
}
else if (t2->ty == Tpointer)
{
- type = e2->type;
- error("can't subtract pointer from %s", e1->type->toChars());
- return new IntegerExp(0);
+ type = e2->type;
+ error("can't subtract pointer from %s", e1->type->toChars());
+ return new IntegerExp(0);
}
else
{
- typeCombine(sc);
- t1 = e1->type->toBasetype();
- t2 = e2->type->toBasetype();
- if ((t1->isreal() && t2->isimaginary()) ||
- (t1->isimaginary() && t2->isreal()))
- {
- switch (type->ty)
- {
- case Tfloat32:
- case Timaginary32:
- type = Type::tcomplex32;
- break;
+ typeCombine(sc);
+ t1 = e1->type->toBasetype();
+ t2 = e2->type->toBasetype();
+ if ((t1->isreal() && t2->isimaginary()) ||
+ (t1->isimaginary() && t2->isreal()))
+ {
+ switch (type->ty)
+ {
+ case Tfloat32:
+ case Timaginary32:
+ type = Type::tcomplex32;
+ break;
- case Tfloat64:
- case Timaginary64:
- type = Type::tcomplex64;
- break;
+ case Tfloat64:
+ case Timaginary64:
+ type = Type::tcomplex64;
+ break;
- case Tfloat80:
- case Timaginary80:
- type = Type::tcomplex80;
- break;
+ case Tfloat80:
+ case Timaginary80:
+ type = Type::tcomplex80;
+ break;
- default:
- assert(0);
- }
- }
+ default:
+ assert(0);
+ }
+ }
}
return e;
}
@@ -9101,7 +9101,7 @@ Expression *MinExp::semantic(Scope *sc)
/************************* CatExp *****************************/
CatExp::CatExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKcat, sizeof(CatExp), e1, e2)
+ : BinExp(loc, TOKcat, sizeof(CatExp), e1, e2)
{
}
@@ -9111,76 +9111,76 @@ Expression *CatExp::semantic(Scope *sc)
//printf("CatExp::semantic() %s\n", toChars());
if (!type)
{
- BinExp::semanticp(sc);
- e = op_overload(sc);
- if (e)
- return e;
+ BinExp::semanticp(sc);
+ e = op_overload(sc);
+ if (e)
+ return e;
- Type *tb1 = e1->type->toBasetype();
- Type *tb2 = e2->type->toBasetype();
+ Type *tb1 = e1->type->toBasetype();
+ Type *tb2 = e2->type->toBasetype();
- /* BUG: Should handle things like:
- * char c;
- * c ~ ' '
- * ' ' ~ c;
- */
+ /* BUG: Should handle things like:
+ * char c;
+ * c ~ ' '
+ * ' ' ~ c;
+ */
#if 0
- e1->type->print();
- e2->type->print();
+ e1->type->print();
+ e2->type->print();
#endif
- if ((tb1->ty == Tsarray || tb1->ty == Tarray) &&
- e2->type->equals(tb1->next))
- {
- type = tb1->nextOf()->arrayOf();
- if (tb2->ty == Tarray)
- { // Make e2 into [e2]
- e2 = new ArrayLiteralExp(e2->loc, e2);
- e2->type = type;
- }
- return this;
- }
- else if ((tb2->ty == Tsarray || tb2->ty == Tarray) &&
- e1->type->equals(tb2->next))
- {
- type = tb2->nextOf()->arrayOf();
- if (tb1->ty == Tarray)
- { // Make e1 into [e1]
- e1 = new ArrayLiteralExp(e1->loc, e1);
- e1->type = type;
- }
- return this;
- }
+ if ((tb1->ty == Tsarray || tb1->ty == Tarray) &&
+ e2->type->equals(tb1->next))
+ {
+ type = tb1->nextOf()->arrayOf();
+ if (tb2->ty == Tarray)
+ { // Make e2 into [e2]
+ e2 = new ArrayLiteralExp(e2->loc, e2);
+ e2->type = type;
+ }
+ return this;
+ }
+ else if ((tb2->ty == Tsarray || tb2->ty == Tarray) &&
+ e1->type->equals(tb2->next))
+ {
+ type = tb2->nextOf()->arrayOf();
+ if (tb1->ty == Tarray)
+ { // Make e1 into [e1]
+ e1 = new ArrayLiteralExp(e1->loc, e1);
+ e1->type = type;
+ }
+ return this;
+ }
- typeCombine(sc);
+ typeCombine(sc);
- if (type->toBasetype()->ty == Tsarray)
- type = type->toBasetype()->next->arrayOf();
+ if (type->toBasetype()->ty == Tsarray)
+ type = type->toBasetype()->next->arrayOf();
#if 0
- e1->type->print();
- e2->type->print();
- type->print();
- print();
+ e1->type->print();
+ e2->type->print();
+ type->print();
+ print();
#endif
- if (e1->op == TOKstring && e2->op == TOKstring)
- e = optimize(WANTvalue);
- else if (e1->type->equals(e2->type) &&
- (e1->type->toBasetype()->ty == Tarray ||
- e1->type->toBasetype()->ty == Tsarray))
- {
- e = this;
- }
- else
- {
- //printf("(%s) ~ (%s)\n", e1->toChars(), e2->toChars());
- error("Can only concatenate arrays, not (%s ~ %s)",
- e1->type->toChars(), e2->type->toChars());
- type = Type::tint32;
- e = this;
- }
- e->type = e->type->semantic(loc, sc);
- return e;
+ if (e1->op == TOKstring && e2->op == TOKstring)
+ e = optimize(WANTvalue);
+ else if (e1->type->equals(e2->type) &&
+ (e1->type->toBasetype()->ty == Tarray ||
+ e1->type->toBasetype()->ty == Tsarray))
+ {
+ e = this;
+ }
+ else
+ {
+ //printf("(%s) ~ (%s)\n", e1->toChars(), e2->toChars());
+ error("Can only concatenate arrays, not (%s ~ %s)",
+ e1->type->toChars(), e2->type->toChars());
+ type = Type::tint32;
+ e = this;
+ }
+ e->type = e->type->semantic(loc, sc);
+ return e;
}
return this;
}
@@ -9188,7 +9188,7 @@ Expression *CatExp::semantic(Scope *sc)
/************************************************************/
MulExp::MulExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKmul, sizeof(MulExp), e1, e2)
+ : BinExp(loc, TOKmul, sizeof(MulExp), e1, e2)
{
}
@@ -9200,58 +9200,58 @@ Expression *MulExp::semantic(Scope *sc)
#endif
if (type)
{
- return this;
+ return this;
}
BinExp::semanticp(sc);
e = op_overload(sc);
if (e)
- return e;
+ return e;
typeCombine(sc);
if (!e1->isArrayOperand())
- e1->checkArithmetic();
+ e1->checkArithmetic();
if (!e2->isArrayOperand())
- e2->checkArithmetic();
+ e2->checkArithmetic();
if (type->isfloating())
- { Type *t1 = e1->type;
- Type *t2 = e2->type;
+ { Type *t1 = e1->type;
+ Type *t2 = e2->type;
- if (t1->isreal())
- {
- type = t2;
- }
- else if (t2->isreal())
- {
- type = t1;
- }
- else if (t1->isimaginary())
- {
- if (t2->isimaginary())
- { Expression *e;
+ if (t1->isreal())
+ {
+ type = t2;
+ }
+ else if (t2->isreal())
+ {
+ type = t1;
+ }
+ else if (t1->isimaginary())
+ {
+ if (t2->isimaginary())
+ { Expression *e;
- switch (t1->ty)
- {
- case Timaginary32: type = Type::tfloat32; break;
- case Timaginary64: type = Type::tfloat64; break;
- case Timaginary80: type = Type::tfloat80; break;
- default: assert(0);
- }
+ switch (t1->ty)
+ {
+ case Timaginary32: type = Type::tfloat32; break;
+ case Timaginary64: type = Type::tfloat64; break;
+ case Timaginary80: type = Type::tfloat80; break;
+ default: assert(0);
+ }
- // iy * iv = -yv
- e1->type = type;
- e2->type = type;
- e = new NegExp(loc, this);
- e = e->semantic(sc);
- return e;
- }
- else
- type = t2; // t2 is complex
- }
- else if (t2->isimaginary())
- {
- type = t1; // t1 is complex
- }
+ // iy * iv = -yv
+ e1->type = type;
+ e2->type = type;
+ e = new NegExp(loc, this);
+ e = e->semantic(sc);
+ return e;
+ }
+ else
+ type = t2; // t2 is complex
+ }
+ else if (t2->isimaginary())
+ {
+ type = t1; // t1 is complex
+ }
}
return this;
}
@@ -9259,7 +9259,7 @@ Expression *MulExp::semantic(Scope *sc)
/************************************************************/
DivExp::DivExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKdiv, sizeof(DivExp), e1, e2)
+ : BinExp(loc, TOKdiv, sizeof(DivExp), e1, e2)
{
}
@@ -9267,58 +9267,58 @@ Expression *DivExp::semantic(Scope *sc)
{ Expression *e;
if (type)
- return this;
+ return this;
BinExp::semanticp(sc);
e = op_overload(sc);
if (e)
- return e;
+ return e;
typeCombine(sc);
if (!e1->isArrayOperand())
- e1->checkArithmetic();
+ e1->checkArithmetic();
if (!e2->isArrayOperand())
- e2->checkArithmetic();
+ e2->checkArithmetic();
if (type->isfloating())
- { Type *t1 = e1->type;
- Type *t2 = e2->type;
+ { Type *t1 = e1->type;
+ Type *t2 = e2->type;
- if (t1->isreal())
- {
- type = t2;
- if (t2->isimaginary())
- { Expression *e;
+ if (t1->isreal())
+ {
+ type = t2;
+ if (t2->isimaginary())
+ { Expression *e;
- // x/iv = i(-x/v)
- e2->type = t1;
- e = new NegExp(loc, this);
- e = e->semantic(sc);
- return e;
- }
- }
- else if (t2->isreal())
- {
- type = t1;
- }
- else if (t1->isimaginary())
- {
- if (t2->isimaginary())
- {
- switch (t1->ty)
- {
- case Timaginary32: type = Type::tfloat32; break;
- case Timaginary64: type = Type::tfloat64; break;
- case Timaginary80: type = Type::tfloat80; break;
- default: assert(0);
- }
- }
- else
- type = t2; // t2 is complex
- }
- else if (t2->isimaginary())
- {
- type = t1; // t1 is complex
- }
+ // x/iv = i(-x/v)
+ e2->type = t1;
+ e = new NegExp(loc, this);
+ e = e->semantic(sc);
+ return e;
+ }
+ }
+ else if (t2->isreal())
+ {
+ type = t1;
+ }
+ else if (t1->isimaginary())
+ {
+ if (t2->isimaginary())
+ {
+ switch (t1->ty)
+ {
+ case Timaginary32: type = Type::tfloat32; break;
+ case Timaginary64: type = Type::tfloat64; break;
+ case Timaginary80: type = Type::tfloat80; break;
+ default: assert(0);
+ }
+ }
+ else
+ type = t2; // t2 is complex
+ }
+ else if (t2->isimaginary())
+ {
+ type = t1; // t1 is complex
+ }
}
return this;
}
@@ -9326,7 +9326,7 @@ Expression *DivExp::semantic(Scope *sc)
/************************************************************/
ModExp::ModExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKmod, sizeof(ModExp), e1, e2)
+ : BinExp(loc, TOKmod, sizeof(ModExp), e1, e2)
{
}
@@ -9334,24 +9334,24 @@ Expression *ModExp::semantic(Scope *sc)
{ Expression *e;
if (type)
- return this;
+ return this;
BinExp::semanticp(sc);
e = op_overload(sc);
if (e)
- return e;
+ return e;
typeCombine(sc);
if (!e1->isArrayOperand())
- e1->checkArithmetic();
+ e1->checkArithmetic();
if (!e2->isArrayOperand())
- e2->checkArithmetic();
+ e2->checkArithmetic();
if (type->isfloating())
- { type = e1->type;
- if (e2->type->iscomplex())
- { error("cannot perform modulo complex arithmetic");
- return new IntegerExp(0);
- }
+ { type = e1->type;
+ if (e2->type->iscomplex())
+ { error("cannot perform modulo complex arithmetic");
+ return new IntegerExp(0);
+ }
}
return this;
}
@@ -9359,7 +9359,7 @@ Expression *ModExp::semantic(Scope *sc)
/************************************************************/
ShlExp::ShlExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKshl, sizeof(ShlExp), e1, e2)
+ : BinExp(loc, TOKshl, sizeof(ShlExp), e1, e2)
{
}
@@ -9368,19 +9368,19 @@ Expression *ShlExp::semantic(Scope *sc)
//printf("ShlExp::semantic(), type = %p\n", type);
if (!type)
- { BinExp::semanticp(sc);
- e = op_overload(sc);
- if (e)
- return e;
- e1 = e1->checkIntegral();
- e2 = e2->checkIntegral();
- e1 = e1->integralPromotions(sc);
+ { BinExp::semanticp(sc);
+ e = op_overload(sc);
+ if (e)
+ return e;
+ e1 = e1->checkIntegral();
+ e2 = e2->checkIntegral();
+ e1 = e1->integralPromotions(sc);
#if !IN_LLVM
- e2 = e2->castTo(sc, Type::tshiftcnt);
+ e2 = e2->castTo(sc, Type::tshiftcnt);
#else
e2 = e2->castTo(sc, e1->type);
#endif
- type = e1->type;
+ type = e1->type;
}
return this;
}
@@ -9388,7 +9388,7 @@ Expression *ShlExp::semantic(Scope *sc)
/************************************************************/
ShrExp::ShrExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKshr, sizeof(ShrExp), e1, e2)
+ : BinExp(loc, TOKshr, sizeof(ShrExp), e1, e2)
{
}
@@ -9396,19 +9396,19 @@ Expression *ShrExp::semantic(Scope *sc)
{ Expression *e;
if (!type)
- { BinExp::semanticp(sc);
- e = op_overload(sc);
- if (e)
- return e;
- e1 = e1->checkIntegral();
- e2 = e2->checkIntegral();
- e1 = e1->integralPromotions(sc);
+ { BinExp::semanticp(sc);
+ e = op_overload(sc);
+ if (e)
+ return e;
+ e1 = e1->checkIntegral();
+ e2 = e2->checkIntegral();
+ e1 = e1->integralPromotions(sc);
#if !IN_LLVM
- e2 = e2->castTo(sc, Type::tshiftcnt);
+ e2 = e2->castTo(sc, Type::tshiftcnt);
#else
e2 = e2->castTo(sc, e1->type);
#endif
- type = e1->type;
+ type = e1->type;
}
return this;
}
@@ -9416,7 +9416,7 @@ Expression *ShrExp::semantic(Scope *sc)
/************************************************************/
UshrExp::UshrExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKushr, sizeof(UshrExp), e1, e2)
+ : BinExp(loc, TOKushr, sizeof(UshrExp), e1, e2)
{
}
@@ -9424,19 +9424,19 @@ Expression *UshrExp::semantic(Scope *sc)
{ Expression *e;
if (!type)
- { BinExp::semanticp(sc);
- e = op_overload(sc);
- if (e)
- return e;
- e1 = e1->checkIntegral();
- e2 = e2->checkIntegral();
- e1 = e1->integralPromotions(sc);
+ { BinExp::semanticp(sc);
+ e = op_overload(sc);
+ if (e)
+ return e;
+ e1 = e1->checkIntegral();
+ e2 = e2->checkIntegral();
+ e1 = e1->integralPromotions(sc);
#if !IN_LLVM
- e2 = e2->castTo(sc, Type::tshiftcnt);
+ e2 = e2->castTo(sc, Type::tshiftcnt);
#else
e2 = e2->castTo(sc, e1->type);
#endif
- type = e1->type;
+ type = e1->type;
}
return this;
}
@@ -9444,7 +9444,7 @@ Expression *UshrExp::semantic(Scope *sc)
/************************************************************/
AndExp::AndExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKand, sizeof(AndExp), e1, e2)
+ : BinExp(loc, TOKand, sizeof(AndExp), e1, e2)
{
}
@@ -9452,24 +9452,24 @@ Expression *AndExp::semantic(Scope *sc)
{ Expression *e;
if (!type)
- { BinExp::semanticp(sc);
- e = op_overload(sc);
- if (e)
- return e;
- if (e1->type->toBasetype()->ty == Tbool &&
- e2->type->toBasetype()->ty == Tbool)
- {
- type = e1->type;
- e = this;
- }
- else
- {
- typeCombine(sc);
- if (!e1->isArrayOperand())
- e1->checkIntegral();
- if (!e2->isArrayOperand())
- e2->checkIntegral();
- }
+ { BinExp::semanticp(sc);
+ e = op_overload(sc);
+ if (e)
+ return e;
+ if (e1->type->toBasetype()->ty == Tbool &&
+ e2->type->toBasetype()->ty == Tbool)
+ {
+ type = e1->type;
+ e = this;
+ }
+ else
+ {
+ typeCombine(sc);
+ if (!e1->isArrayOperand())
+ e1->checkIntegral();
+ if (!e2->isArrayOperand())
+ e2->checkIntegral();
+ }
}
return this;
}
@@ -9477,7 +9477,7 @@ Expression *AndExp::semantic(Scope *sc)
/************************************************************/
OrExp::OrExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKor, sizeof(OrExp), e1, e2)
+ : BinExp(loc, TOKor, sizeof(OrExp), e1, e2)
{
}
@@ -9485,24 +9485,24 @@ Expression *OrExp::semantic(Scope *sc)
{ Expression *e;
if (!type)
- { BinExp::semanticp(sc);
- e = op_overload(sc);
- if (e)
- return e;
- if (e1->type->toBasetype()->ty == Tbool &&
- e2->type->toBasetype()->ty == Tbool)
- {
- type = e1->type;
- e = this;
- }
- else
- {
- typeCombine(sc);
- if (!e1->isArrayOperand())
- e1->checkIntegral();
- if (!e2->isArrayOperand())
- e2->checkIntegral();
- }
+ { BinExp::semanticp(sc);
+ e = op_overload(sc);
+ if (e)
+ return e;
+ if (e1->type->toBasetype()->ty == Tbool &&
+ e2->type->toBasetype()->ty == Tbool)
+ {
+ type = e1->type;
+ e = this;
+ }
+ else
+ {
+ typeCombine(sc);
+ if (!e1->isArrayOperand())
+ e1->checkIntegral();
+ if (!e2->isArrayOperand())
+ e2->checkIntegral();
+ }
}
return this;
}
@@ -9510,7 +9510,7 @@ Expression *OrExp::semantic(Scope *sc)
/************************************************************/
XorExp::XorExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKxor, sizeof(XorExp), e1, e2)
+ : BinExp(loc, TOKxor, sizeof(XorExp), e1, e2)
{
}
@@ -9518,24 +9518,24 @@ Expression *XorExp::semantic(Scope *sc)
{ Expression *e;
if (!type)
- { BinExp::semanticp(sc);
- e = op_overload(sc);
- if (e)
- return e;
- if (e1->type->toBasetype()->ty == Tbool &&
- e2->type->toBasetype()->ty == Tbool)
- {
- type = e1->type;
- e = this;
- }
- else
- {
- typeCombine(sc);
- if (!e1->isArrayOperand())
- e1->checkIntegral();
- if (!e2->isArrayOperand())
- e2->checkIntegral();
- }
+ { BinExp::semanticp(sc);
+ e = op_overload(sc);
+ if (e)
+ return e;
+ if (e1->type->toBasetype()->ty == Tbool &&
+ e2->type->toBasetype()->ty == Tbool)
+ {
+ type = e1->type;
+ e = this;
+ }
+ else
+ {
+ typeCombine(sc);
+ if (!e1->isArrayOperand())
+ e1->checkIntegral();
+ if (!e2->isArrayOperand())
+ e2->checkIntegral();
+ }
}
return this;
}
@@ -9544,7 +9544,7 @@ Expression *XorExp::semantic(Scope *sc)
/************************************************************/
OrOrExp::OrOrExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKoror, sizeof(OrOrExp), e1, e2)
+ : BinExp(loc, TOKoror, sizeof(OrOrExp), e1, e2)
{
}
@@ -9561,13 +9561,13 @@ Expression *OrOrExp::semantic(Scope *sc)
if (sc->flags & SCOPEstaticif)
{
- /* If in static if, don't evaluate e2 if we don't have to.
- */
- e1 = e1->optimize(WANTflags);
- if (e1->isBool(TRUE))
- {
- return new IntegerExp(loc, 1, Type::tboolean);
- }
+ /* If in static if, don't evaluate e2 if we don't have to.
+ */
+ e1 = e1->optimize(WANTflags);
+ if (e1->isBool(TRUE))
+ {
+ return new IntegerExp(loc, 1, Type::tboolean);
+ }
}
e2 = e2->semantic(sc);
@@ -9577,9 +9577,9 @@ Expression *OrOrExp::semantic(Scope *sc)
type = Type::tboolean;
if (e2->type->ty == Tvoid)
- type = Type::tvoid;
+ type = Type::tvoid;
if (e2->op == TOKtype || e2->op == TOKimport)
- error("%s is not an expression", e2->toChars());
+ error("%s is not an expression", e2->toChars());
return this;
}
@@ -9598,18 +9598,18 @@ int OrOrExp::checkSideEffect(int flag)
{
if (flag == 2)
{
- return e1->checkSideEffect(2) || e2->checkSideEffect(2);
+ return e1->checkSideEffect(2) || e2->checkSideEffect(2);
}
else
- { e1->checkSideEffect(1);
- return e2->checkSideEffect(flag);
+ { e1->checkSideEffect(1);
+ return e2->checkSideEffect(flag);
}
}
/************************************************************/
AndAndExp::AndAndExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKandand, sizeof(AndAndExp), e1, e2)
+ : BinExp(loc, TOKandand, sizeof(AndAndExp), e1, e2)
{
}
@@ -9626,13 +9626,13 @@ Expression *AndAndExp::semantic(Scope *sc)
if (sc->flags & SCOPEstaticif)
{
- /* If in static if, don't evaluate e2 if we don't have to.
- */
- e1 = e1->optimize(WANTflags);
- if (e1->isBool(FALSE))
- {
- return new IntegerExp(loc, 0, Type::tboolean);
- }
+ /* If in static if, don't evaluate e2 if we don't have to.
+ */
+ e1 = e1->optimize(WANTflags);
+ if (e1->isBool(FALSE))
+ {
+ return new IntegerExp(loc, 0, Type::tboolean);
+ }
}
e2 = e2->semantic(sc);
@@ -9642,9 +9642,9 @@ Expression *AndAndExp::semantic(Scope *sc)
type = Type::tboolean;
if (e2->type->ty == Tvoid)
- type = Type::tvoid;
+ type = Type::tvoid;
if (e2->op == TOKtype || e2->op == TOKimport)
- error("%s is not an expression", e2->toChars());
+ error("%s is not an expression", e2->toChars());
return this;
}
@@ -9663,19 +9663,19 @@ int AndAndExp::checkSideEffect(int flag)
{
if (flag == 2)
{
- return e1->checkSideEffect(2) || e2->checkSideEffect(2);
+ return e1->checkSideEffect(2) || e2->checkSideEffect(2);
}
else
{
- e1->checkSideEffect(1);
- return e2->checkSideEffect(flag);
+ e1->checkSideEffect(1);
+ return e2->checkSideEffect(flag);
}
}
/************************************************************/
InExp::InExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKin, sizeof(InExp), e1, e2)
+ : BinExp(loc, TOKin, sizeof(InExp), e1, e2)
{
}
@@ -9683,29 +9683,29 @@ Expression *InExp::semantic(Scope *sc)
{ Expression *e;
if (type)
- return this;
+ return this;
BinExp::semanticp(sc);
e = op_overload(sc);
if (e)
- return e;
+ return e;
//type = Type::tboolean;
Type *t2b = e2->type->toBasetype();
if (t2b->ty != Taarray)
{
- error("rvalue of in expression must be an associative array, not %s", e2->type->toChars());
- type = Type::terror;
+ error("rvalue of in expression must be an associative array, not %s", e2->type->toChars());
+ type = Type::terror;
}
else
{
- TypeAArray *ta = (TypeAArray *)t2b;
+ TypeAArray *ta = (TypeAArray *)t2b;
- // Convert key to type of key
- e1 = e1->implicitCastTo(sc, ta->index);
+ // Convert key to type of key
+ e1 = e1->implicitCastTo(sc, ta->index);
- // Return type is pointer to value
- type = ta->nextOf()->pointerTo();
+ // Return type is pointer to value
+ type = ta->nextOf()->pointerTo();
}
return this;
}
@@ -9722,7 +9722,7 @@ int InExp::isBit()
*/
RemoveExp::RemoveExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKremove, sizeof(RemoveExp), e1, e2)
+ : BinExp(loc, TOKremove, sizeof(RemoveExp), e1, e2)
{
type = Type::tvoid;
}
@@ -9730,7 +9730,7 @@ RemoveExp::RemoveExp(Loc loc, Expression *e1, Expression *e2)
/************************************************************/
CmpExp::CmpExp(enum TOK op, Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, op, sizeof(CmpExp), e1, e2)
+ : BinExp(loc, op, sizeof(CmpExp), e1, e2)
{
}
@@ -9741,40 +9741,40 @@ Expression *CmpExp::semantic(Scope *sc)
printf("CmpExp::semantic('%s')\n", toChars());
#endif
if (type)
- return this;
+ return this;
BinExp::semanticp(sc);
Type *t1 = e1->type->toBasetype();
Type *t2 = e2->type->toBasetype();
if (t1->ty == Tclass && e2->op == TOKnull ||
- t2->ty == Tclass && e1->op == TOKnull)
+ t2->ty == Tclass && e1->op == TOKnull)
{
- error("do not use null when comparing class types");
+ error("do not use null when comparing class types");
}
e = op_overload(sc);
if (e)
{
- if (!e->type->isscalar() && e->type->equals(e1->type))
- {
- error("recursive opCmp expansion");
- e = new ErrorExp();
- }
- else
- { e = new CmpExp(op, loc, e, new IntegerExp(loc, 0, Type::tint32));
- e = e->semantic(sc);
- }
- return e;
+ if (!e->type->isscalar() && e->type->equals(e1->type))
+ {
+ error("recursive opCmp expansion");
+ e = new ErrorExp();
+ }
+ else
+ { e = new CmpExp(op, loc, e, new IntegerExp(loc, 0, Type::tint32));
+ e = e->semantic(sc);
+ }
+ return e;
}
/* Disallow comparing T[]==T and T==T[]
*/
if (e1->op == TOKslice && t1->ty == Tarray && e2->implicitConvTo(t1->nextOf()) ||
- e2->op == TOKslice && t2->ty == Tarray && e1->implicitConvTo(t2->nextOf()))
+ e2->op == TOKslice && t2->ty == Tarray && e1->implicitConvTo(t2->nextOf()))
{
- incompatibleTypes();
- return new ErrorExp();
+ incompatibleTypes();
+ return new ErrorExp();
}
typeCombine(sc);
@@ -9784,30 +9784,30 @@ Expression *CmpExp::semantic(Scope *sc)
t1 = e1->type->toBasetype();
t2 = e2->type->toBasetype();
if ((t1->ty == Tarray || t1->ty == Tsarray) &&
- (t2->ty == Tarray || t2->ty == Tsarray))
+ (t2->ty == Tarray || t2->ty == Tsarray))
{
- if (!t1->next->equals(t2->next))
- error("array comparison type mismatch, %s vs %s", t1->next->toChars(), t2->next->toChars());
- e = this;
+ if (!t1->next->equals(t2->next))
+ error("array comparison type mismatch, %s vs %s", t1->next->toChars(), t2->next->toChars());
+ e = this;
}
else if (t1->ty == Tstruct || t2->ty == Tstruct ||
- (t1->ty == Tclass && t2->ty == Tclass))
+ (t1->ty == Tclass && t2->ty == Tclass))
{
- if (t2->ty == Tstruct)
- error("need member function opCmp() for %s %s to compare", t2->toDsymbol(sc)->kind(), t2->toChars());
- else
- error("need member function opCmp() for %s %s to compare", t1->toDsymbol(sc)->kind(), t1->toChars());
- e = this;
+ if (t2->ty == Tstruct)
+ error("need member function opCmp() for %s %s to compare", t2->toDsymbol(sc)->kind(), t2->toChars());
+ else
+ error("need member function opCmp() for %s %s to compare", t1->toDsymbol(sc)->kind(), t1->toChars());
+ e = this;
}
#if 1
else if (t1->iscomplex() || t2->iscomplex())
{
- error("compare not defined for complex operands");
- e = new IntegerExp(0);
+ error("compare not defined for complex operands");
+ e = new IntegerExp(0);
}
#endif
else
- e = this;
+ e = this;
//printf("CmpExp: %s\n", e->toChars());
return e;
}
@@ -9821,7 +9821,7 @@ int CmpExp::isBit()
/************************************************************/
EqualExp::EqualExp(enum TOK op, Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, op, sizeof(EqualExp), e1, e2)
+ : BinExp(loc, op, sizeof(EqualExp), e1, e2)
{
assert(op == TOKequal || op == TOKnotequal);
}
@@ -9831,7 +9831,7 @@ Expression *EqualExp::semantic(Scope *sc)
//printf("EqualExp::semantic('%s')\n", toChars());
if (type)
- return this;
+ return this;
BinExp::semanticp(sc);
@@ -9840,53 +9840,53 @@ Expression *EqualExp::semantic(Scope *sc)
* if they are the same symbol.
*/
if (e1->op == TOKaddress && e2->op == TOKaddress)
- { AddrExp *ae1 = (AddrExp *)e1;
- AddrExp *ae2 = (AddrExp *)e2;
+ { AddrExp *ae1 = (AddrExp *)e1;
+ AddrExp *ae2 = (AddrExp *)e2;
- if (ae1->e1->op == TOKvar && ae2->e1->op == TOKvar)
- { VarExp *ve1 = (VarExp *)ae1->e1;
- VarExp *ve2 = (VarExp *)ae2->e1;
+ if (ae1->e1->op == TOKvar && ae2->e1->op == TOKvar)
+ { VarExp *ve1 = (VarExp *)ae1->e1;
+ VarExp *ve2 = (VarExp *)ae2->e1;
- if (ve1->var == ve2->var /*|| ve1->var->toSymbol() == ve2->var->toSymbol()*/)
- {
- // They are the same, result is 'true' for ==, 'false' for !=
- e = new IntegerExp(loc, (op == TOKequal), Type::tboolean);
- return e;
- }
- }
+ if (ve1->var == ve2->var /*|| ve1->var->toSymbol() == ve2->var->toSymbol()*/)
+ {
+ // They are the same, result is 'true' for ==, 'false' for !=
+ e = new IntegerExp(loc, (op == TOKequal), Type::tboolean);
+ return e;
+ }
+ }
}
Type *t1 = e1->type->toBasetype();
Type *t2 = e2->type->toBasetype();
if (t1->ty == Tclass && e2->op == TOKnull ||
- t2->ty == Tclass && e1->op == TOKnull)
+ t2->ty == Tclass && e1->op == TOKnull)
{
- error("use '%s' instead of '%s' when comparing with null",
- Token::toChars(op == TOKequal ? TOKidentity : TOKnotidentity),
- Token::toChars(op));
+ error("use '%s' instead of '%s' when comparing with null",
+ Token::toChars(op == TOKequal ? TOKidentity : TOKnotidentity),
+ Token::toChars(op));
}
//if (e2->op != TOKnull)
{
- e = op_overload(sc);
- if (e)
- {
- if (op == TOKnotequal)
- {
- e = new NotExp(e->loc, e);
- e = e->semantic(sc);
- }
- return e;
- }
+ e = op_overload(sc);
+ if (e)
+ {
+ if (op == TOKnotequal)
+ {
+ e = new NotExp(e->loc, e);
+ e = e->semantic(sc);
+ }
+ return e;
+ }
}
/* Disallow comparing T[]==T and T==T[]
*/
if (e1->op == TOKslice && t1->ty == Tarray && e2->implicitConvTo(t1->nextOf()) ||
- e2->op == TOKslice && t2->ty == Tarray && e1->implicitConvTo(t2->nextOf()))
+ e2->op == TOKslice && t2->ty == Tarray && e1->implicitConvTo(t2->nextOf()))
{
- incompatibleTypes();
- return new ErrorExp();
+ incompatibleTypes();
+ return new ErrorExp();
}
e = typeCombine(sc);
@@ -9896,19 +9896,19 @@ Expression *EqualExp::semantic(Scope *sc)
t1 = e1->type->toBasetype();
t2 = e2->type->toBasetype();
if ((t1->ty == Tarray || t1->ty == Tsarray) &&
- (t2->ty == Tarray || t2->ty == Tsarray))
+ (t2->ty == Tarray || t2->ty == Tsarray))
{
- if (!t1->next->equals(t2->next))
- error("array comparison type mismatch, %s vs %s", t1->next->toChars(), t2->next->toChars());
+ if (!t1->next->equals(t2->next))
+ error("array comparison type mismatch, %s vs %s", t1->next->toChars(), t2->next->toChars());
}
else
{
- if (e1->type != e2->type && e1->type->isfloating() && e2->type->isfloating())
- {
- // Cast both to complex
- e1 = e1->castTo(sc, Type::tcomplex80);
- e2 = e2->castTo(sc, Type::tcomplex80);
- }
+ if (e1->type != e2->type && e1->type->isfloating() && e2->type->isfloating())
+ {
+ // Cast both to complex
+ e1 = e1->castTo(sc, Type::tcomplex80);
+ e2 = e2->castTo(sc, Type::tcomplex80);
+ }
}
return e;
}
@@ -9923,23 +9923,23 @@ int EqualExp::isBit()
/************************************************************/
IdentityExp::IdentityExp(enum TOK op, Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, op, sizeof(IdentityExp), e1, e2)
+ : BinExp(loc, op, sizeof(IdentityExp), e1, e2)
{
}
Expression *IdentityExp::semantic(Scope *sc)
{
if (type)
- return this;
+ return this;
BinExp::semanticp(sc);
type = Type::tboolean;
typeCombine(sc);
if (e1->type != e2->type && e1->type->isfloating() && e2->type->isfloating())
{
- // Cast both to complex
- e1 = e1->castTo(sc, Type::tcomplex80);
- e2 = e2->castTo(sc, Type::tcomplex80);
+ // Cast both to complex
+ e1 = e1->castTo(sc, Type::tcomplex80);
+ e2 = e2->castTo(sc, Type::tcomplex80);
}
return this;
}
@@ -9953,7 +9953,7 @@ int IdentityExp::isBit()
/****************************************************************/
CondExp::CondExp(Loc loc, Expression *econd, Expression *e1, Expression *e2)
- : BinExp(loc, TOKquestion, sizeof(CondExp), e1, e2)
+ : BinExp(loc, TOKquestion, sizeof(CondExp), e1, e2)
{
this->econd = econd;
}
@@ -9974,33 +9974,33 @@ Expression *CondExp::semantic(Scope *sc)
printf("CondExp::semantic('%s')\n", toChars());
#endif
if (type)
- return this;
+ return this;
econd = econd->semantic(sc);
econd = resolveProperties(sc, econd);
econd = econd->checkToPointer();
econd = econd->checkToBoolean();
-#if 0 /* this cannot work right because the types of e1 and e2
- * both contribute to the type of the result.
- */
+#if 0 /* this cannot work right because the types of e1 and e2
+ * both contribute to the type of the result.
+ */
if (sc->flags & SCOPEstaticif)
{
- /* If in static if, don't evaluate what we don't have to.
- */
- econd = econd->optimize(WANTflags);
- if (econd->isBool(TRUE))
- {
- e1 = e1->semantic(sc);
- e1 = resolveProperties(sc, e1);
- return e1;
- }
- else if (econd->isBool(FALSE))
- {
- e2 = e2->semantic(sc);
- e2 = resolveProperties(sc, e2);
- return e2;
- }
+ /* If in static if, don't evaluate what we don't have to.
+ */
+ econd = econd->optimize(WANTflags);
+ if (econd->isBool(TRUE))
+ {
+ e1 = e1->semantic(sc);
+ e1 = resolveProperties(sc, e1);
+ return e1;
+ }
+ else if (econd->isBool(FALSE))
+ {
+ e2 = e2->semantic(sc);
+ e2 = resolveProperties(sc, e2);
+ return e2;
+ }
}
#endif
@@ -10019,28 +10019,28 @@ Expression *CondExp::semantic(Scope *sc)
t1 = e1->type;
t2 = e2->type;
if (t1->ty == Tvoid || t2->ty == Tvoid)
- type = Type::tvoid;
+ type = Type::tvoid;
else if (t1 == t2)
- type = t1;
+ type = t1;
else
{
- typeCombine(sc);
- switch (e1->type->toBasetype()->ty)
- {
- case Tcomplex32:
- case Tcomplex64:
- case Tcomplex80:
- e2 = e2->castTo(sc, e1->type);
- break;
- }
- switch (e2->type->toBasetype()->ty)
- {
- case Tcomplex32:
- case Tcomplex64:
- case Tcomplex80:
- e1 = e1->castTo(sc, e2->type);
- break;
- }
+ typeCombine(sc);
+ switch (e1->type->toBasetype()->ty)
+ {
+ case Tcomplex32:
+ case Tcomplex64:
+ case Tcomplex80:
+ e2 = e2->castTo(sc, e1->type);
+ break;
+ }
+ switch (e2->type->toBasetype()->ty)
+ {
+ case Tcomplex32:
+ case Tcomplex64:
+ case Tcomplex80:
+ e1 = e1->castTo(sc, e2->type);
+ break;
+ }
}
#if 0
printf("res: %s\n", type->toChars());
@@ -10106,15 +10106,15 @@ int CondExp::checkSideEffect(int flag)
{
if (flag == 2)
{
- return econd->checkSideEffect(2) ||
- e1->checkSideEffect(2) ||
- e2->checkSideEffect(2);
+ return econd->checkSideEffect(2) ||
+ e1->checkSideEffect(2) ||
+ e2->checkSideEffect(2);
}
else
{
- econd->checkSideEffect(1);
- e1->checkSideEffect(flag);
- return e2->checkSideEffect(flag);
+ econd->checkSideEffect(1);
+ e1->checkSideEffect(flag);
+ return e2->checkSideEffect(flag);
}
}
diff --git a/dmd/expression.h b/dmd/expression.h
index 8f36b32f..eda63855 100644
--- a/dmd/expression.h
+++ b/dmd/expression.h
@@ -53,7 +53,7 @@ struct IRState;
struct dt_t;
struct elem;
-struct Symbol; // back end symbol
+struct Symbol; // back end symbol
#endif
#ifdef IN_GCC
@@ -89,17 +89,17 @@ struct IntRange
struct Expression : Object
{
- Loc loc; // file location
- enum TOK op; // handy to minimize use of dynamic_cast
- Type *type; // !=NULL means that semantic() has been run
- int size; // # of bytes in Expression so we can copy() it
+ Loc loc; // file location
+ enum TOK op; // handy to minimize use of dynamic_cast
+ Type *type; // !=NULL means that semantic() has been run
+ int size; // # of bytes in Expression so we can copy() it
Expression(Loc loc, enum TOK op, int size);
Expression *copy();
virtual Expression *syntaxCopy();
virtual Expression *semantic(Scope *sc);
- int dyncast() { return DYNCAST_EXPRESSION; } // kludge for template.isExpression()
+ int dyncast() { return DYNCAST_EXPRESSION; } // kludge for template.isExpression()
void print();
char *toChars();
@@ -140,8 +140,8 @@ struct Expression : Object
virtual void scanForNestedRef(Scope *sc);
virtual Expression *optimize(int result);
- #define WANTflags 1
- #define WANTvalue 2
+ #define WANTflags 1
+ #define WANTvalue 2
#define WANTinterpret 4
virtual Expression *interpret(InterState *istate);
@@ -350,7 +350,7 @@ struct SuperExp : ThisExp
struct NullExp : Expression
{
- unsigned char committed; // !=0 if type is committed
+ unsigned char committed; // !=0 if type is committed
NullExp(Loc loc, Type *t = NULL);
Expression *semantic(Scope *sc);
@@ -372,11 +372,11 @@ struct NullExp : Expression
struct StringExp : Expression
{
- void *string; // char, wchar, or dchar data
- size_t len; // number of chars, wchars, or dchars
- unsigned char sz; // 1: char, 2: wchar, 4: dchar
- unsigned char committed; // !=0 if type is committed
- unsigned char postfix; // 'c', 'w', 'd'
+ void *string; // char, wchar, or dchar data
+ size_t len; // number of chars, wchars, or dchars
+ unsigned char sz; // 1: char, 2: wchar, 4: dchar
+ unsigned char committed; // !=0 if type is committed
+ unsigned char postfix; // 'c', 'w', 'd'
StringExp(Loc loc, char *s);
StringExp(Loc loc, void *s, size_t len);
@@ -500,15 +500,15 @@ struct AssocArrayLiteralExp : Expression
struct StructLiteralExp : Expression
{
- StructDeclaration *sd; // which aggregate this is for
- Expressions *elements; // parallels sd->fields[] with
- // NULL entries for fields to skip
+ StructDeclaration *sd; // which aggregate this is for
+ Expressions *elements; // parallels sd->fields[] with
+ // NULL entries for fields to skip
#if IN_DMD
- Symbol *sym; // back end symbol to initialize with literal
+ Symbol *sym; // back end symbol to initialize with literal
#endif
- size_t soffset; // offset from start of s
- int fillHoles; // fill alignment 'holes' with zero
+ size_t soffset; // offset from start of s
+ int fillHoles; // fill alignment 'holes' with zero
StructLiteralExp(Loc loc, StructDeclaration *sd, Expressions *elements);
@@ -591,17 +591,17 @@ struct NewExp : Expression
{
/* thisexp.new(newargs) newtype(arguments)
*/
- Expression *thisexp; // if !NULL, 'this' for class being allocated
- Expressions *newargs; // Array of Expression's to call new operator
+ Expression *thisexp; // if !NULL, 'this' for class being allocated
+ Expressions *newargs; // Array of Expression's to call new operator
Type *newtype;
- Expressions *arguments; // Array of Expression's
+ Expressions *arguments; // Array of Expression's
- CtorDeclaration *member; // constructor function
- NewDeclaration *allocator; // allocator function
- int onstack; // allocate on stack
+ CtorDeclaration *member; // constructor function
+ NewDeclaration *allocator; // allocator function
+ int onstack; // allocate on stack
NewExp(Loc loc, Expression *thisexp, Expressions *newargs,
- Type *newtype, Expressions *arguments);
+ Type *newtype, Expressions *arguments);
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
Expression *optimize(int result);
@@ -625,13 +625,13 @@ struct NewAnonClassExp : Expression
{
/* thisexp.new(newargs) class baseclasses { } (arguments)
*/
- Expression *thisexp; // if !NULL, 'this' for class being allocated
- Expressions *newargs; // Array of Expression's to call new operator
- ClassDeclaration *cd; // class being instantiated
- Expressions *arguments; // Array of Expression's to call class constructor
+ Expression *thisexp; // if !NULL, 'this' for class being allocated
+ Expressions *newargs; // Array of Expression's to call new operator
+ ClassDeclaration *cd; // class being instantiated
+ Expressions *arguments; // Array of Expression's to call class constructor
NewAnonClassExp(Loc loc, Expression *thisexp, Expressions *newargs,
- ClassDeclaration *cd, Expressions *arguments);
+ ClassDeclaration *cd, Expressions *arguments);
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
int checkSideEffect(int flag);
@@ -644,7 +644,7 @@ struct SymOffExp : Expression
{
Declaration *var;
unsigned offset;
- Module* m; // starting point for overload resolution
+ Module* m; // starting point for overload resolution
SymOffExp(Loc loc, Declaration *var, unsigned offset);
Expression *semantic(Scope *sc);
@@ -815,10 +815,10 @@ struct IsExp : Expression
* is(targ id == tok2)
*/
Type *targ;
- Identifier *id; // can be NULL
- enum TOK tok; // ':' or '=='
- Type *tspec; // can be NULL
- enum TOK tok2; // 'struct', 'union', 'typedef', etc.
+ Identifier *id; // can be NULL
+ enum TOK tok; // ':' or '=='
+ Type *tspec; // can be NULL
+ enum TOK tok2; // 'struct', 'union', 'typedef', etc.
IsExp(Loc loc, Type *targ, Identifier *id, enum TOK tok, Type *tspec, enum TOK tok2);
Expression *syntaxCopy();
@@ -845,7 +845,7 @@ struct UnaExp : Expression
Expression *doInline(InlineDoState *ids);
Expression *inlineScan(InlineScanState *iss);
- Expression *op_overload(Scope *sc); // doesn't need to be virtual
+ Expression *op_overload(Scope *sc); // doesn't need to be virtual
};
struct BinExp : Expression
@@ -986,7 +986,7 @@ struct DotTemplateInstanceExp : UnaExp
struct DelegateExp : UnaExp
{
FuncDeclaration *func;
- Module* m; // starting point for overload resolution
+ Module* m; // starting point for overload resolution
DelegateExp(Loc loc, Expression *e, FuncDeclaration *func);
Expression *semantic(Scope *sc);
@@ -1008,7 +1008,7 @@ struct DelegateExp : UnaExp
struct DotTypeExp : UnaExp
{
- Dsymbol *sym; // symbol that represents a type
+ Dsymbol *sym; // symbol that represents a type
DotTypeExp(Loc loc, Expression *e, Dsymbol *sym);
Expression *semantic(Scope *sc);
@@ -1024,7 +1024,7 @@ struct DotTypeExp : UnaExp
struct CallExp : UnaExp
{
- Expressions *arguments; // function arguments
+ Expressions *arguments; // function arguments
CallExp(Loc loc, Expression *e, Expressions *exps);
CallExp(Loc loc, Expression *e);
@@ -1056,7 +1056,7 @@ struct CallExp : UnaExp
struct AddrExp : UnaExp
{
- Module* m; // starting point for overload resolution
+ Module* m; // starting point for overload resolution
AddrExp(Loc loc, Expression *e);
Expression *semantic(Scope *sc);
@@ -1196,7 +1196,7 @@ struct DeleteExp : UnaExp
struct CastExp : UnaExp
{
// Possible to cast to one type while painting to another type
- Type *to; // type to cast to
+ Type *to; // type to cast to
CastExp(Loc loc, Expression *e, Type *t);
Expression *syntaxCopy();
@@ -1224,8 +1224,8 @@ struct CastExp : UnaExp
struct SliceExp : UnaExp
{
- Expression *upr; // NULL if implicit 0
- Expression *lwr; // NULL if implicit [length - 1]
+ Expression *upr; // NULL if implicit 0
+ Expression *lwr; // NULL if implicit [length - 1]
VarDeclaration *lengthVar;
SliceExp(Loc loc, Expression *e1, Expression *lwr, Expression *upr);
@@ -1276,7 +1276,7 @@ struct ArrayLengthExp : UnaExp
struct ArrayExp : UnaExp
{
- Expressions *arguments; // Array of Expression's
+ Expressions *arguments; // Array of Expression's
ArrayExp(Loc loc, Expression *e1, Expressions *arguments);
Expression *syntaxCopy();
@@ -1365,7 +1365,7 @@ struct PostExp : BinExp
};
struct AssignExp : BinExp
-{ int ismemset; // !=0 if setting the contents of an array
+{ int ismemset; // !=0 if setting the contents of an array
AssignExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
@@ -1393,18 +1393,18 @@ struct AssignExp : BinExp
#define ASSIGNEXP_TOELEM
#endif
-#define ASSIGNEXP(op) \
-struct op##AssignExp : BinExp \
-{ \
- op##AssignExp(Loc loc, Expression *e1, Expression *e2); \
- Expression *semantic(Scope *sc); \
- Expression *interpret(InterState *istate); \
+#define ASSIGNEXP(op) \
+struct op##AssignExp : BinExp \
+{ \
+ op##AssignExp(Loc loc, Expression *e1, Expression *e2); \
+ Expression *semantic(Scope *sc); \
+ Expression *interpret(InterState *istate); \
X(void buildArrayIdent(OutBuffer *buf, Expressions *arguments);) \
- X(Expression *buildArrayLoop(Parameters *fparams);) \
- \
- Identifier *opId(); /* For operator overloading */ \
- \
- ASSIGNEXP_TOELEM \
+ X(Expression *buildArrayLoop(Parameters *fparams);) \
+ \
+ Identifier *opId(); /* For operator overloading */ \
+ \
+ ASSIGNEXP_TOELEM \
};
#define X(a) a
@@ -1871,7 +1871,7 @@ struct CondExp : BinExp
struct DefaultInitExp : Expression
{
- enum TOK subop; // which of the derived classes this is
+ enum TOK subop; // which of the derived classes this is
DefaultInitExp(Loc loc, enum TOK subop, int size);
virtual Expression *resolve(Loc loc, Scope *sc) = 0;
@@ -1918,11 +1918,11 @@ struct GEPExp : UnaExp
/* Special values used by the interpreter
*/
-#define EXP_CANT_INTERPRET ((Expression *)1)
-#define EXP_CONTINUE_INTERPRET ((Expression *)2)
-#define EXP_BREAK_INTERPRET ((Expression *)3)
-#define EXP_GOTO_INTERPRET ((Expression *)4)
-#define EXP_VOID_INTERPRET ((Expression *)5)
+#define EXP_CANT_INTERPRET ((Expression *)1)
+#define EXP_CONTINUE_INTERPRET ((Expression *)2)
+#define EXP_BREAK_INTERPRET ((Expression *)3)
+#define EXP_GOTO_INTERPRET ((Expression *)4)
+#define EXP_VOID_INTERPRET ((Expression *)5)
Expression *expType(Type *type, Expression *e);
diff --git a/dmd/func.c b/dmd/func.c
index f96a0e0c..7d7715e1 100644
--- a/dmd/func.c
+++ b/dmd/func.c
@@ -122,9 +122,9 @@ Dsymbol *FuncDeclaration::syntaxCopy(Dsymbol *s)
//printf("FuncDeclaration::syntaxCopy('%s')\n", toChars());
if (s)
- f = (FuncDeclaration *)s;
+ f = (FuncDeclaration *)s;
else
- f = new FuncDeclaration(loc, endloc, ident, storage_class, type->syntaxCopy());
+ f = new FuncDeclaration(loc, endloc, ident, storage_class, type->syntaxCopy());
f->outId = outId;
f->frequire = frequire ? frequire->syntaxCopy() : NULL;
f->fensure = fensure ? fensure->syntaxCopy() : NULL;
@@ -151,48 +151,48 @@ void FuncDeclaration::semantic(Scope *sc)
#if 0
printf("FuncDeclaration::semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc->linkage);
if (isFuncLiteralDeclaration())
- printf("\tFuncLiteralDeclaration()\n");
+ printf("\tFuncLiteralDeclaration()\n");
printf("sc->parent = %s, parent = %s\n", sc->parent->toChars(), parent ? parent->toChars() : "");
printf("type: %p, %s\n", type, type->toChars());
#endif
if (semanticRun != PASSinit && isFuncLiteralDeclaration())
{
- /* Member functions that have return types that are
- * forward references can have semantic() run more than
- * once on them.
- * See test\interface2.d, test20
- */
- return;
+ /* Member functions that have return types that are
+ * forward references can have semantic() run more than
+ * once on them.
+ * See test\interface2.d, test20
+ */
+ return;
}
parent = sc->parent;
Dsymbol *parent = toParent();
if (semanticRun == PASSsemanticdone)
{
- if (!parent->isClassDeclaration())
- return;
- // need to re-run semantic() in order to set the class's vtbl[]
+ if (!parent->isClassDeclaration())
+ return;
+ // need to re-run semantic() in order to set the class's vtbl[]
}
else
{
- assert(semanticRun <= PASSsemantic);
- semanticRun = PASSsemantic;
+ assert(semanticRun <= PASSsemantic);
+ semanticRun = PASSsemantic;
}
unsigned dprogress_save = Module::dprogress;
- foverrides.setDim(0); // reset in case semantic() is being retried for this function
+ foverrides.setDim(0); // reset in case semantic() is being retried for this function
if (!type->deco)
{
- type = type->semantic(loc, sc);
+ type = type->semantic(loc, sc);
}
//type->print();
if (type->ty != Tfunction)
{
- error("%s must be a function", toChars());
- return;
+ error("%s must be a function", toChars());
+ return;
}
f = (TypeFunction *)(type);
size_t nparams = Parameter::dim(f->parameters);
@@ -203,29 +203,29 @@ void FuncDeclaration::semantic(Scope *sc)
//printf("function storage_class = x%x\n", storage_class);
if (ident == Id::ctor && !isCtorDeclaration())
- error("_ctor is reserved for constructors");
+ error("_ctor is reserved for constructors");
if (isConst() || isAuto() || isScope())
- error("functions cannot be const, auto or scope");
+ error("functions cannot be const, auto or scope");
if (isAbstract() && !isVirtual())
- error("non-virtual functions cannot be abstract");
+ error("non-virtual functions cannot be abstract");
if (isAbstract() && isFinal())
- error("cannot be both final and abstract");
+ error("cannot be both final and abstract");
#if 0
if (isAbstract() && fbody)
- error("abstract functions cannot have bodies");
+ error("abstract functions cannot have bodies");
#endif
#if 0
if (isStaticConstructor() || isStaticDestructor())
{
- if (!isStatic() || type->nextOf()->ty != Tvoid)
- error("static constructors / destructors must be static void");
- if (f->arguments && f->arguments->dim)
- error("static constructors / destructors must have empty parameter list");
- // BUG: check for invalid storage classes
+ if (!isStatic() || type->nextOf()->ty != Tvoid)
+ error("static constructors / destructors must be static void");
+ if (f->arguments && f->arguments->dim)
+ error("static constructors / destructors must have empty parameter list");
+ // BUG: check for invalid storage classes
}
#endif
@@ -234,52 +234,52 @@ void FuncDeclaration::semantic(Scope *sc)
ad = parent->isAggregateDeclaration();
if (ad)
- ad->methods.push(this);
+ ad->methods.push(this);
#endif
sd = parent->isStructDeclaration();
if (sd)
{
- // Verify no constructors, destructors, etc.
- if (isCtorDeclaration() ||
- isDtorDeclaration()
- //|| isInvariantDeclaration()
- //|| isUnitTestDeclaration()
- )
- {
- error("special member functions not allowed for %ss", sd->kind());
- }
+ // Verify no constructors, destructors, etc.
+ if (isCtorDeclaration() ||
+ isDtorDeclaration()
+ //|| isInvariantDeclaration()
+ //|| isUnitTestDeclaration()
+ )
+ {
+ error("special member functions not allowed for %ss", sd->kind());
+ }
#if 0
- if (!sd->inv)
- sd->inv = isInvariantDeclaration();
+ if (!sd->inv)
+ sd->inv = isInvariantDeclaration();
- if (!sd->aggNew)
- sd->aggNew = isNewDeclaration();
+ if (!sd->aggNew)
+ sd->aggNew = isNewDeclaration();
- if (isDelete())
- {
- if (sd->aggDelete)
- error("multiple delete's for struct %s", sd->toChars());
- sd->aggDelete = (DeleteDeclaration *)(this);
- }
+ if (isDelete())
+ {
+ if (sd->aggDelete)
+ error("multiple delete's for struct %s", sd->toChars());
+ sd->aggDelete = (DeleteDeclaration *)(this);
+ }
#endif
}
id = parent->isInterfaceDeclaration();
if (id)
{
- storage_class |= STCabstract;
+ storage_class |= STCabstract;
- if (isCtorDeclaration() ||
+ if (isCtorDeclaration() ||
#if DMDV2
- isPostBlitDeclaration() ||
+ isPostBlitDeclaration() ||
#endif
- isDtorDeclaration() ||
- isInvariantDeclaration() ||
- isUnitTestDeclaration() || isNewDeclaration() || isDelete())
- error("special function not allowed in interface %s", id->toChars());
- if (fbody && isVirtual())
- error("function body is not abstract in interface %s", id->toChars());
+ isDtorDeclaration() ||
+ isInvariantDeclaration() ||
+ isUnitTestDeclaration() || isNewDeclaration() || isDelete())
+ error("special function not allowed in interface %s", id->toChars());
+ if (fbody && isVirtual())
+ error("function body is not abstract in interface %s", id->toChars());
}
/* Template member functions aren't virtual:
@@ -287,388 +287,388 @@ void FuncDeclaration::semantic(Scope *sc)
* and so won't work in interfaces
*/
if ((pd = toParent()) != NULL &&
- pd->isTemplateInstance() &&
- (pd = toParent2()) != NULL &&
- (id = pd->isInterfaceDeclaration()) != NULL)
+ pd->isTemplateInstance() &&
+ (pd = toParent2()) != NULL &&
+ (id = pd->isInterfaceDeclaration()) != NULL)
{
- error("template member function not allowed in interface %s", id->toChars());
+ error("template member function not allowed in interface %s", id->toChars());
}
cd = parent->isClassDeclaration();
if (cd)
- { int vi;
- CtorDeclaration *ctor;
- DtorDeclaration *dtor;
- InvariantDeclaration *inv;
+ { int vi;
+ CtorDeclaration *ctor;
+ DtorDeclaration *dtor;
+ InvariantDeclaration *inv;
- if (isCtorDeclaration())
- {
-// ctor = (CtorDeclaration *)this;
-// if (!cd->ctor)
-// cd->ctor = ctor;
- return;
- }
+ if (isCtorDeclaration())
+ {
+// ctor = (CtorDeclaration *)this;
+// if (!cd->ctor)
+// cd->ctor = ctor;
+ return;
+ }
#if 0
- dtor = isDtorDeclaration();
- if (dtor)
- {
- if (cd->dtor)
- error("multiple destructors for class %s", cd->toChars());
- cd->dtor = dtor;
- }
+ dtor = isDtorDeclaration();
+ if (dtor)
+ {
+ if (cd->dtor)
+ error("multiple destructors for class %s", cd->toChars());
+ cd->dtor = dtor;
+ }
- inv = isInvariantDeclaration();
- if (inv)
- {
- cd->inv = inv;
- }
+ inv = isInvariantDeclaration();
+ if (inv)
+ {
+ cd->inv = inv;
+ }
- if (isNewDeclaration())
- {
- if (!cd->aggNew)
- cd->aggNew = (NewDeclaration *)(this);
- }
+ if (isNewDeclaration())
+ {
+ if (!cd->aggNew)
+ cd->aggNew = (NewDeclaration *)(this);
+ }
- if (isDelete())
- {
- if (cd->aggDelete)
- error("multiple delete's for class %s", cd->toChars());
- cd->aggDelete = (DeleteDeclaration *)(this);
- }
+ if (isDelete())
+ {
+ if (cd->aggDelete)
+ error("multiple delete's for class %s", cd->toChars());
+ cd->aggDelete = (DeleteDeclaration *)(this);
+ }
#endif
- if (storage_class & STCabstract)
- cd->isabstract = 1;
+ if (storage_class & STCabstract)
+ cd->isabstract = 1;
- // if static function, do not put in vtbl[]
- if (!isVirtual())
- {
- //printf("\tnot virtual\n");
- goto Ldone;
- }
+ // if static function, do not put in vtbl[]
+ if (!isVirtual())
+ {
+ //printf("\tnot virtual\n");
+ goto Ldone;
+ }
- /* Find index of existing function in base class's vtbl[] to override
- * (the index will be the same as in cd's current vtbl[])
- */
- vi = cd->baseClass ? findVtblIndex(&cd->baseClass->vtbl, cd->baseClass->vtbl.dim)
- : -1;
+ /* Find index of existing function in base class's vtbl[] to override
+ * (the index will be the same as in cd's current vtbl[])
+ */
+ vi = cd->baseClass ? findVtblIndex(&cd->baseClass->vtbl, cd->baseClass->vtbl.dim)
+ : -1;
- switch (vi)
- {
- case -1:
- /* Didn't find one, so
- * This is an 'introducing' function which gets a new
- * slot in the vtbl[].
- */
+ switch (vi)
+ {
+ case -1:
+ /* Didn't find one, so
+ * This is an 'introducing' function which gets a new
+ * slot in the vtbl[].
+ */
- // Verify this doesn't override previous final function
- if (cd->baseClass)
- { Dsymbol *s = cd->baseClass->search(loc, ident, 0);
- if (s)
- {
- FuncDeclaration *f = s->isFuncDeclaration();
- f = f->overloadExactMatch(type, getModule());
- if (f && f->isFinal() && f->prot() != PROTprivate)
- error("cannot override final function %s", f->toPrettyChars());
- }
- }
+ // Verify this doesn't override previous final function
+ if (cd->baseClass)
+ { Dsymbol *s = cd->baseClass->search(loc, ident, 0);
+ if (s)
+ {
+ FuncDeclaration *f = s->isFuncDeclaration();
+ f = f->overloadExactMatch(type, getModule());
+ if (f && f->isFinal() && f->prot() != PROTprivate)
+ error("cannot override final function %s", f->toPrettyChars());
+ }
+ }
- if (isFinal())
- {
- if (isOverride())
- error("does not override any function");
- cd->vtblFinal.push(this);
- }
- else
- {
- // Append to end of vtbl[]
- //printf("\tintroducing function\n");
- introducing = 1;
- vi = cd->vtbl.dim;
- cd->vtbl.push(this);
- vtblIndex = vi;
- }
- break;
+ if (isFinal())
+ {
+ if (isOverride())
+ error("does not override any function");
+ cd->vtblFinal.push(this);
+ }
+ else
+ {
+ // Append to end of vtbl[]
+ //printf("\tintroducing function\n");
+ introducing = 1;
+ vi = cd->vtbl.dim;
+ cd->vtbl.push(this);
+ vtblIndex = vi;
+ }
+ break;
- case -2: // can't determine because of fwd refs
- cd->sizeok = 2; // can't finish due to forward reference
- Module::dprogress = dprogress_save;
- return;
+ case -2: // can't determine because of fwd refs
+ cd->sizeok = 2; // can't finish due to forward reference
+ Module::dprogress = dprogress_save;
+ return;
- default:
- { FuncDeclaration *fdv = (FuncDeclaration *)cd->baseClass->vtbl.data[vi];
- // This function is covariant with fdv
- if (fdv->isFinal())
- error("cannot override final function %s", fdv->toPrettyChars());
+ default:
+ { FuncDeclaration *fdv = (FuncDeclaration *)cd->baseClass->vtbl.data[vi];
+ // This function is covariant with fdv
+ if (fdv->isFinal())
+ error("cannot override final function %s", fdv->toPrettyChars());
#if DMDV2
- if (!isOverride())
- warning(loc, "overrides base class function %s, but is not marked with 'override'", fdv->toPrettyChars());
+ if (!isOverride())
+ warning(loc, "overrides base class function %s, but is not marked with 'override'", fdv->toPrettyChars());
#endif
- if (fdv->toParent() == parent)
- {
- // If both are mixins, then error.
- // If either is not, the one that is not overrides
- // the other.
- if (fdv->parent->isClassDeclaration())
- break;
- if (!this->parent->isClassDeclaration()
+ if (fdv->toParent() == parent)
+ {
+ // If both are mixins, then error.
+ // If either is not, the one that is not overrides
+ // the other.
+ if (fdv->parent->isClassDeclaration())
+ break;
+ if (!this->parent->isClassDeclaration()
#if !BREAKABI
- && !isDtorDeclaration()
+ && !isDtorDeclaration()
#endif
#if DMDV2
- && !isPostBlitDeclaration()
+ && !isPostBlitDeclaration()
#endif
- )
- error("multiple overrides of same function");
- }
- cd->vtbl.data[vi] = (void *)this;
- vtblIndex = vi;
+ )
+ error("multiple overrides of same function");
+ }
+ cd->vtbl.data[vi] = (void *)this;
+ vtblIndex = vi;
- /* Remember which functions this overrides
- */
- foverrides.push(fdv);
+ /* Remember which functions this overrides
+ */
+ foverrides.push(fdv);
- /* This works by whenever this function is called,
- * it actually returns tintro, which gets dynamically
- * cast to type. But we know that tintro is a base
- * of type, so we could optimize it by not doing a
- * dynamic cast, but just subtracting the isBaseOf()
- * offset if the value is != null.
- */
+ /* This works by whenever this function is called,
+ * it actually returns tintro, which gets dynamically
+ * cast to type. But we know that tintro is a base
+ * of type, so we could optimize it by not doing a
+ * dynamic cast, but just subtracting the isBaseOf()
+ * offset if the value is != null.
+ */
- if (fdv->tintro)
- tintro = fdv->tintro;
- else if (!type->equals(fdv->type))
- {
- /* Only need to have a tintro if the vptr
- * offsets differ
- */
- int offset;
- if (fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset))
- {
- tintro = fdv->type;
- }
- }
- break;
- }
- }
+ if (fdv->tintro)
+ tintro = fdv->tintro;
+ else if (!type->equals(fdv->type))
+ {
+ /* Only need to have a tintro if the vptr
+ * offsets differ
+ */
+ int offset;
+ if (fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset))
+ {
+ tintro = fdv->type;
+ }
+ }
+ break;
+ }
+ }
- /* Go through all the interface bases.
- * If this function is covariant with any members of those interface
- * functions, set the tintro.
- */
- for (int i = 0; i < cd->interfaces_dim; i++)
- {
- BaseClass *b = cd->interfaces[i];
- vi = findVtblIndex(&b->base->vtbl, b->base->vtbl.dim);
- switch (vi)
- {
- case -1:
- break;
+ /* Go through all the interface bases.
+ * If this function is covariant with any members of those interface
+ * functions, set the tintro.
+ */
+ for (int i = 0; i < cd->interfaces_dim; i++)
+ {
+ BaseClass *b = cd->interfaces[i];
+ vi = findVtblIndex(&b->base->vtbl, b->base->vtbl.dim);
+ switch (vi)
+ {
+ case -1:
+ break;
- case -2:
- cd->sizeok = 2; // can't finish due to forward reference
- Module::dprogress = dprogress_save;
- return;
+ case -2:
+ cd->sizeok = 2; // can't finish due to forward reference
+ Module::dprogress = dprogress_save;
+ return;
- default:
- { FuncDeclaration *fdv = (FuncDeclaration *)b->base->vtbl.data[vi];
- Type *ti = NULL;
+ default:
+ { FuncDeclaration *fdv = (FuncDeclaration *)b->base->vtbl.data[vi];
+ Type *ti = NULL;
- /* Remember which functions this overrides
- */
- foverrides.push(fdv);
+ /* Remember which functions this overrides
+ */
+ foverrides.push(fdv);
- if (fdv->tintro)
- ti = fdv->tintro;
- else if (!type->equals(fdv->type))
- {
- /* Only need to have a tintro if the vptr
- * offsets differ
- */
- unsigned errors = global.errors;
- global.gag++; // suppress printing of error messages
- int offset;
- int baseOf = fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset);
- global.gag--; // suppress printing of error messages
- if (errors != global.errors)
- {
- // any error in isBaseOf() is a forward reference error, so we bail out
- global.errors = errors;
- cd->sizeok = 2; // can't finish due to forward reference
- Module::dprogress = dprogress_save;
- return;
- }
- if (baseOf)
- {
- ti = fdv->type;
- }
- }
- if (ti)
- {
- if (tintro && !tintro->equals(ti))
- {
- error("incompatible covariant types %s and %s", tintro->toChars(), ti->toChars());
- }
- tintro = ti;
- }
- goto L2;
- }
- }
- }
+ if (fdv->tintro)
+ ti = fdv->tintro;
+ else if (!type->equals(fdv->type))
+ {
+ /* Only need to have a tintro if the vptr
+ * offsets differ
+ */
+ unsigned errors = global.errors;
+ global.gag++; // suppress printing of error messages
+ int offset;
+ int baseOf = fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset);
+ global.gag--; // suppress printing of error messages
+ if (errors != global.errors)
+ {
+ // any error in isBaseOf() is a forward reference error, so we bail out
+ global.errors = errors;
+ cd->sizeok = 2; // can't finish due to forward reference
+ Module::dprogress = dprogress_save;
+ return;
+ }
+ if (baseOf)
+ {
+ ti = fdv->type;
+ }
+ }
+ if (ti)
+ {
+ if (tintro && !tintro->equals(ti))
+ {
+ error("incompatible covariant types %s and %s", tintro->toChars(), ti->toChars());
+ }
+ tintro = ti;
+ }
+ goto L2;
+ }
+ }
+ }
- if (introducing && isOverride())
- {
- error("does not override any function");
- }
+ if (introducing && isOverride())
+ {
+ error("does not override any function");
+ }
L2: ;
}
else if (isOverride() && !parent->isTemplateInstance())
- error("override only applies to class member functions");
+ error("override only applies to class member functions");
/* Do not allow template instances to add virtual functions
* to a class.
*/
if (isVirtual())
{
- TemplateInstance *ti = parent->isTemplateInstance();
- if (ti)
- {
- // Take care of nested templates
- while (1)
- {
- TemplateInstance *ti2 = ti->tempdecl->parent->isTemplateInstance();
- if (!ti2)
- break;
- ti = ti2;
- }
+ TemplateInstance *ti = parent->isTemplateInstance();
+ if (ti)
+ {
+ // Take care of nested templates
+ while (1)
+ {
+ TemplateInstance *ti2 = ti->tempdecl->parent->isTemplateInstance();
+ if (!ti2)
+ break;
+ ti = ti2;
+ }
- // If it's a member template
- ClassDeclaration *cd = ti->tempdecl->isClassMember();
- if (cd)
- {
- error("cannot use template to add virtual function to class '%s'", cd->toChars());
- }
- }
+ // If it's a member template
+ ClassDeclaration *cd = ti->tempdecl->isClassMember();
+ if (cd)
+ {
+ error("cannot use template to add virtual function to class '%s'", cd->toChars());
+ }
+ }
}
if (isMain())
{
- // Check parameters to see if they are either () or (char[][] args)
- switch (nparams)
- {
- case 0:
- break;
+ // Check parameters to see if they are either () or (char[][] args)
+ switch (nparams)
+ {
+ case 0:
+ break;
- case 1:
- {
- Parameter *arg0 = Parameter::getNth(f->parameters, 0);
- if (arg0->type->ty != Tarray ||
- arg0->type->nextOf()->ty != Tarray ||
- arg0->type->nextOf()->nextOf()->ty != Tchar ||
- arg0->storageClass & (STCout | STCref | STClazy))
- goto Lmainerr;
- break;
- }
+ case 1:
+ {
+ Parameter *arg0 = Parameter::getNth(f->parameters, 0);
+ if (arg0->type->ty != Tarray ||
+ arg0->type->nextOf()->ty != Tarray ||
+ arg0->type->nextOf()->nextOf()->ty != Tchar ||
+ arg0->storageClass & (STCout | STCref | STClazy))
+ goto Lmainerr;
+ break;
+ }
- default:
- goto Lmainerr;
- }
+ default:
+ goto Lmainerr;
+ }
- if (!f->nextOf())
- error("must return int or void");
- else if (f->nextOf()->ty != Tint32 && f->nextOf()->ty != Tvoid)
- error("must return int or void, not %s", f->nextOf()->toChars());
- if (f->varargs)
- {
- Lmainerr:
- error("parameters must be main() or main(char[][] args)");
- }
+ if (!f->nextOf())
+ error("must return int or void");
+ else if (f->nextOf()->ty != Tint32 && f->nextOf()->ty != Tvoid)
+ error("must return int or void, not %s", f->nextOf()->toChars());
+ if (f->varargs)
+ {
+ Lmainerr:
+ error("parameters must be main() or main(char[][] args)");
+ }
}
if (ident == Id::assign && (sd || cd))
- { // Disallow identity assignment operator.
+ { // Disallow identity assignment operator.
- // opAssign(...)
- if (nparams == 0)
- { if (f->varargs == 1)
- goto Lassignerr;
- }
- else
- {
- Parameter *arg0 = Parameter::getNth(f->parameters, 0);
- Type *t0 = arg0->type->toBasetype();
- Type *tb = sd ? sd->type : cd->type;
- if (arg0->type->implicitConvTo(tb) ||
- (sd && t0->ty == Tpointer && t0->nextOf()->implicitConvTo(tb))
- )
- {
- if (nparams == 1)
- goto Lassignerr;
- Parameter *arg1 = Parameter::getNth(f->parameters, 1);
- if (arg1->defaultArg)
- goto Lassignerr;
- }
- }
+ // opAssign(...)
+ if (nparams == 0)
+ { if (f->varargs == 1)
+ goto Lassignerr;
+ }
+ else
+ {
+ Parameter *arg0 = Parameter::getNth(f->parameters, 0);
+ Type *t0 = arg0->type->toBasetype();
+ Type *tb = sd ? sd->type : cd->type;
+ if (arg0->type->implicitConvTo(tb) ||
+ (sd && t0->ty == Tpointer && t0->nextOf()->implicitConvTo(tb))
+ )
+ {
+ if (nparams == 1)
+ goto Lassignerr;
+ Parameter *arg1 = Parameter::getNth(f->parameters, 1);
+ if (arg1->defaultArg)
+ goto Lassignerr;
+ }
+ }
}
if (isVirtual() && semanticRun != PASSsemanticdone)
{
- /* Rewrite contracts as nested functions, then call them.
- * Doing it as nested functions means that overriding functions
- * can call them.
- */
- if (frequire)
- { /* in { ... }
- * becomes:
- * void __require() { ... }
- * __require();
- */
- Loc loc = frequire->loc;
- TypeFunction *tf = new TypeFunction(NULL, Type::tvoid, 0, LINKd);
- FuncDeclaration *fd = new FuncDeclaration(loc, loc,
- Id::require, STCundefined, tf);
- fd->fbody = frequire;
- Statement *s1 = new DeclarationStatement(loc, fd);
- Expression *e = new CallExp(loc, new VarExp(loc, fd), (Expressions *)NULL);
- Statement *s2 = new ExpStatement(loc, e);
- frequire = new CompoundStatement(loc, s1, s2);
- fdrequire = fd;
- }
+ /* Rewrite contracts as nested functions, then call them.
+ * Doing it as nested functions means that overriding functions
+ * can call them.
+ */
+ if (frequire)
+ { /* in { ... }
+ * becomes:
+ * void __require() { ... }
+ * __require();
+ */
+ Loc loc = frequire->loc;
+ TypeFunction *tf = new TypeFunction(NULL, Type::tvoid, 0, LINKd);
+ FuncDeclaration *fd = new FuncDeclaration(loc, loc,
+ Id::require, STCundefined, tf);
+ fd->fbody = frequire;
+ Statement *s1 = new DeclarationStatement(loc, fd);
+ Expression *e = new CallExp(loc, new VarExp(loc, fd), (Expressions *)NULL);
+ Statement *s2 = new ExpStatement(loc, e);
+ frequire = new CompoundStatement(loc, s1, s2);
+ fdrequire = fd;
+ }
- if (!outId && f->nextOf()->toBasetype()->ty != Tvoid)
- outId = Id::result; // provide a default
+ if (!outId && f->nextOf()->toBasetype()->ty != Tvoid)
+ outId = Id::result; // provide a default
- if (fensure)
- { /* out (result) { ... }
- * becomes:
- * tret __ensure(ref tret result) { ... }
- * __ensure(result);
- */
- Loc loc = fensure->loc;
- Parameters *arguments = new Parameters();
- Parameter *a = NULL;
- if (outId)
- { a = new Parameter(STCref, f->nextOf(), outId, NULL);
- arguments->push(a);
- }
- TypeFunction *tf = new TypeFunction(arguments, Type::tvoid, 0, LINKd);
- FuncDeclaration *fd = new FuncDeclaration(loc, loc,
- Id::ensure, STCundefined, tf);
- fd->fbody = fensure;
- Statement *s1 = new DeclarationStatement(loc, fd);
- Expression *eresult = NULL;
- if (outId)
- eresult = new IdentifierExp(loc, outId);
- Expression *e = new CallExp(loc, new VarExp(loc, fd), eresult);
- Statement *s2 = new ExpStatement(loc, e);
- fensure = new CompoundStatement(loc, s1, s2);
- fdensure = fd;
- }
+ if (fensure)
+ { /* out (result) { ... }
+ * becomes:
+ * tret __ensure(ref tret result) { ... }
+ * __ensure(result);
+ */
+ Loc loc = fensure->loc;
+ Parameters *arguments = new Parameters();
+ Parameter *a = NULL;
+ if (outId)
+ { a = new Parameter(STCref, f->nextOf(), outId, NULL);
+ arguments->push(a);
+ }
+ TypeFunction *tf = new TypeFunction(arguments, Type::tvoid, 0, LINKd);
+ FuncDeclaration *fd = new FuncDeclaration(loc, loc,
+ Id::ensure, STCundefined, tf);
+ fd->fbody = fensure;
+ Statement *s1 = new DeclarationStatement(loc, fd);
+ Expression *eresult = NULL;
+ if (outId)
+ eresult = new IdentifierExp(loc, outId);
+ Expression *e = new CallExp(loc, new VarExp(loc, fd), eresult);
+ Statement *s2 = new ExpStatement(loc, e);
+ fensure = new CompoundStatement(loc, s1, s2);
+ fdensure = fd;
+ }
}
Ldone:
@@ -699,10 +699,10 @@ void FuncDeclaration::semantic3(Scope *sc)
if (!parent)
{
- if (global.errors)
- return;
- //printf("FuncDeclaration::semantic3(%s '%s', sc = %p)\n", kind(), toChars(), sc);
- assert(0);
+ if (global.errors)
+ return;
+ //printf("FuncDeclaration::semantic3(%s '%s', sc = %p)\n", kind(), toChars(), sc);
+ assert(0);
}
//printf("FuncDeclaration::semantic3('%s.%s', sc = %p, loc = %s)\n", parent->toChars(), toChars(), sc, loc.toChars());
//fflush(stdout);
@@ -712,7 +712,7 @@ void FuncDeclaration::semantic3(Scope *sc)
//printf(" sc->incontract = %d\n", sc->incontract);
if (semanticRun >= PASSsemantic3)
- return;
+ return;
semanticRun = PASSsemantic3;
#if IN_LLVM
@@ -720,20 +720,20 @@ void FuncDeclaration::semantic3(Scope *sc)
availableExternally = false;
#endif
if (!type || type->ty != Tfunction)
- return;
+ return;
f = (TypeFunction *)(type);
// Check the 'throws' clause
if (fthrows)
{
- for (int i = 0; i < fthrows->dim; i++)
- {
- Type *t = (Type *)fthrows->data[i];
+ for (int i = 0; i < fthrows->dim; i++)
+ {
+ Type *t = (Type *)fthrows->data[i];
- t = t->semantic(loc, sc);
- if (!t->isClassHandle())
- error("can only throw classes, not %s", t->toChars());
- }
+ t = t->semantic(loc, sc);
+ if (!t->isClassHandle())
+ error("can only throw classes, not %s", t->toChars());
+ }
}
frequire = mergeFrequire(frequire);
@@ -741,115 +741,115 @@ void FuncDeclaration::semantic3(Scope *sc)
if (fbody || frequire)
{
- /* Symbol table into which we place parameters and nested functions,
- * solely to diagnose name collisions.
- */
- localsymtab = new DsymbolTable();
+ /* Symbol table into which we place parameters and nested functions,
+ * solely to diagnose name collisions.
+ */
+ localsymtab = new DsymbolTable();
- // Establish function scope
- ScopeDsymbol *ss = new ScopeDsymbol();
- ss->parent = sc->scopesym;
- Scope *sc2 = sc->push(ss);
- sc2->func = this;
- sc2->parent = this;
- sc2->callSuper = 0;
- sc2->sbreak = NULL;
- sc2->scontinue = NULL;
- sc2->sw = NULL;
- sc2->fes = fes;
- sc2->linkage = LINKd;
- sc2->stc &= ~(STCauto | STCscope | STCstatic | STCabstract | STCdeprecated | STCfinal);
- sc2->protection = PROTpublic;
- sc2->explicitProtection = 0;
- sc2->structalign = 8;
- sc2->incontract = 0;
- sc2->enclosingFinally = NULL;
- sc2->enclosingScopeExit = NULL;
- sc2->noctor = 0;
+ // Establish function scope
+ ScopeDsymbol *ss = new ScopeDsymbol();
+ ss->parent = sc->scopesym;
+ Scope *sc2 = sc->push(ss);
+ sc2->func = this;
+ sc2->parent = this;
+ sc2->callSuper = 0;
+ sc2->sbreak = NULL;
+ sc2->scontinue = NULL;
+ sc2->sw = NULL;
+ sc2->fes = fes;
+ sc2->linkage = LINKd;
+ sc2->stc &= ~(STCauto | STCscope | STCstatic | STCabstract | STCdeprecated | STCfinal);
+ sc2->protection = PROTpublic;
+ sc2->explicitProtection = 0;
+ sc2->structalign = 8;
+ sc2->incontract = 0;
+ sc2->enclosingFinally = NULL;
+ sc2->enclosingScopeExit = NULL;
+ sc2->noctor = 0;
- // Declare 'this'
- AggregateDeclaration *ad = isThis();
- if (ad)
- { VarDeclaration *v;
+ // Declare 'this'
+ AggregateDeclaration *ad = isThis();
+ if (ad)
+ { VarDeclaration *v;
- if (isFuncLiteralDeclaration() && isNested() && !sc->intypeof)
- {
- error("function literals cannot be class members");
- return;
- }
- else
- {
- assert(!isNested() || sc->intypeof); // can't be both member and nested
- assert(ad->handle);
- v = new ThisDeclaration(loc, ad->handle);
- v->storage_class |= STCparameter | STCin;
- v->semantic(sc2);
- if (!sc2->insert(v))
- assert(0);
- v->parent = this;
- vthis = v;
- }
- }
- else if (isNested())
- {
- /* The 'this' for a nested function is the link to the
- * enclosing function's stack frame.
- * Note that nested functions and member functions are disjoint.
- */
- VarDeclaration *v = new ThisDeclaration(loc, Type::tvoid->pointerTo());
- v->storage_class |= STCparameter | STCin;
- v->semantic(sc2);
- if (!sc2->insert(v))
- assert(0);
- v->parent = this;
- vthis = v;
- }
+ if (isFuncLiteralDeclaration() && isNested() && !sc->intypeof)
+ {
+ error("function literals cannot be class members");
+ return;
+ }
+ else
+ {
+ assert(!isNested() || sc->intypeof); // can't be both member and nested
+ assert(ad->handle);
+ v = new ThisDeclaration(loc, ad->handle);
+ v->storage_class |= STCparameter | STCin;
+ v->semantic(sc2);
+ if (!sc2->insert(v))
+ assert(0);
+ v->parent = this;
+ vthis = v;
+ }
+ }
+ else if (isNested())
+ {
+ /* The 'this' for a nested function is the link to the
+ * enclosing function's stack frame.
+ * Note that nested functions and member functions are disjoint.
+ */
+ VarDeclaration *v = new ThisDeclaration(loc, Type::tvoid->pointerTo());
+ v->storage_class |= STCparameter | STCin;
+ v->semantic(sc2);
+ if (!sc2->insert(v))
+ assert(0);
+ v->parent = this;
+ vthis = v;
+ }
- // Declare hidden variable _arguments[] and _argptr
- if (f->varargs == 1)
- {
+ // Declare hidden variable _arguments[] and _argptr
+ if (f->varargs == 1)
+ {
#if TARGET_NET
varArgs(sc2, f, argptr, _arguments);
#else
Type *t;
- if (f->linkage == LINKd)
- { // Declare _arguments[]
+ if (f->linkage == LINKd)
+ { // Declare _arguments[]
#if BREAKABI
- v_arguments = new VarDeclaration(0, Type::typeinfotypelist->type, Id::_arguments_typeinfo, NULL);
- v_arguments->storage_class = STCparameter | STCin;
- v_arguments->semantic(sc2);
- sc2->insert(v_arguments);
- v_arguments->parent = this;
+ v_arguments = new VarDeclaration(0, Type::typeinfotypelist->type, Id::_arguments_typeinfo, NULL);
+ v_arguments->storage_class = STCparameter | STCin;
+ v_arguments->semantic(sc2);
+ sc2->insert(v_arguments);
+ v_arguments->parent = this;
- t = Type::typeinfo->type->arrayOf();
- _arguments = new VarDeclaration(0, t, Id::_arguments, NULL);
- _arguments->semantic(sc2);
- sc2->insert(_arguments);
- _arguments->parent = this;
+ t = Type::typeinfo->type->arrayOf();
+ _arguments = new VarDeclaration(0, t, Id::_arguments, NULL);
+ _arguments->semantic(sc2);
+ sc2->insert(_arguments);
+ _arguments->parent = this;
#else
- t = Type::typeinfo->type->arrayOf();
- v_arguments = new VarDeclaration(0, t, Id::_arguments, NULL);
- v_arguments->storage_class = STCparameter | STCin;
- v_arguments->semantic(sc2);
- sc2->insert(v_arguments);
- v_arguments->parent = this;
+ t = Type::typeinfo->type->arrayOf();
+ v_arguments = new VarDeclaration(0, t, Id::_arguments, NULL);
+ v_arguments->storage_class = STCparameter | STCin;
+ v_arguments->semantic(sc2);
+ sc2->insert(v_arguments);
+ v_arguments->parent = this;
#endif
- }
- if (f->linkage == LINKd || (parameters && parameters->dim))
- { // Declare _argptr
+ }
+ if (f->linkage == LINKd || (parameters && parameters->dim))
+ { // Declare _argptr
#if IN_GCC
- t = d_gcc_builtin_va_list_d_type;
+ t = d_gcc_builtin_va_list_d_type;
#else
- t = Type::tvoid->pointerTo();
+ t = Type::tvoid->pointerTo();
#endif
- argptr = new VarDeclaration(0, t, Id::_argptr, NULL);
- argptr->semantic(sc2);
- sc2->insert(argptr);
- argptr->parent = this;
- }
+ argptr = new VarDeclaration(0, t, Id::_argptr, NULL);
+ argptr->semantic(sc2);
+ sc2->insert(argptr);
+ argptr->parent = this;
+ }
#endif
- }
+ }
#if IN_LLVM
// LDC make sure argument type is semanticed.
@@ -857,7 +857,7 @@ void FuncDeclaration::semantic3(Scope *sc)
if (f->parameters)
{
for (size_t i = 0; i < Parameter::dim(f->parameters); i++)
- { Parameter *arg = (Parameter *)Parameter::getNth(f->parameters, i);
+ { Parameter *arg = (Parameter *)Parameter::getNth(f->parameters, i);
Type* nw = arg->type->semantic(0, sc);
if (arg->type != nw) {
arg->type = nw;
@@ -874,485 +874,485 @@ void FuncDeclaration::semantic3(Scope *sc)
#endif
#if 0
- // Propagate storage class from tuple parameters to their element-parameters.
- if (f->parameters)
- {
- for (size_t i = 0; i < f->parameters->dim; i++)
- { Parameter *arg = (Parameter *)f->parameters->data[i];
+ // Propagate storage class from tuple parameters to their element-parameters.
+ if (f->parameters)
+ {
+ for (size_t i = 0; i < f->parameters->dim; i++)
+ { Parameter *arg = (Parameter *)f->parameters->data[i];
- //printf("[%d] arg->type->ty = %d %s\n", i, arg->type->ty, arg->type->toChars());
- if (arg->type->ty == Ttuple)
- { TypeTuple *t = (TypeTuple *)arg->type;
- size_t dim = Parameter::dim(t->arguments);
- for (size_t j = 0; j < dim; j++)
- { Parameter *narg = Parameter::getNth(t->arguments, j);
- narg->storageClass = arg->storageClass;
- }
- }
- }
- }
+ //printf("[%d] arg->type->ty = %d %s\n", i, arg->type->ty, arg->type->toChars());
+ if (arg->type->ty == Ttuple)
+ { TypeTuple *t = (TypeTuple *)arg->type;
+ size_t dim = Parameter::dim(t->arguments);
+ for (size_t j = 0; j < dim; j++)
+ { Parameter *narg = Parameter::getNth(t->arguments, j);
+ narg->storageClass = arg->storageClass;
+ }
+ }
+ }
+ }
#endif
- /* Declare all the function parameters as variables
- * and install them in parameters[]
- */
- size_t nparams = Parameter::dim(f->parameters);
- if (nparams)
- { /* parameters[] has all the tuples removed, as the back end
- * doesn't know about tuples
- */
- parameters = new Dsymbols();
- parameters->reserve(nparams);
- for (size_t i = 0; i < nparams; i++)
- {
- Parameter *arg = Parameter::getNth(f->parameters, i);
- Identifier *id = arg->ident;
- if (!id)
- {
- /* Generate identifier for un-named parameter,
- * because we need it later on.
- */
- arg->ident = id = Identifier::generateId("_param_", i);
- }
- Type *vtype = arg->type;
- VarDeclaration *v = new VarDeclaration(loc, vtype, id, NULL);
- //printf("declaring parameter %s of type %s\n", v->toChars(), v->type->toChars());
- v->storage_class |= STCparameter;
- if (f->varargs == 2 && i + 1 == nparams)
- v->storage_class |= STCvariadic;
- v->storage_class |= arg->storageClass & (STCin | STCout | STCref | STClazy);
- if (v->storage_class & STClazy)
- v->storage_class |= STCin;
- v->semantic(sc2);
- if (!sc2->insert(v))
- error("parameter %s.%s is already defined", toChars(), v->toChars());
- else
- parameters->push(v);
- localsymtab->insert(v);
- v->parent = this;
- }
- }
+ /* Declare all the function parameters as variables
+ * and install them in parameters[]
+ */
+ size_t nparams = Parameter::dim(f->parameters);
+ if (nparams)
+ { /* parameters[] has all the tuples removed, as the back end
+ * doesn't know about tuples
+ */
+ parameters = new Dsymbols();
+ parameters->reserve(nparams);
+ for (size_t i = 0; i < nparams; i++)
+ {
+ Parameter *arg = Parameter::getNth(f->parameters, i);
+ Identifier *id = arg->ident;
+ if (!id)
+ {
+ /* Generate identifier for un-named parameter,
+ * because we need it later on.
+ */
+ arg->ident = id = Identifier::generateId("_param_", i);
+ }
+ Type *vtype = arg->type;
+ VarDeclaration *v = new VarDeclaration(loc, vtype, id, NULL);
+ //printf("declaring parameter %s of type %s\n", v->toChars(), v->type->toChars());
+ v->storage_class |= STCparameter;
+ if (f->varargs == 2 && i + 1 == nparams)
+ v->storage_class |= STCvariadic;
+ v->storage_class |= arg->storageClass & (STCin | STCout | STCref | STClazy);
+ if (v->storage_class & STClazy)
+ v->storage_class |= STCin;
+ v->semantic(sc2);
+ if (!sc2->insert(v))
+ error("parameter %s.%s is already defined", toChars(), v->toChars());
+ else
+ parameters->push(v);
+ localsymtab->insert(v);
+ v->parent = this;
+ }
+ }
- // Declare the tuple symbols and put them in the symbol table,
- // but not in parameters[].
- if (f->parameters)
- {
- for (size_t i = 0; i < f->parameters->dim; i++)
- { Parameter *arg = (Parameter *)f->parameters->data[i];
+ // Declare the tuple symbols and put them in the symbol table,
+ // but not in parameters[].
+ if (f->parameters)
+ {
+ for (size_t i = 0; i < f->parameters->dim; i++)
+ { Parameter *arg = (Parameter *)f->parameters->data[i];
- if (!arg->ident)
- continue; // never used, so ignore
- if (arg->type->ty == Ttuple)
- { TypeTuple *t = (TypeTuple *)arg->type;
- size_t dim = Parameter::dim(t->arguments);
- Objects *exps = new Objects();
- exps->setDim(dim);
- for (size_t j = 0; j < dim; j++)
- { Parameter *narg = Parameter::getNth(t->arguments, j);
- assert(narg->ident);
- VarDeclaration *v = sc2->search(0, narg->ident, NULL)->isVarDeclaration();
- assert(v);
- Expression *e = new VarExp(v->loc, v);
- exps->data[j] = (void *)e;
- }
- assert(arg->ident);
- TupleDeclaration *v = new TupleDeclaration(loc, arg->ident, exps);
- //printf("declaring tuple %s\n", v->toChars());
- v->isexp = 1;
- if (!sc2->insert(v))
- error("parameter %s.%s is already defined", toChars(), v->toChars());
- localsymtab->insert(v);
- v->parent = this;
- }
- }
- }
+ if (!arg->ident)
+ continue; // never used, so ignore
+ if (arg->type->ty == Ttuple)
+ { TypeTuple *t = (TypeTuple *)arg->type;
+ size_t dim = Parameter::dim(t->arguments);
+ Objects *exps = new Objects();
+ exps->setDim(dim);
+ for (size_t j = 0; j < dim; j++)
+ { Parameter *narg = Parameter::getNth(t->arguments, j);
+ assert(narg->ident);
+ VarDeclaration *v = sc2->search(0, narg->ident, NULL)->isVarDeclaration();
+ assert(v);
+ Expression *e = new VarExp(v->loc, v);
+ exps->data[j] = (void *)e;
+ }
+ assert(arg->ident);
+ TupleDeclaration *v = new TupleDeclaration(loc, arg->ident, exps);
+ //printf("declaring tuple %s\n", v->toChars());
+ v->isexp = 1;
+ if (!sc2->insert(v))
+ error("parameter %s.%s is already defined", toChars(), v->toChars());
+ localsymtab->insert(v);
+ v->parent = this;
+ }
+ }
+ }
- /* Do the semantic analysis on the [in] preconditions and
- * [out] postconditions.
- */
- sc2->incontract++;
+ /* Do the semantic analysis on the [in] preconditions and
+ * [out] postconditions.
+ */
+ sc2->incontract++;
- if (frequire)
- { /* frequire is composed of the [in] contracts
- */
- // BUG: need to error if accessing out parameters
- // BUG: need to treat parameters as const
- // BUG: need to disallow returns and throws
- // BUG: verify that all in and ref parameters are read
- frequire = frequire->semantic(sc2);
- labtab = NULL; // so body can't refer to labels
- }
+ if (frequire)
+ { /* frequire is composed of the [in] contracts
+ */
+ // BUG: need to error if accessing out parameters
+ // BUG: need to treat parameters as const
+ // BUG: need to disallow returns and throws
+ // BUG: verify that all in and ref parameters are read
+ frequire = frequire->semantic(sc2);
+ labtab = NULL; // so body can't refer to labels
+ }
- if (fensure || addPostInvariant())
- { /* fensure is composed of the [out] contracts
- */
- if (!type->nextOf())
- { // Have to do semantic() on fbody first
- error("post conditions are not supported if the return type is inferred");
- return;
- }
+ if (fensure || addPostInvariant())
+ { /* fensure is composed of the [out] contracts
+ */
+ if (!type->nextOf())
+ { // Have to do semantic() on fbody first
+ error("post conditions are not supported if the return type is inferred");
+ return;
+ }
- ScopeDsymbol *sym = new ScopeDsymbol();
- sym->parent = sc2->scopesym;
- sc2 = sc2->push(sym);
+ ScopeDsymbol *sym = new ScopeDsymbol();
+ sym->parent = sc2->scopesym;
+ sc2 = sc2->push(sym);
- assert(type->nextOf());
- if (type->nextOf()->ty == Tvoid)
- {
- if (outId)
- error("void functions have no result");
- }
- else
- {
- if (!outId)
- outId = Id::result; // provide a default
- }
+ assert(type->nextOf());
+ if (type->nextOf()->ty == Tvoid)
+ {
+ if (outId)
+ error("void functions have no result");
+ }
+ else
+ {
+ if (!outId)
+ outId = Id::result; // provide a default
+ }
- if (outId)
- { // Declare result variable
- VarDeclaration *v;
- Loc loc = this->loc;
+ if (outId)
+ { // Declare result variable
+ VarDeclaration *v;
+ Loc loc = this->loc;
- if (fensure)
- loc = fensure->loc;
+ if (fensure)
+ loc = fensure->loc;
- v = new VarDeclaration(loc, type->nextOf(), outId, NULL);
- v->noscope = 1;
+ v = new VarDeclaration(loc, type->nextOf(), outId, NULL);
+ v->noscope = 1;
#if DMDV2
- if (!isVirtual())
- v->storage_class |= STCconst;
- if (f->isref)
- {
- v->storage_class |= STCref | STCforeach;
- }
+ if (!isVirtual())
+ v->storage_class |= STCconst;
+ if (f->isref)
+ {
+ v->storage_class |= STCref | STCforeach;
+ }
#endif
- sc2->incontract--;
- v->semantic(sc2);
- sc2->incontract++;
- if (!sc2->insert(v))
- error("out result %s is already defined", v->toChars());
- v->parent = this;
- vresult = v;
+ sc2->incontract--;
+ v->semantic(sc2);
+ sc2->incontract++;
+ if (!sc2->insert(v))
+ error("out result %s is already defined", v->toChars());
+ v->parent = this;
+ vresult = v;
- // vresult gets initialized with the function return value
- // in ReturnStatement::semantic()
- }
+ // vresult gets initialized with the function return value
+ // in ReturnStatement::semantic()
+ }
- // BUG: need to treat parameters as const
- // BUG: need to disallow returns and throws
- if (fensure)
- { fensure = fensure->semantic(sc2);
- labtab = NULL; // so body can't refer to labels
- }
+ // BUG: need to treat parameters as const
+ // BUG: need to disallow returns and throws
+ if (fensure)
+ { fensure = fensure->semantic(sc2);
+ labtab = NULL; // so body can't refer to labels
+ }
- if (!global.params.useOut)
- { fensure = NULL; // discard
- vresult = NULL;
- }
+ if (!global.params.useOut)
+ { fensure = NULL; // discard
+ vresult = NULL;
+ }
- // Postcondition invariant
- if (addPostInvariant())
- {
- Expression *e = NULL;
- if (isCtorDeclaration())
- {
- // Call invariant directly only if it exists
- InvariantDeclaration *inv = ad->inv;
- ClassDeclaration *cd = ad->isClassDeclaration();
+ // Postcondition invariant
+ if (addPostInvariant())
+ {
+ Expression *e = NULL;
+ if (isCtorDeclaration())
+ {
+ // Call invariant directly only if it exists
+ InvariantDeclaration *inv = ad->inv;
+ ClassDeclaration *cd = ad->isClassDeclaration();
- while (!inv && cd)
- {
- cd = cd->baseClass;
- if (!cd)
- break;
- inv = cd->inv;
- }
- if (inv)
- {
- e = new DsymbolExp(0, inv);
- e = new CallExp(0, e);
- e = e->semantic(sc2);
- }
- }
- else
- { // Call invariant virtually
- Expression *v = new ThisExp(0);
- v->type = vthis->type;
+ while (!inv && cd)
+ {
+ cd = cd->baseClass;
+ if (!cd)
+ break;
+ inv = cd->inv;
+ }
+ if (inv)
+ {
+ e = new DsymbolExp(0, inv);
+ e = new CallExp(0, e);
+ e = e->semantic(sc2);
+ }
+ }
+ else
+ { // Call invariant virtually
+ Expression *v = new ThisExp(0);
+ v->type = vthis->type;
#if STRUCTTHISREF
- if (ad->isStructDeclaration())
- v = v->addressOf(sc);
+ if (ad->isStructDeclaration())
+ v = v->addressOf(sc);
#endif
- e = new AssertExp(0, v);
- }
- if (e)
- {
- ExpStatement *s = new ExpStatement(0, e);
- if (fensure)
- fensure = new CompoundStatement(0, s, fensure);
- else
- fensure = s;
- }
- }
+ e = new AssertExp(0, v);
+ }
+ if (e)
+ {
+ ExpStatement *s = new ExpStatement(0, e);
+ if (fensure)
+ fensure = new CompoundStatement(0, s, fensure);
+ else
+ fensure = s;
+ }
+ }
- if (fensure)
- { returnLabel = new LabelDsymbol(Id::returnLabel);
- LabelStatement *ls = new LabelStatement(0, Id::returnLabel, fensure);
- ls->isReturnLabel = 1;
- returnLabel->statement = ls;
- }
- sc2 = sc2->pop();
- }
+ if (fensure)
+ { returnLabel = new LabelDsymbol(Id::returnLabel);
+ LabelStatement *ls = new LabelStatement(0, Id::returnLabel, fensure);
+ ls->isReturnLabel = 1;
+ returnLabel->statement = ls;
+ }
+ sc2 = sc2->pop();
+ }
- sc2->incontract--;
+ sc2->incontract--;
- if (fbody)
- { ClassDeclaration *cd = isClassMember();
+ if (fbody)
+ { ClassDeclaration *cd = isClassMember();
- /* If this is a class constructor
- */
- if (isCtorDeclaration() && cd)
- {
- for (int i = 0; i < cd->fields.dim; i++)
- { VarDeclaration *v = (VarDeclaration *)cd->fields.data[i];
+ /* If this is a class constructor
+ */
+ if (isCtorDeclaration() && cd)
+ {
+ for (int i = 0; i < cd->fields.dim; i++)
+ { VarDeclaration *v = (VarDeclaration *)cd->fields.data[i];
- v->ctorinit = 0;
- }
- }
+ v->ctorinit = 0;
+ }
+ }
- if (inferRetType || f->retStyle() != RETstack)
- nrvo_can = 0;
+ if (inferRetType || f->retStyle() != RETstack)
+ nrvo_can = 0;
- fbody = fbody->semantic(sc2);
+ fbody = fbody->semantic(sc2);
- if (inferRetType)
- { // If no return type inferred yet, then infer a void
- if (!type->nextOf())
- {
- ((TypeFunction *)type)->next = Type::tvoid;
- type = type->semantic(loc, sc);
- }
- f = (TypeFunction *)type;
- }
+ if (inferRetType)
+ { // If no return type inferred yet, then infer a void
+ if (!type->nextOf())
+ {
+ ((TypeFunction *)type)->next = Type::tvoid;
+ type = type->semantic(loc, sc);
+ }
+ f = (TypeFunction *)type;
+ }
- int offend = fbody ? fbody->blockExit() & BEfallthru : TRUE;
+ int offend = fbody ? fbody->blockExit() & BEfallthru : TRUE;
- if (isStaticCtorDeclaration())
- { /* It's a static constructor. Ensure that all
- * ctor consts were initialized.
- */
+ if (isStaticCtorDeclaration())
+ { /* It's a static constructor. Ensure that all
+ * ctor consts were initialized.
+ */
- Dsymbol *p = toParent();
- ScopeDsymbol *ad = p->isScopeDsymbol();
- if (!ad)
- {
- error("static constructor can only be member of struct/class/module, not %s %s", p->kind(), p->toChars());
- }
- else
- {
- for (int i = 0; i < ad->members->dim; i++)
- { Dsymbol *s = (Dsymbol *)ad->members->data[i];
+ Dsymbol *p = toParent();
+ ScopeDsymbol *ad = p->isScopeDsymbol();
+ if (!ad)
+ {
+ error("static constructor can only be member of struct/class/module, not %s %s", p->kind(), p->toChars());
+ }
+ else
+ {
+ for (int i = 0; i < ad->members->dim; i++)
+ { Dsymbol *s = (Dsymbol *)ad->members->data[i];
- s->checkCtorConstInit();
- }
- }
- }
+ s->checkCtorConstInit();
+ }
+ }
+ }
- if (isCtorDeclaration() && cd)
- {
- //printf("callSuper = x%x\n", sc2->callSuper);
+ if (isCtorDeclaration() && cd)
+ {
+ //printf("callSuper = x%x\n", sc2->callSuper);
- // Verify that all the ctorinit fields got initialized
- if (!(sc2->callSuper & CSXthis_ctor))
- {
- for (int i = 0; i < cd->fields.dim; i++)
- { VarDeclaration *v = (VarDeclaration *)cd->fields.data[i];
+ // Verify that all the ctorinit fields got initialized
+ if (!(sc2->callSuper & CSXthis_ctor))
+ {
+ for (int i = 0; i < cd->fields.dim; i++)
+ { VarDeclaration *v = (VarDeclaration *)cd->fields.data[i];
- if (v->ctorinit == 0 && v->isCtorinit())
- error("missing initializer for const field %s", v->toChars());
- }
- }
+ if (v->ctorinit == 0 && v->isCtorinit())
+ error("missing initializer for const field %s", v->toChars());
+ }
+ }
- if (!(sc2->callSuper & CSXany_ctor) &&
- cd->baseClass && cd->baseClass->ctor)
- {
- sc2->callSuper = 0;
+ if (!(sc2->callSuper & CSXany_ctor) &&
+ cd->baseClass && cd->baseClass->ctor)
+ {
+ sc2->callSuper = 0;
- // Insert implicit super() at start of fbody
- Expression *e1 = new SuperExp(0);
- Expression *e = new CallExp(0, e1);
+ // Insert implicit super() at start of fbody
+ Expression *e1 = new SuperExp(0);
+ Expression *e = new CallExp(0, e1);
- unsigned errors = global.errors;
- global.gag++;
- e = e->semantic(sc2);
- global.gag--;
- if (errors != global.errors)
- error("no match for implicit super() call in constructor");
+ unsigned errors = global.errors;
+ global.gag++;
+ e = e->semantic(sc2);
+ global.gag--;
+ if (errors != global.errors)
+ error("no match for implicit super() call in constructor");
- Statement *s = new ExpStatement(0, e);
- fbody = new CompoundStatement(0, s, fbody);
- }
- }
- else if (fes)
- { // For foreach(){} body, append a return 0;
- Expression *e = new IntegerExp(0);
- Statement *s = new ReturnStatement(0, e);
- fbody = new CompoundStatement(0, fbody, s);
- assert(!returnLabel);
- }
- else if (!hasReturnExp && type->nextOf()->ty != Tvoid)
- error("expected to return a value of type %s", type->nextOf()->toChars());
- else if (!inlineAsm)
- {
+ Statement *s = new ExpStatement(0, e);
+ fbody = new CompoundStatement(0, s, fbody);
+ }
+ }
+ else if (fes)
+ { // For foreach(){} body, append a return 0;
+ Expression *e = new IntegerExp(0);
+ Statement *s = new ReturnStatement(0, e);
+ fbody = new CompoundStatement(0, fbody, s);
+ assert(!returnLabel);
+ }
+ else if (!hasReturnExp && type->nextOf()->ty != Tvoid)
+ error("expected to return a value of type %s", type->nextOf()->toChars());
+ else if (!inlineAsm)
+ {
#if DMDV2
- int blockexit = fbody ? fbody->blockExit() : BEfallthru;
- if (f->isnothrow && blockexit & BEthrow)
- error("'%s' is nothrow yet may throw", toChars());
+ int blockexit = fbody ? fbody->blockExit() : BEfallthru;
+ if (f->isnothrow && blockexit & BEthrow)
+ error("'%s' is nothrow yet may throw", toChars());
- int offend = blockexit & BEfallthru;
+ int offend = blockexit & BEfallthru;
#endif
- if (type->nextOf()->ty == Tvoid)
- {
- if (offend && isMain())
- { // Add a return 0; statement
- Statement *s = new ReturnStatement(0, new IntegerExp(0));
- fbody = new CompoundStatement(0, fbody, s);
- }
- }
- else
- {
- if (offend)
- { Expression *e;
+ if (type->nextOf()->ty == Tvoid)
+ {
+ if (offend && isMain())
+ { // Add a return 0; statement
+ Statement *s = new ReturnStatement(0, new IntegerExp(0));
+ fbody = new CompoundStatement(0, fbody, s);
+ }
+ }
+ else
+ {
+ if (offend)
+ { Expression *e;
#if DMDV1
- warning(loc, "no return exp; or assert(0); at end of function");
+ warning(loc, "no return exp; or assert(0); at end of function");
#else
- error("no return exp; or assert(0); at end of function");
+ error("no return exp; or assert(0); at end of function");
#endif
- if (global.params.useAssert &&
- !global.params.useInline)
- { /* Add an assert(0, msg); where the missing return
- * should be.
- */
- e = new AssertExp(
- endloc,
- new IntegerExp(0),
- new StringExp(loc, (char *)"missing return expression")
- );
- }
- else
- e = new HaltExp(endloc);
- e = new CommaExp(0, e, type->nextOf()->defaultInit());
- e = e->semantic(sc2);
- Statement *s = new ExpStatement(0, e);
- fbody = new CompoundStatement(0, fbody, s);
- }
- }
- }
- }
+ if (global.params.useAssert &&
+ !global.params.useInline)
+ { /* Add an assert(0, msg); where the missing return
+ * should be.
+ */
+ e = new AssertExp(
+ endloc,
+ new IntegerExp(0),
+ new StringExp(loc, (char *)"missing return expression")
+ );
+ }
+ else
+ e = new HaltExp(endloc);
+ e = new CommaExp(0, e, type->nextOf()->defaultInit());
+ e = e->semantic(sc2);
+ Statement *s = new ExpStatement(0, e);
+ fbody = new CompoundStatement(0, fbody, s);
+ }
+ }
+ }
+ }
- {
- Statements *a = new Statements();
+ {
+ Statements *a = new Statements();
- // Merge in initialization of 'out' parameters
- if (parameters)
- { for (size_t i = 0; i < parameters->dim; i++)
- {
- VarDeclaration *v = (VarDeclaration *)parameters->data[i];
- if (v->storage_class & STCout)
- {
- assert(v->init);
- ExpInitializer *ie = v->init->isExpInitializer();
- assert(ie);
- a->push(new ExpStatement(0, ie->exp));
- }
- }
- }
+ // Merge in initialization of 'out' parameters
+ if (parameters)
+ { for (size_t i = 0; i < parameters->dim; i++)
+ {
+ VarDeclaration *v = (VarDeclaration *)parameters->data[i];
+ if (v->storage_class & STCout)
+ {
+ assert(v->init);
+ ExpInitializer *ie = v->init->isExpInitializer();
+ assert(ie);
+ a->push(new ExpStatement(0, ie->exp));
+ }
+ }
+ }
// we'll handle variadics ourselves
#if !IN_LLVM
- if (argptr)
- { // Initialize _argptr to point past non-variadic arg
+ if (argptr)
+ { // Initialize _argptr to point past non-variadic arg
#if IN_GCC
- // Handled in FuncDeclaration::toObjFile
- v_argptr = argptr;
- v_argptr->init = new VoidInitializer(loc);
+ // Handled in FuncDeclaration::toObjFile
+ v_argptr = argptr;
+ v_argptr->init = new VoidInitializer(loc);
#else
- Type *t = argptr->type;
- VarDeclaration *p;
- unsigned offset;
+ Type *t = argptr->type;
+ VarDeclaration *p;
+ unsigned offset;
- Expression *e1 = new VarExp(0, argptr);
- if (parameters && parameters->dim)
- p = (VarDeclaration *)parameters->data[parameters->dim - 1];
- else
- p = v_arguments; // last parameter is _arguments[]
- if (p->storage_class & STClazy)
- // If the last parameter is lazy, it's the size of a delegate
- offset = PTRSIZE * 2;
- else
- offset = p->type->size();
- offset = (offset + 3) & ~3; // assume stack aligns on 4
- Expression *e = new SymOffExp(0, p, offset);
- e = new AssignExp(0, e1, e);
- e->type = t;
- a->push(new ExpStatement(0, e));
+ Expression *e1 = new VarExp(0, argptr);
+ if (parameters && parameters->dim)
+ p = (VarDeclaration *)parameters->data[parameters->dim - 1];
+ else
+ p = v_arguments; // last parameter is _arguments[]
+ if (p->storage_class & STClazy)
+ // If the last parameter is lazy, it's the size of a delegate
+ offset = PTRSIZE * 2;
+ else
+ offset = p->type->size();
+ offset = (offset + 3) & ~3; // assume stack aligns on 4
+ Expression *e = new SymOffExp(0, p, offset);
+ e = new AssignExp(0, e1, e);
+ e->type = t;
+ a->push(new ExpStatement(0, e));
#endif // IN_GCC
- }
+ }
- if (_arguments)
- {
- /* Advance to elements[] member of TypeInfo_Tuple with:
- * _arguments = v_arguments.elements;
- */
- Expression *e = new VarExp(0, v_arguments);
- e = new DotIdExp(0, e, Id::elements);
- Expression *e1 = new VarExp(0, _arguments);
- e = new AssignExp(0, e1, e);
- e->op = TOKconstruct;
- e = e->semantic(sc2);
- a->push(new ExpStatement(0, e));
- }
+ if (_arguments)
+ {
+ /* Advance to elements[] member of TypeInfo_Tuple with:
+ * _arguments = v_arguments.elements;
+ */
+ Expression *e = new VarExp(0, v_arguments);
+ e = new DotIdExp(0, e, Id::elements);
+ Expression *e1 = new VarExp(0, _arguments);
+ e = new AssignExp(0, e1, e);
+ e->op = TOKconstruct;
+ e = e->semantic(sc2);
+ a->push(new ExpStatement(0, e));
+ }
#endif // !IN_LLVM
- // Merge contracts together with body into one compound statement
+ // Merge contracts together with body into one compound statement
#ifdef _DH
- if (frequire && global.params.useIn)
- { frequire->incontract = 1;
- a->push(frequire);
- }
+ if (frequire && global.params.useIn)
+ { frequire->incontract = 1;
+ a->push(frequire);
+ }
#else
- if (frequire && global.params.useIn)
- a->push(frequire);
+ if (frequire && global.params.useIn)
+ a->push(frequire);
#endif
- // Precondition invariant
- if (addPreInvariant())
- {
- Expression *e = NULL;
+ // Precondition invariant
+ if (addPreInvariant())
+ {
+ Expression *e = NULL;
Expression *ee = NULL;
- if (isDtorDeclaration())
- {
- // Call invariant directly only if it exists
- InvariantDeclaration *inv = ad->inv;
- ClassDeclaration *cd = ad->isClassDeclaration();
+ if (isDtorDeclaration())
+ {
+ // Call invariant directly only if it exists
+ InvariantDeclaration *inv = ad->inv;
+ ClassDeclaration *cd = ad->isClassDeclaration();
- while (!inv && cd)
- {
- cd = cd->baseClass;
- if (!cd)
- break;
- inv = cd->inv;
- }
- if (inv)
- {
- e = new DsymbolExp(0, inv);
- e = new CallExp(0, e);
- e = e->semantic(sc2);
- }
- }
- else
- { // Call invariant virtually
+ while (!inv && cd)
+ {
+ cd = cd->baseClass;
+ if (!cd)
+ break;
+ inv = cd->inv;
+ }
+ if (inv)
+ {
+ e = new DsymbolExp(0, inv);
+ e = new CallExp(0, e);
+ e = e->semantic(sc2);
+ }
+ }
+ else
+ { // Call invariant virtually
// LDC: unless this is a struct without invariant
StructDeclaration* sd = ad->isStructDeclaration();
if (!sd || sd->inv)
@@ -1366,9 +1366,9 @@ void FuncDeclaration::semantic3(Scope *sc)
ThisExp* v = new ThisExp(0);
v->type = vthis->type;
#if STRUCTTHISREF
- if (ad->isStructDeclaration())
- v = v->addressOf(sc);
-#endif
+ if (ad->isStructDeclaration())
+ v = v->addressOf(sc);
+#endif
v->var = vthis;
NullExp *nv = new NullExp(0);
@@ -1377,117 +1377,117 @@ void FuncDeclaration::semantic3(Scope *sc)
IdentityExp *ie = new IdentityExp(TOKnotidentity, 0, v, nv);
ie->type = Type::tbool;
- Expression *se = new StringExp(0, (char *)"null this");
- se = se->semantic(sc);
- se->type = Type::tchar->arrayOf();
+ Expression *se = new StringExp(0, (char *)"null this");
+ se = se->semantic(sc);
+ se->type = Type::tchar->arrayOf();
- ee = new AssertExp(loc, ie, se);
- }
+ ee = new AssertExp(loc, ie, se);
+ }
if (ee)
{
ExpStatement *s = new ExpStatement(0, ee);
a->push(s);
}
- if (e)
- {
- ExpStatement *s = new ExpStatement(0, e);
- a->push(s);
- }
- }
+ if (e)
+ {
+ ExpStatement *s = new ExpStatement(0, e);
+ a->push(s);
+ }
+ }
- if (fbody)
- a->push(fbody);
+ if (fbody)
+ a->push(fbody);
- if (fensure)
- {
- a->push(returnLabel->statement);
+ if (fensure)
+ {
+ a->push(returnLabel->statement);
- if (type->nextOf()->ty != Tvoid)
- {
- // Create: return vresult;
- assert(vresult);
- Expression *e = new VarExp(0, vresult);
- if (tintro)
- { e = e->implicitCastTo(sc, tintro->nextOf());
- e = e->semantic(sc);
- }
- ReturnStatement *s = new ReturnStatement(0, e);
- a->push(s);
- }
- }
+ if (type->nextOf()->ty != Tvoid)
+ {
+ // Create: return vresult;
+ assert(vresult);
+ Expression *e = new VarExp(0, vresult);
+ if (tintro)
+ { e = e->implicitCastTo(sc, tintro->nextOf());
+ e = e->semantic(sc);
+ }
+ ReturnStatement *s = new ReturnStatement(0, e);
+ a->push(s);
+ }
+ }
- fbody = new CompoundStatement(0, a);
+ fbody = new CompoundStatement(0, a);
#if DMDV2
- /* Append destructor calls for parameters as finally blocks.
- */
- if (parameters)
- { for (size_t i = 0; i < parameters->dim; i++)
- {
- VarDeclaration *v = (VarDeclaration *)parameters->data[i];
+ /* Append destructor calls for parameters as finally blocks.
+ */
+ if (parameters)
+ { for (size_t i = 0; i < parameters->dim; i++)
+ {
+ VarDeclaration *v = (VarDeclaration *)parameters->data[i];
- if (v->storage_class & (STCref | STCout))
- continue;
+ if (v->storage_class & (STCref | STCout))
+ continue;
- /* Don't do this for static arrays, since static
- * arrays are called by reference. Remove this
- * when we change them to call by value.
- */
- if (v->type->toBasetype()->ty == Tsarray)
- continue;
+ /* Don't do this for static arrays, since static
+ * arrays are called by reference. Remove this
+ * when we change them to call by value.
+ */
+ if (v->type->toBasetype()->ty == Tsarray)
+ continue;
- Expression *e = v->callAutoDtor(sc);
- if (e)
- { Statement *s = new ExpStatement(0, e);
- s = s->semantic(sc);
- if (fbody->blockExit() == BEfallthru)
- fbody = new CompoundStatement(0, fbody, s);
- else
- fbody = new TryFinallyStatement(0, fbody, s);
- }
- }
- }
+ Expression *e = v->callAutoDtor(sc);
+ if (e)
+ { Statement *s = new ExpStatement(0, e);
+ s = s->semantic(sc);
+ if (fbody->blockExit() == BEfallthru)
+ fbody = new CompoundStatement(0, fbody, s);
+ else
+ fbody = new TryFinallyStatement(0, fbody, s);
+ }
+ }
+ }
#endif
- // wrap body of synchronized functions in a synchronized statement
- if (isSynchronized())
- {
- ClassDeclaration *cd = parent->isClassDeclaration();
- if (!cd)
- error("synchronized function %s must be a member of a class", toChars());
-
- Expression *sync;
- if (isStatic())
- {
- // static member functions synchronize on classinfo
- sync = cd->type->dotExp(sc2, new TypeExp(loc, cd->type), Id::classinfo);
- }
- else
- {
- // non-static member functions synchronize on this
- sync = new VarExp(loc, vthis);
- }
-
- // we do not want to rerun semantics on the whole function, so we
- // manually adjust all labels in the function that currently don't
- // have an enclosingScopeExit to use the new SynchronizedStatement
- SynchronizedStatement* s = new SynchronizedStatement(loc, sync, NULL);
- s->semantic(sc2);
- s->body = fbody;
-
- // LDC
- LabelMap::iterator it, end = labmap.end();
- for (it = labmap.begin(); it != end; ++it)
- if (it->second->enclosingScopeExit == NULL)
- it->second->enclosingScopeExit = s;
-
- a = new Statements;
- a->push(s);
- fbody = new CompoundStatement(0, a);
- }
- }
+ // wrap body of synchronized functions in a synchronized statement
+ if (isSynchronized())
+ {
+ ClassDeclaration *cd = parent->isClassDeclaration();
+ if (!cd)
+ error("synchronized function %s must be a member of a class", toChars());
- sc2->callSuper = 0;
- sc2->pop();
+ Expression *sync;
+ if (isStatic())
+ {
+ // static member functions synchronize on classinfo
+ sync = cd->type->dotExp(sc2, new TypeExp(loc, cd->type), Id::classinfo);
+ }
+ else
+ {
+ // non-static member functions synchronize on this
+ sync = new VarExp(loc, vthis);
+ }
+
+ // we do not want to rerun semantics on the whole function, so we
+ // manually adjust all labels in the function that currently don't
+ // have an enclosingScopeExit to use the new SynchronizedStatement
+ SynchronizedStatement* s = new SynchronizedStatement(loc, sync, NULL);
+ s->semantic(sc2);
+ s->body = fbody;
+
+ // LDC
+ LabelMap::iterator it, end = labmap.end();
+ for (it = labmap.begin(); it != end; ++it)
+ if (it->second->enclosingScopeExit == NULL)
+ it->second->enclosingScopeExit = s;
+
+ a = new Statements;
+ a->push(s);
+ fbody = new CompoundStatement(0, a);
+ }
+ }
+
+ sc2->callSuper = 0;
+ sc2->pop();
}
semanticRun = PASSsemantic3done;
}
@@ -1504,43 +1504,43 @@ void FuncDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
void FuncDeclaration::bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (fbody &&
- (!hgs->hdrgen || hgs->tpltMember || canInline(1,1))
+ (!hgs->hdrgen || hgs->tpltMember || canInline(1,1))
)
- { buf->writenl();
+ { buf->writenl();
- // in{}
- if (frequire)
- { buf->writestring("in");
- buf->writenl();
- frequire->toCBuffer(buf, hgs);
- }
+ // in{}
+ if (frequire)
+ { buf->writestring("in");
+ buf->writenl();
+ frequire->toCBuffer(buf, hgs);
+ }
- // out{}
- if (fensure)
- { buf->writestring("out");
- if (outId)
- { buf->writebyte('(');
- buf->writestring(outId->toChars());
- buf->writebyte(')');
- }
- buf->writenl();
- fensure->toCBuffer(buf, hgs);
- }
+ // out{}
+ if (fensure)
+ { buf->writestring("out");
+ if (outId)
+ { buf->writebyte('(');
+ buf->writestring(outId->toChars());
+ buf->writebyte(')');
+ }
+ buf->writenl();
+ fensure->toCBuffer(buf, hgs);
+ }
if (frequire || fensure)
- { buf->writestring("body");
- buf->writenl();
- }
+ { buf->writestring("body");
+ buf->writenl();
+ }
- buf->writebyte('{');
- buf->writenl();
- fbody->toCBuffer(buf, hgs);
- buf->writebyte('}');
- buf->writenl();
+ buf->writebyte('{');
+ buf->writenl();
+ fbody->toCBuffer(buf, hgs);
+ buf->writebyte('}');
+ buf->writenl();
}
else
- { buf->writeByte(';');
- buf->writenl();
+ { buf->writeByte(';');
+ buf->writenl();
}
}
@@ -1560,37 +1560,37 @@ Statement *FuncDeclaration::mergeFrequire(Statement *sf)
* place by definition, since it's an overriding function. The problem is
* getting the 'this' pointer in the same place, since it is a local variable.
* We did some hacks in the code generator to make this happen:
- * 1. always generate exception handler frame, or at least leave space for it
+ * 1. always generate exception handler frame, or at least leave space for it
* in the frame (Windows 32 SEH only)
- * 2. always generate an EBP style frame
+ * 2. always generate an EBP style frame
* 3. since 'this' is passed in a register that is subsequently copied into
* a stack local, allocate that local immediately following the exception
* handler block, so it is always at the same offset from EBP.
*/
for (int i = 0; i < foverrides.dim; i++)
{
- FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i];
- sf = fdv->mergeFrequire(sf);
- if (fdv->fdrequire)
- {
- //printf("fdv->frequire: %s\n", fdv->frequire->toChars());
- /* Make the call:
- * try { __require(); }
- * catch { frequire; }
- */
- Expression *eresult = NULL;
- Expression *e = new CallExp(loc, new VarExp(loc, fdv->fdrequire), eresult);
- Statement *s2 = new ExpStatement(loc, e);
+ FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i];
+ sf = fdv->mergeFrequire(sf);
+ if (fdv->fdrequire)
+ {
+ //printf("fdv->frequire: %s\n", fdv->frequire->toChars());
+ /* Make the call:
+ * try { __require(); }
+ * catch { frequire; }
+ */
+ Expression *eresult = NULL;
+ Expression *e = new CallExp(loc, new VarExp(loc, fdv->fdrequire), eresult);
+ Statement *s2 = new ExpStatement(loc, e);
- if (sf)
- { Catch *c = new Catch(loc, NULL, NULL, sf);
- Array *catches = new Array();
- catches->push(c);
- sf = new TryCatchStatement(loc, s2, catches);
- }
- else
- sf = s2;
- }
+ if (sf)
+ { Catch *c = new Catch(loc, NULL, NULL, sf);
+ Array *catches = new Array();
+ catches->push(c);
+ sf = new TryCatchStatement(loc, s2, catches);
+ }
+ else
+ sf = s2;
+ }
}
return sf;
}
@@ -1613,25 +1613,25 @@ Statement *FuncDeclaration::mergeFensure(Statement *sf)
*/
for (int i = 0; i < foverrides.dim; i++)
{
- FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i];
- sf = fdv->mergeFensure(sf);
- if (fdv->fdensure)
- {
- //printf("fdv->fensure: %s\n", fdv->fensure->toChars());
- // Make the call: __ensure(result)
- Expression *eresult = NULL;
- if (outId)
- eresult = new IdentifierExp(loc, outId);
- Expression *e = new CallExp(loc, new VarExp(loc, fdv->fdensure), eresult);
- Statement *s2 = new ExpStatement(loc, e);
+ FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i];
+ sf = fdv->mergeFensure(sf);
+ if (fdv->fdensure)
+ {
+ //printf("fdv->fensure: %s\n", fdv->fensure->toChars());
+ // Make the call: __ensure(result)
+ Expression *eresult = NULL;
+ if (outId)
+ eresult = new IdentifierExp(loc, outId);
+ Expression *e = new CallExp(loc, new VarExp(loc, fdv->fdensure), eresult);
+ Statement *s2 = new ExpStatement(loc, e);
- if (sf)
- {
- sf = new CompoundStatement(fensure->loc, s2, sf);
- }
- else
- sf = s2;
- }
+ if (sf)
+ {
+ sf = new CompoundStatement(fensure->loc, s2, sf);
+ }
+ else
+ sf = s2;
+ }
}
return sf;
}
@@ -1646,14 +1646,14 @@ int FuncDeclaration::overrides(FuncDeclaration *fd)
if (fd->ident == ident)
{
- int cov = type->covariant(fd->type);
- if (cov)
- { ClassDeclaration *cd1 = toParent()->isClassDeclaration();
- ClassDeclaration *cd2 = fd->toParent()->isClassDeclaration();
+ int cov = type->covariant(fd->type);
+ if (cov)
+ { ClassDeclaration *cd1 = toParent()->isClassDeclaration();
+ ClassDeclaration *cd2 = fd->toParent()->isClassDeclaration();
- if (cd1 && cd2 && cd2->isBaseOf(cd1, NULL))
- result = 1;
- }
+ if (cd1 && cd2 && cd2->isBaseOf(cd1, NULL))
+ result = 1;
+ }
}
return result;
}
@@ -1663,8 +1663,8 @@ int FuncDeclaration::overrides(FuncDeclaration *fd)
* this function overrides.
* Prefer an exact match to a covariant one.
* Returns:
- * -1 didn't find one
- * -2 can't determine because of forward references
+ * -1 didn't find one
+ * -2 can't determine because of forward references
*/
int FuncDeclaration::findVtblIndex(Array *vtbl, int dim)
@@ -1673,42 +1673,42 @@ int FuncDeclaration::findVtblIndex(Array *vtbl, int dim)
int bestvi = -1;
for (int vi = 0; vi < dim; vi++)
{
- FuncDeclaration *fdv = ((Dsymbol *)vtbl->data[vi])->isFuncDeclaration();
- if (fdv && fdv->ident == ident)
- {
- if (type->equals(fdv->type)) // if exact match
- return vi; // no need to look further
+ FuncDeclaration *fdv = ((Dsymbol *)vtbl->data[vi])->isFuncDeclaration();
+ if (fdv && fdv->ident == ident)
+ {
+ if (type->equals(fdv->type)) // if exact match
+ return vi; // no need to look further
- int cov = type->covariant(fdv->type);
- //printf("\tbaseclass cov = %d\n", cov);
- switch (cov)
- {
- case 0: // types are distinct
- break;
+ int cov = type->covariant(fdv->type);
+ //printf("\tbaseclass cov = %d\n", cov);
+ switch (cov)
+ {
+ case 0: // types are distinct
+ break;
- case 1:
- bestvi = vi; // covariant, but not identical
- break; // keep looking for an exact match
+ case 1:
+ bestvi = vi; // covariant, but not identical
+ break; // keep looking for an exact match
- case 2:
- mismatch = fdv; // overrides, but is not covariant
- break; // keep looking for an exact match
+ case 2:
+ mismatch = fdv; // overrides, but is not covariant
+ break; // keep looking for an exact match
- case 3:
- return -2; // forward references
+ case 3:
+ return -2; // forward references
- default:
- assert(0);
- }
- }
+ default:
+ assert(0);
+ }
+ }
}
if (bestvi == -1 && mismatch)
{
- //type->print();
- //mismatch->type->print();
- //printf("%s %s\n", type->deco, mismatch->type->deco);
- error("of type %s overrides but is not covariant with %s of type %s",
- type->toChars(), mismatch->toPrettyChars(), mismatch->type->toChars());
+ //type->print();
+ //mismatch->type->print();
+ //printf("%s %s\n", type->deco, mismatch->type->deco);
+ error("of type %s overrides but is not covariant with %s of type %s",
+ type->toChars(), mismatch->toPrettyChars(), mismatch->type->toChars());
}
return bestvi;
}
@@ -1727,31 +1727,31 @@ int FuncDeclaration::overloadInsert(Dsymbol *s)
a = s->isAliasDeclaration();
if (a)
{
- if (overnext)
- return overnext->overloadInsert(a);
- if (!a->aliassym && a->type->ty != Tident && a->type->ty != Tinstance)
- {
- //printf("\ta = '%s'\n", a->type->toChars());
- return FALSE;
- }
- overnext = a;
- //printf("\ttrue: no conflict\n");
- return TRUE;
+ if (overnext)
+ return overnext->overloadInsert(a);
+ if (!a->aliassym && a->type->ty != Tident && a->type->ty != Tinstance)
+ {
+ //printf("\ta = '%s'\n", a->type->toChars());
+ return FALSE;
+ }
+ overnext = a;
+ //printf("\ttrue: no conflict\n");
+ return TRUE;
}
f = s->isFuncDeclaration();
if (!f)
- return FALSE;
+ return FALSE;
- if (type && f->type && // can be NULL for overloaded constructors
- f->type->covariant(type) &&
- !isFuncAliasDeclaration())
+ if (type && f->type && // can be NULL for overloaded constructors
+ f->type->covariant(type) &&
+ !isFuncAliasDeclaration())
{
- //printf("\tfalse: conflict %s\n", kind());
- return FALSE;
+ //printf("\tfalse: conflict %s\n", kind());
+ return FALSE;
}
if (overnext)
- return overnext->overloadInsert(f);
+ return overnext->overloadInsert(f);
overnext = f;
//printf("\ttrue: no conflict\n");
return TRUE;
@@ -1766,57 +1766,57 @@ int FuncDeclaration::overloadInsert(Dsymbol *s)
* (*fp)(param, f) on it.
* Exit when no more, or (*fp)(param, f) returns 1.
* Returns:
- * 0 continue
- * 1 done
+ * 0 continue
+ * 1 done
*/
int overloadApply(Module* from, FuncDeclaration *fstart,
- int (*fp)(void *, FuncDeclaration *),
- void *param)
+ int (*fp)(void *, FuncDeclaration *),
+ void *param)
{
FuncDeclaration *f;
Declaration *d;
Declaration *next;
for (d = fstart; d; d = next)
- { FuncAliasDeclaration *fa = d->isFuncAliasDeclaration();
+ { FuncAliasDeclaration *fa = d->isFuncAliasDeclaration();
- if (fa)
- {
- if (fa->getModule() == from || fa->importprot != PROTprivate)
- if (overloadApply(from, fa->funcalias, fp, param))
- return 1;
- next = fa->overnext;
- }
- else
- {
- AliasDeclaration *a = d->isAliasDeclaration();
+ if (fa)
+ {
+ if (fa->getModule() == from || fa->importprot != PROTprivate)
+ if (overloadApply(from, fa->funcalias, fp, param))
+ return 1;
+ next = fa->overnext;
+ }
+ else
+ {
+ AliasDeclaration *a = d->isAliasDeclaration();
- if (a)
- {
- Dsymbol *s = a->toAlias();
- next = s->isDeclaration();
- if (next == a)
- break;
- if (next == fstart)
- break;
- if (a->importprot == PROTprivate && a->getModule() != from)
- if (FuncDeclaration* fd = next->isFuncDeclaration())
- next = fd->overnext;
- }
- else
- {
- f = d->isFuncDeclaration();
- if (!f)
- { d->error("is aliased to a function");
- break; // BUG: should print error message?
- }
- if ((*fp)(param, f))
- return 1;
+ if (a)
+ {
+ Dsymbol *s = a->toAlias();
+ next = s->isDeclaration();
+ if (next == a)
+ break;
+ if (next == fstart)
+ break;
+ if (a->importprot == PROTprivate && a->getModule() != from)
+ if (FuncDeclaration* fd = next->isFuncDeclaration())
+ next = fd->overnext;
+ }
+ else
+ {
+ f = d->isFuncDeclaration();
+ if (!f)
+ { d->error("is aliased to a function");
+ break; // BUG: should print error message?
+ }
+ if ((*fp)(param, f))
+ return 1;
- next = f->overnext;
- }
- }
+ next = f->overnext;
+ }
+ }
}
return 0;
}
@@ -1830,12 +1830,12 @@ static int fpunique(void *param, FuncDeclaration *f)
{ FuncDeclaration **pf = (FuncDeclaration **)param;
if (*pf)
- { *pf = NULL;
- return 1; // ambiguous, done
+ { *pf = NULL;
+ return 1; // ambiguous, done
}
else
- { *pf = f;
- return 0;
+ { *pf = f;
+ return 0;
}
}
@@ -1852,8 +1852,8 @@ FuncDeclaration *FuncDeclaration::isUnique()
struct Param1
{
- Type *t; // type to match
- FuncDeclaration *f; // return value
+ Type *t; // type to match
+ FuncDeclaration *f; // return value
};
int fp1(void *param, FuncDeclaration *f)
@@ -1861,8 +1861,8 @@ int fp1(void *param, FuncDeclaration *f)
Type *t = p->t;
if (t->equals(f->type))
- { p->f = f;
- return 1;
+ { p->f = f;
+ return 1;
}
#if DMDV2
@@ -1871,12 +1871,12 @@ int fp1(void *param, FuncDeclaration *f)
*/
if (t->ty == Tfunction)
{ TypeFunction *tf = (TypeFunction *)f->type;
- if (tf->covariant(t) == 1 &&
- tf->nextOf()->implicitConvTo(t->nextOf()) >= MATCHconst)
- {
- p->f = f;
- return 1;
- }
+ if (tf->covariant(t) == 1 &&
+ tf->nextOf()->implicitConvTo(t->nextOf()) >= MATCHconst)
+ {
+ p->f = f;
+ return 1;
+ }
}
#endif
return 0;
@@ -1911,64 +1911,64 @@ int fp2(void *param, FuncDeclaration *f)
Expressions *arguments = p->arguments;
MATCH match;
- if (f != m->lastf) // skip duplicates
+ if (f != m->lastf) // skip duplicates
{
- m->anyf = f;
- TypeFunction *tf = (TypeFunction *)f->type;
- match = (MATCH) tf->callMatch(arguments);
- //printf("1match = %d\n", match);
- if (match != MATCHnomatch)
- {
- if (match > m->last)
- goto LfIsBetter;
+ m->anyf = f;
+ TypeFunction *tf = (TypeFunction *)f->type;
+ match = (MATCH) tf->callMatch(arguments);
+ //printf("1match = %d\n", match);
+ if (match != MATCHnomatch)
+ {
+ if (match > m->last)
+ goto LfIsBetter;
- if (match < m->last)
- goto LlastIsBetter;
+ if (match < m->last)
+ goto LlastIsBetter;
- /* See if one of the matches overrides the other.
- */
- if (m->lastf->overrides(f))
- goto LlastIsBetter;
- else if (f->overrides(m->lastf))
- goto LfIsBetter;
+ /* See if one of the matches overrides the other.
+ */
+ if (m->lastf->overrides(f))
+ goto LlastIsBetter;
+ else if (f->overrides(m->lastf))
+ goto LfIsBetter;
#if DMDV2
- /* Try to disambiguate using template-style partial ordering rules.
- * In essence, if f() and g() are ambiguous, if f() can call g(),
- * but g() cannot call f(), then pick f().
- * This is because f() is "more specialized."
- */
- {
- MATCH c1 = f->leastAsSpecialized(m->lastf);
- MATCH c2 = m->lastf->leastAsSpecialized(f);
- //printf("c1 = %d, c2 = %d\n", c1, c2);
- if (c1 > c2)
- goto LfIsBetter;
- if (c1 < c2)
- goto LlastIsBetter;
- }
+ /* Try to disambiguate using template-style partial ordering rules.
+ * In essence, if f() and g() are ambiguous, if f() can call g(),
+ * but g() cannot call f(), then pick f().
+ * This is because f() is "more specialized."
+ */
+ {
+ MATCH c1 = f->leastAsSpecialized(m->lastf);
+ MATCH c2 = m->lastf->leastAsSpecialized(f);
+ //printf("c1 = %d, c2 = %d\n", c1, c2);
+ if (c1 > c2)
+ goto LfIsBetter;
+ if (c1 < c2)
+ goto LlastIsBetter;
+ }
#endif
- Lambiguous:
- m->nextf = f;
- m->count++;
- return 0;
+ Lambiguous:
+ m->nextf = f;
+ m->count++;
+ return 0;
- LfIsBetter:
- m->last = match;
- m->lastf = f;
- m->count = 1;
- return 0;
+ LfIsBetter:
+ m->last = match;
+ m->lastf = f;
+ m->count = 1;
+ return 0;
- LlastIsBetter:
- return 0;
- }
+ LlastIsBetter:
+ return 0;
+ }
}
return 0;
}
void overloadResolveX(Match *m, FuncDeclaration *fstart,
- Expression *ethis, Expressions *arguments, Module *from)
+ Expression *ethis, Expressions *arguments, Module *from)
{
Param2 p;
p.m = m;
@@ -1990,10 +1990,10 @@ if (arguments)
for (i = 0; i < arguments->dim; i++)
{ Expression *arg;
- arg = (Expression *)arguments->data[i];
- assert(arg->type);
- printf("\t%s: ", arg->toChars());
- arg->type->print();
+ arg = (Expression *)arguments->data[i];
+ assert(arg->type);
+ printf("\t%s: ", arg->toChars());
+ arg->type->print();
}
}
#endif
@@ -2002,49 +2002,49 @@ if (arguments)
m.last = MATCHnomatch;
overloadResolveX(&m, this, NULL, arguments, from);
- if (m.count == 1) // exactly one match
+ if (m.count == 1) // exactly one match
{
- return m.lastf;
+ return m.lastf;
}
else
{
- OutBuffer buf;
+ OutBuffer buf;
- if (arguments)
- {
- HdrGenState hgs;
+ if (arguments)
+ {
+ HdrGenState hgs;
- argExpTypesToCBuffer(&buf, arguments, &hgs);
- }
+ argExpTypesToCBuffer(&buf, arguments, &hgs);
+ }
- if (m.last == MATCHnomatch)
- {
- tf = (TypeFunction *)type;
+ if (m.last == MATCHnomatch)
+ {
+ tf = (TypeFunction *)type;
- //printf("tf = %s, args = %s\n", tf->deco, ((Expression *)arguments->data[0])->type->deco);
- error(loc, "%s does not match parameter types (%s)",
- Parameter::argsTypesToChars(tf->parameters, tf->varargs),
- buf.toChars());
- return m.anyf; // as long as it's not a FuncAliasDeclaration
- }
- else
- {
+ //printf("tf = %s, args = %s\n", tf->deco, ((Expression *)arguments->data[0])->type->deco);
+ error(loc, "%s does not match parameter types (%s)",
+ Parameter::argsTypesToChars(tf->parameters, tf->varargs),
+ buf.toChars());
+ return m.anyf; // as long as it's not a FuncAliasDeclaration
+ }
+ else
+ {
#if 1
- TypeFunction *t1 = (TypeFunction *)m.lastf->type;
- TypeFunction *t2 = (TypeFunction *)m.nextf->type;
+ TypeFunction *t1 = (TypeFunction *)m.lastf->type;
+ TypeFunction *t2 = (TypeFunction *)m.nextf->type;
- error(loc, "called with argument types:\n\t(%s)\nmatches both:\n\t%s%s\nand:\n\t%s%s",
- buf.toChars(),
- m.lastf->toPrettyChars(), Parameter::argsTypesToChars(t1->parameters, t1->varargs),
- m.nextf->toPrettyChars(), Parameter::argsTypesToChars(t2->parameters, t2->varargs));
+ error(loc, "called with argument types:\n\t(%s)\nmatches both:\n\t%s%s\nand:\n\t%s%s",
+ buf.toChars(),
+ m.lastf->toPrettyChars(), Parameter::argsTypesToChars(t1->parameters, t1->varargs),
+ m.nextf->toPrettyChars(), Parameter::argsTypesToChars(t2->parameters, t2->varargs));
#else
- error(loc, "overloads %s and %s both match argument list for %s",
- m.lastf->type->toChars(),
- m.nextf->type->toChars(),
- m.lastf->toChars());
+ error(loc, "overloads %s and %s both match argument list for %s",
+ m.lastf->type->toChars(),
+ m.nextf->type->toChars(),
+ m.lastf->toChars());
#endif
- return m.lastf;
- }
+ return m.lastf;
+ }
}
}
@@ -2052,8 +2052,8 @@ if (arguments)
* Determine partial specialization order of 'this' vs g.
* This is very similar to TemplateDeclaration::leastAsSpecialized().
* Returns:
- * match 'this' is at least as specialized as g
- * 0 g is more specialized than 'this'
+ * match 'this' is at least as specialized as g
+ * 0 g is more specialized than 'this'
*/
#if DMDV2
@@ -2081,13 +2081,13 @@ MATCH FuncDeclaration::leastAsSpecialized(FuncDeclaration *g)
*/
if (needThis() && g->needThis())
{
- if (tf->mod != tg->mod)
- {
- if (tg->mod == MODconst)
- match = MATCHconst;
- else
- return MATCHnomatch;
- }
+ if (tf->mod != tg->mod)
+ {
+ if (tg->mod == MODconst)
+ match = MATCHconst;
+ else
+ return MATCHnomatch;
+ }
}
/* Create a dummy array of arguments out of the parameters to f()
@@ -2096,16 +2096,16 @@ MATCH FuncDeclaration::leastAsSpecialized(FuncDeclaration *g)
args.setDim(nfparams);
for (int u = 0; u < nfparams; u++)
{
- Parameter *p = Parameter::getNth(tf->parameters, u);
- Expression *e;
- if (p->storageClass & (STCref | STCout))
- {
- e = new IdentifierExp(0, p->ident);
- e->type = p->type;
- }
- else
- e = p->type->defaultInit();
- args.data[u] = e;
+ Parameter *p = Parameter::getNth(tf->parameters, u);
+ Expression *e;
+ if (p->storageClass & (STCref | STCout))
+ {
+ e = new IdentifierExp(0, p->ident);
+ e->type = p->type;
+ }
+ else
+ e = p->type->defaultInit();
+ args.data[u] = e;
}
MATCH m = (MATCH) tg->callMatch(NULL, &args);
@@ -2115,7 +2115,7 @@ MATCH FuncDeclaration::leastAsSpecialized(FuncDeclaration *g)
* non-variadic one.
*/
if (tf->varargs && !tg->varargs)
- goto L1; // less specialized
+ goto L1; // less specialized
#if LOG_LEASTAS
printf(" matches %d, so is least as specialized\n", m);
@@ -2132,29 +2132,29 @@ MATCH FuncDeclaration::leastAsSpecialized(FuncDeclaration *g)
/*******************************************
* Given a symbol that could be either a FuncDeclaration or
* a function template, resolve it to a function symbol.
- * sc instantiation scope
- * loc instantiation location
- * targsi initial list of template arguments
- * ethis if !NULL, the 'this' pointer argument
- * fargs arguments to function
- * flags 1: do not issue error message on no match, just return NULL
+ * sc instantiation scope
+ * loc instantiation location
+ * targsi initial list of template arguments
+ * ethis if !NULL, the 'this' pointer argument
+ * fargs arguments to function
+ * flags 1: do not issue error message on no match, just return NULL
*/
FuncDeclaration *resolveFuncCall(Scope *sc, Loc loc, Dsymbol *s,
- Objects *tiargs,
- Expression *ethis,
- Expressions *arguments,
- int flags)
+ Objects *tiargs,
+ Expression *ethis,
+ Expressions *arguments,
+ int flags)
{
if (!s)
- return NULL; // no match
+ return NULL; // no match
FuncDeclaration *f = s->isFuncDeclaration();
if (f)
- f = f->overloadResolve(loc, ethis, arguments);
+ f = f->overloadResolve(loc, ethis, arguments);
else
- { TemplateDeclaration *td = s->isTemplateDeclaration();
- assert(td);
- f = td->deduceFunctionTemplate(sc, loc, tiargs, NULL, arguments, flags);
+ { TemplateDeclaration *td = s->isTemplateDeclaration();
+ assert(td);
+ f = td->deduceFunctionTemplate(sc, loc, tiargs, NULL, arguments, flags);
}
return f;
}
@@ -2168,13 +2168,13 @@ LabelDsymbol *FuncDeclaration::searchLabel(Identifier *ident)
{ Dsymbol *s;
if (!labtab)
- labtab = new DsymbolTable(); // guess we need one
+ labtab = new DsymbolTable(); // guess we need one
s = labtab->lookup(ident);
if (!s)
{
- s = new LabelDsymbol(ident);
- labtab->insert(s);
+ s = new LabelDsymbol(ident);
+ labtab->insert(s);
}
return (LabelDsymbol *)s;
}
@@ -2192,7 +2192,7 @@ AggregateDeclaration *FuncDeclaration::isThis()
ad = NULL;
if ((storage_class & STCstatic) == 0)
{
- ad = isMember2();
+ ad = isMember2();
}
//printf("-FuncDeclaration::isThis() %p\n", ad);
return ad;
@@ -2206,15 +2206,15 @@ AggregateDeclaration *FuncDeclaration::isMember2()
for (Dsymbol *s = this; s; s = s->parent)
{
//printf("\ts = '%s', parent = '%s', kind = %s\n", s->toChars(), s->parent->toChars(), s->parent->kind());
- ad = s->isMember();
- if (ad)
+ ad = s->isMember();
+ if (ad)
{ //printf("test4\n");
- break;
+ break;
}
- if (!s->parent ||
- (!s->parent->isTemplateInstance()))
+ if (!s->parent ||
+ (!s->parent->isTemplateInstance()))
{ //printf("test5\n");
- break;
+ break;
}
}
//printf("-FuncDeclaration::isMember2() %p\n", ad);
@@ -2225,9 +2225,9 @@ AggregateDeclaration *FuncDeclaration::isMember2()
* Determine lexical level difference from 'this' to nested function 'fd'.
* Error if this cannot call fd.
* Returns:
- * 0 same level
- * -1 increase nesting by 1 (fd is nested within 'this')
- * >0 decrease nesting by number
+ * 0 same level
+ * -1 increase nesting by 1 (fd is nested within 'this')
+ * >0 decrease nesting by number
*/
int FuncDeclaration::getLevel(Loc loc, FuncDeclaration *fd)
@@ -2238,31 +2238,31 @@ int FuncDeclaration::getLevel(Loc loc, FuncDeclaration *fd)
//printf("FuncDeclaration::getLevel(fd = '%s')\n", fd->toChars());
fdparent = fd->toParent2();
if (fdparent == this)
- return -1;
+ return -1;
s = this;
level = 0;
while (fd != s && fdparent != s->toParent2())
{
- //printf("\ts = '%s'\n", s->toChars());
- FuncDeclaration *thisfd = s->isFuncDeclaration();
- if (thisfd)
- { if (!thisfd->isNested() && !thisfd->vthis)
- goto Lerr;
- }
- else
- {
- ClassDeclaration *thiscd = s->isClassDeclaration();
- if (thiscd)
- { if (!thiscd->isNested())
- goto Lerr;
- }
- else
- goto Lerr;
- }
+ //printf("\ts = '%s'\n", s->toChars());
+ FuncDeclaration *thisfd = s->isFuncDeclaration();
+ if (thisfd)
+ { if (!thisfd->isNested() && !thisfd->vthis)
+ goto Lerr;
+ }
+ else
+ {
+ ClassDeclaration *thiscd = s->isClassDeclaration();
+ if (thiscd)
+ { if (!thiscd->isNested())
+ goto Lerr;
+ }
+ else
+ goto Lerr;
+ }
- s = s->toParent2();
- assert(s);
- level++;
+ s = s->toParent2();
+ assert(s);
+ level++;
}
return level;
@@ -2281,10 +2281,10 @@ void FuncDeclaration::appendExp(Expression *e)
void FuncDeclaration::appendState(Statement *s)
{
if (!fbody)
- { Statements *a;
+ { Statements *a;
- a = new Statements();
- fbody = new CompoundStatement(0, a);
+ a = new Statements();
+ fbody = new CompoundStatement(0, a);
}
CompoundStatement *cs = fbody->isCompoundStatement();
cs->statements->push(s);
@@ -2293,15 +2293,15 @@ void FuncDeclaration::appendState(Statement *s)
const char *FuncDeclaration::toPrettyChars()
{
if (isMain())
- return "D main";
+ return "D main";
else
- return Dsymbol::toPrettyChars();
+ return Dsymbol::toPrettyChars();
}
int FuncDeclaration::isMain()
{
return ident == Id::main &&
- linkage != LINKc && !isMember() && !isNested();
+ linkage != LINKc && !isMember() && !isNested();
}
int FuncDeclaration::isWinMain()
@@ -2309,19 +2309,19 @@ int FuncDeclaration::isWinMain()
//printf("FuncDeclaration::isWinMain() %s\n", toChars());
#if 0
int x = ident == Id::WinMain &&
- linkage != LINKc && !isMember();
+ linkage != LINKc && !isMember();
printf("%s\n", x ? "yes" : "no");
return x;
#else
return ident == Id::WinMain &&
- linkage != LINKc && !isMember();
+ linkage != LINKc && !isMember();
#endif
}
int FuncDeclaration::isDllMain()
{
return ident == Id::DllMain &&
- linkage != LINKc && !isMember();
+ linkage != LINKc && !isMember();
}
int FuncDeclaration::isExport()
@@ -2344,13 +2344,13 @@ int FuncDeclaration::isVirtual()
printf("FuncDeclaration::isVirtual(%s)\n", toChars());
printf("isMember:%p isStatic:%d private:%d ctor:%d !Dlinkage:%d\n", isMember(), isStatic(), protection == PROTprivate, isCtorDeclaration(), linkage != LINKd);
printf("result is %d\n",
- isMember() &&
- !(isStatic() || protection == PROTprivate || protection == PROTpackage) &&
- toParent()->isClassDeclaration());
+ isMember() &&
+ !(isStatic() || protection == PROTprivate || protection == PROTpackage) &&
+ toParent()->isClassDeclaration());
#endif
return isMember() &&
- !(isStatic() || protection == PROTprivate || protection == PROTpackage) &&
- toParent()->isClassDeclaration();
+ !(isStatic() || protection == PROTprivate || protection == PROTpackage) &&
+ toParent()->isClassDeclaration();
}
int FuncDeclaration::isFinal()
@@ -2360,14 +2360,14 @@ int FuncDeclaration::isFinal()
printf("FuncDeclaration::isFinal(%s)\n", toChars());
printf("%p %d %d %d %d\n", isMember(), isStatic(), protection == PROTprivate, isCtorDeclaration(), linkage != LINKd);
printf("result is %d\n",
- isMember() &&
- !(isStatic() || protection == PROTprivate || protection == PROTpackage) &&
- (cd = toParent()->isClassDeclaration()) != NULL &&
- cd->storage_class & STCfinal);
+ isMember() &&
+ !(isStatic() || protection == PROTprivate || protection == PROTpackage) &&
+ (cd = toParent()->isClassDeclaration()) != NULL &&
+ cd->storage_class & STCfinal);
#endif
return isMember() &&
- (Declaration::isFinal() ||
- ((cd = toParent()->isClassDeclaration()) != NULL && cd->storage_class & STCfinal));
+ (Declaration::isFinal() ||
+ ((cd = toParent()->isClassDeclaration()) != NULL && cd->storage_class & STCfinal));
}
int FuncDeclaration::isAbstract()
@@ -2377,7 +2377,7 @@ int FuncDeclaration::isAbstract()
int FuncDeclaration::isCodeseg()
{
- return TRUE; // functions are always in the code segment
+ return TRUE; // functions are always in the code segment
}
// Determine if function needs
@@ -2386,10 +2386,10 @@ int FuncDeclaration::isCodeseg()
int FuncDeclaration::isNested()
{
//if (!toParent())
- //printf("FuncDeclaration::isNested('%s') parent=%p\n", toChars(), parent);
+ //printf("FuncDeclaration::isNested('%s') parent=%p\n", toChars(), parent);
//printf("\ttoParent2() = '%s'\n", toParent2()->toChars());
return ((storage_class & STCstatic) == 0) && toParent2() &&
- (toParent2()->isFuncDeclaration() != NULL);
+ (toParent2()->isFuncDeclaration() != NULL);
}
int FuncDeclaration::needThis()
@@ -2398,7 +2398,7 @@ int FuncDeclaration::needThis()
int i = isThis() != NULL;
//printf("\t%d\n", i);
if (!i && isFuncAliasDeclaration())
- i = ((FuncAliasDeclaration *)this)->funcalias->needThis();
+ i = ((FuncAliasDeclaration *)this)->funcalias->needThis();
return i;
}
@@ -2406,21 +2406,21 @@ int FuncDeclaration::addPreInvariant()
{
AggregateDeclaration *ad = isThis();
return (ad &&
- //ad->isClassDeclaration() &&
- global.params.useInvariants &&
- (protection == PROTpublic || protection == PROTexport) &&
- !naked);
+ //ad->isClassDeclaration() &&
+ global.params.useInvariants &&
+ (protection == PROTpublic || protection == PROTexport) &&
+ !naked);
}
int FuncDeclaration::addPostInvariant()
{
AggregateDeclaration *ad = isThis();
return (ad &&
- ad->inv &&
- //ad->isClassDeclaration() &&
- global.params.useInvariants &&
- (protection == PROTpublic || protection == PROTexport) &&
- !naked);
+ ad->inv &&
+ //ad->isClassDeclaration() &&
+ global.params.useInvariants &&
+ (protection == PROTpublic || protection == PROTexport) &&
+ !naked);
}
/**********************************
@@ -2448,22 +2448,22 @@ FuncDeclaration *FuncDeclaration::genCfunc(Parameters *args, Type *treturn, Iden
// See if already in table
if (!st)
- st = new DsymbolTable();
+ st = new DsymbolTable();
s = st->lookup(id);
if (s)
{
- fd = s->isFuncDeclaration();
- assert(fd);
- assert(fd->type->nextOf()->equals(treturn));
+ fd = s->isFuncDeclaration();
+ assert(fd);
+ assert(fd->type->nextOf()->equals(treturn));
}
else
{
- tf = new TypeFunction(args, treturn, 0, LINKc);
- fd = new FuncDeclaration(0, 0, id, STCstatic, tf);
- fd->protection = PROTpublic;
- fd->linkage = LINKc;
+ tf = new TypeFunction(args, treturn, 0, LINKc);
+ fd = new FuncDeclaration(0, 0, id, STCstatic, tf);
+ fd->protection = PROTpublic;
+ fd->linkage = LINKc;
- st->insert(fd);
+ st->insert(fd);
}
return fd;
}
@@ -2498,26 +2498,26 @@ int FuncDeclaration::needsClosure()
//printf("FuncDeclaration::needsClosure() %s\n", toChars());
for (int i = 0; i < closureVars.dim; i++)
- { VarDeclaration *v = (VarDeclaration *)closureVars.data[i];
- assert(v->isVarDeclaration());
- //printf("\tv = %s\n", v->toChars());
+ { VarDeclaration *v = (VarDeclaration *)closureVars.data[i];
+ assert(v->isVarDeclaration());
+ //printf("\tv = %s\n", v->toChars());
- for (int j = 0; j < v->nestedrefs.dim; j++)
- { FuncDeclaration *f = (FuncDeclaration *)v->nestedrefs.data[j];
- assert(f != this);
+ for (int j = 0; j < v->nestedrefs.dim; j++)
+ { FuncDeclaration *f = (FuncDeclaration *)v->nestedrefs.data[j];
+ assert(f != this);
- //printf("\t\tf = %s, %d, %d\n", f->toChars(), f->isVirtual(), f->tookAddressOf);
- if (f->isThis() || f->tookAddressOf)
- goto Lyes; // assume f escapes this function's scope
+ //printf("\t\tf = %s, %d, %d\n", f->toChars(), f->isVirtual(), f->tookAddressOf);
+ if (f->isThis() || f->tookAddressOf)
+ goto Lyes; // assume f escapes this function's scope
- // Look to see if any parents of f that are below this escape
- for (Dsymbol *s = f->parent; s && s != this; s = s->parent)
- {
- f = s->isFuncDeclaration();
- if (f && (f->isThis() || f->tookAddressOf))
- goto Lyes;
- }
- }
+ // Look to see if any parents of f that are below this escape
+ for (Dsymbol *s = f->parent; s && s != this; s = s->parent)
+ {
+ f = s->isFuncDeclaration();
+ if (f && (f->isThis() || f->tookAddressOf))
+ goto Lyes;
+ }
+ }
}
return 0;
@@ -2538,19 +2538,19 @@ Parameters *FuncDeclaration::getParameters(int *pvarargs)
if (type)
{
- assert(type->ty == Tfunction);
- TypeFunction *fdtype = (TypeFunction *)type;
- fparameters = fdtype->parameters;
- fvarargs = fdtype->varargs;
+ assert(type->ty == Tfunction);
+ TypeFunction *fdtype = (TypeFunction *)type;
+ fparameters = fdtype->parameters;
+ fvarargs = fdtype->varargs;
}
else // Constructors don't have type's
{ CtorDeclaration *fctor = isCtorDeclaration();
- assert(fctor);
- fparameters = fctor->arguments;
- fvarargs = fctor->varargs;
+ assert(fctor);
+ fparameters = fctor->arguments;
+ fvarargs = fctor->varargs;
}
if (pvarargs)
- *pvarargs = fvarargs;
+ *pvarargs = fvarargs;
return fparameters;
}
@@ -2561,7 +2561,7 @@ Parameters *FuncDeclaration::getParameters(int *pvarargs)
FuncAliasDeclaration::FuncAliasDeclaration(FuncDeclaration *funcalias)
: FuncDeclaration(funcalias->loc, funcalias->endloc, funcalias->ident,
- (enum STC)funcalias->storage_class, funcalias->type)
+ (enum STC)funcalias->storage_class, funcalias->type)
{
assert(funcalias != this);
this->funcalias = funcalias;
@@ -2577,17 +2577,17 @@ const char *FuncAliasDeclaration::kind()
/****************************** FuncLiteralDeclaration ************************/
FuncLiteralDeclaration::FuncLiteralDeclaration(Loc loc, Loc endloc, Type *type,
- enum TOK tok, ForeachStatement *fes)
+ enum TOK tok, ForeachStatement *fes)
: FuncDeclaration(loc, endloc, NULL, STCundefined, type)
{
const char *id;
if (fes)
- id = "__foreachbody";
+ id = "__foreachbody";
else if (tok == TOKdelegate)
- id = "__dgliteral";
+ id = "__dgliteral";
else
- id = "__funcliteral";
+ id = "__funcliteral";
this->ident = Lexer::uniqueId(id);
this->tok = tok;
this->fes = fes;
@@ -2600,10 +2600,10 @@ Dsymbol *FuncLiteralDeclaration::syntaxCopy(Dsymbol *s)
//printf("FuncLiteralDeclaration::syntaxCopy('%s')\n", toChars());
if (s)
- f = (FuncLiteralDeclaration *)s;
+ f = (FuncLiteralDeclaration *)s;
else
- { f = new FuncLiteralDeclaration(loc, endloc, type->syntaxCopy(), tok, fes);
- f->ident = ident; // keep old identifier
+ { f = new FuncLiteralDeclaration(loc, endloc, type->syntaxCopy(), tok, fes);
+ f->ident = ident; // keep old identifier
}
FuncDeclaration::syntaxCopy(f);
return f;
@@ -2666,7 +2666,7 @@ void CtorDeclaration::semantic(Scope *sc)
{
//printf("CtorDeclaration::semantic() %s\n", toChars());
sc = sc->push();
- sc->stc &= ~STCstatic; // not a static constructor
+ sc->stc &= ~STCstatic; // not a static constructor
parent = sc->parent;
Dsymbol *parent = toParent();
@@ -2674,33 +2674,33 @@ void CtorDeclaration::semantic(Scope *sc)
ClassDeclaration *cd = parent->isClassDeclaration();
if (!cd)
{
- error("constructors are only for class definitions");
- fatal();
- tret = Type::tvoid;
+ error("constructors are only for class definitions");
+ fatal();
+ tret = Type::tvoid;
}
else
- tret = cd->type; //->referenceTo();
+ tret = cd->type; //->referenceTo();
if (!type)
- type = new TypeFunction(arguments, tret, varargs, LINKd);
+ type = new TypeFunction(arguments, tret, varargs, LINKd);
#if STRUCTTHISREF
if (ad && ad->isStructDeclaration())
- ((TypeFunction *)type)->isref = 1;
+ ((TypeFunction *)type)->isref = 1;
#endif
if (!originalType)
- originalType = type;
+ originalType = type;
sc->flags |= SCOPEctor;
type = type->semantic(loc, sc);
sc->flags &= ~SCOPEctor;
// Append:
- // return this;
+ // return this;
// to the function body
if (fbody && semanticRun < PASSsemantic)
{
- Expression *e = new ThisExp(loc);
- Statement *s = new ReturnStatement(loc, e);
- fbody = new CompoundStatement(loc, fbody, s);
+ Expression *e = new ThisExp(loc);
+ Statement *s = new ReturnStatement(loc, e);
+ fbody = new CompoundStatement(loc, fbody, s);
}
FuncDeclaration::semantic(sc);
@@ -2709,7 +2709,7 @@ void CtorDeclaration::semantic(Scope *sc)
// See if it's the default constructor
if (cd && varargs == 0 && Parameter::dim(arguments) == 0)
- cd->defaultCtor = this;
+ cd->defaultCtor = this;
}
const char *CtorDeclaration::kind()
@@ -2776,16 +2776,16 @@ void PostBlitDeclaration::semantic(Scope *sc)
StructDeclaration *ad = parent->isStructDeclaration();
if (!ad)
{
- error("post blits are only for struct/union definitions, not %s %s", parent->kind(), parent->toChars());
+ error("post blits are only for struct/union definitions, not %s %s", parent->kind(), parent->toChars());
}
else if (ident == Id::_postblit && semanticRun < PASSsemantic)
- ad->postblits.push(this);
+ ad->postblits.push(this);
if (!type)
- type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
+ type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
sc = sc->push();
- sc->stc &= ~STCstatic; // not static
+ sc->stc &= ~STCstatic; // not static
sc->linkage = LINKd;
FuncDeclaration::semantic(sc);
@@ -2795,7 +2795,7 @@ void PostBlitDeclaration::semantic(Scope *sc)
int PostBlitDeclaration::overloadInsert(Dsymbol *s)
{
- return FALSE; // cannot overload postblits
+ return FALSE; // cannot overload postblits
}
int PostBlitDeclaration::addPreInvariant()
@@ -2849,17 +2849,17 @@ void DtorDeclaration::semantic(Scope *sc)
ClassDeclaration *cd = parent->isClassDeclaration();
if (!cd)
{
- error("destructors are only for class/struct/union definitions, not %s %s", parent->kind(), parent->toChars());
- fatal();
+ error("destructors are only for class/struct/union definitions, not %s %s", parent->kind(), parent->toChars());
+ fatal();
}
else if (semanticRun < PASSsemantic)
- cd->dtors.push(this);
+ cd->dtors.push(this);
if (!type)
- type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
+ type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
sc = sc->push();
- sc->stc &= ~STCstatic; // not a static destructor
+ sc->stc &= ~STCstatic; // not a static destructor
sc->linkage = LINKd;
FuncDeclaration::semantic(sc);
@@ -2869,7 +2869,7 @@ void DtorDeclaration::semantic(Scope *sc)
int DtorDeclaration::overloadInsert(Dsymbol *s)
{
- return FALSE; // cannot overload destructors
+ return FALSE; // cannot overload destructors
}
int DtorDeclaration::addPreInvariant()
@@ -2883,7 +2883,7 @@ int DtorDeclaration::addPostInvariant()
}
const char *DtorDeclaration::kind()
-{
+{
return "destructor";
}
@@ -2907,7 +2907,7 @@ int DtorDeclaration::isVirtual()
void DtorDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (hgs->hdrgen)
- return;
+ return;
buf->writestring("~this()");
bodyToCBuffer(buf, hgs);
}
@@ -2933,7 +2933,7 @@ void StaticCtorDeclaration::semantic(Scope *sc)
//printf("StaticCtorDeclaration::semantic()\n");
if (!type)
- type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
+ type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
/* If the static ctor appears within a template instantiation,
* it could get called multiple times by the module constructors
@@ -2941,26 +2941,26 @@ void StaticCtorDeclaration::semantic(Scope *sc)
*/
if (inTemplateInstance() && semanticRun < PASSsemantic)
{
- /* Add this prefix to the function:
- * static int gate;
- * if (++gate != 1) return;
- * Note that this is not thread safe; should not have threads
- * during static construction.
- */
- Identifier *id = Lexer::idPool("__gate");
- VarDeclaration *v = new VarDeclaration(0, Type::tint32, id, NULL);
- v->storage_class = STCstatic;
- Statements *sa = new Statements();
- Statement *s = new DeclarationStatement(0, v);
- sa->push(s);
- Expression *e = new IdentifierExp(0, id);
- e = new AddAssignExp(0, e, new IntegerExp(1));
- e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(1));
- s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL);
- sa->push(s);
- if (fbody)
- sa->push(fbody);
- fbody = new CompoundStatement(0, sa);
+ /* Add this prefix to the function:
+ * static int gate;
+ * if (++gate != 1) return;
+ * Note that this is not thread safe; should not have threads
+ * during static construction.
+ */
+ Identifier *id = Lexer::idPool("__gate");
+ VarDeclaration *v = new VarDeclaration(0, Type::tint32, id, NULL);
+ v->storage_class = STCstatic;
+ Statements *sa = new Statements();
+ Statement *s = new DeclarationStatement(0, v);
+ sa->push(s);
+ Expression *e = new IdentifierExp(0, id);
+ e = new AddAssignExp(0, e, new IntegerExp(1));
+ e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(1));
+ s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL);
+ sa->push(s);
+ if (fbody)
+ sa->push(fbody);
+ fbody = new CompoundStatement(0, sa);
}
FuncDeclaration::semantic(sc);
@@ -2968,12 +2968,12 @@ void StaticCtorDeclaration::semantic(Scope *sc)
// We're going to need ModuleInfo
Module *m = getModule();
if (!m)
- m = sc->module;
+ m = sc->module;
if (m)
- { m->needmoduleinfo = 1;
- //printf("module1 %s needs moduleinfo\n", m->toChars());
+ { m->needmoduleinfo = 1;
+ //printf("module1 %s needs moduleinfo\n", m->toChars());
#ifdef IN_GCC
- m->strictlyneedmoduleinfo = 1;
+ m->strictlyneedmoduleinfo = 1;
#endif
}
}
@@ -3006,8 +3006,8 @@ int StaticCtorDeclaration::addPostInvariant()
void StaticCtorDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (hgs->hdrgen)
- { buf->writestring("static this();\n");
- return;
+ { buf->writestring("static this();\n");
+ return;
}
buf->writestring("static this()");
bodyToCBuffer(buf, hgs);
@@ -3037,7 +3037,7 @@ void StaticDtorDeclaration::semantic(Scope *sc)
ClassDeclaration *cd = sc->scopesym->isClassDeclaration();
if (!type)
- type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
+ type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
/* If the static ctor appears within a template instantiation,
* it could get called multiple times by the module constructors
@@ -3045,28 +3045,28 @@ void StaticDtorDeclaration::semantic(Scope *sc)
*/
if (inTemplateInstance() && semanticRun < PASSsemantic)
{
- /* Add this prefix to the function:
- * static int gate;
- * if (--gate != 0) return;
- * Increment gate during constructor execution.
- * Note that this is not thread safe; should not have threads
- * during static destruction.
- */
- Identifier *id = Lexer::idPool("__gate");
- VarDeclaration *v = new VarDeclaration(0, Type::tint32, id, NULL);
- v->storage_class = STCstatic;
- Statements *sa = new Statements();
- Statement *s = new DeclarationStatement(0, v);
- sa->push(s);
- Expression *e = new IdentifierExp(0, id);
- e = new AddAssignExp(0, e, new IntegerExp((uint64_t)-1));
- e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(0));
- s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL);
- sa->push(s);
- if (fbody)
- sa->push(fbody);
- fbody = new CompoundStatement(0, sa);
- vgate = v;
+ /* Add this prefix to the function:
+ * static int gate;
+ * if (--gate != 0) return;
+ * Increment gate during constructor execution.
+ * Note that this is not thread safe; should not have threads
+ * during static destruction.
+ */
+ Identifier *id = Lexer::idPool("__gate");
+ VarDeclaration *v = new VarDeclaration(0, Type::tint32, id, NULL);
+ v->storage_class = STCstatic;
+ Statements *sa = new Statements();
+ Statement *s = new DeclarationStatement(0, v);
+ sa->push(s);
+ Expression *e = new IdentifierExp(0, id);
+ e = new AddAssignExp(0, e, new IntegerExp((uint64_t)-1));
+ e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(0));
+ s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL);
+ sa->push(s);
+ if (fbody)
+ sa->push(fbody);
+ fbody = new CompoundStatement(0, sa);
+ vgate = v;
}
FuncDeclaration::semantic(sc);
@@ -3074,12 +3074,12 @@ void StaticDtorDeclaration::semantic(Scope *sc)
// We're going to need ModuleInfo
Module *m = getModule();
if (!m)
- m = sc->module;
+ m = sc->module;
if (m)
- { m->needmoduleinfo = 1;
- //printf("module2 %s needs moduleinfo\n", m->toChars());
+ { m->needmoduleinfo = 1;
+ //printf("module2 %s needs moduleinfo\n", m->toChars());
#ifdef IN_GCC
- m->strictlyneedmoduleinfo = 1;
+ m->strictlyneedmoduleinfo = 1;
#endif
}
}
@@ -3112,7 +3112,7 @@ int StaticDtorDeclaration::addPostInvariant()
void StaticDtorDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (hgs->hdrgen)
- return;
+ return;
buf->writestring("static ~this()");
bodyToCBuffer(buf, hgs);
}
@@ -3142,19 +3142,19 @@ void InvariantDeclaration::semantic(Scope *sc)
AggregateDeclaration *ad = parent->isAggregateDeclaration();
if (!ad)
{
- error("invariants are only for struct/union/class definitions");
- return;
+ error("invariants are only for struct/union/class definitions");
+ return;
}
else if (ad->inv && ad->inv != this && semanticRun < PASSsemantic)
{
- error("more than one invariant for %s", ad->toChars());
+ error("more than one invariant for %s", ad->toChars());
}
ad->inv = this;
if (!type)
- type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
+ type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
sc = sc->push();
- sc->stc &= ~STCstatic; // not a static invariant
+ sc->stc &= ~STCstatic; // not a static invariant
sc->incontract++;
sc->linkage = LINKd;
@@ -3181,7 +3181,7 @@ int InvariantDeclaration::addPostInvariant()
void InvariantDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (hgs->hdrgen)
- return;
+ return;
buf->writestring("invariant");
bodyToCBuffer(buf, hgs);
}
@@ -3218,12 +3218,12 @@ void UnitTestDeclaration::semantic(Scope *sc)
{
if (global.params.useUnitTests)
{
- if (!type)
- type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
- Scope *sc2 = sc->push();
- sc2->linkage = LINKd;
- FuncDeclaration::semantic(sc2);
- sc2->pop();
+ if (!type)
+ type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
+ Scope *sc2 = sc->push();
+ sc2->linkage = LINKd;
+ FuncDeclaration::semantic(sc2);
+ sc2->pop();
}
#if 0
@@ -3233,11 +3233,11 @@ void UnitTestDeclaration::semantic(Scope *sc)
// (This doesn't make sense to me?)
Module *m = getModule();
if (!m)
- m = sc->module;
+ m = sc->module;
if (m)
{
- //printf("module3 %s needs moduleinfo\n", m->toChars());
- m->needmoduleinfo = 1;
+ //printf("module3 %s needs moduleinfo\n", m->toChars());
+ m->needmoduleinfo = 1;
}
#endif
}
@@ -3265,7 +3265,7 @@ int UnitTestDeclaration::addPostInvariant()
void UnitTestDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (hgs->hdrgen)
- return;
+ return;
buf->writestring("unittest");
bodyToCBuffer(buf, hgs);
}
@@ -3302,11 +3302,11 @@ void NewDeclaration::semantic(Scope *sc)
ClassDeclaration *cd = parent->isClassDeclaration();
if (!cd && !parent->isStructDeclaration())
{
- error("new allocators only are for class or struct definitions");
+ error("new allocators only are for class or struct definitions");
}
Type *tret = Type::tvoid->pointerTo();
if (!type)
- type = new TypeFunction(arguments, tret, varargs, LINKd);
+ type = new TypeFunction(arguments, tret, varargs, LINKd);
type = type->semantic(loc, sc);
assert(type->ty == Tfunction);
@@ -3315,13 +3315,13 @@ void NewDeclaration::semantic(Scope *sc)
TypeFunction *tf = (TypeFunction *)type;
if (Parameter::dim(tf->parameters) < 1)
{
- error("at least one argument of type size_t expected");
+ error("at least one argument of type size_t expected");
}
else
{
- Parameter *a = Parameter::getNth(tf->parameters, 0);
- if (!a->type->equals(Type::tsize_t))
- error("first argument must be type size_t, not %s", a->type->toChars());
+ Parameter *a = Parameter::getNth(tf->parameters, 0);
+ if (!a->type->equals(Type::tsize_t))
+ error("first argument must be type size_t, not %s", a->type->toChars());
}
FuncDeclaration::semantic(sc);
@@ -3386,10 +3386,10 @@ void DeleteDeclaration::semantic(Scope *sc)
ClassDeclaration *cd = parent->isClassDeclaration();
if (!cd && !parent->isStructDeclaration())
{
- error("new allocators only are for class or struct definitions");
+ error("new allocators only are for class or struct definitions");
}
if (!type)
- type = new TypeFunction(arguments, Type::tvoid, 0, LINKd);
+ type = new TypeFunction(arguments, Type::tvoid, 0, LINKd);
type = type->semantic(loc, sc);
assert(type->ty == Tfunction);
@@ -3398,13 +3398,13 @@ void DeleteDeclaration::semantic(Scope *sc)
TypeFunction *tf = (TypeFunction *)type;
if (Parameter::dim(tf->parameters) != 1)
{
- error("one argument of type void* expected");
+ error("one argument of type void* expected");
}
else
{
- Parameter *a = Parameter::getNth(tf->parameters, 0);
- if (!a->type->equals(Type::tvoid->pointerTo()))
- error("one argument of type void* expected, not %s", a->type->toChars());
+ Parameter *a = Parameter::getNth(tf->parameters, 0);
+ if (!a->type->equals(Type::tvoid->pointerTo()))
+ error("one argument of type void* expected, not %s", a->type->toChars());
}
FuncDeclaration::semantic(sc);
diff --git a/dmd/hdrgen.c b/dmd/hdrgen.c
index b7a14fb6..392ab439 100644
--- a/dmd/hdrgen.c
+++ b/dmd/hdrgen.c
@@ -13,7 +13,7 @@
#ifdef _DH
#define PRETTY_PRINT
-#define TEST_EMIT_ALL 0 // For Testing
+#define TEST_EMIT_ALL 0 // For Testing
#define LOG 0
@@ -69,7 +69,7 @@ void Module::genhdrfile()
char *pt = FileName::path(hdrfile->toChars());
if (*pt)
- FileName::ensurePathExists(pt);
+ FileName::ensurePathExists(pt);
mem.free(pt);
hdrfile->writev();
}
@@ -80,7 +80,7 @@ void Module::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
if (md)
{
buf->writestring("module ");
- buf->writestring(md->toChars());
+ buf->writestring(md->toChars());
buf->writebyte(';');
buf->writenl();
}
diff --git a/dmd/hdrgen.h b/dmd/hdrgen.h
index d4a21861..6e007ed7 100644
--- a/dmd/hdrgen.h
+++ b/dmd/hdrgen.h
@@ -11,9 +11,9 @@
struct HdrGenState
{
- int hdrgen; // 1 if generating header file
- int ddoc; // 1 if generating Ddoc file
- int console; // 1 if writing to console
+ int hdrgen; // 1 if generating header file
+ int ddoc; // 1 if generating Ddoc file
+ int console; // 1 if writing to console
int tpltMember;
int inCallExp;
int inPtrExp;
diff --git a/dmd/html.c b/dmd/html.c
index 59e19f77..ee708cdd 100644
--- a/dmd/html.c
+++ b/dmd/html.c
@@ -66,15 +66,15 @@ void Html::error(const char *format, ...)
{
if (!global.gag)
{
- printf("%s(%d) : HTML Error: ", sourcename, linnum);
+ printf("%s(%d) : HTML Error: ", sourcename, linnum);
- va_list ap;
- va_start(ap, format);
- vprintf(format, ap);
- va_end(ap);
+ va_list ap;
+ va_start(ap, format);
+ vprintf(format, ap);
+ va_end(ap);
- printf("\n");
- fflush(stdout);
+ printf("\n");
+ fflush(stdout);
}
global.errors++;
@@ -88,74 +88,74 @@ void Html::error(const char *format, ...)
void Html::extractCode(OutBuffer *buf)
{
//printf("Html::extractCode()\n");
- dbuf = buf; // save for other routines
+ dbuf = buf; // save for other routines
buf->reserve(end - p);
inCode = 0;
while (1)
{
- //printf("p = %p, *p = x%x\n", p, *p);
- switch (*p)
- {
+ //printf("p = %p, *p = x%x\n", p, *p);
+ switch (*p)
+ {
#if 0 // strings are not recognized outside of tags
- case '"':
- case '\'':
- skipString();
- continue;
+ case '"':
+ case '\'':
+ skipString();
+ continue;
#endif
- case '<':
- if (p[1] == '!' && isCommentStart())
- { // Comments start with
- p++;
- break;
- }
- continue;
+ case '>':
+ if (scangt)
+ { // found -->
+ p++;
+ break;
+ }
+ continue;
- case ' ':
- case '\t':
- case '\f':
- case '\v':
- // skip white space
- continue;
+ case ' ':
+ case '\t':
+ case '\f':
+ case '\v':
+ // skip white space
+ continue;
- case '\r':
- if (p[1] == '\n')
- goto Ldefault;
- case '\n':
- linnum++; // remember to count lines
- // Always extract new lines, so that D lexer counts the
- // lines right.
- dbuf->writeByte(*p);
- continue;
+ case '\r':
+ if (p[1] == '\n')
+ goto Ldefault;
+ case '\n':
+ linnum++; // remember to count lines
+ // Always extract new lines, so that D lexer counts the
+ // lines right.
+ dbuf->writeByte(*p);
+ continue;
- case 0:
- case 0x1a:
- error("end of file before closing --> of comment");
- break;
+ case 0:
+ case 0x1a:
+ error("end of file before closing --> of comment");
+ break;
- default:
- Ldefault:
- scangt = 0; // it's not -->
- continue;
- }
- break;
+ default:
+ Ldefault:
+ scangt = 0; // it's not -->
+ continue;
+ }
+ break;
}
//printf("*p = '%c'\n", *p);
}
@@ -448,59 +448,59 @@ void Html::scanComment()
/********************************************
* Determine if we are at the start of a comment.
* Input:
- * p is on the opening '<'
+ * p is on the opening '<'
* Returns:
- * 0 if not start of a comment
- * 1 if start of a comment, p is adjusted to point past --
+ * 0 if not start of a comment
+ * 1 if start of a comment, p is adjusted to point past --
*/
int Html::isCommentStart()
#ifdef __DMC__
__out(result)
{
- if (result == 0)
- ;
- else if (result == 1)
- {
- assert(p[-2] == '-' && p[-1] == '-');
- }
- else
- assert(0);
+ if (result == 0)
+ ;
+ else if (result == 1)
+ {
+ assert(p[-2] == '-' && p[-1] == '-');
+ }
+ else
+ assert(0);
}
__body
#endif /* __DMC__ */
- { unsigned char *s;
+ { unsigned char *s;
- if (p[0] == '<' && p[1] == '!')
- {
- for (s = p + 2; 1; s++)
- {
- switch (*s)
- {
- case ' ':
- case '\t':
- case '\r':
- case '\f':
- case '\v':
- // skip white space, even though spec says no
- // white space is allowed
- continue;
+ if (p[0] == '<' && p[1] == '!')
+ {
+ for (s = p + 2; 1; s++)
+ {
+ switch (*s)
+ {
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\f':
+ case '\v':
+ // skip white space, even though spec says no
+ // white space is allowed
+ continue;
- case '-':
- if (s[1] == '-')
- {
- p = s + 2;
- return 1;
- }
- goto No;
+ case '-':
+ if (s[1] == '-')
+ {
+ p = s + 2;
+ return 1;
+ }
+ goto No;
- default:
- goto No;
- }
- }
- }
+ default:
+ goto No;
+ }
+ }
+ }
No:
- return 0;
+ return 0;
}
int Html::isCDATAStart()
@@ -510,12 +510,12 @@ int Html::isCDATAStart()
if (strncmp((char*)p, CDATA_START_MARKER, len) == 0)
{
- p += len;
- return 1;
+ p += len;
+ return 1;
}
else
{
- return 0;
+ return 0;
}
}
@@ -523,41 +523,41 @@ void Html::scanCDATA()
{
while(*p && *p != 0x1A)
{
- int lineSepLength = isLineSeparator(p);
- if (lineSepLength>0)
- {
- /* Always extract new lines, so that D lexer counts the lines
- * right.
- */
- linnum++;
- dbuf->writeUTF8('\n');
- p += lineSepLength;
- continue;
+ int lineSepLength = isLineSeparator(p);
+ if (lineSepLength>0)
+ {
+ /* Always extract new lines, so that D lexer counts the lines
+ * right.
+ */
+ linnum++;
+ dbuf->writeUTF8('\n');
+ p += lineSepLength;
+ continue;
+ }
+ else if (p[0] == ']' && p[1] == ']' && p[2] == '>')
+ {
+ /* end of CDATA section */
+ p += 3;
+ return;
+ }
+ else if (inCode)
+ {
+ /* this CDATA section contains D code */
+ dbuf->writeByte(*p);
}
- else if (p[0] == ']' && p[1] == ']' && p[2] == '>')
- {
- /* end of CDATA section */
- p += 3;
- return;
- }
- else if (inCode)
- {
- /* this CDATA section contains D code */
- dbuf->writeByte(*p);
- }
- p++;
+ p++;
}
}
/********************************************
* Convert an HTML character entity into a character.
* Forms are:
- * &name; named entity
- * ddd; decimal
- * hhhh; hex
+ * &name; named entity
+ * ddd; decimal
+ * hhhh; hex
* Input:
- * p is on the &
+ * p is on the &
*/
int Html::charEntity()
@@ -569,117 +569,117 @@ int Html::charEntity()
//printf("Html::charEntity('%c')\n", *p);
if (p[1] == '#')
{
- p++;
- if (p[1] == 'x' || p[1] == 'X')
- { p++;
- hex = 1;
- }
- else
- hex = 0;
- if (p[1] == ';')
- goto Linvalid;
- while (1)
- {
- p++;
- switch (*p)
- {
- case 0:
- case 0x1a:
- error("end of file before end of character entity");
- goto Lignore;
+ p++;
+ if (p[1] == 'x' || p[1] == 'X')
+ { p++;
+ hex = 1;
+ }
+ else
+ hex = 0;
+ if (p[1] == ';')
+ goto Linvalid;
+ while (1)
+ {
+ p++;
+ switch (*p)
+ {
+ case 0:
+ case 0x1a:
+ error("end of file before end of character entity");
+ goto Lignore;
- case '\n':
- case '\r':
- case '<': // tag start
- // Termination is assumed
- break;
+ case '\n':
+ case '\r':
+ case '<': // tag start
+ // Termination is assumed
+ break;
- case ';':
- // Termination is explicit
- p++;
- break;
+ case ';':
+ // Termination is explicit
+ p++;
+ break;
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- v = *p - '0';
- goto Lvalue;
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ v = *p - '0';
+ goto Lvalue;
- case 'a': case 'b': case 'c':
- case 'd': case 'e': case 'f':
- if (!hex)
- goto Linvalid;
- v = (*p - 'a') + 10;
- goto Lvalue;
+ case 'a': case 'b': case 'c':
+ case 'd': case 'e': case 'f':
+ if (!hex)
+ goto Linvalid;
+ v = (*p - 'a') + 10;
+ goto Lvalue;
- case 'A': case 'B': case 'C':
- case 'D': case 'E': case 'F':
- if (!hex)
- goto Linvalid;
- v = (*p - 'A') + 10;
- goto Lvalue;
+ case 'A': case 'B': case 'C':
+ case 'D': case 'E': case 'F':
+ if (!hex)
+ goto Linvalid;
+ v = (*p - 'A') + 10;
+ goto Lvalue;
- Lvalue:
- if (hex)
- c = (c << 4) + v;
- else
- c = (c * 10) + v;
- if (c > 0x10FFFF)
- {
- error("character entity out of range");
- goto Lignore;
- }
- continue;
+ Lvalue:
+ if (hex)
+ c = (c << 4) + v;
+ else
+ c = (c * 10) + v;
+ if (c > 0x10FFFF)
+ {
+ error("character entity out of range");
+ goto Lignore;
+ }
+ continue;
- default:
- Linvalid:
- error("invalid numeric character reference");
- goto Lignore;
- }
- break;
- }
+ default:
+ Linvalid:
+ error("invalid numeric character reference");
+ goto Lignore;
+ }
+ break;
+ }
}
else
{
- // It's a named entity; gather all characters until ;
- unsigned char *idstart = p + 1;
+ // It's a named entity; gather all characters until ;
+ unsigned char *idstart = p + 1;
- while (1)
- {
- p++;
- switch (*p)
- {
- case 0:
- case 0x1a:
- error("end of file before end of character entity");
- break;
+ while (1)
+ {
+ p++;
+ switch (*p)
+ {
+ case 0:
+ case 0x1a:
+ error("end of file before end of character entity");
+ break;
- case '\n':
- case '\r':
- case '<': // tag start
- // Termination is assumed
- c = HtmlNamedEntity(idstart, p - idstart);
- if (c == -1)
- goto Lignore;
- break;
+ case '\n':
+ case '\r':
+ case '<': // tag start
+ // Termination is assumed
+ c = HtmlNamedEntity(idstart, p - idstart);
+ if (c == -1)
+ goto Lignore;
+ break;
- case ';':
- // Termination is explicit
- c = HtmlNamedEntity(idstart, p - idstart);
- if (c == -1)
- goto Lignore;
- p++;
- break;
+ case ';':
+ // Termination is explicit
+ c = HtmlNamedEntity(idstart, p - idstart);
+ if (c == -1)
+ goto Lignore;
+ p++;
+ break;
- default:
- continue;
- }
- break;
- }
+ default:
+ continue;
+ }
+ break;
+ }
}
// Kludge to convert non-breaking space to ascii space
if (c == 160)
- c = ' ';
+ c = ' ';
return c;
@@ -699,19 +699,19 @@ static int isLineSeparator(const unsigned char* p)
{
// Linux
if( p[0]=='\n')
- return 1;
+ return 1;
// Mac & Dos
if( p[0]=='\r')
- return (p[1]=='\n') ? 2 : 1;
+ return (p[1]=='\n') ? 2 : 1;
// Unicode (line || paragraph sep.)
if( p[0]==0xE2 && p[1]==0x80 && (p[2]==0xA8 || p[2]==0xA9))
- return 3;
+ return 3;
// Next
if( p[0]==0xC2 && p[1]==0x85)
- return 2;
+ return 2;
return 0;
}
diff --git a/dmd/html.h b/dmd/html.h
index afb72087..451a1954 100644
--- a/dmd/html.h
+++ b/dmd/html.h
@@ -17,12 +17,12 @@ struct Html
{
const char *sourcename;
- unsigned char *base; // pointer to start of buffer
- unsigned char *end; // past end of buffer
- unsigned char *p; // current character
- unsigned linnum; // current line number
- OutBuffer *dbuf; // code source buffer
- int inCode; // !=0 if in code
+ unsigned char *base; // pointer to start of buffer
+ unsigned char *end; // past end of buffer
+ unsigned char *p; // current character
+ unsigned linnum; // current line number
+ OutBuffer *dbuf; // code source buffer
+ int inCode; // !=0 if in code
Html(const char *sourcename, unsigned char *base, unsigned length);
diff --git a/dmd/identifier.c b/dmd/identifier.c
index 30ed7721..2a7606fd 100644
--- a/dmd/identifier.c
+++ b/dmd/identifier.c
@@ -58,14 +58,14 @@ const char *Identifier::toHChars2()
else if (this == Id::result) p = "result";
else if (this == Id::returnLabel) p = "return";
else
- { p = toChars();
- if (*p == '_')
- {
- if (memcmp(p, "_staticCtor", 11) == 0)
- p = "static this";
- else if (memcmp(p, "_staticDtor", 11) == 0)
- p = "static ~this";
- }
+ { p = toChars();
+ if (*p == '_')
+ {
+ if (memcmp(p, "_staticCtor", 11) == 0)
+ p = "static this";
+ else if (memcmp(p, "_staticDtor", 11) == 0)
+ p = "static ~this";
+ }
}
return p;
diff --git a/dmd/idgen.c b/dmd/idgen.c
index 6babf391..80469a91 100644
--- a/dmd/idgen.c
+++ b/dmd/idgen.c
@@ -11,8 +11,8 @@
// Program to generate string files in d data structures.
// Saves much tedious typing, and eliminates typo problems.
// Generates:
-// id.h
-// id.c
+// id.h
+// id.c
#include
#include
@@ -22,8 +22,8 @@
struct Msgtable
{
- const char *ident; // name to use in DMD source
- const char *name; // name in D executable
+ const char *ident; // name to use in DMD source
+ const char *name; // name in D executable
};
Msgtable msgtable[] =
@@ -139,7 +139,7 @@ Msgtable msgtable[] =
{ "__LOCAL_SIZE" },
// For operator overloads
- { "uadd", "opPos" },
+ { "uadd", "opPos" },
{ "neg", "opNeg" },
{ "com", "opCom" },
{ "add", "opAdd" },
@@ -183,14 +183,14 @@ Msgtable msgtable[] =
{ "catass", "opCatAssign" },
{ "postinc", "opPostInc" },
{ "postdec", "opPostDec" },
- { "index", "opIndex" },
+ { "index", "opIndex" },
{ "indexass", "opIndexAssign" },
- { "slice", "opSlice" },
+ { "slice", "opSlice" },
{ "sliceass", "opSliceAssign" },
- { "call", "opCall" },
- { "cast", "opCast" },
- { "match", "opMatch" },
- { "next", "opNext" },
+ { "call", "opCall" },
+ { "cast", "opCast" },
+ { "match", "opMatch" },
+ { "next", "opNext" },
{ "opIn" },
{ "opIn_r" },
@@ -251,71 +251,71 @@ int main()
unsigned i;
{
- fp = fopen("id.h","w");
- if (!fp)
- { printf("can't open id.h\n");
- exit(EXIT_FAILURE);
- }
+ fp = fopen("id.h","w");
+ if (!fp)
+ { printf("can't open id.h\n");
+ exit(EXIT_FAILURE);
+ }
- fprintf(fp, "// File generated by idgen.c\n");
+ fprintf(fp, "// File generated by idgen.c\n");
#if __DMC__
- fprintf(fp, "#pragma once\n");
+ fprintf(fp, "#pragma once\n");
#endif
- fprintf(fp, "#ifndef DMD_ID_H\n");
- fprintf(fp, "#define DMD_ID_H 1\n");
- fprintf(fp, "struct Identifier;\n");
- fprintf(fp, "struct Id\n");
- fprintf(fp, "{\n");
+ fprintf(fp, "#ifndef DMD_ID_H\n");
+ fprintf(fp, "#define DMD_ID_H 1\n");
+ fprintf(fp, "struct Identifier;\n");
+ fprintf(fp, "struct Id\n");
+ fprintf(fp, "{\n");
- for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
- { const char *id = msgtable[i].ident;
+ for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
+ { const char *id = msgtable[i].ident;
- fprintf(fp," static Identifier *%s;\n", id);
- }
+ fprintf(fp," static Identifier *%s;\n", id);
+ }
- fprintf(fp, " static void initialize();\n");
- fprintf(fp, "};\n");
- fprintf(fp, "#endif\n");
+ fprintf(fp, " static void initialize();\n");
+ fprintf(fp, "};\n");
+ fprintf(fp, "#endif\n");
- fclose(fp);
+ fclose(fp);
}
{
- fp = fopen("id.c","w");
- if (!fp)
- { printf("can't open id.c\n");
- exit(EXIT_FAILURE);
- }
+ fp = fopen("id.c","w");
+ if (!fp)
+ { printf("can't open id.c\n");
+ exit(EXIT_FAILURE);
+ }
- fprintf(fp, "// File generated by idgen.c\n");
- fprintf(fp, "#include \"id.h\"\n");
- fprintf(fp, "#include \"identifier.h\"\n");
- fprintf(fp, "#include \"lexer.h\"\n");
+ fprintf(fp, "// File generated by idgen.c\n");
+ fprintf(fp, "#include \"id.h\"\n");
+ fprintf(fp, "#include \"identifier.h\"\n");
+ fprintf(fp, "#include \"lexer.h\"\n");
- for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
- { const char *id = msgtable[i].ident;
- const char *p = msgtable[i].name;
+ for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
+ { const char *id = msgtable[i].ident;
+ const char *p = msgtable[i].name;
- if (!p)
- p = id;
- fprintf(fp,"Identifier *Id::%s;\n", id);
- }
+ if (!p)
+ p = id;
+ fprintf(fp,"Identifier *Id::%s;\n", id);
+ }
- fprintf(fp, "void Id::initialize()\n");
- fprintf(fp, "{\n");
+ fprintf(fp, "void Id::initialize()\n");
+ fprintf(fp, "{\n");
- for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
- { const char *id = msgtable[i].ident;
- const char *p = msgtable[i].name;
+ for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
+ { const char *id = msgtable[i].ident;
+ const char *p = msgtable[i].name;
- if (!p)
- p = id;
- fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p);
- }
+ if (!p)
+ p = id;
+ fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p);
+ }
- fprintf(fp, "}\n");
+ fprintf(fp, "}\n");
- fclose(fp);
+ fclose(fp);
}
return EXIT_SUCCESS;
diff --git a/dmd/impcnvgen.c b/dmd/impcnvgen.c
index ed0f0b27..b3f9f211 100644
--- a/dmd/impcnvgen.c
+++ b/dmd/impcnvgen.c
@@ -21,16 +21,16 @@ int integral_promotion(int t)
{
switch (t)
{
- case Tchar:
- case Twchar:
- case Tbit:
- case Tbool:
- case Tint8:
- case Tuns8:
- case Tint16:
- case Tuns16: return Tint32;
- case Tdchar: return Tuns32;
- default: return t;
+ case Tchar:
+ case Twchar:
+ case Tbit:
+ case Tbool:
+ case Tint8:
+ case Tuns8:
+ case Tint16:
+ case Tuns16: return Tint32;
+ case Tdchar: return Tuns32;
+ default: return t;
}
}
@@ -39,17 +39,17 @@ void init()
// Set conversion tables
for (i = 0; i < TMAX; i++)
- for (j = 0; j < TMAX; j++)
- { impcnvResult[i][j] = Terror;
- impcnvType1[i][j] = Terror;
- impcnvType2[i][j] = Terror;
- impcnvWarn[i][j] = 0;
- }
+ for (j = 0; j < TMAX; j++)
+ { impcnvResult[i][j] = Terror;
+ impcnvType1[i][j] = Terror;
+ impcnvType2[i][j] = Terror;
+ impcnvWarn[i][j] = 0;
+ }
-#define X(t1,t2, nt1,nt2, rt) \
- impcnvResult[t1][t2] = rt; \
- impcnvType1[t1][t2] = nt1; \
- impcnvType2[t1][t2] = nt2;
+#define X(t1,t2, nt1,nt2, rt) \
+ impcnvResult[t1][t2] = rt; \
+ impcnvType1[t1][t2] = nt1; \
+ impcnvType2[t1][t2] = nt2;
/* ======================= */
@@ -318,7 +318,7 @@ void init()
#undef X
-#define Y(t1,t2) impcnvWarn[t1][t2] = 1;
+#define Y(t1,t2) impcnvWarn[t1][t2] = 1;
Y(Tint8, Tbit)
Y(Tuns8, Tbit)
Y(Tint16, Tbit)
@@ -385,15 +385,15 @@ void init()
Y(Tuns64, Tint64)
for (i = 0; i < TMAX; i++)
- for (j = 0; j < TMAX; j++)
- {
- if (impcnvResult[i][j] == Terror)
- {
- impcnvResult[i][j] = impcnvResult[j][i];
- impcnvType1[i][j] = impcnvType2[j][i];
- impcnvType2[i][j] = impcnvType1[j][i];
- }
- }
+ for (j = 0; j < TMAX; j++)
+ {
+ if (impcnvResult[i][j] == Terror)
+ {
+ impcnvResult[i][j] = impcnvResult[j][i];
+ impcnvType1[i][j] = impcnvType2[j][i];
+ impcnvType2[i][j] = impcnvType1[j][i];
+ }
+ }
}
int main()
@@ -411,44 +411,44 @@ int main()
fprintf(fp,"unsigned char Type::impcnvResult[TMAX][TMAX] =\n{\n");
for (i = 0; i < TMAX; i++)
{
- for (j = 0; j < TMAX; j++)
- {
- fprintf(fp, "%d,",impcnvResult[i][j]);
- }
- fprintf(fp, "\n");
+ for (j = 0; j < TMAX; j++)
+ {
+ fprintf(fp, "%d,",impcnvResult[i][j]);
+ }
+ fprintf(fp, "\n");
}
fprintf(fp,"};\n");
fprintf(fp,"unsigned char Type::impcnvType1[TMAX][TMAX] =\n{\n");
for (i = 0; i < TMAX; i++)
{
- for (j = 0; j < TMAX; j++)
- {
- fprintf(fp, "%d,",impcnvType1[i][j]);
- }
- fprintf(fp, "\n");
+ for (j = 0; j < TMAX; j++)
+ {
+ fprintf(fp, "%d,",impcnvType1[i][j]);
+ }
+ fprintf(fp, "\n");
}
fprintf(fp,"};\n");
fprintf(fp,"unsigned char Type::impcnvType2[TMAX][TMAX] =\n{\n");
for (i = 0; i < TMAX; i++)
{
- for (j = 0; j < TMAX; j++)
- {
- fprintf(fp, "%d,",impcnvType2[i][j]);
- }
- fprintf(fp, "\n");
+ for (j = 0; j < TMAX; j++)
+ {
+ fprintf(fp, "%d,",impcnvType2[i][j]);
+ }
+ fprintf(fp, "\n");
}
fprintf(fp,"};\n");
fprintf(fp,"unsigned char Type::impcnvWarn[TMAX][TMAX] =\n{\n");
for (i = 0; i < TMAX; i++)
{
- for (j = 0; j < TMAX; j++)
- {
- fprintf(fp, "%d,",impcnvWarn[i][j]);
- }
- fprintf(fp, "\n");
+ for (j = 0; j < TMAX; j++)
+ {
+ fprintf(fp, "%d,",impcnvWarn[i][j]);
+ }
+ fprintf(fp, "\n");
}
fprintf(fp,"};\n");
diff --git a/dmd/import.c b/dmd/import.c
index d99a7896..c85a0a01 100644
--- a/dmd/import.c
+++ b/dmd/import.c
@@ -26,7 +26,7 @@
/********************************* Import ****************************/
Import::Import(Loc loc, Array *packages, Identifier *id, Identifier *aliasId,
- int isstatic)
+ int isstatic)
: Dsymbol(id)
{
assert(id);
@@ -40,19 +40,19 @@ Import::Import(Loc loc, Array *packages, Identifier *id, Identifier *aliasId,
mod = NULL;
if (aliasId)
- this->ident = aliasId;
+ this->ident = aliasId;
// Kludge to change Import identifier to first package
else if (packages && packages->dim)
- this->ident = (Identifier *)packages->data[0];
+ this->ident = (Identifier *)packages->data[0];
}
void Import::addAlias(Identifier *name, Identifier *alias)
{
if (isstatic)
- error("cannot have an import bind list");
+ error("cannot have an import bind list");
if (!aliasId)
- this->ident = NULL; // make it an anonymous import
+ this->ident = NULL; // make it an anonymous import
names.push(name);
aliases.push(alias);
@@ -78,7 +78,7 @@ Dsymbol *Import::syntaxCopy(Dsymbol *s)
for (size_t i = 0; i < names.dim; i++)
{
- si->addAlias((Identifier *)names.data[i], (Identifier *)aliases.data[i]);
+ si->addAlias((Identifier *)names.data[i], (Identifier *)aliases.data[i]);
}
return si;
@@ -95,26 +95,26 @@ void Import::load(Scope *sc)
if (s)
{
#if TARGET_NET
- mod = (Module *)s;
+ mod = (Module *)s;
#else
- if (s->isModule())
- mod = (Module *)s;
- else
- error("package and module have the same name");
+ if (s->isModule())
+ mod = (Module *)s;
+ else
+ error("package and module have the same name");
#endif
}
if (!mod)
{
- // Load module
- mod = Module::load(loc, packages, id);
- dst->insert(id, mod); // id may be different from mod->ident,
- // if so then insert alias
- if (!mod->importedFrom)
- mod->importedFrom = sc ? sc->module->importedFrom : Module::rootModule;
+ // Load module
+ mod = Module::load(loc, packages, id);
+ dst->insert(id, mod); // id may be different from mod->ident,
+ // if so then insert alias
+ if (!mod->importedFrom)
+ mod->importedFrom = sc ? sc->module->importedFrom : Module::rootModule;
}
if (!pkg)
- pkg = mod;
+ pkg = mod;
//printf("-Import::load('%s'), pkg = %p\n", toChars(), pkg);
}
@@ -123,19 +123,19 @@ void escapePath(OutBuffer *buf, const char *fname)
{
while (1)
{
- switch (*fname)
- {
- case 0:
- return;
- case '(':
- case ')':
- case '\\':
- buf->writebyte('\\');
- default:
- buf->writebyte(*fname);
- break;
- }
- fname++;
+ switch (*fname)
+ {
+ case 0:
+ return;
+ case '(':
+ case ')':
+ case '\\':
+ buf->writebyte('\\');
+ default:
+ buf->writebyte(*fname);
+ break;
+ }
+ fname++;
}
}
@@ -164,124 +164,124 @@ void Import::semantic(Scope *sc)
// Load if not already done so
if (!mod)
- { load(sc);
- mod->importAll(0);
+ { load(sc);
+ mod->importAll(0);
}
if (mod)
{
#if 0
- if (mod->loc.linnum != 0)
- { /* If the line number is not 0, then this is not
- * a 'root' module, i.e. it was not specified on the command line.
- */
- mod->importedFrom = sc->module->importedFrom;
- assert(mod->importedFrom);
- }
+ if (mod->loc.linnum != 0)
+ { /* If the line number is not 0, then this is not
+ * a 'root' module, i.e. it was not specified on the command line.
+ */
+ mod->importedFrom = sc->module->importedFrom;
+ assert(mod->importedFrom);
+ }
#endif
- // Modules need a list of each imported module
- //printf("%s imports %s\n", sc->module->toChars(), mod->toChars());
- sc->module->aimports.push(mod);
+ // Modules need a list of each imported module
+ //printf("%s imports %s\n", sc->module->toChars(), mod->toChars());
+ sc->module->aimports.push(mod);
- /* Default to private importing
- */
- protection = sc->protection;
- if (!sc->explicitProtection)
- protection = PROTprivate;
+ /* Default to private importing
+ */
+ protection = sc->protection;
+ if (!sc->explicitProtection)
+ protection = PROTprivate;
- if (!isstatic && !aliasId && !names.dim)
- {
- sc->scopesym->importScope(mod, protection);
- }
+ if (!isstatic && !aliasId && !names.dim)
+ {
+ sc->scopesym->importScope(mod, protection);
+ }
- mod->semantic();
+ mod->semantic();
- if (mod->needmoduleinfo)
- sc->module->needmoduleinfo = 1;
+ if (mod->needmoduleinfo)
+ sc->module->needmoduleinfo = 1;
- sc = sc->push(mod);
- for (size_t i = 0; i < aliasdecls.dim; i++)
- { AliasDeclaration *ad = (AliasDeclaration *)aliasdecls.data[i];
+ sc = sc->push(mod);
+ for (size_t i = 0; i < aliasdecls.dim; i++)
+ { AliasDeclaration *ad = (AliasDeclaration *)aliasdecls.data[i];
- //printf("\tImport alias semantic('%s')\n", s->toChars());
- if (!mod->search(loc, (Identifier *)names.data[i], 0))
- error("%s not found", ((Identifier *)names.data[i])->toChars());
+ //printf("\tImport alias semantic('%s')\n", s->toChars());
+ if (!mod->search(loc, (Identifier *)names.data[i], 0))
+ error("%s not found", ((Identifier *)names.data[i])->toChars());
- ad->importprot = protection;
- ad->semantic(sc);
- }
- sc = sc->pop();
+ ad->importprot = protection;
+ ad->semantic(sc);
+ }
+ sc = sc->pop();
}
//printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg);
if (global.params.moduleDeps != NULL)
{
- /* The grammar of the file is:
- * ImportDeclaration
- * ::= BasicImportDeclaration [ " : " ImportBindList ] [ " -> "
- * ModuleAliasIdentifier ] "\n"
- *
- * BasicImportDeclaration
- * ::= ModuleFullyQualifiedName " (" FilePath ") : " Protection
- * " [ " static" ] : " ModuleFullyQualifiedName " (" FilePath ")"
- *
- * FilePath
- * - any string with '(', ')' and '\' escaped with the '\' character
- */
+ /* The grammar of the file is:
+ * ImportDeclaration
+ * ::= BasicImportDeclaration [ " : " ImportBindList ] [ " -> "
+ * ModuleAliasIdentifier ] "\n"
+ *
+ * BasicImportDeclaration
+ * ::= ModuleFullyQualifiedName " (" FilePath ") : " Protection
+ * " [ " static" ] : " ModuleFullyQualifiedName " (" FilePath ")"
+ *
+ * FilePath
+ * - any string with '(', ')' and '\' escaped with the '\' character
+ */
- OutBuffer *ob = global.params.moduleDeps;
+ OutBuffer *ob = global.params.moduleDeps;
- ob->writestring(sc->module->toPrettyChars());
- ob->writestring(" (");
- escapePath(ob, sc->module->srcfile->toChars());
- ob->writestring(") : ");
+ ob->writestring(sc->module->toPrettyChars());
+ ob->writestring(" (");
+ escapePath(ob, sc->module->srcfile->toChars());
+ ob->writestring(") : ");
- ProtDeclaration::protectionToCBuffer(ob, sc->protection);
- if (isstatic)
- StorageClassDeclaration::stcToCBuffer(ob, STCstatic);
- ob->writestring(": ");
+ ProtDeclaration::protectionToCBuffer(ob, sc->protection);
+ if (isstatic)
+ StorageClassDeclaration::stcToCBuffer(ob, STCstatic);
+ ob->writestring(": ");
- if (packages)
- {
- for (size_t i = 0; i < packages->dim; i++)
- {
- Identifier *pid = (Identifier *)packages->data[i];
- ob->printf("%s.", pid->toChars());
- }
- }
+ if (packages)
+ {
+ for (size_t i = 0; i < packages->dim; i++)
+ {
+ Identifier *pid = (Identifier *)packages->data[i];
+ ob->printf("%s.", pid->toChars());
+ }
+ }
- ob->writestring(id->toChars());
- ob->writestring(" (");
- if (mod)
- escapePath(ob, mod->srcfile->toChars());
- else
- ob->writestring("???");
- ob->writebyte(')');
+ ob->writestring(id->toChars());
+ ob->writestring(" (");
+ if (mod)
+ escapePath(ob, mod->srcfile->toChars());
+ else
+ ob->writestring("???");
+ ob->writebyte(')');
- for (size_t i = 0; i < names.dim; i++)
- {
- if (i == 0)
- ob->writebyte(':');
- else
- ob->writebyte(',');
+ for (size_t i = 0; i < names.dim; i++)
+ {
+ if (i == 0)
+ ob->writebyte(':');
+ else
+ ob->writebyte(',');
- Identifier *name = (Identifier *)names.data[i];
- Identifier *alias = (Identifier *)aliases.data[i];
+ Identifier *name = (Identifier *)names.data[i];
+ Identifier *alias = (Identifier *)aliases.data[i];
- if (!alias)
- {
- ob->printf("%s", name->toChars());
- alias = name;
- }
- else
- ob->printf("%s=%s", alias->toChars(), name->toChars());
- }
+ if (!alias)
+ {
+ ob->printf("%s", name->toChars());
+ alias = name;
+ }
+ else
+ ob->printf("%s=%s", alias->toChars(), name->toChars());
+ }
- if (aliasId)
- ob->printf(" -> %s", aliasId->toChars());
+ if (aliasId)
+ ob->printf(" -> %s", aliasId->toChars());
- ob->writenl();
+ ob->writenl();
}
//printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg);
@@ -292,13 +292,13 @@ void Import::semantic2(Scope *sc)
//printf("Import::semantic2('%s')\n", toChars());
mod->semantic2();
if (mod->needmoduleinfo)
- sc->module->needmoduleinfo = 1;
+ sc->module->needmoduleinfo = 1;
}
Dsymbol *Import::toAlias()
{
if (aliasId)
- return mod;
+ return mod;
return this;
}
@@ -311,27 +311,27 @@ int Import::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
int result = 0;
if (names.dim == 0)
- return Dsymbol::addMember(sc, sd, memnum);
+ return Dsymbol::addMember(sc, sd, memnum);
if (aliasId)
- result = Dsymbol::addMember(sc, sd, memnum);
+ result = Dsymbol::addMember(sc, sd, memnum);
/* Instead of adding the import to sd's symbol table,
* add each of the alias=name pairs
*/
for (size_t i = 0; i < names.dim; i++)
{
- Identifier *name = (Identifier *)names.data[i];
- Identifier *alias = (Identifier *)aliases.data[i];
+ Identifier *name = (Identifier *)names.data[i];
+ Identifier *alias = (Identifier *)aliases.data[i];
- if (!alias)
- alias = name;
+ if (!alias)
+ alias = name;
- TypeIdentifier *tname = new TypeIdentifier(loc, name);
- AliasDeclaration *ad = new AliasDeclaration(loc, alias, tname);
- result |= ad->addMember(sc, sd, memnum);
+ TypeIdentifier *tname = new TypeIdentifier(loc, name);
+ AliasDeclaration *ad = new AliasDeclaration(loc, alias, tname);
+ result |= ad->addMember(sc, sd, memnum);
- aliasdecls.push(ad);
+ aliasdecls.push(ad);
}
return result;
@@ -342,8 +342,8 @@ Dsymbol *Import::search(Loc loc, Identifier *ident, int flags)
//printf("%s.Import::search(ident = '%s', flags = x%x)\n", toChars(), ident->toChars(), flags);
if (!pkg)
- { load(NULL);
- mod->semantic();
+ { load(NULL);
+ mod->semantic();
}
// Forward it to the package/module
@@ -359,42 +359,42 @@ int Import::overloadInsert(Dsymbol *s)
void Import::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (hgs->hdrgen && id == Id::object)
- return; // object is imported by default
+ return; // object is imported by default
if (isstatic)
- buf->writestring("static ");
+ buf->writestring("static ");
buf->writestring("import ");
if (aliasId)
{
- buf->printf("%s = ", aliasId->toChars());
+ buf->printf("%s = ", aliasId->toChars());
}
if (packages && packages->dim)
{
- for (size_t i = 0; i < packages->dim; i++)
- { Identifier *pid = (Identifier *)packages->data[i];
+ for (size_t i = 0; i < packages->dim; i++)
+ { Identifier *pid = (Identifier *)packages->data[i];
- buf->printf("%s.", pid->toChars());
- }
+ buf->printf("%s.", pid->toChars());
+ }
}
buf->printf("%s", id->toChars());
if (names.dim > 0) {
- buf->writebyte(':');
- for (size_t i = 0; i < names.dim; i++)
- {
- if (i > 0) {
- buf->writebyte(',');
- }
+ buf->writebyte(':');
+ for (size_t i = 0; i < names.dim; i++)
+ {
+ if (i > 0) {
+ buf->writebyte(',');
+ }
- Identifier *name = (Identifier *)names.data[i];
- Identifier *alias = (Identifier *)aliases.data[i];
+ Identifier *name = (Identifier *)names.data[i];
+ Identifier *alias = (Identifier *)aliases.data[i];
- if (!alias) {
- buf->printf("%s", name->toChars());
- alias = name;
- } else {
- buf->printf("%s=%s", alias->toChars(), name->toChars());
- }
- }
+ if (!alias) {
+ buf->printf("%s", name->toChars());
+ alias = name;
+ } else {
+ buf->printf("%s=%s", alias->toChars(), name->toChars());
+ }
+ }
}
buf->writebyte(';');
buf->writenl();
diff --git a/dmd/import.h b/dmd/import.h
index a2496493..b04fed48 100644
--- a/dmd/import.h
+++ b/dmd/import.h
@@ -30,28 +30,28 @@ struct HdrGenState;
struct Import : Dsymbol
{
- Array *packages; // array of Identifier's representing packages
- Identifier *id; // module Identifier
+ Array *packages; // array of Identifier's representing packages
+ Identifier *id; // module Identifier
Identifier *aliasId;
- int isstatic; // !=0 if static import
+ int isstatic; // !=0 if static import
enum PROT protection;
// Pairs of alias=name to bind into current namespace
Array names;
Array aliases;
- Array aliasdecls; // AliasDeclarations for names/aliases
+ Array aliasdecls; // AliasDeclarations for names/aliases
Module *mod;
- Package *pkg; // leftmost package/module
+ Package *pkg; // leftmost package/module
Import(Loc loc, Array *packages, Identifier *id, Identifier *aliasId,
- int isstatic);
+ int isstatic);
void addAlias(Identifier *name, Identifier *alias);
const char *kind();
enum PROT prot();
- Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
+ Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
void load(Scope *sc);
void importAll(Scope *sc);
void semantic(Scope *sc);
diff --git a/dmd/init.c b/dmd/init.c
index f59c3081..21aed083 100644
--- a/dmd/init.c
+++ b/dmd/init.c
@@ -50,14 +50,14 @@ Initializers *Initializer::arraySyntaxCopy(Initializers *ai)
if (ai)
{
- a = new Initializers();
- a->setDim(ai->dim);
- for (int i = 0; i < a->dim; i++)
- { Initializer *e = (Initializer *)ai->data[i];
+ a = new Initializers();
+ a->setDim(ai->dim);
+ for (int i = 0; i < a->dim; i++)
+ { Initializer *e = (Initializer *)ai->data[i];
- e = e->syntaxCopy();
- a->data[i] = e;
- }
+ e = e->syntaxCopy();
+ a->data[i] = e;
+ }
}
return a;
}
@@ -124,12 +124,12 @@ Initializer *StructInitializer::syntaxCopy()
ai->field.setDim(field.dim);
ai->value.setDim(value.dim);
for (int i = 0; i < field.dim; i++)
- {
- ai->field.data[i] = field.data[i];
+ {
+ ai->field.data[i] = field.data[i];
- Initializer *init = (Initializer *)value.data[i];
- init = init->syntaxCopy();
- ai->value.data[i] = init;
+ Initializer *init = (Initializer *)value.data[i];
+ init = init->syntaxCopy();
+ ai->value.data[i] = init;
}
return ai;
}
@@ -150,88 +150,88 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t)
vars.setDim(field.dim);
t = t->toBasetype();
if (t->ty == Tstruct)
- { unsigned i;
- unsigned fieldi = 0;
+ { unsigned i;
+ unsigned fieldi = 0;
- ts = (TypeStruct *)t;
- ad = ts->sym;
- for (i = 0; i < field.dim; i++)
- {
- Identifier *id = (Identifier *)field.data[i];
- Initializer *val = (Initializer *)value.data[i];
- Dsymbol *s;
- VarDeclaration *v;
+ ts = (TypeStruct *)t;
+ ad = ts->sym;
+ for (i = 0; i < field.dim; i++)
+ {
+ Identifier *id = (Identifier *)field.data[i];
+ Initializer *val = (Initializer *)value.data[i];
+ Dsymbol *s;
+ VarDeclaration *v;
- if (id == NULL)
- {
- if (fieldi >= ad->fields.dim)
- { error(loc, "too many initializers for %s", ad->toChars());
- field.remove(i);
- i--;
- continue;
- }
- else
- {
- s = (Dsymbol *)ad->fields.data[fieldi];
- }
- }
- else
- {
- //s = ad->symtab->lookup(id);
- s = ad->search(loc, id, 0);
- if (!s)
- {
- error(loc, "'%s' is not a member of '%s'", id->toChars(), t->toChars());
- continue;
- }
+ if (id == NULL)
+ {
+ if (fieldi >= ad->fields.dim)
+ { error(loc, "too many initializers for %s", ad->toChars());
+ field.remove(i);
+ i--;
+ continue;
+ }
+ else
+ {
+ s = (Dsymbol *)ad->fields.data[fieldi];
+ }
+ }
+ else
+ {
+ //s = ad->symtab->lookup(id);
+ s = ad->search(loc, id, 0);
+ if (!s)
+ {
+ error(loc, "'%s' is not a member of '%s'", id->toChars(), t->toChars());
+ continue;
+ }
- // Find out which field index it is
- for (fieldi = 0; 1; fieldi++)
- {
- if (fieldi >= ad->fields.dim)
- {
- s->error("is not a per-instance initializable field");
- break;
- }
- if (s == (Dsymbol *)ad->fields.data[fieldi])
- break;
- }
- }
- if (s && (v = s->isVarDeclaration()) != NULL)
- {
- val = val->semantic(sc, v->type);
- value.data[i] = (void *)val;
- vars.data[i] = (void *)v;
- }
- else
- { error(loc, "%s is not a field of %s", id ? id->toChars() : s->toChars(), ad->toChars());
- errors = 1;
- }
- fieldi++;
- }
+ // Find out which field index it is
+ for (fieldi = 0; 1; fieldi++)
+ {
+ if (fieldi >= ad->fields.dim)
+ {
+ s->error("is not a per-instance initializable field");
+ break;
+ }
+ if (s == (Dsymbol *)ad->fields.data[fieldi])
+ break;
+ }
+ }
+ if (s && (v = s->isVarDeclaration()) != NULL)
+ {
+ val = val->semantic(sc, v->type);
+ value.data[i] = (void *)val;
+ vars.data[i] = (void *)v;
+ }
+ else
+ { error(loc, "%s is not a field of %s", id ? id->toChars() : s->toChars(), ad->toChars());
+ errors = 1;
+ }
+ fieldi++;
+ }
}
else if (t->ty == Tdelegate && value.dim == 0)
- { /* Rewrite as empty delegate literal { }
- */
- Parameters *arguments = new Parameters;
- Type *tf = new TypeFunction(arguments, NULL, 0, LINKd);
- FuncLiteralDeclaration *fd = new FuncLiteralDeclaration(loc, 0, tf, TOKdelegate, NULL);
- fd->fbody = new CompoundStatement(loc, new Statements());
- fd->endloc = loc;
- Expression *e = new FuncExp(loc, fd);
- ExpInitializer *ie = new ExpInitializer(loc, e);
- return ie->semantic(sc, t);
+ { /* Rewrite as empty delegate literal { }
+ */
+ Parameters *arguments = new Parameters;
+ Type *tf = new TypeFunction(arguments, NULL, 0, LINKd);
+ FuncLiteralDeclaration *fd = new FuncLiteralDeclaration(loc, 0, tf, TOKdelegate, NULL);
+ fd->fbody = new CompoundStatement(loc, new Statements());
+ fd->endloc = loc;
+ Expression *e = new FuncExp(loc, fd);
+ ExpInitializer *ie = new ExpInitializer(loc, e);
+ return ie->semantic(sc, t);
}
else
{
- error(loc, "a struct is not a valid initializer for a %s", t->toChars());
- errors = 1;
+ error(loc, "a struct is not a valid initializer for a %s", t->toChars());
+ errors = 1;
}
if (errors)
{
- field.setDim(0);
- value.setDim(0);
- vars.setDim(0);
+ field.setDim(0);
+ value.setDim(0);
+ vars.setDim(0);
}
return this;
}
@@ -246,25 +246,25 @@ Expression *StructInitializer::toExpression()
{ Expression *e;
//printf("StructInitializer::toExpression() %s\n", toChars());
- if (!ad) // if fwd referenced
+ if (!ad) // if fwd referenced
{
- return NULL;
+ return NULL;
}
StructDeclaration *sd = ad->isStructDeclaration();
if (!sd)
- return NULL;
+ return NULL;
Expressions *elements = new Expressions();
for (size_t i = 0; i < value.dim; i++)
{
- if (field.data[i])
- goto Lno;
- Initializer *iz = (Initializer *)value.data[i];
- if (!iz)
- goto Lno;
- Expression *ex = iz->toExpression();
- if (!ex)
- goto Lno;
- elements->push(ex);
+ if (field.data[i])
+ goto Lno;
+ Initializer *iz = (Initializer *)value.data[i];
+ if (!iz)
+ goto Lno;
+ Expression *ex = iz->toExpression();
+ if (!ex)
+ goto Lno;
+ elements->push(ex);
}
e = new StructLiteralExp(loc, sd, elements);
e->type = sd->type;
@@ -284,7 +284,7 @@ void StructInitializer::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
for (int i = 0; i < field.dim; i++)
{
if (i > 0)
- buf->writebyte(',');
+ buf->writebyte(',');
Identifier *id = (Identifier *)field.data[i];
if (id)
{
@@ -318,14 +318,14 @@ Initializer *ArrayInitializer::syntaxCopy()
ai->index.setDim(index.dim);
ai->value.setDim(value.dim);
for (int i = 0; i < ai->value.dim; i++)
- { Expression *e = (Expression *)index.data[i];
- if (e)
- e = e->syntaxCopy();
- ai->index.data[i] = e;
+ { Expression *e = (Expression *)index.data[i];
+ if (e)
+ e = e->syntaxCopy();
+ ai->index.data[i] = e;
- Initializer *init = (Initializer *)value.data[i];
- init = init->syntaxCopy();
- ai->value.data[i] = init;
+ Initializer *init = (Initializer *)value.data[i];
+ init = init->syntaxCopy();
+ ai->value.data[i] = init;
}
return ai;
}
@@ -343,48 +343,48 @@ Initializer *ArrayInitializer::semantic(Scope *sc, Type *t)
unsigned length;
//printf("ArrayInitializer::semantic(%s)\n", t->toChars());
- if (sem) // if semantic() already run
- return this;
+ if (sem) // if semantic() already run
+ return this;
sem = 1;
type = t;
t = t->toBasetype();
switch (t->ty)
{
- case Tpointer:
- case Tsarray:
- case Tarray:
- break;
+ case Tpointer:
+ case Tsarray:
+ case Tarray:
+ break;
- default:
- error(loc, "cannot use array to initialize %s", type->toChars());
- return this;
+ default:
+ error(loc, "cannot use array to initialize %s", type->toChars());
+ return this;
}
length = 0;
for (i = 0; i < index.dim; i++)
- { Expression *idx;
- Initializer *val;
+ { Expression *idx;
+ Initializer *val;
- idx = (Expression *)index.data[i];
- if (idx)
- { idx = idx->semantic(sc);
- idx = idx->optimize(WANTvalue | WANTinterpret);
- index.data[i] = (void *)idx;
- length = idx->toInteger();
- }
+ idx = (Expression *)index.data[i];
+ if (idx)
+ { idx = idx->semantic(sc);
+ idx = idx->optimize(WANTvalue | WANTinterpret);
+ index.data[i] = (void *)idx;
+ length = idx->toInteger();
+ }
- val = (Initializer *)value.data[i];
- val = val->semantic(sc, t->next);
- value.data[i] = (void *)val;
- length++;
- if (length == 0)
- error(loc, "array dimension overflow");
- if (length > dim)
- dim = length;
+ val = (Initializer *)value.data[i];
+ val = val->semantic(sc, t->next);
+ value.data[i] = (void *)val;
+ length++;
+ if (length == 0)
+ error(loc, "array dimension overflow");
+ if (length > dim)
+ dim = length;
}
unsigned long amax = 0x80000000;
if ((unsigned long) dim * t->next->size() >= amax)
- error(loc, "array dimension %u exceeds max of %ju", dim, amax / t->next->size());
+ error(loc, "array dimension %u exceeds max of %ju", dim, amax / t->next->size());
return this;
}
@@ -403,53 +403,53 @@ Expression *ArrayInitializer::toExpression()
Type *t = NULL;
if (type)
{
- if (type == Type::terror)
- return new ErrorExp();
+ if (type == Type::terror)
+ return new ErrorExp();
- t = type->toBasetype();
- switch (t->ty)
- {
- case Tsarray:
- edim = ((TypeSArray *)t)->dim->toInteger();
- break;
+ t = type->toBasetype();
+ switch (t->ty)
+ {
+ case Tsarray:
+ edim = ((TypeSArray *)t)->dim->toInteger();
+ break;
- case Tpointer:
- case Tarray:
- edim = dim;
- break;
+ case Tpointer:
+ case Tarray:
+ edim = dim;
+ break;
- default:
- assert(0);
- }
+ default:
+ assert(0);
+ }
}
else
{
- edim = value.dim;
- for (size_t i = 0, j = 0; i < value.dim; i++, j++)
- {
- if (index.data[i])
- j = ((Expression *)index.data[i])->toInteger();
- if (j >= edim)
- edim = j + 1;
- }
+ edim = value.dim;
+ for (size_t i = 0, j = 0; i < value.dim; i++, j++)
+ {
+ if (index.data[i])
+ j = ((Expression *)index.data[i])->toInteger();
+ if (j >= edim)
+ edim = j + 1;
+ }
}
elements = new Expressions();
elements->setDim(edim);
for (size_t i = 0, j = 0; i < value.dim; i++, j++)
{
- if (index.data[i])
- j = ((Expression *)index.data[i])->toInteger();
- assert(j < edim);
- Initializer *iz = (Initializer *)value.data[i];
- if (!iz)
- goto Lno;
- Expression *ex = iz->toExpression();
- if (!ex)
- {
- goto Lno;
- }
- elements->data[j] = ex;
+ if (index.data[i])
+ j = ((Expression *)index.data[i])->toInteger();
+ assert(j < edim);
+ Initializer *iz = (Initializer *)value.data[i];
+ if (!iz)
+ goto Lno;
+ Expression *ex = iz->toExpression();
+ if (!ex)
+ {
+ goto Lno;
+ }
+ elements->data[j] = ex;
}
/* Fill in any missing elements with the default initializer
@@ -458,14 +458,14 @@ Expression *ArrayInitializer::toExpression()
Expression *init = NULL;
for (size_t i = 0; i < edim; i++)
{
- if (!elements->data[i])
- {
- if (!type)
- goto Lno;
- if (!init)
- init = t->next->defaultInit();
- elements->data[i] = init;
- }
+ if (!elements->data[i])
+ {
+ if (!type)
+ goto Lno;
+ if (!init)
+ init = t->next->defaultInit();
+ elements->data[i] = init;
+ }
}
Expression *e = new ArrayLiteralExp(loc, elements);
@@ -497,18 +497,18 @@ Initializer *ArrayInitializer::toAssocArrayInitializer()
for (size_t i = 0; i < value.dim; i++)
{
- e = (Expression *)index.data[i];
- if (!e)
- goto Lno;
- keys->data[i] = (void *)e;
+ e = (Expression *)index.data[i];
+ if (!e)
+ goto Lno;
+ keys->data[i] = (void *)e;
- Initializer *iz = (Initializer *)value.data[i];
- if (!iz)
- goto Lno;
- e = iz->toExpression();
- if (!e)
- goto Lno;
- values->data[i] = (void *)e;
+ Initializer *iz = (Initializer *)value.data[i];
+ if (!iz)
+ goto Lno;
+ e = iz->toExpression();
+ if (!e)
+ goto Lno;
+ values->data[i] = (void *)e;
}
e = new AssocArrayLiteralExp(loc, keys, values);
return new ExpInitializer(loc, e);
@@ -525,18 +525,18 @@ Type *ArrayInitializer::inferType(Scope *sc)
{
for (size_t i = 0; i < value.dim; i++)
{
- if (index.data[i])
- goto Laa;
+ if (index.data[i])
+ goto Laa;
}
if (value.dim)
{
- Initializer *iz = (Initializer *)value.data[0];
- if (iz)
- { Type *t = iz->inferType(sc);
- t = new TypeSArray(t, new IntegerExp(value.dim));
- t = t->semantic(loc, sc);
- return t;
- }
+ Initializer *iz = (Initializer *)value.data[0];
+ if (iz)
+ { Type *t = iz->inferType(sc);
+ t = new TypeSArray(t, new IntegerExp(value.dim));
+ t = t->semantic(loc, sc);
+ return t;
+ }
}
Laa:
@@ -546,13 +546,13 @@ Laa:
Expression *indexinit = (Expression *)index.data[0];
if (iz && indexinit)
{ Type *t = iz->inferType(sc);
- indexinit = indexinit->semantic(sc);
- Type *indext = indexinit->type;
- t = new TypeAArray(t, indext);
- type = t->semantic(loc, sc);
+ indexinit = indexinit->semantic(sc);
+ Type *indext = indexinit->type;
+ t = new TypeAArray(t, indext);
+ type = t->semantic(loc, sc);
}
else
- error(loc, "cannot infer type from this array initializer");
+ error(loc, "cannot infer type from this array initializer");
return type;
}
@@ -563,7 +563,7 @@ void ArrayInitializer::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
for (int i = 0; i < index.dim; i++)
{
if (i > 0)
- buf->writebyte(',');
+ buf->writebyte(',');
Expression *ex = (Expression *)index.data[i];
if (ex)
{
@@ -599,30 +599,30 @@ Initializer *ExpInitializer::semantic(Scope *sc, Type *t)
/* Look for case of initializing a static array with a too-short
* string literal, such as:
- * char[5] foo = "abc";
+ * char[5] foo = "abc";
* Allow this by doing an explicit cast, which will lengthen the string
* literal.
*/
if (exp->op == TOKstring && tb->ty == Tsarray && exp->type->ty == Tsarray)
- { StringExp *se = (StringExp *)exp;
+ { StringExp *se = (StringExp *)exp;
- if (!se->committed && se->type->ty == Tsarray &&
- ((TypeSArray *)se->type)->dim->toInteger() <
- ((TypeSArray *)t)->dim->toInteger())
- {
- exp = se->castTo(sc, t);
- goto L1;
- }
+ if (!se->committed && se->type->ty == Tsarray &&
+ ((TypeSArray *)se->type)->dim->toInteger() <
+ ((TypeSArray *)t)->dim->toInteger())
+ {
+ exp = se->castTo(sc, t);
+ goto L1;
+ }
}
// Look for the case of statically initializing an array
// with a single member.
if (tb->ty == Tsarray &&
- !tb->next->equals(exp->type->toBasetype()->next) &&
- exp->implicitConvTo(tb->next)
+ !tb->next->equals(exp->type->toBasetype()->next) &&
+ exp->implicitConvTo(tb->next)
)
{
- t = tb->next;
+ t = tb->next;
}
exp = exp->implicitCastTo(sc, t);
@@ -641,28 +641,28 @@ Type *ExpInitializer::inferType(Scope *sc)
// Give error for overloaded function addresses
if (exp->op == TOKsymoff)
{ SymOffExp *se = (SymOffExp *)exp;
- if (
+ if (
#if DMDV2
- se->hasOverloads &&
+ se->hasOverloads &&
#else
- se->var->isFuncDeclaration() &&
+ se->var->isFuncDeclaration() &&
#endif
- !se->var->isFuncDeclaration()->isUnique())
- exp->error("cannot infer type from overloaded function symbol %s", exp->toChars());
+ !se->var->isFuncDeclaration()->isUnique())
+ exp->error("cannot infer type from overloaded function symbol %s", exp->toChars());
}
// Give error for overloaded function addresses
if (exp->op == TOKdelegate)
{ DelegateExp *se = (DelegateExp *)exp;
- if (
- se->func->isFuncDeclaration() &&
- !se->func->isFuncDeclaration()->isUnique())
- exp->error("cannot infer type from overloaded function symbol %s", exp->toChars());
+ if (
+ se->func->isFuncDeclaration() &&
+ !se->func->isFuncDeclaration()->isUnique())
+ exp->error("cannot infer type from overloaded function symbol %s", exp->toChars());
}
Type *t = exp->type;
if (!t)
- t = Initializer::inferType(sc);
+ t = Initializer::inferType(sc);
return t;
}
diff --git a/dmd/init.h b/dmd/init.h
index d7a4bcf0..aab5d043 100644
--- a/dmd/init.h
+++ b/dmd/init.h
@@ -56,7 +56,7 @@ struct Initializer : Object
struct VoidInitializer : Initializer
{
- Type *type; // type that this will initialize to
+ Type *type; // type that this will initialize to
VoidInitializer(Loc loc);
Initializer *syntaxCopy();
@@ -73,11 +73,11 @@ struct VoidInitializer : Initializer
struct StructInitializer : Initializer
{
- Identifiers field; // of Identifier *'s
- Initializers value; // parallel array of Initializer *'s
+ Identifiers field; // of Identifier *'s
+ Initializers value; // parallel array of Initializer *'s
- Array vars; // parallel array of VarDeclaration *'s
- AggregateDeclaration *ad; // which aggregate this is for
+ Array vars; // parallel array of VarDeclaration *'s
+ AggregateDeclaration *ad; // which aggregate this is for
StructInitializer(Loc loc);
Initializer *syntaxCopy();
@@ -95,11 +95,11 @@ struct StructInitializer : Initializer
struct ArrayInitializer : Initializer
{
- Expressions index; // indices
- Initializers value; // of Initializer *'s
- unsigned dim; // length of array being initialized
- Type *type; // type that array will be used to initialize
- int sem; // !=0 if semantic() is run
+ Expressions index; // indices
+ Initializers value; // of Initializer *'s
+ unsigned dim; // length of array being initialized
+ Type *type; // type that array will be used to initialize
+ int sem; // !=0 if semantic() is run
ArrayInitializer(Loc loc);
Initializer *syntaxCopy();
@@ -112,7 +112,7 @@ struct ArrayInitializer : Initializer
#if IN_DMD
dt_t *toDt();
- dt_t *toDtBit(); // for bit arrays
+ dt_t *toDtBit(); // for bit arrays
#endif
ArrayInitializer *isArrayInitializer() { return this; }
diff --git a/dmd/inline.c b/dmd/inline.c
index fcfb7eaf..de8dca47 100644
--- a/dmd/inline.c
+++ b/dmd/inline.c
@@ -41,7 +41,7 @@ const int COST_MAX = 250;
int Statement::inlineCost(InlineCostState *ics)
{
- return COST_MAX; // default is we can't inline it
+ return COST_MAX; // default is we can't inline it
}
int ExpStatement::inlineCost(InlineCostState *ics)
@@ -53,13 +53,13 @@ int CompoundStatement::inlineCost(InlineCostState *ics)
{ int cost = 0;
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s)
- {
- cost += s->inlineCost(ics);
- if (cost >= COST_MAX)
- break;
- }
+ { Statement *s = (Statement *) statements->data[i];
+ if (s)
+ {
+ cost += s->inlineCost(ics);
+ if (cost >= COST_MAX)
+ break;
+ }
}
return cost;
}
@@ -68,13 +68,13 @@ int UnrolledLoopStatement::inlineCost(InlineCostState *ics)
{ int cost = 0;
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s)
- {
- cost += s->inlineCost(ics);
- if (cost >= COST_MAX)
- break;
- }
+ { Statement *s = (Statement *) statements->data[i];
+ if (s)
+ {
+ cost += s->inlineCost(ics);
+ if (cost >= COST_MAX)
+ break;
+ }
}
return cost;
}
@@ -88,37 +88,37 @@ int IfStatement::inlineCost(InlineCostState *ics)
* we cannot inline if a variable is declared.
*/
if (arg)
- return COST_MAX;
+ return COST_MAX;
#endif
cost = condition->inlineCost(ics);
#if !IN_LLVM
/* Specifically allow:
- * if (condition)
- * return exp1;
- * else
- * return exp2;
+ * if (condition)
+ * return exp1;
+ * else
+ * return exp2;
* Otherwise, we can't handle return statements nested in if's.
*/
if (elsebody && ifbody &&
- ifbody->isReturnStatement() &&
- elsebody->isReturnStatement())
+ ifbody->isReturnStatement() &&
+ elsebody->isReturnStatement())
{
- cost += ifbody->inlineCost(ics);
- cost += elsebody->inlineCost(ics);
- //printf("cost = %d\n", cost);
+ cost += ifbody->inlineCost(ics);
+ cost += elsebody->inlineCost(ics);
+ //printf("cost = %d\n", cost);
}
else
#endif
{
- ics->nested += 1;
- if (ifbody)
- cost += ifbody->inlineCost(ics);
- if (elsebody)
- cost += elsebody->inlineCost(ics);
- ics->nested -= 1;
+ ics->nested += 1;
+ if (ifbody)
+ cost += ifbody->inlineCost(ics);
+ if (elsebody)
+ cost += elsebody->inlineCost(ics);
+ ics->nested -= 1;
}
return cost;
}
@@ -128,7 +128,7 @@ int ReturnStatement::inlineCost(InlineCostState *ics)
#if !IN_LLVM
// Can't handle return statements nested in if's
if (ics->nested)
- return COST_MAX;
+ return COST_MAX;
#endif
return exp ? exp->inlineCost(ics) : 0;
}
@@ -140,12 +140,12 @@ int arrayInlineCost(InlineCostState *ics, Array *arguments)
if (arguments)
{
- for (int i = 0; i < arguments->dim; i++)
- { Expression *e = (Expression *)arguments->data[i];
+ for (int i = 0; i < arguments->dim; i++)
+ { Expression *e = (Expression *)arguments->data[i];
- if (e)
- cost += e->inlineCost(ics);
- }
+ if (e)
+ cost += e->inlineCost(ics);
+ }
}
return cost;
}
@@ -166,8 +166,8 @@ int ThisExp::inlineCost(InlineCostState *ics)
#if !IN_LLVM
FuncDeclaration *fd = ics->fd;
if (!ics->hdrscan)
- if (fd->isNested() || !ics->hasthis)
- return COST_MAX;
+ if (fd->isNested() || !ics->hasthis)
+ return COST_MAX;
#endif
return 1;
}
@@ -177,8 +177,8 @@ int SuperExp::inlineCost(InlineCostState *ics)
#if !IN_LLVM
FuncDeclaration *fd = ics->fd;
if (!ics->hdrscan)
- if (fd->isNested() || !ics->hasthis)
- return COST_MAX;
+ if (fd->isNested() || !ics->hasthis)
+ return COST_MAX;
#endif
return 1;
}
@@ -226,50 +226,50 @@ int DeclarationExp::inlineCost(InlineCostState *ics)
vd = declaration->isVarDeclaration();
if (vd)
{
- TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
- if (td)
- {
+ TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
+ if (td)
+ {
#if 1
- return COST_MAX; // finish DeclarationExp::doInline
+ return COST_MAX; // finish DeclarationExp::doInline
#else
- for (size_t i = 0; i < td->objects->dim; i++)
- { Object *o = (Object *)td->objects->data[i];
- if (o->dyncast() != DYNCAST_EXPRESSION)
- return COST_MAX;
- Expression *eo = (Expression *)o;
- if (eo->op != TOKdsymbol)
- return COST_MAX;
- }
- return td->objects->dim;
+ for (size_t i = 0; i < td->objects->dim; i++)
+ { Object *o = (Object *)td->objects->data[i];
+ if (o->dyncast() != DYNCAST_EXPRESSION)
+ return COST_MAX;
+ Expression *eo = (Expression *)o;
+ if (eo->op != TOKdsymbol)
+ return COST_MAX;
+ }
+ return td->objects->dim;
#endif
- }
+ }
// This breaks on LDC too, since nested static variables have internal
// linkage and thus can't be referenced from other objects.
- if (!ics->hdrscan && vd->isDataseg())
- return COST_MAX;
- cost += 1;
+ if (!ics->hdrscan && vd->isDataseg())
+ return COST_MAX;
+ cost += 1;
- // Scan initializer (vd->init)
- if (vd->init)
- {
- ExpInitializer *ie = vd->init->isExpInitializer();
+ // Scan initializer (vd->init)
+ if (vd->init)
+ {
+ ExpInitializer *ie = vd->init->isExpInitializer();
- if (ie)
- {
- cost += ie->exp->inlineCost(ics);
- }
- }
+ if (ie)
+ {
+ cost += ie->exp->inlineCost(ics);
+ }
+ }
}
// These can contain functions, which when copied, get output twice.
// These break on LDC too, since nested static variables and functions have
// internal linkage and thus can't be referenced from other objects.
if (declaration->isStructDeclaration() ||
- declaration->isClassDeclaration() ||
- declaration->isFuncDeclaration() ||
- declaration->isTypedefDeclaration() ||
- declaration->isTemplateMixin())
- return COST_MAX;
+ declaration->isClassDeclaration() ||
+ declaration->isFuncDeclaration() ||
+ declaration->isTypedefDeclaration() ||
+ declaration->isTemplateMixin())
+ return COST_MAX;
//printf("DeclarationExp::inlineCost('%s')\n", toChars());
return cost;
@@ -295,7 +295,7 @@ int CallExp::inlineCost(InlineCostState *ics)
// Bugzilla 3500: super.func() calls must be devirtualized, and the inliner
// can't handle that at present.
if (e1->op == TOKdotvar && ((DotVarExp *)e1)->e1->op == TOKsuper)
- return COST_MAX;
+ return COST_MAX;
return 1 + e1->inlineCost(ics) + arrayInlineCost(ics, arguments);
}
@@ -305,9 +305,9 @@ int SliceExp::inlineCost(InlineCostState *ics)
cost = 1 + e1->inlineCost(ics);
if (lwr)
- cost += lwr->inlineCost(ics);
+ cost += lwr->inlineCost(ics);
if (upr)
- cost += upr->inlineCost(ics);
+ cost += upr->inlineCost(ics);
return cost;
}
@@ -320,32 +320,32 @@ int ArrayExp::inlineCost(InlineCostState *ics)
int CondExp::inlineCost(InlineCostState *ics)
{
return 1 +
- e1->inlineCost(ics) +
- e2->inlineCost(ics) +
- econd->inlineCost(ics);
+ e1->inlineCost(ics) +
+ e2->inlineCost(ics) +
+ econd->inlineCost(ics);
}
/* ======================== Perform the inlining ============================== */
/* Inlining is done by:
- * o Converting to an Expression
- * o Copying the trees of the function to be inlined
- * o Renaming the variables
+ * o Converting to an Expression
+ * o Copying the trees of the function to be inlined
+ * o Renaming the variables
*/
struct InlineDoState
{
VarDeclaration *vthis;
- Array from; // old Dsymbols
- Array to; // parallel array of new Dsymbols
- Dsymbol *parent; // new parent
+ Array from; // old Dsymbols
+ Array to; // parallel array of new Dsymbols
+ Dsymbol *parent; // new parent
};
Expression *Statement::doInline(InlineDoState *ids)
{
assert(0);
- return NULL; // default is we can't inline it
+ return NULL; // default is we can't inline it
}
Expression *ExpStatement::doInline(InlineDoState *ids)
@@ -362,28 +362,28 @@ Expression *CompoundStatement::doInline(InlineDoState *ids)
//printf("CompoundStatement::doInline() %d\n", statements->dim);
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s)
- {
- Expression *e2 = s->doInline(ids);
- e = Expression::combine(e, e2);
- if (s->isReturnStatement())
- break;
+ { Statement *s = (Statement *) statements->data[i];
+ if (s)
+ {
+ Expression *e2 = s->doInline(ids);
+ e = Expression::combine(e, e2);
+ if (s->isReturnStatement())
+ break;
- /* Check for:
- * if (condition)
- * return exp1;
- * else
- * return exp2;
- */
- IfStatement *ifs = s->isIfStatement();
- if (ifs && ifs->elsebody && ifs->ifbody &&
- ifs->ifbody->isReturnStatement() &&
- ifs->elsebody->isReturnStatement()
- )
- break;
+ /* Check for:
+ * if (condition)
+ * return exp1;
+ * else
+ * return exp2;
+ */
+ IfStatement *ifs = s->isIfStatement();
+ if (ifs && ifs->elsebody && ifs->ifbody &&
+ ifs->ifbody->isReturnStatement() &&
+ ifs->elsebody->isReturnStatement()
+ )
+ break;
- }
+ }
}
return e;
}
@@ -394,14 +394,14 @@ Expression *UnrolledLoopStatement::doInline(InlineDoState *ids)
//printf("UnrolledLoopStatement::doInline() %d\n", statements->dim);
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s)
- {
- Expression *e2 = s->doInline(ids);
- e = Expression::combine(e, e2);
- if (s->isReturnStatement())
- break;
- }
+ { Statement *s = (Statement *) statements->data[i];
+ if (s)
+ {
+ Expression *e2 = s->doInline(ids);
+ e = Expression::combine(e, e2);
+ if (s->isReturnStatement())
+ break;
+ }
}
return e;
}
@@ -417,31 +417,31 @@ Expression *IfStatement::doInline(InlineDoState *ids)
econd = condition->doInline(ids);
assert(econd);
if (ifbody)
- e1 = ifbody->doInline(ids);
+ e1 = ifbody->doInline(ids);
else
- e1 = NULL;
+ e1 = NULL;
if (elsebody)
- e2 = elsebody->doInline(ids);
+ e2 = elsebody->doInline(ids);
else
- e2 = NULL;
+ e2 = NULL;
if (e1 && e2)
{
- e = new CondExp(econd->loc, econd, e1, e2);
- e->type = e1->type;
+ e = new CondExp(econd->loc, econd, e1, e2);
+ e->type = e1->type;
}
else if (e1)
{
- e = new AndAndExp(econd->loc, econd, e1);
- e->type = Type::tvoid;
+ e = new AndAndExp(econd->loc, econd, e1);
+ e->type = Type::tvoid;
}
else if (e2)
{
- e = new OrOrExp(econd->loc, econd, e2);
- e->type = Type::tvoid;
+ e = new OrOrExp(econd->loc, econd, e2);
+ e->type = Type::tvoid;
}
else
{
- e = econd;
+ e = econd;
}
return e;
}
@@ -463,18 +463,18 @@ Expressions *arrayExpressiondoInline(Expressions *a, InlineDoState *ids)
if (a)
{
- newa = new Expressions();
- newa->setDim(a->dim);
+ newa = new Expressions();
+ newa->setDim(a->dim);
- for (int i = 0; i < a->dim; i++)
- { Expression *e = (Expression *)a->data[i];
+ for (int i = 0; i < a->dim; i++)
+ { Expression *e = (Expression *)a->data[i];
- if (e)
- {
- e = e->doInline(ids);
- newa->data[i] = (void *)e;
- }
- }
+ if (e)
+ {
+ e = e->doInline(ids);
+ newa->data[i] = (void *)e;
+ }
+ }
}
return newa;
}
@@ -492,13 +492,13 @@ Expression *SymOffExp::doInline(InlineDoState *ids)
//printf("SymOffExp::doInline(%s)\n", toChars());
for (i = 0; i < ids->from.dim; i++)
{
- if (var == (Declaration *)ids->from.data[i])
- {
- SymOffExp *se = (SymOffExp *)copy();
+ if (var == (Declaration *)ids->from.data[i])
+ {
+ SymOffExp *se = (SymOffExp *)copy();
- se->var = (Declaration *)ids->to.data[i];
- return se;
- }
+ se->var = (Declaration *)ids->to.data[i];
+ return se;
+ }
}
return this;
}
@@ -510,13 +510,13 @@ Expression *VarExp::doInline(InlineDoState *ids)
//printf("VarExp::doInline(%s)\n", toChars());
for (i = 0; i < ids->from.dim; i++)
{
- if (var == (Declaration *)ids->from.data[i])
- {
- VarExp *ve = (VarExp *)copy();
+ if (var == (Declaration *)ids->from.data[i])
+ {
+ VarExp *ve = (VarExp *)copy();
- ve->var = (Declaration *)ids->to.data[i];
- return ve;
- }
+ ve->var = (Declaration *)ids->to.data[i];
+ return ve;
+ }
}
return this;
}
@@ -524,10 +524,10 @@ Expression *VarExp::doInline(InlineDoState *ids)
Expression *ThisExp::doInline(InlineDoState *ids)
{
//if (!ids->vthis)
- //error("no 'this' when inlining %s", ids->parent->toChars());
+ //error("no 'this' when inlining %s", ids->parent->toChars());
if (!ids->vthis)
{
- return this;
+ return this;
}
VarExp *ve = new VarExp(loc, ids->vthis);
@@ -553,50 +553,50 @@ Expression *DeclarationExp::doInline(InlineDoState *ids)
if (vd)
{
#if 0
- // Need to figure this out before inlining can work for tuples
- TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
- if (td)
- {
- for (size_t i = 0; i < td->objects->dim; i++)
- { DsymbolExp *se = (DsymbolExp *)td->objects->data[i];
- assert(se->op == TOKdsymbol);
- se->s;
- }
- return st->objects->dim;
- }
+ // Need to figure this out before inlining can work for tuples
+ TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
+ if (td)
+ {
+ for (size_t i = 0; i < td->objects->dim; i++)
+ { DsymbolExp *se = (DsymbolExp *)td->objects->data[i];
+ assert(se->op == TOKdsymbol);
+ se->s;
+ }
+ return st->objects->dim;
+ }
#endif
- if (vd->isStatic() || vd->isConst())
- ;
- else
- {
- VarDeclaration *vto;
+ if (vd->isStatic() || vd->isConst())
+ ;
+ else
+ {
+ VarDeclaration *vto;
- vto = new VarDeclaration(vd->loc, vd->type, vd->ident, vd->init);
- *vto = *vd;
- vto->parent = ids->parent;
+ vto = new VarDeclaration(vd->loc, vd->type, vd->ident, vd->init);
+ *vto = *vd;
+ vto->parent = ids->parent;
#if IN_DMD
- vto->csym = NULL;
- vto->isym = NULL;
+ vto->csym = NULL;
+ vto->isym = NULL;
#endif
- ids->from.push(vd);
- ids->to.push(vto);
+ ids->from.push(vd);
+ ids->to.push(vto);
- if (vd->init)
- {
- if (vd->init->isVoidInitializer())
- {
- vto->init = new VoidInitializer(vd->init->loc);
- }
- else
- {
- ExpInitializer *ie = vd->init->isExpInitializer();
- assert(ie);
- vto->init = new ExpInitializer(ie->loc, ie->exp->doInline(ids));
- }
- }
- de->declaration = (Dsymbol *) (void *)vto;
- }
+ if (vd->init)
+ {
+ if (vd->init->isVoidInitializer())
+ {
+ vto->init = new VoidInitializer(vd->init->loc);
+ }
+ else
+ {
+ ExpInitializer *ie = vd->init->isExpInitializer();
+ assert(ie);
+ vto->init = new ExpInitializer(ie->loc, ie->exp->doInline(ids));
+ }
+ }
+ de->declaration = (Dsymbol *) (void *)vto;
+ }
}
/* This needs work, like DeclarationExp::toElem(), if we are
* to handle TemplateMixin's. For now, we just don't inline them.
@@ -610,7 +610,7 @@ Expression *NewExp::doInline(InlineDoState *ids)
NewExp *ne = (NewExp *)copy();
if (thisexp)
- ne->thisexp = thisexp->doInline(ids);
+ ne->thisexp = thisexp->doInline(ids);
ne->newargs = arrayExpressiondoInline(ne->newargs, ids);
ne->arguments = arrayExpressiondoInline(ne->arguments, ids);
return ne;
@@ -630,7 +630,7 @@ Expression *AssertExp::doInline(InlineDoState *ids)
ae->e1 = e1->doInline(ids);
if (msg)
- ae->msg = msg->doInline(ids);
+ ae->msg = msg->doInline(ids);
return ae;
}
@@ -661,32 +661,32 @@ Expression *IndexExp::doInline(InlineDoState *ids)
are->e1 = e1->doInline(ids);
if (lengthVar)
- { //printf("lengthVar\n");
- VarDeclaration *vd = lengthVar;
- ExpInitializer *ie;
- ExpInitializer *ieto;
- VarDeclaration *vto;
+ { //printf("lengthVar\n");
+ VarDeclaration *vd = lengthVar;
+ ExpInitializer *ie;
+ ExpInitializer *ieto;
+ VarDeclaration *vto;
- vto = new VarDeclaration(vd->loc, vd->type, vd->ident, vd->init);
- *vto = *vd;
- vto->parent = ids->parent;
+ vto = new VarDeclaration(vd->loc, vd->type, vd->ident, vd->init);
+ *vto = *vd;
+ vto->parent = ids->parent;
#if IN_DMD
- vto->csym = NULL;
- vto->isym = NULL;
+ vto->csym = NULL;
+ vto->isym = NULL;
#endif
- ids->from.push(vd);
- ids->to.push(vto);
+ ids->from.push(vd);
+ ids->to.push(vto);
- if (vd->init)
- {
- ie = vd->init->isExpInitializer();
- assert(ie);
- ieto = new ExpInitializer(ie->loc, ie->exp->doInline(ids));
- vto->init = ieto;
- }
+ if (vd->init)
+ {
+ ie = vd->init->isExpInitializer();
+ assert(ie);
+ ieto = new ExpInitializer(ie->loc, ie->exp->doInline(ids));
+ vto->init = ieto;
+ }
- are->lengthVar = (VarDeclaration *) (void *)vto;
+ are->lengthVar = (VarDeclaration *) (void *)vto;
}
are->e2 = e2->doInline(ids);
return are;
@@ -700,37 +700,37 @@ Expression *SliceExp::doInline(InlineDoState *ids)
are->e1 = e1->doInline(ids);
if (lengthVar)
- { //printf("lengthVar\n");
- VarDeclaration *vd = lengthVar;
- ExpInitializer *ie;
- ExpInitializer *ieto;
- VarDeclaration *vto;
+ { //printf("lengthVar\n");
+ VarDeclaration *vd = lengthVar;
+ ExpInitializer *ie;
+ ExpInitializer *ieto;
+ VarDeclaration *vto;
- vto = new VarDeclaration(vd->loc, vd->type, vd->ident, vd->init);
- *vto = *vd;
- vto->parent = ids->parent;
+ vto = new VarDeclaration(vd->loc, vd->type, vd->ident, vd->init);
+ *vto = *vd;
+ vto->parent = ids->parent;
#if IN_DMD
- vto->csym = NULL;
- vto->isym = NULL;
+ vto->csym = NULL;
+ vto->isym = NULL;
#endif
- ids->from.push(vd);
- ids->to.push(vto);
+ ids->from.push(vd);
+ ids->to.push(vto);
- if (vd->init)
- {
- ie = vd->init->isExpInitializer();
- assert(ie);
- ieto = new ExpInitializer(ie->loc, ie->exp->doInline(ids));
- vto->init = ieto;
- }
+ if (vd->init)
+ {
+ ie = vd->init->isExpInitializer();
+ assert(ie);
+ ieto = new ExpInitializer(ie->loc, ie->exp->doInline(ids));
+ vto->init = ieto;
+ }
- are->lengthVar = (VarDeclaration *) (void *)vto;
+ are->lengthVar = (VarDeclaration *) (void *)vto;
}
if (lwr)
- are->lwr = lwr->doInline(ids);
+ are->lwr = lwr->doInline(ids);
if (upr)
- are->upr = upr->doInline(ids);
+ are->upr = upr->doInline(ids);
return are;
}
@@ -806,7 +806,7 @@ Expression *CondExp::doInline(InlineDoState *ids)
struct InlineScanState
{
- FuncDeclaration *fd; // function being scanned
+ FuncDeclaration *fd; // function being scanned
};
Statement *Statement::inlineScan(InlineScanState *iss)
@@ -820,16 +820,16 @@ Statement *ExpStatement::inlineScan(InlineScanState *iss)
printf("ExpStatement::inlineScan(%s)\n", toChars());
#endif
if (exp)
- exp = exp->inlineScan(iss);
+ exp = exp->inlineScan(iss);
return this;
}
Statement *CompoundStatement::inlineScan(InlineScanState *iss)
{
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s)
- statements->data[i] = (void *)s->inlineScan(iss);
+ { Statement *s = (Statement *) statements->data[i];
+ if (s)
+ statements->data[i] = (void *)s->inlineScan(iss);
}
return this;
}
@@ -837,9 +837,9 @@ Statement *CompoundStatement::inlineScan(InlineScanState *iss)
Statement *UnrolledLoopStatement::inlineScan(InlineScanState *iss)
{
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s)
- statements->data[i] = (void *)s->inlineScan(iss);
+ { Statement *s = (Statement *) statements->data[i];
+ if (s)
+ statements->data[i] = (void *)s->inlineScan(iss);
}
return this;
}
@@ -847,7 +847,7 @@ Statement *UnrolledLoopStatement::inlineScan(InlineScanState *iss)
Statement *ScopeStatement::inlineScan(InlineScanState *iss)
{
if (statement)
- statement = statement->inlineScan(iss);
+ statement = statement->inlineScan(iss);
return this;
}
@@ -870,13 +870,13 @@ Statement *DoStatement::inlineScan(InlineScanState *iss)
Statement *ForStatement::inlineScan(InlineScanState *iss)
{
if (init)
- init = init->inlineScan(iss);
+ init = init->inlineScan(iss);
if (condition)
- condition = condition->inlineScan(iss);
+ condition = condition->inlineScan(iss);
if (increment)
- increment = increment->inlineScan(iss);
+ increment = increment->inlineScan(iss);
if (body)
- body = body->inlineScan(iss);
+ body = body->inlineScan(iss);
return this;
}
@@ -885,7 +885,7 @@ Statement *ForeachStatement::inlineScan(InlineScanState *iss)
{
aggr = aggr->inlineScan(iss);
if (body)
- body = body->inlineScan(iss);
+ body = body->inlineScan(iss);
return this;
}
@@ -896,7 +896,7 @@ Statement *ForeachRangeStatement::inlineScan(InlineScanState *iss)
lwr = lwr->inlineScan(iss);
upr = upr->inlineScan(iss);
if (body)
- body = body->inlineScan(iss);
+ body = body->inlineScan(iss);
return this;
}
#endif
@@ -906,9 +906,9 @@ Statement *IfStatement::inlineScan(InlineScanState *iss)
{
condition = condition->inlineScan(iss);
if (ifbody)
- ifbody = ifbody->inlineScan(iss);
+ ifbody = ifbody->inlineScan(iss);
if (elsebody)
- elsebody = elsebody->inlineScan(iss);
+ elsebody = elsebody->inlineScan(iss);
return this;
}
@@ -919,15 +919,15 @@ Statement *SwitchStatement::inlineScan(InlineScanState *iss)
condition = condition->inlineScan(iss);
body = body ? body->inlineScan(iss) : NULL;
if (sdefault)
- sdefault = (DefaultStatement *)sdefault->inlineScan(iss);
+ sdefault = (DefaultStatement *)sdefault->inlineScan(iss);
if (cases)
{
- for (int i = 0; i < cases->dim; i++)
- { Statement *s;
+ for (int i = 0; i < cases->dim; i++)
+ { Statement *s;
- s = (Statement *) cases->data[i];
- cases->data[i] = (void *)s->inlineScan(iss);
- }
+ s = (Statement *) cases->data[i];
+ cases->data[i] = (void *)s->inlineScan(iss);
+ }
}
return this;
}
@@ -938,7 +938,7 @@ Statement *CaseStatement::inlineScan(InlineScanState *iss)
//printf("CaseStatement::inlineScan()\n");
exp = exp->inlineScan(iss);
if (statement)
- statement = statement->inlineScan(iss);
+ statement = statement->inlineScan(iss);
return this;
}
@@ -946,7 +946,7 @@ Statement *CaseStatement::inlineScan(InlineScanState *iss)
Statement *DefaultStatement::inlineScan(InlineScanState *iss)
{
if (statement)
- statement = statement->inlineScan(iss);
+ statement = statement->inlineScan(iss);
return this;
}
@@ -956,7 +956,7 @@ Statement *ReturnStatement::inlineScan(InlineScanState *iss)
//printf("ReturnStatement::inlineScan()\n");
if (exp)
{
- exp = exp->inlineScan(iss);
+ exp = exp->inlineScan(iss);
}
return this;
}
@@ -965,9 +965,9 @@ Statement *ReturnStatement::inlineScan(InlineScanState *iss)
Statement *SynchronizedStatement::inlineScan(InlineScanState *iss)
{
if (exp)
- exp = exp->inlineScan(iss);
+ exp = exp->inlineScan(iss);
if (body)
- body = body->inlineScan(iss);
+ body = body->inlineScan(iss);
return this;
}
@@ -975,9 +975,9 @@ Statement *SynchronizedStatement::inlineScan(InlineScanState *iss)
Statement *WithStatement::inlineScan(InlineScanState *iss)
{
if (exp)
- exp = exp->inlineScan(iss);
+ exp = exp->inlineScan(iss);
if (body)
- body = body->inlineScan(iss);
+ body = body->inlineScan(iss);
return this;
}
@@ -985,15 +985,15 @@ Statement *WithStatement::inlineScan(InlineScanState *iss)
Statement *TryCatchStatement::inlineScan(InlineScanState *iss)
{
if (body)
- body = body->inlineScan(iss);
+ body = body->inlineScan(iss);
if (catches)
{
- for (int i = 0; i < catches->dim; i++)
- { Catch *c = (Catch *)catches->data[i];
+ for (int i = 0; i < catches->dim; i++)
+ { Catch *c = (Catch *)catches->data[i];
- if (c->handler)
- c->handler = c->handler->inlineScan(iss);
- }
+ if (c->handler)
+ c->handler = c->handler->inlineScan(iss);
+ }
}
return this;
}
@@ -1002,9 +1002,9 @@ Statement *TryCatchStatement::inlineScan(InlineScanState *iss)
Statement *TryFinallyStatement::inlineScan(InlineScanState *iss)
{
if (body)
- body = body->inlineScan(iss);
+ body = body->inlineScan(iss);
if (finalbody)
- finalbody = finalbody->inlineScan(iss);
+ finalbody = finalbody->inlineScan(iss);
return this;
}
@@ -1012,7 +1012,7 @@ Statement *TryFinallyStatement::inlineScan(InlineScanState *iss)
Statement *ThrowStatement::inlineScan(InlineScanState *iss)
{
if (exp)
- exp = exp->inlineScan(iss);
+ exp = exp->inlineScan(iss);
return this;
}
@@ -1020,7 +1020,7 @@ Statement *ThrowStatement::inlineScan(InlineScanState *iss)
Statement *VolatileStatement::inlineScan(InlineScanState *iss)
{
if (statement)
- statement = statement->inlineScan(iss);
+ statement = statement->inlineScan(iss);
return this;
}
@@ -1028,7 +1028,7 @@ Statement *VolatileStatement::inlineScan(InlineScanState *iss)
Statement *LabelStatement::inlineScan(InlineScanState *iss)
{
if (statement)
- statement = statement->inlineScan(iss);
+ statement = statement->inlineScan(iss);
return this;
}
@@ -1038,15 +1038,15 @@ void arrayInlineScan(InlineScanState *iss, Array *arguments)
{
if (arguments)
{
- for (int i = 0; i < arguments->dim; i++)
- { Expression *e = (Expression *)arguments->data[i];
+ for (int i = 0; i < arguments->dim; i++)
+ { Expression *e = (Expression *)arguments->data[i];
- if (e)
- {
- e = e->inlineScan(iss);
- arguments->data[i] = (void *)e;
- }
- }
+ if (e)
+ {
+ e = e->inlineScan(iss);
+ arguments->data[i] = (void *)e;
+ }
+ }
}
}
@@ -1060,53 +1060,53 @@ void scanVar(Dsymbol *s, InlineScanState *iss)
VarDeclaration *vd = s->isVarDeclaration();
if (vd)
{
- TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
- if (td)
- {
- for (size_t i = 0; i < td->objects->dim; i++)
- { DsymbolExp *se = (DsymbolExp *)td->objects->data[i];
- assert(se->op == TOKdsymbol);
- scanVar(se->s, iss);
- }
- }
- else
- {
- // Scan initializer (vd->init)
- if (vd->init)
- {
- ExpInitializer *ie = vd->init->isExpInitializer();
+ TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
+ if (td)
+ {
+ for (size_t i = 0; i < td->objects->dim; i++)
+ { DsymbolExp *se = (DsymbolExp *)td->objects->data[i];
+ assert(se->op == TOKdsymbol);
+ scanVar(se->s, iss);
+ }
+ }
+ else
+ {
+ // Scan initializer (vd->init)
+ if (vd->init)
+ {
+ ExpInitializer *ie = vd->init->isExpInitializer();
- if (ie)
- {
+ if (ie)
+ {
#if DMDV2
- if (vd->type)
- { Type *tb = vd->type->toBasetype();
- if (tb->ty == Tstruct)
- { StructDeclaration *sd = ((TypeStruct *)tb)->sym;
- if (sd->cpctor)
- { /* The problem here is that if the initializer is a
- * function call that returns a struct S with a cpctor:
- * S s = foo();
- * the postblit is done by the return statement in foo()
- * in s2ir.c, the intermediate code generator.
- * But, if foo() is inlined and now the code looks like:
- * S s = x;
- * the postblit is not there, because such assignments
- * are rewritten as s.cpctor(&x) by the front end.
- * So, the inlining won't get the postblit called.
- * Work around by not inlining these cases.
- * A proper fix would be to move all the postblit
- * additions to the front end.
- */
- return;
- }
- }
- }
+ if (vd->type)
+ { Type *tb = vd->type->toBasetype();
+ if (tb->ty == Tstruct)
+ { StructDeclaration *sd = ((TypeStruct *)tb)->sym;
+ if (sd->cpctor)
+ { /* The problem here is that if the initializer is a
+ * function call that returns a struct S with a cpctor:
+ * S s = foo();
+ * the postblit is done by the return statement in foo()
+ * in s2ir.c, the intermediate code generator.
+ * But, if foo() is inlined and now the code looks like:
+ * S s = x;
+ * the postblit is not there, because such assignments
+ * are rewritten as s.cpctor(&x) by the front end.
+ * So, the inlining won't get the postblit called.
+ * Work around by not inlining these cases.
+ * A proper fix would be to move all the postblit
+ * additions to the front end.
+ */
+ return;
+ }
+ }
+ }
#endif
- ie->exp = ie->exp->inlineScan(iss);
- }
- }
- }
+ ie->exp = ie->exp->inlineScan(iss);
+ }
+ }
+ }
}
}
@@ -1127,7 +1127,7 @@ Expression *AssertExp::inlineScan(InlineScanState *iss)
{
e1 = e1->inlineScan(iss);
if (msg)
- msg = msg->inlineScan(iss);
+ msg = msg->inlineScan(iss);
return this;
}
@@ -1148,33 +1148,33 @@ Expression *CallExp::inlineScan(InlineScanState *iss)
if (e1->op == TOKvar)
{
- VarExp *ve = (VarExp *)e1;
- FuncDeclaration *fd = ve->var->isFuncDeclaration();
+ VarExp *ve = (VarExp *)e1;
+ FuncDeclaration *fd = ve->var->isFuncDeclaration();
- if (fd && fd != iss->fd && fd->canInline(0))
- {
- e = fd->doInline(iss, NULL, arguments);
- }
+ if (fd && fd != iss->fd && fd->canInline(0))
+ {
+ e = fd->doInline(iss, NULL, arguments);
+ }
}
else if (e1->op == TOKdotvar)
{
- DotVarExp *dve = (DotVarExp *)e1;
- FuncDeclaration *fd = dve->var->isFuncDeclaration();
+ DotVarExp *dve = (DotVarExp *)e1;
+ FuncDeclaration *fd = dve->var->isFuncDeclaration();
- if (fd && fd != iss->fd && fd->canInline(1))
- {
- if (dve->e1->op == TOKcall &&
- dve->e1->type->toBasetype()->ty == Tstruct)
- {
- /* To create ethis, we'll need to take the address
- * of dve->e1, but this won't work if dve->e1 is
- * a function call.
- */
- ;
- }
- else
- e = fd->doInline(iss, dve->e1, arguments);
- }
+ if (fd && fd != iss->fd && fd->canInline(1))
+ {
+ if (dve->e1->op == TOKcall &&
+ dve->e1->type->toBasetype()->ty == Tstruct)
+ {
+ /* To create ethis, we'll need to take the address
+ * of dve->e1, but this won't work if dve->e1 is
+ * a function call.
+ */
+ ;
+ }
+ else
+ e = fd->doInline(iss, dve->e1, arguments);
+ }
}
return e;
@@ -1185,9 +1185,9 @@ Expression *SliceExp::inlineScan(InlineScanState *iss)
{
e1 = e1->inlineScan(iss);
if (lwr)
- lwr = lwr->inlineScan(iss);
+ lwr = lwr->inlineScan(iss);
if (upr)
- upr = upr->inlineScan(iss);
+ upr = upr->inlineScan(iss);
return this;
}
@@ -1266,9 +1266,9 @@ void FuncDeclaration::inlineScan()
iss.fd = this;
if (fbody)
{
- inlineNest++;
- fbody = fbody->inlineScan(&iss);
- inlineNest--;
+ inlineNest++;
+ fbody = fbody->inlineScan(&iss);
+ inlineNest--;
}
}
@@ -1284,88 +1284,88 @@ int FuncDeclaration::canInline(int hasthis, int hdrscan)
#endif
if (needThis() && !hasthis)
- return 0;
+ return 0;
if (inlineNest || (semanticRun < PASSsemantic3 && !hdrscan))
{
#if CANINLINE_LOG
- printf("\t1: no, inlineNest = %d, semanticRun = %d\n", inlineNest, semanticRun);
+ printf("\t1: no, inlineNest = %d, semanticRun = %d\n", inlineNest, semanticRun);
#endif
- return 0;
+ return 0;
}
switch (inlineStatus)
{
- case ILSyes:
+ case ILSyes:
#if CANINLINE_LOG
- printf("\t1: yes %s\n", toChars());
+ printf("\t1: yes %s\n", toChars());
#endif
- return 1;
+ return 1;
- case ILSno:
+ case ILSno:
#if CANINLINE_LOG
- printf("\t1: no %s\n", toChars());
+ printf("\t1: no %s\n", toChars());
#endif
- return 0;
+ return 0;
- case ILSuninitialized:
- break;
+ case ILSuninitialized:
+ break;
- default:
- assert(0);
+ default:
+ assert(0);
}
if (type)
- { assert(type->ty == Tfunction);
- TypeFunction *tf = (TypeFunction *)(type);
+ { assert(type->ty == Tfunction);
+ TypeFunction *tf = (TypeFunction *)(type);
#if IN_LLVM
// LDC: Only extern(C) varargs count.
if (tf->linkage != LINKd)
#endif
- if (tf->varargs == 1) // no variadic parameter lists
- goto Lno;
+ if (tf->varargs == 1) // no variadic parameter lists
+ goto Lno;
- /* Don't inline a function that returns non-void, but has
- * no return expression.
- */
- if (tf->next && tf->next->ty != Tvoid &&
- !(hasReturnExp & 1) &&
- !hdrscan)
- goto Lno;
+ /* Don't inline a function that returns non-void, but has
+ * no return expression.
+ */
+ if (tf->next && tf->next->ty != Tvoid &&
+ !(hasReturnExp & 1) &&
+ !hdrscan)
+ goto Lno;
}
#if !IN_LLVM
// LDC: Only extern(C) varargs count, and ctors use extern(D).
else
- { CtorDeclaration *ctor = isCtorDeclaration();
+ { CtorDeclaration *ctor = isCtorDeclaration();
- if (ctor && ctor->varargs == 1)
- goto Lno;
+ if (ctor && ctor->varargs == 1)
+ goto Lno;
}
#endif
if (
- !fbody ||
- !hdrscan &&
- (
+ !fbody ||
+ !hdrscan &&
+ (
#if 0
- isCtorDeclaration() || // cannot because need to convert:
- // return;
- // to:
- // return this;
+ isCtorDeclaration() || // cannot because need to convert:
+ // return;
+ // to:
+ // return this;
#endif
- isSynchronized() ||
- isImportedSymbol() ||
+ isSynchronized() ||
+ isImportedSymbol() ||
#if !IN_LLVM
#if DMDV2
- closureVars.dim || // no nested references to this frame
+ closureVars.dim || // no nested references to this frame
#else
- nestedFrameRef || // no nested references to this frame
+ nestedFrameRef || // no nested references to this frame
#endif
#endif // !IN_LLVM
- (isVirtual() && !isFinal())
+ (isVirtual() && !isFinal())
))
{
- goto Lno;
+ goto Lno;
}
#if !IN_LLVM
@@ -1374,12 +1374,12 @@ int FuncDeclaration::canInline(int hasthis, int hdrscan)
*/
if (parameters)
{
- for (int i = 0; i < parameters->dim; i++)
- {
- VarDeclaration *v = (VarDeclaration *)parameters->data[i];
- if (v->isOut() || v->isRef() || v->type->toBasetype()->ty == Tsarray)
- goto Lno;
- }
+ for (int i = 0; i < parameters->dim; i++)
+ {
+ VarDeclaration *v = (VarDeclaration *)parameters->data[i];
+ if (v->isOut() || v->isRef() || v->type->toBasetype()->ty == Tsarray)
+ goto Lno;
+ }
}
#endif
@@ -1392,16 +1392,16 @@ int FuncDeclaration::canInline(int hasthis, int hdrscan)
printf("cost = %d\n", cost);
#endif
if (cost >= COST_MAX)
- goto Lno;
+ goto Lno;
#if !IN_LLVM
if (!hdrscan) // Don't scan recursively for header content scan
- inlineScan();
+ inlineScan();
#endif
Lyes:
if (!hdrscan) // Don't modify inlineStatus for header content scan
- inlineStatus = ILSyes;
+ inlineStatus = ILSyes;
#if CANINLINE_LOG
printf("\t2: yes %s\n", toChars());
#endif
@@ -1409,7 +1409,7 @@ Lyes:
Lno:
if (!hdrscan) // Don't modify inlineStatus for header content scan
- inlineStatus = ILSno;
+ inlineStatus = ILSno;
#if CANINLINE_LOG
printf("\t2: no %s\n", toChars());
#endif
@@ -1432,99 +1432,99 @@ Expression *FuncDeclaration::doInline(InlineScanState *iss, Expression *ethis, A
// Set up vthis
if (ethis)
{
- VarDeclaration *vthis;
- ExpInitializer *ei;
- VarExp *ve;
+ VarDeclaration *vthis;
+ ExpInitializer *ei;
+ VarExp *ve;
#if STRUCTTHISREF
- if (ethis->type->ty == Tpointer)
- { Type *t = ethis->type->nextOf();
- ethis = new PtrExp(ethis->loc, ethis);
- ethis->type = t;
- }
- ei = new ExpInitializer(ethis->loc, ethis);
+ if (ethis->type->ty == Tpointer)
+ { Type *t = ethis->type->nextOf();
+ ethis = new PtrExp(ethis->loc, ethis);
+ ethis->type = t;
+ }
+ ei = new ExpInitializer(ethis->loc, ethis);
- vthis = new VarDeclaration(ethis->loc, ethis->type, Id::This, ei);
- if (ethis->type->ty != Tclass)
- vthis->storage_class = STCref;
- else
- vthis->storage_class = STCin;
+ vthis = new VarDeclaration(ethis->loc, ethis->type, Id::This, ei);
+ if (ethis->type->ty != Tclass)
+ vthis->storage_class = STCref;
+ else
+ vthis->storage_class = STCin;
#else
- if (ethis->type->ty != Tclass && ethis->type->ty != Tpointer)
- {
- ethis = ethis->addressOf(NULL);
- }
+ if (ethis->type->ty != Tclass && ethis->type->ty != Tpointer)
+ {
+ ethis = ethis->addressOf(NULL);
+ }
- ei = new ExpInitializer(ethis->loc, ethis);
+ ei = new ExpInitializer(ethis->loc, ethis);
- vthis = new VarDeclaration(ethis->loc, ethis->type, Id::This, ei);
- vthis->storage_class = STCin;
+ vthis = new VarDeclaration(ethis->loc, ethis->type, Id::This, ei);
+ vthis->storage_class = STCin;
#endif
- vthis->linkage = LINKd;
- vthis->parent = iss->fd;
+ vthis->linkage = LINKd;
+ vthis->parent = iss->fd;
- ve = new VarExp(vthis->loc, vthis);
- ve->type = vthis->type;
+ ve = new VarExp(vthis->loc, vthis);
+ ve->type = vthis->type;
- ei->exp = new AssignExp(vthis->loc, ve, ethis);
- ei->exp->type = ve->type;
+ ei->exp = new AssignExp(vthis->loc, ve, ethis);
+ ei->exp->type = ve->type;
#if STRUCTTHISREF
- if (ethis->type->ty != Tclass)
- { /* This is a reference initialization, not a simple assignment.
- */
- ei->exp->op = TOKconstruct;
- }
+ if (ethis->type->ty != Tclass)
+ { /* This is a reference initialization, not a simple assignment.
+ */
+ ei->exp->op = TOKconstruct;
+ }
#endif
- ids.vthis = vthis;
+ ids.vthis = vthis;
}
// Set up parameters
if (ethis)
{
- e = new DeclarationExp(0, ids.vthis);
- e->type = Type::tvoid;
+ e = new DeclarationExp(0, ids.vthis);
+ e->type = Type::tvoid;
}
if (arguments && arguments->dim)
{
- assert(parameters->dim == arguments->dim);
+ assert(parameters->dim == arguments->dim);
- for (int i = 0; i < arguments->dim; i++)
- {
- VarDeclaration *vfrom = (VarDeclaration *)parameters->data[i];
- VarDeclaration *vto;
- Expression *arg = (Expression *)arguments->data[i];
- ExpInitializer *ei;
- VarExp *ve;
+ for (int i = 0; i < arguments->dim; i++)
+ {
+ VarDeclaration *vfrom = (VarDeclaration *)parameters->data[i];
+ VarDeclaration *vto;
+ Expression *arg = (Expression *)arguments->data[i];
+ ExpInitializer *ei;
+ VarExp *ve;
- ei = new ExpInitializer(arg->loc, arg);
+ ei = new ExpInitializer(arg->loc, arg);
- vto = new VarDeclaration(vfrom->loc, vfrom->type, vfrom->ident, ei);
- vto->storage_class |= vfrom->storage_class & (STCin | STCout | STClazy | STCref);
- vto->linkage = vfrom->linkage;
- vto->parent = iss->fd;
- //printf("vto = '%s', vto->storage_class = x%x\n", vto->toChars(), vto->storage_class);
- //printf("vto->parent = '%s'\n", iss->fd->toChars());
+ vto = new VarDeclaration(vfrom->loc, vfrom->type, vfrom->ident, ei);
+ vto->storage_class |= vfrom->storage_class & (STCin | STCout | STClazy | STCref);
+ vto->linkage = vfrom->linkage;
+ vto->parent = iss->fd;
+ //printf("vto = '%s', vto->storage_class = x%x\n", vto->toChars(), vto->storage_class);
+ //printf("vto->parent = '%s'\n", iss->fd->toChars());
- ve = new VarExp(vto->loc, vto);
- //ve->type = vto->type;
- ve->type = arg->type;
+ ve = new VarExp(vto->loc, vto);
+ //ve->type = vto->type;
+ ve->type = arg->type;
- ei->exp = new AssignExp(vto->loc, ve, arg);
- ei->exp->type = ve->type;
+ ei->exp = new AssignExp(vto->loc, ve, arg);
+ ei->exp->type = ve->type;
//ve->type->print();
//arg->type->print();
//ei->exp->print();
- ids.from.push(vfrom);
- ids.to.push(vto);
+ ids.from.push(vfrom);
+ ids.to.push(vto);
- de = new DeclarationExp(0, vto);
- de->type = Type::tvoid;
+ de = new DeclarationExp(0, vto);
+ de->type = Type::tvoid;
- e = Expression::combine(e, de);
- }
+ e = Expression::combine(e, de);
+ }
}
inlineNest++;
diff --git a/dmd/interpret.c b/dmd/interpret.c
index efd65f6a..47d7b0d3 100644
--- a/dmd/interpret.c
+++ b/dmd/interpret.c
@@ -25,16 +25,16 @@
#include "aggregate.h"
#include "id.h"
-#define LOG 0
+#define LOG 0
struct InterState
{
- InterState *caller; // calling function's InterState
- FuncDeclaration *fd; // function being interpreted
- Dsymbols vars; // variables used in this function
- Statement *start; // if !=NULL, start execution at this statement
- Statement *gotoTarget; // target of EXP_GOTO_INTERPRET result
- Expression *localThis; // value of 'this', or NULL if none
+ InterState *caller; // calling function's InterState
+ FuncDeclaration *fd; // function being interpreted
+ Dsymbols vars; // variables used in this function
+ Statement *start; // if !=NULL, start execution at this statement
+ Statement *gotoTarget; // target of EXP_GOTO_INTERPRET result
+ Expression *localThis; // value of 'this', or NULL if none
bool awaitingLvalueReturn; // Support for ref return values:
// Any return to this function should return an lvalue.
InterState();
@@ -59,9 +59,9 @@ Expression * resolveReferences(Expression *e, Expression *thisval, bool *isRefer
/*************************************
* Attempt to interpret a function given the arguments.
* Input:
- * istate state for calling function (NULL if none)
+ * istate state for calling function (NULL if none)
* arguments function arguments
- * thisarg 'this', if a needThis() function, NULL if not.
+ * thisarg 'this', if a needThis() function, NULL if not.
*
* Return result expression if successful, NULL if not.
*/
@@ -73,61 +73,61 @@ Expression *FuncDeclaration::interpret(InterState *istate, Expressions *argument
printf("cantInterpret = %d, semanticRun = %d\n", cantInterpret, semanticRun);
#endif
if (global.errors)
- return NULL;
+ return NULL;
#if DMDV2
if (thisarg &&
- (!arguments || arguments->dim == 0))
+ (!arguments || arguments->dim == 0))
{
- if (ident == Id::length)
- return interpret_length(istate, thisarg);
- else if (ident == Id::keys)
- return interpret_keys(istate, thisarg, this);
- else if (ident == Id::values)
- return interpret_values(istate, thisarg, this);
+ if (ident == Id::length)
+ return interpret_length(istate, thisarg);
+ else if (ident == Id::keys)
+ return interpret_keys(istate, thisarg, this);
+ else if (ident == Id::values)
+ return interpret_values(istate, thisarg, this);
}
#endif
if (cantInterpret || semanticRun == PASSsemantic3)
- return NULL;
+ return NULL;
if (!fbody)
- { cantInterpret = 1;
- error("cannot be interpreted at compile time,"
- " because it has no available source code");
- return NULL;
+ { cantInterpret = 1;
+ error("cannot be interpreted at compile time,"
+ " because it has no available source code");
+ return NULL;
}
if (semanticRun < PASSsemantic3 && scope)
{
- semantic3(scope);
- if (global.errors) // if errors compiling this function
- return NULL;
+ semantic3(scope);
+ if (global.errors) // if errors compiling this function
+ return NULL;
}
if (semanticRun < PASSsemantic3done)
- return NULL;
+ return NULL;
Type *tb = type->toBasetype();
assert(tb->ty == Tfunction);
TypeFunction *tf = (TypeFunction *)tb;
Type *tret = tf->next->toBasetype();
if (tf->varargs && arguments &&
- ((parameters && arguments->dim != parameters->dim) || (!parameters && arguments->dim)))
- { cantInterpret = 1;
- error("C-style variadic functions are not yet implemented in CTFE");
- return NULL;
+ ((parameters && arguments->dim != parameters->dim) || (!parameters && arguments->dim)))
+ { cantInterpret = 1;
+ error("C-style variadic functions are not yet implemented in CTFE");
+ return NULL;
}
-
+
// Ensure there are no lazy parameters
if (tf->parameters)
- { size_t dim = Parameter::dim(tf->parameters);
- for (size_t i = 0; i < dim; i++)
- { Parameter *arg = Parameter::getNth(tf->parameters, i);
- if (arg->storageClass & STClazy)
- { cantInterpret = 1;
- return NULL;
- }
- }
+ { size_t dim = Parameter::dim(tf->parameters);
+ for (size_t i = 0; i < dim; i++)
+ { Parameter *arg = Parameter::getNth(tf->parameters, i);
+ if (arg->storageClass & STClazy)
+ { cantInterpret = 1;
+ return NULL;
+ }
+ }
}
InterState istatex;
@@ -135,101 +135,101 @@ Expression *FuncDeclaration::interpret(InterState *istate, Expressions *argument
istatex.fd = this;
istatex.localThis = thisarg;
- Expressions vsave; // place to save previous parameter values
+ Expressions vsave; // place to save previous parameter values
size_t dim = 0;
if (needThis() && !thisarg)
- { cantInterpret = 1;
- // error, no this. Prevent segfault.
- error("need 'this' to access member %s", toChars());
- return NULL;
+ { cantInterpret = 1;
+ // error, no this. Prevent segfault.
+ error("need 'this' to access member %s", toChars());
+ return NULL;
}
if (arguments)
{
- dim = arguments->dim;
- assert(!dim || (parameters && (parameters->dim == dim)));
- vsave.setDim(dim);
+ dim = arguments->dim;
+ assert(!dim || (parameters && (parameters->dim == dim)));
+ vsave.setDim(dim);
- /* Evaluate all the arguments to the function,
- * store the results in eargs[]
- */
- Expressions eargs;
- eargs.setDim(dim);
+ /* Evaluate all the arguments to the function,
+ * store the results in eargs[]
+ */
+ Expressions eargs;
+ eargs.setDim(dim);
- for (size_t i = 0; i < dim; i++)
- { Expression *earg = (Expression *)arguments->data[i];
- Parameter *arg = Parameter::getNth(tf->parameters, i);
+ for (size_t i = 0; i < dim; i++)
+ { Expression *earg = (Expression *)arguments->data[i];
+ Parameter *arg = Parameter::getNth(tf->parameters, i);
- if (arg->storageClass & (STCout | STCref | STClazy))
- {
- }
- else
- { /* Value parameters
- */
- Type *ta = arg->type->toBasetype();
- if (ta->ty == Tsarray && earg->op == TOKaddress)
- {
- /* Static arrays are passed by a simple pointer.
- * Skip past this to get at the actual arg.
- */
- earg = ((AddrExp *)earg)->e1;
- }
- earg = earg->interpret(istate ? istate : &istatex);
- if (earg == EXP_CANT_INTERPRET)
- { cantInterpret = 1;
- return NULL;
- }
- }
- eargs.data[i] = earg;
- }
+ if (arg->storageClass & (STCout | STCref | STClazy))
+ {
+ }
+ else
+ { /* Value parameters
+ */
+ Type *ta = arg->type->toBasetype();
+ if (ta->ty == Tsarray && earg->op == TOKaddress)
+ {
+ /* Static arrays are passed by a simple pointer.
+ * Skip past this to get at the actual arg.
+ */
+ earg = ((AddrExp *)earg)->e1;
+ }
+ earg = earg->interpret(istate ? istate : &istatex);
+ if (earg == EXP_CANT_INTERPRET)
+ { cantInterpret = 1;
+ return NULL;
+ }
+ }
+ eargs.data[i] = earg;
+ }
- for (size_t i = 0; i < dim; i++)
- { Expression *earg = (Expression *)eargs.data[i];
- Parameter *arg = Parameter::getNth(tf->parameters, i);
- VarDeclaration *v = (VarDeclaration *)parameters->data[i];
- vsave.data[i] = v->value;
+ for (size_t i = 0; i < dim; i++)
+ { Expression *earg = (Expression *)eargs.data[i];
+ Parameter *arg = Parameter::getNth(tf->parameters, i);
+ VarDeclaration *v = (VarDeclaration *)parameters->data[i];
+ vsave.data[i] = v->value;
#if LOG
- printf("arg[%d] = %s\n", i, earg->toChars());
+ printf("arg[%d] = %s\n", i, earg->toChars());
#endif
- if (arg->storageClass & (STCout | STCref) && earg->op==TOKvar)
- {
- VarExp *ve = (VarExp *)earg;
- VarDeclaration *v2 = ve->var->isVarDeclaration();
- if (!v2)
- { cantInterpret = 1;
- return NULL;
- }
- v->value = earg;
- /* Don't restore the value of v2 upon function return
- */
- assert(istate);
- for (size_t i = 0; i < istate->vars.dim; i++)
- { VarDeclaration *vx = (VarDeclaration *)istate->vars.data[i];
- if (vx == v2)
- { istate->vars.data[i] = NULL;
- break;
- }
- }
- }
- else
- { // Value parameters and non-trivial references
- v->value = earg;
- }
+ if (arg->storageClass & (STCout | STCref) && earg->op==TOKvar)
+ {
+ VarExp *ve = (VarExp *)earg;
+ VarDeclaration *v2 = ve->var->isVarDeclaration();
+ if (!v2)
+ { cantInterpret = 1;
+ return NULL;
+ }
+ v->value = earg;
+ /* Don't restore the value of v2 upon function return
+ */
+ assert(istate);
+ for (size_t i = 0; i < istate->vars.dim; i++)
+ { VarDeclaration *vx = (VarDeclaration *)istate->vars.data[i];
+ if (vx == v2)
+ { istate->vars.data[i] = NULL;
+ break;
+ }
+ }
+ }
+ else
+ { // Value parameters and non-trivial references
+ v->value = earg;
+ }
#if LOG
- printf("interpreted arg[%d] = %s\n", i, earg->toChars());
+ printf("interpreted arg[%d] = %s\n", i, earg->toChars());
#endif
- }
+ }
}
// Don't restore the value of 'this' upon function return
if (needThis() && thisarg->op == TOKvar && istate)
{
- VarDeclaration *thisvar = ((VarExp *)(thisarg))->var->isVarDeclaration();
- for (size_t i = 0; i < istate->vars.dim; i++)
- { VarDeclaration *v = (VarDeclaration *)istate->vars.data[i];
- if (v == thisvar)
- { istate->vars.data[i] = NULL;
- break;
- }
- }
+ VarDeclaration *thisvar = ((VarExp *)(thisarg))->var->isVarDeclaration();
+ for (size_t i = 0; i < istate->vars.dim; i++)
+ { VarDeclaration *v = (VarDeclaration *)istate->vars.data[i];
+ if (v == thisvar)
+ { istate->vars.data[i] = NULL;
+ break;
+ }
+ }
}
/* Save the values of the local variables used
@@ -237,84 +237,84 @@ Expression *FuncDeclaration::interpret(InterState *istate, Expressions *argument
Expressions valueSaves;
if (istate && !isNested())
{
- //printf("saving local variables...\n");
- valueSaves.setDim(istate->vars.dim);
- for (size_t i = 0; i < istate->vars.dim; i++)
- { VarDeclaration *v = (VarDeclaration *)istate->vars.data[i];
- if (v)
- {
- //printf("\tsaving [%d] %s = %s\n", i, v->toChars(), v->value ? v->value->toChars() : "");
- valueSaves.data[i] = v->value;
- v->value = NULL;
- }
- }
+ //printf("saving local variables...\n");
+ valueSaves.setDim(istate->vars.dim);
+ for (size_t i = 0; i < istate->vars.dim; i++)
+ { VarDeclaration *v = (VarDeclaration *)istate->vars.data[i];
+ if (v)
+ {
+ //printf("\tsaving [%d] %s = %s\n", i, v->toChars(), v->value ? v->value->toChars() : "");
+ valueSaves.data[i] = v->value;
+ v->value = NULL;
+ }
+ }
}
Expression *e = NULL;
while (1)
{
- e = fbody->interpret(&istatex);
- if (e == EXP_CANT_INTERPRET)
- {
+ e = fbody->interpret(&istatex);
+ if (e == EXP_CANT_INTERPRET)
+ {
#if LOG
- printf("function body failed to interpret\n");
+ printf("function body failed to interpret\n");
#endif
- e = NULL;
- }
+ e = NULL;
+ }
- /* This is how we deal with a recursive statement AST
- * that has arbitrary goto statements in it.
- * Bubble up a 'result' which is the target of the goto
- * statement, then go recursively down the AST looking
- * for that statement, then execute starting there.
- */
- if (e == EXP_GOTO_INTERPRET)
- {
- istatex.start = istatex.gotoTarget; // set starting statement
- istatex.gotoTarget = NULL;
- }
- else
- break;
+ /* This is how we deal with a recursive statement AST
+ * that has arbitrary goto statements in it.
+ * Bubble up a 'result' which is the target of the goto
+ * statement, then go recursively down the AST looking
+ * for that statement, then execute starting there.
+ */
+ if (e == EXP_GOTO_INTERPRET)
+ {
+ istatex.start = istatex.gotoTarget; // set starting statement
+ istatex.gotoTarget = NULL;
+ }
+ else
+ break;
}
/* Restore the parameter values
*/
for (size_t i = 0; i < dim; i++)
{
- VarDeclaration *v = (VarDeclaration *)parameters->data[i];
- v->value = (Expression *)vsave.data[i];
+ VarDeclaration *v = (VarDeclaration *)parameters->data[i];
+ v->value = (Expression *)vsave.data[i];
}
if (istate && !isNested())
{
- /* Restore the variable values
- */
- //printf("restoring local variables...\n");
- for (size_t i = 0; i < istate->vars.dim; i++)
- { VarDeclaration *v = (VarDeclaration *)istate->vars.data[i];
- if (v)
- { v->value = (Expression *)valueSaves.data[i];
- //printf("\trestoring [%d] %s = %s\n", i, v->toChars(), v->value ? v->value->toChars() : "");
- }
- }
+ /* Restore the variable values
+ */
+ //printf("restoring local variables...\n");
+ for (size_t i = 0; i < istate->vars.dim; i++)
+ { VarDeclaration *v = (VarDeclaration *)istate->vars.data[i];
+ if (v)
+ { v->value = (Expression *)valueSaves.data[i];
+ //printf("\trestoring [%d] %s = %s\n", i, v->toChars(), v->value ? v->value->toChars() : "");
+ }
+ }
}
return e;
}
/******************************** Statement ***************************/
-#define START() \
- if (istate->start) \
- { if (istate->start != this) \
- return NULL; \
- istate->start = NULL; \
+#define START() \
+ if (istate->start) \
+ { if (istate->start != this) \
+ return NULL; \
+ istate->start = NULL; \
}
/***********************************
* Interpret the statement.
* Returns:
- * NULL continue to next statement
- * EXP_CANT_INTERPRET cannot interpret statement at compile time
- * !NULL expression from return statement
+ * NULL continue to next statement
+ * EXP_CANT_INTERPRET cannot interpret statement at compile time
+ * !NULL expression from return statement
*/
Expression *Statement::interpret(InterState *istate)
@@ -334,12 +334,12 @@ Expression *ExpStatement::interpret(InterState *istate)
START()
if (exp)
{
- Expression *e = exp->interpret(istate);
- if (e == EXP_CANT_INTERPRET)
- {
- //printf("-ExpStatement::interpret(): %p\n", e);
- return EXP_CANT_INTERPRET;
- }
+ Expression *e = exp->interpret(istate);
+ if (e == EXP_CANT_INTERPRET)
+ {
+ //printf("-ExpStatement::interpret(): %p\n", e);
+ return EXP_CANT_INTERPRET;
+ }
}
return NULL;
}
@@ -351,19 +351,19 @@ Expression *CompoundStatement::interpret(InterState *istate)
printf("CompoundStatement::interpret()\n");
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
if (statements)
{
- for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *)statements->data[i];
+ for (size_t i = 0; i < statements->dim; i++)
+ { Statement *s = (Statement *)statements->data[i];
- if (s)
- {
- e = s->interpret(istate);
- if (e)
- break;
- }
- }
+ if (s)
+ {
+ e = s->interpret(istate);
+ if (e)
+ break;
+ }
+ }
}
#if LOG
printf("-CompoundStatement::interpret() %p\n", e);
@@ -378,26 +378,26 @@ Expression *UnrolledLoopStatement::interpret(InterState *istate)
printf("UnrolledLoopStatement::interpret()\n");
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
if (statements)
{
- for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *)statements->data[i];
+ for (size_t i = 0; i < statements->dim; i++)
+ { Statement *s = (Statement *)statements->data[i];
- e = s->interpret(istate);
- if (e == EXP_CANT_INTERPRET)
- break;
- if (e == EXP_CONTINUE_INTERPRET)
- { e = NULL;
- continue;
- }
- if (e == EXP_BREAK_INTERPRET)
- { e = NULL;
- break;
- }
- if (e)
- break;
- }
+ e = s->interpret(istate);
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ if (e == EXP_CONTINUE_INTERPRET)
+ { e = NULL;
+ continue;
+ }
+ if (e == EXP_BREAK_INTERPRET)
+ { e = NULL;
+ break;
+ }
+ if (e)
+ break;
+ }
}
return e;
}
@@ -409,15 +409,15 @@ Expression *IfStatement::interpret(InterState *istate)
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
if (istate->start)
{
- Expression *e = NULL;
- if (ifbody)
- e = ifbody->interpret(istate);
- if (istate->start && elsebody)
- e = elsebody->interpret(istate);
- return e;
+ Expression *e = NULL;
+ if (ifbody)
+ e = ifbody->interpret(istate);
+ if (istate->start && elsebody)
+ e = elsebody->interpret(istate);
+ return e;
}
Expression *e = condition->interpret(istate);
@@ -425,14 +425,14 @@ Expression *IfStatement::interpret(InterState *istate)
//if (e == EXP_CANT_INTERPRET) printf("cannot interpret\n");
if (e != EXP_CANT_INTERPRET)
{
- if (e->isBool(TRUE))
- e = ifbody ? ifbody->interpret(istate) : NULL;
- else if (e->isBool(FALSE))
- e = elsebody ? elsebody->interpret(istate) : NULL;
- else
- {
- e = EXP_CANT_INTERPRET;
- }
+ if (e->isBool(TRUE))
+ e = ifbody ? ifbody->interpret(istate) : NULL;
+ else if (e->isBool(FALSE))
+ e = elsebody ? elsebody->interpret(istate) : NULL;
+ else
+ {
+ e = EXP_CANT_INTERPRET;
+ }
}
return e;
}
@@ -443,7 +443,7 @@ Expression *ScopeStatement::interpret(InterState *istate)
printf("ScopeStatement::interpret()\n");
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
return statement ? statement->interpret(istate) : NULL;
}
@@ -537,8 +537,8 @@ Expression *ReturnStatement::interpret(InterState *istate)
#endif
START()
if (!exp)
- return EXP_VOID_INTERPRET;
- assert(istate && istate->fd && istate->fd->type);
+ return EXP_VOID_INTERPRET;
+ assert(istate && istate->fd && istate->fd->type);
#if DMDV2
/* If the function returns a ref AND it's been called from an assignment,
* we need to return an lvalue. Otherwise, just do an (rvalue) interpret.
@@ -579,9 +579,9 @@ Expression *BreakStatement::interpret(InterState *istate)
#endif
START()
if (ident)
- return EXP_CANT_INTERPRET;
+ return EXP_CANT_INTERPRET;
else
- return EXP_BREAK_INTERPRET;
+ return EXP_BREAK_INTERPRET;
}
Expression *ContinueStatement::interpret(InterState *istate)
@@ -591,9 +591,9 @@ Expression *ContinueStatement::interpret(InterState *istate)
#endif
START()
if (ident)
- return EXP_CANT_INTERPRET;
+ return EXP_CANT_INTERPRET;
else
- return EXP_CONTINUE_INTERPRET;
+ return EXP_CONTINUE_INTERPRET;
}
Expression *WhileStatement::interpret(InterState *istate)
@@ -601,7 +601,7 @@ Expression *WhileStatement::interpret(InterState *istate)
#if LOG
printf("WhileStatement::interpret()\n");
#endif
- assert(0); // rewritten to ForStatement
+ assert(0); // rewritten to ForStatement
return NULL;
}
@@ -611,53 +611,53 @@ Expression *DoStatement::interpret(InterState *istate)
printf("DoStatement::interpret()\n");
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
Expression *e;
if (istate->start)
{
- e = body ? body->interpret(istate) : NULL;
- if (istate->start)
- return NULL;
- if (e == EXP_CANT_INTERPRET)
- return e;
- if (e == EXP_BREAK_INTERPRET)
- return NULL;
- if (e == EXP_CONTINUE_INTERPRET)
- goto Lcontinue;
- if (e)
- return e;
+ e = body ? body->interpret(istate) : NULL;
+ if (istate->start)
+ return NULL;
+ if (e == EXP_CANT_INTERPRET)
+ return e;
+ if (e == EXP_BREAK_INTERPRET)
+ return NULL;
+ if (e == EXP_CONTINUE_INTERPRET)
+ goto Lcontinue;
+ if (e)
+ return e;
}
while (1)
{
- e = body ? body->interpret(istate) : NULL;
- if (e == EXP_CANT_INTERPRET)
- break;
- if (e == EXP_BREAK_INTERPRET)
- { e = NULL;
- break;
- }
- if (e && e != EXP_CONTINUE_INTERPRET)
- break;
+ e = body ? body->interpret(istate) : NULL;
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ if (e == EXP_BREAK_INTERPRET)
+ { e = NULL;
+ break;
+ }
+ if (e && e != EXP_CONTINUE_INTERPRET)
+ break;
Lcontinue:
- e = condition->interpret(istate);
- if (e == EXP_CANT_INTERPRET)
- break;
- if (!e->isConst())
- { e = EXP_CANT_INTERPRET;
- break;
- }
- if (e->isBool(TRUE))
- {
- }
- else if (e->isBool(FALSE))
- { e = NULL;
- break;
- }
- else
- assert(0);
+ e = condition->interpret(istate);
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ if (!e->isConst())
+ { e = EXP_CANT_INTERPRET;
+ break;
+ }
+ if (e->isBool(TRUE))
+ {
+ }
+ else if (e->isBool(FALSE))
+ { e = NULL;
+ break;
+ }
+ else
+ assert(0);
}
return e;
}
@@ -668,69 +668,69 @@ Expression *ForStatement::interpret(InterState *istate)
printf("ForStatement::interpret()\n");
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
Expression *e;
if (init)
{
- e = init->interpret(istate);
- if (e == EXP_CANT_INTERPRET)
- return e;
- assert(!e);
+ e = init->interpret(istate);
+ if (e == EXP_CANT_INTERPRET)
+ return e;
+ assert(!e);
}
if (istate->start)
{
- e = body ? body->interpret(istate) : NULL;
- if (istate->start)
- return NULL;
- if (e == EXP_CANT_INTERPRET)
- return e;
- if (e == EXP_BREAK_INTERPRET)
- return NULL;
- if (e == EXP_CONTINUE_INTERPRET)
- goto Lcontinue;
- if (e)
- return e;
+ e = body ? body->interpret(istate) : NULL;
+ if (istate->start)
+ return NULL;
+ if (e == EXP_CANT_INTERPRET)
+ return e;
+ if (e == EXP_BREAK_INTERPRET)
+ return NULL;
+ if (e == EXP_CONTINUE_INTERPRET)
+ goto Lcontinue;
+ if (e)
+ return e;
}
while (1)
{
- if (!condition)
- goto Lhead;
- e = condition->interpret(istate);
- if (e == EXP_CANT_INTERPRET)
- break;
- if (!e->isConst())
- { e = EXP_CANT_INTERPRET;
- break;
- }
- if (e->isBool(TRUE))
- {
- Lhead:
- e = body ? body->interpret(istate) : NULL;
- if (e == EXP_CANT_INTERPRET)
- break;
- if (e == EXP_BREAK_INTERPRET)
- { e = NULL;
- break;
- }
- if (e && e != EXP_CONTINUE_INTERPRET)
- break;
- Lcontinue:
- if (increment)
- {
- e = increment->interpret(istate);
- if (e == EXP_CANT_INTERPRET)
- break;
- }
- }
- else if (e->isBool(FALSE))
- { e = NULL;
- break;
- }
- else
- assert(0);
+ if (!condition)
+ goto Lhead;
+ e = condition->interpret(istate);
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ if (!e->isConst())
+ { e = EXP_CANT_INTERPRET;
+ break;
+ }
+ if (e->isBool(TRUE))
+ {
+ Lhead:
+ e = body ? body->interpret(istate) : NULL;
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ if (e == EXP_BREAK_INTERPRET)
+ { e = NULL;
+ break;
+ }
+ if (e && e != EXP_CONTINUE_INTERPRET)
+ break;
+ Lcontinue:
+ if (increment)
+ {
+ e = increment->interpret(istate);
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ }
+ }
+ else if (e->isBool(FALSE))
+ { e = NULL;
+ break;
+ }
+ else
+ assert(0);
}
return e;
}
@@ -741,23 +741,23 @@ Expression *ForeachStatement::interpret(InterState *istate)
printf("ForeachStatement::interpret()\n");
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
if (istate->start)
- return NULL;
+ return NULL;
Expression *e = NULL;
Expression *eaggr;
if (value->isOut() || value->isRef())
- return EXP_CANT_INTERPRET;
+ return EXP_CANT_INTERPRET;
eaggr = aggr->interpret(istate);
if (eaggr == EXP_CANT_INTERPRET)
- return EXP_CANT_INTERPRET;
+ return EXP_CANT_INTERPRET;
Expression *dim = ArrayLength(Type::tsize_t, eaggr);
if (dim == EXP_CANT_INTERPRET)
- return EXP_CANT_INTERPRET;
+ return EXP_CANT_INTERPRET;
Expression *keysave = key ? key->value : NULL;
Expression *valuesave = value->value;
@@ -767,57 +767,57 @@ Expression *ForeachStatement::interpret(InterState *istate)
if (op == TOKforeach)
{
- for (index = 0; index < d; index++)
- {
- Expression *ekey = new IntegerExp(loc, index, Type::tsize_t);
- if (key)
- key->value = ekey;
- e = Index(value->type, eaggr, ekey);
- if (e == EXP_CANT_INTERPRET)
- break;
- value->value = e;
+ for (index = 0; index < d; index++)
+ {
+ Expression *ekey = new IntegerExp(loc, index, Type::tsize_t);
+ if (key)
+ key->value = ekey;
+ e = Index(value->type, eaggr, ekey);
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ value->value = e;
- e = body ? body->interpret(istate) : NULL;
- if (e == EXP_CANT_INTERPRET)
- break;
- if (e == EXP_BREAK_INTERPRET)
- { e = NULL;
- break;
- }
- if (e == EXP_CONTINUE_INTERPRET)
- e = NULL;
- else if (e)
- break;
- }
+ e = body ? body->interpret(istate) : NULL;
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ if (e == EXP_BREAK_INTERPRET)
+ { e = NULL;
+ break;
+ }
+ if (e == EXP_CONTINUE_INTERPRET)
+ e = NULL;
+ else if (e)
+ break;
+ }
}
else // TOKforeach_reverse
{
- for (index = d; index-- != 0;)
- {
- Expression *ekey = new IntegerExp(loc, index, Type::tsize_t);
- if (key)
- key->value = ekey;
- e = Index(value->type, eaggr, ekey);
- if (e == EXP_CANT_INTERPRET)
- break;
- value->value = e;
+ for (index = d; index-- != 0;)
+ {
+ Expression *ekey = new IntegerExp(loc, index, Type::tsize_t);
+ if (key)
+ key->value = ekey;
+ e = Index(value->type, eaggr, ekey);
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ value->value = e;
- e = body ? body->interpret(istate) : NULL;
- if (e == EXP_CANT_INTERPRET)
- break;
- if (e == EXP_BREAK_INTERPRET)
- { e = NULL;
- break;
- }
- if (e == EXP_CONTINUE_INTERPRET)
- e = NULL;
- else if (e)
- break;
- }
+ e = body ? body->interpret(istate) : NULL;
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ if (e == EXP_BREAK_INTERPRET)
+ { e = NULL;
+ break;
+ }
+ if (e == EXP_CONTINUE_INTERPRET)
+ e = NULL;
+ else if (e)
+ break;
+ }
}
value->value = valuesave;
if (key)
- key->value = keysave;
+ key->value = keysave;
return e;
}
@@ -828,79 +828,79 @@ Expression *ForeachRangeStatement::interpret(InterState *istate)
printf("ForeachRangeStatement::interpret()\n");
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
if (istate->start)
- return NULL;
+ return NULL;
Expression *e = NULL;
Expression *elwr = lwr->interpret(istate);
if (elwr == EXP_CANT_INTERPRET)
- return EXP_CANT_INTERPRET;
+ return EXP_CANT_INTERPRET;
Expression *eupr = upr->interpret(istate);
if (eupr == EXP_CANT_INTERPRET)
- return EXP_CANT_INTERPRET;
+ return EXP_CANT_INTERPRET;
Expression *keysave = key->value;
if (op == TOKforeach)
{
- key->value = elwr;
+ key->value = elwr;
- while (1)
- {
- e = Cmp(TOKlt, key->value->type, key->value, eupr);
- if (e == EXP_CANT_INTERPRET)
- break;
- if (e->isBool(TRUE) == FALSE)
- { e = NULL;
- break;
- }
+ while (1)
+ {
+ e = Cmp(TOKlt, key->value->type, key->value, eupr);
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ if (e->isBool(TRUE) == FALSE)
+ { e = NULL;
+ break;
+ }
- e = body ? body->interpret(istate) : NULL;
- if (e == EXP_CANT_INTERPRET)
- break;
- if (e == EXP_BREAK_INTERPRET)
- { e = NULL;
- break;
- }
- if (e == NULL || e == EXP_CONTINUE_INTERPRET)
- { e = Add(key->value->type, key->value, new IntegerExp(loc, 1, key->value->type));
- if (e == EXP_CANT_INTERPRET)
- break;
- key->value = e;
- }
- else
- break;
- }
+ e = body ? body->interpret(istate) : NULL;
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ if (e == EXP_BREAK_INTERPRET)
+ { e = NULL;
+ break;
+ }
+ if (e == NULL || e == EXP_CONTINUE_INTERPRET)
+ { e = Add(key->value->type, key->value, new IntegerExp(loc, 1, key->value->type));
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ key->value = e;
+ }
+ else
+ break;
+ }
}
else // TOKforeach_reverse
{
- key->value = eupr;
+ key->value = eupr;
- do
- {
- e = Cmp(TOKgt, key->value->type, key->value, elwr);
- if (e == EXP_CANT_INTERPRET)
- break;
- if (e->isBool(TRUE) == FALSE)
- { e = NULL;
- break;
- }
+ do
+ {
+ e = Cmp(TOKgt, key->value->type, key->value, elwr);
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ if (e->isBool(TRUE) == FALSE)
+ { e = NULL;
+ break;
+ }
- e = Min(key->value->type, key->value, new IntegerExp(loc, 1, key->value->type));
- if (e == EXP_CANT_INTERPRET)
- break;
- key->value = e;
+ e = Min(key->value->type, key->value, new IntegerExp(loc, 1, key->value->type));
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ key->value = e;
- e = body ? body->interpret(istate) : NULL;
- if (e == EXP_CANT_INTERPRET)
- break;
- if (e == EXP_BREAK_INTERPRET)
- { e = NULL;
- break;
- }
- } while (e == NULL || e == EXP_CONTINUE_INTERPRET);
+ e = body ? body->interpret(istate) : NULL;
+ if (e == EXP_CANT_INTERPRET)
+ break;
+ if (e == EXP_BREAK_INTERPRET)
+ { e = NULL;
+ break;
+ }
+ } while (e == NULL || e == EXP_CONTINUE_INTERPRET);
}
key->value = keysave;
return e;
@@ -913,45 +913,45 @@ Expression *SwitchStatement::interpret(InterState *istate)
printf("SwitchStatement::interpret()\n");
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
Expression *e = NULL;
if (istate->start)
{
- e = body ? body->interpret(istate) : NULL;
- if (istate->start)
- return NULL;
- if (e == EXP_CANT_INTERPRET)
- return e;
- if (e == EXP_BREAK_INTERPRET)
- return NULL;
- return e;
+ e = body ? body->interpret(istate) : NULL;
+ if (istate->start)
+ return NULL;
+ if (e == EXP_CANT_INTERPRET)
+ return e;
+ if (e == EXP_BREAK_INTERPRET)
+ return NULL;
+ return e;
}
Expression *econdition = condition->interpret(istate);
if (econdition == EXP_CANT_INTERPRET)
- return EXP_CANT_INTERPRET;
+ return EXP_CANT_INTERPRET;
Statement *s = NULL;
if (cases)
{
- for (size_t i = 0; i < cases->dim; i++)
- {
- CaseStatement *cs = (CaseStatement *)cases->data[i];
- e = Equal(TOKequal, Type::tint32, econdition, cs->exp);
- if (e == EXP_CANT_INTERPRET)
- return EXP_CANT_INTERPRET;
- if (e->isBool(TRUE))
- { s = cs;
- break;
- }
- }
+ for (size_t i = 0; i < cases->dim; i++)
+ {
+ CaseStatement *cs = (CaseStatement *)cases->data[i];
+ e = Equal(TOKequal, Type::tint32, econdition, cs->exp);
+ if (e == EXP_CANT_INTERPRET)
+ return EXP_CANT_INTERPRET;
+ if (e->isBool(TRUE))
+ { s = cs;
+ break;
+ }
+ }
}
if (!s)
- { if (hasNoDefault)
- error("no default or case for %s in switch statement", econdition->toChars());
- s = sdefault;
+ { if (hasNoDefault)
+ error("no default or case for %s in switch statement", econdition->toChars());
+ s = sdefault;
}
assert(s);
@@ -959,7 +959,7 @@ Expression *SwitchStatement::interpret(InterState *istate)
e = body ? body->interpret(istate) : NULL;
assert(!istate->start);
if (e == EXP_BREAK_INTERPRET)
- return NULL;
+ return NULL;
return e;
}
@@ -969,11 +969,11 @@ Expression *CaseStatement::interpret(InterState *istate)
printf("CaseStatement::interpret(%s) this = %p\n", exp->toChars(), this);
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
if (statement)
- return statement->interpret(istate);
+ return statement->interpret(istate);
else
- return NULL;
+ return NULL;
}
Expression *DefaultStatement::interpret(InterState *istate)
@@ -982,11 +982,11 @@ Expression *DefaultStatement::interpret(InterState *istate)
printf("DefaultStatement::interpret()\n");
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
if (statement)
- return statement->interpret(istate);
+ return statement->interpret(istate);
else
- return NULL;
+ return NULL;
}
Expression *GotoStatement::interpret(InterState *istate)
@@ -1028,7 +1028,7 @@ Expression *LabelStatement::interpret(InterState *istate)
printf("LabelStatement::interpret()\n");
#endif
if (istate->start == this)
- istate->start = NULL;
+ istate->start = NULL;
return statement ? statement->interpret(istate) : NULL;
}
@@ -1101,7 +1101,7 @@ Expression *SymOffExp::interpret(InterState *istate)
#endif
if (var->isFuncDeclaration() && offset == 0)
{
- return this;
+ return this;
}
error("Cannot interpret %s at compile time", toChars());
return EXP_CANT_INTERPRET;
@@ -1175,53 +1175,53 @@ Expression *getVarExp(Loc loc, InterState *istate, Declaration *d)
if (v)
{
#if DMDV2
- /* Magic variable __ctfe always returns true when interpreting
- */
- if (v->ident == Id::ctfe)
- return new IntegerExp(loc, 1, Type::tbool);
+ /* Magic variable __ctfe always returns true when interpreting
+ */
+ if (v->ident == Id::ctfe)
+ return new IntegerExp(loc, 1, Type::tbool);
- if ((v->isConst() || v->isImmutable() || v->storage_class & STCmanifest) && v->init && !v->value)
+ if ((v->isConst() || v->isImmutable() || v->storage_class & STCmanifest) && v->init && !v->value)
#else
- if (v->isConst() && v->init)
+ if (v->isConst() && v->init)
#endif
- { e = v->init->toExpression();
- if (e && !e->type)
- e->type = v->type;
- }
- else if (v->isCTFE() && !v->value)
- {
- if (v->init)
- {
- if (v->init->isVoidInitializer())
- {
- error(loc, "variable %s is used before initialization", v->toChars());
- return EXP_CANT_INTERPRET;
- }
- e = v->init->toExpression();
- e = e->interpret(istate);
- }
- else // This should never happen
- e = v->type->defaultInitLiteral();
- }
- else
- { e = v->value;
- if (!v->isCTFE())
- { error(loc, "static variable %s cannot be read at compile time", v->toChars());
- e = EXP_CANT_INTERPRET;
- }
- else if (!e)
- error(loc, "variable %s is used before initialization", v->toChars());
- else if (e != EXP_CANT_INTERPRET)
- e = e->interpret(istate);
- }
- if (!e)
- e = EXP_CANT_INTERPRET;
+ { e = v->init->toExpression();
+ if (e && !e->type)
+ e->type = v->type;
+ }
+ else if (v->isCTFE() && !v->value)
+ {
+ if (v->init)
+ {
+ if (v->init->isVoidInitializer())
+ {
+ error(loc, "variable %s is used before initialization", v->toChars());
+ return EXP_CANT_INTERPRET;
+ }
+ e = v->init->toExpression();
+ e = e->interpret(istate);
+ }
+ else // This should never happen
+ e = v->type->defaultInitLiteral();
+ }
+ else
+ { e = v->value;
+ if (!v->isCTFE())
+ { error(loc, "static variable %s cannot be read at compile time", v->toChars());
+ e = EXP_CANT_INTERPRET;
+ }
+ else if (!e)
+ error(loc, "variable %s is used before initialization", v->toChars());
+ else if (e != EXP_CANT_INTERPRET)
+ e = e->interpret(istate);
+ }
+ if (!e)
+ e = EXP_CANT_INTERPRET;
}
else if (s)
{
- Expressions *exps = new Expressions();
- e = new StructLiteralExp(0, s->dsym, exps);
- e = e->semantic(NULL);
+ Expressions *exps = new Expressions();
+ e = new StructLiteralExp(0, s->dsym, exps);
+ e = e->semantic(NULL);
}
return e;
}
@@ -1243,38 +1243,38 @@ Expression *DeclarationExp::interpret(InterState *istate)
VarDeclaration *v = declaration->isVarDeclaration();
if (v)
{
- Dsymbol *s = v->toAlias();
- if (s == v && !v->isStatic() && v->init)
- {
- ExpInitializer *ie = v->init->isExpInitializer();
- if (ie)
- e = ie->exp->interpret(istate);
- else if (v->init->isVoidInitializer())
- e = NULL;
- }
+ Dsymbol *s = v->toAlias();
+ if (s == v && !v->isStatic() && v->init)
+ {
+ ExpInitializer *ie = v->init->isExpInitializer();
+ if (ie)
+ e = ie->exp->interpret(istate);
+ else if (v->init->isVoidInitializer())
+ e = NULL;
+ }
#if DMDV2
- else if (s == v && (v->isConst() || v->isImmutable()) && v->init)
+ else if (s == v && (v->isConst() || v->isImmutable()) && v->init)
#else
- else if (s == v && v->isConst() && v->init)
+ else if (s == v && v->isConst() && v->init)
#endif
- { e = v->init->toExpression();
- if (!e)
- e = EXP_CANT_INTERPRET;
- else if (!e->type)
- e->type = v->type;
- }
+ { e = v->init->toExpression();
+ if (!e)
+ e = EXP_CANT_INTERPRET;
+ else if (!e->type)
+ e->type = v->type;
+ }
}
else if (declaration->isAttribDeclaration() ||
- declaration->isTemplateMixin() ||
- declaration->isTupleDeclaration())
- { // These can be made to work, too lazy now
+ declaration->isTemplateMixin() ||
+ declaration->isTupleDeclaration())
+ { // These can be made to work, too lazy now
error("Declaration %s is not yet implemented in CTFE", toChars());
- e = EXP_CANT_INTERPRET;
+ e = EXP_CANT_INTERPRET;
}
else
- { // Others should not contain executable code, so are trivial to evaluate
- e = NULL;
+ { // Others should not contain executable code, so are trivial to evaluate
+ e = NULL;
}
#if LOG
printf("-DeclarationExp::interpret(%s): %p\n", toChars(), e);
@@ -1291,34 +1291,34 @@ Expression *TupleExp::interpret(InterState *istate)
for (size_t i = 0; i < exps->dim; i++)
{ Expression *e = (Expression *)exps->data[i];
- Expression *ex;
+ Expression *ex;
- ex = e->interpret(istate);
- if (ex == EXP_CANT_INTERPRET)
- { delete expsx;
- return ex;
- }
+ ex = e->interpret(istate);
+ if (ex == EXP_CANT_INTERPRET)
+ { delete expsx;
+ return ex;
+ }
- /* If any changes, do Copy On Write
- */
- if (ex != e)
- {
- if (!expsx)
- { expsx = new Expressions();
- expsx->setDim(exps->dim);
- for (size_t j = 0; j < i; j++)
- {
- expsx->data[j] = exps->data[j];
- }
- }
- expsx->data[i] = (void *)ex;
- }
+ /* If any changes, do Copy On Write
+ */
+ if (ex != e)
+ {
+ if (!expsx)
+ { expsx = new Expressions();
+ expsx->setDim(exps->dim);
+ for (size_t j = 0; j < i; j++)
+ {
+ expsx->data[j] = exps->data[j];
+ }
+ }
+ expsx->data[i] = (void *)ex;
+ }
}
if (expsx)
- { TupleExp *te = new TupleExp(loc, expsx);
- expandTuples(te->exps);
- te->type = new TypeTuple(te->exps);
- return te;
+ { TupleExp *te = new TupleExp(loc, expsx);
+ expandTuples(te->exps);
+ te->type = new TypeTuple(te->exps);
+ return te;
}
return this;
}
@@ -1331,44 +1331,44 @@ Expression *ArrayLiteralExp::interpret(InterState *istate)
#endif
if (elements)
{
- for (size_t i = 0; i < elements->dim; i++)
- { Expression *e = (Expression *)elements->data[i];
- Expression *ex;
+ for (size_t i = 0; i < elements->dim; i++)
+ { Expression *e = (Expression *)elements->data[i];
+ Expression *ex;
- ex = e->interpret(istate);
- if (ex == EXP_CANT_INTERPRET)
- goto Lerror;
+ ex = e->interpret(istate);
+ if (ex == EXP_CANT_INTERPRET)
+ goto Lerror;
- /* If any changes, do Copy On Write
- */
- if (ex != e)
- {
- if (!expsx)
- { expsx = new Expressions();
- expsx->setDim(elements->dim);
- for (size_t j = 0; j < elements->dim; j++)
- {
- expsx->data[j] = elements->data[j];
- }
- }
- expsx->data[i] = (void *)ex;
- }
- }
+ /* If any changes, do Copy On Write
+ */
+ if (ex != e)
+ {
+ if (!expsx)
+ { expsx = new Expressions();
+ expsx->setDim(elements->dim);
+ for (size_t j = 0; j < elements->dim; j++)
+ {
+ expsx->data[j] = elements->data[j];
+ }
+ }
+ expsx->data[i] = (void *)ex;
+ }
+ }
}
if (elements && expsx)
{
- expandTuples(expsx);
- if (expsx->dim != elements->dim)
- goto Lerror;
- ArrayLiteralExp *ae = new ArrayLiteralExp(loc, expsx);
- ae->type = type;
- return ae;
+ expandTuples(expsx);
+ if (expsx->dim != elements->dim)
+ goto Lerror;
+ ArrayLiteralExp *ae = new ArrayLiteralExp(loc, expsx);
+ ae->type = type;
+ return ae;
}
return this;
Lerror:
if (expsx)
- delete expsx;
+ delete expsx;
error("cannot interpret array literal");
return EXP_CANT_INTERPRET;
}
@@ -1382,81 +1382,81 @@ Expression *AssocArrayLiteralExp::interpret(InterState *istate)
#endif
for (size_t i = 0; i < keys->dim; i++)
{ Expression *ekey = (Expression *)keys->data[i];
- Expression *evalue = (Expression *)values->data[i];
- Expression *ex;
+ Expression *evalue = (Expression *)values->data[i];
+ Expression *ex;
- ex = ekey->interpret(istate);
- if (ex == EXP_CANT_INTERPRET)
- goto Lerr;
+ ex = ekey->interpret(istate);
+ if (ex == EXP_CANT_INTERPRET)
+ goto Lerr;
- /* If any changes, do Copy On Write
- */
- if (ex != ekey)
- {
- if (keysx == keys)
- keysx = (Expressions *)keys->copy();
- keysx->data[i] = (void *)ex;
- }
+ /* If any changes, do Copy On Write
+ */
+ if (ex != ekey)
+ {
+ if (keysx == keys)
+ keysx = (Expressions *)keys->copy();
+ keysx->data[i] = (void *)ex;
+ }
- ex = evalue->interpret(istate);
- if (ex == EXP_CANT_INTERPRET)
- goto Lerr;
+ ex = evalue->interpret(istate);
+ if (ex == EXP_CANT_INTERPRET)
+ goto Lerr;
- /* If any changes, do Copy On Write
- */
- if (ex != evalue)
- {
- if (valuesx == values)
- valuesx = (Expressions *)values->copy();
- valuesx->data[i] = (void *)ex;
- }
+ /* If any changes, do Copy On Write
+ */
+ if (ex != evalue)
+ {
+ if (valuesx == values)
+ valuesx = (Expressions *)values->copy();
+ valuesx->data[i] = (void *)ex;
+ }
}
if (keysx != keys)
- expandTuples(keysx);
+ expandTuples(keysx);
if (valuesx != values)
- expandTuples(valuesx);
+ expandTuples(valuesx);
if (keysx->dim != valuesx->dim)
- goto Lerr;
+ goto Lerr;
/* Remove duplicate keys
*/
for (size_t i = 1; i < keysx->dim; i++)
{ Expression *ekey = (Expression *)keysx->data[i - 1];
- for (size_t j = i; j < keysx->dim; j++)
- { Expression *ekey2 = (Expression *)keysx->data[j];
- Expression *ex = Equal(TOKequal, Type::tbool, ekey, ekey2);
- if (ex == EXP_CANT_INTERPRET)
- goto Lerr;
- if (ex->isBool(TRUE)) // if a match
- {
- // Remove ekey
- if (keysx == keys)
- keysx = (Expressions *)keys->copy();
- if (valuesx == values)
- valuesx = (Expressions *)values->copy();
- keysx->remove(i - 1);
- valuesx->remove(i - 1);
- i -= 1; // redo the i'th iteration
- break;
- }
- }
+ for (size_t j = i; j < keysx->dim; j++)
+ { Expression *ekey2 = (Expression *)keysx->data[j];
+ Expression *ex = Equal(TOKequal, Type::tbool, ekey, ekey2);
+ if (ex == EXP_CANT_INTERPRET)
+ goto Lerr;
+ if (ex->isBool(TRUE)) // if a match
+ {
+ // Remove ekey
+ if (keysx == keys)
+ keysx = (Expressions *)keys->copy();
+ if (valuesx == values)
+ valuesx = (Expressions *)values->copy();
+ keysx->remove(i - 1);
+ valuesx->remove(i - 1);
+ i -= 1; // redo the i'th iteration
+ break;
+ }
+ }
}
if (keysx != keys || valuesx != values)
{
- AssocArrayLiteralExp *ae;
- ae = new AssocArrayLiteralExp(loc, keysx, valuesx);
- ae->type = type;
- return ae;
+ AssocArrayLiteralExp *ae;
+ ae = new AssocArrayLiteralExp(loc, keysx, valuesx);
+ ae->type = type;
+ return ae;
}
return this;
Lerr:
if (keysx != keys)
- delete keysx;
+ delete keysx;
if (valuesx != values)
- delete values;
+ delete values;
return EXP_CANT_INTERPRET;
}
@@ -1469,49 +1469,49 @@ Expression *StructLiteralExp::interpret(InterState *istate)
/* We don't know how to deal with overlapping fields
*/
if (sd->hasUnions)
- { error("Unions with overlapping fields are not yet supported in CTFE");
- return EXP_CANT_INTERPRET;
+ { error("Unions with overlapping fields are not yet supported in CTFE");
+ return EXP_CANT_INTERPRET;
}
if (elements)
{
- for (size_t i = 0; i < elements->dim; i++)
- { Expression *e = (Expression *)elements->data[i];
- if (!e)
- continue;
+ for (size_t i = 0; i < elements->dim; i++)
+ { Expression *e = (Expression *)elements->data[i];
+ if (!e)
+ continue;
- Expression *ex = e->interpret(istate);
- if (ex == EXP_CANT_INTERPRET)
- { delete expsx;
- return EXP_CANT_INTERPRET;
- }
+ Expression *ex = e->interpret(istate);
+ if (ex == EXP_CANT_INTERPRET)
+ { delete expsx;
+ return EXP_CANT_INTERPRET;
+ }
- /* If any changes, do Copy On Write
- */
- if (ex != e)
- {
- if (!expsx)
- { expsx = new Expressions();
- expsx->setDim(elements->dim);
- for (size_t j = 0; j < elements->dim; j++)
- {
- expsx->data[j] = elements->data[j];
- }
- }
- expsx->data[i] = (void *)ex;
- }
- }
+ /* If any changes, do Copy On Write
+ */
+ if (ex != e)
+ {
+ if (!expsx)
+ { expsx = new Expressions();
+ expsx->setDim(elements->dim);
+ for (size_t j = 0; j < elements->dim; j++)
+ {
+ expsx->data[j] = elements->data[j];
+ }
+ }
+ expsx->data[i] = (void *)ex;
+ }
+ }
}
if (elements && expsx)
{
- expandTuples(expsx);
- if (expsx->dim != elements->dim)
- { delete expsx;
- return EXP_CANT_INTERPRET;
- }
- StructLiteralExp *se = new StructLiteralExp(loc, sd, expsx);
- se->type = type;
- return se;
+ expandTuples(expsx);
+ if (expsx->dim != elements->dim)
+ { delete expsx;
+ return EXP_CANT_INTERPRET;
+ }
+ StructLiteralExp *se = new StructLiteralExp(loc, sd, expsx);
+ se->type = type;
+ return se;
}
return this;
}
@@ -1525,9 +1525,9 @@ Expression *UnaExp::interpretCommon(InterState *istate, Expression *(*fp)(Type *
#endif
e1 = this->e1->interpret(istate);
if (e1 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
if (e1->isConst() != 1)
- goto Lcant;
+ goto Lcant;
e = (*fp)(type, e1);
return e;
@@ -1537,9 +1537,9 @@ Lcant:
}
#define UNA_INTERPRET(op) \
-Expression *op##Exp::interpret(InterState *istate) \
-{ \
- return interpretCommon(istate, &op); \
+Expression *op##Exp::interpret(InterState *istate) \
+{ \
+ return interpretCommon(istate, &op); \
}
UNA_INTERPRET(Neg)
@@ -1560,15 +1560,15 @@ Expression *BinExp::interpretCommon(InterState *istate, fp_t fp)
#endif
e1 = this->e1->interpret(istate);
if (e1 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
if (e1->isConst() != 1)
- goto Lcant;
+ goto Lcant;
e2 = this->e2->interpret(istate);
if (e2 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
if (e2->isConst() != 1)
- goto Lcant;
+ goto Lcant;
e = (*fp)(type, e1, e2);
return e;
@@ -1578,9 +1578,9 @@ Lcant:
}
#define BIN_INTERPRET(op) \
-Expression *op##Exp::interpret(InterState *istate) \
-{ \
- return interpretCommon(istate, &op); \
+Expression *op##Exp::interpret(InterState *istate) \
+{ \
+ return interpretCommon(istate, &op); \
}
BIN_INTERPRET(Add)
@@ -1608,23 +1608,23 @@ Expression *BinExp::interpretCommon2(InterState *istate, fp2_t fp)
#endif
e1 = this->e1->interpret(istate);
if (e1 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
if (e1->isConst() != 1 &&
- e1->op != TOKnull &&
- e1->op != TOKstring &&
- e1->op != TOKarrayliteral &&
- e1->op != TOKstructliteral)
- goto Lcant;
+ e1->op != TOKnull &&
+ e1->op != TOKstring &&
+ e1->op != TOKarrayliteral &&
+ e1->op != TOKstructliteral)
+ goto Lcant;
e2 = this->e2->interpret(istate);
if (e2 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
if (e2->isConst() != 1 &&
- e2->op != TOKnull &&
- e2->op != TOKstring &&
- e2->op != TOKarrayliteral &&
- e2->op != TOKstructliteral)
- goto Lcant;
+ e2->op != TOKnull &&
+ e2->op != TOKstring &&
+ e2->op != TOKarrayliteral &&
+ e2->op != TOKstructliteral)
+ goto Lcant;
e = (*fp)(op, type, e1, e2);
return e;
@@ -1634,9 +1634,9 @@ Lcant:
}
#define BIN_INTERPRET2(op) \
-Expression *op##Exp::interpret(InterState *istate) \
-{ \
- return interpretCommon2(istate, &op); \
+Expression *op##Exp::interpret(InterState *istate) \
+{ \
+ return interpretCommon2(istate, &op); \
}
BIN_INTERPRET2(Equal)
@@ -1655,10 +1655,10 @@ Expressions *changeOneElement(Expressions *oldelems, size_t indexToChange, void
expsx->setDim(oldelems->dim);
for (size_t j = 0; j < expsx->dim; j++)
{
- if (j == indexToChange)
- expsx->data[j] = newelem;
- else
- expsx->data[j] = oldelems->data[j];
+ if (j == indexToChange)
+ expsx->data[j] = newelem;
+ else
+ expsx->data[j] = oldelems->data[j];
}
return expsx;
}
@@ -1667,16 +1667,16 @@ Expressions *changeOneElement(Expressions *oldelems, size_t indexToChange, void
* Returns oldelems[0..insertpoint] ~ newelems ~ oldelems[insertpoint+newelems.length..$]
*/
Expressions *spliceElements(Expressions *oldelems,
- Expressions *newelems, size_t insertpoint)
+ Expressions *newelems, size_t insertpoint)
{
Expressions *expsx = new Expressions();
expsx->setDim(oldelems->dim);
for (size_t j = 0; j < expsx->dim; j++)
{
- if (j >= insertpoint && j < insertpoint + newelems->dim)
- expsx->data[j] = newelems->data[j - insertpoint];
- else
- expsx->data[j] = oldelems->data[j];
+ if (j >= insertpoint && j < insertpoint + newelems->dim)
+ expsx->data[j] = newelems->data[j - insertpoint];
+ else
+ expsx->data[j] = oldelems->data[j];
}
return expsx;
}
@@ -1705,12 +1705,12 @@ StringExp *spliceStringExp(StringExp *oldstr, StringExp *newstr, size_t insertpo
* Create an array literal consisting of 'elem' duplicated 'dim' times.
*/
ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Type *type,
- Expression *elem, size_t dim)
+ Expression *elem, size_t dim)
{
Expressions *elements = new Expressions();
elements->setDim(dim);
for (size_t i = 0; i < dim; i++)
- elements->data[i] = elem;
+ elements->data[i] = elem;
ArrayLiteralExp *ae = new ArrayLiteralExp(0, elements);
ae->type = type;
return ae;
@@ -1720,19 +1720,19 @@ ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Type *type,
* Create a string literal consisting of 'value' duplicated 'dim' times.
*/
StringExp *createBlockDuplicatedStringLiteral(Type *type,
- unsigned value, size_t dim, int sz)
+ unsigned value, size_t dim, int sz)
{
unsigned char *s;
s = (unsigned char *)mem.calloc(dim + 1, sz);
for (int elemi=0; elemitype = type;
@@ -1746,16 +1746,16 @@ void addVarToInterstate(InterState *istate, VarDeclaration *v)
{
if (!v->isParameter())
{
- for (size_t i = 0; 1; i++)
- {
- if (i == istate->vars.dim)
- { istate->vars.push(v);
- //printf("\tadding %s to istate\n", v->toChars());
- break;
- }
- if (v == (VarDeclaration *)istate->vars.data[i])
- break;
- }
+ for (size_t i = 0; 1; i++)
+ {
+ if (i == istate->vars.dim)
+ { istate->vars.push(v);
+ //printf("\tadding %s to istate\n", v->toChars());
+ break;
+ }
+ if (v == (VarDeclaration *)istate->vars.data[i])
+ break;
+ }
}
}
@@ -2423,9 +2423,9 @@ Expression *AssignExp::interpret(InterState *istate)
}
#define BIN_ASSIGN_INTERPRET(op) \
-Expression *op##AssignExp::interpret(InterState *istate) \
-{ \
- return interpretAssignCommon(istate, &op); \
+Expression *op##AssignExp::interpret(InterState *istate) \
+{ \
+ return interpretAssignCommon(istate, &op); \
}
BIN_ASSIGN_INTERPRET(Add)
@@ -2448,12 +2448,12 @@ Expression *PostExp::interpret(InterState *istate)
#endif
Expression *e;
if (op == TOKplusplus)
- e = interpretAssignCommon(istate, &Add, 1);
+ e = interpretAssignCommon(istate, &Add, 1);
else
- e = interpretAssignCommon(istate, &Min, 1);
+ e = interpretAssignCommon(istate, &Min, 1);
#if LOG
if (e == EXP_CANT_INTERPRET)
- printf("PostExp::interpret() CANT\n");
+ printf("PostExp::interpret() CANT\n");
#endif
return e;
}
@@ -2466,23 +2466,23 @@ Expression *AndAndExp::interpret(InterState *istate)
Expression *e = e1->interpret(istate);
if (e != EXP_CANT_INTERPRET)
{
- if (e->isBool(FALSE))
- e = new IntegerExp(e1->loc, 0, type);
- else if (e->isBool(TRUE))
- {
- e = e2->interpret(istate);
- if (e != EXP_CANT_INTERPRET)
- {
- if (e->isBool(FALSE))
- e = new IntegerExp(e1->loc, 0, type);
- else if (e->isBool(TRUE))
- e = new IntegerExp(e1->loc, 1, type);
- else
- e = EXP_CANT_INTERPRET;
- }
- }
- else
- e = EXP_CANT_INTERPRET;
+ if (e->isBool(FALSE))
+ e = new IntegerExp(e1->loc, 0, type);
+ else if (e->isBool(TRUE))
+ {
+ e = e2->interpret(istate);
+ if (e != EXP_CANT_INTERPRET)
+ {
+ if (e->isBool(FALSE))
+ e = new IntegerExp(e1->loc, 0, type);
+ else if (e->isBool(TRUE))
+ e = new IntegerExp(e1->loc, 1, type);
+ else
+ e = EXP_CANT_INTERPRET;
+ }
+ }
+ else
+ e = EXP_CANT_INTERPRET;
}
return e;
}
@@ -2495,23 +2495,23 @@ Expression *OrOrExp::interpret(InterState *istate)
Expression *e = e1->interpret(istate);
if (e != EXP_CANT_INTERPRET)
{
- if (e->isBool(TRUE))
- e = new IntegerExp(e1->loc, 1, type);
- else if (e->isBool(FALSE))
- {
- e = e2->interpret(istate);
- if (e != EXP_CANT_INTERPRET)
- {
- if (e->isBool(FALSE))
- e = new IntegerExp(e1->loc, 0, type);
- else if (e->isBool(TRUE))
- e = new IntegerExp(e1->loc, 1, type);
- else
- e = EXP_CANT_INTERPRET;
- }
- }
- else
- e = EXP_CANT_INTERPRET;
+ if (e->isBool(TRUE))
+ e = new IntegerExp(e1->loc, 1, type);
+ else if (e->isBool(FALSE))
+ {
+ e = e2->interpret(istate);
+ if (e != EXP_CANT_INTERPRET)
+ {
+ if (e->isBool(FALSE))
+ e = new IntegerExp(e1->loc, 0, type);
+ else if (e->isBool(TRUE))
+ e = new IntegerExp(e1->loc, 1, type);
+ else
+ e = EXP_CANT_INTERPRET;
+ }
+ }
+ else
+ e = EXP_CANT_INTERPRET;
}
return e;
}
@@ -2524,7 +2524,7 @@ Expression *CallExp::interpret(InterState *istate)
printf("CallExp::interpret() %s\n", toChars());
#endif
- Expression * pthis = NULL;
+ Expression * pthis = NULL;
FuncDeclaration *fd = NULL;
Expression *ecall = e1;
if (ecall->op == TOKcall)
@@ -2553,82 +2553,82 @@ Expression *CallExp::interpret(InterState *istate)
ecall = e1->interpret(istate);
if (ecall->op == TOKdotvar && !((DotVarExp*)ecall)->var->isFuncDeclaration())
ecall = e1->interpret(istate);
-
+
if (ecall->op == TOKdotvar)
- { // Calling a member function
+ { // Calling a member function
pthis = ((DotVarExp*)e1)->e1;
- fd = ((DotVarExp*)e1)->var->isFuncDeclaration();
+ fd = ((DotVarExp*)e1)->var->isFuncDeclaration();
}
else if (ecall->op == TOKvar)
{
VarDeclaration *vd = ((VarExp *)ecall)->var->isVarDeclaration();
- if (vd && vd->value)
- ecall = vd->value;
- else // Calling a function
- fd = ((VarExp *)e1)->var->isFuncDeclaration();
- }
+ if (vd && vd->value)
+ ecall = vd->value;
+ else // Calling a function
+ fd = ((VarExp *)e1)->var->isFuncDeclaration();
+ }
if (ecall->op == TOKdelegate)
{ // Calling a delegate
- fd = ((DelegateExp *)ecall)->func;
- pthis = ((DelegateExp *)ecall)->e1;
+ fd = ((DelegateExp *)ecall)->func;
+ pthis = ((DelegateExp *)ecall)->e1;
}
else if (ecall->op == TOKfunction)
- { // Calling a delegate literal
+ { // Calling a delegate literal
fd = ((FuncExp*)ecall)->fd;
}
else if (ecall->op == TOKstar && ((PtrExp*)ecall)->e1->op==TOKfunction)
{ // Calling a function literal
fd = ((FuncExp*)((PtrExp*)ecall)->e1)->fd;
}
-
+
TypeFunction *tf = fd ? (TypeFunction *)(fd->type) : NULL;
if (!tf)
{ // DAC: I'm not sure if this ever happens
- //printf("ecall=%s %d %d\n", ecall->toChars(), ecall->op, TOKcall);
- error("cannot evaluate %s at compile time", toChars());
- return EXP_CANT_INTERPRET;
+ //printf("ecall=%s %d %d\n", ecall->toChars(), ecall->op, TOKcall);
+ error("cannot evaluate %s at compile time", toChars());
+ return EXP_CANT_INTERPRET;
}
if (pthis && fd)
{ // Member function call
- if (pthis->op == TOKthis)
- pthis = istate ? istate->localThis : NULL;
- else if (pthis->op == TOKcomma)
- pthis = pthis->interpret(istate);
- if (!fd->fbody)
- {
- error("%s cannot be interpreted at compile time,"
- " because it has no available source code", fd->toChars());
- return EXP_CANT_INTERPRET;
- }
- Expression *eresult = fd->interpret(istate, arguments, pthis);
- if (eresult)
- e = eresult;
- else if (fd->type->toBasetype()->nextOf()->ty == Tvoid && !global.errors)
- e = EXP_VOID_INTERPRET;
- else
- error("cannot evaluate %s at compile time", toChars());
- return e;
+ if (pthis->op == TOKthis)
+ pthis = istate ? istate->localThis : NULL;
+ else if (pthis->op == TOKcomma)
+ pthis = pthis->interpret(istate);
+ if (!fd->fbody)
+ {
+ error("%s cannot be interpreted at compile time,"
+ " because it has no available source code", fd->toChars());
+ return EXP_CANT_INTERPRET;
+ }
+ Expression *eresult = fd->interpret(istate, arguments, pthis);
+ if (eresult)
+ e = eresult;
+ else if (fd->type->toBasetype()->nextOf()->ty == Tvoid && !global.errors)
+ e = EXP_VOID_INTERPRET;
+ else
+ error("cannot evaluate %s at compile time", toChars());
+ return e;
}
else if (fd)
{ // function call
#if DMDV2
- enum BUILTIN b = fd->isBuiltin();
- if (b)
- { Expressions args;
- args.setDim(arguments->dim);
- for (size_t i = 0; i < args.dim; i++)
- {
- Expression *earg = (Expression *)arguments->data[i];
- earg = earg->interpret(istate);
- if (earg == EXP_CANT_INTERPRET)
- return earg;
- args.data[i] = (void *)earg;
- }
- e = eval_builtin(b, &args);
- if (!e)
- e = EXP_CANT_INTERPRET;
- }
- else
+ enum BUILTIN b = fd->isBuiltin();
+ if (b)
+ { Expressions args;
+ args.setDim(arguments->dim);
+ for (size_t i = 0; i < args.dim; i++)
+ {
+ Expression *earg = (Expression *)arguments->data[i];
+ earg = earg->interpret(istate);
+ if (earg == EXP_CANT_INTERPRET)
+ return earg;
+ args.data[i] = (void *)earg;
+ }
+ e = eval_builtin(b, &args);
+ if (!e)
+ e = EXP_CANT_INTERPRET;
+ }
+ else
#endif
#if DMDV1
@@ -2640,39 +2640,39 @@ Expression *CallExp::interpret(InterState *istate)
return interpret_aaValues(istate, arguments);
#endif
- // Inline .dup
- if (fd->ident == Id::adDup && arguments && arguments->dim == 2)
- {
- e = (Expression *)arguments->data[1];
- e = e->interpret(istate);
- if (e != EXP_CANT_INTERPRET)
- {
- e = expType(type, e);
- }
- }
- else
- {
- if (!fd->fbody)
- {
- error("%s cannot be interpreted at compile time,"
- " because it has no available source code", fd->toChars());
- return EXP_CANT_INTERPRET;
- }
- Expression *eresult = fd->interpret(istate, arguments);
- if (eresult)
- e = eresult;
- else if (fd->type->toBasetype()->nextOf()->ty == Tvoid && !global.errors)
- e = EXP_VOID_INTERPRET;
- else
- error("cannot evaluate %s at compile time", toChars());
- }
+ // Inline .dup
+ if (fd->ident == Id::adDup && arguments && arguments->dim == 2)
+ {
+ e = (Expression *)arguments->data[1];
+ e = e->interpret(istate);
+ if (e != EXP_CANT_INTERPRET)
+ {
+ e = expType(type, e);
+ }
+ }
+ else
+ {
+ if (!fd->fbody)
+ {
+ error("%s cannot be interpreted at compile time,"
+ " because it has no available source code", fd->toChars());
+ return EXP_CANT_INTERPRET;
+ }
+ Expression *eresult = fd->interpret(istate, arguments);
+ if (eresult)
+ e = eresult;
+ else if (fd->type->toBasetype()->nextOf()->ty == Tvoid && !global.errors)
+ e = EXP_VOID_INTERPRET;
+ else
+ error("cannot evaluate %s at compile time", toChars());
+ }
}
else
{
- error("cannot evaluate %s at compile time", toChars());
+ error("cannot evaluate %s at compile time", toChars());
return EXP_CANT_INTERPRET;
}
- return e;
+ return e;
}
Expression *CommaExp::interpret(InterState *istate)
@@ -2720,12 +2720,12 @@ Expression *CondExp::interpret(InterState *istate)
Expression *e = econd->interpret(istate);
if (e != EXP_CANT_INTERPRET)
{
- if (e->isBool(TRUE))
- e = e1->interpret(istate);
- else if (e->isBool(FALSE))
- e = e2->interpret(istate);
- else
- e = EXP_CANT_INTERPRET;
+ if (e->isBool(TRUE))
+ e = e1->interpret(istate);
+ else if (e->isBool(FALSE))
+ e = e2->interpret(istate);
+ else
+ e = EXP_CANT_INTERPRET;
}
return e;
}
@@ -2739,17 +2739,17 @@ Expression *ArrayLengthExp::interpret(InterState *istate)
#endif
e1 = this->e1->interpret(istate);
if (e1 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
if (e1->op == TOKstring || e1->op == TOKarrayliteral || e1->op == TOKassocarrayliteral)
{
- e = ArrayLength(type, e1);
+ e = ArrayLength(type, e1);
}
else if (e1->op == TOKnull)
{
- e = new IntegerExp(loc, 0, type);
+ e = new IntegerExp(loc, 0, type);
}
else
- goto Lcant;
+ goto Lcant;
return e;
Lcant:
@@ -2766,22 +2766,22 @@ Expression *IndexExp::interpret(InterState *istate)
#endif
e1 = this->e1->interpret(istate);
if (e1 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
if (e1->op == TOKstring || e1->op == TOKarrayliteral)
{
- /* Set the $ variable
- */
- e = ArrayLength(Type::tsize_t, e1);
- if (e == EXP_CANT_INTERPRET)
- goto Lcant;
- if (lengthVar)
- lengthVar->value = e;
+ /* Set the $ variable
+ */
+ e = ArrayLength(Type::tsize_t, e1);
+ if (e == EXP_CANT_INTERPRET)
+ goto Lcant;
+ if (lengthVar)
+ lengthVar->value = e;
}
e2 = this->e2->interpret(istate);
if (e2 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
return Index(type, e1, e2);
Lcant:
@@ -2800,29 +2800,29 @@ Expression *SliceExp::interpret(InterState *istate)
#endif
e1 = this->e1->interpret(istate);
if (e1 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
if (!this->lwr)
{
- e = e1->castTo(NULL, type);
- return e->interpret(istate);
+ e = e1->castTo(NULL, type);
+ return e->interpret(istate);
}
/* Set the $ variable
*/
e = ArrayLength(Type::tsize_t, e1);
if (e == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
if (lengthVar)
- lengthVar->value = e;
+ lengthVar->value = e;
/* Evaluate lower and upper bounds of slice
*/
lwr = this->lwr->interpret(istate);
if (lwr == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
upr = this->upr->interpret(istate);
if (upr == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
return Slice(type, e1, lwr, upr);
@@ -2842,11 +2842,11 @@ Expression *CatExp::interpret(InterState *istate)
e1 = this->e1->interpret(istate);
if (e1 == EXP_CANT_INTERPRET)
{
- goto Lcant;
+ goto Lcant;
}
e2 = this->e2->interpret(istate);
if (e2 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
return Cat(type, e1, e2);
Lcant:
@@ -2866,7 +2866,7 @@ Expression *CastExp::interpret(InterState *istate)
#endif
e1 = this->e1->interpret(istate);
if (e1 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
return Cast(type, to, e1);
Lcant:
@@ -2885,41 +2885,41 @@ Expression *AssertExp::interpret(InterState *istate)
printf("AssertExp::interpret() %s\n", toChars());
#endif
if( this->e1->op == TOKaddress)
- { // Special case: deal with compiler-inserted assert(&this, "null this")
- AddrExp *ade = (AddrExp *)this->e1;
- if (ade->e1->op == TOKthis && istate->localThis)
- if (ade->e1->op == TOKdotvar
- && ((DotVarExp *)(istate->localThis))->e1->op == TOKthis)
- return getVarExp(loc, istate, ((DotVarExp*)(istate->localThis))->var);
- else
- return istate->localThis->interpret(istate);
+ { // Special case: deal with compiler-inserted assert(&this, "null this")
+ AddrExp *ade = (AddrExp *)this->e1;
+ if (ade->e1->op == TOKthis && istate->localThis)
+ if (ade->e1->op == TOKdotvar
+ && ((DotVarExp *)(istate->localThis))->e1->op == TOKthis)
+ return getVarExp(loc, istate, ((DotVarExp*)(istate->localThis))->var);
+ else
+ return istate->localThis->interpret(istate);
}
if (this->e1->op == TOKthis)
{
- if (istate->localThis)
- return istate->localThis->interpret(istate);
+ if (istate->localThis)
+ return istate->localThis->interpret(istate);
}
e1 = this->e1->interpret(istate);
if (e1 == EXP_CANT_INTERPRET)
- goto Lcant;
+ goto Lcant;
if (e1->isBool(TRUE))
{
}
else if (e1->isBool(FALSE))
{
- if (msg)
- {
- e = msg->interpret(istate);
- if (e == EXP_CANT_INTERPRET)
- goto Lcant;
- error("%s", e->toChars());
- }
- else
- error("%s failed", toChars());
- goto Lcant;
+ if (msg)
+ {
+ e = msg->interpret(istate);
+ if (e == EXP_CANT_INTERPRET)
+ goto Lcant;
+ error("%s", e->toChars());
+ }
+ else
+ error("%s failed", toChars());
+ goto Lcant;
}
else
- goto Lcant;
+ goto Lcant;
return e1;
Lcant:
@@ -2935,51 +2935,51 @@ Expression *PtrExp::interpret(InterState *istate)
// Constant fold *(&structliteral + offset)
if (e1->op == TOKadd)
- { AddExp *ae = (AddExp *)e1;
- if (ae->e1->op == TOKaddress && ae->e2->op == TOKint64)
- { AddrExp *ade = (AddrExp *)ae->e1;
- Expression *ex = ade->e1;
- ex = ex->interpret(istate);
- if (ex != EXP_CANT_INTERPRET)
- {
- if (ex->op == TOKstructliteral)
- { StructLiteralExp *se = (StructLiteralExp *)ex;
- unsigned offset = ae->e2->toInteger();
- e = se->getField(type, offset);
- if (!e)
- e = EXP_CANT_INTERPRET;
- return e;
- }
- }
- }
- e = Ptr(type, e1);
+ { AddExp *ae = (AddExp *)e1;
+ if (ae->e1->op == TOKaddress && ae->e2->op == TOKint64)
+ { AddrExp *ade = (AddrExp *)ae->e1;
+ Expression *ex = ade->e1;
+ ex = ex->interpret(istate);
+ if (ex != EXP_CANT_INTERPRET)
+ {
+ if (ex->op == TOKstructliteral)
+ { StructLiteralExp *se = (StructLiteralExp *)ex;
+ unsigned offset = ae->e2->toInteger();
+ e = se->getField(type, offset);
+ if (!e)
+ e = EXP_CANT_INTERPRET;
+ return e;
+ }
+ }
+ }
+ e = Ptr(type, e1);
}
else if (e1->op == TOKsymoff)
- { SymOffExp *soe = (SymOffExp *)e1;
- VarDeclaration *v = soe->var->isVarDeclaration();
- if (v)
- { Expression *ev = getVarExp(loc, istate, v);
- if (ev != EXP_CANT_INTERPRET && ev->op == TOKstructliteral)
- { StructLiteralExp *se = (StructLiteralExp *)ev;
- e = se->getField(type, soe->offset);
- if (!e)
- e = EXP_CANT_INTERPRET;
- }
- }
+ { SymOffExp *soe = (SymOffExp *)e1;
+ VarDeclaration *v = soe->var->isVarDeclaration();
+ if (v)
+ { Expression *ev = getVarExp(loc, istate, v);
+ if (ev != EXP_CANT_INTERPRET && ev->op == TOKstructliteral)
+ { StructLiteralExp *se = (StructLiteralExp *)ev;
+ e = se->getField(type, soe->offset);
+ if (!e)
+ e = EXP_CANT_INTERPRET;
+ }
+ }
}
#if DMDV2
-#else // this is required for D1, where structs return *this instead of 'this'.
+#else // this is required for D1, where structs return *this instead of 'this'.
else if (e1->op == TOKthis)
{
- if(istate->localThis)
- return istate->localThis->interpret(istate);
+ if(istate->localThis)
+ return istate->localThis->interpret(istate);
}
-#endif
+#endif
else
error("Cannot interpret %s at compile time", toChars());
#if LOG
if (e == EXP_CANT_INTERPRET)
- printf("PtrExp::interpret() %s = EXP_CANT_INTERPRET\n", toChars());
+ printf("PtrExp::interpret() %s = EXP_CANT_INTERPRET\n", toChars());
#endif
return e;
}
@@ -2994,26 +2994,26 @@ Expression *DotVarExp::interpret(InterState *istate)
Expression *ex = e1->interpret(istate);
if (ex != EXP_CANT_INTERPRET)
{
- if (ex->op == TOKstructliteral)
- { StructLiteralExp *se = (StructLiteralExp *)ex;
- VarDeclaration *v = var->isVarDeclaration();
- if (v)
- { e = se->getField(type, v->offset);
- if (!e)
- {
- error("couldn't find field %s in %s", v->toChars(), type->toChars());
- e = EXP_CANT_INTERPRET;
- }
- return e;
- }
- }
- else
- error("%s.%s is not yet implemented at compile time", ex->toChars(), var->toChars());
+ if (ex->op == TOKstructliteral)
+ { StructLiteralExp *se = (StructLiteralExp *)ex;
+ VarDeclaration *v = var->isVarDeclaration();
+ if (v)
+ { e = se->getField(type, v->offset);
+ if (!e)
+ {
+ error("couldn't find field %s in %s", v->toChars(), type->toChars());
+ e = EXP_CANT_INTERPRET;
+ }
+ return e;
+ }
+ }
+ else
+ error("%s.%s is not yet implemented at compile time", ex->toChars(), var->toChars());
}
#if LOG
if (e == EXP_CANT_INTERPRET)
- printf("DotVarExp::interpret() %s = EXP_CANT_INTERPRET\n", toChars());
+ printf("DotVarExp::interpret() %s = EXP_CANT_INTERPRET\n", toChars());
#endif
return e;
}
@@ -3025,13 +3025,13 @@ Expression *DotVarExp::interpret(InterState *istate)
Expression *interpret_aaLen(InterState *istate, Expressions *arguments)
{
if (!arguments || arguments->dim != 1)
- return NULL;
+ return NULL;
Expression *earg = (Expression *)arguments->data[0];
earg = earg->interpret(istate);
if (earg == EXP_CANT_INTERPRET)
- return NULL;
+ return NULL;
if (earg->op != TOKassocarrayliteral)
- return NULL;
+ return NULL;
AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg;
Expression *e = new IntegerExp(aae->loc, aae->keys->dim, Type::tsize_t);
return e;
@@ -3043,13 +3043,13 @@ Expression *interpret_aaKeys(InterState *istate, Expressions *arguments)
printf("interpret_aaKeys()\n");
#endif
if (!arguments || arguments->dim != 2)
- return NULL;
+ return NULL;
Expression *earg = (Expression *)arguments->data[0];
earg = earg->interpret(istate);
if (earg == EXP_CANT_INTERPRET)
- return NULL;
+ return NULL;
if (earg->op != TOKassocarrayliteral)
- return NULL;
+ return NULL;
AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg;
Expression *e = new ArrayLiteralExp(aae->loc, aae->keys);
Type *elemType = ((TypeAArray *)aae->type)->index;
@@ -3061,13 +3061,13 @@ Expression *interpret_aaValues(InterState *istate, Expressions *arguments)
{
//printf("interpret_aaValues()\n");
if (!arguments || arguments->dim != 3)
- return NULL;
+ return NULL;
Expression *earg = (Expression *)arguments->data[0];
earg = earg->interpret(istate);
if (earg == EXP_CANT_INTERPRET)
- return NULL;
+ return NULL;
if (earg->op != TOKassocarrayliteral)
- return NULL;
+ return NULL;
AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg;
Expression *e = new ArrayLiteralExp(aae->loc, aae->values);
Type *elemType = ((TypeAArray *)aae->type)->next;
@@ -3085,9 +3085,9 @@ Expression *interpret_length(InterState *istate, Expression *earg)
//printf("interpret_length()\n");
earg = earg->interpret(istate);
if (earg == EXP_CANT_INTERPRET)
- return NULL;
+ return NULL;
if (earg->op != TOKassocarrayliteral)
- return NULL;
+ return NULL;
AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg;
Expression *e = new IntegerExp(aae->loc, aae->keys->dim, Type::tsize_t);
return e;
@@ -3100,9 +3100,9 @@ Expression *interpret_keys(InterState *istate, Expression *earg, FuncDeclaration
#endif
earg = earg->interpret(istate);
if (earg == EXP_CANT_INTERPRET)
- return NULL;
+ return NULL;
if (earg->op != TOKassocarrayliteral)
- return NULL;
+ return NULL;
AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg;
Expression *e = new ArrayLiteralExp(aae->loc, aae->keys);
assert(fd->type->ty == Tfunction);
@@ -3117,9 +3117,9 @@ Expression *interpret_values(InterState *istate, Expression *earg, FuncDeclarati
//printf("interpret_values()\n");
earg = earg->interpret(istate);
if (earg == EXP_CANT_INTERPRET)
- return NULL;
+ return NULL;
if (earg->op != TOKassocarrayliteral)
- return NULL;
+ return NULL;
AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg;
Expression *e = new ArrayLiteralExp(aae->loc, aae->values);
assert(fd->type->ty == Tfunction);
diff --git a/dmd/json.c b/dmd/json.c
index e147765d..d445d862 100644
--- a/dmd/json.c
+++ b/dmd/json.c
@@ -51,11 +51,11 @@ void json_generate(Array *modules)
buf.writestring("[\n");
for (int i = 0; i < modules->dim; i++)
- { Module *m = (Module *)modules->data[i];
- if (global.params.verbose)
- printf("json gen %s\n", m->toChars());
- m->toJsonBuffer(&buf);
- buf.writestring(",\n");
+ { Module *m = (Module *)modules->data[i];
+ if (global.params.verbose)
+ printf("json gen %s\n", m->toChars());
+ m->toJsonBuffer(&buf);
+ buf.writestring(",\n");
}
JsonRemoveComma(&buf);
buf.writestring("]\n");
@@ -71,9 +71,9 @@ void json_generate(Array *modules)
arg = fn->toChars();
}
else if (arg[0] == '-' && arg[1] == 0)
- { // Write to stdout
- fwrite(buf.data, 1, buf.offset, stdout);
- return;
+ { // Write to stdout
+ fwrite(buf.data, 1, buf.offset, stdout);
+ return;
}
// if (!FileName::absolute(arg))
// arg = FileName::combine(dir, arg);
@@ -84,7 +84,7 @@ void json_generate(Array *modules)
jsonfile->ref = 1;
char *pt = FileName::path(jsonfile->toChars());
if (*pt)
- FileName::ensurePathExists(pt);
+ FileName::ensurePathExists(pt);
mem.free(pt);
jsonfile->writev();
}
@@ -98,49 +98,49 @@ void JsonString(OutBuffer *buf, const char *s)
buf->writeByte('\"');
for (; *s; s++)
{
- unsigned char c = (unsigned char) *s;
- switch (c)
- {
- case '\n':
- buf->writestring("\\n");
- break;
+ unsigned char c = (unsigned char) *s;
+ switch (c)
+ {
+ case '\n':
+ buf->writestring("\\n");
+ break;
- case '\r':
- buf->writestring("\\r");
- break;
+ case '\r':
+ buf->writestring("\\r");
+ break;
- case '\t':
- buf->writestring("\\t");
- break;
+ case '\t':
+ buf->writestring("\\t");
+ break;
- case '\"':
- buf->writestring("\\\"");
- break;
+ case '\"':
+ buf->writestring("\\\"");
+ break;
- case '\\':
- buf->writestring("\\\\");
- break;
+ case '\\':
+ buf->writestring("\\\\");
+ break;
- case '/':
- buf->writestring("\\/");
- break;
+ case '/':
+ buf->writestring("\\/");
+ break;
- case '\b':
- buf->writestring("\\b");
- break;
+ case '\b':
+ buf->writestring("\\b");
+ break;
- case '\f':
- buf->writestring("\\f");
- break;
+ case '\f':
+ buf->writestring("\\f");
+ break;
- default:
- if (c < 0x20)
- buf->printf("\\u%04x", c);
- else
- // Note that UTF-8 chars pass through here just fine
- buf->writeByte(c);
- break;
- }
+ default:
+ if (c < 0x20)
+ buf->printf("\\u%04x", c);
+ else
+ // Note that UTF-8 chars pass through here just fine
+ buf->writeByte(c);
+ break;
+ }
}
buf->writeByte('\"');
}
@@ -164,9 +164,9 @@ void JsonProperty(OutBuffer *buf, const char *name, int value)
void JsonRemoveComma(OutBuffer *buf)
{
if (buf->offset >= 2 &&
- buf->data[buf->offset - 2] == ',' &&
- buf->data[buf->offset - 1] == '\n')
- buf->offset -= 2;
+ buf->data[buf->offset - 2] == ',' &&
+ buf->data[buf->offset - 1] == '\n')
+ buf->offset -= 2;
}
void Dsymbol::toJsonBuffer(OutBuffer *buf)
@@ -178,26 +178,26 @@ void Module::toJsonBuffer(OutBuffer *buf)
buf->writestring("{\n");
if (md)
- JsonProperty(buf, Pname, md->toChars());
+ JsonProperty(buf, Pname, md->toChars());
JsonProperty(buf, Pkind, kind());
JsonProperty(buf, Pfile, srcfile->toChars());
if (comment)
- JsonProperty(buf, Pcomment, (const char *)comment);
+ JsonProperty(buf, Pcomment, (const char *)comment);
JsonString(buf, Pmembers);
buf->writestring(" : [\n");
size_t offset = buf->offset;
for (int i = 0; i < members->dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- if (offset != buf->offset)
- { buf->writestring(",\n");
- offset = buf->offset;
- }
- s->toJsonBuffer(buf);
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ if (offset != buf->offset)
+ { buf->writestring(",\n");
+ offset = buf->offset;
+ }
+ s->toJsonBuffer(buf);
}
JsonRemoveComma(buf);
@@ -214,11 +214,11 @@ void AttribDeclaration::toJsonBuffer(OutBuffer *buf)
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
- //printf("AttribDeclaration::toJsonBuffer %s\n", s->toChars());
- s->toJsonBuffer(buf);
- }
+ for (unsigned i = 0; i < d->dim; i++)
+ { Dsymbol *s = (Dsymbol *)d->data[i];
+ //printf("AttribDeclaration::toJsonBuffer %s\n", s->toChars());
+ s->toJsonBuffer(buf);
+ }
}
}
@@ -228,7 +228,7 @@ void ConditionalDeclaration::toJsonBuffer(OutBuffer *buf)
//printf("ConditionalDeclaration::toJsonBuffer()\n");
if (condition->inc)
{
- AttribDeclaration::toJsonBuffer(buf);
+ AttribDeclaration::toJsonBuffer(buf);
}
}
@@ -252,18 +252,18 @@ void Declaration::toJsonBuffer(OutBuffer *buf)
JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());
if (type)
- JsonProperty(buf, Ptype, type->toChars());
+ JsonProperty(buf, Ptype, type->toChars());
if (comment)
- JsonProperty(buf, Pcomment, (const char *)comment);
+ JsonProperty(buf, Pcomment, (const char *)comment);
if (loc.linnum)
- JsonProperty(buf, Pline, loc.linnum);
+ JsonProperty(buf, Pline, loc.linnum);
TypedefDeclaration *td = isTypedefDeclaration();
if (td)
{
- JsonProperty(buf, "base", td->basetype->toChars());
+ JsonProperty(buf, "base", td->basetype->toChars());
}
JsonRemoveComma(buf);
@@ -278,45 +278,45 @@ void AggregateDeclaration::toJsonBuffer(OutBuffer *buf)
JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());
if (comment)
- JsonProperty(buf, Pcomment, (const char *)comment);
+ JsonProperty(buf, Pcomment, (const char *)comment);
if (loc.linnum)
- JsonProperty(buf, Pline, loc.linnum);
+ JsonProperty(buf, Pline, loc.linnum);
ClassDeclaration *cd = isClassDeclaration();
if (cd)
{
- if (cd->baseClass)
- {
- JsonProperty(buf, "base", cd->baseClass->toChars());
- }
- if (cd->interfaces_dim)
- {
- JsonString(buf, "interfaces");
- buf->writestring(" : [\n");
- size_t offset = buf->offset;
- for (int i = 0; i < cd->interfaces_dim; i++)
- { BaseClass *b = cd->interfaces[i];
- if (offset != buf->offset)
- { buf->writestring(",\n");
- offset = buf->offset;
- }
- JsonString(buf, b->base->toChars());
- }
- JsonRemoveComma(buf);
- buf->writestring("],\n");
- }
+ if (cd->baseClass)
+ {
+ JsonProperty(buf, "base", cd->baseClass->toChars());
+ }
+ if (cd->interfaces_dim)
+ {
+ JsonString(buf, "interfaces");
+ buf->writestring(" : [\n");
+ size_t offset = buf->offset;
+ for (int i = 0; i < cd->interfaces_dim; i++)
+ { BaseClass *b = cd->interfaces[i];
+ if (offset != buf->offset)
+ { buf->writestring(",\n");
+ offset = buf->offset;
+ }
+ JsonString(buf, b->base->toChars());
+ }
+ JsonRemoveComma(buf);
+ buf->writestring("],\n");
+ }
}
JsonString(buf, Pmembers);
buf->writestring(" : [\n");
size_t offset = buf->offset;
for (int i = 0; i < members->dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- if (offset != buf->offset)
- { buf->writestring(",\n");
- offset = buf->offset;
- }
- s->toJsonBuffer(buf);
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ if (offset != buf->offset)
+ { buf->writestring(",\n");
+ offset = buf->offset;
+ }
+ s->toJsonBuffer(buf);
}
JsonRemoveComma(buf);
buf->writestring("]\n");
@@ -333,21 +333,21 @@ void TemplateDeclaration::toJsonBuffer(OutBuffer *buf)
JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());
if (comment)
- JsonProperty(buf, Pcomment, (const char *)comment);
+ JsonProperty(buf, Pcomment, (const char *)comment);
if (loc.linnum)
- JsonProperty(buf, Pline, loc.linnum);
+ JsonProperty(buf, Pline, loc.linnum);
JsonString(buf, Pmembers);
buf->writestring(" : [\n");
size_t offset = buf->offset;
for (int i = 0; i < members->dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- if (offset != buf->offset)
- { buf->writestring(",\n");
- offset = buf->offset;
- }
- s->toJsonBuffer(buf);
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ if (offset != buf->offset)
+ { buf->writestring(",\n");
+ offset = buf->offset;
+ }
+ s->toJsonBuffer(buf);
}
JsonRemoveComma(buf);
buf->writestring("]\n");
@@ -360,17 +360,17 @@ void EnumDeclaration::toJsonBuffer(OutBuffer *buf)
//printf("EnumDeclaration::toJsonBuffer()\n");
if (isAnonymous())
{
- if (members)
- {
- for (int i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->toJsonBuffer(buf);
- buf->writestring(",\n");
- }
- JsonRemoveComma(buf);
- }
- return;
+ if (members)
+ {
+ for (int i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->toJsonBuffer(buf);
+ buf->writestring(",\n");
+ }
+ JsonRemoveComma(buf);
+ }
+ return;
}
buf->writestring("{\n");
@@ -378,24 +378,24 @@ void EnumDeclaration::toJsonBuffer(OutBuffer *buf)
JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());
if (comment)
- JsonProperty(buf, Pcomment, (const char *)comment);
+ JsonProperty(buf, Pcomment, (const char *)comment);
if (loc.linnum)
- JsonProperty(buf, Pline, loc.linnum);
+ JsonProperty(buf, Pline, loc.linnum);
if (memtype)
- JsonProperty(buf, "base", memtype->toChars());
+ JsonProperty(buf, "base", memtype->toChars());
JsonString(buf, Pmembers);
buf->writestring(" : [\n");
size_t offset = buf->offset;
for (int i = 0; i < members->dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- if (offset != buf->offset)
- { buf->writestring(",\n");
- offset = buf->offset;
- }
- s->toJsonBuffer(buf);
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ if (offset != buf->offset)
+ { buf->writestring(",\n");
+ offset = buf->offset;
+ }
+ s->toJsonBuffer(buf);
}
JsonRemoveComma(buf);
buf->writestring("]\n");
@@ -412,10 +412,10 @@ void EnumMember::toJsonBuffer(OutBuffer *buf)
JsonProperty(buf, Pkind, kind());
if (comment)
- JsonProperty(buf, Pcomment, (const char *)comment);
+ JsonProperty(buf, Pcomment, (const char *)comment);
if (loc.linnum)
- JsonProperty(buf, Pline, loc.linnum);
+ JsonProperty(buf, Pline, loc.linnum);
JsonRemoveComma(buf);
buf->writestring("}\n");
diff --git a/dmd/lexer.c b/dmd/lexer.c
index ce883fa8..c070a77a 100644
--- a/dmd/lexer.c
+++ b/dmd/lexer.c
@@ -26,7 +26,7 @@
#include
#include
#include
-#include // for time() and ctime()
+#include // for time() and ctime()
#include "rmem.h"
@@ -45,8 +45,8 @@ extern "C" char * __cdecl __locale_decpoint;
extern int HtmlNamedEntity(unsigned char *p, int length);
-#define LS 0x2028 // UTF line separator
-#define PS 0x2029 // UTF paragraph separator
+#define LS 0x2028 // UTF line separator
+#define PS 0x2029 // UTF paragraph separator
/********************************************
* Do our own char maps
@@ -54,9 +54,9 @@ extern int HtmlNamedEntity(unsigned char *p, int length);
static unsigned char cmtable[256];
-const int CMoctal = 0x1;
-const int CMhex = 0x2;
-const int CMidchar = 0x4;
+const int CMoctal = 0x1;
+const int CMhex = 0x2;
+const int CMidchar = 0x4;
inline unsigned char isoctal (unsigned char c) { return cmtable[c] & CMoctal; }
inline unsigned char ishex (unsigned char c) { return cmtable[c] & CMhex; }
@@ -66,12 +66,12 @@ static void cmtable_init()
{
for (unsigned c = 0; c < sizeof(cmtable) / sizeof(cmtable[0]); c++)
{
- if ('0' <= c && c <= '7')
- cmtable[c] |= CMoctal;
- if (isdigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'))
- cmtable[c] |= CMhex;
- if (isalnum(c) || c == '_')
- cmtable[c] |= CMidchar;
+ if ('0' <= c && c <= '7')
+ cmtable[c] |= CMoctal;
+ if (isdigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'))
+ cmtable[c] |= CMhex;
+ if (isalnum(c) || c == '_')
+ cmtable[c] |= CMidchar;
}
}
@@ -85,9 +85,9 @@ void *Token::operator new(size_t size)
if (Lexer::freelist)
{
- t = Lexer::freelist;
- Lexer::freelist = t->next;
- return t;
+ t = Lexer::freelist;
+ Lexer::freelist = t->next;
+ return t;
}
return ::operator new(size);
@@ -107,116 +107,116 @@ const char *Token::toChars()
p = buffer;
switch (value)
{
- case TOKint32v:
- sprintf(buffer,"%d",(d_int32)int64value);
- break;
+ case TOKint32v:
+ sprintf(buffer,"%d",(d_int32)int64value);
+ break;
- case TOKuns32v:
- case TOKcharv:
- case TOKwcharv:
- case TOKdcharv:
- sprintf(buffer,"%uU",(d_uns32)uns64value);
- break;
+ case TOKuns32v:
+ case TOKcharv:
+ case TOKwcharv:
+ case TOKdcharv:
+ sprintf(buffer,"%uU",(d_uns32)uns64value);
+ break;
- case TOKint64v:
- sprintf(buffer,"%jdL",int64value);
- break;
+ case TOKint64v:
+ sprintf(buffer,"%jdL",int64value);
+ break;
- case TOKuns64v:
- sprintf(buffer,"%juUL",uns64value);
- break;
+ case TOKuns64v:
+ sprintf(buffer,"%juUL",uns64value);
+ break;
#if IN_GCC
- case TOKfloat32v:
- case TOKfloat64v:
- case TOKfloat80v:
- float80value.format(buffer, sizeof(buffer));
- break;
- case TOKimaginary32v:
- case TOKimaginary64v:
- case TOKimaginary80v:
- float80value.format(buffer, sizeof(buffer));
- // %% buffer
- strcat(buffer, "i");
- break;
+ case TOKfloat32v:
+ case TOKfloat64v:
+ case TOKfloat80v:
+ float80value.format(buffer, sizeof(buffer));
+ break;
+ case TOKimaginary32v:
+ case TOKimaginary64v:
+ case TOKimaginary80v:
+ float80value.format(buffer, sizeof(buffer));
+ // %% buffer
+ strcat(buffer, "i");
+ break;
#else
- case TOKfloat32v:
- sprintf(buffer,"%Lgf", float80value);
- break;
+ case TOKfloat32v:
+ sprintf(buffer,"%Lgf", float80value);
+ break;
- case TOKfloat64v:
- sprintf(buffer,"%Lg", float80value);
- break;
+ case TOKfloat64v:
+ sprintf(buffer,"%Lg", float80value);
+ break;
- case TOKfloat80v:
- sprintf(buffer,"%LgL", float80value);
- break;
+ case TOKfloat80v:
+ sprintf(buffer,"%LgL", float80value);
+ break;
- case TOKimaginary32v:
- sprintf(buffer,"%Lgfi", float80value);
- break;
+ case TOKimaginary32v:
+ sprintf(buffer,"%Lgfi", float80value);
+ break;
- case TOKimaginary64v:
- sprintf(buffer,"%Lgi", float80value);
- break;
+ case TOKimaginary64v:
+ sprintf(buffer,"%Lgi", float80value);
+ break;
- case TOKimaginary80v:
- sprintf(buffer,"%LgLi", float80value);
- break;
+ case TOKimaginary80v:
+ sprintf(buffer,"%LgLi", float80value);
+ break;
#endif
- case TOKstring:
+ case TOKstring:
#if CSTRINGS
- p = string;
+ p = string;
#else
- { OutBuffer buf;
+ { OutBuffer buf;
- buf.writeByte('"');
- for (size_t i = 0; i < len; )
- { unsigned c;
+ buf.writeByte('"');
+ for (size_t i = 0; i < len; )
+ { unsigned c;
- utf_decodeChar((unsigned char *)ustring, len, &i, &c);
- switch (c)
- {
- case 0:
- break;
+ utf_decodeChar((unsigned char *)ustring, len, &i, &c);
+ switch (c)
+ {
+ case 0:
+ break;
- case '"':
- case '\\':
- buf.writeByte('\\');
- default:
- if (isprint(c))
- buf.writeByte(c);
- else if (c <= 0x7F)
- buf.printf("\\x%02x", c);
- else if (c <= 0xFFFF)
- buf.printf("\\u%04x", c);
- else
- buf.printf("\\U%08x", c);
- continue;
- }
- break;
- }
- buf.writeByte('"');
- if (postfix)
- buf.writeByte('"');
- buf.writeByte(0);
- p = (char *)buf.extractData();
- }
+ case '"':
+ case '\\':
+ buf.writeByte('\\');
+ default:
+ if (isprint(c))
+ buf.writeByte(c);
+ else if (c <= 0x7F)
+ buf.printf("\\x%02x", c);
+ else if (c <= 0xFFFF)
+ buf.printf("\\u%04x", c);
+ else
+ buf.printf("\\U%08x", c);
+ continue;
+ }
+ break;
+ }
+ buf.writeByte('"');
+ if (postfix)
+ buf.writeByte('"');
+ buf.writeByte(0);
+ p = (char *)buf.extractData();
+ }
#endif
- break;
+ break;
- case TOKidentifier:
- case TOKenum:
- case TOKstruct:
- case TOKimport:
- case BASIC_TYPES:
- p = ident->toChars();
- break;
+ case TOKidentifier:
+ case TOKenum:
+ case TOKstruct:
+ case TOKimport:
+ case BASIC_TYPES:
+ p = ident->toChars();
+ break;
- default:
- p = toChars(value);
- break;
+ default:
+ p = toChars(value);
+ break;
}
return p;
}
@@ -227,8 +227,8 @@ const char *Token::toChars(enum TOK value)
p = tochars[value];
if (!p)
- { sprintf(buffer,"TOK%d",value);
- p = buffer;
+ { sprintf(buffer,"TOK%d",value);
+ p = buffer;
}
return p;
}
@@ -240,8 +240,8 @@ StringTable Lexer::stringtable;
OutBuffer Lexer::stringbuffer;
Lexer::Lexer(Module *mod,
- unsigned char *base, unsigned begoffset, unsigned endoffset,
- int doDocComment, int commentToken)
+ unsigned char *base, unsigned begoffset, unsigned endoffset,
+ int doDocComment, int commentToken)
: loc(mod, 1)
{
//printf("Lexer::Lexer(%p,%d)\n",base,length);
@@ -261,37 +261,37 @@ Lexer::Lexer(Module *mod,
if (p[0] == '#' && p[1] =='!')
{
- p += 2;
- while (1)
- { unsigned char c = *p;
- switch (c)
- {
- case '\n':
- p++;
- break;
+ p += 2;
+ while (1)
+ { unsigned char c = *p;
+ switch (c)
+ {
+ case '\n':
+ p++;
+ break;
- case '\r':
- p++;
- if (*p == '\n')
- p++;
- break;
+ case '\r':
+ p++;
+ if (*p == '\n')
+ p++;
+ break;
- case 0:
- case 0x1A:
- break;
+ case 0:
+ case 0x1A:
+ break;
- default:
- if (c & 0x80)
- { unsigned u = decodeUTF();
- if (u == PS || u == LS)
- break;
- }
- p++;
- continue;
- }
- break;
- }
- loc.linnum = 2;
+ default:
+ if (c & 0x80)
+ { unsigned u = decodeUTF();
+ if (u == PS || u == LS)
+ break;
+ }
+ p++;
+ continue;
+ }
+ break;
+ }
+ loc.linnum = 2;
}
}
@@ -300,21 +300,21 @@ void Lexer::error(const char *format, ...)
{
if (mod && !global.gag)
{
- char *p = loc.toChars();
- if (*p)
- fprintf(stdmsg, "%s: ", p);
- mem.free(p);
+ char *p = loc.toChars();
+ if (*p)
+ fprintf(stdmsg, "%s: ", p);
+ mem.free(p);
- va_list ap;
- va_start(ap, format);
- vfprintf(stdmsg, format, ap);
- va_end(ap);
+ va_list ap;
+ va_start(ap, format);
+ vfprintf(stdmsg, format, ap);
+ va_end(ap);
- fprintf(stdmsg, "\n");
- fflush(stdmsg);
+ fprintf(stdmsg, "\n");
+ fflush(stdmsg);
- if (global.errors >= 20) // moderate blizzard of cascading messages
- fatal();
+ if (global.errors >= 20) // moderate blizzard of cascading messages
+ fatal();
}
global.errors++;
}
@@ -323,21 +323,21 @@ void Lexer::error(Loc loc, const char *format, ...)
{
if (mod && !global.gag)
{
- char *p = loc.toChars();
- if (*p)
- fprintf(stdmsg, "%s: ", p);
- mem.free(p);
+ char *p = loc.toChars();
+ if (*p)
+ fprintf(stdmsg, "%s: ", p);
+ mem.free(p);
- va_list ap;
- va_start(ap, format);
- vfprintf(stdmsg, format, ap);
- va_end(ap);
+ va_list ap;
+ va_start(ap, format);
+ vfprintf(stdmsg, format, ap);
+ va_end(ap);
- fprintf(stdmsg, "\n");
- fflush(stdmsg);
+ fprintf(stdmsg, "\n");
+ fflush(stdmsg);
- if (global.errors >= 20) // moderate blizzard of cascading messages
- fatal();
+ if (global.errors >= 20) // moderate blizzard of cascading messages
+ fatal();
}
global.errors++;
}
@@ -347,14 +347,14 @@ TOK Lexer::nextToken()
if (token.next)
{
- t = token.next;
- memcpy(&token,t,sizeof(Token));
- t->next = freelist;
- freelist = t;
+ t = token.next;
+ memcpy(&token,t,sizeof(Token));
+ t->next = freelist;
+ freelist = t;
}
else
{
- scan(&token);
+ scan(&token);
}
//token.print();
return token.value;
@@ -364,13 +364,13 @@ Token *Lexer::peek(Token *ct)
{ Token *t;
if (ct->next)
- t = ct->next;
+ t = ct->next;
else
{
- t = new Token();
- scan(t);
- t->next = NULL;
- ct->next = t;
+ t = new Token();
+ scan(t);
+ t->next = NULL;
+ ct->next = t;
}
return t;
}
@@ -396,42 +396,42 @@ Token *Lexer::peekPastParen(Token *tk)
int curlynest = 0;
while (1)
{
- tk = peek(tk);
- //tk->print();
- switch (tk->value)
- {
- case TOKlparen:
- parens++;
- continue;
+ tk = peek(tk);
+ //tk->print();
+ switch (tk->value)
+ {
+ case TOKlparen:
+ parens++;
+ continue;
- case TOKrparen:
- --parens;
- if (parens)
- continue;
- tk = peek(tk);
- break;
+ case TOKrparen:
+ --parens;
+ if (parens)
+ continue;
+ tk = peek(tk);
+ break;
- case TOKlcurly:
- curlynest++;
- continue;
+ case TOKlcurly:
+ curlynest++;
+ continue;
- case TOKrcurly:
- if (--curlynest >= 0)
- continue;
- break;
+ case TOKrcurly:
+ if (--curlynest >= 0)
+ continue;
+ break;
- case TOKsemicolon:
- if (curlynest)
- continue;
- break;
+ case TOKsemicolon:
+ if (curlynest)
+ continue;
+ break;
- case TOKeof:
- break;
+ case TOKeof:
+ break;
- default:
- continue;
- }
- return tk;
+ default:
+ continue;
+ }
+ return tk;
}
}
@@ -439,7 +439,7 @@ Token *Lexer::peekPastParen(Token *tk)
* Determine if string is a valid Identifier.
* Placed here because of commonality with Lexer functionality.
* Returns:
- * 0 invalid
+ * 0 invalid
*/
int Lexer::isValidIdentifier(char *p)
@@ -448,22 +448,22 @@ int Lexer::isValidIdentifier(char *p)
size_t idx;
if (!p || !*p)
- goto Linvalid;
+ goto Linvalid;
- if (*p >= '0' && *p <= '9') // beware of isdigit() on signed chars
- goto Linvalid;
+ if (*p >= '0' && *p <= '9') // beware of isdigit() on signed chars
+ goto Linvalid;
len = strlen(p);
idx = 0;
while (p[idx])
{ dchar_t dc;
- const char *q = utf_decodeChar((unsigned char *)p, len, &idx, &dc);
- if (q)
- goto Linvalid;
+ const char *q = utf_decodeChar((unsigned char *)p, len, &idx, &dc);
+ if (q)
+ goto Linvalid;
- if (!((dc >= 0x80 && isUniAlpha(dc)) || isalnum(dc) || dc == '_'))
- goto Linvalid;
+ if (!((dc >= 0x80 && isUniAlpha(dc)) || isalnum(dc) || dc == '_'))
+ goto Linvalid;
}
return 1;
@@ -484,733 +484,733 @@ void Lexer::scan(Token *t)
t->lineComment = NULL;
while (1)
{
- t->ptr = p;
- //printf("p = %p, *p = '%c'\n",p,*p);
- switch (*p)
- {
- case 0:
- case 0x1A:
- t->value = TOKeof; // end of file
- return;
+ t->ptr = p;
+ //printf("p = %p, *p = '%c'\n",p,*p);
+ switch (*p)
+ {
+ case 0:
+ case 0x1A:
+ t->value = TOKeof; // end of file
+ return;
- case ' ':
- case '\t':
- case '\v':
- case '\f':
- p++;
- continue; // skip white space
+ case ' ':
+ case '\t':
+ case '\v':
+ case '\f':
+ p++;
+ continue; // skip white space
- case '\r':
- p++;
- if (*p != '\n') // if CR stands by itself
- loc.linnum++;
- continue; // skip white space
+ case '\r':
+ p++;
+ if (*p != '\n') // if CR stands by itself
+ loc.linnum++;
+ continue; // skip white space
- case '\n':
- p++;
- loc.linnum++;
- continue; // skip white space
+ case '\n':
+ p++;
+ loc.linnum++;
+ continue; // skip white space
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- t->value = number(t);
- return;
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ t->value = number(t);
+ return;
#if CSTRINGS
- case '\'':
- t->value = charConstant(t, 0);
- return;
+ case '\'':
+ t->value = charConstant(t, 0);
+ return;
- case '"':
- t->value = stringConstant(t,0);
- return;
+ case '"':
+ t->value = stringConstant(t,0);
+ return;
- case 'l':
- case 'L':
- if (p[1] == '\'')
- {
- p++;
- t->value = charConstant(t, 1);
- return;
- }
- else if (p[1] == '"')
- {
- p++;
- t->value = stringConstant(t, 1);
- return;
- }
+ case 'l':
+ case 'L':
+ if (p[1] == '\'')
+ {
+ p++;
+ t->value = charConstant(t, 1);
+ return;
+ }
+ else if (p[1] == '"')
+ {
+ p++;
+ t->value = stringConstant(t, 1);
+ return;
+ }
#else
- case '\'':
- t->value = charConstant(t,0);
- return;
+ case '\'':
+ t->value = charConstant(t,0);
+ return;
- case 'r':
- if (p[1] != '"')
- goto case_ident;
- p++;
- case '`':
- t->value = wysiwygStringConstant(t, *p);
- return;
+ case 'r':
+ if (p[1] != '"')
+ goto case_ident;
+ p++;
+ case '`':
+ t->value = wysiwygStringConstant(t, *p);
+ return;
- case 'x':
- if (p[1] != '"')
- goto case_ident;
- p++;
- t->value = hexStringConstant(t);
- return;
+ case 'x':
+ if (p[1] != '"')
+ goto case_ident;
+ p++;
+ t->value = hexStringConstant(t);
+ return;
#if DMDV2
- case 'q':
- if (p[1] == '"')
- {
- p++;
- t->value = delimitedStringConstant(t);
- return;
- }
- else if (p[1] == '{')
- {
- p++;
- t->value = tokenStringConstant(t);
- return;
- }
- else
- goto case_ident;
+ case 'q':
+ if (p[1] == '"')
+ {
+ p++;
+ t->value = delimitedStringConstant(t);
+ return;
+ }
+ else if (p[1] == '{')
+ {
+ p++;
+ t->value = tokenStringConstant(t);
+ return;
+ }
+ else
+ goto case_ident;
#endif
- case '"':
- t->value = escapeStringConstant(t,0);
- return;
+ case '"':
+ t->value = escapeStringConstant(t,0);
+ return;
- case '\\': // escaped string literal
- { unsigned c;
+ case '\\': // escaped string literal
+ { unsigned c;
- stringbuffer.reset();
- do
- {
- p++;
- switch (*p)
- {
- case 'u':
- case 'U':
- case '&':
- c = escapeSequence();
- stringbuffer.writeUTF8(c);
- break;
+ stringbuffer.reset();
+ do
+ {
+ p++;
+ switch (*p)
+ {
+ case 'u':
+ case 'U':
+ case '&':
+ c = escapeSequence();
+ stringbuffer.writeUTF8(c);
+ break;
- default:
- c = escapeSequence();
- stringbuffer.writeByte(c);
- break;
- }
- } while (*p == '\\');
- t->len = stringbuffer.offset;
- stringbuffer.writeByte(0);
- t->ustring = (unsigned char *)mem.malloc(stringbuffer.offset);
- memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
- t->postfix = 0;
- t->value = TOKstring;
- return;
- }
+ default:
+ c = escapeSequence();
+ stringbuffer.writeByte(c);
+ break;
+ }
+ } while (*p == '\\');
+ t->len = stringbuffer.offset;
+ stringbuffer.writeByte(0);
+ t->ustring = (unsigned char *)mem.malloc(stringbuffer.offset);
+ memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
+ t->postfix = 0;
+ t->value = TOKstring;
+ return;
+ }
- case 'l':
- case 'L':
+ case 'l':
+ case 'L':
#endif
- case 'a': case 'b': case 'c': case 'd': case 'e':
- case 'f': case 'g': case 'h': case 'i': case 'j':
- case 'k': case 'm': case 'n': case 'o':
+ case 'a': case 'b': case 'c': case 'd': case 'e':
+ case 'f': case 'g': case 'h': case 'i': case 'j':
+ case 'k': case 'm': case 'n': case 'o':
#if DMDV2
- case 'p': /*case 'q': case 'r':*/ case 's': case 't':
+ case 'p': /*case 'q': case 'r':*/ case 's': case 't':
#else
- case 'p': case 'q': /*case 'r':*/ case 's': case 't':
+ case 'p': case 'q': /*case 'r':*/ case 's': case 't':
#endif
- case 'u': case 'v': case 'w': /*case 'x':*/ case 'y':
- case 'z':
- case 'A': case 'B': case 'C': case 'D': case 'E':
- case 'F': case 'G': case 'H': case 'I': case 'J':
- case 'K': case 'M': case 'N': case 'O':
- case 'P': case 'Q': case 'R': case 'S': case 'T':
- case 'U': case 'V': case 'W': case 'X': case 'Y':
- case 'Z':
- case '_':
- case_ident:
- { unsigned char c;
+ case 'u': case 'v': case 'w': /*case 'x':*/ case 'y':
+ case 'z':
+ case 'A': case 'B': case 'C': case 'D': case 'E':
+ case 'F': case 'G': case 'H': case 'I': case 'J':
+ case 'K': case 'M': case 'N': case 'O':
+ case 'P': case 'Q': case 'R': case 'S': case 'T':
+ case 'U': case 'V': case 'W': case 'X': case 'Y':
+ case 'Z':
+ case '_':
+ case_ident:
+ { unsigned char c;
- while (1)
- {
- c = *++p;
- if (isidchar(c))
- continue;
- else if (c & 0x80)
- { unsigned char *s = p;
- unsigned u = decodeUTF();
- if (isUniAlpha(u))
- continue;
- error("char 0x%04x not allowed in identifier", u);
- p = s;
- }
- break;
- }
+ while (1)
+ {
+ c = *++p;
+ if (isidchar(c))
+ continue;
+ else if (c & 0x80)
+ { unsigned char *s = p;
+ unsigned u = decodeUTF();
+ if (isUniAlpha(u))
+ continue;
+ error("char 0x%04x not allowed in identifier", u);
+ p = s;
+ }
+ break;
+ }
- StringValue *sv = stringtable.update((char *)t->ptr, p - t->ptr);
- Identifier *id = (Identifier *) sv->ptrvalue;
- if (!id)
- { id = new Identifier(sv->lstring.string,TOKidentifier);
- sv->ptrvalue = id;
- }
- t->ident = id;
- t->value = (enum TOK) id->value;
- anyToken = 1;
- if (*t->ptr == '_') // if special identifier token
- {
- static char date[11+1];
- static char time[8+1];
- static char timestamp[24+1];
+ StringValue *sv = stringtable.update((char *)t->ptr, p - t->ptr);
+ Identifier *id = (Identifier *) sv->ptrvalue;
+ if (!id)
+ { id = new Identifier(sv->lstring.string,TOKidentifier);
+ sv->ptrvalue = id;
+ }
+ t->ident = id;
+ t->value = (enum TOK) id->value;
+ anyToken = 1;
+ if (*t->ptr == '_') // if special identifier token
+ {
+ static char date[11+1];
+ static char time[8+1];
+ static char timestamp[24+1];
- if (!date[0]) // lazy evaluation
- { time_t t;
- char *p;
+ if (!date[0]) // lazy evaluation
+ { time_t t;
+ char *p;
- ::time(&t);
- p = ctime(&t);
- assert(p);
- sprintf(date, "%.6s %.4s", p + 4, p + 20);
- sprintf(time, "%.8s", p + 11);
- sprintf(timestamp, "%.24s", p);
- }
+ ::time(&t);
+ p = ctime(&t);
+ assert(p);
+ sprintf(date, "%.6s %.4s", p + 4, p + 20);
+ sprintf(time, "%.8s", p + 11);
+ sprintf(timestamp, "%.24s", p);
+ }
#if DMDV1
- if (mod && id == Id::FILE)
- {
- t->ustring = (unsigned char *)(loc.filename ? loc.filename : mod->ident->toChars());
- goto Lstr;
- }
- else if (mod && id == Id::LINE)
- {
- t->value = TOKint64v;
- t->uns64value = loc.linnum;
- }
- else
+ if (mod && id == Id::FILE)
+ {
+ t->ustring = (unsigned char *)(loc.filename ? loc.filename : mod->ident->toChars());
+ goto Lstr;
+ }
+ else if (mod && id == Id::LINE)
+ {
+ t->value = TOKint64v;
+ t->uns64value = loc.linnum;
+ }
+ else
#endif
- if (id == Id::DATE)
- {
- t->ustring = (unsigned char *)date;
- goto Lstr;
- }
- else if (id == Id::TIME)
- {
- t->ustring = (unsigned char *)time;
- goto Lstr;
- }
- else if (id == Id::VENDOR)
- {
- t->ustring = (unsigned char *)"LDC";
- goto Lstr;
- }
- else if (id == Id::TIMESTAMP)
- {
- t->ustring = (unsigned char *)timestamp;
- Lstr:
- t->value = TOKstring;
- Llen:
- t->postfix = 0;
- t->len = strlen((char *)t->ustring);
- }
- else if (id == Id::VERSIONX)
- { unsigned major = 0;
- unsigned minor = 0;
+ if (id == Id::DATE)
+ {
+ t->ustring = (unsigned char *)date;
+ goto Lstr;
+ }
+ else if (id == Id::TIME)
+ {
+ t->ustring = (unsigned char *)time;
+ goto Lstr;
+ }
+ else if (id == Id::VENDOR)
+ {
+ t->ustring = (unsigned char *)"LDC";
+ goto Lstr;
+ }
+ else if (id == Id::TIMESTAMP)
+ {
+ t->ustring = (unsigned char *)timestamp;
+ Lstr:
+ t->value = TOKstring;
+ Llen:
+ t->postfix = 0;
+ t->len = strlen((char *)t->ustring);
+ }
+ else if (id == Id::VERSIONX)
+ { unsigned major = 0;
+ unsigned minor = 0;
- for (const char *p = global.version + 1; 1; p++)
- {
- char c = *p;
- if (isdigit(c))
- minor = minor * 10 + c - '0';
- else if (c == '.')
- { major = minor;
- minor = 0;
- }
- else
- break;
- }
- t->value = TOKint64v;
- t->uns64value = major * 1000 + minor;
- }
+ for (const char *p = global.version + 1; 1; p++)
+ {
+ char c = *p;
+ if (isdigit(c))
+ minor = minor * 10 + c - '0';
+ else if (c == '.')
+ { major = minor;
+ minor = 0;
+ }
+ else
+ break;
+ }
+ t->value = TOKint64v;
+ t->uns64value = major * 1000 + minor;
+ }
#if DMDV2
- else if (id == Id::EOFX)
- {
- t->value = TOKeof;
- // Advance scanner to end of file
- while (!(*p == 0 || *p == 0x1A))
- p++;
- }
+ else if (id == Id::EOFX)
+ {
+ t->value = TOKeof;
+ // Advance scanner to end of file
+ while (!(*p == 0 || *p == 0x1A))
+ p++;
+ }
#endif
- }
- //printf("t->value = %d\n",t->value);
- return;
- }
+ }
+ //printf("t->value = %d\n",t->value);
+ return;
+ }
- case '/':
- p++;
- switch (*p)
- {
- case '=':
- p++;
- t->value = TOKdivass;
- return;
+ case '/':
+ p++;
+ switch (*p)
+ {
+ case '=':
+ p++;
+ t->value = TOKdivass;
+ return;
- case '*':
- p++;
- linnum = loc.linnum;
- while (1)
- {
- while (1)
- { unsigned char c = *p;
- switch (c)
- {
- case '/':
- break;
+ case '*':
+ p++;
+ linnum = loc.linnum;
+ while (1)
+ {
+ while (1)
+ { unsigned char c = *p;
+ switch (c)
+ {
+ case '/':
+ break;
- case '\n':
- loc.linnum++;
- p++;
- continue;
+ case '\n':
+ loc.linnum++;
+ p++;
+ continue;
- case '\r':
- p++;
- if (*p != '\n')
- loc.linnum++;
- continue;
+ case '\r':
+ p++;
+ if (*p != '\n')
+ loc.linnum++;
+ continue;
- case 0:
- case 0x1A:
- error("unterminated /* */ comment");
- p = end;
- t->value = TOKeof;
- return;
+ case 0:
+ case 0x1A:
+ error("unterminated /* */ comment");
+ p = end;
+ t->value = TOKeof;
+ return;
- default:
- if (c & 0x80)
- { unsigned u = decodeUTF();
- if (u == PS || u == LS)
- loc.linnum++;
- }
- p++;
- continue;
- }
- break;
- }
- p++;
- if (p[-2] == '*' && p - 3 != t->ptr)
- break;
- }
- if (commentToken)
- {
- t->value = TOKcomment;
- return;
- }
- else if (doDocComment && t->ptr[2] == '*' && p - 4 != t->ptr)
- { // if /** but not /**/
- getDocComment(t, lastLine == linnum);
- }
- continue;
+ default:
+ if (c & 0x80)
+ { unsigned u = decodeUTF();
+ if (u == PS || u == LS)
+ loc.linnum++;
+ }
+ p++;
+ continue;
+ }
+ break;
+ }
+ p++;
+ if (p[-2] == '*' && p - 3 != t->ptr)
+ break;
+ }
+ if (commentToken)
+ {
+ t->value = TOKcomment;
+ return;
+ }
+ else if (doDocComment && t->ptr[2] == '*' && p - 4 != t->ptr)
+ { // if /** but not /**/
+ getDocComment(t, lastLine == linnum);
+ }
+ continue;
- case '/': // do // style comments
- linnum = loc.linnum;
- while (1)
- { unsigned char c = *++p;
- switch (c)
- {
- case '\n':
- break;
+ case '/': // do // style comments
+ linnum = loc.linnum;
+ while (1)
+ { unsigned char c = *++p;
+ switch (c)
+ {
+ case '\n':
+ break;
- case '\r':
- if (p[1] == '\n')
- p++;
- break;
+ case '\r':
+ if (p[1] == '\n')
+ p++;
+ break;
- case 0:
- case 0x1A:
- if (commentToken)
- {
- p = end;
- t->value = TOKcomment;
- return;
- }
- if (doDocComment && t->ptr[2] == '/')
- getDocComment(t, lastLine == linnum);
- p = end;
- t->value = TOKeof;
- return;
+ case 0:
+ case 0x1A:
+ if (commentToken)
+ {
+ p = end;
+ t->value = TOKcomment;
+ return;
+ }
+ if (doDocComment && t->ptr[2] == '/')
+ getDocComment(t, lastLine == linnum);
+ p = end;
+ t->value = TOKeof;
+ return;
- default:
- if (c & 0x80)
- { unsigned u = decodeUTF();
- if (u == PS || u == LS)
- break;
- }
- continue;
- }
- break;
- }
+ default:
+ if (c & 0x80)
+ { unsigned u = decodeUTF();
+ if (u == PS || u == LS)
+ break;
+ }
+ continue;
+ }
+ break;
+ }
- if (commentToken)
- {
- p++;
- loc.linnum++;
- t->value = TOKcomment;
- return;
- }
- if (doDocComment && t->ptr[2] == '/')
- getDocComment(t, lastLine == linnum);
+ if (commentToken)
+ {
+ p++;
+ loc.linnum++;
+ t->value = TOKcomment;
+ return;
+ }
+ if (doDocComment && t->ptr[2] == '/')
+ getDocComment(t, lastLine == linnum);
- p++;
- loc.linnum++;
- continue;
+ p++;
+ loc.linnum++;
+ continue;
- case '+':
- { int nest;
+ case '+':
+ { int nest;
- linnum = loc.linnum;
- p++;
- nest = 1;
- while (1)
- { unsigned char c = *p;
- switch (c)
- {
- case '/':
- p++;
- if (*p == '+')
- {
- p++;
- nest++;
- }
- continue;
+ linnum = loc.linnum;
+ p++;
+ nest = 1;
+ while (1)
+ { unsigned char c = *p;
+ switch (c)
+ {
+ case '/':
+ p++;
+ if (*p == '+')
+ {
+ p++;
+ nest++;
+ }
+ continue;
- case '+':
- p++;
- if (*p == '/')
- {
- p++;
- if (--nest == 0)
- break;
- }
- continue;
+ case '+':
+ p++;
+ if (*p == '/')
+ {
+ p++;
+ if (--nest == 0)
+ break;
+ }
+ continue;
- case '\r':
- p++;
- if (*p != '\n')
- loc.linnum++;
- continue;
+ case '\r':
+ p++;
+ if (*p != '\n')
+ loc.linnum++;
+ continue;
- case '\n':
- loc.linnum++;
- p++;
- continue;
+ case '\n':
+ loc.linnum++;
+ p++;
+ continue;
- case 0:
- case 0x1A:
- error("unterminated /+ +/ comment");
- p = end;
- t->value = TOKeof;
- return;
+ case 0:
+ case 0x1A:
+ error("unterminated /+ +/ comment");
+ p = end;
+ t->value = TOKeof;
+ return;
- default:
- if (c & 0x80)
- { unsigned u = decodeUTF();
- if (u == PS || u == LS)
- loc.linnum++;
- }
- p++;
- continue;
- }
- break;
- }
- if (commentToken)
- {
- t->value = TOKcomment;
- return;
- }
- if (doDocComment && t->ptr[2] == '+' && p - 4 != t->ptr)
- { // if /++ but not /++/
- getDocComment(t, lastLine == linnum);
- }
- continue;
- }
- }
- t->value = TOKdiv;
- return;
+ default:
+ if (c & 0x80)
+ { unsigned u = decodeUTF();
+ if (u == PS || u == LS)
+ loc.linnum++;
+ }
+ p++;
+ continue;
+ }
+ break;
+ }
+ if (commentToken)
+ {
+ t->value = TOKcomment;
+ return;
+ }
+ if (doDocComment && t->ptr[2] == '+' && p - 4 != t->ptr)
+ { // if /++ but not /++/
+ getDocComment(t, lastLine == linnum);
+ }
+ continue;
+ }
+ }
+ t->value = TOKdiv;
+ return;
- case '.':
- p++;
- if (isdigit(*p))
- { /* Note that we don't allow ._1 and ._ as being
- * valid floating point numbers.
- */
- p--;
- t->value = inreal(t);
- }
- else if (p[0] == '.')
- {
- if (p[1] == '.')
- { p += 2;
- t->value = TOKdotdotdot;
- }
- else
- { p++;
- t->value = TOKslice;
- }
- }
- else
- t->value = TOKdot;
- return;
+ case '.':
+ p++;
+ if (isdigit(*p))
+ { /* Note that we don't allow ._1 and ._ as being
+ * valid floating point numbers.
+ */
+ p--;
+ t->value = inreal(t);
+ }
+ else if (p[0] == '.')
+ {
+ if (p[1] == '.')
+ { p += 2;
+ t->value = TOKdotdotdot;
+ }
+ else
+ { p++;
+ t->value = TOKslice;
+ }
+ }
+ else
+ t->value = TOKdot;
+ return;
- case '&':
- p++;
- if (*p == '=')
- { p++;
- t->value = TOKandass;
- }
- else if (*p == '&')
- { p++;
- t->value = TOKandand;
- }
- else
- t->value = TOKand;
- return;
+ case '&':
+ p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKandass;
+ }
+ else if (*p == '&')
+ { p++;
+ t->value = TOKandand;
+ }
+ else
+ t->value = TOKand;
+ return;
- case '|':
- p++;
- if (*p == '=')
- { p++;
- t->value = TOKorass;
- }
- else if (*p == '|')
- { p++;
- t->value = TOKoror;
- }
- else
- t->value = TOKor;
- return;
+ case '|':
+ p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKorass;
+ }
+ else if (*p == '|')
+ { p++;
+ t->value = TOKoror;
+ }
+ else
+ t->value = TOKor;
+ return;
- case '-':
- p++;
- if (*p == '=')
- { p++;
- t->value = TOKminass;
- }
+ case '-':
+ p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKminass;
+ }
#if 0
- else if (*p == '>')
- { p++;
- t->value = TOKarrow;
- }
+ else if (*p == '>')
+ { p++;
+ t->value = TOKarrow;
+ }
#endif
- else if (*p == '-')
- { p++;
- t->value = TOKminusminus;
- }
- else
- t->value = TOKmin;
- return;
+ else if (*p == '-')
+ { p++;
+ t->value = TOKminusminus;
+ }
+ else
+ t->value = TOKmin;
+ return;
- case '+':
- p++;
- if (*p == '=')
- { p++;
- t->value = TOKaddass;
- }
- else if (*p == '+')
- { p++;
- t->value = TOKplusplus;
- }
- else
- t->value = TOKadd;
- return;
+ case '+':
+ p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKaddass;
+ }
+ else if (*p == '+')
+ { p++;
+ t->value = TOKplusplus;
+ }
+ else
+ t->value = TOKadd;
+ return;
- case '<':
- p++;
- if (*p == '=')
- { p++;
- t->value = TOKle; // <=
- }
- else if (*p == '<')
- { p++;
- if (*p == '=')
- { p++;
- t->value = TOKshlass; // <<=
- }
- else
- t->value = TOKshl; // <<
- }
- else if (*p == '>')
- { p++;
- if (*p == '=')
- { p++;
- t->value = TOKleg; // <>=
- }
- else
- t->value = TOKlg; // <>
- }
- else
- t->value = TOKlt; // <
- return;
+ case '<':
+ p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKle; // <=
+ }
+ else if (*p == '<')
+ { p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKshlass; // <<=
+ }
+ else
+ t->value = TOKshl; // <<
+ }
+ else if (*p == '>')
+ { p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKleg; // <>=
+ }
+ else
+ t->value = TOKlg; // <>
+ }
+ else
+ t->value = TOKlt; // <
+ return;
- case '>':
- p++;
- if (*p == '=')
- { p++;
- t->value = TOKge; // >=
- }
- else if (*p == '>')
- { p++;
- if (*p == '=')
- { p++;
- t->value = TOKshrass; // >>=
- }
- else if (*p == '>')
- { p++;
- if (*p == '=')
- { p++;
- t->value = TOKushrass; // >>>=
- }
- else
- t->value = TOKushr; // >>>
- }
- else
- t->value = TOKshr; // >>
- }
- else
- t->value = TOKgt; // >
- return;
+ case '>':
+ p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKge; // >=
+ }
+ else if (*p == '>')
+ { p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKshrass; // >>=
+ }
+ else if (*p == '>')
+ { p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKushrass; // >>>=
+ }
+ else
+ t->value = TOKushr; // >>>
+ }
+ else
+ t->value = TOKshr; // >>
+ }
+ else
+ t->value = TOKgt; // >
+ return;
- case '!':
- p++;
- if (*p == '=')
- { p++;
- if (*p == '=' && global.params.Dversion == 1)
- { p++;
- t->value = TOKnotidentity; // !==
- }
- else
- t->value = TOKnotequal; // !=
- }
- else if (*p == '<')
- { p++;
- if (*p == '>')
- { p++;
- if (*p == '=')
- { p++;
- t->value = TOKunord; // !<>=
- }
- else
- t->value = TOKue; // !<>
- }
- else if (*p == '=')
- { p++;
- t->value = TOKug; // !<=
- }
- else
- t->value = TOKuge; // !<
- }
- else if (*p == '>')
- { p++;
- if (*p == '=')
- { p++;
- t->value = TOKul; // !>=
- }
- else
- t->value = TOKule; // !>
- }
- else
- t->value = TOKnot; // !
- return;
+ case '!':
+ p++;
+ if (*p == '=')
+ { p++;
+ if (*p == '=' && global.params.Dversion == 1)
+ { p++;
+ t->value = TOKnotidentity; // !==
+ }
+ else
+ t->value = TOKnotequal; // !=
+ }
+ else if (*p == '<')
+ { p++;
+ if (*p == '>')
+ { p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKunord; // !<>=
+ }
+ else
+ t->value = TOKue; // !<>
+ }
+ else if (*p == '=')
+ { p++;
+ t->value = TOKug; // !<=
+ }
+ else
+ t->value = TOKuge; // !<
+ }
+ else if (*p == '>')
+ { p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKul; // !>=
+ }
+ else
+ t->value = TOKule; // !>
+ }
+ else
+ t->value = TOKnot; // !
+ return;
- case '=':
- p++;
- if (*p == '=')
- { p++;
- if (*p == '=' && global.params.Dversion == 1)
- { p++;
- t->value = TOKidentity; // ===
- }
- else
- t->value = TOKequal; // ==
- }
- else
- t->value = TOKassign; // =
- return;
+ case '=':
+ p++;
+ if (*p == '=')
+ { p++;
+ if (*p == '=' && global.params.Dversion == 1)
+ { p++;
+ t->value = TOKidentity; // ===
+ }
+ else
+ t->value = TOKequal; // ==
+ }
+ else
+ t->value = TOKassign; // =
+ return;
- case '~':
- p++;
- if (*p == '=')
- { p++;
- t->value = TOKcatass; // ~=
- }
- else
- t->value = TOKtilde; // ~
- return;
+ case '~':
+ p++;
+ if (*p == '=')
+ { p++;
+ t->value = TOKcatass; // ~=
+ }
+ else
+ t->value = TOKtilde; // ~
+ return;
#define SINGLE(c,tok) case c: p++; t->value = tok; return;
- SINGLE('(', TOKlparen)
- SINGLE(')', TOKrparen)
- SINGLE('[', TOKlbracket)
- SINGLE(']', TOKrbracket)
- SINGLE('{', TOKlcurly)
- SINGLE('}', TOKrcurly)
- SINGLE('?', TOKquestion)
- SINGLE(',', TOKcomma)
- SINGLE(';', TOKsemicolon)
- SINGLE(':', TOKcolon)
- SINGLE('$', TOKdollar)
+ SINGLE('(', TOKlparen)
+ SINGLE(')', TOKrparen)
+ SINGLE('[', TOKlbracket)
+ SINGLE(']', TOKrbracket)
+ SINGLE('{', TOKlcurly)
+ SINGLE('}', TOKrcurly)
+ SINGLE('?', TOKquestion)
+ SINGLE(',', TOKcomma)
+ SINGLE(';', TOKsemicolon)
+ SINGLE(':', TOKcolon)
+ SINGLE('$', TOKdollar)
#undef SINGLE
-#define DOUBLE(c1,tok1,c2,tok2) \
- case c1: \
- p++; \
- if (*p == c2) \
- { p++; \
- t->value = tok2; \
- } \
- else \
- t->value = tok1; \
- return;
+#define DOUBLE(c1,tok1,c2,tok2) \
+ case c1: \
+ p++; \
+ if (*p == c2) \
+ { p++; \
+ t->value = tok2; \
+ } \
+ else \
+ t->value = tok1; \
+ return;
- DOUBLE('*', TOKmul, '=', TOKmulass)
- DOUBLE('%', TOKmod, '=', TOKmodass)
- DOUBLE('^', TOKxor, '=', TOKxorass)
+ DOUBLE('*', TOKmul, '=', TOKmulass)
+ DOUBLE('%', TOKmod, '=', TOKmodass)
+ DOUBLE('^', TOKxor, '=', TOKxorass)
#undef DOUBLE
- case '#':
- p++;
- pragma();
- continue;
+ case '#':
+ p++;
+ pragma();
+ continue;
- default:
- { unsigned c = *p;
+ default:
+ { unsigned c = *p;
- if (c & 0x80)
- { c = decodeUTF();
+ if (c & 0x80)
+ { c = decodeUTF();
- // Check for start of unicode identifier
- if (isUniAlpha(c))
- goto case_ident;
+ // Check for start of unicode identifier
+ if (isUniAlpha(c))
+ goto case_ident;
- if (c == PS || c == LS)
- {
- loc.linnum++;
- p++;
- continue;
- }
- }
- if (c < 0x80 && isprint(c))
- error("unsupported char '%c'", c);
- else
- error("unsupported char 0x%02x", c);
- p++;
- continue;
- }
- }
+ if (c == PS || c == LS)
+ {
+ loc.linnum++;
+ p++;
+ continue;
+ }
+ }
+ if (c < 0x80 && isprint(c))
+ error("unsupported char '%c'", c);
+ else
+ error("unsupported char 0x%02x", c);
+ p++;
+ continue;
+ }
+ }
}
}
@@ -1226,113 +1226,113 @@ unsigned Lexer::escapeSequence()
c = *p;
switch (c)
{
- case '\'':
- case '"':
- case '?':
- case '\\':
- Lconsume:
- p++;
- break;
+ case '\'':
+ case '"':
+ case '?':
+ case '\\':
+ Lconsume:
+ p++;
+ break;
- case 'a': c = 7; goto Lconsume;
- case 'b': c = 8; goto Lconsume;
- case 'f': c = 12; goto Lconsume;
- case 'n': c = 10; goto Lconsume;
- case 'r': c = 13; goto Lconsume;
- case 't': c = 9; goto Lconsume;
- case 'v': c = 11; goto Lconsume;
+ case 'a': c = 7; goto Lconsume;
+ case 'b': c = 8; goto Lconsume;
+ case 'f': c = 12; goto Lconsume;
+ case 'n': c = 10; goto Lconsume;
+ case 'r': c = 13; goto Lconsume;
+ case 't': c = 9; goto Lconsume;
+ case 'v': c = 11; goto Lconsume;
- case 'u':
- ndigits = 4;
- goto Lhex;
- case 'U':
- ndigits = 8;
- goto Lhex;
- case 'x':
- ndigits = 2;
- Lhex:
- p++;
- c = *p;
- if (ishex(c))
- { unsigned v;
+ case 'u':
+ ndigits = 4;
+ goto Lhex;
+ case 'U':
+ ndigits = 8;
+ goto Lhex;
+ case 'x':
+ ndigits = 2;
+ Lhex:
+ p++;
+ c = *p;
+ if (ishex(c))
+ { unsigned v;
- n = 0;
- v = 0;
- while (1)
- {
- if (isdigit(c))
- c -= '0';
- else if (islower(c))
- c -= 'a' - 10;
- else
- c -= 'A' - 10;
- v = v * 16 + c;
- c = *++p;
- if (++n == ndigits)
- break;
- if (!ishex(c))
- { error("escape hex sequence has %d hex digits instead of %d", n, ndigits);
- break;
- }
- }
- if (ndigits != 2 && !utf_isValidDchar(v))
- { error("invalid UTF character \\U%08x", v);
- v = '?'; // recover with valid UTF character
- }
- c = v;
- }
- else
- error("undefined escape hex sequence \\%c\n",c);
- break;
+ n = 0;
+ v = 0;
+ while (1)
+ {
+ if (isdigit(c))
+ c -= '0';
+ else if (islower(c))
+ c -= 'a' - 10;
+ else
+ c -= 'A' - 10;
+ v = v * 16 + c;
+ c = *++p;
+ if (++n == ndigits)
+ break;
+ if (!ishex(c))
+ { error("escape hex sequence has %d hex digits instead of %d", n, ndigits);
+ break;
+ }
+ }
+ if (ndigits != 2 && !utf_isValidDchar(v))
+ { error("invalid UTF character \\U%08x", v);
+ v = '?'; // recover with valid UTF character
+ }
+ c = v;
+ }
+ else
+ error("undefined escape hex sequence \\%c\n",c);
+ break;
- case '&': // named character entity
- for (unsigned char *idstart = ++p; 1; p++)
- {
- switch (*p)
- {
- case ';':
- c = HtmlNamedEntity(idstart, p - idstart);
- if (c == ~0)
- { error("unnamed character entity &%.*s;", (int)(p - idstart), idstart);
- c = ' ';
- }
- p++;
- break;
+ case '&': // named character entity
+ for (unsigned char *idstart = ++p; 1; p++)
+ {
+ switch (*p)
+ {
+ case ';':
+ c = HtmlNamedEntity(idstart, p - idstart);
+ if (c == ~0)
+ { error("unnamed character entity &%.*s;", (int)(p - idstart), idstart);
+ c = ' ';
+ }
+ p++;
+ break;
- default:
- if (isalpha(*p) ||
- (p != idstart + 1 && isdigit(*p)))
- continue;
- error("unterminated named entity");
- break;
- }
- break;
- }
- break;
+ default:
+ if (isalpha(*p) ||
+ (p != idstart + 1 && isdigit(*p)))
+ continue;
+ error("unterminated named entity");
+ break;
+ }
+ break;
+ }
+ break;
- case 0:
- case 0x1A: // end of file
- c = '\\';
- break;
+ case 0:
+ case 0x1A: // end of file
+ c = '\\';
+ break;
- default:
- if (isoctal(c))
- { unsigned v;
+ default:
+ if (isoctal(c))
+ { unsigned v;
- n = 0;
- v = 0;
- do
- {
- v = v * 8 + (c - '0');
- c = *++p;
- } while (++n < 3 && isoctal(c));
- c = v;
- if (c > 0xFF)
- error("0%03o is larger than a byte", c);
- }
- else
- error("undefined escape sequence \\%c\n",c);
- break;
+ n = 0;
+ v = 0;
+ do
+ {
+ v = v * 8 + (c - '0');
+ c = *++p;
+ } while (++n < 3 && isoctal(c));
+ c = v;
+ if (c > 0xFF)
+ error("0%03o is larger than a byte", c);
+ }
+ else
+ error("undefined escape sequence \\%c\n",c);
+ break;
}
return c;
}
@@ -1348,60 +1348,60 @@ TOK Lexer::wysiwygStringConstant(Token *t, int tc)
stringbuffer.reset();
while (1)
{
- c = *p++;
- switch (c)
- {
- case '\n':
- loc.linnum++;
- break;
+ c = *p++;
+ switch (c)
+ {
+ case '\n':
+ loc.linnum++;
+ break;
- case '\r':
- if (*p == '\n')
- continue; // ignore
- c = '\n'; // treat EndOfLine as \n character
- loc.linnum++;
- break;
+ case '\r':
+ if (*p == '\n')
+ continue; // ignore
+ c = '\n'; // treat EndOfLine as \n character
+ loc.linnum++;
+ break;
- case 0:
- case 0x1A:
- error("unterminated string constant starting at %s", start.toChars());
- t->ustring = (unsigned char *)"";
- t->len = 0;
- t->postfix = 0;
- return TOKstring;
+ case 0:
+ case 0x1A:
+ error("unterminated string constant starting at %s", start.toChars());
+ t->ustring = (unsigned char *)"";
+ t->len = 0;
+ t->postfix = 0;
+ return TOKstring;
- case '"':
- case '`':
- if (c == tc)
- {
- t->len = stringbuffer.offset;
- stringbuffer.writeByte(0);
- t->ustring = (unsigned char *)mem.malloc(stringbuffer.offset);
- memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
- stringPostfix(t);
- return TOKstring;
- }
- break;
+ case '"':
+ case '`':
+ if (c == tc)
+ {
+ t->len = stringbuffer.offset;
+ stringbuffer.writeByte(0);
+ t->ustring = (unsigned char *)mem.malloc(stringbuffer.offset);
+ memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
+ stringPostfix(t);
+ return TOKstring;
+ }
+ break;
- default:
- if (c & 0x80)
- { p--;
- unsigned u = decodeUTF();
- p++;
- if (u == PS || u == LS)
- loc.linnum++;
- stringbuffer.writeUTF8(u);
- continue;
- }
- break;
- }
- stringbuffer.writeByte(c);
+ default:
+ if (c & 0x80)
+ { p--;
+ unsigned u = decodeUTF();
+ p++;
+ if (u == PS || u == LS)
+ loc.linnum++;
+ stringbuffer.writeUTF8(u);
+ continue;
+ }
+ break;
+ }
+ stringbuffer.writeByte(c);
}
}
/**************************************
* Lex hex strings:
- * x"0A ae 34FE BD"
+ * x"0A ae 34FE BD"
*/
TOK Lexer::hexStringConstant(Token *t)
@@ -1414,70 +1414,70 @@ TOK Lexer::hexStringConstant(Token *t)
stringbuffer.reset();
while (1)
{
- c = *p++;
- switch (c)
- {
- case ' ':
- case '\t':
- case '\v':
- case '\f':
- continue; // skip white space
+ c = *p++;
+ switch (c)
+ {
+ case ' ':
+ case '\t':
+ case '\v':
+ case '\f':
+ continue; // skip white space
- case '\r':
- if (*p == '\n')
- continue; // ignore
- // Treat isolated '\r' as if it were a '\n'
- case '\n':
- loc.linnum++;
- continue;
+ case '\r':
+ if (*p == '\n')
+ continue; // ignore
+ // Treat isolated '\r' as if it were a '\n'
+ case '\n':
+ loc.linnum++;
+ continue;
- case 0:
- case 0x1A:
- error("unterminated string constant starting at %s", start.toChars());
- t->ustring = (unsigned char *)"";
- t->len = 0;
- t->postfix = 0;
- return TOKstring;
+ case 0:
+ case 0x1A:
+ error("unterminated string constant starting at %s", start.toChars());
+ t->ustring = (unsigned char *)"";
+ t->len = 0;
+ t->postfix = 0;
+ return TOKstring;
- case '"':
- if (n & 1)
- { error("odd number (%d) of hex characters in hex string", n);
- stringbuffer.writeByte(v);
- }
- t->len = stringbuffer.offset;
- stringbuffer.writeByte(0);
- t->ustring = (unsigned char *)mem.malloc(stringbuffer.offset);
- memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
- stringPostfix(t);
- return TOKstring;
+ case '"':
+ if (n & 1)
+ { error("odd number (%d) of hex characters in hex string", n);
+ stringbuffer.writeByte(v);
+ }
+ t->len = stringbuffer.offset;
+ stringbuffer.writeByte(0);
+ t->ustring = (unsigned char *)mem.malloc(stringbuffer.offset);
+ memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
+ stringPostfix(t);
+ return TOKstring;
- default:
- if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'a' && c <= 'f')
- c -= 'a' - 10;
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else if (c & 0x80)
- { p--;
- unsigned u = decodeUTF();
- p++;
- if (u == PS || u == LS)
- loc.linnum++;
- else
- error("non-hex character \\u%04x", u);
- }
- else
- error("non-hex character '%c'", c);
- if (n & 1)
- { v = (v << 4) | c;
- stringbuffer.writeByte(v);
- }
- else
- v = c;
- n++;
- break;
- }
+ default:
+ if (c >= '0' && c <= '9')
+ c -= '0';
+ else if (c >= 'a' && c <= 'f')
+ c -= 'a' - 10;
+ else if (c >= 'A' && c <= 'F')
+ c -= 'A' - 10;
+ else if (c & 0x80)
+ { p--;
+ unsigned u = decodeUTF();
+ p++;
+ if (u == PS || u == LS)
+ loc.linnum++;
+ else
+ error("non-hex character \\u%04x", u);
+ }
+ else
+ error("non-hex character '%c'", c);
+ if (n & 1)
+ { v = (v << 4) | c;
+ stringbuffer.writeByte(v);
+ }
+ else
+ v = c;
+ n++;
+ break;
+ }
}
}
@@ -1485,14 +1485,14 @@ TOK Lexer::hexStringConstant(Token *t)
#if DMDV2
/**************************************
* Lex delimited strings:
- * q"(foo(xxx))" // "foo(xxx)"
- * q"[foo(]" // "foo("
- * q"/foo]/" // "foo]"
- * q"HERE
- * foo
- * HERE" // "foo\n"
+ * q"(foo(xxx))" // "foo(xxx)"
+ * q"[foo(]" // "foo("
+ * q"/foo]/" // "foo]"
+ * q"HERE
+ * foo
+ * HERE" // "foo\n"
* Input:
- * p is on the "
+ * p is on the "
*/
TOK Lexer::delimitedStringConstant(Token *t)
@@ -1510,120 +1510,120 @@ TOK Lexer::delimitedStringConstant(Token *t)
stringbuffer.reset();
while (1)
{
- c = *p++;
- //printf("c = '%c'\n", c);
- switch (c)
- {
- case '\n':
- Lnextline:
- loc.linnum++;
- startline = 1;
- if (blankrol)
- { blankrol = 0;
- continue;
- }
- if (hereid)
- {
- stringbuffer.writeUTF8(c);
- continue;
- }
- break;
+ c = *p++;
+ //printf("c = '%c'\n", c);
+ switch (c)
+ {
+ case '\n':
+ Lnextline:
+ loc.linnum++;
+ startline = 1;
+ if (blankrol)
+ { blankrol = 0;
+ continue;
+ }
+ if (hereid)
+ {
+ stringbuffer.writeUTF8(c);
+ continue;
+ }
+ break;
- case '\r':
- if (*p == '\n')
- continue; // ignore
- c = '\n'; // treat EndOfLine as \n character
- goto Lnextline;
+ case '\r':
+ if (*p == '\n')
+ continue; // ignore
+ c = '\n'; // treat EndOfLine as \n character
+ goto Lnextline;
- case 0:
- case 0x1A:
- goto Lerror;
+ case 0:
+ case 0x1A:
+ goto Lerror;
- default:
- if (c & 0x80)
- { p--;
- c = decodeUTF();
- p++;
- if (c == PS || c == LS)
- goto Lnextline;
- }
- break;
- }
- if (delimleft == 0)
- { delimleft = c;
- nest = 1;
- nestcount = 1;
- if (c == '(')
- delimright = ')';
- else if (c == '{')
- delimright = '}';
- else if (c == '[')
- delimright = ']';
- else if (c == '<')
- delimright = '>';
- else if (isalpha(c) || c == '_' || (c >= 0x80 && isUniAlpha(c)))
- { // Start of identifier; must be a heredoc
- Token t;
- p--;
- scan(&t); // read in heredoc identifier
- if (t.value != TOKidentifier)
- { error("identifier expected for heredoc, not %s", t.toChars());
- delimright = c;
- }
- else
- { hereid = t.ident;
- //printf("hereid = '%s'\n", hereid->toChars());
- blankrol = 1;
- }
- nest = 0;
- }
- else
- { delimright = c;
- nest = 0;
- }
- }
- else
- {
- if (blankrol)
- { error("heredoc rest of line should be blank");
- blankrol = 0;
- continue;
- }
- if (nest == 1)
- {
- if (c == delimleft)
- nestcount++;
- else if (c == delimright)
- { nestcount--;
- if (nestcount == 0)
- goto Ldone;
- }
- }
- else if (c == delimright)
- goto Ldone;
- if (startline && isalpha(c))
- { Token t;
- unsigned char *psave = p;
- p--;
- scan(&t); // read in possible heredoc identifier
- //printf("endid = '%s'\n", t.ident->toChars());
- if (t.value == TOKidentifier && t.ident->equals(hereid))
- { /* should check that rest of line is blank
- */
- goto Ldone;
- }
- p = psave;
- }
- stringbuffer.writeUTF8(c);
- startline = 0;
- }
+ default:
+ if (c & 0x80)
+ { p--;
+ c = decodeUTF();
+ p++;
+ if (c == PS || c == LS)
+ goto Lnextline;
+ }
+ break;
+ }
+ if (delimleft == 0)
+ { delimleft = c;
+ nest = 1;
+ nestcount = 1;
+ if (c == '(')
+ delimright = ')';
+ else if (c == '{')
+ delimright = '}';
+ else if (c == '[')
+ delimright = ']';
+ else if (c == '<')
+ delimright = '>';
+ else if (isalpha(c) || c == '_' || (c >= 0x80 && isUniAlpha(c)))
+ { // Start of identifier; must be a heredoc
+ Token t;
+ p--;
+ scan(&t); // read in heredoc identifier
+ if (t.value != TOKidentifier)
+ { error("identifier expected for heredoc, not %s", t.toChars());
+ delimright = c;
+ }
+ else
+ { hereid = t.ident;
+ //printf("hereid = '%s'\n", hereid->toChars());
+ blankrol = 1;
+ }
+ nest = 0;
+ }
+ else
+ { delimright = c;
+ nest = 0;
+ }
+ }
+ else
+ {
+ if (blankrol)
+ { error("heredoc rest of line should be blank");
+ blankrol = 0;
+ continue;
+ }
+ if (nest == 1)
+ {
+ if (c == delimleft)
+ nestcount++;
+ else if (c == delimright)
+ { nestcount--;
+ if (nestcount == 0)
+ goto Ldone;
+ }
+ }
+ else if (c == delimright)
+ goto Ldone;
+ if (startline && isalpha(c))
+ { Token t;
+ unsigned char *psave = p;
+ p--;
+ scan(&t); // read in possible heredoc identifier
+ //printf("endid = '%s'\n", t.ident->toChars());
+ if (t.value == TOKidentifier && t.ident->equals(hereid))
+ { /* should check that rest of line is blank
+ */
+ goto Ldone;
+ }
+ p = psave;
+ }
+ stringbuffer.writeUTF8(c);
+ startline = 0;
+ }
}
Ldone:
if (*p == '"')
- p++;
+ p++;
else
- error("delimited string must end in %c\"", delimright);
+ error("delimited string must end in %c\"", delimright);
t->len = stringbuffer.offset;
stringbuffer.writeByte(0);
t->ustring = (unsigned char *)mem.malloc(stringbuffer.offset);
@@ -1641,11 +1641,11 @@ Lerror:
/**************************************
* Lex delimited strings:
- * q{ foo(xxx) } // " foo(xxx) "
- * q{foo(} // "foo("
- * q{{foo}"}"} // "{foo}"}""
+ * q{ foo(xxx) } // " foo(xxx) "
+ * q{foo(} // "foo("
+ * q{{foo}"}"} // "{foo}"}""
* Input:
- * p is on the q
+ * p is on the q
*/
TOK Lexer::tokenStringConstant(Token *t)
@@ -1655,26 +1655,26 @@ TOK Lexer::tokenStringConstant(Token *t)
unsigned char *pstart = ++p;
while (1)
- { Token tok;
+ { Token tok;
- scan(&tok);
- switch (tok.value)
- {
- case TOKlcurly:
- nest++;
- continue;
+ scan(&tok);
+ switch (tok.value)
+ {
+ case TOKlcurly:
+ nest++;
+ continue;
- case TOKrcurly:
- if (--nest == 0)
- goto Ldone;
- continue;
+ case TOKrcurly:
+ if (--nest == 0)
+ goto Ldone;
+ continue;
- case TOKeof:
- goto Lerror;
+ case TOKeof:
+ goto Lerror;
- default:
- continue;
- }
+ default:
+ continue;
+ }
}
Ldone:
@@ -1707,69 +1707,69 @@ TOK Lexer::escapeStringConstant(Token *t, int wide)
stringbuffer.reset();
while (1)
{
- c = *p++;
- switch (c)
- {
- case '\\':
- switch (*p)
- {
- case 'u':
- case 'U':
- case '&':
- c = escapeSequence();
- stringbuffer.writeUTF8(c);
- continue;
+ c = *p++;
+ switch (c)
+ {
+ case '\\':
+ switch (*p)
+ {
+ case 'u':
+ case 'U':
+ case '&':
+ c = escapeSequence();
+ stringbuffer.writeUTF8(c);
+ continue;
- default:
- c = escapeSequence();
- break;
- }
- break;
+ default:
+ c = escapeSequence();
+ break;
+ }
+ break;
- case '\n':
- loc.linnum++;
- break;
+ case '\n':
+ loc.linnum++;
+ break;
- case '\r':
- if (*p == '\n')
- continue; // ignore
- c = '\n'; // treat EndOfLine as \n character
- loc.linnum++;
- break;
+ case '\r':
+ if (*p == '\n')
+ continue; // ignore
+ c = '\n'; // treat EndOfLine as \n character
+ loc.linnum++;
+ break;
- case '"':
- t->len = stringbuffer.offset;
- stringbuffer.writeByte(0);
- t->ustring = (unsigned char *)mem.malloc(stringbuffer.offset);
- memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
- stringPostfix(t);
- return TOKstring;
+ case '"':
+ t->len = stringbuffer.offset;
+ stringbuffer.writeByte(0);
+ t->ustring = (unsigned char *)mem.malloc(stringbuffer.offset);
+ memcpy(t->ustring, stringbuffer.data, stringbuffer.offset);
+ stringPostfix(t);
+ return TOKstring;
- case 0:
- case 0x1A:
- p--;
- error("unterminated string constant starting at %s", start.toChars());
- t->ustring = (unsigned char *)"";
- t->len = 0;
- t->postfix = 0;
- return TOKstring;
+ case 0:
+ case 0x1A:
+ p--;
+ error("unterminated string constant starting at %s", start.toChars());
+ t->ustring = (unsigned char *)"";
+ t->len = 0;
+ t->postfix = 0;
+ return TOKstring;
- default:
- if (c & 0x80)
- {
- p--;
- c = decodeUTF();
- if (c == LS || c == PS)
- { c = '\n';
- loc.linnum++;
- }
- p++;
- stringbuffer.writeUTF8(c);
- continue;
- }
- break;
- }
- stringbuffer.writeByte(c);
+ default:
+ if (c & 0x80)
+ {
+ p--;
+ c = decodeUTF();
+ if (c == LS || c == PS)
+ { c = '\n';
+ loc.linnum++;
+ }
+ p++;
+ stringbuffer.writeUTF8(c);
+ continue;
+ }
+ break;
+ }
+ stringbuffer.writeByte(c);
}
}
@@ -1786,56 +1786,56 @@ TOK Lexer::charConstant(Token *t, int wide)
c = *p++;
switch (c)
{
- case '\\':
- switch (*p)
- {
- case 'u':
- t->uns64value = escapeSequence();
- tk = TOKwcharv;
- break;
+ case '\\':
+ switch (*p)
+ {
+ case 'u':
+ t->uns64value = escapeSequence();
+ tk = TOKwcharv;
+ break;
- case 'U':
- case '&':
- t->uns64value = escapeSequence();
- tk = TOKdcharv;
- break;
+ case 'U':
+ case '&':
+ t->uns64value = escapeSequence();
+ tk = TOKdcharv;
+ break;
- default:
- t->uns64value = escapeSequence();
- break;
- }
- break;
+ default:
+ t->uns64value = escapeSequence();
+ break;
+ }
+ break;
- case '\n':
- L1:
- loc.linnum++;
- case '\r':
- case 0:
- case 0x1A:
- case '\'':
- error("unterminated character constant");
- return tk;
+ case '\n':
+ L1:
+ loc.linnum++;
+ case '\r':
+ case 0:
+ case 0x1A:
+ case '\'':
+ error("unterminated character constant");
+ return tk;
- default:
- if (c & 0x80)
- {
- p--;
- c = decodeUTF();
- p++;
- if (c == LS || c == PS)
- goto L1;
- if (c < 0xD800 || (c >= 0xE000 && c < 0xFFFE))
- tk = TOKwcharv;
- else
- tk = TOKdcharv;
- }
- t->uns64value = c;
- break;
+ default:
+ if (c & 0x80)
+ {
+ p--;
+ c = decodeUTF();
+ p++;
+ if (c == LS || c == PS)
+ goto L1;
+ if (c < 0xD800 || (c >= 0xE000 && c < 0xFFFE))
+ tk = TOKwcharv;
+ else
+ tk = TOKdcharv;
+ }
+ t->uns64value = c;
+ break;
}
if (*p != '\'')
- { error("unterminated character constant");
- return tk;
+ { error("unterminated character constant");
+ return tk;
}
p++;
return tk;
@@ -1849,23 +1849,23 @@ void Lexer::stringPostfix(Token *t)
{
switch (*p)
{
- case 'c':
- case 'w':
- case 'd':
- t->postfix = *p;
- p++;
- break;
+ case 'c':
+ case 'w':
+ case 'd':
+ t->postfix = *p;
+ p++;
+ break;
- default:
- t->postfix = 0;
- break;
+ default:
+ t->postfix = 0;
+ break;
}
}
/***************************************
* Read \u or \U unicode sequence
* Input:
- * u 'u' or 'U'
+ * u 'u' or 'U'
*/
#if 0
@@ -1880,22 +1880,22 @@ unsigned Lexer::wchar(unsigned u)
value = 0;
for (n = 0; 1; n++)
{
- ++p;
- if (n == nchars)
- break;
- c = *p;
- if (!ishex(c))
- { error("\\%c sequence must be followed by %d hex characters", u, nchars);
- break;
- }
- if (isdigit(c))
- c -= '0';
- else if (islower(c))
- c -= 'a' - 10;
- else
- c -= 'A' - 10;
- value <<= 4;
- value |= c;
+ ++p;
+ if (n == nchars)
+ break;
+ c = *p;
+ if (!ishex(c))
+ { error("\\%c sequence must be followed by %d hex characters", u, nchars);
+ break;
+ }
+ if (isdigit(c))
+ c -= '0';
+ else if (islower(c))
+ c -= 'a' - 10;
+ else
+ c -= 'A' - 10;
+ value <<= 4;
+ value |= c;
}
return value;
}
@@ -1904,26 +1904,26 @@ unsigned Lexer::wchar(unsigned u)
/**************************************
* Read in a number.
* If it's an integer, store it in tok.TKutok.Vlong.
- * integers can be decimal, octal or hex
- * Handle the suffixes U, UL, LU, L, etc.
+ * integers can be decimal, octal or hex
+ * Handle the suffixes U, UL, LU, L, etc.
* If it's double, store it in tok.TKutok.Vdouble.
* Returns:
- * TKnum
- * TKdouble,...
+ * TKnum
+ * TKdouble,...
*/
TOK Lexer::number(Token *t)
{
// We use a state machine to collect numbers
enum STATE { STATE_initial, STATE_0, STATE_decimal, STATE_octal, STATE_octale,
- STATE_hex, STATE_binary, STATE_hex0, STATE_binary0,
- STATE_hexh, STATE_error };
+ STATE_hex, STATE_binary, STATE_hex0, STATE_binary0,
+ STATE_hexh, STATE_error };
enum STATE state;
enum FLAGS
- { FLAGS_decimal = 1, // decimal
- FLAGS_unsigned = 2, // u or U suffix
- FLAGS_long = 4, // l or L suffix
+ { FLAGS_decimal = 1, // decimal
+ FLAGS_unsigned = 2, // u or U suffix
+ FLAGS_long = 4, // l or L suffix
};
enum FLAGS flags = FLAGS_decimal;
@@ -1940,364 +1940,364 @@ TOK Lexer::number(Token *t)
start = p;
while (1)
{
- c = *p;
- switch (state)
- {
- case STATE_initial: // opening state
- if (c == '0')
- state = STATE_0;
- else
- state = STATE_decimal;
- break;
+ c = *p;
+ switch (state)
+ {
+ case STATE_initial: // opening state
+ if (c == '0')
+ state = STATE_0;
+ else
+ state = STATE_decimal;
+ break;
- case STATE_0:
- flags = (FLAGS) (flags & ~FLAGS_decimal);
- switch (c)
- {
+ case STATE_0:
+ flags = (FLAGS) (flags & ~FLAGS_decimal);
+ switch (c)
+ {
#if ZEROH
- case 'H': // 0h
- case 'h':
- goto hexh;
+ case 'H': // 0h
+ case 'h':
+ goto hexh;
#endif
- case 'X':
- case 'x':
- state = STATE_hex0;
- break;
+ case 'X':
+ case 'x':
+ state = STATE_hex0;
+ break;
- case '.':
- if (p[1] == '.') // .. is a separate token
- goto done;
- case 'i':
- case 'f':
- case 'F':
- goto real;
+ case '.':
+ if (p[1] == '.') // .. is a separate token
+ goto done;
+ case 'i':
+ case 'f':
+ case 'F':
+ goto real;
#if ZEROH
- case 'E':
- case 'e':
- goto case_hex;
+ case 'E':
+ case 'e':
+ goto case_hex;
#endif
- case 'B':
- case 'b':
- state = STATE_binary0;
- break;
+ case 'B':
+ case 'b':
+ state = STATE_binary0;
+ break;
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- state = STATE_octal;
- break;
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ state = STATE_octal;
+ break;
#if ZEROH
- case '8': case '9': case 'A':
- case 'C': case 'D': case 'F':
- case 'a': case 'c': case 'd': case 'f':
- case_hex:
- state = STATE_hexh;
- break;
+ case '8': case '9': case 'A':
+ case 'C': case 'D': case 'F':
+ case 'a': case 'c': case 'd': case 'f':
+ case_hex:
+ state = STATE_hexh;
+ break;
#endif
- case '_':
- state = STATE_octal;
- p++;
- continue;
+ case '_':
+ state = STATE_octal;
+ p++;
+ continue;
- case 'L':
- if (p[1] == 'i')
- goto real;
- goto done;
+ case 'L':
+ if (p[1] == 'i')
+ goto real;
+ goto done;
- default:
- goto done;
- }
- break;
+ default:
+ goto done;
+ }
+ break;
- case STATE_decimal: // reading decimal number
- if (!isdigit(c))
- {
+ case STATE_decimal: // reading decimal number
+ if (!isdigit(c))
+ {
#if ZEROH
- if (ishex(c)
- || c == 'H' || c == 'h'
- )
- goto hexh;
+ if (ishex(c)
+ || c == 'H' || c == 'h'
+ )
+ goto hexh;
#endif
- if (c == '_') // ignore embedded _
- { p++;
- continue;
- }
- if (c == '.' && p[1] != '.')
- goto real;
- else if (c == 'i' || c == 'f' || c == 'F' ||
- c == 'e' || c == 'E')
- {
- real: // It's a real number. Back up and rescan as a real
- p = start;
- return inreal(t);
- }
- else if (c == 'L' && p[1] == 'i')
- goto real;
- goto done;
- }
- break;
+ if (c == '_') // ignore embedded _
+ { p++;
+ continue;
+ }
+ if (c == '.' && p[1] != '.')
+ goto real;
+ else if (c == 'i' || c == 'f' || c == 'F' ||
+ c == 'e' || c == 'E')
+ {
+ real: // It's a real number. Back up and rescan as a real
+ p = start;
+ return inreal(t);
+ }
+ else if (c == 'L' && p[1] == 'i')
+ goto real;
+ goto done;
+ }
+ break;
- case STATE_hex0: // reading hex number
- case STATE_hex:
- if (!ishex(c))
- {
- if (c == '_') // ignore embedded _
- { p++;
- continue;
- }
- if (c == '.' && p[1] != '.')
- goto real;
- if (c == 'P' || c == 'p' || c == 'i')
- goto real;
- if (state == STATE_hex0)
- error("Hex digit expected, not '%c'", c);
- goto done;
- }
- state = STATE_hex;
- break;
+ case STATE_hex0: // reading hex number
+ case STATE_hex:
+ if (!ishex(c))
+ {
+ if (c == '_') // ignore embedded _
+ { p++;
+ continue;
+ }
+ if (c == '.' && p[1] != '.')
+ goto real;
+ if (c == 'P' || c == 'p' || c == 'i')
+ goto real;
+ if (state == STATE_hex0)
+ error("Hex digit expected, not '%c'", c);
+ goto done;
+ }
+ state = STATE_hex;
+ break;
#if ZEROH
- hexh:
- state = STATE_hexh;
- case STATE_hexh: // parse numbers like 0FFh
- if (!ishex(c))
- {
- if (c == 'H' || c == 'h')
- {
- p++;
- base = 16;
- goto done;
- }
- else
- {
- // Check for something like 1E3 or 0E24
- if (memchr((char *)stringbuffer.data, 'E', stringbuffer.offset) ||
- memchr((char *)stringbuffer.data, 'e', stringbuffer.offset))
- goto real;
- error("Hex digit expected, not '%c'", c);
- goto done;
- }
- }
- break;
+ hexh:
+ state = STATE_hexh;
+ case STATE_hexh: // parse numbers like 0FFh
+ if (!ishex(c))
+ {
+ if (c == 'H' || c == 'h')
+ {
+ p++;
+ base = 16;
+ goto done;
+ }
+ else
+ {
+ // Check for something like 1E3 or 0E24
+ if (memchr((char *)stringbuffer.data, 'E', stringbuffer.offset) ||
+ memchr((char *)stringbuffer.data, 'e', stringbuffer.offset))
+ goto real;
+ error("Hex digit expected, not '%c'", c);
+ goto done;
+ }
+ }
+ break;
#endif
- case STATE_octal: // reading octal number
- case STATE_octale: // reading octal number with non-octal digits
- if (!isoctal(c))
- {
+ case STATE_octal: // reading octal number
+ case STATE_octale: // reading octal number with non-octal digits
+ if (!isoctal(c))
+ {
#if ZEROH
- if (ishex(c)
- || c == 'H' || c == 'h'
- )
- goto hexh;
+ if (ishex(c)
+ || c == 'H' || c == 'h'
+ )
+ goto hexh;
#endif
- if (c == '_') // ignore embedded _
- { p++;
- continue;
- }
- if (c == '.' && p[1] != '.')
- goto real;
- if (c == 'i')
- goto real;
- if (isdigit(c))
- {
- state = STATE_octale;
- }
- else
- goto done;
- }
- break;
+ if (c == '_') // ignore embedded _
+ { p++;
+ continue;
+ }
+ if (c == '.' && p[1] != '.')
+ goto real;
+ if (c == 'i')
+ goto real;
+ if (isdigit(c))
+ {
+ state = STATE_octale;
+ }
+ else
+ goto done;
+ }
+ break;
- case STATE_binary0: // starting binary number
- case STATE_binary: // reading binary number
- if (c != '0' && c != '1')
- {
+ case STATE_binary0: // starting binary number
+ case STATE_binary: // reading binary number
+ if (c != '0' && c != '1')
+ {
#if ZEROH
- if (ishex(c)
- || c == 'H' || c == 'h'
- )
- goto hexh;
+ if (ishex(c)
+ || c == 'H' || c == 'h'
+ )
+ goto hexh;
#endif
- if (c == '_') // ignore embedded _
- { p++;
- continue;
- }
- if (state == STATE_binary0)
- { error("binary digit expected");
- state = STATE_error;
- break;
- }
- else
- goto done;
- }
- state = STATE_binary;
- break;
+ if (c == '_') // ignore embedded _
+ { p++;
+ continue;
+ }
+ if (state == STATE_binary0)
+ { error("binary digit expected");
+ state = STATE_error;
+ break;
+ }
+ else
+ goto done;
+ }
+ state = STATE_binary;
+ break;
- case STATE_error: // for error recovery
- if (!isdigit(c)) // scan until non-digit
- goto done;
- break;
+ case STATE_error: // for error recovery
+ if (!isdigit(c)) // scan until non-digit
+ goto done;
+ break;
- default:
- assert(0);
- }
- stringbuffer.writeByte(c);
- p++;
+ default:
+ assert(0);
+ }
+ stringbuffer.writeByte(c);
+ p++;
}
done:
- stringbuffer.writeByte(0); // terminate string
+ stringbuffer.writeByte(0); // terminate string
if (state == STATE_octale)
- error("Octal digit expected");
+ error("Octal digit expected");
- uinteger_t n; // unsigned >=64 bit integer type
+ uinteger_t n; // unsigned >=64 bit integer type
if (stringbuffer.offset == 2 && (state == STATE_decimal || state == STATE_0))
- n = stringbuffer.data[0] - '0';
+ n = stringbuffer.data[0] - '0';
else
{
- // Convert string to integer
+ // Convert string to integer
#if __DMC__
- errno = 0;
- n = strtoull((char *)stringbuffer.data,NULL,base);
- if (errno == ERANGE)
- error("integer overflow");
+ errno = 0;
+ n = strtoull((char *)stringbuffer.data,NULL,base);
+ if (errno == ERANGE)
+ error("integer overflow");
#else
- // Not everybody implements strtoull()
- char *p = (char *)stringbuffer.data;
- int r = 10, d;
+ // Not everybody implements strtoull()
+ char *p = (char *)stringbuffer.data;
+ int r = 10, d;
- if (*p == '0')
- {
- if (p[1] == 'x' || p[1] == 'X')
- p += 2, r = 16;
- else if (p[1] == 'b' || p[1] == 'B')
- p += 2, r = 2;
- else if (isdigit(p[1]))
- p += 1, r = 8;
- }
+ if (*p == '0')
+ {
+ if (p[1] == 'x' || p[1] == 'X')
+ p += 2, r = 16;
+ else if (p[1] == 'b' || p[1] == 'B')
+ p += 2, r = 2;
+ else if (isdigit(p[1]))
+ p += 1, r = 8;
+ }
- n = 0;
- while (1)
- {
- if (*p >= '0' && *p <= '9')
- d = *p - '0';
- else if (*p >= 'a' && *p <= 'z')
- d = *p - 'a' + 10;
- else if (*p >= 'A' && *p <= 'Z')
- d = *p - 'A' + 10;
- else
- break;
- if (d >= r)
- break;
- uinteger_t n2 = n * r;
- //printf("n2 / r = %llx, n = %llx\n", n2/r, n);
- if (n2 / r != n || n2 + d < n)
- {
- error ("integer overflow");
- break;
- }
+ n = 0;
+ while (1)
+ {
+ if (*p >= '0' && *p <= '9')
+ d = *p - '0';
+ else if (*p >= 'a' && *p <= 'z')
+ d = *p - 'a' + 10;
+ else if (*p >= 'A' && *p <= 'Z')
+ d = *p - 'A' + 10;
+ else
+ break;
+ if (d >= r)
+ break;
+ uinteger_t n2 = n * r;
+ //printf("n2 / r = %llx, n = %llx\n", n2/r, n);
+ if (n2 / r != n || n2 + d < n)
+ {
+ error ("integer overflow");
+ break;
+ }
- n = n2 + d;
- p++;
- }
+ n = n2 + d;
+ p++;
+ }
#endif
- if (sizeof(n) > 8 &&
- n > 0xFFFFFFFFFFFFFFFFULL) // if n needs more than 64 bits
- error("integer overflow");
+ if (sizeof(n) > 8 &&
+ n > 0xFFFFFFFFFFFFFFFFULL) // if n needs more than 64 bits
+ error("integer overflow");
}
// Parse trailing 'u', 'U', 'l' or 'L' in any combination
while (1)
{ unsigned char f;
- switch (*p)
- { case 'U':
- case 'u':
- f = FLAGS_unsigned;
- goto L1;
+ switch (*p)
+ { case 'U':
+ case 'u':
+ f = FLAGS_unsigned;
+ goto L1;
- case 'l':
- if (1 || !global.params.useDeprecated)
- error("'l' suffix is deprecated, use 'L' instead");
- case 'L':
- f = FLAGS_long;
- L1:
- p++;
- if (flags & f)
- error("unrecognized token");
- flags = (FLAGS) (flags | f);
- continue;
- default:
- break;
- }
- break;
+ case 'l':
+ if (1 || !global.params.useDeprecated)
+ error("'l' suffix is deprecated, use 'L' instead");
+ case 'L':
+ f = FLAGS_long;
+ L1:
+ p++;
+ if (flags & f)
+ error("unrecognized token");
+ flags = (FLAGS) (flags | f);
+ continue;
+ default:
+ break;
+ }
+ break;
}
switch (flags)
{
- case 0:
- /* Octal or Hexadecimal constant.
- * First that fits: int, uint, long, ulong
- */
- if (n & 0x8000000000000000LL)
- result = TOKuns64v;
- else if (n & 0xFFFFFFFF00000000LL)
- result = TOKint64v;
- else if (n & 0x80000000)
- result = TOKuns32v;
- else
- result = TOKint32v;
- break;
+ case 0:
+ /* Octal or Hexadecimal constant.
+ * First that fits: int, uint, long, ulong
+ */
+ if (n & 0x8000000000000000LL)
+ result = TOKuns64v;
+ else if (n & 0xFFFFFFFF00000000LL)
+ result = TOKint64v;
+ else if (n & 0x80000000)
+ result = TOKuns32v;
+ else
+ result = TOKint32v;
+ break;
- case FLAGS_decimal:
- /* First that fits: int, long, long long
- */
- if (n & 0x8000000000000000LL)
- { error("signed integer overflow");
- result = TOKuns64v;
- }
- else if (n & 0xFFFFFFFF80000000LL)
- result = TOKint64v;
- else
- result = TOKint32v;
- break;
+ case FLAGS_decimal:
+ /* First that fits: int, long, long long
+ */
+ if (n & 0x8000000000000000LL)
+ { error("signed integer overflow");
+ result = TOKuns64v;
+ }
+ else if (n & 0xFFFFFFFF80000000LL)
+ result = TOKint64v;
+ else
+ result = TOKint32v;
+ break;
- case FLAGS_unsigned:
- case FLAGS_decimal | FLAGS_unsigned:
- /* First that fits: uint, ulong
- */
- if (n & 0xFFFFFFFF00000000LL)
- result = TOKuns64v;
- else
- result = TOKuns32v;
- break;
+ case FLAGS_unsigned:
+ case FLAGS_decimal | FLAGS_unsigned:
+ /* First that fits: uint, ulong
+ */
+ if (n & 0xFFFFFFFF00000000LL)
+ result = TOKuns64v;
+ else
+ result = TOKuns32v;
+ break;
- case FLAGS_decimal | FLAGS_long:
- if (n & 0x8000000000000000LL)
- { error("signed integer overflow");
- result = TOKuns64v;
- }
- else
- result = TOKint64v;
- break;
+ case FLAGS_decimal | FLAGS_long:
+ if (n & 0x8000000000000000LL)
+ { error("signed integer overflow");
+ result = TOKuns64v;
+ }
+ else
+ result = TOKint64v;
+ break;
- case FLAGS_long:
- if (n & 0x8000000000000000LL)
- result = TOKuns64v;
- else
- result = TOKint64v;
- break;
+ case FLAGS_long:
+ if (n & 0x8000000000000000LL)
+ result = TOKuns64v;
+ else
+ result = TOKint64v;
+ break;
- case FLAGS_unsigned | FLAGS_long:
- case FLAGS_decimal | FLAGS_unsigned | FLAGS_long:
- result = TOKuns64v;
- break;
+ case FLAGS_unsigned | FLAGS_long:
+ case FLAGS_decimal | FLAGS_unsigned | FLAGS_long:
+ result = TOKuns64v;
+ break;
- default:
- #ifdef DEBUG
- printf("%x\n",flags);
- #endif
- assert(0);
+ default:
+ #ifdef DEBUG
+ printf("%x\n",flags);
+ #endif
+ assert(0);
}
t->uns64value = n;
return result;
@@ -2306,8 +2306,8 @@ done:
/**************************************
* Read in characters, converting them to real.
* Bugs:
- * Exponent overflow not detected.
- * Too much requested precision is not detected.
+ * Exponent overflow not detected.
+ * Too much requested precision is not detected.
*/
TOK Lexer::inreal(Token *t)
@@ -2320,23 +2320,23 @@ __out (result)
{
switch (result)
{
- case TOKfloat32v:
- case TOKfloat64v:
- case TOKfloat80v:
- case TOKimaginary32v:
- case TOKimaginary64v:
- case TOKimaginary80v:
- break;
+ case TOKfloat32v:
+ case TOKfloat64v:
+ case TOKfloat80v:
+ case TOKimaginary32v:
+ case TOKimaginary64v:
+ case TOKimaginary80v:
+ break;
- default:
- assert(0);
+ default:
+ assert(0);
}
}
__body
#endif /* __DMC__ */
{ int dblstate;
unsigned c;
- char hex; // is this a hexadecimal-floating-constant?
+ char hex; // is this a hexadecimal-floating-constant?
TOK result;
//printf("Lexer::inreal()\n");
@@ -2346,72 +2346,72 @@ __body
Lnext:
while (1)
{
- // Get next char from input
- c = *p++;
- //printf("dblstate = %d, c = '%c'\n", dblstate, c);
- while (1)
- {
- switch (dblstate)
- {
- case 0: // opening state
- if (c == '0')
- dblstate = 9;
- else if (c == '.')
- dblstate = 3;
- else
- dblstate = 1;
- break;
+ // Get next char from input
+ c = *p++;
+ //printf("dblstate = %d, c = '%c'\n", dblstate, c);
+ while (1)
+ {
+ switch (dblstate)
+ {
+ case 0: // opening state
+ if (c == '0')
+ dblstate = 9;
+ else if (c == '.')
+ dblstate = 3;
+ else
+ dblstate = 1;
+ break;
- case 9:
- dblstate = 1;
- if (c == 'X' || c == 'x')
- { hex++;
- break;
- }
- case 1: // digits to left of .
- case 3: // digits to right of .
- case 7: // continuing exponent digits
- if (!isdigit(c) && !(hex && isxdigit(c)))
- {
- if (c == '_')
- goto Lnext; // ignore embedded '_'
- dblstate++;
- continue;
- }
- break;
+ case 9:
+ dblstate = 1;
+ if (c == 'X' || c == 'x')
+ { hex++;
+ break;
+ }
+ case 1: // digits to left of .
+ case 3: // digits to right of .
+ case 7: // continuing exponent digits
+ if (!isdigit(c) && !(hex && isxdigit(c)))
+ {
+ if (c == '_')
+ goto Lnext; // ignore embedded '_'
+ dblstate++;
+ continue;
+ }
+ break;
- case 2: // no more digits to left of .
- if (c == '.')
- { dblstate++;
- break;
- }
- case 4: // no more digits to right of .
- if ((c == 'E' || c == 'e') ||
- hex && (c == 'P' || c == 'p'))
- { dblstate = 5;
- hex = 0; // exponent is always decimal
- break;
- }
- if (hex)
- error("binary-exponent-part required");
- goto done;
+ case 2: // no more digits to left of .
+ if (c == '.')
+ { dblstate++;
+ break;
+ }
+ case 4: // no more digits to right of .
+ if ((c == 'E' || c == 'e') ||
+ hex && (c == 'P' || c == 'p'))
+ { dblstate = 5;
+ hex = 0; // exponent is always decimal
+ break;
+ }
+ if (hex)
+ error("binary-exponent-part required");
+ goto done;
- case 5: // looking immediately to right of E
- dblstate++;
- if (c == '-' || c == '+')
- break;
- case 6: // 1st exponent digit expected
- if (!isdigit(c))
- error("exponent expected");
- dblstate++;
- break;
+ case 5: // looking immediately to right of E
+ dblstate++;
+ if (c == '-' || c == '+')
+ break;
+ case 6: // 1st exponent digit expected
+ if (!isdigit(c))
+ error("exponent expected");
+ dblstate++;
+ break;
- case 8: // past end of exponent digits
- goto done;
- }
- break;
- }
- stringbuffer.writeByte(c);
+ case 8: // past end of exponent digits
+ goto done;
+ }
+ break;
+ }
+ stringbuffer.writeByte(c);
}
done:
p--;
@@ -2432,72 +2432,72 @@ done:
double strtodres;
switch (*p)
{
- case 'F':
- case 'f':
+ case 'F':
+ case 'f':
#ifdef IN_GCC
- real_t::parse((char *)stringbuffer.data, real_t::Float);
+ real_t::parse((char *)stringbuffer.data, real_t::Float);
#else
- strtofres = strtof((char *)stringbuffer.data, NULL);
- // LDC change: don't error on gradual underflow
- if (errno == ERANGE &&
- strtofres != 0 && strtofres != HUGE_VALF && strtofres != -HUGE_VALF)
- errno = 0;
+ strtofres = strtof((char *)stringbuffer.data, NULL);
+ // LDC change: don't error on gradual underflow
+ if (errno == ERANGE &&
+ strtofres != 0 && strtofres != HUGE_VALF && strtofres != -HUGE_VALF)
+ errno = 0;
#endif
- result = TOKfloat32v;
- p++;
- break;
+ result = TOKfloat32v;
+ p++;
+ break;
- default:
+ default:
#ifdef IN_GCC
- real_t::parse((char *)stringbuffer.data, real_t::Double);
-#else
- strtodres = strtod((char *)stringbuffer.data, NULL);
- // LDC change: don't error on gradual underflow
- if (errno == ERANGE &&
- strtodres != 0 && strtodres != HUGE_VAL && strtodres != -HUGE_VAL)
- errno = 0;
+ real_t::parse((char *)stringbuffer.data, real_t::Double);
+#else
+ strtodres = strtod((char *)stringbuffer.data, NULL);
+ // LDC change: don't error on gradual underflow
+ if (errno == ERANGE &&
+ strtodres != 0 && strtodres != HUGE_VAL && strtodres != -HUGE_VAL)
+ errno = 0;
#endif
- result = TOKfloat64v;
- break;
+ result = TOKfloat64v;
+ break;
- case 'l':
- if (!global.params.useDeprecated)
- error("'l' suffix is deprecated, use 'L' instead");
- case 'L':
- result = TOKfloat80v;
- p++;
- break;
+ case 'l':
+ if (!global.params.useDeprecated)
+ error("'l' suffix is deprecated, use 'L' instead");
+ case 'L':
+ result = TOKfloat80v;
+ p++;
+ break;
}
if (*p == 'i' || *p == 'I')
{
- if (!global.params.useDeprecated && *p == 'I')
- error("'I' suffix is deprecated, use 'i' instead");
- p++;
- switch (result)
- {
- case TOKfloat32v:
- result = TOKimaginary32v;
- break;
- case TOKfloat64v:
- result = TOKimaginary64v;
- break;
- case TOKfloat80v:
- result = TOKimaginary80v;
- break;
- }
+ if (!global.params.useDeprecated && *p == 'I')
+ error("'I' suffix is deprecated, use 'i' instead");
+ p++;
+ switch (result)
+ {
+ case TOKfloat32v:
+ result = TOKimaginary32v;
+ break;
+ case TOKfloat64v:
+ result = TOKimaginary64v;
+ break;
+ case TOKfloat80v:
+ result = TOKimaginary80v;
+ break;
+ }
}
#if _WIN32 && __DMC__
__locale_decpoint = save;
#endif
if (errno == ERANGE)
- error("number is not representable");
+ error("number is not representable");
return result;
}
/*********************************************
* Do pragma.
* Currently, the only pragma supported is:
- * #line linnum [filespec]
+ * #line linnum [filespec]
*/
void Lexer::pragma()
@@ -2509,95 +2509,95 @@ void Lexer::pragma()
scan(&tok);
if (tok.value != TOKidentifier || tok.ident != Id::line)
- goto Lerr;
+ goto Lerr;
scan(&tok);
if (tok.value == TOKint32v || tok.value == TOKint64v)
- linnum = tok.uns64value - 1;
+ linnum = tok.uns64value - 1;
else
- goto Lerr;
+ goto Lerr;
while (1)
{
- switch (*p)
- {
- case 0:
- case 0x1A:
- case '\n':
- Lnewline:
- this->loc.linnum = linnum;
- if (filespec)
- this->loc.filename = filespec;
- return;
+ switch (*p)
+ {
+ case 0:
+ case 0x1A:
+ case '\n':
+ Lnewline:
+ this->loc.linnum = linnum;
+ if (filespec)
+ this->loc.filename = filespec;
+ return;
- case '\r':
- p++;
- if (*p != '\n')
- { p--;
- goto Lnewline;
- }
- continue;
+ case '\r':
+ p++;
+ if (*p != '\n')
+ { p--;
+ goto Lnewline;
+ }
+ continue;
- case ' ':
- case '\t':
- case '\v':
- case '\f':
- p++;
- continue; // skip white space
+ case ' ':
+ case '\t':
+ case '\v':
+ case '\f':
+ p++;
+ continue; // skip white space
- case '_':
- if (mod && memcmp(p, "__FILE__", 8) == 0)
- {
- p += 8;
- filespec = mem.strdup(loc.filename ? loc.filename : mod->ident->toChars());
- }
- continue;
+ case '_':
+ if (mod && memcmp(p, "__FILE__", 8) == 0)
+ {
+ p += 8;
+ filespec = mem.strdup(loc.filename ? loc.filename : mod->ident->toChars());
+ }
+ continue;
- case '"':
- if (filespec)
- goto Lerr;
- stringbuffer.reset();
- p++;
- while (1)
- { unsigned c;
+ case '"':
+ if (filespec)
+ goto Lerr;
+ stringbuffer.reset();
+ p++;
+ while (1)
+ { unsigned c;
- c = *p;
- switch (c)
- {
- case '\n':
- case '\r':
- case 0:
- case 0x1A:
- goto Lerr;
+ c = *p;
+ switch (c)
+ {
+ case '\n':
+ case '\r':
+ case 0:
+ case 0x1A:
+ goto Lerr;
- case '"':
- stringbuffer.writeByte(0);
- filespec = mem.strdup((char *)stringbuffer.data);
- p++;
- break;
+ case '"':
+ stringbuffer.writeByte(0);
+ filespec = mem.strdup((char *)stringbuffer.data);
+ p++;
+ break;
- default:
- if (c & 0x80)
- { unsigned u = decodeUTF();
- if (u == PS || u == LS)
- goto Lerr;
- }
- stringbuffer.writeByte(c);
- p++;
- continue;
- }
- break;
- }
- continue;
+ default:
+ if (c & 0x80)
+ { unsigned u = decodeUTF();
+ if (u == PS || u == LS)
+ goto Lerr;
+ }
+ stringbuffer.writeByte(c);
+ p++;
+ continue;
+ }
+ break;
+ }
+ continue;
- default:
- if (*p & 0x80)
- { unsigned u = decodeUTF();
- if (u == PS || u == LS)
- goto Lnewline;
- }
- goto Lerr;
- }
+ default:
+ if (*p & 0x80)
+ { unsigned u = decodeUTF();
+ if (u == PS || u == LS)
+ goto Lnewline;
+ }
+ goto Lerr;
+ }
}
Lerr:
@@ -2625,14 +2625,14 @@ unsigned Lexer::decodeUTF()
// Check length of remaining string up to 6 UTF-8 characters
for (len = 1; len < 6 && s[len]; len++)
- ;
+ ;
idx = 0;
msg = utf_decodeChar(s, len, &idx, &u);
p += idx - 1;
if (msg)
{
- error("%s", msg);
+ error("%s", msg);
}
return u;
}
@@ -2655,29 +2655,29 @@ void Lexer::getDocComment(Token *t, unsigned lineComment)
/* Start of comment text skips over / * *, / + +, or / / /
*/
- unsigned char *q = t->ptr + 3; // start of comment text
+ unsigned char *q = t->ptr + 3; // start of comment text
unsigned char *qend = p;
if (ct == '*' || ct == '+')
- qend -= 2;
+ qend -= 2;
/* Scan over initial row of ****'s or ++++'s or ////'s
*/
for (; q < qend; q++)
{
- if (*q != ct)
- break;
+ if (*q != ct)
+ break;
}
/* Remove trailing row of ****'s or ++++'s
*/
if (ct != '/')
{
- for (; q < qend; qend--)
- {
- if (qend[-1] != ct)
- break;
- }
+ for (; q < qend; qend--)
+ {
+ if (qend[-1] != ct)
+ break;
+ }
}
/* Comment is now [q .. qend].
@@ -2688,77 +2688,77 @@ void Lexer::getDocComment(Token *t, unsigned lineComment)
for (; q < qend; q++)
{
- unsigned char c = *q;
+ unsigned char c = *q;
- switch (c)
- {
- case '*':
- case '+':
- if (linestart && c == ct)
- { linestart = 0;
- /* Trim preceding whitespace up to preceding \n
- */
- while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
- buf.offset--;
- continue;
- }
- break;
+ switch (c)
+ {
+ case '*':
+ case '+':
+ if (linestart && c == ct)
+ { linestart = 0;
+ /* Trim preceding whitespace up to preceding \n
+ */
+ while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
+ buf.offset--;
+ continue;
+ }
+ break;
- case ' ':
- case '\t':
- break;
+ case ' ':
+ case '\t':
+ break;
- case '\r':
- if (q[1] == '\n')
- continue; // skip the \r
- goto Lnewline;
+ case '\r':
+ if (q[1] == '\n')
+ continue; // skip the \r
+ goto Lnewline;
- default:
- if (c == 226)
- {
- // If LS or PS
- if (q[1] == 128 &&
- (q[2] == 168 || q[2] == 169))
- {
- q += 2;
- goto Lnewline;
- }
- }
- linestart = 0;
- break;
+ default:
+ if (c == 226)
+ {
+ // If LS or PS
+ if (q[1] == 128 &&
+ (q[2] == 168 || q[2] == 169))
+ {
+ q += 2;
+ goto Lnewline;
+ }
+ }
+ linestart = 0;
+ break;
- Lnewline:
- c = '\n'; // replace all newlines with \n
- case '\n':
- linestart = 1;
+ Lnewline:
+ c = '\n'; // replace all newlines with \n
+ case '\n':
+ linestart = 1;
- /* Trim trailing whitespace
- */
- while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
- buf.offset--;
+ /* Trim trailing whitespace
+ */
+ while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
+ buf.offset--;
- break;
- }
- buf.writeByte(c);
+ break;
+ }
+ buf.writeByte(c);
}
// Always end with a newline
if (!buf.offset || buf.data[buf.offset - 1] != '\n')
- buf.writeByte('\n');
+ buf.writeByte('\n');
buf.writeByte(0);
// It's a line comment if the start of the doc comment comes
// after other non-whitespace on the same line.
unsigned char** dc = (lineComment && anyToken)
- ? &t->lineComment
- : &t->blockComment;
+ ? &t->lineComment
+ : &t->blockComment;
// Combine with previous doc comment, if any
if (*dc)
- *dc = combineComments(*dc, (unsigned char *)buf.data);
+ *dc = combineComments(*dc, (unsigned char *)buf.data);
else
- *dc = (unsigned char *)buf.extractData();
+ *dc = (unsigned char *)buf.extractData();
}
/********************************************
@@ -2773,20 +2773,20 @@ unsigned char *Lexer::combineComments(unsigned char *c1, unsigned char *c2)
unsigned char *c = c2;
if (c1)
- { c = c1;
- if (c2)
- { size_t len1 = strlen((char *)c1);
- size_t len2 = strlen((char *)c2);
+ { c = c1;
+ if (c2)
+ { size_t len1 = strlen((char *)c1);
+ size_t len2 = strlen((char *)c2);
- c = (unsigned char *)mem.malloc(len1 + 1 + len2 + 1);
- memcpy(c, c1, len1);
- if (len1 && c1[len1 - 1] != '\n')
- { c[len1] = '\n';
- len1++;
- }
- memcpy(c + len1, c2, len2);
- c[len1 + len2] = 0;
- }
+ c = (unsigned char *)mem.malloc(len1 + 1 + len2 + 1);
+ memcpy(c, c1, len1);
+ if (len1 && c1[len1 - 1] != '\n')
+ { c[len1] = '\n';
+ len1++;
+ }
+ memcpy(c + len1, c2, len2);
+ c[len1 + len2] = 0;
+ }
}
return c;
}
@@ -2802,8 +2802,8 @@ Identifier *Lexer::idPool(const char *s)
Identifier *id = (Identifier *) sv->ptrvalue;
if (!id)
{
- id = new Identifier(sv->lstring.string, TOKidentifier);
- sv->ptrvalue = id;
+ id = new Identifier(sv->lstring.string, TOKidentifier);
+ sv->ptrvalue = id;
}
return id;
}
@@ -2837,129 +2837,129 @@ struct Keyword
static Keyword keywords[] =
{
-// { "", TOK },
+// { "", TOK },
- { "this", TOKthis },
- { "super", TOKsuper },
- { "assert", TOKassert },
- { "null", TOKnull },
- { "true", TOKtrue },
- { "false", TOKfalse },
- { "cast", TOKcast },
- { "new", TOKnew },
- { "delete", TOKdelete },
- { "throw", TOKthrow },
- { "module", TOKmodule },
- { "pragma", TOKpragma },
- { "typeof", TOKtypeof },
- { "typeid", TOKtypeid },
+ { "this", TOKthis },
+ { "super", TOKsuper },
+ { "assert", TOKassert },
+ { "null", TOKnull },
+ { "true", TOKtrue },
+ { "false", TOKfalse },
+ { "cast", TOKcast },
+ { "new", TOKnew },
+ { "delete", TOKdelete },
+ { "throw", TOKthrow },
+ { "module", TOKmodule },
+ { "pragma", TOKpragma },
+ { "typeof", TOKtypeof },
+ { "typeid", TOKtypeid },
- { "template", TOKtemplate },
+ { "template", TOKtemplate },
- { "void", TOKvoid },
- { "byte", TOKint8 },
- { "ubyte", TOKuns8 },
- { "short", TOKint16 },
- { "ushort", TOKuns16 },
- { "int", TOKint32 },
- { "uint", TOKuns32 },
- { "long", TOKint64 },
- { "ulong", TOKuns64 },
- { "cent", TOKcent, },
- { "ucent", TOKucent, },
- { "float", TOKfloat32 },
- { "double", TOKfloat64 },
- { "real", TOKfloat80 },
+ { "void", TOKvoid },
+ { "byte", TOKint8 },
+ { "ubyte", TOKuns8 },
+ { "short", TOKint16 },
+ { "ushort", TOKuns16 },
+ { "int", TOKint32 },
+ { "uint", TOKuns32 },
+ { "long", TOKint64 },
+ { "ulong", TOKuns64 },
+ { "cent", TOKcent, },
+ { "ucent", TOKucent, },
+ { "float", TOKfloat32 },
+ { "double", TOKfloat64 },
+ { "real", TOKfloat80 },
- { "bool", TOKbool },
- { "char", TOKchar },
- { "wchar", TOKwchar },
- { "dchar", TOKdchar },
+ { "bool", TOKbool },
+ { "char", TOKchar },
+ { "wchar", TOKwchar },
+ { "dchar", TOKdchar },
- { "ifloat", TOKimaginary32 },
- { "idouble", TOKimaginary64 },
- { "ireal", TOKimaginary80 },
+ { "ifloat", TOKimaginary32 },
+ { "idouble", TOKimaginary64 },
+ { "ireal", TOKimaginary80 },
- { "cfloat", TOKcomplex32 },
- { "cdouble", TOKcomplex64 },
- { "creal", TOKcomplex80 },
+ { "cfloat", TOKcomplex32 },
+ { "cdouble", TOKcomplex64 },
+ { "creal", TOKcomplex80 },
- { "delegate", TOKdelegate },
- { "function", TOKfunction },
+ { "delegate", TOKdelegate },
+ { "function", TOKfunction },
- { "is", TOKis },
- { "if", TOKif },
- { "else", TOKelse },
- { "while", TOKwhile },
- { "for", TOKfor },
- { "do", TOKdo },
- { "switch", TOKswitch },
- { "case", TOKcase },
- { "default", TOKdefault },
- { "break", TOKbreak },
- { "continue", TOKcontinue },
- { "synchronized", TOKsynchronized },
- { "return", TOKreturn },
- { "goto", TOKgoto },
- { "try", TOKtry },
- { "catch", TOKcatch },
- { "finally", TOKfinally },
- { "with", TOKwith },
- { "asm", TOKasm },
- { "foreach", TOKforeach },
- { "foreach_reverse", TOKforeach_reverse },
- { "scope", TOKscope },
+ { "is", TOKis },
+ { "if", TOKif },
+ { "else", TOKelse },
+ { "while", TOKwhile },
+ { "for", TOKfor },
+ { "do", TOKdo },
+ { "switch", TOKswitch },
+ { "case", TOKcase },
+ { "default", TOKdefault },
+ { "break", TOKbreak },
+ { "continue", TOKcontinue },
+ { "synchronized", TOKsynchronized },
+ { "return", TOKreturn },
+ { "goto", TOKgoto },
+ { "try", TOKtry },
+ { "catch", TOKcatch },
+ { "finally", TOKfinally },
+ { "with", TOKwith },
+ { "asm", TOKasm },
+ { "foreach", TOKforeach },
+ { "foreach_reverse", TOKforeach_reverse },
+ { "scope", TOKscope },
- { "struct", TOKstruct },
- { "class", TOKclass },
- { "interface", TOKinterface },
- { "union", TOKunion },
- { "enum", TOKenum },
- { "import", TOKimport },
- { "mixin", TOKmixin },
- { "static", TOKstatic },
- { "final", TOKfinal },
- { "const", TOKconst },
- { "typedef", TOKtypedef },
- { "alias", TOKalias },
- { "override", TOKoverride },
- { "abstract", TOKabstract },
- { "volatile", TOKvolatile },
- { "debug", TOKdebug },
- { "deprecated", TOKdeprecated },
- { "in", TOKin },
- { "out", TOKout },
- { "inout", TOKinout },
- { "lazy", TOKlazy },
- { "auto", TOKauto },
+ { "struct", TOKstruct },
+ { "class", TOKclass },
+ { "interface", TOKinterface },
+ { "union", TOKunion },
+ { "enum", TOKenum },
+ { "import", TOKimport },
+ { "mixin", TOKmixin },
+ { "static", TOKstatic },
+ { "final", TOKfinal },
+ { "const", TOKconst },
+ { "typedef", TOKtypedef },
+ { "alias", TOKalias },
+ { "override", TOKoverride },
+ { "abstract", TOKabstract },
+ { "volatile", TOKvolatile },
+ { "debug", TOKdebug },
+ { "deprecated", TOKdeprecated },
+ { "in", TOKin },
+ { "out", TOKout },
+ { "inout", TOKinout },
+ { "lazy", TOKlazy },
+ { "auto", TOKauto },
- { "align", TOKalign },
- { "extern", TOKextern },
- { "private", TOKprivate },
- { "package", TOKpackage },
- { "protected", TOKprotected },
- { "public", TOKpublic },
- { "export", TOKexport },
+ { "align", TOKalign },
+ { "extern", TOKextern },
+ { "private", TOKprivate },
+ { "package", TOKpackage },
+ { "protected", TOKprotected },
+ { "public", TOKpublic },
+ { "export", TOKexport },
- { "body", TOKbody },
- { "invariant", TOKinvariant },
- { "unittest", TOKunittest },
- { "version", TOKversion },
- //{ "manifest", TOKmanifest },
+ { "body", TOKbody },
+ { "invariant", TOKinvariant },
+ { "unittest", TOKunittest },
+ { "version", TOKversion },
+ //{ "manifest", TOKmanifest },
// Added after 1.0
- { "ref", TOKref },
- { "macro", TOKmacro },
+ { "ref", TOKref },
+ { "macro", TOKmacro },
#if DMDV2
- { "pure", TOKpure },
- { "nothrow", TOKnothrow },
- { "__thread", TOKtls },
- { "__traits", TOKtraits },
- { "__overloadset", TOKoverloadset },
- { "__FILE__", TOKfile },
- { "__LINE__", TOKline },
- { "shared", TOKshared },
- { "immutable", TOKimmutable },
+ { "pure", TOKpure },
+ { "nothrow", TOKnothrow },
+ { "__thread", TOKtls },
+ { "__traits", TOKtraits },
+ { "__overloadset", TOKoverloadset },
+ { "__FILE__", TOKfile },
+ { "__LINE__", TOKline },
+ { "shared", TOKshared },
+ { "immutable", TOKimmutable },
#endif
};
@@ -2967,8 +2967,8 @@ int Token::isKeyword()
{
for (unsigned u = 0; u < sizeof(keywords) / sizeof(keywords[0]); u++)
{
- if (keywords[u].value == value)
- return 1;
+ if (keywords[u].value == value)
+ return 1;
}
return 0;
}
@@ -2980,125 +2980,125 @@ void Lexer::initKeywords()
unsigned nkeywords = sizeof(keywords) / sizeof(keywords[0]);
if (global.params.Dversion == 1)
- nkeywords -= 2;
+ nkeywords -= 2;
cmtable_init();
for (u = 0; u < nkeywords; u++)
- { const char *s;
+ { const char *s;
- //printf("keyword[%d] = '%s'\n",u, keywords[u].name);
- s = keywords[u].name;
- v = keywords[u].value;
- sv = stringtable.insert(s, strlen(s));
- sv->ptrvalue = (void *) new Identifier(sv->lstring.string,v);
+ //printf("keyword[%d] = '%s'\n",u, keywords[u].name);
+ s = keywords[u].name;
+ v = keywords[u].value;
+ sv = stringtable.insert(s, strlen(s));
+ sv->ptrvalue = (void *) new Identifier(sv->lstring.string,v);
- //printf("tochars[%d] = '%s'\n",v, s);
- Token::tochars[v] = s;
+ //printf("tochars[%d] = '%s'\n",v, s);
+ Token::tochars[v] = s;
}
- Token::tochars[TOKeof] = "EOF";
- Token::tochars[TOKlcurly] = "{";
- Token::tochars[TOKrcurly] = "}";
- Token::tochars[TOKlparen] = "(";
- Token::tochars[TOKrparen] = ")";
- Token::tochars[TOKlbracket] = "[";
- Token::tochars[TOKrbracket] = "]";
- Token::tochars[TOKsemicolon] = ";";
- Token::tochars[TOKcolon] = ":";
- Token::tochars[TOKcomma] = ",";
- Token::tochars[TOKdot] = ".";
- Token::tochars[TOKxor] = "^";
- Token::tochars[TOKxorass] = "^=";
- Token::tochars[TOKassign] = "=";
- Token::tochars[TOKconstruct] = "=";
+ Token::tochars[TOKeof] = "EOF";
+ Token::tochars[TOKlcurly] = "{";
+ Token::tochars[TOKrcurly] = "}";
+ Token::tochars[TOKlparen] = "(";
+ Token::tochars[TOKrparen] = ")";
+ Token::tochars[TOKlbracket] = "[";
+ Token::tochars[TOKrbracket] = "]";
+ Token::tochars[TOKsemicolon] = ";";
+ Token::tochars[TOKcolon] = ":";
+ Token::tochars[TOKcomma] = ",";
+ Token::tochars[TOKdot] = ".";
+ Token::tochars[TOKxor] = "^";
+ Token::tochars[TOKxorass] = "^=";
+ Token::tochars[TOKassign] = "=";
+ Token::tochars[TOKconstruct] = "=";
#if DMDV2
- Token::tochars[TOKblit] = "=";
+ Token::tochars[TOKblit] = "=";
#endif
- Token::tochars[TOKlt] = "<";
- Token::tochars[TOKgt] = ">";
- Token::tochars[TOKle] = "<=";
- Token::tochars[TOKge] = ">=";
- Token::tochars[TOKequal] = "==";
- Token::tochars[TOKnotequal] = "!=";
- Token::tochars[TOKnotidentity] = "!is";
- Token::tochars[TOKtobool] = "!!";
+ Token::tochars[TOKlt] = "<";
+ Token::tochars[TOKgt] = ">";
+ Token::tochars[TOKle] = "<=";
+ Token::tochars[TOKge] = ">=";
+ Token::tochars[TOKequal] = "==";
+ Token::tochars[TOKnotequal] = "!=";
+ Token::tochars[TOKnotidentity] = "!is";
+ Token::tochars[TOKtobool] = "!!";
- Token::tochars[TOKunord] = "!<>=";
- Token::tochars[TOKue] = "!<>";
- Token::tochars[TOKlg] = "<>";
- Token::tochars[TOKleg] = "<>=";
- Token::tochars[TOKule] = "!>";
- Token::tochars[TOKul] = "!>=";
- Token::tochars[TOKuge] = "!<";
- Token::tochars[TOKug] = "!<=";
+ Token::tochars[TOKunord] = "!<>=";
+ Token::tochars[TOKue] = "!<>";
+ Token::tochars[TOKlg] = "<>";
+ Token::tochars[TOKleg] = "<>=";
+ Token::tochars[TOKule] = "!>";
+ Token::tochars[TOKul] = "!>=";
+ Token::tochars[TOKuge] = "!<";
+ Token::tochars[TOKug] = "!<=";
- Token::tochars[TOKnot] = "!";
- Token::tochars[TOKtobool] = "!!";
- Token::tochars[TOKshl] = "<<";
- Token::tochars[TOKshr] = ">>";
- Token::tochars[TOKushr] = ">>>";
- Token::tochars[TOKadd] = "+";
- Token::tochars[TOKmin] = "-";
- Token::tochars[TOKmul] = "*";
- Token::tochars[TOKdiv] = "/";
- Token::tochars[TOKmod] = "%";
- Token::tochars[TOKslice] = "..";
- Token::tochars[TOKdotdotdot] = "...";
- Token::tochars[TOKand] = "&";
- Token::tochars[TOKandand] = "&&";
- Token::tochars[TOKor] = "|";
- Token::tochars[TOKoror] = "||";
- Token::tochars[TOKarray] = "[]";
- Token::tochars[TOKindex] = "[i]";
- Token::tochars[TOKaddress] = "&";
- Token::tochars[TOKstar] = "*";
- Token::tochars[TOKtilde] = "~";
- Token::tochars[TOKdollar] = "$";
- Token::tochars[TOKcast] = "cast";
- Token::tochars[TOKplusplus] = "++";
- Token::tochars[TOKminusminus] = "--";
- Token::tochars[TOKtype] = "type";
- Token::tochars[TOKquestion] = "?";
- Token::tochars[TOKneg] = "-";
- Token::tochars[TOKuadd] = "+";
- Token::tochars[TOKvar] = "var";
- Token::tochars[TOKaddass] = "+=";
- Token::tochars[TOKminass] = "-=";
- Token::tochars[TOKmulass] = "*=";
- Token::tochars[TOKdivass] = "/=";
- Token::tochars[TOKmodass] = "%=";
- Token::tochars[TOKshlass] = "<<=";
- Token::tochars[TOKshrass] = ">>=";
- Token::tochars[TOKushrass] = ">>>=";
- Token::tochars[TOKandass] = "&=";
- Token::tochars[TOKorass] = "|=";
- Token::tochars[TOKcatass] = "~=";
- Token::tochars[TOKcat] = "~";
- Token::tochars[TOKcall] = "call";
- Token::tochars[TOKidentity] = "is";
- Token::tochars[TOKnotidentity] = "!is";
+ Token::tochars[TOKnot] = "!";
+ Token::tochars[TOKtobool] = "!!";
+ Token::tochars[TOKshl] = "<<";
+ Token::tochars[TOKshr] = ">>";
+ Token::tochars[TOKushr] = ">>>";
+ Token::tochars[TOKadd] = "+";
+ Token::tochars[TOKmin] = "-";
+ Token::tochars[TOKmul] = "*";
+ Token::tochars[TOKdiv] = "/";
+ Token::tochars[TOKmod] = "%";
+ Token::tochars[TOKslice] = "..";
+ Token::tochars[TOKdotdotdot] = "...";
+ Token::tochars[TOKand] = "&";
+ Token::tochars[TOKandand] = "&&";
+ Token::tochars[TOKor] = "|";
+ Token::tochars[TOKoror] = "||";
+ Token::tochars[TOKarray] = "[]";
+ Token::tochars[TOKindex] = "[i]";
+ Token::tochars[TOKaddress] = "&";
+ Token::tochars[TOKstar] = "*";
+ Token::tochars[TOKtilde] = "~";
+ Token::tochars[TOKdollar] = "$";
+ Token::tochars[TOKcast] = "cast";
+ Token::tochars[TOKplusplus] = "++";
+ Token::tochars[TOKminusminus] = "--";
+ Token::tochars[TOKtype] = "type";
+ Token::tochars[TOKquestion] = "?";
+ Token::tochars[TOKneg] = "-";
+ Token::tochars[TOKuadd] = "+";
+ Token::tochars[TOKvar] = "var";
+ Token::tochars[TOKaddass] = "+=";
+ Token::tochars[TOKminass] = "-=";
+ Token::tochars[TOKmulass] = "*=";
+ Token::tochars[TOKdivass] = "/=";
+ Token::tochars[TOKmodass] = "%=";
+ Token::tochars[TOKshlass] = "<<=";
+ Token::tochars[TOKshrass] = ">>=";
+ Token::tochars[TOKushrass] = ">>>=";
+ Token::tochars[TOKandass] = "&=";
+ Token::tochars[TOKorass] = "|=";
+ Token::tochars[TOKcatass] = "~=";
+ Token::tochars[TOKcat] = "~";
+ Token::tochars[TOKcall] = "call";
+ Token::tochars[TOKidentity] = "is";
+ Token::tochars[TOKnotidentity] = "!is";
- Token::tochars[TOKorass] = "|=";
- Token::tochars[TOKidentifier] = "identifier";
+ Token::tochars[TOKorass] = "|=";
+ Token::tochars[TOKidentifier] = "identifier";
// For debugging
- Token::tochars[TOKerror] = "error";
- Token::tochars[TOKdotexp] = "dotexp";
- Token::tochars[TOKdotti] = "dotti";
- Token::tochars[TOKdotvar] = "dotvar";
- Token::tochars[TOKdottype] = "dottype";
- Token::tochars[TOKsymoff] = "symoff";
- Token::tochars[TOKarraylength] = "arraylength";
- Token::tochars[TOKarrayliteral] = "arrayliteral";
+ Token::tochars[TOKerror] = "error";
+ Token::tochars[TOKdotexp] = "dotexp";
+ Token::tochars[TOKdotti] = "dotti";
+ Token::tochars[TOKdotvar] = "dotvar";
+ Token::tochars[TOKdottype] = "dottype";
+ Token::tochars[TOKsymoff] = "symoff";
+ Token::tochars[TOKarraylength] = "arraylength";
+ Token::tochars[TOKarrayliteral] = "arrayliteral";
Token::tochars[TOKassocarrayliteral] = "assocarrayliteral";
- Token::tochars[TOKstructliteral] = "structliteral";
- Token::tochars[TOKstring] = "string";
- Token::tochars[TOKdsymbol] = "symbol";
- Token::tochars[TOKtuple] = "tuple";
- Token::tochars[TOKdeclaration] = "declaration";
- Token::tochars[TOKdottd] = "dottd";
- Token::tochars[TOKon_scope_exit] = "scope(exit)";
- Token::tochars[TOKon_scope_success] = "scope(success)";
- Token::tochars[TOKon_scope_failure] = "scope(failure)";
+ Token::tochars[TOKstructliteral] = "structliteral";
+ Token::tochars[TOKstring] = "string";
+ Token::tochars[TOKdsymbol] = "symbol";
+ Token::tochars[TOKtuple] = "tuple";
+ Token::tochars[TOKdeclaration] = "declaration";
+ Token::tochars[TOKdottd] = "dottd";
+ Token::tochars[TOKon_scope_exit] = "scope(exit)";
+ Token::tochars[TOKon_scope_success] = "scope(success)";
+ Token::tochars[TOKon_scope_failure] = "scope(failure)";
}
diff --git a/dmd/lexer.h b/dmd/lexer.h
index e32b870c..6f4f3f06 100644
--- a/dmd/lexer.h
+++ b/dmd/lexer.h
@@ -23,143 +23,143 @@ struct Identifier;
struct Module;
/* Tokens:
- ( )
- [ ]
- { }
- < > <= >= == != === !==
- << >> <<= >>= >>> >>>=
- + - += -=
- * / % *= /= %=
- & | ^ &= |= ^=
- = ! ~
- ++ --
- . -> : ,
- ? && ||
+ ( )
+ [ ]
+ { }
+ < > <= >= == != === !==
+ << >> <<= >>= >>> >>>=
+ + - += -=
+ * / % *= /= %=
+ & | ^ &= |= ^=
+ = ! ~
+ ++ --
+ . -> : ,
+ ? && ||
*/
enum TOK
{
- TOKreserved,
+ TOKreserved,
- // Other
- TOKlparen, TOKrparen,
- TOKlbracket, TOKrbracket,
- TOKlcurly, TOKrcurly,
- TOKcolon, TOKneg,
- TOKsemicolon, TOKdotdotdot,
- TOKeof, TOKcast,
- TOKnull, TOKassert,
- TOKtrue, TOKfalse,
- TOKarray, TOKcall,
- TOKaddress,
- TOKtype, TOKthrow,
- TOKnew, TOKdelete,
- TOKstar, TOKsymoff,
- TOKvar, TOKdotvar,
- TOKdotti, TOKdotexp,
- TOKdottype, TOKslice,
- TOKarraylength, TOKversion,
- TOKmodule, TOKdollar,
- TOKtemplate, TOKdottd,
- TOKdeclaration, TOKtypeof,
- TOKpragma, TOKdsymbol,
- TOKtypeid, TOKuadd,
- TOKremove,
- TOKnewanonclass, TOKcomment,
- TOKarrayliteral, TOKassocarrayliteral,
- TOKstructliteral,
+ // Other
+ TOKlparen, TOKrparen,
+ TOKlbracket, TOKrbracket,
+ TOKlcurly, TOKrcurly,
+ TOKcolon, TOKneg,
+ TOKsemicolon, TOKdotdotdot,
+ TOKeof, TOKcast,
+ TOKnull, TOKassert,
+ TOKtrue, TOKfalse,
+ TOKarray, TOKcall,
+ TOKaddress,
+ TOKtype, TOKthrow,
+ TOKnew, TOKdelete,
+ TOKstar, TOKsymoff,
+ TOKvar, TOKdotvar,
+ TOKdotti, TOKdotexp,
+ TOKdottype, TOKslice,
+ TOKarraylength, TOKversion,
+ TOKmodule, TOKdollar,
+ TOKtemplate, TOKdottd,
+ TOKdeclaration, TOKtypeof,
+ TOKpragma, TOKdsymbol,
+ TOKtypeid, TOKuadd,
+ TOKremove,
+ TOKnewanonclass, TOKcomment,
+ TOKarrayliteral, TOKassocarrayliteral,
+ TOKstructliteral,
- // Operators
- TOKlt, TOKgt,
- TOKle, TOKge,
- TOKequal, TOKnotequal,
- TOKidentity, TOKnotidentity,
- TOKindex, TOKis,
- TOKtobool,
+ // Operators
+ TOKlt, TOKgt,
+ TOKle, TOKge,
+ TOKequal, TOKnotequal,
+ TOKidentity, TOKnotidentity,
+ TOKindex, TOKis,
+ TOKtobool,
// 60
- // NCEG floating point compares
- // !<>= <> <>= !> !>= !< !<= !<>
- TOKunord,TOKlg,TOKleg,TOKule,TOKul,TOKuge,TOKug,TOKue,
+ // NCEG floating point compares
+ // !<>= <> <>= !> !>= !< !<= !<>
+ TOKunord,TOKlg,TOKleg,TOKule,TOKul,TOKuge,TOKug,TOKue,
- TOKshl, TOKshr,
- TOKshlass, TOKshrass,
- TOKushr, TOKushrass,
- TOKcat, TOKcatass, // ~ ~=
- TOKadd, TOKmin, TOKaddass, TOKminass,
- TOKmul, TOKdiv, TOKmod,
- TOKmulass, TOKdivass, TOKmodass,
- TOKand, TOKor, TOKxor,
- TOKandass, TOKorass, TOKxorass,
- TOKassign, TOKnot, TOKtilde,
- TOKplusplus, TOKminusminus, TOKconstruct, TOKblit,
- TOKdot, TOKarrow, TOKcomma,
- TOKquestion, TOKandand, TOKoror,
+ TOKshl, TOKshr,
+ TOKshlass, TOKshrass,
+ TOKushr, TOKushrass,
+ TOKcat, TOKcatass, // ~ ~=
+ TOKadd, TOKmin, TOKaddass, TOKminass,
+ TOKmul, TOKdiv, TOKmod,
+ TOKmulass, TOKdivass, TOKmodass,
+ TOKand, TOKor, TOKxor,
+ TOKandass, TOKorass, TOKxorass,
+ TOKassign, TOKnot, TOKtilde,
+ TOKplusplus, TOKminusminus, TOKconstruct, TOKblit,
+ TOKdot, TOKarrow, TOKcomma,
+ TOKquestion, TOKandand, TOKoror,
// 104
- // Numeric literals
- TOKint32v, TOKuns32v,
- TOKint64v, TOKuns64v,
- TOKfloat32v, TOKfloat64v, TOKfloat80v,
- TOKimaginary32v, TOKimaginary64v, TOKimaginary80v,
+ // Numeric literals
+ TOKint32v, TOKuns32v,
+ TOKint64v, TOKuns64v,
+ TOKfloat32v, TOKfloat64v, TOKfloat80v,
+ TOKimaginary32v, TOKimaginary64v, TOKimaginary80v,
- // Char constants
- TOKcharv, TOKwcharv, TOKdcharv,
+ // Char constants
+ TOKcharv, TOKwcharv, TOKdcharv,
- // Leaf operators
- TOKidentifier, TOKstring,
- TOKthis, TOKsuper,
- TOKhalt, TOKtuple,
- TOKerror,
+ // Leaf operators
+ TOKidentifier, TOKstring,
+ TOKthis, TOKsuper,
+ TOKhalt, TOKtuple,
+ TOKerror,
- // Basic types
- TOKvoid,
- TOKint8, TOKuns8,
- TOKint16, TOKuns16,
- TOKint32, TOKuns32,
- TOKint64, TOKuns64,
- TOKfloat32, TOKfloat64, TOKfloat80,
- TOKimaginary32, TOKimaginary64, TOKimaginary80,
- TOKcomplex32, TOKcomplex64, TOKcomplex80,
- TOKchar, TOKwchar, TOKdchar, TOKbit, TOKbool,
- TOKcent, TOKucent,
+ // Basic types
+ TOKvoid,
+ TOKint8, TOKuns8,
+ TOKint16, TOKuns16,
+ TOKint32, TOKuns32,
+ TOKint64, TOKuns64,
+ TOKfloat32, TOKfloat64, TOKfloat80,
+ TOKimaginary32, TOKimaginary64, TOKimaginary80,
+ TOKcomplex32, TOKcomplex64, TOKcomplex80,
+ TOKchar, TOKwchar, TOKdchar, TOKbit, TOKbool,
+ TOKcent, TOKucent,
// 150
- // Aggregates
- TOKstruct, TOKclass, TOKinterface, TOKunion, TOKenum, TOKimport,
- TOKtypedef, TOKalias, TOKoverride, TOKdelegate, TOKfunction,
- TOKmixin,
+ // Aggregates
+ TOKstruct, TOKclass, TOKinterface, TOKunion, TOKenum, TOKimport,
+ TOKtypedef, TOKalias, TOKoverride, TOKdelegate, TOKfunction,
+ TOKmixin,
- TOKalign, TOKextern, TOKprivate, TOKprotected, TOKpublic, TOKexport,
- TOKstatic, /*TOKvirtual,*/ TOKfinal, TOKconst, TOKabstract, TOKvolatile,
- TOKdebug, TOKdeprecated, TOKin, TOKout, TOKinout, TOKlazy,
- TOKauto, TOKpackage, TOKmanifest,
+ TOKalign, TOKextern, TOKprivate, TOKprotected, TOKpublic, TOKexport,
+ TOKstatic, /*TOKvirtual,*/ TOKfinal, TOKconst, TOKabstract, TOKvolatile,
+ TOKdebug, TOKdeprecated, TOKin, TOKout, TOKinout, TOKlazy,
+ TOKauto, TOKpackage, TOKmanifest,
- // Statements
- TOKif, TOKelse, TOKwhile, TOKfor, TOKdo, TOKswitch,
- TOKcase, TOKdefault, TOKbreak, TOKcontinue, TOKwith,
- TOKsynchronized, TOKreturn, TOKgoto, TOKtry, TOKcatch, TOKfinally,
- TOKasm, TOKforeach, TOKforeach_reverse,
- TOKscope,
- TOKon_scope_exit, TOKon_scope_failure, TOKon_scope_success,
+ // Statements
+ TOKif, TOKelse, TOKwhile, TOKfor, TOKdo, TOKswitch,
+ TOKcase, TOKdefault, TOKbreak, TOKcontinue, TOKwith,
+ TOKsynchronized, TOKreturn, TOKgoto, TOKtry, TOKcatch, TOKfinally,
+ TOKasm, TOKforeach, TOKforeach_reverse,
+ TOKscope,
+ TOKon_scope_exit, TOKon_scope_failure, TOKon_scope_success,
- // Contracts
- TOKbody, TOKinvariant,
+ // Contracts
+ TOKbody, TOKinvariant,
- // Testing
- TOKunittest,
+ // Testing
+ TOKunittest,
- // Added after 1.0
- TOKref,
- TOKmacro,
+ // Added after 1.0
+ TOKref,
+ TOKmacro,
#if DMDV2
- TOKtraits,
- TOKoverloadset,
- TOKpure,
- TOKnothrow,
- TOKtls,
- TOKline,
- TOKfile,
+ TOKtraits,
+ TOKoverloadset,
+ TOKpure,
+ TOKnothrow,
+ TOKtls,
+ TOKline,
+ TOKfile,
TOKshared,
#endif
@@ -168,74 +168,74 @@ enum TOK
TOKgep,
#endif
- TOKMAX
+ TOKMAX
};
-#define BASIC_TYPES \
- TOKwchar: case TOKdchar: \
- case TOKbit: case TOKbool: case TOKchar: \
- case TOKint8: case TOKuns8: \
- case TOKint16: case TOKuns16: \
- case TOKint32: case TOKuns32: \
- case TOKint64: case TOKuns64: \
- case TOKfloat32: case TOKfloat64: case TOKfloat80: \
- case TOKimaginary32: case TOKimaginary64: case TOKimaginary80: \
- case TOKcomplex32: case TOKcomplex64: case TOKcomplex80: \
- case TOKvoid
+#define BASIC_TYPES \
+ TOKwchar: case TOKdchar: \
+ case TOKbit: case TOKbool: case TOKchar: \
+ case TOKint8: case TOKuns8: \
+ case TOKint16: case TOKuns16: \
+ case TOKint32: case TOKuns32: \
+ case TOKint64: case TOKuns64: \
+ case TOKfloat32: case TOKfloat64: case TOKfloat80: \
+ case TOKimaginary32: case TOKimaginary64: case TOKimaginary80: \
+ case TOKcomplex32: case TOKcomplex64: case TOKcomplex80: \
+ case TOKvoid
-#define BASIC_TYPES_X(t) \
- TOKvoid: t = Type::tvoid; goto LabelX; \
- case TOKint8: t = Type::tint8; goto LabelX; \
- case TOKuns8: t = Type::tuns8; goto LabelX; \
- case TOKint16: t = Type::tint16; goto LabelX; \
- case TOKuns16: t = Type::tuns16; goto LabelX; \
- case TOKint32: t = Type::tint32; goto LabelX; \
- case TOKuns32: t = Type::tuns32; goto LabelX; \
- case TOKint64: t = Type::tint64; goto LabelX; \
- case TOKuns64: t = Type::tuns64; goto LabelX; \
- case TOKfloat32: t = Type::tfloat32; goto LabelX; \
- case TOKfloat64: t = Type::tfloat64; goto LabelX; \
- case TOKfloat80: t = Type::tfloat80; goto LabelX; \
- case TOKimaginary32: t = Type::timaginary32; goto LabelX; \
- case TOKimaginary64: t = Type::timaginary64; goto LabelX; \
- case TOKimaginary80: t = Type::timaginary80; goto LabelX; \
- case TOKcomplex32: t = Type::tcomplex32; goto LabelX; \
- case TOKcomplex64: t = Type::tcomplex64; goto LabelX; \
- case TOKcomplex80: t = Type::tcomplex80; goto LabelX; \
- case TOKbit: t = Type::tbit; goto LabelX; \
- case TOKbool: t = Type::tbool; goto LabelX; \
- case TOKchar: t = Type::tchar; goto LabelX; \
- case TOKwchar: t = Type::twchar; goto LabelX; \
- case TOKdchar: t = Type::tdchar; goto LabelX; \
- LabelX
+#define BASIC_TYPES_X(t) \
+ TOKvoid: t = Type::tvoid; goto LabelX; \
+ case TOKint8: t = Type::tint8; goto LabelX; \
+ case TOKuns8: t = Type::tuns8; goto LabelX; \
+ case TOKint16: t = Type::tint16; goto LabelX; \
+ case TOKuns16: t = Type::tuns16; goto LabelX; \
+ case TOKint32: t = Type::tint32; goto LabelX; \
+ case TOKuns32: t = Type::tuns32; goto LabelX; \
+ case TOKint64: t = Type::tint64; goto LabelX; \
+ case TOKuns64: t = Type::tuns64; goto LabelX; \
+ case TOKfloat32: t = Type::tfloat32; goto LabelX; \
+ case TOKfloat64: t = Type::tfloat64; goto LabelX; \
+ case TOKfloat80: t = Type::tfloat80; goto LabelX; \
+ case TOKimaginary32: t = Type::timaginary32; goto LabelX; \
+ case TOKimaginary64: t = Type::timaginary64; goto LabelX; \
+ case TOKimaginary80: t = Type::timaginary80; goto LabelX; \
+ case TOKcomplex32: t = Type::tcomplex32; goto LabelX; \
+ case TOKcomplex64: t = Type::tcomplex64; goto LabelX; \
+ case TOKcomplex80: t = Type::tcomplex80; goto LabelX; \
+ case TOKbit: t = Type::tbit; goto LabelX; \
+ case TOKbool: t = Type::tbool; goto LabelX; \
+ case TOKchar: t = Type::tchar; goto LabelX; \
+ case TOKwchar: t = Type::twchar; goto LabelX; \
+ case TOKdchar: t = Type::tdchar; goto LabelX; \
+ LabelX
struct Token
{
Token *next;
- unsigned char *ptr; // pointer to first character of this token within buffer
+ unsigned char *ptr; // pointer to first character of this token within buffer
enum TOK value;
unsigned char *blockComment; // doc comment string prior to this token
- unsigned char *lineComment; // doc comment for previous token
+ unsigned char *lineComment; // doc comment for previous token
union
{
- // Integers
- d_int64 int64value;
- d_uns64 uns64value;
+ // Integers
+ d_int64 int64value;
+ d_uns64 uns64value;
- // Floats
+ // Floats
#ifdef IN_GCC
- // real_t float80value; // can't use this in a union!
+ // real_t float80value; // can't use this in a union!
#else
- d_float80 float80value;
+ d_float80 float80value;
#endif
- struct
- { unsigned char *ustring; // UTF8 string
- unsigned len;
- unsigned char postfix; // 'c', 'w', 'd'
- };
+ struct
+ { unsigned char *ustring; // UTF8 string
+ unsigned len;
+ unsigned char postfix; // 'c', 'w', 'd'
+ };
- Identifier *ident;
+ Identifier *ident;
};
#ifdef IN_GCC
real_t float80value; // can't use this in a union!
@@ -256,20 +256,20 @@ struct Lexer
static OutBuffer stringbuffer;
static Token *freelist;
- Loc loc; // for error messages
+ Loc loc; // for error messages
- unsigned char *base; // pointer to start of buffer
- unsigned char *end; // past end of buffer
- unsigned char *p; // current character
+ unsigned char *base; // pointer to start of buffer
+ unsigned char *end; // past end of buffer
+ unsigned char *p; // current character
Token token;
Module *mod;
- int doDocComment; // collect doc comment information
- int anyToken; // !=0 means seen at least one token
- int commentToken; // !=0 means comments are TOKcomment's
+ int doDocComment; // collect doc comment information
+ int anyToken; // !=0 means seen at least one token
+ int commentToken; // !=0 means comments are TOKcomment's
Lexer(Module *mod,
- unsigned char *base, unsigned begoffset, unsigned endoffset,
- int doDocComment, int commentToken);
+ unsigned char *base, unsigned begoffset, unsigned endoffset,
+ int doDocComment, int commentToken);
static void initKeywords();
static Identifier *idPool(const char *s);
diff --git a/dmd/macro.c b/dmd/macro.c
index 6f800b6d..e87a0e06 100644
--- a/dmd/macro.c
+++ b/dmd/macro.c
@@ -56,12 +56,12 @@ Macro *Macro::search(unsigned char *name, size_t namelen)
//printf("Macro::search(%.*s)\n", namelen, name);
for (table = this; table; table = table->next)
{
- if (table->namelen == namelen &&
- memcmp(table->name, name, namelen) == 0)
- {
- //printf("\tfound %d\n", table->textlen);
- break;
- }
+ if (table->namelen == namelen &&
+ memcmp(table->name, name, namelen) == 0)
+ {
+ //printf("\tfound %d\n", table->textlen);
+ break;
+ }
}
return table;
}
@@ -75,13 +75,13 @@ Macro *Macro::define(Macro **ptable, unsigned char *name, size_t namelen, unsign
//assert(ptable);
for (table = *ptable; table; table = table->next)
{
- if (table->namelen == namelen &&
- memcmp(table->name, name, namelen) == 0)
- {
- table->text = text;
- table->textlen = textlen;
- return table;
- }
+ if (table->namelen == namelen &&
+ memcmp(table->name, name, namelen) == 0)
+ {
+ table->text = text;
+ table->textlen = textlen;
+ return table;
+ }
}
table = new Macro(name, namelen, text, textlen);
table->next = *ptable;
@@ -92,9 +92,9 @@ Macro *Macro::define(Macro **ptable, unsigned char *name, size_t namelen, unsign
/**********************************************************
* Given buffer p[0..end], extract argument marg[0..marglen].
* Params:
- * n 0: get entire argument
- * 1..9: get nth argument
- * -1: get 2nd through end
+ * n 0: get entire argument
+ * 1..9: get nth argument
+ * -1: get 2nd through end
*/
unsigned extractArgN(unsigned char *p, unsigned end, unsigned char **pmarg, unsigned *pmarglen, int n)
@@ -120,111 +120,111 @@ unsigned extractArgN(unsigned char *p, unsigned end, unsigned char **pmarg, unsi
#if 1
// Skip first space, if any, to find the start of the macro argument
if (v < end && isspace(p[v]))
- v++;
+ v++;
#else
// Skip past spaces to find the start of the macro argument
for (; v < end && isspace(p[v]); v++)
- ;
+ ;
#endif
*pmarg = p + v;
for (; v < end; v++)
{ unsigned char c = p[v];
- switch (c)
- {
- case ',':
- if (!inexp && !instring && !incomment && parens == 1)
- {
- argn++;
- if (argn == 1 && n == -1)
- { v++;
- goto Largstart;
- }
- if (argn == n)
- break;
- if (argn + 1 == n)
- { v++;
- goto Largstart;
- }
- }
- continue;
+ switch (c)
+ {
+ case ',':
+ if (!inexp && !instring && !incomment && parens == 1)
+ {
+ argn++;
+ if (argn == 1 && n == -1)
+ { v++;
+ goto Largstart;
+ }
+ if (argn == n)
+ break;
+ if (argn + 1 == n)
+ { v++;
+ goto Largstart;
+ }
+ }
+ continue;
- case '(':
- if (!inexp && !instring && !incomment)
- parens++;
- continue;
+ case '(':
+ if (!inexp && !instring && !incomment)
+ parens++;
+ continue;
- case ')':
- if (!inexp && !instring && !incomment && --parens == 0)
- {
- break;
- }
- continue;
+ case ')':
+ if (!inexp && !instring && !incomment && --parens == 0)
+ {
+ break;
+ }
+ continue;
- case '"':
- case '\'':
- if (!inexp && !incomment && intag)
- {
- if (c == instring)
- instring = 0;
- else if (!instring)
- instring = c;
- }
- continue;
+ case '"':
+ case '\'':
+ if (!inexp && !incomment && intag)
+ {
+ if (c == instring)
+ instring = 0;
+ else if (!instring)
+ instring = c;
+ }
+ continue;
- case '<':
- if (!inexp && !instring && !incomment)
- {
- if (v + 6 < end &&
- p[v + 1] == '!' &&
- p[v + 2] == '-' &&
- p[v + 3] == '-')
- {
- incomment = 1;
- v += 3;
- }
- else if (v + 2 < end &&
- isalpha(p[v + 1]))
- intag = 1;
- }
- continue;
+ case '<':
+ if (!inexp && !instring && !incomment)
+ {
+ if (v + 6 < end &&
+ p[v + 1] == '!' &&
+ p[v + 2] == '-' &&
+ p[v + 3] == '-')
+ {
+ incomment = 1;
+ v += 3;
+ }
+ else if (v + 2 < end &&
+ isalpha(p[v + 1]))
+ intag = 1;
+ }
+ continue;
- case '>':
- if (!inexp)
- intag = 0;
- continue;
+ case '>':
+ if (!inexp)
+ intag = 0;
+ continue;
- case '-':
- if (!inexp &&
- !instring &&
- incomment &&
- v + 2 < end &&
- p[v + 1] == '-' &&
- p[v + 2] == '>')
- {
- incomment = 0;
- v += 2;
- }
- continue;
+ case '-':
+ if (!inexp &&
+ !instring &&
+ incomment &&
+ v + 2 < end &&
+ p[v + 1] == '-' &&
+ p[v + 2] == '>')
+ {
+ incomment = 0;
+ v += 2;
+ }
+ continue;
- case 0xFF:
- if (v + 1 < end)
- {
- if (p[v + 1] == '{')
- inexp++;
- else if (p[v + 1] == '}')
- inexp--;
- }
- continue;
+ case 0xFF:
+ if (v + 1 < end)
+ {
+ if (p[v + 1] == '{')
+ inexp++;
+ else if (p[v + 1] == '}')
+ inexp--;
+ }
+ continue;
- default:
- continue;
- }
- break;
+ default:
+ continue;
+ }
+ break;
}
if (argn == 0 && n == -1)
- *pmarg = p + v;
+ *pmarg = p + v;
*pmarglen = p + v - *pmarg;
//printf("extractArg%d('%.*s') = '%.*s'\n", n, end, p, *pmarglen, *pmarg);
return v;
@@ -237,7 +237,7 @@ unsigned extractArgN(unsigned char *p, unsigned end, unsigned char **pmarg, unsi
*/
void Macro::expand(OutBuffer *buf, unsigned start, unsigned *pend,
- unsigned char *arg, unsigned arglen)
+ unsigned char *arg, unsigned arglen)
{
#if 0
printf("Macro::expand(buf[%d..%d], arg = '%.*s')\n", start, *pend, arglen, arg);
@@ -245,8 +245,8 @@ void Macro::expand(OutBuffer *buf, unsigned start, unsigned *pend,
#endif
static int nest;
- if (nest > 100) // limit recursive expansion
- return;
+ if (nest > 100) // limit recursive expansion
+ return;
nest++;
unsigned end = *pend;
@@ -258,190 +258,190 @@ void Macro::expand(OutBuffer *buf, unsigned start, unsigned *pend,
arg = memdup(arg, arglen);
for (unsigned u = start; u + 1 < end; )
{
- unsigned char *p = buf->data; // buf->data is not loop invariant
+ unsigned char *p = buf->data; // buf->data is not loop invariant
- /* Look for $0, but not $$0, and replace it with arg.
- */
- if (p[u] == '$' && (isdigit(p[u + 1]) || p[u + 1] == '+'))
- {
- if (u > start && p[u - 1] == '$')
- { // Don't expand $$0, but replace it with $0
- buf->remove(u - 1, 1);
- end--;
- u += 1; // now u is one past the closing '1'
- continue;
- }
+ /* Look for $0, but not $$0, and replace it with arg.
+ */
+ if (p[u] == '$' && (isdigit(p[u + 1]) || p[u + 1] == '+'))
+ {
+ if (u > start && p[u - 1] == '$')
+ { // Don't expand $$0, but replace it with $0
+ buf->remove(u - 1, 1);
+ end--;
+ u += 1; // now u is one past the closing '1'
+ continue;
+ }
- unsigned char c = p[u + 1];
- int n = (c == '+') ? -1 : c - '0';
+ unsigned char c = p[u + 1];
+ int n = (c == '+') ? -1 : c - '0';
- unsigned char *marg;
- unsigned marglen;
- extractArgN(arg, arglen, &marg, &marglen, n);
- if (marglen == 0)
- { // Just remove macro invocation
- //printf("Replacing '$%c' with '%.*s'\n", p[u + 1], marglen, marg);
- buf->remove(u, 2);
- end -= 2;
- }
- else if (c == '+')
- {
- // Replace '$+' with 'arg'
- //printf("Replacing '$%c' with '%.*s'\n", p[u + 1], marglen, marg);
- buf->remove(u, 2);
- buf->insert(u, marg, marglen);
- end += marglen - 2;
+ unsigned char *marg;
+ unsigned marglen;
+ extractArgN(arg, arglen, &marg, &marglen, n);
+ if (marglen == 0)
+ { // Just remove macro invocation
+ //printf("Replacing '$%c' with '%.*s'\n", p[u + 1], marglen, marg);
+ buf->remove(u, 2);
+ end -= 2;
+ }
+ else if (c == '+')
+ {
+ // Replace '$+' with 'arg'
+ //printf("Replacing '$%c' with '%.*s'\n", p[u + 1], marglen, marg);
+ buf->remove(u, 2);
+ buf->insert(u, marg, marglen);
+ end += marglen - 2;
- // Scan replaced text for further expansion
- unsigned mend = u + marglen;
- expand(buf, u, &mend, NULL, 0);
- end += mend - (u + marglen);
- u = mend;
- }
- else
- {
- // Replace '$1' with '\xFF{arg\xFF}'
- //printf("Replacing '$%c' with '\xFF{%.*s\xFF}'\n", p[u + 1], marglen, marg);
- buf->data[u] = 0xFF;
- buf->data[u + 1] = '{';
- buf->insert(u + 2, marg, marglen);
- buf->insert(u + 2 + marglen, "\xFF}", 2);
- end += -2 + 2 + marglen + 2;
+ // Scan replaced text for further expansion
+ unsigned mend = u + marglen;
+ expand(buf, u, &mend, NULL, 0);
+ end += mend - (u + marglen);
+ u = mend;
+ }
+ else
+ {
+ // Replace '$1' with '\xFF{arg\xFF}'
+ //printf("Replacing '$%c' with '\xFF{%.*s\xFF}'\n", p[u + 1], marglen, marg);
+ buf->data[u] = 0xFF;
+ buf->data[u + 1] = '{';
+ buf->insert(u + 2, marg, marglen);
+ buf->insert(u + 2 + marglen, "\xFF}", 2);
+ end += -2 + 2 + marglen + 2;
- // Scan replaced text for further expansion
- unsigned mend = u + 2 + marglen;
- expand(buf, u + 2, &mend, NULL, 0);
- end += mend - (u + 2 + marglen);
- u = mend;
- }
- //printf("u = %d, end = %d\n", u, end);
- //printf("#%.*s#\n", end, &buf->data[0]);
- continue;
- }
+ // Scan replaced text for further expansion
+ unsigned mend = u + 2 + marglen;
+ expand(buf, u + 2, &mend, NULL, 0);
+ end += mend - (u + 2 + marglen);
+ u = mend;
+ }
+ //printf("u = %d, end = %d\n", u, end);
+ //printf("#%.*s#\n", end, &buf->data[0]);
+ continue;
+ }
- u++;
+ u++;
}
/* Second pass - replace other macros
*/
for (unsigned u = start; u + 4 < end; )
{
- unsigned char *p = buf->data; // buf->data is not loop invariant
+ unsigned char *p = buf->data; // buf->data is not loop invariant
- /* A valid start of macro expansion is $(c, where c is
- * an id start character, and not $$(c.
- */
- if (p[u] == '$' && p[u + 1] == '(' && isidstart(p[u + 2]))
- {
- //printf("\tfound macro start '%c'\n", p[u + 2]);
- unsigned char *name = p + u + 2;
- unsigned namelen = 0;
+ /* A valid start of macro expansion is $(c, where c is
+ * an id start character, and not $$(c.
+ */
+ if (p[u] == '$' && p[u + 1] == '(' && isidstart(p[u + 2]))
+ {
+ //printf("\tfound macro start '%c'\n", p[u + 2]);
+ unsigned char *name = p + u + 2;
+ unsigned namelen = 0;
- unsigned char *marg;
- unsigned marglen;
+ unsigned char *marg;
+ unsigned marglen;
- unsigned v;
- /* Scan forward to find end of macro name and
- * beginning of macro argument (marg).
- */
- for (v = u + 2; v < end; v++)
- { unsigned char c = p[v];
+ unsigned v;
+ /* Scan forward to find end of macro name and
+ * beginning of macro argument (marg).
+ */
+ for (v = u + 2; v < end; v++)
+ { unsigned char c = p[v];
- if (!isidchar(c))
- { // We've gone past the end of the macro name.
- namelen = v - (u + 2);
- break;
- }
- }
+ if (!isidchar(c))
+ { // We've gone past the end of the macro name.
+ namelen = v - (u + 2);
+ break;
+ }
+ }
- v += extractArgN(p + v, end - v, &marg, &marglen, 0);
- assert(v <= end);
+ v += extractArgN(p + v, end - v, &marg, &marglen, 0);
+ assert(v <= end);
- if (v < end)
- { // v is on the closing ')'
- if (u > start && p[u - 1] == '$')
- { // Don't expand $$(NAME), but replace it with $(NAME)
- buf->remove(u - 1, 1);
- end--;
- u = v; // now u is one past the closing ')'
- continue;
- }
+ if (v < end)
+ { // v is on the closing ')'
+ if (u > start && p[u - 1] == '$')
+ { // Don't expand $$(NAME), but replace it with $(NAME)
+ buf->remove(u - 1, 1);
+ end--;
+ u = v; // now u is one past the closing ')'
+ continue;
+ }
- Macro *m = search(name, namelen);
- if (m)
- {
+ Macro *m = search(name, namelen);
+ if (m)
+ {
#if 0
- if (m->textlen && m->text[0] == ' ')
- { m->text++;
- m->textlen--;
- }
+ if (m->textlen && m->text[0] == ' ')
+ { m->text++;
+ m->textlen--;
+ }
#endif
- if (m->inuse && marglen == 0)
- { // Remove macro invocation
- buf->remove(u, v + 1 - u);
- end -= v + 1 - u;
- }
- else if (m->inuse && arglen == marglen && memcmp(arg, marg, arglen) == 0)
- { // Recursive expansion; just leave in place
+ if (m->inuse && marglen == 0)
+ { // Remove macro invocation
+ buf->remove(u, v + 1 - u);
+ end -= v + 1 - u;
+ }
+ else if (m->inuse && arglen == marglen && memcmp(arg, marg, arglen) == 0)
+ { // Recursive expansion; just leave in place
- }
- else
- {
- //printf("\tmacro '%.*s'(%.*s) = '%.*s'\n", m->namelen, m->name, marglen, marg, m->textlen, m->text);
+ }
+ else
+ {
+ //printf("\tmacro '%.*s'(%.*s) = '%.*s'\n", m->namelen, m->name, marglen, marg, m->textlen, m->text);
#if 1
- marg = memdup(marg, marglen);
- // Insert replacement text
- buf->spread(v + 1, 2 + m->textlen + 2);
- buf->data[v + 1] = 0xFF;
- buf->data[v + 2] = '{';
- memcpy(buf->data + v + 3, m->text, m->textlen);
- buf->data[v + 3 + m->textlen] = 0xFF;
- buf->data[v + 3 + m->textlen + 1] = '}';
+ marg = memdup(marg, marglen);
+ // Insert replacement text
+ buf->spread(v + 1, 2 + m->textlen + 2);
+ buf->data[v + 1] = 0xFF;
+ buf->data[v + 2] = '{';
+ memcpy(buf->data + v + 3, m->text, m->textlen);
+ buf->data[v + 3 + m->textlen] = 0xFF;
+ buf->data[v + 3 + m->textlen + 1] = '}';
- end += 2 + m->textlen + 2;
+ end += 2 + m->textlen + 2;
- // Scan replaced text for further expansion
- m->inuse++;
- unsigned mend = v + 1 + 2+m->textlen+2;
- expand(buf, v + 1, &mend, marg, marglen);
- end += mend - (v + 1 + 2+m->textlen+2);
- m->inuse--;
+ // Scan replaced text for further expansion
+ m->inuse++;
+ unsigned mend = v + 1 + 2+m->textlen+2;
+ expand(buf, v + 1, &mend, marg, marglen);
+ end += mend - (v + 1 + 2+m->textlen+2);
+ m->inuse--;
- buf->remove(u, v + 1 - u);
- end -= v + 1 - u;
- u += mend - (v + 1);
+ buf->remove(u, v + 1 - u);
+ end -= v + 1 - u;
+ u += mend - (v + 1);
#else
- // Insert replacement text
- buf->insert(v + 1, m->text, m->textlen);
- end += m->textlen;
+ // Insert replacement text
+ buf->insert(v + 1, m->text, m->textlen);
+ end += m->textlen;
- // Scan replaced text for further expansion
- m->inuse++;
- unsigned mend = v + 1 + m->textlen;
- expand(buf, v + 1, &mend, marg, marglen);
- end += mend - (v + 1 + m->textlen);
- m->inuse--;
+ // Scan replaced text for further expansion
+ m->inuse++;
+ unsigned mend = v + 1 + m->textlen;
+ expand(buf, v + 1, &mend, marg, marglen);
+ end += mend - (v + 1 + m->textlen);
+ m->inuse--;
- buf->remove(u, v + 1 - u);
- end -= v + 1 - u;
- u += mend - (v + 1);
+ buf->remove(u, v + 1 - u);
+ end -= v + 1 - u;
+ u += mend - (v + 1);
#endif
- mem.free(marg);
- //printf("u = %d, end = %d\n", u, end);
- //printf("#%.*s#\n", end - u, &buf->data[u]);
- continue;
- }
- }
- else
- {
- // Replace $(NAME) with nothing
- buf->remove(u, v + 1 - u);
- end -= (v + 1 - u);
- continue;
- }
- }
- }
- u++;
+ mem.free(marg);
+ //printf("u = %d, end = %d\n", u, end);
+ //printf("#%.*s#\n", end - u, &buf->data[u]);
+ continue;
+ }
+ }
+ else
+ {
+ // Replace $(NAME) with nothing
+ buf->remove(u, v + 1 - u);
+ end -= (v + 1 - u);
+ continue;
+ }
+ }
+ }
+ u++;
}
mem.free(arg);
*pend = end;
diff --git a/dmd/macro.h b/dmd/macro.h
index ecaf96b9..cf99ab81 100644
--- a/dmd/macro.h
+++ b/dmd/macro.h
@@ -21,15 +21,15 @@
class Macro
{
- Macro *next; // next in list
+ Macro *next; // next in list
- unsigned char *name; // macro name
- size_t namelen; // length of macro name
+ unsigned char *name; // macro name
+ size_t namelen; // length of macro name
- unsigned char *text; // macro replacement text
- size_t textlen; // length of replacement text
+ unsigned char *text; // macro replacement text
+ size_t textlen; // length of replacement text
- int inuse; // macro is in use (don't expand)
+ int inuse; // macro is in use (don't expand)
Macro(unsigned char *name, size_t namelen, unsigned char *text, size_t textlen);
Macro *search(unsigned char *name, size_t namelen);
@@ -38,7 +38,7 @@ class Macro
static Macro *define(Macro **ptable, unsigned char *name, size_t namelen, unsigned char *text, size_t textlen);
void expand(OutBuffer *buf, unsigned start, unsigned *pend,
- unsigned char *arg, unsigned arglen);
+ unsigned char *arg, unsigned arglen);
};
#endif
diff --git a/dmd/mangle.c b/dmd/mangle.c
index 3ee06554..af8294ed 100644
--- a/dmd/mangle.c
+++ b/dmd/mangle.c
@@ -38,29 +38,29 @@ char *mangle(Declaration *sthis)
s = sthis;
do
{
- //printf("mangle: s = %p, '%s', parent = %p\n", s, s->toChars(), s->parent);
- if (s->ident)
- {
- FuncDeclaration *fd = s->isFuncDeclaration();
- if (s != sthis && fd)
- {
- id = mangle(fd);
- buf.prependstring(id);
- goto L1;
- }
- else
- {
- id = s->ident->toChars();
- int len = strlen(id);
- char tmp[sizeof(len) * 3 + 1];
- buf.prependstring(id);
- sprintf(tmp, "%d", len);
- buf.prependstring(tmp);
- }
- }
- else
- buf.prependstring("0");
- s = s->parent;
+ //printf("mangle: s = %p, '%s', parent = %p\n", s, s->toChars(), s->parent);
+ if (s->ident)
+ {
+ FuncDeclaration *fd = s->isFuncDeclaration();
+ if (s != sthis && fd)
+ {
+ id = mangle(fd);
+ buf.prependstring(id);
+ goto L1;
+ }
+ else
+ {
+ id = s->ident->toChars();
+ int len = strlen(id);
+ char tmp[sizeof(len) * 3 + 1];
+ buf.prependstring(id);
+ sprintf(tmp, "%d", len);
+ buf.prependstring(tmp);
+ }
+ }
+ else
+ buf.prependstring("0");
+ s = s->parent;
} while (s);
// buf.prependstring("_D");
@@ -69,16 +69,16 @@ L1:
//printf("sthis->type = %s\n", sthis->type->toChars());
FuncDeclaration *fd = sthis->isFuncDeclaration();
if (fd && (fd->needThis() || fd->isNested()))
- buf.writeByte(Type::needThisPrefix());
+ buf.writeByte(Type::needThisPrefix());
if (sthis->type->deco)
- buf.writestring(sthis->type->deco);
+ buf.writestring(sthis->type->deco);
else
{
#ifdef DEBUG
- if (!fd->inferRetType)
- printf("%s\n", fd->toChars());
+ if (!fd->inferRetType)
+ printf("%s\n", fd->toChars());
#endif
- assert(fd && fd->inferRetType);
+ assert(fd && fd->inferRetType);
}
id = buf.toChars();
@@ -90,81 +90,81 @@ char *Declaration::mangle()
#if __DMC__
__out(result)
{
- int len = strlen(result);
+ int len = strlen(result);
- assert(len > 0);
- //printf("mangle: '%s' => '%s'\n", toChars(), result);
- for (int i = 0; i < len; i++)
- {
- assert(result[i] == '_' ||
- result[i] == '@' ||
- isalnum(result[i]) || result[i] & 0x80);
- }
+ assert(len > 0);
+ //printf("mangle: '%s' => '%s'\n", toChars(), result);
+ for (int i = 0; i < len; i++)
+ {
+ assert(result[i] == '_' ||
+ result[i] == '@' ||
+ isalnum(result[i]) || result[i] & 0x80);
+ }
}
__body
#endif
{
- //printf("Declaration::mangle(this = %p, '%s', parent = '%s', linkage = %d)\n", this, toChars(), parent ? parent->toChars() : "null", linkage);
- if (!parent || parent->isModule()) // if at global scope
- {
- // If it's not a D declaration, no mangling
- switch (linkage)
- {
- case LINKd:
- break;
+ //printf("Declaration::mangle(this = %p, '%s', parent = '%s', linkage = %d)\n", this, toChars(), parent ? parent->toChars() : "null", linkage);
+ if (!parent || parent->isModule()) // if at global scope
+ {
+ // If it's not a D declaration, no mangling
+ switch (linkage)
+ {
+ case LINKd:
+ break;
#if IN_LLVM
case LINKintrinsic:
#endif
- case LINKc:
- case LINKwindows:
- case LINKpascal:
- return ident->toChars();
+ case LINKc:
+ case LINKwindows:
+ case LINKpascal:
+ return ident->toChars();
- case LINKcpp:
+ case LINKcpp:
#if DMDV2 && (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS)
- return cpp_mangle(this);
+ return cpp_mangle(this);
#else
- // Windows C++ mangling is done by C++ back end
- return ident->toChars();
+ // Windows C++ mangling is done by C++ back end
+ return ident->toChars();
#endif
- case LINKdefault:
- error("forward declaration");
- return ident->toChars();
+ case LINKdefault:
+ error("forward declaration");
+ return ident->toChars();
- default:
- fprintf(stdmsg, "'%s', linkage = %d\n", toChars(), linkage);
- assert(0);
- }
- }
- char *p = ::mangle(this);
- OutBuffer buf;
- buf.writestring("_D");
- buf.writestring(p);
- p = buf.toChars();
- buf.data = NULL;
- //printf("Declaration::mangle(this = %p, '%s', parent = '%s', linkage = %d) = %s\n", this, toChars(), parent ? parent->toChars() : "null", linkage, p);
- return p;
+ default:
+ fprintf(stdmsg, "'%s', linkage = %d\n", toChars(), linkage);
+ assert(0);
+ }
+ }
+ char *p = ::mangle(this);
+ OutBuffer buf;
+ buf.writestring("_D");
+ buf.writestring(p);
+ p = buf.toChars();
+ buf.data = NULL;
+ //printf("Declaration::mangle(this = %p, '%s', parent = '%s', linkage = %d) = %s\n", this, toChars(), parent ? parent->toChars() : "null", linkage, p);
+ return p;
}
char *FuncDeclaration::mangle()
#if __DMC__
__out(result)
{
- assert(strlen(result) > 0);
+ assert(strlen(result) > 0);
}
__body
#endif
{
- if (isMain())
- return (char *)"_Dmain";
+ if (isMain())
+ return (char *)"_Dmain";
- if (isWinMain() || isDllMain())
- return ident->toChars();
+ if (isWinMain() || isDllMain())
+ return ident->toChars();
- assert(this);
- return Declaration::mangle();
+ assert(this);
+ return Declaration::mangle();
}
char *StructDeclaration::mangle()
@@ -191,21 +191,21 @@ char *ClassDeclaration::mangle()
* names for them.
*/
if (ident == Id::Exception)
- { if (parent->ident == Id::object)
- parent = NULL;
+ { if (parent->ident == Id::object)
+ parent = NULL;
}
else if (ident == Id::TypeInfo ||
-// ident == Id::Exception ||
- ident == Id::TypeInfo_Struct ||
- ident == Id::TypeInfo_Class ||
- ident == Id::TypeInfo_Typedef ||
- ident == Id::TypeInfo_Tuple ||
- this == object ||
- this == classinfo ||
- this == Module::moduleinfo ||
- memcmp(ident->toChars(), "TypeInfo_", 9) == 0
+// ident == Id::Exception ||
+ ident == Id::TypeInfo_Struct ||
+ ident == Id::TypeInfo_Class ||
+ ident == Id::TypeInfo_Typedef ||
+ ident == Id::TypeInfo_Tuple ||
+ this == object ||
+ this == classinfo ||
+ this == Module::moduleinfo ||
+ memcmp(ident->toChars(), "TypeInfo_", 9) == 0
)
- parent = NULL;
+ parent = NULL;
char *id = Dsymbol::mangle();
parent = parentsave;
@@ -221,18 +221,18 @@ char *TemplateInstance::mangle()
#if 0
printf("TemplateInstance::mangle() %s", toChars());
if (parent)
- printf(" parent = %s %s", parent->kind(), parent->toChars());
+ printf(" parent = %s %s", parent->kind(), parent->toChars());
printf("\n");
#endif
id = ident ? ident->toChars() : toChars();
if (!tempdecl)
- error("is not defined");
+ error("is not defined");
else if (tempdecl->parent)
{
- char *p = tempdecl->parent->mangle();
- if (p[0] == '_' && p[1] == 'D')
- p += 2;
- buf.writestring(p);
+ char *p = tempdecl->parent->mangle();
+ if (p[0] == '_' && p[1] == 'D')
+ p += 2;
+ buf.writestring(p);
}
buf.printf("%zu%s", strlen(id), id);
id = buf.toChars();
@@ -256,10 +256,10 @@ char *TemplateMixin::mangle()
id = ident ? ident->toChars() : toChars();
if (parent)
{
- char *p = parent->mangle();
- if (p[0] == '_' && p[1] == 'D')
- p += 2;
- buf.writestring(p);
+ char *p = parent->mangle();
+ if (p[0] == '_' && p[1] == 'D')
+ p += 2;
+ buf.writestring(p);
}
buf.printf("%zu%s", strlen(id), id);
id = buf.toChars();
@@ -276,16 +276,16 @@ char *Dsymbol::mangle()
#if 0
printf("Dsymbol::mangle() '%s'", toChars());
if (parent)
- printf(" parent = %s %s", parent->kind(), parent->toChars());
+ printf(" parent = %s %s", parent->kind(), parent->toChars());
printf("\n");
#endif
id = ident ? ident->toChars() : toChars();
if (parent)
{
- char *p = parent->mangle();
- if (p[0] == '_' && p[1] == 'D')
- p += 2;
- buf.writestring(p);
+ char *p = parent->mangle();
+ if (p[0] == '_' && p[1] == 'D')
+ p += 2;
+ buf.writestring(p);
}
buf.printf("%zu%s", strlen(id), id);
id = buf.toChars();
diff --git a/dmd/mars.c b/dmd/mars.c
index dbc46460..0fee5e66 100644
--- a/dmd/mars.c
+++ b/dmd/mars.c
@@ -82,11 +82,11 @@ char *Loc::toChars() const
if (filename)
{
- buf.printf("%s", filename);
+ buf.printf("%s", filename);
}
if (linnum)
- buf.printf("(%d)", linnum);
+ buf.printf("(%d)", linnum);
buf.writeByte(0);
return (char *)buf.extractData();
}
@@ -126,16 +126,16 @@ void verror(Loc loc, const char *format, va_list ap)
{
if (!global.gag)
{
- char *p = loc.toChars();
+ char *p = loc.toChars();
- if (*p)
- fprintf(stdmsg, "%s: ", p);
- mem.free(p);
+ if (*p)
+ fprintf(stdmsg, "%s: ", p);
+ mem.free(p);
- fprintf(stdmsg, "Error: ");
- vfprintf(stdmsg, format, ap);
- fprintf(stdmsg, "\n");
- fflush(stdmsg);
+ fprintf(stdmsg, "Error: ");
+ vfprintf(stdmsg, format, ap);
+ fprintf(stdmsg, "\n");
+ fflush(stdmsg);
}
global.errors++;
}
@@ -144,26 +144,26 @@ void vwarning(Loc loc, const char *format, va_list ap)
{
if (global.params.warnings && !global.gag)
{
- char *p = loc.toChars();
+ char *p = loc.toChars();
- if (*p)
- fprintf(stdmsg, "%s: ", p);
- mem.free(p);
+ if (*p)
+ fprintf(stdmsg, "%s: ", p);
+ mem.free(p);
- fprintf(stdmsg, "Warning: ");
+ fprintf(stdmsg, "Warning: ");
#if _MSC_VER
- // MS doesn't recognize %zu format
- OutBuffer tmp;
- tmp.vprintf(format, ap);
- fprintf(stdmsg, "%s", tmp.toChars());
+ // MS doesn't recognize %zu format
+ OutBuffer tmp;
+ tmp.vprintf(format, ap);
+ fprintf(stdmsg, "%s", tmp.toChars());
#else
- vfprintf(stdmsg, format, ap);
+ vfprintf(stdmsg, format, ap);
#endif
- fprintf(stdmsg, "\n");
- fflush(stdmsg);
+ fprintf(stdmsg, "\n");
+ fflush(stdmsg);
//halt();
- if (global.params.warnings == 1)
- global.warnings++; // warnings don't count if gagged
+ if (global.params.warnings == 1)
+ global.warnings++; // warnings don't count if gagged
}
}
@@ -208,9 +208,9 @@ void getenv_setargv(const char *envvar, int *pargc, char** *pargv)
char *env = getenv(envvar);
if (!env)
- return;
+ return;
- env = mem.strdup(env); // create our own writable copy
+ env = mem.strdup(env); // create our own writable copy
int argc = *pargc;
Array *argv = new Array();
@@ -235,76 +235,76 @@ void getenv_setargv(const char *envvar, int *pargc, char** *pargv)
argv->push((char*)"");
argc++;
- int j = 1; // leave argv[0] alone
+ int j = 1; // leave argv[0] alone
while (1)
{
- int wildcard = 1; // do wildcard expansion
- switch (*env)
- {
- case ' ':
- case '\t':
- env++;
- break;
+ int wildcard = 1; // do wildcard expansion
+ switch (*env)
+ {
+ case ' ':
+ case '\t':
+ env++;
+ break;
- case 0:
- goto Ldone;
+ case 0:
+ goto Ldone;
- case '"':
- wildcard = 0;
- default:
- argv->push(env); // append
- //argv->insert(j, env); // insert at position j
- j++;
- argc++;
- p = env;
- slash = 0;
- instring = 0;
- c = 0;
+ case '"':
+ wildcard = 0;
+ default:
+ argv->push(env); // append
+ //argv->insert(j, env); // insert at position j
+ j++;
+ argc++;
+ p = env;
+ slash = 0;
+ instring = 0;
+ c = 0;
- while (1)
- {
- c = *env++;
- switch (c)
- {
- case '"':
- p -= (slash >> 1);
- if (slash & 1)
- { p--;
- goto Laddc;
- }
- instring ^= 1;
- slash = 0;
- continue;
+ while (1)
+ {
+ c = *env++;
+ switch (c)
+ {
+ case '"':
+ p -= (slash >> 1);
+ if (slash & 1)
+ { p--;
+ goto Laddc;
+ }
+ instring ^= 1;
+ slash = 0;
+ continue;
- case ' ':
- case '\t':
- if (instring)
- goto Laddc;
- *p = 0;
- //if (wildcard)
- //wildcardexpand(); // not implemented
- break;
+ case ' ':
+ case '\t':
+ if (instring)
+ goto Laddc;
+ *p = 0;
+ //if (wildcard)
+ //wildcardexpand(); // not implemented
+ break;
- case '\\':
- slash++;
- *p++ = c;
- continue;
+ case '\\':
+ slash++;
+ *p++ = c;
+ continue;
- case 0:
- *p = 0;
- //if (wildcard)
- //wildcardexpand(); // not implemented
- goto Ldone;
+ case 0:
+ *p = 0;
+ //if (wildcard)
+ //wildcardexpand(); // not implemented
+ goto Ldone;
- default:
- Laddc:
- slash = 0;
- *p++ = c;
- continue;
- }
- break;
- }
- }
+ default:
+ Laddc:
+ slash = 0;
+ *p++ = c;
+ continue;
+ }
+ break;
+ }
+ }
}
Ldone:
diff --git a/dmd/mars.h b/dmd/mars.h
index b4594051..8500b378 100644
--- a/dmd/mars.h
+++ b/dmd/mars.h
@@ -26,37 +26,37 @@ dmd are:
Macros defined by the compiler, not the code:
Compiler:
- __DMC__ Digital Mars compiler
- _MSC_VER Microsoft compiler
- __GNUC__ Gnu compiler
+ __DMC__ Digital Mars compiler
+ _MSC_VER Microsoft compiler
+ __GNUC__ Gnu compiler
Host operating system:
- _WIN32 Microsoft NT, Windows 95, Windows 98, Win32s,
- Windows 2000, Win XP, Vista
- _WIN64 Windows for AMD64
- linux Linux
- __APPLE__ Mac OSX
- __FreeBSD__ FreeBSD
- __sun&&__SVR4 Solaris, OpenSolaris (yes, both macros are necessary)
+ _WIN32 Microsoft NT, Windows 95, Windows 98, Win32s,
+ Windows 2000, Win XP, Vista
+ _WIN64 Windows for AMD64
+ linux Linux
+ __APPLE__ Mac OSX
+ __FreeBSD__ FreeBSD
+ __sun&&__SVR4 Solaris, OpenSolaris (yes, both macros are necessary)
For the target systems, there are the target operating system and
the target object file format:
Target operating system:
- TARGET_WINDOS Covers 32 bit windows and 64 bit windows
- TARGET_LINUX Covers 32 and 64 bit linux
- TARGET_OSX Covers 32 and 64 bit Mac OSX
- TARGET_FREEBSD Covers 32 and 64 bit FreeBSD
- TARGET_SOLARIS Covers 32 and 64 bit Solaris
- TARGET_NET Covers .Net
+ TARGET_WINDOS Covers 32 bit windows and 64 bit windows
+ TARGET_LINUX Covers 32 and 64 bit linux
+ TARGET_OSX Covers 32 and 64 bit Mac OSX
+ TARGET_FREEBSD Covers 32 and 64 bit FreeBSD
+ TARGET_SOLARIS Covers 32 and 64 bit Solaris
+ TARGET_NET Covers .Net
It is expected that the compiler for each platform will be able
to generate 32 and 64 bit code from the same compiler binary.
Target object module format:
- OMFOBJ Intel Object Module Format, used on Windows
- ELFOBJ Elf Object Module Format, used on linux, FreeBSD and Solaris
- MACHOBJ Mach-O Object Module Format, used on Mac OSX
+ OMFOBJ Intel Object Module Format, used on Windows
+ ELFOBJ Elf Object Module Format, used on linux, FreeBSD and Solaris
+ MACHOBJ Mach-O Object Module Format, used on Mac OSX
There are currently no macros for byte endianness order.
*/
@@ -89,11 +89,11 @@ the target object file format:
/* Changes for the GDC compiler by David Friedman */
#endif
-#define DMDV2 0 // Version 2.0 features
-#define BREAKABI 1 // 0 if not ready to break the ABI just yet
-#define STRUCTTHISREF DMDV2 // if 'this' for struct is a reference, not a pointer
-#define SNAN_DEFAULT_INIT DMDV2 // if floats are default initialized to signalling NaN
-#define SARRAYVALUE DMDV2 // static arrays are value types
+#define DMDV2 0 // Version 2.0 features
+#define BREAKABI 1 // 0 if not ready to break the ABI just yet
+#define STRUCTTHISREF DMDV2 // if 'this' for struct is a reference, not a pointer
+#define SNAN_DEFAULT_INIT DMDV2 // if floats are default initialized to signalling NaN
+#define SARRAYVALUE DMDV2 // static arrays are value types
#define MODULEINFO_IS_STRUCT DMDV2 // if ModuleInfo is a struct rather than a class
// Set if C++ mangling is done by the front end
@@ -105,7 +105,7 @@ the target object file format:
*/
#if _WIN32
-#define TARGET_WINDOS 1 // Windows dmd generates Windows targets
+#define TARGET_WINDOS 1 // Windows dmd generates Windows targets
#define OMFOBJ 1
#endif
@@ -161,15 +161,15 @@ struct Param
bool obj; // write object file
bool link; // perform link
bool verbose; // verbose compile
- ubyte symdebug; // insert debug symbolic information
+ ubyte symdebug; // insert debug symbolic information
#if !IN_LLVM
// LDC uses a different mechanism
bool optimize; // run optimizer
char optimizeLevel; // optimization level
#endif
- char vtls; // identify thread local variables
- ARCH cpu; // target CPU
- OS os; // target OS
+ char vtls; // identify thread local variables
+ ARCH cpu; // target CPU
+ OS os; // target OS
bool is64bit; // generate 64 bit code
bool isLE; // generate little endian code
bool useDeprecated; // allow use of deprecated features
@@ -182,42 +182,42 @@ struct Param
bool useUnitTests; // generate unittest code
bool useInline; // inline expand functions
bool warnings; // enable warnings
- ubyte Dversion; // D version number
- // 1: warnings as errors
- // 2: informational warnings (no errors)
- char safe; // enforce safe memory model
+ ubyte Dversion; // D version number
+ // 1: warnings as errors
+ // 2: informational warnings (no errors)
+ char safe; // enforce safe memory model
- char *argv0; // program name
- Array *imppath; // array of char*'s of where to look for import modules
- Array *fileImppath; // array of char*'s of where to look for file import modules
- char *objdir; // .obj file output directory
- char *objname; // .obj file output name
+ char *argv0; // program name
+ Array *imppath; // array of char*'s of where to look for import modules
+ Array *fileImppath; // array of char*'s of where to look for file import modules
+ char *objdir; // .obj file output directory
+ char *objname; // .obj file output name
bool doDocComments; // process embedded documentation comments
- char *docdir; // write documentation file to docdir directory
- char *docname; // write documentation file to docname
- Array *ddocfiles; // macro include files for Ddoc
+ char *docdir; // write documentation file to docdir directory
+ char *docname; // write documentation file to docname
+ Array *ddocfiles; // macro include files for Ddoc
bool doHdrGeneration; // process embedded documentation comments
- char *hdrdir; // write 'header' file to docdir directory
- char *hdrname; // write 'header' file to docname
+ char *hdrdir; // write 'header' file to docdir directory
+ char *hdrname; // write 'header' file to docname
- char doXGeneration; // write JSON file
- char *xfilename; // write JSON file to xfilename
+ char doXGeneration; // write JSON file
+ char *xfilename; // write JSON file to xfilename
- unsigned debuglevel; // debug level
- Array *debugids; // debug identifiers
+ unsigned debuglevel; // debug level
+ Array *debugids; // debug identifiers
- unsigned versionlevel; // version level
- Array *versionids; // version identifiers
+ unsigned versionlevel; // version level
+ Array *versionids; // version identifiers
bool dump_source;
- Array *defaultlibnames; // default libraries for non-debug builds
- Array *debuglibnames; // default libraries for debug builds
+ Array *defaultlibnames; // default libraries for non-debug builds
+ Array *debuglibnames; // default libraries for debug builds
- char *moduleDepsFile; // filename for deps output
- OutBuffer *moduleDeps; // contents to be written to deps file
+ char *moduleDepsFile; // filename for deps output
+ OutBuffer *moduleDeps; // contents to be written to deps file
// Hidden debug switches
bool debuga;
@@ -270,24 +270,24 @@ struct Global
char *bc_ext;
char *s_ext;
const char *lib_ext;
- const char *doc_ext; // for Ddoc generated files
- const char *ddoc_ext; // for Ddoc macro include files
- const char *hdr_ext; // for D 'header' import files
- const char *json_ext; // for JSON files
- const char *map_ext; // for .map files
+ const char *doc_ext; // for Ddoc generated files
+ const char *ddoc_ext; // for Ddoc macro include files
+ const char *hdr_ext; // for D 'header' import files
+ const char *json_ext; // for JSON files
+ const char *map_ext; // for .map files
const char *copyright;
const char *written;
- Array *path; // Array of char*'s which form the import lookup path
- Array *filePath; // Array of char*'s which form the file import lookup path
+ Array *path; // Array of char*'s which form the import lookup path
+ Array *filePath; // Array of char*'s which form the file import lookup path
int structalign;
const char *version;
char *ldc_version;
char *llvm_version;
Param params;
- unsigned errors; // number of errors reported so far
- unsigned warnings; // number of warnings reported so far
- unsigned gag; // !=0 means gag reporting of errors & warnings
+ unsigned errors; // number of errors reported so far
+ unsigned warnings; // number of warnings reported so far
+ unsigned gag; // !=0 means gag reporting of errors & warnings
Global();
};
@@ -297,7 +297,7 @@ extern Global global;
/* Set if Windows Structured Exception Handling C extensions are supported.
* Apparently, VC has dropped support for these?
*/
-#define WINDOWS_SEH (_WIN32 && __DMC__)
+#define WINDOWS_SEH (_WIN32 && __DMC__)
#ifdef __DMC__
@@ -313,29 +313,29 @@ extern Global global;
// Be careful not to care about sign when using dinteger_t
//typedef uint64_t integer_t;
-typedef uint64_t dinteger_t; // use this instead of integer_t to
- // avoid conflicts with system #include's
+typedef uint64_t dinteger_t; // use this instead of integer_t to
+ // avoid conflicts with system #include's
// Signed and unsigned variants
typedef int64_t sinteger_t;
typedef uint64_t uinteger_t;
-typedef int8_t d_int8;
-typedef uint8_t d_uns8;
-typedef int16_t d_int16;
-typedef uint16_t d_uns16;
-typedef int32_t d_int32;
-typedef uint32_t d_uns32;
-typedef int64_t d_int64;
-typedef uint64_t d_uns64;
+typedef int8_t d_int8;
+typedef uint8_t d_uns8;
+typedef int16_t d_int16;
+typedef uint16_t d_uns16;
+typedef int32_t d_int32;
+typedef uint32_t d_uns32;
+typedef int64_t d_int64;
+typedef uint64_t d_uns64;
-typedef float d_float32;
-typedef double d_float64;
-typedef long double d_float80;
+typedef float d_float32;
+typedef double d_float64;
+typedef long double d_float80;
-typedef d_uns8 d_char;
-typedef d_uns16 d_wchar;
-typedef d_uns32 d_dchar;
+typedef d_uns8 d_char;
+typedef d_uns16 d_wchar;
+typedef d_uns32 d_dchar;
#ifdef IN_GCC
#include "d-gcc-real.h"
@@ -357,7 +357,7 @@ typedef long double real_t;
struct Module;
-//typedef unsigned Loc; // file location
+//typedef unsigned Loc; // file location
struct Loc
{
const char *filename;
@@ -365,14 +365,14 @@ struct Loc
Loc()
{
- linnum = 0;
- filename = NULL;
+ linnum = 0;
+ filename = NULL;
}
Loc(int x)
{
- linnum = x;
- filename = NULL;
+ linnum = x;
+ filename = NULL;
}
Loc(Module *mod, unsigned linnum);
@@ -382,15 +382,15 @@ struct Loc
};
#ifndef GCC_SAFE_DMD
-#define TRUE 1
-#define FALSE 0
+#define TRUE 1
+#define FALSE 0
#endif
-#define INTERFACE_OFFSET 0 // if 1, put classinfo as first entry
- // in interface vtbl[]'s
-#define INTERFACE_VIRTUAL 0 // 1 means if an interface appears
- // in the inheritance graph multiple
- // times, only one is used
+#define INTERFACE_OFFSET 0 // if 1, put classinfo as first entry
+ // in interface vtbl[]'s
+#define INTERFACE_VIRTUAL 0 // 1 means if an interface appears
+ // in the inheritance graph multiple
+ // times, only one is used
enum LINK
{
@@ -418,12 +418,12 @@ enum DYNCAST
enum MATCH
{
- MATCHnomatch, // no match
- MATCHconvert, // match with conversions
+ MATCHnomatch, // no match
+ MATCHconvert, // match with conversions
#if DMDV2
- MATCHconst, // match with conversion to const
+ MATCHconst, // match with conversion to const
#endif
- MATCHexact // exact match
+ MATCHexact // exact match
};
typedef uint64_t StorageClass;
diff --git a/dmd/mem.c b/dmd/mem.c
index cdd0958c..3660cd85 100644
--- a/dmd/mem.c
+++ b/dmd/mem.c
@@ -1,6 +1,6 @@
-/* Copyright (c) 2000 Digital Mars */
-/* All Rights Reserved */
+/* Copyright (c) 2000 Digital Mars */
+/* All Rights Reserved */
#include
#include
@@ -35,10 +35,10 @@ char *Mem::strdup(const char *s)
if (s)
{
- p = GC_strdup(s);
- if (p)
- return p;
- error();
+ p = GC_strdup(s);
+ if (p)
+ return p;
+ error();
}
return NULL;
}
@@ -47,12 +47,12 @@ void *Mem::malloc(size_t size)
{ void *p;
if (!size)
- p = NULL;
+ p = NULL;
else
{
- p = GC_malloc(size);
- if (!p)
- error();
+ p = GC_malloc(size);
+ if (!p)
+ error();
}
return p;
}
@@ -61,12 +61,12 @@ void *Mem::calloc(size_t size, size_t n)
{ void *p;
if (!size || !n)
- p = NULL;
+ p = NULL;
else
{
- p = GC_malloc(size * n);
- if (!p)
- error();
+ p = GC_malloc(size * n);
+ if (!p)
+ error();
memset(p, 0, size * n);
}
return p;
@@ -75,22 +75,22 @@ void *Mem::calloc(size_t size, size_t n)
void *Mem::realloc(void *p, size_t size)
{
if (!size)
- { if (p)
- { GC_free(p);
- p = NULL;
- }
+ { if (p)
+ { GC_free(p);
+ p = NULL;
+ }
}
else if (!p)
{
- p = GC_malloc(size);
- if (!p)
- error();
+ p = GC_malloc(size);
+ if (!p)
+ error();
}
else
{
- p = GC_realloc(p, size);
- if (!p)
- error();
+ p = GC_realloc(p, size);
+ if (!p)
+ error();
}
return p;
}
@@ -98,21 +98,21 @@ void *Mem::realloc(void *p, size_t size)
void Mem::free(void *p)
{
if (p)
- GC_free(p);
+ GC_free(p);
}
void *Mem::mallocdup(void *o, size_t size)
{ void *p;
if (!size)
- p = NULL;
+ p = NULL;
else
{
- p = GC_malloc(size);
- if (!p)
- error();
- else
- memcpy(p,o,size);
+ p = GC_malloc(size);
+ if (!p)
+ error();
+ else
+ memcpy(p,o,size);
}
return p;
}
@@ -130,7 +130,7 @@ void Mem::fullcollect()
void Mem::mark(void *pointer)
{
- (void) pointer; // necessary for VC /W4
+ (void) pointer; // necessary for VC /W4
}
/* =================================================== */
@@ -143,7 +143,7 @@ void * operator new(size_t m_size)
}
void *p = GC_malloc(m_size);
if (p)
- return p;
+ return p;
printf("Error: out of memory\n");
exit(EXIT_FAILURE);
return p;
diff --git a/dmd/mem.h b/dmd/mem.h
index 61930209..4d452e7b 100644
--- a/dmd/mem.h
+++ b/dmd/mem.h
@@ -4,15 +4,15 @@
#ifndef ROOT_MEM_H
#define ROOT_MEM_H
-#include // for size_t
+#include // for size_t
typedef void (*FINALIZERPROC)(void* pObj, void* pClientData);
-struct GC; // thread specific allocator
+struct GC; // thread specific allocator
struct Mem
{
- GC *gc; // pointer to our thread specific allocator
+ GC *gc; // pointer to our thread specific allocator
Mem() { gc = NULL; }
void init();
@@ -35,15 +35,15 @@ struct Mem
void free_uncollectable(void *p);
void *mallocdup(void *o, size_t size);
void error();
- void check(void *p); // validate pointer
- void fullcollect(); // do full garbage collection
- void fullcollectNoStack(); // do full garbage collection, no scan stack
+ void check(void *p); // validate pointer
+ void fullcollect(); // do full garbage collection
+ void fullcollectNoStack(); // do full garbage collection, no scan stack
void mark(void *pointer);
void addroots(char* pStart, char* pEnd);
void removeroots(char* pStart);
void setFinalizer(void* pObj, FINALIZERPROC pFn, void* pClientData);
void setStackBottom(void *bottom);
- GC *getThreadGC(); // get apartment allocator for this thread
+ GC *getThreadGC(); // get apartment allocator for this thread
};
extern Mem mem;
diff --git a/dmd/module.c b/dmd/module.c
index 1b2308cb..ec1d65d6 100644
--- a/dmd/module.c
+++ b/dmd/module.c
@@ -63,7 +63,7 @@ Module *Module::rootModule;
DsymbolTable *Module::modules;
Array Module::amodules;
-Array Module::deferred; // deferred Dsymbol's needing semantic() run on them
+Array Module::deferred; // deferred Dsymbol's needing semantic() run on them
unsigned Module::dprogress;
void Module::init()
@@ -72,7 +72,7 @@ void Module::init()
}
Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen)
- : Package(ident)
+ : Package(ident)
{
FileName *srcfilename;
@@ -134,14 +134,14 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
!srcfilename->equalsExt(global.hdr_ext) &&
!srcfilename->equalsExt("dd"))
{
- if (srcfilename->equalsExt("html") ||
- srcfilename->equalsExt("htm") ||
- srcfilename->equalsExt("xhtml"))
- isHtml = 1;
- else
- { error("source file name '%s' must have .%s extension", srcfilename->toChars(), global.mars_ext);
- fatal();
- }
+ if (srcfilename->equalsExt("html") ||
+ srcfilename->equalsExt("htm") ||
+ srcfilename->equalsExt("xhtml"))
+ isHtml = 1;
+ else
+ { error("source file name '%s' must have .%s extension", srcfilename->toChars(), global.mars_ext);
+ fatal();
+ }
}
srcfile = new File(srcfilename);
@@ -155,49 +155,49 @@ File* Module::buildFilePath(const char* forcename, const char* path, const char*
{
const char *argobj;
if (forcename)
- argobj = forcename;
+ argobj = forcename;
else
{
- if (preservePaths)
- argobj = (char*)this->arg;
- else
- argobj = FileName::name((char*)this->arg);
+ if (preservePaths)
+ argobj = (char*)this->arg;
+ else
+ argobj = FileName::name((char*)this->arg);
- if (fqnNames)
- {
- if(md)
- argobj = FileName::replaceName((char*)argobj, md->toChars());
- else
- argobj = FileName::replaceName((char*)argobj, toChars());
+ if (fqnNames)
+ {
+ if(md)
+ argobj = FileName::replaceName((char*)argobj, md->toChars());
+ else
+ argobj = FileName::replaceName((char*)argobj, toChars());
- // add ext, otherwise forceExt will make nested.module into nested.bc
- size_t len = strlen(argobj);
- size_t extlen = strlen(ext);
- char* s = (char *)alloca(len + 1 + extlen + 1);
- memcpy(s, argobj, len);
- s[len] = '.';
- memcpy(s + len + 1, ext, extlen + 1);
- s[len+1+extlen] = 0;
- argobj = s;
- }
+ // add ext, otherwise forceExt will make nested.module into nested.bc
+ size_t len = strlen(argobj);
+ size_t extlen = strlen(ext);
+ char* s = (char *)alloca(len + 1 + extlen + 1);
+ memcpy(s, argobj, len);
+ s[len] = '.';
+ memcpy(s + len + 1, ext, extlen + 1);
+ s[len+1+extlen] = 0;
+ argobj = s;
+ }
}
if (!FileName::absolute(argobj))
{
- argobj = FileName::combine(path, argobj);
+ argobj = FileName::combine(path, argobj);
}
FileName::ensurePathExists(FileName::path(argobj));
// always append the extension! otherwise hard to make output switches consistent
// if (forcename)
-// return new File(argobj);
+// return new File(argobj);
// else
// allow for .o and .obj on windows
#if _WIN32
- if (ext == global.params.objdir && FileName::ext(argobj)
- && stricmp(FileName::ext(argobj), global.obj_ext_alt) == 0)
- return new File((char*)argobj);
+ if (ext == global.params.objdir && FileName::ext(argobj)
+ && stricmp(FileName::ext(argobj), global.obj_ext_alt) == 0)
+ return new File((char*)argobj);
#endif
return new File(FileName::forceExt(argobj, ext));
}
@@ -221,42 +221,42 @@ static void check_and_add_output_file(Module* NewMod, const std::string& str)
void Module::buildTargetFiles(bool singleObj)
{
- if(objfile &&
- (!doDocComment || docfile) &&
+ if(objfile &&
+ (!doDocComment || docfile) &&
(!doHdrGen || hdrfile))
- return;
+ return;
if(!objfile)
{
- if (global.params.output_bc)
- objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext);
- else if (global.params.output_ll)
- objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.ll_ext);
- else if (global.params.output_s)
- objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.s_ext);
- else
- objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.obj_ext);
+ if (global.params.output_bc)
+ objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext);
+ else if (global.params.output_ll)
+ objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.ll_ext);
+ else if (global.params.output_s)
+ objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.s_ext);
+ else
+ objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.obj_ext);
}
if(doDocComment && !docfile)
- docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext);
+ docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext);
if(doHdrGen && !hdrfile)
- hdrfile = Module::buildFilePath(global.params.hdrname, global.params.hdrdir, global.hdr_ext);
+ hdrfile = Module::buildFilePath(global.params.hdrname, global.params.hdrdir, global.hdr_ext);
// safety check: never allow obj, doc or hdr file to have the source file's name
if(stricmp(FileName::name(objfile->name->str), FileName::name((char*)this->arg)) == 0)
{
- error("Output object files with the same name as the source file are forbidden");
- fatal();
+ error("Output object files with the same name as the source file are forbidden");
+ fatal();
}
if(docfile && stricmp(FileName::name(docfile->name->str), FileName::name((char*)this->arg)) == 0)
{
- error("Output doc files with the same name as the source file are forbidden");
- fatal();
+ error("Output doc files with the same name as the source file are forbidden");
+ fatal();
}
if(hdrfile && stricmp(FileName::name(hdrfile->name->str), FileName::name((char*)this->arg)) == 0)
{
- error("Output header files with the same name as the source file are forbidden");
- fatal();
+ error("Output header files with the same name as the source file are forbidden");
+ fatal();
}
// LDC
@@ -272,11 +272,11 @@ void Module::buildTargetFiles(bool singleObj)
void Module::deleteObjFile()
{
if (global.params.obj)
- objfile->remove();
+ objfile->remove();
//if (global.params.llvmBC)
//bcfile->remove();
if (doDocComment && docfile)
- docfile->remove();
+ docfile->remove();
}
Module::~Module()
@@ -295,28 +295,28 @@ Module *Module::load(Loc loc, Array *packages, Identifier *ident)
//printf("Module::load(ident = '%s')\n", ident->toChars());
// Build module filename by turning:
- // foo.bar.baz
+ // foo.bar.baz
// into:
- // foo\bar\baz
+ // foo\bar\baz
filename = ident->toChars();
if (packages && packages->dim)
{
- OutBuffer buf;
- int i;
+ OutBuffer buf;
+ int i;
- for (i = 0; i < packages->dim; i++)
- { Identifier *pid = (Identifier *)packages->data[i];
+ for (i = 0; i < packages->dim; i++)
+ { Identifier *pid = (Identifier *)packages->data[i];
- buf.writestring(pid->toChars());
+ buf.writestring(pid->toChars());
#if _WIN32
- buf.writeByte('\\');
+ buf.writeByte('\\');
#else
- buf.writeByte('/');
+ buf.writeByte('/');
#endif
- }
- buf.writestring(filename);
- buf.writeByte(0);
- filename = (char *)buf.extractData();
+ }
+ buf.writestring(filename);
+ buf.writeByte(0);
+ filename = (char *)buf.extractData();
}
m = new Module(filename, ident, 0, 0);
@@ -331,46 +331,46 @@ Module *Module::load(Loc loc, Array *packages, Identifier *ident)
char *sd = fd->toChars();
if (FileName::exists(sdi))
- result = sdi;
+ result = sdi;
else if (FileName::exists(sd))
- result = sd;
+ result = sd;
else if (FileName::absolute(filename))
- ;
+ ;
else if (!global.path)
- ;
+ ;
else
{
- for (size_t i = 0; i < global.path->dim; i++)
- {
- char *p = (char *)global.path->data[i];
- char *n = FileName::combine(p, sdi);
- if (FileName::exists(n))
- { result = n;
- break;
- }
- mem.free(n);
- n = FileName::combine(p, sd);
- if (FileName::exists(n))
- { result = n;
- break;
- }
- mem.free(n);
- }
+ for (size_t i = 0; i < global.path->dim; i++)
+ {
+ char *p = (char *)global.path->data[i];
+ char *n = FileName::combine(p, sdi);
+ if (FileName::exists(n))
+ { result = n;
+ break;
+ }
+ mem.free(n);
+ n = FileName::combine(p, sd);
+ if (FileName::exists(n))
+ { result = n;
+ break;
+ }
+ mem.free(n);
+ }
}
if (result)
- m->srcfile = new File(result);
+ m->srcfile = new File(result);
if (global.params.verbose)
{
- printf("import ");
- if (packages)
- {
- for (size_t i = 0; i < packages->dim; i++)
- { Identifier *pid = (Identifier *)packages->data[i];
- printf("%s.", pid->toChars());
- }
- }
- printf("%s\t(%s)\n", ident->toChars(), m->srcfile->toChars());
+ printf("import ");
+ if (packages)
+ {
+ for (size_t i = 0; i < packages->dim; i++)
+ { Identifier *pid = (Identifier *)packages->data[i];
+ printf("%s.", pid->toChars());
+ }
+ }
+ printf("%s\t(%s)\n", ident->toChars(), m->srcfile->toChars());
}
m->read(loc);
@@ -387,17 +387,17 @@ void Module::read(Loc loc)
{
//printf("Module::read('%s') file '%s'\n", toChars(), srcfile->toChars());
if (srcfile->read())
- { error(loc, "cannot read file '%s'", srcfile->toChars());
+ { error(loc, "cannot read file '%s'", srcfile->toChars());
if (!global.gag)
- { /* Print path
- */
- for (size_t i = 0; i < global.path->dim; i++)
- {
- char *p = (char *)global.path->data[i];
- fprintf(stdmsg, "import path[%d] = %s\n", i, p);
- }
- }
- fatal();
+ { /* Print path
+ */
+ for (size_t i = 0; i < global.path->dim; i++)
+ {
+ char *p = (char *)global.path->data[i];
+ fprintf(stdmsg, "import path[%d] = %s\n", i, p);
+ }
+ }
+ fatal();
}
}
@@ -421,18 +421,18 @@ inline unsigned readlongLE(unsigned *p)
return *p;
#else
return ((unsigned char *)p)[0] |
- (((unsigned char *)p)[1] << 8) |
- (((unsigned char *)p)[2] << 16) |
- (((unsigned char *)p)[3] << 24);
+ (((unsigned char *)p)[1] << 8) |
+ (((unsigned char *)p)[2] << 16) |
+ (((unsigned char *)p)[3] << 24);
#endif
}
inline unsigned readlongBE(unsigned *p)
{
return ((unsigned char *)p)[3] |
- (((unsigned char *)p)[2] << 8) |
- (((unsigned char *)p)[1] << 16) |
- (((unsigned char *)p)[0] << 24);
+ (((unsigned char *)p)[2] << 8) |
+ (((unsigned char *)p)[1] << 16) |
+ (((unsigned char *)p)[0] << 24);
}
#if IN_GCC
@@ -456,169 +456,169 @@ void Module::parse()
if (buflen >= 2)
{
- /* Convert all non-UTF-8 formats to UTF-8.
- * BOM : http://www.unicode.org/faq/utf_bom.html
- * 00 00 FE FF UTF-32BE, big-endian
- * FF FE 00 00 UTF-32LE, little-endian
- * FE FF UTF-16BE, big-endian
- * FF FE UTF-16LE, little-endian
- * EF BB BF UTF-8
- */
+ /* Convert all non-UTF-8 formats to UTF-8.
+ * BOM : http://www.unicode.org/faq/utf_bom.html
+ * 00 00 FE FF UTF-32BE, big-endian
+ * FF FE 00 00 UTF-32LE, little-endian
+ * FE FF UTF-16BE, big-endian
+ * FF FE UTF-16LE, little-endian
+ * EF BB BF UTF-8
+ */
- bom = 1; // assume there's a BOM
- if (buf[0] == 0xFF && buf[1] == 0xFE)
- {
- if (buflen >= 4 && buf[2] == 0 && buf[3] == 0)
- { // UTF-32LE
- le = 1;
+ bom = 1; // assume there's a BOM
+ if (buf[0] == 0xFF && buf[1] == 0xFE)
+ {
+ if (buflen >= 4 && buf[2] == 0 && buf[3] == 0)
+ { // UTF-32LE
+ le = 1;
- Lutf32:
- OutBuffer dbuf;
- unsigned *pu = (unsigned *)(buf);
- unsigned *pumax = &pu[buflen / 4];
+ Lutf32:
+ OutBuffer dbuf;
+ unsigned *pu = (unsigned *)(buf);
+ unsigned *pumax = &pu[buflen / 4];
- if (buflen & 3)
- { error("odd length of UTF-32 char source %u", buflen);
- fatal();
- }
+ if (buflen & 3)
+ { error("odd length of UTF-32 char source %u", buflen);
+ fatal();
+ }
- dbuf.reserve(buflen / 4);
- for (pu += bom; pu < pumax; pu++)
- { unsigned u;
+ dbuf.reserve(buflen / 4);
+ for (pu += bom; pu < pumax; pu++)
+ { unsigned u;
- u = le ? readlongLE(pu) : readlongBE(pu);
- if (u & ~0x7F)
- {
- if (u > 0x10FFFF)
- { error("UTF-32 value %08x greater than 0x10FFFF", u);
- fatal();
- }
- dbuf.writeUTF8(u);
- }
- else
- dbuf.writeByte(u);
- }
- dbuf.writeByte(0); // add 0 as sentinel for scanner
- buflen = dbuf.offset - 1; // don't include sentinel in count
- buf = (unsigned char *) dbuf.extractData();
- }
- else
- { // UTF-16LE (X86)
- // Convert it to UTF-8
- le = 1;
+ u = le ? readlongLE(pu) : readlongBE(pu);
+ if (u & ~0x7F)
+ {
+ if (u > 0x10FFFF)
+ { error("UTF-32 value %08x greater than 0x10FFFF", u);
+ fatal();
+ }
+ dbuf.writeUTF8(u);
+ }
+ else
+ dbuf.writeByte(u);
+ }
+ dbuf.writeByte(0); // add 0 as sentinel for scanner
+ buflen = dbuf.offset - 1; // don't include sentinel in count
+ buf = (unsigned char *) dbuf.extractData();
+ }
+ else
+ { // UTF-16LE (X86)
+ // Convert it to UTF-8
+ le = 1;
- Lutf16:
- OutBuffer dbuf;
- unsigned short *pu = (unsigned short *)(buf);
- unsigned short *pumax = &pu[buflen / 2];
+ Lutf16:
+ OutBuffer dbuf;
+ unsigned short *pu = (unsigned short *)(buf);
+ unsigned short *pumax = &pu[buflen / 2];
- if (buflen & 1)
- { error("odd length of UTF-16 char source %u", buflen);
- fatal();
- }
+ if (buflen & 1)
+ { error("odd length of UTF-16 char source %u", buflen);
+ fatal();
+ }
- dbuf.reserve(buflen / 2);
- for (pu += bom; pu < pumax; pu++)
- { unsigned u;
+ dbuf.reserve(buflen / 2);
+ for (pu += bom; pu < pumax; pu++)
+ { unsigned u;
- u = le ? readwordLE(pu) : readwordBE(pu);
- if (u & ~0x7F)
- { if (u >= 0xD800 && u <= 0xDBFF)
- { unsigned u2;
+ u = le ? readwordLE(pu) : readwordBE(pu);
+ if (u & ~0x7F)
+ { if (u >= 0xD800 && u <= 0xDBFF)
+ { unsigned u2;
- if (++pu > pumax)
- { error("surrogate UTF-16 high value %04x at EOF", u);
- fatal();
- }
- u2 = le ? readwordLE(pu) : readwordBE(pu);
- if (u2 < 0xDC00 || u2 > 0xDFFF)
- { error("surrogate UTF-16 low value %04x out of range", u2);
- fatal();
- }
- u = (u - 0xD7C0) << 10;
- u |= (u2 - 0xDC00);
- }
- else if (u >= 0xDC00 && u <= 0xDFFF)
- { error("unpaired surrogate UTF-16 value %04x", u);
- fatal();
- }
- else if (u == 0xFFFE || u == 0xFFFF)
- { error("illegal UTF-16 value %04x", u);
- fatal();
- }
- dbuf.writeUTF8(u);
- }
- else
- dbuf.writeByte(u);
- }
- dbuf.writeByte(0); // add 0 as sentinel for scanner
- buflen = dbuf.offset - 1; // don't include sentinel in count
- buf = (unsigned char *) dbuf.extractData();
- }
- }
- else if (buf[0] == 0xFE && buf[1] == 0xFF)
- { // UTF-16BE
- le = 0;
- goto Lutf16;
- }
- else if (buflen >= 4 && buf[0] == 0 && buf[1] == 0 && buf[2] == 0xFE && buf[3] == 0xFF)
- { // UTF-32BE
- le = 0;
- goto Lutf32;
- }
- else if (buflen >= 3 && buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF)
- { // UTF-8
+ if (++pu > pumax)
+ { error("surrogate UTF-16 high value %04x at EOF", u);
+ fatal();
+ }
+ u2 = le ? readwordLE(pu) : readwordBE(pu);
+ if (u2 < 0xDC00 || u2 > 0xDFFF)
+ { error("surrogate UTF-16 low value %04x out of range", u2);
+ fatal();
+ }
+ u = (u - 0xD7C0) << 10;
+ u |= (u2 - 0xDC00);
+ }
+ else if (u >= 0xDC00 && u <= 0xDFFF)
+ { error("unpaired surrogate UTF-16 value %04x", u);
+ fatal();
+ }
+ else if (u == 0xFFFE || u == 0xFFFF)
+ { error("illegal UTF-16 value %04x", u);
+ fatal();
+ }
+ dbuf.writeUTF8(u);
+ }
+ else
+ dbuf.writeByte(u);
+ }
+ dbuf.writeByte(0); // add 0 as sentinel for scanner
+ buflen = dbuf.offset - 1; // don't include sentinel in count
+ buf = (unsigned char *) dbuf.extractData();
+ }
+ }
+ else if (buf[0] == 0xFE && buf[1] == 0xFF)
+ { // UTF-16BE
+ le = 0;
+ goto Lutf16;
+ }
+ else if (buflen >= 4 && buf[0] == 0 && buf[1] == 0 && buf[2] == 0xFE && buf[3] == 0xFF)
+ { // UTF-32BE
+ le = 0;
+ goto Lutf32;
+ }
+ else if (buflen >= 3 && buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF)
+ { // UTF-8
- buf += 3;
- buflen -= 3;
- }
- else
- {
- /* There is no BOM. Make use of Arcane Jill's insight that
- * the first char of D source must be ASCII to
- * figure out the encoding.
- */
+ buf += 3;
+ buflen -= 3;
+ }
+ else
+ {
+ /* There is no BOM. Make use of Arcane Jill's insight that
+ * the first char of D source must be ASCII to
+ * figure out the encoding.
+ */
- bom = 0;
- if (buflen >= 4)
- { if (buf[1] == 0 && buf[2] == 0 && buf[3] == 0)
- { // UTF-32LE
- le = 1;
- goto Lutf32;
- }
- else if (buf[0] == 0 && buf[1] == 0 && buf[2] == 0)
- { // UTF-32BE
- le = 0;
- goto Lutf32;
- }
- }
- if (buflen >= 2)
- {
- if (buf[1] == 0)
- { // UTF-16LE
- le = 1;
- goto Lutf16;
- }
- else if (buf[0] == 0)
- { // UTF-16BE
- le = 0;
- goto Lutf16;
- }
- }
+ bom = 0;
+ if (buflen >= 4)
+ { if (buf[1] == 0 && buf[2] == 0 && buf[3] == 0)
+ { // UTF-32LE
+ le = 1;
+ goto Lutf32;
+ }
+ else if (buf[0] == 0 && buf[1] == 0 && buf[2] == 0)
+ { // UTF-32BE
+ le = 0;
+ goto Lutf32;
+ }
+ }
+ if (buflen >= 2)
+ {
+ if (buf[1] == 0)
+ { // UTF-16LE
+ le = 1;
+ goto Lutf16;
+ }
+ else if (buf[0] == 0)
+ { // UTF-16BE
+ le = 0;
+ goto Lutf16;
+ }
+ }
- // It's UTF-8
- if (buf[0] >= 0x80)
- { error("source file must start with BOM or ASCII character, not \\x%02X", buf[0]);
- fatal();
- }
- }
+ // It's UTF-8
+ if (buf[0] >= 0x80)
+ { error("source file must start with BOM or ASCII character, not \\x%02X", buf[0]);
+ fatal();
+ }
+ }
}
#ifdef IN_GCC
- // dump utf-8 encoded source
+ // dump utf-8 encoded source
if (dump_source)
- { // %% srcname could contain a path ...
- d_gcc_dump_source(srcname, "utf-8", buf, buflen);
+ { // %% srcname could contain a path ...
+ d_gcc_dump_source(srcname, "utf-8", buf, buflen);
}
#endif
@@ -627,21 +627,21 @@ void Module::parse()
*/
if (buflen >= 4 && memcmp(buf, "Ddoc", 4) == 0)
{
- comment = buf + 4;
- isDocFile = 1;
- return;
+ comment = buf + 4;
+ isDocFile = 1;
+ return;
}
if (isHtml)
{
- OutBuffer *dbuf = new OutBuffer();
- Html h(srcname, buf, buflen);
- h.extractCode(dbuf);
- buf = dbuf->data;
- buflen = dbuf->offset;
+ OutBuffer *dbuf = new OutBuffer();
+ Html h(srcname, buf, buflen);
+ h.extractCode(dbuf);
+ buf = dbuf->data;
+ buflen = dbuf->offset;
#ifdef IN_GCC
- // dump extracted source
- if (dump_source)
- d_gcc_dump_source(srcname, "d.utf-8", buf, buflen);
+ // dump extracted source
+ if (dump_source)
+ d_gcc_dump_source(srcname, "d.utf-8", buf, buflen);
#endif
}
Parser p(this, buf, buflen, docfile != NULL);
@@ -653,17 +653,17 @@ void Module::parse()
DsymbolTable *dst;
if (md)
- { this->ident = md->id;
- dst = Package::resolve(md->packages, &this->parent, NULL);
+ { this->ident = md->id;
+ dst = Package::resolve(md->packages, &this->parent, NULL);
}
else
{
- dst = modules;
+ dst = modules;
- /* Check to see if module name is a valid identifier
- */
- if (!Lexer::isValidIdentifier(this->ident->toChars()))
- error("has non-identifier characters in filename, use module declaration instead");
+ /* Check to see if module name is a valid identifier
+ */
+ if (!Lexer::isValidIdentifier(this->ident->toChars()))
+ error("has non-identifier characters in filename, use module declaration instead");
}
// Update global list of modules
@@ -678,7 +678,7 @@ void Module::parse()
}
else
{
- amodules.push(this);
+ amodules.push(this);
}
}
@@ -687,34 +687,34 @@ void Module::importAll(Scope *prevsc)
//printf("+Module::importAll(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
if (scope)
- return; // already done
+ return; // already done
/* Note that modules get their own scope, from scratch.
* This is so regardless of where in the syntax a module
* gets imported, it is unaffected by context.
* Ignore prevsc.
*/
- Scope *sc = Scope::createGlobal(this); // create root scope
+ Scope *sc = Scope::createGlobal(this); // create root scope
// Add import of "object" if this module isn't "object"
if (ident != Id::object)
{
- if (members->dim == 0 || ((Dsymbol *)members->data[0])->ident != Id::object)
- {
- Import *im = new Import(0, NULL, Id::object, NULL, 0);
- members->shift(im);
- }
+ if (members->dim == 0 || ((Dsymbol *)members->data[0])->ident != Id::object)
+ {
+ Import *im = new Import(0, NULL, Id::object, NULL, 0);
+ members->shift(im);
+ }
}
if (!symtab)
{
- // Add all symbols into module's symbol table
- symtab = new DsymbolTable();
- for (int i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->addMember(NULL, sc->scopesym, 1);
- }
+ // Add all symbols into module's symbol table
+ symtab = new DsymbolTable();
+ for (int i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->addMember(NULL, sc->scopesym, 1);
+ }
}
// anything else should be run after addMember, so version/debug symbols are defined
@@ -723,26 +723,26 @@ void Module::importAll(Scope *prevsc)
* If this works out well, it can be extended to all modules
* before any semantic() on any of them.
*/
- setScope(sc); // remember module scope for semantic
+ setScope(sc); // remember module scope for semantic
for (int i = 0; i < members->dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- s->setScope(sc);
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ s->setScope(sc);
}
for (int i = 0; i < members->dim; i++)
{
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->importAll(sc);
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->importAll(sc);
}
sc = sc->pop();
- sc->pop(); // 2 pops because Scope::createGlobal() created 2
+ sc->pop(); // 2 pops because Scope::createGlobal() created 2
}
void Module::semantic(Scope *unused_sc)
{
if (semanticstarted)
- return;
+ return;
//printf("+Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
semanticstarted = 1;
@@ -750,10 +750,10 @@ void Module::semantic(Scope *unused_sc)
// Note that modules get their own scope, from scratch.
// This is so regardless of where in the syntax a module
// gets imported, it is unaffected by context.
- Scope *sc = scope; // see if already got one from importAll()
+ Scope *sc = scope; // see if already got one from importAll()
if (!sc)
- { printf("test2\n");
- Scope::createGlobal(this); // create root scope
+ { printf("test2\n");
+ Scope::createGlobal(this); // create root scope
}
//printf("Module = %p, linkage = %d\n", sc->scopesym, sc->linkage);
@@ -762,15 +762,15 @@ void Module::semantic(Scope *unused_sc)
// Add import of "object" if this module isn't "object"
if (ident != Id::object)
{
- Import *im = new Import(0, NULL, Id::object, NULL, 0);
- members->shift(im);
+ Import *im = new Import(0, NULL, Id::object, NULL, 0);
+ members->shift(im);
}
// Add all symbols into module's symbol table
symtab = new DsymbolTable();
for (int i = 0; i < members->dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- s->addMember(NULL, sc->scopesym, 1);
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ s->addMember(NULL, sc->scopesym, 1);
}
/* Set scope for the symbols so that if we forward reference
@@ -779,23 +779,23 @@ void Module::semantic(Scope *unused_sc)
* before any semantic() on any of them.
*/
for (int i = 0; i < members->dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- s->setScope(sc);
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ s->setScope(sc);
}
#endif
// Pass 1 semantic routines: do public side of the definition
for (int i = 0; i < members->dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
+ { Dsymbol *s = (Dsymbol *)members->data[i];
- //printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars());
- s->semantic(sc);
- runDeferredSemantic();
+ //printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars());
+ s->semantic(sc);
+ runDeferredSemantic();
}
if (!scope)
- { sc = sc->pop();
- sc->pop(); // 2 pops because Scope::createGlobal() created 2
+ { sc = sc->pop();
+ sc->pop(); // 2 pops because Scope::createGlobal() created 2
}
semanticRun = semanticstarted;
//printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
@@ -806,32 +806,32 @@ void Module::semantic2(Scope* unused_sc)
if (deferred.dim)
{
- for (int i = 0; i < deferred.dim; i++)
- {
- Dsymbol *sd = (Dsymbol *)deferred.data[i];
+ for (int i = 0; i < deferred.dim; i++)
+ {
+ Dsymbol *sd = (Dsymbol *)deferred.data[i];
- sd->error("unable to resolve forward reference in definition");
- }
- return;
+ sd->error("unable to resolve forward reference in definition");
+ }
+ return;
}
//printf("Module::semantic2('%s'): parent = %p\n", toChars(), parent);
if (semanticstarted >= 2)
- return;
+ return;
assert(semanticstarted == 1);
semanticstarted = 2;
// Note that modules get their own scope, from scratch.
// This is so regardless of where in the syntax a module
// gets imported, it is unaffected by context.
- Scope *sc = Scope::createGlobal(this); // create root scope
+ Scope *sc = Scope::createGlobal(this); // create root scope
//printf("Module = %p\n", sc.scopesym);
// Pass 2 semantic routines: do initializers and function bodies
for (i = 0; i < members->dim; i++)
- { Dsymbol *s;
+ { Dsymbol *s;
- s = (Dsymbol *)members->data[i];
- s->semantic2(sc);
+ s = (Dsymbol *)members->data[i];
+ s->semantic2(sc);
}
sc = sc->pop();
@@ -845,23 +845,23 @@ void Module::semantic3(Scope* unused_sc)
//printf("Module::semantic3('%s'): parent = %p\n", toChars(), parent);
if (semanticstarted >= 3)
- return;
+ return;
assert(semanticstarted == 2);
semanticstarted = 3;
// Note that modules get their own scope, from scratch.
// This is so regardless of where in the syntax a module
// gets imported, it is unaffected by context.
- Scope *sc = Scope::createGlobal(this); // create root scope
+ Scope *sc = Scope::createGlobal(this); // create root scope
//printf("Module = %p\n", sc.scopesym);
// Pass 3 semantic routines: do initializers and function bodies
for (i = 0; i < members->dim; i++)
- { Dsymbol *s;
+ { Dsymbol *s;
- s = (Dsymbol *)members->data[i];
- //printf("Module %s: %s.semantic3()\n", toChars(), s->toChars());
- s->semantic3(sc);
+ s = (Dsymbol *)members->data[i];
+ //printf("Module %s: %s.semantic3()\n", toChars(), s->toChars());
+ s->semantic3(sc);
}
sc = sc->pop();
@@ -872,7 +872,7 @@ void Module::semantic3(Scope* unused_sc)
void Module::inlineScan()
{
if (semanticstarted >= 4)
- return;
+ return;
assert(semanticstarted == 3);
semanticstarted = 4;
@@ -882,11 +882,11 @@ void Module::inlineScan()
//printf("Module = %p\n", sc.scopesym);
for (int i = 0; i < members->dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- //if (global.params.verbose)
- //printf("inline scan symbol %s\n", s->toChars());
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ //if (global.params.verbose)
+ //printf("inline scan symbol %s\n", s->toChars());
- s->inlineScan();
+ s->inlineScan();
}
semanticRun = semanticstarted;
}
@@ -907,9 +907,9 @@ void Module::gensymfile()
buf.writenl();
for (int i = 0; i < members->dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
+ { Dsymbol *s = (Dsymbol *)members->data[i];
- s->toCBuffer(&buf, &hgs);
+ s->toCBuffer(&buf, &hgs);
}
// Transfer image to file
@@ -940,36 +940,36 @@ Dsymbol *Module::search(Loc loc, Identifier *ident, int flags)
//printf("%s Module::search('%s', flags = %d) insearch = %d\n", toChars(), ident->toChars(), flags, insearch);
Dsymbol *s;
if (insearch)
- s = NULL;
+ s = NULL;
else if (searchCacheIdent == ident && searchCacheFlags == flags)
{
- s = searchCacheSymbol;
- //printf("%s Module::search('%s', flags = %d) insearch = %d searchCacheSymbol = %s\n", toChars(), ident->toChars(), flags, insearch, searchCacheSymbol ? searchCacheSymbol->toChars() : "null");
+ s = searchCacheSymbol;
+ //printf("%s Module::search('%s', flags = %d) insearch = %d searchCacheSymbol = %s\n", toChars(), ident->toChars(), flags, insearch, searchCacheSymbol ? searchCacheSymbol->toChars() : "null");
}
else
{
- insearch = 1;
- s = ScopeDsymbol::search(loc, ident, flags);
- insearch = 0;
+ insearch = 1;
+ s = ScopeDsymbol::search(loc, ident, flags);
+ insearch = 0;
- searchCacheIdent = ident;
- searchCacheSymbol = s;
- searchCacheFlags = flags;
+ searchCacheIdent = ident;
+ searchCacheSymbol = s;
+ searchCacheFlags = flags;
}
return s;
}
Dsymbol *Module::symtabInsert(Dsymbol *s)
{
- searchCacheIdent = 0; // symbol is inserted, so invalidate cache
+ searchCacheIdent = 0; // symbol is inserted, so invalidate cache
return Package::symtabInsert(s);
}
void Module::clearCache()
{
for (int i = 0; i < amodules.dim; i++)
- { Module *m = (Module *)amodules.data[i];
- m->searchCacheIdent = NULL;
+ { Module *m = (Module *)amodules.data[i];
+ m->searchCacheIdent = NULL;
}
}
@@ -982,10 +982,10 @@ void Module::addDeferredSemantic(Dsymbol *s)
// Don't add it if it is already there
for (int i = 0; i < deferred.dim; i++)
{
- Dsymbol *sd = (Dsymbol *)deferred.data[i];
+ Dsymbol *sd = (Dsymbol *)deferred.data[i];
- if (sd == s)
- return;
+ if (sd == s)
+ return;
}
//printf("Module::addDeferredSemantic('%s')\n", s->toChars());
@@ -1000,45 +1000,45 @@ void Module::addDeferredSemantic(Dsymbol *s)
void Module::runDeferredSemantic()
{
if (dprogress == 0)
- return;
+ return;
static int nested;
if (nested)
- return;
+ return;
//if (deferred.dim) printf("+Module::runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim);
nested++;
size_t len;
do
{
- dprogress = 0;
- len = deferred.dim;
- if (!len)
- break;
+ dprogress = 0;
+ len = deferred.dim;
+ if (!len)
+ break;
- Dsymbol **todo;
- Dsymbol *tmp;
- if (len == 1)
- {
- todo = &tmp;
- }
- else
- {
- todo = (Dsymbol **)alloca(len * sizeof(Dsymbol *));
- assert(todo);
- }
- memcpy(todo, deferred.data, len * sizeof(Dsymbol *));
- deferred.setDim(0);
+ Dsymbol **todo;
+ Dsymbol *tmp;
+ if (len == 1)
+ {
+ todo = &tmp;
+ }
+ else
+ {
+ todo = (Dsymbol **)alloca(len * sizeof(Dsymbol *));
+ assert(todo);
+ }
+ memcpy(todo, deferred.data, len * sizeof(Dsymbol *));
+ deferred.setDim(0);
- for (int i = 0; i < len; i++)
- {
- Dsymbol *s = todo[i];
+ for (int i = 0; i < len; i++)
+ {
+ Dsymbol *s = todo[i];
- s->semantic(NULL);
- //printf("deferred: %s, parent = %s\n", s->toChars(), s->parent->toChars());
- }
- //printf("\tdeferred.dim = %d, len = %d, dprogress = %d\n", deferred.dim, len, dprogress);
- } while (deferred.dim < len || dprogress); // while making progress
+ s->semantic(NULL);
+ //printf("deferred: %s, parent = %s\n", s->toChars(), s->parent->toChars());
+ }
+ //printf("\tdeferred.dim = %d, len = %d, dprogress = %d\n", deferred.dim, len, dprogress);
+ } while (deferred.dim < len || dprogress); // while making progress
nested--;
//printf("-Module::runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim);
}
@@ -1055,21 +1055,21 @@ int Module::imports(Module *m)
int aimports_dim = aimports.dim;
#if 0
for (int i = 0; i < aimports.dim; i++)
- { Module *mi = (Module *)aimports.data[i];
- printf("\t[%d] %s\n", i, mi->toChars());
+ { Module *mi = (Module *)aimports.data[i];
+ printf("\t[%d] %s\n", i, mi->toChars());
}
#endif
for (int i = 0; i < aimports.dim; i++)
- { Module *mi = (Module *)aimports.data[i];
- if (mi == m)
- return TRUE;
- if (!mi->insearch)
- {
- mi->insearch = 1;
- int r = mi->imports(m);
- if (r)
- return r;
- }
+ { Module *mi = (Module *)aimports.data[i];
+ if (mi == m)
+ return TRUE;
+ if (!mi->insearch)
+ {
+ mi->insearch = 1;
+ int r = mi->imports(m);
+ if (r)
+ return r;
+ }
}
return FALSE;
}
@@ -1083,19 +1083,19 @@ int Module::selfImports()
//printf("Module::selfImports() %s\n", toChars());
if (!selfimports)
{
- for (int i = 0; i < amodules.dim; i++)
- { Module *mi = (Module *)amodules.data[i];
- //printf("\t[%d] %s\n", i, mi->toChars());
- mi->insearch = 0;
- }
+ for (int i = 0; i < amodules.dim; i++)
+ { Module *mi = (Module *)amodules.data[i];
+ //printf("\t[%d] %s\n", i, mi->toChars());
+ mi->insearch = 0;
+ }
- selfimports = imports(this) + 1;
+ selfimports = imports(this) + 1;
- for (int i = 0; i < amodules.dim; i++)
- { Module *mi = (Module *)amodules.data[i];
- //printf("\t[%d] %s\n", i, mi->toChars());
- mi->insearch = 0;
- }
+ for (int i = 0; i < amodules.dim; i++)
+ { Module *mi = (Module *)amodules.data[i];
+ //printf("\t[%d] %s\n", i, mi->toChars());
+ mi->insearch = 0;
+ }
}
return selfimports - 1;
}
@@ -1116,12 +1116,12 @@ char *ModuleDeclaration::toChars()
if (packages && packages->dim)
{
- for (i = 0; i < packages->dim; i++)
- { Identifier *pid = (Identifier *)packages->data[i];
+ for (i = 0; i < packages->dim; i++)
+ { Identifier *pid = (Identifier *)packages->data[i];
- buf.writestring(pid->toChars());
- buf.writeByte('.');
- }
+ buf.writestring(pid->toChars());
+ buf.writeByte('.');
+ }
}
buf.writestring(id->toChars());
buf.writeByte(0);
@@ -1131,7 +1131,7 @@ char *ModuleDeclaration::toChars()
/* =========================== Package ===================== */
Package::Package(Identifier *ident)
- : ScopeDsymbol(ident)
+ : ScopeDsymbol(ident)
{
}
@@ -1149,44 +1149,44 @@ DsymbolTable *Package::resolve(Array *packages, Dsymbol **pparent, Package **ppk
//printf("Package::resolve()\n");
if (ppkg)
- *ppkg = NULL;
+ *ppkg = NULL;
if (packages)
{ int i;
- for (i = 0; i < packages->dim; i++)
- { Identifier *pid = (Identifier *)packages->data[i];
- Dsymbol *p;
+ for (i = 0; i < packages->dim; i++)
+ { Identifier *pid = (Identifier *)packages->data[i];
+ Dsymbol *p;
- p = dst->lookup(pid);
- if (!p)
- {
- p = new Package(pid);
- dst->insert(p);
- p->parent = parent;
- ((ScopeDsymbol *)p)->symtab = new DsymbolTable();
- }
- else
- {
- assert(p->isPackage());
+ p = dst->lookup(pid);
+ if (!p)
+ {
+ p = new Package(pid);
+ dst->insert(p);
+ p->parent = parent;
+ ((ScopeDsymbol *)p)->symtab = new DsymbolTable();
+ }
+ else
+ {
+ assert(p->isPackage());
#if TARGET_NET //dot net needs modules and packages with same name
#else
- if (p->isModule())
- { p->error("module and package have the same name");
- fatal();
- break;
- }
+ if (p->isModule())
+ { p->error("module and package have the same name");
+ fatal();
+ break;
+ }
#endif
- }
- parent = p;
- dst = ((Package *)p)->symtab;
- if (ppkg && !*ppkg)
- *ppkg = (Package *)p;
- }
- if (pparent)
- {
- *pparent = parent;
- }
+ }
+ parent = p;
+ dst = ((Package *)p)->symtab;
+ if (ppkg && !*ppkg)
+ *ppkg = (Package *)p;
+ }
+ if (pparent)
+ {
+ *pparent = parent;
+ }
}
return dst;
}
diff --git a/dmd/module.h b/dmd/module.h
index 22109d5b..09491317 100644
--- a/dmd/module.h
+++ b/dmd/module.h
@@ -59,70 +59,70 @@ struct Package : ScopeDsymbol
struct Module : Package
{
static Module *rootModule;
- static DsymbolTable *modules; // symbol table of all modules
- static Array amodules; // array of all modules
- static Array deferred; // deferred Dsymbol's needing semantic() run on them
- static unsigned dprogress; // progress resolving the deferred list
+ static DsymbolTable *modules; // symbol table of all modules
+ static Array amodules; // array of all modules
+ static Array deferred; // deferred Dsymbol's needing semantic() run on them
+ static unsigned dprogress; // progress resolving the deferred list
static void init();
static ClassDeclaration *moduleinfo;
- const char *arg; // original argument name
+ const char *arg; // original argument name
ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration
- File *srcfile; // input source file
+ File *srcfile; // input source file
File *objfile; // output object file
File *docfile; // output doc file
File *hdrfile; // output hdr file
-
- unsigned errors; // if any errors in file
- unsigned numlines; // number of lines in source file
- int isHtml; // if it is an HTML file
- int isDocFile; // if it is a documentation input file, not D source
+
+ unsigned errors; // if any errors in file
+ unsigned numlines; // number of lines in source file
+ int isHtml; // if it is an HTML file
+ int isDocFile; // if it is a documentation input file, not D source
int needmoduleinfo;
#ifdef IN_GCC
int strictlyneedmoduleinfo;
#endif
- int selfimports; // 0: don't know, 1: does not, 2: does
- int selfImports(); // returns !=0 if module imports itself
+ int selfimports; // 0: don't know, 1: does not, 2: does
+ int selfImports(); // returns !=0 if module imports itself
int insearch;
Identifier *searchCacheIdent;
- Dsymbol *searchCacheSymbol; // cached value of search
- int searchCacheFlags; // cached flags
+ Dsymbol *searchCacheSymbol; // cached value of search
+ int searchCacheFlags; // cached flags
- int semanticstarted; // has semantic() been started?
- int semanticRun; // has semantic() been done?
- int root; // != 0 if this is a 'root' module,
- // i.e. a module that will be taken all the
- // way to an object file
- Module *importedFrom; // module from command line we're imported from,
- // i.e. a module that will be taken all the
- // way to an object file
+ int semanticstarted; // has semantic() been started?
+ int semanticRun; // has semantic() been done?
+ int root; // != 0 if this is a 'root' module,
+ // i.e. a module that will be taken all the
+ // way to an object file
+ Module *importedFrom; // module from command line we're imported from,
+ // i.e. a module that will be taken all the
+ // way to an object file
- Array *decldefs; // top level declarations for this Module
+ Array *decldefs; // top level declarations for this Module
- Array aimports; // all imported modules
+ Array aimports; // all imported modules
ModuleInfoDeclaration *vmoduleinfo;
- unsigned debuglevel; // debug level
- Array *debugids; // debug identifiers
- Array *debugidsNot; // forward referenced debug identifiers
+ unsigned debuglevel; // debug level
+ Array *debugids; // debug identifiers
+ Array *debugidsNot; // forward referenced debug identifiers
- unsigned versionlevel; // version level
- Array *versionids; // version identifiers
- Array *versionidsNot; // forward referenced version identifiers
+ unsigned versionlevel; // version level
+ Array *versionids; // version identifiers
+ Array *versionidsNot; // forward referenced version identifiers
- Macro *macrotable; // document comment macros
- struct Escape *escapetable; // document comment escapes
+ Macro *macrotable; // document comment macros
+ struct Escape *escapetable; // document comment escapes
int doDocComment; // enable generating doc comments for this module
int doHdrGen; // enable generating header file for this module
- bool safe; // TRUE if module is marked as 'safe'
+ bool safe; // TRUE if module is marked as 'safe'
Module(char *arg, Identifier *ident, int doDocComment, int doHdrGen);
~Module();
@@ -132,17 +132,17 @@ struct Module : Package
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toJsonBuffer(OutBuffer *buf);
const char *kind();
- void read(Loc loc); // read file
+ void read(Loc loc); // read file
#if IN_GCC
- void parse(bool dump_source = false); // syntactic parse
+ void parse(bool dump_source = false); // syntactic parse
#else
- void parse(); // syntactic parse
+ void parse(); // syntactic parse
#endif
void importAll(Scope *sc);
- void semantic(Scope* unused_sc = NULL); // semantic analysis
- void semantic2(Scope* unused_sc = NULL); // pass 2 semantic analysis
- void semantic3(Scope* unused_sc = NULL); // pass 3 semantic analysis
- void inlineScan(); // scan for functions to inline
+ void semantic(Scope* unused_sc = NULL); // semantic analysis
+ void semantic2(Scope* unused_sc = NULL); // pass 2 semantic analysis
+ void semantic3(Scope* unused_sc = NULL); // pass 3 semantic analysis
+ void inlineScan(); // scan for functions to inline
#ifdef _DH
void genhdrfile(); // generate D import file
#endif
@@ -159,22 +159,22 @@ struct Module : Package
// Back end
#if IN_DMD
- int doppelganger; // sub-module
- Symbol *cov; // private uint[] __coverage;
- unsigned *covb; // bit array of valid code line numbers
+ int doppelganger; // sub-module
+ Symbol *cov; // private uint[] __coverage;
+ unsigned *covb; // bit array of valid code line numbers
- Symbol *sictor; // module order independent constructor
- Symbol *sctor; // module constructor
- Symbol *sdtor; // module destructor
- Symbol *stest; // module unit test
+ Symbol *sictor; // module order independent constructor
+ Symbol *sctor; // module constructor
+ Symbol *sdtor; // module destructor
+ Symbol *stest; // module unit test
- Symbol *sfilename; // symbol for filename
+ Symbol *sfilename; // symbol for filename
- Symbol *massert; // module assert function
- Symbol *toModuleAssert(); // get module assert function
+ Symbol *massert; // module assert function
+ Symbol *toModuleAssert(); // get module assert function
- Symbol *marray; // module array bounds function
- Symbol *toModuleArray(); // get module array bounds function
+ Symbol *marray; // module array bounds function
+ Symbol *toModuleArray(); // get module array bounds function
static Symbol *gencritsec();
@@ -203,7 +203,7 @@ struct Module : Package
struct ModuleDeclaration
{
Identifier *id;
- Array *packages; // array of Identifier's representing packages
+ Array *packages; // array of Identifier's representing packages
bool safe;
ModuleDeclaration(Array *packages, Identifier *id);
diff --git a/dmd/mtype.c b/dmd/mtype.c
index 560e74c0..2ad9ce8e 100644
--- a/dmd/mtype.c
+++ b/dmd/mtype.c
@@ -8,8 +8,8 @@
// in artistic.txt, or the GNU General Public License in gnu.txt.
// See the included readme.txt for details.
-#define __C99FEATURES__ 1 // Needed on Solaris for NaN and more
-#define __USE_ISOC99 1 // so signbit() gets defined
+#define __C99FEATURES__ 1 // Needed on Solaris for NaN and more
+#define __USE_ISOC99 1 // so signbit() gets defined
#if (defined (__SVR4) && defined (__sun))
#include
@@ -61,11 +61,11 @@ unsigned GetTypeAlignment(Ir* ir, Type* t);
FuncDeclaration *hasThis(Scope *sc);
-#define LOGDOTEXP 0 // log ::dotExp()
-#define LOGDEFAULTINIT 0 // log ::defaultInit()
+#define LOGDOTEXP 0 // log ::dotExp()
+#define LOGDEFAULTINIT 0 // log ::defaultInit()
// Allow implicit conversion of T[] to T*
-#define IMPLICIT_ARRAY_TO_PTR global.params.useDeprecated
+#define IMPLICIT_ARRAY_TO_PTR global.params.useDeprecated
/* These have default values for 32 bit code, they get
* adjusted for 64 bit code.
@@ -167,11 +167,11 @@ int Type::equals(Object *o)
t = (Type *)o;
//printf("Type::equals(%s, %s)\n", toChars(), t->toChars());
if (this == o ||
- (t && deco == t->deco) && // deco strings are unique
- deco != NULL) // and semantic() has been run
+ (t && deco == t->deco) && // deco strings are unique
+ deco != NULL) // and semantic() has been run
{
- //printf("deco = '%s', t->deco = '%s'\n", deco, t->deco);
- return 1;
+ //printf("deco = '%s', t->deco = '%s'\n", deco, t->deco);
+ return 1;
}
//if (deco && t && t->deco) printf("deco = '%s', t->deco = '%s'\n", deco, t->deco);
return 0;
@@ -179,7 +179,7 @@ int Type::equals(Object *o)
char Type::needThisPrefix()
{
- return 'M'; // name mangling prefix for functions needing 'this'
+ return 'M'; // name mangling prefix for functions needing 'this'
}
#if IN_LLVM
@@ -240,22 +240,22 @@ void Type::init()
mangleChar[Treturn] = '@';
for (i = 0; i < TMAX; i++)
- { if (!mangleChar[i])
- fprintf(stdmsg, "ty = %d\n", i);
- assert(mangleChar[i]);
+ { if (!mangleChar[i])
+ fprintf(stdmsg, "ty = %d\n", i);
+ assert(mangleChar[i]);
}
// Set basic types
static TY basetab[] =
- { Tvoid, Tint8, Tuns8, Tint16, Tuns16, Tint32, Tuns32, Tint64, Tuns64,
- Tfloat32, Tfloat64, Tfloat80,
- Timaginary32, Timaginary64, Timaginary80,
- Tcomplex32, Tcomplex64, Tcomplex80,
- Tbit, Tbool,
- Tascii, Twchar, Tdchar };
+ { Tvoid, Tint8, Tuns8, Tint16, Tuns16, Tint32, Tuns32, Tint64, Tuns64,
+ Tfloat32, Tfloat64, Tfloat80,
+ Timaginary32, Timaginary64, Timaginary80,
+ Tcomplex32, Tcomplex64, Tcomplex80,
+ Tbit, Tbool,
+ Tascii, Twchar, Tdchar };
for (i = 0; i < sizeof(basetab) / sizeof(basetab[0]); i++)
- basic[basetab[i]] = new TypeBasic(basetab[i]);
+ basic[basetab[i]] = new TypeBasic(basetab[i]);
basic[Terror] = basic[Tint32];
tvoidptr = tvoid->pointerTo();
@@ -266,32 +266,32 @@ void Type::init()
// set size_t / ptrdiff_t types and pointer size
if (global.params.is64bit)
{
- Tsize_t = Tuns64;
- Tptrdiff_t = Tint64;
- PTRSIZE = 8;
+ Tsize_t = Tuns64;
+ Tptrdiff_t = Tint64;
+ PTRSIZE = 8;
}
else
{
- Tsize_t = Tuns32;
- Tptrdiff_t = Tint32;
- PTRSIZE = 4;
+ Tsize_t = Tuns32;
+ Tptrdiff_t = Tint32;
+ PTRSIZE = 4;
}
// set real size and padding
if (global.params.cpu == ARCHx86)
{
- REALSIZE = 12;
- REALPAD = 2;
+ REALSIZE = 12;
+ REALPAD = 2;
}
else if (global.params.cpu == ARCHx86_64)
{
- REALSIZE = 16;
- REALPAD = 6;
+ REALSIZE = 16;
+ REALPAD = 6;
}
else
{
- REALSIZE = 8;
- REALPAD = 0;
+ REALSIZE = 8;
+ REALPAD = 0;
}
}
@@ -314,17 +314,17 @@ unsigned Type::alignsize()
Type *Type::semantic(Loc loc, Scope *sc)
{
if (next)
- next = next->semantic(loc,sc);
+ next = next->semantic(loc,sc);
return merge();
}
Type *Type::pointerTo()
{
if (!pto)
- { Type *t;
+ { Type *t;
- t = new TypePointer(this);
- pto = t->merge();
+ t = new TypePointer(this);
+ pto = t->merge();
}
return pto;
}
@@ -332,10 +332,10 @@ Type *Type::pointerTo()
Type *Type::referenceTo()
{
if (!rto)
- { Type *t;
+ { Type *t;
- t = new TypeReference(this);
- rto = t->merge();
+ t = new TypeReference(this);
+ rto = t->merge();
}
return rto;
}
@@ -343,10 +343,10 @@ Type *Type::referenceTo()
Type *Type::arrayOf()
{
if (!arrayof)
- { Type *t;
+ { Type *t;
- t = new TypeDArray(this);
- arrayof = t->merge();
+ t = new TypeDArray(this);
+ arrayof = t->merge();
}
return arrayof;
}
@@ -375,9 +375,9 @@ void Type::toDecoBuffer(OutBuffer *buf, bool mangle)
buf->writeByte(mangleChar[ty]);
if (next)
{
- assert(next != this);
- //printf("this = %p, ty = %d, next = %p, ty = %d\n", this, this->ty, next, next->ty);
- next->toDecoBuffer(buf, mangle);
+ assert(next != this);
+ //printf("this = %p, ty = %d, next = %p, ty = %d\n", this, this->ty, next, next->ty);
+ next->toDecoBuffer(buf, mangle);
}
}
@@ -398,16 +398,16 @@ void Type::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs)
{
toCBuffer2(buf, hgs, 0);
if (ident)
- { buf->writeByte(' ');
- buf->writestring(ident->toChars());
+ { buf->writeByte(' ');
+ buf->writestring(ident->toChars());
}
}
void Type::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
buf->writestring(toChars());
}
@@ -415,25 +415,25 @@ void Type::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
void Type::toCBuffer3(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { const char *p;
+ { const char *p;
- switch (this->mod)
- {
- case 0:
- toCBuffer2(buf, hgs, this->mod);
- break;
- case MODconst:
- p = "const(";
- goto L1;
- case MODimmutable:
- p = "invariant(";
- L1: buf->writestring(p);
- toCBuffer2(buf, hgs, this->mod);
- buf->writeByte(')');
- break;
- default:
- assert(0);
- }
+ switch (this->mod)
+ {
+ case 0:
+ toCBuffer2(buf, hgs, this->mod);
+ break;
+ case MODconst:
+ p = "const(";
+ goto L1;
+ case MODimmutable:
+ p = "invariant(";
+ L1: buf->writestring(p);
+ toCBuffer2(buf, hgs, this->mod);
+ buf->writeByte(')');
+ break;
+ default:
+ assert(0);
+ }
}
}
@@ -448,39 +448,39 @@ Type *Type::merge()
assert(t);
if (!deco)
{
- if (next)
- next = next->merge();
+ if (next)
+ next = next->merge();
- OutBuffer buf;
- toDecoBuffer(&buf, false);
- StringValue *sv = stringtable.update((char *)buf.data, buf.offset);
- if (sv->ptrvalue)
- { t = (Type *) sv->ptrvalue;
- assert(t->deco);
- //printf("old value, deco = '%s' %p\n", t->deco, t->deco);
- }
- else
- {
- sv->ptrvalue = this;
+ OutBuffer buf;
+ toDecoBuffer(&buf, false);
+ StringValue *sv = stringtable.update((char *)buf.data, buf.offset);
+ if (sv->ptrvalue)
+ { t = (Type *) sv->ptrvalue;
+ assert(t->deco);
+ //printf("old value, deco = '%s' %p\n", t->deco, t->deco);
+ }
+ else
+ {
+ sv->ptrvalue = this;
// we still need deco strings to be unique
// or Type::equals fails, which breaks a bunch of stuff,
// like covariant member function overloads.
- OutBuffer mangle;
- toDecoBuffer(&mangle, true);
- StringValue* sv2 = deco_stringtable.update((char *)mangle.data, mangle.offset);
- if (sv2->ptrvalue)
- { Type* t2 = (Type *) sv2->ptrvalue;
- assert(t2->deco);
- deco = t2->deco;
- }
- else
- {
- sv2->ptrvalue = this;
- deco = (char *)sv2->lstring.string;
- }
- //printf("new value, deco = '%s' %p\n", t->deco, t->deco);
- }
+ OutBuffer mangle;
+ toDecoBuffer(&mangle, true);
+ StringValue* sv2 = deco_stringtable.update((char *)mangle.data, mangle.offset);
+ if (sv2->ptrvalue)
+ { Type* t2 = (Type *) sv2->ptrvalue;
+ assert(t2->deco);
+ deco = t2->deco;
+ }
+ else
+ {
+ sv2->ptrvalue = this;
+ deco = (char *)sv2->lstring.string;
+ }
+ //printf("new value, deco = '%s' %p\n", t->deco, t->deco);
+ }
}
return t;
}
@@ -495,15 +495,15 @@ Type *Type::merge2()
Type *t = this;
assert(t);
if (!t->deco)
- return t->merge();
+ return t->merge();
StringValue *sv = deco_stringtable.lookup((char *)t->deco, strlen(t->deco));
if (sv && sv->ptrvalue)
{ t = (Type *) sv->ptrvalue;
- assert(t->deco);
+ assert(t->deco);
}
else
- assert(0);
+ assert(0);
return t;
}
@@ -575,9 +575,9 @@ void Type::checkDeprecated(Loc loc, Scope *sc)
{
for (Type *t = this; t; t = t->next)
{
- Dsymbol *s = t->toDsymbol(sc);
- if (s)
- s->checkDeprecated(loc, sc);
+ Dsymbol *s = t->toDsymbol(sc);
+ if (s)
+ s->checkDeprecated(loc, sc);
}
}
@@ -604,21 +604,21 @@ Expression *Type::defaultInitLiteral(Loc loc)
int Type::isZeroInit(Loc loc)
{
- return 0; // assume not
+ return 0; // assume not
}
int Type::isBaseOf(Type *t, int *poffset)
{
- return 0; // assume not
+ return 0; // assume not
}
/********************************
* Determine if 'this' can be implicitly converted
* to type 'to'.
* Returns:
- * 0 can't convert
- * 1 can convert using implicit conversions
- * 2 this and to are the same type
+ * 0 can't convert
+ * 1 can convert using implicit conversions
+ * 2 this and to are the same type
*/
MATCH Type::implicitConvTo(Type *to)
@@ -626,9 +626,9 @@ MATCH Type::implicitConvTo(Type *to)
//printf("Type::implicitConvTo(this=%p, to=%p)\n", this, to);
//printf("\tthis->next=%p, to->next=%p\n", this->next, to->next);
if (this == to)
- return MATCHexact;
+ return MATCHexact;
// if (to->ty == Tvoid)
-// return 1;
+// return 1;
return MATCHnomatch;
}
@@ -640,59 +640,59 @@ Expression *Type::getProperty(Loc loc, Identifier *ident)
#endif
if (ident == Id::__sizeof)
{
- e = new IntegerExp(loc, size(loc), Type::tsize_t);
+ e = new IntegerExp(loc, size(loc), Type::tsize_t);
}
else if (ident == Id::size)
{
- error(loc, ".size property should be replaced with .sizeof");
- e = new ErrorExp();
+ error(loc, ".size property should be replaced with .sizeof");
+ e = new ErrorExp();
}
else if (ident == Id::alignof)
{
- e = new IntegerExp(loc, alignsize(), Type::tsize_t);
+ e = new IntegerExp(loc, alignsize(), Type::tsize_t);
}
else if (ident == Id::typeinfo)
{
- if (!global.params.useDeprecated)
- error(loc, ".typeinfo deprecated, use typeid(type)");
- e = getTypeInfo(NULL);
+ if (!global.params.useDeprecated)
+ error(loc, ".typeinfo deprecated, use typeid(type)");
+ e = getTypeInfo(NULL);
}
else if (ident == Id::init)
{
- if (ty == Tvoid)
- error(loc, "void does not have an initializer");
- e = defaultInit(loc);
+ if (ty == Tvoid)
+ error(loc, "void does not have an initializer");
+ e = defaultInit(loc);
}
else if (ident == Id::mangleof)
- { const char *s;
- if (!deco)
- { s = toChars();
- error(loc, "forward reference of type %s.mangleof", s);
- }
- else
- s = deco;
- e = new StringExp(loc, (char *)s, strlen(s), 'c');
- Scope sc;
- e = e->semantic(&sc);
+ { const char *s;
+ if (!deco)
+ { s = toChars();
+ error(loc, "forward reference of type %s.mangleof", s);
+ }
+ else
+ s = deco;
+ e = new StringExp(loc, (char *)s, strlen(s), 'c');
+ Scope sc;
+ e = e->semantic(&sc);
}
else if (ident == Id::stringof)
- { char *s = toChars();
- e = new StringExp(loc, s, strlen(s), 'c');
- Scope sc;
- e = e->semantic(&sc);
+ { char *s = toChars();
+ e = new StringExp(loc, s, strlen(s), 'c');
+ Scope sc;
+ e = e->semantic(&sc);
}
else
{
- Dsymbol *s = NULL;
- if (ty == Tstruct || ty == Tclass || ty == Tenum || ty == Ttypedef)
- s = toDsymbol(NULL);
- if (s)
- s = s->search_correct(ident);
- if (s)
- error(loc, "no property '%s' for type '%s', did you mean '%s'?", ident->toChars(), toChars(), s->toChars());
- else
- error(loc, "no property '%s' for type '%s'", ident->toChars(), toChars());
- e = new ErrorExp();
+ Dsymbol *s = NULL;
+ if (ty == Tstruct || ty == Tclass || ty == Tenum || ty == Ttypedef)
+ s = toDsymbol(NULL);
+ if (s)
+ s = s->search_correct(ident);
+ if (s)
+ error(loc, "no property '%s' for type '%s', did you mean '%s'?", ident->toChars(), toChars(), s->toChars());
+ else
+ error(loc, "no property '%s' for type '%s'", ident->toChars(), toChars());
+ e = new ErrorExp();
}
return e;
}
@@ -705,79 +705,79 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
#endif
if (e->op == TOKdotvar)
{
- DotVarExp *dv = (DotVarExp *)e;
- v = dv->var->isVarDeclaration();
+ DotVarExp *dv = (DotVarExp *)e;
+ v = dv->var->isVarDeclaration();
}
else if (e->op == TOKvar)
{
- VarExp *ve = (VarExp *)e;
- v = ve->var->isVarDeclaration();
+ VarExp *ve = (VarExp *)e;
+ v = ve->var->isVarDeclaration();
}
if (v)
{
- if (ident == Id::offset)
- {
- if (!global.params.useDeprecated)
- error(e->loc, ".offset deprecated, use .offsetof");
- goto Loffset;
- }
- else if (ident == Id::offsetof)
- {
- Loffset:
- if (v->storage_class & STCfield)
- {
- e = new IntegerExp(e->loc, v->offset, Type::tsize_t);
- return e;
- }
- }
- else if (ident == Id::init)
- {
+ if (ident == Id::offset)
+ {
+ if (!global.params.useDeprecated)
+ error(e->loc, ".offset deprecated, use .offsetof");
+ goto Loffset;
+ }
+ else if (ident == Id::offsetof)
+ {
+ Loffset:
+ if (v->storage_class & STCfield)
+ {
+ e = new IntegerExp(e->loc, v->offset, Type::tsize_t);
+ return e;
+ }
+ }
+ else if (ident == Id::init)
+ {
#if 0
- if (v->init)
- {
- if (v->init->isVoidInitializer())
- error(e->loc, "%s.init is void", v->toChars());
- else
- { Loc loc = e->loc;
- e = v->init->toExpression();
- if (e->op == TOKassign || e->op == TOKconstruct)
- {
- e = ((AssignExp *)e)->e2;
+ if (v->init)
+ {
+ if (v->init->isVoidInitializer())
+ error(e->loc, "%s.init is void", v->toChars());
+ else
+ { Loc loc = e->loc;
+ e = v->init->toExpression();
+ if (e->op == TOKassign || e->op == TOKconstruct)
+ {
+ e = ((AssignExp *)e)->e2;
- /* Take care of case where we used a 0
- * to initialize the struct.
- */
- if (e->type == Type::tint32 &&
- e->isBool(0) &&
- v->type->toBasetype()->ty == Tstruct)
- {
- e = v->type->defaultInit(loc);
- }
- }
- e = e->optimize(WANTvalue | WANTinterpret);
-// if (!e->isConst())
-// error(loc, ".init cannot be evaluated at compile time");
- }
- return e;
- }
+ /* Take care of case where we used a 0
+ * to initialize the struct.
+ */
+ if (e->type == Type::tint32 &&
+ e->isBool(0) &&
+ v->type->toBasetype()->ty == Tstruct)
+ {
+ e = v->type->defaultInit(loc);
+ }
+ }
+ e = e->optimize(WANTvalue | WANTinterpret);
+// if (!e->isConst())
+// error(loc, ".init cannot be evaluated at compile time");
+ }
+ return e;
+ }
#endif
- Expression *ex = defaultInit(e->loc);
- return ex;
- }
+ Expression *ex = defaultInit(e->loc);
+ return ex;
+ }
}
if (ident == Id::typeinfo)
{
- if (!global.params.useDeprecated)
- error(e->loc, ".typeinfo deprecated, use typeid(type)");
- e = getTypeInfo(sc);
- return e;
+ if (!global.params.useDeprecated)
+ error(e->loc, ".typeinfo deprecated, use typeid(type)");
+ e = getTypeInfo(sc);
+ return e;
}
if (ident == Id::stringof)
- { char *s = e->toChars();
- e = new StringExp(e->loc, s, strlen(s), 'c');
- Scope sc;
- e = e->semantic(&sc);
- return e;
+ { char *s = e->toChars();
+ e = new StringExp(e->loc, s, strlen(s), 'c');
+ Scope sc;
+ e = e->semantic(&sc);
+ return e;
}
return getProperty(e->loc, ident);
}
@@ -813,12 +813,12 @@ Identifier *Type::getTypeInfoIdent(int internal)
//toTypeInfoBuffer(&buf);
if (internal)
- { buf.writeByte(mangleChar[ty]);
- if (ty == Tarray)
- buf.writeByte(mangleChar[((TypeArray *)this)->next->ty]);
+ { buf.writeByte(mangleChar[ty]);
+ if (ty == Tarray)
+ buf.writeByte(mangleChar[((TypeArray *)this)->next->ty]);
}
else
- toDecoBuffer(&buf, true);
+ toDecoBuffer(&buf, true);
len = buf.offset;
name = (char *)alloca(19 + sizeof(len) * 3 + len + 1);
buf.writeByte(0);
@@ -826,7 +826,7 @@ Identifier *Type::getTypeInfoIdent(int internal)
// LDC
// it is not clear where the underscore that's stripped here is added back in
// if (global.params.isWindows)
-// name++; // C mangling will add it back in
+// name++; // C mangling will add it back in
//printf("name = %s\n", name);
id = Lexer::idPool(name);
return id;
@@ -855,9 +855,9 @@ void Type::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps)
Type *Type::reliesOnTident()
{
if (!next)
- return NULL;
+ return NULL;
else
- return next->reliesOnTident();
+ return next->reliesOnTident();
}
/********************************
@@ -884,137 +884,137 @@ int Type::hasPointers()
/* ============================= TypeBasic =========================== */
TypeBasic::TypeBasic(TY ty)
- : Type(ty, NULL)
+ : Type(ty, NULL)
{ const char *c;
const char *d;
unsigned flags;
-#define TFLAGSintegral 1
-#define TFLAGSfloating 2
-#define TFLAGSunsigned 4
-#define TFLAGSreal 8
-#define TFLAGSimaginary 0x10
-#define TFLAGScomplex 0x20
+#define TFLAGSintegral 1
+#define TFLAGSfloating 2
+#define TFLAGSunsigned 4
+#define TFLAGSreal 8
+#define TFLAGSimaginary 0x10
+#define TFLAGScomplex 0x20
flags = 0;
switch (ty)
{
- case Tvoid: d = Token::toChars(TOKvoid);
- c = "void";
- break;
+ case Tvoid: d = Token::toChars(TOKvoid);
+ c = "void";
+ break;
- case Tint8: d = Token::toChars(TOKint8);
- c = "byte";
- flags |= TFLAGSintegral;
- break;
+ case Tint8: d = Token::toChars(TOKint8);
+ c = "byte";
+ flags |= TFLAGSintegral;
+ break;
- case Tuns8: d = Token::toChars(TOKuns8);
- c = "ubyte";
- flags |= TFLAGSintegral | TFLAGSunsigned;
- break;
+ case Tuns8: d = Token::toChars(TOKuns8);
+ c = "ubyte";
+ flags |= TFLAGSintegral | TFLAGSunsigned;
+ break;
- case Tint16: d = Token::toChars(TOKint16);
- c = "short";
- flags |= TFLAGSintegral;
- break;
+ case Tint16: d = Token::toChars(TOKint16);
+ c = "short";
+ flags |= TFLAGSintegral;
+ break;
- case Tuns16: d = Token::toChars(TOKuns16);
- c = "ushort";
- flags |= TFLAGSintegral | TFLAGSunsigned;
- break;
+ case Tuns16: d = Token::toChars(TOKuns16);
+ c = "ushort";
+ flags |= TFLAGSintegral | TFLAGSunsigned;
+ break;
- case Tint32: d = Token::toChars(TOKint32);
- c = "int";
- flags |= TFLAGSintegral;
- break;
+ case Tint32: d = Token::toChars(TOKint32);
+ c = "int";
+ flags |= TFLAGSintegral;
+ break;
- case Tuns32: d = Token::toChars(TOKuns32);
- c = "uint";
- flags |= TFLAGSintegral | TFLAGSunsigned;
- break;
+ case Tuns32: d = Token::toChars(TOKuns32);
+ c = "uint";
+ flags |= TFLAGSintegral | TFLAGSunsigned;
+ break;
- case Tfloat32: d = Token::toChars(TOKfloat32);
- c = "float";
- flags |= TFLAGSfloating | TFLAGSreal;
- break;
+ case Tfloat32: d = Token::toChars(TOKfloat32);
+ c = "float";
+ flags |= TFLAGSfloating | TFLAGSreal;
+ break;
- case Tint64: d = Token::toChars(TOKint64);
- c = "long";
- flags |= TFLAGSintegral;
- break;
+ case Tint64: d = Token::toChars(TOKint64);
+ c = "long";
+ flags |= TFLAGSintegral;
+ break;
- case Tuns64: d = Token::toChars(TOKuns64);
- c = "ulong";
- flags |= TFLAGSintegral | TFLAGSunsigned;
- break;
+ case Tuns64: d = Token::toChars(TOKuns64);
+ c = "ulong";
+ flags |= TFLAGSintegral | TFLAGSunsigned;
+ break;
- case Tfloat64: d = Token::toChars(TOKfloat64);
- c = "double";
- flags |= TFLAGSfloating | TFLAGSreal;
- break;
+ case Tfloat64: d = Token::toChars(TOKfloat64);
+ c = "double";
+ flags |= TFLAGSfloating | TFLAGSreal;
+ break;
- case Tfloat80: d = Token::toChars(TOKfloat80);
- c = "real";
- flags |= TFLAGSfloating | TFLAGSreal;
- break;
+ case Tfloat80: d = Token::toChars(TOKfloat80);
+ c = "real";
+ flags |= TFLAGSfloating | TFLAGSreal;
+ break;
- case Timaginary32: d = Token::toChars(TOKimaginary32);
- c = "ifloat";
- flags |= TFLAGSfloating | TFLAGSimaginary;
- break;
+ case Timaginary32: d = Token::toChars(TOKimaginary32);
+ c = "ifloat";
+ flags |= TFLAGSfloating | TFLAGSimaginary;
+ break;
- case Timaginary64: d = Token::toChars(TOKimaginary64);
- c = "idouble";
- flags |= TFLAGSfloating | TFLAGSimaginary;
- break;
+ case Timaginary64: d = Token::toChars(TOKimaginary64);
+ c = "idouble";
+ flags |= TFLAGSfloating | TFLAGSimaginary;
+ break;
- case Timaginary80: d = Token::toChars(TOKimaginary80);
- c = "ireal";
- flags |= TFLAGSfloating | TFLAGSimaginary;
- break;
+ case Timaginary80: d = Token::toChars(TOKimaginary80);
+ c = "ireal";
+ flags |= TFLAGSfloating | TFLAGSimaginary;
+ break;
- case Tcomplex32: d = Token::toChars(TOKcomplex32);
- c = "cfloat";
- flags |= TFLAGSfloating | TFLAGScomplex;
- break;
+ case Tcomplex32: d = Token::toChars(TOKcomplex32);
+ c = "cfloat";
+ flags |= TFLAGSfloating | TFLAGScomplex;
+ break;
- case Tcomplex64: d = Token::toChars(TOKcomplex64);
- c = "cdouble";
- flags |= TFLAGSfloating | TFLAGScomplex;
- break;
+ case Tcomplex64: d = Token::toChars(TOKcomplex64);
+ c = "cdouble";
+ flags |= TFLAGSfloating | TFLAGScomplex;
+ break;
- case Tcomplex80: d = Token::toChars(TOKcomplex80);
- c = "creal";
- flags |= TFLAGSfloating | TFLAGScomplex;
- break;
+ case Tcomplex80: d = Token::toChars(TOKcomplex80);
+ c = "creal";
+ flags |= TFLAGSfloating | TFLAGScomplex;
+ break;
- case Tbit: d = Token::toChars(TOKbit);
- c = "bit";
- flags |= TFLAGSintegral | TFLAGSunsigned;
- break;
+ case Tbit: d = Token::toChars(TOKbit);
+ c = "bit";
+ flags |= TFLAGSintegral | TFLAGSunsigned;
+ break;
- case Tbool: d = "bool";
- c = d;
- flags |= TFLAGSintegral | TFLAGSunsigned;
- break;
+ case Tbool: d = "bool";
+ c = d;
+ flags |= TFLAGSintegral | TFLAGSunsigned;
+ break;
- case Tascii: d = Token::toChars(TOKchar);
- c = "char";
- flags |= TFLAGSintegral | TFLAGSunsigned;
- break;
+ case Tascii: d = Token::toChars(TOKchar);
+ c = "char";
+ flags |= TFLAGSintegral | TFLAGSunsigned;
+ break;
- case Twchar: d = Token::toChars(TOKwchar);
- c = "wchar";
- flags |= TFLAGSintegral | TFLAGSunsigned;
- break;
+ case Twchar: d = Token::toChars(TOKwchar);
+ c = "wchar";
+ flags |= TFLAGSintegral | TFLAGSunsigned;
+ break;
- case Tdchar: d = Token::toChars(TOKdchar);
- c = "dchar";
- flags |= TFLAGSintegral | TFLAGSunsigned;
- break;
+ case Tdchar: d = Token::toChars(TOKdchar);
+ c = "dchar";
+ flags |= TFLAGSintegral | TFLAGSunsigned;
+ break;
- default: assert(0);
+ default: assert(0);
}
this->dstring = d;
this->cstring = c;
@@ -1038,8 +1038,8 @@ void TypeBasic::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
//printf("TypeBasic::toCBuffer2(mod = %d, this->mod = %d)\n", mod, this->mod);
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
buf->writestring(dstring);
}
@@ -1050,44 +1050,44 @@ d_uns64 TypeBasic::size(Loc loc)
//printf("TypeBasic::size()\n");
switch (ty)
{
- case Tint8:
- case Tuns8: size = 1; break;
- case Tint16:
- case Tuns16: size = 2; break;
- case Tint32:
- case Tuns32:
- case Tfloat32:
- case Timaginary32:
- size = 4; break;
- case Tint64:
- case Tuns64:
- case Tfloat64:
- case Timaginary64:
- size = 8; break;
- case Tfloat80:
- case Timaginary80:
- size = REALSIZE; break;
- case Tcomplex32:
- size = 8; break;
- case Tcomplex64:
- size = 16; break;
- case Tcomplex80:
- size = REALSIZE * 2; break;
+ case Tint8:
+ case Tuns8: size = 1; break;
+ case Tint16:
+ case Tuns16: size = 2; break;
+ case Tint32:
+ case Tuns32:
+ case Tfloat32:
+ case Timaginary32:
+ size = 4; break;
+ case Tint64:
+ case Tuns64:
+ case Tfloat64:
+ case Timaginary64:
+ size = 8; break;
+ case Tfloat80:
+ case Timaginary80:
+ size = REALSIZE; break;
+ case Tcomplex32:
+ size = 8; break;
+ case Tcomplex64:
+ size = 16; break;
+ case Tcomplex80:
+ size = REALSIZE * 2; break;
- case Tvoid:
- //size = Type::size(); // error message
- size = 1;
- break;
+ case Tvoid:
+ //size = Type::size(); // error message
+ size = 1;
+ break;
- case Tbit: size = 1; break;
- case Tbool: size = 1; break;
- case Tascii: size = 1; break;
- case Twchar: size = 2; break;
- case Tdchar: size = 4; break;
+ case Tbit: size = 1; break;
+ case Tbool: size = 1; break;
+ case Tascii: size = 1; break;
+ case Twchar: size = 2; break;
+ case Tdchar: size = 4; break;
- default:
- assert(0);
- break;
+ default:
+ assert(0);
+ break;
}
//printf("TypeBasic::size() = %d\n", size);
return size;
@@ -1099,14 +1099,14 @@ unsigned TypeBasic::alignsize()
return 1;
return GetTypeAlignment(sir, this);
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS
- case Tint64:
- case Tuns64:
- case Tfloat64:
- case Timaginary64:
- case Tcomplex32:
- case Tcomplex64:
- sz = 4;
- break;
+ case Tint64:
+ case Tuns64:
+ case Tfloat64:
+ case Timaginary64:
+ case Tcomplex32:
+ case Tcomplex64:
+ sz = 4;
+ break;
#endif
}
@@ -1125,202 +1125,202 @@ Expression *TypeBasic::getProperty(Loc loc, Identifier *ident)
//printf("TypeBasic::getProperty('%s')\n", ident->toChars());
if (ident == Id::max)
{
- switch (ty)
- {
- case Tint8: ivalue = 0x7F; goto Livalue;
- case Tuns8: ivalue = 0xFF; goto Livalue;
- case Tint16: ivalue = 0x7FFFUL; goto Livalue;
- case Tuns16: ivalue = 0xFFFFUL; goto Livalue;
- case Tint32: ivalue = 0x7FFFFFFFUL; goto Livalue;
- case Tuns32: ivalue = 0xFFFFFFFFUL; goto Livalue;
- case Tint64: ivalue = 0x7FFFFFFFFFFFFFFFLL; goto Livalue;
- case Tuns64: ivalue = 0xFFFFFFFFFFFFFFFFULL; goto Livalue;
- case Tbit: ivalue = 1; goto Livalue;
- case Tbool: ivalue = 1; goto Livalue;
- case Tchar: ivalue = 0xFF; goto Livalue;
- case Twchar: ivalue = 0xFFFFUL; goto Livalue;
- case Tdchar: ivalue = 0x10FFFFUL; goto Livalue;
+ switch (ty)
+ {
+ case Tint8: ivalue = 0x7F; goto Livalue;
+ case Tuns8: ivalue = 0xFF; goto Livalue;
+ case Tint16: ivalue = 0x7FFFUL; goto Livalue;
+ case Tuns16: ivalue = 0xFFFFUL; goto Livalue;
+ case Tint32: ivalue = 0x7FFFFFFFUL; goto Livalue;
+ case Tuns32: ivalue = 0xFFFFFFFFUL; goto Livalue;
+ case Tint64: ivalue = 0x7FFFFFFFFFFFFFFFLL; goto Livalue;
+ case Tuns64: ivalue = 0xFFFFFFFFFFFFFFFFULL; goto Livalue;
+ case Tbit: ivalue = 1; goto Livalue;
+ case Tbool: ivalue = 1; goto Livalue;
+ case Tchar: ivalue = 0xFF; goto Livalue;
+ case Twchar: ivalue = 0xFFFFUL; goto Livalue;
+ case Tdchar: ivalue = 0x10FFFFUL; goto Livalue;
- case Tcomplex32:
- case Timaginary32:
- case Tfloat32: fvalue = FLT_MAX; goto Lfvalue;
- case Tcomplex64:
- case Timaginary64:
- case Tfloat64: fvalue = DBL_MAX; goto Lfvalue;
- case Tcomplex80:
- case Timaginary80:
- case Tfloat80: fvalue = Port::ldbl_max; goto Lfvalue;
- }
+ case Tcomplex32:
+ case Timaginary32:
+ case Tfloat32: fvalue = FLT_MAX; goto Lfvalue;
+ case Tcomplex64:
+ case Timaginary64:
+ case Tfloat64: fvalue = DBL_MAX; goto Lfvalue;
+ case Tcomplex80:
+ case Timaginary80:
+ case Tfloat80: fvalue = Port::ldbl_max; goto Lfvalue;
+ }
}
else if (ident == Id::min)
{
- switch (ty)
- {
- case Tint8: ivalue = -128; goto Livalue;
- case Tuns8: ivalue = 0; goto Livalue;
- case Tint16: ivalue = -32768; goto Livalue;
- case Tuns16: ivalue = 0; goto Livalue;
- case Tint32: ivalue = -2147483647L - 1; goto Livalue;
- case Tuns32: ivalue = 0; goto Livalue;
- case Tint64: ivalue = (-9223372036854775807LL-1LL); goto Livalue;
- case Tuns64: ivalue = 0; goto Livalue;
- case Tbit: ivalue = 0; goto Livalue;
- case Tbool: ivalue = 0; goto Livalue;
- case Tchar: ivalue = 0; goto Livalue;
- case Twchar: ivalue = 0; goto Livalue;
- case Tdchar: ivalue = 0; goto Livalue;
+ switch (ty)
+ {
+ case Tint8: ivalue = -128; goto Livalue;
+ case Tuns8: ivalue = 0; goto Livalue;
+ case Tint16: ivalue = -32768; goto Livalue;
+ case Tuns16: ivalue = 0; goto Livalue;
+ case Tint32: ivalue = -2147483647L - 1; goto Livalue;
+ case Tuns32: ivalue = 0; goto Livalue;
+ case Tint64: ivalue = (-9223372036854775807LL-1LL); goto Livalue;
+ case Tuns64: ivalue = 0; goto Livalue;
+ case Tbit: ivalue = 0; goto Livalue;
+ case Tbool: ivalue = 0; goto Livalue;
+ case Tchar: ivalue = 0; goto Livalue;
+ case Twchar: ivalue = 0; goto Livalue;
+ case Tdchar: ivalue = 0; goto Livalue;
- case Tcomplex32:
- case Timaginary32:
- case Tfloat32: fvalue = FLT_MIN; goto Lfvalue;
- case Tcomplex64:
- case Timaginary64:
- case Tfloat64: fvalue = DBL_MIN; goto Lfvalue;
- case Tcomplex80:
- case Timaginary80:
- case Tfloat80: fvalue = LDBL_MIN; goto Lfvalue;
- }
+ case Tcomplex32:
+ case Timaginary32:
+ case Tfloat32: fvalue = FLT_MIN; goto Lfvalue;
+ case Tcomplex64:
+ case Timaginary64:
+ case Tfloat64: fvalue = DBL_MIN; goto Lfvalue;
+ case Tcomplex80:
+ case Timaginary80:
+ case Tfloat80: fvalue = LDBL_MIN; goto Lfvalue;
+ }
}
else if (ident == Id::nan)
{
- switch (ty)
- {
- case Tcomplex32:
- case Tcomplex64:
- case Tcomplex80:
- case Timaginary32:
- case Timaginary64:
- case Timaginary80:
- case Tfloat32:
- case Tfloat64:
- case Tfloat80:
- {
- fvalue = Port::nan;
- goto Lfvalue;
- }
- }
+ switch (ty)
+ {
+ case Tcomplex32:
+ case Tcomplex64:
+ case Tcomplex80:
+ case Timaginary32:
+ case Timaginary64:
+ case Timaginary80:
+ case Tfloat32:
+ case Tfloat64:
+ case Tfloat80:
+ {
+ fvalue = Port::nan;
+ goto Lfvalue;
+ }
+ }
}
else if (ident == Id::infinity)
{
- switch (ty)
- {
- case Tcomplex32:
- case Tcomplex64:
- case Tcomplex80:
- case Timaginary32:
- case Timaginary64:
- case Timaginary80:
- case Tfloat32:
- case Tfloat64:
- case Tfloat80:
- fvalue = Port::infinity;
- goto Lfvalue;
- }
+ switch (ty)
+ {
+ case Tcomplex32:
+ case Tcomplex64:
+ case Tcomplex80:
+ case Timaginary32:
+ case Timaginary64:
+ case Timaginary80:
+ case Tfloat32:
+ case Tfloat64:
+ case Tfloat80:
+ fvalue = Port::infinity;
+ goto Lfvalue;
+ }
}
else if (ident == Id::dig)
{
- switch (ty)
- {
- case Tcomplex32:
- case Timaginary32:
- case Tfloat32: ivalue = FLT_DIG; goto Lint;
- case Tcomplex64:
- case Timaginary64:
- case Tfloat64: ivalue = DBL_DIG; goto Lint;
- case Tcomplex80:
- case Timaginary80:
- case Tfloat80: ivalue = LDBL_DIG; goto Lint;
- }
+ switch (ty)
+ {
+ case Tcomplex32:
+ case Timaginary32:
+ case Tfloat32: ivalue = FLT_DIG; goto Lint;
+ case Tcomplex64:
+ case Timaginary64:
+ case Tfloat64: ivalue = DBL_DIG; goto Lint;
+ case Tcomplex80:
+ case Timaginary80:
+ case Tfloat80: ivalue = LDBL_DIG; goto Lint;
+ }
}
else if (ident == Id::epsilon)
{
- switch (ty)
- {
- case Tcomplex32:
- case Timaginary32:
- case Tfloat32: fvalue = FLT_EPSILON; goto Lfvalue;
- case Tcomplex64:
- case Timaginary64:
- case Tfloat64: fvalue = DBL_EPSILON; goto Lfvalue;
- case Tcomplex80:
- case Timaginary80:
- case Tfloat80: fvalue = LDBL_EPSILON; goto Lfvalue;
- }
+ switch (ty)
+ {
+ case Tcomplex32:
+ case Timaginary32:
+ case Tfloat32: fvalue = FLT_EPSILON; goto Lfvalue;
+ case Tcomplex64:
+ case Timaginary64:
+ case Tfloat64: fvalue = DBL_EPSILON; goto Lfvalue;
+ case Tcomplex80:
+ case Timaginary80:
+ case Tfloat80: fvalue = LDBL_EPSILON; goto Lfvalue;
+ }
}
else if (ident == Id::mant_dig)
{
- switch (ty)
- {
- case Tcomplex32:
- case Timaginary32:
- case Tfloat32: ivalue = FLT_MANT_DIG; goto Lint;
- case Tcomplex64:
- case Timaginary64:
- case Tfloat64: ivalue = DBL_MANT_DIG; goto Lint;
- case Tcomplex80:
- case Timaginary80:
- case Tfloat80: ivalue = LDBL_MANT_DIG; goto Lint;
- }
+ switch (ty)
+ {
+ case Tcomplex32:
+ case Timaginary32:
+ case Tfloat32: ivalue = FLT_MANT_DIG; goto Lint;
+ case Tcomplex64:
+ case Timaginary64:
+ case Tfloat64: ivalue = DBL_MANT_DIG; goto Lint;
+ case Tcomplex80:
+ case Timaginary80:
+ case Tfloat80: ivalue = LDBL_MANT_DIG; goto Lint;
+ }
}
else if (ident == Id::max_10_exp)
{
- switch (ty)
- {
- case Tcomplex32:
- case Timaginary32:
- case Tfloat32: ivalue = FLT_MAX_10_EXP; goto Lint;
- case Tcomplex64:
- case Timaginary64:
- case Tfloat64: ivalue = DBL_MAX_10_EXP; goto Lint;
- case Tcomplex80:
- case Timaginary80:
- case Tfloat80: ivalue = LDBL_MAX_10_EXP; goto Lint;
- }
+ switch (ty)
+ {
+ case Tcomplex32:
+ case Timaginary32:
+ case Tfloat32: ivalue = FLT_MAX_10_EXP; goto Lint;
+ case Tcomplex64:
+ case Timaginary64:
+ case Tfloat64: ivalue = DBL_MAX_10_EXP; goto Lint;
+ case Tcomplex80:
+ case Timaginary80:
+ case Tfloat80: ivalue = LDBL_MAX_10_EXP; goto Lint;
+ }
}
else if (ident == Id::max_exp)
{
- switch (ty)
- {
- case Tcomplex32:
- case Timaginary32:
- case Tfloat32: ivalue = FLT_MAX_EXP; goto Lint;
- case Tcomplex64:
- case Timaginary64:
- case Tfloat64: ivalue = DBL_MAX_EXP; goto Lint;
- case Tcomplex80:
- case Timaginary80:
- case Tfloat80: ivalue = LDBL_MAX_EXP; goto Lint;
- }
+ switch (ty)
+ {
+ case Tcomplex32:
+ case Timaginary32:
+ case Tfloat32: ivalue = FLT_MAX_EXP; goto Lint;
+ case Tcomplex64:
+ case Timaginary64:
+ case Tfloat64: ivalue = DBL_MAX_EXP; goto Lint;
+ case Tcomplex80:
+ case Timaginary80:
+ case Tfloat80: ivalue = LDBL_MAX_EXP; goto Lint;
+ }
}
else if (ident == Id::min_10_exp)
{
- switch (ty)
- {
- case Tcomplex32:
- case Timaginary32:
- case Tfloat32: ivalue = FLT_MIN_10_EXP; goto Lint;
- case Tcomplex64:
- case Timaginary64:
- case Tfloat64: ivalue = DBL_MIN_10_EXP; goto Lint;
- case Tcomplex80:
- case Timaginary80:
- case Tfloat80: ivalue = LDBL_MIN_10_EXP; goto Lint;
- }
+ switch (ty)
+ {
+ case Tcomplex32:
+ case Timaginary32:
+ case Tfloat32: ivalue = FLT_MIN_10_EXP; goto Lint;
+ case Tcomplex64:
+ case Timaginary64:
+ case Tfloat64: ivalue = DBL_MIN_10_EXP; goto Lint;
+ case Tcomplex80:
+ case Timaginary80:
+ case Tfloat80: ivalue = LDBL_MIN_10_EXP; goto Lint;
+ }
}
else if (ident == Id::min_exp)
{
- switch (ty)
- {
- case Tcomplex32:
- case Timaginary32:
- case Tfloat32: ivalue = FLT_MIN_EXP; goto Lint;
- case Tcomplex64:
- case Timaginary64:
- case Tfloat64: ivalue = DBL_MIN_EXP; goto Lint;
- case Tcomplex80:
- case Timaginary80:
- case Tfloat80: ivalue = LDBL_MIN_EXP; goto Lint;
- }
+ switch (ty)
+ {
+ case Tcomplex32:
+ case Timaginary32:
+ case Tfloat32: ivalue = FLT_MIN_EXP; goto Lint;
+ case Tcomplex64:
+ case Timaginary64:
+ case Tfloat64: ivalue = DBL_MIN_EXP; goto Lint;
+ case Tcomplex80:
+ case Timaginary80:
+ case Tfloat80: ivalue = LDBL_MIN_EXP; goto Lint;
+ }
}
Ldefault:
@@ -1332,23 +1332,23 @@ Livalue:
Lfvalue:
if (isreal() || isimaginary())
- e = new RealExp(loc, fvalue, this);
+ e = new RealExp(loc, fvalue, this);
else
{
- complex_t cvalue;
+ complex_t cvalue;
#if __DMC__
- //((real_t *)&cvalue)[0] = fvalue;
- //((real_t *)&cvalue)[1] = fvalue;
- cvalue = fvalue + fvalue * I;
+ //((real_t *)&cvalue)[0] = fvalue;
+ //((real_t *)&cvalue)[1] = fvalue;
+ cvalue = fvalue + fvalue * I;
#else
- cvalue.re = fvalue;
- cvalue.im = fvalue;
+ cvalue.re = fvalue;
+ cvalue.im = fvalue;
#endif
- //for (int i = 0; i < 20; i++)
- // printf("%02x ", ((unsigned char *)&cvalue)[i]);
- //printf("\n");
- e = new ComplexExp(loc, cvalue, this);
+ //for (int i = 0; i < 20; i++)
+ // printf("%02x ", ((unsigned char *)&cvalue)[i]);
+ //printf("\n");
+ e = new ComplexExp(loc, cvalue, this);
}
return e;
@@ -1366,64 +1366,64 @@ Expression *TypeBasic::dotExp(Scope *sc, Expression *e, Identifier *ident)
if (ident == Id::re)
{
- switch (ty)
- {
- case Tcomplex32: t = tfloat32; goto L1;
- case Tcomplex64: t = tfloat64; goto L1;
- case Tcomplex80: t = tfloat80; goto L1;
- L1:
- e = e->castTo(sc, t);
- break;
+ switch (ty)
+ {
+ case Tcomplex32: t = tfloat32; goto L1;
+ case Tcomplex64: t = tfloat64; goto L1;
+ case Tcomplex80: t = tfloat80; goto L1;
+ L1:
+ e = e->castTo(sc, t);
+ break;
- case Tfloat32:
- case Tfloat64:
- case Tfloat80:
- break;
+ case Tfloat32:
+ case Tfloat64:
+ case Tfloat80:
+ break;
- case Timaginary32: t = tfloat32; goto L2;
- case Timaginary64: t = tfloat64; goto L2;
- case Timaginary80: t = tfloat80; goto L2;
- L2:
- e = new RealExp(0, 0.0, t);
- break;
+ case Timaginary32: t = tfloat32; goto L2;
+ case Timaginary64: t = tfloat64; goto L2;
+ case Timaginary80: t = tfloat80; goto L2;
+ L2:
+ e = new RealExp(0, 0.0, t);
+ break;
- default:
- return Type::getProperty(e->loc, ident);
- }
+ default:
+ return Type::getProperty(e->loc, ident);
+ }
}
else if (ident == Id::im)
- { Type *t2;
+ { Type *t2;
- switch (ty)
- {
- case Tcomplex32: t = timaginary32; t2 = tfloat32; goto L3;
- case Tcomplex64: t = timaginary64; t2 = tfloat64; goto L3;
- case Tcomplex80: t = timaginary80; t2 = tfloat80; goto L3;
- L3:
- e = e->castTo(sc, t);
- e->type = t2;
- break;
+ switch (ty)
+ {
+ case Tcomplex32: t = timaginary32; t2 = tfloat32; goto L3;
+ case Tcomplex64: t = timaginary64; t2 = tfloat64; goto L3;
+ case Tcomplex80: t = timaginary80; t2 = tfloat80; goto L3;
+ L3:
+ e = e->castTo(sc, t);
+ e->type = t2;
+ break;
- case Timaginary32: t = tfloat32; goto L4;
- case Timaginary64: t = tfloat64; goto L4;
- case Timaginary80: t = tfloat80; goto L4;
- L4:
- e->type = t;
- break;
+ case Timaginary32: t = tfloat32; goto L4;
+ case Timaginary64: t = tfloat64; goto L4;
+ case Timaginary80: t = tfloat80; goto L4;
+ L4:
+ e->type = t;
+ break;
- case Tfloat32:
- case Tfloat64:
- case Tfloat80:
- e = new RealExp(0, 0.0, this);
- break;
+ case Tfloat32:
+ case Tfloat64:
+ case Tfloat80:
+ e = new RealExp(0, 0.0, this);
+ break;
- default:
- return Type::getProperty(e->loc, ident);
- }
+ default:
+ return Type::getProperty(e->loc, ident);
+ }
}
else
{
- return Type::dotExp(sc, e, ident);
+ return Type::dotExp(sc, e, ident);
}
return e;
}
@@ -1436,28 +1436,28 @@ Expression *TypeBasic::defaultInit(Loc loc)
#endif
switch (ty)
{
- case Tvoid:
- return new IntegerExp(loc, value, Type::tbool);
+ case Tvoid:
+ return new IntegerExp(loc, value, Type::tbool);
- case Tchar:
- value = 0xFF;
- break;
+ case Tchar:
+ value = 0xFF;
+ break;
- case Twchar:
- case Tdchar:
- value = 0xFFFF;
- break;
+ case Twchar:
+ case Tdchar:
+ value = 0xFFFF;
+ break;
- case Timaginary32:
- case Timaginary64:
- case Timaginary80:
- case Tfloat32:
- case Tfloat64:
- case Tfloat80:
- case Tcomplex32:
- case Tcomplex64:
- case Tcomplex80:
- return getProperty(loc, Id::nan);
+ case Timaginary32:
+ case Timaginary64:
+ case Timaginary80:
+ case Tfloat32:
+ case Tfloat64:
+ case Tfloat80:
+ case Tcomplex32:
+ case Tcomplex64:
+ case Tcomplex80:
+ return getProperty(loc, Id::nan);
}
return new IntegerExp(loc, value, this);
}
@@ -1466,21 +1466,21 @@ int TypeBasic::isZeroInit(Loc loc)
{
switch (ty)
{
- case Tchar:
- case Twchar:
- case Tdchar:
- case Timaginary32:
- case Timaginary64:
- case Timaginary80:
- case Tfloat32:
- case Tfloat64:
- case Tfloat80:
- case Tcomplex32:
- case Tcomplex64:
- case Tcomplex80:
- return 0; // no
+ case Tchar:
+ case Twchar:
+ case Tdchar:
+ case Timaginary32:
+ case Timaginary64:
+ case Timaginary80:
+ case Tfloat32:
+ case Tfloat64:
+ case Tfloat80:
+ case Tcomplex32:
+ case Tcomplex64:
+ case Tcomplex80:
+ return 0; // no
}
- return 1; // yes
+ return 1; // yes
}
int TypeBasic::isbit()
@@ -1528,59 +1528,59 @@ MATCH TypeBasic::implicitConvTo(Type *to)
{
//printf("TypeBasic::implicitConvTo(%s) from %s\n", to->toChars(), toChars());
if (this == to)
- return MATCHexact;
+ return MATCHexact;
if (ty == Tvoid || to->ty == Tvoid)
- return MATCHnomatch;
+ return MATCHnomatch;
if (to->ty == Tbool)
- return MATCHnomatch;
+ return MATCHnomatch;
if (!to->isTypeBasic())
- return MATCHnomatch;
+ return MATCHnomatch;
TypeBasic *tob = (TypeBasic *)to;
if (flags & TFLAGSintegral)
{
- // Disallow implicit conversion of integers to imaginary or complex
- if (tob->flags & (TFLAGSimaginary | TFLAGScomplex))
- return MATCHnomatch;
+ // Disallow implicit conversion of integers to imaginary or complex
+ if (tob->flags & (TFLAGSimaginary | TFLAGScomplex))
+ return MATCHnomatch;
#if DMDV2
- // If converting to integral
- if (0 && global.params.Dversion > 1 && tob->flags & TFLAGSintegral)
- { d_uns64 sz = size(0);
- d_uns64 tosz = tob->size(0);
+ // If converting to integral
+ if (0 && global.params.Dversion > 1 && tob->flags & TFLAGSintegral)
+ { d_uns64 sz = size(0);
+ d_uns64 tosz = tob->size(0);
- /* Can't convert to smaller size or, if same size, change sign
- */
- if (sz > tosz)
- return MATCHnomatch;
+ /* Can't convert to smaller size or, if same size, change sign
+ */
+ if (sz > tosz)
+ return MATCHnomatch;
- /*if (sz == tosz && (flags ^ tob->flags) & TFLAGSunsigned)
- return MATCHnomatch;*/
- }
+ /*if (sz == tosz && (flags ^ tob->flags) & TFLAGSunsigned)
+ return MATCHnomatch;*/
+ }
#endif
}
else if (flags & TFLAGSfloating)
{
- // Disallow implicit conversion of floating point to integer
- if (tob->flags & TFLAGSintegral)
- return MATCHnomatch;
+ // Disallow implicit conversion of floating point to integer
+ if (tob->flags & TFLAGSintegral)
+ return MATCHnomatch;
- assert(tob->flags & TFLAGSfloating);
+ assert(tob->flags & TFLAGSfloating);
- // Disallow implicit conversion from complex to non-complex
- if (flags & TFLAGScomplex && !(tob->flags & TFLAGScomplex))
- return MATCHnomatch;
+ // Disallow implicit conversion from complex to non-complex
+ if (flags & TFLAGScomplex && !(tob->flags & TFLAGScomplex))
+ return MATCHnomatch;
- // Disallow implicit conversion of real or imaginary to complex
- if (flags & (TFLAGSreal | TFLAGSimaginary) &&
- tob->flags & TFLAGScomplex)
- return MATCHnomatch;
+ // Disallow implicit conversion of real or imaginary to complex
+ if (flags & (TFLAGSreal | TFLAGSimaginary) &&
+ tob->flags & TFLAGScomplex)
+ return MATCHnomatch;
- // Disallow implicit conversion to-from real and imaginary
- if ((flags & (TFLAGSreal | TFLAGSimaginary)) !=
- (tob->flags & (TFLAGSreal | TFLAGSimaginary)))
- return MATCHnomatch;
+ // Disallow implicit conversion to-from real and imaginary
+ if ((flags & (TFLAGSreal | TFLAGSimaginary)) !=
+ (tob->flags & (TFLAGSreal | TFLAGSimaginary)))
+ return MATCHnomatch;
}
return MATCHconvert;
}
@@ -1599,106 +1599,106 @@ TypeArray::TypeArray(TY ty, Type *next)
Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
{
- Type *n = this->next->toBasetype(); // uncover any typedef's
+ Type *n = this->next->toBasetype(); // uncover any typedef's
#if LOGDOTEXP
printf("TypeArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars());
#endif
if (ident == Id::reverse && (n->ty == Tchar || n->ty == Twchar))
{
- Expression *ec;
- Expressions *arguments;
+ Expression *ec;
+ Expressions *arguments;
- //LDC: Build arguments.
- static FuncDeclaration *adReverseChar_fd = NULL;
- if(!adReverseChar_fd) {
- Parameters* args = new Parameters;
- Type* arrty = Type::tchar->arrayOf();
- args->push(new Parameter(STCin, arrty, NULL, NULL));
- adReverseChar_fd = FuncDeclaration::genCfunc(args, arrty, "_adReverseChar");
- }
- static FuncDeclaration *adReverseWchar_fd = NULL;
- if(!adReverseWchar_fd) {
- Parameters* args = new Parameters;
- Type* arrty = Type::twchar->arrayOf();
- args->push(new Parameter(STCin, arrty, NULL, NULL));
- adReverseWchar_fd = FuncDeclaration::genCfunc(args, arrty, "_adReverseWchar");
- }
+ //LDC: Build arguments.
+ static FuncDeclaration *adReverseChar_fd = NULL;
+ if(!adReverseChar_fd) {
+ Parameters* args = new Parameters;
+ Type* arrty = Type::tchar->arrayOf();
+ args->push(new Parameter(STCin, arrty, NULL, NULL));
+ adReverseChar_fd = FuncDeclaration::genCfunc(args, arrty, "_adReverseChar");
+ }
+ static FuncDeclaration *adReverseWchar_fd = NULL;
+ if(!adReverseWchar_fd) {
+ Parameters* args = new Parameters;
+ Type* arrty = Type::twchar->arrayOf();
+ args->push(new Parameter(STCin, arrty, NULL, NULL));
+ adReverseWchar_fd = FuncDeclaration::genCfunc(args, arrty, "_adReverseWchar");
+ }
- if(n->ty == Twchar)
- ec = new VarExp(0, adReverseWchar_fd);
- else
- ec = new VarExp(0, adReverseChar_fd);
- e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
- arguments = new Expressions();
- arguments->push(e);
- e = new CallExp(e->loc, ec, arguments);
- e->type = next->arrayOf();
+ if(n->ty == Twchar)
+ ec = new VarExp(0, adReverseWchar_fd);
+ else
+ ec = new VarExp(0, adReverseChar_fd);
+ e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
+ arguments = new Expressions();
+ arguments->push(e);
+ e = new CallExp(e->loc, ec, arguments);
+ e->type = next->arrayOf();
}
else if (ident == Id::sort && (n->ty == Tchar || n->ty == Twchar))
{
- Expression *ec;
- Expressions *arguments;
+ Expression *ec;
+ Expressions *arguments;
- //LDC: Build arguments.
- static FuncDeclaration *adSortChar_fd = NULL;
- if(!adSortChar_fd) {
- Parameters* args = new Parameters;
- Type* arrty = Type::tchar->arrayOf();
- args->push(new Parameter(STCin, arrty, NULL, NULL));
- adSortChar_fd = FuncDeclaration::genCfunc(args, arrty, "_adSortChar");
- }
- static FuncDeclaration *adSortWchar_fd = NULL;
- if(!adSortWchar_fd) {
- Parameters* args = new Parameters;
- Type* arrty = Type::twchar->arrayOf();
- args->push(new Parameter(STCin, arrty, NULL, NULL));
- adSortWchar_fd = FuncDeclaration::genCfunc(args, arrty, "_adSortWchar");
- }
+ //LDC: Build arguments.
+ static FuncDeclaration *adSortChar_fd = NULL;
+ if(!adSortChar_fd) {
+ Parameters* args = new Parameters;
+ Type* arrty = Type::tchar->arrayOf();
+ args->push(new Parameter(STCin, arrty, NULL, NULL));
+ adSortChar_fd = FuncDeclaration::genCfunc(args, arrty, "_adSortChar");
+ }
+ static FuncDeclaration *adSortWchar_fd = NULL;
+ if(!adSortWchar_fd) {
+ Parameters* args = new Parameters;
+ Type* arrty = Type::twchar->arrayOf();
+ args->push(new Parameter(STCin, arrty, NULL, NULL));
+ adSortWchar_fd = FuncDeclaration::genCfunc(args, arrty, "_adSortWchar");
+ }
- if(n->ty == Twchar)
- ec = new VarExp(0, adSortWchar_fd);
- else
- ec = new VarExp(0, adSortChar_fd);
- e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
- arguments = new Expressions();
- arguments->push(e);
- e = new CallExp(e->loc, ec, arguments);
- e->type = next->arrayOf();
+ if(n->ty == Twchar)
+ ec = new VarExp(0, adSortWchar_fd);
+ else
+ ec = new VarExp(0, adSortChar_fd);
+ e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
+ arguments = new Expressions();
+ arguments->push(e);
+ e = new CallExp(e->loc, ec, arguments);
+ e->type = next->arrayOf();
}
else if (ident == Id::reverse || ident == Id::dup)
{
- Expression *ec;
- Expressions *arguments;
- int size = next->size(e->loc);
- int dup;
+ Expression *ec;
+ Expressions *arguments;
+ int size = next->size(e->loc);
+ int dup;
- assert(size);
- dup = (ident == Id::dup);
- //LDC: Build arguments.
- static FuncDeclaration *adDup_fd = NULL;
- if(!adDup_fd) {
- Parameters* args = new Parameters;
- args->push(new Parameter(STCin, Type::typeinfo->type, NULL, NULL));
- args->push(new Parameter(STCin, Type::tvoid->arrayOf(), NULL, NULL));
- adDup_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::adDup);
- }
- static FuncDeclaration *adReverse_fd = NULL;
- if(!adReverse_fd) {
- Parameters* args = new Parameters;
- args->push(new Parameter(STCin, Type::tvoid->arrayOf(), NULL, NULL));
- args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
- adReverse_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::adReverse);
- }
+ assert(size);
+ dup = (ident == Id::dup);
+ //LDC: Build arguments.
+ static FuncDeclaration *adDup_fd = NULL;
+ if(!adDup_fd) {
+ Parameters* args = new Parameters;
+ args->push(new Parameter(STCin, Type::typeinfo->type, NULL, NULL));
+ args->push(new Parameter(STCin, Type::tvoid->arrayOf(), NULL, NULL));
+ adDup_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::adDup);
+ }
+ static FuncDeclaration *adReverse_fd = NULL;
+ if(!adReverse_fd) {
+ Parameters* args = new Parameters;
+ args->push(new Parameter(STCin, Type::tvoid->arrayOf(), NULL, NULL));
+ args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
+ adReverse_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::adReverse);
+ }
- if(dup)
- ec = new VarExp(0, adDup_fd);
- else
- ec = new VarExp(0, adReverse_fd);
- e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
- arguments = new Expressions();
- if (dup)
- arguments->push(getTypeInfo(sc));
+ if(dup)
+ ec = new VarExp(0, adDup_fd);
+ else
+ ec = new VarExp(0, adReverse_fd);
+ e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
+ arguments = new Expressions();
+ if (dup)
+ arguments->push(getTypeInfo(sc));
// LDC repaint array type to void[]
if (n->ty != Tvoid) {
@@ -1707,39 +1707,39 @@ Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
}
arguments->push(e);
- if (!dup)
- arguments->push(new IntegerExp(0, size, Type::tsize_t));
- e = new CallExp(e->loc, ec, arguments);
- e->type = next->arrayOf();
+ if (!dup)
+ arguments->push(new IntegerExp(0, size, Type::tsize_t));
+ e = new CallExp(e->loc, ec, arguments);
+ e->type = next->arrayOf();
}
else if (ident == Id::sort)
{
- Expression *ec;
- Expressions *arguments;
- bool isBit = (n->ty == Tbit);
+ Expression *ec;
+ Expressions *arguments;
+ bool isBit = (n->ty == Tbit);
- //LDC: Build arguments.
- static FuncDeclaration *adSort_fd = NULL;
- if(!adSort_fd) {
- Parameters* args = new Parameters;
- args->push(new Parameter(STCin, Type::tvoid->arrayOf(), NULL, NULL));
- args->push(new Parameter(STCin, Type::typeinfo->type, NULL, NULL));
- adSort_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSort");
- }
- static FuncDeclaration *adSortBit_fd = NULL;
- if(!adSortBit_fd) {
- Parameters* args = new Parameters;
- args->push(new Parameter(STCin, Type::tvoid->arrayOf(), NULL, NULL));
- args->push(new Parameter(STCin, Type::typeinfo->type, NULL, NULL));
- adSortBit_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSortBit");
- }
+ //LDC: Build arguments.
+ static FuncDeclaration *adSort_fd = NULL;
+ if(!adSort_fd) {
+ Parameters* args = new Parameters;
+ args->push(new Parameter(STCin, Type::tvoid->arrayOf(), NULL, NULL));
+ args->push(new Parameter(STCin, Type::typeinfo->type, NULL, NULL));
+ adSort_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSort");
+ }
+ static FuncDeclaration *adSortBit_fd = NULL;
+ if(!adSortBit_fd) {
+ Parameters* args = new Parameters;
+ args->push(new Parameter(STCin, Type::tvoid->arrayOf(), NULL, NULL));
+ args->push(new Parameter(STCin, Type::typeinfo->type, NULL, NULL));
+ adSortBit_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSortBit");
+ }
- if(isBit)
- ec = new VarExp(0, adSortBit_fd);
- else
- ec = new VarExp(0, adSort_fd);
- e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
- arguments = new Expressions();
+ if(isBit)
+ ec = new VarExp(0, adSortBit_fd);
+ else
+ ec = new VarExp(0, adSort_fd);
+ e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
+ arguments = new Expressions();
// LDC repaint array type to void[]
if (n->ty != Tvoid) {
@@ -1751,12 +1751,12 @@ Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
if (next->ty != Tbit)
arguments->push(n->getTypeInfo(sc)); // LDC, we don't support the getInternalTypeInfo
// optimization arbitrarily, not yet at least...
- e = new CallExp(e->loc, ec, arguments);
- e->type = next->arrayOf();
+ e = new CallExp(e->loc, ec, arguments);
+ e->type = next->arrayOf();
}
else
{
- e = Type::dotExp(sc, e, ident);
+ e = Type::dotExp(sc, e, ident);
}
return e;
}
@@ -1783,22 +1783,22 @@ d_uns64 TypeSArray::size(Loc loc)
{ dinteger_t sz;
if (!dim)
- return Type::size(loc);
+ return Type::size(loc);
sz = dim->toInteger();
- if (next->toBasetype()->ty == Tbit) // if array of bits
+ if (next->toBasetype()->ty == Tbit) // if array of bits
{
- if (sz + 31 < sz)
- goto Loverflow;
- sz = ((sz + 31) & ~31) / 8; // size in bytes, rounded up to 32 bit dwords
+ if (sz + 31 < sz)
+ goto Loverflow;
+ sz = ((sz + 31) & ~31) / 8; // size in bytes, rounded up to 32 bit dwords
}
else
- { dinteger_t n, n2;
+ { dinteger_t n, n2;
- n = next->size();
- n2 = n * sz;
- if (n && (n2 / n) != sz)
- goto Loverflow;
- sz = n2;
+ n = next->size();
+ n2 = n * sz;
+ if (n && (n2 / n) != sz)
+ goto Loverflow;
+ sz = n2;
}
return sz;
@@ -1819,16 +1819,16 @@ unsigned TypeSArray::alignsize()
Expression *semanticLength(Scope *sc, Type *t, Expression *exp)
{
if (t->ty == Ttuple)
- { ScopeDsymbol *sym = new ArrayScopeSymbol((TypeTuple *)t);
- sym->parent = sc->scopesym;
- sc = sc->push(sym);
+ { ScopeDsymbol *sym = new ArrayScopeSymbol((TypeTuple *)t);
+ sym->parent = sc->scopesym;
+ sc = sc->push(sym);
- exp = exp->semantic(sc);
+ exp = exp->semantic(sc);
- sc->pop();
+ sc->pop();
}
else
- exp = exp->semantic(sc);
+ exp = exp->semantic(sc);
return exp;
}
@@ -1850,62 +1850,62 @@ void TypeSArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
next->resolve(loc, sc, pe, pt, ps);
//printf("s = %p, e = %p, t = %p\n", *ps, *pe, *pt);
if (*pe)
- { // It's really an index expression
- Expression *e;
- e = new IndexExp(loc, *pe, dim);
- *pe = e;
+ { // It's really an index expression
+ Expression *e;
+ e = new IndexExp(loc, *pe, dim);
+ *pe = e;
}
else if (*ps)
- { Dsymbol *s = *ps;
- TupleDeclaration *td = s->isTupleDeclaration();
- if (td)
- {
- ScopeDsymbol *sym = new ArrayScopeSymbol(td);
- sym->parent = sc->scopesym;
- sc = sc->push(sym);
+ { Dsymbol *s = *ps;
+ TupleDeclaration *td = s->isTupleDeclaration();
+ if (td)
+ {
+ ScopeDsymbol *sym = new ArrayScopeSymbol(td);
+ sym->parent = sc->scopesym;
+ sc = sc->push(sym);
- dim = dim->semantic(sc);
- dim = dim->optimize(WANTvalue | WANTinterpret);
- uinteger_t d = dim->toUInteger();
+ dim = dim->semantic(sc);
+ dim = dim->optimize(WANTvalue | WANTinterpret);
+ uinteger_t d = dim->toUInteger();
- sc = sc->pop();
+ sc = sc->pop();
- if (d >= td->objects->dim)
- { error(loc, "tuple index %ju exceeds %u", d, td->objects->dim);
- goto Ldefault;
- }
- Object *o = (Object *)td->objects->data[(size_t)d];
- if (o->dyncast() == DYNCAST_DSYMBOL)
- {
- *ps = (Dsymbol *)o;
- return;
- }
- if (o->dyncast() == DYNCAST_EXPRESSION)
- {
- *ps = NULL;
- *pe = (Expression *)o;
- return;
- }
+ if (d >= td->objects->dim)
+ { error(loc, "tuple index %ju exceeds %u", d, td->objects->dim);
+ goto Ldefault;
+ }
+ Object *o = (Object *)td->objects->data[(size_t)d];
+ if (o->dyncast() == DYNCAST_DSYMBOL)
+ {
+ *ps = (Dsymbol *)o;
+ return;
+ }
+ if (o->dyncast() == DYNCAST_EXPRESSION)
+ {
+ *ps = NULL;
+ *pe = (Expression *)o;
+ return;
+ }
- /* Create a new TupleDeclaration which
- * is a slice [d..d+1] out of the old one.
- * Do it this way because TemplateInstance::semanticTiargs()
- * can handle unresolved Objects this way.
- */
- Objects *objects = new Objects;
- objects->setDim(1);
- objects->data[0] = o;
+ /* Create a new TupleDeclaration which
+ * is a slice [d..d+1] out of the old one.
+ * Do it this way because TemplateInstance::semanticTiargs()
+ * can handle unresolved Objects this way.
+ */
+ Objects *objects = new Objects;
+ objects->setDim(1);
+ objects->data[0] = o;
- TupleDeclaration *tds = new TupleDeclaration(loc, td->ident, objects);
- *ps = tds;
- }
- else
- goto Ldefault;
+ TupleDeclaration *tds = new TupleDeclaration(loc, td->ident, objects);
+ *ps = tds;
+ }
+ else
+ goto Ldefault;
}
else
{
Ldefault:
- Type::resolve(loc, sc, pe, pt, ps);
+ Type::resolve(loc, sc, pe, pt, ps);
}
}
@@ -1918,98 +1918,98 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
Dsymbol *s;
next->resolve(loc, sc, &e, &t, &s);
if (dim && s && s->isTupleDeclaration())
- { TupleDeclaration *sd = s->isTupleDeclaration();
+ { TupleDeclaration *sd = s->isTupleDeclaration();
- dim = semanticLength(sc, sd, dim);
- dim = dim->optimize(WANTvalue | WANTinterpret);
- uinteger_t d = dim->toUInteger();
+ dim = semanticLength(sc, sd, dim);
+ dim = dim->optimize(WANTvalue | WANTinterpret);
+ uinteger_t d = dim->toUInteger();
- if (d >= sd->objects->dim)
- { error(loc, "tuple index %ju exceeds %u", d, sd->objects->dim);
- return Type::terror;
- }
- Object *o = (Object *)sd->objects->data[(size_t)d];
- if (o->dyncast() != DYNCAST_TYPE)
- { error(loc, "%s is not a type", toChars());
- return Type::terror;
- }
- t = (Type *)o;
- return t;
+ if (d >= sd->objects->dim)
+ { error(loc, "tuple index %ju exceeds %u", d, sd->objects->dim);
+ return Type::terror;
+ }
+ Object *o = (Object *)sd->objects->data[(size_t)d];
+ if (o->dyncast() != DYNCAST_TYPE)
+ { error(loc, "%s is not a type", toChars());
+ return Type::terror;
+ }
+ t = (Type *)o;
+ return t;
}
next = next->semantic(loc,sc);
Type *tbn = next->toBasetype();
if (dim)
- { dinteger_t n, n2;
+ { dinteger_t n, n2;
- dim = semanticLength(sc, tbn, dim);
+ dim = semanticLength(sc, tbn, dim);
- dim = dim->optimize(WANTvalue | WANTinterpret);
- if (sc && sc->parameterSpecialization && dim->op == TOKvar &&
- ((VarExp *)dim)->var->storage_class & STCtemplateparameter)
- {
- /* It could be a template parameter N which has no value yet:
- * template Foo(T : T[N], size_t N);
- */
- return this;
- }
- dinteger_t d1 = dim->toInteger();
- dim = dim->castTo(sc, tsize_t);
- dim = dim->optimize(WANTvalue);
- dinteger_t d2 = dim->toInteger();
+ dim = dim->optimize(WANTvalue | WANTinterpret);
+ if (sc && sc->parameterSpecialization && dim->op == TOKvar &&
+ ((VarExp *)dim)->var->storage_class & STCtemplateparameter)
+ {
+ /* It could be a template parameter N which has no value yet:
+ * template Foo(T : T[N], size_t N);
+ */
+ return this;
+ }
+ dinteger_t d1 = dim->toInteger();
+ dim = dim->castTo(sc, tsize_t);
+ dim = dim->optimize(WANTvalue);
+ dinteger_t d2 = dim->toInteger();
- if (d1 != d2)
- goto Loverflow;
+ if (d1 != d2)
+ goto Loverflow;
- if (tbn->isintegral() ||
- tbn->isfloating() ||
- tbn->ty == Tpointer ||
- tbn->ty == Tarray ||
- tbn->ty == Tsarray ||
- tbn->ty == Taarray ||
- tbn->ty == Tclass)
- {
- /* Only do this for types that don't need to have semantic()
- * run on them for the size, since they may be forward referenced.
- */
- n = tbn->size(loc);
- n2 = n * d2;
- if ((int)n2 < 0)
- goto Loverflow;
- if (n2 >= 0x1000000) // put a 'reasonable' limit on it
- goto Loverflow;
- if (n && n2 / n != d2)
- {
- Loverflow:
- error(loc, "index %jd overflow for static array", d1);
- dim = new IntegerExp(0, 1, tsize_t);
- }
- }
+ if (tbn->isintegral() ||
+ tbn->isfloating() ||
+ tbn->ty == Tpointer ||
+ tbn->ty == Tarray ||
+ tbn->ty == Tsarray ||
+ tbn->ty == Taarray ||
+ tbn->ty == Tclass)
+ {
+ /* Only do this for types that don't need to have semantic()
+ * run on them for the size, since they may be forward referenced.
+ */
+ n = tbn->size(loc);
+ n2 = n * d2;
+ if ((int)n2 < 0)
+ goto Loverflow;
+ if (n2 >= 0x1000000) // put a 'reasonable' limit on it
+ goto Loverflow;
+ if (n && n2 / n != d2)
+ {
+ Loverflow:
+ error(loc, "index %jd overflow for static array", d1);
+ dim = new IntegerExp(0, 1, tsize_t);
+ }
+ }
}
switch (tbn->ty)
{
- case Ttuple:
- { // Index the tuple to get the type
- assert(dim);
- TypeTuple *tt = (TypeTuple *)tbn;
- uinteger_t d = dim->toUInteger();
+ case Ttuple:
+ { // Index the tuple to get the type
+ assert(dim);
+ TypeTuple *tt = (TypeTuple *)tbn;
+ uinteger_t d = dim->toUInteger();
- if (d >= tt->arguments->dim)
- { error(loc, "tuple index %ju exceeds %u", d, tt->arguments->dim);
- return Type::terror;
- }
- Parameter *arg = (Parameter *)tt->arguments->data[(size_t)d];
- return arg->type;
- }
- case Tfunction:
- case Tnone:
- error(loc, "can't have array of %s", tbn->toChars());
- tbn = next = tint32;
- break;
+ if (d >= tt->arguments->dim)
+ { error(loc, "tuple index %ju exceeds %u", d, tt->arguments->dim);
+ return Type::terror;
+ }
+ Parameter *arg = (Parameter *)tt->arguments->data[(size_t)d];
+ return arg->type;
+ }
+ case Tfunction:
+ case Tnone:
+ error(loc, "can't have array of %s", tbn->toChars());
+ tbn = next = tint32;
+ break;
}
if (tbn->isscope())
- error(loc, "cannot have array of scope %s", tbn->toChars());
+ error(loc, "cannot have array of scope %s", tbn->toChars());
return merge();
}
@@ -2017,16 +2017,16 @@ void TypeSArray::toDecoBuffer(OutBuffer *buf, bool mangle)
{
buf->writeByte(mangleChar[ty]);
if (dim)
- buf->printf("%ju", dim->toInteger());
+ buf->printf("%ju", dim->toInteger());
if (next)
- next->toDecoBuffer(buf, mangle);
+ next->toDecoBuffer(buf, mangle);
}
void TypeSArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
next->toCBuffer2(buf, hgs, this->mod);
buf->printf("[%s]", dim->toChars());
@@ -2039,15 +2039,15 @@ Expression *TypeSArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
#endif
if (ident == Id::length)
{
- e = dim;
+ e = dim;
}
else if (ident == Id::ptr)
{
- e = e->castTo(sc, next->pointerTo());
+ e = e->castTo(sc, next->pointerTo());
}
else
{
- e = TypeArray::dotExp(sc, e, ident);
+ e = TypeArray::dotExp(sc, e, ident);
}
return e;
}
@@ -2069,28 +2069,28 @@ MATCH TypeSArray::implicitConvTo(Type *to)
// Allow implicit conversion of static array to pointer or dynamic array
if ((IMPLICIT_ARRAY_TO_PTR && to->ty == Tpointer) &&
- (to->next->ty == Tvoid || next->equals(to->next)
- /*|| to->next->isBaseOf(next)*/))
+ (to->next->ty == Tvoid || next->equals(to->next)
+ /*|| to->next->isBaseOf(next)*/))
{
- return MATCHconvert;
+ return MATCHconvert;
}
if (to->ty == Tarray)
- { int offset = 0;
+ { int offset = 0;
- if (next->equals(to->next) ||
- (to->next->isBaseOf(next, &offset) && offset == 0) ||
- to->next->ty == Tvoid)
- return MATCHconvert;
+ if (next->equals(to->next) ||
+ (to->next->isBaseOf(next, &offset) && offset == 0) ||
+ to->next->ty == Tvoid)
+ return MATCHconvert;
}
#if 0
if (to->ty == Tsarray)
{
- TypeSArray *tsa = (TypeSArray *)to;
+ TypeSArray *tsa = (TypeSArray *)to;
- if (next->equals(tsa->next) && dim->equals(tsa->dim))
- {
- return MATCHconvert;
- }
+ if (next->equals(tsa->next) && dim->equals(tsa->dim))
+ {
+ return MATCHconvert;
+ }
}
#endif
return Type::implicitConvTo(to);
@@ -2129,9 +2129,9 @@ Expression *TypeSArray::toExpression()
{
Expression *e = next->toExpression();
if (e)
- { Expressions *arguments = new Expressions();
- arguments->push(dim);
- e = new ArrayExp(dim->loc, e, arguments);
+ { Expressions *arguments = new Expressions();
+ arguments->push(dim);
+ e = new ArrayExp(dim->loc, e, arguments);
}
return e;
}
@@ -2153,9 +2153,9 @@ Type *TypeDArray::syntaxCopy()
{
Type *t = next->syntaxCopy();
if (t == next)
- t = this;
+ t = this;
else
- t = new TypeDArray(t);
+ t = new TypeDArray(t);
return t;
}
@@ -2179,18 +2179,18 @@ Type *TypeDArray::semantic(Loc loc, Scope *sc)
Type *tbn = tn->toBasetype();
switch (tbn->ty)
{
- case Tfunction:
- case Tnone:
- case Ttuple:
- error(loc, "can't have array of %s", tbn->toChars());
- tn = next = tint32;
- break;
+ case Tfunction:
+ case Tnone:
+ case Ttuple:
+ error(loc, "can't have array of %s", tbn->toChars());
+ tn = next = tint32;
+ break;
}
if (tn->isscope())
- error(loc, "cannot have array of scope %s", tn->toChars());
+ error(loc, "cannot have array of scope %s", tn->toChars());
if (next != tn)
- //deco = NULL; // redo
- return tn->arrayOf();
+ //deco = NULL; // redo
+ return tn->arrayOf();
return merge();
}
@@ -2198,14 +2198,14 @@ void TypeDArray::toDecoBuffer(OutBuffer *buf, bool mangle)
{
buf->writeByte(mangleChar[ty]);
if (next)
- next->toDecoBuffer(buf, mangle);
+ next->toDecoBuffer(buf, mangle);
}
void TypeDArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
next->toCBuffer2(buf, hgs, this->mod);
buf->writestring("[]");
@@ -2218,23 +2218,23 @@ Expression *TypeDArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
#endif
if (ident == Id::length)
{
- if (e->op == TOKstring)
- { StringExp *se = (StringExp *)e;
+ if (e->op == TOKstring)
+ { StringExp *se = (StringExp *)e;
- return new IntegerExp(se->loc, se->len, Type::tindex);
- }
- e = new ArrayLengthExp(e->loc, e);
- e->type = Type::tsize_t;
- return e;
+ return new IntegerExp(se->loc, se->len, Type::tindex);
+ }
+ e = new ArrayLengthExp(e->loc, e);
+ e->type = Type::tsize_t;
+ return e;
}
else if (ident == Id::ptr)
{
- e = e->castTo(sc, next->pointerTo());
- return e;
+ e = e->castTo(sc, next->pointerTo());
+ return e;
}
else
{
- e = TypeArray::dotExp(sc, e, ident);
+ e = TypeArray::dotExp(sc, e, ident);
}
return e;
}
@@ -2251,18 +2251,18 @@ MATCH TypeDArray::implicitConvTo(Type *to)
// Allow implicit conversion of array to pointer
if (IMPLICIT_ARRAY_TO_PTR &&
- to->ty == Tpointer &&
- (to->next->ty == Tvoid || next->equals(to->next) /*|| to->next->isBaseOf(next)*/))
+ to->ty == Tpointer &&
+ (to->next->ty == Tvoid || next->equals(to->next) /*|| to->next->isBaseOf(next)*/))
{
- return MATCHconvert;
+ return MATCHconvert;
}
if (to->ty == Tarray)
- { int offset = 0;
+ { int offset = 0;
- if ((to->next->isBaseOf(next, &offset) && offset == 0) ||
- to->next->ty == Tvoid)
- return MATCHconvert;
+ if ((to->next->isBaseOf(next, &offset) && offset == 0) ||
+ to->next->ty == Tvoid)
+ return MATCHconvert;
}
return Type::implicitConvTo(to);
}
@@ -2304,9 +2304,9 @@ Type *TypeAArray::syntaxCopy()
Type *t = next->syntaxCopy();
Type *ti = index->syntaxCopy();
if (t == next && ti == index)
- t = this;
+ t = this;
else
- t = new TypeAArray(t, ti);
+ t = new TypeAArray(t, ti);
return t;
}
@@ -2324,26 +2324,26 @@ Type *TypeAArray::semantic(Loc loc, Scope *sc)
// in reality it was an expression.
if (index->ty == Tident || index->ty == Tinstance || index->ty == Tsarray)
{
- Expression *e;
- Type *t;
- Dsymbol *s;
+ Expression *e;
+ Type *t;
+ Dsymbol *s;
- index->resolve(loc, sc, &e, &t, &s);
- if (e)
- { // It was an expression -
- // Rewrite as a static array
- TypeSArray *tsa;
+ index->resolve(loc, sc, &e, &t, &s);
+ if (e)
+ { // It was an expression -
+ // Rewrite as a static array
+ TypeSArray *tsa;
- tsa = new TypeSArray(next, e);
- return tsa->semantic(loc,sc);
- }
- else if (t)
- index = t;
- else
- index->error(loc, "index is not a type or an expression");
+ tsa = new TypeSArray(next, e);
+ return tsa->semantic(loc,sc);
+ }
+ else if (t)
+ index = t;
+ else
+ index->error(loc, "index is not a type or an expression");
}
else
- index = index->semantic(loc,sc);
+ index = index->semantic(loc,sc);
// Compute key type; the purpose of the key type is to
// minimize the permutations of runtime library
@@ -2352,39 +2352,39 @@ Type *TypeAArray::semantic(Loc loc, Scope *sc)
switch (key->ty)
{
#if 0
- case Tint8:
- case Tuns8:
- case Tint16:
- case Tuns16:
- key = tint32;
- break;
+ case Tint8:
+ case Tuns8:
+ case Tint16:
+ case Tuns16:
+ key = tint32;
+ break;
#endif
- case Tsarray:
+ case Tsarray:
#if 0
- // Convert to Tarray
- key = key->next->arrayOf();
+ // Convert to Tarray
+ key = key->next->arrayOf();
#endif
- break;
- case Tbit:
- case Tbool:
- case Tfunction:
- case Tvoid:
- case Tnone:
- case Ttuple:
- error(loc, "can't have associative array key of %s", key->toChars());
- break;
+ break;
+ case Tbit:
+ case Tbool:
+ case Tfunction:
+ case Tvoid:
+ case Tnone:
+ case Ttuple:
+ error(loc, "can't have associative array key of %s", key->toChars());
+ break;
}
next = next->semantic(loc,sc);
switch (next->toBasetype()->ty)
{
- case Tfunction:
- case Tnone:
- error(loc, "can't have associative array of %s", next->toChars());
- break;
+ case Tfunction:
+ case Tnone:
+ error(loc, "can't have associative array of %s", next->toChars());
+ break;
}
if (next->isscope())
- error(loc, "cannot have array of scope %s", next->toChars());
+ error(loc, "cannot have array of scope %s", next->toChars());
return merge();
}
@@ -2397,22 +2397,22 @@ void TypeAArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
// in reality it was an expression.
if (index->ty == Tident || index->ty == Tinstance || index->ty == Tsarray)
{
- Expression *e;
- Type *t;
- Dsymbol *s;
+ Expression *e;
+ Type *t;
+ Dsymbol *s;
- index->resolve(loc, sc, &e, &t, &s);
- if (e)
- { // It was an expression -
- // Rewrite as a static array
+ index->resolve(loc, sc, &e, &t, &s);
+ if (e)
+ { // It was an expression -
+ // Rewrite as a static array
- TypeSArray *tsa = new TypeSArray(next, e);
- return tsa->resolve(loc, sc, pe, pt, ps);
- }
- else if (t)
- index = t;
- else
- index->error(loc, "index is not a type or an expression");
+ TypeSArray *tsa = new TypeSArray(next, e);
+ return tsa->resolve(loc, sc, pe, pt, ps);
+ }
+ else if (t)
+ index = t;
+ else
+ index->error(loc, "index is not a type or an expression");
}
Type::resolve(loc, sc, pe, pt, ps);
}
@@ -2425,95 +2425,95 @@ Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
#endif
if (ident == Id::length)
{
- Expression *ec;
- Expressions *arguments;
+ Expression *ec;
+ Expressions *arguments;
- //LDC: Build arguments.
- static FuncDeclaration *aaLen_fd = NULL;
- if(!aaLen_fd) {
- Parameters* args = new Parameters;
- args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
- aaLen_fd = FuncDeclaration::genCfunc(args, Type::tsize_t, Id::aaLen);
- }
+ //LDC: Build arguments.
+ static FuncDeclaration *aaLen_fd = NULL;
+ if(!aaLen_fd) {
+ Parameters* args = new Parameters;
+ args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
+ aaLen_fd = FuncDeclaration::genCfunc(args, Type::tsize_t, Id::aaLen);
+ }
- ec = new VarExp(0, aaLen_fd);
- arguments = new Expressions();
- arguments->push(e);
- e = new CallExp(e->loc, ec, arguments);
- e->type = aaLen_fd->type->next;
+ ec = new VarExp(0, aaLen_fd);
+ arguments = new Expressions();
+ arguments->push(e);
+ e = new CallExp(e->loc, ec, arguments);
+ e->type = aaLen_fd->type->next;
}
else if (ident == Id::keys)
{
- Expression *ec;
- Expressions *arguments;
- int size = key->size(e->loc);
+ Expression *ec;
+ Expressions *arguments;
+ int size = key->size(e->loc);
- assert(size);
- //LDC: Build arguments.
- static FuncDeclaration *aaKeys_fd = NULL;
- if(!aaKeys_fd) {
- Parameters* args = new Parameters;
- args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
- args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
- aaKeys_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaKeys);
- }
+ assert(size);
+ //LDC: Build arguments.
+ static FuncDeclaration *aaKeys_fd = NULL;
+ if(!aaKeys_fd) {
+ Parameters* args = new Parameters;
+ args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
+ args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
+ aaKeys_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaKeys);
+ }
- ec = new VarExp(0, aaKeys_fd);
- arguments = new Expressions();
- arguments->push(e);
- arguments->push(new IntegerExp(0, size, Type::tsize_t));
- e = new CallExp(e->loc, ec, arguments);
- e->type = index->arrayOf();
+ ec = new VarExp(0, aaKeys_fd);
+ arguments = new Expressions();
+ arguments->push(e);
+ arguments->push(new IntegerExp(0, size, Type::tsize_t));
+ e = new CallExp(e->loc, ec, arguments);
+ e->type = index->arrayOf();
}
else if (ident == Id::values)
{
- Expression *ec;
- Expressions *arguments;
+ Expression *ec;
+ Expressions *arguments;
- //LDC: Build arguments.
- static FuncDeclaration *aaValues_fd = NULL;
- if(!aaValues_fd) {
- Parameters* args = new Parameters;
- args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
- args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
- args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
- aaValues_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaValues);
- }
+ //LDC: Build arguments.
+ static FuncDeclaration *aaValues_fd = NULL;
+ if(!aaValues_fd) {
+ Parameters* args = new Parameters;
+ args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
+ args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
+ args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
+ aaValues_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaValues);
+ }
- ec = new VarExp(0, aaValues_fd);
- arguments = new Expressions();
- arguments->push(e);
- size_t keysize = key->size(e->loc);
- keysize = (keysize + PTRSIZE - 1) & ~(PTRSIZE - 1);
- arguments->push(new IntegerExp(0, keysize, Type::tsize_t));
- arguments->push(new IntegerExp(0, next->size(e->loc), Type::tsize_t));
- e = new CallExp(e->loc, ec, arguments);
- e->type = next->arrayOf();
+ ec = new VarExp(0, aaValues_fd);
+ arguments = new Expressions();
+ arguments->push(e);
+ size_t keysize = key->size(e->loc);
+ keysize = (keysize + PTRSIZE - 1) & ~(PTRSIZE - 1);
+ arguments->push(new IntegerExp(0, keysize, Type::tsize_t));
+ arguments->push(new IntegerExp(0, next->size(e->loc), Type::tsize_t));
+ e = new CallExp(e->loc, ec, arguments);
+ e->type = next->arrayOf();
}
else if (ident == Id::rehash)
{
- Expression *ec;
- Expressions *arguments;
+ Expression *ec;
+ Expressions *arguments;
- //LDC: Build arguments.
- static FuncDeclaration *aaRehash_fd = NULL;
- if(!aaRehash_fd) {
- Parameters* args = new Parameters;
- args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
- args->push(new Parameter(STCin, Type::typeinfo->type, NULL, NULL));
- aaRehash_fd = FuncDeclaration::genCfunc(args, Type::tvoidptr, Id::aaRehash);
- }
+ //LDC: Build arguments.
+ static FuncDeclaration *aaRehash_fd = NULL;
+ if(!aaRehash_fd) {
+ Parameters* args = new Parameters;
+ args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
+ args->push(new Parameter(STCin, Type::typeinfo->type, NULL, NULL));
+ aaRehash_fd = FuncDeclaration::genCfunc(args, Type::tvoidptr, Id::aaRehash);
+ }
- ec = new VarExp(0, aaRehash_fd);
- arguments = new Expressions();
- arguments->push(e->addressOf(sc));
- arguments->push(key->getTypeInfo(sc)); // LDC doesn't support getInternalTypeInfo, see above
- e = new CallExp(e->loc, ec, arguments);
- e->type = this;
+ ec = new VarExp(0, aaRehash_fd);
+ arguments = new Expressions();
+ arguments->push(e->addressOf(sc));
+ arguments->push(key->getTypeInfo(sc)); // LDC doesn't support getInternalTypeInfo, see above
+ e = new CallExp(e->loc, ec, arguments);
+ e->type = this;
}
else
{
- e = Type::dotExp(sc, e, ident);
+ e = Type::dotExp(sc, e, ident);
}
return e;
}
@@ -2528,8 +2528,8 @@ void TypeAArray::toDecoBuffer(OutBuffer *buf, bool mangle)
void TypeAArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
next->toCBuffer2(buf, hgs, this->mod);
buf->writeByte('[');
@@ -2571,28 +2571,28 @@ Type *TypePointer::syntaxCopy()
{
Type *t = next->syntaxCopy();
if (t == next)
- t = this;
+ t = this;
else
- t = new TypePointer(t);
+ t = new TypePointer(t);
return t;
}
Type *TypePointer::semantic(Loc loc, Scope *sc)
{
if (deco)
- return this;
+ return this;
//printf("TypePointer::semantic()\n");
Type *n = next->semantic(loc, sc);
switch (n->toBasetype()->ty)
{
- case Ttuple:
- error(loc, "can't have pointer to %s", n->toChars());
- n = tint32;
- break;
+ case Ttuple:
+ error(loc, "can't have pointer to %s", n->toChars());
+ n = tint32;
+ break;
}
if (n != next)
- deco = NULL;
+ deco = NULL;
next = n;
return merge();
}
@@ -2607,12 +2607,12 @@ void TypePointer::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
//printf("TypePointer::toCBuffer2() next = %d\n", next->ty);
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
next->toCBuffer2(buf, hgs, this->mod);
if (next->ty != Tfunction)
- buf->writeByte('*');
+ buf->writeByte('*');
}
MATCH TypePointer::implicitConvTo(Type *to)
@@ -2620,28 +2620,28 @@ MATCH TypePointer::implicitConvTo(Type *to)
//printf("TypePointer::implicitConvTo()\n");
if (this == to)
- return MATCHexact;
+ return MATCHexact;
if (to->ty == Tpointer && to->next)
{
- if (to->next->ty == Tvoid)
- return MATCHconvert;
+ if (to->next->ty == Tvoid)
+ return MATCHconvert;
#if 0
- if (to->next->isBaseOf(next))
- return MATCHconvert;
+ if (to->next->isBaseOf(next))
+ return MATCHconvert;
#endif
- if (next->ty == Tfunction && to->next->ty == Tfunction)
- { TypeFunction *tf;
- TypeFunction *tfto;
+ if (next->ty == Tfunction && to->next->ty == Tfunction)
+ { TypeFunction *tf;
+ TypeFunction *tfto;
- tf = (TypeFunction *)(next);
- tfto = (TypeFunction *)(to->next);
- return tfto->equals(tf) ? MATCHexact : MATCHnomatch;
- }
+ tf = (TypeFunction *)(next);
+ tfto = (TypeFunction *)(to->next);
+ return tfto->equals(tf) ? MATCHexact : MATCHnomatch;
+ }
}
// if (to->ty == Tvoid)
-// return MATCHconvert;
+// return MATCHconvert;
return MATCHnomatch;
}
@@ -2675,7 +2675,7 @@ TypeReference::TypeReference(Type *t)
: Type(Treference, t)
{
if (t->ty == Tbit)
- error(0,"cannot make reference to a bit");
+ error(0,"cannot make reference to a bit");
// BUG: what about references to static arrays?
}
@@ -2683,9 +2683,9 @@ Type *TypeReference::syntaxCopy()
{
Type *t = next->syntaxCopy();
if (t == next)
- t = this;
+ t = this;
else
- t = new TypeReference(t);
+ t = new TypeReference(t);
return t;
}
@@ -2697,8 +2697,8 @@ d_uns64 TypeReference::size(Loc loc)
void TypeReference::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
next->toCBuffer2(buf, hgs, this->mod);
buf->writeByte('&');
@@ -2755,11 +2755,11 @@ Type *TypeFunction::syntaxCopy()
/*******************************
* Returns:
- * 0 types are distinct
- * 1 this is covariant with t
- * 2 arguments match as far as overloading goes,
- * but types are not covariant
- * 3 cannot determine covariance because of forward references
+ * 0 types are distinct
+ * 1 this is covariant with t
+ * 2 arguments match as far as overloading goes,
+ * but types are not covariant
+ * 3 cannot determine covariance because of forward references
*/
int Type::covariant(Type *t)
@@ -2773,62 +2773,62 @@ int Type::covariant(Type *t)
int inoutmismatch = 0;
if (equals(t))
- goto Lcovariant;
+ goto Lcovariant;
if (ty != Tfunction || t->ty != Tfunction)
- goto Ldistinct;
+ goto Ldistinct;
{
TypeFunction *t1 = (TypeFunction *)this;
TypeFunction *t2 = (TypeFunction *)t;
if (t1->varargs != t2->varargs)
- goto Ldistinct;
+ goto Ldistinct;
if (t1->parameters && t2->parameters)
{
- size_t dim = Parameter::dim(t1->parameters);
- if (dim != Parameter::dim(t2->parameters))
- goto Ldistinct;
+ size_t dim = Parameter::dim(t1->parameters);
+ if (dim != Parameter::dim(t2->parameters))
+ goto Ldistinct;
- for (size_t i = 0; i < dim; i++)
- { Parameter *arg1 = Parameter::getNth(t1->parameters, i);
- Parameter *arg2 = Parameter::getNth(t2->parameters, i);
+ for (size_t i = 0; i < dim; i++)
+ { Parameter *arg1 = Parameter::getNth(t1->parameters, i);
+ Parameter *arg2 = Parameter::getNth(t2->parameters, i);
- if (!arg1->type->equals(arg2->type))
- goto Ldistinct;
- if (arg1->storageClass != arg2->storageClass)
- inoutmismatch = 1;
- }
+ if (!arg1->type->equals(arg2->type))
+ goto Ldistinct;
+ if (arg1->storageClass != arg2->storageClass)
+ inoutmismatch = 1;
+ }
}
else if (t1->parameters != t2->parameters)
- goto Ldistinct;
+ goto Ldistinct;
// The argument lists match
if (inoutmismatch)
- goto Lnotcovariant;
+ goto Lnotcovariant;
if (t1->linkage != t2->linkage)
- goto Lnotcovariant;
+ goto Lnotcovariant;
Type *t1n = t1->next;
Type *t2n = t2->next;
- if (!t1n || !t2n) // happens with return type inference
- goto Lnotcovariant;
+ if (!t1n || !t2n) // happens with return type inference
+ goto Lnotcovariant;
if (t1n->equals(t2n))
- goto Lcovariant;
+ goto Lcovariant;
if (t1n->ty != Tclass || t2n->ty != Tclass)
- goto Lnotcovariant;
+ goto Lnotcovariant;
// If t1n is forward referenced:
ClassDeclaration *cd = ((TypeClass *)t1n)->sym;
if (!cd->baseClass && cd->baseclasses.dim && !cd->isInterfaceDeclaration())
{
- return 3;
+ return 3;
}
if (t1n->implicitConvTo(t2n))
- goto Lcovariant;
+ goto Lcovariant;
goto Lnotcovariant;
}
@@ -2851,23 +2851,23 @@ void TypeFunction::toDecoBuffer(OutBuffer *buf, bool mangle)
//printf("TypeFunction::toDecoBuffer() this = %p %s\n", this, toChars());
//static int nest; if (++nest == 50) *(char*)0=0;
if (inuse)
- { inuse = 2; // flag error to caller
- return;
+ { inuse = 2; // flag error to caller
+ return;
}
inuse++;
switch (linkage)
{
- case LINKd: mc = 'F'; break;
- case LINKc: mc = 'U'; break;
- case LINKwindows: mc = 'W'; break;
- case LINKpascal: mc = 'V'; break;
- case LINKcpp: mc = 'R'; break;
+ case LINKd: mc = 'F'; break;
+ case LINKc: mc = 'U'; break;
+ case LINKwindows: mc = 'W'; break;
+ case LINKpascal: mc = 'V'; break;
+ case LINKcpp: mc = 'R'; break;
// LDC
case LINKintrinsic: mc = 'Q'; break;
- default:
- assert(0);
+ default:
+ assert(0);
}
buf->writeByte(mc);
@@ -2875,31 +2875,31 @@ void TypeFunction::toDecoBuffer(OutBuffer *buf, bool mangle)
// type to prevent merging different member function
if (!mangle && funcdecl)
{
- if (funcdecl->needThis())
- {
- AggregateDeclaration* ad = funcdecl->isMember2();
- buf->writeByte('M');
- ad->type->toDecoBuffer(buf, false);
- }
- /* BUG This causes problems with delegate types
- On the other hand, the llvm type for nested functions *is* different
- so not doing anything here may be lead to bugs!
- A sane solution would be DtoType(Dsymbol)...
- if (funcdecl->isNested())
- {
- buf->writeByte('M');
- if (funcdecl->toParent2() && funcdecl->toParent2()->isFuncDeclaration())
- {
- FuncDeclaration* fd = funcdecl->toParent2()->isFuncDeclaration();
- fd->type->toDecoBuffer(buf, false);
- }
- }*/
+ if (funcdecl->needThis())
+ {
+ AggregateDeclaration* ad = funcdecl->isMember2();
+ buf->writeByte('M');
+ ad->type->toDecoBuffer(buf, false);
+ }
+ /* BUG This causes problems with delegate types
+ On the other hand, the llvm type for nested functions *is* different
+ so not doing anything here may be lead to bugs!
+ A sane solution would be DtoType(Dsymbol)...
+ if (funcdecl->isNested())
+ {
+ buf->writeByte('M');
+ if (funcdecl->toParent2() && funcdecl->toParent2()->isFuncDeclaration())
+ {
+ FuncDeclaration* fd = funcdecl->toParent2()->isFuncDeclaration();
+ fd->type->toDecoBuffer(buf, false);
+ }
+ }*/
}
// Write argument types
Parameter::argsToDecoBuffer(buf, parameters, mangle);
//if (buf->data[buf->offset - 1] == '@') halt();
- buf->writeByte('Z' - varargs); // mark end of arg list
+ buf->writeByte('Z' - varargs); // mark end of arg list
next->toDecoBuffer(buf, mangle);
inuse--;
}
@@ -2909,35 +2909,35 @@ void TypeFunction::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs
const char *p = NULL;
if (inuse)
- { inuse = 2; // flag error to caller
- return;
+ { inuse = 2; // flag error to caller
+ return;
}
inuse++;
if (next && (!ident || ident->toHChars2() == ident->toChars()))
- next->toCBuffer2(buf, hgs, 0);
+ next->toCBuffer2(buf, hgs, 0);
if (hgs->ddoc != 1)
{
- switch (linkage)
- {
- case LINKd: p = NULL; break;
- case LINKc: p = "C "; break;
- case LINKwindows: p = "Windows "; break;
- case LINKpascal: p = "Pascal "; break;
- case LINKcpp: p = "C++ "; break;
+ switch (linkage)
+ {
+ case LINKd: p = NULL; break;
+ case LINKc: p = "C "; break;
+ case LINKwindows: p = "Windows "; break;
+ case LINKpascal: p = "Pascal "; break;
+ case LINKcpp: p = "C++ "; break;
// LDC
case LINKintrinsic: p = "Intrinsic"; break;
- default:
- assert(0);
- }
+ default:
+ assert(0);
+ }
}
if (!hgs->hdrgen && p)
- buf->writestring(p);
+ buf->writestring(p);
if (ident)
{ buf->writeByte(' ');
- buf->writestring(ident->toHChars2());
+ buf->writestring(ident->toHChars2());
}
Parameter::argsToCBuffer(buf, hgs, parameters, varargs);
inuse--;
@@ -2948,32 +2948,32 @@ void TypeFunction::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
const char *p = NULL;
if (inuse)
- { inuse = 2; // flag error to caller
- return;
+ { inuse = 2; // flag error to caller
+ return;
}
inuse++;
if (next)
- next->toCBuffer2(buf, hgs, 0);
+ next->toCBuffer2(buf, hgs, 0);
if (hgs->ddoc != 1)
{
- switch (linkage)
- {
- case LINKd: p = NULL; break;
- case LINKc: p = " C"; break;
- case LINKwindows: p = " Windows"; break;
- case LINKpascal: p = " Pascal"; break;
- case LINKcpp: p = " C++"; break;
+ switch (linkage)
+ {
+ case LINKd: p = NULL; break;
+ case LINKc: p = " C"; break;
+ case LINKwindows: p = " Windows"; break;
+ case LINKpascal: p = " Pascal"; break;
+ case LINKcpp: p = " C++"; break;
// LDC
case LINKintrinsic: p = "Intrinsic"; break;
- default:
- assert(0);
- }
+ default:
+ assert(0);
+ }
}
if (!hgs->hdrgen && p)
- buf->writestring(p);
+ buf->writestring(p);
buf->writestring(" function");
Parameter::argsToCBuffer(buf, hgs, parameters, varargs);
inuse--;
@@ -2981,10 +2981,10 @@ void TypeFunction::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
Type *TypeFunction::semantic(Loc loc, Scope *sc)
{
- if (deco) // if semantic() already run
+ if (deco) // if semantic() already run
{
- //printf("already done\n");
- return this;
+ //printf("already done\n");
+ return this;
}
//printf("TypeFunction::semantic() this = %p\n", this);
//printf("TypeFunction::semantic() %s, sc->stc = %x\n", toChars(), sc->stc);
@@ -2996,116 +2996,116 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
TypeFunction *tf = (TypeFunction *)mem.malloc(sizeof(TypeFunction));
memcpy(tf, this, sizeof(TypeFunction));
if (parameters)
- { tf->parameters = (Parameters *)parameters->copy();
- for (size_t i = 0; i < parameters->dim; i++)
- { Parameter *arg = (Parameter *)parameters->data[i];
- Parameter *cpy = (Parameter *)mem.malloc(sizeof(Parameter));
- memcpy(cpy, arg, sizeof(Parameter));
- tf->parameters->data[i] = (void *)cpy;
- }
+ { tf->parameters = (Parameters *)parameters->copy();
+ for (size_t i = 0; i < parameters->dim; i++)
+ { Parameter *arg = (Parameter *)parameters->data[i];
+ Parameter *cpy = (Parameter *)mem.malloc(sizeof(Parameter));
+ memcpy(cpy, arg, sizeof(Parameter));
+ tf->parameters->data[i] = (void *)cpy;
+ }
}
tf->linkage = sc->linkage;
if (tf->next)
{
- tf->next = tf->next->semantic(loc,sc);
+ tf->next = tf->next->semantic(loc,sc);
#if !SARRAYVALUE
- if (tf->next->toBasetype()->ty == Tsarray)
- { error(loc, "functions cannot return static array %s", tf->next->toChars());
- tf->next = Type::terror;
- }
+ if (tf->next->toBasetype()->ty == Tsarray)
+ { error(loc, "functions cannot return static array %s", tf->next->toChars());
+ tf->next = Type::terror;
+ }
#endif
- if (tf->next->toBasetype()->ty == Tfunction)
- { error(loc, "functions cannot return a function");
- tf->next = Type::terror;
- }
- if (tf->next->toBasetype()->ty == Ttuple)
- { error(loc, "functions cannot return a tuple");
- tf->next = Type::terror;
- }
- if (tf->next->isscope() && !(sc->flags & SCOPEctor))
- error(loc, "functions cannot return scope %s", tf->next->toChars());
+ if (tf->next->toBasetype()->ty == Tfunction)
+ { error(loc, "functions cannot return a function");
+ tf->next = Type::terror;
+ }
+ if (tf->next->toBasetype()->ty == Ttuple)
+ { error(loc, "functions cannot return a tuple");
+ tf->next = Type::terror;
+ }
+ if (tf->next->isscope() && !(sc->flags & SCOPEctor))
+ error(loc, "functions cannot return scope %s", tf->next->toChars());
}
if (tf->parameters)
{
- /* Create a scope for evaluating the default arguments for the parameters
- */
- Scope *argsc = sc->push();
- argsc->stc = 0; // don't inherit storage class
- argsc->protection = PROTpublic;
+ /* Create a scope for evaluating the default arguments for the parameters
+ */
+ Scope *argsc = sc->push();
+ argsc->stc = 0; // don't inherit storage class
+ argsc->protection = PROTpublic;
- size_t dim = Parameter::dim(tf->parameters);
- for (size_t i = 0; i < dim; i++)
- { Parameter *fparam = Parameter::getNth(tf->parameters, i);
+ size_t dim = Parameter::dim(tf->parameters);
+ for (size_t i = 0; i < dim; i++)
+ { Parameter *fparam = Parameter::getNth(tf->parameters, i);
- tf->inuse++;
- fparam->type = fparam->type->semantic(loc, argsc);
- if (tf->inuse == 1) tf->inuse--;
+ tf->inuse++;
+ fparam->type = fparam->type->semantic(loc, argsc);
+ if (tf->inuse == 1) tf->inuse--;
- // each function needs its own copy of a tuple arg, since
- // they mustn't share arg flags like inreg, ...
- if (fparam->type->ty == Ttuple) {
- fparam->type = fparam->type->syntaxCopy();
- tf->inuse++;
- fparam->type = fparam->type->semantic(loc,sc);
- if (tf->inuse == 1) tf->inuse--;
- }
+ // each function needs its own copy of a tuple arg, since
+ // they mustn't share arg flags like inreg, ...
+ if (fparam->type->ty == Ttuple) {
+ fparam->type = fparam->type->syntaxCopy();
+ tf->inuse++;
+ fparam->type = fparam->type->semantic(loc,sc);
+ if (tf->inuse == 1) tf->inuse--;
+ }
- Type *t = fparam->type->toBasetype();
+ Type *t = fparam->type->toBasetype();
- if (fparam->storageClass & (STCout | STCref | STClazy))
- {
- if (t->ty == Tsarray)
- error(loc, "cannot have out or ref parameter of type %s", t->toChars());
- }
- if (!(fparam->storageClass & STClazy) && t->ty == Tvoid)
- error(loc, "cannot have parameter of type %s", fparam->type->toChars());
+ if (fparam->storageClass & (STCout | STCref | STClazy))
+ {
+ if (t->ty == Tsarray)
+ error(loc, "cannot have out or ref parameter of type %s", t->toChars());
+ }
+ if (!(fparam->storageClass & STClazy) && t->ty == Tvoid)
+ error(loc, "cannot have parameter of type %s", fparam->type->toChars());
- if (fparam->defaultArg)
- {
- fparam->defaultArg = fparam->defaultArg->semantic(argsc);
- fparam->defaultArg = resolveProperties(argsc, fparam->defaultArg);
- fparam->defaultArg = fparam->defaultArg->implicitCastTo(argsc, fparam->type);
- }
+ if (fparam->defaultArg)
+ {
+ fparam->defaultArg = fparam->defaultArg->semantic(argsc);
+ fparam->defaultArg = resolveProperties(argsc, fparam->defaultArg);
+ fparam->defaultArg = fparam->defaultArg->implicitCastTo(argsc, fparam->type);
+ }
- /* If arg turns out to be a tuple, the number of parameters may
- * change.
- */
- if (t->ty == Ttuple)
- {
- // Propagate storage class from tuple parameters to their element-parameters.
- TypeTuple *tt = (TypeTuple *)t;
- if (tt->arguments)
- {
- size_t tdim = tt->arguments->dim;
- for (size_t j = 0; j < tdim; j++)
- { Parameter *narg = (Parameter *)tt->arguments->data[j];
- narg->storageClass = fparam->storageClass;
- }
- }
+ /* If arg turns out to be a tuple, the number of parameters may
+ * change.
+ */
+ if (t->ty == Ttuple)
+ {
+ // Propagate storage class from tuple parameters to their element-parameters.
+ TypeTuple *tt = (TypeTuple *)t;
+ if (tt->arguments)
+ {
+ size_t tdim = tt->arguments->dim;
+ for (size_t j = 0; j < tdim; j++)
+ { Parameter *narg = (Parameter *)tt->arguments->data[j];
+ narg->storageClass = fparam->storageClass;
+ }
+ }
- /* Reset number of parameters, and back up one to do this arg again,
- * now that it is the first element of a tuple
- */
- dim = Parameter::dim(tf->parameters);
- i--;
- continue;
- }
- }
- argsc->pop();
+ /* Reset number of parameters, and back up one to do this arg again,
+ * now that it is the first element of a tuple
+ */
+ dim = Parameter::dim(tf->parameters);
+ i--;
+ continue;
+ }
+ }
+ argsc->pop();
}
if (tf->next)
- tf->deco = tf->merge()->deco;
+ tf->deco = tf->merge()->deco;
if (tf->inuse)
- { error(loc, "recursive type");
- tf->inuse = 0;
- return terror;
+ { error(loc, "recursive type");
+ tf->inuse = 0;
+ return terror;
}
if (tf->varargs == 1 && tf->linkage != LINKd && Parameter::dim(tf->parameters) == 0)
- error(loc, "variadic functions with non-D linkage must have at least one parameter");
+ error(loc, "variadic functions with non-D linkage must have at least one parameter");
/* Don't return merge(), because arg identifiers and default args
* can be different
@@ -3118,113 +3118,113 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
* 'args' are being matched to function 'this'
* Determine match level.
* Returns:
- * MATCHxxxx
+ * MATCHxxxx
*/
int TypeFunction::callMatch(Expressions *args)
{
//printf("TypeFunction::callMatch()\n");
- int match = MATCHexact; // assume exact match
+ int match = MATCHexact; // assume exact match
size_t nparams = Parameter::dim(parameters);
size_t nargs = args ? args->dim : 0;
if (nparams == nargs)
- ;
+ ;
else if (nargs > nparams)
{
- if (varargs == 0)
- goto Nomatch; // too many args; no match
- match = MATCHconvert; // match ... with a "conversion" match level
+ if (varargs == 0)
+ goto Nomatch; // too many args; no match
+ match = MATCHconvert; // match ... with a "conversion" match level
}
for (size_t u = 0; u < nparams; u++)
- { int m;
- Expression *arg;
+ { int m;
+ Expression *arg;
- // BUG: what about out and ref?
+ // BUG: what about out and ref?
- Parameter *p = Parameter::getNth(parameters, u);
- assert(p);
- if (u >= nargs)
- {
- if (p->defaultArg)
- continue;
- if (varargs == 2 && u + 1 == nparams)
- goto L1;
- goto Nomatch; // not enough arguments
- }
- arg = (Expression *)args->data[u];
- assert(arg);
- if (p->storageClass & STClazy && p->type->ty == Tvoid && arg->type->ty != Tvoid)
- m = MATCHconvert;
- else
- m = arg->implicitConvTo(p->type);
- //printf("\tm = %d\n", m);
- if (m == MATCHnomatch) // if no match
- {
- L1:
- if (varargs == 2 && u + 1 == nparams) // if last varargs param
- { Type *tb = p->type->toBasetype();
- TypeSArray *tsa;
- dinteger_t sz;
+ Parameter *p = Parameter::getNth(parameters, u);
+ assert(p);
+ if (u >= nargs)
+ {
+ if (p->defaultArg)
+ continue;
+ if (varargs == 2 && u + 1 == nparams)
+ goto L1;
+ goto Nomatch; // not enough arguments
+ }
+ arg = (Expression *)args->data[u];
+ assert(arg);
+ if (p->storageClass & STClazy && p->type->ty == Tvoid && arg->type->ty != Tvoid)
+ m = MATCHconvert;
+ else
+ m = arg->implicitConvTo(p->type);
+ //printf("\tm = %d\n", m);
+ if (m == MATCHnomatch) // if no match
+ {
+ L1:
+ if (varargs == 2 && u + 1 == nparams) // if last varargs param
+ { Type *tb = p->type->toBasetype();
+ TypeSArray *tsa;
+ dinteger_t sz;
- switch (tb->ty)
- {
- case Tsarray:
- tsa = (TypeSArray *)tb;
- sz = tsa->dim->toInteger();
- if (sz != nargs - u)
- goto Nomatch;
- case Tarray:
- for (; u < nargs; u++)
- {
- arg = (Expression *)args->data[u];
- assert(arg);
+ switch (tb->ty)
+ {
+ case Tsarray:
+ tsa = (TypeSArray *)tb;
+ sz = tsa->dim->toInteger();
+ if (sz != nargs - u)
+ goto Nomatch;
+ case Tarray:
+ for (; u < nargs; u++)
+ {
+ arg = (Expression *)args->data[u];
+ assert(arg);
#if 1
- /* If lazy array of delegates,
- * convert arg(s) to delegate(s)
- */
- Type *tret = p->isLazyArray();
- if (tret)
- {
- if (tb->next->equals(arg->type))
- { m = MATCHexact;
- }
- else
- {
- m = arg->implicitConvTo(tret);
- if (m == MATCHnomatch)
- {
- if (tret->toBasetype()->ty == Tvoid)
- m = MATCHconvert;
- }
- }
- }
- else
- m = arg->implicitConvTo(tb->next);
+ /* If lazy array of delegates,
+ * convert arg(s) to delegate(s)
+ */
+ Type *tret = p->isLazyArray();
+ if (tret)
+ {
+ if (tb->next->equals(arg->type))
+ { m = MATCHexact;
+ }
+ else
+ {
+ m = arg->implicitConvTo(tret);
+ if (m == MATCHnomatch)
+ {
+ if (tret->toBasetype()->ty == Tvoid)
+ m = MATCHconvert;
+ }
+ }
+ }
+ else
+ m = arg->implicitConvTo(tb->next);
#else
- m = arg->implicitConvTo(tb->next);
+ m = arg->implicitConvTo(tb->next);
#endif
- if (m == 0)
- goto Nomatch;
- if (m < match)
- match = m;
- }
- goto Ldone;
+ if (m == 0)
+ goto Nomatch;
+ if (m < match)
+ match = m;
+ }
+ goto Ldone;
- case Tclass:
- // Should see if there's a constructor match?
- // Or just leave it ambiguous?
- goto Ldone;
+ case Tclass:
+ // Should see if there's a constructor match?
+ // Or just leave it ambiguous?
+ goto Ldone;
- default:
- goto Nomatch;
- }
- }
- goto Nomatch;
- }
- if (m < match)
- match = m; // pick worst match
+ default:
+ goto Nomatch;
+ }
+ }
+ goto Nomatch;
+ }
+ if (m < match)
+ match = m; // pick worst match
}
Ldone:
@@ -3240,12 +3240,12 @@ Type *TypeFunction::reliesOnTident()
{
if (parameters)
{
- for (size_t i = 0; i < parameters->dim; i++)
- { Parameter *arg = (Parameter *)parameters->data[i];
- Type *t = arg->type->reliesOnTident();
- if (t)
- return t;
- }
+ for (size_t i = 0; i < parameters->dim; i++)
+ { Parameter *arg = (Parameter *)parameters->data[i];
+ Type *t = arg->type->reliesOnTident();
+ if (t)
+ return t;
+ }
}
return next->reliesOnTident();
}
@@ -3262,18 +3262,18 @@ Type *TypeDelegate::syntaxCopy()
{
Type *t = next->syntaxCopy();
if (t == next)
- t = this;
+ t = this;
else
- t = new TypeDelegate(t);
+ t = new TypeDelegate(t);
return t;
}
Type *TypeDelegate::semantic(Loc loc, Scope *sc)
{
- if (deco) // if semantic() already run
+ if (deco) // if semantic() already run
{
- //printf("already done\n");
- return this;
+ //printf("already done\n");
+ return this;
}
next = next->semantic(loc,sc);
return merge();
@@ -3295,8 +3295,8 @@ unsigned TypeDelegate::alignsize()
void TypeDelegate::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
TypeFunction *tf = (TypeFunction *)next;
@@ -3331,18 +3331,18 @@ Expression *TypeDelegate::dotExp(Scope *sc, Expression *e, Identifier *ident)
if (ident == Id::ptr)
{
e = new GEPExp(e->loc, e, ident, 0);
- e->type = tvoidptr;
- return e;
+ e->type = tvoidptr;
+ return e;
}
else if (ident == Id::funcptr)
{
e = new GEPExp(e->loc, e, ident, 1);
e->type = tvoidptr;
- return e;
+ return e;
}
else
{
- e = Type::dotExp(sc, e, ident);
+ e = Type::dotExp(sc, e, ident);
}
return e;
}
@@ -3368,15 +3368,15 @@ void TypeQualified::syntaxCopyHelper(TypeQualified *t)
idents.setDim(t->idents.dim);
for (int i = 0; i < idents.dim; i++)
{
- Identifier *id = (Identifier *)t->idents.data[i];
- if (id->dyncast() == DYNCAST_DSYMBOL)
- {
- TemplateInstance *ti = (TemplateInstance *)id;
+ Identifier *id = (Identifier *)t->idents.data[i];
+ if (id->dyncast() == DYNCAST_DSYMBOL)
+ {
+ TemplateInstance *ti = (TemplateInstance *)id;
- ti = (TemplateInstance *)ti->syntaxCopy(NULL);
- id = (Identifier *)ti;
- }
- idents.data[i] = id;
+ ti = (TemplateInstance *)ti->syntaxCopy(NULL);
+ id = (Identifier *)ti;
+ }
+ idents.data[i] = id;
}
}
@@ -3391,17 +3391,17 @@ void TypeQualified::toCBuffer2Helper(OutBuffer *buf, HdrGenState *hgs)
int i;
for (i = 0; i < idents.dim; i++)
- { Identifier *id = (Identifier *)idents.data[i];
+ { Identifier *id = (Identifier *)idents.data[i];
- buf->writeByte('.');
+ buf->writeByte('.');
- if (id->dyncast() == DYNCAST_DSYMBOL)
- {
- TemplateInstance *ti = (TemplateInstance *)id;
- ti->toCBuffer(buf, hgs);
- }
- else
- buf->writestring(id->toChars());
+ if (id->dyncast() == DYNCAST_DSYMBOL)
+ {
+ TemplateInstance *ti = (TemplateInstance *)id;
+ ti->toCBuffer(buf, hgs);
+ }
+ else
+ buf->writestring(id->toChars());
}
}
@@ -3415,13 +3415,13 @@ d_uns64 TypeQualified::size(Loc loc)
* Takes an array of Identifiers and figures out if
* it represents a Type or an Expression.
* Output:
- * if expression, *pe is set
- * if type, *pt is set
+ * if expression, *pe is set
+ * if type, *pt is set
*/
void TypeQualified::resolveHelper(Loc loc, Scope *sc,
- Dsymbol *s, Dsymbol *scopesym,
- Expression **pe, Type **pt, Dsymbol **ps)
+ Dsymbol *s, Dsymbol *scopesym,
+ Expression **pe, Type **pt, Dsymbol **ps)
{
Identifier *id = NULL;
int i;
@@ -3434,181 +3434,181 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
#if 0
printf("TypeQualified::resolveHelper(sc = %p, idents = '%s')\n", sc, toChars());
if (scopesym)
- printf("\tscopesym = '%s'\n", scopesym->toChars());
+ printf("\tscopesym = '%s'\n", scopesym->toChars());
#endif
*pe = NULL;
*pt = NULL;
*ps = NULL;
if (s)
{
- //printf("\t1: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
- s->checkDeprecated(loc, sc); // check for deprecated aliases
- s = s->toAlias();
- //printf("\t2: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
- for (i = 0; i < idents.dim; i++)
- { Dsymbol *sm;
+ //printf("\t1: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
+ s->checkDeprecated(loc, sc); // check for deprecated aliases
+ s = s->toAlias();
+ //printf("\t2: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
+ for (i = 0; i < idents.dim; i++)
+ { Dsymbol *sm;
- id = (Identifier *)idents.data[i];
- sm = s->searchX(loc, sc, id);
- //printf("\t3: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
- //printf("getType = '%s'\n", s->getType()->toChars());
- if (!sm)
- {
- v = s->isVarDeclaration();
- if (v && id == Id::length)
- {
- if (v->isSameAsInitializer() && v->getExpInitializer())
- { e = v->getExpInitializer()->exp;
- }
- else
- e = new VarExp(loc, v);
- t = e->type;
- if (!t)
- goto Lerror;
- goto L3;
- }
- else if (v && id == Id::stringof)
- {
- e = new DsymbolExp(loc, s);
- do
- {
- id = (Identifier *)idents.data[i];
- e = new DotIdExp(loc, e, id);
- } while (++i < idents.dim);
- e = e->semantic(sc);
- *pe = e;
- return;
- }
+ id = (Identifier *)idents.data[i];
+ sm = s->searchX(loc, sc, id);
+ //printf("\t3: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
+ //printf("getType = '%s'\n", s->getType()->toChars());
+ if (!sm)
+ {
+ v = s->isVarDeclaration();
+ if (v && id == Id::length)
+ {
+ if (v->isSameAsInitializer() && v->getExpInitializer())
+ { e = v->getExpInitializer()->exp;
+ }
+ else
+ e = new VarExp(loc, v);
+ t = e->type;
+ if (!t)
+ goto Lerror;
+ goto L3;
+ }
+ else if (v && id == Id::stringof)
+ {
+ e = new DsymbolExp(loc, s);
+ do
+ {
+ id = (Identifier *)idents.data[i];
+ e = new DotIdExp(loc, e, id);
+ } while (++i < idents.dim);
+ e = e->semantic(sc);
+ *pe = e;
+ return;
+ }
- t = s->getType();
- if (!t && s->isDeclaration())
- t = s->isDeclaration()->type;
- if (t)
- {
- sm = t->toDsymbol(sc);
- if (sm)
- { sm = sm->search(loc, id, 0);
- if (sm)
- goto L2;
- }
- //e = t->getProperty(loc, id);
- e = new TypeExp(loc, t);
- e = t->dotExp(sc, e, id);
- i++;
- L3:
- for (; i < idents.dim; i++)
- {
- id = (Identifier *)idents.data[i];
- //printf("e: '%s', id: '%s', type = %p\n", e->toChars(), id->toChars(), e->type);
- e = e->type->dotExp(sc, e, id);
- }
- *pe = e;
- }
- else
- Lerror:
- error(loc, "identifier '%s' of '%s' is not defined", id->toChars(), toChars());
- return;
- }
- L2:
- s = sm->toAlias();
- }
+ t = s->getType();
+ if (!t && s->isDeclaration())
+ t = s->isDeclaration()->type;
+ if (t)
+ {
+ sm = t->toDsymbol(sc);
+ if (sm)
+ { sm = sm->search(loc, id, 0);
+ if (sm)
+ goto L2;
+ }
+ //e = t->getProperty(loc, id);
+ e = new TypeExp(loc, t);
+ e = t->dotExp(sc, e, id);
+ i++;
+ L3:
+ for (; i < idents.dim; i++)
+ {
+ id = (Identifier *)idents.data[i];
+ //printf("e: '%s', id: '%s', type = %p\n", e->toChars(), id->toChars(), e->type);
+ e = e->type->dotExp(sc, e, id);
+ }
+ *pe = e;
+ }
+ else
+ Lerror:
+ error(loc, "identifier '%s' of '%s' is not defined", id->toChars(), toChars());
+ return;
+ }
+ L2:
+ s = sm->toAlias();
+ }
- v = s->isVarDeclaration();
- if (v)
- {
- // It's not a type, it's an expression
- if (v->isSameAsInitializer() && v->getExpInitializer())
- {
- ExpInitializer *ei = v->getExpInitializer();
- assert(ei);
- *pe = ei->exp->copy(); // make copy so we can change loc
- (*pe)->loc = loc;
- }
- else
- {
+ v = s->isVarDeclaration();
+ if (v)
+ {
+ // It's not a type, it's an expression
+ if (v->isSameAsInitializer() && v->getExpInitializer())
+ {
+ ExpInitializer *ei = v->getExpInitializer();
+ assert(ei);
+ *pe = ei->exp->copy(); // make copy so we can change loc
+ (*pe)->loc = loc;
+ }
+ else
+ {
#if 0
- WithScopeSymbol *withsym;
- if (scopesym && (withsym = scopesym->isWithScopeSymbol()) != NULL)
- {
- // Same as wthis.ident
- e = new VarExp(loc, withsym->withstate->wthis);
- e = new DotIdExp(loc, e, ident);
- //assert(0); // BUG: should handle this
- }
- else
+ WithScopeSymbol *withsym;
+ if (scopesym && (withsym = scopesym->isWithScopeSymbol()) != NULL)
+ {
+ // Same as wthis.ident
+ e = new VarExp(loc, withsym->withstate->wthis);
+ e = new DotIdExp(loc, e, ident);
+ //assert(0); // BUG: should handle this
+ }
+ else
#endif
- *pe = new VarExp(loc, v);
- }
- return;
- }
- em = s->isEnumMember();
- if (em)
- {
- // It's not a type, it's an expression
- *pe = em->value->copy();
- return;
- }
+ *pe = new VarExp(loc, v);
+ }
+ return;
+ }
+ em = s->isEnumMember();
+ if (em)
+ {
+ // It's not a type, it's an expression
+ *pe = em->value->copy();
+ return;
+ }
L1:
- t = s->getType();
- if (!t)
- {
- // If the symbol is an import, try looking inside the import
- Import *si;
+ t = s->getType();
+ if (!t)
+ {
+ // If the symbol is an import, try looking inside the import
+ Import *si;
- si = s->isImport();
- if (si)
- {
- s = si->search(loc, s->ident, 0);
- if (s && s != si)
- goto L1;
- s = si;
- }
- *ps = s;
- return;
- }
- if (t->ty == Tinstance && t != this && !t->deco)
- { error(loc, "forward reference to '%s'", t->toChars());
- return;
- }
+ si = s->isImport();
+ if (si)
+ {
+ s = si->search(loc, s->ident, 0);
+ if (s && s != si)
+ goto L1;
+ s = si;
+ }
+ *ps = s;
+ return;
+ }
+ if (t->ty == Tinstance && t != this && !t->deco)
+ { error(loc, "forward reference to '%s'", t->toChars());
+ return;
+ }
- if (t != this)
- {
- if (t->reliesOnTident())
- {
- if (s->scope)
- t = t->semantic(loc, s->scope);
- else
- {
- /* Attempt to find correct scope in which to evaluate t.
- * Not sure if this is right or not, or if we should just
- * give forward reference error if s->scope is not set.
- */
- for (Scope *scx = sc; 1; scx = scx->enclosing)
- {
- if (!scx)
- { error(loc, "forward reference to '%s'", t->toChars());
- return;
- }
- if (scx->scopesym == scopesym)
- {
- t = t->semantic(loc, scx);
- break;
- }
- }
- }
- }
- }
- if (t->ty == Ttuple)
- *pt = t;
- else if (t->ty == Ttypeof)
- *pt = t->semantic(loc, sc);
- else
- *pt = t->merge();
+ if (t != this)
+ {
+ if (t->reliesOnTident())
+ {
+ if (s->scope)
+ t = t->semantic(loc, s->scope);
+ else
+ {
+ /* Attempt to find correct scope in which to evaluate t.
+ * Not sure if this is right or not, or if we should just
+ * give forward reference error if s->scope is not set.
+ */
+ for (Scope *scx = sc; 1; scx = scx->enclosing)
+ {
+ if (!scx)
+ { error(loc, "forward reference to '%s'", t->toChars());
+ return;
+ }
+ if (scx->scopesym == scopesym)
+ {
+ t = t->semantic(loc, scx);
+ break;
+ }
+ }
+ }
+ }
+ }
+ if (t->ty == Ttuple)
+ *pt = t;
+ else if (t->ty == Ttypeof)
+ *pt = t->semantic(loc, sc);
+ else
+ *pt = t->merge();
}
if (!s)
{
- error(loc, "identifier '%s' is not defined", toChars());
+ error(loc, "identifier '%s' is not defined", toChars());
}
}
@@ -3643,8 +3643,8 @@ void TypeIdentifier::toDecoBuffer(OutBuffer *buf, bool mangle)
void TypeIdentifier::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
buf->writestring(this->ident->toChars());
toCBuffer2Helper(buf, hgs);
@@ -3654,8 +3654,8 @@ void TypeIdentifier::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
* Takes an array of Identifiers and figures out if
* it represents a Type or an Expression.
* Output:
- * if expression, *pe is set
- * if type, *pt is set
+ * if expression, *pe is set
+ * if type, *pt is set
*/
void TypeIdentifier::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps)
@@ -3676,22 +3676,22 @@ Dsymbol *TypeIdentifier::toDsymbol(Scope *sc)
{
//printf("TypeIdentifier::toDsymbol('%s')\n", toChars());
if (!sc)
- return NULL;
+ return NULL;
//printf("ident = '%s'\n", ident->toChars());
Dsymbol *scopesym;
Dsymbol *s = sc->search(loc, ident, &scopesym);
if (s)
{
- for (int i = 0; i < idents.dim; i++)
- {
- Identifier *id = (Identifier *)idents.data[i];
- s = s->searchX(loc, sc, id);
- if (!s) // failed to find a symbol
- { //printf("\tdidn't find a symbol\n");
- break;
- }
- }
+ for (int i = 0; i < idents.dim; i++)
+ {
+ Identifier *id = (Identifier *)idents.data[i];
+ s = s->searchX(loc, sc, id);
+ if (!s) // failed to find a symbol
+ { //printf("\tdidn't find a symbol\n");
+ break;
+ }
+ }
}
return s;
}
@@ -3706,28 +3706,28 @@ Type *TypeIdentifier::semantic(Loc loc, Scope *sc)
resolve(loc, sc, &e, &t, &s);
if (t)
{
- //printf("\tit's a type %d, %s, %s\n", t->ty, t->toChars(), t->deco);
+ //printf("\tit's a type %d, %s, %s\n", t->ty, t->toChars(), t->deco);
- if (t->ty == Ttypedef)
- { TypeTypedef *tt = (TypeTypedef *)t;
+ if (t->ty == Ttypedef)
+ { TypeTypedef *tt = (TypeTypedef *)t;
- if (tt->sym->sem == 1)
- error(loc, "circular reference of typedef %s", tt->toChars());
- }
+ if (tt->sym->sem == 1)
+ error(loc, "circular reference of typedef %s", tt->toChars());
+ }
}
else
{
#ifdef DEBUG
- if (!global.gag)
- printf("1: ");
+ if (!global.gag)
+ printf("1: ");
#endif
- if (s)
- {
- s->error(loc, "is used as a type");
- }
- else
- error(loc, "%s is used as a type", toChars());
- t = tvoid;
+ if (s)
+ {
+ s->error(loc, "is used as a type");
+ }
+ else
+ error(loc, "%s is used as a type", toChars());
+ t = tvoid;
}
//t->print();
return t;
@@ -3743,8 +3743,8 @@ Expression *TypeIdentifier::toExpression()
Expression *e = new IdentifierExp(loc, ident);
for (int i = 0; i < idents.dim; i++)
{
- Identifier *id = (Identifier *)idents.data[i];
- e = new DotIdExp(loc, e, id);
+ Identifier *id = (Identifier *)idents.data[i];
+ e = new DotIdExp(loc, e, id);
}
return e;
@@ -3772,8 +3772,8 @@ Type *TypeInstance::syntaxCopy()
void TypeInstance::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
tempinst->toCBuffer(buf, hgs);
toCBuffer2Helper(buf, hgs);
@@ -3792,15 +3792,15 @@ void TypeInstance::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymb
#if 0
if (!idents.dim)
{
- error(loc, "template instance '%s' has no identifier", toChars());
- return;
+ error(loc, "template instance '%s' has no identifier", toChars());
+ return;
}
#endif
//id = (Identifier *)idents.data[0];
//printf("TypeInstance::resolve(sc = %p, idents = '%s')\n", sc, id->toChars());
s = tempinst;
if (s)
- s->semantic(sc);
+ s->semantic(sc);
resolveHelper(loc, sc, s, NULL, pe, pt, ps);
//printf("pt = '%s'\n", (*pt)->toChars());
}
@@ -3815,29 +3815,29 @@ Type *TypeInstance::semantic(Loc loc, Scope *sc)
if (sc->parameterSpecialization)
{
- unsigned errors = global.errors;
- global.gag++;
+ unsigned errors = global.errors;
+ global.gag++;
- resolve(loc, sc, &e, &t, &s);
+ resolve(loc, sc, &e, &t, &s);
- global.gag--;
- if (errors != global.errors)
- { if (global.gag == 0)
- global.errors = errors;
- return this;
- }
+ global.gag--;
+ if (errors != global.errors)
+ { if (global.gag == 0)
+ global.errors = errors;
+ return this;
+ }
}
else
- resolve(loc, sc, &e, &t, &s);
+ resolve(loc, sc, &e, &t, &s);
if (!t)
{
#ifdef DEBUG
- if (s) printf("s = %s\n", s->kind());
- printf("2: e:%p s:%p ", e, s);
+ if (s) printf("s = %s\n", s->kind());
+ printf("2: e:%p s:%p ", e, s);
#endif
- error(loc, "%s is used as a type", toChars());
- t = tvoid;
+ error(loc, "%s is used as a type", toChars());
+ t = tvoid;
}
return t;
}
@@ -3852,20 +3852,20 @@ Dsymbol *TypeInstance::toDsymbol(Scope *sc)
if (sc->parameterSpecialization)
{
- unsigned errors = global.errors;
- global.gag++;
+ unsigned errors = global.errors;
+ global.gag++;
- resolve(loc, sc, &e, &t, &s);
+ resolve(loc, sc, &e, &t, &s);
- global.gag--;
- if (errors != global.errors)
- { if (global.gag == 0)
- global.errors = errors;
- return NULL;
- }
+ global.gag--;
+ if (errors != global.errors)
+ { if (global.gag == 0)
+ global.errors = errors;
+ return NULL;
+ }
}
else
- resolve(loc, sc, &e, &t, &s);
+ resolve(loc, sc, &e, &t, &s);
return s;
}
@@ -3874,7 +3874,7 @@ Dsymbol *TypeInstance::toDsymbol(Scope *sc)
/***************************** TypeTypeof *****************************/
TypeTypeof::TypeTypeof(Loc loc, Expression *exp)
- : TypeQualified(Ttypeof, loc)
+ : TypeQualified(Ttypeof, loc)
{
this->exp = exp;
}
@@ -3895,15 +3895,15 @@ Dsymbol *TypeTypeof::toDsymbol(Scope *sc)
t = semantic(loc, sc);
if (t == this)
- return NULL;
+ return NULL;
return t->toDsymbol(sc);
}
void TypeTypeof::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
buf->writestring("typeof(");
exp->toCBuffer(buf, hgs);
@@ -3930,89 +3930,89 @@ Type *TypeTypeof::semantic(Loc loc, Scope *sc)
*/
if (exp->op == TOKthis || exp->op == TOKsuper)
{
- // Find enclosing struct or class
- for (Dsymbol *s = sc->parent; 1; s = s->parent)
- {
- ClassDeclaration *cd;
- StructDeclaration *sd;
+ // Find enclosing struct or class
+ for (Dsymbol *s = sc->parent; 1; s = s->parent)
+ {
+ ClassDeclaration *cd;
+ StructDeclaration *sd;
- if (!s)
- {
- error(loc, "%s is not in a struct or class scope", exp->toChars());
- goto Lerr;
- }
- cd = s->isClassDeclaration();
- if (cd)
- {
- if (exp->op == TOKsuper)
- {
- cd = cd->baseClass;
- if (!cd)
- { error(loc, "class %s has no 'super'", s->toChars());
- goto Lerr;
- }
- }
- t = cd->type;
- break;
- }
- sd = s->isStructDeclaration();
- if (sd)
- {
- if (exp->op == TOKsuper)
- {
- error(loc, "struct %s has no 'super'", sd->toChars());
- goto Lerr;
- }
- t = sd->type->pointerTo();
- break;
- }
- }
+ if (!s)
+ {
+ error(loc, "%s is not in a struct or class scope", exp->toChars());
+ goto Lerr;
+ }
+ cd = s->isClassDeclaration();
+ if (cd)
+ {
+ if (exp->op == TOKsuper)
+ {
+ cd = cd->baseClass;
+ if (!cd)
+ { error(loc, "class %s has no 'super'", s->toChars());
+ goto Lerr;
+ }
+ }
+ t = cd->type;
+ break;
+ }
+ sd = s->isStructDeclaration();
+ if (sd)
+ {
+ if (exp->op == TOKsuper)
+ {
+ error(loc, "struct %s has no 'super'", sd->toChars());
+ goto Lerr;
+ }
+ t = sd->type->pointerTo();
+ break;
+ }
+ }
}
else
#endif
{
- sc->intypeof++;
- exp = exp->semantic(sc);
- sc->intypeof--;
- if (exp->op == TOKtype)
- {
- error(loc, "argument %s to typeof is not an expression", exp->toChars());
- goto Lerr;
- }
- t = exp->type;
- if (!t)
- {
- error(loc, "expression (%s) has no type", exp->toChars());
- goto Lerr;
- }
- if (t->ty == Ttypeof)
- { error(loc, "forward reference to %s", toChars());
- goto Lerr;
- }
+ sc->intypeof++;
+ exp = exp->semantic(sc);
+ sc->intypeof--;
+ if (exp->op == TOKtype)
+ {
+ error(loc, "argument %s to typeof is not an expression", exp->toChars());
+ goto Lerr;
+ }
+ t = exp->type;
+ if (!t)
+ {
+ error(loc, "expression (%s) has no type", exp->toChars());
+ goto Lerr;
+ }
+ if (t->ty == Ttypeof)
+ { error(loc, "forward reference to %s", toChars());
+ goto Lerr;
+ }
}
if (idents.dim)
{
- Dsymbol *s = t->toDsymbol(sc);
- for (size_t i = 0; i < idents.dim; i++)
- {
- if (!s)
- break;
- Identifier *id = (Identifier *)idents.data[i];
- s = s->searchX(loc, sc, id);
- }
- if (s)
- {
- t = s->getType();
- if (!t)
- { error(loc, "%s is not a type", s->toChars());
- goto Lerr;
- }
- }
- else
- { error(loc, "cannot resolve .property for %s", toChars());
- goto Lerr;
- }
+ Dsymbol *s = t->toDsymbol(sc);
+ for (size_t i = 0; i < idents.dim; i++)
+ {
+ if (!s)
+ break;
+ Identifier *id = (Identifier *)idents.data[i];
+ s = s->searchX(loc, sc, id);
+ }
+ if (s)
+ {
+ t = s->getType();
+ if (!t)
+ { error(loc, "%s is not a type", s->toChars());
+ goto Lerr;
+ }
+ }
+ else
+ { error(loc, "cannot resolve .property for %s", toChars());
+ goto Lerr;
+ }
}
return t;
@@ -4023,9 +4023,9 @@ Lerr:
d_uns64 TypeTypeof::size(Loc loc)
{
if (exp->type)
- return exp->type->size(loc);
+ return exp->type->size(loc);
else
- return TypeQualified::size(loc);
+ return TypeQualified::size(loc);
}
@@ -4033,7 +4033,7 @@ d_uns64 TypeTypeof::size(Loc loc)
/***************************** TypeEnum *****************************/
TypeEnum::TypeEnum(EnumDeclaration *sym)
- : Type(Tenum, NULL)
+ : Type(Tenum, NULL)
{
this->sym = sym;
}
@@ -4058,8 +4058,8 @@ d_uns64 TypeEnum::size(Loc loc)
{
if (!sym->memtype)
{
- error(loc, "enum %s is forward referenced", sym->toChars());
- return 4;
+ error(loc, "enum %s is forward referenced", sym->toChars());
+ return 4;
}
return sym->memtype->size(loc);
}
@@ -4069,10 +4069,10 @@ unsigned TypeEnum::alignsize()
if (!sym->memtype)
{
#ifdef DEBUG
- printf("1: ");
+ printf("1: ");
#endif
- error(0, "enum %s is forward referenced", sym->toChars());
- return 4;
+ error(0, "enum %s is forward referenced", sym->toChars());
+ return 4;
}
return sym->memtype->alignsize();
}
@@ -4085,23 +4085,23 @@ Dsymbol *TypeEnum::toDsymbol(Scope *sc)
Type *TypeEnum::toBasetype()
{
if (sym->scope)
- { // Enum is forward referenced. We don't need to resolve the whole thing,
- // just the base type
- if (sym->memtype)
- { sym->memtype = sym->memtype->semantic(sym->loc, sym->scope);
- }
- else
- { if (!sym->isAnonymous())
- sym->memtype = Type::tint32;
- }
+ { // Enum is forward referenced. We don't need to resolve the whole thing,
+ // just the base type
+ if (sym->memtype)
+ { sym->memtype = sym->memtype->semantic(sym->loc, sym->scope);
+ }
+ else
+ { if (!sym->isAnonymous())
+ sym->memtype = Type::tint32;
+ }
}
if (!sym->memtype)
{
#ifdef DEBUG
- printf("2: ");
+ printf("2: ");
#endif
- error(sym->loc, "enum %s is forward referenced", sym->toChars());
- return terror;
+ error(sym->loc, "enum %s is forward referenced", sym->toChars());
+ return terror;
}
return sym->memtype->toBasetype();
}
@@ -4111,15 +4111,15 @@ void TypeEnum::toDecoBuffer(OutBuffer *buf, bool mangle)
name = sym->mangle();
// if (name[0] == '_' && name[1] == 'D')
-// name += 2;
+// name += 2;
buf->printf("%c%s", mangleChar[ty], name);
}
void TypeEnum::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
buf->writestring(sym->toChars());
}
@@ -4134,20 +4134,20 @@ Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident)
printf("TypeEnum::dotExp(e = '%s', ident = '%s') '%s'\n", e->toChars(), ident->toChars(), toChars());
#endif
if (!sym->symtab)
- goto Lfwd;
+ goto Lfwd;
s = sym->symtab->lookup(ident);
if (!s)
{
- if (ident == Id::max ||
- ident == Id::min ||
- ident == Id::init ||
- ident == Id::stringof ||
- !sym->memtype
- )
- {
- return getProperty(e->loc, ident);
- }
- return sym->memtype->dotExp(sc, e, ident);
+ if (ident == Id::max ||
+ ident == Id::min ||
+ ident == Id::init ||
+ ident == Id::stringof ||
+ !sym->memtype
+ )
+ {
+ return getProperty(e->loc, ident);
+ }
+ return sym->memtype->dotExp(sc, e, ident);
}
m = s->isEnumMember();
em = m->value->copy();
@@ -4164,33 +4164,33 @@ Expression *TypeEnum::getProperty(Loc loc, Identifier *ident)
if (ident == Id::max)
{
- if (!sym->symtab)
- goto Lfwd;
- e = new IntegerExp(0, sym->maxval, this);
+ if (!sym->symtab)
+ goto Lfwd;
+ e = new IntegerExp(0, sym->maxval, this);
}
else if (ident == Id::min)
{
- if (!sym->symtab)
- goto Lfwd;
- e = new IntegerExp(0, sym->minval, this);
+ if (!sym->symtab)
+ goto Lfwd;
+ e = new IntegerExp(0, sym->minval, this);
}
else if (ident == Id::init)
{
- if (!sym->symtab)
- goto Lfwd;
- e = defaultInit(loc);
+ if (!sym->symtab)
+ goto Lfwd;
+ e = defaultInit(loc);
}
else if (ident == Id::stringof)
- { char *s = toChars();
- e = new StringExp(loc, s, strlen(s), 'c');
- Scope sc;
- e = e->semantic(&sc);
+ { char *s = toChars();
+ e = new StringExp(loc, s, strlen(s), 'c');
+ Scope sc;
+ e = e->semantic(&sc);
}
else
{
- if (!sym->memtype)
- goto Lfwd;
- e = sym->memtype->getProperty(loc, ident);
+ if (!sym->memtype)
+ goto Lfwd;
+ e = sym->memtype->getProperty(loc, ident);
}
return e;
@@ -4225,11 +4225,11 @@ MATCH TypeEnum::implicitConvTo(Type *to)
//printf("TypeEnum::implicitConvTo()\n");
if (this->equals(to))
- m = MATCHexact; // exact match
+ m = MATCHexact; // exact match
else if (sym->memtype->implicitConvTo(to))
- m = MATCHconvert; // match with conversions
+ m = MATCHconvert; // match with conversions
else
- m = MATCHnomatch; // no match
+ m = MATCHnomatch; // no match
return m;
}
@@ -4257,7 +4257,7 @@ int TypeEnum::hasPointers()
/***************************** TypeTypedef *****************************/
TypeTypedef::TypeTypedef(TypedefDeclaration *sym)
- : Type(Ttypedef, NULL)
+ : Type(Ttypedef, NULL)
{
this->sym = sym;
}
@@ -4300,7 +4300,7 @@ void TypeTypedef::toDecoBuffer(OutBuffer *buf, bool mangle)
name = sym->mangle();
// if (name[0] == '_' && name[1] == 'D')
-// name += 2;
+// name += 2;
//len = strlen(name);
//buf->printf("%c%d%s", mangleChar[ty], len, name);
buf->printf("%c%s", mangleChar[ty], name);
@@ -4310,8 +4310,8 @@ void TypeTypedef::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
//printf("TypeTypedef::toCBuffer2() '%s'\n", sym->toChars());
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
buf->writestring(sym->toChars());
}
@@ -4323,7 +4323,7 @@ Expression *TypeTypedef::dotExp(Scope *sc, Expression *e, Identifier *ident)
#endif
if (ident == Id::init)
{
- return Type::dotExp(sc, e, ident);
+ return Type::dotExp(sc, e, ident);
}
return sym->basetype->dotExp(sc, e, ident);
}
@@ -4332,7 +4332,7 @@ Expression *TypeTypedef::getProperty(Loc loc, Identifier *ident)
{
if (ident == Id::init)
{
- return Type::getProperty(loc, ident);
+ return Type::getProperty(loc, ident);
}
return sym->basetype->getProperty(loc, ident);
}
@@ -4389,9 +4389,9 @@ Type *TypeTypedef::toBasetype()
{
if (sym->inuse)
{
- sym->error("circular definition");
- sym->basetype = Type::terror;
- return Type::terror;
+ sym->error("circular definition");
+ sym->basetype = Type::terror;
+ return Type::terror;
}
sym->inuse = 1;
Type *t = sym->basetype->toBasetype();
@@ -4404,11 +4404,11 @@ MATCH TypeTypedef::implicitConvTo(Type *to)
//printf("TypeTypedef::implicitConvTo()\n");
if (this->equals(to))
- m = MATCHexact; // exact match
+ m = MATCHexact; // exact match
else if (sym->basetype->implicitConvTo(to))
- m = MATCHconvert; // match with conversions
+ m = MATCHconvert; // match with conversions
else
- m = MATCHnomatch; // no match
+ m = MATCHnomatch; // no match
return m;
}
@@ -4421,16 +4421,16 @@ Expression *TypeTypedef::defaultInit(Loc loc)
#endif
if (sym->init)
{
- //sym->init->toExpression()->print();
- return sym->init->toExpression();
+ //sym->init->toExpression()->print();
+ return sym->init->toExpression();
}
bt = sym->basetype;
e = bt->defaultInit(loc);
e->type = this;
while (bt->ty == Tsarray)
{
- e->type = bt->next;
- bt = bt->next->toBasetype();
+ e->type = bt->next;
+ bt = bt->next->toBasetype();
}
return e;
}
@@ -4439,17 +4439,17 @@ int TypeTypedef::isZeroInit(Loc loc)
{
if (sym->init)
{
- if (sym->init->isVoidInitializer())
- return 1; // initialize voids to 0
- Expression *e = sym->init->toExpression();
- if (e && e->isBool(FALSE))
- return 1;
- return 0; // assume not
+ if (sym->init->isVoidInitializer())
+ return 1; // initialize voids to 0
+ Expression *e = sym->init->toExpression();
+ if (e && e->isBool(FALSE))
+ return 1;
+ return 0; // assume not
}
if (sym->inuse)
{
- sym->error("circular definition");
- sym->basetype = Type::terror;
+ sym->error("circular definition");
+ sym->basetype = Type::terror;
}
sym->inuse = 1;
int result = sym->basetype->isZeroInit(loc);
@@ -4465,7 +4465,7 @@ int TypeTypedef::hasPointers()
/***************************** TypeStruct *****************************/
TypeStruct::TypeStruct(StructDeclaration *sym)
- : Type(Tstruct, NULL)
+ : Type(Tstruct, NULL)
{
this->sym = sym;
@@ -4478,7 +4478,7 @@ char *TypeStruct::toChars()
//printf("sym.parent: %s, deco = %s\n", sym->parent->toChars(), deco);
TemplateInstance *ti = sym->parent->isTemplateInstance();
if (ti && ti->toAlias() == sym)
- return ti->toChars();
+ return ti->toChars();
return sym->toChars();
}
@@ -4507,10 +4507,10 @@ d_uns64 TypeStruct::size(Loc loc)
unsigned TypeStruct::alignsize()
{ unsigned sz;
- sym->size(0); // give error for forward references
+ sym->size(0); // give error for forward references
sz = sym->alignsize;
if (sz > sym->structalign)
- sz = sym->structalign;
+ sz = sym->structalign;
return sz;
}
@@ -4526,7 +4526,7 @@ void TypeStruct::toDecoBuffer(OutBuffer *buf, bool mangle)
name = sym->mangle();
//printf("TypeStruct::toDecoBuffer('%s') = '%s'\n", toChars(), name);
// if (name[0] == '_' && name[1] == 'D')
-// name += 2;
+// name += 2;
//len = strlen(name);
//buf->printf("%c%d%s", mangleChar[ty], len, name);
buf->printf("%c%s", mangleChar[ty], name);
@@ -4535,14 +4535,14 @@ void TypeStruct::toDecoBuffer(OutBuffer *buf, bool mangle)
void TypeStruct::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
TemplateInstance *ti = sym->parent->isTemplateInstance();
if (ti && ti->toAlias() == sym)
- buf->writestring(ti->toChars());
+ buf->writestring(ti->toChars());
else
- buf->writestring(sym->toChars());
+ buf->writestring(sym->toChars());
}
Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident)
@@ -4559,88 +4559,88 @@ Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident)
#endif
if (!sym->members)
{
- error(e->loc, "struct %s is forward referenced", sym->toChars());
- return new IntegerExp(e->loc, 0, Type::tint32);
+ error(e->loc, "struct %s is forward referenced", sym->toChars());
+ return new IntegerExp(e->loc, 0, Type::tint32);
}
/* If e.tupleof
*/
if (ident == Id::tupleof)
{
- /* Create a TupleExp out of the fields of the struct e:
- * (e.field0, e.field1, e.field2, ...)
- */
- e = e->semantic(sc); // do this before turning on noaccesscheck
- Expressions *exps = new Expressions;
- exps->reserve(sym->fields.dim);
- for (size_t i = 0; i < sym->fields.dim; i++)
- { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i];
- Expression *fe = new DotVarExp(e->loc, e, v);
- exps->push(fe);
- }
- e = new TupleExp(e->loc, exps);
- sc = sc->push();
- sc->noaccesscheck = 1;
- e = e->semantic(sc);
- sc->pop();
- return e;
+ /* Create a TupleExp out of the fields of the struct e:
+ * (e.field0, e.field1, e.field2, ...)
+ */
+ e = e->semantic(sc); // do this before turning on noaccesscheck
+ Expressions *exps = new Expressions;
+ exps->reserve(sym->fields.dim);
+ for (size_t i = 0; i < sym->fields.dim; i++)
+ { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i];
+ Expression *fe = new DotVarExp(e->loc, e, v);
+ exps->push(fe);
+ }
+ e = new TupleExp(e->loc, exps);
+ sc = sc->push();
+ sc->noaccesscheck = 1;
+ e = e->semantic(sc);
+ sc->pop();
+ return e;
}
if (e->op == TOKdotexp)
- { DotExp *de = (DotExp *)e;
+ { DotExp *de = (DotExp *)e;
- if (de->e1->op == TOKimport)
- {
- ScopeExp *se = (ScopeExp *)de->e1;
+ if (de->e1->op == TOKimport)
+ {
+ ScopeExp *se = (ScopeExp *)de->e1;
- s = se->sds->search(e->loc, ident, 0);
- e = de->e1;
- goto L1;
- }
+ s = se->sds->search(e->loc, ident, 0);
+ e = de->e1;
+ goto L1;
+ }
}
s = sym->search(e->loc, ident, 0);
L1:
if (!s)
{
- //return getProperty(e->loc, ident);
- return Type::dotExp(sc, e, ident);
+ //return getProperty(e->loc, ident);
+ return Type::dotExp(sc, e, ident);
}
- if (!s->isFuncDeclaration()) // because of overloading
- s->checkDeprecated(e->loc, sc);
+ if (!s->isFuncDeclaration()) // because of overloading
+ s->checkDeprecated(e->loc, sc);
s = s->toAlias();
v = s->isVarDeclaration();
if (v && v->isSameAsInitializer() && v->type->toBasetype()->ty != Tsarray)
- { ExpInitializer *ei = v->getExpInitializer();
+ { ExpInitializer *ei = v->getExpInitializer();
- if (ei)
- { e = ei->exp->copy(); // need to copy it if it's a StringExp
- e = e->semantic(sc);
- return e;
- }
+ if (ei)
+ { e = ei->exp->copy(); // need to copy it if it's a StringExp
+ e = e->semantic(sc);
+ return e;
+ }
}
if (s->getType())
{
- //return new DotTypeExp(e->loc, e, s);
- return new TypeExp(e->loc, s->getType());
+ //return new DotTypeExp(e->loc, e, s);
+ return new TypeExp(e->loc, s->getType());
}
EnumMember *em = s->isEnumMember();
if (em)
{
- assert(em->value);
- return em->value->copy();
+ assert(em->value);
+ return em->value->copy();
}
TemplateMixin *tm = s->isTemplateMixin();
if (tm)
- { Expression *de;
+ { Expression *de;
- de = new DotExp(e->loc, e, new ScopeExp(e->loc, tm));
- de->type = e->type;
- return de;
+ de = new DotExp(e->loc, e, new ScopeExp(e->loc, tm));
+ de->type = e->type;
+ return de;
}
TemplateDeclaration *td = s->isTemplateDeclaration();
@@ -4648,85 +4648,85 @@ L1:
{
e = new DotTemplateExp(e->loc, e, td);
e->semantic(sc);
- return e;
+ return e;
}
TemplateInstance *ti = s->isTemplateInstance();
if (ti)
- { if (!ti->semanticRun)
- {
- if (global.errors)
- return new ErrorExp(); // TemplateInstance::semantic() will fail anyway
- ti->semantic(sc);
- }
- s = ti->inst->toAlias();
- if (!s->isTemplateInstance())
- goto L1;
- Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti));
- de->type = e->type;
- return de;
+ { if (!ti->semanticRun)
+ {
+ if (global.errors)
+ return new ErrorExp(); // TemplateInstance::semantic() will fail anyway
+ ti->semantic(sc);
+ }
+ s = ti->inst->toAlias();
+ if (!s->isTemplateInstance())
+ goto L1;
+ Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti));
+ de->type = e->type;
+ return de;
}
Import *timp = s->isImport();
if (timp)
{
- e = new DsymbolExp(e->loc, s);
- e = e->semantic(sc);
- return e;
+ e = new DsymbolExp(e->loc, s);
+ e = e->semantic(sc);
+ return e;
}
d = s->isDeclaration();
#ifdef DEBUG
if (!d)
- printf("d = %s '%s'\n", s->kind(), s->toChars());
+ printf("d = %s '%s'\n", s->kind(), s->toChars());
#endif
assert(d);
if (e->op == TOKtype)
- { FuncDeclaration *fd = sc->func;
+ { FuncDeclaration *fd = sc->func;
- if (d->needThis() && fd && fd->vthis)
- {
- e = new DotVarExp(e->loc, new ThisExp(e->loc), d);
- e = e->semantic(sc);
- return e;
- }
- if (d->isTupleDeclaration())
- {
- e = new TupleExp(e->loc, d->isTupleDeclaration());
- e = e->semantic(sc);
- return e;
- }
- return new VarExp(e->loc, d);
+ if (d->needThis() && fd && fd->vthis)
+ {
+ e = new DotVarExp(e->loc, new ThisExp(e->loc), d);
+ e = e->semantic(sc);
+ return e;
+ }
+ if (d->isTupleDeclaration())
+ {
+ e = new TupleExp(e->loc, d->isTupleDeclaration());
+ e = e->semantic(sc);
+ return e;
+ }
+ return new VarExp(e->loc, d);
}
if (d->isDataseg())
{
- // (e, d)
- VarExp *ve;
+ // (e, d)
+ VarExp *ve;
- accessCheck(e->loc, sc, e, d);
- ve = new VarExp(e->loc, d);
- e = new CommaExp(e->loc, e, ve);
- e->type = d->type;
- return e;
+ accessCheck(e->loc, sc, e, d);
+ ve = new VarExp(e->loc, d);
+ e = new CommaExp(e->loc, e, ve);
+ e->type = d->type;
+ return e;
}
if (v)
{
- if (v->toParent() != sym)
- sym->error(e->loc, "'%s' is not a member", v->toChars());
+ if (v->toParent() != sym)
+ sym->error(e->loc, "'%s' is not a member", v->toChars());
- // *(&e + offset)
- accessCheck(e->loc, sc, e, d);
+ // *(&e + offset)
+ accessCheck(e->loc, sc, e, d);
#if 0
- b = new AddrExp(e->loc, e);
- b->type = e->type->pointerTo();
- b = new AddExp(e->loc, b, new IntegerExp(e->loc, v->offset, Type::tint32));
- b->type = v->type->pointerTo();
- e = new PtrExp(e->loc, b);
- e->type = v->type;
- return e;
+ b = new AddrExp(e->loc, e);
+ b->type = e->type->pointerTo();
+ b = new AddExp(e->loc, b, new IntegerExp(e->loc, v->offset, Type::tint32));
+ b->type = v->type->pointerTo();
+ e = new PtrExp(e->loc, b);
+ e->type = v->type;
+ return e;
#endif
}
@@ -4736,7 +4736,7 @@ L1:
unsigned TypeStruct::memalign(unsigned salign)
{
- sym->size(0); // give error for forward references
+ sym->size(0); // give error for forward references
return sym->structalign;
}
@@ -4764,13 +4764,13 @@ Expression *TypeStruct::defaultInitLiteral(Loc loc)
structelems->setDim(sym->fields.dim);
for (size_t j = 0; j < structelems->dim; j++)
{
- VarDeclaration *vd = (VarDeclaration *)(sym->fields.data[j]);
- Expression *e;
- if (vd->init)
- e = vd->init->toExpression();
- else
- e = vd->type->defaultInitLiteral();
- structelems->data[j] = e;
+ VarDeclaration *vd = (VarDeclaration *)(sym->fields.data[j]);
+ Expression *e;
+ if (vd->init)
+ e = vd->init->toExpression();
+ else
+ e = vd->type->defaultInitLiteral();
+ structelems->data[j] = e;
}
StructLiteralExp *structinit = new StructLiteralExp(loc, (StructDeclaration *)sym, structelems);
// Why doesn't the StructLiteralExp constructor do this, when
@@ -4794,15 +4794,15 @@ int TypeStruct::hasPointers()
{
StructDeclaration *s = sym;
- sym->size(0); // give error for forward references
+ sym->size(0); // give error for forward references
if (s->members)
{
- for (size_t i = 0; i < s->members->dim; i++)
- {
- Dsymbol *sm = (Dsymbol *)s->members->data[i];
- if (sm->hasPointers())
- return TRUE;
- }
+ for (size_t i = 0; i < s->members->dim; i++)
+ {
+ Dsymbol *sm = (Dsymbol *)s->members->data[i];
+ if (sm->hasPointers())
+ return TRUE;
+ }
}
return FALSE;
}
@@ -4811,7 +4811,7 @@ int TypeStruct::hasPointers()
/***************************** TypeClass *****************************/
TypeClass::TypeClass(ClassDeclaration *sym)
- : Type(Tclass, NULL)
+ : Type(Tclass, NULL)
{
this->sym = sym;
}
@@ -4830,7 +4830,7 @@ Type *TypeClass::semantic(Loc loc, Scope *sc)
{
//printf("TypeClass::semantic(%s)\n", sym->toChars());
if (deco)
- return this;
+ return this;
return merge();
}
@@ -4850,7 +4850,7 @@ void TypeClass::toDecoBuffer(OutBuffer *buf, bool mangle)
name = sym->mangle();
// if (name[0] == '_' && name[1] == 'D')
-// name += 2;
+// name += 2;
//printf("TypeClass::toDecoBuffer('%s') = '%s'\n", toChars(), name);
//len = strlen(name);
//buf->printf("%c%d%s", mangleChar[ty], len, name);
@@ -4860,8 +4860,8 @@ void TypeClass::toDecoBuffer(OutBuffer *buf, bool mangle)
void TypeClass::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
buf->writestring(sym->toChars());
}
@@ -4880,72 +4880,72 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
#endif
if (e->op == TOKdotexp)
- { DotExp *de = (DotExp *)e;
+ { DotExp *de = (DotExp *)e;
- if (de->e1->op == TOKimport)
- {
- ScopeExp *se = (ScopeExp *)de->e1;
+ if (de->e1->op == TOKimport)
+ {
+ ScopeExp *se = (ScopeExp *)de->e1;
- s = se->sds->search(e->loc, ident, 0);
- e = de->e1;
- goto L1;
- }
+ s = se->sds->search(e->loc, ident, 0);
+ e = de->e1;
+ goto L1;
+ }
}
if (ident == Id::tupleof)
{
- /* Create a TupleExp
- */
- e = e->semantic(sc); // do this before turning on noaccesscheck
- Expressions *exps = new Expressions;
- exps->reserve(sym->fields.dim);
- for (size_t i = 0; i < sym->fields.dim; i++)
- { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i];
- Expression *fe = new DotVarExp(e->loc, e, v);
- exps->push(fe);
- }
- e = new TupleExp(e->loc, exps);
- sc = sc->push();
- sc->noaccesscheck = 1;
- e = e->semantic(sc);
- sc->pop();
- return e;
+ /* Create a TupleExp
+ */
+ e = e->semantic(sc); // do this before turning on noaccesscheck
+ Expressions *exps = new Expressions;
+ exps->reserve(sym->fields.dim);
+ for (size_t i = 0; i < sym->fields.dim; i++)
+ { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i];
+ Expression *fe = new DotVarExp(e->loc, e, v);
+ exps->push(fe);
+ }
+ e = new TupleExp(e->loc, exps);
+ sc = sc->push();
+ sc->noaccesscheck = 1;
+ e = e->semantic(sc);
+ sc->pop();
+ return e;
}
s = sym->search(e->loc, ident, 0);
L1:
if (!s)
{
- // See if it's a base class
- ClassDeclaration *cbase;
- for (cbase = sym->baseClass; cbase; cbase = cbase->baseClass)
- {
- if (cbase->ident->equals(ident))
- {
- e = new DotTypeExp(0, e, cbase);
- return e;
- }
- }
+ // See if it's a base class
+ ClassDeclaration *cbase;
+ for (cbase = sym->baseClass; cbase; cbase = cbase->baseClass)
+ {
+ if (cbase->ident->equals(ident))
+ {
+ e = new DotTypeExp(0, e, cbase);
+ return e;
+ }
+ }
- if (ident == Id::classinfo)
- {
- Type *t;
+ if (ident == Id::classinfo)
+ {
+ Type *t;
- assert(ClassDeclaration::classinfo);
- t = ClassDeclaration::classinfo->type;
- if (e->op == TOKtype || e->op == TOKdottype)
- {
- /* For type.classinfo, we know the classinfo
- * at compile time.
- */
- if (!sym->vclassinfo)
- sym->vclassinfo = new ClassInfoDeclaration(sym);
- e = new VarExp(e->loc, sym->vclassinfo);
- e = e->addressOf(sc);
- e->type = t; // do this so we don't get redundant dereference
- }
- else
- {
+ assert(ClassDeclaration::classinfo);
+ t = ClassDeclaration::classinfo->type;
+ if (e->op == TOKtype || e->op == TOKdottype)
+ {
+ /* For type.classinfo, we know the classinfo
+ * at compile time.
+ */
+ if (!sym->vclassinfo)
+ sym->vclassinfo = new ClassInfoDeclaration(sym);
+ e = new VarExp(e->loc, sym->vclassinfo);
+ e = e->addressOf(sc);
+ e->type = t; // do this so we don't get redundant dereference
+ }
+ else
+ {
/* For class objects, the classinfo reference is the first
* entry in the vtbl[]
*/
@@ -4986,106 +4986,106 @@ L1:
#else
- e = new PtrExp(e->loc, e);
- e->type = t->pointerTo();
- if (sym->isInterfaceDeclaration())
- {
- if (sym->isCOMinterface())
- { /* COM interface vtbl[]s are different in that the
- * first entry is always pointer to QueryInterface().
- * We can't get a .classinfo for it.
- */
- error(e->loc, "no .classinfo for COM interface objects");
- }
- /* For an interface, the first entry in the vtbl[]
- * is actually a pointer to an instance of struct Interface.
- * The first member of Interface is the .classinfo,
- * so add an extra pointer indirection.
- */
- e->type = e->type->pointerTo();
- e = new PtrExp(e->loc, e);
- e->type = t->pointerTo();
- }
- e = new PtrExp(e->loc, e, t);
+ e = new PtrExp(e->loc, e);
+ e->type = t->pointerTo();
+ if (sym->isInterfaceDeclaration())
+ {
+ if (sym->isCOMinterface())
+ { /* COM interface vtbl[]s are different in that the
+ * first entry is always pointer to QueryInterface().
+ * We can't get a .classinfo for it.
+ */
+ error(e->loc, "no .classinfo for COM interface objects");
+ }
+ /* For an interface, the first entry in the vtbl[]
+ * is actually a pointer to an instance of struct Interface.
+ * The first member of Interface is the .classinfo,
+ * so add an extra pointer indirection.
+ */
+ e->type = e->type->pointerTo();
+ e = new PtrExp(e->loc, e);
+ e->type = t->pointerTo();
+ }
+ e = new PtrExp(e->loc, e, t);
}
#endif // !LDC
- return e;
- }
+ return e;
+ }
- if (ident == Id::__vptr)
- { /* The pointer to the vtbl[]
- * *cast(void***)e
- */
- e = e->castTo(sc, tvoidptr->pointerTo()->pointerTo());
- e = new PtrExp(e->loc, e);
- e = e->semantic(sc);
- return e;
- }
+ if (ident == Id::__vptr)
+ { /* The pointer to the vtbl[]
+ * *cast(void***)e
+ */
+ e = e->castTo(sc, tvoidptr->pointerTo()->pointerTo());
+ e = new PtrExp(e->loc, e);
+ e = e->semantic(sc);
+ return e;
+ }
- if (ident == Id::__monitor)
- { /* The handle to the monitor (call it a void*)
- * *(cast(void**)e + 1)
- */
- e = e->castTo(sc, tvoidptr->pointerTo());
- e = new AddExp(e->loc, e, new IntegerExp(1));
- e = new PtrExp(e->loc, e);
- e = e->semantic(sc);
- return e;
- }
+ if (ident == Id::__monitor)
+ { /* The handle to the monitor (call it a void*)
+ * *(cast(void**)e + 1)
+ */
+ e = e->castTo(sc, tvoidptr->pointerTo());
+ e = new AddExp(e->loc, e, new IntegerExp(1));
+ e = new PtrExp(e->loc, e);
+ e = e->semantic(sc);
+ return e;
+ }
- if (ident == Id::typeinfo)
- {
- if (!global.params.useDeprecated)
- error(e->loc, ".typeinfo deprecated, use typeid(type)");
- return getTypeInfo(sc);
- }
- if (ident == Id::outer && sym->vthis)
- {
- s = sym->vthis;
- }
- else
- {
- //return getProperty(e->loc, ident);
- return Type::dotExp(sc, e, ident);
- }
+ if (ident == Id::typeinfo)
+ {
+ if (!global.params.useDeprecated)
+ error(e->loc, ".typeinfo deprecated, use typeid(type)");
+ return getTypeInfo(sc);
+ }
+ if (ident == Id::outer && sym->vthis)
+ {
+ s = sym->vthis;
+ }
+ else
+ {
+ //return getProperty(e->loc, ident);
+ return Type::dotExp(sc, e, ident);
+ }
}
- if (!s->isFuncDeclaration()) // because of overloading
- s->checkDeprecated(e->loc, sc);
+ if (!s->isFuncDeclaration()) // because of overloading
+ s->checkDeprecated(e->loc, sc);
s = s->toAlias();
v = s->isVarDeclaration();
if (v && v->isSameAsInitializer() && v->type->toBasetype()->ty != Tsarray)
- { ExpInitializer *ei = v->getExpInitializer();
+ { ExpInitializer *ei = v->getExpInitializer();
- if (ei)
- { e = ei->exp->copy(); // need to copy it if it's a StringExp
- e = e->semantic(sc);
- return e;
- }
+ if (ei)
+ { e = ei->exp->copy(); // need to copy it if it's a StringExp
+ e = e->semantic(sc);
+ return e;
+ }
}
if (s->getType())
{
-// if (e->op == TOKtype)
- return new TypeExp(e->loc, s->getType());
-// return new DotTypeExp(e->loc, e, s);
+// if (e->op == TOKtype)
+ return new TypeExp(e->loc, s->getType());
+// return new DotTypeExp(e->loc, e, s);
}
EnumMember *em = s->isEnumMember();
if (em)
{
- assert(em->value);
- return em->value->copy();
+ assert(em->value);
+ return em->value->copy();
}
TemplateMixin *tm = s->isTemplateMixin();
if (tm)
- { Expression *de;
+ { Expression *de;
- de = new DotExp(e->loc, e, new ScopeExp(e->loc, tm));
- de->type = e->type;
- return de;
+ de = new DotExp(e->loc, e, new ScopeExp(e->loc, tm));
+ de->type = e->type;
+ return de;
}
TemplateDeclaration *td = s->isTemplateDeclaration();
@@ -5093,100 +5093,100 @@ L1:
{
e = new DotTemplateExp(e->loc, e, td);
e->semantic(sc);
- return e;
+ return e;
}
TemplateInstance *ti = s->isTemplateInstance();
if (ti)
- { if (!ti->semanticRun)
- {
- if (global.errors)
- return new ErrorExp(); // TemplateInstance::semantic() will fail anyway
- ti->semantic(sc);
- }
- s = ti->inst->toAlias();
- if (!s->isTemplateInstance())
- goto L1;
- Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti));
- de->type = e->type;
- return de;
+ { if (!ti->semanticRun)
+ {
+ if (global.errors)
+ return new ErrorExp(); // TemplateInstance::semantic() will fail anyway
+ ti->semantic(sc);
+ }
+ s = ti->inst->toAlias();
+ if (!s->isTemplateInstance())
+ goto L1;
+ Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti));
+ de->type = e->type;
+ return de;
}
d = s->isDeclaration();
if (!d)
{
- e->error("%s.%s is not a declaration", e->toChars(), ident->toChars());
- return new IntegerExp(e->loc, 1, Type::tint32);
+ e->error("%s.%s is not a declaration", e->toChars(), ident->toChars());
+ return new IntegerExp(e->loc, 1, Type::tint32);
}
if (e->op == TOKtype)
{
- /* It's:
- * Class.d
- */
- if (d->isTupleDeclaration())
- {
- e = new TupleExp(e->loc, d->isTupleDeclaration());
- e = e->semantic(sc);
- return e;
- }
- else if (d->needThis() && (hasThis(sc) || !(sc->intypeof || d->isFuncDeclaration())))
- {
- if (sc->func)
- {
- ClassDeclaration *thiscd;
- thiscd = sc->func->toParent()->isClassDeclaration();
+ /* It's:
+ * Class.d
+ */
+ if (d->isTupleDeclaration())
+ {
+ e = new TupleExp(e->loc, d->isTupleDeclaration());
+ e = e->semantic(sc);
+ return e;
+ }
+ else if (d->needThis() && (hasThis(sc) || !(sc->intypeof || d->isFuncDeclaration())))
+ {
+ if (sc->func)
+ {
+ ClassDeclaration *thiscd;
+ thiscd = sc->func->toParent()->isClassDeclaration();
- if (thiscd)
- {
- ClassDeclaration *cd = e->type->isClassHandle();
+ if (thiscd)
+ {
+ ClassDeclaration *cd = e->type->isClassHandle();
- if (cd == thiscd)
- {
- e = new ThisExp(e->loc);
- e = new DotTypeExp(e->loc, e, cd);
- de = new DotVarExp(e->loc, e, d);
- e = de->semantic(sc);
- return e;
- }
- else if ((!cd || !cd->isBaseOf(thiscd, NULL)) &&
- !d->isFuncDeclaration())
- e->error("'this' is required, but %s is not a base class of %s", e->type->toChars(), thiscd->toChars());
- }
- }
+ if (cd == thiscd)
+ {
+ e = new ThisExp(e->loc);
+ e = new DotTypeExp(e->loc, e, cd);
+ de = new DotVarExp(e->loc, e, d);
+ e = de->semantic(sc);
+ return e;
+ }
+ else if ((!cd || !cd->isBaseOf(thiscd, NULL)) &&
+ !d->isFuncDeclaration())
+ e->error("'this' is required, but %s is not a base class of %s", e->type->toChars(), thiscd->toChars());
+ }
+ }
- de = new DotVarExp(e->loc, new ThisExp(e->loc), d);
- e = de->semantic(sc);
- return e;
- }
- else
- {
- VarExp *ve = new VarExp(e->loc, d);
- return ve;
- }
+ de = new DotVarExp(e->loc, new ThisExp(e->loc), d);
+ e = de->semantic(sc);
+ return e;
+ }
+ else
+ {
+ VarExp *ve = new VarExp(e->loc, d);
+ return ve;
+ }
}
if (d->isDataseg())
{
- // (e, d)
- VarExp *ve;
+ // (e, d)
+ VarExp *ve;
- accessCheck(e->loc, sc, e, d);
- ve = new VarExp(e->loc, d);
- e = new CommaExp(e->loc, e, ve);
- e->type = d->type;
- return e;
+ accessCheck(e->loc, sc, e, d);
+ ve = new VarExp(e->loc, d);
+ e = new CommaExp(e->loc, e, ve);
+ e->type = d->type;
+ return e;
}
if (d->parent && d->toParent()->isModule())
{
- // (e, d)
- VarExp *ve;
+ // (e, d)
+ VarExp *ve;
- ve = new VarExp(e->loc, d);
- e = new CommaExp(e->loc, e, ve);
- e->type = d->type;
- return e;
+ ve = new VarExp(e->loc, d);
+ e = new CommaExp(e->loc, e, ve);
+ e->type = d->type;
+ return e;
}
de = new DotVarExp(e->loc, e, d);
@@ -5208,9 +5208,9 @@ int TypeClass::isBaseOf(Type *t, int *poffset)
if (t->ty == Tclass)
{ ClassDeclaration *cd;
- cd = ((TypeClass *)t)->sym;
- if (sym->isBaseOf(cd, poffset))
- return 1;
+ cd = ((TypeClass *)t)->sym;
+ if (sym->isBaseOf(cd, poffset))
+ return 1;
}
return 0;
}
@@ -5219,19 +5219,19 @@ MATCH TypeClass::implicitConvTo(Type *to)
{
//printf("TypeClass::implicitConvTo('%s')\n", to->toChars());
if (this == to)
- return MATCHexact;
+ return MATCHexact;
ClassDeclaration *cdto = to->isClassHandle();
if (cdto && cdto->isBaseOf(sym, NULL))
- { //printf("is base\n");
- return MATCHconvert;
+ { //printf("is base\n");
+ return MATCHconvert;
}
if (global.params.Dversion == 1)
{
- // Allow conversion to (void *)
- if (to->ty == Tpointer && to->next->ty == Tvoid)
- return MATCHconvert;
+ // Allow conversion to (void *)
+ if (to->ty == Tpointer && to->next->ty == Tvoid)
+ return MATCHconvert;
}
return MATCHnomatch;
@@ -5271,11 +5271,11 @@ TypeTuple::TypeTuple(Parameters *arguments)
#ifdef DEBUG
if (arguments)
{
- for (size_t i = 0; i < arguments->dim; i++)
- {
- Parameter *arg = (Parameter *)arguments->data[i];
- assert(arg && arg->type);
- }
+ for (size_t i = 0; i < arguments->dim; i++)
+ {
+ Parameter *arg = (Parameter *)arguments->data[i];
+ assert(arg && arg->type);
+ }
}
#endif
}
@@ -5291,14 +5291,14 @@ TypeTuple::TypeTuple(Expressions *exps)
Parameters *arguments = new Parameters;
if (exps)
{
- arguments->setDim(exps->dim);
- for (size_t i = 0; i < exps->dim; i++)
- { Expression *e = (Expression *)exps->data[i];
- if (e->type->ty == Ttuple)
- e->error("cannot form tuple of tuples");
- Parameter *arg = new Parameter(STCin, e->type, NULL, NULL);
- arguments->data[i] = (void *)arg;
- }
+ arguments->setDim(exps->dim);
+ for (size_t i = 0; i < exps->dim; i++)
+ { Expression *e = (Expression *)exps->data[i];
+ if (e->type->ty == Ttuple)
+ e->error("cannot form tuple of tuples");
+ Parameter *arg = new Parameter(STCin, e->type, NULL, NULL);
+ arguments->data[i] = (void *)arg;
+ }
}
this->arguments = arguments;
}
@@ -5315,7 +5315,7 @@ Type *TypeTuple::semantic(Loc loc, Scope *sc)
//printf("TypeTuple::semantic(this = %p)\n", this);
//printf("TypeTuple::semantic() %s\n", toChars());
if (!deco)
- deco = merge()->deco;
+ deco = merge()->deco;
/* Don't return merge(), because a tuple with one type has the
* same deco as that type.
@@ -5330,22 +5330,22 @@ int TypeTuple::equals(Object *o)
//printf("TypeTuple::equals(%s, %s)\n", toChars(), t->toChars());
if (this == t)
{
- return 1;
+ return 1;
}
if (t->ty == Ttuple)
- { TypeTuple *tt = (TypeTuple *)t;
+ { TypeTuple *tt = (TypeTuple *)t;
- if (arguments->dim == tt->arguments->dim)
- {
- for (size_t i = 0; i < tt->arguments->dim; i++)
- { Parameter *arg1 = (Parameter *)arguments->data[i];
- Parameter *arg2 = (Parameter *)tt->arguments->data[i];
+ if (arguments->dim == tt->arguments->dim)
+ {
+ for (size_t i = 0; i < tt->arguments->dim; i++)
+ { Parameter *arg1 = (Parameter *)arguments->data[i];
+ Parameter *arg2 = (Parameter *)tt->arguments->data[i];
- if (!arg1->type->equals(arg2->type))
- return 0;
- }
- return 1;
- }
+ if (!arg1->type->equals(arg2->type))
+ return 0;
+ }
+ return 1;
+ }
}
return 0;
}
@@ -5354,13 +5354,13 @@ Type *TypeTuple::reliesOnTident()
{
if (arguments)
{
- for (size_t i = 0; i < arguments->dim; i++)
- {
- Parameter *arg = (Parameter *)arguments->data[i];
- Type *t = arg->type->reliesOnTident();
- if (t)
- return t;
- }
+ for (size_t i = 0; i < arguments->dim; i++)
+ {
+ Parameter *arg = (Parameter *)arguments->data[i];
+ Type *t = arg->type->reliesOnTident();
+ if (t)
+ return t;
+ }
}
return NULL;
}
@@ -5387,12 +5387,12 @@ Expression *TypeTuple::getProperty(Loc loc, Identifier *ident)
#endif
if (ident == Id::length)
{
- e = new IntegerExp(loc, arguments->dim, Type::tsize_t);
+ e = new IntegerExp(loc, arguments->dim, Type::tsize_t);
}
else
{
- error(loc, "no property '%s' for tuple '%s'", ident->toChars(), toChars());
- e = new IntegerExp(loc, 1, Type::tint32);
+ error(loc, "no property '%s' for tuple '%s'", ident->toChars(), toChars());
+ e = new IntegerExp(loc, 1, Type::tint32);
}
return e;
}
@@ -5423,8 +5423,8 @@ Type *TypeSlice::semantic(Loc loc, Scope *sc)
Type *tbn = next->toBasetype();
if (tbn->ty != Ttuple)
- { error(loc, "can only slice tuple types, not %s", tbn->toChars());
- return Type::terror;
+ { error(loc, "can only slice tuple types, not %s", tbn->toChars());
+ return Type::terror;
}
TypeTuple *tt = (TypeTuple *)tbn;
@@ -5437,15 +5437,15 @@ Type *TypeSlice::semantic(Loc loc, Scope *sc)
uinteger_t i2 = upr->toUInteger();
if (!(i1 <= i2 && i2 <= tt->arguments->dim))
- { error(loc, "slice [%ju..%ju] is out of range of [0..%u]", i1, i2, tt->arguments->dim);
- return Type::terror;
+ { error(loc, "slice [%ju..%ju] is out of range of [0..%u]", i1, i2, tt->arguments->dim);
+ return Type::terror;
}
Parameters *args = new Parameters;
args->reserve(i2 - i1);
for (size_t i = i1; i < i2; i++)
- { Parameter *arg = (Parameter *)tt->arguments->data[i];
- args->push(arg);
+ { Parameter *arg = (Parameter *)tt->arguments->data[i];
+ args->push(arg);
}
return new TypeTuple(args);
@@ -5455,71 +5455,71 @@ void TypeSlice::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
{
next->resolve(loc, sc, pe, pt, ps);
if (*pe)
- { // It's really a slice expression
- Expression *e;
- e = new SliceExp(loc, *pe, lwr, upr);
- *pe = e;
+ { // It's really a slice expression
+ Expression *e;
+ e = new SliceExp(loc, *pe, lwr, upr);
+ *pe = e;
}
else if (*ps)
- { Dsymbol *s = *ps;
- TupleDeclaration *td = s->isTupleDeclaration();
- if (td)
- {
- /* It's a slice of a TupleDeclaration
- */
- ScopeDsymbol *sym = new ArrayScopeSymbol(td);
- sym->parent = sc->scopesym;
- sc = sc->push(sym);
+ { Dsymbol *s = *ps;
+ TupleDeclaration *td = s->isTupleDeclaration();
+ if (td)
+ {
+ /* It's a slice of a TupleDeclaration
+ */
+ ScopeDsymbol *sym = new ArrayScopeSymbol(td);
+ sym->parent = sc->scopesym;
+ sc = sc->push(sym);
- lwr = lwr->semantic(sc);
- lwr = lwr->optimize(WANTvalue);
- uinteger_t i1 = lwr->toUInteger();
+ lwr = lwr->semantic(sc);
+ lwr = lwr->optimize(WANTvalue);
+ uinteger_t i1 = lwr->toUInteger();
- upr = upr->semantic(sc);
- upr = upr->optimize(WANTvalue);
- uinteger_t i2 = upr->toUInteger();
+ upr = upr->semantic(sc);
+ upr = upr->optimize(WANTvalue);
+ uinteger_t i2 = upr->toUInteger();
- sc = sc->pop();
+ sc = sc->pop();
- if (!(i1 <= i2 && i2 <= td->objects->dim))
- { error(loc, "slice [%ju..%ju] is out of range of [0..%u]", i1, i2, td->objects->dim);
- goto Ldefault;
- }
+ if (!(i1 <= i2 && i2 <= td->objects->dim))
+ { error(loc, "slice [%ju..%ju] is out of range of [0..%u]", i1, i2, td->objects->dim);
+ goto Ldefault;
+ }
- if (i1 == 0 && i2 == td->objects->dim)
- {
- *ps = td;
- return;
- }
+ if (i1 == 0 && i2 == td->objects->dim)
+ {
+ *ps = td;
+ return;
+ }
- /* Create a new TupleDeclaration which
- * is a slice [i1..i2] out of the old one.
- */
- Objects *objects = new Objects;
- objects->setDim(i2 - i1);
- for (size_t i = 0; i < objects->dim; i++)
- {
- objects->data[i] = td->objects->data[(size_t)i1 + i];
- }
+ /* Create a new TupleDeclaration which
+ * is a slice [i1..i2] out of the old one.
+ */
+ Objects *objects = new Objects;
+ objects->setDim(i2 - i1);
+ for (size_t i = 0; i < objects->dim; i++)
+ {
+ objects->data[i] = td->objects->data[(size_t)i1 + i];
+ }
- TupleDeclaration *tds = new TupleDeclaration(loc, td->ident, objects);
- *ps = tds;
- }
- else
- goto Ldefault;
+ TupleDeclaration *tds = new TupleDeclaration(loc, td->ident, objects);
+ *ps = tds;
+ }
+ else
+ goto Ldefault;
}
else
{
Ldefault:
- Type::resolve(loc, sc, pe, pt, ps);
+ Type::resolve(loc, sc, pe, pt, ps);
}
}
void TypeSlice::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
{
if (mod != this->mod)
- { toCBuffer3(buf, hgs, mod);
- return;
+ { toCBuffer3(buf, hgs, mod);
+ return;
}
next->toCBuffer2(buf, hgs, this->mod);
@@ -5540,9 +5540,9 @@ Parameter::Parameter(StorageClass storageClass, Type *type, Identifier *ident, E
Parameter *Parameter::syntaxCopy()
{
Parameter *a = new Parameter(storageClass,
- type ? type->syntaxCopy() : NULL,
- ident,
- defaultArg ? defaultArg->syntaxCopy() : NULL);
+ type ? type->syntaxCopy() : NULL,
+ ident,
+ defaultArg ? defaultArg->syntaxCopy() : NULL);
return a;
}
@@ -5551,14 +5551,14 @@ Parameters *Parameter::arraySyntaxCopy(Parameters *args)
if (args)
{
- a = new Parameters();
- a->setDim(args->dim);
- for (size_t i = 0; i < a->dim; i++)
- { Parameter *arg = (Parameter *)args->data[i];
+ a = new Parameters();
+ a->setDim(args->dim);
+ for (size_t i = 0; i < a->dim; i++)
+ { Parameter *arg = (Parameter *)args->data[i];
- arg = arg->syntaxCopy();
- a->data[i] = (void *)arg;
- }
+ arg = arg->syntaxCopy();
+ a->data[i] = (void *)arg;
+ }
}
return a;
}
@@ -5570,26 +5570,26 @@ char *Parameter::argsTypesToChars(Parameters *args, int varargs)
buf->writeByte('(');
if (args)
- { int i;
- OutBuffer argbuf;
- HdrGenState hgs;
+ { int i;
+ OutBuffer argbuf;
+ HdrGenState hgs;
- for (i = 0; i < args->dim; i++)
- { Parameter *arg;
+ for (i = 0; i < args->dim; i++)
+ { Parameter *arg;
- if (i)
- buf->writeByte(',');
- arg = (Parameter *)args->data[i];
- argbuf.reset();
- arg->type->toCBuffer2(&argbuf, &hgs, 0);
- buf->write(&argbuf);
- }
- if (varargs)
- {
- if (i && varargs == 1)
- buf->writeByte(',');
- buf->writestring("...");
- }
+ if (i)
+ buf->writeByte(',');
+ arg = (Parameter *)args->data[i];
+ argbuf.reset();
+ arg->type->toCBuffer2(&argbuf, &hgs, 0);
+ buf->write(&argbuf);
+ }
+ if (varargs)
+ {
+ if (i && varargs == 1)
+ buf->writeByte(',');
+ buf->writestring("...");
+ }
}
buf->writeByte(')');
@@ -5600,37 +5600,37 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
{
buf->writeByte('(');
if (arguments)
- { int i;
- OutBuffer argbuf;
+ { int i;
+ OutBuffer argbuf;
- for (i = 0; i < arguments->dim; i++)
- { Parameter *arg;
+ for (i = 0; i < arguments->dim; i++)
+ { Parameter *arg;
- if (i)
- buf->writestring(", ");
- arg = (Parameter *)arguments->data[i];
- if (arg->storageClass & STCout)
- buf->writestring("out ");
- else if (arg->storageClass & STCref)
- buf->writestring((global.params.Dversion == 1)
- ? (char *)"inout " : (char *)"ref ");
- else if (arg->storageClass & STClazy)
- buf->writestring("lazy ");
- argbuf.reset();
- arg->type->toCBuffer(&argbuf, arg->ident, hgs);
- if (arg->defaultArg)
- {
- argbuf.writestring(" = ");
- arg->defaultArg->toCBuffer(&argbuf, hgs);
- }
- buf->write(&argbuf);
- }
- if (varargs)
- {
- if (i && varargs == 1)
- buf->writeByte(',');
- buf->writestring("...");
- }
+ if (i)
+ buf->writestring(", ");
+ arg = (Parameter *)arguments->data[i];
+ if (arg->storageClass & STCout)
+ buf->writestring("out ");
+ else if (arg->storageClass & STCref)
+ buf->writestring((global.params.Dversion == 1)
+ ? (char *)"inout " : (char *)"ref ");
+ else if (arg->storageClass & STClazy)
+ buf->writestring("lazy ");
+ argbuf.reset();
+ arg->type->toCBuffer(&argbuf, arg->ident, hgs);
+ if (arg->defaultArg)
+ {
+ argbuf.writestring(" = ");
+ arg->defaultArg->toCBuffer(&argbuf, hgs);
+ }
+ buf->write(&argbuf);
+ }
+ if (varargs)
+ {
+ if (i && varargs == 1)
+ buf->writeByte(',');
+ buf->writestring("...");
+ }
}
buf->writeByte(')');
}
@@ -5643,12 +5643,12 @@ void Parameter::argsToDecoBuffer(OutBuffer *buf, Parameters *arguments, bool man
// Write argument types
if (arguments)
{
- size_t dim = Parameter::dim(arguments);
- for (size_t i = 0; i < dim; i++)
- {
- Parameter *arg = Parameter::getNth(arguments, i);
- arg->toDecoBuffer(buf, mangle);
- }
+ size_t dim = Parameter::dim(arguments);
+ for (size_t i = 0; i < dim; i++)
+ {
+ Parameter *arg = Parameter::getNth(arguments, i);
+ arg->toDecoBuffer(buf, mangle);
+ }
}
}
@@ -5662,21 +5662,21 @@ Type *Parameter::isLazyArray()
{
// if (inout == Lazy)
{
- Type *tb = type->toBasetype();
- if (tb->ty == Tsarray || tb->ty == Tarray)
- {
- Type *tel = tb->next->toBasetype();
- if (tel->ty == Tdelegate)
- {
- TypeDelegate *td = (TypeDelegate *)tel;
- TypeFunction *tf = (TypeFunction *)td->next;
+ Type *tb = type->toBasetype();
+ if (tb->ty == Tsarray || tb->ty == Tarray)
+ {
+ Type *tel = tb->next->toBasetype();
+ if (tel->ty == Tdelegate)
+ {
+ TypeDelegate *td = (TypeDelegate *)tel;
+ TypeFunction *tf = (TypeFunction *)td->next;
- if (!tf->varargs && Parameter::dim(tf->parameters) == 0)
- {
- return tf->next; // return type of delegate
- }
- }
- }
+ if (!tf->varargs && Parameter::dim(tf->parameters) == 0)
+ {
+ return tf->next; // return type of delegate
+ }
+ }
+ }
}
return NULL;
}
@@ -5685,22 +5685,22 @@ void Parameter::toDecoBuffer(OutBuffer *buf, bool mangle)
{
switch (storageClass & (STCin | STCout | STCref | STClazy))
{ case 0:
- case STCin:
- break;
- case STCout:
- buf->writeByte('J');
- break;
- case STCref:
- buf->writeByte('K');
- break;
- case STClazy:
- buf->writeByte('L');
- break;
- default:
+ case STCin:
+ break;
+ case STCout:
+ buf->writeByte('J');
+ break;
+ case STCref:
+ buf->writeByte('K');
+ break;
+ case STClazy:
+ buf->writeByte('L');
+ break;
+ default:
#ifdef DEBUG
- halt();
+ halt();
#endif
- assert(0);
+ assert(0);
}
type->toDecoBuffer(buf, mangle);
}
@@ -5714,17 +5714,17 @@ size_t Parameter::dim(Parameters *args)
size_t n = 0;
if (args)
{
- for (size_t i = 0; i < args->dim; i++)
- { Parameter *arg = (Parameter *)args->data[i];
- Type *t = arg->type->toBasetype();
+ for (size_t i = 0; i < args->dim; i++)
+ { Parameter *arg = (Parameter *)args->data[i];
+ Type *t = arg->type->toBasetype();
- if (t->ty == Ttuple)
- { TypeTuple *tu = (TypeTuple *)t;
- n += dim(tu->arguments);
- }
- else
- n++;
- }
+ if (t->ty == Ttuple)
+ { TypeTuple *tu = (TypeTuple *)t;
+ n += dim(tu->arguments);
+ }
+ else
+ n++;
+ }
}
return n;
}
@@ -5732,34 +5732,34 @@ size_t Parameter::dim(Parameters *args)
/***************************************
* Get nth Parameter, folding in tuples.
* Returns:
- * Parameter* nth Parameter
- * NULL not found, *pn gets incremented by the number
- * of Parameters
+ * Parameter* nth Parameter
+ * NULL not found, *pn gets incremented by the number
+ * of Parameters
*/
Parameter *Parameter::getNth(Parameters *args, size_t nth, size_t *pn)
{
if (!args)
- return NULL;
+ return NULL;
size_t n = 0;
for (size_t i = 0; i < args->dim; i++)
{ Parameter *arg = (Parameter *)args->data[i];
- Type *t = arg->type->toBasetype();
+ Type *t = arg->type->toBasetype();
- if (t->ty == Ttuple)
- { TypeTuple *tu = (TypeTuple *)t;
- arg = getNth(tu->arguments, nth - n, &n);
- if (arg)
- return arg;
- }
- else if (n == nth)
- return arg;
- else
- n++;
+ if (t->ty == Ttuple)
+ { TypeTuple *tu = (TypeTuple *)t;
+ arg = getNth(tu->arguments, nth - n, &n);
+ if (arg)
+ return arg;
+ }
+ else if (n == nth)
+ return arg;
+ else
+ n++;
}
if (pn)
- *pn += n;
+ *pn += n;
return NULL;
}
diff --git a/dmd/mtype.h b/dmd/mtype.h
index 81c3ed15..bc6c1cbd 100644
--- a/dmd/mtype.h
+++ b/dmd/mtype.h
@@ -59,9 +59,9 @@ struct Symbol;
enum TY
{
- Tarray, // dynamic array
- Tsarray, // static array
- Taarray, // associative array
+ Tarray, // dynamic array
+ Tsarray, // static array
+ Taarray, // associative array
Tpointer,
Treference,
Tfunction,
@@ -118,60 +118,60 @@ extern int Tptrdiff_t;
struct Type : Object
{
TY ty;
- unsigned char mod; // modifiers MODxxxx
- /* pick this order of numbers so switch statements work better
- */
- #define MODconst 1 // type is const
- #define MODimmutable 4 // type is invariant
- #define MODshared 2 // type is shared
+ unsigned char mod; // modifiers MODxxxx
+ /* pick this order of numbers so switch statements work better
+ */
+ #define MODconst 1 // type is const
+ #define MODimmutable 4 // type is invariant
+ #define MODshared 2 // type is shared
char *deco;
- Type *pto; // merged pointer to this type
- Type *rto; // reference to this type
- Type *arrayof; // array of this type
- TypeInfoDeclaration *vtinfo; // TypeInfo object for this Type
+ Type *pto; // merged pointer to this type
+ Type *rto; // reference to this type
+ Type *arrayof; // array of this type
+ TypeInfoDeclaration *vtinfo; // TypeInfo object for this Type
#if IN_DMD
- type *ctype; // for back end
+ type *ctype; // for back end
#endif
- #define tvoid basic[Tvoid]
- #define tint8 basic[Tint8]
- #define tuns8 basic[Tuns8]
- #define tint16 basic[Tint16]
- #define tuns16 basic[Tuns16]
- #define tint32 basic[Tint32]
- #define tuns32 basic[Tuns32]
- #define tint64 basic[Tint64]
- #define tuns64 basic[Tuns64]
- #define tfloat32 basic[Tfloat32]
- #define tfloat64 basic[Tfloat64]
- #define tfloat80 basic[Tfloat80]
+ #define tvoid basic[Tvoid]
+ #define tint8 basic[Tint8]
+ #define tuns8 basic[Tuns8]
+ #define tint16 basic[Tint16]
+ #define tuns16 basic[Tuns16]
+ #define tint32 basic[Tint32]
+ #define tuns32 basic[Tuns32]
+ #define tint64 basic[Tint64]
+ #define tuns64 basic[Tuns64]
+ #define tfloat32 basic[Tfloat32]
+ #define tfloat64 basic[Tfloat64]
+ #define tfloat80 basic[Tfloat80]
#define timaginary32 basic[Timaginary32]
#define timaginary64 basic[Timaginary64]
#define timaginary80 basic[Timaginary80]
- #define tcomplex32 basic[Tcomplex32]
- #define tcomplex64 basic[Tcomplex64]
- #define tcomplex80 basic[Tcomplex80]
+ #define tcomplex32 basic[Tcomplex32]
+ #define tcomplex64 basic[Tcomplex64]
+ #define tcomplex80 basic[Tcomplex80]
- #define tbit basic[Tbit]
- #define tbool basic[Tbool]
- #define tchar basic[Tchar]
- #define twchar basic[Twchar]
- #define tdchar basic[Tdchar]
+ #define tbit basic[Tbit]
+ #define tbool basic[Tbool]
+ #define tchar basic[Tchar]
+ #define twchar basic[Twchar]
+ #define tdchar basic[Tdchar]
// Some special types
- #define tshiftcnt tint32 // right side of shift expression
-// #define tboolean tint32 // result of boolean expression
- #define tboolean tbool // result of boolean expression
- #define tindex tint32 // array/ptr index
- static Type *tvoidptr; // void*
- #define terror basic[Terror] // for error recovery
+ #define tshiftcnt tint32 // right side of shift expression
+// #define tboolean tint32 // result of boolean expression
+ #define tboolean tbool // result of boolean expression
+ #define tindex tint32 // array/ptr index
+ static Type *tvoidptr; // void*
+ #define terror basic[Terror] // for error recovery
- #define tsize_t basic[Tsize_t] // matches size_t alias
- #define tptrdiff_t basic[Tptrdiff_t] // matches ptrdiff_t alias
- #define thash_t tsize_t // matches hash_t alias
+ #define tsize_t basic[Tsize_t] // matches size_t alias
+ #define tptrdiff_t basic[Tptrdiff_t] // matches ptrdiff_t alias
+ #define thash_t tsize_t // matches hash_t alias
static ClassDeclaration *typeinfo;
static ClassDeclaration *typeinfoclass;
@@ -228,7 +228,7 @@ struct Type : Object
void toCBuffer3(OutBuffer *buf, HdrGenState *hgs, int mod);
virtual int isbit();
virtual int isintegral();
- virtual int isfloating(); // real, imaginary, or complex
+ virtual int isfloating(); // real, imaginary, or complex
virtual int isreal();
virtual int isimaginary();
virtual int iscomplex();
@@ -236,7 +236,7 @@ struct Type : Object
virtual int isunsigned();
virtual int isscope();
virtual int isString();
- virtual int checkBoolean(); // if can be converted to boolean value
+ virtual int checkBoolean(); // if can be converted to boolean value
void checkDeprecated(Loc loc, Scope *sc);
Type *pointerTo();
Type *referenceTo();
@@ -251,7 +251,7 @@ struct Type : Object
virtual unsigned memalign(unsigned salign);
virtual Expression *defaultInit(Loc loc = 0);
virtual Expression *defaultInitLiteral(Loc loc = 0);
- virtual int isZeroInit(Loc loc = 0); // if initializer is 0
+ virtual int isZeroInit(Loc loc = 0); // if initializer is 0
#if IN_DMD
virtual dt_t **toDt(dt_t **pdt);
#endif
@@ -387,8 +387,8 @@ struct TypeDArray : TypeArray
struct TypeAArray : TypeArray
{
- Type *index; // key type for type checking
- Type *key; // actual key type
+ Type *index; // key type for type checking
+ Type *key; // actual key type
TypeAArray(Type *t, Type *index);
Type *syntaxCopy();
@@ -447,16 +447,16 @@ struct TypeReference : Type
enum RET
{
- RETregs = 1, // returned in registers
- RETstack = 2, // returned on stack
+ RETregs = 1, // returned in registers
+ RETstack = 2, // returned on stack
};
struct TypeFunction : Type
{
- Parameters *parameters; // function parameters
- int varargs; // 1: T t, ...) style for variable number of arguments
- // 2: T t ...) style for variable number of arguments
- enum LINK linkage; // calling convention
+ Parameters *parameters; // function parameters
+ int varargs; // 1: T t, ...) style for variable number of arguments
+ // 2: T t ...) style for variable number of arguments
+ enum LINK linkage; // calling convention
int inuse;
@@ -510,7 +510,7 @@ struct TypeDelegate : Type
struct TypeQualified : Type
{
Loc loc;
- Array idents; // array of Identifier's representing ident.ident.ident etc.
+ Array idents; // array of Identifier's representing ident.ident.ident etc.
TypeQualified(TY ty, Loc loc);
void syntaxCopyHelper(TypeQualified *t);
@@ -518,7 +518,7 @@ struct TypeQualified : Type
void toCBuffer2Helper(OutBuffer *buf, HdrGenState *hgs);
d_uns64 size(Loc loc);
void resolveHelper(Loc loc, Scope *sc, Dsymbol *s, Dsymbol *scopesym,
- Expression **pe, Type **pt, Dsymbol **ps);
+ Expression **pe, Type **pt, Dsymbol **ps);
};
struct TypeIdentifier : TypeQualified
@@ -721,7 +721,7 @@ struct TypeClass : Type
struct TypeTuple : Type
{
- Parameters *arguments; // types making up the tuple
+ Parameters *arguments; // types making up the tuple
TypeTuple(Parameters *arguments);
TypeTuple(Expressions *exps);
diff --git a/dmd/opover.c b/dmd/opover.c
index 25ef466e..54f4de33 100644
--- a/dmd/opover.c
+++ b/dmd/opover.c
@@ -45,7 +45,7 @@ static void templateResolve(Match *m, TemplateDeclaration *td, Scope *sc, Loc lo
int Expression::isCommutative()
{
- return FALSE; // default is no reverse
+ return FALSE; // default is no reverse
}
/***********************************
@@ -82,8 +82,8 @@ Identifier *InExp::opId() { return Id::opIn; }
Identifier *InExp::opId_r() { return Id::opIn_r; }
Identifier *PostExp::opId() { return (op == TOKplusplus)
- ? Id::postinc
- : Id::postdec; }
+ ? Id::postinc
+ : Id::postdec; }
int AddExp::isCommutative() { return TRUE; }
Identifier *AddExp::opId() { return Id::add; }
@@ -146,7 +146,7 @@ Identifier *EqualExp::opId() { return Id::eq; }
int CmpExp::isCommutative() { return TRUE; }
Identifier *CmpExp::opId() { return Id::cmp; }
-Identifier *ArrayExp::opId() { return Id::index; }
+Identifier *ArrayExp::opId() { return Id::index; }
/************************************
@@ -165,48 +165,48 @@ Expression *UnaExp::op_overload(Scope *sc)
if (t1->ty == Tclass)
{
- ad = ((TypeClass *)t1)->sym;
- goto L1;
+ ad = ((TypeClass *)t1)->sym;
+ goto L1;
}
else if (t1->ty == Tstruct)
{
- ad = ((TypeStruct *)t1)->sym;
+ ad = ((TypeStruct *)t1)->sym;
L1:
- fd = search_function(ad, opId());
- if (fd)
- {
- if (op == TOKarray)
- {
- /* Rewrite op e1[arguments] as:
- * e1.fd(arguments)
- */
- Expression *e = new DotIdExp(loc, e1, fd->ident);
- ArrayExp *ae = (ArrayExp *)this;
- e = new CallExp(loc, e, ae->arguments);
- e = e->semantic(sc);
- return e;
- }
- else
- {
- // Rewrite +e1 as e1.add()
- return build_overload(loc, sc, e1, NULL, fd->ident);
- }
- }
+ fd = search_function(ad, opId());
+ if (fd)
+ {
+ if (op == TOKarray)
+ {
+ /* Rewrite op e1[arguments] as:
+ * e1.fd(arguments)
+ */
+ Expression *e = new DotIdExp(loc, e1, fd->ident);
+ ArrayExp *ae = (ArrayExp *)this;
+ e = new CallExp(loc, e, ae->arguments);
+ e = e->semantic(sc);
+ return e;
+ }
+ else
+ {
+ // Rewrite +e1 as e1.add()
+ return build_overload(loc, sc, e1, NULL, fd->ident);
+ }
+ }
#if DMDV2
- // Didn't find it. Forward to aliasthis
- if (ad->aliasthis)
- {
- /* Rewrite op(e1) as:
- * op(e1.aliasthis)
- */
- Expression *e1 = new DotIdExp(loc, this->e1, ad->aliasthis->ident);
- Expression *e = copy();
- ((UnaExp *)e)->e1 = e1;
- e = e->semantic(sc);
- return e;
- }
+ // Didn't find it. Forward to aliasthis
+ if (ad->aliasthis)
+ {
+ /* Rewrite op(e1) as:
+ * op(e1.aliasthis)
+ */
+ Expression *e1 = new DotIdExp(loc, this->e1, ad->aliasthis->ident);
+ Expression *e = copy();
+ ((UnaExp *)e)->e1 = e1;
+ e = e->semantic(sc);
+ return e;
+ }
#endif
}
return NULL;
@@ -230,19 +230,19 @@ Expression *BinExp::op_overload(Scope *sc)
AggregateDeclaration *ad1;
if (t1->ty == Tclass)
- ad1 = ((TypeClass *)t1)->sym;
+ ad1 = ((TypeClass *)t1)->sym;
else if (t1->ty == Tstruct)
- ad1 = ((TypeStruct *)t1)->sym;
+ ad1 = ((TypeStruct *)t1)->sym;
else
- ad1 = NULL;
+ ad1 = NULL;
AggregateDeclaration *ad2;
if (t2->ty == Tclass)
- ad2 = ((TypeClass *)t2)->sym;
+ ad2 = ((TypeClass *)t2)->sym;
else if (t2->ty == Tstruct)
- ad2 = ((TypeStruct *)t2)->sym;
+ ad2 = ((TypeStruct *)t2)->sym;
else
- ad2 = NULL;
+ ad2 = NULL;
Dsymbol *s = NULL;
Dsymbol *s_r = NULL;
@@ -250,221 +250,221 @@ Expression *BinExp::op_overload(Scope *sc)
TemplateDeclaration *td = NULL;
if (ad1 && id)
{
- s = search_function(ad1, id);
+ s = search_function(ad1, id);
}
if (ad2 && id_r)
{
- s_r = search_function(ad2, id_r);
+ s_r = search_function(ad2, id_r);
}
if (s || s_r)
{
- /* Try:
- * a.opfunc(b)
- * b.opfunc_r(a)
- * and see which is better.
- */
- Expression *e;
- FuncDeclaration *lastf;
+ /* Try:
+ * a.opfunc(b)
+ * b.opfunc_r(a)
+ * and see which is better.
+ */
+ Expression *e;
+ FuncDeclaration *lastf;
- args1.setDim(1);
- args1.data[0] = (void*) e1;
- args2.setDim(1);
- args2.data[0] = (void*) e2;
- argsset = 1;
+ args1.setDim(1);
+ args1.data[0] = (void*) e1;
+ args2.setDim(1);
+ args2.data[0] = (void*) e2;
+ argsset = 1;
- memset(&m, 0, sizeof(m));
- m.last = MATCHnomatch;
+ memset(&m, 0, sizeof(m));
+ m.last = MATCHnomatch;
- if (s)
- {
- fd = s->isFuncDeclaration();
- if (fd)
- {
- overloadResolveX(&m, fd, NULL, &args2, sc->module);
- }
- else
- { td = s->isTemplateDeclaration();
- templateResolve(&m, td, sc, loc, NULL, NULL, &args2);
- }
- }
-
- lastf = m.lastf;
+ if (s)
+ {
+ fd = s->isFuncDeclaration();
+ if (fd)
+ {
+ overloadResolveX(&m, fd, NULL, &args2, sc->module);
+ }
+ else
+ { td = s->isTemplateDeclaration();
+ templateResolve(&m, td, sc, loc, NULL, NULL, &args2);
+ }
+ }
- if (s_r)
- {
- fd = s_r->isFuncDeclaration();
- if (fd)
- {
- overloadResolveX(&m, fd, NULL, &args1, sc->module);
- }
- else
- { td = s_r->isTemplateDeclaration();
- templateResolve(&m, td, sc, loc, NULL, NULL, &args1);
- }
- }
+ lastf = m.lastf;
- if (m.count > 1)
- {
- // Error, ambiguous
- error("overloads %s and %s both match argument list for %s",
- m.lastf->type->toChars(),
- m.nextf->type->toChars(),
- m.lastf->toChars());
- }
- else if (m.last == MATCHnomatch)
- {
- m.lastf = m.anyf;
- }
+ if (s_r)
+ {
+ fd = s_r->isFuncDeclaration();
+ if (fd)
+ {
+ overloadResolveX(&m, fd, NULL, &args1, sc->module);
+ }
+ else
+ { td = s_r->isTemplateDeclaration();
+ templateResolve(&m, td, sc, loc, NULL, NULL, &args1);
+ }
+ }
- if (op == TOKplusplus || op == TOKminusminus)
- // Kludge because operator overloading regards e++ and e--
- // as unary, but it's implemented as a binary.
- // Rewrite (e1 ++ e2) as e1.postinc()
- // Rewrite (e1 -- e2) as e1.postdec()
- e = build_overload(loc, sc, e1, NULL, id);
- else if (lastf && m.lastf == lastf || m.last == MATCHnomatch)
- // Rewrite (e1 op e2) as e1.opfunc(e2)
- e = build_overload(loc, sc, e1, e2, id);
- else
- // Rewrite (e1 op e2) as e2.opfunc_r(e1)
- e = build_overload(loc, sc, e2, e1, id_r);
- return e;
+ if (m.count > 1)
+ {
+ // Error, ambiguous
+ error("overloads %s and %s both match argument list for %s",
+ m.lastf->type->toChars(),
+ m.nextf->type->toChars(),
+ m.lastf->toChars());
+ }
+ else if (m.last == MATCHnomatch)
+ {
+ m.lastf = m.anyf;
+ }
+
+ if (op == TOKplusplus || op == TOKminusminus)
+ // Kludge because operator overloading regards e++ and e--
+ // as unary, but it's implemented as a binary.
+ // Rewrite (e1 ++ e2) as e1.postinc()
+ // Rewrite (e1 -- e2) as e1.postdec()
+ e = build_overload(loc, sc, e1, NULL, id);
+ else if (lastf && m.lastf == lastf || m.last == MATCHnomatch)
+ // Rewrite (e1 op e2) as e1.opfunc(e2)
+ e = build_overload(loc, sc, e1, e2, id);
+ else
+ // Rewrite (e1 op e2) as e2.opfunc_r(e1)
+ e = build_overload(loc, sc, e2, e1, id_r);
+ return e;
}
if (isCommutative())
{
- s = NULL;
- s_r = NULL;
- if (ad1 && id_r)
- {
- s_r = search_function(ad1, id_r);
- }
- if (ad2 && id)
- {
- s = search_function(ad2, id);
- }
+ s = NULL;
+ s_r = NULL;
+ if (ad1 && id_r)
+ {
+ s_r = search_function(ad1, id_r);
+ }
+ if (ad2 && id)
+ {
+ s = search_function(ad2, id);
+ }
- if (s || s_r)
- {
- /* Try:
- * a.opfunc_r(b)
- * b.opfunc(a)
- * and see which is better.
- */
- FuncDeclaration *lastf;
+ if (s || s_r)
+ {
+ /* Try:
+ * a.opfunc_r(b)
+ * b.opfunc(a)
+ * and see which is better.
+ */
+ FuncDeclaration *lastf;
- if (!argsset)
- { args1.setDim(1);
- args1.data[0] = (void*) e1;
- args2.setDim(1);
- args2.data[0] = (void*) e2;
- }
+ if (!argsset)
+ { args1.setDim(1);
+ args1.data[0] = (void*) e1;
+ args2.setDim(1);
+ args2.data[0] = (void*) e2;
+ }
- memset(&m, 0, sizeof(m));
- m.last = MATCHnomatch;
+ memset(&m, 0, sizeof(m));
+ m.last = MATCHnomatch;
- if (s_r)
- {
- fd = s_r->isFuncDeclaration();
- if (fd)
- {
- overloadResolveX(&m, fd, NULL, &args2, sc->module);
- }
- else
- { td = s_r->isTemplateDeclaration();
- templateResolve(&m, td, sc, loc, NULL, NULL, &args2);
- }
- }
- lastf = m.lastf;
+ if (s_r)
+ {
+ fd = s_r->isFuncDeclaration();
+ if (fd)
+ {
+ overloadResolveX(&m, fd, NULL, &args2, sc->module);
+ }
+ else
+ { td = s_r->isTemplateDeclaration();
+ templateResolve(&m, td, sc, loc, NULL, NULL, &args2);
+ }
+ }
+ lastf = m.lastf;
- if (s)
- {
- fd = s->isFuncDeclaration();
- if (fd)
- {
- overloadResolveX(&m, fd, NULL, &args1, sc->module);
- }
- else
- { td = s->isTemplateDeclaration();
- templateResolve(&m, td, sc, loc, NULL, NULL, &args1);
- }
- }
+ if (s)
+ {
+ fd = s->isFuncDeclaration();
+ if (fd)
+ {
+ overloadResolveX(&m, fd, NULL, &args1, sc->module);
+ }
+ else
+ { td = s->isTemplateDeclaration();
+ templateResolve(&m, td, sc, loc, NULL, NULL, &args1);
+ }
+ }
- if (m.count > 1)
- {
- // Error, ambiguous
- error("overloads %s and %s both match argument list for %s",
- m.lastf->type->toChars(),
- m.nextf->type->toChars(),
- m.lastf->toChars());
- }
- else if (m.last == MATCHnomatch)
- {
- m.lastf = m.anyf;
- }
+ if (m.count > 1)
+ {
+ // Error, ambiguous
+ error("overloads %s and %s both match argument list for %s",
+ m.lastf->type->toChars(),
+ m.nextf->type->toChars(),
+ m.lastf->toChars());
+ }
+ else if (m.last == MATCHnomatch)
+ {
+ m.lastf = m.anyf;
+ }
- Expression *e;
- if (lastf && m.lastf == lastf ||
- id_r && m.last == MATCHnomatch)
- // Rewrite (e1 op e2) as e1.opfunc_r(e2)
- e = build_overload(loc, sc, e1, e2, id_r);
- else
- // Rewrite (e1 op e2) as e2.opfunc(e1)
- e = build_overload(loc, sc, e2, e1, id);
+ Expression *e;
+ if (lastf && m.lastf == lastf ||
+ id_r && m.last == MATCHnomatch)
+ // Rewrite (e1 op e2) as e1.opfunc_r(e2)
+ e = build_overload(loc, sc, e1, e2, id_r);
+ else
+ // Rewrite (e1 op e2) as e2.opfunc(e1)
+ e = build_overload(loc, sc, e2, e1, id);
- // When reversing operands of comparison operators,
- // need to reverse the sense of the op
- switch (op)
- {
- case TOKlt: op = TOKgt; break;
- case TOKgt: op = TOKlt; break;
- case TOKle: op = TOKge; break;
- case TOKge: op = TOKle; break;
+ // When reversing operands of comparison operators,
+ // need to reverse the sense of the op
+ switch (op)
+ {
+ case TOKlt: op = TOKgt; break;
+ case TOKgt: op = TOKlt; break;
+ case TOKle: op = TOKge; break;
+ case TOKge: op = TOKle; break;
- // Floating point compares
- case TOKule: op = TOKuge; break;
- case TOKul: op = TOKug; break;
- case TOKuge: op = TOKule; break;
- case TOKug: op = TOKul; break;
+ // Floating point compares
+ case TOKule: op = TOKuge; break;
+ case TOKul: op = TOKug; break;
+ case TOKuge: op = TOKule; break;
+ case TOKug: op = TOKul; break;
- // These are symmetric
- case TOKunord:
- case TOKlg:
- case TOKleg:
- case TOKue:
- break;
- }
+ // These are symmetric
+ case TOKunord:
+ case TOKlg:
+ case TOKleg:
+ case TOKue:
+ break;
+ }
- return e;
- }
+ return e;
+ }
}
#if DMDV2
// Try alias this on first operand
if (ad1 && ad1->aliasthis)
{
- /* Rewrite (e1 op e2) as:
- * (e1.aliasthis op e2)
- */
- Expression *e1 = new DotIdExp(loc, this->e1, ad1->aliasthis->ident);
- Expression *e = copy();
- ((BinExp *)e)->e1 = e1;
- e = e->semantic(sc);
- return e;
+ /* Rewrite (e1 op e2) as:
+ * (e1.aliasthis op e2)
+ */
+ Expression *e1 = new DotIdExp(loc, this->e1, ad1->aliasthis->ident);
+ Expression *e = copy();
+ ((BinExp *)e)->e1 = e1;
+ e = e->semantic(sc);
+ return e;
}
// Try alias this on second operand
if (ad2 && ad2->aliasthis)
{
- /* Rewrite (e1 op e2) as:
- * (e1 op e2.aliasthis)
- */
- Expression *e2 = new DotIdExp(loc, this->e2, ad2->aliasthis->ident);
- Expression *e = copy();
- ((BinExp *)e)->e2 = e2;
- e = e->semantic(sc);
- return e;
+ /* Rewrite (e1 op e2) as:
+ * (e1 op e2.aliasthis)
+ */
+ Expression *e2 = new DotIdExp(loc, this->e2, ad2->aliasthis->ident);
+ Expression *e = copy();
+ ((BinExp *)e)->e2 = e2;
+ e = e->semantic(sc);
+ return e;
}
#endif
return NULL;
@@ -484,9 +484,9 @@ Expression *build_overload(Loc loc, Scope *sc, Expression *ethis, Expression *ea
e = new DotIdExp(loc, ethis, id);
if (earg)
- e = new CallExp(loc, e, earg);
+ e = new CallExp(loc, e, earg);
else
- e = new CallExp(loc, e);
+ e = new CallExp(loc, e);
e = e->semantic(sc);
return e;
@@ -504,18 +504,18 @@ Dsymbol *search_function(AggregateDeclaration *ad, Identifier *funcid)
s = ad->search(0, funcid, 0);
if (s)
- { Dsymbol *s2;
+ { Dsymbol *s2;
- //printf("search_function: s = '%s'\n", s->kind());
- s2 = s->toAlias();
- //printf("search_function: s2 = '%s'\n", s2->kind());
- fd = s2->isFuncDeclaration();
- if (fd && fd->type->ty == Tfunction)
- return fd;
+ //printf("search_function: s = '%s'\n", s->kind());
+ s2 = s->toAlias();
+ //printf("search_function: s2 = '%s'\n", s2->kind());
+ fd = s2->isFuncDeclaration();
+ if (fd && fd->type->ty == Tfunction)
+ return fd;
- td = s2->isTemplateDeclaration();
- if (td)
- return td;
+ td = s2->isTemplateDeclaration();
+ if (td)
+ return td;
}
return NULL;
}
@@ -530,16 +530,16 @@ Dsymbol *search_function(AggregateDeclaration *ad, Identifier *funcid)
void inferApplyArgTypes(enum TOK op, Parameters *arguments, Expression *aggr, Module* from)
{
if (!arguments || !arguments->dim)
- return;
+ return;
/* Return if no arguments need types.
*/
for (size_t u = 0; 1; u++)
- { if (u == arguments->dim)
- return;
- Parameter *arg = (Parameter *)arguments->data[u];
- if (!arg->type)
- break;
+ { if (u == arguments->dim)
+ return;
+ Parameter *arg = (Parameter *)arguments->data[u];
+ if (!arg->type)
+ break;
}
AggregateDeclaration *ad;
@@ -547,97 +547,97 @@ void inferApplyArgTypes(enum TOK op, Parameters *arguments, Expression *aggr, Mo
Parameter *arg = (Parameter *)arguments->data[0];
Type *taggr = aggr->type;
if (!taggr)
- return;
+ return;
Type *tab = taggr->toBasetype();
switch (tab->ty)
{
- case Tarray:
- case Tsarray:
- case Ttuple:
- if (arguments->dim == 2)
- {
- if (!arg->type)
- arg->type = Type::tsize_t; // key type
- arg = (Parameter *)arguments->data[1];
- }
- if (!arg->type && tab->ty != Ttuple)
- arg->type = tab->nextOf(); // value type
- break;
+ case Tarray:
+ case Tsarray:
+ case Ttuple:
+ if (arguments->dim == 2)
+ {
+ if (!arg->type)
+ arg->type = Type::tsize_t; // key type
+ arg = (Parameter *)arguments->data[1];
+ }
+ if (!arg->type && tab->ty != Ttuple)
+ arg->type = tab->nextOf(); // value type
+ break;
- case Taarray:
- { TypeAArray *taa = (TypeAArray *)tab;
+ case Taarray:
+ { TypeAArray *taa = (TypeAArray *)tab;
- if (arguments->dim == 2)
- {
- if (!arg->type)
- arg->type = taa->index; // key type
- arg = (Parameter *)arguments->data[1];
- }
- if (!arg->type)
- arg->type = taa->next; // value type
- break;
- }
+ if (arguments->dim == 2)
+ {
+ if (!arg->type)
+ arg->type = taa->index; // key type
+ arg = (Parameter *)arguments->data[1];
+ }
+ if (!arg->type)
+ arg->type = taa->next; // value type
+ break;
+ }
- case Tclass:
- ad = ((TypeClass *)tab)->sym;
- goto Laggr;
+ case Tclass:
+ ad = ((TypeClass *)tab)->sym;
+ goto Laggr;
- case Tstruct:
- ad = ((TypeStruct *)tab)->sym;
- goto Laggr;
+ case Tstruct:
+ ad = ((TypeStruct *)tab)->sym;
+ goto Laggr;
- Laggr:
+ Laggr:
#if 0
- if (arguments->dim == 1)
- {
- if (!arg->type)
- {
- /* Look for an opNext() overload
- */
- Dsymbol *s = search_function(ad, Id::next);
- fd = s ? s->isFuncDeclaration() : NULL;
- if (!fd)
- goto Lapply;
- arg->type = fd->type->next;
- }
- break;
- }
+ if (arguments->dim == 1)
+ {
+ if (!arg->type)
+ {
+ /* Look for an opNext() overload
+ */
+ Dsymbol *s = search_function(ad, Id::next);
+ fd = s ? s->isFuncDeclaration() : NULL;
+ if (!fd)
+ goto Lapply;
+ arg->type = fd->type->next;
+ }
+ break;
+ }
#endif
- Lapply:
- { /* Look for an
- * int opApply(int delegate(ref Type [, ...]) dg);
- * overload
- */
- Dsymbol *s = search_function(ad,
- (op == TOKforeach_reverse) ? Id::applyReverse
- : Id::apply);
- if (s)
- {
- FuncDeclaration *fd = s->isFuncDeclaration();
- if (fd)
- inferApplyArgTypesX(from, fd, arguments);
- }
- break;
- }
+ Lapply:
+ { /* Look for an
+ * int opApply(int delegate(ref Type [, ...]) dg);
+ * overload
+ */
+ Dsymbol *s = search_function(ad,
+ (op == TOKforeach_reverse) ? Id::applyReverse
+ : Id::apply);
+ if (s)
+ {
+ FuncDeclaration *fd = s->isFuncDeclaration();
+ if (fd)
+ inferApplyArgTypesX(from, fd, arguments);
+ }
+ break;
+ }
- case Tdelegate:
- {
- if (0 && aggr->op == TOKdelegate)
- { DelegateExp *de = (DelegateExp *)aggr;
+ case Tdelegate:
+ {
+ if (0 && aggr->op == TOKdelegate)
+ { DelegateExp *de = (DelegateExp *)aggr;
- FuncDeclaration *fd = de->func->isFuncDeclaration();
- if (fd)
- inferApplyArgTypesX(from, fd, arguments);
- }
- else
- {
- inferApplyArgTypesY((TypeFunction *)tab->nextOf(), arguments);
- }
- break;
- }
+ FuncDeclaration *fd = de->func->isFuncDeclaration();
+ if (fd)
+ inferApplyArgTypesX(from, fd, arguments);
+ }
+ else
+ {
+ inferApplyArgTypesY((TypeFunction *)tab->nextOf(), arguments);
+ }
+ break;
+ }
- default:
- break; // ignore error, caught later
+ default:
+ break; // ignore error, caught later
}
}
@@ -651,9 +651,9 @@ int fp3(void *param, FuncDeclaration *f)
Parameters *arguments = (Parameters *)param;
TypeFunction *tf = (TypeFunction *)f->type;
if (inferApplyArgTypesY(tf, arguments) == 1)
- return 0;
+ return 0;
if (arguments->dim == 0)
- return 1;
+ return 1;
return 0;
}
@@ -670,39 +670,39 @@ static void inferApplyArgTypesX(FuncDeclaration *fstart, Parameters *arguments)
for (d = fstart; d; d = next)
{
- FuncDeclaration *f;
- FuncAliasDeclaration *fa;
- AliasDeclaration *a;
+ FuncDeclaration *f;
+ FuncAliasDeclaration *fa;
+ AliasDeclaration *a;
- fa = d->isFuncAliasDeclaration();
- if (fa)
- {
- inferApplyArgTypesX(fa->funcalias, arguments);
- next = fa->overnext;
- }
- else if ((f = d->isFuncDeclaration()) != NULL)
- {
- next = f->overnext;
+ fa = d->isFuncAliasDeclaration();
+ if (fa)
+ {
+ inferApplyArgTypesX(fa->funcalias, arguments);
+ next = fa->overnext;
+ }
+ else if ((f = d->isFuncDeclaration()) != NULL)
+ {
+ next = f->overnext;
- TypeFunction *tf = (TypeFunction *)f->type;
- if (inferApplyArgTypesY(tf, arguments) == 1)
- continue;
- if (arguments->dim == 0)
- return;
- }
- else if ((a = d->isAliasDeclaration()) != NULL)
- {
- Dsymbol *s = a->toAlias();
- next = s->isDeclaration();
- if (next == a)
- break;
- if (next == fstart)
- break;
- }
- else
- { d->error("is aliased to a function");
- break;
- }
+ TypeFunction *tf = (TypeFunction *)f->type;
+ if (inferApplyArgTypesY(tf, arguments) == 1)
+ continue;
+ if (arguments->dim == 0)
+ return;
+ }
+ else if ((a = d->isAliasDeclaration()) != NULL)
+ {
+ Dsymbol *s = a->toAlias();
+ next = s->isDeclaration();
+ if (next == a)
+ break;
+ if (next == fstart)
+ break;
+ }
+ else
+ { d->error("is aliased to a function");
+ break;
+ }
}
}
#endif
@@ -710,8 +710,8 @@ static void inferApplyArgTypesX(FuncDeclaration *fstart, Parameters *arguments)
/******************************
* Infer arguments from type of function.
* Returns:
- * 0 match for this function
- * 1 no match for this function
+ * 0 match for this function
+ * 1 no match for this function
*/
static int inferApplyArgTypesY(TypeFunction *tf, Parameters *arguments)
@@ -719,10 +719,10 @@ static int inferApplyArgTypesY(TypeFunction *tf, Parameters *arguments)
Parameter *p;
if (Parameter::dim(tf->parameters) != 1)
- goto Lnomatch;
+ goto Lnomatch;
p = Parameter::getNth(tf->parameters, 0);
if (p->type->ty != Tdelegate)
- goto Lnomatch;
+ goto Lnomatch;
tf = (TypeFunction *)p->type->nextOf();
assert(tf->ty == Tfunction);
@@ -731,26 +731,26 @@ static int inferApplyArgTypesY(TypeFunction *tf, Parameters *arguments)
*/
nparams = Parameter::dim(tf->parameters);
if (nparams == 0 || tf->varargs)
- goto Lnomatch; // not enough parameters
+ goto Lnomatch; // not enough parameters
if (arguments->dim != nparams)
- goto Lnomatch; // not enough parameters
+ goto Lnomatch; // not enough parameters
for (size_t u = 0; u < nparams; u++)
{
- Parameter *arg = (Parameter *)arguments->data[u];
- Parameter *param = Parameter::getNth(tf->parameters, u);
- if (arg->type)
- { if (!arg->type->equals(param->type))
- {
- /* Cannot resolve argument types. Indicate an
- * error by setting the number of arguments to 0.
- */
- arguments->dim = 0;
- goto Lmatch;
- }
- continue;
- }
- arg->type = param->type;
+ Parameter *arg = (Parameter *)arguments->data[u];
+ Parameter *param = Parameter::getNth(tf->parameters, u);
+ if (arg->type)
+ { if (!arg->type->equals(param->type))
+ {
+ /* Cannot resolve argument types. Indicate an
+ * error by setting the number of arguments to 0.
+ */
+ arguments->dim = 0;
+ goto Lmatch;
+ }
+ continue;
+ }
+ arg->type = param->type;
}
Lmatch:
return 0;
@@ -769,18 +769,18 @@ static void templateResolve(Match *m, TemplateDeclaration *td, Scope *sc, Loc lo
assert(td);
fd = td->deduceFunctionTemplate(sc, loc, targsi, NULL, arguments);
if (!fd)
- return;
+ return;
m->anyf = fd;
if (m->last >= MATCHexact)
{
- m->nextf = fd;
- m->count++;
+ m->nextf = fd;
+ m->count++;
}
else
{
- m->last = MATCHexact;
- m->lastf = fd;
- m->count = 1;
+ m->last = MATCHexact;
+ m->lastf = fd;
+ m->count = 1;
}
}
diff --git a/dmd/optimize.c b/dmd/optimize.c
index f8f0c19b..86edce0b 100644
--- a/dmd/optimize.c
+++ b/dmd/optimize.c
@@ -32,7 +32,7 @@
extern "C" bool real_isnan (const real_t *);
#endif
-static real_t zero; // work around DMC bug for now
+static real_t zero; // work around DMC bug for now
/*************************************
@@ -44,13 +44,13 @@ Expression *fromConstInitializer(Expression *e1)
{
//printf("fromConstInitializer(%s)\n", e1->toChars());
if (e1->op == TOKvar)
- { VarExp *ve = (VarExp *)e1;
- VarDeclaration *v = ve->var->isVarDeclaration();
- if (v && v->isConst() && v->init)
- { Expression *ei = v->init->toExpression();
- if (ei && ei->type)
- e1 = ei;
- }
+ { VarExp *ve = (VarExp *)e1;
+ VarDeclaration *v = ve->var->isVarDeclaration();
+ if (v && v->isConst() && v->init)
+ { Expression *ei = v->init->toExpression();
+ if (ei && ei->type)
+ e1 = ei;
+ }
}
return e1;
}
@@ -66,7 +66,7 @@ Expression *VarExp::optimize(int result)
{
if (result & WANTinterpret)
{
- return fromConstInitializer(this);
+ return fromConstInitializer(this);
}
return this;
}
@@ -76,8 +76,8 @@ Expression *TupleExp::optimize(int result)
for (size_t i = 0; i < exps->dim; i++)
{ Expression *e = (Expression *)exps->data[i];
- e = e->optimize(WANTvalue | (result & WANTinterpret));
- exps->data[i] = (void *)e;
+ e = e->optimize(WANTvalue | (result & WANTinterpret));
+ exps->data[i] = (void *)e;
}
return this;
}
@@ -86,12 +86,12 @@ Expression *ArrayLiteralExp::optimize(int result)
{
if (elements)
{
- for (size_t i = 0; i < elements->dim; i++)
- { Expression *e = (Expression *)elements->data[i];
+ for (size_t i = 0; i < elements->dim; i++)
+ { Expression *e = (Expression *)elements->data[i];
- e = e->optimize(WANTvalue | (result & WANTinterpret));
- elements->data[i] = (void *)e;
- }
+ e = e->optimize(WANTvalue | (result & WANTinterpret));
+ elements->data[i] = (void *)e;
+ }
}
return this;
}
@@ -102,12 +102,12 @@ Expression *AssocArrayLiteralExp::optimize(int result)
for (size_t i = 0; i < keys->dim; i++)
{ Expression *e = (Expression *)keys->data[i];
- e = e->optimize(WANTvalue | (result & WANTinterpret));
- keys->data[i] = (void *)e;
+ e = e->optimize(WANTvalue | (result & WANTinterpret));
+ keys->data[i] = (void *)e;
- e = (Expression *)values->data[i];
- e = e->optimize(WANTvalue | (result & WANTinterpret));
- values->data[i] = (void *)e;
+ e = (Expression *)values->data[i];
+ e = e->optimize(WANTvalue | (result & WANTinterpret));
+ values->data[i] = (void *)e;
}
return this;
}
@@ -116,13 +116,13 @@ Expression *StructLiteralExp::optimize(int result)
{
if (elements)
{
- for (size_t i = 0; i < elements->dim; i++)
- { Expression *e = (Expression *)elements->data[i];
- if (!e)
- continue;
- e = e->optimize(WANTvalue | (result & WANTinterpret));
- elements->data[i] = (void *)e;
- }
+ for (size_t i = 0; i < elements->dim; i++)
+ { Expression *e = (Expression *)elements->data[i];
+ if (!e)
+ continue;
+ e = e->optimize(WANTvalue | (result & WANTinterpret));
+ elements->data[i] = (void *)e;
+ }
}
return this;
}
@@ -144,10 +144,10 @@ Expression *NegExp::optimize(int result)
e1 = e1->optimize(result);
if (e1->isConst() == 1)
{
- e = Neg(type, e1);
+ e = Neg(type, e1);
}
else
- e = this;
+ e = this;
return e;
}
@@ -157,10 +157,10 @@ Expression *ComExp::optimize(int result)
e1 = e1->optimize(result);
if (e1->isConst() == 1)
{
- e = Com(type, e1);
+ e = Com(type, e1);
}
else
- e = this;
+ e = this;
return e;
}
@@ -170,10 +170,10 @@ Expression *NotExp::optimize(int result)
e1 = e1->optimize(result);
if (e1->isConst() == 1)
{
- e = Not(type, e1);
+ e = Not(type, e1);
}
else
- e = this;
+ e = this;
return e;
}
@@ -183,10 +183,10 @@ Expression *BoolExp::optimize(int result)
e1 = e1->optimize(result);
if (e1->isConst() == 1)
{
- e = Bool(type, e1);
+ e = Bool(type, e1);
}
else
- e = this;
+ e = this;
return e;
}
@@ -199,49 +199,49 @@ Expression *AddrExp::optimize(int result)
e1 = e1->optimize(result & ~WANTinterpret);
// Convert &*ex to ex
if (e1->op == TOKstar)
- { Expression *ex;
+ { Expression *ex;
- ex = ((PtrExp *)e1)->e1;
- if (type->equals(ex->type))
- e = ex;
- else
- {
- e = ex->copy();
- e->type = type;
- }
- return e;
+ ex = ((PtrExp *)e1)->e1;
+ if (type->equals(ex->type))
+ e = ex;
+ else
+ {
+ e = ex->copy();
+ e->type = type;
+ }
+ return e;
}
#if !IN_LLVM
if (e1->op == TOKvar)
- { VarExp *ve = (VarExp *)e1;
- if (!ve->var->isOut() && !ve->var->isRef() &&
- !ve->var->isImportedSymbol())
- {
- e = new SymOffExp(loc, ve->var, 0);
- e->type = type;
- return e;
- }
+ { VarExp *ve = (VarExp *)e1;
+ if (!ve->var->isOut() && !ve->var->isRef() &&
+ !ve->var->isImportedSymbol())
+ {
+ e = new SymOffExp(loc, ve->var, 0);
+ e->type = type;
+ return e;
+ }
}
if (e1->op == TOKindex)
- { // Convert &array[n] to &array+n
- IndexExp *ae = (IndexExp *)e1;
+ { // Convert &array[n] to &array+n
+ IndexExp *ae = (IndexExp *)e1;
- if (ae->e2->op == TOKint64 && ae->e1->op == TOKvar)
- {
- dinteger_t index = ae->e2->toInteger();
- VarExp *ve = (VarExp *)ae->e1;
- if (ve->type->ty == Tsarray && ve->type->next->ty != Tbit
- && !ve->var->isImportedSymbol())
- {
- TypeSArray *ts = (TypeSArray *)ve->type;
- dinteger_t dim = ts->dim->toInteger();
- if (index < 0 || index >= dim)
- error("array index %jd is out of bounds [0..%jd]", index, dim);
- e = new SymOffExp(loc, ve->var, index * ts->next->size());
- e->type = type;
- return e;
- }
- }
+ if (ae->e2->op == TOKint64 && ae->e1->op == TOKvar)
+ {
+ dinteger_t index = ae->e2->toInteger();
+ VarExp *ve = (VarExp *)ae->e1;
+ if (ve->type->ty == Tsarray && ve->type->next->ty != Tbit
+ && !ve->var->isImportedSymbol())
+ {
+ TypeSArray *ts = (TypeSArray *)ve->type;
+ dinteger_t dim = ts->dim->toInteger();
+ if (index < 0 || index >= dim)
+ error("array index %jd is out of bounds [0..%jd]", index, dim);
+ e = new SymOffExp(loc, ve->var, index * ts->next->size());
+ e->type = type;
+ return e;
+ }
+ }
}
#endif
return this;
@@ -253,26 +253,26 @@ Expression *PtrExp::optimize(int result)
e1 = e1->optimize(result);
// Convert *&ex to ex
if (e1->op == TOKaddress)
- { Expression *e;
- Expression *ex;
+ { Expression *e;
+ Expression *ex;
- ex = ((AddrExp *)e1)->e1;
- if (type->equals(ex->type))
- e = ex;
- else
- {
- e = ex->copy();
- e->type = type;
- }
- return e;
+ ex = ((AddrExp *)e1)->e1;
+ if (type->equals(ex->type))
+ e = ex;
+ else
+ {
+ e = ex->copy();
+ e->type = type;
+ }
+ return e;
}
// Constant fold *(&structliteral + offset)
if (e1->op == TOKadd)
{
- Expression *e;
- e = Ptr(type, e1);
- if (e != EXP_CANT_INTERPRET)
- return e;
+ Expression *e;
+ e = Ptr(type, e1);
+ if (e != EXP_CANT_INTERPRET)
+ return e;
}
return this;
@@ -285,31 +285,31 @@ Expression *DotVarExp::optimize(int result)
#if DMDV2
if (e1->op == TOKvar)
- { VarExp *ve = (VarExp *)e1;
- VarDeclaration *v = ve->var->isVarDeclaration();
- Expression *e = expandVar(result, v);
- if (e && e->op == TOKstructliteral)
- { StructLiteralExp *sle = (StructLiteralExp *)e;
- VarDeclaration *vf = var->isVarDeclaration();
- if (vf)
- {
- e = sle->getField(type, vf->offset);
- if (e && e != EXP_CANT_INTERPRET)
- return e;
- }
- }
+ { VarExp *ve = (VarExp *)e1;
+ VarDeclaration *v = ve->var->isVarDeclaration();
+ Expression *e = expandVar(result, v);
+ if (e && e->op == TOKstructliteral)
+ { StructLiteralExp *sle = (StructLiteralExp *)e;
+ VarDeclaration *vf = var->isVarDeclaration();
+ if (vf)
+ {
+ e = sle->getField(type, vf->offset);
+ if (e && e != EXP_CANT_INTERPRET)
+ return e;
+ }
+ }
}
else
#endif
if (e1->op == TOKstructliteral)
{ StructLiteralExp *sle = (StructLiteralExp *)e1;
- VarDeclaration *vf = var->isVarDeclaration();
- if (vf)
- {
- Expression *e = sle->getField(type, vf->offset);
- if (e && e != EXP_CANT_INTERPRET)
- return e;
- }
+ VarDeclaration *vf = var->isVarDeclaration();
+ if (vf)
+ {
+ Expression *e = sle->getField(type, vf->offset);
+ if (e && e != EXP_CANT_INTERPRET)
+ return e;
+ }
}
return this;
@@ -318,27 +318,27 @@ Expression *DotVarExp::optimize(int result)
Expression *NewExp::optimize(int result)
{
if (thisexp)
- thisexp = thisexp->optimize(WANTvalue);
+ thisexp = thisexp->optimize(WANTvalue);
// Optimize parameters
if (newargs)
{
- for (size_t i = 0; i < newargs->dim; i++)
- { Expression *e = (Expression *)newargs->data[i];
+ for (size_t i = 0; i < newargs->dim; i++)
+ { Expression *e = (Expression *)newargs->data[i];
- e = e->optimize(WANTvalue);
- newargs->data[i] = (void *)e;
- }
+ e = e->optimize(WANTvalue);
+ newargs->data[i] = (void *)e;
+ }
}
if (arguments)
{
- for (size_t i = 0; i < arguments->dim; i++)
- { Expression *e = (Expression *)arguments->data[i];
+ for (size_t i = 0; i < arguments->dim; i++)
+ { Expression *e = (Expression *)arguments->data[i];
- e = e->optimize(WANTvalue);
- arguments->data[i] = (void *)e;
- }
+ e = e->optimize(WANTvalue);
+ arguments->data[i] = (void *)e;
+ }
}
return this;
}
@@ -351,24 +351,24 @@ Expression *CallExp::optimize(int result)
// Optimize parameters
if (arguments)
{
- for (size_t i = 0; i < arguments->dim; i++)
- { Expression *e = (Expression *)arguments->data[i];
+ for (size_t i = 0; i < arguments->dim; i++)
+ { Expression *e = (Expression *)arguments->data[i];
- e = e->optimize(WANTvalue);
- arguments->data[i] = (void *)e;
- }
+ e = e->optimize(WANTvalue);
+ arguments->data[i] = (void *)e;
+ }
}
e1 = e1->optimize(result);
if (result & WANTinterpret)
{
Expression *eresult = interpret(NULL);
- if (eresult == EXP_CANT_INTERPRET)
- return e;
- if (eresult && eresult != EXP_VOID_INTERPRET)
- e = eresult;
- else
- error("cannot evaluate %s at compile time", toChars());
+ if (eresult == EXP_CANT_INTERPRET)
+ return e;
+ if (eresult && eresult != EXP_VOID_INTERPRET)
+ e = eresult;
+ else
+ error("cannot evaluate %s at compile time", toChars());
}
return e;
}
@@ -386,67 +386,67 @@ Expression *CastExp::optimize(int result)
e1 = e1->optimize(result);
if (result & WANTinterpret)
- e1 = fromConstInitializer(e1);
+ e1 = fromConstInitializer(e1);
if ((e1->op == TOKstring || e1->op == TOKarrayliteral) &&
- (type->ty == Tpointer || type->ty == Tarray) &&
- type->next->equals(e1->type->next)
+ (type->ty == Tpointer || type->ty == Tarray) &&
+ type->next->equals(e1->type->next)
)
{
- // make a copy before adjusting type to avoid
- // messing up the type of an existing initializer
- e1 = e1->syntaxCopy();
- e1->type = type;
- return e1;
+ // make a copy before adjusting type to avoid
+ // messing up the type of an existing initializer
+ e1 = e1->syntaxCopy();
+ e1->type = type;
+ return e1;
}
/* The first test here is to prevent infinite loops
*/
if (op1 != TOKarrayliteral && e1->op == TOKarrayliteral)
- return e1->castTo(NULL, to);
+ return e1->castTo(NULL, to);
if (e1->op == TOKnull &&
- (type->ty == Tpointer || type->ty == Tclass))
+ (type->ty == Tpointer || type->ty == Tclass))
{
- e1->type = type;
- return e1;
+ e1->type = type;
+ return e1;
}
if (result & WANTflags && type->ty == Tclass && e1->type->ty == Tclass)
{
- // See if we can remove an unnecessary cast
- ClassDeclaration *cdfrom;
- ClassDeclaration *cdto;
- int offset;
+ // See if we can remove an unnecessary cast
+ ClassDeclaration *cdfrom;
+ ClassDeclaration *cdto;
+ int offset;
- cdfrom = e1->type->isClassHandle();
- cdto = type->isClassHandle();
- if (cdto->isBaseOf(cdfrom, &offset) && offset == 0)
- {
- e1->type = type;
- return e1;
- }
+ cdfrom = e1->type->isClassHandle();
+ cdto = type->isClassHandle();
+ if (cdto->isBaseOf(cdfrom, &offset) && offset == 0)
+ {
+ e1->type = type;
+ return e1;
+ }
}
Expression *e;
if (e1->isConst())
{
- if (e1->op == TOKsymoff)
- {
- if (type->size() == e1->type->size() &&
- type->toBasetype()->ty != Tsarray)
- {
- e1->type = type;
- return e1;
- }
- return this;
- }
- if (to->toBasetype()->ty == Tvoid)
- e = this;
- else
- e = Cast(type, to, e1);
+ if (e1->op == TOKsymoff)
+ {
+ if (type->size() == e1->type->size() &&
+ type->toBasetype()->ty != Tsarray)
+ {
+ e1->type = type;
+ return e1;
+ }
+ return this;
+ }
+ if (to->toBasetype()->ty == Tvoid)
+ e = this;
+ else
+ e = Cast(type, to, e1);
}
else
- e = this;
+ e = this;
return e;
}
@@ -457,15 +457,15 @@ Expression *BinExp::optimize(int result)
e2 = e2->optimize(result);
if (op == TOKshlass || op == TOKshrass || op == TOKushrass)
{
- if (e2->isConst() == 1)
- {
- dinteger_t i2 = e2->toInteger();
- d_uns64 sz = e1->type->size() * 8;
- if (i2 < 0 || i2 > sz)
- { error("shift assign by %jd is outside the range 0..%zu", i2, sz);
- e2 = new IntegerExp(0);
- }
- }
+ if (e2->isConst() == 1)
+ {
+ dinteger_t i2 = e2->toInteger();
+ d_uns64 sz = e1->type->size() * 8;
+ if (i2 < 0 || i2 > sz)
+ { error("shift assign by %jd is outside the range 0..%zu", i2, sz);
+ e2 = new IntegerExp(0);
+ }
+ }
}
return this;
}
@@ -478,12 +478,12 @@ Expression *AddExp::optimize(int result)
e2 = e2->optimize(result);
if (e1->isConst() && e2->isConst())
{
- if (e1->op == TOKsymoff && e2->op == TOKsymoff)
- return this;
- e = Add(type, e1, e2);
+ if (e1->op == TOKsymoff && e2->op == TOKsymoff)
+ return this;
+ e = Add(type, e1, e2);
}
else
- e = this;
+ e = this;
return e;
}
@@ -494,12 +494,12 @@ Expression *MinExp::optimize(int result)
e2 = e2->optimize(result);
if (e1->isConst() && e2->isConst())
{
- if (e2->op == TOKsymoff)
- return this;
- e = Min(type, e1, e2);
+ if (e2->op == TOKsymoff)
+ return this;
+ e = Min(type, e1, e2);
}
else
- e = this;
+ e = this;
return e;
}
@@ -511,10 +511,10 @@ Expression *MulExp::optimize(int result)
e2 = e2->optimize(result);
if (e1->isConst() == 1 && e2->isConst() == 1)
{
- e = Mul(type, e1, e2);
+ e = Mul(type, e1, e2);
}
else
- e = this;
+ e = this;
return e;
}
@@ -526,10 +526,10 @@ Expression *DivExp::optimize(int result)
e2 = e2->optimize(result);
if (e1->isConst() == 1 && e2->isConst() == 1)
{
- e = Div(type, e1, e2);
+ e = Div(type, e1, e2);
}
else
- e = this;
+ e = this;
return e;
}
@@ -540,10 +540,10 @@ Expression *ModExp::optimize(int result)
e2 = e2->optimize(result);
if (e1->isConst() == 1 && e2->isConst() == 1)
{
- e = Mod(type, e1, e2);
+ e = Mod(type, e1, e2);
}
else
- e = this;
+ e = this;
return e;
}
@@ -554,14 +554,14 @@ Expression *shift_optimize(int result, BinExp *e, Expression *(*shift)(Type *, E
e->e2 = e->e2->optimize(result);
if (e->e2->isConst() == 1)
{
- dinteger_t i2 = e->e2->toInteger();
- d_uns64 sz = e->e1->type->size() * 8;
- if (i2 < 0 || i2 > sz)
- { e->error("shift by %jd is outside the range 0..%zu", i2, sz);
- e->e2 = new IntegerExp(0);
- }
- if (e->e1->isConst() == 1)
- ex = (*shift)(e->type, e->e1, e->e2);
+ dinteger_t i2 = e->e2->toInteger();
+ d_uns64 sz = e->e1->type->size() * 8;
+ if (i2 < 0 || i2 > sz)
+ { e->error("shift by %jd is outside the range 0..%zu", i2, sz);
+ e->e2 = new IntegerExp(0);
+ }
+ if (e->e1->isConst() == 1)
+ ex = (*shift)(e->type, e->e1, e->e2);
}
return ex;
}
@@ -590,9 +590,9 @@ Expression *AndExp::optimize(int result)
e1 = e1->optimize(result);
e2 = e2->optimize(result);
if (e1->isConst() == 1 && e2->isConst() == 1)
- e = And(type, e1, e2);
+ e = And(type, e1, e2);
else
- e = this;
+ e = this;
return e;
}
@@ -602,9 +602,9 @@ Expression *OrExp::optimize(int result)
e1 = e1->optimize(result);
e2 = e2->optimize(result);
if (e1->isConst() == 1 && e2->isConst() == 1)
- e = Or(type, e1, e2);
+ e = Or(type, e1, e2);
else
- e = this;
+ e = this;
return e;
}
@@ -614,9 +614,9 @@ Expression *XorExp::optimize(int result)
e1 = e1->optimize(result);
e2 = e2->optimize(result);
if (e1->isConst() == 1 && e2->isConst() == 1)
- e = Xor(type, e1, e2);
+ e = Xor(type, e1, e2);
else
- e = this;
+ e = this;
return e;
}
@@ -633,8 +633,8 @@ Expression *CommaExp::optimize(int result)
if (result & WANTinterpret)
{ // Interpreting comma needs special treatment, because it may
// contain compiler-generated declarations.
- e = interpret(NULL);
- return (e == EXP_CANT_INTERPRET) ? this : e;
+ e = interpret(NULL);
+ return (e == EXP_CANT_INTERPRET) ? this : e;
}
// Don't constant fold if it is a compiler-generated temporary.
if (e1->op == TOKdeclaration)
@@ -644,12 +644,12 @@ Expression *CommaExp::optimize(int result)
e2 = e2->optimize(result);
if (!e1 || e1->op == TOKint64 || e1->op == TOKfloat64 || !e1->checkSideEffect(2))
{
- e = e2;
- if (e)
- e->type = type;
+ e = e2;
+ if (e)
+ e->type = type;
}
else
- e = this;
+ e = this;
//printf("-CommaExp::optimize(result = %d) %s\n", result, e->toChars());
return e;
}
@@ -662,7 +662,7 @@ Expression *ArrayLengthExp::optimize(int result)
e = this;
if (e1->op == TOKstring || e1->op == TOKarrayliteral || e1->op == TOKassocarrayliteral)
{
- e = ArrayLength(type, e1);
+ e = ArrayLength(type, e1);
}
return e;
}
@@ -680,7 +680,7 @@ Expression *EqualExp::optimize(int result)
e = Equal(op, type, e1, e2);
if (e == EXP_CANT_INTERPRET)
- e = this;
+ e = this;
return e;
}
@@ -692,11 +692,11 @@ Expression *IdentityExp::optimize(int result)
Expression *e = this;
if ((this->e1->isConst() && this->e2->isConst()) ||
- (this->e1->op == TOKnull && this->e2->op == TOKnull))
+ (this->e1->op == TOKnull && this->e2->op == TOKnull))
{
- e = Identity(op, type, this->e1, this->e2);
- if (e == EXP_CANT_INTERPRET)
- e = this;
+ e = Identity(op, type, this->e1, this->e2);
+ if (e == EXP_CANT_INTERPRET)
+ e = this;
}
return e;
}
@@ -707,11 +707,11 @@ Expression *IndexExp::optimize(int result)
//printf("IndexExp::optimize(result = %d) %s\n", result, toChars());
Expression *e1 = this->e1->optimize(WANTvalue | (result & WANTinterpret));
if (result & WANTinterpret)
- e1 = fromConstInitializer(e1);
+ e1 = fromConstInitializer(e1);
e2 = e2->optimize(WANTvalue | (result & WANTinterpret));
e = Index(type, e1, e2);
if (e == EXP_CANT_INTERPRET)
- e = this;
+ e = this;
return e;
}
@@ -722,21 +722,21 @@ Expression *SliceExp::optimize(int result)
e = this;
e1 = e1->optimize(WANTvalue | (result & WANTinterpret));
if (!lwr)
- { if (e1->op == TOKstring)
- { // Convert slice of string literal into dynamic array
- Type *t = e1->type->toBasetype();
- if (t->nextOf())
- e = e1->castTo(NULL, t->nextOf()->arrayOf());
- }
- return e;
+ { if (e1->op == TOKstring)
+ { // Convert slice of string literal into dynamic array
+ Type *t = e1->type->toBasetype();
+ if (t->nextOf())
+ e = e1->castTo(NULL, t->nextOf()->arrayOf());
+ }
+ return e;
}
if (result & WANTinterpret)
- e1 = fromConstInitializer(e1);
+ e1 = fromConstInitializer(e1);
lwr = lwr->optimize(WANTvalue | (result & WANTinterpret));
upr = upr->optimize(WANTvalue | (result & WANTinterpret));
e = Slice(type, e1, lwr, upr);
if (e == EXP_CANT_INTERPRET)
- e = this;
+ e = this;
return e;
}
@@ -748,26 +748,26 @@ Expression *AndAndExp::optimize(int result)
e = this;
if (e1->isBool(FALSE))
{
- e = new CommaExp(loc, e1, new IntegerExp(loc, 0, type));
- e->type = type;
- e = e->optimize(result);
+ e = new CommaExp(loc, e1, new IntegerExp(loc, 0, type));
+ e->type = type;
+ e = e->optimize(result);
}
else
{
- e2 = e2->optimize(WANTflags | (result & WANTinterpret));
- if (result && e2->type->toBasetype()->ty == Tvoid && !global.errors)
- error("void has no value");
- if (e1->isConst())
- {
- if (e2->isConst())
- { int n1 = e1->isBool(1);
- int n2 = e2->isBool(1);
+ e2 = e2->optimize(WANTflags | (result & WANTinterpret));
+ if (result && e2->type->toBasetype()->ty == Tvoid && !global.errors)
+ error("void has no value");
+ if (e1->isConst())
+ {
+ if (e2->isConst())
+ { int n1 = e1->isBool(1);
+ int n2 = e2->isBool(1);
- e = new IntegerExp(loc, n1 && n2, type);
- }
- else if (e1->isBool(TRUE))
- e = new BoolExp(loc, e2, type);
- }
+ e = new IntegerExp(loc, n1 && n2, type);
+ }
+ else if (e1->isBool(TRUE))
+ e = new BoolExp(loc, e2, type);
+ }
}
return e;
}
@@ -778,27 +778,27 @@ Expression *OrOrExp::optimize(int result)
e1 = e1->optimize(WANTflags | (result & WANTinterpret));
e = this;
if (e1->isBool(TRUE))
- { // Replace with (e1, 1)
- e = new CommaExp(loc, e1, new IntegerExp(loc, 1, type));
- e->type = type;
- e = e->optimize(result);
+ { // Replace with (e1, 1)
+ e = new CommaExp(loc, e1, new IntegerExp(loc, 1, type));
+ e->type = type;
+ e = e->optimize(result);
}
else
{
- e2 = e2->optimize(WANTflags | (result & WANTinterpret));
- if (result && e2->type->toBasetype()->ty == Tvoid && !global.errors)
- error("void has no value");
- if (e1->isConst())
- {
- if (e2->isConst())
- { int n1 = e1->isBool(1);
- int n2 = e2->isBool(1);
+ e2 = e2->optimize(WANTflags | (result & WANTinterpret));
+ if (result && e2->type->toBasetype()->ty == Tvoid && !global.errors)
+ error("void has no value");
+ if (e1->isConst())
+ {
+ if (e2->isConst())
+ { int n1 = e1->isBool(1);
+ int n2 = e2->isBool(1);
- e = new IntegerExp(loc, n1 || n2, type);
- }
- else if (e1->isBool(FALSE))
- e = new BoolExp(loc, e2, type);
- }
+ e = new IntegerExp(loc, n1 || n2, type);
+ }
+ else if (e1->isBool(FALSE))
+ e = new BoolExp(loc, e2, type);
+ }
}
return e;
}
@@ -811,10 +811,10 @@ Expression *CmpExp::optimize(int result)
e2 = e2->optimize(result);
if (e1->isConst() == 1 && e2->isConst() == 1)
{
- e = Cmp(op, type, this->e1, this->e2);
+ e = Cmp(op, type, this->e1, this->e2);
}
else
- e = this;
+ e = this;
return e;
}
@@ -826,7 +826,7 @@ Expression *CatExp::optimize(int result)
e2 = e2->optimize(result);
e = Cat(type, e1, e2);
if (e == EXP_CANT_INTERPRET)
- e = this;
+ e = this;
return e;
}
@@ -836,13 +836,13 @@ Expression *CondExp::optimize(int result)
econd = econd->optimize(WANTflags | (result & WANTinterpret));
if (econd->isBool(TRUE))
- e = e1->optimize(result);
+ e = e1->optimize(result);
else if (econd->isBool(FALSE))
- e = e2->optimize(result);
+ e = e2->optimize(result);
else
- { e1 = e1->optimize(result);
- e2 = e2->optimize(result);
- e = this;
+ { e1 = e1->optimize(result);
+ e2 = e2->optimize(result);
+ e = this;
}
return e;
}
diff --git a/dmd/parse.c b/dmd/parse.c
index 88207e34..c0525f74 100644
--- a/dmd/parse.c
+++ b/dmd/parse.c
@@ -39,22 +39,22 @@
// How multiple declarations are parsed.
// If 1, treat as C.
// If 0, treat:
-// int *p, i;
+// int *p, i;
// as:
-// int* p;
-// int* i;
-#define CDECLSYNTAX 0
+// int* p;
+// int* i;
+#define CDECLSYNTAX 0
// Support C cast syntax:
-// (type)(expression)
-#define CCASTSYNTAX 1
+// (type)(expression)
+#define CCASTSYNTAX 1
// Support postfix C array declarations, such as
-// int a[3][4];
-#define CARRAYDECL 1
+// int a[3][4];
+#define CARRAYDECL 1
// Support left-to-right array declarations
-#define LTORARRAYDECL 1
+#define LTORARRAYDECL 1
Parser::Parser(Module *module, unsigned char *base, unsigned length, int doDocComment)
@@ -65,7 +65,7 @@ Parser::Parser(Module *module, unsigned char *base, unsigned length, int doDocCo
linkage = LINKd;
endloc = 0;
inBrackets = 0;
- //nextToken(); // start up the scanner
+ //nextToken(); // start up the scanner
}
Array *Parser::parseModule()
@@ -75,70 +75,70 @@ Array *Parser::parseModule()
// ModuleDeclation leads off
if (token.value == TOKmodule)
{
- unsigned char *comment = token.blockComment;
+ unsigned char *comment = token.blockComment;
- nextToken();
+ nextToken();
#if DMDV2
- if (token.value == TOKlparen)
- {
- nextToken();
- if (token.value != TOKidentifier)
- { error("module (system) identifier expected");
- goto Lerr;
- }
- Identifier *id = token.ident;
+ if (token.value == TOKlparen)
+ {
+ nextToken();
+ if (token.value != TOKidentifier)
+ { error("module (system) identifier expected");
+ goto Lerr;
+ }
+ Identifier *id = token.ident;
- if (id == Id::system)
- safe = TRUE;
- else
- error("(safe) expected, not %s", id->toChars());
- nextToken();
- check(TOKrparen);
- }
+ if (id == Id::system)
+ safe = TRUE;
+ else
+ error("(safe) expected, not %s", id->toChars());
+ nextToken();
+ check(TOKrparen);
+ }
#endif
- if (token.value != TOKidentifier)
- { error("Identifier expected following module");
- goto Lerr;
- }
- else
- {
- Array *a = NULL;
- Identifier *id;
+ if (token.value != TOKidentifier)
+ { error("Identifier expected following module");
+ goto Lerr;
+ }
+ else
+ {
+ Array *a = NULL;
+ Identifier *id;
- id = token.ident;
- while (nextToken() == TOKdot)
- {
- if (!a)
- a = new Array();
- a->push(id);
- nextToken();
- if (token.value != TOKidentifier)
- { error("Identifier expected following package");
- goto Lerr;
- }
- id = token.ident;
- }
+ id = token.ident;
+ while (nextToken() == TOKdot)
+ {
+ if (!a)
+ a = new Array();
+ a->push(id);
+ nextToken();
+ if (token.value != TOKidentifier)
+ { error("Identifier expected following package");
+ goto Lerr;
+ }
+ id = token.ident;
+ }
- md = new ModuleDeclaration(a, id);
+ md = new ModuleDeclaration(a, id);
- if (token.value != TOKsemicolon)
- error("';' expected following module declaration instead of %s", token.toChars());
- nextToken();
- addComment(mod, comment);
- }
+ if (token.value != TOKsemicolon)
+ error("';' expected following module declaration instead of %s", token.toChars());
+ nextToken();
+ addComment(mod, comment);
+ }
}
decldefs = parseDeclDefs(0);
if (token.value != TOKeof)
- { error("unrecognized declaration");
- goto Lerr;
+ { error("unrecognized declaration");
+ goto Lerr;
}
return decldefs;
Lerr:
while (token.value != TOKsemicolon && token.value != TOKeof)
- nextToken();
+ nextToken();
nextToken();
return new Array();
}
@@ -157,360 +157,360 @@ Array *Parser::parseDeclDefs(int once)
decldefs = new Array();
do
{
- comment = token.blockComment;
- switch (token.value)
- {
- case TOKenum:
- s = parseEnum();
- break;
+ comment = token.blockComment;
+ switch (token.value)
+ {
+ case TOKenum:
+ s = parseEnum();
+ break;
- case TOKstruct:
- case TOKunion:
- case TOKclass:
- case TOKinterface:
- s = parseAggregate();
- break;
+ case TOKstruct:
+ case TOKunion:
+ case TOKclass:
+ case TOKinterface:
+ s = parseAggregate();
+ break;
- case TOKimport:
- s = parseImport(decldefs, 0);
- break;
+ case TOKimport:
+ s = parseImport(decldefs, 0);
+ break;
- case TOKtemplate:
- s = (Dsymbol *)parseTemplateDeclaration();
- break;
+ case TOKtemplate:
+ s = (Dsymbol *)parseTemplateDeclaration();
+ break;
- case TOKmixin:
- { Loc loc = this->loc;
- if (peek(&token)->value == TOKlparen)
- { // mixin(string)
- nextToken();
- check(TOKlparen, "mixin");
- Expression *e = parseAssignExp();
- check(TOKrparen);
- check(TOKsemicolon);
- s = new CompileDeclaration(loc, e);
- break;
- }
- s = parseMixin();
- break;
- }
+ case TOKmixin:
+ { Loc loc = this->loc;
+ if (peek(&token)->value == TOKlparen)
+ { // mixin(string)
+ nextToken();
+ check(TOKlparen, "mixin");
+ Expression *e = parseAssignExp();
+ check(TOKrparen);
+ check(TOKsemicolon);
+ s = new CompileDeclaration(loc, e);
+ break;
+ }
+ s = parseMixin();
+ break;
+ }
- case BASIC_TYPES:
- case TOKalias:
- case TOKtypedef:
- case TOKidentifier:
- case TOKtypeof:
- case TOKdot:
- Ldeclaration:
- a = parseDeclarations();
- decldefs->append(a);
- continue;
+ case BASIC_TYPES:
+ case TOKalias:
+ case TOKtypedef:
+ case TOKidentifier:
+ case TOKtypeof:
+ case TOKdot:
+ Ldeclaration:
+ a = parseDeclarations();
+ decldefs->append(a);
+ continue;
- case TOKthis:
- s = parseCtor();
- break;
+ case TOKthis:
+ s = parseCtor();
+ break;
- case TOKtilde:
- s = parseDtor();
- break;
+ case TOKtilde:
+ s = parseDtor();
+ break;
- case TOKinvariant:
+ case TOKinvariant:
#if 1
- s = parseInvariant();
+ s = parseInvariant();
#else
- if (peek(&token)->value == TOKlcurly)
- s = parseInvariant();
- else
- {
- stc = STCimmutable;
- goto Lstc;
- }
+ if (peek(&token)->value == TOKlcurly)
+ s = parseInvariant();
+ else
+ {
+ stc = STCimmutable;
+ goto Lstc;
+ }
#endif
- break;
+ break;
- case TOKunittest:
- s = parseUnitTest();
- break;
+ case TOKunittest:
+ s = parseUnitTest();
+ break;
- case TOKnew:
- s = parseNew();
- break;
+ case TOKnew:
+ s = parseNew();
+ break;
- case TOKdelete:
- s = parseDelete();
- break;
+ case TOKdelete:
+ s = parseDelete();
+ break;
- case TOKeof:
- case TOKrcurly:
- return decldefs;
+ case TOKeof:
+ case TOKrcurly:
+ return decldefs;
- case TOKstatic:
- nextToken();
- if (token.value == TOKthis)
- s = parseStaticCtor();
- else if (token.value == TOKtilde)
- s = parseStaticDtor();
- else if (token.value == TOKassert)
- s = parseStaticAssert();
- else if (token.value == TOKif)
- { condition = parseStaticIfCondition();
- a = parseBlock();
- aelse = NULL;
- if (token.value == TOKelse)
- { nextToken();
- aelse = parseBlock();
- }
- s = new StaticIfDeclaration(condition, a, aelse);
- break;
- }
- else if (token.value == TOKimport)
- {
- s = parseImport(decldefs, 1);
- }
- else
- { stc = STCstatic;
- goto Lstc2;
- }
- break;
+ case TOKstatic:
+ nextToken();
+ if (token.value == TOKthis)
+ s = parseStaticCtor();
+ else if (token.value == TOKtilde)
+ s = parseStaticDtor();
+ else if (token.value == TOKassert)
+ s = parseStaticAssert();
+ else if (token.value == TOKif)
+ { condition = parseStaticIfCondition();
+ a = parseBlock();
+ aelse = NULL;
+ if (token.value == TOKelse)
+ { nextToken();
+ aelse = parseBlock();
+ }
+ s = new StaticIfDeclaration(condition, a, aelse);
+ break;
+ }
+ else if (token.value == TOKimport)
+ {
+ s = parseImport(decldefs, 1);
+ }
+ else
+ { stc = STCstatic;
+ goto Lstc2;
+ }
+ break;
- case TOKconst: stc = STCconst; goto Lstc;
- case TOKfinal: stc = STCfinal; goto Lstc;
- case TOKauto: stc = STCauto; goto Lstc;
- case TOKscope: stc = STCscope; goto Lstc;
- case TOKoverride: stc = STCoverride; goto Lstc;
- case TOKabstract: stc = STCabstract; goto Lstc;
- case TOKsynchronized: stc = STCsynchronized; goto Lstc;
- case TOKdeprecated: stc = STCdeprecated; goto Lstc;
+ case TOKconst: stc = STCconst; goto Lstc;
+ case TOKfinal: stc = STCfinal; goto Lstc;
+ case TOKauto: stc = STCauto; goto Lstc;
+ case TOKscope: stc = STCscope; goto Lstc;
+ case TOKoverride: stc = STCoverride; goto Lstc;
+ case TOKabstract: stc = STCabstract; goto Lstc;
+ case TOKsynchronized: stc = STCsynchronized; goto Lstc;
+ case TOKdeprecated: stc = STCdeprecated; goto Lstc;
#if DMDV2
- case TOKnothrow: stc = STCnothrow; goto Lstc;
- case TOKpure: stc = STCpure; goto Lstc;
- case TOKref: stc = STCref; goto Lstc;
- case TOKtls: stc = STCtls; goto Lstc;
- case TOKgshared: stc = STCgshared; goto Lstc;
- //case TOKmanifest: stc = STCmanifest; goto Lstc;
+ case TOKnothrow: stc = STCnothrow; goto Lstc;
+ case TOKpure: stc = STCpure; goto Lstc;
+ case TOKref: stc = STCref; goto Lstc;
+ case TOKtls: stc = STCtls; goto Lstc;
+ case TOKgshared: stc = STCgshared; goto Lstc;
+ //case TOKmanifest: stc = STCmanifest; goto Lstc;
#endif
- Lstc:
- nextToken();
- Lstc2:
- switch (token.value)
- {
- case TOKconst: stc |= STCconst; goto Lstc;
- case TOKfinal: stc |= STCfinal; goto Lstc;
- case TOKauto: stc |= STCauto; goto Lstc;
- case TOKscope: stc |= STCscope; goto Lstc;
- case TOKoverride: stc |= STCoverride; goto Lstc;
- case TOKabstract: stc |= STCabstract; goto Lstc;
- case TOKsynchronized: stc |= STCsynchronized; goto Lstc;
- case TOKdeprecated: stc |= STCdeprecated; goto Lstc;
- //case TOKinvariant: stc |= STCimmutable; goto Lstc;
- default:
- break;
- }
+ Lstc:
+ nextToken();
+ Lstc2:
+ switch (token.value)
+ {
+ case TOKconst: stc |= STCconst; goto Lstc;
+ case TOKfinal: stc |= STCfinal; goto Lstc;
+ case TOKauto: stc |= STCauto; goto Lstc;
+ case TOKscope: stc |= STCscope; goto Lstc;
+ case TOKoverride: stc |= STCoverride; goto Lstc;
+ case TOKabstract: stc |= STCabstract; goto Lstc;
+ case TOKsynchronized: stc |= STCsynchronized; goto Lstc;
+ case TOKdeprecated: stc |= STCdeprecated; goto Lstc;
+ //case TOKinvariant: stc |= STCimmutable; goto Lstc;
+ default:
+ break;
+ }
- /* Look for auto initializers:
- * storage_class identifier = initializer;
- */
- if (token.value == TOKidentifier &&
- peek(&token)->value == TOKassign)
- {
- while (1)
- {
- Identifier *ident = token.ident;
- nextToken();
- nextToken();
- Initializer *init = parseInitializer();
- VarDeclaration *v = new VarDeclaration(loc, NULL, ident, init);
- v->storage_class = stc;
- s = v;
- if (token.value == TOKsemicolon)
- {
- nextToken();
- }
- else if (token.value == TOKcomma)
- {
- nextToken();
- if (token.value == TOKidentifier &&
- peek(&token)->value == TOKassign)
- {
- decldefs->push(s);
- addComment(s, comment);
- continue;
- }
- else
- error("Identifier expected following comma");
- }
- else
- error("semicolon expected following auto declaration, not '%s'", token.toChars());
- break;
- }
- }
- else
- { a = parseBlock();
- s = new StorageClassDeclaration(stc, a);
- }
- break;
+ /* Look for auto initializers:
+ * storage_class identifier = initializer;
+ */
+ if (token.value == TOKidentifier &&
+ peek(&token)->value == TOKassign)
+ {
+ while (1)
+ {
+ Identifier *ident = token.ident;
+ nextToken();
+ nextToken();
+ Initializer *init = parseInitializer();
+ VarDeclaration *v = new VarDeclaration(loc, NULL, ident, init);
+ v->storage_class = stc;
+ s = v;
+ if (token.value == TOKsemicolon)
+ {
+ nextToken();
+ }
+ else if (token.value == TOKcomma)
+ {
+ nextToken();
+ if (token.value == TOKidentifier &&
+ peek(&token)->value == TOKassign)
+ {
+ decldefs->push(s);
+ addComment(s, comment);
+ continue;
+ }
+ else
+ error("Identifier expected following comma");
+ }
+ else
+ error("semicolon expected following auto declaration, not '%s'", token.toChars());
+ break;
+ }
+ }
+ else
+ { a = parseBlock();
+ s = new StorageClassDeclaration(stc, a);
+ }
+ break;
- case TOKextern:
- if (peek(&token)->value != TOKlparen)
- { stc = STCextern;
- goto Lstc;
- }
- {
- enum LINK linksave = linkage;
- linkage = parseLinkage();
- a = parseBlock();
- s = new LinkDeclaration(linkage, a);
- linkage = linksave;
- break;
- }
- case TOKprivate: prot = PROTprivate; goto Lprot;
- case TOKpackage: prot = PROTpackage; goto Lprot;
- case TOKprotected: prot = PROTprotected; goto Lprot;
- case TOKpublic: prot = PROTpublic; goto Lprot;
- case TOKexport: prot = PROTexport; goto Lprot;
+ case TOKextern:
+ if (peek(&token)->value != TOKlparen)
+ { stc = STCextern;
+ goto Lstc;
+ }
+ {
+ enum LINK linksave = linkage;
+ linkage = parseLinkage();
+ a = parseBlock();
+ s = new LinkDeclaration(linkage, a);
+ linkage = linksave;
+ break;
+ }
+ case TOKprivate: prot = PROTprivate; goto Lprot;
+ case TOKpackage: prot = PROTpackage; goto Lprot;
+ case TOKprotected: prot = PROTprotected; goto Lprot;
+ case TOKpublic: prot = PROTpublic; goto Lprot;
+ case TOKexport: prot = PROTexport; goto Lprot;
- Lprot:
- nextToken();
- switch (token.value)
- {
- case TOKprivate:
- case TOKpackage:
- case TOKprotected:
- case TOKpublic:
- case TOKexport:
- error("redundant protection attribute");
- break;
- }
- a = parseBlock();
- s = new ProtDeclaration(prot, a);
- break;
+ Lprot:
+ nextToken();
+ switch (token.value)
+ {
+ case TOKprivate:
+ case TOKpackage:
+ case TOKprotected:
+ case TOKpublic:
+ case TOKexport:
+ error("redundant protection attribute");
+ break;
+ }
+ a = parseBlock();
+ s = new ProtDeclaration(prot, a);
+ break;
- case TOKalign:
- { unsigned n;
+ case TOKalign:
+ { unsigned n;
// LDC better align code locations
Loc alignloc = loc;
- s = NULL;
- nextToken();
- if (token.value == TOKlparen)
- {
- nextToken();
- if (token.value == TOKint32v)
- n = (unsigned)token.uns64value;
- else
- { error("integer expected, not %s", token.toChars());
- n = 1;
- }
- nextToken();
- check(TOKrparen);
- }
- else
- n = global.structalign; // default
+ s = NULL;
+ nextToken();
+ if (token.value == TOKlparen)
+ {
+ nextToken();
+ if (token.value == TOKint32v)
+ n = (unsigned)token.uns64value;
+ else
+ { error("integer expected, not %s", token.toChars());
+ n = 1;
+ }
+ nextToken();
+ check(TOKrparen);
+ }
+ else
+ n = global.structalign; // default
- a = parseBlock();
- s = new AlignDeclaration(alignloc, n, a);
- break;
- }
+ a = parseBlock();
+ s = new AlignDeclaration(alignloc, n, a);
+ break;
+ }
- case TOKpragma:
- { Identifier *ident;
- Expressions *args = NULL;
+ case TOKpragma:
+ { Identifier *ident;
+ Expressions *args = NULL;
- nextToken();
- check(TOKlparen);
- if (token.value != TOKidentifier)
- { error("pragma(identifier expected");
- goto Lerror;
- }
- ident = token.ident;
- nextToken();
- if (token.value == TOKcomma && peekNext() != TOKrparen)
- args = parseArguments(); // pragma(identifier, args...)
- else
- check(TOKrparen); // pragma(identifier)
+ nextToken();
+ check(TOKlparen);
+ if (token.value != TOKidentifier)
+ { error("pragma(identifier expected");
+ goto Lerror;
+ }
+ ident = token.ident;
+ nextToken();
+ if (token.value == TOKcomma && peekNext() != TOKrparen)
+ args = parseArguments(); // pragma(identifier, args...)
+ else
+ check(TOKrparen); // pragma(identifier)
- if (token.value == TOKsemicolon)
- a = NULL;
- else
- a = parseBlock();
- s = new PragmaDeclaration(loc, ident, args, a);
- break;
- }
+ if (token.value == TOKsemicolon)
+ a = NULL;
+ else
+ a = parseBlock();
+ s = new PragmaDeclaration(loc, ident, args, a);
+ break;
+ }
- case TOKdebug:
- nextToken();
- if (token.value == TOKassign)
- {
- nextToken();
- if (token.value == TOKidentifier)
- s = new DebugSymbol(loc, token.ident);
- else if (token.value == TOKint32v)
- s = new DebugSymbol(loc, (unsigned)token.uns64value);
- else
- { error("identifier or integer expected, not %s", token.toChars());
- s = NULL;
- }
- nextToken();
- if (token.value != TOKsemicolon)
- error("semicolon expected");
- nextToken();
- break;
- }
+ case TOKdebug:
+ nextToken();
+ if (token.value == TOKassign)
+ {
+ nextToken();
+ if (token.value == TOKidentifier)
+ s = new DebugSymbol(loc, token.ident);
+ else if (token.value == TOKint32v)
+ s = new DebugSymbol(loc, (unsigned)token.uns64value);
+ else
+ { error("identifier or integer expected, not %s", token.toChars());
+ s = NULL;
+ }
+ nextToken();
+ if (token.value != TOKsemicolon)
+ error("semicolon expected");
+ nextToken();
+ break;
+ }
- condition = parseDebugCondition();
- goto Lcondition;
+ condition = parseDebugCondition();
+ goto Lcondition;
- case TOKversion:
- nextToken();
- if (token.value == TOKassign)
- {
- nextToken();
- if (token.value == TOKidentifier)
- s = new VersionSymbol(loc, token.ident);
- else if (token.value == TOKint32v)
- s = new VersionSymbol(loc, (unsigned)token.uns64value);
- else
- { error("identifier or integer expected, not %s", token.toChars());
- s = NULL;
- }
- nextToken();
- if (token.value != TOKsemicolon)
- error("semicolon expected");
- nextToken();
- break;
- }
- condition = parseVersionCondition();
- goto Lcondition;
+ case TOKversion:
+ nextToken();
+ if (token.value == TOKassign)
+ {
+ nextToken();
+ if (token.value == TOKidentifier)
+ s = new VersionSymbol(loc, token.ident);
+ else if (token.value == TOKint32v)
+ s = new VersionSymbol(loc, (unsigned)token.uns64value);
+ else
+ { error("identifier or integer expected, not %s", token.toChars());
+ s = NULL;
+ }
+ nextToken();
+ if (token.value != TOKsemicolon)
+ error("semicolon expected");
+ nextToken();
+ break;
+ }
+ condition = parseVersionCondition();
+ goto Lcondition;
- Lcondition:
- a = parseBlock();
- aelse = NULL;
- if (token.value == TOKelse)
- { nextToken();
- aelse = parseBlock();
- }
- s = new ConditionalDeclaration(condition, a, aelse);
- break;
+ Lcondition:
+ a = parseBlock();
+ aelse = NULL;
+ if (token.value == TOKelse)
+ { nextToken();
+ aelse = parseBlock();
+ }
+ s = new ConditionalDeclaration(condition, a, aelse);
+ break;
- case TOKsemicolon: // empty declaration
- nextToken();
- continue;
+ case TOKsemicolon: // empty declaration
+ nextToken();
+ continue;
- default:
- error("Declaration expected, not '%s'",token.toChars());
- Lerror:
- while (token.value != TOKsemicolon && token.value != TOKeof)
- nextToken();
- nextToken();
- s = NULL;
- continue;
- }
- if (s)
- { decldefs->push(s);
- addComment(s, comment);
- }
+ default:
+ error("Declaration expected, not '%s'",token.toChars());
+ Lerror:
+ while (token.value != TOKsemicolon && token.value != TOKeof)
+ nextToken();
+ nextToken();
+ s = NULL;
+ continue;
+ }
+ if (s)
+ { decldefs->push(s);
+ addComment(s, comment);
+ }
} while (!once);
return decldefs;
}
@@ -525,11 +525,11 @@ void Parser::composeStorageClass(StorageClass stc)
StorageClass u = stc;
u &= STCconst | STCimmutable | STCmanifest;
if (u & (u - 1))
- error("conflicting storage class %s", Token::toChars(token.value));
+ error("conflicting storage class %s", Token::toChars(token.value));
u = stc;
u &= STCgshared | STCshared | STCtls;
if (u & (u - 1))
- error("conflicting storage class %s", Token::toChars(token.value));
+ error("conflicting storage class %s", Token::toChars(token.value));
}
#endif
@@ -545,38 +545,38 @@ Array *Parser::parseBlock()
//printf("parseBlock()\n");
switch (token.value)
{
- case TOKsemicolon:
- error("declaration expected following attribute, not ';'");
- nextToken();
- break;
+ case TOKsemicolon:
+ error("declaration expected following attribute, not ';'");
+ nextToken();
+ break;
- case TOKeof:
- error("declaration expected following attribute, not EOF");
- break;
+ case TOKeof:
+ error("declaration expected following attribute, not EOF");
+ break;
- case TOKlcurly:
- nextToken();
- a = parseDeclDefs(0);
- if (token.value != TOKrcurly)
- { /* { */
- error("matching '}' expected, not %s", token.toChars());
- }
- else
- nextToken();
- break;
+ case TOKlcurly:
+ nextToken();
+ a = parseDeclDefs(0);
+ if (token.value != TOKrcurly)
+ { /* { */
+ error("matching '}' expected, not %s", token.toChars());
+ }
+ else
+ nextToken();
+ break;
- case TOKcolon:
- nextToken();
+ case TOKcolon:
+ nextToken();
#if 0
- a = NULL;
+ a = NULL;
#else
- a = parseDeclDefs(0); // grab declarations up to closing curly bracket
+ a = parseDeclDefs(0); // grab declarations up to closing curly bracket
#endif
- break;
+ break;
- default:
- a = parseDeclDefs(1);
- break;
+ default:
+ a = parseDeclDefs(1);
+ break;
}
return a;
}
@@ -596,8 +596,8 @@ StaticAssert *Parser::parseStaticAssert()
check(TOKlparen);
exp = parseAssignExp();
if (token.value == TOKcomma)
- { nextToken();
- msg = parseAssignExp();
+ { nextToken();
+ msg = parseAssignExp();
}
check(TOKrparen);
check(TOKsemicolon);
@@ -616,14 +616,14 @@ TypeQualified *Parser::parseTypeof()
nextToken();
check(TOKlparen);
- if (token.value == TOKreturn) // typeof(return)
+ if (token.value == TOKreturn) // typeof(return)
{
- nextToken();
- t = new TypeReturn(loc);
+ nextToken();
+ t = new TypeReturn(loc);
}
else
- { Expression *exp = parseExpression(); // typeof(expression)
- t = new TypeTypeof(loc, exp);
+ { Expression *exp = parseExpression(); // typeof(expression)
+ t = new TypeTypeof(loc, exp);
}
check(TOKrparen);
return t;
@@ -644,38 +644,38 @@ enum LINK Parser::parseLinkage()
if (token.value == TOKidentifier)
{ Identifier *id = token.ident;
- nextToken();
- if (id == Id::Windows)
- link = LINKwindows;
- else if (id == Id::Pascal)
- link = LINKpascal;
- else if (id == Id::D)
- link = LINKd;
- else if (id == Id::C)
- {
- link = LINKc;
- if (token.value == TOKplusplus)
- { link = LINKcpp;
- nextToken();
- }
- }
- else if (id == Id::System)
- {
+ nextToken();
+ if (id == Id::Windows)
+ link = LINKwindows;
+ else if (id == Id::Pascal)
+ link = LINKpascal;
+ else if (id == Id::D)
+ link = LINKd;
+ else if (id == Id::C)
+ {
+ link = LINKc;
+ if (token.value == TOKplusplus)
+ { link = LINKcpp;
+ nextToken();
+ }
+ }
+ else if (id == Id::System)
+ {
// LDC we configure target at runtime
if (global.params.os == OSWindows)
link = LINKwindows;
else
link = LINKc;
- }
- else
- {
- error("valid linkage identifiers are D, C, C++, Pascal, Windows, System");
- link = LINKd;
- }
+ }
+ else
+ {
+ error("valid linkage identifiers are D, C, C++, Pascal, Windows, System");
+ link = LINKd;
+ }
}
else
{
- link = LINKd; // default
+ link = LINKd; // default
}
check(TOKrparen);
return link;
@@ -691,22 +691,22 @@ Condition *Parser::parseDebugCondition()
if (token.value == TOKlparen)
{
- nextToken();
- unsigned level = 1;
- Identifier *id = NULL;
+ nextToken();
+ unsigned level = 1;
+ Identifier *id = NULL;
- if (token.value == TOKidentifier)
- id = token.ident;
- else if (token.value == TOKint32v)
- level = (unsigned)token.uns64value;
- else
- error("identifier or integer expected, not %s", token.toChars());
- nextToken();
- check(TOKrparen);
- c = new DebugCondition(mod, level, id);
+ if (token.value == TOKidentifier)
+ id = token.ident;
+ else if (token.value == TOKint32v)
+ level = (unsigned)token.uns64value;
+ else
+ error("identifier or integer expected, not %s", token.toChars());
+ nextToken();
+ check(TOKrparen);
+ c = new DebugCondition(mod, level, id);
}
else
- c = new DebugCondition(mod, 1, NULL);
+ c = new DebugCondition(mod, 1, NULL);
return c;
}
@@ -723,23 +723,23 @@ Condition *Parser::parseVersionCondition()
if (token.value == TOKlparen)
{
- nextToken();
- if (token.value == TOKidentifier)
- id = token.ident;
- else if (token.value == TOKint32v)
- level = (unsigned)token.uns64value;
+ nextToken();
+ if (token.value == TOKidentifier)
+ id = token.ident;
+ else if (token.value == TOKint32v)
+ level = (unsigned)token.uns64value;
#if DMDV2
- /* Allow:
- * version (unittest)
- * even though unittest is a keyword
- */
- else if (token.value == TOKunittest)
- id = Lexer::idPool(Token::toChars(TOKunittest));
+ /* Allow:
+ * version (unittest)
+ * even though unittest is a keyword
+ */
+ else if (token.value == TOKunittest)
+ id = Lexer::idPool(Token::toChars(TOKunittest));
#endif
- else
- error("identifier or integer expected, not %s", token.toChars());
- nextToken();
- check(TOKrparen);
+ else
+ error("identifier or integer expected, not %s", token.toChars());
+ nextToken();
+ check(TOKrparen);
}
else
@@ -750,10 +750,10 @@ Condition *Parser::parseVersionCondition()
}
/***********************************************
- * static if (expression)
- * body
- * else
- * body
+ * static if (expression)
+ * body
+ * else
+ * body
*/
Condition *Parser::parseStaticIfCondition()
@@ -766,13 +766,13 @@ Condition *Parser::parseStaticIfCondition()
nextToken();
if (token.value == TOKlparen)
{
- nextToken();
- exp = parseAssignExp();
- check(TOKrparen);
+ nextToken();
+ exp = parseAssignExp();
+ check(TOKrparen);
}
else
{ error("(expression) expected following static if");
- exp = NULL;
+ exp = NULL;
}
condition = new StaticIfCondition(loc, exp);
return condition;
@@ -781,7 +781,7 @@ Condition *Parser::parseStaticIfCondition()
/*****************************************
* Parse a constructor definition:
- * this(arguments) { body }
+ * this(arguments) { body }
* Current token is 'this'.
*/
@@ -801,7 +801,7 @@ Dsymbol *Parser::parseCtor()
/*****************************************
* Parse a destructor definition:
- * ~this() { body }
+ * ~this() { body }
* Current token is '~'.
*/
@@ -822,7 +822,7 @@ DtorDeclaration *Parser::parseDtor()
/*****************************************
* Parse a static constructor definition:
- * static this() { body }
+ * static this() { body }
* Current token is 'this'.
*/
@@ -842,7 +842,7 @@ StaticCtorDeclaration *Parser::parseStaticCtor()
/*****************************************
* Parse a static destructor definition:
- * static ~this() { body }
+ * static ~this() { body }
* Current token is '~'.
*/
@@ -863,7 +863,7 @@ StaticDtorDeclaration *Parser::parseStaticDtor()
/*****************************************
* Parse an invariant definition:
- * invariant() { body }
+ * invariant() { body }
* Current token is 'invariant'.
*/
@@ -873,10 +873,10 @@ InvariantDeclaration *Parser::parseInvariant()
Loc loc = this->loc;
nextToken();
- if (token.value == TOKlparen) // optional ()
+ if (token.value == TOKlparen) // optional ()
{
- nextToken();
- check(TOKrparen);
+ nextToken();
+ check(TOKrparen);
}
f = new InvariantDeclaration(loc, 0);
@@ -886,7 +886,7 @@ InvariantDeclaration *Parser::parseInvariant()
/*****************************************
* Parse a unittest definition:
- * unittest { body }
+ * unittest { body }
* Current token is 'unittest'.
*/
@@ -907,7 +907,7 @@ UnitTestDeclaration *Parser::parseUnitTest()
/*****************************************
* Parse a new definition:
- * new(arguments) { body }
+ * new(arguments) { body }
* Current token is 'new'.
*/
@@ -927,7 +927,7 @@ NewDeclaration *Parser::parseNew()
/*****************************************
* Parse a delete definition:
- * delete(arguments) { body }
+ * delete(arguments) { body }
* Current token is 'delete'.
*/
@@ -941,7 +941,7 @@ DeleteDeclaration *Parser::parseDelete()
nextToken();
arguments = parseParameters(&varargs);
if (varargs)
- error("... not allowed in delete function parameter list");
+ error("... not allowed in delete function parameter list");
f = new DeleteDeclaration(loc, 0, arguments);
parseContracts(f);
return f;
@@ -960,81 +960,81 @@ Parameters *Parser::parseParameters(int *pvarargs)
check(TOKlparen);
while (1)
{ Type *tb;
- Identifier *ai = NULL;
- Type *at;
- Parameter *a;
- StorageClass storageClass = 0;
- Expression *ae;
+ Identifier *ai = NULL;
+ Type *at;
+ Parameter *a;
+ StorageClass storageClass = 0;
+ Expression *ae;
- storageClass = STCin; // parameter is "in" by default
- switch (token.value)
- {
- case TOKrparen:
- break;
+ storageClass = STCin; // parameter is "in" by default
+ switch (token.value)
+ {
+ case TOKrparen:
+ break;
- case TOKdotdotdot:
- varargs = 1;
- nextToken();
- break;
+ case TOKdotdotdot:
+ varargs = 1;
+ nextToken();
+ break;
- case TOKin:
- storageClass = STCin;
- nextToken();
- goto L1;
+ case TOKin:
+ storageClass = STCin;
+ nextToken();
+ goto L1;
- case TOKout:
- storageClass = STCout;
- nextToken();
- goto L1;
+ case TOKout:
+ storageClass = STCout;
+ nextToken();
+ goto L1;
- case TOKinout:
- case TOKref:
- storageClass = STCref;
- nextToken();
- goto L1;
+ case TOKinout:
+ case TOKref:
+ storageClass = STCref;
+ nextToken();
+ goto L1;
- case TOKlazy:
- storageClass = STClazy;
- nextToken();
- goto L1;
+ case TOKlazy:
+ storageClass = STClazy;
+ nextToken();
+ goto L1;
- default:
- L1:
- tb = parseBasicType();
- at = parseDeclarator(tb, &ai);
- ae = NULL;
- if (token.value == TOKassign) // = defaultArg
- { nextToken();
- ae = parseAssignExp();
- hasdefault = 1;
- }
- else
- { if (hasdefault)
- error("default argument expected for %s",
- ai ? ai->toChars() : at->toChars());
- }
- if (token.value == TOKdotdotdot)
- { /* This is:
- * at ai ...
- */
+ default:
+ L1:
+ tb = parseBasicType();
+ at = parseDeclarator(tb, &ai);
+ ae = NULL;
+ if (token.value == TOKassign) // = defaultArg
+ { nextToken();
+ ae = parseAssignExp();
+ hasdefault = 1;
+ }
+ else
+ { if (hasdefault)
+ error("default argument expected for %s",
+ ai ? ai->toChars() : at->toChars());
+ }
+ if (token.value == TOKdotdotdot)
+ { /* This is:
+ * at ai ...
+ */
- if (storageClass & (STCout | STCref))
- error("variadic argument cannot be out or ref");
- varargs = 2;
- a = new Parameter(storageClass, at, ai, ae);
- arguments->push(a);
- nextToken();
- break;
- }
- a = new Parameter(storageClass, at, ai, ae);
- arguments->push(a);
- if (token.value == TOKcomma)
- { nextToken();
- continue;
- }
- break;
- }
- break;
+ if (storageClass & (STCout | STCref))
+ error("variadic argument cannot be out or ref");
+ varargs = 2;
+ a = new Parameter(storageClass, at, ai, ae);
+ arguments->push(a);
+ nextToken();
+ break;
+ }
+ a = new Parameter(storageClass, at, ai, ae);
+ arguments->push(a);
+ if (token.value == TOKcomma)
+ { nextToken();
+ continue;
+ }
+ break;
+ }
+ break;
}
check(TOKrparen);
*pvarargs = varargs;
@@ -1054,66 +1054,66 @@ EnumDeclaration *Parser::parseEnum()
//printf("Parser::parseEnum()\n");
nextToken();
if (token.value == TOKidentifier)
- { id = token.ident;
- nextToken();
+ { id = token.ident;
+ nextToken();
}
else
- id = NULL;
+ id = NULL;
if (token.value == TOKcolon)
{
- nextToken();
- memtype = parseBasicType();
+ nextToken();
+ memtype = parseBasicType();
}
else
- memtype = NULL;
+ memtype = NULL;
e = new EnumDeclaration(loc, id, memtype);
if (token.value == TOKsemicolon && id)
- nextToken();
+ nextToken();
else if (token.value == TOKlcurly)
{
- //printf("enum definition\n");
- e->members = new Array();
- nextToken();
- unsigned char *comment = token.blockComment;
- while (token.value != TOKrcurly)
- {
- if (token.value == TOKidentifier)
- { EnumMember *em;
- Expression *value;
- Identifier *ident;
+ //printf("enum definition\n");
+ e->members = new Array();
+ nextToken();
+ unsigned char *comment = token.blockComment;
+ while (token.value != TOKrcurly)
+ {
+ if (token.value == TOKidentifier)
+ { EnumMember *em;
+ Expression *value;
+ Identifier *ident;
- loc = this->loc;
- ident = token.ident;
- value = NULL;
- nextToken();
- if (token.value == TOKassign)
- {
- nextToken();
- value = parseAssignExp();
- }
- em = new EnumMember(loc, ident, value);
- e->members->push(em);
- if (token.value == TOKrcurly)
- ;
- else
- { addComment(em, comment);
- comment = NULL;
- check(TOKcomma);
- }
- addComment(em, comment);
- comment = token.blockComment;
- }
- else
- { error("enum member expected");
- nextToken();
- }
- }
- nextToken();
+ loc = this->loc;
+ ident = token.ident;
+ value = NULL;
+ nextToken();
+ if (token.value == TOKassign)
+ {
+ nextToken();
+ value = parseAssignExp();
+ }
+ em = new EnumMember(loc, ident, value);
+ e->members->push(em);
+ if (token.value == TOKrcurly)
+ ;
+ else
+ { addComment(em, comment);
+ comment = NULL;
+ check(TOKcomma);
+ }
+ addComment(em, comment);
+ comment = token.blockComment;
+ }
+ else
+ { error("enum member expected");
+ nextToken();
+ }
+ }
+ nextToken();
}
else
- error("enum declaration is invalid");
+ error("enum declaration is invalid");
//printf("-parseEnum() %s\n", e->toChars());
return e;
@@ -1134,99 +1134,99 @@ Dsymbol *Parser::parseAggregate()
tok = token.value;
nextToken();
if (token.value != TOKidentifier)
- { id = NULL;
+ { id = NULL;
}
else
- { id = token.ident;
- nextToken();
+ { id = token.ident;
+ nextToken();
- if (token.value == TOKlparen)
- { // Class template declaration.
+ if (token.value == TOKlparen)
+ { // Class template declaration.
- // Gather template parameter list
- tpl = parseTemplateParameterList();
- }
+ // Gather template parameter list
+ tpl = parseTemplateParameterList();
+ }
}
Loc loc = this->loc;
switch (tok)
- { case TOKclass:
- case TOKinterface:
- {
- if (!id)
- error("anonymous classes not allowed");
+ { case TOKclass:
+ case TOKinterface:
+ {
+ if (!id)
+ error("anonymous classes not allowed");
- // Collect base class(es)
- BaseClasses *baseclasses = NULL;
- if (token.value == TOKcolon)
- {
- nextToken();
- baseclasses = parseBaseClasses();
+ // Collect base class(es)
+ BaseClasses *baseclasses = NULL;
+ if (token.value == TOKcolon)
+ {
+ nextToken();
+ baseclasses = parseBaseClasses();
- if (token.value != TOKlcurly)
- error("members expected");
- }
+ if (token.value != TOKlcurly)
+ error("members expected");
+ }
- if (tok == TOKclass)
- a = new ClassDeclaration(loc, id, baseclasses);
- else
- a = new InterfaceDeclaration(loc, id, baseclasses);
- break;
- }
+ if (tok == TOKclass)
+ a = new ClassDeclaration(loc, id, baseclasses);
+ else
+ a = new InterfaceDeclaration(loc, id, baseclasses);
+ break;
+ }
- case TOKstruct:
- if (id)
- a = new StructDeclaration(loc, id);
- else
- anon = 1;
- break;
+ case TOKstruct:
+ if (id)
+ a = new StructDeclaration(loc, id);
+ else
+ anon = 1;
+ break;
- case TOKunion:
- if (id)
- a = new UnionDeclaration(loc, id);
- else
- anon = 2;
- break;
+ case TOKunion:
+ if (id)
+ a = new UnionDeclaration(loc, id);
+ else
+ anon = 2;
+ break;
- default:
- assert(0);
- break;
+ default:
+ assert(0);
+ break;
}
if (a && token.value == TOKsemicolon)
- { nextToken();
+ { nextToken();
}
else if (token.value == TOKlcurly)
{
- //printf("aggregate definition\n");
- nextToken();
- Array *decl = parseDeclDefs(0);
- if (token.value != TOKrcurly)
- error("} expected following member declarations in aggregate");
- nextToken();
- if (anon)
- {
- /* Anonymous structs/unions are more like attributes.
- */
- return new AnonDeclaration(loc, anon - 1, decl);
- }
- else
- a->members = decl;
+ //printf("aggregate definition\n");
+ nextToken();
+ Array *decl = parseDeclDefs(0);
+ if (token.value != TOKrcurly)
+ error("} expected following member declarations in aggregate");
+ nextToken();
+ if (anon)
+ {
+ /* Anonymous structs/unions are more like attributes.
+ */
+ return new AnonDeclaration(loc, anon - 1, decl);
+ }
+ else
+ a->members = decl;
}
else
{
- error("{ } expected following aggregate declaration");
- a = new StructDeclaration(loc, NULL);
+ error("{ } expected following aggregate declaration");
+ a = new StructDeclaration(loc, NULL);
}
if (tpl)
- { Array *decldefs;
- TemplateDeclaration *tempdecl;
+ { Array *decldefs;
+ TemplateDeclaration *tempdecl;
- // Wrap a template around the aggregate declaration
- decldefs = new Array();
- decldefs->push(a);
- tempdecl = new TemplateDeclaration(loc, id, tpl, NULL, decldefs);
- return tempdecl;
+ // Wrap a template around the aggregate declaration
+ decldefs = new Array();
+ decldefs->push(a);
+ tempdecl = new TemplateDeclaration(loc, id, tpl, NULL, decldefs);
+ return tempdecl;
}
return a;
@@ -1242,31 +1242,31 @@ BaseClasses *Parser::parseBaseClasses()
for (; 1; nextToken())
{
- switch (token.value)
- {
- case TOKidentifier:
- break;
- case TOKprivate:
- protection = PROTprivate;
- continue;
- case TOKpackage:
- protection = PROTpackage;
- continue;
- case TOKprotected:
- protection = PROTprotected;
- continue;
- case TOKpublic:
- protection = PROTpublic;
- continue;
- default:
- error("base classes expected instead of %s", token.toChars());
- return NULL;
- }
- BaseClass *b = new BaseClass(parseBasicType(), protection);
- baseclasses->push(b);
- if (token.value != TOKcomma)
- break;
- protection = PROTpublic;
+ switch (token.value)
+ {
+ case TOKidentifier:
+ break;
+ case TOKprivate:
+ protection = PROTprivate;
+ continue;
+ case TOKpackage:
+ protection = PROTpackage;
+ continue;
+ case TOKprotected:
+ protection = PROTprotected;
+ continue;
+ case TOKpublic:
+ protection = PROTpublic;
+ continue;
+ default:
+ error("base classes expected instead of %s", token.toChars());
+ return NULL;
+ }
+ BaseClass *b = new BaseClass(parseBasicType(), protection);
+ baseclasses->push(b);
+ if (token.value != TOKcomma)
+ break;
+ protection = PROTpublic;
}
return baseclasses;
}
@@ -1274,7 +1274,7 @@ BaseClasses *Parser::parseBaseClasses()
/**************************************
* Parse constraint.
* Constraint is of the form:
- * if ( ConstraintExpression )
+ * if ( ConstraintExpression )
*/
#if DMDV2
@@ -1283,10 +1283,10 @@ Expression *Parser::parseConstraint()
if (token.value == TOKif)
{
- nextToken(); // skip over 'if'
- check(TOKlparen);
- e = parseExpression();
- check(TOKrparen);
+ nextToken(); // skip over 'if'
+ check(TOKlparen);
+ e = parseExpression();
+ check(TOKrparen);
}
return e;
}
@@ -1307,27 +1307,27 @@ TemplateDeclaration *Parser::parseTemplateDeclaration()
nextToken();
if (token.value != TOKidentifier)
{ error("TemplateIdentifier expected following template");
- goto Lerr;
+ goto Lerr;
}
id = token.ident;
nextToken();
tpl = parseTemplateParameterList();
if (!tpl)
- goto Lerr;
+ goto Lerr;
if (token.value != TOKlcurly)
- { error("members of template declaration expected");
- goto Lerr;
+ { error("members of template declaration expected");
+ goto Lerr;
}
else
{
- nextToken();
- decldefs = parseDeclDefs(0);
- if (token.value != TOKrcurly)
- { error("template member expected");
- goto Lerr;
- }
- nextToken();
+ nextToken();
+ decldefs = parseDeclDefs(0);
+ if (token.value != TOKrcurly)
+ { error("template member expected");
+ goto Lerr;
+ }
+ nextToken();
}
tempdecl = new TemplateDeclaration(loc, id, tpl, NULL, decldefs);
@@ -1347,133 +1347,133 @@ TemplateParameters *Parser::parseTemplateParameterList(int flag)
if (token.value != TOKlparen)
{ error("parenthesized TemplateParameterList expected following TemplateIdentifier");
- goto Lerr;
+ goto Lerr;
}
nextToken();
// Get array of TemplateParameters
if (token.value != TOKrparen)
- { int isvariadic = 0;
+ { int isvariadic = 0;
- while (1)
- { TemplateParameter *tp;
- Identifier *tp_ident = NULL;
- Type *tp_spectype = NULL;
- Type *tp_valtype = NULL;
- Type *tp_defaulttype = NULL;
- Expression *tp_specvalue = NULL;
- Expression *tp_defaultvalue = NULL;
- Token *t;
+ while (1)
+ { TemplateParameter *tp;
+ Identifier *tp_ident = NULL;
+ Type *tp_spectype = NULL;
+ Type *tp_valtype = NULL;
+ Type *tp_defaulttype = NULL;
+ Expression *tp_specvalue = NULL;
+ Expression *tp_defaultvalue = NULL;
+ Token *t;
- // Get TemplateParameter
+ // Get TemplateParameter
- // First, look ahead to see if it is a TypeParameter or a ValueParameter
- t = peek(&token);
- if (token.value == TOKalias)
- { // AliasParameter
- nextToken();
- if (token.value != TOKidentifier)
- { error("Identifier expected for template parameter");
- goto Lerr;
- }
- tp_ident = token.ident;
- nextToken();
- if (token.value == TOKcolon) // : Type
- {
- nextToken();
- tp_spectype = parseBasicType();
- tp_spectype = parseDeclarator(tp_spectype, NULL);
- }
- if (token.value == TOKassign) // = Type
- {
- nextToken();
- tp_defaulttype = parseBasicType();
- tp_defaulttype = parseDeclarator(tp_defaulttype, NULL);
- }
- tp = new TemplateAliasParameter(loc, tp_ident, tp_spectype, tp_defaulttype);
- }
- else if (t->value == TOKcolon || t->value == TOKassign ||
- t->value == TOKcomma || t->value == TOKrparen)
- { // TypeParameter
- if (token.value != TOKidentifier)
- { error("Identifier expected for template parameter");
- goto Lerr;
- }
- tp_ident = token.ident;
- nextToken();
- if (token.value == TOKcolon) // : Type
- {
- nextToken();
- tp_spectype = parseBasicType();
- tp_spectype = parseDeclarator(tp_spectype, NULL);
- }
- if (token.value == TOKassign) // = Type
- {
- nextToken();
- tp_defaulttype = parseBasicType();
- tp_defaulttype = parseDeclarator(tp_defaulttype, NULL);
- }
- tp = new TemplateTypeParameter(loc, tp_ident, tp_spectype, tp_defaulttype);
- }
- else if (token.value == TOKidentifier && t->value == TOKdotdotdot)
- { // ident...
- if (isvariadic)
- error("variadic template parameter must be last");
- isvariadic = 1;
- tp_ident = token.ident;
- nextToken();
- nextToken();
- tp = new TemplateTupleParameter(loc, tp_ident);
- }
+ // First, look ahead to see if it is a TypeParameter or a ValueParameter
+ t = peek(&token);
+ if (token.value == TOKalias)
+ { // AliasParameter
+ nextToken();
+ if (token.value != TOKidentifier)
+ { error("Identifier expected for template parameter");
+ goto Lerr;
+ }
+ tp_ident = token.ident;
+ nextToken();
+ if (token.value == TOKcolon) // : Type
+ {
+ nextToken();
+ tp_spectype = parseBasicType();
+ tp_spectype = parseDeclarator(tp_spectype, NULL);
+ }
+ if (token.value == TOKassign) // = Type
+ {
+ nextToken();
+ tp_defaulttype = parseBasicType();
+ tp_defaulttype = parseDeclarator(tp_defaulttype, NULL);
+ }
+ tp = new TemplateAliasParameter(loc, tp_ident, tp_spectype, tp_defaulttype);
+ }
+ else if (t->value == TOKcolon || t->value == TOKassign ||
+ t->value == TOKcomma || t->value == TOKrparen)
+ { // TypeParameter
+ if (token.value != TOKidentifier)
+ { error("Identifier expected for template parameter");
+ goto Lerr;
+ }
+ tp_ident = token.ident;
+ nextToken();
+ if (token.value == TOKcolon) // : Type
+ {
+ nextToken();
+ tp_spectype = parseBasicType();
+ tp_spectype = parseDeclarator(tp_spectype, NULL);
+ }
+ if (token.value == TOKassign) // = Type
+ {
+ nextToken();
+ tp_defaulttype = parseBasicType();
+ tp_defaulttype = parseDeclarator(tp_defaulttype, NULL);
+ }
+ tp = new TemplateTypeParameter(loc, tp_ident, tp_spectype, tp_defaulttype);
+ }
+ else if (token.value == TOKidentifier && t->value == TOKdotdotdot)
+ { // ident...
+ if (isvariadic)
+ error("variadic template parameter must be last");
+ isvariadic = 1;
+ tp_ident = token.ident;
+ nextToken();
+ nextToken();
+ tp = new TemplateTupleParameter(loc, tp_ident);
+ }
#if DMDV2
- else if (token.value == TOKthis)
- { // ThisParameter
- nextToken();
- if (token.value != TOKidentifier)
- { error("identifier expected for template this parameter");
- goto Lerr;
- }
- tp_ident = token.ident;
- nextToken();
- if (token.value == TOKcolon) // : Type
- {
- nextToken();
- tp_spectype = parseType();
- }
- if (token.value == TOKassign) // = Type
- {
- nextToken();
- tp_defaulttype = parseType();
- }
- tp = new TemplateThisParameter(loc, tp_ident, tp_spectype, tp_defaulttype);
- }
+ else if (token.value == TOKthis)
+ { // ThisParameter
+ nextToken();
+ if (token.value != TOKidentifier)
+ { error("identifier expected for template this parameter");
+ goto Lerr;
+ }
+ tp_ident = token.ident;
+ nextToken();
+ if (token.value == TOKcolon) // : Type
+ {
+ nextToken();
+ tp_spectype = parseType();
+ }
+ if (token.value == TOKassign) // = Type
+ {
+ nextToken();
+ tp_defaulttype = parseType();
+ }
+ tp = new TemplateThisParameter(loc, tp_ident, tp_spectype, tp_defaulttype);
+ }
#endif
- else
- { // ValueParameter
- tp_valtype = parseBasicType();
- tp_valtype = parseDeclarator(tp_valtype, &tp_ident);
- if (!tp_ident)
- {
- error("identifier expected for template value parameter");
- tp_ident = new Identifier("error", TOKidentifier);
- }
- if (token.value == TOKcolon) // : CondExpression
- {
- nextToken();
- tp_specvalue = parseCondExp();
- }
- if (token.value == TOKassign) // = CondExpression
- {
- nextToken();
- tp_defaultvalue = parseCondExp();
- }
- tp = new TemplateValueParameter(loc, tp_ident, tp_valtype, tp_specvalue, tp_defaultvalue);
- }
- tpl->push(tp);
- if (token.value != TOKcomma)
- break;
- nextToken();
- }
+ else
+ { // ValueParameter
+ tp_valtype = parseBasicType();
+ tp_valtype = parseDeclarator(tp_valtype, &tp_ident);
+ if (!tp_ident)
+ {
+ error("identifier expected for template value parameter");
+ tp_ident = new Identifier("error", TOKidentifier);
+ }
+ if (token.value == TOKcolon) // : CondExpression
+ {
+ nextToken();
+ tp_specvalue = parseCondExp();
+ }
+ if (token.value == TOKassign) // = CondExpression
+ {
+ nextToken();
+ tp_defaultvalue = parseCondExp();
+ }
+ tp = new TemplateValueParameter(loc, tp_ident, tp_valtype, tp_specvalue, tp_defaultvalue);
+ }
+ tpl->push(tp);
+ if (token.value != TOKcomma)
+ break;
+ nextToken();
+ }
}
check(TOKrparen);
Lerr:
@@ -1482,11 +1482,11 @@ Lerr:
/******************************************
* Parse template mixin.
- * mixin Foo;
- * mixin Foo!(args);
- * mixin a.b.c!(args).Foo!(args);
- * mixin Foo!(args) identifier;
- * mixin typeof(expr).identifier!(args);
+ * mixin Foo;
+ * mixin Foo!(args);
+ * mixin a.b.c!(args).Foo!(args);
+ * mixin Foo!(args) identifier;
+ * mixin typeof(expr).identifier!(args);
*/
Dsymbol *Parser::parseMixin()
@@ -1502,72 +1502,72 @@ Dsymbol *Parser::parseMixin()
tqual = NULL;
if (token.value == TOKdot)
{
- id = Id::empty;
+ id = Id::empty;
}
else
{
- if (token.value == TOKtypeof)
- { Expression *exp;
+ if (token.value == TOKtypeof)
+ { Expression *exp;
- nextToken();
- check(TOKlparen);
- exp = parseExpression();
- check(TOKrparen);
- tqual = new TypeTypeof(loc, exp);
- check(TOKdot);
- }
- if (token.value != TOKidentifier)
- {
- error("identifier expected, not %s", token.toChars());
- id = Id::empty;
- }
- else
- id = token.ident;
- nextToken();
+ nextToken();
+ check(TOKlparen);
+ exp = parseExpression();
+ check(TOKrparen);
+ tqual = new TypeTypeof(loc, exp);
+ check(TOKdot);
+ }
+ if (token.value != TOKidentifier)
+ {
+ error("identifier expected, not %s", token.toChars());
+ id = Id::empty;
+ }
+ else
+ id = token.ident;
+ nextToken();
}
idents = new Array();
while (1)
{
- tiargs = NULL;
- if (token.value == TOKnot)
- {
- nextToken();
- tiargs = parseTemplateArgumentList();
- }
+ tiargs = NULL;
+ if (token.value == TOKnot)
+ {
+ nextToken();
+ tiargs = parseTemplateArgumentList();
+ }
- if (token.value != TOKdot)
- break;
+ if (token.value != TOKdot)
+ break;
- if (tiargs)
- { TemplateInstance *tempinst = new TemplateInstance(loc, id);
- tempinst->tiargs = tiargs;
- id = (Identifier *)tempinst;
- tiargs = NULL;
- }
- idents->push(id);
+ if (tiargs)
+ { TemplateInstance *tempinst = new TemplateInstance(loc, id);
+ tempinst->tiargs = tiargs;
+ id = (Identifier *)tempinst;
+ tiargs = NULL;
+ }
+ idents->push(id);
- nextToken();
- if (token.value != TOKidentifier)
- { error("identifier expected following '.' instead of '%s'", token.toChars());
- break;
- }
- id = token.ident;
- nextToken();
+ nextToken();
+ if (token.value != TOKidentifier)
+ { error("identifier expected following '.' instead of '%s'", token.toChars());
+ break;
+ }
+ id = token.ident;
+ nextToken();
}
idents->push(id);
if (token.value == TOKidentifier)
{
- id = token.ident;
- nextToken();
+ id = token.ident;
+ nextToken();
}
else
- id = NULL;
+ id = NULL;
tm = new TemplateMixin(loc, id, tqual, idents, tiargs);
if (token.value != TOKsemicolon)
- error("';' expected after mixin");
+ error("';' expected after mixin");
nextToken();
return tm;
@@ -1576,9 +1576,9 @@ Dsymbol *Parser::parseMixin()
/******************************************
* Parse template argument list.
* Input:
- * current token is opening '('
+ * current token is opening '('
* Output:
- * current token is one after closing ')'
+ * current token is one after closing ')'
*/
Objects *Parser::parseTemplateArgumentList()
@@ -1587,36 +1587,36 @@ Objects *Parser::parseTemplateArgumentList()
Objects *tiargs = new Objects();
if (token.value != TOKlparen)
{ error("!(TemplateArgumentList) expected following TemplateIdentifier");
- return tiargs;
+ return tiargs;
}
nextToken();
// Get TemplateArgumentList
if (token.value != TOKrparen)
{
- while (1)
- {
- // See if it is an Expression or a Type
- if (isDeclaration(&token, 0, TOKreserved, NULL))
- { // Type
- Type *ta;
+ while (1)
+ {
+ // See if it is an Expression or a Type
+ if (isDeclaration(&token, 0, TOKreserved, NULL))
+ { // Type
+ Type *ta;
- // Get TemplateArgument
- ta = parseBasicType();
- ta = parseDeclarator(ta, NULL);
- tiargs->push(ta);
- }
- else
- { // Expression
- Expression *ea;
+ // Get TemplateArgument
+ ta = parseBasicType();
+ ta = parseDeclarator(ta, NULL);
+ tiargs->push(ta);
+ }
+ else
+ { // Expression
+ Expression *ea;
- ea = parseAssignExp();
- tiargs->push(ea);
- }
- if (token.value != TOKcomma)
- break;
- nextToken();
- }
+ ea = parseAssignExp();
+ tiargs->push(ea);
+ }
+ if (token.value != TOKcomma)
+ break;
+ nextToken();
+ }
}
check(TOKrparen, "template argument list");
return tiargs;
@@ -1633,83 +1633,83 @@ Import *Parser::parseImport(Array *decldefs, int isstatic)
do
{
L1:
- nextToken();
- if (token.value != TOKidentifier)
- { error("Identifier expected following import");
- break;
- }
+ nextToken();
+ if (token.value != TOKidentifier)
+ { error("Identifier expected following import");
+ break;
+ }
- loc = this->loc;
- a = NULL;
- id = token.ident;
- nextToken();
- if (!aliasid && token.value == TOKassign)
- {
- aliasid = id;
- goto L1;
- }
- while (token.value == TOKdot)
- {
- if (!a)
- a = new Array();
- a->push(id);
- nextToken();
- if (token.value != TOKidentifier)
- { error("Identifier expected following package");
- break;
- }
- id = token.ident;
- nextToken();
- }
+ loc = this->loc;
+ a = NULL;
+ id = token.ident;
+ nextToken();
+ if (!aliasid && token.value == TOKassign)
+ {
+ aliasid = id;
+ goto L1;
+ }
+ while (token.value == TOKdot)
+ {
+ if (!a)
+ a = new Array();
+ a->push(id);
+ nextToken();
+ if (token.value != TOKidentifier)
+ { error("Identifier expected following package");
+ break;
+ }
+ id = token.ident;
+ nextToken();
+ }
- s = new Import(loc, a, id, aliasid, isstatic);
- decldefs->push(s);
+ s = new Import(loc, a, id, aliasid, isstatic);
+ decldefs->push(s);
- /* Look for
- * : alias=name, alias=name;
- * syntax.
- */
- if (token.value == TOKcolon)
- {
- do
- { Identifier *name;
- Identifier *alias;
+ /* Look for
+ * : alias=name, alias=name;
+ * syntax.
+ */
+ if (token.value == TOKcolon)
+ {
+ do
+ { Identifier *name;
+ Identifier *alias;
- nextToken();
- if (token.value != TOKidentifier)
- { error("Identifier expected following :");
- break;
- }
- alias = token.ident;
- nextToken();
- if (token.value == TOKassign)
- {
- nextToken();
- if (token.value != TOKidentifier)
- { error("Identifier expected following %s=", alias->toChars());
- break;
- }
- name = token.ident;
- nextToken();
- }
- else
- { name = alias;
- alias = NULL;
- }
- s->addAlias(name, alias);
- } while (token.value == TOKcomma);
- break; // no comma-separated imports of this form
- }
+ nextToken();
+ if (token.value != TOKidentifier)
+ { error("Identifier expected following :");
+ break;
+ }
+ alias = token.ident;
+ nextToken();
+ if (token.value == TOKassign)
+ {
+ nextToken();
+ if (token.value != TOKidentifier)
+ { error("Identifier expected following %s=", alias->toChars());
+ break;
+ }
+ name = token.ident;
+ nextToken();
+ }
+ else
+ { name = alias;
+ alias = NULL;
+ }
+ s->addAlias(name, alias);
+ } while (token.value == TOKcomma);
+ break; // no comma-separated imports of this form
+ }
- aliasid = NULL;
+ aliasid = NULL;
} while (token.value == TOKcomma);
if (token.value == TOKsemicolon)
- nextToken();
+ nextToken();
else
{
- error("';' expected");
- nextToken();
+ error("';' expected");
+ nextToken();
}
return NULL;
@@ -1724,46 +1724,46 @@ Type *Parser::parseType(Identifier **pident, TemplateParameters **tpl)
* const shared, shared const, const, invariant, shared
*/
if (token.value == TOKconst && peekNext() == TOKshared && peekNext2() != TOKlparen ||
- token.value == TOKshared && peekNext() == TOKconst && peekNext2() != TOKlparen)
+ token.value == TOKshared && peekNext() == TOKconst && peekNext2() != TOKlparen)
{
- nextToken();
- nextToken();
- /* shared const type
- */
- t = parseType(pident, tpl);
- t = t->makeSharedConst();
- return t;
+ nextToken();
+ nextToken();
+ /* shared const type
+ */
+ t = parseType(pident, tpl);
+ t = t->makeSharedConst();
+ return t;
}
else if (token.value == TOKconst && peekNext() != TOKlparen)
{
- nextToken();
- /* const type
- */
- t = parseType(pident, tpl);
- t = t->makeConst();
- return t;
+ nextToken();
+ /* const type
+ */
+ t = parseType(pident, tpl);
+ t = t->makeConst();
+ return t;
}
else if ((token.value == TOKinvariant || token.value == TOKimmutable) &&
peekNext() != TOKlparen)
{
- nextToken();
- /* invariant type
- */
- t = parseType(pident, tpl);
- t = t->makeInvariant();
- return t;
+ nextToken();
+ /* invariant type
+ */
+ t = parseType(pident, tpl);
+ t = t->makeInvariant();
+ return t;
}
else if (token.value == TOKshared && peekNext() != TOKlparen)
{
- nextToken();
- /* shared type
- */
- t = parseType(pident, tpl);
- t = t->makeShared();
- return t;
+ nextToken();
+ /* shared type
+ */
+ t = parseType(pident, tpl);
+ t = t->makeShared();
+ return t;
}
else
- t = parseBasicType();
+ t = parseBasicType();
t = parseDeclarator(t, pident, tpl);
return t;
}
@@ -1778,78 +1778,78 @@ Type *Parser::parseBasicType()
//printf("parseBasicType()\n");
switch (token.value)
{
- case BASIC_TYPES_X(t):
- nextToken();
- break;
+ case BASIC_TYPES_X(t):
+ nextToken();
+ break;
- case TOKidentifier:
- id = token.ident;
- nextToken();
- if (token.value == TOKnot)
- {
- nextToken();
- tempinst = new TemplateInstance(loc, id);
- tempinst->tiargs = parseTemplateArgumentList();
- tid = new TypeInstance(loc, tempinst);
- goto Lident2;
- }
- Lident:
- tid = new TypeIdentifier(loc, id);
- Lident2:
- while (token.value == TOKdot)
- { nextToken();
- if (token.value != TOKidentifier)
- { error("identifier expected following '.' instead of '%s'", token.toChars());
- break;
- }
- id = token.ident;
- nextToken();
- if (token.value == TOKnot)
- {
- nextToken();
- tempinst = new TemplateInstance(loc, id);
- tempinst->tiargs = parseTemplateArgumentList();
- tid->addIdent((Identifier *)tempinst);
- }
- else
- tid->addIdent(id);
- }
- t = tid;
- break;
+ case TOKidentifier:
+ id = token.ident;
+ nextToken();
+ if (token.value == TOKnot)
+ {
+ nextToken();
+ tempinst = new TemplateInstance(loc, id);
+ tempinst->tiargs = parseTemplateArgumentList();
+ tid = new TypeInstance(loc, tempinst);
+ goto Lident2;
+ }
+ Lident:
+ tid = new TypeIdentifier(loc, id);
+ Lident2:
+ while (token.value == TOKdot)
+ { nextToken();
+ if (token.value != TOKidentifier)
+ { error("identifier expected following '.' instead of '%s'", token.toChars());
+ break;
+ }
+ id = token.ident;
+ nextToken();
+ if (token.value == TOKnot)
+ {
+ nextToken();
+ tempinst = new TemplateInstance(loc, id);
+ tempinst->tiargs = parseTemplateArgumentList();
+ tid->addIdent((Identifier *)tempinst);
+ }
+ else
+ tid->addIdent(id);
+ }
+ t = tid;
+ break;
- case TOKdot:
- // Leading . as in .foo
- id = Id::empty;
- goto Lident;
+ case TOKdot:
+ // Leading . as in .foo
+ id = Id::empty;
+ goto Lident;
- case TOKtypeof:
- { Expression *exp;
+ case TOKtypeof:
+ { Expression *exp;
- nextToken();
- check(TOKlparen);
- exp = parseExpression();
- check(TOKrparen);
- tid = new TypeTypeof(loc, exp);
- goto Lident2;
- }
+ nextToken();
+ check(TOKlparen);
+ exp = parseExpression();
+ check(TOKrparen);
+ tid = new TypeTypeof(loc, exp);
+ goto Lident2;
+ }
- default:
- error("basic type expected, not %s", token.toChars());
- t = Type::tint32;
- break;
+ default:
+ error("basic type expected, not %s", token.toChars());
+ t = Type::tint32;
+ break;
}
return t;
}
/******************************************
* Parse things that follow the initial type t.
- * t *
- * t []
- * t [type]
- * t [expression]
- * t [expression .. expression]
- * t function
- * t delegate
+ * t *
+ * t []
+ * t [type]
+ * t [expression]
+ * t [expression .. expression]
+ * t function
+ * t delegate
*/
Type *Parser::parseBasicType2(Type *t)
@@ -1860,115 +1860,115 @@ Type *Parser::parseBasicType2(Type *t)
//printf("parseBasicType2()\n");
while (1)
{
- switch (token.value)
- {
- case TOKmul:
- t = new TypePointer(t);
- nextToken();
- continue;
+ switch (token.value)
+ {
+ case TOKmul:
+ t = new TypePointer(t);
+ nextToken();
+ continue;
- case TOKlbracket:
+ case TOKlbracket:
#if LTORARRAYDECL
- // Handle []. Make sure things like
- // int[3][1] a;
- // is (array[1] of array[3] of int)
- nextToken();
- if (token.value == TOKrbracket)
- {
- t = new TypeDArray(t); // []
- nextToken();
- }
- else if (isDeclaration(&token, 0, TOKrbracket, NULL))
- { // It's an associative array declaration
- Type *index;
+ // Handle []. Make sure things like
+ // int[3][1] a;
+ // is (array[1] of array[3] of int)
+ nextToken();
+ if (token.value == TOKrbracket)
+ {
+ t = new TypeDArray(t); // []
+ nextToken();
+ }
+ else if (isDeclaration(&token, 0, TOKrbracket, NULL))
+ { // It's an associative array declaration
+ Type *index;
- //printf("it's an associative array\n");
- index = parseBasicType();
- index = parseDeclarator(index, NULL); // [ type ]
- t = new TypeAArray(t, index);
- check(TOKrbracket);
- }
- else
- {
- //printf("it's [expression]\n");
- inBrackets++;
- Expression *e = parseExpression(); // [ expression ]
- if (token.value == TOKslice)
- { Expression *e2;
+ //printf("it's an associative array\n");
+ index = parseBasicType();
+ index = parseDeclarator(index, NULL); // [ type ]
+ t = new TypeAArray(t, index);
+ check(TOKrbracket);
+ }
+ else
+ {
+ //printf("it's [expression]\n");
+ inBrackets++;
+ Expression *e = parseExpression(); // [ expression ]
+ if (token.value == TOKslice)
+ { Expression *e2;
- nextToken();
- e2 = parseExpression(); // [ exp .. exp ]
- t = new TypeSlice(t, e, e2);
- }
- else
- t = new TypeSArray(t,e);
- inBrackets--;
- check(TOKrbracket);
- }
- continue;
+ nextToken();
+ e2 = parseExpression(); // [ exp .. exp ]
+ t = new TypeSlice(t, e, e2);
+ }
+ else
+ t = new TypeSArray(t,e);
+ inBrackets--;
+ check(TOKrbracket);
+ }
+ continue;
#else
- // Handle []. Make sure things like
- // int[3][1] a;
- // is (array[3] of array[1] of int)
- ts = t;
- while (token.value == TOKlbracket)
- {
- nextToken();
- if (token.value == TOKrbracket)
- {
- ta = new TypeDArray(t); // []
- nextToken();
- }
- else if (isDeclaration(&token, 0, TOKrbracket, NULL))
- { // It's an associative array declaration
- Type *index;
+ // Handle []. Make sure things like
+ // int[3][1] a;
+ // is (array[3] of array[1] of int)
+ ts = t;
+ while (token.value == TOKlbracket)
+ {
+ nextToken();
+ if (token.value == TOKrbracket)
+ {
+ ta = new TypeDArray(t); // []
+ nextToken();
+ }
+ else if (isDeclaration(&token, 0, TOKrbracket, NULL))
+ { // It's an associative array declaration
+ Type *index;
- //printf("it's an associative array\n");
- index = parseBasicType();
- index = parseDeclarator(index, NULL); // [ type ]
- check(TOKrbracket);
- ta = new TypeAArray(t, index);
- }
- else
- {
- //printf("it's [expression]\n");
- Expression *e = parseExpression(); // [ expression ]
- ta = new TypeSArray(t,e);
- check(TOKrbracket);
- }
- Type **pt;
- for (pt = &ts; *pt != t; pt = &(*pt)->next)
- ;
- *pt = ta;
- }
- t = ts;
- continue;
+ //printf("it's an associative array\n");
+ index = parseBasicType();
+ index = parseDeclarator(index, NULL); // [ type ]
+ check(TOKrbracket);
+ ta = new TypeAArray(t, index);
+ }
+ else
+ {
+ //printf("it's [expression]\n");
+ Expression *e = parseExpression(); // [ expression ]
+ ta = new TypeSArray(t,e);
+ check(TOKrbracket);
+ }
+ Type **pt;
+ for (pt = &ts; *pt != t; pt = &(*pt)->next)
+ ;
+ *pt = ta;
+ }
+ t = ts;
+ continue;
#endif
- case TOKdelegate:
- case TOKfunction:
- { // Handle delegate declaration:
- // t delegate(parameter list)
- // t function(parameter list)
- Parameters *arguments;
- int varargs;
- enum TOK save = token.value;
+ case TOKdelegate:
+ case TOKfunction:
+ { // Handle delegate declaration:
+ // t delegate(parameter list)
+ // t function(parameter list)
+ Parameters *arguments;
+ int varargs;
+ enum TOK save = token.value;
- nextToken();
- arguments = parseParameters(&varargs);
- t = new TypeFunction(arguments, t, varargs, linkage);
- if (save == TOKdelegate)
- t = new TypeDelegate(t);
- else
- t = new TypePointer(t); // pointer to function
- continue;
- }
+ nextToken();
+ arguments = parseParameters(&varargs);
+ t = new TypeFunction(arguments, t, varargs, linkage);
+ if (save == TOKdelegate)
+ t = new TypeDelegate(t);
+ else
+ t = new TypePointer(t); // pointer to function
+ continue;
+ }
- default:
- ts = t;
- break;
- }
- break;
+ default:
+ ts = t;
+ break;
+ }
+ break;
}
return ts;
}
@@ -1983,108 +1983,108 @@ Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters *
switch (token.value)
{
- case TOKidentifier:
- if (pident)
- *pident = token.ident;
- else
- error("unexpected identifer '%s' in declarator", token.ident->toChars());
- ts = t;
- nextToken();
- break;
+ case TOKidentifier:
+ if (pident)
+ *pident = token.ident;
+ else
+ error("unexpected identifer '%s' in declarator", token.ident->toChars());
+ ts = t;
+ nextToken();
+ break;
- case TOKlparen:
- /* Parse things with parentheses around the identifier, like:
- * int (*ident[3])[]
- * although the D style would be:
- * int[]*[3] ident
- */
- nextToken();
- ts = parseDeclarator(t, pident);
- check(TOKrparen);
- break;
+ case TOKlparen:
+ /* Parse things with parentheses around the identifier, like:
+ * int (*ident[3])[]
+ * although the D style would be:
+ * int[]*[3] ident
+ */
+ nextToken();
+ ts = parseDeclarator(t, pident);
+ check(TOKrparen);
+ break;
- default:
- ts = t;
- break;
+ default:
+ ts = t;
+ break;
}
// parse DeclaratorSuffixes
while (1)
{
- switch (token.value)
- {
+ switch (token.value)
+ {
#if CARRAYDECL
- /* Support C style array syntax:
- * int ident[]
- * as opposed to D-style:
- * int[] ident
- */
- case TOKlbracket:
- { // This is the old C-style post [] syntax.
- nextToken();
- if (token.value == TOKrbracket)
- { // It's a dynamic array
- ta = new TypeDArray(t); // []
- nextToken();
- }
- else if (isDeclaration(&token, 0, TOKrbracket, NULL))
- { // It's an associative array declaration
- Type *index;
+ /* Support C style array syntax:
+ * int ident[]
+ * as opposed to D-style:
+ * int[] ident
+ */
+ case TOKlbracket:
+ { // This is the old C-style post [] syntax.
+ nextToken();
+ if (token.value == TOKrbracket)
+ { // It's a dynamic array
+ ta = new TypeDArray(t); // []
+ nextToken();
+ }
+ else if (isDeclaration(&token, 0, TOKrbracket, NULL))
+ { // It's an associative array declaration
+ Type *index;
- //printf("it's an associative array\n");
- index = parseBasicType();
- index = parseDeclarator(index, NULL); // [ type ]
- check(TOKrbracket);
- ta = new TypeAArray(t, index);
- }
- else
- {
- //printf("it's [expression]\n");
- Expression *e = parseExpression(); // [ expression ]
- ta = new TypeSArray(t, e);
- check(TOKrbracket);
- }
+ //printf("it's an associative array\n");
+ index = parseBasicType();
+ index = parseDeclarator(index, NULL); // [ type ]
+ check(TOKrbracket);
+ ta = new TypeAArray(t, index);
+ }
+ else
+ {
+ //printf("it's [expression]\n");
+ Expression *e = parseExpression(); // [ expression ]
+ ta = new TypeSArray(t, e);
+ check(TOKrbracket);
+ }
- /* Insert ta into
- * ts -> ... -> t
- * so that
- * ts -> ... -> ta -> t
- */
- Type **pt;
- for (pt = &ts; *pt != t; pt = &(*pt)->next)
- ;
- *pt = ta;
- continue;
- }
+ /* Insert ta into
+ * ts -> ... -> t
+ * so that
+ * ts -> ... -> ta -> t
+ */
+ Type **pt;
+ for (pt = &ts; *pt != t; pt = &(*pt)->next)
+ ;
+ *pt = ta;
+ continue;
+ }
#endif
- case TOKlparen:
- { Parameters *arguments;
- int varargs;
+ case TOKlparen:
+ { Parameters *arguments;
+ int varargs;
- if (tpl)
- {
- /* Look ahead to see if this is (...)(...),
- * i.e. a function template declaration
- */
- if (peekPastParen(&token)->value == TOKlparen)
- { // It's a function template declaration
- //printf("function template declaration\n");
+ if (tpl)
+ {
+ /* Look ahead to see if this is (...)(...),
+ * i.e. a function template declaration
+ */
+ if (peekPastParen(&token)->value == TOKlparen)
+ { // It's a function template declaration
+ //printf("function template declaration\n");
- // Gather template parameter list
- *tpl = parseTemplateParameterList();
- }
- }
+ // Gather template parameter list
+ *tpl = parseTemplateParameterList();
+ }
+ }
- arguments = parseParameters(&varargs);
- Type *ta = new TypeFunction(arguments, t, varargs, linkage);
- Type **pt;
- for (pt = &ts; *pt != t; pt = &(*pt)->next)
- ;
- *pt = ta;
- break;
- }
- }
- break;
+ arguments = parseParameters(&varargs);
+ Type *ta = new TypeFunction(arguments, t, varargs, linkage);
+ Type **pt;
+ for (pt = &ts; *pt != t; pt = &(*pt)->next)
+ ;
+ *pt = ta;
+ break;
+ }
+ }
+ break;
}
return ts;
@@ -2093,8 +2093,8 @@ Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters *
/**********************************
* Parse Declarations.
* These can be:
- * 1. declarations at global/class level
- * 2. declarations at statement level
+ * 1. declarations at global/class level
+ * 2. declarations at statement level
* Return array of Declaration *'s.
*/
@@ -2114,104 +2114,104 @@ Array *Parser::parseDeclarations()
//printf("parseDeclarations()\n");
switch (token.value)
{
- case TOKtypedef:
- case TOKalias:
- tok = token.value;
- nextToken();
- break;
+ case TOKtypedef:
+ case TOKalias:
+ tok = token.value;
+ nextToken();
+ break;
- default:
- tok = TOKreserved;
- break;
+ default:
+ tok = TOKreserved;
+ break;
}
storage_class = STCundefined;
while (1)
{
- switch (token.value)
- {
- case TOKconst: stc = STCconst; goto L1;
- case TOKstatic: stc = STCstatic; goto L1;
- case TOKfinal: stc = STCfinal; goto L1;
- case TOKauto: stc = STCauto; goto L1;
- case TOKscope: stc = STCscope; goto L1;
- case TOKoverride: stc = STCoverride; goto L1;
- case TOKabstract: stc = STCabstract; goto L1;
- case TOKsynchronized: stc = STCsynchronized; goto L1;
- case TOKdeprecated: stc = STCdeprecated; goto L1;
+ switch (token.value)
+ {
+ case TOKconst: stc = STCconst; goto L1;
+ case TOKstatic: stc = STCstatic; goto L1;
+ case TOKfinal: stc = STCfinal; goto L1;
+ case TOKauto: stc = STCauto; goto L1;
+ case TOKscope: stc = STCscope; goto L1;
+ case TOKoverride: stc = STCoverride; goto L1;
+ case TOKabstract: stc = STCabstract; goto L1;
+ case TOKsynchronized: stc = STCsynchronized; goto L1;
+ case TOKdeprecated: stc = STCdeprecated; goto L1;
#if DMDV2
- case TOKnothrow: stc = STCnothrow; goto L1;
- case TOKpure: stc = STCpure; goto L1;
- case TOKref: stc = STCref; goto L1;
- case TOKtls: stc = STCtls; goto L1;
- case TOKenum: stc = STCmanifest; goto L1;
+ case TOKnothrow: stc = STCnothrow; goto L1;
+ case TOKpure: stc = STCpure; goto L1;
+ case TOKref: stc = STCref; goto L1;
+ case TOKtls: stc = STCtls; goto L1;
+ case TOKenum: stc = STCmanifest; goto L1;
#endif
- L1:
- if (storage_class & stc)
- error("redundant storage class '%s'", token.toChars());
- storage_class = (STC) (storage_class | stc);
- nextToken();
- continue;
+ L1:
+ if (storage_class & stc)
+ error("redundant storage class '%s'", token.toChars());
+ storage_class = (STC) (storage_class | stc);
+ nextToken();
+ continue;
- case TOKextern:
- if (peek(&token)->value != TOKlparen)
- { stc = STCextern;
- goto L1;
- }
+ case TOKextern:
+ if (peek(&token)->value != TOKlparen)
+ { stc = STCextern;
+ goto L1;
+ }
- link = parseLinkage();
- continue;
+ link = parseLinkage();
+ continue;
- default:
- break;
- }
- break;
+ default:
+ break;
+ }
+ break;
}
a = new Array();
/* Look for auto initializers:
- * storage_class identifier = initializer;
+ * storage_class identifier = initializer;
*/
while (storage_class &&
- token.value == TOKidentifier &&
- peek(&token)->value == TOKassign)
+ token.value == TOKidentifier &&
+ peek(&token)->value == TOKassign)
{
- ident = token.ident;
- nextToken();
- nextToken();
- Initializer *init = parseInitializer();
- VarDeclaration *v = new VarDeclaration(loc, NULL, ident, init);
- v->storage_class = storage_class;
- a->push(v);
- if (token.value == TOKsemicolon)
- {
- nextToken();
- addComment(v, comment);
- }
- else if (token.value == TOKcomma)
- {
- nextToken();
- if (!(token.value == TOKidentifier && peek(&token)->value == TOKassign))
- {
- error("Identifier expected following comma");
- }
- else
- continue;
- }
- else
- error("semicolon expected following auto declaration, not '%s'", token.toChars());
- return a;
+ ident = token.ident;
+ nextToken();
+ nextToken();
+ Initializer *init = parseInitializer();
+ VarDeclaration *v = new VarDeclaration(loc, NULL, ident, init);
+ v->storage_class = storage_class;
+ a->push(v);
+ if (token.value == TOKsemicolon)
+ {
+ nextToken();
+ addComment(v, comment);
+ }
+ else if (token.value == TOKcomma)
+ {
+ nextToken();
+ if (!(token.value == TOKidentifier && peek(&token)->value == TOKassign))
+ {
+ error("Identifier expected following comma");
+ }
+ else
+ continue;
+ }
+ else
+ error("semicolon expected following auto declaration, not '%s'", token.toChars());
+ return a;
}
if (token.value == TOKclass)
- { AggregateDeclaration *s;
+ { AggregateDeclaration *s;
- s = (AggregateDeclaration *)parseAggregate();
- s->storage_class |= storage_class;
- a->push(s);
- addComment(s, comment);
- return a;
+ s = (AggregateDeclaration *)parseAggregate();
+ s->storage_class |= storage_class;
+ a->push(s);
+ addComment(s, comment);
+ return a;
}
ts = parseBasicType();
@@ -2220,129 +2220,129 @@ Array *Parser::parseDeclarations()
while (1)
{
- Loc loc = this->loc;
- TemplateParameters *tpl = NULL;
+ Loc loc = this->loc;
+ TemplateParameters *tpl = NULL;
- ident = NULL;
- t = parseDeclarator(ts, &ident, &tpl);
- assert(t);
- if (!tfirst)
- tfirst = t;
- else if (t != tfirst)
- error("multiple declarations must have the same type, not %s and %s",
- tfirst->toChars(), t->toChars());
- if (!ident)
- error("no identifier for declarator %s", t->toChars());
+ ident = NULL;
+ t = parseDeclarator(ts, &ident, &tpl);
+ assert(t);
+ if (!tfirst)
+ tfirst = t;
+ else if (t != tfirst)
+ error("multiple declarations must have the same type, not %s and %s",
+ tfirst->toChars(), t->toChars());
+ if (!ident)
+ error("no identifier for declarator %s", t->toChars());
- if (tok == TOKtypedef || tok == TOKalias)
- { Declaration *v;
- Initializer *init = NULL;
+ if (tok == TOKtypedef || tok == TOKalias)
+ { Declaration *v;
+ Initializer *init = NULL;
- if (token.value == TOKassign)
- {
- nextToken();
- init = parseInitializer();
- }
- if (tok == TOKtypedef)
- v = new TypedefDeclaration(loc, ident, t, init);
- else
- { if (init)
- error("alias cannot have initializer");
- v = new AliasDeclaration(loc, ident, t);
- }
- v->storage_class = storage_class;
- if (link == linkage)
- a->push(v);
- else
- {
- Array *ax = new Array();
- ax->push(v);
- Dsymbol *s = new LinkDeclaration(link, ax);
- a->push(s);
- }
- switch (token.value)
- { case TOKsemicolon:
- nextToken();
- addComment(v, comment);
- break;
+ if (token.value == TOKassign)
+ {
+ nextToken();
+ init = parseInitializer();
+ }
+ if (tok == TOKtypedef)
+ v = new TypedefDeclaration(loc, ident, t, init);
+ else
+ { if (init)
+ error("alias cannot have initializer");
+ v = new AliasDeclaration(loc, ident, t);
+ }
+ v->storage_class = storage_class;
+ if (link == linkage)
+ a->push(v);
+ else
+ {
+ Array *ax = new Array();
+ ax->push(v);
+ Dsymbol *s = new LinkDeclaration(link, ax);
+ a->push(s);
+ }
+ switch (token.value)
+ { case TOKsemicolon:
+ nextToken();
+ addComment(v, comment);
+ break;
- case TOKcomma:
- nextToken();
- addComment(v, comment);
- continue;
+ case TOKcomma:
+ nextToken();
+ addComment(v, comment);
+ continue;
- default:
- error("semicolon expected to close %s declaration", Token::toChars(tok));
- break;
- }
- }
- else if (t->ty == Tfunction)
- { FuncDeclaration *f =
- new FuncDeclaration(loc, 0, ident, storage_class, t);
- addComment(f, comment);
- parseContracts(f);
- addComment(f, NULL);
- Dsymbol *s;
- if (link == linkage)
- {
- s = f;
- }
- else
- {
- Array *ax = new Array();
- ax->push(f);
- s = new LinkDeclaration(link, ax);
- }
- if (tpl) // it's a function template
- { Array *decldefs;
- TemplateDeclaration *tempdecl;
+ default:
+ error("semicolon expected to close %s declaration", Token::toChars(tok));
+ break;
+ }
+ }
+ else if (t->ty == Tfunction)
+ { FuncDeclaration *f =
+ new FuncDeclaration(loc, 0, ident, storage_class, t);
+ addComment(f, comment);
+ parseContracts(f);
+ addComment(f, NULL);
+ Dsymbol *s;
+ if (link == linkage)
+ {
+ s = f;
+ }
+ else
+ {
+ Array *ax = new Array();
+ ax->push(f);
+ s = new LinkDeclaration(link, ax);
+ }
+ if (tpl) // it's a function template
+ { Array *decldefs;
+ TemplateDeclaration *tempdecl;
- // Wrap a template around the aggregate declaration
- decldefs = new Array();
- decldefs->push(s);
- tempdecl = new TemplateDeclaration(loc, s->ident, tpl, NULL, decldefs);
- s = tempdecl;
- }
- addComment(s, comment);
- a->push(s);
- }
- else
- {
- Initializer *init = NULL;
- if (token.value == TOKassign)
- {
- nextToken();
- init = parseInitializer();
- }
+ // Wrap a template around the aggregate declaration
+ decldefs = new Array();
+ decldefs->push(s);
+ tempdecl = new TemplateDeclaration(loc, s->ident, tpl, NULL, decldefs);
+ s = tempdecl;
+ }
+ addComment(s, comment);
+ a->push(s);
+ }
+ else
+ {
+ Initializer *init = NULL;
+ if (token.value == TOKassign)
+ {
+ nextToken();
+ init = parseInitializer();
+ }
- VarDeclaration *v = new VarDeclaration(loc, t, ident, init);
- v->storage_class = storage_class;
- if (link == linkage)
- a->push(v);
- else
- {
- Array *ax = new Array();
- ax->push(v);
- Dsymbol *s = new LinkDeclaration(link, ax);
- a->push(s);
- }
- switch (token.value)
- { case TOKsemicolon:
- nextToken();
- addComment(v, comment);
- break;
+ VarDeclaration *v = new VarDeclaration(loc, t, ident, init);
+ v->storage_class = storage_class;
+ if (link == linkage)
+ a->push(v);
+ else
+ {
+ Array *ax = new Array();
+ ax->push(v);
+ Dsymbol *s = new LinkDeclaration(link, ax);
+ a->push(s);
+ }
+ switch (token.value)
+ { case TOKsemicolon:
+ nextToken();
+ addComment(v, comment);
+ break;
- case TOKcomma:
- nextToken();
- addComment(v, comment);
- continue;
+ case TOKcomma:
+ nextToken();
+ addComment(v, comment);
+ continue;
- default:
- error("semicolon expected, not '%s'", token.toChars());
- break;
- }
- }
- break;
+ default:
+ error("semicolon expected, not '%s'", token.toChars());
+ break;
+ }
+ }
+ break;
}
return a;
}
@@ -2362,34 +2362,34 @@ Array *Parser::parseAutoDeclarations(StorageClass storageClass, unsigned char *c
while (1)
{
- Identifier *ident = token.ident;
- nextToken(); // skip over ident
- assert(token.value == TOKassign);
- nextToken(); // skip over '='
- Initializer *init = parseInitializer();
- VarDeclaration *v = new VarDeclaration(loc, NULL, ident, init);
- v->storage_class = storageClass;
- a->push(v);
- if (token.value == TOKsemicolon)
- {
- nextToken();
- addComment(v, comment);
- }
- else if (token.value == TOKcomma)
- {
- nextToken();
- if (token.value == TOKidentifier &&
- peek(&token)->value == TOKassign)
- {
- addComment(v, comment);
- continue;
- }
- else
- error("Identifier expected following comma");
- }
- else
- error("semicolon expected following auto declaration, not '%s'", token.toChars());
- break;
+ Identifier *ident = token.ident;
+ nextToken(); // skip over ident
+ assert(token.value == TOKassign);
+ nextToken(); // skip over '='
+ Initializer *init = parseInitializer();
+ VarDeclaration *v = new VarDeclaration(loc, NULL, ident, init);
+ v->storage_class = storageClass;
+ a->push(v);
+ if (token.value == TOKsemicolon)
+ {
+ nextToken();
+ addComment(v, comment);
+ }
+ else if (token.value == TOKcomma)
+ {
+ nextToken();
+ if (token.value == TOKidentifier &&
+ peek(&token)->value == TOKassign)
+ {
+ addComment(v, comment);
+ continue;
+ }
+ else
+ error("Identifier expected following comma");
+ }
+ else
+ error("semicolon expected following auto declaration, not '%s'", token.toChars());
+ break;
}
return a;
}
@@ -2406,83 +2406,83 @@ void Parser::parseContracts(FuncDeclaration *f)
// The following is irrelevant, as it is overridden by sc->linkage in
// TypeFunction::semantic
- linkage = LINKd; // nested functions have D linkage
+ linkage = LINKd; // nested functions have D linkage
L1:
switch (token.value)
{
- case TOKlcurly:
- if (f->frequire || f->fensure)
- error("missing body { ... } after in or out");
- f->fbody = parseStatement(PSsemi);
- f->endloc = endloc;
- break;
+ case TOKlcurly:
+ if (f->frequire || f->fensure)
+ error("missing body { ... } after in or out");
+ f->fbody = parseStatement(PSsemi);
+ f->endloc = endloc;
+ break;
- case TOKbody:
- nextToken();
- f->fbody = parseStatement(PScurly);
- f->endloc = endloc;
- break;
+ case TOKbody:
+ nextToken();
+ f->fbody = parseStatement(PScurly);
+ f->endloc = endloc;
+ break;
- case TOKsemicolon:
- if (f->frequire || f->fensure)
- error("missing body { ... } after in or out");
- nextToken();
- break;
+ case TOKsemicolon:
+ if (f->frequire || f->fensure)
+ error("missing body { ... } after in or out");
+ nextToken();
+ break;
-#if 0 // Do we want this for function declarations, so we can do:
+#if 0 // Do we want this for function declarations, so we can do:
// int x, y, foo(), z;
- case TOKcomma:
- nextToken();
- continue;
+ case TOKcomma:
+ nextToken();
+ continue;
#endif
#if 0 // Dumped feature
- case TOKthrow:
- if (!f->fthrows)
- f->fthrows = new Array();
- nextToken();
- check(TOKlparen);
- while (1)
- {
- tb = parseBasicType();
- f->fthrows->push(tb);
- if (token.value == TOKcomma)
- { nextToken();
- continue;
- }
- break;
- }
- check(TOKrparen);
- goto L1;
+ case TOKthrow:
+ if (!f->fthrows)
+ f->fthrows = new Array();
+ nextToken();
+ check(TOKlparen);
+ while (1)
+ {
+ tb = parseBasicType();
+ f->fthrows->push(tb);
+ if (token.value == TOKcomma)
+ { nextToken();
+ continue;
+ }
+ break;
+ }
+ check(TOKrparen);
+ goto L1;
#endif
- case TOKin:
- nextToken();
- if (f->frequire)
- error("redundant 'in' statement");
- f->frequire = parseStatement(PScurly | PSscope);
- goto L1;
+ case TOKin:
+ nextToken();
+ if (f->frequire)
+ error("redundant 'in' statement");
+ f->frequire = parseStatement(PScurly | PSscope);
+ goto L1;
- case TOKout:
- // parse: out (identifier) { statement }
- nextToken();
- if (token.value != TOKlcurly)
- {
- check(TOKlparen);
- if (token.value != TOKidentifier)
- error("(identifier) following 'out' expected, not %s", token.toChars());
- f->outId = token.ident;
- nextToken();
- check(TOKrparen);
- }
- if (f->fensure)
- error("redundant 'out' statement");
- f->fensure = parseStatement(PScurly | PSscope);
- goto L1;
+ case TOKout:
+ // parse: out (identifier) { statement }
+ nextToken();
+ if (token.value != TOKlcurly)
+ {
+ check(TOKlparen);
+ if (token.value != TOKidentifier)
+ error("(identifier) following 'out' expected, not %s", token.toChars());
+ f->outId = token.ident;
+ nextToken();
+ check(TOKrparen);
+ }
+ if (f->fensure)
+ error("redundant 'out' statement");
+ f->fensure = parseStatement(PScurly | PSscope);
+ goto L1;
- default:
- error("semicolon expected following function declaration");
- break;
+ default:
+ error("semicolon expected following function declaration");
+ break;
}
linkage = linksave;
}
@@ -2507,192 +2507,192 @@ Initializer *Parser::parseInitializer()
switch (token.value)
{
- case TOKlcurly:
- /* Scan ahead to see if it is a struct initializer or
- * a function literal.
- * If it contains a ';', it is a function literal.
- * Treat { } as a struct initializer.
- */
- braces = 1;
- for (t = peek(&token); 1; t = peek(t))
- {
- switch (t->value)
- {
- case TOKsemicolon:
- case TOKreturn:
- goto Lexpression;
+ case TOKlcurly:
+ /* Scan ahead to see if it is a struct initializer or
+ * a function literal.
+ * If it contains a ';', it is a function literal.
+ * Treat { } as a struct initializer.
+ */
+ braces = 1;
+ for (t = peek(&token); 1; t = peek(t))
+ {
+ switch (t->value)
+ {
+ case TOKsemicolon:
+ case TOKreturn:
+ goto Lexpression;
- case TOKlcurly:
- braces++;
- continue;
+ case TOKlcurly:
+ braces++;
+ continue;
- case TOKrcurly:
- if (--braces == 0)
- break;
- continue;
+ case TOKrcurly:
+ if (--braces == 0)
+ break;
+ continue;
- case TOKeof:
- break;
+ case TOKeof:
+ break;
- default:
- continue;
- }
- break;
- }
+ default:
+ continue;
+ }
+ break;
+ }
- is = new StructInitializer(loc);
- nextToken();
- comma = 0;
- while (1)
- {
- switch (token.value)
- {
- case TOKidentifier:
- if (comma == 1)
- error("comma expected separating field initializers");
- t = peek(&token);
- if (t->value == TOKcolon)
- {
- id = token.ident;
- nextToken();
- nextToken(); // skip over ':'
- }
- else
- { id = NULL;
- }
- value = parseInitializer();
- is->addInit(id, value);
- comma = 1;
- continue;
+ is = new StructInitializer(loc);
+ nextToken();
+ comma = 0;
+ while (1)
+ {
+ switch (token.value)
+ {
+ case TOKidentifier:
+ if (comma == 1)
+ error("comma expected separating field initializers");
+ t = peek(&token);
+ if (t->value == TOKcolon)
+ {
+ id = token.ident;
+ nextToken();
+ nextToken(); // skip over ':'
+ }
+ else
+ { id = NULL;
+ }
+ value = parseInitializer();
+ is->addInit(id, value);
+ comma = 1;
+ continue;
- case TOKcomma:
- nextToken();
- comma = 2;
- continue;
+ case TOKcomma:
+ nextToken();
+ comma = 2;
+ continue;
- case TOKrcurly: // allow trailing comma's
- nextToken();
- break;
+ case TOKrcurly: // allow trailing comma's
+ nextToken();
+ break;
- case TOKeof:
- error("found EOF instead of initializer");
- break;
+ case TOKeof:
+ error("found EOF instead of initializer");
+ break;
- default:
- value = parseInitializer();
- is->addInit(NULL, value);
- comma = 1;
- continue;
- //error("found '%s' instead of field initializer", token.toChars());
- //break;
- }
- break;
- }
- return is;
+ default:
+ value = parseInitializer();
+ is->addInit(NULL, value);
+ comma = 1;
+ continue;
+ //error("found '%s' instead of field initializer", token.toChars());
+ //break;
+ }
+ break;
+ }
+ return is;
- case TOKlbracket:
- /* Scan ahead to see if it is an array initializer or
- * an expression.
- * If it ends with a ';', it is an array initializer.
- */
- brackets = 1;
- for (t = peek(&token); 1; t = peek(t))
- {
- switch (t->value)
- {
- case TOKlbracket:
- brackets++;
- continue;
+ case TOKlbracket:
+ /* Scan ahead to see if it is an array initializer or
+ * an expression.
+ * If it ends with a ';', it is an array initializer.
+ */
+ brackets = 1;
+ for (t = peek(&token); 1; t = peek(t))
+ {
+ switch (t->value)
+ {
+ case TOKlbracket:
+ brackets++;
+ continue;
- case TOKrbracket:
- if (--brackets == 0)
- { t = peek(t);
- if (t->value != TOKsemicolon &&
- t->value != TOKcomma &&
- t->value != TOKrcurly)
- goto Lexpression;
- break;
- }
- continue;
+ case TOKrbracket:
+ if (--brackets == 0)
+ { t = peek(t);
+ if (t->value != TOKsemicolon &&
+ t->value != TOKcomma &&
+ t->value != TOKrcurly)
+ goto Lexpression;
+ break;
+ }
+ continue;
- case TOKeof:
- break;
+ case TOKeof:
+ break;
- default:
- continue;
- }
- break;
- }
+ default:
+ continue;
+ }
+ break;
+ }
- ia = new ArrayInitializer(loc);
- nextToken();
- comma = 0;
- while (1)
- {
- switch (token.value)
- {
- default:
- if (comma == 1)
- { error("comma expected separating array initializers, not %s", token.toChars());
- nextToken();
- break;
- }
- e = parseAssignExp();
- if (!e)
- break;
- if (token.value == TOKcolon)
- {
- nextToken();
- value = parseInitializer();
- }
- else
- { value = new ExpInitializer(e->loc, e);
- e = NULL;
- }
- ia->addInit(e, value);
- comma = 1;
- continue;
+ ia = new ArrayInitializer(loc);
+ nextToken();
+ comma = 0;
+ while (1)
+ {
+ switch (token.value)
+ {
+ default:
+ if (comma == 1)
+ { error("comma expected separating array initializers, not %s", token.toChars());
+ nextToken();
+ break;
+ }
+ e = parseAssignExp();
+ if (!e)
+ break;
+ if (token.value == TOKcolon)
+ {
+ nextToken();
+ value = parseInitializer();
+ }
+ else
+ { value = new ExpInitializer(e->loc, e);
+ e = NULL;
+ }
+ ia->addInit(e, value);
+ comma = 1;
+ continue;
- case TOKlcurly:
- case TOKlbracket:
- if (comma == 1)
- error("comma expected separating array initializers, not %s", token.toChars());
- value = parseInitializer();
- ia->addInit(NULL, value);
- comma = 1;
- continue;
+ case TOKlcurly:
+ case TOKlbracket:
+ if (comma == 1)
+ error("comma expected separating array initializers, not %s", token.toChars());
+ value = parseInitializer();
+ ia->addInit(NULL, value);
+ comma = 1;
+ continue;
- case TOKcomma:
- nextToken();
- comma = 2;
- continue;
+ case TOKcomma:
+ nextToken();
+ comma = 2;
+ continue;
- case TOKrbracket: // allow trailing comma's
- nextToken();
- break;
+ case TOKrbracket: // allow trailing comma's
+ nextToken();
+ break;
- case TOKeof:
- error("found '%s' instead of array initializer", token.toChars());
- break;
- }
- break;
- }
- return ia;
+ case TOKeof:
+ error("found '%s' instead of array initializer", token.toChars());
+ break;
+ }
+ break;
+ }
+ return ia;
- case TOKvoid:
- t = peek(&token);
- if (t->value == TOKsemicolon || t->value == TOKcomma)
- {
- nextToken();
- return new VoidInitializer(loc);
- }
- goto Lexpression;
+ case TOKvoid:
+ t = peek(&token);
+ if (t->value == TOKsemicolon || t->value == TOKcomma)
+ {
+ nextToken();
+ return new VoidInitializer(loc);
+ }
+ goto Lexpression;
- default:
- Lexpression:
- e = parseAssignExp();
- ie = new ExpInitializer(loc, e);
- return ie;
+ default:
+ Lexpression:
+ e = parseAssignExp();
+ ie = new ExpInitializer(loc, e);
+ return ie;
}
}
@@ -2705,19 +2705,19 @@ Initializer *Parser::parseInitializer()
Expression *Parser::parseDefaultInitExp()
{
if (token.value == TOKfile ||
- token.value == TOKline)
+ token.value == TOKline)
{
- Token *t = peek(&token);
- if (t->value == TOKcomma || t->value == TOKrparen)
- { Expression *e;
+ Token *t = peek(&token);
+ if (t->value == TOKcomma || t->value == TOKrparen)
+ { Expression *e;
- if (token.value == TOKfile)
- e = new FileInitExp(loc);
- else
- e = new LineInitExp(loc);
- nextToken();
- return e;
- }
+ if (token.value == TOKfile)
+ e = new FileInitExp(loc);
+ else
+ e = new LineInitExp(loc);
+ nextToken();
+ return e;
+ }
}
Expression *e = parseAssignExp();
@@ -2727,7 +2727,7 @@ Expression *Parser::parseDefaultInitExp()
/*****************************************
* Input:
- * flags PSxxxx
+ * flags PSxxxx
*/
Statement *Parser::parseStatement(int flags)
@@ -2741,823 +2741,823 @@ Statement *Parser::parseStatement(int flags)
//printf("parseStatement()\n");
if (flags & PScurly && token.value != TOKlcurly)
- error("statement expected to be { }, not %s", token.toChars());
+ error("statement expected to be { }, not %s", token.toChars());
switch (token.value)
{
- case TOKidentifier:
- /* A leading identifier can be a declaration, label, or expression.
- * The easiest case to check first is label:
- */
- t = peek(&token);
- if (t->value == TOKcolon)
- { // It's a label
+ case TOKidentifier:
+ /* A leading identifier can be a declaration, label, or expression.
+ * The easiest case to check first is label:
+ */
+ t = peek(&token);
+ if (t->value == TOKcolon)
+ { // It's a label
- Identifier *ident = token.ident;
- nextToken();
- nextToken();
- s = parseStatement(PSsemi);
- s = new LabelStatement(loc, ident, s);
- break;
- }
- // fallthrough to TOKdot
- case TOKdot:
- case TOKtypeof:
- if (isDeclaration(&token, 2, TOKreserved, NULL))
- goto Ldeclaration;
- else
- goto Lexp;
- break;
+ Identifier *ident = token.ident;
+ nextToken();
+ nextToken();
+ s = parseStatement(PSsemi);
+ s = new LabelStatement(loc, ident, s);
+ break;
+ }
+ // fallthrough to TOKdot
+ case TOKdot:
+ case TOKtypeof:
+ if (isDeclaration(&token, 2, TOKreserved, NULL))
+ goto Ldeclaration;
+ else
+ goto Lexp;
+ break;
- case TOKassert:
- case TOKthis:
- case TOKsuper:
- case TOKint32v:
- case TOKuns32v:
- case TOKint64v:
- case TOKuns64v:
- case TOKfloat32v:
- case TOKfloat64v:
- case TOKfloat80v:
- case TOKimaginary32v:
- case TOKimaginary64v:
- case TOKimaginary80v:
- case TOKcharv:
- case TOKwcharv:
- case TOKdcharv:
- case TOKnull:
- case TOKtrue:
- case TOKfalse:
- case TOKstring:
- case TOKlparen:
- case TOKcast:
- case TOKmul:
- case TOKmin:
- case TOKadd:
- case TOKplusplus:
- case TOKminusminus:
- case TOKnew:
- case TOKdelete:
- case TOKdelegate:
- case TOKfunction:
- case TOKtypeid:
- case TOKis:
- case TOKlbracket:
+ case TOKassert:
+ case TOKthis:
+ case TOKsuper:
+ case TOKint32v:
+ case TOKuns32v:
+ case TOKint64v:
+ case TOKuns64v:
+ case TOKfloat32v:
+ case TOKfloat64v:
+ case TOKfloat80v:
+ case TOKimaginary32v:
+ case TOKimaginary64v:
+ case TOKimaginary80v:
+ case TOKcharv:
+ case TOKwcharv:
+ case TOKdcharv:
+ case TOKnull:
+ case TOKtrue:
+ case TOKfalse:
+ case TOKstring:
+ case TOKlparen:
+ case TOKcast:
+ case TOKmul:
+ case TOKmin:
+ case TOKadd:
+ case TOKplusplus:
+ case TOKminusminus:
+ case TOKnew:
+ case TOKdelete:
+ case TOKdelegate:
+ case TOKfunction:
+ case TOKtypeid:
+ case TOKis:
+ case TOKlbracket:
#if DMDV2
- case TOKtraits:
- case TOKfile:
- case TOKline:
+ case TOKtraits:
+ case TOKfile:
+ case TOKline:
#endif
- Lexp:
- { Expression *exp;
+ Lexp:
+ { Expression *exp;
- exp = parseExpression();
- check(TOKsemicolon, "statement");
- s = new ExpStatement(loc, exp);
- break;
- }
+ exp = parseExpression();
+ check(TOKsemicolon, "statement");
+ s = new ExpStatement(loc, exp);
+ break;
+ }
- case TOKstatic:
- { // Look ahead to see if it's static assert() or static if()
- Token *t;
+ case TOKstatic:
+ { // Look ahead to see if it's static assert() or static if()
+ Token *t;
- t = peek(&token);
- if (t->value == TOKassert)
- {
- nextToken();
- s = new StaticAssertStatement(parseStaticAssert());
- break;
- }
- if (t->value == TOKif)
- {
- nextToken();
- condition = parseStaticIfCondition();
- goto Lcondition;
- }
- goto Ldeclaration;
- }
+ t = peek(&token);
+ if (t->value == TOKassert)
+ {
+ nextToken();
+ s = new StaticAssertStatement(parseStaticAssert());
+ break;
+ }
+ if (t->value == TOKif)
+ {
+ nextToken();
+ condition = parseStaticIfCondition();
+ goto Lcondition;
+ }
+ goto Ldeclaration;
+ }
- case BASIC_TYPES:
- case TOKtypedef:
- case TOKalias:
- case TOKconst:
- case TOKauto:
- case TOKextern:
- case TOKfinal:
- case TOKinvariant:
+ case BASIC_TYPES:
+ case TOKtypedef:
+ case TOKalias:
+ case TOKconst:
+ case TOKauto:
+ case TOKextern:
+ case TOKfinal:
+ case TOKinvariant:
#if DMDV2
- case TOKimmutable:
- case TOKshared:
+ case TOKimmutable:
+ case TOKshared:
#endif
-// case TOKtypeof:
- Ldeclaration:
- { Array *a;
+// case TOKtypeof:
+ Ldeclaration:
+ { Array *a;
- a = parseDeclarations();
- if (a->dim > 1)
- {
- Statements *as = new Statements();
- as->reserve(a->dim);
- for (int i = 0; i < a->dim; i++)
- {
- Dsymbol *d = (Dsymbol *)a->data[i];
- s = new DeclarationStatement(loc, d);
- as->push(s);
- }
- s = new CompoundDeclarationStatement(loc, as);
- }
- else if (a->dim == 1)
- {
- Dsymbol *d = (Dsymbol *)a->data[0];
- s = new DeclarationStatement(loc, d);
- }
- else
- assert(0);
- if (flags & PSscope)
- s = new ScopeStatement(loc, s);
- break;
- }
+ a = parseDeclarations();
+ if (a->dim > 1)
+ {
+ Statements *as = new Statements();
+ as->reserve(a->dim);
+ for (int i = 0; i < a->dim; i++)
+ {
+ Dsymbol *d = (Dsymbol *)a->data[i];
+ s = new DeclarationStatement(loc, d);
+ as->push(s);
+ }
+ s = new CompoundDeclarationStatement(loc, as);
+ }
+ else if (a->dim == 1)
+ {
+ Dsymbol *d = (Dsymbol *)a->data[0];
+ s = new DeclarationStatement(loc, d);
+ }
+ else
+ assert(0);
+ if (flags & PSscope)
+ s = new ScopeStatement(loc, s);
+ break;
+ }
- case TOKstruct:
- case TOKunion:
- case TOKclass:
- case TOKinterface:
- { Dsymbol *d;
+ case TOKstruct:
+ case TOKunion:
+ case TOKclass:
+ case TOKinterface:
+ { Dsymbol *d;
- d = parseAggregate();
- s = new DeclarationStatement(loc, d);
- break;
- }
+ d = parseAggregate();
+ s = new DeclarationStatement(loc, d);
+ break;
+ }
- case TOKenum:
- { Dsymbol *d;
+ case TOKenum:
+ { Dsymbol *d;
- d = parseEnum();
- s = new DeclarationStatement(loc, d);
- break;
- }
+ d = parseEnum();
+ s = new DeclarationStatement(loc, d);
+ break;
+ }
- case TOKmixin:
- { t = peek(&token);
- if (t->value == TOKlparen)
- { // mixin(string)
- nextToken();
- check(TOKlparen, "mixin");
- Expression *e = parseAssignExp();
- check(TOKrparen);
- check(TOKsemicolon);
- s = new CompileStatement(loc, e);
- break;
- }
- Dsymbol *d = parseMixin();
- s = new DeclarationStatement(loc, d);
- break;
- }
+ case TOKmixin:
+ { t = peek(&token);
+ if (t->value == TOKlparen)
+ { // mixin(string)
+ nextToken();
+ check(TOKlparen, "mixin");
+ Expression *e = parseAssignExp();
+ check(TOKrparen);
+ check(TOKsemicolon);
+ s = new CompileStatement(loc, e);
+ break;
+ }
+ Dsymbol *d = parseMixin();
+ s = new DeclarationStatement(loc, d);
+ break;
+ }
- case TOKlcurly:
- {
- nextToken();
- Statements *statements = new Statements();
- while (token.value != TOKrcurly && token.value != TOKeof)
- {
- statements->push(parseStatement(PSsemi | PScurlyscope));
- }
- endloc = this->loc;
- s = new CompoundStatement(loc, statements);
- if (flags & (PSscope | PScurlyscope))
- s = new ScopeStatement(loc, s);
- nextToken();
- break;
- }
+ case TOKlcurly:
+ {
+ nextToken();
+ Statements *statements = new Statements();
+ while (token.value != TOKrcurly && token.value != TOKeof)
+ {
+ statements->push(parseStatement(PSsemi | PScurlyscope));
+ }
+ endloc = this->loc;
+ s = new CompoundStatement(loc, statements);
+ if (flags & (PSscope | PScurlyscope))
+ s = new ScopeStatement(loc, s);
+ nextToken();
+ break;
+ }
- case TOKwhile:
- { Expression *condition;
- Statement *body;
+ case TOKwhile:
+ { Expression *condition;
+ Statement *body;
- nextToken();
- check(TOKlparen);
- condition = parseExpression();
- check(TOKrparen);
- body = parseStatement(PSscope);
- s = new WhileStatement(loc, condition, body);
- break;
- }
+ nextToken();
+ check(TOKlparen);
+ condition = parseExpression();
+ check(TOKrparen);
+ body = parseStatement(PSscope);
+ s = new WhileStatement(loc, condition, body);
+ break;
+ }
- case TOKsemicolon:
- if (!(flags & PSsemi))
- error("use '{ }' for an empty statement, not a ';'");
- nextToken();
- s = new ExpStatement(loc, NULL);
- break;
+ case TOKsemicolon:
+ if (!(flags & PSsemi))
+ error("use '{ }' for an empty statement, not a ';'");
+ nextToken();
+ s = new ExpStatement(loc, NULL);
+ break;
- case TOKdo:
- { Statement *body;
- Expression *condition;
+ case TOKdo:
+ { Statement *body;
+ Expression *condition;
- nextToken();
- body = parseStatement(PSscope);
- check(TOKwhile);
- check(TOKlparen);
- condition = parseExpression();
- check(TOKrparen);
- s = new DoStatement(loc, body, condition);
- break;
- }
+ nextToken();
+ body = parseStatement(PSscope);
+ check(TOKwhile);
+ check(TOKlparen);
+ condition = parseExpression();
+ check(TOKrparen);
+ s = new DoStatement(loc, body, condition);
+ break;
+ }
- case TOKfor:
- {
- Statement *init;
- Expression *condition;
- Expression *increment;
- Statement *body;
+ case TOKfor:
+ {
+ Statement *init;
+ Expression *condition;
+ Expression *increment;
+ Statement *body;
- nextToken();
- check(TOKlparen);
- if (token.value == TOKsemicolon)
- { init = NULL;
- nextToken();
- }
- else
- { init = parseStatement(0);
- }
- if (token.value == TOKsemicolon)
- {
- condition = NULL;
- nextToken();
- }
- else
- {
- condition = parseExpression();
- check(TOKsemicolon, "for condition");
- }
- if (token.value == TOKrparen)
- { increment = NULL;
- nextToken();
- }
- else
- { increment = parseExpression();
- check(TOKrparen);
- }
- body = parseStatement(PSscope);
- s = new ForStatement(loc, init, condition, increment, body);
- if (init)
- s = new ScopeStatement(loc, s);
- break;
- }
+ nextToken();
+ check(TOKlparen);
+ if (token.value == TOKsemicolon)
+ { init = NULL;
+ nextToken();
+ }
+ else
+ { init = parseStatement(0);
+ }
+ if (token.value == TOKsemicolon)
+ {
+ condition = NULL;
+ nextToken();
+ }
+ else
+ {
+ condition = parseExpression();
+ check(TOKsemicolon, "for condition");
+ }
+ if (token.value == TOKrparen)
+ { increment = NULL;
+ nextToken();
+ }
+ else
+ { increment = parseExpression();
+ check(TOKrparen);
+ }
+ body = parseStatement(PSscope);
+ s = new ForStatement(loc, init, condition, increment, body);
+ if (init)
+ s = new ScopeStatement(loc, s);
+ break;
+ }
- case TOKforeach:
- case TOKforeach_reverse:
- {
- enum TOK op = token.value;
- Parameters *arguments;
+ case TOKforeach:
+ case TOKforeach_reverse:
+ {
+ enum TOK op = token.value;
+ Parameters *arguments;
- Statement *d;
- Statement *body;
- Expression *aggr;
+ Statement *d;
+ Statement *body;
+ Expression *aggr;
- nextToken();
- check(TOKlparen);
+ nextToken();
+ check(TOKlparen);
- arguments = new Parameters();
+ arguments = new Parameters();
- while (1)
- {
- Type *tb;
- Identifier *ai = NULL;
- Type *at;
- unsigned storageClass;
- Parameter *a;
+ while (1)
+ {
+ Type *tb;
+ Identifier *ai = NULL;
+ Type *at;
+ unsigned storageClass;
+ Parameter *a;
- storageClass = STCin;
- if (token.value == TOKinout || token.value == TOKref)
- { storageClass = STCref;
- nextToken();
- }
- if (token.value == TOKidentifier)
- {
- Token *t = peek(&token);
- if (t->value == TOKcomma || t->value == TOKsemicolon)
- { ai = token.ident;
- at = NULL; // infer argument type
- nextToken();
- goto Larg;
- }
- }
- tb = parseBasicType();
- at = parseDeclarator(tb, &ai);
- if (!ai)
- error("no identifier for declarator %s", at->toChars());
- Larg:
- a = new Parameter(storageClass, at, ai, NULL);
- arguments->push(a);
- if (token.value == TOKcomma)
- { nextToken();
- continue;
- }
- break;
- }
- check(TOKsemicolon);
+ storageClass = STCin;
+ if (token.value == TOKinout || token.value == TOKref)
+ { storageClass = STCref;
+ nextToken();
+ }
+ if (token.value == TOKidentifier)
+ {
+ Token *t = peek(&token);
+ if (t->value == TOKcomma || t->value == TOKsemicolon)
+ { ai = token.ident;
+ at = NULL; // infer argument type
+ nextToken();
+ goto Larg;
+ }
+ }
+ tb = parseBasicType();
+ at = parseDeclarator(tb, &ai);
+ if (!ai)
+ error("no identifier for declarator %s", at->toChars());
+ Larg:
+ a = new Parameter(storageClass, at, ai, NULL);
+ arguments->push(a);
+ if (token.value == TOKcomma)
+ { nextToken();
+ continue;
+ }
+ break;
+ }
+ check(TOKsemicolon);
- aggr = parseExpression();
- check(TOKrparen);
- body = parseStatement(0);
- s = new ForeachStatement(loc, op, arguments, aggr, body);
- break;
- }
+ aggr = parseExpression();
+ check(TOKrparen);
+ body = parseStatement(0);
+ s = new ForeachStatement(loc, op, arguments, aggr, body);
+ break;
+ }
- case TOKif:
- { Parameter *arg = NULL;
- Expression *condition;
- Statement *ifbody;
- Statement *elsebody;
+ case TOKif:
+ { Parameter *arg = NULL;
+ Expression *condition;
+ Statement *ifbody;
+ Statement *elsebody;
- nextToken();
- check(TOKlparen);
+ nextToken();
+ check(TOKlparen);
- if (token.value == TOKauto)
- {
- nextToken();
- if (token.value == TOKidentifier)
- {
- Token *t = peek(&token);
- if (t->value == TOKassign)
- {
- arg = new Parameter(STCin, NULL, token.ident, NULL);
- nextToken();
- nextToken();
- }
- else
- { error("= expected following auto identifier");
- goto Lerror;
- }
- }
- else
- { error("identifier expected following auto");
- goto Lerror;
- }
- }
- else if (isDeclaration(&token, 2, TOKassign, NULL))
- {
- Type *tb;
- Type *at;
- Identifier *ai;
+ if (token.value == TOKauto)
+ {
+ nextToken();
+ if (token.value == TOKidentifier)
+ {
+ Token *t = peek(&token);
+ if (t->value == TOKassign)
+ {
+ arg = new Parameter(STCin, NULL, token.ident, NULL);
+ nextToken();
+ nextToken();
+ }
+ else
+ { error("= expected following auto identifier");
+ goto Lerror;
+ }
+ }
+ else
+ { error("identifier expected following auto");
+ goto Lerror;
+ }
+ }
+ else if (isDeclaration(&token, 2, TOKassign, NULL))
+ {
+ Type *tb;
+ Type *at;
+ Identifier *ai;
- tb = parseBasicType();
- at = parseDeclarator(tb, &ai);
- check(TOKassign);
- arg = new Parameter(STCin, at, ai, NULL);
- }
+ tb = parseBasicType();
+ at = parseDeclarator(tb, &ai);
+ check(TOKassign);
+ arg = new Parameter(STCin, at, ai, NULL);
+ }
- // Check for " ident;"
- else if (token.value == TOKidentifier)
- {
- Token *t = peek(&token);
- if (t->value == TOKcomma || t->value == TOKsemicolon)
- {
- arg = new Parameter(STCin, NULL, token.ident, NULL);
- nextToken();
- nextToken();
- if (1 || !global.params.useDeprecated)
- error("if (v; e) is deprecated, use if (auto v = e)");
- }
- }
+ // Check for " ident;"
+ else if (token.value == TOKidentifier)
+ {
+ Token *t = peek(&token);
+ if (t->value == TOKcomma || t->value == TOKsemicolon)
+ {
+ arg = new Parameter(STCin, NULL, token.ident, NULL);
+ nextToken();
+ nextToken();
+ if (1 || !global.params.useDeprecated)
+ error("if (v; e) is deprecated, use if (auto v = e)");
+ }
+ }
- condition = parseExpression();
- check(TOKrparen);
- ifbody = parseStatement(PSscope);
- if (token.value == TOKelse)
- {
- nextToken();
- elsebody = parseStatement(PSscope);
- }
- else
- elsebody = NULL;
- s = new IfStatement(loc, arg, condition, ifbody, elsebody);
- break;
- }
+ condition = parseExpression();
+ check(TOKrparen);
+ ifbody = parseStatement(PSscope);
+ if (token.value == TOKelse)
+ {
+ nextToken();
+ elsebody = parseStatement(PSscope);
+ }
+ else
+ elsebody = NULL;
+ s = new IfStatement(loc, arg, condition, ifbody, elsebody);
+ break;
+ }
- case TOKscope:
- if (peek(&token)->value != TOKlparen)
- goto Ldeclaration; // scope used as storage class
- nextToken();
- check(TOKlparen);
- if (token.value != TOKidentifier)
- { error("scope identifier expected");
- goto Lerror;
- }
- else
- { TOK t = TOKon_scope_exit;
- Identifier *id = token.ident;
+ case TOKscope:
+ if (peek(&token)->value != TOKlparen)
+ goto Ldeclaration; // scope used as storage class
+ nextToken();
+ check(TOKlparen);
+ if (token.value != TOKidentifier)
+ { error("scope identifier expected");
+ goto Lerror;
+ }
+ else
+ { TOK t = TOKon_scope_exit;
+ Identifier *id = token.ident;
- if (id == Id::exit)
- t = TOKon_scope_exit;
- else if (id == Id::failure)
- t = TOKon_scope_failure;
- else if (id == Id::success)
- t = TOKon_scope_success;
- else
- error("valid scope identifiers are exit, failure, or success, not %s", id->toChars());
- nextToken();
- check(TOKrparen);
- Statement *st = parseStatement(PScurlyscope);
- s = new OnScopeStatement(loc, t, st);
- break;
- }
+ if (id == Id::exit)
+ t = TOKon_scope_exit;
+ else if (id == Id::failure)
+ t = TOKon_scope_failure;
+ else if (id == Id::success)
+ t = TOKon_scope_success;
+ else
+ error("valid scope identifiers are exit, failure, or success, not %s", id->toChars());
+ nextToken();
+ check(TOKrparen);
+ Statement *st = parseStatement(PScurlyscope);
+ s = new OnScopeStatement(loc, t, st);
+ break;
+ }
- case TOKdebug:
- nextToken();
- condition = parseDebugCondition();
- goto Lcondition;
+ case TOKdebug:
+ nextToken();
+ condition = parseDebugCondition();
+ goto Lcondition;
- case TOKversion:
- nextToken();
- condition = parseVersionCondition();
- goto Lcondition;
+ case TOKversion:
+ nextToken();
+ condition = parseVersionCondition();
+ goto Lcondition;
- Lcondition:
- ifbody = parseStatement(0 /*PSsemi*/);
- elsebody = NULL;
- if (token.value == TOKelse)
- {
- nextToken();
- elsebody = parseStatement(0 /*PSsemi*/);
- }
- s = new ConditionalStatement(loc, condition, ifbody, elsebody);
- break;
+ Lcondition:
+ ifbody = parseStatement(0 /*PSsemi*/);
+ elsebody = NULL;
+ if (token.value == TOKelse)
+ {
+ nextToken();
+ elsebody = parseStatement(0 /*PSsemi*/);
+ }
+ s = new ConditionalStatement(loc, condition, ifbody, elsebody);
+ break;
- case TOKpragma:
- { Identifier *ident;
- Expressions *args = NULL;
- Statement *body;
+ case TOKpragma:
+ { Identifier *ident;
+ Expressions *args = NULL;
+ Statement *body;
- nextToken();
- check(TOKlparen);
- if (token.value != TOKidentifier)
- { error("pragma(identifier expected");
- goto Lerror;
- }
- ident = token.ident;
- nextToken();
- if (token.value == TOKcomma && peekNext() != TOKrparen)
- args = parseArguments(); // pragma(identifier, args...);
- else
- check(TOKrparen); // pragma(identifier);
- if (token.value == TOKsemicolon)
- { nextToken();
- body = NULL;
- }
- else
- body = parseStatement(PSsemi);
- s = new PragmaStatement(loc, ident, args, body);
- break;
- }
+ nextToken();
+ check(TOKlparen);
+ if (token.value != TOKidentifier)
+ { error("pragma(identifier expected");
+ goto Lerror;
+ }
+ ident = token.ident;
+ nextToken();
+ if (token.value == TOKcomma && peekNext() != TOKrparen)
+ args = parseArguments(); // pragma(identifier, args...);
+ else
+ check(TOKrparen); // pragma(identifier);
+ if (token.value == TOKsemicolon)
+ { nextToken();
+ body = NULL;
+ }
+ else
+ body = parseStatement(PSsemi);
+ s = new PragmaStatement(loc, ident, args, body);
+ break;
+ }
- case TOKswitch:
- { Expression *condition;
- Statement *body;
+ case TOKswitch:
+ { Expression *condition;
+ Statement *body;
- nextToken();
- check(TOKlparen);
- condition = parseExpression();
- check(TOKrparen);
- body = parseStatement(PSscope);
- s = new SwitchStatement(loc, condition, body);
- break;
- }
+ nextToken();
+ check(TOKlparen);
+ condition = parseExpression();
+ check(TOKrparen);
+ body = parseStatement(PSscope);
+ s = new SwitchStatement(loc, condition, body);
+ break;
+ }
- case TOKcase:
- { Expression *exp;
- Statements *statements;
- Array cases; // array of Expression's
+ case TOKcase:
+ { Expression *exp;
+ Statements *statements;
+ Array cases; // array of Expression's
- while (1)
- {
- nextToken();
- exp = parseAssignExp();
- cases.push(exp);
- if (token.value != TOKcomma)
- break;
- }
- check(TOKcolon);
+ while (1)
+ {
+ nextToken();
+ exp = parseAssignExp();
+ cases.push(exp);
+ if (token.value != TOKcomma)
+ break;
+ }
+ check(TOKcolon);
- statements = new Statements();
- while (token.value != TOKcase &&
- token.value != TOKdefault &&
- token.value != TOKeof &&
- token.value != TOKrcurly)
- {
- statements->push(parseStatement(PSsemi | PScurlyscope));
- }
- s = new CompoundStatement(loc, statements);
- s = new ScopeStatement(loc, s);
+ statements = new Statements();
+ while (token.value != TOKcase &&
+ token.value != TOKdefault &&
+ token.value != TOKeof &&
+ token.value != TOKrcurly)
+ {
+ statements->push(parseStatement(PSsemi | PScurlyscope));
+ }
+ s = new CompoundStatement(loc, statements);
+ s = new ScopeStatement(loc, s);
- // Keep cases in order by building the case statements backwards
- for (int i = cases.dim; i; i--)
- {
- exp = (Expression *)cases.data[i - 1];
- s = new CaseStatement(loc, exp, s);
- }
- break;
- }
+ // Keep cases in order by building the case statements backwards
+ for (int i = cases.dim; i; i--)
+ {
+ exp = (Expression *)cases.data[i - 1];
+ s = new CaseStatement(loc, exp, s);
+ }
+ break;
+ }
- case TOKdefault:
- {
- Statements *statements;
+ case TOKdefault:
+ {
+ Statements *statements;
- nextToken();
- check(TOKcolon);
+ nextToken();
+ check(TOKcolon);
- statements = new Statements();
- while (token.value != TOKcase &&
- token.value != TOKdefault &&
- token.value != TOKeof &&
- token.value != TOKrcurly)
- {
- statements->push(parseStatement(PSsemi | PScurlyscope));
- }
- s = new CompoundStatement(loc, statements);
- s = new ScopeStatement(loc, s);
- s = new DefaultStatement(loc, s);
- break;
- }
+ statements = new Statements();
+ while (token.value != TOKcase &&
+ token.value != TOKdefault &&
+ token.value != TOKeof &&
+ token.value != TOKrcurly)
+ {
+ statements->push(parseStatement(PSsemi | PScurlyscope));
+ }
+ s = new CompoundStatement(loc, statements);
+ s = new ScopeStatement(loc, s);
+ s = new DefaultStatement(loc, s);
+ break;
+ }
- case TOKreturn:
- { Expression *exp;
+ case TOKreturn:
+ { Expression *exp;
- nextToken();
- if (token.value == TOKsemicolon)
- exp = NULL;
- else
- exp = parseExpression();
- check(TOKsemicolon, "return statement");
- s = new ReturnStatement(loc, exp);
- break;
- }
+ nextToken();
+ if (token.value == TOKsemicolon)
+ exp = NULL;
+ else
+ exp = parseExpression();
+ check(TOKsemicolon, "return statement");
+ s = new ReturnStatement(loc, exp);
+ break;
+ }
- case TOKbreak:
- { Identifier *ident;
+ case TOKbreak:
+ { Identifier *ident;
- nextToken();
- if (token.value == TOKidentifier)
- { ident = token.ident;
- nextToken();
- }
- else
- ident = NULL;
- check(TOKsemicolon, "break statement");
- s = new BreakStatement(loc, ident);
- break;
- }
+ nextToken();
+ if (token.value == TOKidentifier)
+ { ident = token.ident;
+ nextToken();
+ }
+ else
+ ident = NULL;
+ check(TOKsemicolon, "break statement");
+ s = new BreakStatement(loc, ident);
+ break;
+ }
- case TOKcontinue:
- { Identifier *ident;
+ case TOKcontinue:
+ { Identifier *ident;
- nextToken();
- if (token.value == TOKidentifier)
- { ident = token.ident;
- nextToken();
- }
- else
- ident = NULL;
- check(TOKsemicolon, "continue statement");
- s = new ContinueStatement(loc, ident);
- break;
- }
+ nextToken();
+ if (token.value == TOKidentifier)
+ { ident = token.ident;
+ nextToken();
+ }
+ else
+ ident = NULL;
+ check(TOKsemicolon, "continue statement");
+ s = new ContinueStatement(loc, ident);
+ break;
+ }
- case TOKgoto:
- { Identifier *ident;
+ case TOKgoto:
+ { Identifier *ident;
- nextToken();
- if (token.value == TOKdefault)
- {
- nextToken();
- s = new GotoDefaultStatement(loc);
- }
- else if (token.value == TOKcase)
- {
- Expression *exp = NULL;
+ nextToken();
+ if (token.value == TOKdefault)
+ {
+ nextToken();
+ s = new GotoDefaultStatement(loc);
+ }
+ else if (token.value == TOKcase)
+ {
+ Expression *exp = NULL;
- nextToken();
- if (token.value != TOKsemicolon)
- exp = parseExpression();
- s = new GotoCaseStatement(loc, exp);
- }
- else
- {
- if (token.value != TOKidentifier)
- { error("Identifier expected following goto");
- ident = NULL;
- }
- else
- { ident = token.ident;
- nextToken();
- }
- s = new GotoStatement(loc, ident);
- }
- check(TOKsemicolon, "goto statement");
- break;
- }
+ nextToken();
+ if (token.value != TOKsemicolon)
+ exp = parseExpression();
+ s = new GotoCaseStatement(loc, exp);
+ }
+ else
+ {
+ if (token.value != TOKidentifier)
+ { error("Identifier expected following goto");
+ ident = NULL;
+ }
+ else
+ { ident = token.ident;
+ nextToken();
+ }
+ s = new GotoStatement(loc, ident);
+ }
+ check(TOKsemicolon, "goto statement");
+ break;
+ }
- case TOKsynchronized:
- { Expression *exp;
- Statement *body;
+ case TOKsynchronized:
+ { Expression *exp;
+ Statement *body;
- nextToken();
- if (token.value == TOKlparen)
- {
- nextToken();
- exp = parseExpression();
- check(TOKrparen);
- }
- else
- exp = NULL;
- body = parseStatement(PSscope);
- s = new SynchronizedStatement(loc, exp, body);
- break;
- }
+ nextToken();
+ if (token.value == TOKlparen)
+ {
+ nextToken();
+ exp = parseExpression();
+ check(TOKrparen);
+ }
+ else
+ exp = NULL;
+ body = parseStatement(PSscope);
+ s = new SynchronizedStatement(loc, exp, body);
+ break;
+ }
- case TOKwith:
- { Expression *exp;
- Statement *body;
+ case TOKwith:
+ { Expression *exp;
+ Statement *body;
- nextToken();
- check(TOKlparen);
- exp = parseExpression();
- check(TOKrparen);
- body = parseStatement(PSscope);
- s = new WithStatement(loc, exp, body);
- break;
- }
+ nextToken();
+ check(TOKlparen);
+ exp = parseExpression();
+ check(TOKrparen);
+ body = parseStatement(PSscope);
+ s = new WithStatement(loc, exp, body);
+ break;
+ }
- case TOKtry:
- { Statement *body;
- Array *catches = NULL;
- Statement *finalbody = NULL;
+ case TOKtry:
+ { Statement *body;
+ Array *catches = NULL;
+ Statement *finalbody = NULL;
- nextToken();
- body = parseStatement(PSscope);
- while (token.value == TOKcatch)
- {
- Statement *handler;
- Catch *c;
- Type *t;
- Identifier *id;
- Loc loc = this->loc;
+ nextToken();
+ body = parseStatement(PSscope);
+ while (token.value == TOKcatch)
+ {
+ Statement *handler;
+ Catch *c;
+ Type *t;
+ Identifier *id;
+ Loc loc = this->loc;
- nextToken();
- if (token.value == TOKlcurly)
- {
- t = NULL;
- id = NULL;
- }
- else
- {
- check(TOKlparen);
- t = parseBasicType();
- id = NULL;
- t = parseDeclarator(t, &id);
- check(TOKrparen);
- }
- handler = parseStatement(0);
- c = new Catch(loc, t, id, handler);
- if (!catches)
- catches = new Array();
- catches->push(c);
- }
+ nextToken();
+ if (token.value == TOKlcurly)
+ {
+ t = NULL;
+ id = NULL;
+ }
+ else
+ {
+ check(TOKlparen);
+ t = parseBasicType();
+ id = NULL;
+ t = parseDeclarator(t, &id);
+ check(TOKrparen);
+ }
+ handler = parseStatement(0);
+ c = new Catch(loc, t, id, handler);
+ if (!catches)
+ catches = new Array();
+ catches->push(c);
+ }
- if (token.value == TOKfinally)
- { nextToken();
- finalbody = parseStatement(0);
- }
+ if (token.value == TOKfinally)
+ { nextToken();
+ finalbody = parseStatement(0);
+ }
- s = body;
- if (!catches && !finalbody)
- error("catch or finally expected following try");
- else
- { if (catches)
- s = new TryCatchStatement(loc, body, catches);
- if (finalbody)
- s = new TryFinallyStatement(loc, s, finalbody);
- }
- break;
- }
+ s = body;
+ if (!catches && !finalbody)
+ error("catch or finally expected following try");
+ else
+ { if (catches)
+ s = new TryCatchStatement(loc, body, catches);
+ if (finalbody)
+ s = new TryFinallyStatement(loc, s, finalbody);
+ }
+ break;
+ }
- case TOKthrow:
- { Expression *exp;
+ case TOKthrow:
+ { Expression *exp;
- nextToken();
- exp = parseExpression();
- check(TOKsemicolon, "throw statement");
- s = new ThrowStatement(loc, exp);
- break;
- }
+ nextToken();
+ exp = parseExpression();
+ check(TOKsemicolon, "throw statement");
+ s = new ThrowStatement(loc, exp);
+ break;
+ }
- case TOKvolatile:
- nextToken();
- s = parseStatement(PSsemi | PScurlyscope);
+ case TOKvolatile:
+ nextToken();
+ s = parseStatement(PSsemi | PScurlyscope);
#if DMDV2
- if (!global.params.useDeprecated)
- error("volatile statements deprecated; used synchronized statements instead");
+ if (!global.params.useDeprecated)
+ error("volatile statements deprecated; used synchronized statements instead");
#endif
- s = new VolatileStatement(loc, s);
- break;
+ s = new VolatileStatement(loc, s);
+ break;
- case TOKasm:
- { Statements *statements;
- Identifier *label;
- Loc labelloc;
- Token *toklist;
- Token **ptoklist;
+ case TOKasm:
+ { Statements *statements;
+ Identifier *label;
+ Loc labelloc;
+ Token *toklist;
+ Token **ptoklist;
- // Parse the asm block into a sequence of AsmStatements,
- // each AsmStatement is one instruction.
- // Separate out labels.
- // Defer parsing of AsmStatements until semantic processing.
+ // Parse the asm block into a sequence of AsmStatements,
+ // each AsmStatement is one instruction.
+ // Separate out labels.
+ // Defer parsing of AsmStatements until semantic processing.
- nextToken();
- check(TOKlcurly);
- toklist = NULL;
- ptoklist = &toklist;
- label = NULL;
- statements = new Statements();
- while (1)
- {
- switch (token.value)
- {
- case TOKidentifier:
- if (!toklist)
- {
- // Look ahead to see if it is a label
- t = peek(&token);
- if (t->value == TOKcolon)
- { // It's a label
- label = token.ident;
- labelloc = this->loc;
- nextToken();
- nextToken();
- continue;
- }
- }
- goto Ldefault;
+ nextToken();
+ check(TOKlcurly);
+ toklist = NULL;
+ ptoklist = &toklist;
+ label = NULL;
+ statements = new Statements();
+ while (1)
+ {
+ switch (token.value)
+ {
+ case TOKidentifier:
+ if (!toklist)
+ {
+ // Look ahead to see if it is a label
+ t = peek(&token);
+ if (t->value == TOKcolon)
+ { // It's a label
+ label = token.ident;
+ labelloc = this->loc;
+ nextToken();
+ nextToken();
+ continue;
+ }
+ }
+ goto Ldefault;
- case TOKrcurly:
- if (toklist || label)
- {
- error("asm statements must end in ';'");
- }
- break;
+ case TOKrcurly:
+ if (toklist || label)
+ {
+ error("asm statements must end in ';'");
+ }
+ break;
- case TOKsemicolon:
- s = NULL;
- if (toklist || label)
- { // Create AsmStatement from list of tokens we've saved
- s = new AsmStatement(this->loc, toklist);
- toklist = NULL;
- ptoklist = &toklist;
- if (label)
- { s = new LabelStatement(labelloc, label, s);
- label = NULL;
- }
- statements->push(s);
- }
- nextToken();
- continue;
+ case TOKsemicolon:
+ s = NULL;
+ if (toklist || label)
+ { // Create AsmStatement from list of tokens we've saved
+ s = new AsmStatement(this->loc, toklist);
+ toklist = NULL;
+ ptoklist = &toklist;
+ if (label)
+ { s = new LabelStatement(labelloc, label, s);
+ label = NULL;
+ }
+ statements->push(s);
+ }
+ nextToken();
+ continue;
- case TOKeof:
- /* { */
- error("matching '}' expected, not end of file");
- break;
+ case TOKeof:
+ /* { */
+ error("matching '}' expected, not end of file");
+ break;
- default:
- Ldefault:
- *ptoklist = new Token();
- memcpy(*ptoklist, &token, sizeof(Token));
- ptoklist = &(*ptoklist)->next;
- *ptoklist = NULL;
+ default:
+ Ldefault:
+ *ptoklist = new Token();
+ memcpy(*ptoklist, &token, sizeof(Token));
+ ptoklist = &(*ptoklist)->next;
+ *ptoklist = NULL;
- nextToken();
- continue;
- }
- break;
- }
+ nextToken();
+ continue;
+ }
+ break;
+ }
s = new AsmBlockStatement(loc, statements);
- nextToken();
- break;
- }
+ nextToken();
+ break;
+ }
- default:
- error("found '%s' instead of statement", token.toChars());
- goto Lerror;
+ default:
+ error("found '%s' instead of statement", token.toChars());
+ goto Lerror;
- Lerror:
- while (token.value != TOKrcurly &&
- token.value != TOKsemicolon &&
- token.value != TOKeof)
- nextToken();
- if (token.value == TOKsemicolon)
- nextToken();
- s = NULL;
- break;
+ Lerror:
+ while (token.value != TOKrcurly &&
+ token.value != TOKsemicolon &&
+ token.value != TOKeof)
+ nextToken();
+ if (token.value == TOKsemicolon)
+ nextToken();
+ s = NULL;
+ break;
}
return s;
@@ -3571,24 +3571,24 @@ void Parser::check(enum TOK value)
void Parser::check(Loc loc, enum TOK value)
{
if (token.value != value)
- error(loc, "found '%s' when expecting '%s'", token.toChars(), Token::toChars(value));
+ error(loc, "found '%s' when expecting '%s'", token.toChars(), Token::toChars(value));
nextToken();
}
void Parser::check(enum TOK value, const char *string)
{
if (token.value != value)
- error("found '%s' when expecting '%s' following '%s'",
- token.toChars(), Token::toChars(value), string);
+ error("found '%s' when expecting '%s' following '%s'",
+ token.toChars(), Token::toChars(value), string);
nextToken();
}
/************************************
* Determine if the scanner is sitting on the start of a declaration.
* Input:
- * needId 0 no identifier
- * 1 identifier optional
- * 2 must have identifier
+ * needId 0 no identifier
+ * 1 identifier optional
+ * 2 must have identifier
*/
int Parser::isDeclaration(Token *t, int needId, enum TOK endtok, Token **pt)
@@ -3598,27 +3598,27 @@ int Parser::isDeclaration(Token *t, int needId, enum TOK endtok, Token **pt)
#if DMDV2
if ((t->value == TOKconst || t->value == TOKinvariant) &&
- peek(t)->value != TOKlparen)
- { /* const type
- * invariant type
- */
- t = peek(t);
+ peek(t)->value != TOKlparen)
+ { /* const type
+ * invariant type
+ */
+ t = peek(t);
}
#endif
if (!isBasicType(&t))
- return FALSE;
+ return FALSE;
if (!isDeclarator(&t, &haveId, endtok))
- return FALSE;
+ return FALSE;
if ( needId == 1 ||
- (needId == 0 && !haveId) ||
- (needId == 2 && haveId))
- { if (pt)
- *pt = t;
- return TRUE;
+ (needId == 0 && !haveId) ||
+ (needId == 2 && haveId))
+ { if (pt)
+ *pt = t;
+ return TRUE;
}
else
- return FALSE;
+ return FALSE;
}
int Parser::isBasicType(Token **pt)
@@ -3630,58 +3630,58 @@ int Parser::isBasicType(Token **pt)
switch (t->value)
{
- case BASIC_TYPES:
- t = peek(t);
- break;
+ case BASIC_TYPES:
+ t = peek(t);
+ break;
- case TOKidentifier:
- t = peek(t);
- if (t->value == TOKnot)
- {
- goto L4;
- }
- goto L3;
- while (1)
- {
- L2:
- t = peek(t);
- L3:
- if (t->value == TOKdot)
- {
- Ldot:
- t = peek(t);
- if (t->value != TOKidentifier)
- goto Lfalse;
- t = peek(t);
- if (t->value != TOKnot)
- goto L3;
- L4:
- t = peek(t);
- if (t->value != TOKlparen)
- goto Lfalse;
- if (!skipParens(t, &t))
- goto Lfalse;
- }
- else
- break;
- }
- break;
+ case TOKidentifier:
+ t = peek(t);
+ if (t->value == TOKnot)
+ {
+ goto L4;
+ }
+ goto L3;
+ while (1)
+ {
+ L2:
+ t = peek(t);
+ L3:
+ if (t->value == TOKdot)
+ {
+ Ldot:
+ t = peek(t);
+ if (t->value != TOKidentifier)
+ goto Lfalse;
+ t = peek(t);
+ if (t->value != TOKnot)
+ goto L3;
+ L4:
+ t = peek(t);
+ if (t->value != TOKlparen)
+ goto Lfalse;
+ if (!skipParens(t, &t))
+ goto Lfalse;
+ }
+ else
+ break;
+ }
+ break;
- case TOKdot:
- goto Ldot;
+ case TOKdot:
+ goto Ldot;
- case TOKtypeof:
- /* typeof(exp).identifier...
- */
- t = peek(t);
- if (t->value != TOKlparen)
- goto Lfalse;
- if (!skipParens(t, &t))
- goto Lfalse;
- goto L2;
+ case TOKtypeof:
+ /* typeof(exp).identifier...
+ */
+ t = peek(t);
+ if (t->value != TOKlparen)
+ goto Lfalse;
+ if (!skipParens(t, &t))
+ goto Lfalse;
+ goto L2;
- default:
- goto Lfalse;
+ default:
+ goto Lfalse;
}
*pt = t;
//printf("is\n");
@@ -3700,158 +3700,158 @@ int Parser::isDeclarator(Token **pt, int *haveId, enum TOK endtok)
//printf("Parser::isDeclarator()\n");
//t->print();
if (t->value == TOKassign)
- return FALSE;
+ return FALSE;
while (1)
{
- parens = FALSE;
- switch (t->value)
- {
- case TOKmul:
- //case TOKand:
- t = peek(t);
- continue;
+ parens = FALSE;
+ switch (t->value)
+ {
+ case TOKmul:
+ //case TOKand:
+ t = peek(t);
+ continue;
- case TOKlbracket:
- t = peek(t);
- if (t->value == TOKrbracket)
- {
- t = peek(t);
- }
- else if (isDeclaration(t, 0, TOKrbracket, &t))
- { // It's an associative array declaration
- t = peek(t);
- }
- else
- {
- // [ expression ]
- // [ expression .. expression ]
- if (!isExpression(&t))
- return FALSE;
- if (t->value == TOKslice)
- { t = peek(t);
- if (!isExpression(&t))
- return FALSE;
- }
- if (t->value != TOKrbracket)
- return FALSE;
- t = peek(t);
- }
- continue;
+ case TOKlbracket:
+ t = peek(t);
+ if (t->value == TOKrbracket)
+ {
+ t = peek(t);
+ }
+ else if (isDeclaration(t, 0, TOKrbracket, &t))
+ { // It's an associative array declaration
+ t = peek(t);
+ }
+ else
+ {
+ // [ expression ]
+ // [ expression .. expression ]
+ if (!isExpression(&t))
+ return FALSE;
+ if (t->value == TOKslice)
+ { t = peek(t);
+ if (!isExpression(&t))
+ return FALSE;
+ }
+ if (t->value != TOKrbracket)
+ return FALSE;
+ t = peek(t);
+ }
+ continue;
- case TOKidentifier:
- if (*haveId)
- return FALSE;
- *haveId = TRUE;
- t = peek(t);
- break;
+ case TOKidentifier:
+ if (*haveId)
+ return FALSE;
+ *haveId = TRUE;
+ t = peek(t);
+ break;
- case TOKlparen:
- t = peek(t);
+ case TOKlparen:
+ t = peek(t);
- if (t->value == TOKrparen)
- return FALSE; // () is not a declarator
+ if (t->value == TOKrparen)
+ return FALSE; // () is not a declarator
- /* Regard ( identifier ) as not a declarator
- * BUG: what about ( *identifier ) in
- * f(*p)(x);
- * where f is a class instance with overloaded () ?
- * Should we just disallow C-style function pointer declarations?
- */
- if (t->value == TOKidentifier)
- { Token *t2 = peek(t);
- if (t2->value == TOKrparen)
- return FALSE;
- }
+ /* Regard ( identifier ) as not a declarator
+ * BUG: what about ( *identifier ) in
+ * f(*p)(x);
+ * where f is a class instance with overloaded () ?
+ * Should we just disallow C-style function pointer declarations?
+ */
+ if (t->value == TOKidentifier)
+ { Token *t2 = peek(t);
+ if (t2->value == TOKrparen)
+ return FALSE;
+ }
- if (!isDeclarator(&t, haveId, TOKrparen))
- return FALSE;
- t = peek(t);
- parens = TRUE;
- break;
+ if (!isDeclarator(&t, haveId, TOKrparen))
+ return FALSE;
+ t = peek(t);
+ parens = TRUE;
+ break;
- case TOKdelegate:
- case TOKfunction:
- t = peek(t);
- if (!isParameters(&t))
- return FALSE;
- continue;
- }
- break;
+ case TOKdelegate:
+ case TOKfunction:
+ t = peek(t);
+ if (!isParameters(&t))
+ return FALSE;
+ continue;
+ }
+ break;
}
while (1)
{
- switch (t->value)
- {
+ switch (t->value)
+ {
#if CARRAYDECL
- case TOKlbracket:
- parens = FALSE;
- t = peek(t);
- if (t->value == TOKrbracket)
- {
- t = peek(t);
- }
- else if (isDeclaration(t, 0, TOKrbracket, &t))
- { // It's an associative array declaration
- t = peek(t);
- }
- else
- {
- // [ expression ]
- if (!isExpression(&t))
- return FALSE;
- if (t->value != TOKrbracket)
- return FALSE;
- t = peek(t);
- }
- continue;
+ case TOKlbracket:
+ parens = FALSE;
+ t = peek(t);
+ if (t->value == TOKrbracket)
+ {
+ t = peek(t);
+ }
+ else if (isDeclaration(t, 0, TOKrbracket, &t))
+ { // It's an associative array declaration
+ t = peek(t);
+ }
+ else
+ {
+ // [ expression ]
+ if (!isExpression(&t))
+ return FALSE;
+ if (t->value != TOKrbracket)
+ return FALSE;
+ t = peek(t);
+ }
+ continue;
#endif
- case TOKlparen:
- parens = FALSE;
- if (!isParameters(&t))
- return FALSE;
+ case TOKlparen:
+ parens = FALSE;
+ if (!isParameters(&t))
+ return FALSE;
#if DMDV2
- while (1)
- {
- switch (t->value)
- {
- case TOKconst:
- case TOKinvariant:
- case TOKimmutable:
- case TOKshared:
- case TOKpure:
- case TOKnothrow:
- t = peek(t);
- continue;
- default:
- break;
- }
- break;
- }
+ while (1)
+ {
+ switch (t->value)
+ {
+ case TOKconst:
+ case TOKinvariant:
+ case TOKimmutable:
+ case TOKshared:
+ case TOKpure:
+ case TOKnothrow:
+ t = peek(t);
+ continue;
+ default:
+ break;
+ }
+ break;
+ }
#endif
- continue;
+ continue;
- // Valid tokens that follow a declaration
- case TOKrparen:
- case TOKrbracket:
- case TOKassign:
- case TOKcomma:
- case TOKsemicolon:
- case TOKlcurly:
- case TOKin:
- // The !parens is to disallow unnecessary parentheses
- if (!parens && (endtok == TOKreserved || endtok == t->value))
- { *pt = t;
- return TRUE;
- }
- return FALSE;
+ // Valid tokens that follow a declaration
+ case TOKrparen:
+ case TOKrbracket:
+ case TOKassign:
+ case TOKcomma:
+ case TOKsemicolon:
+ case TOKlcurly:
+ case TOKin:
+ // The !parens is to disallow unnecessary parentheses
+ if (!parens && (endtok == TOKreserved || endtok == t->value))
+ { *pt = t;
+ return TRUE;
+ }
+ return FALSE;
- default:
- return FALSE;
- }
+ default:
+ return FALSE;
+ }
}
}
@@ -3863,53 +3863,53 @@ int Parser::isParameters(Token **pt)
//printf("isParameters()\n");
if (t->value != TOKlparen)
- return FALSE;
+ return FALSE;
t = peek(t);
while (1)
{
- switch (t->value)
- {
- case TOKrparen:
- break;
+ switch (t->value)
+ {
+ case TOKrparen:
+ break;
- case TOKdotdotdot:
- t = peek(t);
- break;
+ case TOKdotdotdot:
+ t = peek(t);
+ break;
- case TOKin:
- case TOKout:
- case TOKinout:
- case TOKref:
- case TOKlazy:
- t = peek(t);
- default:
- if (!isBasicType(&t))
- return FALSE;
- tmp = FALSE;
- if (t->value != TOKdotdotdot &&
- !isDeclarator(&t, &tmp, TOKreserved))
- return FALSE;
- if (t->value == TOKassign)
- { t = peek(t);
- if (!isExpression(&t))
- return FALSE;
- }
- if (t->value == TOKdotdotdot)
- {
- t = peek(t);
- break;
- }
- if (t->value == TOKcomma)
- { t = peek(t);
- continue;
- }
- break;
- }
- break;
+ case TOKin:
+ case TOKout:
+ case TOKinout:
+ case TOKref:
+ case TOKlazy:
+ t = peek(t);
+ default:
+ if (!isBasicType(&t))
+ return FALSE;
+ tmp = FALSE;
+ if (t->value != TOKdotdotdot &&
+ !isDeclarator(&t, &tmp, TOKreserved))
+ return FALSE;
+ if (t->value == TOKassign)
+ { t = peek(t);
+ if (!isExpression(&t))
+ return FALSE;
+ }
+ if (t->value == TOKdotdotdot)
+ {
+ t = peek(t);
+ break;
+ }
+ if (t->value == TOKcomma)
+ { t = peek(t);
+ continue;
+ }
+ break;
+ }
+ break;
}
if (t->value != TOKrparen)
- return FALSE;
+ return FALSE;
t = peek(t);
*pt = t;
return TRUE;
@@ -3927,43 +3927,43 @@ int Parser::isExpression(Token **pt)
for (;; t = peek(t))
{
- switch (t->value)
- {
- case TOKlbracket:
- brnest++;
- continue;
+ switch (t->value)
+ {
+ case TOKlbracket:
+ brnest++;
+ continue;
- case TOKrbracket:
- if (--brnest >= 0)
- continue;
- break;
+ case TOKrbracket:
+ if (--brnest >= 0)
+ continue;
+ break;
- case TOKlparen:
- panest++;
- continue;
+ case TOKlparen:
+ panest++;
+ continue;
- case TOKcomma:
- if (brnest || panest)
- continue;
- break;
+ case TOKcomma:
+ if (brnest || panest)
+ continue;
+ break;
- case TOKrparen:
- if (--panest >= 0)
- continue;
- break;
+ case TOKrparen:
+ if (--panest >= 0)
+ continue;
+ break;
- case TOKslice:
- if (brnest)
- continue;
- break;
+ case TOKslice:
+ if (brnest)
+ continue;
+ break;
- case TOKeof:
- return FALSE;
+ case TOKeof:
+ return FALSE;
- default:
- continue;
- }
- break;
+ default:
+ continue;
+ }
+ break;
}
*pt = t;
@@ -3972,12 +3972,12 @@ int Parser::isExpression(Token **pt)
/**********************************************
* Skip over
- * instance foo.bar(parameters...)
+ * instance foo.bar(parameters...)
* Output:
- * if (pt), *pt is set to the token following the closing )
+ * if (pt), *pt is set to the token following the closing )
* Returns:
- * 1 it's valid instance syntax
- * 0 invalid instance syntax
+ * 1 it's valid instance syntax
+ * 0 invalid instance syntax
*/
int Parser::isTemplateInstance(Token *t, Token **pt)
@@ -3985,53 +3985,53 @@ int Parser::isTemplateInstance(Token *t, Token **pt)
t = peek(t);
if (t->value != TOKdot)
{
- if (t->value != TOKidentifier)
- goto Lfalse;
- t = peek(t);
+ if (t->value != TOKidentifier)
+ goto Lfalse;
+ t = peek(t);
}
while (t->value == TOKdot)
{
- t = peek(t);
- if (t->value != TOKidentifier)
- goto Lfalse;
- t = peek(t);
+ t = peek(t);
+ if (t->value != TOKidentifier)
+ goto Lfalse;
+ t = peek(t);
}
if (t->value != TOKlparen)
- goto Lfalse;
+ goto Lfalse;
// Skip over the template arguments
while (1)
{
- while (1)
- {
- t = peek(t);
- switch (t->value)
- {
- case TOKlparen:
- if (!skipParens(t, &t))
- goto Lfalse;
- continue;
- case TOKrparen:
- break;
- case TOKcomma:
- break;
- case TOKeof:
- case TOKsemicolon:
- goto Lfalse;
- default:
- continue;
- }
- break;
- }
+ while (1)
+ {
+ t = peek(t);
+ switch (t->value)
+ {
+ case TOKlparen:
+ if (!skipParens(t, &t))
+ goto Lfalse;
+ continue;
+ case TOKrparen:
+ break;
+ case TOKcomma:
+ break;
+ case TOKeof:
+ case TOKsemicolon:
+ goto Lfalse;
+ default:
+ continue;
+ }
+ break;
+ }
- if (t->value != TOKcomma)
- break;
+ if (t->value != TOKcomma)
+ break;
}
if (t->value != TOKrparen)
- goto Lfalse;
+ goto Lfalse;
t = peek(t);
if (pt)
- *pt = t;
+ *pt = t;
return 1;
Lfalse:
@@ -4041,12 +4041,12 @@ Lfalse:
/*******************************************
* Skip parens, brackets.
* Input:
- * t is on opening (
+ * t is on opening (
* Output:
- * *pt is set to closing token, which is ')' on success
+ * *pt is set to closing token, which is ')' on success
* Returns:
- * !=0 successful
- * 0 some parsing error
+ * !=0 successful
+ * 0 some parsing error
*/
int Parser::skipParens(Token *t, Token **pt)
@@ -4055,33 +4055,33 @@ int Parser::skipParens(Token *t, Token **pt)
while (1)
{
- switch (t->value)
- {
- case TOKlparen:
- parens++;
- break;
+ switch (t->value)
+ {
+ case TOKlparen:
+ parens++;
+ break;
- case TOKrparen:
- parens--;
- if (parens < 0)
- goto Lfalse;
- if (parens == 0)
- goto Ldone;
- break;
+ case TOKrparen:
+ parens--;
+ if (parens < 0)
+ goto Lfalse;
+ if (parens == 0)
+ goto Ldone;
+ break;
- case TOKeof:
- case TOKsemicolon:
- goto Lfalse;
+ case TOKeof:
+ case TOKsemicolon:
+ goto Lfalse;
- default:
- break;
- }
- t = peek(t);
+ default:
+ break;
+ }
+ t = peek(t);
}
Ldone:
if (*pt)
- *pt = t;
+ *pt = t;
return 1;
Lfalse:
@@ -4100,430 +4100,430 @@ Expression *Parser::parsePrimaryExp()
//printf("parsePrimaryExp(): loc = %d\n", loc.linnum);
switch (token.value)
{
- case TOKidentifier:
- id = token.ident;
- nextToken();
- if (token.value == TOKnot && peek(&token)->value == TOKlparen)
- { // identifier!(template-argument-list)
- TemplateInstance *tempinst;
+ case TOKidentifier:
+ id = token.ident;
+ nextToken();
+ if (token.value == TOKnot && peek(&token)->value == TOKlparen)
+ { // identifier!(template-argument-list)
+ TemplateInstance *tempinst;
- tempinst = new TemplateInstance(loc, id);
- nextToken();
- tempinst->tiargs = parseTemplateArgumentList();
- e = new ScopeExp(loc, tempinst);
- }
- else
- e = new IdentifierExp(loc, id);
- break;
+ tempinst = new TemplateInstance(loc, id);
+ nextToken();
+ tempinst->tiargs = parseTemplateArgumentList();
+ e = new ScopeExp(loc, tempinst);
+ }
+ else
+ e = new IdentifierExp(loc, id);
+ break;
- case TOKdollar:
- if (!inBrackets)
- error("'$' is valid only inside [] of index or slice");
- e = new DollarExp(loc);
- nextToken();
- break;
+ case TOKdollar:
+ if (!inBrackets)
+ error("'$' is valid only inside [] of index or slice");
+ e = new DollarExp(loc);
+ nextToken();
+ break;
- case TOKdot:
- // Signal global scope '.' operator with "" identifier
- e = new IdentifierExp(loc, Id::empty);
- break;
+ case TOKdot:
+ // Signal global scope '.' operator with "" identifier
+ e = new IdentifierExp(loc, Id::empty);
+ break;
- case TOKthis:
- e = new ThisExp(loc);
- nextToken();
- break;
+ case TOKthis:
+ e = new ThisExp(loc);
+ nextToken();
+ break;
- case TOKsuper:
- e = new SuperExp(loc);
- nextToken();
- break;
+ case TOKsuper:
+ e = new SuperExp(loc);
+ nextToken();
+ break;
- case TOKint32v:
- e = new IntegerExp(loc, (d_int32)token.int64value, Type::tint32);
- nextToken();
- break;
+ case TOKint32v:
+ e = new IntegerExp(loc, (d_int32)token.int64value, Type::tint32);
+ nextToken();
+ break;
- case TOKuns32v:
- e = new IntegerExp(loc, (d_uns32)token.uns64value, Type::tuns32);
- nextToken();
- break;
+ case TOKuns32v:
+ e = new IntegerExp(loc, (d_uns32)token.uns64value, Type::tuns32);
+ nextToken();
+ break;
- case TOKint64v:
- e = new IntegerExp(loc, token.int64value, Type::tint64);
- nextToken();
- break;
+ case TOKint64v:
+ e = new IntegerExp(loc, token.int64value, Type::tint64);
+ nextToken();
+ break;
- case TOKuns64v:
- e = new IntegerExp(loc, token.uns64value, Type::tuns64);
- nextToken();
- break;
+ case TOKuns64v:
+ e = new IntegerExp(loc, token.uns64value, Type::tuns64);
+ nextToken();
+ break;
- case TOKfloat32v:
- e = new RealExp(loc, token.float80value, Type::tfloat32);
- nextToken();
- break;
+ case TOKfloat32v:
+ e = new RealExp(loc, token.float80value, Type::tfloat32);
+ nextToken();
+ break;
- case TOKfloat64v:
- e = new RealExp(loc, token.float80value, Type::tfloat64);
- nextToken();
- break;
+ case TOKfloat64v:
+ e = new RealExp(loc, token.float80value, Type::tfloat64);
+ nextToken();
+ break;
- case TOKfloat80v:
- e = new RealExp(loc, token.float80value, Type::tfloat80);
- nextToken();
- break;
+ case TOKfloat80v:
+ e = new RealExp(loc, token.float80value, Type::tfloat80);
+ nextToken();
+ break;
- case TOKimaginary32v:
- e = new RealExp(loc, token.float80value, Type::timaginary32);
- nextToken();
- break;
+ case TOKimaginary32v:
+ e = new RealExp(loc, token.float80value, Type::timaginary32);
+ nextToken();
+ break;
- case TOKimaginary64v:
- e = new RealExp(loc, token.float80value, Type::timaginary64);
- nextToken();
- break;
+ case TOKimaginary64v:
+ e = new RealExp(loc, token.float80value, Type::timaginary64);
+ nextToken();
+ break;
- case TOKimaginary80v:
- e = new RealExp(loc, token.float80value, Type::timaginary80);
- nextToken();
- break;
+ case TOKimaginary80v:
+ e = new RealExp(loc, token.float80value, Type::timaginary80);
+ nextToken();
+ break;
- case TOKnull:
- e = new NullExp(loc);
- nextToken();
- break;
+ case TOKnull:
+ e = new NullExp(loc);
+ nextToken();
+ break;
#if DMDV2
- case TOKfile:
- { char *s = loc.filename ? loc.filename : mod->ident->toChars();
- e = new StringExp(loc, s, strlen(s), 0);
- nextToken();
- break;
- }
+ case TOKfile:
+ { char *s = loc.filename ? loc.filename : mod->ident->toChars();
+ e = new StringExp(loc, s, strlen(s), 0);
+ nextToken();
+ break;
+ }
- case TOKline:
- e = new IntegerExp(loc, loc.linnum, Type::tint32);
- nextToken();
- break;
+ case TOKline:
+ e = new IntegerExp(loc, loc.linnum, Type::tint32);
+ nextToken();
+ break;
#endif
- case TOKtrue:
- e = new IntegerExp(loc, 1, Type::tbool);
- nextToken();
- break;
+ case TOKtrue:
+ e = new IntegerExp(loc, 1, Type::tbool);
+ nextToken();
+ break;
- case TOKfalse:
- e = new IntegerExp(loc, 0, Type::tbool);
- nextToken();
- break;
+ case TOKfalse:
+ e = new IntegerExp(loc, 0, Type::tbool);
+ nextToken();
+ break;
- case TOKcharv:
- e = new IntegerExp(loc, (d_uns8)token.uns64value, Type::tchar);
- nextToken();
- break;
+ case TOKcharv:
+ e = new IntegerExp(loc, (d_uns8)token.uns64value, Type::tchar);
+ nextToken();
+ break;
- case TOKwcharv:
- e = new IntegerExp(loc, (d_uns16)token.uns64value, Type::twchar);
- nextToken();
- break;
+ case TOKwcharv:
+ e = new IntegerExp(loc, (d_uns16)token.uns64value, Type::twchar);
+ nextToken();
+ break;
- case TOKdcharv:
- e = new IntegerExp(loc, (d_uns32)token.uns64value, Type::tdchar);
- nextToken();
- break;
+ case TOKdcharv:
+ e = new IntegerExp(loc, (d_uns32)token.uns64value, Type::tdchar);
+ nextToken();
+ break;
- case TOKstring:
- { unsigned char *s;
- unsigned len;
- unsigned char postfix;
+ case TOKstring:
+ { unsigned char *s;
+ unsigned len;
+ unsigned char postfix;
- // cat adjacent strings
- s = token.ustring;
- len = token.len;
- postfix = token.postfix;
- while (1)
- {
- nextToken();
- if (token.value == TOKstring)
- { unsigned len1;
- unsigned len2;
- unsigned char *s2;
+ // cat adjacent strings
+ s = token.ustring;
+ len = token.len;
+ postfix = token.postfix;
+ while (1)
+ {
+ nextToken();
+ if (token.value == TOKstring)
+ { unsigned len1;
+ unsigned len2;
+ unsigned char *s2;
- if (token.postfix)
- { if (token.postfix != postfix)
- error("mismatched string literal postfixes '%c' and '%c'", postfix, token.postfix);
- postfix = token.postfix;
- }
+ if (token.postfix)
+ { if (token.postfix != postfix)
+ error("mismatched string literal postfixes '%c' and '%c'", postfix, token.postfix);
+ postfix = token.postfix;
+ }
- len1 = len;
- len2 = token.len;
- len = len1 + len2;
- s2 = (unsigned char *)mem.malloc((len + 1) * sizeof(unsigned char));
- memcpy(s2, s, len1 * sizeof(unsigned char));
- memcpy(s2 + len1, token.ustring, (len2 + 1) * sizeof(unsigned char));
- s = s2;
- }
- else
- break;
- }
- e = new StringExp(loc, s, len, postfix);
- break;
- }
+ len1 = len;
+ len2 = token.len;
+ len = len1 + len2;
+ s2 = (unsigned char *)mem.malloc((len + 1) * sizeof(unsigned char));
+ memcpy(s2, s, len1 * sizeof(unsigned char));
+ memcpy(s2 + len1, token.ustring, (len2 + 1) * sizeof(unsigned char));
+ s = s2;
+ }
+ else
+ break;
+ }
+ e = new StringExp(loc, s, len, postfix);
+ break;
+ }
- case BASIC_TYPES_X(t):
- nextToken();
- L1:
- check(TOKdot, t->toChars());
- if (token.value != TOKidentifier)
- { error("found '%s' when expecting identifier following '%s.'", token.toChars(), t->toChars());
- goto Lerr;
- }
- e = typeDotIdExp(loc, t, token.ident);
- nextToken();
- break;
+ case BASIC_TYPES_X(t):
+ nextToken();
+ L1:
+ check(TOKdot, t->toChars());
+ if (token.value != TOKidentifier)
+ { error("found '%s' when expecting identifier following '%s.'", token.toChars(), t->toChars());
+ goto Lerr;
+ }
+ e = typeDotIdExp(loc, t, token.ident);
+ nextToken();
+ break;
- case TOKtypeof:
- { Expression *exp;
+ case TOKtypeof:
+ { Expression *exp;
- nextToken();
- check(TOKlparen);
- exp = parseExpression();
- check(TOKrparen);
- t = new TypeTypeof(loc, exp);
- e = new TypeExp(loc, t);
- break;
- }
+ nextToken();
+ check(TOKlparen);
+ exp = parseExpression();
+ check(TOKrparen);
+ t = new TypeTypeof(loc, exp);
+ e = new TypeExp(loc, t);
+ break;
+ }
- case TOKtypeid:
- { Type *t;
+ case TOKtypeid:
+ { Type *t;
- nextToken();
- check(TOKlparen, "typeid");
- t = parseBasicType();
- t = parseDeclarator(t,NULL); // ( type )
- check(TOKrparen);
- e = new TypeidExp(loc, t);
- break;
- }
+ nextToken();
+ check(TOKlparen, "typeid");
+ t = parseBasicType();
+ t = parseDeclarator(t,NULL); // ( type )
+ check(TOKrparen);
+ e = new TypeidExp(loc, t);
+ break;
+ }
#if DMDV2
- case TOKtraits:
- { /* __traits(identifier, args...)
- */
- Identifier *ident;
- Objects *args = NULL;
+ case TOKtraits:
+ { /* __traits(identifier, args...)
+ */
+ Identifier *ident;
+ Objects *args = NULL;
- nextToken();
- check(TOKlparen);
- if (token.value != TOKidentifier)
- { error("__traits(identifier, args...) expected");
- goto Lerr;
- }
- ident = token.ident;
- nextToken();
- if (token.value == TOKcomma)
- args = parseTemplateArgumentList2(); // __traits(identifier, args...)
- else
- check(TOKrparen); // __traits(identifier)
+ nextToken();
+ check(TOKlparen);
+ if (token.value != TOKidentifier)
+ { error("__traits(identifier, args...) expected");
+ goto Lerr;
+ }
+ ident = token.ident;
+ nextToken();
+ if (token.value == TOKcomma)
+ args = parseTemplateArgumentList2(); // __traits(identifier, args...)
+ else
+ check(TOKrparen); // __traits(identifier)
- e = new TraitsExp(loc, ident, args);
- break;
- }
+ e = new TraitsExp(loc, ident, args);
+ break;
+ }
#endif
- case TOKis:
- { Type *targ;
- Identifier *ident = NULL;
- Type *tspec = NULL;
- enum TOK tok = TOKreserved;
- enum TOK tok2 = TOKreserved;
- Loc loc = this->loc;
+ case TOKis:
+ { Type *targ;
+ Identifier *ident = NULL;
+ Type *tspec = NULL;
+ enum TOK tok = TOKreserved;
+ enum TOK tok2 = TOKreserved;
+ Loc loc = this->loc;
- nextToken();
- if (token.value == TOKlparen)
- {
- nextToken();
- targ = parseBasicType();
- targ = parseDeclarator(targ, &ident);
- if (token.value == TOKcolon || token.value == TOKequal)
- {
- tok = token.value;
- nextToken();
- if (tok == TOKequal &&
- (token.value == TOKtypedef ||
- token.value == TOKstruct ||
- token.value == TOKunion ||
- token.value == TOKclass ||
- token.value == TOKsuper ||
- token.value == TOKenum ||
- token.value == TOKinterface ||
+ nextToken();
+ if (token.value == TOKlparen)
+ {
+ nextToken();
+ targ = parseBasicType();
+ targ = parseDeclarator(targ, &ident);
+ if (token.value == TOKcolon || token.value == TOKequal)
+ {
+ tok = token.value;
+ nextToken();
+ if (tok == TOKequal &&
+ (token.value == TOKtypedef ||
+ token.value == TOKstruct ||
+ token.value == TOKunion ||
+ token.value == TOKclass ||
+ token.value == TOKsuper ||
+ token.value == TOKenum ||
+ token.value == TOKinterface ||
#if DMDV2
- token.value == TOKconst && peek(&token)->value == TOKrparen ||
- token.value == TOKinvariant && peek(&token)->value == TOKrparen ||
- token.value == TOKimmutable && peek(&token)->value == TOKrparen ||
- token.value == TOKshared && peek(&token)->value == TOKrparen ||
+ token.value == TOKconst && peek(&token)->value == TOKrparen ||
+ token.value == TOKinvariant && peek(&token)->value == TOKrparen ||
+ token.value == TOKimmutable && peek(&token)->value == TOKrparen ||
+ token.value == TOKshared && peek(&token)->value == TOKrparen ||
#endif
- token.value == TOKfunction ||
- token.value == TOKdelegate ||
- token.value == TOKreturn))
- {
- tok2 = token.value;
- nextToken();
- }
- else
- {
- tspec = parseBasicType();
- tspec = parseDeclarator(tspec, NULL);
- }
- }
- check(TOKrparen);
- }
- else
- { error("(type identifier : specialization) expected following is");
- goto Lerr;
- }
- e = new IsExp(loc, targ, ident, tok, tspec, tok2);
- break;
- }
+ token.value == TOKfunction ||
+ token.value == TOKdelegate ||
+ token.value == TOKreturn))
+ {
+ tok2 = token.value;
+ nextToken();
+ }
+ else
+ {
+ tspec = parseBasicType();
+ tspec = parseDeclarator(tspec, NULL);
+ }
+ }
+ check(TOKrparen);
+ }
+ else
+ { error("(type identifier : specialization) expected following is");
+ goto Lerr;
+ }
+ e = new IsExp(loc, targ, ident, tok, tspec, tok2);
+ break;
+ }
- case TOKassert:
- { Expression *msg = NULL;
+ case TOKassert:
+ { Expression *msg = NULL;
- nextToken();
- check(TOKlparen, "assert");
- e = parseAssignExp();
- if (token.value == TOKcomma)
- { nextToken();
- msg = parseAssignExp();
- }
- check(TOKrparen);
- e = new AssertExp(loc, e, msg);
- break;
- }
+ nextToken();
+ check(TOKlparen, "assert");
+ e = parseAssignExp();
+ if (token.value == TOKcomma)
+ { nextToken();
+ msg = parseAssignExp();
+ }
+ check(TOKrparen);
+ e = new AssertExp(loc, e, msg);
+ break;
+ }
- case TOKmixin:
- {
- nextToken();
- check(TOKlparen, "mixin");
- e = parseAssignExp();
- check(TOKrparen);
- e = new CompileExp(loc, e);
- break;
- }
+ case TOKmixin:
+ {
+ nextToken();
+ check(TOKlparen, "mixin");
+ e = parseAssignExp();
+ check(TOKrparen);
+ e = new CompileExp(loc, e);
+ break;
+ }
- case TOKimport:
- {
- nextToken();
- check(TOKlparen, "import");
- e = parseAssignExp();
- check(TOKrparen);
- e = new FileExp(loc, e);
- break;
- }
+ case TOKimport:
+ {
+ nextToken();
+ check(TOKlparen, "import");
+ e = parseAssignExp();
+ check(TOKrparen);
+ e = new FileExp(loc, e);
+ break;
+ }
- case TOKlparen:
- if (peekPastParen(&token)->value == TOKlcurly)
- { // (arguments) { statements... }
- save = TOKdelegate;
- goto case_delegate;
- }
- // ( expression )
- nextToken();
- e = parseExpression();
- check(loc, TOKrparen);
- break;
+ case TOKlparen:
+ if (peekPastParen(&token)->value == TOKlcurly)
+ { // (arguments) { statements... }
+ save = TOKdelegate;
+ goto case_delegate;
+ }
+ // ( expression )
+ nextToken();
+ e = parseExpression();
+ check(loc, TOKrparen);
+ break;
- case TOKlbracket:
- { /* Parse array literals and associative array literals:
- * [ value, value, value ... ]
- * [ key:value, key:value, key:value ... ]
- */
- Expressions *values = new Expressions();
- Expressions *keys = NULL;
+ case TOKlbracket:
+ { /* Parse array literals and associative array literals:
+ * [ value, value, value ... ]
+ * [ key:value, key:value, key:value ... ]
+ */
+ Expressions *values = new Expressions();
+ Expressions *keys = NULL;
- nextToken();
- if (token.value != TOKrbracket)
- {
- while (token.value != TOKeof)
- {
- Expression *e = parseAssignExp();
- if (token.value == TOKcolon && (keys || values->dim == 0))
- { nextToken();
- if (!keys)
- keys = new Expressions();
- keys->push(e);
- e = parseAssignExp();
- }
- else if (keys)
- { error("'key:value' expected for associative array literal");
- delete keys;
- keys = NULL;
- }
- values->push(e);
- if (token.value == TOKrbracket)
- break;
- check(TOKcomma);
- }
- }
- check(TOKrbracket);
+ nextToken();
+ if (token.value != TOKrbracket)
+ {
+ while (token.value != TOKeof)
+ {
+ Expression *e = parseAssignExp();
+ if (token.value == TOKcolon && (keys || values->dim == 0))
+ { nextToken();
+ if (!keys)
+ keys = new Expressions();
+ keys->push(e);
+ e = parseAssignExp();
+ }
+ else if (keys)
+ { error("'key:value' expected for associative array literal");
+ delete keys;
+ keys = NULL;
+ }
+ values->push(e);
+ if (token.value == TOKrbracket)
+ break;
+ check(TOKcomma);
+ }
+ }
+ check(TOKrbracket);
- if (keys)
- e = new AssocArrayLiteralExp(loc, keys, values);
- else
- e = new ArrayLiteralExp(loc, values);
- break;
- }
+ if (keys)
+ e = new AssocArrayLiteralExp(loc, keys, values);
+ else
+ e = new ArrayLiteralExp(loc, values);
+ break;
+ }
- case TOKlcurly:
- // { statements... }
- save = TOKdelegate;
- goto case_delegate;
+ case TOKlcurly:
+ // { statements... }
+ save = TOKdelegate;
+ goto case_delegate;
- case TOKfunction:
- case TOKdelegate:
- save = token.value;
- nextToken();
- case_delegate:
- {
- /* function type(parameters) { body }
- * delegate type(parameters) { body }
- */
- Parameters *arguments;
- int varargs;
- FuncLiteralDeclaration *fd;
- Type *t;
+ case TOKfunction:
+ case TOKdelegate:
+ save = token.value;
+ nextToken();
+ case_delegate:
+ {
+ /* function type(parameters) { body }
+ * delegate type(parameters) { body }
+ */
+ Parameters *arguments;
+ int varargs;
+ FuncLiteralDeclaration *fd;
+ Type *t;
- if (token.value == TOKlcurly)
- {
- t = NULL;
- varargs = 0;
- arguments = new Parameters();
- }
- else
- {
- if (token.value == TOKlparen)
- t = NULL;
- else
- {
- t = parseBasicType();
- t = parseBasicType2(t); // function return type
- }
- arguments = parseParameters(&varargs);
- }
- t = new TypeFunction(arguments, t, varargs, linkage);
- fd = new FuncLiteralDeclaration(loc, 0, t, save, NULL);
- parseContracts(fd);
- e = new FuncExp(loc, fd);
- break;
- }
+ if (token.value == TOKlcurly)
+ {
+ t = NULL;
+ varargs = 0;
+ arguments = new Parameters();
+ }
+ else
+ {
+ if (token.value == TOKlparen)
+ t = NULL;
+ else
+ {
+ t = parseBasicType();
+ t = parseBasicType2(t); // function return type
+ }
+ arguments = parseParameters(&varargs);
+ }
+ t = new TypeFunction(arguments, t, varargs, linkage);
+ fd = new FuncLiteralDeclaration(loc, 0, t, save, NULL);
+ parseContracts(fd);
+ e = new FuncExp(loc, fd);
+ break;
+ }
- default:
- error("expression expected, not '%s'", token.toChars());
- Lerr:
- // Anything for e, as long as it's not NULL
- e = new IntegerExp(loc, 0, Type::tint32);
- nextToken();
- break;
+ default:
+ error("expression expected, not '%s'", token.toChars());
+ Lerr:
+ // Anything for e, as long as it's not NULL
+ e = new IntegerExp(loc, 0, Type::tint32);
+ nextToken();
+ break;
}
return parsePostExp(e);
}
@@ -4534,102 +4534,102 @@ Expression *Parser::parsePostExp(Expression *e)
while (1)
{
- loc = this->loc;
- switch (token.value)
- {
- case TOKdot:
- nextToken();
- if (token.value == TOKidentifier)
- { Identifier *id = token.ident;
+ loc = this->loc;
+ switch (token.value)
+ {
+ case TOKdot:
+ nextToken();
+ if (token.value == TOKidentifier)
+ { Identifier *id = token.ident;
- nextToken();
- if (token.value == TOKnot && peek(&token)->value == TOKlparen)
- { // identifier!(template-argument-list)
- TemplateInstance *tempinst;
+ nextToken();
+ if (token.value == TOKnot && peek(&token)->value == TOKlparen)
+ { // identifier!(template-argument-list)
+ TemplateInstance *tempinst;
- tempinst = new TemplateInstance(loc, id);
- nextToken();
- tempinst->tiargs = parseTemplateArgumentList();
- e = new DotTemplateInstanceExp(loc, e, tempinst);
- }
- else
- e = new DotIdExp(loc, e, id);
- continue;
- }
- else if (token.value == TOKnew)
- {
- e = parseNewExp(e);
- continue;
- }
- else
- error("identifier expected following '.', not '%s'", token.toChars());
- break;
+ tempinst = new TemplateInstance(loc, id);
+ nextToken();
+ tempinst->tiargs = parseTemplateArgumentList();
+ e = new DotTemplateInstanceExp(loc, e, tempinst);
+ }
+ else
+ e = new DotIdExp(loc, e, id);
+ continue;
+ }
+ else if (token.value == TOKnew)
+ {
+ e = parseNewExp(e);
+ continue;
+ }
+ else
+ error("identifier expected following '.', not '%s'", token.toChars());
+ break;
- case TOKplusplus:
- e = new PostExp(TOKplusplus, loc, e);
- break;
+ case TOKplusplus:
+ e = new PostExp(TOKplusplus, loc, e);
+ break;
- case TOKminusminus:
- e = new PostExp(TOKminusminus, loc, e);
- break;
+ case TOKminusminus:
+ e = new PostExp(TOKminusminus, loc, e);
+ break;
- case TOKlparen:
- e = new CallExp(loc, e, parseArguments());
- continue;
+ case TOKlparen:
+ e = new CallExp(loc, e, parseArguments());
+ continue;
- case TOKlbracket:
- { // array dereferences:
- // array[index]
- // array[]
- // array[lwr .. upr]
- Expression *index;
- Expression *upr;
+ case TOKlbracket:
+ { // array dereferences:
+ // array[index]
+ // array[]
+ // array[lwr .. upr]
+ Expression *index;
+ Expression *upr;
- inBrackets++;
- nextToken();
- if (token.value == TOKrbracket)
- { // array[]
- e = new SliceExp(loc, e, NULL, NULL);
- nextToken();
- }
- else
- {
- index = parseAssignExp();
- if (token.value == TOKslice)
- { // array[lwr .. upr]
- nextToken();
- upr = parseAssignExp();
- e = new SliceExp(loc, e, index, upr);
- }
- else
- { // array[index, i2, i3, i4, ...]
- Expressions *arguments = new Expressions();
- arguments->push(index);
- if (token.value == TOKcomma)
- {
- nextToken();
- while (1)
- { Expression *arg;
+ inBrackets++;
+ nextToken();
+ if (token.value == TOKrbracket)
+ { // array[]
+ e = new SliceExp(loc, e, NULL, NULL);
+ nextToken();
+ }
+ else
+ {
+ index = parseAssignExp();
+ if (token.value == TOKslice)
+ { // array[lwr .. upr]
+ nextToken();
+ upr = parseAssignExp();
+ e = new SliceExp(loc, e, index, upr);
+ }
+ else
+ { // array[index, i2, i3, i4, ...]
+ Expressions *arguments = new Expressions();
+ arguments->push(index);
+ if (token.value == TOKcomma)
+ {
+ nextToken();
+ while (1)
+ { Expression *arg;
- arg = parseAssignExp();
- arguments->push(arg);
- if (token.value == TOKrbracket)
- break;
- check(TOKcomma);
- }
- }
- e = new ArrayExp(loc, e, arguments);
- }
- check(TOKrbracket);
- inBrackets--;
- }
- continue;
- }
+ arg = parseAssignExp();
+ arguments->push(arg);
+ if (token.value == TOKrbracket)
+ break;
+ check(TOKcomma);
+ }
+ }
+ e = new ArrayExp(loc, e, arguments);
+ }
+ check(TOKrbracket);
+ inBrackets--;
+ }
+ continue;
+ }
- default:
- return e;
- }
- nextToken();
+ default:
+ return e;
+ }
+ nextToken();
}
}
@@ -4639,171 +4639,171 @@ Expression *Parser::parseUnaryExp()
switch (token.value)
{
- case TOKand:
- nextToken();
- e = parseUnaryExp();
- e = new AddrExp(loc, e);
- break;
+ case TOKand:
+ nextToken();
+ e = parseUnaryExp();
+ e = new AddrExp(loc, e);
+ break;
- case TOKplusplus:
- nextToken();
- e = parseUnaryExp();
- e = new AddAssignExp(loc, e, new IntegerExp(loc, 1, Type::tint32));
- break;
+ case TOKplusplus:
+ nextToken();
+ e = parseUnaryExp();
+ e = new AddAssignExp(loc, e, new IntegerExp(loc, 1, Type::tint32));
+ break;
- case TOKminusminus:
- nextToken();
- e = parseUnaryExp();
- e = new MinAssignExp(loc, e, new IntegerExp(loc, 1, Type::tint32));
- break;
+ case TOKminusminus:
+ nextToken();
+ e = parseUnaryExp();
+ e = new MinAssignExp(loc, e, new IntegerExp(loc, 1, Type::tint32));
+ break;
- case TOKmul:
- nextToken();
- e = parseUnaryExp();
- e = new PtrExp(loc, e);
- break;
+ case TOKmul:
+ nextToken();
+ e = parseUnaryExp();
+ e = new PtrExp(loc, e);
+ break;
- case TOKmin:
- nextToken();
- e = parseUnaryExp();
- e = new NegExp(loc, e);
- break;
+ case TOKmin:
+ nextToken();
+ e = parseUnaryExp();
+ e = new NegExp(loc, e);
+ break;
- case TOKadd:
- nextToken();
- e = parseUnaryExp();
- e = new UAddExp(loc, e);
- break;
+ case TOKadd:
+ nextToken();
+ e = parseUnaryExp();
+ e = new UAddExp(loc, e);
+ break;
- case TOKnot:
- nextToken();
- e = parseUnaryExp();
- e = new NotExp(loc, e);
- break;
+ case TOKnot:
+ nextToken();
+ e = parseUnaryExp();
+ e = new NotExp(loc, e);
+ break;
- case TOKtilde:
- nextToken();
- e = parseUnaryExp();
- e = new ComExp(loc, e);
- break;
+ case TOKtilde:
+ nextToken();
+ e = parseUnaryExp();
+ e = new ComExp(loc, e);
+ break;
- case TOKdelete:
- nextToken();
- e = parseUnaryExp();
- e = new DeleteExp(loc, e);
- break;
+ case TOKdelete:
+ nextToken();
+ e = parseUnaryExp();
+ e = new DeleteExp(loc, e);
+ break;
- case TOKnew:
- e = parseNewExp(NULL);
- break;
+ case TOKnew:
+ e = parseNewExp(NULL);
+ break;
- case TOKcast: // cast(type) expression
- { Type *t;
+ case TOKcast: // cast(type) expression
+ { Type *t;
- nextToken();
- check(TOKlparen);
- t = parseBasicType();
- t = parseDeclarator(t,NULL); // ( type )
- check(TOKrparen);
+ nextToken();
+ check(TOKlparen);
+ t = parseBasicType();
+ t = parseDeclarator(t,NULL); // ( type )
+ check(TOKrparen);
- e = parseUnaryExp();
- e = new CastExp(loc, e, t);
- break;
- }
+ e = parseUnaryExp();
+ e = new CastExp(loc, e, t);
+ break;
+ }
- case TOKlparen:
- { Token *tk;
+ case TOKlparen:
+ { Token *tk;
- tk = peek(&token);
+ tk = peek(&token);
#if CCASTSYNTAX
- // If cast
- if (isDeclaration(tk, 0, TOKrparen, &tk))
- {
- tk = peek(tk); // skip over right parenthesis
- switch (tk->value)
- {
- case TOKnot:
- tk = peek(tk);
- if (tk->value == TOKis) // !is
- break;
- case TOKdot:
- case TOKplusplus:
- case TOKminusminus:
- case TOKdelete:
- case TOKnew:
- case TOKlparen:
- case TOKidentifier:
- case TOKthis:
- case TOKsuper:
- case TOKint32v:
- case TOKuns32v:
- case TOKint64v:
- case TOKuns64v:
- case TOKfloat32v:
- case TOKfloat64v:
- case TOKfloat80v:
- case TOKimaginary32v:
- case TOKimaginary64v:
- case TOKimaginary80v:
- case TOKnull:
- case TOKtrue:
- case TOKfalse:
- case TOKcharv:
- case TOKwcharv:
- case TOKdcharv:
- case TOKstring:
+ // If cast
+ if (isDeclaration(tk, 0, TOKrparen, &tk))
+ {
+ tk = peek(tk); // skip over right parenthesis
+ switch (tk->value)
+ {
+ case TOKnot:
+ tk = peek(tk);
+ if (tk->value == TOKis) // !is
+ break;
+ case TOKdot:
+ case TOKplusplus:
+ case TOKminusminus:
+ case TOKdelete:
+ case TOKnew:
+ case TOKlparen:
+ case TOKidentifier:
+ case TOKthis:
+ case TOKsuper:
+ case TOKint32v:
+ case TOKuns32v:
+ case TOKint64v:
+ case TOKuns64v:
+ case TOKfloat32v:
+ case TOKfloat64v:
+ case TOKfloat80v:
+ case TOKimaginary32v:
+ case TOKimaginary64v:
+ case TOKimaginary80v:
+ case TOKnull:
+ case TOKtrue:
+ case TOKfalse:
+ case TOKcharv:
+ case TOKwcharv:
+ case TOKdcharv:
+ case TOKstring:
#if 0
- case TOKtilde:
- case TOKand:
- case TOKmul:
- case TOKmin:
- case TOKadd:
+ case TOKtilde:
+ case TOKand:
+ case TOKmul:
+ case TOKmin:
+ case TOKadd:
#endif
- case TOKfunction:
- case TOKdelegate:
- case TOKtypeof:
+ case TOKfunction:
+ case TOKdelegate:
+ case TOKtypeof:
#if DMDV2
- case TOKfile:
- case TOKline:
+ case TOKfile:
+ case TOKline:
#endif
- case BASIC_TYPES: // (type)int.size
- { // (type) una_exp
- Type *t;
+ case BASIC_TYPES: // (type)int.size
+ { // (type) una_exp
+ Type *t;
- nextToken();
- t = parseBasicType();
- t = parseDeclarator(t,NULL);
- check(TOKrparen);
+ nextToken();
+ t = parseBasicType();
+ t = parseDeclarator(t,NULL);
+ check(TOKrparen);
- // if .identifier
- if (token.value == TOKdot)
- {
- nextToken();
- if (token.value != TOKidentifier)
- { error("Identifier expected following (type).");
- return NULL;
- }
- e = typeDotIdExp(loc, t, token.ident);
- nextToken();
- e = parsePostExp(e);
- }
- else
- {
- e = parseUnaryExp();
- e = new CastExp(loc, e, t);
- error("C style cast illegal, use %s", e->toChars());
- }
- return e;
- }
- }
- }
+ // if .identifier
+ if (token.value == TOKdot)
+ {
+ nextToken();
+ if (token.value != TOKidentifier)
+ { error("Identifier expected following (type).");
+ return NULL;
+ }
+ e = typeDotIdExp(loc, t, token.ident);
+ nextToken();
+ e = parsePostExp(e);
+ }
+ else
+ {
+ e = parseUnaryExp();
+ e = new CastExp(loc, e, t);
+ error("C style cast illegal, use %s", e->toChars());
+ }
+ return e;
+ }
+ }
+ }
#endif
- e = parsePrimaryExp();
- break;
- }
- default:
- e = parsePrimaryExp();
- break;
+ e = parsePrimaryExp();
+ break;
+ }
+ default:
+ e = parsePrimaryExp();
+ break;
}
assert(e);
return e;
@@ -4817,16 +4817,16 @@ Expression *Parser::parseMulExp()
e = parseUnaryExp();
while (1)
{
- switch (token.value)
- {
- case TOKmul: nextToken(); e2 = parseUnaryExp(); e = new MulExp(loc,e,e2); continue;
- case TOKdiv: nextToken(); e2 = parseUnaryExp(); e = new DivExp(loc,e,e2); continue;
- case TOKmod: nextToken(); e2 = parseUnaryExp(); e = new ModExp(loc,e,e2); continue;
+ switch (token.value)
+ {
+ case TOKmul: nextToken(); e2 = parseUnaryExp(); e = new MulExp(loc,e,e2); continue;
+ case TOKdiv: nextToken(); e2 = parseUnaryExp(); e = new DivExp(loc,e,e2); continue;
+ case TOKmod: nextToken(); e2 = parseUnaryExp(); e = new ModExp(loc,e,e2); continue;
- default:
- break;
- }
- break;
+ default:
+ break;
+ }
+ break;
}
return e;
}
@@ -4839,16 +4839,16 @@ Expression *Parser::parseAddExp()
e = parseMulExp();
while (1)
{
- switch (token.value)
- {
- case TOKadd: nextToken(); e2 = parseMulExp(); e = new AddExp(loc,e,e2); continue;
- case TOKmin: nextToken(); e2 = parseMulExp(); e = new MinExp(loc,e,e2); continue;
- case TOKtilde: nextToken(); e2 = parseMulExp(); e = new CatExp(loc,e,e2); continue;
+ switch (token.value)
+ {
+ case TOKadd: nextToken(); e2 = parseMulExp(); e = new AddExp(loc,e,e2); continue;
+ case TOKmin: nextToken(); e2 = parseMulExp(); e = new MinExp(loc,e,e2); continue;
+ case TOKtilde: nextToken(); e2 = parseMulExp(); e = new CatExp(loc,e,e2); continue;
- default:
- break;
- }
- break;
+ default:
+ break;
+ }
+ break;
}
return e;
}
@@ -4861,16 +4861,16 @@ Expression *Parser::parseShiftExp()
e = parseAddExp();
while (1)
{
- switch (token.value)
- {
- case TOKshl: nextToken(); e2 = parseAddExp(); e = new ShlExp(loc,e,e2); continue;
- case TOKshr: nextToken(); e2 = parseAddExp(); e = new ShrExp(loc,e,e2); continue;
- case TOKushr: nextToken(); e2 = parseAddExp(); e = new UshrExp(loc,e,e2); continue;
+ switch (token.value)
+ {
+ case TOKshl: nextToken(); e2 = parseAddExp(); e = new ShlExp(loc,e,e2); continue;
+ case TOKshr: nextToken(); e2 = parseAddExp(); e = new ShrExp(loc,e,e2); continue;
+ case TOKushr: nextToken(); e2 = parseAddExp(); e = new UshrExp(loc,e,e2); continue;
- default:
- break;
- }
- break;
+ default:
+ break;
+ }
+ break;
}
return e;
}
@@ -4884,36 +4884,36 @@ Expression *Parser::parseRelExp()
e = parseShiftExp();
while (1)
{
- switch (token.value)
- {
- case TOKlt:
- case TOKle:
- case TOKgt:
- case TOKge:
- case TOKunord:
- case TOKlg:
- case TOKleg:
- case TOKule:
- case TOKul:
- case TOKuge:
- case TOKug:
- case TOKue:
- op = token.value;
- nextToken();
- e2 = parseShiftExp();
- e = new CmpExp(op, loc, e, e2);
- continue;
+ switch (token.value)
+ {
+ case TOKlt:
+ case TOKle:
+ case TOKgt:
+ case TOKge:
+ case TOKunord:
+ case TOKlg:
+ case TOKleg:
+ case TOKule:
+ case TOKul:
+ case TOKuge:
+ case TOKug:
+ case TOKue:
+ op = token.value;
+ nextToken();
+ e2 = parseShiftExp();
+ e = new CmpExp(op, loc, e, e2);
+ continue;
- case TOKin:
- nextToken();
- e2 = parseShiftExp();
- e = new InExp(loc, e, e2);
- continue;
+ case TOKin:
+ nextToken();
+ e2 = parseShiftExp();
+ e = new InExp(loc, e, e2);
+ continue;
- default:
- break;
- }
- break;
+ default:
+ break;
+ }
+ break;
}
return e;
}
@@ -4926,48 +4926,48 @@ Expression *Parser::parseEqualExp()
e = parseRelExp();
while (1)
- { enum TOK value = token.value;
+ { enum TOK value = token.value;
- switch (value)
- {
- case TOKequal:
- case TOKnotequal:
- nextToken();
- e2 = parseRelExp();
- e = new EqualExp(value, loc, e, e2);
- continue;
+ switch (value)
+ {
+ case TOKequal:
+ case TOKnotequal:
+ nextToken();
+ e2 = parseRelExp();
+ e = new EqualExp(value, loc, e, e2);
+ continue;
- case TOKidentity:
- error("'===' is no longer legal, use 'is' instead");
- goto L1;
+ case TOKidentity:
+ error("'===' is no longer legal, use 'is' instead");
+ goto L1;
- case TOKnotidentity:
- error("'!==' is no longer legal, use '!is' instead");
- goto L1;
+ case TOKnotidentity:
+ error("'!==' is no longer legal, use '!is' instead");
+ goto L1;
- case TOKis:
- value = TOKidentity;
- goto L1;
+ case TOKis:
+ value = TOKidentity;
+ goto L1;
- case TOKnot:
- // Attempt to identify '!is'
- t = peek(&token);
- if (t->value != TOKis)
- break;
- nextToken();
- value = TOKnotidentity;
- goto L1;
+ case TOKnot:
+ // Attempt to identify '!is'
+ t = peek(&token);
+ if (t->value != TOKis)
+ break;
+ nextToken();
+ value = TOKnotidentity;
+ goto L1;
- L1:
- nextToken();
- e2 = parseRelExp();
- e = new IdentityExp(value, loc, e, e2);
- continue;
+ L1:
+ nextToken();
+ e2 = parseRelExp();
+ e = new IdentityExp(value, loc, e, e2);
+ continue;
- default:
- break;
- }
- break;
+ default:
+ break;
+ }
+ break;
}
return e;
}
@@ -4983,57 +4983,57 @@ Expression *Parser::parseCmpExp()
switch (op)
{
- case TOKequal:
- case TOKnotequal:
- nextToken();
- e2 = parseShiftExp();
- e = new EqualExp(op, loc, e, e2);
- break;
+ case TOKequal:
+ case TOKnotequal:
+ nextToken();
+ e2 = parseShiftExp();
+ e = new EqualExp(op, loc, e, e2);
+ break;
- case TOKis:
- op = TOKidentity;
- goto L1;
+ case TOKis:
+ op = TOKidentity;
+ goto L1;
- case TOKnot:
- // Attempt to identify '!is'
- t = peek(&token);
- if (t->value != TOKis)
- break;
- nextToken();
- op = TOKnotidentity;
- goto L1;
+ case TOKnot:
+ // Attempt to identify '!is'
+ t = peek(&token);
+ if (t->value != TOKis)
+ break;
+ nextToken();
+ op = TOKnotidentity;
+ goto L1;
- L1:
- nextToken();
- e2 = parseShiftExp();
- e = new IdentityExp(op, loc, e, e2);
- break;
+ L1:
+ nextToken();
+ e2 = parseShiftExp();
+ e = new IdentityExp(op, loc, e, e2);
+ break;
- case TOKlt:
- case TOKle:
- case TOKgt:
- case TOKge:
- case TOKunord:
- case TOKlg:
- case TOKleg:
- case TOKule:
- case TOKul:
- case TOKuge:
- case TOKug:
- case TOKue:
- nextToken();
- e2 = parseShiftExp();
- e = new CmpExp(op, loc, e, e2);
- break;
+ case TOKlt:
+ case TOKle:
+ case TOKgt:
+ case TOKge:
+ case TOKunord:
+ case TOKlg:
+ case TOKleg:
+ case TOKule:
+ case TOKul:
+ case TOKuge:
+ case TOKug:
+ case TOKue:
+ nextToken();
+ e2 = parseShiftExp();
+ e = new CmpExp(op, loc, e, e2);
+ break;
- case TOKin:
- nextToken();
- e2 = parseShiftExp();
- e = new InExp(loc, e, e2);
- break;
+ case TOKin:
+ nextToken();
+ e2 = parseShiftExp();
+ e = new InExp(loc, e, e2);
+ break;
- default:
- break;
+ default:
+ break;
}
return e;
}
@@ -5045,25 +5045,25 @@ Expression *Parser::parseAndExp()
if (global.params.Dversion == 1)
{
- e = parseEqualExp();
- while (token.value == TOKand)
- {
- nextToken();
- e2 = parseEqualExp();
- e = new AndExp(loc,e,e2);
- loc = this->loc;
- }
+ e = parseEqualExp();
+ while (token.value == TOKand)
+ {
+ nextToken();
+ e2 = parseEqualExp();
+ e = new AndExp(loc,e,e2);
+ loc = this->loc;
+ }
}
else
{
- e = parseCmpExp();
- while (token.value == TOKand)
- {
- nextToken();
- e2 = parseCmpExp();
- e = new AndExp(loc,e,e2);
- loc = this->loc;
- }
+ e = parseCmpExp();
+ while (token.value == TOKand)
+ {
+ nextToken();
+ e2 = parseCmpExp();
+ e = new AndExp(loc,e,e2);
+ loc = this->loc;
+ }
}
return e;
}
@@ -5076,9 +5076,9 @@ Expression *Parser::parseXorExp()
e = parseAndExp();
while (token.value == TOKxor)
{
- nextToken();
- e2 = parseAndExp();
- e = new XorExp(loc, e, e2);
+ nextToken();
+ e2 = parseAndExp();
+ e = new XorExp(loc, e, e2);
}
return e;
}
@@ -5091,9 +5091,9 @@ Expression *Parser::parseOrExp()
e = parseXorExp();
while (token.value == TOKor)
{
- nextToken();
- e2 = parseXorExp();
- e = new OrExp(loc, e, e2);
+ nextToken();
+ e2 = parseXorExp();
+ e = new OrExp(loc, e, e2);
}
return e;
}
@@ -5106,9 +5106,9 @@ Expression *Parser::parseAndAndExp()
e = parseOrExp();
while (token.value == TOKandand)
{
- nextToken();
- e2 = parseOrExp();
- e = new AndAndExp(loc, e, e2);
+ nextToken();
+ e2 = parseOrExp();
+ e = new AndAndExp(loc, e, e2);
}
return e;
}
@@ -5121,9 +5121,9 @@ Expression *Parser::parseOrOrExp()
e = parseAndAndExp();
while (token.value == TOKoror)
{
- nextToken();
- e2 = parseAndAndExp();
- e = new OrOrExp(loc, e, e2);
+ nextToken();
+ e2 = parseAndAndExp();
+ e = new OrOrExp(loc, e, e2);
}
return e;
}
@@ -5137,11 +5137,11 @@ Expression *Parser::parseCondExp()
e = parseOrOrExp();
if (token.value == TOKquestion)
{
- nextToken();
- e1 = parseExpression();
- check(TOKcolon);
- e2 = parseCondExp();
- e = new CondExp(loc, e, e1, e2);
+ nextToken();
+ e1 = parseExpression();
+ check(TOKcolon);
+ e2 = parseCondExp();
+ e = new CondExp(loc, e, e1, e2);
}
return e;
}
@@ -5154,31 +5154,31 @@ Expression *Parser::parseAssignExp()
e = parseCondExp();
while (1)
{
- loc = this->loc;
- switch (token.value)
- {
+ loc = this->loc;
+ switch (token.value)
+ {
#define X(tok,ector) \
- case tok: nextToken(); e2 = parseAssignExp(); e = new ector(loc,e,e2); continue;
+ case tok: nextToken(); e2 = parseAssignExp(); e = new ector(loc,e,e2); continue;
- X(TOKassign, AssignExp);
- X(TOKaddass, AddAssignExp);
- X(TOKminass, MinAssignExp);
- X(TOKmulass, MulAssignExp);
- X(TOKdivass, DivAssignExp);
- X(TOKmodass, ModAssignExp);
- X(TOKandass, AndAssignExp);
- X(TOKorass, OrAssignExp);
- X(TOKxorass, XorAssignExp);
- X(TOKshlass, ShlAssignExp);
- X(TOKshrass, ShrAssignExp);
- X(TOKushrass, UshrAssignExp);
- X(TOKcatass, CatAssignExp);
+ X(TOKassign, AssignExp);
+ X(TOKaddass, AddAssignExp);
+ X(TOKminass, MinAssignExp);
+ X(TOKmulass, MulAssignExp);
+ X(TOKdivass, DivAssignExp);
+ X(TOKmodass, ModAssignExp);
+ X(TOKandass, AndAssignExp);
+ X(TOKorass, OrAssignExp);
+ X(TOKxorass, XorAssignExp);
+ X(TOKshlass, ShlAssignExp);
+ X(TOKshrass, ShrAssignExp);
+ X(TOKushrass, UshrAssignExp);
+ X(TOKcatass, CatAssignExp);
#undef X
- default:
- break;
- }
- break;
+ default:
+ break;
+ }
+ break;
}
return e;
}
@@ -5192,10 +5192,10 @@ Expression *Parser::parseExpression()
e = parseAssignExp();
while (token.value == TOKcomma)
{
- nextToken();
- e2 = parseAssignExp();
- e = new CommaExp(loc, e, e2);
- loc = this->loc;
+ nextToken();
+ e2 = parseAssignExp();
+ e = new CommaExp(loc, e, e2);
+ loc = this->loc;
}
return e;
}
@@ -5214,24 +5214,24 @@ Expressions *Parser::parseArguments()
arguments = new Expressions();
if (token.value == TOKlbracket)
- endtok = TOKrbracket;
+ endtok = TOKrbracket;
else
- endtok = TOKrparen;
+ endtok = TOKrparen;
{
- nextToken();
- if (token.value != endtok)
- {
- while (1)
- {
- arg = parseAssignExp();
- arguments->push(arg);
- if (token.value == endtok)
- break;
- check(TOKcomma);
- }
- }
- check(endtok);
+ nextToken();
+ if (token.value != endtok)
+ {
+ while (1)
+ {
+ arg = parseAssignExp();
+ arguments->push(arg);
+ if (token.value == endtok)
+ break;
+ check(TOKcomma);
+ }
+ }
+ check(endtok);
}
return arguments;
}
@@ -5250,40 +5250,40 @@ Expression *Parser::parseNewExp(Expression *thisexp)
newargs = NULL;
if (token.value == TOKlparen)
{
- newargs = parseArguments();
+ newargs = parseArguments();
}
// An anonymous nested class starts with "class"
if (token.value == TOKclass)
{
- nextToken();
- if (token.value == TOKlparen)
- arguments = parseArguments();
+ nextToken();
+ if (token.value == TOKlparen)
+ arguments = parseArguments();
- BaseClasses *baseclasses = NULL;
- if (token.value != TOKlcurly)
- baseclasses = parseBaseClasses();
+ BaseClasses *baseclasses = NULL;
+ if (token.value != TOKlcurly)
+ baseclasses = parseBaseClasses();
- Identifier *id = NULL;
- ClassDeclaration *cd = new ClassDeclaration(loc, id, baseclasses);
+ Identifier *id = NULL;
+ ClassDeclaration *cd = new ClassDeclaration(loc, id, baseclasses);
- if (token.value != TOKlcurly)
- { error("{ members } expected for anonymous class");
- cd->members = NULL;
- }
- else
- {
- nextToken();
- Array *decl = parseDeclDefs(0);
- if (token.value != TOKrcurly)
- error("class member expected");
- nextToken();
- cd->members = decl;
- }
+ if (token.value != TOKlcurly)
+ { error("{ members } expected for anonymous class");
+ cd->members = NULL;
+ }
+ else
+ {
+ nextToken();
+ Array *decl = parseDeclDefs(0);
+ if (token.value != TOKrcurly)
+ error("class member expected");
+ nextToken();
+ cd->members = decl;
+ }
- e = new NewAnonClassExp(loc, thisexp, newargs, cd, arguments);
+ e = new NewAnonClassExp(loc, thisexp, newargs, cd, arguments);
- return e;
+ return e;
}
#if LTORARRAYDECL
@@ -5291,53 +5291,53 @@ Expression *Parser::parseNewExp(Expression *thisexp)
t = parseBasicType2(t);
if (t->ty == Taarray)
{
- Type *index = ((TypeAArray *)t)->index;
+ Type *index = ((TypeAArray *)t)->index;
- Expression *e = index->toExpression();
- if (e)
- { arguments = new Expressions();
- arguments->push(e);
- t = new TypeDArray(t->next);
- }
- else
- {
- error("need size of rightmost array, not type %s", index->toChars());
- return new NullExp(loc);
- }
+ Expression *e = index->toExpression();
+ if (e)
+ { arguments = new Expressions();
+ arguments->push(e);
+ t = new TypeDArray(t->next);
+ }
+ else
+ {
+ error("need size of rightmost array, not type %s", index->toChars());
+ return new NullExp(loc);
+ }
}
else if (t->ty == Tsarray)
{
- TypeSArray *tsa = (TypeSArray *)t;
- Expression *e = tsa->dim;
+ TypeSArray *tsa = (TypeSArray *)t;
+ Expression *e = tsa->dim;
- arguments = new Expressions();
- arguments->push(e);
- t = new TypeDArray(t->next);
+ arguments = new Expressions();
+ arguments->push(e);
+ t = new TypeDArray(t->next);
}
else if (token.value == TOKlparen)
{
- arguments = parseArguments();
+ arguments = parseArguments();
}
#else
t = parseBasicType();
while (token.value == TOKmul)
{ t = new TypePointer(t);
- nextToken();
+ nextToken();
}
if (token.value == TOKlbracket)
{
- Expression *e;
+ Expression *e;
- nextToken();
- e = parseAssignExp();
- arguments = new Array();
- arguments->push(e);
- check(TOKrbracket);
- t = parseDeclarator(t, NULL);
- t = new TypeDArray(t);
+ nextToken();
+ e = parseAssignExp();
+ arguments = new Array();
+ arguments->push(e);
+ check(TOKrbracket);
+ t = parseDeclarator(t, NULL);
+ t = new TypeDArray(t);
}
else if (token.value == TOKlparen)
- arguments = parseArguments();
+ arguments = parseArguments();
#endif
e = new NewExp(loc, thisexp, newargs, t, arguments);
return e;
diff --git a/dmd/parse.h b/dmd/parse.h
index 78b97192..c80e364d 100644
--- a/dmd/parse.h
+++ b/dmd/parse.h
@@ -50,10 +50,10 @@ struct StaticAssert;
enum ParseStatementFlags
{
- PSsemi = 1, // empty ';' statements are allowed
- PSscope = 2, // start a new scope
- PScurly = 4, // { } statement is required
- PScurlyscope = 8, // { } starts a new scope
+ PSsemi = 1, // empty ';' statements are allowed
+ PSscope = 2, // start a new scope
+ PScurly = 4, // { } statement is required
+ PScurlyscope = 8, // { } starts a new scope
};
@@ -61,8 +61,8 @@ struct Parser : Lexer
{
ModuleDeclaration *md;
enum LINK linkage;
- Loc endloc; // set to location of last right curly
- int inBrackets; // inside [] of array index or slice
+ Loc endloc; // set to location of last right curly
+ int inBrackets; // inside [] of array index or slice
Parser(Module *module, unsigned char *base, unsigned length, int doDocComment);
diff --git a/dmd/root/array.c b/dmd/root/array.c
index 9ec8784d..5efa1dc6 100644
--- a/dmd/root/array.c
+++ b/dmd/root/array.c
@@ -13,7 +13,7 @@
#include
#include
-#if (defined (__SVR4) && defined (__sun))
+#if (defined (__SVR4) && defined (__sun))
#include
#endif
@@ -63,7 +63,7 @@ void Array::mark()
mem.mark(data);
for (u = 0; u < dim; u++)
- mem.mark(data[u]); // BUG: what if arrays of Object's?
+ mem.mark(data[u]); // BUG: what if arrays of Object's?
}
void Array::reserve(unsigned nentries)
@@ -71,8 +71,8 @@ void Array::reserve(unsigned nentries)
//printf("Array::reserve: size = %d, offset = %d, nbytes = %d\n", size, offset, nbytes);
if (allocdim - dim < nentries)
{
- allocdim = dim + nentries;
- data = (void **)mem.realloc(data, allocdim * sizeof(*data));
+ allocdim = dim + nentries;
+ data = (void **)mem.realloc(data, allocdim * sizeof(*data));
}
}
@@ -80,7 +80,7 @@ void Array::setDim(unsigned newdim)
{
if (dim < newdim)
{
- reserve(newdim - dim);
+ reserve(newdim - dim);
}
dim = newdim;
}
@@ -88,8 +88,8 @@ void Array::setDim(unsigned newdim)
void Array::fixDim()
{
if (dim != allocdim)
- { data = (void **)mem.realloc(data, dim * sizeof(*data));
- allocdim = dim;
+ { data = (void **)mem.realloc(data, dim * sizeof(*data));
+ allocdim = dim;
}
}
@@ -124,14 +124,14 @@ void Array::insert(unsigned index, void *ptr)
void Array::insert(unsigned index, Array *a)
{
if (a)
- { unsigned d;
+ { unsigned d;
- d = a->dim;
- reserve(d);
- if (dim != index)
- memmove(data + index + d, data + index, (dim - index) * sizeof(*data));
- memcpy(data + index, a->data, d * sizeof(*data));
- dim += d;
+ d = a->dim;
+ reserve(d);
+ if (dim != index)
+ memmove(data + index + d, data + index, (dim - index) * sizeof(*data));
+ memcpy(data + index, a->data, d * sizeof(*data));
+ dim += d;
}
}
@@ -163,8 +163,8 @@ char *Array::toChars()
len = 2;
for (u = 0; u < dim; u++)
{
- buf[u] = ((Object *)data[u])->toChars();
- len += strlen(buf[u]) + 1;
+ buf[u] = ((Object *)data[u])->toChars();
+ len += strlen(buf[u]) + 1;
}
str = (char *)mem.malloc(len);
@@ -172,11 +172,11 @@ char *Array::toChars()
p = str + 1;
for (u = 0; u < dim; u++)
{
- if (u)
- *p++ = ',';
- len = strlen(buf[u]);
- memcpy(p,buf[u],len);
- p += len;
+ if (u)
+ *p++ = ',';
+ len = strlen(buf[u]);
+ memcpy(p,buf[u],len);
+ p += len;
}
*p++ = ']';
*p = 0;
@@ -197,7 +197,7 @@ int
#if _WIN32
__cdecl
#endif
- Array_sort_compare(const void *x, const void *y)
+ Array_sort_compare(const void *x, const void *y)
{
Object *ox = *(Object **)x;
Object *oy = *(Object **)y;
@@ -209,7 +209,7 @@ void Array::sort()
{
if (dim)
{
- qsort(data, dim, sizeof(Object *), Array_sort_compare);
+ qsort(data, dim, sizeof(Object *), Array_sort_compare);
}
}
diff --git a/dmd/root/async.c b/dmd/root/async.c
index f732e5fe..df72b931 100644
--- a/dmd/root/async.c
+++ b/dmd/root/async.c
@@ -43,7 +43,7 @@ struct AsyncRead
AsyncRead *AsyncRead::create(size_t nfiles)
{
AsyncRead *aw = (AsyncRead *)mem.calloc(1, sizeof(AsyncRead) +
- (nfiles - 1) * sizeof(FileData));
+ (nfiles - 1) * sizeof(FileData));
aw->filesmax = nfiles;
return aw;
}
@@ -64,22 +64,22 @@ void AsyncRead::start()
//printf("aw->filesdim = %p %d\n", this, filesdim);
if (filesdim)
{
- unsigned threadaddr;
- hThread = (HANDLE) _beginthreadex(NULL,
- 0,
- &startthread,
- this,
- 0,
- (unsigned *)&threadaddr);
+ unsigned threadaddr;
+ hThread = (HANDLE) _beginthreadex(NULL,
+ 0,
+ &startthread,
+ this,
+ 0,
+ (unsigned *)&threadaddr);
- if (hThread)
- {
- SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST);
- }
- else
- {
- assert(0);
- }
+ if (hThread)
+ {
+ SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST);
+ }
+ else
+ {
+ assert(0);
+ }
}
}
@@ -87,7 +87,7 @@ int AsyncRead::read(size_t i)
{
FileData *f = &files[i];
WaitForSingleObject(f->event, INFINITE);
- Sleep(0); // give up time slice
+ Sleep(0); // give up time slice
return f->result;
}
@@ -104,13 +104,13 @@ unsigned __stdcall startthread(void *p)
//printf("aw->filesdim = %p %d\n", aw, aw->filesdim);
for (size_t i = 0; i < aw->filesdim; i++)
- { FileData *f = &aw->files[i];
+ { FileData *f = &aw->files[i];
- f->result = f->file->read();
- SetEvent(f->event);
+ f->result = f->file->read();
+ SetEvent(f->event);
}
_endthreadex(EXIT_SUCCESS);
- return EXIT_SUCCESS; // if skidding
+ return EXIT_SUCCESS; // if skidding
}
#else
@@ -147,7 +147,7 @@ struct AsyncRead
AsyncRead *AsyncRead::create(size_t nfiles)
{
AsyncRead *aw = (AsyncRead *)mem.calloc(1, sizeof(AsyncRead) +
- (nfiles - 1) * sizeof(FileData));
+ (nfiles - 1) * sizeof(FileData));
aw->filesmax = nfiles;
return aw;
}
diff --git a/dmd/root/dchar.c b/dmd/root/dchar.c
index 94d97d1e..741e7d7a 100644
--- a/dmd/root/dchar.c
+++ b/dmd/root/dchar.c
@@ -26,12 +26,12 @@ dchar *Dchar::dup(char *p)
size_t len;
if (!p)
- return NULL;
+ return NULL;
len = strlen(p);
s = (dchar *)mem.malloc((len + 1) * sizeof(dchar));
for (unsigned i = 0; i < len; i++)
{
- s[i] = (dchar)(p[i] & 0xFF);
+ s[i] = (dchar)(p[i] & 0xFF);
}
s[len] = 0;
return s;
@@ -43,8 +43,8 @@ dchar *Dchar::memchr(dchar *p, int c, int count)
for (u = 0; u < count; u++)
{
- if (p[u] == c)
- return p + u;
+ if (p[u] == c)
+ return p + u;
}
return NULL;
}
@@ -55,31 +55,31 @@ unsigned Dchar::calcHash(const dchar *str, unsigned len)
{
__asm
{
- mov ECX,4[ESP]
- mov EDX,8[ESP]
- xor EAX,EAX
- test EDX,EDX
- je L92
+ mov ECX,4[ESP]
+ mov EDX,8[ESP]
+ xor EAX,EAX
+ test EDX,EDX
+ je L92
-LC8: cmp EDX,1
- je L98
- cmp EDX,2
- je LAE
+LC8: cmp EDX,1
+ je L98
+ cmp EDX,2
+ je LAE
- add EAX,[ECX]
-// imul EAX,EAX,025h
- lea EAX,[EAX][EAX*8]
- add ECX,4
- sub EDX,2
- jmp LC8
+ add EAX,[ECX]
+// imul EAX,EAX,025h
+ lea EAX,[EAX][EAX*8]
+ add ECX,4
+ sub EDX,2
+ jmp LC8
-L98: mov DX,[ECX]
- and EDX,0FFFFh
- add EAX,EDX
- ret
+L98: mov DX,[ECX]
+ and EDX,0FFFFh
+ add EAX,EDX
+ ret
-LAE: add EAX,[ECX]
-L92: ret
+LAE: add EAX,[ECX]
+L92: ret
}
}
#else
@@ -89,26 +89,26 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
for (;;)
{
- switch (len)
- {
- case 0:
- return hash;
+ switch (len)
+ {
+ case 0:
+ return hash;
- case 1:
- hash += *(const uint16_t *)str;
- return hash;
+ case 1:
+ hash += *(const uint16_t *)str;
+ return hash;
- case 2:
- hash += *(const uint32_t *)str;
- return hash;
+ case 2:
+ hash += *(const uint32_t *)str;
+ return hash;
- default:
- hash += *(const uint32_t *)str;
- hash *= 37;
- str += 2;
- len -= 2;
- break;
- }
+ default:
+ hash += *(const uint32_t *)str;
+ hash *= 37;
+ str += 2;
+ len -= 2;
+ break;
+ }
}
}
#endif
@@ -119,26 +119,26 @@ hash_t Dchar::icalcHash(const dchar *str, size_t len)
for (;;)
{
- switch (len)
- {
- case 0:
- return hash;
+ switch (len)
+ {
+ case 0:
+ return hash;
- case 1:
- hash += *(const uint16_t *)str | 0x20;
- return hash;
+ case 1:
+ hash += *(const uint16_t *)str | 0x20;
+ return hash;
- case 2:
- hash += *(const uint32_t *)str | 0x200020;
- return hash;
+ case 2:
+ hash += *(const uint32_t *)str | 0x200020;
+ return hash;
- default:
- hash += *(const uint32_t *)str | 0x200020;
- hash *= 37;
- str += 2;
- len -= 2;
- break;
- }
+ default:
+ hash += *(const uint32_t *)str | 0x200020;
+ hash *= 37;
+ str += 2;
+ len -= 2;
+ break;
+ }
}
}
@@ -150,34 +150,34 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
while (1)
{
- switch (len)
- {
- case 0:
- return hash;
+ switch (len)
+ {
+ case 0:
+ return hash;
- case 1:
- hash *= 37;
- hash += *(const uint8_t *)str;
- return hash;
+ case 1:
+ hash *= 37;
+ hash += *(const uint8_t *)str;
+ return hash;
- case 2:
- hash *= 37;
- hash += *(const uint16_t *)str;
- return hash;
+ case 2:
+ hash *= 37;
+ hash += *(const uint16_t *)str;
+ return hash;
- case 3:
- hash *= 37;
- hash += (*(const uint16_t *)str << 8) +
- ((const uint8_t *)str)[2];
- return hash;
+ case 3:
+ hash *= 37;
+ hash += (*(const uint16_t *)str << 8) +
+ ((const uint8_t *)str)[2];
+ return hash;
- default:
- hash *= 37;
- hash += *(const uint32_t *)str;
- str += 4;
- len -= 4;
- break;
- }
+ default:
+ hash *= 37;
+ hash += *(const uint32_t *)str;
+ str += 4;
+ len -= 4;
+ break;
+ }
}
}
@@ -208,7 +208,7 @@ char Dchar::mblen[256] =
dchar *Dchar::dec(dchar *pstart, dchar *p)
{
while ((p[-1] & 0xC0) == 0x80)
- p--;
+ p--;
return p;
}
@@ -220,40 +220,40 @@ int Dchar::get(dchar *p)
c = q[0];
switch (mblen[c])
{
- case 2:
- c = ((c - 0xC0) << 6) |
- (q[1] - 0x80);
- break;
+ case 2:
+ c = ((c - 0xC0) << 6) |
+ (q[1] - 0x80);
+ break;
- case 3:
- c = ((c - 0xE0) << 12) |
- ((q[1] - 0x80) << 6) |
- (q[2] - 0x80);
- break;
+ case 3:
+ c = ((c - 0xE0) << 12) |
+ ((q[1] - 0x80) << 6) |
+ (q[2] - 0x80);
+ break;
- case 4:
- c = ((c - 0xF0) << 18) |
- ((q[1] - 0x80) << 12) |
- ((q[2] - 0x80) << 6) |
- (q[3] - 0x80);
- break;
+ case 4:
+ c = ((c - 0xF0) << 18) |
+ ((q[1] - 0x80) << 12) |
+ ((q[2] - 0x80) << 6) |
+ (q[3] - 0x80);
+ break;
- case 5:
- c = ((c - 0xF8) << 24) |
- ((q[1] - 0x80) << 18) |
- ((q[2] - 0x80) << 12) |
- ((q[3] - 0x80) << 6) |
- (q[4] - 0x80);
- break;
+ case 5:
+ c = ((c - 0xF8) << 24) |
+ ((q[1] - 0x80) << 18) |
+ ((q[2] - 0x80) << 12) |
+ ((q[3] - 0x80) << 6) |
+ (q[4] - 0x80);
+ break;
- case 6:
- c = ((c - 0xFC) << 30) |
- ((q[1] - 0x80) << 24) |
- ((q[2] - 0x80) << 18) |
- ((q[3] - 0x80) << 12) |
- ((q[4] - 0x80) << 6) |
- (q[5] - 0x80);
- break;
+ case 6:
+ c = ((c - 0xFC) << 30) |
+ ((q[1] - 0x80) << 24) |
+ ((q[2] - 0x80) << 18) |
+ ((q[3] - 0x80) << 12) |
+ ((q[4] - 0x80) << 6) |
+ (q[5] - 0x80);
+ break;
}
return c;
}
@@ -262,50 +262,50 @@ dchar *Dchar::put(dchar *p, unsigned c)
{
if (c <= 0x7F)
{
- *p++ = c;
+ *p++ = c;
}
else if (c <= 0x7FF)
{
- p[0] = 0xC0 + (c >> 6);
- p[1] = 0x80 + (c & 0x3F);
- p += 2;
+ p[0] = 0xC0 + (c >> 6);
+ p[1] = 0x80 + (c & 0x3F);
+ p += 2;
}
else if (c <= 0xFFFF)
{
- p[0] = 0xE0 + (c >> 12);
- p[1] = 0x80 + ((c >> 6) & 0x3F);
- p[2] = 0x80 + (c & 0x3F);
- p += 3;
+ p[0] = 0xE0 + (c >> 12);
+ p[1] = 0x80 + ((c >> 6) & 0x3F);
+ p[2] = 0x80 + (c & 0x3F);
+ p += 3;
}
else if (c <= 0x1FFFFF)
{
- p[0] = 0xF0 + (c >> 18);
- p[1] = 0x80 + ((c >> 12) & 0x3F);
- p[2] = 0x80 + ((c >> 6) & 0x3F);
- p[3] = 0x80 + (c & 0x3F);
- p += 4;
+ p[0] = 0xF0 + (c >> 18);
+ p[1] = 0x80 + ((c >> 12) & 0x3F);
+ p[2] = 0x80 + ((c >> 6) & 0x3F);
+ p[3] = 0x80 + (c & 0x3F);
+ p += 4;
}
else if (c <= 0x3FFFFFF)
{
- p[0] = 0xF8 + (c >> 24);
- p[1] = 0x80 + ((c >> 18) & 0x3F);
- p[2] = 0x80 + ((c >> 12) & 0x3F);
- p[3] = 0x80 + ((c >> 6) & 0x3F);
- p[4] = 0x80 + (c & 0x3F);
- p += 5;
+ p[0] = 0xF8 + (c >> 24);
+ p[1] = 0x80 + ((c >> 18) & 0x3F);
+ p[2] = 0x80 + ((c >> 12) & 0x3F);
+ p[3] = 0x80 + ((c >> 6) & 0x3F);
+ p[4] = 0x80 + (c & 0x3F);
+ p += 5;
}
else if (c <= 0x7FFFFFFF)
{
- p[0] = 0xFC + (c >> 30);
- p[1] = 0x80 + ((c >> 24) & 0x3F);
- p[2] = 0x80 + ((c >> 18) & 0x3F);
- p[3] = 0x80 + ((c >> 12) & 0x3F);
- p[4] = 0x80 + ((c >> 6) & 0x3F);
- p[5] = 0x80 + (c & 0x3F);
- p += 6;
+ p[0] = 0xFC + (c >> 30);
+ p[1] = 0x80 + ((c >> 24) & 0x3F);
+ p[2] = 0x80 + ((c >> 18) & 0x3F);
+ p[3] = 0x80 + ((c >> 12) & 0x3F);
+ p[4] = 0x80 + ((c >> 6) & 0x3F);
+ p[5] = 0x80 + (c & 0x3F);
+ p += 6;
}
else
- assert(0); // not a UCS-4 character
+ assert(0); // not a UCS-4 character
return p;
}
@@ -315,47 +315,47 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
while (1)
{
- switch (len)
- {
- case 0:
- return hash;
+ switch (len)
+ {
+ case 0:
+ return hash;
- case 1:
- hash *= 37;
- hash += *(const uint8_t *)str;
- return hash;
+ case 1:
+ hash *= 37;
+ hash += *(const uint8_t *)str;
+ return hash;
- case 2:
- hash *= 37;
+ case 2:
+ hash *= 37;
#if __I86__
- hash += *(const uint16_t *)str;
+ hash += *(const uint16_t *)str;
#else
- hash += str[0] * 256 + str[1];
+ hash += str[0] * 256 + str[1];
#endif
- return hash;
+ return hash;
- case 3:
- hash *= 37;
+ case 3:
+ hash *= 37;
#if __I86__
- hash += (*(const uint16_t *)str << 8) +
- ((const uint8_t *)str)[2];
+ hash += (*(const uint16_t *)str << 8) +
+ ((const uint8_t *)str)[2];
#else
- hash += (str[0] * 256 + str[1]) * 256 + str[2];
+ hash += (str[0] * 256 + str[1]) * 256 + str[2];
#endif
- return hash;
+ return hash;
- default:
- hash *= 37;
+ default:
+ hash *= 37;
#if __I86__
- hash += *(const uint32_t *)str;
+ hash += *(const uint32_t *)str;
#else
- hash += ((str[0] * 256 + str[1]) * 256 + str[2]) * 256 + str[3];
+ hash += ((str[0] * 256 + str[1]) * 256 + str[2]) * 256 + str[3];
#endif
- str += 4;
- len -= 4;
- break;
- }
+ str += 4;
+ len -= 4;
+ break;
+ }
}
}
@@ -367,46 +367,46 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
while (1)
{
- switch (len)
- {
- case 0:
- return hash;
+ switch (len)
+ {
+ case 0:
+ return hash;
- case 1:
- hash *= 37;
- hash += *(const uint8_t *)str;
- return hash;
+ case 1:
+ hash *= 37;
+ hash += *(const uint8_t *)str;
+ return hash;
- case 2:
- hash *= 37;
+ case 2:
+ hash *= 37;
#if __I86__
- hash += *(const uint16_t *)str;
+ hash += *(const uint16_t *)str;
#else
- hash += str[0] * 256 + str[1];
+ hash += str[0] * 256 + str[1];
#endif
- return hash;
+ return hash;
- case 3:
- hash *= 37;
+ case 3:
+ hash *= 37;
#if __I86__
- hash += (*(const uint16_t *)str << 8) +
- ((const uint8_t *)str)[2];
+ hash += (*(const uint16_t *)str << 8) +
+ ((const uint8_t *)str)[2];
#else
- hash += (str[0] * 256 + str[1]) * 256 + str[2];
+ hash += (str[0] * 256 + str[1]) * 256 + str[2];
#endif
- return hash;
+ return hash;
- default:
- hash *= 37;
+ default:
+ hash *= 37;
#if __I86__
- hash += *(const uint32_t *)str;
+ hash += *(const uint32_t *)str;
#else
- hash += ((str[0] * 256 + str[1]) * 256 + str[2]) * 256 + str[3];
+ hash += ((str[0] * 256 + str[1]) * 256 + str[2]) * 256 + str[3];
#endif
- str += 4;
- len -= 4;
- break;
- }
+ str += 4;
+ len -= 4;
+ break;
+ }
}
}
@@ -416,34 +416,34 @@ hash_t Dchar::icalcHash(const dchar *str, size_t len)
while (1)
{
- switch (len)
- {
- case 0:
- return hash;
+ switch (len)
+ {
+ case 0:
+ return hash;
- case 1:
- hash *= 37;
- hash += *(const uint8_t *)str | 0x20;
- return hash;
+ case 1:
+ hash *= 37;
+ hash += *(const uint8_t *)str | 0x20;
+ return hash;
- case 2:
- hash *= 37;
- hash += *(const uint16_t *)str | 0x2020;
- return hash;
+ case 2:
+ hash *= 37;
+ hash += *(const uint16_t *)str | 0x2020;
+ return hash;
- case 3:
- hash *= 37;
- hash += ((*(const uint16_t *)str << 8) +
- ((const uint8_t *)str)[2]) | 0x202020;
- return hash;
+ case 3:
+ hash *= 37;
+ hash += ((*(const uint16_t *)str << 8) +
+ ((const uint8_t *)str)[2]) | 0x202020;
+ return hash;
- default:
- hash *= 37;
- hash += *(const uint32_t *)str | 0x20202020;
- str += 4;
- len -= 4;
- break;
- }
+ default:
+ hash *= 37;
+ hash += *(const uint32_t *)str | 0x20202020;
+ str += 4;
+ len -= 4;
+ break;
+ }
}
}
@@ -460,23 +460,23 @@ void main()
for (c = 0; c < 256; c++)
{
- s = 1;
- if (c >= 0xC0 && c <= 0xDF)
- s = 2;
- if (c >= 0xE0 && c <= 0xEF)
- s = 3;
- if (c >= 0xF0 && c <= 0xF7)
- s = 4;
- if (c >= 0xF8 && c <= 0xFB)
- s = 5;
- if (c >= 0xFC && c <= 0xFD)
- s = 6;
+ s = 1;
+ if (c >= 0xC0 && c <= 0xDF)
+ s = 2;
+ if (c >= 0xE0 && c <= 0xEF)
+ s = 3;
+ if (c >= 0xF0 && c <= 0xF7)
+ s = 4;
+ if (c >= 0xF8 && c <= 0xFB)
+ s = 5;
+ if (c >= 0xFC && c <= 0xFD)
+ s = 6;
- printf("%d", s);
- if ((c & 15) == 15)
- printf(",\n");
- else
- printf(",");
+ printf("%d", s);
+ if ((c & 15) == 15)
+ printf(",\n");
+ else
+ printf(",");
}
}
#endif
diff --git a/dmd/root/dchar.h b/dmd/root/dchar.h
index 4aa8413d..c22b48db 100644
--- a/dmd/root/dchar.h
+++ b/dmd/root/dchar.h
@@ -33,9 +33,9 @@ typedef size_t hash_t;
#include
typedef wchar_t dchar;
-#define TEXT(x) L##x
+#define TEXT(x) L##x
-#define Dchar_mbmax 1
+#define Dchar_mbmax 1
struct Dchar
{
@@ -48,14 +48,14 @@ struct Dchar
static int cmp(dchar *s1, dchar *s2)
{
#if __DMC__
- if (!*s1 && !*s2) // wcscmp is broken
- return 0;
+ if (!*s1 && !*s2) // wcscmp is broken
+ return 0;
#endif
- return wcscmp(s1, s2);
+ return wcscmp(s1, s2);
#if 0
- return (*s1 == *s2)
- ? wcscmp(s1, s2)
- : ((int)*s1 - (int)*s2);
+ return (*s1 == *s2)
+ ? wcscmp(s1, s2)
+ : ((int)*s1 - (int)*s2);
#endif
}
static int memcmp(const dchar *s1, const dchar *s2, int nchars) { return ::memcmp(s1, s2, nchars * sizeof(dchar)); }
@@ -68,7 +68,7 @@ struct Dchar
static int toLower(dchar c) { return isUpper(c) ? towlower(c) : c; }
static int toLower(dchar *p) { return toLower(*p); }
static int toUpper(dchar c) { return isLower(c) ? towupper(c) : c; }
- static dchar *dup(dchar *p) { return ::_wcsdup(p); } // BUG: out of memory?
+ static dchar *dup(dchar *p) { return ::_wcsdup(p); } // BUG: out of memory?
static dchar *dup(char *p);
static dchar *chr(dchar *p, unsigned c) { return wcschr(p, (dchar)c); }
static dchar *rchr(dchar *p, unsigned c) { return wcsrchr(p, (dchar)c); }
@@ -89,16 +89,16 @@ struct Dchar
#include
typedef char dchar;
-#define TEXT(x) x
+#define TEXT(x) x
-#define Dchar_mbmax MB_LEN_MAX
+#define Dchar_mbmax MB_LEN_MAX
#elif UTF8
typedef char dchar;
-#define TEXT(x) x
+#define TEXT(x) x
-#define Dchar_mbmax 6
+#define Dchar_mbmax 6
struct Dchar
{
@@ -109,7 +109,7 @@ struct Dchar
static int len(const dchar *p) { return strlen(p); }
static int get(dchar *p);
static int getprev(dchar *pstart, dchar *p)
- { return *dec(pstart, p) & 0xFF; }
+ { return *dec(pstart, p) & 0xFF; }
static dchar *put(dchar *p, unsigned c);
static int cmp(dchar *s1, dchar *s2) { return strcmp(s1, s2); }
static int memcmp(const dchar *s1, const dchar *s2, int nchars) { return ::memcmp(s1, s2, nchars); }
@@ -122,11 +122,11 @@ struct Dchar
static int toLower(dchar c) { return isUpper(c) ? tolower(c) : c; }
static int toLower(dchar *p) { return toLower(*p); }
static int toUpper(dchar c) { return isLower(c) ? toupper(c) : c; }
- static dchar *dup(dchar *p) { return ::strdup(p); } // BUG: out of memory?
+ static dchar *dup(dchar *p) { return ::strdup(p); } // BUG: out of memory?
static dchar *chr(dchar *p, int c) { return strchr(p, c); }
static dchar *rchr(dchar *p, int c) { return strrchr(p, c); }
static dchar *memchr(dchar *p, int c, int count)
- { return (dchar *)::memchr(p, c, count); }
+ { return (dchar *)::memchr(p, c, count); }
static dchar *cpy(dchar *s1, dchar *s2) { return strcpy(s1, s2); }
static dchar *str(dchar *s1, dchar *s2) { return strstr(s1, s2); }
static hash_t calcHash(const dchar *str, size_t len);
@@ -145,9 +145,9 @@ struct Dchar
#endif
typedef char dchar;
-#define TEXT(x) x
+#define TEXT(x) x
-#define Dchar_mbmax 1
+#define Dchar_mbmax 1
struct Dchar
{
@@ -169,12 +169,12 @@ struct Dchar
static int toLower(dchar c) { return isupper(c) ? tolower(c) : c; }
static int toLower(dchar *p) { return toLower(*p); }
static int toUpper(dchar c) { return islower(c) ? toupper(c) : c; }
- static dchar *dup(dchar *p) { return ::strdup(p); } // BUG: out of memory?
+ static dchar *dup(dchar *p) { return ::strdup(p); } // BUG: out of memory?
#endif
static dchar *chr(dchar *p, int c) { return strchr(p, c); }
static dchar *rchr(dchar *p, int c) { return strrchr(p, c); }
static dchar *memchr(dchar *p, int c, int count)
- { return (dchar *)::memchr(p, c, count); }
+ { return (dchar *)::memchr(p, c, count); }
static dchar *cpy(dchar *s1, dchar *s2) { return strcpy(s1, s2); }
static dchar *str(dchar *s1, dchar *s2) { return strstr(s1, s2); }
static hash_t calcHash(const dchar *str, size_t len);
diff --git a/dmd/root/gnuc.c b/dmd/root/gnuc.c
index 849d1e4d..8f33d839 100644
--- a/dmd/root/gnuc.c
+++ b/dmd/root/gnuc.c
@@ -8,20 +8,20 @@ int memicmp(const char *s1, const char *s2, int n)
int result = 0;
for (int i = 0; i < n; i++)
- { char c1 = s1[i];
- char c2 = s2[i];
+ { char c1 = s1[i];
+ char c2 = s2[i];
- result = c1 - c2;
- if (result)
- {
- if ('A' <= c1 && c1 <= 'Z')
- c1 += 'a' - 'A';
- if ('A' <= c2 && c2 <= 'Z')
- c2 += 'a' - 'A';
- result = c1 - c2;
- if (result)
- break;
- }
+ result = c1 - c2;
+ if (result)
+ {
+ if ('A' <= c1 && c1 <= 'Z')
+ c1 += 'a' - 'A';
+ if ('A' <= c2 && c2 <= 'Z')
+ c2 += 'a' - 'A';
+ result = c1 - c2;
+ if (result)
+ break;
+ }
}
return result;
}
@@ -31,24 +31,24 @@ int stricmp(const char *s1, const char *s2)
int result = 0;
for (;;)
- { char c1 = *s1;
- char c2 = *s2;
+ { char c1 = *s1;
+ char c2 = *s2;
- result = c1 - c2;
- if (result)
- {
- if ('A' <= c1 && c1 <= 'Z')
- c1 += 'a' - 'A';
- if ('A' <= c2 && c2 <= 'Z')
- c2 += 'a' - 'A';
- result = c1 - c2;
- if (result)
- break;
- }
- if (!c1)
- break;
- s1++;
- s2++;
+ result = c1 - c2;
+ if (result)
+ {
+ if ('A' <= c1 && c1 <= 'Z')
+ c1 += 'a' - 'A';
+ if ('A' <= c2 && c2 <= 'Z')
+ c2 += 'a' - 'A';
+ result = c1 - c2;
+ if (result)
+ break;
+ }
+ if (!c1)
+ break;
+ s1++;
+ s2++;
}
return result;
}
diff --git a/dmd/root/lstring.c b/dmd/root/lstring.c
index b222450e..c354d4b3 100644
--- a/dmd/root/lstring.c
+++ b/dmd/root/lstring.c
@@ -44,7 +44,7 @@ Lstring *Lstring::append(const Lstring *s)
Lstring *t;
if (!s->length)
- return this;
+ return this;
t = alloc(length + s->length);
memcpy(t->string, string, length * sizeof(dchar));
memcpy(t->string + length, s->string, s->length * sizeof(dchar));
@@ -56,7 +56,7 @@ Lstring *Lstring::substring(int start, int end)
Lstring *t;
if (start == end)
- return &zero;
+ return &zero;
t = alloc(end - start);
memcpy(t->string, string + start, (end - start) * sizeof(dchar));
return t;
diff --git a/dmd/root/lstring.h b/dmd/root/lstring.h
index 665fe547..fed39199 100644
--- a/dmd/root/lstring.h
+++ b/dmd/root/lstring.h
@@ -23,7 +23,7 @@ struct Lstring
#pragma warning (disable : 4200)
dchar string[];
- static Lstring zero; // 0 length string
+ static Lstring zero; // 0 length string
// No constructors because we want to be able to statically
// initialize Lstring's, and Lstrings are of variable size.
@@ -55,14 +55,14 @@ struct Lstring
static int cmp(const Lstring *s1, const Lstring *s2)
{
- int c = s2->length - s1->length;
- return c ? c : Dchar::memcmp(s1->string, s2->string, s1->length);
+ int c = s2->length - s1->length;
+ return c ? c : Dchar::memcmp(s1->string, s2->string, s1->length);
}
static int icmp(const Lstring *s1, const Lstring *s2)
{
- int c = s2->length - s1->length;
- return c ? c : Dchar::memicmp(s1->string, s2->string, s1->length);
+ int c = s2->length - s1->length;
+ return c ? c : Dchar::memicmp(s1->string, s2->string, s1->length);
}
Lstring *append(const Lstring *s);
diff --git a/dmd/root/man.c b/dmd/root/man.c
index ec066a64..2c3bbc40 100644
--- a/dmd/root/man.c
+++ b/dmd/root/man.c
@@ -28,9 +28,9 @@ void browse(const char *url)
#if linux || __FreeBSD__ || __sun&&__SVR4
-#include
-#include
-#include
+#include
+#include
+#include
void browse(const char *url)
{
@@ -39,9 +39,9 @@ void browse(const char *url)
const char *browser = getenv("BROWSER");
if (browser)
- browser = strdup(browser);
+ browser = strdup(browser);
else
- browser = "x-www-browser";
+ browser = "x-www-browser";
args[0] = browser;
args[1] = url;
@@ -50,9 +50,9 @@ void browse(const char *url)
childpid = fork();
if (childpid == 0)
{
- execvp(args[0], (char**)args);
- perror(args[0]); // failed to execute
- return;
+ execvp(args[0], (char**)args);
+ perror(args[0]); // failed to execute
+ return;
}
}
@@ -60,9 +60,9 @@ void browse(const char *url)
#if __APPLE__
-#include
-#include
-#include
+#include
+#include
+#include
void browse(const char *url)
{
@@ -71,27 +71,27 @@ void browse(const char *url)
char *browser = getenv("BROWSER");
if (browser)
- { browser = strdup(browser);
- args[0] = browser;
- args[1] = url;
- args[2] = NULL;
+ { browser = strdup(browser);
+ args[0] = browser;
+ args[1] = url;
+ args[2] = NULL;
}
else
{
- //browser = "/Applications/Safari.app/Contents/MacOS/Safari";
- args[0] = "open";
- args[1] = "-a";
- args[2] = "/Applications/Safari.app";
- args[3] = url;
- args[4] = NULL;
+ //browser = "/Applications/Safari.app/Contents/MacOS/Safari";
+ args[0] = "open";
+ args[1] = "-a";
+ args[2] = "/Applications/Safari.app";
+ args[3] = url;
+ args[4] = NULL;
}
childpid = fork();
if (childpid == 0)
{
- execvp(args[0], (char**)args);
- perror(args[0]); // failed to execute
- return;
+ execvp(args[0], (char**)args);
+ perror(args[0]); // failed to execute
+ return;
}
}
diff --git a/dmd/root/port.c b/dmd/root/port.c
index ae3bffe8..2a0ec6f1 100644
--- a/dmd/root/port.c
+++ b/dmd/root/port.c
@@ -197,7 +197,7 @@ double Port::floor(double d)
double Port::pow(double x, double y)
{
if (y == 0)
- return 1; // even if x is NAN
+ return 1; // even if x is NAN
return ::pow(x, y);
}
@@ -208,64 +208,64 @@ unsigned _int64 Port::strtoull(const char *p, char **pend, int base)
int error;
#define ULLONG_MAX ((unsigned _int64)~0I64)
- while (isspace(*p)) /* skip leading white space */
- p++;
+ while (isspace(*p)) /* skip leading white space */
+ p++;
if (*p == '+')
- p++;
+ p++;
switch (base)
{ case 0:
- base = 10; /* assume decimal base */
- if (*p == '0')
- { base = 8; /* could be octal */
- p++;
- switch (*p)
- { case 'x':
- case 'X':
- base = 16; /* hex */
- p++;
- break;
+ base = 10; /* assume decimal base */
+ if (*p == '0')
+ { base = 8; /* could be octal */
+ p++;
+ switch (*p)
+ { case 'x':
+ case 'X':
+ base = 16; /* hex */
+ p++;
+ break;
#if BINARY
- case 'b':
- case 'B':
- base = 2; /* binary */
- p++;
- break;
+ case 'b':
+ case 'B':
+ base = 2; /* binary */
+ p++;
+ break;
#endif
- }
- }
- break;
- case 16: /* skip over '0x' and '0X' */
- if (*p == '0' && (p[1] == 'x' || p[1] == 'X'))
- p += 2;
- break;
+ }
+ }
+ break;
+ case 16: /* skip over '0x' and '0X' */
+ if (*p == '0' && (p[1] == 'x' || p[1] == 'X'))
+ p += 2;
+ break;
#if BINARY
- case 2: /* skip over '0b' and '0B' */
- if (*p == '0' && (p[1] == 'b' || p[1] == 'B'))
- p += 2;
- break;
+ case 2: /* skip over '0b' and '0B' */
+ if (*p == '0' && (p[1] == 'b' || p[1] == 'B'))
+ p += 2;
+ break;
#endif
}
error = 0;
for (;;)
{ c = *p;
- if (isdigit(c))
- c -= '0';
- else if (isalpha(c))
- c = (c & ~0x20) - ('A' - 10);
- else /* unrecognized character */
- break;
- if (c >= base) /* not in number base */
- break;
- if ((ULLONG_MAX - c) / base < number)
- error = 1;
- number = number * base + c;
- p++;
+ if (isdigit(c))
+ c -= '0';
+ else if (isalpha(c))
+ c = (c & ~0x20) - ('A' - 10);
+ else /* unrecognized character */
+ break;
+ if (c >= base) /* not in number base */
+ break;
+ if ((ULLONG_MAX - c) / base < number)
+ error = 1;
+ number = number * base + c;
+ p++;
}
if (pend)
- *pend = (char *)p;
+ *pend = (char *)p;
if (error)
{ number = ULLONG_MAX;
- errno = ERANGE;
+ errno = ERANGE;
}
return number;
}
@@ -287,12 +287,12 @@ double Port::ull_to_double(ulonglong ull)
if ((__int64) ull < 0)
{
- // MSVC doesn't implement the conversion
- d = (double) (__int64)(ull - 0x8000000000000000i64);
- d += (double)(signed __int64)(0x7FFFFFFFFFFFFFFFi64) + 1.0;
+ // MSVC doesn't implement the conversion
+ d = (double) (__int64)(ull - 0x8000000000000000i64);
+ d += (double)(signed __int64)(0x7FFFFFFFFFFFFFFFi64) + 1.0;
}
else
- d = (double)(__int64)ull;
+ d = (double)(__int64)ull;
return d;
}
@@ -351,14 +351,14 @@ PortInitializer::PortInitializer()
// constant folding.
volatile long double foo;
foo = NAN;
- if (signbit(foo)) // signbit sometimes, not always, set
- foo = -foo; // turn off sign bit
+ if (signbit(foo)) // signbit sometimes, not always, set
+ foo = -foo; // turn off sign bit
Port::nan = foo;
#if __FreeBSD__
// LDBL_MAX comes out as infinity. Fix.
static unsigned char x[sizeof(long double)] =
- { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x7F };
+ { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x7F };
Port::ldbl_max = *(long double *)&x[0];
#endif
}
@@ -479,11 +479,11 @@ const wchar_t *Port::wlist_separator()
char *Port::strupr(char *s)
{
char *t = s;
-
+
while (*s)
{
- *s = toupper(*s);
- s++;
+ *s = toupper(*s);
+ s++;
}
return t;
@@ -493,7 +493,7 @@ char *Port::strupr(char *s)
#if __sun&&__SVR4
-#define __C99FEATURES__ 1 // Needed on Solaris for NaN and more
+#define __C99FEATURES__ 1 // Needed on Solaris for NaN and more
#include
#include
#include
@@ -525,8 +525,8 @@ PortInitializer::PortInitializer()
// constant folding.
volatile long double foo;
foo = NAN;
- if (signbit(foo)) // signbit sometimes, not always, set
- foo = -foo; // turn off sign bit
+ if (signbit(foo)) // signbit sometimes, not always, set
+ foo = -foo; // turn off sign bit
Port::nan = foo;
}
@@ -618,11 +618,11 @@ const wchar_t *Port::wlist_separator()
char *Port::strupr(char *s)
{
char *t = s;
-
+
while (*s)
{
- *s = toupper(*s);
- s++;
+ *s = toupper(*s);
+ s++;
}
return t;
@@ -759,11 +759,11 @@ const wchar_t *Port::wlist_separator()
char *Port::strupr(char *s)
{
char *t = s;
-
+
while (*s)
{
- *s = toupper(*s);
- s++;
+ *s = toupper(*s);
+ s++;
}
return t;
diff --git a/dmd/root/root.c b/dmd/root/root.c
index 35ee8585..8b62ae5f 100644
--- a/dmd/root/root.c
+++ b/dmd/root/root.c
@@ -74,7 +74,7 @@ char *wchar2ascii(wchar_t *us, unsigned len)
p = (char *)mem.malloc(len + 1);
for (i = 0; i <= len; i++)
- p[i] = (char) us[i];
+ p[i] = (char) us[i];
return p;
}
@@ -89,8 +89,8 @@ int wcharIsAscii(wchar_t *us, unsigned len)
for (i = 0; i <= len; i++)
{
- if (us[i] & ~0xFF) // if high bits set
- return 0; // it's not ascii
+ if (us[i] & ~0xFF) // if high bits set
+ return 0; // it's not ascii
}
return 1;
}
@@ -249,34 +249,34 @@ hash_t String::calcHash(const char *str, size_t len)
for (;;)
{
- switch (len)
- {
- case 0:
- return hash;
+ switch (len)
+ {
+ case 0:
+ return hash;
- case 1:
- hash *= 37;
- hash += *(uint8_t *)str;
- return hash;
+ case 1:
+ hash *= 37;
+ hash += *(uint8_t *)str;
+ return hash;
- case 2:
- hash *= 37;
- hash += *(uint16_t *)str;
- return hash;
+ case 2:
+ hash *= 37;
+ hash += *(uint16_t *)str;
+ return hash;
- case 3:
- hash *= 37;
- hash += (*(uint16_t *)str << 8) +
- ((uint8_t *)str)[2];
- return hash;
+ case 3:
+ hash *= 37;
+ hash += (*(uint16_t *)str << 8) +
+ ((uint8_t *)str)[2];
+ return hash;
- default:
- hash *= 37;
- hash += *(uint32_t *)str;
- str += 4;
- len -= 4;
- break;
- }
+ default:
+ hash *= 37;
+ hash += *(uint32_t *)str;
+ str += 4;
+ len -= 4;
+ break;
+ }
}
}
@@ -329,22 +329,22 @@ char *FileName::combine(const char *path, const char *name)
size_t namelen;
if (!path || !*path)
- return (char *)name;
+ return (char *)name;
pathlen = strlen(path);
namelen = strlen(name);
f = (char *)mem.malloc(pathlen + 1 + namelen + 1);
memcpy(f, path, pathlen);
#if POSIX
if (path[pathlen - 1] != '/')
- { f[pathlen] = '/';
- pathlen++;
+ { f[pathlen] = '/';
+ pathlen++;
}
#elif _WIN32
if (path[pathlen - 1] != '\\' &&
- path[pathlen - 1] != '/' &&
- path[pathlen - 1] != ':')
- { f[pathlen] = '\\';
- pathlen++;
+ path[pathlen - 1] != '/' &&
+ path[pathlen - 1] != ':')
+ { f[pathlen] = '\\';
+ pathlen++;
}
#else
assert(0);
@@ -361,7 +361,7 @@ FileName::FileName(char *path, char *name)
// Split a path into an Array of paths
Array *FileName::splitPath(const char *path)
{
- char c = 0; // unnecessary initializer is for VC /W4
+ char c = 0; // unnecessary initializer is for VC /W4
const char *p;
OutBuffer buf;
Array *array;
@@ -369,72 +369,72 @@ Array *FileName::splitPath(const char *path)
array = new Array();
if (path)
{
- p = path;
- do
- { char instring = 0;
+ p = path;
+ do
+ { char instring = 0;
- while (isspace(*p)) // skip leading whitespace
- p++;
- buf.reserve(strlen(p) + 1); // guess size of path
+ while (isspace(*p)) // skip leading whitespace
+ p++;
+ buf.reserve(strlen(p) + 1); // guess size of path
// LDC remember first character
const char* start = p;
- for (; ; p++)
- {
- c = *p;
- switch (c)
- {
- case '"':
- instring ^= 1; // toggle inside/outside of string
- continue;
+ for (; ; p++)
+ {
+ c = *p;
+ switch (c)
+ {
+ case '"':
+ instring ^= 1; // toggle inside/outside of string
+ continue;
#if MACINTOSH
- case ',':
+ case ',':
#endif
#if _WIN32
- case ';':
+ case ';':
#endif
#if POSIX
- case ':':
+ case ':':
#endif
- p++;
- break; // note that ; cannot appear as part
- // of a path, quotes won't protect it
+ p++;
+ break; // note that ; cannot appear as part
+ // of a path, quotes won't protect it
- case 0x1A: // ^Z means end of file
- case 0:
- break;
+ case 0x1A: // ^Z means end of file
+ case 0:
+ break;
- case '\r':
- continue; // ignore carriage returns
+ case '\r':
+ continue; // ignore carriage returns
#if POSIX
- case '~':
+ case '~':
// LDC don't expand unless first character of path
if (p != start)
goto Ldefault;
- buf.writestring(getenv("HOME"));
- continue;
+ buf.writestring(getenv("HOME"));
+ continue;
#endif
#if 0
- case ' ':
- case '\t': // tabs in filenames?
- if (!instring) // if not in string
- break; // treat as end of path
+ case ' ':
+ case '\t': // tabs in filenames?
+ if (!instring) // if not in string
+ break; // treat as end of path
#endif
- default:
+ default:
Ldefault:
- buf.writeByte(c);
- continue;
- }
- break;
- }
- if (buf.offset) // if path is not empty
- {
- buf.writeByte(0); // to asciiz
- array->push(buf.extractData());
- }
- } while (c);
+ buf.writeByte(c);
+ continue;
+ }
+ break;
+ }
+ if (buf.offset) // if path is not empty
+ {
+ buf.writeByte(0); // to asciiz
+ array->push(buf.extractData());
+ }
+ } while (c);
}
return array;
}
@@ -449,34 +449,34 @@ hash_t FileName::hashCode()
for (;;)
{
- switch (len)
- {
- case 0:
- return hash;
+ switch (len)
+ {
+ case 0:
+ return hash;
- case 1:
- hash *= 37;
- hash += *(uint8_t *)s | 0x20;
- return hash;
+ case 1:
+ hash *= 37;
+ hash += *(uint8_t *)s | 0x20;
+ return hash;
- case 2:
- hash *= 37;
- hash += *(uint16_t *)s | 0x2020;
- return hash;
+ case 2:
+ hash *= 37;
+ hash += *(uint16_t *)s | 0x2020;
+ return hash;
- case 3:
- hash *= 37;
- hash += ((*(uint16_t *)s << 8) +
- ((uint8_t *)s)[2]) | 0x202020;
- break;
+ case 3:
+ hash *= 37;
+ hash += ((*(uint16_t *)s << 8) +
+ ((uint8_t *)s)[2]) | 0x202020;
+ break;
- default:
- hash *= 37;
- hash += *(uint32_t *)s | 0x20202020;
- s += 4;
- len -= 4;
- break;
- }
+ default:
+ hash *= 37;
+ hash += *(uint32_t *)s | 0x20202020;
+ s += 4;
+ len -= 4;
+ break;
+ }
}
#else
// darwin HFS is case insensitive, though...
@@ -516,8 +516,8 @@ int FileName::absolute(const char *name)
{
#if _WIN32
return (*name == '\\') ||
- (*name == '/') ||
- (*name && name[1] == ':');
+ (*name == '/') ||
+ (*name && name[1] == ':');
#elif POSIX
return (*name == '/');
#else
@@ -539,26 +539,26 @@ char *FileName::ext(const char *str)
e = (char *)str + len;
for (;;)
{
- switch (*e)
- { case '.':
- return e + 1;
+ switch (*e)
+ { case '.':
+ return e + 1;
#if POSIX
- case '/':
- break;
+ case '/':
+ break;
#endif
#if _WIN32
- case '\\':
- case ':':
- case '/':
- break;
+ case '\\':
+ case ':':
+ case '/':
+ break;
#endif
- default:
- if (e == str)
- break;
- e--;
- continue;
- }
- return NULL;
+ default:
+ if (e == str)
+ break;
+ e--;
+ continue;
+ }
+ return NULL;
}
}
@@ -575,11 +575,11 @@ char *FileName::removeExt(const char *str)
{
const char *e = ext(str);
if (e)
- { size_t len = (e - str) - 1;
- char *n = (char *)mem.malloc(len + 1);
- memcpy(n, str, len);
- n[len] = 0;
- return n;
+ { size_t len = (e - str) - 1;
+ char *n = (char *)mem.malloc(len + 1);
+ memcpy(n, str, len);
+ n[len] = 0;
+ return n;
}
return mem.strdup(str);
}
@@ -596,32 +596,32 @@ char *FileName::name(const char *str)
e = (char *)str + len;
for (;;)
{
- switch (*e)
- {
+ switch (*e)
+ {
#if POSIX
- case '/':
- return e + 1;
+ case '/':
+ return e + 1;
#endif
#if _WIN32
- case '/':
- case '\\':
- return e + 1;
- case ':':
- /* The ':' is a drive letter only if it is the second
- * character or the last character,
- * otherwise it is an ADS (Alternate Data Stream) separator.
- * Consider ADS separators as part of the file name.
- */
- if (e == str + 1 || e == str + len - 1)
- return e + 1;
+ case '/':
+ case '\\':
+ return e + 1;
+ case ':':
+ /* The ':' is a drive letter only if it is the second
+ * character or the last character,
+ * otherwise it is an ADS (Alternate Data Stream) separator.
+ * Consider ADS separators as part of the file name.
+ */
+ if (e == str + 1 || e == str + len - 1)
+ return e + 1;
#endif
- default:
- if (e == str)
- break;
- e--;
- continue;
- }
- return e;
+ default:
+ if (e == str)
+ break;
+ e--;
+ continue;
+ }
+ return e;
}
}
@@ -644,13 +644,13 @@ char *FileName::path(const char *str)
if (n > str)
{
#if POSIX
- if (n[-1] == '/')
- n--;
+ if (n[-1] == '/')
+ n--;
#elif _WIN32
- if (n[-1] == '\\' || n[-1] == '/')
- n--;
+ if (n[-1] == '\\' || n[-1] == '/')
+ n--;
#else
- assert(0);
+ assert(0);
#endif
}
pathlen = n - str;
@@ -671,26 +671,26 @@ const char *FileName::replaceName(const char *path, const char *name)
size_t namelen;
if (absolute(name))
- return name;
+ return name;
n = FileName::name(path);
if (n == path)
- return name;
+ return name;
pathlen = n - path;
namelen = strlen(name);
f = (char *)mem.malloc(pathlen + 1 + namelen + 1);
memcpy(f, path, pathlen);
#if POSIX
if (path[pathlen - 1] != '/')
- { f[pathlen] = '/';
- pathlen++;
+ { f[pathlen] = '/';
+ pathlen++;
}
#elif _WIN32
if (path[pathlen - 1] != '\\' &&
- path[pathlen - 1] != '/' &&
- path[pathlen - 1] != ':')
- { f[pathlen] = '\\';
- pathlen++;
+ path[pathlen - 1] != '/' &&
+ path[pathlen - 1] != ':')
+ { f[pathlen] = '\\';
+ pathlen++;
}
#else
assert(0);
@@ -710,8 +710,8 @@ FileName *FileName::defaultExt(const char *name, const char *ext)
size_t extlen;
e = FileName::ext(name);
- if (e) // if already has an extension
- return new FileName((char *)name, 0);
+ if (e) // if already has an extension
+ return new FileName((char *)name, 0);
len = strlen(name);
extlen = strlen(ext);
@@ -733,18 +733,18 @@ FileName *FileName::forceExt(const char *name, const char *ext)
size_t extlen;
e = FileName::ext(name);
- if (e) // if already has an extension
+ if (e) // if already has an extension
{
- len = e - name;
- extlen = strlen(ext);
+ len = e - name;
+ extlen = strlen(ext);
- s = (char *)alloca(len + extlen + 1);
- memcpy(s,name,len);
- memcpy(s + len, ext, extlen + 1);
- return new FileName(s, 0);
+ s = (char *)alloca(len + extlen + 1);
+ memcpy(s,name,len);
+ memcpy(s + len, ext, extlen + 1);
+ return new FileName(s, 0);
}
else
- return defaultExt(name, ext); // doesn't have one
+ return defaultExt(name, ext); // doesn't have one
}
/******************************
@@ -756,9 +756,9 @@ int FileName::equalsExt(const char *ext)
e = FileName::ext();
if (!e && !ext)
- return 1;
+ return 1;
if (!e || !ext)
- return 0;
+ return 0;
#if POSIX
return strcmp(e,ext) == 0;
#elif _WIN32
@@ -777,7 +777,7 @@ void FileName::CopyTo(FileName *to)
File file(this);
#if _WIN32
- file.touchtime = mem.malloc(sizeof(WIN32_FIND_DATAA)); // keep same file time
+ file.touchtime = mem.malloc(sizeof(WIN32_FIND_DATAA)); // keep same file time
#elif POSIX
file.touchtime = mem.malloc(sizeof(struct stat)); // keep same file time
#else
@@ -791,31 +791,31 @@ void FileName::CopyTo(FileName *to)
/*************************************
* Search Path for file.
* Input:
- * cwd if !=0, search current directory before searching path
+ * cwd if !=0, search current directory before searching path
*/
char *FileName::searchPath(Array *path, const char *name, int cwd)
{
if (absolute(name))
{
- return exists(name) ? (char *)name : NULL;
+ return exists(name) ? (char *)name : NULL;
}
if (cwd)
{
- if (exists(name))
- return (char *)name;
+ if (exists(name))
+ return (char *)name;
}
if (path)
- { unsigned i;
+ { unsigned i;
- for (i = 0; i < path->dim; i++)
- {
- char *p = (char *)path->data[i];
- char *n = combine(p, name);
+ for (i = 0; i < path->dim; i++)
+ {
+ char *p = (char *)path->data[i];
+ char *n = combine(p, name);
- if (exists(n))
- return n;
- }
+ if (exists(n))
+ return n;
+ }
}
return NULL;
}
@@ -826,12 +826,12 @@ char *FileName::searchPath(Array *path, const char *name, int cwd)
*
* Be wary of CWE-22: Improper Limitation of a Pathname to a Restricted Directory
* ('Path Traversal') attacks.
- * http://cwe.mitre.org/data/definitions/22.html
+ * http://cwe.mitre.org/data/definitions/22.html
* More info:
- * https://www.securecoding.cert.org/confluence/display/seccode/FIO02-C.+Canonicalize+path+names+originating+from+untrusted+sources
+ * https://www.securecoding.cert.org/confluence/display/seccode/FIO02-C.+Canonicalize+path+names+originating+from+untrusted+sources
* Returns:
- * NULL file not found
- * !=NULL mem.malloc'd file name
+ * NULL file not found
+ * !=NULL mem.malloc'd file name
*/
char *FileName::safeSearchPath(Array *path, const char *name)
@@ -841,12 +841,12 @@ char *FileName::safeSearchPath(Array *path, const char *name)
*/
for (const char *p = name; *p; p++)
{
- char c = *p;
- if (c == '\\' || c == '/' || c == ':' || c == '%' ||
- (c == '.' && p[1] == '.'))
- {
- return NULL;
- }
+ char c = *p;
+ if (c == '\\' || c == '/' || c == ':' || c == '%' ||
+ (c == '.' && p[1] == '.'))
+ {
+ return NULL;
+ }
}
return FileName::searchPath(path, name, 0);
@@ -855,48 +855,48 @@ char *FileName::safeSearchPath(Array *path, const char *name)
*/
for (const char *p = name; *p; p++)
{
- char c = *p;
- if (c == '/' && p[1] == '/')
- {
- return NULL;
- }
+ char c = *p;
+ if (c == '/' && p[1] == '/')
+ {
+ return NULL;
+ }
}
if (path)
- { unsigned i;
+ { unsigned i;
- /* Each path is converted to a cannonical name and then a check is done to see
- * that the searched name is really a child one of the the paths searched.
- */
- for (i = 0; i < path->dim; i++)
- {
- char *cname = NULL;
- char *cpath = canonicalName((char *)path->data[i]);
- //printf("FileName::safeSearchPath(): name=%s; path=%s; cpath=%s\n",
- // name, (char *)path->data[i], cpath);
- if (cpath == NULL)
- goto cont;
- cname = canonicalName(combine(cpath, name));
- //printf("FileName::safeSearchPath(): cname=%s\n", cname);
- if (cname == NULL)
- goto cont;
- //printf("FileName::safeSearchPath(): exists=%i "
- // "strncmp(cpath, cname, %i)=%i\n", exists(cname),
- // strlen(cpath), strncmp(cpath, cname, strlen(cpath)));
- // exists and name is *really* a "child" of path
- if (exists(cname) && strncmp(cpath, cname, strlen(cpath)) == 0)
- {
- free(cpath);
- char *p = mem.strdup(cname);
- free(cname);
- return p;
- }
+ /* Each path is converted to a cannonical name and then a check is done to see
+ * that the searched name is really a child one of the the paths searched.
+ */
+ for (i = 0; i < path->dim; i++)
+ {
+ char *cname = NULL;
+ char *cpath = canonicalName((char *)path->data[i]);
+ //printf("FileName::safeSearchPath(): name=%s; path=%s; cpath=%s\n",
+ // name, (char *)path->data[i], cpath);
+ if (cpath == NULL)
+ goto cont;
+ cname = canonicalName(combine(cpath, name));
+ //printf("FileName::safeSearchPath(): cname=%s\n", cname);
+ if (cname == NULL)
+ goto cont;
+ //printf("FileName::safeSearchPath(): exists=%i "
+ // "strncmp(cpath, cname, %i)=%i\n", exists(cname),
+ // strlen(cpath), strncmp(cpath, cname, strlen(cpath)));
+ // exists and name is *really* a "child" of path
+ if (exists(cname) && strncmp(cpath, cname, strlen(cpath)) == 0)
+ {
+ free(cpath);
+ char *p = mem.strdup(cname);
+ free(cname);
+ return p;
+ }
cont:
- if (cpath)
- free(cpath);
- if (cname)
- free(cname);
- }
+ if (cpath)
+ free(cpath);
+ if (cname)
+ free(cname);
+ }
}
return NULL;
#else
@@ -911,9 +911,9 @@ int FileName::exists(const char *name)
struct stat st;
if (stat(name, &st) < 0)
- return 0;
+ return 0;
if (S_ISDIR(st.st_mode))
- return 2;
+ return 2;
return 1;
#elif _WIN32
DWORD dw;
@@ -921,11 +921,11 @@ int FileName::exists(const char *name)
dw = GetFileAttributesA(name);
if (dw == -1L)
- result = 0;
+ result = 0;
else if (dw & FILE_ATTRIBUTE_DIRECTORY)
- result = 2;
+ result = 2;
else
- result = 1;
+ result = 1;
return result;
#else
assert(0);
@@ -937,38 +937,38 @@ void FileName::ensurePathExists(const char *path)
//printf("FileName::ensurePathExists(%s)\n", path ? path : "");
if (path && *path)
{
- if (!exists(path))
- {
- char *p = FileName::path(path);
- if (*p)
- {
+ if (!exists(path))
+ {
+ char *p = FileName::path(path);
+ if (*p)
+ {
#if _WIN32
- size_t len = strlen(path);
- if (len > 2 && p[-1] == ':' && path + 2 == p)
- { mem.free(p);
- return;
- }
+ size_t len = strlen(path);
+ if (len > 2 && p[-1] == ':' && path + 2 == p)
+ { mem.free(p);
+ return;
+ }
#endif
- ensurePathExists(p);
- mem.free(p);
- }
+ ensurePathExists(p);
+ mem.free(p);
+ }
#if _WIN32
- if (path[strlen(path) - 1] != '\\')
+ if (path[strlen(path) - 1] != '\\')
#endif
#if POSIX
- if (path[strlen(path) - 1] != '\\')
+ if (path[strlen(path) - 1] != '\\')
#endif
- {
- //printf("mkdir(%s)\n", path);
+ {
+ //printf("mkdir(%s)\n", path);
#if _WIN32
- if (mkdir(path))
+ if (mkdir(path))
#endif
#if POSIX
- if (mkdir(path, 0777))
+ if (mkdir(path, 0777))
#endif
- error("cannot create directory %s", path);
- }
- }
+ error("cannot create directory %s", path);
+ }
+ }
}
}
@@ -989,19 +989,19 @@ char *FileName::canonicalName(const char *name)
#else
char *cname = NULL;
#if PATH_MAX
- /* PATH_MAX must be defined as a constant in ,
- * otherwise using it is unsafe due to TOCTOU
- */
- size_t path_max = (size_t)PATH_MAX;
- if (path_max > 0)
- {
- /* Need to add one to PATH_MAX because of realpath() buffer overflow bug:
- * http://isec.pl/vulnerabilities/isec-0011-wu-ftpd.txt
- */
- cname = (char *)malloc(path_max + 1);
- if (cname == NULL)
- return NULL;
- }
+ /* PATH_MAX must be defined as a constant in ,
+ * otherwise using it is unsafe due to TOCTOU
+ */
+ size_t path_max = (size_t)PATH_MAX;
+ if (path_max > 0)
+ {
+ /* Need to add one to PATH_MAX because of realpath() buffer overflow bug:
+ * http://isec.pl/vulnerabilities/isec-0011-wu-ftpd.txt
+ */
+ cname = (char *)malloc(path_max + 1);
+ if (cname == NULL)
+ return NULL;
+ }
#endif
return realpath(name, cname);
#endif
@@ -1042,15 +1042,15 @@ File::~File()
{
if (buffer)
{
- if (ref == 0)
- mem.free(buffer);
+ if (ref == 0)
+ mem.free(buffer);
#if _WIN32
- else if (ref == 2)
- UnmapViewOfFile(buffer);
+ else if (ref == 2)
+ UnmapViewOfFile(buffer);
#endif
}
if (touchtime)
- mem.free(touchtime);
+ mem.free(touchtime);
}
void File::mark()
@@ -1077,34 +1077,34 @@ int File::read()
//printf("File::read('%s')\n",name);
fd = open(name, O_RDONLY);
if (fd == -1)
- { result = errno;
- //printf("\topen error, errno = %d\n",errno);
- goto err1;
+ { result = errno;
+ //printf("\topen error, errno = %d\n",errno);
+ goto err1;
}
if (!ref)
- mem.free(buffer);
+ mem.free(buffer);
ref = 0; // we own the buffer now
//printf("\tfile opened\n");
if (fstat(fd, &buf))
{
- printf("\tfstat error, errno = %d\n",errno);
+ printf("\tfstat error, errno = %d\n",errno);
goto err2;
}
size = buf.st_size;
buffer = (unsigned char *) mem.malloc(size + 2);
if (!buffer)
{
- printf("\tmalloc error, errno = %d\n",errno);
- goto err2;
+ printf("\tmalloc error, errno = %d\n",errno);
+ goto err2;
}
numread = ::read(fd, buffer, size);
if (numread != size)
{
- printf("\tread error, errno = %d\n",errno);
- goto err2;
+ printf("\tread error, errno = %d\n",errno);
+ goto err2;
}
if (touchtime)
@@ -1112,14 +1112,14 @@ int File::read()
if (close(fd) == -1)
{
- printf("\tclose error, errno = %d\n",errno);
- goto err;
+ printf("\tclose error, errno = %d\n",errno);
+ goto err;
}
len = size;
// Always store a wchar ^Z past end of buffer so scanner has a sentinel
- buffer[size] = 0; // ^Z is obsolete, use 0
+ buffer[size] = 0; // ^Z is obsolete, use 0
buffer[size + 1] = 0;
return 0;
@@ -1142,38 +1142,38 @@ err1:
name = this->name->toChars();
h = CreateFileA(name,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,0);
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,0);
if (h == INVALID_HANDLE_VALUE)
- goto err1;
+ goto err1;
if (!ref)
- mem.free(buffer);
+ mem.free(buffer);
ref = 0;
size = GetFileSize(h,NULL);
buffer = (unsigned char *) mem.malloc(size + 2);
if (!buffer)
- goto err2;
+ goto err2;
if (ReadFile(h,buffer,size,&numread,NULL) != TRUE)
- goto err2;
+ goto err2;
if (numread != size)
- goto err2;
+ goto err2;
if (touchtime)
{
- if (!GetFileTime(h, NULL, NULL, &((WIN32_FIND_DATAA *)touchtime)->ftLastWriteTime))
- goto err2;
+ if (!GetFileTime(h, NULL, NULL, &((WIN32_FIND_DATAA *)touchtime)->ftLastWriteTime))
+ goto err2;
}
if (!CloseHandle(h))
- goto err;
+ goto err;
len = size;
// Always store a wchar ^Z past end of buffer so scanner has a sentinel
- buffer[size] = 0; // ^Z is obsolete, use 0
+ buffer[size] = 0; // ^Z is obsolete, use 0
buffer[size + 1] = 0;
return 0;
@@ -1208,30 +1208,30 @@ int File::mmread()
name = this->name->toChars();
hFile = CreateFile(name, GENERIC_READ,
- FILE_SHARE_READ, NULL,
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
- goto Lerr;
+ goto Lerr;
size = GetFileSize(hFile, NULL);
//printf(" file created, size %d\n", size);
hFileMap = CreateFileMapping(hFile,NULL,PAGE_READONLY,0,size,NULL);
if (CloseHandle(hFile) != TRUE)
- goto Lerr;
+ goto Lerr;
if (hFileMap == NULL)
- goto Lerr;
+ goto Lerr;
//printf(" mapping created\n");
if (!ref)
- mem.free(buffer);
+ mem.free(buffer);
ref = 2;
buffer = (unsigned char *)MapViewOfFileEx(hFileMap, FILE_MAP_READ,0,0,size,NULL);
if (CloseHandle(hFileMap) != TRUE)
- goto Lerr;
- if (buffer == NULL) // mapping view failed
- goto Lerr;
+ goto Lerr;
+ if (buffer == NULL) // mapping view failed
+ goto Lerr;
len = size;
//printf(" buffer = %p\n", buffer);
@@ -1239,7 +1239,7 @@ int File::mmread()
return 0;
Lerr:
- return GetLastError(); // failure
+ return GetLastError(); // failure
#else
assert(0);
#endif
@@ -1248,7 +1248,7 @@ Lerr:
/*********************************************
* Write a file.
* Returns:
- * 0 success
+ * 0 success
*/
int File::write()
@@ -1261,22 +1261,22 @@ int File::write()
name = this->name->toChars();
fd = open(name, O_CREAT | O_WRONLY | O_TRUNC, 0644);
if (fd == -1)
- goto err;
+ goto err;
numwritten = ::write(fd, buffer, len);
if (len != numwritten)
- goto err2;
-
+ goto err2;
+
if (close(fd) == -1)
- goto err;
+ goto err;
if (touchtime)
{ struct utimbuf ubuf;
ubuf.actime = ((struct stat *)touchtime)->st_atime;
ubuf.modtime = ((struct stat *)touchtime)->st_mtime;
- if (utime(name, &ubuf))
- goto err;
+ if (utime(name, &ubuf))
+ goto err;
}
return 0;
@@ -1292,21 +1292,21 @@ err:
name = this->name->toChars();
h = CreateFileA(name,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL);
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL);
if (h == INVALID_HANDLE_VALUE)
- goto err;
+ goto err;
if (WriteFile(h,buffer,len,&numwritten,NULL) != TRUE)
- goto err2;
+ goto err2;
if (len != numwritten)
- goto err2;
-
+ goto err2;
+
if (touchtime) {
SetFileTime(h, NULL, NULL, &((WIN32_FIND_DATAA *)touchtime)->ftLastWriteTime);
}
if (!CloseHandle(h))
- goto err;
+ goto err;
return 0;
err2:
@@ -1322,7 +1322,7 @@ err:
/*********************************************
* Append to a file.
* Returns:
- * 0 success
+ * 0 success
*/
int File::append()
@@ -1336,28 +1336,28 @@ int File::append()
name = this->name->toChars();
h = CreateFileA(name,GENERIC_WRITE,0,NULL,OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL);
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL);
if (h == INVALID_HANDLE_VALUE)
- goto err;
+ goto err;
#if 1
SetFilePointer(h, 0, NULL, FILE_END);
#else // INVALID_SET_FILE_POINTER doesn't seem to have a definition
if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
- goto err;
+ goto err;
#endif
if (WriteFile(h,buffer,len,&numwritten,NULL) != TRUE)
- goto err2;
+ goto err2;
if (len != numwritten)
- goto err2;
-
+ goto err2;
+
if (touchtime) {
SetFileTime(h, NULL, NULL, &((WIN32_FIND_DATAA *)touchtime)->ftLastWriteTime);
}
if (!CloseHandle(h))
- goto err;
+ goto err;
return 0;
err2:
@@ -1375,7 +1375,7 @@ err:
void File::readv()
{
if (read())
- error("Error reading file '%s'\n",name->toChars());
+ error("Error reading file '%s'\n",name->toChars());
}
/**************************************
@@ -1384,26 +1384,26 @@ void File::readv()
void File::mmreadv()
{
if (mmread())
- readv();
+ readv();
}
void File::writev()
{
if (write())
- error("Error writing file '%s'\n",name->toChars());
+ error("Error writing file '%s'\n",name->toChars());
}
void File::appendv()
{
if (write())
- error("Error appending to file '%s'\n",name->toChars());
+ error("Error appending to file '%s'\n",name->toChars());
}
/*******************************************
* Return !=0 if file exists.
- * 0: file doesn't exist
- * 1: normal file
- * 2: directory
+ * 0: file doesn't exist
+ * 1: normal file
+ * 2: directory
*/
int File::exists()
@@ -1417,15 +1417,15 @@ int File::exists()
name = this->name->toChars();
if (touchtime)
- dw = ((WIN32_FIND_DATAA *)touchtime)->dwFileAttributes;
+ dw = ((WIN32_FIND_DATAA *)touchtime)->dwFileAttributes;
else
- dw = GetFileAttributesA(name);
+ dw = GetFileAttributesA(name);
if (dw == -1L)
- result = 0;
+ result = 0;
else if (dw & FILE_ATTRIBUTE_DIRECTORY)
- result = 2;
+ result = 2;
else
- result = 1;
+ result = 1;
return result;
#else
assert(0);
@@ -1465,21 +1465,21 @@ Array *File::match(FileName *n)
h = FindFirstFileA(c,&fileinfo);
if (h != INVALID_HANDLE_VALUE)
{
- do
- {
- // Glue path together with name
- char *fn;
- File *f;
+ do
+ {
+ // Glue path together with name
+ char *fn;
+ File *f;
- fn = (char *)mem.malloc(name - c + strlen(fileinfo.cFileName) + 1);
- memcpy(fn, c, name - c);
- strcpy(fn + (name - c), fileinfo.cFileName);
- f = new File(fn);
- f->touchtime = mem.malloc(sizeof(WIN32_FIND_DATAA));
- memcpy(f->touchtime, &fileinfo, sizeof(fileinfo));
- a->push(f);
- } while (FindNextFileA(h,&fileinfo) != FALSE);
- FindClose(h);
+ fn = (char *)mem.malloc(name - c + strlen(fileinfo.cFileName) + 1);
+ memcpy(fn, c, name - c);
+ strcpy(fn + (name - c), fileinfo.cFileName);
+ f = new File(fn);
+ f->touchtime = mem.malloc(sizeof(WIN32_FIND_DATAA));
+ memcpy(f->touchtime, &fileinfo, sizeof(fileinfo));
+ a->push(f);
+ } while (FindNextFileA(h,&fileinfo) != FALSE);
+ FindClose(h);
}
return a;
#else
@@ -1493,9 +1493,9 @@ int File::compareTime(File *f)
return 0;
#elif _WIN32
if (!touchtime)
- stat();
+ stat();
if (!f->touchtime)
- f->stat();
+ f->stat();
return CompareFileTime(&((WIN32_FIND_DATAA *)touchtime)->ftLastWriteTime, &((WIN32_FIND_DATAA *)f->touchtime)->ftLastWriteTime);
#else
assert(0);
@@ -1507,19 +1507,19 @@ void File::stat()
#if POSIX
if (!touchtime)
{
- touchtime = mem.calloc(1, sizeof(struct stat));
+ touchtime = mem.calloc(1, sizeof(struct stat));
}
#elif _WIN32
HANDLE h;
if (!touchtime)
{
- touchtime = mem.calloc(1, sizeof(WIN32_FIND_DATAA));
+ touchtime = mem.calloc(1, sizeof(WIN32_FIND_DATAA));
}
h = FindFirstFileA(name->toChars(),(WIN32_FIND_DATAA *)touchtime);
if (h != INVALID_HANDLE_VALUE)
{
- FindClose(h);
+ FindClose(h);
}
#else
assert(0);
@@ -1529,7 +1529,7 @@ void File::stat()
void File::checkoffset(size_t offset, size_t nbytes)
{
if (offset > len || offset + nbytes > len)
- error("Corrupt file '%s': offset x%zx off end of file",toChars(),offset);
+ error("Corrupt file '%s': offset x%zx off end of file",toChars(),offset);
}
char *File::toChars()
@@ -1574,11 +1574,11 @@ void OutBuffer::reserve(unsigned nbytes)
if (size - offset < nbytes)
{
#if defined (__x86_64__)
- size = (offset + nbytes) * 2 + 2;
+ size = (offset + nbytes) * 2 + 2;
#else
- size = (offset + nbytes) * 2;
+ size = (offset + nbytes) * 2;
#endif
- data = (unsigned char *)mem.realloc(data, size);
+ data = (unsigned char *)mem.realloc(data, size);
}
}
@@ -1614,7 +1614,7 @@ void OutBuffer::writedstring(const char *string)
#if M_UNICODE
for (; *string; string++)
{
- writedchar(*string);
+ writedchar(*string);
}
#else
write(string,strlen(string));
@@ -1628,7 +1628,7 @@ void OutBuffer::writedstring(const wchar_t *string)
#else
for (; *string; string++)
{
- writedchar(*string);
+ writedchar(*string);
}
#endif
}
@@ -1647,9 +1647,9 @@ void OutBuffer::writenl()
{
#if _WIN32
#if M_UNICODE
- write4(0x000A000D); // newline is CR,LF on Microsoft OS's
+ write4(0x000A000D); // newline is CR,LF on Microsoft OS's
#else
- writeword(0x0A0D); // newline is CR,LF on Microsoft OS's
+ writeword(0x0A0D); // newline is CR,LF on Microsoft OS's
#endif
#else
#if M_UNICODE
@@ -1672,58 +1672,58 @@ void OutBuffer::writeUTF8(unsigned b)
reserve(6);
if (b <= 0x7F)
{
- this->data[offset] = (unsigned char)b;
- offset++;
+ this->data[offset] = (unsigned char)b;
+ offset++;
}
else if (b <= 0x7FF)
{
- this->data[offset + 0] = (unsigned char)((b >> 6) | 0xC0);
- this->data[offset + 1] = (unsigned char)((b & 0x3F) | 0x80);
- offset += 2;
+ this->data[offset + 0] = (unsigned char)((b >> 6) | 0xC0);
+ this->data[offset + 1] = (unsigned char)((b & 0x3F) | 0x80);
+ offset += 2;
}
else if (b <= 0xFFFF)
{
- this->data[offset + 0] = (unsigned char)((b >> 12) | 0xE0);
- this->data[offset + 1] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
- this->data[offset + 2] = (unsigned char)((b & 0x3F) | 0x80);
- offset += 3;
+ this->data[offset + 0] = (unsigned char)((b >> 12) | 0xE0);
+ this->data[offset + 1] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
+ this->data[offset + 2] = (unsigned char)((b & 0x3F) | 0x80);
+ offset += 3;
}
else if (b <= 0x1FFFFF)
{
- this->data[offset + 0] = (unsigned char)((b >> 18) | 0xF0);
- this->data[offset + 1] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
- this->data[offset + 2] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
- this->data[offset + 3] = (unsigned char)((b & 0x3F) | 0x80);
- offset += 4;
+ this->data[offset + 0] = (unsigned char)((b >> 18) | 0xF0);
+ this->data[offset + 1] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
+ this->data[offset + 2] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
+ this->data[offset + 3] = (unsigned char)((b & 0x3F) | 0x80);
+ offset += 4;
}
else if (b <= 0x3FFFFFF)
{
- this->data[offset + 0] = (unsigned char)((b >> 24) | 0xF8);
- this->data[offset + 1] = (unsigned char)(((b >> 18) & 0x3F) | 0x80);
- this->data[offset + 2] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
- this->data[offset + 3] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
- this->data[offset + 4] = (unsigned char)((b & 0x3F) | 0x80);
- offset += 5;
+ this->data[offset + 0] = (unsigned char)((b >> 24) | 0xF8);
+ this->data[offset + 1] = (unsigned char)(((b >> 18) & 0x3F) | 0x80);
+ this->data[offset + 2] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
+ this->data[offset + 3] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
+ this->data[offset + 4] = (unsigned char)((b & 0x3F) | 0x80);
+ offset += 5;
}
else if (b <= 0x7FFFFFFF)
{
- this->data[offset + 0] = (unsigned char)((b >> 30) | 0xFC);
- this->data[offset + 1] = (unsigned char)(((b >> 24) & 0x3F) | 0x80);
- this->data[offset + 2] = (unsigned char)(((b >> 18) & 0x3F) | 0x80);
- this->data[offset + 3] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
- this->data[offset + 4] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
- this->data[offset + 5] = (unsigned char)((b & 0x3F) | 0x80);
- offset += 6;
+ this->data[offset + 0] = (unsigned char)((b >> 30) | 0xFC);
+ this->data[offset + 1] = (unsigned char)(((b >> 24) & 0x3F) | 0x80);
+ this->data[offset + 2] = (unsigned char)(((b >> 18) & 0x3F) | 0x80);
+ this->data[offset + 3] = (unsigned char)(((b >> 12) & 0x3F) | 0x80);
+ this->data[offset + 4] = (unsigned char)(((b >> 6) & 0x3F) | 0x80);
+ this->data[offset + 5] = (unsigned char)((b & 0x3F) | 0x80);
+ offset += 6;
}
else
- assert(0);
+ assert(0);
}
void OutBuffer::writedchar(unsigned b)
{
reserve(Dchar_mbmax * sizeof(dchar));
offset = (unsigned char *)Dchar::put((dchar *)(this->data + offset), (dchar)b) -
- this->data;
+ this->data;
}
void OutBuffer::prependbyte(unsigned b)
@@ -1746,17 +1746,17 @@ void OutBuffer::writeUTF16(unsigned w)
reserve(4);
if (w <= 0xFFFF)
{
- *(unsigned short *)(this->data + offset) = (unsigned short)w;
- offset += 2;
+ *(unsigned short *)(this->data + offset) = (unsigned short)w;
+ offset += 2;
}
else if (w <= 0x10FFFF)
{
- *(unsigned short *)(this->data + offset) = (unsigned short)((w >> 10) + 0xD7C0);
- *(unsigned short *)(this->data + offset + 2) = (unsigned short)((w & 0x3FF) | 0xDC00);
- offset += 4;
+ *(unsigned short *)(this->data + offset) = (unsigned short)((w >> 10) + 0xD7C0);
+ *(unsigned short *)(this->data + offset + 2) = (unsigned short)((w & 0x3FF) | 0xDC00);
+ offset += 4;
}
else
- assert(0);
+ assert(0);
}
void OutBuffer::write4(unsigned w)
@@ -1769,9 +1769,9 @@ void OutBuffer::write4(unsigned w)
void OutBuffer::write(OutBuffer *buf)
{
if (buf)
- { reserve(buf->offset);
- memcpy(data + offset, buf->data, buf->offset);
- offset += buf->offset;
+ { reserve(buf->offset);
+ memcpy(data + offset, buf->data, buf->offset);
+ offset += buf->offset;
}
}
@@ -1779,7 +1779,7 @@ void OutBuffer::write(Object *obj)
{
if (obj)
{
- writestring(obj->toChars());
+ writestring(obj->toChars());
}
}
@@ -1807,12 +1807,12 @@ using std::string;
using std::wstring;
template
-inline void
+inline void
search_and_replace(S& str, const S& what, const S& replacement)
{
assert(!what.empty());
size_t pos = str.find(what);
- while (pos != S::npos)
+ while (pos != S::npos)
{
str.replace(pos, what.size(), replacement);
pos = str.find(what, pos + replacement.size());
@@ -1841,10 +1841,10 @@ void OutBuffer::vprintf(const char *format, va_list args)
for (;;)
{
#if _WIN32
- count = _vsnprintf(p,psize,format,args);
- if (count != -1)
- break;
- psize *= 2;
+ count = _vsnprintf(p,psize,format,args);
+ if (count != -1)
+ break;
+ psize *= 2;
#elif POSIX
va_list va;
va_copy(va, args);
@@ -1857,18 +1857,18 @@ void OutBuffer::vprintf(const char *format, va_list args)
of ap is undefined after the call. The application should call
va_end(ap) itself afterwards.
*/
- count = vsnprintf(p,psize,format,va);
+ count = vsnprintf(p,psize,format,va);
va_end(va);
- if (count == -1)
- psize *= 2;
- else if (count >= psize)
- psize = count + 1;
- else
- break;
+ if (count == -1)
+ psize *= 2;
+ else if (count >= psize)
+ psize = count + 1;
+ else
+ break;
#else
assert(0);
#endif
- p = (char *) alloca(psize); // buffer too small, try again with larger size
+ p = (char *) alloca(psize); // buffer too small, try again with larger size
}
write(p,count);
}
@@ -1888,26 +1888,26 @@ void OutBuffer::vprintf(const wchar_t *format, va_list args)
for (;;)
{
#if _WIN32
- count = _vsnwprintf(p,psize,format,args);
- if (count != -1)
- break;
- psize *= 2;
+ count = _vsnwprintf(p,psize,format,args);
+ if (count != -1)
+ break;
+ psize *= 2;
#elif POSIX
va_list va;
va_copy(va, args);
- count = vsnwprintf(p,psize,format,va);
- va_end(va);
+ count = vsnwprintf(p,psize,format,va);
+ va_end(va);
- if (count == -1)
- psize *= 2;
- else if (count >= psize)
- psize = count + 1;
- else
- break;
+ if (count == -1)
+ psize *= 2;
+ else if (count >= psize)
+ psize = count + 1;
+ else
+ break;
#else
assert(0);
#endif
- p = (dchar *) alloca(psize * 2); // buffer too small, try again with larger size
+ p = (dchar *) alloca(psize * 2); // buffer too small, try again with larger size
}
write(p,count * 2);
}
@@ -1959,7 +1959,7 @@ void OutBuffer::spread(unsigned offset, unsigned nbytes)
{
reserve(nbytes);
memmove(data + offset + nbytes, data + offset,
- this->offset - offset);
+ this->offset - offset);
this->offset += nbytes;
}
@@ -2013,12 +2013,12 @@ void Bits::resize(unsigned bitdim)
allocdim = (bitdim + 31) / 32;
data = (unsigned *)mem.realloc(data, allocdim * sizeof(data[0]));
if (this->allocdim < allocdim)
- memset(data + this->allocdim, 0, (allocdim - this->allocdim) * sizeof(data[0]));
+ memset(data + this->allocdim, 0, (allocdim - this->allocdim) * sizeof(data[0]));
// Clear other bits in last word
mask = (1 << (bitdim & 31)) - 1;
if (mask)
- data[allocdim - 1] &= ~mask;
+ data[allocdim - 1] &= ~mask;
this->bitdim = bitdim;
this->allocdim = allocdim;
@@ -2047,7 +2047,7 @@ void Bits::set()
// Clear other bits in last word
mask = (1 << (bitdim & 31)) - 1;
if (mask)
- data[allocdim - 1] &= mask;
+ data[allocdim - 1] &= mask;
}
void Bits::clear()
@@ -2076,7 +2076,7 @@ void Bits::sub(Bits *b)
unsigned u;
for (u = 0; u < allocdim; u++)
- data[u] &= ~b->data[u];
+ data[u] &= ~b->data[u];
}
diff --git a/dmd/root/root.h b/dmd/root/root.h
index 0ec30515..f74bf88a 100644
--- a/dmd/root/root.h
+++ b/dmd/root/root.h
@@ -106,14 +106,14 @@ struct Object
/**
* Marks pointers for garbage collector by calling mem.mark() for all pointers into heap.
*/
- /*virtual*/ // not used, disable for now
- void mark();
+ /*virtual*/ // not used, disable for now
+ void mark();
};
struct String : Object
{
- int ref; // != 0 if this is a reference to someone else's string
- char *str; // the string itself
+ int ref; // != 0 if this is a reference to someone else's string
+ char *str; // the string itself
String(char *str, int ref = 1);
@@ -164,12 +164,12 @@ struct FileName : String
struct File : Object
{
- int ref; // != 0 if this is a reference to someone else's buffer
- unsigned char *buffer; // data for our file
- unsigned len; // amount of data in buffer[]
- void *touchtime; // system time to use for file
+ int ref; // != 0 if this is a reference to someone else's buffer
+ unsigned char *buffer; // data for our file
+ unsigned len; // amount of data in buffer[]
+ void *touchtime; // system time to use for file
- FileName *name; // name of our file
+ FileName *name; // name of our file
File(char *);
File(FileName *);
@@ -213,9 +213,9 @@ struct File : Object
void writev();
/* Return !=0 if file exists.
- * 0: file doesn't exist
- * 1: normal file
- * 2: directory
+ * 0: file doesn't exist
+ * 1: normal file
+ * 2: directory
*/
/* Append to file, return !=0 if error
@@ -230,9 +230,9 @@ struct File : Object
void appendv();
/* Return !=0 if file exists.
- * 0: file doesn't exist
- * 1: normal file
- * 2: directory
+ * 0: file doesn't exist
+ * 1: normal file
+ * 2: directory
*/
int exists();
@@ -245,9 +245,9 @@ struct File : Object
static Array *match(FileName *);
// Compare file times.
- // Return <0 this < f
- // =0 this == f
- // >0 this > f
+ // Return <0 this < f
+ // =0 this == f
+ // >0 this > f
int compareTime(File *f);
// Read system file statistics
@@ -258,13 +258,13 @@ struct File : Object
void setbuffer(void *buffer, unsigned len)
{
- this->buffer = (unsigned char *)buffer;
- this->len = len;
+ this->buffer = (unsigned char *)buffer;
+ this->len = len;
}
void checkoffset(size_t offset, size_t nbytes);
- void remove(); // delete file
+ void remove(); // delete file
};
struct OutBuffer : Object
@@ -287,7 +287,7 @@ struct OutBuffer : Object
void writedstring(const char *string);
void writedstring(const wchar_t *string);
void prependstring(const char *string);
- void writenl(); // write newline
+ void writenl(); // write newline
void writeByte(unsigned b);
void writebyte(unsigned b) { writeByte(b); }
void writeUTF8(unsigned b);
diff --git a/dmd/root/stringtable.c b/dmd/root/stringtable.c
index 0bc63034..2f54852a 100644
--- a/dmd/root/stringtable.c
+++ b/dmd/root/stringtable.c
@@ -32,7 +32,7 @@ StringTable::~StringTable()
// Zero out dangling pointers to help garbage collector.
// Should zero out StringEntry's too.
for (i = 0; i < count; i++)
- table[i] = NULL;
+ table[i] = NULL;
mem.free(table);
table = NULL;
@@ -74,21 +74,21 @@ void **StringTable::search(const dchar *s, unsigned len)
//printf("\thash = %d, u = %d\n",hash,u);
while (*se)
{
- cmp = (*se)->hash - hash;
- if (cmp == 0)
- {
- cmp = (*se)->value.lstring.len() - len;
- if (cmp == 0)
- {
- cmp = Dchar::memcmp(s,(*se)->value.lstring.toDchars(),len);
- if (cmp == 0)
- break;
- }
- }
- if (cmp < 0)
- se = &(*se)->left;
- else
- se = &(*se)->right;
+ cmp = (*se)->hash - hash;
+ if (cmp == 0)
+ {
+ cmp = (*se)->value.lstring.len() - len;
+ if (cmp == 0)
+ {
+ cmp = Dchar::memcmp(s,(*se)->value.lstring.toDchars(),len);
+ if (cmp == 0)
+ break;
+ }
+ }
+ if (cmp < 0)
+ se = &(*se)->left;
+ else
+ se = &(*se)->right;
}
//printf("\treturn %p, %p\n",se, (*se));
return (void **)se;
@@ -99,9 +99,9 @@ StringValue *StringTable::lookup(const dchar *s, unsigned len)
se = *(StringEntry **)search(s,len);
if (se)
- return &se->value;
+ return &se->value;
else
- return NULL;
+ return NULL;
}
StringValue *StringTable::update(const dchar *s, unsigned len)
@@ -110,10 +110,10 @@ StringValue *StringTable::update(const dchar *s, unsigned len)
pse = (StringEntry **)search(s,len);
se = *pse;
- if (!se) // not in table: so create new entry
+ if (!se) // not in table: so create new entry
{
- se = StringEntry::alloc(s, len);
- *pse = se;
+ se = StringEntry::alloc(s, len);
+ *pse = se;
}
return &se->value;
}
@@ -125,11 +125,11 @@ StringValue *StringTable::insert(const dchar *s, unsigned len)
pse = (StringEntry **)search(s,len);
se = *pse;
if (se)
- return NULL; // error: already in table
+ return NULL; // error: already in table
else
{
- se = StringEntry::alloc(s, len);
- *pse = se;
+ se = StringEntry::alloc(s, len);
+ *pse = se;
}
return &se->value;
}
diff --git a/dmd/root/stringtable.h b/dmd/root/stringtable.h
index 51e59f83..c56d9b4f 100644
--- a/dmd/root/stringtable.h
+++ b/dmd/root/stringtable.h
@@ -21,9 +21,9 @@
struct StringValue
{
union
- { int intvalue;
- void *ptrvalue;
- dchar *string;
+ { int intvalue;
+ void *ptrvalue;
+ dchar *string;
};
Lstring lstring;
};
diff --git a/dmd/scope.c b/dmd/scope.c
index 3fb625ad..b6414bde 100644
--- a/dmd/scope.c
+++ b/dmd/scope.c
@@ -30,12 +30,12 @@ void *Scope::operator new(size_t size)
{
if (freelist)
{
- Scope *s = freelist;
- freelist = s->enclosing;
- //printf("freelist %p\n", s);
- assert(s->flags & SCOPEfree);
- s->flags &= ~SCOPEfree;
- return s;
+ Scope *s = freelist;
+ freelist = s->enclosing;
+ //printf("freelist %p\n", s);
+ assert(s->flags & SCOPEfree);
+ s->flags &= ~SCOPEfree;
+ return s;
}
void *p = ::operator new(size);
@@ -103,10 +103,10 @@ Scope::Scope(Scope *enclosing)
this->enclosing = enclosing;
#ifdef DEBUG
if (enclosing->enclosing)
- assert(!(enclosing->enclosing->flags & SCOPEfree));
+ assert(!(enclosing->enclosing->flags & SCOPEfree));
if (this == enclosing->enclosing)
{
- printf("this = %p, enclosing = %p, enclosing->enclosing = %p\n", this, enclosing, enclosing->enclosing);
+ printf("this = %p, enclosing = %p, enclosing->enclosing = %p\n", this, enclosing, enclosing->enclosing);
}
assert(this != enclosing->enclosing);
#endif
@@ -145,9 +145,9 @@ Scope *Scope::createGlobal(Module *module)
// Add top level package as member of this global scope
Dsymbol *m = module;
while (m->parent)
- m = m->parent;
+ m = m->parent;
m->addMember(NULL, sc->scopesym, 1);
- m->parent = NULL; // got changed by addMember()
+ m->parent = NULL; // got changed by addMember()
// Create the module scope underneath the global scope
sc = sc->push(module);
@@ -177,12 +177,12 @@ Scope *Scope::pop()
Scope *enc = enclosing;
if (enclosing)
- enclosing->callSuper |= callSuper;
+ enclosing->callSuper |= callSuper;
if (!nofree)
- { enclosing = freelist;
- freelist = this;
- flags |= SCOPEfree;
+ { enclosing = freelist;
+ freelist = this;
+ flags |= SCOPEfree;
}
return enc;
@@ -196,25 +196,25 @@ void Scope::mergeCallSuper(Loc loc, unsigned cs)
// The two paths are callSuper and cs; the result is merged into callSuper.
if (cs != callSuper)
- { int a;
- int b;
+ { int a;
+ int b;
- callSuper |= cs & (CSXany_ctor | CSXlabel);
- if (cs & CSXreturn)
- {
- }
- else if (callSuper & CSXreturn)
- {
- callSuper = cs | (callSuper & (CSXany_ctor | CSXlabel));
- }
- else
- {
- a = (cs & (CSXthis_ctor | CSXsuper_ctor)) != 0;
- b = (callSuper & (CSXthis_ctor | CSXsuper_ctor)) != 0;
- if (a != b)
- error(loc, "one path skips constructor");
- callSuper |= cs;
- }
+ callSuper |= cs & (CSXany_ctor | CSXlabel);
+ if (cs & CSXreturn)
+ {
+ }
+ else if (callSuper & CSXreturn)
+ {
+ callSuper = cs | (callSuper & (CSXany_ctor | CSXlabel));
+ }
+ else
+ {
+ a = (cs & (CSXthis_ctor | CSXsuper_ctor)) != 0;
+ b = (callSuper & (CSXthis_ctor | CSXsuper_ctor)) != 0;
+ if (a != b)
+ error(loc, "one path skips constructor");
+ callSuper |= cs;
+ }
}
}
@@ -225,50 +225,50 @@ Dsymbol *Scope::search(Loc loc, Identifier *ident, Dsymbol **pscopesym)
//printf("Scope::search(%p, '%s')\n", this, ident->toChars());
if (ident == Id::empty)
{
- // Look for module scope
- for (sc = this; sc; sc = sc->enclosing)
- {
- assert(sc != sc->enclosing);
- if (sc->scopesym)
- {
- s = sc->scopesym->isModule();
- if (s)
- {
- //printf("\tfound %s.%s\n", s->parent ? s->parent->toChars() : "", s->toChars());
- if (pscopesym)
- *pscopesym = sc->scopesym;
- return s;
- }
- }
- }
- return NULL;
+ // Look for module scope
+ for (sc = this; sc; sc = sc->enclosing)
+ {
+ assert(sc != sc->enclosing);
+ if (sc->scopesym)
+ {
+ s = sc->scopesym->isModule();
+ if (s)
+ {
+ //printf("\tfound %s.%s\n", s->parent ? s->parent->toChars() : "", s->toChars());
+ if (pscopesym)
+ *pscopesym = sc->scopesym;
+ return s;
+ }
+ }
+ }
+ return NULL;
}
for (sc = this; sc; sc = sc->enclosing)
{
- assert(sc != sc->enclosing);
- if (sc->scopesym)
- {
- //printf("\tlooking in scopesym '%s', kind = '%s'\n", sc->scopesym->toChars(), sc->scopesym->kind());
- s = sc->scopesym->search(loc, ident, 0);
- if (s)
- {
- if ((global.params.warnings ||
- global.params.Dversion > 1) &&
- ident == Id::length &&
- sc->scopesym->isArrayScopeSymbol() &&
- sc->enclosing &&
- sc->enclosing->search(loc, ident, NULL))
- {
- warning(s->loc, "array 'length' hides other 'length' name in outer scope");
- }
+ assert(sc != sc->enclosing);
+ if (sc->scopesym)
+ {
+ //printf("\tlooking in scopesym '%s', kind = '%s'\n", sc->scopesym->toChars(), sc->scopesym->kind());
+ s = sc->scopesym->search(loc, ident, 0);
+ if (s)
+ {
+ if ((global.params.warnings ||
+ global.params.Dversion > 1) &&
+ ident == Id::length &&
+ sc->scopesym->isArrayScopeSymbol() &&
+ sc->enclosing &&
+ sc->enclosing->search(loc, ident, NULL))
+ {
+ warning(s->loc, "array 'length' hides other 'length' name in outer scope");
+ }
- //printf("\tfound %s.%s, kind = '%s'\n", s->parent ? s->parent->toChars() : "", s->toChars(), s->kind());
- if (pscopesym)
- *pscopesym = sc->scopesym;
- return s;
- }
- }
+ //printf("\tfound %s.%s, kind = '%s'\n", s->parent ? s->parent->toChars() : "", s->toChars(), s->kind());
+ if (pscopesym)
+ *pscopesym = sc->scopesym;
+ return s;
+ }
+ }
}
return NULL;
@@ -279,14 +279,14 @@ Dsymbol *Scope::insert(Dsymbol *s)
for (sc = this; sc; sc = sc->enclosing)
{
- //printf("\tsc = %p\n", sc);
- if (sc->scopesym)
- {
- //printf("\t\tsc->scopesym = %p\n", sc->scopesym);
- if (!sc->scopesym->symtab)
- sc->scopesym->symtab = new DsymbolTable();
- return sc->scopesym->symtabInsert(s);
- }
+ //printf("\tsc = %p\n", sc);
+ if (sc->scopesym)
+ {
+ //printf("\t\tsc->scopesym = %p\n", sc->scopesym);
+ if (!sc->scopesym->symtab)
+ sc->scopesym->symtab = new DsymbolTable();
+ return sc->scopesym->symtabInsert(s);
+ }
}
assert(0);
return NULL;
@@ -301,14 +301,14 @@ ClassDeclaration *Scope::getClassScope()
for (sc = this; sc; sc = sc->enclosing)
{
- ClassDeclaration *cd;
-
- if (sc->scopesym)
- {
- cd = sc->scopesym->isClassDeclaration();
- if (cd)
- return cd;
- }
+ ClassDeclaration *cd;
+
+ if (sc->scopesym)
+ {
+ cd = sc->scopesym->isClassDeclaration();
+ if (cd)
+ return cd;
+ }
}
return NULL;
}
@@ -322,19 +322,19 @@ AggregateDeclaration *Scope::getStructClassScope()
for (sc = this; sc; sc = sc->enclosing)
{
- AggregateDeclaration *ad;
-
- if (sc->scopesym)
- {
- ad = sc->scopesym->isClassDeclaration();
- if (ad)
- return ad;
- else
- { ad = sc->scopesym->isStructDeclaration();
- if (ad)
- return ad;
- }
- }
+ AggregateDeclaration *ad;
+
+ if (sc->scopesym)
+ {
+ ad = sc->scopesym->isClassDeclaration();
+ if (ad)
+ return ad;
+ else
+ { ad = sc->scopesym->isStructDeclaration();
+ if (ad)
+ return ad;
+ }
+ }
}
return NULL;
}
@@ -352,14 +352,14 @@ void Scope::setNoFree()
//printf("Scope::setNoFree(this = %p)\n", this);
for (sc = this; sc; sc = sc->enclosing)
{
- //printf("\tsc = %p\n", sc);
- sc->nofree = 1;
+ //printf("\tsc = %p\n", sc);
+ sc->nofree = 1;
- assert(!(flags & SCOPEfree));
- //assert(sc != sc->enclosing);
- //assert(!sc->enclosing || sc != sc->enclosing->enclosing);
- //if (++i == 10)
- //assert(0);
+ assert(!(flags & SCOPEfree));
+ //assert(sc != sc->enclosing);
+ //assert(!sc->enclosing || sc != sc->enclosing->enclosing);
+ //if (++i == 10)
+ //assert(0);
}
}
@@ -382,7 +382,7 @@ void *scope_search_fp(void *arg, const char *seed)
Dsymbol *Scope::search_correct(Identifier *ident)
{
if (global.gag)
- return NULL; // don't do it for speculative compiles; too time consuming
+ return NULL; // don't do it for speculative compiles; too time consuming
return (Dsymbol *)speller(ident->toChars(), &scope_search_fp, this, idchars);
}
diff --git a/dmd/scope.h b/dmd/scope.h
index 71325311..7b719d9f 100644
--- a/dmd/scope.h
+++ b/dmd/scope.h
@@ -43,63 +43,63 @@ struct AnonDeclaration;
#else
enum LINK;
enum PROT;
-#endif
+#endif
struct Scope
{
- Scope *enclosing; // enclosing Scope
+ Scope *enclosing; // enclosing Scope
- Module *module; // Root module
- ScopeDsymbol *scopesym; // current symbol
- ScopeDsymbol *sd; // if in static if, and declaring new symbols,
- // sd gets the addMember()
- FuncDeclaration *func; // function we are in
- Dsymbol *parent; // parent to use
- LabelStatement *slabel; // enclosing labelled statement
- SwitchStatement *sw; // enclosing switch statement
- TryFinallyStatement *enclosingFinally; // enclosing try finally statement; set inside its finally block
+ Module *module; // Root module
+ ScopeDsymbol *scopesym; // current symbol
+ ScopeDsymbol *sd; // if in static if, and declaring new symbols,
+ // sd gets the addMember()
+ FuncDeclaration *func; // function we are in
+ Dsymbol *parent; // parent to use
+ LabelStatement *slabel; // enclosing labelled statement
+ SwitchStatement *sw; // enclosing switch statement
+ TryFinallyStatement *enclosingFinally; // enclosing try finally statement; set inside its finally block
TemplateInstance *tinst; // enclosing template instance
Statement *enclosingScopeExit; // enclosing statement that wants to do something on scope exit
- Statement *sbreak; // enclosing statement that supports "break"
- Statement *scontinue; // enclosing statement that supports "continue"
- ForeachStatement *fes; // if nested function for ForeachStatement, this is it
- unsigned offset; // next offset to use in aggregate
- int inunion; // we're processing members of a union
- int incontract; // we're inside contract code
- int nofree; // set if shouldn't free it
- int noctor; // set if constructor calls aren't allowed
- int intypeof; // in typeof(exp)
+ Statement *sbreak; // enclosing statement that supports "break"
+ Statement *scontinue; // enclosing statement that supports "continue"
+ ForeachStatement *fes; // if nested function for ForeachStatement, this is it
+ unsigned offset; // next offset to use in aggregate
+ int inunion; // we're processing members of a union
+ int incontract; // we're inside contract code
+ int nofree; // set if shouldn't free it
+ int noctor; // set if constructor calls aren't allowed
+ int intypeof; // in typeof(exp)
int parameterSpecialization; // if in template parameter specialization
- int noaccesscheck; // don't do access checks
- int mustsemantic; // cannot defer semantic()
+ int noaccesscheck; // don't do access checks
+ int mustsemantic; // cannot defer semantic()
- unsigned callSuper; // primitive flow analysis for constructors
-#define CSXthis_ctor 1 // called this()
-#define CSXsuper_ctor 2 // called super()
-#define CSXthis 4 // referenced this
-#define CSXsuper 8 // referenced super
-#define CSXlabel 0x10 // seen a label
-#define CSXreturn 0x20 // seen a return statement
-#define CSXany_ctor 0x40 // either this() or super() was called
+ unsigned callSuper; // primitive flow analysis for constructors
+#define CSXthis_ctor 1 // called this()
+#define CSXsuper_ctor 2 // called super()
+#define CSXthis 4 // referenced this
+#define CSXsuper 8 // referenced super
+#define CSXlabel 0x10 // seen a label
+#define CSXreturn 0x20 // seen a return statement
+#define CSXany_ctor 0x40 // either this() or super() was called
- unsigned structalign; // alignment for struct members
- enum LINK linkage; // linkage for external functions
+ unsigned structalign; // alignment for struct members
+ enum LINK linkage; // linkage for external functions
- enum PROT protection; // protection for class members
- int explicitProtection; // set if in an explicit protection attribute
+ enum PROT protection; // protection for class members
+ int explicitProtection; // set if in an explicit protection attribute
- StorageClass stc; // storage class
+ StorageClass stc; // storage class
unsigned flags;
-#define SCOPEctor 1 // constructor type
-#define SCOPEstaticif 2 // inside static if
-#define SCOPEfree 4 // is on free list
+#define SCOPEctor 1 // constructor type
+#define SCOPEstaticif 2 // inside static if
+#define SCOPEfree 4 // is on free list
- AnonymousAggregateDeclaration *anonAgg; // for temporary analysis
+ AnonymousAggregateDeclaration *anonAgg; // for temporary analysis
- DocComment *lastdc; // documentation comment for last symbol at this scope
- unsigned lastoffset; // offset in docbuf of where to insert next dec
- OutBuffer *docbuf; // buffer for documentation output
+ DocComment *lastdc; // documentation comment for last symbol at this scope
+ unsigned lastoffset; // offset in docbuf of where to insert next dec
+ OutBuffer *docbuf; // buffer for documentation output
static Scope *freelist;
static void *operator new(size_t sz);
diff --git a/dmd/statement.c b/dmd/statement.c
index 9dce3c98..0453f68e 100644
--- a/dmd/statement.c
+++ b/dmd/statement.c
@@ -83,9 +83,9 @@ Statement *Statement::semanticScope(Scope *sc, Statement *sbreak, Statement *sco
scd = sc->push();
if (sbreak)
- scd->sbreak = sbreak;
+ scd->sbreak = sbreak;
if (scontinue)
- scd->scontinue = scontinue;
+ scd->scontinue = scontinue;
s = semantic(scd);
scd->pop();
return s;
@@ -155,9 +155,9 @@ int Statement::isEmpty()
* at the end of the current scope, return that code in the form of
* a Statement.
* Output:
- * *sentry code executed upon entry to the scope
- * *sexception code executed upon exit from the scope via exception
- * *sfinally code executed in finally block
+ * *sentry code executed upon entry to the scope
+ * *sexception code executed upon exit from the scope via exception
+ * *sfinally code executed in finally block
*/
void Statement::scopeCode(Scope *sc, Statement **sentry, Statement **sexception, Statement **sfinally)
@@ -215,7 +215,7 @@ Statement *ExpStatement::syntaxCopy()
void ExpStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (exp)
- exp->toCBuffer(buf, hgs);
+ exp->toCBuffer(buf, hgs);
buf->writeByte(';');
if (!hgs->FLinit.init)
buf->writenl();
@@ -225,16 +225,16 @@ Statement *ExpStatement::semantic(Scope *sc)
{
if (exp)
{
- //printf("ExpStatement::semantic() %s\n", exp->toChars());
- exp = exp->semantic(sc);
- exp = resolveProperties(sc, exp);
- exp->checkSideEffect(0);
- exp = exp->optimize(0);
- if (exp->op == TOKdeclaration && !isDeclarationStatement())
- { Statement *s = new DeclarationStatement(loc, exp);
- return s;
- }
- //exp = exp->optimize(isDeclarationStatement() ? WANTvalue : 0);
+ //printf("ExpStatement::semantic() %s\n", exp->toChars());
+ exp = exp->semantic(sc);
+ exp = resolveProperties(sc, exp);
+ exp->checkSideEffect(0);
+ exp = exp->optimize(0);
+ if (exp->op == TOKdeclaration && !isDeclarationStatement())
+ { Statement *s = new DeclarationStatement(loc, exp);
+ return s;
+ }
+ //exp = exp->optimize(isDeclarationStatement() ? WANTvalue : 0);
}
return this;
}
@@ -244,16 +244,16 @@ int ExpStatement::blockExit()
if (exp)
{
- if (exp->op == TOKhalt)
- return BEhalt;
- if (exp->op == TOKassert)
- { AssertExp *a = (AssertExp *)exp;
+ if (exp->op == TOKhalt)
+ return BEhalt;
+ if (exp->op == TOKassert)
+ { AssertExp *a = (AssertExp *)exp;
- if (a->e1->isBool(FALSE)) // if it's an assert(0)
- return BEhalt;
- }
- if (exp->canThrow())
- result |= BEthrow;
+ if (a->e1->isBool(FALSE)) // if it's an assert(0)
+ return BEhalt;
+ }
+ if (exp->canThrow())
+ result |= BEthrow;
}
return result;
}
@@ -295,8 +295,8 @@ Statements *CompileStatement::flatten(Scope *sc)
exp = resolveProperties(sc, exp);
exp = exp->optimize(WANTvalue | WANTinterpret);
if (exp->op != TOKstring)
- { error("argument to mixin must be a string, not (%s)", exp->toChars());
- return NULL;
+ { error("argument to mixin must be a string, not (%s)", exp->toChars());
+ return NULL;
}
StringExp *se = (StringExp *)exp;
se = se->toUTF8(sc);
@@ -307,8 +307,8 @@ Statements *CompileStatement::flatten(Scope *sc)
Statements *a = new Statements();
while (p.token.value != TOKeof)
{
- Statement *s = p.parseStatement(PSsemi | PScurlyscope);
- a->push(s);
+ Statement *s = p.parseStatement(PSsemi | PScurlyscope);
+ a->push(s);
}
return a;
}
@@ -318,7 +318,7 @@ Statement *CompileStatement::semantic(Scope *sc)
//printf("CompileStatement::semantic() %s\n", exp->toChars());
Statements *a = flatten(sc);
if (!a)
- return NULL;
+ return NULL;
Statement *s = new CompoundStatement(loc, a);
return s->semantic(sc);
}
@@ -353,21 +353,21 @@ void DeclarationStatement::scopeCode(Scope *sc, Statement **sentry, Statement **
if (exp)
{
- if (exp->op == TOKdeclaration)
- {
- DeclarationExp *de = (DeclarationExp *)(exp);
- VarDeclaration *v = de->declaration->isVarDeclaration();
- if (v)
- { Expression *e;
+ if (exp->op == TOKdeclaration)
+ {
+ DeclarationExp *de = (DeclarationExp *)(exp);
+ VarDeclaration *v = de->declaration->isVarDeclaration();
+ if (v)
+ { Expression *e;
- e = v->callScopeDtor(sc);
- if (e)
- {
- //printf("dtor is: "); e->print();
- *sfinally = new ExpStatement(loc, e);
- }
- }
- }
+ e = v->callScopeDtor(sc);
+ if (e)
+ {
+ //printf("dtor is: "); e->print();
+ *sfinally = new ExpStatement(loc, e);
+ }
+ }
+ }
}
}
@@ -399,10 +399,10 @@ Statement *CompoundStatement::syntaxCopy()
Statements *a = new Statements();
a->setDim(statements->dim);
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *)statements->data[i];
- if (s)
- s = s->syntaxCopy();
- a->data[i] = s;
+ { Statement *s = (Statement *)statements->data[i];
+ if (s)
+ s = s->syntaxCopy();
+ a->data[i] = s;
}
CompoundStatement *cs = new CompoundStatement(loc, a);
return cs;
@@ -416,116 +416,116 @@ Statement *CompoundStatement::semantic(Scope *sc)
for (size_t i = 0; i < statements->dim; )
{
- s = (Statement *) statements->data[i];
- if (s)
- { Statements *a = s->flatten(sc);
+ s = (Statement *) statements->data[i];
+ if (s)
+ { Statements *a = s->flatten(sc);
- if (a)
- {
- statements->remove(i);
- statements->insert(i, a);
- continue;
- }
- s = s->semantic(sc);
- statements->data[i] = s;
- if (s)
- {
- Statement *sentry;
- Statement *sexception;
- Statement *sfinally;
+ if (a)
+ {
+ statements->remove(i);
+ statements->insert(i, a);
+ continue;
+ }
+ s = s->semantic(sc);
+ statements->data[i] = s;
+ if (s)
+ {
+ Statement *sentry;
+ Statement *sexception;
+ Statement *sfinally;
- s->scopeCode(sc, &sentry, &sexception, &sfinally);
- if (sentry)
- {
- sentry = sentry->semantic(sc);
- statements->data[i] = sentry;
- }
- if (sexception)
- {
- if (i + 1 == statements->dim && !sfinally)
- {
+ s->scopeCode(sc, &sentry, &sexception, &sfinally);
+ if (sentry)
+ {
+ sentry = sentry->semantic(sc);
+ statements->data[i] = sentry;
+ }
+ if (sexception)
+ {
+ if (i + 1 == statements->dim && !sfinally)
+ {
#if 1
- sexception = sexception->semantic(sc);
+ sexception = sexception->semantic(sc);
#else
- statements->push(sexception);
- if (sfinally)
- // Assume sexception does not throw
- statements->push(sfinally);
+ statements->push(sexception);
+ if (sfinally)
+ // Assume sexception does not throw
+ statements->push(sfinally);
#endif
- }
- else
- {
- /* Rewrite:
- * s; s1; s2;
- * As:
- * s;
- * try { s1; s2; }
- * catch (Object __o)
- * { sexception; throw __o; }
- */
- Statement *body;
- Statements *a = new Statements();
+ }
+ else
+ {
+ /* Rewrite:
+ * s; s1; s2;
+ * As:
+ * s;
+ * try { s1; s2; }
+ * catch (Object __o)
+ * { sexception; throw __o; }
+ */
+ Statement *body;
+ Statements *a = new Statements();
- for (int j = i + 1; j < statements->dim; j++)
- {
- a->push(statements->data[j]);
- }
- body = new CompoundStatement(0, a);
- body = new ScopeStatement(0, body);
+ for (int j = i + 1; j < statements->dim; j++)
+ {
+ a->push(statements->data[j]);
+ }
+ body = new CompoundStatement(0, a);
+ body = new ScopeStatement(0, body);
- Identifier *id = Lexer::uniqueId("__o");
+ Identifier *id = Lexer::uniqueId("__o");
- Statement *handler = new ThrowStatement(0, new IdentifierExp(0, id));
- handler = new CompoundStatement(0, sexception, handler);
+ Statement *handler = new ThrowStatement(0, new IdentifierExp(0, id));
+ handler = new CompoundStatement(0, sexception, handler);
- Array *catches = new Array();
- Catch *ctch = new Catch(0, NULL, id, handler);
- catches->push(ctch);
- s = new TryCatchStatement(0, body, catches);
+ Array *catches = new Array();
+ Catch *ctch = new Catch(0, NULL, id, handler);
+ catches->push(ctch);
+ s = new TryCatchStatement(0, body, catches);
- if (sfinally)
- s = new TryFinallyStatement(0, s, sfinally);
- s = s->semantic(sc);
- statements->setDim(i + 1);
- statements->push(s);
- break;
- }
- }
- else if (sfinally)
- {
- if (0 && i + 1 == statements->dim)
- {
- statements->push(sfinally);
- }
- else
- {
- /* Rewrite:
- * s; s1; s2;
- * As:
- * s; try { s1; s2; } finally { sfinally; }
- */
- Statement *body;
- Statements *a = new Statements();
+ if (sfinally)
+ s = new TryFinallyStatement(0, s, sfinally);
+ s = s->semantic(sc);
+ statements->setDim(i + 1);
+ statements->push(s);
+ break;
+ }
+ }
+ else if (sfinally)
+ {
+ if (0 && i + 1 == statements->dim)
+ {
+ statements->push(sfinally);
+ }
+ else
+ {
+ /* Rewrite:
+ * s; s1; s2;
+ * As:
+ * s; try { s1; s2; } finally { sfinally; }
+ */
+ Statement *body;
+ Statements *a = new Statements();
- for (int j = i + 1; j < statements->dim; j++)
- {
- a->push(statements->data[j]);
- }
- body = new CompoundStatement(0, a);
- s = new TryFinallyStatement(0, body, sfinally);
- s = s->semantic(sc);
- statements->setDim(i + 1);
- statements->push(s);
- break;
- }
- }
- }
- }
- i++;
+ for (int j = i + 1; j < statements->dim; j++)
+ {
+ a->push(statements->data[j]);
+ }
+ body = new CompoundStatement(0, a);
+ s = new TryFinallyStatement(0, body, sfinally);
+ s = s->semantic(sc);
+ statements->setDim(i + 1);
+ statements->push(s);
+ break;
+ }
+ }
+ }
+ }
+ i++;
}
if (statements->dim == 1 && !isAsmBlockStatement())
{
- return (Statement *)statements->data[0];
+ return (Statement *)statements->data[0];
}
return this;
}
@@ -540,13 +540,13 @@ ReturnStatement *CompoundStatement::isReturnStatement()
ReturnStatement *rs = NULL;
for (int i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s)
- {
- rs = s->isReturnStatement();
- if (rs)
- break;
- }
+ { Statement *s = (Statement *) statements->data[i];
+ if (s)
+ {
+ rs = s->isReturnStatement();
+ if (rs)
+ break;
+ }
}
return rs;
}
@@ -554,18 +554,18 @@ ReturnStatement *CompoundStatement::isReturnStatement()
void CompoundStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
for (int i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s)
- s->toCBuffer(buf, hgs);
+ { Statement *s = (Statement *) statements->data[i];
+ if (s)
+ s->toCBuffer(buf, hgs);
}
}
int CompoundStatement::usesEH()
{
for (int i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s && s->usesEH())
- return TRUE;
+ { Statement *s = (Statement *) statements->data[i];
+ if (s && s->usesEH())
+ return TRUE;
}
return FALSE;
}
@@ -575,22 +575,22 @@ int CompoundStatement::blockExit()
//printf("CompoundStatement::blockExit(%p) %d\n", this, statements->dim);
int result = BEfallthru;
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s)
- {
+ { Statement *s = (Statement *) statements->data[i];
+ if (s)
+ {
//printf("result = x%x\n", result);
//printf("%s\n", s->toChars());
- if (!(result & BEfallthru) && !s->comeFrom())
- {
- if (s->blockExit() != BEhalt && !s->isEmpty())
- s->warning("statement is not reachable");
- }
- else
- {
- result &= ~BEfallthru;
- result |= s->blockExit();
- }
- }
+ if (!(result & BEfallthru) && !s->comeFrom())
+ {
+ if (s->blockExit() != BEhalt && !s->isEmpty())
+ s->warning("statement is not reachable");
+ }
+ else
+ {
+ result &= ~BEfallthru;
+ result |= s->blockExit();
+ }
+ }
}
return result;
}
@@ -600,12 +600,12 @@ int CompoundStatement::comeFrom()
//printf("CompoundStatement::comeFrom()\n");
for (int i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *)statements->data[i];
+ { Statement *s = (Statement *)statements->data[i];
- if (!s)
- continue;
+ if (!s)
+ continue;
- comefrom |= s->comeFrom();
+ comefrom |= s->comeFrom();
}
return comefrom;
}
@@ -613,9 +613,9 @@ int CompoundStatement::comeFrom()
int CompoundStatement::isEmpty()
{
for (int i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s && !s->isEmpty())
- return FALSE;
+ { Statement *s = (Statement *) statements->data[i];
+ if (s && !s->isEmpty())
+ return FALSE;
}
return TRUE;
}
@@ -634,10 +634,10 @@ Statement *CompoundDeclarationStatement::syntaxCopy()
Statements *a = new Statements();
a->setDim(statements->dim);
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *)statements->data[i];
- if (s)
- s = s->syntaxCopy();
- a->data[i] = s;
+ { Statement *s = (Statement *)statements->data[i];
+ if (s)
+ s = s->syntaxCopy();
+ a->data[i] = s;
}
CompoundDeclarationStatement *cs = new CompoundDeclarationStatement(loc, a);
return cs;
@@ -647,50 +647,50 @@ void CompoundDeclarationStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
int nwritten = 0;
for (int i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s)
- { DeclarationStatement *ds = s->isDeclarationStatement();
- assert(ds);
- DeclarationExp *de = (DeclarationExp *)ds->exp;
- assert(de->op == TOKdeclaration);
- Declaration *d = de->declaration->isDeclaration();
- assert(d);
- VarDeclaration *v = d->isVarDeclaration();
- if (v)
- {
- /* This essentially copies the part of VarDeclaration::toCBuffer()
- * that does not print the type.
- * Should refactor this.
- */
- if (nwritten)
- {
- buf->writeByte(',');
- buf->writestring(v->ident->toChars());
- }
- else
- {
- StorageClassDeclaration::stcToCBuffer(buf, v->storage_class);
- if (v->type)
- v->type->toCBuffer(buf, v->ident, hgs);
- else
- buf->writestring(v->ident->toChars());
- }
+ { Statement *s = (Statement *) statements->data[i];
+ if (s)
+ { DeclarationStatement *ds = s->isDeclarationStatement();
+ assert(ds);
+ DeclarationExp *de = (DeclarationExp *)ds->exp;
+ assert(de->op == TOKdeclaration);
+ Declaration *d = de->declaration->isDeclaration();
+ assert(d);
+ VarDeclaration *v = d->isVarDeclaration();
+ if (v)
+ {
+ /* This essentially copies the part of VarDeclaration::toCBuffer()
+ * that does not print the type.
+ * Should refactor this.
+ */
+ if (nwritten)
+ {
+ buf->writeByte(',');
+ buf->writestring(v->ident->toChars());
+ }
+ else
+ {
+ StorageClassDeclaration::stcToCBuffer(buf, v->storage_class);
+ if (v->type)
+ v->type->toCBuffer(buf, v->ident, hgs);
+ else
+ buf->writestring(v->ident->toChars());
+ }
- if (v->init)
- { buf->writestring(" = ");
+ if (v->init)
+ { buf->writestring(" = ");
#if DMDV2
- ExpInitializer *ie = v->init->isExpInitializer();
- if (ie && (ie->exp->op == TOKconstruct || ie->exp->op == TOKblit))
- ((AssignExp *)ie->exp)->e2->toCBuffer(buf, hgs);
- else
+ ExpInitializer *ie = v->init->isExpInitializer();
+ if (ie && (ie->exp->op == TOKconstruct || ie->exp->op == TOKblit))
+ ((AssignExp *)ie->exp)->e2->toCBuffer(buf, hgs);
+ else
#endif
- v->init->toCBuffer(buf, hgs);
- }
- }
- else
- d->toCBuffer(buf, hgs);
- nwritten++;
- }
+ v->init->toCBuffer(buf, hgs);
+ }
+ }
+ else
+ d->toCBuffer(buf, hgs);
+ nwritten++;
+ }
}
buf->writeByte(';');
if (!hgs->FLinit.init)
@@ -710,10 +710,10 @@ Statement *UnrolledLoopStatement::syntaxCopy()
Statements *a = new Statements();
a->setDim(statements->dim);
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *)statements->data[i];
- if (s)
- s = s->syntaxCopy();
- a->data[i] = s;
+ { Statement *s = (Statement *)statements->data[i];
+ if (s)
+ s = s->syntaxCopy();
+ a->data[i] = s;
}
UnrolledLoopStatement *cs = new UnrolledLoopStatement(loc, a);
return cs;
@@ -731,13 +731,13 @@ Statement *UnrolledLoopStatement::semantic(Scope *sc)
for (size_t i = 0; i < statements->dim; i++)
{
- Statement *s = (Statement *) statements->data[i];
- if (s)
- {
- //printf("[%d]: %s\n", i, s->toChars());
- s = s->semantic(scd);
- statements->data[i] = s;
- }
+ Statement *s = (Statement *) statements->data[i];
+ if (s)
+ {
+ //printf("[%d]: %s\n", i, s->toChars());
+ s = s->semantic(scd);
+ statements->data[i] = s;
+ }
}
scd->pop();
@@ -751,11 +751,11 @@ void UnrolledLoopStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writenl();
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s;
+ { Statement *s;
- s = (Statement *) statements->data[i];
- if (s)
- s->toCBuffer(buf, hgs);
+ s = (Statement *) statements->data[i];
+ if (s)
+ s->toCBuffer(buf, hgs);
}
buf->writeByte('}');
@@ -775,9 +775,9 @@ int UnrolledLoopStatement::hasContinue()
int UnrolledLoopStatement::usesEH()
{
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s && s->usesEH())
- return TRUE;
+ { Statement *s = (Statement *) statements->data[i];
+ if (s && s->usesEH())
+ return TRUE;
}
return FALSE;
}
@@ -786,12 +786,12 @@ int UnrolledLoopStatement::blockExit()
{
int result = BEfallthru;
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *) statements->data[i];
- if (s)
- {
- int r = s->blockExit();
- result |= r & ~(BEbreak | BEcontinue);
- }
+ { Statement *s = (Statement *) statements->data[i];
+ if (s)
+ {
+ int r = s->blockExit();
+ result |= r & ~(BEbreak | BEcontinue);
+ }
}
return result;
}
@@ -802,12 +802,12 @@ int UnrolledLoopStatement::comeFrom()
//printf("UnrolledLoopStatement::comeFrom()\n");
for (size_t i = 0; i < statements->dim; i++)
- { Statement *s = (Statement *)statements->data[i];
+ { Statement *s = (Statement *)statements->data[i];
- if (!s)
- continue;
+ if (!s)
+ continue;
- comefrom |= s->comeFrom();
+ comefrom |= s->comeFrom();
}
return comefrom;
}
@@ -836,34 +836,34 @@ Statement *ScopeStatement::semantic(Scope *sc)
//printf("ScopeStatement::semantic(sc = %p)\n", sc);
if (statement)
- { Statements *a;
+ { Statements *a;
- sym = new ScopeDsymbol();
- sym->parent = sc->scopesym;
- sc = sc->push(sym);
+ sym = new ScopeDsymbol();
+ sym->parent = sc->scopesym;
+ sc = sc->push(sym);
- a = statement->flatten(sc);
- if (a)
- {
- statement = new CompoundStatement(loc, a);
- }
+ a = statement->flatten(sc);
+ if (a)
+ {
+ statement = new CompoundStatement(loc, a);
+ }
- statement = statement->semantic(sc);
- if (statement)
- {
- Statement *sentry;
- Statement *sexception;
- Statement *sfinally;
+ statement = statement->semantic(sc);
+ if (statement)
+ {
+ Statement *sentry;
+ Statement *sexception;
+ Statement *sfinally;
- statement->scopeCode(sc, &sentry, &sexception, &sfinally);
- if (sfinally)
- {
- //printf("adding sfinally\n");
- statement = new CompoundStatement(loc, statement, sfinally);
- }
- }
+ statement->scopeCode(sc, &sentry, &sexception, &sfinally);
+ if (sfinally)
+ {
+ //printf("adding sfinally\n");
+ statement = new CompoundStatement(loc, statement, sfinally);
+ }
+ }
- sc->pop();
+ sc->pop();
}
return this;
}
@@ -909,7 +909,7 @@ void ScopeStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writenl();
if (statement)
- statement->toCBuffer(buf, hgs);
+ statement->toCBuffer(buf, hgs);
buf->writeByte('}');
buf->writenl();
@@ -964,24 +964,24 @@ int WhileStatement::blockExit()
int result = BEnone;
if (condition->canThrow())
- result |= BEthrow;
+ result |= BEthrow;
if (condition->isBool(TRUE))
{
- if (body)
- { result |= body->blockExit();
- if (result & BEbreak)
- result |= BEfallthru;
- }
+ if (body)
+ { result |= body->blockExit();
+ if (result & BEbreak)
+ result |= BEfallthru;
+ }
}
else if (condition->isBool(FALSE))
{
- result |= BEfallthru;
+ result |= BEfallthru;
}
else
{
- if (body)
- result |= body->blockExit();
- result |= BEfallthru;
+ if (body)
+ result |= body->blockExit();
+ result |= BEfallthru;
}
result &= ~(BEbreak | BEcontinue);
return result;
@@ -992,7 +992,7 @@ int WhileStatement::comeFrom()
{
assert(0);
if (body)
- return body->comeFrom();
+ return body->comeFrom();
return FALSE;
}
@@ -1003,7 +1003,7 @@ void WhileStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writebyte(')');
buf->writenl();
if (body)
- body->toCBuffer(buf, hgs);
+ body->toCBuffer(buf, hgs);
}
/******************************** DoStatement ***************************/
@@ -1026,7 +1026,7 @@ Statement *DoStatement::semantic(Scope *sc)
{
sc->noctor++;
if (body)
- body = body->semanticScope(sc, this, this);
+ body = body->semanticScope(sc, this, this);
sc->noctor--;
condition = condition->semantic(sc);
condition = resolveProperties(sc, condition);
@@ -1056,19 +1056,19 @@ int DoStatement::blockExit()
{ int result;
if (body)
- { result = body->blockExit();
- if (result == BEbreak)
- return BEfallthru;
- if (result & BEcontinue)
- result |= BEfallthru;
+ { result = body->blockExit();
+ if (result == BEbreak)
+ return BEfallthru;
+ if (result & BEcontinue)
+ result |= BEfallthru;
}
else
- result = BEfallthru;
+ result = BEfallthru;
if (result & BEfallthru)
- { if (condition->canThrow())
- result |= BEthrow;
- if (!(result & BEbreak) && condition->isBool(TRUE))
- result &= ~BEfallthru;
+ { if (condition->canThrow())
+ result |= BEthrow;
+ if (!(result & BEbreak) && condition->isBool(TRUE))
+ result &= ~BEfallthru;
}
result &= ~(BEbreak | BEcontinue);
return result;
@@ -1078,7 +1078,7 @@ int DoStatement::blockExit()
int DoStatement::comeFrom()
{
if (body)
- return body->comeFrom();
+ return body->comeFrom();
return FALSE;
}
@@ -1087,7 +1087,7 @@ void DoStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring("do");
buf->writenl();
if (body)
- body->toCBuffer(buf, hgs);
+ body->toCBuffer(buf, hgs);
buf->writestring("while (");
condition->toCBuffer(buf, hgs);
buf->writebyte(')');
@@ -1108,13 +1108,13 @@ Statement *ForStatement::syntaxCopy()
{
Statement *i = NULL;
if (init)
- i = init->syntaxCopy();
+ i = init->syntaxCopy();
Expression *c = NULL;
if (condition)
- c = condition->syntaxCopy();
+ c = condition->syntaxCopy();
Expression *inc = NULL;
if (increment)
- inc = increment->syntaxCopy();
+ inc = increment->syntaxCopy();
ForStatement *s = new ForStatement(loc, i, c, inc, body->syntaxCopy());
return s;
}
@@ -1125,30 +1125,30 @@ Statement *ForStatement::semantic(Scope *sc)
sym->parent = sc->scopesym;
sc = sc->push(sym);
if (init)
- init = init->semantic(sc);
+ init = init->semantic(sc);
#if 0
if (!condition)
- // Use a default value
- condition = new IntegerExp(loc, 1, Type::tboolean);
+ // Use a default value
+ condition = new IntegerExp(loc, 1, Type::tboolean);
#endif
sc->noctor++;
if (condition)
{
- condition = condition->semantic(sc);
- condition = resolveProperties(sc, condition);
- condition = condition->optimize(WANTvalue);
- condition = condition->checkToBoolean();
+ condition = condition->semantic(sc);
+ condition = resolveProperties(sc, condition);
+ condition = condition->optimize(WANTvalue);
+ condition = condition->checkToBoolean();
}
if (increment)
- { increment = increment->semantic(sc);
- increment = resolveProperties(sc, increment);
- increment = increment->optimize(0);
+ { increment = increment->semantic(sc);
+ increment = resolveProperties(sc, increment);
+ increment = increment->optimize(0);
}
sc->sbreak = this;
sc->scontinue = this;
if (body)
- body = body->semantic(sc);
+ body = body->semantic(sc);
sc->noctor--;
sc->pop();
@@ -1160,9 +1160,9 @@ void ForStatement::scopeCode(Scope *sc, Statement **sentry, Statement **sexcepti
//printf("ForStatement::scopeCode()\n");
//print();
if (init)
- init->scopeCode(sc, sentry, sexception, sfinally);
+ init->scopeCode(sc, sentry, sexception, sfinally);
else
- Statement::scopeCode(sc, sentry, sexception, sfinally);
+ Statement::scopeCode(sc, sentry, sexception, sfinally);
}
int ForStatement::hasBreak()
@@ -1185,28 +1185,28 @@ int ForStatement::blockExit()
{ int result = BEfallthru;
if (init)
- { result = init->blockExit();
- if (!(result & BEfallthru))
- return result;
+ { result = init->blockExit();
+ if (!(result & BEfallthru))
+ return result;
}
if (condition)
- { if (condition->canThrow())
- result |= BEthrow;
- if (condition->isBool(TRUE))
- result &= ~BEfallthru;
- else if (condition->isBool(FALSE))
- return result;
+ { if (condition->canThrow())
+ result |= BEthrow;
+ if (condition->isBool(TRUE))
+ result &= ~BEfallthru;
+ else if (condition->isBool(FALSE))
+ return result;
}
else
- result &= ~BEfallthru; // the body must do the exiting
+ result &= ~BEfallthru; // the body must do the exiting
if (body)
- { int r = body->blockExit();
- if (r & (BEbreak | BEgoto))
- result |= BEfallthru;
- result |= r & ~(BEfallthru | BEbreak | BEcontinue);
+ { int r = body->blockExit();
+ if (r & (BEbreak | BEgoto))
+ result |= BEfallthru;
+ result |= r & ~(BEfallthru | BEbreak | BEcontinue);
}
if (increment && increment->canThrow())
- result |= BEthrow;
+ result |= BEthrow;
return result;
}
@@ -1215,9 +1215,9 @@ int ForStatement::comeFrom()
{
//printf("ForStatement::comeFrom()\n");
if (body)
- { int result = body->comeFrom();
- //printf("result = %d\n", result);
- return result;
+ { int result = body->comeFrom();
+ //printf("result = %d\n", result);
+ return result;
}
return FALSE;
}
@@ -1254,7 +1254,7 @@ void ForStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/******************************** ForeachStatement ***************************/
ForeachStatement::ForeachStatement(Loc loc, enum TOK op, Parameters *arguments,
- Expression *aggr, Statement *body)
+ Expression *aggr, Statement *body)
: Statement(loc)
{
this->op = op;
@@ -1273,7 +1273,7 @@ Statement *ForeachStatement::syntaxCopy()
Parameters *args = Parameter::arraySyntaxCopy(arguments);
Expression *exp = aggr->syntaxCopy();
ForeachStatement *s = new ForeachStatement(loc, op, args, exp,
- body ? body->syntaxCopy() : NULL);
+ body ? body->syntaxCopy() : NULL);
return s;
}
@@ -1290,15 +1290,15 @@ Statement *ForeachStatement::semantic(Scope *sc)
func = sc->func;
if (func->fes)
- func = func->fes->func;
+ func = func->fes->func;
aggr = aggr->semantic(sc);
aggr = resolveProperties(sc, aggr);
aggr = aggr->optimize(WANTvalue);
if (!aggr->type)
{
- error("invalid foreach aggregate %s", aggr->toChars());
- return this;
+ error("invalid foreach aggregate %s", aggr->toChars());
+ return this;
}
inferApplyArgTypes(op, arguments, aggr, sc->module);
@@ -1307,114 +1307,114 @@ Statement *ForeachStatement::semantic(Scope *sc)
*/
if (dim != arguments->dim)
{
- //printf("dim = %d, arguments->dim = %d\n", dim, arguments->dim);
- error("cannot uniquely infer foreach argument types");
- return this;
+ //printf("dim = %d, arguments->dim = %d\n", dim, arguments->dim);
+ error("cannot uniquely infer foreach argument types");
+ return this;
}
Type *tab = aggr->type->toBasetype();
- if (tab->ty == Ttuple) // don't generate new scope for tuple loops
+ if (tab->ty == Ttuple) // don't generate new scope for tuple loops
{
- if (dim < 1 || dim > 2)
- {
- error("only one (value) or two (key,value) arguments for tuple foreach");
- return s;
- }
+ if (dim < 1 || dim > 2)
+ {
+ error("only one (value) or two (key,value) arguments for tuple foreach");
+ return s;
+ }
- TypeTuple *tuple = (TypeTuple *)tab;
- Statements *statements = new Statements();
- //printf("aggr: op = %d, %s\n", aggr->op, aggr->toChars());
- size_t n;
- TupleExp *te = NULL;
- if (aggr->op == TOKtuple) // expression tuple
- { te = (TupleExp *)aggr;
- n = te->exps->dim;
- }
- else if (aggr->op == TOKtype) // type tuple
- {
- n = Parameter::dim(tuple->arguments);
- }
- else
- assert(0);
- for (size_t j = 0; j < n; j++)
- { size_t k = (op == TOKforeach) ? j : n - 1 - j;
- Expression *e;
- Type *t;
- if (te)
- e = (Expression *)te->exps->data[k];
- else
- t = Parameter::getNth(tuple->arguments, k)->type;
- Parameter *arg = (Parameter *)arguments->data[0];
- Statements *st = new Statements();
+ TypeTuple *tuple = (TypeTuple *)tab;
+ Statements *statements = new Statements();
+ //printf("aggr: op = %d, %s\n", aggr->op, aggr->toChars());
+ size_t n;
+ TupleExp *te = NULL;
+ if (aggr->op == TOKtuple) // expression tuple
+ { te = (TupleExp *)aggr;
+ n = te->exps->dim;
+ }
+ else if (aggr->op == TOKtype) // type tuple
+ {
+ n = Parameter::dim(tuple->arguments);
+ }
+ else
+ assert(0);
+ for (size_t j = 0; j < n; j++)
+ { size_t k = (op == TOKforeach) ? j : n - 1 - j;
+ Expression *e;
+ Type *t;
+ if (te)
+ e = (Expression *)te->exps->data[k];
+ else
+ t = Parameter::getNth(tuple->arguments, k)->type;
+ Parameter *arg = (Parameter *)arguments->data[0];
+ Statements *st = new Statements();
- if (dim == 2)
- { // Declare key
- if (arg->storageClass & (STCout | STCref | STClazy))
- error("no storage class for key %s", arg->ident->toChars());
- TY keyty = arg->type->ty;
- if (keyty != Tint32 && keyty != Tuns32)
- {
- if (global.params.is64bit)
- {
- if (keyty != Tint64 && keyty != Tuns64)
- error("foreach: key type must be int or uint, long or ulong, not %s", arg->type->toChars());
- }
- else
- error("foreach: key type must be int or uint, not %s", arg->type->toChars());
- }
- Initializer *ie = new ExpInitializer(0, new IntegerExp(k));
- VarDeclaration *var = new VarDeclaration(loc, arg->type, arg->ident, ie);
- var->storage_class |= STCconst;
- DeclarationExp *de = new DeclarationExp(loc, var);
- st->push(new ExpStatement(loc, de));
- arg = (Parameter *)arguments->data[1]; // value
- }
- // Declare value
- if (arg->storageClass & (STCout | STCref | STClazy))
- error("no storage class for value %s", arg->ident->toChars());
- Dsymbol *var;
- if (te)
- { Type *tb = e->type->toBasetype();
- if ((tb->ty == Tfunction || tb->ty == Tsarray) && e->op == TOKvar)
- { VarExp *ve = (VarExp *)e;
- var = new AliasDeclaration(loc, arg->ident, ve->var);
- }
- else
- {
- arg->type = e->type;
- Initializer *ie = new ExpInitializer(0, e);
- VarDeclaration *v = new VarDeclaration(loc, arg->type, arg->ident, ie);
- if (e->isConst())
- v->storage_class |= STCconst;
- var = v;
- }
- }
- else
- {
- var = new AliasDeclaration(loc, arg->ident, t);
- }
- DeclarationExp *de = new DeclarationExp(loc, var);
- st->push(new ExpStatement(loc, de));
+ if (dim == 2)
+ { // Declare key
+ if (arg->storageClass & (STCout | STCref | STClazy))
+ error("no storage class for key %s", arg->ident->toChars());
+ TY keyty = arg->type->ty;
+ if (keyty != Tint32 && keyty != Tuns32)
+ {
+ if (global.params.is64bit)
+ {
+ if (keyty != Tint64 && keyty != Tuns64)
+ error("foreach: key type must be int or uint, long or ulong, not %s", arg->type->toChars());
+ }
+ else
+ error("foreach: key type must be int or uint, not %s", arg->type->toChars());
+ }
+ Initializer *ie = new ExpInitializer(0, new IntegerExp(k));
+ VarDeclaration *var = new VarDeclaration(loc, arg->type, arg->ident, ie);
+ var->storage_class |= STCconst;
+ DeclarationExp *de = new DeclarationExp(loc, var);
+ st->push(new ExpStatement(loc, de));
+ arg = (Parameter *)arguments->data[1]; // value
+ }
+ // Declare value
+ if (arg->storageClass & (STCout | STCref | STClazy))
+ error("no storage class for value %s", arg->ident->toChars());
+ Dsymbol *var;
+ if (te)
+ { Type *tb = e->type->toBasetype();
+ if ((tb->ty == Tfunction || tb->ty == Tsarray) && e->op == TOKvar)
+ { VarExp *ve = (VarExp *)e;
+ var = new AliasDeclaration(loc, arg->ident, ve->var);
+ }
+ else
+ {
+ arg->type = e->type;
+ Initializer *ie = new ExpInitializer(0, e);
+ VarDeclaration *v = new VarDeclaration(loc, arg->type, arg->ident, ie);
+ if (e->isConst())
+ v->storage_class |= STCconst;
+ var = v;
+ }
+ }
+ else
+ {
+ var = new AliasDeclaration(loc, arg->ident, t);
+ }
+ DeclarationExp *de = new DeclarationExp(loc, var);
+ st->push(new ExpStatement(loc, de));
- st->push(body->syntaxCopy());
- s = new CompoundStatement(loc, st);
- s = new ScopeStatement(loc, s);
- statements->push(s);
- }
+ st->push(body->syntaxCopy());
+ s = new CompoundStatement(loc, st);
+ s = new ScopeStatement(loc, s);
+ statements->push(s);
+ }
- s = new UnrolledLoopStatement(loc, statements);
- s = s->semantic(sc);
- return s;
+ s = new UnrolledLoopStatement(loc, statements);
+ s = s->semantic(sc);
+ return s;
}
for (size_t i = 0; i < dim; i++)
- { Parameter *arg = (Parameter *)arguments->data[i];
- if (!arg->type)
- {
- error("cannot infer type for %s", arg->ident->toChars());
- return this;
- }
+ { Parameter *arg = (Parameter *)arguments->data[i];
+ if (!arg->type)
+ {
+ error("cannot infer type for %s", arg->ident->toChars());
+ return this;
+ }
}
sym = new ScopeDsymbol();
@@ -1425,373 +1425,373 @@ Statement *ForeachStatement::semantic(Scope *sc)
switch (tab->ty)
{
- case Tarray:
- case Tsarray:
- if (dim < 1 || dim > 2)
- {
- error("only one or two arguments for array foreach");
- break;
- }
+ case Tarray:
+ case Tsarray:
+ if (dim < 1 || dim > 2)
+ {
+ error("only one or two arguments for array foreach");
+ break;
+ }
- /* Look for special case of parsing char types out of char type
- * array.
- */
- tn = tab->nextOf()->toBasetype();
- if (tn->ty == Tchar || tn->ty == Twchar || tn->ty == Tdchar)
- { Parameter *arg;
+ /* Look for special case of parsing char types out of char type
+ * array.
+ */
+ tn = tab->nextOf()->toBasetype();
+ if (tn->ty == Tchar || tn->ty == Twchar || tn->ty == Tdchar)
+ { Parameter *arg;
- int i = (dim == 1) ? 0 : 1; // index of value
- arg = (Parameter *)arguments->data[i];
- arg->type = arg->type->semantic(loc, sc);
- tnv = arg->type->toBasetype();
- if (tnv->ty != tn->ty &&
- (tnv->ty == Tchar || tnv->ty == Twchar || tnv->ty == Tdchar))
- {
- if (arg->storageClass & STCref)
- error("foreach: value of UTF conversion cannot be ref");
- if (dim == 2)
- { arg = (Parameter *)arguments->data[0];
- if (arg->storageClass & STCref)
- error("foreach: key cannot be ref");
- }
- goto Lapply;
- }
- }
+ int i = (dim == 1) ? 0 : 1; // index of value
+ arg = (Parameter *)arguments->data[i];
+ arg->type = arg->type->semantic(loc, sc);
+ tnv = arg->type->toBasetype();
+ if (tnv->ty != tn->ty &&
+ (tnv->ty == Tchar || tnv->ty == Twchar || tnv->ty == Tdchar))
+ {
+ if (arg->storageClass & STCref)
+ error("foreach: value of UTF conversion cannot be ref");
+ if (dim == 2)
+ { arg = (Parameter *)arguments->data[0];
+ if (arg->storageClass & STCref)
+ error("foreach: key cannot be ref");
+ }
+ goto Lapply;
+ }
+ }
- for (size_t i = 0; i < dim; i++)
- { // Declare args
- Parameter *arg = (Parameter *)arguments->data[i];
- Type *argtype = arg->type->semantic(loc, sc);
- VarDeclaration *var;
+ for (size_t i = 0; i < dim; i++)
+ { // Declare args
+ Parameter *arg = (Parameter *)arguments->data[i];
+ Type *argtype = arg->type->semantic(loc, sc);
+ VarDeclaration *var;
- var = new VarDeclaration(loc, argtype, arg->ident, NULL);
- var->storage_class |= STCforeach;
- var->storage_class |= arg->storageClass & (STCin | STCout | STCref);
+ var = new VarDeclaration(loc, argtype, arg->ident, NULL);
+ var->storage_class |= STCforeach;
+ var->storage_class |= arg->storageClass & (STCin | STCout | STCref);
- if (dim == 2 && i == 0)
- key = var;
- else
- value = var;
+ if (dim == 2 && i == 0)
+ key = var;
+ else
+ value = var;
#if 0
- DeclarationExp *de = new DeclarationExp(loc, var);
- de->semantic(sc);
+ DeclarationExp *de = new DeclarationExp(loc, var);
+ de->semantic(sc);
#endif
- }
+ }
#if 1
- {
- /* Convert to a ForStatement
- * foreach (key, value; a) body =>
- * for (T[] tmp = a[], size_t key; key < tmp.length; ++key)
- * { T value = tmp[k]; body }
- *
- * foreach_reverse (key, value; a) body =>
- * for (T[] tmp = a[], size_t key = tmp.length; key--; )
- * { T value = tmp[k]; body }
- */
- Identifier *id = Lexer::uniqueId("__aggr");
- ExpInitializer *ie = new ExpInitializer(loc, new SliceExp(loc, aggr, NULL, NULL));
- VarDeclaration *tmp = new VarDeclaration(loc, aggr->type->nextOf()->arrayOf(), id, ie);
+ {
+ /* Convert to a ForStatement
+ * foreach (key, value; a) body =>
+ * for (T[] tmp = a[], size_t key; key < tmp.length; ++key)
+ * { T value = tmp[k]; body }
+ *
+ * foreach_reverse (key, value; a) body =>
+ * for (T[] tmp = a[], size_t key = tmp.length; key--; )
+ * { T value = tmp[k]; body }
+ */
+ Identifier *id = Lexer::uniqueId("__aggr");
+ ExpInitializer *ie = new ExpInitializer(loc, new SliceExp(loc, aggr, NULL, NULL));
+ VarDeclaration *tmp = new VarDeclaration(loc, aggr->type->nextOf()->arrayOf(), id, ie);
- Expression *tmp_length = new DotIdExp(loc, new VarExp(loc, tmp), Id::length);
+ Expression *tmp_length = new DotIdExp(loc, new VarExp(loc, tmp), Id::length);
- if (!key)
- {
- Identifier *id = Lexer::uniqueId("__key");
- key = new VarDeclaration(loc, Type::tsize_t, id, NULL);
- }
- if (op == TOKforeach_reverse)
- key->init = new ExpInitializer(loc, tmp_length);
- else
- key->init = new ExpInitializer(loc, new IntegerExp(0));
+ if (!key)
+ {
+ Identifier *id = Lexer::uniqueId("__key");
+ key = new VarDeclaration(loc, Type::tsize_t, id, NULL);
+ }
+ if (op == TOKforeach_reverse)
+ key->init = new ExpInitializer(loc, tmp_length);
+ else
+ key->init = new ExpInitializer(loc, new IntegerExp(0));
- Statements *cs = new Statements();
- cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
- cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, key)));
- Statement *forinit = new CompoundDeclarationStatement(loc, cs);
+ Statements *cs = new Statements();
+ cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
+ cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, key)));
+ Statement *forinit = new CompoundDeclarationStatement(loc, cs);
- Expression *cond;
- if (op == TOKforeach_reverse)
- // key--
- cond = new PostExp(TOKminusminus, loc, new VarExp(loc, key));
- else
- // key < tmp.length
- cond = new CmpExp(TOKlt, loc, new VarExp(loc, key), tmp_length);
+ Expression *cond;
+ if (op == TOKforeach_reverse)
+ // key--
+ cond = new PostExp(TOKminusminus, loc, new VarExp(loc, key));
+ else
+ // key < tmp.length
+ cond = new CmpExp(TOKlt, loc, new VarExp(loc, key), tmp_length);
- Expression *increment = NULL;
- if (op == TOKforeach)
- // key += 1
- increment = new AddAssignExp(loc, new VarExp(loc, key), new IntegerExp(1));
+ Expression *increment = NULL;
+ if (op == TOKforeach)
+ // key += 1
+ increment = new AddAssignExp(loc, new VarExp(loc, key), new IntegerExp(1));
- // T value = tmp[key];
- value->init = new ExpInitializer(loc, new IndexExp(loc, new VarExp(loc, tmp), new VarExp(loc, key)));
- Statement *ds = new DeclarationStatement(loc, new DeclarationExp(loc, value));
+ // T value = tmp[key];
+ value->init = new ExpInitializer(loc, new IndexExp(loc, new VarExp(loc, tmp), new VarExp(loc, key)));
+ Statement *ds = new DeclarationStatement(loc, new DeclarationExp(loc, value));
- body = new CompoundStatement(loc, ds, body);
+ body = new CompoundStatement(loc, ds, body);
- ForStatement *fs = new ForStatement(loc, forinit, cond, increment, body);
- s = fs->semantic(sc);
- break;
- }
+ ForStatement *fs = new ForStatement(loc, forinit, cond, increment, body);
+ s = fs->semantic(sc);
+ break;
+ }
#else
- if (!value->type->equals(tab->next))
- {
- if (aggr->op == TOKstring)
- aggr = aggr->implicitCastTo(sc, value->type->arrayOf());
- else
- error("foreach: %s is not an array of %s",
- tab->toChars(), value->type->toChars());
- }
+ if (!value->type->equals(tab->next))
+ {
+ if (aggr->op == TOKstring)
+ aggr = aggr->implicitCastTo(sc, value->type->arrayOf());
+ else
+ error("foreach: %s is not an array of %s",
+ tab->toChars(), value->type->toChars());
+ }
- if (key)
- {
- if (key->type->ty != Tint32 && key->type->ty != Tuns32)
- {
- if (global.params.is64bit)
- {
- if (key->type->ty != Tint64 && key->type->ty != Tuns64)
- error("foreach: key type must be int or uint, long or ulong, not %s", key->type->toChars());
- }
- else
- error("foreach: key type must be int or uint, not %s", key->type->toChars());
- }
+ if (key)
+ {
+ if (key->type->ty != Tint32 && key->type->ty != Tuns32)
+ {
+ if (global.params.is64bit)
+ {
+ if (key->type->ty != Tint64 && key->type->ty != Tuns64)
+ error("foreach: key type must be int or uint, long or ulong, not %s", key->type->toChars());
+ }
+ else
+ error("foreach: key type must be int or uint, not %s", key->type->toChars());
+ }
- if (key->storage_class & (STCout | STCref))
- error("foreach: key cannot be out or ref");
- }
+ if (key->storage_class & (STCout | STCref))
+ error("foreach: key cannot be out or ref");
+ }
- sc->sbreak = this;
- sc->scontinue = this;
- body = body->semantic(sc);
- break;
+ sc->sbreak = this;
+ sc->scontinue = this;
+ body = body->semantic(sc);
+ break;
#endif
- case Taarray:
- taa = (TypeAArray *)tab;
- if (dim < 1 || dim > 2)
- {
- error("only one or two arguments for associative array foreach");
- break;
- }
- if (op == TOKforeach_reverse)
- {
- error("no reverse iteration on associative arrays");
- }
- goto Lapply;
+ case Taarray:
+ taa = (TypeAArray *)tab;
+ if (dim < 1 || dim > 2)
+ {
+ error("only one or two arguments for associative array foreach");
+ break;
+ }
+ if (op == TOKforeach_reverse)
+ {
+ error("no reverse iteration on associative arrays");
+ }
+ goto Lapply;
- case Tclass:
- case Tstruct:
+ case Tclass:
+ case Tstruct:
#if DMDV2
- { /* Look for range iteration, i.e. the properties
- * .empty, .next, .retreat, .head and .rear
- * foreach (e; aggr) { ... }
- * translates to:
- * for (auto __r = aggr[]; !__r.empty; __r.next)
- * { auto e = __r.head;
- * ...
- * }
- */
- if (dim != 1) // only one argument allowed with ranges
- goto Lapply;
- AggregateDeclaration *ad = (tab->ty == Tclass)
- ? (AggregateDeclaration *)((TypeClass *)tab)->sym
- : (AggregateDeclaration *)((TypeStruct *)tab)->sym;
- Identifier *idhead;
- Identifier *idnext;
- if (op == TOKforeach)
- { idhead = Id::Fhead;
- idnext = Id::Fnext;
- }
- else
- { idhead = Id::Ftoe;
- idnext = Id::Fretreat;
- }
- Dsymbol *shead = search_function(ad, idhead);
- if (!shead)
- goto Lapply;
+ { /* Look for range iteration, i.e. the properties
+ * .empty, .next, .retreat, .head and .rear
+ * foreach (e; aggr) { ... }
+ * translates to:
+ * for (auto __r = aggr[]; !__r.empty; __r.next)
+ * { auto e = __r.head;
+ * ...
+ * }
+ */
+ if (dim != 1) // only one argument allowed with ranges
+ goto Lapply;
+ AggregateDeclaration *ad = (tab->ty == Tclass)
+ ? (AggregateDeclaration *)((TypeClass *)tab)->sym
+ : (AggregateDeclaration *)((TypeStruct *)tab)->sym;
+ Identifier *idhead;
+ Identifier *idnext;
+ if (op == TOKforeach)
+ { idhead = Id::Fhead;
+ idnext = Id::Fnext;
+ }
+ else
+ { idhead = Id::Ftoe;
+ idnext = Id::Fretreat;
+ }
+ Dsymbol *shead = search_function(ad, idhead);
+ if (!shead)
+ goto Lapply;
- /* Generate a temporary __r and initialize it with the aggregate.
- */
- Identifier *id = Identifier::generateId("__r");
- Expression *rinit = new SliceExp(loc, aggr, NULL, NULL);
- rinit = rinit->trySemantic(sc);
- if (!rinit) // if application of [] failed
- rinit = aggr;
- VarDeclaration *r = new VarDeclaration(loc, NULL, id, new ExpInitializer(loc, rinit));
-// r->semantic(sc);
+ /* Generate a temporary __r and initialize it with the aggregate.
+ */
+ Identifier *id = Identifier::generateId("__r");
+ Expression *rinit = new SliceExp(loc, aggr, NULL, NULL);
+ rinit = rinit->trySemantic(sc);
+ if (!rinit) // if application of [] failed
+ rinit = aggr;
+ VarDeclaration *r = new VarDeclaration(loc, NULL, id, new ExpInitializer(loc, rinit));
+// r->semantic(sc);
//printf("r: %s, init: %s\n", r->toChars(), r->init->toChars());
- Statement *init = new DeclarationStatement(loc, r);
+ Statement *init = new DeclarationStatement(loc, r);
//printf("init: %s\n", init->toChars());
- // !__r.empty
- Expression *e = new VarExp(loc, r);
- e = new DotIdExp(loc, e, Id::Fempty);
- Expression *condition = new NotExp(loc, e);
+ // !__r.empty
+ Expression *e = new VarExp(loc, r);
+ e = new DotIdExp(loc, e, Id::Fempty);
+ Expression *condition = new NotExp(loc, e);
- // __r.next
- e = new VarExp(loc, r);
- Expression *increment = new DotIdExp(loc, e, idnext);
+ // __r.next
+ e = new VarExp(loc, r);
+ Expression *increment = new DotIdExp(loc, e, idnext);
- /* Declaration statement for e:
- * auto e = __r.idhead;
- */
- e = new VarExp(loc, r);
- Expression *einit = new DotIdExp(loc, e, idhead);
-// einit = einit->semantic(sc);
- Parameter *arg = (Parameter *)arguments->data[0];
- VarDeclaration *ve = new VarDeclaration(loc, arg->type, arg->ident, new ExpInitializer(loc, einit));
- ve->storage_class |= STCforeach;
- ve->storage_class |= arg->storageClass & (STCin | STCout | STCref | STC_TYPECTOR);
+ /* Declaration statement for e:
+ * auto e = __r.idhead;
+ */
+ e = new VarExp(loc, r);
+ Expression *einit = new DotIdExp(loc, e, idhead);
+// einit = einit->semantic(sc);
+ Parameter *arg = (Parameter *)arguments->data[0];
+ VarDeclaration *ve = new VarDeclaration(loc, arg->type, arg->ident, new ExpInitializer(loc, einit));
+ ve->storage_class |= STCforeach;
+ ve->storage_class |= arg->storageClass & (STCin | STCout | STCref | STC_TYPECTOR);
- DeclarationExp *de = new DeclarationExp(loc, ve);
+ DeclarationExp *de = new DeclarationExp(loc, ve);
- Statement *body = new CompoundStatement(loc,
- new DeclarationStatement(loc, de), this->body);
+ Statement *body = new CompoundStatement(loc,
+ new DeclarationStatement(loc, de), this->body);
- s = new ForStatement(loc, init, condition, increment, body);
+ s = new ForStatement(loc, init, condition, increment, body);
#if 0
- printf("init: %s\n", init->toChars());
- printf("condition: %s\n", condition->toChars());
- printf("increment: %s\n", increment->toChars());
- printf("body: %s\n", body->toChars());
+ printf("init: %s\n", init->toChars());
+ printf("condition: %s\n", condition->toChars());
+ printf("increment: %s\n", increment->toChars());
+ printf("body: %s\n", body->toChars());
#endif
- s = s->semantic(sc);
- break;
- }
+ s = s->semantic(sc);
+ break;
+ }
#endif
- case Tdelegate:
- Lapply:
- { FuncDeclaration *fdapply;
- Parameters *args;
- Expression *ec;
- Expression *e;
- FuncLiteralDeclaration *fld;
- Parameter *a;
- Type *t;
- Expression *flde;
- Identifier *id;
- Type *tret;
+ case Tdelegate:
+ Lapply:
+ { FuncDeclaration *fdapply;
+ Parameters *args;
+ Expression *ec;
+ Expression *e;
+ FuncLiteralDeclaration *fld;
+ Parameter *a;
+ Type *t;
+ Expression *flde;
+ Identifier *id;
+ Type *tret;
TypeDelegate* dgty;
TypeDelegate* dgty2;
TypeDelegate* fldeTy;
- tret = func->type->nextOf();
+ tret = func->type->nextOf();
- // Need a variable to hold value from any return statements in body.
- if (!sc->func->vresult && tret && tret != Type::tvoid)
- { VarDeclaration *v;
+ // Need a variable to hold value from any return statements in body.
+ if (!sc->func->vresult && tret && tret != Type::tvoid)
+ { VarDeclaration *v;
- v = new VarDeclaration(loc, tret, Id::result, NULL);
- v->noscope = 1;
- v->semantic(sc);
- if (!sc->insert(v))
- assert(0);
- v->parent = sc->func;
- sc->func->vresult = v;
- }
+ v = new VarDeclaration(loc, tret, Id::result, NULL);
+ v->noscope = 1;
+ v->semantic(sc);
+ if (!sc->insert(v))
+ assert(0);
+ v->parent = sc->func;
+ sc->func->vresult = v;
+ }
- /* Turn body into the function literal:
- * int delegate(ref T arg) { body }
- */
- args = new Parameters();
- for (size_t i = 0; i < dim; i++)
- { Parameter *arg = (Parameter *)arguments->data[i];
+ /* Turn body into the function literal:
+ * int delegate(ref T arg) { body }
+ */
+ args = new Parameters();
+ for (size_t i = 0; i < dim; i++)
+ { Parameter *arg = (Parameter *)arguments->data[i];
- arg->type = arg->type->semantic(loc, sc);
- if (arg->storageClass & STCref)
- id = arg->ident;
- else
- { // Make a copy of the ref argument so it isn't
- // a reference.
- VarDeclaration *v;
- Initializer *ie;
+ arg->type = arg->type->semantic(loc, sc);
+ if (arg->storageClass & STCref)
+ id = arg->ident;
+ else
+ { // Make a copy of the ref argument so it isn't
+ // a reference.
+ VarDeclaration *v;
+ Initializer *ie;
- id = Lexer::uniqueId("__applyArg", i);
+ id = Lexer::uniqueId("__applyArg", i);
- ie = new ExpInitializer(0, new IdentifierExp(0, id));
- v = new VarDeclaration(0, arg->type, arg->ident, ie);
- s = new DeclarationStatement(0, v);
- body = new CompoundStatement(loc, s, body);
- }
- a = new Parameter(STCref, arg->type, id, NULL);
- args->push(a);
- }
- t = new TypeFunction(args, Type::tint32, 0, LINKd);
- fld = new FuncLiteralDeclaration(loc, 0, t, TOKdelegate, this);
- fld->fbody = body;
- flde = new FuncExp(loc, fld);
- flde = flde->semantic(sc);
+ ie = new ExpInitializer(0, new IdentifierExp(0, id));
+ v = new VarDeclaration(0, arg->type, arg->ident, ie);
+ s = new DeclarationStatement(0, v);
+ body = new CompoundStatement(loc, s, body);
+ }
+ a = new Parameter(STCref, arg->type, id, NULL);
+ args->push(a);
+ }
+ t = new TypeFunction(args, Type::tint32, 0, LINKd);
+ fld = new FuncLiteralDeclaration(loc, 0, t, TOKdelegate, this);
+ fld->fbody = body;
+ flde = new FuncExp(loc, fld);
+ flde = flde->semantic(sc);
- // Resolve any forward referenced goto's
- for (int i = 0; i < gotos.dim; i++)
- { CompoundStatement *cs = (CompoundStatement *)gotos.data[i];
- GotoStatement *gs = (GotoStatement *)cs->statements->data[0];
+ // Resolve any forward referenced goto's
+ for (int i = 0; i < gotos.dim; i++)
+ { CompoundStatement *cs = (CompoundStatement *)gotos.data[i];
+ GotoStatement *gs = (GotoStatement *)cs->statements->data[0];
- if (!gs->label->statement)
- { // 'Promote' it to this scope, and replace with a return
- cases.push(gs);
- s = new ReturnStatement(0, new IntegerExp(cases.dim + 1));
- cs->statements->data[0] = (void *)s;
- }
- }
+ if (!gs->label->statement)
+ { // 'Promote' it to this scope, and replace with a return
+ cases.push(gs);
+ s = new ReturnStatement(0, new IntegerExp(cases.dim + 1));
+ cs->statements->data[0] = (void *)s;
+ }
+ }
- if (tab->ty == Taarray)
- {
- // Check types
- Parameter *arg = (Parameter *)arguments->data[0];
- if (dim == 2)
- {
- if (arg->storageClass & STCref)
- error("foreach: index cannot be ref");
- if (!arg->type->equals(taa->index))
- error("foreach: index must be type %s, not %s", taa->index->toChars(), arg->type->toChars());
- arg = (Parameter *)arguments->data[1];
- }
- if (!arg->type->equals(taa->nextOf()))
- error("foreach: value must be type %s, not %s", taa->nextOf()->toChars(), arg->type->toChars());
+ if (tab->ty == Taarray)
+ {
+ // Check types
+ Parameter *arg = (Parameter *)arguments->data[0];
+ if (dim == 2)
+ {
+ if (arg->storageClass & STCref)
+ error("foreach: index cannot be ref");
+ if (!arg->type->equals(taa->index))
+ error("foreach: index must be type %s, not %s", taa->index->toChars(), arg->type->toChars());
+ arg = (Parameter *)arguments->data[1];
+ }
+ if (!arg->type->equals(taa->nextOf()))
+ error("foreach: value must be type %s, not %s", taa->nextOf()->toChars(), arg->type->toChars());
- /* Call:
- * _aaApply(aggr, keysize, flde)
- */
- //LDC: Build arguments.
- static FuncDeclaration *aaApply2_fd = NULL;
+ /* Call:
+ * _aaApply(aggr, keysize, flde)
+ */
+ //LDC: Build arguments.
+ static FuncDeclaration *aaApply2_fd = NULL;
static TypeDelegate* aaApply2_dg;
- if(!aaApply2_fd) {
- Parameters* args = new Parameters;
- args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
- args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
- Parameters* dgargs = new Parameters;
- dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
- dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
- aaApply2_dg = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd));
- args->push(new Parameter(STCin, aaApply2_dg, NULL, NULL));
- aaApply2_fd = FuncDeclaration::genCfunc(args, Type::tindex, "_aaApply2");
- }
- static FuncDeclaration *aaApply_fd = NULL;
+ if(!aaApply2_fd) {
+ Parameters* args = new Parameters;
+ args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
+ args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
+ Parameters* dgargs = new Parameters;
+ dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
+ dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
+ aaApply2_dg = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd));
+ args->push(new Parameter(STCin, aaApply2_dg, NULL, NULL));
+ aaApply2_fd = FuncDeclaration::genCfunc(args, Type::tindex, "_aaApply2");
+ }
+ static FuncDeclaration *aaApply_fd = NULL;
static TypeDelegate* aaApply_dg;
- if(!aaApply_fd) {
- Parameters* args = new Parameters;
- args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
- args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
- Parameters* dgargs = new Parameters;
- dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
- aaApply_dg = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd));
- args->push(new Parameter(STCin, aaApply_dg, NULL, NULL));
- aaApply_fd = FuncDeclaration::genCfunc(args, Type::tindex, "_aaApply");
- }
- if (dim == 2) {
- fdapply = aaApply2_fd;
+ if(!aaApply_fd) {
+ Parameters* args = new Parameters;
+ args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL));
+ args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL));
+ Parameters* dgargs = new Parameters;
+ dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
+ aaApply_dg = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd));
+ args->push(new Parameter(STCin, aaApply_dg, NULL, NULL));
+ aaApply_fd = FuncDeclaration::genCfunc(args, Type::tindex, "_aaApply");
+ }
+ if (dim == 2) {
+ fdapply = aaApply2_fd;
fldeTy = aaApply2_dg;
- } else {
- fdapply = aaApply_fd;
+ } else {
+ fdapply = aaApply_fd;
fldeTy = aaApply_dg;
- }
- ec = new VarExp(0, fdapply);
- Expressions *exps = new Expressions();
- exps->push(aggr);
- size_t keysize = taa->key->size();
- keysize = (keysize + (PTRSIZE-1)) & ~(PTRSIZE-1);
- exps->push(new IntegerExp(0, keysize, Type::tsize_t));
+ }
+ ec = new VarExp(0, fdapply);
+ Expressions *exps = new Expressions();
+ exps->push(aggr);
+ size_t keysize = taa->key->size();
+ keysize = (keysize + (PTRSIZE-1)) & ~(PTRSIZE-1);
+ exps->push(new IntegerExp(0, keysize, Type::tsize_t));
// LDC paint delegate argument to the type runtime expects
if (!fldeTy->equals(flde->type))
@@ -1799,66 +1799,66 @@ Statement *ForeachStatement::semantic(Scope *sc)
flde = new CastExp(loc, flde, flde->type);
flde->type = fldeTy;
}
- exps->push(flde);
- e = new CallExp(loc, ec, exps);
- e->type = Type::tindex; // don't run semantic() on e
- }
- else if (tab->ty == Tarray || tab->ty == Tsarray)
- {
- /* Call:
- * _aApply(aggr, flde)
- */
- static char fntab[9][3] =
- { "cc","cw","cd",
- "wc","cc","wd",
- "dc","dw","dd"
- };
- char fdname[7+1+2+ sizeof(dim)*3 + 1];
- int flag;
+ exps->push(flde);
+ e = new CallExp(loc, ec, exps);
+ e->type = Type::tindex; // don't run semantic() on e
+ }
+ else if (tab->ty == Tarray || tab->ty == Tsarray)
+ {
+ /* Call:
+ * _aApply(aggr, flde)
+ */
+ static char fntab[9][3] =
+ { "cc","cw","cd",
+ "wc","cc","wd",
+ "dc","dw","dd"
+ };
+ char fdname[7+1+2+ sizeof(dim)*3 + 1];
+ int flag;
- switch (tn->ty)
- {
- case Tchar: flag = 0; break;
- case Twchar: flag = 3; break;
- case Tdchar: flag = 6; break;
- default: assert(0);
- }
- switch (tnv->ty)
- {
- case Tchar: flag += 0; break;
- case Twchar: flag += 1; break;
- case Tdchar: flag += 2; break;
- default: assert(0);
- }
- const char *r = (op == TOKforeach_reverse) ? "R" : "";
+ switch (tn->ty)
+ {
+ case Tchar: flag = 0; break;
+ case Twchar: flag = 3; break;
+ case Tdchar: flag = 6; break;
+ default: assert(0);
+ }
+ switch (tnv->ty)
+ {
+ case Tchar: flag += 0; break;
+ case Twchar: flag += 1; break;
+ case Tdchar: flag += 2; break;
+ default: assert(0);
+ }
+ const char *r = (op == TOKforeach_reverse) ? "R" : "";
#ifdef __MINGW32__
- int j = sprintf(fdname, "_aApply%s%.*s%lu", r, 2, fntab[flag], dim);
+ int j = sprintf(fdname, "_aApply%s%.*s%lu", r, 2, fntab[flag], dim);
#else
- int j = sprintf(fdname, "_aApply%s%.*s%zu", r, 2, fntab[flag], dim);
+ int j = sprintf(fdname, "_aApply%s%.*s%zu", r, 2, fntab[flag], dim);
#endif
- assert(j < sizeof(fdname));
- //LDC: Build arguments.
- Parameters* args = new Parameters;
- args->push(new Parameter(STCin, tn->arrayOf(), NULL, NULL));
- if (dim == 2) {
- Parameters* dgargs = new Parameters;
- dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
- dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
- dgty = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd));
- args->push(new Parameter(STCin, dgty, NULL, NULL));
- fdapply = FuncDeclaration::genCfunc(args, Type::tindex, fdname);
- } else {
- Parameters* dgargs = new Parameters;
- dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
- dgty = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd));
- args->push(new Parameter(STCin, dgty, NULL, NULL));
- fdapply = FuncDeclaration::genCfunc(args, Type::tindex, fdname);
- }
+ assert(j < sizeof(fdname));
+ //LDC: Build arguments.
+ Parameters* args = new Parameters;
+ args->push(new Parameter(STCin, tn->arrayOf(), NULL, NULL));
+ if (dim == 2) {
+ Parameters* dgargs = new Parameters;
+ dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
+ dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
+ dgty = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd));
+ args->push(new Parameter(STCin, dgty, NULL, NULL));
+ fdapply = FuncDeclaration::genCfunc(args, Type::tindex, fdname);
+ } else {
+ Parameters* dgargs = new Parameters;
+ dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL));
+ dgty = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd));
+ args->push(new Parameter(STCin, dgty, NULL, NULL));
+ fdapply = FuncDeclaration::genCfunc(args, Type::tindex, fdname);
+ }
- ec = new VarExp(0, fdapply);
- Expressions *exps = new Expressions();
- if (tab->ty == Tsarray)
- aggr = aggr->castTo(sc, tn->arrayOf());
+ ec = new VarExp(0, fdapply);
+ Expressions *exps = new Expressions();
+ if (tab->ty == Tsarray)
+ aggr = aggr->castTo(sc, tn->arrayOf());
exps->push(aggr);
// LDC paint delegate argument to the type runtime expects
@@ -1867,70 +1867,70 @@ Statement *ForeachStatement::semantic(Scope *sc)
flde = new CastExp(loc, flde, flde->type);
flde->type = dgty;
}
- exps->push(flde);
- e = new CallExp(loc, ec, exps);
- e->type = Type::tindex; // don't run semantic() on e
- }
- else if (tab->ty == Tdelegate)
- {
- /* Call:
- * aggr(flde)
- */
- Expressions *exps = new Expressions();
- exps->push(flde);
- e = new CallExp(loc, aggr, exps);
- e = e->semantic(sc);
- if (e->type != Type::tint32)
- error("opApply() function for %s must return an int", tab->toChars());
- }
- else
- {
- /* Call:
- * aggr.apply(flde)
- */
- ec = new DotIdExp(loc, aggr,
- (op == TOKforeach_reverse) ? Id::applyReverse
- : Id::apply);
- Expressions *exps = new Expressions();
- exps->push(flde);
- e = new CallExp(loc, ec, exps);
- e = e->semantic(sc);
- if (e->type != Type::tint32)
- error("opApply() function for %s must return an int", tab->toChars());
- }
+ exps->push(flde);
+ e = new CallExp(loc, ec, exps);
+ e->type = Type::tindex; // don't run semantic() on e
+ }
+ else if (tab->ty == Tdelegate)
+ {
+ /* Call:
+ * aggr(flde)
+ */
+ Expressions *exps = new Expressions();
+ exps->push(flde);
+ e = new CallExp(loc, aggr, exps);
+ e = e->semantic(sc);
+ if (e->type != Type::tint32)
+ error("opApply() function for %s must return an int", tab->toChars());
+ }
+ else
+ {
+ /* Call:
+ * aggr.apply(flde)
+ */
+ ec = new DotIdExp(loc, aggr,
+ (op == TOKforeach_reverse) ? Id::applyReverse
+ : Id::apply);
+ Expressions *exps = new Expressions();
+ exps->push(flde);
+ e = new CallExp(loc, ec, exps);
+ e = e->semantic(sc);
+ if (e->type != Type::tint32)
+ error("opApply() function for %s must return an int", tab->toChars());
+ }
- if (!cases.dim)
- // Easy case, a clean exit from the loop
- s = new ExpStatement(loc, e);
- else
- { // Construct a switch statement around the return value
- // of the apply function.
- Statements *a = new Statements();
+ if (!cases.dim)
+ // Easy case, a clean exit from the loop
+ s = new ExpStatement(loc, e);
+ else
+ { // Construct a switch statement around the return value
+ // of the apply function.
+ Statements *a = new Statements();
- // default: break; takes care of cases 0 and 1
- s = new BreakStatement(0, NULL);
- s = new DefaultStatement(0, s);
- a->push(s);
+ // default: break; takes care of cases 0 and 1
+ s = new BreakStatement(0, NULL);
+ s = new DefaultStatement(0, s);
+ a->push(s);
- // cases 2...
- for (int i = 0; i < cases.dim; i++)
- {
- s = (Statement *)cases.data[i];
- s = new CaseStatement(0, new IntegerExp(i + 2), s);
- a->push(s);
- }
+ // cases 2...
+ for (int i = 0; i < cases.dim; i++)
+ {
+ s = (Statement *)cases.data[i];
+ s = new CaseStatement(0, new IntegerExp(i + 2), s);
+ a->push(s);
+ }
- s = new CompoundStatement(loc, a);
- s = new SwitchStatement(loc, e, s);
- s = s->semantic(sc);
- }
- break;
- }
+ s = new CompoundStatement(loc, a);
+ s = new SwitchStatement(loc, e, s);
+ s = s->semantic(sc);
+ }
+ break;
+ }
- default:
- error("foreach: %s is not an aggregate type", aggr->type->toChars());
- s = NULL; // error recovery
- break;
+ default:
+ error("foreach: %s is not an aggregate type", aggr->type->toChars());
+ s = NULL; // error recovery
+ break;
}
sc->noctor--;
sc->pop();
@@ -1956,11 +1956,11 @@ int ForeachStatement::blockExit()
{ int result = BEfallthru;
if (aggr->canThrow())
- result |= BEthrow;
+ result |= BEthrow;
if (body)
{
- result |= body->blockExit() & ~(BEbreak | BEcontinue);
+ result |= body->blockExit() & ~(BEbreak | BEcontinue);
}
return result;
}
@@ -1969,7 +1969,7 @@ int ForeachStatement::blockExit()
int ForeachStatement::comeFrom()
{
if (body)
- return body->comeFrom();
+ return body->comeFrom();
return FALSE;
}
@@ -1979,16 +1979,16 @@ void ForeachStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring(" (");
for (int i = 0; i < arguments->dim; i++)
{
- Parameter *a = (Parameter *)arguments->data[i];
- if (i)
- buf->writestring(", ");
- if (a->storageClass & STCref)
- buf->writestring((global.params.Dversion == 1)
- ? (char*)"inout " : (char*)"ref ");
- if (a->type)
- a->type->toCBuffer(buf, a->ident, hgs);
- else
- buf->writestring(a->ident->toChars());
+ Parameter *a = (Parameter *)arguments->data[i];
+ if (i)
+ buf->writestring(", ");
+ if (a->storageClass & STCref)
+ buf->writestring((global.params.Dversion == 1)
+ ? (char*)"inout " : (char*)"ref ");
+ if (a->type)
+ a->type->toCBuffer(buf, a->ident, hgs);
+ else
+ buf->writestring(a->ident->toChars());
}
buf->writestring("; ");
aggr->toCBuffer(buf, hgs);
@@ -1997,7 +1997,7 @@ void ForeachStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writebyte('{');
buf->writenl();
if (body)
- body->toCBuffer(buf, hgs);
+ body->toCBuffer(buf, hgs);
buf->writebyte('}');
buf->writenl();
}
@@ -2007,7 +2007,7 @@ void ForeachStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
#if DMDV2
ForeachRangeStatement::ForeachRangeStatement(Loc loc, enum TOK op, Parameter *arg,
- Expression *lwr, Expression *upr, Statement *body)
+ Expression *lwr, Expression *upr, Statement *body)
: Statement(loc)
{
this->op = op;
@@ -2022,10 +2022,10 @@ ForeachRangeStatement::ForeachRangeStatement(Loc loc, enum TOK op, Parameter *ar
Statement *ForeachRangeStatement::syntaxCopy()
{
ForeachRangeStatement *s = new ForeachRangeStatement(loc, op,
- arg->syntaxCopy(),
- lwr->syntaxCopy(),
- upr->syntaxCopy(),
- body ? body->syntaxCopy() : NULL);
+ arg->syntaxCopy(),
+ lwr->syntaxCopy(),
+ upr->syntaxCopy(),
+ body ? body->syntaxCopy() : NULL);
return s;
}
@@ -2040,8 +2040,8 @@ Statement *ForeachRangeStatement::semantic(Scope *sc)
lwr = lwr->optimize(WANTvalue);
if (!lwr->type)
{
- error("invalid range lower bound %s", lwr->toChars());
- return this;
+ error("invalid range lower bound %s", lwr->toChars());
+ return this;
}
upr = upr->semantic(sc);
@@ -2049,33 +2049,33 @@ Statement *ForeachRangeStatement::semantic(Scope *sc)
upr = upr->optimize(WANTvalue);
if (!upr->type)
{
- error("invalid range upper bound %s", upr->toChars());
- return this;
+ error("invalid range upper bound %s", upr->toChars());
+ return this;
}
if (arg->type)
{
- arg->type = arg->type->semantic(loc, sc);
- lwr = lwr->implicitCastTo(sc, arg->type);
- upr = upr->implicitCastTo(sc, arg->type);
+ arg->type = arg->type->semantic(loc, sc);
+ lwr = lwr->implicitCastTo(sc, arg->type);
+ upr = upr->implicitCastTo(sc, arg->type);
}
else
{
- /* Must infer types from lwr and upr
- */
- AddExp ea(loc, lwr, upr);
- ea.typeCombine(sc);
- arg->type = ea.type->mutableOf();
- lwr = ea.e1;
- upr = ea.e2;
+ /* Must infer types from lwr and upr
+ */
+ AddExp ea(loc, lwr, upr);
+ ea.typeCombine(sc);
+ arg->type = ea.type->mutableOf();
+ lwr = ea.e1;
+ upr = ea.e2;
}
#if 1
/* Convert to a for loop:
- * foreach (key; lwr .. upr) =>
- * for (auto key = lwr, auto tmp = upr; key < tmp; ++key)
+ * foreach (key; lwr .. upr) =>
+ * for (auto key = lwr, auto tmp = upr; key < tmp; ++key)
*
- * foreach_reverse (key; lwr .. upr) =>
- * for (auto tmp = lwr, auto key = upr; key-- > tmp;)
+ * foreach_reverse (key; lwr .. upr) =>
+ * for (auto tmp = lwr, auto key = upr; key-- > tmp;)
*/
ExpInitializer *ie = new ExpInitializer(loc, (op == TOKforeach) ? lwr : upr);
@@ -2089,37 +2089,37 @@ Statement *ForeachRangeStatement::semantic(Scope *sc)
// Keep order of evaluation as lwr, then upr
if (op == TOKforeach)
{
- cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, key)));
- cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
+ cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, key)));
+ cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
}
else
{
- cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
- cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, key)));
+ cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
+ cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, key)));
}
Statement *forinit = new CompoundDeclarationStatement(loc, cs);
Expression *cond;
if (op == TOKforeach_reverse)
- { // key-- > tmp
- cond = new PostExp(TOKminusminus, loc, new VarExp(loc, key));
- cond = new CmpExp(TOKgt, loc, cond, new VarExp(loc, tmp));
+ { // key-- > tmp
+ cond = new PostExp(TOKminusminus, loc, new VarExp(loc, key));
+ cond = new CmpExp(TOKgt, loc, cond, new VarExp(loc, tmp));
}
else
- // key < tmp
- cond = new CmpExp(TOKlt, loc, new VarExp(loc, key), new VarExp(loc, tmp));
+ // key < tmp
+ cond = new CmpExp(TOKlt, loc, new VarExp(loc, key), new VarExp(loc, tmp));
Expression *increment = NULL;
if (op == TOKforeach)
- // key += 1
- increment = new AddAssignExp(loc, new VarExp(loc, key), new IntegerExp(1));
+ // key += 1
+ increment = new AddAssignExp(loc, new VarExp(loc, key), new IntegerExp(1));
ForStatement *fs = new ForStatement(loc, forinit, cond, increment, body);
s = fs->semantic(sc);
return s;
#else
if (!arg->type->isscalar())
- error("%s is not a scalar type", arg->type->toChars());
+ error("%s is not a scalar type", arg->type->toChars());
sym = new ScopeDsymbol();
sym->parent = sc->scopesym;
@@ -2132,7 +2132,7 @@ Statement *ForeachRangeStatement::semantic(Scope *sc)
de->semantic(sc);
if (key->storage_class)
- error("foreach range: key cannot have storage class");
+ error("foreach range: key cannot have storage class");
sc->sbreak = this;
sc->scontinue = this;
@@ -2166,13 +2166,13 @@ int ForeachRangeStatement::blockExit()
int result = BEfallthru;
if (lwr && lwr->canThrow())
- result |= BEthrow;
+ result |= BEthrow;
else if (upr && upr->canThrow())
- result |= BEthrow;
+ result |= BEthrow;
if (body)
{
- result |= body->blockExit() & ~(BEbreak | BEcontinue);
+ result |= body->blockExit() & ~(BEbreak | BEcontinue);
}
return result;
}
@@ -2182,7 +2182,7 @@ int ForeachRangeStatement::comeFrom()
{
assert(0);
if (body)
- return body->comeFrom();
+ return body->comeFrom();
return FALSE;
}
@@ -2192,9 +2192,9 @@ void ForeachRangeStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring(" (");
if (arg->type)
- arg->type->toCBuffer(buf, arg->ident, hgs);
+ arg->type->toCBuffer(buf, arg->ident, hgs);
else
- buf->writestring(arg->ident->toChars());
+ buf->writestring(arg->ident->toChars());
buf->writestring("; ");
lwr->toCBuffer(buf, hgs);
@@ -2205,7 +2205,7 @@ void ForeachRangeStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writebyte('{');
buf->writenl();
if (body)
- body->toCBuffer(buf, hgs);
+ body->toCBuffer(buf, hgs);
buf->writebyte('}');
buf->writenl();
}
@@ -2232,7 +2232,7 @@ Statement *IfStatement::syntaxCopy()
Statement *e = NULL;
if (elsebody)
- e = elsebody->syntaxCopy();
+ e = elsebody->syntaxCopy();
Parameter *a = arg ? arg->syntaxCopy() : NULL;
IfStatement *s = new IfStatement(loc, a, condition->syntaxCopy(), i, e);
@@ -2256,37 +2256,37 @@ Statement *IfStatement::semantic(Scope *sc)
Scope *scd;
if (arg)
- { /* Declare arg, which we will set to be the
- * result of condition.
- */
- ScopeDsymbol *sym = new ScopeDsymbol();
- sym->parent = sc->scopesym;
- scd = sc->push(sym);
+ { /* Declare arg, which we will set to be the
+ * result of condition.
+ */
+ ScopeDsymbol *sym = new ScopeDsymbol();
+ sym->parent = sc->scopesym;
+ scd = sc->push(sym);
- Type *t = arg->type ? arg->type : condition->type;
- match = new VarDeclaration(loc, t, arg->ident, NULL);
- match->noscope = 1;
- match->semantic(scd);
- if (!scd->insert(match))
- assert(0);
- match->parent = sc->func;
+ Type *t = arg->type ? arg->type : condition->type;
+ match = new VarDeclaration(loc, t, arg->ident, NULL);
+ match->noscope = 1;
+ match->semantic(scd);
+ if (!scd->insert(match))
+ assert(0);
+ match->parent = sc->func;
- /* Generate:
- * (arg = condition)
- */
- VarExp *v = new VarExp(0, match);
- condition = new AssignExp(loc, v, condition);
- condition = condition->semantic(scd);
+ /* Generate:
+ * (arg = condition)
+ */
+ VarExp *v = new VarExp(0, match);
+ condition = new AssignExp(loc, v, condition);
+ condition = condition->semantic(scd);
}
else
- scd = sc->push();
+ scd = sc->push();
ifbody = ifbody->semantic(scd);
scd->pop();
cs1 = sc->callSuper;
sc->callSuper = cs0;
if (elsebody)
- elsebody = elsebody->semanticScope(sc, NULL, NULL);
+ elsebody = elsebody->semanticScope(sc, NULL, NULL);
sc->mergeCallSuper(loc, cs1);
return this;
@@ -2303,31 +2303,31 @@ int IfStatement::blockExit()
int result = BEnone;
if (condition->canThrow())
- result |= BEthrow;
+ result |= BEthrow;
if (condition->isBool(TRUE))
{
- if (ifbody)
- result |= ifbody->blockExit();
- else
- result |= BEfallthru;
+ if (ifbody)
+ result |= ifbody->blockExit();
+ else
+ result |= BEfallthru;
}
else if (condition->isBool(FALSE))
{
- if (elsebody)
- result |= elsebody->blockExit();
- else
- result |= BEfallthru;
+ if (elsebody)
+ result |= elsebody->blockExit();
+ else
+ result |= BEfallthru;
}
else
{
- if (ifbody)
- result |= ifbody->blockExit();
- else
- result |= BEfallthru;
- if (elsebody)
- result |= elsebody->blockExit();
- else
- result |= BEfallthru;
+ if (ifbody)
+ result |= ifbody->blockExit();
+ else
+ result |= BEfallthru;
+ if (elsebody)
+ result |= elsebody->blockExit();
+ else
+ result |= BEfallthru;
}
//printf("IfStatement::blockExit(%p) = x%x\n", this, result);
return result;
@@ -2339,13 +2339,13 @@ void IfStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring("if (");
if (arg)
{
- if (arg->type)
- arg->type->toCBuffer(buf, arg->ident, hgs);
- else
- { buf->writestring("auto ");
- buf->writestring(arg->ident->toChars());
- }
- buf->writestring(" = ");
+ if (arg->type)
+ arg->type->toCBuffer(buf, arg->ident, hgs);
+ else
+ { buf->writestring("auto ");
+ buf->writestring(arg->ident->toChars());
+ }
+ buf->writestring(" = ");
}
condition->toCBuffer(buf, hgs);
buf->writebyte(')');
@@ -2372,9 +2372,9 @@ Statement *ConditionalStatement::syntaxCopy()
{
Statement *e = NULL;
if (elsebody)
- e = elsebody->syntaxCopy();
+ e = elsebody->syntaxCopy();
ConditionalStatement *s = new ConditionalStatement(loc,
- condition->syntaxCopy(), ifbody->syntaxCopy(), e);
+ condition->syntaxCopy(), ifbody->syntaxCopy(), e);
return s;
}
@@ -2387,14 +2387,14 @@ Statement *ConditionalStatement::semantic(Scope *sc)
// This feature allows a limited form of conditional compilation.
if (condition->include(sc, NULL))
{
- ifbody = ifbody->semantic(sc);
- return ifbody;
+ ifbody = ifbody->semantic(sc);
+ return ifbody;
}
else
{
- if (elsebody)
- elsebody = elsebody->semantic(sc);
- return elsebody;
+ if (elsebody)
+ elsebody = elsebody->semantic(sc);
+ return elsebody;
}
}
@@ -2403,9 +2403,9 @@ Statements *ConditionalStatement::flatten(Scope *sc)
Statement *s;
if (condition->include(sc, NULL))
- s = ifbody;
+ s = ifbody;
else
- s = elsebody;
+ s = elsebody;
Statements *a = new Statements();
a->push(s);
@@ -2421,7 +2421,7 @@ int ConditionalStatement::blockExit()
{
int result = ifbody->blockExit();
if (elsebody)
- result |= elsebody->blockExit();
+ result |= elsebody->blockExit();
return result;
}
@@ -2432,18 +2432,18 @@ void ConditionalStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writeByte('{');
buf->writenl();
if (ifbody)
- ifbody->toCBuffer(buf, hgs);
+ ifbody->toCBuffer(buf, hgs);
buf->writeByte('}');
buf->writenl();
if (elsebody)
{
- buf->writestring("else");
- buf->writenl();
- buf->writeByte('{');
- buf->writenl();
- elsebody->toCBuffer(buf, hgs);
- buf->writeByte('}');
- buf->writenl();
+ buf->writestring("else");
+ buf->writenl();
+ buf->writeByte('{');
+ buf->writenl();
+ elsebody->toCBuffer(buf, hgs);
+ buf->writeByte('}');
+ buf->writenl();
}
buf->writenl();
}
@@ -2463,9 +2463,9 @@ Statement *PragmaStatement::syntaxCopy()
{
Statement *b = NULL;
if (body)
- b = body->syntaxCopy();
+ b = body->syntaxCopy();
PragmaStatement *s = new PragmaStatement(loc,
- ident, Expression::arraySyntaxCopy(args), b);
+ ident, Expression::arraySyntaxCopy(args), b);
return s;
}
@@ -2483,11 +2483,11 @@ Statement *PragmaStatement::semantic(Scope *sc)
e = e->semantic(sc);
#if 1
- e = e->optimize(WANTvalue | WANTinterpret);
+ e = e->optimize(WANTvalue | WANTinterpret);
#else
- e = e->interpret(NULL);
- if (e == EXP_CANT_INTERPRET)
- fprintf(stdmsg, ((Expression *)args->data[i])->toChars());
+ e = e->interpret(NULL);
+ if (e == EXP_CANT_INTERPRET)
+ fprintf(stdmsg, ((Expression *)args->data[i])->toChars());
else
#endif
if (e->op == TOKstring)
@@ -2496,7 +2496,7 @@ Statement *PragmaStatement::semantic(Scope *sc)
fprintf(stdmsg, "%.*s", (int)se->len, (char *)se->string);
}
else
- fprintf(stdmsg, e->toChars());
+ fprintf(stdmsg, e->toChars());
}
fprintf(stdmsg, "\n");
}
@@ -2504,31 +2504,31 @@ Statement *PragmaStatement::semantic(Scope *sc)
else if (ident == Id::lib)
{
#if 1
- /* Should this be allowed?
- */
- error("pragma(lib) not allowed as statement");
+ /* Should this be allowed?
+ */
+ error("pragma(lib) not allowed as statement");
#else
- if (!args || args->dim != 1)
- error("string expected for library name");
- else
- {
- Expression *e = (Expression *)args->data[0];
+ if (!args || args->dim != 1)
+ error("string expected for library name");
+ else
+ {
+ Expression *e = (Expression *)args->data[0];
- e = e->semantic(sc);
- e = e->optimize(WANTvalue | WANTinterpret);
- args->data[0] = (void *)e;
- if (e->op != TOKstring)
- error("string expected for library name, not '%s'", e->toChars());
- else if (global.params.verbose)
- {
- StringExp *se = (StringExp *)e;
- char *name = (char *)mem.malloc(se->len + 1);
- memcpy(name, se->string, se->len);
- name[se->len] = 0;
- printf("library %s\n", name);
- mem.free(name);
- }
- }
+ e = e->semantic(sc);
+ e = e->optimize(WANTvalue | WANTinterpret);
+ args->data[0] = (void *)e;
+ if (e->op != TOKstring)
+ error("string expected for library name, not '%s'", e->toChars());
+ else if (global.params.verbose)
+ {
+ StringExp *se = (StringExp *)e;
+ char *name = (char *)mem.malloc(se->len + 1);
+ memcpy(name, se->string, se->len);
+ name[se->len] = 0;
+ printf("library %s\n", name);
+ mem.free(name);
+ }
+ }
#endif
}
@@ -2540,23 +2540,23 @@ Statement *PragmaStatement::semantic(Scope *sc)
#if DMDV2
else if (ident == Id::startaddress)
{
- if (!args || args->dim != 1)
- error("function name expected for start address");
- else
- {
- Expression *e = (Expression *)args->data[0];
- e = e->semantic(sc);
- e = e->optimize(WANTvalue | WANTinterpret);
- args->data[0] = (void *)e;
- Dsymbol *sa = getDsymbol(e);
- if (!sa || !sa->isFuncDeclaration())
- error("function name expected for start address, not '%s'", e->toChars());
- if (body)
- {
- body = body->semantic(sc);
- }
- return this;
- }
+ if (!args || args->dim != 1)
+ error("function name expected for start address");
+ else
+ {
+ Expression *e = (Expression *)args->data[0];
+ e = e->semantic(sc);
+ e = e->optimize(WANTvalue | WANTinterpret);
+ args->data[0] = (void *)e;
+ Dsymbol *sa = getDsymbol(e);
+ if (!sa || !sa->isFuncDeclaration())
+ error("function name expected for start address, not '%s'", e->toChars());
+ if (body)
+ {
+ body = body->semantic(sc);
+ }
+ return this;
+ }
}
#endif
else
@@ -2564,7 +2564,7 @@ Statement *PragmaStatement::semantic(Scope *sc)
if (body)
{
- body = body->semantic(sc);
+ body = body->semantic(sc);
}
return body;
}
@@ -2579,9 +2579,9 @@ int PragmaStatement::blockExit()
int result = BEfallthru;
#if 0 // currently, no code is generated for Pragma's, so it's just fallthru
if (arrayExpressionCanThrow(args))
- result |= BEthrow;
+ result |= BEthrow;
if (body)
- result |= body->blockExit();
+ result |= body->blockExit();
#endif
return result;
}
@@ -2593,25 +2593,25 @@ void PragmaStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring(ident->toChars());
if (args && args->dim)
{
- buf->writestring(", ");
- argsToCBuffer(buf, args, hgs);
+ buf->writestring(", ");
+ argsToCBuffer(buf, args, hgs);
}
buf->writeByte(')');
if (body)
{
- buf->writenl();
- buf->writeByte('{');
- buf->writenl();
+ buf->writenl();
+ buf->writeByte('{');
+ buf->writenl();
- body->toCBuffer(buf, hgs);
+ body->toCBuffer(buf, hgs);
- buf->writeByte('}');
- buf->writenl();
+ buf->writeByte('}');
+ buf->writenl();
}
else
{
- buf->writeByte(';');
- buf->writenl();
+ buf->writeByte(';');
+ buf->writenl();
}
}
@@ -2664,14 +2664,14 @@ SwitchStatement::SwitchStatement(Loc loc, Expression *c, Statement *b)
Statement *SwitchStatement::syntaxCopy()
{
SwitchStatement *s = new SwitchStatement(loc,
- condition->syntaxCopy(), body->syntaxCopy());
+ condition->syntaxCopy(), body->syntaxCopy());
return s;
}
Statement *SwitchStatement::semantic(Scope *sc)
{
//printf("SwitchStatement::semantic(%p)\n", this);
- assert(!cases); // ensure semantic() is only run once
+ assert(!cases); // ensure semantic() is only run once
// LDC
enclosingScopeExit = sc->enclosingScopeExit;
@@ -2680,15 +2680,15 @@ Statement *SwitchStatement::semantic(Scope *sc)
condition = resolveProperties(sc, condition);
if (condition->type->isString())
{
- // If it's not an array, cast it to one
- if (condition->type->ty != Tarray)
- {
- condition = condition->implicitCastTo(sc, condition->type->nextOf()->arrayOf());
- }
+ // If it's not an array, cast it to one
+ if (condition->type->ty != Tarray)
+ {
+ condition = condition->implicitCastTo(sc, condition->type->nextOf()->arrayOf());
+ }
}
else
- { condition = condition->integralPromotions(sc);
- condition->checkIntegral();
+ { condition = condition->integralPromotions(sc);
+ condition->checkIntegral();
}
condition = condition->optimize(WANTvalue);
@@ -2697,101 +2697,101 @@ Statement *SwitchStatement::semantic(Scope *sc)
sc->sw = this;
cases = new Array();
- sc->noctor++; // BUG: should use Scope::mergeCallSuper() for each case instead
+ sc->noctor++; // BUG: should use Scope::mergeCallSuper() for each case instead
body = body->semantic(sc);
sc->noctor--;
// Resolve any goto case's with exp
for (int i = 0; i < gotoCases.dim; i++)
{
- GotoCaseStatement *gcs = (GotoCaseStatement *)gotoCases.data[i];
+ GotoCaseStatement *gcs = (GotoCaseStatement *)gotoCases.data[i];
- if (!gcs->exp)
- {
- gcs->error("no case statement following goto case;");
- break;
- }
+ if (!gcs->exp)
+ {
+ gcs->error("no case statement following goto case;");
+ break;
+ }
- for (Scope *scx = sc; scx; scx = scx->enclosing)
- {
- if (!scx->sw)
- continue;
- for (int j = 0; j < scx->sw->cases->dim; j++)
- {
- CaseStatement *cs = (CaseStatement *)scx->sw->cases->data[j];
+ for (Scope *scx = sc; scx; scx = scx->enclosing)
+ {
+ if (!scx->sw)
+ continue;
+ for (int j = 0; j < scx->sw->cases->dim; j++)
+ {
+ CaseStatement *cs = (CaseStatement *)scx->sw->cases->data[j];
- if (cs->exp->equals(gcs->exp))
- {
- gcs->cs = cs;
- goto Lfoundcase;
- }
- }
- }
- gcs->error("case %s not found", gcs->exp->toChars());
+ if (cs->exp->equals(gcs->exp))
+ {
+ gcs->cs = cs;
+ goto Lfoundcase;
+ }
+ }
+ }
+ gcs->error("case %s not found", gcs->exp->toChars());
Lfoundcase:
- ;
+ ;
}
if (!sc->sw->sdefault)
- { hasNoDefault = 1;
+ { hasNoDefault = 1;
- warning("switch statement has no default");
+ warning("switch statement has no default");
- // Generate runtime error if the default is hit
- Statements *a = new Statements();
- CompoundStatement *cs;
- Statement *s;
+ // Generate runtime error if the default is hit
+ Statements *a = new Statements();
+ CompoundStatement *cs;
+ Statement *s;
- if (global.params.useSwitchError)
- s = new SwitchErrorStatement(loc);
- else
- { Expression *e = new HaltExp(loc);
- s = new ExpStatement(loc, e);
- }
+ if (global.params.useSwitchError)
+ s = new SwitchErrorStatement(loc);
+ else
+ { Expression *e = new HaltExp(loc);
+ s = new ExpStatement(loc, e);
+ }
- a->reserve(4);
- a->push(body);
+ a->reserve(4);
+ a->push(body);
- // LDC needs semantic to be run on break
- Statement *breakstmt = new BreakStatement(loc, NULL);
- breakstmt->semantic(sc);
- a->push(breakstmt);
+ // LDC needs semantic to be run on break
+ Statement *breakstmt = new BreakStatement(loc, NULL);
+ breakstmt->semantic(sc);
+ a->push(breakstmt);
- sc->sw->sdefault = new DefaultStatement(loc, s);
- a->push(sc->sw->sdefault);
- cs = new CompoundStatement(loc, a);
- body = cs;
+ sc->sw->sdefault = new DefaultStatement(loc, s);
+ a->push(sc->sw->sdefault);
+ cs = new CompoundStatement(loc, a);
+ body = cs;
}
#if DMDV2
if (isFinal)
- { Type *t = condition->type;
- while (t->ty == Ttypedef)
- { // Don't use toBasetype() because that will skip past enums
- t = ((TypeTypedef *)t)->sym->basetype;
- }
- if (condition->type->ty == Tenum)
- { TypeEnum *te = (TypeEnum *)condition->type;
- EnumDeclaration *ed = te->toDsymbol(sc)->isEnumDeclaration();
- assert(ed);
- size_t dim = ed->members->dim;
- for (size_t i = 0; i < dim; i++)
- {
- EnumMember *em = ((Dsymbol *)ed->members->data[i])->isEnumMember();
- if (em)
- {
- for (size_t j = 0; j < cases->dim; j++)
- { CaseStatement *cs = (CaseStatement *)cases->data[j];
- if (cs->exp->equals(em->value))
- goto L1;
- }
- error("enum member %s not represented in final switch", em->toChars());
- }
- L1:
- ;
- }
- }
+ { Type *t = condition->type;
+ while (t->ty == Ttypedef)
+ { // Don't use toBasetype() because that will skip past enums
+ t = ((TypeTypedef *)t)->sym->basetype;
+ }
+ if (condition->type->ty == Tenum)
+ { TypeEnum *te = (TypeEnum *)condition->type;
+ EnumDeclaration *ed = te->toDsymbol(sc)->isEnumDeclaration();
+ assert(ed);
+ size_t dim = ed->members->dim;
+ for (size_t i = 0; i < dim; i++)
+ {
+ EnumMember *em = ((Dsymbol *)ed->members->data[i])->isEnumMember();
+ if (em)
+ {
+ for (size_t j = 0; j < cases->dim; j++)
+ { CaseStatement *cs = (CaseStatement *)cases->data[j];
+ if (cs->exp->equals(em->value))
+ goto L1;
+ }
+ error("enum member %s not represented in final switch", em->toChars());
+ }
+ L1:
+ ;
+ }
+ }
}
#endif
@@ -2812,17 +2812,17 @@ int SwitchStatement::usesEH()
int SwitchStatement::blockExit()
{ int result = BEnone;
if (condition->canThrow())
- result |= BEthrow;
+ result |= BEthrow;
if (body)
- { result |= body->blockExit();
- if (result & BEbreak)
- { result |= BEfallthru;
- result &= ~BEbreak;
- }
+ { result |= body->blockExit();
+ if (result & BEbreak)
+ { result |= BEfallthru;
+ result &= ~BEbreak;
+ }
}
else
- result |= BEfallthru;
+ result |= BEfallthru;
return result;
}
@@ -2836,7 +2836,7 @@ void SwitchStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writenl();
if (body)
{
- if (!body->isScopeStatement())
+ if (!body->isScopeStatement())
{ buf->writebyte('{');
buf->writenl();
body->toCBuffer(buf, hgs);
@@ -2874,52 +2874,52 @@ Statement *CaseStatement::semantic(Scope *sc)
{ SwitchStatement *sw = sc->sw;
//printf("CaseStatement::semantic() %s\n", toChars());
-
+
exp = exp->semantic(sc);
if (sw)
{
- // LDC
- enclosingScopeExit = sc->enclosingScopeExit;
- if (enclosingScopeExit != sw->enclosingScopeExit)
- {
- error("case must be inside the same try, synchronized or volatile level as switch");
- }
+ // LDC
+ enclosingScopeExit = sc->enclosingScopeExit;
+ if (enclosingScopeExit != sw->enclosingScopeExit)
+ {
+ error("case must be inside the same try, synchronized or volatile level as switch");
+ }
- exp = exp->implicitCastTo(sc, sw->condition->type);
- exp = exp->optimize(WANTvalue | WANTinterpret);
- if (exp->op != TOKstring && exp->op != TOKint64)
- {
- error("case must be a string or an integral constant, not %s", exp->toChars());
- exp = new IntegerExp(0);
- }
+ exp = exp->implicitCastTo(sc, sw->condition->type);
+ exp = exp->optimize(WANTvalue | WANTinterpret);
+ if (exp->op != TOKstring && exp->op != TOKint64)
+ {
+ error("case must be a string or an integral constant, not %s", exp->toChars());
+ exp = new IntegerExp(0);
+ }
- for (int i = 0; i < sw->cases->dim; i++)
- {
- CaseStatement *cs = (CaseStatement *)sw->cases->data[i];
+ for (int i = 0; i < sw->cases->dim; i++)
+ {
+ CaseStatement *cs = (CaseStatement *)sw->cases->data[i];
- //printf("comparing '%s' with '%s'\n", exp->toChars(), cs->exp->toChars());
- if (cs->exp->equals(exp))
- { error("duplicate case %s in switch statement", exp->toChars());
- break;
- }
- }
+ //printf("comparing '%s' with '%s'\n", exp->toChars(), cs->exp->toChars());
+ if (cs->exp->equals(exp))
+ { error("duplicate case %s in switch statement", exp->toChars());
+ break;
+ }
+ }
- sw->cases->push(this);
+ sw->cases->push(this);
- // Resolve any goto case's with no exp to this case statement
- for (size_t i = 0; i < sw->gotoCases.dim; i++)
- {
- GotoCaseStatement *gcs = (GotoCaseStatement *)sw->gotoCases.data[i];
+ // Resolve any goto case's with no exp to this case statement
+ for (size_t i = 0; i < sw->gotoCases.dim; i++)
+ {
+ GotoCaseStatement *gcs = (GotoCaseStatement *)sw->gotoCases.data[i];
- if (!gcs->exp)
- {
- gcs->cs = this;
- sw->gotoCases.remove(i); // remove from array
- }
- }
+ if (!gcs->exp)
+ {
+ gcs->cs = this;
+ sw->gotoCases.remove(i); // remove from array
+ }
+ }
}
else
- error("case not in switch statement");
+ error("case not in switch statement");
statement = statement->semantic(sc);
return this;
}
@@ -2962,7 +2962,7 @@ void CaseStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
#if DMDV2
CaseRangeStatement::CaseRangeStatement(Loc loc, Expression *first,
- Expression *last, Statement *s)
+ Expression *last, Statement *s)
: Statement(loc)
{
this->first = first;
@@ -2973,7 +2973,7 @@ CaseRangeStatement::CaseRangeStatement(Loc loc, Expression *first,
Statement *CaseRangeStatement::syntaxCopy()
{
CaseRangeStatement *s = new CaseRangeStatement(loc,
- first->syntaxCopy(), last->syntaxCopy(), statement->syntaxCopy());
+ first->syntaxCopy(), last->syntaxCopy(), statement->syntaxCopy());
return s;
}
@@ -2982,7 +2982,7 @@ Statement *CaseRangeStatement::semantic(Scope *sc)
//printf("CaseRangeStatement::semantic() %s\n", toChars());
if (sw->isFinal)
- error("case ranges not allowed in final switch");
+ error("case ranges not allowed in final switch");
first = first->semantic(sc);
first = first->implicitCastTo(sc, sw->condition->type);
@@ -2995,8 +2995,8 @@ Statement *CaseRangeStatement::semantic(Scope *sc)
dinteger_t lval = last->toInteger();
if (lval - fval > 256)
- { error("more than 256 cases in case range");
- lval = fval + 256;
+ { error("more than 256 cases in case range");
+ lval = fval + 256;
}
/* This works by replacing the CaseRange with an array of Case's.
@@ -3012,12 +3012,12 @@ Statement *CaseRangeStatement::semantic(Scope *sc)
Statements *statements = new Statements();
for (dinteger_t i = fval; i <= lval; i++)
{
- Statement *s = statement;
- if (i != lval)
- s = new ExpStatement(loc, NULL);
- Expression *e = new IntegerExp(loc, i, first->type);
- Statement *cs = new CaseStatement(loc, e, s);
- statements->push(cs);
+ Statement *s = statement;
+ if (i != lval)
+ s = new ExpStatement(loc, NULL);
+ Expression *e = new IntegerExp(loc, i, first->type);
+ Statement *cs = new CaseStatement(loc, e, s);
+ statements->push(cs);
}
Statement *s = new CompoundStatement(loc, statements);
s = s->semantic(sc);
@@ -3062,21 +3062,21 @@ Statement *DefaultStatement::semantic(Scope *sc)
if (sc->sw)
{
- if (sc->sw->sdefault)
- {
- error("switch statement already has a default");
- }
- sc->sw->sdefault = this;
+ if (sc->sw->sdefault)
+ {
+ error("switch statement already has a default");
+ }
+ sc->sw->sdefault = this;
- // LDC
- enclosingScopeExit = sc->enclosingScopeExit;
- if (enclosingScopeExit != sc->sw->enclosingScopeExit)
- {
- error("default must be inside the same try, synchronized or volatile level as switch");
- }
+ // LDC
+ enclosingScopeExit = sc->enclosingScopeExit;
+ if (enclosingScopeExit != sc->sw->enclosingScopeExit)
+ {
+ error("default must be inside the same try, synchronized or volatile level as switch");
+ }
}
else
- error("default not in switch statement");
+ error("default not in switch statement");
statement = statement->semantic(sc);
return this;
}
@@ -3121,7 +3121,7 @@ Statement *GotoDefaultStatement::semantic(Scope *sc)
{
sw = sc->sw;
if (!sw)
- error("goto default not in switch statement");
+ error("goto default not in switch statement");
return this;
}
@@ -3156,19 +3156,19 @@ Statement *GotoCaseStatement::syntaxCopy()
Statement *GotoCaseStatement::semantic(Scope *sc)
{
if (exp)
- exp = exp->semantic(sc);
+ exp = exp->semantic(sc);
if (!sc->sw)
- error("goto case not in switch statement");
+ error("goto case not in switch statement");
else
{
- sw = sc->sw;
- sc->sw->gotoCases.push(this);
- if (exp)
- {
- exp = exp->implicitCastTo(sc, sc->sw->condition->type);
- exp = exp->optimize(WANTvalue);
- }
+ sw = sc->sw;
+ sc->sw->gotoCases.push(this);
+ if (exp)
+ {
+ exp = exp->implicitCastTo(sc, sc->sw->condition->type);
+ exp = exp->optimize(WANTvalue);
+ }
}
return this;
}
@@ -3221,7 +3221,7 @@ Statement *ReturnStatement::syntaxCopy()
{
Expression *e = NULL;
if (exp)
- e = exp->syntaxCopy();
+ e = exp->syntaxCopy();
ReturnStatement *s = new ReturnStatement(loc, e);
return s;
}
@@ -3236,236 +3236,236 @@ Statement *ReturnStatement::semantic(Scope *sc)
if (sc->fes)
{
- // Find scope of function foreach is in
- for (; 1; scx = scx->enclosing)
- {
- assert(scx);
- if (scx->func != fd)
- { fd = scx->func; // fd is now function enclosing foreach
- break;
- }
- }
+ // Find scope of function foreach is in
+ for (; 1; scx = scx->enclosing)
+ {
+ assert(scx);
+ if (scx->func != fd)
+ { fd = scx->func; // fd is now function enclosing foreach
+ break;
+ }
+ }
}
Type *tret = fd->type->nextOf();
if (fd->tintro)
- /* We'll be implicitly casting the return expression to tintro
- */
- tret = fd->tintro->nextOf();
+ /* We'll be implicitly casting the return expression to tintro
+ */
+ tret = fd->tintro->nextOf();
Type *tbret = NULL;
if (tret)
- tbret = tret->toBasetype();
+ tbret = tret->toBasetype();
// main() returns 0, even if it returns void
if (!exp && (!tbret || tbret->ty == Tvoid) && fd->isMain())
- { implicit0 = 1;
- exp = new IntegerExp(0);
+ { implicit0 = 1;
+ exp = new IntegerExp(0);
}
if (sc->incontract || scx->incontract)
- error("return statements cannot be in contracts");
+ error("return statements cannot be in contracts");
if (sc->enclosingFinally || scx->enclosingFinally)
- error("return statements cannot be in finally, scope(exit) or scope(success) bodies");
+ error("return statements cannot be in finally, scope(exit) or scope(success) bodies");
if (fd->isCtorDeclaration())
{
- // Constructors implicitly do:
- // return this;
- if (exp && exp->op != TOKthis)
- error("cannot return expression from constructor");
- exp = new ThisExp(0);
+ // Constructors implicitly do:
+ // return this;
+ if (exp && exp->op != TOKthis)
+ error("cannot return expression from constructor");
+ exp = new ThisExp(0);
}
if (!exp)
- fd->nrvo_can = 0;
+ fd->nrvo_can = 0;
if (exp)
{
- fd->hasReturnExp |= 1;
+ fd->hasReturnExp |= 1;
- exp = exp->semantic(sc);
- exp = resolveProperties(sc, exp);
- exp = exp->optimize(WANTvalue);
+ exp = exp->semantic(sc);
+ exp = resolveProperties(sc, exp);
+ exp = exp->optimize(WANTvalue);
- if (fd->nrvo_can && exp->op == TOKvar)
- { VarExp *ve = (VarExp *)exp;
- VarDeclaration *v = ve->var->isVarDeclaration();
+ if (fd->nrvo_can && exp->op == TOKvar)
+ { VarExp *ve = (VarExp *)exp;
+ VarDeclaration *v = ve->var->isVarDeclaration();
- if (!v || v->isOut() || v->isRef())
- fd->nrvo_can = 0;
- else if (fd->nrvo_var == NULL)
- { if (!v->isDataseg() && !v->isParameter() && v->toParent2() == fd)
- { //printf("Setting nrvo to %s\n", v->toChars());
- fd->nrvo_var = v;
- }
- else
- fd->nrvo_can = 0;
- }
- else if (fd->nrvo_var != v)
- fd->nrvo_can = 0;
- }
- else
- fd->nrvo_can = 0;
+ if (!v || v->isOut() || v->isRef())
+ fd->nrvo_can = 0;
+ else if (fd->nrvo_var == NULL)
+ { if (!v->isDataseg() && !v->isParameter() && v->toParent2() == fd)
+ { //printf("Setting nrvo to %s\n", v->toChars());
+ fd->nrvo_var = v;
+ }
+ else
+ fd->nrvo_can = 0;
+ }
+ else if (fd->nrvo_var != v)
+ fd->nrvo_can = 0;
+ }
+ else
+ fd->nrvo_can = 0;
- if (fd->returnLabel && tbret->ty != Tvoid)
- {
- }
- else if (fd->inferRetType)
- {
- if (fd->type->nextOf())
- {
- if (!exp->type->equals(fd->type->nextOf()))
- error("mismatched function return type inference of %s and %s",
- exp->type->toChars(), fd->type->nextOf()->toChars());
- }
- else
- {
- fd->type->next = exp->type;
- fd->type = fd->type->semantic(loc, sc);
- if (!fd->tintro)
- { tret = fd->type->nextOf();
- tbret = tret->toBasetype();
- }
- }
- }
- else if (tbret->ty != Tvoid)
- {
- exp = exp->implicitCastTo(sc, tret);
- }
+ if (fd->returnLabel && tbret->ty != Tvoid)
+ {
+ }
+ else if (fd->inferRetType)
+ {
+ if (fd->type->nextOf())
+ {
+ if (!exp->type->equals(fd->type->nextOf()))
+ error("mismatched function return type inference of %s and %s",
+ exp->type->toChars(), fd->type->nextOf()->toChars());
+ }
+ else
+ {
+ fd->type->next = exp->type;
+ fd->type = fd->type->semantic(loc, sc);
+ if (!fd->tintro)
+ { tret = fd->type->nextOf();
+ tbret = tret->toBasetype();
+ }
+ }
+ }
+ else if (tbret->ty != Tvoid)
+ {
+ exp = exp->implicitCastTo(sc, tret);
+ }
}
else if (fd->inferRetType)
{
- if (fd->type->nextOf())
- {
- if (fd->type->nextOf()->ty != Tvoid)
- error("mismatched function return type inference of void and %s",
- fd->type->nextOf()->toChars());
- }
- else
- {
- fd->type->next = Type::tvoid;
- fd->type = fd->type->semantic(loc, sc);
- if (!fd->tintro)
- { tret = Type::tvoid;
- tbret = tret;
- }
- }
+ if (fd->type->nextOf())
+ {
+ if (fd->type->nextOf()->ty != Tvoid)
+ error("mismatched function return type inference of void and %s",
+ fd->type->nextOf()->toChars());
+ }
+ else
+ {
+ fd->type->next = Type::tvoid;
+ fd->type = fd->type->semantic(loc, sc);
+ if (!fd->tintro)
+ { tret = Type::tvoid;
+ tbret = tret;
+ }
+ }
}
- else if (tbret->ty != Tvoid) // if non-void return
- error("return expression expected");
+ else if (tbret->ty != Tvoid) // if non-void return
+ error("return expression expected");
if (sc->fes)
{
- Statement *s;
+ Statement *s;
- if (exp && !implicit0)
- {
- exp = exp->implicitCastTo(sc, tret);
- }
- if (!exp || exp->op == TOKint64 || exp->op == TOKfloat64 ||
- exp->op == TOKimaginary80 || exp->op == TOKcomplex80 ||
- exp->op == TOKthis || exp->op == TOKsuper || exp->op == TOKnull ||
- exp->op == TOKstring)
- {
- sc->fes->cases.push(this);
- // Construct: return cases.dim+1;
- s = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1));
- }
- else if (fd->type->nextOf()->toBasetype() == Type::tvoid)
- {
- s = new ReturnStatement(0, NULL);
- sc->fes->cases.push(s);
+ if (exp && !implicit0)
+ {
+ exp = exp->implicitCastTo(sc, tret);
+ }
+ if (!exp || exp->op == TOKint64 || exp->op == TOKfloat64 ||
+ exp->op == TOKimaginary80 || exp->op == TOKcomplex80 ||
+ exp->op == TOKthis || exp->op == TOKsuper || exp->op == TOKnull ||
+ exp->op == TOKstring)
+ {
+ sc->fes->cases.push(this);
+ // Construct: return cases.dim+1;
+ s = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1));
+ }
+ else if (fd->type->nextOf()->toBasetype() == Type::tvoid)
+ {
+ s = new ReturnStatement(0, NULL);
+ sc->fes->cases.push(s);
- // Construct: { exp; return cases.dim + 1; }
- Statement *s1 = new ExpStatement(loc, exp);
- Statement *s2 = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1));
- s = new CompoundStatement(loc, s1, s2);
- }
- else
- {
- // Construct: return vresult;
- if (!fd->vresult)
- { // Declare vresult
- VarDeclaration *v = new VarDeclaration(loc, tret, Id::result, NULL);
- v->noscope = 1;
- v->semantic(scx);
- if (!scx->insert(v))
- assert(0);
- v->parent = fd;
- fd->vresult = v;
- }
+ // Construct: { exp; return cases.dim + 1; }
+ Statement *s1 = new ExpStatement(loc, exp);
+ Statement *s2 = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1));
+ s = new CompoundStatement(loc, s1, s2);
+ }
+ else
+ {
+ // Construct: return vresult;
+ if (!fd->vresult)
+ { // Declare vresult
+ VarDeclaration *v = new VarDeclaration(loc, tret, Id::result, NULL);
+ v->noscope = 1;
+ v->semantic(scx);
+ if (!scx->insert(v))
+ assert(0);
+ v->parent = fd;
+ fd->vresult = v;
+ }
- s = new ReturnStatement(0, new VarExp(0, fd->vresult));
- sc->fes->cases.push(s);
+ s = new ReturnStatement(0, new VarExp(0, fd->vresult));
+ sc->fes->cases.push(s);
- // Construct: { vresult = exp; return cases.dim + 1; }
- exp = new AssignExp(loc, new VarExp(0, fd->vresult), exp);
- exp->op = TOKconstruct;
- exp = exp->semantic(sc);
- Statement *s1 = new ExpStatement(loc, exp);
- Statement *s2 = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1));
- s = new CompoundStatement(loc, s1, s2);
- }
- return s;
+ // Construct: { vresult = exp; return cases.dim + 1; }
+ exp = new AssignExp(loc, new VarExp(0, fd->vresult), exp);
+ exp->op = TOKconstruct;
+ exp = exp->semantic(sc);
+ Statement *s1 = new ExpStatement(loc, exp);
+ Statement *s2 = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1));
+ s = new CompoundStatement(loc, s1, s2);
+ }
+ return s;
}
if (exp)
{
- if (fd->returnLabel && tbret->ty != Tvoid)
- {
- assert(fd->vresult);
- VarExp *v = new VarExp(0, fd->vresult);
+ if (fd->returnLabel && tbret->ty != Tvoid)
+ {
+ assert(fd->vresult);
+ VarExp *v = new VarExp(0, fd->vresult);
- exp = new AssignExp(loc, v, exp);
- exp->op = TOKconstruct;
- exp = exp->semantic(sc);
- }
- //exp->dump(0);
- //exp->print();
- exp->checkEscape();
+ exp = new AssignExp(loc, v, exp);
+ exp->op = TOKconstruct;
+ exp = exp->semantic(sc);
+ }
+ //exp->dump(0);
+ //exp->print();
+ exp->checkEscape();
}
/* BUG: need to issue an error on:
- * this
- * { if (x) return;
- * super();
- * }
+ * this
+ * { if (x) return;
+ * super();
+ * }
*/
if (sc->callSuper & CSXany_ctor &&
- !(sc->callSuper & (CSXthis_ctor | CSXsuper_ctor)))
- error("return without calling constructor");
+ !(sc->callSuper & (CSXthis_ctor | CSXsuper_ctor)))
+ error("return without calling constructor");
sc->callSuper |= CSXreturn;
// See if all returns are instead to be replaced with a goto returnLabel;
if (fd->returnLabel)
{
- GotoStatement *gs = new GotoStatement(loc, Id::returnLabel);
+ GotoStatement *gs = new GotoStatement(loc, Id::returnLabel);
- gs->label = fd->returnLabel;
- if (exp)
- { /* Replace: return exp;
- * with: exp; goto returnLabel;
- */
- Statement *s = new ExpStatement(0, exp);
- return new CompoundStatement(loc, s, gs);
- }
- return gs;
+ gs->label = fd->returnLabel;
+ if (exp)
+ { /* Replace: return exp;
+ * with: exp; goto returnLabel;
+ */
+ Statement *s = new ExpStatement(0, exp);
+ return new CompoundStatement(loc, s, gs);
+ }
+ return gs;
}
if (exp && tbret->ty == Tvoid && !implicit0)
{
- /* Replace:
- * return exp;
- * with:
- * exp; return;
- */
- Statement *s = new ExpStatement(loc, exp);
- exp = NULL;
- s = s->semantic(sc);
- return new CompoundStatement(loc, s, this);
+ /* Replace:
+ * return exp;
+ * with:
+ * exp; return;
+ */
+ Statement *s = new ExpStatement(loc, exp);
+ exp = NULL;
+ s = s->semantic(sc);
+ return new CompoundStatement(loc, s, this);
}
return this;
@@ -3475,7 +3475,7 @@ int ReturnStatement::blockExit()
{ int result = BEreturn;
if (exp && exp->canThrow())
- result |= BEthrow;
+ result |= BEthrow;
return result;
}
@@ -3484,7 +3484,7 @@ void ReturnStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->printf("return ");
if (exp)
- exp->toCBuffer(buf, hgs);
+ exp->toCBuffer(buf, hgs);
buf->writeByte(';');
buf->writenl();
}
@@ -3507,61 +3507,61 @@ Statement *BreakStatement::semantic(Scope *sc)
{
//printf("BreakStatement::semantic()\n");
// If:
- // break Identifier;
+ // break Identifier;
if (ident)
{
- Scope *scx;
- FuncDeclaration *thisfunc = sc->func;
+ Scope *scx;
+ FuncDeclaration *thisfunc = sc->func;
- for (scx = sc; scx; scx = scx->enclosing)
- {
- LabelStatement *ls;
+ for (scx = sc; scx; scx = scx->enclosing)
+ {
+ LabelStatement *ls;
- if (scx->func != thisfunc) // if in enclosing function
- {
- if (sc->fes) // if this is the body of a foreach
- {
- /* Post this statement to the fes, and replace
- * it with a return value that caller will put into
- * a switch. Caller will figure out where the break
- * label actually is.
- * Case numbers start with 2, not 0, as 0 is continue
- * and 1 is break.
- */
- Statement *s;
- sc->fes->cases.push(this);
- s = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1));
- return s;
- }
- break; // can't break to it
- }
+ if (scx->func != thisfunc) // if in enclosing function
+ {
+ if (sc->fes) // if this is the body of a foreach
+ {
+ /* Post this statement to the fes, and replace
+ * it with a return value that caller will put into
+ * a switch. Caller will figure out where the break
+ * label actually is.
+ * Case numbers start with 2, not 0, as 0 is continue
+ * and 1 is break.
+ */
+ Statement *s;
+ sc->fes->cases.push(this);
+ s = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1));
+ return s;
+ }
+ break; // can't break to it
+ }
- ls = scx->slabel;
- if (ls && ls->ident == ident)
- {
- Statement *s = ls->statement;
+ ls = scx->slabel;
+ if (ls && ls->ident == ident)
+ {
+ Statement *s = ls->statement;
- if (!s->hasBreak())
- error("label '%s' has no break", ident->toChars());
- if (ls->enclosingFinally != sc->enclosingFinally)
- error("cannot break out of finally block");
-
- this->target = ls;
- return this;
- }
- }
- error("enclosing label '%s' for break not found", ident->toChars());
+ if (!s->hasBreak())
+ error("label '%s' has no break", ident->toChars());
+ if (ls->enclosingFinally != sc->enclosingFinally)
+ error("cannot break out of finally block");
+
+ this->target = ls;
+ return this;
+ }
+ }
+ error("enclosing label '%s' for break not found", ident->toChars());
}
else if (!sc->sbreak)
{
- if (sc->fes)
- { Statement *s;
+ if (sc->fes)
+ { Statement *s;
- // Replace break; with return 1;
- s = new ReturnStatement(0, new IntegerExp(1));
- return s;
- }
- error("break is not inside a loop or switch");
+ // Replace break; with return 1;
+ s = new ReturnStatement(0, new IntegerExp(1));
+ return s;
+ }
+ error("break is not inside a loop or switch");
}
return this;
}
@@ -3603,68 +3603,68 @@ Statement *ContinueStatement::semantic(Scope *sc)
//printf("ContinueStatement::semantic() %p\n", this);
if (ident)
{
- Scope *scx;
- FuncDeclaration *thisfunc = sc->func;
+ Scope *scx;
+ FuncDeclaration *thisfunc = sc->func;
- for (scx = sc; scx; scx = scx->enclosing)
- {
- LabelStatement *ls;
+ for (scx = sc; scx; scx = scx->enclosing)
+ {
+ LabelStatement *ls;
- if (scx->func != thisfunc) // if in enclosing function
- {
- if (sc->fes) // if this is the body of a foreach
- {
- for (; scx; scx = scx->enclosing)
- {
- ls = scx->slabel;
- if (ls && ls->ident == ident && ls->statement == sc->fes)
- {
- // Replace continue ident; with return 0;
- return new ReturnStatement(0, new IntegerExp(0));
- }
- }
+ if (scx->func != thisfunc) // if in enclosing function
+ {
+ if (sc->fes) // if this is the body of a foreach
+ {
+ for (; scx; scx = scx->enclosing)
+ {
+ ls = scx->slabel;
+ if (ls && ls->ident == ident && ls->statement == sc->fes)
+ {
+ // Replace continue ident; with return 0;
+ return new ReturnStatement(0, new IntegerExp(0));
+ }
+ }
- /* Post this statement to the fes, and replace
- * it with a return value that caller will put into
- * a switch. Caller will figure out where the break
- * label actually is.
- * Case numbers start with 2, not 0, as 0 is continue
- * and 1 is break.
- */
- Statement *s;
- sc->fes->cases.push(this);
- s = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1));
- return s;
- }
- break; // can't continue to it
- }
+ /* Post this statement to the fes, and replace
+ * it with a return value that caller will put into
+ * a switch. Caller will figure out where the break
+ * label actually is.
+ * Case numbers start with 2, not 0, as 0 is continue
+ * and 1 is break.
+ */
+ Statement *s;
+ sc->fes->cases.push(this);
+ s = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1));
+ return s;
+ }
+ break; // can't continue to it
+ }
- ls = scx->slabel;
- if (ls && ls->ident == ident)
- {
- Statement *s = ls->statement;
+ ls = scx->slabel;
+ if (ls && ls->ident == ident)
+ {
+ Statement *s = ls->statement;
- if (!s->hasContinue())
- error("label '%s' has no continue", ident->toChars());
- if (ls->enclosingFinally != sc->enclosingFinally)
- error("cannot continue out of finally block");
-
- this->target = ls;
- return this;
- }
- }
- error("enclosing label '%s' for continue not found", ident->toChars());
+ if (!s->hasContinue())
+ error("label '%s' has no continue", ident->toChars());
+ if (ls->enclosingFinally != sc->enclosingFinally)
+ error("cannot continue out of finally block");
+
+ this->target = ls;
+ return this;
+ }
+ }
+ error("enclosing label '%s' for continue not found", ident->toChars());
}
else if (!sc->scontinue)
{
- if (sc->fes)
- { Statement *s;
+ if (sc->fes)
+ { Statement *s;
- // Replace continue; with return 0;
- s = new ReturnStatement(0, new IntegerExp(0));
- return s;
- }
- error("continue is not inside a loop");
+ // Replace continue; with return 0;
+ s = new ReturnStatement(0, new IntegerExp(0));
+ return s;
+ }
+ error("continue is not inside a loop");
}
return this;
}
@@ -3719,92 +3719,92 @@ Statement *SynchronizedStatement::semantic(Scope *sc)
{
if (exp)
{
- exp = exp->semantic(sc);
- exp = resolveProperties(sc, exp);
- ClassDeclaration *cd = exp->type->isClassHandle();
- if (!cd)
- error("can only synchronize on class objects, not '%s'", exp->type->toChars());
- else if (cd->isInterfaceDeclaration())
- { /* Cast the interface to an object, as the object has the monitor,
- * not the interface.
- */
- Type *t = new TypeIdentifier(0, Id::Object);
+ exp = exp->semantic(sc);
+ exp = resolveProperties(sc, exp);
+ ClassDeclaration *cd = exp->type->isClassHandle();
+ if (!cd)
+ error("can only synchronize on class objects, not '%s'", exp->type->toChars());
+ else if (cd->isInterfaceDeclaration())
+ { /* Cast the interface to an object, as the object has the monitor,
+ * not the interface.
+ */
+ Type *t = new TypeIdentifier(0, Id::Object);
- t = t->semantic(0, sc);
- exp = new CastExp(loc, exp, t);
- exp = exp->semantic(sc);
- }
+ t = t->semantic(0, sc);
+ exp = new CastExp(loc, exp, t);
+ exp = exp->semantic(sc);
+ }
#if 0
- /* Rewrite as:
- * auto tmp = exp;
- * _d_monitorenter(tmp);
- * try { body } finally { _d_monitorexit(tmp); }
- */
- Identifier *id = Lexer::uniqueId("__sync");
- ExpInitializer *ie = new ExpInitializer(loc, exp);
- VarDeclaration *tmp = new VarDeclaration(loc, exp->type, id, ie);
+ /* Rewrite as:
+ * auto tmp = exp;
+ * _d_monitorenter(tmp);
+ * try { body } finally { _d_monitorexit(tmp); }
+ */
+ Identifier *id = Lexer::uniqueId("__sync");
+ ExpInitializer *ie = new ExpInitializer(loc, exp);
+ VarDeclaration *tmp = new VarDeclaration(loc, exp->type, id, ie);
- Statements *cs = new Statements();
- cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
+ Statements *cs = new Statements();
+ cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
- FuncDeclaration *fdenter = FuncDeclaration::genCfunc(Type::tvoid, Id::monitorenter);
- Expression *e = new CallExp(loc, new VarExp(loc, fdenter), new VarExp(loc, tmp));
- e->type = Type::tvoid; // do not run semantic on e
- cs->push(new ExpStatement(loc, e));
+ FuncDeclaration *fdenter = FuncDeclaration::genCfunc(Type::tvoid, Id::monitorenter);
+ Expression *e = new CallExp(loc, new VarExp(loc, fdenter), new VarExp(loc, tmp));
+ e->type = Type::tvoid; // do not run semantic on e
+ cs->push(new ExpStatement(loc, e));
- FuncDeclaration *fdexit = FuncDeclaration::genCfunc(Type::tvoid, Id::monitorexit);
- e = new CallExp(loc, new VarExp(loc, fdexit), new VarExp(loc, tmp));
- e->type = Type::tvoid; // do not run semantic on e
- Statement *s = new ExpStatement(loc, e);
- s = new TryFinallyStatement(loc, body, s);
- cs->push(s);
+ FuncDeclaration *fdexit = FuncDeclaration::genCfunc(Type::tvoid, Id::monitorexit);
+ e = new CallExp(loc, new VarExp(loc, fdexit), new VarExp(loc, tmp));
+ e->type = Type::tvoid; // do not run semantic on e
+ Statement *s = new ExpStatement(loc, e);
+ s = new TryFinallyStatement(loc, body, s);
+ cs->push(s);
- s = new CompoundStatement(loc, cs);
- return s->semantic(sc);
+ s = new CompoundStatement(loc, cs);
+ return s->semantic(sc);
#endif
}
#if 0
else
- { /* Generate our own critical section, then rewrite as:
- * __gshared byte[CriticalSection.sizeof] critsec;
- * _d_criticalenter(critsec.ptr);
- * try { body } finally { _d_criticalexit(critsec.ptr); }
- */
- Identifier *id = Lexer::uniqueId("__critsec");
- Type *t = new TypeSArray(Type::tint8, new IntegerExp(PTRSIZE + os_critsecsize()));
- VarDeclaration *tmp = new VarDeclaration(loc, t, id, NULL);
- tmp->storage_class |= STCgshared | STCstatic;
+ { /* Generate our own critical section, then rewrite as:
+ * __gshared byte[CriticalSection.sizeof] critsec;
+ * _d_criticalenter(critsec.ptr);
+ * try { body } finally { _d_criticalexit(critsec.ptr); }
+ */
+ Identifier *id = Lexer::uniqueId("__critsec");
+ Type *t = new TypeSArray(Type::tint8, new IntegerExp(PTRSIZE + os_critsecsize()));
+ VarDeclaration *tmp = new VarDeclaration(loc, t, id, NULL);
+ tmp->storage_class |= STCgshared | STCstatic;
- Statements *cs = new Statements();
- cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
+ Statements *cs = new Statements();
+ cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
- FuncDeclaration *fdenter = FuncDeclaration::genCfunc(Type::tvoid, Id::criticalenter);
- Expression *e = new DotIdExp(loc, new VarExp(loc, tmp), Id::ptr);
- e = e->semantic(sc);
- e = new CallExp(loc, new VarExp(loc, fdenter), e);
- e->type = Type::tvoid; // do not run semantic on e
- cs->push(new ExpStatement(loc, e));
+ FuncDeclaration *fdenter = FuncDeclaration::genCfunc(Type::tvoid, Id::criticalenter);
+ Expression *e = new DotIdExp(loc, new VarExp(loc, tmp), Id::ptr);
+ e = e->semantic(sc);
+ e = new CallExp(loc, new VarExp(loc, fdenter), e);
+ e->type = Type::tvoid; // do not run semantic on e
+ cs->push(new ExpStatement(loc, e));
- FuncDeclaration *fdexit = FuncDeclaration::genCfunc(Type::tvoid, Id::criticalexit);
- e = new DotIdExp(loc, new VarExp(loc, tmp), Id::ptr);
- e = e->semantic(sc);
- e = new CallExp(loc, new VarExp(loc, fdexit), e);
- e->type = Type::tvoid; // do not run semantic on e
- Statement *s = new ExpStatement(loc, e);
- s = new TryFinallyStatement(loc, body, s);
- cs->push(s);
+ FuncDeclaration *fdexit = FuncDeclaration::genCfunc(Type::tvoid, Id::criticalexit);
+ e = new DotIdExp(loc, new VarExp(loc, tmp), Id::ptr);
+ e = e->semantic(sc);
+ e = new CallExp(loc, new VarExp(loc, fdexit), e);
+ e->type = Type::tvoid; // do not run semantic on e
+ Statement *s = new ExpStatement(loc, e);
+ s = new TryFinallyStatement(loc, body, s);
+ cs->push(s);
- s = new CompoundStatement(loc, cs);
- return s->semantic(sc);
+ s = new CompoundStatement(loc, cs);
+ return s->semantic(sc);
}
#endif
if (body)
{
- Statement* oldScopeExit = sc->enclosingScopeExit;
- sc->enclosingScopeExit = this;
- body = body->semantic(sc);
- sc->enclosingScopeExit = oldScopeExit;
+ Statement* oldScopeExit = sc->enclosingScopeExit;
+ sc->enclosingScopeExit = this;
+ body = body->semantic(sc);
+ sc->enclosingScopeExit = oldScopeExit;
}
return this;
}
@@ -3835,13 +3835,13 @@ void SynchronizedStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring("synchronized");
if (exp)
{ buf->writebyte('(');
- exp->toCBuffer(buf, hgs);
- buf->writebyte(')');
+ exp->toCBuffer(buf, hgs);
+ buf->writebyte(')');
}
if (body)
{
- buf->writebyte(' ');
- body->toCBuffer(buf, hgs);
+ buf->writebyte(' ');
+ body->toCBuffer(buf, hgs);
}
}
@@ -3869,52 +3869,52 @@ Statement *WithStatement::semantic(Scope *sc)
exp = exp->semantic(sc);
exp = resolveProperties(sc, exp);
if (exp->op == TOKimport)
- { ScopeExp *es = (ScopeExp *)exp;
+ { ScopeExp *es = (ScopeExp *)exp;
- sym = es->sds;
+ sym = es->sds;
}
else if (exp->op == TOKtype)
- { TypeExp *es = (TypeExp *)exp;
+ { TypeExp *es = (TypeExp *)exp;
- sym = es->type->toDsymbol(sc)->isScopeDsymbol();
- if (!sym)
- { error("%s has no members", es->toChars());
- body = body->semantic(sc);
- return this;
- }
+ sym = es->type->toDsymbol(sc)->isScopeDsymbol();
+ if (!sym)
+ { error("%s has no members", es->toChars());
+ body = body->semantic(sc);
+ return this;
+ }
}
else
- { Type *t = exp->type;
+ { Type *t = exp->type;
- assert(t);
- t = t->toBasetype();
- if (t->isClassHandle())
- {
- init = new ExpInitializer(loc, exp);
- wthis = new VarDeclaration(loc, exp->type, Id::withSym, init);
- wthis->semantic(sc);
+ assert(t);
+ t = t->toBasetype();
+ if (t->isClassHandle())
+ {
+ init = new ExpInitializer(loc, exp);
+ wthis = new VarDeclaration(loc, exp->type, Id::withSym, init);
+ wthis->semantic(sc);
- sym = new WithScopeSymbol(this);
- sym->parent = sc->scopesym;
- }
- else if (t->ty == Tstruct)
- {
- Expression *e = exp->addressOf(sc);
- init = new ExpInitializer(loc, e);
- wthis = new VarDeclaration(loc, e->type, Id::withSym, init);
- wthis->semantic(sc);
- sym = new WithScopeSymbol(this);
- sym->parent = sc->scopesym;
- }
- else
- { error("with expressions must be class objects, not '%s'", exp->type->toChars());
- return NULL;
- }
+ sym = new WithScopeSymbol(this);
+ sym->parent = sc->scopesym;
+ }
+ else if (t->ty == Tstruct)
+ {
+ Expression *e = exp->addressOf(sc);
+ init = new ExpInitializer(loc, e);
+ wthis = new VarDeclaration(loc, e->type, Id::withSym, init);
+ wthis->semantic(sc);
+ sym = new WithScopeSymbol(this);
+ sym->parent = sc->scopesym;
+ }
+ else
+ { error("with expressions must be class objects, not '%s'", exp->type->toChars());
+ return NULL;
+ }
}
sc = sc->push(sym);
if (body)
- body = body->semantic(sc);
+ body = body->semantic(sc);
sc->pop();
@@ -3927,7 +3927,7 @@ void WithStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
exp->toCBuffer(buf, hgs);
buf->writestring(")\n");
if (body)
- body->toCBuffer(buf, hgs);
+ body->toCBuffer(buf, hgs);
}
int WithStatement::usesEH()
@@ -3939,11 +3939,11 @@ int WithStatement::blockExit()
{
int result = BEnone;
if (exp->canThrow())
- result = BEthrow;
+ result = BEthrow;
if (body)
- result |= body->blockExit();
+ result |= body->blockExit();
else
- result |= BEfallthru;
+ result |= BEfallthru;
return result;
}
@@ -3964,9 +3964,9 @@ Statement *TryCatchStatement::syntaxCopy()
for (int i = 0; i < a->dim; i++)
{ Catch *c;
- c = (Catch *)catches->data[i];
- c = c->syntaxCopy();
- a->data[i] = c;
+ c = (Catch *)catches->data[i];
+ c = c->syntaxCopy();
+ a->data[i] = c;
}
TryCatchStatement *s = new TryCatchStatement(loc, body->syntaxCopy(), a);
return s;
@@ -3980,22 +3980,22 @@ Statement *TryCatchStatement::semantic(Scope *sc)
*/
for (size_t i = 0; i < catches->dim; i++)
{ Catch *c = (Catch *)catches->data[i];
- c->semantic(sc);
+ c->semantic(sc);
- // Determine if current catch 'hides' any previous catches
- for (size_t j = 0; j < i; j++)
- { Catch *cj = (Catch *)catches->data[j];
- char *si = c->loc.toChars();
- char *sj = cj->loc.toChars();
+ // Determine if current catch 'hides' any previous catches
+ for (size_t j = 0; j < i; j++)
+ { Catch *cj = (Catch *)catches->data[j];
+ char *si = c->loc.toChars();
+ char *sj = cj->loc.toChars();
- if (c->type->toBasetype()->implicitConvTo(cj->type->toBasetype()))
- error("catch at %s hides catch at %s", sj, si);
- }
+ if (c->type->toBasetype()->implicitConvTo(cj->type->toBasetype()))
+ error("catch at %s hides catch at %s", sj, si);
+ }
}
if (!body || body->isEmpty())
{
- return NULL;
+ return NULL;
}
return this;
}
@@ -4051,9 +4051,9 @@ Catch::Catch(Loc loc, Type *t, Identifier *id, Statement *handler)
Catch *Catch::syntaxCopy()
{
Catch *c = new Catch(loc,
- (type ? type->syntaxCopy() : NULL),
- ident,
- (handler ? handler->syntaxCopy() : NULL));
+ (type ? type->syntaxCopy() : NULL),
+ ident,
+ (handler ? handler->syntaxCopy() : NULL));
return c;
}
@@ -4065,13 +4065,13 @@ void Catch::semantic(Scope *sc)
#ifndef IN_GCC
if (sc->enclosingFinally)
{
- /* This is because the _d_local_unwind() gets the stack munged
- * up on this. The workaround is to place any try-catches into
- * a separate function, and call that.
- * To fix, have the compiler automatically convert the finally
- * body into a nested function.
- */
- error(loc, "cannot put catch statement inside finally block");
+ /* This is because the _d_local_unwind() gets the stack munged
+ * up on this. The workaround is to place any try-catches into
+ * a separate function, and call that.
+ * To fix, have the compiler automatically convert the finally
+ * body into a nested function.
+ */
+ error(loc, "cannot put catch statement inside finally block");
}
#endif
@@ -4080,15 +4080,15 @@ void Catch::semantic(Scope *sc)
sc = sc->push(sym);
if (!type)
- type = new TypeIdentifier(0, Id::Object);
+ type = new TypeIdentifier(0, Id::Object);
type = type->semantic(loc, sc);
if (!type->toBasetype()->isClassHandle())
- error("can only catch class objects, not '%s'", type->toChars());
+ error("can only catch class objects, not '%s'", type->toChars());
else if (ident)
{
- var = new VarDeclaration(loc, type, ident, NULL);
- var->parent = sc->parent;
- sc->insert(var);
+ var = new VarDeclaration(loc, type, ident, NULL);
+ var->parent = sc->parent;
+ sc->insert(var);
}
handler = handler->semantic(sc);
@@ -4105,14 +4105,14 @@ void Catch::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring("catch");
if (type)
{ buf->writebyte('(');
- type->toCBuffer(buf, ident, hgs);
+ type->toCBuffer(buf, ident, hgs);
buf->writebyte(')');
}
buf->writenl();
buf->writebyte('{');
buf->writenl();
if (handler)
- handler->toCBuffer(buf, hgs);
+ handler->toCBuffer(buf, hgs);
buf->writebyte('}');
buf->writenl();
}
@@ -4129,7 +4129,7 @@ TryFinallyStatement::TryFinallyStatement(Loc loc, Statement *body, Statement *fi
Statement *TryFinallyStatement::syntaxCopy()
{
TryFinallyStatement *s = new TryFinallyStatement(loc,
- body->syntaxCopy(), finalbody->syntaxCopy());
+ body->syntaxCopy(), finalbody->syntaxCopy());
return s;
}
@@ -4145,7 +4145,7 @@ Statement *TryFinallyStatement::semantic(Scope *sc)
sc = sc->push();
sc->enclosingFinally = this;
sc->sbreak = NULL;
- sc->scontinue = NULL; // no break or continue out of finally block
+ sc->scontinue = NULL; // no break or continue out of finally block
finalbody = finalbody->semantic(sc);
sc->pop();
return this;
@@ -4179,7 +4179,7 @@ int TryFinallyStatement::usesEH()
int TryFinallyStatement::blockExit()
{
if (body)
- return body->blockExit();
+ return body->blockExit();
return BEfallthru;
}
@@ -4196,7 +4196,7 @@ OnScopeStatement::OnScopeStatement(Loc loc, TOK tok, Statement *statement)
Statement *OnScopeStatement::syntaxCopy()
{
OnScopeStatement *s = new OnScopeStatement(loc,
- tok, statement->syntaxCopy());
+ tok, statement->syntaxCopy());
return s;
}
@@ -4232,40 +4232,40 @@ void OnScopeStatement::scopeCode(Scope *sc, Statement **sentry, Statement **sexc
*sfinally = NULL;
switch (tok)
{
- case TOKon_scope_exit:
- *sfinally = statement;
- break;
+ case TOKon_scope_exit:
+ *sfinally = statement;
+ break;
- case TOKon_scope_failure:
- *sexception = statement;
- break;
+ case TOKon_scope_failure:
+ *sexception = statement;
+ break;
- case TOKon_scope_success:
- {
- /* Create:
- * sentry: int x = 0;
- * sexception: x = 1;
- * sfinally: if (!x) statement;
- */
- Identifier *id = Lexer::uniqueId("__os");
+ case TOKon_scope_success:
+ {
+ /* Create:
+ * sentry: int x = 0;
+ * sexception: x = 1;
+ * sfinally: if (!x) statement;
+ */
+ Identifier *id = Lexer::uniqueId("__os");
- ExpInitializer *ie = new ExpInitializer(loc, new IntegerExp(0));
- VarDeclaration *v = new VarDeclaration(loc, Type::tint32, id, ie);
- *sentry = new DeclarationStatement(loc, v);
+ ExpInitializer *ie = new ExpInitializer(loc, new IntegerExp(0));
+ VarDeclaration *v = new VarDeclaration(loc, Type::tint32, id, ie);
+ *sentry = new DeclarationStatement(loc, v);
- Expression *e = new IntegerExp(1);
- e = new AssignExp(0, new VarExp(0, v), e);
- *sexception = new ExpStatement(0, e);
+ Expression *e = new IntegerExp(1);
+ e = new AssignExp(0, new VarExp(0, v), e);
+ *sexception = new ExpStatement(0, e);
- e = new VarExp(0, v);
- e = new NotExp(0, e);
- *sfinally = new IfStatement(0, NULL, e, statement, NULL);
+ e = new VarExp(0, v);
+ e = new NotExp(0, e);
+ *sfinally = new IfStatement(0, NULL, e, statement, NULL);
- break;
- }
+ break;
+ }
- default:
- assert(0);
+ default:
+ assert(0);
}
}
@@ -4291,11 +4291,11 @@ Statement *ThrowStatement::semantic(Scope *sc)
fd->hasReturnExp |= 2;
if (sc->incontract)
- error("Throw statements cannot be in contracts");
+ error("Throw statements cannot be in contracts");
exp = exp->semantic(sc);
exp = resolveProperties(sc, exp);
if (!exp->type->toBasetype()->isClassHandle())
- error("can only throw class objects, not type %s", exp->type->toChars());
+ error("can only throw class objects, not type %s", exp->type->toChars());
return this;
}
@@ -4324,7 +4324,7 @@ VolatileStatement::VolatileStatement(Loc loc, Statement *statement)
Statement *VolatileStatement::syntaxCopy()
{
VolatileStatement *s = new VolatileStatement(loc,
- statement ? statement->syntaxCopy() : NULL);
+ statement ? statement->syntaxCopy() : NULL);
return s;
}
@@ -4332,10 +4332,10 @@ Statement *VolatileStatement::semantic(Scope *sc)
{
if (statement)
{
- Statement* oldScopeExit = sc->enclosingScopeExit;
- sc->enclosingScopeExit = this;
- statement = statement->semantic(sc);
- sc->enclosingScopeExit = oldScopeExit;
+ Statement* oldScopeExit = sc->enclosingScopeExit;
+ sc->enclosingScopeExit = this;
+ statement = statement->semantic(sc);
+ sc->enclosingScopeExit = oldScopeExit;
}
return this;
}
@@ -4346,12 +4346,12 @@ Statements *VolatileStatement::flatten(Scope *sc)
a = statement ? statement->flatten(sc) : NULL;
if (a)
- { for (int i = 0; i < a->dim; i++)
- { Statement *s = (Statement *)a->data[i];
+ { for (int i = 0; i < a->dim; i++)
+ { Statement *s = (Statement *)a->data[i];
- s = new VolatileStatement(loc, s);
- a->data[i] = s;
- }
+ s = new VolatileStatement(loc, s);
+ a->data[i] = s;
+ }
}
return a;
@@ -4403,22 +4403,22 @@ Statement *GotoStatement::semantic(Scope *sc)
label = fd->searchLabel(ident);
if (!label->statement && sc->fes)
{
- /* Either the goto label is forward referenced or it
- * is in the function that the enclosing foreach is in.
- * Can't know yet, so wrap the goto in a compound statement
- * so we can patch it later, and add it to a 'look at this later'
- * list.
- */
- Statements *a = new Statements();
- Statement *s;
+ /* Either the goto label is forward referenced or it
+ * is in the function that the enclosing foreach is in.
+ * Can't know yet, so wrap the goto in a compound statement
+ * so we can patch it later, and add it to a 'look at this later'
+ * list.
+ */
+ Statements *a = new Statements();
+ Statement *s;
- a->push(this);
- s = new CompoundStatement(loc, a);
- sc->fes->gotos.push(s); // 'look at this later' list
- return s;
+ a->push(this);
+ s = new CompoundStatement(loc, a);
+ sc->fes->gotos.push(s); // 'look at this later' list
+ return s;
}
if (label->statement && label->statement->enclosingFinally != sc->enclosingFinally)
- error("cannot goto in or out of finally block");
+ error("cannot goto in or out of finally block");
return this;
}
@@ -4464,9 +4464,9 @@ Statement *LabelStatement::semantic(Scope *sc)
//printf("LabelStatement::semantic()\n");
ls = fd->searchLabel(ident);
if (ls->statement)
- error("Label '%s' already defined", ls->toChars());
+ error("Label '%s' already defined", ls->toChars());
else
- ls->statement = this;
+ ls->statement = this;
enclosingFinally = sc->enclosingFinally;
enclosingScopeExit = sc->enclosingScopeExit;
@@ -4476,7 +4476,7 @@ Statement *LabelStatement::semantic(Scope *sc)
sc->callSuper |= CSXlabel;
sc->slabel = this;
if (statement)
- statement = statement->semantic(sc);
+ statement = statement->semantic(sc);
sc->pop();
// LDC put in labmap
@@ -4491,18 +4491,18 @@ Statements *LabelStatement::flatten(Scope *sc)
if (statement)
{
- a = statement->flatten(sc);
- if (a)
- {
- if (!a->dim)
- {
- a->push(new ExpStatement(loc, NULL));
- }
- Statement *s = (Statement *)a->data[0];
+ a = statement->flatten(sc);
+ if (a)
+ {
+ if (!a->dim)
+ {
+ a->push(new ExpStatement(loc, NULL));
+ }
+ Statement *s = (Statement *)a->data[0];
- s = new LabelStatement(loc, ident, s);
- a->data[0] = s;
- }
+ s = new LabelStatement(loc, ident, s);
+ a->data[0] = s;
+ }
}
return a;
@@ -4540,12 +4540,12 @@ void LabelStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/******************************** LabelDsymbol ***************************/
LabelDsymbol::LabelDsymbol(Identifier *ident)
- : Dsymbol(ident)
+ : Dsymbol(ident)
{
statement = NULL;
}
-LabelDsymbol *LabelDsymbol::isLabel() // is this a LabelDsymbol()?
+LabelDsymbol *LabelDsymbol::isLabel() // is this a LabelDsymbol()?
{
return this;
}
diff --git a/dmd/statement.h b/dmd/statement.h
index 6780c907..1ed3f503 100644
--- a/dmd/statement.h
+++ b/dmd/statement.h
@@ -84,13 +84,13 @@ struct code;
*/
enum BE
{
- BEnone = 0,
+ BEnone = 0,
BEfallthru = 1,
BEthrow = 2,
BEreturn = 4,
BEgoto = 8,
- BEhalt = 0x10,
- BEbreak = 0x20,
+ BEhalt = 0x10,
+ BEbreak = 0x20,
BEcontinue = 0x40,
BEany = (BEfallthru | BEthrow | BEreturn | BEgoto | BEhalt),
};
@@ -357,18 +357,18 @@ struct ForStatement : Statement
struct ForeachStatement : Statement
{
- enum TOK op; // TOKforeach or TOKforeach_reverse
- Parameters *arguments; // array of Parameter*'s
+ enum TOK op; // TOKforeach or TOKforeach_reverse
+ Parameters *arguments; // array of Parameter*'s
Expression *aggr;
Statement *body;
VarDeclaration *key;
VarDeclaration *value;
- FuncDeclaration *func; // function we're lexically in
+ FuncDeclaration *func; // function we're lexically in
- Array cases; // put breaks, continues, gotos and returns here
- Array gotos; // forward referenced goto's go here
+ Array cases; // put breaks, continues, gotos and returns here
+ Array gotos; // forward referenced goto's go here
ForeachStatement(Loc loc, enum TOK op, Parameters *arguments, Expression *aggr, Statement *body);
Statement *syntaxCopy();
@@ -389,8 +389,8 @@ struct ForeachStatement : Statement
#if DMDV2
struct ForeachRangeStatement : Statement
{
- enum TOK op; // TOKforeach or TOKforeach_reverse
- Parameter *arg; // loop index variable
+ enum TOK op; // TOKforeach or TOKforeach_reverse
+ Parameter *arg; // loop index variable
Expression *lwr;
Expression *upr;
Statement *body;
@@ -398,7 +398,7 @@ struct ForeachRangeStatement : Statement
VarDeclaration *key;
ForeachRangeStatement(Loc loc, enum TOK op, Parameter *arg,
- Expression *lwr, Expression *upr, Statement *body);
+ Expression *lwr, Expression *upr, Statement *body);
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
int hasBreak();
@@ -422,7 +422,7 @@ struct IfStatement : Statement
Statement *ifbody;
Statement *elsebody;
- VarDeclaration *match; // for MatchExpression results
+ VarDeclaration *match; // for MatchExpression results
IfStatement(Loc loc, Parameter *arg, Expression *condition, Statement *ifbody, Statement *elsebody);
Statement *syntaxCopy();
@@ -459,7 +459,7 @@ struct ConditionalStatement : Statement
struct PragmaStatement : Statement
{
Identifier *ident;
- Expressions *args; // array of Expression's
+ Expressions *args; // array of Expression's
Statement *body;
PragmaStatement(Loc loc, Identifier *ident, Expressions *args, Statement *body);
@@ -490,9 +490,9 @@ struct SwitchStatement : Statement
DefaultStatement *sdefault;
- Array gotoCases; // array of unresolved GotoCaseStatement's
- Array *cases; // array of CaseStatement's
- int hasNoDefault; // !=0 if no default statement
+ Array gotoCases; // array of unresolved GotoCaseStatement's
+ Array *cases; // array of CaseStatement's
+ int hasNoDefault; // !=0 if no default statement
// LDC
Statement *enclosingScopeExit;
@@ -516,8 +516,8 @@ struct CaseStatement : Statement
Expression *exp;
Statement *statement;
- int index; // which case it is (since we sort this)
- block *cblock; // back end: label for the block
+ int index; // which case it is (since we sort this)
+ block *cblock; // back end: label for the block
// LDC
Statement *enclosingScopeExit;
@@ -563,7 +563,7 @@ struct DefaultStatement : Statement
{
Statement *statement;
#if IN_GCC
- block *cblock; // back end: label for the block
+ block *cblock; // back end: label for the block
#endif
// LDC
@@ -602,8 +602,8 @@ struct GotoDefaultStatement : Statement
struct GotoCaseStatement : Statement
{
- Expression *exp; // NULL, or which case to goto
- CaseStatement *cs; // case statement it resolves to
+ Expression *exp; // NULL, or which case to goto
+ CaseStatement *cs; // case statement it resolves to
SwitchStatement *sw;
GotoCaseStatement(Loc loc, Expression *exp);
@@ -844,7 +844,7 @@ struct LabelStatement : Statement
Statement *statement;
TryFinallyStatement *enclosingFinally;
Statement* enclosingScopeExit;
- block *lblock; // back end
+ block *lblock; // back end
int isReturnLabel;
LabelStatement(Loc loc, Identifier *ident, Statement *statement);
@@ -880,9 +880,9 @@ struct AsmStatement : Statement
{
Token *tokens;
code *asmcode;
- unsigned asmalign; // alignment of this statement
- unsigned refparam; // !=0 if function parameter is referenced
- unsigned naked; // !=0 if function is to be naked
+ unsigned asmalign; // alignment of this statement
+ unsigned refparam; // !=0 if function parameter is referenced
+ unsigned naked; // !=0 if function is to be naked
AsmStatement(Loc loc, Token *tokens);
Statement *syntaxCopy();
diff --git a/dmd/staticassert.c b/dmd/staticassert.c
index 1a06ac7b..e80e4603 100644
--- a/dmd/staticassert.c
+++ b/dmd/staticassert.c
@@ -24,7 +24,7 @@
/********************************* AttribDeclaration ****************************/
StaticAssert::StaticAssert(Loc loc, Expression *exp, Expression *msg)
- : Dsymbol(Id::empty)
+ : Dsymbol(Id::empty)
{
this->loc = loc;
this->exp = exp;
@@ -42,7 +42,7 @@ Dsymbol *StaticAssert::syntaxCopy(Dsymbol *s)
int StaticAssert::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
{
- return 0; // we didn't add anything
+ return 0; // we didn't add anything
}
void StaticAssert::semantic(Scope *sc)
@@ -58,26 +58,26 @@ void StaticAssert::semantic2(Scope *sc)
e = e->optimize(WANTvalue | WANTinterpret);
if (e->isBool(FALSE))
{
- if (msg)
- { HdrGenState hgs;
- OutBuffer buf;
+ if (msg)
+ { HdrGenState hgs;
+ OutBuffer buf;
- msg = msg->semantic(sc);
- msg = msg->optimize(WANTvalue | WANTinterpret);
- hgs.console = 1;
- msg->toCBuffer(&buf, &hgs);
- error("%s", buf.toChars());
- }
- else
- error("(%s) is false", exp->toChars());
- if (sc->tinst)
- sc->tinst->printInstantiationTrace();
- if (!global.gag)
- fatal();
+ msg = msg->semantic(sc);
+ msg = msg->optimize(WANTvalue | WANTinterpret);
+ hgs.console = 1;
+ msg->toCBuffer(&buf, &hgs);
+ error("%s", buf.toChars());
+ }
+ else
+ error("(%s) is false", exp->toChars());
+ if (sc->tinst)
+ sc->tinst->printInstantiationTrace();
+ if (!global.gag)
+ fatal();
}
else if (!e->isBool(TRUE))
{
- error("(%s) is not evaluatable at compile time", exp->toChars());
+ error("(%s) is not evaluatable at compile time", exp->toChars());
}
}
@@ -108,8 +108,8 @@ void StaticAssert::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
exp->toCBuffer(buf, hgs);
if (msg)
{
- buf->writeByte(',');
- msg->toCBuffer(buf, hgs);
+ buf->writeByte(',');
+ msg->toCBuffer(buf, hgs);
}
buf->writestring(");");
buf->writenl();
diff --git a/dmd/struct.c b/dmd/struct.c
index fb6123b2..a71328cf 100644
--- a/dmd/struct.c
+++ b/dmd/struct.c
@@ -32,11 +32,11 @@ AggregateDeclaration::AggregateDeclaration(Loc loc, Identifier *id)
protection = PROTpublic;
type = NULL;
handle = NULL;
- structsize = 0; // size of struct
- alignsize = 0; // size of struct for alignment purposes
- structalign = 0; // struct member alignment in effect
+ structsize = 0; // size of struct
+ alignsize = 0; // size of struct for alignment purposes
+ structalign = 0; // struct member alignment in effect
hasUnions = 0;
- sizeok = 0; // size not determined yet
+ sizeok = 0; // size not determined yet
isdeprecated = 0;
inv = NULL;
aggNew = NULL;
@@ -67,18 +67,18 @@ void AggregateDeclaration::semantic2(Scope *sc)
{
//printf("AggregateDeclaration::semantic2(%s)\n", toChars());
if (scope && members)
- { error("has forward references");
- return;
+ { error("has forward references");
+ return;
}
if (members)
{
- sc = sc->push(this);
- for (size_t i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->semantic2(sc);
- }
- sc->pop();
+ sc = sc->push(this);
+ for (size_t i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->semantic2(sc);
+ }
+ sc->pop();
}
}
@@ -92,13 +92,13 @@ void AggregateDeclaration::semantic3(Scope *sc)
//printf("AggregateDeclaration::semantic3(%s)\n", toChars());
if (members)
{
- sc = sc->push(this);
- for (i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->semantic3(sc);
- }
- sc->pop();
+ sc = sc->push(this);
+ for (i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->semantic3(sc);
+ }
+ sc->pop();
}
}
@@ -108,12 +108,12 @@ void AggregateDeclaration::inlineScan()
//printf("AggregateDeclaration::inlineScan(%s)\n", toChars());
if (members)
{
- for (i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- //printf("inline scan aggregate symbol '%s'\n", s->toChars());
- s->inlineScan();
- }
+ for (i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ //printf("inline scan aggregate symbol '%s'\n", s->toChars());
+ s->inlineScan();
+ }
}
}
@@ -121,10 +121,10 @@ unsigned AggregateDeclaration::size(Loc loc)
{
//printf("AggregateDeclaration::size() = %d\n", structsize);
if (!members)
- error(loc, "unknown size");
+ error(loc, "unknown size");
if (sizeok != 1)
- { error(loc, "no size yet for forward reference");
- //*(char*)0=0;
+ { error(loc, "no size yet for forward reference");
+ //*(char*)0=0;
}
return structsize;
}
@@ -145,18 +145,18 @@ int AggregateDeclaration::isDeprecated()
*/
void AggregateDeclaration::alignmember(
- unsigned salign, // struct alignment that is in effect
- unsigned size, // alignment requirement of field
- unsigned *poffset)
+ unsigned salign, // struct alignment that is in effect
+ unsigned size, // alignment requirement of field
+ unsigned *poffset)
{
//printf("salign = %d, size = %d, offset = %d\n",salign,size,offset);
if (salign > 1)
{
- assert(size != 3);
- int sa = size;
- if (sa == 0 || salign < sa)
- sa = salign;
- *poffset = (*poffset + sa - 1) & ~(sa - 1);
+ assert(size != 3);
+ int sa = size;
+ if (sa == 0 || salign < sa)
+ sa = salign;
+ *poffset = (*poffset + sa - 1) & ~(sa - 1);
}
//printf("result = %d\n",offset);
}
@@ -164,33 +164,33 @@ void AggregateDeclaration::alignmember(
void AggregateDeclaration::addField(Scope *sc, VarDeclaration *v)
{
- unsigned memsize; // size of member
- unsigned memalignsize; // size of member for alignment purposes
- unsigned xalign; // alignment boundaries
+ unsigned memsize; // size of member
+ unsigned memalignsize; // size of member for alignment purposes
+ unsigned xalign; // alignment boundaries
//printf("AggregateDeclaration::addField('%s') %s\n", v->toChars(), toChars());
// Check for forward referenced types which will fail the size() call
Type *t = v->type->toBasetype();
if (t->ty == Tstruct /*&& isStructDeclaration()*/)
- { TypeStruct *ts = (TypeStruct *)t;
+ { TypeStruct *ts = (TypeStruct *)t;
#if DMDV2
- if (ts->sym == this)
- {
- error("cannot have field %s with same struct type", v->toChars());
- }
+ if (ts->sym == this)
+ {
+ error("cannot have field %s with same struct type", v->toChars());
+ }
#endif
- if (ts->sym->sizeok != 1)
- {
- sizeok = 2; // cannot finish; flag as forward referenced
- return;
- }
+ if (ts->sym->sizeok != 1)
+ {
+ sizeok = 2; // cannot finish; flag as forward referenced
+ return;
+ }
}
if (t->ty == Tident)
{
- sizeok = 2; // cannot finish; flag as forward referenced
- return;
+ sizeok = 2; // cannot finish; flag as forward referenced
+ return;
}
memsize = v->type->size(loc);
@@ -200,11 +200,11 @@ void AggregateDeclaration::addField(Scope *sc, VarDeclaration *v)
v->offset = sc->offset;
sc->offset += memsize;
if (sc->offset > structsize)
- structsize = sc->offset;
+ structsize = sc->offset;
if (sc->structalign < memalignsize)
- memalignsize = sc->structalign;
+ memalignsize = sc->structalign;
if (alignsize < memalignsize)
- alignsize = memalignsize;
+ alignsize = memalignsize;
//printf("\talignsize = %d\n", alignsize);
v->storage_class |= STCfield;
@@ -218,7 +218,7 @@ void AggregateDeclaration::addField(Scope *sc, VarDeclaration *v)
StructDeclaration::StructDeclaration(Loc loc, Identifier *id)
: AggregateDeclaration(loc, id)
{
- zeroInit = 0; // assume false until we do semantic processing
+ zeroInit = 0; // assume false until we do semantic processing
#if DMDV2
hasIdentityAssign = 0;
cpctor = NULL;
@@ -234,9 +234,9 @@ Dsymbol *StructDeclaration::syntaxCopy(Dsymbol *s)
StructDeclaration *sd;
if (s)
- sd = (StructDeclaration *)s;
+ sd = (StructDeclaration *)s;
else
- sd = new StructDeclaration(loc, ident);
+ sd = new StructDeclaration(loc, ident);
ScopeDsymbol::syntaxCopy(sd);
return sd;
}
@@ -250,15 +250,15 @@ void StructDeclaration::semantic(Scope *sc)
//static int count; if (++count == 20) *(char*)0=0;
assert(type);
- if (!members) // if forward reference
- return;
+ if (!members) // if forward reference
+ return;
if (symtab)
{ if (sizeok == 1 || !scope)
- { //printf("already completed\n");
- scope = NULL;
+ { //printf("already completed\n");
+ scope = NULL;
return; // semantic() already completed
- }
+ }
}
else
symtab = new DsymbolTable();
@@ -282,10 +282,10 @@ void StructDeclaration::semantic(Scope *sc)
structalign = sc->structalign;
protection = sc->protection;
if (sc->stc & STCdeprecated)
- isdeprecated = 1;
+ isdeprecated = 1;
assert(!isAnonymous());
if (sc->stc & STCabstract)
- error("structs, unions cannot be abstract");
+ error("structs, unions cannot be abstract");
#if DMDV2
if (storage_class & STCimmutable)
type = type->invariantOf();
@@ -293,14 +293,14 @@ void StructDeclaration::semantic(Scope *sc)
type = type->constOf();
#endif
- if (sizeok == 0) // if not already done the addMember step
+ if (sizeok == 0) // if not already done the addMember step
{
- for (i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- //printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars());
- s->addMember(sc, this, 1);
- }
+ for (i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ //printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars());
+ s->addMember(sc, this, 1);
+ }
}
sizeok = 0;
@@ -308,7 +308,7 @@ void StructDeclaration::semantic(Scope *sc)
sc2->stc = 0;
sc2->parent = this;
if (isUnionDeclaration())
- sc2->inunion = 1;
+ sc2->inunion = 1;
sc2->protection = PROTpublic;
sc2->explicitProtection = 0;
@@ -318,28 +318,28 @@ void StructDeclaration::semantic(Scope *sc)
* resolve individual members like enums.
*/
for (int i = 0; i < members_dim; i++)
- { Dsymbol *s = (Dsymbol *)members->data[i];
- /* There are problems doing this in the general case because
- * Scope keeps track of things like 'offset'
- */
- if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident))
- {
- //printf("setScope %s %s\n", s->kind(), s->toChars());
- s->setScope(sc2);
- }
+ { Dsymbol *s = (Dsymbol *)members->data[i];
+ /* There are problems doing this in the general case because
+ * Scope keeps track of things like 'offset'
+ */
+ if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident))
+ {
+ //printf("setScope %s %s\n", s->kind(), s->toChars());
+ s->setScope(sc2);
+ }
}
for (i = 0; i < members_dim; i++)
{
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->semantic(sc2);
- if (isUnionDeclaration())
- sc2->offset = 0;
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->semantic(sc2);
+ if (isUnionDeclaration())
+ sc2->offset = 0;
#if 0
- if (sizeok == 2)
- { //printf("forward reference\n");
- break;
- }
+ if (sizeok == 2)
+ { //printf("forward reference\n");
+ break;
+ }
#endif
}
@@ -347,58 +347,58 @@ void StructDeclaration::semantic(Scope *sc)
* a parameter that is a pointer to the struct. But if there
* isn't one, but is an opEquals or opCmp with a value, write
* another that is a shell around the value:
- * int opCmp(struct *p) { return opCmp(*p); }
+ * int opCmp(struct *p) { return opCmp(*p); }
*/
TypeFunction *tfeqptr;
{
- Parameters *arguments = new Parameters;
- Parameter *arg = new Parameter(STCin, handle, Id::p, NULL);
+ Parameters *arguments = new Parameters;
+ Parameter *arg = new Parameter(STCin, handle, Id::p, NULL);
- arguments->push(arg);
- tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd);
- tfeqptr = (TypeFunction *)tfeqptr->semantic(0, sc);
+ arguments->push(arg);
+ tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd);
+ tfeqptr = (TypeFunction *)tfeqptr->semantic(0, sc);
}
TypeFunction *tfeq;
{
- Parameters *arguments = new Parameters;
- Parameter *arg = new Parameter(STCin, type, NULL, NULL);
+ Parameters *arguments = new Parameters;
+ Parameter *arg = new Parameter(STCin, type, NULL, NULL);
- arguments->push(arg);
- tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd);
- tfeq = (TypeFunction *)tfeq->semantic(0, sc);
+ arguments->push(arg);
+ tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd);
+ tfeq = (TypeFunction *)tfeq->semantic(0, sc);
}
Identifier *id = Id::eq;
for (int i = 0; i < 2; i++)
{
- Dsymbol *s = search_function(this, id);
- FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL;
- if (fdx)
- { FuncDeclaration *fd = fdx->overloadExactMatch(tfeqptr, getModule());
- if (!fd)
- { fd = fdx->overloadExactMatch(tfeq, getModule());
- if (fd)
- { // Create the thunk, fdptr
- FuncDeclaration *fdptr = new FuncDeclaration(loc, loc, fdx->ident, STCundefined, tfeqptr);
- Expression *e = new IdentifierExp(loc, Id::p);
- e = new PtrExp(loc, e);
- Expressions *args = new Expressions();
- args->push(e);
- e = new IdentifierExp(loc, id);
- e = new CallExp(loc, e, args);
- fdptr->fbody = new ReturnStatement(loc, e);
- ScopeDsymbol *s = fdx->parent->isScopeDsymbol();
- assert(s);
- s->members->push(fdptr);
- fdptr->addMember(sc, s, 1);
- fdptr->semantic(sc2);
- }
- }
- }
+ Dsymbol *s = search_function(this, id);
+ FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL;
+ if (fdx)
+ { FuncDeclaration *fd = fdx->overloadExactMatch(tfeqptr, getModule());
+ if (!fd)
+ { fd = fdx->overloadExactMatch(tfeq, getModule());
+ if (fd)
+ { // Create the thunk, fdptr
+ FuncDeclaration *fdptr = new FuncDeclaration(loc, loc, fdx->ident, STCundefined, tfeqptr);
+ Expression *e = new IdentifierExp(loc, Id::p);
+ e = new PtrExp(loc, e);
+ Expressions *args = new Expressions();
+ args->push(e);
+ e = new IdentifierExp(loc, id);
+ e = new CallExp(loc, e, args);
+ fdptr->fbody = new ReturnStatement(loc, e);
+ ScopeDsymbol *s = fdx->parent->isScopeDsymbol();
+ assert(s);
+ s->members->push(fdptr);
+ fdptr->addMember(sc, s, 1);
+ fdptr->semantic(sc2);
+ }
+ }
+ }
- id = Id::cmp;
+ id = Id::cmp;
}
#if DMDV2
dtor = buildDtor(sc2);
@@ -410,27 +410,27 @@ void StructDeclaration::semantic(Scope *sc)
sc2->pop();
if (sizeok == 2)
- { // semantic() failed because of forward references.
- // Unwind what we did, and defer it for later
- fields.setDim(0);
- structsize = 0;
- alignsize = 0;
- structalign = 0;
+ { // semantic() failed because of forward references.
+ // Unwind what we did, and defer it for later
+ fields.setDim(0);
+ structsize = 0;
+ alignsize = 0;
+ structalign = 0;
- scope = scx ? scx : new Scope(*sc);
- scope->setNoFree();
- scope->module->addDeferredSemantic(this);
+ scope = scx ? scx : new Scope(*sc);
+ scope->setNoFree();
+ scope->module->addDeferredSemantic(this);
- Module::dprogress = dprogress_save;
- //printf("\tdeferring %s\n", toChars());
- return;
+ Module::dprogress = dprogress_save;
+ //printf("\tdeferring %s\n", toChars());
+ return;
}
// 0 sized struct's are set to 1 byte
if (structsize == 0)
{
- structsize = 1;
- alignsize = 1;
+ structsize = 1;
+ alignsize = 1;
}
// Round struct size up to next alignsize boundary.
@@ -447,25 +447,25 @@ void StructDeclaration::semantic(Scope *sc)
zeroInit = 1;
for (i = 0; i < fields.dim; i++)
{
- Dsymbol *s = (Dsymbol *)fields.data[i];
- VarDeclaration *vd = s->isVarDeclaration();
- if (vd && !vd->isDataseg())
- {
- if (vd->init)
- {
- // Should examine init to see if it is really all 0's
- zeroInit = 0;
- break;
- }
- else
- {
- if (!vd->type->isZeroInit(loc))
- {
- zeroInit = 0;
- break;
- }
- }
- }
+ Dsymbol *s = (Dsymbol *)fields.data[i];
+ VarDeclaration *vd = s->isVarDeclaration();
+ if (vd && !vd->isDataseg())
+ {
+ if (vd->init)
+ {
+ // Should examine init to see if it is really all 0's
+ zeroInit = 0;
+ break;
+ }
+ else
+ {
+ if (!vd->type->isZeroInit(loc))
+ {
+ zeroInit = 0;
+ break;
+ }
+ }
+ }
}
/* Look for special member functions.
@@ -479,8 +479,8 @@ void StructDeclaration::semantic(Scope *sc)
if (sc->func)
{
- semantic2(sc);
- semantic3(sc);
+ semantic2(sc);
+ semantic3(sc);
}
}
@@ -489,12 +489,12 @@ Dsymbol *StructDeclaration::search(Loc loc, Identifier *ident, int flags)
//printf("%s.StructDeclaration::search('%s')\n", toChars(), ident->toChars());
if (scope)
- semantic(scope);
+ semantic(scope);
if (!members || !symtab)
{
- error("is forward referenced when looking for '%s'", ident->toChars());
- return NULL;
+ error("is forward referenced when looking for '%s'", ident->toChars());
+ return NULL;
}
return ScopeDsymbol::search(loc, ident, flags);
@@ -505,22 +505,22 @@ void StructDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->printf("%s ", kind());
if (!isAnonymous())
- buf->writestring(toChars());
+ buf->writestring(toChars());
if (!members)
{
- buf->writeByte(';');
- buf->writenl();
- return;
+ buf->writeByte(';');
+ buf->writenl();
+ return;
}
buf->writenl();
buf->writeByte('{');
buf->writenl();
for (i = 0; i < members->dim; i++)
{
- Dsymbol *s = (Dsymbol *)members->data[i];
+ Dsymbol *s = (Dsymbol *)members->data[i];
- buf->writestring(" ");
- s->toCBuffer(buf, hgs);
+ buf->writestring(" ");
+ s->toCBuffer(buf, hgs);
}
buf->writeByte('}');
buf->writenl();
@@ -544,9 +544,9 @@ Dsymbol *UnionDeclaration::syntaxCopy(Dsymbol *s)
UnionDeclaration *ud;
if (s)
- ud = (UnionDeclaration *)s;
+ ud = (UnionDeclaration *)s;
else
- ud = new UnionDeclaration(loc, ident);
+ ud = new UnionDeclaration(loc, ident);
StructDeclaration::syntaxCopy(ud);
return ud;
}
diff --git a/dmd/template.c b/dmd/template.c
index faacb23b..aef93d8a 100644
--- a/dmd/template.c
+++ b/dmd/template.c
@@ -36,7 +36,7 @@
long __cdecl __ehfilter(LPEXCEPTION_POINTERS ep);
#endif
-#define LOG 0
+#define LOG 0
/********************************************
* These functions substitute for dynamic_cast. dynamic_cast does not work
@@ -47,7 +47,7 @@ Expression *isExpression(Object *o)
{
//return dynamic_cast(o);
if (!o || o->dyncast() != DYNCAST_EXPRESSION)
- return NULL;
+ return NULL;
return (Expression *)o;
}
@@ -55,7 +55,7 @@ Dsymbol *isDsymbol(Object *o)
{
//return dynamic_cast(o);
if (!o || o->dyncast() != DYNCAST_DSYMBOL)
- return NULL;
+ return NULL;
return (Dsymbol *)o;
}
@@ -63,7 +63,7 @@ Type *isType(Object *o)
{
//return dynamic_cast(o);
if (!o || o->dyncast() != DYNCAST_TYPE)
- return NULL;
+ return NULL;
return (Type *)o;
}
@@ -71,7 +71,7 @@ Tuple *isTuple(Object *o)
{
//return dynamic_cast(o);
if (!o || o->dyncast() != DYNCAST_TUPLE)
- return NULL;
+ return NULL;
return (Tuple *)o;
}
@@ -85,8 +85,8 @@ Type *getType(Object *o)
Type *t = isType(o);
if (!t)
{ Expression *e = isExpression(o);
- if (e)
- t = e->type;
+ if (e)
+ t = e->type;
}
return t;
}
@@ -97,20 +97,20 @@ Dsymbol *getDsymbol(Object *oarg)
Expression *ea = isExpression(oarg);
if (ea)
{ // Try to convert Expression to symbol
- if (ea->op == TOKvar)
- sa = ((VarExp *)ea)->var;
- else if (ea->op == TOKfunction)
- sa = ((FuncExp *)ea)->fd;
- else
- sa = NULL;
+ if (ea->op == TOKvar)
+ sa = ((VarExp *)ea)->var;
+ else if (ea->op == TOKfunction)
+ sa = ((FuncExp *)ea)->fd;
+ else
+ sa = NULL;
}
else
{ // Try to convert Type to symbol
- Type *ta = isType(oarg);
- if (ta)
- sa = ta->toDsymbol(NULL);
- else
- sa = isDsymbol(oarg); // if already a symbol
+ Type *ta = isType(oarg);
+ if (ta)
+ sa = ta->toDsymbol(NULL);
+ else
+ sa = isDsymbol(oarg); // if already a symbol
}
return sa;
}
@@ -140,84 +140,84 @@ int match(Object *o1, Object *o2, TemplateDeclaration *tempdecl, Scope *sc)
if (t1)
{
- /* if t1 is an instance of ti, then give error
- * about recursive expansions.
- */
- Dsymbol *s = t1->toDsymbol(sc);
- if (s && s->parent)
- { TemplateInstance *ti1 = s->parent->isTemplateInstance();
- if (ti1 && ti1->tempdecl == tempdecl)
- {
- for (Scope *sc1 = sc; sc1; sc1 = sc1->enclosing)
- {
- if (sc1->scopesym == ti1)
- {
- error("recursive template expansion for template argument %s", t1->toChars());
- return 1; // fake a match
- }
- }
- }
- }
+ /* if t1 is an instance of ti, then give error
+ * about recursive expansions.
+ */
+ Dsymbol *s = t1->toDsymbol(sc);
+ if (s && s->parent)
+ { TemplateInstance *ti1 = s->parent->isTemplateInstance();
+ if (ti1 && ti1->tempdecl == tempdecl)
+ {
+ for (Scope *sc1 = sc; sc1; sc1 = sc1->enclosing)
+ {
+ if (sc1->scopesym == ti1)
+ {
+ error("recursive template expansion for template argument %s", t1->toChars());
+ return 1; // fake a match
+ }
+ }
+ }
+ }
- //printf("t1 = %s\n", t1->toChars());
- //printf("t2 = %s\n", t2->toChars());
- if (!t2 || !t1->equals(t2))
- goto Lnomatch;
+ //printf("t1 = %s\n", t1->toChars());
+ //printf("t2 = %s\n", t2->toChars());
+ if (!t2 || !t1->equals(t2))
+ goto Lnomatch;
}
else if (e1)
{
#if 0
- if (e1 && e2)
- {
- printf("match %d\n", e1->equals(e2));
- e1->print();
- e2->print();
- e1->type->print();
- e2->type->print();
- }
+ if (e1 && e2)
+ {
+ printf("match %d\n", e1->equals(e2));
+ e1->print();
+ e2->print();
+ e1->type->print();
+ e2->type->print();
+ }
#endif
- if (!e2)
- goto Lnomatch;
- if (!e1->equals(e2))
- goto Lnomatch;
+ if (!e2)
+ goto Lnomatch;
+ if (!e1->equals(e2))
+ goto Lnomatch;
}
else if (s1)
{
- //printf("%p %s, %p %s\n", s1, s1->toChars(), s2, s2->toChars());
- if (!s2 || !s1->equals(s2) || s1->parent != s2->parent)
- {
- goto Lnomatch;
- }
+ //printf("%p %s, %p %s\n", s1, s1->toChars(), s2, s2->toChars());
+ if (!s2 || !s1->equals(s2) || s1->parent != s2->parent)
+ {
+ goto Lnomatch;
+ }
#if DMDV2
- VarDeclaration *v1 = s1->isVarDeclaration();
- VarDeclaration *v2 = s2->isVarDeclaration();
- if (v1 && v2 && v1->storage_class & v2->storage_class & STCmanifest)
- { ExpInitializer *ei1 = v1->init->isExpInitializer();
- ExpInitializer *ei2 = v2->init->isExpInitializer();
- if (ei1 && ei2 && !ei1->exp->equals(ei2->exp))
- goto Lnomatch;
- }
+ VarDeclaration *v1 = s1->isVarDeclaration();
+ VarDeclaration *v2 = s2->isVarDeclaration();
+ if (v1 && v2 && v1->storage_class & v2->storage_class & STCmanifest)
+ { ExpInitializer *ei1 = v1->init->isExpInitializer();
+ ExpInitializer *ei2 = v2->init->isExpInitializer();
+ if (ei1 && ei2 && !ei1->exp->equals(ei2->exp))
+ goto Lnomatch;
+ }
#endif
}
else if (v1)
{
- if (!v2)
- goto Lnomatch;
- if (v1->objects.dim != v2->objects.dim)
- goto Lnomatch;
- for (size_t i = 0; i < v1->objects.dim; i++)
- {
- if (!match((Object *)v1->objects.data[i],
- (Object *)v2->objects.data[i],
- tempdecl, sc))
- goto Lnomatch;
- }
+ if (!v2)
+ goto Lnomatch;
+ if (v1->objects.dim != v2->objects.dim)
+ goto Lnomatch;
+ for (size_t i = 0; i < v1->objects.dim; i++)
+ {
+ if (!match((Object *)v1->objects.data[i],
+ (Object *)v2->objects.data[i],
+ tempdecl, sc))
+ goto Lnomatch;
+ }
}
//printf("match\n");
- return 1; // match
+ return 1; // match
Lnomatch:
//printf("nomatch\n");
- return 0; // nomatch;
+ return 0; // nomatch;
}
/****************************************
@@ -231,37 +231,37 @@ void ObjectToCBuffer(OutBuffer *buf, HdrGenState *hgs, Object *oarg)
Dsymbol *s = isDsymbol(oarg);
Tuple *v = isTuple(oarg);
if (t)
- { //printf("\tt: %s ty = %d\n", t->toChars(), t->ty);
- t->toCBuffer(buf, NULL, hgs);
+ { //printf("\tt: %s ty = %d\n", t->toChars(), t->ty);
+ t->toCBuffer(buf, NULL, hgs);
}
else if (e)
- e->toCBuffer(buf, hgs);
+ e->toCBuffer(buf, hgs);
else if (s)
{
- char *p = s->ident ? s->ident->toChars() : s->toChars();
- buf->writestring(p);
+ char *p = s->ident ? s->ident->toChars() : s->toChars();
+ buf->writestring(p);
}
else if (v)
{
- Objects *args = &v->objects;
- for (size_t i = 0; i < args->dim; i++)
- {
- if (i)
- buf->writeByte(',');
- Object *o = (Object *)args->data[i];
- ObjectToCBuffer(buf, hgs, o);
- }
+ Objects *args = &v->objects;
+ for (size_t i = 0; i < args->dim; i++)
+ {
+ if (i)
+ buf->writeByte(',');
+ Object *o = (Object *)args->data[i];
+ ObjectToCBuffer(buf, hgs, o);
+ }
}
else if (!oarg)
{
- buf->writestring("NULL");
+ buf->writestring("NULL");
}
else
{
#ifdef DEBUG
- printf("bad Object = %p\n", oarg);
+ printf("bad Object = %p\n", oarg);
#endif
- assert(0);
+ assert(0);
}
}
@@ -269,13 +269,13 @@ void ObjectToCBuffer(OutBuffer *buf, HdrGenState *hgs, Object *oarg)
Object *objectSyntaxCopy(Object *o)
{
if (!o)
- return NULL;
+ return NULL;
Type *t = isType(o);
if (t)
- return t->syntaxCopy();
+ return t->syntaxCopy();
Expression *e = isExpression(o);
if (e)
- return e->syntaxCopy();
+ return e->syntaxCopy();
return o;
}
#endif
@@ -284,7 +284,7 @@ Object *objectSyntaxCopy(Object *o)
/* ======================== TemplateDeclaration ============================= */
TemplateDeclaration::TemplateDeclaration(Loc loc, Identifier *id,
- TemplateParameters *parameters, Expression *constraint, Array *decldefs)
+ TemplateParameters *parameters, Expression *constraint, Array *decldefs)
: ScopeDsymbol(id)
{
#if LOG
@@ -292,16 +292,16 @@ TemplateDeclaration::TemplateDeclaration(Loc loc, Identifier *id,
#endif
#if 0
if (parameters)
- for (int i = 0; i < parameters->dim; i++)
- { TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- //printf("\tparameter[%d] = %p\n", i, tp);
- TemplateTypeParameter *ttp = tp->isTemplateTypeParameter();
+ for (int i = 0; i < parameters->dim; i++)
+ { TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ //printf("\tparameter[%d] = %p\n", i, tp);
+ TemplateTypeParameter *ttp = tp->isTemplateTypeParameter();
- if (ttp)
- {
- printf("\tparameter[%d] = %s : %s\n", i, tp->ident->toChars(), ttp->specType ? ttp->specType->toChars() : "");
- }
- }
+ if (ttp)
+ {
+ printf("\tparameter[%d] = %s : %s\n", i, tp->ident->toChars(), ttp->specType ? ttp->specType->toChars() : "");
+ }
+ }
#endif
this->loc = loc;
this->parameters = parameters;
@@ -324,16 +324,16 @@ Dsymbol *TemplateDeclaration::syntaxCopy(Dsymbol *)
p = NULL;
if (parameters)
{
- p = new TemplateParameters();
- p->setDim(parameters->dim);
- for (int i = 0; i < p->dim; i++)
- { TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- p->data[i] = (void *)tp->syntaxCopy();
- }
+ p = new TemplateParameters();
+ p->setDim(parameters->dim);
+ for (int i = 0; i < p->dim; i++)
+ { TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ p->data[i] = (void *)tp->syntaxCopy();
+ }
}
Expression *e = NULL;
if (constraint)
- e = constraint->syntaxCopy();
+ e = constraint->syntaxCopy();
d = Dsymbol::arraySyntaxCopy(members);
td = new TemplateDeclaration(loc, ident, p, e, d);
@@ -351,32 +351,32 @@ void TemplateDeclaration::semantic(Scope *sc)
printf("TemplateDeclaration::semantic(this = %p, id = '%s')\n", this, ident->toChars());
#endif
if (semanticRun)
- return; // semantic() already run
+ return; // semantic() already run
semanticRun = 1;
if (sc->func)
{
#if DMDV1
- error("cannot declare template at function scope %s", sc->func->toChars());
+ error("cannot declare template at function scope %s", sc->func->toChars());
#endif
}
if (/*global.params.useArrayBounds &&*/ sc->module)
{
- // Generate this function as it may be used
- // when template is instantiated in other modules
+ // Generate this function as it may be used
+ // when template is instantiated in other modules
- // FIXME: LDC
- //sc->module->toModuleArray();
+ // FIXME: LDC
+ //sc->module->toModuleArray();
}
if (/*global.params.useAssert &&*/ sc->module)
{
- // Generate this function as it may be used
- // when template is instantiated in other modules
+ // Generate this function as it may be used
+ // when template is instantiated in other modules
- // FIXME: LDC
- //sc->module->toModuleAssert();
+ // FIXME: LDC
+ //sc->module->toModuleAssert();
}
/* Remember Scope for later instantiations, but make
@@ -394,56 +394,56 @@ void TemplateDeclaration::semantic(Scope *sc)
if (global.params.doDocComments)
{
- origParameters = new TemplateParameters();
- origParameters->setDim(parameters->dim);
- for (int i = 0; i < parameters->dim; i++)
- {
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- origParameters->data[i] = (void *)tp->syntaxCopy();
- }
+ origParameters = new TemplateParameters();
+ origParameters->setDim(parameters->dim);
+ for (int i = 0; i < parameters->dim; i++)
+ {
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ origParameters->data[i] = (void *)tp->syntaxCopy();
+ }
}
for (int i = 0; i < parameters->dim; i++)
{
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- tp->declareParameter(paramscope);
+ tp->declareParameter(paramscope);
}
for (int i = 0; i < parameters->dim; i++)
{
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- tp->semantic(paramscope);
- if (i + 1 != parameters->dim && tp->isTemplateTupleParameter())
- error("template tuple parameter must be last one");
+ tp->semantic(paramscope);
+ if (i + 1 != parameters->dim && tp->isTemplateTupleParameter())
+ error("template tuple parameter must be last one");
}
paramscope->pop();
if (members)
{
- Dsymbol *s;
- if (Dsymbol::oneMembers(members, &s))
- {
- if (s && s->ident && s->ident->equals(ident))
- {
- onemember = s;
- s->parent = this;
- }
- }
+ Dsymbol *s;
+ if (Dsymbol::oneMembers(members, &s))
+ {
+ if (s && s->ident && s->ident->equals(ident))
+ {
+ onemember = s;
+ s->parent = this;
+ }
+ }
}
/* BUG: should check:
- * o no virtual functions or non-static data members of classes
+ * o no virtual functions or non-static data members of classes
*/
}
const char *TemplateDeclaration::kind()
{
return (onemember && onemember->isAggregateDeclaration())
- ? onemember->kind()
- : (char *)"template";
+ ? onemember->kind()
+ : (char *)"template";
}
/**********************************
@@ -461,34 +461,34 @@ int TemplateDeclaration::overloadInsert(Dsymbol *s)
#endif
f = s->isTemplateDeclaration();
if (!f)
- return FALSE;
+ return FALSE;
TemplateDeclaration *pthis = this;
for (pf = &pthis; *pf; pf = &(*pf)->overnext)
{
#if 0
- // Conflict if TemplateParameter's match
- // Will get caught anyway later with TemplateInstance, but
- // should check it now.
- TemplateDeclaration *f2 = *pf;
+ // Conflict if TemplateParameter's match
+ // Will get caught anyway later with TemplateInstance, but
+ // should check it now.
+ TemplateDeclaration *f2 = *pf;
- if (f->parameters->dim != f2->parameters->dim)
- goto Lcontinue;
+ if (f->parameters->dim != f2->parameters->dim)
+ goto Lcontinue;
- for (int i = 0; i < f->parameters->dim; i++)
- { TemplateParameter *p1 = (TemplateParameter *)f->parameters->data[i];
- TemplateParameter *p2 = (TemplateParameter *)f2->parameters->data[i];
+ for (int i = 0; i < f->parameters->dim; i++)
+ { TemplateParameter *p1 = (TemplateParameter *)f->parameters->data[i];
+ TemplateParameter *p2 = (TemplateParameter *)f2->parameters->data[i];
- if (!p1->overloadMatch(p2))
- goto Lcontinue;
- }
+ if (!p1->overloadMatch(p2))
+ goto Lcontinue;
+ }
#if LOG
- printf("\tfalse: conflict\n");
+ printf("\tfalse: conflict\n");
#endif
- return FALSE;
+ return FALSE;
Lcontinue:
- ;
+ ;
#endif
}
@@ -505,15 +505,15 @@ int TemplateDeclaration::overloadInsert(Dsymbol *s)
* deduce the types of the parameters to this, and store
* those deduced types in dedtypes[].
* Input:
- * flag 1: don't do semantic() because of dummy types
- * 2: don't change types in matchArg()
+ * flag 1: don't do semantic() because of dummy types
+ * 2: don't change types in matchArg()
* Output:
- * dedtypes deduced arguments
+ * dedtypes deduced arguments
* Return match level.
*/
MATCH TemplateDeclaration::matchWithInstance(TemplateInstance *ti,
- Objects *dedtypes, int flag)
+ Objects *dedtypes, int flag)
{ MATCH m;
int dedtypes_dim = dedtypes->dim;
@@ -525,9 +525,9 @@ MATCH TemplateDeclaration::matchWithInstance(TemplateInstance *ti,
#if 0
printf("dedtypes->dim = %d, parameters->dim = %d\n", dedtypes_dim, parameters->dim);
if (ti->tiargs->dim)
- printf("ti->tiargs->dim = %d, [0] = %p\n",
- ti->tiargs->dim,
- ti->tiargs->data[0]);
+ printf("ti->tiargs->dim = %d, [0] = %p\n",
+ ti->tiargs->dim,
+ ti->tiargs->data[0]);
#endif
dedtypes->zero();
@@ -538,9 +538,9 @@ MATCH TemplateDeclaration::matchWithInstance(TemplateInstance *ti,
if (ti->tiargs->dim > parameters_dim && !variadic)
{
#if LOGM
- printf(" no match: more arguments than parameters\n");
+ printf(" no match: more arguments than parameters\n");
#endif
- return MATCHnomatch;
+ return MATCHnomatch;
}
assert(dedtypes_dim == parameters_dim);
@@ -556,65 +556,65 @@ MATCH TemplateDeclaration::matchWithInstance(TemplateInstance *ti,
// Attempt type deduction
m = MATCHexact;
for (int i = 0; i < dedtypes_dim; i++)
- { MATCH m2;
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- Declaration *sparam;
+ { MATCH m2;
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ Declaration *sparam;
- //printf("\targument [%d]\n", i);
+ //printf("\targument [%d]\n", i);
#if LOGM
- //printf("\targument [%d] is %s\n", i, oarg ? oarg->toChars() : "null");
- TemplateTypeParameter *ttp = tp->isTemplateTypeParameter();
- if (ttp)
- printf("\tparameter[%d] is %s : %s\n", i, tp->ident->toChars(), ttp->specType ? ttp->specType->toChars() : "");
+ //printf("\targument [%d] is %s\n", i, oarg ? oarg->toChars() : "null");
+ TemplateTypeParameter *ttp = tp->isTemplateTypeParameter();
+ if (ttp)
+ printf("\tparameter[%d] is %s : %s\n", i, tp->ident->toChars(), ttp->specType ? ttp->specType->toChars() : "");
#endif
#if DMDV1
- m2 = tp->matchArg(paramscope, ti->tiargs, i, parameters, dedtypes, &sparam);
+ m2 = tp->matchArg(paramscope, ti->tiargs, i, parameters, dedtypes, &sparam);
#else
- m2 = tp->matchArg(paramscope, ti->tiargs, i, parameters, dedtypes, &sparam, (flag & 2) ? 1 : 0);
+ m2 = tp->matchArg(paramscope, ti->tiargs, i, parameters, dedtypes, &sparam, (flag & 2) ? 1 : 0);
#endif
- //printf("\tm2 = %d\n", m2);
+ //printf("\tm2 = %d\n", m2);
- if (m2 == MATCHnomatch)
- {
+ if (m2 == MATCHnomatch)
+ {
#if 0
- printf("\tmatchArg() for parameter %i failed\n", i);
+ printf("\tmatchArg() for parameter %i failed\n", i);
#endif
- goto Lnomatch;
- }
+ goto Lnomatch;
+ }
- if (m2 < m)
- m = m2;
+ if (m2 < m)
+ m = m2;
- if (!flag)
- sparam->semantic(paramscope);
- if (!paramscope->insert(sparam))
- goto Lnomatch;
+ if (!flag)
+ sparam->semantic(paramscope);
+ if (!paramscope->insert(sparam))
+ goto Lnomatch;
}
if (!flag)
{
- /* Any parameter left without a type gets the type of
- * its corresponding arg
- */
- for (int i = 0; i < dedtypes_dim; i++)
- {
- if (!dedtypes->data[i])
- { assert(i < ti->tiargs->dim);
- dedtypes->data[i] = ti->tiargs->data[i];
- }
- }
+ /* Any parameter left without a type gets the type of
+ * its corresponding arg
+ */
+ for (int i = 0; i < dedtypes_dim; i++)
+ {
+ if (!dedtypes->data[i])
+ { assert(i < ti->tiargs->dim);
+ dedtypes->data[i] = ti->tiargs->data[i];
+ }
+ }
}
#if DMDV2
if (m && constraint && !(flag & 1))
- { /* Check to see if constraint is satisfied.
- */
- Expression *e = constraint->syntaxCopy();
- paramscope->flags |= SCOPEstaticif;
- e = e->semantic(paramscope);
- e = e->optimize(WANTvalue | WANTinterpret);
+ { /* Check to see if constraint is satisfied.
+ */
+ Expression *e = constraint->syntaxCopy();
+ paramscope->flags |= SCOPEstaticif;
+ e = e->semantic(paramscope);
+ e = e->optimize(WANTvalue | WANTinterpret);
if (e->isBool(TRUE))
;
else if (e->isBool(FALSE))
@@ -633,22 +633,22 @@ MATCH TemplateDeclaration::matchWithInstance(TemplateInstance *ti,
printf("instance %s\n", ti->toChars());
if (m)
{
- for (int i = 0; i < dedtypes_dim; i++)
- {
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- Object *oarg;
+ for (int i = 0; i < dedtypes_dim; i++)
+ {
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ Object *oarg;
- printf(" [%d]", i);
+ printf(" [%d]", i);
- if (i < ti->tiargs->dim)
- oarg = (Object *)ti->tiargs->data[i];
- else
- oarg = NULL;
- tp->print(oarg, (Object *)dedtypes->data[i]);
- }
+ if (i < ti->tiargs->dim)
+ oarg = (Object *)ti->tiargs->data[i];
+ else
+ oarg = NULL;
+ tp->print(oarg, (Object *)dedtypes->data[i]);
+ }
}
else
- goto Lnomatch;
+ goto Lnomatch;
#endif
#if LOGM
@@ -673,8 +673,8 @@ Lret:
/********************************************
* Determine partial specialization order of 'this' vs td2.
* Returns:
- * match this is at least as specialized as td2
- * 0 td2 is more specialized than this
+ * match this is at least as specialized as td2
+ * 0 td2 is more specialized than this
*/
MATCH TemplateDeclaration::leastAsSpecialized(TemplateDeclaration *td2)
@@ -686,10 +686,10 @@ MATCH TemplateDeclaration::leastAsSpecialized(TemplateDeclaration *td2)
* as td2.
*/
- TemplateInstance ti(0, ident); // create dummy template instance
+ TemplateInstance ti(0, ident); // create dummy template instance
Objects dedtypes;
-#define LOG_LEASTAS 0
+#define LOG_LEASTAS 0
#if LOG_LEASTAS
printf("%s.leastAsSpecialized(%s)\n", toChars(), td2->toChars());
@@ -701,13 +701,13 @@ MATCH TemplateDeclaration::leastAsSpecialized(TemplateDeclaration *td2)
ti.tiargs->setDim(parameters->dim);
for (int i = 0; i < ti.tiargs->dim; i++)
{
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- void *p = tp->dummyArg();
- if (p)
- ti.tiargs->data[i] = p;
- else
- ti.tiargs->setDim(i);
+ void *p = tp->dummyArg();
+ if (p)
+ ti.tiargs->data[i] = p;
+ else
+ ti.tiargs->setDim(i);
}
// Temporary Array to hold deduced types
@@ -718,16 +718,16 @@ MATCH TemplateDeclaration::leastAsSpecialized(TemplateDeclaration *td2)
MATCH m = td2->matchWithInstance(&ti, &dedtypes, 1);
if (m)
{
- /* A non-variadic template is more specialized than a
- * variadic one.
- */
- if (isVariadic() && !td2->isVariadic())
- goto L1;
+ /* A non-variadic template is more specialized than a
+ * variadic one.
+ */
+ if (isVariadic() && !td2->isVariadic())
+ goto L1;
#if LOG_LEASTAS
- printf(" matches %d, so is least as specialized\n", m);
+ printf(" matches %d, so is least as specialized\n", m);
#endif
- return m;
+ return m;
}
L1:
#if LOG_LEASTAS
@@ -740,37 +740,37 @@ MATCH TemplateDeclaration::leastAsSpecialized(TemplateDeclaration *td2)
/*************************************************
* Match function arguments against a specific template function.
* Input:
- * loc instantiation location
- * targsi Expression/Type initial list of template arguments
- * ethis 'this' argument if !NULL
- * fargs arguments to function
+ * loc instantiation location
+ * targsi Expression/Type initial list of template arguments
+ * ethis 'this' argument if !NULL
+ * fargs arguments to function
* Output:
- * dedargs Expression/Type deduced template arguments
+ * dedargs Expression/Type deduced template arguments
* Returns:
- * match level
+ * match level
*/
MATCH TemplateDeclaration::deduceFunctionTemplateMatch(Loc loc, Objects *targsi,
- Expression *ethis, Expressions *fargs,
- Objects *dedargs)
+ Expression *ethis, Expressions *fargs,
+ Objects *dedargs)
{
size_t i;
size_t nfparams;
size_t nfargs;
- size_t nargsi; // array size of targsi
+ size_t nargsi; // array size of targsi
int fptupindex = -1;
int tuple_dim = 0;
MATCH match = MATCHexact;
FuncDeclaration *fd = onemember->toAlias()->isFuncDeclaration();
- Parameters *fparameters; // function parameter list
- int fvarargs; // function varargs
- Objects dedtypes; // for T:T*, the dedargs is the T*, dedtypes is the T
+ Parameters *fparameters; // function parameter list
+ int fvarargs; // function varargs
+ Objects dedtypes; // for T:T*, the dedargs is the T*, dedtypes is the T
#if 0
printf("\nTemplateDeclaration::deduceFunctionTemplateMatch() %s\n", toChars());
for (i = 0; i < fargs->dim; i++)
- { Expression *e = (Expression *)fargs->data[i];
- printf("\tfarg[%d] is %s, type is %s\n", i, e->toChars(), e->type->toChars());
+ { Expression *e = (Expression *)fargs->data[i];
+ printf("\tfarg[%d] is %s, type is %s\n", i, e->toChars(), e->type->toChars());
}
printf("fd = %s\n", fd->toChars());
printf("fd->type = %p\n", fd->type);
@@ -794,67 +794,67 @@ MATCH TemplateDeclaration::deduceFunctionTemplateMatch(Loc loc, Objects *targsi,
#if 0
for (i = 0; i < dedargs->dim; i++)
{
- printf("\tdedarg[%d] = ", i);
- Object *oarg = (Object *)dedargs->data[i];
- if (oarg) printf("%s", oarg->toChars());
- printf("\n");
+ printf("\tdedarg[%d] = ", i);
+ Object *oarg = (Object *)dedargs->data[i];
+ if (oarg) printf("%s", oarg->toChars());
+ printf("\n");
}
#endif
nargsi = 0;
if (targsi)
- { // Set initial template arguments
+ { // Set initial template arguments
- nargsi = targsi->dim;
- size_t n = parameters->dim;
- if (nargsi > n)
- { if (!tp)
- goto Lnomatch;
- dedargs->setDim(nargsi);
- dedargs->zero();
- }
- else
- n = nargsi;
+ nargsi = targsi->dim;
+ size_t n = parameters->dim;
+ if (nargsi > n)
+ { if (!tp)
+ goto Lnomatch;
+ dedargs->setDim(nargsi);
+ dedargs->zero();
+ }
+ else
+ n = nargsi;
- /* Test case for nargsi instead of n:
- * string foo(T...)() { return ""; }
- * void main() { foo!(int, char)(); }
- */
- //memcpy(dedargs->data, targsi->data, n * sizeof(*dedargs->data));
- memcpy(dedargs->data, targsi->data, nargsi * sizeof(*dedargs->data));
+ /* Test case for nargsi instead of n:
+ * string foo(T...)() { return ""; }
+ * void main() { foo!(int, char)(); }
+ */
+ //memcpy(dedargs->data, targsi->data, n * sizeof(*dedargs->data));
+ memcpy(dedargs->data, targsi->data, nargsi * sizeof(*dedargs->data));
- for (size_t i = 0; i < n; i++)
- { assert(i < parameters->dim);
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- MATCH m;
- Declaration *sparam = NULL;
+ for (size_t i = 0; i < n; i++)
+ { assert(i < parameters->dim);
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ MATCH m;
+ Declaration *sparam = NULL;
- m = tp->matchArg(paramscope, dedargs, i, parameters, &dedtypes, &sparam);
- //printf("\tdeduceType m = %d\n", m);
- if (m == MATCHnomatch)
- goto Lnomatch;
- if (m < match)
- match = m;
+ m = tp->matchArg(paramscope, dedargs, i, parameters, &dedtypes, &sparam);
+ //printf("\tdeduceType m = %d\n", m);
+ if (m == MATCHnomatch)
+ goto Lnomatch;
+ if (m < match)
+ match = m;
- sparam->semantic(paramscope);
- if (!paramscope->insert(sparam))
- goto Lnomatch;
- }
+ sparam->semantic(paramscope);
+ if (!paramscope->insert(sparam))
+ goto Lnomatch;
+ }
}
#if 0
for (i = 0; i < dedargs->dim; i++)
{
- printf("\tdedarg[%d] = ", i);
- Object *oarg = (Object *)dedargs->data[i];
- if (oarg) printf("%s", oarg->toChars());
- printf("\n");
+ printf("\tdedarg[%d] = ", i);
+ Object *oarg = (Object *)dedargs->data[i];
+ if (oarg) printf("%s", oarg->toChars());
+ printf("\n");
}
#endif
fparameters = fd->getParameters(&fvarargs);
- nfparams = Parameter::dim(fparameters); // number of function parameters
- nfargs = fargs ? fargs->dim : 0; // number of function arguments
+ nfparams = Parameter::dim(fparameters); // number of function parameters
+ nfargs = fargs ? fargs->dim : 0; // number of function arguments
/* Check for match of function arguments with variadic template
* parameter, such as:
@@ -862,64 +862,64 @@ MATCH TemplateDeclaration::deduceFunctionTemplateMatch(Loc loc, Objects *targsi,
* template Foo(T, A...) { void Foo(T t, A a); }
* void main() { Foo(1,2,3); }
*/
- if (tp) // if variadic
+ if (tp) // if variadic
{
- if (nfparams == 0 && nfargs != 0) // if no function parameters
- {
- Tuple *t = new Tuple();
- //printf("t = %p\n", t);
- dedargs->data[parameters->dim - 1] = (void *)t;
- declareParameter(paramscope, tp, t);
- goto L2;
- }
- else if (nfargs < nfparams - 1)
- goto L1;
- else
- {
- /* Figure out which of the function parameters matches
- * the tuple template parameter. Do this by matching
- * type identifiers.
- * Set the index of this function parameter to fptupindex.
- */
- for (fptupindex = 0; fptupindex < nfparams; fptupindex++)
- {
- Parameter *fparam = (Parameter *)fparameters->data[fptupindex];
- if (fparam->type->ty != Tident)
- continue;
- TypeIdentifier *tid = (TypeIdentifier *)fparam->type;
- if (!tp->ident->equals(tid->ident) || tid->idents.dim)
- continue;
+ if (nfparams == 0 && nfargs != 0) // if no function parameters
+ {
+ Tuple *t = new Tuple();
+ //printf("t = %p\n", t);
+ dedargs->data[parameters->dim - 1] = (void *)t;
+ declareParameter(paramscope, tp, t);
+ goto L2;
+ }
+ else if (nfargs < nfparams - 1)
+ goto L1;
+ else
+ {
+ /* Figure out which of the function parameters matches
+ * the tuple template parameter. Do this by matching
+ * type identifiers.
+ * Set the index of this function parameter to fptupindex.
+ */
+ for (fptupindex = 0; fptupindex < nfparams; fptupindex++)
+ {
+ Parameter *fparam = (Parameter *)fparameters->data[fptupindex];
+ if (fparam->type->ty != Tident)
+ continue;
+ TypeIdentifier *tid = (TypeIdentifier *)fparam->type;
+ if (!tp->ident->equals(tid->ident) || tid->idents.dim)
+ continue;
- if (fvarargs) // variadic function doesn't
- goto Lnomatch; // go with variadic template
+ if (fvarargs) // variadic function doesn't
+ goto Lnomatch; // go with variadic template
- /* The types of the function arguments
- * now form the tuple argument.
- */
- Tuple *t = new Tuple();
- dedargs->data[parameters->dim - 1] = (void *)t;
+ /* The types of the function arguments
+ * now form the tuple argument.
+ */
+ Tuple *t = new Tuple();
+ dedargs->data[parameters->dim - 1] = (void *)t;
- tuple_dim = nfargs - (nfparams - 1);
- t->objects.setDim(tuple_dim);
- for (i = 0; i < tuple_dim; i++)
- { Expression *farg = (Expression *)fargs->data[fptupindex + i];
- t->objects.data[i] = (void *)farg->type;
- }
- declareParameter(paramscope, tp, t);
- goto L2;
- }
- fptupindex = -1;
- }
+ tuple_dim = nfargs - (nfparams - 1);
+ t->objects.setDim(tuple_dim);
+ for (i = 0; i < tuple_dim; i++)
+ { Expression *farg = (Expression *)fargs->data[fptupindex + i];
+ t->objects.data[i] = (void *)farg->type;
+ }
+ declareParameter(paramscope, tp, t);
+ goto L2;
+ }
+ fptupindex = -1;
+ }
}
L1:
if (nfparams == nfargs)
- ;
+ ;
else if (nfargs > nfparams)
{
- if (fvarargs == 0)
- goto Lnomatch; // too many args, no match
- match = MATCHconvert; // match ... with a conversion
+ if (fvarargs == 0)
+ goto Lnomatch; // too many args, no match
+ match = MATCHconvert; // match ... with a conversion
}
L2:
@@ -927,160 +927,160 @@ L2:
// Match 'ethis' to any TemplateThisParameter's
if (ethis)
{
- for (size_t i = 0; i < parameters->dim; i++)
- { TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- TemplateThisParameter *ttp = tp->isTemplateThisParameter();
- if (ttp)
- { MATCH m;
+ for (size_t i = 0; i < parameters->dim; i++)
+ { TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ TemplateThisParameter *ttp = tp->isTemplateThisParameter();
+ if (ttp)
+ { MATCH m;
- Type *t = new TypeIdentifier(0, ttp->ident);
- m = ethis->type->deduceType(paramscope, t, parameters, &dedtypes);
- if (!m)
- goto Lnomatch;
- if (m < match)
- match = m; // pick worst match
- }
- }
+ Type *t = new TypeIdentifier(0, ttp->ident);
+ m = ethis->type->deduceType(paramscope, t, parameters, &dedtypes);
+ if (!m)
+ goto Lnomatch;
+ if (m < match)
+ match = m; // pick worst match
+ }
+ }
}
#endif
// Loop through the function parameters
for (i = 0; i < nfparams; i++)
{
- /* Skip over function parameters which wound up
- * as part of a template tuple parameter.
- */
- if (i == fptupindex)
- { if (fptupindex == nfparams - 1)
- break;
- i += tuple_dim - 1;
- continue;
- }
+ /* Skip over function parameters which wound up
+ * as part of a template tuple parameter.
+ */
+ if (i == fptupindex)
+ { if (fptupindex == nfparams - 1)
+ break;
+ i += tuple_dim - 1;
+ continue;
+ }
- Parameter *fparam = Parameter::getNth(fparameters, i);
+ Parameter *fparam = Parameter::getNth(fparameters, i);
- if (i >= nfargs) // if not enough arguments
- {
- if (fparam->defaultArg)
- { /* Default arguments do not participate in template argument
- * deduction.
- */
- goto Lmatch;
- }
- }
- else
- { Expression *farg = (Expression *)fargs->data[i];
+ if (i >= nfargs) // if not enough arguments
+ {
+ if (fparam->defaultArg)
+ { /* Default arguments do not participate in template argument
+ * deduction.
+ */
+ goto Lmatch;
+ }
+ }
+ else
+ { Expression *farg = (Expression *)fargs->data[i];
#if 0
- printf("\tfarg->type = %s\n", farg->type->toChars());
- printf("\tfparam->type = %s\n", fparam->type->toChars());
+ printf("\tfarg->type = %s\n", farg->type->toChars());
+ printf("\tfparam->type = %s\n", fparam->type->toChars());
#endif
- Type *argtype = farg->type;
+ Type *argtype = farg->type;
#if DMDV2
- /* Allow string literals which are type [] to match with [dim]
- */
- if (farg->op == TOKstring)
- { StringExp *se = (StringExp *)farg;
- if (!se->committed && argtype->ty == Tarray &&
- fparam->type->toBasetype()->ty == Tsarray)
- {
- argtype = new TypeSArray(argtype->nextOf(), new IntegerExp(se->loc, se->len, Type::tindex));
- argtype = argtype->semantic(se->loc, NULL);
- argtype = argtype->invariantOf();
- }
- }
+ /* Allow string literals which are type [] to match with [dim]
+ */
+ if (farg->op == TOKstring)
+ { StringExp *se = (StringExp *)farg;
+ if (!se->committed && argtype->ty == Tarray &&
+ fparam->type->toBasetype()->ty == Tsarray)
+ {
+ argtype = new TypeSArray(argtype->nextOf(), new IntegerExp(se->loc, se->len, Type::tindex));
+ argtype = argtype->semantic(se->loc, NULL);
+ argtype = argtype->invariantOf();
+ }
+ }
#endif
- MATCH m;
- m = argtype->deduceType(paramscope, fparam->type, parameters, &dedtypes);
- //printf("\tdeduceType m = %d\n", m);
+ MATCH m;
+ m = argtype->deduceType(paramscope, fparam->type, parameters, &dedtypes);
+ //printf("\tdeduceType m = %d\n", m);
- /* If no match, see if there's a conversion to a delegate
- */
- if (!m && fparam->type->toBasetype()->ty == Tdelegate)
- {
- TypeDelegate *td = (TypeDelegate *)fparam->type->toBasetype();
- TypeFunction *tf = (TypeFunction *)td->next;
+ /* If no match, see if there's a conversion to a delegate
+ */
+ if (!m && fparam->type->toBasetype()->ty == Tdelegate)
+ {
+ TypeDelegate *td = (TypeDelegate *)fparam->type->toBasetype();
+ TypeFunction *tf = (TypeFunction *)td->next;
- if (!tf->varargs && Parameter::dim(tf->parameters) == 0)
- {
- m = farg->type->deduceType(paramscope, tf->next, parameters, &dedtypes);
- if (!m && tf->next->toBasetype()->ty == Tvoid)
- m = MATCHconvert;
- }
- //printf("\tm2 = %d\n", m);
- }
+ if (!tf->varargs && Parameter::dim(tf->parameters) == 0)
+ {
+ m = farg->type->deduceType(paramscope, tf->next, parameters, &dedtypes);
+ if (!m && tf->next->toBasetype()->ty == Tvoid)
+ m = MATCHconvert;
+ }
+ //printf("\tm2 = %d\n", m);
+ }
- if (m)
- { if (m < match)
- match = m; // pick worst match
- continue;
- }
- }
+ if (m)
+ { if (m < match)
+ match = m; // pick worst match
+ continue;
+ }
+ }
- /* The following code for variadic arguments closely
- * matches TypeFunction::callMatch()
- */
- if (!(fvarargs == 2 && i + 1 == nfparams))
- goto Lnomatch;
+ /* The following code for variadic arguments closely
+ * matches TypeFunction::callMatch()
+ */
+ if (!(fvarargs == 2 && i + 1 == nfparams))
+ goto Lnomatch;
- /* Check for match with function parameter T...
- */
- Type *tb = fparam->type->toBasetype();
- switch (tb->ty)
- {
- // Perhaps we can do better with this, see TypeFunction::callMatch()
- case Tsarray:
- { TypeSArray *tsa = (TypeSArray *)tb;
- dinteger_t sz = tsa->dim->toInteger();
- if (sz != nfargs - i)
- goto Lnomatch;
- }
- case Tarray:
- { TypeArray *ta = (TypeArray *)tb;
- for (; i < nfargs; i++)
- {
- Expression *arg = (Expression *)fargs->data[i];
- assert(arg);
- MATCH m;
- /* If lazy array of delegates,
- * convert arg(s) to delegate(s)
- */
- Type *tret = fparam->isLazyArray();
- if (tret)
- {
- if (ta->next->equals(arg->type))
- { m = MATCHexact;
- }
- else
- {
- m = arg->implicitConvTo(tret);
- if (m == MATCHnomatch)
- {
- if (tret->toBasetype()->ty == Tvoid)
- m = MATCHconvert;
- }
- }
- }
- else
- {
- m = arg->type->deduceType(paramscope, ta->next, parameters, &dedtypes);
- //m = arg->implicitConvTo(ta->next);
- }
- if (m == MATCHnomatch)
- goto Lnomatch;
- if (m < match)
- match = m;
- }
- goto Lmatch;
- }
- case Tclass:
- case Tident:
- goto Lmatch;
+ /* Check for match with function parameter T...
+ */
+ Type *tb = fparam->type->toBasetype();
+ switch (tb->ty)
+ {
+ // Perhaps we can do better with this, see TypeFunction::callMatch()
+ case Tsarray:
+ { TypeSArray *tsa = (TypeSArray *)tb;
+ dinteger_t sz = tsa->dim->toInteger();
+ if (sz != nfargs - i)
+ goto Lnomatch;
+ }
+ case Tarray:
+ { TypeArray *ta = (TypeArray *)tb;
+ for (; i < nfargs; i++)
+ {
+ Expression *arg = (Expression *)fargs->data[i];
+ assert(arg);
+ MATCH m;
+ /* If lazy array of delegates,
+ * convert arg(s) to delegate(s)
+ */
+ Type *tret = fparam->isLazyArray();
+ if (tret)
+ {
+ if (ta->next->equals(arg->type))
+ { m = MATCHexact;
+ }
+ else
+ {
+ m = arg->implicitConvTo(tret);
+ if (m == MATCHnomatch)
+ {
+ if (tret->toBasetype()->ty == Tvoid)
+ m = MATCHconvert;
+ }
+ }
+ }
+ else
+ {
+ m = arg->type->deduceType(paramscope, ta->next, parameters, &dedtypes);
+ //m = arg->implicitConvTo(ta->next);
+ }
+ if (m == MATCHnomatch)
+ goto Lnomatch;
+ if (m < match)
+ match = m;
+ }
+ goto Lmatch;
+ }
+ case Tclass:
+ case Tident:
+ goto Lmatch;
- default:
- goto Lnomatch;
- }
+ default:
+ goto Lnomatch;
+ }
}
Lmatch:
@@ -1089,55 +1089,55 @@ Lmatch:
*/
for (i = nargsi; i < dedargs->dim; i++)
{
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- //printf("tp[%d] = %s\n", i, tp->ident->toChars());
- /* For T:T*, the dedargs is the T*, dedtypes is the T
- * But for function templates, we really need them to match
- */
- Object *oarg = (Object *)dedargs->data[i];
- Object *oded = (Object *)dedtypes.data[i];
- //printf("1dedargs[%d] = %p, dedtypes[%d] = %p\n", i, oarg, i, oded);
- //if (oarg) printf("oarg: %s\n", oarg->toChars());
- //if (oded) printf("oded: %s\n", oded->toChars());
- if (!oarg)
- {
- if (oded)
- {
- if (tp->specialization())
- { /* The specialization can work as long as afterwards
- * the oded == oarg
- */
- Declaration *sparam;
- dedargs->data[i] = (void *)oded;
- MATCH m2 = tp->matchArg(paramscope, dedargs, i, parameters, &dedtypes, &sparam, 0);
- //printf("m2 = %d\n", m2);
- if (!m2)
- goto Lnomatch;
- if (m2 < match)
- match = m2; // pick worst match
- if (dedtypes.data[i] != oded)
- error("specialization not allowed for deduced parameter %s", tp->ident->toChars());
- }
- }
- else
- { oded = tp->defaultArg(loc, paramscope);
- if (!oded)
- goto Lnomatch;
- }
- declareParameter(paramscope, tp, oded);
- dedargs->data[i] = (void *)oded;
- }
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ //printf("tp[%d] = %s\n", i, tp->ident->toChars());
+ /* For T:T*, the dedargs is the T*, dedtypes is the T
+ * But for function templates, we really need them to match
+ */
+ Object *oarg = (Object *)dedargs->data[i];
+ Object *oded = (Object *)dedtypes.data[i];
+ //printf("1dedargs[%d] = %p, dedtypes[%d] = %p\n", i, oarg, i, oded);
+ //if (oarg) printf("oarg: %s\n", oarg->toChars());
+ //if (oded) printf("oded: %s\n", oded->toChars());
+ if (!oarg)
+ {
+ if (oded)
+ {
+ if (tp->specialization())
+ { /* The specialization can work as long as afterwards
+ * the oded == oarg
+ */
+ Declaration *sparam;
+ dedargs->data[i] = (void *)oded;
+ MATCH m2 = tp->matchArg(paramscope, dedargs, i, parameters, &dedtypes, &sparam, 0);
+ //printf("m2 = %d\n", m2);
+ if (!m2)
+ goto Lnomatch;
+ if (m2 < match)
+ match = m2; // pick worst match
+ if (dedtypes.data[i] != oded)
+ error("specialization not allowed for deduced parameter %s", tp->ident->toChars());
+ }
+ }
+ else
+ { oded = tp->defaultArg(loc, paramscope);
+ if (!oded)
+ goto Lnomatch;
+ }
+ declareParameter(paramscope, tp, oded);
+ dedargs->data[i] = (void *)oded;
+ }
}
#if DMDV2
if (constraint)
- { /* Check to see if constraint is satisfied.
- */
- makeParamNamesVisibleInConstraint(paramscope);
- Expression *e = constraint->syntaxCopy();
- paramscope->flags |= SCOPEstaticif;
- e = e->semantic(paramscope);
- e = e->optimize(WANTvalue | WANTinterpret);
+ { /* Check to see if constraint is satisfied.
+ */
+ makeParamNamesVisibleInConstraint(paramscope);
+ Expression *e = constraint->syntaxCopy();
+ paramscope->flags |= SCOPEstaticif;
+ e = e->semantic(paramscope);
+ e = e->optimize(WANTvalue | WANTinterpret);
if (e->isBool(TRUE))
;
else if (e->isBool(FALSE))
@@ -1151,8 +1151,8 @@ Lmatch:
#if 0
for (i = 0; i < dedargs->dim; i++)
- { Type *t = (Type *)dedargs->data[i];
- printf("\tdedargs[%d] = %d, %s\n", i, t->dyncast(), t->toChars());
+ { Type *t = (Type *)dedargs->data[i];
+ printf("\tdedargs[%d] = %d, %s\n", i, t->dyncast(), t->toChars());
}
#endif
@@ -1186,52 +1186,52 @@ void TemplateDeclaration::declareParameter(Scope *sc, TemplateParameter *tp, Obj
s = sc->search(loc, tp->ident, &scopesym);
if (s && scopesym == sc->scopesym)
{
- TupleDeclaration *td = s->isTupleDeclaration();
- if (va && td)
- { Tuple tup;
- tup.objects = *td->objects;
- if (match(va, &tup, this, sc))
- {
- return;
- }
- }
+ TupleDeclaration *td = s->isTupleDeclaration();
+ if (va && td)
+ { Tuple tup;
+ tup.objects = *td->objects;
+ if (match(va, &tup, this, sc))
+ {
+ return;
+ }
+ }
}
if (targ)
{
- //printf("type %s\n", targ->toChars());
- s = new AliasDeclaration(0, tp->ident, targ);
+ //printf("type %s\n", targ->toChars());
+ s = new AliasDeclaration(0, tp->ident, targ);
}
else if (sa)
{
- //printf("Alias %s %s;\n", sa->ident->toChars(), tp->ident->toChars());
- s = new AliasDeclaration(0, tp->ident, sa);
+ //printf("Alias %s %s;\n", sa->ident->toChars(), tp->ident->toChars());
+ s = new AliasDeclaration(0, tp->ident, sa);
}
else if (ea)
{
- // tdtypes.data[i] always matches ea here
- Initializer *init = new ExpInitializer(loc, ea);
- TemplateValueParameter *tvp = tp->isTemplateValueParameter();
- assert(tvp);
+ // tdtypes.data[i] always matches ea here
+ Initializer *init = new ExpInitializer(loc, ea);
+ TemplateValueParameter *tvp = tp->isTemplateValueParameter();
+ assert(tvp);
- VarDeclaration *v = new VarDeclaration(loc, tvp->valType, tp->ident, init);
- v->storage_class = STCconst;
- s = v;
+ VarDeclaration *v = new VarDeclaration(loc, tvp->valType, tp->ident, init);
+ v->storage_class = STCconst;
+ s = v;
}
else if (va)
{
- //printf("\ttuple\n");
- s = new TupleDeclaration(loc, tp->ident, &va->objects);
+ //printf("\ttuple\n");
+ s = new TupleDeclaration(loc, tp->ident, &va->objects);
}
else
{
#ifdef DEBUG
- o->print();
+ o->print();
#endif
- assert(0);
+ assert(0);
}
if (!sc->insert(s))
- error("declaration %s is already defined", tp->ident->toChars());
+ error("declaration %s is already defined", tp->ident->toChars());
s->semantic(sc);
}
@@ -1244,7 +1244,7 @@ TemplateTupleParameter *isVariadic(TemplateParameters *parameters)
TemplateTupleParameter *tp = NULL;
if (dim)
- tp = ((TemplateParameter *)parameters->data[dim - 1])->isTemplateTupleParameter();
+ tp = ((TemplateParameter *)parameters->data[dim - 1])->isTemplateTupleParameter();
return tp;
}
@@ -1267,16 +1267,16 @@ int TemplateDeclaration::isOverloadable()
* to expand, and return that function.
* If no match, give error message and return NULL.
* Input:
- * sc instantiation scope
- * loc instantiation location
- * targsi initial list of template arguments
- * ethis if !NULL, the 'this' pointer argument
- * fargs arguments to function
- * flags 1: do not issue error message on no match, just return NULL
+ * sc instantiation scope
+ * loc instantiation location
+ * targsi initial list of template arguments
+ * ethis if !NULL, the 'this' pointer argument
+ * fargs arguments to function
+ * flags 1: do not issue error message on no match, just return NULL
*/
FuncDeclaration *TemplateDeclaration::deduceFunctionTemplate(Scope *sc, Loc loc,
- Objects *targsi, Expression *ethis, Expressions *fargs, int flags)
+ Objects *targsi, Expression *ethis, Expressions *fargs, int flags)
{
MATCH m_best = MATCHnomatch;
TemplateDeclaration *td_ambig = NULL;
@@ -1289,85 +1289,85 @@ FuncDeclaration *TemplateDeclaration::deduceFunctionTemplate(Scope *sc, Loc loc,
printf("TemplateDeclaration::deduceFunctionTemplate() %s\n", toChars());
printf(" targsi:\n");
if (targsi)
- { for (int i = 0; i < targsi->dim; i++)
- { Object *arg = (Object *)targsi->data[i];
- printf("\t%s\n", arg->toChars());
- }
+ { for (int i = 0; i < targsi->dim; i++)
+ { Object *arg = (Object *)targsi->data[i];
+ printf("\t%s\n", arg->toChars());
+ }
}
printf(" fargs:\n");
for (int i = 0; i < fargs->dim; i++)
- { Expression *arg = (Expression *)fargs->data[i];
- printf("\t%s %s\n", arg->type->toChars(), arg->toChars());
- //printf("\tty = %d\n", arg->type->ty);
+ { Expression *arg = (Expression *)fargs->data[i];
+ printf("\t%s %s\n", arg->type->toChars(), arg->toChars());
+ //printf("\tty = %d\n", arg->type->ty);
}
#endif
for (TemplateDeclaration *td = this; td; td = td->overnext)
{
- if (!td->semanticRun)
- {
- error("forward reference to template %s", td->toChars());
- goto Lerror;
- }
- if (!td->onemember || !td->onemember->toAlias()->isFuncDeclaration())
- {
- error("is not a function template");
- goto Lerror;
- }
+ if (!td->semanticRun)
+ {
+ error("forward reference to template %s", td->toChars());
+ goto Lerror;
+ }
+ if (!td->onemember || !td->onemember->toAlias()->isFuncDeclaration())
+ {
+ error("is not a function template");
+ goto Lerror;
+ }
- MATCH m;
- Objects dedargs;
+ MATCH m;
+ Objects dedargs;
- m = td->deduceFunctionTemplateMatch(loc, targsi, ethis, fargs, &dedargs);
- //printf("deduceFunctionTemplateMatch = %d\n", m);
- if (!m) // if no match
- continue;
+ m = td->deduceFunctionTemplateMatch(loc, targsi, ethis, fargs, &dedargs);
+ //printf("deduceFunctionTemplateMatch = %d\n", m);
+ if (!m) // if no match
+ continue;
- if (m < m_best)
- goto Ltd_best;
- if (m > m_best)
- goto Ltd;
+ if (m < m_best)
+ goto Ltd_best;
+ if (m > m_best)
+ goto Ltd;
- {
- // Disambiguate by picking the most specialized TemplateDeclaration
- MATCH c1 = td->leastAsSpecialized(td_best);
- MATCH c2 = td_best->leastAsSpecialized(td);
- //printf("c1 = %d, c2 = %d\n", c1, c2);
+ {
+ // Disambiguate by picking the most specialized TemplateDeclaration
+ MATCH c1 = td->leastAsSpecialized(td_best);
+ MATCH c2 = td_best->leastAsSpecialized(td);
+ //printf("c1 = %d, c2 = %d\n", c1, c2);
- if (c1 > c2)
- goto Ltd;
- else if (c1 < c2)
- goto Ltd_best;
- else
- goto Lambig;
- }
+ if (c1 > c2)
+ goto Ltd;
+ else if (c1 < c2)
+ goto Ltd_best;
+ else
+ goto Lambig;
+ }
- Lambig: // td_best and td are ambiguous
- td_ambig = td;
- continue;
+ Lambig: // td_best and td are ambiguous
+ td_ambig = td;
+ continue;
- Ltd_best: // td_best is the best match so far
- td_ambig = NULL;
- continue;
+ Ltd_best: // td_best is the best match so far
+ td_ambig = NULL;
+ continue;
- Ltd: // td is the new best match
- td_ambig = NULL;
- assert((size_t)td->scope > 0x10000);
- td_best = td;
- m_best = m;
- tdargs->setDim(dedargs.dim);
- memcpy(tdargs->data, dedargs.data, tdargs->dim * sizeof(void *));
- continue;
+ Ltd: // td is the new best match
+ td_ambig = NULL;
+ assert((size_t)td->scope > 0x10000);
+ td_best = td;
+ m_best = m;
+ tdargs->setDim(dedargs.dim);
+ memcpy(tdargs->data, dedargs.data, tdargs->dim * sizeof(void *));
+ continue;
}
if (!td_best)
{
- error(loc, "does not match any function template declaration");
- goto Lerror;
+ error(loc, "does not match any function template declaration");
+ goto Lerror;
}
if (td_ambig)
{
- error(loc, "matches more than one function template declaration:\n %s\nand:\n %s",
- td_best->toChars(), td_ambig->toChars());
+ error(loc, "matches more than one function template declaration:\n %s\nand:\n %s",
+ td_best->toChars(), td_ambig->toChars());
}
/* The best match is td_best with arguments tdargs.
@@ -1378,7 +1378,7 @@ FuncDeclaration *TemplateDeclaration::deduceFunctionTemplate(Scope *sc, Loc loc,
ti->semantic(sc);
fd = ti->toAlias()->isFuncDeclaration();
if (!fd)
- goto Lerror;
+ goto Lerror;
return fd;
Lerror:
@@ -1386,24 +1386,24 @@ FuncDeclaration *TemplateDeclaration::deduceFunctionTemplate(Scope *sc, Loc loc,
if (!(flags & 1))
#endif
{
- HdrGenState hgs;
+ HdrGenState hgs;
- OutBuffer bufa;
- Objects *args = targsi;
- if (args)
- { for (int i = 0; i < args->dim; i++)
- {
- if (i)
- bufa.writeByte(',');
- Object *oarg = (Object *)args->data[i];
- ObjectToCBuffer(&bufa, &hgs, oarg);
- }
- }
+ OutBuffer bufa;
+ Objects *args = targsi;
+ if (args)
+ { for (int i = 0; i < args->dim; i++)
+ {
+ if (i)
+ bufa.writeByte(',');
+ Object *oarg = (Object *)args->data[i];
+ ObjectToCBuffer(&bufa, &hgs, oarg);
+ }
+ }
- OutBuffer buf;
- argExpTypesToCBuffer(&buf, fargs, &hgs);
- error(loc, "cannot deduce template function from argument types !(%s)(%s)",
- bufa.toChars(), buf.toChars());
+ OutBuffer buf;
+ argExpTypesToCBuffer(&buf, fargs, &hgs);
+ error(loc, "cannot deduce template function from argument types !(%s)(%s)",
+ bufa.toChars(), buf.toChars());
}
return NULL;
}
@@ -1412,7 +1412,7 @@ void TemplateDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
#if 0 // Should handle template functions
if (onemember && onemember->isFuncDeclaration())
- buf->writestring("foo ");
+ buf->writestring("foo ");
#endif
buf->writestring(kind());
buf->writeByte(' ');
@@ -1420,36 +1420,36 @@ void TemplateDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writeByte('(');
for (int i = 0; i < parameters->dim; i++)
{
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- if (hgs->ddoc)
- tp = (TemplateParameter *)origParameters->data[i];
- if (i)
- buf->writeByte(',');
- tp->toCBuffer(buf, hgs);
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ if (hgs->ddoc)
+ tp = (TemplateParameter *)origParameters->data[i];
+ if (i)
+ buf->writeByte(',');
+ tp->toCBuffer(buf, hgs);
}
buf->writeByte(')');
#if DMDV2
if (constraint)
- { buf->writestring(" if (");
- constraint->toCBuffer(buf, hgs);
- buf->writeByte(')');
+ { buf->writestring(" if (");
+ constraint->toCBuffer(buf, hgs);
+ buf->writeByte(')');
}
#endif
if (hgs->hdrgen)
{
- hgs->tpltMember++;
- buf->writenl();
- buf->writebyte('{');
- buf->writenl();
- for (int i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->toCBuffer(buf, hgs);
- }
- buf->writebyte('}');
- buf->writenl();
- hgs->tpltMember--;
+ hgs->tpltMember++;
+ buf->writenl();
+ buf->writebyte('{');
+ buf->writenl();
+ for (int i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->toCBuffer(buf, hgs);
+ }
+ buf->writebyte('}');
+ buf->writenl();
+ hgs->tpltMember--;
}
}
@@ -1463,17 +1463,17 @@ char *TemplateDeclaration::toChars()
buf.writeByte('(');
for (int i = 0; i < parameters->dim; i++)
{
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- if (i)
- buf.writeByte(',');
- tp->toCBuffer(&buf, &hgs);
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ if (i)
+ buf.writeByte(',');
+ tp->toCBuffer(&buf, &hgs);
}
buf.writeByte(')');
#if DMDV2
if (constraint)
- { buf.writestring(" if (");
- constraint->toCBuffer(&buf, &hgs);
- buf.writeByte(')');
+ { buf.writestring(" if (");
+ constraint->toCBuffer(&buf, &hgs);
+ buf.writeByte(')');
}
#endif
buf.writeByte(0);
@@ -1492,8 +1492,8 @@ int templateIdentifierLookup(Identifier *id, TemplateParameters *parameters)
for (size_t i = 0; i < parameters->dim; i++)
{ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- if (tp->ident->equals(id))
- return i;
+ if (tp->ident->equals(id))
+ return i;
}
return -1;
}
@@ -1505,7 +1505,7 @@ int templateParameterLookup(Type *tparam, TemplateParameters *parameters)
//printf("\ttident = '%s'\n", tident->toChars());
if (tident->idents.dim == 0)
{
- return templateIdentifierLookup(tident->ident, parameters);
+ return templateIdentifierLookup(tident->ident, parameters);
}
return -1;
}
@@ -1515,18 +1515,18 @@ int templateParameterLookup(Type *tparam, TemplateParameters *parameters)
* it is matched against the template declaration parameter specialization
* 'tparam' to determine the type to be used for the parameter.
* Example:
- * template Foo(T:T*) // template declaration
- * Foo!(int*) // template instantiation
+ * template Foo(T:T*) // template declaration
+ * Foo!(int*) // template instantiation
* Input:
- * this = int*
- * tparam = T
- * parameters = [ T:T* ] // Array of TemplateParameter's
+ * this = int*
+ * tparam = T
+ * parameters = [ T:T* ] // Array of TemplateParameter's
* Output:
- * dedtypes = [ int ] // Array of Expression/Type's
+ * dedtypes = [ int ] // Array of Expression/Type's
*/
MATCH Type::deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters,
- Objects *dedtypes)
+ Objects *dedtypes)
{
#if 0
printf("Type::deduceType()\n");
@@ -1534,69 +1534,69 @@ MATCH Type::deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters,
printf("\ttparam = %d, ", tparam->ty); tparam->print();
#endif
if (!tparam)
- goto Lnomatch;
+ goto Lnomatch;
if (this == tparam)
- goto Lexact;
+ goto Lexact;
if (tparam->ty == Tident)
{
- // Determine which parameter tparam is
- int i = templateParameterLookup(tparam, parameters);
- if (i == -1)
- {
- if (!sc)
- goto Lnomatch;
+ // Determine which parameter tparam is
+ int i = templateParameterLookup(tparam, parameters);
+ if (i == -1)
+ {
+ if (!sc)
+ goto Lnomatch;
- /* Need a loc to go with the semantic routine.
- */
- Loc loc;
- if (parameters->dim)
- {
- TemplateParameter *tp = (TemplateParameter *)parameters->data[0];
- loc = tp->loc;
- }
+ /* Need a loc to go with the semantic routine.
+ */
+ Loc loc;
+ if (parameters->dim)
+ {
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[0];
+ loc = tp->loc;
+ }
- /* BUG: what if tparam is a template instance, that
- * has as an argument another Tident?
- */
- tparam = tparam->semantic(loc, sc);
- assert(tparam->ty != Tident);
- return deduceType(sc, tparam, parameters, dedtypes);
- }
+ /* BUG: what if tparam is a template instance, that
+ * has as an argument another Tident?
+ */
+ tparam = tparam->semantic(loc, sc);
+ assert(tparam->ty != Tident);
+ return deduceType(sc, tparam, parameters, dedtypes);
+ }
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- // Found the corresponding parameter tp
- if (!tp->isTemplateTypeParameter())
- goto Lnomatch;
- Type *at = (Type *)dedtypes->data[i];
- if (!at)
- {
- dedtypes->data[i] = (void *)this;
- goto Lexact;
- }
- if (equals(at))
- goto Lexact;
- else if (ty == Tclass && at->ty == Tclass)
- {
- return (MATCH) implicitConvTo(at);
- }
- else if (ty == Tsarray && at->ty == Tarray &&
- nextOf()->equals(at->nextOf()))
- {
- goto Lexact;
- }
- else
- goto Lnomatch;
+ // Found the corresponding parameter tp
+ if (!tp->isTemplateTypeParameter())
+ goto Lnomatch;
+ Type *at = (Type *)dedtypes->data[i];
+ if (!at)
+ {
+ dedtypes->data[i] = (void *)this;
+ goto Lexact;
+ }
+ if (equals(at))
+ goto Lexact;
+ else if (ty == Tclass && at->ty == Tclass)
+ {
+ return (MATCH) implicitConvTo(at);
+ }
+ else if (ty == Tsarray && at->ty == Tarray &&
+ nextOf()->equals(at->nextOf()))
+ {
+ goto Lexact;
+ }
+ else
+ goto Lnomatch;
}
if (ty != tparam->ty)
- return implicitConvTo(tparam);
-// goto Lnomatch;
+ return implicitConvTo(tparam);
+// goto Lnomatch;
if (nextOf())
- return nextOf()->deduceType(sc, tparam->nextOf(), parameters, dedtypes);
+ return nextOf()->deduceType(sc, tparam->nextOf(), parameters, dedtypes);
Lexact:
return MATCHexact;
@@ -1612,7 +1612,7 @@ Lconst:
#if DMDV2
MATCH TypeDArray::deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters,
- Objects *dedtypes)
+ Objects *dedtypes)
{
#if 0
printf("TypeDArray::deduceType()\n");
@@ -1627,7 +1627,7 @@ MATCH TypeDArray::deduceType(Scope *sc, Type *tparam, TemplateParameters *parame
#endif
MATCH TypeSArray::deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters,
- Objects *dedtypes)
+ Objects *dedtypes)
{
#if 0
printf("TypeSArray::deduceType()\n");
@@ -1638,78 +1638,78 @@ MATCH TypeSArray::deduceType(Scope *sc, Type *tparam, TemplateParameters *parame
// Extra check that array dimensions must match
if (tparam)
{
- if (tparam->ty == Tsarray)
- {
- TypeSArray *tp = (TypeSArray *)tparam;
+ if (tparam->ty == Tsarray)
+ {
+ TypeSArray *tp = (TypeSArray *)tparam;
- if (tp->dim->op == TOKvar &&
- ((VarExp *)tp->dim)->var->storage_class & STCtemplateparameter)
- { int i = templateIdentifierLookup(((VarExp *)tp->dim)->var->ident, parameters);
- // This code matches code in TypeInstance::deduceType()
- if (i == -1)
- goto Lnomatch;
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- TemplateValueParameter *tvp = tp->isTemplateValueParameter();
- if (!tvp)
- goto Lnomatch;
- Expression *e = (Expression *)dedtypes->data[i];
- if (e)
- {
- if (!dim->equals(e))
- goto Lnomatch;
- }
- else
- { Type *vt = tvp->valType->semantic(0, sc);
- MATCH m = (MATCH)dim->implicitConvTo(vt);
- if (!m)
- goto Lnomatch;
- dedtypes->data[i] = dim;
- }
- }
- else if (dim->toInteger() != tp->dim->toInteger())
- return MATCHnomatch;
- }
- else if (tparam->ty == Taarray)
- {
- TypeAArray *tp = (TypeAArray *)tparam;
- if (tp->index->ty == Tident)
- { TypeIdentifier *tident = (TypeIdentifier *)tp->index;
+ if (tp->dim->op == TOKvar &&
+ ((VarExp *)tp->dim)->var->storage_class & STCtemplateparameter)
+ { int i = templateIdentifierLookup(((VarExp *)tp->dim)->var->ident, parameters);
+ // This code matches code in TypeInstance::deduceType()
+ if (i == -1)
+ goto Lnomatch;
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ TemplateValueParameter *tvp = tp->isTemplateValueParameter();
+ if (!tvp)
+ goto Lnomatch;
+ Expression *e = (Expression *)dedtypes->data[i];
+ if (e)
+ {
+ if (!dim->equals(e))
+ goto Lnomatch;
+ }
+ else
+ { Type *vt = tvp->valType->semantic(0, sc);
+ MATCH m = (MATCH)dim->implicitConvTo(vt);
+ if (!m)
+ goto Lnomatch;
+ dedtypes->data[i] = dim;
+ }
+ }
+ else if (dim->toInteger() != tp->dim->toInteger())
+ return MATCHnomatch;
+ }
+ else if (tparam->ty == Taarray)
+ {
+ TypeAArray *tp = (TypeAArray *)tparam;
+ if (tp->index->ty == Tident)
+ { TypeIdentifier *tident = (TypeIdentifier *)tp->index;
- if (tident->idents.dim == 0)
- { Identifier *id = tident->ident;
+ if (tident->idents.dim == 0)
+ { Identifier *id = tident->ident;
- for (size_t i = 0; i < parameters->dim; i++)
- {
- TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
+ for (size_t i = 0; i < parameters->dim; i++)
+ {
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[i];
- if (tp->ident->equals(id))
- { // Found the corresponding template parameter
- TemplateValueParameter *tvp = tp->isTemplateValueParameter();
- if (!tvp || !tvp->valType->isintegral())
- goto Lnomatch;
+ if (tp->ident->equals(id))
+ { // Found the corresponding template parameter
+ TemplateValueParameter *tvp = tp->isTemplateValueParameter();
+ if (!tvp || !tvp->valType->isintegral())
+ goto Lnomatch;
- if (dedtypes->data[i])
- {
- if (!dim->equals((Object *)dedtypes->data[i]))
- goto Lnomatch;
- }
- else
- { dedtypes->data[i] = (void *)dim;
- }
- return next->deduceType(sc, tparam->nextOf(), parameters, dedtypes);
- }
- }
- }
- }
- }
- else if (tparam->ty == Tarray)
- { MATCH m;
+ if (dedtypes->data[i])
+ {
+ if (!dim->equals((Object *)dedtypes->data[i]))
+ goto Lnomatch;
+ }
+ else
+ { dedtypes->data[i] = (void *)dim;
+ }
+ return next->deduceType(sc, tparam->nextOf(), parameters, dedtypes);
+ }
+ }
+ }
+ }
+ }
+ else if (tparam->ty == Tarray)
+ { MATCH m;
- m = next->deduceType(sc, tparam->nextOf(), parameters, dedtypes);
- if (m == MATCHexact)
- m = MATCHconvert;
- return m;
- }
+ m = next->deduceType(sc, tparam->nextOf(), parameters, dedtypes);
+ if (m == MATCHexact)
+ m = MATCHconvert;
+ return m;
+ }
}
return Type::deduceType(sc, tparam, parameters, dedtypes);
@@ -1728,11 +1728,11 @@ MATCH TypeAArray::deduceType(Scope *sc, Type *tparam, TemplateParameters *parame
// Extra check that index type must match
if (tparam && tparam->ty == Taarray)
{
- TypeAArray *tp = (TypeAArray *)tparam;
- if (!index->deduceType(sc, tp->index, parameters, dedtypes))
- {
- return MATCHnomatch;
- }
+ TypeAArray *tp = (TypeAArray *)tparam;
+ if (!index->deduceType(sc, tp->index, parameters, dedtypes))
+ {
+ return MATCHnomatch;
+ }
}
return Type::deduceType(sc, tparam, parameters, dedtypes);
}
@@ -1746,85 +1746,85 @@ MATCH TypeFunction::deduceType(Scope *sc, Type *tparam, TemplateParameters *para
// Extra check that function characteristics must match
if (tparam && tparam->ty == Tfunction)
{
- TypeFunction *tp = (TypeFunction *)tparam;
- if (varargs != tp->varargs ||
- linkage != tp->linkage)
- return MATCHnomatch;
+ TypeFunction *tp = (TypeFunction *)tparam;
+ if (varargs != tp->varargs ||
+ linkage != tp->linkage)
+ return MATCHnomatch;
- size_t nfargs = Parameter::dim(this->parameters);
- size_t nfparams = Parameter::dim(tp->parameters);
+ size_t nfargs = Parameter::dim(this->parameters);
+ size_t nfparams = Parameter::dim(tp->parameters);
- /* See if tuple match
- */
- if (nfparams > 0 && nfargs >= nfparams - 1)
- {
- /* See if 'A' of the template parameter matches 'A'
- * of the type of the last function parameter.
- */
- Parameter *fparam = Parameter::getNth(tp->parameters, nfparams - 1);
- if (fparam->type->ty != Tident)
- goto L1;
- TypeIdentifier *tid = (TypeIdentifier *)fparam->type;
- if (tid->idents.dim)
- goto L1;
+ /* See if tuple match
+ */
+ if (nfparams > 0 && nfargs >= nfparams - 1)
+ {
+ /* See if 'A' of the template parameter matches 'A'
+ * of the type of the last function parameter.
+ */
+ Parameter *fparam = Parameter::getNth(tp->parameters, nfparams - 1);
+ if (fparam->type->ty != Tident)
+ goto L1;
+ TypeIdentifier *tid = (TypeIdentifier *)fparam->type;
+ if (tid->idents.dim)
+ goto L1;
- /* Look through parameters to find tuple matching tid->ident
- */
- size_t tupi = 0;
- for (; 1; tupi++)
- { if (tupi == parameters->dim)
- goto L1;
- TemplateParameter *t = (TemplateParameter *)parameters->data[tupi];
- TemplateTupleParameter *tup = t->isTemplateTupleParameter();
- if (tup && tup->ident->equals(tid->ident))
- break;
- }
+ /* Look through parameters to find tuple matching tid->ident
+ */
+ size_t tupi = 0;
+ for (; 1; tupi++)
+ { if (tupi == parameters->dim)
+ goto L1;
+ TemplateParameter *t = (TemplateParameter *)parameters->data[tupi];
+ TemplateTupleParameter *tup = t->isTemplateTupleParameter();
+ if (tup && tup->ident->equals(tid->ident))
+ break;
+ }
- /* The types of the function arguments [nfparams - 1 .. nfargs]
- * now form the tuple argument.
- */
- int tuple_dim = nfargs - (nfparams - 1);
+ /* The types of the function arguments [nfparams - 1 .. nfargs]
+ * now form the tuple argument.
+ */
+ int tuple_dim = nfargs - (nfparams - 1);
- /* See if existing tuple, and whether it matches or not
- */
- Object *o = (Object *)dedtypes->data[tupi];
- if (o)
- { // Existing deduced argument must be a tuple, and must match
- Tuple *t = isTuple(o);
- if (!t || t->objects.dim != tuple_dim)
- return MATCHnomatch;
- for (size_t i = 0; i < tuple_dim; i++)
- { Parameter *arg = Parameter::getNth(this->parameters, nfparams - 1 + i);
- if (!arg->type->equals((Object *)t->objects.data[i]))
- return MATCHnomatch;
- }
- }
- else
- { // Create new tuple
- Tuple *t = new Tuple();
- t->objects.setDim(tuple_dim);
- for (size_t i = 0; i < tuple_dim; i++)
- { Parameter *arg = Parameter::getNth(this->parameters, nfparams - 1 + i);
- t->objects.data[i] = (void *)arg->type;
- }
- dedtypes->data[tupi] = (void *)t;
- }
- nfparams--; // don't consider the last parameter for type deduction
- goto L2;
- }
+ /* See if existing tuple, and whether it matches or not
+ */
+ Object *o = (Object *)dedtypes->data[tupi];
+ if (o)
+ { // Existing deduced argument must be a tuple, and must match
+ Tuple *t = isTuple(o);
+ if (!t || t->objects.dim != tuple_dim)
+ return MATCHnomatch;
+ for (size_t i = 0; i < tuple_dim; i++)
+ { Parameter *arg = Parameter::getNth(this->parameters, nfparams - 1 + i);
+ if (!arg->type->equals((Object *)t->objects.data[i]))
+ return MATCHnomatch;
+ }
+ }
+ else
+ { // Create new tuple
+ Tuple *t = new Tuple();
+ t->objects.setDim(tuple_dim);
+ for (size_t i = 0; i < tuple_dim; i++)
+ { Parameter *arg = Parameter::getNth(this->parameters, nfparams - 1 + i);
+ t->objects.data[i] = (void *)arg->type;
+ }
+ dedtypes->data[tupi] = (void *)t;
+ }
+ nfparams--; // don't consider the last parameter for type deduction
+ goto L2;
+ }
L1:
- if (nfargs != nfparams)
- return MATCHnomatch;
+ if (nfargs != nfparams)
+ return MATCHnomatch;
L2:
- for (size_t i = 0; i < nfparams; i++)
- {
- Parameter *a = Parameter::getNth(this->parameters, i);
- Parameter *ap = Parameter::getNth(tp->parameters, i);
- if (a->storageClass != ap->storageClass ||
- !a->type->deduceType(sc, ap->type, parameters, dedtypes))
- return MATCHnomatch;
- }
+ for (size_t i = 0; i < nfparams; i++)
+ {
+ Parameter *a = Parameter::getNth(this->parameters, i);
+ Parameter *ap = Parameter::getNth(tp->parameters, i);
+ if (a->storageClass != ap->storageClass ||
+ !a->type->deduceType(sc, ap->type, parameters, dedtypes))
+ return MATCHnomatch;
+ }
}
return Type::deduceType(sc, tparam, parameters, dedtypes);
}
@@ -1834,23 +1834,23 @@ MATCH TypeIdentifier::deduceType(Scope *sc, Type *tparam, TemplateParameters *pa
// Extra check
if (tparam && tparam->ty == Tident)
{
- TypeIdentifier *tp = (TypeIdentifier *)tparam;
+ TypeIdentifier *tp = (TypeIdentifier *)tparam;
- for (int i = 0; i < idents.dim; i++)
- {
- Identifier *id1 = (Identifier *)idents.data[i];
- Identifier *id2 = (Identifier *)tp->idents.data[i];
+ for (int i = 0; i < idents.dim; i++)
+ {
+ Identifier *id1 = (Identifier *)idents.data[i];
+ Identifier *id2 = (Identifier *)tp->idents.data[i];
- if (!id1->equals(id2))
- return MATCHnomatch;
- }
+ if (!id1->equals(id2))
+ return MATCHnomatch;
+ }
}
return Type::deduceType(sc, tparam, parameters, dedtypes);
}
MATCH TypeInstance::deduceType(Scope *sc,
- Type *tparam, TemplateParameters *parameters,
- Objects *dedtypes)
+ Type *tparam, TemplateParameters *parameters,
+ Objects *dedtypes)
{
#if 0
printf("TypeInstance::deduceType()\n");
@@ -1861,208 +1861,208 @@ MATCH TypeInstance::deduceType(Scope *sc,
// Extra check
if (tparam && tparam->ty == Tinstance)
{
- TypeInstance *tp = (TypeInstance *)tparam;
+ TypeInstance *tp = (TypeInstance *)tparam;
- //printf("tempinst->tempdecl = %p\n", tempinst->tempdecl);
- //printf("tp->tempinst->tempdecl = %p\n", tp->tempinst->tempdecl);
- if (!tp->tempinst->tempdecl)
- { //printf("tp->tempinst->name = '%s'\n", tp->tempinst->name->toChars());
- if (!tp->tempinst->name->equals(tempinst->name))
- {
- /* Handle case of:
- * template Foo(T : sa!(T), alias sa)
- */
- int i = templateIdentifierLookup(tp->tempinst->name, parameters);
- if (i == -1)
- { /* Didn't find it as a parameter identifier. Try looking
- * it up and seeing if is an alias. See Bugzilla 1454
- */
- Dsymbol *s = tempinst->tempdecl->scope->search(0, tp->tempinst->name, NULL);
- if (s)
- {
- s = s->toAlias();
- TemplateDeclaration *td = s->isTemplateDeclaration();
- if (td && td == tempinst->tempdecl)
- goto L2;
- }
- goto Lnomatch;
- }
- TemplateParameter *tpx = (TemplateParameter *)parameters->data[i];
- // This logic duplicates tpx->matchArg()
- TemplateAliasParameter *ta = tpx->isTemplateAliasParameter();
- if (!ta)
- goto Lnomatch;
- Object *sa = tempinst->tempdecl;
- if (!sa)
- goto Lnomatch;
- if (ta->specAlias && sa != ta->specAlias)
- goto Lnomatch;
- if (dedtypes->data[i])
- { // Must match already deduced symbol
- Object *s = (Object *)dedtypes->data[i];
+ //printf("tempinst->tempdecl = %p\n", tempinst->tempdecl);
+ //printf("tp->tempinst->tempdecl = %p\n", tp->tempinst->tempdecl);
+ if (!tp->tempinst->tempdecl)
+ { //printf("tp->tempinst->name = '%s'\n", tp->tempinst->name->toChars());
+ if (!tp->tempinst->name->equals(tempinst->name))
+ {
+ /* Handle case of:
+ * template Foo(T : sa!(T), alias sa)
+ */
+ int i = templateIdentifierLookup(tp->tempinst->name, parameters);
+ if (i == -1)
+ { /* Didn't find it as a parameter identifier. Try looking
+ * it up and seeing if is an alias. See Bugzilla 1454
+ */
+ Dsymbol *s = tempinst->tempdecl->scope->search(0, tp->tempinst->name, NULL);
+ if (s)
+ {
+ s = s->toAlias();
+ TemplateDeclaration *td = s->isTemplateDeclaration();
+ if (td && td == tempinst->tempdecl)
+ goto L2;
+ }
+ goto Lnomatch;
+ }
+ TemplateParameter *tpx = (TemplateParameter *)parameters->data[i];
+ // This logic duplicates tpx->matchArg()
+ TemplateAliasParameter *ta = tpx->isTemplateAliasParameter();
+ if (!ta)
+ goto Lnomatch;
+ Object *sa = tempinst->tempdecl;
+ if (!sa)
+ goto Lnomatch;
+ if (ta->specAlias && sa != ta->specAlias)
+ goto Lnomatch;
+ if (dedtypes->data[i])
+ { // Must match already deduced symbol
+ Object *s = (Object *)dedtypes->data[i];
- if (s != sa)
- goto Lnomatch;
- }
- dedtypes->data[i] = sa;
- }
- }
- else if (tempinst->tempdecl != tp->tempinst->tempdecl)
- goto Lnomatch;
+ if (s != sa)
+ goto Lnomatch;
+ }
+ dedtypes->data[i] = sa;
+ }
+ }
+ else if (tempinst->tempdecl != tp->tempinst->tempdecl)
+ goto Lnomatch;
L2:
- for (int i = 0; 1; i++)
- {
- //printf("\ttest: tempinst->tiargs[%d]\n", i);
- Object *o1;
- if (i < tempinst->tiargs->dim)
- o1 = (Object *)tempinst->tiargs->data[i];
- else if (i < tempinst->tdtypes.dim && i < tp->tempinst->tiargs->dim)
- // Pick up default arg
- o1 = (Object *)tempinst->tdtypes.data[i];
- else
- break;
+ for (int i = 0; 1; i++)
+ {
+ //printf("\ttest: tempinst->tiargs[%d]\n", i);
+ Object *o1;
+ if (i < tempinst->tiargs->dim)
+ o1 = (Object *)tempinst->tiargs->data[i];
+ else if (i < tempinst->tdtypes.dim && i < tp->tempinst->tiargs->dim)
+ // Pick up default arg
+ o1 = (Object *)tempinst->tdtypes.data[i];
+ else
+ break;
- if (i >= tp->tempinst->tiargs->dim)
- goto Lnomatch;
+ if (i >= tp->tempinst->tiargs->dim)
+ goto Lnomatch;
- Object *o2 = (Object *)tp->tempinst->tiargs->data[i];
+ Object *o2 = (Object *)tp->tempinst->tiargs->data[i];
- Type *t1 = isType(o1);
- Type *t2 = isType(o2);
+ Type *t1 = isType(o1);
+ Type *t2 = isType(o2);
- Expression *e1 = isExpression(o1);
- Expression *e2 = isExpression(o2);
+ Expression *e1 = isExpression(o1);
+ Expression *e2 = isExpression(o2);
- Dsymbol *s1 = isDsymbol(o1);
- Dsymbol *s2 = isDsymbol(o2);
+ Dsymbol *s1 = isDsymbol(o1);
+ Dsymbol *s2 = isDsymbol(o2);
- Tuple *v1 = isTuple(o1);
- Tuple *v2 = isTuple(o2);
+ Tuple *v1 = isTuple(o1);
+ Tuple *v2 = isTuple(o2);
#if 0
- if (t1) printf("t1 = %s\n", t1->toChars());
- if (t2) printf("t2 = %s\n", t2->toChars());
- if (e1) printf("e1 = %s\n", e1->toChars());
- if (e2) printf("e2 = %s\n", e2->toChars());
- if (s1) printf("s1 = %s\n", s1->toChars());
- if (s2) printf("s2 = %s\n", s2->toChars());
- if (v1) printf("v1 = %s\n", v1->toChars());
- if (v2) printf("v2 = %s\n", v2->toChars());
+ if (t1) printf("t1 = %s\n", t1->toChars());
+ if (t2) printf("t2 = %s\n", t2->toChars());
+ if (e1) printf("e1 = %s\n", e1->toChars());
+ if (e2) printf("e2 = %s\n", e2->toChars());
+ if (s1) printf("s1 = %s\n", s1->toChars());
+ if (s2) printf("s2 = %s\n", s2->toChars());
+ if (v1) printf("v1 = %s\n", v1->toChars());
+ if (v2) printf("v2 = %s\n", v2->toChars());
#endif
- TemplateTupleParameter *ttp;
- int j;
- if (t2 &&
- t2->ty == Tident &&
- i == tp->tempinst->tiargs->dim - 1 &&
- i == tempinst->tempdecl->parameters->dim - 1 &&
- (ttp = tempinst->tempdecl->isVariadic()) != NULL)
- {
- /* Given:
- * struct A(B...) {}
- * alias A!(int, float) X;
- * static if (!is(X Y == A!(Z), Z))
- * deduce that Z is a tuple(int, float)
- */
+ TemplateTupleParameter *ttp;
+ int j;
+ if (t2 &&
+ t2->ty == Tident &&
+ i == tp->tempinst->tiargs->dim - 1 &&
+ i == tempinst->tempdecl->parameters->dim - 1 &&
+ (ttp = tempinst->tempdecl->isVariadic()) != NULL)
+ {
+ /* Given:
+ * struct A(B...) {}
+ * alias A!(int, float) X;
+ * static if (!is(X Y == A!(Z), Z))
+ * deduce that Z is a tuple(int, float)
+ */
- j = templateParameterLookup(t2, parameters);
- if (j == -1)
- goto Lnomatch;
+ j = templateParameterLookup(t2, parameters);
+ if (j == -1)
+ goto Lnomatch;
- /* Create tuple from remaining args
- */
- Tuple *vt = new Tuple();
- int vtdim = tempinst->tiargs->dim - i;
- vt->objects.setDim(vtdim);
- for (size_t k = 0; k < vtdim; k++)
- vt->objects.data[k] = (void *)tempinst->tiargs->data[i + k];
+ /* Create tuple from remaining args
+ */
+ Tuple *vt = new Tuple();
+ int vtdim = tempinst->tiargs->dim - i;
+ vt->objects.setDim(vtdim);
+ for (size_t k = 0; k < vtdim; k++)
+ vt->objects.data[k] = (void *)tempinst->tiargs->data[i + k];
- Tuple *v = (Tuple *)dedtypes->data[j];
- if (v)
- {
- if (!match(v, vt, tempinst->tempdecl, sc))
- goto Lnomatch;
- }
- else
- dedtypes->data[j] = vt;
- break; //return MATCHexact;
- }
+ Tuple *v = (Tuple *)dedtypes->data[j];
+ if (v)
+ {
+ if (!match(v, vt, tempinst->tempdecl, sc))
+ goto Lnomatch;
+ }
+ else
+ dedtypes->data[j] = vt;
+ break; //return MATCHexact;
+ }
- if (t1 && t2)
- {
- if (!t1->deduceType(sc, t2, parameters, dedtypes))
- goto Lnomatch;
- }
- else if (e1 && e2)
- {
- if (!e1->equals(e2))
- { if (e2->op == TOKvar)
- {
- /*
- * (T:Number!(e2), int e2)
- */
- j = templateIdentifierLookup(((VarExp *)e2)->var->ident, parameters);
- goto L1;
- }
- goto Lnomatch;
- }
- }
- else if (e1 && t2 && t2->ty == Tident)
- {
- j = templateParameterLookup(t2, parameters);
- L1:
- if (j == -1)
- goto Lnomatch;
- TemplateParameter *tp = (TemplateParameter *)parameters->data[j];
- // BUG: use tp->matchArg() instead of the following
- TemplateValueParameter *tv = tp->isTemplateValueParameter();
- if (!tv)
- goto Lnomatch;
- Expression *e = (Expression *)dedtypes->data[j];
- if (e)
- {
- if (!e1->equals(e))
- goto Lnomatch;
- }
- else
- { Type *vt = tv->valType->semantic(0, sc);
- MATCH m = (MATCH)e1->implicitConvTo(vt);
- if (!m)
- goto Lnomatch;
- dedtypes->data[j] = e1;
- }
- }
- else if (s1 && t2 && t2->ty == Tident)
- {
- j = templateParameterLookup(t2, parameters);
- if (j == -1)
- goto Lnomatch;
- TemplateParameter *tp = (TemplateParameter *)parameters->data[j];
- // BUG: use tp->matchArg() instead of the following
- TemplateAliasParameter *ta = tp->isTemplateAliasParameter();
- if (!ta)
- goto Lnomatch;
- Dsymbol *s = (Dsymbol *)dedtypes->data[j];
- if (s)
- {
- if (!s1->equals(s))
- goto Lnomatch;
- }
- else
- {
- dedtypes->data[j] = s1;
- }
- }
- else if (s1 && s2)
- {
- if (!s1->equals(s2))
- goto Lnomatch;
- }
- // BUG: Need to handle tuple parameters
- else
- goto Lnomatch;
- }
+ if (t1 && t2)
+ {
+ if (!t1->deduceType(sc, t2, parameters, dedtypes))
+ goto Lnomatch;
+ }
+ else if (e1 && e2)
+ {
+ if (!e1->equals(e2))
+ { if (e2->op == TOKvar)
+ {
+ /*
+ * (T:Number!(e2), int e2)
+ */
+ j = templateIdentifierLookup(((VarExp *)e2)->var->ident, parameters);
+ goto L1;
+ }
+ goto Lnomatch;
+ }
+ }
+ else if (e1 && t2 && t2->ty == Tident)
+ {
+ j = templateParameterLookup(t2, parameters);
+ L1:
+ if (j == -1)
+ goto Lnomatch;
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[j];
+ // BUG: use tp->matchArg() instead of the following
+ TemplateValueParameter *tv = tp->isTemplateValueParameter();
+ if (!tv)
+ goto Lnomatch;
+ Expression *e = (Expression *)dedtypes->data[j];
+ if (e)
+ {
+ if (!e1->equals(e))
+ goto Lnomatch;
+ }
+ else
+ { Type *vt = tv->valType->semantic(0, sc);
+ MATCH m = (MATCH)e1->implicitConvTo(vt);
+ if (!m)
+ goto Lnomatch;
+ dedtypes->data[j] = e1;
+ }
+ }
+ else if (s1 && t2 && t2->ty == Tident)
+ {
+ j = templateParameterLookup(t2, parameters);
+ if (j == -1)
+ goto Lnomatch;
+ TemplateParameter *tp = (TemplateParameter *)parameters->data[j];
+ // BUG: use tp->matchArg() instead of the following
+ TemplateAliasParameter *ta = tp->isTemplateAliasParameter();
+ if (!ta)
+ goto Lnomatch;
+ Dsymbol *s = (Dsymbol *)dedtypes->data[j];
+ if (s)
+ {
+ if (!s1->equals(s))
+ goto Lnomatch;
+ }
+ else
+ {
+ dedtypes->data[j] = s1;
+ }
+ }
+ else if (s1 && s2)
+ {
+ if (!s1->equals(s2))
+ goto Lnomatch;
+ }
+ // BUG: Need to handle tuple parameters
+ else
+ goto Lnomatch;
+ }
}
return Type::deduceType(sc, tparam, parameters, dedtypes);
@@ -2084,41 +2084,41 @@ MATCH TypeStruct::deduceType(Scope *sc, Type *tparam, TemplateParameters *parame
if (tparam && tparam->ty == Tinstance)
{
- if (ti && ti->toAlias() == sym)
- {
- TypeInstance *t = new TypeInstance(0, ti);
- return t->deduceType(sc, tparam, parameters, dedtypes);
- }
+ if (ti && ti->toAlias() == sym)
+ {
+ TypeInstance *t = new TypeInstance(0, ti);
+ return t->deduceType(sc, tparam, parameters, dedtypes);
+ }
- /* Match things like:
- * S!(T).foo
- */
- TypeInstance *tpi = (TypeInstance *)tparam;
- if (tpi->idents.dim)
- { Identifier *id = (Identifier *)tpi->idents.data[tpi->idents.dim - 1];
- if (id->dyncast() == DYNCAST_IDENTIFIER && sym->ident->equals(id))
- {
- Type *tparent = sym->parent->getType();
- if (tparent)
- {
- /* Slice off the .foo in S!(T).foo
- */
- tpi->idents.dim--;
- MATCH m = tparent->deduceType(sc, tpi, parameters, dedtypes);
- tpi->idents.dim++;
- return m;
- }
- }
- }
+ /* Match things like:
+ * S!(T).foo
+ */
+ TypeInstance *tpi = (TypeInstance *)tparam;
+ if (tpi->idents.dim)
+ { Identifier *id = (Identifier *)tpi->idents.data[tpi->idents.dim - 1];
+ if (id->dyncast() == DYNCAST_IDENTIFIER && sym->ident->equals(id))
+ {
+ Type *tparent = sym->parent->getType();
+ if (tparent)
+ {
+ /* Slice off the .foo in S!(T).foo
+ */
+ tpi->idents.dim--;
+ MATCH m = tparent->deduceType(sc, tpi, parameters, dedtypes);
+ tpi->idents.dim++;
+ return m;
+ }
+ }
+ }
}
// Extra check
if (tparam && tparam->ty == Tstruct)
{
- TypeStruct *tp = (TypeStruct *)tparam;
+ TypeStruct *tp = (TypeStruct *)tparam;
- if (sym != tp->sym)
- return MATCHnomatch;
+ if (sym != tp->sym)
+ return MATCHnomatch;
}
return Type::deduceType(sc, tparam, parameters, dedtypes);
}
@@ -2128,10 +2128,10 @@ MATCH TypeEnum::deduceType(Scope *sc, Type *tparam, TemplateParameters *paramete
// Extra check
if (tparam && tparam->ty == Tenum)
{
- TypeEnum *tp = (TypeEnum *)tparam;
+ TypeEnum *tp = (TypeEnum *)tparam;
- if (sym != tp->sym)
- return MATCHnomatch;
+ if (sym != tp->sym)
+ return MATCHnomatch;
}
return Type::deduceType(sc, tparam, parameters, dedtypes);
}
@@ -2141,10 +2141,10 @@ MATCH TypeTypedef::deduceType(Scope *sc, Type *tparam, TemplateParameters *param
// Extra check
if (tparam && tparam->ty == Ttypedef)
{
- TypeTypedef *tp = (TypeTypedef *)tparam;
+ TypeTypedef *tp = (TypeTypedef *)tparam;
- if (sym != tp->sym)
- return MATCHnomatch;
+ if (sym != tp->sym)
+ return MATCHnomatch;
}
return Type::deduceType(sc, tparam, parameters, dedtypes);
}
@@ -2161,41 +2161,41 @@ MATCH TypeClass::deduceType(Scope *sc, Type *tparam, TemplateParameters *paramet
if (tparam && tparam->ty == Tinstance)
{
- if (ti && ti->toAlias() == sym)
- {
- TypeInstance *t = new TypeInstance(0, ti);
- return t->deduceType(sc, tparam, parameters, dedtypes);
- }
+ if (ti && ti->toAlias() == sym)
+ {
+ TypeInstance *t = new TypeInstance(0, ti);
+ return t->deduceType(sc, tparam, parameters, dedtypes);
+ }
- /* Match things like:
- * S!(T).foo
- */
- TypeInstance *tpi = (TypeInstance *)tparam;
- if (tpi->idents.dim)
- { Identifier *id = (Identifier *)tpi->idents.data[tpi->idents.dim - 1];
- if (id->dyncast() == DYNCAST_IDENTIFIER && sym->ident->equals(id))
- {
- Type *tparent = sym->parent->getType();
- if (tparent)
- {
- /* Slice off the .foo in S!(T).foo
- */
- tpi->idents.dim--;
- MATCH m = tparent->deduceType(sc, tpi, parameters, dedtypes);
- tpi->idents.dim++;
- return m;
- }
- }
- }
+ /* Match things like:
+ * S!(T).foo
+ */
+ TypeInstance *tpi = (TypeInstance *)tparam;
+ if (tpi->idents.dim)
+ { Identifier *id = (Identifier *)tpi->idents.data[tpi->idents.dim - 1];
+ if (id->dyncast() == DYNCAST_IDENTIFIER && sym->ident->equals(id))
+ {
+ Type *tparent = sym->parent->getType();
+ if (tparent)
+ {
+ /* Slice off the .foo in S!(T).foo
+ */
+ tpi->idents.dim--;
+ MATCH m = tparent->deduceType(sc, tpi, parameters, dedtypes);
+ tpi->idents.dim++;
+ return m;
+ }
+ }
+ }
}
// Extra check
if (tparam && tparam->ty == Tclass)
{
- TypeClass *tp = (TypeClass *)tparam;
+ TypeClass *tp = (TypeClass *)tparam;
- //printf("\t%d\n", (MATCH) implicitConvTo(tp));
- return (MATCH) implicitConvTo(tp);
+ //printf("\t%d\n", (MATCH) implicitConvTo(tp));
+ return (MATCH) implicitConvTo(tp);
}
return Type::deduceType(sc, tparam, parameters, dedtypes);
}
@@ -2241,7 +2241,7 @@ TemplateThisParameter *TemplateParameter::isTemplateThisParameter()
// type-parameter
TemplateTypeParameter::TemplateTypeParameter(Loc loc, Identifier *ident, Type *specType,
- Type *defaultType)
+ Type *defaultType)
: TemplateParameter(loc, ident)
{
this->ident = ident;
@@ -2258,9 +2258,9 @@ TemplateParameter *TemplateTypeParameter::syntaxCopy()
{
TemplateTypeParameter *tp = new TemplateTypeParameter(loc, ident, specType, defaultType);
if (tp->specType)
- tp->specType = specType->syntaxCopy();
+ tp->specType = specType->syntaxCopy();
if (defaultType)
- tp->defaultType = defaultType->syntaxCopy();
+ tp->defaultType = defaultType->syntaxCopy();
return tp;
}
@@ -2270,7 +2270,7 @@ void TemplateTypeParameter::declareParameter(Scope *sc)
TypeIdentifier *ti = new TypeIdentifier(loc, ident);
sparam = new AliasDeclaration(loc, ident, ti);
if (!sc->insert(sparam))
- error(loc, "parameter '%s' multiply defined", ident->toChars());
+ error(loc, "parameter '%s' multiply defined", ident->toChars());
}
void TemplateTypeParameter::semantic(Scope *sc)
@@ -2278,12 +2278,12 @@ void TemplateTypeParameter::semantic(Scope *sc)
//printf("TemplateTypeParameter::semantic('%s')\n", ident->toChars());
if (specType)
{
- specType = specType->semantic(loc, sc);
+ specType = specType->semantic(loc, sc);
}
#if 0 // Don't do semantic() until instantiation
if (defaultType)
{
- defaultType = defaultType->semantic(loc, sc);
+ defaultType = defaultType->semantic(loc, sc);
}
#endif
}
@@ -2292,8 +2292,8 @@ void TemplateTypeParameter::semantic(Scope *sc)
* Determine if two TemplateParameters are the same
* as far as TemplateDeclaration overloading goes.
* Returns:
- * 1 match
- * 0 no match
+ * 1 match
+ * 0 no match
*/
int TemplateTypeParameter::overloadMatch(TemplateParameter *tp)
@@ -2302,13 +2302,13 @@ int TemplateTypeParameter::overloadMatch(TemplateParameter *tp)
if (ttp)
{
- if (specType != ttp->specType)
- goto Lnomatch;
+ if (specType != ttp->specType)
+ goto Lnomatch;
- if (specType && !specType->equals(ttp->specType))
- goto Lnomatch;
+ if (specType && !specType->equals(ttp->specType))
+ goto Lnomatch;
- return 1; // match
+ return 1; // match
}
Lnomatch:
@@ -2318,16 +2318,16 @@ Lnomatch:
/*******************************************
* Match to a particular TemplateParameter.
* Input:
- * i i'th argument
- * tiargs[] actual arguments to template instance
- * parameters[] template parameters
- * dedtypes[] deduced arguments to template instance
- * *psparam set to symbol declared and initialized to dedtypes[i]
+ * i i'th argument
+ * tiargs[] actual arguments to template instance
+ * parameters[] template parameters
+ * dedtypes[] deduced arguments to template instance
+ * *psparam set to symbol declared and initialized to dedtypes[i]
*/
MATCH TemplateTypeParameter::matchArg(Scope *sc, Objects *tiargs,
- int i, TemplateParameters *parameters, Objects *dedtypes,
- Declaration **psparam, int flags)
+ int i, TemplateParameters *parameters, Objects *dedtypes,
+ Declaration **psparam, int flags)
{
//printf("TemplateTypeParameter::matchArg()\n");
Type *t;
@@ -2336,58 +2336,58 @@ MATCH TemplateTypeParameter::matchArg(Scope *sc, Objects *tiargs,
Type *ta;
if (i < tiargs->dim)
- oarg = (Object *)tiargs->data[i];
+ oarg = (Object *)tiargs->data[i];
else
- { // Get default argument instead
- oarg = defaultArg(loc, sc);
- if (!oarg)
- { assert(i < dedtypes->dim);
- // It might have already been deduced
- oarg = (Object *)dedtypes->data[i];
- if (!oarg)
- goto Lnomatch;
- }
+ { // Get default argument instead
+ oarg = defaultArg(loc, sc);
+ if (!oarg)
+ { assert(i < dedtypes->dim);
+ // It might have already been deduced
+ oarg = (Object *)dedtypes->data[i];
+ if (!oarg)
+ goto Lnomatch;
+ }
}
ta = isType(oarg);
if (!ta)
- goto Lnomatch;
+ goto Lnomatch;
//printf("ta is %s\n", ta->toChars());
t = (Type *)dedtypes->data[i];
if (specType)
{
- //printf("\tcalling deduceType(): ta is %s, specType is %s\n", ta->toChars(), specType->toChars());
- MATCH m2 = ta->deduceType(sc, specType, parameters, dedtypes);
- if (m2 == MATCHnomatch)
- { //printf("\tfailed deduceType\n");
- goto Lnomatch;
- }
+ //printf("\tcalling deduceType(): ta is %s, specType is %s\n", ta->toChars(), specType->toChars());
+ MATCH m2 = ta->deduceType(sc, specType, parameters, dedtypes);
+ if (m2 == MATCHnomatch)
+ { //printf("\tfailed deduceType\n");
+ goto Lnomatch;
+ }
- if (m2 < m)
- m = m2;
- t = (Type *)dedtypes->data[i];
+ if (m2 < m)
+ m = m2;
+ t = (Type *)dedtypes->data[i];
}
else
{
- // So that matches with specializations are better
- m = MATCHconvert;
- if (t)
- { // Must match already deduced type
+ // So that matches with specializations are better
+ m = MATCHconvert;
+ if (t)
+ { // Must match already deduced type
- m = MATCHexact;
- if (!t->equals(ta))
- { //printf("t = %s ta = %s\n", t->toChars(), ta->toChars());
- goto Lnomatch;
- }
- }
+ m = MATCHexact;
+ if (!t->equals(ta))
+ { //printf("t = %s ta = %s\n", t->toChars(), ta->toChars());
+ goto Lnomatch;
+ }
+ }
}
if (!t)
{
- dedtypes->data[i] = ta;
- t = ta;
+ dedtypes->data[i] = ta;
+ t = ta;
}
*psparam = new AliasDeclaration(loc, ident, t);
//printf("\tm = %d\n", m);
@@ -2410,9 +2410,9 @@ void TemplateTypeParameter::print(Object *oarg, Object *oded)
assert(ta);
if (specType)
- printf("\tSpecialization: %s\n", specType->toChars());
+ printf("\tSpecialization: %s\n", specType->toChars());
if (defaultType)
- printf("\tDefault: %s\n", defaultType->toChars());
+ printf("\tDefault: %s\n", defaultType->toChars());
printf("\tParameter: %s\n", t ? t->toChars() : "NULL");
printf("\tDeduced Type: %s\n", ta->toChars());
}
@@ -2423,13 +2423,13 @@ void TemplateTypeParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring(ident->toChars());
if (specType)
{
- buf->writestring(" : ");
- specType->toCBuffer(buf, NULL, hgs);
+ buf->writestring(" : ");
+ specType->toCBuffer(buf, NULL, hgs);
}
if (defaultType)
{
- buf->writestring(" = ");
- defaultType->toCBuffer(buf, NULL, hgs);
+ buf->writestring(" = ");
+ defaultType->toCBuffer(buf, NULL, hgs);
}
}
@@ -2438,10 +2438,10 @@ void *TemplateTypeParameter::dummyArg()
{ Type *t;
if (specType)
- t = specType;
+ t = specType;
else
{ // Use this for alias-parameter's too (?)
- t = new TypeIdentifier(loc, ident);
+ t = new TypeIdentifier(loc, ident);
}
return (void *)t;
}
@@ -2460,8 +2460,8 @@ Object *TemplateTypeParameter::defaultArg(Loc loc, Scope *sc)
t = defaultType;
if (t)
{
- t = t->syntaxCopy();
- t = t->semantic(loc, sc);
+ t = t->syntaxCopy();
+ t = t->semantic(loc, sc);
}
return t;
}
@@ -2472,8 +2472,8 @@ Object *TemplateTypeParameter::defaultArg(Loc loc, Scope *sc)
// this-parameter
TemplateThisParameter::TemplateThisParameter(Loc loc, Identifier *ident,
- Type *specType,
- Type *defaultType)
+ Type *specType,
+ Type *defaultType)
: TemplateTypeParameter(loc, ident, specType, defaultType)
{
}
@@ -2487,9 +2487,9 @@ TemplateParameter *TemplateThisParameter::syntaxCopy()
{
TemplateThisParameter *tp = new TemplateThisParameter(loc, ident, specType, defaultType);
if (tp->specType)
- tp->specType = specType->syntaxCopy();
+ tp->specType = specType->syntaxCopy();
if (defaultType)
- tp->defaultType = defaultType->syntaxCopy();
+ tp->defaultType = defaultType->syntaxCopy();
return tp;
}
@@ -2525,9 +2525,9 @@ TemplateParameter *TemplateAliasParameter::syntaxCopy()
{
TemplateAliasParameter *tp = new TemplateAliasParameter(loc, ident, specAliasT, defaultAlias);
if (tp->specAliasT)
- tp->specAliasT = specAliasT->syntaxCopy();
+ tp->specAliasT = specAliasT->syntaxCopy();
if (defaultAlias)
- tp->defaultAlias = defaultAlias->syntaxCopy();
+ tp->defaultAlias = defaultAlias->syntaxCopy();
return tp;
}
@@ -2536,20 +2536,20 @@ void TemplateAliasParameter::declareParameter(Scope *sc)
TypeIdentifier *ti = new TypeIdentifier(loc, ident);
sparam = new AliasDeclaration(loc, ident, ti);
if (!sc->insert(sparam))
- error(loc, "parameter '%s' multiply defined", ident->toChars());
+ error(loc, "parameter '%s' multiply defined", ident->toChars());
}
void TemplateAliasParameter::semantic(Scope *sc)
{
if (specAliasT)
{
- specAlias = specAliasT->toDsymbol(sc);
- if (!specAlias)
- error(loc, "%s is not a symbol", specAliasT->toChars());
+ specAlias = specAliasT->toDsymbol(sc);
+ if (!specAlias)
+ error(loc, "%s is not a symbol", specAliasT->toChars());
}
#if 0 // Don't do semantic() until instantiation
if (defaultAlias)
- defaultAlias = defaultAlias->semantic(loc, sc);
+ defaultAlias = defaultAlias->semantic(loc, sc);
#endif
}
@@ -2559,10 +2559,10 @@ int TemplateAliasParameter::overloadMatch(TemplateParameter *tp)
if (tap)
{
- if (specAlias != tap->specAlias)
- goto Lnomatch;
+ if (specAlias != tap->specAlias)
+ goto Lnomatch;
- return 1; // match
+ return 1; // match
}
Lnomatch:
@@ -2570,8 +2570,8 @@ Lnomatch:
}
MATCH TemplateAliasParameter::matchArg(Scope *sc,
- Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes,
- Declaration **psparam, int flags)
+ Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes,
+ Declaration **psparam, int flags)
{
Dsymbol *sa;
Object *oarg;
@@ -2580,36 +2580,36 @@ MATCH TemplateAliasParameter::matchArg(Scope *sc,
//printf("TemplateAliasParameter::matchArg()\n");
if (i < tiargs->dim)
- oarg = (Object *)tiargs->data[i];
+ oarg = (Object *)tiargs->data[i];
else
- { // Get default argument instead
- oarg = defaultArg(loc, sc);
- if (!oarg)
- { assert(i < dedtypes->dim);
- // It might have already been deduced
- oarg = (Object *)dedtypes->data[i];
- if (!oarg)
- goto Lnomatch;
- }
+ { // Get default argument instead
+ oarg = defaultArg(loc, sc);
+ if (!oarg)
+ { assert(i < dedtypes->dim);
+ // It might have already been deduced
+ oarg = (Object *)dedtypes->data[i];
+ if (!oarg)
+ goto Lnomatch;
+ }
}
sa = getDsymbol(oarg);
if (!sa)
- goto Lnomatch;
+ goto Lnomatch;
if (specAlias)
{
- if (!sa || sa == sdummy)
- goto Lnomatch;
- if (sa != specAlias)
- goto Lnomatch;
+ if (!sa || sa == sdummy)
+ goto Lnomatch;
+ if (sa != specAlias)
+ goto Lnomatch;
}
else if (dedtypes->data[i])
{ // Must match already deduced symbol
- Dsymbol *s = (Dsymbol *)dedtypes->data[i];
+ Dsymbol *s = (Dsymbol *)dedtypes->data[i];
- if (!sa || s != sa)
- goto Lnomatch;
+ if (!sa || s != sa)
+ goto Lnomatch;
}
dedtypes->data[i] = sa;
@@ -2638,13 +2638,13 @@ void TemplateAliasParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring(ident->toChars());
if (specAliasT)
{
- buf->writestring(" : ");
- specAliasT->toCBuffer(buf, NULL, hgs);
+ buf->writestring(" : ");
+ specAliasT->toCBuffer(buf, NULL, hgs);
}
if (defaultAlias)
{
- buf->writestring(" = ");
- defaultAlias->toCBuffer(buf, NULL, hgs);
+ buf->writestring(" = ");
+ defaultAlias->toCBuffer(buf, NULL, hgs);
}
}
@@ -2655,9 +2655,9 @@ void *TemplateAliasParameter::dummyArg()
s = specAlias;
if (!s)
{
- if (!sdummy)
- sdummy = new Dsymbol();
- s = sdummy;
+ if (!sdummy)
+ sdummy = new Dsymbol();
+ s = sdummy;
}
return (void*)s;
}
@@ -2675,9 +2675,9 @@ Object *TemplateAliasParameter::defaultArg(Loc loc, Scope *sc)
if (defaultAlias)
{
- s = defaultAlias->toDsymbol(sc);
- if (!s)
- error("%s is not a symbol", defaultAlias->toChars());
+ s = defaultAlias->toDsymbol(sc);
+ if (!s)
+ error("%s is not a symbol", defaultAlias->toChars());
}
return s;
}
@@ -2689,7 +2689,7 @@ Object *TemplateAliasParameter::defaultArg(Loc loc, Scope *sc)
Expression *TemplateValueParameter::edummy = NULL;
TemplateValueParameter::TemplateValueParameter(Loc loc, Identifier *ident, Type *valType,
- Expression *specValue, Expression *defaultValue)
+ Expression *specValue, Expression *defaultValue)
: TemplateParameter(loc, ident)
{
this->ident = ident;
@@ -2706,12 +2706,12 @@ TemplateValueParameter *TemplateValueParameter::isTemplateValueParameter()
TemplateParameter *TemplateValueParameter::syntaxCopy()
{
TemplateValueParameter *tp =
- new TemplateValueParameter(loc, ident, valType, specValue, defaultValue);
+ new TemplateValueParameter(loc, ident, valType, specValue, defaultValue);
tp->valType = valType->syntaxCopy();
if (specValue)
- tp->specValue = specValue->syntaxCopy();
+ tp->specValue = specValue->syntaxCopy();
if (defaultValue)
- tp->defaultValue = defaultValue->syntaxCopy();
+ tp->defaultValue = defaultValue->syntaxCopy();
return tp;
}
@@ -2720,7 +2720,7 @@ void TemplateValueParameter::declareParameter(Scope *sc)
VarDeclaration *v = new VarDeclaration(loc, valType, ident, NULL);
v->storage_class = STCtemplateparameter;
if (!sc->insert(v))
- error(loc, "parameter '%s' multiply defined", ident->toChars());
+ error(loc, "parameter '%s' multiply defined", ident->toChars());
sparam = v;
}
@@ -2729,31 +2729,31 @@ void TemplateValueParameter::semantic(Scope *sc)
sparam->semantic(sc);
valType = valType->semantic(loc, sc);
if (!(valType->isintegral() || valType->isfloating() || valType->isString()) &&
- valType->ty != Tident)
- error(loc, "arithmetic/string type expected for value-parameter, not %s", valType->toChars());
+ valType->ty != Tident)
+ error(loc, "arithmetic/string type expected for value-parameter, not %s", valType->toChars());
if (specValue)
{ Expression *e = specValue;
- e = e->semantic(sc);
- e = e->implicitCastTo(sc, valType);
- e = e->optimize(WANTvalue | WANTinterpret);
- if (e->op == TOKint64 || e->op == TOKfloat64 ||
- e->op == TOKcomplex80 || e->op == TOKnull || e->op == TOKstring)
- specValue = e;
- //e->toInteger();
+ e = e->semantic(sc);
+ e = e->implicitCastTo(sc, valType);
+ e = e->optimize(WANTvalue | WANTinterpret);
+ if (e->op == TOKint64 || e->op == TOKfloat64 ||
+ e->op == TOKcomplex80 || e->op == TOKnull || e->op == TOKstring)
+ specValue = e;
+ //e->toInteger();
}
-#if 0 // defer semantic analysis to arg match
+#if 0 // defer semantic analysis to arg match
if (defaultValue)
{ Expression *e = defaultValue;
- e = e->semantic(sc);
- e = e->implicitCastTo(sc, valType);
- e = e->optimize(WANTvalue | WANTinterpret);
- if (e->op == TOKint64)
- defaultValue = e;
- //e->toInteger();
+ e = e->semantic(sc);
+ e = e->implicitCastTo(sc, valType);
+ e = e->optimize(WANTvalue | WANTinterpret);
+ if (e->op == TOKint64)
+ defaultValue = e;
+ //e->toInteger();
}
#endif
}
@@ -2764,16 +2764,16 @@ int TemplateValueParameter::overloadMatch(TemplateParameter *tp)
if (tvp)
{
- if (valType != tvp->valType)
- goto Lnomatch;
+ if (valType != tvp->valType)
+ goto Lnomatch;
- if (valType && !valType->equals(tvp->valType))
- goto Lnomatch;
+ if (valType && !valType->equals(tvp->valType))
+ goto Lnomatch;
- if (specValue != tvp->specValue)
- goto Lnomatch;
+ if (specValue != tvp->specValue)
+ goto Lnomatch;
- return 1; // match
+ return 1; // match
}
Lnomatch:
@@ -2782,8 +2782,8 @@ Lnomatch:
MATCH TemplateValueParameter::matchArg(Scope *sc,
- Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes,
- Declaration **psparam, int flags)
+ Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes,
+ Declaration **psparam, int flags)
{
//printf("TemplateValueParameter::matchArg()\n");
@@ -2794,50 +2794,50 @@ MATCH TemplateValueParameter::matchArg(Scope *sc,
Object *oarg;
if (i < tiargs->dim)
- oarg = (Object *)tiargs->data[i];
+ oarg = (Object *)tiargs->data[i];
else
- { // Get default argument instead
- oarg = defaultArg(loc, sc);
- if (!oarg)
- { assert(i < dedtypes->dim);
- // It might have already been deduced
- oarg = (Object *)dedtypes->data[i];
- if (!oarg)
- goto Lnomatch;
- }
+ { // Get default argument instead
+ oarg = defaultArg(loc, sc);
+ if (!oarg)
+ { assert(i < dedtypes->dim);
+ // It might have already been deduced
+ oarg = (Object *)dedtypes->data[i];
+ if (!oarg)
+ goto Lnomatch;
+ }
}
ei = isExpression(oarg);
Type *vt;
if (!ei && oarg)
- goto Lnomatch;
+ goto Lnomatch;
if (specValue)
{
- if (!ei || ei == edummy)
- goto Lnomatch;
+ if (!ei || ei == edummy)
+ goto Lnomatch;
- Expression *e = specValue;
+ Expression *e = specValue;
- e = e->semantic(sc);
- e = e->implicitCastTo(sc, valType);
- e = e->optimize(WANTvalue | WANTinterpret);
+ e = e->semantic(sc);
+ e = e->implicitCastTo(sc, valType);
+ e = e->optimize(WANTvalue | WANTinterpret);
- ei = ei->syntaxCopy();
- ei = ei->semantic(sc);
- ei = ei->optimize(WANTvalue | WANTinterpret);
- //printf("ei: %s, %s\n", ei->toChars(), ei->type->toChars());
- //printf("e : %s, %s\n", e->toChars(), e->type->toChars());
- if (!ei->equals(e))
- goto Lnomatch;
+ ei = ei->syntaxCopy();
+ ei = ei->semantic(sc);
+ ei = ei->optimize(WANTvalue | WANTinterpret);
+ //printf("ei: %s, %s\n", ei->toChars(), ei->type->toChars());
+ //printf("e : %s, %s\n", e->toChars(), e->type->toChars());
+ if (!ei->equals(e))
+ goto Lnomatch;
}
else if (dedtypes->data[i])
{ // Must match already deduced value
- Expression *e = (Expression *)dedtypes->data[i];
+ Expression *e = (Expression *)dedtypes->data[i];
- if (!ei || !ei->equals(e))
- goto Lnomatch;
+ if (!ei || !ei->equals(e))
+ goto Lnomatch;
}
Lmatch:
//printf("valType: %s, ty = %d\n", valType->toChars(), valType->ty);
@@ -2845,10 +2845,10 @@ Lmatch:
//printf("ei: %s, %s\n", ei->toChars(), ei->type->toChars());
if (ei->type)
{
- m = (MATCH)ei->implicitConvTo(vt);
- //printf("m: %d\n", m);
- if (!m)
- goto Lnomatch;
+ m = (MATCH)ei->implicitConvTo(vt);
+ //printf("m: %d\n", m);
+ if (!m)
+ goto Lnomatch;
}
dedtypes->data[i] = ei;
@@ -2872,7 +2872,7 @@ void TemplateValueParameter::print(Object *oarg, Object *oded)
Expression *ea = isExpression(oded);
if (specValue)
- printf("\tSpecialization: %s\n", specValue->toChars());
+ printf("\tSpecialization: %s\n", specValue->toChars());
printf("\tParameter Value: %s\n", ea ? ea->toChars() : "NULL");
}
@@ -2882,13 +2882,13 @@ void TemplateValueParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
valType->toCBuffer(buf, ident, hgs);
if (specValue)
{
- buf->writestring(" : ");
- specValue->toCBuffer(buf, hgs);
+ buf->writestring(" : ");
+ specValue->toCBuffer(buf, hgs);
}
if (defaultValue)
{
- buf->writestring(" = ");
- defaultValue->toCBuffer(buf, hgs);
+ buf->writestring(" = ");
+ defaultValue->toCBuffer(buf, hgs);
}
}
@@ -2899,10 +2899,10 @@ void *TemplateValueParameter::dummyArg()
e = specValue;
if (!e)
{
- // Create a dummy value
- if (!edummy)
- edummy = valType->defaultInit();
- e = edummy;
+ // Create a dummy value
+ if (!edummy)
+ edummy = valType->defaultInit();
+ e = edummy;
}
return (void *)e;
}
@@ -2919,13 +2919,13 @@ Object *TemplateValueParameter::defaultArg(Loc loc, Scope *sc)
Expression *e = defaultValue;
if (e)
{
- e = e->syntaxCopy();
- e = e->semantic(sc);
+ e = e->syntaxCopy();
+ e = e->semantic(sc);
#if DMDV2
- if (e->op == TOKdefault)
- { DefaultInitExp *de = (DefaultInitExp *)e;
- e = de->resolve(loc, sc);
- }
+ if (e->op == TOKdefault)
+ { DefaultInitExp *de = (DefaultInitExp *)e;
+ e = de->resolve(loc, sc);
+ }
#endif
}
return e;
@@ -2957,7 +2957,7 @@ void TemplateTupleParameter::declareParameter(Scope *sc)
TypeIdentifier *ti = new TypeIdentifier(loc, ident);
sparam = new AliasDeclaration(loc, ident, ti);
if (!sc->insert(sparam))
- error(loc, "parameter '%s' multiply defined", ident->toChars());
+ error(loc, "parameter '%s' multiply defined", ident->toChars());
}
void TemplateTupleParameter::semantic(Scope *sc)
@@ -2970,7 +2970,7 @@ int TemplateTupleParameter::overloadMatch(TemplateParameter *tp)
if (tvp)
{
- return 1; // match
+ return 1; // match
}
Lnomatch:
@@ -2978,30 +2978,30 @@ Lnomatch:
}
MATCH TemplateTupleParameter::matchArg(Scope *sc,
- Objects *tiargs, int i, TemplateParameters *parameters,
- Objects *dedtypes,
- Declaration **psparam, int flags)
+ Objects *tiargs, int i, TemplateParameters *parameters,
+ Objects *dedtypes,
+ Declaration **psparam, int flags)
{
//printf("TemplateTupleParameter::matchArg()\n");
/* The rest of the actual arguments (tiargs[]) form the match
* for the variadic parameter.
*/
- assert(i + 1 == dedtypes->dim); // must be the last one
+ assert(i + 1 == dedtypes->dim); // must be the last one
Tuple *ovar;
if (i + 1 == tiargs->dim && isTuple((Object *)tiargs->data[i]))
- ovar = isTuple((Object *)tiargs->data[i]);
+ ovar = isTuple((Object *)tiargs->data[i]);
else
{
- ovar = new Tuple();
- //printf("ovar = %p\n", ovar);
- if (i < tiargs->dim)
- {
- //printf("i = %d, tiargs->dim = %d\n", i, tiargs->dim);
- ovar->objects.setDim(tiargs->dim - i);
- for (size_t j = 0; j < ovar->objects.dim; j++)
- ovar->objects.data[j] = tiargs->data[i + j];
- }
+ ovar = new Tuple();
+ //printf("ovar = %p\n", ovar);
+ if (i < tiargs->dim)
+ {
+ //printf("i = %d, tiargs->dim = %d\n", i, tiargs->dim);
+ ovar->objects.setDim(tiargs->dim - i);
+ for (size_t j = 0; j < ovar->objects.dim; j++)
+ ovar->objects.data[j] = tiargs->data[i + j];
+ }
}
*psparam = new TupleDeclaration(loc, ident, &ovar->objects);
dedtypes->data[i] = (void *)ovar;
@@ -3018,24 +3018,24 @@ void TemplateTupleParameter::print(Object *oarg, Object *oded)
//printf("|%d| ", v->objects.dim);
for (int i = 0; i < v->objects.dim; i++)
{
- if (i)
- printf(", ");
+ if (i)
+ printf(", ");
- Object *o = (Object *)v->objects.data[i];
+ Object *o = (Object *)v->objects.data[i];
- Dsymbol *sa = isDsymbol(o);
- if (sa)
- printf("alias: %s", sa->toChars());
+ Dsymbol *sa = isDsymbol(o);
+ if (sa)
+ printf("alias: %s", sa->toChars());
- Type *ta = isType(o);
- if (ta)
- printf("type: %s", ta->toChars());
+ Type *ta = isType(o);
+ if (ta)
+ printf("type: %s", ta->toChars());
- Expression *ea = isExpression(o);
- if (ea)
- printf("exp: %s", ea->toChars());
+ Expression *ea = isExpression(o);
+ if (ea)
+ printf("exp: %s", ea->toChars());
- assert(!isTuple(o)); // no nested Tuple arguments
+ assert(!isTuple(o)); // no nested Tuple arguments
}
printf("]\n");
@@ -3137,20 +3137,20 @@ Objects *TemplateInstance::arraySyntaxCopy(Objects *objs)
{
Objects *a = NULL;
if (objs)
- { a = new Objects();
- a->setDim(objs->dim);
- for (size_t i = 0; i < objs->dim; i++)
- {
- Type *ta = isType((Object *)objs->data[i]);
- if (ta)
- a->data[i] = ta->syntaxCopy();
- else
- {
- Expression *ea = isExpression((Object *)objs->data[i]);
- assert(ea);
- a->data[i] = ea->syntaxCopy();
- }
- }
+ { a = new Objects();
+ a->setDim(objs->dim);
+ for (size_t i = 0; i < objs->dim; i++)
+ {
+ Type *ta = isType((Object *)objs->data[i]);
+ if (ta)
+ a->data[i] = ta->syntaxCopy();
+ else
+ {
+ Expression *ea = isExpression((Object *)objs->data[i]);
+ assert(ea);
+ a->data[i] = ea->syntaxCopy();
+ }
+ }
}
return a;
}
@@ -3160,9 +3160,9 @@ Dsymbol *TemplateInstance::syntaxCopy(Dsymbol *s)
TemplateInstance *ti;
if (s)
- ti = (TemplateInstance *)s;
+ ti = (TemplateInstance *)s;
else
- ti = new TemplateInstance(loc, name);
+ ti = new TemplateInstance(loc, name);
ti->tiargs = arraySyntaxCopy(tiargs);
@@ -3175,24 +3175,24 @@ void TemplateInstance::semantic(Scope *sc)
{
if (global.errors)
{
- if (!global.gag)
- {
- /* Trying to soldier on rarely generates useful messages
- * at this point.
- */
- fatal();
- }
- return;
+ if (!global.gag)
+ {
+ /* Trying to soldier on rarely generates useful messages
+ * at this point.
+ */
+ fatal();
+ }
+ return;
}
#if LOG
printf("\n+TemplateInstance::semantic('%s', this=%p)\n", toChars(), this);
#endif
- if (inst) // if semantic() was already run
+ if (inst) // if semantic() was already run
{
#if LOG
- printf("-TemplateInstance::semantic('%s', this=%p) already run\n", inst->toChars(), inst);
+ printf("-TemplateInstance::semantic('%s', this=%p) already run\n", inst->toChars(), inst);
#endif
- return;
+ return;
}
// get the enclosing template instance from the scope tinst
@@ -3200,9 +3200,9 @@ void TemplateInstance::semantic(Scope *sc)
if (semanticRun != 0)
{
- error(loc, "recursive template expansion");
-// inst = this;
- return;
+ error(loc, "recursive template expansion");
+// inst = this;
+ return;
}
semanticRun = 1;
@@ -3211,9 +3211,9 @@ void TemplateInstance::semantic(Scope *sc)
// get the module of the outermost enclosing instantiation
if (tinst)
- tmodule = tinst->tmodule;
+ tmodule = tinst->tmodule;
else
- tmodule = sc->module;
+ tmodule = sc->module;
//printf("%s in %s\n", toChars(), tmodule->toChars());
#if LOG
@@ -3221,31 +3221,31 @@ void TemplateInstance::semantic(Scope *sc)
#endif
if (havetempdecl)
{
- assert((size_t)tempdecl->scope > 0x10000);
- // Deduce tdtypes
- tdtypes.setDim(tempdecl->parameters->dim);
- if (!tempdecl->matchWithInstance(this, &tdtypes, 0))
- {
- error("incompatible arguments for template instantiation");
- inst = this;
- return;
- }
+ assert((size_t)tempdecl->scope > 0x10000);
+ // Deduce tdtypes
+ tdtypes.setDim(tempdecl->parameters->dim);
+ if (!tempdecl->matchWithInstance(this, &tdtypes, 0))
+ {
+ error("incompatible arguments for template instantiation");
+ inst = this;
+ return;
+ }
}
else
{
- /* Run semantic on each argument, place results in tiargs[]
- * (if we havetempdecl, then tiargs is already evaluated)
- */
- semanticTiargs(sc);
+ /* Run semantic on each argument, place results in tiargs[]
+ * (if we havetempdecl, then tiargs is already evaluated)
+ */
+ semanticTiargs(sc);
- tempdecl = findTemplateDeclaration(sc);
- if (tempdecl)
- tempdecl = findBestMatch(sc);
- if (!tempdecl || global.errors)
- { inst = this;
- //printf("error return %p, %d\n", tempdecl, global.errors);
- return; // error recovery
- }
+ tempdecl = findTemplateDeclaration(sc);
+ if (tempdecl)
+ tempdecl = findBestMatch(sc);
+ if (!tempdecl || global.errors)
+ { inst = this;
+ //printf("error return %p, %d\n", tempdecl, global.errors);
+ return; // error recovery
+ }
}
hasNestedArgs(tiargs);
@@ -3256,41 +3256,41 @@ void TemplateInstance::semantic(Scope *sc)
for (size_t i = 0; i < tempdecl->instances.dim; i++)
{
- TemplateInstance *ti = (TemplateInstance *)tempdecl->instances.data[i];
+ TemplateInstance *ti = (TemplateInstance *)tempdecl->instances.data[i];
#if LOG
- printf("\t%s: checking for match with instance %d (%p): '%s'\n", toChars(), i, ti, ti->toChars());
+ printf("\t%s: checking for match with instance %d (%p): '%s'\n", toChars(), i, ti, ti->toChars());
#endif
- assert(tdtypes.dim == ti->tdtypes.dim);
+ assert(tdtypes.dim == ti->tdtypes.dim);
- // Nesting must match
- if (isnested != ti->isnested)
- {
- //printf("test2 isnested %s ti->isnested %s\n", isnested ? isnested->toChars() : "", ti->isnested ? ti->isnested->toChars() : "");
- continue;
- }
+ // Nesting must match
+ if (isnested != ti->isnested)
+ {
+ //printf("test2 isnested %s ti->isnested %s\n", isnested ? isnested->toChars() : "", ti->isnested ? ti->isnested->toChars() : "");
+ continue;
+ }
#if 0
- if (isnested && sc->parent != ti->parent)
- continue;
+ if (isnested && sc->parent != ti->parent)
+ continue;
#endif
- for (size_t j = 0; j < tdtypes.dim; j++)
- { Object *o1 = (Object *)tdtypes.data[j];
- Object *o2 = (Object *)ti->tdtypes.data[j];
- if (!match(o1, o2, tempdecl, sc))
- {
- goto L1;
- }
- }
+ for (size_t j = 0; j < tdtypes.dim; j++)
+ { Object *o1 = (Object *)tdtypes.data[j];
+ Object *o2 = (Object *)ti->tdtypes.data[j];
+ if (!match(o1, o2, tempdecl, sc))
+ {
+ goto L1;
+ }
+ }
- // It's a match
- inst = ti;
- parent = ti->parent;
+ // It's a match
+ inst = ti;
+ parent = ti->parent;
#if LOG
- printf("\tit's a match with instance %p\n", inst);
+ printf("\tit's a match with instance %p\n", inst);
#endif
- return;
+ return;
L1:
- ;
+ ;
}
/* So, we need to implement 'this' instance.
@@ -3305,11 +3305,11 @@ void TemplateInstance::semantic(Scope *sc)
parent = tempdecl->parent;
//printf("parent = '%s'\n", parent->kind());
- ident = genIdent(); // need an identifier for name mangling purposes.
+ ident = genIdent(); // need an identifier for name mangling purposes.
#if 1
if (isnested)
- parent = isnested;
+ parent = isnested;
#endif
//printf("parent = '%s'\n", parent->kind());
@@ -3317,49 +3317,49 @@ void TemplateInstance::semantic(Scope *sc)
// will get called on the instance members
#if 1
int dosemantic3 = 0;
- { Array *a;
+ { Array *a;
- Scope *scx = sc;
+ Scope *scx = sc;
#if 0
- for (scx = sc; scx; scx = scx->enclosing)
- if (scx->scopesym)
- break;
+ for (scx = sc; scx; scx = scx->enclosing)
+ if (scx->scopesym)
+ break;
#endif
- //if (scx && scx->scopesym) printf("3: scx is %s %s\n", scx->scopesym->kind(), scx->scopesym->toChars());
- if (scx && scx->scopesym &&
- scx->scopesym->members && !scx->scopesym->isTemplateMixin()
+ //if (scx && scx->scopesym) printf("3: scx is %s %s\n", scx->scopesym->kind(), scx->scopesym->toChars());
+ if (scx && scx->scopesym &&
+ scx->scopesym->members && !scx->scopesym->isTemplateMixin()
#if 1 // removed because it bloated compile times
- /* The problem is if A imports B, and B imports A, and both A
- * and B instantiate the same template, does the compilation of A
- * or the compilation of B do the actual instantiation?
- *
- * see bugzilla 2500.
- */
- && !scx->module->selfImports()
+ /* The problem is if A imports B, and B imports A, and both A
+ * and B instantiate the same template, does the compilation of A
+ * or the compilation of B do the actual instantiation?
+ *
+ * see bugzilla 2500.
+ */
+ && !scx->module->selfImports()
#endif
- )
- {
- //printf("\t1: adding to %s %s\n", scx->scopesym->kind(), scx->scopesym->toChars());
- a = scx->scopesym->members;
- }
- else
- { Module *m = sc->module->importedFrom;
- //printf("\t2: adding to module %s instead of module %s\n", m->toChars(), sc->module->toChars());
- a = m->members;
- if (m->semanticRun >= 3)
- dosemantic3 = 1;
- }
- for (int i = 0; 1; i++)
- {
- if (i == a->dim)
- {
- a->push(this);
- break;
- }
- if (this == (Dsymbol *)a->data[i]) // if already in Array
- break;
- }
+ )
+ {
+ //printf("\t1: adding to %s %s\n", scx->scopesym->kind(), scx->scopesym->toChars());
+ a = scx->scopesym->members;
+ }
+ else
+ { Module *m = sc->module->importedFrom;
+ //printf("\t2: adding to module %s instead of module %s\n", m->toChars(), sc->module->toChars());
+ a = m->members;
+ if (m->semanticRun >= 3)
+ dosemantic3 = 1;
+ }
+ for (int i = 0; 1; i++)
+ {
+ if (i == a->dim)
+ {
+ a->push(this);
+ break;
+ }
+ if (this == (Dsymbol *)a->data[i]) // if already in Array
+ break;
+ }
}
#endif
@@ -3370,8 +3370,8 @@ void TemplateInstance::semantic(Scope *sc)
Scope *scope = tempdecl->scope;
if (!tempdecl->semanticRun)
{
- error("template instantiation %s forward references template declaration %s\n", toChars(), tempdecl->toChars());
- return;
+ error("template instantiation %s forward references template declaration %s\n", toChars(), tempdecl->toChars());
+ return;
}
#if LOG
@@ -3393,11 +3393,11 @@ void TemplateInstance::semantic(Scope *sc)
int memnum = 0;
for (int i = 0; i < members->dim; i++)
{
- Dsymbol *s = (Dsymbol *)members->data[i];
+ Dsymbol *s = (Dsymbol *)members->data[i];
#if LOG
- printf("\t[%d] adding member '%s' %p kind %s to '%s', memnum = %d\n", i, s->toChars(), s, s->kind(), this->toChars(), memnum);
+ printf("\t[%d] adding member '%s' %p kind %s to '%s', memnum = %d\n", i, s->toChars(), s, s->kind(), this->toChars(), memnum);
#endif
- memnum |= s->addMember(scope, this, memnum);
+ memnum |= s->addMember(scope, this, memnum);
}
#if LOG
printf("adding members done\n");
@@ -3410,16 +3410,16 @@ void TemplateInstance::semantic(Scope *sc)
//printf("members->dim = %d\n", members->dim);
if (members->dim)
{
- Dsymbol *s;
- if (Dsymbol::oneMembers(members, &s) && s)
- {
- //printf("s->kind = '%s'\n", s->kind());
- //s->print();
- //printf("'%s', '%s'\n", s->ident->toChars(), tempdecl->ident->toChars());
- if (s->ident && s->ident->equals(tempdecl->ident))
- {
- //printf("setting aliasdecl\n");
- aliasdecl = new AliasDeclaration(loc, s->ident, s);
+ Dsymbol *s;
+ if (Dsymbol::oneMembers(members, &s) && s)
+ {
+ //printf("s->kind = '%s'\n", s->kind());
+ //s->print();
+ //printf("'%s', '%s'\n", s->ident->toChars(), tempdecl->ident->toChars());
+ if (s->ident && s->ident->equals(tempdecl->ident))
+ {
+ //printf("setting aliasdecl\n");
+ aliasdecl = new AliasDeclaration(loc, s->ident, s);
#if IN_LLVM
// LDC propagate internal information
@@ -3430,8 +3430,8 @@ void TemplateInstance::semantic(Scope *sc)
}
}
#endif
- }
- }
+ }
+ }
}
// Do semantic() analysis on template instance members
@@ -3452,28 +3452,28 @@ void TemplateInstance::semantic(Scope *sc)
//printf("%d\n", nest);
if (++nest > 500)
{
- global.gag = 0; // ensure error message gets printed
- error("recursive expansion");
- fatal();
+ global.gag = 0; // ensure error message gets printed
+ error("recursive expansion");
+ fatal();
}
for (int i = 0; i < members->dim; i++)
{
- Dsymbol *s = (Dsymbol *)members->data[i];
- //printf("\t[%d] semantic on '%s' %p kind %s in '%s'\n", i, s->toChars(), s, s->kind(), this->toChars());
- //printf("test: isnested = %d, sc2->parent = %s\n", isnested, sc2->parent->toChars());
-// if (isnested)
-// s->parent = sc->parent;
- //printf("test3: isnested = %d, s->parent = %s\n", isnested, s->parent->toChars());
- s->semantic(sc2);
- //printf("test4: isnested = %d, s->parent = %s\n", isnested, s->parent->toChars());
- sc2->module->runDeferredSemantic();
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ //printf("\t[%d] semantic on '%s' %p kind %s in '%s'\n", i, s->toChars(), s, s->kind(), this->toChars());
+ //printf("test: isnested = %d, sc2->parent = %s\n", isnested, sc2->parent->toChars());
+// if (isnested)
+// s->parent = sc->parent;
+ //printf("test3: isnested = %d, s->parent = %s\n", isnested, s->parent->toChars());
+ s->semantic(sc2);
+ //printf("test4: isnested = %d, s->parent = %s\n", isnested, s->parent->toChars());
+ sc2->module->runDeferredSemantic();
}
--nest;
#if WINDOWS_SEH
}
__except (__ehfilter(GetExceptionInformation()))
{
- global.gag = 0; // ensure error message gets printed
+ global.gag = 0; // ensure error message gets printed
error("recursive expansion");
fatal();
}
@@ -3484,10 +3484,10 @@ void TemplateInstance::semantic(Scope *sc)
* or semantic3() yet.
*/
for (size_t i = 0; i < Module::deferred.dim; i++)
- { Dsymbol *sd = (Dsymbol *)Module::deferred.data[i];
+ { Dsymbol *sd = (Dsymbol *)Module::deferred.data[i];
- if (sd->parent == this)
- goto Laftersemantic;
+ if (sd->parent == this)
+ goto Laftersemantic;
}
/* The problem is when to parse the initializer for a variable.
@@ -3496,35 +3496,35 @@ void TemplateInstance::semantic(Scope *sc)
*/
// if (sc->parent->isFuncDeclaration())
- /* BUG 782: this has problems if the classes this depends on
- * are forward referenced. Find a way to defer semantic()
- * on this template.
- */
- semantic2(sc2);
+ /* BUG 782: this has problems if the classes this depends on
+ * are forward referenced. Find a way to defer semantic()
+ * on this template.
+ */
+ semantic2(sc2);
if (sc->func || dosemantic3)
{
#if WINDOWS_SEH
- __try
- {
+ __try
+ {
#endif
- static int nest;
- if (++nest > 300)
- {
- global.gag = 0; // ensure error message gets printed
- error("recursive expansion");
- fatal();
- }
- semantic3(sc2);
- --nest;
+ static int nest;
+ if (++nest > 300)
+ {
+ global.gag = 0; // ensure error message gets printed
+ error("recursive expansion");
+ fatal();
+ }
+ semantic3(sc2);
+ --nest;
#if WINDOWS_SEH
- }
- __except (__ehfilter(GetExceptionInformation()))
- {
- global.gag = 0; // ensure error message gets printed
- error("recursive expansion");
- fatal();
- }
+ }
+ __except (__ehfilter(GetExceptionInformation()))
+ {
+ global.gag = 0; // ensure error message gets printed
+ error("recursive expansion");
+ fatal();
+ }
#endif
}
@@ -3536,15 +3536,15 @@ void TemplateInstance::semantic(Scope *sc)
// Give additional context info if error occurred during instantiation
if (global.errors != errorsave)
{
- error("error instantiating");
- if (tinst)
- { tinst->printInstantiationTrace();
- if (!global.gag)
- fatal();
- }
- errors = 1;
- if (global.gag)
- tempdecl->instances.remove(tempdecl_instance_idx);
+ error("error instantiating");
+ if (tinst)
+ { tinst->printInstantiationTrace();
+ if (!global.gag)
+ fatal();
+ }
+ errors = 1;
+ if (global.gag)
+ tempdecl->instances.remove(tempdecl_instance_idx);
}
#if LOG
@@ -3557,14 +3557,14 @@ void TemplateInstance::semanticTiargs(Scope *sc)
{
//printf("+TemplateInstance::semanticTiargs() %s\n", toChars());
if (semantictiargsdone)
- return;
+ return;
semantictiargsdone = 1;
semanticTiargs(loc, sc, tiargs, 0);
}
/**********************************
* Input:
- * flags 1: replace const variables with their initializers
+ * flags 1: replace const variables with their initializers
*/
void TemplateInstance::semanticTiargs(Loc loc, Scope *sc, Objects *tiargs, int flags)
@@ -3572,110 +3572,110 @@ void TemplateInstance::semanticTiargs(Loc loc, Scope *sc, Objects *tiargs, int f
// Run semantic on each argument, place results in tiargs[]
//printf("+TemplateInstance::semanticTiargs() %s\n", toChars());
if (!tiargs)
- return;
+ return;
for (size_t j = 0; j < tiargs->dim; j++)
{
- Object *o = (Object *)tiargs->data[j];
- Type *ta = isType(o);
- Expression *ea = isExpression(o);
- Dsymbol *sa = isDsymbol(o);
+ Object *o = (Object *)tiargs->data[j];
+ Type *ta = isType(o);
+ Expression *ea = isExpression(o);
+ Dsymbol *sa = isDsymbol(o);
- //printf("1: tiargs->data[%d] = %p, %p, %p, ea=%p, ta=%p\n", j, o, isDsymbol(o), isTuple(o), ea, ta);
- if (ta)
- {
- //printf("type %s\n", ta->toChars());
- // It might really be an Expression or an Alias
- ta->resolve(loc, sc, &ea, &ta, &sa);
- if (ea)
- {
- ea = ea->semantic(sc);
- ea = ea->optimize(WANTvalue | WANTinterpret);
- tiargs->data[j] = ea;
- }
- else if (sa)
- { tiargs->data[j] = sa;
- TupleDeclaration *d = sa->toAlias()->isTupleDeclaration();
- if (d)
- {
- size_t dim = d->objects->dim;
- tiargs->remove(j);
- tiargs->insert(j, d->objects);
- j--;
- }
- }
- else if (ta)
- {
- Ltype:
- if (ta->ty == Ttuple)
- { // Expand tuple
- TypeTuple *tt = (TypeTuple *)ta;
- size_t dim = tt->arguments->dim;
- tiargs->remove(j);
- if (dim)
- { tiargs->reserve(dim);
- for (size_t i = 0; i < dim; i++)
- { Parameter *arg = (Parameter *)tt->arguments->data[i];
- tiargs->insert(j + i, arg->type);
- }
- }
- j--;
- }
- else
- tiargs->data[j] = ta;
- }
- else
- {
- assert(global.errors);
- tiargs->data[j] = Type::terror;
- }
- }
- else if (ea)
- {
- if (!ea)
- { assert(global.errors);
- ea = new IntegerExp(0);
- }
- assert(ea);
- ea = ea->semantic(sc);
- ea = ea->optimize(WANTvalue | WANTinterpret);
- tiargs->data[j] = ea;
- if (ea->op == TOKtype)
- { ta = ea->type;
- goto Ltype;
- }
- if (ea->op == TOKtuple)
- { // Expand tuple
- TupleExp *te = (TupleExp *)ea;
- size_t dim = te->exps->dim;
- tiargs->remove(j);
- if (dim)
- { tiargs->reserve(dim);
- for (size_t i = 0; i < dim; i++)
- tiargs->insert(j + i, te->exps->data[i]);
- }
- j--;
- }
- }
- else if (sa)
- {
- }
- else
- {
- assert(0);
- }
- //printf("1: tiargs->data[%d] = %p\n", j, tiargs->data[j]);
+ //printf("1: tiargs->data[%d] = %p, %p, %p, ea=%p, ta=%p\n", j, o, isDsymbol(o), isTuple(o), ea, ta);
+ if (ta)
+ {
+ //printf("type %s\n", ta->toChars());
+ // It might really be an Expression or an Alias
+ ta->resolve(loc, sc, &ea, &ta, &sa);
+ if (ea)
+ {
+ ea = ea->semantic(sc);
+ ea = ea->optimize(WANTvalue | WANTinterpret);
+ tiargs->data[j] = ea;
+ }
+ else if (sa)
+ { tiargs->data[j] = sa;
+ TupleDeclaration *d = sa->toAlias()->isTupleDeclaration();
+ if (d)
+ {
+ size_t dim = d->objects->dim;
+ tiargs->remove(j);
+ tiargs->insert(j, d->objects);
+ j--;
+ }
+ }
+ else if (ta)
+ {
+ Ltype:
+ if (ta->ty == Ttuple)
+ { // Expand tuple
+ TypeTuple *tt = (TypeTuple *)ta;
+ size_t dim = tt->arguments->dim;
+ tiargs->remove(j);
+ if (dim)
+ { tiargs->reserve(dim);
+ for (size_t i = 0; i < dim; i++)
+ { Parameter *arg = (Parameter *)tt->arguments->data[i];
+ tiargs->insert(j + i, arg->type);
+ }
+ }
+ j--;
+ }
+ else
+ tiargs->data[j] = ta;
+ }
+ else
+ {
+ assert(global.errors);
+ tiargs->data[j] = Type::terror;
+ }
+ }
+ else if (ea)
+ {
+ if (!ea)
+ { assert(global.errors);
+ ea = new IntegerExp(0);
+ }
+ assert(ea);
+ ea = ea->semantic(sc);
+ ea = ea->optimize(WANTvalue | WANTinterpret);
+ tiargs->data[j] = ea;
+ if (ea->op == TOKtype)
+ { ta = ea->type;
+ goto Ltype;
+ }
+ if (ea->op == TOKtuple)
+ { // Expand tuple
+ TupleExp *te = (TupleExp *)ea;
+ size_t dim = te->exps->dim;
+ tiargs->remove(j);
+ if (dim)
+ { tiargs->reserve(dim);
+ for (size_t i = 0; i < dim; i++)
+ tiargs->insert(j + i, te->exps->data[i]);
+ }
+ j--;
+ }
+ }
+ else if (sa)
+ {
+ }
+ else
+ {
+ assert(0);
+ }
+ //printf("1: tiargs->data[%d] = %p\n", j, tiargs->data[j]);
}
#if 0
printf("-TemplateInstance::semanticTiargs('%s', this=%p)\n", toChars(), this);
for (size_t j = 0; j < tiargs->dim; j++)
{
- Object *o = (Object *)tiargs->data[j];
- Type *ta = isType(o);
- Expression *ea = isExpression(o);
- Dsymbol *sa = isDsymbol(o);
- Tuple *va = isTuple(o);
+ Object *o = (Object *)tiargs->data[j];
+ Type *ta = isType(o);
+ Expression *ea = isExpression(o);
+ Dsymbol *sa = isDsymbol(o);
+ Tuple *va = isTuple(o);
- printf("\ttiargs[%d] = ta %p, ea %p, sa %p, va %p\n", j, ta, ea, sa, va);
+ printf("\ttiargs[%d] = ta %p, ea %p, sa %p, va %p\n", j, ta, ea, sa, va);
}
#endif
}
@@ -3689,103 +3689,103 @@ TemplateDeclaration *TemplateInstance::findTemplateDeclaration(Scope *sc)
//printf("TemplateInstance::findTemplateDeclaration() %s\n", toChars());
if (!tempdecl)
{
- /* Given:
- * foo!( ... )
- * figure out which TemplateDeclaration foo refers to.
- */
- Dsymbol *s;
- Dsymbol *scopesym;
- Identifier *id;
- int i;
+ /* Given:
+ * foo!( ... )
+ * figure out which TemplateDeclaration foo refers to.
+ */
+ Dsymbol *s;
+ Dsymbol *scopesym;
+ Identifier *id;
+ int i;
- id = name;
- s = sc->search(loc, id, &scopesym);
- if (!s)
- {
- s = sc->search_correct(id);
- if (s)
- error("template '%s' is not defined, did you mean %s?", id->toChars(), s->toChars());
- else
- error("template '%s' is not defined", id->toChars());
- return NULL;
- }
+ id = name;
+ s = sc->search(loc, id, &scopesym);
+ if (!s)
+ {
+ s = sc->search_correct(id);
+ if (s)
+ error("template '%s' is not defined, did you mean %s?", id->toChars(), s->toChars());
+ else
+ error("template '%s' is not defined", id->toChars());
+ return NULL;
+ }
#if LOG
- printf("It's an instance of '%s' kind '%s'\n", s->toChars(), s->kind());
- if (s->parent)
- printf("s->parent = '%s'\n", s->parent->toChars());
+ printf("It's an instance of '%s' kind '%s'\n", s->toChars(), s->kind());
+ if (s->parent)
+ printf("s->parent = '%s'\n", s->parent->toChars());
#endif
- withsym = scopesym->isWithScopeSymbol();
+ withsym = scopesym->isWithScopeSymbol();
- /* We might have found an alias within a template when
- * we really want the template.
- */
- TemplateInstance *ti;
- if (s->parent &&
- (ti = s->parent->isTemplateInstance()) != NULL)
- {
- if (
- (ti->name == id ||
- ti->toAlias()->ident == id)
- &&
- ti->tempdecl)
- {
- /* This is so that one can refer to the enclosing
- * template, even if it has the same name as a member
- * of the template, if it has a !(arguments)
- */
- tempdecl = ti->tempdecl;
- if (tempdecl->overroot) // if not start of overloaded list of TemplateDeclaration's
- tempdecl = tempdecl->overroot; // then get the start
- s = tempdecl;
- }
- }
+ /* We might have found an alias within a template when
+ * we really want the template.
+ */
+ TemplateInstance *ti;
+ if (s->parent &&
+ (ti = s->parent->isTemplateInstance()) != NULL)
+ {
+ if (
+ (ti->name == id ||
+ ti->toAlias()->ident == id)
+ &&
+ ti->tempdecl)
+ {
+ /* This is so that one can refer to the enclosing
+ * template, even if it has the same name as a member
+ * of the template, if it has a !(arguments)
+ */
+ tempdecl = ti->tempdecl;
+ if (tempdecl->overroot) // if not start of overloaded list of TemplateDeclaration's
+ tempdecl = tempdecl->overroot; // then get the start
+ s = tempdecl;
+ }
+ }
- s = s->toAlias();
+ s = s->toAlias();
- /* It should be a TemplateDeclaration, not some other symbol
- */
- tempdecl = s->isTemplateDeclaration();
- if (!tempdecl)
- {
- if (!s->parent && global.errors)
- return NULL;
- if (!s->parent && s->getType())
- { Dsymbol *s2 = s->getType()->toDsymbol(sc);
- if (!s2)
- {
- error("%s is not a template declaration, it is a %s", id->toChars(), s->kind());
- return NULL;
- }
- s = s2;
- }
+ /* It should be a TemplateDeclaration, not some other symbol
+ */
+ tempdecl = s->isTemplateDeclaration();
+ if (!tempdecl)
+ {
+ if (!s->parent && global.errors)
+ return NULL;
+ if (!s->parent && s->getType())
+ { Dsymbol *s2 = s->getType()->toDsymbol(sc);
+ if (!s2)
+ {
+ error("%s is not a template declaration, it is a %s", id->toChars(), s->kind());
+ return NULL;
+ }
+ s = s2;
+ }
#ifdef DEBUG
- //if (!s->parent) printf("s = %s %s\n", s->kind(), s->toChars());
+ //if (!s->parent) printf("s = %s %s\n", s->kind(), s->toChars());
#endif
- //assert(s->parent);
- TemplateInstance *ti = s->parent ? s->parent->isTemplateInstance() : NULL;
- if (ti &&
- (ti->name == id ||
- ti->toAlias()->ident == id)
- &&
- ti->tempdecl)
- {
- /* This is so that one can refer to the enclosing
- * template, even if it has the same name as a member
- * of the template, if it has a !(arguments)
- */
- tempdecl = ti->tempdecl;
- if (tempdecl->overroot) // if not start of overloaded list of TemplateDeclaration's
- tempdecl = tempdecl->overroot; // then get the start
- }
- else
- {
- error("%s is not a template declaration, it is a %s", id->toChars(), s->kind());
- return NULL;
- }
- }
+ //assert(s->parent);
+ TemplateInstance *ti = s->parent ? s->parent->isTemplateInstance() : NULL;
+ if (ti &&
+ (ti->name == id ||
+ ti->toAlias()->ident == id)
+ &&
+ ti->tempdecl)
+ {
+ /* This is so that one can refer to the enclosing
+ * template, even if it has the same name as a member
+ * of the template, if it has a !(arguments)
+ */
+ tempdecl = ti->tempdecl;
+ if (tempdecl->overroot) // if not start of overloaded list of TemplateDeclaration's
+ tempdecl = tempdecl->overroot; // then get the start
+ }
+ else
+ {
+ error("%s is not a template declaration, it is a %s", id->toChars(), s->kind());
+ return NULL;
+ }
+ }
}
else
- assert(tempdecl->isTemplateDeclaration());
+ assert(tempdecl->isTemplateDeclaration());
return tempdecl;
}
@@ -3805,91 +3805,91 @@ TemplateDeclaration *TemplateInstance::findBestMatch(Scope *sc)
// First look for forward references
for (TemplateDeclaration *td = tempdecl; td; td = td->overnext)
{
- if (!td->semanticRun)
- {
- if (td->scope)
- { // Try to fix forward reference
- td->semantic(td->scope);
- }
- if (!td->semanticRun)
- {
- error("%s forward references template declaration %s\n", toChars(), td->toChars());
- return NULL;
- }
- }
+ if (!td->semanticRun)
+ {
+ if (td->scope)
+ { // Try to fix forward reference
+ td->semantic(td->scope);
+ }
+ if (!td->semanticRun)
+ {
+ error("%s forward references template declaration %s\n", toChars(), td->toChars());
+ return NULL;
+ }
+ }
}
for (TemplateDeclaration *td = tempdecl; td; td = td->overnext)
{
- MATCH m;
+ MATCH m;
//if (tiargs->dim) printf("2: tiargs->dim = %d, data[0] = %p\n", tiargs->dim, tiargs->data[0]);
- // If more arguments than parameters,
- // then this is no match.
- if (td->parameters->dim < tiargs->dim)
- {
- if (!td->isVariadic())
- continue;
- }
+ // If more arguments than parameters,
+ // then this is no match.
+ if (td->parameters->dim < tiargs->dim)
+ {
+ if (!td->isVariadic())
+ continue;
+ }
- dedtypes.setDim(td->parameters->dim);
- dedtypes.zero();
- assert(td->semanticRun);
- m = td->matchWithInstance(this, &dedtypes, 0);
- //printf("matchWithInstance = %d\n", m);
- if (!m) // no match at all
- continue;
+ dedtypes.setDim(td->parameters->dim);
+ dedtypes.zero();
+ assert(td->semanticRun);
+ m = td->matchWithInstance(this, &dedtypes, 0);
+ //printf("matchWithInstance = %d\n", m);
+ if (!m) // no match at all
+ continue;
- if (m < m_best)
- goto Ltd_best;
- if (m > m_best)
- goto Ltd;
+ if (m < m_best)
+ goto Ltd_best;
+ if (m > m_best)
+ goto Ltd;
- {
- // Disambiguate by picking the most specialized TemplateDeclaration
- MATCH c1 = td->leastAsSpecialized(td_best);
- MATCH c2 = td_best->leastAsSpecialized(td);
- //printf("c1 = %d, c2 = %d\n", c1, c2);
+ {
+ // Disambiguate by picking the most specialized TemplateDeclaration
+ MATCH c1 = td->leastAsSpecialized(td_best);
+ MATCH c2 = td_best->leastAsSpecialized(td);
+ //printf("c1 = %d, c2 = %d\n", c1, c2);
- if (c1 > c2)
- goto Ltd;
- else if (c1 < c2)
- goto Ltd_best;
- else
- goto Lambig;
- }
+ if (c1 > c2)
+ goto Ltd;
+ else if (c1 < c2)
+ goto Ltd_best;
+ else
+ goto Lambig;
+ }
- Lambig: // td_best and td are ambiguous
- td_ambig = td;
- continue;
+ Lambig: // td_best and td are ambiguous
+ td_ambig = td;
+ continue;
- Ltd_best: // td_best is the best match so far
- td_ambig = NULL;
- continue;
+ Ltd_best: // td_best is the best match so far
+ td_ambig = NULL;
+ continue;
- Ltd: // td is the new best match
- td_ambig = NULL;
- td_best = td;
- m_best = m;
- tdtypes.setDim(dedtypes.dim);
- memcpy(tdtypes.data, dedtypes.data, tdtypes.dim * sizeof(void *));
- continue;
+ Ltd: // td is the new best match
+ td_ambig = NULL;
+ td_best = td;
+ m_best = m;
+ tdtypes.setDim(dedtypes.dim);
+ memcpy(tdtypes.data, dedtypes.data, tdtypes.dim * sizeof(void *));
+ continue;
}
if (!td_best)
{
- if (tempdecl && !tempdecl->overnext)
- // Only one template, so we can give better error message
- error("%s does not match template declaration %s", toChars(), tempdecl->toChars());
- else
- error("%s does not match any template declaration", toChars());
- return NULL;
+ if (tempdecl && !tempdecl->overnext)
+ // Only one template, so we can give better error message
+ error("%s does not match template declaration %s", toChars(), tempdecl->toChars());
+ else
+ error("%s does not match any template declaration", toChars());
+ return NULL;
}
if (td_ambig)
{
- error("%s matches more than one template declaration, %s and %s",
- toChars(), td_best->toChars(), td_ambig->toChars());
+ error("%s matches more than one template declaration, %s and %s",
+ toChars(), td_best->toChars(), td_ambig->toChars());
}
/* The best match is td_best
@@ -3900,18 +3900,18 @@ TemplateDeclaration *TemplateInstance::findBestMatch(Scope *sc)
/* Cast any value arguments to be same type as value parameter
*/
for (size_t i = 0; i < tiargs->dim; i++)
- { Object *o = (Object *)tiargs->data[i];
- Expression *ea = isExpression(o); // value argument
- TemplateParameter *tp = (TemplateParameter *)tempdecl->parameters->data[i];
- assert(tp);
- TemplateValueParameter *tvp = tp->isTemplateValueParameter();
- if (tvp)
- {
- assert(ea);
- ea = ea->castTo(tvp->valType);
- ea = ea->optimize(WANTvalue | WANTinterpret);
- tiargs->data[i] = (Object *)ea;
- }
+ { Object *o = (Object *)tiargs->data[i];
+ Expression *ea = isExpression(o); // value argument
+ TemplateParameter *tp = (TemplateParameter *)tempdecl->parameters->data[i];
+ assert(tp);
+ TemplateValueParameter *tvp = tp->isTemplateValueParameter();
+ if (tvp)
+ {
+ assert(ea);
+ ea = ea->castTo(tvp->valType);
+ ea = ea->optimize(WANTvalue | WANTinterpret);
+ tiargs->data[i] = (Object *)ea;
+ }
}
#endif
@@ -3936,70 +3936,70 @@ int TemplateInstance::hasNestedArgs(Objects *args)
*/
for (size_t i = 0; i < args->dim; i++)
{ Object *o = (Object *)args->data[i];
- Expression *ea = isExpression(o);
- Dsymbol *sa = isDsymbol(o);
- Tuple *va = isTuple(o);
- if (ea)
- {
- if (ea->op == TOKvar)
- {
- sa = ((VarExp *)ea)->var;
- goto Lsa;
- }
- if (ea->op == TOKfunction)
- {
- sa = ((FuncExp *)ea)->fd;
- goto Lsa;
- }
- }
- else if (sa)
- {
- Lsa:
- Declaration *d = sa->isDeclaration();
- if (d && !d->isDataseg() &&
+ Expression *ea = isExpression(o);
+ Dsymbol *sa = isDsymbol(o);
+ Tuple *va = isTuple(o);
+ if (ea)
+ {
+ if (ea->op == TOKvar)
+ {
+ sa = ((VarExp *)ea)->var;
+ goto Lsa;
+ }
+ if (ea->op == TOKfunction)
+ {
+ sa = ((FuncExp *)ea)->fd;
+ goto Lsa;
+ }
+ }
+ else if (sa)
+ {
+ Lsa:
+ Declaration *d = sa->isDeclaration();
+ if (d && !d->isDataseg() &&
#if DMDV2
- !(d->storage_class & STCmanifest) &&
+ !(d->storage_class & STCmanifest) &&
#endif
- (!d->isFuncDeclaration() || d->isFuncDeclaration()->isNested()) &&
- !isTemplateMixin())
- {
- // if module level template
- if (tempdecl->toParent()->isModule())
- { Dsymbol *dparent = d->toParent();
- if (!isnested)
- isnested = dparent;
- else if (isnested != dparent)
- {
- /* Select the more deeply nested of the two.
- * Error if one is not nested inside the other.
- */
- for (Dsymbol *p = isnested; p; p = p->parent)
- {
- if (p == dparent)
- goto L1; // isnested is most nested
- }
- for (Dsymbol *p = dparent; p; p = p->parent)
- {
- if (p == isnested)
- { isnested = dparent;
- goto L1; // dparent is most nested
- }
- }
- error("%s is nested in both %s and %s",
- toChars(), isnested->toChars(), dparent->toChars());
- }
- L1:
- //printf("\tnested inside %s\n", isnested->toChars());
- nested |= 1;
- }
- else
- error("cannot use local '%s' as parameter to non-global template %s", d->toChars(), tempdecl->toChars());
- }
- }
- else if (va)
- {
- nested |= hasNestedArgs(&va->objects);
- }
+ (!d->isFuncDeclaration() || d->isFuncDeclaration()->isNested()) &&
+ !isTemplateMixin())
+ {
+ // if module level template
+ if (tempdecl->toParent()->isModule())
+ { Dsymbol *dparent = d->toParent();
+ if (!isnested)
+ isnested = dparent;
+ else if (isnested != dparent)
+ {
+ /* Select the more deeply nested of the two.
+ * Error if one is not nested inside the other.
+ */
+ for (Dsymbol *p = isnested; p; p = p->parent)
+ {
+ if (p == dparent)
+ goto L1; // isnested is most nested
+ }
+ for (Dsymbol *p = dparent; p; p = p->parent)
+ {
+ if (p == isnested)
+ { isnested = dparent;
+ goto L1; // dparent is most nested
+ }
+ }
+ error("%s is nested in both %s and %s",
+ toChars(), isnested->toChars(), dparent->toChars());
+ }
+ L1:
+ //printf("\tnested inside %s\n", isnested->toChars());
+ nested |= 1;
+ }
+ else
+ error("cannot use local '%s' as parameter to non-global template %s", d->toChars(), tempdecl->toChars());
+ }
+ }
+ else if (va)
+ {
+ nested |= hasNestedArgs(&va->objects);
+ }
}
return nested;
}
@@ -4019,81 +4019,81 @@ Identifier *TemplateInstance::genIdent()
Objects *args = tiargs;
for (int i = 0; i < args->dim; i++)
{ Object *o = (Object *)args->data[i];
- Type *ta = isType(o);
- Expression *ea = isExpression(o);
- Dsymbol *sa = isDsymbol(o);
- Tuple *va = isTuple(o);
- //printf("\to [%d] %p ta %p ea %p sa %p va %p\n", i, o, ta, ea, sa, va);
- if (ta)
- {
- buf.writeByte('T');
- if (ta->deco)
- buf.writestring(ta->deco);
- else
- {
+ Type *ta = isType(o);
+ Expression *ea = isExpression(o);
+ Dsymbol *sa = isDsymbol(o);
+ Tuple *va = isTuple(o);
+ //printf("\to [%d] %p ta %p ea %p sa %p va %p\n", i, o, ta, ea, sa, va);
+ if (ta)
+ {
+ buf.writeByte('T');
+ if (ta->deco)
+ buf.writestring(ta->deco);
+ else
+ {
#ifdef DEBUG
- printf("ta = %d, %s\n", ta->ty, ta->toChars());
+ printf("ta = %d, %s\n", ta->ty, ta->toChars());
#endif
- assert(global.errors);
- }
- }
- else if (ea)
- { sinteger_t v;
- real_t r;
+ assert(global.errors);
+ }
+ }
+ else if (ea)
+ { sinteger_t v;
+ real_t r;
- ea = ea->optimize(WANTvalue | WANTinterpret);
- if (ea->op == TOKvar)
- {
- sa = ((VarExp *)ea)->var;
- ea = NULL;
- goto Lsa;
- }
- if (ea->op == TOKfunction)
- {
- sa = ((FuncExp *)ea)->fd;
- ea = NULL;
- goto Lsa;
- }
- buf.writeByte('V');
- if (ea->op == TOKtuple)
- { ea->error("tuple is not a valid template value argument");
- continue;
- }
+ ea = ea->optimize(WANTvalue | WANTinterpret);
+ if (ea->op == TOKvar)
+ {
+ sa = ((VarExp *)ea)->var;
+ ea = NULL;
+ goto Lsa;
+ }
+ if (ea->op == TOKfunction)
+ {
+ sa = ((FuncExp *)ea)->fd;
+ ea = NULL;
+ goto Lsa;
+ }
+ buf.writeByte('V');
+ if (ea->op == TOKtuple)
+ { ea->error("tuple is not a valid template value argument");
+ continue;
+ }
#if 1
- /* Use deco that matches what it would be for a function parameter
- */
- buf.writestring(ea->type->deco);
+ /* Use deco that matches what it would be for a function parameter
+ */
+ buf.writestring(ea->type->deco);
#else
- // Use type of parameter, not type of argument
- TemplateParameter *tp = (TemplateParameter *)tempdecl->parameters->data[i];
- assert(tp);
- TemplateValueParameter *tvp = tp->isTemplateValueParameter();
- assert(tvp);
- buf.writestring(tvp->valType->deco);
+ // Use type of parameter, not type of argument
+ TemplateParameter *tp = (TemplateParameter *)tempdecl->parameters->data[i];
+ assert(tp);
+ TemplateValueParameter *tvp = tp->isTemplateValueParameter();
+ assert(tvp);
+ buf.writestring(tvp->valType->deco);
#endif
- ea->toMangleBuffer(&buf);
- }
- else if (sa)
- {
- Lsa:
- buf.writeByte('S');
- Declaration *d = sa->isDeclaration();
- if (d && (!d->type || !d->type->deco))
- error("forward reference of %s", d->toChars());
- else
- {
- char *p = sa->mangle();
- buf.printf("%zu%s", strlen(p), p);
- }
- }
- else if (va)
- {
- assert(i + 1 == args->dim); // must be last one
- args = &va->objects;
- i = -1;
- }
- else
- assert(0);
+ ea->toMangleBuffer(&buf);
+ }
+ else if (sa)
+ {
+ Lsa:
+ buf.writeByte('S');
+ Declaration *d = sa->isDeclaration();
+ if (d && (!d->type || !d->type->deco))
+ error("forward reference of %s", d->toChars());
+ else
+ {
+ char *p = sa->mangle();
+ buf.printf("%zu%s", strlen(p), p);
+ }
+ }
+ else if (va)
+ {
+ assert(i + 1 == args->dim); // must be last one
+ args = &va->objects;
+ i = -1;
+ }
+ else
+ assert(0);
}
buf.writeByte('Z');
id = buf.toChars();
@@ -4113,12 +4113,12 @@ void TemplateInstance::declareParameters(Scope *sc)
//printf("TemplateInstance::declareParameters()\n");
for (int i = 0; i < tdtypes.dim; i++)
{
- TemplateParameter *tp = (TemplateParameter *)tempdecl->parameters->data[i];
- //Object *o = (Object *)tiargs->data[i];
- Object *o = (Object *)tdtypes.data[i]; // initializer for tp
+ TemplateParameter *tp = (TemplateParameter *)tempdecl->parameters->data[i];
+ //Object *o = (Object *)tiargs->data[i];
+ Object *o = (Object *)tdtypes.data[i]; // initializer for tp
- //printf("\ttdtypes[%d] = %p\n", i, o);
- tempdecl->declareParameter(sc, tp, o);
+ //printf("\ttdtypes[%d] = %p\n", i, o);
+ tempdecl->declareParameter(sc, tp, o);
}
}
@@ -4133,32 +4133,32 @@ int TemplateInstance::needsTypeInference(Scope *sc)
{
//printf("TemplateInstance::needsTypeInference() %s\n", toChars());
if (!tempdecl)
- tempdecl = findTemplateDeclaration(sc);
+ tempdecl = findTemplateDeclaration(sc);
for (TemplateDeclaration *td = tempdecl; td; td = td->overnext)
{
- /* If any of the overloaded template declarations need inference,
- * then return TRUE
- */
- FuncDeclaration *fd;
- if (!td->onemember ||
- (fd = td->onemember->toAlias()->isFuncDeclaration()) == NULL ||
- fd->type->ty != Tfunction)
- {
- /* Not a template function, therefore type inference is not possible.
- */
- //printf("false\n");
- return FALSE;
- }
+ /* If any of the overloaded template declarations need inference,
+ * then return TRUE
+ */
+ FuncDeclaration *fd;
+ if (!td->onemember ||
+ (fd = td->onemember->toAlias()->isFuncDeclaration()) == NULL ||
+ fd->type->ty != Tfunction)
+ {
+ /* Not a template function, therefore type inference is not possible.
+ */
+ //printf("false\n");
+ return FALSE;
+ }
- /* Determine if the instance arguments, tiargs, are all that is necessary
- * to instantiate the template.
- */
- TemplateTupleParameter *tp = td->isVariadic();
- //printf("tp = %p, td->parameters->dim = %d, tiargs->dim = %d\n", tp, td->parameters->dim, tiargs->dim);
- TypeFunction *fdtype = (TypeFunction *)fd->type;
- if (Parameter::dim(fdtype->parameters) &&
- (tp || tiargs->dim < td->parameters->dim))
- return TRUE;
+ /* Determine if the instance arguments, tiargs, are all that is necessary
+ * to instantiate the template.
+ */
+ TemplateTupleParameter *tp = td->isVariadic();
+ //printf("tp = %p, td->parameters->dim = %d, tiargs->dim = %d\n", tp, td->parameters->dim, tiargs->dim);
+ TypeFunction *fdtype = (TypeFunction *)fd->type;
+ if (Parameter::dim(fdtype->parameters) &&
+ (tp || tiargs->dim < td->parameters->dim))
+ return TRUE;
}
//printf("false\n");
return FALSE;
@@ -4168,28 +4168,28 @@ void TemplateInstance::semantic2(Scope *sc)
{ int i;
if (semanticRun >= 2)
- return;
+ return;
semanticRun = 2;
#if LOG
printf("+TemplateInstance::semantic2('%s')\n", toChars());
#endif
if (!errors && members)
{
- sc = tempdecl->scope;
- assert(sc);
- sc = sc->push(argsym);
- sc = sc->push(this);
- sc->tinst = this;
- for (i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
+ sc = tempdecl->scope;
+ assert(sc);
+ sc = sc->push(argsym);
+ sc = sc->push(this);
+ sc->tinst = this;
+ for (i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
#if LOG
printf("\tmember '%s', kind = '%s'\n", s->toChars(), s->kind());
#endif
- s->semantic2(sc);
- }
- sc = sc->pop();
- sc->pop();
+ s->semantic2(sc);
+ }
+ sc = sc->pop();
+ sc->pop();
}
#if LOG
printf("-TemplateInstance::semantic2('%s')\n", toChars());
@@ -4203,21 +4203,21 @@ void TemplateInstance::semantic3(Scope *sc)
#endif
//if (toChars()[0] == 'D') *(char*)0=0;
if (semanticRun >= 3)
- return;
+ return;
semanticRun = 3;
if (!errors && members)
{
- sc = tempdecl->scope;
- sc = sc->push(argsym);
- sc = sc->push(this);
- sc->tinst = this;
- for (int i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->semantic3(sc);
- }
- sc = sc->pop();
- sc->pop();
+ sc = tempdecl->scope;
+ sc = sc->push(argsym);
+ sc = sc->push(this);
+ sc->tinst = this;
+ for (int i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->semantic3(sc);
+ }
+ sc = sc->pop();
+ sc->pop();
}
}
@@ -4231,7 +4231,7 @@ void TemplateInstance::semantic3(Scope *sc)
void TemplateInstance::printInstantiationTrace()
{
if (global.gag)
- return;
+ return;
const int max_shown = 6;
const char format[] = "%s: instantiated from here: %s\n";
@@ -4241,62 +4241,62 @@ void TemplateInstance::printInstantiationTrace()
int n_totalrecursions = 0;
for (TemplateInstance *cur = this; cur; cur = cur->tinst)
{
- ++n_instantiations;
- // If two instantiations use the same declaration, they are recursive.
- // (this works even if they are instantiated from different places in the
- // same template).
- // In principle, we could also check for multiple-template recursion, but it's
- // probably not worthwhile.
- if (cur->tinst && cur->tempdecl && cur->tinst->tempdecl
- && cur->tempdecl->loc.equals(cur->tinst->tempdecl->loc))
- ++n_totalrecursions;
+ ++n_instantiations;
+ // If two instantiations use the same declaration, they are recursive.
+ // (this works even if they are instantiated from different places in the
+ // same template).
+ // In principle, we could also check for multiple-template recursion, but it's
+ // probably not worthwhile.
+ if (cur->tinst && cur->tempdecl && cur->tinst->tempdecl
+ && cur->tempdecl->loc.equals(cur->tinst->tempdecl->loc))
+ ++n_totalrecursions;
}
// show full trace only if it's short or verbose is on
if (n_instantiations <= max_shown || global.params.verbose)
{
- for (TemplateInstance *cur = this; cur; cur = cur->tinst)
- {
- fprintf(stdmsg, format, cur->loc.toChars(), cur->toChars());
- }
+ for (TemplateInstance *cur = this; cur; cur = cur->tinst)
+ {
+ fprintf(stdmsg, format, cur->loc.toChars(), cur->toChars());
+ }
}
else if (n_instantiations - n_totalrecursions <= max_shown)
{
- // By collapsing recursive instantiations into a single line,
- // we can stay under the limit.
- int recursionDepth=0;
- for (TemplateInstance *cur = this; cur; cur = cur->tinst)
- {
- if (cur->tinst && cur->tempdecl && cur->tinst->tempdecl
- && cur->tempdecl->loc.equals(cur->tinst->tempdecl->loc))
- {
- ++recursionDepth;
- }
- else
- {
- if (recursionDepth)
- fprintf(stdmsg, "%s: %d recursive instantiations from here: %s\n", cur->loc.toChars(), recursionDepth+2, cur->toChars());
- else
- fprintf(stdmsg,format, cur->loc.toChars(), cur->toChars());
- recursionDepth = 0;
- }
- }
+ // By collapsing recursive instantiations into a single line,
+ // we can stay under the limit.
+ int recursionDepth=0;
+ for (TemplateInstance *cur = this; cur; cur = cur->tinst)
+ {
+ if (cur->tinst && cur->tempdecl && cur->tinst->tempdecl
+ && cur->tempdecl->loc.equals(cur->tinst->tempdecl->loc))
+ {
+ ++recursionDepth;
+ }
+ else
+ {
+ if (recursionDepth)
+ fprintf(stdmsg, "%s: %d recursive instantiations from here: %s\n", cur->loc.toChars(), recursionDepth+2, cur->toChars());
+ else
+ fprintf(stdmsg,format, cur->loc.toChars(), cur->toChars());
+ recursionDepth = 0;
+ }
+ }
}
else
{
- // Even after collapsing the recursions, the depth is too deep.
- // Just display the first few and last few instantiations.
- size_t i = 0;
- for (TemplateInstance *cur = this; cur; cur = cur->tinst)
- {
- if (i == max_shown / 2)
- fprintf(stdmsg," ... (%d instantiations, -v to show) ...\n", n_instantiations - max_shown);
+ // Even after collapsing the recursions, the depth is too deep.
+ // Just display the first few and last few instantiations.
+ size_t i = 0;
+ for (TemplateInstance *cur = this; cur; cur = cur->tinst)
+ {
+ if (i == max_shown / 2)
+ fprintf(stdmsg," ... (%d instantiations, -v to show) ...\n", n_instantiations - max_shown);
- if (i < max_shown / 2 ||
- i >= n_instantiations - max_shown + max_shown / 2)
- fprintf(stdmsg, format, cur->loc.toChars(), cur->toChars());
- ++i;
- }
+ if (i < max_shown / 2 ||
+ i >= n_instantiations - max_shown + max_shown / 2)
+ fprintf(stdmsg, format, cur->loc.toChars(), cur->toChars());
+ ++i;
+ }
}
}
@@ -4307,18 +4307,18 @@ void TemplateInstance::toObjFile(int multiobj)
#endif
if (!errors && members)
{
- if (multiobj)
- // Append to list of object files to be written later
- //obj_append(this);
+ if (multiobj)
+ // Append to list of object files to be written later
+ //obj_append(this);
assert(0 && "multiobj");
- else
- {
- for (int i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->toObjFile(multiobj);
- }
- }
+ else
+ {
+ for (int i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->toObjFile(multiobj);
+ }
+ }
}
}
@@ -4331,11 +4331,11 @@ void TemplateInstance::inlineScan()
#endif
if (!errors && members)
{
- for (int i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->inlineScan();
- }
+ for (int i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->inlineScan();
+ }
}
}
@@ -4347,19 +4347,19 @@ void TemplateInstance::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring(id->toChars());
buf->writestring("!(");
if (nest)
- buf->writestring("...");
+ buf->writestring("...");
else
{
- nest++;
- Objects *args = tiargs;
- for (i = 0; i < args->dim; i++)
- {
- if (i)
- buf->writeByte(',');
- Object *oarg = (Object *)args->data[i];
- ObjectToCBuffer(buf, hgs, oarg);
- }
- nest--;
+ nest++;
+ Objects *args = tiargs;
+ for (i = 0; i < args->dim; i++)
+ {
+ if (i)
+ buf->writeByte(',');
+ Object *oarg = (Object *)args->data[i];
+ ObjectToCBuffer(buf, hgs, oarg);
+ }
+ nest--;
}
buf->writeByte(')');
}
@@ -4371,17 +4371,17 @@ Dsymbol *TemplateInstance::toAlias()
printf("TemplateInstance::toAlias()\n");
#endif
if (!inst)
- { error("cannot resolve forward reference");
- errors = 1;
- return this;
+ { error("cannot resolve forward reference");
+ errors = 1;
+ return this;
}
if (inst != this)
- return inst->toAlias();
+ return inst->toAlias();
if (aliasdecl)
{
- return aliasdecl->toAlias();
+ return aliasdecl->toAlias();
}
return inst;
@@ -4420,7 +4420,7 @@ char *TemplateInstance::toChars()
void TemplateInstance::printInstantiationTrace()
{
if(global.gag)
- return;
+ return;
const int max_shown = 6;
@@ -4428,29 +4428,29 @@ void TemplateInstance::printInstantiationTrace()
int n_instantiations = 1;
TemplateInstance* cur = this;
while(cur = cur->tinst)
- ++n_instantiations;
+ ++n_instantiations;
// show full trace only if it's short or verbose is on
if(n_instantiations <= max_shown || global.params.verbose)
{
- cur = this;
- while(cur)
- {
- fprintf(stdmsg," instantiatied in %s: %s\n", cur->loc.toChars(), cur->toChars());
- cur = cur->tinst;
- }
+ cur = this;
+ while(cur)
+ {
+ fprintf(stdmsg," instantiatied in %s: %s\n", cur->loc.toChars(), cur->toChars());
+ cur = cur->tinst;
+ }
}
else
{
- cur = this;
- size_t i = 0;
- for(; i < max_shown/2; ++i, cur = cur->tinst)
- fprintf(stdmsg," instantiatied in %s: %s\n", cur->loc.toChars(), cur->toChars());
- fprintf(stdmsg," ... (%d instantiations, -v to show) ...\n", n_instantiations - max_shown);
- for(; i < n_instantiations - max_shown + max_shown/2; ++i, cur = cur->tinst)
- {}
- for(; i < n_instantiations; ++i, cur = cur->tinst)
- fprintf(stdmsg," instantiatied in %s: %s\n", cur->loc.toChars(), cur->toChars());
+ cur = this;
+ size_t i = 0;
+ for(; i < max_shown/2; ++i, cur = cur->tinst)
+ fprintf(stdmsg," instantiatied in %s: %s\n", cur->loc.toChars(), cur->toChars());
+ fprintf(stdmsg," ... (%d instantiations, -v to show) ...\n", n_instantiations - max_shown);
+ for(; i < n_instantiations - max_shown + max_shown/2; ++i, cur = cur->tinst)
+ {}
+ for(; i < n_instantiations; ++i, cur = cur->tinst)
+ fprintf(stdmsg," instantiatied in %s: %s\n", cur->loc.toChars(), cur->toChars());
}
}
@@ -4459,8 +4459,8 @@ void TemplateInstance::printInstantiationTrace()
/* ======================== TemplateMixin ================================ */
TemplateMixin::TemplateMixin(Loc loc, Identifier *ident, Type *tqual,
- Array *idents, Objects *tiargs)
- : TemplateInstance(loc, (Identifier *)idents->data[idents->dim - 1])
+ Array *idents, Objects *tiargs)
+ : TemplateInstance(loc, (Identifier *)idents->data[idents->dim - 1])
{
//printf("TemplateMixin(ident = '%s')\n", ident ? ident->toChars() : "");
this->ident = ident;
@@ -4475,7 +4475,7 @@ Dsymbol *TemplateMixin::syntaxCopy(Dsymbol *s)
Array *ids = new Array();
ids->setDim(idents->dim);
for (int i = 0; i < idents->dim; i++)
- { // Matches TypeQualified::syntaxCopyHelper()
+ { // Matches TypeQualified::syntaxCopyHelper()
Identifier *id = (Identifier *)idents->data[i];
if (id->dyncast() == DYNCAST_DSYMBOL)
{
@@ -4488,8 +4488,8 @@ Dsymbol *TemplateMixin::syntaxCopy(Dsymbol *s)
}
tm = new TemplateMixin(loc, ident,
- (Type *)(tqual ? tqual->syntaxCopy() : NULL),
- ids, tiargs);
+ (Type *)(tqual ? tqual->syntaxCopy() : NULL),
+ ids, tiargs);
TemplateInstance::syntaxCopy(tm);
return tm;
}
@@ -4502,20 +4502,20 @@ void TemplateMixin::semantic(Scope *sc)
#endif
if (semanticRun)
{
- // This for when a class/struct contains mixin members, and
- // is done over because of forward references
- if (parent && toParent()->isAggregateDeclaration())
- semanticRun = 1; // do over
- else
- {
+ // This for when a class/struct contains mixin members, and
+ // is done over because of forward references
+ if (parent && toParent()->isAggregateDeclaration())
+ semanticRun = 1; // do over
+ else
+ {
#if LOG
- printf("\tsemantic done\n");
+ printf("\tsemantic done\n");
#endif
- return;
- }
+ return;
+ }
}
if (!semanticRun)
- semanticRun = 1;
+ semanticRun = 1;
#if LOG
printf("\tdo semantic\n");
#endif
@@ -4527,106 +4527,106 @@ void TemplateMixin::semantic(Scope *sc)
Scope *scx = NULL;
if (scope)
- { sc = scope;
- scx = scope; // save so we don't make redundant copies
- scope = NULL;
+ { sc = scope;
+ scx = scope; // save so we don't make redundant copies
+ scope = NULL;
}
// Follow qualifications to find the TemplateDeclaration
if (!tempdecl)
- { Dsymbol *s;
- int i;
- Identifier *id;
+ { Dsymbol *s;
+ int i;
+ Identifier *id;
- if (tqual)
- { s = tqual->toDsymbol(sc);
- i = 0;
- }
- else
- {
- i = 1;
- id = (Identifier *)idents->data[0];
- switch (id->dyncast())
- {
- case DYNCAST_IDENTIFIER:
- s = sc->search(loc, id, NULL);
- break;
+ if (tqual)
+ { s = tqual->toDsymbol(sc);
+ i = 0;
+ }
+ else
+ {
+ i = 1;
+ id = (Identifier *)idents->data[0];
+ switch (id->dyncast())
+ {
+ case DYNCAST_IDENTIFIER:
+ s = sc->search(loc, id, NULL);
+ break;
- case DYNCAST_DSYMBOL:
- {
- TemplateInstance *ti = (TemplateInstance *)id;
- ti->semantic(sc);
- s = ti;
- break;
- }
- default:
- assert(0);
- }
- }
+ case DYNCAST_DSYMBOL:
+ {
+ TemplateInstance *ti = (TemplateInstance *)id;
+ ti->semantic(sc);
+ s = ti;
+ break;
+ }
+ default:
+ assert(0);
+ }
+ }
- for (; i < idents->dim; i++)
- {
- if (!s)
- break;
- id = (Identifier *)idents->data[i];
- s = s->searchX(loc, sc, id);
- }
- if (!s)
- {
- error("is not defined");
- inst = this;
- return;
- }
- tempdecl = s->toAlias()->isTemplateDeclaration();
- if (!tempdecl)
- {
- error("%s isn't a template", s->toChars());
- inst = this;
- return;
- }
+ for (; i < idents->dim; i++)
+ {
+ if (!s)
+ break;
+ id = (Identifier *)idents->data[i];
+ s = s->searchX(loc, sc, id);
+ }
+ if (!s)
+ {
+ error("is not defined");
+ inst = this;
+ return;
+ }
+ tempdecl = s->toAlias()->isTemplateDeclaration();
+ if (!tempdecl)
+ {
+ error("%s isn't a template", s->toChars());
+ inst = this;
+ return;
+ }
}
// Look for forward reference
assert(tempdecl);
for (TemplateDeclaration *td = tempdecl; td; td = td->overnext)
{
- if (!td->semanticRun)
- {
- /* Cannot handle forward references if mixin is a struct member,
- * because addField must happen during struct's semantic, not
- * during the mixin semantic.
- * runDeferred will re-run mixin's semantic outside of the struct's
- * semantic.
- */
- semanticRun = 0;
- AggregateDeclaration *ad = toParent()->isAggregateDeclaration();
- if (ad)
- ad->sizeok = 2;
- else
- {
- // Forward reference
- //printf("forward reference - deferring\n");
- scope = scx ? scx : new Scope(*sc);
- scope->setNoFree();
- scope->module->addDeferredSemantic(this);
- }
- return;
- }
+ if (!td->semanticRun)
+ {
+ /* Cannot handle forward references if mixin is a struct member,
+ * because addField must happen during struct's semantic, not
+ * during the mixin semantic.
+ * runDeferred will re-run mixin's semantic outside of the struct's
+ * semantic.
+ */
+ semanticRun = 0;
+ AggregateDeclaration *ad = toParent()->isAggregateDeclaration();
+ if (ad)
+ ad->sizeok = 2;
+ else
+ {
+ // Forward reference
+ //printf("forward reference - deferring\n");
+ scope = scx ? scx : new Scope(*sc);
+ scope->setNoFree();
+ scope->module->addDeferredSemantic(this);
+ }
+ return;
+ }
}
// Run semantic on each argument, place results in tiargs[]
semanticTiargs(sc);
if (errors)
- return;
+ return;
tempdecl = findBestMatch(sc);
if (!tempdecl)
- { inst = this;
- return; // error recovery
+ { inst = this;
+ return; // error recovery
}
if (!ident)
- ident = genIdent();
+ ident = genIdent();
inst = this;
parent = sc->parent;
@@ -4635,66 +4635,66 @@ void TemplateMixin::semantic(Scope *sc)
*/
for (Dsymbol *s = parent; s; s = s->parent)
{
- //printf("\ts = '%s'\n", s->toChars());
- TemplateMixin *tm = s->isTemplateMixin();
- if (!tm || tempdecl != tm->tempdecl)
- continue;
+ //printf("\ts = '%s'\n", s->toChars());
+ TemplateMixin *tm = s->isTemplateMixin();
+ if (!tm || tempdecl != tm->tempdecl)
+ continue;
- /* Different argument list lengths happen with variadic args
- */
- if (tiargs->dim != tm->tiargs->dim)
- continue;
+ /* Different argument list lengths happen with variadic args
+ */
+ if (tiargs->dim != tm->tiargs->dim)
+ continue;
- for (int i = 0; i < tiargs->dim; i++)
- { Object *o = (Object *)tiargs->data[i];
- Type *ta = isType(o);
- Expression *ea = isExpression(o);
- Dsymbol *sa = isDsymbol(o);
- Object *tmo = (Object *)tm->tiargs->data[i];
- if (ta)
- {
- Type *tmta = isType(tmo);
- if (!tmta)
- goto Lcontinue;
- if (!ta->equals(tmta))
- goto Lcontinue;
- }
- else if (ea)
- { Expression *tme = isExpression(tmo);
- if (!tme || !ea->equals(tme))
- goto Lcontinue;
- }
- else if (sa)
- {
- Dsymbol *tmsa = isDsymbol(tmo);
- if (sa != tmsa)
- goto Lcontinue;
- }
- else
- assert(0);
- }
- error("recursive mixin instantiation");
- return;
+ for (int i = 0; i < tiargs->dim; i++)
+ { Object *o = (Object *)tiargs->data[i];
+ Type *ta = isType(o);
+ Expression *ea = isExpression(o);
+ Dsymbol *sa = isDsymbol(o);
+ Object *tmo = (Object *)tm->tiargs->data[i];
+ if (ta)
+ {
+ Type *tmta = isType(tmo);
+ if (!tmta)
+ goto Lcontinue;
+ if (!ta->equals(tmta))
+ goto Lcontinue;
+ }
+ else if (ea)
+ { Expression *tme = isExpression(tmo);
+ if (!tme || !ea->equals(tme))
+ goto Lcontinue;
+ }
+ else if (sa)
+ {
+ Dsymbol *tmsa = isDsymbol(tmo);
+ if (sa != tmsa)
+ goto Lcontinue;
+ }
+ else
+ assert(0);
+ }
+ error("recursive mixin instantiation");
+ return;
Lcontinue:
- continue;
+ continue;
}
// Copy the syntax trees from the TemplateDeclaration
members = Dsymbol::arraySyntaxCopy(tempdecl->members);
if (!members)
- return;
+ return;
symtab = new DsymbolTable();
for (Scope *sce = sc; 1; sce = sce->enclosing)
{
- ScopeDsymbol *sds = (ScopeDsymbol *)sce->scopesym;
- if (sds)
- {
- sds->importScope(this, PROTpublic);
- break;
- }
+ ScopeDsymbol *sds = (ScopeDsymbol *)sce->scopesym;
+ if (sds)
+ {
+ sds->importScope(this, PROTpublic);
+ break;
+ }
}
#if LOG
@@ -4717,11 +4717,11 @@ void TemplateMixin::semantic(Scope *sc)
for (unsigned i = 0; i < members->dim; i++)
{ Dsymbol *s;
- s = (Dsymbol *)members->data[i];
- s->addMember(argscope, this, i);
- //sc->insert(s);
- //printf("sc->parent = %p, sc->scopesym = %p\n", sc->parent, sc->scopesym);
- //printf("s->parent = %s\n", s->parent->toChars());
+ s = (Dsymbol *)members->data[i];
+ s->addMember(argscope, this, i);
+ //sc->insert(s);
+ //printf("sc->parent = %p, sc->scopesym = %p\n", sc->parent, sc->scopesym);
+ //printf("s->parent = %s\n", s->parent->toChars());
}
// Do semantic() analysis on template instance members
@@ -4736,15 +4736,15 @@ void TemplateMixin::semantic(Scope *sc)
//printf("%d\n", nest);
if (++nest > 500)
{
- global.gag = 0; // ensure error message gets printed
- error("recursive expansion");
- fatal();
+ global.gag = 0; // ensure error message gets printed
+ error("recursive expansion");
+ fatal();
}
for (int i = 0; i < members->dim; i++)
{
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->semantic(sc2);
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->semantic(sc2);
}
nest--;
@@ -4757,17 +4757,17 @@ void TemplateMixin::semantic(Scope *sc)
*/
// if (sc->parent->isFuncDeclaration())
- semantic2(sc2);
+ semantic2(sc2);
if (sc->func)
{
- semantic3(sc2);
+ semantic3(sc2);
}
// Give additional context info if error occurred during instantiation
if (global.errors != errorsave)
{
- error("error instantiating");
+ error("error instantiating");
}
sc2->pop();
@@ -4776,7 +4776,7 @@ void TemplateMixin::semantic(Scope *sc)
// if (!isAnonymous())
{
- scy->pop();
+ scy->pop();
}
#if LOG
printf("-TemplateMixin::semantic('%s', this=%p)\n", toChars(), this);
@@ -4787,26 +4787,26 @@ void TemplateMixin::semantic2(Scope *sc)
{ int i;
if (semanticRun >= 2)
- return;
+ return;
semanticRun = 2;
#if LOG
printf("+TemplateMixin::semantic2('%s')\n", toChars());
#endif
if (members)
{
- assert(sc);
- sc = sc->push(argsym);
- sc = sc->push(this);
- for (i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
+ assert(sc);
+ sc = sc->push(argsym);
+ sc = sc->push(this);
+ for (i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
#if LOG
- printf("\tmember '%s', kind = '%s'\n", s->toChars(), s->kind());
+ printf("\tmember '%s', kind = '%s'\n", s->toChars(), s->kind());
#endif
- s->semantic2(sc);
- }
- sc = sc->pop();
- sc->pop();
+ s->semantic2(sc);
+ }
+ sc = sc->pop();
+ sc->pop();
}
#if LOG
printf("-TemplateMixin::semantic2('%s')\n", toChars());
@@ -4817,22 +4817,22 @@ void TemplateMixin::semantic3(Scope *sc)
{ int i;
if (semanticRun >= 3)
- return;
+ return;
semanticRun = 3;
#if LOG
printf("TemplateMixin::semantic3('%s')\n", toChars());
#endif
if (members)
{
- sc = sc->push(argsym);
- sc = sc->push(this);
- for (i = 0; i < members->dim; i++)
- {
- Dsymbol *s = (Dsymbol *)members->data[i];
- s->semantic3(sc);
- }
- sc = sc->pop();
- sc->pop();
+ sc = sc->push(argsym);
+ sc = sc->push(this);
+ for (i = 0; i < members->dim; i++)
+ {
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ s->semantic3(sc);
+ }
+ sc = sc->pop();
+ sc->pop();
}
}
@@ -4856,12 +4856,12 @@ int TemplateMixin::hasPointers()
//printf("TemplateMixin::hasPointers() %s\n", toChars());
for (size_t i = 0; i < members->dim; i++)
{
- Dsymbol *s = (Dsymbol *)members->data[i];
- //printf(" s = %s %s\n", s->kind(), s->toChars());
- if (s->hasPointers())
- {
- return 1;
- }
+ Dsymbol *s = (Dsymbol *)members->data[i];
+ //printf(" s = %s %s\n", s->kind(), s->toChars());
+ if (s->hasPointers())
+ {
+ return 1;
+ }
}
return 0;
}
@@ -4885,9 +4885,9 @@ void TemplateMixin::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
for (int i = 0; i < idents->dim; i++)
{ Identifier *id = (Identifier *)idents->data[i];
- if (i)
- buf->writeByte('.');
- buf->writestring(id->toChars());
+ if (i)
+ buf->writeByte('.');
+ buf->writestring(id->toChars());
}
buf->writestring("!(");
if (tiargs)
@@ -4895,34 +4895,34 @@ void TemplateMixin::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
for (int i = 0; i < tiargs->dim; i++)
{ if (i)
buf->writebyte(',');
- Object *oarg = (Object *)tiargs->data[i];
- Type *t = isType(oarg);
- Expression *e = isExpression(oarg);
- Dsymbol *s = isDsymbol(oarg);
- if (t)
- t->toCBuffer(buf, NULL, hgs);
- else if (e)
- e->toCBuffer(buf, hgs);
- else if (s)
- {
- char *p = s->ident ? s->ident->toChars() : s->toChars();
- buf->writestring(p);
- }
- else if (!oarg)
- {
- buf->writestring("NULL");
- }
- else
- {
- assert(0);
- }
+ Object *oarg = (Object *)tiargs->data[i];
+ Type *t = isType(oarg);
+ Expression *e = isExpression(oarg);
+ Dsymbol *s = isDsymbol(oarg);
+ if (t)
+ t->toCBuffer(buf, NULL, hgs);
+ else if (e)
+ e->toCBuffer(buf, hgs);
+ else if (s)
+ {
+ char *p = s->ident ? s->ident->toChars() : s->toChars();
+ buf->writestring(p);
+ }
+ else if (!oarg)
+ {
+ buf->writestring("NULL");
+ }
+ else
+ {
+ assert(0);
+ }
}
}
buf->writebyte(')');
if (ident)
{
- buf->writebyte(' ');
- buf->writestring(ident->toChars());
+ buf->writebyte(' ');
+ buf->writestring(ident->toChars());
}
buf->writebyte(';');
buf->writenl();
diff --git a/dmd/template.h b/dmd/template.h
index 2d98f04f..f03362c6 100644
--- a/dmd/template.h
+++ b/dmd/template.h
@@ -51,21 +51,21 @@ struct Tuple : Object
struct TemplateDeclaration : ScopeDsymbol
{
- TemplateParameters *parameters; // array of TemplateParameter's
+ TemplateParameters *parameters; // array of TemplateParameter's
- TemplateParameters *origParameters; // originals for Ddoc
+ TemplateParameters *origParameters; // originals for Ddoc
Expression *constraint;
- Array instances; // array of TemplateInstance's
+ Array instances; // array of TemplateInstance's
- TemplateDeclaration *overnext; // next overloaded TemplateDeclaration
- TemplateDeclaration *overroot; // first in overnext list
+ TemplateDeclaration *overnext; // next overloaded TemplateDeclaration
+ TemplateDeclaration *overroot; // first in overnext list
- int semanticRun; // 1 semantic() run
+ int semanticRun; // 1 semantic() run
- Dsymbol *onemember; // if !=NULL then one member of this template
+ Dsymbol *onemember; // if !=NULL then one member of this template
TemplateDeclaration(Loc loc, Identifier *id, TemplateParameters *parameters,
- Expression *constraint, Array *decldefs);
+ Expression *constraint, Array *decldefs);
Dsymbol *syntaxCopy(Dsymbol *);
void semantic(Scope *sc);
int overloadInsert(Dsymbol *s);
@@ -100,15 +100,15 @@ struct TemplateDeclaration : ScopeDsymbol
struct TemplateParameter
{
/* For type-parameter:
- * template Foo(ident) // specType is set to NULL
- * template Foo(ident : specType)
+ * template Foo(ident) // specType is set to NULL
+ * template Foo(ident : specType)
* For value-parameter:
- * template Foo(valType ident) // specValue is set to NULL
- * template Foo(valType ident : specValue)
+ * template Foo(valType ident) // specValue is set to NULL
+ * template Foo(valType ident : specValue)
* For alias-parameter:
- * template Foo(alias ident)
+ * template Foo(alias ident)
* For this-parameter:
- * template Foo(this ident)
+ * template Foo(this ident)
*/
Loc loc;
@@ -150,9 +150,9 @@ struct TemplateParameter
struct TemplateTypeParameter : TemplateParameter
{
/* Syntax:
- * ident : specType = defaultType
+ * ident : specType = defaultType
*/
- Type *specType; // type parameter: if !=NULL, this is the type specialization
+ Type *specType; // type parameter: if !=NULL, this is the type specialization
Type *defaultType;
TemplateTypeParameter(Loc loc, Identifier *ident, Type *specType, Type *defaultType);
@@ -174,9 +174,9 @@ struct TemplateTypeParameter : TemplateParameter
struct TemplateThisParameter : TemplateTypeParameter
{
/* Syntax:
- * this ident : specType = defaultType
+ * this ident : specType = defaultType
*/
- Type *specType; // type parameter: if !=NULL, this is the type specialization
+ Type *specType; // type parameter: if !=NULL, this is the type specialization
Type *defaultType;
TemplateThisParameter(Loc loc, Identifier *ident, Type *specType, Type *defaultType);
@@ -190,7 +190,7 @@ struct TemplateThisParameter : TemplateTypeParameter
struct TemplateValueParameter : TemplateParameter
{
/* Syntax:
- * valType ident : specValue = defaultValue
+ * valType ident : specValue = defaultValue
*/
Type *valType;
@@ -217,7 +217,7 @@ struct TemplateValueParameter : TemplateParameter
struct TemplateAliasParameter : TemplateParameter
{
/* Syntax:
- * specType ident : specAlias = defaultAlias
+ * specType ident : specAlias = defaultAlias
*/
Type *specAliasT;
@@ -245,7 +245,7 @@ struct TemplateAliasParameter : TemplateParameter
struct TemplateTupleParameter : TemplateParameter
{
/* Syntax:
- * ident ...
+ * ident ...
*/
TemplateTupleParameter(Loc loc, Identifier *ident);
@@ -266,32 +266,32 @@ struct TemplateTupleParameter : TemplateParameter
struct TemplateInstance : ScopeDsymbol
{
/* Given:
- * foo!(args) =>
- * name = foo
- * tiargs = args
+ * foo!(args) =>
+ * name = foo
+ * tiargs = args
*/
Identifier *name;
//Array idents;
- Objects *tiargs; // Array of Types/Expressions of template
- // instance arguments [int*, char, 10*10]
+ Objects *tiargs; // Array of Types/Expressions of template
+ // instance arguments [int*, char, 10*10]
- Objects tdtypes; // Array of Types/Expressions corresponding
- // to TemplateDeclaration.parameters
- // [int, char, 100]
+ Objects tdtypes; // Array of Types/Expressions corresponding
+ // to TemplateDeclaration.parameters
+ // [int, char, 100]
- TemplateDeclaration *tempdecl; // referenced by foo.bar.abc
- TemplateInstance *inst; // refer to existing instance
- TemplateInstance *tinst; // enclosing template instance
- ScopeDsymbol *argsym; // argument symbol table
- AliasDeclaration *aliasdecl; // !=NULL if instance is an alias for its
- // sole member
- WithScopeSymbol *withsym; // if a member of a with statement
- int semanticRun; // has semantic() been done?
- int semantictiargsdone; // has semanticTiargs() been done?
- int nest; // for recursion detection
- int havetempdecl; // 1 if used second constructor
- Dsymbol *isnested; // if referencing local symbols, this is the context
- int errors; // 1 if compiled with errors
+ TemplateDeclaration *tempdecl; // referenced by foo.bar.abc
+ TemplateInstance *inst; // refer to existing instance
+ TemplateInstance *tinst; // enclosing template instance
+ ScopeDsymbol *argsym; // argument symbol table
+ AliasDeclaration *aliasdecl; // !=NULL if instance is an alias for its
+ // sole member
+ WithScopeSymbol *withsym; // if a member of a with statement
+ int semanticRun; // has semantic() been done?
+ int semantictiargsdone; // has semanticTiargs() been done?
+ int nest; // for recursion detection
+ int havetempdecl; // 1 if used second constructor
+ Dsymbol *isnested; // if referencing local symbols, this is the context
+ int errors; // 1 if compiled with errors
#ifdef IN_GCC
/* On some targets, it is necessary to know whether a symbol
will be emitted in the output or not before the symbol
@@ -308,7 +308,7 @@ struct TemplateInstance : ScopeDsymbol
void semantic3(Scope *sc);
void inlineScan();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
- Dsymbol *toAlias(); // resolve real symbol
+ Dsymbol *toAlias(); // resolve real symbol
const char *kind();
int oneMember(Dsymbol **ps);
int needsTypeInference(Scope *sc);
@@ -317,7 +317,7 @@ struct TemplateInstance : ScopeDsymbol
void printInstantiationTrace();
#if IN_DMD
- void toObjFile(int multiobj); // compile to .obj file
+ void toObjFile(int multiobj); // compile to .obj file
#endif
// Internal
@@ -360,7 +360,7 @@ struct TemplateMixin : TemplateInstance
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
#if IN_DMD
- void toObjFile(int multiobj); // compile to .obj file
+ void toObjFile(int multiobj); // compile to .obj file
#endif
TemplateMixin *isTemplateMixin() { return this; }
diff --git a/dmd/unialpha.c b/dmd/unialpha.c
index 2f604f48..b9fef9fd 100644
--- a/dmd/unialpha.c
+++ b/dmd/unialpha.c
@@ -18,269 +18,269 @@ int isUniAlpha(unsigned u)
{
static unsigned short table[][2] =
{
- { 0x00AA, 0x00AA },
- { 0x00B5, 0x00B5 },
- { 0x00B7, 0x00B7 },
- { 0x00BA, 0x00BA },
- { 0x00C0, 0x00D6 },
- { 0x00D8, 0x00F6 },
- { 0x00F8, 0x01F5 },
- { 0x01FA, 0x0217 },
- { 0x0250, 0x02A8 },
- { 0x02B0, 0x02B8 },
- { 0x02BB, 0x02BB },
- { 0x02BD, 0x02C1 },
- { 0x02D0, 0x02D1 },
- { 0x02E0, 0x02E4 },
- { 0x037A, 0x037A },
- { 0x0386, 0x0386 },
- { 0x0388, 0x038A },
- { 0x038C, 0x038C },
- { 0x038E, 0x03A1 },
- { 0x03A3, 0x03CE },
- { 0x03D0, 0x03D6 },
- { 0x03DA, 0x03DA },
- { 0x03DC, 0x03DC },
- { 0x03DE, 0x03DE },
- { 0x03E0, 0x03E0 },
- { 0x03E2, 0x03F3 },
- { 0x0401, 0x040C },
- { 0x040E, 0x044F },
- { 0x0451, 0x045C },
- { 0x045E, 0x0481 },
- { 0x0490, 0x04C4 },
- { 0x04C7, 0x04C8 },
- { 0x04CB, 0x04CC },
- { 0x04D0, 0x04EB },
- { 0x04EE, 0x04F5 },
- { 0x04F8, 0x04F9 },
- { 0x0531, 0x0556 },
- { 0x0559, 0x0559 },
- { 0x0561, 0x0587 },
- { 0x05B0, 0x05B9 },
- { 0x05BB, 0x05BD },
- { 0x05BF, 0x05BF },
- { 0x05C1, 0x05C2 },
- { 0x05D0, 0x05EA },
- { 0x05F0, 0x05F2 },
- { 0x0621, 0x063A },
- { 0x0640, 0x0652 },
- { 0x0660, 0x0669 },
- { 0x0670, 0x06B7 },
- { 0x06BA, 0x06BE },
- { 0x06C0, 0x06CE },
- { 0x06D0, 0x06DC },
- { 0x06E5, 0x06E8 },
- { 0x06EA, 0x06ED },
- { 0x06F0, 0x06F9 },
- { 0x0901, 0x0903 },
- { 0x0905, 0x0939 },
- { 0x093D, 0x093D },
- { 0x093E, 0x094D },
- { 0x0950, 0x0952 },
- { 0x0958, 0x0963 },
- { 0x0966, 0x096F },
- { 0x0981, 0x0983 },
- { 0x0985, 0x098C },
- { 0x098F, 0x0990 },
- { 0x0993, 0x09A8 },
- { 0x09AA, 0x09B0 },
- { 0x09B2, 0x09B2 },
- { 0x09B6, 0x09B9 },
- { 0x09BE, 0x09C4 },
- { 0x09C7, 0x09C8 },
- { 0x09CB, 0x09CD },
- { 0x09DC, 0x09DD },
- { 0x09DF, 0x09E3 },
- { 0x09E6, 0x09EF },
- { 0x09F0, 0x09F1 },
- { 0x0A02, 0x0A02 },
- { 0x0A05, 0x0A0A },
- { 0x0A0F, 0x0A10 },
- { 0x0A13, 0x0A28 },
- { 0x0A2A, 0x0A30 },
- { 0x0A32, 0x0A33 },
- { 0x0A35, 0x0A36 },
- { 0x0A38, 0x0A39 },
- { 0x0A3E, 0x0A42 },
- { 0x0A47, 0x0A48 },
- { 0x0A4B, 0x0A4D },
- { 0x0A59, 0x0A5C },
- { 0x0A5E, 0x0A5E },
- { 0x0A66, 0x0A6F },
- { 0x0A74, 0x0A74 },
- { 0x0A81, 0x0A83 },
- { 0x0A85, 0x0A8B },
- { 0x0A8D, 0x0A8D },
- { 0x0A8F, 0x0A91 },
- { 0x0A93, 0x0AA8 },
- { 0x0AAA, 0x0AB0 },
- { 0x0AB2, 0x0AB3 },
- { 0x0AB5, 0x0AB9 },
- { 0x0ABD, 0x0AC5 },
- { 0x0AC7, 0x0AC9 },
- { 0x0ACB, 0x0ACD },
- { 0x0AD0, 0x0AD0 },
- { 0x0AE0, 0x0AE0 },
- { 0x0AE6, 0x0AEF },
- { 0x0B01, 0x0B03 },
- { 0x0B05, 0x0B0C },
- { 0x0B0F, 0x0B10 },
- { 0x0B13, 0x0B28 },
- { 0x0B2A, 0x0B30 },
- { 0x0B32, 0x0B33 },
- { 0x0B36, 0x0B39 },
- { 0x0B3D, 0x0B3D },
- { 0x0B3E, 0x0B43 },
- { 0x0B47, 0x0B48 },
- { 0x0B4B, 0x0B4D },
- { 0x0B5C, 0x0B5D },
- { 0x0B5F, 0x0B61 },
- { 0x0B66, 0x0B6F },
- { 0x0B82, 0x0B83 },
- { 0x0B85, 0x0B8A },
- { 0x0B8E, 0x0B90 },
- { 0x0B92, 0x0B95 },
- { 0x0B99, 0x0B9A },
- { 0x0B9C, 0x0B9C },
- { 0x0B9E, 0x0B9F },
- { 0x0BA3, 0x0BA4 },
- { 0x0BA8, 0x0BAA },
- { 0x0BAE, 0x0BB5 },
- { 0x0BB7, 0x0BB9 },
- { 0x0BBE, 0x0BC2 },
- { 0x0BC6, 0x0BC8 },
- { 0x0BCA, 0x0BCD },
- { 0x0BE7, 0x0BEF },
- { 0x0C01, 0x0C03 },
- { 0x0C05, 0x0C0C },
- { 0x0C0E, 0x0C10 },
- { 0x0C12, 0x0C28 },
- { 0x0C2A, 0x0C33 },
- { 0x0C35, 0x0C39 },
- { 0x0C3E, 0x0C44 },
- { 0x0C46, 0x0C48 },
- { 0x0C4A, 0x0C4D },
- { 0x0C60, 0x0C61 },
- { 0x0C66, 0x0C6F },
- { 0x0C82, 0x0C83 },
- { 0x0C85, 0x0C8C },
- { 0x0C8E, 0x0C90 },
- { 0x0C92, 0x0CA8 },
- { 0x0CAA, 0x0CB3 },
- { 0x0CB5, 0x0CB9 },
- { 0x0CBE, 0x0CC4 },
- { 0x0CC6, 0x0CC8 },
- { 0x0CCA, 0x0CCD },
- { 0x0CDE, 0x0CDE },
- { 0x0CE0, 0x0CE1 },
- { 0x0CE6, 0x0CEF },
- { 0x0D02, 0x0D03 },
- { 0x0D05, 0x0D0C },
- { 0x0D0E, 0x0D10 },
- { 0x0D12, 0x0D28 },
- { 0x0D2A, 0x0D39 },
- { 0x0D3E, 0x0D43 },
- { 0x0D46, 0x0D48 },
- { 0x0D4A, 0x0D4D },
- { 0x0D60, 0x0D61 },
- { 0x0D66, 0x0D6F },
- { 0x0E01, 0x0E3A },
- { 0x0E40, 0x0E5B },
-// { 0x0E50, 0x0E59 },
- { 0x0E81, 0x0E82 },
- { 0x0E84, 0x0E84 },
- { 0x0E87, 0x0E88 },
- { 0x0E8A, 0x0E8A },
- { 0x0E8D, 0x0E8D },
- { 0x0E94, 0x0E97 },
- { 0x0E99, 0x0E9F },
- { 0x0EA1, 0x0EA3 },
- { 0x0EA5, 0x0EA5 },
- { 0x0EA7, 0x0EA7 },
- { 0x0EAA, 0x0EAB },
- { 0x0EAD, 0x0EAE },
- { 0x0EB0, 0x0EB9 },
- { 0x0EBB, 0x0EBD },
- { 0x0EC0, 0x0EC4 },
- { 0x0EC6, 0x0EC6 },
- { 0x0EC8, 0x0ECD },
- { 0x0ED0, 0x0ED9 },
- { 0x0EDC, 0x0EDD },
- { 0x0F00, 0x0F00 },
- { 0x0F18, 0x0F19 },
- { 0x0F20, 0x0F33 },
- { 0x0F35, 0x0F35 },
- { 0x0F37, 0x0F37 },
- { 0x0F39, 0x0F39 },
- { 0x0F3E, 0x0F47 },
- { 0x0F49, 0x0F69 },
- { 0x0F71, 0x0F84 },
- { 0x0F86, 0x0F8B },
- { 0x0F90, 0x0F95 },
- { 0x0F97, 0x0F97 },
- { 0x0F99, 0x0FAD },
- { 0x0FB1, 0x0FB7 },
- { 0x0FB9, 0x0FB9 },
- { 0x10A0, 0x10C5 },
- { 0x10D0, 0x10F6 },
- { 0x1E00, 0x1E9B },
- { 0x1EA0, 0x1EF9 },
- { 0x1F00, 0x1F15 },
- { 0x1F18, 0x1F1D },
- { 0x1F20, 0x1F45 },
- { 0x1F48, 0x1F4D },
- { 0x1F50, 0x1F57 },
- { 0x1F59, 0x1F59 },
- { 0x1F5B, 0x1F5B },
- { 0x1F5D, 0x1F5D },
- { 0x1F5F, 0x1F7D },
- { 0x1F80, 0x1FB4 },
- { 0x1FB6, 0x1FBC },
- { 0x1FBE, 0x1FBE },
- { 0x1FC2, 0x1FC4 },
- { 0x1FC6, 0x1FCC },
- { 0x1FD0, 0x1FD3 },
- { 0x1FD6, 0x1FDB },
- { 0x1FE0, 0x1FEC },
- { 0x1FF2, 0x1FF4 },
- { 0x1FF6, 0x1FFC },
- { 0x203F, 0x2040 },
- { 0x207F, 0x207F },
- { 0x2102, 0x2102 },
- { 0x2107, 0x2107 },
- { 0x210A, 0x2113 },
- { 0x2115, 0x2115 },
- { 0x2118, 0x211D },
- { 0x2124, 0x2124 },
- { 0x2126, 0x2126 },
- { 0x2128, 0x2128 },
- { 0x212A, 0x2131 },
- { 0x2133, 0x2138 },
- { 0x2160, 0x2182 },
- { 0x3005, 0x3007 },
- { 0x3021, 0x3029 },
- { 0x3041, 0x3093 },
- { 0x309B, 0x309C },
- { 0x30A1, 0x30F6 },
- { 0x30FB, 0x30FC },
- { 0x3105, 0x312C },
- { 0x4E00, 0x9FA5 },
- { 0xAC00, 0xD7A3 },
+ { 0x00AA, 0x00AA },
+ { 0x00B5, 0x00B5 },
+ { 0x00B7, 0x00B7 },
+ { 0x00BA, 0x00BA },
+ { 0x00C0, 0x00D6 },
+ { 0x00D8, 0x00F6 },
+ { 0x00F8, 0x01F5 },
+ { 0x01FA, 0x0217 },
+ { 0x0250, 0x02A8 },
+ { 0x02B0, 0x02B8 },
+ { 0x02BB, 0x02BB },
+ { 0x02BD, 0x02C1 },
+ { 0x02D0, 0x02D1 },
+ { 0x02E0, 0x02E4 },
+ { 0x037A, 0x037A },
+ { 0x0386, 0x0386 },
+ { 0x0388, 0x038A },
+ { 0x038C, 0x038C },
+ { 0x038E, 0x03A1 },
+ { 0x03A3, 0x03CE },
+ { 0x03D0, 0x03D6 },
+ { 0x03DA, 0x03DA },
+ { 0x03DC, 0x03DC },
+ { 0x03DE, 0x03DE },
+ { 0x03E0, 0x03E0 },
+ { 0x03E2, 0x03F3 },
+ { 0x0401, 0x040C },
+ { 0x040E, 0x044F },
+ { 0x0451, 0x045C },
+ { 0x045E, 0x0481 },
+ { 0x0490, 0x04C4 },
+ { 0x04C7, 0x04C8 },
+ { 0x04CB, 0x04CC },
+ { 0x04D0, 0x04EB },
+ { 0x04EE, 0x04F5 },
+ { 0x04F8, 0x04F9 },
+ { 0x0531, 0x0556 },
+ { 0x0559, 0x0559 },
+ { 0x0561, 0x0587 },
+ { 0x05B0, 0x05B9 },
+ { 0x05BB, 0x05BD },
+ { 0x05BF, 0x05BF },
+ { 0x05C1, 0x05C2 },
+ { 0x05D0, 0x05EA },
+ { 0x05F0, 0x05F2 },
+ { 0x0621, 0x063A },
+ { 0x0640, 0x0652 },
+ { 0x0660, 0x0669 },
+ { 0x0670, 0x06B7 },
+ { 0x06BA, 0x06BE },
+ { 0x06C0, 0x06CE },
+ { 0x06D0, 0x06DC },
+ { 0x06E5, 0x06E8 },
+ { 0x06EA, 0x06ED },
+ { 0x06F0, 0x06F9 },
+ { 0x0901, 0x0903 },
+ { 0x0905, 0x0939 },
+ { 0x093D, 0x093D },
+ { 0x093E, 0x094D },
+ { 0x0950, 0x0952 },
+ { 0x0958, 0x0963 },
+ { 0x0966, 0x096F },
+ { 0x0981, 0x0983 },
+ { 0x0985, 0x098C },
+ { 0x098F, 0x0990 },
+ { 0x0993, 0x09A8 },
+ { 0x09AA, 0x09B0 },
+ { 0x09B2, 0x09B2 },
+ { 0x09B6, 0x09B9 },
+ { 0x09BE, 0x09C4 },
+ { 0x09C7, 0x09C8 },
+ { 0x09CB, 0x09CD },
+ { 0x09DC, 0x09DD },
+ { 0x09DF, 0x09E3 },
+ { 0x09E6, 0x09EF },
+ { 0x09F0, 0x09F1 },
+ { 0x0A02, 0x0A02 },
+ { 0x0A05, 0x0A0A },
+ { 0x0A0F, 0x0A10 },
+ { 0x0A13, 0x0A28 },
+ { 0x0A2A, 0x0A30 },
+ { 0x0A32, 0x0A33 },
+ { 0x0A35, 0x0A36 },
+ { 0x0A38, 0x0A39 },
+ { 0x0A3E, 0x0A42 },
+ { 0x0A47, 0x0A48 },
+ { 0x0A4B, 0x0A4D },
+ { 0x0A59, 0x0A5C },
+ { 0x0A5E, 0x0A5E },
+ { 0x0A66, 0x0A6F },
+ { 0x0A74, 0x0A74 },
+ { 0x0A81, 0x0A83 },
+ { 0x0A85, 0x0A8B },
+ { 0x0A8D, 0x0A8D },
+ { 0x0A8F, 0x0A91 },
+ { 0x0A93, 0x0AA8 },
+ { 0x0AAA, 0x0AB0 },
+ { 0x0AB2, 0x0AB3 },
+ { 0x0AB5, 0x0AB9 },
+ { 0x0ABD, 0x0AC5 },
+ { 0x0AC7, 0x0AC9 },
+ { 0x0ACB, 0x0ACD },
+ { 0x0AD0, 0x0AD0 },
+ { 0x0AE0, 0x0AE0 },
+ { 0x0AE6, 0x0AEF },
+ { 0x0B01, 0x0B03 },
+ { 0x0B05, 0x0B0C },
+ { 0x0B0F, 0x0B10 },
+ { 0x0B13, 0x0B28 },
+ { 0x0B2A, 0x0B30 },
+ { 0x0B32, 0x0B33 },
+ { 0x0B36, 0x0B39 },
+ { 0x0B3D, 0x0B3D },
+ { 0x0B3E, 0x0B43 },
+ { 0x0B47, 0x0B48 },
+ { 0x0B4B, 0x0B4D },
+ { 0x0B5C, 0x0B5D },
+ { 0x0B5F, 0x0B61 },
+ { 0x0B66, 0x0B6F },
+ { 0x0B82, 0x0B83 },
+ { 0x0B85, 0x0B8A },
+ { 0x0B8E, 0x0B90 },
+ { 0x0B92, 0x0B95 },
+ { 0x0B99, 0x0B9A },
+ { 0x0B9C, 0x0B9C },
+ { 0x0B9E, 0x0B9F },
+ { 0x0BA3, 0x0BA4 },
+ { 0x0BA8, 0x0BAA },
+ { 0x0BAE, 0x0BB5 },
+ { 0x0BB7, 0x0BB9 },
+ { 0x0BBE, 0x0BC2 },
+ { 0x0BC6, 0x0BC8 },
+ { 0x0BCA, 0x0BCD },
+ { 0x0BE7, 0x0BEF },
+ { 0x0C01, 0x0C03 },
+ { 0x0C05, 0x0C0C },
+ { 0x0C0E, 0x0C10 },
+ { 0x0C12, 0x0C28 },
+ { 0x0C2A, 0x0C33 },
+ { 0x0C35, 0x0C39 },
+ { 0x0C3E, 0x0C44 },
+ { 0x0C46, 0x0C48 },
+ { 0x0C4A, 0x0C4D },
+ { 0x0C60, 0x0C61 },
+ { 0x0C66, 0x0C6F },
+ { 0x0C82, 0x0C83 },
+ { 0x0C85, 0x0C8C },
+ { 0x0C8E, 0x0C90 },
+ { 0x0C92, 0x0CA8 },
+ { 0x0CAA, 0x0CB3 },
+ { 0x0CB5, 0x0CB9 },
+ { 0x0CBE, 0x0CC4 },
+ { 0x0CC6, 0x0CC8 },
+ { 0x0CCA, 0x0CCD },
+ { 0x0CDE, 0x0CDE },
+ { 0x0CE0, 0x0CE1 },
+ { 0x0CE6, 0x0CEF },
+ { 0x0D02, 0x0D03 },
+ { 0x0D05, 0x0D0C },
+ { 0x0D0E, 0x0D10 },
+ { 0x0D12, 0x0D28 },
+ { 0x0D2A, 0x0D39 },
+ { 0x0D3E, 0x0D43 },
+ { 0x0D46, 0x0D48 },
+ { 0x0D4A, 0x0D4D },
+ { 0x0D60, 0x0D61 },
+ { 0x0D66, 0x0D6F },
+ { 0x0E01, 0x0E3A },
+ { 0x0E40, 0x0E5B },
+// { 0x0E50, 0x0E59 },
+ { 0x0E81, 0x0E82 },
+ { 0x0E84, 0x0E84 },
+ { 0x0E87, 0x0E88 },
+ { 0x0E8A, 0x0E8A },
+ { 0x0E8D, 0x0E8D },
+ { 0x0E94, 0x0E97 },
+ { 0x0E99, 0x0E9F },
+ { 0x0EA1, 0x0EA3 },
+ { 0x0EA5, 0x0EA5 },
+ { 0x0EA7, 0x0EA7 },
+ { 0x0EAA, 0x0EAB },
+ { 0x0EAD, 0x0EAE },
+ { 0x0EB0, 0x0EB9 },
+ { 0x0EBB, 0x0EBD },
+ { 0x0EC0, 0x0EC4 },
+ { 0x0EC6, 0x0EC6 },
+ { 0x0EC8, 0x0ECD },
+ { 0x0ED0, 0x0ED9 },
+ { 0x0EDC, 0x0EDD },
+ { 0x0F00, 0x0F00 },
+ { 0x0F18, 0x0F19 },
+ { 0x0F20, 0x0F33 },
+ { 0x0F35, 0x0F35 },
+ { 0x0F37, 0x0F37 },
+ { 0x0F39, 0x0F39 },
+ { 0x0F3E, 0x0F47 },
+ { 0x0F49, 0x0F69 },
+ { 0x0F71, 0x0F84 },
+ { 0x0F86, 0x0F8B },
+ { 0x0F90, 0x0F95 },
+ { 0x0F97, 0x0F97 },
+ { 0x0F99, 0x0FAD },
+ { 0x0FB1, 0x0FB7 },
+ { 0x0FB9, 0x0FB9 },
+ { 0x10A0, 0x10C5 },
+ { 0x10D0, 0x10F6 },
+ { 0x1E00, 0x1E9B },
+ { 0x1EA0, 0x1EF9 },
+ { 0x1F00, 0x1F15 },
+ { 0x1F18, 0x1F1D },
+ { 0x1F20, 0x1F45 },
+ { 0x1F48, 0x1F4D },
+ { 0x1F50, 0x1F57 },
+ { 0x1F59, 0x1F59 },
+ { 0x1F5B, 0x1F5B },
+ { 0x1F5D, 0x1F5D },
+ { 0x1F5F, 0x1F7D },
+ { 0x1F80, 0x1FB4 },
+ { 0x1FB6, 0x1FBC },
+ { 0x1FBE, 0x1FBE },
+ { 0x1FC2, 0x1FC4 },
+ { 0x1FC6, 0x1FCC },
+ { 0x1FD0, 0x1FD3 },
+ { 0x1FD6, 0x1FDB },
+ { 0x1FE0, 0x1FEC },
+ { 0x1FF2, 0x1FF4 },
+ { 0x1FF6, 0x1FFC },
+ { 0x203F, 0x2040 },
+ { 0x207F, 0x207F },
+ { 0x2102, 0x2102 },
+ { 0x2107, 0x2107 },
+ { 0x210A, 0x2113 },
+ { 0x2115, 0x2115 },
+ { 0x2118, 0x211D },
+ { 0x2124, 0x2124 },
+ { 0x2126, 0x2126 },
+ { 0x2128, 0x2128 },
+ { 0x212A, 0x2131 },
+ { 0x2133, 0x2138 },
+ { 0x2160, 0x2182 },
+ { 0x3005, 0x3007 },
+ { 0x3021, 0x3029 },
+ { 0x3041, 0x3093 },
+ { 0x309B, 0x309C },
+ { 0x30A1, 0x30F6 },
+ { 0x30FB, 0x30FC },
+ { 0x3105, 0x312C },
+ { 0x4E00, 0x9FA5 },
+ { 0xAC00, 0xD7A3 },
};
#ifdef DEBUG
for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++)
{
- //printf("%x\n", table[i][0]);
- assert(table[i][0] <= table[i][1]);
- if (i < sizeof(table) / sizeof(table[0]) - 1)
- assert(table[i][1] < table[i + 1][0]);
+ //printf("%x\n", table[i][0]);
+ assert(table[i][0] <= table[i][1]);
+ if (i < sizeof(table) / sizeof(table[0]) - 1)
+ assert(table[i][1] < table[i + 1][0]);
}
#endif
if (u > 0xD7A3)
- goto Lisnot;
+ goto Lisnot;
// Binary search
int mid;
@@ -291,20 +291,20 @@ int isUniAlpha(unsigned u)
high = sizeof(table) / sizeof(table[0]) - 1;
while (low <= high)
{
- mid = (low + high) >> 1;
- if (u < table[mid][0])
- high = mid - 1;
- else if (u > table[mid][1])
- low = mid + 1;
- else
- goto Lis;
+ mid = (low + high) >> 1;
+ if (u < table[mid][0])
+ high = mid - 1;
+ else if (u > table[mid][1])
+ low = mid + 1;
+ else
+ goto Lis;
}
Lisnot:
#ifdef DEBUG
for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++)
{
- assert(u < table[i][0] || u > table[i][1]);
+ assert(u < table[i][0] || u > table[i][1]);
}
#endif
return 0;
@@ -313,10 +313,10 @@ Lis:
#ifdef DEBUG
for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++)
{
- if (u >= table[i][0] && u <= table[i][1])
- return 1;
+ if (u >= table[i][0] && u <= table[i][1])
+ return 1;
}
- assert(0); // should have been in table
+ assert(0); // should have been in table
#endif
return 1;
}
diff --git a/dmd/utf.c b/dmd/utf.c
index f8f93be4..0438bdba 100644
--- a/dmd/utf.c
+++ b/dmd/utf.c
@@ -18,14 +18,14 @@
int utf_isValidDchar(dchar_t c)
{
return c < 0xD800 ||
- (c > 0xDFFF && c <= 0x10FFFF && c != 0xFFFE && c != 0xFFFF);
+ (c > 0xDFFF && c <= 0x10FFFF && c != 0xFFFE && c != 0xFFFF);
}
/********************************************
* Decode a single UTF-8 character sequence.
* Returns:
- * NULL success
- * !=NULL error message string
+ * NULL success
+ * !=NULL error message string
*/
char *utf_decodeChar(unsigned char *s, size_t len, size_t *pidx, dchar_t *presult)
@@ -38,65 +38,65 @@ char *utf_decodeChar(unsigned char *s, size_t len, size_t *pidx, dchar_t *presul
if (u & 0x80)
{ unsigned n;
- unsigned char u2;
+ unsigned char u2;
- /* The following encodings are valid, except for the 5 and 6 byte
- * combinations:
- * 0xxxxxxx
- * 110xxxxx 10xxxxxx
- * 1110xxxx 10xxxxxx 10xxxxxx
- * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
- * 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
- * 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
- */
- for (n = 1; ; n++)
- {
- if (n > 4)
- goto Lerr; // only do the first 4 of 6 encodings
- if (((u << n) & 0x80) == 0)
- {
- if (n == 1)
- goto Lerr;
- break;
- }
- }
+ /* The following encodings are valid, except for the 5 and 6 byte
+ * combinations:
+ * 0xxxxxxx
+ * 110xxxxx 10xxxxxx
+ * 1110xxxx 10xxxxxx 10xxxxxx
+ * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ * 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ * 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ */
+ for (n = 1; ; n++)
+ {
+ if (n > 4)
+ goto Lerr; // only do the first 4 of 6 encodings
+ if (((u << n) & 0x80) == 0)
+ {
+ if (n == 1)
+ goto Lerr;
+ break;
+ }
+ }
- // Pick off (7 - n) significant bits of B from first byte of octet
- V = (dchar_t)(u & ((1 << (7 - n)) - 1));
+ // Pick off (7 - n) significant bits of B from first byte of octet
+ V = (dchar_t)(u & ((1 << (7 - n)) - 1));
- if (i + (n - 1) >= len)
- goto Lerr; // off end of string
+ if (i + (n - 1) >= len)
+ goto Lerr; // off end of string
- /* The following combinations are overlong, and illegal:
- * 1100000x (10xxxxxx)
- * 11100000 100xxxxx (10xxxxxx)
- * 11110000 1000xxxx (10xxxxxx 10xxxxxx)
- * 11111000 10000xxx (10xxxxxx 10xxxxxx 10xxxxxx)
- * 11111100 100000xx (10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx)
- */
- u2 = s[i + 1];
- if ((u & 0xFE) == 0xC0 ||
- (u == 0xE0 && (u2 & 0xE0) == 0x80) ||
- (u == 0xF0 && (u2 & 0xF0) == 0x80) ||
- (u == 0xF8 && (u2 & 0xF8) == 0x80) ||
- (u == 0xFC && (u2 & 0xFC) == 0x80))
- goto Lerr; // overlong combination
+ /* The following combinations are overlong, and illegal:
+ * 1100000x (10xxxxxx)
+ * 11100000 100xxxxx (10xxxxxx)
+ * 11110000 1000xxxx (10xxxxxx 10xxxxxx)
+ * 11111000 10000xxx (10xxxxxx 10xxxxxx 10xxxxxx)
+ * 11111100 100000xx (10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx)
+ */
+ u2 = s[i + 1];
+ if ((u & 0xFE) == 0xC0 ||
+ (u == 0xE0 && (u2 & 0xE0) == 0x80) ||
+ (u == 0xF0 && (u2 & 0xF0) == 0x80) ||
+ (u == 0xF8 && (u2 & 0xF8) == 0x80) ||
+ (u == 0xFC && (u2 & 0xFC) == 0x80))
+ goto Lerr; // overlong combination
- for (unsigned j = 1; j != n; j++)
- {
- u = s[i + j];
- if ((u & 0xC0) != 0x80)
- goto Lerr; // trailing bytes are 10xxxxxx
- V = (V << 6) | (u & 0x3F);
- }
- if (!utf_isValidDchar(V))
- goto Lerr;
- i += n;
+ for (unsigned j = 1; j != n; j++)
+ {
+ u = s[i + j];
+ if ((u & 0xC0) != 0x80)
+ goto Lerr; // trailing bytes are 10xxxxxx
+ V = (V << 6) | (u & 0x3F);
+ }
+ if (!utf_isValidDchar(V))
+ goto Lerr;
+ i += n;
}
else
{
- V = (dchar_t) u;
- i++;
+ V = (dchar_t) u;
+ i++;
}
assert(utf_isValidDchar(V));
@@ -113,8 +113,8 @@ char *utf_decodeChar(unsigned char *s, size_t len, size_t *pidx, dchar_t *presul
/***************************************************
* Validate a UTF-8 string.
* Returns:
- * NULL success
- * !=NULL error message string
+ * NULL success
+ * !=NULL error message string
*/
char *utf_validateString(unsigned char *s, size_t len)
@@ -125,9 +125,9 @@ char *utf_validateString(unsigned char *s, size_t len)
for (idx = 0; idx < len; )
{
- err = utf_decodeChar(s, len, &idx, &dc);
- if (err)
- break;
+ err = utf_decodeChar(s, len, &idx, &dc);
+ if (err)
+ break;
}
return err;
}
@@ -136,8 +136,8 @@ char *utf_validateString(unsigned char *s, size_t len)
/********************************************
* Decode a single UTF-16 character sequence.
* Returns:
- * NULL success
- * !=NULL error message string
+ * NULL success
+ * !=NULL error message string
*/
@@ -150,34 +150,34 @@ char *utf_decodeWchar(unsigned short *s, size_t len, size_t *pidx, dchar_t *pres
assert(i >= 0 && i < len);
if (u & ~0x7F)
{ if (u >= 0xD800 && u <= 0xDBFF)
- { unsigned u2;
+ { unsigned u2;
- if (i + 1 == len)
- { msg = "surrogate UTF-16 high value past end of string";
- goto Lerr;
- }
- u2 = s[i + 1];
- if (u2 < 0xDC00 || u2 > 0xDFFF)
- { msg = "surrogate UTF-16 low value out of range";
- goto Lerr;
- }
- u = ((u - 0xD7C0) << 10) + (u2 - 0xDC00);
- i += 2;
- }
- else if (u >= 0xDC00 && u <= 0xDFFF)
- { msg = "unpaired surrogate UTF-16 value";
- goto Lerr;
- }
- else if (u == 0xFFFE || u == 0xFFFF)
- { msg = "illegal UTF-16 value";
- goto Lerr;
- }
- else
- i++;
+ if (i + 1 == len)
+ { msg = "surrogate UTF-16 high value past end of string";
+ goto Lerr;
+ }
+ u2 = s[i + 1];
+ if (u2 < 0xDC00 || u2 > 0xDFFF)
+ { msg = "surrogate UTF-16 low value out of range";
+ goto Lerr;
+ }
+ u = ((u - 0xD7C0) << 10) + (u2 - 0xDC00);
+ i += 2;
+ }
+ else if (u >= 0xDC00 && u <= 0xDFFF)
+ { msg = "unpaired surrogate UTF-16 value";
+ goto Lerr;
+ }
+ else if (u == 0xFFFE || u == 0xFFFF)
+ { msg = "illegal UTF-16 value";
+ goto Lerr;
+ }
+ else
+ i++;
}
else
{
- i++;
+ i++;
}
assert(utf_isValidDchar(u));
diff --git a/dmd/version.c b/dmd/version.c
index c55c238b..37bc8775 100644
--- a/dmd/version.c
+++ b/dmd/version.c
@@ -21,8 +21,8 @@
/* ================================================== */
/* DebugSymbol's happen for statements like:
- * debug = identifier;
- * debug = integer;
+ * debug = identifier;
+ * debug = integer;
*/
DebugSymbol::DebugSymbol(Loc loc, Identifier *ident)
@@ -56,23 +56,23 @@ int DebugSymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
m = sd->isModule();
if (ident)
{
- if (!m)
- error("declaration must be at module level");
- else
- {
- if (findCondition(m->debugidsNot, ident))
- error("defined after use");
- if (!m->debugids)
- m->debugids = new Array();
- m->debugids->push(ident->toChars());
- }
+ if (!m)
+ error("declaration must be at module level");
+ else
+ {
+ if (findCondition(m->debugidsNot, ident))
+ error("defined after use");
+ if (!m->debugids)
+ m->debugids = new Array();
+ m->debugids->push(ident->toChars());
+ }
}
else
{
- if (!m)
- error("level declaration must be at module level");
- else
- m->debuglevel = level;
+ if (!m)
+ error("level declaration must be at module level");
+ else
+ m->debuglevel = level;
}
return 0;
}
@@ -86,9 +86,9 @@ void DebugSymbol::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writestring("debug = ");
if (ident)
- buf->writestring(ident->toChars());
+ buf->writestring(ident->toChars());
else
- buf->printf("%u", level);
+ buf->printf("%u", level);
buf->writestring(";");
buf->writenl();
}
@@ -101,8 +101,8 @@ const char *DebugSymbol::kind()
/* ================================================== */
/* VersionSymbol's happen for statements like:
- * version = identifier;
- * version = integer;
+ * version = identifier;
+ * version = integer;
*/
VersionSymbol::VersionSymbol(Loc loc, Identifier *ident)
@@ -136,24 +136,24 @@ int VersionSymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
m = sd->isModule();
if (ident)
{
- VersionCondition::checkPredefined(loc, ident->toChars());
- if (!m)
- error("declaration must be at module level");
- else
- {
- if (findCondition(m->versionidsNot, ident))
- error("defined after use");
- if (!m->versionids)
- m->versionids = new Array();
- m->versionids->push(ident->toChars());
- }
+ VersionCondition::checkPredefined(loc, ident->toChars());
+ if (!m)
+ error("declaration must be at module level");
+ else
+ {
+ if (findCondition(m->versionidsNot, ident))
+ error("defined after use");
+ if (!m->versionids)
+ m->versionids = new Array();
+ m->versionids->push(ident->toChars());
+ }
}
else
{
- if (!m)
- error("level declaration must be at module level");
- else
- m->versionlevel = level;
+ if (!m)
+ error("level declaration must be at module level");
+ else
+ m->versionlevel = level;
}
return 0;
}
@@ -166,9 +166,9 @@ void VersionSymbol::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writestring("version = ");
if (ident)
- buf->writestring(ident->toChars());
+ buf->writestring(ident->toChars());
else
- buf->printf("%u", level);
+ buf->printf("%u", level);
buf->writestring(";");
buf->writenl();
}