@@ -154,6 +154,40 @@ def _PrintTokenTooLong(loc_tok, f):
154
154
f .write (buf .getvalue ())
155
155
156
156
157
+ def GetFilenameString (line ):
158
+ # type: (SourceLine) -> str
159
+ """Get the path of the file that a line appears in.
160
+
161
+ Returns "main" if it's stdin or -c
162
+ Returns "?" if it's not in a file.
163
+
164
+ Used by declare -F, with shopt -s extdebug.
165
+ """
166
+ src = line .src
167
+ UP_src = src
168
+
169
+ filename_str = '?' # default
170
+ with tagswitch (src ) as case :
171
+ # Copying bash, it uses the string 'main'.
172
+ # I think ? would be better here, because this can get confused with a
173
+ # file 'main'. But it's fine for our task file usage.
174
+ if case (source_e .CFlag ):
175
+ filename_str = 'main'
176
+ elif case (source_e .Stdin ):
177
+ filename_str = 'main'
178
+
179
+ elif case (source_e .MainFile ):
180
+ src = cast (source .MainFile , UP_src )
181
+ filename_str = src .path
182
+ elif case (source_e .OtherFile ):
183
+ src = cast (source .OtherFile , UP_src )
184
+ filename_str = src .path
185
+
186
+ else :
187
+ pass
188
+ return filename_str
189
+
190
+
157
191
def GetLineSourceString (line , quote_filename = False ):
158
192
# type: (SourceLine, bool) -> str
159
193
"""Returns a human-readable string for dev tools.
0 commit comments