Ejemplo n.º 1
0
 /**
  * Determines the sibling node of the given node that is part of a two component sum as described
  * in {@link COperandTreeNode#determineAddendValue}.
  *
  * @param node The node for which to determine the addend sibling.
  * @return The addend sibling or null if no such node exists.
  */
 private static INaviOperandTreeNode determineAddendSibling(final INaviOperandTreeNode node) {
   final INaviOperandTreeNode parent = node.getParent();
   if (parent == null || parent.getChildren().size() != 2 || !parent.getValue().equals("+")) {
     return null;
   }
   final INaviOperandTreeNode firstChild = parent.getChildren().get(0);
   final INaviOperandTreeNode secondChild = parent.getChildren().get(1);
   // One node must be an immediate integer in the pair to be a valid addend.
   if (firstChild.getType().equals(ExpressionType.IMMEDIATE_INTEGER)
       ^ secondChild.getType().equals(ExpressionType.IMMEDIATE_INTEGER)) {
     return firstChild == node ? secondChild : firstChild;
   }
   return null;
 }
Ejemplo n.º 2
0
 @Override
 public long determineAddendValue() {
   final INaviOperandTreeNode sibling =
       Preconditions.checkNotNull(
           determineAddendSibling(this), "Error: operand expression is not a two component sum.");
   // TODO(jannewger): there should be a sane way to determine the architecture of an instruction
   // (e.g. via an enum).
   if (sibling.getOperand().getInstruction().getArchitecture().equalsIgnoreCase("x86-64")) {
     return new BigInteger(sibling.getValue()).longValue();
   }
   // If the default assumption of a 32-bit architecture doesn't hold we'll get an exception here.
   // However, since the architecture might be unknown anyway we have no better way than to fail
   // here.
   return (int) Long.parseLong(sibling.getValue());
 }