Skip to content

Commit

Permalink
[unittests] Remove a use of addTopLevelDecl
Browse files Browse the repository at this point in the history
Instead, cache the decls as a result of
ParseSourceFileRequest.
  • Loading branch information
hamishknight committed Mar 3, 2020
1 parent 011f4f1 commit dafa9b9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions unittests/AST/TestContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

#include "TestContext.h"
#include "swift/AST/Module.h"
#include "swift/AST/ParseRequests.h"
#include "swift/Strings.h"
#include "swift/Subsystems.h"

using namespace swift;
using namespace swift::unittest;


static void declareOptionalType(ASTContext &ctx, SourceFile *fileForLookups,
static Decl *createOptionalType(ASTContext &ctx, SourceFile *fileForLookups,
Identifier name) {
auto wrapped = new (ctx) GenericTypeParamDecl(fileForLookups,
ctx.getIdentifier("Wrapped"),
Expand All @@ -30,7 +30,7 @@ static void declareOptionalType(ASTContext &ctx, SourceFile *fileForLookups,
auto decl = new (ctx) EnumDecl(SourceLoc(), name, SourceLoc(),
/*inherited*/{}, params, fileForLookups);
wrapped->setDeclContext(decl);
fileForLookups->addTopLevelDecl(decl);
return decl;
}

TestContext::TestContext(ShouldDeclareOptionalTypes optionals)
Expand All @@ -50,8 +50,13 @@ TestContext::TestContext(ShouldDeclareOptionalTypes optionals)
module->addFile(*FileForLookups);

if (optionals == DeclareOptionalTypes) {
declareOptionalType(Ctx, FileForLookups, Ctx.getIdentifier("Optional"));
declareOptionalType(Ctx, FileForLookups,
Ctx.getIdentifier("ImplicitlyUnwrappedOptional"));
SmallVector<Decl *, 2> optionalTypes;
optionalTypes.push_back(createOptionalType(
Ctx, FileForLookups, Ctx.getIdentifier("Optional")));
optionalTypes.push_back(createOptionalType(
Ctx, FileForLookups, Ctx.getIdentifier("ImplicitlyUnwrappedOptional")));

Ctx.evaluator.cacheOutput(ParseSourceFileRequest{FileForLookups},
Ctx.AllocateCopy(optionalTypes));
}
}

0 comments on commit dafa9b9

Please sign in to comment.