Skip to content

Commit d6ced16

Browse files
committed
Swift: declaration visitor
This transfers the current state of `DeclVisitor` from the proof-of-concept. TODO: make the `declarations` tests in `extractor-tests` more comprehensive.
1 parent da7e700 commit d6ced16

29 files changed

+789
-43
lines changed

swift/codegen/schema.yml

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Type: {}
3232
# diagnostics_name: string
3333
# canonical_type: Type
3434

35-
IterableDeclContext: {}
36-
# members: Decl*
35+
IterableDeclContext:
36+
members: Decl*
3737

3838
ExtensionDecl:
3939
_extends:
@@ -45,7 +45,7 @@ NominalTypeDecl:
4545
_extends:
4646
- IterableDeclContext
4747
- GenericTypeDecl
48-
# type: Type
48+
type: Type
4949

5050
AstNode:
5151
_extends: Locatable
@@ -240,7 +240,7 @@ TypeAliasType:
240240

241241
EnumCaseDecl:
242242
_extends: Decl
243-
# elements: EnumElementDecl*
243+
elements: EnumElementDecl*
244244

245245
IfConfigDecl:
246246
_extends: Decl
@@ -253,11 +253,12 @@ MissingMemberDecl:
253253

254254
OperatorDecl:
255255
_extends: Decl
256+
name: string
256257

257258
PatternBindingDecl:
258259
_extends: Decl
259-
# inits: Expr?*
260-
# patterns: Pattern*
260+
inits: Expr?*
261+
patterns: Pattern*
261262

262263
PoundDiagnosticDecl:
263264
_extends: Decl
@@ -267,11 +268,11 @@ PrecedenceGroupDecl:
267268

268269
TopLevelCodeDecl:
269270
_extends: Decl
270-
# body: BraceStmt
271+
body: BraceStmt
271272

272273
ValueDecl:
273274
_extends: Decl
274-
# interface_type: Type
275+
interface_type: Type
275276

276277
AbstractClosureExpr:
277278
_extends: Expr
@@ -623,6 +624,7 @@ UnarySyntaxSugarType:
623624

624625
InfixOperatorDecl:
625626
_extends: OperatorDecl
627+
precedence_group: PrecedenceGroupDecl?
626628

627629
PostfixOperatorDecl:
628630
_extends: OperatorDecl
@@ -634,21 +636,22 @@ AbstractFunctionDecl:
634636
_extends:
635637
- GenericContext
636638
- ValueDecl
637-
# name: string
638-
# body: BraceStmt?
639-
# params: ParamDecl*
639+
name: string
640+
body: BraceStmt?
641+
params: ParamDecl*
640642

641643
AbstractStorageDecl:
642644
_extends: ValueDecl
643645

644646
EnumElementDecl:
645647
_extends: ValueDecl
646-
# name: string
647-
# params: ParamDecl*
648+
name: string
649+
params: ParamDecl*
648650

649651
TypeDecl:
650652
_extends: ValueDecl
651-
# name: string
653+
name: string
654+
base_types: Type*
652655

653656
AutoClosureExpr:
654657
_extends: AbstractClosureExpr
@@ -918,14 +921,17 @@ SubscriptDecl:
918921

919922
VarDecl:
920923
_extends: AbstractStorageDecl
921-
# name: string
922-
# type: Type
924+
name: string
925+
type: Type
926+
attached_property_wrapper_type: Type?
927+
parent_pattern: Pattern?
928+
parent_initializer: Expr?
923929

924930
AbstractTypeParamDecl:
925931
_extends: TypeDecl
926932

927-
GenericContext: {}
928-
# generic_type_params: GenericTypeParamDecl*
933+
GenericContext:
934+
generic_type_params: GenericTypeParamDecl*
929935

930936
GenericTypeDecl:
931937
_extends:
@@ -992,7 +998,7 @@ ConcreteFuncDecl:
992998

993999
ConcreteVarDecl:
9941000
_extends: VarDecl
995-
# introducer_int: int
1001+
introducer_int: int
9961002

9971003
ParamDecl:
9981004
_extends: VarDecl

swift/extractor/SwiftDispatcher.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ class SwiftDispatcher {
3838
emit(ElementIsUnknownTrap{label});
3939
}
4040

41-
private:
42-
// types to be supported by assignNewLabel/fetchLabel need to be listed here
43-
using Store = TrapLabelStore<swift::Decl,
44-
swift::Stmt,
45-
swift::Expr,
46-
swift::Pattern,
47-
swift::TypeRepr,
48-
swift::TypeBase>;
49-
5041
// This method gives a TRAP label for already emitted AST node.
5142
// If the AST node was not emitted yet, then the emission is dispatched to a corresponding
5243
// visitor (see `visit(T *)` methods below).
@@ -72,6 +63,10 @@ class SwiftDispatcher {
7263
return {};
7364
}
7465

66+
// convenience `fetchLabel` overload for `swift::Type` (which is just a wrapper for
67+
// `swift::TypeBase*`)
68+
TrapLabel<TypeTag> fetchLabel(swift::Type t) { return fetchLabel(t.getPointer()); }
69+
7570
// Due to the lazy emission approach, we must assign a label to a corresponding AST node before
7671
// it actually gets emitted to handle recursive cases such as recursive calls, or recursive type
7772
// declarations
@@ -118,6 +113,15 @@ class SwiftDispatcher {
118113
trap.emit(LocatablesTrap{locatableLabel, locLabel});
119114
}
120115

116+
private:
117+
// types to be supported by assignNewLabel/fetchLabel need to be listed here
118+
using Store = TrapLabelStore<swift::Decl,
119+
swift::Stmt,
120+
swift::Expr,
121+
swift::Pattern,
122+
swift::TypeRepr,
123+
swift::TypeBase>;
124+
121125
std::string getFilepath(swift::SourceLoc loc) {
122126
// TODO: this needs more testing
123127
// TODO: check canonicaliztion of names on a case insensitive filesystems

0 commit comments

Comments
 (0)