8000 Add location() to instruction trait by CohenArthur · Pull Request #516 · jinko-core/jinko · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/instruction/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ impl Instruction for FunctionCall {

ret_val
}

fn location(&self) -> Option<&SpanTuple> {
self.location.as_ref()
}
}

impl TypeCheck for FunctionCall {
Expand Down
4 changes: 4 additions & 0 deletions src/instruction/function_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ impl Instruction for FunctionDec {
None => format!("{} {{}}", base),
}
}

fn location(&self) -> Option<&SpanTuple> {
self.location.as_ref()
}
}

impl TypeCheck for FunctionDec {
Expand Down
8 changes: 7 additions & 1 deletion src/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! When using nested instructions, such as `foo = bar();`, you're actually using
//! two instructions: A function call expression, and a variable assignment statement

use crate::{Context, ErrKind, Error, Generic, ObjectInstance, TypeCheck};
use crate::{Context, ErrKind, Error, Generic, ObjectInstance, SpanTuple, TypeCheck};

use colored::Colorize;
use downcast_rs::{impl_downcast, Downcast};
Expand Down Expand Up @@ -117,6 +117,12 @@ pub trait Instruction: InstructionClone + Downcast + TypeCheck + Generic {

/// Pretty-print the instruction to valid jinko code
fn print(&self) -> String;

/// Fetch a reference to this instruction's location
fn location(&self) -> Option<&SpanTuple> {
// FIXME: Remove default implementation
None
}
}

impl_downcast!(Instruction);
Expand Down
0