-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,46 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
// Declaring multiple variables in a block with initializer. This is one | ||
// GenDecl with two ValueSpec specs and one "Name" and (initializer) "Value" | ||
// each. | ||
// | ||
// We translate this into one DeclarationStatement with two | ||
// VariableDeclaration nodes | ||
var ( | ||
a int = 1 | ||
b int = 2 | ||
) | ||
|
||
// Declaring multiple variables in a single line. This is one GenDecl with | ||
// one ValueSpec spec which contains two "Names" and two "Values" which | ||
// correspond to the respective initializer values. Note, that the number of | ||
// values MUST match the number of names | ||
// | ||
// We translate this into one DeclarationStatement with two | ||
// VariableDeclaration nodes | ||
var c, d = 3, 4 | ||
|
||
// Short assignment using an assignment, where all variables were not | ||
// defined before. This is an AssignStmt which has DEFINE as its token. | ||
// | ||
// We need to split this up into several nodes. First, we translate this | ||
// into one (implicit) DeclarationStatement with two VariableDeclaration | ||
// nodes. Afterwards we are parsing it as a regular assignment. | ||
e, f := 5, 6 | ||
|
||
// Short assignment using an assignment, where one variable (f) was defined | ||
// before in the local scope. This is an AssignStmt which has DEFINE as its | ||
// token. From the AST we cannot differentiate this from the previous | ||
// example and we need to do a (local) variable lookup here. | ||
// | ||
// Finally, We need to split this up into several nodes. First, we translate | ||
// this into one (implicit) DeclarationStatement with one | ||
// VariableDeclaration node. Afterwards we are parsing it as a regular | ||
// assignment. | ||
f, g := 7, 8 | ||
|
||
fmt.Printf("%d %d %d %d %d %d %d\n", a, b, c, d, e, f, g) | ||
} |
This file contains 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,21 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
var a = []int{1,2,3} | ||
|
||
// [1] | ||
var b = a[:1] | ||
|
||
// [2, 3] | ||
var c = a[1:] | ||
|
||
// [1] | ||
var d = a[0:1] | ||
|
||
// [1] | ||
var e = a[0:1:1] | ||
|
||
fmt.Printf("%v %v %v %v %v", a, b, c, d, e) | ||
} |
8 changes: 8 additions & 0 deletions
8
cpg-language-go/src/test/resources/golang/type_constraints.go
This file contains 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,8 @@ | ||
package main | ||
|
||
type MyStruct[T any] {} | ||
type MyInterface{} | ||
|
||
func main() { | ||
_ := &MyStruct[MyInterface]{} | ||
} |