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 15-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.

Definition in file cst_macros.h.

Macro Definition Documentation

◆ ralt_id

#define ralt_id (   nt_node)    ralt_idx(nt_node)

Deprecated.

Deprecated:
Use ralt_idx(nt_node) instead.

Definition at line 92 of file cst_macros.h.

◆ ralt_idx

#define ralt_idx (   nt_node)     _rdesc_priv_node_deref(nt_node).n.nt.alt_idx

Returns index of the nonterminal alternative in production rule.

Available only for nonterminals.

Definition at line 84 of file cst_macros.h.

◆ rchild

#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.

Available only for nonterminals.

Definition at line 115 of file cst_macros.h.

◆ rchild_count

#define rchild_count (   nt_node)     _rdesc_priv_node_deref(nt_node).n.nt.child_count

Returns number of the child nodes.

Available only for nonterminals.

Definition at line 107 of file cst_macros.h.

◆ rid

#define rid (   node)    _rdesc_priv_node_deref(node).n.nt.id

Returns the 15-bit identifier for underlying token/nonterminal.

Can be used both for tokens and nonterminals.

Definition at line 77 of file cst_macros.h.

◆ rparent

#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.

Can be used both for tokens and nonterminals.

Definition at line 60 of file cst_macros.h.

◆ rseminfo

#define rseminfo (   tk_node)     ((void *) &_rdesc_priv_node_deref(tk_node).n.tk.seminfo)

Returns a reference to the token's seminfo field.

Available only for tokens.

Definition at line 99 of file cst_macros.h.

◆ rtype

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

Returns node type (RDESC_TOKEN or RDESC_NONTERMINAL).

Can be used both for tokens and nonterminals.

See also
enum rdesc_grammar_symbol_type

Definition at line 70 of file cst_macros.h.