Skip to content

Commit

Permalink
Merge pull request #7 from xushiwei/q
Browse files Browse the repository at this point in the history
use internal/gopdoc (alias github.com/goplus/gop/doc)
  • Loading branch information
xushiwei authored Mar 15, 2024
2 parents 4d75eb0 + f731441 commit 5a0f62c
Show file tree
Hide file tree
Showing 6 changed files with 594 additions and 146 deletions.
125 changes: 0 additions & 125 deletions internal/_gopdoc/parse_overload_func.go

This file was deleted.

20 changes: 0 additions & 20 deletions internal/_gopdoc/transform.go

This file was deleted.

5 changes: 4 additions & 1 deletion internal/godoc/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"golang.org/x/pkgsite/internal/godoc/dochtml"
"golang.org/x/pkgsite/internal/source"
"golang.org/x/pkgsite/internal/stdlib"

gopdoc "golang.org/x/pkgsite/internal/gopdoc"
)

const (
Expand Down Expand Up @@ -125,6 +127,7 @@ func (p *Package) DocPackage(innerPath string, modInfo *ModuleInfo) (_ *doc.Pack
if d.ImportPath != importPath {
panic(fmt.Errorf("internal error: *doc.Package has an unexpected import path (%q != %q)", d.ImportPath, importPath))
}

if noTypeAssociation {
for _, t := range d.Types {
d.Consts, t.Consts = append(d.Consts, t.Consts...), nil
Expand All @@ -138,7 +141,7 @@ func (p *Package) DocPackage(innerPath string, modInfo *ModuleInfo) (_ *doc.Pack
if len(d.Imports) > maxImportsPerPackage {
return nil, fmt.Errorf("%d imports found package %q; exceeds limit %d for maxImportsPerPackage", len(d.Imports), importPath, maxImportsPerPackage)
}
return d, nil
return gopdoc.Transform(d), nil
}

// renderOptions returns a RenderOptions for p.
Expand Down
76 changes: 76 additions & 0 deletions internal/gopdoc/z_gop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). 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 doc

import (
"go/doc"
"strings"
)

const (
goptPrefix = "Gopt_" // template method
gopoPrefix = "Gopo_" // overload function/method
gopxPrefix = "Gopx_" // type as parameters function/method
gopPackage = "GopPackage"
)

func isGopPackage(in *doc.Package) bool {
for _, v := range in.Consts {
for _, name := range v.Names {
if name == gopPackage {
return true
}
}
}
return false
}

func isGopoConst(name string) bool {
return strings.HasPrefix(name, gopoPrefix)
}

func hasGopoConst(in *doc.Value) bool {
for _, name := range in.Names {
if isGopoConst(name) {
return true
}
}
return false
}

func isOverload(name string) bool {
n := len(name)
return n > 3 && name[n-3:n-1] == "__"
}

// Func (no _ func name)
// _Func (with _ func name)
// TypeName_Method (no _ method name)
// _TypeName__Method (with _ method name)
func checkTypeMethod(name string) mthd {
if pos := strings.IndexByte(name, '_'); pos >= 0 {
if pos == 0 {
t := name[1:]
if pos = strings.Index(t, "__"); pos <= 0 {
return mthd{"", t} // _Func
}
return mthd{t[:pos], t[pos+2:]} // _TypeName__Method
}
return mthd{name[:pos], name[pos+1:]} // TypeName_Method
}
return mthd{"", name} // Func
}
Loading

0 comments on commit 5a0f62c

Please sign in to comment.