| 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 |
#include "rust-ast-builder-type.h" |
| 20 |
#include "rust-ast-builder.h" |
| 21 |
#include "rust-ast-full.h" |
| 22 |
#include "rust-common.h" |
| 23 |
|
| 24 |
namespace Rust { |
| 25 |
namespace AST { |
| 26 |
|
| 27 |
ASTTypeBuilder::ASTTypeBuilder () : translated (nullptr) {} |
| 28 |
|
| 29 |
Type * |
| 30 |
ASTTypeBuilder::build (Type &type) |
| 31 |
{ |
| 32 |
ASTTypeBuilder builder; |
| 33 |
type.accept_vis (builder); |
| 34 |
rust_assert (builder.translated != nullptr); |
| 35 |
return builder.translated; |
| 36 |
} |
| 37 |
|
| 38 |
void |
| 39 |
ASTTypeBuilder::visit (BareFunctionType &fntype) |
| 40 |
{ |
| 41 |
/* TODO */ |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
ASTTypeBuilder::visit (TupleType &tuple) |
| 46 |
{ |
| 47 |
std::vector<std::unique_ptr<Type> > elems; |
| 48 |
for (auto &elem : tuple.get_elems ()) |
| 49 |
{ |
| 50 |
Type *t = ASTTypeBuilder::build (*elem.get ()); |
| 51 |
std::unique_ptr<Type> ty (t); |
| 52 |
elems.push_back (std::move (ty)); |
| 53 |
} |
| 54 |
translated = new TupleType (std::move (elems), tuple.get_locus ()); |
| 55 |
} |
| 56 |
|
| 57 |
void |
| 58 |
ASTTypeBuilder::visit (TypePath &path) |
| 59 |
{ |
| 60 |
std::vector<std::unique_ptr<TypePathSegment> > segments; |
| 61 |
for (auto &seg : path.get_segments ()) |
| 62 |
{ |
| 63 |
switch (seg->get_type ()) |
| 64 |
{ |
| 65 |
case TypePathSegment::REG: { |
| 66 |
const TypePathSegment &segment |
| 67 |
= (const TypePathSegment &) (*seg.get ()); |
| 68 |
TypePathSegment *s |
| 69 |
= new TypePathSegment (segment.get_ident_segment (), |
| 70 |
segment.get_separating_scope_resolution (), |
| 71 |
segment.get_locus ()); |
| 72 |
std::unique_ptr<TypePathSegment> sg (s); |
| 73 |
segments.push_back (std::move (sg)); |
| 74 |
} |
| 75 |
break; |
| 76 |
|
| 77 |
case TypePathSegment::GENERIC: { |
| 78 |
TypePathSegmentGeneric &generic |
| 79 |
= (TypePathSegmentGeneric &) (*seg.get ()); |
| 80 |
|
| 81 |
GenericArgs args |
| 82 |
= Builder::new_generic_args (generic.get_generic_args ()); |
| 83 |
TypePathSegmentGeneric *s |
| 84 |
= new TypePathSegmentGeneric (generic.get_ident_segment (), false, |
| 85 |
std::move (args), |
| 86 |
generic.get_locus ()); |
| 87 |
std::unique_ptr<TypePathSegment> sg (s); |
| 88 |
segments.push_back (std::move (sg)); |
| 89 |
} |
| 90 |
break; |
| 91 |
|
| 92 |
case TypePathSegment::FUNCTION: { |
| 93 |
rust_unreachable (); |
| 94 |
// TODO |
| 95 |
// const TypePathSegmentFunction &fn |
| 96 |
// = (const TypePathSegmentFunction &) (*seg.get ()); |
| 97 |
} |
| 98 |
break; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
translated = new TypePath (std::move (segments), path.get_locus (), |
| 103 |
path.has_opening_scope_resolution_op ()); |
| 104 |
} |
| 105 |
|
| 106 |
void |
| 107 |
ASTTypeBuilder::visit (QualifiedPathInType &path) |
| 108 |
{ |
| 109 |
/* TODO */ |
| 110 |
} |
| 111 |
|
| 112 |
void |
| 113 |
ASTTypeBuilder::visit (ArrayType &type) |
| 114 |
{ |
| 115 |
/* TODO */ |
| 116 |
} |
| 117 |
|
| 118 |
void |
| 119 |
ASTTypeBuilder::visit (ReferenceType &type) |
| 120 |
{ |
| 121 |
/* TODO */ |
| 122 |
} |
| 123 |
|
| 124 |
void |
| 125 |
ASTTypeBuilder::visit (RawPointerType &type) |
| 126 |
{ |
| 127 |
/* TODO */ |
| 128 |
} |
| 129 |
|
| 130 |
void |
| 131 |
ASTTypeBuilder::visit (SliceType &type) |
| 132 |
{ |
| 133 |
Type *t = ASTTypeBuilder::build (type.get_elem_type ()); |
| 134 |
std::unique_ptr<Type> ty (t); |
| 135 |
translated = new SliceType (std::move (ty), type.get_locus ()); |
| 136 |
} |
| 137 |
|
| 138 |
void |
| 139 |
ASTTypeBuilder::visit (InferredType &type) |
| 140 |
{ |
| 141 |
translated = new InferredType (type.get_locus ()); |
| 142 |
} |
| 143 |
|
| 144 |
void |
| 145 |
ASTTypeBuilder::visit (NeverType &type) |
| 146 |
{ |
| 147 |
translated = new NeverType (type.get_locus ()); |
| 148 |
} |
| 149 |
|
| 150 |
void |
| 151 |
ASTTypeBuilder::visit (TraitObjectTypeOneBound &type) |
| 152 |
{ |
| 153 |
/* TODO */ |
| 154 |
} |
| 155 |
|
| 156 |
void |
| 157 |
ASTTypeBuilder::visit (TraitObjectType &type) |
| 158 |
{ |
| 159 |
/* TODO */ |
| 160 |
} |
| 161 |
|
| 162 |
} // namespace AST |
| 163 |
} // namespace Rust |