| 1 |
// Copyright (C) 2020-2025 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_AST_LOWER_TYPE |
| 20 |
#define RUST_AST_LOWER_TYPE |
| 21 |
|
| 22 |
#include "rust-ast-lower-base.h" |
| 23 |
#include "rust-ast-lower-expr.h" |
| 24 |
#include "rust-hir-path.h" |
| 25 |
#include "rust-type.h" |
| 26 |
|
| 27 |
namespace Rust { |
| 28 |
namespace HIR { |
| 29 |
|
| 30 |
class ASTLowerTypePath : public ASTLoweringBase |
| 31 |
{ |
| 32 |
protected: |
| 33 |
using Rust::HIR::ASTLoweringBase::visit; |
| 34 |
|
| 35 |
public: |
| 36 |
static HIR::TypePath *translate (AST::TypePath &type); |
| 37 |
|
| 38 |
void visit (AST::TypePathSegmentFunction &segment) override; |
| 39 |
void visit (AST::TypePathSegment &segment) override; |
| 40 |
void visit (AST::TypePathSegmentGeneric &segment) override; |
| 41 |
void visit (AST::TypePath &path) override; |
| 42 |
|
| 43 |
protected: |
| 44 |
HIR::TypePathSegment *translated_segment; |
| 45 |
|
| 46 |
private: |
| 47 |
HIR::TypePath *translated; |
| 48 |
}; |
| 49 |
|
| 50 |
class ASTLowerQualifiedPathInType : public ASTLowerTypePath |
| 51 |
{ |
| 52 |
using ASTLowerTypePath::visit; |
| 53 |
|
| 54 |
public: |
| 55 |
static HIR::QualifiedPathInType *translate (AST::QualifiedPathInType &type); |
| 56 |
|
| 57 |
void visit (AST::QualifiedPathInType &path) override; |
| 58 |
|
| 59 |
private: |
| 60 |
HIR::QualifiedPathInType *translated; |
| 61 |
}; |
| 62 |
|
| 63 |
class ASTLoweringType : public ASTLoweringBase |
| 64 |
{ |
| 65 |
using Rust::HIR::ASTLoweringBase::visit; |
| 66 |
|
| 67 |
public: |
| 68 |
static HIR::Type *translate (AST::Type &type, |
| 69 |
bool default_to_static_lifetime = false); |
| 70 |
|
| 71 |
void visit (AST::BareFunctionType &fntype) override; |
| 72 |
void visit (AST::TupleType &tuple) override; |
| 73 |
void visit (AST::TypePath &path) override; |
| 74 |
void visit (AST::QualifiedPathInType &path) override; |
| 75 |
void visit (AST::ArrayType &type) override; |
| 76 |
void visit (AST::ReferenceType &type) override; |
| 77 |
void visit (AST::RawPointerType &type) override; |
| 78 |
void visit (AST::SliceType &type) override; |
| 79 |
void visit (AST::InferredType &type) override; |
| 80 |
void visit (AST::NeverType &type) override; |
| 81 |
void visit (AST::TraitObjectTypeOneBound &type) override; |
| 82 |
void visit (AST::TraitObjectType &type) override; |
| 83 |
void visit (AST::ParenthesisedType &type) override; |
| 84 |
|
| 85 |
void visit (AST::ImplTraitType &type) override; |
| 86 |
void visit (AST::ImplTraitTypeOneBound &type) override; |
| 87 |
|
| 88 |
private: |
| 89 |
ASTLoweringType (bool default_to_static_lifetime) |
| 90 |
: ASTLoweringBase (), |
| 91 |
default_to_static_lifetime (default_to_static_lifetime), |
| 92 |
translated (nullptr) |
| 93 |
{} |
| 94 |
|
| 95 |
/** Used when compiling const and static items. */ |
| 96 |
bool default_to_static_lifetime; |
| 97 |
|
| 98 |
HIR::Type *translated; |
| 99 |
}; |
| 100 |
|
| 101 |
class ASTLowerGenericParam : public ASTLoweringBase |
| 102 |
{ |
| 103 |
using Rust::HIR::ASTLoweringBase::visit; |
| 104 |
|
| 105 |
public: |
| 106 |
static HIR::GenericParam *translate (AST::GenericParam ¶m); |
| 107 |
|
| 108 |
void visit (AST::LifetimeParam ¶m) override; |
| 109 |
void visit (AST::ConstGenericParam ¶m) override; |
| 110 |
void visit (AST::TypeParam ¶m) override; |
| 111 |
|
| 112 |
private: |
| 113 |
ASTLowerGenericParam () : ASTLoweringBase (), translated (nullptr) {} |
| 114 |
|
| 115 |
HIR::GenericParam *translated; |
| 116 |
}; |
| 117 |
|
| 118 |
class ASTLoweringTypeBounds : public ASTLoweringBase |
| 119 |
{ |
| 120 |
using Rust::HIR::ASTLoweringBase::visit; |
| 121 |
|
| 122 |
public: |
| 123 |
static HIR::TypeParamBound *translate (AST::TypeParamBound &type); |
| 124 |
|
| 125 |
void visit (AST::TraitBound &bound) override; |
| 126 |
void visit (AST::Lifetime &bound) override; |
| 127 |
|
| 128 |
private: |
| 129 |
ASTLoweringTypeBounds () : ASTLoweringBase (), translated (nullptr) {} |
| 130 |
|
| 131 |
HIR::TypeParamBound *translated; |
| 132 |
}; |
| 133 |
|
| 134 |
class ASTLowerWhereClauseItem : public ASTLoweringBase |
| 135 |
{ |
| 136 |
using Rust::HIR::ASTLoweringBase::visit; |
| 137 |
|
| 138 |
public: |
| 139 |
static HIR::WhereClauseItem *translate (AST::WhereClauseItem &item); |
| 140 |
|
| 141 |
void visit (AST::LifetimeWhereClauseItem &item) override; |
| 142 |
void visit (AST::TypeBoundWhereClauseItem &item) override; |
| 143 |
|
| 144 |
private: |
| 145 |
ASTLowerWhereClauseItem () : ASTLoweringBase (), translated (nullptr) {} |
| 146 |
|
| 147 |
HIR::WhereClauseItem *translated; |
| 148 |
}; |
| 149 |
|
| 150 |
} // namespace HIR |
| 151 |
} // namespace Rust |
| 152 |
|
| 153 |
#endif // RUST_AST_LOWER_TYPE |