Permalink
Browse files

Added ArrayOf macro, renamed Array to ArrayBase, changed all direct u…

…ses of Array to type-cheched derivatives.
  • Loading branch information...
michelf committed Jun 26, 2011
1 parent 95229fe commit 8b3bb0dcf07e1b60edc90694ed77142e06b836fa
Showing with 293 additions and 205 deletions.
  1. +5 −5 src/aggregate.h
  2. +76 −11 src/arraytypes.h
  3. +2 −2 src/class.c
  4. +5 −5 src/cond.c
  5. +1 −1 src/cond.h
  6. +2 −2 src/cppmangle.c
  7. +3 −3 src/declaration.h
  8. +3 −1 src/doc.c
  9. +4 −4 src/dsymbol.c
  10. +4 −4 src/dsymbol.h
  11. +4 −4 src/e2ir.c
  12. +2 −2 src/func.c
  13. +4 −4 src/glue.c
  14. +1 −1 src/hdrgen.c
  15. +1 −1 src/import.c
  16. +5 −5 src/import.h
  17. +1 −1 src/inifile.c
  18. +1 −1 src/init.h
  19. +5 −5 src/inline.c
  20. +3 −3 src/irstate.h
  21. +2 −2 src/json.c
  22. +2 −2 src/json.h
  23. +7 −2 src/lib.h
  24. +1 −1 src/libomf.c
  25. +4 −2 src/link.c
  26. +14 −14 src/mars.c
  27. +14 −11 src/mars.h
  28. +5 −5 src/module.c
  29. +12 −12 src/module.h
  30. +1 −1 src/mtype.h
  31. +13 −13 src/parse.c
  32. +20 −20 src/root/array.c
  33. +11 −9 src/root/root.c
  34. +21 −13 src/root/root.h
  35. +2 −2 src/s2ir.c
  36. +0 −1 src/scope.h
  37. +6 −6 src/statement.c
  38. +7 −7 src/statement.h
  39. +4 −4 src/template.c
  40. +4 −4 src/template.h
  41. +2 −2 src/tocsym.c
  42. +5 −3 src/todt.c
  43. +2 −2 src/toobj.c
  44. +2 −2 src/version.c
