mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 13:58:49 +00:00
Bug 1358037 - Inline the methods of nsHtml5ElementName and nsHtml5AttributeName.
Tag UXP Issue #1344
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -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 = {};
|
||||
|
||||
|
||||
+17
-26
@@ -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_");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-28
@@ -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();
|
||||
|
||||
+4
-4
@@ -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",
|
||||
|
||||
+23
-10
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user