diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 0cc42b5cf96f6d9f8f527c5e7a5df2a55e477256..1319623c653120031c9b57e9e688dc3fd9fbac93 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -234,11 +234,25 @@ static bool isTypedefType(QualType QT) { return false; } +static bool isFuncType(QualType QT) { + if (QT.getTypePtr()->isFunctionType()) { + return true; + } + if (const auto *PT = dyn_cast(QT)) { + return isFuncType(PT->getPointeeType()); + } + if (const auto *AT = dyn_cast(QT)) { + return isFuncType(AT->getElementType()); + } + return false; +} + static SplitQualType splitAccordingToPolicy(QualType QT, const PrintingPolicy &Policy) { #if ENABLE_BSC - // for original or pointee or array typedef type in BSCMethodDecl, we just print the original TypedefType name - if (Policy.RewriteBSC && isTypedefType(QT)) { + // for original or pointee or array typedef type or function proto type in BSCMethodDecl, + // we just print the original TypedefType name + if (Policy.RewriteBSC && (isFuncType(QT) || isTypedefType(QT))) { return QT.split(); } #endif diff --git a/clang/test/BSC/Positive/Driver/rewrite-bsc/rewrite_bsc_funcpointer_const/rewrite_bsc_funcpointer_const.cbs b/clang/test/BSC/Positive/Driver/rewrite-bsc/rewrite_bsc_funcpointer_const/rewrite_bsc_funcpointer_const.cbs new file mode 100644 index 0000000000000000000000000000000000000000..1f462015675a769ec16b62f089e5e14cb246c754 --- /dev/null +++ b/clang/test/BSC/Positive/Driver/rewrite-bsc/rewrite_bsc_funcpointer_const/rewrite_bsc_funcpointer_const.cbs @@ -0,0 +1,46 @@ +// RUN: %clang -rewrite-bsc %s -o %t-rw.c +// RUN: FileCheck --input-file=%t-rw.c %s +// RUN: %clang %t-rw.c -o %t-rw.output +// RUN: %t-rw.output + +//test1 +const int( * const q)(int const a,const float b,const int c , const int d); + +//test2 +const int( * const p)(const int* owned const a,const float b,const int c , const int d); + +//test3 +int add(int a, int b) { return a + b; } +int sub(int a, int b) { return a - b; } +int mul(int a, int b) { return a * b; } +int (*ops[])(int const a, int const b) = { add, sub, mul }; + +//test4 +typedef int myint; +typedef Myfloat = float; +const myint( * const qs)(myint const a,const Myfloat b,const myint c , const myint d); + +int main(){ + return 0; +} +// CHECK: typedef int myint; +// CHECK-EMPTY: +// CHECK-NEXT:typedef float Myfloat; +// CHECK-EMPTY: +// CHECK-NEXT:const int (*const q)(const int, const float, const int, const int); +// CHECK-EMPTY: +// CHECK-NEXT:const int (*const p)(const int *const, const float, const int, const int); +// CHECK-EMPTY: +// CHECK-NEXT:int add(int a, int b) { return a + b; } +// CHECK-EMPTY: +// CHECK-NEXT:int sub(int a, int b) { return a - b; } +// CHECK-EMPTY: +// CHECK-NEXT:int mul(int a, int b) { return a * b; } +// CHECK-EMPTY: +// CHECK-NEXT:int (*ops[])(const int, const int) = {add, sub, mul}; +// CHECK-EMPTY: +// CHECK-NEXT:const myint (*const qs)(const myint, const Myfloat, const myint, const myint); +// CHECK-EMPTY: +// CHECK-NEXT:int main(){ +// CHECK-NEXT: return 0; +// CHECK-NEXT: } \ No newline at end of file diff --git a/clang/test/BSC/Positive/Trait/r3/trait_qualifiers_this_param/trait_qualifiers_this_param.cbs b/clang/test/BSC/Positive/Trait/r3/trait_qualifiers_this_param/trait_qualifiers_this_param.cbs index fce69a4f204f3020089789db22f89b7681cf04cc..2ba119439caad89393389f69582cb15ad765dddf 100644 --- a/clang/test/BSC/Positive/Trait/r3/trait_qualifiers_this_param/trait_qualifiers_this_param.cbs +++ b/clang/test/BSC/Positive/Trait/r3/trait_qualifiers_this_param/trait_qualifiers_this_param.cbs @@ -62,10 +62,10 @@ int main(){ // CHECK-NEXT: int (*foo)(const void *); // CHECK-NEXT: int (*goo)( void *); // CHECK-NEXT: int (*hoo)(const void *); -// CHECK-NEXT: int (*ioo)(void *); -// CHECK-NEXT: int (*joo)(const void *); +// CHECK-NEXT: int (*ioo)(void *const); +// CHECK-NEXT: int (*joo)(const void *const); // CHECK-NEXT: int (*koo)( void *); -// CHECK-NEXT: int (*loo)( void *); +// CHECK-NEXT: int (*loo)( void *const); // CHECK-NEXT: int (*moo)(const void *); // CHECK-NEXT: }; @@ -109,7 +109,7 @@ int main(){ // CHECK-NEXT: return 1; // CHECK-NEXT: } -// CHECK: struct __Trait_F_Vtable __int_trait_F = {.foo = (int (*)(const void *))int_foo, .goo = (int (*)( void *))int_goo, .hoo = (int (*)(const void *))int_hoo, .ioo = (int (*)(void *))int_ioo, .joo = (int (*)(const void *))int_joo, .koo = (int (*)( void *))int_koo, .loo = (int (*)( void *))int_loo, .moo = (int (*)(const void *))int_moo}; +// CHECK: struct __Trait_F_Vtable __int_trait_F = {.foo = (int (*)(const void *))int_foo, .goo = (int (*)( void *))int_goo, .hoo = (int (*)(const void *))int_hoo, .ioo = (int (*)(void *const))int_ioo, .joo = (int (*)(const void *const))int_joo, .koo = (int (*)( void *))int_koo, .loo = (int (*)( void *const))int_loo, .moo = (int (*)(const void *))int_moo}; // CHECK: int main(){ // CHECK-NEXT: return 0;