@@ -21,6 +21,85 @@ namespace lang {
2121
2222// / TreeView provides a statically-typed way to access the members of a TreeRef
2323// / instead of using TK_MATCH
24+ //
25+ // clang-format off
26+ //
27+ // A few notes on types and their aliases:
28+ // - List<T> is really a Tree with kind TK_LIST and elements as subtrees
29+ // - Maybe<T> is really a Tree with kind TK_OPTION that has 0 or 1 subtree of type T
30+ // - Builtin types are: Ident (TK_IDENT), String (TK_STRING)
31+ //
32+ // -- NB: dim_list can only contain Const and Ident trees
33+ // -- NB: dim_list is optional (can be empty)
34+ // Type = TensorType(ScalarType scalar_type, List<Expr> dim_list) TK_TENSOR_TYPE
35+ // Param = Param(Ident name, Type type) TK_PARAM
36+ //
37+ // Def = Def(Ident name, List<Param> params, List<Param> returns, List<Stmt> body) TK_DEF
38+ //
39+ // -- NB: reduction_variables are only filled during semantic analysis
40+ // Stmt = Comprehension(Ident lhs_ident, List<Ident> lhs_indices, TK_COMPREHENSION
41+ // AssignKind assignment, Expr rhs,
42+ // List<WhereClause> range_constraints,
43+ // Option<Equivalent> eqiuvalent_stmt,
44+ // List<Ident> reduction_variables)
45+ //
46+ // WhereClause = Let(Ident name, Expr expr) TK_LET
47+ // | RangeConstraint(Ident name, Expr l, Expr r) TK_RANGE_CONSTRAINT
48+ // | Exists(Expr expr) TK_EXISTS
49+ //
50+ // Equivalent = Equivalent(String name, List<Expr> accesses) TK_EQUIVALENT
51+ //
52+ // Expr = TernaryIf(Expr cond, Expr true_expr, Expr false_expr) TK_IF_EXPR
53+ // | BinOp(Expr lhs, Expr rhs)
54+ // | And TK_AND
55+ // | Or TK_OR
56+ // | Lt '<'
57+ // | Gt '>'
58+ // | Eq TK_EQ
59+ // | Le TK_LE
60+ // | Ge TK_GE
61+ // | Ne TK_NE
62+ // | Add '+'
63+ // | Sub '-'
64+ // | Mul '*'
65+ // | Div '/'
66+ // | UnaryOp(Expr expr)
67+ // | Not '!'
68+ // | USub '-'
69+ // | Const(Number value, ScalarType type) TK_CONST
70+ // | Cast(Expr expr, ScalarType type) TK_CAST
71+ // | Select(Expr base, Number dim) '.'
72+ // -- XXX: Apply is emitted by the parser, and gets desugared into
73+ // -- Access and BuiltIn as part of the Sema pass.
74+ // | Apply(Ident name, List<Expr> args) TK_APPLY
75+ // | Access(Ident name, List<Expr> args) TK_ACCESS
76+ // | BuiltIn(Ident name, List<Expr> args, Type type) TK_BUILT_IN
77+ // -- XXX: yes, Ident is a valid Expr too
78+ // | Ident name TK_IDENT
79+ //
80+ // ScalarType = Int8() TK_INT8
81+ // | Int16() TK_INT16
82+ // | Int32() TK_INT32
83+ // | Int64() TK_INT64
84+ // | UInt8() TK_UINT8
85+ // | UInt16() TK_UINT16
86+ // | UInt32() TK_UINT32
87+ // | UInt64() TK_UINT64
88+ // | Bool() TK_BOOL
89+ // | Float() TK_FLOAT
90+ // | Double() TK_DOUBLE
91+ //
92+ // AssignKind = PlusEq() TK_PLUS_EQ
93+ // | TimesEq() TK_TIMES_EQ
94+ // | MinEq() TK_MIN_EQ
95+ // | MaxEq() TK_MAX_EQ
96+ // | PlusEqB() TK_PLUS_EQ_B
97+ // | TimesEqB() TK_TIMES_EQ_B
98+ // | MinEqB() TK_MIN_EQ_B
99+ // | MaxEqB() TK_MAX_EQ_B
100+ //
101+ // clang-format on
102+
24103struct TreeView {
25104 explicit TreeView (const TreeRef& tree_) : tree_(tree_) {}
26105 TreeRef tree () const {
0 commit comments