@@ -220,19 +220,19 @@ def describe_signature(
220
220
221
221
def run (self ) -> list [Node ]:
222
222
env = self .state .document .settings .env # from ObjectDescription.run
223
- if 'c:parent_symbol' not in env .temp_data :
223
+ if env .current_document . c_parent_symbol is None :
224
224
root = env .domaindata ['c' ]['root_symbol' ]
225
- env .temp_data [ 'c:parent_symbol' ] = root
225
+ env .current_document . c_parent_symbol = root
226
226
env .ref_context ['c:parent_key' ] = root .get_lookup_key ()
227
227
228
228
# When multiple declarations are made in the same directive
229
229
# they need to know about each other to provide symbol lookup for function parameters.
230
230
# We use last_symbol to store the latest added declaration in a directive.
231
- env .temp_data [ 'c:last_symbol' ] = None
231
+ env .current_document . c_last_symbol = None
232
232
return super ().run ()
233
233
234
234
def handle_signature (self , sig : str , signode : TextElement ) -> ASTDeclaration :
235
- parent_symbol : Symbol = self .env .temp_data [ 'c:parent_symbol' ]
235
+ parent_symbol : Symbol = self .env .current_document . c_parent_symbol
236
236
237
237
max_len = (
238
238
self .env .config .c_maximum_signature_line_length
@@ -254,7 +254,7 @@ def handle_signature(self, sig: str, signode: TextElement) -> ASTDeclaration:
254
254
# the possibly inner declarations.
255
255
name = _make_phony_error_name ()
256
256
symbol = parent_symbol .add_name (name )
257
- self .env .temp_data [ 'c:last_symbol' ] = symbol
257
+ self .env .current_document . c_last_symbol = symbol
258
258
raise ValueError from e
259
259
260
260
try :
@@ -264,15 +264,15 @@ def handle_signature(self, sig: str, signode: TextElement) -> ASTDeclaration:
264
264
# append the new declaration to the sibling list
265
265
assert symbol .siblingAbove is None
266
266
assert symbol .siblingBelow is None
267
- symbol .siblingAbove = self .env .temp_data [ 'c:last_symbol' ]
267
+ symbol .siblingAbove = self .env .current_document . c_last_symbol
268
268
if symbol .siblingAbove is not None :
269
269
assert symbol .siblingAbove .siblingBelow is None
270
270
symbol .siblingAbove .siblingBelow = symbol
271
- self .env .temp_data [ 'c:last_symbol' ] = symbol
271
+ self .env .current_document . c_last_symbol = symbol
272
272
except _DuplicateSymbolError as e :
273
273
# Assume we are actually in the old symbol,
274
274
# instead of the newly created duplicate.
275
- self .env .temp_data [ 'c:last_symbol' ] = e .symbol
275
+ self .env .current_document . c_last_symbol = e .symbol
276
276
msg = __ (
277
277
'Duplicate C declaration, also defined at %s:%s.\n '
278
278
"Declaration is '.. c:%s:: %s'."
@@ -298,15 +298,15 @@ def handle_signature(self, sig: str, signode: TextElement) -> ASTDeclaration:
298
298
return ast
299
299
300
300
def before_content (self ) -> None :
301
- last_symbol : Symbol = self .env .temp_data [ 'c:last_symbol' ]
301
+ last_symbol : Symbol = self .env .current_document . c_last_symbol
302
302
assert last_symbol
303
- self .oldParentSymbol = self .env .temp_data [ 'c:parent_symbol' ]
303
+ self .oldParentSymbol = self .env .current_document . c_parent_symbol
304
304
self .oldParentKey : LookupKey = self .env .ref_context ['c:parent_key' ]
305
- self .env .temp_data [ 'c:parent_symbol' ] = last_symbol
305
+ self .env .current_document . c_parent_symbol = last_symbol
306
306
self .env .ref_context ['c:parent_key' ] = last_symbol .get_lookup_key ()
307
307
308
308
def after_content (self ) -> None :
309
- self .env .temp_data [ 'c:parent_symbol' ] = self .oldParentSymbol
309
+ self .env .current_document . c_parent_symbol = self .oldParentSymbol
310
310
self .env .ref_context ['c:parent_key' ] = self .oldParentKey
311
311
312
312
@@ -410,8 +410,8 @@ def run(self) -> list[Node]:
410
410
name = _make_phony_error_name ()
411
411
symbol = root_symbol .add_name (name )
412
412
stack = [symbol ]
413
- self .env .temp_data [ 'c:parent_symbol' ] = symbol
414
- self .env .temp_data [ 'c:namespace_stack' ] = stack
413
+ self .env .current_document . c_parent_symbol = symbol
414
+ self .env .current_document . c_namespace_stack = stack
415
415
self .env .ref_context ['c:parent_key' ] = symbol .get_lookup_key ()
416
416
return []
417
417
@@ -435,14 +435,12 @@ def run(self) -> list[Node]:
435
435
except DefinitionError as e :
436
436
logger .warning (e , location = self .get_location ())
437
437
name = _make_phony_error_name ()
438
- old_parent = self .env .temp_data . get ( 'c:parent_symbol' , None )
438
+ old_parent = self .env .current_document . c_parent_symbol
439
439
if not old_parent :
440
440
old_parent = self .env .domaindata ['c' ]['root_symbol' ]
441
441
symbol = old_parent .add_name (name )
442
- stack = self .env .temp_data .get ('c:namespace_stack' , [])
443
- stack .append (symbol )
444
- self .env .temp_data ['c:parent_symbol' ] = symbol
445
- self .env .temp_data ['c:namespace_stack' ] = stack
442
+ self .env .current_document .c_namespace_stack .append (symbol )
443
+ self .env .current_document .c_parent_symbol = symbol
446
444
self .env .ref_context ['c:parent_key' ] = symbol .get_lookup_key ()
447
445
return []
448
446
@@ -455,21 +453,19 @@ class CNamespacePopObject(SphinxDirective):
455
453
option_spec : ClassVar [OptionSpec ] = {}
456
454
457
455
def run (self ) -> list [Node ]:
458
- stack = self .env .temp_data . get ( 'c:namespace_stack' , None )
459
- if not stack or len (stack ) == 0 :
456
+ stack = self .env .current_document . c_namespace_stack
457
+ if len (stack ) == 0 :
460
458
logger .warning (
461
459
'C namespace pop on empty stack. Defaulting to global scope.' ,
462
460
location = self .get_location (),
463
461
)
464
- stack = []
465
462
else :
466
463
stack .pop ()
467
464
if len (stack ) > 0 :
468
465
symbol = stack [- 1 ]
469
466
else :
470
467
symbol = self .env .domaindata ['c' ]['root_symbol' ]
471
- self .env .temp_data ['c:parent_symbol' ] = symbol
472
- self .env .temp_data ['c:namespace_stack' ] = stack
468
+ self .env .current_document .c_parent_symbol = symbol
473
469
self .env .ref_context ['c:parent_key' ] = symbol .get_lookup_key ()
474
470
return []
475
471
@@ -488,9 +484,9 @@ def __init__(
488
484
self .aliasOptions = aliasOptions
489
485
self .document = document
490
486
if env is not None :
491
- if 'c:parent_symbol' not in env .temp_data :
487
+ if env .current_document . c_parent_symbol is None :
492
488
root = env .domaindata ['c' ]['root_symbol' ]
493
- env .temp_data [ 'c:parent_symbol' ] = root
489
+ env .current_document . c_parent_symbol = root
494
490
env .ref_context ['c:parent_key' ] = root .get_lookup_key ()
495
491
self .parentKey = env .ref_context ['c:parent_key' ]
496
492
else :
@@ -735,7 +731,7 @@ def run(self) -> tuple[list[Node], list[system_message]]:
735
731
# see below
736
732
node = addnodes .desc_inline ('c' , text , text , classes = [self .class_type ])
737
733
return [node ], []
738
- parent_symbol = self .env .temp_data . get ( 'c:parent_symbol' , None )
734
+ parent_symbol = self .env .current_document . c_parent_symbol
739
735
if parent_symbol is None :
740
736
parent_symbol = self .env .domaindata ['c' ]['root_symbol' ]
741
737
# ...most if not all of these classes should really apply to the individual references,
0 commit comments