未验证 提交 bb61cc0d 编写于 作者: A Alexander Smorkalov 提交者: GitHub

Merge pull request #23954 from VadimLevin:dev/vlevin/matrix-type-constants-stubs

feat: add matrix type stubs generation
...@@ -4,11 +4,13 @@ __all__ = [ ...@@ -4,11 +4,13 @@ __all__ = [
from typing import Sequence, Callable from typing import Sequence, Callable
from .nodes import NamespaceNode, FunctionNode, OptionalTypeNode, ClassProperty, PrimitiveTypeNode from .nodes import (NamespaceNode, FunctionNode, OptionalTypeNode,
ClassProperty, PrimitiveTypeNode)
from .ast_utils import find_function_node, SymbolName from .ast_utils import find_function_node, SymbolName
def apply_manual_api_refinement(root: NamespaceNode) -> None: def apply_manual_api_refinement(root: NamespaceNode) -> None:
export_matrix_type_constants(root)
# Export OpenCV exception class # Export OpenCV exception class
builtin_exception = root.add_class("Exception") builtin_exception = root.add_class("Exception")
builtin_exception.is_exported = False builtin_exception.is_exported = False
...@@ -17,6 +19,33 @@ def apply_manual_api_refinement(root: NamespaceNode) -> None: ...@@ -17,6 +19,33 @@ def apply_manual_api_refinement(root: NamespaceNode) -> None:
refine_symbol(root, symbol_name) refine_symbol(root, symbol_name)
def export_matrix_type_constants(root: NamespaceNode) -> None:
MAX_PREDEFINED_CHANNELS = 4
depth_names = ("CV_8U", "CV_8S", "CV_16U", "CV_16S", "CV_32S",
"CV_32F", "CV_64F", "CV_16F")
for depth_value, depth_name in enumerate(depth_names):
# Export depth constants
root.add_constant(depth_name, str(depth_value))
# Export predefined types
for c in range(MAX_PREDEFINED_CHANNELS):
root.add_constant(f"{depth_name}C{c + 1}",
f"{depth_value + 8 * c}")
# Export type creation function
root.add_function(
f"{depth_name}C",
(FunctionNode.Arg("channels", PrimitiveTypeNode.int_()), ),
FunctionNode.RetType(PrimitiveTypeNode.int_())
)
# Export CV_MAKETYPE
root.add_function(
"CV_MAKETYPE",
(FunctionNode.Arg("depth", PrimitiveTypeNode.int_()),
FunctionNode.Arg("channels", PrimitiveTypeNode.int_())),
FunctionNode.RetType(PrimitiveTypeNode.int_())
)
def make_optional_arg(arg_name: str) -> Callable[[NamespaceNode, SymbolName], None]: def make_optional_arg(arg_name: str) -> Callable[[NamespaceNode, SymbolName], None]:
def _make_optional_arg(root_node: NamespaceNode, def _make_optional_arg(root_node: NamespaceNode,
function_symbol_name: SymbolName) -> None: function_symbol_name: SymbolName) -> None:
......
...@@ -103,9 +103,6 @@ def _generate_typing_stubs(root: NamespaceNode, output_path: Path) -> None: ...@@ -103,9 +103,6 @@ def _generate_typing_stubs(root: NamespaceNode, output_path: Path) -> None:
_write_reexported_symbols_section(root, output_stream) _write_reexported_symbols_section(root, output_stream)
# Write constants section, because constants don't impose any dependencies
_generate_section_stub(StubSection("# Constants", ConstantNode), root,
output_stream, 0)
# NOTE: Enumerations require special handling, because all enumeration # NOTE: Enumerations require special handling, because all enumeration
# constants are exposed as module attributes # constants are exposed as module attributes
has_enums = _generate_section_stub(StubSection("# Enumerations", EnumerationNode), has_enums = _generate_section_stub(StubSection("# Enumerations", EnumerationNode),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册