Ejemplo n.º 1
0
	CXChildVisitResult FunctionDefinition::executeParse (CXCursor cursor, ParserContext *context) {
		auto returnType = clang_getCursorResultType(cursor);
		auto returnTypeValue = CXStringToString(clang_getTypeSpelling(clang_getCursorResultType(cursor)));
		this->returnType = new Type(context, returnType, returnTypeValue);
		this->variadic = clang_isFunctionTypeVariadic(clang_getCursorType(cursor));
		addBlockIfFound(context, this, this->getFramework(), this->returnType, "");
		context->getParserTree()->addFunction(this);
		clang_visitChildren(cursor, parseFunctionMember, this);
		return CXChildVisit_Continue;
	}
Ejemplo n.º 2
0
cursor::type cursor::getResultType()
{
    return { clang_getCursorResultType(cur) };
}
Ejemplo n.º 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;
}