View
@@ -45,7 +45,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
@@ -176,7 +176,7 @@ 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;
@@ -186,7 +186,7 @@ struct BaseClass
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 *);
};
@@ -210,8 +210,8 @@ 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[]
+ FuncDeclarations vtbl; // Array of FuncDeclaration's making up the vtbl[]
+ FuncDeclarations vtblFinal; // More FuncDeclaration's that aren't in vtbl[]
BaseClasses *baseclasses; // Array of BaseClass's; first is super,
// rest are Interface's
View
@@ -26,26 +26,91 @@ struct FuncDeclaration;
struct Identifier;
struct Initializer;
-struct TemplateParameters : Array { };
+struct Dsymbol;
+struct ClassDeclaration;
+struct Parameter;
+
+struct VarDeclaration;
+struct Type;
+struct ScopeDsymbol;
+struct Catch;
+struct StaticDtorDeclaration;
+struct SharedStaticDtorDeclaration;
+struct AliasDeclaration;
+struct Module;
+struct File;
+struct CaseStatement;
+struct CompoundStatement;
+struct GotoCaseStatement;
+struct TemplateInstance;
+struct TemplateParameter;
+
+struct block;
+struct Symbol;
+
+#define ArrayOf(TYPE) struct ArrayOf_##TYPE : ArrayBase \
+{ \
+ TYPE **tdata() { return (TYPE **)data; } \
+ void insert(unsigned index, TYPE *v) { ArrayBase::insert(index, (void *)v); } \
+ void insert(unsigned index, ArrayOf_##TYPE *a) { ArrayBase::insert(index, (ArrayBase *)a); } \
+ void append(ArrayOf_##TYPE *a) { ArrayBase::append((ArrayBase *)a); } \
+ ArrayOf_##TYPE *copy() { return (ArrayOf_##TYPE *)ArrayBase::copy(); } \
+}
+
+typedef ArrayOf(TemplateParameter) TemplateParameters;
+
+typedef ArrayOf(Expression) Expressions;
+
+typedef ArrayOf(Statement) Statements;
+
+typedef ArrayOf(BaseClass) BaseClasses;
+
+typedef ArrayOf(ClassDeclaration) ClassDeclarations;
+
+typedef ArrayOf(Dsymbol) Dsymbols;
+
+typedef ArrayOf(Object) Objects;
+
+typedef ArrayOf(FuncDeclaration) FuncDeclarations;
+
+typedef ArrayOf(Parameter) Parameters;
+
+typedef ArrayOf(Identifier) Identifiers;
+
+typedef ArrayOf(Initializer) Initializers;
+
+typedef ArrayOf(VarDeclaration) VarDeclarations;
+
+typedef ArrayOf(Type) Types;
+
+typedef ArrayOf(ScopeDsymbol) ScopeDsymbols;
+
+typedef ArrayOf(Catch) Catches;
+
+typedef ArrayOf(StaticDtorDeclaration) StaticDtorDeclarations;
+
+typedef ArrayOf(SharedStaticDtorDeclaration) SharedStaticDtorDeclarations;
+
+typedef ArrayOf(AliasDeclaration) AliasDeclarations;
-struct Expressions : Array { };
+typedef ArrayOf(Module) Modules;
-struct Statements : Array { };
+typedef ArrayOf(File) Files;
-struct BaseClasses : Array { };
+typedef ArrayOf(CaseStatement) CaseStatements;
-struct ClassDeclarations : Array { };
+typedef ArrayOf(CompoundStatement) CompoundStatements;
-struct Dsymbols : Array { };
+typedef ArrayOf(GotoCaseStatement) GotoCaseStatements;
-struct Objects : Array { };
+typedef ArrayOf(TemplateInstance) TemplateInstances;
-struct FuncDeclarations : Array { };
+typedef ArrayOf(char) Strings;
-struct Parameters : Array { };
+typedef ArrayOf(void) Voids;
-struct Identifiers : Array { };
+typedef ArrayOf(block) Blocks;
-struct Initializers : Array { };
+typedef ArrayOf(Symbol) Symbols;
#endif
View
@@ -967,7 +967,7 @@ FuncDeclaration *ClassDeclaration::findFunc(Identifier *ident, TypeFunction *tf)
//printf("ClassDeclaration::findFunc(%s, %s) %s\n", ident->toChars(), tf->toChars(), toChars());
ClassDeclaration *cd = this;
- Array *vtbl = &cd->vtbl;
+ FuncDeclarations *vtbl = &cd->vtbl;
while (1)
{
for (size_t i = 0; i < vtbl->dim; i++)
@@ -1465,7 +1465,7 @@ BaseClass::BaseClass(Type *type, enum PROT protection)
* by base classes)
*/
-int BaseClass::fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance)
+int BaseClass::fillVtbl(ClassDeclaration *cd, FuncDeclarations *vtbl, int newinstance)
{
ClassDeclaration *id = base;
int j;
View
@@ -25,7 +25,7 @@
#include "scope.h"
#endif
-int findCondition(Array *ids, Identifier *ident)
+int findCondition(Identifiers *ids, Identifier *ident)
{
if (ids)
{
@@ -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 Identifiers();
global.params.debugids->push((void *)ident);
}
@@ -98,7 +98,7 @@ int DebugCondition::include(Scope *sc, ScopeDsymbol *s)
inc = 1;
else
{ if (!mod->debugidsNot)
- mod->debugidsNot = new Array();
+ mod->debugidsNot = new Identifiers();
mod->debugidsNot->push(ident->toChars());
}
}
@@ -168,7 +168,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 Identifiers();
global.params.versionids->push((void *)ident);
}
@@ -194,7 +194,7 @@ int VersionCondition::include(Scope *sc, ScopeDsymbol *s)
else
{
if (!mod->versionidsNot)
- mod->versionidsNot = new Array();
+ mod->versionidsNot = new Identifiers();
mod->versionidsNot->push(ident->toChars());
}
}
View
@@ -26,7 +26,7 @@ enum TOK;
struct HdrGenState;
#endif
-int findCondition(Array *ids, Identifier *ident);
+int findCondition(Identifiers *ids, Identifier *ident);
struct Condition
{
View
@@ -40,14 +40,14 @@
struct CppMangleState
{
- static Array components;
+ static Voids components;
int substitute(OutBuffer *buf, void *p);
int exist(void *p);
void store(void *p);
};
-Array CppMangleState::components;
+Voids CppMangleState::components;
void writeBase36(OutBuffer *buf, unsigned i)
View
@@ -521,7 +521,7 @@ enum BUILTIN { };
struct FuncDeclaration : Declaration
{
- Array *fthrows; // Array of Type's of exceptions (not used)
+ Types *fthrows; // Array of Type's of exceptions (not used)
Statement *frequire;
Statement *fensure;
Statement *fbody;
@@ -599,7 +599,7 @@ struct FuncDeclaration : Declaration
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs);
int overrides(FuncDeclaration *fd);
- int findVtblIndex(Array *vtbl, int dim);
+ int findVtblIndex(FuncDeclarations *vtbl, int dim);
int overloadInsert(Dsymbol *s);
FuncDeclaration *overloadExactMatch(Type *t);
FuncDeclaration *overloadResolve(Loc loc, Expression *ethis, Expressions *arguments, int flags = 0);
@@ -633,7 +633,7 @@ struct FuncDeclaration : Declaration
Expression *interpret(InterState *istate, Expressions *arguments, Expression *thisexp = NULL);
void inlineScan();
int canInline(int hasthis, int hdrscan = 0);
- Expression *doInline(InlineScanState *iss, Expression *ethis, Array *arguments);
+ Expression *doInline(InlineScanState *iss, Expression *ethis, Expressions *arguments);
const char *kind();
void toDocBuffer(OutBuffer *buf);
FuncDeclaration *isUnique();
View
@@ -65,9 +65,11 @@ struct MacroSection : Section
void write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf);
};
+typedef ArrayOf(Section) Sections;
+
struct DocComment
{
- Array sections; // Section*[]
+ Sections sections; // Section*[]
Section *summary;
Section *copyright;
View
@@ -105,7 +105,7 @@ int Dsymbol::oneMember(Dsymbol **ps)
* Same as Dsymbol::oneMember(), but look at an array of Dsymbols.
*/
-int Dsymbol::oneMembers(Array *members, Dsymbol **ps)
+int Dsymbol::oneMembers(Dsymbols *members, Dsymbol **ps)
{
//printf("Dsymbol::oneMembers() %d\n", members ? members->dim : 0);
Dsymbol *s = NULL;
@@ -865,7 +865,7 @@ void ScopeDsymbol::importScope(ScopeDsymbol *s, enum PROT protection)
if (s != this)
{
if (!imports)
- imports = new Array();
+ imports = new ScopeDsymbols();
else
{
for (int i = 0; i < imports->dim; i++)
@@ -960,7 +960,7 @@ Dsymbol *ScopeDsymbol::symtabInsert(Dsymbol *s)
*/
#if DMDV2
-size_t ScopeDsymbol::dim(Array *members)
+size_t ScopeDsymbol::dim(Dsymbols *members)
{
size_t n = 0;
if (members)
@@ -990,7 +990,7 @@ size_t ScopeDsymbol::dim(Array *members)
*/
#if DMDV2
-Dsymbol *ScopeDsymbol::getNth(Array *members, size_t nth, size_t *pn)
+Dsymbol *ScopeDsymbol::getNth(Dsymbols *members, size_t nth, size_t *pn)
{
if (!members)
return NULL;
View
@@ -180,7 +180,7 @@ struct Dsymbol : Object
virtual enum PROT prot();
virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
virtual int oneMember(Dsymbol **ps);
- static int oneMembers(Array *members, Dsymbol **ps);
+ static int oneMembers(Dsymbols *members, Dsymbol **ps);
virtual int hasPointers();
virtual void addLocalClass(ClassDeclarations *) { }
virtual void checkCtorConstInit() { }
@@ -254,7 +254,7 @@ struct ScopeDsymbol : Dsymbol
Dsymbols *members; // all Dsymbol's in this scope
DsymbolTable *symtab; // members[] sorted into table
- Array *imports; // imported ScopeDsymbol's
+ ScopeDsymbols *imports; // imported ScopeDsymbol's
unsigned char *prots; // array of PROT, one for each import
ScopeDsymbol();
@@ -272,8 +272,8 @@ struct ScopeDsymbol : Dsymbol
void emitMemberComments(Scope *sc);
- static size_t dim(Array *members);
- static Dsymbol *getNth(Array *members, size_t nth, size_t *pn = NULL);
+ static size_t dim(Dsymbols *members);
+ static Dsymbol *getNth(Dsymbols *members, size_t nth, size_t *pn = NULL);
ScopeDsymbol *isScopeDsymbol() { return this; }
};
View
@@ -75,7 +75,7 @@ elem *callfunc(Loc loc,
FuncDeclaration *fd, // if !=NULL, this is the function being called
Type *t, // TypeDelegate or TypeFunction for this function
elem *ehidden, // if !=NULL, this is the 'hidden' argument
- Array *arguments)
+ Expressions *arguments)
{
elem *ep;
elem *e;
@@ -1137,7 +1137,7 @@ elem *Dsymbol_toElem(Dsymbol *s, IRState *irs)
ad = s->isAttribDeclaration();
if (ad)
{
- Array *decl = ad->include(NULL, NULL);
+ Dsymbols *decl = ad->include(NULL, NULL);
if (decl && decl->dim)
{
for (size_t i = 0; i < decl->dim; i++)
@@ -1178,7 +1178,7 @@ elem *Dsymbol_toElem(Dsymbol *s, IRState *irs)
// Put vd on list of things needing destruction
if (!irs->varsInScope)
- irs->varsInScope = new Array();
+ irs->varsInScope = new Dsymbols();
irs->varsInScope->push(vd);
}
}
@@ -4784,7 +4784,7 @@ elem *ExpressionsToStaticArray(IRState *irs, Loc loc, Expressions *exps, Type *t
symbol *stmp = symbol_genauto(tsarray->toCtype());
targ_size_t szelem = telem->size();
- Array elems;
+ Voids elems;
elems.setDim(dim);
::type *te = telem->toCtype(); // stmp[] element type
View
@@ -1750,7 +1750,7 @@ Statement *FuncDeclaration::mergeFrequire(Statement *sf)
if (sf)
{ Catch *c = new Catch(loc, NULL, NULL, sf);
- Array *catches = new Array();
+ Catches *catches = new Catches();
catches->push(c);
sf = new TryCatchStatement(loc, s2, catches);
}
@@ -1846,7 +1846,7 @@ int FuncDeclaration::overrides(FuncDeclaration *fd)
* -2 can't determine because of forward references
*/
-int FuncDeclaration::findVtblIndex(Array *vtbl, int dim)
+int FuncDeclaration::findVtblIndex(FuncDeclarations *vtbl, int dim)
{
FuncDeclaration *mismatch = NULL;
int bestvi = -1;
Oops, something went wrong.

0 comments on commit 8b3bb0d

Please sign in to comment.