Skip to content

Commit

Permalink
Rust: avoid multiple PrimaryQLClass warnings
Browse files Browse the repository at this point in the history
Fixes things like:
```
multiplePrimaryQlClasses
| x | PathExpr,VariableAccess |
```
  • Loading branch information
aibaars committed Oct 17, 2024
1 parent 54b94ae commit 72515e9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
private import rust
private import codeql.rust.elements.internal.generated.ParentChild
private import codeql.rust.elements.internal.ExprImpl::Impl as ExprImpl
private import codeql.rust.elements.internal.PathExprImpl::Impl as PathExprImpl
private import codeql.rust.elements.internal.ImplicitVariableAccessImpl::Impl as ImplicitVariableAccessImpl
private import codeql.util.DenseRank

module Impl {
Expand Down Expand Up @@ -450,7 +452,8 @@ module Impl {
private class TVariableAccess = Synth::TPathExpr or Synth::TImplicitVariableAccess;

/** A variable access. */
class VariableAccess extends ExprImpl::Expr, TVariableAccess instanceof VariableAccessCand {
abstract class VariableAccess extends ExprImpl::Expr, TVariableAccess instanceof VariableAccessCand
{
private string name;
private Variable v;

Expand All @@ -467,6 +470,18 @@ module Impl {
override string getAPrimaryQlClass() { result = "VariableAccess" }
}

private class VariableAccessPathExpr extends VariableAccess, PathExprImpl::PathExpr {
override string getAPrimaryQlClass() { result = VariableAccess.super.getAPrimaryQlClass() }
}

private class VariableAccessImplicitVariableAccess extends VariableAccess,
ImplicitVariableAccessImpl::ImplicitVariableAccess
{
override string toString() { result = VariableAccess.super.toString() }

override string getAPrimaryQlClass() { result = VariableAccess.super.getAPrimaryQlClass() }
}

/** Holds if `e` occurs in the LHS of an assignment or compound assignment. */
private predicate assignmentExprDescendant(Expr e) {
e = any(AssignmentExpr ae).getLhs()
Expand Down

0 comments on commit 72515e9

Please sign in to comment.