GoExtraPass

This pass takes care of several things that we need to clean up, once all translation units are successfully parsed, but before any of the remaining CPG passes, such as call resolving occurs.

Add Type Listeners for Key/Value Variables in For-Each Statements

In Go, a common idiom is to use a short assignment in a for-each statement to declare a key and value object without explicitly specifying the type.

var bytes = []byte{1,2,3,4}
for key, value := range bytes {
// key is of type int; value of type byte
fmt.Printf("bytes[%d]=%d\n", key, value)
}

The key variable is always of type int, whereas the value variable depends on the iterated expression. Therefore, we set up type listeners based on the iterated object.

Infer NamespaceDeclarations for Import Packages

We want to infer namespace declarations for import packages, that are unknown to us. This allows us to then infer functions in those packages as well.

Declare Variables in Short Assignments

We want to implicitly declare variables in a short assignment. We cannot do this in the frontend itself, because some of the variables in the assignment might already exist, and those are not declared, but just assigned. Only the non-defined variables are declared by the short assignment.

The following short assignment (in the second line) only declares the variable b but assigns 1 to the already existing variable a and 2 to the new variable b.

var a int
a, b := 1, 2

In the frontend we only do the assignment, therefore we need to create a new VariableDeclaration for b and inject a DeclarationStatement.

Adjust Names of Keys in Key Value Expressions to FQN

This pass also adjusts the names of keys in a KeyValueExpression, which is part of an InitializerListExpression to a fully-qualified name that contains the name of the ObjectType that the expression is creating. This way we can resolve the static references to the field to the actual field.

Add Methods of Embedded Structs to the Record's Scope

This pass also adds methods of RecordDeclaration.embeddedStructs into the scope of the RecordDeclaration itself, so that it can be resolved using the regular SymbolResolver.

Constructors

Link copied to clipboard
constructor(ctx: TranslationContext)

Properties

Link copied to clipboard
Link copied to clipboard
override val ctx: TranslationContext
Link copied to clipboard
Link copied to clipboard
open override val scope: Scope?
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open override fun accept(component: Component)
Link copied to clipboard
Link copied to clipboard
open override fun cleanup()
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun toString(): String