Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Autoformat.
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Schaefer committed Jan 21, 2020
1 parent 1d33a61 commit 8fc414b
Showing 1 changed file with 89 additions and 59 deletions.
148 changes: 89 additions & 59 deletions ql/src/semmle/go/controlflow/IR.qll
Original file line number Diff line number Diff line change
Expand Up @@ -114,33 +114,60 @@ module IR {

/** Gets a textual representation of the kind of this instruction. */
string getInsnKind() {
this instanceof MkExprNode and result = "expression" or
this instanceof MkLiteralElementInitNode and result = "element init" or
this instanceof MkImplicitLiteralElementIndex and result = "element index" or
this instanceof MkAssignNode and result = "assignment" or
this instanceof MkCompoundAssignRhsNode and result = "right-hand side of compound assignment" or
this instanceof MkExtractNode and result = "tuple element extraction" or
this instanceof MkZeroInitNode and result = "zero value" or
this instanceof MkFuncDeclNode and result = "function declaration" or
this instanceof MkDeferNode and result = "defer" or
this instanceof MkGoNode and result = "go" or
this instanceof MkConditionGuardNode and result = "condition guard" or
this instanceof MkIncDecNode and result = "increment/decrement" or
this instanceof MkIncDecRhs and result = "right-hand side of increment/decrement" or
this instanceof MkImplicitOne and result = "implicit 1" or
this instanceof MkReturnNode and result = "return" or
this instanceof MkResultWriteNode and result = "result write" or
this instanceof MkResultReadNode and result = "result read" or
this instanceof MkSelectNode and result = "select" or
this instanceof MkSendNode and result = "send" or
this instanceof MkParameterInit and result = "parameter initialization" or
this instanceof MkArgumentNode and result = "argument" or
this instanceof MkResultInit and result = "result initialization" or
this instanceof MkNextNode and result = "next key-value pair" or
this instanceof MkImplicitTrue and result = "implicit true" or
this instanceof MkCaseCheckNode and result = "case" or
this instanceof MkImplicitLowerSliceBound and result = "implicit lower bound" or
this instanceof MkImplicitUpperSliceBound and result = "implicit upper bound" or
this instanceof MkExprNode and result = "expression"
or
this instanceof MkLiteralElementInitNode and result = "element init"
or
this instanceof MkImplicitLiteralElementIndex and result = "element index"
or
this instanceof MkAssignNode and result = "assignment"
or
this instanceof MkCompoundAssignRhsNode and result = "right-hand side of compound assignment"
or
this instanceof MkExtractNode and result = "tuple element extraction"
or
this instanceof MkZeroInitNode and result = "zero value"
or
this instanceof MkFuncDeclNode and result = "function declaration"
or
this instanceof MkDeferNode and result = "defer"
or
this instanceof MkGoNode and result = "go"
or
this instanceof MkConditionGuardNode and result = "condition guard"
or
this instanceof MkIncDecNode and result = "increment/decrement"
or
this instanceof MkIncDecRhs and result = "right-hand side of increment/decrement"
or
this instanceof MkImplicitOne and result = "implicit 1"
or
this instanceof MkReturnNode and result = "return"
or
this instanceof MkResultWriteNode and result = "result write"
or
this instanceof MkResultReadNode and result = "result read"
or
this instanceof MkSelectNode and result = "select"
or
this instanceof MkSendNode and result = "send"
or
this instanceof MkParameterInit and result = "parameter initialization"
or
this instanceof MkArgumentNode and result = "argument"
or
this instanceof MkResultInit and result = "result initialization"
or
this instanceof MkNextNode and result = "next key-value pair"
or
this instanceof MkImplicitTrue and result = "implicit true"
or
this instanceof MkCaseCheckNode and result = "case"
or
this instanceof MkImplicitLowerSliceBound and result = "implicit lower bound"
or
this instanceof MkImplicitUpperSliceBound and result = "implicit upper bound"
or
this instanceof MkImplicitMaxSliceBound and result = "implicit maximum"
}
}
Expand Down Expand Up @@ -222,17 +249,14 @@ module IR {
/** Gets the field being read. */
Field getField() { e.getSelector() = result.getAReference() }

override predicate readsField(Instruction base, Field f) {
base = getBase() and f = getField()
}
override predicate readsField(Instruction base, Field f) { base = getBase() and f = getField() }
}

