Skip to content

Commit

Permalink
Added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Dec 14, 2024
1 parent 10b3a9a commit a02c921
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ class ImportDeclaration : Declaration() {
var importedSymbols: SymbolMap = mutableMapOf()
}

/**
* This property determines if a given name represents an import declaration within the context of a
* [Pass].
*
* The resolution is performed by looking up the current scope's symbols to find matching
* [ImportDeclaration] instances for the name's [Name.localName]. If such instances are found, the
* property evaluates to `true`, indicating the name is an import declaration. Otherwise, it
* evaluates to `false`. The lookup does not replace imports during the resolution process.
*
* This property operates within the contextual scope provided by the associated [Pass].
*/
context(Pass<*>)
val Name.isImport: Boolean
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ import de.fraunhofer.aisec.cpg.passes.configuration.DependsOn
import de.fraunhofer.aisec.cpg.passes.configuration.ExecuteBefore
import de.fraunhofer.aisec.cpg.passes.configuration.RequiresLanguageTrait

/**
* A translation unit pass that resolves ambiguities in member expressions within a translation unit.
* This pass checks whether the base or member name in a member expression refers to an import and,
* if so, replaces the member expression with a reference using the fully qualified name.
*
* This pass is dependent on the [ImportResolver] pass and requires the language trait [HasCallExpressionAmbiguity].
* It is executed before the [EvaluationOrderGraphPass].
*
* @constructor Initializes the pass with the provided translation context.
*/
@ExecuteBefore(EvaluationOrderGraphPass::class)
@DependsOn(ImportResolver::class)
@RequiresLanguageTrait(HasCallExpressionAmbiguity::class)
Expand All @@ -58,6 +68,13 @@ class ResolveMemberExpressionAmbiguityPass(ctx: TranslationContext) : Translatio
walker.iterate(tu)
}

/**
* Resolves ambiguities in a given member expression. Checks whether the base or member name of
* the member expression refers to an import, and if so, replaces the member expression with a
* reference that uses the fully qualified name.
*
* @param me The member expression to disambiguate and potentially replace.
*/
private fun resolveAmbiguity(me: MemberExpression) {
// We need to check, if our "base" (or our expression) is really a name that refers to an
// import, because in this case we do not have a member expression, but a reference with a
Expand Down

0 comments on commit a02c921

Please sign in to comment.