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

Method combineOperators

externals/simplecpp/simplecpp.cpp:1032–1158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1030}
1031
1032void simplecpp::TokenList::combineOperators()
1033{
1034 std::stack<bool> executableScope;
1035 executableScope.push(false);
1036 for (Token *tok = front(); tok; tok = tok->next) {
1037 if (tok->op == '{') {
1038 if (executableScope.top()) {
1039 executableScope.push(true);
1040 continue;
1041 }
1042 const Token *prev = tok->previous;
1043 while (prev && prev->isOneOf(";{}()"))
1044 prev = prev->previous;
1045 executableScope.push(prev && prev->op == ')');
1046 continue;
1047 }
1048 if (tok->op == '}') {
1049 if (executableScope.size() > 1)
1050 executableScope.pop();
1051 continue;
1052 }
1053
1054 if (tok->op == '.') {
1055 // ellipsis ...
1056 if (tok->next && tok->next->op == '.' && tok->next->location.col == (tok->location.col + 1) &&
1057 tok->next->next && tok->next->next->op == '.' && tok->next->next->location.col == (tok->location.col + 2)) {
1058 tok->setstr("...");
1059 deleteToken(tok->next);
1060 deleteToken(tok->next);
1061 continue;
1062 }
1063 // float literals..
1064 if (tok->previous && tok->previous->number && sameline(tok->previous, tok) && tok->previous->str().find_first_of("._") == std::string::npos) {
1065 tok->setstr(tok->previous->str() + '.');
1066 deleteToken(tok->previous);
1067 if (sameline(tok, tok->next) && (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp") && !isAlternativeAndBitandBitor(tok->next)))) {
1068 tok->setstr(tok->str() + tok->next->str());
1069 deleteToken(tok->next);
1070 }
1071 }
1072 if (tok->next && tok->next->number) {
1073 tok->setstr(tok->str() + tok->next->str());
1074 deleteToken(tok->next);
1075 }
1076 }
1077 // match: [0-9.]+E [+-] [0-9]+
1078 const char lastChar = tok->str()[tok->str().size() - 1];
1079 if (tok->number && !isOct(tok->str()) &&
1080 ((!isHex(tok->str()) && (lastChar == 'E' || lastChar == 'e')) ||
1081 (isHex(tok->str()) && (lastChar == 'P' || lastChar == 'p'))) &&
1082 tok->next && tok->next->isOneOf("+-") && tok->next->next && tok->next->next->number) {
1083 tok->setstr(tok->str() + tok->next->op + tok->next->next->str());
1084 deleteToken(tok->next);
1085 deleteToken(tok->next);
1086 }
1087
1088 if (tok->op == '\0' || !tok->next || tok->next->op == '\0')
1089 continue;

Callers

nothing calls this directly

Calls 11

deleteTokenFunction · 0.85
isFloatSuffixFunction · 0.85
isOctFunction · 0.85
isHexFunction · 0.85
isOneOfMethod · 0.80
startsWithOneOfMethod · 0.80
frontFunction · 0.70
samelineFunction · 0.70
sizeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected