|
1
|
1 |
|
from typing import Union |
|
2
|
|
|
|
|
3
|
1 |
|
from sdoc.sdoc1.data_type.DataType import DataType |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
1 |
View Code Duplication |
class IntegerDataType(DataType): |
|
7
|
|
|
""" |
|
8
|
|
|
Class for integer data types. |
|
9
|
|
|
""" |
|
10
|
|
|
|
|
11
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
12
|
1 |
|
def __init__(self, value: Union[int, str]): |
|
13
|
|
|
""" |
|
14
|
|
|
Object constructor. |
|
15
|
|
|
|
|
16
|
|
|
:param int|str value: The value of this integer constant. |
|
17
|
|
|
""" |
|
18
|
1 |
|
self._value: int = int(value) |
|
19
|
1 |
|
""" |
|
20
|
|
|
The value of this constant integer. |
|
21
|
|
|
""" |
|
22
|
|
|
|
|
23
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
24
|
1 |
|
def debug(self, indent: int = 0) -> str: |
|
25
|
|
|
""" |
|
26
|
|
|
Returns a string for debugging. |
|
27
|
|
|
|
|
28
|
|
|
:param int indent: Unused. |
|
29
|
|
|
""" |
|
30
|
1 |
|
return str(self._value) |
|
31
|
|
|
|
|
32
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
33
|
1 |
|
def dereference(self): |
|
34
|
|
|
""" |
|
35
|
|
|
Returns a clone of this integer. |
|
36
|
|
|
|
|
37
|
|
|
:rtype: sdoc.sdoc1.data_type.IntegerDataType.IntegerDataType |
|
38
|
|
|
""" |
|
39
|
1 |
|
return IntegerDataType(self._value) |
|
40
|
|
|
|
|
41
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
42
|
1 |
|
def get_value(self) -> int: |
|
43
|
|
|
""" |
|
44
|
|
|
Returns the underling value of this data type. |
|
45
|
|
|
""" |
|
46
|
1 |
|
return self._value |
|
47
|
|
|
|
|
48
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
49
|
1 |
|
def get_type_id(self) -> int: |
|
50
|
|
|
""" |
|
51
|
|
|
Returns the ID of this data type. |
|
52
|
|
|
""" |
|
53
|
|
|
return DataType.INT |
|
54
|
|
|
|
|
55
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
56
|
1 |
|
def is_constant(self) -> bool: |
|
57
|
|
|
""" |
|
58
|
|
|
Returns False always. |
|
59
|
|
|
""" |
|
60
|
|
|
return False |
|
61
|
|
|
|
|
62
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
63
|
1 |
|
def is_defined(self) -> bool: |
|
64
|
|
|
""" |
|
65
|
|
|
Returns True always. |
|
66
|
|
|
""" |
|
67
|
1 |
|
return True |
|
68
|
|
|
|
|
69
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
70
|
1 |
|
def is_scalar(self) -> bool: |
|
71
|
|
|
""" |
|
72
|
|
|
Returns True always. |
|
73
|
|
|
""" |
|
74
|
|
|
return False |
|
75
|
|
|
|
|
76
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
77
|
1 |
|
def is_true(self) -> bool: |
|
78
|
|
|
""" |
|
79
|
|
|
Returns True if this integer is not 0. Returns False otherwise. |
|
80
|
|
|
""" |
|
81
|
|
|
return self._value != 0 |
|
82
|
|
|
|
|
83
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
84
|
1 |
|
def __str__(self) -> str: |
|
85
|
|
|
""" |
|
86
|
|
|
Returns the string representation of the integer constant. |
|
87
|
|
|
""" |
|
88
|
|
|
return str(self._value) |
|
89
|
|
|
|
|
90
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
91
|
|
|
|