diff --git a/Cargo.lock b/Cargo.lock index 6c78ad8..fc3dfe7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1072,7 +1072,7 @@ dependencies = [ "include_dir", "indexmap 2.0.0", "indoc", - "libninja_hir", + "libninja_mir", "ln-core", "ln-macro", "log", @@ -1098,7 +1098,7 @@ dependencies = [ ] [[package]] -name = "libninja_hir" +name = "libninja_mir" version = "0.1.0" dependencies = [ "proc-macro2", @@ -1126,7 +1126,7 @@ dependencies = [ "convert_case 0.6.0", "include_dir", "indexmap 2.0.0", - "libninja_hir", + "libninja_mir", "openapiv3-extended", "proc-macro2", "quote", @@ -1142,7 +1142,7 @@ dependencies = [ name = "ln-macro" version = "0.1.0" dependencies = [ - "libninja_hir", + "libninja_mir", "pretty_assertions", "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 295747c..d9468e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = [ "libninja", "macro", "core", - "hir", + "mir", ] exclude = [ "commercial", diff --git a/core/Cargo.toml b/core/Cargo.toml index 3b957ac..262f20f 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -17,7 +17,7 @@ proc-macro2 = "1.0.63" tracing-ez = "0.3.0" indexmap = "2.0" syn = "2.0" -libninja_hir = { path = "../hir" } +libninja_mir = { path = "../mir" } include_dir = "0.7.3" tera = "1.19.0" diff --git a/core/src/extractor.rs b/core/src/extractor.rs index 6197629..b36f38a 100644 --- a/core/src/extractor.rs +++ b/core/src/extractor.rs @@ -6,7 +6,7 @@ use openapiv3::{APIKeyLocation, OpenAPI, Operation, PathItem, ReferenceOr, Schem use openapiv3 as oa; use tracing_ez::{span, warn}; -use hir::{Doc, Name, NewType}; +use mir::{Doc, Name, NewType}; pub use record::*; pub use resolution::{schema_to_ty, schema_ref_to_ty, schema_ref_to_ty_already_resolved}; pub use resolution::*; diff --git a/core/src/extractor/record.rs b/core/src/extractor/record.rs index a046a67..4f3aece 100644 --- a/core/src/extractor/record.rs +++ b/core/src/extractor/record.rs @@ -1,7 +1,7 @@ /// Records are the "model"s of the MIR world. model is a crazy overloaded word though. use openapiv3::{ObjectType, OpenAPI, ReferenceOr, Schema, SchemaData, SchemaKind, SchemaReference, StatusCode, StringType, Type}; -use hir::{Doc, Name}; +use mir::{Doc, Name}; use std::collections::{BTreeMap, HashMap}; use tracing_ez::warn; use crate::{extractor, mir2}; diff --git a/core/src/mir2.rs b/core/src/mir2.rs index d1b3a2e..8d6bd3e 100644 --- a/core/src/mir2.rs +++ b/core/src/mir2.rs @@ -8,7 +8,7 @@ use anyhow::Result; use convert_case::{Case, Casing}; use crate::{LibraryOptions, Language}; -pub use hir::{Doc, Name}; +pub use mir::{Doc, Name}; use openapiv3 as oa; #[derive(Debug, Clone, Copy, PartialEq)] diff --git a/core/src/options.rs b/core/src/options.rs index 1fc05eb..10eb457 100644 --- a/core/src/options.rs +++ b/core/src/options.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; use convert_case::{Case, Casing}; -use hir::{literal, Name, Literal}; +use mir::{literal, Name, Literal}; use crate::Language; #[derive(Debug, Clone, Default)] diff --git a/libninja/Cargo.toml b/libninja/Cargo.toml index efcf4e6..96fdb17 100644 --- a/libninja/Cargo.toml +++ b/libninja/Cargo.toml @@ -43,7 +43,7 @@ semver = "1.0.17" indexmap = "2.0" ln-macro = { path = "../macro" } ln-core = { path = "../core" } -libninja_hir = { path = "../hir" } +libninja_mir = { path = "../mir" } [dev-dependencies] env_logger = "0.10.0" diff --git a/libninja/src/rust.rs b/libninja/src/rust.rs index 66f68ad..501ecfd 100644 --- a/libninja/src/rust.rs +++ b/libninja/src/rust.rs @@ -12,20 +12,20 @@ use codegen::ToRustIdent; use codegen::ToRustType; use format::format_code; use ln_core::{copy_files, copy_templates, create_context, get_template_file, prepare_templates}; -use hir::{Visibility, Import, File}; +use ::mir::{Visibility, Import, File}; use ln_core::fs; use crate::{add_operation_models, extract_spec, LibraryOptions, MirSpec, OutputOptions, util}; pub use crate::rust::codegen::generate_example; use crate::rust::codegen::ToRustCode; use crate::rust::io::write_rust_file_to_path; -use crate::rust::mir::{generate_model_rs, generate_single_model_file}; +use crate::rust::lower_mir::{generate_model_rs, generate_single_model_file}; use crate::rust::request::{build_request_struct, generate_request_model_rs}; pub mod client; pub mod codegen; pub mod format; -pub mod mir; +pub mod lower_mir; pub mod request; mod io; mod serde; @@ -158,11 +158,11 @@ fn write_lib_rs(mir_spec: &MirSpec, extras: &Extras, spec: &OpenAPI, opts: &Outp }; let client_name = struct_Client.name.to_string(); - let template_path = opts.dest_path.join("template").join("src").join("hir"); + let template_path = opts.dest_path.join("template").join("src").join("../../mir"); let lib_rs_template = if template_path.exists() { fs::read_to_string(template_path)? } else { - let s = get_template_file("rust/src/hir"); + let s = get_template_file("rust/src/mir"); formatdoc!( r#" //! [`{client}`](struct.{client}.html) is the main entry point for this library. @@ -192,7 +192,7 @@ fn write_lib_rs(mir_spec: &MirSpec, extras: &Extras, spec: &OpenAPI, opts: &Outp #security }; - io::write_rust_to_path(&src_path.join("hir"), code, &lib_rs_template)?; + io::write_rust_to_path(&src_path.join("../../mir"), code, &lib_rs_template)?; Ok(()) } diff --git a/libninja/src/rust/client.rs b/libninja/src/rust/client.rs index 90260c2..e651ebc 100644 --- a/libninja/src/rust/client.rs +++ b/libninja/src/rust/client.rs @@ -3,8 +3,8 @@ use ln_core::extractor::{extract_response_success, extract_security_strategies, use crate::rust::codegen::{ToRustCode}; use ln_core::{extractor, Language, LibraryOptions, MirSpec, mir2}; use convert_case::{Case, Casing}; -use hir::{Doc, field, Function, Ident, Name}; -use hir::{Class, Field, FnArg, Visibility}; +use mir::{Doc, field, Function, Ident, Name}; +use mir::{Class, Field, FnArg, Visibility}; use openapiv3::{ APIKeyLocation, OpenAPI, Operation, ReferenceOr, RequestBody, Schema, SchemaKind, SecurityRequirement, SecurityScheme, StatusCode, diff --git a/libninja/src/rust/codegen.rs b/libninja/src/rust/codegen.rs index 830bc01..d707c50 100644 --- a/libninja/src/rust/codegen.rs +++ b/libninja/src/rust/codegen.rs @@ -6,7 +6,7 @@ use quote::{quote, TokenStreamExt}; use regex::{Captures, Regex}; use syn::Path; -use hir::{ArgIdent, Class, Doc, Field, File, Function, Ident, Import, ImportItem, Literal, Visibility}; +use mir::{ArgIdent, Class, Doc, Field, File, Function, Ident, Import, ImportItem, Literal, Visibility}; pub use typ::*; pub use example::*; pub use ident::*; @@ -425,7 +425,7 @@ pub fn formatted_code(code: impl ToRustCode) -> String { #[cfg(test)] mod tests { - use hir::{Ident, import, Import, Name}; + use mir::{Ident, import, Import, Name}; use crate::rust::codegen::{ToRustCode, ToRustIdent}; diff --git a/libninja/src/rust/codegen/example.rs b/libninja/src/rust/codegen/example.rs index 6a82300..699692f 100644 --- a/libninja/src/rust/codegen/example.rs +++ b/libninja/src/rust/codegen/example.rs @@ -1,7 +1,7 @@ use proc_macro2::TokenStream; use quote::quote; use ln_macro::rfunction; -use hir::{File, Import}; +use mir::{File, Import}; use crate::{Language, LibraryOptions, }; use ln_core::{mir2, mir2::{MirSpec, Parameter}}; use crate::rust::codegen; diff --git a/libninja/src/rust/codegen/ident.rs b/libninja/src/rust/codegen/ident.rs index fc83232..f3423d0 100644 --- a/libninja/src/rust/codegen/ident.rs +++ b/libninja/src/rust/codegen/ident.rs @@ -1,5 +1,5 @@ use convert_case::{Case, Casing}; -use hir::{Ident, Name}; +use mir::{Ident, Name}; use crate::rust::codegen; pub trait ToRustIdent { diff --git a/libninja/src/rust/io.rs b/libninja/src/rust/io.rs index 0f000ab..01f6867 100644 --- a/libninja/src/rust/io.rs +++ b/libninja/src/rust/io.rs @@ -5,7 +5,7 @@ use crate::rust::codegen::ToRustCode; use crate::rust::format::format_code; use crate::util; -pub fn write_rust_file_to_path(path: &Path, file: ::hir::File) -> anyhow::Result<()> { +pub fn write_rust_file_to_path(path: &Path, file: ::mir::File) -> anyhow::Result<()> { let code = file.to_rust_code(); write_rust_code_to_path(path, code) } diff --git a/libninja/src/rust/mir.rs b/libninja/src/rust/lower_mir.rs similarity index 99% rename from libninja/src/rust/mir.rs rename to libninja/src/rust/lower_mir.rs index 482d325..4c70df8 100644 --- a/libninja/src/rust/mir.rs +++ b/libninja/src/rust/lower_mir.rs @@ -7,8 +7,8 @@ use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; use tracing_ez::{info, span}; -use hir::{Field, File, Ident, Import, import, Name, Visibility}; -use hir as model; +use ::mir::{Field, File, Ident, Import, import, Name, Visibility}; +use ::mir as model; use ln_core::{extractor, mir2, MirSpec}; use ln_core::mir2::{DateSerialization, IntegerSerialization, MirField, NewType, Record, StrEnum, Struct, Ty, TypeAlias}; diff --git a/libninja/src/rust/request.rs b/libninja/src/rust/request.rs index 803d589..122ae47 100644 --- a/libninja/src/rust/request.rs +++ b/libninja/src/rust/request.rs @@ -14,8 +14,8 @@ use ln_core::extractor::{extract_response_success, schema_ref_to_ty, spec_define use ln_core::mir2; use ln_core::LibraryOptions; use ln_core::OutputOptions; -use hir::{Doc, doc, Ident, Name}; -use hir::{Class, Field, FnArg, Function, Visibility}; +use mir::{Doc, doc, Ident, Name}; +use mir::{Class, Field, FnArg, Function, Visibility}; use crate::rust::codegen::ToRustCode; use crate::rust::codegen::ToRustIdent; diff --git a/libninja/src/util.rs b/libninja/src/util.rs index d29a948..095a664 100644 --- a/libninja/src/util.rs +++ b/libninja/src/util.rs @@ -9,7 +9,7 @@ use url::Host; use ln_core::fs; use ln_core::OutputOptions; -pub use hir::build_struct; +pub use mir::build_struct; use crate::{MirSpec, }; diff --git a/libninja/tests/all_of/main.rs b/libninja/tests/all_of/main.rs index 63fad04..1d0e44f 100644 --- a/libninja/tests/all_of/main.rs +++ b/libninja/tests/all_of/main.rs @@ -20,7 +20,7 @@ fn record_for_schema(name: &str, schema: &str, spec: &OpenAPI) -> mir2::Record { fn formatted_code(record: mir2::Record) -> String { let config = LibraryConfig::default(); - let code = libninja::rust::mir::create_struct(&record, &config); + let code = libninja::rust::lower_mir::create_struct(&record, &config); libninja::rust::format::format_code(code).unwrap() } diff --git a/libninja/tests/regression/main.rs b/libninja/tests/regression/main.rs index 7ebfe91..f807c29 100644 --- a/libninja/tests/regression/main.rs +++ b/libninja/tests/regression/main.rs @@ -1,6 +1,6 @@ use openapiv3::{OpenAPI, ReferenceOr, Schema}; use ln_core::{mir2, mir2::Record}; -use libninja::rust::mir::StructExt; +use libninja::rust::lower_mir::StructExt; const LINK_TOKEN_CREATE: &str = include_str!("link_token_create.yaml"); diff --git a/macro/Cargo.toml b/macro/Cargo.toml index 33ea8dd..2b3ac95 100644 --- a/macro/Cargo.toml +++ b/macro/Cargo.toml @@ -13,7 +13,7 @@ proc_macro = true [dependencies] proc-macro2 = { version = "1.0", features = ["span-locations"] } quote = "1.0.29" -libninja_hir = { path = "../hir" } +libninja_mir = { path = "../mir" } [dev-dependencies] pretty_assertions = "1.3.0" diff --git a/macro/src/function.rs b/macro/src/function.rs index 096e0fa..a4d8373 100644 --- a/macro/src/function.rs +++ b/macro/src/function.rs @@ -39,13 +39,13 @@ pub fn parse_intro(toks: &mut impl Iterator) -> Tags { } }; let fn_name = if captured.is_empty() { - quote!( ::hir::Ident(#fn_name.to_string()) ) + quote!( ::mir::Ident(#fn_name.to_string()) ) } else { let captured = captured .into_iter() .map(|name| Ident2::new(&name, proc_macro2::Span::call_site())); - quote!( ::hir::Ident(format!("{}", #( #captured ),*)) ) + quote!( ::mir::Ident(format!("{}", #( #captured ),*)) ) }; Tags { asyn, diff --git a/macro/src/lib.rs b/macro/src/lib.rs index 22e9b62..e9b9c5e 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -24,7 +24,7 @@ pub fn function(item: TokenStream) -> TokenStream { let args = parse_args(arg_toks.stream()).into_iter().map(|arg| { let Arg { name, arg_type, default } = arg; quote! { - ::hir::FnArg { + ::mir::FnArg { name: #name.into(), ty: #arg_type, default: #default, @@ -44,14 +44,14 @@ pub fn function(item: TokenStream) -> TokenStream { }; quote! { - ::hir::Function { + ::mir::Function { name: #fn_name, async_: #asyn, public: #public, args: vec![#(#args),*], ret: #ret, body: #body, - ..::hir::Function::default() + ..::mir::Function::default() } }.into() } @@ -70,7 +70,7 @@ pub fn rfunction(item: TokenStream) -> TokenStream { let args = rfunction::parse_args2(arg_toks.stream()).into_iter().map(|arg| { let Arg { name, arg_type, default } = arg; quote! { - ::hir::FnArg { + ::mir::FnArg { name: #name.into(), ty: #arg_type, default: #default, @@ -93,14 +93,14 @@ pub fn rfunction(item: TokenStream) -> TokenStream { }; quote! { - ::hir::Function { + ::mir::Function { name: #fn_name, async_: #asyn, public: #public, args: vec![#(#args),*], ret: #ret, body: #body, - ..::hir::Function::default() + ..::mir::Function::default() } }.into() } diff --git a/macro/tests/function.rs b/macro/tests/function.rs index 2180d96..29bab84 100644 --- a/macro/tests/function.rs +++ b/macro/tests/function.rs @@ -1,5 +1,5 @@ use ln_macro::function; -use hir::{Function, ArgIdent}; +use mir::{Function, ArgIdent}; use pretty_assertions::assert_eq; #[test] diff --git a/macro/tests/rfunction.rs b/macro/tests/rfunction.rs index f63eb03..85b34dc 100644 --- a/macro/tests/rfunction.rs +++ b/macro/tests/rfunction.rs @@ -1,7 +1,7 @@ use proc_macro2::TokenStream; use ln_macro::rfunction; -use hir::Function; +use mir::Function; use quote::quote; #[test] diff --git a/hir/Cargo.toml b/mir/Cargo.toml similarity index 64% rename from hir/Cargo.toml rename to mir/Cargo.toml index d061752..2c0d954 100644 --- a/hir/Cargo.toml +++ b/mir/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "libninja_hir" +name = "libninja_mir" version = "0.1.0" edition = "2021" [lib] -name = "hir" +name = "mir" path = "src/lib.rs" [dependencies] quote = "1.0.29" -proc-macro2 = "1.0.63" +proc-macro2 = "1.0.63" \ No newline at end of file diff --git a/hir/src/function.rs b/mir/src/function.rs similarity index 100% rename from hir/src/function.rs rename to mir/src/function.rs diff --git a/hir/src/lib.rs b/mir/src/lib.rs similarity index 99% rename from hir/src/lib.rs rename to mir/src/lib.rs index ccc0f1d..1264a1d 100644 --- a/hir/src/lib.rs +++ b/mir/src/lib.rs @@ -1,5 +1,6 @@ /// Models that represent code /// Things like, Parameters, Functions, Fields, Class, etc. +/// use core::default::Default; use core::fmt::{Debug, Formatter}; diff --git a/hir/src/macro.rs b/mir/src/macro.rs similarity index 70% rename from hir/src/macro.rs rename to mir/src/macro.rs index d8ababa..ea66e58 100644 --- a/hir/src/macro.rs +++ b/mir/src/macro.rs @@ -5,13 +5,13 @@ #[macro_export] macro_rules! import { ($path:expr) => { - ::hir::Import::package($path) + ::mir::Import::package($path) }; ($path:expr, $($imports:ident),*) => { - ::hir::Import::new($path, vec![$(stringify!($imports)),*]) + ::mir::Import::new($path, vec![$(stringify!($imports)),*]) }; (pub $path:expr, $($imports:ident),*) => { - ::hir::Import::new($path, vec![$(stringify!($imports)),*]).public() + ::mir::Import::new($path, vec![$(stringify!($imports)),*]).public() }; } /// Macro to create a FnArg. Called targ because the type is a TokenStream (specifically a path), rather than a &str. @@ -19,7 +19,7 @@ macro_rules! import { #[macro_export] macro_rules! targ { ($name:ident : $ty:path) => { - ::hir::FnArg { + ::mir::FnArg { name: stringify!($name).to_string(), ty: { let ty = ::syn::parse_str::<::syn::Ident>(stringify!($ty)).unwrap(); @@ -35,16 +35,16 @@ macro_rules! targ { #[macro_export] macro_rules! arg { ($name:ident : $ty:expr) => { - ::hir::FnArg { - name: ::hir::ArgIdent::from(stringify!($name)), + ::mir::FnArg { + name: ::mir::ArgIdent::from(stringify!($name)), ty: $ty.to_string(), default: None, treatment: None, } }; ($name:ident : $ty:expr , $default:expr) => { - ::hir::FnArg { - name: ::hir::ArgIdent::from(stringify!($name).to_string()), + ::mir::FnArg { + name: ::mir::ArgIdent::from(stringify!($name).to_string()), ty: $ty.to_string(), default: $default.to_string(), treatment: None, @@ -56,24 +56,24 @@ macro_rules! arg { #[macro_export] macro_rules! field { (pub(crate) $name:ident : $ty:expr) => { - ::hir::Field { - name: ::hir::Name::new(stringify!($name)), + ::mir::Field { + name: ::mir::Name::new(stringify!($name)), ty: ($ty).into(), - visibility: ::hir::Visibility::Crate, + visibility: ::mir::Visibility::Crate, ..Field::default() } }; (pub $name:ident : $ty:expr) => { - ::hir::Field { - name: ::hir::Name::new(stringify!($name)), + ::mir::Field { + name: ::mir::Name::new(stringify!($name)), ty: ($ty).into(), - visibility: ::hir::Visibility::Public, + visibility: ::mir::Visibility::Public, ..Field::default() } }; ($name:ident : $ty:expr) => { - ::hir::Field { - name: ::hir::Name::new(stringify!($name)), + ::mir::Field { + name: ::mir::Name::new(stringify!($name)), ty: ($ty).into(), ..Field::default() } @@ -84,6 +84,6 @@ macro_rules! field { #[macro_export] macro_rules! lit { ($($arg:tt)*) => { - ::hir::Literal(format!($($arg)*)); + ::mir::Literal(format!($($arg)*)); }; } \ No newline at end of file