Merge pull request #1948 from hvitved/csharp/autoformat

Approved by calumgrant
This commit is contained in:
semmle-qlci
2019-09-18 14:17:02 +01:00
committed by GitHub
8 changed files with 26 additions and 30 deletions

View File

@@ -33,7 +33,8 @@ private predicate canCreateCompilerGeneratedElement(Element generatedBy, int nth
generatedBy instanceof DelegateCreation and
nth in [0 .. DelegateElements::noGeneratedElements(generatedBy)]
or
generatedBy instanceof DelegateCall and nth in [0 .. DelegateElements::noGeneratedElements(generatedBy)]
generatedBy instanceof DelegateCall and
nth in [0 .. DelegateElements::noGeneratedElements(generatedBy)]
}
/**
@@ -223,9 +224,7 @@ newtype TTranslatedElement =
// Because of their implementation in C#,
// we deal with all the types of initialization separately.
// First only simple local variable initialization (ie. `int x = 0`)
exists(LocalVariableDeclAndInitExpr lvInit |
lvInit.getInitializer() = expr
)
exists(LocalVariableDeclAndInitExpr lvInit | lvInit.getInitializer() = expr)
or
// Then treat more complex ones
expr instanceof ArrayInitializer

View File

@@ -750,40 +750,37 @@ abstract class TranslatedSpecificJump extends TranslatedStmt {
class TranslatedBreakStmt extends TranslatedSpecificJump {
override BreakStmt stmt;
override Instruction getTargetInstruction() {
result = getEnclosingLoopOrSwitchNextInstr(stmt)
}
override Instruction getTargetInstruction() { result = getEnclosingLoopOrSwitchNextInstr(stmt) }
}
private Instruction getEnclosingLoopOrSwitchNextInstr(Stmt crtStmt) {
if crtStmt instanceof LoopStmt or crtStmt instanceof SwitchStmt
then
result = getTranslatedStmt(crtStmt).getParent().getChildSuccessor(getTranslatedStmt(crtStmt))
then result = getTranslatedStmt(crtStmt).getParent().getChildSuccessor(getTranslatedStmt(crtStmt))
else result = getEnclosingLoopOrSwitchNextInstr(crtStmt.getParent())
}
class TranslatedContinueStmt extends TranslatedSpecificJump {
override ContinueStmt stmt;
override Instruction getTargetInstruction() {
result = getEnclosingLoopTargetInstruction(stmt)
}
override Instruction getTargetInstruction() { result = getEnclosingLoopTargetInstruction(stmt) }
}
private Instruction getEnclosingLoopTargetInstruction(Stmt crtStmt) {
if crtStmt instanceof ForStmt
then result = getNextForInstruction(crtStmt)
else if crtStmt instanceof LoopStmt
then result = getTranslatedStmt(crtStmt).getFirstInstruction()
else result = getEnclosingLoopTargetInstruction(crtStmt.getParent())
else
if crtStmt instanceof LoopStmt
then result = getTranslatedStmt(crtStmt).getFirstInstruction()
else result = getEnclosingLoopTargetInstruction(crtStmt.getParent())
}
private Instruction getNextForInstruction(ForStmt for) {
if exists(for.getUpdate(0))
then result = getTranslatedStmt(for).(TranslatedForStmt).getUpdate(0).getFirstInstruction()
else if exists(for.getCondition())
then result = getTranslatedStmt(for).(TranslatedForStmt).getCondition().getFirstInstruction()
else result = getTranslatedStmt(for).(TranslatedForStmt).getBody().getFirstInstruction()
else
if exists(for.getCondition())
then result = getTranslatedStmt(for).(TranslatedForStmt).getCondition().getFirstInstruction()
else result = getTranslatedStmt(for).(TranslatedForStmt).getBody().getFirstInstruction()
}
class TranslatedGotoLabelStmt extends TranslatedSpecificJump {

View File

@@ -1,7 +1,7 @@
/**
* Contains an abstract class that serves as a Base for classes that deal with the translation of calls
* (both AST generated and compiler generated).
*/
* Contains an abstract class that serves as a Base for classes that deal with the translation of calls
* (both AST generated and compiler generated).
*/
import csharp
private import semmle.code.csharp.ir.implementation.Opcode
@@ -14,7 +14,7 @@ private import semmle.code.csharp.ir.internal.IRCSharpLanguage as Language
private import TranslatedExprBase
abstract class TranslatedCallBase extends TranslatedElement {
override final TranslatedElement getChild(int id) {
final override TranslatedElement getChild(int id) {
// We choose the child's id in the order of evaluation.
// Note: some calls do need qualifiers, though instructions for them have already
// been generated; eg. a constructor does not need to generate a qualifier,
@@ -174,9 +174,7 @@ abstract class TranslatedCallBase extends TranslatedElement {
/**
* Holds if the call has any arguments, not counting the `this` argument.
*/
final predicate hasArguments() {
exists(getArgument(0))
}
final predicate hasArguments() { exists(getArgument(0)) }
predicate hasReadSideEffect() { any() }

View File

@@ -1,5 +1,5 @@
/**
* Contains an abstract class that serves as a Base for classes that deal with the translation of exprs
* Contains an abstract class that serves as a Base for classes that deal with the translation of exprs
* (both AST generated and compiler generated).
*/

View File

@@ -76,7 +76,7 @@ predicate hasPositionalArgIndex(int argIndex) {
// correct number of parameters; it is an overestimation,
// since we don't care about all the callables, so it
// should be restricted more
argIndex in [0..any(CSharp::Callable c).getNumberOfParameters() - 1]
argIndex in [0 .. any(CSharp::Callable c).getNumberOfParameters() - 1]
}
predicate hasAsmOperandIndex(int operandIndex) { none() }

View File

@@ -9,8 +9,7 @@ Type getVariableType(Variable v) {
exists(Type declaredType |
declaredType = v.getType() and
if v instanceof Parameter
then
result = declaredType
then result = declaredType
else
if declaredType instanceof ArrayType
then

View File

@@ -1,6 +1,8 @@
import csharp
private import semmle.code.csharp.controlflow.Guards
query predicate emptinessCheck(Expr check, CollectionExpr collection, AbstractValue v, boolean isEmpty) {
query predicate emptinessCheck(
Expr check, CollectionExpr collection, AbstractValue v, boolean isEmpty
) {
check = collection.getAnEmptinessCheck(v, isEmpty)
}