visit (attr);
}
visit (field.get_visibility ());
- auto name = field.get_field_name ();
+ auto name = field.get_field_name ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (field.get_locus (), std::move (name)));
tokens.push_back (Rust::Token::make (COLON, Location ()));
{
visit (attr);
}
- auto param_name = param.get_name ();
+ auto param_name = param.get_name ().as_string ();
switch (param.get_param_kind ())
{
case MaybeNamedParam::UNNAMED:
void
TokenCollector::visit (IdentifierExpr &ident_expr)
{
- auto ident = ident_expr.get_ident ();
+ auto ident = ident_expr.get_ident ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (ident_expr.get_locus (), std::move (ident)));
}
// const IDENTIFIER : Type ( = Block | IDENTIFIER | -?LITERAL )?
tokens.push_back (Rust::Token::make (CONST, param.get_locus ()));
- auto id = param.get_name ();
+ auto id = param.get_name ().as_string ();
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
tokens.push_back (Rust::Token::make (COLON, Location ()));
visit (param.get_type ());
{
// Syntax:
// IDENTIFIER `=` Type
- auto identifier = binding.get_identifier ();
+ auto identifier = binding.get_identifier ().as_string ();
tokens.push_back (Rust::Token::make_identifier (binding.get_locus (),
std::move (identifier)));
{
// TODO: Add attributes
// visit_items_as_lines (expr.get_attrs ());
- auto id = expr.get_field_name ();
+ auto id = expr.get_field_name ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (expr.get_locus (), std::move (id)));
}
{
visit (expr.get_receiver_expr ());
tokens.push_back (Rust::Token::make (DOT, expr.get_locus ()));
- auto field_name = expr.get_field_name ();
+ auto field_name = expr.get_field_name ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (Location (), std::move (field_name)));
}
// TypeParamBounds :
// TypeParamBound ( + TypeParamBound )* +?
- auto id = param.get_type_representation ();
+ auto id = param.get_type_representation ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (param.get_locus (), std::move (id)));
if (param.has_type_param_bounds ())
TokenCollector::visit (Method &method)
{
visit (method.get_visibility ());
- auto method_name = method.get_method_name ();
+ auto method_name = method.get_method_name ().as_string ();
tokens.push_back (Rust::Token::make (FN_TOK, method.get_locus ()));
tokens.push_back (
Rust::Token::make_identifier (Location (), std::move (method_name)));
visit_items_as_lines (module.get_outer_attrs ());
visit (module.get_visibility ());
- auto name = module.get_name ();
+ auto name = module.get_name ().as_string ();
tokens.push_back (Rust::Token::make (MOD, module.get_locus ()));
tokens.push_back (
Rust::Token::make_identifier (Location (), std::move (name)));
{
case UseTreeRebind::NewBindType::IDENTIFIER: {
tokens.push_back (Rust::Token::make (AS, Location ()));
- auto id = use_tree.get_identifier ();
+ auto id = use_tree.get_identifier ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (use_tree.get_locus (), std::move (id)));
}
visit (function.get_visibility ());
tokens.push_back (Rust::Token::make (FN_TOK, function.get_locus ()));
- auto name = function.get_function_name ();
+ auto name = function.get_function_name ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (Location (), std::move (name)));
if (function.has_generics ())
visit_items_as_lines (type_alias.get_outer_attrs ());
if (type_alias.has_visibility ())
visit (type_alias.get_visibility ());
- auto alias_name = type_alias.get_new_type_name ();
+ auto alias_name = type_alias.get_new_type_name ().as_string ();
tokens.push_back (Rust::Token::make (TYPE, type_alias.get_locus ()));
tokens.push_back (
Rust::Token::make_identifier (Location (), std::move (alias_name)));
visit_items_as_lines (struct_item.get_outer_attrs ());
if (struct_item.has_visibility ())
visit (struct_item.get_visibility ());
- auto struct_name = struct_item.get_identifier ();
+ auto struct_name = struct_item.get_identifier ().as_string ();
tokens.push_back (Rust::Token::make (STRUCT_TOK, struct_item.get_locus ()));
tokens.push_back (
Rust::Token::make_identifier (Location (), std::move (struct_name)));
TokenCollector::visit (TupleStruct &tuple_struct)
{
visit_items_as_lines (tuple_struct.get_outer_attrs ());
- auto struct_name = tuple_struct.get_identifier ();
+ auto struct_name = tuple_struct.get_identifier ().as_string ();
tokens.push_back (Rust::Token::make (STRUCT_TOK, tuple_struct.get_locus ()));
tokens.push_back (
Rust::Token::make_identifier (Location (), std::move (struct_name)));
TokenCollector::visit (EnumItem &item)
{
visit_items_as_lines (item.get_outer_attrs ());
- auto id = item.get_identifier ();
+ auto id = item.get_identifier ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (item.get_locus (), std::move (id)));
}
void
TokenCollector::visit (EnumItemTuple &item)
{
- auto id = item.get_identifier ();
+ auto id = item.get_identifier ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (item.get_locus (), std::move (id)));
tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
void
TokenCollector::visit (EnumItemStruct &item)
{
- auto id = item.get_identifier ();
+ auto id = item.get_identifier ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (item.get_locus (), std::move (id)));
visit_items_as_block (item.get_struct_fields (),
void
TokenCollector::visit (EnumItemDiscriminant &item)
{
- auto id = item.get_identifier ();
+ auto id = item.get_identifier ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (item.get_locus (), std::move (id)));
tokens.push_back (Rust::Token::make (EQUAL, Location ()));
if (enumeration.has_visibility ())
visit (enumeration.get_visibility ());
tokens.push_back (Rust::Token::make (ENUM_TOK, enumeration.get_locus ()));
- auto id = enumeration.get_identifier ();
+ auto id = enumeration.get_identifier ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (enumeration.get_locus (), std::move (id)));
if (enumeration.has_generics ())
TokenCollector::visit (Union &union_item)
{
visit_items_as_lines (union_item.get_outer_attrs ());
- auto id = union_item.get_identifier ();
+ auto id = union_item.get_identifier ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (union_item.get_locus (), "union"));
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
tokens.push_back (Rust::Token::make (STATIC_TOK, item.get_locus ()));
if (item.is_mutable ())
tokens.push_back (Rust::Token::make (MUT, Location ()));
- auto id = item.get_identifier ();
+ auto id = item.get_identifier ().as_string ();
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
tokens.push_back (Rust::Token::make (COLON, Location ()));
visit (item.get_type ());
TokenCollector::visit (TraitItemFunc &item)
{
auto func = item.get_trait_function_decl ();
- auto id = func.get_identifier ();
+ auto id = func.get_identifier ().as_string ();
tokens.push_back (Rust::Token::make (FN_TOK, item.get_locus ()));
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
TokenCollector::visit (TraitItemMethod &item)
{
auto method = item.get_trait_method_decl ();
- auto id = method.get_identifier ();
+ auto id = method.get_identifier ().as_string ();
tokens.push_back (Rust::Token::make (FN_TOK, item.get_locus ()));
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
void
TokenCollector::visit (TraitItemConst &item)
{
- auto id = item.get_identifier ();
+ auto id = item.get_identifier ().as_string ();
indentation ();
tokens.push_back (Rust::Token::make (CONST, item.get_locus ()));
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
void
TokenCollector::visit (TraitItemType &item)
{
- auto id = item.get_identifier ();
+ auto id = item.get_identifier ().as_string ();
indentation ();
tokens.push_back (Rust::Token::make (TYPE, item.get_locus ()));
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
visit (trait.get_visibility ());
- auto id = trait.get_identifier ();
+ auto id = trait.get_identifier ().as_string ();
tokens.push_back (Rust::Token::make (TRAIT, trait.get_locus ()));
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
{
visit (type.get_visibility ());
- auto id = type.get_identifier ();
+ auto id = type.get_identifier ().as_string ();
tokens.push_back (Rust::Token::make (TYPE, Location ()));
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
void
TokenCollector::visit (ExternalStaticItem &item)
{
- auto id = item.get_identifier ();
+ auto id = item.get_identifier ().as_string ();
visit_items_as_lines (item.get_outer_attrs ());
if (item.has_visibility ())
visit (item.get_visibility ());
{
visit (function.get_visibility ());
- auto id = function.get_identifier ();
+ auto id = function.get_identifier ().as_string ();
tokens.push_back (Rust::Token::make (FN_TOK, function.get_locus ()));
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
void
TokenCollector::visit (MacroMatchFragment &match)
{
- auto id = match.get_ident ();
+ auto id = match.get_ident ().as_string ();
auto frag_spec = match.get_frag_spec ().as_string ();
tokens.push_back (Rust::Token::make (DOLLAR_SIGN, Location ()));
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
for (auto &outer_attr : rules_def.get_outer_attrs ())
visit (outer_attr);
- auto rule_name = rules_def.get_rule_name ();
+ auto rule_name = rules_def.get_rule_name ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (rules_def.get_locus (), "macro_rules"));
tokens.push_back (Rust::Token::make (EXCLAM, Location ()));
void
TokenCollector::visit (MetaWord &word)
{
- auto id = word.get_ident ();
+ auto id = word.get_ident ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (word.get_locus (), std::move (id)));
}
TokenCollector::visit (MetaNameValueStr &name)
{
auto pair = name.get_name_value_pair ();
- auto id = std::get<0> (pair);
+ auto id = std::get<0> (pair).as_string ();
auto value = std::get<1> (pair);
tokens.push_back (
Rust::Token::make_identifier (name.get_locus (), std::move (id)));
void
TokenCollector::visit (MetaListPaths &list)
{
- auto id = list.get_ident ();
+ auto id = list.get_ident ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (list.get_locus (), std::move (id)));
tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
void
TokenCollector::visit (MetaListNameValueStr &list)
{
- auto id = list.get_ident ();
+ auto id = list.get_ident ().as_string ();
tokens.push_back (
Rust::Token::make_identifier (list.get_locus (), std::move (id)));
tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
{
tokens.push_back (Rust::Token::make (MUT, Location ()));
}
- auto id = pattern.get_ident ();
+ auto id = pattern.get_ident ().as_string ();
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
if (pattern.has_pattern_to_bind ())
{
TokenCollector::visit (StructPatternFieldIdentPat &pattern)
{
visit_items_as_lines (pattern.get_outer_attrs ());
- auto id = pattern.get_identifier ();
+ auto id = pattern.get_identifier ().as_string ();
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
tokens.push_back (Rust::Token::make (COLON, pattern.get_locus ()));
visit (pattern.get_ident_pattern ());
if (pattern.is_mut ())
tokens.push_back (Rust::Token::make (MUT, Location ()));
- auto id = pattern.get_identifier ();
+ auto id = pattern.get_identifier ().as_string ();
tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
}
std::string
Module::as_string () const
{
- std::string str = VisItem::as_string () + "mod " + module_name;
+ std::string str = VisItem::as_string () + "mod " + module_name.as_string ();
// Return early if we're dealing with an unloaded module as their body resides
// in a different file
if (has_mut)
str += " mut";
- str += " " + name;
+ str += " " + name.as_string ();
// DEBUG: null pointer check
if (type == nullptr)
{
std::string str = VisItem::as_string ();
- str += "struct " + struct_name;
+ str += "struct " + struct_name.as_string ();
// generic params
str += "\n Generic params: ";
str += vis.as_string () + " " + qualifiers.as_string ();
- str += " fn " + method_name;
+ str += " fn " + method_name.as_string ();
// generic params
str += "\n Generic params: ";
{
std::string str = VisItem::as_string ();
- str += "struct " + struct_name;
+ str += "struct " + struct_name.as_string ();
// generic params
str += "\n Generic params: ";
// nothing to add, just path
break;
case IDENTIFIER:
- path_str += " as " + identifier;
+ path_str += " as " + identifier.as_string ();
break;
case WILDCARD:
path_str += " as _";
Enum::as_string () const
{
std::string str = VisItem::as_string ();
- str += enum_name;
+ str += enum_name.as_string ();
// generic params
str += "\n Generic params: ";
if (has_unsafe)
str += "unsafe ";
- str += "trait " + name;
+ str += "trait " + name.as_string ();
// generic params
str += "\n Generic params: ";
{
std::string str = VisItem::as_string ();
- str += "union " + union_name;
+ str += "union " + union_name.as_string ();
// generic params
str += "\n Generic params: ";
str += "void ";
}
- str += function_name;
+ str += function_name.as_string ();
if (has_generics ())
{
{
std::string str = VisItem::as_string ();
- str += " " + new_type_name;
+ str += " " + new_type_name.as_string ();
// generic params
str += "\n Generic params: ";
// TODO: deal with macro_2_0
str += "macro_rules!";
- str += rule_name;
+ str += rule_name.as_string ();
str += "\n Macro rules: ";
if (rules.empty ())
FieldAccessExpr::as_string () const
{
// TODO: rewrite dump to better reflect non-literal exprs
- return receiver->as_string () + "." + field;
+ return receiver->as_string () + "." + field.as_string ();
}
std::string
std::string
MacroMatchFragment::as_string () const
{
- return "$" + ident + ": " + frag_spec.as_string ();
+ return "$" + ident.as_string () + ": " + frag_spec.as_string ();
}
std::string
else
str += outer_attr.as_string ();
- str += "\n Identifier: " + type_representation;
+ str += "\n Identifier: " + type_representation.as_string ();
str += "\n Type param bounds: ";
if (!has_type_param_bounds ())
StructExprFieldIdentifierValue::as_string () const
{
// TODO: rewrite to work with non-linearisable exprs
- return field_name + " : " + StructExprFieldWithVal::as_string ();
+ return field_name.as_string () + " : " + StructExprFieldWithVal::as_string ();
}
std::string
EnumItem::as_string () const
{
std::string str = VisItem::as_string ();
- str += variant_name;
+ str += variant_name.as_string ();
return str;
}
if (has_visibility ())
str += "\n" + visibility.as_string ();
- str += " " + field_name + " : " + field_type->as_string ();
+ str += " " + field_name.as_string () + " : " + field_type->as_string ();
return str;
}
{
auto str = append_attributes (outer_attrs, OUTER);
- str += "type " + item_name + ";";
+ str += "type " + item_name.as_string () + ";";
return str;
}
str += "mut ";
// add name
- str += item_name;
+ str += item_name.as_string ();
// add type on new line
str += "\n Type: " + item_type->as_string ();
str += "fn ";
// add name
- str += item_name;
+ str += item_name.as_string ();
// generic params
str += "\n Generic params: ";
std::string
TraitFunctionDecl::as_string () const
{
- std::string str = qualifiers.as_string () + "fn " + function_name;
+ std::string str
+ = qualifiers.as_string () + "fn " + function_name.as_string ();
// generic params
str += "\n Generic params: ";
std::string
TraitMethodDecl::as_string () const
{
- std::string str = qualifiers.as_string () + "fn " + function_name;
+ std::string str
+ = qualifiers.as_string () + "fn " + function_name.as_string ();
// generic params
str += "\n Generic params: ";
// TODO: rewrite to work with non-linearisable exprs
std::string str = append_attributes (outer_attrs, OUTER);
- str += "\nconst " + name + " : " + type->as_string ();
+ str += "\nconst " + name.as_string () + " : " + type->as_string ();
if (has_expression ())
str += " = " + expr->as_string ();
{
std::string str = append_attributes (outer_attrs, OUTER);
- str += "\ntype " + name;
+ str += "\ntype " + name.as_string ();
str += "\n Type param bounds: ";
if (!has_type_param_bounds ())
case UNNAMED:
break;
case IDENTIFIER:
- str = name + " : ";
+ str = name.as_string () + " : ";
break;
case WILDCARD:
str = "_ : ";
std::string
MetaListPaths::as_string () const
{
- std::string str = ident + "(";
+ std::string str = ident.as_string () + "(";
auto i = paths.begin ();
auto e = paths.end ();
std::string
MetaListNameValueStr::as_string () const
{
- std::string str = ident + "(";
+ std::string str = ident.as_string () + "(";
auto i = strs.begin ();
auto e = strs.end ();
// file that contains the 'mod <file>;' directive
std::string including_fpath (outer_filename);
- std::string expected_file_path = module_name + ".rs";
+ std::string expected_file_path = module_name.as_string () + ".rs";
std::string expected_dir_path = "mod.rs";
auto dir_slash_pos = including_fpath.rfind (file_separator);
bool file_mod_found = file_exists (file_mod_path);
// Then, search for <directory>/<module_name>/mod.rs
- std::string dir_mod_path
- = current_directory_name + module_name + file_separator + expected_dir_path;
+ std::string dir_mod_path = current_directory_name + module_name.as_string ()
+ + file_separator + expected_dir_path;
bool dir_mod_found = file_exists (dir_mod_path);
bool multiple_candidates_found = file_mod_found && dir_mod_found;
if (multiple_candidates_found)
rust_error_at (locus,
"two candidates found for module %s: %s.rs and %s%smod.rs",
- module_name.c_str (), module_name.c_str (),
- module_name.c_str (), file_separator);
+ module_name.as_string ().c_str (),
+ module_name.as_string ().c_str (),
+ module_name.as_string ().c_str (), file_separator);
if (no_candidates_found)
rust_error_at (locus, "no candidate found for module %s",
- module_name.c_str ());
+ module_name.as_string ().c_str ());
if (no_candidates_found || multiple_candidates_found)
return;
bool
MetaListNameValueStr::check_cfg_predicate (const Session &session) const
{
- if (ident == "all")
+ if (ident.as_string () == "all")
{
for (const auto &str : strs)
{
}
return true;
}
- else if (ident == "any")
+ else if (ident.as_string () == "any")
{
for (const auto &str : strs)
{
}
return false;
}
- else if (ident == "not")
+ else if (ident.as_string () == "not")
{
if (strs.size () != 1)
{
"cfg predicate could not be checked for "
"MetaListNameValueStr with ident of "
"'%s' - ident must be 'all' or 'any'",
- ident.c_str ());
+ ident.as_string ().c_str ());
return false;
}
}
bool
MetaListPaths::check_cfg_predicate (const Session &session) const
{
- if (ident == "all")
+ if (ident.as_string () == "all")
{
for (const auto &path : paths)
{
}
return true;
}
- else if (ident == "any")
+ else if (ident.as_string () == "any")
{
for (const auto &path : paths)
{
}
return false;
}
- else if (ident == "not")
+ else if (ident.as_string () == "not")
{
if (paths.size () != 1)
{
"cfg predicate could not be checked for "
"MetaListNameValueStr with ident of "
"'%s' - ident must be 'all' or 'any'",
- ident.c_str ());
+ ident.as_string ().c_str ());
return false;
}
}
bool
MetaWord::check_cfg_predicate (const Session &session) const
{
- return session.options.target_data.has_key (ident);
+ return session.options.target_data.has_key (ident.as_string ());
}
bool
// DEBUG
rust_debug (
"checked key-value pair for cfg: '%s', '%s' - is%s in target data",
- ident.c_str (), str.c_str (),
- session.options.target_data.has_key_value_pair (ident, str) ? "" : " not");
+ ident.as_string ().c_str (), str.c_str (),
+ session.options.target_data.has_key_value_pair (ident.as_string (), str)
+ ? ""
+ : " not");
- return session.options.target_data.has_key_value_pair (ident, str);
+ return session.options.target_data.has_key_value_pair (ident.as_string (),
+ str);
}
bool
// FIXME: What location do we put here? Is the literal above supposed to have
// an empty location as well?
// Should MetaNameValueStr keep a location?
- return Attribute (SimplePath::from_str (ident, ident_locus),
+ return Attribute (SimplePath::from_str (ident.as_string (), ident_locus),
std::unique_ptr<AttrInputLiteral> (
new AttrInputLiteral (std::move (lit_expr))));
}
Attribute
MetaWord::to_attribute () const
{
- return Attribute (SimplePath::from_str (ident, ident_locus), nullptr);
+ return Attribute (SimplePath::from_str (ident.as_string (), ident_locus),
+ nullptr);
}
Attribute
std::unique_ptr<AttrInputMetaItemContainer> new_seq_container (
new AttrInputMetaItemContainer (std::move (new_seq)));
- return Attribute (SimplePath::from_str (ident, ident_locus),
+ return Attribute (SimplePath::from_str (ident.as_string (), ident_locus),
std::move (new_seq_container));
}
std::unique_ptr<AttrInputMetaItemContainer> new_seq_container (
new AttrInputMetaItemContainer (std::move (new_seq)));
- return Attribute (SimplePath::from_str (ident, ident_locus),
+ return Attribute (SimplePath::from_str (ident.as_string (), ident_locus),
std::move (new_seq_container));
}
}
} // namespace AST
+
+std::ostream &
+operator<< (std::ostream &os, Identifier const &i)
+{
+ return os << i.as_string ();
+}
+
} // namespace Rust
namespace Rust {
// TODO: remove typedefs and make actual types for these
-typedef std::string Identifier;
typedef int TupleIndex;
struct Session;
struct MacroExpander;
+class Identifier
+{
+public:
+ Identifier (std::string ident = "")
+ : ident (ident), node_id (Analysis::Mappings::get ()->get_next_node_id ())
+ {}
+
+ NodeId get_node_id () const { return node_id; }
+ const std::string &as_string () const { return ident; }
+
+ bool empty () const { return ident.empty (); }
+
+private:
+ std::string ident;
+ NodeId node_id;
+};
+
+std::ostream &
+operator<< (std::ostream &os, Identifier const &i);
+
namespace AST {
// foward decl: ast visitor
class ASTVisitor;
public:
/**
* Get the kind of Node this is. This is used to differentiate various AST
- * elements with very little overhead when extracting the derived type through
- * static casting is not necessary.
+ * elements with very little overhead when extracting the derived type
+ * through static casting is not necessary.
*/
- // FIXME: Mark this as `= 0` in the future to make sure every node implements
- // it
+ // FIXME: Mark this as `= 0` in the future to make sure every node
+ // implements it
virtual Kind get_ast_kind () const { return Kind::UNKNOWN; }
};
virtual std::string as_string () const = 0;
- /* Converts token tree to a flat token stream. Tokens must be pointer to avoid
- * mutual dependency with Token. */
+ /* Converts token tree to a flat token stream. Tokens must be pointer to
+ * avoid mutual dependency with Token. */
virtual std::vector<std::unique_ptr<Token>> to_token_stream () const = 0;
protected:
const_TokenPtr tok_ref;
- /* new idea: wrapper around const_TokenPtr used for heterogeneuous storage in
- * token trees. rather than convert back and forth when parsing macros, just
- * wrap it. */
+ /* new idea: wrapper around const_TokenPtr used for heterogeneuous storage
+ * in token trees. rather than convert back and forth when parsing macros,
+ * just wrap it. */
public:
// Unique pointer custom clone function
// No virtual for now as not polymorphic but can be in future
/*virtual*/ Token *clone_token_impl () const { return new Token (*this); }
- /* Use covariance to implement clone function as returning this object rather
- * than base */
+ /* Use covariance to implement clone function as returning this object
+ * rather than base */
Token *clone_token_tree_impl () const final override
{
return clone_token_impl ();
}
- /* Use covariance to implement clone function as returning this object rather
- * than base */
+ /* Use covariance to implement clone function as returning this object
+ * rather than base */
Token *clone_macro_match_impl () const final override
{
return clone_token_impl ();
};
private:
- /* TODO: maybe make subclasses of each type of literal with their typed values
- * (or generics) */
+ /* TODO: maybe make subclasses of each type of literal with their typed
+ * values (or generics) */
std::string value_as_string;
LitType type;
PrimitiveCoreType type_hint;
bool is_error () const { return type == ERROR; }
};
-/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to
- * be defined */
+/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr
+ * to be defined */
class AttrInputLiteral;
/* TODO: move applicable stuff into here or just don't include it because
// Call to parse attribute body to meta item syntax.
void parse_attr_to_meta_item ();
- /* Determines whether cfg predicate is true and item with attribute should not
- * be stripped. Attribute body must already be parsed to meta item. */
+ /* Determines whether cfg predicate is true and item with attribute should
+ * not be stripped. Attribute body must already be parsed to meta item. */
bool check_cfg_predicate (const Session &session) const;
// Returns whether body has been parsed to meta item form or not.
std::vector<Attribute> separate_cfg_attrs () const;
protected:
- // not virtual as currently no subclasses of Attribute, but could be in future
+ // not virtual as currently no subclasses of Attribute, but could be in
+ // future
/*virtual*/ Attribute *clone_attribute_impl () const
{
return new Attribute (*this);
DelimType get_delim_type () const { return delim_type; }
};
-/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to
- * be defined */
+/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr
+ * to be defined */
class AttrInputLiteral;
// abstract base meta item class
// Forward decl - defined in rust-macro.h
class MetaListNameValueStr;
-/* Base statement abstract class. Note that most "statements" are not allowed in
- * top-level module scope - only a subclass of statements called "items" are. */
+/* Base statement abstract class. Note that most "statements" are not allowed
+ * in top-level module scope - only a subclass of statements called "items"
+ * are. */
class Stmt : public Node
{
public:
// pure virtual clone implementation
virtual ExprWithoutBlock *clone_expr_without_block_impl () const = 0;
- /* Save having to specify two clone methods in derived classes by making expr
- * clone return exprwithoutblock clone. Hopefully won't affect performance too
- * much. */
+ /* Save having to specify two clone methods in derived classes by making
+ * expr clone return exprwithoutblock clone. Hopefully won't affect
+ * performance too much. */
ExprWithoutBlock *clone_expr_impl () const final override
{
return clone_expr_without_block_impl ();
/* HACK: IdentifierExpr, delete when figure out identifier vs expr problem in
* Pratt parser */
-/* Alternatively, identifiers could just be represented as single-segment paths
+/* Alternatively, identifiers could just be represented as single-segment
+ * paths
*/
class IdentifierExpr : public ExprWithoutBlock
{
locus (locus)
{}
- std::string as_string () const override { return ident; }
+ std::string as_string () const override { return ident.as_string (); }
Location get_locus () const override final { return locus; }
// Clone function implementation as pure virtual method
virtual TypeNoBounds *clone_type_no_bounds_impl () const = 0;
- /* Save having to specify two clone methods in derived classes by making type
- * clone return typenobounds clone. Hopefully won't affect performance too
- * much. */
+ /* Save having to specify two clone methods in derived classes by making
+ * type clone return typenobounds clone. Hopefully won't affect performance
+ * too much. */
TypeNoBounds *clone_type_impl () const final override
{
return clone_type_no_bounds_impl ();
TypeNoBounds () : Type () {}
};
-/* Abstract base class representing a type param bound - Lifetime and TraitBound
- * extends it */
+/* Abstract base class representing a type param bound - Lifetime and
+ * TraitBound extends it */
class TypeParamBound : public Visitable
{
public:
std::string get_lifetime_name () const { return lifetime_name; }
protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
+ /* Use covariance to implement clone function as returning this object
+ * rather than base */
Lifetime *clone_type_param_bound_impl () const override
{
return new Lifetime (node_id, lifetime_type, lifetime_name, locus);
}
};
-/* Base generic parameter in AST. Abstract - can be represented by a Lifetime or
- * Type param */
+/* Base generic parameter in AST. Abstract - can be represented by a Lifetime
+ * or Type param */
class GenericParam : public Visitable
{
public:
Kind get_kind () const override final { return Kind::Lifetime; }
protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
+ /* Use covariance to implement clone function as returning this object
+ * rather than base */
LifetimeParam *clone_generic_param_impl () const override
{
return new LifetimeParam (*this);
} // namespace AST
} // namespace Rust
+namespace std {
+template <> struct less<Rust::Identifier>
+{
+ bool operator() (const Rust::Identifier &lhs,
+ const Rust::Identifier &rhs) const
+ {
+ return lhs.as_string () < rhs.as_string ();
+ }
+};
+} // namespace std
+
#endif
locus (locus)
{}
- std::string as_string () const override { return field_name; }
+ std::string as_string () const override { return field_name.as_string (); }
Location get_locus () const override final { return locus; }
void accept_vis (ASTVisitor &vis) override;
- std::string get_field_name () const { return field_name; }
+ std::string get_field_name () const { return field_name.as_string (); }
Location get_locus () const override final { return locus; }
// Creates an error state method.
static Method create_error ()
{
- return Method ("", FunctionQualifiers (Location (), NONE, true),
+ return Method ({""}, FunctionQualifiers (Location (), NONE, true),
std::vector<std::unique_ptr<GenericParam>> (),
SelfParam::create_error (), std::vector<FunctionParam> (),
nullptr, WhereClause::create_empty (), nullptr,
Location get_locus () const override final { return locus; }
// Invalid if name is empty, so base stripping on that.
- void mark_for_strip () override { module_name = ""; }
+ void mark_for_strip () override { module_name = {""}; }
bool is_marked_for_strip () const override { return module_name.empty (); }
protected:
Location get_locus () const override final { return locus; }
// Invalid if name is empty, so base stripping on that.
- void mark_for_strip () override { struct_name = ""; }
+ void mark_for_strip () override { struct_name = {""}; }
bool is_marked_for_strip () const override { return struct_name.empty (); }
Identifier get_struct_name () const { return struct_name; }
Identifier get_identifier () const { return variant_name; }
// Based on idea that name is never empty.
- void mark_for_strip () override { variant_name = ""; }
+ void mark_for_strip () override { variant_name = {""}; }
bool is_marked_for_strip () const override { return variant_name.empty (); }
protected:
Identifier get_identifier () const { return enum_name; }
// Invalid if name is empty, so base stripping on that.
- void mark_for_strip () override { enum_name = ""; }
+ void mark_for_strip () override { enum_name = {""}; }
bool is_marked_for_strip () const override { return enum_name.empty (); }
// TODO: this mutable getter seems really dodgy. Think up better way.
void accept_vis (ASTVisitor &vis) override;
// Invalid if name is empty, so base stripping on that.
- void mark_for_strip () override { union_name = ""; }
+ void mark_for_strip () override { union_name = {""}; }
bool is_marked_for_strip () const override { return union_name.empty (); }
// TODO: this mutable getter seems really dodgy. Think up better way.
std::string as_string () const;
// Invalid if function name is empty, so base stripping on that.
- void mark_for_strip () { function_name = ""; }
+ void mark_for_strip () { function_name = {""}; }
bool is_marked_for_strip () const { return function_name.empty (); }
// TODO: this mutable getter seems really dodgy. Think up better way.
std::string as_string () const;
// Invalid if method name is empty, so base stripping on that.
- void mark_for_strip () { function_name = ""; }
+ void mark_for_strip () { function_name = {""}; }
bool is_marked_for_strip () const { return function_name.empty (); }
// TODO: this mutable getter seems really dodgy. Think up better way.
void accept_vis (ASTVisitor &vis) override;
// Invalid if name is empty, so base stripping on that.
- void mark_for_strip () override { name = ""; }
+ void mark_for_strip () override { name = {""}; }
bool is_marked_for_strip () const override { return name.empty (); }
// TODO: this mutable getter seems really dodgy. Think up better way.
void accept_vis (ASTVisitor &vis) override;
// Invalid if trait name is empty, so base stripping on that.
- void mark_for_strip () override { name = ""; }
+ void mark_for_strip () override { name = {""}; }
bool is_marked_for_strip () const override { return name.empty (); }
// TODO: think of better way to do this
void accept_vis (ASTVisitor &vis) override;
// Based on idea that nane should never be empty.
- void mark_for_strip () override { item_name = ""; };
+ void mark_for_strip () override { item_name = {""}; };
bool is_marked_for_strip () const override { return item_name.empty (); };
// TODO: this mutable getter seems really dodgy. Think up better way.
void accept_vis (ASTVisitor &vis) override;
// Invalid if rule name is empty, so base stripping on that.
- void mark_for_strip () override { rule_name = ""; }
+ void mark_for_strip () override { rule_name = {""}; }
bool is_marked_for_strip () const override { return rule_name.empty (); }
// TODO: this mutable getter seems really dodgy. Think up better way.
: ident (std::move (ident)), ident_locus (ident_locus)
{}
- std::string as_string () const override { return ident; }
+ std::string as_string () const override { return ident.as_string (); }
void accept_vis (ASTVisitor &vis) override;
std::string as_string () const override
{
- return ident + " = \"" + str + "\"";
+ return ident.as_string () + " = \"" + str + "\"";
}
void accept_vis (ASTVisitor &vis) override;
rust_assert (get_kind () == Kind::Either);
auto segment = std::unique_ptr<TypePathSegment> (
- new TypePathSegment (path, false, locus));
+ new TypePathSegment (path.as_string (), false, locus));
auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
segments.emplace_back (std::move (segment));
GenericArgsBinding::as_string () const
{
// TODO: rewrite to work with non-literalisable types
- return identifier + " = " + type->as_string ();
+ return identifier.as_string () + " = " + type->as_string ();
}
std::string
ConstGenericParam::as_string () const
{
std::string str ("ConstGenericParam: ");
- str += "const " + name + ": " + type->as_string ();
+ str += "const " + name.as_string () + ": " + type->as_string ();
if (has_default_value ())
str += " = " + get_default_value ().as_string ();
// Creates an error state generic args binding.
static GenericArgsBinding create_error ()
{
- return GenericArgsBinding ("", nullptr);
+ return GenericArgsBinding ({""}, nullptr);
}
// Pointer type for type in constructor to enable polymorphism
static GenericArg create_error ()
{
- return GenericArg (nullptr, nullptr, "", Kind::Error, Location ());
+ return GenericArg (nullptr, nullptr, {""}, Kind::Error, Location ());
}
static GenericArg create_const (std::unique_ptr<Expr> expression)
{
auto locus = expression->get_locus ();
- return GenericArg (std::move (expression), nullptr, "", Kind::Const, locus);
+ return GenericArg (std::move (expression), nullptr, {""}, Kind::Const,
+ locus);
}
static GenericArg create_type (std::unique_ptr<Type> type)
{
auto locus = type->get_locus ();
- return GenericArg (nullptr, std::move (type), "", Kind::Type, locus);
+ return GenericArg (nullptr, std::move (type), {""}, Kind::Type, locus);
}
static GenericArg create_ambiguous (Identifier path, Location locus)
{
rust_assert (kind == Kind::Either);
- return path;
+ return path.as_string ();
}
std::string as_string () const
case Kind::Error:
gcc_unreachable ();
case Kind::Either:
- return "Ambiguous: " + path;
+ return "Ambiguous: " + path.as_string ();
case Kind::Const:
return "Const: { " + expression->as_string () + " }";
case Kind::Type:
if (is_mut)
str += "mut ";
- str += variable_ident;
+ str += variable_ident.as_string ();
if (has_pattern_to_bind ())
str += " @ " + to_bind->as_string ();
str += "\n";
- str += ident + " : " + ident_pattern->as_string ();
+ str += ident.as_string () + " : " + ident_pattern->as_string ();
return str;
}
if (has_mut)
str += "mut ";
- str += ident;
+ str += ident.as_string ();
return str;
}
// Creates an error state param.
static MaybeNamedParam create_error ()
{
- return MaybeNamedParam ("", UNNAMED, nullptr, {}, Location ());
+ return MaybeNamedParam ({""}, UNNAMED, nullptr, {}, Location ());
}
Location get_locus () const { return locus; }
if (!converted_item)
continue;
auto key_value = converted_item->get_name_value_pair ();
- if (key_value.first.compare ("since") == 0)
+ if (key_value.first.as_string ().compare ("since") == 0)
{
// valid, but this is handled by Cargo and some third-party audit
// tools
continue;
}
- else if (key_value.first.compare ("note") == 0)
+ else if (key_value.first.as_string ().compare ("note") == 0)
{
const auto &msg_str = key_value.second;
if (value)
else
{
rust_error_at (attr.get_locus (), "unknown meta item %qs",
- key_value.first.c_str ());
+ key_value.first.as_string ().c_str ());
}
}
}
rust_assert (adt->number_of_variants () == 1);
TyTy::VariantDef *variant = adt->get_variants ().at (0);
- bool ok
- = variant->lookup_field (expr.get_field_name (), nullptr, &field_index);
+ bool ok = variant->lookup_field (expr.get_field_name ().as_string (),
+ nullptr, &field_index);
rust_assert (ok);
}
else if (receiver->get_kind () == TyTy::TypeKind::REF)
rust_assert (adt->number_of_variants () == 1);
TyTy::VariantDef *variant = adt->get_variants ().at (0);
- bool ok
- = variant->lookup_field (expr.get_field_name (), nullptr, &field_index);
+ bool ok = variant->lookup_field (expr.get_field_name ().as_string (),
+ nullptr, &field_index);
rust_assert (ok);
tree indirect = indirect_expression (receiver_ref, expr.get_locus ());
&resolved_type);
rust_assert (ok);
- std::string name = item.get_item_name ();
+ std::string name = item.get_item_name ().as_string ();
// FIXME this is assuming C ABI
std::string asm_name = name;
}
tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
- std::string ir_symbol_name = function.get_item_name ();
- std::string asm_name = function.get_item_name ();
+ std::string ir_symbol_name = function.get_item_name ().as_string ();
+ std::string asm_name = function.get_item_name ().as_string ();
if (fntype->get_abi () == ABI::RUST)
{
// then we need to get the canonical path of it and mangle it
if (!pattern.is_mut ())
decl_type = ctx->get_backend ()->immutable_type (decl_type);
- compiled_param
- = ctx->get_backend ()->parameter_variable (fndecl,
- pattern.get_identifier (),
- decl_type, locus);
+ compiled_param = ctx->get_backend ()->parameter_variable (
+ fndecl, pattern.get_identifier ().as_string (), decl_type, locus);
}
void
auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);
HIR::TraitFunctionDecl &function = func.get_decl ();
tree fndecl
- = compile_function (function.get_function_name (), function.get_self (),
- function.get_function_params (),
+ = compile_function (function.get_function_name ().as_string (),
+ function.get_self (), function.get_function_params (),
function.get_qualifiers (), vis,
func.get_outer_attrs (), func.get_locus (),
func.get_block_expr ().get (), canonical_path, fntype);
ctx->push_const_context ();
tree fndecl
- = compile_function (function.get_function_name (),
+ = compile_function (function.get_function_name ().as_string (),
function.get_self_param (),
function.get_function_params (),
function.get_qualifiers (), function.get_visibility (),
= static_cast<HIR::StructPatternFieldIdent &> (*field.get ());
size_t offs = 0;
- ok
- = variant->lookup_field (ident.get_identifier (), nullptr, &offs);
+ ok = variant->lookup_field (ident.get_identifier ().as_string (),
+ nullptr, &offs);
rust_assert (ok);
tree binding = error_mark_node;
Analysis::NodeMapping mappings_copy1 = field.get_mappings ();
Analysis::NodeMapping mappings_copy2 = field.get_mappings ();
- HIR::PathIdentSegment ident_seg (field.get_field_name ());
+ HIR::PathIdentSegment ident_seg (field.get_field_name ().as_string ());
HIR::PathExprSegment seg (mappings_copy1, ident_seg, field.get_locus (),
HIR::GenericArgs::create_empty ());
HIR::PathInExpression expr (mappings_copy2, {seg}, field.get_locus (), false,
if (!pattern.is_mut ())
translated_type = ctx->get_backend ()->immutable_type (translated_type);
- Bvariable *var
- = ctx->get_backend ()->local_variable (fndecl, pattern.get_identifier (),
- translated_type, NULL /*decl_var*/,
- pattern.get_locus ());
+ Bvariable *var = ctx->get_backend ()->local_variable (
+ fndecl, pattern.get_identifier ().as_string (), translated_type,
+ NULL /*decl_var*/, pattern.get_locus ());
HirId stmt_id = pattern.get_pattern_mappings ().get_hirid ();
ctx->insert_var_decl (stmt_id, var);
HIR::Function *fn = static_cast<HIR::Function *> (impl_item.get ());
bool found_associated_item
- = fn->get_function_name ().compare (ref->get_identifier ()) == 0;
+ = fn->get_function_name ().as_string ().compare (ref->get_identifier ())
+ == 0;
if (found_associated_item)
associated_function = fn;
}
// Some intrinsics are safe to call
if (parent_block->get_abi () == Rust::ABI::INTRINSIC
- && is_safe_intrinsic (maybe_fn->get_item_name ()))
+ && is_safe_intrinsic (maybe_fn->get_item_name ().as_string ()))
return;
rust_error_at (locus,
// TODO not only fn main can be a entry point.
void visit (HIR::Function &function) override
{
- if (function.get_function_name () == "main")
+ if (function.get_function_name ().as_string () == "main")
{
entryPoints.push_back (function.get_mappings ().get_hirid ());
}
// get the field index
size_t index;
TyTy::StructFieldType *field;
- bool ok = variant->lookup_field (expr.get_field_name (), &field, &index);
+ bool ok = variant->lookup_field (expr.get_field_name ().as_string (), &field,
+ &index);
rust_assert (ok);
if (index >= variant->num_fields ())
{
= mappings->lookup_associated_impl (hirId);
if (!implBlock->has_trait_ref ())
{
- rust_warning_at (function.get_locus (), 0,
- "associated function is never used: %<%s%>",
- function.get_function_name ().c_str ());
+ rust_warning_at (
+ function.get_locus (), 0,
+ "associated function is never used: %<%s%>",
+ function.get_function_name ().as_string ().c_str ());
}
}
else
{
- rust_warning_at (function.get_locus (), 0,
- "function is never used: %<%s%>",
- function.get_function_name ().c_str ());
+ rust_warning_at (
+ function.get_locus (), 0, "function is never used: %<%s%>",
+ function.get_function_name ().as_string ().c_str ());
}
}
}
HirId hirId = stct.get_mappings ().get_hirid ();
if (should_warn (hirId) && !stct.get_visibility ().is_public ())
{
- bool name_starts_underscore = stct.get_identifier ().at (0) == '_';
+ bool name_starts_underscore
+ = stct.get_identifier ().as_string ().at (0) == '_';
if (!name_starts_underscore)
rust_warning_at (stct.get_locus (), 0,
"struct is never constructed: %<%s%>",
- stct.get_identifier ().c_str ());
+ stct.get_identifier ().as_string ().c_str ());
}
else
{
{
rust_warning_at (field.get_locus (), 0,
"field is never read: %<%s%>",
- field.get_field_name ().c_str ());
+ field.get_field_name ().as_string ().c_str ());
}
}
}
{
rust_warning_at (stct.get_locus (), 0,
"struct is never constructed: %<%s%>",
- stct.get_identifier ().c_str ());
+ stct.get_identifier ().as_string ().c_str ());
}
}
auto big_self_type = builder.single_type_path ("Self");
return std::unique_ptr<TraitImplItem> (
- new Method ("clone", builder.fn_qualifiers (), /* generics */ {},
+ new Method ({"clone"}, builder.fn_qualifiers (), /* generics */ {},
SelfParam (Lifetime::error (), /* is_mut */ false, loc),
/* function params */ {}, std::move (big_self_type),
WhereClause::create_empty (), std::move (block),
clone_call (builder.ref (builder.tuple_idx ("self", idx))));
auto path = std::unique_ptr<Expr> (new PathInExpression (
- builder.path_in_expression ({item.get_identifier ()})));
+ builder.path_in_expression ({item.get_identifier ().as_string ()})));
auto constructor = builder.call (std::move (path), std::move (cloned_fields));
- expanded
- = clone_impl (clone_fn (std::move (constructor)), item.get_identifier ());
+ expanded = clone_impl (clone_fn (std::move (constructor)),
+ item.get_identifier ().as_string ());
}
void
{
if (item.is_unit_struct ())
{
- auto unit_ctor = builder.struct_expr_struct (item.get_struct_name ());
+ auto unit_ctor
+ = builder.struct_expr_struct (item.get_struct_name ().as_string ());
expanded = clone_impl (clone_fn (std::move (unit_ctor)),
- item.get_struct_name ());
+ item.get_struct_name ().as_string ());
return;
}
auto cloned_fields = std::vector<std::unique_ptr<StructExprField>> ();
for (auto &field : item.get_fields ())
{
- auto name = field.get_field_name ();
+ auto name = field.get_field_name ().as_string ();
auto expr = clone_call (
builder.ref (builder.field_access (builder.identifier ("self"), name)));
builder.struct_expr_field (std::move (name), std::move (expr)));
}
- auto ctor
- = builder.struct_expr (item.get_struct_name (), std::move (cloned_fields));
- expanded = clone_impl (clone_fn (std::move (ctor)), item.get_struct_name ());
+ auto ctor = builder.struct_expr (item.get_struct_name ().as_string (),
+ std::move (cloned_fields));
+ expanded = clone_impl (clone_fn (std::move (ctor)),
+ item.get_struct_name ().as_string ());
}
void
auto block = builder.block (std::move (stmts), std::move (tail_expr));
- expanded = clone_impl (clone_fn (std::move (block)), item.get_identifier ());
+ expanded = clone_impl (clone_fn (std::move (block)),
+ item.get_identifier ().as_string ());
}
} // namespace AST
void
DeriveCopy::visit_struct (StructStruct &item)
{
- expanded = copy_impl (item.get_struct_name ());
+ expanded = copy_impl (item.get_struct_name ().as_string ());
}
void
DeriveCopy::visit_tuple (TupleStruct &item)
{
- expanded = copy_impl (item.get_struct_name ());
+ expanded = copy_impl (item.get_struct_name ().as_string ());
}
void
DeriveCopy::visit_enum (Enum &item)
{
- expanded = copy_impl (item.get_identifier ());
+ expanded = copy_impl (item.get_identifier ().as_string ());
}
void
DeriveCopy::visit_union (Union &item)
{
- expanded = copy_impl (item.get_identifier ());
+ expanded = copy_impl (item.get_identifier ().as_string ());
}
} // namespace AST
size_t offs_end = source.get_offs ();
if (in_repetition)
sub_stack.append_fragment (
- MatchedFragment (fragment->get_ident (), offs_begin, offs_end));
+ MatchedFragment (fragment->get_ident ().as_string (),
+ offs_begin, offs_end));
else
sub_stack.insert_metavar (
- MatchedFragment (fragment->get_ident (), offs_begin, offs_end));
+ MatchedFragment (fragment->get_ident ().as_string (),
+ offs_begin, offs_end));
}
break;
// creating a metavariable, but a repetition of one, which is
// really different.
sub_stack.append_fragment (
- MatchedFragment (fragment->get_ident (), offs_begin,
- offs_end));
+ MatchedFragment (fragment->get_ident ().as_string (),
+ offs_begin, offs_end));
}
break;
AST::MacroMatchFragment &fragment)
{
auto &stack_map = sub_stack.peek ();
- auto it = stack_map.find (fragment.get_ident ());
+ auto it = stack_map.find (fragment.get_ident ().as_string ());
if (it == stack_map.end ())
- sub_stack.insert_matches (fragment.get_ident (),
+ sub_stack.insert_matches (fragment.get_ident ().as_string (),
MatchedFragmentContainer::zero ());
}
{
for (auto &field : fields)
{
- if (field.get_field_name ().compare (new_field.get_field_name ()) == 0)
+ if (field.get_field_name ().as_string ().compare (
+ new_field.get_field_name ().as_string ())
+ == 0)
{
RichLocation r (new_field.get_locus ());
r.add_range (field.get_locus ());
rust_error_at (r, "duplicate field name %qs",
- field.get_field_name ().c_str ());
+ field.get_field_name ().as_string ().c_str ());
return true;
}
}
UNKNOWN_LOCAL_DEFID);
Analysis::NodeMapping mapping2 (mapping1);
- HIR::PathIdentSegment ident_seg (expr.get_ident ());
+ HIR::PathIdentSegment ident_seg (expr.get_ident ().as_string ());
HIR::PathExprSegment seg (mapping1, ident_seg, expr.get_locus (),
HIR::GenericArgs::create_empty ());
translated = new HIR::PathInExpression (mapping2, {seg}, expr.get_locus (),
default_expr = ASTLoweringExpr::translate (
param.get_default_value ().get_expression ().get ());
- translated = new HIR::ConstGenericParam (param.get_name (),
+ translated = new HIR::ConstGenericParam (param.get_name ().as_string (),
std::unique_ptr<Type> (type),
std::unique_ptr<Expr> (default_expr),
mapping, param.get_locus ());
// function name
stream << indentation << "func_name: ";
auto func_name = func.get_function_name ();
- stream << func_name;
+ stream << func_name.as_string ();
stream << ",\n";
// return type
Dump::visit (IdentifierPattern &ident)
{
auto ident_name = ident.get_identifier ();
- stream << ident_name;
+ stream << ident_name.as_string ();
}
void
Dump::visit (WildcardPattern &)
field_name (std::move (field_identifier))
{}
- std::string as_string () const override { return field_name; }
+ std::string as_string () const override { return field_name.as_string (); }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
std::string get_impl_item_name () const override final
{
- return get_function_name ();
+ return get_function_name ().as_string ();
}
protected:
std::string get_impl_item_name () const override final
{
- return get_new_type_name ();
+ return get_new_type_name ().as_string ();
}
protected:
// Returns whether constant item is an "unnamed" (wildcard underscore used
// as identifier) constant.
- bool is_unnamed () const { return identifier == std::string ("_"); }
+ bool is_unnamed () const
+ {
+ return identifier.as_string () == std::string ("_");
+ }
Location get_locus () const override final { return locus; }
Expr *get_expr () { return const_expr.get (); }
- std::string get_identifier () const { return identifier; }
+ Identifier get_identifier () const { return identifier; }
Analysis::NodeMapping get_impl_mappings () const override
{
std::string get_impl_item_name () const override final
{
- return get_identifier ();
+ return get_identifier ().as_string ();
}
protected:
const std::string trait_identifier () const override final
{
- return decl.get_function_name ();
+ return decl.get_function_name ().as_string ();
}
TraitItemKind get_item_kind () const override final
return expr;
}
- const std::string trait_identifier () const override final { return name; }
+ const std::string trait_identifier () const override final
+ {
+ return name.as_string ();
+ }
TraitItemKind get_item_kind () const override final
{
return type_param_bounds;
}
- const std::string trait_identifier () const override final { return name; }
+ const std::string trait_identifier () const override final
+ {
+ return name.as_string ();
+ }
TraitItemKind get_item_kind () const override final
{
Analysis::NodeMapping mappings;
public:
- bool has_name () const { return name != "_"; }
+ bool has_name () const { return name.as_string () != "_"; }
NamedFunctionParam (Analysis::NodeMapping mappings, Identifier name,
std::unique_ptr<Type> param_type)
// Creates an error state generic args binding.
static GenericArgsBinding create_error ()
{
- return GenericArgsBinding ("", nullptr);
+ return GenericArgsBinding ({""}, nullptr);
}
// Pointer type for type in constructor to enable polymorphism
// Creates an error state param.
static MaybeNamedParam create_error ()
{
- return MaybeNamedParam ("", UNNAMED, nullptr, Location ());
+ return MaybeNamedParam ({""}, UNNAMED, nullptr, Location ());
}
Location get_locus () const { return locus; }
Module::as_string () const
{
// get module string for "[vis] mod [name]"
- std::string str = VisItem::as_string () + "mod " + module_name;
+ std::string str = VisItem::as_string () + "mod " + module_name.as_string ();
// inner attributes
str += "\n inner attributes: ";
str += " mut";
}
- str += name;
+ str += name.as_string ();
// DEBUG: null pointer check
if (type == nullptr)
{
std::string str = VisItem::as_string ();
- str += "struct " + struct_name;
+ str += "struct " + struct_name.as_string ();
// generic params
str += "\n Generic params: ";
{
std::string str = VisItem::as_string ();
- str += "const " + identifier;
+ str += "const " + identifier.as_string ();
// DEBUG: null pointer check
if (type == nullptr)
{
std::string str = VisItem::as_string ();
- str += "struct " + struct_name;
+ str += "struct " + struct_name.as_string ();
// generic params
str += "\n Generic params: ";
// nothing to add, just path
break;
case IDENTIFIER:
- path_str += " as " + identifier;
+ path_str += " as " + identifier.as_string ();
break;
case WILDCARD:
path_str += " as _";
Enum::as_string () const
{
std::string str = VisItem::as_string ();
- str += enum_name;
+ str += enum_name.as_string ();
// generic params
str += "\n Generic params: ";
str += "unsafe ";
}
- str += "trait " + name;
+ str += "trait " + name.as_string ();
// generic params
str += "\n Generic params: ";
{
std::string str = VisItem::as_string ();
- str += "union " + union_name;
+ str += "union " + union_name.as_string ();
// generic params
str += "\n Generic params: ";
str += "void ";
}
- str += function_name;
+ str += function_name.as_string ();
if (has_generics ())
{
{
std::string str = VisItem::as_string ();
- str += " " + new_type_name;
+ str += " " + new_type_name.as_string ();
// generic params
str += "\n Generic params: ";
std::string
FieldAccessExpr::as_string () const
{
- return receiver->as_string () + "." + field;
+ return receiver->as_string () + "." + field.as_string ();
}
std::string
str += outer_attr.as_string ();
}
- str += "\n Identifier: " + type_representation;
+ str += "\n Identifier: " + type_representation.as_string ();
str += "\n Type param bounds: ";
if (!has_type_param_bounds ())
std::string
GenericArgsBinding::as_string () const
{
- return identifier + " = " + type->as_string ();
+ return identifier.as_string () + " = " + type->as_string ();
}
std::string
str += "mut ";
}
- str += ident;
+ str += ident.as_string ();
return str;
}
str += "\n";
- str += ident + " : " + ident_pattern->as_string ();
+ str += ident.as_string () + " : " + ident_pattern->as_string ();
return str;
}
str += "mut ";
}
- str += variable_ident;
+ str += variable_ident.as_string ();
if (has_pattern_to_bind ())
{
std::string
StructExprFieldIdentifierValue::as_string () const
{
- return field_name + " : " + StructExprFieldWithVal::as_string ();
+ return field_name.as_string () + " : " + StructExprFieldWithVal::as_string ();
}
std::string
EnumItem::as_string () const
{
std::string str = Item::as_string ();
- str += variant_name;
+ str += variant_name.as_string ();
str += " ";
switch (get_enum_item_kind ())
{
str += "\n" + visibility.as_string ();
}
- str += " " + field_name + " : " + field_type->as_string ();
+ str += " " + field_name.as_string () + " : " + field_type->as_string ();
return str;
}
}
// add name
- str += get_item_name ();
+ str += get_item_name ().as_string ();
// add type on new line
str += "\n Type: " + item_type->as_string ();
str += "fn ";
// add name
- str += get_item_name ();
+ str += get_item_name ().as_string ();
// generic params
str += "\n Generic params: ";
std::string
NamedFunctionParam::as_string () const
{
- std::string str = name;
+ std::string str = name.as_string ();
str += "\n Type: " + param_type->as_string ();
std::string
TraitFunctionDecl::as_string () const
{
- std::string str = qualifiers.as_string () + "fn " + function_name;
+ std::string str
+ = qualifiers.as_string () + "fn " + function_name.as_string ();
// generic params
str += "\n Generic params: ";
}
}
- str += "\nconst " + name + " : " + type->as_string ();
+ str += "\nconst " + name.as_string () + " : " + type->as_string ();
if (has_expression ())
{
}
}
- str += "\ntype " + name;
+ str += "\ntype " + name.as_string ();
str += "\n Type param bounds: ";
if (!has_type_param_bounds ())
case UNNAMED:
break;
case IDENTIFIER:
- str = name + " : ";
+ str = name.as_string () + " : ";
break;
case WILDCARD:
str = "_ : ";
#include "rust-diagnostics.h"
namespace Rust {
-typedef std::string Identifier;
typedef int TupleIndex;
namespace HIR {
Location fragment_locus = lexer.peek_token ()->get_locus ();
skip_token (DOLLAR_SIGN);
- Identifier ident = "";
+ Identifier ident{""};
auto identifier = lexer.peek_token ();
if (identifier->get_id () == UNDERSCORE)
- ident = "_";
+ ident = {"_"};
else
ident = identifier->get_str ();
{
return nullptr;
}
- Identifier name = module_name->get_str ();
+ Identifier name{module_name->get_str ()};
const_TokenPtr t = lexer.peek_token ();
// parse inner attributes
AST::AttrVec inner_attrs = parse_inner_attributes ();
- std::string default_path = name;
+ std::string default_path = name.as_string ();
if (inline_module_stack.empty ())
{
std::string subdir;
if (get_file_subdir (filename, subdir))
- default_path = subdir + file_separator + name;
+ default_path = subdir + file_separator + name.as_string ();
}
std::string module_path_name
return std::unique_ptr<AST::UseTreeRebind> (
new AST::UseTreeRebind (AST::UseTreeRebind::WILDCARD,
- std::move (path), locus, "_"));
+ std::move (path), locus, {"_"}));
default:
add_error (Error (
t->get_locus (),
else if (current->get_id () == UNDERSCORE && next->get_id () == COLON)
{
// wildcard param
- name = "_";
+ name = {"_"};
kind = AST::MaybeNamedParam::WILDCARD;
lexer.skip_token (1);
}
void visit (AST::TypeAlias &type) override
{
- auto decl
- = CanonicalPath::new_seg (type.get_node_id (), type.get_new_type_name ());
+ auto decl = CanonicalPath::new_seg (type.get_node_id (),
+ type.get_new_type_name ().as_string ());
auto path = prefix.append (decl);
resolver->get_type_scope ().insert (
void visit (AST::Function &function) override
{
- auto decl = CanonicalPath::new_seg (function.get_node_id (),
- function.get_function_name ());
+ auto decl
+ = CanonicalPath::new_seg (function.get_node_id (),
+ function.get_function_name ().as_string ());
auto path = prefix.append (decl);
resolver->get_name_scope ().insert (
void visit (AST::Method &method) override
{
auto decl = CanonicalPath::new_seg (method.get_node_id (),
- method.get_method_name ());
+ method.get_method_name ().as_string ());
auto path = prefix.append (decl);
resolver->get_name_scope ().insert (
{
auto decl = CanonicalPath::new_seg (
function.get_node_id (),
- function.get_trait_function_decl ().get_identifier ());
+ function.get_trait_function_decl ().get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::TraitItemMethod &method) override
{
auto decl = CanonicalPath::new_seg (
- method.get_node_id (), method.get_trait_method_decl ().get_identifier ());
+ method.get_node_id (),
+ method.get_trait_method_decl ().get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::TraitItemConst &constant) override
{
- auto decl = CanonicalPath::new_seg (constant.get_node_id (),
- constant.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (constant.get_node_id (),
+ constant.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::TraitItemType &type) override
{
- auto decl
- = CanonicalPath::new_seg (type.get_node_id (), type.get_identifier ());
+ auto decl = CanonicalPath::new_seg (type.get_node_id (),
+ type.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::ExternalFunctionItem &function) override
{
- auto decl = CanonicalPath::new_seg (function.get_node_id (),
- function.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (function.get_node_id (),
+ function.get_identifier ().as_string ());
auto path = prefix.append (decl);
resolver->get_name_scope ().insert (
void visit (AST::ExternalStaticItem &item) override
{
- auto decl
- = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+ auto decl = CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ());
auto path = prefix.append (decl);
resolver->get_name_scope ().insert (
void
ResolveTraitItems::visit (AST::TraitItemType &type)
{
- auto decl
- = CanonicalPath::new_seg (type.get_node_id (), type.get_identifier ());
+ auto decl = CanonicalPath::new_seg (type.get_node_id (),
+ type.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (type.get_node_id (), cpath);
ResolveTraitItems::visit (AST::TraitItemFunc &func)
{
auto decl = CanonicalPath::new_seg (
- func.get_node_id (), func.get_trait_function_decl ().get_identifier ());
+ func.get_node_id (),
+ func.get_trait_function_decl ().get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (func.get_node_id (), cpath);
void
ResolveTraitItems::visit (AST::TraitItemMethod &func)
{
- auto decl
- = CanonicalPath::new_seg (func.get_node_id (),
- func.get_trait_method_decl ().get_identifier ());
+ auto decl = CanonicalPath::new_seg (
+ func.get_node_id (),
+ func.get_trait_method_decl ().get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (func.get_node_id (), cpath);
// self turns into (self: Self) as a function param
AST::SelfParam &self_param = function.get_self_param ();
- AST::IdentifierPattern self_pattern (self_param.get_node_id (), "self",
+ AST::IdentifierPattern self_pattern (self_param.get_node_id (), {"self"},
self_param.get_locus (),
self_param.get_has_ref (),
self_param.get_is_mut (),
ResolveTraitItems::visit (AST::TraitItemConst &constant)
{
auto decl = CanonicalPath::new_seg (constant.get_node_id (),
- constant.get_identifier ());
+ constant.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (constant.get_node_id (), cpath);
ResolveItem::visit (AST::TypeAlias &alias)
{
auto talias
- = CanonicalPath::new_seg (alias.get_node_id (), alias.get_new_type_name ());
+ = CanonicalPath::new_seg (alias.get_node_id (),
+ alias.get_new_type_name ().as_string ());
auto path = prefix.append (talias);
auto cpath = canonical_prefix.append (talias);
mappings->insert_canonical_path (alias.get_node_id (), cpath);
void
ResolveItem::visit (AST::Module &module)
{
- auto mod = CanonicalPath::new_seg (module.get_node_id (), module.get_name ());
+ auto mod = CanonicalPath::new_seg (module.get_node_id (),
+ module.get_name ().as_string ());
auto path = prefix.append (mod);
auto cpath = canonical_prefix.append (mod);
mappings->insert_canonical_path (module.get_node_id (), cpath);
void
ResolveItem::visit (AST::TupleStruct &struct_decl)
{
- auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
- struct_decl.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (struct_decl.get_node_id (),
+ struct_decl.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (struct_decl.get_node_id (), cpath);
ResolveItem::visit (AST::Enum &enum_decl)
{
auto decl = CanonicalPath::new_seg (enum_decl.get_node_id (),
- enum_decl.get_identifier ());
+ enum_decl.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (enum_decl.get_node_id (), cpath);
// Since at this point we cannot have visibilities on enum items anymore, we
// can skip handling them
- auto decl
- = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+ auto decl = CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (item.get_node_id (), cpath);
void
ResolveItem::visit (AST::EnumItemTuple &item)
{
- auto decl
- = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+ auto decl = CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (item.get_node_id (), cpath);
void
ResolveItem::visit (AST::EnumItemStruct &item)
{
- auto decl
- = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+ auto decl = CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (item.get_node_id (), cpath);
void
ResolveItem::visit (AST::EnumItemDiscriminant &item)
{
- auto decl
- = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+ auto decl = CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void
ResolveItem::visit (AST::StructStruct &struct_decl)
{
- auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
- struct_decl.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (struct_decl.get_node_id (),
+ struct_decl.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (struct_decl.get_node_id (), cpath);
void
ResolveItem::visit (AST::Union &union_decl)
{
- auto decl = CanonicalPath::new_seg (union_decl.get_node_id (),
- union_decl.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (union_decl.get_node_id (),
+ union_decl.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (union_decl.get_node_id (), cpath);
void
ResolveItem::visit (AST::StaticItem &var)
{
- auto decl
- = CanonicalPath::new_seg (var.get_node_id (), var.get_identifier ());
+ auto decl = CanonicalPath::new_seg (var.get_node_id (),
+ var.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (var.get_node_id (), cpath);
void
ResolveItem::visit (AST::Function &function)
{
- auto decl = CanonicalPath::new_seg (function.get_node_id (),
- function.get_function_name ());
+ auto decl
+ = CanonicalPath::new_seg (function.get_node_id (),
+ function.get_function_name ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void
ResolveItem::visit (AST::Method &method)
{
- auto decl
- = CanonicalPath::new_seg (method.get_node_id (), method.get_method_name ());
+ auto decl = CanonicalPath::new_seg (method.get_node_id (),
+ method.get_method_name ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (method.get_node_id (), cpath);
// self turns into (self: Self) as a function param
AST::SelfParam &self_param = method.get_self_param ();
- AST::IdentifierPattern self_pattern (self_param.get_node_id (), "self",
+ AST::IdentifierPattern self_pattern (self_param.get_node_id (), {"self"},
self_param.get_locus (),
self_param.get_has_ref (),
self_param.get_is_mut (),
// we need to inject an implicit self TypeParam here
AST::TypeParam *implicit_self
- = new AST::TypeParam ("Self", trait.get_locus ());
+ = new AST::TypeParam ({"Self"}, trait.get_locus ());
trait.insert_implict_self (
std::unique_ptr<AST::GenericParam> (implicit_self));
CanonicalPath Self = CanonicalPath::get_big_self (trait.get_node_id ());
// Add the identifier as a new path
rebind_path.get_segments ().back ()
- = AST::SimplePathSegment (new_seg, Location ());
+ = AST::SimplePathSegment (new_seg.as_string (), Location ());
paths.emplace_back (rebind_path);
}
{
NodeId scope_node_id = function.get_node_id ();
auto decl = CanonicalPath::new_seg (function.get_node_id (),
- function.get_identifier ());
+ function.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
auto frob = Rust::AST::SimplePath::from_str ("frobulator", Location ());
auto rebind = Rust::AST::UseTreeRebind (Rust::AST::UseTreeRebind::IDENTIFIER,
- frob, Location (), "saindoux");
+ frob, Location (), {"saindoux"});
auto paths = std::vector<Rust::AST::SimplePath> ();
Rust::Resolver::flatten_rebind (rebind, paths);
auto foo_bar_baz = Rust::AST::SimplePath ({foo, bar, baz});
- auto rebind = Rust::AST::UseTreeRebind (Rust::AST::UseTreeRebind::IDENTIFIER,
- foo_bar_baz, Location (), "saindoux");
+ auto rebind
+ = Rust::AST::UseTreeRebind (Rust::AST::UseTreeRebind::IDENTIFIER,
+ foo_bar_baz, Location (), {"saindoux"});
auto paths = std::vector<Rust::AST::SimplePath> ();
Rust::Resolver::flatten_rebind (rebind, paths);
rust_error_at (info.get_locus (), ErrorCode ("E0408"),
"variable '%s' is not bound in all patterns",
- ident.c_str ());
+ ident.as_string ().c_str ());
}
for (auto &map_entry : resolver.inconsistent_bindings)
rust_error_at (
info.get_locus (), ErrorCode ("E0409"),
"variable '%s' is bound inconsistently across pattern alternatives",
- ident.c_str ());
+ ident.as_string ().c_str ());
}
}
auto idents = bindings_with_ctx.back ().idents;
bindings_with_ctx.pop_back ();
for (auto &ident : idents)
- bindings_with_ctx.back ().idents.insert (ident);
+ bindings_with_ctx.back ().idents.insert (ident.as_string ());
// ...we repopulate the binding_info_map correctly (the initial bindings
// stored in the tmp_binding_map + all the bindings from all the alts)
rust_error_at (info.get_locus (), ErrorCode ("E0415"),
"identifier '%s' is bound more than once in the "
"same parameter list",
- ident.c_str ());
+ ident.as_string ().c_str ());
}
else
{
rust_error_at (
info.get_locus (), ErrorCode ("E0416"),
"identifier '%s' is bound more than once in the same pattern",
- ident.c_str ());
+ ident.as_string ().c_str ());
}
return;
if (!identifier_or_bound)
{
bindings_with_ctx.back ().idents.insert (ident);
- resolver->get_name_scope ().insert (CanonicalPath::new_seg (node_id,
- ident),
- node_id, info.get_locus (), type);
+ resolver->get_name_scope ().insert (
+ CanonicalPath::new_seg (node_id, ident.as_string ()), node_id,
+ info.get_locus (), type);
}
binding_info_map.insert ({ident, info});
void visit (AST::TupleStruct &struct_decl) override
{
- auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
- struct_decl.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (struct_decl.get_node_id (),
+ struct_decl.get_identifier ().as_string ());
auto path = decl; // this ensures we have the correct relative resolution
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (struct_decl.get_node_id (), cpath);
void visit (AST::Enum &enum_decl) override
{
- auto decl = CanonicalPath::new_seg (enum_decl.get_node_id (),
- enum_decl.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (enum_decl.get_node_id (),
+ enum_decl.get_identifier ().as_string ());
auto path = decl; // this ensures we have the correct relative resolution
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (enum_decl.get_node_id (), cpath);
void visit (AST::EnumItem &item) override
{
auto decl = enum_prefix.append (
- CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()));
+ CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ()));
auto path = decl; // this ensures we have the correct relative resolution
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (item.get_node_id (), cpath);
void visit (AST::EnumItemTuple &item) override
{
auto decl = enum_prefix.append (
- CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()));
+ CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ()));
auto path = decl; // this ensures we have the correct relative resolution
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (item.get_node_id (), cpath);
void visit (AST::EnumItemStruct &item) override
{
auto decl = enum_prefix.append (
- CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()));
+ CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ()));
auto path = decl; // this ensures we have the correct relative resolution
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (item.get_node_id (), cpath);
void visit (AST::EnumItemDiscriminant &item) override
{
auto decl = enum_prefix.append (
- CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()));
+ CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ()));
auto path = decl; // this ensures we have the correct relative resolution
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (item.get_node_id (), cpath);
void visit (AST::StructStruct &struct_decl) override
{
- auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
- struct_decl.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (struct_decl.get_node_id (),
+ struct_decl.get_identifier ().as_string ());
auto path = decl; // this ensures we have the correct relative resolution
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (struct_decl.get_node_id (), cpath);
void visit (AST::Union &union_decl) override
{
- auto decl = CanonicalPath::new_seg (union_decl.get_node_id (),
- union_decl.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (union_decl.get_node_id (),
+ union_decl.get_identifier ().as_string ());
auto path = decl; // this ensures we have the correct relative resolution
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (union_decl.get_node_id (), cpath);
void visit (AST::Function &function) override
{
- auto decl = CanonicalPath::new_seg (function.get_node_id (),
- function.get_function_name ());
+ auto decl
+ = CanonicalPath::new_seg (function.get_node_id (),
+ function.get_function_name ().as_string ());
auto path = decl; // this ensures we have the correct relative resolution
auto cpath = canonical_prefix.append (decl);
mappings->insert_canonical_path (function.get_node_id (), cpath);
void visit (AST::Module &module) override
{
- auto mod
- = CanonicalPath::new_seg (module.get_node_id (), module.get_name ());
+ auto mod = CanonicalPath::new_seg (module.get_node_id (),
+ module.get_name ().as_string ());
auto path = prefix.append (mod);
auto cpath = canonical_prefix.append (mod);
void visit (AST::TypeAlias &alias) override
{
- auto talias = CanonicalPath::new_seg (alias.get_node_id (),
- alias.get_new_type_name ());
+ auto talias
+ = CanonicalPath::new_seg (alias.get_node_id (),
+ alias.get_new_type_name ().as_string ());
auto path = prefix.append (talias);
auto cpath = canonical_prefix.append (talias);
void visit (AST::TupleStruct &struct_decl) override
{
- auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
- struct_decl.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (struct_decl.get_node_id (),
+ struct_decl.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::Enum &enum_decl) override
{
- auto decl = CanonicalPath::new_seg (enum_decl.get_node_id (),
- enum_decl.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (enum_decl.get_node_id (),
+ enum_decl.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::EnumItem &item) override
{
- auto decl
- = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+ auto decl = CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::EnumItemTuple &item) override
{
- auto decl
- = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+ auto decl = CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::EnumItemStruct &item) override
{
- auto decl
- = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+ auto decl = CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::EnumItemDiscriminant &item) override
{
- auto decl
- = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+ auto decl = CanonicalPath::new_seg (item.get_node_id (),
+ item.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::StructStruct &struct_decl) override
{
- auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
- struct_decl.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (struct_decl.get_node_id (),
+ struct_decl.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::Union &union_decl) override
{
- auto decl = CanonicalPath::new_seg (union_decl.get_node_id (),
- union_decl.get_identifier ());
+ auto decl
+ = CanonicalPath::new_seg (union_decl.get_node_id (),
+ union_decl.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::StaticItem &var) override
{
- auto decl
- = CanonicalPath::new_seg (var.get_node_id (), var.get_identifier ());
+ auto decl = CanonicalPath::new_seg (var.get_node_id (),
+ var.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::Function &function) override
{
- auto decl = CanonicalPath::new_seg (function.get_node_id (),
- function.get_function_name ());
+ auto decl
+ = CanonicalPath::new_seg (function.get_node_id (),
+ function.get_function_name ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
void visit (AST::Trait &trait) override
{
- auto decl
- = CanonicalPath::new_seg (trait.get_node_id (), trait.get_identifier ());
+ auto decl = CanonicalPath::new_seg (trait.get_node_id (),
+ trait.get_identifier ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
}
}
- auto seg = CanonicalPath::new_seg (param.get_node_id (),
- param.get_type_representation ());
+ auto seg
+ = CanonicalPath::new_seg (param.get_node_id (),
+ param.get_type_representation ().as_string ());
resolver->get_type_scope ().insert (
seg, param.get_node_id (), param.get_locus (), false, Rib::ItemType::Type,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
EarlyNameResolver::visit (AST::MacroRulesDefinition &rules_def)
{
auto path = CanonicalPath::new_seg (rules_def.get_node_id (),
- rules_def.get_rule_name ());
+ rules_def.get_rule_name ().as_string ());
resolver.get_macro_scope ().insert (path, rules_def.get_node_id (),
rules_def.get_locus ());
if (is_builtin)
{
auto builtin_kind
- = builtin_macro_from_string (rules_def->get_rule_name ());
+ = builtin_macro_from_string (rules_def->get_rule_name ().as_string ());
invoc.map_to_builtin (builtin_kind);
}
HIR::Function *fn = impl_item.second;
if (parent->has_trait_ref ()
- && fn->get_function_name ().compare (associated_item_name) == 0)
+ && fn->get_function_name ().as_string ().compare (
+ associated_item_name)
+ == 0)
{
TraitReference *trait_reference
= TraitResolver::Lookup (*parent->get_trait_ref ().get ());
if (!func->is_method ())
return true;
- bool name_matches
- = func->get_function_name ().compare (segment_name.as_string ()) == 0;
+ bool name_matches = func->get_function_name ().as_string ().compare (
+ segment_name.as_string ())
+ == 0;
if (!name_matches)
return true;
};
std::vector<trait_item_candidate> trait_fns;
- mappings->iterate_impl_blocks ([&] (HirId id,
- HIR::ImplBlock *impl) mutable -> bool {
- bool is_trait_impl = impl->has_trait_ref ();
- if (!is_trait_impl)
- return true;
-
- // look for impl implementation else lookup the associated trait item
- for (auto &impl_item : impl->get_impl_items ())
- {
- bool is_fn = impl_item->get_impl_item_type ()
- == HIR::ImplItem::ImplItemType::FUNCTION;
- if (!is_fn)
- continue;
-
- HIR::Function *func = static_cast<HIR::Function *> (impl_item.get ());
- if (!func->is_method ())
- continue;
-
- bool name_matches
- = func->get_function_name ().compare (segment_name.as_string ()) == 0;
- if (!name_matches)
- continue;
-
- TyTy::BaseType *ty = nullptr;
- if (!query_type (func->get_mappings ().get_hirid (), &ty))
- continue;
- if (ty->get_kind () == TyTy::TypeKind::ERROR)
- continue;
-
- rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
- TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
- const TyTy::BaseType *impl_self
- = TypeCheckItem::ResolveImplBlockSelf (*impl);
-
- // see:
- // https://gcc-rust.zulipchat.com/#narrow/stream/266897-general/topic/Method.20Resolution/near/338646280
- // https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/method/probe.rs#L650-L660
- bool impl_self_is_ptr
- = impl_self->get_kind () == TyTy::TypeKind::POINTER;
- bool impl_self_is_ref = impl_self->get_kind () == TyTy::TypeKind::REF;
- if (receiver_is_raw_ptr && impl_self_is_ptr)
- {
- const TyTy::PointerType &sptr
- = *static_cast<const TyTy::PointerType *> (impl_self);
- const TyTy::PointerType &ptr
- = *static_cast<const TyTy::PointerType *> (raw);
-
- // we could do this via lang-item assemblies if we refactor this
- bool mut_match = sptr.mutability () == ptr.mutability ();
- if (!mut_match)
- continue;
- }
- else if (receiver_is_ref && impl_self_is_ref)
- {
- const TyTy::ReferenceType &sptr
- = *static_cast<const TyTy::ReferenceType *> (impl_self);
- const TyTy::ReferenceType &ptr
- = *static_cast<const TyTy::ReferenceType *> (raw);
-
- // we could do this via lang-item assemblies if we refactor this
- bool mut_match = sptr.mutability () == ptr.mutability ();
- if (!mut_match)
- continue;
- }
-
- inherent_impl_fns.push_back ({func, impl, fnty});
+ mappings->iterate_impl_blocks (
+ [&] (HirId id, HIR::ImplBlock *impl) mutable -> bool {
+ bool is_trait_impl = impl->has_trait_ref ();
+ if (!is_trait_impl)
return true;
- }
- TraitReference *trait_ref
- = TraitResolver::Resolve (*impl->get_trait_ref ().get ());
- rust_assert (!trait_ref->is_error ());
+ // look for impl implementation else lookup the associated trait item
+ for (auto &impl_item : impl->get_impl_items ())
+ {
+ bool is_fn = impl_item->get_impl_item_type ()
+ == HIR::ImplItem::ImplItemType::FUNCTION;
+ if (!is_fn)
+ continue;
+
+ HIR::Function *func = static_cast<HIR::Function *> (impl_item.get ());
+ if (!func->is_method ())
+ continue;
+
+ bool name_matches = func->get_function_name ().as_string ().compare (
+ segment_name.as_string ())
+ == 0;
+ if (!name_matches)
+ continue;
+
+ TyTy::BaseType *ty = nullptr;
+ if (!query_type (func->get_mappings ().get_hirid (), &ty))
+ continue;
+ if (ty->get_kind () == TyTy::TypeKind::ERROR)
+ continue;
+
+ rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
+ TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
+ const TyTy::BaseType *impl_self
+ = TypeCheckItem::ResolveImplBlockSelf (*impl);
+
+ // see:
+ // https://gcc-rust.zulipchat.com/#narrow/stream/266897-general/topic/Method.20Resolution/near/338646280
+ // https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/method/probe.rs#L650-L660
+ bool impl_self_is_ptr
+ = impl_self->get_kind () == TyTy::TypeKind::POINTER;
+ bool impl_self_is_ref = impl_self->get_kind () == TyTy::TypeKind::REF;
+ if (receiver_is_raw_ptr && impl_self_is_ptr)
+ {
+ const TyTy::PointerType &sptr
+ = *static_cast<const TyTy::PointerType *> (impl_self);
+ const TyTy::PointerType &ptr
+ = *static_cast<const TyTy::PointerType *> (raw);
+
+ // we could do this via lang-item assemblies if we refactor this
+ bool mut_match = sptr.mutability () == ptr.mutability ();
+ if (!mut_match)
+ continue;
+ }
+ else if (receiver_is_ref && impl_self_is_ref)
+ {
+ const TyTy::ReferenceType &sptr
+ = *static_cast<const TyTy::ReferenceType *> (impl_self);
+ const TyTy::ReferenceType &ptr
+ = *static_cast<const TyTy::ReferenceType *> (raw);
+
+ // we could do this via lang-item assemblies if we refactor this
+ bool mut_match = sptr.mutability () == ptr.mutability ();
+ if (!mut_match)
+ continue;
+ }
- auto item_ref
- = trait_ref->lookup_trait_item (segment_name.as_string (),
- TraitItemReference::TraitItemType::FN);
- if (item_ref->is_error ())
- return true;
+ inherent_impl_fns.push_back ({func, impl, fnty});
+ return true;
+ }
- const HIR::Trait *trait = trait_ref->get_hir_trait_ref ();
- HIR::TraitItem *item = item_ref->get_hir_trait_item ();
- if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::FUNC)
- return true;
+ TraitReference *trait_ref
+ = TraitResolver::Resolve (*impl->get_trait_ref ().get ());
+ rust_assert (!trait_ref->is_error ());
- HIR::TraitItemFunc *func = static_cast<HIR::TraitItemFunc *> (item);
- if (!func->get_decl ().is_method ())
- return true;
+ auto item_ref
+ = trait_ref->lookup_trait_item (segment_name.as_string (),
+ TraitItemReference::TraitItemType::FN);
+ if (item_ref->is_error ())
+ return true;
- TyTy::BaseType *ty = item_ref->get_tyty ();
- rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
- TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
+ const HIR::Trait *trait = trait_ref->get_hir_trait_ref ();
+ HIR::TraitItem *item = item_ref->get_hir_trait_item ();
+ if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::FUNC)
+ return true;
- trait_item_candidate candidate{func, trait, fnty, trait_ref, item_ref};
- trait_fns.push_back (candidate);
+ HIR::TraitItemFunc *func = static_cast<HIR::TraitItemFunc *> (item);
+ if (!func->get_decl ().is_method ())
+ return true;
- return true;
- });
+ TyTy::BaseType *ty = item_ref->get_tyty ();
+ rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
+ TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
+
+ trait_item_candidate candidate{func, trait, fnty, trait_ref, item_ref};
+ trait_fns.push_back (candidate);
+
+ return true;
+ });
// lookup specified bounds for an associated item
struct precdicate_candidate
PathProbeType::visit (HIR::TypeAlias &alias)
{
Identifier name = alias.get_new_type_name ();
- if (search.as_string ().compare (name) == 0)
+ if (search.as_string ().compare (name.as_string ()) == 0)
{
HirId tyid = alias.get_mappings ().get_hirid ();
TyTy::BaseType *ty = nullptr;
PathProbeType::visit (HIR::ConstantItem &constant)
{
Identifier name = constant.get_identifier ();
- if (search.as_string ().compare (name) == 0)
+ if (search.as_string ().compare (name.as_string ()) == 0)
{
HirId tyid = constant.get_mappings ().get_hirid ();
TyTy::BaseType *ty = nullptr;
PathProbeType::visit (HIR::Function &function)
{
Identifier name = function.get_function_name ();
- if (search.as_string ().compare (name) == 0)
+ if (search.as_string ().compare (name.as_string ()) == 0)
{
HirId tyid = function.get_mappings ().get_hirid ();
TyTy::BaseType *ty = nullptr;
TraitReference::get_name () const
{
rust_assert (!is_error ());
- return hir_trait_ref->get_name ();
+ return hir_trait_ref->get_name ().as_string ();
}
std::string
// create trait-item-ref
Location locus = type.get_locus ();
bool is_optional = false;
- std::string identifier = type.get_name ();
+ std::string identifier = type.get_name ().as_string ();
resolved = TraitItemReference (identifier, is_optional,
TraitItemReference::TraitItemType::TYPE, &type,
// create trait-item-ref
Location locus = cst.get_locus ();
bool is_optional = cst.has_expr ();
- std::string identifier = cst.get_name ();
+ std::string identifier = cst.get_name ().as_string ();
resolved = TraitItemReference (identifier, is_optional,
TraitItemReference::TraitItemType::CONST, &cst,
// create trait-item-ref
Location locus = fn.get_locus ();
bool is_optional = fn.has_block_defined ();
- std::string identifier = fn.get_decl ().get_function_name ();
+ std::string identifier = fn.get_decl ().get_function_name ().as_string ();
resolved = TraitItemReference (identifier, is_optional,
TraitItemReference::TraitItemType::FN, &fn,
substitutions.push_back (
TyTy::SubstitutionParamMapping (typaram, param_type));
- if (typaram.get_type_representation ().compare ("Self") == 0)
+ if (typaram.get_type_representation ().as_string ().compare ("Self")
+ == 0)
{
rust_assert (param_type->get_kind () == TyTy::TypeKind::PARAM);
TyTy::ParamType *p
TraitItemReference::resolve_item (HIR::TraitItemType &type)
{
TyTy::BaseType *ty
- = new TyTy::PlaceholderType (type.get_name (),
+ = new TyTy::PlaceholderType (type.get_name ().as_string (),
type.get_mappings ().get_hirid ());
context->insert_type (type.get_mappings (), ty);
}
HIR::TypeAlias &type = *static_cast<HIR::TypeAlias *> (impl_item.get ());
TraitItemReference *resolved_trait_item = nullptr;
- bool ok = trait->lookup_trait_item (type.get_new_type_name (),
- &resolved_trait_item);
+ bool ok
+ = trait->lookup_trait_item (type.get_new_type_name ().as_string (),
+ &resolved_trait_item);
if (!ok)
continue;
if (resolved_trait_item->get_trait_item_type ()
HIR::TypeAlias &type = *static_cast<HIR::TypeAlias *> (impl_item.get ());
TraitItemReference *resolved_trait_item = nullptr;
- bool ok = trait->lookup_trait_item (type.get_new_type_name (),
- &resolved_trait_item);
+ bool ok
+ = trait->lookup_trait_item (type.get_new_type_name ().as_string (),
+ &resolved_trait_item);
if (!ok)
continue;
if (resolved_trait_item->get_trait_item_type ()
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
- item.get_identifier (), ident, discim_expr);
+ item.get_identifier ().as_string (), ident,
+ discim_expr);
}
void
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
- item.get_identifier (), ident,
+ item.get_identifier ().as_string (), ident,
item.get_discriminant_expression ().get ());
}
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
- item.get_identifier (), ident,
+ item.get_identifier ().as_string (), ident,
TyTy::VariantDef::VariantType::TUPLE,
discim_expr, fields);
}
= TypeCheckType::Resolve (field.get_field_type ().get ());
TyTy::StructFieldType *ty_field
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
- field.get_field_name (), field_type,
- field.get_locus ());
+ field.get_field_name ().as_string (),
+ field_type, field.get_locus ());
fields.push_back (ty_field);
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
}
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
- item.get_identifier (), ident,
+ item.get_identifier ().as_string (), ident,
TyTy::VariantDef::VariantType::STRUCT,
discrim_expr, fields);
}
TyTy::VariantDef *vaiant = adt->get_variants ().at (0);
TyTy::StructFieldType *lookup = nullptr;
- bool found = vaiant->lookup_field (expr.get_field_name (), &lookup, nullptr);
+ bool found = vaiant->lookup_field (expr.get_field_name ().as_string (),
+ &lookup, nullptr);
if (!found)
{
rust_error_at (expr.get_locus (), "unknown field [%s] for type [%s]",
- expr.get_field_name ().c_str (),
+ expr.get_field_name ().as_string ().c_str (),
adt->as_string ().c_str ());
return;
}
HIR::Function *fn = impl_item.second;
if (parent->has_trait_ref ()
- && fn->get_function_name ().compare (associated_item_name) == 0)
+ && fn->get_function_name ().as_string ().compare (
+ associated_item_name)
+ == 0)
{
TraitReference *trait_reference
= TraitResolver::Lookup (*parent->get_trait_ref ().get ());
RustIdent ident{
CanonicalPath::new_seg (function.get_mappings ().get_nodeid (),
- function.get_item_name ()),
+ function.get_item_name ().as_string ()),
function.get_locus ()};
auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (),
function.get_mappings ().get_defid (),
- function.get_item_name (), ident, flags,
- parent.get_abi (), std::move (params),
+ function.get_item_name ().as_string (), ident,
+ flags, parent.get_abi (), std::move (params),
ret_type, std::move (substitutions));
context->insert_type (function.get_mappings (), fnType);
// compilation to know parameter names. The types are ignored but we
// reuse the HIR identifier pattern which requires it
HIR::SelfParam &self_param = function.get_self_param ();
- HIR::IdentifierPattern *self_pattern
- = new HIR::IdentifierPattern (mapping, "self", self_param.get_locus (),
- self_param.is_ref (),
- self_param.get_mut (),
- std::unique_ptr<HIR::Pattern> (nullptr));
+ HIR::IdentifierPattern *self_pattern = new HIR::IdentifierPattern (
+ mapping, {"self"}, self_param.get_locus (), self_param.is_ref (),
+ self_param.get_mut (), std::unique_ptr<HIR::Pattern> (nullptr));
// might have a specified type
TyTy::BaseType *self_type = nullptr;
rust_assert (ok);
RustIdent ident{*canonical_path, function.get_locus ()};
- auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (),
- function.get_mappings ().get_defid (),
- function.get_function_name (), ident,
- function.is_method ()
- ? TyTy::FnType::FNTYPE_IS_METHOD_FLAG
- : TyTy::FnType::FNTYPE_DEFAULT_FLAGS,
- ABI::RUST, std::move (params), ret_type,
- std::move (substitutions));
+ auto fnType
+ = new TyTy::FnType (function.get_mappings ().get_hirid (),
+ function.get_mappings ().get_defid (),
+ function.get_function_name ().as_string (), ident,
+ function.is_method ()
+ ? TyTy::FnType::FNTYPE_IS_METHOD_FLAG
+ : TyTy::FnType::FNTYPE_DEFAULT_FLAGS,
+ ABI::RUST, std::move (params), ret_type,
+ std::move (substitutions));
context->insert_type (function.get_mappings (), fnType);
result = fnType;
const auto tref = trait_reference.get ();
const TraitItemReference *raw_trait_item = nullptr;
bool found
- = tref->lookup_trait_item_by_type (constant.get_identifier (),
+ = tref->lookup_trait_item_by_type (constant.get_identifier ().as_string (),
TraitItemReference::TraitItemType::CONST,
&raw_trait_item);
RichLocation r (constant.get_locus ());
r.add_range (trait_reference.get_locus ());
rust_error_at (r, "constant %<%s%> is not a member of trait %<%s%>",
- constant.get_identifier ().c_str (),
+ constant.get_identifier ().as_string ().c_str (),
trait_reference.get_name ().c_str ());
return;
}
rust_error_at (
r, "constant %<%s%> has an incompatible type for trait %<%s%>",
- constant.get_identifier ().c_str (),
+ constant.get_identifier ().as_string ().c_str (),
trait_reference.get_name ().c_str ());
}
}
const auto tref = trait_reference.get ();
const TraitItemReference *raw_trait_item = nullptr;
bool found
- = tref->lookup_trait_item_by_type (type.get_new_type_name (),
+ = tref->lookup_trait_item_by_type (type.get_new_type_name ().as_string (),
TraitItemReference::TraitItemType::TYPE,
&raw_trait_item);
RichLocation r (type.get_locus ());
r.add_range (trait_reference.get_locus ());
rust_error_at (r, "type alias %<%s%> is not a member of trait %<%s%>",
- type.get_new_type_name ().c_str (),
+ type.get_new_type_name ().as_string ().c_str (),
trait_reference.get_name ().c_str ());
return;
}
rust_error_at (
r, "type alias %<%s%> has an incompatible type for trait %<%s%>",
- type.get_new_type_name ().c_str (),
+ type.get_new_type_name ().as_string ().c_str (),
trait_reference.get_name ().c_str ());
}
// map the impl item to the associated trait item
const auto tref = trait_reference.get ();
const TraitItemReference *raw_trait_item = nullptr;
- bool found
- = tref->lookup_trait_item_by_type (function.get_function_name (),
- TraitItemReference::TraitItemType::FN,
- &raw_trait_item);
+ bool found = tref->lookup_trait_item_by_type (
+ function.get_function_name ().as_string (),
+ TraitItemReference::TraitItemType::FN, &raw_trait_item);
// unknown trait item
if (!found || raw_trait_item->is_error ())
RichLocation r (function.get_locus ());
r.add_range (trait_reference.get_locus ());
rust_error_at (r, "method %<%s%> is not a member of trait %<%s%>",
- function.get_function_name ().c_str (),
+ function.get_function_name ().as_string ().c_str (),
trait_reference.get_name ().c_str ());
return;
}
rust_error_at (r,
"method %<%s%> has an incompatible type for trait %<%s%>",
- function.get_function_name ().c_str (),
+ function.get_function_name ().as_string ().c_str (),
trait_reference.get_name ().c_str ());
}
}
// its a single variant ADT
std::vector<TyTy::VariantDef *> variants;
- variants.push_back (new TyTy::VariantDef (
- struct_decl.get_mappings ().get_hirid (),
- struct_decl.get_mappings ().get_defid (), struct_decl.get_identifier (),
- ident, TyTy::VariantDef::VariantType::TUPLE, nullptr, std::move (fields)));
+ variants.push_back (
+ new TyTy::VariantDef (struct_decl.get_mappings ().get_hirid (),
+ struct_decl.get_mappings ().get_defid (),
+ struct_decl.get_identifier ().as_string (), ident,
+ TyTy::VariantDef::VariantType::TUPLE, nullptr,
+ std::move (fields)));
// Process #[repr(X)] attribute, if any
const AST::AttrVec &attrs = struct_decl.get_outer_attrs ();
TyTy::BaseType *type
= new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (),
mappings->get_next_hir_id (),
- struct_decl.get_identifier (), ident,
+ struct_decl.get_identifier ().as_string (), ident,
TyTy::ADTType::ADTKind::TUPLE_STRUCT,
std::move (variants), std::move (substitutions), repr);
= TypeCheckType::Resolve (field.get_field_type ().get ());
TyTy::StructFieldType *ty_field
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
- field.get_field_name (), field_type,
- field.get_locus ());
+ field.get_field_name ().as_string (),
+ field_type, field.get_locus ());
fields.push_back (ty_field);
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
}
// its a single variant ADT
std::vector<TyTy::VariantDef *> variants;
- variants.push_back (new TyTy::VariantDef (
- struct_decl.get_mappings ().get_hirid (),
- struct_decl.get_mappings ().get_defid (), struct_decl.get_identifier (),
- ident, TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields)));
+ variants.push_back (
+ new TyTy::VariantDef (struct_decl.get_mappings ().get_hirid (),
+ struct_decl.get_mappings ().get_defid (),
+ struct_decl.get_identifier ().as_string (), ident,
+ TyTy::VariantDef::VariantType::STRUCT, nullptr,
+ std::move (fields)));
// Process #[repr(X)] attribute, if any
const AST::AttrVec &attrs = struct_decl.get_outer_attrs ();
TyTy::BaseType *type
= new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (),
mappings->get_next_hir_id (),
- struct_decl.get_identifier (), ident,
+ struct_decl.get_identifier ().as_string (), ident,
TyTy::ADTType::ADTKind::STRUCT_STRUCT,
std::move (variants), std::move (substitutions), repr);
TyTy::BaseType *type
= new TyTy::ADTType (enum_decl.get_mappings ().get_hirid (),
mappings->get_next_hir_id (),
- enum_decl.get_identifier (), ident,
+ enum_decl.get_identifier ().as_string (), ident,
TyTy::ADTType::ADTKind::ENUM, std::move (variants),
std::move (substitutions));
= TypeCheckType::Resolve (variant.get_field_type ().get ());
TyTy::StructFieldType *ty_variant
= new TyTy::StructFieldType (variant.get_mappings ().get_hirid (),
- variant.get_field_name (), variant_type,
- variant.get_locus ());
+ variant.get_field_name ().as_string (),
+ variant_type, variant.get_locus ());
fields.push_back (ty_variant);
context->insert_type (variant.get_mappings (),
ty_variant->get_field_type ());
// there is only a single variant
std::vector<TyTy::VariantDef *> variants;
- variants.push_back (new TyTy::VariantDef (
- union_decl.get_mappings ().get_hirid (),
- union_decl.get_mappings ().get_defid (), union_decl.get_identifier (),
- ident, TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields)));
+ variants.push_back (
+ new TyTy::VariantDef (union_decl.get_mappings ().get_hirid (),
+ union_decl.get_mappings ().get_defid (),
+ union_decl.get_identifier ().as_string (), ident,
+ TyTy::VariantDef::VariantType::STRUCT, nullptr,
+ std::move (fields)));
TyTy::BaseType *type
= new TyTy::ADTType (union_decl.get_mappings ().get_hirid (),
mappings->get_next_hir_id (),
- union_decl.get_identifier (), ident,
+ union_decl.get_identifier ().as_string (), ident,
TyTy::ADTType::ADTKind::UNION, std::move (variants),
std::move (substitutions));
RustIdent ident{*canonical_path, function.get_locus ()};
auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (),
function.get_mappings ().get_defid (),
- function.get_function_name (), ident,
- TyTy::FnType::FNTYPE_DEFAULT_FLAGS, ABI::RUST,
- std::move (params), ret_type,
+ function.get_function_name ().as_string (),
+ ident, TyTy::FnType::FNTYPE_DEFAULT_FLAGS,
+ ABI::RUST, std::move (params), ret_type,
std::move (substitutions));
context->insert_type (function.get_mappings (), fnType);
= static_cast<HIR::StructPatternFieldIdentPat &> (*field.get ());
TyTy::StructFieldType *field = nullptr;
- if (!variant->lookup_field (ident.get_identifier (), &field,
- nullptr))
+ if (!variant->lookup_field (ident.get_identifier ().as_string (),
+ &field, nullptr))
{
rust_error_at (ident.get_locus (), ErrorCode ("E0026"),
"variant %s does not have a field named %s",
variant->get_identifier ().c_str (),
- ident.get_identifier ().c_str ());
+ ident.get_identifier ().as_string ().c_str ());
break;
}
- named_fields.push_back (ident.get_identifier ());
+ named_fields.push_back (ident.get_identifier ().as_string ());
TyTy::BaseType *fty = field->get_field_type ();
TypeCheckPattern::Resolve (ident.get_pattern ().get (), fty);
= static_cast<HIR::StructPatternFieldIdent &> (*field.get ());
TyTy::StructFieldType *field = nullptr;
- if (!variant->lookup_field (ident.get_identifier (), &field,
- nullptr))
+ if (!variant->lookup_field (ident.get_identifier ().as_string (),
+ &field, nullptr))
{
rust_error_at (ident.get_locus (), ErrorCode ("E0026"),
"variant %s does not have a field named %s",
variant->get_identifier ().c_str (),
- ident.get_identifier ().c_str ());
+ ident.get_identifier ().as_string ().c_str ());
break;
}
- named_fields.push_back (ident.get_identifier ());
+ named_fields.push_back (ident.get_identifier ().as_string ());
// setup the type on this pattern
TyTy::BaseType *fty = field->get_field_type ();
void
TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifierValue &field)
{
- auto it = fields_assigned.find (field.field_name);
+ auto it = fields_assigned.find (field.field_name.as_string ());
if (it != fields_assigned.end ())
{
rust_fatal_error (field.get_locus (), "used more than once");
size_t field_index;
TyTy::StructFieldType *field_type;
- bool ok = variant->lookup_field (field.field_name, &field_type, &field_index);
+ bool ok = variant->lookup_field (field.field_name.as_string (), &field_type,
+ &field_index);
if (!ok)
{
rust_error_at (field.get_locus (), "unknown field");
field.get_locus ());
if (resolved_field_value_expr != nullptr)
{
- fields_assigned.insert (field.field_name);
+ fields_assigned.insert (field.field_name.as_string ());
adtFieldIndexToField[field_index] = &field;
}
}
void
TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field)
{
- auto it = fields_assigned.find (field.get_field_name ());
+ auto it = fields_assigned.find (field.get_field_name ().as_string ());
if (it != fields_assigned.end ())
{
rust_fatal_error (field.get_locus (), "used more than once");
size_t field_index;
TyTy::StructFieldType *field_type;
- bool ok = variant->lookup_field (field.get_field_name (), &field_type,
- &field_index);
+ bool ok = variant->lookup_field (field.get_field_name ().as_string (),
+ &field_type, &field_index);
if (!ok)
{
rust_error_at (field.get_locus (), "unknown field");
Analysis::NodeMapping mappings_copy1 = field.get_mappings ();
Analysis::NodeMapping mappings_copy2 = field.get_mappings ();
- HIR::PathIdentSegment ident_seg (field.get_field_name ());
+ HIR::PathIdentSegment ident_seg (field.get_field_name ().as_string ());
HIR::PathExprSegment seg (mappings_copy1, ident_seg, field.get_locus (),
HIR::GenericArgs::create_empty ());
HIR::PathInExpression expr (mappings_copy2, {seg}, field.get_locus (), false,
if (resolved_field_value_expr != nullptr)
{
- fields_assigned.insert (field.get_field_name ());
+ fields_assigned.insert (field.get_field_name ().as_string ());
adtFieldIndexToField[field_index] = &field;
}
}
// bounds otherwise it will be a trait cycle
HirId implicit_id = mappings->get_next_hir_id ();
TyTy::ParamType *p
- = new TyTy::ParamType (param.get_type_representation (),
+ = new TyTy::ParamType (param.get_type_representation ().as_string (),
param.get_locus (), implicit_id, param,
{} /*empty specified bounds*/);
context->insert_implicit_type (implicit_id, p);
}
}
- resolved
- = new TyTy::ParamType (param.get_type_representation (), param.get_locus (),
- param.get_mappings ().get_hirid (), param,
- specified_bounds);
+ resolved = new TyTy::ParamType (param.get_type_representation ().as_string (),
+ param.get_locus (),
+ param.get_mappings ().get_hirid (), param,
+ specified_bounds);
}
void
// for compilation to know parameter names. The types are ignored
// but we reuse the HIR identifier pattern which requires it
HIR::SelfParam &self_param = function.get_self ();
- HIR::IdentifierPattern *self_pattern
- = new HIR::IdentifierPattern (mapping, "self", self_param.get_locus (),
- self_param.is_ref (),
- self_param.is_mut () ? Mutability::Mut
- : Mutability::Imm,
- std::unique_ptr<HIR::Pattern> (nullptr));
+ HIR::IdentifierPattern *self_pattern = new HIR::IdentifierPattern (
+ mapping, {"self"}, self_param.get_locus (), self_param.is_ref (),
+ self_param.is_mut () ? Mutability::Mut : Mutability::Imm,
+ std::unique_ptr<HIR::Pattern> (nullptr));
// might have a specified type
TyTy::BaseType *self_type = nullptr;
if (self_param.has_type ())
auto resolved
= new TyTy::FnType (fn.get_mappings ().get_hirid (),
fn.get_mappings ().get_defid (),
- function.get_function_name (), ident,
+ function.get_function_name ().as_string (), ident,
function.is_method ()
? TyTy::FnType::FNTYPE_IS_METHOD_FLAG
: TyTy::FnType::FNTYPE_DEFAULT_FLAGS,
}
// resolve to relevant binding
- auto binding_item
- = lookup_associated_type (binding.get_identifier ());
+ auto binding_item = lookup_associated_type (
+ binding.get_identifier ().as_string ());
if (binding_item.is_error ())
{
- rust_error_at (binding.get_locus (),
- "unknown associated type binding: %s",
- binding.get_identifier ().c_str ());
+ rust_error_at (
+ binding.get_locus (), "unknown associated type binding: %s",
+ binding.get_identifier ().as_string ().c_str ());
return SubstitutionArgumentMappings::error ();
}
- binding_arguments[binding.get_identifier ()] = resolved;
+ binding_arguments[binding.get_identifier ().as_string ()]
+ = resolved;
}
}
else
->get_name_value_pair ();
// FIXME: Check for other stuff than #[doc(alias = ...)]
- if (name_value.first == "alias")
+ if (name_value.first.as_string () == "alias")
check_doc_alias (name_value.second, attribute.get_locus ());
}
}
});
if (should_be_builtin)
{
- auto builtin = MacroBuiltin::builtins.lookup (macro->get_rule_name ());
+ auto builtin
+ = MacroBuiltin::builtins.lookup (macro->get_rule_name ().as_string ());
if (!MacroBuiltin::builtins.is_iter_ok (builtin))
{
rust_error_at (macro->get_locus (),
"cannot find a built-in macro with name %qs",
- macro->get_rule_name ().c_str ());
+ macro->get_rule_name ().as_string ().c_str ());
return;
}
- auto transcriber
- = MacroBuiltin::builtin_transcribers.find (macro->get_rule_name ());
+ auto transcriber = MacroBuiltin::builtin_transcribers.find (
+ macro->get_rule_name ().as_string ());
macro->set_builtin_transcriber (transcriber->second);
}