Last active
December 27, 2017 16:09
-
-
Save romix/13db5f4c85b1b20d5ec8546c3a057dc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Build a function signature. | |
static std::string get_function_signature(IndexFile* db, | |
const CXIdxDeclInfo* decl) { | |
// Build the function name, with scope and parameters | |
std::string returnType; | |
if (decl->entityInfo->kind != CXCursor_Constructor && | |
decl->entityInfo->kind != CXCursor_Destructor) { | |
returnType = ::ToString( | |
clang_getTypeSpelling(clang_getCursorResultType(decl->cursor))); | |
} | |
std::string signature{returnType}; | |
signature.append(" "); | |
auto container = decl->semanticContainer; | |
if (IsTypeDefinition(container)) { | |
IndexTypeId declaring_type_id = db->ToTypeId(container->cursor); | |
IndexType* declaring_type_def = db->Resolve(declaring_type_id); | |
auto container_name = declaring_type_def->def.detailed_name; | |
signature.append(container_name); | |
signature.append("::"); | |
} | |
auto functionName = ::ToString(clang_getCursorSpelling(decl->cursor)); | |
auto pos = functionName.find("<", 0); | |
if (pos != std::string::npos) { | |
functionName = functionName.substr(0, pos); | |
} | |
signature.append(functionName); | |
std::string parameter_types = ""; | |
// Add the parameters declarations including their names. | |
parameter_types.append("("); | |
int numArgs = clang_Cursor_getNumArguments(decl->cursor); | |
for (int i = 0; i < numArgs; i++) { | |
CXCursor arg = clang_Cursor_getArgument(decl->cursor, i); | |
auto id = ::ToString(clang_getCursorDisplayName(arg)); | |
auto type = ::ToString(clang_getTypeSpelling(clang_getCursorType(arg))); | |
parameter_types.append(type + ' ' + id + (i < numArgs - 1 ? ", " : "")); | |
} | |
if (clang_Cursor_isVariadic(decl->cursor)) { | |
parameter_types.append(numArgs > 0 ? ", ..." : "..."); | |
} | |
parameter_types.append(")"); | |
signature.append(parameter_types); | |
return signature; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment