use of kalang.core.Type in project kalang by kasonyang.
the class Ast2Class method visitPrimitiveCastExpr.
@Override
public Object visitPrimitiveCastExpr(PrimitiveCastExpr node) {
ExprNode expr = node.getExpr();
visit(expr);
int opc;
Type ft = expr.getType();
Type tt = node.getToType();
opc = getPrimitiveCastOpc(ft, tt);
if (opc > 0) {
md.visitInsn(opc);
}
return null;
}
use of kalang.core.Type in project kalang by kasonyang.
the class Ast2Class method visitUnaryExpr.
@Override
public Object visitUnaryExpr(UnaryExpr node) {
Type exprType = node.getExpr().getType();
org.objectweb.asm.Type t = asmType(exprType);
visit(node.getExpr());
switch(node.getOperation()) {
case UnaryExpr.OPERATION_POS:
break;
case UnaryExpr.OPERATION_NEG:
md.visitInsn(t.getOpcode(INEG));
break;
case UnaryExpr.OPERATION_NOT:
// TODO here I am not sure
constX(exprType, -1);
md.visitInsn(t.getOpcode(IXOR));
break;
// md.visitInsn(ICONST_M1);
case UnaryExpr.OPERATION_LOGIC_NOT:
Label falseLabel = new Label();
Label stopLabel = new Label();
md.visitJumpInsn(IFEQ, falseLabel);
constFalse();
md.visitJumpInsn(GOTO, stopLabel);
md.visitLabel(falseLabel);
constTrue();
md.visitLabel(stopLabel);
break;
default:
throw new UnsupportedOperationException("unsupported unary operation:" + node.getOperation());
}
return null;
}
use of kalang.core.Type in project kalang by kasonyang.
the class Ast2Class method visitReturnStmt.
@Override
public Object visitReturnStmt(ReturnStmt node) {
int lnsn = RETURN;
if (node.expr != null) {
visit(node.expr);
Type type = node.expr.getType();
lnsn = asmType(type).getOpcode(IRETURN);
}
md.visitInsn(lnsn);
return null;
}
use of kalang.core.Type in project kalang by kasonyang.
the class Ast2Class method visitExprStmt.
@Override
public Object visitExprStmt(ExprStmt node) {
visitChildren(node);
Type type = node.getExpr().getType();
if (type != null && !Types.VOID_TYPE.equals(type)) {
pop(type);
}
return null;
}
use of kalang.core.Type in project kalang by kasonyang.
the class Ast2Class method typeSignature.
@Nullable
private String typeSignature(Type type) {
if (type instanceof GenericType) {
return "T" + type.getName() + ";";
} else if (type instanceof ClassType) {
ClassType pt = (ClassType) type;
String ptypes = "";
for (Type p : pt.getTypeArguments()) {
ptypes += typeSignature(p);
}
if (!ptypes.isEmpty())
ptypes = "<" + ptypes + ">";
return "L" + pt.getClassNode().name.replace('.', '/') + ptypes + ";";
} else if (type instanceof PrimitiveType) {
return getTypeDescriptor(type);
} else if (type instanceof ArrayType) {
return "[" + typeSignature(((ArrayType) type).getComponentType());
} else if (type instanceof WildcardType) {
WildcardType wt = (WildcardType) type;
Type[] lbs = wt.getLowerBounds();
Type[] ubs = wt.getUpperBounds();
if (lbs.length > 0) {
// FIXME handle other lowerBounds
return "-" + typeSignature(lbs[0]);
} else if (ubs.length > 0) {
// FIXME handle other lowerBounds
return "+" + typeSignature(ubs[0]);
} else {
return "*";
}
} else {
throw Exceptions.unsupportedTypeException(type);
}
}
Aggregations