Skip to content

Commit 6dd1c5e

Browse files
committed
C++: Split out 'NotExpr' to its own class.
1 parent a0d2213 commit 6dd1c5e

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,9 +1262,10 @@ abstract class TranslatedSingleInstructionExpr extends TranslatedNonConstantExpr
12621262

12631263
class TranslatedUnaryExpr extends TranslatedSingleInstructionExpr {
12641264
TranslatedUnaryExpr() {
1265-
expr instanceof NotExpr or
1266-
expr instanceof ComplementExpr or
1267-
expr instanceof UnaryPlusExpr or
1265+
expr instanceof ComplementExpr
1266+
or
1267+
expr instanceof UnaryPlusExpr
1268+
or
12681269
expr instanceof UnaryMinusExpr
12691270
}
12701271

@@ -1298,8 +1299,6 @@ class TranslatedUnaryExpr extends TranslatedSingleInstructionExpr {
12981299
}
12991300

13001301
final override Opcode getOpcode() {
1301-
expr instanceof NotExpr and result instanceof Opcode::LogicalNot
1302-
or
13031302
expr instanceof ComplementExpr and result instanceof Opcode::BitComplement
13041303
or
13051304
expr instanceof UnaryPlusExpr and result instanceof Opcode::CopyValue
@@ -1312,6 +1311,51 @@ class TranslatedUnaryExpr extends TranslatedSingleInstructionExpr {
13121311
}
13131312
}
13141313

1314+
class TranslatedNotExpr extends TranslatedNonConstantExpr {
1315+
override NotExpr expr;
1316+
1317+
final override Instruction getFirstInstruction(EdgeKind kind) {
1318+
result = this.getOperand().getFirstInstruction(kind)
1319+
}
1320+
1321+
override Instruction getALastInstructionInternal() {
1322+
result = this.getInstruction(OnlyInstructionTag())
1323+
}
1324+
1325+
final override TranslatedElement getChildInternal(int id) {
1326+
id = 0 and result = this.getOperand()
1327+
}
1328+
1329+
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
1330+
tag = OnlyInstructionTag() and
1331+
opcode instanceof Opcode::LogicalNot and
1332+
resultType = getBoolType()
1333+
}
1334+
1335+
final override Instruction getInstructionSuccessorInternal(InstructionTag tag, EdgeKind kind) {
1336+
tag = OnlyInstructionTag() and
1337+
result = this.getParent().getChildSuccessor(this, kind)
1338+
}
1339+
1340+
final override Instruction getChildSuccessorInternal(TranslatedElement child, EdgeKind kind) {
1341+
child = this.getOperand() and
1342+
kind instanceof GotoEdge and
1343+
result = this.getInstruction(OnlyInstructionTag())
1344+
}
1345+
1346+
final override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {
1347+
tag = OnlyInstructionTag() and
1348+
operandTag instanceof UnaryOperandTag and
1349+
result = this.getOperand().getResult()
1350+
}
1351+
1352+
private TranslatedExpr getOperand() {
1353+
result = getTranslatedExpr(expr.getOperand().getFullyConverted())
1354+
}
1355+
1356+
final override Instruction getResult() { result = this.getInstruction(OnlyInstructionTag()) }
1357+
}
1358+
13151359
/**
13161360
* IR translation of a `co_await` or `co_yield` expression.
13171361
*

0 commit comments

Comments
 (0)