aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-12-13 16:07:36 +0100
committerMattias Andrée <maandree@operamail.com>2014-12-13 16:07:36 +0100
commitfc0cdca948f16bcf7590e057878fca1d4ce1ed6e (patch)
tree85702bcba4e49ede4dc8984fa0ca44ac83bc84d7
parentmds-kbdc: compile-layout: use the call-stack (diff)
downloadmds-fc0cdca948f16bcf7590e057878fca1d4ce1ed6e.tar.gz
mds-fc0cdca948f16bcf7590e057878fca1d4ce1ed6e.tar.bz2
mds-fc0cdca948f16bcf7590e057878fca1d4ce1ed6e.tar.xz
mds-kbdc: dump call-stack
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/mds-kbdc/call-stack.c34
-rw-r--r--src/mds-kbdc/call-stack.h15
-rw-r--r--src/mds-kbdc/compile-layout.c11
3 files changed, 57 insertions, 3 deletions
diff --git a/src/mds-kbdc/call-stack.c b/src/mds-kbdc/call-stack.c
index cd77b15..642988a 100644
--- a/src/mds-kbdc/call-stack.c
+++ b/src/mds-kbdc/call-stack.c
@@ -91,6 +91,40 @@ static size_t calls_ptr = 0;
/**
+ * Add “called from here”-notes
+ *
+ * @return Zero on success, -1 on error
+ */
+int mds_kbdc_call_stack_dump(void)
+{
+ char* old_pathname = result->pathname;
+ mds_kbdc_source_code_t* old_source_code = result->source_code;
+ size_t ptr = calls_ptr, iptr;
+ mds_kbdc_call_t* restrict call;
+ mds_kbdc_include_stack_t* restrict includes;
+
+ while (ptr--)
+ {
+ call = calls + ptr;
+ includes = call->include_stack;
+ iptr = includes->ptr;
+ result->pathname = iptr ? includes->stack[iptr - 1]->filename : original_pathname;
+ result->source_code = iptr ? includes->stack[iptr - 1]->source_code : original_source_code;
+ NEW_ERROR_(result, NOTE, 1, call->tree->loc_line, call->start, call->end, 1, "called from here");
+ DUMP_INCLUDE_STACK(iptr);
+ }
+
+ result->pathname = old_pathname;
+ result->source_code = old_source_code;
+ return 0;
+ fail:
+ result->pathname = old_pathname;
+ result->source_code = old_source_code;
+ return -1;
+}
+
+
+/**
* Prepare for usage of call-stacks
*
xo * @param result_ The `result` parameter of root procedure that requires the call-stack
diff --git a/src/mds-kbdc/call-stack.h b/src/mds-kbdc/call-stack.h
index aa206b3..3c010cf 100644
--- a/src/mds-kbdc/call-stack.h
+++ b/src/mds-kbdc/call-stack.h
@@ -25,6 +25,21 @@
/**
+ * Add “called from here”-notes
+ */
+#define DUMP_CALL_STACK \
+ fail_if (mds_kbdc_call_stack_dump())
+
+
+
+/**
+ * Add “called from here”-notes
+ *
+ * @return Zero on success, -1 on error
+ */
+int mds_kbdc_call_stack_dump(void);
+
+/**
* Prepare for usage of call-stacks
*
* @param result The `result` parameter of root procedure that requires the call-stack
diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c
index b2cd5e0..89f507f 100644
--- a/src/mds-kbdc/compile-layout.c
+++ b/src/mds-kbdc/compile-layout.c
@@ -17,7 +17,7 @@
*/
#include "compile-layout.h"
/* XXX fix so that for-loops do not generate the same errors/warnings in all iterations [loopy_error]. */
-/* XXX add pragma support */
+/* XXX add pragma support: mark as shadowable, stop warnings, print variable value */
#include "call-stack.h"
#include "builtin-functions.h"
@@ -49,8 +49,13 @@
* @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(NODE, SEVERITY, ...) \
- NEW_ERROR_WITH_INCLUDES(NODE, includes_ptr, SEVERITY, __VA_ARGS__)
+#define NEW_ERROR(NODE, SEVERITY, ...) \
+ do \
+ { \
+ NEW_ERROR_WITH_INCLUDES(NODE, includes_ptr, SEVERITY, __VA_ARGS__); \
+ DUMP_CALL_STACK; \
+ } \
+ while (0)
/**
* Beginning of failure clause