示例#1
0
  private String getValue() {
    TypeSpec ts = const_type.symbol.typeSpec();
    while (ts instanceof AliasTypeSpec) {
      ts = ((AliasTypeSpec) ts).originalType();
    }

    if (logger.isDebugEnabled()) {
      logger.debug("ConstDecl(" + name + ": " + ts.getClass() + ") = " + const_type.toString());
    }

    // Bugzilla #851 - Infinity values wrapping
    String exprStr = const_expr.toString();
    if (exprStr != null && exprStr.contains("Infinity")) {
      logger.warn(
          "["
              + token.line_no
              + ":"
              + token.char_pos
              + "]"
              + "Infinity value used in const declaration");
      if (exprStr.startsWith("-")) {
        exprStr = "Double.NEGATIVE_INFINITY";
      } else {
        exprStr = "Double.POSITIVE_INFINITY";
      }
    }

    if (ts instanceof ShortType) {
      // short constant values have to be cast explicitly
      return ("(short)(" + exprStr + ")");
    } else if (ts instanceof FloatType) {
      // float constant values have to be cast explicitly
      return ("(float)(" + exprStr + ")");
    } else if (ts instanceof OctetType) {
      // byte constant values have to be cast explicitly
      return ("(byte)(" + exprStr + ")");
    } else if (ts instanceof FixedPointConstType || ts instanceof FixedPointType) {
      return ("new java.math.BigDecimal (" + exprStr + ")");
    } else if (ts instanceof LongLongType) {
      String cast = "";
      try {
        if (const_expr.or_expr.xor_expr.and_expr.shift_expr.operator != null
            || const_expr.or_expr.xor_expr.and_expr.shift_expr.add_expr.operator != null
            || const_expr.or_expr.xor_expr.and_expr.shift_expr.add_expr.mult_expr.operator
                != null) {
          cast = "(long)";
        }
      } catch (Exception e) {
        // Don't care if any of the above cause null ptr - just won't do cast.
      }
      return (cast + const_expr.toString());
    } else {
      return exprStr;
    }
  }
示例#2
0
  private ConstrTypeSpec unwindTypedefs(ScopedName scopedName) {
    TypeSpec resolvedTSpec = scopedName.resolvedTypeSpec();
    // unwind any typedefs
    while (resolvedTSpec instanceof AliasTypeSpec) {
      resolvedTSpec = ((AliasTypeSpec) resolvedTSpec).originalType();
    }

    if (!(resolvedTSpec instanceof ConstrTypeSpec)) {
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Illegal inheritance spec in Interface.unwindTypeDefs, not a constr. type but "
                + resolvedTSpec.getClass()
                + ", name "
                + scopedName);
      }
      parser.fatal_error(
          "Illegal inheritance spec in Interface.unwindTypeDefs (not a constr. type): "
              + inheritanceSpec,
          token);
    }

    return (ConstrTypeSpec) resolvedTSpec;
  }