diff options
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | src/mds-kbdc/mds-kbdc.c | 16 | ||||
-rw-r--r-- | src/mds-kbdc/process-includes.c | 57 | ||||
-rw-r--r-- | src/mds-kbdc/process-includes.h | 35 | ||||
-rw-r--r-- | src/mds-kbdc/tree.c | 13 | ||||
-rw-r--r-- | src/mds-kbdc/tree.h | 7 | ||||
-rw-r--r-- | test-files/mds-kbdc/make-tree/valid/include | 4 |
7 files changed, 122 insertions, 13 deletions
@@ -31,7 +31,8 @@ OBJ_mds-registry_ = mds-registry util globals reexec registry signals \ slave OBJ_mds-kbdc_ = mds-kbdc globals raw-data functions string tree \ - make-tree parse-error simplify-tree parsed + make-tree parse-error simplify-tree parsed \ + process-includes OBJ_mds-server = $(foreach O,$(OBJ_mds-server_),obj/mds-server/$(O).o) OBJ_mds-registry = $(foreach O,$(OBJ_mds-registry_),obj/mds-registry/$(O).o) diff --git a/src/mds-kbdc/mds-kbdc.c b/src/mds-kbdc/mds-kbdc.c index 55e3587..a2b5b70 100644 --- a/src/mds-kbdc/mds-kbdc.c +++ b/src/mds-kbdc/mds-kbdc.c @@ -39,6 +39,11 @@ */ int main(int argc_, char** argv_) { +#define process(expr) \ + fail_if ((expr) < 0); \ + if (fatal = mds_kbdc_parsed_is_fatal(&result), fatal) \ + goto stop; + mds_kbdc_parsed_t result; int fatal; @@ -46,10 +51,12 @@ int main(int argc_, char** argv_) argv = argv_; mds_kbdc_parsed_initialise(&result); - fail_if (parse_to_tree(argv[1], &result) < 0); - if (fatal = mds_kbdc_parsed_is_fatal(&result), fatal) - goto stop; - fail_if (simplify_tree(&result) < 0); + process (parse_to_tree(argv[1], &result)); + //process (simplify_tree(&result)); + //process (process_includes(&result)); + /* TODO process (validate_tree(&result)); */ + /* TODO process (eliminate_dead_code(&result)); */ + /* TODO process (compile_layout(&result)); */ stop: mds_kbdc_tree_print(result.tree, stderr); mds_kbdc_parsed_print_errors(&result, stderr); @@ -60,5 +67,6 @@ int main(int argc_, char** argv_) xperror(*argv); mds_kbdc_parsed_destroy(&result); return 1; +#undef process } diff --git a/src/mds-kbdc/process-includes.c b/src/mds-kbdc/process-includes.c new file mode 100644 index 0000000..0b068f1 --- /dev/null +++ b/src/mds-kbdc/process-includes.c @@ -0,0 +1,57 @@ +/** + * 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/>. + */ +#include "process-includes.h" + + + +/** + * Add an error the to 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(NODE, SEVERITY, ...) \ + NEW_ERROR_(result, SEVERITY, 1, (NODE)->loc_line, \ + (NODE)->loc_start, (NODE)->loc_end, 1, __VA_ARGS__) + + + +/** + * Variable whether the latest created error is stored + */ +static mds_kbdc_parse_error_t* error; + + + +/** + * Include included files and process them upto this level + * + * @param result `result` from `simplify_tree`, will be updated + * @return -1 if an error occursed that cannot be stored in `result`, zero otherwise + */ +int process_includes(mds_kbdc_parsed_t* restrict result) +{ + return 0; +} + + + +#undef NEW_ERROR + diff --git a/src/mds-kbdc/process-includes.h b/src/mds-kbdc/process-includes.h new file mode 100644 index 0000000..f9817c6 --- /dev/null +++ b/src/mds-kbdc/process-includes.h @@ -0,0 +1,35 @@ +/** + * 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_PROCESS_INCLUDES_H +#define MDS_MDS_KBDC_PROCESS_INCLUDES_H + + +#include "parsed.h" + + +/** + * Include included files and process them upto this level + * + * @param result `result` from `simplify_tree`, will be updated + * @return -1 if an error occursed that cannot be stored in `result`, zero otherwise + */ +int process_includes(mds_kbdc_parsed_t* restrict result); + + +#endif + diff --git a/src/mds-kbdc/tree.c b/src/mds-kbdc/tree.c index df94a97..695a8a7 100644 --- a/src/mds-kbdc/tree.c +++ b/src/mds-kbdc/tree.c @@ -94,23 +94,24 @@ static void mds_kbdc_tree_destroy_(mds_kbdc_tree_t* restrict this, int recursive case C(ALTERNATION): case C(UNORDERED): case C(ORDERED): - xdestroy(struct mds_kbdc_tree_nesting*, inner); + xdestroy(mds_kbdc_tree_nesting_t*, inner); break; case C(INFORMATION_LANGUAGE): case C(INFORMATION_COUNTRY): case C(INFORMATION_VARIANT): - xfree(struct mds_kbdc_tree_information_data*, data); + xfree(mds_kbdc_tree_information_data_t*, data); break; case C(FUNCTION): case C(MACRO): - xfree(struct mds_kbdc_tree_callable*, name); - xdestroy(struct mds_kbdc_tree_callable*, inner); + xfree(mds_kbdc_tree_callable_t*, name); + xdestroy(mds_kbdc_tree_callable_t*, inner); break; case C(INCLUDE): xfree(mds_kbdc_tree_include_t*, filename); + xdestroy(mds_kbdc_tree_include_t*, inner); break; case C(ASSUMPTION_HAVE): @@ -303,7 +304,7 @@ mds_kbdc_tree_t* mds_kbdc_tree_dup(mds_kbdc_tree_t* restrict this) case C(INFORMATION_LANGUAGE): case C(INFORMATION_COUNTRY): case C(INFORMATION_VARIANT): { NODE(information_data); S(data); } break; - case C(INCLUDE): { NODE(include); S(filename); } break; + case C(INCLUDE): { NODE(include); S(filename);T(inner); } break; case C(ASSUMPTION_HAVE_CHARS): { NODE(assumption_have_chars); S(chars); } break; case C(KEYS): { NODE(keys); S(keys); } break; case C(STRING): { NODE(string); S(string); } break; @@ -495,7 +496,7 @@ static void mds_kbdc_tree_print_indented(mds_kbdc_tree_t* restrict this, FILE* o case C(INFORMATION_LANGUAGE): SIMPLEX(information_language, "language", data); case C(INFORMATION_COUNTRY): SIMPLEX(information_country, "country", data); case C(INFORMATION_VARIANT): SIMPLEX(information_variant, "variant", data); - case C(INCLUDE): SIMPLEX(include, "include", filename); + case C(INCLUDE): NAMED_NESTING(include, "include", filename, inner); case C(FUNCTION): NAMED_NESTING(function, "function", name, inner); case C(MACRO): NAMED_NESTING(macro, "macro", name, inner); case C(ASSUMPTION): NESTING(assumption, "assumption", inner); diff --git a/src/mds-kbdc/tree.h b/src/mds-kbdc/tree.h index 6fd5bca..64a703d 100644 --- a/src/mds-kbdc/tree.h +++ b/src/mds-kbdc/tree.h @@ -285,7 +285,12 @@ typedef struct mds_kbdc_tree_include */ char* filename; - MDS_KBDC_TREE_PADDING(1); + /** + * The included layout code tree + */ + mds_kbdc_tree_t* inner; + + MDS_KBDC_TREE_PADDING(2); } mds_kbdc_tree_include_t; diff --git a/test-files/mds-kbdc/make-tree/valid/include b/test-files/mds-kbdc/make-tree/valid/include index 32dcdf2..fb302b1 100644 --- a/test-files/mds-kbdc/make-tree/valid/include +++ b/test-files/mds-kbdc/make-tree/valid/include @@ -1,4 +1,6 @@ include "assumption-filled" -# (include (@ 1 0-7) ‘"assumption-filled"’) +# (include (@ 1 0-7) ‘"assumption-filled"’ +# (.inner nil) +# ) |