| 7025 | |
| 7026 | |
| 7027 | Var *Script::FindOrAddVar(LPCTSTR aVarName, size_t aVarNameLength, int aScope) |
| 7028 | // Caller has ensured that aVarName isn't NULL. |
| 7029 | // Returns the Var whose name matches aVarName. If it doesn't exist, it is created. |
| 7030 | { |
| 7031 | if (!*aVarName) |
| 7032 | return NULL; |
| 7033 | ResultType result = OK; // Must set default. |
| 7034 | VarList *varlist; |
| 7035 | int insert_pos; |
| 7036 | Var *var; |
| 7037 | if (var = FindVar(aVarName, aVarNameLength, aScope, &varlist, &insert_pos, &result)) |
| 7038 | return var; |
| 7039 | if (!result) // An error was displayed. |
| 7040 | return nullptr; |
| 7041 | // Otherwise, no match found, so create a new var. |
| 7042 | bool is_local = varlist != GlobalVars(); |
| 7043 | // This will return NULL if there was a problem, in which case AddVar() will already have displayed the error: |
| 7044 | return AddVar(aVarName, aVarNameLength, varlist, insert_pos |
| 7045 | , (aScope & ~(VAR_LOCAL | VAR_GLOBAL)) | (is_local ? VAR_LOCAL : VAR_GLOBAL)); // When aScope == FINDVAR_DEFAULT, it contains both the "local" and "global" bits. This ensures only the appropriate bit is set. |
| 7046 | } |
| 7047 | |
| 7048 | |
| 7049 |
no outgoing calls
no test coverage detected