77"""
88import uuid
99from collections import defaultdict
10- from typing import TYPE_CHECKING , Dict , Set , Optional
10+ from typing import TYPE_CHECKING , Dict , List , Set , Optional
1111
1212from crytic_compile .compiler .compiler import CompilerVersion
1313from crytic_compile .source_unit import SourceUnit
@@ -36,7 +36,7 @@ def __init__(self, crytic_compile: "CryticCompile", unique_id: str):
3636 self ._source_units : Dict [Filename , SourceUnit ] = {}
3737
3838 # set containing all the filenames of this compilation unit
39- self ._filenames : Set [Filename ] = set ()
39+ self ._filenames : List [Filename ] = []
4040
4141 # mapping from absolute/relative/used to filename
4242 self ._filenames_lookup : Optional [Dict [str , Filename ]] = None
@@ -114,6 +114,8 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
114114 Create the source unit associated with the filename
115115 Add the relevant info in the compilation unit/crytic compile
116116 If the source unit already exist, return it
117+ Also appends filename to the end of filenames, if not already present
118+ So this function should be called in the order you want filenames to have
117119
118120 Args:
119121 filename (Filename): filename of the source unit
@@ -123,8 +125,9 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
123125 """
124126 if not filename in self ._source_units :
125127 source_unit = SourceUnit (self , filename ) # type: ignore
126- self .filenames .add (filename )
127128 self ._source_units [filename ] = source_unit
129+ if filename not in self .filenames :
130+ self .filenames .append (filename )
128131 return self ._source_units [filename ]
129132
130133 # endregion
@@ -135,20 +138,20 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
135138 ###################################################################################
136139
137140 @property
138- def filenames (self ) -> Set [Filename ]:
141+ def filenames (self ) -> List [Filename ]:
139142 """Return the filenames used by the compilation unit
140143
141144 Returns:
142- Set [Filename]: Filenames used by the compilation units
145+ list [Filename]: Filenames used by the compilation units
143146 """
144147 return self ._filenames
145148
146149 @filenames .setter
147- def filenames (self , all_filenames : Set [Filename ]) -> None :
150+ def filenames (self , all_filenames : List [Filename ]) -> None :
148151 """Set the filenames
149152
150153 Args:
151- all_filenames (Set [Filename]): new filenames
154+ all_filenames (List [Filename]): new filenames
152155 """
153156 self ._filenames = all_filenames
154157
0 commit comments