Skip to content

[Parse] Remove unnecessary dependencies to Parser.h #77361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "swift/IRGen/TBDGen.h"
#include "swift/Migrator/MigratorOptions.h"
#include "swift/Parse/IDEInspectionCallbacks.h"
#include "swift/Parse/Parser.h"
#include "swift/Sema/SourceLoader.h"
#include "swift/Serialization/Validation.h"
#include "swift/Subsystems.h"
Expand All @@ -52,9 +51,9 @@
#include "llvm/Option/ArgList.h"
#include "llvm/Support/BLAKE3.h"
#include "llvm/Support/HashingOutputBackend.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/VirtualOutputBackend.h"
#include "llvm/TargetParser/Host.h"

#include <memory>

Expand Down
1 change: 1 addition & 0 deletions include/swift/Migrator/FixitFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define SWIFT_MIGRATOR_FIXITFILTER_H

#include "swift/AST/DiagnosticConsumer.h"
#include "swift/AST/DiagnosticsParse.h"
#include "swift/AST/DiagnosticsSema.h"

namespace swift {
Expand Down
100 changes: 100 additions & 0 deletions include/swift/Parse/ParseDeclName.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//===--- ParseDeclName.h ----------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_PARSE_PARSEDECLNAME_H
#define SWIFT_PARSE_PARSEDECLNAME_H

#include "swift/AST/Identifier.h"
#include "swift/Basic/LLVM.h"
#include "swift/Parse/Lexer.h"

namespace swift {

/// Describes a parsed declaration name.
struct ParsedDeclName {
/// The name of the context of which the corresponding entity should
/// become a member.
StringRef ContextName;

/// The base name of the declaration.
StringRef BaseName;

/// The argument labels for a function declaration.
SmallVector<StringRef, 4> ArgumentLabels;

/// Whether this is a function name (vs. a value name).
bool IsFunctionName = false;

/// Whether this is a getter for the named property.
bool IsGetter = false;

/// Whether this is a setter for the named property.
bool IsSetter = false;

bool IsSubscript = false;

/// For a declaration name that makes the declaration into an
/// instance member, the index of the "Self" parameter.
std::optional<unsigned> SelfIndex;

/// Determine whether this is a valid name.
explicit operator bool() const { return !BaseName.empty(); }

/// Whether this declaration name turns the declaration into a
/// member of some named context.
bool isMember() const { return !ContextName.empty(); }

/// Whether the result is translated into an instance member.
bool isInstanceMember() const {
return isMember() && static_cast<bool>(SelfIndex);
}

/// Whether the result is translated into a static/class member.
bool isClassMember() const {
return isMember() && !static_cast<bool>(SelfIndex);
}

/// Whether this is a property accessor.
bool isPropertyAccessor() const { return IsGetter || IsSetter; }

/// Whether this is an operator.
bool isOperator() const { return Lexer::isOperator(BaseName); }

/// Form a declaration name from this parsed declaration name.
DeclName formDeclName(ASTContext &ctx, bool isSubscript = false,
bool isCxxClassTemplateSpec = false) const;

/// Form a declaration name from this parsed declaration name.
DeclNameRef formDeclNameRef(ASTContext &ctx, bool isSubscript = false,
bool isCxxClassTemplateSpec = false) const;
};

/// Parse a stringified Swift declaration name,
/// e.g. "Foo.translateBy(self:x:y:)".
ParsedDeclName parseDeclName(StringRef name) LLVM_READONLY;

/// Form a Swift declaration name from its constituent parts.
DeclName formDeclName(ASTContext &ctx, StringRef baseName,
ArrayRef<StringRef> argumentLabels, bool isFunctionName,
bool isInitializer, bool isSubscript = false,
bool isCxxClassTemplateSpec = false);

/// Form a Swift declaration name reference from its constituent parts.
DeclNameRef formDeclNameRef(ASTContext &ctx, StringRef baseName,
ArrayRef<StringRef> argumentLabels,
bool isFunctionName, bool isInitializer,
bool isSubscript = false,
bool isCxxClassTemplateSpec = false);

} // namespace swift

#endif // SWIFT_PARSE_PARSEDECLNAME_H
85 changes: 1 addition & 84 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -2118,67 +2118,6 @@ class Parser {
ParserResult<Expr> parseExprFromSyntaxTree();
};

/// Describes a parsed declaration name.
struct ParsedDeclName {
/// The name of the context of which the corresponding entity should
/// become a member.
StringRef ContextName;

/// The base name of the declaration.
StringRef BaseName;

/// The argument labels for a function declaration.
SmallVector<StringRef, 4> ArgumentLabels;

/// Whether this is a function name (vs. a value name).
bool IsFunctionName = false;

/// Whether this is a getter for the named property.
bool IsGetter = false;

/// Whether this is a setter for the named property.
bool IsSetter = false;

bool IsSubscript = false;

/// For a declaration name that makes the declaration into an
/// instance member, the index of the "Self" parameter.
std::optional<unsigned> SelfIndex;

/// Determine whether this is a valid name.
explicit operator bool() const { return !BaseName.empty(); }

/// Whether this declaration name turns the declaration into a
/// member of some named context.
bool isMember() const { return !ContextName.empty(); }

/// Whether the result is translated into an instance member.
bool isInstanceMember() const {
return isMember() && static_cast<bool>(SelfIndex);
}

/// Whether the result is translated into a static/class member.
bool isClassMember() const {
return isMember() && !static_cast<bool>(SelfIndex);
}

/// Whether this is a property accessor.
bool isPropertyAccessor() const { return IsGetter || IsSetter; }

/// Whether this is an operator.
bool isOperator() const {
return Lexer::isOperator(BaseName);
}

/// Form a declaration name from this parsed declaration name.
DeclName formDeclName(ASTContext &ctx, bool isSubscript = false,
bool isCxxClassTemplateSpec = false) const;

/// Form a declaration name from this parsed declaration name.
DeclNameRef formDeclNameRef(ASTContext &ctx, bool isSubscript = false,
bool isCxxClassTemplateSpec = false) const;
};

/// To assist debugging parser crashes, tell us the location of the
/// current token.
class PrettyStackTraceParser : public llvm::PrettyStackTraceEntry {
Expand All @@ -2188,28 +2127,6 @@ class PrettyStackTraceParser : public llvm::PrettyStackTraceEntry {
void print(llvm::raw_ostream &out) const override;
};

/// Parse a stringified Swift declaration name,
/// e.g. "Foo.translateBy(self:x:y:)".
ParsedDeclName parseDeclName(StringRef name) LLVM_READONLY;

/// Form a Swift declaration name from its constituent parts.
DeclName formDeclName(ASTContext &ctx,
StringRef baseName,
ArrayRef<StringRef> argumentLabels,
bool isFunctionName,
bool isInitializer,
bool isSubscript = false,
bool isCxxClassTemplateSpec = false);

/// Form a Swift declaration name reference from its constituent parts.
DeclNameRef formDeclNameRef(ASTContext &ctx,
StringRef baseName,
ArrayRef<StringRef> argumentLabels,
bool isFunctionName,
bool isInitializer,
bool isSubscript = false,
bool isCxxClassTemplateSpec = false);

/// Whether a given token can be the start of a decl.
bool isKeywordPossibleDeclStart(const LangOptions &options, const Token &Tok);

Expand Down
5 changes: 3 additions & 2 deletions lib/APIDigester/ModuleAnalyzerNodes.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "llvm/ADT/STLExtras.h"
#include "swift/AST/ASTMangler.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/Defer.h"
#include "swift/Parse/Lexer.h"
#include "swift/Sema/IDETypeChecking.h"
#include <swift/APIDigester/ModuleAnalyzerNodes.h>
#include "llvm/ADT/STLExtras.h"
#include <algorithm>
#include <swift/APIDigester/ModuleAnalyzerNodes.h>

using namespace swift;
using namespace ide;
Expand Down
5 changes: 3 additions & 2 deletions lib/AST/AccessNotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
//===----------------------------------------------------------------------===//

#include "swift/AST/AccessNotes.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/Attr.h"
#include "swift/AST/Decl.h"
#include "swift/AST/Module.h" // DeclContext::isModuleScopeContext()
#include "swift/AST/DiagnosticsFrontend.h"
#include "swift/AST/Module.h" // DeclContext::isModuleScopeContext()
#include "swift/Basic/Assertions.h"
#include "swift/Parse/Parser.h"
#include "swift/Parse/ParseDeclName.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/YAMLTraits.h"
Expand Down
2 changes: 0 additions & 2 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
#include "swift/Basic/Version.h"
#include "swift/ClangImporter/ClangImporterRequests.h"
#include "swift/ClangImporter/ClangModule.h"
#include "swift/Parse/Lexer.h"
#include "swift/Parse/ParseVersion.h"
#include "swift/Parse/Parser.h"
#include "swift/Strings.h"
#include "swift/Subsystems.h"
#include "clang/AST/ASTContext.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "swift/Basic/STLExtras.h"
#include "swift/Basic/StringExtras.h"
#include "swift/ClangImporter/ClangImporterRequests.h"
#include "swift/Parse/Parser.h"
#include "swift/Parse/ParseDeclName.h"
#include "swift/Strings.h"
#include "swift/Subsystems.h"
#include "clang/AST/ASTContext.h"
Expand Down
6 changes: 3 additions & 3 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@
#include "ArgsToFrontendOptionsConverter.h"
#include "swift/AST/DiagnosticsFrontend.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/Feature.h"
#include "swift/Basic/Platform.h"
#include "swift/Option/Options.h"
#include "swift/Option/SanitizerOptions.h"
#include "swift/Parse/Lexer.h"
#include "swift/Parse/ParseVersion.h"
#include "swift/SIL/SILBridging.h"
#include "swift/Strings.h"
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/VersionTuple.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/WithColor.h"
#include "llvm/TargetParser/Triple.h"

using namespace swift;
using namespace llvm::opt;
Expand Down
6 changes: 3 additions & 3 deletions lib/IDE/Formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#include "swift/AST/GenericParamList.h"
#include "swift/AST/TypeRepr.h"
#include "swift/Basic/Assertions.h"
#include "swift/IDE/SourceEntityWalker.h"
#include "swift/Parse/Parser.h"
#include "swift/Frontend/Frontend.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Frontend/Frontend.h"
#include "swift/IDE/Indenting.h"
#include "swift/IDE/SourceEntityWalker.h"
#include "swift/Parse/Lexer.h"
#include "swift/Subsystems.h"

using namespace swift;
Expand Down
7 changes: 4 additions & 3 deletions lib/IDE/IDERequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@
//
//===----------------------------------------------------------------------===//

#include "swift/IDE/IDERequests.h"
#include "swift/AST/ASTDemangler.h"
#include "swift/AST/ASTPrinter.h"
#include "swift/AST/Decl.h"
#include "swift/AST/Effects.h"
#include "swift/AST/NameLookup.h"
#include "swift/AST/ASTDemangler.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Frontend/Frontend.h"
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
#include "swift/IDE/CommentConversion.h"
#include "swift/IDE/Utils.h"
#include "swift/Sema/IDETypeChecking.h"
#include "swift/Markup/XMLUtils.h"
#include "swift/Parse/Lexer.h"
#include "swift/Sema/IDETypeChecking.h"
#include "swift/Subsystems.h"
#include "swift/IDE/IDERequests.h"

using namespace swift;
using namespace swift::ide;
Expand Down
5 changes: 2 additions & 3 deletions lib/IDE/REPLCodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
#include "swift/AST/SourceFile.h"
#include "swift/Basic/LLVM.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Parse/Parser.h"
#include "swift/Subsystems.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>

using namespace swift;
Expand Down
9 changes: 5 additions & 4 deletions lib/Migrator/APIDiffMigratorPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,27 @@
//
//===----------------------------------------------------------------------===//

#include "swift/AST/USRGeneration.h"
#include "swift/AST/ASTVisitor.h"
#include "swift/AST/USRGeneration.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/Defer.h"
#include "swift/Basic/StringExtras.h"
#include "swift/Frontend/Frontend.h"
#include "swift/IDE/APIDigesterData.h"
#include "swift/IDE/Utils.h"
#include "swift/Sema/IDETypeChecking.h"
#include "swift/Migrator/ASTMigratorPass.h"
#include "swift/Migrator/EditorAdapter.h"
#include "swift/Migrator/FixitApplyDiagnosticConsumer.h"
#include "swift/Migrator/Migrator.h"
#include "swift/Migrator/RewriteBufferEditsReceiver.h"
#include "swift/Parse/Lexer.h"
#include "swift/Sema/IDETypeChecking.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Edit/EditedSource.h"
#include "clang/Rewrite/Core/RewriteBuffer.h"
#include "llvm/Support/FileSystem.h"
#include "swift/IDE/APIDigesterData.h"
#include "swift/Basic/Defer.h"

using namespace swift;
using namespace swift::migrator;
Expand Down
Loading