summaryrefslogtreecommitdiff
path: root/python/typeprinter.py
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-11-15 17:18:52 -0500
committerGlenn Smith <glenn@vector35.com>2022-11-16 13:57:49 -0500
commit23f33aa2f5f4a886716e39727c29004bbc57899b (patch)
tree6019f566b01f7a319359d53f8b09f44f60596f2d /python/typeprinter.py
parentedc6b36a5f367229faf1ccf81fb075b005a867f7 (diff)
Add python docs for TypePrinter methods
Diffstat (limited to 'python/typeprinter.py')
-rw-r--r--python/typeprinter.py76
1 files changed, 75 insertions, 1 deletions
diff --git a/python/typeprinter.py b/python/typeprinter.py
index 993ac5d0..b9ccabf7 100644
--- a/python/typeprinter.py
+++ b/python/typeprinter.py
@@ -18,7 +18,6 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
-import abc
import ctypes
import dataclasses
from json import dumps
@@ -73,6 +72,10 @@ class _TypePrinterMetaclass(type):
class TypePrinter(metaclass=_TypePrinterMetaclass):
+ """
+ Class for turning Type objects into strings and tokens.
+ """
+
name = None
_registered_printers = []
_cached_tokens = None
@@ -299,27 +302,98 @@ class TypePrinter(metaclass=_TypePrinterMetaclass):
return core.pyNativeStr(result.value)
def get_type_tokens(self, type: types.Type, platform: Optional[_platform.Platform] = None, name: types.QualifiedNameType = "", base_confidence: int = core.max_confidence, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> List[_function.InstructionTextToken]:
+ """
+ Generate a single-line text representation of a type
+ :param type: Type to print
+ :param platform: Platform responsible for this type
+ :param name: Name of the type
+ :param base_confidence: Confidence to use for tokens created for this type
+ :param escaping: Style of escaping literals which may not be parsable
+ :return: List of text tokens representing the type
+ """
raise NotImplementedError()
def get_type_tokens_before_name(self, type: types.Type, platform: Optional[_platform.Platform] = None, base_confidence: int = core.max_confidence, parent_type: Optional[types.Type] = None, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> List[_function.InstructionTextToken]:
+ """
+ In a single-line text representation of a type, generate the tokens that should
+ be printed before the type's name.
+ :param type: Type to print
+ :param platform: Platform responsible for this type
+ :param base_confidence: Confidence to use for tokens created for this type
+ :param parent_type: Type of the parent of this type, or None
+ :param escaping: Style of escaping literals which may not be parsable
+ :return: List of text tokens representing the type
+ """
raise NotImplementedError()
def get_type_tokens_after_name(self, type: types.Type, platform: Optional[_platform.Platform] = None, base_confidence: int = core.max_confidence, parent_type: Optional[types.Type] = None, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> List[_function.InstructionTextToken]:
+ """
+ In a single-line text representation of a type, generate the tokens that should
+ be printed after the type's name.
+ :param type: Type to print
+ :param platform: Platform responsible for this type
+ :param base_confidence: Confidence to use for tokens created for this type
+ :param parent_type: Type of the parent of this type, or None
+ :param escaping: Style of escaping literals which may not be parsable
+ :return: List of text tokens representing the type
+ """
raise NotImplementedError()
def get_type_string(self, type: types.Type, platform: Optional[_platform.Platform] = None, name: types.QualifiedNameType = "", escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str:
+ """
+ Generate a single-line text representation of a type
+ :param type: Type to print
+ :param platform: Platform responsible for this type
+ :param name: Name of the type
+ :param escaping: Style of escaping literals which may not be parsable
+ :return: String representing the type
+ """
raise NotImplementedError()
def get_type_string_before_name(self, type: types.Type, platform: Optional[_platform.Platform] = None, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str:
+ """
+ In a single-line text representation of a type, generate the string that should
+ be printed before the type's name.
+ :param type: Type to print
+ :param platform: Platform responsible for this type
+ :param escaping: Style of escaping literals which may not be parsable
+ :return: String representing the type
+ """
raise NotImplementedError()
def get_type_string_after_name(self, type: types.Type, platform: Optional[_platform.Platform] = None, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str:
+ """
+ In a single-line text representation of a type, generate the string that should
+ be printed after the type's name.
+ :param type: Type to print
+ :param platform: Platform responsible for this type
+ :param escaping: Style of escaping literals which may not be parsable
+ :return: String representing the type
+ """
raise NotImplementedError()
def get_type_lines(self, type: types.Type, data: binaryview.BinaryView, name: types.QualifiedNameType, line_width = 80, collapsed = False, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> List[types.TypeDefinitionLine]:
+ """
+ Generate a multi-line representation of a type
+ :param type: Type to print
+ :param data: Binary View in which the type is defined
+ :param name: Name of the type
+ :param line_width: Maximum width of lines, in characters
+ :param collapsed: Whether to collapse structure/enum blocks
+ :param escaping: Style of escaping literals which may not be parsable
+ :return: List of type definition lines
+ """
raise NotImplementedError()
def print_all_types(self, types: List[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, line_width = 80, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str:
+ """
+ Print all types to a single big string, including headers, sections, etc
+ :param types: All types to print
+ :param data: Binary View in which all the types are defined
+ :param line_width: Maximum width of lines, in characters
+ :param escaping: Style of escaping literals which may not be parsable
+ :return: All the types in a string
+ """
return self._default_print_all_types(types, data, line_width, escaping)