| 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 |
#include "rust-compile-struct-field-expr.h" |
| 20 |
#include "rust-compile-expr.h" |
| 21 |
|
| 22 |
namespace Rust { |
| 23 |
namespace Compile { |
| 24 |
|
| 25 |
CompileStructExprField::CompileStructExprField (Context *ctx) |
| 26 |
: HIRCompileBase (ctx), translated (error_mark_node) |
| 27 |
{} |
| 28 |
|
| 29 |
tree |
| 30 |
CompileStructExprField::Compile (HIR::StructExprField &field, Context *ctx) |
| 31 |
{ |
| 32 |
CompileStructExprField compiler (ctx); |
| 33 |
switch (field.get_kind ()) |
| 34 |
{ |
| 35 |
case HIR::StructExprField::StructExprFieldKind::IDENTIFIER: |
| 36 |
compiler.visit (static_cast<HIR::StructExprFieldIdentifier &> (field)); |
| 37 |
break; |
| 38 |
|
| 39 |
case HIR::StructExprField::StructExprFieldKind::IDENTIFIER_VALUE: |
| 40 |
compiler.visit ( |
| 41 |
static_cast<HIR::StructExprFieldIdentifierValue &> (field)); |
| 42 |
break; |
| 43 |
|
| 44 |
case HIR::StructExprField::StructExprFieldKind::INDEX_VALUE: |
| 45 |
compiler.visit (static_cast<HIR::StructExprFieldIndexValue &> (field)); |
| 46 |
break; |
| 47 |
} |
| 48 |
return compiler.translated; |
| 49 |
} |
| 50 |
|
| 51 |
void |
| 52 |
CompileStructExprField::visit (HIR::StructExprFieldIdentifierValue &field) |
| 53 |
{ |
| 54 |
translated = CompileExpr::Compile (field.get_value (), ctx); |
| 55 |
} |
| 56 |
|
| 57 |
void |
| 58 |
CompileStructExprField::visit (HIR::StructExprFieldIndexValue &field) |
| 59 |
{ |
| 60 |
translated = CompileExpr::Compile (field.get_value (), ctx); |
| 61 |
} |
| 62 |
|
| 63 |
void |
| 64 |
CompileStructExprField::visit (HIR::StructExprFieldIdentifier &field) |
| 65 |
{ |
| 66 |
// we can make the field look like a path expr to take advantage of existing |
| 67 |
// code |
| 68 |
|
| 69 |
Analysis::NodeMapping mappings_copy1 = field.get_mappings (); |
| 70 |
Analysis::NodeMapping mappings_copy2 = field.get_mappings (); |
| 71 |
|
| 72 |
HIR::PathIdentSegment ident_seg (field.get_field_name ().as_string ()); |
| 73 |
HIR::PathExprSegment seg (mappings_copy1, ident_seg, field.get_locus (), |
| 74 |
HIR::GenericArgs::create_empty ()); |
| 75 |
HIR::PathInExpression expr (mappings_copy2, {seg}, field.get_locus (), false, |
| 76 |
{}); |
| 77 |
translated = CompileExpr::Compile (expr, ctx); |
| 78 |
} |
| 79 |
|
| 80 |
} // namespace Compile |
| 81 |
} // namespace Rust |