Skip to content

Commit bd93302

Browse files
committed
ASTDumper: Fix archetype address dumping
1 parent 6d66211 commit bd93302

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ static unsigned getDumpString(unsigned value) {
445445
static size_t getDumpString(size_t value) {
446446
return value;
447447
}
448+
static void *getDumpString(void *value) { return value; }
448449

449450
//===----------------------------------------------------------------------===//
450451
// Decl printing.

unittests/AST/ASTDumperTests.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//===--- ASTDumperTests.cpp - Tests for ASTDumper -----------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "TestContext.h"
14+
#include "swift/AST/ASTContext.h"
15+
#include "swift/AST/GenericSignature.h"
16+
#include "swift/AST/Types.h"
17+
#include "llvm/ADT/StringRef.h"
18+
#include "llvm/Support/raw_ostream.h"
19+
#include "gtest/gtest.h"
20+
#include <string>
21+
22+
using namespace swift;
23+
using namespace swift::unittest;
24+
25+
TEST(ASTDumper, ArchetypeType) {
26+
TestContext C;
27+
auto &ctx = C.Ctx;
28+
29+
auto *genericParamTy = GenericTypeParamType::get(false, 0, 0, ctx);
30+
auto sig = buildGenericSignature(ctx, nullptr, {genericParamTy}, {});
31+
32+
TypeBase *archetype = nullptr;
33+
{
34+
llvm::SmallVector<ProtocolDecl *> protocols;
35+
archetype = PrimaryArchetypeType::getNew(ctx, sig.getGenericEnvironment(),
36+
genericParamTy, protocols, Type(),
37+
nullptr);
38+
}
39+
40+
std::string fullStr;
41+
{
42+
llvm::raw_string_ostream os(fullStr);
43+
archetype->dump(os);
44+
}
45+
46+
llvm::StringRef str(fullStr);
47+
EXPECT_TRUE(str.consume_front("(primary_archetype_type address=0x"));
48+
{
49+
intptr_t integer;
50+
EXPECT_FALSE(str.consumeInteger(16, integer));
51+
}
52+
53+
EXPECT_EQ(str,
54+
" name=\"\\xCF\\x84_0_0\"\n"
55+
" (interface_type=generic_type_param_type depth=0 index=0))\n");
56+
}

unittests/AST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_swift_unittest(SwiftASTTests
22
ArithmeticEvaluator.cpp
3+
ASTDumperTests.cpp
34
IndexSubsetTests.cpp
45
DiagnosticConsumerTests.cpp
56
SourceLocTests.cpp

0 commit comments

Comments
 (0)