duskphantom_frontend/ir/decl.rs
1// Copyright 2024 Duskphantom Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16
17use super::*;
18
19/// A declaration.
20/// Example: `int x = 4;`
21#[derive(Clone, PartialEq, Debug)]
22pub enum Decl {
23 /// A declaration of a constant, optionally with assignment.
24 /// Example:
25 /// `const int x;` is `Const(Int, x, None)`
26 /// `const int x = 4;` is `Const(Int, x, Some(Int(4)))`
27 Const(Type, String, Option<Expr>),
28
29 /// A declaration of a variable, optionally with assignment.
30 /// Example:
31 /// `int x;` is `Var(Int, x, None)`
32 /// `int x = 4;` is `Var(Int, x, Some(Int(4)))`
33 Var(Type, String, Option<Expr>),
34
35 /// Stacked declarations.
36 /// Example:
37 /// `int x = 1, y = 2;` is `Stack([Var(Int, x, Some(Int(1))), Var(Int, y, Some(Int(2)))])`
38 Stack(Vec<Decl>),
39
40 /// A declaration of a function, optionally with implementation.
41 /// Example:
42 /// `void f(int x)` is `Func(Void, "f", [(Int, (Some("x"))], None)`
43 /// `void f() { ... }` is `Func(Void, "f", [], Some(...))`
44 Func(Type, String, Option<Box<Stmt>>),
45}