Skip to content
Browse files

Merge 1.072

  • Loading branch information...
1 parent 8108299 commit f9201e83526e863c5f1923e311379cd1ee4a5acf @redstar redstar committed Feb 2, 2012
Showing with 7,093 additions and 3,017 deletions.
  1. +12 −17 dmd/access.c
  2. +13 −8 dmd/aggregate.h
  3. +215 −199 dmd/arrayop.c
  4. +25 −11 dmd/arraytypes.h
  5. +107 −79 dmd/attrib.c
  6. +15 −16 dmd/attrib.h
  7. +30 −19 dmd/cast.c
  8. +105 −54 dmd/class.c
  9. +7 −7 dmd/clone.c
  10. +24 −22 dmd/cond.c
  11. +3 −6 dmd/cond.h
  12. +169 −50 dmd/constfold.c
  13. +97 −50 dmd/declaration.c
  14. +37 −15 dmd/declaration.h
  15. +3 −3 dmd/delegatize.c
  16. +47 −53 dmd/doc.c
  17. +148 −143 dmd/dsymbol.c
  18. +14 −15 dmd/dsymbol.h
  19. +11 −12 dmd/enum.c
  20. +0 −2 dmd/enum.h
  21. +474 −212 dmd/expression.c
  22. +90 −59 dmd/expression.h
  23. +81 −36 dmd/func.c
  24. +2 −6 dmd/hdrgen.c
  25. +0 −2 dmd/identifier.h
  26. +27 −1 dmd/idgen.c
  27. +1 −1 dmd/import.c
  28. +2 −4 dmd/import.h
  29. +141 −49 dmd/init.c
  30. +9 −9 dmd/init.h
  31. +24 −24 dmd/inline.c
  32. +4,287 −1,366 dmd/interpret.c
  33. +40 −18 dmd/json.c
  34. +2 −2 dmd/json.h
  35. +30 −26 dmd/lexer.c
  36. +1 −1 dmd/lexer.h
  37. +3 −2 dmd/macro.h
  38. +3 −3 dmd/mangle.c
  39. +46 −9 dmd/mars.c
  40. +81 −21 dmd/mars.h
  41. +68 −66 dmd/module.c
  42. +18 −18 dmd/module.h
  43. +271 −137 dmd/mtype.c
  44. +10 −2 dmd/mtype.h
  45. +1 −1 dmd/opover.c
  46. +47 −13 dmd/optimize.c
  47. +93 −58 dmd/parse.c
  48. +4 −4 dmd/parse.h
  49. +3 −1 dmd/root/array.c
  50. +6 −9 dmd/root/async.c
  51. +6 −6 dmd/root/dchar.c
  52. +8 −8 dmd/root/dchar.h
  53. +1 −1 dmd/root/man.c
  54. +35 −18 dmd/root/port.c
  55. +4 −1 dmd/root/port.h
  56. +25 −25 dmd/root/root.c
  57. +58 −8 dmd/root/root.h
  58. +2 −2 dmd/root/stringtable.c
  59. +3 −3 dmd/root/stringtable.h
  60. +4 −4 dmd/speller.c
