예제 #1
0
 public void genConversionOperation(
     FixedPrecisionType type, Context ctx, TabbedWriter out, AsExpression arg) {
   Type toType = arg.getEType();
   Type fromType = arg.getObjectExpr().getType();
   if ((arg.getConversionOperation() != null) && TypeUtils.isNumericType(fromType)) {
     if (needsConversion(fromType, toType)
         && CommonUtilities.proceedWithConversion(ctx, arg.getConversionOperation())) {
       out.print(ctx.getNativeImplementationMapping(toType) + '.');
       out.print(CommonUtilities.getOpName(ctx, arg.getConversionOperation()));
       out.print("(");
       Expression objectExpr = arg.getObjectExpr();
       if (objectExpr instanceof BoxingExpression) {
         objectExpr = ((BoxingExpression) objectExpr).getExpr();
       }
       ctx.invoke(genExpression, objectExpr, ctx, out);
       ctx.invoke(genTypeDependentOptions, arg.getEType(), ctx, out, arg);
       out.print(")");
     } else {
       ctx.invoke(genExpression, arg.getObjectExpr(), ctx, out);
     }
   } else {
     // we need to invoke the logic in type template to call back to the other conversion
     // situations
     ctx.invokeSuper(this, genConversionOperation, type, ctx, out, arg);
   }
 }
예제 #2
0
 protected boolean needsConversion(Operation conOp) {
   boolean result = true;
   Type fromType = conOp.getParameters().get(0).getType();
   Type toType = conOp.getReturnType();
   // don't convert matching types
   if (CommonUtilities.getEglNameForTypeCamelCase(toType)
       .equals(CommonUtilities.getEglNameForTypeCamelCase(fromType))) result = false;
   if (toType.getTypeSignature().equalsIgnoreCase("eglx.lang.ENumber")) result = true;
   else if (TypeUtils.isNumericType(fromType)
       && (TypeUtils.Type_DECIMAL.equals(fromType) || TypeUtils.Type_MONEY.equals(fromType)))
     result = conOp.isNarrowConversion();
   return result;
 }
예제 #3
0
 protected boolean needsConversion(Type fromType, Type toType) {
   boolean result = true;
   if (TypeUtils.isNumericType(fromType) && !CommonUtilities.needsConversion(fromType, toType))
     result = !CommonUtilities.isJavaScriptBigDecimal(toType);
   return result;
 }