When finding comment for an enum, don't accidentally pick up a same-line comment of an enum value on the preceding line

This commit is contained in:
rdb 2014-09-21 13:22:52 +00:00
parent 0e785de0ff
commit db7a6561f2
1 changed files with 16 additions and 3 deletions

View File

@ -151,12 +151,25 @@ add_enum_value(CPPInstance *inst, CPPPreprocessor *preprocessor,
if (inst->_leading_comment == (CPPCommentBlock *)NULL) {
// Same-line comment?
inst->_leading_comment =
CPPCommentBlock *comment =
preprocessor->get_comment_on(pos.first_line, pos.file);
if (inst->_leading_comment == (CPPCommentBlock *)NULL) {
inst->_leading_comment =
if (comment == (CPPCommentBlock *)NULL) {
// Nope. Check for a comment before this line.
comment =
preprocessor->get_comment_before(pos.first_line, pos.file);
if (comment != NULL) {
// This is a bit of a hack, but it prevents us from picking
// up a same-line comment from the previous line.
if (comment->_line_number != pos.first_line - 1 ||
comment->_col_number <= pos.first_column) {
inst->_leading_comment = comment;
}
}
} else {
inst->_leading_comment = comment;
}
}