Mercurial > projects > ddmd
view dmd/NewDeclaration.d @ 123:9e39c7de8438
Make dmd test suite compile
author | korDen |
---|---|
date | Fri, 03 Sep 2010 20:46:58 +0400 |
parents | e28b18c23469 |
children | 60bb0fe4563e |
line wrap: on
line source
module dmd.NewDeclaration; import dmd.common; import dmd.FuncDeclaration; import dmd.Loc; import dmd.ArrayTypes; import dmd.Dsymbol; import dmd.Argument; import dmd.ClassDeclaration; import dmd.Type; import dmd.TypeFunction; import dmd.LINK; import dmd.TY; import dmd.Scope; import dmd.OutBuffer; import dmd.HdrGenState; import dmd.STC; import dmd.Id; class NewDeclaration : FuncDeclaration { Arguments arguments; int varargs; this(Loc loc, Loc endloc, Arguments arguments, int varargs) { super(loc, endloc, Id.classNew, STCstatic, null); this.arguments = arguments; this.varargs = varargs; } override Dsymbol syntaxCopy(Dsymbol) { NewDeclaration f; f = new NewDeclaration(loc, endloc, null, varargs); FuncDeclaration.syntaxCopy(f); f.arguments = Argument.arraySyntaxCopy(arguments); return f; } override void semantic(Scope sc) { ClassDeclaration cd; Type tret; //printf("NewDeclaration.semantic()\n"); parent = sc.parent; Dsymbol parent = toParent(); cd = parent.isClassDeclaration(); if (!cd && !parent.isStructDeclaration()) { error("new allocators only are for class or struct definitions"); } tret = Type.tvoid.pointerTo(); type = new TypeFunction(arguments, tret, varargs, LINKd); type = type.semantic(loc, sc); assert(type.ty == Tfunction); // Check that there is at least one argument of type size_t TypeFunction tf = cast(TypeFunction)type; if (Argument.dim(tf.parameters) < 1) { error("at least one argument of type size_t expected"); } else { Argument a = Argument.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); } override void toCBuffer(OutBuffer buf, HdrGenState* hgs) { buf.writestring("new"); Argument.argsToCBuffer(buf, hgs, arguments, varargs); bodyToCBuffer(buf, hgs); } override string kind() { return "allocator"; } override bool isVirtual() { return false; } override bool addPreInvariant() { return false; } override bool addPostInvariant() { return false; } override NewDeclaration isNewDeclaration() { return this; } }