Skip to content

Commit f883c48

Browse files
committed
[NFC] Move TypeOrExtensionDecl out of PrintOptions.h.
1 parent edfa805 commit f883c48

File tree

5 files changed

+76
-43
lines changed

5 files changed

+76
-43
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/Basic/STLExtras.h"
1717
#include "swift/AST/AttrKind.h"
1818
#include "swift/AST/Identifier.h"
19+
#include "swift/AST/TypeOrExtensionDecl.h"
1920
#include "llvm/ADT/Optional.h"
2021
#include <limits.h>
2122
#include <vector>
@@ -36,32 +37,6 @@ enum DeclAttrKind : unsigned;
3637
class SynthesizedExtensionAnalyzer;
3738
struct PrintOptions;
3839

39-
/// \brief Describes either a nominal type declaration or an extension
40-
/// declaration.
41-
struct TypeOrExtensionDecl {
42-
llvm::PointerUnion<NominalTypeDecl *, ExtensionDecl *> Decl;
43-
44-
TypeOrExtensionDecl() = default;
45-
46-
TypeOrExtensionDecl(NominalTypeDecl *D);
47-
TypeOrExtensionDecl(ExtensionDecl *D);
48-
49-
/// \brief Return the contained *Decl as the Decl superclass.
50-
class Decl *getAsDecl() const;
51-
/// \brief Return the contained *Decl as the DeclContext superclass.
52-
DeclContext *getAsDeclContext() const;
53-
/// \brief Return the contained NominalTypeDecl or that of the extended type
54-
/// in the ExtensionDecl.
55-
NominalTypeDecl *getBaseNominal() const;
56-
57-
/// \brief Is the contained pointer null?
58-
bool isNull() const;
59-
explicit operator bool() const { return !isNull(); }
60-
61-
bool operator==(TypeOrExtensionDecl rhs) { return Decl == rhs.Decl; }
62-
bool operator!=(TypeOrExtensionDecl rhs) { return Decl != rhs.Decl; }
63-
bool operator<(TypeOrExtensionDecl rhs) { return Decl < rhs.Decl; }
64-
};
6540

