summaryrefslogtreecommitdiff
path: root/source/slang/expr-defs.h
blob: 8afa93fbdf6bd41414a4a82fa397fc834db4e3ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// expr-defs.h

// Syntax class definitions for expressions.


// Base class for expressions that will reference declarations
ABSTRACT_SYNTAX_CLASS(DeclRefExpr, Expr)

// The scope in which to perform lookup
    FIELD(RefPtr<Scope>, scope)

    // The declaration of the symbol being referenced
    DECL_FIELD(DeclRef<Decl>, declRef)

    // The name of the symbol being referenced
    FIELD(Name*, name)
END_SYNTAX_CLASS()

SIMPLE_SYNTAX_CLASS(VarExpr, DeclRefExpr)

// An expression that references an overloaded set of declarations
// having the same name.
SYNTAX_CLASS(OverloadedExpr, Expr)

    // Optional: the base expression is this overloaded result
    // arose from a member-reference expression.
    SYNTAX_FIELD(RefPtr<Expr>, base)

    // The lookup result that was ambiguous
    FIELD(LookupResult, lookupResult2)
END_SYNTAX_CLASS()

// An expression that references an overloaded set of declarations
// having the same name.
SYNTAX_CLASS(OverloadedExpr2, Expr)

    // Optional: the base expression is this overloaded result
    // arose from a member-reference expression.
    SYNTAX_FIELD(RefPtr<Expr>, base)

    // The lookup result that was ambiguous
    FIELD(List<RefPtr<Expr>>, candidiateExprs)
END_SYNTAX_CLASS()

ABSTRACT_SYNTAX_CLASS(LiteralExpr, Expr)
    // The token that was used to express the literal. This can be
    // used to get the raw text of the literal, including any suffix.
    FIELD(Token, token)
END_SYNTAX_CLASS()

SYNTAX_CLASS(IntegerLiteralExpr, LiteralExpr)
    FIELD(IntegerLiteralValue, value)
END_SYNTAX_CLASS()

SYNTAX_CLASS(FloatingPointLiteralExpr, LiteralExpr)
    FIELD(FloatingPointLiteralValue, value)
END_SYNTAX_CLASS()

SYNTAX_CLASS(BoolLiteralExpr, LiteralExpr)
    FIELD(bool, value)
END_SYNTAX_CLASS()

SYNTAX_CLASS(StringLiteralExpr, LiteralExpr)
    // TODO: consider storing the "segments" of the string
    // literal, in the case where multiple literals were
    //lined up at the lexer level, e.g.:
    //
    //      "first" "second" "third"
    //
    FIELD(String, value)
END_SYNTAX_CLASS()

// An initializer list, e.g. `{ 1, 2, 3 }`
SYNTAX_CLASS(InitializerListExpr, Expr)
    SYNTAX_FIELD(List<RefPtr<Expr>>, args)
END_SYNTAX_CLASS()

// A base class for expressions with arguments
ABSTRACT_SYNTAX_CLASS(ExprWithArgsBase, Expr)
    SYNTAX_FIELD(List<RefPtr<Expr>>, Arguments)
END_SYNTAX_CLASS()

// An aggregate type constructor
SYNTAX_CLASS(AggTypeCtorExpr, ExprWithArgsBase)
    SYNTAX_FIELD(TypeExp, base);
END_SYNTAX_CLASS()


// A base expression being applied to arguments: covers
// both ordinary `()` function calls and `<>` generic application
ABSTRACT_SYNTAX_CLASS(AppExprBase, ExprWithArgsBase)
    SYNTAX_FIELD(RefPtr<Expr>, FunctionExpr)
END_SYNTAX_CLASS()

SIMPLE_SYNTAX_CLASS(InvokeExpr, AppExprBase)

SIMPLE_SYNTAX_CLASS(OperatorExpr, InvokeExpr)

SIMPLE_SYNTAX_CLASS(InfixExpr  , OperatorExpr)
SIMPLE_SYNTAX_CLASS(PrefixExpr , OperatorExpr)
SIMPLE_SYNTAX_CLASS(PostfixExpr, OperatorExpr)

