@@ -20,41 +20,42 @@ namespace Microsoft.Python.Analysis {
20
20
public static class PythonWalkerExtensions {
21
21
public static bool WalkIfWithSystemConditions ( this IfStatement node , PythonWalker walker , PythonLanguageVersion languageVersion , bool isWindows ) {
22
22
// System version, platform and os.path specializations
23
- var someRecognized = false ;
23
+ var executeElse = false ;
24
24
foreach ( var test in node . Tests ) {
25
+
25
26
var result = test . TryHandleSysVersionInfo ( languageVersion ) ;
26
- if ( result != ConditionTestResult . Unrecognized ) {
27
- if ( result == ConditionTestResult . WalkBody ) {
28
- test . Walk ( walker ) ;
29
- } else {
30
- node . ElseStatement ? . Walk ( walker ) ;
27
+ if ( result == ConditionTestResult . Unrecognized ) {
28
+ result = test . TryHandleSysPlatform ( isWindows ) ;
29
+ if ( result == ConditionTestResult . Unrecognized ) {
30
+ result = test . TryHandleOsPath ( isWindows ) ;
31
31
}
32
- someRecognized = true ;
33
- continue ;
34
32
}
35
33
36
- result = test . TryHandleSysPlatform ( isWindows ) ;
37
- if ( result != ConditionTestResult . Unrecognized ) {
38
- if ( result == ConditionTestResult . WalkBody ) {
34
+ // If condition is satisfied, walk the corresponding block and
35
+ // return false indicating that statement should not be walked again.
36
+ // If condition is false or was not recognized, continue but remember
37
+ // if we need to execute final else clause.
38
+ switch ( result ) {
39
+ case ConditionTestResult . WalkBody :
39
40
test . Walk ( walker ) ;
40
- } else {
41
- node . ElseStatement ? . Walk ( walker ) ;
42
- }
43
- someRecognized = true ;
44
- continue ;
41
+ return false ; // We only need to execute one of the clauses.
42
+ case ConditionTestResult . DontWalkBody :
43
+ // If condition is false, continue but remember
44
+ // if we may need to execute the final else clause.
45
+ executeElse = true ;
46
+ break ;
47
+ case ConditionTestResult . Unrecognized :
48
+ continue ; // See if other conditions may work.
45
49
}
50
+ }
46
51
47
- result = test . TryHandleOsPath ( isWindows ) ;
48
- if ( result != ConditionTestResult . Unrecognized ) {
49
- if ( result == ConditionTestResult . WalkBody ) {
50
- test . Walk ( walker ) ;
51
- } else {
52
- node . ElseStatement ? . Walk ( walker ) ;
53
- }
54
- return false ; // Execute only one condition.
55
- }
52
+ if ( executeElse ) {
53
+ node . ElseStatement ? . Walk ( walker ) ;
54
+ return false ;
56
55
}
57
- return ! someRecognized ;
56
+
57
+ // We didn't walk anything, so me caller do their own thing.
58
+ return true ;
58
59
}
59
60
}
60
61
}
0 commit comments