File tree Expand file tree Collapse file tree 3 files changed +75
-0
lines changed Expand file tree Collapse file tree 3 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ class CompileTimeValue {
36
36
Array,
37
37
Tuple,
38
38
Enum,
39
+ Type,
39
40
Runtime
40
41
};
41
42
@@ -183,6 +184,21 @@ class EnumValue : public CompileTimeValue {
183
184
llvm::Optional<std::vector<FunctionParameter>> Parameters;
184
185
};
185
186
187
+ // / An type value representation
188
+ class TypeValue : public CompileTimeValue {
189
+ public:
190
+ TypeValue (swift::Type Type) : CompileTimeValue(ValueKind::Type), Type(Type) {}
191
+
192
+ swift::Type getType () const { return Type; }
193
+
194
+ static bool classof (const CompileTimeValue *T) {
195
+ return T->getKind () == ValueKind::Type;
196
+ }
197
+
198
+ private:
199
+ swift::Type Type;
200
+ };
201
+
186
202
// / A representation of an arbitrary value that does not fall under
187
203
// / any of the above categories.
188
204
class RuntimeValue : public CompileTimeValue {
Original file line number Diff line number Diff line change @@ -299,6 +299,11 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
299
299
return extractCompileTimeValue (coerceExpr->getSubExpr ());
300
300
}
301
301
302
+ case ExprKind::DotSelf: {
303
+ auto dotSelfExpr = cast<DotSelfExpr>(expr);
304
+ return std::make_shared<TypeValue>(dotSelfExpr->getType ());
305
+ }
306
+
302
307
default : {
303
308
break ;
304
309
}
@@ -586,6 +591,16 @@ void writeValue(llvm::json::OStream &JSON,
586
591
break ;
587
592
}
588
593
594
+ case CompileTimeValue::ValueKind::Type: {
595
+ auto typeValue = cast<TypeValue>(value);
596
+ JSON.attribute (" valueKind" , " Type" );
597
+ JSON.attributeObject (" value" , [&]() {
598
+ JSON.attribute (" type" ,
599
+ toFullyQualifiedTypeNameString (typeValue->getType ()));
600
+ });
601
+ break ;
602
+ }
603
+
589
604
case CompileTimeValue::ValueKind::Runtime: {
590
605
JSON.attribute (" valueKind" , " Runtime" );
591
606
break ;
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: echo "[MyProto]" > %t/protocols.json
3
+
4
+ // RUN: %target-swift-frontend -typecheck -emit-const-values-path %t/ExtractTypes.swiftconstvalues -const-gather-protocols-file %t/protocols.json -primary-file %s
5
+ // RUN: cat %t/ExtractTypes.swiftconstvalues 2>&1 | %FileCheck %s
6
+
7
+ protocol MyProto { }
8
+ protocol ContainerType { }
9
+
10
+ struct TypeA : ContainerType { }
11
+ enum TypeB : ContainerType { }
12
+ final class TypeC : ContainerType { }
13
+
14
+ public struct Types : MyProto {
15
+ static var types1 : [ ContainerType . Type ] = [
16
+ TypeA . self,
17
+ TypeB . self,
18
+ TypeC . self
19
+ ]
20
+ }
21
+
22
+ // CHECK: "label": "types1",
23
+ // CHECK-NEXT: "type": "Swift.Array<ExtractTypes.ContainerType.Type>",
24
+ // CHECK: "valueKind": "Array",
25
+ // CHECK-NEXT: "value": [
26
+ // CHECK-NEXT: {
27
+ // CHECK-NEXT: "valueKind": "Type",
28
+ // CHECK-NEXT: "value": {
29
+ // CHECK-NEXT: "type": "ExtractTypes.TypeA.Type"
30
+ // CHECK-NEXT: }
31
+ // CHECK-NEXT: },
32
+ // CHECK-NEXT: {
33
+ // CHECK-NEXT: "valueKind": "Type",
34
+ // CHECK-NEXT: "value": {
35
+ // CHECK-NEXT: "type": "ExtractTypes.TypeB.Type"
36
+ // CHECK-NEXT: }
37
+ // CHECK-NEXT: },
38
+ // CHECK-NEXT: {
39
+ // CHECK-NEXT: "valueKind": "Type",
40
+ // CHECK-NEXT: "value": {
41
+ // CHECK-NEXT: "type": "ExtractTypes.TypeC.Type"
42
+ // CHECK-NEXT: }
43
+ // CHECK-NEXT: }
44
+ // CHECK-NEXT: ]
You can’t perform that action at this time.
0 commit comments