Пример #1
0
    @Override
    protected Type visitIfExpression(IfExpression node, AnalysisContext context) {
      coerceType(context, node.getCondition(), BOOLEAN, "IF condition");

      Type type;
      if (node.getFalseValue().isPresent()) {
        type =
            coerceToSingleType(
                context,
                node,
                "Result types for IF must be the same: %s vs %s",
                node.getTrueValue(),
                node.getFalseValue().get());
      } else {
        type = process(node.getTrueValue(), context);
      }

      expressionTypes.put(node, type);
      return type;
    }
Пример #2
0
 @Override
 protected String visitIfExpression(IfExpression node, Boolean unmangleNames) {
   StringBuilder builder = new StringBuilder();
   builder
       .append("IF(")
       .append(process(node.getCondition(), unmangleNames))
       .append(", ")
       .append(process(node.getTrueValue(), unmangleNames));
   if (node.getFalseValue().isPresent()) {
     builder.append(", ").append(process(node.getFalseValue().get(), unmangleNames));
   }
   builder.append(")");
   return builder.toString();
 }