2012-06-21 17:51:26 +08:00
|
|
|
set(LLVM_LINK_COMPONENTS
|
|
|
|
Support
|
|
|
|
)
|
|
|
|
|
2012-08-31 00:22:32 +08:00
|
|
|
set(ADTSources
|
2012-06-21 17:51:26 +08:00
|
|
|
APFloatTest.cpp
|
|
|
|
APIntTest.cpp
|
2014-03-03 04:56:28 +08:00
|
|
|
APSIntTest.cpp
|
2014-02-06 06:22:56 +08:00
|
|
|
ArrayRefTest.cpp
|
[ADT] Add LLVM_MARK_AS_BITMASK_ENUM, used to enable bitwise operations on enums without static_cast.
Summary: Normally when you do a bitwise operation on an enum value, you
get back an instance of the underlying type (e.g. int). But using this
macro, bitwise ops on your enum will return you back instances of the
enum. This is particularly useful for enums which represent a
combination of flags.
Suppose you have a function which takes an int and a set of flags. One
way to do this would be to take two numeric params:
enum SomeFlags { F1 = 1, F2 = 2, F3 = 4, ... };
void Fn(int Num, int Flags);
void foo() {
Fn(42, F2 | F3);
}
But now if you get the order of arguments wrong, you won't get an error.
You might try to fix this by changing the signature of Fn so it accepts
a SomeFlags arg:
enum SomeFlags { F1 = 1, F2 = 2, F3 = 4, ... };
void Fn(int Num, SomeFlags Flags);
void foo() {
Fn(42, static_cast<SomeFlags>(F2 | F3));
}
But now we need a static cast after doing "F2 | F3" because the result
of that computation is the enum's underlying type.
This patch adds a mechanism which gives us the safety of the second
approach with the brevity of the first.
enum SomeFlags {
F1 = 1, F2 = 2, F3 = 4, ..., F_MAX = 128,
LLVM_MARK_AS_BITMASK_ENUM(F_MAX)
};
void Fn(int Num, SomeFlags Flags);
void foo() {
Fn(42, F2 | F3); // No static_cast.
}
The LLVM_MARK_AS_BITMASK_ENUM macro enables overloads for bitwise
operators on SomeFlags. Critically, these operators return the enum
type, not its underlying type, so you don't need any static_casts.
An advantage of this solution over the previously-proposed BitMask class
[0, 1] is that we don't need any wrapper classes -- we can operate
directly on the enum itself.
The approach here is somewhat similar to OpenOffice's typed_flags_set
[2]. But we skirt the need for a wrapper class (and a good deal of
complexity) by judicious use of enable_if. We SFINAE on the presence of
a particular enumerator (added by the LLVM_MARK_AS_BITMASK_ENUM macro)
instead of using a traits class so that it's impossible to use the enum
before the overloads are present. The solution here also seamlessly
works across multiple namespaces.
[0] http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20150622/283369.html
[1] http://lists.llvm.org/pipermail/llvm-commits/attachments/20150623/073434b6/attachment.obj
[2] https://cgit.freedesktop.org/libreoffice/core/tree/include/o3tl/typed_flags_set.hxx
Reviewers: chandlerc, rsmith
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D22279
llvm-svn: 275292
2016-07-14 02:23:16 +08:00
|
|
|
BitmaskEnumTest.cpp
|
2012-06-21 17:51:26 +08:00
|
|
|
BitVectorTest.cpp
|
|
|
|
DAGDeltaAlgorithmTest.cpp
|
|
|
|
DeltaAlgorithmTest.cpp
|
|
|
|
DenseMapTest.cpp
|
|
|
|
DenseSetTest.cpp
|
|
|
|
FoldingSet.cpp
|
2014-11-12 10:06:08 +08:00
|
|
|
FunctionRefTest.cpp
|
2012-06-21 17:51:26 +08:00
|
|
|
HashingTest.cpp
|
|
|
|
ilistTest.cpp
|
2012-10-15 00:06:09 +08:00
|
|
|
ImmutableMapTest.cpp
|
2012-06-21 17:51:26 +08:00
|
|
|
ImmutableSetTest.cpp
|
|
|
|
IntEqClassesTest.cpp
|
|
|
|
IntervalMapTest.cpp
|
|
|
|
IntrusiveRefCntPtrTest.cpp
|
2014-03-09 19:20:17 +08:00
|
|
|
MakeUniqueTest.cpp
|
2013-01-26 06:29:23 +08:00
|
|
|
MapVectorTest.cpp
|
2013-02-20 08:26:04 +08:00
|
|
|
OptionalTest.cpp
|
2012-06-21 17:51:26 +08:00
|
|
|
PackedVectorTest.cpp
|
2016-01-10 17:40:13 +08:00
|
|
|
PointerEmbeddedIntTest.cpp
|
2014-03-08 03:19:56 +08:00
|
|
|
PointerIntPairTest.cpp
|
2016-01-10 16:48:23 +08:00
|
|
|
PointerSumTypeTest.cpp
|
2013-08-22 05:30:23 +08:00
|
|
|
PointerUnionTest.cpp
|
2014-11-21 03:33:33 +08:00
|
|
|
PostOrderIteratorTest.cpp
|
2016-06-30 10:32:20 +08:00
|
|
|
PriorityWorklistTest.cpp
|
2015-07-30 06:19:09 +08:00
|
|
|
RangeAdapterTest.cpp
|
2012-06-21 17:51:26 +08:00
|
|
|
SCCIteratorTest.cpp
|
2016-08-19 10:07:51 +08:00
|
|
|
STLExtrasTest.cpp
|
2016-08-11 01:52:09 +08:00
|
|
|
ScopeExitTest.cpp
|
2016-05-13 11:57:50 +08:00
|
|
|
SequenceTest.cpp
|
2016-03-26 03:28:08 +08:00
|
|
|
SetVectorTest.cpp
|
2012-06-21 17:51:26 +08:00
|
|
|
SmallPtrSetTest.cpp
|
|
|
|
SmallStringTest.cpp
|
|
|
|
SmallVectorTest.cpp
|
|
|
|
SparseBitVectorTest.cpp
|
2013-01-22 02:18:53 +08:00
|
|
|
SparseMultiSetTest.cpp
|
2012-06-21 17:51:26 +08:00
|
|
|
SparseSetTest.cpp
|
|
|
|
StringMapTest.cpp
|
|
|
|
StringRefTest.cpp
|
Bring TinyPtrVector under test. Somehow we never picked up unit tests
for this class. These tests exercise most of the basic properties, but
the API for TinyPtrVector is very strange currently. My plan is to start
fleshing out the API to match that of SmallVector, but I wanted a test
for what is there first.
Sadly, it doesn't look reasonable to just re-use the SmallVector tests,
as this container can only ever store pointers, and much of the
SmallVector testing is to get construction and destruction right.
Just to get this basic test working, I had to add value_type to the
interface.
While here I found a subtle bug in the combination of 'erase', 'begin',
and 'end'. Both 'begin' and 'end' wanted to use a null pointer to
indicate the "end" iterator of an empty vector, regardless of whether
there is actually a vector allocated or the pointer union is null.
Everything else was fine with this except for erase. If you erase the
last element of a vector after it has held more than one element, we
return the end iterator of the underlying SmallVector which need not be
a null pointer. Instead, simply use the pointer, and poniter + size()
begin/end definitions in the tiny case, and delegate to the inner vector
whenever it is present.
llvm-svn: 161024
2012-07-31 10:48:31 +08:00
|
|
|
TinyPtrVectorTest.cpp
|
2012-06-21 17:51:26 +08:00
|
|
|
TripleTest.cpp
|
|
|
|
TwineTest.cpp
|
|
|
|
VariadicFunctionTest.cpp
|
|
|
|
)
|
2012-08-31 00:22:32 +08:00
|
|
|
|
|
|
|
add_llvm_unittest(ADTTests
|
|
|
|
${ADTSources}
|
|
|
|
)
|
2015-06-16 08:44:12 +08:00
|
|
|
|
|
|
|
add_dependencies(ADTTests intrinsics_gen)
|