Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add __int__, __hash__, __eq__ methods and missing annotations to Token, Local, and Argument classes #103

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dncil/clr/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ def __str__(self) -> str:

def __repr__(self) -> str:
return str(self)

def __int__(self) -> int:
return int(self.index)
akhilguruprasad22 marked this conversation as resolved.
Show resolved Hide resolved

def __eq__(self, other: object) -> bool:
return isinstance(other, Argument) and self.index == other.index

def __hash__(self) -> int:
return hash(self.index)
9 changes: 9 additions & 0 deletions dncil/clr/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ def __str__(self) -> str:

def __repr__(self) -> str:
return str(self)

def __int__(self) -> int:
return int(self.index)
akhilguruprasad22 marked this conversation as resolved.
Show resolved Hide resolved

def __eq__(self, other: object) -> bool:
return isinstance(other, Local) and self.index == other.index

def __hash__(self) -> int:
return hash(self.index)
37 changes: 24 additions & 13 deletions dncil/clr/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,60 @@
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.

from __future__ import annotations


class Token(object):
"""store managed token"""

RID_MASK = 0x00FFFFFF
RID_MAX = RID_MASK
TABLE_SHIFT = 24
RID_MASK: int = 0x00FFFFFF
RID_MAX: int = RID_MASK
TABLE_SHIFT: int = 24

def __init__(self, value):
self.value = value
def __init__(self, value: int):
self.value: int = value

@property
def rid(self):
def rid(self) -> int:
"""get token row index"""
return self.value & Token.RID_MASK

@property
def table(self):
def table(self) -> int:
"""get token table index"""
return self.value >> Token.TABLE_SHIFT

def __str__(self):
def __str__(self) -> str:
return "token(0x%08X)" % self.value

def __repr__(self):
def __repr__(self) -> str:
return str(self)

def __int__(self) -> int:
return int(self.value)
akhilguruprasad22 marked this conversation as resolved.
Show resolved Hide resolved

def __eq__(self, other: object) -> bool:
return isinstance(other, Token) and self.value == other.value

def __hash__(self) -> int:
return hash(self.value)


class InvalidToken(Token):
"""store invalid managed token"""

def __init__(self, value):
def __init__(self, value: int):
super(InvalidToken, self).__init__(value)

def __str__(self):
def __str__(self) -> str:
return "invalid token(0x%08X)" % self.value


class StringToken(Token):
"""store string managed token"""

def __init__(self, value):
def __init__(self, value: int):
super(StringToken, self).__init__(value)

def __str__(self):
def __str__(self) -> str:
return "string token(0x%08X)" % self.value
Loading