|
2 | 2 |
|
3 | 3 | namespace codeql { |
4 | 4 |
|
5 | | -void PatternVisitor::visitNamedPattern(swift::NamedPattern* pattern) { |
6 | | - auto label = dispatcher_.assignNewLabel(pattern); |
| 5 | +codeql::NamedPattern PatternVisitor::translateNamedPattern(const swift::NamedPattern& pattern) { |
| 6 | + auto entry = dispatcher_.createEntry(pattern); |
7 | 7 | // TODO: in some (but not all) cases, this seems to introduce a duplicate entry |
8 | 8 | // for example the vars listed in a case stmt have a different pointer than then ones in |
9 | 9 | // patterns. |
10 | | - // assert(pattern->getDecl() && "expect NamedPattern to have Decl"); |
11 | | - // dispatcher_.emit(NamedPatternsTrap{label, pattern->getNameStr().str(), |
12 | | - // dispatcher_.fetchLabel(pattern->getDecl())}); |
13 | | - dispatcher_.emit(NamedPatternsTrap{label, pattern->getNameStr().str()}); |
| 10 | + // assert(pattern.getDecl() && "expect NamedPattern to have Decl"); |
| 11 | + // dispatcher_.emit(NamedPatternsTrap{label, pattern.getNameStr().str(), |
| 12 | + // dispatcher_.fetchLabel(pattern.getDecl())}); |
| 13 | + entry.name = pattern.getNameStr().str(); |
| 14 | + return entry; |
14 | 15 | } |
15 | 16 |
|
16 | | -void PatternVisitor::visitTypedPattern(swift::TypedPattern* pattern) { |
17 | | - auto label = dispatcher_.assignNewLabel(pattern); |
18 | | - assert(pattern->getSubPattern() && "expect TypedPattern to have a SubPattern"); |
19 | | - dispatcher_.emit(TypedPatternsTrap{label, dispatcher_.fetchLabel(pattern->getSubPattern())}); |
20 | | - if (auto typeRepr = pattern->getTypeRepr()) { |
21 | | - dispatcher_.emit(TypedPatternTypeReprsTrap{ |
22 | | - label, dispatcher_.fetchLabel(pattern->getTypeRepr(), pattern->getType())}); |
23 | | - } |
| 17 | +codeql::TypedPattern PatternVisitor::translateTypedPattern(const swift::TypedPattern& pattern) { |
| 18 | + auto entry = dispatcher_.createEntry(pattern); |
| 19 | + entry.sub_pattern = dispatcher_.fetchLabel(pattern.getSubPattern()); |
| 20 | + entry.type_repr = dispatcher_.fetchOptionalLabel(pattern.getTypeRepr(), pattern.getType()); |
| 21 | + return entry; |
24 | 22 | } |
25 | 23 |
|
26 | | -void PatternVisitor::visitTuplePattern(swift::TuplePattern* pattern) { |
27 | | - auto label = dispatcher_.assignNewLabel(pattern); |
28 | | - dispatcher_.emit(TuplePatternsTrap{label}); |
29 | | - auto i = 0u; |
30 | | - for (auto p : pattern->getElements()) { |
31 | | - dispatcher_.emit(TuplePatternElementsTrap{label, i++, dispatcher_.fetchLabel(p.getPattern())}); |
| 24 | +codeql::TuplePattern PatternVisitor::translateTuplePattern(const swift::TuplePattern& pattern) { |
| 25 | + auto entry = dispatcher_.createEntry(pattern); |
| 26 | + for (const auto& p : pattern.getElements()) { |
| 27 | + entry.elements.push_back(dispatcher_.fetchLabel(p.getPattern())); |
32 | 28 | } |
| 29 | + return entry; |
33 | 30 | } |
34 | | -void PatternVisitor::visitAnyPattern(swift::AnyPattern* pattern) { |
35 | | - dispatcher_.emit(AnyPatternsTrap{dispatcher_.assignNewLabel(pattern)}); |
| 31 | +codeql::AnyPattern PatternVisitor::translateAnyPattern(const swift::AnyPattern& pattern) { |
| 32 | + auto entry = dispatcher_.createEntry(pattern); |
| 33 | + return entry; |
36 | 34 | } |
37 | 35 |
|
38 | | -void PatternVisitor::visitBindingPattern(swift::BindingPattern* pattern) { |
39 | | - auto label = dispatcher_.assignNewLabel(pattern); |
40 | | - assert(pattern->getSubPattern() && "expect BindingPattern to have a SubPattern"); |
41 | | - dispatcher_.emit(BindingPatternsTrap{label, dispatcher_.fetchLabel(pattern->getSubPattern())}); |
| 36 | +codeql::BindingPattern PatternVisitor::translateBindingPattern( |
| 37 | + const swift::BindingPattern& pattern) { |
| 38 | + auto entry = dispatcher_.createEntry(pattern); |
| 39 | + entry.sub_pattern = dispatcher_.fetchLabel(pattern.getSubPattern()); |
| 40 | + return entry; |
42 | 41 | } |
43 | 42 |
|
44 | | -void PatternVisitor::visitEnumElementPattern(swift::EnumElementPattern* pattern) { |
45 | | - auto label = dispatcher_.assignNewLabel(pattern); |
46 | | - dispatcher_.emit( |
47 | | - EnumElementPatternsTrap{label, dispatcher_.fetchLabel(pattern->getElementDecl())}); |
48 | | - if (auto subPattern = pattern->getSubPattern()) { |
49 | | - dispatcher_.emit( |
50 | | - EnumElementPatternSubPatternsTrap{label, dispatcher_.fetchLabel(pattern->getSubPattern())}); |
51 | | - } |
| 43 | +codeql::EnumElementPattern PatternVisitor::translateEnumElementPattern( |
| 44 | + const swift::EnumElementPattern& pattern) { |
| 45 | + auto entry = dispatcher_.createEntry(pattern); |
| 46 | + entry.element = dispatcher_.fetchLabel(pattern.getElementDecl()); |
| 47 | + entry.sub_pattern = dispatcher_.fetchOptionalLabel(pattern.getSubPattern()); |
| 48 | + return entry; |
52 | 49 | } |
53 | 50 |
|
54 | | -void PatternVisitor::visitOptionalSomePattern(swift::OptionalSomePattern* pattern) { |
55 | | - auto label = dispatcher_.assignNewLabel(pattern); |
56 | | - assert(pattern->getSubPattern() && "expect BindingPattern to have a SubPattern"); |
57 | | - dispatcher_.emit( |
58 | | - OptionalSomePatternsTrap{label, dispatcher_.fetchLabel(pattern->getSubPattern())}); |
| 51 | +codeql::OptionalSomePattern PatternVisitor::translateOptionalSomePattern( |
| 52 | + const swift::OptionalSomePattern& pattern) { |
| 53 | + auto entry = dispatcher_.createEntry(pattern); |
| 54 | + entry.sub_pattern = dispatcher_.fetchLabel(pattern.getSubPattern()); |
| 55 | + return entry; |
59 | 56 | } |
60 | 57 |
|
61 | | -void PatternVisitor::visitIsPattern(swift::IsPattern* pattern) { |
62 | | - auto label = dispatcher_.assignNewLabel(pattern); |
63 | | - dispatcher_.emit(IsPatternsTrap{label}); |
64 | | - |
65 | | - if (auto typeRepr = pattern->getCastTypeRepr()) { |
66 | | - dispatcher_.emit(IsPatternCastTypeReprsTrap{ |
67 | | - label, dispatcher_.fetchLabel(typeRepr, pattern->getCastType())}); |
68 | | - } |
69 | | - if (auto subPattern = pattern->getSubPattern()) { |
70 | | - dispatcher_.emit(IsPatternSubPatternsTrap{label, dispatcher_.fetchLabel(subPattern)}); |
71 | | - } |
| 58 | +codeql::IsPattern PatternVisitor::translateIsPattern(const swift::IsPattern& pattern) { |
| 59 | + auto entry = dispatcher_.createEntry(pattern); |
| 60 | + entry.cast_type_repr = |
| 61 | + dispatcher_.fetchOptionalLabel(pattern.getCastTypeRepr(), pattern.getCastType()); |
| 62 | + entry.sub_pattern = dispatcher_.fetchOptionalLabel(pattern.getSubPattern()); |
| 63 | + return entry; |
72 | 64 | } |
73 | 65 |
|
74 | | -void PatternVisitor::visitExprPattern(swift::ExprPattern* pattern) { |
75 | | - auto label = dispatcher_.assignNewLabel(pattern); |
76 | | - assert(pattern->getSubExpr() && "expect ExprPattern to have SubExpr"); |
77 | | - dispatcher_.emit(ExprPatternsTrap{label, dispatcher_.fetchLabel(pattern->getSubExpr())}); |
| 66 | +codeql::ExprPattern PatternVisitor::translateExprPattern(const swift::ExprPattern& pattern) { |
| 67 | + auto entry = dispatcher_.createEntry(pattern); |
| 68 | + entry.sub_expr = dispatcher_.fetchLabel(pattern.getSubExpr()); |
| 69 | + return entry; |
78 | 70 | } |
79 | 71 |
|
80 | | -void PatternVisitor::visitParenPattern(swift::ParenPattern* pattern) { |
81 | | - auto label = dispatcher_.assignNewLabel(pattern); |
82 | | - assert(pattern->getSubPattern() && "expect ParenPattern to have SubPattern"); |
83 | | - dispatcher_.emit(ParenPatternsTrap{label, dispatcher_.fetchLabel(pattern->getSubPattern())}); |
| 72 | +codeql::ParenPattern PatternVisitor::translateParenPattern(const swift::ParenPattern& pattern) { |
| 73 | + auto entry = dispatcher_.createEntry(pattern); |
| 74 | + entry.sub_pattern = dispatcher_.fetchLabel(pattern.getSubPattern()); |
| 75 | + return entry; |
84 | 76 | } |
85 | 77 |
|
86 | | -void PatternVisitor::visitBoolPattern(swift::BoolPattern* pattern) { |
87 | | - auto label = dispatcher_.assignNewLabel(pattern); |
88 | | - dispatcher_.emit(BoolPatternsTrap{label, pattern->getValue()}); |
| 78 | +codeql::BoolPattern PatternVisitor::translateBoolPattern(const swift::BoolPattern& pattern) { |
| 79 | + auto entry = dispatcher_.createEntry(pattern); |
| 80 | + entry.value = pattern.getValue(); |
| 81 | + return entry; |
89 | 82 | } |
90 | 83 |
|
91 | 84 | } // namespace codeql |
0 commit comments