OMCompiler/Compiler/FrontEnd/ElementSource.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), | ||
| 5 | * c/o Linköpings universitet, Department of Computer and Information Science, | ||
| 6 | * SE-58183 Linköping, Sweden. | ||
| 7 | * | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 15 | * | ||
| 16 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) | ||
| 17 | * Public License (OSMC-PL) are obtained from OSMC, either from the above | ||
| 18 | * address, from the URLs: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | encapsulated package ElementSource "A package for recording symbolic operations (used by the debugger) as well as other operations recording where an equation came from" | ||
| 37 | |||
| 38 | import DAE; | ||
| 39 | |||
| 40 | protected | ||
| 41 | |||
| 42 | import Absyn; | ||
| 43 | import Error; | ||
| 44 | import ExpressionBasics; | ||
| 45 | import Flags; | ||
| 46 | import List; | ||
| 47 | import SCode; | ||
| 48 | |||
| 49 | public | ||
| 50 | |||
| 51 | function mergeSources | ||
| 52 | input DAE.ElementSource src1; | ||
| 53 | input DAE.ElementSource src2; | ||
| 54 | output DAE.ElementSource mergedSrc; | ||
| 55 | algorithm | ||
| 56 | mergedSrc := match(src1,src2) | ||
| 57 | local | ||
| 58 | SourceInfo info; | ||
| 59 | list<Absyn.Within> partOfLst1,partOfLst2,p; | ||
| 60 | DAE.ComponentPrefix instanceOpt1,instanceOpt2,i; | ||
| 61 | list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst1,connectEquationOptLst2,c; | ||
| 62 | list<Absyn.Path> typeLst1,typeLst2,t; | ||
| 63 | list<DAE.SymbolicOperation> o,operations1,operations2; | ||
| 64 | list<SCode.Comment> comment, comment1,comment2; | ||
| 65 | case (DAE.SOURCE(info, partOfLst1, instanceOpt1, connectEquationOptLst1, typeLst1, operations1, comment1), | ||
| 66 | DAE.SOURCE(_ /* Discard */, partOfLst2, instanceOpt2, connectEquationOptLst2, typeLst2, operations2, comment2)) | ||
| 67 | algorithm | ||
| 68 | 91253 | p := List.union(partOfLst1, partOfLst2); | |
| 69 | i := match instanceOpt1 case DAE.NOCOMPPRE() then instanceOpt2; else instanceOpt1; end match; | ||
| 70 | 91253 | c := List.union(connectEquationOptLst1, connectEquationOptLst2); | |
| 71 | 91253 | t := List.union(typeLst1, typeLst2); | |
| 72 | 91253 | o := listAppend(operations1, operations2); | |
| 73 | 91253 | comment := List.union(comment1,comment2); | |
| 74 | 91253 | then DAE.SOURCE(info,p,i,c,t, o,comment); | |
| 75 | end match; | ||
| 76 | end mergeSources; | ||
| 77 | |||
| 78 | function addCommentToSource | ||
| 79 | input output DAE.ElementSource source; | ||
| 80 | input Option<SCode.Comment> commentIn; | ||
| 81 | algorithm | ||
| 82 | source := match(source,commentIn) | ||
| 83 | local | ||
| 84 | SCode.Comment comment; | ||
| 85 | case (DAE.SOURCE(_, _, _, _, _, _, _),SOME(comment)) | ||
| 86 | algorithm | ||
| 87 | 40986 | source.comment := comment::source.comment; | |
| 88 | then source; | ||
| 89 | else source; | ||
| 90 | end match; | ||
| 91 | end addCommentToSource; | ||
| 92 | |||
| 93 | function createElementSource | ||
| 94 | "@author: adrpo | ||
| 95 | set the various sources of the element" | ||
| 96 | input SourceInfo fileInfo; | ||
| 97 | input Option<Absyn.Path> partOf = NONE() "the model(s) this element came from"; | ||
| 98 | input DAE.Prefix prefix = DAE.NOPRE() "the instance(s) this element is part of"; | ||
| 99 | input tuple<DAE.ComponentRef, DAE.ComponentRef> connectEquation = (DAE.emptyCref, DAE.emptyCref) "this element came from this connect(s)"; | ||
| 100 | output DAE.ElementSource source; | ||
| 101 | protected | ||
| 102 | Absyn.Path path; | ||
| 103 | algorithm | ||
| 104 | source := DAE.SOURCE( | ||
| 105 | fileInfo, | ||
| 106 | 1112630 | match partOf case NONE() then {}; case SOME(path) then {Absyn.WITHIN(path)}; end match, | |
| 107 | 594822 | match prefix case DAE.NOPRE() then DAE.NOCOMPPRE(); case DAE.PREFIX() then prefix.compPre; end match, | |
| 108 | match connectEquation case (DAE.CREF_IDENT(ident=""),_) then {}; else {connectEquation}; end match, | ||
| 109 | {}, | ||
| 110 | {}, | ||
| 111 | {} | ||
| 112 | ); | ||
| 113 | end createElementSource; | ||
| 114 | |||
| 115 | function addAdditionalComment | ||
| 116 | input DAE.ElementSource source; | ||
| 117 | input String message; | ||
| 118 | output DAE.ElementSource outSource; | ||
| 119 | algorithm | ||
| 120 | outSource := match source | ||
| 121 | local | ||
| 122 | SourceInfo info "the line and column numbers of the equations and algorithms this element came from"; | ||
| 123 | list<Absyn.Path> typeLst "the absyn type of the element" ; | ||
| 124 | list<Absyn.Within> partOfLst "the models this element came from" ; | ||
| 125 | DAE.ComponentPrefix instanceOpt "the instance this element is part of" ; | ||
| 126 | list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ; | ||
| 127 | list<DAE.SymbolicOperation> operations; | ||
| 128 | list<SCode.Comment> comment; | ||
| 129 | Boolean b; | ||
| 130 | SCode.Comment c; | ||
| 131 | |||
| 132 | case DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, typeLst, operations, comment) | ||
| 133 | algorithm | ||
| 134 | 836 | c := SCode.COMMENT(NONE(), SOME(message)); | |
| 135 | 836 | b := listMember(c, comment); | |
| 136 |
1/2✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
|
836 | comment := if b then comment else (c::comment); |
| 137 | 836 | then | |
| 138 | DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, typeLst, operations, comment); | ||
| 139 | |||
| 140 | end match; | ||
| 141 | end addAdditionalComment; | ||
| 142 | |||
| 143 | function addAnnotation | ||
| 144 | input DAE.ElementSource source; | ||
| 145 | input SCode.Comment comment; | ||
| 146 | output DAE.ElementSource outSource; | ||
| 147 | algorithm | ||
| 148 | outSource := match (source,comment) | ||
| 149 | local | ||
| 150 | SourceInfo info "the line and column numbers of the equations and algorithms this element came from"; | ||
| 151 | list<Absyn.Path> typeLst "the absyn type of the element" ; | ||
| 152 | list<Absyn.Within> partOfLst "the models this element came from" ; | ||
| 153 | DAE.ComponentPrefix instanceOpt "the instance this element is part of" ; | ||
| 154 | list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ; | ||
| 155 | list<DAE.SymbolicOperation> operations; | ||
| 156 | list<SCode.Comment> commentLst; | ||
| 157 | |||
| 158 | case (DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, typeLst, operations, commentLst),SCode.COMMENT(annotation_=SOME(_))) | ||
| 159 | 3 | then DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, typeLst, operations, comment::commentLst); | |
| 160 | else source; | ||
| 161 | |||
| 162 | end match; | ||
| 163 | end addAnnotation; | ||
| 164 | |||
| 165 | function getComments | ||
| 166 | input DAE.ElementSource source; | ||
| 167 | output list<SCode.Comment> outComments; | ||
| 168 | algorithm | ||
| 169 | outComments := match source | ||
| 170 | local | ||
| 171 | list<SCode.Comment> comment; | ||
| 172 | |||
| 173 | case DAE.SOURCE(comment = comment) then comment; | ||
| 174 | |||
| 175 | end match; | ||
| 176 | end getComments; | ||
| 177 | |||
| 178 | function getOptComment | ||
| 179 | "Returns the first added comment if there is one, otherwise NONE." | ||
| 180 | input DAE.ElementSource source; | ||
| 181 | output Option<SCode.Comment> outComment; | ||
| 182 | algorithm | ||
| 183 |
2/2✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 24 times.
|
1824 | if not listEmpty(source.comment) then |
| 184 | 1800 | outComment := SOME(List.last(source.comment)); | |
| 185 | else | ||
| 186 | outComment := NONE(); | ||
| 187 | end if; | ||
| 188 | end getOptComment; | ||
| 189 | |||
| 190 | function addSymbolicTransformation | ||
| 191 | input output DAE.ElementSource source; | ||
| 192 | input DAE.SymbolicOperation op; | ||
| 193 | algorithm | ||
| 194 |
2/2✓ Branch 1 taken 399964 times.
✓ Branch 2 taken 3557 times.
|
403521 | if not Flags.isSet(Flags.INFO_XML_OPERATIONS) then |
| 195 | 399964 | return; | |
| 196 | end if; | ||
| 197 | source := match (source,op) | ||
| 198 | local | ||
| 199 | SourceInfo info "the line and column numbers of the equations and algorithms this element came from"; | ||
| 200 | list<Absyn.Path> typeLst "the absyn type of the element" ; | ||
| 201 | list<Absyn.Within> partOfLst "the models this element came from" ; | ||
| 202 | DAE.ComponentPrefix instanceOpt "the instance this element is part of" ; | ||
| 203 | list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ; | ||
| 204 | list<DAE.SymbolicOperation> operations; | ||
| 205 | DAE.Exp h1,t1,t2; | ||
| 206 | list<DAE.Exp> es1,es2,es; | ||
| 207 | list<SCode.Comment> comment; | ||
| 208 | |||
| 209 | case (DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, typeLst, DAE.SUBSTITUTION(es1 as (h1::_),t1)::operations,comment),DAE.SUBSTITUTION(es2,t2)) | ||
| 210 | guard | ||
| 211 | // The tail of the new substitution chain is the same as the head of the old one... | ||
| 212 | ExpressionBasics.expEqual(t2,h1) | ||
| 213 | algorithm | ||
| 214 | // Reference equality would be fine as otherwise it is not really a chain... But replaceExp is stupid :( | ||
| 215 | // true = referenceEq(t2,h1); | ||
| 216 | 12 | es := listAppend(es2,es1); | |
| 217 | 24 | then DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, typeLst, DAE.SUBSTITUTION(es,t1)::operations,comment); | |
| 218 | |||
| 219 | case (DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, typeLst, operations, comment),_) | ||
| 220 | 3545 | then DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, typeLst, op::operations,comment); | |
| 221 | end match; | ||
| 222 | end addSymbolicTransformation; | ||
| 223 | |||
| 224 | function condAddSymbolicTransformation | ||
| 225 | input Boolean cond; | ||
| 226 | input output DAE.ElementSource source; | ||
| 227 | input DAE.SymbolicOperation op; | ||
| 228 | algorithm | ||
| 229 |
2/2✓ Branch 0 taken 115201 times.
✓ Branch 1 taken 53388 times.
|
168589 | if not cond then |
| 230 | 115201 | return; | |
| 231 | end if; | ||
| 232 | 53388 | source := addSymbolicTransformation(source,op); | |
| 233 | end condAddSymbolicTransformation; | ||
| 234 | |||
| 235 | function addSymbolicTransformationDeriveLst | ||
| 236 | input output DAE.ElementSource source; | ||
| 237 | input list<DAE.Exp> explst1; | ||
| 238 | input list<DAE.Exp> explst2; | ||
| 239 | algorithm | ||
| 240 | ✗ | if not Flags.isSet(Flags.INFO_XML_OPERATIONS) then | |
| 241 | ✗ | return; | |
| 242 | end if; | ||
| 243 | source := match(explst1,explst2) | ||
| 244 | local | ||
| 245 | DAE.SymbolicOperation op; | ||
| 246 | list<DAE.Exp> rexplst1,rexplst2; | ||
| 247 | DAE.Exp exp1,exp2; | ||
| 248 | case({},_) then source; | ||
| 249 | case(exp1::rexplst1,exp2::rexplst2) | ||
| 250 | algorithm | ||
| 251 | ✗ | op := DAE.OP_DIFFERENTIATE(DAE.crefTime,exp1,exp2); | |
| 252 | ✗ | source := addSymbolicTransformation(source,op); | |
| 253 | ✗ | then | |
| 254 | addSymbolicTransformationDeriveLst(source,rexplst1,rexplst2); | ||
| 255 | end match; | ||
| 256 | end addSymbolicTransformationDeriveLst; | ||
| 257 | |||
| 258 | function addSymbolicTransformationFlattenedEqs | ||
| 259 | input output DAE.ElementSource source; | ||
| 260 | input DAE.Element elt; | ||
| 261 | algorithm | ||
| 262 |
2/2✓ Branch 1 taken 78405 times.
✓ Branch 2 taken 15 times.
|
78420 | if not Flags.isSet(Flags.INFO_XML_OPERATIONS) then |
| 263 | 78405 | return; | |
| 264 | end if; | ||
| 265 | source := match source | ||
| 266 | local | ||
| 267 | SourceInfo info "the line and column numbers of the equations and algorithms this element came from"; | ||
| 268 | list<Absyn.Path> typeLst "the absyn type of the element" ; | ||
| 269 | list<Absyn.Within> partOfLst "the models this element came from" ; | ||
| 270 | DAE.ComponentPrefix instanceOpt "the instance this element is part of" ; | ||
| 271 | list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ; | ||
| 272 | list<DAE.SymbolicOperation> operations; | ||
| 273 | list<SCode.Comment> comment; | ||
| 274 | SCode.Equation scode; | ||
| 275 | case DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, typeLst, DAE.FLATTEN(scode,NONE())::operations,comment) | ||
| 276 | 30 | then DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, typeLst, DAE.FLATTEN(scode,SOME(elt))::operations,comment); | |
| 277 | case DAE.SOURCE(info=info) | ||
| 278 | algorithm | ||
| 279 | ✗ | Error.addSourceMessage(Error.INTERNAL_ERROR, {"Tried to add the flattened elements to the list of operations, but did not find the SCode equation"}, info); | |
| 280 | ✗ | then fail(); | |
| 281 | end match; | ||
| 282 | end addSymbolicTransformationFlattenedEqs; | ||
| 283 | |||
| 284 | function addSymbolicTransformationSubstitutionLst | ||
| 285 | input list<Boolean> add; | ||
| 286 | input output DAE.ElementSource source; | ||
| 287 | input list<DAE.Exp> explst1; | ||
| 288 | input list<DAE.Exp> explst2; | ||
| 289 | algorithm | ||
| 290 |
1/2✓ Branch 1 taken 155 times.
✗ Branch 2 not taken.
|
155 | if not Flags.isSet(Flags.INFO_XML_OPERATIONS) then |
| 291 | 155 | return; | |
| 292 | end if; | ||
| 293 | source := match(add,explst1,explst2) | ||
| 294 | local | ||
| 295 | list<Boolean> brest; | ||
| 296 | list<DAE.Exp> rexplst1,rexplst2; | ||
| 297 | DAE.Exp exp1,exp2; | ||
| 298 | case({},_,_) then source; | ||
| 299 | case(true::brest,exp1::rexplst1,exp2::rexplst2) | ||
| 300 | algorithm | ||
| 301 | ✗ | source := addSymbolicTransformationSubstitution(true,source,exp1,exp2); | |
| 302 | ✗ | then | |
| 303 | addSymbolicTransformationSubstitutionLst(brest,source,rexplst1,rexplst2); | ||
| 304 | case(false::brest,_::rexplst1,_::rexplst2) | ||
| 305 | ✗ | then | |
| 306 | addSymbolicTransformationSubstitutionLst(brest,source,rexplst1,rexplst2); | ||
| 307 | end match; | ||
| 308 | end addSymbolicTransformationSubstitutionLst; | ||
| 309 | |||
| 310 | function addSymbolicTransformationSubstitution | ||
| 311 | input Boolean add; | ||
| 312 | input output DAE.ElementSource source; | ||
| 313 | input DAE.Exp exp1; | ||
| 314 | input DAE.Exp exp2; | ||
| 315 | algorithm | ||
| 316 |
2/2✓ Branch 1 taken 201010 times.
✓ Branch 2 taken 532 times.
|
201542 | if not Flags.isSet(Flags.INFO_XML_OPERATIONS) then |
| 317 | 201010 | return; | |
| 318 | end if; | ||
| 319 | 532 | source := condAddSymbolicTransformation(add,source,DAE.SUBSTITUTION({exp2},exp1)); | |
| 320 | end addSymbolicTransformationSubstitution; | ||
| 321 | |||
| 322 | function addSymbolicTransformationSimplifyLst | ||
| 323 | input list<Boolean> add; | ||
| 324 | input output DAE.ElementSource source; | ||
| 325 | input list<DAE.Exp> explst1; | ||
| 326 | input list<DAE.Exp> explst2; | ||
| 327 | algorithm | ||
| 328 |
1/2✓ Branch 1 taken 155 times.
✗ Branch 2 not taken.
|
155 | if not Flags.isSet(Flags.INFO_XML_OPERATIONS) then |
| 329 | 155 | return; | |
| 330 | end if; | ||
| 331 | source := match(add,explst1,explst2) | ||
| 332 | local | ||
| 333 | list<Boolean> brest; | ||
| 334 | list<DAE.Exp> rexplst1,rexplst2; | ||
| 335 | DAE.Exp exp1,exp2; | ||
| 336 | case({},_,_) then source; | ||
| 337 | case(true::brest,exp1::rexplst1,exp2::rexplst2) | ||
| 338 | algorithm | ||
| 339 | ✗ | source := addSymbolicTransformation(source, DAE.SIMPLIFY(DAE.PARTIAL_EQUATION(exp1),DAE.PARTIAL_EQUATION(exp2))); | |
| 340 | ✗ | then | |
| 341 | addSymbolicTransformationSimplifyLst(brest,source,rexplst1,rexplst2); | ||
| 342 | case(false::brest,_::rexplst1,_::rexplst2) | ||
| 343 | ✗ | then | |
| 344 | addSymbolicTransformationSimplifyLst(brest,source,rexplst1,rexplst2); | ||
| 345 | end match; | ||
| 346 | end addSymbolicTransformationSimplifyLst; | ||
| 347 | |||
| 348 | function addSymbolicTransformationSimplify | ||
| 349 | input Boolean add; | ||
| 350 | input output DAE.ElementSource source; | ||
| 351 | input DAE.EquationExp exp1; | ||
| 352 | input DAE.EquationExp exp2; | ||
| 353 | algorithm | ||
| 354 |
1/2✓ Branch 1 taken 153 times.
✗ Branch 2 not taken.
|
153 | if not Flags.isSet(Flags.INFO_XML_OPERATIONS) then |
| 355 | 153 | return; | |
| 356 | end if; | ||
| 357 | ✗ | source := condAddSymbolicTransformation(add,source,DAE.SIMPLIFY(exp1,exp2)); | |
| 358 | end addSymbolicTransformationSimplify; | ||
| 359 | |||
| 360 | function addSymbolicTransformationSolve | ||
| 361 | input Boolean add; | ||
| 362 | input output DAE.ElementSource source; | ||
| 363 | input DAE.ComponentRef cr; | ||
| 364 | input DAE.Exp exp1; | ||
| 365 | input DAE.Exp exp2; | ||
| 366 | input DAE.Exp exp; | ||
| 367 | input list<DAE.Statement> asserts; | ||
| 368 | protected | ||
| 369 | DAE.SymbolicOperation op,op1,op2; | ||
| 370 | algorithm | ||
| 371 |
3/4✓ Branch 0 taken 336669 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 336595 times.
✓ Branch 4 taken 74 times.
|
336669 | if not (add and Flags.isSet(Flags.INFO_XML_OPERATIONS)) then |
| 372 | 336595 | return; | |
| 373 | end if; | ||
| 374 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 74 times.
|
74 | op1 := DAE.SOLVE(cr,exp1,exp2,exp,list(getAssertCond(ass) for ass in asserts)); |
| 375 | 74 | op2 := DAE.SOLVED(cr,exp2) "If it was already on solved form"; | |
| 376 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 2 taken 68 times.
|
74 | op := if ExpressionBasics.expEqual(exp2,exp) then op2 else op1; |
| 377 | 74 | source := addSymbolicTransformation(source,op); | |
| 378 | end addSymbolicTransformationSolve; | ||
| 379 | |||
| 380 | function getAssertCond | ||
| 381 | input DAE.Statement stmt; | ||
| 382 | output DAE.Exp cond; | ||
| 383 | algorithm | ||
| 384 | ✗ | DAE.STMT_ASSERT(cond=cond) := stmt; | |
| 385 | end getAssertCond; | ||
| 386 | |||
| 387 | function getSymbolicTransformations | ||
| 388 | input DAE.ElementSource source; | ||
| 389 | output list<DAE.SymbolicOperation> ops; | ||
| 390 | algorithm | ||
| 391 | 161786 | ops := source.operations; | |
| 392 | end getSymbolicTransformations; | ||
| 393 | |||
| 394 | function getElementSource | ||
| 395 | input DAE.Element element; | ||
| 396 | output DAE.ElementSource source; | ||
| 397 | algorithm | ||
| 398 | source := match element | ||
| 399 | ✗ | case DAE.VAR() then element.source; | |
| 400 | ✗ | case DAE.DEFINE() then element.source; | |
| 401 | ✗ | case DAE.INITIALDEFINE() then element.source; | |
| 402 | ✗ | case DAE.EQUATION() then element.source; | |
| 403 | ✗ | case DAE.EQUEQUATION() then element.source; | |
| 404 | ✗ | case DAE.ARRAY_EQUATION() then element.source; | |
| 405 | ✗ | case DAE.INITIAL_ARRAY_EQUATION() then element.source; | |
| 406 | ✗ | case DAE.COMPLEX_EQUATION() then element.source; | |
| 407 | ✗ | case DAE.INITIAL_COMPLEX_EQUATION() then element.source; | |
| 408 | 2 | case DAE.WHEN_EQUATION() then element.source; | |
| 409 | ✗ | case DAE.IF_EQUATION() then element.source; | |
| 410 | ✗ | case DAE.INITIAL_IF_EQUATION() then element.source; | |
| 411 | ✗ | case DAE.INITIALEQUATION() then element.source; | |
| 412 | ✗ | case DAE.ALGORITHM() then element.source; | |
| 413 | ✗ | case DAE.INITIALALGORITHM() then element.source; | |
| 414 | ✗ | case DAE.COMP() then element.source; | |
| 415 | ✗ | case DAE.EXTOBJECTCLASS() then element.source; | |
| 416 | ✗ | case DAE.ASSERT() then element.source; | |
| 417 | ✗ | case DAE.INITIAL_ASSERT() then element.source; | |
| 418 | ✗ | case DAE.TERMINATE() then element.source; | |
| 419 | ✗ | case DAE.INITIAL_TERMINATE() then element.source; | |
| 420 | ✗ | case DAE.REINIT() then element.source; | |
| 421 | ✗ | case DAE.NORETCALL() then element.source; | |
| 422 | ✗ | case DAE.CONSTRAINT() then element.source; | |
| 423 | ✗ | case DAE.INITIAL_NORETCALL() then element.source; | |
| 424 | |||
| 425 | else | ||
| 426 | algorithm | ||
| 427 | ✗ | Error.addMessage(Error.INTERNAL_ERROR, {"ElementSource.getElementSource failed: Element does not have a source"}); | |
| 428 | ✗ | then fail(); | |
| 429 | end match; | ||
| 430 | end getElementSource; | ||
| 431 | |||
| 432 | function getStatementSource | ||
| 433 | "Returns the element source associated with a statement." | ||
| 434 | input DAE.Statement stmt; | ||
| 435 | output DAE.ElementSource source; | ||
| 436 | algorithm | ||
| 437 | source := match stmt | ||
| 438 | ✗ | case DAE.STMT_ASSIGN() then stmt.source; | |
| 439 | ✗ | case DAE.STMT_TUPLE_ASSIGN() then stmt.source; | |
| 440 | ✗ | case DAE.STMT_ASSIGN_ARR() then stmt.source; | |
| 441 | ✗ | case DAE.STMT_IF() then stmt.source; | |
| 442 | ✗ | case DAE.STMT_FOR() then stmt.source; | |
| 443 | ✗ | case DAE.STMT_PARFOR() then stmt.source; | |
| 444 | ✗ | case DAE.STMT_WHILE() then stmt.source; | |
| 445 | ✗ | case DAE.STMT_WHEN() then stmt.source; | |
| 446 | ✗ | case DAE.STMT_ASSERT() then stmt.source; | |
| 447 | ✗ | case DAE.STMT_TERMINATE() then stmt.source; | |
| 448 | ✗ | case DAE.STMT_REINIT() then stmt.source; | |
| 449 | ✗ | case DAE.STMT_NORETCALL() then stmt.source; | |
| 450 | ✗ | case DAE.STMT_RETURN() then stmt.source; | |
| 451 | ✗ | case DAE.STMT_BREAK() then stmt.source; | |
| 452 | ✗ | case DAE.STMT_ARRAY_INIT() then stmt.source; | |
| 453 | ✗ | case DAE.STMT_FAILURE() then stmt.source; | |
| 454 | end match; | ||
| 455 | end getStatementSource; | ||
| 456 | |||
| 457 | function getInfo = getElementSourceFileInfo; | ||
| 458 | |||
| 459 | function getElementSourceFileInfo | ||
| 460 | "Gets the file information associated with an element. | ||
| 461 | If there are several candidates, select the first one." | ||
| 462 | input DAE.ElementSource source; | ||
| 463 | output SourceInfo info; | ||
| 464 | algorithm | ||
| 465 | 2198821 | info := source.info; | |
| 466 | end getElementSourceFileInfo; | ||
| 467 | |||
| 468 | function getElementSourceTypes | ||
| 469 | "@author: adrpo | ||
| 470 | retrieves the paths from the DAE.ElementSource.SOURCE.typeLst" | ||
| 471 | input DAE.ElementSource source "the source of the element"; | ||
| 472 | output list<Absyn.Path> pathLst; | ||
| 473 | algorithm | ||
| 474 | 26029 | pathLst := source.typeLst; | |
| 475 | end getElementSourceTypes; | ||
| 476 | |||
| 477 | function getElementSourceInstances | ||
| 478 | "@author: adrpo | ||
| 479 | retrieves the paths from the DAE.ElementSource.SOURCE.instanceOpt" | ||
| 480 | input DAE.ElementSource source "the source of the element"; | ||
| 481 | output DAE.ComponentPrefix instanceOpt; | ||
| 482 | algorithm | ||
| 483 | ✗ | instanceOpt := source.instance; | |
| 484 | end getElementSourceInstances; | ||
| 485 | |||
| 486 | function getElementSourceConnects | ||
| 487 | "@author: adrpo | ||
| 488 | retrieves the paths from the DAE.ElementSource.SOURCE.connectEquationOptLst" | ||
| 489 | input DAE.ElementSource source "the source of the element"; | ||
| 490 | output list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst; | ||
| 491 | algorithm | ||
| 492 | ✗ | connectEquationOptLst := source.connectEquationOptLst; | |
| 493 | end getElementSourceConnects; | ||
| 494 | |||
| 495 | function getElementSourcePartOfs | ||
| 496 | "@author: adrpo | ||
| 497 | retrieves the withins from the DAE.ElementSource.SOURCE.partOfLst" | ||
| 498 | input DAE.ElementSource source "the source of the element"; | ||
| 499 | output list<Absyn.Within> withinLst; | ||
| 500 | algorithm | ||
| 501 | ✗ | withinLst := source.partOfLst; | |
| 502 | end getElementSourcePartOfs; | ||
| 503 | |||
| 504 | function addElementSourcePartOf | ||
| 505 | input output DAE.ElementSource source; | ||
| 506 | input Absyn.Within withinPath; | ||
| 507 | algorithm | ||
| 508 | ✗ | if not (Flags.isSet(Flags.INFO_XML_OPERATIONS) or Flags.isSet(Flags.VISUAL_XML)) then | |
| 509 | ✗ | return; | |
| 510 | end if; | ||
| 511 | ✗ | source.partOfLst := withinPath::source.partOfLst; | |
| 512 | end addElementSourcePartOf; | ||
| 513 | |||
| 514 | function addElementSourcePartOfOpt | ||
| 515 | input output DAE.ElementSource source; | ||
| 516 | input Option<Absyn.Path> classPathOpt; | ||
| 517 | algorithm | ||
| 518 |
3/4✓ Branch 1 taken 1147 times.
✓ Branch 2 taken 1 time.
✓ Branch 4 taken 1147 times.
✗ Branch 5 not taken.
|
1148 | if not (Flags.isSet(Flags.INFO_XML_OPERATIONS) or Flags.isSet(Flags.VISUAL_XML)) then |
| 519 | 1147 | return; | |
| 520 | end if; | ||
| 521 | source := match classPathOpt | ||
| 522 | local | ||
| 523 | Absyn.Path classPath; | ||
| 524 | // a top level | ||
| 525 | case NONE() | ||
| 526 | then source; | ||
| 527 | case SOME(classPath) | ||
| 528 | ✗ | then addElementSourcePartOf(source, Absyn.WITHIN(classPath)); | |
| 529 | end match; | ||
| 530 | end addElementSourcePartOfOpt; | ||
| 531 | |||
| 532 | function addElementSourceFileInfo | ||
| 533 | input DAE.ElementSource source; | ||
| 534 | input SourceInfo fileInfo; | ||
| 535 | output DAE.ElementSource outSource = source; | ||
| 536 | algorithm | ||
| 537 | 43699 | outSource.info := fileInfo; | |
| 538 | end addElementSourceFileInfo; | ||
| 539 | |||
| 540 | function addElementSourceConnect | ||
| 541 | input DAE.ElementSource inSource; | ||
| 542 | input tuple<DAE.ComponentRef,DAE.ComponentRef> connectEquationOpt; | ||
| 543 | output DAE.ElementSource outSource; | ||
| 544 | algorithm | ||
| 545 | outSource := match inSource | ||
| 546 | local | ||
| 547 | SourceInfo info "the line and column numbers of the equations and algorithms this element came from"; | ||
| 548 | list<Absyn.Within> partOfLst "the models this element came from" ; | ||
| 549 | DAE.ComponentPrefix instanceOpt "the instance this element is part of" ; | ||
| 550 | list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ; | ||
| 551 | list<Absyn.Path> typeLst "the classes where the type of the element is defined" ; | ||
| 552 | list<DAE.SymbolicOperation> operations; | ||
| 553 | list<SCode.Comment> comment; | ||
| 554 | |||
| 555 | // a top level | ||
| 556 | case DAE.SOURCE(info,partOfLst,instanceOpt,connectEquationOptLst,typeLst,operations,comment) | ||
| 557 | 18059 | then DAE.SOURCE(info,partOfLst,instanceOpt,connectEquationOpt::connectEquationOptLst,typeLst,operations,comment); | |
| 558 | end match; | ||
| 559 | end addElementSourceConnect; | ||
| 560 | |||
| 561 | function addElementSourceType | ||
| 562 | input output DAE.ElementSource source; | ||
| 563 | input Absyn.Path classPath; | ||
| 564 | algorithm | ||
| 565 |
3/4✓ Branch 1 taken 7674 times.
✓ Branch 2 taken 3682 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 7674 times.
|
11356 | if not (Flags.isSet(Flags.INFO_XML_OPERATIONS) or Flags.isSet(Flags.VISUAL_XML)) then |
| 566 | ✗ | return; | |
| 567 | end if; | ||
| 568 | source := match source | ||
| 569 | local | ||
| 570 | SourceInfo info "the line and column numbers of the equations and algorithms this element came from"; | ||
| 571 | list<Absyn.Path> typeLst "the absyn type of the element" ; | ||
| 572 | list<Absyn.Within> partOfLst "the models this element came from" ; | ||
| 573 | DAE.ComponentPrefix instanceOpt "the instance this element is part of" ; | ||
| 574 | list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ; | ||
| 575 | list<DAE.SymbolicOperation> operations; | ||
| 576 | list<SCode.Comment> comment; | ||
| 577 | |||
| 578 | case DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, typeLst, operations,comment) | ||
| 579 | 11356 | then DAE.SOURCE(info, partOfLst, instanceOpt, connectEquationOptLst, classPath::typeLst, operations,comment); | |
| 580 | end match; | ||
| 581 | end addElementSourceType; | ||
| 582 | |||
| 583 | function addElementSourceInstanceOpt | ||
| 584 | input output DAE.ElementSource source; | ||
| 585 | input DAE.ComponentPrefix instanceOpt; | ||
| 586 | algorithm | ||
| 587 | () := match (source, instanceOpt) | ||
| 588 | // a NONE() means top level (equivalent to NO_PRE, SOME(cref) means subcomponent | ||
| 589 | case (_, DAE.NOCOMPPRE()) then (); | ||
| 590 | |||
| 591 | case (DAE.SOURCE(), _) | ||
| 592 | algorithm | ||
| 593 | 6 | source.instance := instanceOpt; | |
| 594 | then | ||
| 595 | (); | ||
| 596 | end match; | ||
| 597 | end addElementSourceInstanceOpt; | ||
| 598 | |||
| 599 | annotation(__OpenModelica_Interface="frontend_dump"); | ||
| 600 | end ElementSource; | ||
| 601 |