Share
Embed
Transcript
155 slides
-
͡Ίʹ let a = 1 do { let a =
2 print(a) } print(a) -
͡Ίʹ let a = 1 do { let a =
2 print(a) // 2 } print(a) // 1 -
͡Ίʹ let a = 1 do { let a =
2 print(a) } print(a) B B -
͡Ίʹ let a = 1 if let a = Optional(2)
{ print(a) } guard let a = Optional(3) else { print(a) return } print(a) -
͡Ίʹ let a = 1 if let a = Optional(2)
{ print(a) // 2 } guard let a = Optional(3) else { print(a) // 1 return } print(a) // 3 -
͡Ίʹ let a = 1 if let a = Optional(2)
{ print(a) } guard let a = Optional(3) else { print(a) return } print(a) B B B -
/BNF-PPLVQ w"45্Ͱ໊લࢀর͔ΒఆٛΛݕࡧ͢Δखଓ͖ let a = value let b = B.f()
let value = 1 struct B { static func f() } -
/BNF-PPLVQ let a = 1 do { let a =
2 print(a) } print(a) 2͔͜͜Βݟ͑ΔBͷఆٛͲΕʁ -
/BNF-PPLVQ let a = 1 do { let a =
2 print(a) } print(a) 2͔͜͜Βݟ͑ΔBͷఆٛͲΕʁ "͜Ε -
2VBMJGJFE-PPLVQʢΏΔ;Θઆ໌ʣ protocol A {} extension A { static var a:
Int { 1 } } class B { static let a = 2 } class C: B, A {} 2RVBMJ fi FS$ͷOBNFBΛ୳ͯ͠ -
2VBMJGJFE-PPLVQʢΏΔ;Θઆ໌ʣ protocol A {} extension A { static var a:
Int { 1 } } class B { static let a = 2 } class C: B, A {} 2RVBMJ fi FS$ͷOBNFBΛ୳ͯ͠ -
2VBMJGJFE-PPLVQʢΏΔ;Θઆ໌ʣ protocol A {} extension A { static var a:
Int { 1 } } class B { static let a = 2 } class C: B, A {} 2RVBMJ fi FS$ͷOBNFBΛ୳ͯ͠ -
-FYJDBM-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } -
-FYJDBM-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } 2ᶃͷҐஔ͔Βݟ͑ΔʮBʯͷఆٛͲΕͰ͔͢ʁ ᶃ -
-FYJDBM-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } 2ᶃͷҐஔ͔Βݟ͑ΔʮBʯͷఆٛͲΕͰ͔͢ʁ ᶃ "ᶄᶅͷҐஔͷ7BS%FDMͩΑ ᶄ ᶅ -
"454DPQFߏ swift -frontend -dump-scope-maps expanded Source.swift ASTSourceFileScope 0x738faf000, [1:1 -
13:1] 'Source.swift' `-AbstractFunctionDeclScope 0x738fe5ee0, [1:1 - 11:1] 'f()' `-FunctionBodyScope 0x738fe5ee0, [1:10 - 11:1] `-BraceStmtScope 0x73842a900, [1:10 - 11:1] `-PatternEntryDeclScope 0x73842a0f0, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope 0x73842a0f0, [2:13 - 2:13] entry 0 'a' |-IfStmtScope 0x73842a478, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] let a? |-ConditionalClauseInitializerScope, [3:16 - 3:26] `-BraceStmtScope 0x73842a450, [3:28 - 5:5] `-GuardStmtScope 0x73842a7e8, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] let a? |-ConditionalClauseInitializerScope, [6:19 - 6:29] `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope 0x73842a7b8, [6:36 - 9:5] func f() { let a = 1 if let a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } -
"454DPQFߏ ASTSourceFileScope 0x738faf000, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope 0x738fe5ee0, [1:1
- 11:1] 'f()' `-FunctionBodyScope 0x738fe5ee0, [1:10 - 11:1] `-BraceStmtScope 0x73842a900, [1:10 - 11:1] `-PatternEntryDeclScope 0x73842a0f0, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope 0x73842a0f0, [2:13 - 2:13] entry 0 'a' |-IfStmtScope 0x73842a478, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] let a? |-ConditionalClauseInitializerScope, [3:16 - 3:26] `-BraceStmtScope 0x73842a450, [3:28 - 5:5] `-GuardStmtScope 0x73842a7e8, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] let a? |-ConditionalClauseInitializerScope, [6:19 - 6:29] `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope 0x73842a7b8, [6:36 - 9:5] -
"454DPQFߏ ASTSourceFileScope 0x738faf000, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope 0x738fe5ee0, [1:1
- 11:1] 'f()' `-FunctionBodyScope 0x738fe5ee0, [1:10 - 11:1] `-BraceStmtScope 0x73842a900, [1:10 - 11:1] `-PatternEntryDeclScope 0x73842a0f0, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope 0x73842a0f0, [2:13 - 2:13] entry 0 'a' |-IfStmtScope 0x73842a478, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] let a? |-ConditionalClauseInitializerScope, [3:16 - 3:26] `-BraceStmtScope 0x73842a450, [3:28 - 5:5] `-GuardStmtScope 0x73842a7e8, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] let a? |-ConditionalClauseInitializerScope, [6:19 - 6:29] `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope 0x73842a7b8, [6:36 - 9:5] 4DPQFͷ໊લ -
"454DPQFߏ ASTSourceFileScope 0x738faf000, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope 0x738fe5ee0, [1:1
- 11:1] 'f()' `-FunctionBodyScope 0x738fe5ee0, [1:10 - 11:1] `-BraceStmtScope 0x73842a900, [1:10 - 11:1] `-PatternEntryDeclScope 0x73842a0f0, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope 0x73842a0f0, [2:13 - 2:13] entry 0 'a' |-IfStmtScope 0x73842a478, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] let a? |-ConditionalClauseInitializerScope, [3:16 - 3:26] `-BraceStmtScope 0x73842a450, [3:28 - 5:5] `-GuardStmtScope 0x73842a7e8, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] let a? |-ConditionalClauseInitializerScope, [6:19 - 6:29] `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope 0x73842a7b8, [6:36 - 9:5] ରԠ͢Δ"45ͷ/PEF -
"454DPQFߏ ASTSourceFileScope 0x738faf000, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope 0x738fe5ee0, [1:1
- 11:1] 'f()' `-FunctionBodyScope 0x738fe5ee0, [1:10 - 11:1] `-BraceStmtScope 0x73842a900, [1:10 - 11:1] `-PatternEntryDeclScope 0x73842a0f0, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope 0x73842a0f0, [2:13 - 2:13] entry 0 'a' |-IfStmtScope 0x73842a478, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] let a? |-ConditionalClauseInitializerScope, [3:16 - 3:26] `-BraceStmtScope 0x73842a450, [3:28 - 5:5] `-GuardStmtScope 0x73842a7e8, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] let a? |-ConditionalClauseInitializerScope, [6:19 - 6:29] `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope 0x73842a7b8, [6:36 - 9:5] 4DPQFͷ࡞༻ൣғ -
"454DPQFߏ ASTSourceFileScope 0x738faf000, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope 0x738fe5ee0, [1:1
- 11:1] 'f()' `-FunctionBodyScope 0x738fe5ee0, [1:10 - 11:1] `-BraceStmtScope 0x73842a900, [1:10 - 11:1] `-PatternEntryDeclScope 0x73842a0f0, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope 0x73842a0f0, [2:13 - 2:13] entry 0 'a' |-IfStmtScope 0x73842a478, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] let a? |-ConditionalClauseInitializerScope, [3:16 - 3:26] `-BraceStmtScope 0x73842a450, [3:28 - 5:5] `-GuardStmtScope 0x73842a7e8, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] let a? |-ConditionalClauseInitializerScope, [6:19 - 6:29] `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope 0x73842a7b8, [6:36 - 9:5] ͦͷଞิใ -
"454DPQFߏ ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1]
'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 'a' |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] let a? |-ConditionalClauseInitializerScope, [3:16 - 3:26] `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] let a? |-ConditionalClauseInitializerScope, [6:19 - 6:29] `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] -
"454DPQFߏ ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1]
'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] func f() { let a = 1 if let a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } -
"454DPQFߏ ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1]
'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] func f() { let a = 1 if let a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } -
"454DPQFߏ ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1]
'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] func f() { let a = 1 if let a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } -
"454DPQFߏ ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1]
'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] func f() { let a = 1 if let a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } *GMFUBMFUBͷࢠ -
"454DPQFߏ ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1]
'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] func f() { let a = 1 if let a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } *GMFUBͱHVBSEMFUBMFUBͷࢠ *GMFUBͱHVBSEMFUBܑఋ -
"454DPQF-PPLVQ static void unqualifiedLookup( SourceFile *sourceFile, const SourceLoc loc, DeclConsumer
consumer) "45ͷSPPU -PPLVQ͢Δॴ -
"454DPQF-PPLVQ static void unqualifiedLookup( SourceFile *sourceFile, const SourceLoc loc, DeclConsumer
consumer) "45ͷSPPU -PPLVQ͢Δॴ ܧଓఆͷڍಈΛૢ࡞͢Δܕ -
"454DPQF-PPLVQ static void unqualifiedLookup( SourceFile *sourceFile, const SourceLoc loc, DeclConsumer
consumer) "45ͷSPPU -PPLVQ͢Δॴ ܧଓఆͷڍಈΛૢ࡞͢Δܕ $POTVNFSʹ݁Ռ͕͞ΕΔ $POTVNFS͕ݕࡧ໊Λ࣋ͪɺܧଓఆʹར༻͢Δ class AbstractASTScopeDeclConsumer { virtual bool consume(ArrayRef<ValueDecl *> values, NullablePtr<DeclContext> baseDC = nullptr) -
"454DPQF-PPLVQ static void unqualifiedLookup( SourceFile *sourceFile, const SourceLoc loc, DeclConsumer
consumer) "45ͷSPPU -PPLVQ͢Δॴ ܧଓఆͷڍಈΛૢ࡞͢Δܕ static func unqualifiedLookup( sourceFile: SourceFile, at location: SourceLoc, filterBy name: DeclReference ) -> [LookupResult] -
"454DPQF-PPLVQ void ASTScopeImpl::unqualifiedLookup( SourceFile *sourceFile, const SourceLoc loc, DeclConsumer consumer)
{ const auto *start = findStartingScopeForLookup(sourceFile, loc); if (start) start->lookup(nullptr, nullptr, consumer); } -
"454DPQF-PPLVQ void ASTScopeImpl::unqualifiedLookup( SourceFile *sourceFile, const SourceLoc loc, DeclConsumer consumer)
{ const auto *start = findStartingScopeForLookup(sourceFile, loc); if (start) start->lookup(nullptr, nullptr, consumer); } MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ MPPLVQ -
"454DPQF-PPLVQ void ASTScopeImpl::unqualifiedLookup( SourceFile *sourceFile, const SourceLoc loc, DeclConsumer consumer)
{ const auto *start = findStartingScopeForLookup(sourceFile, loc); if (start) start->lookup(nullptr, nullptr, consumer); } MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ MPPLVQ -
"454DPQF-PPLVQ const ASTScopeImpl *ASTScopeImpl::findStartingScopeForLookup( SourceFile *sourceFile, const SourceLoc loc) {
auto *fileScope = sourceFile->getScope().impl; (লུ) return fileScope->findInnermostEnclosingScope(loc, nullptr); } MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ const ASTScopeImpl *ASTScopeImpl::findStartingScopeForLookup( SourceFile *sourceFile, const SourceLoc loc) {
auto *fileScope = sourceFile->getScope().impl; (লུ) return fileScope->findInnermostEnclosingScope(loc, nullptr); } MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ "45SPPU͔Β"454DPQFSPPUΛऔಘʢ࡞PSΩϟογϡʣ -
"454DPQF-PPLVQ const ASTScopeImpl *ASTScopeImpl::findStartingScopeForLookup( SourceFile *sourceFile, const SourceLoc loc) {
auto *fileScope = sourceFile->getScope().impl; (লུ) return fileScope->findInnermostEnclosingScope(loc, nullptr); } MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ ࠶ؼԼ߱ͰMPPLVQMPDBUJPOΛؚΉ࠷TDPQFΛ୳͢ "45SPPU͔Β"454DPQFSPPUΛऔಘʢ࡞PSΩϟογϡʣ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ ෳࢠ͕͋Δ߹ೋ୳ࡧ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ -
"454DPQF-PPLVQ void ASTScopeImpl::unqualifiedLookup( SourceFile *sourceFile, const SourceLoc loc, DeclConsumer consumer)
{ const auto *start = findStartingScopeForLookup(sourceFile, loc); if (start) start->lookup(nullptr, nullptr, consumer); } MPDBUJPO͕ଐ͢Δ*OOFSNPTUTDPQFͷಛఆ MPPLVQ MPPLVQ -
"454DPQF-PPLVQ MPPLVQ void ASTScopeImpl::lookup(const NullablePtr<const ASTScopeImpl> limit, NullablePtr<const GenericParamList> lastListSearched,
DeclConsumer consumer) const { (লུ) if (lookupLocalsOrMembers(consumer)) return; (লུ) const auto *const lookupParent = getLookupParent().getPtrOrNull(); return lookupParent->lookup(limitForParent, lastListSearched, consumer); } -
"454DPQF-PPLVQ MPPLVQ void ASTScopeImpl::lookup(const NullablePtr<const ASTScopeImpl> limit, NullablePtr<const GenericParamList> lastListSearched,
DeclConsumer consumer) const { (লུ) if (lookupLocalsOrMembers(consumer)) return; (লུ) const auto *const lookupParent = getLookupParent().getPtrOrNull(); return lookupParent->lookup(limitForParent, lastListSearched, consumer); } Λ࠶ؼతʹMPPLVQ -
"454DPQF-PPLVQ MPPLVQ void ASTScopeImpl::lookup(const NullablePtr<const ASTScopeImpl> limit, NullablePtr<const GenericParamList> lastListSearched,
DeclConsumer consumer) const { (লུ) if (lookupLocalsOrMembers(consumer)) return; (লུ) const auto *const lookupParent = getLookupParent().getPtrOrNull(); return lookupParent->lookup(limitForParent, lastListSearched, consumer); } ͜ͷؔΛ֤4DPQF۩ܕͰ࣮͢Δ -
"454DPQF-PPLVQ MPPLVQ1BUUFSO&OUSZ%FDM4DPQF bool PatternEntryDeclScope::lookupLocalsOrMembers(DeclConsumer consumer) const { if (!isLocalBinding) return
false; return lookupLocalBindingsInPattern(getPattern(), consumer); } bool ASTScopeImpl::lookupLocalBindingsInPattern(const Pattern *p, DeclConsumer consumer) { if (!p) return false; bool isDone = false; p->forEachVariable([&](VarDecl *var) { if (!isDone) { SmallVector<ValueDecl *, 2> vars = { var }; auto abiRole = ABIRoleInfo(var); if (!abiRole.providesABI()) vars.push_back(abiRole.getCounterpart()); isDone = consumer.consume(vars); } }); return isDone; } let a = 1 -
"454DPQF-PPLVQ MPPLVQ1BUUFSO&OUSZ%FDM4DPQF bool PatternEntryDeclScope::lookupLocalsOrMembers(DeclConsumer consumer) const { if (!isLocalBinding) return
false; return lookupLocalBindingsInPattern(getPattern(), consumer); } bool ASTScopeImpl::lookupLocalBindingsInPattern(const Pattern *p, DeclConsumer consumer) { if (!p) return false; bool isDone = false; p->forEachVariable([&](VarDecl *var) { if (!isDone) { isDone = consumer.consume({ vars }); } }); return isDone; } 4DPQFରԠ͢Δ"45/PEFΛอ࣋ɾใநग़ʹར༻ let a = 1 -
"454DPQF-PPLVQ MPPLVQ1BUUFSO&OUSZ%FDM4DPQF bool PatternEntryDeclScope::lookupLocalsOrMembers(DeclConsumer consumer) const { if (!isLocalBinding) return
false; return lookupLocalBindingsInPattern(getPattern(), consumer); } bool ASTScopeImpl::lookupLocalBindingsInPattern(const Pattern *p, DeclConsumer consumer) { if (!p) return false; bool isDone = false; p->forEachVariable([&](VarDecl *var) { if (!isDone) { isDone = consumer.consume({ vars }); } }); return isDone; } ϊʔυ͕࣋ͭ7BS%FDMΛશͯDPOTVNFSʹ͢ DPOTVNF͕USVFΛฦͤऴྃɺGBMTFଓߦ let a = 1 -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPPLVQ DPOTVNF B -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPPLVQ VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPPLVQ DPOTVNF B VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPPLVQ VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPPLVQ VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPPLVQ VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPPLVQ VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz -
"454DPQF-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] MPPLVQ VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz DPOTVNF B DPOTVNF B -
"454DPQFHVBSE ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1]
'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] func f() { let a = 1 if let a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } HVBSEͷCPEZ͕HVBSEMFUBͷࢠʜ -
"454DPQFHVBSE ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1]
'f()' `-FunctionBodyScope, [1:10 - 11:1] `-BraceStmtScope, [1:10 - 11:1] `-PatternEntryDeclScope, [2:9 - 11:1] entry 0 'a' |-PatternEntryInitializerScope, [2:13 - 2:13] entry 0 |-IfStmtScope, [3:5 - 5:5] `-ConditionalClausePatternUseScope, [3:16 - 5:5] le |-ConditionalClauseInitializerScope, [3:16 - 3:26 `-BraceStmtScope, [3:28 - 5:5] `-GuardStmtScope, [6:5 - 11:1] `-ConditionalClausePatternUseScope, [6:19 - 11:1] l |-ConditionalClauseInitializerScope, [6:19 - 6:29 `-GuardStmtBodyScope, [6:36 - 9:5] `-BraceStmtScope, [6:36 - 9:5] func f() { let a = 1 if let a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } HVBSEͷCPEZ͕HVBSEMFUBͷࢠʜ HVBSE͚ͩྫ֎తʹQBSFOUͱMPPLVQ1BSFOU͕ҟͳΔ -
"454DPQFHVBSE /// The tree is organized by source location and
for most nodes this is also /// what obtains for scoping. However, guards are different. The scope after /// the guard else must hop into the innermoset scope of the guard condition. virtual NullablePtr<const ASTScopeImpl> getLookupParent() const -
"454DPQFTPVSDFSBOHFͷ੍ //===----------------------------------------------------------------------===// /// /// This fi le de fi nes
the ASTScopeImpl class ontology, which /// describes the scopes that exist within a Swift AST. /// /// Each scope has four basic functions: printing for debugging, creation of /// itself and its children, obtaining its SourceRange (for lookup), and looking /// up names accessible from that scope. /// /// Invariants: /// a child's source range is a subset (proper or improper) of its parent's, /// children are ordered by source range, and do not overlap, /// all the names visible within a parent are visible within the child, unless /// the nesting is illegal. For instance, a protocol nested inside of a class /// does not get to see the symbols in the class or its ancestors. /// //===----------------------------------------------------------------------===// -
"454DPQFTPVSDFSBOHFͷ੍ //===----------------------------------------------------------------------===// /// /// This fi le de fi nes
the ASTScopeImpl class ontology, which /// describes the scopes that exist within a Swift AST. /// /// Each scope has four basic functions: printing for debugging, creation of /// itself and its children, obtaining its SourceRange (for lookup), and looking /// up names accessible from that scope. /// /// Invariants: /// a child's source range is a subset (proper or improper) of its parent's, /// children are ordered by source range, and do not overlap, /// all the names visible within a parent are visible within the child, unless /// the nesting is illegal. For instance, a protocol nested inside of a class /// does not get to see the symbols in the class or its ancestors. /// //===----------------------------------------------------------------------===// MJC"45"454DPQFI -
"454DPQFTPVSDFSBOHFͷ੍ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } `-GuardStmtScope, [6:5 - 11:1] ɹ`-ConditionalClausePatternUseScope, [6:19 - 11:1] let ɹɹ|-ConditionalClauseInitializerScope, [6:19 - 6:29] ɹɹ`-GuardStmtBodyScope, [6:36 - 9:5] ɹɹɹ`-BraceStmtScope, [6:36 - 9:5] -
"454DPQFTPVSDFSBOHFͷ੍ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } `-GuardStmtScope, [6:5 - 11:1] ɹ|-ConditionalClausePatternUseScope, [6:19 - 11:1] let ɹɹ`-ConditionalClauseInitializerScope, [6:19 - 6:29] ɹ`-GuardStmtBodyScope, [6:36 - 9:5] ɹɹ`-BraceStmtScope, [6:36 - 9:5] -
"454DPQFTPVSDFSBOHFͷ੍ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } `-GuardStmtScope, [6:5 - 11:1] ɹ|-ConditionalClausePatternUseScope, [6:19 - 11:1] let ɹɹ`-ConditionalClauseInitializerScope, [6:19 - 6:29] ɹ`-GuardStmtBodyScope, [6:36 - 9:5] ɹɹ`-BraceStmtScope, [6:36 - 9:5] -
"454DPQF-B[JMZ&YQBOTJPO func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' -
"454DPQF-B[JMZ&YQBOTJPO func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' FYQBOE -
"454DPQF-B[JMZ&YQBOTJPO func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] -
"454DPQF-B[JMZ&YQBOTJPO func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] ಛఆͷ/PEFͰల։͕ࢭ·Δʢ%FGFSSFE/PEFʣ -
"454DPQF-B[JMZ&YQBOTJPO func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } VORVBMJ fi FE-PPLVQ BU<> fi MUFS#ZlBz ASTSourceFileScope, [1:1 - 13:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 11:1] 'f()' `-FunctionBodyScope, [1:10 - 11:1] -
"454DPQF-B[JMZ&YQBOTJPO struct A { func a() { let a =
1 } func b() { let a = 1 } func c() { let a = 1 } } ASTSourceFileScope 0xb3ef67000, [1:1 - 14:1] 'Source.swift' `-NominalTypeDeclScope 0xb3ef79eb0, [1:1 - 13:1] 'A' `-NominalTypeBodyScope 0xb3ef79eb0, [1:10 - 13:1] 'A' |-AbstractFunctionDeclScope 0xb3ef8a020, [2:5 - 4:5] 'a()' `-FunctionBodyScope 0xb3ef8a020, [2:14 - 4:5] `-BraceStmtScope 0xb3ef8a268, [2:14 - 4:5] `-PatternEntryDeclScope 0xb3ef8a1f0, [3:13 - 4:5] entry `-PatternEntryInitializerScope 0xb3ef8a1f0, [3:17 - 3: |-AbstractFunctionDeclScope 0xb3ef8a300, [6:5 - 8:5] 'b()' `-FunctionBodyScope 0xb3ef8a300, [6:14 - 8:5] `-BraceStmtScope 0xb3ef8a548, [6:14 - 8:5] `-PatternEntryDeclScope 0xb3ef8a4d0, [7:13 - 8:5] entry `-PatternEntryInitializerScope 0xb3ef8a4d0, [7:17 - 7: `-AbstractFunctionDeclScope 0xb3ef8a5e0, [10:5 - 12:5] 'c()' `-FunctionBodyScope 0xb3ef8a5e0, [10:14 - 12:5] `-BraceStmtScope 0xb3ef8a828, [10:14 - 12:5] `-PatternEntryDeclScope 0xb3ef8a7b0, [11:13 - 12:5] entr `-PatternEntryInitializerScope 0xb3ef8a7b0, [11:17 - 1 -
4XJGU-FYJDBM-PPLVQҐஔ͚ wTXJGUTZOUBYʹಉ෧ w!@TQJ &YQFSJNFOUBM JNQPSU4XJGU-FYJDBM-PPLVQ w(4P$Ͱ։ൃ wকདྷతʹ"454DPQFΛஔ͖͍͑ͨΒ͍͠ w4XJGUίϯύΠϥʹόϦσʔγϣϯ͕࣮ࡁΈ w TXJGUFOBCMFFYQFSJNFOUBMGFBUVSF6ORVBMJ
fi FE-PPLVQ7BMJEBUJPO4PVSDFTXJGU IUUQTGPSVNTTXJGUPSHUHTPDTXJGUMFYJDBMMPPLVQBOFXMFYJDBMOBNFMPPLVQMJCSBSZ -
4XJGU-FYJDBM-PPLVQ @_spi(Experimental) public protocol ScopeSyntax: SyntaxProtocol {…} @_spi(Experimental) extension IfExprSyntax:
ScopeSyntax { … } @_spi(Experimental) extension WhileStmtSyntax: ScopeSyntax { … } … -
4XJGU-FYJDBM-PPLVQߏ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } -
4XJGU-FYJDBM-PPLVQߏ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } -
4XJGU-FYJDBM-PPLVQߏ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } ߏจͱείʔϓͷߏ͕ಉҰͳͷͰਓؒʹ༏͍͠ -
4XJGU-FYJDBM-PPLVQ MPPLVQQPTJUJPOͰಈతʹఆٛͷՄࢹੑΛ੍ޚ if let a = Optional(2) { // a͕ݟ͑Δ
} else { // a͕ݟ͑ͳ͍ } *O"454DPQF -
4XJGU-FYJDBM-PPLVQ if let a = Optional(2) { // a͕ݟ͑Δ }
else { // a͕ݟ͑ͳ͍ } ASTSourceFileScope, [1:1 - 11:1] 'Source.swift' `-AbstractFunctionDeclScope, [1:1 - 10:1] 'f()' `-FunctionBodyScope, [1:10 - 10:1] `-BraceStmtScope, [1:10 - 10:1] `-IfStmtScope, [2:5 - 9:5] |-ConditionalClausePatternUseScope, [2:16 - 5: |-ConditionalClauseInitializerScope, [2:16 - `-BraceStmtScope, [2:28 - 5:5] `-BraceStmtScope, [6:10 - 9:5] ߏʹΑͬͯՄࢹੑΛ੍ޚ *O"454DPQF MPPLVQQPTJUJPOͰಈతʹఆٛͷՄࢹੑΛ੍ޚ -
4XJGU-FYJDBM-PPLVQ if let a = Optional(2) { // a͕ݟ͑Δ }
else { // a͕ݟ͑ͳ͍ } *O4XJGU-FYJDBM-PPLVQ MPPLVQQPTJUJPOͰಈతʹఆٛͷՄࢹੑΛ੍ޚ -
4XJGU-FYJDBM-PPLVQ @_spi(Experimental) extension IfExprSyntax: ScopeSyntax { @_spi(Experimental) public func lookup(
_ identifier: Identifier?, at lookUpPosition: AbsolutePosition, with config: LookupConfig ) -> [LookupResult] { if let elseBody, elseBody.range.contains(lookUpPosition) { return lookupInParent(identifier, at: lookUpPosition, with: config) } else { return defaultLookupImplementation(identifier, at: lookUpPosition, with: config) } } MPPLVQQPTJUJPOͰಈతʹఆٛͷՄࢹੑΛ੍ޚ -
4XJGU-FYJDBM-PPLVQ @_spi(Experimental) extension IfExprSyntax: ScopeSyntax { @_spi(Experimental) public func lookup(
_ identifier: Identifier?, at lookUpPosition: AbsolutePosition, with config: LookupConfig ) -> [LookupResult] { if let elseBody, elseBody.range.contains(lookUpPosition) { return lookupInParent(identifier, at: lookUpPosition, with: config) } else { return defaultLookupImplementation(identifier, at: lookUpPosition, with: config) } } MPPLVQQPTJUJPOͰಈతʹఆٛͷՄࢹੑΛ੍ޚ FMTFCPEZ͔ΒͷMPPLVQJGMFUΛݟͤͳ͍ -
4XJGU-FYJDBM-PPLVQ-PPLVQ @_spi(Experimental) public protocol ScopeSyntax: SyntaxProtocol { func lookup( _
identifier: Identifier?, at lookUpPosition: AbsolutePosition, with config: LookupConfig ) -> [LookupResult] } -
4XJGU-FYJDBM-PPLVQ-PPLVQ extension SyntaxProtocol { /// Parent scope of this syntax
node, or scope introduced by this syntax node. var scope: ScopeSyntax? { if let scopeSyntax = Syntax(self).asProtocol(SyntaxProtocol.self) as? ScopeSyntax { return scopeSyntax } else { return self.parent?.scope } } public func lookup( _ identifier: Identifier?, with config: LookupConfig = LookupConfig() ) -> [LookupResult] { scope?.lookup(identifier, at: self.position, with: config) ?? [] } } -
4XJGU-FYJDBM-PPLVQ-PPLVQ func f() { let a = 1 if let
a = Optional(2) { print(a) } guard let a = Optional(3) else { print(a) return } print(a) } TPVSDFUPLFO BU<> MPPLVQ lBz -
w$PEF#MPDLͷఆٛ$PEF#MPDL4DPQF͕ཧ 4XJGU-FYJDBM-PPLVQ-PPLVQ @_spi(Experimental) extension CodeBlockSyntax: SequentialScopeSyntax { @_spi(Experimental) public func
lookup( _ identifier: Identifier?, at lookUpPosition: AbsolutePosition, with config: LookupConfig ) -> [LookupResult] { sequentialLookup( in: statements, identifier, at: lookUpPosition, with: config ) } } -
4XJGU-FYJDBM-PPLVQ-PPLVQ func sequentialLookup(…) -> [LookupResult] { var collectedNamedDecls: [NamedDeclSyntax] =
[] for codeBlockItem in codeBlockItems.reversed() { if let namedDecl = codeBlockItem.item.asProtocol(NamedDeclSyntax.self) { guard !ignoreNamedDecl else { continue } collectedNamedDecls.append(namedDecl) continue } } for namedDecl in collectedNamedDecls.reversed() { currentChunk += LookupName.getNames( from: namedDecl, accessibleAfter: namedDecl.endPosition ).filter { introducedName in checkIdentifier(identifier, refersTo: introducedName, at: lookUpPosition) } } … } -
4XJGU-FYJDBM-PPLVQ-PPLVQ func sequentialLookup(…) -> [LookupResult] { var collectedNamedDecls: [NamedDeclSyntax] =
[] for codeBlockItem in codeBlockItems.reversed() { if let namedDecl = codeBlockItem.item.asProtocol(NamedDeclSyntax.self) { guard !ignoreNamedDecl else { continue } collectedNamedDecls.append(namedDecl) continue } } for namedDecl in collectedNamedDecls.reversed() { currentChunk += LookupName.getNames( from: namedDecl, accessibleAfter: namedDecl.endPosition ).filter { introducedName in checkIdentifier(identifier, refersTo: introducedName, at: lookUpPosition) } } … } $PEF#MPDLͷEFDMΛר͖औΔ -
4XJGU-FYJDBM-PPLVQ-PPLVQ func sequentialLookup(…) -> [LookupResult] { var collectedNamedDecls: [NamedDeclSyntax] =
[] for codeBlockItem in codeBlockItems.reversed() { if let namedDecl = codeBlockItem.item.asProtocol(NamedDeclSyntax.self) { guard !ignoreNamedDecl else { continue } collectedNamedDecls.append(namedDecl) continue } } for namedDecl in collectedNamedDecls.reversed() { currentChunk += LookupName.getNames( from: namedDecl, accessibleAfter: namedDecl.endPosition ).filter { introducedName in checkIdentifier(identifier, refersTo: introducedName, at: lookUpPosition) } } … } ABDDFTTJCMF"GUFSAͰՄࢹੑใΛ༩ ʮ͜ͷQPTJUJPOΑΓޙͰݟ͑Δʯ -
4XJGU-FYJDBM-PPLVQBDDFTTJCMF"GUFS let a = 1 if let a = Optional(2)
{ print(a) } guard let a = Optional(3) else { print(a) return } print(a) B B B -
4XJGU-FYJDBM-PPLVQBDDFTTJCMF"GUFS let a = 1 if let a = Optional(2)
{ print(a) } guard let a = Optional(3) else { print(a) return } print(a) B B B -
4XJGU-FYJDBM-PPLVQ-PPLVQ func sequentialLookup(…) -> [LookupResult] { var collectedNamedDecls: [NamedDeclSyntax] =
[] for codeBlockItem in codeBlockItems.reversed() { if let namedDecl = codeBlockItem.item.asProtocol(NamedDeclSyntax.self) { guard !ignoreNamedDecl else { continue } collectedNamedDecls.append(namedDecl) continue } } for namedDecl in collectedNamedDecls.reversed() { currentChunk += LookupName.getNames( from: namedDecl, accessibleAfter: namedDecl.endPosition ).filter { introducedName in checkIdentifier(identifier, refersTo: introducedName, at: lookUpPosition) } } … } BDDFTTJCMF"GUFSMPPLVQQPTJUJPO͚ͩϑΟϧλ -
͓·͚2VBMJGJFE-PPLVQ /// Represents result from a speci fi c scope.
public enum LookupResult { /// Scope and the names that matched lookup. case fromScope(Syntax, withNames: [LookupName]) /// Indicates where to perform member lookup. case lookForMembers(in: Syntax) /// Indicates to lookup generic parameters of extended type. /// /// ### Example /// ```swift /// extension Foo { /// func bar() { /// let a = A() // <-- lookup here /// } /// } /// ``` case lookForGenericParameters(of: ExtensionDeclSyntax) /// Indicates this closure expression could introduce dollar identi fi ers. /// /// ### Example /// ```swift /// func foo() { /// let a = { /// $0 // <-- lookup here /// } /// } /// ``` case lookForImplicitClosureParameters(ClosureExprSyntax) -
͓·͚4XJGU2VBMJGJFE-PPLVQ // In SwiftLexicalLookup result processing for result in someNode.lookup("area",
with: config) { switch result { case .lookInMembers(let typeSyntax): // Hand off to qualified lookup let memberResults = typeSyntax.qualifiedLookup("area", in: sourceFile) // ... process memberResults default: // ... process unqualified results } } -
ग़య w "454DPQF w IUUQTHJUIVCDPNTXJGUMBOHTXJGUUSFFNBJOMJC"45 w 4XJGU-FYJDBM-PPLVQ w IUUQTHJUIVCDPNTXJGUMBOHTXJGUTZOUBYUSFFNBJO4PVSDFT4XJGU-FYJDBM-PPLVQ w
<(4P$>4XJGU-FYJDBM-PPLVQBOFXMFYJDBMOBNFMPPLVQMJCSBSZ w IUUQTGPSVNTTXJGUPSHUHTPDTXJGUMFYJDBMMPPLVQBOFXMFYJDBMOBNFMPPLVQMJCSBSZ w <(4P$>2VBMJ fi FE/BNF-PPLVQGPSTXJGUTZOUBY w IUUQTGPSVNTTXJGUPSHUHTPDRVBMJ fi FEOBNFMPPLVQGPSTXJGUTZOUBY