Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
#if: "!contains(github.event.pull_request.title, '[NO-REGRESSION-TEST]')"
env:
LANGS: "go rust python typescript cxx cpp"
LANGS: "go rust python typescript"
# ignore package version for Go e.g. 'a.b/c@506fb8ece467f3a71c29322169bef9b0bc92d554'
DIFFJSON_IGNORE: >
['id']
Expand Down
63 changes: 63 additions & 0 deletions go.sum

Large diffs are not rendered by default.

47 changes: 10 additions & 37 deletions lang/collect/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

sitter "github.com/smacker/go-tree-sitter"

"github.com/cloudwego/abcoder/lang/cpp"
"github.com/cloudwego/abcoder/lang/cxx"
"github.com/cloudwego/abcoder/lang/java"
javaipc "github.com/cloudwego/abcoder/lang/java/ipc"
Expand Down Expand Up @@ -114,8 +113,6 @@ func switchSpec(l uniast.Language, repo string) LanguageSpec {
return python.NewPythonSpec()
case uniast.Java:
return java.NewJavaSpec(repo)
case uniast.Cpp:
return cpp.NewCppSpec()
default:
panic(fmt.Sprintf("unsupported language %s", l))
}
Expand Down Expand Up @@ -1701,11 +1698,9 @@ func (c *Collector) getSymbolByLocation(ctx context.Context, loc Location, depth
// return sym, nil
// }

if !(from.Type == "typeParameter" && c.Language == uniast.Cpp) {
// 1. already loaded
if sym := c.findMatchingSymbolIn(loc, slices.Collect(maps.Values(c.syms))); sym != nil {
return sym, nil
}
// 1. already loaded
if sym := c.findMatchingSymbolIn(loc, slices.Collect(maps.Values(c.syms))); sym != nil {
return sym, nil
}

if c.LoadExternalSymbol && !c.internal(loc) && (c.NeedStdSymbol || !c.spec.IsStdToken(from)) {
Expand Down Expand Up @@ -1934,11 +1929,11 @@ func (c *Collector) processSymbol(ctx context.Context, sym *DocumentSymbol, dept

// function info: type params, inputs, outputs, receiver (if !needImpl)
if sym.Kind == SKFunction || sym.Kind == SKMethod {
var rd *dependency
var rsym *dependency
rec, tps, ips, ops := c.spec.FunctionSymbol(*sym)
if (!hasImpl || c.Language == uniast.Cpp) && rec >= 0 {

if !hasImpl && rec >= 0 {
rsym, err := c.getSymbolByTokenWithLimit(ctx, sym.Tokens[rec], depth)
rd = &dependency{sym.Tokens[rec].Location, rsym}
if err != nil || rsym == nil {
log.Error("get receiver symbol for token %v failed: %v\n", rec, err)
}
Expand All @@ -1947,18 +1942,6 @@ func (c *Collector) processSymbol(ctx context.Context, sym *DocumentSymbol, dept
ipsyms, is := c.getDepsWithLimit(ctx, sym, ips, depth-1)
opsyms, os := c.getDepsWithLimit(ctx, sym, ops, depth-1)

// filter tsym is type parameter
if c.Language == uniast.Cpp {
tsFiltered := make([]dependency, 0, len(ts))
for _, d := range ts {
if d.Symbol == nil || d.Symbol.Kind == SKTypeParameter {
continue
}
tsFiltered = append(tsFiltered, d)
}
ts = tsFiltered
}

//get last token of params for get signature
lastToken := rec
for _, t := range tps {
Expand All @@ -1977,28 +1960,18 @@ func (c *Collector) processSymbol(ctx context.Context, sym *DocumentSymbol, dept
}
}

c.updateFunctionInfo(sym, tsyms, ipsyms, opsyms, ts, is, os, rd, lastToken)
c.updateFunctionInfo(sym, tsyms, ipsyms, opsyms, ts, is, os, rsym, lastToken)
}

// variable info: type
if sym.Kind == SKVariable || sym.Kind == SKConstant {
i := c.spec.DeclareTokenOfSymbol(*sym)
// in cpp, it should search form behind to front to find the first entity token
// find first entity token
if c.Language == uniast.Cpp {
for i = i - 1; i >= 0; i-- {
if c.spec.IsEntityToken(sym.Tokens[i]) {
break
}
}
} else {
for i = i + 1; i < len(sym.Tokens); i++ {
if c.spec.IsEntityToken(sym.Tokens[i]) {
break
}
for i = i + 1; i < len(sym.Tokens); i++ {
if c.spec.IsEntityToken(sym.Tokens[i]) {
break
}
}

if i < 0 || i >= len(sym.Tokens) {
log.Error("get type token of variable symbol %s failed\n", sym)
return
Expand Down
155 changes: 0 additions & 155 deletions lang/collect/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"strings"

"github.com/cloudwego/abcoder/lang/log"
"github.com/cloudwego/abcoder/lang/lsp"
. "github.com/cloudwego/abcoder/lang/lsp"
"github.com/cloudwego/abcoder/lang/uniast"
"github.com/cloudwego/abcoder/lang/utils"
Expand Down Expand Up @@ -253,21 +252,6 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
// NOTICE: use refName as id when symbol name is missing
name = refName
}

if c.Language == uniast.Cpp {
// for function override, use call signature as id
if symbol.Kind == SKMethod || symbol.Kind == SKFunction {
name = c.extractCppCallSig(symbol)
}

// join name with namespace
if ns := c.scopePrefix(symbol); ns != "" {
if !strings.HasPrefix(name, ns+"::") {
name = ns + "::" + name
}
}
}

tmp := uniast.NewIdentity(mod, path, name)
id = &tmp
// Save to visited ONLY WHEN no errors occur
Expand Down Expand Up @@ -397,18 +381,6 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
id.Name = iid.Name + "<" + id.Name + ">"
}
}

// cpp get method name without class name
if c.Language == uniast.Cpp && rid != nil {
rec := strings.TrimSpace(rid.Name)
if rec != "" {
searchStr := rec + "::"
if idx := strings.Index(name, searchStr); idx >= 0 {
name = name[idx+len(searchStr):]
}
}
}

if k == SKFunction {
// NOTICE: class static method name is: type::method
id.Name += "::" + name
Expand Down Expand Up @@ -551,130 +523,3 @@ func mapKind(kind SymbolKind) uniast.TypeKind {
panic(fmt.Sprintf("unexpected kind %v", kind))
}
}

func (c *Collector) scopePrefix(sym *DocumentSymbol) string {
parts := []string{}
cur := sym
for {
p := c.cli.GetParent(cur)
if p == nil {
break
}
if p.Kind == lsp.SKNamespace {
if p.Name != "" {
parts = append([]string{p.Name}, parts...)
}
}
cur = p
}
return strings.Join(parts, "::") // "a::b"
}

func (c *Collector) cppBaseName(n string) string {
n = strings.TrimSpace(n)
if i := strings.LastIndex(n, "::"); i >= 0 {
n = n[i+2:]
}
n = strings.TrimSpace(n)
// optional: strip template args on the function name itself: foo<T> -> foo
if j := strings.IndexByte(n, '<'); j >= 0 {
n = n[:j]
}
return strings.TrimSpace(n)
}

// extractCppCallSig returns "sym.Name(params)" where params is extracted from sym.Text.
func (c *Collector) extractCppCallSig(sym *lsp.DocumentSymbol) (ret string) {
name := strings.TrimSpace(sym.Name)
if name == "" {
return ""
}
text := sym.Text
if text == "" {
return name + "()"
}

want := c.cppBaseName(name)
if want == "" {
want = name
}
fallback := name + "()"

isIdent := func(b byte) bool {
return (b >= 'a' && b <= 'z') ||
(b >= 'A' && b <= 'Z') ||
(b >= '0' && b <= '9') ||
b == '_'
}
isWholeIdentAt := func(s string, pos int, w string) bool {
if pos < 0 || pos+len(w) > len(s) || s[pos:pos+len(w)] != w {
return false
}
if pos > 0 && isIdent(s[pos-1]) {
return false
}
if pos+len(w) < len(s) && isIdent(s[pos+len(w)]) {
return false
}
return true
}
findMatchingParenIn := func(s string, openIdx int, end int) int {
if openIdx < 0 || openIdx >= len(s) || s[openIdx] != '(' {
return -1
}
if end > len(s) {
end = len(s)
}
depth := 0
for i := openIdx; i < end; i++ {
switch s[i] {
case '(':
depth++
case ')':
depth--
if depth == 0 {
return i
}
}
}
return -1
}

headerEnd := len(text)
if i := strings.IndexByte(text, '{'); i >= 0 && i < headerEnd {
headerEnd = i
}
if i := strings.IndexByte(text, ';'); i >= 0 && i < headerEnd {
headerEnd = i
}
header := text[:headerEnd]

namePos := -1
for i := 0; i+len(want) <= len(header); i++ {
if isWholeIdentAt(header, i, want) {
namePos = i
break
}
}
if namePos < 0 {
return fallback
}

openIdx := -1
for i := namePos + len(want); i < len(header); i++ {
if header[i] == '(' {
openIdx = i
break
}
}
if openIdx < 0 {
return fallback
}

closeIdx := findMatchingParenIn(header, openIdx, len(header))
if closeIdx < 0 {
return fallback
}

return name + header[openIdx:closeIdx+1]
}
46 changes: 0 additions & 46 deletions lang/cpp/lib.go

This file was deleted.

Loading
Loading