53
53
54
54
#include < algorithm>
55
55
#include < cassert>
56
+ #include < cstddef>
56
57
#include < deque>
57
58
#include < iterator>
58
59
#include < map>
@@ -1902,42 +1903,51 @@ void collect_type_info(const FunctionDecl* FD, QualType& QT,
1902
1903
1903
1904
void make_narg_ctor (const FunctionDecl* FD, const unsigned N,
1904
1905
std::ostringstream& typedefbuf, std::ostringstream& callbuf,
1905
- const std::string& class_name, int indent_level) {
1906
+ const std::string& class_name, int indent_level,
1907
+ bool array = false ) {
1906
1908
// Make a code string that follows this pattern:
1907
1909
//
1908
1910
// ClassName(args...)
1911
+ // OR
1912
+ // ClassName[nary] // array of objects
1909
1913
//
1910
1914
1911
- callbuf << class_name << " (" ;
1912
- for (unsigned i = 0U ; i < N; ++i) {
1913
- const ParmVarDecl* PVD = FD->getParamDecl (i);
1914
- QualType Ty = PVD->getType ();
1915
- QualType QT = Ty.getCanonicalType ();
1916
- std::string type_name;
1917
- EReferenceType refType = kNotReference ;
1918
- bool isPointer = false ;
1919
- collect_type_info (FD, QT, typedefbuf, callbuf, type_name, refType,
1920
- isPointer, indent_level, true );
1921
- if (i) {
1922
- callbuf << ' ,' ;
1923
- if (i % 2 ) {
1924
- callbuf << ' ' ;
1915
+ if (array)
1916
+ callbuf << class_name << " [nary]" ;
1917
+ else
1918
+ callbuf << class_name;
1919
+ if (N) {
1920
+ callbuf << " (" ;
1921
+ for (unsigned i = 0U ; i < N; ++i) {
1922
+ const ParmVarDecl* PVD = FD->getParamDecl (i);
1923
+ QualType Ty = PVD->getType ();
1924
+ QualType QT = Ty.getCanonicalType ();
1925
+ std::string type_name;
1926
+ EReferenceType refType = kNotReference ;
1927
+ bool isPointer = false ;
1928
+ collect_type_info (FD, QT, typedefbuf, callbuf, type_name, refType,
1929
+ isPointer, indent_level, true );
1930
+ if (i) {
1931
+ callbuf << ' ,' ;
1932
+ if (i % 2 ) {
1933
+ callbuf << ' ' ;
1934
+ } else {
1935
+ callbuf << " \n " ;
1936
+ indent (callbuf, indent_level);
1937
+ }
1938
+ }
1939
+ if (refType != kNotReference ) {
1940
+ callbuf << " (" << type_name.c_str ()
1941
+ << (refType == kLValueReference ? " &" : " &&" ) << " )*("
1942
+ << type_name.c_str () << " *)args[" << i << " ]" ;
1943
+ } else if (isPointer) {
1944
+ callbuf << " *(" << type_name.c_str () << " **)args[" << i << " ]" ;
1925
1945
} else {
1926
- callbuf << " \n " ;
1927
- indent (callbuf, indent_level + 1 );
1946
+ callbuf << " *(" << type_name.c_str () << " *)args[" << i << " ]" ;
1928
1947
}
1929
1948
}
1930
- if (refType != kNotReference ) {
1931
- callbuf << " (" << type_name.c_str ()
1932
- << (refType == kLValueReference ? " &" : " &&" ) << " )*("
1933
- << type_name.c_str () << " *)args[" << i << " ]" ;
1934
- } else if (isPointer) {
1935
- callbuf << " *(" << type_name.c_str () << " **)args[" << i << " ]" ;
1936
- } else {
1937
- callbuf << " *(" << type_name.c_str () << " *)args[" << i << " ]" ;
1938
- }
1949
+ callbuf << " )" ;
1939
1950
}
1940
- callbuf << " )" ;
1941
1951
}
1942
1952
1943
1953
const DeclContext* get_non_transparent_decl_context (const FunctionDecl* FD) {
@@ -2095,18 +2105,59 @@ void make_narg_ctor_with_return(const FunctionDecl* FD, const unsigned N,
2095
2105
std::ostringstream& buf, int indent_level) {
2096
2106
// Make a code string that follows this pattern:
2097
2107
//
2098
- // (*(ClassName**)ret) = (obj) ?
2099
- // new (*(ClassName**)ret) ClassName(args...) : new ClassName(args...);
2100
- //
2108
+ // Array new if nary has been passed, and nargs is 0 (must be default ctor)
2109
+ // if (nary) {
2110
+ // (*(ClassName**)ret) = (obj) ? new (*(ClassName**)ret) ClassName[nary] :
2111
+ // new ClassName[nary];
2112
+ // }
2113
+ // else {
2114
+ // (*(ClassName**)ret) = (obj) ? new (*(ClassName**)ret) ClassName(args...)
2115
+ // : new ClassName(args...);
2116
+ // }
2101
2117
{
2102
2118
std::ostringstream typedefbuf;
2103
2119
std::ostringstream callbuf;
2104
2120
//
2105
2121
// Write the return value assignment part.
2106
2122
//
2107
2123
indent (callbuf, indent_level);
2124
+ const auto * CD = dyn_cast<CXXConstructorDecl>(FD);
2125
+
2126
+ // Activate this block only if array new is possible
2127
+ // if (nary) {
2128
+ // (*(ClassName**)ret) = (obj) ? new (*(ClassName**)ret) ClassName[nary]
2129
+ // : new ClassName[nary];
2130
+ // }
2131
+ // else {
2132
+ if (CD->getNumParams () == 0 ) {
2133
+ callbuf << " if (nary > 1) {\n " ;
2134
+ indent (callbuf, indent_level);
2135
+ callbuf << " (*(" << class_name << " **)ret) = " ;
2136
+ callbuf << " (is_arena) ? new (*(" << class_name << " **)ret) " ;
2137
+ make_narg_ctor (FD, N, typedefbuf, callbuf, class_name, indent_level,
2138
+ true );
2139
+
2140
+ callbuf << " : new " ;
2141
+ //
2142
+ // Write the actual expression.
2143
+ //
2144
+ make_narg_ctor (FD, N, typedefbuf, callbuf, class_name, indent_level,
2145
+ true );
2146
+ //
2147
+ // End the new expression statement.
2148
+ //
2149
+ callbuf << " ;\n " ;
2150
+ indent (callbuf, indent_level);
2151
+ callbuf << " }\n " ;
2152
+ callbuf << " else {\n " ;
2153
+ }
2154
+
2155
+ // Standard branch:
2156
+ // (*(ClassName**)ret) = (obj) ? new (*(ClassName**)ret) ClassName(args...)
2157
+ // : new ClassName(args...);
2158
+ indent (callbuf, indent_level);
2108
2159
callbuf << " (*(" << class_name << " **)ret) = " ;
2109
- callbuf << " (obj ) ? new (*(" << class_name << " **)ret) " ;
2160
+ callbuf << " (is_arena ) ? new (*(" << class_name << " **)ret) " ;
2110
2161
make_narg_ctor (FD, N, typedefbuf, callbuf, class_name, indent_level);
2111
2162
2112
2163
callbuf << " : new " ;
@@ -2118,6 +2169,10 @@ void make_narg_ctor_with_return(const FunctionDecl* FD, const unsigned N,
2118
2169
// End the new expression statement.
2119
2170
//
2120
2171
callbuf << " ;\n " ;
2172
+ indent (callbuf, --indent_level);
2173
+ if (CD->getNumParams () == 0 )
2174
+ callbuf << " }\n " ;
2175
+
2121
2176
//
2122
2177
// Output the whole new expression and return statement.
2123
2178
//
@@ -2630,8 +2685,14 @@ int get_wrapper_code(compat::Interpreter& I, const FunctionDecl* FD,
2630
2685
" __attribute__((annotate(\" __cling__ptrcheck(off)\" )))\n "
2631
2686
" extern \" C\" void " ;
2632
2687
buf << wrapper_name;
2633
- buf << " (void* obj, int nargs, void** args, void* ret)\n "
2634
- " {\n " ;
2688
+ if (Cpp::IsConstructor (FD)) {
2689
+ buf << " (void* ret, unsigned long nary, unsigned long nargs, void** args, "
2690
+ " void* is_arena)\n "
2691
+ " {\n " ;
2692
+ } else
2693
+ buf << " (void* obj, unsigned long nargs, void** args, void* ret)\n "
2694
+ " {\n " ;
2695
+
2635
2696
++indent_level;
2636
2697
if (min_args == num_params) {
2637
2698
// No parameters with defaults.
0 commit comments