From 6bc2431b6b0d8af4ed10ffde56b601f726a1bf77 Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Sat, 30 Apr 2011 15:30:57 +0400 Subject: [PATCH] Skip unittests in imported modules --- dmd/module.c | 1 + dmd/module.h | 2 ++ dmd2/func.c | 4 ++++ dmd2/module.c | 1 + dmd2/module.h | 2 ++ gen/functions.cpp | 2 +- gen/main.cpp | 1 + 7 files changed, 12 insertions(+), 1 deletion(-) diff --git a/dmd/module.c b/dmd/module.c index 8a7da88a..7fef940f 100644 --- a/dmd/module.c +++ b/dmd/module.c @@ -156,6 +156,7 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen moduleInfoType = new llvm::PATypeHolder(llvm::OpaqueType::get(llvm::getGlobalContext())); this->doDocComment = doDocComment; this->doHdrGen = doHdrGen; + this->isRoot = false; #endif } diff --git a/dmd/module.h b/dmd/module.h index f8e34136..c32ddf3f 100644 --- a/dmd/module.h +++ b/dmd/module.h @@ -206,6 +206,8 @@ struct Module : Package // array ops emitted in this module already StringTable arrayfuncs; + + bool isRoot; #endif }; diff --git a/dmd2/func.c b/dmd2/func.c index 8bbcbcf5..80f097e3 100644 --- a/dmd2/func.c +++ b/dmd2/func.c @@ -3700,7 +3700,11 @@ Dsymbol *UnitTestDeclaration::syntaxCopy(Dsymbol *s) void UnitTestDeclaration::semantic(Scope *sc) { +#if IN_LLVM + if (global.params.useUnitTests && sc->module->isRoot) +#else if (global.params.useUnitTests) +#endif { if (!type) type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); diff --git a/dmd2/module.c b/dmd2/module.c index dc3e2694..0973893f 100644 --- a/dmd2/module.c +++ b/dmd2/module.c @@ -218,6 +218,7 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen moduleInfoType = new llvm::PATypeHolder(llvm::OpaqueType::get(llvm::getGlobalContext())); this->doDocComment = doDocComment; this->doHdrGen = doHdrGen; + this->isRoot = false; #endif } #if IN_LLVM diff --git a/dmd2/module.h b/dmd2/module.h index af4451b0..0183e04f 100644 --- a/dmd2/module.h +++ b/dmd2/module.h @@ -214,6 +214,8 @@ struct Module : Package // array ops emitted in this module already StringTable arrayfuncs; + + bool isRoot; #endif }; diff --git a/gen/functions.cpp b/gen/functions.cpp index 5062dc53..dc1d0fb3 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -298,7 +298,7 @@ static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl) void DtoResolveFunction(FuncDeclaration* fdecl) { - if (!global.params.useUnitTests && fdecl->isUnitTestDeclaration()) { + if ((!global.params.useUnitTests || !fdecl->type) && fdecl->isUnitTestDeclaration()) { Logger::println("Ignoring unittest %s", fdecl->toPrettyChars()); return; // ignore declaration completely } diff --git a/gen/main.cpp b/gen/main.cpp index 38699d8c..b3b0cb83 100644 --- a/gen/main.cpp +++ b/gen/main.cpp @@ -780,6 +780,7 @@ LDC_TARGETS id = Lexer::idPool(name); m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration); + m->isRoot = true; modules.push(m); }