C++: Cleanup now that we're back to an abstract class.

This commit is contained in:
Mathias Vorreiter Pedersen
2023-12-19 12:10:23 +01:00
parent 937e0ee8d2
commit 4844c43f06
4 changed files with 55 additions and 44 deletions

View File

@@ -1,14 +1,14 @@
/**
* This file contains a module that implements the _debug_ version of
* This file contains the class that implements the _debug_ version of
* `toString` for `Instruction` and `Operand` dataflow nodes.
*/
private import semmle.code.cpp.ir.IR
private import codeql.util.Unit
private import Node0ToStringSig
private import Node0ToString
private import DataFlowUtil
class DebugNode0ToString extends Node0ToString {
private class DebugNode0ToString extends Node0ToString {
override string instructionToString(Instruction i) { result = i.getDumpString() }
override string operandToString(Operand op) {

View File

@@ -1,9 +1,53 @@
/**
* This file imports the module that is used to construct the strings used by `Node.ToString`.
* This file imports the class that is used to construct the strings used by
* `Node.ToString`.
*
* Normally, this file should just import `NormalNode0ToString` to compute the efficient `toString`, but for debugging purposes
* one can import `DebugPrinting.qll` to better correlate the dataflow nodes with their underlying instructions and operands.
* Normally, this file should just import `NormalNode0ToString` to compute the
* efficient `toString`, but for debugging purposes one can import
* `DebugPrinting.qll` to better correlate the dataflow nodes with their
* underlying instructions and operands.
*/
import Node0ToStringSig
import NormalNode0ToString
private import semmle.code.cpp.ir.IR
private import codeql.util.Unit
private import DataFlowUtil
import NormalNode0ToString // Change this import to control which version should be used.
/** An abstract class to control the behavior of `Node.toString`. */
abstract class Node0ToString extends Unit {
/**
* Gets the string that should be used by `OperandNode.toString` to print the
* dataflow node whose underlying operand is `op.`
*/
abstract string operandToString(Operand op);
/**
* Gets the string that should be used by `InstructionNode.toString` to print
* the dataflow node whose underlying instruction is `instr`.
*/
abstract string instructionToString(Instruction i);
/**
* Gets the string representation of the `Expr` associated with `n`, if any.
*/
abstract string toExprString(Node n);
}
/**
* Gets the string that should be used by `OperandNode.toString` to print the
* dataflow node whose underlying operand is `op.`
*/
string operandToString(Operand op) { result = any(Node0ToString s).operandToString(op) }
/**
* Gets the string that should be used by `InstructionNode.toString` to print
* the dataflow node whose underlying instruction is `instr`.
*/
string instructionToString(Instruction instr) {
result = any(Node0ToString s).instructionToString(instr)
}
/**
* Gets the string representation of the `Expr` associated with `n`, if any.
*/
string toExprString(Node n) { result = any(Node0ToString s).toExprString(n) }

View File

@@ -1,33 +0,0 @@
/**
* This file contains the signature module for controlling the behavior of `Node.toString`.
*/
private import semmle.code.cpp.ir.IR
private import codeql.util.Unit
private import DataFlowUtil
/** A signature for a module to control the behavior of `Node.toString`. */
abstract class Node0ToString extends Unit {
/**
* Gets the string that should be used by `OperandNode.toString`.
*/
abstract string operandToString(Operand op);
/**
* Gets the string that should be used by `InstructionNode.toString`.
*/
abstract string instructionToString(Instruction i);
/**
* Gets the string representation of the `Expr` associated with `n`, if any.
*/
abstract string toExprString(Node n);
}
string operandToString(Operand op) { result = any(Node0ToString s).operandToString(op) }
string instructionToString(Instruction instr) {
result = any(Node0ToString s).instructionToString(instr)
}
string toExprString(Node n) { result = any(Node0ToString s).toExprString(n) }

View File

@@ -1,15 +1,15 @@
/**
* This file contains module that implements the non-debug version of
* This file contains the class that implements the non-debug version of
* `toString` for `Instruction` and `Operand` dataflow nodes.
*/
private import semmle.code.cpp.ir.IR
private import codeql.util.Unit
private import Node0ToStringSig
private import Node0ToString
private import DataFlowUtil
private import DataFlowPrivate
class NormalNode0ToStringImpl extends Node0ToString {
private class NormalNode0ToString extends Node0ToString {
override string instructionToString(Instruction i) {
if i.(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
then result = "this"