Skip to content

Commit b35718e

Browse files
authored
Python: Remove uses of getAQlClass
1 parent 095f27f commit b35718e

File tree

1 file changed

+58
-7
lines changed
  • python/ql/lib/semmle/python/essa

1 file changed

+58
-7
lines changed

python/ql/lib/semmle/python/essa/Essa.qll

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ abstract class EssaDefinition extends TEssaDefinition {
171171
EssaVariable getVariable() { result.getDefinition() = this }
172172

173173
abstract BasicBlock getBasicBlock();
174+
175+
/** Gets the name of the primary QL class for this element. */
176+
string getAPrimaryQlClass() { result = "EssaDefinition" }
174177
}
175178

176179
/**
@@ -216,13 +219,15 @@ class EssaEdgeRefinement extends EssaDefinition, TEssaEdgeDefinition {
216219
}
217220

218221
override string getRepresentation() {
219-
result = this.getAQlClass() + "(" + this.getInput().getRepresentation() + ")"
222+
result = this.getAPrimaryQlClass() + "(" + this.getInput().getRepresentation() + ")"
220223
}
221224

222225
/** Gets the scope of the variable defined by this definition. */
223226
override Scope getScope() { result = this.getPredecessor().getScope() }
224227

225228
override BasicBlock getBasicBlock() { result = this.getSuccessor() }
229+
230+
override string getAPrimaryQlClass() { result = "EssaEdgeRefinement" }
226231
}
227232

228233
/** A Phi-function as specified in classic SSA form. */
@@ -366,6 +371,8 @@ class PhiFunction extends EssaDefinition, TPhiFunction {
366371
)
367372
)
368373
}
374+
375+
override string getAPrimaryQlClass() { result = "PhiFunction" }
369376
}
370377

371378
/**
@@ -396,7 +403,7 @@ class EssaNodeDefinition extends EssaDefinition, TEssaNodeDefinition {
396403

397404
override Location getLocation() { result = this.getDefiningNode().getLocation() }
398405

399-
override string getRepresentation() { result = this.getAQlClass() }
406+
override string getRepresentation() { result = this.getAPrimaryQlClass() }
400407

401408
override Scope getScope() {
402409
exists(BasicBlock defb |
@@ -414,6 +421,8 @@ class EssaNodeDefinition extends EssaDefinition, TEssaNodeDefinition {
414421
}
415422

416423
override BasicBlock getBasicBlock() { result = this.getDefiningNode().getBasicBlock() }
424+
425+
override string getAPrimaryQlClass() { result = "EssaNodeDefinition" }
417426
}
418427

419428
/** A definition of an ESSA variable that takes another ESSA variable as an input. */
@@ -448,10 +457,10 @@ class EssaNodeRefinement extends EssaDefinition, TEssaNodeRefinement {
448457
override Location getLocation() { result = this.getDefiningNode().getLocation() }
449458

450459
override string getRepresentation() {
451-
result = this.getAQlClass() + "(" + this.getInput().getRepresentation() + ")"
460+
result = this.getAPrimaryQlClass() + "(" + this.getInput().getRepresentation() + ")"
452461
or
453462
not exists(this.getInput()) and
454-
result = this.getAQlClass() + "(" + this.getSourceVariable().getName() + "??)"
463+
result = this.getAPrimaryQlClass() + "(" + this.getSourceVariable().getName() + "??)"
455464
}
456465

457466
override Scope getScope() {
@@ -470,6 +479,8 @@ class EssaNodeRefinement extends EssaDefinition, TEssaNodeRefinement {
470479
}
471480

472481
override BasicBlock getBasicBlock() { result = this.getDefiningNode().getBasicBlock() }
482+
483+
override string getAPrimaryQlClass() { result = "EssaNodeRefinement" }
473484
}
474485

475486
pragma[noopt]
@@ -500,6 +511,8 @@ class AssignmentDefinition extends EssaNodeDefinition {
500511
}
501512

502513
override string getRepresentation() { result = this.getValue().getNode().toString() }
514+
515+
override string getAPrimaryQlClass() { result = "AssignmentDefinition" }
503516
}
504517

