mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Start the Migrator library
The Swift 4 Migrator is invoked through either the driver and frontend
with the -update-code flag.
The basic pipeline in the frontend is:
- Perform some list of syntactic fixes (there are currently none).
- Perform N rounds of sema fix-its on the primary input file, currently
set to 7 based on prior migrator seasons. Right now, this is just set
to take any fix-it suggested by the compiler.
- Emit a replacement map file, a JSON file describing replacements to a
file that Xcode knows how to understand.
Currently, the Migrator maintains a history of migration states along
the way for debugging purposes.
- Add -emit-remap frontend option
This will indicate the EmitRemap frontend action.
- Don't fork to a separte swift-update binary.
This is going to be a mode of the compiler, invoked by the same flags.
- Add -disable-migrator-fixits option
Useful for debugging, this skips the phase in the Migrator that
automatically applies fix-its suggested by the compiler.
- Add -emit-migrated-file-path option
This is used for testing/debugging scenarios. This takes the final
migration state's output text and writes it to the file specified
by this option.
- Add -dump-migration-states-dir
This dumps all of the migration states encountered during a migration
run for a file to the given directory. For example, the compiler
fix-it migration pass dumps the input file, the output file, and the
remap file between the two.
State output has the following naming convention:
${Index}-${MigrationPassName}-${What}.${extension}, such as:
1-FixitMigrationState-Input.swift
rdar://problem/30926261
This commit is contained in:
@@ -69,7 +69,7 @@ int getTokensFromFile(unsigned BufferID,
|
||||
LangOptions &LangOpts,
|
||||
SourceManager &SourceMgr,
|
||||
DiagnosticEngine &Diags,
|
||||
std::vector<std::pair<syntax::RC<syntax::TokenSyntax>,
|
||||
std::vector<std::pair<RC<syntax::TokenSyntax>,
|
||||
syntax::AbsolutePosition>> &Tokens) {
|
||||
Tokens = tokenizeWithTrivia(LangOpts, SourceMgr, BufferID);
|
||||
return Diags.hadAnyError() ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
@@ -81,7 +81,7 @@ getTokensFromFile(const StringRef InputFilename,
|
||||
LangOptions &LangOpts,
|
||||
SourceManager &SourceMgr,
|
||||
DiagnosticEngine &Diags,
|
||||
std::vector<std::pair<syntax::RC<syntax::TokenSyntax>,
|
||||
std::vector<std::pair<RC<syntax::TokenSyntax>,
|
||||
syntax::AbsolutePosition>> &Tokens) {
|
||||
auto Buffer = llvm::MemoryBuffer::getFile(InputFilename);
|
||||
if (!Buffer) {
|
||||
@@ -101,7 +101,7 @@ int doFullLexRoundTrip(const StringRef InputFilename) {
|
||||
PrintingDiagnosticConsumer DiagPrinter;
|
||||
Diags.addConsumer(DiagPrinter);
|
||||
|
||||
std::vector<std::pair<syntax::RC<syntax::TokenSyntax>,
|
||||
std::vector<std::pair<RC<syntax::TokenSyntax>,
|
||||
syntax::AbsolutePosition>> Tokens;
|
||||
if (getTokensFromFile(InputFilename, LangOpts, SourceMgr,
|
||||
Diags, Tokens) == EXIT_FAILURE) {
|
||||
@@ -123,7 +123,7 @@ int doDumpTokenSyntax(const StringRef InputFilename) {
|
||||
Diags.addConsumer(DiagPrinter);
|
||||
|
||||
|
||||
std::vector<std::pair<syntax::RC<syntax::TokenSyntax>,
|
||||
std::vector<std::pair<RC<syntax::TokenSyntax>,
|
||||
syntax::AbsolutePosition>> Tokens;
|
||||
if (getTokensFromFile(InputFilename, LangOpts, SourceMgr,
|
||||
Diags, Tokens) == EXIT_FAILURE) {
|
||||
@@ -172,7 +172,7 @@ int doFullParseRoundTrip(const StringRef InputFilename) {
|
||||
assert(SF && "No source file");
|
||||
|
||||
// Retokenize the buffer with full fidelity
|
||||
std::vector<std::pair<syntax::RC<syntax::TokenSyntax>,
|
||||
std::vector<std::pair<RC<syntax::TokenSyntax>,
|
||||
syntax::AbsolutePosition>> Tokens;
|
||||
if (getTokensFromFile(BufferID, Invocation.getLangOptions(),
|
||||
SourceMgr,
|
||||
|
||||
Reference in New Issue
Block a user