| | 1 | | #pragma rtGlobals=3 |
| | 2 | | #pragma rtFunctionErrors=1 |
| | 3 | | #pragma version=1.10 |
| | 4 | | #pragma TextEncoding="UTF-8" |
| | 5 | | #pragma ModuleName=IUTF_FunctionTags |
| | 6 | |
|
| | 7 | | /// @brief Returns a global wave that stores the Function Tag Waves of this testrun |
| 84 | 8 | | static Function/WAVE GetFunctionTagWaves() |
| | 9 | |
|
| 84 | 10 | | string name = "FunctionTagWaves" |
| | 11 | |
|
| 84 | 12 | | DFREF dfr = GetPackageFolder() |
| 84 | 13 | | WAVE/Z/WAVE wv = dfr:$name |
| 84 | 14 | | if(WaveExists(wv)) |
| 78 | 15 | | return wv |
| 6 | 16 | | endif |
| | 17 | |
|
| 6 | 18 | | Make/WAVE/N=(IUTF_WAVECHUNK_SIZE) dfr:$name/WAVE=wv |
| 6 | 19 | | IUTF_Utils_Vector#SetLength(wv, 0) |
| | 20 | |
|
| 6 | 21 | | return wv |
| 84 | 22 | | End |
| | 23 | |
|
| | 24 | | /// @brief Returns a global wave that stores the full function names at the same position as their |
| | 25 | | /// tag waves. This is used to find the references easier. |
| 406 | 26 | | static Function/WAVE GetFunctionTagRefs() |
| 406 | 27 | | string name = "FunctionTagRefs" |
| | 28 | |
|
| 406 | 29 | | DFREF dfr = GetPackageFolder() |
| 406 | 30 | | WAVE/Z/T wv = dfr:$name |
| 406 | 31 | | if(WaveExists(wv)) |
| 400 | 32 | | return wv |
| 6 | 33 | | endif |
| | 34 | |
|
| 6 | 35 | | Make/T/N=(IUTF_WAVECHUNK_SIZE) dfr:$name/WAVE=wv |
| 6 | 36 | | IUTF_Utils_Vector#SetLength(wv, 0) |
| | 37 | |
|
| 6 | 38 | | return wv |
| 406 | 39 | | End |
| | 40 | |
|
| 79 | 41 | | static Function AddFunctionTagWave(fullFuncName) |
| | 42 | | string fullFuncName |
| | 43 | |
|
| 79 | 44 | | variable index |
| | 45 | |
|
| 79 | 46 | | WAVE/WAVE ftagWaves = GetFunctionTagWaves() |
| 79 | 47 | | WAVE/T ftagRefs = GetFunctionTagRefs() |
| 79 | 48 | | WAVE/T tags = GetFunctionTagWave(fullFuncName) |
| 79 | 49 | | if(!DimSize(tags, UTF_ROW)) |
| 79 | 50 | | return NaN |
| 0 | 51 | | endif |
| | 52 | |
|
| 0 | 53 | | index = IUTF_Utils_Vector#AddRow(ftagRefs) |
| 0 | 54 | | ftagRefs[index] = fullFuncName |
| 0 | 55 | | IUTF_Utils_Vector#EnsureCapacity(ftagWaves, index) |
| 0 | 56 | | ftagWaves[index] = tags |
| 79 | 57 | | End |
| | 58 | |
|
| | 59 | | /// @brief Find the current index in the global function tag wave reference wave. |
| | 60 | | /// |
| | 61 | | /// @param fullFuncName the full function name |
| | 62 | | /// |
| | 63 | | /// @returns The index inside the function tag wave reference wave. -1 if not found. |
| 322 | 64 | | static Function GetFunctionTagRef(fullFuncName) |
| | 65 | | string fullFuncName |
| | 66 | |
|
| 322 | 67 | | WAVE/T ftagRefs = GetFunctionTagRefs() |
| | 68 | |
|
| 322 | 69 | | return IUTF_Utils_Vector#FindText(ftagRefs, fullFuncName) |
| 322 | 70 | | End |
| | 71 | |
|
| | 72 | | /// @brief returns 1 if the comments above a function contain a certain tag, zero otherwise |
| | 73 | | /// |
| | 74 | | /// @param funcName function name |
| | 75 | | /// @param tagName tag that is searched (see FunctionTagStrings for possible tags) |
| | 76 | | /// @returns 1 if the comments above a function contain a certain tag, zero otherwise |
| 243 | 77 | | static Function HasFunctionTag(funcName, tagName) |
| | 78 | | string funcName, tagName |
| | 79 | |
|
| 243 | 80 | | variable funcPos = GetFunctionTagRef(funcName) |
| | 81 | |
|
| 243 | 82 | | if(funcPos == -1) |
| 243 | 83 | | return 0 |
| 0 | 84 | | endif |
| | 85 | |
|
| 0 | 86 | | WAVE/WAVE ftagWaves = GetFunctionTagWaves() |
| 0 | 87 | | WAVE tagValues = ftagWaves[funcPos] |
| | 88 | |
|
| 0 | 89 | | return (FindDimLabel(tagValues, UTF_ROW, tagName) != -2) |
| 243 | 90 | | End |
| | 91 | |
|
| | 92 | | /// @brief returns the value belonging to a certain tag in the comments above a function. |
| | 93 | | /// In case of an error, returns a detailed error message instead. |
| | 94 | | /// |
| | 95 | | /// @param[in] funcName function name |
| | 96 | | /// @param[in] tagName tag that is searched (see FunctionTagStrings for possible tags) |
| | 97 | | /// @param[out] err error code (see constants UTF_TAG*) |
| | 98 | | /// @returns value belonging to a certain tag in the comments above a function, error message if not found |
| 79 | 99 | | static Function/S GetFunctionTagValue(funcName, tagName, err) |
| | 100 | | string funcName, tagName |
| | 101 | | variable &err |
| | 102 | |
|
| 79 | 103 | | variable tagPosition |
| 79 | 104 | | string tagValue, msg |
| 79 | 105 | | variable funcPos = GetFunctionTagRef(funcName) |
| | 106 | |
|
| 79 | 107 | | err = UTF_TAG_ABORTED |
| 79 | 108 | | if(funcPos == -1) |
| 79 | 109 | | err = UTF_TAG_NOT_FOUND |
| 79 | 110 | | sprintf msg, "The tag %s was not found.", tagName |
| 79 | 111 | | return msg |
| 0 | 112 | | endif |
| | 113 | |
|
| 0 | 114 | | WAVE/WAVE ftagWaves = GetFunctionTagWaves() |
| 0 | 115 | | WAVE/T tagValueWave = ftagWaves[funcPos] |
| 0 | 116 | | tagPosition = FindDimLabel(tagValueWave, UTF_ROW, tagName) |
| 0 | 117 | | if(tagPosition == -2) |
| 0 | 118 | | err = UTF_TAG_NOT_FOUND |
| 0 | 119 | | sprintf msg, "The tag %s was not found.", tagName |
| 0 | 120 | | return msg |
| 0 | 121 | | endif |
| | 122 | |
|
| 0 | 123 | | tagValue = tagValueWave[tagPosition] |
| 0 | 124 | | if(IUTF_Utils#IsEmpty(tagValue)) |
| 0 | 125 | | err = UTF_TAG_EMPTY |
| 0 | 126 | | sprintf msg, "The tag %s has no value.", tagName |
| 0 | 127 | | return msg |
| 0 | 128 | | endif |
| | 129 | |
|
| 0 | 130 | | err = UTF_TAG_OK |
| | 131 | |
|
| 0 | 132 | | return tagValue |
| 79 | 133 | | End |
| | 134 | |
|
| | 135 | | /// @brief returns a wave consisting of function tags (see FunctionTagStrings) |
| 79 | 136 | | static Function/WAVE GetTagConstants() |
| | 137 | |
|
| 79 | 138 | | Make/T/FREE tagConstants = {UTF_FTAG_NOINSTRUMENTATION, UTF_FTAG_TD_GENERATOR, UTF_FTAG_EXPECTED_FAILURE, UTF_FTAG_SKI |
| | 139 | |
|
| 79 | 140 | | return tagConstants |
| 79 | 141 | | End |
| | 142 | |
|
| | 143 | | /// @brief Checks if the line has the specified function/procedure tag. |
| | 144 | | /// |
| | 145 | | /// @param tag The function/procedure tag to check |
| | 146 | | /// @param line The line to search tag |
| | 147 | | /// @param[out] value The value of the tag if found, otherwise an empty string |
| | 148 | | /// |
| | 149 | | /// @returns 1 if tag matched, 0 if not |
| 1840 | 150 | | static Function IsTagMatch(tag, line, value) |
| | 151 | | string tag, line |
| | 152 | | string &value |
| | 153 | |
|
| 1840 | 154 | | string expr, tagValue |
| | 155 | |
|
| 1840 | 156 | | value = "" |
| | 157 | |
|
| 1840 | 158 | | if(CmpStr("IUTF_", tag[0, 4])) |
| 460 | 159 | | // function tags that do not use the IUTF_ prefix |
| 460 | 160 | | expr = "\/{2,}[[:space:]]*\\Q" + tag + "\\E(?::)?(.*)$" |
| 1380 | 161 | | else |
| 1380 | 162 | | // compatibility layer to allow the deprecated UTF_ and the new IUTF_ prefix for |
| 1380 | 163 | | // function tags |
| 1380 | 164 | | expr = "\/{2,}[[:space:]]*I?\\Q" + tag[1, Inf] + "\\E(?::)?(.*)$" |
| 1840 | 165 | | endif |
| | 166 | |
|
| 1840 | 167 | | SplitString/E=expr line, tagValue |
| 1840 | 168 | | if(V_flag != 1) |
| 1840 | 169 | | return 0 |
| 0 | 170 | | endif |
| | 171 | |
|
| 0 | 172 | | value = tagValue |
| 0 | 173 | | return 1 |
| 1840 | 174 | | End |
| | 175 | |
|
| | 176 | | /// @brief Reads the function tags in the comments preceding the function keyword |
| | 177 | | /// returns a wave containing the tag values with their tag names as dimLabel |
| | 178 | | /// see FunctionTagStrings for possible tags |
| | 179 | | /// |
| | 180 | | /// @param funcName Name of function |
| | 181 | | /// @returns a wave containing the tag values with their tag names as dimLabel |
| 79 | 182 | | static Function/WAVE GetFunctionTagWave(funcName) |
| | 183 | | string funcName |
| | 184 | |
|
| 79 | 185 | | string msg, expr, funcText, funcTextWithoutContext, funcTextWithContext, funcLine, tagName, tagValue, varName, allVarL |
| 79 | 186 | | variable i, j, numUniqueTags, numLines, numFound |
| 79 | 187 | | WAVE/T tag_constants = GetTagConstants() |
| | 188 | |
|
| 79 | 189 | | WAVE templates = IUTF_Test_MD_MMD#GetMMDVarTemplates() |
| 79 | 190 | | numUniqueTags = DimSize(tag_constants, UTF_ROW) |
| | 191 | |
|
| 79 | 192 | | numFound = 0 |
| | 193 | |
|
| 79 | 194 | | funcTextWithContext = ProcedureText(funcName, -1, "[" + GetIndependentModuleName() + "]") |
| 79 | 195 | | funcTextWithoutContext = ProcedureText(funcName, 0, "[" + GetIndependentModuleName() + "]") |
| 79 | 196 | | funcText = ReplaceString(funcTextWithoutContext, funcTextWithContext, "") |
| 79 | 197 | | numLines = ItemsInList(funcText, "\r") |
| | 198 | |
|
| 79 | 199 | | Make/FREE/T/N=(numLines) tagValueWave |
| | 200 | |
|
| 79 | 201 | | for(i = numLines - 1; numLines > 0 && i >= 0; i -= 1) |
| 230 | 202 | | funcLine = StringFromList(i, funcText, "\r") |
| 230 | 203 | | if(IUTF_Utils#IsEmpty(funcLine)) |
| 0 | 204 | | continue |
| 230 | 205 | | endif |
| | 206 | |
|
| 230 | 207 | | for(j = 0; j < numUniqueTags; j += 1) |
| 1840 | 208 | | tagName = tag_constants[j] |
| 1840 | 209 | | if(!IsTagMatch(tagName, funcLine, tagValue)) |
| 1840 | 210 | | continue |
| 0 | 211 | | endif |
| | 212 | |
|
| 0 | 213 | | tagValue = TrimString(tagValue) |
| 0 | 214 | | if(FindDimLabel(tagValueWave, 0, tagName) != -2) |
| 0 | 215 | | sprintf msg, "Test case %s has the tag %s at least twice.", funcName, tagValue |
| 0 | 216 | | IUTF_Reporting#ReportErrorAndAbort(msg) |
| 0 | 217 | | endif |
| | 218 | |
|
| 0 | 219 | | if(!CmpStr(tagName, UTF_FTAG_TD_GENERATOR) && ItemsInList(tagValue, ":") == 2) |
| 0 | 220 | | varName = StringFromList(0, tagvalue, ":") |
| 0 | 221 | | tagName = UTF_FTAG_TD_GENERATOR + " " + varName |
| 0 | 222 | | allVarList = IUTF_Test_MD_MMD#GetMMDAllVariablesList() |
| 0 | 223 | | if(WhichListItem(varName, allVarList, ";", 0, 0) == -1) |
| 0 | 224 | | sprintf msg, "Test case %s uses an unknown variable name %s in the tag %s.", funcName, varName, tagValue |
| 0 | 225 | | IUTF_Reporting#ReportErrorAndAbort(msg) |
| 0 | 226 | | endif |
| 0 | 227 | | tagValue = StringFromList(1, tagvalue, ":") |
| 0 | 228 | | endif |
| | 229 | |
|
| 0 | 230 | | tagValueWave[numFound] = tagValue |
| 0 | 231 | | SetDimLabel UTF_ROW, numFound, $tagName, tagValueWave |
| 0 | 232 | | numfound += 1 |
| 0 | 233 | | break |
| 0 | 234 | | endfor |
| 230 | 235 | | endfor |
| | 236 | |
|
| 79 | 237 | | Redimension/N=(numFound) tagValueWave |
| 79 | 238 | | return tagValueWave |
| 79 | 239 | | End |