* Check if the currently reached '*', '&' or '^' character is * a pointer-or-reference symbol, or another operator. * A pointer dereference (*) or an "address of" character (&) * counts as a pointer or reference because it is not an * arithmetic operator. * * @return whether current character is a reference-or-pointer */
| 3159 | * @return whether current character is a reference-or-pointer |
| 3160 | */ |
| 3161 | bool ASFormatter::isPointerOrReference() const |
| 3162 | { |
| 3163 | assert(currentChar == '*' || currentChar == '&' || currentChar == '^'); |
| 3164 | |
| 3165 | if (isJavaStyle()) |
| 3166 | return false; |
| 3167 | |
| 3168 | if (isCharImmediatelyPostOperator) |
| 3169 | return false; |
| 3170 | |
| 3171 | // get the last legal word (may be a number) |
| 3172 | string lastWord = getPreviousWord(currentLine, charNum); |
| 3173 | if (lastWord.empty()) |
| 3174 | lastWord = " "; |
| 3175 | |
| 3176 | // check for preceding or following numeric values |
| 3177 | string nextText = peekNextText(currentLine.substr(charNum + 1)); |
| 3178 | if (nextText.length() == 0) |
| 3179 | nextText = " "; |
| 3180 | if (isDigit(lastWord[0]) |
| 3181 | || isDigit(nextText[0]) |
| 3182 | || nextText[0] == '!' |
| 3183 | || nextText[0] == '~') |
| 3184 | return false; |
| 3185 | |
| 3186 | // check for multiply then a dereference (a * *b) |
| 3187 | char nextChar = peekNextChar(); |
| 3188 | if (currentChar == '*' |
| 3189 | && nextChar == '*' |
| 3190 | && !isPointerToPointer(currentLine, charNum)) |
| 3191 | return false; |
| 3192 | |
| 3193 | if ((foundCastOperator && nextChar == '>') |
| 3194 | || isPointerOrReferenceVariable(lastWord)) |
| 3195 | return true; |
| 3196 | |
| 3197 | if (isInClassInitializer |
| 3198 | && previousNonWSChar != '(' |
| 3199 | && previousNonWSChar != '{' |
| 3200 | && previousCommandChar != ',' |
| 3201 | && nextChar != ')' |
| 3202 | && nextChar != '}') |
| 3203 | return false; |
| 3204 | |
| 3205 | //check for rvalue reference |
| 3206 | if (currentChar == '&' && nextChar == '&') |
| 3207 | { |
| 3208 | if (lastWord == AS_AUTO) |
| 3209 | return true; |
| 3210 | if (previousNonWSChar == '>') |
| 3211 | return true; |
| 3212 | string followingText; |
| 3213 | if ((int) currentLine.length() > charNum + 2) |
| 3214 | followingText = peekNextText(currentLine.substr(charNum + 2)); |
| 3215 | if (followingText.length() > 0 && followingText[0] == ')') |
| 3216 | return true; |
| 3217 | if (currentHeader != nullptr || isInPotentialCalculation) |
| 3218 | return false; |