Changeset 13714
- Timestamp:
- Oct 9, 2019 2:24:19 PM (2 months ago)
- 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 16262 16262 end StringOperations11; 16263 16263 16264 16265 model 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 16283 annotation(__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=" 16289 void 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 16306 jmi_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 ")}))); 16313 end StringOperations12; 16314 16264 16315 package TestTerminate 16265 16316 -
branches/dev-mj-5835/Compiler/ModelicaFrontEnd/src/jastadd/errorcheck/ComplianceCheck.jadd
r13702 r13714 284 284 public static final SimpleProblemProducer ASTNode.UNSUPPORTED_NON_FIXED_STRING_ARGUMENT = 285 285 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."); 287 287 288 288 public void FStringExp.complianceCheck(ErrorCheckType checkType) { … … 290 290 if (hasFormat()) { 291 291 getFormat().markAsStructuralParameter(checkType); 292 // TODO: need to cover functions as well293 292 if (!getFormat().variability().parameterOrLess()) 294 293 UNSUPPORTED_NON_FIXED_STRING_ARGUMENT.invoke(getFormat(), "format"); -
branches/dev-mj-5835/Compiler/ModelicaFrontEnd/test/modelica/ComplianceTests.mo
r13702 r13714 537 537 Integer len = if time < 0 then 4 else 3; 538 538 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); 545 initial equation 546 selFmt1 = if len == 4 then 1 else 2; 540 547 equation 541 548 assert(time>2.0, String(time, significantDigits=digits, minimumLength=len, leftJustified=time<1)); 542 549 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 ")}))); 550 annotation(__JModelica(UnitTesting(tests={ 551 ComplianceErrorTestCase( 552 name="StringOperator1", 553 description="Test compliance warnings for non fixed string operator format argument", 554 errorMessage=" 555 556 557 Compliance 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 560 Compliance error at line 15, column 5, in file '...': 561 Parameters with fixed=false can not be used as structural parameters 562 563 Compliance 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 ")}))); 556 566 end StringOperator1; 557 567
Note: See TracChangeset
for help on using the changeset viewer.