Пример #1
0
  @Override
  protected String declareConversionFunction(
      final ILocation loc, final CPrimitive oldType, final CPrimitive newType) {

    final String functionName = "convert" + oldType.toString() + "To" + newType.toString();
    final String prefixedFunctionName = "~" + functionName;
    if (!mFunctionDeclarations.getDeclaredFunctions().containsKey(prefixedFunctionName)) {

      final Attribute[] attributes;
      final ASTType paramASTType = mTypeHandler.ctype2asttype(loc, oldType);
      if (newType.isFloatingType()) {
        attributes =
            generateAttributes(loc, mOverapproximateFloatingPointOperations, "to_real", null);
      } else if (newType.isIntegerType()) {
        attributes =
            generateAttributes(loc, mOverapproximateFloatingPointOperations, "to_int", null);
      } else {
        throw new AssertionError("unhandled case");
      }
      final ASTType[] params = new ASTType[] {paramASTType};
      final ASTType resultASTType = mTypeHandler.ctype2asttype(loc, newType);

      mFunctionDeclarations.declareFunction(
          loc, prefixedFunctionName, attributes, resultASTType, params);
    }
    return prefixedFunctionName;
  }
Пример #2
0
 @Override
 public Expression constructArithmeticFloatingPointExpression(
     final ILocation loc,
     final int nodeOperator,
     final Expression exp1,
     final CPrimitive type1,
     final Expression exp2,
     final CPrimitive type2) {
   if (mOverapproximateFloatingPointOperations) {
     final String functionName = "someBinaryArithmetic" + type1.toString() + "operation";
     final String prefixedFunctionName = "~" + functionName;
     if (!mFunctionDeclarations.getDeclaredFunctions().containsKey(prefixedFunctionName)) {
       final Attribute attribute =
           new NamedAttribute(
               loc,
               FunctionDeclarations.s_OVERAPPROX_IDENTIFIER,
               new Expression[] {new StringLiteral(loc, functionName)});
       final Attribute[] attributes = new Attribute[] {attribute};
       final ASTType astType = mTypeHandler.ctype2asttype(loc, type1);
       mFunctionDeclarations.declareFunction(
           loc, prefixedFunctionName, attributes, astType, astType, astType);
     }
     return new FunctionApplication(loc, prefixedFunctionName, new Expression[] {exp1, exp2});
   } else {
     return constructArithmeticExpression(loc, nodeOperator, exp1, exp2);
   }
 }
Пример #3
0
  @Override
  public Expression constructBinaryComparisonFloatingPointExpression(
      final ILocation loc,
      final int nodeOperator,
      final Expression exp1,
      final CPrimitive type1,
      final Expression exp2,
      final CPrimitive type2) {
    if (mOverapproximateFloatingPointOperations) {
      final String functionName = "someBinary" + type1.toString() + "ComparisonOperation";
      final String prefixedFunctionName = "~" + functionName;
      if (!mFunctionDeclarations.getDeclaredFunctions().containsKey(prefixedFunctionName)) {
        final Attribute attribute =
            new NamedAttribute(
                loc,
                FunctionDeclarations.s_OVERAPPROX_IDENTIFIER,
                new Expression[] {new StringLiteral(loc, functionName)});
        final Attribute[] attributes = new Attribute[] {attribute};
        final ASTType paramAstType = mTypeHandler.ctype2asttype(loc, type1);
        final ASTType resultAstType = new PrimitiveType(loc, SFO.BOOL);
        mFunctionDeclarations.declareFunction(
            loc, prefixedFunctionName, attributes, resultAstType, paramAstType, paramAstType);
      }
      return new FunctionApplication(loc, prefixedFunctionName, new Expression[] {exp1, exp2});
    } else {
      BinaryExpression.Operator op;
      switch (nodeOperator) {
        case IASTBinaryExpression.op_equals:
          op = BinaryExpression.Operator.COMPEQ;
          break;
        case IASTBinaryExpression.op_greaterEqual:
          op = BinaryExpression.Operator.COMPGEQ;
          break;
        case IASTBinaryExpression.op_greaterThan:
          op = BinaryExpression.Operator.COMPGT;
          break;
        case IASTBinaryExpression.op_lessEqual:
          op = BinaryExpression.Operator.COMPLEQ;
          break;
        case IASTBinaryExpression.op_lessThan:
          op = BinaryExpression.Operator.COMPLT;
          break;
        case IASTBinaryExpression.op_notequals:
          op = BinaryExpression.Operator.COMPNEQ;
          break;
        default:
          throw new AssertionError("Unknown BinaryExpression operator " + nodeOperator);
      }

      return ExpressionFactory.newBinaryExpression(loc, op, exp1, exp2);
    }
  }