1# DExTer : Debugging Experience Tester 2# ~~~~~~ ~ ~~ ~ ~~ 3# 4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5# See https://llvm.org/LICENSE.txt for license information. 6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7"""Base class for all DExTer commands, where a command is a specific Python 8function that can be embedded into a comment in the source code under test 9which will then be executed by DExTer during debugging. 10""" 11 12import abc 13from typing import List 14 15class CommandBase(object, metaclass=abc.ABCMeta): 16 def __init__(self): 17 self.path = None 18 self.lineno = None 19 self.raw_text = '' 20 21 def get_label_args(self): 22 return list() 23 24 def has_labels(self): 25 return False 26 27 @abc.abstractstaticmethod 28 def get_name(): 29 """This abstract method is usually implemented in subclasses as: 30 return __class__.__name__ 31 """ 32 33 def get_watches(self) -> List[str]: 34 return [] 35 36 @abc.abstractmethod 37 def eval(self): 38 """Evaluate the command. 39 40 This will be called when constructing a Heuristic object to determine 41 the debug score. 42 43 Returns: 44 The logic for handling the result of CommandBase.eval() must be 45 defined in Heuristic.__init__() so a consitent return type between 46 commands is not enforced. 47 """ 48 49 @staticmethod 50 def get_subcommands() -> dict: 51 """Returns a dictionary of subcommands in the form {name: command} or 52 None if no subcommands are required. 53 """ 54 return None 55