* format pointer or reference * currentChar contains the pointer or reference * the symbol and necessary padding will be appended to formattedLine * the calling function should have a continue statement after calling this method * * NOTE: Do NOT use appendCurrentChar() in this method. The line should not be * broken once the calculation starts. */
| 3279 | * broken once the calculation starts. |
| 3280 | */ |
| 3281 | void ASFormatter::formatPointerOrReference(void) |
| 3282 | { |
| 3283 | assert(currentChar == '*' || currentChar == '&' || currentChar == '^'); |
| 3284 | assert(!isJavaStyle()); |
| 3285 | |
| 3286 | int pa = pointerAlignment; |
| 3287 | int ra = referenceAlignment; |
| 3288 | int itemAlignment = (currentChar == '*' || currentChar == '^') ? pa : ((ra == REF_SAME_AS_PTR) ? pa : ra); |
| 3289 | |
| 3290 | // check for ** |
| 3291 | char peekedChar = peekNextChar(); |
| 3292 | if (currentChar == '*' && peekedChar == '*') |
| 3293 | { |
| 3294 | // remove any spaces between * and * (compiles OK if there are) |
| 3295 | if (currentLine[charNum + 1] != '*') |
| 3296 | { |
| 3297 | size_t nextPointer = currentLine.find_first_not_of(" \t", charNum + 1); |
| 3298 | assert(nextPointer != string::npos && currentLine[nextPointer] == '*'); |
| 3299 | currentLine.erase(charNum + 1, nextPointer - (charNum + 1)); |
| 3300 | } |
| 3301 | size_t nextChar = currentLine.find_first_not_of(" \t", charNum + 2); |
| 3302 | if (nextChar == string::npos) |
| 3303 | peekedChar = ' '; |
| 3304 | else |
| 3305 | peekedChar = currentLine[nextChar]; |
| 3306 | } |
| 3307 | if (currentChar == '&' && peekedChar == '&') |
| 3308 | { |
| 3309 | size_t nextChar = currentLine.find_first_not_of(" \t", charNum + 2); |
| 3310 | if (nextChar == string::npos) |
| 3311 | peekedChar = ' '; |
| 3312 | else |
| 3313 | peekedChar = currentLine[nextChar]; |
| 3314 | } |
| 3315 | // check for cast |
| 3316 | if (peekedChar == ')' || peekedChar == '>' || peekedChar == ',') |
| 3317 | { |
| 3318 | formatPointerOrReferenceCast(); |
| 3319 | return; |
| 3320 | } |
| 3321 | |
| 3322 | // check for a padded space and remove it |
| 3323 | if (charNum > 0 |
| 3324 | && !isWhiteSpace(currentLine[charNum - 1]) |
| 3325 | && formattedLine.length() > 0 |
| 3326 | && isWhiteSpace(formattedLine[formattedLine.length() - 1])) |
| 3327 | { |
| 3328 | formattedLine.erase(formattedLine.length() - 1); |
| 3329 | spacePadNum--; |
| 3330 | } |
| 3331 | |
| 3332 | if (itemAlignment == PTR_ALIGN_TYPE) |
| 3333 | { |
| 3334 | formatPointerOrReferenceToType(); |
| 3335 | } |
| 3336 | else if (itemAlignment == PTR_ALIGN_MIDDLE) |
| 3337 | { |
| 3338 | formatPointerOrReferenceToMiddle(); |
nothing calls this directly
no outgoing calls
no test coverage detected