|
22 | 22 | #include "tokenize.h" |
23 | 23 | #include "utils.h" |
24 | 24 |
|
| 25 | +#include <cstring> |
25 | 26 | #include <algorithm> |
| 27 | +#include <iostream> |
26 | 28 | #include <memory> |
| 29 | +#include <stack> |
27 | 30 | #include <vector> |
28 | | -#include <iostream> |
29 | 31 |
|
30 | 32 | static const std::string AccessSpecDecl = "AccessSpecDecl"; |
31 | 33 | static const std::string ArraySubscriptExpr = "ArraySubscriptExpr"; |
@@ -110,8 +112,8 @@ static std::vector<std::string> splitString(const std::string &line) |
110 | 112 | std::string::size_type pos1 = line.find_first_not_of(" "); |
111 | 113 | while (pos1 < line.size()) { |
112 | 114 | std::string::size_type pos2; |
113 | | - if (line[pos1] == '*') { |
114 | | - ret.push_back("*"); |
| 115 | + if (std::strchr("*()", line[pos1])) { |
| 116 | + ret.push_back(line.substr(pos1,1)); |
115 | 117 | pos1 = line.find_first_not_of(" ", pos1 + 1); |
116 | 118 | continue; |
117 | 119 | } |
@@ -509,8 +511,21 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList *tokenList, const s |
509 | 511 | } else |
510 | 512 | type = unquote(str); |
511 | 513 |
|
512 | | - for (const std::string &s: splitString(type)) |
513 | | - addtoken(tokenList, s, false); |
| 514 | + if (type.find("(*)(") != std::string::npos) { |
| 515 | + type.erase(type.find("(*)(")); |
| 516 | + type += "*"; |
| 517 | + } |
| 518 | + |
| 519 | + std::stack<Token *> lpar; |
| 520 | + for (const std::string &s: splitString(type)) { |
| 521 | + Token *tok = addtoken(tokenList, s, false); |
| 522 | + if (tok->str() == "(") |
| 523 | + lpar.push(tok); |
| 524 | + else if (tok->str() == ")") { |
| 525 | + Token::createMutualLinks(tok, lpar.top()); |
| 526 | + lpar.pop(); |
| 527 | + } |
| 528 | + } |
514 | 529 |
|
515 | 530 | // Set Type |
516 | 531 | if (!scope) { |
@@ -1379,20 +1394,19 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList *tokenList) |
1379 | 1394 | Token * clangimport::AstNode::createTokensVarDecl(TokenList *tokenList) |
1380 | 1395 | { |
1381 | 1396 | const std::string addr = mExtTokens.front(); |
1382 | | - const Token *startToken = nullptr; |
1383 | 1397 | if (contains(mExtTokens, "static")) |
1384 | | - startToken = addtoken(tokenList, "static"); |
| 1398 | + addtoken(tokenList, "static"); |
1385 | 1399 | int typeIndex = mExtTokens.size() - 1; |
1386 | 1400 | while (typeIndex > 1 && std::isalpha(mExtTokens[typeIndex][0])) |
1387 | 1401 | typeIndex--; |
1388 | 1402 | const std::string type = mExtTokens[typeIndex]; |
1389 | 1403 | const std::string name = mExtTokens[typeIndex - 1]; |
| 1404 | + const Token *startToken = tokenList->back(); |
1390 | 1405 | const ::Type *recordType = addTypeTokens(tokenList, type); |
1391 | | - if (!startToken && tokenList->back()) { |
1392 | | - startToken = tokenList->back(); |
1393 | | - while (Token::Match(startToken->previous(), "%type%|*|&|&&")) |
1394 | | - startToken = startToken->previous(); |
1395 | | - } |
| 1406 | + if (!startToken) |
| 1407 | + startToken = tokenList->front(); |
| 1408 | + else if (startToken->str() != "static") |
| 1409 | + startToken = startToken->next(); |
1396 | 1410 | Token *vartok1 = addtoken(tokenList, name); |
1397 | 1411 | Scope *scope = const_cast<Scope *>(tokenList->back()->scope()); |
1398 | 1412 | scope->varlist.push_back(Variable(vartok1, unquote(type), startToken, vartok1->previous(), 0, scope->defaultAccess(), recordType, scope)); |
|
0 commit comments