summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1ea5791)
raw | patch | inline | side by side (parent: 1ea5791)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 5 May 2015 21:33:04 +0000 (23:33 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 5 May 2015 21:33:04 +0000 (23:33 +0200) |
src/include/parser/ast.h | patch | blob | history | |
t/Makefile.am | patch | blob | history | |
t/unit/parser/ast_test.c | [new file with mode: 0644] | patch | blob |
index 3bdc5b6c1e5d69d23d96f0175b6eb6ad9136efe5..665caf50f174118efb3bd1d30590d301d43e098e 100644 (file)
--- a/src/include/parser/ast.h
+++ b/src/include/parser/ast.h
SDB_AST_CONCAT = 2005,
/* iterators */
+#define SDB_AST_IS_ITERATOR(n) \
+ (((n)->type == SDB_AST_TYPE_ITERATOR) \
+ && ((SDB_AST_ALL <= SDB_AST_ITER(n)->kind) \
+ && (SDB_AST_ITER(n)->kind <= SDB_AST_ANY)))
SDB_AST_ALL = 3000,
SDB_AST_ANY = 3001,
} sdb_ast_operator_t;
: ((op) == SDB_AST_ANY) ? "ANY" \
: "UNKNOWN")
+#define SDB_AST_TYPE_TO_STRING(n) \
+ (((n)->type == SDB_AST_TYPE_FETCH) ? "FETCH" \
+ : ((n)->type == SDB_AST_TYPE_LIST) ? "LIST" \
+ : ((n)->type == SDB_AST_TYPE_LOOKUP) ? "LOOKUP" \
+ : ((n)->type == SDB_AST_TYPE_STORE) ? "STORE" \
+ : ((n)->type == SDB_AST_TYPE_TIMESERIES) ? "TIMESERIES" \
+ : ((n)->type == SDB_AST_TYPE_OPERATOR) \
+ ? SDB_AST_OP_TO_STRING(SDB_AST_OP(n)->kind) \
+ : ((n)->type == SDB_AST_TYPE_ITERATOR) ? "ITERATOR" \
+ : ((n)->type == SDB_AST_TYPE_CONST) ? "CONSTANT" \
+ : ((n)->type == SDB_AST_TYPE_VALUE) ? "VALUE" \
+ : ((n)->type == SDB_AST_TYPE_TYPED) ? "TYPED VALUE" \
+ : "UNKNOWN")
+
/*
* sdb_ast_node_t is the interface for AST nodes. The first field of any
* actual implementation of the interface is of type sdb_ast_node_t to
sdb_ast_node_t *right;
} sdb_ast_op_t;
#define SDB_AST_OP(obj) ((sdb_ast_op_t *)(obj))
+#define SDB_AST_OP_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_OPERATOR }, -1, NULL, NULL }
/*
* sdb_ast_iter_t represents an iterator.
sdb_ast_node_t *expr;
} sdb_ast_iter_t;
#define SDB_AST_ITER(obj) ((sdb_ast_iter_t *)(obj))
+#define SDB_AST_ITER_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_ITERATOR }, -1, -1, NULL, NULL }
/*
* sdb_ast_typed_t represents a typed value.
sdb_ast_node_t *expr;
} sdb_ast_typed_t;
#define SDB_AST_TYPED(obj) ((sdb_ast_typed_t *)(obj))
+#define SDB_AST_TYPED_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_TYPED }, -1, NULL }
/*
* sdb_ast_const_t represents a constant value.
sdb_data_t value;
} sdb_ast_const_t;
#define SDB_AST_CONST(obj) ((sdb_ast_const_t *)(obj))
+#define SDB_AST_CONST_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_CONST }, SDB_DATA_INIT }
/*
* sdb_ast_value_t represents an object-specific value: sibling nodes,
char *name; /* object name; optional */
} sdb_ast_value_t;
#define SDB_AST_VALUE(obj) ((sdb_ast_value_t *)(obj))
+#define SDB_AST_VALUE_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_VALUE }, -1, NULL }
/*
* sdb_ast_fetch_t represents a FETCH command.
sdb_ast_node_t *filter; /* optional */
} sdb_ast_fetch_t;
#define SDB_AST_FETCH(obj) ((sdb_ast_fetch_t *)(obj))
+#define SDB_AST_FETCH_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_FETCH }, -1, NULL, NULL, NULL }
/*
* sdb_ast_list_t represents a LIST command.
sdb_ast_node_t *filter; /* optional */
} sdb_ast_list_t;
#define SDB_AST_LIST(obj) ((sdb_ast_list_t *)(obj))
+#define SDB_AST_LIST_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_LIST }, -1, NULL }
/*
* sdb_ast_lookup_t represents a LOOKUP command.
sdb_ast_node_t *filter; /* optional */
} sdb_ast_lookup_t;
#define SDB_AST_LOOKUP(obj) ((sdb_ast_lookup_t *)(obj))
+#define SDB_AST_LOOKUP_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_LOOKUP }, -1, NULL, NULL }
/*
* sdb_ast_store_t represents a STORE command.
sdb_data_t value;
} sdb_ast_store_t;
#define SDB_AST_STORE(obj) ((sdb_ast_store_t *)(obj))
+#define SDB_AST_STORE_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_STORE }, \
+ -1, NULL, -1, NULL, NULL, 0, NULL, NULL, SDB_DATA_INIT }
/*
* sdb_ast_timeseries_t represents a TIMESERIES command.
sdb_time_t end;
} sdb_ast_timeseries_t;
#define SDB_AST_TIMESERIES(obj) ((sdb_ast_timeseries_t *)(obj))
+#define SDB_AST_TIMESERIES_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_TIMESERIES }, NULL, NULL, 0, 0 }
/*
* AST constructors:
diff --git a/t/Makefile.am b/t/Makefile.am
index 3f1fd4bc20179d0ac8dc2f2b4da763d788b664ee..1b2960d982defe93128dcb43cad4d3d59f2d3be8 100644 (file)
--- a/t/Makefile.am
+++ b/t/Makefile.am
unit/frontend/parser_test \
unit/frontend/query_test \
unit/frontend/sock_test \
+ unit/parser/ast_test \
+ unit/parser/ast_test \
unit/parser/parser_test \
unit/utils/avltree_test \
unit/utils/channel_test \
@@ -102,6 +104,10 @@ unit_frontend_sock_test_SOURCES = $(UNIT_TEST_SOURCES) unit/frontend/sock_test.c
unit_frontend_sock_test_CFLAGS = $(UNIT_TEST_CFLAGS)
unit_frontend_sock_test_LDADD = $(UNIT_TEST_LDADD)
+unit_parser_ast_test_SOURCES = $(UNIT_TEST_SOURCES) unit/parser/ast_test.c
+unit_parser_ast_test_CFLAGS = $(UNIT_TEST_CFLAGS)
+unit_parser_ast_test_LDADD = $(UNIT_TEST_LDADD)
+
unit_parser_parser_test_SOURCES = $(UNIT_TEST_SOURCES) unit/parser/parser_test.c
unit_parser_parser_test_CFLAGS = $(UNIT_TEST_CFLAGS)
unit_parser_parser_test_LDADD = $(UNIT_TEST_LDADD)
diff --git a/t/unit/parser/ast_test.c b/t/unit/parser/ast_test.c
--- /dev/null
+++ b/t/unit/parser/ast_test.c
@@ -0,0 +1,80 @@
+/*
+ * SysDB - t/unit/parser/ast_test.c
+ * Copyright (C) 2015 Sebastian 'tokkee' Harl <sh@tokkee.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "parser/ast.h"
+#include "parser/parser.h"
+#include "testutils.h"
+
+#include <check.h>
+
+/*
+ * tests
+ */
+
+START_TEST(test_init)
+{
+ /* simple test to check that the initializers match;
+ * not all of them are used at all times */
+ sdb_ast_op_t op = SDB_AST_OP_INIT;
+ sdb_ast_iter_t iter = SDB_AST_ITER_INIT;
+ sdb_ast_typed_t typed = SDB_AST_TYPED_INIT;
+ sdb_ast_const_t constant = SDB_AST_CONST_INIT;
+ sdb_ast_value_t value = SDB_AST_VALUE_INIT;
+ sdb_ast_fetch_t fetch = SDB_AST_FETCH_INIT;
+ sdb_ast_list_t list = SDB_AST_LIST_INIT;
+ sdb_ast_lookup_t lookup = SDB_AST_LOOKUP_INIT;
+ sdb_ast_store_t store = SDB_AST_STORE_INIT;
+ sdb_ast_timeseries_t ts = SDB_AST_TIMESERIES_INIT;
+
+ /* do some (mostly) dummy operation */
+ sdb_parser_analyze(SDB_AST_NODE(&op), NULL);
+ sdb_parser_analyze(SDB_AST_NODE(&iter), NULL);
+ sdb_parser_analyze(SDB_AST_NODE(&typed), NULL);
+ sdb_parser_analyze(SDB_AST_NODE(&constant), NULL);
+ sdb_parser_analyze(SDB_AST_NODE(&value), NULL);
+ sdb_parser_analyze(SDB_AST_NODE(&fetch), NULL);
+ sdb_parser_analyze(SDB_AST_NODE(&list), NULL);
+ sdb_parser_analyze(SDB_AST_NODE(&lookup), NULL);
+ sdb_parser_analyze(SDB_AST_NODE(&store), NULL);
+ sdb_parser_analyze(SDB_AST_NODE(&ts), NULL);
+}
+END_TEST
+
+TEST_MAIN("parser::ast")
+{
+ TCase *tc = tcase_create("core");
+ tcase_add_test(tc, test_init);
+ ADD_TCASE(tc);
+}
+TEST_MAIN_END
+
+/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
+