xref: /linux/tools/net/sunrpc/xdrgen/generators/constant.py (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1#!/usr/bin/env python3
2# ex: set filetype=python:
3
4"""Generate code to handle XDR constants"""
5
6from generators import SourceGenerator, create_jinja2_environment
7from xdr_ast import _XdrConstant
8
9class XdrConstantGenerator(SourceGenerator):
10    """Generate source code for XDR constants"""
11
12    def __init__(self, language: str, peer: str):
13        """Initialize an instance of this class"""
14        self.environment = create_jinja2_environment(language, "constants")
15        self.peer = peer
16
17    def emit_definition(self, node: _XdrConstant) -> None:
18        """Emit one definition for a constant"""
19        template = self.environment.get_template("definition.j2")
20        print(template.render(name=node.name, value=node.value))
21