Skip to content

Commit dacdb8f

Browse files
authored
Merge pull request #76577 from compnerd/undent
Remove `swift-indent` tool
2 parents e6e174c + 6443619 commit dacdb8f

20 files changed

+10
-1934
lines changed

docs/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,6 @@ provide greater clarity to contributors wanting to add new documentation.
356356
- [Testing.md](/docs/Testing.md):
357357
TODO: Consider splitting into a how-to guide on writing a new test case
358358
and an explanation for how the compiler is tested.
359-
- [SwiftIndent.md](/docs/SwiftIndent.md):
360-
TODO: Unclear if this is intended to be an explanation or a reference guide.
361359
- [Random.md](/docs/Random.md): Stub.
362360

363361
### Archive

docs/SwiftIndent.md

Lines changed: 0 additions & 56 deletions
This file was deleted.

include/swift/Driver/Driver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ class Driver {
180180
SwiftDependencyTool, // swift-dependency-tool
181181
SwiftLLVMOpt, // swift-llvm-opt
182182
AutolinkExtract, // swift-autolink-extract
183-
SwiftIndent, // swift-indent
184183
SymbolGraph, // swift-symbolgraph
185184
APIDigester, // swift-api-digester
186185
CacheTool, // swift-cache-tool

include/swift/Option/Options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace options {
3333
DoesNotAffectIncrementalBuild = (1 << 8),
3434
AutolinkExtractOption = (1 << 9),
3535
ModuleWrapOption = (1 << 10),
36-
SwiftIndentOption = (1 << 11),
36+
// 1 << 11 was previously `SwiftIndentOption`
3737
ArgumentIsPath = (1 << 12),
3838
ModuleInterfaceOption = (1 << 13),
3939
SupplementaryOutput = (1 << 14),

include/swift/Option/Options.td

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ def AutolinkExtractOption : OptionFlag;
2929
// The option should be accepted by swift -modulewrap
3030
def ModuleWrapOption : OptionFlag;
3131

32-
// The option should be accepted by swift-indent
33-
def SwiftIndentOption : OptionFlag;
34-
3532
// The option should not be accepted by the driver.
3633
def NoDriverOption : OptionFlag;
3734

@@ -218,7 +215,6 @@ def driver_mode : Joined<["--"], "driver-mode=">, Flags<[HelpHidden]>,
218215

219216
def help : Flag<["-", "--"], "help">,
220217
Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption,
221-
SwiftIndentOption,
222218
SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
223219
HelpText<"Display available options">;
224220
def h : Flag<["-"], "h">, Alias<help>;
@@ -268,8 +264,8 @@ def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>,
268264

269265
def o : JoinedOrSeparate<["-"], "o">,
270266
Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption,
271-
NoInteractiveOption, SwiftIndentOption, ArgumentIsPath,
272-
SwiftAPIDigesterOption, CacheInvariant]>,
267+
NoInteractiveOption, ArgumentIsPath, SwiftAPIDigesterOption,
268+
CacheInvariant]>,
273269
HelpText<"Write output to <file>">, MetaVarName<"<file>">;
274270

275271
def j : JoinedOrSeparate<["-"], "j">, Flags<[DoesNotAffectIncrementalBuild]>,
@@ -1146,28 +1142,28 @@ def AssertConfig : Separate<["-"], "assert-config">,
11461142
def code_formatting_Group : OptionGroup<"<code formatting options>">;
11471143

11481144
def use_tabs : Flag<["-"], "use-tabs">, Group<code_formatting_Group>,
1149-
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
1145+
Flags<[NoInteractiveOption, NoBatchOption]>,
11501146
HelpText<"Use tabs for indentation.">;
11511147

11521148
def indent_switch_case : Flag<["-"], "indent-switch-case">,
11531149
Group<code_formatting_Group>,
1154-
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
1150+
Flags<[NoInteractiveOption, NoBatchOption]>,
11551151
HelpText<"Indent cases in switch statements.">;
11561152

11571153
def in_place : Flag<["-"], "in-place">, Group<code_formatting_Group>,
1158-
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
1154+
Flags<[NoInteractiveOption, NoBatchOption]>,
11591155
HelpText<"Overwrite input file with formatted file.">;
11601156

