CodePreprocessing.hpp¶
Contains the definition of the functions used to preprocess the code before the analysis and execution.
-
namespace mqt
-
namespace debugger
-
struct Block
- #include <CodePreprocessing.hpp>
Represents a block of code.
Code blocks are typically given in curly braces after a custom gate definition or an assertion.
Public Members
-
bool valid
Indicates whether the block is valid.
After finishing to parse the block, this field is set to
true. By default, it is set tofalse.
-
std::string code
The code in the block.
-
bool valid
-
struct ClassicCondition
- #include <CodePreprocessing.hpp>
Represents a parsed classic-controlled condition.
-
struct ClassicControlledGate
- #include <CodePreprocessing.hpp>
Represents a classic-controlled gate in the code.
Classic-controlled gates are defined using the
ifkeyword with one of the following formats:if (condition) operation;orif (condition) { operation1; operation2; ... }
-
struct FunctionDefinition
- #include <CodePreprocessing.hpp>
Represents a function definition in the code.
-
struct Instruction
- #include <CodePreprocessing.hpp>
Represents a preprocessed instruction in the code.
Also contains additional meta-information about the instruction.
Public Functions
-
Instruction(size_t inputLineNumber, std::string inputCode, std::unique_ptr<Assertion> &inputAssertion, std::vector<std::string> inputTargets, size_t startPos, size_t endPos, size_t successor, bool isFuncCall, std::string function, bool inFuncDef, bool isFuncDef, Block inputBlock)
Constructs a new Instruction object.
- Parameters:
inputLineNumber – The instruction number of the instruction in the original code.
inputCode – The string representation of this code.
inputAssertion – The representation of this instruction as an assertion, or
nullptr.inputTargets – The target variables or registers of this instruction.
startPos – The position of the instruction’s string’s first character in the un-processed code.
endPos – The position of the instruction’s string’s last character in the un-processed code.
successor – The index of the successor instruction in the preprocessed code.
isFuncCall – True if the instruction is a custom gate call.
function – The name of the custom gate called by this instruction, if it is a custom gate call.
inFuncDef – True if the instruction is located inside a custom gate definition.
isFuncDef – True if the instruction represents a custom gate definition.
inputBlock – The block of code following this instruction.
Public Members
-
size_t lineNumber
The instruction number of the instruction in the original code.
Numbering starts at 0 and it typically coincides with the line number in the code, but if multiple instructions are given in a single line, the numbering is incremented by 1 for each instruction.
-
std::string code
The string representation of this code.
-
std::unique_ptr<Assertion> assertion
The representation of this instruction as an assertion.
If the instruction is an assertion, this field contains the parsed assertion. Otherwise, it is
nullptr.
-
size_t originalCodeStartPosition
The position of the instruction’s string’s first character in the un-processed code.
-
size_t originalCodeEndPosition
The position of the instruction’s string’s last character in the un-processed code.
-
size_t successorIndex
The index of the successor instruction in the preprocessed code.
Typically, this is
lineNumber + 1, but it can be different if the instruction is a call to a custom gate. If the instruction represents areturn, this value is set to 0, as the successor is not known at static time.
-
bool isFunctionCall
Indicates whether the instruction is a custom gate call.
-
std::string calledFunction
The name of the custom gate called by this instruction, if it is a custom gate call.
-
bool inFunctionDefinition
Indicates whether the instruction is located inside a custom gate definition.
-
bool isFunctionDefinition
Indicates whether the instruction represents a custom gate definition.
-
std::map<std::string, std::string> callSubstitution
The substitutions to be made in the code when calling a custom gate.
Maps from the names of the parameters of the custom gate to the names of the variables used to call the custom gate.
-
std::vector<std::pair<size_t, size_t>> dataDependencies
The immediate data dependencies of this instruction.
For each variable used by this instruction, this vector contains a reference to the last instruction that used it. It also contains the index of the variable in that dependency’s argument list, so that it can be identified exactly.
-
Block block
The block of code following this instruction.
If the instruction is a custom gate definition or an assertion, this block contains the code in the curly braces following the definition or assertion. Otherwise, it is an empty block instance with
valid = false.
-
std::vector<size_t> childInstructions
The indices of the child instructions of this instruction.
If the instruction is a custom gate definition, this vector contains the indices of the instructions that are part of the custom gate. Otherwise, it is an empty vector.
-
Instruction(size_t inputLineNumber, std::string inputCode, std::unique_ptr<Assertion> &inputAssertion, std::vector<std::string> inputTargets, size_t startPos, size_t endPos, size_t successor, bool isFuncCall, std::string function, bool inFuncDef, bool isFuncDef, Block inputBlock)
-
struct Block
-
namespace debugger