diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 7c6b0ba87f6e..e648578c0ffa 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3615,26 +3615,50 @@ bool Variable::arrayDimensions(const Settings* settings, bool& isContainer) return arr; } +static std::string scopeTypeToString(Scope::ScopeType type) +{ + switch (type) { + case Scope::ScopeType::eGlobal: + return "Global"; + case Scope::ScopeType::eClass: + return "Class"; + case Scope::ScopeType::eStruct: + return "Struct"; + case Scope::ScopeType::eUnion: + return "Union"; + case Scope::ScopeType::eNamespace: + return "Namespace"; + case Scope::ScopeType::eFunction: + return "Function"; + case Scope::ScopeType::eIf: + return "If"; + case Scope::ScopeType::eElse: + return "Else"; + case Scope::ScopeType::eFor: + return "For"; + case Scope::ScopeType::eWhile: + return "While"; + case Scope::ScopeType::eDo: + return "Do"; + case Scope::ScopeType::eSwitch: + return "Switch"; + case Scope::ScopeType::eTry: + return "Try"; + case Scope::ScopeType::eCatch: + return "Catch"; + case Scope::ScopeType::eUnconditional: + return "Unconditional"; + case Scope::ScopeType::eLambda: + return "Lambda"; + case Scope::ScopeType::eEnum: + return "Enum"; + } + return "Unknown"; +} + static std::ostream & operator << (std::ostream & s, Scope::ScopeType type) { - s << (type == Scope::eGlobal ? "Global" : - type == Scope::eClass ? "Class" : - type == Scope::eStruct ? "Struct" : - type == Scope::eUnion ? "Union" : - type == Scope::eNamespace ? "Namespace" : - type == Scope::eFunction ? "Function" : - type == Scope::eIf ? "If" : - type == Scope::eElse ? "Else" : - type == Scope::eFor ? "For" : - type == Scope::eWhile ? "While" : - type == Scope::eDo ? "Do" : - type == Scope::eSwitch ? "Switch" : - type == Scope::eTry ? "Try" : - type == Scope::eCatch ? "Catch" : - type == Scope::eUnconditional ? "Unconditional" : - type == Scope::eLambda ? "Lambda" : - type == Scope::eEnum ? "Enum" : - "Unknown"); + s << scopeTypeToString(type); return s; } @@ -4010,137 +4034,223 @@ void SymbolDatabase::printOut(const char *title) const void SymbolDatabase::printXml(std::ostream &out) const { - out << std::setiosflags(std::ios::boolalpha); + std::string outs; std::set variables; // Scopes.. - out << " " << std::endl; + outs += " \n"; for (std::list::const_iterator scope = scopeList.cbegin(); scope != scopeList.cend(); ++scope) { - out << " type << "\""; - if (!scope->className.empty()) - out << " className=\"" << ErrorLogger::toxml(scope->className) << "\""; - if (scope->bodyStart) - out << " bodyStart=\"" << scope->bodyStart << '\"'; - if (scope->bodyEnd) - out << " bodyEnd=\"" << scope->bodyEnd << '\"'; - if (scope->nestedIn) - out << " nestedIn=\"" << scope->nestedIn << "\""; - if (scope->function) - out << " function=\"" << scope->function << "\""; - if (scope->definedType) - out << " definedType=\"" << scope->definedType << "\""; + outs += " type); + outs += "\""; + if (!scope->className.empty()) { + outs += " className=\""; + outs += ErrorLogger::toxml(scope->className); + outs += "\""; + } + if (scope->bodyStart) { + outs += " bodyStart=\""; + outs += ptr_to_string(scope->bodyStart); + outs += '\"'; + } + if (scope->bodyEnd) { + outs += " bodyEnd=\""; + outs += ptr_to_string(scope->bodyEnd); + outs += '\"'; + } + if (scope->nestedIn) { + outs += " nestedIn=\""; + outs += ptr_to_string(scope->nestedIn); + outs += "\""; + } + if (scope->function) { + outs += " function=\""; + outs += ptr_to_string(scope->function); + outs += "\""; + } + if (scope->definedType) { + outs += " definedType=\""; + outs += ptr_to_string(scope->definedType); + outs += "\""; + } if (scope->functionList.empty() && scope->varlist.empty()) - out << "/>" << std::endl; + outs += "/>\n"; else { - out << '>' << std::endl; + outs += ">\n"; if (!scope->functionList.empty()) { - out << " " << std::endl; + outs += " \n"; for (std::list::const_iterator function = scope->functionList.cbegin(); function != scope->functionList.cend(); ++function) { - out << " token - << "\" tokenDef=\"" << function->tokenDef - << "\" name=\"" << ErrorLogger::toxml(function->name()) << '\"'; - out << " type=\"" << (function->type == Function::eConstructor? "Constructor" : - function->type == Function::eCopyConstructor ? "CopyConstructor" : - function->type == Function::eMoveConstructor ? "MoveConstructor" : - function->type == Function::eOperatorEqual ? "OperatorEqual" : - function->type == Function::eDestructor ? "Destructor" : - function->type == Function::eFunction ? "Function" : - function->type == Function::eLambda ? "Lambda" : - "Unknown") << '\"'; + outs += " token); + outs += "\" tokenDef=\""; + outs += ptr_to_string(function->tokenDef); + outs += "\" name=\""; + outs += ErrorLogger::toxml(function->name()); + outs += '\"'; + outs += " type=\""; + outs += (function->type == Function::eConstructor? "Constructor" : + function->type == Function::eCopyConstructor ? "CopyConstructor" : + function->type == Function::eMoveConstructor ? "MoveConstructor" : + function->type == Function::eOperatorEqual ? "OperatorEqual" : + function->type == Function::eDestructor ? "Destructor" : + function->type == Function::eFunction ? "Function" : + function->type == Function::eLambda ? "Lambda" : + "Unknown"); + outs += '\"'; if (function->nestedIn->definedType) { if (function->hasVirtualSpecifier()) - out << " hasVirtualSpecifier=\"true\""; + outs += " hasVirtualSpecifier=\"true\""; else if (function->isImplicitlyVirtual()) - out << " isImplicitlyVirtual=\"true\""; + outs += " isImplicitlyVirtual=\"true\""; + } + if (function->access == AccessControl::Public || function->access == AccessControl::Protected || function->access == AccessControl::Private) { + outs += " access=\""; + outs += accessControlToString(function->access); + outs +="\""; } - if (function->access == AccessControl::Public || function->access == AccessControl::Protected || function->access == AccessControl::Private) - out << " access=\"" << accessControlToString(function->access) << "\""; if (function->isInlineKeyword()) - out << " isInlineKeyword=\"true\""; + outs += " isInlineKeyword=\"true\""; if (function->isStatic()) - out << " isStatic=\"true\""; + outs += " isStatic=\"true\""; if (function->isAttributeNoreturn()) - out << " isAttributeNoreturn=\"true\""; - if (const Function* overriddenFunction = function->getOverriddenFunction()) - out << " overriddenFunction=\"" << overriddenFunction << "\""; + outs += " isAttributeNoreturn=\"true\""; + if (const Function* overriddenFunction = function->getOverriddenFunction()) { + outs += " overriddenFunction=\""; + outs += ptr_to_string(overriddenFunction); + outs += "\""; + } if (function->argCount() == 0U) - out << "/>" << std::endl; + outs += "/>\n"; else { - out << ">" << std::endl; + outs += ">\n"; for (unsigned int argnr = 0; argnr < function->argCount(); ++argnr) { const Variable *arg = function->getArgumentVar(argnr); - out << " " << std::endl; + outs += " \n"; variables.insert(arg); } - out << " " << std::endl; + outs += " \n"; } } - out << " " << std::endl; + outs += " \n"; } if (!scope->varlist.empty()) { - out << " " << std::endl; - for (std::list::const_iterator var = scope->varlist.cbegin(); var != scope->varlist.cend(); ++var) - out << " " << std::endl; - out << " " << std::endl; + outs += " \n"; + for (std::list::const_iterator var = scope->varlist.cbegin(); var != scope->varlist.cend(); ++var) { + outs += " \n"; + } + outs += " \n"; } - out << " " << std::endl; + outs += " \n"; } } - out << " " << std::endl; + outs += " \n"; if (!typeList.empty()) { - out << " \n"; + outs += " \n"; for (const Type& type:typeList) { - out << " \n"; + outs += "/>\n"; continue; } - out << ">\n"; + outs += ">\n"; for (const Type::BaseInfo& baseInfo: type.derivedFrom) { - out << " \n"; - } - out << " \n"; - } - out << " \n"; + outs += " " << std::endl; + outs += " \n"; for (const Variable *var : variables) { if (!var) continue; - out << " nameToken() << '\"'; - out << " typeStartToken=\"" << var->typeStartToken() << '\"'; - out << " typeEndToken=\"" << var->typeEndToken() << '\"'; - out << " access=\"" << accessControlToString(var->mAccess) << '\"'; - out << " scope=\"" << var->scope() << '\"'; - if (var->valueType()) - out << " constness=\"" << var->valueType()->constness << '\"'; - out << " isArray=\"" << var->isArray() << '\"'; - out << " isClass=\"" << var->isClass() << '\"'; - out << " isConst=\"" << var->isConst() << '\"'; - out << " isExtern=\"" << var->isExtern() << '\"'; - out << " isPointer=\"" << var->isPointer() << '\"'; - out << " isReference=\"" << var->isReference() << '\"'; - out << " isStatic=\"" << var->isStatic() << '\"'; - out << " isVolatile=\"" << var->isVolatile() << '\"'; - out << "/>" << std::endl; - } - out << " " << std::endl; - out << std::resetiosflags(std::ios::boolalpha); + outs += " nameToken()); + outs += '\"'; + outs += " typeStartToken=\""; + outs += ptr_to_string(var->typeStartToken()); + outs += '\"'; + outs += " typeEndToken=\""; + outs += ptr_to_string(var->typeEndToken()); + outs += '\"'; + outs += " access=\""; + outs += accessControlToString(var->mAccess); + outs += '\"'; + outs += " scope=\""; + outs += ptr_to_string(var->scope()); + outs += '\"'; + if (var->valueType()) { + outs += " constness=\""; + outs += std::to_string(var->valueType()->constness); + outs += '\"'; + } + outs += " isArray=\""; + outs += bool_to_string(var->isArray()); + outs += '\"'; + outs += " isClass=\""; + outs += bool_to_string(var->isClass()); + outs += '\"'; + outs += " isConst=\""; + outs += bool_to_string(var->isConst()); + outs += '\"'; + outs += " isExtern=\""; + outs += bool_to_string(var->isExtern()); + outs += '\"'; + outs += " isPointer=\""; + outs += bool_to_string(var->isPointer()); + outs += '\"'; + outs += " isReference=\""; + outs += bool_to_string(var->isReference()); + outs += '\"'; + outs += " isStatic=\""; + outs += bool_to_string(var->isStatic()); + outs += '\"'; + outs += " isVolatile=\""; + outs += bool_to_string(var->isVolatile()); + outs += '\"'; + outs += "/>\n"; + } + outs += " \n"; + + out << outs; } //---------------------------------------------------------------------------