Ticket #3230: 3230.diff
| File 3230.diff, 7.0 KB (added by , 11 years ago) |
|---|
-
Compiler/BackEnd/Initialization.mo
355 355 DAE.ElementSource source; 356 356 DAE.Algorithm alg; 357 357 Integer size; 358 list< DAE.Statement> stmts;358 list<DAE.Statement> stmts; 359 359 list< BackendDAE.Equation> eqns; 360 360 BackendDAE.WhenEquation weqn; 361 list< DAE.ComponentRef> crefLst;361 list<DAE.ComponentRef> crefLst; 362 362 HashSet.HashSet leftCrs; 363 363 DAE.Expand crefExpand; 364 364 BackendDAE.EquationAttributes eqAttr; … … 369 369 then eqns; 370 370 371 371 // algorithm 372 case BackendDAE.ALGORITHM(alg=alg, source=source, expand=crefExpand) equation372 case BackendDAE.ALGORITHM(alg=alg, source=source, expand=crefExpand) equation 373 373 DAE.ALGORITHM_STMTS(statementLst=stmts) = alg; 374 (stmts, leftCrs) = inlineWhenForInitializationWhenAlgorithm(stmts, {}, HashSet.emptyHashSetSized(50) );374 (stmts, leftCrs) = inlineWhenForInitializationWhenAlgorithm(stmts, {}, HashSet.emptyHashSetSized(50), source); 375 375 alg = DAE.ALGORITHM_STMTS(stmts); 376 376 size = listLength(CheckModel.checkAndGetAlgorithmOutputs(alg, source, crefExpand)); 377 377 crefLst = BaseHashSet.hashSetList(leftCrs); 378 eqns = generateInactiveWhenEquationForInitialization(crefLst, source, inAccEq);379 eqns = List.consOnTrue(not listEmpty(stmts), BackendDAE.ALGORITHM(size, alg, source, crefExpand, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC), eqns);378 //eqns = generateInactiveWhenEquationForInitialization(crefLst, source, inAccEq); 379 eqns = List.consOnTrue(not listEmpty(stmts), BackendDAE.ALGORITHM(size, alg, source, crefExpand, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC), inAccEq); 380 380 then eqns; 381 381 382 382 else inEq::inAccEq; … … 416 416 417 417 protected function inlineWhenForInitializationWhenAlgorithm "author: lochel 418 418 This function generates out of a given when-algorithm, a algorithm for the initialization-problem." 419 input list< DAE.Statement> inStmts;420 input list< DAE.Statement> inAcc "={}";419 input list<DAE.Statement> inStmts; 420 input list<DAE.Statement> inAcc "={}"; 421 421 input HashSet.HashSet inLeftCrs; 422 output list< DAE.Statement> outStmts; 422 input DAE.ElementSource inSource; 423 output list<DAE.Statement> outStmts; 423 424 output HashSet.HashSet outLeftCrs; 424 425 algorithm 425 426 (outStmts, outLeftCrs) := matchcontinue(inStmts) 426 427 local 427 428 DAE.Exp condition; 428 list< DAE.ComponentRef> crefLst;429 list<DAE.ComponentRef> crefLst; 429 430 DAE.Statement stmt; 430 list< DAE.Statement> stmts, rest;431 list<DAE.Statement> stmts, rest; 431 432 HashSet.HashSet leftCrs; 432 433 list<tuple<DAE.ComponentRef, Integer>> crintLst; 433 434 … … 438 439 case (stmt as DAE.STMT_WHEN())::rest equation 439 440 // for when statements it is not necessary that all branches have the same left hand side variables 440 441 // -> take care that for each left hand side an assigment is generated 441 (stmts, leftCrs) = inlineWhenForInitializationWhenStmt(stmt, inLeftCrs, inAcc );442 (stmts, leftCrs) = inlineWhenForInitializationWhenAlgorithm(rest, stmts, leftCrs );442 (stmts, leftCrs) = inlineWhenForInitializationWhenStmt(stmt, inLeftCrs, inAcc, inSource); 443 (stmts, leftCrs) = inlineWhenForInitializationWhenAlgorithm(rest, stmts, leftCrs, inSource); 443 444 then (stmts, leftCrs); 444 445 445 446 // no when statement 446 447 case stmt::rest equation 447 (stmts, leftCrs) = inlineWhenForInitializationWhenAlgorithm(rest, stmt::inAcc, inLeftCrs );448 (stmts, leftCrs) = inlineWhenForInitializationWhenAlgorithm(rest, stmt::inAcc, inLeftCrs, inSource); 448 449 then (stmts, leftCrs); 449 450 end matchcontinue; 450 451 end inlineWhenForInitializationWhenAlgorithm; … … 453 454 This function generates out of a given when-algorithm, a algorithm for the initialization-problem." 454 455 input DAE.Statement inWhenStatement; 455 456 input HashSet.HashSet inLeftCrs; 456 input list< DAE.Statement> inAcc; 457 output list< DAE.Statement> outStmts; 457 input list<DAE.Statement> inAcc; 458 input DAE.ElementSource inSource; 459 output list<DAE.Statement> outStmts; 458 460 output HashSet.HashSet outLeftCrs; 459 461 algorithm 460 462 (outStmts, outLeftCrs) := matchcontinue(inWhenStatement) 461 463 local 462 464 DAE.Exp condition; 463 list< DAE.ComponentRef> crefLst;465 list<DAE.ComponentRef> crefLst; 464 466 DAE.Statement stmt; 465 list< DAE.Statement> stmts;467 list<DAE.Statement> stmts; 466 468 HashSet.HashSet leftCrs; 467 469 list<tuple<DAE.ComponentRef, Integer>> crintLst; 468 470 … … 476 478 case DAE.STMT_WHEN(exp=condition, statementLst=stmts, elseWhen=NONE()) equation 477 479 false = Expression.containsInitialCall(condition, false); 478 480 crefLst = CheckModel.algorithmStatementListOutputs(stmts, DAE.EXPAND()); // expand as we're in an algorithm 481 482 stmts = generateInactiveWhenStatement(crefLst, inSource, {}); 483 stmts = List.foldr(stmts, List.consr, inAcc); 484 479 485 leftCrs = List.fold(crefLst, BaseHashSet.add, inLeftCrs); 480 then ( inAcc, leftCrs);486 then (stmts, leftCrs); 481 487 482 488 // inactive when equation during initialization with elsewhen part 483 489 case DAE.STMT_WHEN(exp=condition, statementLst=stmts, elseWhen=SOME(stmt)) equation 484 490 false = Expression.containsInitialCall(condition, false); 485 491 crefLst = CheckModel.algorithmStatementListOutputs(stmts, DAE.EXPAND()); // expand as we're in an algorithm 492 493 stmts = generateInactiveWhenStatement(crefLst, inSource, {}); 494 stmts = List.foldr(stmts, List.consr, inAcc); 495 486 496 leftCrs = List.fold(crefLst, BaseHashSet.add, inLeftCrs); 487 (stmts, leftCrs) = inlineWhenForInitializationWhenStmt(stmt, leftCrs, inAcc );497 (stmts, leftCrs) = inlineWhenForInitializationWhenStmt(stmt, leftCrs, inAcc, inSource); 488 498 then (stmts, leftCrs); 489 499 490 500 else equation … … 523 533 end match; 524 534 end generateInactiveWhenEquationForInitialization; 525 535 536 protected function generateInactiveWhenStatement "author: lochel" 537 input list<DAE.ComponentRef> inCrLst; 538 input DAE.ElementSource inSource; 539 input list<DAE.Statement> inStmts; 540 output list<DAE.Statement> outStmts; 541 algorithm 542 outStmts := match (inCrLst) 543 local 544 DAE.Type identType; 545 DAE.Exp crefExp, crefPreExp; 546 DAE.ComponentRef cr; 547 list<DAE.ComponentRef> rest; 548 DAE.Statement stmt; 549 list<DAE.Statement> stmts; 550 551 case {} 552 then inStmts; 553 554 case cr::rest equation 555 identType = ComponentReference.crefTypeConsiderSubs(cr); 556 crefExp = DAE.CREF(cr, identType); 557 crefPreExp = Expression.makePureBuiltinCall("pre", {crefExp}, DAE.T_BOOL_DEFAULT); 558 stmt = DAE.STMT_ASSIGN(identType, crefExp, crefPreExp, inSource); 559 stmts = generateInactiveWhenStatement(rest, inSource, stmt::inStmts); 560 then stmts; 561 end match; 562 end generateInactiveWhenStatement; 563 526 564 // ============================================================================= 527 565 // section for collecting all variables, of which the left limit is also used. 528 566 //
