diff options
| author | Michele Calgaro <michele.calgaro@yahoo.it> | 2021-11-21 17:04:21 +0900 |
|---|---|---|
| committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2021-11-21 17:09:35 +0900 |
| commit | e6ba08c3b21cdb14ee3a97b5d584759a4597b54b (patch) | |
| tree | e8b4121323f2f448aeaa15bf3bddb465f36aea8b /debian/uncrustify-trinity/uncrustify-trinity-0.74.0/src/remove_duplicate_include.cpp | |
| parent | f312c235ea5f9971066f3808997d20f89c25f33b (diff) | |
| download | extra-dependencies-e6ba08c3b21cdb14ee3a97b5d584759a4597b54b.tar.gz extra-dependencies-e6ba08c3b21cdb14ee3a97b5d584759a4597b54b.zip | |
uncrustify-trinity: updated based on upstream version 0.74.0
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'debian/uncrustify-trinity/uncrustify-trinity-0.74.0/src/remove_duplicate_include.cpp')
| -rw-r--r-- | debian/uncrustify-trinity/uncrustify-trinity-0.74.0/src/remove_duplicate_include.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/debian/uncrustify-trinity/uncrustify-trinity-0.74.0/src/remove_duplicate_include.cpp b/debian/uncrustify-trinity/uncrustify-trinity-0.74.0/src/remove_duplicate_include.cpp new file mode 100644 index 00000000..118db91c --- /dev/null +++ b/debian/uncrustify-trinity/uncrustify-trinity-0.74.0/src/remove_duplicate_include.cpp @@ -0,0 +1,94 @@ +/** + * @file remove_duplicate_include.cpp + * + * @author Guy Maurel + * October 2015, 2016 + * @license GPL v2+ + */ + +#include "remove_duplicate_include.h" + +#include "chunk_list.h" +#include "uncrustify.h" + +using std::vector; + + +void remove_duplicate_include(void) +{ + LOG_FUNC_ENTRY(); + + vector<chunk_t *> includes; + + chunk_t *preproc = nullptr; + chunk_t *pc = chunk_get_head(); + + while (pc != nullptr) + { + //LOG_FMT(LRMRETURN, "%s(%d): orig_line is %zu, orig_col is %zu, text() is '%s', type is %s, parent_type is %s\n", + // __func__, __LINE__, pc->orig_line, pc->orig_col, pc->text(), + // get_token_name(pc->type), get_token_name(pc->parent_type)); + + if (chunk_is_token(pc, CT_PREPROC)) + { + preproc = pc; + } + else if (chunk_is_token(pc, CT_PP_INCLUDE)) + { + chunk_t *next = chunk_get_next(pc); + + //LOG_FMT(LRMRETURN, "%s(%d): orig_line is %zu, orig_col is %zu, text() is '%s', type is %s, parent_type is %s\n", + // __func__, __LINE__, next->orig_line, next->orig_col, next->text(), + // get_token_name(next->type), get_token_name(next->parent_type)); + if (includes.empty()) + { + includes.push_back(next); + // goto next newline + pc = chunk_get_next_nl(next); + } + else + { + //LOG_FMT(LRMRETURN, "%s(%d): size is %zu\n", + // __func__, __LINE__, includes.size()); + // look for duplicate + auto ite = includes.end(); + + for (auto itc = includes.begin(); itc != ite; ++itc) + { + chunk_t *current = *itc; + + //LOG_FMT(LRMRETURN, "%s(%d): next->text() is '%s'\n", + // __func__, __LINE__, next->text()); + //LOG_FMT(LRMRETURN, "%s(%d): current->text() is '%s'\n", + // __func__, __LINE__, current->text()); + if (std::strcmp(next->text(), current->text()) == 0) + { + // erase the statement + chunk_t *temp = pc; + chunk_t *comment = chunk_get_next(next); + chunk_t *eol = chunk_get_next_nl(next); + pc = chunk_get_prev(preproc); + chunk_del(preproc); + chunk_del(temp); + chunk_del(next); + + if (comment != eol) + { + chunk_del(comment); + } + chunk_del(eol); + break; + } + else + { + // goto next newline + pc = chunk_get_next_nl(next); + // and still look for duplicate + } + } // for (auto itc = includes.begin(); + } // if (includes.empty()) + } // else if (chunk_is_token(pc, CT_PP_INCLUDE)) + // get the next token + pc = chunk_get_next(pc); + } +} // remove_duplicate_include |
