[Frontend] Nicer assert when -dump-parse foo.sil

Invoking the following command to `-dump-parse` a file containing SIL
triggers an assertion from within the Swift compiler frontend:

```
swiftc -dump-parse foo.sil
```

The assertion is not coupled with a description of what went wrong.
It turns out the frontend doesn't support `-dump-parse` for SIL files,
although `swiftc -help` wouldn't inform users of that:

```
-dump-parse      Parse input file(s) and dump AST(s)
```

As a result, a user may invoke `-dump-parse` on a SIL file and not know
what went wrong. Add an assertion message to inform the user that only
Swift code may be parsed. (`IFK_Swift_Library` here is for the case
where `swiftc -parse-as-library -dump-parse foo.swift` is invoked.)
This commit is contained in:
Brian Gesiak
2016-03-30 00:14:08 -04:00
parent 9674182943
commit 2e5f1649d6

View File

@@ -531,7 +531,8 @@ void CompilerInstance::performParseOnly() {
Module *MainModule = getMainModule();
Context->LoadedModules[MainModule->getName()] = MainModule;
assert(Kind == InputFileKind::IFK_Swift || Kind == InputFileKind::IFK_Swift_Library);
assert((Kind == InputFileKind::IFK_Swift || Kind == InputFileKind::IFK_Swift_Library) &&
"only supports parsing a single .swift file");
assert(BufferIDs.size() == 1 && "only supports parsing a single file");
if (Kind == InputFileKind::IFK_Swift)