| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e7fa839 commit b2bccf4
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1766,7 +1766,9 @@ private Type handleIncrementExpression(UnaryExpression node) { | |||
| 1766 | 1766 | */ | |
| 1767 | 1767 | @Override public Type visit(ArrayTypeName node) { | |
| 1768 | 1768 | Type elementType = node.getElementType().acceptVisitor(this); | |
| 1769 | - return setType(node, new SimpleArrayType(elementType)); | ||
| 1769 | + Type arrayT = node.isVararg() ? new VarargArrayType(elementType) : | ||
| 1770 | + new SimpleArrayType(elementType); | ||
| 1771 | + return setType(node, arrayT); | ||
| 1770 | 1772 | } | |
| 1771 | 1773 | ||
| 1772 | 1774 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -198,12 +198,14 @@ private boolean isConcreteClass(DJClass c) { | |||
| 198 | 198 | * (in terms of {@link isEqual}), transitive relation. | |
| 199 | 199 | */ | |
| 200 | 200 | public boolean isSubtype(Type subT, Type superT) { | |
| 201 | - return isSubtype(subT, superT, new RecursionStack2<Type, Type>()); | ||
| 201 | + //debug.logStart(new String[]{"subT", "superT"}, subT, superT); | ||
| 202 | + boolean result = isSubtype(subT, superT, new RecursionStack2<Type, Type>()); | ||
| 203 | + //debug.logEnd("result", result); | ||
| 204 | + return result; | ||
| 202 | 205 | } | |
| 203 | 206 | ||
| 204 | 207 | private boolean isSubtype(final Type subT, final Type superT, final RecursionStack2<Type, Type> stack) { | |
| 205 | - //debug.logStart(); | ||
| 206 | - //debug.logValues(new String[]{"subT", "superT"}, subT, superT); try { | ||
| 208 | + //debug.logStart(new String[]{"subT", "superT"}, subT, superT); try { | ||
| 207 | 209 | ||
| 208 | 210 | if (subT.equals(superT)) { return true; } // what follows assumes the types are not syntactically equal | |
| 209 | 211 | ||
@@ -319,7 +321,10 @@ private Boolean handleArrayType(final ArrayType subT) { | |||
| 319 | 321 | public Boolean defaultCase(Type superT) { return false; } | |
| 320 | 322 | ||
| 321 | 323 | @Override public Boolean forArrayType(ArrayType superT) { | |
| 322 | - if (isPrimitive(subT.ofType())) { return false; } | ||
| 324 | + if (isPrimitive(subT.ofType())) { | ||
| 325 | + // types may be inequal if one is vararg and the other is not | ||
| 326 | + return subT.ofType().equals(superT.ofType()); | ||
| 327 | + } | ||
| 323 | 328 | else { return isSubtype(subT.ofType(), superT.ofType(), stack); } | |
| 324 | 329 | } | |
| 325 | 330 | ||
@@ -445,14 +450,15 @@ public boolean isAssignable(Type target, Type expT, Object expValue) { | |||
| 445 | 450 | ||
| 446 | 451 | public boolean isPrimitiveConvertible(Type t) { | |
| 447 | 452 | return isPrimitive(t) || | |
| 448 | - isSubtype(t, BOOLEAN_CLASS) || | ||
| 449 | - isSubtype(t, CHARACTER_CLASS) || | ||
| 450 | - isSubtype(t, BYTE_CLASS) || | ||
| 451 | - isSubtype(t, SHORT_CLASS) || | ||
| 452 | - isSubtype(t, INTEGER_CLASS) || | ||
| 453 | - isSubtype(t, LONG_CLASS) || | ||
| 454 | - isSubtype(t, FLOAT_CLASS) || | ||
| 455 | - isSubtype(t, DOUBLE_CLASS); | ||
| 453 | + (!isSubtype(t, NULL) && | ||
| 454 | + (isSubtype(t, BOOLEAN_CLASS) || | ||
| 455 | + isSubtype(t, CHARACTER_CLASS) || | ||
| 456 | + isSubtype(t, BYTE_CLASS) || | ||
| 457 | + isSubtype(t, SHORT_CLASS) || | ||
| 458 | + isSubtype(t, INTEGER_CLASS) || | ||
| 459 | + isSubtype(t, LONG_CLASS) || | ||
| 460 | + isSubtype(t, FLOAT_CLASS) || | ||
| 461 | + isSubtype(t, DOUBLE_CLASS))); | ||
| 456 | 462 | } | |
| 457 | 463 | ||
| 458 | 464 | ||
@@ -1121,7 +1127,9 @@ public Expression makePrimitive(Expression e) throws UnsupportedConversionExcept | |||
| 1121 | 1127 | Type t = NodeProperties.getType(e); | |
| 1122 | 1128 | if (isPrimitive(t)) { return e; } | |
| 1123 | 1129 | // Note: The spec is not clear about whether a *subtype* (such as a variable) can | |
| 1124 | - // be unboxed. We allow it here, because that seems like the correct approach. | ||
| 1130 | + // be unboxed. We allow it here unless the type is null, because that seems | ||
| 1131 | + // like the correct approach. | ||
| 1132 | + else if (isSubtype(t, NULL)) { throw new UnsupportedConversionException(); } | ||
| 1125 | 1133 | else if (isSubtype(t, BOOLEAN_CLASS)) { return unbox(e, "booleanValue"); } | |
| 1126 | 1134 | else if (isSubtype(t, CHARACTER_CLASS)) { return unbox(e, "charValue"); } | |
| 1127 | 1135 | else if (isSubtype(t, BYTE_CLASS)) { return unbox(e, "byteValue"); } | |
@@ -2610,7 +2618,7 @@ public MultiVarargChecker(Iterable<? extends Type> params, Iterable<? extends Ex | |||
| 2610 | 2618 | @Override public boolean matchesWithVarargs() { | |
| 2611 | 2619 | if (_varargParam instanceof VarargArrayType) { | |
| 2612 | 2620 | boxArgs(); | |
| 2613 | - if (matches()) { | ||
| 2621 | + if (super.matches()) { | ||
| 2614 | 2622 | ArrayType arrayT = (ArrayType) substitute((ArrayType) _varargParam, _tparams, _targs); | |
| 2615 | 2623 | Type elementT = arrayT.ofType(); | |
| 2616 | 2624 | Iterable<Expression> boxedVarargArgs = EMPTY_EXPRESSION_ITERABLE; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -171,10 +171,10 @@ public class Parser { | |||
| 171 | 171 | ||
| 172 | 172 | // If the field is an array, create an array type node | |
| 173 | 173 | if (dim > 0) { | |
| 174 | - typ = new ArrayTypeName(typ, dim, | ||
| 175 | - filename, | ||
| 176 | - typ.getBeginLine(), typ.getBeginColumn(), | ||
| 177 | - typ.getEndLine(), typ.getEndColumn()); | ||
| 174 | + typ = new ArrayTypeName(typ, dim, false, | ||
| 175 | + filename, | ||
| 176 | + typ.getBeginLine(), typ.getBeginColumn(), | ||
| 177 | + typ.getEndLine(), typ.getEndColumn()); | ||
| 178 | 178 | } | |
| 179 | 179 | ||
| 180 | 180 | return new FieldDeclaration(flags, typ, name.image, exp, | |
@@ -212,10 +212,10 @@ public class Parser { | |||
| 212 | 212 | ||
| 213 | 213 | // If the variable contains an array, create an array type node | |
| 214 | 214 | if (dim > 0) { | |
| 215 | - typ = new ArrayTypeName(typ, dim, | ||
| 216 | - filename, | ||
| 217 | - typ.getBeginLine(), typ.getBeginColumn(), | ||
| 218 | - typ.getEndLine(), typ.getEndColumn()); | ||
| 215 | + typ = new ArrayTypeName(typ, dim, false, | ||
| 216 | + filename, | ||
| 217 | + typ.getBeginLine(), typ.getBeginColumn(), | ||
| 218 | + typ.getEndLine(), typ.getEndColumn()); | ||
| 219 | 219 | } | |
| 220 | 220 | ||
| 221 | 221 | return new VariableDeclaration(isFinal, typ, name.image, exp, | |
@@ -1757,10 +1757,10 @@ PARSER_END(Parser) | |||
| 1757 | 1757 | bc = typ.getBeginColumn(); | |
| 1758 | 1758 | } | |
| 1759 | 1759 | if (dim > 0) { | |
| 1760 | - typ = new ArrayTypeName(typ, dim, | ||
| 1761 | - filename, | ||
| 1762 | - typ.getBeginLine(), typ.getBeginColumn(), | ||
| 1763 | - typ.getEndLine(), typ.getEndColumn()); | ||
| 1760 | + typ = new ArrayTypeName(typ, dim, false, | ||
| 1761 | + filename, | ||
| 1762 | + typ.getBeginLine(), typ.getBeginColumn(), | ||
| 1763 | + typ.getEndLine(), typ.getEndColumn()); | ||
| 1764 | 1764 | } | |
| 1765 | 1765 | if(lastFormalParameterIsVarArgs) flags |= 0x00000080; // java.lang.reflect.Modifier.VARARGS == 0x00000080 /**/ | |
| 1766 | 1766 | ||
@@ -1842,10 +1842,10 @@ PARSER_END(Parser) | |||
| 1842 | 1842 | [ f="final" ] typ=type() id=<IDENTIFIER> ( "[" "]" { dim++; } )* | |
| 1843 | 1843 | { | |
| 1844 | 1844 | if (dim > 0) { | |
| 1845 | - typ = new ArrayTypeName(typ, dim, | ||
| 1846 | - filename, | ||
| 1847 | - typ.getBeginLine(), typ.getBeginColumn(), | ||
| 1848 | - typ.getEndLine(), typ.getEndColumn()); | ||
| 1845 | + typ = new ArrayTypeName(typ, dim, false, | ||
| 1846 | + filename, | ||
| 1847 | + typ.getBeginLine(), typ.getBeginColumn(), | ||
| 1848 | + typ.getEndLine(), typ.getEndColumn()); | ||
| 1849 | 1849 | } | |
| 1850 | 1850 | return new FormalParameter(f != null, typ, id.image, | |
| 1851 | 1851 | filename, | |
@@ -1875,10 +1875,10 @@ PARSER_END(Parser) | |||
| 1875 | 1875 | [ f="final" ] typ=type() <VAR_ARGS> id=<IDENTIFIER> | |
| 1876 | 1876 | { | |
| 1877 | 1877 | // convert the type of the formal parameter to be an array | |
| 1878 | - typ = new ArrayTypeName(typ, 1, | ||
| 1879 | - filename, | ||
| 1880 | - typ.getBeginLine(), typ.getBeginColumn(), | ||
| 1881 | - typ.getEndLine(), typ.getEndColumn()); | ||
| 1878 | + typ = new ArrayTypeName(typ, 1, true, | ||
| 1879 | + filename, | ||
| 1880 | + typ.getBeginLine(), typ.getBeginColumn(), | ||
| 1881 | + typ.getEndLine(), typ.getEndColumn()); | ||
| 1882 | 1882 | return new FormalParameter(f != null, typ, id.image, | |
| 1883 | 1883 | filename, | |
| 1884 | 1884 | (f != null) ? f.beginLine : typ.getBeginLine(), | |
@@ -1887,7 +1887,7 @@ PARSER_END(Parser) | |||
| 1887 | 1887 | } | |
| 1888 | 1888 | } | |
| 1889 | 1889 | catch(ParseException pe) { | |
| 1890 | - _throwParseException(pe, "Invalid variable arguments formal parameter"); | ||
| 1890 | + _throwParseException(pe, "Invalid varargs formal parameter"); | ||
| 1891 | 1891 | } | |
| 1892 | 1892 | } | |
| 1893 | 1893 | ||
@@ -4110,10 +4110,10 @@ PARSER_END(Parser) | |||
| 4110 | 4110 | if (dim == 0) { | |
| 4111 | 4111 | return rt; | |
| 4112 | 4112 | } else { | |
| 4113 | - return new ArrayTypeName(rt, dim, | ||
| 4114 | - filename, | ||
| 4115 | - rt.getBeginLine(), rt.getBeginColumn(), | ||
| 4116 | - t.endLine, t.endColumn); | ||
| 4113 | + return new ArrayTypeName(rt, dim, false, | ||
| 4114 | + filename, | ||
| 4115 | + rt.getBeginLine(), rt.getBeginColumn(), | ||
| 4116 | + t.endLine, t.endColumn); | ||
| 4117 | 4117 | } | |
| 4118 | 4118 | } | |
| 4119 | 4119 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -187,7 +187,7 @@ void initialize(TypeName t) { | |||
| 187 | 187 | if (initialization != null) { | |
| 188 | 188 | TypeName et; | |
| 189 | 189 | if (dimension > 1) | |
| 190 | - et = new ArrayTypeName(t, dimension-1, t.getFilename(), t.getBeginLine(), t.getBeginColumn(), endLine, endColumn); | ||
| 190 | + et = new ArrayTypeName(t, dimension-1, false, t.getFilename(), t.getBeginLine(), t.getBeginColumn(), endLine, endColumn); | ||
| 191 | 191 | else | |
| 192 | 192 | et = t; | |
| 193 | 193 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,14 +48,16 @@ public class ArrayTypeName extends TypeName { | |||
| 48 | 48 | */ | |
| 49 | 49 | private TypeName elementType; | |
| 50 | 50 | ||
| 51 | + private boolean vararg; | ||
| 52 | + | ||
| 51 | 53 | /** | |
| 52 | 54 | * Initializes the type | |
| 53 | 55 | * @param et the element type | |
| 54 | 56 | * @param dim the dimension of the arrays represented by this type (> 0) | |
| 55 | 57 | * @exception IllegalArgumentException if et is null or dim < 1 | |
| 56 | 58 | */ | |
| 57 | - public ArrayTypeName(TypeName et, int dim) { | ||
| 58 | - this(et, dim, null, 0, 0, 0, 0); | ||
| 59 | + public ArrayTypeName(TypeName et, int dim, boolean varg) { | ||
| 60 | + this(et, dim, varg, null, 0, 0, 0, 0); | ||
| 59 | 61 | } | |
| 60 | 62 | ||
| 61 | 63 | /** | |
@@ -69,13 +71,14 @@ public ArrayTypeName(TypeName et, int dim) { | |||
| 69 | 71 | * @param ec the end column | |
| 70 | 72 | * @exception IllegalArgumentException if et is null or dim < 1 | |
| 71 | 73 | */ | |
| 72 | - public ArrayTypeName(TypeName et, int dim, String fn, int bl, int bc, int el, int ec) { | ||
| 74 | + public ArrayTypeName(TypeName et, int dim, boolean varg, String fn, int bl, int bc, int el, int ec) { | ||
| 73 | 75 | super(fn, bl, bc, el, ec); | |
| 74 | 76 | ||
| 75 | 77 | if (et == null) throw new IllegalArgumentException("et == null"); | |
| 76 | 78 | if (dim < 1) throw new IllegalArgumentException("dim < 1"); | |
| 77 | 79 | ||
| 78 | - elementType = (dim > 1) ? new ArrayTypeName(et, dim - 1, fn, bl, bc, el, ec) : et; | ||
| 80 | + elementType = (dim > 1) ? new ArrayTypeName(et, dim - 1, false, fn, bl, bc, el, ec) : et; | ||
| 81 | + vararg = varg; | ||
| 79 | 82 | } | |
| 80 | 83 | ||
| 81 | 84 | /** | |
@@ -95,6 +98,8 @@ public void setElementType(TypeName t) { | |||
| 95 | 98 | firePropertyChange(ELEMENT_TYPE, elementType, elementType = t); | |
| 96 | 99 | } | |
| 97 | 100 | ||
| 101 | + public boolean isVararg() { return vararg; } | ||
| 102 | + | ||
| 98 | 103 | /** | |
| 99 | 104 | * Allows a visitor to traverse the tree | |
| 100 | 105 | * @param visitor the visitor to accept | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -114,7 +114,7 @@ static List<Node> AddValues(String enumTypeName, List<Node> body, List<EnumConst | |||
| 114 | 114 | int accessFlags = java.lang.reflect.Modifier.PRIVATE | java.lang.reflect.Modifier.STATIC | java.lang.reflect.Modifier.FINAL; | |
| 115 | 115 | ||
| 116 | 116 | ReferenceTypeName enumType = new ReferenceTypeName(enumTypeName); | |
| 117 | - TypeName valuesType = new ArrayTypeName(enumType, 1); | ||
| 117 | + TypeName valuesType = new ArrayTypeName(enumType, 1, false); | ||
| 118 | 118 | List<Expression> sizes = new LinkedList<Expression>(); | |
| 119 | 119 | sizes.add(new IntegerLiteral(String.valueOf(consts_names.length))); | |
| 120 | 120 | List<Expression> cells = new LinkedList<Expression>(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,7 +78,7 @@ public static TypeName classToTypeName(Class<?> c, String fn, int bl, int bc, in | |||
| 78 | 78 | result = new VoidTypeName(fn, bl, bc, el, ec); | |
| 79 | 79 | } else if (c.isArray()) { | |
| 80 | 80 | result = new ArrayTypeName(classToTypeName(c.getComponentType(), fn, bl, bc, el, ec), | |
| 81 | - 1, fn, bl, bc, el, ec); | ||
| 81 | + 1, false, fn, bl, bc, el, ec); | ||
| 82 | 82 | } else { | |
| 83 | 83 | List<IdentifierToken> ids = new ArrayList<IdentifierToken>(1); | |
| 84 | 84 | ids.add(new Identifier(c.getName())); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,7 +70,7 @@ public void testClassToType() { | |||
| 70 | 70 | equals(TreeUtilities.classToTypeName(boolean.class))); | |
| 71 | 71 | assertEquals("",true,new VoidTypeName(). | |
| 72 | 72 | equals(TreeUtilities.classToTypeName(void.class))); | |
| 73 | - assertEquals("",true,new ArrayTypeName(new IntTypeName(),1). | ||
| 73 | + assertEquals("",true,new ArrayTypeName(new IntTypeName(),1, false). | ||
| 74 | 74 | equals(TreeUtilities.classToTypeName(int[].class))); | |
| 75 | 75 | assertEquals("",true,new ReferenceTypeName(Integer.class.getName()). | |
| 76 | 76 | equals(TreeUtilities.classToTypeName(Integer.class))); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments