Browse Source

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

rdb 11 years ago
parent
commit
db7a6561f2
1 changed files with 16 additions and 3 deletions
  1. 16 3
      dtool/src/cppparser/cppScope.cxx

+ 16 - 3
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;
     }
   }