Skip to content

Commit ce91401

Browse files
committed
Python: Add getMaDRepresentation()
This adds a convenient way of getting the Models-as-Data representation of a particular type of content. This avoids repeating the same construction over and over in our various summaries. Currently this is defined for all types of content except the captured variable content, which to my knowledge doesn't have any representation in Models-as-Data.
1 parent e16405c commit ce91401

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,16 +687,23 @@ newtype TContent =
687687
class Content extends TContent {
688688
/** Gets a textual representation of this element. */
689689
string toString() { result = "Content" }
690+
691+
/** Gets the Models-as-Data representation of this content (if any). */
692+
string getMaDRepresentation() { none() }
690693
}
691694

692695
/** An element of a list. */
693696
class ListElementContent extends TListElementContent, Content {
694697
override string toString() { result = "List element" }
698+
699+
override string getMaDRepresentation() { result = "ListElement" }
695700
}
696701

697702
/** An element of a set. */
698703
class SetElementContent extends TSetElementContent, Content {
699704
override string toString() { result = "Set element" }
705+
706+
override string getMaDRepresentation() { result = "SetElement" }
700707
}
701708

702709
/** An element of a tuple at a specific index. */
@@ -709,6 +716,8 @@ class TupleElementContent extends TTupleElementContent, Content {
709716
int getIndex() { result = index }
710717

711718
override string toString() { result = "Tuple element at index " + index.toString() }
719+
720+
override string getMaDRepresentation() { result = "TupleElement[" + index + "]" }
712721
}
713722

714723
/** An element of a dictionary under a specific key. */
@@ -721,11 +730,15 @@ class DictionaryElementContent extends TDictionaryElementContent, Content {
721730
string getKey() { result = key }
722731

723732
override string toString() { result = "Dictionary element at key " + key }
733+
734+
override string getMaDRepresentation() { result = "DictionaryElement[" + key + "]" }
724735
}
725736

726737
/** An element of a dictionary under any key. */
727738
class DictionaryElementAnyContent extends TDictionaryElementAnyContent, Content {
728739
override string toString() { result = "Any dictionary element" }
740+
741+
override string getMaDRepresentation() { result = "DictionaryElementAny" }
729742
}
730743

731744
/** An object attribute. */
@@ -738,6 +751,8 @@ class AttributeContent extends TAttributeContent, Content {
738751
string getAttribute() { result = attr }
739752

740753
override string toString() { result = "Attribute " + attr }
754+
755+
override string getMaDRepresentation() { result = "Attribute[" + attr + "]" }
741756
}
742757

743758
/** A captured variable. */
@@ -750,6 +765,8 @@ class CapturedVariableContent extends Content, TCapturedVariableContent {
750765
VariableCapture::CapturedVariable getVariable() { result = v }
751766

752767
override string toString() { result = "captured " + v }
768+
769+
override string getMaDRepresentation() { none() }
753770
}
754771

755772
/**

0 commit comments

Comments
 (0)