MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / multiComparePercent

Function multiComparePercent

lib/token.cpp:413–545  ·  view source on GitHub ↗

GCC does not inline this by itself need to use the old syntax since the C++11 [[xxx:always_inline]] cannot be used here

Source from the content-addressed store, hash-verified

411// GCC does not inline this by itself
412// need to use the old syntax since the C++11 [[xxx:always_inline]] cannot be used here
413inline __attribute__((always_inline))
414#endif
415int multiComparePercent(const Token *tok, const char*& haystack, nonneg int varid)
416{
417 ++haystack;
418 // Compare only the first character of the string for optimization reasons
419 switch (haystack[0]) {
420 case 'v':
421 if (haystack[3] == '%') { // %var%
422 haystack += 4;
423 if (tok->varId() != 0)
424 return 1;
425 } else { // %varid%
426 if (varid == 0) {
427 throw InternalError(tok, "Internal error. Token::Match called with varid 0.");
428 }
429
430 haystack += 6;
431
432 if (tok->varId() == varid)
433 return 1;
434 }
435 break;
436 case 't':
437 // Type (%type%)
438 {
439 haystack += 5;
440 if (tok->isName() && tok->varId() == 0)
441 return 1;
442 }
443 break;
444 case 'a':
445 // Accept any token (%any%) or assign (%assign%)
446 {
447 if (haystack[3] == '%') { // %any%
448 haystack += 4;
449 return 1;
450 }
451 // %assign%
452 haystack += 7;
453 if (tok->isAssignmentOp())
454 return 1;
455 }
456 break;
457 case 'n':
458 // Number (%num%) or name (%name%)
459 {
460 if (haystack[4] == '%') { // %name%
461 haystack += 5;
462 if (tok->isName())
463 return 1;
464 } else {
465 haystack += 4;
466 if (tok->isNumber())
467 return 1;
468 }
469 }
470 break;

Callers 1

multiCompareImplFunction · 0.85

Calls 4

isAssignmentOpMethod · 0.80
isConstOpMethod · 0.80
isOpMethod · 0.80
strMethod · 0.45

Tested by

no test coverage detected