505518
/** Capture of a raised exception `except ExceptionType ex:` */
@@ -516,6 +529,8 @@ class ExceptionCapture extends EssaNodeDefinition {
516529
}
517530

518531
override string getRepresentation() { result = "except " + this.getSourceVariable().getName() }
532+
533+
override string getAPrimaryQlClass() { result = "ExceptionCapture" }
519534
}
520535

521536
/** An assignment to a variable as part of a multiple assignment `..., v, ... = val` */
@@ -536,13 +551,17 @@ class MultiAssignmentDefinition extends EssaNodeDefinition {
536551
SsaSource::multi_assignment_definition(this.getSourceVariable(), this.getDefiningNode(), index,
537552
lhs)
538553
}
554+
555+
override string getAPrimaryQlClass() { result = "MultiAssignmentDefinition" }
539556
}
540557

541558
/** A definition of a variable in a `with` statement */
542559
class WithDefinition extends EssaNodeDefinition {
543560
WithDefinition() { SsaSource::with_definition(this.getSourceVariable(), this.getDefiningNode()) }
544561

545562
override string getRepresentation() { result = "with" }
563+
564+
override string getAPrimaryQlClass() { result = "WithDefinition" }
546565
}
547566

548567
/** A definition of a variable via a capture pattern */
@@ -552,6 +571,8 @@ class PatternCaptureDefinition extends EssaNodeDefinition {
552571
}
553572

554573
override string getRepresentation() { result = "pattern capture" }
574+
575+
override string getAPrimaryQlClass() { result = "PatternCaptureDefinition" }
555576
}
556577

557578
/** A definition of a variable via a pattern alias */
@@ -561,6 +582,8 @@ class PatternAliasDefinition extends EssaNodeDefinition {
561582
}
562583

563584
override string getRepresentation() { result = "pattern alias" }
585+
586+
override string getAPrimaryQlClass() { result = "PatternAliasDefinition" }
564587
}
565588

566589
/** A definition of a variable by declaring it as a parameter */
@@ -594,13 +617,17 @@ class ParameterDefinition extends EssaNodeDefinition {
594617

595618
/** Gets the `Parameter` this `ParameterDefinition` represents. */
596619
Parameter getParameter() { result = this.getDefiningNode().getNode() }
620+
621+
override string getAPrimaryQlClass() { result = "ParameterDefinition" }
597622
}
598623

599624
/** A deletion of a variable `del v` */
600625
class DeletionDefinition extends EssaNodeDefinition {
601626
DeletionDefinition() {
602627
SsaSource::deletion_definition(this.getSourceVariable(), this.getDefiningNode())
603628
}
629+
630+
override string getAPrimaryQlClass() { result = "DeletionDefinition" }
604631
}
605632

606633
/**
@@ -614,13 +641,17 @@ class ScopeEntryDefinition extends EssaNodeDefinition {
614641
}
615642

616643
override Scope getScope() { result.getEntryNode() = this.getDefiningNode() }
644+
645+
override string getAPrimaryQlClass() { result = "ScopeEntryDefinition" }
617646
}
618647

619648
/** Possible redefinition of variable via `from ... import *` */
620649
class ImportStarRefinement extends EssaNodeRefinement {
621650
ImportStarRefinement() {
622651
SsaSource::import_star_refinement(this.getSourceVariable(), _, this.getDefiningNode())
623652
}
653+
654+
override string getAPrimaryQlClass() { result = "ImportStarRefinement" }
624655
}
625656

