-
Notifications
You must be signed in to change notification settings - Fork 91
Add Rust language frontend leveraging Rust Analyzer internals for parsing and inference #2560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
konradweiss
wants to merge
97
commits into
main
Choose a base branch
from
feature/language-rust
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
97 commits
Select commit
Hold shift + click to select a range
f09150e
Adding Frontend to configurations and build general frontend structure
konradweiss 7530437
Cleanup of basic structure
konradweiss bd942b7
Fix Build
konradweiss 0ade67b
Adding builtin type names and operator overloading information to the…
konradweiss 31df1db
Add initial jna call example before reconsidering
konradweiss 367f04d
building uniffi with kotlin binding print_string
konradweiss 3c2c28a
Fixing problems in rust frontend generation
konradweiss 5cd4559
Add prebuild rustlibrary .so and kotlin bindings to the resources and…
konradweiss a5da5d0
rust export struct over ffi
konradweiss d4abc88
get source file file contents and call the parser
konradweiss 173bb48
Return Optional and try to explore binding wrappers
konradweiss 099a015
Restructure Ast node interfaces, add code location generation
konradweiss c99b2c4
More Enums and node wrappers
konradweiss 343503c
Add params and ret type to Fn
konradweiss 2879668
Binding stubs for parameters
konradweiss c310661
Dispatching structure for syntax node conversion structures
konradweiss 0d52331
Add Problem node and fix ast node retrieval
konradweiss 393370b
Adding Bloack expressions to functions
konradweiss eed0331
Handing through function body and let stmt components
konradweiss 7f6de57
Name and let rust boilerplate, whith an issue of my approach with wit…
konradweiss de68870
Solving the infinit size data structure with a vector of size 0 or 1.…
konradweiss e602d3c
Arglist conversion
konradweiss e8dee4d
Handing over binary expression
konradweiss 873b7e3
Macro Call and Expr
konradweiss e9359c6
Adding initial call and macro support
konradweiss 6588d03
Adding struct support for records and tuples
konradweiss 0a13484
Adding cargo build and bindings generation to the gradle build process
konradweiss 73f98a1
Making rust build and bindings generation work from gradle
konradweiss 06ad58b
Handing through declarations in impl block
konradweiss 8dfdc80
Adding implementation handler and partially implementing it; Correcti…
konradweiss 37ef377
Adding ExtensionDeclaration as a representative for the implementatio…
konradweiss aae7be9
Transport MethodCallExpression
konradweiss 46012ed
Adding MethodCallExpression handling in frontend. We may have to wrap…
konradweiss 3630ba6
MemberExpression as callee in a MemberCallExpression
konradweiss d36c0c1
Add Type transportation
konradweiss 2fccee4
Add Tuple type and other base types
konradweiss 12c3a02
Adding a return type to a function, parsing builtin types, and object…
konradweiss 492c09f
Removing some unneeded template code and adding translation of Prefix…
konradweiss fa2945c
Remove old rust lib that was ment to use Rustc
konradweiss ff4ed3e
Type and supertype addition of impl block
konradweiss eaa7968
Better messages in Problem nodes
konradweiss 342318b
Fixing some code ends and cast exception
konradweiss f5beae4
Handle Traits and Const
konradweiss 71b2a38
Add Const init expression
konradweiss c334f60
Fix Problem Expression
konradweiss 1c188a5
Allow Const du have empty init
konradweiss ea0b4ee
Merge branch 'main' into feature/language-rust
konradweiss 392093a
Add If Else support
konradweiss e41a793
Adding support for loop, while and for stmt
konradweiss 40e91a7
Add MemberAccess
konradweiss 2fac5c8
Adding support for break and continue, especially for breaks to have …
konradweiss 9eb11e6
Support Cast Expression
konradweiss 68e631c
SUpporting index expressions as subscript expression
konradweiss e961dd0
Handle Reference Expression as unary operator with & operation and fo…
konradweiss 75a515f
Merge branch 'main' into feature/language-rust
konradweiss be41b6c
Support Record Declaration and initializer based struct construction
konradweiss 01d92c5
Adjusting base of spread argument in recrod expression
konradweiss 030cd62
add tuple expression as initializer list
konradweiss ac9c8eb
Support Use expressions, flattening nested imports into a declaration…
konradweiss c374fc4
Fixing some keyword path issues for use, and fixes some paths for nam…
konradweiss 91d9224
Adding functional tests for use, where we do not test the creation of…
konradweiss 29bd3ef
Correct flag
konradweiss 313f680
Add first deconstruction draft, and handling of match
konradweiss b70ec7f
Correct code and location raw nodes for match and its subnodes. Imple…
konradweiss b40050f
Match version with Variables as bindings
konradweiss 3aa6156
Add declarations to scopes where missing. Support underscore expression
konradweiss 2b4fa8c
Merge branch 'main' of github.com:Fraunhofer-AISEC/cpg
konradweiss cac6288
Merge branch 'main' into feature/language-rust
konradweiss ccb0475
Allow break to have empty expression. Implement basic try that modell…
konradweiss 885d61a
Add Variants to union and generic params to all ast nodes in rust ast…
konradweiss 8a96c2b
Finish the raemaining rust wrapper between rust analyzer and UniFFI
konradweiss d3bd7c0
Merge branch 'main' into feature/language-rust
konradweiss 7d1bb9f
Add Let tests and adapt let expression
konradweiss b7f7a8f
Merge branch 'feature/language-rust' of github.com:Fraunhofer-AISEC/c…
konradweiss 0af6596
Addapt Let statement, add test for dfg edges based on literals
konradweiss ec5102c
Adding Closure and Enum support
konradweiss d7473ea
Fix issue in fro loop, implement structural test with few df asserts …
konradweiss ce36ff0
Merge branch 'main' into feature/language-rust
konradweiss 75e14f7
Add whitelisting file
konradweiss 035a9bd
Merge branch 'fix/allow-esbuild-scripts' into feature/language-rust
konradweiss e78ad83
Merge branch 'feature/language-rust' of github.com:Fraunhofer-AISEC/c…
konradweiss d73511b
Add test for alternative in match
konradweiss 2b4f755
df structures
konradweiss 1d9d104
Add more refined dfg granularities for deconstruction
konradweiss c5c3adc
Adapt gradle task
konradweiss 1e6f404
Correct package before library move
konradweiss 88817e1
Merge branch 'main' into feature/language-rust
konradweiss 5f5ac70
Using native lib from libast
konradweiss ade007a
Fixing Empty ParenExpression, and Empty expression is returned
konradweiss b006e57
Revert "Update dependency io.ktor.plugin to v3.5.0 (#2742)"
maximiliankaul c4f0ae4
Change the ktor dependency to API to allow usage in other projects
maximiliankaul fc22967
Change Ktor dependencies from api to implementation for non-CIO
maximiliankaul 13a73e1
Merge remote-tracking branch 'origin/restore-ktor-3.3.3' into feature…
konradweiss 6def724
Merge remote-tracking branch 'origin/ktor-api-dependency' into featur…
konradweiss 56ac5e6
Enable the Rust frontend in the example file
maximiliankaul 563ad0e
Ignoring tests temporarely for snapshot build
konradweiss 6b82528
Merge branch 'feature/language-rust' of github.com:Fraunhofer-AISEC/c…
konradweiss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/ExtensionDeclaration.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright (c) 2026, Fraunhofer AISEC. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| * $$$$$$\ $$$$$$$\ $$$$$$\ | ||
| * $$ __$$\ $$ __$$\ $$ __$$\ | ||
| * $$ / \__|$$ | $$ |$$ / \__| | ||
| * $$ | $$$$$$$ |$$ |$$$$\ | ||
| * $$ | $$ ____/ $$ |\_$$ | | ||
| * $$ | $$\ $$ | $$ | $$ | | ||
| * \$$$$$ |$$ | \$$$$$ | | ||
| * \______/ \__| \______/ | ||
| * | ||
| */ | ||
| package de.fraunhofer.aisec.cpg.graph.declarations | ||
|
|
||
| import de.fraunhofer.aisec.cpg.graph.DeclarationHolder | ||
| import de.fraunhofer.aisec.cpg.graph.Node | ||
| import de.fraunhofer.aisec.cpg.graph.edges.ast.astEdgesOf | ||
| import de.fraunhofer.aisec.cpg.graph.edges.unwrapping | ||
| import java.util.Objects | ||
|
|
||
| /** | ||
| * Children in this declaration are added to an existing node with namespace. This can be a Record, | ||
| * or another similar construct that contains declarations. The children are therefore in this ast | ||
| * construct but are added to the symbol table of the construct it is extending. | ||
| * | ||
| * The name that this extension has needs to identify the construct, it is extending | ||
| */ | ||
| class ExtensionDeclaration : Declaration(), DeclarationHolder { | ||
| /** | ||
| * Edges to nested namespaces, records, functions, fields etc. contained in the current | ||
| * namespace. | ||
| */ | ||
| val declarationEdges = astEdgesOf<Declaration>() | ||
| override val declarations by unwrapping(ExtensionDeclaration::declarationEdges) | ||
|
|
||
| /** | ||
| * In some languages, there is a relationship between paths / directories and the package | ||
| * structure. Therefore, we need to be aware of the path this namespace / package is in. | ||
| */ | ||
| var path: String? = null | ||
|
|
||
| override fun equals(other: Any?): Boolean { | ||
| if (this === other) return true | ||
| if (other !is ExtensionDeclaration) return false | ||
| return super.equals(other) && declarations == other.declarations | ||
| } | ||
|
|
||
| override fun hashCode() = Objects.hash(super.hashCode(), declarations) | ||
|
|
||
| override fun addDeclaration(declaration: Declaration) { | ||
| addIfNotContains(declarations, declaration) | ||
| } | ||
|
|
||
| override fun getStartingPrevEOG(): Collection<Node> { | ||
| return setOf() | ||
| } | ||
|
|
||
| override fun getExitNextEOG(): Collection<Node> { | ||
| return setOf() | ||
| } | ||
| } | ||
81 changes: 81 additions & 0 deletions
81
...re/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/expressions/AlternativeDeconstruction.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Copyright (c) 2026, Fraunhofer AISEC. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| * $$$$$$\ $$$$$$$\ $$$$$$\ | ||
| * $$ __$$\ $$ __$$\ $$ __$$\ | ||
| * $$ / \__|$$ | $$ |$$ / \__| | ||
| * $$ | $$$$$$$ |$$ |$$$$\ | ||
| * $$ | $$ ____/ $$ |\_$$ | | ||
| * $$ | $$\ $$ | $$ | $$ | | ||
| * \$$$$$ |$$ | \$$$$$ | | ||
| * \______/ \__| \______/ | ||
| * | ||
| */ | ||
| package de.fraunhofer.aisec.cpg.graph.expressions | ||
|
|
||
| import de.fraunhofer.aisec.cpg.graph.ArgumentHolder | ||
| import de.fraunhofer.aisec.cpg.graph.edges.ast.astEdgesOf | ||
| import de.fraunhofer.aisec.cpg.graph.edges.unwrapping | ||
| import de.fraunhofer.aisec.cpg.graph.types.HasType | ||
| import de.fraunhofer.aisec.cpg.graph.types.Type | ||
| import de.fraunhofer.aisec.cpg.persistence.Relationship | ||
| import java.util.Objects | ||
| import kotlin.collections.plusAssign | ||
|
|
||
| class AlternativeDeconstruction : Deconstruction(), ArgumentHolder, HasType.TypeObserver { | ||
|
|
||
| @Relationship("ALTERNATIVES") var alternativeEdges = astEdgesOf<Expression>() | ||
| var alternatives by unwrapping(AlternativeDeconstruction::alternativeEdges) | ||
|
|
||
| override fun equals(other: Any?): Boolean { | ||
| if (this === other) return true | ||
| if (other !is AlternativeDeconstruction) return false | ||
| return super.equals(other) && alternatives == other.alternatives | ||
| } | ||
|
|
||
| override fun hashCode() = Objects.hash(super.hashCode(), alternatives) | ||
|
|
||
| override fun addArgument(expression: Expression) { | ||
| this.alternatives += expression | ||
| expression.access = this.access | ||
| } | ||
|
|
||
| override fun replaceArgument(old: Expression, new: Expression): Boolean { | ||
| val idx = alternativeEdges.indexOfFirst { it.end == old } | ||
| if (idx != -1) { | ||
| old.unregisterTypeObserver(this) | ||
| alternativeEdges[idx].end = new | ||
| new.registerTypeObserver(this) | ||
| new.access = this.access | ||
| return true | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| override fun hasArgument(expression: Expression): Boolean { | ||
| return expression in this.alternatives | ||
| } | ||
|
|
||
| override fun typeChanged(newType: Type, src: HasType) { | ||
| val type = type | ||
| typeObservers.forEach { it.typeChanged(type, this) } | ||
| } | ||
|
|
||
| override fun assignedTypeChanged(assignedTypes: Set<Type>, src: HasType) { | ||
| addAssignedTypes(assignedTypes) | ||
| typeObservers.forEach { it.assignedTypeChanged(assignedTypes, this) } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/expressions/Deconstruction.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright (c) 2026, Fraunhofer AISEC. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| * $$$$$$\ $$$$$$$\ $$$$$$\ | ||
| * $$ __$$\ $$ __$$\ $$ __$$\ | ||
| * $$ / \__|$$ | $$ |$$ / \__| | ||
| * $$ | $$$$$$$ |$$ |$$$$\ | ||
| * $$ | $$ ____/ $$ |\_$$ | | ||
| * $$ | $$\ $$ | $$ | $$ | | ||
| * \$$$$$ |$$ | \$$$$$ | | ||
| * \______/ \__| \______/ | ||
| * | ||
| */ | ||
| package de.fraunhofer.aisec.cpg.graph.expressions | ||
|
|
||
| abstract class Deconstruction : Expression() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.