# HG changeset patch # User Christian Kamm # Date 1223200079 -7200 # Node ID 505f41873d4fe819d8f24a2fe46fb500c090a128 # Parent 669a2c84f4e4ff575ca3ef60fa55ba6d1f775c9e# Parent 8d850fa25713d0ed43f0cac52f21e4eeff1aa07e Automated merge with http://hg.dsource.org/projects/llvmdc diff -r 669a2c84f4e4 -r 505f41873d4f gen/llvmhelpers.cpp --- a/gen/llvmhelpers.cpp Sun Oct 05 02:01:50 2008 +0200 +++ b/gen/llvmhelpers.cpp Sun Oct 05 11:47:59 2008 +0200 @@ -1129,6 +1129,12 @@ { Logger::println("VarDeclaration"); + // if aliassym is set, this VarDecl is redone as an alias to another symbol + // this seems to be done to rewrite Tuple!(...) v; + // as a TupleDecl that contains a bunch of individual VarDecls + if (vd->aliassym) + return DtoDeclarationExp(vd->aliassym); + // static if (vd->isDataseg()) { @@ -1249,6 +1255,22 @@ DtoDeclarationExp(mdsym); } } + // tuple declaration + else if (TupleDeclaration* tupled = declaration->isTupleDeclaration()) + { + Logger::println("TupleDeclaration"); + if(!tupled->isexp) { + error(declaration->loc, "don't know how to handle non-expression tuple decls yet"); + assert(0); + } + + assert(tupled->objects); + for (int i=0; i < tupled->objects->dim; ++i) + { + DsymbolExp* exp = (DsymbolExp*)tupled->objects->data[i]; + DtoDeclarationExp(exp->s); + } + } // unsupported declaration else { diff -r 669a2c84f4e4 -r 505f41873d4f gen/tollvm.cpp --- a/gen/tollvm.cpp Sun Oct 05 02:01:50 2008 +0200 +++ b/gen/tollvm.cpp Sun Oct 05 11:47:59 2008 +0200 @@ -169,6 +169,16 @@ return getPtrToType(LLStructType::get(DtoType(taa->key), DtoType(taa->next), 0)); } +/* + Not needed atm as VarDecls for tuples are rewritten as a string of + VarDecls for the fields (u -> _u_field_0, ...) + + case Ttuple: + { + TypeTuple* ttupl = (TypeTuple*)t; + return DtoStructTypeFromArguments(ttupl->arguments); + } +*/ // opaque type case Topaque: return llvm::OpaqueType::get(); @@ -182,6 +192,26 @@ ////////////////////////////////////////////////////////////////////////////////////////// +/* +const LLType* DtoStructTypeFromArguments(Arguments* arguments) +{ + if (!arguments) + return LLType::VoidTy; + + std::vector types; + for (size_t i = 0; i < arguments->dim; i++) + { + Argument *arg = (Argument *)arguments->data[i]; + assert(arg && arg->type); + + types.push_back(DtoType(arg->type)); + } + return LLStructType::get(types); +} +*/ + +////////////////////////////////////////////////////////////////////////////////////////// + const LLType* DtoTypeNotVoid(Type* t) { const LLType* lt = DtoType(t); diff -r 669a2c84f4e4 -r 505f41873d4f gen/tollvm.h --- a/gen/tollvm.h Sun Oct 05 02:01:50 2008 +0200 +++ b/gen/tollvm.h Sun Oct 05 11:47:59 2008 +0200 @@ -23,6 +23,10 @@ unsigned DtoShouldExtend(Type* type); +// tuple helper +// takes a arguments list and makes a struct type out of them +//const LLType* DtoStructTypeFromArguments(Arguments* arguments); + // delegate helpers const LLStructType* DtoDelegateType(Type* t); LLValue* DtoDelegateEquals(TOK op, LLValue* lhs, LLValue* rhs); diff -r 669a2c84f4e4 -r 505f41873d4f tests/mini/tupleval.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/mini/tupleval.d Sun Oct 05 11:47:59 2008 +0200 @@ -0,0 +1,30 @@ +module foo; + +template ParameterTupleOf( Fn ) +{ + static if( is( Fn Params == function ) ) + alias Params ParameterTupleOf; + else static if( is( Fn Params == delegate ) ) + alias ParameterTupleOf!(Params) ParameterTupleOf; + else static if( is( Fn Params == Params* ) ) + alias ParameterTupleOf!(Params) ParameterTupleOf; + else + static assert( false, "Argument has no parameters." ); +} + +struct S +{ + int opApply(T)(T dg) + { + alias ParameterTupleOf!(T) U; + U u; + u[0] = 1; + u[1] = 2; + return 0; + } +} + +void main() +{ + foreach(int x, int y; S()){} +}