How to extend cast-expression pre-checking
In `cif2plc` the "nop" cast and the "int to real" cast must be allowed by the pre-checker, implemented as ``` java @Override protected void preprocessCastExpression(CastExpression expr) { // Check supported. CifType ctype = normalizeType(expr.getChild().getType()); CifType rtype = normalizeType(expr.getType()); if (ctype instanceof IntType && rtype instanceof RealType) { // Integer to real conversion supported by PLC code. return; } if (CifTypeUtils.checkTypeCompat(ctype, rtype, RangeCompat.EQUAL)) { // Keeping the type the same is supported by removing the cast. return; } // Unsupported. String msg = fmt( "Unsupported expression \"%s\": casts from type \"%s\" to type \"%s\" are currently not supported.", exprToStr(expr), typeToStr(ctype), typeToStr(rtype)); problems.add(msg); } ``` In `ExprNoSpecificExprsCheck` (`oee.cif.common.checkers.checks`) a cast expression can be limited to types, which current lists values ``` java /** Disallow all cast expressions. */ CAST_EXPRS, /** Disallow cast expressions that cast to a different type. */ CAST_EXPRS_NON_EQUAL_TYPE, ``` As far as I can see there is no extension path in the above checks. You can set `CAST_EXPRS_NON_EQUAL_TYPE`, but then the int-to-real conversion get flagged as violation. Theoretically you could make "override" constants, but that doesn't seem like a good solution. You can make a `CAST_EXPRS_INT_TO_REAL` values that behaves like `CAST_EXPRS_NON_EQUAL_TYPE` except for the int-to-real conversion, but that breaks again as soon as you need a second exception. Addresses #424
issue

Copyright © Eclipse Foundation AISBL. All rights reserved.     Privacy Policy | Terms of Use | Copyright Agent