From db7a6561f283b5fb400a0c7ab82a8117db179ae8 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Sep 2014 13:22:52 +0000 Subject: [PATCH] When finding comment for an enum, don't accidentally pick up a same-line comment of an enum value on the preceding line --- dtool/src/cppparser/cppScope.cxx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/dtool/src/cppparser/cppScope.cxx b/dtool/src/cppparser/cppScope.cxx index eb8008583b..8ca9babad4 100644 --- a/dtool/src/cppparser/cppScope.cxx +++ b/dtool/src/cppparser/cppScope.cxx @@ -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; } }