Record the location of parsed functions.

Remember the location of the 'function' keyword that starts every
function. This can be useful for reporting test failures etc.
This commit is contained in:
Jakob Stoklund Olesen
2016-09-17 11:42:08 -07:00
parent 81f26422fa
commit a4774ce87d
2 changed files with 7 additions and 3 deletions

View File

@@ -523,7 +523,7 @@ impl<'a> Parser<'a> {
self.comments.clear();
self.gather_comments(AnyEntity::Function);
let (name, sig) = try!(self.parse_function_spec());
let (location, name, sig) = try!(self.parse_function_spec());
let mut ctx = Context::new(Function::with_name_signature(name, sig));
// function ::= function-spec * "{" preamble function-body "}"
@@ -545,6 +545,7 @@ impl<'a> Parser<'a> {
try!(ctx.rewrite_references());
let details = Details {
location: location,
comments: mem::replace(&mut self.comments, Vec::new()),
map: sourcemap::new(ctx.values, ctx.ebbs, ctx.stack_slots, ctx.jump_tables),
};
@@ -556,8 +557,9 @@ impl<'a> Parser<'a> {
//
// function-spec ::= * "function" name signature
//
fn parse_function_spec(&mut self) -> Result<(FunctionName, Signature)> {
fn parse_function_spec(&mut self) -> Result<(Location, FunctionName, Signature)> {
try!(self.match_token(Token::Function, "expected 'function' keyword"));
let location = self.loc;
// function-spec ::= "function" * name signature
let name = try!(self.parse_function_name());
@@ -565,7 +567,7 @@ impl<'a> Parser<'a> {
// function-spec ::= "function" name * signature
let sig = try!(self.parse_signature());
Ok((name, sig))
Ok((location, name, sig))
}
// Parse a function name.

View File

@@ -8,6 +8,7 @@ use cretonne::ir::Function;
use cretonne::ir::entities::AnyEntity;
use testcommand::TestCommand;
use sourcemap::SourceMap;
use parser::Location;
/// A parsed test case.
///
@@ -24,6 +25,7 @@ pub struct TestFile<'a> {
/// The details to not affect the semantics of the function.
#[derive(Debug)]
pub struct Details<'a> {
pub location: Location,
pub comments: Vec<Comment<'a>>,
pub map: SourceMap,
}