Skip to content

Commit

Permalink
add source type for context (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
LYF1999 authored Mar 17, 2023
1 parent 5aa7b4e commit cf0af28
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pilota-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pilota-build"
version = "0.6.0"
version = "0.6.1"
edition = "2021"
description = "Compile thrift and protobuf idl into rust code at compile-time."
documentation = "https://docs.rs/pilota-build"
Expand Down
8 changes: 6 additions & 2 deletions pilota-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use db::{RirDatabase, RootDatabase};
use fmt::fmt_file;
pub use middle::{context::Context, rir, ty};
use middle::{
context::{tls::CONTEXT, CollectMode},
context::{tls::CONTEXT, CollectMode, SourceType},
rir::NodeKind,
type_graph::TypeGraph,
};
Expand Down Expand Up @@ -73,6 +73,7 @@ impl MakeBackend for MkProtobufBackend {
}

pub struct Builder<MkB, P> {
source_type: SourceType,
mk_backend: MkB,
parser: P,
plugins: Vec<Box<dyn Plugin>>,
Expand All @@ -83,6 +84,7 @@ pub struct Builder<MkB, P> {
impl Builder<MkThriftBackend, ThriftParser> {
pub fn thrift() -> Self {
Builder {
source_type: SourceType::Thrift,
mk_backend: MkThriftBackend,
parser: ThriftParser::default(),
plugins: vec![
Expand All @@ -99,6 +101,7 @@ impl Builder<MkThriftBackend, ThriftParser> {
impl Builder<MkProtobufBackend, ProtobufParser> {
pub fn protobuf() -> Self {
Builder {
source_type: SourceType::Protobuf,
mk_backend: MkProtobufBackend,
parser: ProtobufParser::default(),
plugins: vec![
Expand All @@ -125,6 +128,7 @@ where
impl<MkB, P> Builder<MkB, P> {
pub fn with_backend<B: MakeBackend>(self, mk_backend: B) -> Builder<B, P> {
Builder {
source_type: self.source_type,
mk_backend,
parser: self.parser,
plugins: self.plugins,
Expand Down Expand Up @@ -195,7 +199,7 @@ where
db.set_type_graph_with_durability(type_graph, Durability::HIGH);
db.set_nodes_with_durability(Arc::new(nodes), Durability::HIGH);

let mut cx = Context::new(db.snapshot());
let mut cx = Context::new(self.source_type, db.snapshot());
cx.set_tags_map(tags);

cx.exec_plugin(BoxedPlugin);
Expand Down
9 changes: 8 additions & 1 deletion pilota-build/src/middle/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub enum CollectMode {
}

pub struct Context {
pub source_type: SourceType,
pub db: salsa::Snapshot<RootDatabase>,
adjusts: FxHashMap<DefId, Adjust>,
tags_map: FxHashMap<TagId, Arc<Tags>>,
Expand All @@ -41,9 +42,15 @@ impl Deref for Context {
}
}

pub enum SourceType {
Thrift,
Protobuf,
}

impl Context {
pub fn new(db: salsa::Snapshot<RootDatabase>) -> Context {
pub fn new(source_type: SourceType, db: salsa::Snapshot<RootDatabase>) -> Context {
Context {
source_type,
db,
adjusts: Default::default(),
tags_map: Default::default(),
Expand Down

0 comments on commit cf0af28

Please sign in to comment.