if (is_op_overload)
{
auto lang_item_type
- = Analysis::RustLangItem::OperatorToLangItem (expr.get_expr_type ());
+ = LangItem::OperatorToLangItem (expr.get_expr_type ());
translated = resolve_operator_overload (lang_item_type, expr, lhs, rhs,
expr.get_lhs ().get (),
expr.get_rhs ().get ());
expr.get_mappings ().get_hirid (), &fntype);
if (is_op_overload)
{
- auto lang_item_type
- = Analysis::RustLangItem::CompoundAssignmentOperatorToLangItem (
- expr.get_expr_type ());
+ auto lang_item_type = LangItem::CompoundAssignmentOperatorToLangItem (
+ expr.get_expr_type ());
auto compound_assignment
= resolve_operator_overload (lang_item_type, expr, lhs, rhs,
expr.get_lhs ().get (),
expr.get_mappings ().get_hirid (), &fntype);
if (is_op_overload)
{
- auto lang_item_type
- = Analysis::RustLangItem::NegationOperatorToLangItem (op);
+ auto lang_item_type = LangItem::NegationOperatorToLangItem (op);
translated
= resolve_operator_overload (lang_item_type, expr, negated_expr,
nullptr, expr.get_expr ().get (), nullptr);
expr.get_mappings ().get_hirid (), &fntype);
if (is_op_overload)
{
- auto lang_item_type = Analysis::RustLangItem::ItemType::DEREF;
+ auto lang_item_type = LangItem::Kind::DEREF;
tree operator_overload_call
= resolve_operator_overload (lang_item_type, expr, main_expr, nullptr,
expr.get_expr ().get (), nullptr);
}
tree
-CompileExpr::resolve_operator_overload (
- Analysis::RustLangItem::ItemType lang_item_type, HIR::OperatorExprMeta expr,
- tree lhs, tree rhs, HIR::Expr *lhs_expr, HIR::Expr *rhs_expr)
+CompileExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
+ HIR::OperatorExprMeta expr, tree lhs,
+ tree rhs, HIR::Expr *lhs_expr,
+ HIR::Expr *rhs_expr)
{
TyTy::FnType *fntype;
bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
}
// lookup compiled functions since it may have already been compiled
- HIR::PathIdentSegment segment_name (
- Analysis::RustLangItem::ToString (lang_item_type));
+ HIR::PathIdentSegment segment_name (LangItem::ToString (lang_item_type));
tree fn_expr = resolve_method_address (fntype, receiver, expr.get_locus ());
// lookup the autoderef mappings
expr.get_mappings ().get_hirid (), &fntype);
if (is_op_overload)
{
- auto lang_item_type = Analysis::RustLangItem::ItemType::INDEX;
+ auto lang_item_type = LangItem::Kind::INDEX;
tree operator_overload_call
= resolve_operator_overload (lang_item_type, expr, array_reference,
index, expr.get_array_expr ().get (),
TyTy::BaseType *receiver, TyTy::FnType *fntype,
tree receiver_ref, location_t expr_locus);
- tree
- resolve_operator_overload (Analysis::RustLangItem::ItemType lang_item_type,
- HIR::OperatorExprMeta expr, tree lhs, tree rhs,
- HIR::Expr *lhs_expr, HIR::Expr *rhs_expr);
+ tree resolve_operator_overload (LangItem::Kind lang_item_type,
+ HIR::OperatorExprMeta expr, tree lhs,
+ tree rhs, HIR::Expr *lhs_expr,
+ HIR::Expr *rhs_expr);
tree compile_bool_literal (const HIR::LiteralExpr &expr,
const TyTy::BaseType *tyty);
{
auto &literal = static_cast<AST::AttrInputLiteral &> (attr.get_attr_input ());
const auto &lang_item_type_str = literal.get_literal ().as_string ();
- auto lang_item_type = Analysis::RustLangItem::Parse (lang_item_type_str);
+ auto lang_item_type = LangItem::Parse (lang_item_type_str);
if (lang_item_type)
mappings->insert_lang_item (*lang_item_type,
static bool
resolve_operator_overload_fn (
- Analysis::RustLangItem::ItemType lang_item_type, TyTy::BaseType *ty,
- TyTy::FnType **resolved_fn,
+ LangItem::Kind lang_item_type, TyTy::BaseType *ty, TyTy::FnType **resolved_fn,
Adjustment::AdjustmentType *requires_ref_adjustment);
TyTy::BaseType *
}
Adjustment
-Adjuster::try_deref_type (TyTy::BaseType *ty,
- Analysis::RustLangItem::ItemType deref_lang_item)
+Adjuster::try_deref_type (TyTy::BaseType *ty, LangItem::Kind deref_lang_item)
{
TyTy::FnType *fn = nullptr;
Adjustment::AdjustmentType requires_ref_adjustment
= Adjustment::AdjustmentType::ERROR;
switch (deref_lang_item)
{
- case Analysis::RustLangItem::ItemType::DEREF:
+ case LangItem::Kind::DEREF:
adjustment_type = Adjustment::AdjustmentType::DEREF;
break;
- case Analysis::RustLangItem::ItemType::DEREF_MUT:
+ case LangItem::Kind::DEREF_MUT:
adjustment_type = Adjustment::AdjustmentType::DEREF_MUT;
break;
static bool
resolve_operator_overload_fn (
- Analysis::RustLangItem::ItemType lang_item_type, TyTy::BaseType *lhs,
+ LangItem::Kind lang_item_type, TyTy::BaseType *lhs,
TyTy::FnType **resolved_fn,
Adjustment::AdjustmentType *requires_ref_adjustment)
{
auto mappings = Analysis::Mappings::get ();
// look up lang item for arithmetic type
- std::string associated_item_name
- = Analysis::RustLangItem::ToString (lang_item_type);
+ std::string associated_item_name = LangItem::ToString (lang_item_type);
DefId respective_lang_item_id = UNKNOWN_DEFID;
bool lang_item_defined
= mappings->lookup_lang_item (lang_item_type, &respective_lang_item_id);
return false;
}
- Adjustment deref
- = Adjuster::try_deref_type (r, Analysis::RustLangItem::ItemType::DEREF);
+ Adjustment deref = Adjuster::try_deref_type (r, LangItem::Kind::DEREF);
if (!deref.is_error ())
{
auto deref_r = deref.get_expected ();
adjustments.pop_back ();
}
- Adjustment deref_mut = Adjuster::try_deref_type (
- r, Analysis::RustLangItem::ItemType::DEREF_MUT);
+ Adjustment deref_mut
+ = Adjuster::try_deref_type (r, LangItem::Kind::DEREF_MUT);
if (!deref_mut.is_error ())
{
auto deref_r = deref_mut.get_expected ();
TyTy::BaseType *adjust_type (const std::vector<Adjustment> &adjustments);
- static Adjustment
- try_deref_type (TyTy::BaseType *ty,
- Analysis::RustLangItem::ItemType deref_lang_item);
+ static Adjustment try_deref_type (TyTy::BaseType *ty,
+ LangItem::Kind deref_lang_item);
static Adjustment try_raw_deref_type (TyTy::BaseType *ty);
private:
void scan ();
void assemble_sized_builtin ();
- void assemble_builtin_candidate (Analysis::RustLangItem::ItemType item);
+ void assemble_builtin_candidate (LangItem::Kind item);
private:
TypeBoundsProbe (const TyTy::BaseType *receiver);
}
TyTy::TypeBoundPredicate
-TypeCheckBase::get_marker_predicate (Analysis::RustLangItem::ItemType item_type,
- location_t locus)
+TypeCheckBase::get_marker_predicate (LangItem::Kind item_type, location_t locus)
{
DefId item_id = mappings->get_lang_item (item_type, locus);
HIR::Item *item = mappings->lookup_defid (item_id);
const std::vector<std::unique_ptr<HIR::GenericParam> > &generic_params,
std::vector<TyTy::SubstitutionParamMapping> &substitutions);
- TyTy::TypeBoundPredicate
- get_marker_predicate (Analysis::RustLangItem::ItemType item_type,
- location_t locus);
+ TyTy::TypeBoundPredicate get_marker_predicate (LangItem::Kind item_type,
+ location_t locus);
Analysis::Mappings *mappings;
Resolver *resolver;
expr.get_locus ());
auto lang_item_type
- = Analysis::RustLangItem::CompoundAssignmentOperatorToLangItem (
- expr.get_expr_type ());
+ = LangItem::CompoundAssignmentOperatorToLangItem (expr.get_expr_type ());
bool operator_overloaded
= resolve_operator_overload (lang_item_type, expr, lhs, rhs);
if (operator_overloaded)
auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ());
auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ());
- auto lang_item_type
- = Analysis::RustLangItem::OperatorToLangItem (expr.get_expr_type ());
+ auto lang_item_type = LangItem::OperatorToLangItem (expr.get_expr_type ());
bool operator_overloaded
= resolve_operator_overload (lang_item_type, expr, lhs, rhs);
if (operator_overloaded)
auto negated_expr_ty = TypeCheckExpr::Resolve (expr.get_expr ().get ());
// check for operator overload
- auto lang_item_type = Analysis::RustLangItem::NegationOperatorToLangItem (
- expr.get_expr_type ());
+ auto lang_item_type
+ = LangItem::NegationOperatorToLangItem (expr.get_expr_type ());
bool operator_overloaded
= resolve_operator_overload (lang_item_type, expr, negated_expr_ty,
nullptr);
void
TypeCheckExpr::visit (HIR::RangeFromToExpr &expr)
{
- auto lang_item_type = Analysis::RustLangItem::ItemType::RANGE;
+ auto lang_item_type = LangItem::Kind::RANGE;
DefId respective_lang_item_id = UNKNOWN_DEFID;
bool lang_item_defined
// we need to have it maybe
if (!lang_item_defined)
{
- rust_internal_error_at (
- expr.get_locus (), "unable to find relevant lang item: %s",
- Analysis::RustLangItem::ToString (lang_item_type).c_str ());
+ rust_internal_error_at (expr.get_locus (),
+ "unable to find relevant lang item: %s",
+ LangItem::ToString (lang_item_type).c_str ());
return;
}
void
TypeCheckExpr::visit (HIR::RangeFromExpr &expr)
{
- auto lang_item_type = Analysis::RustLangItem::ItemType::RANGE_FROM;
+ auto lang_item_type = LangItem::Kind::RANGE_FROM;
DefId respective_lang_item_id = UNKNOWN_DEFID;
bool lang_item_defined
// we need to have it maybe
if (!lang_item_defined)
{
- rust_internal_error_at (
- expr.get_locus (), "unable to find relevant lang item: %s",
- Analysis::RustLangItem::ToString (lang_item_type).c_str ());
+ rust_internal_error_at (expr.get_locus (),
+ "unable to find relevant lang item: %s",
+ LangItem::ToString (lang_item_type).c_str ());
return;
}
void
TypeCheckExpr::visit (HIR::RangeToExpr &expr)
{
- auto lang_item_type = Analysis::RustLangItem::ItemType::RANGE_TO;
+ auto lang_item_type = LangItem::Kind::RANGE_TO;
DefId respective_lang_item_id = UNKNOWN_DEFID;
bool lang_item_defined
// we need to have it maybe
if (!lang_item_defined)
{
- rust_internal_error_at (
- expr.get_locus (), "unable to find relevant lang item: %s",
- Analysis::RustLangItem::ToString (lang_item_type).c_str ());
+ rust_internal_error_at (expr.get_locus (),
+ "unable to find relevant lang item: %s",
+ LangItem::ToString (lang_item_type).c_str ());
return;
}
void
TypeCheckExpr::visit (HIR::RangeFullExpr &expr)
{
- auto lang_item_type = Analysis::RustLangItem::ItemType::RANGE_FULL;
+ auto lang_item_type = LangItem::Kind::RANGE_FULL;
DefId respective_lang_item_id = UNKNOWN_DEFID;
bool lang_item_defined
// we need to have it maybe
if (!lang_item_defined)
{
- rust_internal_error_at (
- expr.get_locus (), "unable to find relevant lang item: %s",
- Analysis::RustLangItem::ToString (lang_item_type).c_str ());
+ rust_internal_error_at (expr.get_locus (),
+ "unable to find relevant lang item: %s",
+ LangItem::ToString (lang_item_type).c_str ());
return;
}
void
TypeCheckExpr::visit (HIR::RangeFromToInclExpr &expr)
{
- auto lang_item_type = Analysis::RustLangItem::ItemType::RANGE_INCLUSIVE;
+ auto lang_item_type = LangItem::Kind::RANGE_INCLUSIVE;
DefId respective_lang_item_id = UNKNOWN_DEFID;
bool lang_item_defined
// we need to have it maybe
if (!lang_item_defined)
{
- rust_internal_error_at (
- expr.get_locus (), "unable to find relevant lang item: %s",
- Analysis::RustLangItem::ToString (lang_item_type).c_str ());
+ rust_internal_error_at (expr.get_locus (),
+ "unable to find relevant lang item: %s",
+ LangItem::ToString (lang_item_type).c_str ());
return;
}
}
// is this a case of core::ops::index?
- auto lang_item_type = Analysis::RustLangItem::ItemType::INDEX;
+ auto lang_item_type = LangItem::Kind::INDEX;
bool operator_overloaded
= resolve_operator_overload (lang_item_type, expr, array_expr_ty,
index_expr_ty);
= TypeCheckExpr::Resolve (expr.get_expr ().get ());
rust_debug_loc (expr.get_locus (), "attempting deref operator overload");
- auto lang_item_type = Analysis::RustLangItem::ItemType::DEREF;
+ auto lang_item_type = LangItem::Kind::DEREF;
bool operator_overloaded
= resolve_operator_overload (lang_item_type, expr, resolved_base, nullptr);
if (operator_overloaded)
// assume FnOnce for now. I think this is based on the return type of the
// closure
- Analysis::RustLangItem::ItemType lang_item_type
- = Analysis::RustLangItem::ItemType::FN_ONCE;
+ LangItem::Kind lang_item_type = LangItem::Kind::FN_ONCE;
DefId respective_lang_item_id = UNKNOWN_DEFID;
bool lang_item_defined
= mappings->lookup_lang_item (lang_item_type, &respective_lang_item_id);
// FIXME
// we need to have a unified way or error'ing when we are missing lang
// items that is useful
- rust_fatal_error (
- expr.get_locus (), "unable to find lang item: %<%s%>",
- Analysis::RustLangItem::ToString (lang_item_type).c_str ());
+ rust_fatal_error (expr.get_locus (), "unable to find lang item: %<%s%>",
+ LangItem::ToString (lang_item_type).c_str ());
}
rust_assert (lang_item_defined);
}
bool
-TypeCheckExpr::resolve_operator_overload (
- Analysis::RustLangItem::ItemType lang_item_type, HIR::OperatorExprMeta expr,
- TyTy::BaseType *lhs, TyTy::BaseType *rhs)
+TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
+ HIR::OperatorExprMeta expr,
+ TyTy::BaseType *lhs,
+ TyTy::BaseType *rhs)
{
// look up lang item for arithmetic type
- std::string associated_item_name
- = Analysis::RustLangItem::ToString (lang_item_type);
+ std::string associated_item_name = LangItem::ToString (lang_item_type);
DefId respective_lang_item_id = UNKNOWN_DEFID;
bool lang_item_defined
= mappings->lookup_lang_item (lang_item_type, &respective_lang_item_id);
}
protected:
- bool
- resolve_operator_overload (Analysis::RustLangItem::ItemType lang_item_type,
- HIR::OperatorExprMeta expr, TyTy::BaseType *lhs,
- TyTy::BaseType *rhs);
+ bool resolve_operator_overload (LangItem::Kind lang_item_type,
+ HIR::OperatorExprMeta expr,
+ TyTy::BaseType *lhs, TyTy::BaseType *rhs);
bool resolve_fn_trait_call (HIR::CallExpr &expr,
TyTy::BaseType *function_tyty,
if (apply_sized)
{
TyTy::TypeBoundPredicate sized_predicate
- = get_marker_predicate (Analysis::RustLangItem::ItemType::SIZED,
- param.get_locus ());
+ = get_marker_predicate (LangItem::Kind::SIZED, param.get_locus ());
predicates[sized_predicate.get_id ()] = {sized_predicate};
}
case TyTy::NEVER:
case TyTy::PLACEHOLDER:
case TyTy::PROJECTION:
- assemble_builtin_candidate (Analysis::RustLangItem::SIZED);
+ assemble_builtin_candidate (LangItem::Kind::SIZED);
break;
// FIXME str and slice need to be moved and test cases updated
case TyTy::ADT:
case TyTy::TUPLE:
// FIXME add extra checks
- assemble_builtin_candidate (Analysis::RustLangItem::SIZED);
+ assemble_builtin_candidate (LangItem::Kind::SIZED);
break;
case TyTy::DYNAMIC:
}
void
-TypeBoundsProbe::assemble_builtin_candidate (
- Analysis::RustLangItem::ItemType lang_item)
+TypeBoundsProbe::assemble_builtin_candidate (LangItem::Kind lang_item)
{
DefId id;
bool found_lang_item = mappings->lookup_lang_item (lang_item, &id);
trait_references.push_back ({trait_ref, mappings->lookup_builtin_marker ()});
rust_debug ("Added builtin lang_item: %s for %s",
- Analysis::RustLangItem::ToString (lang_item).c_str (),
+ LangItem::ToString (lang_item).c_str (),
raw->get_name ().c_str ());
}
TypeCheckType::Resolve (fn.get_return_type ().get ());
HIR::TraitItem *trait_item = mappings->lookup_trait_item_lang_item (
- Analysis::RustLangItem::ItemType::FN_ONCE_OUTPUT,
- final_seg->get_locus ());
+ LangItem::Kind::FN_ONCE_OUTPUT, final_seg->get_locus ());
std::vector<HIR::GenericArgsBinding> bindings;
location_t output_locus = fn.get_return_type ()->get_locus ();
ClosureType::setup_fn_once_output () const
{
// lookup the lang items
- auto fn_once_lang_item = Analysis::RustLangItem::ItemType::FN_ONCE;
- auto fn_once_output_lang_item
- = Analysis::RustLangItem::ItemType::FN_ONCE_OUTPUT;
+ auto fn_once_lang_item = LangItem::Kind::FN_ONCE;
+ auto fn_once_output_lang_item = LangItem::Kind::FN_ONCE_OUTPUT;
DefId trait_id = UNKNOWN_DEFID;
bool trait_lang_item_defined
}
DefId
-Mappings::get_lang_item (RustLangItem::ItemType item_type, location_t locus)
+Mappings::get_lang_item (LangItem::Kind item_type, location_t locus)
{
DefId item = UNKNOWN_DEFID;
bool ok = lookup_lang_item (item_type, &item);
if (!ok)
rust_fatal_error (locus, "failed to find lang item %s",
- RustLangItem::ToString (item_type).c_str ());
+ LangItem::ToString (item_type).c_str ());
return item;
}
HIR::TraitItem *
-Mappings::lookup_trait_item_lang_item (Analysis::RustLangItem::ItemType item,
- location_t locus)
+Mappings::lookup_trait_item_lang_item (LangItem::Kind item, location_t locus)
{
DefId trait_item_id = get_lang_item (item, locus);
return lookup_trait_item_defid (trait_item_id);
return true;
}
- void insert_lang_item (RustLangItem::ItemType item_type, DefId id)
+ void insert_lang_item (LangItem::Kind item_type, DefId id)
{
auto it = lang_item_mappings.find (item_type);
rust_assert (it == lang_item_mappings.end ());
lang_item_mappings[item_type] = id;
}
- bool lookup_lang_item (RustLangItem::ItemType item_type, DefId *id)
+ bool lookup_lang_item (LangItem::Kind item_type, DefId *id)
{
auto it = lang_item_mappings.find (item_type);
if (it == lang_item_mappings.end ())
}
// This will fatal_error when this lang item does not exist
- DefId get_lang_item (RustLangItem::ItemType item_type, location_t locus);
+ DefId get_lang_item (LangItem::Kind item_type, location_t locus);
void insert_macro_def (AST::MacroRulesDefinition *macro);
HIR::ImplBlock *lookup_builtin_marker ();
- HIR::TraitItem *
- lookup_trait_item_lang_item (Analysis::RustLangItem::ItemType item,
- location_t locus);
+ HIR::TraitItem *lookup_trait_item_lang_item (LangItem::Kind item,
+ location_t locus);
private:
Mappings ();
std::map<HirId, HIR::GenericParam *> hirGenericParamMappings;
std::map<HirId, HIR::Trait *> hirTraitItemsToTraitMappings;
std::map<HirId, HIR::Pattern *> hirPatternMappings;
- std::map<RustLangItem::ItemType, DefId> lang_item_mappings;
+ std::map<LangItem::Kind, DefId> lang_item_mappings;
std::map<NodeId, const Resolver::CanonicalPath> paths;
std::map<NodeId, location_t> locations;
std::map<NodeId, HirId> nodeIdToHirMappings;
#include "rust-system.h"
namespace Rust {
-namespace Analysis {
-
-const BiMap<std::string, RustLangItem::ItemType>
- Rust::Analysis::RustLangItem::lang_items = {{
- {"add", ADD},
- {"sub", SUBTRACT},
- {"mul", MULTIPLY},
- {"div", DIVIDE},
- {"rem", REMAINDER},
- {"bitand", BITAND},
- {"bitor", BITOR},
- {"bitxor", BITXOR},
- {"shl", SHL},
- {"shr", SHR},
- {"neg", NEGATION},
- {"not", NOT},
- {"add_assign", ADD_ASSIGN},
- {"sub_assign", SUB_ASSIGN},
- {"mul_assign", MUL_ASSIGN},
- {"div_assign", DIV_ASSIGN},
- {"rem_assign", REM_ASSIGN},
- {"bitand_assign", BITAND_ASSIGN},
- {"bitor_assign", BITOR_ASSIGN},
- {"bitxor_assign", BITXOR_ASSIGN},
- {"shl_assign", SHL_ASSIGN},
- {"shr_assign", SHR_ASSIGN},
- {"deref", DEREF},
- {"deref_mut", DEREF_MUT},
- {"index", INDEX},
- {"index_mut", INDEX_MUT},
- {"RangeFull", RANGE_FULL},
- {"Range", RANGE},
- {"RangeFrom", RANGE_FROM},
- {"RangeTo", RANGE_TO},
- {"RangeInclusive", RANGE_INCLUSIVE},
- {"RangeToInclusive", RANGE_TO_INCLUSIVE},
- {"phantom_data", PHANTOM_DATA},
- {"fn", FN},
- {"fn_mut", FN_MUT},
- {"fn_once", FN_ONCE},
- {"fn_once_output", FN_ONCE_OUTPUT},
- {"copy", COPY},
- {"clone", CLONE},
- {"sized", SIZED},
- {"slice_alloc", SLICE_ALLOC},
- {"slice_u8_alloc", SLICE_U8_ALLOC},
- {"str_alloc", STR_ALLOC},
- {"array", ARRAY},
- {"bool", BOOL},
- {"char", CHAR},
- {"f32", F32},
- {"f64", F64},
- {"i8", I8},
- {"i16", I16},
- {"i32", I32},
- {"i64", I64},
- {"i128", I128},
- {"isize", ISIZE},
- {"u8", U8},
- {"u16", U16},
- {"u32", U32},
- {"u64", U64},
- {"u128", U128},
- {"usize", USIZE},
- {"const_ptr", CONST_PTR},
- {"const_slice_ptr", CONST_SLICE_PTR},
- {"mut_ptr", MUT_PTR},
- {"mut_slice_ptr", MUT_SLICE_PTR},
- {"slice_u8", SLICE_U8},
- {"slice", SLICE},
- {"str", STR},
- {"f32_runtime", F32_RUNTIME},
- {"f64_runtime", F64_RUNTIME},
- }};
-
-tl::optional<RustLangItem::ItemType>
-RustLangItem::Parse (const std::string &item)
+
+const BiMap<std::string, LangItem::Kind> Rust::LangItem::lang_items = {{
+ {"add", Kind::ADD},
+ {"sub", Kind::SUBTRACT},
+ {"mul", Kind::MULTIPLY},
+ {"div", Kind::DIVIDE},
+ {"rem", Kind::REMAINDER},
+ {"bitand", Kind::BITAND},
+ {"bitor", Kind::BITOR},
+ {"bitxor", Kind::BITXOR},
+ {"shl", Kind::SHL},
+ {"shr", Kind::SHR},
+ {"neg", Kind::NEGATION},
+ {"not", Kind::NOT},
+ {"add_assign", Kind::ADD_ASSIGN},
+ {"sub_assign", Kind::SUB_ASSIGN},
+ {"mul_assign", Kind::MUL_ASSIGN},
+ {"div_assign", Kind::DIV_ASSIGN},
+ {"rem_assign", Kind::REM_ASSIGN},
+ {"bitand_assign", Kind::BITAND_ASSIGN},
+ {"bitor_assign", Kind::BITOR_ASSIGN},
+ {"bitxor_assign", Kind::BITXOR_ASSIGN},
+ {"shl_assign", Kind::SHL_ASSIGN},
+ {"shr_assign", Kind::SHR_ASSIGN},
+ {"deref", Kind::DEREF},
+ {"deref_mut", Kind::DEREF_MUT},
+ {"index", Kind::INDEX},
+ {"index_mut", Kind::INDEX_MUT},
+ {"RangeFull", Kind::RANGE_FULL},
+ {"Range", Kind::RANGE},
+ {"RangeFrom", Kind::RANGE_FROM},
+ {"RangeTo", Kind::RANGE_TO},
+ {"RangeInclusive", Kind::RANGE_INCLUSIVE},
+ {"RangeToInclusive", Kind::RANGE_TO_INCLUSIVE},
+ {"phantom_data", Kind::PHANTOM_DATA},
+ {"fn", Kind::FN},
+ {"fn_mut", Kind::FN_MUT},
+ {"fn_once", Kind::FN_ONCE},
+ {"fn_once_output", Kind::FN_ONCE_OUTPUT},
+ {"copy", Kind::COPY},
+ {"clone", Kind::CLONE},
+ {"sized", Kind::SIZED},
+ {"slice_alloc", Kind::SLICE_ALLOC},
+ {"slice_u8_alloc", Kind::SLICE_U8_ALLOC},
+ {"str_alloc", Kind::STR_ALLOC},
+ {"array", Kind::ARRAY},
+ {"bool", Kind::BOOL},
+ {"char", Kind::CHAR},
+ {"f32", Kind::F32},
+ {"f64", Kind::F64},
+ {"i8", Kind::I8},
+ {"i16", Kind::I16},
+ {"i32", Kind::I32},
+ {"i64", Kind::I64},
+ {"i128", Kind::I128},
+ {"isize", Kind::ISIZE},
+ {"u8", Kind::U8},
+ {"u16", Kind::U16},
+ {"u32", Kind::U32},
+ {"u64", Kind::U64},
+ {"u128", Kind::U128},
+ {"usize", Kind::USIZE},
+ {"const_ptr", Kind::CONST_PTR},
+ {"const_slice_ptr", Kind::CONST_SLICE_PTR},
+ {"mut_ptr", Kind::MUT_PTR},
+ {"mut_slice_ptr", Kind::MUT_SLICE_PTR},
+ {"slice_u8", Kind::SLICE_U8},
+ {"slice", Kind::SLICE},
+ {"str", Kind::STR},
+ {"f32_runtime", Kind::F32_RUNTIME},
+ {"f64_runtime", Kind::F64_RUNTIME},
+}};
+
+tl::optional<LangItem::Kind>
+LangItem::Parse (const std::string &item)
{
- auto lang_item = RustLangItem::lang_items.lookup (item);
- if (!RustLangItem::lang_items.is_iter_ok (lang_item))
+ auto lang_item = LangItem::lang_items.lookup (item);
+ if (!LangItem::lang_items.is_iter_ok (lang_item))
return tl::nullopt;
return lang_item->second;
}
std::string
-RustLangItem::ToString (RustLangItem::ItemType type)
+LangItem::ToString (LangItem::Kind type)
{
- auto str = RustLangItem::lang_items.lookup (type);
+ auto str = LangItem::lang_items.lookup (type);
return str->second;
}
-RustLangItem::ItemType
-RustLangItem::OperatorToLangItem (ArithmeticOrLogicalOperator op)
+LangItem::Kind
+LangItem::OperatorToLangItem (ArithmeticOrLogicalOperator op)
{
switch (op)
{
case ArithmeticOrLogicalOperator::ADD:
- return RustLangItem::ItemType::ADD;
+ return LangItem::Kind::ADD;
case ArithmeticOrLogicalOperator::SUBTRACT:
- return RustLangItem::ItemType::SUBTRACT;
+ return LangItem::Kind::SUBTRACT;
case ArithmeticOrLogicalOperator::MULTIPLY:
- return RustLangItem::ItemType::MULTIPLY;
+ return LangItem::Kind::MULTIPLY;
case ArithmeticOrLogicalOperator::DIVIDE:
- return RustLangItem::ItemType::DIVIDE;
+ return LangItem::Kind::DIVIDE;
case ArithmeticOrLogicalOperator::MODULUS:
- return RustLangItem::ItemType::REMAINDER;
+ return LangItem::Kind::REMAINDER;
case ArithmeticOrLogicalOperator::BITWISE_AND:
- return RustLangItem::ItemType::BITAND;
+ return LangItem::Kind::BITAND;
case ArithmeticOrLogicalOperator::BITWISE_OR:
- return RustLangItem::ItemType::BITOR;
+ return LangItem::Kind::BITOR;
case ArithmeticOrLogicalOperator::BITWISE_XOR:
- return RustLangItem::ItemType::BITXOR;
+ return LangItem::Kind::BITXOR;
case ArithmeticOrLogicalOperator::LEFT_SHIFT:
- return RustLangItem::ItemType::SHL;
+ return LangItem::Kind::SHL;
case ArithmeticOrLogicalOperator::RIGHT_SHIFT:
- return RustLangItem::ItemType::SHR;
+ return LangItem::Kind::SHR;
}
rust_unreachable ();
}
-RustLangItem::ItemType
-RustLangItem::CompoundAssignmentOperatorToLangItem (
- ArithmeticOrLogicalOperator op)
+LangItem::Kind
+LangItem::CompoundAssignmentOperatorToLangItem (ArithmeticOrLogicalOperator op)
{
switch (op)
{
case ArithmeticOrLogicalOperator::ADD:
- return RustLangItem::ItemType::ADD_ASSIGN;
+ return LangItem::Kind::ADD_ASSIGN;
case ArithmeticOrLogicalOperator::SUBTRACT:
- return RustLangItem::ItemType::SUB_ASSIGN;
+ return LangItem::Kind::SUB_ASSIGN;
case ArithmeticOrLogicalOperator::MULTIPLY:
- return RustLangItem::ItemType::MUL_ASSIGN;
+ return LangItem::Kind::MUL_ASSIGN;
case ArithmeticOrLogicalOperator::DIVIDE:
- return RustLangItem::ItemType::DIV_ASSIGN;
+ return LangItem::Kind::DIV_ASSIGN;
case ArithmeticOrLogicalOperator::MODULUS:
- return RustLangItem::ItemType::REM_ASSIGN;
+ return LangItem::Kind::REM_ASSIGN;
case ArithmeticOrLogicalOperator::BITWISE_AND:
- return RustLangItem::ItemType::BITAND_ASSIGN;
+ return LangItem::Kind::BITAND_ASSIGN;
case ArithmeticOrLogicalOperator::BITWISE_OR:
- return RustLangItem::ItemType::BITOR_ASSIGN;
+ return LangItem::Kind::BITOR_ASSIGN;
case ArithmeticOrLogicalOperator::BITWISE_XOR:
- return RustLangItem::ItemType::BITXOR_ASSIGN;
+ return LangItem::Kind::BITXOR_ASSIGN;
case ArithmeticOrLogicalOperator::LEFT_SHIFT:
- return RustLangItem::ItemType::SHL_ASSIGN;
+ return LangItem::Kind::SHL_ASSIGN;
case ArithmeticOrLogicalOperator::RIGHT_SHIFT:
- return RustLangItem::ItemType::SHR_ASSIGN;
+ return LangItem::Kind::SHR_ASSIGN;
}
rust_unreachable ();
}
-RustLangItem::ItemType
-RustLangItem::NegationOperatorToLangItem (NegationOperator op)
+LangItem::Kind
+LangItem::NegationOperatorToLangItem (NegationOperator op)
{
switch (op)
{
case NegationOperator::NEGATE:
- return RustLangItem::ItemType::NEGATION;
+ return LangItem::Kind::NEGATION;
case NegationOperator::NOT:
- return RustLangItem::ItemType::NOT;
+ return LangItem::Kind::NOT;
}
rust_unreachable ();
}
-} // namespace Analysis
} // namespace Rust
#include "bi-map.h"
namespace Rust {
-namespace Analysis {
// https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
-class RustLangItem
+class LangItem
{
public:
- enum ItemType
+ enum class Kind
{
ADD,
SUBTRACT,
F64_RUNTIME,
};
- static const BiMap<std::string, ItemType> lang_items;
+ static const BiMap<std::string, Kind> lang_items;
- static tl::optional<ItemType> Parse (const std::string &item);
- static std::string ToString (ItemType type);
- static ItemType OperatorToLangItem (ArithmeticOrLogicalOperator op);
- static ItemType
+ static tl::optional<Kind> Parse (const std::string &item);
+ static std::string ToString (Kind type);
+ static Kind OperatorToLangItem (ArithmeticOrLogicalOperator op);
+ static Kind
CompoundAssignmentOperatorToLangItem (ArithmeticOrLogicalOperator op);
- static ItemType NegationOperatorToLangItem (NegationOperator op);
+ static Kind NegationOperatorToLangItem (NegationOperator op);
};
-} // namespace Analysis
} // namespace Rust
+
+// GCC 4.8 needs us to manually implement hashing for enum classes
+namespace std {
+template <> struct hash<Rust::LangItem::Kind>
+{
+ size_t operator() (const Rust::LangItem::Kind &lang_item) const noexcept
+ {
+ return hash<std::underlying_type<Rust::LangItem::Kind>::type> () (
+ static_cast<std::underlying_type<Rust::LangItem::Kind>::type> (
+ lang_item));
+ }
+};
+} // namespace std