Changeset 13714


Ignore:
Timestamp:
Oct 9, 2019 2:24:19 PM (2 months ago)
Author:
Jesper Mattsson
Message:

Updated error message for variability of format argument of String, and added additional tests. (#5835)

Location:
branches/dev-mj-5835/Compiler
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-mj-5835/Compiler/ModelicaCBackEnd/test/modelica/CCodeGenTests.mo

    r13702 r13714  
    1626216262end StringOperations11;
    1626316263
     16264
     16265model StringOperations12
     16266    type E = enumeration(Alice, Bob, Eve);
     16267
     16268    function f
     16269        input Integer x;
     16270        input E e;
     16271        output Real y;
     16272    protected
     16273        String s;
     16274    algorithm
     16275        s := String(x, format="7u") +
     16276             String(x, format="-3d") +
     16277             String(e);
     16278        y := x + .5;
     16279    end f;
     16280   
     16281    Real y = f(integer(time), if time < 1 then E.Alice else E.Eve);
     16282
     16283annotation(__JModelica(UnitTesting(tests={
     16284    CCodeGenTestCase(
     16285        name="StringOperations12",
     16286        description="Check that integer-typed format strings generate the correct casts",
     16287        template="$C_functions$",
     16288        generatedCode="
     16289void func_CCodeGenTests_StringOperations12_f_def0(jmi_real_t x_v, jmi_real_t e_v, jmi_real_t* y_o) {
     16290    JMI_DYNAMIC_INIT()
     16291    JMI_DEF(REA, y_v)
     16292    JMI_DEF(STR, s_v)
     16293    JMI_DEF_STR_STAT(tmp_1, 37)
     16294    JMI_INI(STR, s_v)
     16295    JMI_INI_STR_STAT(tmp_1)
     16296    snprintf(JMI_STR_END(tmp_1), JMI_STR_LEFT(tmp_1), \"%7u\", (unsigned int) x_v);
     16297    snprintf(JMI_STR_END(tmp_1), JMI_STR_LEFT(tmp_1), \"%-3d\", (int) x_v);
     16298    snprintf(JMI_STR_END(tmp_1), JMI_STR_LEFT(tmp_1), \"%-s\", E_0_e[(int) e_v]);
     16299    JMI_ASG(STR, s_v, tmp_1)
     16300    y_v = x_v + 0.5;
     16301    JMI_RET(GEN, y_o, y_v)
     16302    JMI_DYNAMIC_FREE()
     16303    return;
     16304}
     16305
     16306jmi_real_t func_CCodeGenTests_StringOperations12_f_exp0(jmi_real_t x_v, jmi_real_t e_v) {
     16307    JMI_DEF(REA, y_v)
     16308    func_CCodeGenTests_StringOperations12_f_def0(x_v, e_v, &y_v);
     16309    return y_v;
     16310}
     16311
     16312")})));
     16313end StringOperations12;
     16314
    1626416315package TestTerminate
    1626516316
  • branches/dev-mj-5835/Compiler/ModelicaFrontEnd/src/jastadd/errorcheck/ComplianceCheck.jadd

    r13702 r13714  
    284284    public static final SimpleProblemProducer ASTNode.UNSUPPORTED_NON_FIXED_STRING_ARGUMENT =
    285285            new SimpleErrorProducer("UNSUPPORTED_NON_FIXED_STRING_ARGUMENT", ProblemKind.COMPLIANCE,
    286                     "Argument %s of String operator is only supported as parameter expression.");
     286                    "Argument %s of String operator is only supported as a fixed parameter expression.");
    287287
    288288    public void FStringExp.complianceCheck(ErrorCheckType checkType) {
     
    290290        if (hasFormat()) {
    291291            getFormat().markAsStructuralParameter(checkType);
    292             // TODO: need to cover functions as well
    293292            if (!getFormat().variability().parameterOrLess())
    294293                UNSUPPORTED_NON_FIXED_STRING_ARGUMENT.invoke(getFormat(), "format");
  • branches/dev-mj-5835/Compiler/ModelicaFrontEnd/test/modelica/ComplianceTests.mo

    r13702 r13714  
    537537    Integer len = if time < 0 then 4 else 3;
    538538    Integer digits = if time < 0 then 5 else 2;
    539     String s = f(time, "g");
     539    String s1 = String(time, format = fmt1);
     540    String s2 = String(time, format = fmt2);
     541    String s3 = f(time, "g");
     542    parameter String fmt1 = if selFmt1 == 1 then "u" else "g";
     543    parameter String fmt2 = "f";
     544    parameter Integer selFmt1(fixed = false);
     545initial equation
     546    selFmt1 = if len == 4 then 1 else 2;
    540547equation
    541548    assert(time>2.0, String(time, significantDigits=digits, minimumLength=len, leftJustified=time<1));
    542549    assert(time>2.0, String(time, format=String(len)+"."+String(digits)+"f"));
    543     annotation(__JModelica(UnitTesting(tests={
    544         ComplianceErrorTestCase(
    545             name="StringOperator1",
    546             description="Test compliance warnings for non fixed string operator format argument",
    547             errorMessage="
    548 2 errors found:
    549  
    550 Compliance error at line 7, column 31, in file 'Compiler/ModelicaFrontEnd/test/modelica/ComplianceTests.mo', UNSUPPORTED_NON_FIXED_STRING_ARGUMENT:
    551  Argument format of String operator is only supported as parameter expression.
    552  
    553 Compliance error at line 15, column 42, in file 'Compiler/ModelicaFrontEnd/test/modelica/ComplianceTests.mo', UNSUPPORTED_NON_FIXED_STRING_ARGUMENT:
    554  Argument format of String operator is only supported as parameter expression.
    555    ")})));
     550annotation(__JModelica(UnitTesting(tests={
     551    ComplianceErrorTestCase(
     552        name="StringOperator1",
     553        description="Test compliance warnings for non fixed string operator format argument",
     554        errorMessage="
     555
     556
     557Compliance error at line 7, column 31, in file '...', UNSUPPORTED_NON_FIXED_STRING_ARGUMENT:
     558  Argument format of String operator is only supported as a fixed parameter expression.
     559
     560Compliance error at line 15, column 5, in file '...':
     561  Parameters with fixed=false can not be used as structural parameters
     562
     563Compliance error at line 22, column 42, in file '...', UNSUPPORTED_NON_FIXED_STRING_ARGUMENT:
     564  Argument format of String operator is only supported as a fixed parameter expression.
     565")})));
    556566end StringOperator1;
    557567
Note: See TracChangeset for help on using the changeset viewer.