Skip to content

Commit 46d7b9e

Browse files
author
AndreiDiaconu1
committed
Lock stmt
Added support for the lock stmt Added a test case and updated the expected output
1 parent 4dd548b commit 46d7b9e

File tree

5 files changed

+605
-2
lines changed

5 files changed

+605
-2
lines changed

csharp/ql/src/semmle/code/csharp/ir/implementation/raw/internal/TranslatedStmt.qll

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ private import common.TranslatedConditionBlueprint
1212
private import IRInternal
1313
private import semmle.code.csharp.ir.internal.IRUtilities
1414
private import desugar.Foreach
15+
private import desugar.Lock
1516

1617
TranslatedStmt getTranslatedStmt(Stmt stmt) { result.getAST() = stmt }
1718

@@ -885,4 +886,55 @@ class TranslatedEnumeratorForeach extends TranslatedLoop {
885886
private TranslatedElement getTempEnumDecl() {
886887
result = ForeachElements::getEnumDecl(stmt)
887888
}
889+
}
890+
891+
class TranslatedLockStmt extends TranslatedStmt {
892+
override LockStmt stmt;
893+
894+
override TranslatedElement getChild(int id) {
895+
id = 0 and result = getLockedVarDecl() or
896+
id = 1 and result = getLockWasTakenDecl() or
897+
id = 2 and result = getTry()
898+
}
899+
900+
override Instruction getFirstInstruction() {
901+
result = getLockedVarDecl().getFirstInstruction()
902+
}
903+
904+
override Instruction getChildSuccessor(TranslatedElement child) {
905+
(
906+
child = getLockedVarDecl() and
907+
result = getLockWasTakenDecl().getFirstInstruction()
908+
) or
909+
(
910+
child = getLockWasTakenDecl() and
911+
result = getTry().getFirstInstruction()
912+
) or
913+
(
914+
child = getTry() and
915+
result = getParent().getChildSuccessor(this)
916+
)
917+
}
918+
919+
override predicate hasInstruction(Opcode opcode, InstructionTag tag,
920+
Type resultType, boolean isLValue) {
921+
none()
922+
}
923+
924+
override Instruction getInstructionSuccessor(InstructionTag tag,
925+
EdgeKind kind) {
926+
none()
927+
}
928+
929+
private TranslatedElement getTry() {
930+
result = LockElements::getTry(stmt)
931+
}
932+
933+
private TranslatedElement getLockedVarDecl() {
934+
result = LockElements::getLockedVarDecl(stmt)
935+
}
936+
937+
private TranslatedElement getLockWasTakenDecl() {
938+
result = LockElements::getLockWasTakenDecl(stmt)
939+
}
888940
}

0 commit comments

Comments
 (0)