Skip to content

Commit

Permalink
fix: escape keywords when generate code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ggiggle committed Nov 13, 2023
1 parent 375c71b commit 4028eaa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
6 changes: 5 additions & 1 deletion pilota-build/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ where
pub fn get_init_service(&self, def_id: DefId) -> (String, String) {
let service_name = self.rust_name(def_id);
let mod_prefix = self.mod_path(def_id);
let service_path = format!("{}::{}", mod_prefix.join("::"), service_name);
let service_path = format!(
"{}::{}",
mod_prefix.iter().map(|item| item.to_string()).join("::"),
service_name
);
tracing::debug!("service_path: {}", service_path);
let methods = self.service_methods(def_id);

Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/codegen/thrift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl ThriftBackend {

fn codegen_impl_message(
&self,
def_id: DefId,
_def_id: DefId,
name: Symbol,
encode: String,
size: String,
Expand Down
24 changes: 12 additions & 12 deletions pilota-build/src/middle/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,18 +871,18 @@ impl Context {
info
}

pub fn def_id_info(&self, def_id: DefId) -> FastStr {
let file_path = self
.file(self.node(def_id).unwrap().file_id)
.unwrap()
.package
.clone();
file_path
.iter()
.chain(&[self.node(def_id).unwrap().name()])
.join("::")
.into()
}
// pub fn def_id_info(&self, def_id: DefId) -> FastStr {
// let file_path = self
// .file(self.node(def_id).unwrap().file_id)
// .unwrap()
// .package
// .clone();
// file_path
// .iter()
// .chain(&[self.node(def_id).unwrap().name()])
// .join("::")
// .into()
// }

pub fn config(&self, crate_id: &CrateId) -> &serde_yaml::Value {
let main_file = crate_id.main_file;
Expand Down
2 changes: 0 additions & 2 deletions pilota-build/src/middle/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ pub trait PathResolver: Sync + Send {
_ => panic!(),
};

// keyword escape
let name = name.to_string().into();
segs.push(name);
}

Expand Down
7 changes: 6 additions & 1 deletion pilota-build/src/middle/ty.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Display;
pub use std::sync::Arc;

use itertools::Itertools;
pub use TyKind::*;

use super::context::tls::with_cx;
Expand Down Expand Up @@ -141,7 +142,11 @@ impl CodegenTy {
.into()
}
CodegenTy::Adt(def) => with_cx(|cx| {
let path = cx.item_path(def.did).join("::");
let path = cx
.item_path(def.did)
.iter()
.map(|item| item.to_string())
.join("::");

format!("::{path}").into()
}),
Expand Down

0 comments on commit 4028eaa

Please sign in to comment.