Skip to content

Commit

Permalink
Fix style of docs (#1504)
Browse files Browse the repository at this point in the history
* Fix style of docs

* Clean DFG spec a bit

* re-generate graph schema with minor style updates
  • Loading branch information
KuechA authored and maximiliankaul committed Apr 17, 2024
1 parent a13a482 commit 317415b
Show file tree
Hide file tree
Showing 16 changed files with 2,969 additions and 2,756 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class ConstructExpression : CallExpression() {
@PopulatedByPass(SymbolResolver::class)
var constructor: ConstructorDeclaration? = null
get() =
if (anoymousClass != null) {
anoymousClass?.constructors?.firstOrNull()
if (anonymousClass != null) {
anonymousClass?.constructors?.firstOrNull()
} else {
field
}
Expand All @@ -62,14 +62,14 @@ class ConstructExpression : CallExpression() {
}
}

@AST var anoymousClass: RecordDeclaration? = null
@AST var anonymousClass: RecordDeclaration? = null

/** The [Declaration] of the type this expression instantiates. */
@PopulatedByPass(SymbolResolver::class)
var instantiates: Declaration? = null
get() =
if (anoymousClass != null) {
anoymousClass
if (anonymousClass != null) {
anonymousClass
} else {
field
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ open class EvaluationOrderGraphPass(ctx: TranslationContext) : TranslationUnitPa
}
pushToEOG(node)

if (node.anoymousClass != null) {
if (node.anonymousClass != null) {
// Generate the EOG inside the anonymous class. It's not linked to the EOG of the outer
// part.
val tmpCurrentEOG = currentPredecessors.toMutableList()
Expand All @@ -750,7 +750,7 @@ open class EvaluationOrderGraphPass(ctx: TranslationContext) : TranslationUnitPa
currentPredecessors.clear()
intermediateNodes.clear()

createEOG(node.anoymousClass)
createEOG(node.anonymousClass)

nextEdgeProperties.clear()
currentPredecessors.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ class ExpressionHandler(lang: JavaLanguageFrontend) :
)
}
anonymousRecord.addConstructor(constructorDeclaration)
ctor.anoymousClass = anonymousRecord
ctor.anonymousClass = anonymousRecord

frontend.scopeManager.addDeclaration(constructorDeclaration)
frontend.scopeManager.leaveScope(anonymousRecord)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ class Schema {
}

if (inheritedRels[entityLabel]?.isNotEmpty() == true) {
out.println("<details markdown><summary>Inherited Relationships</summary>")
out.println("<div class=\"papers\" markdown>")
out.println("??? info \"Inherited Relationships\"")
out.println()
removeLabelDuplicates(inheritedRels[entityLabel])?.forEach { inherited ->
var current = classInfo
Expand All @@ -379,14 +380,15 @@ class Schema {
}
hierarchy[current]?.first?.let { current = it }
}
out.print(" ")
out.println(
getBoxWithClass(
"inherited-relationship",
"[${inherited.second}](#${toConcatName(toLabel(baseClass) + inherited.second)})"
)
)
}
out.println("</details>")
out.println("</div>")
out.println()
}

Expand All @@ -403,12 +405,13 @@ class Schema {
out.println()
}
if (inheritedProperties[entityLabel]?.isNotEmpty() == true) {
out.println("<details markdown><summary>Inherited Properties</summary>")
out.println("<div class=\"papers\" markdown>")
out.println("??? info \"Inherited Properties\"")
removeLabelDuplicates(inheritedProperties[entityLabel])?.forEach {
out.println("${it.second} : ${it.first}")
out.println(" ${it.second} : ${it.first}")
out.println()
}
out.println("</details>")
out.println("</div>")
out.println()
}
}
Expand Down
8 changes: 5 additions & 3 deletions docs/docs/CPG/impl/passes.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ constructs have to be respected.

For example, the `EvaluationOrderGraphPass` uses an internal handle structure.
When extending this pass, it is necessary to add handlers of new Node types to
the internal handler map. If a developer needs to override an exisiting handler,
the internal handler map. If a developer needs to override an existing handler,
the handle has to be implemented with the same signature to use the polymorphism
feature. Additionally the mapping of `node type -> handler` needs to be replaced
feature. Additionally, the mapping of `node type -> handler` needs to be replaced
by a new entry `node type -> overridden` handler.

## Ordering Passes
Expand All @@ -66,4 +66,6 @@ following annotations for the passes:
* `ExecuteLast` -- The annotated pass is executed as the last pass if possible.
* `RequiredFrontend(frontend: KClass<out LanguageFrontend>)` -- The annotated pass
is only executed if the frontend has been used.

* `RequiresLanguageTrait(trait: KClass<out LanguageTrait>)` -- The annotated pass
is only executed if the `language` of the `TranslationUnit` which is currently studied
implements the given `trait`.
148 changes: 74 additions & 74 deletions docs/docs/CPG/specs/dfg-function-summaries.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Specification: Data Flow Graph - Function Summaries

For functions and methods which are part of the analyzed codebase, the CPG can track data flows interprocedurally to some extent.
For functions and methods which are part of the analyzed codebase, the CPG can track data flows inter-procedurally to some extent.
However, for all functions and methods which cannot be analyzed, we have no information available.
For this case, we provide the user a way to specify custom summaries of the data flows through the function.
To do so, you need to fill a JSON or YAML file as follows:
Expand All @@ -27,84 +27,84 @@ An example of a file could look as follows:

=== "JSON"

```json
[
{
"functionDeclaration": {
"language": "de.fraunhofer.aisec.cpg.frontends.java.JavaLanguage",
"methodName": "java.util.List.addAll",
"signature": ["int", "java.util.Object"]
```json
[
{
"functionDeclaration": {
"language": "de.fraunhofer.aisec.cpg.frontends.java.JavaLanguage",
"methodName": "java.util.List.addAll",
"signature": ["int", "java.util.Object"]
},
"dataFlows": [
{
"from": "param1",
"to": "base",
"dfgType": "full"
}
]
},
"dataFlows": [
{
"from": "param1",
"to": "base",
"dfgType": "full"
}
]
},
{
"functionDeclaration": {
"language": "de.fraunhofer.aisec.cpg.frontends.java.JavaLanguage",
"methodName": "java.util.List.addAll",
"signature": ["java.util.Object"]
{
"functionDeclaration": {
"language": "de.fraunhofer.aisec.cpg.frontends.java.JavaLanguage",
"methodName": "java.util.List.addAll",
"signature": ["java.util.Object"]
},
"dataFlows": [
{
"from": "param0",
"to": "base",
"dfgType": "full"
}
]
},
"dataFlows": [
{
"from": "param0",
"to": "base",
"dfgType": "full"
}
]
},
{
"functionDeclaration": {
"language": "de.fraunhofer.aisec.cpg.frontends.cxx.CLanguage",
"methodName": "memcpy"
},
"dataFlows": [
{
"from": "param1",
"to": "param0",
"dfgType": "full"
}
]
}
]
```
{
"functionDeclaration": {
"language": "de.fraunhofer.aisec.cpg.frontends.cxx.CLanguage",
"methodName": "memcpy"
},
"dataFlows": [
{
"from": "param1",
"to": "param0",
"dfgType": "full"
}
]
}
]
```

=== "YAML"

```yml
- functionDeclaration:
language: de.fraunhofer.aisec.cpg.frontends.java.JavaLanguage
methodName: java.util.List.addAll
signature:
- int
- java.util.Object
dataFlows:
- from: param1
to: base
dfgType: full

- functionDeclaration:
language: de.fraunhofer.aisec.cpg.frontends.java.JavaLanguage
methodName: java.util.List.addAll
signature:
- java.util.Object
dataFlows:
- from: param0
to: base
dfgType: full

- functionDeclaration:
language: de.fraunhofer.aisec.cpg.frontends.cxx.CLanguage
methodName: memcpy
dataFlows:
- from: param1
to: param0
dfgType: full
```
```yaml
- functionDeclaration:
language: de.fraunhofer.aisec.cpg.frontends.java.JavaLanguage
methodName: java.util.List.addAll
signature:
- int
- java.util.Object
dataFlows:
- from: param1
to: base
dfgType: full
- functionDeclaration:
language: de.fraunhofer.aisec.cpg.frontends.java.JavaLanguage
methodName: java.util.List.addAll
signature:
- java.util.Object
dataFlows:
- from: param0
to: base
dfgType: full
- functionDeclaration:
language: de.fraunhofer.aisec.cpg.frontends.cxx.CLanguage
methodName: memcpy
dataFlows:
- from: param1
to: param0
dfgType: full
```

This file configures the following edges:

Expand Down
Loading

0 comments on commit 317415b

Please sign in to comment.