RPNXCortado
C++23 JVM class-file, bytecode, validation, and JAR toolkit
Loading...
Searching...
No Matches
signatures.hpp
Go to the documentation of this file.
1// AI Generated 2026 Ryan P. Nicholl <rnicholl@protonmail.com>
2// SPDX-License-Identifier: Apache-2.0
3
7
8#ifndef RPNX_CORTADO_SIGNATURES_HPP
9#define RPNX_CORTADO_SIGNATURES_HPP
10
11#include <cstddef>
12#include <optional>
15#include <string>
16#include <string_view>
17#include <variant>
18#include <vector>
19
20namespace rpnx::cortado
21{
24 {
25 std::size_t maximum_nesting_depth{256};
26 std::size_t maximum_nodes{65'536};
28 };
29
30 struct class_type_signature;
31 struct type_variable_signature;
32 struct array_type_signature;
33
36 {
37 using value_type = rpnx::variant< class_type_signature, type_variable_signature, array_type_signature >;
38 value_type value;
39 RPNX_MEMBER_METADATA(reference_type_signature, value);
40 };
41
44 {
45 using value_type = rpnx::variant< primitive_type_descriptor, reference_type_signature >;
46 value_type value;
47 RPNX_MEMBER_METADATA(java_type_signature, value);
48 };
49
52 {
53 RPNX_EMPTY_METADATA(any_type_argument);
54 };
55
58 {
60 RPNX_MEMBER_METADATA(exact_type_argument, type);
61 };
62
69
72 {
74 RPNX_MEMBER_METADATA(super_type_argument, bound);
75 };
76
78 using type_argument = std::variant< any_type_argument, exact_type_argument, extends_type_argument, super_type_argument >;
79
82 {
83 std::string identifier;
84 std::vector< type_argument > arguments;
85 RPNX_MEMBER_METADATA(simple_class_type_signature, identifier, arguments);
86 };
87
90 {
91 std::string package_name;
93 std::vector< simple_class_type_signature > nested_classes;
95 };
96
99 {
100 std::string identifier;
101 RPNX_MEMBER_METADATA(type_variable_signature, identifier);
102 };
103
110
113 {
114 std::string identifier;
115 std::optional< reference_type_signature > class_bound;
116 std::vector< reference_type_signature > interface_bounds;
117 RPNX_MEMBER_METADATA(type_parameter, identifier, class_bound, interface_bounds);
118 };
119
122 {
123 std::vector< type_parameter > type_parameters;
125 std::vector< class_type_signature > superinterfaces;
127 };
128
130 using method_result_signature = std::variant< void_type_descriptor, java_type_signature >;
131
133 using throws_signature = std::variant< class_type_signature, type_variable_signature >;
134
137 {
138 std::vector< type_parameter > type_parameters;
139 std::vector< java_type_signature > parameters;
141 std::vector< throws_signature > throws_signatures;
143 };
144
151 [[nodiscard]] reference_type_signature parse_field_signature(std::string_view text, signature_parse_options const& options = {});
152
159 [[nodiscard]] class_signature parse_class_signature(std::string_view text, signature_parse_options const& options = {});
160
167 [[nodiscard]] method_signature parse_method_signature(std::string_view text, signature_parse_options const& options = {});
168
174 [[nodiscard]] std::string serialize_field_signature(reference_type_signature const& signature);
175
181 [[nodiscard]] std::string serialize_class_signature(class_signature const& signature);
182
188 [[nodiscard]] std::string serialize_method_signature(method_signature const& signature);
189} // namespace rpnx::cortado
190
191#endif // RPNX_CORTADO_SIGNATURES_HPP
Owning syntax trees and codecs for JVM field and method descriptors.
Exception types used by parsing, validation, and assembly APIs.
JVM class-file, bytecode, validation, generation, and JAR APIs.
std::variant< class_type_signature, type_variable_signature > throws_signature
A declared throws signature for a class or type-variable exception.
class_signature parse_class_signature(std::string_view text, signature_parse_options const &options={})
Parses a complete class generic signature.
std::string serialize_class_signature(class_signature const &signature)
Serializes a class generic signature.
std::variant< any_type_argument, exact_type_argument, extends_type_argument, super_type_argument > type_argument
One generic class type argument.
std::string serialize_field_signature(reference_type_signature const &signature)
Serializes a field or record-component generic signature.
method_signature parse_method_signature(std::string_view text, signature_parse_options const &options={})
Parses a complete method generic signature.
std::variant< void_type_descriptor, java_type_signature > method_result_signature
A void or Java-type method result signature.
std::string serialize_method_signature(method_signature const &signature)
Serializes a method generic signature.
reference_type_signature parse_field_signature(std::string_view text, signature_parse_options const &options={})
Parses a complete field or record-component generic signature.
An unbounded wildcard type argument.
An array whose component is another Java type signature.
java_type_signature component
Immediate array component type.
A complete class Signature attribute grammar value.
class_type_signature superclass
Generic signature of the direct superclass.
std::vector< type_parameter > type_parameters
Generic parameters declared by the class.
std::vector< class_type_signature > superinterfaces
Generic direct superinterfaces in class-file order.
A possibly parameterized and nested class type signature.
std::vector< simple_class_type_signature > nested_classes
Dot-separated nested class segments in source order.
simple_class_type_signature outer_class
First class segment after the package prefix.
std::string package_name
Slash-separated package prefix, empty for the unnamed package.
An invariant reference type argument.
reference_type_signature type
Invariant reference type following the = grammar marker.
An extends-bounded wildcard type argument.
reference_type_signature bound
Upper bound following the + grammar marker.
A primitive or reference Java type signature.
value_type value
Concrete primitive or reference alternative.
A complete method Signature attribute grammar value.
std::vector< java_type_signature > parameters
Formal parameter signatures in invocation order.
method_result_signature result
Return type or explicit void alternative.
std::vector< type_parameter > type_parameters
Generic parameters declared by the method.
std::vector< throws_signature > throws_signatures
Declared generic exception signatures.
A class, type-variable, or array reference type in a generic signature.
value_type value
Concrete class, type-variable, or array alternative.
Resource limits applied while parsing an untrusted generic signature.
std::size_t maximum_nesting_depth
Maximum recursive grammar depth accepted from untrusted input.
std::size_t maximum_nodes
Maximum syntax-tree nodes constructed by one parse.
One simple class segment, including its type arguments.
std::vector< type_argument > arguments
Generic arguments applied to this class segment.
std::string identifier
Simple class identifier without package or nesting separators.
A super-bounded wildcard type argument.
reference_type_signature bound
Lower bound following the - grammar marker.
One generic type parameter and all of its declared bounds.
std::string identifier
Declared parameter name.
std::optional< reference_type_signature > class_bound
Class bound, absent for the grammar's empty class bound.
std::vector< reference_type_signature > interface_bounds
Interface bounds in declaration order.
A generic type-variable reference.
std::string identifier
Declared type-parameter identifier without T or ; delimiters.