626657
/** Assignment of an attribute `obj.attr = val` */
@@ -635,12 +666,16 @@ class AttributeAssignment extends EssaNodeRefinement {
635666

636667
override string getRepresentation() {
637668
result =
638-
this.getAQlClass() + " '" + this.getName() + "'(" + this.getInput().getRepresentation() + ")"
669+
this.getAPrimaryQlClass() + " '" + this.getName() + "'(" + this.getInput().getRepresentation()
670+
+ ")"
639671
or
640672
not exists(this.getInput()) and
641673
result =
642-
this.getAQlClass() + " '" + this.getName() + "'(" + this.getSourceVariable().getName() + "??)"
674+
this.getAPrimaryQlClass() + " '" + this.getName() + "'(" + this.getSourceVariable().getName() +
675+
"??)"
643676
}
677+
678+
override string getAPrimaryQlClass() { result = "AttributeAssignment" }
644679
}
645680

646681
/** A use of a variable as an argument, `foo(v)`, which might modify the object referred to. */
@@ -654,6 +689,8 @@ class ArgumentRefinement extends EssaNodeRefinement {
654689
ControlFlowNode getArgument() { result = argument }
655690

656691
CallNode getCall() { result = this.getDefiningNode() }
692+
693+
override string getAPrimaryQlClass() { result = "ArgumentRefinement" }
657694
}
658695

659696
/** Deletion of an attribute `del obj.attr`. */
@@ -663,6 +700,8 @@ class EssaAttributeDeletion extends EssaNodeRefinement {
663700
}
664701

665702
string getName() { result = this.getDefiningNode().(AttrNode).getName() }
703+
704+
override string getAPrimaryQlClass() { result = "EssaAttributeDeletion" }
666705
}
667706

668707
/** A pi-node (guard) with only one successor. */
@@ -690,6 +729,8 @@ class SingleSuccessorGuard extends EssaNodeRefinement {
690729
test = this.getDefiningNode() and
691730
SsaSource::test_refinement(this.getSourceVariable(), use, test)
692731
}
732+
733+
override string getAPrimaryQlClass() { result = "SingleSuccessorGuard" }
693734
}
694735

695736
/**
@@ -701,11 +742,13 @@ class ImplicitSubModuleDefinition extends EssaNodeDefinition {
701742
ImplicitSubModuleDefinition() {
702743
SsaSource::init_module_submodule_defn(this.getSourceVariable(), this.getDefiningNode())
703744
}
745+
746+
override string getAPrimaryQlClass() { result = "ImplicitSubModuleDefinition" }
704747
}
705748

706749
/** An implicit (possible) definition of an escaping variable at a call-site */
707750
class CallsiteRefinement extends EssaNodeRefinement {
708-
override string toString() { result = "CallsiteRefinement" }
751+
override string toString() { result = "CallSiteRefinement" }
709752

710753
CallsiteRefinement() {
711754
exists(SsaSourceVariable var, ControlFlowNode defn |
@@ -718,6 +761,8 @@ class CallsiteRefinement extends EssaNodeRefinement {
718761
}
719762

720763
CallNode getCall() { this.getDefiningNode() = result }
764+
765+
override string getAPrimaryQlClass() { result = "CallsiteRefinement" }
721766
}
722767

723768
/** An implicit (possible) modification of the object referred at a method call */
@@ -728,11 +773,15 @@ class MethodCallsiteRefinement extends EssaNodeRefinement {
728773
}
729774

730775
CallNode getCall() { this.getDefiningNode() = result }
776+
777+
override string getAPrimaryQlClass() { result = "MethodCallsiteRefinement" }
731778
}
732779

733780
/** An implicit (possible) modification of `self` at a method call */
734781
class SelfCallsiteRefinement extends MethodCallsiteRefinement {
735782
SelfCallsiteRefinement() { this.getSourceVariable().(Variable).isSelf() }
783+
784+
override string getAPrimaryQlClass() { result = "SelfCallsiteRefinement" }
736785
}
737786

738787
/** Python specific sub-class of generic EssaEdgeRefinement */
@@ -750,4 +799,6 @@ class PyEdgeRefinement extends EssaEdgeRefinement {
750799
}
751800

752801
ControlFlowNode getTest() { result = this.getPredecessor().getLastNode() }
802+
803+
override string getAPrimaryQlClass() { result = "PyEdgeRefinement" }
753804
}

0 commit comments

Comments
 (0)