Commit 37313543 authored by Milian Wolff's avatar Milian Wolff

Compile code with strict pedantic string defines, to prevent runtime conversions.

parent fb2aa52c
......@@ -17,11 +17,6 @@ include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings)
add_definitions(
-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS -DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_BYTEARRAY
)
find_package(Qt5 REQUIRED Core Widgets Test)
find_package(KF5 REQUIRED COMPONENTS KDELibs4Support ThreadWeaver TextEditor I18n)
find_package(KDevPlatform ${KDEVPLATFORM_VERSION} REQUIRED)
......@@ -59,11 +54,17 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/libs
)
add_subdirectory(tests)
add_definitions(
-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS -DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_BYTEARRAY
)
add_subdirectory(duchain)
add_subdirectory(codecompletion)
add_subdirectory(codegen)
add_subdirectory(util)
add_subdirectory(tests)
set(kdevclangsupport_SRCS
clangparsejob.cpp
......
......@@ -98,7 +98,7 @@ Path::List readPathListFile(const QString& filepath)
}
const QString text = QString::fromLocal8Bit(f.readAll());
const QStringList lines = text.split('\n', QString::SkipEmptyParts);
const QStringList lines = text.split(QLatin1Char('\n'), QString::SkipEmptyParts);
Path::List paths(lines.length());
std::transform(lines.begin(), lines.end(), paths.begin(), [] (const QString& line) { return Path(line); });
return paths;
......@@ -160,7 +160,7 @@ QString languageStandard(ProjectFileItem* item)
auto cfg = item->project()->projectConfiguration();
auto grp = cfg->group("CustomDefinesAndIncludes");
for (const QString& grpName : grp.groupList()) {
if (grpName.startsWith("ProjectPath")) {
if (grpName.startsWith(QLatin1String("ProjectPath"))) {
KConfigGroup pathgrp = grp.group(grpName);
PathStandard entry;
entry.path = pathgrp.readEntry("Path", "");
......
......@@ -92,14 +92,14 @@ KTextEditor::Range rangeForIncludePathSpec(const QString& line, const KTextEdito
KTextEditor::Range range = originalRange;
int pos = 0;
for (; pos < line.size(); ++pos) {
if(line[pos] == '"' || line[pos] == '<') {
if(line[pos] == QLatin1Char('"') || line[pos] == QLatin1Char('<')) {
range.setStart({range.start().line(), ++pos});
break;
}
}
for (; pos < line.size(); ++pos) {
if(line[pos] == '"' || line[pos] == '>') {
if(line[pos] == QLatin1Char('"') || line[pos] == QLatin1Char('>')) {
range.setEnd({range.start().line(), pos});
break;
}
......@@ -172,7 +172,7 @@ QPair<TopDUContextPointer, KTextEditor::Range> importedContextForPosition(const
auto includeName = line.mid(wordRange.start().column(), wordRange.end().column() - wordRange.start().column());
if (!includeName.isEmpty()) {
if (includeName.startsWith('.')) {
if (includeName.startsWith(QLatin1Char('.'))) {
const Path dir = Path(url).parent();
includeName = Path(dir, includeName).toLocalFile();
}
......@@ -181,7 +181,7 @@ QPair<TopDUContextPointer, KTextEditor::Range> importedContextForPosition(const
auto iterator = recursiveImports.iterator();
while (iterator) {
const auto str = (*iterator).url().str();
if (str == includeName || (str.endsWith(includeName) && str[str.size()-includeName.size()-1]=='/')) {
if (str == includeName || (str.endsWith(includeName) && str[str.size()-includeName.size()-1] == QLatin1Char('/'))) {
return {TopDUContextPointer((*iterator).data()), wordRange};
}
++iterator;
......@@ -293,7 +293,7 @@ void ClangSupport::createActionsForMainWindow (Sublime::MainWindow* /*window*/,
QAction* renameDeclarationAction = actions.addAction(QStringLiteral("code_rename_declaration"));
renameDeclarationAction->setText( i18n("Rename Declaration") );
renameDeclarationAction->setIcon(QIcon::fromTheme("edit-rename"));
renameDeclarationAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename")));
renameDeclarationAction->setShortcut( Qt::CTRL | Qt::ALT | Qt::Key_R);
connect(renameDeclarationAction, &QAction::triggered,
m_refactoring, &SimpleRefactoring::executeRenameAction);
......
......@@ -66,7 +66,7 @@ QStringList templateTypeArguments(CXCursor cursor)
{
QStringList types;
QString tStr = ClangString(clang_getTypeSpelling(clang_getCursorType(cursor))).toString();
ParamIterator iter("<>", tStr);
ParamIterator iter(QStringLiteral("<>"), tStr);
while (iter) {
types.append(*iter);
......@@ -105,7 +105,7 @@ FuncOverrideInfo processCXXMethod(CXCursor cursor, OverrideInfo* info)
if (info->templateTypeMap.contains(type)) {
type = info->templateTypeMap.value(type);
}
params << type + ' ' + id;
params << type + QLatin1Char(' ') + id;
}
FuncOverrideInfo fp;
......@@ -218,19 +218,19 @@ CXChildVisitResult declVisitor(CXCursor cursor, CXCursor parent, CXClientData d)
}
if (kind == CXCursor_ClassTemplate || kind == CXCursor_ClassTemplatePartialSpecialization) {
part = name + "::";
part = name + QLatin1String("::");
//If we're at a template, we need to construct the template<typename T1, typename T2>
//which goes at the front of the prototype
QStringList templateTypes = templateParams(kind == CXCursor_ClassTemplate ? cursor : clang_getSpecializedCursorTemplate(cursor));
templatePrefix = QString("template<");
templatePrefix = QLatin1String("template<");
for (int i = 0; i < templateTypes.count(); i++) {
templatePrefix = templatePrefix + ((i > 0) ? ", " : "") + "typename " + templateTypes.at(i);
templatePrefix = templatePrefix + QLatin1String((i > 0) ? ", " : "") + QLatin1String("typename ") + templateTypes.at(i);
}
templatePrefix = templatePrefix + "> ";
templatePrefix = templatePrefix + QLatin1String("> ");
} else {
part = name + "::";
part = name + QLatin1String("::");
}
}
......@@ -268,7 +268,7 @@ CXChildVisitResult declVisitor(CXCursor cursor, CXCursor parent, CXClientData d)
QString returnType, rest;
if (kind != CXCursor_Constructor && kind != CXCursor_Destructor) {
int spaceIndex = signature.indexOf(" ");
int spaceIndex = signature.indexOf(QLatin1Char(' '));
returnType = signature.left(spaceIndex);
rest = signature.right(signature.count() - spaceIndex - 1);
} else {
......@@ -304,7 +304,7 @@ void CompletionHelper::computeCompletions(const ParseSession& session, CXFile fi
if (clang_equalLocations(clang_getNullLocation(), location)) {
clangDebug() << "Completion helper given invalid position " << position
<< " in file " << ClangString(clang_getFileName(file));
<< " in file " << clang_getFileName(file);
return;
}
......
......@@ -135,7 +135,7 @@ public:
{
if (role == Qt::DecorationRole) {
if (index.column() == KTextEditor::CodeCompletionModel::Icon) {
static const QIcon icon = QIcon::fromTheme("CTparents");
static const QIcon icon = QIcon::fromTheme(QStringLiteral("CTparents"));
return icon;
}
}
......@@ -144,7 +144,7 @@ public:
void execute(KTextEditor::View* view, const KTextEditor::Range& word) override
{
view->document()->replaceText(word, "virtual " + m_returnType + ' ' + m_display);
view->document()->replaceText(word, QLatin1String("virtual ") + m_returnType + QLatin1Char(' ') + m_display);
}
private:
......@@ -157,8 +157,8 @@ public:
ImplementsItem(const FuncImplementInfo& item)
: CompletionItem<KDevelop::CompletionTreeItem>(
item.prototype,
i18n("Implement %1", item.isConstructor ? "<constructor>" :
item.isDestructor ? "<destructor>" : item.returnType)
i18n("Implement %1", item.isConstructor ? QStringLiteral("<constructor>") :
item.isDestructor ? QStringLiteral("<destructor>") : item.returnType)
)
, m_item(item)
{
......@@ -168,7 +168,7 @@ public:
{
if (role == Qt::DecorationRole) {
if (index.column() == KTextEditor::CodeCompletionModel::Icon) {
static const QIcon icon = QIcon::fromTheme("CTsuppliers");
static const QIcon icon = QIcon::fromTheme(QStringLiteral("CTsuppliers"));
return icon;
}
}
......@@ -179,9 +179,9 @@ public:
{
QString replacement = m_item.templatePrefix;
if (!m_item.isDestructor && !m_item.isConstructor) {
replacement += m_item.returnType + ' ';
replacement += m_item.returnType + QLatin1Char(' ');
}
replacement += m_item.prototype + "\n{\n}\n";
replacement += m_item.prototype + QLatin1String("\n{\n}\n");
view->document()->replaceText(word, replacement);
}
......@@ -225,7 +225,7 @@ public:
}
if(m_declaration->isFunctionDeclaration()) {
repl += "()";
repl += QLatin1String("()");
view->document()->replaceText(word, repl);
auto f = m_declaration->type<FunctionType>();
if (f && f->indexedArgumentsSize()) {
......@@ -335,7 +335,7 @@ bool isInsideComment(CXTranslationUnit unit, CXFile file, const KTextEditor::Cur
QString& elideStringRight(QString& str, int length)
{
if (str.size() > length + 3) {
return str.replace(length, str.size() - length, "...");
return str.replace(length, str.size() - length, QLatin1String("..."));
}
return str;
}
......@@ -390,7 +390,7 @@ bool isValidCompletionIdentifier(const QualifiedIdentifier& identifier)
return false; // is constructor
}
const QString idString = id.toString();
if (idString.startsWith("~") && scope.toString() == idString.midRef(1)) {
if (idString.startsWith(QLatin1Char('~')) && scope.toString() == idString.midRef(1)) {
return false; // is destructor
}
return true;
......@@ -412,7 +412,7 @@ bool isValidSpecialCompletionIdentifier(const QualifiedIdentifier& identifier)
const Identifier id = identifier.last();
const QString idString = id.toString();
if (idString.startsWith("operator=")) {
if (idString.startsWith(QLatin1String("operator="))) {
return true; // is assignment operator
}
return false;
......@@ -655,7 +655,7 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
case CXCompletionChunk_RightParen:
--parenDepth;
if (signatureState == Inside && !parenDepth) {
display += ')';
display += QLatin1Char(')');
signatureState = After;
}
break;
......@@ -698,7 +698,7 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
const bool bestMatch = completionPriority <= CCP_SuperCompletion;
//don't set best match property for internal identifiers, also prefer declarations from current file
if (bestMatch && !found->indexedIdentifier().identifier().toString().startsWith("__") ) {
if (bestMatch && !found->indexedIdentifier().identifier().toString().startsWith(QLatin1String("__")) ) {
const int matchQuality = codeCompletionPriorityToMatchQuality(completionPriority);
declarationItem->setMatchQuality(matchQuality);
} else {
......@@ -726,7 +726,7 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
if (result.CursorKind == CXCursor_MacroDefinition) {
// TODO: grouping of macros and built-in stuff
static const QIcon icon = QIcon::fromTheme("code-macro");
static const QIcon icon = QIcon::fromTheme(QStringLiteral("code-macro"));
auto item = CompletionTreeItemPointer(new SimpleItem(display, resultType, replacement, icon));
macros.append(item);
} else if (result.CursorKind == CXCursor_NotImplemented) {
......@@ -769,11 +769,11 @@ void ClangCodeCompletionContext::addOverwritableItems()
QList<CompletionTreeItemPointer> overrides;
for (int i = 0; i < overrideList.count(); i++) {
FuncOverrideInfo info = overrideList.at(i);
QString nameAndParams = info.name + '(' + info.params.join(", ") + ')';
QString nameAndParams = info.name + QLatin1Char('(') + info.params.join(QLatin1String(", ")) + QLatin1Char(')');
if(info.isConst)
nameAndParams = nameAndParams + " const";
nameAndParams = nameAndParams + QLatin1String(" const");
if(info.isVirtual)
nameAndParams = nameAndParams + " = 0";
nameAndParams = nameAndParams + QLatin1String(" = 0");
overrides << CompletionTreeItemPointer(new OverrideItem(nameAndParams, info.returnType));
}
eventuallyAddGroup(i18n("Virtual Override"), 0, overrides);
......
......@@ -61,7 +61,7 @@ IncludePathProperties includePathProperties(const QString& text, int rightBounda
{
IncludePathProperties properties;
int idx = text.lastIndexOf('\n');
int idx = text.lastIndexOf(QLatin1Char('\n'));
if (idx == -1) {
idx = 0;
}
......@@ -78,23 +78,23 @@ IncludePathProperties includePathProperties(const QString& text, int rightBounda
FindTypeEnd
};
FindState state = FindBang;
char expectedEnd = '>';
QChar expectedEnd = QLatin1Char('>');
for (; idx < text.size(); ++idx) {
const auto c = text.at(idx);
if (c.isSpace()) {
continue;
}
if (c == '/' && state != FindTypeEnd) {
if (c == QLatin1Char('/') && state != FindTypeEnd) {
// skip comments
if (idx >= text.length() - 1 || text.at(idx + 1) != '*') {
if (idx >= text.length() - 1 || text.at(idx + 1) != QLatin1Char('*')) {
properties.valid = false;
return properties;
}
idx += 2;
while (idx < text.length() - 1 && (text.at(idx) != '*' || text.at(idx + 1) != '/')) {
while (idx < text.length() - 1 && (text.at(idx) != QLatin1Char('*') || text.at(idx + 1) != QLatin1Char('/'))) {
++idx;
}
if (idx >= text.length() - 1 || text.at(idx) != '*' || text.at(idx + 1) != '/') {
if (idx >= text.length() - 1 || text.at(idx) != QLatin1Char('*') || text.at(idx + 1) != QLatin1Char('/')) {
properties.valid = false;
return properties;
}
......@@ -103,13 +103,13 @@ IncludePathProperties includePathProperties(const QString& text, int rightBounda
}
switch (state) {
case FindBang:
if (c != '#') {
if (c != QLatin1Char('#')) {
return properties;
}
state = FindInclude;
break;
case FindInclude:
if (text.midRef(idx, 7) != "include") {
if (text.midRef(idx, 7) != QLatin1String("include")) {
return properties;
}
idx += 6;
......@@ -118,10 +118,10 @@ IncludePathProperties includePathProperties(const QString& text, int rightBounda
break;
case FindType:
properties.inputFrom = idx + 1;
if (c == '"') {
expectedEnd = '"';
if (c == QLatin1Char('"')) {
expectedEnd = QLatin1Char('"');
properties.local = true;
} else if (c != '<') {
} else if (c != QLatin1Char('<')) {
properties.valid = false;
return properties;
}
......@@ -148,7 +148,7 @@ IncludePathProperties includePathProperties(const QString& text, int rightBounda
if (properties.inputFrom != -1) {
int end = properties.inputTo;
if (end >= rightBoundary || end == -1) {
end = text.lastIndexOf('/', rightBoundary - 1) + 1;
end = text.lastIndexOf(QLatin1Char('/'), rightBoundary - 1) + 1;
}
if (end > 0) {
properties.prefixPath = text.mid(properties.inputFrom, end - properties.inputFrom);
......@@ -184,7 +184,7 @@ QList<KDevelop::IncludeItem> includeItemsForUrl(const QUrl& url, const IncludePa
KDevelop::IncludeItem item;
item.name = dirIterator.fileName();
if (item.name.startsWith('.') || item.name.endsWith('~')) { //filter out ".", "..", hidden files, and backups
if (item.name.startsWith(QLatin1Char('.')) || item.name.endsWith(QLatin1Char('~'))) { //filter out ".", "..", hidden files, and backups
continue;
}
......@@ -193,7 +193,7 @@ QList<KDevelop::IncludeItem> includeItemsForUrl(const QUrl& url, const IncludePa
// filter files that are not a header
// note: system headers sometimes don't have any extension, and we still want to show those
if (!item.isDirectory && item.name.contains('.') && !ClangHelpers::isHeader(item.name)) {
if (!item.isDirectory && item.name.contains(QLatin1Char('.')) && !ClangHelpers::isHeader(item.name)) {
continue;
}
......@@ -234,19 +234,19 @@ public:
return;
}
QString newText = includeItem.isDirectory ? includeItem.name + '/' : includeItem.name;
QString newText = includeItem.isDirectory ? (includeItem.name + QLatin1Char('/')) : includeItem.name;
if (properties.inputFrom == -1) {
newText.prepend('<');
newText.prepend(QLatin1Char('<'));
} else {
range.setStart({lineNumber, properties.inputFrom});
}
if (properties.inputTo == -1) {
// Add suffix
if (properties.local) {
newText += '"';
newText += QLatin1Char('"');
} else {
newText += '>';
newText += QLatin1Char('>');
}
// replace the whole line
......
......@@ -44,14 +44,14 @@ namespace {
bool includePathCompletionRequired(const QString& text)
{
QString line;
const int idx = text.lastIndexOf('\n');
const int idx = text.lastIndexOf(QLatin1Char('\n'));
if (idx != -1) {
line = text.mid(idx + 1).trimmed();
} else {
line = text.trimmed();
}
const static QRegularExpression includeRegExp("^\\s*#\\s*include");
const static QRegularExpression includeRegExp(QStringLiteral("^\\s*#\\s*include"));
if (!line.contains(includeRegExp)) {
return false;
}
......@@ -59,7 +59,7 @@ bool includePathCompletionRequired(const QString& text)
return true;
}
QSharedPointer<CodeCompletionContext> createCompletionContext(const KDevelop::DUContextPointer& context,
QSharedPointer<CodeCompletionContext> createCompletionContext(const DUContextPointer& context,
const ParseSessionData::Ptr& session,
const QUrl& url,
const KTextEditor::Cursor& position,
......
......@@ -49,19 +49,19 @@ QString makeSignatureString(const Declaration* functionDecl, const Signature& si
QString ret = CodegenHelper::simplifiedTypeString(signature.returnType.abstractType(),
visibilityFrom);
ret += ' ';
ret += QLatin1Char(' ');
QualifiedIdentifier namespaceIdentifier = visibilityFrom->scopeIdentifier(false);
Identifier id(IndexedString(functionDecl->qualifiedIdentifier().mid(namespaceIdentifier.count()).toString()));
ret += functionDecl->identifier().toString();
ret += '(';
ret += QLatin1Char('(');
int pos = 0;
foreach(const ParameterItem &item, signature.parameters)
{
if (pos != 0) {
ret += ", ";
ret += QLatin1String(", ");
}
///TODO: merge common code with helpers.cpp::createArgumentList
......@@ -76,24 +76,24 @@ QString makeSignatureString(const Declaration* functionDecl, const Signature& si
arrayAppendix.prepend(QStringLiteral("[%1]").arg(arrayType->dimension()));
} else {
// dimensionless
arrayAppendix.prepend(QStringLiteral("[]"));
arrayAppendix.prepend(QLatin1String("[]"));
}
}
ret += CodegenHelper::simplifiedTypeString(type,
visibilityFrom);
if (!item.second.isEmpty()) {
ret += ' ' + item.second;
ret += QLatin1Char(' ') + item.second;
}
ret += arrayAppendix;
if (signature.defaultParams.size() > pos && !signature.defaultParams[pos].isEmpty()) {
ret += " = " + signature.defaultParams[pos];
ret += QLatin1String(" = ") + signature.defaultParams[pos];
}
++pos;
}
ret += ')';
ret += QLatin1Char(')');
if (signature.isConst) {
ret += " const";
ret += QLatin1String(" const");
}
return ret;
}
......@@ -168,7 +168,7 @@ void AdaptSignatureAction::execute()
QString newText = makeSignatureString(otherSide, m_newSignature);
if (!m_editingDefinition) {
// append a newline after the method signature in case the method definition follows
newText += "\n";
newText += QLatin1Char('\n');
}
DocumentChange changeParameters(functionContext->url(), parameterRange, QString(), newText);
......
......@@ -55,7 +55,7 @@ Signature getDeclarationSignature(const Declaration *functionDecl, const DUConte
Signature signature;
const AbstractFunctionDeclaration* abstractFunDecl = dynamic_cast<const AbstractFunctionDeclaration*>(functionDecl);
foreach(Declaration * parameter, functionCtxt->localDeclarations()) {
signature.defaultParams << (includeDefaults ? abstractFunDecl->defaultParameterForArgument(pos).str() : "");
signature.defaultParams << (includeDefaults ? abstractFunDecl->defaultParameterForArgument(pos).str() : QString());
signature.parameters << qMakePair(parameter->indexedType(), parameter->identifier().identifier().str());
++pos;
}
......
......@@ -126,7 +126,8 @@ KTextEditor::Cursor findSignatureEnd(KTextEditor::Document *targetDoc, CXCursor
int endLine = search.line(), endColumn = search.column();
int rangeEnd = range.end().line();
QChar endChar(')'), searchChar;
QChar endChar = QLatin1Char(')');
QChar searchChar;
do {
searchChar = targetDoc->characterAt(KTextEditor::Cursor(endLine, endColumn));
......@@ -142,8 +143,8 @@ KTextEditor::Cursor findSignatureEnd(KTextEditor::Document *targetDoc, CXCursor
return KTextEditor::Cursor::invalid();
}
if (endChar == QChar(')') && ClangUtils::isConstMethod(cursor)) {
endChar = QChar('t');
if (endChar == QLatin1Char(')') && ClangUtils::isConstMethod(cursor)) {
endChar = QLatin1Char('t');
}
} while (searchChar != endChar);
......@@ -152,8 +153,8 @@ KTextEditor::Cursor findSignatureEnd(KTextEditor::Document *targetDoc, CXCursor
QUrl findCompanionFile(const QUrl &fileUrl, const KTextEditor::Cursor& sc, const CXFile& file, CXCursor& otherSide)
{
static QStringList headerMime({"text/x-c++hdr", "text/x-chdr"});
static QStringList srcMime({"text/x-c++src", "text/x-csrc"});
static QStringList headerMime({QStringLiteral("text/x-c++hdr"), QStringLiteral("text/x-chdr")});
static QStringList srcMime({QStringLiteral("text/x-c++src"), QStringLiteral("text/x-csrc")});
QMimeDatabase db;
QString me = db.mimeTypeForUrl(fileUrl).name();
......
This diff is collapsed.
......@@ -30,12 +30,15 @@ KDevelop::AbstractType::Ptr typeForShortenedString(KDevelop::Declaration* decl);
///@param desiredLength the desired length. No guarantee that the resulting string will be this short. With the default-value, no shortening will happen in most cases.
///@param ctx visibility context to consider. All prefixes of types are shortened to the minimum length while staying visible from here
///@param stripPrefix this prefix will be stripped from qualified identifiers. This is useful to remove parts of the current context.
QString shortenedTypeString(KDevelop::Declaration* decl, KDevelop::DUContext* ctx, int desiredLength = 10000, KDevelop::QualifiedIdentifier stripPrefix = KDevelop::QualifiedIdentifier());
QString shortenedTypeString(KDevelop::AbstractType::Ptr type, KDevelop::DUContext* ctx, int desiredLength = 10000, KDevelop::QualifiedIdentifier stripPrefix = KDevelop::QualifiedIdentifier());
KDevelop::IndexedTypeIdentifier shortenedTypeIdentifier(KDevelop::AbstractType::Ptr type, KDevelop::DUContext* ctx, int desiredLength = 10000, KDevelop::QualifiedIdentifier stripPrefix = KDevelop::QualifiedIdentifier());
QString shortenedTypeString(KDevelop::Declaration* decl, KDevelop::DUContext* ctx, int desiredLength = 10000,
const KDevelop::QualifiedIdentifier& stripPrefix = {});
QString shortenedTypeString(const KDevelop::AbstractType::Ptr& type, KDevelop::DUContext* ctx, int desiredLength = 10000,
const KDevelop::QualifiedIdentifier& stripPrefix = {});
KDevelop::IndexedTypeIdentifier shortenedTypeIdentifier(const KDevelop::AbstractType::Ptr& type, KDevelop::DUContext* ctx, int desiredLength = 10000,
const KDevelop::QualifiedIdentifier& stripPrefix = {});
///Returns a simplified string version of the given type: Template default-parameters are stripped away, qualified identifiers are simplified so they are as short as possible, while staying visible from the given context.
QString simplifiedTypeString(KDevelop::AbstractType::Ptr type, KDevelop::DUContext* visibilityFrom);
QString simplifiedTypeString(const KDevelop::AbstractType::Ptr& type, KDevelop::DUContext* visibilityFrom);
};
#endif // CODEGENHELPER_H
......@@ -50,7 +50,7 @@ void SimpleRefactoring::fillContextMenu(ContextMenuExtension& extension, Context
if (fileInfo.isWritable()) {
QAction* action = new QAction(i18n("Rename %1", declaration->qualifiedIdentifier().toString()), this);
action->setData(QVariant::fromValue(IndexedDeclaration(declaration)));
action->setIcon(QIcon::fromTheme("edit-rename"));
action->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename")));
connect(action, &QAction::triggered,
this, &SimpleRefactoring::executeRenameAction);
......
......@@ -91,7 +91,7 @@ CXCursor referencedCursor(CXCursor cursor)
Identifier makeId(CXCursor cursor)
{
return Identifier(IndexedString(ClangString(clang_getCursorSpelling(cursor))));
return Identifier(ClangString(clang_getCursorSpelling(cursor)).toIndexed());
}
QByteArray makeComment(CXComment comment)
......@@ -99,7 +99,7 @@ QByteArray makeComment(CXComment comment)
if (Q_UNLIKELY(s_jsonTestRun)) {
auto kind = clang_Comment_getKind(comment);
if (kind == CXComment_Text)
return {ClangString(clang_TextComment_getText(comment))};
return ClangString(clang_TextComment_getText(comment)).toByteArray();
QByteArray text;
int numChildren = clang_Comment_getNumChildren(comment);
......@@ -108,7 +108,7 @@ QByteArray makeComment(CXComment comment)
return text;
}
return {ClangString(clang_FullComment_getAsHTML(comment))};
return ClangString(clang_FullComment_getAsHTML(comment)).toByteArray();
}
AbstractType* createDelayedType(CXType type)
......@@ -463,7 +463,7 @@ struct Visitor
if (clang_isFunctionTypeVariadic(type)) {
auto type = new DelayedType;
static const auto id = IndexedTypeIdentifier("...");
static const auto id = IndexedTypeIdentifier(QStringLiteral("..."));
type->setIdentifier(id);
type->setKind(DelayedType::Unresolved);
func->addArgument(AbstractType::Ptr(type));
......@@ -510,7 +510,7 @@ struct Visitor
AbstractType *createType(CXType, CXCursor /*parent*/)
{
auto t = new DelayedType;
static const IndexedTypeIdentifier id(CursorKindTraits::delayedTypeName(TK));
static const IndexedTypeIdentifier id(QLatin1String(CursorKindTraits::delayedTypeName(TK)));
t->setIdentifier(id);
return t;
}
......@@ -572,7 +572,7 @@ struct Visitor
AbstractType *createType(CXCursor)
{
auto t = new DelayedType;
static const IndexedTypeIdentifier id("Label");
static const IndexedTypeIdentifier id(QStringLiteral("Label"));
t->setIdentifier(id);
return t;
}
......@@ -809,9 +809,9 @@ void Visitor::setDeclData(CXCursor cursor, MacroDefinition* decl) const
// And no way to get the actual definition text range
// Should be quite easy to expose that in libclang, though
// Let' still get some basic support for this and parse on our own, it's not that difficult
const QByteArray contents = ClangUtils::getRawContents(unit, range);
const int firstOpeningParen = contents.indexOf('(');
const int firstWhitespace = contents.indexOf(' ');
const QString contents = QString::fromUtf8(ClangUtils::getRawContents(unit, range));
const int firstOpeningParen = contents.indexOf(QLatin1Char('('));
const int firstWhitespace = contents.indexOf(QLatin1Char(' '));
const bool isFunctionLike = (firstOpeningParen != -1) && (firstOpeningParen < firstWhitespace);
decl->setFunctionLike(isFunctionLike);
......@@ -823,8 +823,8 @@ void Visitor::setDeclData(CXCursor cursor, MacroDefinition* decl) const
start = closingParen + 2; // + ')' + ' '
// extract macro function parameters
const QString parameters = QString::fromUtf8(contents.mid(firstOpeningParen, closingParen - firstOpeningParen + 1));
ParamIterator paramIt("():", parameters, 0);
const QString parameters = contents.mid(firstOpeningParen, closingParen - firstOpeningParen + 1);
ParamIterator paramIt(QStringLiteral("():"), parameters, 0);
while (paramIt) {
decl->addParameter(IndexedString(*paramIt));
++paramIt;
......@@ -835,9 +835,9 @@ void Visitor::setDeclData(CXCursor cursor, MacroDefinition* decl) const
}
if (start == -1) {
// unlikely: invalid macro definition, insert the complete #define statement
decl->setDefinition(IndexedString("#define " + contents));
decl->setDefinition(IndexedString(QLatin1String("#define ") + contents));
} else if (start < contents.size()) {
decl->setDefinition(IndexedString(contents.constData() + start));
decl->setDefinition(IndexedString(contents.mid(start)));
} // else: macro has no body => leave the definition text empty
}
......@@ -1021,7 +1021,7 @@ CXChildVisitResult Visitor::buildCXXBaseSpecifier(CXCursor cursor)
auto decl = findDeclaration(classDeclCursor);
if (!decl) {
// this happens for templates with template-dependent base classes e.g. - dunno whether we can/should do more here
clangDebug() << "failed to find declaration for base specifier:" << ClangString(clang_getCursorDisplayName(cursor));