@@ -8,6 +8,15 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
88{
99 internal class ForEach : Statement < ForEachStatementSyntax >
1010 {
11+ internal enum ForeachSymbolType
12+ {
13+ GetEnumeratorMethod = 1 ,
14+ CurrentProperty ,
15+ MoveNextMethod ,
16+ DisposeMethod ,
17+ ElementType
18+ }
19+
1120 private ForEach ( Context cx , ForEachStatementSyntax stmt , IStatementParentEntity parent , int child )
1221 : base ( cx , stmt , StmtKind . FOREACH , parent , child ) { }
1322
@@ -33,13 +42,44 @@ protected override void PopulateStatement(TextWriter trapFile)
3342 Statement . Create ( cx , Stmt . Statement , this , 2 ) ;
3443
3544 var info = semanticModel . GetForEachStatementInfo ( Stmt ) ;
36- var getEnumerator = Method . Create ( cx , info . GetEnumeratorMethod ) ;
37- var currentProp = Property . Create ( cx , info . CurrentProperty ) ;
38- var moveNext = Method . Create ( cx , info . MoveNextMethod ) ;
39- var dispose = Method . Create ( cx , info . DisposeMethod ) ;
40- var elementType = Type . Create ( cx , info . ElementType ) ;
4145
42- trapFile . foreach_stmt_info ( this , elementType , getEnumerator , moveNext , dispose , currentProp , info . IsAsynchronous ) ;
46+ if ( info . Equals ( default ) )
47+ {
48+ cx . ExtractionError ( "Could not get foreach statement info" , null , Location . Create ( cx , this . ReportingLocation ) , severity : Util . Logging . Severity . Info ) ;
49+ return ;
50+ }
51+
52+ trapFile . foreach_stmt_info ( this , info . IsAsynchronous ) ;
53+
54+ if ( info . GetEnumeratorMethod != null )
55+ {
56+ var m = Method . Create ( cx , info . GetEnumeratorMethod ) ;
57+ trapFile . foreach_stmt_desugar ( this , m , ForeachSymbolType . GetEnumeratorMethod ) ;
58+ }
59+
60+ if ( info . MoveNextMethod != null )
61+ {
62+ var m = Method . Create ( cx , info . MoveNextMethod ) ;
63+ trapFile . foreach_stmt_desugar ( this , m , ForeachSymbolType . MoveNextMethod ) ;
64+ }
65+
66+ if ( info . DisposeMethod != null )
67+ {
68+ var m = Method . Create ( cx , info . DisposeMethod ) ;
69+ trapFile . foreach_stmt_desugar ( this , m , ForeachSymbolType . DisposeMethod ) ;
70+ }
71+
72+ if ( info . CurrentProperty != null )
73+ {
74+ var p = Property . Create ( cx , info . CurrentProperty ) ;
75+ trapFile . foreach_stmt_desugar ( this , p , ForeachSymbolType . CurrentProperty ) ;
76+ }
77+
78+ if ( info . ElementType != null )
79+ {
80+ var t = Type . Create ( cx , info . ElementType ) ;
81+ trapFile . foreach_stmt_desugar ( this , t , ForeachSymbolType . ElementType ) ;
82+ }
4383 }
4484 }
4585
0 commit comments