mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Syntax] Remove LegacyASTTransformer
As it is no longer ever instantiated, and since Syntax nodes are being plumbed through the parser, the LegacyASTTransformer no longer needs to exist.
This commit is contained in:
@@ -27,7 +27,6 @@
|
||||
#include "swift/Parse/Lexer.h"
|
||||
#include "swift/Parse/Parser.h"
|
||||
#include "swift/Subsystems.h"
|
||||
#include "swift/AST/LegacyASTTransformer.h"
|
||||
#include "swift/Syntax/Serialization/SyntaxSerialization.h"
|
||||
#include "swift/Syntax/SyntaxData.h"
|
||||
#include "swift/Syntax/SyntaxNodes.h"
|
||||
@@ -155,42 +154,6 @@ SourceFile *getSourceFile(CompilerInstance &Instance,
|
||||
return SF;
|
||||
}
|
||||
|
||||
int getSyntaxTree(const char *MainExecutablePath,
|
||||
const StringRef InputFilename,
|
||||
CompilerInstance &Instance,
|
||||
llvm::SmallVectorImpl<syntax::Syntax> &TopLevelDecls,
|
||||
std::vector<std::pair<RC<syntax::RawTokenSyntax>,
|
||||
syntax::AbsolutePosition>> &Tokens) {
|
||||
auto *SF = getSourceFile(Instance, InputFilename, MainExecutablePath);
|
||||
auto &SourceMgr = Instance.getSourceMgr();
|
||||
auto BufferID = Instance.getInputBufferIDs().back();
|
||||
|
||||
// Retokenize the buffer with full fidelity
|
||||
if (getTokensFromFile(BufferID, SF->getASTContext().LangOpts,
|
||||
SourceMgr,
|
||||
Instance.getDiags(), Tokens) == EXIT_FAILURE) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
SmallVector<Decl *, 256> FileDecls;
|
||||
SF->getTopLevelDecls(FileDecls);
|
||||
SyntaxASTMap ASTMap;
|
||||
// Convert the old ASTs to the new full-fidelity syntax tree and print
|
||||
// them out.
|
||||
for (auto *Decl : FileDecls) {
|
||||
if (Decl->escapedFromIfConfig()) {
|
||||
continue;
|
||||
}
|
||||
auto NewNode = transformAST(ASTNode(Decl), ASTMap, SourceMgr,
|
||||
BufferID, Tokens);
|
||||
if (NewNode.hasValue()) {
|
||||
TopLevelDecls.push_back(NewNode.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int doFullLexRoundTrip(const StringRef InputFilename) {
|
||||
LangOptions LangOpts;
|
||||
SourceManager SourceMgr;
|
||||
@@ -237,46 +200,21 @@ int doDumpRawTokenSyntax(const StringRef InputFilename) {
|
||||
}
|
||||
|
||||
int doFullParseRoundTrip(const char *MainExecutablePath,
|
||||
const StringRef InputFilename) {
|
||||
|
||||
llvm::SmallVector<syntax::Syntax, 10> TopLevelDecls;
|
||||
std::vector<std::pair<RC<syntax::RawTokenSyntax>,
|
||||
syntax::AbsolutePosition>> Tokens;
|
||||
const StringRef InputFileName) {
|
||||
CompilerInstance Instance;
|
||||
|
||||
getSyntaxTree(MainExecutablePath, InputFilename, Instance,
|
||||
TopLevelDecls, Tokens);
|
||||
|
||||
for (auto &Node : TopLevelDecls) {
|
||||
Node.print(llvm::outs());
|
||||
}
|
||||
|
||||
if (Tokens.back().first->getTokenKind() == tok::eof) {
|
||||
Tokens.back().first->print(llvm::outs());
|
||||
}
|
||||
|
||||
SourceFile *SF = getSourceFile(Instance, InputFileName, MainExecutablePath);
|
||||
SF->getSyntaxRoot().print(llvm::outs(), {});
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int doSerializeRawTree(const char *MainExecutablePath,
|
||||
const StringRef InputFilename) {
|
||||
|
||||
llvm::SmallVector<syntax::Syntax, 10> TopLevelDecls;
|
||||
std::vector<std::pair<RC<syntax::RawTokenSyntax>,
|
||||
syntax::AbsolutePosition>> Tokens;
|
||||
const StringRef InputFileName) {
|
||||
CompilerInstance Instance;
|
||||
SourceFile *SF = getSourceFile(Instance, InputFileName, MainExecutablePath);
|
||||
|
||||
getSyntaxTree(MainExecutablePath, InputFilename, Instance,
|
||||
TopLevelDecls, Tokens);
|
||||
|
||||
std::vector<RC<syntax::RawSyntax>> RawTopLevelDecls;
|
||||
for (auto &Decl : TopLevelDecls) {
|
||||
RawTopLevelDecls.push_back(Decl.getRaw());
|
||||
}
|
||||
|
||||
auto Root = SF->getSyntaxRoot().getRaw();
|
||||
swift::json::Output out(llvm::outs());
|
||||
out << RawTopLevelDecls;
|
||||
|
||||
out << Root;
|
||||
llvm::outs() << "\n";
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user