microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
billti/bloch

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

compiler/qsc_fir/src/assigner.rs

82lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use crate::fir::{BlockId, ExprId, LocalVarId, NodeId, PatId, StmtId};
5
6#[derive(Debug)]
7pub struct Assigner {
8 next_node: NodeId,
9 next_block: BlockId,
10 next_expr: ExprId,
11 next_pat: PatId,
12 next_stmt: StmtId,
13 next_local: LocalVarId,
14 stashed_local: LocalVarId,
15}
16
17impl Assigner {
18 #[must_use]
19 pub fn new() -> Self {
20 Self {
21 next_node: NodeId::FIRST,
22 next_block: BlockId::default(),
23 next_expr: ExprId::default(),
24 next_pat: PatId::default(),
25 next_stmt: StmtId::default(),
26 next_local: LocalVarId::default(),
27 stashed_local: LocalVarId::default(),
28 }
29 }
30
31 pub fn next_node(&mut self) -> NodeId {
32 let id = self.next_node;
33 self.next_node = id.successor();
34 id
35 }
36
37 pub fn next_block(&mut self) -> BlockId {
38 let id = self.next_block;
39 self.next_block = id.successor();
40 id
41 }
42
43 pub fn next_expr(&mut self) -> ExprId {
44 let id = self.next_expr;
45 self.next_expr = id.successor();
46 id
47 }
48
49 pub fn next_pat(&mut self) -> PatId {
50 let id = self.next_pat;
51 self.next_pat = id.successor();
52 id
53 }
54
55 pub fn next_stmt(&mut self) -> StmtId {
56 let id = self.next_stmt;
57 self.next_stmt = id.successor();
58 id
59 }
60
61 pub fn next_local(&mut self) -> LocalVarId {
62 let id = self.next_local;
63 self.next_local = id.successor();
64 id
65 }
66
67 pub fn stash_local(&mut self) {
68 self.stashed_local = self.next_local;
69 self.next_local = LocalVarId::default();
70 }
71
72 pub fn reset_local(&mut self) {
73 self.next_local = self.stashed_local;
74 self.stashed_local = LocalVarId::default();
75 }
76}
77
78impl Default for Assigner {
79 fn default() -> Self {
80 Self::new()
81 }
82}
83