mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
clang_generator: Collect function types directly
Do not try to peel off all layers of pointers/references when collecting types, recursion works well here. Also collect the function type itself, even if it is a pointer or if the function was the underlying type of a typedef. PiperOrigin-RevId: 490475937 Change-Id: I13cb3d9d3de7d25b9e627f43112c46758c7e6a22
This commit is contained in:
parent
3155cb0a67
commit
13c5b564b6
@ -105,6 +105,25 @@ TEST_F(EmitterTest, RelatedTypes) {
|
|||||||
"typedef struct { int member; } MyStruct"));
|
"typedef struct { int member; } MyStruct"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(EmitterTest, CollectFunctionPointer) {
|
||||||
|
EmitterForTesting emitter;
|
||||||
|
EXPECT_THAT(
|
||||||
|
RunFrontendAction(
|
||||||
|
R"(typedef void (callback_t)(void*);
|
||||||
|
struct HandlerData {
|
||||||
|
int member;
|
||||||
|
callback_t* cb;
|
||||||
|
};
|
||||||
|
extern "C" int Structize(HandlerData*);)",
|
||||||
|
std::make_unique<GeneratorAction>(emitter, GeneratorOptions())),
|
||||||
|
IsOk());
|
||||||
|
EXPECT_THAT(emitter.GetRenderedFunctions(), SizeIs(1));
|
||||||
|
|
||||||
|
EXPECT_THAT(
|
||||||
|
UglifyAll(emitter.SpellingsForNS("")),
|
||||||
|
ElementsAre("struct HandlerData { int member; callback_t *cb; }"));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(EmitterTest, TypedefNames) {
|
TEST_F(EmitterTest, TypedefNames) {
|
||||||
EmitterForTesting emitter;
|
EmitterForTesting emitter;
|
||||||
ASSERT_THAT(
|
ASSERT_THAT(
|
||||||
|
@ -61,22 +61,19 @@ void TypeCollector::CollectRelatedTypes(clang::QualType qual) {
|
|||||||
qual->isMemberFunctionPointerType()) {
|
qual->isMemberFunctionPointerType()) {
|
||||||
if (const auto* function_type = qual->getPointeeOrArrayElementType()
|
if (const auto* function_type = qual->getPointeeOrArrayElementType()
|
||||||
->getAs<clang::FunctionProtoType>()) {
|
->getAs<clang::FunctionProtoType>()) {
|
||||||
// Note: Do not add the function type itself, as this will always be a
|
// Collect the return type, the parameter types as well as the function
|
||||||
// pointer argument. We only need to collect all its related types.
|
// pointer type itself.
|
||||||
CollectRelatedTypes(function_type->getReturnType());
|
CollectRelatedTypes(function_type->getReturnType());
|
||||||
for (const clang::QualType& param : function_type->getParamTypes()) {
|
for (const clang::QualType& param : function_type->getParamTypes()) {
|
||||||
CollectRelatedTypes(param);
|
CollectRelatedTypes(param);
|
||||||
}
|
}
|
||||||
|
collected_.insert(qual);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsPointerOrReference(qual)) {
|
if (IsPointerOrReference(qual)) {
|
||||||
clang::QualType pointee = qual;
|
CollectRelatedTypes(qual->getPointeeType());
|
||||||
do {
|
|
||||||
pointee = pointee->getPointeeType();
|
|
||||||
} while (IsPointerOrReference(pointee));
|
|
||||||
CollectRelatedTypes(pointee);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user