| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package ast |
| 16 |
|
| 17 |
import ( |
| 18 |
"github.com/google/cel-go/common/types/ref" |
| 19 |
) |
| 20 |
|
| 21 |
|
| 22 |
type ExprKind int |
| 23 |
|
| 24 |
const ( |
| 25 |
|
| 26 |
UnspecifiedExprKind ExprKind = iota |
| 27 |
|
| 28 |
|
| 29 |
CallKind |
| 30 |
|
| 31 |
|
| 32 |
ComprehensionKind |
| 33 |
|
| 34 |
|
| 35 |
IdentKind |
| 36 |
|
| 37 |
|
| 38 |
ListKind |
| 39 |
|
| 40 |
|
| 41 |
LiteralKind |
| 42 |
|
| 43 |
|
| 44 |
MapKind |
| 45 |
|
| 46 |
|
| 47 |
SelectKind |
| 48 |
|
| 49 |
|
| 50 |
StructKind |
| 51 |
) |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
type Expr interface { |
| 58 |
|
| 59 |
ID() int64 |
| 60 |
|
| 61 |
|
| 62 |
Kind() ExprKind |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
AsCall() CallExpr |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
AsComprehension() ComprehensionExpr |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
AsIdent() string |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
AsLiteral() ref.Val |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
AsList() ListExpr |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
AsMap() MapExpr |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
AsSelect() SelectExpr |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
AsStruct() StructExpr |
| 103 |
|
| 104 |
|
| 105 |
RenumberIDs(IDGenerator) |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
SetKindCase(Expr) |
| 114 |
|
| 115 |
|
| 116 |
isExpr() |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
type EntryExprKind int |
| 121 |
|
| 122 |
const ( |
| 123 |
|
| 124 |
UnspecifiedEntryExprKind EntryExprKind = iota |
| 125 |
|
| 126 |
|
| 127 |
MapEntryKind |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
StructFieldKind |
| 132 |
) |
| 133 |
|
| 134 |
|
| 135 |
type EntryExpr interface { |
| 136 |
|
| 137 |
ID() int64 |
| 138 |
|
| 139 |
|
| 140 |
Kind() EntryExprKind |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
AsMapEntry() MapEntry |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
AsStructField() StructField |
| 151 |
|
| 152 |
|
| 153 |
RenumberIDs(IDGenerator) |
| 154 |
|
| 155 |
isEntryExpr() |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
type IDGenerator func(originalID int64) int64 |
| 160 |
|
| 161 |
|
| 162 |
type CallExpr interface { |
| 163 |
|
| 164 |
FunctionName() string |
| 165 |
|
| 166 |
|
| 167 |
IsMemberFunction() bool |
| 168 |
|
| 169 |
|
| 170 |
Target() Expr |
| 171 |
|
| 172 |
|
| 173 |
Args() []Expr |
| 174 |
|
| 175 |
|
| 176 |
isExpr() |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
type ListExpr interface { |
| 181 |
|
| 182 |
Elements() []Expr |
| 183 |
|
| 184 |
|
| 185 |
OptionalIndices() []int32 |
| 186 |
|
| 187 |
|
| 188 |
IsOptional(int32) bool |
| 189 |
|
| 190 |
|
| 191 |
Size() int |
| 192 |
|
| 193 |
|
| 194 |
isExpr() |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
type SelectExpr interface { |
| 199 |
|
| 200 |
Operand() Expr |
| 201 |
|
| 202 |
|
| 203 |
FieldName() string |
| 204 |
|
| 205 |
|
| 206 |
IsTestOnly() bool |
| 207 |
|
| 208 |
|
| 209 |
isExpr() |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
type MapExpr interface { |
| 214 |
|
| 215 |
Entries() []EntryExpr |
| 216 |
|
| 217 |
|
| 218 |
Size() int |
| 219 |
|
| 220 |
|
| 221 |
isExpr() |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
type MapEntry interface { |
| 226 |
|
| 227 |
Key() Expr |
| 228 |
|
| 229 |
|
| 230 |
Value() Expr |
| 231 |
|
| 232 |
|
| 233 |
IsOptional() bool |
| 234 |
|
| 235 |
|
| 236 |
isEntryExpr() |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
type StructExpr interface { |
| 241 |
|
| 242 |
TypeName() string |
| 243 |
|
| 244 |
|
| 245 |
Fields() []EntryExpr |
| 246 |
|
| 247 |
|
| 248 |
isExpr() |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
type StructField interface { |
| 253 |
|
| 254 |
Name() string |
| 255 |
|
| 256 |
|
| 257 |
Value() Expr |
| 258 |
|
| 259 |
|
| 260 |
IsOptional() bool |
| 261 |
|
| 262 |
|
| 263 |
isEntryExpr() |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
type ComprehensionExpr interface { |
| 268 |
|
| 269 |
IterRange() Expr |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
IterVar() string |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
IterVar2() string |
| 284 |
|
| 285 |
|
| 286 |
HasIterVar2() bool |
| 287 |
|
| 288 |
|
| 289 |
AccuVar() string |
| 290 |
|
| 291 |
|
| 292 |
AccuInit() Expr |
| 293 |
|
| 294 |
|
| 295 |
LoopCondition() Expr |
| 296 |
|
| 297 |
|
| 298 |
LoopStep() Expr |
| 299 |
|
| 300 |
|
| 301 |
Result() Expr |
| 302 |
|
| 303 |
|
| 304 |
isExpr() |
| 305 |
} |
| 306 |
|
| 307 |
var _ Expr = &expr{} |
| 308 |
|
| 309 |
type expr struct { |
| 310 |
id int64 |
| 311 |
exprKindCase |
| 312 |
} |
| 313 |
|
| 314 |
type exprKindCase interface { |
| 315 |
Kind() ExprKind |
| 316 |
|
| 317 |
renumberIDs(IDGenerator) |
| 318 |
|
| 319 |
isExpr() |
| 320 |
} |
| 321 |
|
| 322 |
func (e *expr) ID() int64 { |
| 323 |
if e == nil { |
| 324 |
return 0 |
| 325 |
} |
| 326 |
return e.id |
| 327 |
} |
| 328 |
|
| 329 |
func (e *expr) Kind() ExprKind { |
| 330 |
if e == nil || e.exprKindCase == nil { |
| 331 |
return UnspecifiedExprKind |
| 332 |
} |
| 333 |
return e.exprKindCase.Kind() |
| 334 |
} |
| 335 |
|
| 336 |
func (e *expr) AsCall() CallExpr { |
| 337 |
if e.Kind() != CallKind { |
| 338 |
return nilCall |
| 339 |
} |
| 340 |
return e.exprKindCase.(CallExpr) |
| 341 |
} |
| 342 |
|
| 343 |
func (e *expr) AsComprehension() ComprehensionExpr { |
| 344 |
if e.Kind() != ComprehensionKind { |
| 345 |
return nilCompre |
| 346 |
} |
| 347 |
return e.exprKindCase.(ComprehensionExpr) |
| 348 |
} |
| 349 |
|
| 350 |
func (e *expr) AsIdent() string { |
| 351 |
if e.Kind() != IdentKind { |
| 352 |
return "" |
| 353 |
} |
| 354 |
return string(e.exprKindCase.(baseIdentExpr)) |
| 355 |
} |
| 356 |
|
| 357 |
func (e *expr) AsLiteral() ref.Val { |
| 358 |
if e.Kind() != LiteralKind { |
| 359 |
return nil |
| 360 |
} |
| 361 |
return e.exprKindCase.(*baseLiteral).Val |
| 362 |
} |
| 363 |
|
| 364 |
func (e *expr) AsList() ListExpr { |
| 365 |
if e.Kind() != ListKind { |
| 366 |
return nilList |
| 367 |
} |
| 368 |
return e.exprKindCase.(ListExpr) |
| 369 |
} |
| 370 |
|
| 371 |
func (e *expr) AsMap() MapExpr { |
| 372 |
if e.Kind() != MapKind { |
| 373 |
return nilMap |
| 374 |
} |
| 375 |
return e.exprKindCase.(MapExpr) |
| 376 |
} |
| 377 |
|
| 378 |
func (e *expr) AsSelect() SelectExpr { |
| 379 |
if e.Kind() != SelectKind { |
| 380 |
return nilSel |
| 381 |
} |
| 382 |
return e.exprKindCase.(SelectExpr) |
| 383 |
} |
| 384 |
|
| 385 |
func (e *expr) AsStruct() StructExpr { |
| 386 |
if e.Kind() != StructKind { |
| 387 |
return nilStruct |
| 388 |
} |
| 389 |
return e.exprKindCase.(StructExpr) |
| 390 |
} |
| 391 |
|
| 392 |
func (e *expr) SetKindCase(other Expr) { |
| 393 |
if e == nil { |
| 394 |
return |
| 395 |
} |
| 396 |
if other == nil { |
| 397 |
e.exprKindCase = nil |
| 398 |
return |
| 399 |
} |
| 400 |
switch other.Kind() { |
| 401 |
case CallKind: |
| 402 |
c := other.AsCall() |
| 403 |
e.exprKindCase = &baseCallExpr{ |
| 404 |
function: c.FunctionName(), |
| 405 |
target: c.Target(), |
| 406 |
args: c.Args(), |
| 407 |
isMember: c.IsMemberFunction(), |
| 408 |
} |
| 409 |
case ComprehensionKind: |
| 410 |
c := other.AsComprehension() |
| 411 |
e.exprKindCase = &baseComprehensionExpr{ |
| 412 |
iterRange: c.IterRange(), |
| 413 |
iterVar: c.IterVar(), |
| 414 |
iterVar2: c.IterVar2(), |
| 415 |
accuVar: c.AccuVar(), |
| 416 |
accuInit: c.AccuInit(), |
| 417 |
loopCond: c.LoopCondition(), |
| 418 |
loopStep: c.LoopStep(), |
| 419 |
result: c.Result(), |
| 420 |
} |
| 421 |
case IdentKind: |
| 422 |
e.exprKindCase = baseIdentExpr(other.AsIdent()) |
| 423 |
case ListKind: |
| 424 |
l := other.AsList() |
| 425 |
optIndexMap := make(map[int32]struct{}, len(l.OptionalIndices())) |
| 426 |
for _, idx := range l.OptionalIndices() { |
| 427 |
optIndexMap[idx] = struct{}{} |
| 428 |
} |
| 429 |
e.exprKindCase = &baseListExpr{ |
| 430 |
elements: l.Elements(), |
| 431 |
optIndices: l.OptionalIndices(), |
| 432 |
optIndexMap: optIndexMap, |
| 433 |
} |
| 434 |
case LiteralKind: |
| 435 |
e.exprKindCase = &baseLiteral{Val: other.AsLiteral()} |
| 436 |
case MapKind: |
| 437 |
e.exprKindCase = &baseMapExpr{ |
| 438 |
entries: other.AsMap().Entries(), |
| 439 |
} |
| 440 |
case SelectKind: |
| 441 |
s := other.AsSelect() |
| 442 |
e.exprKindCase = &baseSelectExpr{ |
| 443 |
operand: s.Operand(), |
| 444 |
field: s.FieldName(), |
| 445 |
testOnly: s.IsTestOnly(), |
| 446 |
} |
| 447 |
case StructKind: |
| 448 |
s := other.AsStruct() |
| 449 |
e.exprKindCase = &baseStructExpr{ |
| 450 |
typeName: s.TypeName(), |
| 451 |
fields: s.Fields(), |
| 452 |
} |
| 453 |
case UnspecifiedExprKind: |
| 454 |
e.exprKindCase = nil |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
func (e *expr) RenumberIDs(idGen IDGenerator) { |
| 459 |
if e == nil { |
| 460 |
return |
| 461 |
} |
| 462 |
e.id = idGen(e.id) |
| 463 |
if e.exprKindCase != nil { |
| 464 |
e.exprKindCase.renumberIDs(idGen) |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
type baseCallExpr struct { |
| 469 |
function string |
| 470 |
target Expr |
| 471 |
args []Expr |
| 472 |
isMember bool |
| 473 |
} |
| 474 |
|
| 475 |
func (*baseCallExpr) Kind() ExprKind { |
| 476 |
return CallKind |
| 477 |
} |
| 478 |
|
| 479 |
func (e *baseCallExpr) FunctionName() string { |
| 480 |
if e == nil { |
| 481 |
return "" |
| 482 |
} |
| 483 |
return e.function |
| 484 |
} |
| 485 |
|
| 486 |
func (e *baseCallExpr) IsMemberFunction() bool { |
| 487 |
if e == nil { |
| 488 |
return false |
| 489 |
} |
| 490 |
return e.isMember |
| 491 |
} |
| 492 |
|
| 493 |
func (e *baseCallExpr) Target() Expr { |
| 494 |
if e == nil || !e.IsMemberFunction() { |
| 495 |
return nilExpr |
| 496 |
} |
| 497 |
return e.target |
| 498 |
} |
| 499 |
|
| 500 |
func (e *baseCallExpr) Args() []Expr { |
| 501 |
if e == nil { |
| 502 |
return []Expr{} |
| 503 |
} |
| 504 |
return e.args |
| 505 |
} |
| 506 |
|
| 507 |
func (e *baseCallExpr) renumberIDs(idGen IDGenerator) { |
| 508 |
if e.IsMemberFunction() { |
| 509 |
e.Target().RenumberIDs(idGen) |
| 510 |
} |
| 511 |
for _, arg := range e.Args() { |
| 512 |
arg.RenumberIDs(idGen) |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
func (*baseCallExpr) isExpr() {} |
| 517 |
|
| 518 |
var _ ComprehensionExpr = &baseComprehensionExpr{} |
| 519 |
|
| 520 |
type baseComprehensionExpr struct { |
| 521 |
iterRange Expr |
| 522 |
iterVar string |
| 523 |
iterVar2 string |
| 524 |
accuVar string |
| 525 |
accuInit Expr |
| 526 |
loopCond Expr |
| 527 |
loopStep Expr |
| 528 |
result Expr |
| 529 |
} |
| 530 |
|
| 531 |
func (*baseComprehensionExpr) Kind() ExprKind { |
| 532 |
return ComprehensionKind |
| 533 |
} |
| 534 |
|
| 535 |
func (e *baseComprehensionExpr) IterRange() Expr { |
| 536 |
if e == nil { |
| 537 |
return nilExpr |
| 538 |
} |
| 539 |
return e.iterRange |
| 540 |
} |
| 541 |
|
| 542 |
func (e *baseComprehensionExpr) IterVar() string { |
| 543 |
return e.iterVar |
| 544 |
} |
| 545 |
|
| 546 |
func (e *baseComprehensionExpr) IterVar2() string { |
| 547 |
return e.iterVar2 |
| 548 |
} |
| 549 |
|
| 550 |
func (e *baseComprehensionExpr) HasIterVar2() bool { |
| 551 |
return e.iterVar2 != "" |
| 552 |
} |
| 553 |
|
| 554 |
func (e *baseComprehensionExpr) AccuVar() string { |
| 555 |
return e.accuVar |
| 556 |
} |
| 557 |
|
| 558 |
func (e *baseComprehensionExpr) AccuInit() Expr { |
| 559 |
if e == nil { |
| 560 |
return nilExpr |
| 561 |
} |
| 562 |
return e.accuInit |
| 563 |
} |
| 564 |
|
| 565 |
func (e *baseComprehensionExpr) LoopCondition() Expr { |
| 566 |
if e == nil { |
| 567 |
return nilExpr |
| 568 |
} |
| 569 |
return e.loopCond |
| 570 |
} |
| 571 |
|
| 572 |
func (e *baseComprehensionExpr) LoopStep() Expr { |
| 573 |
if e == nil { |
| 574 |
return nilExpr |
| 575 |
} |
| 576 |
return e.loopStep |
| 577 |
} |
| 578 |
|
| 579 |
func (e *baseComprehensionExpr) Result() Expr { |
| 580 |
if e == nil { |
| 581 |
return nilExpr |
| 582 |
} |
| 583 |
return e.result |
| 584 |
} |
| 585 |
|
| 586 |
func (e *baseComprehensionExpr) renumberIDs(idGen IDGenerator) { |
| 587 |
e.IterRange().RenumberIDs(idGen) |
| 588 |
e.AccuInit().RenumberIDs(idGen) |
| 589 |
e.LoopCondition().RenumberIDs(idGen) |
| 590 |
e.LoopStep().RenumberIDs(idGen) |
| 591 |
e.Result().RenumberIDs(idGen) |
| 592 |
} |
| 593 |
|
| 594 |
func (*baseComprehensionExpr) isExpr() {} |
| 595 |
|
| 596 |
var _ exprKindCase = baseIdentExpr("") |
| 597 |
|
| 598 |
type baseIdentExpr string |
| 599 |
|
| 600 |
func (baseIdentExpr) Kind() ExprKind { |
| 601 |
return IdentKind |
| 602 |
} |
| 603 |
|
| 604 |
func (e baseIdentExpr) renumberIDs(IDGenerator) {} |
| 605 |
|
| 606 |
func (baseIdentExpr) isExpr() {} |
| 607 |
|
| 608 |
var _ exprKindCase = &baseLiteral{} |
| 609 |
var _ ref.Val = &baseLiteral{} |
| 610 |
|
| 611 |
type baseLiteral struct { |
| 612 |
ref.Val |
| 613 |
} |
| 614 |
|
| 615 |
func (*baseLiteral) Kind() ExprKind { |
| 616 |
return LiteralKind |
| 617 |
} |
| 618 |
|
| 619 |
func (l *baseLiteral) renumberIDs(IDGenerator) {} |
| 620 |
|
| 621 |
func (*baseLiteral) isExpr() {} |
| 622 |
|
| 623 |
var _ ListExpr = &baseListExpr{} |
| 624 |
|
| 625 |
type baseListExpr struct { |
| 626 |
elements []Expr |
| 627 |
optIndices []int32 |
| 628 |
optIndexMap map[int32]struct{} |
| 629 |
} |
| 630 |
|
| 631 |
func (*baseListExpr) Kind() ExprKind { |
| 632 |
return ListKind |
| 633 |
} |
| 634 |
|
| 635 |
func (e *baseListExpr) Elements() []Expr { |
| 636 |
if e == nil { |
| 637 |
return []Expr{} |
| 638 |
} |
| 639 |
return e.elements |
| 640 |
} |
| 641 |
|
| 642 |
func (e *baseListExpr) IsOptional(index int32) bool { |
| 643 |
_, found := e.optIndexMap[index] |
| 644 |
return found |
| 645 |
} |
| 646 |
|
| 647 |
func (e *baseListExpr) OptionalIndices() []int32 { |
| 648 |
if e == nil { |
| 649 |
return []int32{} |
| 650 |
} |
| 651 |
return e.optIndices |
| 652 |
} |
| 653 |
|
| 654 |
func (e *baseListExpr) Size() int { |
| 655 |
return len(e.Elements()) |
| 656 |
} |
| 657 |
|
| 658 |
func (e *baseListExpr) renumberIDs(idGen IDGenerator) { |
| 659 |
for _, elem := range e.Elements() { |
| 660 |
elem.RenumberIDs(idGen) |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
func (*baseListExpr) isExpr() {} |
| 665 |
|
| 666 |
type baseMapExpr struct { |
| 667 |
entries []EntryExpr |
| 668 |
} |
| 669 |
|
| 670 |
func (*baseMapExpr) Kind() ExprKind { |
| 671 |
return MapKind |
| 672 |
} |
| 673 |
|
| 674 |
func (e *baseMapExpr) Entries() []EntryExpr { |
| 675 |
if e == nil { |
| 676 |
return []EntryExpr{} |
| 677 |
} |
| 678 |
return e.entries |
| 679 |
} |
| 680 |
|
| 681 |
func (e *baseMapExpr) Size() int { |
| 682 |
return len(e.Entries()) |
| 683 |
} |
| 684 |
|
| 685 |
func (e *baseMapExpr) renumberIDs(idGen IDGenerator) { |
| 686 |
for _, entry := range e.Entries() { |
| 687 |
entry.RenumberIDs(idGen) |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
func (*baseMapExpr) isExpr() {} |
| 692 |
|
| 693 |
type baseSelectExpr struct { |
| 694 |
operand Expr |
| 695 |
field string |
| 696 |
testOnly bool |
| 697 |
} |
| 698 |
|
| 699 |
func (*baseSelectExpr) Kind() ExprKind { |
| 700 |
return SelectKind |
| 701 |
} |
| 702 |
|
| 703 |
func (e *baseSelectExpr) Operand() Expr { |
| 704 |
if e == nil || e.operand == nil { |
| 705 |
return nilExpr |
| 706 |
} |
| 707 |
return e.operand |
| 708 |
} |
| 709 |
|
| 710 |
func (e *baseSelectExpr) FieldName() string { |
| 711 |
if e == nil { |
| 712 |
return "" |
| 713 |
} |
| 714 |
return e.field |
| 715 |
} |
| 716 |
|
| 717 |
func (e *baseSelectExpr) IsTestOnly() bool { |
| 718 |
if e == nil { |
| 719 |
return false |
| 720 |
} |
| 721 |
return e.testOnly |
| 722 |
} |
| 723 |
|
| 724 |
func (e *baseSelectExpr) renumberIDs(idGen IDGenerator) { |
| 725 |
e.Operand().RenumberIDs(idGen) |
| 726 |
} |
| 727 |
|
| 728 |
func (*baseSelectExpr) isExpr() {} |
| 729 |
|
| 730 |
type baseStructExpr struct { |
| 731 |
typeName string |
| 732 |
fields []EntryExpr |
| 733 |
} |
| 734 |
|
| 735 |
func (*baseStructExpr) Kind() ExprKind { |
| 736 |
return StructKind |
| 737 |
} |
| 738 |
|
| 739 |
func (e *baseStructExpr) TypeName() string { |
| 740 |
if e == nil { |
| 741 |
return "" |
| 742 |
} |
| 743 |
return e.typeName |
| 744 |
} |
| 745 |
|
| 746 |
func (e *baseStructExpr) Fields() []EntryExpr { |
| 747 |
if e == nil { |
| 748 |
return []EntryExpr{} |
| 749 |
} |
| 750 |
return e.fields |
| 751 |
} |
| 752 |
|
| 753 |
func (e *baseStructExpr) renumberIDs(idGen IDGenerator) { |
| 754 |
for _, f := range e.Fields() { |
| 755 |
f.RenumberIDs(idGen) |
| 756 |
} |
| 757 |
} |
| 758 |
|
| 759 |
func (*baseStructExpr) isExpr() {} |
| 760 |
|
| 761 |
type entryExprKindCase interface { |
| 762 |
Kind() EntryExprKind |
| 763 |
|
| 764 |
renumberIDs(IDGenerator) |
| 765 |
|
| 766 |
isEntryExpr() |
| 767 |
} |
| 768 |
|
| 769 |
var _ EntryExpr = &entryExpr{} |
| 770 |
|
| 771 |
type entryExpr struct { |
| 772 |
id int64 |
| 773 |
entryExprKindCase |
| 774 |
} |
| 775 |
|
| 776 |
func (e *entryExpr) ID() int64 { |
| 777 |
return e.id |
| 778 |
} |
| 779 |
|
| 780 |
func (e *entryExpr) AsMapEntry() MapEntry { |
| 781 |
if e.Kind() != MapEntryKind { |
| 782 |
return nilMapEntry |
| 783 |
} |
| 784 |
return e.entryExprKindCase.(MapEntry) |
| 785 |
} |
| 786 |
|
| 787 |
func (e *entryExpr) AsStructField() StructField { |
| 788 |
if e.Kind() != StructFieldKind { |
| 789 |
return nilStructField |
| 790 |
} |
| 791 |
return e.entryExprKindCase.(StructField) |
| 792 |
} |
| 793 |
|
| 794 |
func (e *entryExpr) RenumberIDs(idGen IDGenerator) { |
| 795 |
e.id = idGen(e.id) |
| 796 |
e.entryExprKindCase.renumberIDs(idGen) |
| 797 |
} |
| 798 |
|
| 799 |
type baseMapEntry struct { |
| 800 |
key Expr |
| 801 |
value Expr |
| 802 |
isOptional bool |
| 803 |
} |
| 804 |
|
| 805 |
func (e *baseMapEntry) Kind() EntryExprKind { |
| 806 |
return MapEntryKind |
| 807 |
} |
| 808 |
|
| 809 |
func (e *baseMapEntry) Key() Expr { |
| 810 |
if e == nil { |
| 811 |
return nilExpr |
| 812 |
} |
| 813 |
return e.key |
| 814 |
} |
| 815 |
|
| 816 |
func (e *baseMapEntry) Value() Expr { |
| 817 |
if e == nil { |
| 818 |
return nilExpr |
| 819 |
} |
| 820 |
return e.value |
| 821 |
} |
| 822 |
|
| 823 |
func (e *baseMapEntry) IsOptional() bool { |
| 824 |
if e == nil { |
| 825 |
return false |
| 826 |
} |
| 827 |
return e.isOptional |
| 828 |
} |
| 829 |
|
| 830 |
func (e *baseMapEntry) renumberIDs(idGen IDGenerator) { |
| 831 |
e.Key().RenumberIDs(idGen) |
| 832 |
e.Value().RenumberIDs(idGen) |
| 833 |
} |
| 834 |
|
| 835 |
func (*baseMapEntry) isEntryExpr() {} |
| 836 |
|
| 837 |
type baseStructField struct { |
| 838 |
field string |
| 839 |
value Expr |
| 840 |
isOptional bool |
| 841 |
} |
| 842 |
|
| 843 |
func (f *baseStructField) Kind() EntryExprKind { |
| 844 |
return StructFieldKind |
| 845 |
} |
| 846 |
|
| 847 |
func (f *baseStructField) Name() string { |
| 848 |
if f == nil { |
| 849 |
return "" |
| 850 |
} |
| 851 |
return f.field |
| 852 |
} |
| 853 |
|
| 854 |
func (f *baseStructField) Value() Expr { |
| 855 |
if f == nil { |
| 856 |
return nilExpr |
| 857 |
} |
| 858 |
return f.value |
| 859 |
} |
| 860 |
|
| 861 |
func (f *baseStructField) IsOptional() bool { |
| 862 |
if f == nil { |
| 863 |
return false |
| 864 |
} |
| 865 |
return f.isOptional |
| 866 |
} |
| 867 |
|
| 868 |
func (f *baseStructField) renumberIDs(idGen IDGenerator) { |
| 869 |
f.Value().RenumberIDs(idGen) |
| 870 |
} |
| 871 |
|
| 872 |
func (*baseStructField) isEntryExpr() {} |
| 873 |
|
| 874 |
var ( |
| 875 |
nilExpr *expr = nil |
| 876 |
nilCall *baseCallExpr = nil |
| 877 |
nilCompre *baseComprehensionExpr = nil |
| 878 |
nilList *baseListExpr = nil |
| 879 |
nilMap *baseMapExpr = nil |
| 880 |
nilMapEntry *baseMapEntry = nil |
| 881 |
nilSel *baseSelectExpr = nil |
| 882 |
nilStruct *baseStructExpr = nil |
| 883 |
nilStructField *baseStructField = nil |
| 884 |
) |