Sorry, we could not display the entire diff because it was too big.
View
29 dmd/access.c
@@ -1,5 +1,5 @@
-// Copyright (c) 1999-2006 by Digital Mars
+// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -76,18 +76,15 @@ enum PROT ClassDeclaration::getAccess(Dsymbol *smember)
}
else
{
- enum PROT access;
- int i;
-
if (smember->isDeclaration()->isStatic())
{
access_ret = smember->prot();
}
- for (i = 0; i < baseclasses->dim; i++)
- { BaseClass *b = (BaseClass *)baseclasses->data[i];
+ for (size_t i = 0; i < baseclasses->dim; i++)
+ { BaseClass *b = (*baseclasses)[i];
- access = b->base->getAccess(smember);
+ enum PROT access = b->base->getAccess(smember);
switch (access)
{
case PROTnone:
@@ -153,11 +150,9 @@ static int accessCheckX(
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);
+ for (size_t i = 0; i < cdthis->baseclasses->dim; i++)
+ { BaseClass *b = (*cdthis->baseclasses)[i];
+ enum PROT access = b->base->getAccess(smember);
if (access >= PROTprotected ||
accessCheckX(smember, sfunc, b->base, cdscope)
)
@@ -174,8 +169,8 @@ static int accessCheckX(
ClassDeclaration *cdthis = dthis->isClassDeclaration();
if (cdthis)
{
- for (int i = 0; i < cdthis->baseclasses->dim; i++)
- { BaseClass *b = (BaseClass *)cdthis->baseclasses->data[i];
+ for (size_t i = 0; i < cdthis->baseclasses->dim; i++)
+ { BaseClass *b = (*cdthis->baseclasses)[i];
if (accessCheckX(smember, sfunc, b->base, cdscope))
return 1;
@@ -219,12 +214,12 @@ void AggregateDeclaration::accessCheck(Loc loc, Scope *sc, Dsymbol *smember)
//assert(smember->parent->isBaseOf(this, NULL));
if (smemberparent == this)
- { enum PROT access = smember->prot();
+ { enum PROT access2 = smember->prot();
- result = access >= PROTpublic ||
+ result = access2 >= PROTpublic ||
hasPrivateAccess(f) ||
isFriendOf(cdscope) ||
- (access == PROTpackage && hasPackageAccess(sc, this));
+ (access2 == PROTpackage && hasPackageAccess(sc, this));
#if LOG
printf("result1 = %d\n", result);
#endif
View
21 dmd/aggregate.h
@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
-// Copyright (c) 1999-2008 by Digital Mars
+// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -61,7 +61,7 @@ struct AggregateDeclaration : ScopeDsymbol
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
+ VarDeclarations fields; // VarDeclaration fields
unsigned sizeok; // set when structsize contains valid data
// 0: no size
// 1: size is correct
@@ -82,6 +82,7 @@ struct AggregateDeclaration : ScopeDsymbol
Dsymbol *ctor; // CtorDeclaration or TemplateDeclaration
CtorDeclaration *defaultCtor; // default constructor
Dsymbol *aliasthis; // forward unresolved lookups to aliasthis
+ bool noDefaultCtor; // no default construction
#endif
FuncDeclarations dtors; // Array of destructors
@@ -99,6 +100,8 @@ struct AggregateDeclaration : ScopeDsymbol
static void alignmember(unsigned salign, unsigned size, unsigned *poffset);
Type *getType();
void addField(Scope *sc, VarDeclaration *v);
+ int firstFieldInUnion(int indx); // first field in union that includes indx
+ int numFieldsInUnion(int firstIndex); // #fields in union starting at index
int isDeprecated(); // is aggregate deprecated?
FuncDeclaration *buildDtor(Scope *sc);
int isNested();
@@ -146,6 +149,7 @@ struct StructDeclaration : AggregateDeclaration
#if DMDV2
int hasIdentityAssign; // !=0 if has identity opAssign
FuncDeclaration *cpctor; // generated copy-constructor, if any
+ FuncDeclaration *eq; // bool opEquals(ref const T), if any
FuncDeclarations postblits; // Array of postblit functions
FuncDeclaration *postblit; // aggregate postblit
@@ -202,17 +206,17 @@ struct BaseClass
ClassDeclaration *base;
int offset; // 'this' pointer offset
- Array vtbl; // for interfaces: Array of FuncDeclaration's
+ FuncDeclarations vtbl; // for interfaces: Array of FuncDeclaration's
// making up the vtbl[]
- int baseInterfaces_dim;
+ size_t baseInterfaces_dim;
BaseClass *baseInterfaces; // if BaseClass is an interface, these
// are a copy of the InterfaceDeclaration::interfaces
BaseClass();
BaseClass(Type *type, enum PROT protection);
- int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance);
+ int fillVtbl(ClassDeclaration *cd, FuncDeclarations *vtbl, int newinstance);
void copyBaseInterfaces(BaseClasses *);
};
@@ -227,6 +231,7 @@ struct ClassDeclaration : AggregateDeclaration
{
static ClassDeclaration *object;
static ClassDeclaration *classinfo;
+ static ClassDeclaration *errorException;
ClassDeclaration *baseClass; // NULL only if this is Object
#if DMDV1
@@ -235,13 +240,13 @@ struct ClassDeclaration : AggregateDeclaration
#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[]
+ Dsymbols vtbl; // Array of FuncDeclaration's making up the vtbl[]
+ Dsymbols vtblFinal; // More FuncDeclaration's that aren't in vtbl[]
BaseClasses *baseclasses; // Array of BaseClass's; first is super,
// rest are Interface's
- int interfaces_dim;
+ size_t interfaces_dim;
BaseClass **interfaces; // interfaces[interfaces_dim] for this class
// (does not include baseClass)
View
414 dmd/arrayop.c
@@ -1,5 +1,5 @@
-// Copyright (c) 1999-2010 by Digital Mars
+// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -13,7 +13,7 @@
#include "rmem.h"
-#include "stringtable.h"
+#include "aav.h"
#include "expression.h"
#include "statement.h"
@@ -31,7 +31,7 @@ extern int binary(const char *p , const char **tab, int high);
* Hash table of array op functions already generated or known about.
*/
-StringTable arrayfuncs;
+AA *arrayfuncs;
#endif
/**********************************************
@@ -125,192 +125,195 @@ Expression *BinExp::arrayOp(Scope *sc)
size_t namelen = buf.offset;
buf.writeByte(0);
- char *name = (char *)buf.extractData();
+ char *name = buf.toChars();
+ Identifier *ident = Lexer::idPool(name);
/* Look up name in hash table
*/
+#if IN_DMD
+ FuncDeclaration **pfd = (FuncDeclaration **)_aaGet(&arrayfuncs, ident);
+ FuncDeclaration *fd = (FuncDeclaration *)*pfd;
+#elif IN_LLVM
StringValue *sv = sc->module->arrayfuncs.update(name, namelen);
FuncDeclaration *fd = (FuncDeclaration *)sv->ptrvalue;
+#endif
if (!fd)
{
-// /* Some of the array op functions are written as library functions,
-// * presumably to optimize them with special CPU vector instructions.
-// * List those library functions here, in alpha order.
-// */
-// static const char *libArrayopFuncs[] =
-// {
-// "_arrayExpSliceAddass_a",
-// "_arrayExpSliceAddass_d", // T[]+=T
-// "_arrayExpSliceAddass_f", // T[]+=T
-// "_arrayExpSliceAddass_g",
-// "_arrayExpSliceAddass_h",
-// "_arrayExpSliceAddass_i",
-// "_arrayExpSliceAddass_k",
-// "_arrayExpSliceAddass_s",
-// "_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[]
-// "_arrayExpSliceMinSliceAssign_g",
-// "_arrayExpSliceMinSliceAssign_h",
-// "_arrayExpSliceMinSliceAssign_i",
-// "_arrayExpSliceMinSliceAssign_k",
-// "_arrayExpSliceMinSliceAssign_s",
-// "_arrayExpSliceMinSliceAssign_t",
-// "_arrayExpSliceMinSliceAssign_u",
-// "_arrayExpSliceMinSliceAssign_w",
-//
-// "_arrayExpSliceMinass_a",
-// "_arrayExpSliceMinass_d", // T[]-=T
-// "_arrayExpSliceMinass_f", // T[]-=T
-// "_arrayExpSliceMinass_g",
-// "_arrayExpSliceMinass_h",
-// "_arrayExpSliceMinass_i",
-// "_arrayExpSliceMinass_k",
-// "_arrayExpSliceMinass_s",
-// "_arrayExpSliceMinass_t",
-// "_arrayExpSliceMinass_u",
-// "_arrayExpSliceMinass_w",
-//
-// "_arrayExpSliceMulass_d", // T[]*=T
-// "_arrayExpSliceMulass_f", // T[]*=T
-// "_arrayExpSliceMulass_i",
-// "_arrayExpSliceMulass_k",
-// "_arrayExpSliceMulass_s",
-// "_arrayExpSliceMulass_t",
-// "_arrayExpSliceMulass_u",
-// "_arrayExpSliceMulass_w",
-//
-// "_arraySliceExpAddSliceAssign_a",
-// "_arraySliceExpAddSliceAssign_d", // T[]=T[]+T
-// "_arraySliceExpAddSliceAssign_f", // T[]=T[]+T
-// "_arraySliceExpAddSliceAssign_g",
-// "_arraySliceExpAddSliceAssign_h",
-// "_arraySliceExpAddSliceAssign_i",
-// "_arraySliceExpAddSliceAssign_k",
-// "_arraySliceExpAddSliceAssign_s",
-// "_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
-// "_arraySliceExpMinSliceAssign_g",
-// "_arraySliceExpMinSliceAssign_h",
-// "_arraySliceExpMinSliceAssign_i",
-// "_arraySliceExpMinSliceAssign_k",
-// "_arraySliceExpMinSliceAssign_s",
-// "_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",
-// "_arraySliceExpMulSliceAssign_k",
-// "_arraySliceExpMulSliceAssign_s",
-// "_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[]
-// "_arraySliceSliceAddSliceAssign_g",
-// "_arraySliceSliceAddSliceAssign_h",
-// "_arraySliceSliceAddSliceAssign_i",
-// "_arraySliceSliceAddSliceAssign_k",
-// "_arraySliceSliceAddSliceAssign_r", // T[]=T[]+T[]
-// "_arraySliceSliceAddSliceAssign_s",
-// "_arraySliceSliceAddSliceAssign_t",
-// "_arraySliceSliceAddSliceAssign_u",
-// "_arraySliceSliceAddSliceAssign_w",
-//
-// "_arraySliceSliceAddass_a",
-// "_arraySliceSliceAddass_d", // T[]+=T[]
-// "_arraySliceSliceAddass_f", // T[]+=T[]
-// "_arraySliceSliceAddass_g",
-// "_arraySliceSliceAddass_h",
-// "_arraySliceSliceAddass_i",
-// "_arraySliceSliceAddass_k",
-// "_arraySliceSliceAddass_s",
-// "_arraySliceSliceAddass_t",
-// "_arraySliceSliceAddass_u",
-// "_arraySliceSliceAddass_w",
-//
-// "_arraySliceSliceMinSliceAssign_a",
-// "_arraySliceSliceMinSliceAssign_d", // T[]=T[]-T[]
-// "_arraySliceSliceMinSliceAssign_f", // T[]=T[]-T[]
-// "_arraySliceSliceMinSliceAssign_g",
-// "_arraySliceSliceMinSliceAssign_h",
-// "_arraySliceSliceMinSliceAssign_i",
-// "_arraySliceSliceMinSliceAssign_k",
-// "_arraySliceSliceMinSliceAssign_r", // T[]=T[]-T[]
-// "_arraySliceSliceMinSliceAssign_s",
-// "_arraySliceSliceMinSliceAssign_t",
-// "_arraySliceSliceMinSliceAssign_u",
-// "_arraySliceSliceMinSliceAssign_w",
-//
-// "_arraySliceSliceMinass_a",
-// "_arraySliceSliceMinass_d", // T[]-=T[]
-// "_arraySliceSliceMinass_f", // T[]-=T[]
-// "_arraySliceSliceMinass_g",
-// "_arraySliceSliceMinass_h",
-// "_arraySliceSliceMinass_i",
-// "_arraySliceSliceMinass_k",
-// "_arraySliceSliceMinass_s",
-// "_arraySliceSliceMinass_t",
-// "_arraySliceSliceMinass_u",
-// "_arraySliceSliceMinass_w",
-//
-// "_arraySliceSliceMulSliceAssign_d", // T[]=T[]*T[]
-// "_arraySliceSliceMulSliceAssign_f", // T[]=T[]*T[]
-// "_arraySliceSliceMulSliceAssign_i",
-// "_arraySliceSliceMulSliceAssign_k",
-// "_arraySliceSliceMulSliceAssign_s",
-// "_arraySliceSliceMulSliceAssign_t",
-// "_arraySliceSliceMulSliceAssign_u",
-// "_arraySliceSliceMulSliceAssign_w",
-//
-// "_arraySliceSliceMulass_d", // T[]*=T[]
-// "_arraySliceSliceMulass_f", // T[]*=T[]
-// "_arraySliceSliceMulass_i",
-// "_arraySliceSliceMulass_k",
-// "_arraySliceSliceMulass_s",
-// "_arraySliceSliceMulass_t",
-// "_arraySliceSliceMulass_u",
-// "_arraySliceSliceMulass_w",
-// };
-//
-// int i = binary(name, libArrayopFuncs, sizeof(libArrayopFuncs) / sizeof(char *));
-// if (i == -1)
-// {
-// #ifdef DEBUG // Make sure our array is alphabetized
-// for (i = 0; i < sizeof(libArrayopFuncs) / sizeof(char *); i++)
-// {
-// if (strcmp(name, libArrayopFuncs[i]) == 0)
-// assert(0);
-// }
-// #endif
-
+#if IN_DMD
+ static const char *libArrayopFuncs[] =
+ {
+ "_arrayExpSliceAddass_a",
+ "_arrayExpSliceAddass_d", // T[]+=T
+ "_arrayExpSliceAddass_f", // T[]+=T
+ "_arrayExpSliceAddass_g",
+ "_arrayExpSliceAddass_h",
+ "_arrayExpSliceAddass_i",
+ "_arrayExpSliceAddass_k",
+ "_arrayExpSliceAddass_s",
+ "_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[]
+ "_arrayExpSliceMinSliceAssign_g",
+ "_arrayExpSliceMinSliceAssign_h",
+ "_arrayExpSliceMinSliceAssign_i",
+ "_arrayExpSliceMinSliceAssign_k",
+ "_arrayExpSliceMinSliceAssign_s",
+ "_arrayExpSliceMinSliceAssign_t",
+ "_arrayExpSliceMinSliceAssign_u",
+ "_arrayExpSliceMinSliceAssign_w",
+
+ "_arrayExpSliceMinass_a",
+ "_arrayExpSliceMinass_d", // T[]-=T
+ "_arrayExpSliceMinass_f", // T[]-=T
+ "_arrayExpSliceMinass_g",
+ "_arrayExpSliceMinass_h",
+ "_arrayExpSliceMinass_i",
+ "_arrayExpSliceMinass_k",
+ "_arrayExpSliceMinass_s",
+ "_arrayExpSliceMinass_t",
+ "_arrayExpSliceMinass_u",
+ "_arrayExpSliceMinass_w",
+
+ "_arrayExpSliceMulass_d", // T[]*=T
+ "_arrayExpSliceMulass_f", // T[]*=T
+ "_arrayExpSliceMulass_i",
+ "_arrayExpSliceMulass_k",
+ "_arrayExpSliceMulass_s",
+ "_arrayExpSliceMulass_t",
+ "_arrayExpSliceMulass_u",
+ "_arrayExpSliceMulass_w",
+
+ "_arraySliceExpAddSliceAssign_a",
+ "_arraySliceExpAddSliceAssign_d", // T[]=T[]+T
+ "_arraySliceExpAddSliceAssign_f", // T[]=T[]+T
+ "_arraySliceExpAddSliceAssign_g",
+ "_arraySliceExpAddSliceAssign_h",
+ "_arraySliceExpAddSliceAssign_i",
+ "_arraySliceExpAddSliceAssign_k",
+ "_arraySliceExpAddSliceAssign_s",
+ "_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
+ "_arraySliceExpMinSliceAssign_g",
+ "_arraySliceExpMinSliceAssign_h",
+ "_arraySliceExpMinSliceAssign_i",
+ "_arraySliceExpMinSliceAssign_k",
+ "_arraySliceExpMinSliceAssign_s",
+ "_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",
+ "_arraySliceExpMulSliceAssign_k",
+ "_arraySliceExpMulSliceAssign_s",
+ "_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[]
+ "_arraySliceSliceAddSliceAssign_g",
+ "_arraySliceSliceAddSliceAssign_h",
+ "_arraySliceSliceAddSliceAssign_i",
+ "_arraySliceSliceAddSliceAssign_k",
+ "_arraySliceSliceAddSliceAssign_r", // T[]=T[]+T[]
+ "_arraySliceSliceAddSliceAssign_s",
+ "_arraySliceSliceAddSliceAssign_t",
+ "_arraySliceSliceAddSliceAssign_u",
+ "_arraySliceSliceAddSliceAssign_w",
+
+ "_arraySliceSliceAddass_a",
+ "_arraySliceSliceAddass_d", // T[]+=T[]
+ "_arraySliceSliceAddass_f", // T[]+=T[]
+ "_arraySliceSliceAddass_g",
+ "_arraySliceSliceAddass_h",
+ "_arraySliceSliceAddass_i",
+ "_arraySliceSliceAddass_k",
+ "_arraySliceSliceAddass_s",
+ "_arraySliceSliceAddass_t",
+ "_arraySliceSliceAddass_u",
+ "_arraySliceSliceAddass_w",
+
+ "_arraySliceSliceMinSliceAssign_a",
+ "_arraySliceSliceMinSliceAssign_d", // T[]=T[]-T[]
+ "_arraySliceSliceMinSliceAssign_f", // T[]=T[]-T[]
+ "_arraySliceSliceMinSliceAssign_g",
+ "_arraySliceSliceMinSliceAssign_h",
+ "_arraySliceSliceMinSliceAssign_i",
+ "_arraySliceSliceMinSliceAssign_k",
+ "_arraySliceSliceMinSliceAssign_r", // T[]=T[]-T[]
+ "_arraySliceSliceMinSliceAssign_s",
+ "_arraySliceSliceMinSliceAssign_t",
+ "_arraySliceSliceMinSliceAssign_u",
+ "_arraySliceSliceMinSliceAssign_w",
+
+ "_arraySliceSliceMinass_a",
+ "_arraySliceSliceMinass_d", // T[]-=T[]
+ "_arraySliceSliceMinass_f", // T[]-=T[]
+ "_arraySliceSliceMinass_g",
+ "_arraySliceSliceMinass_h",
+ "_arraySliceSliceMinass_i",
+ "_arraySliceSliceMinass_k",
+ "_arraySliceSliceMinass_s",
+ "_arraySliceSliceMinass_t",
+ "_arraySliceSliceMinass_u",
+ "_arraySliceSliceMinass_w",
+
+ "_arraySliceSliceMulSliceAssign_d", // T[]=T[]*T[]
+ "_arraySliceSliceMulSliceAssign_f", // T[]=T[]*T[]
+ "_arraySliceSliceMulSliceAssign_i",
+ "_arraySliceSliceMulSliceAssign_k",
+ "_arraySliceSliceMulSliceAssign_s",
+ "_arraySliceSliceMulSliceAssign_t",
+ "_arraySliceSliceMulSliceAssign_u",
+ "_arraySliceSliceMulSliceAssign_w",
+
+ "_arraySliceSliceMulass_d", // T[]*=T[]
+ "_arraySliceSliceMulass_f", // T[]*=T[]
+ "_arraySliceSliceMulass_i",
+ "_arraySliceSliceMulass_k",
+ "_arraySliceSliceMulass_s",
+ "_arraySliceSliceMulass_t",
+ "_arraySliceSliceMulass_u",
+ "_arraySliceSliceMulass_w",
+ };
+
+ int i = binary(name, libArrayopFuncs, sizeof(libArrayopFuncs) / sizeof(char *));
+ if (i == -1)
+ {
+#ifdef DEBUG // Make sure our array is alphabetized
+ for (i = 0; i < sizeof(libArrayopFuncs) / sizeof(char *); i++)
+ {
+ if (strcmp(name, libArrayopFuncs[i]) == 0)
+ assert(0);
+ }
+#endif
+#endif
/* Not in library, so generate it.
* Construct the function body:
* foreach (i; 0 .. p.length) for (size_t i = 0; i < p.length; i++)
@@ -320,13 +323,13 @@ Expression *BinExp::arrayOp(Scope *sc)
Parameters *fparams = new Parameters();
Expression *loopbody = buildArrayLoop(fparams);
- Parameter *p = (Parameter *)fparams->data[0 /*fparams->dim - 1*/];
+ Parameter *p = (*fparams)[0 /*fparams->dim - 1*/];
#if DMDV1
// for (size_t i = 0; i < p.length; i++)
Initializer *init = new ExpInitializer(0, new IntegerExp(0, 0, Type::tsize_t));
Dsymbol *d = new VarDeclaration(0, Type::tsize_t, Id::p, init);
Statement *s1 = new ForStatement(0,
- new DeclarationStatement(0, d),
+ new ExpStatement(0, d),
new CmpExp(TOKlt, 0, new IdentifierExp(0, Id::p), new ArrayLengthExp(0, new IdentifierExp(0, p->ident))),
new PostExp(TOKplusplus, 0, new IdentifierExp(0, Id::p)),
new ExpStatement(0, loopbody));
@@ -346,32 +349,33 @@ Expression *BinExp::arrayOp(Scope *sc)
*/
TypeFunction *ftype = new TypeFunction(fparams, type, 0, LINKc);
//printf("ftype: %s\n", ftype->toChars());
- fd = new FuncDeclaration(0, 0, Lexer::idPool(name), STCundefined, ftype);
+ fd = new FuncDeclaration(loc, 0, ident, STCundefined, ftype);
fd->fbody = fbody;
fd->protection = PROTpublic;
- fd->linkage = LINKd;
-
- // special attention for array ops
- fd->isArrayOp = true;
+ fd->linkage = LINKc;
+ fd->isArrayOp = 1;
sc->module->importedFrom->members->push(fd);
sc = sc->push();
sc->parent = sc->module->importedFrom;
sc->stc = 0;
- sc->linkage = LINKd;
+ sc->linkage = LINKc;
fd->semantic(sc);
fd->semantic2(sc);
fd->semantic3(sc);
sc->pop();
-// }
-// else
-// { /* In library, refer to it.
-// */
-// // FIXME
-// fd = FuncDeclaration::genCfunc(NULL, type, name);
-// }
+#if IN_DMD
+ }
+ else
+ { /* In library, refer to it.
+ */
+ fd = FuncDeclaration::genCfunc(type, ident);
+ }
+ *pfd = fd; // cache symbol in hash table
+#elif IN_LLVM
sv->ptrvalue = fd; // cache symbol in hash table
+#endif
}
/* Call the function fd(arguments)
@@ -438,6 +442,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
+#if DMDV2
+X(Pow)
+#endif
#undef X
@@ -471,6 +478,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
+#if DMDV2
+X(Pow)
+#endif
#undef X
@@ -526,7 +536,7 @@ Expression *AssignExp::buildArrayLoop(Parameters *fparams)
ex2 = new CastExp(0, ex2, e1->type->nextOf());
#endif
Expression *ex1 = e1->buildArrayLoop(fparams);
- Parameter *param = (Parameter *)fparams->data[0];
+ Parameter *param = (*fparams)[0];
param->storageClass = 0;
Expression *e = new AssignExp(0, ex1, ex2);
return e;
@@ -539,7 +549,7 @@ Expression *Str##AssignExp::buildArrayLoop(Parameters *fparams) \
*/ \
Expression *ex2 = e2->buildArrayLoop(fparams); \
Expression *ex1 = e1->buildArrayLoop(fparams); \
- Parameter *param = (Parameter *)fparams->data[0]; \
+ Parameter *param = (*fparams)[0]; \
param->storageClass = 0; \
Expression *e = new Str##AssignExp(0, ex1, ex2); \
return e; \
@@ -553,6 +563,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
+#if DMDV2
+X(Pow)
+#endif
#undef X
@@ -589,6 +602,9 @@ X(Mod)
X(Xor)
X(And)
X(Or)
+#if DMDV2
+X(Pow)
+#endif
#undef X
View
36 dmd/arraytypes.h
@@ -26,26 +26,40 @@ struct FuncDeclaration;
struct Identifier;
struct Initializer;
-struct TemplateParameters : Array { };
+typedef ArrayBase<struct TemplateParameter> TemplateParameters;
-struct Expressions : Array { };
+typedef ArrayBase<struct Expression> Expressions;
-struct Statements : Array { };
+typedef ArrayBase<struct Statement> Statements;
-struct BaseClasses : Array { };
+typedef ArrayBase<struct BaseClass> BaseClasses;
-struct ClassDeclarations : Array { };
+typedef ArrayBase<struct ClassDeclaration> ClassDeclarations;
-struct Dsymbols : Array { };
+typedef ArrayBase<struct Dsymbol> Dsymbols;
-struct Objects : Array { };
+typedef ArrayBase<struct Object> Objects;
-struct FuncDeclarations : Array { };
+typedef ArrayBase<struct FuncDeclaration> FuncDeclarations;
-struct Parameters : Array { };
+typedef ArrayBase<struct Parameter> Parameters;
-struct Identifiers : Array { };
+typedef ArrayBase<struct Identifier> Identifiers;
-struct Initializers : Array { };
+typedef ArrayBase<struct Initializer> Initializers;
+
+typedef ArrayBase<struct VarDeclaration> VarDeclarations;
+
+typedef ArrayBase<struct Type> Types;
+
+typedef ArrayBase<struct ScopeDsymbol> ScopeDsymbols;
+typedef ArrayBase<struct StaticDtorDeclaration> StaticDtorDeclarations;
+
+typedef ArrayBase<struct SharedStaticDtorDeclaration> SharedStaticDtorDeclarations;
+typedef ArrayBase<struct Module> Modules;
+typedef ArrayBase<struct CaseStatement> CaseStatements;
+typedef ArrayBase<struct TemplateInstance> TemplateInstances;
+
+typedef ArrayBase<struct Symbol> Symbols;
#endif
View
186 dmd/attrib.c
@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
-// Copyright (c) 1999-2010 by Digital Mars
+// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -51,26 +51,27 @@ void obj_startaddress(Symbol *s);
/********************************* AttribDeclaration ****************************/
-AttribDeclaration::AttribDeclaration(Array *decl)
+AttribDeclaration::AttribDeclaration(Dsymbols *decl)
: Dsymbol()
{
this->decl = decl;
}
-Array *AttribDeclaration::include(Scope *sc, ScopeDsymbol *sd)
+Dsymbols *AttribDeclaration::include(Scope *sc, ScopeDsymbol *sd)
{
return decl;
}
int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
{
int m = 0;
- Array *d = include(sc, sd);
+ Dsymbols *d = include(sc, sd);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
+ { Dsymbol *s = d->tdata()[i];
+ //printf("\taddMember %s to %s\n", s->toChars(), sd->toChars());
m |= s->addMember(sc, sd, m | memnum);
}
}
@@ -100,7 +101,7 @@ void AttribDeclaration::setScopeNewSc(Scope *sc,
newsc->structalign = structalign;
}
for (unsigned i = 0; i < decl->dim; i++)
- { Dsymbol *s = (Dsymbol *)decl->data[i];
+ { Dsymbol *s = decl->tdata()[i];
s->setScope(newsc); // yes, the only difference from semanticNewSc()
}
@@ -135,7 +136,7 @@ void AttribDeclaration::semanticNewSc(Scope *sc,
newsc->structalign = structalign;
}
for (unsigned i = 0; i < decl->dim; i++)
- { Dsymbol *s = (Dsymbol *)decl->data[i];
+ { Dsymbol *s = decl->tdata()[i];
s->semantic(newsc);
}
@@ -149,14 +150,14 @@ void AttribDeclaration::semanticNewSc(Scope *sc,
void AttribDeclaration::semantic(Scope *sc)
{
- Array *d = include(sc, NULL);
+ Dsymbols *d = include(sc, NULL);
//printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d);
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
+ for (size_t i = 0; i < d->dim; i++)
{
- Dsymbol *s = (Dsymbol *)d->data[i];
+ Dsymbol *s = d->tdata()[i];
s->semantic(sc);
}
@@ -165,38 +166,38 @@ void AttribDeclaration::semantic(Scope *sc)
void AttribDeclaration::semantic2(Scope *sc)
{
- Array *d = include(sc, NULL);
+ Dsymbols *d = include(sc, NULL);
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
+ for (size_t i = 0; i < d->dim; i++)
+ { Dsymbol *s = d->tdata()[i];
s->semantic2(sc);
}
}
}
void AttribDeclaration::semantic3(Scope *sc)
{
- Array *d = include(sc, NULL);
+ Dsymbols *d = include(sc, NULL);
if (d)
{
- for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
+ for (size_t i = 0; i < d->dim; i++)
+ { Dsymbol *s = d->tdata()[i];
s->semantic3(sc);
}
}
}
void AttribDeclaration::inlineScan()
{
- Array *d = include(NULL, NULL);
+ Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
+ { Dsymbol *s = d->tdata()[i];
//printf("AttribDeclaration::inlineScan %s\n", s->toChars());
s->inlineScan();
}
@@ -205,14 +206,15 @@ void AttribDeclaration::inlineScan()
void AttribDeclaration::addComment(unsigned char *comment)
{
+ //printf("AttribDeclaration::addComment %s\n", comment);
if (comment)
{
- Array *d = include(NULL, NULL);
+ Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
+ { Dsymbol *s = d->tdata()[i];
//printf("AttribDeclaration::addComment %s\n", s->toChars());
s->addComment(comment);
}
@@ -232,12 +234,12 @@ void AttribDeclaration::emitComment(Scope *sc)
* Hence, Ddoc omits attributes from template members.
*/
- Array *d = include(NULL, NULL);
+ Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
+ { Dsymbol *s = d->tdata()[i];
//printf("AttribDeclaration::emitComment %s\n", s->toChars());
s->emitComment(sc);
}
@@ -248,12 +250,12 @@ void AttribDeclaration::emitComment(Scope *sc)
void AttribDeclaration::toObjFile(int multiobj)
{
- Array *d = include(NULL, NULL);
+ Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
+ { Dsymbol *s = d->tdata()[i];
s->toObjFile(multiobj);
}
}
@@ -263,12 +265,12 @@ int AttribDeclaration::cvMember(unsigned char *p)
{
int nwritten = 0;
int n;
- Array *d = include(NULL, NULL);
+ Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
+ { Dsymbol *s = d->tdata()[i];
n = s->cvMember(p);
if (p)
p += n;
@@ -281,40 +283,56 @@ int AttribDeclaration::cvMember(unsigned char *p)
int AttribDeclaration::hasPointers()
{
- Array *d = include(NULL, NULL);
+ Dsymbols *d = include(NULL, NULL);
if (d)
{
for (size_t i = 0; i < d->dim; i++)
{
- Dsymbol *s = (Dsymbol *)d->data[i];
+ Dsymbol *s = d->tdata()[i];
if (s->hasPointers())
return 1;
}
}
return 0;
}
+bool AttribDeclaration::hasStaticCtorOrDtor()
+{
+ Dsymbols *d = include(NULL, NULL);
+
+ if (d)
+ {
+ for (size_t i = 0; i < d->dim; i++)
+ {
+ Dsymbol *s = (*d)[i];
+ if (s->hasStaticCtorOrDtor())
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
const char *AttribDeclaration::kind()
{
return "attribute";
}
int AttribDeclaration::oneMember(Dsymbol **ps)
{
- Array *d = include(NULL, NULL);
+ Dsymbols *d = include(NULL, NULL);
return Dsymbol::oneMembers(d, ps);
}
void AttribDeclaration::checkCtorConstInit()
{
- Array *d = include(NULL, NULL);
+ Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
+ { Dsymbol *s = d->tdata()[i];
s->checkCtorConstInit();
}
}
@@ -325,12 +343,12 @@ void AttribDeclaration::checkCtorConstInit()
void AttribDeclaration::addLocalClass(ClassDeclarations *aclasses)
{
- Array *d = include(NULL, NULL);
+ Dsymbols *d = include(NULL, NULL);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
+ { Dsymbol *s = d->tdata()[i];
s->addLocalClass(aclasses);
}
}
@@ -344,15 +362,15 @@ void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
if (decl->dim == 0)
buf->writestring("{}");
else if (decl->dim == 1)
- ((Dsymbol *)decl->data[0])->toCBuffer(buf, hgs);
+ (decl->tdata()[0])->toCBuffer(buf, hgs);
else
{
buf->writenl();
buf->writeByte('{');
buf->writenl();
for (unsigned i = 0; i < decl->dim; i++)
{
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ Dsymbol *s = decl->tdata()[i];
buf->writestring(" ");
s->toCBuffer(buf, hgs);
@@ -367,7 +385,7 @@ void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/************************* StorageClassDeclaration ****************************/
-StorageClassDeclaration::StorageClassDeclaration(StorageClass stc, Array *decl)
+StorageClassDeclaration::StorageClassDeclaration(StorageClass stc, Dsymbols *decl)
: AttribDeclaration(decl)
{
this->stc = stc;
@@ -509,7 +527,7 @@ void StorageClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* LinkDeclaration ****************************/
-LinkDeclaration::LinkDeclaration(enum LINK p, Array *decl)
+LinkDeclaration::LinkDeclaration(enum LINK p, Dsymbols *decl)
: AttribDeclaration(decl)
{
//printf("LinkDeclaration(linkage = %d, decl = %p)\n", p, decl);
@@ -552,7 +570,7 @@ void LinkDeclaration::semantic3(Scope *sc)
sc->linkage = linkage;
for (unsigned i = 0; i < decl->dim; i++)
{
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ Dsymbol *s = decl->tdata()[i];
s->semantic3(sc);
}
@@ -595,7 +613,7 @@ char *LinkDeclaration::toChars()
/********************************* ProtDeclaration ****************************/
-ProtDeclaration::ProtDeclaration(enum PROT p, Array *decl)
+ProtDeclaration::ProtDeclaration(enum PROT p, Dsymbols *decl)
: AttribDeclaration(decl)
{
protection = p;
@@ -632,9 +650,9 @@ void ProtDeclaration::importAll(Scope *sc)
newsc->explicitProtection = 1;
}
- for (int i = 0; i < decl->dim; i++)
+ for (size_t i = 0; i < decl->dim; i++)
{
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ Dsymbol *s = (*decl)[i];
s->importAll(newsc);
}
@@ -677,7 +695,7 @@ void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* AlignDeclaration ****************************/
-AlignDeclaration::AlignDeclaration(Loc loc, unsigned sa, Array *decl)
+AlignDeclaration::AlignDeclaration(Loc loc, unsigned sa, Dsymbols *decl)
: AttribDeclaration(decl)
{
this->loc = loc;
@@ -721,7 +739,7 @@ void AlignDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* AnonDeclaration ****************************/
-AnonDeclaration::AnonDeclaration(Loc loc, int isunion, Array *decl)
+AnonDeclaration::AnonDeclaration(Loc loc, int isunion, Dsymbols *decl)
: AttribDeclaration(decl)
{
this->loc = loc;
@@ -742,6 +760,12 @@ void AnonDeclaration::semantic(Scope *sc)
{
//printf("\tAnonDeclaration::semantic %s %p\n", isunion ? "union" : "struct", this);
+ if (sem == 1)
+ { //printf("already completed\n");
+ scope = NULL;
+ return; // semantic() already completed
+ }
+
Scope *scx = NULL;
if (scope)
{ sc = scope;
@@ -789,7 +813,7 @@ void AnonDeclaration::semantic(Scope *sc)
for (unsigned i = 0; i < decl->dim; i++)
{
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ Dsymbol *s = decl->tdata()[i];
s->semantic(sc);
if (isunion)
@@ -882,7 +906,7 @@ void AnonDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
for (unsigned i = 0; i < decl->dim; i++)
{
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ Dsymbol *s = decl->tdata()[i];
//buf->writestring(" ");
s->toCBuffer(buf, hgs);
@@ -912,7 +936,7 @@ static bool parseStringExp(Expression* e, std::string& res)
return false;
}
-PragmaDeclaration::PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl)
+PragmaDeclaration::PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Dsymbols *decl)
: AttribDeclaration(decl)
{
this->loc = loc;
@@ -942,15 +966,16 @@ void PragmaDeclaration::setScope(Scope *sc)
}
else
{
- Expression *e = (Expression *)args->data[0];
+ Expression *e = args->tdata()[0];
e = e->semantic(sc);
e = e->optimize(WANTvalue | WANTinterpret);
- args->data[0] = (void *)e;
- if (e->op != TOKstring)
+ args->tdata()[0] = e;
+ StringExp* se = e->toString();
+ if (!se)
{
error("string expected, not '%s'", e->toChars());
}
- PragmaScope* pragma = new PragmaScope(this, sc->parent, static_cast<StringExp*>(e));
+ PragmaScope* pragma = new PragmaScope(this, sc->parent, se);
assert(sc);
pragma->setScope(sc);
@@ -980,13 +1005,13 @@ void PragmaDeclaration::semantic(Scope *sc)
{
for (size_t i = 0; i < args->dim; i++)
{
- Expression *e = (Expression *)args->data[i];
+ Expression *e = args->tdata()[i];
e = e->semantic(sc);
e = e->optimize(WANTvalue | WANTinterpret);
- if (e->op == TOKstring)
+ StringExp *se = e->toString();
+ if (se)
{
- StringExp *se = (StringExp *)e;
fprintf(stdmsg, "%.*s", (int)se->len, (char *)se->string);
}
else
@@ -1002,16 +1027,18 @@ void PragmaDeclaration::semantic(Scope *sc)
error("string expected for library name");
else
{
- Expression *e = (Expression *)args->data[0];
+ Expression *e = args->tdata()[0];
e = e->semantic(sc);
e = e->optimize(WANTvalue | WANTinterpret);
- args->data[0] = (void *)e;
- if (e->op != TOKstring)
+ args->tdata()[0] = e;
+ if (e->op == TOKerror)
+ goto Lnodecl;
+ StringExp *se = e->toString();
+ if (!se)
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;
@@ -1043,10 +1070,11 @@ void PragmaDeclaration::semantic(Scope *sc)
if (!d)
error("first argument of GNU_asm must be a function or variable declaration");
- e = (Expression *)args->data[1];
+ e = args->tdata()[1];
e = e->semantic(sc);
e = e->optimize(WANTvalue);
- if (e->op == TOKstring && ((StringExp *)e)->sz == 1)
+ e = e->toString();
+ if (e && ((StringExp *)e)->sz == 1)
s = ((StringExp *)e);
else
error("second argument of GNU_asm must be a char string");
@@ -1307,7 +1335,7 @@ void PragmaDeclaration::semantic(Scope *sc)
{
for (unsigned i = 0; i < decl->dim; i++)
{
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ Dsymbol *s = decl->tdata()[i];
s->semantic(sc);
@@ -1492,7 +1520,7 @@ void PragmaDeclaration::toObjFile(int multiobj)
* so instead append the library name to the list to be passed
* to the linker.
*/
- global.params.libfiles->push((void *) name);
+ global.params.libfiles->push(name);
#else
error("pragma lib not supported");
#endif
@@ -1533,7 +1561,7 @@ void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/********************************* ConditionalDeclaration ****************************/
-ConditionalDeclaration::ConditionalDeclaration(Condition *condition, Array *decl, Array *elsedecl)
+ConditionalDeclaration::ConditionalDeclaration(Condition *condition, Dsymbols *decl, Dsymbols *elsedecl)
: AttribDeclaration(decl)
{
//printf("ConditionalDeclaration::ConditionalDeclaration()\n");
@@ -1558,7 +1586,7 @@ int ConditionalDeclaration::oneMember(Dsymbol **ps)
//printf("ConditionalDeclaration::oneMember(), inc = %d\n", condition->inc);
if (condition->inc)
{
- Array *d = condition->include(NULL, NULL) ? decl : elsedecl;
+ Dsymbols *d = condition->include(NULL, NULL) ? decl : elsedecl;
return Dsymbol::oneMembers(d, ps);
}
*ps = NULL;
@@ -1577,17 +1605,17 @@ void ConditionalDeclaration::emitComment(Scope *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;
+ Dsymbols *d = decl ? decl : elsedecl;
for (unsigned i = 0; i < d->dim; i++)
- { Dsymbol *s = (Dsymbol *)d->data[i];
+ { Dsymbol *s = d->tdata()[i];
s->emitComment(sc);
}
}
}
// Decide if 'then' or 'else' code should be included
-Array *ConditionalDeclaration::include(Scope *sc, ScopeDsymbol *sd)
+Dsymbols *ConditionalDeclaration::include(Scope *sc, ScopeDsymbol *sd)
{
//printf("ConditionalDeclaration::include()\n");
assert(condition);
@@ -1596,14 +1624,14 @@ Array *ConditionalDeclaration::include(Scope *sc, ScopeDsymbol *sd)
void ConditionalDeclaration::setScope(Scope *sc)
{
- Array *d = include(sc, NULL);
+ Dsymbols *d = include(sc, NULL);
//printf("\tConditionalDeclaration::setScope '%s', d = %p\n",toChars(), d);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{
- Dsymbol *s = (Dsymbol *)d->data[i];
+ Dsymbol *s = d->tdata()[i];
s->setScope(sc);
}
@@ -1612,14 +1640,14 @@ void ConditionalDeclaration::setScope(Scope *sc)
void ConditionalDeclaration::importAll(Scope *sc)
{
- Array *d = include(sc, NULL);
+ Dsymbols *d = include(sc, NULL);
//printf("\tConditionalDeclaration::importAll '%s', d = %p\n",toChars(), d);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{
- Dsymbol *s = (Dsymbol *)d->data[i];
+ Dsymbol *s = d->tdata()[i];
s->importAll(sc);
}
@@ -1636,7 +1664,7 @@ void ConditionalDeclaration::addComment(unsigned char *comment)
if (comment)
{
- Array *d = decl;
+ Dsymbols *d = decl;
for (int j = 0; j < 2; j++)
{
@@ -1645,7 +1673,7 @@ void ConditionalDeclaration::addComment(unsigned char *comment)
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s;
- s = (Dsymbol *)d->data[i];
+ s = d->tdata()[i];
//printf("ConditionalDeclaration::addComment %s\n", s->toChars());
s->addComment(comment);
}
@@ -1667,7 +1695,7 @@ void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
for (unsigned i = 0; i < decl->dim; i++)
{
- Dsymbol *s = (Dsymbol *)decl->data[i];
+ Dsymbol *s = decl->tdata()[i];
buf->writestring(" ");
s->toCBuffer(buf, hgs);
@@ -1683,7 +1711,7 @@ void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writenl();
for (unsigned i = 0; i < elsedecl->dim; i++)
{
- Dsymbol *s = (Dsymbol *)elsedecl->data[i];
+ Dsymbol *s = elsedecl->tdata()[i];
buf->writestring(" ");
s->toCBuffer(buf, hgs);
@@ -1699,7 +1727,7 @@ void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
/***************************** StaticIfDeclaration ****************************/
StaticIfDeclaration::StaticIfDeclaration(Condition *condition,
- Array *decl, Array *elsedecl)
+ Dsymbols *decl, Dsymbols *elsedecl)
: ConditionalDeclaration(condition, decl, elsedecl)
{
//printf("StaticIfDeclaration::StaticIfDeclaration()\n");
@@ -1757,7 +1785,7 @@ void StaticIfDeclaration::setScope(Scope *sc)
void StaticIfDeclaration::semantic(Scope *sc)
{
- Array *d = include(sc, sd);
+ Dsymbols *d = include(sc, sd);
//printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d);
if (d)
@@ -1769,7 +1797,7 @@ void StaticIfDeclaration::semantic(Scope *sc)
for (unsigned i = 0; i < d->dim; i++)
{
- Dsymbol *s = (Dsymbol *)d->data[i];
+ Dsymbol *s = d->tdata()[i];
s->semantic(sc);
}
@@ -1821,12 +1849,12 @@ void CompileDeclaration::compileIt(Scope *sc)
exp = exp->semantic(sc);
exp = resolveProperties(sc, exp);
exp = exp->optimize(WANTvalue | WANTinterpret);
- if (exp->op != TOKstring)
+ StringExp *se = exp->toString();
+ if (!se)
{ 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;
View
31 dmd/attrib.h
@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
-// Copyright (c) 1999-2009 by Digital Mars
+// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -23,18 +23,16 @@ struct LabelDsymbol;
struct Initializer;
struct Module;
struct Condition;
-#ifdef _DH
struct HdrGenState;
-#endif
/**************************************************************/
struct AttribDeclaration : Dsymbol
{
- Array *decl; // array of Dsymbol's
+ Dsymbols *decl; // array of Dsymbol's
- AttribDeclaration(Array *decl);
- virtual Array *include(Scope *sc, ScopeDsymbol *s);
+ AttribDeclaration(Dsymbols *decl);
+ virtual Dsymbols *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,
@@ -51,6 +49,7 @@ struct AttribDeclaration : Dsymbol
const char *kind();
int oneMember(Dsymbol **ps);
int hasPointers();
+ bool hasStaticCtorOrDtor();
void checkCtorConstInit();
void addLocalClass(ClassDeclarations *);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -71,7 +70,7 @@ struct StorageClassDeclaration: AttribDeclaration
{
StorageClass stc;
- StorageClassDeclaration(StorageClass stc, Array *decl);
+ StorageClassDeclaration(StorageClass stc, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void setScope(Scope *sc);
void semantic(Scope *sc);
@@ -84,7 +83,7 @@ struct LinkDeclaration : AttribDeclaration
{
enum LINK linkage;
- LinkDeclaration(enum LINK p, Array *decl);
+ LinkDeclaration(enum LINK p, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void setScope(Scope *sc);
void semantic(Scope *sc);
@@ -97,7 +96,7 @@ struct ProtDeclaration : AttribDeclaration
{
enum PROT protection;
- ProtDeclaration(enum PROT p, Array *decl);
+ ProtDeclaration(enum PROT p, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void importAll(Scope *sc);
void setScope(Scope *sc);
@@ -111,7 +110,7 @@ struct AlignDeclaration : AttribDeclaration
{
unsigned salign;
- AlignDeclaration(Loc loc, unsigned sa, Array *decl);
+ AlignDeclaration(Loc loc, unsigned sa, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void setScope(Scope *sc);
void semantic(Scope *sc);
@@ -123,7 +122,7 @@ struct AnonDeclaration : AttribDeclaration
int isunion;
int sem; // 1 if successful semantic()
- AnonDeclaration(Loc loc, int isunion, Array *decl);
+ AnonDeclaration(Loc loc, int isunion, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void semantic(Scope *sc);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@@ -134,7 +133,7 @@ struct PragmaDeclaration : AttribDeclaration
{
Expressions *args; // array of Expression's
- PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl);
+ PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void semantic(Scope *sc);
void setScope(Scope *sc);
@@ -154,13 +153,13 @@ struct PragmaDeclaration : AttribDeclaration
struct ConditionalDeclaration : AttribDeclaration
{
Condition *condition;
- Array *elsedecl; // array of Dsymbol's for else block
+ Dsymbols *elsedecl; // array of Dsymbol's for else block
- ConditionalDeclaration(Condition *condition, Array *decl, Array *elsedecl);
+ ConditionalDeclaration(Condition *condition, Dsymbols *decl, Dsymbols *elsedecl);
Dsymbol *syntaxCopy(Dsymbol *s);
int oneMember(Dsymbol **ps);
void emitComment(Scope *sc);
- Array *include(Scope *sc, ScopeDsymbol *s);
+ Dsymbols *include(Scope *sc, ScopeDsymbol *s);
void addComment(unsigned char *comment);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void toJsonBuffer(OutBuffer *buf);
@@ -173,7 +172,7 @@ struct StaticIfDeclaration : ConditionalDeclaration
ScopeDsymbol *sd;
int addisdone;
- StaticIfDeclaration(Condition *condition, Array *decl, Array *elsedecl);
+ StaticIfDeclaration(Condition *condition, Dsymbols *decl, Dsymbols *elsedecl);
Dsymbol *syntaxCopy(Dsymbol *s);
int addMember(Scope *sc, ScopeDsymbol *s, int memnum);
void semantic(Scope *sc);
View
49 dmd/cast.c
@@ -1,5 +1,5 @@
-// Copyright (c) 1999-2010 by Digital Mars
+// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -123,6 +123,8 @@ MATCH Expression::implicitConvTo(Type *t)
toChars(), type->toChars(), t->toChars());
#endif
//static int nest; if (++nest == 10) halt();
+ if (t == Type::terror)
+ return MATCHnomatch;
if (!type)
{ error("%s is not an expression", toChars());
type = Type::terror;
@@ -377,8 +379,8 @@ MATCH StructLiteralExp::implicitConvTo(Type *t)
((TypeStruct *)type)->sym == ((TypeStruct *)t)->sym)
{
m = MATCHconst;
- for (int i = 0; i < elements->dim; i++)
- { Expression *e = (Expression *)elements->data[i];
+ for (size_t i = 0; i < elements->dim; i++)
+ { Expression *e = (*elements)[i];
Type *te = e->type;
if (t->mod == 0)
te = te->mutableOf();
@@ -397,8 +399,7 @@ MATCH StructLiteralExp::implicitConvTo(Type *t)
#endif
MATCH StringExp::implicitConvTo(Type *t)
-{ MATCH m;
-
+{
#if 0
printf("StringExp::implicitConvTo(this=%s, committed=%d, type=%s, t=%s)\n",
toChars(), committed, type->toChars(), t->toChars());
@@ -466,14 +467,18 @@ MATCH ArrayLiteralExp::implicitConvTo(Type *t)
result = MATCHnomatch;
}
- for (int i = 0; i < elements->dim; i++)
- { Expression *e = (Expression *)elements->data[i];
+ for (size_t i = 0; i < elements->dim; i++)
+ { Expression *e = (*elements)[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
}
+
+ if (!result)
+ result = type->implicitConvTo(t);
+
return result;
}
else
@@ -581,7 +586,6 @@ MATCH DelegateExp::implicitConvTo(Type *t)
if (result == 0)
{
// Look for pointers to functions where the functions are overloaded.
- FuncDeclaration *f;
t = t->toBasetype();
if (type->ty == Tdelegate && type->nextOf()->ty == Tfunction &&
@@ -663,6 +667,12 @@ Expression *Expression::castTo(Scope *sc, Type *t)
}
+Expression *ErrorExp::castTo(Scope *sc, Type *t)
+{
+ return this;
+}
+
+
Expression *RealExp::castTo(Scope *sc, Type *t)
{ Expression *e = this;
if (type != t)
@@ -745,8 +755,6 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
* will result in a copy.
* The this->string member is considered immutable.
*/
- StringExp *se;
- Type *tb;
int copied = 0;
//printf("StringExp::castTo(t = %s), '%s' committed = %d\n", t->toChars(), toChars(), committed);
@@ -757,7 +765,7 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
return new ErrorExp();
}
- se = this;
+ StringExp *se = this;
if (!committed)
{ se = (StringExp *)copy();
se->committed = 1;
@@ -769,7 +777,7 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
return se;
}
- tb = t->toBasetype();
+ Type *tb = t->toBasetype();
//printf("\ttype = %s\n", type->toChars());
if (tb->ty == Tdelegate && type->toBasetype()->ty != Tdelegate)
return Expression::castTo(sc, t);
@@ -913,7 +921,11 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
}
se->string = buffer.extractData();
se->len = newlen;
- se->sz = tb->nextOf()->size();
+ {
+ d_uns64 szx = tb->nextOf()->size();
+ assert(szx <= 255);
+ se->sz = (unsigned char)szx;
+ }
break;
default:
@@ -928,9 +940,9 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
// See if need to truncate or extend the literal
if (tb->ty == Tsarray)
{
- int dim2 = ((TypeSArray *)tb)->dim->toInteger();
+ dinteger_t dim2 = ((TypeSArray *)tb)->dim->toInteger();
- //printf("dim from = %d, to = %d\n", se->len, dim2);
+ //printf("dim from = %d, to = %d\n", (int)se->len, (int)dim2);
// Changing dimensions
if (dim2 != se->len)
@@ -1038,10 +1050,10 @@ Expression *ArrayLiteralExp::castTo(Scope *sc, Type *t)
e = (ArrayLiteralExp *)copy();
e->elements = (Expressions *)elements->copy();
- for (int i = 0; i < elements->dim; i++)
- { Expression *ex = (Expression *)elements->data[i];
+ for (size_t i = 0; i < elements->dim; i++)
+ { Expression *ex = (*elements)[i];
ex = ex->castTo(sc, tb->nextOf());
- e->elements->data[i] = (void *)ex;
+ (*e->elements)[i] = ex;
}
e->type = t;
return e;
@@ -1081,7 +1093,6 @@ Expression *AssocArrayLiteralExp::castTo(Scope *sc, Type *t)
e->type = t;
return e;
}
-L1:
return e->Expression::castTo(sc, t);
}
View
159 dmd/class.c
@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
-// Copyright (c) 1999-2010 by Digital Mars
+// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -31,6 +31,7 @@
ClassDeclaration *ClassDeclaration::classinfo;
ClassDeclaration *ClassDeclaration::object;
+ClassDeclaration *ClassDeclaration::errorException;
ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses)
: AggregateDeclaration(loc, id)
@@ -170,6 +171,12 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
Type::typeinfoshared->error("%s", msg);
Type::typeinfoshared = this;
}
+
+ if (id == Id::TypeInfo_Wild)
+ { if (Type::typeinfowild)
+ Type::typeinfowild->error("%s", msg);
+ Type::typeinfowild = this;
+ }
#endif
}
@@ -179,6 +186,12 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
object = this;
}
+ if (id == Id::Error)
+ { if (errorException)
+ errorException->error("%s", msg);
+ errorException = this;
+ }
+
if (id == Id::ClassInfo)
{ if (classinfo)
classinfo->error("%s", msg);
@@ -213,7 +226,7 @@ Dsymbol *ClassDeclaration::syntaxCopy(Dsymbol *s)
cd->storage_class |= storage_class;
cd->baseclasses->setDim(this->baseclasses->dim);
- for (int i = 0; i < cd->baseclasses->dim; i++)
+ for (size_t i = 0; i < cd->baseclasses->dim; i++)
{
BaseClass *b = (BaseClass *)this->baseclasses->data[i];
BaseClass *b2 = new BaseClass(b->type->syntaxCopy(), b->protection);
@@ -225,9 +238,7 @@ Dsymbol *ClassDeclaration::syntaxCopy(Dsymbol *s)
}
void ClassDeclaration::semantic(Scope *sc)
-{ int i;
- unsigned offset;
-
+{
//printf("ClassDeclaration::semantic(%s), type = %p, sizeok = %d, this = %p\n", toChars(), type, sizeok, this);
//printf("\tparent = %p, '%s'\n", sc->parent, sc->parent ? sc->parent->toChars() : "");
//printf("sc->stc = %x\n", sc->stc);
@@ -278,7 +289,7 @@ void ClassDeclaration::semantic(Scope *sc)
}
// Expand any tuples in baseclasses[]
- for (i = 0; i < baseclasses->dim; )
+ for (size_t i = 0; i < baseclasses->dim; )
{ BaseClass *b = (BaseClass *)baseclasses->data[i];
b->type = b->type->semantic(loc, sc);
Type *tb = b->type->toBasetype();
@@ -368,7 +379,7 @@ void ClassDeclaration::semantic(Scope *sc)
// Treat the remaining entries in baseclasses as interfaces
// Check for errors, handle forward references
- for (i = (baseClass ? 1 : 0); i < baseclasses->dim; )
+ for (size_t i = (baseClass ? 1 : 0); i < baseclasses->dim; )
{ TypeClass *tc;
BaseClass *b;
Type *tb;
@@ -490,7 +501,7 @@ void ClassDeclaration::semantic(Scope *sc)
{
interfaceSemantic(sc);
- for (i = 0; i < members->dim; i++)
+ for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
s->addMember(sc, this, 1);
@@ -536,9 +547,9 @@ void ClassDeclaration::semantic(Scope *sc)
if (ad)
t = ad->handle;
else if (fd)
- { AggregateDeclaration *ad = fd->isMember2();
- if (ad)
- t = ad->handle;
+ { AggregateDeclaration *ad2 = fd->isMember2();
+ if (ad2)
+ t = ad2->handle;
else
{
t = new TypePointer(Type::tvoid);
@@ -594,13 +605,13 @@ void ClassDeclaration::semantic(Scope *sc)
}
structsize = sc->offset;
Scope scsave = *sc;
- int members_dim = members->dim;
+ size_t members_dim = members->dim;
sizeok = 0;
/* Set scope so if there are forward references, we still might be able to
* resolve individual members like enums.
*/
- for (i = 0; i < members_dim; i++)
+ for (size_t 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'
@@ -612,7 +623,7 @@ void ClassDeclaration::semantic(Scope *sc)
}
}
- for (i = 0; i < members_dim; i++)
+ for (size_t i = 0; i < members_dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
s->semantic(sc);
}
@@ -688,7 +699,7 @@ void ClassDeclaration::semantic(Scope *sc)
#endif
// Allocate instance of each new interface
- for (i = 0; i < vtblInterfaces->dim; i++)
+ for (size_t i = 0; i < vtblInterfaces->dim; i++)
{
BaseClass *b = (BaseClass *)vtblInterfaces->data[i];
unsigned thissize = PTRSIZE;
@@ -737,7 +748,7 @@ void ClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
if (baseclasses->dim)
buf->writestring(" : ");
}
- for (int i = 0; i < baseclasses->dim; i++)
+ for (size_t i = 0; i < baseclasses->dim; i++)
{
BaseClass *b = (BaseClass *)baseclasses->data[i];
@@ -751,7 +762,7 @@ void ClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writenl();
buf->writeByte('{');
buf->writenl();
- for (int i = 0; i < members->dim; i++)
+ for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
@@ -787,7 +798,7 @@ int ClassDeclaration::isBaseOf2(ClassDeclaration *cd)
if (!cd)
return 0;
//printf("ClassDeclaration::isBaseOf2(this = '%s', cd = '%s')\n", toChars(), cd->toChars());
- for (int i = 0; i < cd->baseclasses->dim; i++)
+ for (size_t i = 0; i < cd->baseclasses->dim; i++)
{ BaseClass *b = (BaseClass *)cd->baseclasses->data[i];
if (b->base == this || isBaseOf2(b->base))
@@ -807,16 +818,18 @@ int ClassDeclaration::isBaseOf(ClassDeclaration *cd, int *poffset)
*poffset = 0;
while (cd)
{
- 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->semantic(NULL);
+ if (!cd->baseClass)
cd->error("base class is forward referenced by %s", toChars());
}
+ if (this == cd->baseClass)
+ return 1;
+
cd = cd->baseClass;
}
return 0;
@@ -831,7 +844,7 @@ int ClassDeclaration::isBaseInfoComplete()
{
if (!baseClass)
return ident == Id::Object;
- for (int i = 0; i < baseclasses->dim; i++)
+ for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *b = (BaseClass *)baseclasses->data[i];
if (!b->base || !b->base->isBaseInfoComplete())
return 0;
@@ -844,14 +857,14 @@ Dsymbol *ClassDeclaration::search(Loc loc, Identifier *ident, int flags)
Dsymbol *s;
//printf("%s.ClassDeclaration::search('%s')\n", toChars(), ident->toChars());
- if (scope)
+ if (scope && !symtab)
{ Scope *sc = scope;
sc->mustsemantic++;
semantic(sc);
sc->mustsemantic--;
}
- if (!members || !symtab || scope)
+ if (!members || !symtab)
{
error("is forward referenced when looking for '%s'", ident->toChars());
//*(char*)0=0;
@@ -863,9 +876,7 @@ Dsymbol *ClassDeclaration::search(Loc loc, Identifier *ident, int flags)
{
// Search bases classes in depth-first, left to right order
- int i;
-
- for (i = 0; i < baseclasses->dim; i++)
+ for (size_t i = 0; i < baseclasses->dim; i++)
{
BaseClass *b = (BaseClass *)baseclasses->data[i];
@@ -912,7 +923,10 @@ int ClassDeclaration::isFuncHidden(FuncDeclaration *fd)
}
FuncDeclaration *fdstart = s->toAlias()->isFuncDeclaration();
//printf("%s fdstart = %p\n", s->kind(), fdstart);
- return !overloadApply(getModule(), fdstart, &isf, fd);
+ if (overloadApply(fdstart, &isf, fd))
+ return 0;
+
+ return !fd->parent->isTemplateMixin();
}
#endif
@@ -924,24 +938,58 @@ int ClassDeclaration::isFuncHidden(FuncDeclaration *fd)
FuncDeclaration *ClassDeclaration::findFunc(Identifier *ident, TypeFunction *tf)
{
//printf("ClassDeclaration::findFunc(%s, %s) %s\n", ident->toChars(), tf->toChars(), toChars());
+ FuncDeclaration *fdmatch = NULL;
+ FuncDeclaration *fdambig = NULL;
ClassDeclaration *cd = this;
- Array *vtbl = &cd->vtbl;
+ Dsymbols *vtbl = &cd->vtbl;
while (1)
{
for (size_t i = 0; i < vtbl->dim; i++)
{
- FuncDeclaration *fd = ((Dsymbol*)vtbl->data[i])->isFuncDeclaration();
+ FuncDeclaration *fd = (*vtbl)[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;
+ fd->type->covariant(tf) == 1)
+ { //printf("fd->parent->isClassDeclaration() = %p", fd->parent->isClassDeclaration());
+ if (!fdmatch)
+ goto Lfd;
+
+ {
+ // Function type matcing: exact > covariant
+ int m1 = tf->equals(fd ->type) ? MATCHexact : MATCHnomatch;
+ int m2 = tf->equals(fdmatch->type) ? MATCHexact : MATCHnomatch;
+ if (m1 > m2)
+ goto Lfd;
+ else if (m1 < m2)
+ goto Lfdmatch;
+ }
+
+ {
+ // The way of definition: non-mixin > mixin
+ int m1 = fd ->parent->isClassDeclaration() ? MATCHexact : MATCHnomatch;
+ int m2 = fdmatch->parent->isClassDeclaration() ? MATCHexact : MATCHnomatch;
+ if (m1 > m2)
+ goto Lfd;
+ else if (m1 < m2)
+ goto Lfdmatch;
+ }
+
+ Lambig:
+ fdambig = fd;
+ //printf("Lambig fdambig = %s %s [%s]\n", fdambig->toChars(), fdambig->type->toChars(), fdambig->loc.toChars());
+ continue;
+
+ Lfd:
+ fdmatch = fd, fdambig = NULL;
+ //printf("Lfd fdmatch = %s %s [%s]\n", fdmatch->toChars(), fdmatch->type->toChars(), fdmatch->loc.toChars());
+ continue;
+
+ Lfdmatch:
+ continue;
}
//else printf("\t\t%d\n", fd->type->covariant(tf));
}
@@ -951,7 +999,9 @@ FuncDeclaration *ClassDeclaration::findFunc(Identifier *ident, TypeFunction *tf)
cd = cd->baseClass;
}
- return NULL;
+ if (fdambig)
+ error("ambiguous virtual function %s", fdambig->toChars());
+ return fdmatch;
}
void ClassDeclaration::interfaceSemantic(Scope *sc)
@@ -1001,7 +1051,7 @@ int ClassDeclaration::isAbstract()
{
if (isabstract)
return TRUE;
- for (int i = 1; i < vtbl.dim; i++)
+ for (size_t i = 1; i < vtbl.dim; i++)
{
FuncDeclaration *fd = ((Dsymbol *)vtbl.data[i])->isFuncDeclaration();