Skip to content

Commit

Permalink
Upgrading go-jni library to newer version (#887)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Aug 30, 2022
1 parent d0a69fe commit cd43943
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 88 deletions.
29 changes: 17 additions & 12 deletions cpg-language-go/src/main/golang/declarations.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ func (f *FunctionDeclaration) SetType(t *Type) {
}

func (f *FunctionDeclaration) AddParameter(p *ParamVariableDeclaration) {
(*jnigi.ObjectRef)(f).CallMethod(env, "addParameter", jnigi.Void, (*jnigi.ObjectRef)(p))
(*jnigi.ObjectRef)(f).CallMethod(env, "addParameter", nil, (*jnigi.ObjectRef)(p))
}

func (f *FunctionDeclaration) SetBody(s *Statement) (err error) {
_, err = (*jnigi.ObjectRef)(f).CallMethod(env, "setBody", jnigi.Void, (*jnigi.ObjectRef)(s).Cast("de/fraunhofer/aisec/cpg/graph/statements/Statement"))
err = (*jnigi.ObjectRef)(f).CallMethod(env, "setBody", nil, (*jnigi.ObjectRef)(s).Cast("de/fraunhofer/aisec/cpg/graph/statements/Statement"))

return
}
Expand All @@ -88,14 +88,15 @@ func (m *MethodDeclaration) SetReceiver(v *VariableDeclaration) error {
}

func (m *MethodDeclaration) GetReceiver() *VariableDeclaration {
o, err := (*jnigi.ObjectRef)(m).GetField(env, "receiver", jnigi.ObjectType("de/fraunhofer/aisec/cpg/graph/declarations/VariableDeclaration"))
o := jnigi.NewObjectRef("de/fraunhofer/aisec/cpg/graph/declarations/VariableDeclaration")
err := (*jnigi.ObjectRef)(m).GetField(env, "receiver", o)

if err != nil {
log.Fatal(err)
debug.PrintStack()
}

return (*VariableDeclaration)(o.(*jnigi.ObjectRef))
return (*VariableDeclaration)(o)
}

func (p *ParamVariableDeclaration) SetType(t *Type) {
Expand Down Expand Up @@ -127,7 +128,7 @@ func (v *VariableDeclaration) IsNil() bool {
}

func (v *VariableDeclaration) SetInitializer(e *Expression) (err error) {
_, err = (*jnigi.ObjectRef)(v).CallMethod(env, "setInitializer", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
err = (*jnigi.ObjectRef)(v).CallMethod(env, "setInitializer", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))

return
}
Expand All @@ -137,13 +138,14 @@ func (v *VariableDeclaration) Declaration() *Declaration {
}

func (t *TranslationUnitDeclaration) GetIncludeByName(s string) *IncludeDeclaration {
i, err := (*jnigi.ObjectRef)(t).CallMethod(env, "getIncludeByName", jnigi.ObjectType("de/fraunhofer/aisec/cpg/graph/declarations/IncludeDeclaration"), NewString(s))
var i = jnigi.NewObjectRef("de/fraunhofer/aisec/cpg/graph/declarations/IncludeDeclaration")
err := (*jnigi.ObjectRef)(t).CallMethod(env, "getIncludeByName", i, NewString(s))
if err != nil {
log.Fatal(err)
debug.PrintStack()
}

return (*IncludeDeclaration)(i.(*jnigi.ObjectRef))
return (*IncludeDeclaration)(i)
}

func (r *RecordDeclaration) SetName(s string) error {
Expand All @@ -155,7 +157,7 @@ func (r *RecordDeclaration) SetKind(s string) error {
}

func (r *RecordDeclaration) AddMethod(m *MethodDeclaration) (err error) {
_, err = (*jnigi.ObjectRef)(r).CallMethod(env, "addMethod", jnigi.Void, (*jnigi.ObjectRef)(m))
err = (*jnigi.ObjectRef)(r).CallMethod(env, "addMethod", nil, (*jnigi.ObjectRef)(m))

return
}
Expand All @@ -177,23 +179,26 @@ func (c *CaseStatement) SetCaseExpression(e *Expression) error {
}

func NewTranslationUnitDeclaration(fset *token.FileSet, astNode ast.Node, name string, code string) *TranslationUnitDeclaration {
o, err := env.CallStaticMethod("de/fraunhofer/aisec/cpg/graph/NodeBuilder", "newTranslationUnitDeclaration", jnigi.ObjectType("de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration"), NewString(name), NewString(code))
tu := jnigi.NewObjectRef("de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration")

err := env.CallStaticMethod("de/fraunhofer/aisec/cpg/graph/NodeBuilder", "newTranslationUnitDeclaration", tu, NewString(name), NewString(code))
if err != nil {
log.Fatal(err)
debug.PrintStack()
}

return (*TranslationUnitDeclaration)(o.(*jnigi.ObjectRef))
return (*TranslationUnitDeclaration)(tu)
}

func NewNamespaceDeclaration(fset *token.FileSet, astNode ast.Node, name string, code string) *NamespaceDeclaration {
o, err := env.CallStaticMethod("de/fraunhofer/aisec/cpg/graph/NodeBuilder", "newNamespaceDeclaration", jnigi.ObjectType("de/fraunhofer/aisec/cpg/graph/declarations/NamespaceDeclaration"), NewString(name), NewString(code))
var o = jnigi.NewObjectRef("de/fraunhofer/aisec/cpg/graph/declarations/NamespaceDeclaration")
err := env.CallStaticMethod("de/fraunhofer/aisec/cpg/graph/NodeBuilder", "newNamespaceDeclaration", o, NewString(name), NewString(code))
if err != nil {
log.Fatal(err)
debug.PrintStack()
}

return (*NamespaceDeclaration)(o.(*jnigi.ObjectRef))
return (*NamespaceDeclaration)(o)
}

func NewIncludeDeclaration(fset *token.FileSet, astNode ast.Node) *IncludeDeclaration {
Expand Down
47 changes: 31 additions & 16 deletions cpg-language-go/src/main/golang/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ import (
)

type Expression Statement

func (e *Expression) ConvertToGo(o *jnigi.ObjectRef) error {
*e = (Expression)(*o)
return nil
}

func (e *Expression) GetClassName() string {
return "de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"
}

func (e *Expression) IsArray() bool {
return false
}

type CallExpression Expression
type NewExpression Expression
type ArrayCreationExpression Expression
Expand Down Expand Up @@ -254,12 +268,13 @@ func (m *MemberExpression) SetBase(e *Expression) {
}

func (m *MemberExpression) GetBase() *Expression {
i, err := (*jnigi.ObjectRef)(m).GetField(env, "base", jnigi.ObjectType("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
var expr Expression
err := (*jnigi.ObjectRef)(m).GetField(env, "base", &expr)
if err != nil {
log.Fatal(err)
}

return (*Expression)(i.(*jnigi.ObjectRef))
return &expr
}

func (e *Expression) GetName() string {
Expand All @@ -275,23 +290,23 @@ func (r *DeclaredReferenceExpression) Node() *Node {
}

func (c *CallExpression) AddArgument(e *Expression) {
(*jnigi.ObjectRef)(c).CallMethod(env, "addArgument", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
(*jnigi.ObjectRef)(c).CallMethod(env, "addArgument", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
}

func (b *BinaryOperator) SetLHS(e *Expression) {
(*jnigi.ObjectRef)(b).CallMethod(env, "setLhs", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
(*jnigi.ObjectRef)(b).CallMethod(env, "setLhs", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
}

func (b *BinaryOperator) SetRHS(e *Expression) {
(*jnigi.ObjectRef)(b).CallMethod(env, "setRhs", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
(*jnigi.ObjectRef)(b).CallMethod(env, "setRhs", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
}

func (b *BinaryOperator) SetOperatorCode(s string) (err error) {
return (*jnigi.ObjectRef)(b).SetField(env, "operatorCode", NewString(s))
}

func (u *UnaryOperator) SetInput(e *Expression) {
(*jnigi.ObjectRef)(u).CallMethod(env, "setInput", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
(*jnigi.ObjectRef)(u).CallMethod(env, "setInput", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
}

func (u *UnaryOperator) SetOperatorCode(s string) (err error) {
Expand Down Expand Up @@ -320,43 +335,43 @@ func (r *DeclaredReferenceExpression) SetName(s string) {
}

func (r *DeclaredReferenceExpression) SetRefersTo(d *Declaration) {
(*jnigi.ObjectRef)(r).CallMethod(env, "setRefersTo", jnigi.Void, (*jnigi.ObjectRef)(d).Cast("de/fraunhofer/aisec/cpg/graph/declarations/Declaration"))
(*jnigi.ObjectRef)(r).CallMethod(env, "setRefersTo", nil, (*jnigi.ObjectRef)(d).Cast("de/fraunhofer/aisec/cpg/graph/declarations/Declaration"))
}

func (r *ArrayCreationExpression) AddDimension(e *Expression) {
(*jnigi.ObjectRef)(r).CallMethod(env, "addDimension", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
(*jnigi.ObjectRef)(r).CallMethod(env, "addDimension", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
}

func (r *ArraySubscriptionExpression) SetArrayExpression(e *Expression) {
(*jnigi.ObjectRef)(r).CallMethod(env, "setArrayExpression", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
(*jnigi.ObjectRef)(r).CallMethod(env, "setArrayExpression", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
}

func (r *ArraySubscriptionExpression) SetSubscriptExpression(e *Expression) {
(*jnigi.ObjectRef)(r).CallMethod(env, "setSubscriptExpression", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
(*jnigi.ObjectRef)(r).CallMethod(env, "setSubscriptExpression", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
}

func (c *ConstructExpression) AddArgument(e *Expression) {
(*jnigi.ObjectRef)(c).CallMethod(env, "addArgument", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
(*jnigi.ObjectRef)(c).CallMethod(env, "addArgument", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
}

func (c *ConstructExpression) AddPrevDFG(n *Node) {
(*jnigi.ObjectRef)(c).CallMethod(env, "addPrevDFG", jnigi.Void, (*jnigi.ObjectRef)(n).Cast("de/fraunhofer/aisec/cpg/graph/Node"))
(*jnigi.ObjectRef)(c).CallMethod(env, "addPrevDFG", nil, (*jnigi.ObjectRef)(n).Cast("de/fraunhofer/aisec/cpg/graph/Node"))
}

func (n *NewExpression) SetInitializer(e *Expression) (err error) {
_, err = (*jnigi.ObjectRef)(n).CallMethod(env, "setInitializer", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
err = (*jnigi.ObjectRef)(n).CallMethod(env, "setInitializer", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))

return
}

func (c *InitializerListExpression) AddInitializer(e *Expression) {
(*jnigi.ObjectRef)(c).CallMethod(env, "addInitializer", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
(*jnigi.ObjectRef)(c).CallMethod(env, "addInitializer", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
}

func (k *KeyValueExpression) SetKey(e *Expression) {
(*jnigi.ObjectRef)(k).CallMethod(env, "setKey", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
(*jnigi.ObjectRef)(k).CallMethod(env, "setKey", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
}

func (k *KeyValueExpression) SetValue(e *Expression) {
(*jnigi.ObjectRef)(k).CallMethod(env, "setValue", jnigi.Void, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
(*jnigi.ObjectRef)(k).CallMethod(env, "setValue", nil, (*jnigi.ObjectRef)(e).Cast("de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"))
}
25 changes: 11 additions & 14 deletions cpg-language-go/src/main/golang/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ func (g *GoLanguageFrontend) SetCurrentTU(tu *cpg.TranslationUnitDeclaration) {
}

func (g *GoLanguageFrontend) GetCurrentTU() *cpg.TranslationUnitDeclaration {
i, err := g.GetField(env, "currentTU", jnigi.ObjectType("de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration"))
var tu = jnigi.NewObjectRef("de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration")
err := g.GetField(env, "currentTU", tu)
if err != nil {
log.Fatal(err)
}

return (*cpg.TranslationUnitDeclaration)(i.(*jnigi.ObjectRef))
return (*cpg.TranslationUnitDeclaration)(tu)
}

func (g *GoLanguageFrontend) GetCodeFromRawNode(fset *token.FileSet, astNode ast.Node) string {
Expand All @@ -76,22 +77,18 @@ func (g *GoLanguageFrontend) GetCodeFromRawNode(fset *token.FileSet, astNode ast
}

func (g *GoLanguageFrontend) GetScopeManager() *cpg.ScopeManager {
scope, err := g.GetField(env, "scopeManager", jnigi.ObjectType("de/fraunhofer/aisec/cpg/passes/scopes/ScopeManager"))

var scope = jnigi.NewObjectRef("de/fraunhofer/aisec/cpg/passes/scopes/ScopeManager")
err := g.GetField(env, "scopeManager", scope)
if err != nil {
log.Fatal(err)

}

return (*cpg.ScopeManager)(scope.(*jnigi.ObjectRef))
return (*cpg.ScopeManager)(scope)
}

func (g *GoLanguageFrontend) getLog() (logger *jnigi.ObjectRef, err error) {
var ref interface{}

ref, err = env.GetStaticField("de/fraunhofer/aisec/cpg/frontends/LanguageFrontend", "log", jnigi.ObjectType("org/slf4j/Logger"))

logger = ref.(*jnigi.ObjectRef)
logger = jnigi.NewObjectRef("org/slf4j/Logger")
err = env.GetStaticField("de/fraunhofer/aisec/cpg/frontends/LanguageFrontend", "log", logger)

return
}
Expand All @@ -103,7 +100,7 @@ func (g *GoLanguageFrontend) LogInfo(format string, args ...interface{}) (err er
return
}

_, err = logger.CallMethod(env, "info", jnigi.Void, cpg.NewString(fmt.Sprintf(format, args...)))
err = logger.CallMethod(env, "info", nil, cpg.NewString(fmt.Sprintf(format, args...)))

return
}
Expand All @@ -115,7 +112,7 @@ func (g *GoLanguageFrontend) LogDebug(format string, args ...interface{}) (err e
return
}

_, err = logger.CallMethod(env, "debug", jnigi.Void, cpg.NewString(fmt.Sprintf(format, args...)))
err = logger.CallMethod(env, "debug", nil, cpg.NewString(fmt.Sprintf(format, args...)))

return
}
Expand All @@ -127,7 +124,7 @@ func (g *GoLanguageFrontend) LogError(format string, args ...interface{}) (err e
return
}

_, err = logger.CallMethod(env, "error", jnigi.Void, cpg.NewString(fmt.Sprintf(format, args...)))
err = logger.CallMethod(env, "error", nil, cpg.NewString(fmt.Sprintf(format, args...)))

return
}
15 changes: 9 additions & 6 deletions cpg-language-go/src/main/golang/frontend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,12 +890,13 @@ func (this *GoLanguageFrontend) handleNewExpr(fset *token.FileSet, callExpr *ast
t := this.handleType(callExpr.Args[0])

// new is a pointer, so need to reference the type with a pointer
pointer, err := env.GetStaticField("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin", "POINTER", jnigi.ObjectType("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin"))
var pointer = jnigi.NewObjectRef("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin")
err := env.GetStaticField("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin", "POINTER", pointer)
if err != nil {
log.Fatal(err)
}

(*cpg.HasType)(n).SetType(t.Reference(pointer.(*jnigi.ObjectRef)))
(*cpg.HasType)(n).SetType(t.Reference(pointer))

// a new expression also needs an initializer, which is usually a constructexpression
c := cpg.NewConstructExpression(fset, callExpr)
Expand Down Expand Up @@ -1161,25 +1162,27 @@ func (this *GoLanguageFrontend) handleType(typeExpr ast.Expr) *cpg.Type {
case *ast.StarExpr:
t := this.handleType(v.X)

i, err := env.GetStaticField("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin", "POINTER", jnigi.ObjectType("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin"))
var i = jnigi.NewObjectRef("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin")
err := env.GetStaticField("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin", "POINTER", i)
if err != nil {
log.Fatal(err)
}

this.LogDebug("Pointer to %s", (*cpg.Node)(t).GetName())

return t.Reference(i.(*jnigi.ObjectRef))
return t.Reference(i)
case *ast.ArrayType:
t := this.handleType(v.Elt)

i, err := env.GetStaticField("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin", "ARRAY", jnigi.ObjectType("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin"))
var i = jnigi.NewObjectRef("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin")
err := env.GetStaticField("de/fraunhofer/aisec/cpg/graph/types/PointerType$PointerOrigin", "ARRAY", i)
if err != nil {
log.Fatal(err)
}

this.LogDebug("Array of %s", (*cpg.Node)(t).GetName())

return t.Reference(i.(*jnigi.ObjectRef))
return t.Reference(i)
case *ast.MapType:
// we cannot properly represent Golangs built-in map types, yet so we have
// to make a shortcut here and represent it as a Java-like map<K, V> type.
Expand Down
2 changes: 1 addition & 1 deletion cpg-language-go/src/main/golang/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
golang.org/x/mod v0.5.0
tekao.net/jnigi v0.0.0-20201212091834-f7b899046676
tekao.net/jnigi v0.0.0-20220804033536-1481db6c0949
)

require golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 // indirect
2 changes: 2 additions & 0 deletions cpg-language-go/src/main/golang/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbO
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
tekao.net/jnigi v0.0.0-20201212091834-f7b899046676 h1:ZEkhDs0eKEynaUD1XX/WnQCD5/zoEUyMkDx5DbvVq7g=
tekao.net/jnigi v0.0.0-20201212091834-f7b899046676/go.mod h1:SmVvXetJ8N0ov5c2eOC+IxmkdYGEyuXghTuBq5HWZ/Y=
tekao.net/jnigi v0.0.0-20220804033536-1481db6c0949 h1:dm+mZf0sVfEN1CqfVf4li64lPBczL5VxdVlz2Z7r31M=
tekao.net/jnigi v0.0.0-20220804033536-1481db6c0949/go.mod h1:SmVvXetJ8N0ov5c2eOC+IxmkdYGEyuXghTuBq5HWZ/Y=
15 changes: 9 additions & 6 deletions cpg-language-go/src/main/golang/lib/cpg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,37 +67,40 @@ func Java_de_fraunhofer_aisec_cpg_frontends_golang_GoLanguageFrontend_parseInter
frontend.InitEnv(env)
cpg.InitEnv(env)

src, err := srcObject.CallMethod(env, "getBytes", jnigi.Byte|jnigi.Array)
var src []byte
err := srcObject.CallMethod(env, "getBytes", &src)
if err != nil {
log.Fatal(err)
}

path, err := pathObject.CallMethod(env, "getBytes", jnigi.Byte|jnigi.Array)
var path []byte
err = pathObject.CallMethod(env, "getBytes", &path)
if err != nil {
log.Fatal(err)
}

topLevel, err := topLevelObject.CallMethod(env, "getBytes", jnigi.Byte|jnigi.Array)
var topLevel []byte
err = topLevelObject.CallMethod(env, "getBytes", &topLevel)
if err != nil {
log.Fatal(err)
}

fset := token.NewFileSet()
file, err := parser.ParseFile(fset, string(path.([]byte)), string(src.([]byte)), parser.ParseComments)
file, err := parser.ParseFile(fset, string(path), string(src), parser.ParseComments)
if err != nil {
log.Fatal(err)
}

goFrontend.CommentMap = ast.NewCommentMap(fset, file, file.Comments)

_, err = goFrontend.ParseModule(string(topLevel.([]byte)))
_, err = goFrontend.ParseModule(string(topLevel))
if err != nil {
goFrontend.LogError("Error occurred while looking for Go modules file: %v", err)
}

goFrontend.File = file

tu, err := goFrontend.HandleFile(fset, file, string(path.([]byte)))
tu, err := goFrontend.HandleFile(fset, file, string(path))
if err != nil {
log.Fatal(err)
}
Expand Down
Loading

0 comments on commit cd43943

Please sign in to comment.