pub struct CppDeclarator { /* private fields */ }Expand description
A declarator: the part that names the entity, possibly wrapped in pointers, references, arrays,
function parameter lists and template argument lists.
Implementations§
Source§impl CppDeclarator
impl CppDeclarator
Sourcepub fn get_name(&self) -> Option<CppNameToken>
pub fn get_name(&self) -> Option<CppNameToken>
The declared name.
Found among the child nodes rather than the direct tokens: a qualified or templated name
(ns::Foo<int>) is itself a node, so the identifier is one level down.
A parenthesised declarator keeps it further down still — int (*f)(int) is Declarator > Declarator > NameExpr, and the parentheses exist precisely to bind the operators to that name rather than to the
function’s. A walk that stopped at the first level answered None for every shape the language uses to
declare a function pointer: measured on int (*f)(int);, int (&f)(void); and neovim’s
static char *(names[3]) = … — three declarations that plainly name something and that
sema::scopes::is_unnamed_declaration read as “a call statement, not a declaration”.
pub fn get_name_text(&self) -> Option<String>
Sourcepub fn get_pointer_types(&self) -> Vec<CppPointerType>
pub fn get_pointer_types(&self) -> Vec<CppPointerType>
The pointer and reference types this declarator writes, its nested declarators’ included.
int* p is Declarator > Declarator > PointerType (measured), so a one-level search finds nothing; a declaration’s own
type parts are the chain of PointerType/ReferenceType/RValueReferenceType nodes under it.
Sourcepub fn is_a_reference(&self) -> bool
pub fn is_a_reference(&self) -> bool
Is this the declarator of a reference — int& r, int&& rr?
Sourcepub fn is_a_pointer(&self) -> bool
pub fn is_a_pointer(&self) -> bool
Is this the declarator of a pointer — int* p? A pointer-to-a-reference is not a C++ type, so the two answers
cannot both be true for one declarator in practice; the reference is checked first by the callers that care.
Sourcepub fn get_type_suffix(&self) -> String
pub fn get_type_suffix(&self) -> String
The declarator’s type parts, without its name: *, &, &&, [3], in source order.
What a type spelling needs from a declarator. The name is the declarator’s own and not part of the type, and the parameter list of a function declarator is a signature rather than a type.
Sourcepub fn get_declarator_text(&self) -> String
pub fn get_declarator_text(&self) -> String
The full spelling of this declarator including the name, trivia removed.
Sourcepub fn get_param_list(&self) -> Option<CppParamList>
pub fn get_param_list(&self) -> Option<CppParamList>
The parameter list, if this declarator declares a function.
§The parenthesised declarator, whose list is a sibling
void (foo) (int a, char *b); parses as
InitDeclarator "(foo) (int a, char *b)"
Declarator "(foo)"
Declarator "foo"
ParameterList "(int a, char *b)" <- beside the declarator, not inside itso the direct-child search found nothing and the declaration read as a function with no parameters. Lua
writes its whole public API that way (LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);),
and the measurements were: a Function fact with no parameter_list (the hover card printed lua_setfield(…)
and no inlay hint was placed), and its parameters filed as file-scope variables.
The guard is the *: void (*bar)(int a); has the same node shape and is a variable declared as a function
pointer, whose list belongs to the pointed-to type rather than to bar. A parenthesised declarator with a
pointer or a reference inside it is that shape, and it keeps answering None.
Sourcepub fn get_trailing_return_type(&self) -> Option<CppTypeId>
pub fn get_trailing_return_type(&self) -> Option<CppTypeId>
The trailing return type after ->, if this declarator has one.
The returned node is the TypeId inside the TrailingReturnType wrapper, so its text is the
type as written (int*) and does not include the ->.
Sourcepub fn get_pointer_type(&self) -> Option<CppPointerType>
pub fn get_pointer_type(&self) -> Option<CppPointerType>
The first pointer/reference operator, if any.
Sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Is this a function declarator?
True when there is a parameter list or a trailing return type. This is the test that decides
whether a following { is a function body or a brace initializer.
pub fn get_array_type(&self) -> Option<CppArrayType>
Sourcepub fn get_structured_binding(&self) -> Option<CppStructuredBinding>
pub fn get_structured_binding(&self) -> Option<CppStructuredBinding>
The structured binding this declarator introduces, if it is one: the [a, b] of
auto [a, b] = pair;.
Two shapes reach here, because the & of auto& [k, v] is an abstract declarator and the
pattern comes after it: the StructuredBinding is either a child of this declarator or a
child of the InitDeclarator beside it. Both are searched, so a caller asking “is this a
binding?” gets one answer rather than having to know which spelling produced the node.
Sourcepub fn is_structured_binding(&self) -> bool
pub fn is_structured_binding(&self) -> bool
Is this a structured binding declarator?
Sourcepub fn get_binding_names(&self) -> Vec<CppNameToken>
pub fn get_binding_names(&self) -> Vec<CppNameToken>
The names a structured binding introduces. Empty for an ordinary declarator.
Trait Implementations§
Source§impl Clone for CppDeclarator
impl Clone for CppDeclarator
Source§impl CppAstNode for CppDeclarator
impl CppAstNode for CppDeclarator
fn syntax(&self) -> &CppSyntaxNode
Source§fn can_cast(kind: CppSyntaxKind) -> bool
fn can_cast(kind: CppSyntaxKind) -> bool
Self? Read morefn cast(syntax: CppSyntaxNode) -> Option<Self>
Source§fn child<N: CppAstNode>(&self) -> Option<N>
fn child<N: CppAstNode>(&self) -> Option<N>
N.Source§fn token<N: CppAstToken>(&self) -> Option<N>
fn token<N: CppAstToken>(&self) -> Option<N>
N.Source§fn token_by_kind(&self, kind: CppTokenKind) -> Option<CppGeneralToken>
fn token_by_kind(&self, kind: CppTokenKind) -> Option<CppGeneralToken>
Source§fn children<N: CppAstNode>(&self) -> CppAstChildren<N> ⓘ
fn children<N: CppAstNode>(&self) -> CppAstChildren<N> ⓘ
N.Source§fn tokens<N: CppAstToken>(&self) -> CppAstTokenChildren<N> ⓘ
fn tokens<N: CppAstToken>(&self) -> CppAstTokenChildren<N> ⓘ
N.Source§fn descendants<N: CppAstNode>(&self) -> impl Iterator<Item = N>
fn descendants<N: CppAstNode>(&self) -> impl Iterator<Item = N>
N.Source§fn walk_descendants<N: CppAstNode>(&self) -> impl Iterator<Item = WalkEvent<N>>
fn walk_descendants<N: CppAstNode>(&self) -> impl Iterator<Item = WalkEvent<N>>
N, with enter/leave events.Source§fn ancestors<N: CppAstNode>(&self) -> impl Iterator<Item = N>
fn ancestors<N: CppAstNode>(&self) -> impl Iterator<Item = N>
N, innermost first.Source§fn get_root(&self) -> CppSyntaxNode
fn get_root(&self) -> CppSyntaxNode
Source§fn previous_sibling<N: CppAstNode>(&self) -> Option<N>
fn previous_sibling<N: CppAstNode>(&self) -> Option<N>
N. Read moreSource§fn next_sibling<N: CppAstNode>(&self) -> Option<N>
fn next_sibling<N: CppAstNode>(&self) -> Option<N>
N.Source§fn get_parent<N: CppAstNode>(&self) -> Option<N>
fn get_parent<N: CppAstNode>(&self) -> Option<N>
N.fn get_position(&self) -> TextSize
fn get_range(&self) -> TextRange
Source§fn get_self_or_ancestor<N: CppAstNode>(&self) -> Option<N>
fn get_self_or_ancestor<N: CppAstNode>(&self) -> Option<N>
N, starting from this node itself.Source§fn get_syntax_id(&self) -> CppSyntaxId
fn get_syntax_id(&self) -> CppSyntaxId
CppSyntaxId.Source§impl Debug for CppDeclarator
impl Debug for CppDeclarator
impl Eq for CppDeclarator
Source§impl Hash for CppDeclarator
impl Hash for CppDeclarator
Source§impl PartialEq for CppDeclarator
impl PartialEq for CppDeclarator
impl StructuralPartialEq for CppDeclarator
Auto Trait Implementations§
impl !RefUnwindSafe for CppDeclarator
impl !Send for CppDeclarator
impl !Sync for CppDeclarator
impl !UnwindSafe for CppDeclarator
impl Forget for CppDeclarator
impl Freeze for CppDeclarator
impl Move for CppDeclarator
impl Unpin for CppDeclarator
impl UnsafeUnpin for CppDeclarator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more