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:
@@ -523,7 +523,7 @@ impl<'a> Parser<'a> {
|
|||||||
self.comments.clear();
|
self.comments.clear();
|
||||||
self.gather_comments(AnyEntity::Function);
|
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));
|
let mut ctx = Context::new(Function::with_name_signature(name, sig));
|
||||||
|
|
||||||
// function ::= function-spec * "{" preamble function-body "}"
|
// function ::= function-spec * "{" preamble function-body "}"
|
||||||
@@ -545,6 +545,7 @@ impl<'a> Parser<'a> {
|
|||||||
try!(ctx.rewrite_references());
|
try!(ctx.rewrite_references());
|
||||||
|
|
||||||
let details = Details {
|
let details = Details {
|
||||||
|
location: location,
|
||||||
comments: mem::replace(&mut self.comments, Vec::new()),
|
comments: mem::replace(&mut self.comments, Vec::new()),
|
||||||
map: sourcemap::new(ctx.values, ctx.ebbs, ctx.stack_slots, ctx.jump_tables),
|
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
|
// 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"));
|
try!(self.match_token(Token::Function, "expected 'function' keyword"));
|
||||||
|
let location = self.loc;
|
||||||
|
|
||||||
// function-spec ::= "function" * name signature
|
// function-spec ::= "function" * name signature
|
||||||
let name = try!(self.parse_function_name());
|
let name = try!(self.parse_function_name());
|
||||||
@@ -565,7 +567,7 @@ impl<'a> Parser<'a> {
|
|||||||
// function-spec ::= "function" name * signature
|
// function-spec ::= "function" name * signature
|
||||||
let sig = try!(self.parse_signature());
|
let sig = try!(self.parse_signature());
|
||||||
|
|
||||||
Ok((name, sig))
|
Ok((location, name, sig))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse a function name.
|
// Parse a function name.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use cretonne::ir::Function;
|
|||||||
use cretonne::ir::entities::AnyEntity;
|
use cretonne::ir::entities::AnyEntity;
|
||||||
use testcommand::TestCommand;
|
use testcommand::TestCommand;
|
||||||
use sourcemap::SourceMap;
|
use sourcemap::SourceMap;
|
||||||
|
use parser::Location;
|
||||||
|
|
||||||
/// A parsed test case.
|
/// A parsed test case.
|
||||||
///
|
///
|
||||||
@@ -24,6 +25,7 @@ pub struct TestFile<'a> {
|
|||||||
/// The details to not affect the semantics of the function.
|
/// The details to not affect the semantics of the function.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Details<'a> {
|
pub struct Details<'a> {
|
||||||
|
pub location: Location,
|
||||||
pub comments: Vec<Comment<'a>>,
|
pub comments: Vec<Comment<'a>>,
|
||||||
pub map: SourceMap,
|
pub map: SourceMap,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user