| @@ 12-112 (lines=101) @@ | ||
| 9 | from sdoc.sdoc1.data_type.DataType import DataType |
|
| 10 | ||
| 11 | ||
| 12 | class IntegerDataType(DataType): |
|
| 13 | """ |
|
| 14 | Class for integer data types. |
|
| 15 | """ |
|
| 16 | ||
| 17 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 18 | def __init__(self, value): |
|
| 19 | """ |
|
| 20 | Object constructor. |
|
| 21 | ||
| 22 | :param int|str value: The value of this integer constant. |
|
| 23 | """ |
|
| 24 | self._value = int(value) |
|
| 25 | """ |
|
| 26 | The value of this constant integer. |
|
| 27 | ||
| 28 | :type: int |
|
| 29 | """ |
|
| 30 | ||
| 31 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 32 | def debug(self, indent=0): |
|
| 33 | """ |
|
| 34 | Returns a string for debugging. |
|
| 35 | ||
| 36 | :param int indent: Unused. |
|
| 37 | ||
| 38 | :rtype: str |
|
| 39 | """ |
|
| 40 | return str(self._value) |
|
| 41 | ||
| 42 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 43 | def dereference(self): |
|
| 44 | """ |
|
| 45 | Returns a clone of this integer. |
|
| 46 | ||
| 47 | :rtype: IntegerDataType |
|
| 48 | """ |
|
| 49 | return IntegerDataType(self._value) |
|
| 50 | ||
| 51 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 52 | def get_value(self): |
|
| 53 | """ |
|
| 54 | Returns the underling value of this data type. |
|
| 55 | ||
| 56 | :rtype: int |
|
| 57 | """ |
|
| 58 | return self._value |
|
| 59 | ||
| 60 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 61 | def get_type_id(self): |
|
| 62 | """ |
|
| 63 | Returns the ID of this data type. |
|
| 64 | ||
| 65 | :rtype: int |
|
| 66 | """ |
|
| 67 | return DataType.INT |
|
| 68 | ||
| 69 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 70 | def is_constant(self): |
|
| 71 | """ |
|
| 72 | Returns False always. |
|
| 73 | ||
| 74 | :rtype: bool |
|
| 75 | """ |
|
| 76 | return False |
|
| 77 | ||
| 78 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 79 | def is_defined(self): |
|
| 80 | """ |
|
| 81 | Returns True always. |
|
| 82 | ||
| 83 | :rtype: bool |
|
| 84 | """ |
|
| 85 | return True |
|
| 86 | ||
| 87 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 88 | def is_scalar(self): |
|
| 89 | """ |
|
| 90 | Returns True always. |
|
| 91 | ||
| 92 | :rtype: bool |
|
| 93 | """ |
|
| 94 | return False |
|
| 95 | ||
| 96 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 97 | def is_true(self): |
|
| 98 | """ |
|
| 99 | Returns True if this integer is not 0. Returns False otherwise. |
|
| 100 | ||
| 101 | :rtype: bool |
|
| 102 | """ |
|
| 103 | return self._value != 0 |
|
| 104 | ||
| 105 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 106 | def __str__(self): |
|
| 107 | """ |
|
| 108 | Returns the string representation of the integer constant. |
|
| 109 | ||
| 110 | :rtype: str |
|
| 111 | """ |
|
| 112 | return str(self._value) |
|
| 113 | ||
| 114 | # ---------------------------------------------------------------------------------------------------------------------- |
|
| 115 | ||
| @@ 12-112 (lines=101) @@ | ||
| 9 | from sdoc.sdoc1.data_type.DataType import DataType |
|
| 10 | ||
| 11 | ||
| 12 | class StringDataType(DataType): |
|
| 13 | """ |
|
| 14 | Class for string data types. |
|
| 15 | """ |
|
| 16 | ||
| 17 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 18 | def __init__(self, value): |
|
| 19 | """ |
|
| 20 | Object constructor. |
|
| 21 | ||
| 22 | :param str value: The value of this string constant. |
|
| 23 | """ |
|
| 24 | self._value = value |
|
| 25 | """ |
|
| 26 | The value of this constant integer. |
|
| 27 | ||
| 28 | :type: string |
|
| 29 | """ |
|
| 30 | ||
| 31 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 32 | def debug(self, indent=0): |
|
| 33 | """ |
|
| 34 | Returns a string for debugging. |
|
| 35 | ||
| 36 | :param int indent: Unused. |
|
| 37 | ||
| 38 | :rtype: str |
|
| 39 | """ |
|
| 40 | return "'" + self._value + "'" |
|
| 41 | ||
| 42 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 43 | def dereference(self): |
|
| 44 | """ |
|
| 45 | Returns a clone of this string. |
|
| 46 | ||
| 47 | :rtype: StringDataType |
|
| 48 | """ |
|
| 49 | return StringDataType(self._value) |
|
| 50 | ||
| 51 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 52 | def get_value(self): |
|
| 53 | """ |
|
| 54 | Returns the underling value of this data type. |
|
| 55 | ||
| 56 | :rtype: str |
|
| 57 | """ |
|
| 58 | return self._value |
|
| 59 | ||
| 60 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 61 | def get_type_id(self): |
|
| 62 | """ |
|
| 63 | Returns the ID of this data type. |
|
| 64 | ||
| 65 | :rtype: int |
|
| 66 | """ |
|
| 67 | return DataType.STRING |
|
| 68 | ||
| 69 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 70 | def is_constant(self): |
|
| 71 | """ |
|
| 72 | Returns False always. |
|
| 73 | ||
| 74 | :rtype: bool |
|
| 75 | """ |
|
| 76 | return False |
|
| 77 | ||
| 78 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 79 | def is_defined(self): |
|
| 80 | """ |
|
| 81 | Returns True always. |
|
| 82 | ||
| 83 | :rtype: bool |
|
| 84 | """ |
|
| 85 | return True |
|
| 86 | ||
| 87 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 88 | def is_scalar(self): |
|
| 89 | """ |
|
| 90 | Returns True always. |
|
| 91 | ||
| 92 | :rtype: bool |
|
| 93 | """ |
|
| 94 | return True |
|
| 95 | ||
| 96 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 97 | def is_true(self): |
|
| 98 | """ |
|
| 99 | Returns True if this string is not empty. Returns False otherwise. |
|
| 100 | ||
| 101 | :rtype: bool |
|
| 102 | """ |
|
| 103 | return self._value != '' |
|
| 104 | ||
| 105 | # ------------------------------------------------------------------------------------------------------------------ |
|
| 106 | def __str__(self): |
|
| 107 | """ |
|
| 108 | Returns the string representation of the string constant. |
|
| 109 | ||
| 110 | :rtype: str |
|
| 111 | """ |
|
| 112 | return self._value |
|
| 113 | ||
| 114 | # ---------------------------------------------------------------------------------------------------------------------- |
|
| 115 | ||