Token::stringify; refactor in/out parameter to return value
This commit is contained in:
parent
e783df646a
commit
627a5e75cc
|
@ -1938,9 +1938,7 @@ void CheckIO::argumentType(std::ostream& os, const ArgumentInfo * argInfo)
|
|||
os << type->str() << "::";
|
||||
type = type->tokAt(2);
|
||||
}
|
||||
std::string s;
|
||||
type->stringify(s, false, true, false);
|
||||
os << s;
|
||||
os << type->stringify(false, true, false);
|
||||
if (type->strAt(1) == "*" && !argInfo->element)
|
||||
os << " *";
|
||||
else if (argInfo->variableInfo && !argInfo->element && argInfo->variableInfo->isArray())
|
||||
|
@ -1957,10 +1955,7 @@ void CheckIO::argumentType(std::ostream& os, const ArgumentInfo * argInfo)
|
|||
os << type->originalName();
|
||||
if (type->strAt(1) == "*" || argInfo->address)
|
||||
os << " *";
|
||||
os << " {aka ";
|
||||
std::string s;
|
||||
type->stringify(s, false, true, false);
|
||||
os << s;
|
||||
os << " {aka " << type->stringify(false, true, false);
|
||||
if (type->strAt(1) == "*" || argInfo->address)
|
||||
os << " *";
|
||||
os << "}";
|
||||
|
|
|
@ -3488,9 +3488,7 @@ void SymbolDatabase::printOut(const char *title) const
|
|||
if (scope->type == Scope::eEnum) {
|
||||
std::cout << " enumType: ";
|
||||
if (scope->enumType) {
|
||||
std::string s;
|
||||
scope->enumType->stringify(s, false, true, false);
|
||||
std::cout << s;
|
||||
std::cout << scope->enumType->stringify(false, true, false);
|
||||
} else
|
||||
std::cout << "int";
|
||||
std::cout << std::endl;
|
||||
|
|
|
@ -1174,55 +1174,58 @@ void Token::printLines(int lines) const
|
|||
std::cout << stringifyList(stringifyOptions::forDebugExprId(), nullptr, end) << std::endl;
|
||||
}
|
||||
|
||||
void Token::stringify(std::string& os, const stringifyOptions& options) const
|
||||
std::string Token::stringify(const stringifyOptions& options) const
|
||||
{
|
||||
std::string ret;
|
||||
if (options.attributes) {
|
||||
if (isUnsigned())
|
||||
os += "unsigned ";
|
||||
ret += "unsigned ";
|
||||
else if (isSigned())
|
||||
os += "signed ";
|
||||
ret += "signed ";
|
||||
if (isComplex())
|
||||
os += "_Complex ";
|
||||
ret += "_Complex ";
|
||||
if (isLong()) {
|
||||
if (!(mTokType == eString || mTokType == eChar))
|
||||
os += "long ";
|
||||
ret += "long ";
|
||||
}
|
||||
}
|
||||
if (options.macro && isExpandedMacro())
|
||||
os += '$';
|
||||
ret += '$';
|
||||
if (isName() && mStr.find(' ') != std::string::npos) {
|
||||
for (char i : mStr) {
|
||||
if (i != ' ')
|
||||
os += i;
|
||||
ret += i;
|
||||
}
|
||||
} else if (mStr[0] != '\"' || mStr.find('\0') == std::string::npos)
|
||||
os += mStr;
|
||||
ret += mStr;
|
||||
else {
|
||||
for (char i : mStr) {
|
||||
if (i == '\0')
|
||||
os += "\\0";
|
||||
ret += "\\0";
|
||||
else
|
||||
os += i;
|
||||
ret += i;
|
||||
}
|
||||
}
|
||||
if (options.varid && mImpl->mVarId != 0) {
|
||||
os += '@';
|
||||
os += (options.idtype ? "var" : "");
|
||||
os += std::to_string(mImpl->mVarId);
|
||||
ret += '@';
|
||||
ret += (options.idtype ? "var" : "");
|
||||
ret += std::to_string(mImpl->mVarId);
|
||||
} else if (options.exprid && mImpl->mExprId != 0) {
|
||||
os += '@';
|
||||
os += (options.idtype ? "expr" : "");
|
||||
os += std::to_string(mImpl->mExprId);
|
||||
ret += '@';
|
||||
ret += (options.idtype ? "expr" : "");
|
||||
ret += std::to_string(mImpl->mExprId);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Token::stringify(std::string& os, bool varid, bool attributes, bool macro) const
|
||||
std::string Token::stringify(bool varid, bool attributes, bool macro) const
|
||||
{
|
||||
stringifyOptions options;
|
||||
options.varid = varid;
|
||||
options.attributes = attributes;
|
||||
options.macro = macro;
|
||||
stringify(os, options);
|
||||
return stringify(options);
|
||||
}
|
||||
|
||||
std::string Token::stringifyList(const stringifyOptions& options, const std::vector<std::string>* fileNames, const Token* end) const
|
||||
|
@ -1292,7 +1295,7 @@ std::string Token::stringifyList(const stringifyOptions& options, const std::vec
|
|||
lineNumber = tok->linenr();
|
||||
}
|
||||
|
||||
tok->stringify(ret, options); // print token
|
||||
ret += tok->stringify(options); // print token
|
||||
if (tok->next() != end && (!options.linebreaks || (tok->next()->linenr() == tok->linenr() && tok->next()->fileIndex() == tok->fileIndex())))
|
||||
ret += ' ';
|
||||
}
|
||||
|
|
|
@ -887,16 +887,15 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
void stringify(std::string& os, const stringifyOptions& options) const;
|
||||
std::string stringify(const stringifyOptions& options) const;
|
||||
|
||||
/**
|
||||
* Stringify a token
|
||||
* @param os The result is shifted into that output stream
|
||||
* @param varid Print varids. (Style: "varname\@id")
|
||||
* @param attributes Print attributes of tokens like "unsigned" in front of it.
|
||||
* @param macro Prints $ in front of the token if it was expanded from a macro.
|
||||
*/
|
||||
void stringify(std::string& os, bool varid, bool attributes, bool macro) const;
|
||||
std::string stringify(bool varid, bool attributes, bool macro) const;
|
||||
|
||||
std::string stringifyList(const stringifyOptions& options, const std::vector<std::string>* fileNames = nullptr, const Token* end = nullptr) const;
|
||||
std::string stringifyList(const Token* end, bool attributes = true) const;
|
||||
|
|
Loading…
Reference in New Issue