mxrewrite.go raw
1 package loader
2
3 // Moxie source rewrites — thin wrappers around moxie/mxtext.
4
5 import (
6 "go/ast"
7 "go/token"
8 "go/types"
9 "strings"
10
11 "moxie/mxtext"
12 )
13
14 type pipeRewrite = mxtext.PipeRewrite
15
16 func isMoxieStringTarget(importPath string) bool {
17 return mxtext.IsMoxieStringTarget(importPath)
18 }
19
20 func rewriteStringLiterals(file *ast.File) {
21 mxtext.RewriteStringLiterals(file)
22 }
23
24 func rewriteStringTypes(file *ast.File) {
25 mxtext.RewriteStringTypes(file)
26 }
27
28 func rewriteStringConversions(file *ast.File) {
29 mxtext.RewriteStringConversions(file)
30 }
31
32 func wrapInterfaceMandatedReturns(file *ast.File) {
33 mxtext.WrapInterfaceMandatedReturns(file)
34 }
35
36 func rewriteAddToPipe(file *ast.File) bool {
37 return mxtext.RewriteAddToPipe(file)
38 }
39
40 func rewriteConstPipes(files []*ast.File) {
41 mxtext.RewriteConstPipes(files)
42 }
43
44 func findPipeConcat(files []*ast.File, info *types.Info) []pipeRewrite {
45 return mxtext.FindPipeConcat(files, info)
46 }
47
48 func applyPipeRewrites(files []*ast.File, rewrites []pipeRewrite) {
49 mxtext.ApplyPipeRewrites(files, rewrites)
50 }
51
52 func filterPipeErrors(errs []error) []error {
53 return mxtext.FilterPipeErrors(errs)
54 }
55
56 func findByteComparisons(files []*ast.File, info *types.Info) []*ast.BinaryExpr {
57 return mxtext.FindByteComparisons(files, info)
58 }
59
60 func applyByteComparisonRewrites(files []*ast.File, exprs []*ast.BinaryExpr) {
61 mxtext.ApplyByteComparisonRewrites(files, exprs)
62 }
63
64 func findByteSwitches(files []*ast.File, info *types.Info) []*ast.SwitchStmt {
65 return mxtext.FindByteSwitches(files, info)
66 }
67
68 func applyByteSwitchRewrites(switches []*ast.SwitchStmt) {
69 mxtext.ApplyByteSwitchRewrites(switches)
70 }
71
72 func filterByteCompareErrors(errs []error) []error {
73 return mxtext.FilterByteCompareErrors(errs)
74 }
75
76 func filterStringByteMismatch(errs []error) []error {
77 return mxtext.FilterStringByteMismatch(errs)
78 }
79
80 func filterNoNewVarErrors(errs []error) []error {
81 var out []error
82 for _, e := range errs {
83 msg := e.Error()
84 if strings.Contains(msg, "no new variables on left side of :=") {
85 continue
86 }
87 if strings.Contains(msg, "declared and not used") {
88 continue
89 }
90 out = append(out, e)
91 }
92 return out
93 }
94
95 func rewriteAddAssign(files []*ast.File, info *types.Info) int {
96 return mxtext.RewriteAddAssign(files, info)
97 }
98
99 func injectMoxieByteBuiltins(fset *token.FileSet, pkgName string) *ast.File {
100 return mxtext.InjectMoxieByteBuiltins(fset, pkgName)
101 }
102
103 func hasMoxieSecallocRefs(files []*ast.File) bool {
104 return mxtext.HasMoxieSecallocRefs(files)
105 }
106
107 func rewriteChanLiterals(src []byte, fset *token.FileSet) mxtext.RewriteResult {
108 return mxtext.RewriteChanLiterals(src, fset)
109 }
110
111 func checkPlusOnText(files []*ast.File, info *types.Info, fset *token.FileSet) []error {
112 return mxtext.CheckPlusOnText(files, info, fset)
113 }
114
115 func rewriteSliceLiterals(src []byte, fset *token.FileSet, priorOffsets ...[]int) mxtext.RewriteResult {
116 return mxtext.RewriteSliceLiterals(src, fset, priorOffsets...)
117 }
118