vitess.io/vitess@v0.16.2/go/tools/asthelpergen/integration/ast_copy_on_rewrite.go (about)

     1  /*
     2  Copyright 2023 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  // Code generated by ASTHelperGen. DO NOT EDIT.
    17  
    18  package integration
    19  
    20  func (c *cow) copyOnRewriteAST(n AST, parent AST) (out AST, changed bool) {
    21  	if n == nil || c.cursor.stop {
    22  		return n, false
    23  	}
    24  	switch n := n.(type) {
    25  	case BasicType:
    26  		return c.copyOnRewriteBasicType(n, parent)
    27  	case Bytes:
    28  		return c.copyOnRewriteBytes(n, parent)
    29  	case InterfaceContainer:
    30  		return c.copyOnRewriteInterfaceContainer(n, parent)
    31  	case InterfaceSlice:
    32  		return c.copyOnRewriteInterfaceSlice(n, parent)
    33  	case *Leaf:
    34  		return c.copyOnRewriteRefOfLeaf(n, parent)
    35  	case LeafSlice:
    36  		return c.copyOnRewriteLeafSlice(n, parent)
    37  	case *NoCloneType:
    38  		return c.copyOnRewriteRefOfNoCloneType(n, parent)
    39  	case *RefContainer:
    40  		return c.copyOnRewriteRefOfRefContainer(n, parent)
    41  	case *RefSliceContainer:
    42  		return c.copyOnRewriteRefOfRefSliceContainer(n, parent)
    43  	case *SubImpl:
    44  		return c.copyOnRewriteRefOfSubImpl(n, parent)
    45  	case ValueContainer:
    46  		return c.copyOnRewriteValueContainer(n, parent)
    47  	case ValueSliceContainer:
    48  		return c.copyOnRewriteValueSliceContainer(n, parent)
    49  	default:
    50  		// this should never happen
    51  		return nil, false
    52  	}
    53  }
    54  func (c *cow) copyOnRewriteBytes(n Bytes, parent AST) (out AST, changed bool) {
    55  	if n == nil || c.cursor.stop {
    56  		return n, false
    57  	}
    58  	out = n
    59  	if c.pre != nil {
    60  		c.pre(n, parent)
    61  	}
    62  	if c.post != nil {
    63  		out, changed = c.postVisit(out, parent, changed)
    64  	}
    65  	return
    66  }
    67  func (c *cow) copyOnRewriteInterfaceContainer(n InterfaceContainer, parent AST) (out AST, changed bool) {
    68  	out = n
    69  	if c.pre == nil || c.pre(n, parent) {
    70  	}
    71  	if c.post != nil {
    72  		out, changed = c.postVisit(out, parent, changed)
    73  	}
    74  	return
    75  }
    76  func (c *cow) copyOnRewriteInterfaceSlice(n InterfaceSlice, parent AST) (out AST, changed bool) {
    77  	if n == nil || c.cursor.stop {
    78  		return n, false
    79  	}
    80  	out = n
    81  	if c.pre == nil || c.pre(n, parent) {
    82  		res := make(InterfaceSlice, len(n))
    83  		for x, el := range n {
    84  			this, change := c.copyOnRewriteAST(el, n)
    85  			res[x] = this.(AST)
    86  			if change {
    87  				changed = true
    88  			}
    89  		}
    90  		if changed {
    91  			out = res
    92  		}
    93  	}
    94  	if c.post != nil {
    95  		out, changed = c.postVisit(out, parent, changed)
    96  	}
    97  	return
    98  }
    99  func (c *cow) copyOnRewriteRefOfLeaf(n *Leaf, parent AST) (out AST, changed bool) {
   100  	if n == nil || c.cursor.stop {
   101  		return n, false
   102  	}
   103  	out = n
   104  	if c.pre == nil || c.pre(n, parent) {
   105  	}
   106  	if c.post != nil {
   107  		out, changed = c.postVisit(out, parent, changed)
   108  	}
   109  	return
   110  }
   111  func (c *cow) copyOnRewriteLeafSlice(n LeafSlice, parent AST) (out AST, changed bool) {
   112  	if n == nil || c.cursor.stop {
   113  		return n, false
   114  	}
   115  	out = n
   116  	if c.pre == nil || c.pre(n, parent) {
   117  		res := make(LeafSlice, len(n))
   118  		for x, el := range n {
   119  			this, change := c.copyOnRewriteRefOfLeaf(el, n)
   120  			res[x] = this.(*Leaf)
   121  			if change {
   122  				changed = true
   123  			}
   124  		}
   125  		if changed {
   126  			out = res
   127  		}
   128  	}
   129  	if c.post != nil {
   130  		out, changed = c.postVisit(out, parent, changed)
   131  	}
   132  	return
   133  }
   134  func (c *cow) copyOnRewriteRefOfNoCloneType(n *NoCloneType, parent AST) (out AST, changed bool) {
   135  	if n == nil || c.cursor.stop {
   136  		return n, false
   137  	}
   138  	out = n
   139  	if c.pre == nil || c.pre(n, parent) {
   140  	}
   141  	if c.post != nil {
   142  		out, changed = c.postVisit(out, parent, changed)
   143  	}
   144  	return
   145  }
   146  func (c *cow) copyOnRewriteRefOfRefContainer(n *RefContainer, parent AST) (out AST, changed bool) {
   147  	if n == nil || c.cursor.stop {
   148  		return n, false
   149  	}
   150  	out = n
   151  	if c.pre == nil || c.pre(n, parent) {
   152  		_ASTType, changedASTType := c.copyOnRewriteAST(n.ASTType, n)
   153  		_ASTImplementationType, changedASTImplementationType := c.copyOnRewriteRefOfLeaf(n.ASTImplementationType, n)
   154  		if changedASTType || changedASTImplementationType {
   155  			res := *n
   156  			res.ASTType, _ = _ASTType.(AST)
   157  			res.ASTImplementationType, _ = _ASTImplementationType.(*Leaf)
   158  			out = &res
   159  			if c.cloned != nil {
   160  				c.cloned(n, out)
   161  			}
   162  			changed = true
   163  		}
   164  	}
   165  	if c.post != nil {
   166  		out, changed = c.postVisit(out, parent, changed)
   167  	}
   168  	return
   169  }
   170  func (c *cow) copyOnRewriteRefOfRefSliceContainer(n *RefSliceContainer, parent AST) (out AST, changed bool) {
   171  	if n == nil || c.cursor.stop {
   172  		return n, false
   173  	}
   174  	out = n
   175  	if c.pre == nil || c.pre(n, parent) {
   176  		var changedASTElements bool
   177  		_ASTElements := make([]AST, len(n.ASTElements))
   178  		for x, el := range n.ASTElements {
   179  			this, changed := c.copyOnRewriteAST(el, n)
   180  			_ASTElements[x] = this.(AST)
   181  			if changed {
   182  				changedASTElements = true
   183  			}
   184  		}
   185  		var changedASTImplementationElements bool
   186  		_ASTImplementationElements := make([]*Leaf, len(n.ASTImplementationElements))
   187  		for x, el := range n.ASTImplementationElements {
   188  			this, changed := c.copyOnRewriteRefOfLeaf(el, n)
   189  			_ASTImplementationElements[x] = this.(*Leaf)
   190  			if changed {
   191  				changedASTImplementationElements = true
   192  			}
   193  		}
   194  		if changedASTElements || changedASTImplementationElements {
   195  			res := *n
   196  			res.ASTElements = _ASTElements
   197  			res.ASTImplementationElements = _ASTImplementationElements
   198  			out = &res
   199  			if c.cloned != nil {
   200  				c.cloned(n, out)
   201  			}
   202  			changed = true
   203  		}
   204  	}
   205  	if c.post != nil {
   206  		out, changed = c.postVisit(out, parent, changed)
   207  	}
   208  	return
   209  }
   210  func (c *cow) copyOnRewriteRefOfSubImpl(n *SubImpl, parent AST) (out AST, changed bool) {
   211  	if n == nil || c.cursor.stop {
   212  		return n, false
   213  	}
   214  	out = n
   215  	if c.pre == nil || c.pre(n, parent) {
   216  		_inner, changedinner := c.copyOnRewriteSubIface(n.inner, n)
   217  		if changedinner {
   218  			res := *n
   219  			res.inner, _ = _inner.(SubIface)
   220  			out = &res
   221  			if c.cloned != nil {
   222  				c.cloned(n, out)
   223  			}
   224  			changed = true
   225  		}
   226  	}
   227  	if c.post != nil {
   228  		out, changed = c.postVisit(out, parent, changed)
   229  	}
   230  	return
   231  }
   232  func (c *cow) copyOnRewriteValueContainer(n ValueContainer, parent AST) (out AST, changed bool) {
   233  	out = n
   234  	if c.pre == nil || c.pre(n, parent) {
   235  		_ASTType, changedASTType := c.copyOnRewriteAST(n.ASTType, n)
   236  		_ASTImplementationType, changedASTImplementationType := c.copyOnRewriteRefOfLeaf(n.ASTImplementationType, n)
   237  		if changedASTType || changedASTImplementationType {
   238  			res := n
   239  			res.ASTType, _ = _ASTType.(AST)
   240  			res.ASTImplementationType, _ = _ASTImplementationType.(*Leaf)
   241  			out = &res
   242  			if c.cloned != nil {
   243  				c.cloned(n, out)
   244  			}
   245  			changed = true
   246  		}
   247  	}
   248  	if c.post != nil {
   249  		out, changed = c.postVisit(out, parent, changed)
   250  	}
   251  	return
   252  }
   253  func (c *cow) copyOnRewriteValueSliceContainer(n ValueSliceContainer, parent AST) (out AST, changed bool) {
   254  	out = n
   255  	if c.pre == nil || c.pre(n, parent) {
   256  		var changedASTElements bool
   257  		_ASTElements := make([]AST, len(n.ASTElements))
   258  		for x, el := range n.ASTElements {
   259  			this, changed := c.copyOnRewriteAST(el, n)
   260  			_ASTElements[x] = this.(AST)
   261  			if changed {
   262  				changedASTElements = true
   263  			}
   264  		}
   265  		var changedASTImplementationElements bool
   266  		_ASTImplementationElements := make([]*Leaf, len(n.ASTImplementationElements))
   267  		for x, el := range n.ASTImplementationElements {
   268  			this, changed := c.copyOnRewriteRefOfLeaf(el, n)
   269  			_ASTImplementationElements[x] = this.(*Leaf)
   270  			if changed {
   271  				changedASTImplementationElements = true
   272  			}
   273  		}
   274  		if changedASTElements || changedASTImplementationElements {
   275  			res := n
   276  			res.ASTElements = _ASTElements
   277  			res.ASTImplementationElements = _ASTImplementationElements
   278  			out = &res
   279  			if c.cloned != nil {
   280  				c.cloned(n, out)
   281  			}
   282  			changed = true
   283  		}
   284  	}
   285  	if c.post != nil {
   286  		out, changed = c.postVisit(out, parent, changed)
   287  	}
   288  	return
   289  }
   290  func (c *cow) copyOnRewriteSubIface(n SubIface, parent AST) (out AST, changed bool) {
   291  	if n == nil || c.cursor.stop {
   292  		return n, false
   293  	}
   294  	switch n := n.(type) {
   295  	case *SubImpl:
   296  		return c.copyOnRewriteRefOfSubImpl(n, parent)
   297  	default:
   298  		// this should never happen
   299  		return nil, false
   300  	}
   301  }
   302  func (c *cow) copyOnRewriteBasicType(n BasicType, parent AST) (out AST, changed bool) {
   303  	if c.cursor.stop {
   304  		return n, false
   305  	}
   306  	if c.pre != nil {
   307  		c.pre(n, parent)
   308  	}
   309  	if c.post != nil {
   310  		out, changed = c.postVisit(n, parent, changed)
   311  	} else {
   312  		out = n
   313  	}
   314  	return
   315  }
   316  func (c *cow) copyOnRewriteRefOfInterfaceContainer(n *InterfaceContainer, parent AST) (out AST, changed bool) {
   317  	if n == nil || c.cursor.stop {
   318  		return n, false
   319  	}
   320  	out = n
   321  	if c.pre == nil || c.pre(n, parent) {
   322  	}
   323  	if c.post != nil {
   324  		out, changed = c.postVisit(out, parent, changed)
   325  	}
   326  	return
   327  }
   328  func (c *cow) copyOnRewriteRefOfValueContainer(n *ValueContainer, parent AST) (out AST, changed bool) {
   329  	if n == nil || c.cursor.stop {
   330  		return n, false
   331  	}
   332  	out = n
   333  	if c.pre == nil || c.pre(n, parent) {
   334  		_ASTType, changedASTType := c.copyOnRewriteAST(n.ASTType, n)
   335  		_ASTImplementationType, changedASTImplementationType := c.copyOnRewriteRefOfLeaf(n.ASTImplementationType, n)
   336  		if changedASTType || changedASTImplementationType {
   337  			res := *n
   338  			res.ASTType, _ = _ASTType.(AST)
   339  			res.ASTImplementationType, _ = _ASTImplementationType.(*Leaf)
   340  			out = &res
   341  			if c.cloned != nil {
   342  				c.cloned(n, out)
   343  			}
   344  			changed = true
   345  		}
   346  	}
   347  	if c.post != nil {
   348  		out, changed = c.postVisit(out, parent, changed)
   349  	}
   350  	return
   351  }
   352  func (c *cow) copyOnRewriteRefOfValueSliceContainer(n *ValueSliceContainer, parent AST) (out AST, changed bool) {
   353  	if n == nil || c.cursor.stop {
   354  		return n, false
   355  	}
   356  	out = n
   357  	if c.pre == nil || c.pre(n, parent) {
   358  		var changedASTElements bool
   359  		_ASTElements := make([]AST, len(n.ASTElements))
   360  		for x, el := range n.ASTElements {
   361  			this, changed := c.copyOnRewriteAST(el, n)
   362  			_ASTElements[x] = this.(AST)
   363  			if changed {
   364  				changedASTElements = true
   365  			}
   366  		}
   367  		var changedASTImplementationElements bool
   368  		_ASTImplementationElements := make([]*Leaf, len(n.ASTImplementationElements))
   369  		for x, el := range n.ASTImplementationElements {
   370  			this, changed := c.copyOnRewriteRefOfLeaf(el, n)
   371  			_ASTImplementationElements[x] = this.(*Leaf)
   372  			if changed {
   373  				changedASTImplementationElements = true
   374  			}
   375  		}
   376  		if changedASTElements || changedASTImplementationElements {
   377  			res := *n
   378  			res.ASTElements = _ASTElements
   379  			res.ASTImplementationElements = _ASTImplementationElements
   380  			out = &res
   381  			if c.cloned != nil {
   382  				c.cloned(n, out)
   383  			}
   384  			changed = true
   385  		}
   386  	}
   387  	if c.post != nil {
   388  		out, changed = c.postVisit(out, parent, changed)
   389  	}
   390  	return
   391  }