Skip to content

Commit 2a15ea6

Browse files
emiliohsivonen
authored andcommitted
Mozilla bug 1392185 - Remove special handling of atoms in the HTML5 parser. r=hsivonen.
1 parent d404c4a commit 2a15ea6

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,16 @@ public String stringType() {
235235
return "nsHtml5String";
236236
}
237237

238-
public String localType() {
238+
public String weakLocalType() {
239239
return "nsAtom*";
240240
}
241241

242+
public String localType() {
243+
return "RefPtr<nsAtom>";
244+
}
245+
242246
public String prefixType() {
243-
return "nsAtom*";
247+
return "nsStaticAtom*";
244248
}
245249

246250
public String nsUriType() {

translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ public String getSource() {
204204

205205
protected boolean inPrimitiveNoLengthFieldDeclarator = false;
206206

207+
protected boolean inField = false;
208+
209+
protected boolean inArray = false;
210+
207211
protected final SymbolTable symbolTable;
208212

209213
protected String definePrefix;
@@ -467,7 +471,7 @@ public void visit(ClassOrInterfaceType n, LocalSymbolTable arg) {
467471
String name = n.getName();
468472
if ("String".equals(name)) {
469473
if (local()) {
470-
name = cppTypes.localType();
474+
name = inField || inArray ? cppTypes.localType() : cppTypes.weakLocalType();
471475
} else if (prefix()) {
472476
name = cppTypes.prefixType();
473477
} else if (nsUri()) {
@@ -559,6 +563,10 @@ public void visit(ReferenceType n, LocalSymbolTable arg) {
559563
if (isConst()) {
560564
printer.print("const ");
561565
}
566+
boolean wasInArray = inArray;
567+
if (n.getArrayCount() > 0) {
568+
inArray = true;
569+
}
562570
if (noLength()) {
563571
n.getType().accept(this, arg);
564572
for (int i = 0; i < n.getArrayCount(); i++) {
@@ -586,6 +594,9 @@ public void visit(ReferenceType n, LocalSymbolTable arg) {
586594
printer.print(">");
587595
}
588596
}
597+
if (n.getArrayCount() > 0) {
598+
inArray = wasInArray;
599+
}
589600
}
590601

591602
public void visit(WildcardType n, LocalSymbolTable arg) {
@@ -616,6 +627,7 @@ protected boolean isNonToCharArrayMethodCall(Expression exp) {
616627
}
617628

618629
protected void fieldDeclaration(FieldDeclaration n, LocalSymbolTable arg) {
630+
inField = true;
619631
tempPrinterHolder = printer;
620632
printer = staticInitializerPrinter;
621633
int modifiers = n.getModifiers();
@@ -777,6 +789,7 @@ protected void fieldDeclaration(FieldDeclaration n, LocalSymbolTable arg) {
777789
currentArrayCount = 0;
778790
printer = tempPrinterHolder;
779791
inPrimitiveNoLengthFieldDeclarator = false;
792+
inField = false;
780793
}
781794

782795
private void printArrayInit(VariableDeclaratorId variableDeclaratorId,
@@ -854,6 +867,7 @@ public void visit(ArrayCreationExpr n, LocalSymbolTable arg) {
854867
// n.getType().accept(this, arg);
855868
// printTypeArgs(n.getTypeArgs(), arg);
856869

870+
inArray = true;
857871
if (n.getDimensions() != null) {
858872
if (noLength()) {
859873
for (Expression dim : n.getDimensions()) {
@@ -887,6 +901,7 @@ public void visit(ArrayCreationExpr n, LocalSymbolTable arg) {
887901
"Array initializer as part of array creation not supported. "
888902
+ n.toString());
889903
}
904+
inArray = false;
890905
}
891906

892907
public void visit(AssignExpr n, LocalSymbolTable arg) {

translator-src/nu/validator/htmlparser/cpptranslate/HVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public HVisitor(CppTypes cppTypes, SymbolTable symbolTable) {
197197
* @see nu.validator.htmlparser.cpptranslate.CppVisitor#fieldDeclaration(japa.parser.ast.body.FieldDeclaration, java.lang.LocalSymbolTable)
198198
*/
199199
@Override protected void fieldDeclaration(FieldDeclaration n, LocalSymbolTable arg) {
200+
inField = true;
200201
int modifiers = n.getModifiers();
201202
List<VariableDeclarator> variables = n.getVariables();
202203
VariableDeclarator declarator = variables.get(0);
@@ -253,6 +254,7 @@ public HVisitor(CppTypes cppTypes, SymbolTable symbolTable) {
253254
inStatic = false;
254255
inPrimitiveNoLengthFieldDeclarator = false;
255256
}
257+
inField = false;
256258
}
257259

258260
/**

0 commit comments

Comments
 (0)