@@ -44,7 +44,9 @@ Property LineIsPython As array Of %Boolean;
4444/// Set to true if this class/routine is generated
4545Property Generated As %Boolean [ InitialExpression = 0 ];
4646
47- ///
47+ /// If the CodeUnit has changed since we last updated it, used to see if we need to call UpdateComplexity
48+ Property OutdatedComplexity As %Boolean [ InitialExpression = 1 ];
49+
4850/// Methods, branches, etc. within this unit of code.
4951Relationship SubUnits As TestCoverage .Data .CodeSubUnit [ Cardinality = children , Inverse = Parent ];
5052
@@ -87,6 +89,9 @@ ClassMethod GetCurrentByName(pInternalName As %String, pSourceNamespace As %Stri
8789 If (tUpdatedHash '= tKnownHash ) {
8890 //Clear out old data and flag the need for an update.
8991 Set tNeedsUpdate = 1
92+ If $IsObject ($Get (tMapToUnit )) {
93+ set tMapToUnit .OutdatedComplexity = 1
94+ }
9095 &sql (delete from TestCoverage_Data .CodeUnitMap where ToHash = :tKnownHash)
9196 If (SQLCODE < 0 ) {
9297 Throw ##class (%Exception.SQL ).CreateFromSQLCODE (SQLCODE ,%msg )
@@ -399,17 +404,27 @@ Method UpdateSourceMap(pSourceNamespace As %String, ByRef pCache) As %Status
399404 Set tMethodStart = ..MethodMap .GetAt (tMethod )
400405 Set tMethodEnd = ..MethodEndMap .GetAt (tMethod )
401406 Set tMethodName = tMethod
407+
408+ // tFullMap(py/int Line Number, absolute) = $lb("CLS", class name, method name, CLS/mac start line (relative to method), CLS/mac end line (relative to method))
402409 Set tFullMap (tMethodStart ) = $lb (" CLS" , tClass ,tMethodName , -1 , -1 ) ; -1 because the class
403410 ; definition doesn't have the +1 offset from the {
411+
412+ // there's a strange edge case where if the python method in the .CLS file starts with spaces, that's not captured in the Python compiled code
413+ // so we have to find how many empty lines there are at the beginning
414+ Set tEmptyLines = 0
415+ while ($zstrip ( pCLSCodeUnit .Lines .GetAt (tCLSMethodNum + 1 + tEmptyLines + 1 ), " <>W" ) = " " ) {
416+ Set tEmptyLines = tEmptyLines + 1
417+ }
418+
404419 For i = tMethodStart +1 :1 :tMethodEnd {
405420 Set tClassLineNum = i -tMethodStart
406- Set tFullMap (i ) = $lb (" CLS" , tClass ,tMethodName , tClassLineNum , tClassLineNum )
421+ Set tFullMap (i ) = $lb (" CLS" , tClass ,tMethodName , tClassLineNum + tEmptyLines , tClassLineNum + tEmptyLines )
407422
408423 // extra check to make sure that the lines we're mapping between are the same as expected
409- Set tClassLineCode = $zstrip (pCLSCodeUnit .Lines .GetAt (tCLSMethodNum + tClassLineNum + 1 ), " <>W" )
424+ Set tClassLineCode = $zstrip (pCLSCodeUnit .Lines .GetAt (tCLSMethodNum + 1 + tEmptyLines + tClassLineNum ), " <>W" )
410425 Set tPyLineCode = $zstrip (..Lines .GetAt (i ), " <>W" )
411426 if (tPyLineCode '= tClassLineCode ) {
412- Set tSC = $$$ERROR($$$GeneralError," Compiled .py code doesn't match .CLS python code at line " _ $char (10 ,13 ) _ tPyLineCode )
427+ $$$ThrowStatus($$$ ERROR($$$GeneralError," Compiled .py code doesn't match .CLS python code at line " _ $char (10 ,13 ) _ tPyLineCode ) )
413428 }
414429 }
415430 Do ..MethodMap .GetNext (.tMethod )
@@ -521,9 +536,10 @@ Method UpdateSourceMap(pSourceNamespace As %String, ByRef pCache) As %Status
521536 }
522537 }
523538
524- // Update cyclomatic complexity for methods in the linked class
539+ // Update cyclomatic complexity for methods in the linked class if we don't already have the newest version
525540 Set tClass = $Order (tCodeUnits (" CLS" ," " ),1 ,tClassCodeUnit )
526- If $IsObject ($Get (tClassCodeUnit )) {
541+ If ($IsObject ($Get (tClassCodeUnit )) && (tClassCodeUnit .OutdatedComplexity )){
542+ set tClassCodeUnit .OutdatedComplexity = 0
527543 $$$ThrowOnError(tClassCodeUnit .UpdateComplexity ())
528544 }
529545 } Catch e {
@@ -589,7 +605,7 @@ Method GetMethodOffset(pAbsoluteLine As %Integer, Output pMethod As %String, Out
589605{
590606}
591607
592- ClassMethod GetCurrentHash (pName As %String , pType As %String , Output pHash As %String , Output pCodeArray As %String , Output pCache ) As %Status [ Private ]
608+ ClassMethod GetCurrentHash (pName As %String , pType As %String , Output pHash As %String , Output pCodeArray As %String , Output pCache ) As %Status
593609{
594610 Set tSC = $$$OK
595611 Try {
@@ -690,6 +706,9 @@ Storage Default
690706<Value name =" 5" >
691707<Value >Generated </Value >
692708</Value >
709+ <Value name =" 6" >
710+ <Value >OutdatedComplexity </Value >
711+ </Value >
693712</Data >
694713<Data name =" LineIsPython" >
695714<Attribute >LineIsPython </Attribute >
0 commit comments