C++: Fix PR feedback

Note that the various predicates to access the singleton instances of the `EdgeKind` classes have been moved into a module named `EdgeKind`.
This commit is contained in:
Dave Bartolomeo
2020-05-06 17:06:48 -04:00
parent a166a4d143
commit df4fdaf6ff
15 changed files with 119 additions and 103 deletions

View File

@@ -29,12 +29,6 @@ class GotoEdge extends EdgeKind, TGotoEdge {
final override string toString() { result = "Goto" }
}
/**
* Gets the single instance of `GotoEdge`, representing the unconditional successor of an
* `Instruction`
*/
GotoEdge gotoEdge() { result = TGotoEdge() }
/**
* A "true" edge, representing the successor of a conditional branch when the
* condition is non-zero.
@@ -43,12 +37,6 @@ class TrueEdge extends EdgeKind, TTrueEdge {
final override string toString() { result = "True" }
}
/**
* Gets the single instance of `TrueEdge`, representing the successor of a conditional branch when
* the condition is non-zero.
*/
TrueEdge trueEdge() { result = TTrueEdge() }
/**
* A "false" edge, representing the successor of a conditional branch when the
* condition is zero.
@@ -57,12 +45,6 @@ class FalseEdge extends EdgeKind, TFalseEdge {
final override string toString() { result = "False" }
}
/**
* Gets the single instance of `FalseEdge`, representing the successor of a conditional branch when
* the condition is zero.
*/
FalseEdge falseEdge() { result = TFalseEdge() }
/**
* An "exception" edge, representing the successor of an instruction when that
* instruction's evaluation throws an exception.
@@ -71,12 +53,6 @@ class ExceptionEdge extends EdgeKind, TExceptionEdge {
final override string toString() { result = "Exception" }
}
/**
* Gets the single instance of `ExceptionEdge`, representing the successor of an instruction when
* that instruction's evaluation throws an exception.
*/
ExceptionEdge exceptionEdge() { result = TExceptionEdge() }
/**
* A "default" edge, representing the successor of a `Switch` instruction when
* none of the case values matches the condition value.
@@ -85,12 +61,6 @@ class DefaultEdge extends EdgeKind, TDefaultEdge {
final override string toString() { result = "Default" }
}
/**
* Gets the single instance of `DefaultEdge`, representing the successor of a `Switch` instruction
* when none of the case values matches the condition value.
*/
DefaultEdge defaultEdge() { result = TDefaultEdge() }
/**
* A "case" edge, representing the successor of a `Switch` instruction when the
* the condition value matches a correponding `case` label.
@@ -112,8 +82,45 @@ class CaseEdge extends EdgeKind, TCaseEdge {
string getMaxValue() { result = maxValue }
}
/**
* Gets the `CaseEdge` representing the successor of a `Switch` instruction corresponding to the
* `case` label with the specified lower and upper bounds.
*/
CaseEdge caseEdge(string minValue, string maxValue) { result = TCaseEdge(minValue, maxValue) }
module EdgeKind {
/**
* Gets the single instance of the `GotoEdge` class.
*/
GotoEdge gotoEdge() { result = TGotoEdge() }
/**
* Gets the single instance of the `TrueEdge` class.
*/
TrueEdge trueEdge() { result = TTrueEdge() }
/**
* Gets the single instance of the `FalseEdge` class.
*/
FalseEdge falseEdge() { result = TFalseEdge() }
/**
* Gets the single instance of the `ExceptionEdge` class.
*/
ExceptionEdge exceptionEdge() { result = TExceptionEdge() }
/**
* Gets the single instance of the `DefaultEdge` class.
*/
DefaultEdge defaultEdge() { result = TDefaultEdge() }
/**
* Gets the `CaseEdge` representing a `case` label with the specified lower and upper bounds.
* For example:
* ```
* switch (x) {
* case 1: // Edge kind is `caseEdge("1", "1")`
* return x;
* case 2...8: // Edge kind is `caseEdge("2", "8")`
* return x - 1;
* default: // Edge kind is `defaultEdge()`
* return 0;
* }
* ```
*/
CaseEdge caseEdge(string minValue, string maxValue) { result = TCaseEdge(minValue, maxValue) }
}

View File

