Skip to content

Commit d3fdd5d

Browse files
committed
[NFC] Move TypeOrExtensionDecl out of PrintOptions.h.
1 parent 8b68548 commit d3fdd5d

File tree

4 files changed

+78
-43
lines changed

4 files changed

+78
-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 {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 "llvm/ADT/PointerUnion.h"
22+
23+
namespace swift {
24+
class Decl;
25+
class NominalTypeDecl;
26+
class ExtensionDecl;
27+
class DeclContext;
28+
29+
/// \brief Describes either a nominal type declaration or an extension
30+
/// declaration.
31+
struct TypeOrExtensionDecl {
32+
// (The definitions are in Decl.cpp.)
33+
llvm::PointerUnion<NominalTypeDecl *, ExtensionDecl *> Decl;
34+
35+
TypeOrExtensionDecl() = default;
36+
37+
TypeOrExtensionDecl(NominalTypeDecl *D);
38+
TypeOrExtensionDecl(ExtensionDecl *D);
39+
40+
/// \brief Return the contained *Decl as the Decl superclass.
41+
class Decl *getAsDecl() const;
42+
/// \brief Return the contained *Decl as the DeclContext superclass.
43+
DeclContext *getAsDeclContext() const;
44+
/// \brief Return the contained NominalTypeDecl or that of the extended type
45+
/// in the ExtensionDecl.
46+
NominalTypeDecl *getBaseNominal() const;
47+
48+
/// \brief Is the contained pointer null?
49+
bool isNull() const;
50+
explicit operator bool() const { return !isNull(); }
51+
52+
bool operator==(TypeOrExtensionDecl rhs) { return Decl == rhs.Decl; }
53+
bool operator!=(TypeOrExtensionDecl rhs) { return Decl != rhs.Decl; }
54+
bool operator<(TypeOrExtensionDecl rhs) { return Decl < rhs.Decl; }
55+
};
56+
57+
} // end namespace swift
58+
59+
#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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5548,3 +5548,21 @@ void ClassDecl::setSuperclass(Type superclass) {
55485548
&& "superclass must be interface type");
55495549
LazySemanticInfo.Superclass.setPointerAndInt(superclass, true);
55505550
}
5551+
5552+
TypeOrExtensionDecl::TypeOrExtensionDecl(NominalTypeDecl *D) : Decl(D) {}
5553+
TypeOrExtensionDecl::TypeOrExtensionDecl(ExtensionDecl *D) : Decl(D) {}
5554+
5555+
Decl *TypeOrExtensionDecl::getAsDecl() const {
5556+
if (auto NTD = Decl.dyn_cast<NominalTypeDecl *>())
5557+
return NTD;
5558+
5559+
return Decl.get<ExtensionDecl *>();
5560+
}
5561+
DeclContext *TypeOrExtensionDecl::getAsDeclContext() const {
5562+
return getAsDecl()->getInnermostDeclContext();
5563+
}
5564+
NominalTypeDecl *TypeOrExtensionDecl::getBaseNominal() const {
5565+
return getAsDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
5566+
}
5567+
bool TypeOrExtensionDecl::isNull() const { return Decl.isNull(); }
5568+

0 commit comments

Comments
 (0)