Skip to content

Commit

Permalink
Trying to improve test coverage slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Aug 5, 2023
1 parent 23eb330 commit b27fdb5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ class InitializerListExpression : Expression(), ArgumentHolder, HasType.TypeObse
@AST
var initializerEdges = mutableListOf<PropertyEdge<Expression>>()
set(value) {
field.forEach {
it.end.unregisterTypeObserver(this)
removePrevDFG(it.end)
}
field.forEach { it.end.unregisterTypeObserver(this) }
field = value
value.forEach {
it.end.registerTypeObserver(this)
addPrevDFG(it.end)
}
value.forEach { it.end.registerTypeObserver(this) }
}

/** Virtual property to access [initializerEdges] without property edges. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class DFGPass(ctx: TranslationContext) : ComponentPass(ctx) {
is NewExpression -> handleNewExpression(node)
// We keep the logic for the InitializerListExpression in that class because the
// performance would decrease too much.
// is InitializerListExpression -> handleInitializerListExpression(node)
is InitializerListExpression -> handleInitializerListExpression(node)
is KeyValueExpression -> handleKeyValueExpression(node)
is LambdaExpression -> handleLambdaExpression(node)
is UnaryOperator -> handleUnaryOperator(node)
Expand Down Expand Up @@ -272,8 +272,6 @@ class DFGPass(ctx: TranslationContext) : ComponentPass(ctx) {
/**
* Adds the DFG edges for an [InitializerListExpression]. All values in the initializer flow to
* this expression.
*
* TODO: This change seems to have performance issues!
*/
protected fun handleInitializerListExpression(node: InitializerListExpression) {
node.initializers.forEach { node.addPrevDFG(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression.*
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression
import org.eclipse.cdt.internal.core.dom.parser.c.CASTDesignatedInitializer
import org.eclipse.cdt.internal.core.dom.parser.cpp.*
import org.eclipse.cdt.internal.core.model.ASTStringUtil

/**
* Note: CDT expresses hierarchies in Interfaces to allow to have multi-inheritance in java. Because
Expand Down Expand Up @@ -476,47 +477,26 @@ class ExpressionHandler(lang: CXXLanguageFrontend) :
}

private fun handleBinaryExpression(ctx: IASTBinaryExpression): Expression {
var operatorCode = ""
when (ctx.operator) {
op_multiply -> operatorCode = "*"
op_divide -> operatorCode = "/"
op_modulo -> operatorCode = "%"
op_plus -> operatorCode = "+"
op_minus -> operatorCode = "-"
op_shiftLeft -> operatorCode = "<<"
op_shiftRight -> operatorCode = ">>"
op_lessThan -> operatorCode = "<"
op_greaterThan -> operatorCode = ">"
op_lessEqual -> operatorCode = "<="
op_greaterEqual -> operatorCode = ">="
op_binaryAnd -> operatorCode = "&"
op_binaryXor -> operatorCode = "^"
op_binaryOr -> operatorCode = "|"
op_logicalAnd -> operatorCode = "&&"
op_logicalOr -> operatorCode = "||"
op_assign,
op_multiplyAssign,
op_divideAssign,
op_moduloAssign,
op_plusAssign,
op_minusAssign,
op_shiftLeftAssign,
op_shiftRightAssign,
op_binaryAndAssign,
op_binaryXorAssign,
op_binaryOrAssign -> {
return handleAssignment(ctx)
var operatorCode =
when (ctx.operator) {
op_assign,
op_multiplyAssign,
op_divideAssign,
op_moduloAssign,
op_plusAssign,
op_minusAssign,
op_shiftLeftAssign,
op_shiftRightAssign,
op_binaryAndAssign,
op_binaryXorAssign,
op_binaryOrAssign -> {
return handleAssignment(ctx)
}
op_pmdot -> ".*"
op_pmarrow -> "->*"
else -> String(ASTStringUtil.getBinaryOperatorString(ctx))
}
op_equals -> operatorCode = "=="
op_notequals -> operatorCode = "!="
op_pmdot -> operatorCode = ".*"
op_pmarrow -> operatorCode = "->*"
op_max -> operatorCode = ">?"
op_min -> operatorCode = "?<"
op_ellipses -> operatorCode = "..."
else ->
Util.errorWithFileLocation(frontend, ctx, log, "unknown operator {}", ctx.operator)
}

val binaryOperator = newBinaryOperator(operatorCode, ctx.rawSignature)
val lhs = handle(ctx.operand1) ?: newProblemExpression("could not parse lhs")
val rhs =
Expand All @@ -541,22 +521,8 @@ class ExpressionHandler(lang: CXXLanguageFrontend) :
handle(ctx.initOperand2)
}
?: newProblemExpression("missing RHS")
val operatorCode =
when (ctx.operator) {
op_assign -> "="
op_multiplyAssign -> "*="
op_divideAssign -> "/="
op_moduloAssign -> "%="
op_plusAssign -> "+="
op_minusAssign -> "-="
op_shiftLeftAssign -> "<<="
op_shiftRightAssign -> ">>="
op_binaryAndAssign -> "&="
op_binaryXorAssign -> "^="
op_binaryOrAssign -> "|="
else -> ""
}

val operatorCode = String(ASTStringUtil.getBinaryOperatorString(ctx))
val assign = newAssignExpression(operatorCode, listOf(lhs), listOf(rhs), rawNode = ctx)
if (rhs is UnaryOperator && rhs.input is DeclaredReferenceExpression) {
(rhs.input as DeclaredReferenceExpression).resolutionHelper = lhs
Expand Down

0 comments on commit b27fdb5

Please sign in to comment.