Merge pull request #2733 from tausbn/python-add-stringvalue

Python: Extend `Value` API.
This commit is contained in:
Rasmus Wriedt Larsen 2020-01-31 13:12:14 +01:00 коммит произвёл GitHub
Родитель 7855a0b657 ba2bbf1788
Коммит 72fddaf5ed
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 30 добавлений и 0 удалений

Просмотреть файл

@ -117,6 +117,11 @@ class Value extends TObject {
my_class.getABaseType+() = other_class
)
}
/** Gets the boolean value of this value. */
boolean booleanValue() {
result = this.(ObjectInternal).booleanValue()
}
}
/** Class representing modules in the Python program
@ -599,6 +604,22 @@ class TupleValue extends SequenceValue {
}
/** A class representing strings, either present in the source as a literal, or
in a builtin as a value. */
class StringValue extends Value {
StringValue() {
this instanceof BytesObjectInternal or
this instanceof UnicodeObjectInternal
}
string getText() {
result = this.(BytesObjectInternal).strValue()
or
result = this.(UnicodeObjectInternal).strValue()
}
}
/** A method-resolution-order sequence of classes */
class MRO extends TClassList {
@ -694,6 +715,15 @@ module ClassValue {
result = TBuiltinClassObject(Builtin::special("unicode"))
}
/** Get the `ClassValue` for the `str` class. This is `bytes` in Python 2,
and `str` in Python 3. */
ClassValue str() {
if major_version() = 2 then
result = bytes()
else
result = unicode()
}
/** Get the `ClassValue` for the `classmethod` class. */
ClassValue classmethod() {
result = TBuiltinClassObject(Builtin::special("ClassMethod"))