librdesc
Loading...
Searching...
No Matches
Macros
cst_macros.h File Reference

Macros for accessing fields of node structs. More...

#include "detail.h"
#include <stddef.h>
Include dependency graph for cst_macros.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define rparent(p, node)    _rdesc_priv_cst_illegal_access(p, _rdesc_priv_parent_idx(node))
 Returns parent of the node, or NULL if the node is root.
 
#define rtype(node)   _rdesc_priv_node_deref(node).n.ty
 Returns node type (RDESC_TOKEN or RDESC_NONTERMINAL).
 
#define rid(node)   _rdesc_priv_node_deref(node).n.nt.id
 Returns the 16-bit identifier for underlying token/nonterminal.
 
#define ralt_idx(nt_node)    _rdesc_priv_node_deref(nt_node).n.nt.alt_idx
 Returns index of the nonterminal alternative in production rule.
 
#define ralt_id(nt_node)   ralt_idx(nt_node)
 Deprecated.
 
#define rseminfo(tk_node)    ((void *) &_rdesc_priv_node_deref(tk_node).n.tk.seminfo)
 Returns a reference to the token's seminfo field.
 
#define rchild_count(nt_node)    _rdesc_priv_node_deref(nt_node).n.nt.child_count
 Returns number of the child nodes.
 
#define rchild(p, nt_node, child_idx)    _rdesc_priv_cst_illegal_access(p, _rdesc_priv_child_idx(nt_node, child_idx))
 Returns child of the node by its index.
 

Detailed Description

Macros for accessing fields of node structs.

The parser returns opaque CST node pointers that hide memory layout details. This header provides macros to safely access node fields despite the optimized, compact memory representation.

This header undefines its own macros if it is included a second time. You can re-include this header at the end of your file to keep the macro namespace clean and prevent polluting other headers.

Macro Definition Documentation

◆ ralt_id

#define ralt_id (   nt_node)    ralt_idx(nt_node)

Deprecated.

Deprecated:
Use ralt_idx(nt_node) instead.

◆ rtype

#define rtype (   node)    _rdesc_priv_node_deref(node).n.ty

Returns node type (RDESC_TOKEN or RDESC_NONTERMINAL).

See also
enum rdesc_grammar_symbol_type