Compare commits
No commits in common. "main" and "1.2.2" have entirely different histories.
@ -86,8 +86,6 @@ class PlyLexer:
|
||||
"concept",
|
||||
"const",
|
||||
"constexpr",
|
||||
"consteval",
|
||||
"constinit",
|
||||
"const_cast",
|
||||
"continue",
|
||||
"decltype",
|
||||
|
@ -25,7 +25,6 @@ from .types import (
|
||||
Concept,
|
||||
DecltypeSpecifier,
|
||||
DecoratedType,
|
||||
DeductionGuide,
|
||||
EnumDecl,
|
||||
Enumerator,
|
||||
Field,
|
||||
@ -43,7 +42,6 @@ from .types import (
|
||||
Parameter,
|
||||
PQName,
|
||||
Pointer,
|
||||
PointerToMember,
|
||||
Reference,
|
||||
TemplateArgument,
|
||||
TemplateDecl,
|
||||
@ -994,9 +992,7 @@ class CxxParser:
|
||||
|
||||
self.visitor.on_using_namespace(state, names)
|
||||
|
||||
def _parse_using_declaration(
|
||||
self, tok: LexToken, doxygen: typing.Optional[str]
|
||||
) -> None:
|
||||
def _parse_using_declaration(self, tok: LexToken) -> None:
|
||||
"""
|
||||
using_declaration: "using" ["typename"] ["::"] nested_name_specifier unqualified_id ";"
|
||||
| "using" "::" unqualified_id ";"
|
||||
@ -1008,15 +1004,12 @@ class CxxParser:
|
||||
typename, _ = self._parse_pqname(
|
||||
tok, fn_ok=True, compound_ok=True, fund_ok=True
|
||||
)
|
||||
decl = UsingDecl(typename, self._current_access, doxygen)
|
||||
decl = UsingDecl(typename, self._current_access)
|
||||
|
||||
self.visitor.on_using_declaration(self.state, decl)
|
||||
|
||||
def _parse_using_typealias(
|
||||
self,
|
||||
id_tok: LexToken,
|
||||
template: typing.Optional[TemplateDecl],
|
||||
doxygen: typing.Optional[str],
|
||||
self, id_tok: LexToken, template: typing.Optional[TemplateDecl]
|
||||
) -> None:
|
||||
"""
|
||||
alias_declaration: "using" IDENTIFIER "=" type_id ";"
|
||||
@ -1030,7 +1023,7 @@ class CxxParser:
|
||||
|
||||
dtype = self._parse_cv_ptr(parsed_type)
|
||||
|
||||
alias = UsingAlias(id_tok.value, dtype, template, self._current_access, doxygen)
|
||||
alias = UsingAlias(id_tok.value, dtype, template, self._current_access)
|
||||
|
||||
self.visitor.on_using_alias(self.state, alias)
|
||||
|
||||
@ -1059,9 +1052,9 @@ class CxxParser:
|
||||
raise CxxParseError(
|
||||
"unexpected using-declaration when parsing alias-declaration", tok
|
||||
)
|
||||
self._parse_using_declaration(tok, doxygen)
|
||||
self._parse_using_declaration(tok)
|
||||
else:
|
||||
self._parse_using_typealias(tok, template, doxygen)
|
||||
self._parse_using_typealias(tok, template)
|
||||
|
||||
# All using things end with a semicolon
|
||||
self._next_token_must_be(";")
|
||||
@ -1599,7 +1592,6 @@ class CxxParser:
|
||||
fn_ok: bool = False,
|
||||
compound_ok: bool = False,
|
||||
fund_ok: bool = False,
|
||||
ptr_to_member_ok: bool = False,
|
||||
) -> typing.Tuple[PQName, typing.Optional[str]]:
|
||||
"""
|
||||
Parses a possibly qualified function name or a type name, returns when
|
||||
@ -1727,12 +1719,7 @@ class CxxParser:
|
||||
if not self.lex.token_if("DBL_COLON"):
|
||||
break
|
||||
|
||||
tok = self._next_token_must_be("NAME", "operator", "template", "decltype", "*")
|
||||
|
||||
if tok.value == '*':
|
||||
if not ptr_to_member_ok:
|
||||
raise self._parse_error(tok)
|
||||
return name, 'PTR_TO_MEMBER'
|
||||
tok = self._next_token_must_be("NAME", "operator", "template", "decltype")
|
||||
|
||||
pqname = PQName(segments, classkey, has_typename)
|
||||
|
||||
@ -1799,31 +1786,10 @@ class CxxParser:
|
||||
toks = self._consume_balanced_tokens(tok)
|
||||
self.lex.return_tokens(toks[1:-1])
|
||||
|
||||
|
||||
# optional name
|
||||
tok = self.lex.token_if("NAME", "final", "DBL_COLON")
|
||||
tok = self.lex.token_if("NAME", "final")
|
||||
if tok:
|
||||
pqname, op = self._parse_pqname(tok, fn_ok=True, ptr_to_member_ok=True)
|
||||
while op == 'PTR_TO_MEMBER':
|
||||
dtype = PointerToMember(base_type=Type(typename=pqname), ptr_to=dtype, const=dtype.const, volatile=dtype.volatile)
|
||||
# dtype = self._parse_cv_ptr(dtype)
|
||||
tok = self.lex.token_if("NAME", "final", "DBL_COLON")
|
||||
if tok:
|
||||
pqname, op = self._parse_pqname(tok, fn_ok=True, ptr_to_member_ok=True)
|
||||
else:
|
||||
pqname = None
|
||||
op = None
|
||||
if pqname:
|
||||
if len(pqname.segments) != 1:
|
||||
raise self._parse_error(None)
|
||||
param_name = pqname.segments[0].name
|
||||
|
||||
if self.lex.token_if("("):
|
||||
if isinstance(dtype, PointerToMember):
|
||||
params, vararg, at_params = self._parse_parameters(False)
|
||||
dtype.ptr_to = FunctionType(return_type=dtype.ptr_to, parameters=params, vararg=vararg)
|
||||
else:
|
||||
assert(False) # TODO
|
||||
param_name = tok.value
|
||||
|
||||
# optional array parameter
|
||||
tok = self.lex.token_if("[")
|
||||
@ -1897,9 +1863,10 @@ class CxxParser:
|
||||
_auto_return_typename = PQName([AutoSpecifier()])
|
||||
|
||||
def _parse_trailing_return_type(
|
||||
self, return_type: typing.Optional[DecoratedType]
|
||||
) -> DecoratedType:
|
||||
self, fn: typing.Union[Function, FunctionType]
|
||||
) -> None:
|
||||
# entry is "->"
|
||||
return_type = fn.return_type
|
||||
if not (
|
||||
isinstance(return_type, Type)
|
||||
and not return_type.const
|
||||
@ -1918,7 +1885,8 @@ class CxxParser:
|
||||
|
||||
dtype = self._parse_cv_ptr(parsed_type)
|
||||
|
||||
return dtype
|
||||
fn.has_trailing_return = True
|
||||
fn.return_type = dtype
|
||||
|
||||
def _parse_fn_end(self, fn: Function) -> None:
|
||||
"""
|
||||
@ -1939,15 +1907,15 @@ class CxxParser:
|
||||
else:
|
||||
rtok = self.lex.token_if("requires")
|
||||
if rtok:
|
||||
# requires on a function must always be accompanied by a template
|
||||
if fn.template is None:
|
||||
fn_template = fn.template
|
||||
if fn_template is None:
|
||||
raise self._parse_error(rtok)
|
||||
fn.raw_requires = self._parse_requires(rtok)
|
||||
elif isinstance(fn_template, list):
|
||||
fn_template = fn_template[0]
|
||||
fn_template.raw_requires_post = self._parse_requires(rtok)
|
||||
|
||||
if self.lex.token_if("ARROW"):
|
||||
return_type = self._parse_trailing_return_type(fn.return_type)
|
||||
fn.has_trailing_return = True
|
||||
fn.return_type = return_type
|
||||
self._parse_trailing_return_type(fn)
|
||||
|
||||
if self.lex.token_if("{"):
|
||||
self._discard_contents("{", "}")
|
||||
@ -1995,9 +1963,7 @@ class CxxParser:
|
||||
elif tok_value in ("&", "&&"):
|
||||
method.ref_qualifier = tok_value
|
||||
elif tok_value == "->":
|
||||
return_type = self._parse_trailing_return_type(method.return_type)
|
||||
method.has_trailing_return = True
|
||||
method.return_type = return_type
|
||||
self._parse_trailing_return_type(method)
|
||||
if self.lex.token_if("{"):
|
||||
self._discard_contents("{", "}")
|
||||
method.has_body = True
|
||||
@ -2012,7 +1978,12 @@ class CxxParser:
|
||||
toks = self._consume_balanced_tokens(otok)[1:-1]
|
||||
method.noexcept = self._create_value(toks)
|
||||
elif tok_value == "requires":
|
||||
method.raw_requires = self._parse_requires(tok)
|
||||
method_template = method.template
|
||||
if method_template is None:
|
||||
raise self._parse_error(tok)
|
||||
elif isinstance(method_template, list):
|
||||
method_template = method_template[0]
|
||||
method_template.raw_requires_post = self._parse_requires(tok)
|
||||
else:
|
||||
self.lex.return_token(tok)
|
||||
break
|
||||
@ -2031,7 +2002,6 @@ class CxxParser:
|
||||
is_friend: bool,
|
||||
is_typedef: bool,
|
||||
msvc_convention: typing.Optional[LexToken],
|
||||
is_guide: bool = False,
|
||||
) -> bool:
|
||||
"""
|
||||
Assumes the caller has already consumed the return type and name, this consumes the
|
||||
@ -2108,21 +2078,7 @@ class CxxParser:
|
||||
self.visitor.on_method_impl(state, method)
|
||||
|
||||
return method.has_body or method.has_trailing_return
|
||||
elif is_guide:
|
||||
assert isinstance(state, (ExternBlockState, NamespaceBlockState))
|
||||
if not self.lex.token_if("ARROW"):
|
||||
raise self._parse_error(None, expected="Trailing return type")
|
||||
return_type = self._parse_trailing_return_type(
|
||||
Type(PQName([AutoSpecifier()]))
|
||||
)
|
||||
guide = DeductionGuide(
|
||||
return_type,
|
||||
name=pqname,
|
||||
parameters=params,
|
||||
doxygen=doxygen,
|
||||
)
|
||||
self.visitor.on_deduction_guide(state, guide)
|
||||
return False
|
||||
|
||||
else:
|
||||
assert return_type is not None
|
||||
fn = Function(
|
||||
@ -2148,8 +2104,6 @@ class CxxParser:
|
||||
|
||||
if fn.constexpr:
|
||||
raise CxxParseError("typedef function may not be constexpr")
|
||||
if fn.consteval:
|
||||
raise CxxParseError("typedef function may not be consteval")
|
||||
if fn.extern:
|
||||
raise CxxParseError("typedef function may not be extern")
|
||||
if fn.static:
|
||||
@ -2258,9 +2212,7 @@ class CxxParser:
|
||||
assert not isinstance(dtype, FunctionType)
|
||||
dtype = dtype_fn = FunctionType(dtype, fn_params, vararg)
|
||||
if self.lex.token_if("ARROW"):
|
||||
return_type = self._parse_trailing_return_type(dtype_fn.return_type)
|
||||
dtype_fn.has_trailing_return = True
|
||||
dtype_fn.return_type = return_type
|
||||
self._parse_trailing_return_type(dtype_fn)
|
||||
|
||||
else:
|
||||
msvc_convention = None
|
||||
@ -2320,7 +2272,7 @@ class CxxParser:
|
||||
return dtype
|
||||
|
||||
# Applies to variables and return values
|
||||
_type_kwd_both = {"const", "consteval", "constexpr", "constinit", "extern", "inline", "static"}
|
||||
_type_kwd_both = {"const", "constexpr", "extern", "inline", "static"}
|
||||
|
||||
# Only found on methods
|
||||
_type_kwd_meth = {"explicit", "virtual"}
|
||||
@ -2441,7 +2393,6 @@ class CxxParser:
|
||||
destructor = False
|
||||
op = None
|
||||
msvc_convention = None
|
||||
is_guide = False
|
||||
|
||||
# If we have a leading (, that's either an obnoxious grouping
|
||||
# paren or it's a constructor
|
||||
@ -2492,32 +2443,15 @@ class CxxParser:
|
||||
# grouping paren like "void (name(int x));"
|
||||
toks = self._consume_balanced_tokens(tok)
|
||||
|
||||
# check to see if the next token is an arrow, and thus a trailing return
|
||||
if self.lex.token_peek_if("ARROW"):
|
||||
self.lex.return_tokens(toks)
|
||||
# the leading name of the class/ctor has been parsed as a type before the parens
|
||||
pqname = parsed_type.typename
|
||||
is_guide = True
|
||||
else:
|
||||
# .. not sure what it's grouping, so put it back?
|
||||
self.lex.return_tokens(toks[1:-1])
|
||||
# .. not sure what it's grouping, so put it back?
|
||||
self.lex.return_tokens(toks[1:-1])
|
||||
|
||||
if dtype:
|
||||
msvc_convention = self.lex.token_if_val(*self._msvc_conventions)
|
||||
|
||||
tok = self.lex.token_if_in_set(self._pqname_start_tokens)
|
||||
if tok:
|
||||
pqname, op = self._parse_pqname(tok, fn_ok=True, ptr_to_member_ok=True)
|
||||
while op == 'PTR_TO_MEMBER':
|
||||
dtype = PointerToMember(base_type=Type(typename=pqname), ptr_to=dtype, const=dtype.const, volatile=dtype.volatile)
|
||||
# dtype = self._parse_cv_ptr(dtype)
|
||||
tok = self.lex.token_if_in_set(self._pqname_start_tokens)
|
||||
if tok:
|
||||
pqname, op = self._parse_pqname(tok, fn_ok=True, ptr_to_member_ok=True)
|
||||
else:
|
||||
pqname = None
|
||||
op = None
|
||||
|
||||
pqname, op = self._parse_pqname(tok, fn_ok=True)
|
||||
|
||||
# TODO: "type fn(x);" is ambiguous here. Because this is a header
|
||||
# parser, we assume it's a function, not a variable declaration
|
||||
@ -2528,25 +2462,20 @@ class CxxParser:
|
||||
if not pqname:
|
||||
raise self._parse_error(None)
|
||||
|
||||
if isinstance(dtype, PointerToMember):
|
||||
params, vararg, at_params = self._parse_parameters(False)
|
||||
dtype.ptr_to = FunctionType(return_type=dtype.ptr_to, parameters=params, vararg=vararg)
|
||||
else:
|
||||
return self._parse_function(
|
||||
mods,
|
||||
dtype,
|
||||
pqname,
|
||||
op,
|
||||
template,
|
||||
doxygen,
|
||||
location,
|
||||
constructor,
|
||||
destructor,
|
||||
is_friend,
|
||||
is_typedef,
|
||||
msvc_convention,
|
||||
is_guide,
|
||||
)
|
||||
return self._parse_function(
|
||||
mods,
|
||||
dtype,
|
||||
pqname,
|
||||
op,
|
||||
template,
|
||||
doxygen,
|
||||
location,
|
||||
constructor,
|
||||
destructor,
|
||||
is_friend,
|
||||
is_typedef,
|
||||
msvc_convention,
|
||||
)
|
||||
elif msvc_convention:
|
||||
raise self._parse_error(msvc_convention)
|
||||
|
||||
|
@ -35,7 +35,6 @@ from dataclasses import dataclass, field
|
||||
from .types import (
|
||||
ClassDecl,
|
||||
Concept,
|
||||
DeductionGuide,
|
||||
EnumDecl,
|
||||
Field,
|
||||
ForwardDecl,
|
||||
@ -124,9 +123,6 @@ class NamespaceScope:
|
||||
#: Child namespaces
|
||||
namespaces: typing.Dict[str, "NamespaceScope"] = field(default_factory=dict)
|
||||
|
||||
#: Deduction guides
|
||||
deduction_guides: typing.List[DeductionGuide] = field(default_factory=list)
|
||||
|
||||
|
||||
Block = typing.Union[ClassScope, NamespaceScope]
|
||||
|
||||
@ -321,11 +317,6 @@ class SimpleCxxVisitor:
|
||||
def on_class_end(self, state: SClassBlockState) -> None:
|
||||
pass
|
||||
|
||||
def on_deduction_guide(
|
||||
self, state: SNonClassBlockState, guide: DeductionGuide
|
||||
) -> None:
|
||||
state.user_data.deduction_guides.append(guide)
|
||||
|
||||
|
||||
def parse_string(
|
||||
content: str,
|
||||
|
@ -306,7 +306,7 @@ class Array:
|
||||
"""
|
||||
|
||||
#: The type that this is an array of
|
||||
array_of: typing.Union["Array", "Pointer", "PointerToMember", Type]
|
||||
array_of: typing.Union["Array", "Pointer", Type]
|
||||
|
||||
#: Size of the array
|
||||
#:
|
||||
@ -332,7 +332,7 @@ class Pointer:
|
||||
"""
|
||||
|
||||
#: Thing that this points to
|
||||
ptr_to: typing.Union[Array, FunctionType, "Pointer", "PointerToMember", Type]
|
||||
ptr_to: typing.Union[Array, FunctionType, "Pointer", Type]
|
||||
|
||||
const: bool = False
|
||||
volatile: bool = False
|
||||
@ -356,39 +356,6 @@ class Pointer:
|
||||
else:
|
||||
return f"{ptr_to.format()}*{c}{v} {name}"
|
||||
|
||||
@dataclass
|
||||
class PointerToMember:
|
||||
"""
|
||||
Pointer to a class member. (``Class::* int``)
|
||||
"""
|
||||
|
||||
#: Thing that this points to
|
||||
base_type: Type
|
||||
ptr_to: typing.Union[Array, FunctionType, "Pointer", "PointerToMember", Type]
|
||||
|
||||
const: bool = False
|
||||
volatile: bool = False
|
||||
|
||||
def format(self) -> str:
|
||||
c = " const" if self.const else ""
|
||||
v = " volatile" if self.volatile else ""
|
||||
ptr_to = self.ptr_to
|
||||
if isinstance(ptr_to, (Array, FunctionType)):
|
||||
return ptr_to.format_decl(f"({self.base_type.format()}::*{c}{v})")
|
||||
else:
|
||||
return f"{ptr_to.format()} {self.base_type.format()}::*{c}{v}"
|
||||
|
||||
def format_decl(self, name: str):
|
||||
"""Format as a named declaration"""
|
||||
c = " const" if self.const else ""
|
||||
v = " volatile" if self.volatile else ""
|
||||
ptr_to = self.ptr_to
|
||||
if isinstance(ptr_to, (Array, FunctionType)):
|
||||
return ptr_to.format_decl(f"({self.base_type.format()}::*{c}{v} {name})")
|
||||
else:
|
||||
return f"{ptr_to.format()} {self.base_type.format()}::*{c}{v} {name}"
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class Reference:
|
||||
@ -396,7 +363,7 @@ class Reference:
|
||||
A lvalue (``&``) reference
|
||||
"""
|
||||
|
||||
ref_to: typing.Union[Array, FunctionType, Pointer, PointerToMember, Type]
|
||||
ref_to: typing.Union[Array, FunctionType, Pointer, Type]
|
||||
|
||||
def format(self) -> str:
|
||||
ref_to = self.ref_to
|
||||
@ -421,7 +388,7 @@ class MoveReference:
|
||||
An rvalue (``&&``) reference
|
||||
"""
|
||||
|
||||
moveref_to: typing.Union[Array, FunctionType, Pointer, PointerToMember, Type]
|
||||
moveref_to: typing.Union[Array, FunctionType, Pointer, Type]
|
||||
|
||||
def format(self) -> str:
|
||||
return f"{self.moveref_to.format()}&&"
|
||||
@ -435,7 +402,7 @@ class MoveReference:
|
||||
#:
|
||||
#: .. note:: There can only be one of FunctionType or Type in a DecoratedType
|
||||
#: chain
|
||||
DecoratedType = typing.Union[Array, Pointer, PointerToMember, MoveReference, Reference, Type]
|
||||
DecoratedType = typing.Union[Array, Pointer, MoveReference, Reference, Type]
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -559,6 +526,9 @@ class TemplateDecl:
|
||||
#: template <typename T> requires ...
|
||||
raw_requires_pre: typing.Optional[Value] = None
|
||||
|
||||
#: template <typename T> int main() requires ...
|
||||
raw_requires_post: typing.Optional[Value] = None
|
||||
|
||||
|
||||
#: If no template, this is None. This is a TemplateDecl if this there is a single
|
||||
#: declaration:
|
||||
@ -721,7 +691,6 @@ class Function:
|
||||
doxygen: typing.Optional[str] = None
|
||||
|
||||
constexpr: bool = False
|
||||
consteval: bool = False
|
||||
extern: typing.Union[bool, str] = False
|
||||
static: bool = False
|
||||
inline: bool = False
|
||||
@ -761,13 +730,6 @@ class Function:
|
||||
#: is the string "conversion" and the full Type is found in return_type
|
||||
operator: typing.Optional[str] = None
|
||||
|
||||
#: A requires constraint following the function declaration. If you need the
|
||||
#: prior, look at TemplateDecl.raw_requires_pre. At the moment this is just
|
||||
#: a raw value, if we interpret it in the future this will change.
|
||||
#:
|
||||
#: template <typename T> int main() requires ...
|
||||
raw_requires: typing.Optional[Value] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class Method(Function):
|
||||
@ -858,7 +820,6 @@ class Variable:
|
||||
value: typing.Optional[Value] = None
|
||||
|
||||
constexpr: bool = False
|
||||
constinit: bool = False
|
||||
extern: typing.Union[bool, str] = False
|
||||
static: bool = False
|
||||
inline: bool = False
|
||||
@ -885,7 +846,6 @@ class Field:
|
||||
bits: typing.Optional[int] = None
|
||||
|
||||
constexpr: bool = False
|
||||
constinit: bool = False
|
||||
mutable: bool = False
|
||||
static: bool = False
|
||||
inline: bool = False
|
||||
@ -906,9 +866,6 @@ class UsingDecl:
|
||||
#: If within a class, the access level for this decl
|
||||
access: typing.Optional[str] = None
|
||||
|
||||
#: Documentation if present
|
||||
doxygen: typing.Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class UsingAlias:
|
||||
@ -929,24 +886,3 @@ class UsingAlias:
|
||||
|
||||
#: If within a class, the access level for this decl
|
||||
access: typing.Optional[str] = None
|
||||
|
||||
#: Documentation if present
|
||||
doxygen: typing.Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class DeductionGuide:
|
||||
"""
|
||||
.. code-block:: c++
|
||||
|
||||
template <class T>
|
||||
MyClass(T) -> MyClass(int);
|
||||
"""
|
||||
|
||||
#: Only constructors and destructors don't have a return type
|
||||
result_type: typing.Optional[DecoratedType]
|
||||
|
||||
name: PQName
|
||||
parameters: typing.List[Parameter]
|
||||
|
||||
doxygen: typing.Optional[str] = None
|
||||
|
@ -9,7 +9,6 @@ else:
|
||||
|
||||
from .types import (
|
||||
Concept,
|
||||
DeductionGuide,
|
||||
EnumDecl,
|
||||
Field,
|
||||
ForwardDecl,
|
||||
@ -237,13 +236,6 @@ class CxxVisitor(Protocol):
|
||||
``on_variable`` for each instance declared.
|
||||
"""
|
||||
|
||||
def on_deduction_guide(
|
||||
self, state: NonClassBlockState, guide: DeductionGuide
|
||||
) -> None:
|
||||
"""
|
||||
Called when a deduction guide is encountered
|
||||
"""
|
||||
|
||||
|
||||
class NullVisitor:
|
||||
"""
|
||||
@ -326,10 +318,5 @@ class NullVisitor:
|
||||
def on_class_end(self, state: ClassBlockState) -> None:
|
||||
return None
|
||||
|
||||
def on_deduction_guide(
|
||||
self, state: NonClassBlockState, guide: DeductionGuide
|
||||
) -> None:
|
||||
return None
|
||||
|
||||
|
||||
null_visitor = NullVisitor()
|
||||
|
@ -6,7 +6,6 @@ from cxxheaderparser.types import (
|
||||
Concept,
|
||||
Function,
|
||||
FundamentalSpecifier,
|
||||
Method,
|
||||
MoveReference,
|
||||
NameSpecifier,
|
||||
PQName,
|
||||
@ -496,15 +495,15 @@ def test_requires_last_elem() -> None:
|
||||
)
|
||||
],
|
||||
template=TemplateDecl(
|
||||
params=[TemplateTypeParam(typekey="typename", name="T")]
|
||||
),
|
||||
raw_requires=Value(
|
||||
tokens=[
|
||||
Token(value="Eq"),
|
||||
Token(value="<"),
|
||||
Token(value="T"),
|
||||
Token(value=">"),
|
||||
]
|
||||
params=[TemplateTypeParam(typekey="typename", name="T")],
|
||||
raw_requires_post=Value(
|
||||
tokens=[
|
||||
Token(value="Eq"),
|
||||
Token(value="<"),
|
||||
Token(value="T"),
|
||||
Token(value=">"),
|
||||
]
|
||||
),
|
||||
),
|
||||
)
|
||||
]
|
||||
@ -753,14 +752,14 @@ def test_requires_both() -> None:
|
||||
Token(value=">"),
|
||||
]
|
||||
),
|
||||
),
|
||||
raw_requires=Value(
|
||||
tokens=[
|
||||
Token(value="Subtractable"),
|
||||
Token(value="<"),
|
||||
Token(value="T"),
|
||||
Token(value=">"),
|
||||
]
|
||||
raw_requires_post=Value(
|
||||
tokens=[
|
||||
Token(value="Subtractable"),
|
||||
Token(value="<"),
|
||||
Token(value="T"),
|
||||
Token(value=">"),
|
||||
]
|
||||
),
|
||||
),
|
||||
)
|
||||
]
|
||||
@ -792,87 +791,21 @@ def test_requires_paren() -> None:
|
||||
)
|
||||
],
|
||||
template=TemplateDecl(
|
||||
params=[TemplateTypeParam(typekey="class", name="T")]
|
||||
),
|
||||
raw_requires=Value(
|
||||
tokens=[
|
||||
Token(value="("),
|
||||
Token(value="is_purrable"),
|
||||
Token(value="<"),
|
||||
Token(value="T"),
|
||||
Token(value=">"),
|
||||
Token(value="("),
|
||||
Token(value=")"),
|
||||
Token(value=")"),
|
||||
]
|
||||
params=[TemplateTypeParam(typekey="class", name="T")],
|
||||
raw_requires_post=Value(
|
||||
tokens=[
|
||||
Token(value="("),
|
||||
Token(value="is_purrable"),
|
||||
Token(value="<"),
|
||||
Token(value="T"),
|
||||
Token(value=">"),
|
||||
Token(value="("),
|
||||
Token(value=")"),
|
||||
Token(value=")"),
|
||||
]
|
||||
),
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_non_template_requires() -> None:
|
||||
content = """
|
||||
// clang-format off
|
||||
|
||||
template <class T>
|
||||
struct Payload
|
||||
{
|
||||
constexpr Payload(T v)
|
||||
requires(std::is_pod_v<T>)
|
||||
: Value(v)
|
||||
{
|
||||
}
|
||||
};
|
||||
"""
|
||||
data = parse_string(content, cleandoc=True)
|
||||
|
||||
assert data == ParsedData(
|
||||
namespace=NamespaceScope(
|
||||
classes=[
|
||||
ClassScope(
|
||||
class_decl=ClassDecl(
|
||||
typename=PQName(
|
||||
segments=[NameSpecifier(name="Payload")], classkey="struct"
|
||||
),
|
||||
template=TemplateDecl(
|
||||
params=[TemplateTypeParam(typekey="class", name="T")]
|
||||
),
|
||||
),
|
||||
methods=[
|
||||
Method(
|
||||
return_type=None,
|
||||
name=PQName(segments=[NameSpecifier(name="Payload")]),
|
||||
parameters=[
|
||||
Parameter(
|
||||
type=Type(
|
||||
typename=PQName(
|
||||
segments=[NameSpecifier(name="T")]
|
||||
)
|
||||
),
|
||||
name="v",
|
||||
)
|
||||
],
|
||||
constexpr=True,
|
||||
has_body=True,
|
||||
raw_requires=Value(
|
||||
tokens=[
|
||||
Token(value="("),
|
||||
Token(value="std"),
|
||||
Token(value="::"),
|
||||
Token(value="is_pod_v"),
|
||||
Token(value="<"),
|
||||
Token(value="T"),
|
||||
Token(value=">"),
|
||||
Token(value=")"),
|
||||
]
|
||||
),
|
||||
access="public",
|
||||
constructor=True,
|
||||
)
|
||||
],
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
@ -1,104 +0,0 @@
|
||||
def test_constinit_consteval() -> None:
|
||||
content = """
|
||||
struct S
|
||||
{
|
||||
static constinit int i = 5;
|
||||
|
||||
static consteval int func(int i) { return i*i; }
|
||||
};
|
||||
|
||||
template<std::size_t numBits>
|
||||
consteval auto getUintType()
|
||||
{
|
||||
if constexpr (numBits == 8) {
|
||||
return std::uint8_t{};
|
||||
}
|
||||
else if constexpr (numBits == 16) {
|
||||
return std::uint16_t{};
|
||||
}
|
||||
else if constexpr (numBits == 32) {
|
||||
return std::uint32_t{};
|
||||
}
|
||||
else if constexpr (numBits == 64) {
|
||||
return std::uint64_t{};
|
||||
}
|
||||
}
|
||||
"""
|
||||
data = parse_string(content, cleandoc=True)
|
||||
|
||||
assert data == ParsedData(
|
||||
namespace=NamespaceScope(
|
||||
classes=[
|
||||
ClassScope(
|
||||
class_decl=ClassDecl(
|
||||
typename=PQName(
|
||||
segments=[NameSpecifier(name="S")], classkey="struct"
|
||||
)
|
||||
),
|
||||
fields=[
|
||||
Field(
|
||||
access="public",
|
||||
type=Type(
|
||||
typename=PQName(
|
||||
segments=[FundamentalSpecifier(name="int")]
|
||||
)
|
||||
),
|
||||
name="i",
|
||||
value=Value(tokens=[Token(value="5")]),
|
||||
constinit=True,
|
||||
static=True,
|
||||
)
|
||||
],
|
||||
methods=[
|
||||
Method(
|
||||
return_type=Type(
|
||||
typename=PQName(
|
||||
segments=[FundamentalSpecifier(name="int")]
|
||||
)
|
||||
),
|
||||
name=PQName(segments=[NameSpecifier(name="func")]),
|
||||
parameters=[
|
||||
Parameter(
|
||||
type=Type(
|
||||
typename=PQName(
|
||||
segments=[FundamentalSpecifier(name="int")]
|
||||
)
|
||||
),
|
||||
name="i",
|
||||
)
|
||||
],
|
||||
consteval=True,
|
||||
static=True,
|
||||
has_body=True,
|
||||
access="public",
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
functions=[
|
||||
Function(
|
||||
return_type=Type(typename=PQName(segments=[AutoSpecifier()])),
|
||||
name=PQName(segments=[NameSpecifier(name="getUintType")]),
|
||||
parameters=[],
|
||||
consteval=True,
|
||||
has_body=True,
|
||||
template=TemplateDecl(
|
||||
params=[
|
||||
TemplateNonTypeParam(
|
||||
type=Type(
|
||||
typename=PQName(
|
||||
segments=[
|
||||
NameSpecifier(name="std"),
|
||||
NameSpecifier(name="size_t"),
|
||||
]
|
||||
)
|
||||
),
|
||||
name="numBits",
|
||||
)
|
||||
]
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
|
@ -26,7 +26,6 @@ from cxxheaderparser.types import (
|
||||
Type,
|
||||
Typedef,
|
||||
UsingDecl,
|
||||
UsingAlias,
|
||||
Value,
|
||||
Variable,
|
||||
)
|
||||
@ -437,53 +436,3 @@ def test_doxygen_attribute() -> None:
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_doxygen_using_decl() -> None:
|
||||
content = """
|
||||
// clang-format off
|
||||
|
||||
/// Comment
|
||||
using ns::ClassName;
|
||||
"""
|
||||
data = parse_string(content, cleandoc=True)
|
||||
|
||||
assert data == ParsedData(
|
||||
namespace=NamespaceScope(
|
||||
using=[
|
||||
UsingDecl(
|
||||
typename=PQName(
|
||||
segments=[
|
||||
NameSpecifier(name="ns"),
|
||||
NameSpecifier(name="ClassName"),
|
||||
]
|
||||
),
|
||||
doxygen="/// Comment",
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_doxygen_using_alias() -> None:
|
||||
content = """
|
||||
// clang-format off
|
||||
|
||||
/// Comment
|
||||
using alias = sometype;
|
||||
"""
|
||||
data = parse_string(content, cleandoc=True)
|
||||
|
||||
assert data == ParsedData(
|
||||
namespace=NamespaceScope(
|
||||
using_alias=[
|
||||
UsingAlias(
|
||||
alias="alias",
|
||||
type=Type(
|
||||
typename=PQName(segments=[NameSpecifier(name="sometype")])
|
||||
),
|
||||
doxygen="/// Comment",
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
@ -1,188 +0,0 @@
|
||||
def test_pointer_to_member() -> None:
|
||||
content = """
|
||||
class Class
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
int Class::* intPtr;
|
||||
int (Class::* intReturnFuncPtr)();
|
||||
void (Class::* intParamFuncPtr)(int);
|
||||
void (Class::* varargFuncPtr)(...);
|
||||
|
||||
template<typename... TArgs>
|
||||
int takesFunc(void (*func)(TArgs...));
|
||||
|
||||
template<typename TObject, typename... TArgs>
|
||||
int takesMemberFunc(TObject& object, void (TObject::* func)(TArgs...));
|
||||
"""
|
||||
data = parse_string(content, cleandoc=True)
|
||||
|
||||
assert data == ParsedData(
|
||||
namespace=NamespaceScope(
|
||||
classes=[
|
||||
ClassScope(
|
||||
class_decl=ClassDecl(
|
||||
typename=PQName(
|
||||
segments=[NameSpecifier(name="Class")], classkey="class"
|
||||
)
|
||||
)
|
||||
)
|
||||
],
|
||||
functions=[
|
||||
Function(
|
||||
return_type=Type(
|
||||
typename=PQName(segments=[FundamentalSpecifier(name="int")])
|
||||
),
|
||||
name=PQName(segments=[NameSpecifier(name="takesFunc")]),
|
||||
parameters=[
|
||||
Parameter(
|
||||
type=Pointer(
|
||||
ptr_to=FunctionType(
|
||||
return_type=Type(
|
||||
typename=PQName(
|
||||
segments=[FundamentalSpecifier(name="void")]
|
||||
)
|
||||
),
|
||||
parameters=[
|
||||
Parameter(
|
||||
type=Type(
|
||||
typename=PQName(
|
||||
segments=[
|
||||
NameSpecifier(name="TArgs")
|
||||
]
|
||||
)
|
||||
),
|
||||
param_pack=True,
|
||||
)
|
||||
],
|
||||
)
|
||||
),
|
||||
name="func",
|
||||
)
|
||||
],
|
||||
template=TemplateDecl(
|
||||
params=[
|
||||
TemplateTypeParam(
|
||||
typekey="typename", name="TArgs", param_pack=True
|
||||
)
|
||||
]
|
||||
),
|
||||
),
|
||||
Function(
|
||||
return_type=Type(
|
||||
typename=PQName(segments=[FundamentalSpecifier(name="int")])
|
||||
),
|
||||
name=PQName(segments=[NameSpecifier(name="takesMemberFunc")]),
|
||||
parameters=[
|
||||
Parameter(
|
||||
type=Reference(
|
||||
ref_to=Type(
|
||||
typename=PQName(
|
||||
segments=[NameSpecifier(name="TObject")]
|
||||
)
|
||||
)
|
||||
),
|
||||
name="object",
|
||||
),
|
||||
Parameter(
|
||||
type=PointerToMember(
|
||||
base_type=Type(typename=NameSpecifier(name="TObject")),
|
||||
ptr_to=FunctionType(
|
||||
return_type=Type(
|
||||
typename=PQName(
|
||||
segments=[FundamentalSpecifier(name="void")]
|
||||
)
|
||||
),
|
||||
parameters=[
|
||||
Parameter(
|
||||
type=Type(
|
||||
typename=PQName(
|
||||
segments=[
|
||||
NameSpecifier(name="TArgs")
|
||||
]
|
||||
)
|
||||
),
|
||||
param_pack=True,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
name="func",
|
||||
),
|
||||
],
|
||||
template=TemplateDecl(
|
||||
params=[
|
||||
TemplateTypeParam(typekey="typename", name="TObject"),
|
||||
TemplateTypeParam(
|
||||
typekey="typename", name="TArgs", param_pack=True
|
||||
),
|
||||
]
|
||||
),
|
||||
),
|
||||
],
|
||||
variables=[
|
||||
Variable(
|
||||
name=PQName(segments=[NameSpecifier(name="intPtr")]),
|
||||
type=PointerToMember(
|
||||
base_type=Type(typename=NameSpecifier(name="Class")),
|
||||
ptr_to=Type(
|
||||
typename=PQName(segments=[FundamentalSpecifier(name="int")])
|
||||
),
|
||||
),
|
||||
),
|
||||
Variable(
|
||||
name=PQName(segments=[NameSpecifier(name="intReturnFuncPtr")]),
|
||||
type=PointerToMember(
|
||||
base_type=Type(typename=NameSpecifier(name="Class")),
|
||||
ptr_to=FunctionType(
|
||||
return_type=Type(
|
||||
typename=PQName(
|
||||
segments=[FundamentalSpecifier(name="int")]
|
||||
)
|
||||
),
|
||||
parameters=[],
|
||||
),
|
||||
),
|
||||
),
|
||||
Variable(
|
||||
name=PQName(segments=[NameSpecifier(name="intParamFuncPtr")]),
|
||||
type=PointerToMember(
|
||||
base_type=Type(typename=NameSpecifier(name="Class")),
|
||||
ptr_to=FunctionType(
|
||||
return_type=Type(
|
||||
typename=PQName(
|
||||
segments=[FundamentalSpecifier(name="void")]
|
||||
)
|
||||
),
|
||||
parameters=[
|
||||
Parameter(
|
||||
type=Type(
|
||||
typename=PQName(
|
||||
segments=[FundamentalSpecifier(name="int")]
|
||||
)
|
||||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Variable(
|
||||
name=PQName(segments=[NameSpecifier(name="varargFuncPtr")]),
|
||||
type=PointerToMember(
|
||||
base_type=Type(typename=NameSpecifier(name="Class")),
|
||||
ptr_to=FunctionType(
|
||||
return_type=Type(
|
||||
typename=PQName(
|
||||
segments=[FundamentalSpecifier(name="void")]
|
||||
)
|
||||
),
|
||||
parameters=[],
|
||||
vararg=True,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
|
@ -5,7 +5,6 @@ from cxxheaderparser.types import (
|
||||
BaseClass,
|
||||
ClassDecl,
|
||||
DecltypeSpecifier,
|
||||
DeductionGuide,
|
||||
Field,
|
||||
ForwardDecl,
|
||||
Function,
|
||||
@ -2164,86 +2163,3 @@ def test_member_class_template_specialization() -> None:
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_template_deduction_guide() -> None:
|
||||
content = """
|
||||
template <class CharT, class Traits = std::char_traits<CharT>>
|
||||
Error(std::basic_string_view<CharT, Traits>) -> Error<std::string>;
|
||||
"""
|
||||
data = parse_string(content, cleandoc=True)
|
||||
|
||||
assert data == ParsedData(
|
||||
namespace=NamespaceScope(
|
||||
deduction_guides=[
|
||||
DeductionGuide(
|
||||
result_type=Type(
|
||||
typename=PQName(
|
||||
segments=[
|
||||
NameSpecifier(
|
||||
name="Error",
|
||||
specialization=TemplateSpecialization(
|
||||
args=[
|
||||
TemplateArgument(
|
||||
arg=Type(
|
||||
typename=PQName(
|
||||
segments=[
|
||||
NameSpecifier(name="std"),
|
||||
NameSpecifier(
|
||||
name="string"
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
),
|
||||
name=PQName(segments=[NameSpecifier(name="Error")]),
|
||||
parameters=[
|
||||
Parameter(
|
||||
type=Type(
|
||||
typename=PQName(
|
||||
segments=[
|
||||
NameSpecifier(name="std"),
|
||||
NameSpecifier(
|
||||
name="basic_string_view",
|
||||
specialization=TemplateSpecialization(
|
||||
args=[
|
||||
TemplateArgument(
|
||||
arg=Type(
|
||||
typename=PQName(
|
||||
segments=[
|
||||
NameSpecifier(
|
||||
name="CharT"
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
),
|
||||
TemplateArgument(
|
||||
arg=Type(
|
||||
typename=PQName(
|
||||
segments=[
|
||||
NameSpecifier(
|
||||
name="Traits"
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
),
|
||||
]
|
||||
),
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
],
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user