diff options
author | Gaming4JC <g4jc@hyperbola.info> | 2020-01-18 16:30:42 -0500 |
---|---|---|
committer | Gaming4JC <g4jc@hyperbola.info> | 2020-01-26 15:50:36 -0500 |
commit | 1c73529a2a69d618f2ba59c133eb84d10b1d6fae (patch) | |
tree | a21556dd199b6163eecda8032066e7532ff88ecb /parser | |
parent | b9c8513751fc4dc03956d5337ba7fc4607c4ec63 (diff) | |
download | uxp-1c73529a2a69d618f2ba59c133eb84d10b1d6fae.tar.gz |
Bug 1358037 - Inline the methods of nsHtml5ElementName and nsHtml5AttributeName.
Tag UXP Issue mcp-graveyard/UXP#1344
Diffstat (limited to 'parser')
7 files changed, 72 insertions, 80 deletions
diff --git a/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java b/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java index 24f89ddb0a..667e8eb932 100644 --- a/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java +++ b/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java @@ -272,7 +272,7 @@ public final class AttributeName * whether to check ncnameness * @return an <code>AttributeName</code> corresponding to the argument data */ - static AttributeName nameByBuffer(@NoLength char[] buf, int offset, + @Inline static AttributeName nameByBuffer(@NoLength char[] buf, int offset, int length , Interner interner) { // XXX deal with offset @@ -282,7 +282,7 @@ public final class AttributeName return null; } AttributeName attributeName = AttributeName.ATTRIBUTE_NAMES[index]; - @Local String name = attributeName.getLocal(AttributeName.HTML); + @Local String name = attributeName.getLocal(0); if (!Portability.localEqualsBuffer(name, buf, offset, length)) { return null; } @@ -418,11 +418,11 @@ public final class AttributeName // CPPONLY: this.custom = true; // CPPONLY: } // CPPONLY: - // CPPONLY: public boolean isInterned() { + // CPPONLY: @Inline public boolean isInterned() { // CPPONLY: return !custom; // CPPONLY: } // CPPONLY: - // CPPONLY: public void setNameForNonInterned(@Local String name) { + // CPPONLY: @Inline public void setNameForNonInterned(@Local String name) { // CPPONLY: assert custom; // CPPONLY: local[0] = name; // CPPONLY: local[1] = name; diff --git a/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/ElementName.java b/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/ElementName.java index e961c43972..cc363acdec 100644 --- a/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/ElementName.java +++ b/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/ElementName.java @@ -107,15 +107,15 @@ public final class ElementName return flags; } - public int getGroup() { - return flags & GROUP_MASK; + @Inline public int getGroup() { + return flags & ElementName.GROUP_MASK; } - public boolean isInterned() { - return (flags & NOT_INTERNED) == 0; + @Inline public boolean isInterned() { + return (flags & ElementName.NOT_INTERNED) == 0; } - static ElementName elementNameByBuffer(@NoLength char[] buf, int offset, int length, Interner interner) { + @Inline static ElementName elementNameByBuffer(@NoLength char[] buf, int offset, int length, Interner interner) { @Unsigned int hash = ElementName.bufToHash(buf, length); int index = Arrays.binarySearch(ElementName.ELEMENT_HASHES, hash); if (index < 0) { @@ -184,12 +184,15 @@ public final class ElementName // The translator adds refcount debug code here. } - public void setNameForNonInterned(@Local String name) { + @Inline public void setNameForNonInterned(@Local String name) { // No need to worry about refcounting the local name, because in the // C++ case the scoped atom table remembers its own atoms. this.name = name; this.camelCaseName = name; - assert this.flags == (TreeBuilder.OTHER | NOT_INTERNED); + // The assertion below relies on TreeBuilder.OTHER being zero! + // TreeBuilder.OTHER isn't referenced here, because it would create + // a circular C++ header dependency given that this method is inlined. + assert this.flags == ElementName.NOT_INTERNED; } // CPPONLY: public static final ElementName ISINDEX = new ElementName("isindex", "isindex", TreeBuilder.ISINDEX | SPECIAL); diff --git a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java index 6cbba41628..7943368f7d 100644 --- a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java +++ b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java @@ -117,7 +117,7 @@ public class CppTypes { "nsHtml5String", "nsNameSpaceManager", "nsIContent", "nsTraceRefcnt", "jArray", "nsHtml5ArrayCopy", "nsAHtml5TreeBuilderState", "nsHtml5Atoms", "nsHtml5ByteReadable", "nsIUnicodeDecoder", - "nsHtml5Macros", "nsIContentHandle" }; + "nsHtml5Macros", "nsIContentHandle", "nsHtml5Portability" }; private static final String[] OTHER_DECLATIONS = {}; diff --git a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java index 9a2a85795a..2a37e5ce14 100644 --- a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java +++ b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java @@ -331,13 +331,7 @@ public class CppVisitor extends AnnotationHelperVisitor<LocalSymbolTable> { } else if ("errorHandler".equals(n.getName())) { printer.print(cppTypes.errorHandler()); } else { - String prefixedName = javaClassName + "." + n.getName(); - String constant = symbolTable.cppDefinesByJavaNames.get(prefixedName); - if (constant != null) { - printer.print(constant); - } else { - printer.print(n.getName()); - } + printer.print(n.getName()); } } @@ -736,10 +730,14 @@ public class CppVisitor extends AnnotationHelperVisitor<LocalSymbolTable> { printer.print(" "); printer.print(className); printer.print("::"); - if ("AttributeName".equals(n.getType().toString())) { - printer.print("ATTR_"); - } else if ("ElementName".equals(n.getType().toString())) { - printer.print("ELT_"); + String clazzName = n.getType().toString(); + String field = declarator.getId().toString(); + if (symbolTable.isAttributeOrElementName(clazzName, field)) { + if ("AttributeName".equals(clazzName)) { + printer.print("ATTR_"); + } else if ("ElementName".equals(clazzName)) { + printer.print("ELT_"); + } } declarator.getId().accept(this, arg); printer.print(" = "); @@ -1080,21 +1078,14 @@ public class CppVisitor extends AnnotationHelperVisitor<LocalSymbolTable> { printer.print("->"); } } else { - String prefixedName = clazzName + "." + field; - String constant = symbolTable.cppDefinesByJavaNames.get(prefixedName); - if (constant != null) { - printer.print(constant); - return; - } else { - printer.print(cppTypes.classPrefix()); - printer.print(clazzName); - printer.print("::"); - if (symbolTable.isNotAnAttributeOrElementName(field)) { - if ("AttributeName".equals(clazzName)) { - printer.print("ATTR_"); - } else if ("ElementName".equals(clazzName)) { - printer.print("ELT_"); - } + printer.print(cppTypes.classPrefix()); + printer.print(clazzName); + printer.print("::"); + if (symbolTable.isAttributeOrElementName(clazzName, field)) { + if ("AttributeName".equals(clazzName)) { + printer.print("ATTR_"); + } else if ("ElementName".equals(clazzName)) { + printer.print("ELT_"); } } } diff --git a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/HVisitor.java b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/HVisitor.java index 25cf7aef16..902eb348ab 100644 --- a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/HVisitor.java +++ b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/HVisitor.java @@ -37,7 +37,6 @@ package nu.validator.htmlparser.cpptranslate; -import java.util.LinkedList; import java.util.List; import japa.parser.ast.body.FieldDeclaration; @@ -45,12 +44,9 @@ import japa.parser.ast.body.MethodDeclaration; import japa.parser.ast.body.ModifierSet; import japa.parser.ast.body.Parameter; import japa.parser.ast.body.VariableDeclarator; -import japa.parser.ast.expr.IntegerLiteralExpr; -import japa.parser.ast.expr.MethodCallExpr; import japa.parser.ast.stmt.BlockStmt; import japa.parser.ast.type.PrimitiveType; import japa.parser.ast.type.ReferenceType; -import japa.parser.ast.type.Type; public class HVisitor extends CppVisitor { @@ -60,8 +56,6 @@ public class HVisitor extends CppVisitor { private Visibility previousVisibility = Visibility.NONE; - private List<String> defines = new LinkedList<String>(); - /** * @see nu.validator.htmlparser.cpptranslate.CppVisitor#printMethodNamespace() */ @@ -145,10 +139,10 @@ public class HVisitor extends CppVisitor { */ @Override protected void endClassDeclaration() { printModifiers(ModifierSet.PUBLIC | ModifierSet.STATIC); - printer.printLn("void initializeStatics();"); + printer.printLn("void initializeStatics();"); printModifiers(ModifierSet.PUBLIC | ModifierSet.STATIC); - printer.printLn("void releaseStatics();"); - + printer.printLn("void releaseStatics();"); + printer.unindent(); printer.unindent(); @@ -161,13 +155,6 @@ public class HVisitor extends CppVisitor { printer.printLn("};"); printer.printLn(); - - for (String define : defines) { - printer.printLn(define); - } - - printer.printLn(); - printer.printLn(); printer.printLn("#endif"); } @@ -226,18 +213,16 @@ public class HVisitor extends CppVisitor { throw new IllegalStateException( "More than one variable declared by one declarator."); } - String name = javaClassName + "." + declarator.getId().getName(); - String value = declarator.getInit().toString(); - if ("Integer.MAX_VALUE".equals(value)) { - value = cppTypes.maxInteger(); - } - String longName = definePrefix + declarator.getId().getName(); - if (symbolTable.cppDefinesByJavaNames.containsKey(name)) { - throw new IllegalStateException( - "Duplicate #define constant local name: " + name); - } - symbolTable.cppDefinesByJavaNames.put(name, longName); - defines.add("#define " + longName + " " + value); + printModifiers(modifiers); + printer.print("const "); + n.getType().accept(this, arg); + printer.print(" "); + declarator.getId().accept(this, arg); + printer.print(" = "); + declarator.getInit().accept(this, arg); + printer.printLn(";"); + printer.printLn(); + symbolTable.addPrimitiveConstant(javaClassName, declarator.getId().toString()); } else { if (n.getType() instanceof ReferenceType) { ReferenceType rt = (ReferenceType) n.getType(); diff --git a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/Main.java b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/Main.java index 09602ccba3..307d7d8a6d 100644 --- a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/Main.java +++ b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/Main.java @@ -52,11 +52,11 @@ import japa.parser.ast.CompilationUnit; public class Main { static final String[] H_LIST = { + "AttributeName", + "ElementName", "Tokenizer", "TreeBuilder", "MetaScanner", - "AttributeName", - "ElementName", "StackNode", "UTF16Buffer", "StateSnapshot", @@ -64,11 +64,11 @@ public class Main { }; private static final String[] CPP_LIST = { + "AttributeName", + "ElementName", "Tokenizer", "TreeBuilder", "MetaScanner", - "AttributeName", - "ElementName", "StackNode", "UTF16Buffer", "StateSnapshot", diff --git a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/SymbolTable.java b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/SymbolTable.java index 970a2b64b2..3619c923a7 100644 --- a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/SymbolTable.java +++ b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/SymbolTable.java @@ -38,11 +38,13 @@ package nu.validator.htmlparser.cpptranslate; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; public class SymbolTable { - public final Map<String, String> cppDefinesByJavaNames = new HashMap<String, String>(); + private final Set<StringPair> primitiveConstants = new HashSet<StringPair>(); private final Map<StringPair, Type> fields = new HashMap<StringPair, Type>(); @@ -51,17 +53,24 @@ public class SymbolTable { /** * This is a sad hack to work around the fact the there's no real symbol * table yet. - * - * @param name + * + * @param field * @return */ - public boolean isNotAnAttributeOrElementName(String name) { - return !("ATTRIBUTE_HASHES".equals(name) - || "ATTRIBUTE_NAMES".equals(name) - || "ELEMENT_HASHES".equals(name) - || "ELEMENT_NAMES".equals(name) || "ALL_NO_NS".equals(name)); + public boolean isAttributeOrElementName(String klazz, String field) { + if (isPrimitiveConstant(klazz, field)) { + return false; + } + return !("ATTRIBUTE_HASHES".equals(field) + || "ATTRIBUTE_NAMES".equals(field) + || "ELEMENT_HASHES".equals(field) + || "ELEMENT_NAMES".equals(field) || "ALL_NO_NS".equals(field)); } - + + public void addPrimitiveConstant(String klazz, String field) { + primitiveConstants.add(new StringPair(klazz, field)); + } + public void putFieldType(String klazz, String field, Type type) { fields.put(new StringPair(klazz, field), type); } @@ -69,7 +78,11 @@ public class SymbolTable { public void putMethodReturnType(String klazz, String method, Type type) { methodReturns.put(new StringPair(klazz, method), type); } - + + public boolean isPrimitiveConstant(String klazz, String field) { + return primitiveConstants.contains(new StringPair(klazz, field)); + } + public Type getFieldType(String klazz, String field) { return fields.get(new StringPair(klazz, field)); } |