-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFlattenConditional.cpp
More file actions
50 lines (43 loc) · 1.08 KB
/
FlattenConditional.cpp
File metadata and controls
50 lines (43 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Unindents the if or else statement for a conditional.
// This will apply one of the following refactorings:
// Replace Nested Conditional with Guard Clause,
// Remove Redundant Conditional, or
// Reverse Conditional
// followed by
// Remove Redundant Conditional.
// Flatten Conditional is also smart enough to recognize
// if (E) return true; else return false; and convert that to return E;.
namespace FlattenConditionNamespace
{
int TestGuardClause(int *x, int y, int z)
{
// #TEST#: FC1 Flatten Conditional
if (x != 0)
{
if (y > 0)
{
if (z > 0)
{
return (*x + 10) * y * z;
}
}
}
return -1;
}
void TestGuardClause()
{
int x = 10;
int y = 2;
int z = 2;
int r = TestGuardClause(&x, y, z);
}
void TestRedundantConditional() {}
void TestReverseRedundantConditional() {}
} // namespace FlattenConditionNamespace
using namespace FlattenConditionNamespace;
void TestFlattenConditional()
{
TestGuardClause();
TestRedundantConditional();
TestReverseRedundantConditional();
}