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/validate.rs

42lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use crate::{
5 fir::{Block, BlockId, Expr, ExprId, Package, Pat, PatId, Stmt, StmtId},
6 visit::Visitor,
7};
8
9pub struct Validator<'a> {
10 pub package: &'a Package,
11}
12
13pub fn validate(package: &Package, store: &crate::fir::PackageStore) {
14 let mut v = Validator { package };
15 v.validate(store);
16}
17
18/// Validates that the FIR is well-formed.
19/// Running `validate` will validate the entire package.
20impl Validator<'_> {
21 pub fn validate(&mut self, store: &crate::fir::PackageStore) {
22 self.visit_package(self.package, store);
23 }
24}
25
26impl<'a> Visitor<'a> for Validator<'a> {
27 fn get_block(&self, id: BlockId) -> &'a Block {
28 self.package.blocks.get(id).expect("block not found")
29 }
30
31 fn get_expr(&self, id: ExprId) -> &'a Expr {
32 self.package.exprs.get(id).expect("expr not found")
33 }
34
35 fn get_pat(&self, id: PatId) -> &'a Pat {
36 self.package.pats.get(id).expect("pat not found")
37 }
38
39 fn get_stmt(&self, id: StmtId) -> &'a Stmt {
40 self.package.stmts.get(id).expect("stmt not found")
41 }
42}
43