| 1 |
// Copyright (C) 2020-2024 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
// This file is part of GCC. |
| 4 |
|
| 5 |
// GCC is free software; you can redistribute it and/or modify it under |
| 6 |
// the terms of the GNU General Public License as published by the Free |
| 7 |
// Software Foundation; either version 3, or (at your option) any later |
| 8 |
// version. |
| 9 |
|
| 10 |
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 |
// for more details. |
| 14 |
|
| 15 |
// You should have received a copy of the GNU General Public License |
| 16 |
// along with GCC; see the file COPYING3. If not see |
| 17 |
// <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
#ifndef RUST_HIR_TRAIT_BOUND_H |
| 20 |
#define RUST_HIR_TRAIT_BOUND_H |
| 21 |
|
| 22 |
#include "rust-hir-bound-abstract.h" |
| 23 |
#include "rust-hir-path.h" |
| 24 |
#include "rust-hir-generic-param.h" |
| 25 |
|
| 26 |
namespace Rust { |
| 27 |
namespace HIR { |
| 28 |
|
| 29 |
// A trait bound |
| 30 |
class TraitBound : public TypeParamBound |
| 31 |
{ |
| 32 |
bool in_parens; |
| 33 |
BoundPolarity polarity; |
| 34 |
std::vector<LifetimeParam> for_lifetimes; |
| 35 |
TypePath type_path; |
| 36 |
location_t locus; |
| 37 |
|
| 38 |
Analysis::NodeMapping mappings; |
| 39 |
|
| 40 |
public: |
| 41 |
// Returns whether trait bound has "for" lifetimes |
| 42 |
bool has_for_lifetimes () const { return !for_lifetimes.empty (); } |
| 43 |
|
| 44 |
TraitBound (Analysis::NodeMapping mapping, TypePath type_path, |
| 45 |
location_t locus, bool in_parens = false, |
| 46 |
BoundPolarity polarity = BoundPolarity::RegularBound, |
| 47 |
std::vector<LifetimeParam> for_lifetimes |
| 48 |
= std::vector<LifetimeParam> ()) |
| 49 |
: in_parens (in_parens), polarity (polarity), |
| 50 |
for_lifetimes (std::move (for_lifetimes)), |
| 51 |
type_path (std::move (type_path)), locus (locus), mappings (mapping) |
| 52 |
{} |
| 53 |
|
| 54 |
std::string as_string () const override; |
| 55 |
|
| 56 |
location_t get_locus () const override final { return locus; } |
| 57 |
|
| 58 |
void accept_vis (HIRFullVisitor &vis) override; |
| 59 |
|
| 60 |
Analysis::NodeMapping get_mappings () const override final |
| 61 |
{ |
| 62 |
return mappings; |
| 63 |
} |
| 64 |
|
| 65 |
std::vector<LifetimeParam> &get_for_lifetimes () { return for_lifetimes; } |
| 66 |
bool get_in_parens () { return in_parens; } |
| 67 |
BoundPolarity get_polarity () { return polarity; } |
| 68 |
|
| 69 |
BoundType get_bound_type () const final override { return TRAITBOUND; } |
| 70 |
|
| 71 |
TypePath &get_path () { return type_path; } |
| 72 |
|
| 73 |
const TypePath &get_path () const { return type_path; } |
| 74 |
|
| 75 |
protected: |
| 76 |
/* Use covariance to implement clone function as returning this object rather |
| 77 |
* than base */ |
| 78 |
TraitBound *clone_type_param_bound_impl () const override |
| 79 |
{ |
| 80 |
return new TraitBound (*this); |
| 81 |
} |
| 82 |
}; |
| 83 |
|
| 84 |
} // namespace HIR |
| 85 |
} // namespace Rust |
| 86 |
|
| 87 |
#endif |