/**
* An IR instruction that looks up a method.
*/
class MethodReadInstruction extends ReadInstruction, EvalInstruction {
Method method;

override SelectorExpr e;

MethodReadInstruction() { e.getSelector() = method.getAReference() }
Expand Down Expand Up @@ -296,12 +320,12 @@ module IR {
*/
class InitLiteralComponentInstruction extends WriteInstruction, MkLiteralElementInitNode {
CompositeLit lit;

int i;

Expr elt;

InitLiteralComponentInstruction() { this = MkLiteralElementInitNode(elt) and elt = lit.getElement(i) }
InitLiteralComponentInstruction() {
this = MkLiteralElementInitNode(elt) and elt = lit.getElement(i)
}

/** Gets the instruction allocating the composite literal. */
Instruction getBase() { result = evalExprInstruction(lit) }
Expand Down Expand Up @@ -430,7 +454,10 @@ module IR {

/** Gets the index of the `i`th element in (array or slice) literal `lit`. */
private int getElementIndex(CompositeLit lit, int i) {
(lit.getType().getUnderlyingType() instanceof ArrayType or lit.getType().getUnderlyingType() instanceof SliceType) and
(
lit.getType().getUnderlyingType() instanceof ArrayType or
lit.getType().getUnderlyingType() instanceof SliceType
) and
exists(Expr elt | elt = lit.getElement(i) |
// short-circuit computation for literals without any explicit keys
noExplicitKeys(lit) and result = i
Expand Down Expand Up @@ -486,7 +513,6 @@ module IR {
*/
class AssignInstruction extends WriteInstruction, MkAssignNode {
AstNode assgn;

int i;

AssignInstruction() { this = MkAssignNode(assgn, i) }
Expand Down Expand Up @@ -548,7 +574,6 @@ module IR {
*/
class ExtractTupleElementInstruction extends Instruction, MkExtractNode {
AstNode s;

int i;

ExtractTupleElementInstruction() { this = MkExtractNode(s, i) }
Expand All @@ -569,9 +594,7 @@ module IR {
}

/** Holds if this extracts the `idx`th value of the result of `base`. */
predicate extractsElement(Instruction base, int idx) {
base = getBase() and idx = i
}
predicate extractsElement(Instruction base, int idx) { base = getBase() and idx = i }

override Type getResultType() {
exists(CallExpr c | getBase() = evalExprInstruction(c) |
Expand All @@ -581,8 +604,14 @@ module IR {
exists(Type rangeType | rangeType = s.(RangeStmt).getDomain().getType().getUnderlyingType() |
exists(Type baseType |
baseType = rangeType.(ArrayType).getElementType() or
baseType = rangeType.(PointerType).getBaseType().getUnderlyingType().(ArrayType).getElementType() or
baseType = rangeType.(SliceType).getElementType() |
baseType = rangeType
.(PointerType)
.getBaseType()
.getUnderlyingType()
.(ArrayType)
.getElementType() or
baseType = rangeType.(SliceType).getElementType()
|
i = 0 and
result instanceof IntType
or
Expand Down Expand Up @@ -637,13 +666,21 @@ module IR {

override ControlFlow::Root getRoot() { result.isRootOf(v.getDeclaration()) }

override int getIntValue() { v.getType().getUnderlyingType() instanceof IntegerType and result = 0 }
override int getIntValue() {
v.getType().getUnderlyingType() instanceof IntegerType and result = 0
}

override float getFloatValue() { v.getType().getUnderlyingType() instanceof FloatType and result = 0.0 }
override float getFloatValue() {
v.getType().getUnderlyingType() instanceof FloatType and result = 0.0
}

override string getStringValue() { v.getType().getUnderlyingType() instanceof StringType and result = "" }
override string getStringValue() {
v.getType().getUnderlyingType() instanceof StringType and result = ""
}

override boolean getBoolValue() { v.getType().getUnderlyingType() instanceof BoolType and result = false }
override boolean getBoolValue() {
v.getType().getUnderlyingType() instanceof BoolType and result = false
}

override string getExactValue() {
result = getIntValue().toString() or
Expand Down Expand Up @@ -809,9 +846,7 @@ module IR {
ReturnInstruction() { this = MkReturnNode(ret) }

/** Holds if this statement returns multiple results. */
predicate returnsMultipleResults() {
exists(MkExtractNode(ret, _)) or ret.getNumExpr() > 1
}
predicate returnsMultipleResults() { exists(MkExtractNode(ret, _)) or ret.getNumExpr() > 1 }

/** Gets the instruction whose result is the (unique) result returned by this statement. */
Instruction getResult() {
Expand Down Expand Up @@ -844,9 +879,7 @@ module IR {
*/
class WriteResultInstruction extends WriteInstruction, MkResultWriteNode {
ResultVariable var;

int i;

ReturnInstruction ret;

WriteResultInstruction() {
Expand Down Expand Up @@ -1067,7 +1100,6 @@ module IR {
*/
class CaseInstruction extends Instruction, MkCaseCheckNode {
CaseClause cc;

int i;

CaseInstruction() { this = MkCaseCheckNode(cc, i) }
Expand Down Expand Up @@ -1161,7 +1193,9 @@ module IR {
class WriteTarget extends TWriteTarget {
ControlFlow::Node w;

WriteTarget() { this = MkLhs(w, _) or this = MkLiteralElementTarget(w) or this = MkResultWriteTarget(w) }
WriteTarget() {
this = MkLhs(w, _) or this = MkLiteralElementTarget(w) or this = MkResultWriteTarget(w)
}

/** Gets the write instruction of which this is the target. */
WriteInstruction getWrite() { result = w }
Expand Down Expand Up @@ -1260,9 +1294,7 @@ module IR {

/** Gets the instruction computing the base value on which this field is accessed. */
Instruction getBase() {
exists(SelectorExpr sel | this = MkLhs(_, sel) |
result = evalExprInstruction(sel.getBase())
)
exists(SelectorExpr sel | this = MkLhs(_, sel) | result = evalExprInstruction(sel.getBase()))
or
result = w.(InitLiteralStructFieldInstruction).getBase()
}
Expand Down Expand Up @@ -1319,9 +1351,7 @@ module IR {

/** Gets the instruction computing the index of this element reference. */
Instruction getIndex() {
exists(IndexExpr idx | this = MkLhs(_, idx) |
result = evalExprInstruction(idx.getIndex())
)
exists(IndexExpr idx | this = MkLhs(_, idx) | result = evalExprInstruction(idx.getIndex()))
or
result = w.(InitLiteralElementInstruction).getIndex()
}
Expand Down

0 comments on commit 8fc414b

Please sign in to comment.