SYNTAX_CLASS(IndexExpr, Expr)
    SYNTAX_FIELD(RefPtr<Expr>, BaseExpression)
    SYNTAX_FIELD(RefPtr<Expr>, IndexExpression)
END_SYNTAX_CLASS()

SYNTAX_CLASS(MemberExpr, DeclRefExpr)
    SYNTAX_FIELD(RefPtr<Expr>, BaseExpression)
END_SYNTAX_CLASS()

// Member looked up on a type, rather than a value
SYNTAX_CLASS(StaticMemberExpr, DeclRefExpr)
    SYNTAX_FIELD(RefPtr<Expr>, BaseExpression)
END_SYNTAX_CLASS()

SYNTAX_CLASS(SwizzleExpr, Expr)
    SYNTAX_FIELD(RefPtr<Expr>, base)
    FIELD(int, elementCount)
    FIELD(int, elementIndices[4])
END_SYNTAX_CLASS()

// A dereference of a pointer or pointer-like type
SYNTAX_CLASS(DerefExpr, Expr)
    SYNTAX_FIELD(RefPtr<Expr>, base)
END_SYNTAX_CLASS()

// Any operation that performs type-casting
SYNTAX_CLASS(TypeCastExpr, InvokeExpr)
//    SYNTAX_FIELD(TypeExp, TargetType)
//    SYNTAX_FIELD(RefPtr<Expr>, Expression)
END_SYNTAX_CLASS()

// An explicit type-cast that appear in the user's code with `(type) expr` syntax
SYNTAX_CLASS(ExplicitCastExpr, TypeCastExpr)
END_SYNTAX_CLASS()

// An implicit type-cast inserted during semantic checking
SYNTAX_CLASS(ImplicitCastExpr, TypeCastExpr)
END_SYNTAX_CLASS()

    /// A cast from a value to an interface ("existential") type.
SYNTAX_CLASS(CastToInterfaceExpr, Expr)
RAW(
        /// The value being cast to an interface type
    RefPtr<Expr>    valueArg;

        /// A witness showing that `valueArg` conforms to the chosen interface
    RefPtr<Val>     witnessArg;
)
END_SYNTAX_CLASS()

SIMPLE_SYNTAX_CLASS(SelectExpr, OperatorExpr)

SIMPLE_SYNTAX_CLASS(GenericAppExpr, AppExprBase)

// An expression representing re-use of the syntax for a type in more
// than once conceptually-distinct declaration
SYNTAX_CLASS(SharedTypeExpr, Expr)
    // The underlying type expression that we want to share
    SYNTAX_FIELD(TypeExp, base)
END_SYNTAX_CLASS()

SYNTAX_CLASS(AssignExpr, Expr)
    SYNTAX_FIELD(RefPtr<Expr>, left);
    SYNTAX_FIELD(RefPtr<Expr>, right);
END_SYNTAX_CLASS()

// Just an expression inside parentheses `(exp)`
//
// We keep this around explicitly to be sure we don't lose any structure
// when we do rewriter stuff.
SYNTAX_CLASS(ParenExpr, Expr)
    SYNTAX_FIELD(RefPtr<Expr>, base);
END_SYNTAX_CLASS()

// An object-oriented `this` expression, used to
// refer to the current instance of an enclosing type.
SYNTAX_CLASS(ThisExpr, Expr)
    FIELD(RefPtr<Scope>, scope);
END_SYNTAX_CLASS()

// An expression that binds a temporary variable in a local expression context
SYNTAX_CLASS(LetExpr, Expr)
RAW(
    RefPtr<VarDecl> decl;
    RefPtr<Expr> body;
)
END_SYNTAX_CLASS()

SYNTAX_CLASS(ExtractExistentialValueExpr, Expr)
RAW(
    DeclRef<VarDeclBase> declRef;
)
END_SYNTAX_CLASS()

    /// A type expression of the form `__TaggedUnion(A, ...)`.
    ///
    /// An expression of this form will resolve to a `TaggedUnionType`
    /// when checked.
    ///
SYNTAX_CLASS(TaggedUnionTypeExpr, Expr)
RAW(
    List<TypeExp> caseTypes;
)
END_SYNTAX_CLASS()