git.delta.rocks / jrsonnet / refs/commits / c1a6c6ac4824

difftreelog

perf Rc file name

Лач2020-06-26parent: #91108e4.patch.diff
in: master

5 files changed

modifiedcrates/jsonnet-evaluator/build.rsdiffbeforeafterboth
15 let parsed = parse(15 let parsed = parse(
16 STDLIB_STR,16 STDLIB_STR,
17 &ParserSettings {17 &ParserSettings {
18 file_name: PathBuf::from("std.jsonnet"),18 file_name: Rc::new(PathBuf::from("std.jsonnet")),
19 loc_data: true,19 loc_data: true,
20 },20 },
21 )21 )
modifiedcrates/jsonnet-evaluator/src/error.rsdiffbeforeafterboth
38}38}
3939
40#[derive(Clone, Debug)]40#[derive(Clone, Debug)]
41pub struct StackTraceElement(pub Rc<ExprLocation>, pub String);41pub struct StackTraceElement(pub ExprLocation, pub String);
42#[derive(Debug, Clone)]42#[derive(Debug, Clone)]
43pub struct StackTrace(pub Vec<StackTraceElement>);43pub struct StackTrace(pub Vec<StackTraceElement>);
4444
modifiedcrates/jsonnet-evaluator/src/lib.rsdiffbeforeafterboth
117 parse(117 parse(
118 &code,118 &code,
119 &ParserSettings {119 &ParserSettings {
120 file_name: name,120 file_name: Rc::new(name),
121 loc_data: true,121 loc_data: true,
122 },122 },
123 )?,123 )?,
198 let parsed = parse(198 let parsed = parse(
199 &code,199 &code,
200 &ParserSettings {200 &ParserSettings {
201 file_name: PathBuf::from("raw.jsonnet"),201 file_name: Rc::new(PathBuf::from("raw.jsonnet")),
202 loc_data: true,202 loc_data: true,
203 },203 },
204 )204 )
320 let state = EvaluationState::default();320 let state = EvaluationState::default();
321 state321 state
322 .push(322 .push(
323 Rc::new(ExprLocation(PathBuf::from("test1.jsonnet"), 10, 20)),323 ExprLocation(Rc::new(PathBuf::from("test1.jsonnet")), 10, 20),
324 "outer".to_owned(),324 "outer".to_owned(),
325 || {325 || {
326 state.push(326 state.push(
327 Rc::new(ExprLocation(PathBuf::from("test2.jsonnet"), 30, 40)),327 ExprLocation(Rc::new(PathBuf::from("test2.jsonnet")), 30, 40),
328 "inner".to_owned(),328 "inner".to_owned(),
329 || {329 || {
330 state.print_stack_trace();330 state.print_stack_trace();
modifiedcrates/jsonnet-parser/src/expr.rsdiffbeforeafterboth
207207
208/// file, begin offset, end offset208/// file, begin offset, end offset
209#[derive(Clone, PartialEq, Serialize, Deserialize)]209#[derive(Clone, PartialEq, Serialize, Deserialize)]
210pub struct ExprLocation(pub PathBuf, pub usize, pub usize);210pub struct ExprLocation(pub Rc<PathBuf>, pub usize, pub usize);
211impl Debug for ExprLocation {211impl Debug for ExprLocation {
212 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {212 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
213 write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)213 write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)
216216
217/// Holds AST expression and its location in source file+217/// Holds AST expression and its location in source file+
218#[derive(Clone, PartialEq, Serialize, Deserialize)]218#[derive(Clone, PartialEq, Serialize, Deserialize)]
219pub struct LocExpr(pub Rc<Expr>, pub Option<Rc<ExprLocation>>);219pub struct LocExpr(pub Rc<Expr>, pub Option<ExprLocation>);
220impl Debug for LocExpr {220impl Debug for LocExpr {
221 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {221 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
222 write!(f, "{:?} from {:?}", self.0, self.1)222 write!(f, "{:?} from {:?}", self.0, self.1)
230 LocExpr(230 LocExpr(
231 std::rc::Rc::new($expr),231 std::rc::Rc::new($expr),
232 if $need_loc {232 if $need_loc {
233 Some(std::rc::Rc::new(ExprLocation(233 Some(ExprLocation($name, $start, $end))
234 $name.to_owned(),
235 $start,
236 $end,
237 )))
238 } else {234 } else {
239 None235 None
240 },236 },
modifiedcrates/jsonnet-parser/src/lib.rsdiffbeforeafterboth
1111
12pub struct ParserSettings {12pub struct ParserSettings {
13 pub loc_data: bool,13 pub loc_data: bool,
14 pub file_name: PathBuf,14 pub file_name: Rc<PathBuf>,
15}15}
1616
17parser! {17parser! {
289 } end:position!() {289 } end:position!() {
290 let LocExpr(e, _) = a;290 let LocExpr(e, _) = a;
291 LocExpr(e, if s.loc_data {291 LocExpr(e, if s.loc_data {
292 Some(Rc::new(ExprLocation(s.file_name.to_owned(), start, end)))292 Some(ExprLocation(s.file_name.clone(), start, end))
293 } else {293 } else {
294 None294 None
295 })295 })
317 use super::{expr::*, parse};317 use super::{expr::*, parse};
318 use crate::ParserSettings;318 use crate::ParserSettings;
319 use std::path::PathBuf;319 use std::path::PathBuf;
320 use std::rc::Rc;
320321
321 macro_rules! parse {322 macro_rules! parse {
322 ($s:expr) => {323 ($s:expr) => {
323 parse(324 parse(
324 $s,325 $s,
325 &ParserSettings {326 &ParserSettings {
326 loc_data: false,327 loc_data: false,
327 file_name: PathBuf::from("/test.jsonnet"),328 file_name: Rc::new(PathBuf::from("/test.jsonnet")),
328 },329 },
329 )330 )
330 .unwrap()331 .unwrap()