github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/colexec/execgen/cmd/execgen/selection_ops_gen.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package main 12 13 import ( 14 "io" 15 "strings" 16 "text/template" 17 ) 18 19 const selectionOpsTmpl = "pkg/sql/colexec/colexecsel/selection_ops_tmpl.go" 20 21 func getSelectionOpsTmpl(inputFileContents string) (*template.Template, error) { 22 r := strings.NewReplacer( 23 "_LEFT_CANONICAL_TYPE_FAMILY", "{{.LeftCanonicalFamilyStr}}", 24 "_LEFT_TYPE_WIDTH", typeWidthReplacement, 25 "_RIGHT_CANONICAL_TYPE_FAMILY", "{{.RightCanonicalFamilyStr}}", 26 "_RIGHT_TYPE_WIDTH", typeWidthReplacement, 27 28 "_OP_CONST_NAME", "sel{{.Name}}{{.Left.VecMethod}}{{.Right.VecMethod}}ConstOp", 29 "_OP_NAME", "sel{{.Name}}{{.Left.VecMethod}}{{.Right.VecMethod}}Op", 30 "_NAME", "{{.Name}}", 31 "_R_GO_TYPE", "{{.Right.GoType}}", 32 "_L_TYP", "{{.Left.VecMethod}}", 33 "_R_TYP", "{{.Right.VecMethod}}", 34 ) 35 s := r.Replace(inputFileContents) 36 37 assignCmpRe := makeFunctionRegex("_ASSIGN_CMP", 6) 38 s = assignCmpRe.ReplaceAllString(s, makeTemplateFunctionCall("Right.Assign", 6)) 39 40 s = strings.ReplaceAll(s, "_HAS_NULLS", "$hasNulls") 41 selConstLoop := makeFunctionRegex("_SEL_CONST_LOOP", 1) 42 s = selConstLoop.ReplaceAllString(s, `{{template "selConstLoop" buildDict "Global" $ "HasNulls" $1 "Overload" .}}`) 43 selLoop := makeFunctionRegex("_SEL_LOOP", 1) 44 s = selLoop.ReplaceAllString(s, `{{template "selLoop" buildDict "Global" $ "HasNulls" $1 "Overload" .}}`) 45 46 return template.New("selection_ops").Funcs(template.FuncMap{"buildDict": buildDict}).Parse(s) 47 } 48 49 func genSelectionOps(inputFileContents string, wr io.Writer) error { 50 tmpl, err := getSelectionOpsTmpl(inputFileContents) 51 if err != nil { 52 return err 53 } 54 return tmpl.Execute(wr, twoArgsResolvedOverloadsInfo) 55 } 56 57 func init() { 58 registerGenerator(genSelectionOps, "selection_ops.eg.go", selectionOpsTmpl) 59 }