@@ -619,7 +619,16 @@ internal VariableAnalysis InitializeVariableAnalysisHelper(Ast ast, VariableAnal
619
619
/// <param name="classes"></param>
620
620
/// <param name="scriptAst"></param>
621
621
/// <returns></returns>
622
+
623
+ #if PSV3
624
+
625
+ public string GetTypeFromReturnStatementAst ( Ast funcAst , ReturnStatementAst ret )
626
+
627
+ #else
628
+
622
629
public string GetTypeFromReturnStatementAst ( Ast funcAst , ReturnStatementAst ret , IEnumerable < TypeDefinitionAst > classes )
630
+
631
+ #endif
623
632
{
624
633
if ( ret == null || funcAst == null )
625
634
{
@@ -650,7 +659,15 @@ public string GetTypeFromReturnStatementAst(Ast funcAst, ReturnStatementAst ret,
650
659
}
651
660
else if ( cmAst . Expression is MemberExpressionAst )
652
661
{
662
+ #if PSV3
663
+
664
+ result = GetTypeFromMemberExpressionAst ( cmAst . Expression as MemberExpressionAst , funcAst ) ;
665
+
666
+ #else
667
+
653
668
result = GetTypeFromMemberExpressionAst ( cmAst . Expression as MemberExpressionAst , funcAst , classes ) ;
669
+
670
+ #endif
654
671
}
655
672
}
656
673
}
@@ -673,30 +690,56 @@ public string GetTypeFromReturnStatementAst(Ast funcAst, ReturnStatementAst ret,
673
690
/// <param name="scopeAst"></param>
674
691
/// <param name="classes"></param>
675
692
/// <returns></returns>
693
+
694
+ #if PSV3
695
+
696
+ public string GetTypeFromMemberExpressionAst ( MemberExpressionAst memberAst , Ast scopeAst )
697
+
698
+ #else
699
+
676
700
public string GetTypeFromMemberExpressionAst ( MemberExpressionAst memberAst , Ast scopeAst , IEnumerable < TypeDefinitionAst > classes )
701
+
702
+ #endif
677
703
{
678
704
if ( memberAst == null )
679
705
{
680
706
return String . Empty ;
681
707
}
682
708
683
709
VariableAnalysisDetails details = null ;
710
+
711
+ #if ! PSV3
712
+
684
713
TypeDefinitionAst psClass = null ;
685
714
715
+ #endif
716
+
686
717
if ( memberAst . Expression is VariableExpressionAst && VariableAnalysisDictionary . ContainsKey ( scopeAst ) )
687
718
{
688
719
VariableAnalysis VarTypeAnalysis = VariableAnalysisDictionary [ scopeAst ] ;
689
720
// Get the analysis detail for the variable
690
721
details = VarTypeAnalysis . GetVariableAnalysis ( memberAst . Expression as VariableExpressionAst ) ;
691
722
723
+ #if ! PSV3
724
+
692
725
if ( details != null && classes != null )
693
726
{
694
727
// Get the class that corresponds to the name of the type (if possible)
695
728
psClass = classes . FirstOrDefault ( item => String . Equals ( item . Name , details . Type . FullName , StringComparison . OrdinalIgnoreCase ) ) ;
696
729
}
730
+
731
+ #endif
697
732
}
698
733
699
- return GetTypeFromMemberExpressionAstHelper ( memberAst , psClass , details ) ;
734
+ #if PSV3
735
+
736
+ return GetTypeFromMemberExpressionAstHelper ( memberAst , details ) ;
737
+
738
+ #else
739
+
740
+ return GetTypeFromMemberExpressionAstHelper ( memberAst , psClass , details ) ;
741
+
742
+ #endif
700
743
}
701
744
702
745
/// <summary>
@@ -707,17 +750,30 @@ public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast
707
750
/// <param name="psClass"></param>
708
751
/// <param name="analysisDetails"></param>
709
752
/// <returns></returns>
753
+
754
+ #if PSV3
755
+
756
+ internal string GetTypeFromMemberExpressionAstHelper ( MemberExpressionAst memberAst , VariableAnalysisDetails analysisDetails )
757
+
758
+ #else
759
+
710
760
internal string GetTypeFromMemberExpressionAstHelper ( MemberExpressionAst memberAst , TypeDefinitionAst psClass , VariableAnalysisDetails analysisDetails )
761
+
762
+ #endif
711
763
{
712
764
//Try to get the type without using psClass first
713
765
Type result = AssignmentTarget . GetTypeFromMemberExpressionAst ( memberAst ) ;
714
766
767
+ #if ! PSV3
768
+
715
769
//If we can't get the type, then it may be that the type of the object being invoked on is a powershell class
716
770
if ( result == null && psClass != null && analysisDetails != null )
717
771
{
718
772
result = AssignmentTarget . GetTypeFromMemberExpressionAst ( memberAst , analysisDetails , psClass ) ;
719
773
}
720
774
775
+ #endif
776
+
721
777
if ( result != null )
722
778
{
723
779
return result . FullName ;
@@ -816,6 +872,8 @@ public Dictionary<string, List<RuleSuppression>> GetRuleSuppression(Ast ast)
816
872
ruleSuppressionList . AddRange ( GetSuppressionsFunction ( funcAst ) ) ;
817
873
}
818
874
875
+ #if ! PSV3
876
+
819
877
// Get rule suppression from classes
820
878
IEnumerable < TypeDefinitionAst > typeAsts = ast . FindAll ( item => item is TypeDefinitionAst , true ) . Cast < TypeDefinitionAst > ( ) ;
821
879
@@ -824,6 +882,8 @@ public Dictionary<string, List<RuleSuppression>> GetRuleSuppression(Ast ast)
824
882
ruleSuppressionList . AddRange ( GetSuppressionsClass ( typeAst ) ) ;
825
883
}
826
884
885
+ #endif
886
+
827
887
ruleSuppressionList . Sort ( ( item , item2 ) => item . StartOffset . CompareTo ( item2 . StartOffset ) ) ;
828
888
829
889
foreach ( RuleSuppression ruleSuppression in ruleSuppressionList )
@@ -1089,7 +1149,15 @@ public object VisitScriptBlock(ScriptBlockAst scriptBlockAst)
1089
1149
1090
1150
// We already run variable analysis if the parent is a function so skip these.
1091
1151
// Otherwise, we have to do variable analysis using the outer scope variables.
1152
+ #if PSV3
1153
+
1154
+ if ( ! ( scriptBlockAst . Parent is FunctionDefinitionAst ) )
1155
+
1156
+ #else
1157
+
1092
1158
if ( ! ( scriptBlockAst . Parent is FunctionDefinitionAst ) && ! ( scriptBlockAst . Parent is FunctionMemberAst ) )
1159
+
1160
+ #endif
1093
1161
{
1094
1162
OuterAnalysis = Helper . Instance . InitializeVariableAnalysisHelper ( scriptBlockAst , OuterAnalysis ) ;
1095
1163
}
@@ -1117,7 +1185,15 @@ public object VisitScriptBlock(ScriptBlockAst scriptBlockAst)
1117
1185
VariableAnalysis innerAnalysis = OuterAnalysis ;
1118
1186
OuterAnalysis = previousOuter ;
1119
1187
1188
+ #if PSV3
1189
+
1190
+ if ( ! ( scriptBlockAst . Parent is FunctionDefinitionAst ) )
1191
+
1192
+ #else
1193
+
1120
1194
if ( ! ( scriptBlockAst . Parent is FunctionDefinitionAst ) && ! ( scriptBlockAst . Parent is FunctionMemberAst ) )
1195
+
1196
+ #endif
1121
1197
{
1122
1198
// Update the variable analysis of the outer script block
1123
1199
VariableAnalysis . UpdateOuterAnalysis ( OuterAnalysis , innerAnalysis ) ;
@@ -1138,6 +1214,12 @@ private object VisitStatementHelper(StatementAst statementAst)
1138
1214
return null ;
1139
1215
}
1140
1216
1217
+ #if PSV3
1218
+
1219
+ statementAst . Visit ( this ) ;
1220
+
1221
+ #else
1222
+
1141
1223
TypeDefinitionAst typeAst = statementAst as TypeDefinitionAst ;
1142
1224
1143
1225
if ( typeAst == null )
@@ -1164,9 +1246,13 @@ private object VisitStatementHelper(StatementAst statementAst)
1164
1246
}
1165
1247
}
1166
1248
1249
+ #endif
1250
+
1167
1251
return null ;
1168
1252
}
1169
1253
1254
+ #if ! PSV3
1255
+
1170
1256
/// <summary>
1171
1257
/// Do nothing
1172
1258
/// </summary>
@@ -1177,6 +1263,8 @@ public object VisitUsingStatement(UsingStatementAst usingStatement)
1177
1263
return null ;
1178
1264
}
1179
1265
1266
+ #endif
1267
+
1180
1268
/// <summary>
1181
1269
/// Do nothing
1182
1270
/// </summary>
@@ -1842,8 +1930,12 @@ public class FindPipelineOutput : ICustomAstVisitor
1842
1930
{
1843
1931
List < Tuple < string , StatementAst > > outputTypes ;
1844
1932
1933
+ #if ! PSV3
1934
+
1845
1935
IEnumerable < TypeDefinitionAst > classes ;
1846
1936
1937
+ #endif
1938
+
1847
1939
FunctionDefinitionAst myFunction ;
1848
1940
/// <summary>
1849
1941
/// These binary operators will always return boolean value
@@ -1879,10 +1971,25 @@ static FindPipelineOutput()
1879
1971
/// Find the pipeline output
1880
1972
/// </summary>
1881
1973
/// <param name="ast"></param>
1974
+
1975
+ #if PSV3
1976
+
1977
+ public FindPipelineOutput ( FunctionDefinitionAst ast )
1978
+
1979
+ #else
1980
+
1882
1981
public FindPipelineOutput ( FunctionDefinitionAst ast , IEnumerable < TypeDefinitionAst > classes )
1982
+
1983
+ #endif
1883
1984
{
1884
1985
outputTypes = new List < Tuple < string , StatementAst > > ( ) ;
1986
+
1987
+ #if ! PSV3
1988
+
1885
1989
this . classes = classes ;
1990
+
1991
+ #endif
1992
+
1886
1993
myFunction = ast ;
1887
1994
1888
1995
if ( myFunction != null )
@@ -1895,11 +2002,22 @@ public FindPipelineOutput(FunctionDefinitionAst ast, IEnumerable<TypeDefinitionA
1895
2002
/// Get list of outputTypes from functiondefinitionast funcast
1896
2003
/// </summary>
1897
2004
/// <returns></returns>
2005
+
2006
+ #if PSV3
2007
+
2008
+ public static List < Tuple < string , StatementAst > > OutputTypes ( FunctionDefinitionAst funcAst )
2009
+ {
2010
+ return ( new FindPipelineOutput ( funcAst ) ) . outputTypes ;
2011
+ }
2012
+
2013
+ #else
1898
2014
public static List < Tuple < string , StatementAst > > OutputTypes ( FunctionDefinitionAst funcAst , IEnumerable < TypeDefinitionAst > classes )
1899
2015
{
1900
2016
return ( new FindPipelineOutput ( funcAst , classes ) ) . outputTypes ;
1901
2017
}
1902
2018
2019
+ #endif
2020
+
1903
2021
/// <summary>
1904
2022
/// Ignore assignment statement
1905
2023
/// </summary>
@@ -2351,7 +2469,15 @@ public object VisitCommandExpression(CommandExpressionAst commandAst)
2351
2469
/// <returns></returns>
2352
2470
public object VisitReturnStatement ( ReturnStatementAst returnStatementAst )
2353
2471
{
2472
+ #if PSV3
2473
+
2474
+ return Helper . Instance . GetTypeFromReturnStatementAst ( myFunction , returnStatementAst ) ;
2475
+
2476
+ #else
2477
+
2354
2478
return Helper . Instance . GetTypeFromReturnStatementAst ( myFunction , returnStatementAst , classes ) ;
2479
+
2480
+ #endif
2355
2481
}
2356
2482
2357
2483
/// <summary>
@@ -2361,7 +2487,15 @@ public object VisitReturnStatement(ReturnStatementAst returnStatementAst)
2361
2487
/// <returns></returns>
2362
2488
public object VisitMemberExpression ( MemberExpressionAst memAst )
2363
2489
{
2490
+ #if PSV3
2491
+
2492
+ return Helper . Instance . GetTypeFromMemberExpressionAst ( memAst , myFunction ) ;
2493
+
2494
+ #else
2495
+
2364
2496
return Helper . Instance . GetTypeFromMemberExpressionAst ( memAst , myFunction , classes ) ;
2497
+
2498
+ #endif
2365
2499
}
2366
2500
2367
2501
/// <summary>
@@ -2371,7 +2505,15 @@ public object VisitMemberExpression(MemberExpressionAst memAst)
2371
2505
/// <returns></returns>
2372
2506
public object VisitInvokeMemberExpression ( InvokeMemberExpressionAst invokeAst )
2373
2507
{
2508
+ #if PSV3
2509
+
2510
+ return Helper . Instance . GetTypeFromMemberExpressionAst ( invokeAst , myFunction ) ;
2511
+
2512
+ #else
2513
+
2374
2514
return Helper . Instance . GetTypeFromMemberExpressionAst ( invokeAst , myFunction , classes ) ;
2515
+
2516
+ #endif
2375
2517
}
2376
2518
2377
2519
/// <summary>
0 commit comments