tools/net/sunrpc/xdrgen/generators/typedef.py
Source file repositories/reference/linux-study-clean/tools/net/sunrpc/xdrgen/generators/typedef.py
File Facts
- System
- Linux kernel
- Corpus path
tools/net/sunrpc/xdrgen/generators/typedef.py- Extension
.py- Size
- 10334 bytes
- Lines
- 272
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/usr/bin/env python3
# ex: set filetype=python:
"""Generate code to handle XDR typedefs"""
from jinja2 import Environment
from generators import SourceGenerator, kernel_c_type
from generators import create_jinja2_environment, get_jinja2_template
from xdr_ast import _XdrBasic, _XdrTypedef, _XdrString
from xdr_ast import _XdrFixedLengthOpaque, _XdrVariableLengthOpaque
from xdr_ast import _XdrFixedLengthArray, _XdrVariableLengthArray
from xdr_ast import _XdrOptionalData, _XdrVoid, _XdrDeclaration
from xdr_ast import public_apis, get_header_name
def emit_typedef_declaration(environment: Environment, node: _XdrDeclaration) -> None:
"""Emit a declaration pair for one XDR typedef"""
if node.name not in public_apis:
return
if isinstance(node, _XdrBasic):
template = get_jinja2_template(environment, "declaration", node.template)
print(
template.render(
name=node.name,
type=kernel_c_type(node.spec),
classifier=node.spec.c_classifier,
)
)
elif isinstance(node, _XdrString):
template = get_jinja2_template(environment, "declaration", node.template)
print(template.render(name=node.name))
elif isinstance(node, _XdrFixedLengthOpaque):
template = get_jinja2_template(environment, "declaration", node.template)
print(template.render(name=node.name, size=node.size))
elif isinstance(node, _XdrVariableLengthOpaque):
template = get_jinja2_template(environment, "declaration", node.template)
print(template.render(name=node.name))
elif isinstance(node, _XdrFixedLengthArray):
template = get_jinja2_template(environment, "declaration", node.template)
print(
template.render(
name=node.name,
type=node.spec.type_name,
size=node.size,
)
)
elif isinstance(node, _XdrVariableLengthArray):
template = get_jinja2_template(environment, "declaration", node.template)
print(
template.render(
name=node.name,
type=node.spec.type_name,
classifier=node.spec.c_classifier,
)
)
elif isinstance(node, _XdrOptionalData):
raise NotImplementedError("<optional_data> typedef not yet implemented")
elif isinstance(node, _XdrVoid):
raise ValueError("invalid void usage in RPC Specification")
else:
raise NotImplementedError("typedef: type not recognized")
def emit_type_definition(environment: Environment, node: _XdrDeclaration) -> None:
"""Emit a definition for one XDR typedef"""
if isinstance(node, _XdrBasic):
template = get_jinja2_template(environment, "definition", node.template)
print(
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.