Changeset 13502


Ignore:
Timestamp:
Sep 16, 2019 4:21:13 PM (3 months ago)
Author:
mjohnsson
Message:

#5835 Fixes for Format specifiers in Error messages.

Location:
branches/dev-mj-5835/Compiler/ModelicaFlatTree
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-mj-5835/Compiler/ModelicaFlatTree/src/jastadd/ConstantEvaluation/ConstantEvaluation.jrag

    r13498 r13502  
    28062806            formatChar == 'x' || formatChar == 'X' || formatChar == 'u' || formatChar == 'c';
    28072807        if (mustBeInteger && isReal) {
    2808             throw new ConstantEvaluationException(cval, "The format '"+ format + "' requires value of Integer type but Real is provided ");
     2808            throw new ConstantEvaluationException(cval, "format the resulting value. The format '"+ format + "' requires value of Integer type but Real is provided ");
    28092809        }
    28102810
    28112811        if (getValue().type().isInteger()) {
    28122812            // Java formatter do not convert types
    2813             final boolean convertToFloat = formatChar == 'e' || formatChar == 'E' || formatChar == 'f' || formatChar == 'g' || formatChar == 'G';
     2813            final boolean convertToFloat = formatChar == 'e' || formatChar == 'E' ||
     2814                    formatChar == 'f' || formatChar == 'g' || formatChar == 'G';
    28142815            if (convertToFloat) {
    28152816                return new CValueString(String.format((Locale) null, format, cval.realValue()));
    28162817            }
    28172818            if (formatChar == 'u') {
    2818                 String formatCorrect = format.substring(0, format.length() -1) + "s";
     2819                String formatCorrect = format.substring(0, format.length()-1) + "s";
    28192820                return new CValueString(String.format((Locale) null, formatCorrect, Integer.toUnsignedLong(cval.intValue())));
    28202821            }
    28212822
    28222823            if (formatChar == 'i') {
    2823                 String formatCorrect = format.substring(0, format.length() -1) + "d";
     2824                String formatCorrect = format.substring(0, format.length()-1) + "d";
    28242825                return new CValueString(String.format((Locale) null, formatCorrect, cval.intValue()));
    28252826            }
    28262827        }
    2827      
    2828         return new CValueString(String.format((Locale) null, format, value));
     2828       
     2829        try {
     2830            return new CValueString(String.format((Locale) null, format, value));
     2831        } catch (UnknownFormatConversionException e) {
     2832            throw new ConstantEvaluationException(cval,
     2833                    "format the resulting value. " + format + " is not a supported valid format string");
     2834        }
    28292835    }
    28302836    eq FGetInstanceName.cevalCalc(VariableEvaluator evaluator) = new CValueString(calcInstanceName());
  • branches/dev-mj-5835/Compiler/ModelicaFlatTree/test/modelica/EvaluationTests.mo

    r13498 r13502  
    48934893Error at line 3, column 25, in file '...':
    48944894  Could not evaluate binding expression for constant 's': 'String(x, \"3d\")'
    4895     Cannot The format '%3d' requires value of Integer type but Real is provided CValueReal (1.23456789)
     4895    Cannot format the resulting value. The format '%3d' requires value of Integer type but Real is provided CValueReal (1.23456789)
    48964896")})));
    48974897end StringRealformatSpecifier_d;
     
    49244924Error at line 3, column 25, in file '...':
    49254925  Could not evaluate binding expression for constant 's': 'String(x, \"3i\")'
    4926     Cannot The format '%3i' requires value of Integer type but Real is provided CValueReal (1.23456789)
     4926    Cannot format the resulting value. The format '%3i' requires value of Integer type but Real is provided CValueReal (1.23456789)
    49274927")})));
    49284928end StringRealformatSpecifier_i;
     
    49554955Error at line 3, column 25, in file '...':
    49564956  Could not evaluate binding expression for constant 's': 'String(x, \"3o\")'
    4957     Cannot The format '%3o' requires value of Integer type but Real is provided CValueReal (1.23456789)
     4957    Cannot format the resulting value. The format '%3o' requires value of Integer type but Real is provided CValueReal (1.23456789)
    49584958")})));
    49594959end StringRealformatSpecifier_o;
     
    49864986Error at line 3, column 25, in file '...':
    49874987  Could not evaluate binding expression for constant 's': 'String(x, \"3x\")'
    4988     Cannot The format '%3x' requires value of Integer type but Real is provided CValueReal (1.23456789)
     4988    Cannot format the resulting value. The format '%3x' requires value of Integer type but Real is provided CValueReal (1.23456789)
    49894989")})));
    49904990end StringRealformatSpecifier_x;
     
    50175017Error at line 3, column 25, in file '...':
    50185018  Could not evaluate binding expression for constant 's': 'String(x, \"3X\")'
    5019     Cannot The format '%3X' requires value of Integer type but Real is provided CValueReal (1.23456789)
     5019    Cannot format the resulting value. The format '%3X' requires value of Integer type but Real is provided CValueReal (1.23456789)
    50205020")})));
    50215021end StringRealformatSpecifier_X;
     
    50485048Error at line 3, column 25, in file '...':
    50495049  Could not evaluate binding expression for constant 's': 'String(x, \"3u\")'
    5050     Cannot The format '%3u' requires value of Integer type but Real is provided CValueReal (1.23456789)
     5050    Cannot format the resulting value. The format '%3u' requires value of Integer type but Real is provided CValueReal (1.23456789)
    50515051")})));
    50525052end StringRealformatSpecifier_u;
     
    50795079Error at line 3, column 25, in file '...':
    50805080  Could not evaluate binding expression for constant 's': 'String(x, \"3c\")'
    5081     Cannot The format '%3c' requires value of Integer type but Real is provided CValueReal (1.23456789)
     5081    Cannot format the resulting value. The format '%3c' requires value of Integer type but Real is provided CValueReal (1.23456789)
    50825082")})));
    50835083
     
    51005100end StringIntegerformatSpecifier_c;
    51015101
     5102model StringIncorrectformat
     5103    constant Integer x = 1234;
     5104    constant String s = String(x, format = "*.1.3c");
     5105
     5106annotation(__JModelica(UnitTesting(tests={
     5107    ErrorTestCase(
     5108        name="StringIncorrectformat",
     5109        description="String() operator, Real, format using c specifier",
     5110        errorMessage="
     5111Error at line 3, column 25, in file '...':
     5112  Could not evaluate binding expression for constant 's': 'String(x, \"*.1.3c\")'
     5113    Cannot format the resulting value. %*.1.3c is not a supported valid format stringCValueInteger (1234)
     5114")})));
     5115end StringIncorrectformat;
     5116
    51025117end StringConvert;
    51035118
Note: See TracChangeset for help on using the changeset viewer.