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() << "::";
|
os << type->str() << "::";
|
||||||
type = type->tokAt(2);
|
type = type->tokAt(2);
|
||||||
}
|
}
|
||||||
std::string s;
|
os << type->stringify(false, true, false);
|
||||||
type->stringify(s, false, true, false);
|
|
||||||
os << s;
|
|
||||||
if (type->strAt(1) == "*" && !argInfo->element)
|
if (type->strAt(1) == "*" && !argInfo->element)
|
||||||
os << " *";
|
os << " *";
|
||||||
else if (argInfo->variableInfo && !argInfo->element && argInfo->variableInfo->isArray())
|
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();
|
os << type->originalName();
|
||||||
if (type->strAt(1) == "*" || argInfo->address)
|
if (type->strAt(1) == "*" || argInfo->address)
|
||||||
os << " *";
|
os << " *";
|
||||||
os << " {aka ";
|
os << " {aka " << type->stringify(false, true, false);
|
||||||
std::string s;
|
|
||||||
type->stringify(s, false, true, false);
|
|
||||||
os << s;
|
|
||||||
if (type->strAt(1) == "*" || argInfo->address)
|
if (type->strAt(1) == "*" || argInfo->address)
|
||||||
os << " *";
|
os << " *";
|
||||||
os << "}";
|
os << "}";
|
||||||
|
|
|
@ -3488,9 +3488,7 @@ void SymbolDatabase::printOut(const char *title) const
|
||||||
if (scope->type == Scope::eEnum) {
|
if (scope->type == Scope::eEnum) {
|
||||||
std::cout << " enumType: ";
|
std::cout << " enumType: ";
|
||||||
if (scope->enumType) {
|
if (scope->enumType) {
|
||||||
std::string s;
|
std::cout << scope->enumType->stringify(false, true, false);
|
||||||
scope->enumType->stringify(s, false, true, false);
|
|
||||||
std::cout << s;
|
|
||||||
} else
|
} else
|
||||||
std::cout << "int";
|
std::cout << "int";
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
|
@ -1174,55 +1174,58 @@ void Token::printLines(int lines) const
|
||||||
std::cout << stringifyList(stringifyOptions::forDebugExprId(), nullptr, end) << std::endl;
|
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 (options.attributes) {
|
||||||
if (isUnsigned())
|
if (isUnsigned())
|
||||||
os += "unsigned ";
|
ret += "unsigned ";
|
||||||
else if (isSigned())
|
else if (isSigned())
|
||||||
os += "signed ";
|
ret += "signed ";
|
||||||
if (isComplex())
|
if (isComplex())
|
||||||
os += "_Complex ";
|
ret += "_Complex ";
|
||||||
if (isLong()) {
|
if (isLong()) {
|
||||||
if (!(mTokType == eString || mTokType == eChar))
|
if (!(mTokType == eString || mTokType == eChar))
|
||||||
os += "long ";
|
ret += "long ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.macro && isExpandedMacro())
|
if (options.macro && isExpandedMacro())
|
||||||
os += '$';
|
ret += '$';
|
||||||
if (isName() && mStr.find(' ') != std::string::npos) {
|
if (isName() && mStr.find(' ') != std::string::npos) {
|
||||||
for (char i : mStr) {
|
for (char i : mStr) {
|
||||||
if (i != ' ')
|
if (i != ' ')
|
||||||
os += i;
|
ret += i;
|
||||||
}
|
}
|
||||||
} else if (mStr[0] != '\"' || mStr.find('\0') == std::string::npos)
|
} else if (mStr[0] != '\"' || mStr.find('\0') == std::string::npos)
|
||||||
os += mStr;
|
ret += mStr;
|
||||||
else {
|
else {
|
||||||
for (char i : mStr) {
|
for (char i : mStr) {
|
||||||
if (i == '\0')
|
if (i == '\0')
|
||||||
os += "\\0";
|
ret += "\\0";
|
||||||
else
|
else
|
||||||
os += i;
|
ret += i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.varid && mImpl->mVarId != 0) {
|
if (options.varid && mImpl->mVarId != 0) {
|
||||||
os += '@';
|
ret += '@';
|
||||||
os += (options.idtype ? "var" : "");
|
ret += (options.idtype ? "var" : "");
|
||||||
os += std::to_string(mImpl->mVarId);
|
ret += std::to_string(mImpl->mVarId);
|
||||||
} else if (options.exprid && mImpl->mExprId != 0) {
|
} else if (options.exprid && mImpl->mExprId != 0) {
|
||||||
os += '@';
|
ret += '@';
|
||||||
os += (options.idtype ? "expr" : "");
|
ret += (options.idtype ? "expr" : "");
|
||||||
os += std::to_string(mImpl->mExprId);
|
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;
|
stringifyOptions options;
|
||||||
options.varid = varid;
|
options.varid = varid;
|
||||||
options.attributes = attributes;
|
options.attributes = attributes;
|
||||||
options.macro = macro;
|
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
|
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();
|
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())))
|
if (tok->next() != end && (!options.linebreaks || (tok->next()->linenr() == tok->linenr() && tok->next()->fileIndex() == tok->fileIndex())))
|
||||||
ret += ' ';
|
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
|
* Stringify a token
|
||||||
* @param os The result is shifted into that output stream
|
|
||||||
* @param varid Print varids. (Style: "varname\@id")
|
* @param varid Print varids. (Style: "varname\@id")
|
||||||
* @param attributes Print attributes of tokens like "unsigned" in front of it.
|
* @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.
|
* @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 stringifyOptions& options, const std::vector<std::string>* fileNames = nullptr, const Token* end = nullptr) const;
|
||||||
std::string stringifyList(const Token* end, bool attributes = true) const;
|
std::string stringifyList(const Token* end, bool attributes = true) const;
|
||||||
|
|
Loading…
Reference in New Issue