mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Swift: extract UnresolvedPatternExpr
This commit is contained in:
@@ -561,6 +561,8 @@ UnresolvedMemberExpr:
|
||||
UnresolvedPatternExpr:
|
||||
_extends: Expr
|
||||
_pragma: qltest_skip # we should really never extract these
|
||||
_children:
|
||||
sub_pattern: Pattern
|
||||
|
||||
UnresolvedSpecializeExpr:
|
||||
_extends: Expr
|
||||
|
||||
@@ -667,5 +667,11 @@ void ExprVisitor::emitLookupExpr(const swift::LookupExpr* expr, TrapLabel<Lookup
|
||||
dispatcher_.emit(LookupExprMembersTrap{label, declLabel});
|
||||
}
|
||||
}
|
||||
codeql::UnresolvedPatternExpr ExprVisitor::translateUnresolvedPatternExpr(
|
||||
swift::UnresolvedPatternExpr& expr) {
|
||||
auto entry = dispatcher_.createEntry(expr);
|
||||
entry.sub_pattern = dispatcher_.fetchLabel(expr.getSubPattern());
|
||||
return entry;
|
||||
}
|
||||
|
||||
} // namespace codeql
|
||||
|
||||
@@ -84,6 +84,11 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
|
||||
codeql::BridgeFromObjCExpr translateBridgeFromObjCExpr(const swift::BridgeFromObjCExpr& expr);
|
||||
codeql::DotSelfExpr translateDotSelfExpr(const swift::DotSelfExpr& expr);
|
||||
codeql::ErrorExpr translateErrorExpr(const swift::ErrorExpr& expr);
|
||||
// following requires non-const because:
|
||||
// * `swift::UnresolvedPatternExpr::getSubPattern` gives `const swift::Pattern*` on const refs
|
||||
// * `swift::ASTVisitor` only visits non-const pointers
|
||||
// either we accept this, or we fix constness by providing our own const visiting in VisitorBase
|
||||
codeql::UnresolvedPatternExpr translateUnresolvedPatternExpr(swift::UnresolvedPatternExpr& expr);
|
||||
|
||||
private:
|
||||
void fillAbstractClosureExpr(const swift::AbstractClosureExpr& expr,
|
||||
|
||||
@@ -29,7 +29,7 @@ class VisitorBase {
|
||||
public: \
|
||||
void visit##CLASS##KIND(swift::CLASS##KIND* e) { \
|
||||
using TranslateResult = std::invoke_result_t<decltype(&CrtpSubclass::translate##CLASS##KIND), \
|
||||
CrtpSubclass, swift::CLASS##KIND>; \
|
||||
CrtpSubclass, swift::CLASS##KIND&>; \
|
||||
constexpr bool hasTranslateImplementation = !std::is_same_v<TranslateResult, void>; \
|
||||
if constexpr (hasTranslateImplementation) { \
|
||||
dispatcher_.emit(static_cast<CrtpSubclass*>(this)->translate##CLASS##KIND(*e)); \
|
||||
|
||||
@@ -144,6 +144,8 @@ Element getAnImmediateChild(Element e) {
|
||||
or
|
||||
unresolved_dot_exprs(e, x, _)
|
||||
or
|
||||
unresolved_pattern_exprs(e, x)
|
||||
or
|
||||
vararg_expansion_exprs(e, x)
|
||||
or
|
||||
binding_patterns(e, x)
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements.expr.Expr
|
||||
import codeql.swift.elements.pattern.Pattern
|
||||
|
||||
class UnresolvedPatternExprBase extends @unresolved_pattern_expr, Expr {
|
||||
override string getAPrimaryQlClass() { result = "UnresolvedPatternExpr" }
|
||||
|
||||
Pattern getSubPattern() {
|
||||
exists(Pattern x |
|
||||
unresolved_pattern_exprs(this, x) and
|
||||
result = x.resolve()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1141,7 +1141,8 @@ unresolved_member_exprs( //dir=expr
|
||||
);
|
||||
|
||||
unresolved_pattern_exprs( //dir=expr
|
||||
unique int id: @unresolved_pattern_expr
|
||||
unique int id: @unresolved_pattern_expr,
|
||||
int sub_pattern: @pattern ref
|
||||
);
|
||||
|
||||
unresolved_specialize_exprs( //dir=expr
|
||||
|
||||
Reference in New Issue
Block a user