Browse Source

Bug 442166 doesn't detect class definitions reliably
class recognition only recognized empty C++ classes
(regression introduced 1999-01-20 when java support was added)

15 years ago
parent
commit
fa27bd0e2c
2 changed files with 27 additions and 7 deletions
  1. 7 7
      genxref
  2. 20 0
      tests/syntax-highlighting/class.h

+ 7 - 7
genxref

@@ -685,17 +685,17 @@ sub c_classes {
     my $contents = $_[0];
 # XXX this has issues w/ whitespace
     # Find struct, enum and union definitions with params (function returning struct etc)
-    $contents =~ s/((struct|enum|union)\s+($ident|)\s+($ident|)\s*(\{\}|(;)))/
-	"$2 ".($3 ? "\01".$itype{$2}.$3."\02 " : " ").$4.$6.&wash($1)/goes;
+    $contents =~ s/((struct|enum|union)\s+($ident|)\s+($ident|)\s*([{;]))/
+	"$2 ".($3 ? "\01".$itype{$2}.$3."\02 " : " ").$4.$5.&wash($1)/gmoes;
 
     # Find struct, enum and union definitions.
-    $contents =~ s/((struct|enum|union)\s+($ident|)\s*(\{\}|(;)))/
-	"$2 ".($3 ? "\01".$itype{$2}.$3."\02 " : "").$5.&wash($1)/goes;
+    $contents =~ s/((struct|enum|union)\s+($ident|)\s*([{;]))/
+	"$2 ".($3 ? "\01".$itype{$2}.$3."\02 " : "").$4.&wash($1)/gmoes;
 
     # Find class definitions. (C++)
-    $contents =~ s/((class)\s+($ident)\s*(:[^;\{]*|)(\{\}|(;)))/
-	"$2 "."\01".$itype{$2.($6 ? 'forw' : '')}.
-	    &classes($4).$3."\02 ".$6.&wash($1)/goes;
+    $contents =~ s/((class)\s+($ident)\s*(:[^;\{]*|)([{;]))/
+	"$2 "."\01".$itype{$2.($5 eq ';' ? 'forw' : '')}.
+	    &classes($4).$3."\02 ".$5.&wash($1)/gmoes;
 
     return $contents;
 }

+ 20 - 0
tests/syntax-highlighting/class.h

@@ -0,0 +1,20 @@
+/* c++ class syntax highlighting */
+
+class class1;
+
+class class2 {
+
+};
+
+class class3 : public class2 {
+
+};
+
+class class4 {
+  friend class class5;
+};
+
+class class5 {
+  class class6 {
+  };
+};