Bug 1424548 - Part 13: Emit override specifiers in the generated HTML parser code. r=hsivonen
authorChris Peterson <cpeterson@mozilla.com>
Tue, 05 Dec 2017 23:01:44 -0800
changeset 865 afa68d0380edaa20000a7802ab51f95710078e2a
parent 864 79a997f5156f4747ce4d771847a4d754207517e9
child 866 95d2e02251dffb27336fa8045a01d8477a90f480
push id182
push usercpeterson@mozilla.com
push dateMon, 08 Jan 2018 07:22:25 +0000
reviewershsivonen
bugs1424548
Bug 1424548 - Part 13: Emit override specifiers in the generated HTML parser code. r=hsivonen We convert Java @Override annotations to C++ override specifiers in generated HTML parser code. Overridden virtual functions without override specifiers will become errors after gcc -Wsuggest-override warnings are enabled.
translator-src/nu/validator/htmlparser/cpptranslate/AnnotationHelperVisitor.java
translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java
--- a/translator-src/nu/validator/htmlparser/cpptranslate/AnnotationHelperVisitor.java
+++ b/translator-src/nu/validator/htmlparser/cpptranslate/AnnotationHelperVisitor.java
@@ -79,16 +79,20 @@ public class AnnotationHelperVisitor<T> 
     protected boolean auto() {
         return hasAnnotation("Auto");
     }
 
     protected boolean virtual() {
         return hasAnnotation("Virtual");
     }
 
+    protected boolean override() {
+        return hasAnnotation("Override");
+    }
+
     protected boolean isConst() {
         return hasAnnotation("Const");
     }
 
     protected boolean characterName() {
         return hasAnnotation("CharacterName");
     }
 
--- a/translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java
+++ b/translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java
@@ -1597,33 +1597,38 @@ public class CppVisitor extends Annotati
         printMethodNamespace();
         if (destructor) {
             printer.print("~");
             printer.print(className);
         } else {
             printer.print(n.getName());
         }
 
-        currentAnnotations = null;
         printer.print("(");
         if (n.getParameters() != null) {
             for (Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext();) {
                 Parameter p = i.next();
                 p.accept(this, arg);
                 if (i.hasNext()) {
                     printer.print(", ");
                 }
             }
         }
         printer.print(")");
 
         for (int i = 0; i < n.getArrayCount(); i++) {
             printer.print("[]");
         }
 
+        if (override() && inHeader()) {
+            printer.print(" override");
+        }
+
+        currentAnnotations = null;
+
         if (inHeader() == isInline) {
             printMethodBody(n.getBody(), arg);
         } else {
             printer.printLn(";");
         }
     }
 
     private void printMethodBody(BlockStmt n, LocalSymbolTable arg) {