mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-10 18:13:18 +01:00
internal/shaderlister: bug fix: a directive in a function must be ignored
Updates #3157
This commit is contained in:
parent
0182f7044d
commit
aaabea02cb
@ -28,6 +28,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/tools/go/ast/inspector"
|
"golang.org/x/tools/go/ast/inspector"
|
||||||
@ -216,8 +217,21 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
|
|||||||
visitedPatterns := map[string]struct{}{}
|
visitedPatterns := map[string]struct{}{}
|
||||||
visitedPaths := map[string]struct{}{}
|
visitedPaths := map[string]struct{}{}
|
||||||
for _, f := range pkg.Syntax {
|
for _, f := range pkg.Syntax {
|
||||||
|
var funcs []*ast.FuncDecl
|
||||||
|
for _, decl := range f.Decls {
|
||||||
|
if f, ok := decl.(*ast.FuncDecl); ok {
|
||||||
|
funcs = append(funcs, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, c := range f.Comments {
|
for _, c := range f.Comments {
|
||||||
for _, l := range c.List {
|
for _, l := range c.List {
|
||||||
|
// Ignore the line if it is in a function declaration.
|
||||||
|
if slices.ContainsFunc(funcs, func(f *ast.FuncDecl) bool {
|
||||||
|
return f.Pos() <= l.Pos() && l.Pos() < f.End()
|
||||||
|
}) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
m := reShaderFileDirective.FindString(l.Text)
|
m := reShaderFileDirective.FindString(l.Text)
|
||||||
if m == "" {
|
if m == "" {
|
||||||
continue
|
continue
|
||||||
@ -293,6 +307,7 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
|
|||||||
|
|
||||||
// Resolve ebitengine:shadersource directives.
|
// Resolve ebitengine:shadersource directives.
|
||||||
var genDeclStack []*ast.GenDecl
|
var genDeclStack []*ast.GenDecl
|
||||||
|
// inspector.Inspector doesn't iterate comments that are not attached to any other nodes.
|
||||||
in := inspector.New(pkg.Syntax)
|
in := inspector.New(pkg.Syntax)
|
||||||
in.Nodes([]ast.Node{
|
in.Nodes([]ast.Node{
|
||||||
(*ast.GenDecl)(nil),
|
(*ast.GenDecl)(nil),
|
||||||
|
@ -75,3 +75,9 @@ const (
|
|||||||
//ebitengine:shaderfile *_kage.go *_kage.go *_kage.go
|
//ebitengine:shaderfile *_kage.go *_kage.go *_kage.go
|
||||||
|
|
||||||
//ebitengine:shaderfile nonexistent.go
|
//ebitengine:shaderfile nonexistent.go
|
||||||
|
|
||||||
|
func foo() {
|
||||||
|
// Non top-level files are ignored.
|
||||||
|
|
||||||
|
//ebitengine:shaderfile *_notkage.go
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user