# HG changeset patch # User Eldar Insafutdinov # Date 1283560385 -3600 # Node ID e6e542f37b947fd7466c2f2534f8c0a91daa2f81 # Parent 9ee9b55452cba0d1a953f3b84a600023cb5ad4bd Some more Array -> Vector conversions diff -r 9ee9b55452cb -r e6e542f37b94 dmd/ArrayInitializer.d --- a/dmd/ArrayInitializer.d Fri Sep 03 23:55:51 2010 +0100 +++ b/dmd/ArrayInitializer.d Sat Sep 04 01:33:05 2010 +0100 @@ -272,7 +272,7 @@ Type tb = type.toBasetype(); Type tn = tb.nextOf().toBasetype(); - scope Array dts = new Array(); + scope dts = new Vector!(dt_t*)(); uint size; uint length; uint i; @@ -300,9 +300,9 @@ assert(length < dim); val = value[i]; dt = val.toDt(); - if (dts.data[length]) + if (dts[length]) error(loc, "duplicate initializations for index %d", length); - dts.data[length] = cast(void*)dt; + dts[length] = dt; length++; } @@ -319,7 +319,7 @@ pdtend = &d; for (i = 0; i < dim; i++) { - dt = cast(dt_t*)dts.data[i]; + dt = dts[i]; if (dt) pdtend = dtcat(pdtend, dt); else diff -r 9ee9b55452cb -r e6e542f37b94 dmd/Import.d --- a/dmd/Import.d Fri Sep 03 23:55:51 2010 +0100 +++ b/dmd/Import.d Sat Sep 04 01:33:05 2010 +0100 @@ -3,6 +3,7 @@ import dmd.common; import dmd.Dsymbol; import dmd.Array; +import dmd.ArrayTypes; import dmd.DsymbolTable; import dmd.PROT; import dmd.Identifier; @@ -41,7 +42,7 @@ class Import : Dsymbol { - Array packages; // array of Identifier's representing packages + Identifiers packages; // array of Identifier's representing packages Identifier id; // module Identifier Identifier aliasId; int isstatic; // !=0 if static import @@ -55,7 +56,7 @@ Module mod; Package pkg; // leftmost package/module - this(Loc loc, Array packages, Identifier id, Identifier aliasId, int isstatic) + this(Loc loc, Identifiers packages, Identifier id, Identifier aliasId, int isstatic) { super(id); @@ -74,7 +75,7 @@ this.ident = aliasId; // Kludge to change Import identifier to first package else if (packages && packages.dim) - this.ident = cast(Identifier)packages.data[0]; + this.ident = packages[0]; } void addAlias(Identifier name, Identifier alias_) @@ -247,9 +248,8 @@ if (packages) { - for (size_t i = 0; i < packages.dim; i++) + foreach (pid; packages) { - Identifier pid = cast(Identifier)packages.data[i]; ob.printf("%s.", pid.toChars()); } } diff -r 9ee9b55452cb -r e6e542f37b94 dmd/Module.d --- a/dmd/Module.d Fri Sep 03 23:55:51 2010 +0100 +++ b/dmd/Module.d Sat Sep 04 01:33:05 2010 +0100 @@ -297,7 +297,7 @@ symfile = new File(symfilename); } - static Module load(Loc loc, Array packages, Identifier ident) + static Module load(Loc loc, Identifiers packages, Identifier ident) { Module m; string filename; @@ -311,13 +311,10 @@ filename = ident.toChars(); if (packages && packages.dim) { - scope OutBuffer buf = new OutBuffer(); - int i; + scope buf = new OutBuffer(); - for (i = 0; i < packages.dim; i++) + foreach (pid; packages) { - Identifier pid = cast(Identifier)packages.data[i]; - buf.writestring(pid.toChars()); version (Windows) { @@ -379,9 +376,8 @@ writef("import "); if (packages) { - for (size_t i = 0; i < packages.dim; i++) + foreach (pid; packages) { - Identifier pid = cast(Identifier)packages.data[i]; writef("%s.", pid.toChars()); } } diff -r 9ee9b55452cb -r e6e542f37b94 dmd/ModuleDeclaration.d --- a/dmd/ModuleDeclaration.d Fri Sep 03 23:55:51 2010 +0100 +++ b/dmd/ModuleDeclaration.d Sat Sep 04 01:33:05 2010 +0100 @@ -2,15 +2,15 @@ import dmd.common; import dmd.Identifier; -import dmd.Array; +import dmd.ArrayTypes; class ModuleDeclaration { Identifier id; - Array packages; // array of Identifier's representing packages + Identifiers packages; // array of Identifier's representing packages bool safe; - this(Array packages, Identifier id, bool safe) + this(Identifiers packages, Identifier id, bool safe) { this.packages = packages; this.id = id; diff -r 9ee9b55452cb -r e6e542f37b94 dmd/Package.d --- a/dmd/Package.d Fri Sep 03 23:55:51 2010 +0100 +++ b/dmd/Package.d Sat Sep 04 01:33:05 2010 +0100 @@ -3,7 +3,7 @@ import dmd.common; import dmd.ScopeDsymbol; import dmd.Identifier; -import dmd.Array; +import dmd.ArrayTypes; import dmd.DsymbolTable; import dmd.Scope; import dmd.Dsymbol; @@ -22,7 +22,7 @@ assert(false); } - static DsymbolTable resolve(Array packages, Dsymbol* pparent, Package* ppkg) + static DsymbolTable resolve(Identifiers packages, Dsymbol* pparent, Package* ppkg) { DsymbolTable dst = Module.modules; Dsymbol parent = null; @@ -33,9 +33,8 @@ if (packages) { - for (int i = 0; i < packages.dim; i++) + foreach (pid; packages) { - Identifier pid = cast(Identifier)packages.data[i]; Dsymbol p = dst.lookup(pid); if (!p) { diff -r 9ee9b55452cb -r e6e542f37b94 dmd/Parser.d --- a/dmd/Parser.d Fri Sep 03 23:55:51 2010 +0100 +++ b/dmd/Parser.d Sat Sep 04 01:33:05 2010 +0100 @@ -262,13 +262,13 @@ } else { - Array a = null; + Identifiers a = null; Identifier id = token.ident; while (nextToken() == TOK.TOKdot) { if (!a) - a = new Array(); - a.push(cast(void*)id); + a = new Identifiers(); + a.push(id); nextToken(); if (token.value != TOK.TOKidentifier) { error("Identifier expected following package"); @@ -2164,7 +2164,7 @@ Import s; Identifier id; Identifier aliasid = null; - Array a; + Identifiers a; Loc loc; //printf("Parser.parseImport()\n"); @@ -2190,8 +2190,8 @@ while (token.value == TOK.TOKdot) { if (!a) - a = new Array(); - a.push(cast(void*)id); + a = new Identifiers(); + a.push(id); nextToken(); if (token.value != TOK.TOKidentifier) { @@ -3660,14 +3660,14 @@ case TOK.TOKcase: { Expression exp; Statements statements; - scope Array cases = new Array(); // array of Expression's + scope cases = new Expressions(); // array of Expression's Expression last = null; while (1) { nextToken(); exp = parseAssignExp(); - cases.push(cast(void*)exp); + cases.push(exp); if (token.value != TOK.TOKcomma) break; } @@ -3709,7 +3709,7 @@ // Keep cases in order by building the case statements backwards for (int i = cases.dim; i; i--) { - exp = cast(Expression)cases.data[i - 1]; + exp = cases[i - 1]; s = new CaseStatement(loc, exp, s); } } diff -r 9ee9b55452cb -r e6e542f37b94 dmd/StructInitializer.d --- a/dmd/StructInitializer.d Fri Sep 03 23:55:51 2010 +0100 +++ b/dmd/StructInitializer.d Sat Sep 04 01:33:05 2010 +0100 @@ -36,7 +36,7 @@ Identifiers field; // of Identifier *'s Initializers value; // parallel array of Initializer *'s - Array vars; // parallel array of VarDeclaration *'s + VarDeclarations vars; // parallel array of VarDeclaration *'s AggregateDeclaration ad; // which aggregate this is for this(Loc loc) @@ -47,7 +47,7 @@ field = new Identifiers(); value = new Initializers(); - vars = new Array(); + vars = new VarDeclarations(); } override Initializer syntaxCopy() @@ -138,7 +138,7 @@ { val = val.semantic(sc, v.type); value[i] = val; - vars.data[i] = cast(void*)v; + vars[i] = v; } else { @@ -152,7 +152,7 @@ { /* Rewrite as empty delegate literal { } */ - Arguments arguments = new Arguments; + auto arguments = new Arguments; Type tf = new TypeFunction(arguments, null, 0, LINK.LINKd); FuncLiteralDeclaration fd = new FuncLiteralDeclaration(loc, Loc(0), tf, TOK.TOKdelegate, null); fd.fbody = new CompoundStatement(loc, new Statements()); @@ -222,7 +222,7 @@ override dt_t* toDt() { - scope Array dts = new Array(); + scope dts = new Vector!(dt_t*); uint i; uint j; dt_t* dt; @@ -236,7 +236,7 @@ for (i = 0; i < vars.dim; i++) { - VarDeclaration v = cast(VarDeclaration)vars.data[i]; + VarDeclaration v = vars[i]; Initializer val = value[i]; //printf("vars[%d] = %s\n", i, v.toChars()); @@ -247,9 +247,9 @@ //printf(" adfield[%d] = %s\n", j, ((VarDeclaration *)ad.fields[j]).toChars()); if (cast(VarDeclaration)ad.fields[j] == v) // TODO: check if 'is' needs to be used here { - if (dts.data[j]) + if (dts[j]) error(loc, "field %s of %s already initialized", v.toChars(), ad.toChars()); - dts.data[j] = cast(void*)val.toDt(); + dts[j] = val.toDt(); break; } } @@ -260,9 +260,9 @@ offset = 0; for (j = 0; j < dts.dim; j++) { - VarDeclaration v = cast(VarDeclaration)ad.fields[j]; + VarDeclaration v = ad.fields[j]; - d = cast(dt_t*)dts.data[j]; + d = dts[j]; if (!d) { // An instance specific initializer was not provided. @@ -285,9 +285,9 @@ v.type.toDt(&d); break; } - VarDeclaration v2 = cast(VarDeclaration)ad.fields[k]; + VarDeclaration v2 = ad.fields[k]; - if (v2.offset < offset2 && dts.data[k]) + if (v2.offset < offset2 && dts[k]) break; // overlap } } diff -r 9ee9b55452cb -r e6e542f37b94 dmd/TemplateDeclaration.d --- a/dmd/TemplateDeclaration.d Fri Sep 03 23:55:51 2010 +0100 +++ b/dmd/TemplateDeclaration.d Sat Sep 04 01:33:05 2010 +0100 @@ -109,7 +109,7 @@ TemplateParameters origParameters; // originals for Ddoc Expression constraint; - Array instances; // array of TemplateInstance's + Vector!TemplateInstance instances; // array of TemplateInstance's TemplateDeclaration overnext; // next overloaded TemplateDeclaration TemplateDeclaration overroot; // first in overnext list @@ -148,7 +148,7 @@ this.constraint = constraint; this.members = decldefs; - instances = new Array(); + instances = new Vector!TemplateInstance(); } override Dsymbol syntaxCopy(Dsymbol) diff -r 9ee9b55452cb -r e6e542f37b94 dmd/TemplateInstance.d --- a/dmd/TemplateInstance.d Fri Sep 03 23:55:51 2010 +0100 +++ b/dmd/TemplateInstance.d Sat Sep 04 01:33:05 2010 +0100 @@ -337,9 +337,8 @@ * implements the typeargs. If so, just refer to that one instead. */ - for (size_t i = 0; i < tempdecl.instances.dim; i++) + foreach (ti; tempdecl.instances) { - TemplateInstance ti = cast(TemplateInstance)tempdecl.instances.data[i]; version (LOG) { printf("\t%s: checking for match with instance %d (%p): '%s'\n", toChars(), i, ti, ti.toChars()); } @@ -385,7 +384,7 @@ uint errorsave = global.errors; inst = this; int tempdecl_instance_idx = tempdecl.instances.dim; - tempdecl.instances.push(cast(void*)this); + tempdecl.instances.push(this); parent = tempdecl.parent; //printf("parent = '%s'\n", parent.kind());