From c0baa57e4372353aac4fdc30269861ac9d220eb7 Mon Sep 17 00:00:00 2001 From: Alexander Kuechler Date: Tue, 5 Nov 2024 18:40:21 +0100 Subject: [PATCH] Document all nodes using the default EOG --- .../cpg/passes/EvaluationOrderGraphPass.kt | 56 ++++++++++++---- docs/docs/CPG/specs/eog.md | 65 +++++++++++++++++++ 2 files changed, 107 insertions(+), 14 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt index a0b2cc2b36..abac244c2d 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt @@ -178,13 +178,11 @@ open class EvaluationOrderGraphPass(ctx: TranslationContext) : TranslationUnitPa map[ConstructExpression::class.java] = { handleConstructExpression(it as ConstructExpression) } - map[EmptyStatement::class.java] = { - handleDefault(it as EmptyStatement) - } // TODO: Documentation missing - map[Literal::class.java] = { handleDefault(it) } // TODO: Documentation missing - map[DefaultStatement::class.java] = { handleDefault(it) } // TODO: Documentation missing - map[TypeIdExpression::class.java] = { handleDefault(it) } // TODO: Documentation missing - map[Reference::class.java] = { handleDefault(it) } // TODO: Documentation missing + map[EmptyStatement::class.java] = { handleEmptyStatement(it as EmptyStatement) } + map[Literal::class.java] = { handleLiteral(it as Literal<*>) } + map[DefaultStatement::class.java] = { handleDefaultStatement(it as DefaultStatement) } + map[TypeIdExpression::class.java] = { handleTypeIdExpression(it as TypeIdExpression) } + map[Reference::class.java] = { handleReference(it as Reference) } map[CollectionComprehension::class.java] = { handleCollectionComprehension(it as CollectionComprehension) } @@ -198,13 +196,6 @@ open class EvaluationOrderGraphPass(ctx: TranslationContext) : TranslationUnitPa map[ThrowStatement::class.java] = { handleThrowStatement(it as ThrowStatement) } } - /** - * See [Specification](https://fraunhofer-aisec.github.io/cpg/CPG/specs/eog/#includedeclaration) - */ - protected fun handleIncludeDeclaration() { - doNothing() - } - protected fun doNothing() { // Nothing to do for this node type } @@ -448,6 +439,43 @@ open class EvaluationOrderGraphPass(ctx: TranslationContext) : TranslationUnitPa attachToEOG(node) } + /** See [Specification](https://fraunhofer-aisec.github.io/cpg/CPG/specs/eog/#emptystatement) */ + private fun handleEmptyStatement(node: EmptyStatement) { + attachToEOG(node) + } + + /** See [Specification](https://fraunhofer-aisec.github.io/cpg/CPG/specs/eog/#emptystatement) */ + private fun handleLiteral(node: Literal<*>) { + attachToEOG(node) + } + + /** + * See [Specification](https://fraunhofer-aisec.github.io/cpg/CPG/specs/eog/#defaultstatement) + */ + private fun handleDefaultStatement(node: DefaultStatement) { + attachToEOG(node) + } + + /** + * See + * [Specification](https://fraunhofer-aisec.github.io/cpg/CPG/specs/eog/#handletypeidexpression) + */ + private fun handleTypeIdExpression(node: TypeIdExpression) { + attachToEOG(node) + } + + /** See [Specification](https://fraunhofer-aisec.github.io/cpg/CPG/specs/eog/#reference) */ + private fun handleReference(node: Reference) { + attachToEOG(node) + } + + /** + * See [Specification](https://fraunhofer-aisec.github.io/cpg/CPG/specs/eog/#includedeclaration) + */ + protected fun handleIncludeDeclaration() { + doNothing() + } + /** See [Specification](https://fraunhofer-aisec.github.io/cpg/CPG/specs/eog/#callexpression) */ protected fun handleCallExpression(node: CallExpression) { // Todo add call as throwexpression to outer scope of call can throw (which is trivial to diff --git a/docs/docs/CPG/specs/eog.md b/docs/docs/CPG/specs/eog.md index a4aa70a43b..b23e17e404 100644 --- a/docs/docs/CPG/specs/eog.md +++ b/docs/docs/CPG/specs/eog.md @@ -907,6 +907,71 @@ flowchart LR parent --EOG--> next:::outer ``` +## EmptyStatement +The statement itself is connected to the outer EOG. + +Interesting fields: / + +Scheme: +```mermaid +flowchart LR + classDef outer fill:#fff,stroke:#ddd,stroke-dasharray:5 5; + prev:::outer --EOG--> parent["EmptyStatement"] + parent --EOG--> next:::outer +``` + +## Literal +The statement itself is connected to the outer EOG. + +Interesting fields: / + +Scheme: +```mermaid +flowchart LR + classDef outer fill:#fff,stroke:#ddd,stroke-dasharray:5 5; + prev:::outer --EOG--> parent["Literal"] + parent --EOG--> next:::outer +``` + +## DefaultStatement +The statement itself is connected to the outer EOG. + +Interesting fields: / + +Scheme: +```mermaid +flowchart LR + classDef outer fill:#fff,stroke:#ddd,stroke-dasharray:5 5; + prev:::outer --EOG--> parent["DefaultStatement"] + parent --EOG--> next:::outer +``` + +## TypeIdExpression +The statement itself is connected to the outer EOG. + +Interesting fields: / + +Scheme: +```mermaid +flowchart LR + classDef outer fill:#fff,stroke:#ddd,stroke-dasharray:5 5; + prev:::outer --EOG--> parent["TypeIdExpression"] + parent --EOG--> next:::outer +``` + +## Reference +The statement itself is connected to the outer EOG. + +Interesting fields: / + +Scheme: +```mermaid +flowchart LR + classDef outer fill:#fff,stroke:#ddd,stroke-dasharray:5 5; + prev:::outer --EOG--> parent["Reference"] + parent --EOG--> next:::outer +``` + ## IncludeDeclaration The `IncludeDeclaration` is not connected to the EOG. We continue with the next statement.