Commit 489d5c4b authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Added eq and hash to source descriptors

parent 4e70c07a
......@@ -206,6 +206,9 @@ def initial_compile_time_env():
#------------------------------------------------------------------
class SourceDescriptor:
"""
A SourceDescriptor should be considered immutable.
"""
def __str__(self):
assert False # To catch all places where a descriptor is used directly as a filename
......@@ -237,6 +240,12 @@ class FileSourceDescriptor(SourceDescriptor):
def get_filenametable_entry(self):
return self.filename
def __eq__(self, other):
return isinstance(other, FileSourceDescriptor) and self.filename == other.filename
def __hash__(self):
return hash(self.filename)
def __repr__(self):
return "<FileSourceDescriptor:%s>" % self.filename
......@@ -258,6 +267,12 @@ class StringSourceDescriptor(SourceDescriptor):
def get_filenametable_entry(self):
return "stringsource"
def __hash__(self):
return hash(self.name)
def __eq__(self, other):
return isinstance(other, StringSourceDescriptor) and self.name == other.name
def __repr__(self):
return "<StringSourceDescriptor:%s>" % self.name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment