In detailed_name, remove space between * and name

This commit is contained in:
Fangrui Song 2017-12-30 13:11:55 -08:00
parent 947a80ecc8
commit 95126bff61
3 changed files with 18 additions and 14 deletions

View File

@ -1193,8 +1193,10 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
ns->QualifiedName(decl->semanticContainer, var->def.short_name);
if (decl->entityInfo->kind == CXIdxEntity_EnumConstant)
var->def.detailed_name = std::move(qualified_name);
else
var->def.detailed_name = type_name + " " + std::move(qualified_name);
else {
var->def.detailed_name = std::move(type_name);
ConcatTypeAndName(var->def.detailed_name, qualified_name);
}
}
bool is_system = clang_Location_isInSystemHeader(
@ -1603,10 +1605,10 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
// of OnIndexDeclaration. But there `decl` is of type CXIdxDeclInfo
// and has more information, thus not easy to reuse the code.
var->def.short_name = referenced.get_spelling();
std::string type_name = ToString(
var->def.detailed_name = ToString(
clang_getTypeSpelling(clang_getCursorType(referenced.cx_cursor)));
var->def.detailed_name = type_name + " " + var->def.short_name;
var->def.cls = VarClass::Member;
ConcatTypeAndName(var->def.detailed_name, var->def.short_name);
var->def.cls = VarClass::Local;
ClangCursor decl_cursor = referenced;
var->def.comments = decl_cursor.get_comments();
UniqueAdd(var->uses, ResolveSpelling(referenced.cx_cursor));
@ -1930,6 +1932,13 @@ std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
return result;
}
void ConcatTypeAndName(std::string& type, const std::string& name) {
if (type.size() &&
(type.back() != ' ' && type.back() != '*' && type.back() != '&'))
type.push_back(' ');
type.append(name);
}
void IndexInit() {
clang_enableStackTraces();
clang_toggleCrashRecovery(1);

View File

@ -578,6 +578,8 @@ std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
const std::vector<std::string>& args,
const std::vector<CXUnsavedFile>& file_contents);
void ConcatTypeAndName(std::string& type, const std::string& name);
void IndexInit();
void ClangSanityCheck();

View File

@ -4,13 +4,6 @@
namespace {
void AddName(std::string& before, const std::string& name) {
if (before.size() &&
(before.back() != ' ' && before.back() != '*' && before.back() != '&'))
before.push_back(' ');
before.append(name);
}
int GetNameInsertingPosition(const std::string& type_desc,
const std::string& return_type) {
// Check if type_desc contains an (.
@ -99,7 +92,7 @@ std::string GetFunctionSignature(IndexFile* db,
type_desc_with_names.insert(type_desc_with_names.end(), &type_desc[i],
&type_desc[arg.first]);
i = arg.first;
AddName(type_desc_with_names, arg.second);
ConcatTypeAndName(type_desc_with_names, arg.second);
}
type_desc_with_names.insert(type_desc_with_names.end(),
type_desc.begin() + i, type_desc.end());
@ -107,7 +100,7 @@ std::string GetFunctionSignature(IndexFile* db,
} else {
// type_desc is either a typedef, or some complicated type we cannot handle.
// Append the function_name in this case.
AddName(type_desc, function_name);
ConcatTypeAndName(type_desc, function_name);
}
return type_desc;