Record first line number in code object.

This commit is contained in:
Adam Kelly
2019-02-08 17:59:27 +00:00
parent 7b2508a730
commit 7d08867419
2 changed files with 15 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ pub struct CodeObject {
pub kwonlyarg_names: Vec<String>,
pub varkeywords: Option<Option<String>>, // **kwargs or **
pub source_path: Option<String>,
pub first_line_number: usize,
pub obj_name: String, // Name of the object that created this code object
pub is_generator: bool,
}
@@ -34,6 +35,7 @@ impl CodeObject {
kwonlyarg_names: Vec<String>,
varkeywords: Option<Option<String>>,
source_path: Option<String>,
first_line_number: usize,
obj_name: String,
) -> CodeObject {
CodeObject {
@@ -45,6 +47,7 @@ impl CodeObject {
kwonlyarg_names,
varkeywords,
source_path,
first_line_number,
obj_name,
is_generator: false,
}

View File

@@ -79,12 +79,14 @@ impl Compiler {
}
fn push_new_code_object(&mut self, source_path: Option<String>, obj_name: String) {
let line_number = self.get_source_line_number();
self.code_object_stack.push(CodeObject::new(
Vec::new(),
None,
Vec::new(),
None,
source_path.clone(),
line_number,
obj_name,
));
}
@@ -453,12 +455,14 @@ impl Compiler {
} => {
self.prepare_decorators(decorator_list)?;
self.emit(Instruction::LoadBuildClass);
let line_number = self.get_source_line_number();
self.code_object_stack.push(CodeObject::new(
vec![String::from("__locals__")],
None,
vec![],
None,
self.source_path.clone(),
line_number,
name.clone(),
));
self.emit(Instruction::LoadName {
@@ -653,12 +657,14 @@ impl Compiler {
});
}
let line_number = self.get_source_line_number();
self.code_object_stack.push(CodeObject::new(
args.args.clone(),
args.vararg.clone(),
args.kwonlyargs.clone(),
args.kwarg.clone(),
self.source_path.clone(),
line_number,
name.to_string(),
));
@@ -1162,6 +1168,7 @@ impl Compiler {
}
.to_string();
let line_number = self.get_source_line_number();
// Create magnificent function <listcomp>:
self.code_object_stack.push(CodeObject::new(
vec![".0".to_string()],
@@ -1169,6 +1176,7 @@ impl Compiler {
vec![],
None,
self.source_path.clone(),
line_number,
name.clone(),
));
@@ -1338,6 +1346,10 @@ impl Compiler {
self.current_source_location = location.clone();
}
fn get_source_line_number(&mut self) -> usize {
self.current_source_location.get_row()
}
fn mark_generator(&mut self) {
self.current_code_object().is_generator = true;
}