Changeset 13575


Ignore:
Timestamp:
Sep 23, 2019 2:08:00 PM (3 months ago)
Author:
jkulla
Message:

#5848 merge trunk to stable

Location:
branches/stable
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/CHANGELOG.txt

    r13404 r13575  
    11================= Unreleased ==================
     2# Fixed ; Minor ; Compiler; #5835
     3Format string argument to the String function is now useable.
     4
    25# Change ; Minor ; Compiler; #5830
    36ParseHandler now have a target for Subscript.
  • branches/stable/Compiler/ModelicaCBackEnd/src/jastadd/CCodeGen/CCodeGenExternal.jrag

    r11676 r13575  
    151151    }
    152152   
     153    @Override
     154    public void FSizeExp.genExternalCFuncArgs(CodePrinter p, CodeStream str, String indent, CodeGenContext cgc) {
     155        str.print("(size_t) ");
     156        super.genExternalCFuncArgs(p, str, indent, cgc);
     157    }
     158   
    153159}
  • branches/stable/Compiler/ModelicaCBackEnd/test/modelica/CCodeGenExternalCevalTests.mo

    r12934 r13575  
    158158    (x1,x2,x3,x4,x5) = f({1},{2},{true},{"s"},{E.A});
    159159
    160     annotation(__JModelica(UnitTesting(tests={
    161         CCodeGenTestCase(
    162             name="Array",
    163             description="Test code gen for external C functions evaluation. Arrays.",
    164             variability_propagation=false,
    165             inline_functions="none",
    166             template="
     160annotation(__JModelica(UnitTesting(tests={
     161    CCodeGenTestCase(
     162        name="Array",
     163        description="Test code gen for external C functions evaluation. Arrays.",
     164        variability_propagation=false,
     165        inline_functions="none",
     166        template="
    167167$ECE_external_includes$
    168168$ECE_record_definitions$
     
    185185$ECE_free$
    186186",
    187             generatedCode="
     187        generatedCode="
    188188---
    189189
     
    296296            jmi_copy_matrix_to_int(b5_a, b5_a->var, tmp_15->var);
    297297            tmp_16 = (int)f_arg19;
    298             f(a1_a->var, tmp_1, tmp_2->var, tmp_3, tmp_4->var, tmp_5, a4_a->var, tmp_6, tmp_7->var, tmp_8, b1_a->var, tmp_9, tmp_10->var, tmp_11, tmp_12->var, tmp_13, b4_a->var, tmp_14, tmp_15->var, tmp_16);
     298            f(a1_a->var, (size_t) tmp_1, tmp_2->var, (size_t) tmp_3, tmp_4->var, (size_t) tmp_5, a4_a->var, (size_t) tmp_6, tmp_7->var, (size_t) tmp_8, b1_a->var, (size_t) tmp_9, tmp_10->var, (size_t) tmp_11, tmp_12->var, (size_t) tmp_13, b4_a->var, (size_t) tmp_14, tmp_15->var, (size_t) tmp_16);
    299299            jmi_copy_matrix_from_int(b2_a, tmp_10->var, b2_a->var);
    300300            jmi_copy_matrix_from_int(b3_a, tmp_12->var, b3_a->var);
     
    311311
    312312---
    313 
    314313")})));
    315314end Array;
     
    382381    Real x = use2(o2);
    383382
    384     annotation(__JModelica(UnitTesting(tests={
    385         CCodeGenTestCase(
    386             name="ExtObj1",
    387             description="Test code gen for external C functions evaluation. External objects.",
    388             variability_propagation=false,
    389             inline_functions="none",
    390             template="
     383annotation(__JModelica(UnitTesting(tests={
     384    CCodeGenTestCase(
     385        name="ExtObj1",
     386        description="Test code gen for external C functions evaluation. External objects.",
     387        variability_propagation=false,
     388        inline_functions="none",
     389        template="
    391390$ECE_external_includes$
    392391$ECE_record_definitions$
     
    409408$ECE_free$
    410409",
    411             generatedCode="
     410        generatedCode="
    412411#include \"extObjects.h\"
    413412
     
    448447        tmp_4 = (int)tmp_6_arg5;
    449448        tmp_5 = (double)tmp_6_arg6;
    450         my_constructor2(tmp_6_arg0->var, tmp_2->var, &o2_v, tmp_3->var, tmp_6_arg4->var, tmp_4, tmp_5);
     449        my_constructor2(tmp_6_arg0->var, tmp_2->var, &o2_v, tmp_3->var, tmp_6_arg4->var, (size_t) tmp_4, tmp_5);
    451450
    452451---
     
    468467---
    469468        destructor(o2_v);
    470 
    471469")})));
    472470end ExtObj1;
     
    475473    extends ExtObj1(x=use3(o3));
    476474
    477     annotation(__JModelica(UnitTesting(tests={
    478         CCodeGenTestCase(
    479             name="ExtObj2",
    480             description="Test code gen for external C functions evaluation. External objects.",
    481             variability_propagation=false,
    482             inline_functions="none",
    483             template="
     475annotation(__JModelica(UnitTesting(tests={
     476    CCodeGenTestCase(
     477        name="ExtObj2",
     478        description="Test code gen for external C functions evaluation. External objects.",
     479        variability_propagation=false,
     480        inline_functions="none",
     481        template="
    484482$ECE_external_includes$
    485483$ECE_record_definitions$
     
    502500$ECE_free$
    503501",
    504             generatedCode="
     502        generatedCode="
    505503#include \"extObjects.h\"
    506504
     
    562560            tmp_11 = (int)tmp_13_arg5;
    563561            tmp_12 = (double)tmp_13_arg6;
    564             my_constructor2(tmp_13_arg0->var, tmp_9->var, &jmi_array_ref_1(tmp_2_arg1, tmp_7), tmp_10->var, tmp_13_arg4->var, tmp_11, tmp_12);
     562            my_constructor2(tmp_13_arg0->var, tmp_9->var, &jmi_array_ref_1(tmp_2_arg1, tmp_7), tmp_10->var, tmp_13_arg4->var, (size_t) tmp_11, tmp_12);
    565563        }
    566564        my_constructor3(tmp_2_arg0, tmp_2_arg1->var, &o3_v);
     
    588586---
    589587        destructor(o3_v);
    590 
    591588")})));
    592589end ExtObj2;
  • branches/stable/Compiler/ModelicaCBackEnd/test/modelica/CCodeGenExternalTests.mo

    r12934 r13575  
    11481148
    11491149
    1150     annotation(__JModelica(UnitTesting(tests={
    1151         CCodeGenTestCase(
    1152             name="ExternalArray1",
    1153             description="External C function (undeclared) with one dim array input, scalar output.",
    1154             variability_propagation=false,
    1155             template="
    1156 $C_function_headers$
    1157 $C_functions$
    1158 ",
    1159             generatedCode="
     1150annotation(__JModelica(UnitTesting(tests={
     1151    CCodeGenTestCase(
     1152        name="ExternalArray1",
     1153        description="External C function (undeclared) with one dim array input, scalar output.",
     1154        variability_propagation=false,
     1155        template="
     1156$C_function_headers$
     1157$C_functions$
     1158",
     1159        generatedCode="
    11601160void func_CCodeGenExternalTests_ExternalArray1_f_def0(jmi_array_t* a_a, jmi_real_t* b_o);
    11611161jmi_real_t func_CCodeGenExternalTests_ExternalArray1_f_exp0(jmi_array_t* a_a);
     
    11651165    JMI_DEF(REA, b_v)
    11661166    extern double f(double*, size_t);
    1167     b_v = f(a_a->var, jmi_array_size(a_a, 0));
     1167    b_v = f(a_a->var, (size_t) jmi_array_size(a_a, 0));
    11681168    JMI_RET(GEN, b_o, b_v)
    11691169    JMI_DYNAMIC_FREE()
     
    11761176    return b_v;
    11771177}
    1178 
    11791178
    11801179")})));
     
    11921191        b_out = f(a_in);
    11931192
    1194     annotation(__JModelica(UnitTesting(tests={
    1195         CCodeGenTestCase(
    1196             name="ExternalArray2",
    1197             description="External C function (undeclared) with two dim array input, scalar output.",
    1198             variability_propagation=false,
    1199             template="
    1200 $C_function_headers$
    1201 $C_functions$
    1202 ",
    1203             generatedCode="
     1193annotation(__JModelica(UnitTesting(tests={
     1194    CCodeGenTestCase(
     1195        name="ExternalArray2",
     1196        description="External C function (undeclared) with two dim array input, scalar output.",
     1197        variability_propagation=false,
     1198        template="
     1199$C_function_headers$
     1200$C_functions$
     1201",
     1202        generatedCode="
    12041203void func_CCodeGenExternalTests_ExternalArray2_f_def0(jmi_array_t* a_a, jmi_real_t* b_o);
    12051204jmi_real_t func_CCodeGenExternalTests_ExternalArray2_f_exp0(jmi_array_t* a_a);
     
    12091208    JMI_DEF(REA, b_v)
    12101209    extern double f(double*, size_t, size_t);
    1211     b_v = f(a_a->var, jmi_array_size(a_a, 0), jmi_array_size(a_a, 1));
     1210    b_v = f(a_a->var, (size_t) jmi_array_size(a_a, 0), (size_t) jmi_array_size(a_a, 1));
    12121211    JMI_RET(GEN, b_o, b_v)
    12131212    JMI_DYNAMIC_FREE()
     
    12201219    return b_v;
    12211220}
    1222 
    12231221
    12241222")})));
     
    12371235        b_out = f(a_in);
    12381236
    1239     annotation(__JModelica(UnitTesting(tests={
    1240         CCodeGenTestCase(
    1241             name="ExternalArray3",
    1242             description="External C function (undeclared) with two dim and unknown no of elements array input, scalar output.",
    1243             variability_propagation=false,
    1244             template="
    1245 $C_function_headers$
    1246 $C_functions$
    1247 ",
    1248             generatedCode="
     1237annotation(__JModelica(UnitTesting(tests={
     1238    CCodeGenTestCase(
     1239        name="ExternalArray3",
     1240        description="External C function (undeclared) with two dim and unknown no of elements array input, scalar output.",
     1241        variability_propagation=false,
     1242        template="
     1243$C_function_headers$
     1244$C_functions$
     1245",
     1246        generatedCode="
    12491247void func_CCodeGenExternalTests_ExternalArray3_f_def0(jmi_array_t* a_a, jmi_real_t* b_o);
    12501248jmi_real_t func_CCodeGenExternalTests_ExternalArray3_f_exp0(jmi_array_t* a_a);
     
    12541252    JMI_DEF(REA, b_v)
    12551253    extern double f(double*, size_t, size_t);
    1256     b_v = f(a_a->var, jmi_array_size(a_a, 0), jmi_array_size(a_a, 1));
     1254    b_v = f(a_a->var, (size_t) jmi_array_size(a_a, 0), (size_t) jmi_array_size(a_a, 1));
    12571255    JMI_RET(GEN, b_o, b_v)
    12581256    JMI_DYNAMIC_FREE()
     
    12651263    return b_v;
    12661264}
    1267 
    12681265
    12691266")})));
     
    12831280        b_out = f(a_in);
    12841281
    1285     annotation(__JModelica(UnitTesting(tests={
    1286         CCodeGenTestCase(
    1287             name="ExternalArray4",
    1288             description="External C function (undeclared) with one dim array input, one dim array output.",
    1289             variability_propagation=false,
    1290             template="
    1291 $C_function_headers$
    1292 $C_functions$
    1293 ",
    1294             generatedCode="
     1282annotation(__JModelica(UnitTesting(tests={
     1283    CCodeGenTestCase(
     1284        name="ExternalArray4",
     1285        description="External C function (undeclared) with one dim array input, one dim array output.",
     1286        variability_propagation=false,
     1287        template="
     1288$C_function_headers$
     1289$C_functions$
     1290",
     1291        generatedCode="
    12951292void func_CCodeGenExternalTests_ExternalArray4_f_def0(jmi_array_t* a_a, jmi_array_t* b_a);
    12961293
     
    13031300        b_a = b_an;
    13041301    }
    1305     f(a_a->var, jmi_array_size(a_a, 0), b_a->var, jmi_array_size(b_a, 0));
    1306     JMI_DYNAMIC_FREE()
    1307     return;
    1308 }
    1309 
     1302    f(a_a->var, (size_t) jmi_array_size(a_a, 0), b_a->var, (size_t) jmi_array_size(b_a, 0));
     1303    JMI_DYNAMIC_FREE()
     1304    return;
     1305}
    13101306
    13111307")})));
     
    13241320        b_out = f(a_in);
    13251321
    1326     annotation(__JModelica(UnitTesting(tests={
    1327         CCodeGenTestCase(
    1328             name="ExternalArray5",
    1329             description="External C function (undeclared) with two dim array input, two dim array output.",
    1330             variability_propagation=false,
    1331             template="
    1332 $C_function_headers$
    1333 $C_functions$
    1334 ",
    1335             generatedCode="
     1322annotation(__JModelica(UnitTesting(tests={
     1323    CCodeGenTestCase(
     1324        name="ExternalArray5",
     1325        description="External C function (undeclared) with two dim array input, two dim array output.",
     1326        variability_propagation=false,
     1327        template="
     1328$C_function_headers$
     1329$C_functions$
     1330",
     1331        generatedCode="
    13361332void func_CCodeGenExternalTests_ExternalArray5_f_def0(jmi_array_t* a_a, jmi_array_t* b_a);
    13371333
     
    13441340        b_a = b_an;
    13451341    }
    1346     f(a_a->var, jmi_array_size(a_a, 0), jmi_array_size(a_a, 1), b_a->var, jmi_array_size(b_a, 0), jmi_array_size(b_a, 1));
    1347     JMI_DYNAMIC_FREE()
    1348     return;
    1349 }
    1350 
     1342    f(a_a->var, (size_t) jmi_array_size(a_a, 0), (size_t) jmi_array_size(a_a, 1), b_a->var, (size_t) jmi_array_size(b_a, 0), (size_t) jmi_array_size(b_a, 1));
     1343    JMI_DYNAMIC_FREE()
     1344    return;
     1345}
    13511346
    13521347")})));
     
    13651360        b_out = f(a_in);
    13661361
    1367     annotation(__JModelica(UnitTesting(tests={
    1368         CCodeGenTestCase(
    1369             name="ExternalArray6",
    1370             description="External C function (undeclared) with two dim and unknown no of elements array input, two dim array output.",
    1371             variability_propagation=false,
    1372             template="
    1373 $C_function_headers$
    1374 $C_functions$
    1375 ",
    1376             generatedCode="
     1362annotation(__JModelica(UnitTesting(tests={
     1363    CCodeGenTestCase(
     1364        name="ExternalArray6",
     1365        description="External C function (undeclared) with two dim and unknown no of elements array input, two dim array output.",
     1366        variability_propagation=false,
     1367        template="
     1368$C_function_headers$
     1369$C_functions$
     1370",
     1371        generatedCode="
    13771372void func_CCodeGenExternalTests_ExternalArray6_f_def0(jmi_array_t* a_a, jmi_array_t* b_a);
    13781373
     
    13851380        b_a = b_an;
    13861381    }
    1387     f(a_a->var, jmi_array_size(a_a, 0), jmi_array_size(a_a, 1), b_a->var, jmi_array_size(b_a, 0), jmi_array_size(b_a, 1));
    1388     JMI_DYNAMIC_FREE()
    1389     return;
    1390 }
    1391 
     1382    f(a_a->var, (size_t) jmi_array_size(a_a, 0), (size_t) jmi_array_size(a_a, 1), b_a->var, (size_t) jmi_array_size(b_a, 0), (size_t) jmi_array_size(b_a, 1));
     1383    JMI_DYNAMIC_FREE()
     1384    return;
     1385}
    13921386
    13931387")})));
     
    14051399        b_out = f(a_in);
    14061400
    1407     annotation(__JModelica(UnitTesting(tests={
    1408         CCodeGenTestCase(
    1409             name="IntegerExternalArray1",
    1410             description="External C function (undeclared) with one dim Integer array input, scalar Real output.",
    1411             variability_propagation=false,
    1412             template="
    1413 $C_function_headers$
    1414 $C_functions$
    1415 ",
    1416             generatedCode="
     1401annotation(__JModelica(UnitTesting(tests={
     1402    CCodeGenTestCase(
     1403        name="IntegerExternalArray1",
     1404        description="External C function (undeclared) with one dim Integer array input, scalar Real output.",
     1405        variability_propagation=false,
     1406        template="
     1407$C_function_headers$
     1408$C_functions$
     1409",
     1410        generatedCode="
    14171411void func_CCodeGenExternalTests_IntegerExternalArray1_f_def0(jmi_array_t* a_a, jmi_real_t* b_o);
    14181412jmi_real_t func_CCodeGenExternalTests_IntegerExternalArray1_f_exp0(jmi_array_t* a_a);
     
    14251419    JMI_ARRAY_INIT_1(HEAP, jmi_int_t, jmi_int_array_t, tmp_1, jmi_array_size(a_a, 0), 1, jmi_array_size(a_a, 0))
    14261420    jmi_copy_matrix_to_int(a_a, a_a->var, tmp_1->var);
    1427     b_v = f(tmp_1->var, jmi_array_size(a_a, 0));
     1421    b_v = f(tmp_1->var, (size_t) jmi_array_size(a_a, 0));
    14281422    JMI_RET(GEN, b_o, b_v)
    14291423    JMI_DYNAMIC_FREE()
     
    14361430    return b_v;
    14371431}
    1438 
    14391432
    14401433")})));
     
    14521445        b_out = f(a_in);   
    14531446
    1454     annotation(__JModelica(UnitTesting(tests={
    1455         CCodeGenTestCase(
    1456             name="IntegerExternalArray2",
    1457             description="External C function (undeclared) with two dim Integer array input, scalar Real output.",
    1458             variability_propagation=false,
    1459             template="
    1460 $C_function_headers$
    1461 $C_functions$
    1462 ",
    1463             generatedCode="
     1447annotation(__JModelica(UnitTesting(tests={
     1448    CCodeGenTestCase(
     1449        name="IntegerExternalArray2",
     1450        description="External C function (undeclared) with two dim Integer array input, scalar Real output.",
     1451        variability_propagation=false,
     1452        template="
     1453$C_function_headers$
     1454$C_functions$
     1455",
     1456        generatedCode="
    14641457void func_CCodeGenExternalTests_IntegerExternalArray2_f_def0(jmi_array_t* a_a, jmi_real_t* b_o);
    14651458jmi_real_t func_CCodeGenExternalTests_IntegerExternalArray2_f_exp0(jmi_array_t* a_a);
     
    14721465    JMI_ARRAY_INIT_2(HEAP, jmi_int_t, jmi_int_array_t, tmp_1, jmi_array_size(a_a, 0) * jmi_array_size(a_a, 1), 2, jmi_array_size(a_a, 0), jmi_array_size(a_a, 1))
    14731466    jmi_copy_matrix_to_int(a_a, a_a->var, tmp_1->var);
    1474     b_v = f(tmp_1->var, jmi_array_size(a_a, 0), jmi_array_size(a_a, 1));
     1467    b_v = f(tmp_1->var, (size_t) jmi_array_size(a_a, 0), (size_t) jmi_array_size(a_a, 1));
    14751468    JMI_RET(GEN, b_o, b_v)
    14761469    JMI_DYNAMIC_FREE()
     
    14831476    return b_v;
    14841477}
    1485 
    14861478
    14871479")})));
     
    14991491        b_out = f(a_in);
    15001492
    1501     annotation(__JModelica(UnitTesting(tests={
    1502         CCodeGenTestCase(
    1503             name="IntegerExternalArray3",
    1504             description="External C function (undeclared) with one scalar Real input, one dim array Integer output.",
    1505             variability_propagation=false,
    1506             template="
    1507 $C_function_headers$
    1508 $C_functions$
    1509 ",
    1510             generatedCode="
     1493annotation(__JModelica(UnitTesting(tests={
     1494    CCodeGenTestCase(
     1495        name="IntegerExternalArray3",
     1496        description="External C function (undeclared) with one scalar Real input, one dim array Integer output.",
     1497        variability_propagation=false,
     1498        template="
     1499$C_function_headers$
     1500$C_functions$
     1501",
     1502        generatedCode="
    15111503void func_CCodeGenExternalTests_IntegerExternalArray3_f_def0(jmi_real_t a_v, jmi_array_t* b_a);
    15121504
     
    15221514    JMI_ARRAY_INIT_1(HEAP, jmi_int_t, jmi_int_array_t, tmp_1, jmi_array_size(b_a, 0), 1, jmi_array_size(b_a, 0))
    15231515    jmi_copy_matrix_to_int(b_a, b_a->var, tmp_1->var);
    1524     f(a_v, tmp_1->var, jmi_array_size(b_a, 0));
     1516    f(a_v, tmp_1->var, (size_t) jmi_array_size(b_a, 0));
    15251517    jmi_copy_matrix_from_int(b_a, tmp_1->var, b_a->var);
    15261518    JMI_DYNAMIC_FREE()
    15271519    return;
    15281520}
    1529 
    15301521
    15311522")})));
     
    15441535        b_out = f(a_in);   
    15451536
    1546     annotation(__JModelica(UnitTesting(tests={
    1547         CCodeGenTestCase(
    1548             name="IntegerExternalArray4",
    1549             description="External C function (undeclared) with one 2-dim Integer array input, one 2-dim Integer array output.",
    1550             variability_propagation=false,
    1551             template="
    1552 $C_function_headers$
    1553 $C_functions$
    1554 ",
    1555             generatedCode="
     1537annotation(__JModelica(UnitTesting(tests={
     1538    CCodeGenTestCase(
     1539        name="IntegerExternalArray4",
     1540        description="External C function (undeclared) with one 2-dim Integer array input, one 2-dim Integer array output.",
     1541        variability_propagation=false,
     1542        template="
     1543$C_function_headers$
     1544$C_functions$
     1545",
     1546        generatedCode="
    15561547void func_CCodeGenExternalTests_IntegerExternalArray4_f_def0(jmi_array_t* a_a, jmi_array_t* b_a);
    15571548
     
    15701561    JMI_ARRAY_INIT_2(HEAP, jmi_int_t, jmi_int_array_t, tmp_2, jmi_array_size(b_a, 0) * jmi_array_size(b_a, 1), 2, jmi_array_size(b_a, 0), jmi_array_size(b_a, 1))
    15711562    jmi_copy_matrix_to_int(b_a, b_a->var, tmp_2->var);
    1572     f(tmp_1->var, jmi_array_size(a_a, 0), jmi_array_size(a_a, 1), tmp_2->var, jmi_array_size(b_a, 0), jmi_array_size(b_a, 1));
     1563    f(tmp_1->var, (size_t) jmi_array_size(a_a, 0), (size_t) jmi_array_size(a_a, 1), tmp_2->var, (size_t) jmi_array_size(b_a, 0), (size_t) jmi_array_size(b_a, 1));
    15731564    jmi_copy_matrix_from_int(b_a, tmp_2->var, b_a->var);
    15741565    JMI_DYNAMIC_FREE()
    15751566    return;
    15761567}
    1577 
    15781568
    15791569")})));
  • branches/stable/Compiler/ModelicaCBackEnd/test/modelica/CCodeGenGlobalsTests.mo

    r13099 r13575  
    478478    Real y = f1(time) + f2(time);
    479479
    480     annotation(__JModelica(UnitTesting(tests={
    481         CCodeGenTestCase(
    482             name="GlobalConstantScalar1",
    483             description="Constants in external calls",
    484             variability_propagation=false,
    485             template="
     480annotation(__JModelica(UnitTesting(tests={
     481    CCodeGenTestCase(
     482        name="GlobalConstantScalar1",
     483        description="Constants in external calls",
     484        variability_propagation=false,
     485        template="
    486486$C_global_temps$
    487487$C_model_init_eval_independent_globals$
     
    489489$C_functions$
    490490",
    491             generatedCode="
     491        generatedCode="
    492492    jmi_real_t CCodeGenGlobalsTests_GlobalVariables_GlobalConstantScalar1_f1_c;
    493493    jmi_array_t* CCodeGenGlobalsTests_GlobalVariables_GlobalConstantScalar1_f1_d;
     
    555555    JMI_DEF(REA, y_v)
    556556    extern double f2(double, double, double*, size_t);
    557     y_v = f2(x_v, JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantScalar1_f2_c), JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantScalar1_f2_d)->var, jmi_array_size(JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantScalar1_f2_d), 0));
     557    y_v = f2(x_v, JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantScalar1_f2_c), JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantScalar1_f2_d)->var, (size_t) jmi_array_size(JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantScalar1_f2_d), 0));
    558558    JMI_RET(GEN, y_o, y_v)
    559559    JMI_DYNAMIC_FREE()
     
    14371437    JMI_DEF(EXO, eo_v)
    14381438    extern void* constructor(double*, size_t);
    1439     eo_v = constructor(x_a->var, jmi_array_size(x_a, 0));
     1439    eo_v = constructor(x_a->var, (size_t) jmi_array_size(x_a, 0));
    14401440    JMI_RET(GEN, eo_o, eo_v)
    14411441    JMI_DYNAMIC_FREE()
     
    14511451
    14521452    func_CCodeGenGlobalsTests_GlobalVariables_GlobalConstantExternalObject1_P_EO_destructor_def1(JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantExternalObject1_P_eo));
    1453 
    14541453")})));
    14551454end GlobalConstantExternalObject1;
  • branches/stable/Compiler/ModelicaFlatTree/src/jastadd/ConstantEvaluation/ConstantEvaluation.jrag

    r13433 r13575  
    27922792            return CValue.UNKNOWN;
    27932793        }
     2794       
    27942795        CValue cval = getValue().ceval(evaluator);
    2795         if (getValue().type().isReal()) {
     2796        boolean isReal = getValue().type().isReal();
     2797        if (isReal) {
    27962798            cval = cval.convertReal();
    27972799        }
    27982800        Object value = cval.objectValue();
    2799         String format = formatString(evaluator);
    2800         return new CValueString(String.format((Locale) null, format, value));
     2801        final String format = formatString(evaluator);
     2802        char formatChar = format.charAt(format.length() - 1);
     2803       
     2804        // Modelica allows Integer to Real conversion for formatting but not the other direction
     2805        boolean mustBeInteger = formatChar == 'd' || formatChar == 'i' || formatChar == 'o' ||
     2806            formatChar == 'x' || formatChar == 'X' || formatChar == 'u' || formatChar == 'c';
     2807        if (mustBeInteger && isReal) {
     2808            throw new ConstantEvaluationException(cval, "format the resulting value. The format '"+ format + "' requires value of Integer type but Real value is provided. ");
     2809        }
     2810
     2811        if (getValue().type().isInteger()) {
     2812            // Java formatter do not convert types
     2813            final boolean convertToFloat = formatChar == 'e' || formatChar == 'E' ||
     2814                    formatChar == 'f' || formatChar == 'g' || formatChar == 'G';
     2815            if (convertToFloat) {
     2816                return new CValueString(String.format((Locale) null, format, cval.realValue()));
     2817            }
     2818            if (formatChar == 'u') {
     2819                String formatCorrect = format.substring(0, format.length()-1) + "s";
     2820                long unsigned = ((long) cval.intValue()) & 0xffffffffL; // Java 8 Integer.toUnsignedLong
     2821                return new CValueString(String.format((Locale) null, formatCorrect, unsigned));
     2822            }
     2823
     2824            if (formatChar == 'i') {
     2825                String formatCorrect = format.substring(0, format.length()-1) + "d";
     2826                return new CValueString(String.format((Locale) null, formatCorrect, cval.intValue()));
     2827            }
     2828        }
     2829       
     2830        try {
     2831            return new CValueString(String.format((Locale) null, format, value));
     2832        } catch (java.util.IllegalFormatException e) {
     2833            throw new ConstantEvaluationException(cval,
     2834                    "format the resulting value. " + format + " is not a supported valid format string");
     2835        }
    28012836    }
    28022837    eq FGetInstanceName.cevalCalc(VariableEvaluator evaluator) = new CValueString(calcInstanceName());
  • branches/stable/Compiler/ModelicaFlatTree/src/jastadd/PrettyPrint.jrag

    r13357 r13575  
    11391139        getParameterEquations().prettyPrintWithFix(p, str, nextInd, "", ";" + str.getLineEnder());
    11401140   
     1141        prettyPrintEquations(p, str, indent);
     1142       
     1143        if (getNumFFunctionDecl() > 0 || getNumFRecordDecl() > 0 ||
     1144                getNumFEnumDecl() > 0 || getNumFDerivedType() > 0) {
     1145            str.println();
     1146            str.formatln("%spublic", indent);
     1147            p.print(getFFunctionDecls(), str, nextInd);
     1148            p.print(getFRecordDecls(), str, nextInd);
     1149            p.print(getFEnumDecls(), str, nextInd);
     1150            p.print(getFDerivedTypes(), str, nextInd);
     1151        }
     1152       
     1153        getFAttributeList().prettyPrintFAnnotationAttributeList(str, p, indent, ";" + str.getLineEnder());
     1154
     1155        str.println(indent, "end ", name(), ";");
     1156    }
     1157   
     1158    public void FClass.prettyPrintEquations(Printer p, CodeStream str, String indent) {
    11411159        boolean wroteEquation = false;
    1142         for (FAbstractEquation e : getFAbstractEquations()) {
     1160        String nextInd = p.indent(indent);
     1161        for (FAbstractEquation e : equationsForPrinting()) {
    11431162            if (e instanceof FAlgorithm) {
    11441163                p.print(e, str, indent);
     
    11551174            }
    11561175        }
    1157        
    1158         if (getNumFFunctionDecl() > 0 || getNumFRecordDecl() > 0 ||
    1159                 getNumFEnumDecl() > 0 || getNumFDerivedType() > 0) {
    1160             str.println();
    1161             str.formatln("%spublic", indent);
    1162             p.print(getFFunctionDecls(), str, nextInd);
    1163             p.print(getFRecordDecls(), str, nextInd);
    1164             p.print(getFEnumDecls(), str, nextInd);
    1165             p.print(getFDerivedTypes(), str, nextInd);
    1166         }
    1167        
    1168         getFAttributeList().prettyPrintFAnnotationAttributeList(str, p, indent, ";" + str.getLineEnder());
    1169 
    1170         str.println(indent, "end ", name(), ";");
     1176    }
     1177   
     1178    public Iterable<FAbstractEquation> FClass.equationsForPrinting() {
     1179        return getFAbstractEquations();
    11711180    }
    11721181
     
    22032212        getParameterEquations().prettyPrintWithFix(p, str, nextInd, "", ";" + str.getLineEnder());
    22042213    */
    2205         boolean wroteEquation = false;
    2206         for (FAbstractEquation e : getFAbstractEquations()) {
    2207             if (e instanceof FAlgorithm) {
    2208                 p.print(e, str, indent);
    2209                 wroteEquation = false;
    2210             } else {
    2211                 if (!e.isIgnored()) {
    2212                     if (!wroteEquation) {
    2213                         str.println(indent, "equation");
    2214                         wroteEquation = true;
    2215                     }
    2216                     p.print(e, str, nextInd);
    2217                     str.println(";");
    2218                 }
    2219             }
    2220         }
     2214        prettyPrintEquations(p, str, indent);
    22212215               
    22222216        str.println(indent, "end ", nameUnderscore(), ";");
  • branches/stable/Compiler/ModelicaFlatTree/src/jastadd/TypeAnalysis.jrag

    r13433 r13575  
    211211    inh CommonVariableDecl FExternalStmt.myConstructorOutput();
    212212    eq Root.getChild().myConstructorOutput() = null;
    213     eq FFunctionDecl.getChild().myConstructorOutput()     = myOutputs().get(0);
    214     eq InstFullClassDecl.getChild().myConstructorOutput() = myOutputs().get(0);
     213    eq FFunctionDecl.getChild().myConstructorOutput()      = myOutputs().get(0);
     214    eq InstFullClassDecl.getChild().myConstructorOutput()  = myOutputs().get(0);
     215    eq InstShortClassDecl.getChild().myConstructorOutput() = myOutputs().get(0);
    215216
    216217    public ArrayList<FExp> FExternalStmt.myConstructorArgs() {
  • branches/stable/Compiler/ModelicaFlatTree/src/jastadd/Variability.jrag

    r12811 r13575  
    243243    FTimeExp contributes this to FAbstractEquation.timeExps() for myFEquation();
    244244   
    245     syn boolean FAbstractEquation.isConstant()   = variability().constantVariability();
    246     syn boolean FAbstractEquation.isParameter()  = variability().parameterVariability();
    247     syn boolean FAbstractEquation.isDiscrete()   = variability().discreteVariability();
    248245    syn boolean FAbstractEquation.isContinuous() = variability().continuousVariability();
    249246
     
    258255    eq FVariable.isContinuous() = variability().continuousVariability();
    259256
     257    eq FRecordVariable.isConstant()   = variability().combine().constantVariability();
     258    eq FRecordVariable.isParameter()  = variability().combine().parameterVariability();
     259    eq FRecordVariable.isDiscrete()   = variability().combine().discreteVariability();
     260    eq FRecordVariable.isContinuous() = variability().combine().continuousVariability();
    260261
    261262    syn TypePrefixVariability FType.funcOutputVariability() = Variability.DISCRETE;
  • branches/stable/Compiler/ModelicaFlatTree/test/modelica/EvaluationTests.mo

    r13433 r13575  
    47224722end StringConvertWithParam2;
    47234723
     4724model StringRealformatSpecifier_f
     4725    constant Real x = 1.23456789;
     4726    constant String s = String(x, format = "1.3f");
     4727
     4728annotation(__JModelica(UnitTesting(tests={
     4729    FlatteningTestCase(
     4730        name="StringRealformatSpecifier_f",
     4731        description="String() operator,  Real, format using f specifier",
     4732        flatModel="
     4733fclass EvaluationTests.StringConvert.StringRealformatSpecifier_f
     4734 constant Real x = 1.23456789;
     4735 constant String s = \"1.235\";
     4736end EvaluationTests.StringConvert.StringRealformatSpecifier_f;
     4737")})));
     4738end StringRealformatSpecifier_f;
     4739
     4740model StringIntegerformatSpecifier_f
     4741    constant Integer x = 1234;
     4742    constant String s = String(x, format = "1.3f");
     4743
     4744annotation(__JModelica(UnitTesting(tests={
     4745    FlatteningTestCase(
     4746        name="StringIntegerformatSpecifier_f",
     4747        description="String() operator,  Integer, format using f specifier",
     4748        flatModel="
     4749fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_f
     4750 constant Integer x = 1234;
     4751 constant String s = \"1234.000\";
     4752end EvaluationTests.StringConvert.StringIntegerformatSpecifier_f;
     4753")})));
     4754end StringIntegerformatSpecifier_f;
     4755
     4756model StringRealformatSpecifier_e
     4757    constant Real x = 1.23456789;
     4758    constant String s = String(x, format = "1.3e");
     4759
     4760annotation(__JModelica(UnitTesting(tests={
     4761    FlatteningTestCase(
     4762        name="StringRealformatSpecifier_e",
     4763        description="String() operator,  Real, format using e specifier",
     4764        flatModel="
     4765fclass EvaluationTests.StringConvert.StringRealformatSpecifier_e
     4766 constant Real x = 1.23456789;
     4767 constant String s = \"1.235e+00\";
     4768end EvaluationTests.StringConvert.StringRealformatSpecifier_e;
     4769")})));
     4770end StringRealformatSpecifier_e;
     4771
     4772model StringIntegerformatSpecifier_e
     4773    constant Integer x = 1234;
     4774    constant String s = String(x, format = "1.3e");
     4775
     4776annotation(__JModelica(UnitTesting(tests={
     4777    FlatteningTestCase(
     4778        name="StringIntegerformatSpecifier_e",
     4779        description="String() operator, Integer, format using e specifier",
     4780        flatModel="
     4781fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_e
     4782 constant Integer x = 1234;
     4783 constant String s = \"1.234e+03\";
     4784end EvaluationTests.StringConvert.StringIntegerformatSpecifier_e;
     4785")})));
     4786end StringIntegerformatSpecifier_e;
     4787
     4788model StringRealformatSpecifier_E
     4789    constant Real x = 1.23456789;
     4790    constant String s = String(x, format = "1.3E");
     4791
     4792annotation(__JModelica(UnitTesting(tests={
     4793    FlatteningTestCase(
     4794        name="StringRealformatSpecifier_E",
     4795        description="String() operator,  Real, format using E specifier",
     4796        flatModel="
     4797fclass EvaluationTests.StringConvert.StringRealformatSpecifier_E
     4798 constant Real x = 1.23456789;
     4799 constant String s = \"1.235E+00\";
     4800end EvaluationTests.StringConvert.StringRealformatSpecifier_E;
     4801")})));
     4802end StringRealformatSpecifier_E;
     4803
     4804model StringIntegerformatSpecifier_E
     4805    constant Integer x = 1234;
     4806    constant String s = String(x, format = "1.3E");
     4807
     4808annotation(__JModelica(UnitTesting(tests={
     4809    FlatteningTestCase(
     4810        name="StringIntegerformatSpecifier_E",
     4811        description="String() operator,  Integer, format using E specifier",
     4812        flatModel="
     4813fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_E
     4814 constant Integer x = 1234;
     4815 constant String s = \"1.234E+03\";
     4816end EvaluationTests.StringConvert.StringIntegerformatSpecifier_E;
     4817")})));
     4818end StringIntegerformatSpecifier_E;
     4819
     4820model StringRealformatSpecifier_g
     4821    constant Real x = 1.23456789;
     4822    constant String s = String(x, format = "1.3g");
     4823
     4824annotation(__JModelica(UnitTesting(tests={
     4825    FlatteningTestCase(
     4826        name="StringRealformatSpecifier_g",
     4827        description="String() operator, Real, format using g specifier",
     4828        flatModel="
     4829fclass EvaluationTests.StringConvert.StringRealformatSpecifier_g
     4830 constant Real x = 1.23456789;
     4831 constant String s = \"1.23\";
     4832end EvaluationTests.StringConvert.StringRealformatSpecifier_g;
     4833")})));
     4834end StringRealformatSpecifier_g;
     4835
     4836model StringIntegerformatSpecifier_g
     4837    constant Integer x = 1234;
     4838    constant String s = String(x, format = "1.3g");
     4839
     4840annotation(__JModelica(UnitTesting(tests={
     4841    FlatteningTestCase(
     4842        name="StringIntegerformatSpecifier_g",
     4843        description="String() operator,  Integer, format using g specifier",
     4844        flatModel="
     4845fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_g
     4846 constant Integer x = 1234;
     4847 constant String s = \"1.23e+03\";
     4848end EvaluationTests.StringConvert.StringIntegerformatSpecifier_g;
     4849")})));
     4850end StringIntegerformatSpecifier_g;
     4851
     4852model StringRealformatSpecifier_G
     4853    constant Real x = 1.23456789;
     4854    constant String s = String(x, format = "1.3G");
     4855
     4856annotation(__JModelica(UnitTesting(tests={
     4857    FlatteningTestCase(
     4858        name="StringRealformatSpecifier_G",
     4859        description="String() operator, Real, format using G specifier",
     4860        flatModel="
     4861fclass EvaluationTests.StringConvert.StringRealformatSpecifier_G
     4862 constant Real x = 1.23456789;
     4863 constant String s = \"1.23\";
     4864end EvaluationTests.StringConvert.StringRealformatSpecifier_G;
     4865")})));
     4866end StringRealformatSpecifier_G;
     4867
     4868model StringIntegerformatSpecifier_G
     4869    constant Integer x = 1234;
     4870    constant String s = String(x, format = "1.3G");
     4871
     4872annotation(__JModelica(UnitTesting(tests={
     4873    FlatteningTestCase(
     4874        name="StringIntegerformatSpecifier_G",
     4875        description="String() operator,  Integer, format using G specifier",
     4876        flatModel="
     4877fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_G
     4878 constant Integer x = 1234;
     4879 constant String s = \"1.23E+03\";
     4880end EvaluationTests.StringConvert.StringIntegerformatSpecifier_G;
     4881")})));
     4882end StringIntegerformatSpecifier_G;
     4883
     4884model StringRealformatSpecifier_d
     4885    constant Real x = 1.23456789;
     4886    constant String s = String(x, format = "3d");
     4887
     4888annotation(__JModelica(UnitTesting(tests={
     4889      ErrorTestCase(
     4890            name="StringRealformatSpecifier_d",
     4891            description="String() operator, Real, format using d specifier",
     4892            errorMessage="
     4893Error at line 3, column 25, in file '...':
     4894  Could not evaluate binding expression for constant 's': 'String(x, \"3d\")'
     4895    Cannot format the resulting value. The format '%3d' requires value of Integer type but Real value is provided. CValueReal (1.23456789)
     4896")})));
     4897end StringRealformatSpecifier_d;
     4898
     4899model StringIntegerformatSpecifier_d
     4900    constant Integer x = 1234;
     4901    constant String s = String(x, format = "3d");
     4902
     4903annotation(__JModelica(UnitTesting(tests={
     4904    FlatteningTestCase(
     4905        name="StringIntegerformatSpecifier_d",
     4906        description="String() operator,  Integer, format using d specifier",
     4907        flatModel="
     4908fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_d
     4909 constant Integer x = 1234;
     4910 constant String s = \"1234\";
     4911end EvaluationTests.StringConvert.StringIntegerformatSpecifier_d;
     4912")})));
     4913end StringIntegerformatSpecifier_d;
     4914
     4915model StringRealformatSpecifier_i
     4916    constant Real x = 1.23456789;
     4917    constant String s = String(x, format = "3i");
     4918
     4919annotation(__JModelica(UnitTesting(tests={
     4920    ErrorTestCase(
     4921        name="StringRealformatSpecifier_i",
     4922        description="String() operator, Real, format using i specifier",
     4923        errorMessage="
     4924Error at line 3, column 25, in file '...':
     4925  Could not evaluate binding expression for constant 's': 'String(x, \"3i\")'
     4926    Cannot format the resulting value. The format '%3i' requires value of Integer type but Real value is provided. CValueReal (1.23456789)
     4927")})));
     4928end StringRealformatSpecifier_i;
     4929
     4930model StringIntegerformatSpecifier_i
     4931    constant Integer x = 1234;
     4932    constant String s = String(x, format = "3i");
     4933
     4934annotation(__JModelica(UnitTesting(tests={
     4935    FlatteningTestCase(
     4936        name="StringIntegerformatSpecifier_i",
     4937        description="String() operator,  Integer, format using i specifier",
     4938        flatModel="
     4939fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_i
     4940 constant Integer x = 1234;
     4941 constant String s = \"1234\";
     4942end EvaluationTests.StringConvert.StringIntegerformatSpecifier_i;
     4943")})));
     4944end StringIntegerformatSpecifier_i;
     4945
     4946model StringRealformatSpecifier_o
     4947    constant Real x = 1.23456789;
     4948    constant String s = String(x, format = "3o");
     4949
     4950annotation(__JModelica(UnitTesting(tests={
     4951    ErrorTestCase(
     4952        name="StringRealformatSpecifier_o",
     4953        description="String() operator, Real, format using o specifier",
     4954        errorMessage="
     4955Error at line 3, column 25, in file '...':
     4956  Could not evaluate binding expression for constant 's': 'String(x, \"3o\")'
     4957    Cannot format the resulting value. The format '%3o' requires value of Integer type but Real value is provided. CValueReal (1.23456789)
     4958")})));
     4959end StringRealformatSpecifier_o;
     4960
     4961model StringIntegerformatSpecifier_o
     4962    constant Integer x = 1234;
     4963    constant String s = String(x, format = "3o");
     4964
     4965annotation(__JModelica(UnitTesting(tests={
     4966    FlatteningTestCase(
     4967        name="StringIntegerformatSpecifier_o",
     4968        description="String() operator,  Integer, format using o specifier",
     4969        flatModel="
     4970fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_o
     4971 constant Integer x = 1234;
     4972 constant String s = \"2322\";
     4973end EvaluationTests.StringConvert.StringIntegerformatSpecifier_o;
     4974")})));
     4975end StringIntegerformatSpecifier_o;
     4976
     4977model StringRealformatSpecifier_x
     4978    constant Real x = 1.23456789;
     4979    constant String s = String(x, format = "3x");
     4980
     4981annotation(__JModelica(UnitTesting(tests={
     4982    ErrorTestCase(
     4983        name="StringRealformatSpecifier_x",
     4984        description="String() operator, Real, format using x specifier",
     4985        errorMessage="
     4986Error at line 3, column 25, in file '...':
     4987  Could not evaluate binding expression for constant 's': 'String(x, \"3x\")'
     4988    Cannot format the resulting value. The format '%3x' requires value of Integer type but Real value is provided. CValueReal (1.23456789)
     4989")})));
     4990end StringRealformatSpecifier_x;
     4991
     4992model StringIntegerformatSpecifier_x
     4993    constant Integer x = 1234;
     4994    constant String s = String(x, format = "3x");
     4995
     4996annotation(__JModelica(UnitTesting(tests={
     4997    FlatteningTestCase(
     4998        name="StringIntegerformatSpecifier_x",
     4999        description="String() operator,  Integer, format using x specifier",
     5000        flatModel="
     5001fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_x
     5002 constant Integer x = 1234;
     5003 constant String s = \"4d2\";
     5004end EvaluationTests.StringConvert.StringIntegerformatSpecifier_x;
     5005")})));
     5006end StringIntegerformatSpecifier_x;
     5007
     5008model StringRealformatSpecifier_X
     5009    constant Real x = 1.23456789;
     5010    constant String s = String(x, format = "3X");
     5011
     5012annotation(__JModelica(UnitTesting(tests={
     5013    ErrorTestCase(
     5014        name="StringRealformatSpecifier_X",
     5015        description="String() operator, Real, format using X specifier",
     5016        errorMessage="
     5017Error at line 3, column 25, in file '...':
     5018  Could not evaluate binding expression for constant 's': 'String(x, \"3X\")'
     5019    Cannot format the resulting value. The format '%3X' requires value of Integer type but Real value is provided. CValueReal (1.23456789)
     5020")})));
     5021end StringRealformatSpecifier_X;
     5022
     5023model StringIntegerformatSpecifier_X
     5024    constant Integer x = 1234;
     5025    constant String s = String(x, format = "3X");
     5026
     5027annotation(__JModelica(UnitTesting(tests={
     5028    FlatteningTestCase(
     5029        name="StringIntegerformatSpecifier_X",
     5030        description="String() operator,  Integer, format using X specifier",
     5031        flatModel="
     5032fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_X
     5033 constant Integer x = 1234;
     5034 constant String s = \"4D2\";
     5035end EvaluationTests.StringConvert.StringIntegerformatSpecifier_X;
     5036")})));
     5037end StringIntegerformatSpecifier_X;
     5038
     5039model StringRealformatSpecifier_u
     5040    constant Real x = 1.23456789;
     5041    constant String s = String(x, format = "3u");
     5042
     5043annotation(__JModelica(UnitTesting(tests={
     5044    ErrorTestCase(
     5045        name="StringRealformatSpecifier_u",
     5046        description="String() operator, Real, format using u specifier",
     5047        errorMessage="
     5048Error at line 3, column 25, in file '...':
     5049  Could not evaluate binding expression for constant 's': 'String(x, \"3u\")'
     5050    Cannot format the resulting value. The format '%3u' requires value of Integer type but Real value is provided. CValueReal (1.23456789)
     5051")})));
     5052end StringRealformatSpecifier_u;
     5053
     5054model StringIntegerformatSpecifier_u
     5055    constant Integer x = -1234;
     5056    constant String s = String(x, format = "3u");
     5057
     5058annotation(__JModelica(UnitTesting(tests={
     5059    FlatteningTestCase(
     5060        name="StringIntegerformatSpecifier_u",
     5061        description="String() operator,  Integer, format using u specifier",
     5062        flatModel="
     5063fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_u
     5064 constant Integer x = -1234;
     5065 constant String s = \"4294966062\";
     5066end EvaluationTests.StringConvert.StringIntegerformatSpecifier_u;
     5067")})));
     5068end StringIntegerformatSpecifier_u;
     5069
     5070model StringRealformatSpecifier_c
     5071    constant Real x = 1.23456789;
     5072    constant String s = String(x, format = "3c");
     5073
     5074annotation(__JModelica(UnitTesting(tests={
     5075    ErrorTestCase(
     5076        name="StringRealformatSpecifier_c",
     5077        description="String() operator, Real, format using c specifier",
     5078        errorMessage="
     5079Error at line 3, column 25, in file '...':
     5080  Could not evaluate binding expression for constant 's': 'String(x, \"3c\")'
     5081    Cannot format the resulting value. The format '%3c' requires value of Integer type but Real value is provided. CValueReal (1.23456789)
     5082")})));
     5083
     5084end StringRealformatSpecifier_c;
     5085
     5086model StringIntegerformatSpecifier_c
     5087    constant Integer x = 123;
     5088    constant String s = String(x, format = "3c");
     5089
     5090annotation(__JModelica(UnitTesting(tests={
     5091    FlatteningTestCase(
     5092        name="StringIntegerformatSpecifier_c",
     5093        description="String() operator,  Integer, format using c specifier",
     5094        flatModel="
     5095fclass EvaluationTests.StringConvert.StringIntegerformatSpecifier_c
     5096 constant Integer x = 123;
     5097 constant String s = \"  {\";
     5098end EvaluationTests.StringConvert.StringIntegerformatSpecifier_c;
     5099")})));
     5100end StringIntegerformatSpecifier_c;
     5101
     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
    47245117end StringConvert;
    47255118
  • branches/stable/Compiler/ModelicaFrontEnd/src/jastadd/flattening/Flattening.jrag

    r13504 r13575  
    779779                new FCExternalLanguage());
    780780        stmt.extractLibrary(this);
     781        contribute(stmt);
    781782        if (hasInstExternalCall()) {
    782783            InstExternalCall call = getInstExternalCall();
     
    832833        stmt.extractLibrary(this);
    833834        sl.add(stmt);
     835        contribute(stmt);
    834836        return false;
    835837    }
     
    21562158            List<FAttribute> attrs, AttributeExpRetriever aer, boolean cls) {}
    21572159
    2158     syn boolean InstComponentDecl.isBuiltIn() = false;
    2159     eq InstBuiltIn.isBuiltIn()                = true;
    2160     syn boolean InstBuiltInClassDecl.isBuiltIn()                = true;
    2161     syn boolean SrcBuiltInClassDecl.isBuiltIn()       = true;
    2162     syn boolean SrcClassDecl.isBuiltIn() = ((SourceRoot) root()).getProgram().getBuiltInTypes().hasChild(this)
    2163             || ((SourceRoot) root()).getProgram().getBuiltInFunctions().hasChild(this);
    2164    
    2165     public boolean List.hasChild(ASTNode node) {
    2166         for(ASTNode child : children) {
    2167             if(child == node) {
    2168                 return true;
    2169             }
    2170         }
    2171         return false;
    2172     }
    2173    
    2174 
     2160    syn boolean InstComponentDecl.isBuiltIn()    = false;
     2161    eq InstBuiltIn.isBuiltIn()                   = true;
     2162    syn boolean InstBuiltInClassDecl.isBuiltIn() = true;
     2163    syn boolean SrcBuiltInClassDecl.isBuiltIn()  = true;
     2164    inh boolean SrcClassDecl.isBuiltIn();
     2165    eq Root.getChild().isBuiltIn() = false;
     2166    eq Program.getBuiltInType().isBuiltIn() = true;
     2167    eq Program.getBuiltInFunction().isBuiltIn() = true;
     2168   
     2169    syn SourceRoot Root.asSourceRoot() {
     2170        throw new UnsupportedOperationException("Method not implemented for class " + getClass().getSimpleName() + "!");
     2171    }
     2172    eq SourceRoot.asSourceRoot() = this;
     2173   
    21752174    public void InstComponentModification.collectAttributes(Flattener f,
    21762175            List<FAttribute> attrs, AttributeExpRetriever aer, boolean cls) {
     
    34363435
    34373436        /**
     3437         * This method is called during flattening of external statements. All
     3438         * expressions that are added must be flattened.
     3439         */
     3440        protected void contribute(AnnotationNode src, FExternalStmt dest) {}
     3441
     3442        /**
    34383443         * This method is called in order to determine if an attribute should
    34393444         * be considered as active. Return true if the attributes that was
     
    35263531    }
    35273532   
     3533    public class InstExternal {
     3534        public FExternalStmt contribute(FExternalStmt stmt) {
     3535            for (AttributeContributor contributor : attributeContributors()) {
     3536                contributor.contribute(annotation(), stmt);
     3537            }
     3538            return stmt;
     3539        }
     3540    }
     3541   
     3542    public class FExternalStmt {
     3543        public FExternalStmt contribute(FExternalStmt stmt) {
     3544            for (AttributeContributor contributor : attributeContributors()) {
     3545                contributor.contribute(annotation(), stmt);
     3546            }
     3547            return stmt;
     3548        }
     3549    }
     3550   
    35283551}
    35293552
  • branches/stable/Compiler/ModelicaFrontEnd/src/jastadd/instance/InstLookupClasses.jrag

    r13317 r13575  
    258258
    259259    syn lazy HashMap<String,SrcLibNode> InstProgramRoot.libraryMap() {
    260         Program prog = ((SourceRoot) root()).getProgram();
     260        Program prog = root().asSourceRoot().getProgram();
    261261        HashMap<String,SrcLibNode> map = new HashMap<String,SrcLibNode>(prog.getNumSrcLibNode() * 4 / 3 + 1);
    262262        for (SrcLibNode ln : prog.getSrcLibNodes()) {
  • branches/stable/Compiler/ModelicaFrontEnd/src/jastadd/instance/InstanceTree.jrag

    r13396 r13575  
    17681768        hasInstClassModification() ||
    17691769        getSrcClassDecl().hasSrcTypePrefix() ||
    1770         !filteredEnvironment().isEmpty();
     1770        !filteredEnvironment().isEmpty() ||
     1771        inExternalObject();
    17711772    eq InstReplacingShortClassDecl.shouldBeExpanded() =
    17721773        super.shouldBeExpanded() ||
  • branches/stable/Compiler/ModelicaFrontEnd/src/jastadd/instance/Types.jrag

    r13504 r13575  
    6868   
    6969    syn boolean SrcBaseNode.isPrimitiveType() = false;
    70     eq SrcClassDecl.isPrimitiveType() = isPrimitive();
     70    eq SrcClassDecl.isPrimitiveType()         = isPrimitive();
    7171
    7272    public static String InstNode.subTypeMessage(String name, String message) {
  • branches/stable/Compiler/ModelicaFrontEnd/src/jastadd/source/SourceTraversal.jrag

    r13294 r13575  
    9090    syn Iterable<SrcComponentDecl> SrcEnumClassDecl.componentsIterable() = super.components();
    9191    syn SrcEnumClassDecl SrcEnumClassDecl.enumBase() =
    92         ((SourceRoot) root()).getProgram().getEnumBaseDecl();
     92        root().asSourceRoot().getProgram().getEnumBaseDecl();
    9393   
    9494    syn Iterable<SrcModificationOrRedeclareElement> SrcClassDecl.elementModifications();
  • branches/stable/Compiler/ModelicaMiddleEnd/src/jastadd/structural/Symbolic.jrag

    r12811 r13575  
    121121                }
    122122            }
     123           
     124            if (activeTerms.isEmpty()) {
     125                return new FNoExp();
     126            }
     127               
    123128           
    124129            // Compute new expressions for the inactive and active terms
  • branches/stable/Compiler/build-base.xml

    r13504 r13575  
    636636            <isset property="javadoc.packages"/>
    637637            <then>
     638
     639                <!-- We need to add this to builds with Java v9 or greater -->
     640                <condition property="javadoc_additional_params" value="" else="--no-module-directories">
     641                    <or>
     642                        <equals arg1="${ant.java.version}" arg2="1.7" />
     643                        <equals arg1="${ant.java.version}" arg2="1.8" />
     644                    </or>
     645                </condition>
     646
    638647                <!-- The javadoc directory is sometimes unusable, unclear why.
    639648                     It is recreated by the javadoc task. -->
     
    646655                    excludepackagenames="${test_helper_packages}"
    647656                    classpath="${thirdparty_jars_build}"
     657                    additionalparam="${javadoc_additional_params}"
    648658                    failonerror="true" />
    649659            </then>
  • branches/stable/Python/src/pymodelica/compiler_logging.py

    r13252 r13575  
    129129        return self.last
    130130   
     131    def close(self):
     132        """
     133        Closes the underlying stream.
     134        """
     135        self.stream.close()
     136   
    131137    def genErrorMsg(self, e):
    132138        column = e.getColumnNumber()
  • branches/stable/Python/src/tests_jmodelica/optimization/test_realtime_mpc.py

    r10318 r13575  
    3535def check_result(results, ref):
    3636    for key in ref:
    37         assert abs(ref[key] - results[key][-1]) < 1e-5
     37        assert abs(ref[key] - results[key][-1]) < 1e-3, abs(ref[key] - results[key][-1])
    3838       
    3939
  • branches/stable/Python/src/tests_jmodelica/test_compiler.py

    r12127 r13575  
    391391        """
    392392        fmuname = compile_fmu(Test_Compiler_functions.cpath_mc, Test_Compiler_functions.fpath_mc, compiler_options={'generate_html_diagnostics':True})
     393        (diag_name, _) = os.path.splitext(fmuname)
     394        diag_name += '_html_diagnostics'
     395
     396        assert os.access(fmuname, os.F_OK) == True, \
     397               fmuname+" was not created."
     398        assert os.access(diag_name, os.F_OK) == True, \
     399               diag_name+" was not created."
     400        os.remove(fmuname)
     401        shutil.rmtree(diag_name)
     402
     403    @testattr(stddist_base = True)
     404    def test_dynamic_state_html_diagnostics(self):
     405        """
     406        Test that generate_html_diagnostics works with a model with dynamic states, see #5839
     407        """
     408
     409        fmuname = compile_fmu("ThreeDSOneEq", os.path.join(get_files_path(), 'Modelica', 'ThreeDSOneEq.mo'), compiler_options={'generate_html_diagnostics':True})
    393410        (diag_name, _) = os.path.splitext(fmuname)
    394411        diag_name += '_html_diagnostics'
Note: See TracChangeset for help on using the changeset viewer.