Rework PatternBindingDecl to maintain a list of pattern/initexpr pairs inside of it.

Previously, a multi-pattern var/let decl like:
  var x = 4, y = 17

would produce two pattern binding decls (one for x=4 one for y=17).  This is convenient
in some ways, but is bad for source reproducibility from the ASTs (see, e.g. the improvements
in test/IDE/structure.swift and test/decl/inherit/initializer.swift).

The hardest part of this change was to get parseDeclVar to set up the AST in a way
compatible with our existing assumptions. I ended up with an approach that forms PBDs in 
more erroneous cases than before.  One downside of this is that we now produce a spurious
  "type annotation missing in pattern"
diagnostic in some cases.  I'll take care of that in a follow-on patch.





Swift SVN r26224
This commit is contained in:
Chris Lattner
2015-03-17 16:14:18 +00:00
parent a1d3895bd2
commit 59c22383fb
40 changed files with 809 additions and 540 deletions

View File

@@ -24,6 +24,7 @@
#include "swift/AST/ModuleLoader.h"
#include "swift/AST/NameLookup.h"
#include "swift/AST/ReferencedNameTracker.h"
#include "swift/AST/PrettyStackTrace.h"
#include "swift/AST/PrintOptions.h"
#include "swift/Basic/SourceManager.h"
#include "clang/Basic/Module.h"
@@ -1556,6 +1557,10 @@ bool FileUnit::walk(ASTWalker &walker) {
llvm::SaveAndRestore<ASTWalker::ParentTy> SAR(walker.Parent,
getParentModule());
for (Decl *D : Decls) {
#ifndef NDEBUG
PrettyStackTraceDecl debugStack("walking into decl", D);
#endif
if (D->walk(walker))
return true;
}
@@ -1566,6 +1571,10 @@ bool SourceFile::walk(ASTWalker &walker) {
llvm::SaveAndRestore<ASTWalker::ParentTy> SAR(walker.Parent,
getParentModule());
for (Decl *D : Decls) {
#ifndef NDEBUG
PrettyStackTraceDecl debugStack("walking into decl", D);
#endif
if (D->walk(walker))
return true;
}