6641
/// Necessary information for archetype transformation during printing.
6742
struct TypeTransformContext {

include/swift/AST/TypeAlignments.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace swift {
3737
class ExtensionDecl;
3838
class GenericEnvironment;
3939
class GenericTypeParamDecl;
40+
class NominalTypeDecl;
4041
class NormalProtocolConformance;
4142
class OperatorDecl;
4243
class Pattern;
@@ -90,6 +91,7 @@ LLVM_DECLARE_TYPE_ALIGNMENT(swift::OperatorDecl, swift::DeclAlignInBits)
9091
LLVM_DECLARE_TYPE_ALIGNMENT(swift::ProtocolDecl, swift::DeclAlignInBits)
9192
LLVM_DECLARE_TYPE_ALIGNMENT(swift::TypeDecl, swift::DeclAlignInBits)
9293
LLVM_DECLARE_TYPE_ALIGNMENT(swift::ValueDecl, swift::DeclAlignInBits)
94+
LLVM_DECLARE_TYPE_ALIGNMENT(swift::NominalTypeDecl, swift::DeclAlignInBits)
9395
LLVM_DECLARE_TYPE_ALIGNMENT(swift::ExtensionDecl, swift::DeclAlignInBits)
9496

9597
LLVM_DECLARE_TYPE_ALIGNMENT(swift::TypeBase, swift::TypeAlignInBits)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//===- TypeOrExtensionDecl.h - Swift Language Declaration ASTs -*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 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+
// This file defines the TypeOrExtensionDecl struct, separately to Decl.h so
14+
// that this can be included in files that Decl.h includes.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_TYPE_OR_EXTENSION_DECL_H
19+
#define SWIFT_TYPE_OR_EXTENSION_DECL_H
20+
21+
#include "swift/AST/TypeAlignments.h"
22+
#include "llvm/ADT/PointerUnion.h"
23+
24+
namespace swift {
25+
26+
/// \brief Describes either a nominal type declaration or an extension
27+
/// declaration.
28+
struct TypeOrExtensionDecl {
29+
// (The definitions are in Decl.cpp.)
30+
llvm::PointerUnion<NominalTypeDecl *, ExtensionDecl *> Decl;
31+
32+
TypeOrExtensionDecl() = default;
33+
34+
TypeOrExtensionDecl(NominalTypeDecl *D);
35+
TypeOrExtensionDecl(ExtensionDecl *D);
36+
37+
/// \brief Return the contained *Decl as the Decl superclass.
38+
class Decl *getAsDecl() const;
39+
/// \brief Return the contained *Decl as the DeclContext superclass.
40+
DeclContext *getAsDeclContext() const;
41+
/// \brief Return the contained NominalTypeDecl or that of the extended type
42+
/// in the ExtensionDecl.
43+
NominalTypeDecl *getBaseNominal() const;
44+
45+
/// \brief Is the contained pointer null?
46+
bool isNull() const;
47+
explicit operator bool() const { return !isNull(); }
48+
49+
bool operator==(TypeOrExtensionDecl rhs) { return Decl == rhs.Decl; }
50+
bool operator!=(TypeOrExtensionDecl rhs) { return Decl != rhs.Decl; }
51+
bool operator<(TypeOrExtensionDecl rhs) { return Decl < rhs.Decl; }
52+
};
53+
54+
} // end namespace swift
55+
56+
#endif

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@ void PrintOptions::clearSynthesizedExtension() {
6363
TransformContext.reset();
6464
}
6565

66-
TypeOrExtensionDecl::TypeOrExtensionDecl(NominalTypeDecl *D) : Decl(D) {}
67-
TypeOrExtensionDecl::TypeOrExtensionDecl(ExtensionDecl *D) : Decl(D) {}
68-
69-
Decl *TypeOrExtensionDecl::getAsDecl() const {
70-
if (auto NTD = Decl.dyn_cast<NominalTypeDecl *>())
71-
return NTD;
72-
73-
return Decl.get<ExtensionDecl *>();
74-
}
75-
DeclContext *TypeOrExtensionDecl::getAsDeclContext() const {
76-
return getAsDecl()->getInnermostDeclContext();
77-
}
78-
NominalTypeDecl *TypeOrExtensionDecl::getBaseNominal() const {
79-
return getAsDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
80-
}
81-
bool TypeOrExtensionDecl::isNull() const { return Decl.isNull(); }
82-
8366
TypeTransformContext::TypeTransformContext(Type T)
8467
: BaseType(T.getPointer()) {
8568
assert(T->mayHaveMembers());

lib/AST/Decl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5580,3 +5580,20 @@ void ClassDecl::setSuperclass(Type superclass) {
55805580
&& "superclass must be interface type");
55815581
LazySemanticInfo.Superclass.setPointerAndInt(superclass, true);
55825582
}
5583+
5584+
TypeOrExtensionDecl::TypeOrExtensionDecl(NominalTypeDecl *D) : Decl(D) {}
5585+
TypeOrExtensionDecl::TypeOrExtensionDecl(ExtensionDecl *D) : Decl(D) {}
5586+
5587+
Decl *TypeOrExtensionDecl::getAsDecl() const {
5588+
if (auto NTD = Decl.dyn_cast<NominalTypeDecl *>())
5589+
return NTD;
5590+
5591+
return Decl.get<ExtensionDecl *>();
5592+
}
5593+
DeclContext *TypeOrExtensionDecl::getAsDeclContext() const {
5594+
return getAsDecl()->getInnermostDeclContext();
5595+
}
5596+
NominalTypeDecl *TypeOrExtensionDecl::getBaseNominal() const {
5597+
return getAsDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
5598+
}
5599+
bool TypeOrExtensionDecl::isNull() const { return Decl.isNull(); }

0 commit comments

Comments
 (0)