Skip to content

Commit 450f12a

Browse files
author
zhourenjian@gmail.com
committed
Fixing bug that char arguments should be marked as String arguments
Improving compiling char comparison and other operations
1 parent 6db77bf commit 450f12a

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTKeywordVisitor.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -846,13 +846,13 @@ public boolean visit(PostfixExpression node) {
846846
}
847847
return false;
848848
}
849-
ITypeBinding typeBinding = node.getOperand().resolveTypeBinding();
849+
ITypeBinding typeBinding = left.resolveTypeBinding();
850850
if (typeBinding != null && typeBinding.isPrimitive()) {
851851
if ("char".equals(typeBinding.getName())) {
852852
buffer.append("(");
853-
node.getOperand().accept(this);
853+
left.accept(this);
854854
buffer.append(" = String.fromCharCode (($c$ = ");
855-
node.getOperand().accept(this);
855+
left.accept(this);
856856
String op = node.getOperator().toString();
857857
if ("++".equals(op)) {
858858
buffer.append(").charCodeAt (0) + 1)");
@@ -863,7 +863,7 @@ public boolean visit(PostfixExpression node) {
863863
return false;
864864
}
865865
}
866-
boxingNode(node.getOperand());
866+
boxingNode(left);
867867
return false;
868868
//return super.visit(node);
869869
}
@@ -971,24 +971,30 @@ public boolean visit(PrefixExpression node) {
971971
}
972972
return false;
973973
}
974-
ITypeBinding typeBinding = node.getOperand().resolveTypeBinding();
974+
ITypeBinding typeBinding = left.resolveTypeBinding();
975975
if (typeBinding.isPrimitive()) {
976976
if ("char".equals(typeBinding.getName())) {
977977
buffer.append("(");
978-
node.getOperand().accept(this);
979-
buffer.append(" = String.fromCharCode ((");
980-
node.getOperand().accept(this);
978+
left.accept(this);
979+
buffer.append(" = String.fromCharCode (");
980+
if (left instanceof SimpleName || left instanceof QualifiedName) {
981+
left.accept(this);
982+
} else {
983+
buffer.append("(");
984+
left.accept(this);
985+
buffer.append(")");
986+
}
981987
if ("++".equals(op)) {
982-
buffer.append(").charCodeAt (0) + 1)");
988+
buffer.append(".charCodeAt (0) + 1)");
983989
} else {
984-
buffer.append(").charCodeAt (0) - 1)");
990+
buffer.append(".charCodeAt (0) - 1)");
985991
}
986992
buffer.append(")");
987993
return false;
988994
}
989995
}
990996
buffer.append(node.getOperator());
991-
boxingNode(node.getOperand());
997+
boxingNode(left);
992998
return false;
993999
}
9941000

0 commit comments

Comments
 (0)