Project

General

Profile

Task #7527

constant casting while type conversion

Added by Sergey Smolov almost 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Expression
Target version:
Start date:
08/24/2016
Due date:
% Done:

100%

Estimated time:
Detected in build:
svn
Published in build:
0.4.21

Description

Add an option to NodeOperation object constructor that encodes constants casting mode.
By default an exception should be thrown when a "logic family" NodeOperation object(this family includes Boolean and arithmetical operations) has at least one non-constant operand of type that differ from at least one constant (NodeValue) operand's type.
When the option is set, all the constant operands, which types are different from non-constant operand types, should be casted to corresponding types. This technique should be performed in a recursive way (for NodeOperation object and for all it's NodeOperation operands and sub-...operands).
The option should have different values for signed and unsigned extension of bit vector constants.

History

#1

Updated by Sergey Smolov over 3 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

New methods have been implemented at TypeConversion and ConstCastRuleSet.
Here they are:

TypeConversion:

  /**
   * Converts the specified node to the specified data type with some constant casting if needed.
   * <p>If the specified node has the same data type as specified, no constant casting
   * is applied.</p>
   * @param node Node to be converted.
   * @param type Data type of the new node to be produced.
   * @param constCastType Constant operands casting mode.
   * @return A new node that has the specified data type but the rest of it's data are taken
   *         from the specified node. Constant sub-...operands are casted in correspondence
   *         with the specified mode.
   * @throws IllegalArgumentException when either node or data type argument is {@code null}.
   */
  public static Node coerce(final Node node, final DataType type, final Enum<?> constCastType)

ConstCastRuleSet:

  /**
   * Returns constant casting transformer for the specified casting type.
   * @param constCastType Constant casting type.
   * @return Transformer that performs constant operands casting.
   */
  public static NodeTransformer getRuleSet(final Enum<?> constCastType)

The enum of const casting types has been added to TypeConversion class:

  /**
   * Constant operands casting types.
   */
  public enum ConstCast {

    /**
     * Signed casting for constant operands is required.
     */
    SIGNED,

    /**
     * Unsigned casting for constant operands is required (a default value).
     */
    UNSIGNED,
  }

Done in r1315.

#2

Updated by Sergey Smolov over 3 years ago

  • Subject changed from constant casting option for NodeOperation constructor to constant casting while type conversion
#3

Updated by Andrei Tatarnikov over 3 years ago

  • Status changed from Resolved to Closed
  • Published in build set to 0.4.21

Also available in: Atom PDF