Source file src/cmd/compile/internal/contraire/ast.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package contraire
     6  
     7  type prog struct{ decls []decl }
     8  
     9  // ============================== Decls ===============================
    10  
    11  type decl interface {
    12  	node
    13  	decl()
    14  }
    15  
    16  type constDecl struct {
    17  	name string
    18  	expr constExpr
    19  }
    20  
    21  type typeDecl struct {
    22  	name string
    23  	expr typeExpr
    24  }
    25  
    26  func (*constDecl) decl() {}
    27  func (*typeDecl) decl()  {}
    28  
    29  // ============================== Consts ==============================
    30  
    31  type constExpr interface {
    32  	node
    33  	constExpr()
    34  }
    35  
    36  type constName struct{ name string }
    37  type constLtrl struct{}
    38  
    39  func (*constName) constExpr() {}
    40  func (*constLtrl) constExpr() {}
    41  
    42  // ============================== Types ===============================
    43  
    44  type typeExpr interface {
    45  	node
    46  	typeExpr()
    47  }
    48  
    49  type typeName struct{ name string }
    50  type typeBasic struct{}
    51  type typePointer struct{ expr typeExpr }
    52  
    53  func (*typeName) typeExpr()    {}
    54  func (*typeBasic) typeExpr()   {}
    55  func (*typePointer) typeExpr() {}
    56  
    57  // ============================== Visitor =============================
    58  
    59  type node interface {
    60  	receive(visitor)
    61  }
    62  
    63  type visitor interface {
    64  	visitProg(*prog)
    65  	visitConstDecl(*constDecl)
    66  	visitTypeDecl(*typeDecl)
    67  	visitConstName(*constName)
    68  	visitConstLtrl(*constLtrl)
    69  	visitTypeName(*typeName)
    70  	visitTypeBasic(*typeBasic)
    71  	visitTypePointer(*typePointer)
    72  }
    73  
    74  func (x *prog) receive(v visitor)        { v.visitProg(x) }
    75  func (x *constDecl) receive(v visitor)   { v.visitConstDecl(x) }
    76  func (x *typeDecl) receive(v visitor)    { v.visitTypeDecl(x) }
    77  func (x *constName) receive(v visitor)   { v.visitConstName(x) }
    78  func (x *constLtrl) receive(v visitor)   { v.visitConstLtrl(x) }
    79  func (x *typeName) receive(v visitor)    { v.visitTypeName(x) }
    80  func (x *typeBasic) receive(v visitor)   { v.visitTypeBasic(x) }
    81  func (x *typePointer) receive(v visitor) { v.visitTypePointer(x) }
    82  

View as plain text