@@ -6,8 +6,8 @@ private import internal.TempVariableTagInternal
private import Imports::TempVariableTag
/**
* Describes the reason that a particular IR temporary variable was generated. For example, it could
* be generated to hold the return value of a function, or to hold the result of a `?:` operator
* A reason that a particular IR temporary variable was generated. For example, it could be
* generated to hold the return value of a function, or to hold the result of a `?:` operator
* computed on each branch. The set of possible `TempVariableTag`s is language-dependent.
*/
class TempVariableTag extends TTempVariableTag {

View File

@@ -584,9 +584,9 @@ class ConditionalBranchInstruction extends Instruction {
final Instruction getCondition() { result = getConditionOperand().getDef() }
final Instruction getTrueSuccessor() { result = getSuccessor(trueEdge()) }
final Instruction getTrueSuccessor() { result = getSuccessor(EdgeKind::trueEdge()) }
final Instruction getFalseSuccessor() { result = getSuccessor(falseEdge()) }
final Instruction getFalseSuccessor() { result = getSuccessor(EdgeKind::falseEdge()) }
}
class ExitFunctionInstruction extends Instruction {
@@ -906,7 +906,7 @@ class SwitchInstruction extends Instruction {
final Instruction getACaseSuccessor() { exists(CaseEdge edge | result = getSuccessor(edge)) }
final Instruction getDefaultSuccessor() { result = getSuccessor(defaultEdge()) }
final Instruction getDefaultSuccessor() { result = getSuccessor(EdgeKind::defaultEdge()) }
}
/**

View File

@@ -2,6 +2,7 @@
* Defines the set of possible `OperandTag`s, which are used to identify the role each `Operand`
* plays in the evaluation of its `Instruction`.
*/
private import OperandTagInternal
private newtype TOperandTag =
@@ -32,13 +33,13 @@ abstract class OperandTag extends TOperandTag {
abstract string toString();
/**
* Gets an integer representing the order in which this operand should appear in the operand list
* of an instruction when printing the IR.
* Gets an integer that represents where this this operand will appear in the operand list of an
* instruction when the IR is printed.
*/
abstract int getSortOrder();
/**
* Gets a label that will appear before the operand when printing the IR.
* Gets a label that will appear before the operand when the IR is printed.
*/
string getLabel() { result = "" }
}
@@ -59,7 +60,7 @@ abstract class RegisterOperandTag extends OperandTag { }
abstract class TypedOperandTag extends MemoryOperandTag { }
// Note: individual subtypes are listed in the order that the operands should
// appear in the operand list of the instruction when printing.
// appear in the operand list of the instruction when the IR is printed.
/**
* The address operand of an instruction that loads or stores a value from
* memory (e.g. `Load`, `Store`, `InitializeParameter`, `IndirectReadSideEffect`).

View File

@@ -584,9 +584,9 @@ class ConditionalBranchInstruction extends Instruction {
final Instruction getCondition() { result = getConditionOperand().getDef() }
final Instruction getTrueSuccessor() { result = getSuccessor(trueEdge()) }
final Instruction getTrueSuccessor() { result = getSuccessor(EdgeKind::trueEdge()) }
final Instruction getFalseSuccessor() { result = getSuccessor(falseEdge()) }
final Instruction getFalseSuccessor() { result = getSuccessor(EdgeKind::falseEdge()) }
}
class ExitFunctionInstruction extends Instruction {
@@ -906,7 +906,7 @@ class SwitchInstruction extends Instruction {
final Instruction getACaseSuccessor() { exists(CaseEdge edge | result = getSuccessor(edge)) }
final Instruction getDefaultSuccessor() { result = getSuccessor(defaultEdge()) }
final Instruction getDefaultSuccessor() { result = getSuccessor(EdgeKind::defaultEdge()) }
}
/**

View File

@@ -375,7 +375,7 @@ class TranslatedAllocationSideEffects extends TranslatedSideEffects,
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
tag = OnlyInstructionTag() and
kind = gotoEdge() and
kind = EdgeKind::gotoEdge() and
if exists(getChild(0))
then result = getChild(0).getFirstInstruction()
else result = getParent().getChildSuccessor(this)

View File

@@ -720,7 +720,7 @@ class TranslatedReadEffect extends TranslatedElement, TTranslatedReadEffect {
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind edge) {
tag = OnlyInstructionTag() and
edge = gotoEdge() and
edge = EdgeKind::gotoEdge() and
result = getParent().getChildSuccessor(this)
}

View File

@@ -584,9 +584,9 @@ class ConditionalBranchInstruction extends Instruction {
final Instruction getCondition() { result = getConditionOperand().getDef() }
final Instruction getTrueSuccessor() { result = getSuccessor(trueEdge()) }
final Instruction getTrueSuccessor() { result = getSuccessor(EdgeKind::trueEdge()) }
final Instruction getFalseSuccessor() { result = getSuccessor(falseEdge()) }
final Instruction getFalseSuccessor() { result = getSuccessor(EdgeKind::falseEdge()) }
}
class ExitFunctionInstruction extends Instruction {
@@ -906,7 +906,7 @@ class SwitchInstruction extends Instruction {
final Instruction getACaseSuccessor() { exists(CaseEdge edge | result = getSuccessor(edge)) }
final Instruction getDefaultSuccessor() { result = getSuccessor(defaultEdge()) }
final Instruction getDefaultSuccessor() { result = getSuccessor(EdgeKind::defaultEdge()) }
}
/**

View File

@@ -1,6 +1,6 @@
/**
* Provides predicates for manipulating integer constants tracked by constant folding and similar
* analyses.
* Provides predicates for manipulating integer constants that are tracked by constant folding and
* similar analyses.
*/
/**