Skip to content

Commit 5d5a050

Browse files
authored
Merge pull request #77361 from rintaro/parse-no-parser
[Parse] Remove unnecessary dependencies to Parser.h
2 parents 1c331a3 + d4db99c commit 5d5a050

26 files changed

+339
-307
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "swift/IRGen/TBDGen.h"
4040
#include "swift/Migrator/MigratorOptions.h"
4141
#include "swift/Parse/IDEInspectionCallbacks.h"
42-
#include "swift/Parse/Parser.h"
4342
#include "swift/Sema/SourceLoader.h"
4443
#include "swift/Serialization/Validation.h"
4544
#include "swift/Subsystems.h"
@@ -52,9 +51,9 @@
5251
#include "llvm/Option/ArgList.h"
5352
#include "llvm/Support/BLAKE3.h"
5453
#include "llvm/Support/HashingOutputBackend.h"
55-
#include "llvm/TargetParser/Host.h"
5654
#include "llvm/Support/MemoryBuffer.h"
5755
#include "llvm/Support/VirtualOutputBackend.h"
56+
#include "llvm/TargetParser/Host.h"
5857

5958
#include <memory>
6059

include/swift/Migrator/FixitFilter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_MIGRATOR_FIXITFILTER_H
1919

2020
#include "swift/AST/DiagnosticConsumer.h"
21+
#include "swift/AST/DiagnosticsParse.h"
2122
#include "swift/AST/DiagnosticsSema.h"
2223

