microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
compiler/qsc/src/lib.rs
114lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | pub mod codegen; |
| 5 | pub mod compile; |
| 6 | pub mod error; |
| 7 | pub mod incremental; |
| 8 | pub mod interpret; |
| 9 | pub mod location; |
| 10 | pub mod packages; |
| 11 | pub mod target; |
| 12 | pub mod test_callables { |
| 13 | use qsc_data_structures::line_column::{Encoding, Range}; |
| 14 | use qsc_frontend::compile::CompileUnit; |
| 15 | |
| 16 | use crate::location::Location; |
| 17 | |
| 18 | pub struct TestDescriptor { |
| 19 | pub callable_name: String, |
| 20 | pub location: Location, |
| 21 | } |
| 22 | |
| 23 | pub fn collect_test_callables( |
| 24 | unit: &CompileUnit |
| 25 | ) -> Result<impl Iterator<Item = TestDescriptor> + '_, String> { |
| 26 | let test_callables = unit.package.collect_test_callables()?; |
| 27 | |
| 28 | Ok(test_callables.into_iter().map(|(name, span)| { |
| 29 | let source = unit |
| 30 | .sources |
| 31 | .find_by_offset(span.lo) |
| 32 | .expect("source should exist for offset"); |
| 33 | |
| 34 | let location = Location { |
| 35 | source: source.name.clone(), |
| 36 | range: Range::from_span( |
| 37 | // TODO(@sezna) ask @minestarks if this is correct |
| 38 | Encoding::Utf8, |
| 39 | &source.contents, |
| 40 | &(span - source.offset), |
| 41 | ), |
| 42 | }; |
| 43 | TestDescriptor { |
| 44 | callable_name: name, |
| 45 | location, |
| 46 | } |
| 47 | })) |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | pub use qsc_formatter::formatter; |
| 52 | |
| 53 | pub use qsc_frontend::compile::{CompileUnit, PackageStore, SourceContents, SourceMap, SourceName}; |
| 54 | |
| 55 | pub mod resolve { |
| 56 | pub use qsc_frontend::resolve::{path_as_field_accessor, Local, LocalKind, Locals, Res}; |
| 57 | } |
| 58 | |
| 59 | pub mod fir { |
| 60 | pub use qsc_fir::{fir::*, *}; |
| 61 | } |
| 62 | |
| 63 | pub mod hir { |
| 64 | pub use qsc_hir::{hir::*, *}; |
| 65 | } |
| 66 | |
| 67 | pub mod ast { |
| 68 | pub use qsc_ast::{ast::*, *}; |
| 69 | } |
| 70 | |
| 71 | pub mod project { |
| 72 | pub use qsc_project::{ |
| 73 | DirEntry, EntryType, Error, FileSystem, Manifest, ManifestDescriptor, PackageCache, |
| 74 | PackageGraphSources, |
| 75 | }; |
| 76 | } |
| 77 | |
| 78 | pub use qsc_data_structures::{ |
| 79 | functors::FunctorApp, language_features::LanguageFeatures, namespaces::*, span::Span, |
| 80 | target::TargetCapabilityFlags, |
| 81 | }; |
| 82 | |
| 83 | pub use qsc_passes::{lower_hir_to_fir, PackageType, PassContext}; |
| 84 | |
| 85 | pub mod line_column { |
| 86 | pub use qsc_data_structures::line_column::{Encoding, Position, Range}; |
| 87 | } |
| 88 | |
| 89 | pub use qsc_eval::{ |
| 90 | backend::{Backend, SparseSim}, |
| 91 | noise::PauliNoise, |
| 92 | state::{ |
| 93 | fmt_basis_state_label, fmt_complex, format_state_id, get_matrix_latex, get_phase, |
| 94 | get_state_latex, |
| 95 | }, |
| 96 | }; |
| 97 | |
| 98 | pub mod linter { |
| 99 | pub use qsc_linter::{run_lints, LintConfig, LintKind, LintLevel}; |
| 100 | } |
| 101 | |
| 102 | pub use qsc_doc_gen::{display, generate_docs}; |
| 103 | |
| 104 | pub mod circuit { |
| 105 | pub use qsc_circuit::{operations::*, Circuit, Operation}; |
| 106 | } |
| 107 | |
| 108 | pub mod parse { |
| 109 | pub use qsc_parse::{completion, top_level_nodes}; |
| 110 | } |
| 111 | |
| 112 | pub mod partial_eval { |
| 113 | pub use qsc_partial_eval::Error; |
| 114 | } |
| 115 | |