Example #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;
    }
  }
Example #2
0
  public void parse() {
    digits = digit_expr.pos_int_const();
    scale = scale_expr.pos_int_const();

    if ((scale < 0) || (digits <= 0) || (scale > digits)) {
      parser.error(
          "Error in fixed point type "
              + typeName()
              + ", invalid format: <"
              + digits
              + ","
              + scale
              + ">");
    }
  }
Example #3
0
 int pos_int_const() {
   if (!int_const_set) {
     pos_int_const = const_expr.pos_int_const();
     int_const_set = true;
   }
   return pos_int_const;
 }
Example #4
0
 public void setPackage(String s) {
   s = parser.pack_replace(s);
   super.setPackage(s);
   const_type.setPackage(s);
   const_expr.setPackage(s);
   t.typeName = name;
   t.setPackage(s);
 }
Example #5
0
  public void parse() {
    const_expr.setDeclaration(this);
    try {
      NameTable.define(full_name(), IDLTypes.CONSTANT);
    } catch (NameAlreadyDefined p) {
      parser.error("Constant " + full_name() + " already defined", token);
    }
    const_type.parse();
    const_expr.parse();
    t.typeName = name;
    values.put(t.resolvedName() + (contained() ? "" : ".value"), const_expr.toString());

    if (logger.isDebugEnabled()) {
      logger.debug(
          "ConstDecl.parse, put value: "
              + t.resolvedName()
              + (contained() ? "" : ".value")
              + " , "
              + const_expr);
    }

    declarations.put(t.resolvedName(), this);
  }