2324
namespace swift {

include/swift/Parse/ParseDeclName.h

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//===--- ParseDeclName.h ----------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 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+
#ifndef SWIFT_PARSE_PARSEDECLNAME_H
14+
#define SWIFT_PARSE_PARSEDECLNAME_H
15+
16+
#include "swift/AST/Identifier.h"
17+
#include "swift/Basic/LLVM.h"
18+
#include "swift/Parse/Lexer.h"
19+
20+
namespace swift {
21+
22+
/// Describes a parsed declaration name.
23+
struct ParsedDeclName {
24+
/// The name of the context of which the corresponding entity should
25+
/// become a member.
26+
StringRef ContextName;
27+
28+
/// The base name of the declaration.
29+
StringRef BaseName;
30+
31+
/// The argument labels for a function declaration.
32+
SmallVector<StringRef, 4> ArgumentLabels;
33+
34+
/// Whether this is a function name (vs. a value name).
35+
bool IsFunctionName = false;
36+
37+
/// Whether this is a getter for the named property.
38+
bool IsGetter = false;
39+
40+
/// Whether this is a setter for the named property.
41+
bool IsSetter = false;
42+
43+
bool IsSubscript = false;
44+
45+
/// For a declaration name that makes the declaration into an
46+
/// instance member, the index of the "Self" parameter.
47+
std::optional<unsigned> SelfIndex;
48+
49+
/// Determine whether this is a valid name.
50+
explicit operator bool() const { return !BaseName.empty(); }
51+
52+
/// Whether this declaration name turns the declaration into a
53+
/// member of some named context.
54+
bool isMember() const { return !ContextName.empty(); }
55+
56+
/// Whether the result is translated into an instance member.
57+
bool isInstanceMember() const {
58+
return isMember() && static_cast<bool>(SelfIndex);
59+
}
60+
61+
/// Whether the result is translated into a static/class member.
62+
bool isClassMember() const {
63+
return isMember() && !static_cast<bool>(SelfIndex);
64+
}
65+
66+
/// Whether this is a property accessor.
67+
bool isPropertyAccessor() const { return IsGetter || IsSetter; }
68+
69+
/// Whether this is an operator.
70+
bool isOperator() const { return Lexer::isOperator(BaseName); }
71+
72+
/// Form a declaration name from this parsed declaration name.
73+
DeclName formDeclName(ASTContext &ctx, bool isSubscript = false,
74+
bool isCxxClassTemplateSpec = false) const;
75+
76+
/// Form a declaration name from this parsed declaration name.
77+
DeclNameRef formDeclNameRef(ASTContext &ctx, bool isSubscript = false,
78+
bool isCxxClassTemplateSpec = false) const;
79+
};
80+
81+
/// Parse a stringified Swift declaration name,
82+
/// e.g. "Foo.translateBy(self:x:y:)".
83+
ParsedDeclName parseDeclName(StringRef name) LLVM_READONLY;
84+
85+
/// Form a Swift declaration name from its constituent parts.
86+
DeclName formDeclName(ASTContext &ctx, StringRef baseName,
87+
ArrayRef<StringRef> argumentLabels, bool isFunctionName,
88+
bool isInitializer, bool isSubscript = false,
89+
bool isCxxClassTemplateSpec = false);
90+
91+
/// Form a Swift declaration name reference from its constituent parts.
92+
DeclNameRef formDeclNameRef(ASTContext &ctx, StringRef baseName,
93+
ArrayRef<StringRef> argumentLabels,
94+
bool isFunctionName, bool isInitializer,
95+
bool isSubscript = false,
96+
bool isCxxClassTemplateSpec = false);
97+
98+
} // namespace swift
99+
100+
#endif // SWIFT_PARSE_PARSEDECLNAME_H

include/swift/Parse/Parser.h

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -2118,67 +2118,6 @@ class Parser {
21182118
ParserResult<Expr> parseExprFromSyntaxTree();
21192119
};
21202120

2121-
/// Describes a parsed declaration name.
2122-
struct ParsedDeclName {
2123-
/// The name of the context of which the corresponding entity should
2124-
/// become a member.
2125-
StringRef ContextName;
2126-
2127-
/// The base name of the declaration.
2128-
StringRef BaseName;
2129-
2130-
/// The argument labels for a function declaration.
2131-
SmallVector<StringRef, 4> ArgumentLabels;
2132-
2133-
/// Whether this is a function name (vs. a value name).
2134-
bool IsFunctionName = false;
2135-
2136-
/// Whether this is a getter for the named property.
2137-
bool IsGetter = false;
2138-
2139-
/// Whether this is a setter for the named property.
2140-
bool IsSetter = false;
2141-
2142-
bool IsSubscript = false;
2143-
2144-
/// For a declaration name that makes the declaration into an
2145-
/// instance member, the index of the "Self" parameter.
2146-
std::optional<unsigned> SelfIndex;
2147-
2148-
/// Determine whether this is a valid name.
2149-
explicit operator bool() const { return !BaseName.empty(); }
2150-
2151-
/// Whether this declaration name turns the declaration into a
2152-
/// member of some named context.
2153-
bool isMember() const { return !ContextName.empty(); }
2154-
2155-
/// Whether the result is translated into an instance member.
2156-
bool isInstanceMember() const {
2157-
return isMember() && static_cast<bool>(SelfIndex);
2158-
}
2159-
2160-
/// Whether the result is translated into a static/class member.
2161-
bool isClassMember() const {
2162-
return isMember() && !static_cast<bool>(SelfIndex);
2163-
}
2164-
2165-
/// Whether this is a property accessor.
2166-
bool isPropertyAccessor() const { return IsGetter || IsSetter; }
2167-
2168-
/// Whether this is an operator.
2169-
bool isOperator() const {
2170-
return Lexer::isOperator(BaseName);
2171-
}
2172-
2173-
/// Form a declaration name from this parsed declaration name.
2174-
DeclName formDeclName(ASTContext &ctx, bool isSubscript = false,
2175-
bool isCxxClassTemplateSpec = false) const;
2176-
2177-
/// Form a declaration name from this parsed declaration name.
2178-
DeclNameRef formDeclNameRef(ASTContext &ctx, bool isSubscript = false,
2179-
bool isCxxClassTemplateSpec = false) const;
2180-
};
2181-
21822121
/// To assist debugging parser crashes, tell us the location of the
21832122
/// current token.
21842123
class PrettyStackTraceParser : public llvm::PrettyStackTraceEntry {
@@ -2188,28 +2127,6 @@ class PrettyStackTraceParser : public llvm::PrettyStackTraceEntry {
21882127
void print(llvm::raw_ostream &out) const override;
21892128
};
21902129

2191-
/// Parse a stringified Swift declaration name,
2192-
/// e.g. "Foo.translateBy(self:x:y:)".
2193-
ParsedDeclName parseDeclName(StringRef name) LLVM_READONLY;
2194-
2195-
/// Form a Swift declaration name from its constituent parts.
2196-
DeclName formDeclName(ASTContext &ctx,
2197-
StringRef baseName,
2198-
ArrayRef<StringRef> argumentLabels,
2199-
bool isFunctionName,
2200-
bool isInitializer,
2201-
bool isSubscript = false,
2202-
bool isCxxClassTemplateSpec = false);
2203-
2204-
/// Form a Swift declaration name reference from its constituent parts.
2205-
DeclNameRef formDeclNameRef(ASTContext &ctx,
2206-
StringRef baseName,
2207-
ArrayRef<StringRef> argumentLabels,
2208-
bool isFunctionName,
2209-
bool isInitializer,
2210-
bool isSubscript = false,
2211-
bool isCxxClassTemplateSpec = false);
2212-
22132130
/// Whether a given token can be the start of a decl.
22142131
bool isKeywordPossibleDeclStart(const LangOptions &options, const Token &Tok);
22152132

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
#include "llvm/ADT/STLExtras.h"
21
#include "swift/AST/ASTMangler.h"
32
#include "swift/Basic/Assertions.h"
43
#include "swift/Basic/Defer.h"
4+
#include "swift/Parse/Lexer.h"
55
#include "swift/Sema/IDETypeChecking.h"
6-
#include <swift/APIDigester/ModuleAnalyzerNodes.h>
6+
#include "llvm/ADT/STLExtras.h"
77
#include <algorithm>
8+
#include <swift/APIDigester/ModuleAnalyzerNodes.h>
89

910
using namespace swift;
1011
using namespace ide;

lib/AST/AccessNotes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
//===----------------------------------------------------------------------===//
1717

1818
#include "swift/AST/AccessNotes.h"
19+
#include "swift/AST/ASTContext.h"
1920
#include "swift/AST/Attr.h"
2021
#include "swift/AST/Decl.h"
21-
#include "swift/AST/Module.h" // DeclContext::isModuleScopeContext()
2222
#include "swift/AST/DiagnosticsFrontend.h"
23+
#include "swift/AST/Module.h" // DeclContext::isModuleScopeContext()
2324
#include "swift/Basic/Assertions.h"
24-
#include "swift/Parse/Parser.h"
25+
#include "swift/Parse/ParseDeclName.h"
2526
#include "llvm/ADT/STLExtras.h"
2627
#include "llvm/ADT/StringRef.h"
2728
#include "llvm/Support/YAMLTraits.h"

lib/ClangImporter/ClangImporter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
#include "swift/Basic/Version.h"
4848
#include "swift/ClangImporter/ClangImporterRequests.h"
4949
#include "swift/ClangImporter/ClangModule.h"
50-
#include "swift/Parse/Lexer.h"
5150
#include "swift/Parse/ParseVersion.h"
52-
#include "swift/Parse/Parser.h"
5351
#include "swift/Strings.h"
5452
#include "swift/Subsystems.h"
5553
#include "clang/AST/ASTContext.h"

lib/ClangImporter/ImportName.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "swift/Basic/STLExtras.h"
3232
#include "swift/Basic/StringExtras.h"
3333
#include "swift/ClangImporter/ClangImporterRequests.h"
34-
#include "swift/Parse/Parser.h"
34+
#include "swift/Parse/ParseDeclName.h"
3535
#include "swift/Strings.h"
3636
#include "swift/Subsystems.h"
3737
#include "clang/AST/ASTContext.h"

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@
1818
#include "ArgsToFrontendOptionsConverter.h"
1919
#include "swift/AST/DiagnosticsFrontend.h"
2020
#include "swift/Basic/Assertions.h"
21-
#include "swift/Basic/Assertions.h"
2221
#include "swift/Basic/Feature.h"
2322
#include "swift/Basic/Platform.h"
2423
#include "swift/Option/Options.h"
2524
#include "swift/Option/SanitizerOptions.h"
25+
#include "swift/Parse/Lexer.h"
2626
#include "swift/Parse/ParseVersion.h"
2727
#include "swift/SIL/SILBridging.h"
2828
#include "swift/Strings.h"
2929
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
3030
#include "llvm/ADT/STLExtras.h"
31-
#include "llvm/Support/VersionTuple.h"
32-
#include "llvm/TargetParser/Triple.h"
3331
#include "llvm/Option/Arg.h"
3432
#include "llvm/Option/ArgList.h"
3533
#include "llvm/Option/Option.h"
3634
#include "llvm/Support/FileSystem.h"
3735
#include "llvm/Support/LineIterator.h"
3836
#include "llvm/Support/Path.h"
3937
#include "llvm/Support/Process.h"
38+
#include "llvm/Support/VersionTuple.h"
4039
#include "llvm/Support/WithColor.h"
40+
#include "llvm/TargetParser/Triple.h"
4141

4242
using namespace swift;
4343
using namespace llvm::opt;

lib/IDE/Formatting.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
#include "swift/AST/GenericParamList.h"
1515
#include "swift/AST/TypeRepr.h"
1616
#include "swift/Basic/Assertions.h"
17-
#include "swift/IDE/SourceEntityWalker.h"
18-
#include "swift/Parse/Parser.h"
19-
#include "swift/Frontend/Frontend.h"
2017
#include "swift/Basic/SourceManager.h"
18+
#include "swift/Frontend/Frontend.h"
2119
#include "swift/IDE/Indenting.h"
20+
#include "swift/IDE/SourceEntityWalker.h"
21+
#include "swift/Parse/Lexer.h"
2222
#include "swift/Subsystems.h"
2323

2424
using namespace swift;

lib/IDE/IDERequests.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "swift/IDE/IDERequests.h"
14+
#include "swift/AST/ASTDemangler.h"
1315
#include "swift/AST/ASTPrinter.h"
1416
#include "swift/AST/Decl.h"
1517
#include "swift/AST/Effects.h"
1618
#include "swift/AST/NameLookup.h"
17-
#include "swift/AST/ASTDemangler.h"
1819
#include "swift/Basic/Assertions.h"
1920
#include "swift/Basic/SourceManager.h"
2021
#include "swift/Frontend/Frontend.h"
2122
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
2223
#include "swift/IDE/CommentConversion.h"
2324
#include "swift/IDE/Utils.h"
24-
#include "swift/Sema/IDETypeChecking.h"
2525
#include "swift/Markup/XMLUtils.h"
26+
#include "swift/Parse/Lexer.h"
27+
#include "swift/Sema/IDETypeChecking.h"
2628
#include "swift/Subsystems.h"
27-
#include "swift/IDE/IDERequests.h"
2829

2930
using namespace swift;
3031
using namespace swift::ide;

lib/IDE/REPLCodeCompletion.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
#include "swift/AST/SourceFile.h"
2222
#include "swift/Basic/LLVM.h"
2323
#include "swift/Basic/SourceManager.h"
24-
#include "swift/Parse/Parser.h"
2524
#include "swift/Subsystems.h"
26-
#include "llvm/Support/raw_ostream.h"
27-
#include "llvm/Support/MemoryBuffer.h"
2825
#include "llvm/ADT/SmallString.h"
26+
#include "llvm/Support/MemoryBuffer.h"
27+
#include "llvm/Support/raw_ostream.h"
2928
#include <algorithm>
3029

3130
using namespace swift;

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,27 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "swift/AST/USRGeneration.h"
1413
#include "swift/AST/ASTVisitor.h"
14+
#include "swift/AST/USRGeneration.h"
1515
#include "swift/Basic/Assertions.h"
16+
#include "swift/Basic/Defer.h"
1617
#include "swift/Basic/StringExtras.h"
1718
#include "swift/Frontend/Frontend.h"
19+
#include "swift/IDE/APIDigesterData.h"
1820
#include "swift/IDE/Utils.h"
19-
#include "swift/Sema/IDETypeChecking.h"
2021
#include "swift/Migrator/ASTMigratorPass.h"
2122
#include "swift/Migrator/EditorAdapter.h"
2223
#include "swift/Migrator/FixitApplyDiagnosticConsumer.h"
2324
#include "swift/Migrator/Migrator.h"
2425
#include "swift/Migrator/RewriteBufferEditsReceiver.h"
26+
#include "swift/Parse/Lexer.h"
27+
#include "swift/Sema/IDETypeChecking.h"
2528
#include "clang/Basic/Diagnostic.h"
2629
#include "clang/Basic/FileManager.h"
2730
#include "clang/Basic/SourceManager.h"
2831
#include "clang/Edit/EditedSource.h"
2932
#include "clang/Rewrite/Core/RewriteBuffer.h"
3033
#include "llvm/Support/FileSystem.h"
31-
#include "swift/IDE/APIDigesterData.h"
32-
#include "swift/Basic/Defer.h"
3334

3435
using namespace swift;
3536
using namespace swift::migrator;

0 commit comments

Comments
 (0)