#include <stdlib.h>
#include <string.h>
#include "ast.h"
#include "types/token.h"
Go to the source code of this file.
◆ _JSON_PRINT_FIELD
#define _JSON_PRINT_FIELD |
( |
| level, |
|
|
| name, |
|
|
| fmt, |
|
|
| ... ) |
Value: _print_at_level(file, level, "\"" name "\": "); \
fprintf(file, fmt, __VA_ARGS__);
Definition at line 76 of file ast.c.
76#define _JSON_PRINT_FIELD(level, name, fmt, ...) \
77 _print_at_level(file, level, "\"" name "\": "); \
78 fprintf(file, fmt, __VA_ARGS__);
◆ ast_add_children()
Add a new children for the given AST node.
- Parameters
-
parent | The node parent where the new children will be added. |
type | Type of the node. |
token | Token to set for the new children node. |
- Returns
- Pointer for the new children on parent.
Definition at line 40 of file ast.c.
41{
42 _ast_ensure_children_size(parent);
43
46
47 return child;
48}
void ast_node_init(ast_node_t *node, ast_node_t *parent, node_type_t type, token_t *token)
Initializes an AST node.
unsigned int children_count
struct ast_node * children
struct ast_node ast_node_t
◆ ast_close()
Closes the given AST root node and all children.
- Parameters
-
Definition at line 29 of file ast.c.
30{
33 }
34
37}
void ast_close(ast_node_t *root)
Closes the given AST root node and all children.
◆ ast_copy()
Copies the content of source
to destinty
AST nodes.
- Parameters
-
destiny | Where to copy the node data. |
source | The node data that will be copied. |
Definition at line 64 of file ast.c.
◆ ast_insert_children()
Insert a exitent AST node as children of the given parent node.
It's copies the content of the given child
for the new children on parent
node.
- Parameters
-
parent | The parent where to insert the child. |
child | The child to insert as parent's children. |
- Returns
- Pointer for the new children on parent.
Definition at line 51 of file ast.c.
52{
53 _ast_ensure_children_size(parent);
54
56
58 new_child->
parent = parent;
59
60 return new_child;
61}
void ast_copy(ast_node_t *destiny, ast_node_t *source)
Copies the content of source to destinty AST nodes.
◆ ast_node_init()
Initializes an AST node.
- Parameters
-
node | The node to be initialized. |
parent | Parent node of the given node. |
type | Type of the node. |
token | Token of the given node. |
Definition at line 17 of file ast.c.
18{
22
26}
unsigned int _children_length
#define AST_INITIAL_CHILDREN_LENGTH
◆ ast_to_json()
void ast_to_json |
( |
ast_node_t * | root, |
|
|
FILE * | file ) |
Reads the AST and converts it to JSON, writting on the given file stream.
- Parameters
-
root | The root of the AST. |
file | The file where to write the JSON. |
Definition at line 70 of file ast.c.
71{
72 _ast_to_json_aux(root, file, 0);
73 fputc('\n', file);
74}