Exemple #1
0
Cursor::Arguments Cursor::get_arguments() const
{
	auto generator = [this](unsigned int index) {
		CXCursor cx_cursor(clang_Cursor_getArgument(this->m_cx_cursor, index));
		if ( is_null(cx_cursor) ) {
			CLANGXX_THROW_LogicError("Error retrieving the argument cursor of a function or method.");
		}

		return Cursor(std::move(cx_cursor), this->m_translation_unit);
	};

	int num_args{clang_Cursor_getNumArguments(m_cx_cursor)};
	if ( num_args < 0 ) {
		if ( is_null(m_cx_cursor) ) {
			CLANGXX_THROW_LogicError("Error retrieving the number of non-variadic arguments associated with this cursor.");
		}
		num_args = 0;
	}

	return Arguments(generator, num_args);
}
Exemple #2
0
cursor cursor::getArgument(unsigned idx)
{
    return { clang_Cursor_getArgument(cur, idx) };
}
Exemple #3
0
enum CXChildVisitResult
	visitor(
		CXCursor cursor,
		CXCursor parent,
		CXClientData client_data
	)
{
	enum CXCursorKind kind = clang_getCursorKind(cursor);
#if 0
	CXString str = clang_getCursorKindSpelling(kind);
	printf("%s\n", getCString(str));
	disposeString(str);
#endif
	if (kind != CXCursor_FunctionDecl) {
		return CXChildVisit_Recurse;
	}

	CXString str;
	CXType retType = clang_getCursorResultType(cursor);
	str = clang_getTypeSpelling(retType);
	printf("%s\n", clang_getCString(str));
	clang_disposeString(str);

	CXString funcSpelling = clang_getCursorSpelling(cursor);
	const char* funcSpellingCStr = clang_getCString(funcSpelling);
	const char* prefix = (const char*) client_data;
	size_t prefixLen = strlen(prefix);
	if (strncmp(prefix, funcSpellingCStr, prefixLen) == 0) {
		funcSpellingCStr += prefixLen;
	}
	printf("\t%s(\n", funcSpellingCStr);

	int nArgs = clang_Cursor_getNumArguments(cursor);
	argNames.resize(nArgs);
	char nameBuff[32];
	for (int i=0; i<nArgs; ++i) {
		CXCursor arg = clang_Cursor_getArgument(cursor, i);
		CXType type = clang_getCursorType(arg);
		CXString typeSpelling = clang_getTypeSpelling(type);
		CXString name = clang_getCursorDisplayName(arg);
		argNames[i] = name;
		const char* nameStr = getArgNameCString(nameBuff, name, i);
		printf("\t\t%s %s", clang_getCString(typeSpelling), nameStr);
		clang_disposeString(typeSpelling);
		if (i+1 != nArgs) {
			printf(",");
		}
		printf("\n");
	}
	printf("\t)\n");
	printf("{\n");
	printf("\t");
	if (retType.kind != CXType_Void) {
		printf("return ");
	}
	printf("%s(", funcSpelling);

	for (int i=0; i<nArgs; ++i) {
		const char* nameStr = getArgNameCString(nameBuff, argNames[i], i);
		printf("%s", nameStr);
		if (i+1 != nArgs) {
			printf(", ");
		}
		clang_disposeString(argNames[i]);
	}

	printf(");\n");
	printf("}\n");
	clang_disposeString(funcSpelling);
	return CXChildVisit_Continue;
}
Exemple #4
0
Cursor Cursor::argument(int index) const
{
    return clang_Cursor_getArgument(cxCursor, index);
}