Preserve default argument text through serialization (#18579)

This allows us to dump it in the generated interface, though it's
still not syntax-highlighted. This is necessary for textual module
interfaces, but it's also just a longstanding request for Xcode's
"Generated Interface" / "Jump to Definition" feature.

rdar://problem/18675831
This commit is contained in:
Jordan Rose
2018-08-09 11:06:22 -07:00
committed by GitHub
parent b7e513759c
commit 0e10f89964
15 changed files with 117 additions and 74 deletions

View File

@@ -3168,6 +3168,12 @@ void Serializer::writeDecl(const Decl *D) {
auto contextID = addDeclContextRef(param->getDeclContext());
Type interfaceType = param->getInterfaceType();
// Only save the text for normal default arguments, not any of the special
// ones.
StringRef defaultArgumentText;
if (param->getDefaultArgumentKind() == swift::DefaultArgumentKind::Normal)
defaultArgumentText = param->getDefaultValueStringRepresentation();
unsigned abbrCode = DeclTypeAbbrCodes[ParamLayout::Code];
ParamLayout::emitRecord(Out, ScratchRecord, abbrCode,
addDeclBaseNameRef(param->getArgumentName()),
@@ -3176,7 +3182,8 @@ void Serializer::writeDecl(const Decl *D) {
getRawStableVarDeclSpecifier(param->getSpecifier()),
addTypeRef(interfaceType),
param->isVariadic(),
getRawStableDefaultArgumentKind(param->getDefaultArgumentKind()));
getRawStableDefaultArgumentKind(param->getDefaultArgumentKind()),
defaultArgumentText);
if (interfaceType->hasError()) {
param->getDeclContext()->dumpContext();