From 40beb2f3e8643dfbc560f12f98ec1a5c0d5e4de6 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 12 Sep 2026 07:10:04 +0800 Subject: [PATCH] cmd: llimport --- cmd/llcppdump/cppdump.go | 1 - cmd/llimport/import.go | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 cmd/llimport/import.go diff --git a/cmd/llcppdump/cppdump.go b/cmd/llcppdump/cppdump.go index 6aed0aa1..f7c0bb22 100644 --- a/cmd/llcppdump/cppdump.go +++ b/cmd/llcppdump/cppdump.go @@ -54,7 +54,6 @@ func dump(node clang.Cursor, ns string, presumedFile *c.Char) { }) } -// usage: llcppdump func main() { if len(os.Args) < 2 { fmt.Println("usage: llcppdump []") diff --git a/cmd/llimport/import.go b/cmd/llimport/import.go new file mode 100644 index 00000000..330491f1 --- /dev/null +++ b/cmd/llimport/import.go @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + "log" + "os" + + "github.com/goplus/gogen/packages" +) + +func main() { + if len(os.Args) < 2 { + fmt.Println("usage: llimport []") + return + } + + pkgPath := os.Args[1] + workDir := "" + if len(os.Args) > 2 { + workDir = os.Args[2] + } + + imp := packages.NewImporter(nil, workDir) + impPkg, err := imp.Import(pkgPath) + check(err) + + scope := impPkg.Scope() + for _, name := range scope.Names() { + fmt.Println(scope.Lookup(name)) + } +} + +func check(err error) { + if err != nil { + log.Panicln(err) + } +}