2 Star 1 Fork 1

Chan-i / cypher_parser_demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ast.c 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
foxi 提交于 2023-03-08 11:41 . remove warnings on Darwin
#include "ast.h"
void _emit(char *s, ...)
{
#ifndef __YYEMIT
#else
va_list ap;
va_start(ap, s);
printf("rpn: ");
fprintf(stdout, s, va_arg(ap, char *));
fprintf(stdout, "\n");
fflush(stdout);
va_end(ap);
#endif
}
List *
lcons(void *datum, List *list)
{
assert(IsPointerList(list));
if (list == NIL)
list = new_list(T_List);
else
new_head_cell(list);
lfirst(list->head) = datum;
return list;
}
static List *
new_list(NodeTag type)
{
List *new_list;
ListCell *new_head;
new_head = (ListCell *)malloc(sizeof(*new_head));
new_head->next = NULL;
/* new_head->data is left undefined! */
new_list = (List *)malloc(sizeof(*new_list));
new_list->type = type;
new_list->length = 1;
new_list->head = new_head;
new_list->tail = new_head;
return new_list;
}
static void
new_head_cell(List *list)
{
ListCell *new_head;
new_head = (ListCell *)malloc(sizeof(*new_head));
new_head->next = list->head;
list->head = new_head;
list->length++;
}
static void
new_tail_cell(List *list)
{
ListCell *new_tail;
new_tail = (ListCell *)malloc(sizeof(*new_tail));
new_tail->next = NULL;
list->tail->next = new_tail;
list->tail = new_tail;
list->length++;
}
List *
lappend(List *list, void *datum)
{
assert(IsPointerList(list));
if (list == NIL)
list = new_list(T_List);
else
new_tail_cell(list);
lfirst(list->tail) = datum;
return list;
}
static void
check_list_invariants(const List *list)
{
if (list == NIL)
return;
assert(list->length > 0);
assert(list->head != NULL);
assert(list->tail != NULL);
if (list->length == 1)
assert(list->head == list->tail);
if (list->length == 2)
assert(list->head->next == list->tail);
assert(list->tail->next == NULL);
}
static void
list_free_private(List *list, bool deep)
{
ListCell *cell;
check_list_invariants(list);
cell = list_head(list);
while (cell != NULL)
{
ListCell *tmp = cell;
cell = lnext(cell);
if (deep)
FREE(lfirst(tmp));
FREE(tmp);
}
FREE(list);
}
void list_free(List *list)
{
list_free_private(list, true);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/Moeah/cypher_parser_demo.git
git@gitee.com:Moeah/cypher_parser_demo.git
Moeah
cypher_parser_demo
cypher_parser_demo
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891