11611157
def tab_width : Separate<["-"], "tab-width">, Group<code_formatting_Group>,
1162-
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
1158+
Flags<[NoInteractiveOption, NoBatchOption]>,
11631159
HelpText<"Width of tab character.">, MetaVarName<"<n>">;
11641160

11651161
def indent_width : Separate<["-"], "indent-width">, Group<code_formatting_Group>,
1166-
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
1162+
Flags<[NoInteractiveOption, NoBatchOption]>,
11671163
HelpText<"Number of characters to indent.">, MetaVarName<"<n>">;
11681164

11691165
def line_range : Separate<["-"], "line-range">, Group<code_formatting_Group>,
1170-
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
1166+
Flags<[NoInteractiveOption, NoBatchOption]>,
11711167
HelpText<"<start line>:<end line>. Formats a range of lines (1-based). "
11721168
"Can only be used with one input file.">, MetaVarName<"<n:n>">;
11731169

lib/Driver/Driver.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ void Driver::parseDriverKind(ArrayRef<const char *> Args) {
108108
.Case("swift-dependency-tool", DriverKind::SwiftDependencyTool)
109109
.Case("swift-llvm-opt", DriverKind::SwiftLLVMOpt)
110110
.Case("swift-autolink-extract", DriverKind::AutolinkExtract)
111-
.Case("swift-indent", DriverKind::SwiftIndent)
112111
.Case("swift-symbolgraph-extract", DriverKind::SymbolGraph)
113112
.Case("swift-api-digester", DriverKind::APIDigester)
114113
.Case("swift-cache-tool", DriverKind::CacheTool)
@@ -3108,7 +3107,6 @@ void Driver::printHelp(bool ShowHidden) const {
31083107
case DriverKind::SwiftDependencyTool:
31093108
case DriverKind::SwiftLLVMOpt:
31103109
case DriverKind::AutolinkExtract:
3111-
case DriverKind::SwiftIndent:
31123110
case DriverKind::SymbolGraph:
31133111
case DriverKind::APIDigester:
31143112
case DriverKind::CacheTool:

lib/DriverTool/driver.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ extern int autolink_extract_main(ArrayRef<const char *> Args, const char *Argv0,
9494
extern int modulewrap_main(ArrayRef<const char *> Args, const char *Argv0,
9595
void *MainAddr);
9696

97-
/// Run 'swift-indent'
98-
extern int swift_indent_main(ArrayRef<const char *> Args, const char *Argv0,
99-
void *MainAddr);
100-
10197
/// Run 'swift-symbolgraph-extract'
10298
extern int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv0,
10399
void *MainAddr);
@@ -389,10 +385,6 @@ static int run_driver(StringRef ExecName,
389385
return autolink_extract_main(
390386
TheDriver.getArgsWithoutProgramNameAndDriverMode(argv),
391387
argv[0], (void *)(intptr_t)getExecutablePath);
392-
case Driver::DriverKind::SwiftIndent:
393-
return swift_indent_main(
394-
TheDriver.getArgsWithoutProgramNameAndDriverMode(argv),
395-
argv[0], (void *)(intptr_t)getExecutablePath);
396388
case Driver::DriverKind::SymbolGraph:
397389
return swift_symbolgraph_extract_main(TheDriver.getArgsWithoutProgramNameAndDriverMode(argv), argv[0], (void *)(intptr_t)getExecutablePath);
398390
case Driver::DriverKind::APIDigester:

lib/DriverTool/swift_indent_main.cpp

Lines changed: 0 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -76,193 +76,3 @@ class FormatterDocument {
7676
return *SM.getLLVMSourceMgr().getMemoryBuffer(BufferID);
7777
}
7878
};
79-
80-
class SwiftIndentInvocation {
81-
private:
82-
std::string MainExecutablePath;
83-
std::string OutputFilename = "-";
84-
std::vector<std::string> InputFilenames;
85-
CodeFormatOptions FormatOptions;
86-
bool InPlace = false;
87-
std::vector<std::string> LineRanges;
88-
89-
bool parseLineRange(StringRef Input, unsigned &FromLine, unsigned &ToLine) {
90-
std::pair<StringRef, StringRef> LineRange = Input.split(":");
91-
return LineRange.first.getAsInteger(0, FromLine) ||
92-
LineRange.second.getAsInteger(0, ToLine);
93-
}
94-
95-
public:
96-
SwiftIndentInvocation(const std::string &ExecPath)
97-
: MainExecutablePath(ExecPath) {}
98-
99-
const std::string &getOutputFilename() { return OutputFilename; }
100-
101-
const std::vector<std::string> &getInputFilenames() { return InputFilenames; }
102-
103-
const std::vector<std::string> &getLineRanges() { return LineRanges; }
104-
105-
int parseArgs(ArrayRef<const char *> Args, DiagnosticEngine &Diags) {
106-
using namespace options;
107-
108-
std::unique_ptr<llvm::opt::OptTable> Table = createSwiftOptTable();
109-
unsigned MissingIndex;
110-
unsigned MissingCount;
111-
llvm::opt::InputArgList ParsedArgs =
112-
Table->ParseArgs(Args, MissingIndex, MissingCount, SwiftIndentOption);
113-
if (MissingCount) {
114-
Diags.diagnose(SourceLoc(), diag::error_missing_arg_value,
115-
ParsedArgs.getArgString(MissingIndex), MissingCount);
116-
return 1;
117-
}
118-
119-
if (ParsedArgs.getLastArg(OPT_use_tabs))
120-
FormatOptions.UseTabs = true;
121-
122-
if (ParsedArgs.getLastArg(OPT_indent_switch_case))
123-
FormatOptions.IndentSwitchCase = true;
124-
125-
if (ParsedArgs.getLastArg(OPT_in_place))
126-
InPlace = true;
127-
128-
if (const Arg *A = ParsedArgs.getLastArg(OPT_tab_width))
129-
if (StringRef(A->getValue()).getAsInteger(10, FormatOptions.TabWidth))
130-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
131-
A->getAsString(ParsedArgs), A->getValue());
132-
133-
if (const Arg *A = ParsedArgs.getLastArg(OPT_indent_width))
134-
if (StringRef(A->getValue()).getAsInteger(10, FormatOptions.IndentWidth))
135-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
136-
A->getAsString(ParsedArgs), A->getValue());
137-
138-
for (const Arg *A : ParsedArgs.filtered(OPT_line_range))
139-
LineRanges.push_back(A->getValue());
140-
141-
if (ParsedArgs.hasArg(OPT_UNKNOWN)) {
142-
for (const Arg *A : ParsedArgs.filtered(OPT_UNKNOWN)) {
143-
Diags.diagnose(SourceLoc(), diag::error_unknown_arg,
144-
A->getAsString(ParsedArgs));
145-
}
146-
return true;
147-
}
148-
149-
if (ParsedArgs.getLastArg(OPT_help)) {
150-
std::string ExecutableName =
151-
llvm::sys::path::stem(MainExecutablePath).str();
152-
Table->printHelp(llvm::outs(), ExecutableName.c_str(),
153-
"Swift Format Tool", options::SwiftIndentOption, 0,
154-
/*ShowAllAliases*/false);
155-
return 1;
156-
}
157-
158-
for (const Arg *A : ParsedArgs.filtered(OPT_INPUT)) {
159-
InputFilenames.push_back(A->getValue());
160-
}
161-
162-
if (const Arg *A = ParsedArgs.getLastArg(OPT_o)) {
163-
OutputFilename = A->getValue();
164-
}
165-
166-
return 0;
167-
}
168-
169-
/// Formats a filename and returns false if successful, true otherwise.
170-
bool format(StringRef Filename, DiagnosticEngine &Diags) {
171-
auto ErrOrBuf = llvm::MemoryBuffer::getFileOrSTDIN(Filename);
172-
if (!ErrOrBuf) {
173-
Diags.diagnose(SourceLoc(), diag::error_no_such_file_or_directory,
174-
Filename);
175-
return true;
176-
}
177-
std::unique_ptr<llvm::MemoryBuffer> Code = std::move(ErrOrBuf.get());
178-
if (Code->getBufferSize() == 0) {
179-
// Assume empty files are formatted successfully.
180-
return false;
181-
}
182-
FormatterDocument Doc(std::move(Code));
183-
if (LineRanges.empty()) {
184-
LineRanges.push_back("1:" + std::to_string(UINT_MAX));
185-
}
186-
187-
std::string Output = Doc.memBuffer().getBuffer().str();
188-
for (unsigned Range = 0; Range < LineRanges.size(); ++Range) {
189-
unsigned FromLine;
190-
unsigned ToLine;
191-
if (parseLineRange(LineRanges[Range], FromLine, ToLine)) {
192-
Diags.diagnose(SourceLoc(), diag::error_formatting_invalid_range);
193-
return true;
194-
}
195-
if (FromLine > ToLine) {
196-
Diags.diagnose(SourceLoc(), diag::error_formatting_invalid_range);
197-
return true;
198-
}
199-
for (unsigned Line = FromLine; Line <= ToLine; ++Line) {
200-
size_t Offset = getOffsetOfLine(Line, Output);
201-
ssize_t Length = getOffsetOfLine(Line + 1, Output) - 1 - Offset;
202-
if (Length < 0)
203-
break;
204-
205-
std::string Formatted =
206-
Doc.reformat(LineRange(Line, 1), FormatOptions).second;
207-
if (Formatted.find_first_not_of(" \t\v\f", 0) == StringRef::npos)
208-
Formatted = "";
209-
210-
Output.replace(Offset, Length, Formatted);
211-
Doc.updateCode(llvm::MemoryBuffer::getMemBufferCopy(Output));
212-
}
213-
if (Filename == "-" || (!InPlace && OutputFilename == "-")) {
214-
llvm::outs() << Output;
215-
return false;
216-
}
217-
std::error_code EC;
218-
StringRef Destination;
219-
if (InPlace)
220-
Destination = Filename;
221-
else
222-
Destination = OutputFilename;
223-
llvm::raw_fd_ostream out(Destination, EC, llvm::sys::fs::OF_None);
224-
if (out.has_error() || EC) {
225-
Diags.diagnose(SourceLoc(), diag::error_opening_output, Filename,
226-
EC.message());
227-
out.clear_error();
228-
return true;
229-
}
230-
out << Output;
231-
}
232-
return false;
233-
}
234-
};
235-
236-
int swift_indent_main(ArrayRef<const char *> Args, const char *Argv0,
237-
void *MainAddr) {
238-
CompilerInstance Instance;
239-
PrintingDiagnosticConsumer PDC;
240-
Instance.addDiagnosticConsumer(&PDC);
241-
242-
SwiftIndentInvocation Invocation(
243-
llvm::sys::fs::getMainExecutable(Argv0, MainAddr));
244-
245-
DiagnosticEngine &Diags = Instance.getDiags();
246-
if (Invocation.parseArgs(Args, Diags) != 0)
247-
return EXIT_FAILURE;
248-
249-
std::vector<std::string> InputFiles = Invocation.getInputFilenames();
250-
unsigned NumInputFiles = InputFiles.size();
251-
if (NumInputFiles == 0) {
252-
// Read source code from standard input.
253-
Invocation.format("-", Diags);
254-
} else if (NumInputFiles == 1) {
255-
Invocation.format(InputFiles[0], Diags);
256-
} else {
257-
if (!Invocation.getLineRanges().empty()) {
258-
// We don't support formatting file ranges for multiple files.
259-
Instance.getDiags().diagnose(SourceLoc(),
260-
diag::error_formatting_multiple_file_ranges);
261-
return EXIT_FAILURE;
262-
}
263-
for (unsigned i = 0; i < NumInputFiles; ++i)
264-
Invocation.format(InputFiles[i], Diags);
265-
}
266-
267-
return EXIT_SUCCESS;
268-
}

lib/FrontendTool/FrontendTool.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,6 @@ static void printSingleFrontendOpt(llvm::opt::OptTable &table, options::ID id,
10781078
if (table.getOption(id).hasFlag(options::FrontendOption) ||
10791079
table.getOption(id).hasFlag(options::AutolinkExtractOption) ||
10801080
table.getOption(id).hasFlag(options::ModuleWrapOption) ||
1081-
table.getOption(id).hasFlag(options::SwiftIndentOption) ||
10821081
table.getOption(id).hasFlag(options::SwiftSymbolGraphExtractOption) ||
10831082
table.getOption(id).hasFlag(options::SwiftAPIDigesterOption)) {
10841083
auto name = StringRef(table.getOptionName(id));

0 commit comments

Comments
 (0)