[InterfaceGen] Print private/internal properties (#19127)

* [Interface] Print private/internal properties

All properties which contribute to the storage of a type should be
printed, and their names should be hidden from interfaces. Print them
with '_' as their name, and teach the parser to recognize these special
patterns when parsing interface files.

Partially resolves rdar://43810647

* Address review comments

* Disable accessor generation for nameless vars

* Test to ensure interface files preserve type layout

* Ignore attribute differences on Linux
This commit is contained in:
Harlan
2018-09-06 09:58:33 -07:00
committed by GitHub
parent 3e7e9f33d1
commit ad7e1d0e67
6 changed files with 213 additions and 6 deletions

View File

@@ -18,6 +18,7 @@
#include "swift/AST/ASTWalker.h"
#include "swift/AST/Initializer.h"
#include "swift/AST/Module.h"
#include "swift/Basic/StringExtras.h"
#include "swift/Parse/CodeCompletionCallbacks.h"
#include "swift/Parse/SyntaxParsingContext.h"
@@ -907,11 +908,27 @@ ParserResult<Pattern> Parser::parseTypedPattern() {
///
ParserResult<Pattern> Parser::parsePattern() {
SyntaxParsingContext PatternCtx(SyntaxContext, SyntaxContextKind::Pattern);
bool isLet = (InVarOrLetPattern != IVOLP_InVar);
auto specifier = isLet
? VarDecl::Specifier::Let
: VarDecl::Specifier::Var;
switch (Tok.getKind()) {
case tok::l_paren:
return parsePatternTuple();
case tok::kw__:
// Normally, '_' is invalid in type context for patterns, but they show up
// in interface files as the name for type members that are non-public.
// Treat them as an implicitly synthesized NamedPattern with a nameless
// VarDecl inside.
if (CurDeclContext->isTypeContext() &&
SF.Kind == SourceFileKind::Interface) {
PatternCtx.setCreateSyntax(SyntaxKind::IdentifierPattern);
auto VD = new (Context) VarDecl(
/*IsStatic*/false, specifier, /*IsCaptureList*/false,
consumeToken(tok::kw__), Identifier(), CurDeclContext);
return makeParserResult(new (Context) NamedPattern(VD, /*implicit*/true));
}
PatternCtx.setCreateSyntax(SyntaxKind::WildcardPattern);
return makeParserResult(new (Context) AnyPattern(consumeToken(tok::kw__)));
@@ -919,10 +936,6 @@ ParserResult<Pattern> Parser::parsePattern() {
PatternCtx.setCreateSyntax(SyntaxKind::IdentifierPattern);
Identifier name;
SourceLoc loc = consumeIdentifier(&name);
bool isLet = (InVarOrLetPattern != IVOLP_InVar);
auto specifier = isLet
? VarDecl::Specifier::Let
: VarDecl::Specifier::Var;
if (Tok.isIdentifierOrUnderscore() && !Tok.isContextualDeclKeyword())
diagnoseConsecutiveIDs(name.str(), loc, isLet ? "constant" : "variable");