aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <phil@nebuloninc.com>2020-04-13 22:52:23 +0100
committerPhilip Herron <philip.herron@embecosm.com>2020-11-27 17:02:35 +0000
commit52243e9b3960cae794c56498e4d2dfe6dfaa82cc (patch)
treeadedc08f42542c339589a5e6d6b745ae7215d2b0
parent3a2b1a2084aedb12154df1e523cf3092ff563a95 (diff)
downloadgcc-52243e9b3960cae794c56498e4d2dfe6dfaa82cc.zip
gcc-52243e9b3960cae794c56498e4d2dfe6dfaa82cc.tar.gz
gcc-52243e9b3960cae794c56498e4d2dfe6dfaa82cc.tar.bz2
Remove unused compilation code to GCC GENERIC.
Wire up Linemap abstraction object and location_t to Location
-rw-r--r--gcc/rust/Make-lang.in1
-rw-r--r--gcc/rust/ast/rust-ast-full-test.cc56
-rw-r--r--gcc/rust/ast/rust-ast.h76
-rw-r--r--gcc/rust/ast/rust-expr.h302
-rw-r--r--gcc/rust/ast/rust-item.h176
-rw-r--r--gcc/rust/ast/rust-macro.h14
-rw-r--r--gcc/rust/ast/rust-path.h72
-rw-r--r--gcc/rust/ast/rust-pattern.h76
-rw-r--r--gcc/rust/ast/rust-stmt.h24
-rw-r--r--gcc/rust/ast/rust-type.h94
-rw-r--r--gcc/rust/lex/rust-lex.cc125
-rw-r--r--gcc/rust/lex/rust-lex.h13
-rw-r--r--gcc/rust/lex/rust-token.h39
-rw-r--r--gcc/rust/parse/rust-parse-includes.h27
-rw-r--r--gcc/rust/parse/rust-parse.cc2561
-rw-r--r--gcc/rust/parse/rust-parse.h160
-rw-r--r--gcc/rust/parse/rust-scope.cc43
-rw-r--r--gcc/rust/parse/rust-scope.h61
-rw-r--r--gcc/rust/parse/rust-symbol.h78
-rw-r--r--gcc/rust/parse/rust-tree.h167
-rw-r--r--gcc/rust/rust-diagnostics.cc215
-rw-r--r--gcc/rust/rust-session-manager.cc19
-rw-r--r--gcc/rust/rust-session-manager.h10
23 files changed, 1217 insertions, 3192 deletions
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index e5b4d3d..588a05e 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -62,6 +62,7 @@ GRS_OBJS = \
rust/rust-object-export.o \
rust/rust-linemap.o \
rust/rust-gcc-diagnostics.o \
+ rust/rust-diagnostics.o \
rust/rust-gcc.o \
rust/rust-token.o \
rust/rust-lex.o \
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc
index 216299d..b68b770 100644
--- a/gcc/rust/ast/rust-ast-full-test.cc
+++ b/gcc/rust/ast/rust-ast-full-test.cc
@@ -1,8 +1,6 @@
#include "rust-ast-full.h"
-#include "diagnostic.h"
-
+#include "rust-diagnostics.h"
#include "rust-ast-visitor.h"
-
#include "rust-session-manager.h"
/* Compilation unit used for various AST-related functions that would make the headers too long if
@@ -2128,9 +2126,9 @@ namespace Rust {
}
// kind of a HACK to get locus depending on opening scope resolution
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (with_opening_scope_resolution) {
- locus = simple_segments[0].get_locus() - 2; // minus 2 chars for ::
+ locus = simple_segments[0].get_locus()/* - 2*/; // minus 2 chars for ::
} else {
locus = simple_segments[0].get_locus();
}
@@ -2513,7 +2511,7 @@ namespace Rust {
TraitBound* TypePath::to_trait_bound(bool in_parens) const {
// create clone FIXME is this required? or is copy constructor automatically called?
TypePath copy(*this);
- return new TraitBound(::std::move(copy), in_parens);
+ return new TraitBound(::std::move(copy), copy.get_locus(), in_parens);
}
::std::string InferredType::as_string() const {
@@ -3457,7 +3455,7 @@ namespace Rust {
return parse_path_meta_item();
}
default:
- error_at(peek_token()->get_locus(), "unrecognised token '%s' in meta item",
+ rust_error_at(peek_token()->get_locus(), "unrecognised token '%s' in meta item",
get_token_description(peek_token()->get_id()));
return NULL;
}
@@ -3494,7 +3492,7 @@ namespace Rust {
}
if (peek_token(1)->get_id() != LEFT_PAREN) {
- error_at(peek_token(1)->get_locus(),
+ rust_error_at(peek_token(1)->get_locus(),
"unexpected token '%s' after identifier in attribute",
get_token_description(peek_token(1)->get_id()));
return NULL;
@@ -3551,7 +3549,7 @@ namespace Rust {
new MetaListPaths(::std::move(ident), ::std::move(path_items)));
}
- error_at(UNKNOWN_LOCATION, "failed to parse any meta item inner");
+ rust_error_at(Linemap::unknown_location(), "failed to parse any meta item inner");
return NULL;
}
@@ -3562,7 +3560,7 @@ namespace Rust {
::std::unique_ptr<MetaItem> MacroParser::parse_path_meta_item() {
SimplePath path = parse_simple_path();
if (path.is_empty()) {
- error_at(peek_token()->get_locus(), "failed to parse simple path in attribute");
+ rust_error_at(peek_token()->get_locus(), "failed to parse simple path in attribute");
return NULL;
}
@@ -3577,10 +3575,10 @@ namespace Rust {
case EQUAL: {
skip_token();
- location_t locus = peek_token()->get_locus();
+ Location locus = peek_token()->get_locus();
Literal lit = parse_literal();
if (lit.is_error()) {
- error_at(peek_token()->get_locus(), "failed to parse literal in attribute");
+ rust_error_at(peek_token()->get_locus(), "failed to parse literal in attribute");
return NULL;
}
LiteralExpr expr(::std::move(lit), locus);
@@ -3594,7 +3592,7 @@ namespace Rust {
// just simple path
return ::std::unique_ptr<MetaItemPath>(new MetaItemPath(::std::move(path)));
default:
- error_at(peek_token()->get_locus(), "unrecognised token '%s' in meta item",
+ rust_error_at(peek_token()->get_locus(), "unrecognised token '%s' in meta item",
get_token_description(peek_token()->get_id()));
return NULL;
}
@@ -3612,7 +3610,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<MetaItemInner> > meta_items;
if (peek_token()->get_id() != LEFT_PAREN) {
- error_at(peek_token()->get_locus(), "missing left paren in delim token tree");
+ rust_error_at(peek_token()->get_locus(), "missing left paren in delim token tree");
return {};
}
skip_token();
@@ -3620,7 +3618,7 @@ namespace Rust {
while (stream_pos < vec_length && peek_token()->get_id() != RIGHT_PAREN) {
::std::unique_ptr<MetaItemInner> inner = parse_meta_item_inner();
if (inner == NULL) {
- error_at(
+ rust_error_at(
peek_token()->get_locus(), "failed to parse inner meta item in attribute");
return {};
}
@@ -3633,7 +3631,7 @@ namespace Rust {
}
if (peek_token()->get_id() != RIGHT_PAREN) {
- error_at(peek_token()->get_locus(), "missing right paren in delim token tree");
+ rust_error_at(peek_token()->get_locus(), "missing right paren in delim token tree");
return {};
}
skip_token();
@@ -3647,7 +3645,7 @@ namespace Rust {
// simulate presence of delimiters
tokens.push_back(::std::unique_ptr<Token>(
- new Token(LEFT_PAREN, UNKNOWN_LOCATION, "", CORETYPE_UNKNOWN)));
+ new Token(LEFT_PAREN, Linemap::unknown_location(), "", CORETYPE_UNKNOWN)));
for (const auto& tree : token_trees) {
::std::vector< ::std::unique_ptr<Token> > stream = tree->to_token_stream();
@@ -3657,7 +3655,7 @@ namespace Rust {
}
tokens.push_back(::std::unique_ptr<Token>(
- new Token(RIGHT_PAREN, UNKNOWN_LOCATION, "", CORETYPE_UNKNOWN)));
+ new Token(RIGHT_PAREN, Linemap::unknown_location(), "", CORETYPE_UNKNOWN)));
tokens.shrink_to_fit();
@@ -3692,7 +3690,7 @@ namespace Rust {
skip_token();
return Literal("false", Literal::BOOL);
default:
- error_at(tok->get_locus(), "expected literal - found '%s'",
+ rust_error_at(tok->get_locus(), "expected literal - found '%s'",
get_token_description(tok->get_id()));
return Literal::create_error();
}
@@ -3709,7 +3707,7 @@ namespace Rust {
SimplePathSegment segment = parse_simple_path_segment();
if (segment.is_error()) {
- error_at(peek_token()->get_locus(),
+ rust_error_at(peek_token()->get_locus(),
"failed to parse simple path segment in attribute simple path");
return SimplePath::create_empty();
}
@@ -3720,7 +3718,7 @@ namespace Rust {
SimplePathSegment segment = parse_simple_path_segment();
if (segment.is_error()) {
- error_at(peek_token()->get_locus(),
+ rust_error_at(peek_token()->get_locus(),
"failed to parse simple path segment in attribute simple path");
return SimplePath::create_empty();
}
@@ -3753,14 +3751,14 @@ namespace Rust {
}
gcc_fallthrough();
default:
- error_at(tok->get_locus(), "unexpected token '%s' in simple path segment",
+ rust_error_at(tok->get_locus(), "unexpected token '%s' in simple path segment",
get_token_description(tok->get_id()));
return SimplePathSegment::create_error();
}
}
::std::unique_ptr<MetaItemLitExpr> MacroParser::parse_meta_item_lit() {
- location_t locus = peek_token()->get_locus();
+ Location locus = peek_token()->get_locus();
LiteralExpr lit_expr(parse_literal(), locus);
return ::std::unique_ptr<MetaItemLitExpr>(new MetaItemLitExpr(::std::move(lit_expr)));
}
@@ -3802,7 +3800,7 @@ namespace Rust {
} else if (ident == "not") {
if (strs.size() != 1) {
// HACK: convert vector platform-dependent size_type to string to use in printf
- error_at(UNKNOWN_LOCATION,
+ rust_error_at(Linemap::unknown_location(),
"cfg predicate could not be checked for MetaListNameValueStr with ident of "
"'not' because there are '%s' elements, not '1'",
::std::to_string(strs.size()).c_str());
@@ -3811,7 +3809,7 @@ namespace Rust {
return !strs[0].check_cfg_predicate(session);
} else {
- error_at(UNKNOWN_LOCATION,
+ rust_error_at(Linemap::unknown_location(),
"cfg predicate could not be checked for MetaListNameValueStr with ident of "
"'%s' - ident must be 'all' or 'any'",
ident.c_str());
@@ -3837,7 +3835,7 @@ namespace Rust {
} else if (ident == "not") {
if (paths.size() != 1) {
// HACK: convert vector platform-dependent size_type to string to use in printf
- error_at(UNKNOWN_LOCATION,
+ rust_error_at(Linemap::unknown_location(),
"cfg predicate could not be checked for MetaListPaths with ident of 'not' "
"because there are '%s' elements, not '1'",
::std::to_string(paths.size()).c_str());
@@ -3846,7 +3844,7 @@ namespace Rust {
return !check_path_exists_in_cfg(session, paths[0]);
} else {
- error_at(UNKNOWN_LOCATION,
+ rust_error_at(Linemap::unknown_location(),
"cfg predicate could not be checked for MetaListNameValueStr with ident of "
"'%s' - ident must be 'all' or 'any'",
ident.c_str());
@@ -3881,7 +3879,7 @@ namespace Rust {
} else if (path.as_string() == "not") {
if (seq.size() != 1) {
// HACK: convert vector platform-dependent size_type to string to use in printf
- error_at(UNKNOWN_LOCATION,
+ rust_error_at(Linemap::unknown_location(),
"cfg predicate could not be checked for MetaItemSeq with ident of 'not' "
"because there are '%s' elements, not '1'",
::std::to_string(seq.size()).c_str());
@@ -3890,7 +3888,7 @@ namespace Rust {
return !seq[0]->check_cfg_predicate(session);
} else {
- error_at(UNKNOWN_LOCATION,
+ rust_error_at(Linemap::unknown_location(),
"cfg predicate could not be checked for MetaItemSeq with path of "
"'%s' - path must be 'all' or 'any'",
path.as_string().c_str());
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index ebcbd25..0d50f59 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -18,9 +18,11 @@
// required for AST::Token
#include "rust-token.h"
+#include "rust-location.h"
+
namespace Rust {
// TODO: remove typedefs and make actual types for these
- // typedef int location_t;
+ // typedef int Location;
// typedef ::std::string SimplePath;
typedef ::std::string Identifier;
typedef int TupleIndex;
@@ -37,13 +39,13 @@ namespace Rust {
// Base AST node object - TODO is this really required or useful? Where to draw line?
/*class Node {
public:
- // Gets node's location_t.
- location_t get_locus() const {
+ // Gets node's Location.
+ Location get_locus() const {
return loc;
}
- // Sets node's location_t.
- void set_locus(location_t loc_) {
+ // Sets node's Location.
+ void set_locus(Location loc_) {
loc = loc_;
}
@@ -52,11 +54,11 @@ namespace Rust {
virtual ~Node() {}
- // TODO: constructor including location_t? Make all derived classes have location_t?
+ // TODO: constructor including Location? Make all derived classes have Location?
private:
// The node's location.
- location_t loc;
+ Location loc;
};*/
// decided to not have node as a "node" would never need to be stored
@@ -141,7 +143,7 @@ namespace Rust {
// Token kind.
TokenId token_id;
// Token location.
- location_t locus;
+ Location locus;
// Associated text (if any) of token.
std::string str;
// Token type hint (if any).
@@ -155,7 +157,7 @@ namespace Rust {
// constructor from general text - avoid using if lexer const_TokenPtr is available
Token(
- TokenId token_id, location_t locus, ::std::string str, PrimitiveCoreType type_hint) :
+ TokenId token_id, Location locus, ::std::string str, PrimitiveCoreType type_hint) :
token_id(token_id),
locus(locus), str(::std::move(str)), type_hint(type_hint) {}
@@ -197,7 +199,7 @@ namespace Rust {
return token_id;
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -268,7 +270,7 @@ namespace Rust {
DelimType delim_type;
::std::vector< ::std::unique_ptr<TokenTree> > token_trees;
- location_t locus;
+ Location locus;
// TODO: move all the "parse" functions into a separate class that has the token stream
// reference - will be cleaner Parse a meta item inner.
@@ -299,12 +301,12 @@ namespace Rust {
public:
DelimTokenTree(DelimType delim_type,
- ::std::vector< ::std::unique_ptr<TokenTree> > token_trees
- = ::std::vector< ::std::unique_ptr<TokenTree> >(),
- location_t locus = UNKNOWN_LOCATION) :
- delim_type(delim_type),
- token_trees(::std::move(token_trees)), locus(locus) {}
-
+ ::std::vector< ::std::unique_ptr<TokenTree> > token_trees
+ = ::std::vector< ::std::unique_ptr<TokenTree> >(),
+ Location locus = Location()) :
+ delim_type(delim_type),
+ token_trees(::std::move(token_trees)), locus(locus) {}
+
// Copy constructor with vector clone
DelimTokenTree(DelimTokenTree const& other) :
delim_type(other.delim_type), locus(other.locus) {
@@ -370,12 +372,12 @@ namespace Rust {
// A segment of a simple path without generic or type arguments
class SimplePathSegment : public PathSegment {
::std::string segment_name;
- location_t locus;
+ Location locus;
// only allow identifiers, "super", "self", "crate", or "$crate"
public:
// TODO: put checks in constructor to enforce this rule?
- SimplePathSegment(::std::string segment_name, location_t locus = UNKNOWN_LOCATION) :
+ SimplePathSegment(::std::string segment_name, Location locus = Location()) :
segment_name(::std::move(segment_name)), locus(locus) {}
// Returns whether simple path segment is in an invalid state (currently, if empty).
@@ -390,7 +392,7 @@ namespace Rust {
::std::string as_string() const;
- inline location_t get_locus() const {
+ inline Location get_locus() const {
return locus;
}
@@ -401,12 +403,12 @@ namespace Rust {
class SimplePath {
bool has_opening_scope_resolution;
::std::vector<SimplePathSegment> segments;
- location_t locus;
+ Location locus;
public:
// Constructor
SimplePath(::std::vector<SimplePathSegment> path_segments,
- bool has_opening_scope_resolution = false, location_t locus = UNKNOWN_LOCATION) :
+ bool has_opening_scope_resolution = false, Location locus = Location()) :
has_opening_scope_resolution(has_opening_scope_resolution),
segments(::std::move(path_segments)), locus(locus) {}
@@ -422,7 +424,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -455,7 +457,7 @@ namespace Rust {
// AttrInput* attr_input;
::std::unique_ptr<AttrInput> attr_input;
- location_t locus;
+ Location locus;
// TODO: maybe a variable storing whether attr input is parsed or not
@@ -467,7 +469,7 @@ namespace Rust {
// Constructor has pointer AttrInput for polymorphism reasons
Attribute(SimplePath path, ::std::unique_ptr<AttrInput> input,
- location_t locus = UNKNOWN_LOCATION) :
+ Location locus = Location()) :
path(::std::move(path)),
attr_input(::std::move(input)), locus(locus) {}
@@ -803,8 +805,8 @@ namespace Rust {
virtual ~Expr() {}
// HACK: slow way of getting location from base expression through virtual methods.
- virtual location_t get_locus_slow() const {
- return UNKNOWN_LOCATION;
+ virtual Location get_locus_slow() const {
+ return Location();
}
virtual void accept_vis(ASTVisitor& vis) = 0;
@@ -860,10 +862,10 @@ namespace Rust {
class IdentifierExpr : public ExprWithoutBlock {
Identifier ident;
- location_t locus;
+ Location locus;
public:
- IdentifierExpr(Identifier ident, location_t locus = UNKNOWN_LOCATION,
+ IdentifierExpr(Identifier ident, Location locus = Location(),
::std::vector<Attribute> outer_attrs = ::std::vector<Attribute>()) :
ExprWithoutBlock(::std::move(outer_attrs)),
ident(::std::move(ident)), locus(locus) {}
@@ -872,11 +874,11 @@ namespace Rust {
return ident;
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -994,12 +996,12 @@ namespace Rust {
::std::string lifetime_name;
// only applies for NAMED lifetime_type
- location_t locus;
+ Location locus;
public:
// Constructor
Lifetime(LifetimeType type, ::std::string name = ::std::string(),
- location_t locus = UNKNOWN_LOCATION) :
+ Location locus = Location()) :
lifetime_type(type),
lifetime_name(::std::move(name)), locus(locus) {}
@@ -1055,7 +1057,7 @@ namespace Rust {
//::std::unique_ptr<Attribute> outer_attr;
Attribute outer_attr;
- location_t locus;
+ Location locus;
public:
// Returns whether the lifetime param has any lifetime bounds.
@@ -1079,7 +1081,7 @@ namespace Rust {
}
// Constructor
- LifetimeParam(Lifetime lifetime, location_t locus = UNKNOWN_LOCATION,
+ LifetimeParam(Lifetime lifetime, Location locus = Location(),
::std::vector<Lifetime> lifetime_bounds = ::std::vector<Lifetime>(),
Attribute outer_attr = Attribute::create_empty()) :
lifetime(::std::move(lifetime)),
@@ -1213,14 +1215,14 @@ namespace Rust {
//::std::vector<TokenTree> token_trees;
::std::vector< ::std::unique_ptr<TokenTree> > token_trees;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
MacroInvocationSemi(SimplePath macro_path, DelimType delim_type,
::std::vector< ::std::unique_ptr<TokenTree> > token_trees,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
MacroItem(::std::move(outer_attribs)),
path(::std::move(macro_path)), delim_type(delim_type),
token_trees(::std::move(token_trees)), locus(locus) {}
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 1842da9..ea0ac20 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -67,7 +67,7 @@ namespace Rust {
// moved to Literal
Literal literal;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const {
@@ -78,12 +78,12 @@ namespace Rust {
return literal.get_lit_type();
}
- LiteralExpr(::std::string value_as_string, Literal::LitType type, location_t locus,
+ LiteralExpr(::std::string value_as_string, Literal::LitType type, Location locus,
::std::vector<Attribute> outer_attrs = ::std::vector<Attribute>()) :
ExprWithoutBlock(::std::move(outer_attrs)),
literal(::std::move(value_as_string), type), locus(locus) {}
- LiteralExpr(Literal literal, location_t locus,
+ LiteralExpr(Literal literal, Location locus,
::std::vector<Attribute> outer_attrs = ::std::vector<Attribute>()) :
ExprWithoutBlock(::std::move(outer_attrs)),
literal(::std::move(literal)), locus(locus) {}
@@ -93,11 +93,11 @@ namespace Rust {
return ::std::unique_ptr<LiteralExpr>(clone_literal_expr_impl());
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -261,7 +261,7 @@ namespace Rust {
class OperatorExpr : public ExprWithoutBlock {
// TODO: create binary and unary operator subclasses?
- location_t locus;
+ Location locus;
protected:
// Variable must be protected to allow derived classes to use it as a first class citizen
@@ -270,7 +270,7 @@ namespace Rust {
// Constructor (only for initialisation of expr purposes)
OperatorExpr(::std::unique_ptr<Expr> main_or_left_expr,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
ExprWithoutBlock(::std::move(outer_attribs)),
locus(locus), main_or_left_expr(::std::move(main_or_left_expr)) {}
@@ -310,11 +310,11 @@ namespace Rust {
delete main_or_left_expr;
}*/
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
};
@@ -328,7 +328,7 @@ namespace Rust {
::std::string as_string() const;
BorrowExpr(::std::unique_ptr<Expr> borrow_lvalue, bool is_mut_borrow,
- bool is_double_borrow, ::std::vector<Attribute> outer_attribs, location_t locus) :
+ bool is_double_borrow, ::std::vector<Attribute> outer_attribs, Location locus) :
OperatorExpr(::std::move(borrow_lvalue), ::std::move(outer_attribs), locus),
is_mut(is_mut_borrow), double_borrow(is_double_borrow) {}
@@ -364,7 +364,7 @@ namespace Rust {
// Constructor calls OperatorExpr's protected constructor
DereferenceExpr(::std::unique_ptr<Expr> deref_lvalue,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
OperatorExpr(::std::move(deref_lvalue), ::std::move(outer_attribs), locus) {}
// Copy constructor - define here if required
@@ -399,7 +399,7 @@ namespace Rust {
// Constructor calls OperatorExpr's protected constructor
ErrorPropagationExpr(::std::unique_ptr<Expr> potential_error_value,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
OperatorExpr(::std::move(potential_error_value), ::std::move(outer_attribs), locus) {}
// Copy constructor - define here if required
@@ -447,7 +447,7 @@ namespace Rust {
// Constructor calls OperatorExpr's protected constructor
NegationExpr(::std::unique_ptr<Expr> negated_value, NegationType negation_kind,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
OperatorExpr(::std::move(negated_value), ::std::move(outer_attribs), locus),
negation_type(negation_kind) {}
@@ -512,7 +512,7 @@ namespace Rust {
// Constructor calls OperatorExpr's protected constructor
ArithmeticOrLogicalExpr(::std::unique_ptr<Expr> left_value,
- ::std::unique_ptr<Expr> right_value, ExprType expr_kind, location_t locus) :
+ ::std::unique_ptr<Expr> right_value, ExprType expr_kind, Location locus) :
OperatorExpr(::std::move(left_value), ::std::vector<Attribute>(), locus),
expr_type(expr_kind), right_expr(::std::move(right_value)) {}
// outer attributes not allowed
@@ -588,7 +588,7 @@ namespace Rust {
// Constructor requires pointers for polymorphism
ComparisonExpr(::std::unique_ptr<Expr> left_value, ::std::unique_ptr<Expr> right_value,
- ExprType comparison_kind, location_t locus) :
+ ExprType comparison_kind, Location locus) :
OperatorExpr(::std::move(left_value), ::std::vector<Attribute>(), locus),
expr_type(comparison_kind), right_expr(::std::move(right_value)) {}
// outer attributes not allowed
@@ -651,7 +651,7 @@ namespace Rust {
// Constructor calls OperatorExpr's protected constructor
LazyBooleanExpr(::std::unique_ptr<Expr> left_bool_expr,
- ::std::unique_ptr<Expr> right_bool_expr, ExprType expr_kind, location_t locus) :
+ ::std::unique_ptr<Expr> right_bool_expr, ExprType expr_kind, Location locus) :
OperatorExpr(::std::move(left_bool_expr), ::std::vector<Attribute>(), locus),
expr_type(expr_kind), right_expr(::std::move(right_bool_expr)) {}
// outer attributes not allowed
@@ -711,7 +711,7 @@ namespace Rust {
// Constructor requires calling protected constructor of OperatorExpr
TypeCastExpr(::std::unique_ptr<Expr> expr_to_cast,
- ::std::unique_ptr<TypeNoBounds> type_to_cast_to, location_t locus) :
+ ::std::unique_ptr<TypeNoBounds> type_to_cast_to, Location locus) :
OperatorExpr(::std::move(expr_to_cast), ::std::vector<Attribute>(), locus),
type_to_convert_to(::std::move(type_to_cast_to)) {}
// outer attributes not allowed
@@ -767,7 +767,7 @@ namespace Rust {
// Call OperatorExpr constructor to initialise left_expr
AssignmentExpr(::std::unique_ptr<Expr> value_to_assign_to,
- ::std::unique_ptr<Expr> value_to_assign, location_t locus) :
+ ::std::unique_ptr<Expr> value_to_assign, Location locus) :
OperatorExpr(::std::move(value_to_assign_to), ::std::vector<Attribute>(), locus),
right_expr(::std::move(value_to_assign)) {}
// outer attributes not allowed
@@ -860,7 +860,7 @@ namespace Rust {
// Use pointers in constructor to enable polymorphism
CompoundAssignmentExpr(::std::unique_ptr<Expr> value_to_assign_to,
- ::std::unique_ptr<Expr> value_to_assign, ExprType expr_kind, location_t locus) :
+ ::std::unique_ptr<Expr> value_to_assign, ExprType expr_kind, Location locus) :
OperatorExpr(::std::move(value_to_assign_to), ::std::vector<Attribute>(), locus),
expr_type(expr_kind), right_expr(::std::move(value_to_assign)) {}
// outer attributes not allowed
@@ -910,7 +910,7 @@ namespace Rust {
// Expr* expr_in_parens;
::std::unique_ptr<Expr> expr_in_parens;
- location_t locus;
+ Location locus;
public:
/*~GroupedExpr() {
@@ -925,7 +925,7 @@ namespace Rust {
GroupedExpr(::std::unique_ptr<Expr> parenthesised_expr,
::std::vector<Attribute> inner_attribs, ::std::vector<Attribute> outer_attribs,
- location_t locus) :
+ Location locus) :
ExprWithoutBlock(::std::move(outer_attribs)),
inner_attrs(::std::move(inner_attribs)),
expr_in_parens(::std::move(parenthesised_expr)), locus(locus) {}
@@ -952,11 +952,11 @@ namespace Rust {
GroupedExpr(GroupedExpr&& other) = default;
GroupedExpr& operator=(GroupedExpr&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -1101,7 +1101,7 @@ namespace Rust {
// ArrayElems internal_elements;
::std::unique_ptr<ArrayElems> internal_elements;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -1118,7 +1118,7 @@ namespace Rust {
// Constructor requires ArrayElems pointer
ArrayExpr(::std::unique_ptr<ArrayElems> array_elems,
::std::vector<Attribute> inner_attribs, ::std::vector<Attribute> outer_attribs,
- location_t locus) :
+ Location locus) :
ExprWithoutBlock(::std::move(outer_attribs)),
inner_attrs(::std::move(inner_attribs)), internal_elements(::std::move(array_elems)),
locus(locus) {}
@@ -1150,11 +1150,11 @@ namespace Rust {
ArrayExpr(ArrayExpr&& other) = default;
ArrayExpr& operator=(ArrayExpr&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -1182,7 +1182,7 @@ namespace Rust {
::std::unique_ptr<Expr> array_expr;
::std::unique_ptr<Expr> index_expr;
- location_t locus;
+ Location locus;
public:
/*~ArrayIndexExpr() {
@@ -1194,7 +1194,7 @@ namespace Rust {
ArrayIndexExpr(::std::unique_ptr<Expr> array_expr,
::std::unique_ptr<Expr> array_index_expr, ::std::vector<Attribute> outer_attribs,
- location_t locus) :
+ Location locus) :
ExprWithoutBlock(::std::move(outer_attribs)),
array_expr(::std::move(array_expr)), index_expr(::std::move(array_index_expr)),
locus(locus) {}
@@ -1221,11 +1221,11 @@ namespace Rust {
ArrayIndexExpr(ArrayIndexExpr&& other) = default;
ArrayIndexExpr& operator=(ArrayIndexExpr&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -1251,7 +1251,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<Expr> > tuple_elems;
// replaces (inlined version of) TupleElements
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -1262,7 +1262,7 @@ namespace Rust {
TupleExpr(::std::vector< ::std::unique_ptr<Expr> > tuple_elements,
::std::vector<Attribute> inner_attribs, ::std::vector<Attribute> outer_attribs,
- location_t locus) :
+ Location locus) :
ExprWithoutBlock(::std::move(outer_attribs)),
inner_attrs(::std::move(inner_attribs)), tuple_elems(::std::move(tuple_elements)),
locus(locus) {}
@@ -1301,11 +1301,11 @@ namespace Rust {
// Note: syntactically, can disambiguate single-element tuple from parens with comma, i.e.
// (0,) rather than (0)
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -1331,7 +1331,7 @@ namespace Rust {
// TupleIndex is a decimal int literal with no underscores or suffix
TupleIndex tuple_index;
- location_t locus;
+ Location locus;
// i.e. pair.0
@@ -1347,7 +1347,7 @@ namespace Rust {
}
TupleIndexExpr(::std::unique_ptr<Expr> tuple_expr, TupleIndex index,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
ExprWithoutBlock(::std::move(outer_attribs)),
tuple_expr(::std::move(tuple_expr)), tuple_index(index), locus(locus) {}
@@ -1373,11 +1373,11 @@ namespace Rust {
TupleIndexExpr(TupleIndexExpr&& other) = default;
TupleIndexExpr& operator=(TupleIndexExpr&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -1416,7 +1416,7 @@ namespace Rust {
class StructExprStruct : public StructExpr {
::std::vector<Attribute> inner_attrs;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -1427,15 +1427,15 @@ namespace Rust {
// Constructor has to call protected constructor of base class
StructExprStruct(PathInExpression struct_path, ::std::vector<Attribute> inner_attribs,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
StructExpr(::std::move(struct_path), ::std::move(outer_attribs)),
inner_attrs(::std::move(inner_attribs)), locus(locus) {}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -1656,7 +1656,7 @@ namespace Rust {
// Constructor for StructExprStructFields when no struct base is used
StructExprStructFields(PathInExpression struct_path,
- ::std::vector< ::std::unique_ptr<StructExprField> > expr_fields, location_t locus,
+ ::std::vector< ::std::unique_ptr<StructExprField> > expr_fields, Location locus,
StructBase base_struct = StructBase::error(),
::std::vector<Attribute> inner_attribs = ::std::vector<Attribute>(),
::std::vector<Attribute> outer_attribs = ::std::vector<Attribute>()) :
@@ -1756,7 +1756,7 @@ namespace Rust {
StructExprStructBase(PathInExpression struct_path, StructBase base_struct,
::std::vector<Attribute> inner_attribs, ::std::vector<Attribute> outer_attribs,
- location_t locus) :
+ Location locus) :
StructExprStruct(::std::move(struct_path), ::std::move(inner_attribs),
::std::move(outer_attribs), locus),
struct_base(::std::move(base_struct)) {}
@@ -1781,7 +1781,7 @@ namespace Rust {
//::std::vector<Expr> exprs;
::std::vector< ::std::unique_ptr<Expr> > exprs;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -1797,7 +1797,7 @@ namespace Rust {
StructExprTuple(PathInExpression struct_path,
::std::vector< ::std::unique_ptr<Expr> > tuple_exprs,
::std::vector<Attribute> inner_attribs, ::std::vector<Attribute> outer_attribs,
- location_t locus) :
+ Location locus) :
StructExpr(::std::move(struct_path), ::std::move(outer_attribs)),
inner_attrs(::std::move(inner_attribs)), exprs(::std::move(tuple_exprs)), locus(locus) {
}
@@ -1833,11 +1833,11 @@ namespace Rust {
StructExprTuple(StructExprTuple&& other) = default;
StructExprTuple& operator=(StructExprTuple&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -1857,7 +1857,7 @@ namespace Rust {
// AST node of a "unit" struct creator (no fields and no braces)
class StructExprUnit : public StructExpr {
- location_t locus;
+ Location locus;
public:
::std::string as_string() const {
@@ -1866,15 +1866,15 @@ namespace Rust {
}
StructExprUnit(PathInExpression struct_path, ::std::vector<Attribute> outer_attribs,
- location_t locus) :
+ Location locus) :
StructExpr(::std::move(struct_path), ::std::move(outer_attribs)),
locus(locus) {}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -2024,7 +2024,7 @@ namespace Rust {
//::std::vector<EnumExprField> fields;
::std::vector< ::std::unique_ptr<EnumExprField> > fields;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -2035,7 +2035,7 @@ namespace Rust {
EnumExprStruct(PathInExpression enum_variant_path,
::std::vector< ::std::unique_ptr<EnumExprField> > variant_fields,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
EnumVariantExpr(::std::move(enum_variant_path), ::std::move(outer_attribs)),
fields(::std::move(variant_fields)), locus(locus) {}
@@ -2068,11 +2068,11 @@ namespace Rust {
EnumExprStruct(EnumExprStruct&& other) = default;
EnumExprStruct& operator=(EnumExprStruct&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -2095,7 +2095,7 @@ namespace Rust {
//::std::vector<Expr> values;
::std::vector< ::std::unique_ptr<Expr> > values;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -2106,7 +2106,7 @@ namespace Rust {
EnumExprTuple(PathInExpression enum_variant_path,
::std::vector< ::std::unique_ptr<Expr> > variant_values,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
EnumVariantExpr(::std::move(enum_variant_path), ::std::move(outer_attribs)),
values(::std::move(variant_values)), locus(locus) {}
@@ -2139,11 +2139,11 @@ namespace Rust {
EnumExprTuple(EnumExprTuple&& other) = default;
EnumExprTuple& operator=(EnumExprTuple&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -2163,7 +2163,7 @@ namespace Rust {
// No-field enum variant instance creation AST node
class EnumExprFieldless : public EnumVariantExpr {
- location_t locus;
+ Location locus;
public:
::std::string as_string() const {
@@ -2172,17 +2172,17 @@ namespace Rust {
}
EnumExprFieldless(PathInExpression enum_variant_path,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
EnumVariantExpr(::std::move(enum_variant_path), ::std::move(outer_attribs)),
locus(locus) {}
// copy constructor, destructor, and assignment operator should not need defining
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -2207,7 +2207,7 @@ namespace Rust {
//::std::vector<Expr> params; // inlined form of CallParams
::std::vector< ::std::unique_ptr<Expr> > params;
- location_t locus;
+ Location locus;
public:
/*~CallExpr() {
@@ -2222,7 +2222,7 @@ namespace Rust {
CallExpr(::std::unique_ptr<Expr> function_expr,
::std::vector< ::std::unique_ptr<Expr> > function_params,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
ExprWithoutBlock(::std::move(outer_attribs)),
function(::std::move(function_expr)), params(::std::move(function_params)),
locus(locus) {}
@@ -2268,11 +2268,11 @@ namespace Rust {
return !params.empty();
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -2298,7 +2298,7 @@ namespace Rust {
//::std::vector<Expr> params; // inlined form of CallParams
::std::vector< ::std::unique_ptr<Expr> > params;
- location_t locus;
+ Location locus;
public:
/*~MethodCallExpr() {
@@ -2313,7 +2313,7 @@ namespace Rust {
MethodCallExpr(::std::unique_ptr<Expr> call_receiver, PathExprSegment method_path,
::std::vector< ::std::unique_ptr<Expr> > method_params,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
ExprWithoutBlock(::std::move(outer_attribs)),
receiver(::std::move(call_receiver)), method_name(::std::move(method_path)),
params(::std::move(method_params)), locus(locus) {}
@@ -2356,11 +2356,11 @@ namespace Rust {
MethodCallExpr(MethodCallExpr&& other) = default;
MethodCallExpr& operator=(MethodCallExpr&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -2385,7 +2385,7 @@ namespace Rust {
::std::unique_ptr<Expr> receiver;
Identifier field;
- location_t locus;
+ Location locus;
public:
/*~FieldAccessExpr() {
@@ -2395,7 +2395,7 @@ namespace Rust {
::std::string as_string() const;
FieldAccessExpr(::std::unique_ptr<Expr> field_access_receiver, Identifier field_name,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
ExprWithoutBlock(::std::move(outer_attribs)),
receiver(::std::move(field_access_receiver)), field(::std::move(field_name)),
locus(locus) {}
@@ -2422,11 +2422,11 @@ namespace Rust {
FieldAccessExpr(FieldAccessExpr&& other) = default;
FieldAccessExpr& operator=(FieldAccessExpr&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -2509,11 +2509,11 @@ namespace Rust {
::std::vector<ClosureParam> params; // may be empty
// also note a double pipe "||" can be used for empty params - does not need a space
- location_t locus;
+ Location locus;
protected:
ClosureExpr(::std::vector<ClosureParam> closure_params, bool has_move,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
ExprWithoutBlock(::std::move(outer_attribs)),
has_move(has_move), params(::std::move(closure_params)), locus(locus) {}
@@ -2521,11 +2521,11 @@ namespace Rust {
public:
virtual ::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
};
@@ -2544,7 +2544,7 @@ namespace Rust {
// Constructor for a ClosureExprInner
ClosureExprInner(::std::unique_ptr<Expr> closure_inner_expr,
- ::std::vector<ClosureParam> closure_params, location_t locus, bool is_move = false,
+ ::std::vector<ClosureParam> closure_params, Location locus, bool is_move = false,
::std::vector<Attribute> outer_attribs = ::std::vector<Attribute>()) :
ClosureExpr(::std::move(closure_params), is_move, ::std::move(outer_attribs), locus),
closure_inner(::std::move(closure_inner_expr)) {}
@@ -2600,7 +2600,7 @@ namespace Rust {
// bool has_expr;
::std::unique_ptr<ExprWithoutBlock> expr; // inlined from Statements
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -2617,7 +2617,7 @@ namespace Rust {
BlockExpr(::std::vector< ::std::unique_ptr<Stmt> > block_statements,
::std::unique_ptr<ExprWithoutBlock> block_expr, ::std::vector<Attribute> inner_attribs,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
ExprWithBlock(::std::move(outer_attribs)),
inner_attrs(::std::move(inner_attribs)), statements(::std::move(block_statements)),
expr(::std::move(block_expr)), locus(locus) {}
@@ -2669,11 +2669,11 @@ namespace Rust {
return ::std::unique_ptr<BlockExpr>(clone_block_expr_impl());
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -2714,7 +2714,7 @@ namespace Rust {
// Constructor potentially with a move
ClosureExprInnerTyped(::std::unique_ptr<Type> closure_return_type,
::std::unique_ptr<BlockExpr> closure_expr, ::std::vector<ClosureParam> closure_params,
- location_t locus, bool is_move = false,
+ Location locus, bool is_move = false,
::std::vector<Attribute> outer_attribs = ::std::vector<Attribute>()) :
ClosureExpr(::std::move(closure_params), is_move, ::std::move(outer_attribs), locus),
return_type(::std::move(closure_return_type)), expr(::std::move(closure_expr)) {}
@@ -2761,7 +2761,7 @@ namespace Rust {
// bool has_label;
Lifetime label;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -2772,18 +2772,18 @@ namespace Rust {
}
// Constructor for a ContinueExpr with a label.
- ContinueExpr(location_t locus, Lifetime label = Lifetime::error(),
+ ContinueExpr(Location locus, Lifetime label = Lifetime::error(),
::std::vector<Attribute> outer_attribs = ::std::vector<Attribute>()) :
ExprWithoutBlock(::std::move(outer_attribs)),
label(::std::move(label)), locus(locus) {}
// copy constructor, destructor, and assignment operator should not need defining
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -2811,7 +2811,7 @@ namespace Rust {
// Expr* break_expr; // may be uninitialised
::std::unique_ptr<Expr> break_expr;
- location_t locus;
+ Location locus;
public:
/*~BreakExpr() {
@@ -2833,7 +2833,7 @@ namespace Rust {
}
// Constructor for a break expression
- BreakExpr(location_t locus, Lifetime break_label = Lifetime::error(),
+ BreakExpr(Location locus, Lifetime break_label = Lifetime::error(),
::std::unique_ptr<Expr> expr_in_break = NULL,
::std::vector<Attribute> outer_attribs = ::std::vector<Attribute>()) :
ExprWithoutBlock(::std::move(outer_attribs)),
@@ -2865,11 +2865,11 @@ namespace Rust {
BreakExpr(BreakExpr&& other) = default;
BreakExpr& operator=(BreakExpr&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -2889,19 +2889,19 @@ namespace Rust {
// Base range expression AST node object - abstract
class RangeExpr : public ExprWithoutBlock {
- location_t locus;
+ Location locus;
protected:
// outer attributes not allowed before range expressions
- RangeExpr(location_t locus) :
+ RangeExpr(Location locus) :
ExprWithoutBlock(::std::vector<Attribute>()), locus(locus) {}
public:
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
};
@@ -2923,7 +2923,7 @@ namespace Rust {
::std::string as_string() const;
RangeFromToExpr(::std::unique_ptr<Expr> range_from, ::std::unique_ptr<Expr> range_to,
- location_t locus) :
+ Location locus) :
RangeExpr(locus),
from(::std::move(range_from)), to(::std::move(range_to)) {}
@@ -2973,7 +2973,7 @@ namespace Rust {
::std::string as_string() const;
- RangeFromExpr(::std::unique_ptr<Expr> range_from, location_t locus) :
+ RangeFromExpr(::std::unique_ptr<Expr> range_from, Location locus) :
RangeExpr(locus), from(::std::move(range_from)) {}
// Copy constructor with clone
@@ -3022,7 +3022,7 @@ namespace Rust {
::std::string as_string() const;
// outer attributes not allowed
- RangeToExpr(::std::unique_ptr<Expr> range_to, location_t locus) :
+ RangeToExpr(::std::unique_ptr<Expr> range_to, Location locus) :
RangeExpr(locus), to(::std::move(range_to)) {}
// Copy constructor with clone
@@ -3062,7 +3062,7 @@ namespace Rust {
public:
::std::string as_string() const;
- RangeFullExpr(location_t locus) : RangeExpr(locus) {}
+ RangeFullExpr(Location locus) : RangeExpr(locus) {}
// outer attributes not allowed
virtual void accept_vis(ASTVisitor& vis) OVERRIDE;
@@ -3096,7 +3096,7 @@ namespace Rust {
::std::string as_string() const;
RangeFromToInclExpr(::std::unique_ptr<Expr> range_from, ::std::unique_ptr<Expr> range_to,
- location_t locus) :
+ Location locus) :
RangeExpr(locus),
from(::std::move(range_from)), to(::std::move(range_to)) {}
// outer attributes not allowed
@@ -3147,7 +3147,7 @@ namespace Rust {
::std::string as_string() const;
- RangeToInclExpr(::std::unique_ptr<Expr> range_to, location_t locus) :
+ RangeToInclExpr(::std::unique_ptr<Expr> range_to, Location locus) :
RangeExpr(locus), to(::std::move(range_to)) {}
// outer attributes not allowed
@@ -3189,7 +3189,7 @@ namespace Rust {
// Expr* return_expr;
::std::unique_ptr<Expr> return_expr;
- location_t locus;
+ Location locus;
public:
/*~ReturnExpr() {
@@ -3206,7 +3206,7 @@ namespace Rust {
}
// Constructor for ReturnExpr.
- ReturnExpr(location_t locus, ::std::unique_ptr<Expr> returned_expr = NULL,
+ ReturnExpr(Location locus, ::std::unique_ptr<Expr> returned_expr = NULL,
::std::vector<Attribute> outer_attribs = ::std::vector<Attribute>()) :
ExprWithoutBlock(::std::move(outer_attribs)),
return_expr(::std::move(returned_expr)), locus(locus) {}
@@ -3235,11 +3235,11 @@ namespace Rust {
ReturnExpr(ReturnExpr&& other) = default;
ReturnExpr& operator=(ReturnExpr&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -3270,7 +3270,7 @@ namespace Rust {
// BlockExpr* expr;
::std::unique_ptr<BlockExpr> expr;
- location_t locus;
+ Location locus;
public:
/*~UnsafeBlockExpr() {
@@ -3280,7 +3280,7 @@ namespace Rust {
::std::string as_string() const;
UnsafeBlockExpr(::std::unique_ptr<BlockExpr> block_expr,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
ExprWithBlock(::std::move(outer_attribs)),
expr(::std::move(block_expr)), locus(locus) {}
@@ -3304,11 +3304,11 @@ namespace Rust {
UnsafeBlockExpr(UnsafeBlockExpr&& other) = default;
UnsafeBlockExpr& operator=(UnsafeBlockExpr&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -3331,12 +3331,12 @@ namespace Rust {
class LoopLabel /*: public Node*/ {
Lifetime label; // or type LIFETIME_OR_LABEL
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
- LoopLabel(Lifetime loop_label, location_t locus = UNKNOWN_LOCATION) :
+ LoopLabel(Lifetime loop_label, Location locus = Location()) :
label(::std::move(loop_label)), locus(locus) {}
// Returns whether the LoopLabel is in an error state.
@@ -3349,7 +3349,7 @@ namespace Rust {
return LoopLabel(Lifetime::error());
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
};
@@ -3365,11 +3365,11 @@ namespace Rust {
::std::unique_ptr<BlockExpr> loop_block;
private:
- location_t locus;
+ Location locus;
protected:
// Constructor for BaseLoopExpr
- BaseLoopExpr(::std::unique_ptr<BlockExpr> loop_block, location_t locus,
+ BaseLoopExpr(::std::unique_ptr<BlockExpr> loop_block, Location locus,
LoopLabel loop_label = LoopLabel::error(),
::std::vector<Attribute> outer_attribs = ::std::vector<Attribute>()) :
ExprWithBlock(::std::move(outer_attribs)),
@@ -3407,11 +3407,11 @@ namespace Rust {
return !loop_label.is_error();
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
};
@@ -3422,7 +3422,7 @@ namespace Rust {
::std::string as_string() const;
// Constructor for LoopExpr
- LoopExpr(::std::unique_ptr<BlockExpr> loop_block, location_t locus,
+ LoopExpr(::std::unique_ptr<BlockExpr> loop_block, Location locus,
LoopLabel loop_label = LoopLabel::error(),
::std::vector<Attribute> outer_attribs = ::std::vector<Attribute>()) :
BaseLoopExpr(::std::move(loop_block), locus, ::std::move(loop_label),
@@ -3458,7 +3458,7 @@ namespace Rust {
// Constructor for while loop with loop label
WhileLoopExpr(::std::unique_ptr<Expr> loop_condition,
- ::std::unique_ptr<BlockExpr> loop_block, location_t locus,
+ ::std::unique_ptr<BlockExpr> loop_block, Location locus,
LoopLabel loop_label = LoopLabel::error(),
::std::vector<Attribute> outer_attribs = ::std::vector<Attribute>()) :
BaseLoopExpr(
@@ -3520,7 +3520,7 @@ namespace Rust {
// Constructor with a loop label
WhileLetLoopExpr(::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns,
::std::unique_ptr<Expr> condition, ::std::unique_ptr<BlockExpr> loop_block,
- location_t locus, LoopLabel loop_label = LoopLabel::error(),
+ Location locus, LoopLabel loop_label = LoopLabel::error(),
::std::vector<Attribute> outer_attribs = ::std::vector<Attribute>()) :
BaseLoopExpr(
::std::move(loop_block), locus, ::std::move(loop_label), ::std::move(outer_attribs)),
@@ -3595,7 +3595,7 @@ namespace Rust {
// Constructor with loop label
ForLoopExpr(::std::unique_ptr<Pattern> loop_pattern,
::std::unique_ptr<Expr> iterator_expr, ::std::unique_ptr<BlockExpr> loop_body,
- location_t locus, LoopLabel loop_label = LoopLabel::error(),
+ Location locus, LoopLabel loop_label = LoopLabel::error(),
::std::vector<Attribute> outer_attribs = ::std::vector<Attribute>()) :
BaseLoopExpr(
::std::move(loop_body), locus, ::std::move(loop_label), ::std::move(outer_attribs)),
@@ -3653,7 +3653,7 @@ namespace Rust {
IfLetExpr if_let_expr;
} consequent_block;*/
- location_t locus;
+ Location locus;
public:
/*virtual ~IfExpr() {
@@ -3664,7 +3664,7 @@ namespace Rust {
::std::string as_string() const;
IfExpr(::std::unique_ptr<Expr> condition, ::std::unique_ptr<BlockExpr> if_block,
- location_t locus) :
+ Location locus) :
ExprWithBlock(::std::vector<Attribute>()),
condition(::std::move(condition)), if_block(::std::move(if_block)), locus(locus) {}
// outer attributes are never allowed on IfExprs
@@ -3699,11 +3699,11 @@ namespace Rust {
* else ifs - i.e. not like a switch statement. TODO - is this a better approach? or
* does it not parse correctly and have downsides? */
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -3739,7 +3739,7 @@ namespace Rust {
::std::string as_string() const;
IfExprConseqElse(::std::unique_ptr<Expr> condition, ::std::unique_ptr<BlockExpr> if_block,
- ::std::unique_ptr<BlockExpr> else_block, location_t locus) :
+ ::std::unique_ptr<BlockExpr> else_block, Location locus) :
IfExpr(::std::move(condition), ::std::move(if_block), locus),
else_block(::std::move(else_block)) {}
// again, outer attributes not allowed
@@ -3796,7 +3796,7 @@ namespace Rust {
::std::string as_string() const;
IfExprConseqIf(::std::unique_ptr<Expr> condition, ::std::unique_ptr<BlockExpr> if_block,
- ::std::unique_ptr<IfExpr> conseq_if_expr, location_t locus) :
+ ::std::unique_ptr<IfExpr> conseq_if_expr, Location locus) :
IfExpr(::std::move(condition), ::std::move(if_block), locus),
if_expr(::std::move(conseq_if_expr)) {}
// outer attributes not allowed
@@ -3854,14 +3854,14 @@ namespace Rust {
IfLetExpr* if_let_expr;
} consequent_block;*/
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
IfLetExpr(::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns,
::std::unique_ptr<Expr> value, ::std::unique_ptr<BlockExpr> if_block,
- location_t locus) :
+ Location locus) :
ExprWithBlock(::std::vector<Attribute>()),
match_arm_patterns(::std::move(match_arm_patterns)), value(::std::move(value)),
if_block(::std::move(if_block)), locus(locus) {}
@@ -3909,11 +3909,11 @@ namespace Rust {
return ::std::unique_ptr<IfLetExpr>(clone_if_let_expr_impl());
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -3950,7 +3950,7 @@ namespace Rust {
IfExprConseqIfLet(::std::unique_ptr<Expr> condition,
::std::unique_ptr<BlockExpr> if_block, ::std::unique_ptr<IfLetExpr> conseq_if_let_expr,
- location_t locus) :
+ Location locus) :
IfExpr(::std::move(condition), ::std::move(if_block), locus),
if_let_expr(::std::move(conseq_if_let_expr)) {}
// outer attributes not allowed
@@ -4008,7 +4008,7 @@ namespace Rust {
IfLetExprConseqElse(::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns,
::std::unique_ptr<Expr> value, ::std::unique_ptr<BlockExpr> if_block,
- ::std::unique_ptr<BlockExpr> else_block, location_t locus) :
+ ::std::unique_ptr<BlockExpr> else_block, Location locus) :
IfLetExpr(
::std::move(match_arm_patterns), ::std::move(value), ::std::move(if_block), locus),
else_block(::std::move(else_block)) {}
@@ -4069,7 +4069,7 @@ namespace Rust {
IfLetExprConseqIf(::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns,
::std::unique_ptr<Expr> value, ::std::unique_ptr<BlockExpr> if_block,
- ::std::unique_ptr<IfExpr> if_expr, location_t locus) :
+ ::std::unique_ptr<IfExpr> if_expr, Location locus) :
IfLetExpr(
::std::move(match_arm_patterns), ::std::move(value), ::std::move(if_block), locus),
if_expr(::std::move(if_expr)) {}
@@ -4129,7 +4129,7 @@ namespace Rust {
IfLetExprConseqIfLet(::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns,
::std::unique_ptr<Expr> value, ::std::unique_ptr<BlockExpr> if_block,
- ::std::unique_ptr<IfLetExpr> if_let_expr, location_t locus) :
+ ::std::unique_ptr<IfLetExpr> if_let_expr, Location locus) :
IfLetExpr(
::std::move(match_arm_patterns), ::std::move(value), ::std::move(if_block), locus),
if_let_expr(::std::move(if_let_expr)) {}
@@ -4413,7 +4413,7 @@ namespace Rust {
// MatchArms match_arms;
::std::vector< ::std::unique_ptr<MatchCase> > match_arms; // inlined from MatchArms
- location_t locus;
+ Location locus;
public:
/*~MatchExpr() {
@@ -4430,7 +4430,7 @@ namespace Rust {
MatchExpr(::std::unique_ptr<Expr> branch_value,
::std::vector< ::std::unique_ptr<MatchCase> > match_arms,
::std::vector<Attribute> inner_attrs, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
ExprWithBlock(::std::move(outer_attrs)),
branch_value(::std::move(branch_value)), inner_attrs(::std::move(inner_attrs)),
match_arms(::std::move(match_arms)), locus(locus) {}
@@ -4481,11 +4481,11 @@ namespace Rust {
MatchExpr(MatchExpr&& other) = default;
MatchExpr& operator=(MatchExpr&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -4507,12 +4507,12 @@ namespace Rust {
class AwaitExpr : public ExprWithoutBlock {
::std::unique_ptr<Expr> awaited_expr;
- location_t locus;
+ Location locus;
public:
// TODO: ensure outer attributes are actually allowed
AwaitExpr(::std::unique_ptr<Expr> awaited_expr, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
ExprWithoutBlock(::std::move(outer_attrs)),
awaited_expr(::std::move(awaited_expr)), locus(locus) {}
@@ -4538,11 +4538,11 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -4561,11 +4561,11 @@ namespace Rust {
bool has_move;
::std::unique_ptr<BlockExpr> block_expr;
- location_t locus;
+ Location locus;
public:
AsyncBlockExpr(::std::unique_ptr<BlockExpr> block_expr, bool has_move,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
ExprWithBlock(::std::move(outer_attrs)),
has_move(has_move), block_expr(::std::move(block_expr)), locus(locus) {}
@@ -4592,11 +4592,11 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -4611,4 +4611,4 @@ namespace Rust {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index c5154f5..7c69978 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -50,7 +50,7 @@ namespace Rust {
// Type type;
::std::unique_ptr<Type> type;
- location_t locus;
+ Location locus;
public:
// Returns whether the type of the type param has been specified.
@@ -68,7 +68,7 @@ namespace Rust {
return !outer_attr.is_empty();
}
- TypeParam(Identifier type_representation, location_t locus = UNKNOWN_LOCATION,
+ TypeParam(Identifier type_representation, Location locus = Location(),
::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds
= ::std::vector< ::std::unique_ptr<TypeParamBound> >(),
::std::unique_ptr<Type> type = NULL, Attribute outer_attr = Attribute::create_empty()) :
@@ -116,7 +116,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -314,7 +314,7 @@ namespace Rust {
// Type type;
::std::unique_ptr<Type> type;
- location_t locus;
+ Location locus;
// Unrestricted constructor used for error state
SelfParam(Lifetime lifetime, bool has_ref, bool is_mut, Type* type) :
@@ -347,12 +347,12 @@ namespace Rust {
}
// Type-based self parameter (not ref, no lifetime)
- SelfParam(::std::unique_ptr<Type> type, bool is_mut, location_t locus) :
+ SelfParam(::std::unique_ptr<Type> type, bool is_mut, Location locus) :
has_ref(false), is_mut(is_mut), lifetime(Lifetime::error()), type(::std::move(type)),
locus(locus) {}
// Lifetime-based self parameter (is ref, no type)
- SelfParam(Lifetime lifetime, bool is_mut, location_t locus) :
+ SelfParam(Lifetime lifetime, bool is_mut, Location locus) :
/*type(NULL), */ has_ref(true), is_mut(is_mut), lifetime(::std::move(lifetime)),
locus(locus) {}
@@ -380,7 +380,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
};
@@ -432,11 +432,11 @@ namespace Rust {
// Type type;
::std::unique_ptr<Type> type;
- location_t locus;
+ Location locus;
public:
FunctionParam(::std::unique_ptr<Pattern> param_name, ::std::unique_ptr<Type> param_type,
- location_t locus) :
+ Location locus) :
param_name(::std::move(param_name)),
type(::std::move(param_type)), locus(locus) {}
@@ -467,12 +467,12 @@ namespace Rust {
// Creates an error FunctionParam.
static FunctionParam create_error() {
- return FunctionParam(NULL, NULL, UNKNOWN_LOCATION);
+ return FunctionParam(NULL, NULL, Location());
}
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
};
@@ -587,7 +587,7 @@ namespace Rust {
// BlockExpr* expr;
::std::unique_ptr<BlockExpr> expr;
- location_t locus;
+ Location locus;
public:
/*~Method() {
@@ -637,7 +637,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<GenericParam> > generic_params, SelfParam self_param,
::std::vector<FunctionParam> function_params, ::std::unique_ptr<Type> return_type,
WhereClause where_clause, ::std::unique_ptr<BlockExpr> function_body, Visibility vis,
- ::std::vector<Attribute> outer_attrs, location_t locus = UNKNOWN_LOCATION) :
+ ::std::vector<Attribute> outer_attrs, Location locus = Location()) :
outer_attrs(::std::move(outer_attrs)),
vis(::std::move(vis)), qualifiers(::std::move(qualifiers)),
method_name(::std::move(method_name)), generic_params(::std::move(generic_params)),
@@ -751,11 +751,11 @@ namespace Rust {
class Module : public VisItem {
Identifier module_name;
- location_t locus;
+ Location locus;
protected:
// Protected constructor
- Module(Identifier module_name, Visibility visibility, location_t locus,
+ Module(Identifier module_name, Visibility visibility, Location locus,
::std::vector<Attribute> outer_attrs = ::std::vector<Attribute>()) :
VisItem(::std::move(visibility), ::std::move(outer_attrs)),
module_name(module_name), locus(locus) {}
@@ -763,7 +763,7 @@ namespace Rust {
public:
virtual ::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
};
@@ -790,7 +790,7 @@ namespace Rust {
}
// Full constructor
- ModuleBodied(Identifier name, location_t locus,
+ ModuleBodied(Identifier name, Location locus,
::std::vector< ::std::unique_ptr<Item> > items
= ::std::vector< ::std::unique_ptr<Item> >(),
Visibility visibility = Visibility::create_error(),
@@ -852,7 +852,7 @@ namespace Rust {
// Full constructor
ModuleNoBody(Identifier name, Visibility visibility, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
Module(::std::move(name), ::std::move(visibility), locus, ::std::move(outer_attrs)) {}
virtual void accept_vis(ASTVisitor& vis) OVERRIDE;
@@ -878,7 +878,7 @@ namespace Rust {
// this is either an identifier or "_", with _ parsed to string
::std::string as_clause_name;
- location_t locus;
+ Location locus;
/* e.g.
"extern crate foo as _"
@@ -899,13 +899,13 @@ namespace Rust {
// Constructor
ExternCrate(::std::string referenced_crate, Visibility visibility,
- ::std::vector<Attribute> outer_attrs, location_t locus,
+ ::std::vector<Attribute> outer_attrs, Location locus,
::std::string as_clause_name = ::std::string()) :
VisItem(::std::move(visibility), ::std::move(outer_attrs)),
referenced_crate(::std::move(referenced_crate)),
as_clause_name(::std::move(as_clause_name)), locus(locus) {}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -930,7 +930,7 @@ namespace Rust {
// The path-ish thing referred to in a use declaration - abstract base class
class UseTree {
- location_t locus;
+ Location locus;
public:
virtual ~UseTree() {}
@@ -942,7 +942,7 @@ namespace Rust {
virtual ::std::string as_string() const = 0;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -952,7 +952,7 @@ namespace Rust {
// Clone function implementation as pure virtual method
virtual UseTree* clone_use_tree_impl() const = 0;
- UseTree(location_t locus) : locus(locus) {}
+ UseTree(Location locus) : locus(locus) {}
};
// Use tree with a glob (wildcard) operator
@@ -965,7 +965,7 @@ namespace Rust {
SimplePath path;
public:
- UseTreeGlob(PathType glob_type, SimplePath path, location_t locus) :
+ UseTreeGlob(PathType glob_type, SimplePath path, Location locus) :
UseTree(locus), glob_type(glob_type), path(::std::move(path)) {}
// Returns whether has path. Should be made redundant by PathType PATH_PREFIXED.
@@ -998,7 +998,7 @@ namespace Rust {
public:
UseTreeList(PathType path_type, SimplePath path,
- ::std::vector< ::std::unique_ptr<UseTree> > trees, location_t locus) :
+ ::std::vector< ::std::unique_ptr<UseTree> > trees, Location locus) :
UseTree(locus),
path_type(path_type), path(::std::move(path)), trees(::std::move(trees)) {}
@@ -1067,7 +1067,7 @@ namespace Rust {
Identifier identifier; // only if NewBindType is IDENTIFIER
public:
- UseTreeRebind(NewBindType bind_type, SimplePath path, location_t locus,
+ UseTreeRebind(NewBindType bind_type, SimplePath path, Location locus,
Identifier identifier = ::std::string()) :
UseTree(locus),
path(::std::move(path)), bind_type(bind_type), identifier(::std::move(identifier)) {}
@@ -1098,13 +1098,13 @@ namespace Rust {
class UseDeclaration : public VisItem {
::std::unique_ptr<UseTree> use_tree;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
UseDeclaration(::std::unique_ptr<UseTree> use_tree, Visibility visibility,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
VisItem(::std::move(visibility), ::std::move(outer_attrs)),
use_tree(::std::move(use_tree)), locus(locus) {}
@@ -1129,7 +1129,7 @@ namespace Rust {
UseDeclaration(UseDeclaration&& other) = default;
UseDeclaration& operator=(UseDeclaration&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -1179,7 +1179,7 @@ namespace Rust {
// BlockExpr* function_body;
::std::unique_ptr<BlockExpr> function_body;
- location_t locus;
+ Location locus;
public:
/*~Function() {
@@ -1212,7 +1212,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
::std::vector<FunctionParam> function_params, ::std::unique_ptr<Type> return_type,
WhereClause where_clause, ::std::unique_ptr<BlockExpr> function_body, Visibility vis,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
VisItem(::std::move(vis), ::std::move(outer_attrs)),
qualifiers(::std::move(qualifiers)), function_name(::std::move(function_name)),
generic_params(::std::move(generic_params)),
@@ -1266,7 +1266,7 @@ namespace Rust {
Function(Function&& other) = default;
Function& operator=(Function&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -1310,7 +1310,7 @@ namespace Rust {
// Type exiting_type;
::std::unique_ptr<Type> existing_type;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -1329,7 +1329,7 @@ namespace Rust {
TypeAlias(Identifier new_type_name,
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
WhereClause where_clause, ::std::unique_ptr<Type> existing_type, Visibility vis,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
VisItem(::std::move(vis), ::std::move(outer_attrs)),
new_type_name(::std::move(new_type_name)), generic_params(::std::move(generic_params)),
where_clause(::std::move(where_clause)), existing_type(::std::move(existing_type)),
@@ -1376,7 +1376,7 @@ namespace Rust {
TypeAlias(TypeAlias&& other) = default;
TypeAlias& operator=(TypeAlias&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -1412,7 +1412,7 @@ namespace Rust {
// bool has_where_clause;
WhereClause where_clause;
- location_t locus;
+ Location locus;
public:
// Returns whether struct has generic parameters.
@@ -1425,14 +1425,14 @@ namespace Rust {
return !where_clause.is_empty();
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
protected:
Struct(Identifier struct_name,
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
- WhereClause where_clause, Visibility vis, location_t locus,
+ WhereClause where_clause, Visibility vis, Location locus,
::std::vector<Attribute> outer_attrs = ::std::vector<Attribute>()) :
VisItem(::std::move(vis), ::std::move(outer_attrs)),
struct_name(::std::move(struct_name)), generic_params(::std::move(generic_params)),
@@ -1551,7 +1551,7 @@ namespace Rust {
StructStruct(::std::vector<StructField> fields, Identifier struct_name,
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
WhereClause where_clause, bool is_unit, Visibility vis,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
Struct(::std::move(struct_name), ::std::move(generic_params), ::std::move(where_clause),
::std::move(vis), locus, ::std::move(outer_attrs)),
fields(::std::move(fields)), is_unit(is_unit) {}
@@ -1560,7 +1560,7 @@ namespace Rust {
StructStruct(Identifier struct_name,
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
WhereClause where_clause, Visibility vis, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
Struct(::std::move(struct_name), ::std::move(generic_params), ::std::move(where_clause),
::std::move(vis), locus, ::std::move(outer_attrs)),
is_unit(true) {}
@@ -1661,7 +1661,7 @@ namespace Rust {
TupleStruct(::std::vector<TupleField> fields, Identifier struct_name,
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
WhereClause where_clause, Visibility vis, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
Struct(::std::move(struct_name), ::std::move(generic_params), ::std::move(where_clause),
::std::move(vis), locus, ::std::move(outer_attrs)),
fields(::std::move(fields)) {}
@@ -1687,7 +1687,7 @@ namespace Rust {
Identifier variant_name;
- location_t locus;
+ Location locus;
public:
virtual ~EnumItem() {}
@@ -1698,7 +1698,7 @@ namespace Rust {
}
EnumItem(
- Identifier variant_name, ::std::vector<Attribute> outer_attrs, location_t locus) :
+ Identifier variant_name, ::std::vector<Attribute> outer_attrs, Location locus) :
outer_attrs(::std::move(outer_attrs)),
variant_name(::std::move(variant_name)), locus(locus) {}
@@ -1731,7 +1731,7 @@ namespace Rust {
}
EnumItemTuple(Identifier variant_name, ::std::vector<TupleField> tuple_fields,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
EnumItem(::std::move(variant_name), ::std::move(outer_attrs), locus),
tuple_fields(::std::move(tuple_fields)) {}
@@ -1758,7 +1758,7 @@ namespace Rust {
}
EnumItemStruct(Identifier variant_name, ::std::vector<StructField> struct_fields,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
EnumItem(::std::move(variant_name), ::std::move(outer_attrs), locus),
struct_fields(::std::move(struct_fields)) {}
@@ -1784,7 +1784,7 @@ namespace Rust {
}*/
EnumItemDiscriminant(Identifier variant_name, ::std::unique_ptr<Expr> expr,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
EnumItem(::std::move(variant_name), ::std::move(outer_attrs), locus),
expression(::std::move(expr)) {}
@@ -1832,7 +1832,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<EnumItem> > items;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -1857,7 +1857,7 @@ namespace Rust {
Enum(Identifier enum_name, Visibility vis,
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
WhereClause where_clause, ::std::vector< ::std::unique_ptr<EnumItem> > items,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
VisItem(::std::move(vis), ::std::move(outer_attrs)),
enum_name(::std::move(enum_name)), generic_params(::std::move(generic_params)),
where_clause(::std::move(where_clause)), items(::std::move(items)), locus(locus) {}
@@ -1911,7 +1911,7 @@ namespace Rust {
Enum(Enum&& other) = default;
Enum& operator=(Enum&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -1942,7 +1942,7 @@ namespace Rust {
::std::vector<StructField> variants;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -1960,7 +1960,7 @@ namespace Rust {
Union(Identifier union_name, Visibility vis,
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
WhereClause where_clause, ::std::vector<StructField> variants,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
VisItem(::std::move(vis), ::std::move(outer_attrs)),
union_name(::std::move(union_name)), generic_params(::std::move(generic_params)),
where_clause(::std::move(where_clause)), variants(::std::move(variants)), locus(locus) {
@@ -2000,7 +2000,7 @@ namespace Rust {
Union(Union&& other) = default;
Union& operator=(Union&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -2034,7 +2034,7 @@ namespace Rust {
// Expr* const_expr;
::std::unique_ptr<Expr> const_expr;
- location_t locus;
+ Location locus;
public:
/*~ConstantItem() {
@@ -2045,7 +2045,7 @@ namespace Rust {
ConstantItem(Identifier ident, Visibility vis, ::std::unique_ptr<Type> type,
::std::unique_ptr<Expr> const_expr, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
VisItem(::std::move(vis), ::std::move(outer_attrs)),
identifier(::std::move(ident)), type(::std::move(type)),
const_expr(::std::move(const_expr)), locus(locus) {}
@@ -2077,7 +2077,7 @@ namespace Rust {
return identifier == ::std::string("_");
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -2117,7 +2117,7 @@ namespace Rust {
// Expr* expr;
::std::unique_ptr<Expr> expr;
- location_t locus;
+ Location locus;
public:
/*~StaticItem() {
@@ -2128,7 +2128,7 @@ namespace Rust {
StaticItem(Identifier name, bool is_mut, ::std::unique_ptr<Type> type,
::std::unique_ptr<Expr> expr, Visibility vis, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
VisItem(::std::move(vis), ::std::move(outer_attrs)),
has_mut(is_mut), name(::std::move(name)), type(::std::move(type)),
expr(::std::move(expr)), locus(locus) {}
@@ -2156,7 +2156,7 @@ namespace Rust {
StaticItem(StaticItem&& other) = default;
StaticItem& operator=(StaticItem&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -2277,7 +2277,7 @@ namespace Rust {
// BlockExpr* block_expr;
::std::unique_ptr<BlockExpr> block_expr;
- location_t locus;
+ Location locus;
public:
/*~TraitItemFunc() {
@@ -2290,7 +2290,7 @@ namespace Rust {
}
TraitItemFunc(TraitFunctionDecl decl, ::std::unique_ptr<BlockExpr> block_expr,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
outer_attrs(::std::move(outer_attrs)),
decl(::std::move(decl)), block_expr(::std::move(block_expr)), locus(locus) {}
@@ -2325,7 +2325,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -2445,7 +2445,7 @@ namespace Rust {
// BlockExpr* block_expr;
::std::unique_ptr<BlockExpr> block_expr;
- location_t locus;
+ Location locus;
public:
/*~TraitItemMethod() {
@@ -2458,7 +2458,7 @@ namespace Rust {
}
TraitItemMethod(TraitMethodDecl decl, ::std::unique_ptr<BlockExpr> block_expr,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
outer_attrs(::std::move(outer_attrs)),
decl(::std::move(decl)), block_expr(::std::move(block_expr)), locus(locus) {}
@@ -2486,7 +2486,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -2510,7 +2510,7 @@ namespace Rust {
// Expr* expr;
::std::unique_ptr<Expr> expr;
- location_t locus;
+ Location locus;
public:
/*~TraitItemConst() {
@@ -2523,7 +2523,7 @@ namespace Rust {
}
TraitItemConst(Identifier name, ::std::unique_ptr<Type> type,
- ::std::unique_ptr<Expr> expr, ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::unique_ptr<Expr> expr, ::std::vector<Attribute> outer_attrs, Location locus) :
outer_attrs(::std::move(outer_attrs)),
name(::std::move(name)), type(::std::move(type)), expr(::std::move(expr)),
locus(locus) {}
@@ -2553,7 +2553,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -2576,7 +2576,7 @@ namespace Rust {
// TypeParamBounds type_param_bounds;
::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds; // inlined form
- location_t locus;
+ Location locus;
public:
// Returns whether trait item type has type param bounds.
@@ -2586,7 +2586,7 @@ namespace Rust {
TraitItemType(Identifier name,
::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
outer_attrs(::std::move(outer_attrs)),
name(::std::move(name)), type_param_bounds(::std::move(type_param_bounds)),
locus(locus) {}
@@ -2625,7 +2625,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -2671,7 +2671,7 @@ namespace Rust {
// bool has_trait_items;
::std::vector< ::std::unique_ptr<TraitItem> > trait_items;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -2701,7 +2701,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds,
WhereClause where_clause, ::std::vector< ::std::unique_ptr<TraitItem> > trait_items,
- Visibility vis, ::std::vector<Attribute> outer_attrs, location_t locus) :
+ Visibility vis, ::std::vector<Attribute> outer_attrs, Location locus) :
VisItem(::std::move(vis), ::std::move(outer_attrs)),
has_unsafe(is_unsafe), name(::std::move(name)),
generic_params(::std::move(generic_params)),
@@ -2771,7 +2771,7 @@ namespace Rust {
Trait(Trait&& other) = default;
Trait& operator=(Trait&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -2808,7 +2808,7 @@ namespace Rust {
private:
// doesn't really need to be protected as write access probably not needed
- location_t locus;
+ Location locus;
public:
// Returns whether impl has generic parameters.
@@ -2826,7 +2826,7 @@ namespace Rust {
return !inner_attrs.empty();
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -2835,7 +2835,7 @@ namespace Rust {
Impl(::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
::std::unique_ptr<Type> trait_type, WhereClause where_clause, Visibility vis,
::std::vector<Attribute> inner_attrs, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
VisItem(::std::move(vis), ::std::move(outer_attrs)),
generic_params(::std::move(generic_params)), trait_type(::std::move(trait_type)),
where_clause(::std::move(where_clause)), inner_attrs(::std::move(inner_attrs)),
@@ -2898,7 +2898,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
::std::unique_ptr<Type> trait_type, WhereClause where_clause, Visibility vis,
::std::vector<Attribute> inner_attrs, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
Impl(::std::move(generic_params), ::std::move(trait_type), ::std::move(where_clause),
::std::move(vis), ::std::move(inner_attrs), ::std::move(outer_attrs), locus),
impl_items(::std::move(impl_items)) {}
@@ -2970,7 +2970,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
::std::unique_ptr<Type> trait_type, WhereClause where_clause, Visibility vis,
::std::vector<Attribute> inner_attrs, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
Impl(::std::move(generic_params), ::std::move(trait_type), ::std::move(where_clause),
::std::move(vis), ::std::move(inner_attrs), ::std::move(outer_attrs), locus),
has_unsafe(is_unsafe), has_exclam(has_exclam), trait_path(::std::move(trait_path)),
@@ -3035,7 +3035,7 @@ namespace Rust {
Identifier item_name;
- location_t locus;
+ Location locus;
public:
virtual ~ExternalItem() {}
@@ -3057,7 +3057,7 @@ namespace Rust {
virtual ::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -3065,7 +3065,7 @@ namespace Rust {
protected:
ExternalItem(Identifier item_name, Visibility vis, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
outer_attrs(::std::move(outer_attrs)),
visibility(::std::move(vis)), item_name(::std::move(item_name)), locus(locus) {}
@@ -3106,7 +3106,7 @@ namespace Rust {
public:
ExternalStaticItem(Identifier item_name, ::std::unique_ptr<Type> item_type, bool is_mut,
- Visibility vis, ::std::vector<Attribute> outer_attrs, location_t locus) :
+ Visibility vis, ::std::vector<Attribute> outer_attrs, Location locus) :
ExternalItem(::std::move(item_name), ::std::move(vis), ::std::move(outer_attrs), locus),
has_mut(is_mut), item_type(::std::move(item_type)) {}
@@ -3230,7 +3230,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<GenericParam> > generic_params,
::std::unique_ptr<Type> return_type, WhereClause where_clause,
::std::vector<NamedFunctionParam> function_params, bool has_variadics, Visibility vis,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
ExternalItem(::std::move(item_name), ::std::move(vis), ::std::move(outer_attrs), locus),
generic_params(::std::move(generic_params)), return_type(::std::move(return_type)),
where_clause(::std::move(where_clause)), function_params(::std::move(function_params)),
@@ -3297,7 +3297,7 @@ namespace Rust {
// bool has_extern_items;
::std::vector< ::std::unique_ptr<ExternalItem> > extern_items;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -3320,7 +3320,7 @@ namespace Rust {
ExternBlock(::std::string abi,
::std::vector< ::std::unique_ptr<ExternalItem> > extern_items, Visibility vis,
::std::vector<Attribute> inner_attrs, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
VisItem(::std::move(vis), ::std::move(outer_attrs)),
abi(::std::move(abi)), inner_attrs(::std::move(inner_attrs)),
extern_items(::std::move(extern_items)), locus(locus) {}
@@ -3357,7 +3357,7 @@ namespace Rust {
ExternBlock(ExternBlock&& other) = default;
ExternBlock& operator=(ExternBlock&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -3382,4 +3382,4 @@ namespace Rust {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index 4c8237e..4b8e4d6 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -282,14 +282,14 @@ namespace Rust {
// MacroRules rules;
::std::vector<MacroRule> rules; // inlined form
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
MacroRulesDefinition(Identifier rule_name, DelimType delim_type,
::std::vector<MacroRule> rules, ::std::vector<Attribute> outer_attrs,
- location_t locus) :
+ Location locus) :
MacroItem(::std::move(outer_attrs)),
rule_name(::std::move(rule_name)), delim_type(delim_type), rules(::std::move(rules)),
locus(locus) {}
@@ -311,21 +311,21 @@ namespace Rust {
SimplePath path;
DelimTokenTree token_tree;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
MacroInvocation(SimplePath path, DelimTokenTree token_tree,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
ExprWithoutBlock(::std::move(outer_attrs)),
path(::std::move(path)), token_tree(::std::move(token_tree)), locus(locus) {}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -585,4 +585,4 @@ namespace Rust {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index cddd062..5fe7fd0 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -53,7 +53,7 @@ namespace Rust {
// Type type;
::std::unique_ptr<Type> type;
- location_t locus;
+ Location locus;
public:
// Returns whether binding is in an error state.
@@ -68,7 +68,7 @@ namespace Rust {
// Pointer type for type in constructor to enable polymorphism
GenericArgsBinding(Identifier ident, ::std::unique_ptr<Type> type_ptr,
- location_t locus = UNKNOWN_LOCATION) :
+ Location locus = Location()) :
identifier(::std::move(ident)),
type(::std::move(type_ptr)), locus(locus) {}
@@ -101,7 +101,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<Type> > type_args;
::std::vector<GenericArgsBinding> binding_args;
- location_t locus;
+ Location locus;
public:
// Returns true if there are any generic arguments
@@ -111,7 +111,7 @@ namespace Rust {
GenericArgs(::std::vector<Lifetime> lifetime_args,
::std::vector< ::std::unique_ptr<Type> > type_args,
- ::std::vector<GenericArgsBinding> binding_args, location_t locus = UNKNOWN_LOCATION) :
+ ::std::vector<GenericArgsBinding> binding_args, Location locus = Location()) :
lifetime_args(::std::move(lifetime_args)),
type_args(::std::move(type_args)), binding_args(::std::move(binding_args)),
locus(locus) {}
@@ -167,7 +167,7 @@ namespace Rust {
// bool has_generic_args;
GenericArgs generic_args;
- location_t locus;
+ Location locus;
// TODO: does this require visitor? pretty sure not polymorphic
@@ -178,13 +178,13 @@ namespace Rust {
}
// Constructor for segment (from IdentSegment and GenericArgs)
- PathExprSegment(PathIdentSegment segment_name, location_t locus = UNKNOWN_LOCATION,
+ PathExprSegment(PathIdentSegment segment_name, Location locus = Location(),
GenericArgs generic_args = GenericArgs::create_empty()) :
segment_name(::std::move(segment_name)),
generic_args(::std::move(generic_args)), locus(locus) {}
// Constructor for segment with generic arguments (from segment name and all args)
- PathExprSegment(::std::string segment_name, location_t locus,
+ PathExprSegment(::std::string segment_name, Location locus,
::std::vector<Lifetime> lifetime_args = ::std::vector<Lifetime>(),
::std::vector< ::std::unique_ptr<Type> > type_args
= ::std::vector< ::std::unique_ptr<Type> >(),
@@ -206,7 +206,7 @@ namespace Rust {
::std::string as_string() const;
- inline location_t get_locus() const {
+ inline Location get_locus() const {
return locus;
}
};
@@ -243,14 +243,14 @@ namespace Rust {
, public PathExpr {
bool has_opening_scope_resolution;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
// Constructor
PathInExpression(::std::vector<PathExprSegment> path_segments,
- location_t locus = UNKNOWN_LOCATION, bool has_opening_scope_resolution = false,
+ Location locus = Location(), bool has_opening_scope_resolution = false,
::std::vector<Attribute> outer_attrs = ::std::vector<Attribute>()) :
PathPattern(::std::move(path_segments)),
PathExpr(::std::move(outer_attrs)),
@@ -276,11 +276,11 @@ namespace Rust {
return convert_to_simple_path(has_opening_scope_resolution);
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -307,7 +307,7 @@ namespace Rust {
* so could disallow that in constructor, which won't give that much size overhead. */
PathIdentSegment ident_segment;
- location_t locus;
+ Location locus;
protected:
// This is protected because it is only really used by derived classes, not the base.
@@ -327,12 +327,12 @@ namespace Rust {
}
TypePathSegment(PathIdentSegment ident_segment, bool has_separating_scope_resolution,
- location_t locus) :
+ Location locus) :
ident_segment(::std::move(ident_segment)),
locus(locus), has_separating_scope_resolution(has_separating_scope_resolution) {}
TypePathSegment(
- ::std::string segment_name, bool has_separating_scope_resolution, location_t locus) :
+ ::std::string segment_name, bool has_separating_scope_resolution, Location locus) :
ident_segment(PathIdentSegment(::std::move(segment_name))),
locus(locus), has_separating_scope_resolution(has_separating_scope_resolution) {}
@@ -351,7 +351,7 @@ namespace Rust {
return true;
}
- inline bool get_locus() const {
+ inline Location get_locus() const {
return locus;
}
@@ -374,7 +374,7 @@ namespace Rust {
// Constructor with PathIdentSegment and GenericArgs
TypePathSegmentGeneric(PathIdentSegment ident_segment,
- bool has_separating_scope_resolution, GenericArgs generic_args, location_t locus) :
+ bool has_separating_scope_resolution, GenericArgs generic_args, Location locus) :
TypePathSegment(::std::move(ident_segment), has_separating_scope_resolution, locus),
generic_args(::std::move(generic_args)) {}
@@ -382,7 +382,7 @@ namespace Rust {
TypePathSegmentGeneric(::std::string segment_name, bool has_separating_scope_resolution,
::std::vector<Lifetime> lifetime_args,
::std::vector< ::std::unique_ptr<Type> > type_args,
- ::std::vector<GenericArgsBinding> binding_args, location_t locus) :
+ ::std::vector<GenericArgsBinding> binding_args, Location locus) :
TypePathSegment(::std::move(segment_name), has_separating_scope_resolution, locus),
generic_args(GenericArgs(
::std::move(lifetime_args), ::std::move(type_args), ::std::move(binding_args))) {}
@@ -497,13 +497,13 @@ namespace Rust {
// Constructor with PathIdentSegment and TypePathFn
TypePathSegmentFunction(PathIdentSegment ident_segment,
bool has_separating_scope_resolution, TypePathFunction function_path,
- location_t locus) :
+ Location locus) :
TypePathSegment(::std::move(ident_segment), has_separating_scope_resolution, locus),
function_path(::std::move(function_path)) {}
// Constructor with segment name and TypePathFn
TypePathSegmentFunction(::std::string segment_name, bool has_separating_scope_resolution,
- TypePathFunction function_path, location_t locus) :
+ TypePathFunction function_path, Location locus) :
TypePathSegment(::std::move(segment_name), has_separating_scope_resolution, locus),
function_path(::std::move(function_path)) {}
@@ -527,7 +527,7 @@ namespace Rust {
bool has_opening_scope_resolution;
::std::vector< ::std::unique_ptr<TypePathSegment> > segments;
- location_t locus;
+ Location locus;
protected:
// Use covariance to implement clone function as returning this object rather than base
@@ -554,12 +554,16 @@ namespace Rust {
// Creates an error state TypePath.
static TypePath create_error() {
- return TypePath(::std::vector< ::std::unique_ptr<TypePathSegment> >());
+ return TypePath(
+ ::std::vector< ::std::unique_ptr<TypePathSegment> >(),
+ Linemap::unknown_location(),
+ false);
}
// Constructor
TypePath(::std::vector< ::std::unique_ptr<TypePathSegment> > segments,
- location_t locus = UNKNOWN_LOCATION, bool has_opening_scope_resolution = false) :
+ Location locus,
+ bool has_opening_scope_resolution = false) :
has_opening_scope_resolution(has_opening_scope_resolution),
segments(::std::move(segments)), locus(locus) {}
@@ -602,7 +606,7 @@ namespace Rust {
// Creates a trait bound with a clone of this type path as its only element.
virtual TraitBound* to_trait_bound(bool in_parens) const OVERRIDE;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -617,12 +621,12 @@ namespace Rust {
// bool has_as_clause;
TypePath trait_path;
- location_t locus;
+ Location locus;
public:
// Constructor
QualifiedPathType(::std::unique_ptr<Type> invoke_on_type,
- location_t locus = UNKNOWN_LOCATION, TypePath trait_path = TypePath::create_error()) :
+ Location locus = Location(), TypePath trait_path = TypePath::create_error()) :
type_to_invoke_on(::std::move(invoke_on_type)),
trait_path(::std::move(trait_path)), locus(locus) {}
@@ -663,7 +667,7 @@ namespace Rust {
::std::string as_string() const;
- inline location_t get_locus() const {
+ inline Location get_locus() const {
return locus;
}
};
@@ -675,13 +679,13 @@ namespace Rust {
, public PathExpr {
QualifiedPathType path_type;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
QualifiedPathInExpression(QualifiedPathType qual_path_type,
- ::std::vector<PathExprSegment> path_segments, location_t locus = UNKNOWN_LOCATION,
+ ::std::vector<PathExprSegment> path_segments, Location locus = Location(),
::std::vector<Attribute> outer_attrs = ::std::vector<Attribute>()) :
PathPattern(::std::move(path_segments)),
PathExpr(::std::move(outer_attrs)), path_type(::std::move(qual_path_type)),
@@ -702,11 +706,11 @@ namespace Rust {
QualifiedPathType::create_error(), ::std::vector<PathExprSegment>());
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
- location_t get_locus_slow() const OVERRIDE {
+ Location get_locus_slow() const OVERRIDE {
return get_locus();
}
@@ -730,7 +734,7 @@ namespace Rust {
// ::std::vector<TypePathSegment> segments;
::std::vector< ::std::unique_ptr<TypePathSegment> > segments;
- location_t locus;
+ Location locus;
protected:
// Use covariance to implement clone function as returning this object rather than base
@@ -746,7 +750,7 @@ namespace Rust {
public:
QualifiedPathInType(QualifiedPathType qual_path_type,
::std::vector< ::std::unique_ptr<TypePathSegment> > path_segments,
- location_t locus = UNKNOWN_LOCATION) :
+ Location locus = Location()) :
path_type(::std::move(qual_path_type)),
segments(::std::move(path_segments)), locus(locus) {}
@@ -800,4 +804,4 @@ namespace Rust {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h
index f0cabee..5df0528 100644
--- a/gcc/rust/ast/rust-pattern.h
+++ b/gcc/rust/ast/rust-pattern.h
@@ -15,21 +15,21 @@ namespace Rust {
bool has_minus;
// Actually, this might be a good place to use a template.
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
// Constructor for a literal pattern
- LiteralPattern(Literal lit, location_t locus, bool has_minus = false) :
+ LiteralPattern(Literal lit, Location locus, bool has_minus = false) :
lit(::std::move(lit)), has_minus(has_minus), locus(locus) {}
LiteralPattern(
- ::std::string val, Literal::LitType type, location_t locus, bool has_minus = false) :
+ ::std::string val, Literal::LitType type, Location locus, bool has_minus = false) :
lit(Literal(::std::move(val), type)),
has_minus(has_minus), locus(locus) {}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -52,7 +52,7 @@ namespace Rust {
// Pattern* to_bind;
::std::unique_ptr<Pattern> to_bind;
- location_t locus;
+ Location locus;
public:
/*~IdentifierPattern() {
@@ -67,7 +67,7 @@ namespace Rust {
}
// Constructor
- IdentifierPattern(Identifier ident, location_t locus, bool is_ref = false,
+ IdentifierPattern(Identifier ident, Location locus, bool is_ref = false,
bool is_mut = false, ::std::unique_ptr<Pattern> to_bind = NULL) :
variable_ident(::std::move(ident)),
is_ref(is_ref), is_mut(is_mut), to_bind(::std::move(to_bind)), locus(locus) {}
@@ -102,7 +102,7 @@ namespace Rust {
IdentifierPattern(IdentifierPattern&& other) = default;
IdentifierPattern& operator=(IdentifierPattern&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -117,16 +117,16 @@ namespace Rust {
// AST node for using the '_' wildcard "match any value" pattern
class WildcardPattern : public Pattern {
- location_t locus;
+ Location locus;
public:
::std::string as_string() const {
return ::std::string(1, '_');
}
- WildcardPattern(location_t locus) : locus(locus) {}
+ WildcardPattern(Location locus) : locus(locus) {}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -174,16 +174,16 @@ namespace Rust {
// Minus prefixed to literal (if integer or floating-point)
bool has_minus;
- location_t locus;
+ Location locus;
public:
// Constructor
- RangePatternBoundLiteral(Literal literal, location_t locus, bool has_minus = false) :
+ RangePatternBoundLiteral(Literal literal, Location locus, bool has_minus = false) :
literal(literal), has_minus(has_minus), locus(locus) {}
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -210,7 +210,7 @@ namespace Rust {
return path.as_string();
}
- location_t get_locus() const {
+ Location get_locus() const {
return path.get_locus();
}
@@ -237,7 +237,7 @@ namespace Rust {
return path.as_string();
}
- location_t get_locus() const {
+ Location get_locus() const {
return path.get_locus();
}
@@ -261,14 +261,14 @@ namespace Rust {
// location only stored to avoid a dereference - lower pattern should give correct
// location so maybe change in future
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
// Constructor
RangePattern(::std::unique_ptr<RangePatternBound> lower,
- ::std::unique_ptr<RangePatternBound> upper, location_t locus,
+ ::std::unique_ptr<RangePatternBound> upper, Location locus,
bool has_ellipsis_syntax = false) :
lower(::std::move(lower)),
upper(::std::move(upper)), has_ellipsis_syntax(has_ellipsis_syntax), locus(locus) {}
@@ -295,7 +295,7 @@ namespace Rust {
RangePattern(RangePattern&& other) = default;
RangePattern& operator=(RangePattern&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -315,7 +315,7 @@ namespace Rust {
// Pattern* pattern;
::std::unique_ptr<Pattern> pattern;
- location_t locus;
+ Location locus;
public:
/*~ReferencePattern() {
@@ -325,7 +325,7 @@ namespace Rust {
::std::string as_string() const;
ReferencePattern(::std::unique_ptr<Pattern> pattern, bool is_mut_reference,
- bool ref_has_two_amps, location_t locus) :
+ bool ref_has_two_amps, Location locus) :
has_two_amps(ref_has_two_amps),
is_mut(is_mut_reference), pattern(::std::move(pattern)), locus(locus) {}
@@ -395,7 +395,7 @@ namespace Rust {
} ident;
} pattern;*/
- location_t locus;
+ Location locus;
public:
virtual ~StructPatternField() {}
@@ -407,14 +407,14 @@ namespace Rust {
virtual ::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
virtual void accept_vis(ASTVisitor& vis) = 0;
protected:
- StructPatternField(::std::vector<Attribute> outer_attribs, location_t locus) :
+ StructPatternField(::std::vector<Attribute> outer_attribs, Location locus) :
outer_attrs(::std::move(outer_attribs)), locus(locus) {}
// Clone function implementation as pure virtual method
@@ -433,7 +433,7 @@ namespace Rust {
}*/
StructPatternFieldTuplePat(TupleIndex index, ::std::unique_ptr<Pattern> tuple_pattern,
- ::std::vector<Attribute> outer_attribs, location_t locus) :
+ ::std::vector<Attribute> outer_attribs, Location locus) :
StructPatternField(::std::move(outer_attribs), locus),
index(index), tuple_pattern(::std::move(tuple_pattern)) {}
@@ -481,7 +481,7 @@ namespace Rust {
}*/
StructPatternFieldIdentPat(Identifier ident, ::std::unique_ptr<Pattern> ident_pattern,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
StructPatternField(::std::move(outer_attrs), locus),
ident(::std::move(ident)), ident_pattern(::std::move(ident_pattern)) {}
@@ -526,7 +526,7 @@ namespace Rust {
public:
StructPatternFieldIdent(Identifier ident, bool is_ref, bool is_mut,
- ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::vector<Attribute> outer_attrs, Location locus) :
StructPatternField(::std::move(outer_attrs), locus),
has_ref(is_ref), has_mut(is_mut), ident(::std::move(ident)) {}
@@ -641,7 +641,7 @@ namespace Rust {
return !elems.is_empty();
}
- location_t get_locus() const {
+ Location get_locus() const {
return path.get_locus();
}
@@ -819,7 +819,7 @@ namespace Rust {
TupleStructPattern(TupleStructPattern&& other) = default;
TupleStructPattern& operator=(TupleStructPattern&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return path.get_locus();
}
@@ -1002,7 +1002,7 @@ namespace Rust {
// TuplePatternItems items;
::std::unique_ptr<TuplePatternItems> items;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
@@ -1012,7 +1012,7 @@ namespace Rust {
return items != NULL;
}
- TuplePattern(::std::unique_ptr<TuplePatternItems> items, location_t locus) :
+ TuplePattern(::std::unique_ptr<TuplePatternItems> items, Location locus) :
items(::std::move(items)), locus(locus) {}
// Copy constructor requires clone
@@ -1029,7 +1029,7 @@ namespace Rust {
return *this;
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -1047,14 +1047,14 @@ namespace Rust {
// Pattern pattern_in_parens;
::std::unique_ptr<Pattern> pattern_in_parens;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const {
return "(" + pattern_in_parens->as_string() + ")";
}
- GroupedPattern(::std::unique_ptr<Pattern> pattern_in_parens, location_t locus) :
+ GroupedPattern(::std::unique_ptr<Pattern> pattern_in_parens, Location locus) :
pattern_in_parens(::std::move(pattern_in_parens)), locus(locus) {}
// Copy constructor uses clone
@@ -1075,7 +1075,7 @@ namespace Rust {
GroupedPattern(GroupedPattern&& other) = default;
GroupedPattern& operator=(GroupedPattern&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -1093,12 +1093,12 @@ namespace Rust {
//::std::vector<Pattern> items;
::std::vector< ::std::unique_ptr<Pattern> > items;
- location_t locus;
+ Location locus;
public:
::std::string as_string() const;
- SlicePattern(::std::vector< ::std::unique_ptr<Pattern> > items, location_t locus) :
+ SlicePattern(::std::vector< ::std::unique_ptr<Pattern> > items, Location locus) :
items(::std::move(items)), locus(locus) {}
// Copy constructor with vector clone
@@ -1128,7 +1128,7 @@ namespace Rust {
SlicePattern(SlicePattern&& other) = default;
SlicePattern& operator=(SlicePattern&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -1160,4 +1160,4 @@ namespace Rust {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/gcc/rust/ast/rust-stmt.h b/gcc/rust/ast/rust-stmt.h
index ece0801..767b620 100644
--- a/gcc/rust/ast/rust-stmt.h
+++ b/gcc/rust/ast/rust-stmt.h
@@ -9,16 +9,16 @@ namespace Rust {
namespace AST {
// Just a semi-colon, which apparently is a statement.
class EmptyStmt : public Stmt {
- location_t locus;
+ Location locus;
public:
::std::string as_string() const {
return ::std::string(1, ';');
}
- EmptyStmt(location_t locus) : locus(locus) {}
+ EmptyStmt(Location locus) : locus(locus) {}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -59,7 +59,7 @@ namespace Rust {
// Expr* init_expr;
::std::unique_ptr<Expr> init_expr;
- location_t locus;
+ Location locus;
public:
// Returns whether let statement has outer attributes.
@@ -86,7 +86,7 @@ namespace Rust {
::std::string as_string() const;
LetStmt(::std::unique_ptr<Pattern> variables_pattern, ::std::unique_ptr<Expr> init_expr,
- ::std::unique_ptr<Type> type, ::std::vector<Attribute> outer_attrs, location_t locus) :
+ ::std::unique_ptr<Type> type, ::std::vector<Attribute> outer_attrs, Location locus) :
outer_attrs(::std::move(outer_attrs)),
variables_pattern(::std::move(variables_pattern)), type(::std::move(type)),
init_expr(::std::move(init_expr)), locus(locus) {}
@@ -115,7 +115,7 @@ namespace Rust {
LetStmt(LetStmt&& other) = default;
LetStmt& operator=(LetStmt&& other) = default;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -132,15 +132,15 @@ namespace Rust {
class ExprStmt : public Stmt {
// TODO: add any useful virtual functions
- location_t locus;
+ Location locus;
public:
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
protected:
- ExprStmt(location_t locus) : locus(locus) {}
+ ExprStmt(Location locus) : locus(locus) {}
};
/* Statement containing an expression without a block (or, due to technical difficulties, can
@@ -161,7 +161,7 @@ namespace Rust {
// ExprStmtWithoutBlock(::std::unique_ptr<ExprWithoutBlock> expr) :
// expr(::std::move(expr)) {}
- ExprStmtWithoutBlock(::std::unique_ptr<Expr> expr, location_t locus) :
+ ExprStmtWithoutBlock(::std::unique_ptr<Expr> expr, Location locus) :
ExprStmt(locus), expr(::std::move(expr)) {}
// Copy constructor with clone
@@ -203,7 +203,7 @@ namespace Rust {
::std::string as_string() const;
- ExprStmtWithBlock(::std::unique_ptr<ExprWithBlock> expr, location_t locus) :
+ ExprStmtWithBlock(::std::unique_ptr<ExprWithBlock> expr, Location locus) :
ExprStmt(locus), expr(::std::move(expr)) {}
// Copy constructor with clone
@@ -242,4 +242,4 @@ namespace Rust {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h
index 4ca408d..d6bd2f4 100644
--- a/gcc/rust/ast/rust-type.h
+++ b/gcc/rust/ast/rust-type.h
@@ -21,7 +21,7 @@ namespace Rust {
TypePath type_path;
- location_t locus;
+ Location locus;
public:
// Returns whether trait bound has "for" lifetimes
@@ -29,7 +29,7 @@ namespace Rust {
return !for_lifetimes.empty();
}
- TraitBound(TypePath type_path, location_t locus, bool in_parens = false,
+ TraitBound(TypePath type_path, Location locus, bool in_parens = false,
bool opening_question_mark = false,
::std::vector<LifetimeParam> for_lifetimes = ::std::vector<LifetimeParam>()) :
in_parens(in_parens),
@@ -38,7 +38,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -59,7 +59,7 @@ namespace Rust {
// TypeParamBounds type_param_bounds;
::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds; // inlined form
- location_t locus;
+ Location locus;
protected:
// Use covariance to implement clone function as returning this object rather than base
@@ -69,7 +69,7 @@ namespace Rust {
public:
ImplTraitType(::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds,
- location_t locus) :
+ Location locus) :
type_param_bounds(::std::move(type_param_bounds)),
locus(locus) {}
@@ -102,7 +102,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -115,7 +115,7 @@ namespace Rust {
// TypeParamBounds type_param_bounds;
::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds; // inlined form
- location_t locus;
+ Location locus;
protected:
// Use covariance to implement clone function as returning this object rather than base
@@ -125,7 +125,7 @@ namespace Rust {
public:
TraitObjectType(::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds,
- location_t locus, bool is_dyn_dispatch = false) :
+ Location locus, bool is_dyn_dispatch = false) :
has_dyn(is_dyn_dispatch),
type_param_bounds(::std::move(type_param_bounds)), locus(locus) {}
@@ -160,7 +160,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -172,7 +172,7 @@ namespace Rust {
// Type type_in_parens;
::std::unique_ptr<Type> type_in_parens;
- location_t locus;
+ Location locus;
protected:
// Use covariance to implement clone function as returning this object rather than base
@@ -187,7 +187,7 @@ namespace Rust {
public:
// Constructor uses Type pointer for polymorphism
- ParenthesisedType(::std::unique_ptr<Type> type_inside_parens, location_t locus) :
+ ParenthesisedType(::std::unique_ptr<Type> type_inside_parens, Location locus) :
type_in_parens(::std::move(type_inside_parens)), locus(locus) {}
// Copy constructor uses custom deep copy method for type to preserve polymorphism
@@ -219,7 +219,7 @@ namespace Rust {
return type_in_parens->to_trait_bound(true);
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -230,7 +230,7 @@ namespace Rust {
class ImplTraitTypeOneBound : public TypeNoBounds {
TraitBound trait_bound;
- location_t locus;
+ Location locus;
protected:
// Use covariance to implement clone function as returning this object rather than base
@@ -244,12 +244,12 @@ namespace Rust {
}
public:
- ImplTraitTypeOneBound(TraitBound trait_bound, location_t locus) :
+ ImplTraitTypeOneBound(TraitBound trait_bound, Location locus) :
trait_bound(::std::move(trait_bound)), locus(locus) {}
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -262,7 +262,7 @@ namespace Rust {
bool has_dyn;
TraitBound trait_bound;
- location_t locus;
+ Location locus;
protected:
// Use covariance to implement clone function as returning this object rather than base
@@ -277,7 +277,7 @@ namespace Rust {
public:
TraitObjectTypeOneBound(
- TraitBound trait_bound, location_t locus, bool is_dyn_dispatch = false) :
+ TraitBound trait_bound, Location locus, bool is_dyn_dispatch = false) :
has_dyn(is_dyn_dispatch),
trait_bound(::std::move(trait_bound)), locus(locus) {}
@@ -290,7 +290,7 @@ namespace Rust {
return new AST::TraitBound(trait_bound);
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -304,7 +304,7 @@ namespace Rust {
//::std::vector<Type> elems;
::std::vector< ::std::unique_ptr<Type> > elems;
- location_t locus;
+ Location locus;
public:
// Returns whether the tuple type is the unit type, i.e. has no elements.
@@ -312,7 +312,7 @@ namespace Rust {
return elems.empty();
}
- TupleType(::std::vector< ::std::unique_ptr<Type> > elems, location_t locus) :
+ TupleType(::std::vector< ::std::unique_ptr<Type> > elems, Location locus) :
elems(::std::move(elems)), locus(locus) {}
// copy constructor with vector clone
@@ -344,7 +344,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -365,7 +365,7 @@ namespace Rust {
/* A type with no values, representing the result of computations that never complete.
* Expressions of NeverType can be coerced into any other types. Represented as "!". */
class NeverType : public TypeNoBounds {
- location_t locus;
+ Location locus;
protected:
// Use covariance to implement clone function as returning this object rather than base
@@ -379,13 +379,13 @@ namespace Rust {
}
public:
- NeverType(location_t locus) : locus(locus) {}
+ NeverType(Location locus) : locus(locus) {}
::std::string as_string() const {
return "! (never type)";
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -403,7 +403,7 @@ namespace Rust {
// TypeNoBounds type;
::std::unique_ptr<TypeNoBounds> type;
- location_t locus;
+ Location locus;
public:
// Returns whether the pointer is mutable or constant.
@@ -413,7 +413,7 @@ namespace Rust {
// Constructor requires pointer for polymorphism reasons
RawPointerType(PointerType pointer_type, ::std::unique_ptr<TypeNoBounds> type_no_bounds,
- location_t locus) :
+ Location locus) :
pointer_type(pointer_type),
type(::std::move(type_no_bounds)), locus(locus) {}
@@ -438,7 +438,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -466,7 +466,7 @@ namespace Rust {
// TypeNoBounds type;
::std::unique_ptr<TypeNoBounds> type;
- location_t locus;
+ Location locus;
public:
// Returns whether the reference is mutable or immutable.
@@ -481,7 +481,7 @@ namespace Rust {
// Constructor
ReferenceType(bool is_mut, ::std::unique_ptr<TypeNoBounds> type_no_bounds,
- location_t locus, Lifetime lifetime = Lifetime::error()) :
+ Location locus, Lifetime lifetime = Lifetime::error()) :
lifetime(::std::move(lifetime)),
has_mut(is_mut), type(::std::move(type_no_bounds)), locus(locus) {}
@@ -508,7 +508,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -533,12 +533,12 @@ namespace Rust {
// Expr* size;
::std::unique_ptr<Expr> size;
- location_t locus;
+ Location locus;
public:
// Constructor requires pointers for polymorphism
ArrayType(
- ::std::unique_ptr<Type> type, ::std::unique_ptr<Expr> array_size, location_t locus) :
+ ::std::unique_ptr<Type> type, ::std::unique_ptr<Expr> array_size, Location locus) :
elem_type(::std::move(type)),
size(::std::move(array_size)), locus(locus) {}
@@ -563,7 +563,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -589,11 +589,11 @@ namespace Rust {
// Type elem_type;
::std::unique_ptr<Type> elem_type;
- location_t locus;
+ Location locus;
public:
// Constructor requires pointer for polymorphism
- SliceType(::std::unique_ptr<Type> type, location_t locus) :
+ SliceType(::std::unique_ptr<Type> type, Location locus) :
elem_type(::std::move(type)), locus(locus) {}
// Copy constructor requires deep copy of Type smart pointer
@@ -616,7 +616,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -636,7 +636,7 @@ namespace Rust {
// Type used in generic arguments to explicitly request type inference (wildcard pattern)
class InferredType : public TypeNoBounds {
- location_t locus;
+ Location locus;
// e.g. Vec<_> = whatever
protected:
@@ -651,11 +651,11 @@ namespace Rust {
}
public:
- InferredType(location_t locus) : locus(locus) {}
+ InferredType(Location locus) : locus(locus) {}
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -676,11 +676,11 @@ namespace Rust {
ParamKind param_kind;
Identifier name; // technically, can be an identifier or '_'
- location_t locus;
+ Location locus;
public:
MaybeNamedParam(Identifier name, ParamKind param_kind, ::std::unique_ptr<Type> param_type,
- location_t locus) :
+ Location locus) :
param_type(::std::move(param_type)),
param_kind(param_kind), name(::std::move(name)), locus(locus) {}
@@ -714,10 +714,10 @@ namespace Rust {
// Creates an error state param.
static MaybeNamedParam create_error() {
- return MaybeNamedParam("", UNNAMED, NULL, UNKNOWN_LOCATION);
+ return MaybeNamedParam("", UNNAMED, NULL, Location());
}
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
};
@@ -737,7 +737,7 @@ namespace Rust {
// BareFunctionReturnType return_type;
::std::unique_ptr<TypeNoBounds> return_type; // inlined version
- location_t locus;
+ Location locus;
public:
// Whether a return type is defined with the function.
@@ -752,7 +752,7 @@ namespace Rust {
BareFunctionType(::std::vector<LifetimeParam> lifetime_params,
FunctionQualifiers qualifiers, ::std::vector<MaybeNamedParam> named_params,
- bool is_variadic, ::std::unique_ptr<TypeNoBounds> type, location_t locus) :
+ bool is_variadic, ::std::unique_ptr<TypeNoBounds> type, Location locus) :
for_lifetimes(::std::move(lifetime_params)),
function_qualifiers(::std::move(qualifiers)), params(::std::move(named_params)),
is_variadic(is_variadic), return_type(::std::move(type)), locus(locus) {}
@@ -783,7 +783,7 @@ namespace Rust {
::std::string as_string() const;
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -825,4 +825,4 @@ namespace Rust {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index 5a7b0cb..f3979f1 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -1,6 +1,7 @@
#include "rust-lex.h"
-#include "diagnostic.h" // for error_at
+#include "rust-diagnostics.h" // for rust_error_at
+#include "rust-linemap.h"
#include "safe-ctype.h"
#include <sstream> // for ostringstream
@@ -25,7 +26,7 @@ namespace Rust {
str += static_cast<char>(0x80 | ((char32.value >> 0) & 0x3F));
} else {
fprintf(stderr, "Invalid unicode codepoint found: '%u' \n", char32.value);
- // error_at(get_current_location(), "Invalid unicode codepoint found: '%u'",
+ // rust_error_at(get_current_location(), "Invalid unicode codepoint found: '%u'",
// char32.value);
}
return str;
@@ -54,7 +55,7 @@ namespace Rust {
str += static_cast<char>(0x80 | ((value >> 6) & 0x3F));
str += static_cast<char>(0x80 | ((value >> 0) & 0x3F));
} else {
- error_at(get_current_location(), "Invalid unicode codepoint found: '%u'", value);
+ rust_error_at(get_current_location(), "Invalid unicode codepoint found: '%u'", value);
}*/
return str;
}
@@ -86,20 +87,18 @@ namespace Rust {
return ISSPACE(character);
}
- Lexer::Lexer(const char* filename, FILE* input) :
- input(input), current_line(1), current_column(1), line_map(0), input_source(input),
+ Lexer::Lexer(const char* filename, FILE* input, Linemap* linemap) :
+ input(input), current_line(1), current_column(1), line_map(linemap), input_source(input),
input_queue(input_source), token_source(this), token_queue(token_source) {
// inform line_table that file is being entered and is in line 1
- line_map
- = ::linemap_add(::line_table, ::LC_ENTER, /* sysp */ 0, filename, /* current_line */ 1);
+ line_map->start_file(filename, current_line);
}
Lexer::~Lexer() {
- ::linemap_add(::line_table, ::LC_LEAVE, /* sysp */ 0, /* filename */ NULL, /* to_line */ 0);
}
- location_t Lexer::get_current_location() {
- return ::linemap_position_for_column(::line_table, current_column);
+ Location Lexer::get_current_location() {
+ return line_map->get_location(current_column);
}
int Lexer::peek_input(int n) {
@@ -177,7 +176,7 @@ namespace Rust {
TokenPtr Lexer::build_token() {
// loop to go through multiple characters to build a single token
while (true) {
- location_t loc = get_current_location();
+ Location loc = get_current_location();
/*int */ current_char = peek_input();
skip_input();
@@ -187,7 +186,7 @@ namespace Rust {
}
// detect shebang
- if (loc == 1 && current_line == 1 && current_char == '#') {
+ if (current_line == 1 && current_char == '#') {
current_char = peek_input();
if (current_char == '!') {
@@ -210,7 +209,7 @@ namespace Rust {
current_line++;
current_column = 1;
// tell line_table that new line starts
- linemap_line_start(::line_table, current_line, max_column_hint);
+ line_map->start_line(current_line, max_column_hint);
continue;
}
}
@@ -609,7 +608,7 @@ namespace Rust {
parse_escape(length, byte_char, '\'');
if (byte_char > 127) {
- error_at(
+ rust_error_at(
get_current_location(), "byte char '%c' out of range", byte_char);
byte_char = 0;
}
@@ -619,7 +618,7 @@ namespace Rust {
length++;
if (current_char != '\'') {
- error_at(get_current_location(), "unclosed byte char");
+ rust_error_at(get_current_location(), "unclosed byte char");
}
// TODO: ensure skipping is needed here
@@ -634,7 +633,7 @@ namespace Rust {
current_char = peek_input();
if (current_char != '\'') {
- error_at(get_current_location(), "unclosed byte char");
+ rust_error_at(get_current_location(), "unclosed byte char");
}
// TODO: ensure skipping is needed here
@@ -642,7 +641,7 @@ namespace Rust {
current_char = peek_input();
length++; // go to next char
} else {
- error_at(get_current_location(), "no character inside '' for byte char");
+ rust_error_at(get_current_location(), "no character inside '' for byte char");
}
current_column += length;
@@ -667,7 +666,7 @@ namespace Rust {
parse_escape(length, output_char, '"');
if (output_char > 127) {
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"char '%c' in byte string out of range", output_char);
output_char = 0;
}
@@ -687,7 +686,7 @@ namespace Rust {
current_column += length;
if (current_char == '\n') {
- error_at(get_current_location(), "unended byte string literal");
+ rust_error_at(get_current_location(), "unended byte string literal");
} else if (current_char == '"') {
skip_input();
current_char = peek_input();
@@ -717,7 +716,7 @@ namespace Rust {
}
if (current_char != '"') {
- error_at(get_current_location(), "raw byte string has no opening '\"'");
+ rust_error_at(get_current_location(), "raw byte string has no opening '\"'");
}
skip_input();
@@ -790,12 +789,12 @@ namespace Rust {
// if just a single underscore, not an identifier
if (first_is_underscore && length == 1) {
- error_at(get_current_location(), "'_' is not a valid raw identifier");
+ rust_error_at(get_current_location(), "'_' is not a valid raw identifier");
}
if (str == "crate" || str == "extern" || str == "self" || str == "super"
|| str == "Self") {
- error_at(
+ rust_error_at(
get_current_location(), "'%s' is a forbidden raw identifier", str.c_str());
} else {
return Token::make_identifier(loc, str);
@@ -819,7 +818,7 @@ namespace Rust {
}
if (current_char != '"') {
- error_at(get_current_location(), "raw string has no opening '\"'");
+ rust_error_at(get_current_location(), "raw string has no opening '\"'");
}
skip_input();
@@ -960,7 +959,7 @@ namespace Rust {
parse_in_type_suffix(/*current_char, */ type_hint, length);
if (type_hint == CORETYPE_F32 || type_hint == CORETYPE_F64) {
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"invalid type suffix '%s' for integer (hex) literal",
get_type_hint_string(type_hint));
}
@@ -1012,7 +1011,7 @@ namespace Rust {
parse_in_type_suffix(/*current_char, */ type_hint, length);
if (type_hint == CORETYPE_F32 || type_hint == CORETYPE_F64) {
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"invalid type suffix '%s' for integer (octal) literal",
get_type_hint_string(type_hint));
}
@@ -1065,7 +1064,7 @@ namespace Rust {
parse_in_type_suffix(/*current_char, */ type_hint, length);
if (type_hint == CORETYPE_F32 || type_hint == CORETYPE_F64) {
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"invalid type suffix '%s' for integer (binary) literal",
get_type_hint_string(type_hint));
}
@@ -1106,7 +1105,7 @@ namespace Rust {
if (type_hint != CORETYPE_F32 && type_hint != CORETYPE_F64
&& type_hint != CORETYPE_UNKNOWN) {
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"invalid type suffix '%s' for float literal",
get_type_hint_string(type_hint));
}
@@ -1134,7 +1133,7 @@ namespace Rust {
if (type_hint != CORETYPE_F32 && type_hint != CORETYPE_F64
&& type_hint != CORETYPE_UNKNOWN) {
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"invalid type suffix '%s' for float literal",
get_type_hint_string(type_hint));
}
@@ -1149,7 +1148,7 @@ namespace Rust {
if (type_hint != CORETYPE_F32 && type_hint != CORETYPE_F64
&& type_hint != CORETYPE_UNKNOWN) {
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"invalid type suffix '%s' for float literal",
get_type_hint_string(type_hint));
}
@@ -1160,7 +1159,7 @@ namespace Rust {
parse_in_type_suffix(/*current_char, */ type_hint, length);
if (type_hint == CORETYPE_F32 || type_hint == CORETYPE_F64) {
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"invalid type suffix '%s' for integer (decimal) literal",
get_type_hint_string(type_hint));
}
@@ -1217,7 +1216,7 @@ namespace Rust {
current_column += length;
if (current_char32.value == '\n') {
- error_at(get_current_location(), "unended string literal");
+ rust_error_at(get_current_location(), "unended string literal");
} else if (current_char32.value == '"') {
skip_input();
@@ -1249,7 +1248,7 @@ namespace Rust {
// test_skip_codepoint_input();
if (test_peek_codepoint_input().value != '\'') {
- error_at(get_current_location(), "unended char literal");
+ rust_error_at(get_current_location(), "unended char literal");
} else {
test_skip_codepoint_input();
current_char = peek_input();
@@ -1302,13 +1301,13 @@ namespace Rust {
return Token::make_lifetime(loc, str);
} else {
- error_at(get_current_location(), "expected ' after character constant");
+ rust_error_at(get_current_location(), "expected ' after character constant");
}
}
}
// didn't match anything so error
- error_at(loc, "unexpected character '%x'", current_char);
+ rust_error_at(loc, "unexpected character '%x'", current_char);
current_column++;
}
}
@@ -1370,7 +1369,7 @@ namespace Rust {
} else if (suffix == "usize") {
type_hint = CORETYPE_USIZE;
} else {
- error_at(get_current_location(), "unknown number suffix '%s'", suffix.c_str());
+ rust_error_at(get_current_location(), "unknown number suffix '%s'", suffix.c_str());
return false;
}
@@ -1446,7 +1445,7 @@ namespace Rust {
length++;
if (!ISXDIGIT(current_char)) {
- error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
+ rust_error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
current_char);
}
hexNum[0] = current_char;
@@ -1457,7 +1456,7 @@ namespace Rust {
length++;
if (!ISXDIGIT(current_char)) {
- error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
+ rust_error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
current_char);
}
hexNum[1] = current_char;
@@ -1465,7 +1464,7 @@ namespace Rust {
long hexLong = ::std::strtol(hexNum, NULL, 16);
if (hexLong > 127)
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"ascii \\x escape '\\x%s' out of range - allows up to '\\x7F'", hexNum);
// gcc_assert(hexLong < 128); // as ascii
char hexChar = static_cast<char>(hexLong);
@@ -1550,13 +1549,13 @@ namespace Rust {
// ensure closing brace
if (need_close_brace && current_char != '}') {
// actually an error
- error_at(get_current_location(), "expected terminating '}' in unicode escape");
+ rust_error_at(get_current_location(), "expected terminating '}' in unicode escape");
return false;
}
// ensure 1-6 hex characters
if (num_str.length() > 6 || num_str.length() < 1) {
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"unicode escape should be between 1 and 6 hex characters; it is %lu",
num_str.length());
return false;
@@ -1566,7 +1565,7 @@ namespace Rust {
// as debug, check hex_num = test_val
if (hex_num > 255) {
- error_at(
+ rust_error_at(
get_current_location(), "non-ascii chars not implemented yet, defaulting to 0");
hex_num = 0;
}
@@ -1620,7 +1619,7 @@ namespace Rust {
return true;
}
default:
- error_at(get_current_location(), "unknown escape sequence '\\%c'", current_char);
+ rust_error_at(get_current_location(), "unknown escape sequence '\\%c'", current_char);
// returns false if no parsing could be done
return false;
break;
@@ -1651,7 +1650,7 @@ namespace Rust {
length++;
if (!ISXDIGIT(current_char)) {
- error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
+ rust_error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
current_char);
}
hexNum[0] = current_char;
@@ -1662,7 +1661,7 @@ namespace Rust {
length++;
if (!ISXDIGIT(current_char)) {
- error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
+ rust_error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
current_char);
}
hexNum[1] = current_char;
@@ -1670,7 +1669,7 @@ namespace Rust {
long hexLong = ::std::strtol(hexNum, NULL, 16);
if (hexLong > 127)
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"ascii \\x escape '\\x%s' out of range - allows up to '\\x7F'", hexNum);
// gcc_assert(hexLong < 128); // as ascii
char hexChar = static_cast<char>(hexLong);
@@ -1758,7 +1757,7 @@ namespace Rust {
length++;
} else {
// actually an error
- error_at(
+ rust_error_at(
get_current_location(), "expected terminating '}' in unicode escape");
return false;
}
@@ -1766,7 +1765,7 @@ namespace Rust {
// ensure 1-6 hex characters
if (num_str.length() > 6 || num_str.length() < 1) {
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"unicode escape should be between 1 and 6 hex characters; it is %lu",
num_str.length());
return false;
@@ -1828,7 +1827,7 @@ namespace Rust {
return true;
}
default:
- error_at(get_current_location(), "unknown escape sequence '\\%c'", current_char);
+ rust_error_at(get_current_location(), "unknown escape sequence '\\%c'", current_char);
// returns false if no parsing could be done
return false;
break;
@@ -1860,7 +1859,7 @@ namespace Rust {
length++;
if (!ISXDIGIT(current_char)) {
- error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
+ rust_error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
current_char);
}
hexNum[0] = current_char;
@@ -1871,7 +1870,7 @@ namespace Rust {
length++;
if (!ISXDIGIT(current_char)) {
- error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
+ rust_error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
current_char);
}
hexNum[1] = current_char;
@@ -1879,7 +1878,7 @@ namespace Rust {
long hexLong = ::std::strtol(hexNum, NULL, 16);
if (hexLong > 127)
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"ascii \\x escape '\\x%s' out of range - allows up to '\\x7F'", hexNum);
// gcc_assert(hexLong < 128); // as ascii
char hexChar = static_cast<char>(hexLong);
@@ -1903,7 +1902,7 @@ namespace Rust {
output_char = '\0';
break;
default:
- // error_at(get_current_location(), "unknown escape sequence '\\%c'", current_char);
+ // rust_error_at(get_current_location(), "unknown escape sequence '\\%c'", current_char);
// returns false if no parsing could be done
return false;
break;
@@ -1996,13 +1995,13 @@ namespace Rust {
// ensure closing brace
if (need_close_brace && current_char != '}') {
// actually an error
- error_at(get_current_location(), "expected terminating '}' in unicode escape");
+ rust_error_at(get_current_location(), "expected terminating '}' in unicode escape");
return false;
}
// ensure 1-6 hex characters
if (num_str.length() > 6 || num_str.length() < 1) {
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"unicode escape should be between 1 and 6 hex characters; it is %lu", num_str.length());
return false;
}
@@ -2035,7 +2034,7 @@ namespace Rust {
length++;
if (!ISXDIGIT(current_char)) {
- error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
+ rust_error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
current_char);
}
hexNum[0] = current_char;
@@ -2046,7 +2045,7 @@ namespace Rust {
length++;
if (!ISXDIGIT(current_char)) {
- error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
+ rust_error_at(get_current_location(), "invalid character '\\x%c' in \\x sequence",
current_char);
}
hexNum[1] = current_char;
@@ -2054,7 +2053,7 @@ namespace Rust {
long hexLong = ::std::strtol(hexNum, NULL, 16);
if (hexLong > 255)
- error_at(get_current_location(),
+ rust_error_at(get_current_location(),
"ascii \\x escape '\\x%s' out of range - allows up to '\\xFF'", hexNum);
// gcc_assert(hexLong < 128); // as ascii
char hexChar = static_cast<char>(hexLong);
@@ -2078,7 +2077,7 @@ namespace Rust {
output_char = '\0';
break;
default:
- // error_at(get_current_location(), "unknown escape sequence '\\%c'", current_char);
+ // rust_error_at(get_current_location(), "unknown escape sequence '\\%c'", current_char);
// returns false if no parsing could be done
return false;
break;
@@ -2149,7 +2148,7 @@ namespace Rust {
return output;*/
return 4;
} else {
- error_at(get_current_location(), "invalid UTF-8 (too long)");
+ rust_error_at(get_current_location(), "invalid UTF-8 (too long)");
return 0;
}
}
@@ -2203,7 +2202,7 @@ namespace Rust {
| ((input3 & 0x3F) << 6) | ((input4 & 0x3F) << 0);
return { output };
} else {
- error_at(get_current_location(), "invalid UTF-8 (too long)");
+ rust_error_at(get_current_location(), "invalid UTF-8 (too long)");
return { 0xFFFE };
}
}
@@ -2274,7 +2273,7 @@ namespace Rust {
return output;*/
return 4;
} else {
- error_at(get_current_location(), "invalid UTF-8 (too long)");
+ rust_error_at(get_current_location(), "invalid UTF-8 (too long)");
return 0;
}
}
@@ -2342,8 +2341,8 @@ namespace Rust {
| ((input3 & 0x3F) << 6) | ((input4 & 0x3F) << 0);
return output;
} else {
- error_at(get_current_location(), "invalid UTF-8 (too long)");
+ rust_error_at(get_current_location(), "invalid UTF-8 (too long)");
return 0xFFFE;
}*/
}
-} \ No newline at end of file
+}
diff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h
index b16cfeb..14b369c 100644
--- a/gcc/rust/lex/rust-lex.h
+++ b/gcc/rust/lex/rust-lex.h
@@ -1,14 +1,15 @@
#ifndef RUST_LEX_H
#define RUST_LEX_H
+#include "rust-linemap.h"
#include "rust-buffered-queue.h"
#include "rust-token.h"
namespace Rust {
class Lexer {
private:
- // Request new location_t for current column in line_table
- location_t get_current_location();
+ // Request new Location for current column in line_table
+ Location get_current_location();
// Skips the current input char.
void skip_input();
@@ -47,7 +48,7 @@ namespace Rust {
public:
// Construct lexer with input file and filename provided
- Lexer(const char* filename, FILE* input);
+ Lexer(const char* filename, FILE* input, Linemap* linemap);
~Lexer();
// Returns token n tokens ahead of current position.
@@ -63,6 +64,8 @@ namespace Rust {
// Replaces the current token with a specified token.
void replace_current_token(TokenPtr replacement);
+ Linemap* get_line_map() { return line_map; }
+
private:
// File for use as input.
FILE* input;
@@ -72,7 +75,7 @@ namespace Rust {
// Current column number.
int current_column;
// Line map.
- const struct line_map* line_map;
+ Linemap* line_map;
// Max column number that can be quickly allocated - higher may require allocating new linemap
static const int max_column_hint = 80;
@@ -122,4 +125,4 @@ namespace Rust {
};
}
-#endif \ No newline at end of file
+#endif
diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h
index bf65ed3..13f4a18 100644
--- a/gcc/rust/lex/rust-token.h
+++ b/gcc/rust/lex/rust-token.h
@@ -12,6 +12,7 @@
// replace with proper std::memory in c++11
#include <memory>
+#include "rust-linemap.h"
#include "rust-codepoint.h"
namespace Rust {
@@ -216,33 +217,33 @@ namespace Rust {
// Token kind.
TokenId token_id;
// Token location.
- location_t locus;
+ Location locus;
// Associated text (if any) of token.
::std::string* str;
// Type hint for token based on lexer data (e.g. type suffix). Does not exist for most tokens.
PrimitiveCoreType type_hint;
// Token constructor from token id and location. Has a null string.
- Token(TokenId token_id, location_t location) :
+ Token(TokenId token_id, Location location) :
token_id(token_id), locus(location), str(NULL), type_hint(CORETYPE_UNKNOWN) {}
// Token constructor from token id, location, and a string.
- Token(TokenId token_id, location_t location, const ::std::string& paramStr) :
+ Token(TokenId token_id, Location location, const ::std::string& paramStr) :
token_id(token_id), locus(location), str(new ::std::string(paramStr)),
type_hint(CORETYPE_UNKNOWN) {}
// Token constructor from token id, location, and a char.
- Token(TokenId token_id, location_t location, char paramChar) :
+ Token(TokenId token_id, Location location, char paramChar) :
token_id(token_id), locus(location), str(new ::std::string(1, paramChar)),
type_hint(CORETYPE_UNKNOWN) {}
// Token constructor from token id, location, and a "codepoint".
- Token(TokenId token_id, location_t location, Codepoint paramCodepoint) :
+ Token(TokenId token_id, Location location, Codepoint paramCodepoint) :
token_id(token_id), locus(location), str(new ::std::string(paramCodepoint.as_string())),
type_hint(CORETYPE_UNKNOWN) {}
// Token constructor from token id, location, a string, and type hint.
- Token(TokenId token_id, location_t location, const ::std::string& paramStr,
+ Token(TokenId token_id, Location location, const ::std::string& paramStr,
PrimitiveCoreType parType) :
token_id(token_id),
locus(location), str(new ::std::string(paramStr)), type_hint(parType) {}
@@ -259,59 +260,59 @@ namespace Rust {
}
// Makes and returns a new TokenPtr (with null string).
- static TokenPtr make(TokenId token_id, location_t locus) {
+ static TokenPtr make(TokenId token_id, Location locus) {
return TokenPtr(new Token(token_id, locus));
}
// Makes and returns a new TokenPtr of type IDENTIFIER.
- static TokenPtr make_identifier(location_t locus, const ::std::string& str) {
+ static TokenPtr make_identifier(Location locus, const ::std::string& str) {
return TokenPtr(new Token(IDENTIFIER, locus, str));
}
// Makes and returns a new TokenPtr of type INT_LITERAL.
- static TokenPtr make_int(location_t locus, const ::std::string& str) {
+ static TokenPtr make_int(Location locus, const ::std::string& str) {
return TokenPtr(new Token(INT_LITERAL, locus, str));
}
// Makes and returns a new TokenPtr of type INT_LITERAL.
static TokenPtr make_int(
- location_t locus, const ::std::string& str, PrimitiveCoreType type_hint) {
+ Location locus, const ::std::string& str, PrimitiveCoreType type_hint) {
return TokenPtr(new Token(INT_LITERAL, locus, str, type_hint));
}
// Makes and returns a new TokenPtr of type FLOAT_LITERAL.
- static TokenPtr make_float(location_t locus, const ::std::string& str) {
+ static TokenPtr make_float(Location locus, const ::std::string& str) {
return TokenPtr(new Token(FLOAT_LITERAL, locus, str));
}
// Makes and returns a new TokenPtr of type FLOAT_LITERAL.
static TokenPtr make_float(
- location_t locus, const ::std::string& str, PrimitiveCoreType type_hint) {
+ Location locus, const ::std::string& str, PrimitiveCoreType type_hint) {
return TokenPtr(new Token(FLOAT_LITERAL, locus, str, type_hint));
}
// Makes and returns a new TokenPtr of type STRING_LITERAL.
- static TokenPtr make_string(location_t locus, const ::std::string& str) {
+ static TokenPtr make_string(Location locus, const ::std::string& str) {
return TokenPtr(new Token(STRING_LITERAL, locus, str, CORETYPE_STR));
}
// Makes and returns a new TokenPtr of type CHAR_LITERAL (fix).
- static TokenPtr make_char(location_t locus, Codepoint char_lit) {
+ static TokenPtr make_char(Location locus, Codepoint char_lit) {
return TokenPtr(new Token(CHAR_LITERAL, locus, char_lit));
}
// Makes and returns a new TokenPtr of type BYTE_CHAR_LITERAL (fix).
- static TokenPtr make_byte_char(location_t locus, char byte_char) {
+ static TokenPtr make_byte_char(Location locus, char byte_char) {
return TokenPtr(new Token(BYTE_CHAR_LITERAL, locus, byte_char));
}
// Makes and returns a new TokenPtr of type BYTE_STRING_LITERAL (fix).
- static TokenPtr make_byte_string(location_t locus, const ::std::string& str) {
+ static TokenPtr make_byte_string(Location locus, const ::std::string& str) {
return TokenPtr(new Token(BYTE_STRING_LITERAL, locus, str));
}
// Makes and returns a new TokenPtr of type LIFETIME.
- static TokenPtr make_lifetime(location_t locus, const ::std::string& str) {
+ static TokenPtr make_lifetime(Location locus, const ::std::string& str) {
return TokenPtr(new Token(LIFETIME, locus, str));
}
@@ -321,7 +322,7 @@ namespace Rust {
}
// Gets location of the token.
- location_t get_locus() const {
+ Location get_locus() const {
return locus;
}
@@ -382,4 +383,4 @@ namespace Rust {
};
}
-#endif \ No newline at end of file
+#endif
diff --git a/gcc/rust/parse/rust-parse-includes.h b/gcc/rust/parse/rust-parse-includes.h
deleted file mode 100644
index ad7b920..0000000
--- a/gcc/rust/parse/rust-parse-includes.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef RUST_PARSE_INCLUDES_H
-#define RUST_PARSE_INCLUDES_H
-/* basically, this is just to stop gcc includes in rust-parse.cc from getting out of order due to
- * formatter, which I can not figure out how to modify to not do this. */
-// HACK: remove for final or near-final compiler where I don't have to use auto formatter anymore
-
-#include "config.h"
-#include "system.h"
-#include "coretypes.h"
-#include "target.h"
-#include "tree.h"
-#include "tree-iterator.h"
-#include "input.h"
-#include "diagnostic.h"
-#include "stringpool.h"
-#include "cgraph.h"
-#include "gimplify.h"
-#include "gimple-expr.h"
-#include "convert.h"
-#include "print-tree.h"
-#include "stor-layout.h"
-#include "fold-const.h"
-/* order: config, system, coretypes, target, tree, tree-iterator, input, diagnostic, stringpool,
- * cgraph, gimplify, gimple-expr, convert, print-tree, stor-layout, fold-const */
-// probably don't need all these
-
-#endif \ No newline at end of file
diff --git a/gcc/rust/parse/rust-parse.cc b/gcc/rust/parse/rust-parse.cc
index 1eac8a1..abd8831 100644
--- a/gcc/rust/parse/rust-parse.cc
+++ b/gcc/rust/parse/rust-parse.cc
@@ -1,7 +1,6 @@
#include "rust-parse.h"
-
-// instead of gcc includes specified here. Thanks clang-format.
-#include "rust-parse-includes.h"
+#include "rust-linemap.h"
+#include "rust-diagnostics.h"
#include <algorithm> // for std::find
@@ -98,28 +97,6 @@ namespace Rust {
LBP_LOWEST = 0
};
- // Checks if Tree has a string type (tree code pointer_type and tree variant char node).
- bool is_string_type(Tree type) {
- // assert node represents a type
- gcc_assert(TYPE_P(type.get_tree()));
-
- // ensure main variant of pointee is char_type_node (i.e. type is char*)
- return type.get_tree_code() == POINTER_TYPE
- && TYPE_MAIN_VARIANT(TREE_TYPE(type.get_tree())) == char_type_node;
- }
-
- // Checks if Tree has array type.
- bool is_array_type(Tree type) {
- gcc_assert(TYPE_P(type.get_tree()));
- return type.get_tree_code() == ARRAY_TYPE;
- }
-
- // Checks if Tree has record type.
- bool is_record_type(Tree type) {
- gcc_assert(TYPE_P(type.get_tree()));
- return type.get_tree_code() == RECORD_TYPE;
- }
-
// Returns whether the token can start a type (i.e. there is a valid type beginning with the
// token).
bool can_tok_start_type(TokenId id) {
@@ -182,7 +159,7 @@ namespace Rust {
/* shit. preferred HACK would be to replace this token in stream with '>', but may not
* be possible at this point. */
// FIXME: ensure locations aren't messed up
- TokenPtr right_angle = Token::make(RIGHT_ANGLE, tok->get_locus() + 1);
+ TokenPtr right_angle = Token::make(RIGHT_ANGLE, tok->get_locus());
lexer.replace_current_token(right_angle);
return true;
}
@@ -191,7 +168,7 @@ namespace Rust {
/* FIXME: is this even required? how many people wouldn't leave a space? - apparently
* rustc has this feature */
// FIXME: ensure locations aren't messed up
- TokenPtr equal = Token::make(EQUAL, tok->get_locus() + 1);
+ TokenPtr equal = Token::make(EQUAL, tok->get_locus());
lexer.replace_current_token(equal);
return true;
}
@@ -199,12 +176,12 @@ namespace Rust {
// another HACK - replace with greater or equal
// FIXME: again, is this really required? rustc has the feature, though
// FIXME: ensure locations aren't messed up
- TokenPtr greater_equal = Token::make(GREATER_OR_EQUAL, tok->get_locus() + 1);
+ TokenPtr greater_equal = Token::make(GREATER_OR_EQUAL, tok->get_locus());
lexer.replace_current_token(greater_equal);
return true;
}
default:
- error_at(tok->get_locus(), "expected '>' at end of generic argument - found '%s'",
+ rust_error_at(tok->get_locus(), "expected '>' at end of generic argument - found '%s'",
tok->get_token_description());
return false;
}
@@ -346,95 +323,12 @@ namespace Rust {
}
}
- TreeStmtList& Parser::get_current_stmt_list() {
- return stack_stmt_list.back();
- }
-
- // Parse statements until done (EOF) and append to current stmt list.
- void Parser::parse_statement_seq(bool (Parser::*done)()) {
- // Parse statements until done and append to the current stmt list
- /*while (!(this->*done)()) {
- // get stmt tree for parsed statement
- Tree stmt = parse_statement();
- // append each stmt tree to current stmt list
- get_current_stmt_list().append(stmt);
- }*/
- }
-
- // Parse "items" until done (EOF) and append to current something list. Seems to be method taken
- // rather than statements in rust.
- /*void Parser::parse_item_seq(bool (Parser::*done)()) {
- // Parse statements until done and append to the current stmt list
- // TODO: fix
- while (!(this->*done)()) {
- // get stmt tree for parsed statement
- Tree item = parse_item();
- // append each stmt tree to current stmt list
- get_current_stmt_list().append(stmt);
- }
- }*/
-
// Returns true when current token is EOF.
bool Parser::done_end_of_file() {
const_TokenPtr t = lexer.peek_token();
return (t->get_id() == END_OF_FILE);
}
- // Entry point - parse entire program (in file) from here.
- void Parser::parse_program() {
- // should be only able to parse decls at this point (scope)?
-
- // TODO: convert to a crate-based approach? parse_crate()?
- parse_crate();
-
- // TODO: structural changes - strongly-typed AST instead of Trees?
-
- // TODO: how much of this is fake main function vs actually required for any function?
- // Built type of main "int (int, char**)"
- tree main_fndecl_type_param[]
- = { integer_type_node, build_pointer_type(build_pointer_type(char_type_node)) };
- tree main_fndecl_type
- = build_function_type_array(integer_type_node, 2, main_fndecl_type_param);
- // Create function declaration "int main(int, char**)"
- main_fndecl = build_fn_decl("main", main_fndecl_type);
-
- // Enter top-level scope.
- enter_scope();
- // program -> statement*
- parse_statement_seq(&Parser::done_end_of_file);
- // Append "return 0;"
- tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, integer_type_node);
- // create decl_context of resdecl for main function (local variable of main function)
- DECL_CONTEXT(resdecl) = main_fndecl;
- DECL_RESULT(main_fndecl) = resdecl;
- tree set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(main_fndecl),
- build_int_cst_type(integer_type_node, 0));
- tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result);
-
- get_current_stmt_list().append(return_stmt);
-
- // Leave top-level scope, get its binding expression and its main block
- TreeSymbolMapping main_tree_scope = leave_scope();
- Tree main_block = main_tree_scope.block;
-
- // Finish/finalise main function
- BLOCK_SUPERCONTEXT(main_block.get_tree()) = main_fndecl;
- DECL_INITIAL(main_fndecl) = main_block.get_tree();
- DECL_SAVED_TREE(main_fndecl) = main_tree_scope.bind_expr.get_tree();
-
- // Main function is not external
- DECL_EXTERNAL(main_fndecl) = 0;
- // Preserve main function
- DECL_PRESERVE_P(main_fndecl) = 1;
-
- // Convert from GENERIC to GIMPLE
- gimplify_function_tree(main_fndecl);
-
- // Insert it into the graph (queue for compilation?)
- cgraph_node::finalize_function(main_fndecl, true);
-
- main_fndecl = NULL_TREE;
- }
// Parses a crate (compilation unit) - entry point
AST::Crate Parser::parse_crate() {
@@ -455,7 +349,7 @@ namespace Rust {
while (t->get_id() != END_OF_FILE) {
::std::unique_ptr<AST::Item> item = parse_item(false);
if (item == NULL) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse item in crate");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse item in crate");
items = ::std::vector< ::std::unique_ptr<AST::Item> >();
break;
}
@@ -517,12 +411,12 @@ namespace Rust {
// Parses the body of an attribute (inner or outer).
AST::Attribute Parser::parse_attribute_body() {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
AST::SimplePath attr_path = parse_simple_path();
// ensure path is valid to parse attribute input
if (attr_path.is_empty()) {
- error_at(lexer.peek_token()->get_locus(), "empty simple path in attribute");
+ rust_error_at(lexer.peek_token()->get_locus(), "empty simple path in attribute");
// Skip past potential further info in attribute (i.e. attr_input)
skip_after_end_attribute();
@@ -538,7 +432,7 @@ namespace Rust {
// Parses a SimplePath AST node
AST::SimplePath Parser::parse_simple_path() {
bool has_opening_scope_resolution = false;
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
// Checks for opening scope resolution (i.e. global scope fully-qualified path)
if (lexer.peek_token()->get_id() == SCOPE_RESOLUTION) {
@@ -553,7 +447,7 @@ namespace Rust {
AST::SimplePathSegment segment = parse_simple_path_segment();
// get location if not gotten already
- if (locus == UNKNOWN_LOCATION) {
+ if (locus == Linemap::unknown_location()) {
locus = segment.get_locus();
}
@@ -622,14 +516,14 @@ namespace Rust {
gcc_fallthrough();
default:
// do nothing but inactivates warning from gcc when compiling
- // could put the error_at thing here but fallthrough (from failing $crate condition)
+ // could put the rust_error_at thing here but fallthrough (from failing $crate condition)
// isn't completely obvious if it is.
// test prevent error
return AST::SimplePathSegment::create_error();
}
gcc_unreachable();
- /*error_at(
+ /*rust_error_at(
t->get_locus(), "invalid token '%s' in simple path segment", t->get_token_description());*/
// this is not necessarily an error, e.g. end of path
// return AST::SimplePathSegment::create_error();
@@ -701,7 +595,7 @@ namespace Rust {
// Ensure token is a "literal expression" (literally only a literal token of any type)
if (!t->is_literal()) {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unknown token '%s' in attribute body - literal expected",
t->get_token_description());
skip_after_end_attribute();
@@ -748,7 +642,7 @@ namespace Rust {
// means AttrInput is missing, which is allowed
return NULL;
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unknown token '%s' in attribute body - attribute input or none expected",
t->get_token_description());
skip_after_end_attribute();
@@ -791,7 +685,7 @@ namespace Rust {
const_TokenPtr t = lexer.peek_token();
lexer.skip_token();
- location_t initial_loc = t->get_locus();
+ Location initial_loc = t->get_locus();
// save delim type to ensure it is reused later
AST::DelimType delim_type = AST::PARENS;
@@ -808,7 +702,7 @@ namespace Rust {
delim_type = AST::CURLY;
break;
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' - expecting delimiters (for a delimited token tree)",
t->get_token_description());
return AST::DelimTokenTree::create_empty();
@@ -824,7 +718,7 @@ namespace Rust {
if (tok_tree == NULL) {
// TODO: is this error handling appropriate?
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"failed to parse token tree in delimited token tree - found '%s'",
t->get_token_description());
return AST::DelimTokenTree::create_empty();
@@ -853,7 +747,7 @@ namespace Rust {
return token_tree;
} else {
// tokens don't match opening delimiters, so produce error
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' - expecting closing delimiter '%s' (for a delimited token tree)",
t->get_token_description(),
(delim_type == AST::PARENS ? ")" : (delim_type == AST::SQUARE ? "]" : "}")));
@@ -881,7 +775,7 @@ namespace Rust {
case RIGHT_SQUARE:
case RIGHT_CURLY:
// error - should not be called when this a token
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected closing delimiter '%s' - token tree requires either paired delimiters "
"or non-delimiter tokens",
t->get_token_description());
@@ -978,7 +872,7 @@ namespace Rust {
default:
// otherwise unrecognised
// return parse_macro_item(::std::move(outer_attrs));
- error_at(t->get_locus(), "unrecognised token '%s' for start of %s",
+ rust_error_at(t->get_locus(), "unrecognised token '%s' for start of %s",
t->get_token_description(), called_from_statement ? "statement" : "item");
// skip somewhere?
return NULL;
@@ -1022,7 +916,7 @@ namespace Rust {
if (id != LEFT_SQUARE) {
if (id == EXCLAM) {
// this is inner attribute syntax, so throw error
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"token '!' found, indicating inner attribute definition. Inner attributes are not "
"possible at this location.");
} // TODO: are there any cases where this wouldn't be an error?
@@ -1074,14 +968,14 @@ namespace Rust {
case LEFT_CURLY:
return parse_extern_block(::std::move(vis), ::std::move(outer_attrs));
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in some sort of extern production",
t->get_token_description());
lexer.skip_token(2); // TODO: is this right thing to do?
return NULL;
}
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in some sort of extern production",
t->get_token_description());
lexer.skip_token(1); // TODO: is this right thing to do?
@@ -1121,7 +1015,7 @@ namespace Rust {
case FN_TOK:
return parse_function(::std::move(vis), ::std::move(outer_attrs));
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in some sort of const production",
t->get_token_description());
lexer.skip_token(1); // TODO: is this right thing to do?
@@ -1146,7 +1040,7 @@ namespace Rust {
case IMPL:
return parse_impl(::std::move(vis), ::std::move(outer_attrs));
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in some sort of unsafe production",
t->get_token_description());
lexer.skip_token(1); // TODO: is this right thing to do?
@@ -1194,12 +1088,12 @@ namespace Rust {
// ensure that first token is identifier saying "macro_rules"
const_TokenPtr t = lexer.peek_token();
if (t->get_id() != IDENTIFIER || t->get_str() != "macro_rules") {
- error_at(t->get_locus(), "macro rules definition does not start with 'macro_rules'");
+ rust_error_at(t->get_locus(), "macro rules definition does not start with 'macro_rules'");
// skip after somewhere?
return NULL;
}
lexer.skip_token();
- location_t macro_locus = t->get_locus();
+ Location macro_locus = t->get_locus();
if (!skip_token(EXCLAM)) {
// skip after somewhere?
@@ -1232,7 +1126,7 @@ namespace Rust {
delim_type = AST::CURLY;
break;
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' - expecting delimiters (for a macro rules definition)",
t->get_token_description());
return NULL;
@@ -1245,7 +1139,7 @@ namespace Rust {
// must be at least one macro rule, so parse it
AST::MacroRule initial_rule = parse_macro_rule();
if (initial_rule.is_error()) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"required first macro rule in macro rules definition could not be parsed");
// skip after somewhere?
return NULL;
@@ -1272,7 +1166,7 @@ namespace Rust {
// try to parse next rule
AST::MacroRule rule = parse_macro_rule();
if (rule.is_error()) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse macro rule in macro rules definition");
return NULL;
}
@@ -1306,7 +1200,7 @@ namespace Rust {
::std::move(macro_rules), ::std::move(outer_attrs), macro_locus));
} else {
// tokens don't match opening delimiters, so produce error
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' - expecting closing delimiter '%s' (for a macro rules "
"definition)",
t->get_token_description(),
@@ -1321,7 +1215,7 @@ namespace Rust {
// Parses a semi-coloned (except for full block) macro invocation item.
::std::unique_ptr<AST::MacroInvocationSemi> Parser::parse_macro_invocation_semi(
::std::vector<AST::Attribute> outer_attrs) {
- location_t macro_locus = lexer.peek_token()->get_locus();
+ Location macro_locus = lexer.peek_token()->get_locus();
AST::SimplePath path = parse_simple_path();
if (!skip_token(EXCLAM)) {
@@ -1345,7 +1239,7 @@ namespace Rust {
delim_type = AST::CURLY;
break;
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' - expecting delimiters (for a macro invocation semi body)",
t->get_token_description());
return NULL;
@@ -1361,7 +1255,7 @@ namespace Rust {
::std::unique_ptr<AST::TokenTree> tree = parse_token_tree();
if (tree == NULL) {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"failed to parse token tree for macro invocation semi - found '%s'",
t->get_token_description());
return NULL;
@@ -1397,7 +1291,7 @@ namespace Rust {
::std::move(outer_attrs), macro_locus));
} else {
// tokens don't match opening delimiters, so produce error
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' - expecting closing delimiter '%s' (for a macro invocation "
"semi)",
t->get_token_description(),
@@ -1415,7 +1309,7 @@ namespace Rust {
// parse macro path
AST::SimplePath macro_path = parse_simple_path();
if (macro_path.is_empty()) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse macro invocation path");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse macro invocation path");
// skip?
return NULL;
}
@@ -1428,7 +1322,7 @@ namespace Rust {
// parse internal delim token tree
AST::DelimTokenTree delim_tok_tree = parse_delim_token_tree();
- location_t macro_locus = macro_path.get_locus();
+ Location macro_locus = macro_path.get_locus();
return ::std::unique_ptr<AST::MacroInvocation>(
new AST::MacroInvocation(::std::move(macro_path), ::std::move(delim_tok_tree),
@@ -1496,7 +1390,7 @@ namespace Rust {
delim_type = AST::CURLY;
break;
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' - expecting delimiters (for a macro matcher)",
t->get_token_description());
return AST::MacroMatcher::create_error();
@@ -1512,7 +1406,7 @@ namespace Rust {
::std::unique_ptr<AST::MacroMatch> match = parse_macro_match();
if (match == NULL) {
- error_at(t->get_locus(), "failed to parse macro match for macro matcher - found '%s'",
+ rust_error_at(t->get_locus(), "failed to parse macro match for macro matcher - found '%s'",
t->get_token_description());
return AST::MacroMatcher::create_error();
}
@@ -1534,7 +1428,7 @@ namespace Rust {
return AST::MacroMatcher(delim_type, ::std::move(matches));
} else {
// tokens don't match opening delimiters, so produce error
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' - expecting closing delimiter '%s' (for a macro matcher)",
t->get_token_description(),
(delim_type == AST::PARENS ? ")" : (delim_type == AST::SQUARE ? "]" : "}")));
@@ -1556,7 +1450,7 @@ namespace Rust {
// must be macro matcher as delimited
AST::MacroMatcher matcher = parse_macro_matcher();
if (matcher.is_error()) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse macro matcher in macro match");
return NULL;
}
@@ -1575,7 +1469,7 @@ namespace Rust {
return parse_macro_match_repetition();
default:
// error: unrecognised
- error_at(t2->get_locus(),
+ rust_error_at(t2->get_locus(),
"unrecognised token combination '$%s' at start of macro match - did you "
"mean '$identifier' or '$('?",
t2->get_token_description());
@@ -1587,7 +1481,7 @@ namespace Rust {
case RIGHT_SQUARE:
case RIGHT_CURLY:
// not allowed
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"closing delimiters like '%s' are not allowed at the start of a macro match",
t->get_token_description());
// skip somewhere?
@@ -1605,7 +1499,7 @@ namespace Rust {
const_TokenPtr ident_tok = expect_token(IDENTIFIER);
if (ident_tok == NULL) {
- error_at(lexer.peek_token()->get_locus(), "missing identifier in macro match fragment");
+ rust_error_at(lexer.peek_token()->get_locus(), "missing identifier in macro match fragment");
return NULL;
}
Identifier ident = ident_tok->get_str();
@@ -1619,7 +1513,7 @@ namespace Rust {
const_TokenPtr t = expect_token(IDENTIFIER);
AST::MacroFragSpec frag = AST::get_frag_spec_from_str(t->get_str());
if (frag == AST::INVALID) {
- error_at(t->get_locus(), "invalid fragment specifier '%s' in fragment macro match",
+ rust_error_at(t->get_locus(), "invalid fragment specifier '%s' in fragment macro match",
t->get_str().c_str());
return NULL;
}
@@ -1638,7 +1532,7 @@ namespace Rust {
// parse required first macro match
::std::unique_ptr<AST::MacroMatch> initial_match = parse_macro_match();
if (initial_match == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"could not parse required first macro match in macro match repetition");
// skip after somewhere?
return NULL;
@@ -1651,7 +1545,7 @@ namespace Rust {
::std::unique_ptr<AST::MacroMatch> match = parse_macro_match();
if (match == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse macro match in macro match repetition");
return NULL;
}
@@ -1707,7 +1601,7 @@ namespace Rust {
lexer.skip_token();
break;
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"expected macro repetition operator ('*', '+', or '?') in macro match - found '%s'",
t->get_token_description());
// skip after somewhere?
@@ -1762,7 +1656,7 @@ namespace Rust {
// parse the "in" path as well
AST::SimplePath path = parse_simple_path();
if (path.is_empty()) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "missing path in pub(in path) visibility");
// skip after somewhere?
return AST::Visibility::create_error();
@@ -1773,7 +1667,7 @@ namespace Rust {
return AST::Visibility::create_in_path(::std::move(path));
}
default:
- error_at(
+ rust_error_at(
t->get_locus(), "unexpected token '%s' in visibility", t->get_token_description());
lexer.skip_token();
return AST::Visibility::create_error();
@@ -1783,7 +1677,7 @@ namespace Rust {
// Parses a module - either a bodied module or a module defined in another file.
::std::unique_ptr<AST::Module> Parser::parse_module(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(MOD);
const_TokenPtr module_name = expect_token(IDENTIFIER);
@@ -1812,7 +1706,7 @@ namespace Rust {
while (tok->get_id() != RIGHT_CURLY) {
::std::unique_ptr<AST::Item> item = parse_item(false);
if (item == NULL) {
- error_at(tok->get_locus(), "failed to parse item in module");
+ rust_error_at(tok->get_locus(), "failed to parse item in module");
return NULL;
}
@@ -1831,7 +1725,7 @@ namespace Rust {
::std::move(outer_attrs))); // module name?
}
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in module declaration/definition item",
t->get_token_description());
lexer.skip_token();
@@ -1842,7 +1736,7 @@ namespace Rust {
// Parses an extern crate declaration (dependency on external crate)
::std::unique_ptr<AST::ExternCrate> Parser::parse_extern_crate(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
if (!skip_token(EXTERN_TOK)) {
skip_after_semicolon();
return NULL;
@@ -1868,7 +1762,7 @@ namespace Rust {
lexer.skip_token();
break;
default:
- error_at(crate_name_tok->get_locus(),
+ rust_error_at(crate_name_tok->get_locus(),
"expecting crate name (identifier or 'self'), found '%s'",
crate_name_tok->get_token_description());
skip_after_semicolon();
@@ -1903,7 +1797,7 @@ namespace Rust {
lexer.skip_token();
break;
default:
- error_at(as_name_tok->get_locus(),
+ rust_error_at(as_name_tok->get_locus(),
"expecting as clause name (identifier or '_'), found '%s'",
as_name_tok->get_token_description());
skip_after_semicolon();
@@ -1922,7 +1816,7 @@ namespace Rust {
// Parses a use declaration.
::std::unique_ptr<AST::UseDeclaration> Parser::parse_use_decl(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
if (!skip_token(USE)) {
skip_after_semicolon();
return NULL;
@@ -1931,7 +1825,7 @@ namespace Rust {
// parse use tree, which is required
::std::unique_ptr<AST::UseTree> use_tree = parse_use_tree();
if (use_tree == NULL) {
- error_at(lexer.peek_token()->get_locus(), "could not parse use tree in use declaration");
+ rust_error_at(lexer.peek_token()->get_locus(), "could not parse use tree in use declaration");
skip_after_semicolon();
return NULL;
}
@@ -1971,7 +1865,7 @@ namespace Rust {
// TODO: I think this function is too complex, probably should split it
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// bool has_path = false;
AST::SimplePath path = parse_simple_path();
@@ -2034,12 +1928,12 @@ namespace Rust {
}
case AS:
// this is not allowed
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"use declaration with rebind 'as' requires a valid simple path - none found.");
skip_after_semicolon();
return NULL;
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in use tree with no valid simple path (i.e. list or "
"glob use tree)",
t->get_token_description());
@@ -2113,7 +2007,7 @@ namespace Rust {
new AST::UseTreeRebind(AST::UseTreeRebind::WILDCARD, ::std::move(path),
locus, ::std::string("_")));
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in use tree with as clause - expected "
"identifier or '_'",
t->get_token_description());
@@ -2135,7 +2029,7 @@ namespace Rust {
return ::std::unique_ptr<AST::UseTreeRebind>(
new AST::UseTreeRebind(AST::UseTreeRebind::NONE, ::std::move(path), locus));
default:
- error_at(t->get_locus(), "unexpected token '%s' in use tree with valid path",
+ rust_error_at(t->get_locus(), "unexpected token '%s' in use tree with valid path",
t->get_token_description());
// skip_after_semicolon();
return NULL;
@@ -2146,7 +2040,7 @@ namespace Rust {
// Parses a function (not a method).
::std::unique_ptr<AST::Function> Parser::parse_function(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// Get qualifiers for function if they exist
AST::FunctionQualifiers qualifiers = parse_function_qualifiers();
@@ -2165,7 +2059,7 @@ namespace Rust {
= parse_generic_params_in_angles();
if (!skip_token(LEFT_PAREN)) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"function declaration missing opening parentheses before parameter list");
skip_after_next_block();
return NULL;
@@ -2178,7 +2072,7 @@ namespace Rust {
}
if (!skip_token(RIGHT_PAREN)) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"function declaration missing closing parentheses after parameter list");
skip_after_next_block();
return NULL;
@@ -2302,7 +2196,7 @@ namespace Rust {
break;
}
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
AST::Lifetime lifetime = parse_lifetime();
// DEBUG
@@ -2336,7 +2230,7 @@ namespace Rust {
// reimpl as type param definitely exists
const_TokenPtr ident_tok = expect_token(IDENTIFIER);
if (ident_tok == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse identifier in type param in generic params");
return ::std::vector< ::std::unique_ptr<AST::GenericParam> >();
}
@@ -2359,7 +2253,7 @@ namespace Rust {
// parse required type
type = parse_type();
if (type == NULL) {
- error_at(lexer.peek_token()->get_id(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse type in type param in generic params");
return ::std::vector< ::std::unique_ptr<AST::GenericParam> >();
}
@@ -2385,7 +2279,7 @@ namespace Rust {
::std::unique_ptr<AST::TypeParam> type_param = parse_type_param();
if (type_param == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse type param in generic params");
return ::std::vector< ::std::unique_ptr<AST::GenericParam> >();
}
@@ -2563,7 +2457,7 @@ namespace Rust {
// parse type (now required)
type = parse_type();
if (type == NULL) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse type in type param");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse type in type param");
return NULL;
}
}
@@ -2607,7 +2501,7 @@ namespace Rust {
// now, as right paren would break, function param is required
AST::FunctionParam param = parse_function_param();
if (param.is_error()) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse function param (in function params)");
// skip somewhere?
return ::std::vector<AST::FunctionParam>();
@@ -2624,7 +2518,7 @@ namespace Rust {
/* Parses a single regular (i.e. non-generic) parameter in a function or method, i.e. the
* "name: type" bit. Also handles it not existing. */
AST::FunctionParam Parser::parse_function_param() {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
::std::unique_ptr<AST::Pattern> param_pattern = parse_pattern();
// create error function param if it doesn't exist
@@ -2682,7 +2576,7 @@ namespace Rust {
::std::unique_ptr<AST::WhereClauseItem> where_clause_item = parse_where_clause_item();
if (where_clause_item == NULL) {
- error_at(t->get_locus(), "failed to parse where clause item");
+ rust_error_at(t->get_locus(), "failed to parse where clause item");
return AST::WhereClause::create_empty();
}
@@ -2844,7 +2738,7 @@ namespace Rust {
bool has_parens = false;
bool has_question_mark = false;
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// handle trait bound being in parentheses
if (lexer.peek_token()->get_id() == LEFT_PAREN) {
@@ -2907,7 +2801,7 @@ namespace Rust {
// Parses a lifetime token (named, 'static, or '_). Also handles lifetime not existing.
AST::Lifetime Parser::parse_lifetime() {
const_TokenPtr lifetime_tok = lexer.peek_token();
- location_t locus = lifetime_tok->get_locus();
+ Location locus = lifetime_tok->get_locus();
// create error lifetime if doesn't exist
if (lifetime_tok->get_id() != LIFETIME) {
return AST::Lifetime::error();
@@ -2928,13 +2822,13 @@ namespace Rust {
// Parses a "type alias" (typedef) item.
::std::unique_ptr<AST::TypeAlias> Parser::parse_type_alias(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(TYPE);
// TODO: use this token for identifier when finished that
const_TokenPtr alias_name_tok = expect_token(IDENTIFIER);
if (alias_name_tok == NULL) {
- error_at(lexer.peek_token()->get_locus(), "could not parse identifier in type alias");
+ rust_error_at(lexer.peek_token()->get_locus(), "could not parse identifier in type alias");
skip_after_semicolon();
return NULL;
}
@@ -2977,13 +2871,13 @@ namespace Rust {
* | ';' ) */
/* Tuple struct <- 'struct' IDENTIFIER generic_params? '(' tuple_fields? ')'
* where_clause? ';' */
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(STRUCT_TOK);
// parse struct name
const_TokenPtr name_tok = expect_token(IDENTIFIER);
if (name_tok == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "could not parse struct or tuple struct identifier");
// skip after somewhere?
return NULL;
@@ -3060,7 +2954,7 @@ namespace Rust {
new AST::StructStruct(::std::move(struct_name), ::std::move(generic_params),
::std::move(where_clause), ::std::move(vis), ::std::move(outer_attrs), locus));
default:
- error_at(t->get_locus(), "unexpected token '%s' in struct declaration",
+ rust_error_at(t->get_locus(), "unexpected token '%s' in struct declaration",
t->get_token_description());
// skip somewhere?
return NULL;
@@ -3130,7 +3024,7 @@ namespace Rust {
// parse field type - this is required
::std::unique_ptr<AST::Type> field_type = parse_type();
if (field_type == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "could not parse type in struct field definition");
// skip after somewhere
return AST::StructField::create_error();
@@ -3168,7 +3062,7 @@ namespace Rust {
AST::TupleField field = parse_tuple_field();
if (field.is_error()) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse tuple field in tuple fields");
return ::std::vector<AST::TupleField>();
}
@@ -3195,7 +3089,7 @@ namespace Rust {
::std::unique_ptr<AST::Type> field_type = parse_type();
if (field_type == NULL) {
// error if null
- error_at(lexer.peek_token()->get_locus(), "could not parse type in tuple struct field");
+ rust_error_at(lexer.peek_token()->get_locus(), "could not parse type in tuple struct field");
// skip after something
return AST::TupleField::create_error();
}
@@ -3206,7 +3100,7 @@ namespace Rust {
// Parses a Rust "enum" tagged union item definition.
::std::unique_ptr<AST::Enum> Parser::parse_enum(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(ENUM_TOK);
// parse enum name
@@ -3345,7 +3239,7 @@ namespace Rust {
::std::unique_ptr<AST::Union> Parser::parse_union(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
// hack - "weak keyword" by finding identifier called "union" (lookahead in item switch)
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// skip union "identifier"
skip_token(IDENTIFIER);
@@ -3385,7 +3279,7 @@ namespace Rust {
// Parses a "constant item" (compile-time constant to maybe "inline" throughout the program).
::std::unique_ptr<AST::ConstantItem> Parser::parse_const_item(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(CONST);
// get constant identifier - this is either a proper identifier or the _ wildcard
@@ -3402,7 +3296,7 @@ namespace Rust {
lexer.skip_token();
break;
default:
- error_at(ident_tok->get_locus(),
+ rust_error_at(ident_tok->get_locus(),
"expected item name (identifier or '_') in constant item declaration - found '%s'",
ident_tok->get_token_description());
skip_after_semicolon();
@@ -3437,7 +3331,7 @@ namespace Rust {
// Parses a "static item" (static storage item, with 'static lifetime).
::std::unique_ptr<AST::StaticItem> Parser::parse_static_item(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(STATIC_TOK);
// determine whether static item is mutable
@@ -3478,7 +3372,7 @@ namespace Rust {
// Parses a trait definition item, including unsafe ones.
::std::unique_ptr<AST::Trait> Parser::parse_trait(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
bool is_unsafe = false;
if (lexer.peek_token()->get_id() == UNSAFE) {
is_unsafe = true;
@@ -3625,7 +3519,7 @@ namespace Rust {
// FIXME: are these outer attributes meant to be passed into the block?
break;
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"expected ';' or definiton at the end of trait %s definition - found '%s' "
"instead",
is_method ? "method" : "function", t->get_token_description());
@@ -3674,7 +3568,7 @@ namespace Rust {
// Parse a typedef trait item.
::std::unique_ptr<AST::TraitItemType> Parser::parse_trait_type(
::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(TYPE);
const_TokenPtr ident_tok = expect_token(IDENTIFIER);
@@ -3704,7 +3598,7 @@ namespace Rust {
// Parses a constant trait item.
::std::unique_ptr<AST::TraitItemConst> Parser::parse_trait_const(
::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(CONST);
// parse constant item name
@@ -3742,7 +3636,7 @@ namespace Rust {
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
/* Note that only trait impls are allowed to be unsafe. So if unsafe, it must be a trait
* impl. However, this isn't enough for full disambiguation, so don't branch here. */
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
bool is_unsafe = false;
if (lexer.peek_token()->get_id() == UNSAFE) {
lexer.skip_token();
@@ -3781,7 +3675,7 @@ namespace Rust {
}
// Type is required, so error if null
if (type == NULL) {
- error_at(lexer.peek_token()->get_locus(), "could not parse type in inherent impl");
+ rust_error_at(lexer.peek_token()->get_locus(), "could not parse type in inherent impl");
skip_after_next_block();
return NULL;
}
@@ -3839,7 +3733,7 @@ namespace Rust {
::std::unique_ptr<AST::Type> type = parse_type();
// ensure type is included as it is required
if (type == NULL) {
- error_at(lexer.peek_token()->get_locus(), "could not parse type in trait impl");
+ rust_error_at(lexer.peek_token()->get_locus(), "could not parse type in trait impl");
skip_after_next_block();
return NULL;
}
@@ -3940,14 +3834,14 @@ namespace Rust {
return parse_inherent_impl_function_or_method(
::std::move(vis), ::std::move(outer_attrs));
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in some sort of const item in inherent impl",
t->get_token_description());
lexer.skip_token(1); // TODO: is this right thing to do?
return NULL;
}
default:
- error_at(t->get_locus(), "unrecognised token '%s' for item in inherent impl",
+ rust_error_at(t->get_locus(), "unrecognised token '%s' for item in inherent impl",
t->get_token_description());
// skip?
return NULL;
@@ -3974,7 +3868,7 @@ namespace Rust {
return parse_inherent_impl_function_or_method(
AST::Visibility::create_error(), ::std::move(outer_attrs));
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in some sort of const item in inherent impl",
t->get_token_description());
lexer.skip_token(1); // TODO: is this right thing to do?
@@ -3982,7 +3876,7 @@ namespace Rust {
}
gcc_unreachable();
default:
- error_at(t->get_locus(), "unrecognised token '%s' for item in inherent impl",
+ rust_error_at(t->get_locus(), "unrecognised token '%s' for item in inherent impl",
t->get_token_description());
// skip?
return NULL;
@@ -3996,7 +3890,7 @@ namespace Rust {
// specialisation of the template while TraitImplItem will be the other.
::std::unique_ptr<AST::InherentImplItem> Parser::parse_inherent_impl_function_or_method(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// parse function or method qualifiers
AST::FunctionQualifiers qualifiers = parse_function_qualifiers();
@@ -4045,7 +3939,7 @@ namespace Rust {
// parse function definition (in block) - semicolon not allowed
if (lexer.peek_token()->get_id() == SEMICOLON) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"%s declaration in inherent impl not allowed - must have a definition",
is_method ? "method" : "function");
lexer.skip_token();
@@ -4053,7 +3947,7 @@ namespace Rust {
}
::std::unique_ptr<AST::BlockExpr> body = parse_block_expr();
if (body == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"could not parse definition in inherent impl %s definition",
is_method ? "method" : "function");
skip_after_end_block();
@@ -4121,14 +4015,14 @@ namespace Rust {
return parse_trait_impl_function_or_method(
::std::move(vis), ::std::move(outer_attrs));
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in some sort of const item in trait impl",
t->get_token_description());
lexer.skip_token(1); // TODO: is this right thing to do?
return NULL;
}
default:
- error_at(t->get_locus(), "unrecognised token '%s' for item in trait impl",
+ rust_error_at(t->get_locus(), "unrecognised token '%s' for item in trait impl",
t->get_token_description());
// skip?
return NULL;
@@ -4155,7 +4049,7 @@ namespace Rust {
return parse_trait_impl_function_or_method(
AST::Visibility::create_error(), ::std::move(outer_attrs));
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in some sort of const item in trait impl",
t->get_token_description());
lexer.skip_token(1); // TODO: is this right thing to do?
@@ -4163,7 +4057,7 @@ namespace Rust {
}
gcc_unreachable();
default:
- error_at(t->get_locus(), "unrecognised token '%s' for item in trait impl",
+ rust_error_at(t->get_locus(), "unrecognised token '%s' for item in trait impl",
t->get_token_description());
// skip?
return NULL;
@@ -4176,7 +4070,7 @@ namespace Rust {
::std::unique_ptr<AST::TraitImplItem> Parser::parse_trait_impl_function_or_method(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
// this shares virtually all logic with parse_inherent_impl_function_or_method - template?
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// parse function or method qualifiers
AST::FunctionQualifiers qualifiers = parse_function_qualifiers();
@@ -4230,7 +4124,7 @@ namespace Rust {
function_params = parse_function_params();
if (function_params.empty()) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse function params in trait impl %s definition",
is_method ? "method" : "function");
skip_after_next_block();
@@ -4263,7 +4157,7 @@ namespace Rust {
// parse function definition (in block) - semicolon not allowed
if (lexer.peek_token()->get_id() == SEMICOLON) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"%s declaration in trait impl not allowed - must have a definition",
is_method ? "method" : "function");
lexer.skip_token();
@@ -4271,7 +4165,7 @@ namespace Rust {
}
::std::unique_ptr<AST::BlockExpr> body = parse_block_expr();
if (body == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"could not parse definition in trait impl %s definition",
is_method ? "method" : "function");
skip_after_end_block();
@@ -4295,7 +4189,7 @@ namespace Rust {
// Parses an extern block of declarations.
::std::unique_ptr<AST::ExternBlock> Parser::parse_extern_block(
AST::Visibility vis, ::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(EXTERN_TOK);
// detect optional abi name
@@ -4321,7 +4215,7 @@ namespace Rust {
::std::unique_ptr<AST::ExternalItem> extern_item = parse_external_item();
if (extern_item == NULL) {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"failed to parse external item despite not reaching end of extern block");
return NULL;
}
@@ -4346,7 +4240,7 @@ namespace Rust {
// parse optional outer attributes
::std::vector<AST::Attribute> outer_attrs = parse_outer_attributes();
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// parse optional visibility
AST::Visibility vis = parse_visibility();
@@ -4380,7 +4274,7 @@ namespace Rust {
// parse type (required)
::std::unique_ptr<AST::Type> type = parse_type();
if (type == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse type in external static item");
skip_after_semicolon();
return NULL;
@@ -4427,7 +4321,7 @@ namespace Rust {
if (param.is_error()) {
// is this an error? probably
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"could not parse named function parameter in external function");
skip_after_semicolon();
return NULL;
@@ -4438,7 +4332,7 @@ namespace Rust {
t = lexer.peek_token();
if (t->get_id() != COMMA) {
if (t->get_id() != RIGHT_PAREN) {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"expected comma or right parentheses in named function parameters, "
"found '%s'",
t->get_token_description());
@@ -4485,7 +4379,7 @@ namespace Rust {
}
default:
// error
- error_at(t->get_locus(), "unrecognised token '%s' in extern block item declaration",
+ rust_error_at(t->get_locus(), "unrecognised token '%s' in extern block item declaration",
t->get_token_description());
skip_after_semicolon();
return NULL;
@@ -4520,7 +4414,7 @@ namespace Rust {
// parse (required) type
::std::unique_ptr<AST::Type> param_type = parse_type();
if (param_type == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"could not parse param type in extern block function declaration");
skip_after_semicolon();
return AST::NamedFunctionParam::create_error();
@@ -4605,13 +4499,13 @@ namespace Rust {
// Parses a let statement.
::std::unique_ptr<AST::LetStmt> Parser::parse_let_stmt(
::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(LET);
// parse pattern (required)
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse pattern in let statement");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse pattern in let statement");
skip_after_semicolon();
return NULL;
}
@@ -4624,7 +4518,7 @@ namespace Rust {
type = parse_type();
if (type == NULL) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse type in let statement");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse type in let statement");
skip_after_semicolon();
return NULL;
}
@@ -4638,7 +4532,7 @@ namespace Rust {
expr = parse_expr();
if (expr == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse expression in let statement");
skip_after_semicolon();
return NULL;
@@ -4686,7 +4580,7 @@ namespace Rust {
::std::unique_ptr<AST::TypePathSegment> segment = parse_type_path_segment();
if (segment == NULL) {
// skip after somewhere?
- error_at(t->get_locus(), "could not parse type path segment");
+ rust_error_at(t->get_locus(), "could not parse type path segment");
return AST::TypePath::create_error();
}
@@ -4695,7 +4589,9 @@ namespace Rust {
t = lexer.peek_token();
}
- return AST::TypePath(::std::move(segments), has_opening_scope_resolution);
+ return AST::TypePath(::std::move(segments),
+ Linemap::unknown_location(),
+ has_opening_scope_resolution);
}
// Parses the generic arguments in each path segment.
@@ -4709,7 +4605,7 @@ namespace Rust {
::std::vector<AST::Lifetime> lifetime_args;
const_TokenPtr t = lexer.peek_token();
- location_t locus = t->get_locus();
+ Location locus = t->get_locus();
const_TokenPtr t2 = lexer.peek_token(1);
while (
t->get_id() == LIFETIME && (t2->get_id() == COMMA || !is_right_angle_tok(t2->get_id()))) {
@@ -4827,7 +4723,7 @@ namespace Rust {
/* Parses a single type path segment (not including opening scope resolution, but includes any
* internal ones). Includes generic args or type path functions too. */
::std::unique_ptr<AST::TypePathSegment> Parser::parse_type_path_segment() {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// parse ident segment part
AST::PathIdentSegment ident_segment = parse_path_ident_segment();
if (ident_segment.is_error()) {
@@ -4917,7 +4813,7 @@ namespace Rust {
// Parses a path inside an expression that allows generic arguments.
AST::PathInExpression Parser::parse_path_in_expression() {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
bool has_opening_scope_resolution = false;
if (lexer.peek_token()->get_id() == SCOPE_RESOLUTION) {
has_opening_scope_resolution = true;
@@ -4930,7 +4826,7 @@ namespace Rust {
// create segment vector
::std::vector<AST::PathExprSegment> segments;
- if (locus == UNKNOWN_LOCATION) {
+ if (locus == Linemap::unknown_location()) {
locus = lexer.peek_token()->get_locus();
}
@@ -4953,7 +4849,7 @@ namespace Rust {
AST::PathExprSegment segment = parse_path_expr_segment();
if (segment.is_error()) {
// skip after somewhere?
- error_at(t->get_locus(), "could not parse path expression segment");
+ rust_error_at(t->get_locus(), "could not parse path expression segment");
return AST::PathInExpression::create_error();
}
@@ -4968,7 +4864,7 @@ namespace Rust {
// Parses a single path in expression path segment (including generic arguments).
AST::PathExprSegment Parser::parse_path_expr_segment() {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// parse ident segment
AST::PathIdentSegment ident = parse_path_ident_segment();
if (ident.is_error()) {
@@ -5009,7 +4905,7 @@ namespace Rust {
// TODO: should this create a parse error?
return AST::QualifiedPathInExpression::create_error();
}
- location_t locus = qual_path_type.get_locus();
+ Location locus = qual_path_type.get_locus();
// parse path segments
::std::vector<AST::PathExprSegment> segments;
@@ -5023,7 +4919,7 @@ namespace Rust {
AST::PathExprSegment initial_segment = parse_path_expr_segment();
if (initial_segment.is_error()) {
// skip after somewhere?
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"required initial path expression segment in "
"qualified path in expression could not be parsed");
return AST::QualifiedPathInExpression::create_error();
@@ -5040,7 +4936,7 @@ namespace Rust {
AST::PathExprSegment segment = parse_path_expr_segment();
if (segment.is_error()) {
// skip after somewhere?
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"could not parse path expression segment in qualified path in expression");
return AST::QualifiedPathInExpression::create_error();
}
@@ -5057,7 +4953,7 @@ namespace Rust {
// Parses the type syntactical construction at the start of a qualified path.
AST::QualifiedPathType Parser::parse_qualified_path_type(bool pratt_parse) {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
// TODO: should this actually be error? is there anywhere where this could be valid?
if (!pratt_parse) {
locus = lexer.peek_token()->get_locus();
@@ -5067,13 +4963,13 @@ namespace Rust {
}
} else {
// move back by 1 if pratt parsing due to skipping '<'
- locus = lexer.peek_token()->get_locus() - 1;
+ locus = lexer.peek_token()->get_locus();
}
// parse type (required)
::std::unique_ptr<AST::Type> type = parse_type();
if (type == NULL) {
- error_at(lexer.peek_token()->get_locus(), "could not parse type in qualified path type");
+ rust_error_at(lexer.peek_token()->get_locus(), "could not parse type in qualified path type");
// skip somewhere?
return AST::QualifiedPathType::create_error();
}
@@ -5086,7 +4982,7 @@ namespace Rust {
// parse type path, which is required now
as_type_path = parse_type_path();
if (as_type_path.is_error()) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"could not parse type path in as clause in qualified path type");
// skip somewhere?
return AST::QualifiedPathType::create_error();
@@ -5105,7 +5001,7 @@ namespace Rust {
// Parses a fully qualified path in type (i.e. a type).
AST::QualifiedPathInType Parser::parse_qualified_path_in_type() {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// parse the qualified path type (required)
AST::QualifiedPathType qual_path_type = parse_qualified_path_type();
if (qual_path_type.is_error()) {
@@ -5125,7 +5021,7 @@ namespace Rust {
::std::unique_ptr<AST::TypePathSegment> initial_segment = parse_type_path_segment();
if (initial_segment == NULL) {
// skip after somewhere?
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"required initial type path segment in qualified path in type could not be parsed");
return AST::QualifiedPathInType::create_error();
}
@@ -5141,7 +5037,7 @@ namespace Rust {
::std::unique_ptr<AST::TypePathSegment> segment = parse_type_path_segment();
if (segment == NULL) {
// skip after somewhere?
- error_at(
+ rust_error_at(
t->get_locus(), "could not parse type path segment in qualified path in type");
return AST::QualifiedPathInType::create_error();
}
@@ -5159,7 +5055,7 @@ namespace Rust {
bool has_reference = false;
AST::Lifetime lifetime = AST::Lifetime::error();
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// test if self is a reference parameter
if (lexer.peek_token()->get_id() == AMP) {
@@ -5172,7 +5068,7 @@ namespace Rust {
// something went wrong somehow
if (lifetime.is_error()) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse lifetime in self param");
// skip after somewhere?
return AST::SelfParam::create_error();
@@ -5203,7 +5099,7 @@ namespace Rust {
// type is now required
type = parse_type();
if (type == NULL) {
- error_at(lexer.peek_token()->get_locus(), "could not parse type in self param");
+ rust_error_at(lexer.peek_token()->get_locus(), "could not parse type in self param");
// skip after somewhere?
return AST::SelfParam::create_error();
}
@@ -5211,7 +5107,7 @@ namespace Rust {
// ensure that cannot have both type and reference
if (type != NULL && has_reference) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"cannot have both a reference and a type specified in a self param");
// skip after somewhere?
return AST::SelfParam::create_error();
@@ -5230,7 +5126,7 @@ namespace Rust {
* probably parse a "function or method" and then resolve it into whatever it is afterward. As
* such, this is only here for algorithmically defining the grammar rule. */
AST::Method Parser::parse_method() {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// Note: as a result of the above, this will not attempt to disambiguate a function
// parse qualifiers
AST::FunctionQualifiers qualifiers = parse_function_qualifiers();
@@ -5249,7 +5145,7 @@ namespace Rust {
= parse_generic_params_in_angles();
if (!skip_token(LEFT_PAREN)) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"method missing opening parentheses before parameter list");
skip_after_next_block();
return AST::Method::create_error();
@@ -5258,7 +5154,7 @@ namespace Rust {
// parse self param
AST::SelfParam self_param = parse_self_param();
if (self_param.is_error()) {
- error_at(lexer.peek_token()->get_locus(), "could not parse self param in method");
+ rust_error_at(lexer.peek_token()->get_locus(), "could not parse self param in method");
skip_after_next_block();
return AST::Method::create_error();
}
@@ -5272,7 +5168,7 @@ namespace Rust {
::std::vector<AST::FunctionParam> function_params = parse_function_params();
if (!skip_token(RIGHT_PAREN)) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"method declaration missing closing parentheses after parameter list");
skip_after_next_block();
return AST::Method::create_error();
@@ -5287,7 +5183,7 @@ namespace Rust {
// parse block expression
::std::unique_ptr<AST::BlockExpr> block_expr = parse_block_expr();
if (block_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(), "method declaration missing block expression");
+ rust_error_at(lexer.peek_token()->get_locus(), "method declaration missing block expression");
skip_after_end_block();
return AST::Method::create_error();
}
@@ -5413,7 +5309,7 @@ namespace Rust {
expr_parsed = parse_labelled_loop_expr(::std::move(outer_attrs));
break;
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"could not recognise expr beginning with '%s' as an expr with block in parsing "
"expr statement.",
t->get_token_description());
@@ -5423,7 +5319,7 @@ namespace Rust {
// ensure expr parsed exists
if (expr_parsed == NULL) {
- error_at(t->get_locus(), "failed to parse expr with block in parsing expr statement");
+ rust_error_at(t->get_locus(), "failed to parse expr with block in parsing expr statement");
skip_after_end_block();
return NULL;
}
@@ -5443,11 +5339,11 @@ namespace Rust {
expr = parse_expr_without_block(::std::move(outer_attrs));*/
// HACK: parse expression instead of expression without block, due to Pratt parsing issues
::std::unique_ptr<AST::Expr> expr = NULL;
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
expr = parse_expr(::std::move(outer_attrs));
if (expr == NULL) {
// expr is required, error
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse expr without block in expr statement");
skip_after_semicolon();
return NULL;
@@ -5540,7 +5436,7 @@ namespace Rust {
fprintf(stderr, "successfully parsed expr (in expr without block method)\n");
if (expr == NULL) {
- error_at(t->get_locus(), "failed to parse expression for expression without "
+ rust_error_at(t->get_locus(), "failed to parse expression for expression without "
"block (pratt-parsed expression is null)");
return NULL;
}
@@ -5560,7 +5456,7 @@ namespace Rust {
return expr_without_block;
} else {
- error_at(t->get_locus(), "converted expr without block is null");
+ rust_error_at(t->get_locus(), "converted expr without block is null");
return NULL;
}
}
@@ -5570,7 +5466,7 @@ namespace Rust {
// Parses a block expression, including the curly braces at start and end.
::std::unique_ptr<AST::BlockExpr> Parser::parse_block_expr(
::std::vector<AST::Attribute> outer_attrs, bool pratt_parse) {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (!pratt_parse) {
locus = lexer.peek_token()->get_locus();
if (!skip_token(LEFT_CURLY)) {
@@ -5578,7 +5474,7 @@ namespace Rust {
return NULL;
}
} else {
- locus = lexer.peek_token()->get_locus() - 1;
+ locus = lexer.peek_token()->get_locus();
}
::std::vector<AST::Attribute> inner_attrs = parse_inner_attributes();
@@ -5591,7 +5487,7 @@ namespace Rust {
while (t->get_id() != RIGHT_CURLY) {
ExprOrStmt expr_or_stmt = parse_stmt_or_expr_without_block();
if (expr_or_stmt.is_error()) {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"failed to parse statement or expression without block in block expression");
return NULL;
}
@@ -5609,7 +5505,7 @@ namespace Rust {
}
if (!skip_token(RIGHT_CURLY)) {
- error_at(t->get_locus(), "error may be from having an expression (as opposed to "
+ rust_error_at(t->get_locus(), "error may be from having an expression (as opposed to "
"statement) in the body of the function but not last");
skip_after_end_block();
return NULL;
@@ -5617,7 +5513,7 @@ namespace Rust {
// ensure that there is at least either a statement or an expr
/*if (stmts.empty() && expr == NULL) {
- error_at(lexer.peek_token()->get_id(),
+ rust_error_at(lexer.peek_token()->get_id(),
"block expression requires statements or an expression without block - found neither");
skip_after_end_block();
return NULL;
@@ -5631,7 +5527,7 @@ namespace Rust {
// Parses a "grouped" expression (expression in parentheses), used to control precedence.
::std::unique_ptr<AST::GroupedExpr> Parser::parse_grouped_expr(
::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(LEFT_PAREN);
::std::vector<AST::Attribute> inner_attrs = parse_inner_attributes();
@@ -5656,7 +5552,7 @@ namespace Rust {
// Parses a closure expression (closure definition).
::std::unique_ptr<AST::ClosureExpr> Parser::parse_closure_expr(
::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
// detect optional "move"
bool has_move = false;
if (lexer.peek_token()->get_id() == MOVE) {
@@ -5681,7 +5577,7 @@ namespace Rust {
AST::ClosureParam param = parse_closure_param();
if (param.is_error()) {
// TODO is this really an error?
- error_at(t->get_locus(), "could not parse closure param");
+ rust_error_at(t->get_locus(), "could not parse closure param");
break;
}
params.push_back(::std::move(param));
@@ -5697,7 +5593,7 @@ namespace Rust {
}
break;
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in closure expression - expected '|' or '||'",
t->get_token_description());
// skip somewhere?
@@ -5716,7 +5612,7 @@ namespace Rust {
::std::unique_ptr<AST::TypeNoBounds> type = parse_type_no_bounds();
if (type == NULL) {
// error
- error_at(t->get_locus(), "failed to parse type for closure");
+ rust_error_at(t->get_locus(), "failed to parse type for closure");
// skip somewhere?
return NULL;
}
@@ -5725,7 +5621,7 @@ namespace Rust {
::std::unique_ptr<AST::BlockExpr> block = parse_block_expr();
if (block == NULL) {
// error
- error_at(lexer.peek_token()->get_locus(), "failed to parse block expr in closure");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse block expr in closure");
// skip somewhere?
return NULL;
}
@@ -5739,7 +5635,7 @@ namespace Rust {
// parse expr, which is required
::std::unique_ptr<AST::Expr> expr = parse_expr();
if (expr == NULL) {
- error_at(t->get_locus(), "failed to parse expression in closure");
+ rust_error_at(t->get_locus(), "failed to parse expression in closure");
// skip somewhere?
return NULL;
}
@@ -5807,7 +5703,7 @@ namespace Rust {
break;
default:
// error - cannot be a literal expr
- error_at(t->get_locus(), "unexpected token '%s' when parsing literal expression",
+ rust_error_at(t->get_locus(), "unexpected token '%s' when parsing literal expression",
t->get_token_description());
// skip?
return NULL;
@@ -5821,7 +5717,7 @@ namespace Rust {
// Parses a return expression (including any expression to return).
::std::unique_ptr<AST::ReturnExpr> Parser::parse_return_expr(
::std::vector<AST::Attribute> outer_attrs, bool pratt_parse) {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (!pratt_parse) {
locus = lexer.peek_token()->get_locus();
@@ -5829,7 +5725,7 @@ namespace Rust {
} else {
// minus 7 chars for 6 in return and a space
// or just TODO: pass in location data
- locus = lexer.peek_token()->get_locus() - 7;
+ locus = lexer.peek_token()->get_locus();
}
// parse expression to return, if it exists
@@ -5843,7 +5739,7 @@ namespace Rust {
// Parses a break expression (including any label to break to AND any return expression).
::std::unique_ptr<AST::BreakExpr> Parser::parse_break_expr(
::std::vector<AST::Attribute> outer_attrs, bool pratt_parse) {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (!pratt_parse) {
locus = lexer.peek_token()->get_locus();
@@ -5851,7 +5747,7 @@ namespace Rust {
} else {
// minus 6 chars for 5 in return and a space
// or just TODO: pass in location data
- locus = lexer.peek_token()->get_locus() - 6;
+ locus = lexer.peek_token()->get_locus();
}
// parse label (lifetime) if it exists - create dummy first
@@ -5870,7 +5766,7 @@ namespace Rust {
// Parses a continue expression (including any label to continue from).
::std::unique_ptr<AST::ContinueExpr> Parser::parse_continue_expr(
::std::vector<AST::Attribute> outer_attrs, bool pratt_parse) {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (!pratt_parse) {
locus = lexer.peek_token()->get_locus();
@@ -5878,7 +5774,7 @@ namespace Rust {
} else {
// minus 9 chars for 8 in return and a space
// or just TODO: pass in location data
- locus = lexer.peek_token()->get_locus() - 9;
+ locus = lexer.peek_token()->get_locus();
}
// parse label (lifetime) if it exists - create dummy first
@@ -5916,12 +5812,12 @@ namespace Rust {
::std::vector<AST::Attribute> outer_attrs ATTRIBUTE_UNUSED) {
// TODO: make having outer attributes an error?
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(IF);
// detect accidental if let
if (lexer.peek_token()->get_id() == LET) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"if let expression probably exists, but is being parsed as an if expression. This may "
"be a parser error.");
// skip somewhere?
@@ -5934,7 +5830,7 @@ namespace Rust {
::std::unique_ptr<AST::Expr> condition
= parse_expr(::std::vector<AST::Attribute>(), no_struct_expr);
if (condition == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse condition expression in if expression");
// skip somewhere?
return NULL;
@@ -5943,7 +5839,7 @@ namespace Rust {
// parse required block expr
::std::unique_ptr<AST::BlockExpr> if_body = parse_block_expr();
if (if_body == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse if body block expression in if expression");
// skip somewhere?
return NULL;
@@ -5968,7 +5864,7 @@ namespace Rust {
// parse else block expr (required)
::std::unique_ptr<AST::BlockExpr> else_body = parse_block_expr();
if (else_body == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse else body block expression in if expression");
// skip somewhere?
return NULL;
@@ -5984,7 +5880,7 @@ namespace Rust {
// parse if let expr (required)
::std::unique_ptr<AST::IfLetExpr> if_let_expr = parse_if_let_expr();
if (if_let_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse (else) if let expression after if expression");
// skip somewhere?
return NULL;
@@ -5997,7 +5893,7 @@ namespace Rust {
// parse if expr (required)
::std::unique_ptr<AST::IfExpr> if_expr = parse_if_expr();
if (if_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse (else) if expression after if expression");
// skip somewhere?
return NULL;
@@ -6009,7 +5905,7 @@ namespace Rust {
}
default:
// error - invalid token
- error_at(t->get_locus(), "unexpected token '%s' after else in if expression",
+ rust_error_at(t->get_locus(), "unexpected token '%s' after else in if expression",
t->get_token_description());
// skip somewhere?
return NULL;
@@ -6023,12 +5919,12 @@ namespace Rust {
::std::vector<AST::Attribute> outer_attrs ATTRIBUTE_UNUSED) {
// TODO: make having outer attributes an error?
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(IF);
// detect accidental if expr parsed as if let expr
if (lexer.peek_token()->get_id() != LET) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"if expression probably exists, but is being parsed as an if let expression. This may "
"be a parser error.");
// skip somewhere?
@@ -6040,7 +5936,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<AST::Pattern> > match_arm_patterns
= parse_match_arm_patterns(EQUAL);
if (match_arm_patterns.empty()) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse any match arm patterns in if let expression");
// skip somewhere?
return NULL;
@@ -6057,7 +5953,7 @@ namespace Rust {
::std::unique_ptr<AST::Expr> scrutinee_expr
= parse_expr(::std::vector<AST::Attribute>(), no_struct_expr);
if (scrutinee_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse scrutinee expression in if let expression");
// skip somewhere?
return NULL;
@@ -6068,7 +5964,7 @@ namespace Rust {
// parse block expression (required)
::std::unique_ptr<AST::BlockExpr> if_let_body = parse_block_expr();
if (if_let_body == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse if let body block expression in if let expression");
// skip somewhere?
return NULL;
@@ -6094,7 +5990,7 @@ namespace Rust {
// parse else block expr (required)
::std::unique_ptr<AST::BlockExpr> else_body = parse_block_expr();
if (else_body == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse else body block expression in if let expression");
// skip somewhere?
return NULL;
@@ -6111,7 +6007,7 @@ namespace Rust {
// parse if let expr (required)
::std::unique_ptr<AST::IfLetExpr> if_let_expr = parse_if_let_expr();
if (if_let_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse (else) if let expression after if let expression");
// skip somewhere?
return NULL;
@@ -6125,7 +6021,7 @@ namespace Rust {
// parse if expr (required)
::std::unique_ptr<AST::IfExpr> if_expr = parse_if_expr();
if (if_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse (else) if expression after if let expression");
// skip somewhere?
return NULL;
@@ -6138,7 +6034,7 @@ namespace Rust {
}
default:
// error - invalid token
- error_at(t->get_locus(), "unexpected token '%s' after else in if let expression",
+ rust_error_at(t->get_locus(), "unexpected token '%s' after else in if let expression",
t->get_token_description());
// skip somewhere?
return NULL;
@@ -6152,7 +6048,7 @@ namespace Rust {
* parse_labelled_loop_expr, which would call this. */
::std::unique_ptr<AST::LoopExpr> Parser::parse_loop_expr(
::std::vector<AST::Attribute> outer_attrs, AST::LoopLabel label) {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (label.is_error()) {
locus = lexer.peek_token()->get_locus();
} else {
@@ -6163,7 +6059,7 @@ namespace Rust {
// parse loop body, which is required
::std::unique_ptr<AST::BlockExpr> loop_body = parse_block_expr();
if (loop_body == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"could not parse loop body in (infinite) loop expression");
return NULL;
}
@@ -6176,7 +6072,7 @@ namespace Rust {
* parse_labelled_loop_expr, which would call this. */
::std::unique_ptr<AST::WhileLoopExpr> Parser::parse_while_loop_expr(
::std::vector<AST::Attribute> outer_attrs, AST::LoopLabel label) {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (label.is_error()) {
locus = lexer.peek_token()->get_locus();
} else {
@@ -6186,7 +6082,7 @@ namespace Rust {
// ensure it isn't a while let loop
if (lexer.peek_token()->get_id() == LET) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"appears to be while let loop but is being parsed by "
"while loop - this may be a compiler issue");
// skip somewhere?
@@ -6199,7 +6095,7 @@ namespace Rust {
::std::unique_ptr<AST::Expr> predicate
= parse_expr(::std::vector<AST::Attribute>(), no_struct_expr);
if (predicate == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse predicate expression in while loop");
// skip somewhere?
return NULL;
@@ -6209,7 +6105,7 @@ namespace Rust {
// parse loop body (required)
::std::unique_ptr<AST::BlockExpr> body = parse_block_expr();
if (body == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse loop body block expression in while loop");
// skip somewhere
return NULL;
@@ -6223,7 +6119,7 @@ namespace Rust {
* parse_labelled_loop_expr, which would call this. */
::std::unique_ptr<AST::WhileLetLoopExpr> Parser::parse_while_let_loop_expr(
::std::vector<AST::Attribute> outer_attrs, AST::LoopLabel label) {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (label.is_error()) {
locus = lexer.peek_token()->get_locus();
} else {
@@ -6233,7 +6129,7 @@ namespace Rust {
// check for possible accidental recognition of a while loop as a while let loop
if (lexer.peek_token()->get_id() != LET) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"appears to be a while loop but is being parsed by "
"while let loop - this may be a compiler issue");
// skip somewhere
@@ -6258,7 +6154,7 @@ namespace Rust {
::std::unique_ptr<AST::Expr> predicate_expr
= parse_expr(::std::vector<AST::Attribute>(), no_struct_expr);
if (predicate_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse predicate expression in while let loop");
// skip somewhere?
return NULL;
@@ -6268,7 +6164,7 @@ namespace Rust {
// parse loop body, which is required
::std::unique_ptr<AST::BlockExpr> body = parse_block_expr();
if (body == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse block expr (loop body) of while let loop");
// skip somewhere?
return NULL;
@@ -6283,7 +6179,7 @@ namespace Rust {
* parse_labelled_loop_expr, which would call this. */
::std::unique_ptr<AST::ForLoopExpr> Parser::parse_for_loop_expr(
::std::vector<AST::Attribute> outer_attrs, AST::LoopLabel label) {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (label.is_error()) {
locus = lexer.peek_token()->get_locus();
} else {
@@ -6294,7 +6190,7 @@ namespace Rust {
// parse pattern, which is required
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse iterator pattern in for loop");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse iterator pattern in for loop");
// skip somewhere?
return NULL;
}
@@ -6310,7 +6206,7 @@ namespace Rust {
::std::unique_ptr<AST::Expr> expr
= parse_expr(::std::vector<AST::Attribute>(), no_struct_expr);
if (expr == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse iterator expression in for loop");
// skip somewhere?
return NULL;
@@ -6320,7 +6216,7 @@ namespace Rust {
// parse loop body, which is required
::std::unique_ptr<AST::BlockExpr> body = parse_block_expr();
if (body == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse loop body block expression in for loop");
// skip somewhere?
return NULL;
@@ -6337,7 +6233,7 @@ namespace Rust {
// at the moment, I will make it not work with no label because that's the implication.
if (lexer.peek_token()->get_id() != LIFETIME) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"expected lifetime in labelled loop expr (to parse loop label) - found '%s'",
lexer.peek_token()->get_token_description());
// skip?
@@ -6347,7 +6243,7 @@ namespace Rust {
// parse loop label (required)
AST::LoopLabel label = parse_loop_label();
if (label.is_error()) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse loop label in labelled loop expr");
// skip?
return NULL;
@@ -6369,7 +6265,7 @@ namespace Rust {
}
default:
// error
- error_at(t->get_locus(), "unexpected token '%s' when parsing labelled loop",
+ rust_error_at(t->get_locus(), "unexpected token '%s' when parsing labelled loop",
t->get_token_description());
// skip?
return NULL;
@@ -6379,7 +6275,7 @@ namespace Rust {
// Parses a match expression.
::std::unique_ptr<AST::MatchExpr> Parser::parse_match_expr(
::std::vector<AST::Attribute> outer_attrs, bool pratt_parse) {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (!pratt_parse) {
locus = lexer.peek_token()->get_locus();
@@ -6387,7 +6283,7 @@ namespace Rust {
} else {
// TODO: probably just pass in location data as param
// get current pos then move back 6 - 5 for match, 1 for space
- locus = lexer.peek_token()->get_locus() - 6;
+ locus = lexer.peek_token()->get_locus();
}
// parse scrutinee expression, which is required (and HACK to prevent struct expr)
@@ -6396,7 +6292,7 @@ namespace Rust {
::std::unique_ptr<AST::Expr> scrutinee
= parse_expr(::std::vector<AST::Attribute>(), no_struct_expr);
if (scrutinee == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse scrutinee expression in match expression");
// skip somewhere?
return NULL;
@@ -6447,7 +6343,7 @@ namespace Rust {
// block expr
::std::unique_ptr<AST::BlockExpr> block_expr = parse_block_expr();
if (block_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse block expr in match arm in match expr");
// skip somewhere
return NULL;
@@ -6466,7 +6362,7 @@ namespace Rust {
// regular expr
::std::unique_ptr<AST::Expr> expr = parse_expr();
if (expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse expr in match arm in match expr");
// skip somewhere?
return NULL;
@@ -6513,7 +6409,7 @@ namespace Rust {
::std::vector< ::std::unique_ptr<AST::Pattern> > match_arm_patterns
= parse_match_arm_patterns(RIGHT_CURLY);
if (match_arm_patterns.empty()) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse any patterns in match arm");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse any patterns in match arm");
// skip somewhere?
return AST::MatchArm::create_error();
}
@@ -6528,7 +6424,7 @@ namespace Rust {
guard_expr = parse_expr();
if (guard_expr == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse guard expression in match arm");
// skip somewhere?
return AST::MatchArm::create_error();
@@ -6588,7 +6484,7 @@ namespace Rust {
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
// this is an error
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse pattern in match arm patterns");
// skip somewhere?
return ::std::vector< ::std::unique_ptr<AST::Pattern> >();
@@ -6605,7 +6501,7 @@ namespace Rust {
// Parses an async block expression.
::std::unique_ptr<AST::AsyncBlockExpr> Parser::parse_async_block_expr(
::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(ASYNC);
// detect optional move token
@@ -6618,7 +6514,7 @@ namespace Rust {
// parse block expression (required)
::std::unique_ptr<AST::BlockExpr> block_expr = parse_block_expr();
if (block_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse block expression of async block expression");
// skip somewhere?
return NULL;
@@ -6631,13 +6527,13 @@ namespace Rust {
// Parses an unsafe block expression.
::std::unique_ptr<AST::UnsafeBlockExpr> Parser::parse_unsafe_block_expr(
::std::vector<AST::Attribute> outer_attrs) {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(UNSAFE);
// parse block expression (required)
::std::unique_ptr<AST::BlockExpr> block_expr = parse_block_expr();
if (block_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse block expression of unsafe block expression");
// skip somewhere?
return NULL;
@@ -6650,13 +6546,13 @@ namespace Rust {
// Parses an array definition expression.
::std::unique_ptr<AST::ArrayExpr> Parser::parse_array_expr(
::std::vector<AST::Attribute> outer_attrs, bool pratt_parse) {
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (!pratt_parse) {
locus = lexer.peek_token()->get_locus();
skip_token(LEFT_SQUARE);
} else {
- locus = lexer.peek_token()->get_locus() - 1;
+ locus = lexer.peek_token()->get_locus();
}
// parse optional inner attributes
@@ -6674,7 +6570,7 @@ namespace Rust {
// parse initial expression, which is required for either
::std::unique_ptr<AST::Expr> initial_expr = parse_expr();
if (initial_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"could not parse expression in array expression "
"(even though arrayelems seems to be present)");
// skip somewhere?
@@ -6688,7 +6584,7 @@ namespace Rust {
// parse copy amount expression (required)
::std::unique_ptr<AST::Expr> copy_amount = parse_expr();
if (copy_amount == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"could not parse copy amount expression in array expression (arrayelems)");
// skip somewhere?
return NULL;
@@ -6725,7 +6621,7 @@ namespace Rust {
// parse expression (required)
::std::unique_ptr<AST::Expr> expr = parse_expr();
if (expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse element in array expression");
// skip somewhere?
return NULL;
@@ -6743,7 +6639,7 @@ namespace Rust {
::std::move(inner_attrs), ::std::move(outer_attrs), locus));
} else {
// error
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"unexpected token '%s' in array expression (arrayelems)",
lexer.peek_token()->get_token_description());
// skip somewhere?
@@ -6769,7 +6665,7 @@ namespace Rust {
// parse type, which is now required
type = parse_type();
if (type == NULL) {
- error_at(lexer.peek_token()->get_id(), "failed to parse type in closure parameter");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse type in closure parameter");
// skip somewhere?
return AST::ClosureParam::create_error();
}
@@ -6782,13 +6678,13 @@ namespace Rust {
::std::unique_ptr<AST::ExprWithoutBlock> Parser::parse_grouped_or_tuple_expr(
::std::vector<AST::Attribute> outer_attrs, bool pratt_parse) {
// adjustment to allow Pratt parsing to reuse function without copy-paste
- location_t locus = UNKNOWN_LOCATION;
+ Location locus = Linemap::unknown_location();
if (!pratt_parse) {
locus = lexer.peek_token()->get_locus();
skip_token(LEFT_PAREN);
} else {
- locus = lexer.peek_token()->get_locus() - 1;
+ locus = lexer.peek_token()->get_locus();
}
// parse optional inner attributes
@@ -6807,7 +6703,7 @@ namespace Rust {
// parse first expression (required)
::std::unique_ptr<AST::Expr> first_expr = parse_expr();
if (first_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse expression in grouped or tuple expression");
// skip after somewhere?
return NULL;
@@ -6839,7 +6735,7 @@ namespace Rust {
// parse expr, which is now required
::std::unique_ptr<AST::Expr> expr = parse_expr();
if (expr == NULL) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse expr in tuple expr");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse expr in tuple expr");
// skip somewhere?
return NULL;
}
@@ -6856,7 +6752,7 @@ namespace Rust {
} else {
// error
const_TokenPtr t = lexer.peek_token();
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' in grouped or tuple expression (parenthesised expression) - "
"expected ')' for grouped expr and ',' for tuple expr",
t->get_token_description());
@@ -6911,7 +6807,7 @@ namespace Rust {
// qualified path in type
AST::QualifiedPathInType path = parse_qualified_path_in_type();
if (path.is_error()) {
- error_at(t->get_locus(), "failed to parse qualified path in type");
+ rust_error_at(t->get_locus(), "failed to parse qualified path in type");
return NULL;
}
return ::std::unique_ptr<AST::QualifiedPathInType>(
@@ -6953,10 +6849,10 @@ namespace Rust {
// parse path as type path
AST::TypePath path = parse_type_path();
if (path.is_error()) {
- error_at(t->get_locus(), "failed to parse path as first component of type");
+ rust_error_at(t->get_locus(), "failed to parse path as first component of type");
return NULL;
}
- location_t locus = path.get_locus();
+ Location locus = path.get_locus();
// branch on next token
t = lexer.peek_token();
@@ -6966,7 +6862,7 @@ namespace Rust {
// convert to simple path
AST::SimplePath macro_path = path.as_simple_path();
if (macro_path.is_empty()) {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"failed to parse simple path in macro invocation (for type)");
return NULL;
}
@@ -7038,12 +6934,12 @@ namespace Rust {
// should be trait bound, so parse trait bound
::std::unique_ptr<AST::TraitBound> initial_bound = parse_trait_bound();
if (initial_bound == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse ImplTraitType initial bound");
return NULL;
}
- location_t locus = t->get_locus();
+ Location locus = t->get_locus();
// short cut if next token isn't '+'
t = lexer.peek_token();
@@ -7098,7 +6994,7 @@ namespace Rust {
// should be trait bound, so parse trait bound
::std::unique_ptr<AST::TraitBound> initial_bound = parse_trait_bound();
if (initial_bound == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse TraitObjectType initial bound");
return NULL;
}
@@ -7139,7 +7035,7 @@ namespace Rust {
}
}
default:
- error_at(
+ rust_error_at(
t->get_locus(), "unrecognised token '%s' in type", t->get_token_description());
return NULL;
}
@@ -7155,7 +7051,7 @@ namespace Rust {
* essentially breaking polymorphism and downcasting via virtual method abuse, as it was
* copied from the rustc implementation (in which types are reified due to tagged union),
* after a more OOP attempt by me failed. */
- location_t left_delim_locus = lexer.peek_token()->get_locus();
+ Location left_delim_locus = lexer.peek_token()->get_locus();
// skip left delim
lexer.skip_token();
@@ -7168,7 +7064,7 @@ namespace Rust {
while (t->get_id() != RIGHT_PAREN) {
::std::unique_ptr<AST::Type> type = parse_type();
if (type == NULL) {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"failed to parse type inside parentheses (probably tuple or parenthesised)");
return NULL;
}
@@ -7200,7 +7096,7 @@ namespace Rust {
AST::TraitBound* converted_bound = released_ptr->to_trait_bound(true);
delete released_ptr;
if (converted_bound == NULL) {
- error_at(lexer.peek_token()->get_id(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to hackily converted parsed type to trait bound");
return NULL;
}
@@ -7262,7 +7158,7 @@ namespace Rust {
* returns either a BareFunctionType, TraitObjectType, or TraitObjectTypeOneBound depending on
* following characters. */
::std::unique_ptr<AST::Type> Parser::parse_for_prefixed_type() {
- location_t for_locus = lexer.peek_token()->get_locus();
+ Location for_locus = lexer.peek_token()->get_locus();
// parse for lifetimes in type
::std::vector<AST::LifetimeParam> for_lifetimes = parse_for_lifetimes();
@@ -7324,7 +7220,7 @@ namespace Rust {
}
default:
// error
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unrecognised token '%s' in bare function type or trait object type or trait "
"object type one bound",
t->get_token_description());
@@ -7359,7 +7255,7 @@ namespace Rust {
// parse type (required)
::std::unique_ptr<AST::Type> type = parse_type();
if (type == NULL) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse type in maybe named param");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse type in maybe named param");
return AST::MaybeNamedParam::create_error();
}
@@ -7371,7 +7267,7 @@ namespace Rust {
::std::unique_ptr<AST::BareFunctionType> Parser::parse_bare_function_type(
::std::vector<AST::LifetimeParam> for_lifetimes) {
// TODO: pass in for lifetime location as param
- location_t best_try_locus = lexer.peek_token()->get_locus();
+ Location best_try_locus = lexer.peek_token()->get_locus();
AST::FunctionQualifiers qualifiers = parse_function_qualifiers();
@@ -7395,7 +7291,7 @@ namespace Rust {
is_variadic = true;
break;
} else {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"ellipsis (for variadic) can only go at end of bare function type");
return NULL;
}
@@ -7404,7 +7300,7 @@ namespace Rust {
// parse required param
AST::MaybeNamedParam param = parse_maybe_named_param();
if (param.is_error()) {
- error_at(t->get_locus(), "failed to parse maybe named param in bare function type");
+ rust_error_at(t->get_locus(), "failed to parse maybe named param in bare function type");
return NULL;
}
params.push_back(::std::move(param));
@@ -7429,7 +7325,7 @@ namespace Rust {
// parse required TypeNoBounds
return_type = parse_type_no_bounds();
if (return_type == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse return type (type no bounds) in bare function type");
return NULL;
}
@@ -7442,7 +7338,7 @@ namespace Rust {
// Parses a reference type (mutable or immutable, with given lifetime).
::std::unique_ptr<AST::ReferenceType> Parser::parse_reference_type() {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(AMP);
// parse optional lifetime
@@ -7450,7 +7346,7 @@ namespace Rust {
if (lexer.peek_token()->get_id() == LIFETIME) {
lifetime = parse_lifetime();
if (lifetime.is_error()) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse lifetime in reference type");
return NULL;
}
@@ -7465,8 +7361,8 @@ namespace Rust {
// parse type no bounds, which is required
::std::unique_ptr<AST::TypeNoBounds> type = parse_type_no_bounds();
if (type == NULL) {
- error_at(
- lexer.peek_token()->get_id(), "failed to parse referenced type in reference type");
+ rust_error_at(
+ lexer.peek_token()->get_locus(), "failed to parse referenced type in reference type");
return NULL;
}
@@ -7476,7 +7372,7 @@ namespace Rust {
// Parses a raw (unsafe) pointer type.
::std::unique_ptr<AST::RawPointerType> Parser::parse_raw_pointer_type() {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(ASTERISK);
AST::RawPointerType::PointerType kind = AST::RawPointerType::CONST;
@@ -7493,7 +7389,7 @@ namespace Rust {
lexer.skip_token();
break;
default:
- error_at(t->get_locus(), "unrecognised token '%s' in raw pointer type",
+ rust_error_at(t->get_locus(), "unrecognised token '%s' in raw pointer type",
t->get_token_description());
return NULL;
}
@@ -7501,7 +7397,7 @@ namespace Rust {
// parse type no bounds (required)
::std::unique_ptr<AST::TypeNoBounds> type = parse_type_no_bounds();
if (type == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse pointed type of raw pointer type");
return NULL;
}
@@ -7512,13 +7408,13 @@ namespace Rust {
// Parses a slice or array type, depending on following arguments (as lookahead is not possible).
::std::unique_ptr<AST::TypeNoBounds> Parser::parse_slice_or_array_type() {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
skip_token(LEFT_SQUARE);
// parse inner type (required)
::std::unique_ptr<AST::Type> inner_type = parse_type();
if (inner_type == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse inner type in slice or array type");
return NULL;
}
@@ -7539,7 +7435,7 @@ namespace Rust {
// parse required array size expression
::std::unique_ptr<AST::Expr> size = parse_expr();
if (size == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse size expression in array type");
return NULL;
}
@@ -7553,7 +7449,7 @@ namespace Rust {
}
default:
// error
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unrecognised token '%s' in slice or array type after inner type",
t->get_token_description());
return NULL;
@@ -7575,7 +7471,7 @@ namespace Rust {
// qualified path in type
AST::QualifiedPathInType path = parse_qualified_path_in_type();
if (path.is_error()) {
- error_at(t->get_locus(), "failed to parse qualified path in type");
+ rust_error_at(t->get_locus(), "failed to parse qualified path in type");
return NULL;
}
return ::std::unique_ptr<AST::QualifiedPathInType>(
@@ -7594,7 +7490,7 @@ namespace Rust {
case LIFETIME: {
// probably a lifetime bound, so probably type param bounds in TraitObjectType
// this is not allowed, but detection here for error message
- error_at(t->get_locus(), "lifetime bounds (i.e. in type param bounds, in "
+ rust_error_at(t->get_locus(), "lifetime bounds (i.e. in type param bounds, in "
"TraitObjectType) are not allowed as TypeNoBounds");
return NULL;
}
@@ -7616,11 +7512,11 @@ namespace Rust {
// parse path as type path
AST::TypePath path = parse_type_path();
if (path.is_error()) {
- error_at(
+ rust_error_at(
t->get_locus(), "failed to parse path as first component of type no bounds");
return NULL;
}
- location_t locus = path.get_locus();
+ Location locus = path.get_locus();
// branch on next token
t = lexer.peek_token();
@@ -7630,7 +7526,7 @@ namespace Rust {
// convert to simple path
AST::SimplePath macro_path = path.as_simple_path();
if (macro_path.is_empty()) {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"failed to parse simple path in macro invocation (for type)");
return NULL;
}
@@ -7645,7 +7541,7 @@ namespace Rust {
}
case PLUS: {
// type param bounds - not allowed, here for error message
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"type param bounds (in TraitObjectType) are not allowed as TypeNoBounds");
return NULL;
}
@@ -7672,7 +7568,7 @@ namespace Rust {
if (lexer.peek_token()->get_id() == LIFETIME) {
// cannot be one bound because lifetime prevents it from being traitbound
// not allowed as type no bounds, only here for error message
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"lifetime (probably lifetime bound, in type param bounds, in ImplTraitType) is "
"not allowed in TypeNoBounds");
return NULL;
@@ -7680,17 +7576,17 @@ namespace Rust {
// should be trait bound, so parse trait bound
::std::unique_ptr<AST::TraitBound> initial_bound = parse_trait_bound();
if (initial_bound == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse ImplTraitTypeOneBound bound");
return NULL;
}
- location_t locus = t->get_locus();
+ Location locus = t->get_locus();
// ensure not a trait with multiple bounds
t = lexer.peek_token();
if (t->get_id() == PLUS) {
- error_at(t->get_locus(), "plus after trait bound means an ImplTraitType, "
+ rust_error_at(t->get_locus(), "plus after trait bound means an ImplTraitType, "
"which is not allowed as a TypeNoBounds");
return NULL;
}
@@ -7715,7 +7611,7 @@ namespace Rust {
if (lexer.peek_token()->get_id() == LIFETIME) {
// means that cannot be TraitObjectTypeOneBound - so here for error message
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"lifetime as bound in TraitObjectTypeOneBound "
"is not allowed, so cannot be TypeNoBounds");
return NULL;
@@ -7724,17 +7620,17 @@ namespace Rust {
// should be trait bound, so parse trait bound
::std::unique_ptr<AST::TraitBound> initial_bound = parse_trait_bound();
if (initial_bound == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse TraitObjectTypeOneBound initial bound");
return NULL;
}
- location_t locus = t->get_locus();
+ Location locus = t->get_locus();
// detect error with plus as next token
t = lexer.peek_token();
if (t->get_id() == PLUS) {
- error_at(t->get_locus(), "plus after trait bound means a TraitObjectType, "
+ rust_error_at(t->get_locus(), "plus after trait bound means a TraitObjectType, "
"which is not allowed as a TypeNoBounds");
return NULL;
}
@@ -7749,7 +7645,7 @@ namespace Rust {
new AST::TraitObjectTypeOneBound(::std::move(value_bound), locus, has_dyn));
}
default:
- error_at(t->get_locus(), "unrecognised token '%s' in type no bounds",
+ rust_error_at(t->get_locus(), "unrecognised token '%s' in type no bounds",
t->get_token_description());
return NULL;
}
@@ -7763,7 +7659,7 @@ namespace Rust {
/* NOTE: again, syntactical ambiguity of a parenthesised trait bound is considered a trait
* bound, not a parenthesised type, so that it can still be used in type param bounds. */
- location_t left_paren_locus = lexer.peek_token()->get_locus();
+ Location left_paren_locus = lexer.peek_token()->get_locus();
// skip left delim
lexer.skip_token();
@@ -7776,7 +7672,7 @@ namespace Rust {
while (t->get_id() != RIGHT_PAREN) {
::std::unique_ptr<AST::Type> type = parse_type();
if (type == NULL) {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"failed to parse type inside parentheses (probably tuple or parenthesised)");
return NULL;
}
@@ -7801,8 +7697,9 @@ namespace Rust {
// must be a TraitObjectType (with more than one bound)
if (lexer.peek_token()->get_id() == PLUS) {
// error - this is not allowed for type no bounds
- error_at(lexer.peek_token()->get_id(), "plus (implying TraitObjectType as type param "
- "bounds) is not allowed in type no bounds");
+ rust_error_at(lexer.peek_token()->get_locus(),
+ "plus (implying TraitObjectType as type param "
+ "bounds) is not allowed in type no bounds");
return NULL;
} else {
// release vector pointer
@@ -7878,7 +7775,7 @@ namespace Rust {
lexer.skip_token(1);
break;
default:
- error_at(range_lower->get_locus(),
+ rust_error_at(range_lower->get_locus(),
"token type '%s' cannot be parsed as range pattern bound or literal after "
"minus "
"symbol",
@@ -7887,7 +7784,7 @@ namespace Rust {
}
break;
default:
- error_at(range_lower->get_locus(),
+ rust_error_at(range_lower->get_locus(),
"token type '%s' cannot be parsed as range pattern bound",
range_lower->get_token_description());
return NULL;
@@ -7897,12 +7794,17 @@ namespace Rust {
if (next->get_id() == DOT_DOT_EQ || next->get_id() == ELLIPSIS) {
// range pattern
lexer.skip_token();
- ::std::unique_ptr<AST::RangePatternBound> lower(new AST::RangePatternBoundLiteral(
- AST::Literal(range_lower->get_str(), type), range_lower->get_locus(), has_minus));
+ ::std::unique_ptr<AST::RangePatternBound> lower(
+ new AST::RangePatternBoundLiteral(
+ AST::Literal(range_lower->get_str(), type),
+ range_lower->get_locus(),
+ has_minus)
+ );
::std::unique_ptr<AST::RangePatternBound> upper = parse_range_pattern_bound();
if (upper == NULL) {
- error_at(next->get_locus(), "failed to parse range pattern bound in range pattern");
+ rust_error_at(next->get_locus(),
+ "failed to parse range pattern bound in range pattern");
return NULL;
}
@@ -7918,7 +7820,7 @@ namespace Rust {
// Parses a range pattern bound (value only).
::std::unique_ptr<AST::RangePatternBound> Parser::parse_range_pattern_bound() {
const_TokenPtr range_lower = lexer.peek_token();
- location_t range_lower_locus = range_lower->get_locus();
+ Location range_lower_locus = range_lower->get_locus();
// get lit type
switch (range_lower->get_id()) {
@@ -7961,7 +7863,7 @@ namespace Rust {
AST::Literal(range_lower->get_str(), AST::Literal::FLOAT),
range_lower_locus, true));
default:
- error_at(range_lower->get_locus(),
+ rust_error_at(range_lower->get_locus(),
"token type '%s' cannot be parsed as range pattern bound after minus "
"symbol",
range_lower->get_token_description());
@@ -7977,7 +7879,7 @@ namespace Rust {
// path in expression
AST::PathInExpression path = parse_path_in_expression();
if (path.is_error()) {
- error_at(range_lower->get_locus(),
+ rust_error_at(range_lower->get_locus(),
"failed to parse path in expression range pattern bound");
return NULL;
}
@@ -7988,7 +7890,7 @@ namespace Rust {
// qualified path in expression
AST::QualifiedPathInExpression path = parse_qualified_path_in_expression();
if (path.is_error()) {
- error_at(range_lower->get_locus(),
+ rust_error_at(range_lower->get_locus(),
"failed to parse qualified path in expression range pattern bound");
return NULL;
}
@@ -7996,7 +7898,7 @@ namespace Rust {
new AST::RangePatternBoundQualPath(::std::move(path)));
}
default:
- error_at(range_lower->get_locus(),
+ rust_error_at(range_lower->get_locus(),
"token type '%s' cannot be parsed as range pattern bound",
range_lower->get_token_description());
return NULL;
@@ -8035,7 +7937,7 @@ namespace Rust {
} else if (lexer.peek_token(1)->get_id() == FLOAT_LITERAL) {
return parse_literal_or_range_pattern();
} else {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '-' in pattern - did you forget an integer literal?");
return NULL;
}
@@ -8107,8 +8009,13 @@ namespace Rust {
::std::unique_ptr<AST::RangePatternBound> upper_bound
= parse_range_pattern_bound();
- return ::std::unique_ptr<AST::RangePattern>(new AST::RangePattern(
- ::std::move(lower_bound), ::std::move(upper_bound), has_ellipsis_syntax));
+ return ::std::unique_ptr<AST::RangePattern>(
+ new AST::RangePattern(
+ ::std::move(lower_bound),
+ ::std::move(upper_bound),
+ Linemap::unknown_location(),
+ has_ellipsis_syntax)
+ );
}
case EXCLAM:
return parse_macro_invocation_partial(
@@ -8120,7 +8027,7 @@ namespace Rust {
// parse items
::std::unique_ptr<AST::TupleStructItems> items = parse_tuple_struct_items();
if (items == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse tuple struct items");
return NULL;
}
@@ -8153,7 +8060,7 @@ namespace Rust {
}
}
default:
- error_at(
+ rust_error_at(
t->get_locus(), "unexpected token '%s' in pattern", t->get_token_description());
return NULL;
}
@@ -8174,7 +8081,7 @@ namespace Rust {
lexer.skip_token();
break;
default:
- error_at(t->get_locus(), "unexpected token '%s' in reference pattern",
+ rust_error_at(t->get_locus(), "unexpected token '%s' in reference pattern",
t->get_token_description());
return NULL;
}
@@ -8189,7 +8096,7 @@ namespace Rust {
// parse pattern to get reference of (required)
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse pattern in reference pattern");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse pattern in reference pattern");
// skip somewhere?
return NULL;
}
@@ -8201,7 +8108,7 @@ namespace Rust {
/* Parses a grouped pattern or tuple pattern. Prefers grouped over tuple if only a single element
* with no commas. */
::std::unique_ptr<AST::Pattern> Parser::parse_grouped_or_tuple_pattern() {
- location_t paren_locus = lexer.peek_token()->get_locus();
+ Location paren_locus = lexer.peek_token()->get_locus();
skip_token(LEFT_PAREN);
// detect '..' token (ranged with no lower range)
@@ -8223,7 +8130,7 @@ namespace Rust {
// parse pattern, which is required
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse pattern inside ranged tuple pattern");
// skip somewhere?
return NULL;
@@ -8248,7 +8155,7 @@ namespace Rust {
// parse initial pattern (required)
::std::unique_ptr<AST::Pattern> initial_pattern = parse_pattern();
if (initial_pattern == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse pattern in grouped or tuple pattern");
return NULL;
}
@@ -8275,7 +8182,7 @@ namespace Rust {
// parse pattern (required)
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(t->get_locus(), "failed to parse pattern in tuple pattern");
+ rust_error_at(t->get_locus(), "failed to parse pattern in tuple pattern");
return NULL;
}
patterns.push_back(::std::move(pattern));
@@ -8315,7 +8222,7 @@ namespace Rust {
// parse pattern (required)
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse pattern in tuple pattern");
return NULL;
}
@@ -8335,14 +8242,14 @@ namespace Rust {
new AST::TuplePattern(::std::move(items), paren_locus));
} else {
// some kind of error
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"failed to parse tuple pattern (probably) or maybe grouped pattern");
return NULL;
}
}
default:
// error
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unrecognised token '%s' in grouped or tuple pattern after first pattern",
t->get_token_description());
return NULL;
@@ -8351,13 +8258,13 @@ namespace Rust {
// Parses a slice pattern that can match arrays or slices. Parses the square brackets too.
::std::unique_ptr<AST::SlicePattern> Parser::parse_slice_pattern() {
- location_t square_locus = lexer.peek_token()->get_locus();
+ Location square_locus = lexer.peek_token()->get_locus();
skip_token(LEFT_SQUARE);
// parse initial pattern (required)
::std::unique_ptr<AST::Pattern> initial_pattern = parse_pattern();
if (initial_pattern == NULL) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse initial pattern in slice pattern");
return NULL;
}
@@ -8377,7 +8284,7 @@ namespace Rust {
// parse pattern (required)
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse pattern in slice pattern");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse pattern in slice pattern");
return NULL;
}
patterns.push_back(::std::move(pattern));
@@ -8395,7 +8302,7 @@ namespace Rust {
// Parses an identifier pattern (pattern that binds a value matched to a variable).
::std::unique_ptr<AST::IdentifierPattern> Parser::parse_identifier_pattern() {
- location_t locus = lexer.peek_token()->get_locus();
+ Location locus = lexer.peek_token()->get_locus();
bool has_ref = false;
if (lexer.peek_token()->get_id() == REF) {
@@ -8431,7 +8338,7 @@ namespace Rust {
// parse required pattern to bind
bind_pattern = parse_pattern();
if (bind_pattern == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse pattern to bind in identifier pattern\n");
return NULL;
}
@@ -8476,7 +8383,7 @@ namespace Rust {
// parse items
::std::unique_ptr<AST::TupleStructItems> items = parse_tuple_struct_items();
if (items == NULL) {
- error_at(lexer.peek_token()->get_locus(), "failed to parse tuple struct items");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse tuple struct items");
return NULL;
}
@@ -8521,8 +8428,13 @@ namespace Rust {
new AST::RangePatternBoundPath(::std::move(path)));
::std::unique_ptr<AST::RangePatternBound> upper_bound = parse_range_pattern_bound();
- return ::std::unique_ptr<AST::RangePattern>(new AST::RangePattern(
- ::std::move(lower_bound), ::std::move(upper_bound), has_ellipsis_syntax));
+ return ::std::unique_ptr<AST::RangePattern>(
+ new AST::RangePattern(
+ ::std::move(lower_bound),
+ ::std::move(upper_bound),
+ Linemap::unknown_location(),
+ has_ellipsis_syntax)
+ );
}
case PATTERN_BIND: {
// only allow on single-segment paths
@@ -8532,7 +8444,7 @@ namespace Rust {
::std::unique_ptr<AST::Pattern> bind_pattern = parse_pattern();
if (bind_pattern == NULL) {
- error_at(
+ rust_error_at(
t->get_locus(), "failed to parse pattern to bind to identifier pattern");
return NULL;
}
@@ -8540,7 +8452,7 @@ namespace Rust {
new AST::IdentifierPattern(::std::move(initial_ident), initial_tok->get_locus(),
false, false, ::std::move(bind_pattern)));
}
- error_at(t->get_locus(), "failed to parse pattern bind to a path, not an identifier");
+ rust_error_at(t->get_locus(), "failed to parse pattern bind to a path, not an identifier");
return NULL;
}
default:
@@ -8584,7 +8496,7 @@ namespace Rust {
// parse pattern, which is now required
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse pattern in tuple struct items");
return NULL;
}
@@ -8610,7 +8522,7 @@ namespace Rust {
// parse pattern, which is required
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(t->get_locus(), "failed to parse pattern in tuple struct items");
+ rust_error_at(t->get_locus(), "failed to parse pattern in tuple struct items");
return NULL;
}
lower_patterns.push_back(::std::move(pattern));
@@ -8653,7 +8565,7 @@ namespace Rust {
// parse pattern, which is required
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse pattern in tuple struct items");
return NULL;
}
@@ -8667,7 +8579,7 @@ namespace Rust {
}
default:
// error
- error_at(t->get_locus(), "unexpected token '%s' in tuple struct items",
+ rust_error_at(t->get_locus(), "unexpected token '%s' in tuple struct items",
t->get_token_description());
return NULL;
}
@@ -8738,7 +8650,7 @@ namespace Rust {
// parse required pattern
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(
+ rust_error_at(
t->get_locus(), "failed to parse pattern in tuple index struct pattern field");
return NULL;
}
@@ -8761,7 +8673,7 @@ namespace Rust {
// parse required pattern
::std::unique_ptr<AST::Pattern> pattern = parse_pattern();
if (pattern == NULL) {
- error_at(
+ rust_error_at(
t->get_locus(), "failed to parse pattern in struct pattern field");
return NULL;
}
@@ -8782,7 +8694,7 @@ namespace Rust {
}
default:
// error
- error_at(t->get_locus(), "unrecognised token '%s' in struct pattern field",
+ rust_error_at(t->get_locus(), "unrecognised token '%s' in struct pattern field",
t->get_token_description());
return NULL;
}
@@ -8899,7 +8811,7 @@ namespace Rust {
return ExprOrStmt(::std::move(item));
}
default:
- error_at(t2->get_locus(),
+ rust_error_at(t2->get_locus(),
"unrecognised token '%s' after parsing unsafe - expected beginning of "
"expression or statement",
t->get_token_description());
@@ -9033,7 +8945,7 @@ namespace Rust {
// Parses a statement or expression beginning with a path (i.e. macro, struct/enum, or path expr)
ExprOrStmt Parser::parse_path_based_stmt_or_expr(::std::vector<AST::Attribute> outer_attrs) {
// attempt to parse path
- location_t stmt_or_expr_loc = lexer.peek_token()->get_locus();
+ Location stmt_or_expr_loc = lexer.peek_token()->get_locus();
AST::PathInExpression path = parse_path_in_expression();
// branch on next token
@@ -9045,7 +8957,7 @@ namespace Rust {
// macros)
AST::SimplePath macro_path = path.as_simple_path();
if (macro_path.is_empty()) {
- error_at(t2->get_locus(), "failed to convert parsed path to simple "
+ rust_error_at(t2->get_locus(), "failed to convert parsed path to simple "
"path (for macro invocation or semi)");
return ExprOrStmt::create_error();
}
@@ -9054,7 +8966,7 @@ namespace Rust {
lexer.skip_token();
const_TokenPtr t3 = lexer.peek_token();
- location_t tok_tree_loc = t3->get_locus();
+ Location tok_tree_loc = t3->get_locus();
AST::DelimType type = AST::PARENS;
switch (t3->get_id()) {
@@ -9068,7 +8980,7 @@ namespace Rust {
type = AST::CURLY;
break;
default:
- error_at(t3->get_locus(),
+ rust_error_at(t3->get_locus(),
"unrecognised token '%s' in macro invocation - (opening) "
"delimiter expected",
t3->get_token_description());
@@ -9085,7 +8997,7 @@ namespace Rust {
::std::unique_ptr<AST::TokenTree> tree = parse_token_tree();
if (tree == NULL) {
- error_at(t3->get_locus(),
+ rust_error_at(t3->get_locus(),
"failed to parse token tree for macro invocation (or semi) - "
"found "
"'%s'",
@@ -9129,7 +9041,7 @@ namespace Rust {
return ExprOrStmt(::std::move(expr));
} else {
// tokens don't match opening delimiters, so produce error
- error_at(t2->get_locus(),
+ rust_error_at(t2->get_locus(),
"unexpected token '%s' - expecting closing delimiter '%s' (for a "
"macro invocation)",
t2->get_token_description(),
@@ -9157,7 +9069,7 @@ namespace Rust {
expr
= parse_struct_expr_struct_partial(::std::move(path), ::std::move(outer_attrs));
if (expr == NULL) {
- error_at(t2->get_locus(), "failed to parse struct expr struct");
+ rust_error_at(t2->get_locus(), "failed to parse struct expr struct");
return ExprOrStmt::create_error();
}
} else {
@@ -9188,7 +9100,7 @@ namespace Rust {
::std::unique_ptr<AST::StructExprTuple> struct_expr
= parse_struct_expr_tuple_partial(::std::move(path), ::std::move(outer_attrs));
if (struct_expr == NULL) {
- error_at(t2->get_locus(), "failed to parse struct expr tuple");
+ rust_error_at(t2->get_locus(), "failed to parse struct expr tuple");
return ExprOrStmt::create_error();
}
@@ -9242,7 +9154,7 @@ namespace Rust {
// parse expression (required)
::std::unique_ptr<AST::Expr> expr = parse_expr();
if (expr == NULL) {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"failed to parse struct expression field with identifier and expression");
return NULL;
}
@@ -9276,7 +9188,7 @@ namespace Rust {
// parse field expression (required)
::std::unique_ptr<AST::Expr> expr = parse_expr();
if (expr == NULL) {
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"failed to parse expr in struct (or enum) expr field with tuple index");
return NULL;
}
@@ -9299,7 +9211,7 @@ namespace Rust {
// DEBUG:
fprintf(stderr, "struct/enum expr field parsing failed - unrecognised char \n");
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unrecognised token '%s' as first token of struct expr field - expected identifier "
"or int literal",
t->get_token_description());
@@ -9309,10 +9221,10 @@ namespace Rust {
// Parses a macro invocation or macro invocation semi.
ExprOrStmt Parser::parse_macro_invocation_maybe_semi(::std::vector<AST::Attribute> outer_attrs) {
- location_t macro_locus = lexer.peek_token()->get_locus();
+ Location macro_locus = lexer.peek_token()->get_locus();
AST::SimplePath macro_path = parse_simple_path();
if (macro_path.is_empty()) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse simple path in macro invocation or semi");
return ExprOrStmt::create_error();
}
@@ -9322,7 +9234,7 @@ namespace Rust {
}
const_TokenPtr t3 = lexer.peek_token();
- location_t tok_tree_loc = t3->get_locus();
+ Location tok_tree_loc = t3->get_locus();
AST::DelimType type = AST::PARENS;
switch (t3->get_id()) {
@@ -9336,7 +9248,7 @@ namespace Rust {
type = AST::CURLY;
break;
default:
- error_at(t3->get_locus(),
+ rust_error_at(t3->get_locus(),
"unrecognised token '%s' in macro invocation - (opening) "
"delimiter expected",
t3->get_token_description());
@@ -9353,7 +9265,7 @@ namespace Rust {
::std::unique_ptr<AST::TokenTree> tree = parse_token_tree();
if (tree == NULL) {
- error_at(t3->get_locus(),
+ rust_error_at(t3->get_locus(),
"failed to parse token tree for macro invocation (or semi) - found '%s'",
t3->get_token_description());
return ExprOrStmt::create_error();
@@ -9396,7 +9308,7 @@ namespace Rust {
} else {
const_TokenPtr t = lexer.peek_token();
// tokens don't match opening delimiters, so produce error
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unexpected token '%s' - expecting closing delimiter '%s' (for a "
"macro invocation)",
t->get_token_description(),
@@ -9407,7 +9319,7 @@ namespace Rust {
// "Unexpected token" panic mode - flags gcc error at unexpected token
void Parser::unexpected_token(const_TokenPtr t) {
- ::error_at(t->get_locus(), "unexpected %s\n", t->get_token_description());
+ ::rust_error_at(t->get_locus(), "unexpected %s\n", t->get_token_description());
}
// Crappy "error recovery" performed after error by skipping tokens until a semi-colon is found
@@ -9423,71 +9335,6 @@ namespace Rust {
lexer.skip_token();
}
-#if 0
- // Parses a variable declaration statement.
- Tree Parser::parse_variable_declaration() {
- // skip initial var keyword - TODO: fix
- if (!skip_token(/*VAR*/ COLON)) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- // keep identifier token as used later
- const_TokenPtr identifier = expect_token(IDENTIFIER);
- if (identifier == NULL) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- // skip colon
- if (!skip_token(COLON)) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- // parse the actual type of the variable
- Tree type_tree = parse_type();
-
- if (type_tree.is_error()) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- // skip the semicolon
- skip_token(SEMICOLON);
-
- // check if current mapping of the scope already contains a mapping for identifier
- if (scope.get_current_mapping().get(identifier->get_str())) {
- // create error if this is true
- error_at(identifier->get_locus(), "name %s already declared in this scope",
- identifier->get_str().c_str());
- return Tree::error();
- }
-
- // create a new symbol using the given identifier
- SymbolPtr sym(new Symbol(VARIABLE, identifier->get_str()));
- // put new symbol into scope mapping
- scope.get_current_mapping().insert(sym);
-
- // create GENERIC tree for variable declaration
- Tree decl = build_decl(identifier->get_locus(), VAR_DECL,
- get_identifier(sym->get_name().c_str()), type_tree.get_tree());
- // set decl_context of decl to main function (make it local variable of main function)
- DECL_CONTEXT(decl.get_tree()) = main_fndecl;
-
- // keep VAR_DECL tree in top list of stack_var_decl_chain stack for block purposes
- gcc_assert(!stack_var_decl_chain.empty());
- stack_var_decl_chain.back().append(decl);
-
- // associate new symbol with VAR_DECL tree
- sym->set_tree_decl(decl);
-
- Tree stmt = build_tree(DECL_EXPR, identifier->get_locus(), void_type_node, decl);
-
- return stmt;
- }
-#endif
-
/* Checks if current token has inputted id - skips it and returns true if so, diagnoses an error
* and returns false otherwise. */
bool Parser::skip_token(TokenId token_id) {
@@ -9502,236 +9349,13 @@ namespace Rust {
lexer.skip_token();
return t;
} else {
- error_at(t->get_locus(), "expecting %s but %s found!\n", get_token_description(token_id),
+ rust_error_at(t->get_locus(), "expecting %s but %s found!\n", get_token_description(token_id),
t->get_token_description());
return const_TokenPtr();
}
}
-#if 0
- // Parses type in variable declaration.
- Tree Parser::parse_type() {
- const_TokenPtr t = lexer.peek_token();
-
- Tree type;
-
- switch (t->get_id()) {
- // TODO: fix
- case /*INT*/ COLON:
- lexer.skip_token();
- type = integer_type_node;
- break;
- case /*FLOAT*/ ELLIPSIS:
- lexer.skip_token();
- type = float_type_node;
- break;
- case /*BOOL*/ BREAK:
- lexer.skip_token();
- type = boolean_type_node;
- break;
- case IDENTIFIER: {
- SymbolPtr s = query_type(t->get_str(), t->get_locus());
- lexer.skip_token();
-
- if (s == NULL)
- type = Tree::error();
- else {
- type = TREE_TYPE(s->get_tree_decl().get_tree());
- }
- } break;
- case /*RECORD*/ DOT:
- type = parse_record();
- break;
- default:
- unexpected_token(t);
- return Tree::error();
- break;
- }
-
- // start parsing index ranges: list of expression pairs (lower and upper indexes of array)
- typedef std::vector<std::pair<Tree, Tree> > Dimensions;
- Dimensions dimensions;
-
- t = lexer.peek_token();
- while (t->get_id() == LEFT_PAREN || t->get_id() == LEFT_SQUARE) {
- lexer.skip_token();
-
- // array bounds
- Tree lower_bound, upper_bound;
-
- if (t->get_id() == LEFT_SQUARE) {
- // for array of form [e]
- Tree size = parse_integer_expression();
- skip_token(RIGHT_SQUARE);
-
- lower_bound = Tree(build_int_cst_type(integer_type_node, 0), size.get_locus());
-
- // set upper to e - 1
- upper_bound = build_tree(MINUS_EXPR, size.get_locus(), integer_type_node, size,
- build_int_cst(integer_type_node, 1));
- } else if (t->get_id() == LEFT_PAREN) {
- // for array of form [e0:e1]
- // parse e0
- lower_bound = parse_integer_expression();
- skip_token(COLON);
-
- // parse e1
- upper_bound = parse_integer_expression();
- skip_token(RIGHT_PAREN);
- } else {
- gcc_unreachable();
- }
-
- dimensions.push_back(std::make_pair(lower_bound, upper_bound));
- t = lexer.peek_token();
- }
-
- // start building array type
- // transverse list in reverse order
- for (Dimensions::reverse_iterator it = dimensions.rbegin(); it != dimensions.rend(); it++) {
- // fold lower and upper expressions (simplify expressions if possible)
- it->first = Tree(fold(it->first.get_tree()), it->first.get_locus());
- it->second = Tree(fold(it->second.get_tree()), it->second.get_locus());
-
- if (!type.is_error()) {
- // build GCC range type using lower and upper
- Tree range_type
- = build_range_type(integer_type_node, it->first.get_tree(), it->second.get_tree());
- // build array type
- type = build_array_type(type.get_tree(), range_type.get_tree());
- }
- }
-
- return type;
- }
-#endif
-
- // Parses an if statement. Probably important to study as it seems complex.
- Tree Parser::parse_if_statement() {
- // skip if statement token
- if (!skip_token(IF)) {
- skip_after_end();
- return Tree::error();
- }
-
- // parse expression in statement body
- Tree expr = parse_boolean_expression();
-
- // skip the "THEN" after expression
- skip_token(LEFT_CURLY);
-
- // enter new block scope
- enter_scope();
- // parse statement sequence? inside if body. Finish at "end if" or "else"
- parse_statement_seq(&Parser::done_end_or_else);
-
- TreeSymbolMapping then_tree_scope = leave_scope();
- Tree then_stmt = then_tree_scope.bind_expr;
-
- Tree else_stmt;
- const_TokenPtr tok = lexer.peek_token();
- // if there is an else, parse statement seq inside its body too
- if (tok->get_id() == ELSE) {
- // Consume 'else'
- skip_token(ELSE);
-
- // enter block scope
- enter_scope();
- parse_statement_seq(&Parser::done_end);
- TreeSymbolMapping else_tree_scope = leave_scope();
- else_stmt = else_tree_scope.bind_expr;
-
- // Consume 'end'
- skip_token(RIGHT_CURLY);
- } else if (tok->get_id() == RIGHT_CURLY) {
- // Consume 'end'
- skip_token(RIGHT_CURLY);
- } else {
- unexpected_token(tok);
- return Tree::error();
- }
-
- // build GENERIC if statement node.
- return build_if_statement(expr, then_stmt, else_stmt);
- }
-
- // Builds an if statement tree.
- Tree Parser::build_if_statement(Tree bool_expr, Tree then_part, Tree else_part) {
- if (bool_expr.is_error())
- return bool_expr;
-
- // create then label declaration tree
- Tree then_label_decl = build_label_decl("then", then_part.get_locus());
-
- // create else label declaration if it exists
- Tree else_label_decl;
- if (!else_part.is_null())
- else_label_decl = build_label_decl("else", else_part.get_locus());
-
- // create endif label declaration
- Tree endif_label_decl = build_label_decl("end_if", then_part.get_locus());
-
- // create goto expressions for entering "if" branch, "else" branch, and code after if block
- Tree goto_then
- = build_tree(GOTO_EXPR, bool_expr.get_locus(), void_type_node, then_label_decl);
- Tree goto_endif
- = build_tree(GOTO_EXPR, bool_expr.get_locus(), void_type_node, endif_label_decl);
-
- Tree goto_else_or_endif;
- if (!else_part.is_null())
- goto_else_or_endif
- = build_tree(GOTO_EXPR, bool_expr.get_locus(), void_type_node, else_label_decl);
- else
- goto_else_or_endif = goto_endif;
-
- // create statement list for if statement which will have required statements appended
- TreeStmtList stmt_list;
-
- // create conditional branch expression and append to stmt_list
- Tree cond_expr = build_tree(
- COND_EXPR, bool_expr.get_locus(), void_type_node, bool_expr, goto_then, goto_else_or_endif);
- stmt_list.append(cond_expr);
-
- // define location related to "then" part and append to stmt_list
- Tree then_label_expr
- = build_tree(LABEL_EXPR, then_part.get_locus(), void_type_node, then_label_decl);
- stmt_list.append(then_label_expr);
-
- // append parameter "then_part" to statement list
- stmt_list.append(then_part);
-
- // if else part exists, append a goto endif
- if (!else_part.is_null()) {
- // Make sure after then part has been executed we go to the end if
- stmt_list.append(goto_endif);
-
- // define location of else label, append it, and append else_part parameter tree
- Tree else_label_expr
- = build_tree(LABEL_EXPR, else_part.get_locus(), void_type_node, else_label_decl);
- stmt_list.append(else_label_expr);
- stmt_list.append(else_part);
- // do not need to jump to endif as handled implicitly here
- }
-
- // define label for endif, append to statement list
- Tree endif_label_expr
- = build_tree(LABEL_EXPR, UNKNOWN_LOCATION, void_type_node, endif_label_decl);
- stmt_list.append(endif_label_expr);
-
- // return the statement list in tree form
- return stmt_list.get_tree();
- }
-
- // Builds a GENERIC tree LABEL_DECL (represents a label, as in a "goto" label).
- Tree Parser::build_label_decl(const char* name, location_t loc) {
- tree t = build_decl(loc, LABEL_DECL, get_identifier(name), void_type_node);
-
- gcc_assert(main_fndecl != NULL_TREE);
- DECL_CONTEXT(t) = main_fndecl;
-
- return t;
- }
// Skips all tokens until EOF or }. Don't use.
void Parser::skip_after_end() {
@@ -9873,64 +9497,7 @@ namespace Rust {
return parse_expr(LBP_LOWEST, ::std::move(outer_attrs), restrictions);
}
- // Pratt parser impl of parse_expression.
- Tree Parser::parse_expression(int right_binding_power) {
- const_TokenPtr current_token = lexer.peek_token();
- lexer.skip_token();
-
- Tree expr = null_denotation(current_token);
-
- if (expr.is_error()) {
- return Tree::error();
- }
- // stop parsing if find lower priority token - parse higher priority first
- while (right_binding_power < left_binding_power(lexer.peek_token())) {
- current_token = lexer.peek_token();
- lexer.skip_token();
-
- expr = left_denotation(current_token, expr);
- if (expr.is_error())
- return Tree::error();
- }
-
- return expr;
- }
-
- // Parse an expression with lowest left binding power.
- Tree Parser::parse_expression() {
- return parse_expression(LBP_LOWEST);
- }
-
- // Parses a boolean expression (basically parses expression and ensures boolean result).
- Tree Parser::parse_boolean_expression() {
- Tree expr = parse_expression();
- if (expr.is_error())
- return expr;
-
- if (expr.get_type() != boolean_type_node) {
- error_at(expr.get_locus(), "expected expression of boolean type but its type is %s",
- print_type(expr.get_type()));
- return Tree::error();
- }
-
- return expr;
- }
-
- // Parses an integer expression (basically parses expression and ensures integer result).
- Tree Parser::parse_integer_expression() {
- Tree expr = parse_expression();
- if (expr.is_error())
- return expr;
-
- if (expr.get_type() != integer_type_node) {
- error_at(expr.get_locus(), "expected expression of integer type but its type is %s",
- print_type(expr.get_type()));
- return Tree::error();
- }
-
- return expr;
- }
/* Determines action to take when finding token at beginning of expression.
* FIXME: this may only apply to precedence-capable expressions (which are all expressions without
@@ -9949,7 +9516,7 @@ namespace Rust {
// when encountering identifier, lookup in scope
SymbolPtr s = scope.lookup(tok->get_str());
if (s == NULL) {
- error_at(tok->get_locus(), "variable '%s' not declared in the current scope",
+ rust_error_at(tok->get_locus(), "variable '%s' not declared in the current scope",
tok->get_str().c_str());
return Tree::error();
@@ -10089,7 +9656,7 @@ namespace Rust {
// end of expression must be a close-bracket
if (tok->get_id() != RIGHT_PAREN)
- error_at(
+ rust_error_at(
tok->get_locus(), "expecting ')' but %s found\n", tok->get_token_description());
else
lexer.skip_token();
@@ -10108,7 +9675,7 @@ namespace Rust {
return NULL;
// can only apply to integer and float expressions
if (expr->get_type() != integer_type_node || expr->get_type() != float_type_node) {
- error_at(tok->get_locus(),
+ rust_error_at(tok->get_locus(),
"operand of unary plus must be int or float but it is %s",
print_type(expr->get_type()));
return NULL;
@@ -10127,7 +9694,7 @@ namespace Rust {
return NULL;
// can only apply to integer and float expressions
/*if (expr.get_type() != integer_type_node || expr.get_type() != float_type_node) {
- error_at(tok->get_locus(),
+ rust_error_at(tok->get_locus(),
"operand of unary minus must be int or float but it is %s",
print_type(expr.get_type()));
return Tree::error();
@@ -10151,7 +9718,7 @@ namespace Rust {
return NULL;
// can only apply to boolean expressions
/*if (expr.get_type() != boolean_type_node) {
- error_at(tok->get_locus(),
+ rust_error_at(tok->get_locus(),
"operand of logical not must be a boolean but it is %s",
print_type(expr.get_type()));
return Tree::error();
@@ -10223,7 +9790,7 @@ namespace Rust {
}
case SCOPE_RESOLUTION: {
// TODO: fix: this is for global paths, i.e. ::std::string::whatever
- error_at(tok->get_locus(), "found null denotation scope resolution operator, and "
+ rust_error_at(tok->get_locus(), "found null denotation scope resolution operator, and "
"haven't written handling for it.");
return NULL;
}
@@ -10331,7 +9898,7 @@ namespace Rust {
// array definition expr (not indexing)
return parse_array_expr(::std::move(outer_attrs), true);
default:
- error_at(tok->get_locus(), "found unexpected token '%s' in null denotation",
+ rust_error_at(tok->get_locus(), "found unexpected token '%s' in null denotation",
tok->get_token_description());
return NULL;
}
@@ -10357,7 +9924,7 @@ namespace Rust {
switch (tok->get_id()) {
// FIXME: allow for outer attributes to be applied
case QUESTION_MARK: {
- location_t left_locus = left->get_locus_slow();
+ Location left_locus = left->get_locus_slow();
// error propagation expression - unary postfix
return ::std::unique_ptr<AST::ErrorPropagationExpr>(new AST::ErrorPropagationExpr(
::std::move(left), ::std::move(outer_attrs), left_locus));
@@ -10494,7 +10061,7 @@ namespace Rust {
tok, ::std::move(left), ::std::move(outer_attrs), restrictions);
case SCOPE_RESOLUTION:
// path expression - binary infix? FIXME should this even be parsed here?
- error_at(tok->get_locus(), "found scope resolution operator in left denotation "
+ rust_error_at(tok->get_locus(), "found scope resolution operator in left denotation "
"function - this should probably be handled elsewhere.");
return NULL;
case DOT: {
@@ -10536,7 +10103,7 @@ namespace Rust {
return parse_tuple_index_expr_float(
tok, ::std::move(left), ::std::move(outer_attrs), restrictions);
default:
- error_at(tok->get_locus(), "found unexpected token '%s' in left denotation",
+ rust_error_at(tok->get_locus(), "found unexpected token '%s' in left denotation",
tok->get_token_description());
return NULL;
}
@@ -10553,7 +10120,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ArithmeticOrLogicalExpr>(new AST::ArithmeticOrLogicalExpr(
::std::move(left), ::std::move(right), AST::ArithmeticOrLogicalExpr::ADD, locus));
@@ -10570,7 +10137,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ArithmeticOrLogicalExpr>(new AST::ArithmeticOrLogicalExpr(
::std::move(left), ::std::move(right), AST::ArithmeticOrLogicalExpr::SUBTRACT, locus));
@@ -10587,7 +10154,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ArithmeticOrLogicalExpr>(new AST::ArithmeticOrLogicalExpr(
::std::move(left), ::std::move(right), AST::ArithmeticOrLogicalExpr::MULTIPLY, locus));
@@ -10604,7 +10171,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ArithmeticOrLogicalExpr>(new AST::ArithmeticOrLogicalExpr(
::std::move(left), ::std::move(right), AST::ArithmeticOrLogicalExpr::DIVIDE, locus));
@@ -10621,7 +10188,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ArithmeticOrLogicalExpr>(new AST::ArithmeticOrLogicalExpr(
::std::move(left), ::std::move(right), AST::ArithmeticOrLogicalExpr::MODULUS, locus));
@@ -10638,7 +10205,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ArithmeticOrLogicalExpr>(new AST::ArithmeticOrLogicalExpr(
::std::move(left), ::std::move(right), AST::ArithmeticOrLogicalExpr::BITWISE_AND, locus));
@@ -10655,7 +10222,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ArithmeticOrLogicalExpr>(new AST::ArithmeticOrLogicalExpr(
::std::move(left), ::std::move(right), AST::ArithmeticOrLogicalExpr::BITWISE_OR, locus));
@@ -10672,7 +10239,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ArithmeticOrLogicalExpr>(new AST::ArithmeticOrLogicalExpr(
::std::move(left), ::std::move(right), AST::ArithmeticOrLogicalExpr::BITWISE_XOR, locus));
@@ -10689,7 +10256,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ArithmeticOrLogicalExpr>(new AST::ArithmeticOrLogicalExpr(
::std::move(left), ::std::move(right), AST::ArithmeticOrLogicalExpr::LEFT_SHIFT, locus));
@@ -10706,7 +10273,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ArithmeticOrLogicalExpr>(new AST::ArithmeticOrLogicalExpr(
::std::move(left), ::std::move(right), AST::ArithmeticOrLogicalExpr::RIGHT_SHIFT, locus));
@@ -10723,7 +10290,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ComparisonExpr>(new AST::ComparisonExpr(
::std::move(left), ::std::move(right), AST::ComparisonExpr::EQUAL, locus));
@@ -10740,7 +10307,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ComparisonExpr>(new AST::ComparisonExpr(
::std::move(left), ::std::move(right), AST::ComparisonExpr::NOT_EQUAL, locus));
@@ -10757,7 +10324,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ComparisonExpr>(new AST::ComparisonExpr(
::std::move(left), ::std::move(right), AST::ComparisonExpr::GREATER_THAN, locus));
@@ -10774,7 +10341,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ComparisonExpr>(new AST::ComparisonExpr(
::std::move(left), ::std::move(right), AST::ComparisonExpr::LESS_THAN, locus));
@@ -10791,7 +10358,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ComparisonExpr>(new AST::ComparisonExpr(
::std::move(left), ::std::move(right), AST::ComparisonExpr::GREATER_OR_EQUAL, locus));
@@ -10808,7 +10375,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::ComparisonExpr>(new AST::ComparisonExpr(
::std::move(left), ::std::move(right), AST::ComparisonExpr::LESS_OR_EQUAL, locus));
@@ -10825,7 +10392,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::LazyBooleanExpr>(new AST::LazyBooleanExpr(
::std::move(left), ::std::move(right), AST::LazyBooleanExpr::LOGICAL_OR, locus));
@@ -10842,7 +10409,7 @@ namespace Rust {
return NULL;
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::LazyBooleanExpr>(new AST::LazyBooleanExpr(
::std::move(left), ::std::move(right), AST::LazyBooleanExpr::LOGICAL_AND, locus));
@@ -10860,7 +10427,7 @@ namespace Rust {
// FIXME: how do I get precedence put in here?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = expr_to_cast->get_locus_slow();
+ Location locus = expr_to_cast->get_locus_slow();
return ::std::unique_ptr<AST::TypeCastExpr>(
new AST::TypeCastExpr(::std::move(expr_to_cast), ::std::move(type), locus));
@@ -10878,7 +10445,7 @@ namespace Rust {
// FIXME: ensure right-associativity for this - 'LBP - 1' may do this?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::AssignmentExpr>(
new AST::AssignmentExpr(::std::move(left), ::std::move(right), locus));
@@ -10896,7 +10463,7 @@ namespace Rust {
// FIXME: ensure right-associativity for this - 'LBP - 1' may do this?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::CompoundAssignmentExpr>(new AST::CompoundAssignmentExpr(
::std::move(left), ::std::move(right), AST::CompoundAssignmentExpr::ADD, locus));
@@ -10914,7 +10481,7 @@ namespace Rust {
// FIXME: ensure right-associativity for this - 'LBP - 1' may do this?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::CompoundAssignmentExpr>(new AST::CompoundAssignmentExpr(
::std::move(left), ::std::move(right), AST::CompoundAssignmentExpr::SUBTRACT, locus));
@@ -10932,7 +10499,7 @@ namespace Rust {
// FIXME: ensure right-associativity for this - 'LBP - 1' may do this?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::CompoundAssignmentExpr>(new AST::CompoundAssignmentExpr(
::std::move(left), ::std::move(right), AST::CompoundAssignmentExpr::MULTIPLY, locus));
@@ -10950,7 +10517,7 @@ namespace Rust {
// FIXME: ensure right-associativity for this - 'LBP - 1' may do this?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::CompoundAssignmentExpr>(new AST::CompoundAssignmentExpr(
::std::move(left), ::std::move(right), AST::CompoundAssignmentExpr::DIVIDE, locus));
@@ -10968,7 +10535,7 @@ namespace Rust {
// FIXME: ensure right-associativity for this - 'LBP - 1' may do this?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::CompoundAssignmentExpr>(new AST::CompoundAssignmentExpr(
::std::move(left), ::std::move(right), AST::CompoundAssignmentExpr::MODULUS, locus));
@@ -10986,7 +10553,7 @@ namespace Rust {
// FIXME: ensure right-associativity for this - 'LBP - 1' may do this?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::CompoundAssignmentExpr>(new AST::CompoundAssignmentExpr(
::std::move(left), ::std::move(right), AST::CompoundAssignmentExpr::BITWISE_AND, locus));
@@ -11004,7 +10571,7 @@ namespace Rust {
// FIXME: ensure right-associativity for this - 'LBP - 1' may do this?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::CompoundAssignmentExpr>(new AST::CompoundAssignmentExpr(
::std::move(left), ::std::move(right), AST::CompoundAssignmentExpr::BITWISE_OR, locus));
@@ -11022,7 +10589,7 @@ namespace Rust {
// FIXME: ensure right-associativity for this - 'LBP - 1' may do this?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::CompoundAssignmentExpr>(new AST::CompoundAssignmentExpr(
::std::move(left), ::std::move(right), AST::CompoundAssignmentExpr::BITWISE_XOR, locus));
@@ -11040,7 +10607,7 @@ namespace Rust {
// FIXME: ensure right-associativity for this - 'LBP - 1' may do this?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::CompoundAssignmentExpr>(new AST::CompoundAssignmentExpr(
::std::move(left), ::std::move(right), AST::CompoundAssignmentExpr::LEFT_SHIFT, locus));
@@ -11058,7 +10625,7 @@ namespace Rust {
// FIXME: ensure right-associativity for this - 'LBP - 1' may do this?
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::CompoundAssignmentExpr>(new AST::CompoundAssignmentExpr(
::std::move(left), ::std::move(right), AST::CompoundAssignmentExpr::RIGHT_SHIFT, locus));
@@ -11070,14 +10637,14 @@ namespace Rust {
// skip "await" identifier (as "." has already been consumed in parse_expression)
// this assumes that the identifier was already identified as await
if (!skip_token(IDENTIFIER)) {
- error_at(tok->get_locus(),
+ rust_error_at(tok->get_locus(),
"failed to skip 'await' in await expr - this is probably a deep issue.");
// skip somewhere?
return NULL;
}
// TODO: check inside async block in semantic analysis
- location_t locus = expr_to_await->get_locus_slow();
+ Location locus = expr_to_await->get_locus_slow();
return ::std::unique_ptr<AST::AwaitExpr>(
new AST::AwaitExpr(::std::move(expr_to_await), ::std::move(outer_attrs), locus));
@@ -11093,7 +10660,7 @@ namespace Rust {
::std::unique_ptr<AST::Expr> right
= parse_expr(LBP_DOT_DOT, ::std::vector<AST::Attribute>(), restrictions);
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
if (right == NULL) {
// range from expr
@@ -11114,7 +10681,7 @@ namespace Rust {
// try parsing RHS (as tok has already been consumed in parse_expression)
::std::unique_ptr<AST::Expr> right = parse_expr(LBP_DOT_DOT, ::std::vector<AST::Attribute>());
- location_t locus = tok->get_locus();
+ Location locus = tok->get_locus();
if (right == NULL) {
// range from expr
@@ -11138,7 +10705,7 @@ namespace Rust {
// FIXME: make non-associative
// TODO: check types. actually, do so during semantic analysis
- location_t locus = left->get_locus_slow();
+ Location locus = left->get_locus_slow();
return ::std::unique_ptr<AST::RangeFromToInclExpr>(
new AST::RangeFromToInclExpr(::std::move(left), ::std::move(right), locus));
@@ -11173,7 +10740,7 @@ namespace Rust {
// convert to integer
int index_int = atoi(index.c_str());
- location_t locus = tuple_expr->get_locus_slow();
+ Location locus = tuple_expr->get_locus_slow();
return ::std::unique_ptr<AST::TupleIndexExpr>(new AST::TupleIndexExpr(
::std::move(tuple_expr), index_int, ::std::move(outer_attrs), locus));
@@ -11196,7 +10763,7 @@ namespace Rust {
}
// TODO: check types. actually, do so during semantic analysis
- location_t locus = array_expr->get_locus_slow();
+ Location locus = array_expr->get_locus_slow();
return ::std::unique_ptr<AST::ArrayIndexExpr>(new AST::ArrayIndexExpr(
::std::move(array_expr), ::std::move(index_expr), ::std::move(outer_attrs), locus));
@@ -11210,7 +10777,7 @@ namespace Rust {
const_TokenPtr ident_tok = expect_token(IDENTIFIER);
Identifier ident = ident_tok->get_str();
- location_t locus = struct_expr->get_locus_slow();
+ Location locus = struct_expr->get_locus_slow();
// TODO: check types. actually, do so during semantic analysis
return ::std::unique_ptr<AST::FieldAccessExpr>(new AST::FieldAccessExpr(
@@ -11224,7 +10791,7 @@ namespace Rust {
// parse path expr segment
AST::PathExprSegment segment = parse_path_expr_segment();
if (segment.is_error()) {
- error_at(tok->get_locus(), "failed to parse path expr segment of method call expr");
+ rust_error_at(tok->get_locus(), "failed to parse path expr segment of method call expr");
return NULL;
}
@@ -11240,7 +10807,7 @@ namespace Rust {
while (t->get_id() != RIGHT_PAREN) {
::std::unique_ptr<AST::Expr> param = parse_expr();
if (param == NULL) {
- error_at(t->get_locus(), "failed to parse method param in method call");
+ rust_error_at(t->get_locus(), "failed to parse method param in method call");
return NULL;
}
params.push_back(::std::move(param));
@@ -11259,7 +10826,7 @@ namespace Rust {
}
// TODO: check types. actually do so in semantic analysis pass.
- location_t locus = receiver_expr->get_locus_slow();
+ Location locus = receiver_expr->get_locus_slow();
return ::std::unique_ptr<AST::MethodCallExpr>(
new AST::MethodCallExpr(::std::move(receiver_expr), ::std::move(segment),
@@ -11277,7 +10844,7 @@ namespace Rust {
while (t->get_id() != RIGHT_PAREN) {
::std::unique_ptr<AST::Expr> param = parse_expr();
if (param == NULL) {
- error_at(t->get_locus(), "failed to parse function param in function call");
+ rust_error_at(t->get_locus(), "failed to parse function param in function call");
return NULL;
}
params.push_back(::std::move(param));
@@ -11297,7 +10864,7 @@ namespace Rust {
}
// TODO: check types. actually, do so during semantic analysis
- location_t locus = function_expr->get_locus_slow();
+ Location locus = function_expr->get_locus_slow();
return ::std::unique_ptr<AST::CallExpr>(new AST::CallExpr(
::std::move(function_expr), ::std::move(params), ::std::move(outer_attrs), locus));
@@ -11314,7 +10881,7 @@ namespace Rust {
// convert PathInExpression to SimplePath - if this isn't possible, error
AST::SimplePath converted_path = path.as_simple_path();
if (converted_path.is_empty()) {
- error_at(
+ rust_error_at(
lexer.peek_token()->get_locus(), "failed to parse simple path in macro invocation");
return NULL;
}
@@ -11323,7 +10890,7 @@ namespace Rust {
fprintf(stderr, "successfully parsed macro invocation (via partial)\n");
- location_t macro_locus = converted_path.get_locus();
+ Location macro_locus = converted_path.get_locus();
return ::std::unique_ptr<AST::MacroInvocation>(new AST::MacroInvocation(
::std::move(converted_path), ::std::move(tok_tree), ::std::move(outer_attrs), macro_locus));
@@ -11343,7 +10910,7 @@ namespace Rust {
// branch based on next token
const_TokenPtr t = lexer.peek_token();
- location_t path_locus = path.get_locus();
+ Location path_locus = path.get_locus();
switch (t->get_id()) {
case RIGHT_CURLY:
// struct with no body
@@ -11364,7 +10931,7 @@ namespace Rust {
while (t->get_id() != RIGHT_CURLY && t->get_id() != DOT_DOT) {
::std::unique_ptr<AST::StructExprField> field = parse_struct_expr_field();
if (field == NULL) {
- error_at(t->get_locus(), "failed to parse struct (or enum) expr field");
+ rust_error_at(t->get_locus(), "failed to parse struct (or enum) expr field");
return NULL;
}
@@ -11401,7 +10968,7 @@ namespace Rust {
// parse required struct base expr
::std::unique_ptr<AST::Expr> base_expr = parse_expr();
if (base_expr == NULL) {
- error_at(lexer.peek_token()->get_locus(),
+ rust_error_at(lexer.peek_token()->get_locus(),
"failed to parse struct base expression in struct "
"expression");
return NULL;
@@ -11428,7 +10995,7 @@ namespace Rust {
::std::move(struct_base), ::std::move(inner_attrs), ::std::move(outer_attrs)));
}
default:
- error_at(t->get_locus(),
+ rust_error_at(t->get_locus(),
"unrecognised token '%s' in struct (or enum) expression - "
"expected '}', identifier, int literal, or '..'",
t->get_token_description());
@@ -11452,7 +11019,7 @@ namespace Rust {
// parse expression (required)
::std::unique_ptr<AST::Expr> expr = parse_expr();
if (expr == NULL) {
- error_at(t->get_locus(), "failed to parse expression in struct "
+ rust_error_at(t->get_locus(), "failed to parse expression in struct "
"(or enum) expression tuple");
return NULL;
}
@@ -11470,7 +11037,7 @@ namespace Rust {
return NULL;
}
- location_t path_locus = path.get_locus();
+ Location path_locus = path.get_locus();
return ::std::unique_ptr<AST::StructExprTuple>(new AST::StructExprTuple(::std::move(path),
::std::move(exprs), ::std::move(inner_attrs), ::std::move(outer_attrs), path_locus));
@@ -11513,7 +11080,7 @@ namespace Rust {
}
gcc_fallthrough();
default:
- error_at(tok->get_locus(), "unrecognised token '%s' in path in expression",
+ rust_error_at(tok->get_locus(), "unrecognised token '%s' in path in expression",
tok->get_token_description());
return AST::PathInExpression::create_error();
}
@@ -11554,7 +11121,7 @@ namespace Rust {
AST::PathExprSegment segment = parse_path_expr_segment();
if (segment.is_error()) {
// skip after somewhere?
- error_at(t->get_locus(), "could not parse path expression segment");
+ rust_error_at(t->get_locus(), "could not parse path expression segment");
return AST::PathInExpression::create_error();
}
@@ -11574,7 +11141,7 @@ namespace Rust {
::std::unique_ptr<AST::ClosureExpr> Parser::parse_closure_expr_pratt(
const_TokenPtr tok, ::std::vector<AST::Attribute> outer_attrs) {
// TODO: does this need pratt parsing (for precedence)? probably not, but idk
- location_t locus = tok->get_locus();
+ Location locus = tok->get_locus();
bool has_move = false;
if (tok->get_id() == MOVE) {
has_move = true;
@@ -11598,7 +11165,7 @@ namespace Rust {
AST::ClosureParam param = parse_closure_param();
if (param.is_error()) {
// TODO is this really an error?
- error_at(t->get_locus(), "could not parse closure param");
+ rust_error_at(t->get_locus(), "could not parse closure param");
return NULL;
}
params.push_back(::std::move(param));
@@ -11619,7 +11186,7 @@ namespace Rust {
break;
}
default:
- error_at(tok->get_locus(),
+ rust_error_at(tok->get_locus(),
"unexpected token '%s' in closure expression - expected '|' or '||'",
tok->get_token_description());
// skip somewhere?
@@ -11638,7 +11205,7 @@ namespace Rust {
::std::unique_ptr<AST::TypeNoBounds> type = parse_type_no_bounds();
if (type == NULL) {
// error
- error_at(tok->get_locus(), "failed to parse type for closure");
+ rust_error_at(tok->get_locus(), "failed to parse type for closure");
// skip somewhere?
return NULL;
}
@@ -11647,7 +11214,7 @@ namespace Rust {
::std::unique_ptr<AST::BlockExpr> block = parse_block_expr();
if (block == NULL) {
// error
- error_at(lexer.peek_token()->get_locus(), "failed to parse block expr in closure");
+ rust_error_at(lexer.peek_token()->get_locus(), "failed to parse block expr in closure");
// skip somewhere?
return NULL;
}
@@ -11661,7 +11228,7 @@ namespace Rust {
// parse expr, which is required
::std::unique_ptr<AST::Expr> expr = parse_expr();
if (expr == NULL) {
- error_at(tok->get_locus(), "failed to parse expression in closure");
+ rust_error_at(tok->get_locus(), "failed to parse expression in closure");
// skip somewhere?
return NULL;
}
@@ -11691,1104 +11258,12 @@ namespace Rust {
// get int from string
int index = atoi(index_str.c_str());
- location_t locus = tuple_expr->get_locus_slow();
+ Location locus = tuple_expr->get_locus_slow();
return ::std::unique_ptr<AST::TupleIndexExpr>(
new AST::TupleIndexExpr(::std::move(tuple_expr), index, ::std::move(outer_attrs), locus));
}
- // Determines action to take when finding token at beginning of expression.
- Tree Parser::null_denotation(const_TokenPtr tok) {
- // note: tok is previous character in input stream, not current one, as parse_expression
- // skips it before passing it in
-
- /* as a Pratt parser (which works by decomposing expressions into a null denotation and then a
- * left denotation), null denotations handle primaries and unary operands (but only prefix
- * unary operands) */
-
- switch (tok->get_id()) {
- case IDENTIFIER: {
- // when encountering identifier, lookup in scope
- SymbolPtr s = scope.lookup(tok->get_str());
- if (s == NULL) {
- error_at(tok->get_locus(), "variable '%s' not declared in the current scope",
- tok->get_str().c_str());
-
- return Tree::error();
- }
- // expression is just its VAR_DECL that was stored in the Symbol at declaration
- return Tree(s->get_tree_decl(), tok->get_locus());
- }
- case INT_LITERAL:
- // we should check the range, but ignore for now
- // literal itself encodes value, so token's text has to be interpreted as int. use
- // atoi for this
- return Tree(build_int_cst_type(integer_type_node, atoi(tok->get_str().c_str())),
- tok->get_locus());
- case FLOAT_LITERAL: {
- REAL_VALUE_TYPE float_value;
- // invoke real_from_string3 to get float value representation from string
- real_from_string3(&float_value, tok->get_str().c_str(), TYPE_MODE(float_type_node));
- // this is because machine-dependent
-
- // create actual tree with that built constant value
- return Tree(build_real(float_type_node, float_value), tok->get_locus());
- }
- case STRING_LITERAL: {
- // get c string from token
- std::string str = tok->get_str();
- const char* c_str = str.c_str();
-
- // use GCC's build_string_literal (with null terminator) to create tree
- return Tree(build_string_literal(strlen(c_str) + 1, c_str), tok->get_locus());
- }
- case TRUE_LITERAL: {
- // construct tree with code INTEGER_CST and value 1 but with boolean_type_node
- return Tree(build_int_cst_type(boolean_type_node, 1), tok->get_locus());
- break;
- }
- case FALSE_LITERAL: {
- return Tree(build_int_cst_type(boolean_type_node, 0), tok->get_locus());
- break;
- }
- case LEFT_PAREN: { // have to parse whole expression if inside brackets
- /* recursively invoke parse_expression with lowest priority possible as it it were
- * a top-level expression. */
- Tree expr = parse_expression();
- tok = lexer.peek_token();
-
- // end of expression must be a close-bracket
- if (tok->get_id() != RIGHT_PAREN)
- error_at(
- tok->get_locus(), "expecting ')' but %s found\n", tok->get_token_description());
- else
- lexer.skip_token();
-
- return Tree(expr, tok->get_locus());
- }
- case PLUS: { // unary plus operator
- // invoke parse_expression recursively with appropriate priority, etc. for below
- Tree expr = parse_expression(LBP_UNARY_PLUS);
-
- if (expr.is_error())
- return Tree::error();
- // can only apply to integer and float expressions
- if (expr.get_type() != integer_type_node || expr.get_type() != float_type_node) {
- error_at(tok->get_locus(),
- "operand of unary plus must be int or float but it is %s",
- print_type(expr.get_type()));
- return Tree::error();
- }
-
- return Tree(expr, tok->get_locus());
- }
- case MINUS: { // unary minus - TODO: does not work on unsigned integers
- Tree expr = parse_expression(LBP_UNARY_MINUS);
-
- if (expr.is_error())
- return Tree::error();
- // can only apply to integer and float expressions
- if (expr.get_type() != integer_type_node || expr.get_type() != float_type_node) {
- error_at(tok->get_locus(),
- "operand of unary minus must be int or float but it is %s",
- print_type(expr.get_type()));
- return Tree::error();
- }
-
- // create NEGATE_EXPR tree, which computes negation of operand
- expr = build_tree(NEGATE_EXPR, tok->get_locus(), expr.get_type(), expr);
- return expr;
- }
- case EXCLAM: { // logical not - TODO: this could also be bitwise not
- Tree expr = parse_expression(LBP_UNARY_EXCLAM /*LOGICAL_NOT*/);
-
- if (expr.is_error())
- return Tree::error();
- // can only apply to boolean expressions
- if (expr.get_type() != boolean_type_node) {
- error_at(tok->get_locus(),
- "operand of logical not must be a boolean but it is %s",
- print_type(expr.get_type()));
- return Tree::error();
- }
-
- // create TRUTH_NOT_EXPR tree, which computes logical negation of operand
- expr = build_tree(TRUTH_NOT_EXPR, tok->get_locus(), boolean_type_node, expr);
- return expr;
- }
- case ASTERISK: {
- // TODO: fix: this is pointer dereference only, I think
- Tree expr = parse_expression(LBP_UNARY_ASTERISK);
- return expr;
- }
- case AMP: {
- // TODO: fix: this is reference only, I think
- Tree expr = NULL_TREE;
-
- if (lexer.peek_token()->get_id() == MUT)
- expr = parse_expression(LBP_UNARY_AMP_MUT);
- else
- expr = parse_expression(LBP_UNARY_AMP);
-
- return expr;
- }
- case SCOPE_RESOLUTION: {
- // TODO: fix: this is for global paths, i.e. ::std::string::whatever
- }
- default:
- unexpected_token(tok);
- return Tree::error();
- }
- }
-
- /* Called for each token that can appear in infix (between) position. Can be operators or other
- * punctuation.
- * Returns a function pointer to member function that implements the left denotation for the token
- * given. */
- Tree Parser::left_denotation(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- /*BinaryHandler binary_handler = get_binary_handler(tok->get_id());
- if (binary_handler == NULL) {
- unexpected_token(tok);
- return Tree::error();
- }
-
- return (this->*binary_handler)(tok, left);*/
- return Tree::error();
- }
-
- // Gets method for handling binary operation parsing for specific token type.
- /*Parser::BinaryHandler Parser::get_binary_handler(TokenId id) {
- switch (id) {
-#define BINARY_HANDLER(name, token_id) \
- case token_id: \
- return &Parser::binary_##name;
- BINARY_HANDLER_LIST
-#undef BINARY_HANDLER
- default:
- return NULL;
- }
- }*/
-
- /* Returns the type of the binary operation. May also modify input trees if types do not match,
- * e.g. change a float and int to two floats in addition. */
- Tree Parser::coerce_binary_arithmetic(const_TokenPtr tok, Tree* left, Tree* right) {
- Tree left_type = left->get_type();
- Tree right_type = right->get_type();
-
- // return error if either types are invalid
- if (left_type.is_error() || right_type.is_error())
- return Tree::error();
-
- // good, easy, no type conversion required
- if (left_type == right_type) {
- if (left_type == integer_type_node || left_type == float_type_node) {
- return left_type;
- }
- // dodgy type coercion happening if types don't match but are both numerical
- } else if ((left_type == integer_type_node && right_type == float_type_node)
- || (left_type == float_type_node && right_type == integer_type_node)) {
- // rebuild one tree as float
- if (left_type == integer_type_node) {
- *left = build_tree(FLOAT_EXPR, left->get_locus(), float_type_node, left->get_tree());
- } else {
- *right
- = build_tree(FLOAT_EXPR, right->get_locus(), float_type_node, right->get_tree());
- }
-
- return float_type_node;
- }
-
- // unhandled - e.g. int + boolean
- error_at(tok->get_locus(), "invalid operands of type %s and %s for operator %s",
- print_type(left_type), print_type(right_type), tok->get_token_description());
- return Tree::error();
- }
-
- // Verifies that both left and right trees are boolean-type nodes.
- bool Parser::check_logical_operands(const_TokenPtr tok, Tree left, Tree right) {
- // ensure both operands are boolean types
- if (left.get_type() != boolean_type_node || right.get_type() != boolean_type_node) {
- error_at(tok->get_locus(),
- "operands of operator %s must be boolean but they are %s and %s\n",
- tok->get_token_description(), print_type(left.get_type()),
- print_type(right.get_type()));
-
- return false;
- }
-
- return true;
- }
-
- // Implementation of addition expression parsing.
- Tree Parser::binary_plus(const_TokenPtr tok, Tree left) {
- // parse RHS (as tok has already been consumed in parse_expression)
- Tree right = parse_expression(LBP_PLUS);
- if (right.is_error())
- return Tree::error();
-
- /* compute resulting type of binary operator with coerce_binary_arithmetic method, which may
- * also modify input trees. */
- Tree tree_type = coerce_binary_arithmetic(tok, &left, &right);
- if (tree_type.is_error())
- return Tree::error();
-
- // construct tree with code PLUS_EXPR to represent binary addition
- return build_tree(PLUS_EXPR, tok->get_locus(), tree_type, left, right);
- }
-
- // Implementation of subtraction expression parsing.
- Tree Parser::binary_minus(const_TokenPtr tok, Tree left) {
- // parse RHS (as tok has already been consumed in parse_expression)
- Tree right = parse_expression(LBP_PLUS);
- if (right.is_error())
- return Tree::error();
-
- /* compute resulting type of binary operator with coerce_binary_arithmetic method, which may
- * also modify input trees. */
- Tree tree_type = coerce_binary_arithmetic(tok, &left, &right);
- if (tree_type.is_error())
- return Tree::error();
-
- // construct tree with code MINUS_EXPR to represent binary subtraction
- return build_tree(MINUS_EXPR, tok->get_locus(), tree_type, left, right);
- }
-
- // Implementation of multiplication expression parsing.
- Tree Parser::binary_mult(const_TokenPtr tok, Tree left) {
- // parse RHS (as tok has already been consumed in parse_expression)
- Tree right = parse_expression(LBP_PLUS);
- if (right.is_error())
- return Tree::error();
-
- /* compute resulting type of binary operator with coerce_binary_arithmetic method, which may
- * also modify input trees. */
- Tree tree_type = coerce_binary_arithmetic(tok, &left, &right);
- if (tree_type.is_error())
- return Tree::error();
-
- // construct tree with code MULT_EXPR to represent binary multiplication
- return build_tree(MULT_EXPR, tok->get_locus(), tree_type, left, right);
- }
-
- // Implementation of divison expression parsing.
- Tree Parser::binary_div(const_TokenPtr tok, Tree left) {
- // parse RHS
- Tree right = parse_expression(LBP_DIV);
- if (right.is_error())
- return Tree::error();
-
- // if integer division, create C-like truncated division expression tree
- if (left.get_type() == integer_type_node && right.get_type() == integer_type_node) {
- return build_tree(TRUNC_DIV_EXPR, tok->get_locus(), integer_type_node, left, right);
- } else {
- // floating-point division
- Tree tree_type = coerce_binary_arithmetic(tok, &left, &right);
- if (tree_type.is_error())
- return Tree::error();
-
- gcc_assert(tree_type == float_type_node);
-
- return build_tree(RDIV_EXPR, tok->get_locus(), tree_type, left, right);
- }
- }
-
- // Implementation of modulo expression parsing.
- Tree Parser::binary_mod(const_TokenPtr tok, Tree left) {
- // parse RHS
- Tree right = parse_expression(LBP_MOD);
- if (right.is_error())
- return Tree::error();
-
- // if integer modulo, create truncated modulo expression
- if (left.get_type() == integer_type_node && right.get_type() == integer_type_node) {
- return build_tree(TRUNC_MOD_EXPR, tok->get_locus(), integer_type_node, left, right);
- } else {
- // no floating-point modulo
- return Tree::error();
- }
- }
-
- // Implementation of binary equal comparison relational operator parsing.
- Tree Parser::binary_equal(const_TokenPtr tok, Tree left) {
- // parse RHS
- Tree right = parse_expression(LBP_EQUAL);
- if (right.is_error())
- return Tree::error();
-
- Tree tree_type = coerce_binary_arithmetic(tok, &left, &right);
- if (tree_type.is_error())
- return Tree::error();
-
- return build_tree(EQ_EXPR, tok->get_locus(), boolean_type_node, left, right);
- }
-
- // Implementation of binary different comparison relational operator parsing.
- Tree Parser::binary_not_equal /*different*/ (const_TokenPtr tok, Tree left) {
- // parse RHS
- Tree right = parse_expression(LBP_NOT_EQUAL);
- if (right.is_error())
- return Tree::error();
-
- Tree tree_type = coerce_binary_arithmetic(tok, &left, &right);
- if (tree_type.is_error())
- return Tree::error();
-
- return build_tree(NE_EXPR, tok->get_locus(), boolean_type_node, left, right);
- }
-
- // Implementation of binary smaller than comparison relational operator parsing.
- Tree Parser::binary_smaller_than(const_TokenPtr tok, Tree left) {
- // parse RHS
- Tree right = parse_expression(LBP_SMALLER_THAN);
- if (right.is_error())
- return Tree::error();
-
- Tree tree_type = coerce_binary_arithmetic(tok, &left, &right);
- if (tree_type.is_error())
- return Tree::error();
-
- return build_tree(LT_EXPR, tok->get_locus(), boolean_type_node, left, right);
- }
-
- // Implementation of binary greater than comparison relational operator parsing.
- Tree Parser::binary_greater_than(const_TokenPtr tok, Tree left) {
- // parse RHS
- Tree right = parse_expression(LBP_GREATER_THAN);
- if (right.is_error())
- return Tree::error();
-
- Tree tree_type = coerce_binary_arithmetic(tok, &left, &right);
- if (tree_type.is_error())
- return Tree::error();
-
- return build_tree(GT_EXPR, tok->get_locus(), boolean_type_node, left, right);
- }
-
- // Implementation of binary smaller than or equal to comparison relational operator parsing.
- Tree Parser::binary_smaller_equal(const_TokenPtr tok, Tree left) {
- // parse RHS
- Tree right = parse_expression(LBP_SMALLER_EQUAL);
- if (right.is_error())
- return Tree::error();
-
- Tree tree_type = coerce_binary_arithmetic(tok, &left, &right);
- if (tree_type.is_error())
- return Tree::error();
-
- return build_tree(LE_EXPR, tok->get_locus(), boolean_type_node, left, right);
- }
-
- // Implementation of binary greater than or equal to comparison relational operator parsing.
- Tree Parser::binary_greater_equal(const_TokenPtr tok, Tree left) {
- // parse RHS
- Tree right = parse_expression(LBP_GREATER_EQUAL);
- if (right.is_error())
- return Tree::error();
-
- Tree tree_type = coerce_binary_arithmetic(tok, &left, &right);
- if (tree_type.is_error())
- return Tree::error();
-
- return build_tree(GE_EXPR, tok->get_locus(), boolean_type_node, left, right);
- }
-
- // Implementation of binary "and" logical operator parsing.
- Tree Parser::binary_logical_and(const_TokenPtr tok, Tree left) {
- // parse RHS
- Tree right = parse_expression(LBP_LOGICAL_AND);
- if (right.is_error())
- return Tree::error();
-
- if (!check_logical_operands(tok, left, right))
- return Tree::error();
-
- return build_tree(TRUTH_ANDIF_EXPR, tok->get_locus(), boolean_type_node, left, right);
- }
-
- // Implementation of binary "or" logical operator parsing.
- Tree Parser::binary_logical_or(const_TokenPtr tok, Tree left) {
- // parse RHS
- Tree right = parse_expression(LBP_LOGICAL_OR);
- if (right.is_error())
- return Tree::error();
-
- if (!check_logical_operands(tok, left, right))
- return Tree::error();
-
- return build_tree(TRUTH_ORIF_EXPR, tok->get_locus(), boolean_type_node, left, right);
- }
-
- // Implementation of binary array reference ([) operator parsing;
- Tree Parser::binary_array_index(const_TokenPtr tok, Tree left) {
- // parse integer expression inside square brackets (array index)
- Tree right = parse_integer_expression();
- if (right.is_error())
- return Tree::error();
-
- // array close token
- if (!skip_token(RIGHT_SQUARE))
- return Tree::error();
-
- // verify left operand has array type
- if (!is_array_type(left.get_type())) {
- error_at(left.get_locus(), "does not have array type");
- return Tree::error();
- }
-
- // compute type of array element
- Tree element_type = TREE_TYPE(left.get_type().get_tree());
-
- // build GENERIC tree ARRAY_REF that represents array access
- return build_tree(ARRAY_REF, tok->get_locus(), element_type, left, right, Tree(), Tree());
- }
-
- // Parses a binary field access on a record.
- Tree Parser::binary_field_ref(const_TokenPtr tok, Tree left) {
- const_TokenPtr identifier = expect_token(IDENTIFIER);
- if (identifier == NULL)
- return Tree::error();
-
- // ensure left expression has record type
- if (!is_record_type(left.get_type())) {
- error_at(left.get_locus(), "does not have record type");
- return Tree::error();
- }
-
- // traverse each FIELD_DECL chaining through TREE_CHAIN
- // list of fields in record type is available through TYPE_FIELDS
- Tree field_decl = TYPE_FIELDS(left.get_type().get_tree());
- while (!field_decl.is_null()) {
- // FIELD_DECL has a DECL_NAME containing an IDENTIFIER_POINTER to get field name
- Tree decl_name = DECL_NAME(field_decl.get_tree());
- const char* field_name = IDENTIFIER_POINTER(decl_name.get_tree());
-
- if (field_name == identifier->get_str())
- break;
-
- field_decl = TREE_CHAIN(field_decl.get_tree());
- }
-
- // if can't find a field with given name, this is an error
- if (field_decl.is_null()) {
- error_at(left.get_locus(), "record type does not have a field named '%s'",
- identifier->get_str().c_str());
- return Tree::error();
- }
-
- // build COMPONENT_REF tree using left tree (record type) and appropriate FIELD_DECL
- return build_tree(COMPONENT_REF, tok->get_locus(), TREE_TYPE(field_decl.get_tree()), left,
- field_decl, Tree());
- }
-
- // Method stub
- Tree Parser::binary_bitwise_or(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_left_shift(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_bitwise_and(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_bitwise_xor(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_right_shift(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_as_cast(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_div_assig(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_mod_assig(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_mult_assig(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_plus_assig(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_minus_assig(const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_assignment_expr(
- const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_bitwise_or_assig(
- const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_bitwise_xor_assig(
- const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_bitwise_and_assig(
- const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_left_shift_assig(
- const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Method stub
- Tree Parser::binary_right_shift_assig(
- const_TokenPtr tok ATTRIBUTE_UNUSED, Tree left ATTRIBUTE_UNUSED) {
- return NULL_TREE;
- }
-
- // Parse variable assignment statement. This is not the same as variable declaration.
- Tree Parser::parse_assignment_statement() {
- Tree variable = parse_lhs_assignment_expression();
-
- if (variable.is_error())
- return Tree::error();
-
- // TODO: fix
- const_TokenPtr assig_tok = expect_token(/*ASSIG*/ COLON);
- if (assig_tok == NULL) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- // skip assignment token and parse expression
- const_TokenPtr first_of_expr = lexer.peek_token();
-
- Tree expr = parse_expression();
- if (expr.is_error())
- return Tree::error();
-
- // skip semicolon token
- skip_token(SEMICOLON);
-
- // enforce rule that rhs of assignment has to have same type as declared lhs type
- if (variable.get_type() != expr.get_type()) {
- // diagnostic
- error_at(first_of_expr->get_locus(),
- "cannot assign value of type %s to a variable of type %s", print_type(expr.get_type()),
- print_type(variable.get_type()));
-
- return Tree::error();
- }
-
- Tree assig_expr
- = build_tree(MODIFY_EXPR, assig_tok->get_locus(), void_type_node, variable, expr);
- return assig_expr;
- }
-
- // Print human-readable name for type.
- const char* Parser::print_type(Tree type) {
- gcc_assert(TYPE_P(type.get_tree()));
-
- if (type == void_type_node)
- return "void";
- else if (type == integer_type_node)
- return "int";
- else if (type == float_type_node)
- return "float";
- else if (is_string_type(type))
- return "string";
- else if (type == boolean_type_node)
- return "boolean";
- else
- return "<<unknown-type>>";
- }
-
- // Returns address to function declaration of printf.
- Tree Parser::get_printf_addr() {
- // only run if printf_fn is null to avoid making repeated function declarations
- if (printf_fn.is_null()) {
- // build const char* type (printf fixed parameter)
- tree fndecl_type_param[]
- = { build_pointer_type(build_qualified_type(char_type_node, TYPE_QUAL_CONST)) };
-
- // build function type as vararg function
- tree fndecl_type
- = build_varargs_function_type_array(integer_type_node, 1, fndecl_type_param);
-
- // build declaration
- tree printf_fn_decl = build_fn_decl("printf", fndecl_type);
- // mark as external
- DECL_EXTERNAL(printf_fn_decl) = 1;
-
- // build an ADDR_EXPR, which returns a pointer to type of function type (function address)
- printf_fn = build1(ADDR_EXPR, build_pointer_type(fndecl_type), printf_fn_decl);
- }
-
- return printf_fn;
- }
-
- // Returns address to function declaration of puts.
- Tree Parser::get_puts_addr() {
- if (puts_fn.is_null()) {
- // build const char* type (puts fixed parameter)
- tree fndecl_type_param[]
- = { build_pointer_type(build_qualified_type(char_type_node, TYPE_QUAL_CONST)) };
-
- // build function type
- tree fndecl_type = build_function_type_array(integer_type_node, 1, fndecl_type_param);
-
- // build declaration
- tree puts_fn_decl = build_fn_decl("puts", fndecl_type);
- // mark as external
- DECL_EXTERNAL(puts_fn_decl) = 1;
-
- // build an ADDR_EXPR, which returns a pointer to type of function type (function address)
- puts_fn = build1(ADDR_EXPR, build_pointer_type(fndecl_type), puts_fn_decl);
- }
-
- return puts_fn;
- }
-
- // Returns address to function declaration of scanf.
- Tree Parser::get_scanf_addr() {
- // only run if scanf_fn is null to avoid making repeated function declarations
- if (scanf_fn.is_null()) {
- // build const char* type (scanf fixed parameter)
- tree fndecl_type_param[]
- = { build_pointer_type(build_qualified_type(char_type_node, TYPE_QUAL_CONST)) };
-
- // build function type as vararg function
- tree fndecl_type
- = build_varargs_function_type_array(integer_type_node, 1, fndecl_type_param);
-
- // build declaration
- tree scanf_fn_decl = build_fn_decl("scanf", fndecl_type);
- // mark as external
- DECL_EXTERNAL(scanf_fn_decl) = 1;
-
- // build an ADDR_EXPR, which returns a pointer to type of function type (function address)
- scanf_fn = build1(ADDR_EXPR, build_pointer_type(fndecl_type), scanf_fn_decl);
- }
-
- return scanf_fn;
- }
-
- // Parses a "write statement".
- /*Tree Parser::parse_write_statement() {
- // write_statement -> "write" expression ";"
-
- if (!skip_token(WRITE)) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- const_TokenPtr first_of_expr = lexer.peek_token();
- Tree expr = parse_expression();
-
- skip_token(SEMICOLON);
-
- if (expr.is_error())
- return Tree::error();
-
- // enable printing of value of expression
- if (expr.get_type() == integer_type_node) {
- // printf("%d\n", expr)
- // build format string for integer (also add null terminator) and integer expression
- const char* format_integer = "%d\n";
- tree args[]
- = { build_string_literal(strlen(format_integer) + 1, format_integer), expr.get_tree() };
-
- // used as trees do not allow calling a FUNCTIONAL_DECL directly
- Tree printf_fn = get_printf_addr();
-
- // build call to print function (printf_fn), in which two arguments in args are passed
- // first argument is format string
- tree stmt = build_call_array_loc(
- first_of_expr->get_locus(), integer_type_node, printf_fn.get_tree(), 2, args);
-
- return stmt;
- } else if (expr.get_type() == float_type_node) {
- // printf("%f\n" (double)expr)
- // have to convert float to double
- const char* format_float = "%f\n";
- tree args[] = { build_string_literal(strlen(format_float) + 1, format_float),
- convert(double_type_node, expr.get_tree()) };
-
- Tree printf_fn = get_printf_addr();
-
- // build call, etc.
- tree stmt = build_call_array_loc(
- first_of_expr->get_locus(), integer_type_node, printf_fn.get_tree(), 2, args);
-
- return stmt;
- } else if (is_string_type(expr.get_type())) {
- // Alternatively we could use printf('%s\n', expr) instead of puts(expr)
- tree args[] = { expr.get_tree() };
-
- Tree puts_fn = get_puts_addr();
-
- tree stmt = build_call_array_loc(
- first_of_expr->get_locus(), integer_type_node, puts_fn.get_tree(), 1, args);
-
- return stmt;
- } else {
- // no more valid types
- error_at(first_of_expr->get_locus(), "value of type %s is not a valid write operand",
- print_type(expr.get_type()));
- return Tree::error();
- }
-
- gcc_unreachable();
- }*/
-
- // Enters new scope (like block scope or whatever).
- void Parser::enter_scope() {
- // push new symbol mapping
- scope.push_scope();
-
- TreeStmtList stmt_list;
- // Used as stack for statements.
- stack_stmt_list.push_back(stmt_list);
-
- // Used as stack of var decls.
- stack_var_decl_chain.push_back(TreeChain());
- // Used as stack for blocks.
- stack_block_chain.push_back(BlockChain());
- }
-
- // Leaves current scope (as defined by blocks - like block scope).
- Parser::TreeSymbolMapping Parser::leave_scope() {
- // Get current list of statements and pop them from stack of statement lists
- TreeStmtList current_stmt_list = get_current_stmt_list();
- stack_stmt_list.pop_back();
-
- // Get current list of var decls and pop them from stack of var decl lists
- TreeChain var_decl_chain = stack_var_decl_chain.back();
- stack_var_decl_chain.pop_back();
-
- // Get current list of blocks and pop them from stack of block lists
- BlockChain subblocks = stack_block_chain.back();
- stack_block_chain.pop_back();
-
- // Create a new block from var decls and subblocks
- tree new_block = build_block(var_decl_chain.first.get_tree(), subblocks.first.get_tree(),
- /* supercontext */ NULL_TREE, /* chain */ NULL_TREE);
-
- // Add the new block to the current chain of blocks (if any)
- if (!stack_block_chain.empty()) {
- stack_block_chain.back().append(new_block);
- }
-
- // Set the subblocks to have the new block as their parent
- for (tree it = subblocks.first.get_tree(); it != NULL_TREE; it = BLOCK_CHAIN(it))
- BLOCK_SUPERCONTEXT(it) = new_block;
- // Do it this way because of double-linkage
-
- // Create BIND_EXPR from decl chain, stmt list, and new block
- tree bind_expr = build3(BIND_EXPR, void_type_node, var_decl_chain.first.get_tree(),
- current_stmt_list.get_tree(), new_block);
-
- // create, basically, a tuple of bind_expr and new_block
- TreeSymbolMapping tree_scope;
- tree_scope.bind_expr = bind_expr;
- tree_scope.block = new_block;
-
- // pop symbol mapping
- scope.pop_scope();
-
- return tree_scope;
- }
-
-#if 0
- // Parses the "read" statement.
- Tree Parser::parse_read_statement() {
- if (!skip_token(READ)) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- const_TokenPtr first_of_expr = lexer.peek_token();
- Tree expr = parse_expression_naming_variable();
-
- skip_token(SEMICOLON);
-
- if (expr.is_error())
- return Tree::error();
-
- // force variable name instead of manually looking up identifier token
- /* if (expr.get_tree_code() != VAR_DECL) {
- error_at(first_of_expr->get_locus(), "invalid expression in read statement");
- return Tree::error();
- }*/
- // not used anymore due to parse_expression_naming_variable
-
- // Variable must be addressable (variable needs address computed)
- TREE_ADDRESSABLE(expr.get_tree()) = 1;
-
- // determine appropriate format string
- const char* format = NULL;
- if (expr.get_type() == integer_type_node) {
- format = "%d";
- } else if (expr.get_type() == float_type_node) {
- format = "%f";
- } else {
- error_at(first_of_expr->get_locus(), "variable of type %s is not a valid read operand",
- print_type(expr.get_type()));
- return Tree::error();
- }
-
- // build args for scanf
- tree args[] = { build_string_literal(strlen(format) + 1, format),
- build_tree(ADDR_EXPR, first_of_expr->get_locus(),
- build_pointer_type(expr.get_type().get_tree()), expr)
- .get_tree() };
-
- // get scanf address
- Tree scanf_fn = get_scanf_addr();
-
- // create tree to call scanf
- tree stmt = build_call_array_loc(
- first_of_expr->get_locus(), integer_type_node, scanf_fn.get_tree(), 2, args);
-
- return stmt;
- }
-#endif
-
- // Parses a while statement.
- Tree Parser::parse_while_statement() {
- if (!skip_token(WHILE)) {
- skip_after_end();
- return Tree::error();
- }
-
- // parse while's conditional expression
- Tree expr = parse_boolean_expression();
- if (!skip_token(DO)) {
- skip_after_end();
- return Tree::error();
- }
-
- // enter loop body scope
- enter_scope();
- parse_statement_seq(&Parser::done_end);
- TreeSymbolMapping while_body_tree_scope = leave_scope();
-
- Tree while_body_stmt = while_body_tree_scope.bind_expr;
-
- skip_token(RIGHT_CURLY);
-
- // build while statement tree
- return build_while_statement(expr, while_body_stmt);
- }
-
- // Builds a while statement tree.
- Tree Parser::build_while_statement(Tree bool_expr, Tree while_body) {
- if (bool_expr.is_error())
- return Tree::error();
-
- TreeStmtList stmt_list;
-
- // build label decl for while condition check
- Tree while_check_label_decl = build_label_decl("while_check", bool_expr.get_locus());
-
- // build label expr for while condition check and add to statement list
- Tree while_check_label_expr
- = build_tree(LABEL_EXPR, bool_expr.get_locus(), void_type_node, while_check_label_decl);
- stmt_list.append(while_check_label_expr);
-
- // build label decl for loop body and end of loop
- Tree while_body_label_decl = build_label_decl("while_body", while_body.get_locus());
- Tree end_of_while_label_decl = build_label_decl("end_of_while", UNKNOWN_LOCATION);
-
- // add cond_expr tree that evaluates condition expression and branches to correct label
- Tree cond_expr = build_tree(COND_EXPR, bool_expr.get_locus(), void_type_node, bool_expr,
- build_tree(GOTO_EXPR, bool_expr.get_locus(), void_type_node, while_body_label_decl),
- build_tree(GOTO_EXPR, bool_expr.get_locus(), void_type_node, end_of_while_label_decl));
- stmt_list.append(cond_expr);
-
- // define location of label for body of loop and append to while body
- Tree while_body_label_expr
- = build_tree(LABEL_EXPR, while_body.get_locus(), void_type_node, while_body_label_decl);
- stmt_list.append(while_body_label_expr);
-
- stmt_list.append(while_body);
-
- // branch back to condition check (as it is a loop)
- Tree goto_check
- = build_tree(GOTO_EXPR, UNKNOWN_LOCATION, void_type_node, while_check_label_decl);
- stmt_list.append(goto_check);
-
- // define location of label for end of the while loop
- Tree end_of_while_label_expr
- = build_tree(LABEL_EXPR, UNKNOWN_LOCATION, void_type_node, end_of_while_label_decl);
- stmt_list.append(end_of_while_label_expr);
-
- return stmt_list.get_tree();
- }
-
- // Parse a for statement.
- Tree Parser::parse_for_statement() {
- // for -> for <identifier> := <expression> to <expression> do <statements> end
- if (!skip_token(FOR)) {
- skip_after_end();
- return Tree::error();
- }
-
- const_TokenPtr identifier = expect_token(IDENTIFIER);
- if (identifier == NULL) {
- skip_after_end();
- return Tree::error();
- }
-
- // TODO
- if (!skip_token(/*ASSIG*/ COLON)) {
- skip_after_end();
- return Tree::error();
- }
-
- // parse lower bound expression
- Tree lower_bound = parse_integer_expression();
-
- // TODO
- if (!skip_token(/*TO*/ DOT)) {
- skip_after_end();
- return Tree::error();
- }
-
- // parse upper bound expression
- Tree upper_bound = parse_integer_expression();
-
- if (!skip_token(DO)) {
- skip_after_end();
- return Tree::error();
- }
-
- // enter loop body scope and parse internal statements
- enter_scope();
- parse_statement_seq(&Parser::done_end);
-
- TreeSymbolMapping for_body_tree_scope = leave_scope();
- Tree for_body_stmt = for_body_tree_scope.bind_expr;
-
- skip_token(RIGHT_CURLY);
-
- // Induction variable ("loop counter" variable) handling
- SymbolPtr ind_var = query_integer_variable(identifier->get_str(), identifier->get_locus());
-
- // build for statement
- return build_for_statement(ind_var, lower_bound, upper_bound, for_body_stmt);
- }
-
- // Builds a for statement tree (piggybacks on while statement tree building).
- Tree Parser::build_for_statement(
- SymbolPtr ind_var, Tree lower_bound, Tree upper_bound, Tree for_body_stmt_list) {
- if (ind_var == NULL)
- return Tree::error();
- Tree ind_var_decl = ind_var->get_tree_decl();
-
- // lower
- if (lower_bound.is_error())
- return Tree::error();
-
- // upper
- if (upper_bound.is_error())
- return Tree::error();
-
- // ind_var = lower
- TreeStmtList stmt_list;
-
- // initialise induction variable with value of lower bound and append to stmt_list
- Tree init_ind_var
- = build_tree(MODIFY_EXPR, UNKNOWN_LOCATION, void_type_node, ind_var_decl, lower_bound);
- stmt_list.append(init_ind_var);
-
- // define condition ind_var <= upper for use in while loop
- Tree while_condition = build_tree(
- LE_EXPR, upper_bound.get_locus(), boolean_type_node, ind_var_decl, upper_bound);
-
- // simulate incrementing ind_var
- Tree incr_ind_var = build_tree(MODIFY_EXPR, UNKNOWN_LOCATION, void_type_node, ind_var_decl,
- build_tree(PLUS_EXPR, UNKNOWN_LOCATION, integer_type_node, ind_var_decl,
- build_int_cst_type(integer_type_node, 1)));
-
- // Wrap as stmt list
- TreeStmtList for_stmt_list = for_body_stmt_list;
- for_stmt_list.append(incr_ind_var);
-
- // construct associated while statement and append to stmt_list
- Tree while_stmt = build_while_statement(while_condition, for_stmt_list.get_tree());
- stmt_list.append(while_stmt);
-
- // return entire stmt_list
- return stmt_list.get_tree();
- }
-
- // Gets type (as in typedef) of name in current scope.
- SymbolPtr Parser::query_type(const std::string& name, location_t loc) {
- SymbolPtr sym = scope.lookup(name);
- if (sym == NULL) {
- error_at(loc, "type '%s' not declared in the current scope", name.c_str());
- } else if (sym->get_kind() != TYPENAME) {
- error_at(loc, "name '%s' is not a type", name.c_str());
- sym = SymbolPtr();
- }
-
- return sym;
- }
-
- // Get variable of name in current scope.
- SymbolPtr Parser::query_variable(const std::string& name, location_t loc) {
- SymbolPtr sym = scope.lookup(name);
- if (sym == NULL) {
- error_at(loc, "variable '%s' not declared in the current scope", name.c_str());
- } else if (sym->get_kind() != VARIABLE) {
- error_at(loc, "name '%s' is not a variable", name.c_str());
- sym = SymbolPtr();
- }
- return sym;
- }
-
- // Gets variable of name in current scope and ensures it has integer type.
- SymbolPtr Parser::query_integer_variable(const std::string& name, location_t loc) {
- SymbolPtr sym = query_variable(name, loc);
- if (sym != NULL) {
- Tree var_decl = sym->get_tree_decl();
- gcc_assert(!var_decl.is_null());
-
- if (var_decl.get_type() != integer_type_node) {
- error_at(loc, "variable '%s' does not have integer type", name.c_str());
- sym = SymbolPtr();
- }
- }
-
- return sym;
- }
-
// Returns true if the next token is END, ELSE, or EOF;
bool Parser::done_end_or_else() {
const_TokenPtr t = lexer.peek_token();
@@ -12801,168 +11276,6 @@ namespace Rust {
return (t->get_id() == RIGHT_CURLY || t->get_id() == END_OF_FILE);
}
- // Parses expression and ensures it is a variable declaration or array reference.
- Tree Parser::parse_expression_naming_variable() {
- Tree expr = parse_expression();
- if (expr.is_error())
- return expr;
-
- if (expr.get_tree_code() != VAR_DECL && expr.get_tree_code() != ARRAY_REF
- && expr.get_tree_code() != COMPONENT_REF) {
- error_at(expr.get_locus(), "does not designate a variable, array element or field");
- return Tree::error();
- }
-
- return expr;
- }
-
- // Parses expression and ensures it is an assignment expression?
- Tree Parser::parse_lhs_assignment_expression() {
- return parse_expression_naming_variable();
- }
-
- // Parses type (as in typedef) declaration statement.
- /*Tree Parser::parse_type_declaration() {
- // type_declaration -> "type" identifier ":" type ";"
- if (!skip_token(TYPE)) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- // get identifier
- const_TokenPtr identifier = expect_token(IDENTIFIER);
- if (identifier == NULL) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- // skip colon
- if (!skip_token(COLON)) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- // get type of expression
- Tree type_tree = parse_type();
-
- if (type_tree.is_error()) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- skip_token(SEMICOLON);
-
- // ensure not already delcared in scope
- if (scope.get_current_mapping().get(identifier->get_str())) {
- error_at(identifier->get_locus(), "name '%s' already declared in this scope",
- identifier->get_str().c_str());
- }
-
- // create new symbol for typedef and put in mapping for current scope
- SymbolPtr sym(new Symbol(TYPENAME, identifier->get_str()));
- scope.get_current_mapping().insert(sym);
-
- // build typedef tree
- Tree decl = build_decl(identifier->get_locus(), TYPE_DECL,
- get_identifier(sym->get_name().c_str()), type_tree.get_tree());
- DECL_CONTEXT(decl.get_tree()) = main_fndecl;
-
- // add type declaration to variable declaration stack
- gcc_assert(!stack_var_decl_chain.empty());
- stack_var_decl_chain.back().append(decl);
-
- // set symbol's declaration tree to declaration tree
- sym->set_tree_decl(decl);
-
- // build declaration statement for tree
- Tree stmt = build_tree(DECL_EXPR, identifier->get_locus(), void_type_node, decl);
-
- return stmt;
- }*/
-
- // Parses a record type field declaration.
- /*Tree Parser::parse_field_declaration(std::vector<std::string>& field_names) {
- // identifier ':' type ';'
- const_TokenPtr identifier = expect_token(IDENTIFIER);
- if (identifier == NULL) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- skip_token(COLON);
-
- Tree type = parse_type();
-
- skip_token(SEMICOLON);
-
- if (type.is_error())
- return Tree::error();
-
- // pass vector of fields to avoid repeated field names - error if they exist
- if (std::find(field_names.begin(), field_names.end(), identifier->get_str())
- != field_names.end()) {
- error_at(identifier->get_locus(), "repeated field name");
- return Tree::error();
- }
-
- field_names.push_back(identifier->get_str());
-
- // create GENERIC FIELD_DECL tree with name of tree and type
- Tree field_decl = build_decl(identifier->get_locus(), FIELD_DECL,
- get_identifier(identifier->get_str().c_str()), type.get_tree());
- // required for read statement to work on fields
- TREE_ADDRESSABLE(field_decl.get_tree()) = 1;
-
- return field_decl;
- }*/
-
- // TODO: remove: here to solve link errors
- Tree Parser::parse_record() {
- return Tree::error();
- }
- // Parses a record.
- /*Tree Parser::parse_record() {
- // "record" field-decl* "end"
- const_TokenPtr record_tok = expect_token(RECORD);
- if (record_tok == NULL) {
- skip_after_semicolon();
- return Tree::error();
- }
-
- // create empty record type tree
- Tree record_type = make_node(RECORD_TYPE);
- Tree field_list, field_last;
- std::vector<std::string> field_names;
-
- // parse field declarations inside record until the end token is found
- const_TokenPtr next = lexer.peek_token();
- while (next->get_id() != END) {
- Tree field_decl = parse_field_declaration(field_names);
-
- if (!field_decl.is_error()) {
- // set field declaration's decl_context to this record type
- DECL_CONTEXT(field_decl.get_tree()) = record_type.get_tree();
- if (field_list.is_null())
- field_list = field_decl;
- if (!field_last.is_null())
- // chain fields in record type by using tree_chain
- TREE_CHAIN(field_last.get_tree()) = field_decl.get_tree();
- field_last = field_decl;
- }
-
- next = lexer.peek_token();
- }
-
- skip_token(END);
-
- // first field sets TYPE_FIELDS attribute of the RECORD_TYPE tree
- TYPE_FIELDS(record_type.get_tree()) = field_list.get_tree();
- // request GCC to layout type in memory
- layout_type(record_type.get_tree());
-
- return record_type;
- }*/
-
// Dumps lexer output to stderr.
void Parser::debug_dump_lex_output() {
Rust::const_TokenPtr tok = lexer.peek_token();
@@ -12974,14 +11287,14 @@ namespace Rust {
|| tok->get_id() == Rust::CHAR_LITERAL || tok->get_id() == Rust::BYTE_STRING_LITERAL
|| tok->get_id() == Rust::BYTE_CHAR_LITERAL;
- location_t loc = tok->get_locus();
+ Location loc = tok->get_locus();
- fprintf(stderr, "<id=%s%s, %s, line=%d, col=%d>\n", tok->token_id_to_str(),
+ fprintf(stderr, "<id=%s%s, %s\n", tok->token_id_to_str(),
has_text ? (std::string(", text=") + tok->get_str() + std::string(", typehint=")
+ std::string(tok->get_type_hint_str()))
.c_str()
: "",
- LOCATION_FILE(loc), LOCATION_LINE(loc), LOCATION_COLUMN(loc));
+ lexer.get_line_map()->to_string(loc).c_str());
if (tok->get_id() == Rust::END_OF_FILE)
break;
@@ -12996,6 +11309,8 @@ namespace Rust {
AST::Crate crate = parse_crate();
// print crate "as string", which then calls each item as string, etc.
- fprintf(stderr, crate.as_string().c_str());
+ fprintf(stderr, "%s", crate.as_string().c_str());
}
-} \ No newline at end of file
+}
+
+
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 94d1eab..ca84659 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -2,11 +2,6 @@
#define RUST_PARSE_H
#include "rust-lex.h"
-//#include "rust-tree.h"
-#include "rust-scope.h"
-
-//#include "rust-ast-containers.h"
-// TODO: change, maybe?
#include "rust-ast-full.h"
namespace Rust {
@@ -78,44 +73,6 @@ namespace Rust {
void unexpected_token(const_TokenPtr t);
bool skip_generics_right_angle();
- // expression parsing
- int left_binding_power(const_TokenPtr tok);
- Tree null_denotation(const_TokenPtr tok);
- Tree left_denotation(const_TokenPtr tok, Tree left);
-
- Tree parse_expression(int right_binding_power);
-
- Tree coerce_binary_arithmetic(const_TokenPtr tok, Tree* left, Tree* right);
- bool check_logical_operands(const_TokenPtr tok, Tree left, Tree right);
-
- Tree get_printf_addr();
- Tree get_puts_addr();
-
- Tree get_scanf_addr();
-
- Tree build_label_decl(const char* name, location_t loc);
- Tree build_if_statement(Tree bool_expr, Tree then_part, Tree else_part);
- Tree build_while_statement(Tree bool_expr, Tree while_body);
- Tree build_for_statement(
- SymbolPtr ind_var, Tree lower_bound, Tree upper_bound, Tree for_body_stmt_list);
-
- const char* print_type(Tree type);
-
- TreeStmtList& get_current_stmt_list();
-
- void enter_scope();
-
- struct TreeSymbolMapping {
- Tree bind_expr;
- Tree block;
- };
-
- TreeSymbolMapping leave_scope();
-
- SymbolPtr query_type(const std::string& name, location_t loc);
- SymbolPtr query_variable(const std::string& name, location_t loc);
- SymbolPtr query_integer_variable(const std::string& name, location_t loc);
-
void parse_statement_seq(bool (Parser::*done)());
// AST-related stuff - maybe move or something?
@@ -476,50 +433,19 @@ namespace Rust {
AST::StructPatternElements parse_struct_pattern_elems();
::std::unique_ptr<AST::StructPatternField> parse_struct_pattern_field();
- // void parse_crate();
- // AST::Module parse_module();
- // void parse_module_item(AST::Module module_for_items, AST::AttributeList
- // item_outer_attributes); AST::Visibility parse_visibility();
+ int left_binding_power(const_TokenPtr token);
bool done_end();
bool done_end_or_else();
bool done_end_of_file();
- typedef Tree (Parser::*BinaryHandler)(const_TokenPtr, Tree);
- BinaryHandler get_binary_handler(TokenId id);
-
public:
// Construct parser with specified lexer reference.
- Parser(Lexer& parLexer) : lexer(parLexer), printf_fn(), puts_fn(), scanf_fn() {}
-
- // (old) Main entry point for parser.
- void parse_program();
+ Parser(Lexer& parLexer) : lexer(parLexer) {}
// Main entry point for parser.
AST::Crate parse_crate();
- Tree parse_statement();
-
- Tree parse_variable_declaration();
- Tree parse_type_declaration();
-
- // Tree parse_type();
- Tree parse_record();
- Tree parse_field_declaration(std::vector<std::string>& field_names);
-
- Tree parse_assignment_statement();
- Tree parse_if_statement();
- Tree parse_while_statement();
- Tree parse_for_statement();
- Tree parse_read_statement();
- Tree parse_write_statement();
-
- Tree parse_expression();
- Tree parse_expression_naming_variable();
- Tree parse_lhs_assignment_expression();
- Tree parse_boolean_expression();
- Tree parse_integer_expression();
-
// Dumps all lexer output.
void debug_dump_lex_output();
void debug_dump_ast_output();
@@ -527,87 +453,7 @@ namespace Rust {
private:
// The lexer associated with the parser.
Lexer& lexer;
- // The current scope.
- Scope scope;
-
- // The simulated "main" function inside which the entire program lies.
- tree main_fndecl;
-
- // Address to function declaration of printf.
- Tree printf_fn;
- // Address to function declaration of puts.
- Tree puts_fn;
- // Address to function declaration of scanf.
- Tree scanf_fn;
-
- // The statement stack.
- std::vector<TreeStmtList> stack_stmt_list;
- // The VAR_DECL stack.
- std::vector<TreeChain> stack_var_decl_chain;
-
- // The block stack.
- std::vector<BlockChain> stack_block_chain;
-
-// x-macro list for binary operators - only defined here to be inside Parser class
-#define BINARY_HANDLER_LIST \
- BINARY_HANDLER(plus, PLUS) \
- BINARY_HANDLER(minus, MINUS) \
- BINARY_HANDLER(mult, ASTERISK) \
- BINARY_HANDLER(div, DIV) \
- BINARY_HANDLER(mod, PERCENT) \
- BINARY_HANDLER(bitwise_and, AMP) \
- BINARY_HANDLER(bitwise_or, PIPE) \
- BINARY_HANDLER(bitwise_xor, CARET) \
- BINARY_HANDLER(left_shift, LEFT_SHIFT) \
- BINARY_HANDLER(right_shift, RIGHT_SHIFT) \
- \
- BINARY_HANDLER(equal, EQUAL_EQUAL) \
- BINARY_HANDLER(not_equal, NOT_EQUAL) \
- BINARY_HANDLER(smaller_than, LEFT_ANGLE) \
- BINARY_HANDLER(smaller_equal, LESS_OR_EQUAL) \
- BINARY_HANDLER(greater_than, RIGHT_ANGLE) \
- BINARY_HANDLER(greater_equal, GREATER_OR_EQUAL) \
- \
- BINARY_HANDLER(logical_and, LOGICAL_AND) \
- BINARY_HANDLER(logical_or, OR) \
- \
- BINARY_HANDLER(as_cast, AS) \
- /* should this really be an operator? */ \
- \
- BINARY_HANDLER(array_index, LEFT_SQUARE) \
- \
- BINARY_HANDLER(field_ref, DOT) \
- /*BINARY_HANDLER(method_call, DOT)*/ \
- BINARY_HANDLER(error_propagation, QUESTION_MARK) \
- /* not a binary operator, technically, but still left denotation */ \
- BINARY_HANDLER(assignment_expr, EQUAL) \
- /* should this really be an operator? or a binary one? */ \
- /* if it should, also add all operation-assign below:*/ \
- BINARY_HANDLER(plus_assig, PLUS_EQ) \
- BINARY_HANDLER(minus_assig, MINUS_EQ) \
- BINARY_HANDLER(mult_assig, ASTERISK_EQ) \
- BINARY_HANDLER(div_assig, DIV_EQ) \
- BINARY_HANDLER(mod_assig, PERCENT_EQ) \
- BINARY_HANDLER(bitwise_and_assig, AMP_EQ) \
- BINARY_HANDLER(bitwise_or_assig, PIPE_EQ) \
- BINARY_HANDLER(bitwise_xor_assig, CARET_EQ) \
- BINARY_HANDLER(left_shift_assig, LEFT_SHIFT_EQ) \
- BINARY_HANDLER(right_shift_assig, RIGHT_SHIFT_EQ) \
- \
- BINARY_HANDLER(range_exclusive, DOT_DOT) \
- BINARY_HANDLER(range_inclusive, DOT_DOT_EQ) \
- \
- BINARY_HANDLER(path, SCOPE_RESOLUTION) \
- \
- BINARY_HANDLER(return, RETURN_TOK) \
- BINARY_HANDLER(break, BREAK) \
- BINARY_HANDLER(closure, MOVE)
-
-// create declarations for binary op handling
-#define BINARY_HANDLER(name, _) Tree binary_##name(const_TokenPtr tok, Tree left);
- BINARY_HANDLER_LIST
-#undef BINARY_HANDLER
};
}
-#endif // RUST_PARSE_H \ No newline at end of file
+#endif // RUST_PARSE_H
diff --git a/gcc/rust/parse/rust-scope.cc b/gcc/rust/parse/rust-scope.cc
deleted file mode 100644
index d38a078..0000000
--- a/gcc/rust/parse/rust-scope.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-#include "rust-scope.h"
-
-#include <utility> // for std::make_pair
-
-namespace Rust {
- Scope::Scope() {}
-
- void SymbolMapping::insert(SymbolPtr s) {
- gcc_assert(s != NULL);
- std::pair<Map::iterator, bool> p = map.insert(std::make_pair(s->get_name(), s));
-
- gcc_assert(p.second);
- }
-
- SymbolPtr SymbolMapping::get(const std::string& str) const {
- Map::const_iterator it = map.find(str);
- if (it != map.end()) {
- return it->second;
- }
-
- return SymbolPtr();
- }
-
- SymbolPtr Scope::lookup(const std::string& str) {
- // Traverse stack from top (end of MapStack) to bottom, so use reverse_iterator.
- for (MapStack::reverse_iterator map = map_stack.rbegin(); map != map_stack.rend(); map++) {
- if (SymbolPtr sym = map->get(str)) {
- return sym;
- }
- }
-
- return SymbolPtr();
- }
-
- void Scope::push_scope() {
- map_stack.push_back(SymbolMapping());
- }
-
- void Scope::pop_scope() {
- gcc_assert(!map_stack.empty());
- map_stack.pop_back();
- }
-} \ No newline at end of file
diff --git a/gcc/rust/parse/rust-scope.h b/gcc/rust/parse/rust-scope.h
deleted file mode 100644
index 7ac38c9..0000000
--- a/gcc/rust/parse/rust-scope.h
+++ /dev/null
@@ -1,61 +0,0 @@
-#ifndef RUST_SCOPE_H
-#define RUST_SCOPE_H
-
-#include "config.h"
-#include "system.h"
-#include "coretypes.h"
-#include "tree.h"
-// order: config, system, coretypes, tree
-// may not all be required
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "rust-tree.h"
-#include "rust-symbol.h"
-
-// maybe split out scope into Symbol, SymbolMapping, and Scope headers
-
-namespace Rust {
- // Map of strings (identifiers) to SymbolPtrs
- struct SymbolMapping {
- public:
- // Inserts a new Symbol into the map using its name as the key. Also checks name is unique.
- void insert(SymbolPtr s);
- // Returns the mapped Symbol for the given string. May return a null Symbol.
- SymbolPtr get(const std::string& str) const;
-
- private:
- typedef std::map<std::string, SymbolPtr> Map;
- // SymbolMapping's map.
- Map map;
- };
-
- // Scope class that holds mapping in it.
- class Scope {
- public:
- // Gets current mapping (created in last push that hasn't been popped yet).
- SymbolMapping& get_current_mapping() {
- gcc_assert(!map_stack.empty());
- return map_stack.back();
- }
-
- // Create new mapping.
- void push_scope();
- // Get rid of mapping?
- void pop_scope();
-
- Scope();
-
- // Get the last mapping for a given string (or null if no such mapping exists).
- SymbolPtr lookup(const std::string& str);
-
- private:
- typedef std::vector<SymbolMapping> MapStack;
- // Scope's MapStack.
- MapStack map_stack;
- }; // TODO: have multiple scopes (for modules, function, etc) at once?
-}
-
-#endif // RUST_SCOPE_H \ No newline at end of file
diff --git a/gcc/rust/parse/rust-symbol.h b/gcc/rust/parse/rust-symbol.h
deleted file mode 100644
index 439325b..0000000
--- a/gcc/rust/parse/rust-symbol.h
+++ /dev/null
@@ -1,78 +0,0 @@
-#ifndef RUST_SYMBOL_H
-#define RUST_SYMBOL_H
-
-#include "config.h"
-#include "system.h"
-#include "coretypes.h"
-#include "tree.h"
-// order: config, system, coretypes, tree
-
-#include <string>
-//#include <tr1/memory> // as shared_ptr is not available in std memory in c++03
-// replaced with proper memory in c++11
-#include <memory>
-
-namespace Rust {
- // Kinds of symbols.
- enum SymbolKind { INVALID, VARIABLE, TYPENAME /*change to STRUCT*/, FUNCTION };
- // TODO: possibly add typedef, struct, union, "enum"
-
- /* TODO: apparently Rust's type symbol table is separate to its identifier symbol table, so have a
- * different symbol table for each? */
-
- /* The symbol table(s) will be generated as a pass over the AST (the first, probably) and each
- * scope, including module namespacing, will be a separate symbol table (with earlier ones still
- * accessible but searched afterward). It will be preserved in later passes over the AST to type
- * check and maybe bind identifiers together or something.
- * It may have to be preserved, at least partially, for GENERIC lowering. */
-
- // A symbol used for identifiers, etc. - TODO: extend to support namespacing (Rust paths?)
- struct Symbol {
- public:
- // Constructs a new symbol of name with no declaration tree set.
- Symbol(SymbolKind kind, const std::string& name_) :
- kind(kind), name(name_), decl(error_mark_node) {
- gcc_assert(name.size() > 0);
- }
-
- // Gets symbol's kind.
- SymbolKind get_kind() const {
- return kind;
- }
-
- // Gets symbol's name.
- std::string get_name() const {
- return name;
- }
-
- // Sets symbol's declaration tree.
- void set_tree_decl(Tree decl_) {
- // Ensure declaration tree is a variable or type declaration.
- gcc_assert((decl_.get_tree_code() == VAR_DECL) || (decl_.get_tree_code() == TYPE_DECL));
- decl = decl_;
- }
-
- // Gets tree with the location of variable declaration.
- Tree get_tree_decl() const {
- return decl;
- }
-
- private:
- // Symbol's kind.
- SymbolKind kind;
- // Symbol's name.
- std::string name;
- // Symbol's declaration tree.
- Tree decl;
-
- // Note: in other languages, other info about symbols would also be kept, e.g. "kind"
- // Also would be able to store more than just variable declaration trees.
- };
-
- // Symbol shared pointer.
- typedef std::shared_ptr<Symbol> SymbolPtr;
- // Const symbol shared pointer (i.e. to const Symbol).
- typedef std::shared_ptr<const Symbol> const_SymbolPtr;
-}
-
-#endif \ No newline at end of file
diff --git a/gcc/rust/parse/rust-tree.h b/gcc/rust/parse/rust-tree.h
deleted file mode 100644
index 6318a50..0000000
--- a/gcc/rust/parse/rust-tree.h
+++ /dev/null
@@ -1,167 +0,0 @@
-#ifndef RUST_TREE_H
-#define RUST_TREE_H
-
-#include "config.h"
-#include "system.h"
-#include "coretypes.h"
-#include "tree.h"
-#include "tree-iterator.h"
-#include "input.h"
-// order: config, system, coretypes, tree, tree-iterator, input
-// may not need all of them
-
-namespace Rust {
- // Wrapper around tree to keep location and tree in one data structure.
- struct Tree {
- public:
- Tree() : t(NULL_TREE), loc(UNKNOWN_LOCATION) {}
- Tree(tree t_) : t(t_), loc(EXPR_LOCATION(t)) {}
- Tree(tree t_, location_t loc_) : t(t_), loc(loc_) {}
- Tree(Tree t_, location_t loc_) : t(t_.get_tree()), loc(loc_) {}
-
- // Get tree's location_t.
- location_t get_locus() const {
- return loc;
- }
-
- // Sets tree's location_t.
- void set_locus(location_t loc_) {
- loc = loc_;
- }
-
- // Gets tree's tree in GCC form.
- tree get_tree() const {
- return t;
- }
-
- // Gets tree's GCC tree code.
- tree_code get_tree_code() const {
- return TREE_CODE(t);
- }
-
- // Sets tree's GCC tree.
- void set_tree(tree t_) {
- t = t_;
- }
-
- // Returns if tree is an error node?
- bool is_error() const {
- return error_operand_p(t);
- }
-
- // Returns whether tree node is null.
- bool is_null() {
- return t == NULL_TREE;
- }
-
- // Creates an error Tree.
- static Tree error() {
- return Tree(error_mark_node);
- }
-
- // Gets tree's GCC type.
- Tree get_type() const {
- return TREE_TYPE(t);
- }
-
- private:
- // The tree object's gcc tree representation.
- tree t;
- // The tree's location.
- location_t loc;
- };
-
- // Comparison by identity as tree is a pointer.
- inline bool operator==(Tree t1, Tree t2) {
- return t1.get_tree() == t2.get_tree();
- }
- inline bool operator!=(Tree t1, Tree t2) {
- return !(t1 == t2);
- }
-
- inline Tree build_tree(tree_code tc, location_t loc, Tree type, Tree t1) {
- return build1_loc(loc, tc, type.get_tree(), t1.get_tree());
- }
-
- inline Tree build_tree(tree_code tc, location_t loc, Tree type, Tree t1, Tree t2) {
- return build2_loc(loc, tc, type.get_tree(), t1.get_tree(), t2.get_tree());
- }
-
- inline Tree build_tree(tree_code tc, location_t loc, Tree type, Tree t1, Tree t2, Tree t3) {
- return build3_loc(loc, tc, type.get_tree(), t1.get_tree(), t2.get_tree(), t3.get_tree());
- }
-
- inline Tree build_tree(
- tree_code tc, location_t loc, Tree type, Tree t1, Tree t2, Tree t3, Tree t4) {
- return build4_loc(
- loc, tc, type.get_tree(), t1.get_tree(), t2.get_tree(), t3.get_tree(), t4.get_tree());
- }
-
- inline Tree build_tree(
- tree_code tc, location_t loc, Tree type, Tree t1, Tree t2, Tree t3, Tree t4, Tree t5) {
- return build5_loc(loc, tc, type.get_tree(), t1.get_tree(), t2.get_tree(), t3.get_tree(),
- t4.get_tree(), t5.get_tree());
- }
-
- // Wrapper around STATEMENT_LIST, used to represent lists of statements. Adapter for TREE_LIST.
- struct TreeStmtList {
- public:
- // Create new statement list from nothing.
- TreeStmtList() : list(alloc_stmt_list()) {}
- // Create new statement list from given tree.
- TreeStmtList(Tree param_tree) : list(param_tree.get_tree()) {}
-
- // Append to statement list.
- void append(Tree param_tree) {
- append_to_statement_list(param_tree.get_tree(), &list);
- }
-
- // Get the statement list.
- tree get_tree() const {
- return list;
- }
-
- private:
- // The statement list.
- tree list;
- };
-
- // TODO: Check if already exists in GCC
- template<typename Append>
- struct TreeChainBase {
- Tree first;
- Tree last;
-
- TreeChainBase() : first(), last() {}
-
- void append(Tree t) {
- gcc_assert(!t.is_null());
- if (first.is_null()) {
- first = last = t;
- } else {
- Append()(last, t);
- last = t;
- }
- }
- };
-
- struct tree_chain_append {
- void operator()(Tree t, Tree a) {
- TREE_CHAIN(t.get_tree()) = a.get_tree();
- }
- };
-
- // Single-linked list implemented with trees. Used for VAR_DECLs.
- struct TreeChain : TreeChainBase<tree_chain_append> {};
-
- struct block_chain_append {
- void operator()(Tree t, Tree a) {
- BLOCK_CHAIN(t.get_tree()) = a.get_tree();
- }
- };
-
- // Single-linked list implemented with trees. Used for chains of blocks.
- struct BlockChain : TreeChainBase<block_chain_append> {};
-}
-
-#endif // RUST_TREE_H \ No newline at end of file
diff --git a/gcc/rust/rust-diagnostics.cc b/gcc/rust/rust-diagnostics.cc
new file mode 100644
index 0000000..d7c6475
--- /dev/null
+++ b/gcc/rust/rust-diagnostics.cc
@@ -0,0 +1,215 @@
+// rust-diagnostics.cc -- GCC implementation of rust diagnostics interface.
+// Copyright (C) 2016-2019 Free Software Foundation, Inc.
+// Contributed by Than McIntosh, Google.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-system.h"
+#include "rust-diagnostics.h"
+
+static std::string
+mformat_value()
+{
+ return std::string(xstrerror(errno));
+}
+
+// Rewrite a format string to expand any extensions not
+// supported by sprintf(). See comments in rust-diagnostics.h
+// for list of supported format specifiers.
+
+static std::string
+expand_format(const char* fmt)
+{
+ std::stringstream ss;
+ for (const char* c = fmt; *c; ++c)
+ {
+ if (*c != '%')
+ {
+ ss << *c;
+ continue;
+ }
+ c++;
+ switch (*c)
+ {
+ case '\0':
+ {
+ // malformed format string
+ rust_unreachable();
+ }
+ case '%':
+ {
+ ss << "%";
+ break;
+ }
+ case 'm':
+ {
+ ss << mformat_value();
+ break;
+ }
+ case '<':
+ {
+ ss << rust_open_quote();
+ break;
+ }
+ case '>':
+ {
+ ss << rust_close_quote();
+ break;
+ }
+ case 'q':
+ {
+ ss << rust_open_quote();
+ c++;
+ if (*c == 'm')
+ {
+ ss << mformat_value();
+ }
+ else
+ {
+ ss << "%" << *c;
+ }
+ ss << rust_close_quote();
+ break;
+ }
+ default:
+ {
+ ss << "%" << *c;
+ }
+ }
+ }
+ return ss.str();
+}
+
+// Expand message format specifiers, using a combination of
+// expand_format above to handle extensions (ex: %m, %q) and vasprintf()
+// to handle regular printf-style formatting. A pragma is being used here to
+// suppress this warning:
+//
+// warning: function ‘std::__cxx11::string expand_message(const char*, __va_list_tag*)’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
+//
+// What appears to be happening here is that the checker is deciding that
+// because of the call to vasprintf() (which has attribute gnu_printf), the
+// calling function must need to have attribute gnu_printf as well, even
+// though there is already an attribute declaration for it.
+
+static std::string
+expand_message(const char* fmt, va_list ap) RUST_ATTRIBUTE_GCC_DIAG(1,0);
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
+
+static std::string
+expand_message(const char* fmt, va_list ap)
+{
+ char* mbuf = 0;
+ std::string expanded_fmt = expand_format(fmt);
+ int nwr = vasprintf(&mbuf, expanded_fmt.c_str(), ap);
+ if (nwr == -1)
+ {
+ // memory allocation failed
+ rust_be_error_at(Linemap::unknown_location(),
+ "memory allocation failed in vasprintf");
+ rust_assert(0);
+ }
+ std::string rval = std::string(mbuf);
+ free(mbuf);
+ return rval;
+}
+
+#pragma GCC diagnostic pop
+
+static const char* cached_open_quote = NULL;
+static const char* cached_close_quote = NULL;
+
+const char*
+rust_open_quote()
+{
+ if (cached_open_quote == NULL)
+ rust_be_get_quotechars(&cached_open_quote, &cached_close_quote);
+ return cached_open_quote;
+}
+
+const char*
+rust_close_quote()
+{
+ if (cached_close_quote == NULL)
+ rust_be_get_quotechars(&cached_open_quote, &cached_close_quote);
+ return cached_close_quote;
+}
+
+void
+rust_error_at(const Location location, const char* fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ rust_be_error_at(location, expand_message(fmt, ap));
+ va_end(ap);
+}
+
+void
+rust_warning_at(const Location location, int opt, const char* fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ rust_be_warning_at(location, opt, expand_message(fmt, ap));
+ va_end(ap);
+}
+
+void
+rust_fatal_error(const Location location, const char* fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ rust_be_fatal_error(location, expand_message(fmt, ap));
+ va_end(ap);
+}
+
+void
+rust_inform(const Location location, const char* fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ rust_be_inform(location, expand_message(fmt, ap));
+ va_end(ap);
+}
+
+// rust_debug uses normal printf formatting, not GCC diagnostic formatting.
+
+void
+rust_debug(const Location location, const char* fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ char* mbuf = NULL;
+ int nwr = vasprintf(&mbuf, fmt, ap);
+ va_end(ap);
+ if (nwr == -1)
+ {
+ rust_be_error_at(Linemap::unknown_location(),
+ "memory allocation failed in vasprintf");
+ rust_assert(0);
+ }
+ std::string rval = std::string(mbuf);
+ free(mbuf);
+ rust_be_inform(location, rval);
+}
+
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 443818c..1701999 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -8,6 +8,8 @@
#include <algorithm>
+extern Linemap* rust_get_linemap();
+
namespace Rust {
// Simple wrapper for FILE* that simplifies destruction.
struct RAIIFile {
@@ -280,7 +282,7 @@ namespace Rust {
// parse file here
// create lexer and parser - these are file-specific and so aren't instance variables
- Rust::Lexer lex(filename, file_wrap.file);
+ Rust::Lexer lex(filename, file_wrap.file, rust_get_linemap());
Rust::Parser parser(lex);
// determine parsing method from options
@@ -515,8 +517,13 @@ namespace Rust {
AST::Attribute attr(AST::SimplePath::from_str("macro_use"), NULL);
// create "extern crate" item with the name
- ::std::unique_ptr<AST::ExternCrate> extern_crate(new AST::ExternCrate(
- *it, AST::Visibility::create_error(), { ::std::move(attr) }, UNKNOWN_LOCATION));
+ ::std::unique_ptr<AST::ExternCrate> extern_crate(
+ new AST::ExternCrate(
+ *it,
+ AST::Visibility::create_error(),
+ { ::std::move(attr) },
+ Linemap::unknown_location())
+ );
// insert at beginning
crate.items.insert(crate.items.begin(), ::std::move(extern_crate));
@@ -529,10 +536,10 @@ namespace Rust {
AST::SimplePathSegment("v1") };
// create use tree and decl
::std::unique_ptr<AST::UseTreeGlob> use_tree(new AST::UseTreeGlob(
- AST::UseTreeGlob::PATH_PREFIXED, AST::SimplePath(::std::move(segments)), UNKNOWN_LOCATION));
+ AST::UseTreeGlob::PATH_PREFIXED, AST::SimplePath(::std::move(segments)), Linemap::unknown_location()));
AST::Attribute prelude_attr(AST::SimplePath::from_str("prelude_import"), NULL);
::std::unique_ptr<AST::UseDeclaration> use_decl(new AST::UseDeclaration(::std::move(use_tree),
- AST::Visibility::create_error(), { ::std::move(prelude_attr) }, UNKNOWN_LOCATION));
+ AST::Visibility::create_error(), { ::std::move(prelude_attr) }, Linemap::unknown_location()));
crate.items.insert(crate.items.begin(), ::std::move(use_decl));
@@ -651,4 +658,4 @@ namespace Rust {
* - analysis on global context (HIR optimisations? create MIR?)
* - code generation
* - link */
-} \ No newline at end of file
+}
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index 38eb494..167d494 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -7,6 +7,10 @@
#include "coretypes.h"
#include "options.h"
#include "rust-system.h"
+
+#include "rust-linemap.h"
+#include "backend.h"
+
#include <utility>
namespace Rust {
@@ -135,6 +139,12 @@ namespace Rust {
// This should really be in a per-crate storage area but it is wiped with every file so eh.
::std::string injected_crate_name;
+ // backend wrapper to GCC GENERIC
+ Backend* backend;
+
+ // backend linemap
+ Linemap* linemap;
+
public:
/* Initialise compiler session. Corresponds to langhook grs_langhook_init(). Note that this is
* called after option handling. */