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"""Command used to give a line in a test a named psuedonym. Every DexLabel has
8   a line number and Label string component.
9"""
10
11from dex.command.CommandBase import CommandBase
12
13
14class DexLabel(CommandBase):
15    def __init__(self, label, **kwargs):
16
17        if not isinstance(label, str):
18            raise TypeError('invalid argument type')
19
20        try:
21            self.on_line = kwargs.pop('on_line')
22        except KeyError:
23            # We cannot use self.lineno because it hasn't been set yet.
24            pass
25        if kwargs:
26            raise TypeError(f'unexpected named args: {", ".join(kwargs)}')
27
28        self._label = label
29        super(DexLabel, self).__init__()
30
31    def get_line(self):
32        return getattr(self, 'on_line', self.lineno)
33
34    def get_as_pair(self):
35        return (self._label, self.get_line())
36
37    @staticmethod
38    def get_name():
39        return __class__.__name__
40
41    def eval(self):
42        return self._label
43