Types
parser types
- class cxxheaderparser.types.AnonymousName(id)
A name for an anonymous class, such as in a typedef. There is no string associated with this name, only an integer id. Things that share the same anonymous name have anonymous name instances with the same id
- Parameters:
id (
int
) –
- format()
- Return type:
str
-
id:
int
Unique id associated with this name (only unique per parser instance!)
- class cxxheaderparser.types.Array(array_of, size)
Information about an array. Multidimensional arrays are represented as an array of array.
- format()
- Return type:
str
- format_decl(name)
- Parameters:
name (
str
) –- Return type:
str
- class cxxheaderparser.types.AutoSpecifier(name='auto')
Used for an auto return type
- Parameters:
name (
str
) –
- format()
- Return type:
str
-
name:
str
= 'auto'
- class cxxheaderparser.types.BaseClass(access, typename, virtual=False, param_pack=False)
Base class declarations for a class
- Parameters:
access (
str
) –typename (
PQName
) –virtual (
bool
) –param_pack (
bool
) –
-
access:
str
access specifier for this base
-
param_pack:
bool
= False Contains a
...
-
virtual:
bool
= False Virtual inheritance
- class cxxheaderparser.types.ClassDecl(typename, bases=<factory>, template=None, explicit=False, final=False, doxygen=None, access=None)
A class is a user defined type (class/struct/union)
- Parameters:
typename (
PQName
) –bases (
List
[BaseClass
]) –template (
Union
[None
,TemplateDecl
,List
[TemplateDecl
]]) –explicit (
bool
) –final (
bool
) –doxygen (
Optional
[str
]) –access (
Optional
[str
]) –
-
access:
Optional
[str
] = None If within a class, the access level for this decl
- property classkey: str | None
-
doxygen:
Optional
[str
] = None
-
explicit:
bool
= False
-
final:
bool
= False
-
template:
Union
[None
,TemplateDecl
,List
[TemplateDecl
]] = None
- class cxxheaderparser.types.Concept(template, name, raw_constraint, doxygen=None)
Preliminary support for consuming headers that contain concepts, but not trying to actually make sense of them at this time. If this is something you care about, pull requests are welcomed!
template <class T> concept Meowable = is_meowable<T>; template<typename T> concept Addable = requires (T x) { x + x; };
- Parameters:
template (
TemplateDecl
) –name (
str
) –raw_constraint (
Value
) –doxygen (
Optional
[str
]) –
-
doxygen:
Optional
[str
] = None
-
name:
str
-
template:
TemplateDecl
- class cxxheaderparser.types.DecltypeSpecifier(tokens)
Contents of a decltype (inside the parentheses)
decltype(Foo::Bar) ~~~~~~~~
- Parameters:
tokens (
List
[Token
]) –
- format()
- Return type:
str
-
tokens:
List
[Token
] Unparsed tokens within the decltype
- cxxheaderparser.types.DecoratedType
A type or function type that is decorated with various things
Note
There can only be one of FunctionType or Type in a DecoratedType chain
alias of
Union
[Array
,Pointer
,MoveReference
,Reference
,Type
]
- class cxxheaderparser.types.DeductionGuide(result_type, name, parameters, doxygen=None)
template <class T> MyClass(T) -> MyClass(int);
- Parameters:
-
doxygen:
Optional
[str
] = None
- class cxxheaderparser.types.EnumDecl(typename, values, base=None, doxygen=None, access=None)
An enumeration type
- Parameters:
typename (
PQName
) –values (
List
[Enumerator
]) –base (
Optional
[PQName
]) –doxygen (
Optional
[str
]) –access (
Optional
[str
]) –
-
access:
Optional
[str
] = None If within a class, the access level for this decl
-
doxygen:
Optional
[str
] = None Documentation if present
-
values:
List
[Enumerator
]
- class cxxheaderparser.types.Enumerator(name, value=None, doxygen=None)
An individual value of an enumeration
- Parameters:
name (
str
) –value (
Optional
[Value
]) –doxygen (
Optional
[str
]) –
-
doxygen:
Optional
[str
] = None Documentation if present
-
name:
str
The enumerator key name
- class cxxheaderparser.types.Field(access, type, name=None, value=None, bits=None, constexpr=False, mutable=False, static=False, inline=False, doxygen=None)
A field of a class
- Parameters:
-
access:
str
public/private/protected
-
bits:
Optional
[int
] = None
-
constexpr:
bool
= False
-
doxygen:
Optional
[str
] = None
-
inline:
bool
= False
-
mutable:
bool
= False
-
name:
Optional
[str
] = None
-
static:
bool
= False
- class cxxheaderparser.types.ForwardDecl(typename, template=None, doxygen=None, enum_base=None, access=None)
Represents a forward declaration of a user defined type
- Parameters:
typename (
PQName
) –template (
Union
[None
,TemplateDecl
,List
[TemplateDecl
]]) –doxygen (
Optional
[str
]) –enum_base (
Optional
[PQName
]) –access (
Optional
[str
]) –
-
access:
Optional
[str
] = None If within a class, the access level for this decl
-
doxygen:
Optional
[str
] = None
-
enum_base:
Optional
[PQName
] = None Set if this is a forward declaration of an enum and it has a base
-
template:
Union
[None
,TemplateDecl
,List
[TemplateDecl
]] = None
- class cxxheaderparser.types.FriendDecl(cls=None, fn=None)
Represents a friend declaration – friends can only be classes or functions
- Parameters:
cls (
Optional
[ForwardDecl
]) –fn (
Optional
[Function
]) –
-
cls:
Optional
[ForwardDecl
] = None
- class cxxheaderparser.types.Function(return_type, name, parameters, vararg=False, doxygen=None, constexpr=False, extern=False, static=False, inline=False, has_body=False, has_trailing_return=False, template=None, throw=None, noexcept=None, msvc_convention=None, operator=None, raw_requires=None)
A function declaration, potentially with the function body
- Parameters:
return_type (
Union
[Array
,Pointer
,MoveReference
,Reference
,Type
,None
]) –name (
PQName
) –parameters (
List
[Parameter
]) –vararg (
bool
) –doxygen (
Optional
[str
]) –constexpr (
bool
) –extern (
Union
[bool
,str
]) –static (
bool
) –inline (
bool
) –has_body (
bool
) –has_trailing_return (
bool
) –template (
Union
[None
,TemplateDecl
,List
[TemplateDecl
]]) –throw (
Optional
[Value
]) –noexcept (
Optional
[Value
]) –msvc_convention (
Optional
[str
]) –operator (
Optional
[str
]) –raw_requires (
Optional
[Value
]) –
-
constexpr:
bool
= False
-
doxygen:
Optional
[str
] = None
-
extern:
Union
[bool
,str
] = False
-
has_body:
bool
= False If true, the body of the function is present
-
has_trailing_return:
bool
= False True if function has a trailing return type (
auto foo() -> int
). In this case, the ‘auto’ return type is removed and replaced with whatever the trailing return type was
-
inline:
bool
= False
-
msvc_convention:
Optional
[str
] = None Only set if an MSVC calling convention (__stdcall, etc) is explictly specified.
Note
If your code contains things like WINAPI, you will need to use a preprocessor to transform it to the appropriate calling convention
-
noexcept:
Optional
[Value
] = None Value of any noexcept specification for this function. The value omits the outer parentheses.
-
operator:
Optional
[str
] = None The operator type (+, +=, etc).
If this object is a Function, then this is a free operator function. If this object is a Method, then it is an operator method.
In the case of a conversion operator (such as ‘operator bool’), this is the string “conversion” and the full Type is found in return_type
-
raw_requires:
Optional
[Value
] = 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 …
-
return_type:
Union
[Array
,Pointer
,MoveReference
,Reference
,Type
,None
] Only constructors and destructors don’t have a return type
-
static:
bool
= False
-
template:
Union
[None
,TemplateDecl
,List
[TemplateDecl
]] = None
-
throw:
Optional
[Value
] = None Value of any throw specification for this function. The value omits the outer parentheses.
-
vararg:
bool
= False Set to True if ends with
...
- class cxxheaderparser.types.FunctionType(return_type, parameters, vararg=False, has_trailing_return=False, noexcept=None, msvc_convention=None)
A function type, currently only used in a function pointer
Note
There can only be one of FunctionType or Type in a DecoratedType chain
- Parameters:
- format()
- Return type:
str
- format_decl(name)
Format as a named declaration
- Parameters:
name (
str
) –- Return type:
str
-
has_trailing_return:
bool
= False True if function has a trailing return type (
auto foo() -> int
). In this case, the ‘auto’ return type is removed and replaced with whatever the trailing return type was
-
msvc_convention:
Optional
[str
] = None Only set if an MSVC calling convention (__stdcall, etc) is explictly specified.
Note
If your code contains things like WINAPI, you will need to use a preprocessor to transform it to the appropriate calling convention
-
vararg:
bool
= False Set to True if ends with
...
- class cxxheaderparser.types.FundamentalSpecifier(name)
A specifier that only contains fundamental types.
Fundamental types include various combinations of the following: unsigned, signed, short, int, long, float, double, char, bool, char16_t, char32_t, nullptr_t, wchar_t, void
- Parameters:
name (
str
) –
- format()
- Return type:
str
-
name:
str
- class cxxheaderparser.types.Method(return_type, name, parameters, vararg=False, doxygen=None, constexpr=False, extern=False, static=False, inline=False, has_body=False, has_trailing_return=False, template=None, throw=None, noexcept=None, msvc_convention=None, operator=None, raw_requires=None, access=None, const=False, volatile=False, ref_qualifier=None, constructor=False, explicit=False, default=False, deleted=False, destructor=False, pure_virtual=False, virtual=False, final=False, override=False)
A method declaration, potentially with the method body
- Parameters:
return_type (
Union
[Array
,Pointer
,MoveReference
,Reference
,Type
,None
]) –name (
PQName
) –parameters (
List
[Parameter
]) –vararg (
bool
) –doxygen (
Optional
[str
]) –constexpr (
bool
) –extern (
Union
[bool
,str
]) –static (
bool
) –inline (
bool
) –has_body (
bool
) –has_trailing_return (
bool
) –template (
Union
[None
,TemplateDecl
,List
[TemplateDecl
]]) –throw (
Optional
[Value
]) –noexcept (
Optional
[Value
]) –msvc_convention (
Optional
[str
]) –operator (
Optional
[str
]) –raw_requires (
Optional
[Value
]) –access (
Optional
[str
]) –const (
bool
) –volatile (
bool
) –ref_qualifier (
Optional
[str
]) –constructor (
bool
) –explicit (
bool
) –default (
bool
) –deleted (
bool
) –destructor (
bool
) –pure_virtual (
bool
) –virtual (
bool
) –final (
bool
) –override (
bool
) –
-
access:
Optional
[str
] = None If parsed within a class, the access level for this method
-
const:
bool
= False
-
constructor:
bool
= False
-
default:
bool
= False
-
deleted:
bool
= False
-
destructor:
bool
= False
-
explicit:
bool
= False
-
final:
bool
= False
-
override:
bool
= False
-
pure_virtual:
bool
= False
-
ref_qualifier:
Optional
[str
] = None ref-qualifier for this method, either lvalue (&) or rvalue (&&)
void foo() &&; ~~
-
virtual:
bool
= False
-
volatile:
bool
= False
- class cxxheaderparser.types.MoveReference(moveref_to)
An rvalue (
&&
) reference- Parameters:
moveref_to (
Union
[Array
,FunctionType
,Pointer
,Type
]) –
- format()
- Return type:
str
- format_decl(name)
Format as a named declaration
- Parameters:
name (
str
) –
-
moveref_to:
Union
[Array
,FunctionType
,Pointer
,Type
]
- class cxxheaderparser.types.NameSpecifier(name, specialization=None)
An individual segment of a type name
Foo::Bar ~~~
- Parameters:
name (
str
) –specialization (
Optional
[TemplateSpecialization
]) –
- format()
- Return type:
str
-
name:
str
-
specialization:
Optional
[TemplateSpecialization
] = None
- class cxxheaderparser.types.NamespaceAlias(alias, names)
A namespace alias
namespace ANS = my::ns; ~~~ ~~~~~~
- Parameters:
alias (
str
) –names (
List
[str
]) –
-
alias:
str
-
names:
List
[str
] These are the names (split by ::) for the namespace that this alias refers to, but does not include any parent namespace names. It may include a leading “::”, but does not include a following :: string.
- class cxxheaderparser.types.NamespaceDecl(names, inline=False, doxygen=None)
Namespace declarations
namespace foo::bar {} ~~~~~~~~
- Parameters:
names (
List
[str
]) –inline (
bool
) –doxygen (
Optional
[str
]) –
-
doxygen:
Optional
[str
] = None Documentation if present
-
inline:
bool
= False
-
names:
List
[str
] These are the names (split by ::) for this namespace declaration, but does not include any parent namespace names
An anonymous namespace is an empty list
- class cxxheaderparser.types.PQName(segments, classkey=None, has_typename=False)
Possibly qualified name of a C++ type.
- Parameters:
segments (
List
[Union
[AnonymousName
,FundamentalSpecifier
,NameSpecifier
,DecltypeSpecifier
,AutoSpecifier
]]) –classkey (
Optional
[str
]) –has_typename (
bool
) –
-
classkey:
Optional
[str
] = None Set if the name starts with class/enum/struct
- format()
- Return type:
str
-
has_typename:
bool
= False Set to true if the type was preceded with ‘typename’
-
segments:
List
[Union
[AnonymousName
,FundamentalSpecifier
,NameSpecifier
,DecltypeSpecifier
,AutoSpecifier
]] All of the segments of the name. This is always guaranteed to have at least one element in it. Name is segmented by ‘::’
If a name refers to the global namespace, the first segment will be an empty NameSpecifier
- class cxxheaderparser.types.Parameter(type, name=None, default=None, param_pack=False)
A parameter of a function/method
- Parameters:
- format()
- Return type:
str
-
name:
Optional
[str
] = None
-
param_pack:
bool
= False
- class cxxheaderparser.types.Pointer(ptr_to, const=False, volatile=False)
A pointer
- Parameters:
ptr_to (
Union
[Array
,FunctionType
,Pointer
,Type
]) –const (
bool
) –volatile (
bool
) –
-
const:
bool
= False
- format()
- Return type:
str
- format_decl(name)
Format as a named declaration
- Parameters:
name (
str
) –
-
ptr_to:
Union
[Array
,FunctionType
,Pointer
,Type
] Thing that this points to
-
volatile:
bool
= False
- class cxxheaderparser.types.Reference(ref_to)
A lvalue (
&
) reference- Parameters:
ref_to (
Union
[Array
,FunctionType
,Pointer
,Type
]) –
- format()
- Return type:
str
- format_decl(name)
Format as a named declaration
- Parameters:
name (
str
) –
-
ref_to:
Union
[Array
,FunctionType
,Pointer
,Type
]
- class cxxheaderparser.types.TemplateArgument(arg, param_pack=False)
A single argument for a template specialization
Foo<int, Bar...> ~~~
- Parameters:
arg (
Union
[Array
,Pointer
,MoveReference
,Reference
,Type
,FunctionType
,Value
]) –param_pack (
bool
) –
-
arg:
Union
[Array
,Pointer
,MoveReference
,Reference
,Type
,FunctionType
,Value
] If this argument is a type, it is stored here as a DecoratedType, otherwise it’s stored as an unparsed set of values
- format()
- Return type:
str
-
param_pack:
bool
= False
- class cxxheaderparser.types.TemplateDecl(params=<factory>, raw_requires_pre=None)
Template declaration for a function or class
template <typename T> class Foo {}; template <typename T> T fn();
- Parameters:
params (
List
[Union
[TemplateNonTypeParam
,TemplateTypeParam
]]) –raw_requires_pre (
Optional
[Value
]) –
-
params:
List
[Union
[TemplateNonTypeParam
,TemplateTypeParam
]]
- cxxheaderparser.types.TemplateDeclTypeVar
If no template, this is None. This is a TemplateDecl if this there is a single declaration:
template <typename T> struct C {};
If there are multiple template declarations, then this is a list of declarations in the order that they’re encountered:
template<> template<class U> struct A<char>::C {};
alias of
Union
[None
,TemplateDecl
,List
[TemplateDecl
]]
- class cxxheaderparser.types.TemplateInst(typename, extern, doxygen=None)
Explicit template instantiation
template class MyClass<1,2>; extern template class MyClass<2,3>;
- Parameters:
typename (
PQName
) –extern (
bool
) –doxygen (
Optional
[str
]) –
-
doxygen:
Optional
[str
] = None
-
extern:
bool
- class cxxheaderparser.types.TemplateNonTypeParam(type, name=None, default=None, param_idx=None, param_pack=False)
template <int T> ~~~~~ template <class T, typename T::type* U> ~~~~~~~~~~~~~~~~~~~ template <auto T> ~~~~~~ // abbreviated template parameters are converted to this and param_idx is set void fn(C auto p) ~~~~~~
- Parameters:
-
name:
Optional
[str
] = None
-
param_idx:
Optional
[int
] = None If this was promoted, the parameter index that this corresponds with
-
param_pack:
bool
= False Contains a
...
- cxxheaderparser.types.TemplateParam
A parameter for a template declaration
template <typename T> ~~~~~~~~~~
alias of
Union
[TemplateNonTypeParam
,TemplateTypeParam
]
- class cxxheaderparser.types.TemplateSpecialization(args)
Contains the arguments of a template specialization
Foo<int, Bar...> ~~~~~~~~~~~
- Parameters:
args (
List
[TemplateArgument
]) –
-
args:
List
[TemplateArgument
]
- format()
- Return type:
str
- class cxxheaderparser.types.TemplateTypeParam(typekey, name=None, param_pack=False, default=None, template=None)
template <typename T> ~~~~~~~~~~
- Parameters:
typekey (
str
) –name (
Optional
[str
]) –param_pack (
bool
) –default (
Optional
[Value
]) –template (
Optional
[TemplateDecl
]) –
-
name:
Optional
[str
] = None
-
param_pack:
bool
= False
-
template:
Optional
[TemplateDecl
] = None A template-template param
-
typekey:
str
‘typename’ or ‘class’
- class cxxheaderparser.types.Type(typename, const=False, volatile=False)
A type with a name associated with it
- Parameters:
typename (
PQName
) –const (
bool
) –volatile (
bool
) –
-
const:
bool
= False
- format()
- Return type:
str
- format_decl(name)
Format as a named declaration
- Parameters:
name (
str
) –
-
volatile:
bool
= False
- class cxxheaderparser.types.Typedef(type, name, access=None)
A typedef specifier. A unique typedef specifier is created for each alias created by the typedef.
typedef type name, *pname;
- Parameters:
type (
Union
[Array
,Pointer
,MoveReference
,Reference
,Type
,FunctionType
]) –name (
str
) –access (
Optional
[str
]) –
-
access:
Optional
[str
] = None If within a class, the access level for this decl
-
name:
str
The alias introduced for the specified type
typedef type *pname; ~~~~~
-
type:
Union
[Array
,Pointer
,MoveReference
,Reference
,Type
,FunctionType
] The aliased type or function type
typedef type *pname; ~~~~~~
- class cxxheaderparser.types.UsingAlias(alias, type, template=None, access=None, doxygen=None)
using foo = int; template <typename T> using VectorT = std::vector<T>;
- Parameters:
alias (
str
) –type (
Union
[Array
,Pointer
,MoveReference
,Reference
,Type
]) –template (
Optional
[TemplateDecl
]) –access (
Optional
[str
]) –doxygen (
Optional
[str
]) –
-
access:
Optional
[str
] = None If within a class, the access level for this decl
-
alias:
str
-
doxygen:
Optional
[str
] = None Documentation if present
-
template:
Optional
[TemplateDecl
] = None
- class cxxheaderparser.types.UsingDecl(typename, access=None, doxygen=None)
using NS::ClassName;
- Parameters:
typename (
PQName
) –access (
Optional
[str
]) –doxygen (
Optional
[str
]) –
-
access:
Optional
[str
] = None If within a class, the access level for this decl
-
doxygen:
Optional
[str
] = None Documentation if present
- class cxxheaderparser.types.Value(tokens)
A unparsed list of tokens
int x = 0x1337; ~~~~~~
- Parameters:
tokens (
List
[Token
]) –
- format()
- Return type:
str
-
tokens:
List
[Token
] Tokens corresponding to the value
- class cxxheaderparser.types.Variable(name, type, value=None, constexpr=False, extern=False, static=False, inline=False, template=None, doxygen=None)
A variable declaration
- Parameters:
name (
PQName
) –type (
Union
[Array
,Pointer
,MoveReference
,Reference
,Type
]) –value (
Optional
[Value
]) –constexpr (
bool
) –extern (
Union
[bool
,str
]) –static (
bool
) –inline (
bool
) –template (
Optional
[TemplateDecl
]) –doxygen (
Optional
[str
]) –
-
constexpr:
bool
= False
-
doxygen:
Optional
[str
] = None
-
extern:
Union
[bool
,str
] = False
-
inline:
bool
= False
-
static:
bool
= False
-
template:
Optional
[TemplateDecl
] = None Can occur for a static variable for a templated class
exceptions
- exception cxxheaderparser.errors.CxxParseError(msg, tok=None)
Exception raised when a parsing error occurs
- Parameters:
msg (
str
) –tok (
Optional
[LexToken
]) –