Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 15cd1d2

Browse files
committed
C#: Implement using declaration statements.
1 parent ac3a06f commit 15cd1d2

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/LocalDeclaration.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Microsoft.CodeAnalysis;
12
using Microsoft.CodeAnalysis.CSharp.Syntax;
23
using Semmle.Extraction.CSharp.Entities.Expressions;
34
using Semmle.Extraction.Kinds;
@@ -6,8 +7,17 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
67
{
78
class LocalDeclaration : Statement<LocalDeclarationStatementSyntax>
89
{
10+
static StmtKind GetKind(LocalDeclarationStatementSyntax declStmt)
11+
{
12+
if (declStmt.UsingKeyword.RawKind != 0) return StmtKind.USING_DECL;
13+
14+
if (declStmt.IsConst) return StmtKind.CONST_DECL;
15+
16+
return StmtKind.VAR_DECL;
17+
}
18+
919
LocalDeclaration(Context cx, LocalDeclarationStatementSyntax declStmt, IStatementParentEntity parent, int child)
10-
: base(cx, declStmt, declStmt.IsConst ? StmtKind.CONST_DECL : StmtKind.VAR_DECL, parent, child) { }
20+
: base(cx, declStmt, GetKind(declStmt), parent, child) { }
1121

1222
public static LocalDeclaration Create(Context cx, LocalDeclarationStatementSyntax node, IStatementParentEntity parent, int child)
1323
{

csharp/extractor/Semmle.Extraction.CSharp/Kinds/StmtKind.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public enum StmtKind
3434
LABEL = 27,
3535
CATCH = 28,
3636
CASE = 29,
37-
LOCAL_FUNCTION = 30
37+
LOCAL_FUNCTION = 30,
38+
USING_DECL = 31
3839
}
3940
}

csharp/ql/src/semmle/code/csharp/Stmt.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,17 @@ class LocalConstantDeclStmt extends LocalVariableDeclStmt, @const_decl_stmt {
12541254
override string toString() { result = "const ... ...;" }
12551255
}
12561256

1257+
/**
1258+
* A `using` declaration statement, for example
1259+
*
1260+
* ```
1261+
* using FileStream f = File.Open("settings.xml");
1262+
* ```
1263+
*/
1264+
class UsingDeclStmt extends LocalVariableDeclStmt, @using_decl_stmt {
1265+
override string toString() { result = "using ... ...;" }
1266+
}
1267+
12571268
/**
12581269
* An empty statement, for example line 2 in
12591270
*

csharp/ql/src/semmlecode.csharp.dbscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,12 @@ case @stmt.kind of
808808
| 28 = @catch
809809
| 29 = @case_stmt
810810
| 30 = @local_function_stmt
811+
| 31 = @using_decl_stmt
811812
;
812813

813814
@labeled_stmt = @label_stmt | @case;
814815

815-
@decl_stmt = @var_decl_stmt | @const_decl_stmt;
816+
@decl_stmt = @var_decl_stmt | @const_decl_stmt | @using_decl_stmt;
816817

817818
@cond_stmt = @if_stmt | @switch_stmt;
818819

0 commit comments

Comments
 (0)