aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-kbdc/include-stack.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-12-02 11:01:41 +0100
committerMattias Andrée <maandree@operamail.com>2014-12-02 11:01:41 +0100
commit4da19d37e78c92ed08d616a1b2331b2c9ce55a37 (patch)
tree24758b614c3503fa846867abdaaeabe03c8743ce /src/mds-kbdc/include-stack.h
parentmds-kbdc: dead code elimination (diff)
downloadmds-4da19d37e78c92ed08d616a1b2331b2c9ce55a37.tar.gz
mds-4da19d37e78c92ed08d616a1b2331b2c9ce55a37.tar.bz2
mds-4da19d37e78c92ed08d616a1b2331b2c9ce55a37.tar.xz
mds-kbdc: split out and dedup include stack
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-kbdc/include-stack.h')
-rw-r--r--src/mds-kbdc/include-stack.h118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/mds-kbdc/include-stack.h b/src/mds-kbdc/include-stack.h
new file mode 100644
index 0000000..2c9fce8
--- /dev/null
+++ b/src/mds-kbdc/include-stack.h
@@ -0,0 +1,118 @@
+/**
+ * mds — A micro-display server
+ * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef MDS_MDS_KBDC_INCLUDE_STACK_H
+#define MDS_MDS_KBDC_INCLUDE_STACK_H
+
+
+#include "parsed.h"
+
+
+
+/**
+ * Add an error to the error list
+ *
+ * @param NODE:const mds_kbdc_tree_t* The node the triggered the error
+ * @param SEVERITY:identifier * in `MDS_KBDC_PARSE_ERROR_*` to indicate severity
+ * @param ...:const char*, ... Error description format string and arguments
+ * @scope error:mds_kbdc_parse_error_t* Variable where the new error will be stored
+ */
+#define NEW_ERROR_WITHOUT_INCLUDES(NODE, SEVERITY, ...) \
+ NEW_ERROR_(result, SEVERITY, 1, (NODE)->loc_line, \
+ (NODE)->loc_start, (NODE)->loc_end, 1, __VA_ARGS__)
+
+/**
+ * Add “included from here”-notes
+ *
+ * @param PTR:size_t The number of “included from here”-notes
+ */
+#define DUMP_INCLUDE_STACK(PTR) \
+ fail_if (mds_kbdc_include_stack_dump(PTR))
+
+/**
+ * Add an error with “included from here”-notes to the error list
+ *
+ * @param NODE:const mds_kbdc_tree_t* The node the triggered the error
+ * @param PTR:size_t The number of “included from here”-notes
+ * @param SEVERITY:identifier * in `MDS_KBDC_PARSE_ERROR_*` to indicate severity
+ * @param ...:const char*, ... Error description format string and arguments
+ * @scope error:mds_kbdc_parse_error_t* Variable where the new error will be stored
+ */
+#define NEW_ERROR_WITH_INCLUDES(NODE, PTR, SEVERITY, ...) \
+ do \
+ { \
+ NEW_ERROR_WITHOUT_INCLUDES(NODE, SEVERITY, __VA_ARGS__); \
+ DUMP_INCLUDE_STACK(PTR); \
+ } \
+ while (0)
+
+
+
+/**
+ * The number elements stored by `mds_kbdc_include_stack_push`
+ * but not removed by `mds_kbdc_include_stack_pop`
+ */
+extern size_t includes_ptr;
+
+
+
+/**
+ * Add “included from here”-notes
+ *
+ * @param ptr The number of “included from here”-notes
+ * @return Zero on success, -1 on error
+ */
+int mds_kbdc_include_stack_dump(size_t ptr);
+
+/**
+ * Mark the root of the tree as included
+ *
+ * @param result The `result` parameter of root procedure that requires the include stack
+ */
+void mds_kbdc_include_stack_begin(mds_kbdc_parsed_t* restrict result);
+
+/**
+ * Mark the root of the tree as no longer being visited,
+ * and release clean up after the use of this module
+ *
+ * This function is guaranteed not to modify `errno`
+ */
+void mds_kbdc_include_stack_end(void);
+
+/**
+ * Mark an include-statement as visited
+ *
+ * @param tree The visisted include-statement
+ * @param data Output parameter with stack information that should be passed to
+ * the corresponding call to `mds_kbdc_include_stack_pop`, `*data`
+ * is undefined on error
+ * @return Zero on success, -1 on error
+ */
+int mds_kbdc_include_stack_push(mds_kbdc_tree_include_t* restrict tree, void** data);
+
+/**
+ * Undo the lasted not-undone call to `mds_kbdc_include_stack_push`
+ *
+ * This function is guaranteed not to modify `errno`
+ *
+ * @param data `*data` from `mds_kbdc_include_stack_push`
+ */
+void mds_kbdc_include_stack_pop(void* data);
+
+
+#endif
+