Skip to content

Commit

Permalink
Update handler.go
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Mar 4, 2023
1 parent 1730f8b commit 017423a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
7 changes: 1 addition & 6 deletions cpg-language-go/src/main/golang/frontend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ func (this *GoLanguageFrontend) HandleFile(fset *token.FileSet, file *ast.File,
}
}

// create a built-in "go" function
goFunc := this.NewFunctionDeclaration(fset, nil, "go", "", true)
goFunc.AddParameter(this.NewParamVariableDeclaration(fset, nil, "call"))
scope.AddDeclaration((*cpg.Declaration)(goFunc))

// create a new namespace declaration, representing the package
p := this.NewNamespaceDeclaration(fset, nil, file.Name.Name)

Expand Down Expand Up @@ -762,7 +757,7 @@ func (this *GoLanguageFrontend) handleAssignStmt(fset *token.FileSet, assignStmt
var rhs = []*cpg.Expression{}
var lhs = []*cpg.Expression{}
for _, expr := range assignStmt.Lhs {
rhs = append(lhs, this.handleExpr(fset, expr))
lhs = append(lhs, this.handleExpr(fset, expr))
}

for _, expr := range assignStmt.Rhs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,16 @@ class GoLanguageFrontendTest : BaseTest() {
val body = myFunc.body as? CompoundStatement
assertNotNull(body)

val binOp = body.statements.first() as? BinaryOperator
assertNotNull(binOp)
val assign = body.statements.first() as? AssignExpression
assertNotNull(assign)

val lhs = binOp.lhs as? MemberExpression
val lhs = assign.lhs.firstOrNull() as? MemberExpression
assertNotNull(lhs)
assertEquals(myFunc.receiver, (lhs.base as? DeclaredReferenceExpression)?.refersTo)
assertLocalName("Field", lhs)
assertEquals(TypeParser.createFrom("int", GoLanguage()), lhs.type)

val rhs = binOp.rhs as? DeclaredReferenceExpression
val rhs = assign.rhs.firstOrNull() as? DeclaredReferenceExpression
assertNotNull(rhs)
assertFullName("otherPackage.OtherField", rhs)
}
Expand Down Expand Up @@ -766,8 +766,9 @@ class GoLanguageFrontendTest : BaseTest() {
val main = mainPackage.byNameOrNull<FunctionDeclaration>("main")
assertNotNull(main)

val binOp = main.bodyOrNull<BinaryOperator>()
assertNotNull(binOp)
val assign = main.bodyOrNull<AssignExpression>()
assertNotNull(assign)
assertEquals(1, assign.rhs.size)

assertNotNull(tu)
}
Expand Down

0 comments on commit 017423a

Please sign in to comment.