From 0b0eaa796ca9afa9421ebee18cb43e417d3e7de8 Mon Sep 17 00:00:00 2001 From: Konrad Weiss Date: Mon, 11 Sep 2023 10:22:06 +0200 Subject: [PATCH] Finish renaming of variables still names Expr --- .../aisec/cpg/passes/CallResolver.kt | 48 +++++++++---------- .../templates/ClassTemplateTest.kt | 40 ++++++++-------- docs/docs/CPG/specs/dfg.md | 12 ++--- docs/docs/CPG/specs/eog.md | 8 ++-- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/CallResolver.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/CallResolver.kt index e5b390d910..34618d832c 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/CallResolver.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/CallResolver.kt @@ -421,46 +421,46 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) { return scopeManager.resolveFunctionStopScopeTraversalOnDefinition(call).isEmpty() } - protected fun handleConstructExpression(constructExpr: ConstructExpression) { - if (constructExpr.instantiates != null && constructExpr.constructor != null) return - val typeName = constructExpr.type.name + protected fun handleConstructExpression(constructExpression: ConstructExpression) { + if (constructExpression.instantiates != null && constructExpression.constructor != null) return + val typeName = constructExpression.type.name val recordDeclaration = recordMap[typeName] - constructExpr.instantiates = recordDeclaration + constructExpression.instantiates = recordDeclaration for (template in templateList) { if ( template is RecordTemplateDeclaration && recordDeclaration != null && recordDeclaration in template.realizations && - (constructExpr.templateParameters.size <= template.parameters.size) + (constructExpression.templateParameters.size <= template.parameters.size) ) { val defaultDifference = - template.parameters.size - constructExpr.templateParameters.size + template.parameters.size - constructExpression.templateParameters.size if (defaultDifference <= template.parameterDefaults.size) { // Check if predefined template value is used as default in next value - addRecursiveDefaultTemplateArgs(constructExpr, template) + addRecursiveDefaultTemplateArgs(constructExpression, template) // Add missing defaults val missingNewParams: List = template.parameterDefaults.subList( - constructExpr.templateParameters.size, + constructExpression.templateParameters.size, template.parameterDefaults.size ) for (missingParam in missingNewParams) { if (missingParam != null) { - constructExpr.addTemplateParameter( + constructExpression.addTemplateParameter( missingParam, TemplateInitialization.DEFAULT ) } } - constructExpr.templateInstantiation = template + constructExpression.templateInstantiation = template break } } } if (recordDeclaration != null) { - val constructor = getConstructorDeclaration(constructExpr, recordDeclaration) - constructExpr.constructor = constructor + val constructor = getConstructorDeclaration(constructExpression, recordDeclaration) + constructExpression.constructor = constructor } } @@ -585,35 +585,35 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) { } /** - * @param constructExpr we want to find an invocation target for + * @param constructExpression we want to find an invocation target for * @param recordDeclaration associated with the Object the ConstructExpression constructs * @return a ConstructDeclaration that is an invocation of the given ConstructExpression. If * there is no valid ConstructDeclaration we will create an implicit ConstructDeclaration that * matches the ConstructExpression. */ protected fun getConstructorDeclaration( - constructExpr: ConstructExpression, + constructExpression: ConstructExpression, recordDeclaration: RecordDeclaration ): ConstructorDeclaration { - val signature = constructExpr.signature + val signature = constructExpression.signature var constructorCandidate = getConstructorDeclarationDirectMatch(signature, recordDeclaration) - if (constructorCandidate == null && constructExpr.language is HasDefaultArguments) { + if (constructorCandidate == null && constructExpression.language is HasDefaultArguments) { // Check for usage of default args constructorCandidate = - resolveConstructorWithDefaults(constructExpr, signature, recordDeclaration) + resolveConstructorWithDefaults(constructExpression, signature, recordDeclaration) } - if (constructorCandidate == null && constructExpr.language.isCPP) { // TODO: Fix this + if (constructorCandidate == null && constructExpression.language.isCPP) { // TODO: Fix this // If we don't find any candidate and our current language is c/c++ we check if there is // a candidate with an implicit cast constructorCandidate = - resolveConstructorWithImplicitCast(constructExpr, recordDeclaration) + resolveConstructorWithImplicitCast(constructExpression, recordDeclaration) } return constructorCandidate ?: recordDeclaration .startInference(ctx) - .createInferredConstructor(constructExpr.signature) + .createInferredConstructor(constructExpression.signature) } protected fun getConstructorDeclarationForExplicitInvocation( @@ -631,18 +631,18 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) { * Adds implicit duplicates of the TemplateParams to the implicit ConstructExpression * * @param templateParams of the VariableDeclaration/NewExpressionp - * @param constructExpr duplicate TemplateParameters (implicit) to preserve AST, as + * @param constructExpression duplicate TemplateParameters (implicit) to preserve AST, as * ConstructExpression uses AST as well as the VariableDeclaration/NewExpression */ fun addImplicitTemplateParametersToCall( templateParams: List, - constructExpr: ConstructExpression + constructExpression: ConstructExpression ) { for (node in templateParams) { if (node is TypeExpression) { - constructExpr.addTemplateParameter(node.duplicate(true)) + constructExpression.addTemplateParameter(node.duplicate(true)) } else if (node is Literal<*>) { - constructExpr.addTemplateParameter(node.duplicate(true)) + constructExpression.addTemplateParameter(node.duplicate(true)) } } } diff --git a/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/templates/ClassTemplateTest.kt b/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/templates/ClassTemplateTest.kt index 8449aee80c..2630dd8154 100644 --- a/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/templates/ClassTemplateTest.kt +++ b/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/templates/ClassTemplateTest.kt @@ -104,28 +104,28 @@ internal class ClassTemplateTest : BaseTest() { private fun testClassTemplateInvocation( pairConstructorDeclaration: ConstructorDeclaration?, - constructExpr: ConstructExpression, + constructExpression: ConstructExpression, pair: RecordDeclaration?, pairType: ObjectType, template: RecordTemplateDeclaration?, point1: VariableDeclaration ) { - assertEquals(pairConstructorDeclaration, constructExpr.constructor) + assertEquals(pairConstructorDeclaration, constructExpression.constructor) assertNotNull(pairConstructorDeclaration) - assertTrue(constructExpr.invokes.contains(pairConstructorDeclaration)) - assertEquals(pair, constructExpr.instantiates) - assertEquals(template, constructExpr.templateInstantiation) - assertLocalName("Pair", constructExpr.type) - assertEquals(constructExpr.type, point1.type) - assertNotEquals(pairType, constructExpr.type) + assertTrue(constructExpression.invokes.contains(pairConstructorDeclaration)) + assertEquals(pair, constructExpression.instantiates) + assertEquals(template, constructExpression.templateInstantiation) + assertLocalName("Pair", constructExpression.type) + assertEquals(constructExpression.type, point1.type) + assertNotEquals(pairType, constructExpression.type) - val instantiatedType = constructExpr.type as? ObjectType + val instantiatedType = constructExpression.type as? ObjectType assertNotNull(instantiatedType) assertEquals(2, instantiatedType.generics.size) assertLocalName("int", instantiatedType.generics[0]) assertLocalName("int", instantiatedType.generics[1]) - val templateParameters = constructExpr.templateParameters + val templateParameters = constructExpression.templateParameters assertNotNull(templateParameters) assertEquals(2, templateParameters.size) assertLocalName("int", (templateParameters[0] as TypeExpression).type) @@ -258,25 +258,25 @@ internal class ClassTemplateTest : BaseTest() { template: RecordTemplateDeclaration?, pair: RecordDeclaration?, pairConstructorDeclaration: ConstructorDeclaration?, - constructExpr: ConstructExpression, + constructExpression: ConstructExpression, point1: VariableDeclaration ) { - assertEquals(pair, constructExpr.instantiates) - assertEquals(template, constructExpr.templateInstantiation) - assertEquals(pairConstructorDeclaration, constructExpr.constructor) - assertEquals(2, constructExpr.templateParameters.size) - assertLocalName("int", constructExpr.templateParameters[0]) + assertEquals(pair, constructExpression.instantiates) + assertEquals(template, constructExpression.templateInstantiation) + assertEquals(pairConstructorDeclaration, constructExpression.constructor) + assertEquals(2, constructExpression.templateParameters.size) + assertLocalName("int", constructExpression.templateParameters[0]) assertEquals( TemplateDeclaration.TemplateInitialization.EXPLICIT, - constructExpr.templateParameterEdges?.get(0)?.getProperty(Properties.INSTANTIATION) + constructExpression.templateParameterEdges?.get(0)?.getProperty(Properties.INSTANTIATION) ) - assertLocalName("int", constructExpr.templateParameters[1]) + assertLocalName("int", constructExpression.templateParameters[1]) assertEquals( TemplateDeclaration.TemplateInitialization.EXPLICIT, - constructExpr.templateParameterEdges?.get(1)?.getProperty(Properties.INSTANTIATION) + constructExpression.templateParameterEdges?.get(1)?.getProperty(Properties.INSTANTIATION) ) - val pairTypeInstantiated = constructExpr.type as ObjectType + val pairTypeInstantiated = constructExpression.type as ObjectType assertEquals(pair, pairTypeInstantiated.recordDeclaration) assertEquals(2, pairTypeInstantiated.generics.size) assertLocalName("int", pairTypeInstantiated.generics[0]) diff --git a/docs/docs/CPG/specs/dfg.md b/docs/docs/CPG/specs/dfg.md index cf71a4d3a2..ac12a851b4 100755 --- a/docs/docs/CPG/specs/dfg.md +++ b/docs/docs/CPG/specs/dfg.md @@ -191,18 +191,18 @@ Scheme: Interesting fields: * `condition: Expression`: The condition which is evaluated -* `thenExpr: Expression`: The expression which is executed if the condition holds -* `elseExpr: Expression`: The expression which is executed if the condition does not hold +* `thenExpression: Expression`: The expression which is executed if the condition holds +* `elseExpression: Expression`: The expression which is executed if the condition does not hold The `thenExpr` and the `elseExpr` flow to the `ConditionalExpression`. This means that implicit data flows are not considered. Scheme: ```mermaid flowchart LR - thenExpr -- DFG --> node([ConditionalExpression]); - thenExpr -.- node; - elseExpr -.- node; - elseExpr -- DFG --> node; + thenExpression -- DFG --> node([ConditionalExpression]); + thenExpression -.- node; + elseExpression -.- node; + elseExpression -- DFG --> node; ``` ## Reference diff --git a/docs/docs/CPG/specs/eog.md b/docs/docs/CPG/specs/eog.md index 73188f49ac..af52a8f4e2 100644 --- a/docs/docs/CPG/specs/eog.md +++ b/docs/docs/CPG/specs/eog.md @@ -604,8 +604,8 @@ A conditional evaluation of two expression, realizing the branching pattern of a Interesting fields: * `condition:Expression`: Executed first to decide the branch of evaluation. -* `thenExpr:Expression`: Evaluated if `condition` evaluates to `true.` -* `elseExpr:Expression`: Evaluated if `condition` evaluates to `false.` +* `thenExpression:Expression`: Evaluated if `condition` evaluates to `true.` +* `elseExpression:Expression`: Evaluated if `condition` evaluates to `false.` Scheme: ```mermaid @@ -613,8 +613,8 @@ flowchart LR classDef outer fill:#fff,stroke:#ddd,stroke-dasharray:5 5; prev:::outer --EOG--> child1["condition"] child1 --EOG--> parent(["ConditionalExpression"]) - parent --EOG:true--> child2["thenExpr"] - parent --EOG:false--> child3["elseExpr"] + parent --EOG:true--> child2["thenExpression"] + parent --EOG:false--> child3["elseExpression"] child2 --EOG--> next:::outer child3 --EOG--> next:::outer parent -.-> child1