-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor hir to avoid raw pointers and unneeded fwd
Refactor the hir tree files to remove raw pointer usage and most forward declarations. Move implementation out of headers and split headers into smaller and more manageable units. gcc/rust/ChangeLog: * Make-lang.in: Add new files. * hir/tree/rust-hir-item.h: Move Item definition and remove implementations to their corresponding cc file. * hir/tree/rust-hir-expr.h: Move implementation to the corresponding cc file. * hir/tree/rust-hir-path.h: Likewise. * hir/tree/rust-hir-pattern.h: Likewise. * hir/tree/rust-hir-stmt.h: Likewise. * hir/tree/rust-hir-type.h: Likewise. * hir/tree/rust-hir-visitor.h: Likewise. * hir/tree/rust-hir.h: Likewise. * hir/tree/rust-hir.cc (Crate::Crate): Add implementations from Crate and remove ConstGenericParam implementations to move them to their own file. * hir/tree/rust-hir-attrs.h: New file. * hir/tree/rust-hir-bound-abstract.h: New file. * hir/tree/rust-hir-bound.h: New file. * hir/tree/rust-hir-expr-abstract.h: New file. * hir/tree/rust-hir-expr.cc: New file. * hir/tree/rust-hir-generic-param.cc: New file. * hir/tree/rust-hir-generic-param.h: New file. * hir/tree/rust-hir-item.cc: New file. * hir/tree/rust-hir-literal.h: New file. * hir/tree/rust-hir-node.h: New file. * hir/tree/rust-hir-path.cc: New file. * hir/tree/rust-hir-pattern-abstract.h: New file. * hir/tree/rust-hir-simple-path.h: New file. * hir/tree/rust-hir-stmt.cc: New file. * hir/tree/rust-hir-trait-bound.h: New file. * hir/tree/rust-hir-type-abstract.cc: New file. * hir/tree/rust-hir-type-abstract.h: New file. * hir/tree/rust-hir-type-no-bounds.h: New file. * hir/tree/rust-hir-type.cc: New file. * hir/tree/rust-hir-visibility.h: New file. * hir/tree/rust-hir-visitable.h: New file. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
- Loading branch information
Showing
31 changed files
with
5,193 additions
and
3,409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
// Copyright (C) 2020-2024 Free Software Foundation, Inc. | ||
|
||
// This file is part of GCC. | ||
|
||
// GCC is free software; you can redistribute it and/or modify it under | ||
// the terms of the GNU General Public License as published by the Free | ||
// Software Foundation; either version 3, or (at your option) any later | ||
// version. | ||
|
||
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY | ||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
// for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with GCC; see the file COPYING3. If not see | ||
// <http://www.gnu.org/licenses/>. | ||
|
||
#ifndef RUST_HIR_ATTRS_H | ||
#define RUST_HIR_ATTRS_H | ||
|
||
#include "rust-ast.h" | ||
|
||
namespace Rust { | ||
namespace HIR { | ||
|
||
class WithOuterAttrs | ||
{ | ||
protected: | ||
AST::AttrVec outer_attrs; | ||
|
||
public: | ||
AST::AttrVec &get_outer_attrs () { return outer_attrs; } | ||
const AST::AttrVec &get_outer_attrs () const { return outer_attrs; } | ||
|
||
WithOuterAttrs (AST::AttrVec outer_attrs) | ||
: outer_attrs (std::move (outer_attrs)){}; | ||
}; | ||
|
||
class WithInnerAttrs | ||
{ | ||
protected: | ||
AST::AttrVec inner_attrs; | ||
|
||
public: | ||
AST::AttrVec get_inner_attrs () const { return inner_attrs; } | ||
|
||
WithInnerAttrs (AST::AttrVec inner_attrs) | ||
: inner_attrs (std::move (inner_attrs)){}; | ||
}; | ||
|
||
} // namespace HIR | ||
} // namespace Rust | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (C) 2020-2024 Free Software Foundation, Inc. | ||
|
||
// This file is part of GCC. | ||
|
||
// GCC is free software; you can redistribute it and/or modify it under | ||
// the terms of the GNU General Public License as published by the Free | ||
// Software Foundation; either version 3, or (at your option) any later | ||
// version. | ||
|
||
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY | ||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
// for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with GCC; see the file COPYING3. If not see | ||
// <http://www.gnu.org/licenses/>. | ||
|
||
#ifndef RUST_HIR_BOUND_ABSTRACT_H | ||
#define RUST_HIR_BOUND_ABSTRACT_H | ||
|
||
#include "rust-hir-visitable.h" | ||
#include "rust-system.h" | ||
#include "rust-hir-map.h" | ||
|
||
namespace Rust { | ||
namespace HIR { | ||
|
||
/* Abstract base class representing a type param bound - Lifetime and TraitBound | ||
* extends it */ | ||
class TypeParamBound : public FullVisitable | ||
{ | ||
public: | ||
using FullVisitable::accept_vis; | ||
enum BoundType | ||
{ | ||
LIFETIME, | ||
TRAITBOUND | ||
}; | ||
|
||
virtual ~TypeParamBound () {} | ||
|
||
// Unique pointer custom clone function | ||
std::unique_ptr<TypeParamBound> clone_type_param_bound () const | ||
{ | ||
return std::unique_ptr<TypeParamBound> (clone_type_param_bound_impl ()); | ||
} | ||
|
||
virtual std::string as_string () const = 0; | ||
|
||
virtual Analysis::NodeMapping get_mappings () const = 0; | ||
|
||
virtual location_t get_locus () const = 0; | ||
|
||
virtual BoundType get_bound_type () const = 0; | ||
|
||
protected: | ||
// Clone function implementation as pure virtual method | ||
virtual TypeParamBound *clone_type_param_bound_impl () const = 0; | ||
}; | ||
|
||
} // namespace HIR | ||
} // namespace Rust | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (C) 2020-2024 Free Software Foundation, Inc. | ||
|
||
// This file is part of GCC. | ||
|
||
// GCC is free software; you can redistribute it and/or modify it under | ||
// the terms of the GNU General Public License as published by the Free | ||
// Software Foundation; either version 3, or (at your option) any later | ||
// version. | ||
|
||
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY | ||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
// for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with GCC; see the file COPYING3. If not see | ||
// <http://www.gnu.org/licenses/>. | ||
|
||
#ifndef RUST_HIR_BOUND_H | ||
#define RUST_HIR_BOUND_H | ||
|
||
#include "rust-hir-bound-abstract.h" | ||
#include "rust-common.h" | ||
#include "rust-hir-path.h" | ||
|
||
namespace Rust { | ||
namespace HIR { | ||
|
||
// Represents a lifetime (and is also a kind of type param bound) | ||
class Lifetime : public TypeParamBound | ||
{ | ||
private: | ||
AST::Lifetime::LifetimeType lifetime_type; | ||
std::string lifetime_name; | ||
location_t locus; | ||
Analysis::NodeMapping mappings; | ||
|
||
public: | ||
// Constructor | ||
Lifetime (Analysis::NodeMapping mapping, AST::Lifetime::LifetimeType type, | ||
std::string name, location_t locus) | ||
: lifetime_type (type), lifetime_name (std::move (name)), locus (locus), | ||
mappings (mapping) | ||
{} | ||
|
||
// Returns true if the lifetime is in an error state. | ||
bool is_error () const | ||
{ | ||
return lifetime_type == AST::Lifetime::LifetimeType::NAMED | ||
&& lifetime_name.empty (); | ||
} | ||
|
||
static Lifetime error () | ||
{ | ||
return Lifetime (Analysis::NodeMapping::get_error (), | ||
AST::Lifetime::LifetimeType::NAMED, "", UNDEF_LOCATION); | ||
} | ||
|
||
std::string as_string () const override; | ||
|
||
void accept_vis (HIRFullVisitor &vis) override; | ||
|
||
WARN_UNUSED_RESULT const std::string &get_name () const | ||
{ | ||
return lifetime_name; | ||
} | ||
|
||
AST::Lifetime::LifetimeType get_lifetime_type () const | ||
{ | ||
return lifetime_type; | ||
} | ||
|
||
location_t get_locus () const override final { return locus; } | ||
|
||
Analysis::NodeMapping get_mappings () const override final | ||
{ | ||
return mappings; | ||
} | ||
|
||
BoundType get_bound_type () const final override { return LIFETIME; } | ||
|
||
protected: | ||
/* Use covariance to implement clone function as returning this object rather | ||
* than base */ | ||
Lifetime *clone_type_param_bound_impl () const override | ||
{ | ||
return new Lifetime (*this); | ||
} | ||
}; | ||
|
||
} // namespace HIR | ||
} // namespace Rust | ||
|
||
#endif |
Oops, something went wrong.