Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for expansion of class templates.
Up to now class templates ended up with just the class tag and name. This change expands the whole class, including methods and variables. There are some cases where a method has no body in the expanded version. In that case this method is unused in the instatiated version. This changes also brings support for more statements/expressions. Like the placement delete or inline variable initialization. A further simplification is the attempt to introduce a function which is responsible to adding parens or curlys.
- Loading branch information
Andreas Fertig
authored and
Andreas Fertig
committed
Jun 16, 2018
1 parent
6de3d9c
commit 86d8bd9
Showing
73 changed files
with
1,388 additions
and
256 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef INSIGHTS_NUMBER_ITERATOR_H | ||
#define INSIGHTS_NUMBER_ITERATOR_H | ||
|
||
template<typename T> | ||
class NumberIterator | ||
{ | ||
public: | ||
NumberIterator(const T num) | ||
: mNum{num} | ||
, mCount{0} | ||
{ | ||
} | ||
|
||
const T& operator*() const { return mCount; } | ||
|
||
NumberIterator& operator++() | ||
{ | ||
++mCount; | ||
|
||
return *this; | ||
} | ||
|
||
bool operator!=(const NumberIterator&) const { return mCount < mNum; } | ||
|
||
const NumberIterator& begin() const { return *this; } | ||
const NumberIterator& end() const { return *this; } | ||
|
||
private: | ||
const T mNum; | ||
T mCount; | ||
}; | ||
//----------------------------------------------------------------------------- | ||
|
||
#endif /* INSIGHTS_NUMBER_ITERATOR_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
int foo(int a,int b){ return a+b; } | ||
|
||
int main(){ | ||
if(true) { | ||
int (*add)(int,int)= foo; | ||
// auto within a function pointer | ||
auto add1= foo; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
int foo(int a,int b){ return a+b; } | ||
|
||
int main(){ | ||
if(true) { | ||
using FuncPtr_5 = int (*)(int, int); | ||
FuncPtr_5 add = foo; | ||
using FuncPtr_7 = int (*)(int, int); | ||
FuncPtr_7 add1 = foo; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
template<typename T, bool array> | ||
class Alloc | ||
{ | ||
const int z; | ||
T* data{nullptr}; | ||
const bool x{false}; | ||
|
||
public: | ||
Alloc() : z{2} | ||
{ | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
Alloc<int, false> a; | ||
Alloc<char, true> b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
template<typename T, bool array> | ||
class Alloc | ||
{ | ||
const int z; | ||
T* data{nullptr}; | ||
const bool x{false}; | ||
|
||
public: | ||
Alloc() : z{2} | ||
{ | ||
} | ||
}; | ||
/* First instantiated from: CXXDefaultInitExprTest.cpp:16 */ | ||
#ifdef INSIGHTS_USE_TEMPLATE | ||
class Alloc<int, 0> | ||
{ | ||
const int z; | ||
int * data; | ||
const bool x; | ||
|
||
public: | ||
inline Alloc() | ||
: z{2} | ||
, data{nullptr} | ||
, x{false} | ||
{ | ||
} | ||
|
||
inline constexpr Alloc(const Alloc<int, 0> &) = default; | ||
inline constexpr Alloc(Alloc<int, 0> &&) = default; | ||
|
||
}; | ||
|
||
#endif | ||
|
||
/* First instantiated from: CXXDefaultInitExprTest.cpp:17 */ | ||
#ifdef INSIGHTS_USE_TEMPLATE | ||
class Alloc<char, 1> | ||
{ | ||
const int z; | ||
char * data; | ||
const bool x; | ||
|
||
public: | ||
inline Alloc() | ||
: z{2} | ||
, data{nullptr} | ||
, x{false} | ||
{ | ||
} | ||
|
||
inline constexpr Alloc(const Alloc<char, 1> &) = default; | ||
inline constexpr Alloc(Alloc<char, 1> &&) = default; | ||
|
||
}; | ||
|
||
#endif | ||
|
||
|
||
int main() | ||
{ | ||
Alloc<int, false> a; | ||
Alloc<char, true> b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
template<typename T, bool array> | ||
class Alloc | ||
{ | ||
T* data; | ||
|
||
public: | ||
Alloc() { | ||
if( array ) { | ||
data = new T[10]; | ||
data = new T[10]{1,2,3}; | ||
} else { | ||
data = new T; | ||
data = new T(2); | ||
data = new T{2}; | ||
} | ||
} | ||
|
||
~Alloc() { | ||
if( array ) { | ||
delete[] data; | ||
} else { | ||
delete data; | ||
} | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
Alloc<int, false> a; | ||
Alloc<char, true> b; | ||
} |
Oops, something went wrong.