diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-04-28 13:46:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-28 13:46:02 +0000 |
commit | 9cf744cbd762442ab33b3f92067829883d7d2d73 (patch) | |
tree | 40fb9a20b8432f0d0267683d04be36250e154ac9 /gcc | |
parent | 1ada076b9324982fd6f49aea6456e99613e394a8 (diff) | |
parent | 1c56e969a647a4c8192ac8cb747f668acf22da7b (diff) | |
download | gcc-9cf744cbd762442ab33b3f92067829883d7d2d73.zip gcc-9cf744cbd762442ab33b3f92067829883d7d2d73.tar.gz gcc-9cf744cbd762442ab33b3f92067829883d7d2d73.tar.bz2 |
Merge #1172
1172: Resolve visibility paths r=CohenArthur a=CohenArthur
This tackles the remaining issues in #1158. ~~It also contains the commit from #1168 so you should wait for bors to merge that before reviewing it :D~~ done
The paths get resolved but their `NodeId`s are not used in the privacy visibility resolver yet.
Closes #1158
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/Make-lang.in | 1 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 6 | ||||
-rw-r--r-- | gcc/rust/ast/rust-item.h | 1 | ||||
-rw-r--r-- | gcc/rust/privacy/rust-visibility-resolver.cc | 11 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-base.cc | 654 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-base.h | 335 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 41 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-path.cc | 72 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-path.h | 17 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/pub_restricted_1.rs | 14 |
10 files changed, 987 insertions, 165 deletions
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index f59deb8..ae385e0 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -87,6 +87,7 @@ GRS_OBJS = \ rust/rust-ast-lower-pattern.o \ rust/rust-name-resolver.o \ rust/rust-ast-resolve.o \ + rust/rust-ast-resolve-base.o \ rust/rust-ast-resolve-item.o \ rust/rust-ast-resolve-pattern.o \ rust/rust-ast-resolve-expr.o \ diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index f2b14ab..fb8982a 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -349,6 +349,7 @@ public: Location get_locus () const { return locus; } NodeId get_node_id () const { return node_id; } + const std::string &get_segment_name () const { return segment_name; } // TODO: visitor pattern? }; @@ -404,6 +405,11 @@ public: = {AST::SimplePathSegment (std::move (str), locus)}; return SimplePath (std::move (single_segments)); } + + const std::vector<SimplePathSegment> &get_segments () const + { + return segments; + } }; // path-to-string inverse comparison operator diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 5d1e0d6..9dc61a8 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -701,6 +701,7 @@ public: std::string as_string () const; const SimplePath &get_path () const { return in_path; } + SimplePath &get_path () { return in_path; } protected: // Clone function implementation - not currently virtual but may be if diff --git a/gcc/rust/privacy/rust-visibility-resolver.cc b/gcc/rust/privacy/rust-visibility-resolver.cc index 8f5aeba..3ab6085 100644 --- a/gcc/rust/privacy/rust-visibility-resolver.cc +++ b/gcc/rust/privacy/rust-visibility-resolver.cc @@ -45,6 +45,17 @@ VisibilityResolver::go (HIR::Crate &crate) } } +// FIXME: At this point in the pipeline, we should not be dealing with +// `AST::SimplePath`s anymore! We need to be dealing with their "resolved +// counterpart", so probably a NodeId/HirId/DefId. + +// static bool +// resolve_module_path (std::vector<HIR::Module> &module_stack, +// const AST::SimplePath &restriction, DefId &id) +// { +// return false; +// } + bool VisibilityResolver::resolve_visibility (const HIR::Visibility &visibility, ModuleVisibility &to_resolve) diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc new file mode 100644 index 0000000..2a86618 --- /dev/null +++ b/gcc/rust/resolve/rust-ast-resolve-base.cc @@ -0,0 +1,654 @@ +// Copyright (C) 2020-2022 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/>. + +#include "rust-ast-resolve-base.h" +#include "rust-ast-resolve-expr.h" +#include "rust-ast-resolve-path.h" +#include "rust-item.h" + +namespace Rust { +namespace Resolver { + +bool +ResolverBase::resolve_visibility (const AST::Visibility &vis) +{ + if (vis.has_path ()) + { + auto path = vis.get_path (); + ResolvePath::go (&path, parent); + + // Do we need to lookup something here? + // Is it just about resolving the names correctly so we can look them up + // later? + } + + return true; +} + +// Default visitors implementations + +void +ResolverBase::visit (AST::Token &) +{} + +void +ResolverBase::visit (AST::DelimTokenTree &) +{} + +void +ResolverBase::visit (AST::AttrInputMetaItemContainer &) +{} + +void +ResolverBase::visit (AST::IdentifierExpr &) +{} + +void +ResolverBase::visit (AST::Lifetime &) +{} + +void +ResolverBase::visit (AST::LifetimeParam &) +{} + +void +ResolverBase::visit (AST::PathInExpression &) +{} + +void +ResolverBase::visit (AST::TypePathSegment &) +{} + +void +ResolverBase::visit (AST::TypePathSegmentGeneric &) +{} + +void +ResolverBase::visit (AST::TypePathSegmentFunction &) +{} + +void +ResolverBase::visit (AST::TypePath &) +{} + +void +ResolverBase::visit (AST::QualifiedPathInExpression &) +{} + +void +ResolverBase::visit (AST::QualifiedPathInType &) +{} + +void +ResolverBase::visit (AST::LiteralExpr &) +{} + +void +ResolverBase::visit (AST::AttrInputLiteral &) +{} + +void +ResolverBase::visit (AST::MetaItemLitExpr &) +{} + +void +ResolverBase::visit (AST::MetaItemPathLit &) +{} + +void +ResolverBase::visit (AST::BorrowExpr &) +{} + +void +ResolverBase::visit (AST::DereferenceExpr &) +{} + +void +ResolverBase::visit (AST::ErrorPropagationExpr &) +{} + +void +ResolverBase::visit (AST::NegationExpr &) +{} + +void +ResolverBase::visit (AST::ArithmeticOrLogicalExpr &) +{} + +void +ResolverBase::visit (AST::ComparisonExpr &) +{} + +void +ResolverBase::visit (AST::LazyBooleanExpr &) +{} + +void +ResolverBase::visit (AST::TypeCastExpr &) +{} + +void +ResolverBase::visit (AST::AssignmentExpr &) +{} + +void +ResolverBase::visit (AST::CompoundAssignmentExpr &) +{} + +void +ResolverBase::visit (AST::GroupedExpr &) +{} + +void +ResolverBase::visit (AST::ArrayElemsValues &) +{} + +void +ResolverBase::visit (AST::ArrayElemsCopied &) +{} + +void +ResolverBase::visit (AST::ArrayExpr &) +{} + +void +ResolverBase::visit (AST::ArrayIndexExpr &) +{} + +void +ResolverBase::visit (AST::TupleExpr &) +{} + +void +ResolverBase::visit (AST::TupleIndexExpr &) +{} + +void +ResolverBase::visit (AST::StructExprStruct &) +{} + +void +ResolverBase::visit (AST::StructExprFieldIdentifier &) +{} + +void +ResolverBase::visit (AST::StructExprFieldIdentifierValue &) +{} + +void +ResolverBase::visit (AST::StructExprFieldIndexValue &) +{} + +void +ResolverBase::visit (AST::StructExprStructFields &) +{} + +void +ResolverBase::visit (AST::StructExprStructBase &) +{} + +void +ResolverBase::visit (AST::CallExpr &) +{} + +void +ResolverBase::visit (AST::MethodCallExpr &) +{} + +void +ResolverBase::visit (AST::FieldAccessExpr &) +{} + +void +ResolverBase::visit (AST::ClosureExprInner &) +{} + +void +ResolverBase::visit (AST::BlockExpr &) +{} + +void +ResolverBase::visit (AST::ClosureExprInnerTyped &) +{} + +void +ResolverBase::visit (AST::ContinueExpr &) +{} + +void +ResolverBase::visit (AST::BreakExpr &) +{} + +void +ResolverBase::visit (AST::RangeFromToExpr &) +{} + +void +ResolverBase::visit (AST::RangeFromExpr &) +{} + +void +ResolverBase::visit (AST::RangeToExpr &) +{} + +void +ResolverBase::visit (AST::RangeFullExpr &) +{} + +void +ResolverBase::visit (AST::RangeFromToInclExpr &) +{} + +void +ResolverBase::visit (AST::RangeToInclExpr &) +{} + +void +ResolverBase::visit (AST::ReturnExpr &) +{} + +void +ResolverBase::visit (AST::UnsafeBlockExpr &) +{} + +void +ResolverBase::visit (AST::LoopExpr &) +{} + +void +ResolverBase::visit (AST::WhileLoopExpr &) +{} + +void +ResolverBase::visit (AST::WhileLetLoopExpr &) +{} + +void +ResolverBase::visit (AST::ForLoopExpr &) +{} + +void +ResolverBase::visit (AST::IfExpr &) +{} + +void +ResolverBase::visit (AST::IfExprConseqElse &) +{} + +void +ResolverBase::visit (AST::IfExprConseqIf &) +{} + +void +ResolverBase::visit (AST::IfExprConseqIfLet &) +{} + +void +ResolverBase::visit (AST::IfLetExpr &) +{} + +void +ResolverBase::visit (AST::IfLetExprConseqElse &) +{} + +void +ResolverBase::visit (AST::IfLetExprConseqIf &) +{} + +void +ResolverBase::visit (AST::IfLetExprConseqIfLet &) +{} + +void +ResolverBase::visit (AST::MatchExpr &) +{} + +void +ResolverBase::visit (AST::AwaitExpr &) +{} + +void +ResolverBase::visit (AST::AsyncBlockExpr &) +{} + +void +ResolverBase::visit (AST::TypeParam &) +{} + +void +ResolverBase::visit (AST::LifetimeWhereClauseItem &) +{} + +void +ResolverBase::visit (AST::TypeBoundWhereClauseItem &) +{} + +void +ResolverBase::visit (AST::Method &) +{} + +void +ResolverBase::visit (AST::Module &) +{} + +void +ResolverBase::visit (AST::ExternCrate &) +{} + +void +ResolverBase::visit (AST::UseTreeGlob &) +{} + +void +ResolverBase::visit (AST::UseTreeList &) +{} + +void +ResolverBase::visit (AST::UseTreeRebind &) +{} + +void +ResolverBase::visit (AST::UseDeclaration &) +{} + +void +ResolverBase::visit (AST::Function &) +{} + +void +ResolverBase::visit (AST::TypeAlias &) +{} + +void +ResolverBase::visit (AST::StructStruct &) +{} + +void +ResolverBase::visit (AST::TupleStruct &) +{} + +void +ResolverBase::visit (AST::EnumItem &) +{} + +void +ResolverBase::visit (AST::EnumItemTuple &) +{} + +void +ResolverBase::visit (AST::EnumItemStruct &) +{} + +void +ResolverBase::visit (AST::EnumItemDiscriminant &) +{} + +void +ResolverBase::visit (AST::Enum &) +{} + +void +ResolverBase::visit (AST::Union &) +{} + +void +ResolverBase::visit (AST::ConstantItem &) +{} + +void +ResolverBase::visit (AST::StaticItem &) +{} + +void +ResolverBase::visit (AST::TraitItemFunc &) +{} + +void +ResolverBase::visit (AST::TraitItemMethod &) +{} + +void +ResolverBase::visit (AST::TraitItemConst &) +{} + +void +ResolverBase::visit (AST::TraitItemType &) +{} + +void +ResolverBase::visit (AST::Trait &) +{} + +void +ResolverBase::visit (AST::InherentImpl &) +{} + +void +ResolverBase::visit (AST::TraitImpl &) +{} + +void +ResolverBase::visit (AST::ExternalStaticItem &) +{} + +void +ResolverBase::visit (AST::ExternalFunctionItem &) +{} + +void +ResolverBase::visit (AST::ExternBlock &) +{} + +void +ResolverBase::visit (AST::MacroMatchFragment &) +{} + +void +ResolverBase::visit (AST::MacroMatchRepetition &) +{} + +void +ResolverBase::visit (AST::MacroMatcher &) +{} + +void +ResolverBase::visit (AST::MacroRulesDefinition &) +{} + +void +ResolverBase::visit (AST::MacroInvocation &) +{} + +void +ResolverBase::visit (AST::MetaItemPath &) +{} + +void +ResolverBase::visit (AST::MetaItemSeq &) +{} + +void +ResolverBase::visit (AST::MetaWord &) +{} + +void +ResolverBase::visit (AST::MetaNameValueStr &) +{} + +void +ResolverBase::visit (AST::MetaListPaths &) +{} + +void +ResolverBase::visit (AST::MetaListNameValueStr &) +{} + +void +ResolverBase::visit (AST::LiteralPattern &) +{} + +void +ResolverBase::visit (AST::IdentifierPattern &) +{} + +void +ResolverBase::visit (AST::WildcardPattern &) +{} + +void +ResolverBase::visit (AST::RangePatternBoundLiteral &) +{} + +void +ResolverBase::visit (AST::RangePatternBoundPath &) +{} + +void +ResolverBase::visit (AST::RangePatternBoundQualPath &) +{} + +void +ResolverBase::visit (AST::RangePattern &) +{} + +void +ResolverBase::visit (AST::ReferencePattern &) +{} + +void +ResolverBase::visit (AST::StructPatternFieldTuplePat &) +{} + +void +ResolverBase::visit (AST::StructPatternFieldIdentPat &) +{} + +void +ResolverBase::visit (AST::StructPatternFieldIdent &) +{} + +void +ResolverBase::visit (AST::StructPattern &) +{} + +void +ResolverBase::visit (AST::TupleStructItemsNoRange &) +{} + +void +ResolverBase::visit (AST::TupleStructItemsRange &) +{} + +void +ResolverBase::visit (AST::TupleStructPattern &) +{} + +void +ResolverBase::visit (AST::TuplePatternItemsMultiple &) +{} + +void +ResolverBase::visit (AST::TuplePatternItemsRanged &) +{} + +void +ResolverBase::visit (AST::TuplePattern &) +{} + +void +ResolverBase::visit (AST::GroupedPattern &) +{} + +void +ResolverBase::visit (AST::SlicePattern &) +{} + +void +ResolverBase::visit (AST::EmptyStmt &) +{} + +void +ResolverBase::visit (AST::LetStmt &) +{} + +void +ResolverBase::visit (AST::ExprStmtWithoutBlock &) +{} + +void +ResolverBase::visit (AST::ExprStmtWithBlock &) +{} + +void +ResolverBase::visit (AST::TraitBound &) +{} + +void +ResolverBase::visit (AST::ImplTraitType &) +{} + +void +ResolverBase::visit (AST::TraitObjectType &) +{} + +void +ResolverBase::visit (AST::ParenthesisedType &) +{} + +void +ResolverBase::visit (AST::ImplTraitTypeOneBound &) +{} + +void +ResolverBase::visit (AST::TraitObjectTypeOneBound &) +{} + +void +ResolverBase::visit (AST::TupleType &) +{} + +void +ResolverBase::visit (AST::NeverType &) +{} + +void +ResolverBase::visit (AST::RawPointerType &) +{} + +void +ResolverBase::visit (AST::ReferenceType &) +{} + +void +ResolverBase::visit (AST::ArrayType &) +{} + +void +ResolverBase::visit (AST::SliceType &) +{} + +void +ResolverBase::visit (AST::InferredType &) +{} + +void +ResolverBase::visit (AST::BareFunctionType &) +{} + +} // namespace Resolver +} // namespace Rust diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h index eca9694..17d05c3 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.h +++ b/gcc/rust/resolve/rust-ast-resolve-base.h @@ -32,171 +32,171 @@ class ResolverBase : public AST::ASTVisitor public: virtual ~ResolverBase () {} - void visit (AST::Token &) {} - void visit (AST::DelimTokenTree &) {} - void visit (AST::AttrInputMetaItemContainer &) {} - void visit (AST::IdentifierExpr &) {} - void visit (AST::Lifetime &) {} - void visit (AST::LifetimeParam &) {} - void visit (AST::PathInExpression &) {} - void visit (AST::TypePathSegment &) {} - void visit (AST::TypePathSegmentGeneric &) {} - void visit (AST::TypePathSegmentFunction &) {} - void visit (AST::TypePath &) {} - void visit (AST::QualifiedPathInExpression &) {} - void visit (AST::QualifiedPathInType &) {} - void visit (AST::LiteralExpr &) {} - void visit (AST::AttrInputLiteral &) {} - void visit (AST::MetaItemLitExpr &) {} - void visit (AST::MetaItemPathLit &) {} - void visit (AST::BorrowExpr &) {} - void visit (AST::DereferenceExpr &) {} - void visit (AST::ErrorPropagationExpr &) {} - void visit (AST::NegationExpr &) {} - void visit (AST::ArithmeticOrLogicalExpr &) {} - void visit (AST::ComparisonExpr &) {} - void visit (AST::LazyBooleanExpr &) {} - void visit (AST::TypeCastExpr &) {} - void visit (AST::AssignmentExpr &) {} - void visit (AST::CompoundAssignmentExpr &) {} - void visit (AST::GroupedExpr &) {} - void visit (AST::ArrayElemsValues &) {} - void visit (AST::ArrayElemsCopied &) {} - void visit (AST::ArrayExpr &) {} - void visit (AST::ArrayIndexExpr &) {} - void visit (AST::TupleExpr &) {} - void visit (AST::TupleIndexExpr &) {} - void visit (AST::StructExprStruct &) {} - void visit (AST::StructExprFieldIdentifier &) {} - void visit (AST::StructExprFieldIdentifierValue &) {} - void visit (AST::StructExprFieldIndexValue &) {} - void visit (AST::StructExprStructFields &) {} - void visit (AST::StructExprStructBase &) {} - void visit (AST::CallExpr &) {} - void visit (AST::MethodCallExpr &) {} - void visit (AST::FieldAccessExpr &) {} - void visit (AST::ClosureExprInner &) {} - void visit (AST::BlockExpr &) {} - void visit (AST::ClosureExprInnerTyped &) {} - void visit (AST::ContinueExpr &) {} - void visit (AST::BreakExpr &) {} - void visit (AST::RangeFromToExpr &) {} - void visit (AST::RangeFromExpr &) {} - void visit (AST::RangeToExpr &) {} - void visit (AST::RangeFullExpr &) {} - void visit (AST::RangeFromToInclExpr &) {} - void visit (AST::RangeToInclExpr &) {} - void visit (AST::ReturnExpr &) {} - void visit (AST::UnsafeBlockExpr &) {} - void visit (AST::LoopExpr &) {} - void visit (AST::WhileLoopExpr &) {} - void visit (AST::WhileLetLoopExpr &) {} - void visit (AST::ForLoopExpr &) {} - void visit (AST::IfExpr &) {} - void visit (AST::IfExprConseqElse &) {} - void visit (AST::IfExprConseqIf &) {} - void visit (AST::IfExprConseqIfLet &) {} - void visit (AST::IfLetExpr &) {} - void visit (AST::IfLetExprConseqElse &) {} - void visit (AST::IfLetExprConseqIf &) {} - void visit (AST::IfLetExprConseqIfLet &) {} - - void visit (AST::MatchExpr &) {} - void visit (AST::AwaitExpr &) {} - void visit (AST::AsyncBlockExpr &) {} - - void visit (AST::TypeParam &) {} - - void visit (AST::LifetimeWhereClauseItem &) {} - void visit (AST::TypeBoundWhereClauseItem &) {} - void visit (AST::Method &) {} - void visit (AST::Module &) {} - void visit (AST::ExternCrate &) {} - - void visit (AST::UseTreeGlob &) {} - void visit (AST::UseTreeList &) {} - void visit (AST::UseTreeRebind &) {} - void visit (AST::UseDeclaration &) {} - void visit (AST::Function &) {} - void visit (AST::TypeAlias &) {} - void visit (AST::StructStruct &) {} - void visit (AST::TupleStruct &) {} - void visit (AST::EnumItem &) {} - void visit (AST::EnumItemTuple &) {} - void visit (AST::EnumItemStruct &) {} - void visit (AST::EnumItemDiscriminant &) {} - void visit (AST::Enum &) {} - void visit (AST::Union &) {} - void visit (AST::ConstantItem &) {} - void visit (AST::StaticItem &) {} - void visit (AST::TraitItemFunc &) {} - void visit (AST::TraitItemMethod &) {} - void visit (AST::TraitItemConst &) {} - void visit (AST::TraitItemType &) {} - void visit (AST::Trait &) {} - void visit (AST::InherentImpl &) {} - void visit (AST::TraitImpl &) {} - - void visit (AST::ExternalStaticItem &) {} - void visit (AST::ExternalFunctionItem &) {} - void visit (AST::ExternBlock &) {} - - void visit (AST::MacroMatchFragment &) {} - void visit (AST::MacroMatchRepetition &) {} - void visit (AST::MacroMatcher &) {} - void visit (AST::MacroRulesDefinition &) {} - void visit (AST::MacroInvocation &) {} - void visit (AST::MetaItemPath &) {} - void visit (AST::MetaItemSeq &) {} - void visit (AST::MetaWord &) {} - void visit (AST::MetaNameValueStr &) {} - void visit (AST::MetaListPaths &) {} - void visit (AST::MetaListNameValueStr &) {} - - void visit (AST::LiteralPattern &) {} - void visit (AST::IdentifierPattern &) {} - void visit (AST::WildcardPattern &) {} - - void visit (AST::RangePatternBoundLiteral &) {} - void visit (AST::RangePatternBoundPath &) {} - void visit (AST::RangePatternBoundQualPath &) {} - void visit (AST::RangePattern &) {} - void visit (AST::ReferencePattern &) {} - - void visit (AST::StructPatternFieldTuplePat &) {} - void visit (AST::StructPatternFieldIdentPat &) {} - void visit (AST::StructPatternFieldIdent &) {} - void visit (AST::StructPattern &) {} - - void visit (AST::TupleStructItemsNoRange &) {} - void visit (AST::TupleStructItemsRange &) {} - void visit (AST::TupleStructPattern &) {} - - void visit (AST::TuplePatternItemsMultiple &) {} - void visit (AST::TuplePatternItemsRanged &) {} - void visit (AST::TuplePattern &) {} - void visit (AST::GroupedPattern &) {} - void visit (AST::SlicePattern &) {} - - void visit (AST::EmptyStmt &) {} - void visit (AST::LetStmt &) {} - void visit (AST::ExprStmtWithoutBlock &) {} - void visit (AST::ExprStmtWithBlock &) {} - - void visit (AST::TraitBound &) {} - void visit (AST::ImplTraitType &) {} - void visit (AST::TraitObjectType &) {} - void visit (AST::ParenthesisedType &) {} - void visit (AST::ImplTraitTypeOneBound &) {} - void visit (AST::TraitObjectTypeOneBound &) {} - void visit (AST::TupleType &) {} - void visit (AST::NeverType &) {} - void visit (AST::RawPointerType &) {} - void visit (AST::ReferenceType &) {} - void visit (AST::ArrayType &) {} - void visit (AST::SliceType &) {} - void visit (AST::InferredType &) {} - void visit (AST::BareFunctionType &) {} + void visit (AST::Token &); + void visit (AST::DelimTokenTree &); + void visit (AST::AttrInputMetaItemContainer &); + void visit (AST::IdentifierExpr &); + void visit (AST::Lifetime &); + void visit (AST::LifetimeParam &); + void visit (AST::PathInExpression &); + void visit (AST::TypePathSegment &); + void visit (AST::TypePathSegmentGeneric &); + void visit (AST::TypePathSegmentFunction &); + void visit (AST::TypePath &); + void visit (AST::QualifiedPathInExpression &); + void visit (AST::QualifiedPathInType &); + void visit (AST::LiteralExpr &); + void visit (AST::AttrInputLiteral &); + void visit (AST::MetaItemLitExpr &); + void visit (AST::MetaItemPathLit &); + void visit (AST::BorrowExpr &); + void visit (AST::DereferenceExpr &); + void visit (AST::ErrorPropagationExpr &); + void visit (AST::NegationExpr &); + void visit (AST::ArithmeticOrLogicalExpr &); + void visit (AST::ComparisonExpr &); + void visit (AST::LazyBooleanExpr &); + void visit (AST::TypeCastExpr &); + void visit (AST::AssignmentExpr &); + void visit (AST::CompoundAssignmentExpr &); + void visit (AST::GroupedExpr &); + void visit (AST::ArrayElemsValues &); + void visit (AST::ArrayElemsCopied &); + void visit (AST::ArrayExpr &); + void visit (AST::ArrayIndexExpr &); + void visit (AST::TupleExpr &); + void visit (AST::TupleIndexExpr &); + void visit (AST::StructExprStruct &); + void visit (AST::StructExprFieldIdentifier &); + void visit (AST::StructExprFieldIdentifierValue &); + void visit (AST::StructExprFieldIndexValue &); + void visit (AST::StructExprStructFields &); + void visit (AST::StructExprStructBase &); + void visit (AST::CallExpr &); + void visit (AST::MethodCallExpr &); + void visit (AST::FieldAccessExpr &); + void visit (AST::ClosureExprInner &); + void visit (AST::BlockExpr &); + void visit (AST::ClosureExprInnerTyped &); + void visit (AST::ContinueExpr &); + void visit (AST::BreakExpr &); + void visit (AST::RangeFromToExpr &); + void visit (AST::RangeFromExpr &); + void visit (AST::RangeToExpr &); + void visit (AST::RangeFullExpr &); + void visit (AST::RangeFromToInclExpr &); + void visit (AST::RangeToInclExpr &); + void visit (AST::ReturnExpr &); + void visit (AST::UnsafeBlockExpr &); + void visit (AST::LoopExpr &); + void visit (AST::WhileLoopExpr &); + void visit (AST::WhileLetLoopExpr &); + void visit (AST::ForLoopExpr &); + void visit (AST::IfExpr &); + void visit (AST::IfExprConseqElse &); + void visit (AST::IfExprConseqIf &); + void visit (AST::IfExprConseqIfLet &); + void visit (AST::IfLetExpr &); + void visit (AST::IfLetExprConseqElse &); + void visit (AST::IfLetExprConseqIf &); + void visit (AST::IfLetExprConseqIfLet &); + + void visit (AST::MatchExpr &); + void visit (AST::AwaitExpr &); + void visit (AST::AsyncBlockExpr &); + + void visit (AST::TypeParam &); + + void visit (AST::LifetimeWhereClauseItem &); + void visit (AST::TypeBoundWhereClauseItem &); + void visit (AST::Method &); + void visit (AST::Module &); + void visit (AST::ExternCrate &); + + void visit (AST::UseTreeGlob &); + void visit (AST::UseTreeList &); + void visit (AST::UseTreeRebind &); + void visit (AST::UseDeclaration &); + void visit (AST::Function &); + void visit (AST::TypeAlias &); + void visit (AST::StructStruct &); + void visit (AST::TupleStruct &); + void visit (AST::EnumItem &); + void visit (AST::EnumItemTuple &); + void visit (AST::EnumItemStruct &); + void visit (AST::EnumItemDiscriminant &); + void visit (AST::Enum &); + void visit (AST::Union &); + void visit (AST::ConstantItem &); + void visit (AST::StaticItem &); + void visit (AST::TraitItemFunc &); + void visit (AST::TraitItemMethod &); + void visit (AST::TraitItemConst &); + void visit (AST::TraitItemType &); + void visit (AST::Trait &); + void visit (AST::InherentImpl &); + void visit (AST::TraitImpl &); + + void visit (AST::ExternalStaticItem &); + void visit (AST::ExternalFunctionItem &); + void visit (AST::ExternBlock &); + + void visit (AST::MacroMatchFragment &); + void visit (AST::MacroMatchRepetition &); + void visit (AST::MacroMatcher &); + void visit (AST::MacroRulesDefinition &); + void visit (AST::MacroInvocation &); + void visit (AST::MetaItemPath &); + void visit (AST::MetaItemSeq &); + void visit (AST::MetaWord &); + void visit (AST::MetaNameValueStr &); + void visit (AST::MetaListPaths &); + void visit (AST::MetaListNameValueStr &); + + void visit (AST::LiteralPattern &); + void visit (AST::IdentifierPattern &); + void visit (AST::WildcardPattern &); + + void visit (AST::RangePatternBoundLiteral &); + void visit (AST::RangePatternBoundPath &); + void visit (AST::RangePatternBoundQualPath &); + void visit (AST::RangePattern &); + void visit (AST::ReferencePattern &); + + void visit (AST::StructPatternFieldTuplePat &); + void visit (AST::StructPatternFieldIdentPat &); + void visit (AST::StructPatternFieldIdent &); + void visit (AST::StructPattern &); + + void visit (AST::TupleStructItemsNoRange &); + void visit (AST::TupleStructItemsRange &); + void visit (AST::TupleStructPattern &); + + void visit (AST::TuplePatternItemsMultiple &); + void visit (AST::TuplePatternItemsRanged &); + void visit (AST::TuplePattern &); + void visit (AST::GroupedPattern &); + void visit (AST::SlicePattern &); + + void visit (AST::EmptyStmt &); + void visit (AST::LetStmt &); + void visit (AST::ExprStmtWithoutBlock &); + void visit (AST::ExprStmtWithBlock &); + + void visit (AST::TraitBound &); + void visit (AST::ImplTraitType &); + void visit (AST::TraitObjectType &); + void visit (AST::ParenthesisedType &); + void visit (AST::ImplTraitTypeOneBound &); + void visit (AST::TraitObjectTypeOneBound &); + void visit (AST::TupleType &); + void visit (AST::NeverType &); + void visit (AST::RawPointerType &); + void visit (AST::ReferenceType &); + void visit (AST::ArrayType &); + void visit (AST::SliceType &); + void visit (AST::InferredType &); + void visit (AST::BareFunctionType &); protected: ResolverBase (NodeId parent) @@ -206,6 +206,11 @@ protected: bool resolved () const { return resolved_node != UNKNOWN_NODEID; } + /** + * Resolve a visibility's path through the name resolver + */ + bool resolve_visibility (const AST::Visibility &vis); + Resolver *resolver; Analysis::Mappings *mappings; NodeId resolved_node; diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 9546698..2c383c9 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -238,6 +238,8 @@ ResolveItem::visit (AST::Module &module) mappings->insert_canonical_path (mappings->get_current_crate (), module.get_node_id (), cpath); + resolve_visibility (module.get_visibility ()); + NodeId scope_node_id = module.get_node_id (); resolver->get_name_scope ().push (scope_node_id); resolver->get_type_scope ().push (scope_node_id); @@ -267,6 +269,8 @@ ResolveItem::visit (AST::TupleStruct &struct_decl) mappings->insert_canonical_path (mappings->get_current_crate (), struct_decl.get_node_id (), cpath); + resolve_visibility (struct_decl.get_visibility ()); + NodeId scope_node_id = struct_decl.get_node_id (); resolver->get_type_scope ().push (scope_node_id); @@ -286,6 +290,8 @@ ResolveItem::visit (AST::TupleStruct &struct_decl) if (field.get_field_type ()->is_marked_for_strip ()) continue; + resolve_visibility (field.get_visibility ()); + ResolveType::go (field.get_field_type ().get (), struct_decl.get_node_id ()); } @@ -303,6 +309,8 @@ ResolveItem::visit (AST::Enum &enum_decl) mappings->insert_canonical_path (mappings->get_current_crate (), enum_decl.get_node_id (), cpath); + resolve_visibility (enum_decl.get_visibility ()); + NodeId scope_node_id = enum_decl.get_node_id (); resolver->get_type_scope ().push (scope_node_id); @@ -328,6 +336,9 @@ ResolveItem::visit (AST::Enum &enum_decl) void ResolveItem::visit (AST::EnumItem &item) { + // Since at this point we cannot have visibilities on enum items anymore, we + // can skip handling them + auto decl = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()); auto path = prefix.append (decl); @@ -396,6 +407,8 @@ ResolveItem::visit (AST::StructStruct &struct_decl) mappings->insert_canonical_path (mappings->get_current_crate (), struct_decl.get_node_id (), cpath); + resolve_visibility (struct_decl.get_visibility ()); + NodeId scope_node_id = struct_decl.get_node_id (); resolver->get_type_scope ().push (scope_node_id); @@ -415,6 +428,8 @@ ResolveItem::visit (AST::StructStruct &struct_decl) if (field.get_field_type ()->is_marked_for_strip ()) continue; + resolve_visibility (field.get_visibility ()); + ResolveType::go (field.get_field_type ().get (), struct_decl.get_node_id ()); } @@ -432,6 +447,8 @@ ResolveItem::visit (AST::Union &union_decl) mappings->insert_canonical_path (mappings->get_current_crate (), union_decl.get_node_id (), cpath); + resolve_visibility (union_decl.get_visibility ()); + NodeId scope_node_id = union_decl.get_node_id (); resolver->get_type_scope ().push (scope_node_id); @@ -485,6 +502,8 @@ ResolveItem::visit (AST::ConstantItem &constant) mappings->insert_canonical_path (mappings->get_current_crate (), constant.get_node_id (), cpath); + resolve_visibility (constant.get_visibility ()); + ResolveType::go (constant.get_type ().get (), constant.get_node_id ()); ResolveExpr::go (constant.get_expr ().get (), constant.get_node_id (), path, cpath); @@ -505,6 +524,8 @@ ResolveItem::visit (AST::Function &function) mappings->insert_canonical_path (mappings->get_current_crate (), function.get_node_id (), cpath); + resolve_visibility (function.get_visibility ()); + NodeId scope_node_id = function.get_node_id (); resolver->get_name_scope ().push (scope_node_id); resolver->get_type_scope ().push (scope_node_id); @@ -559,6 +580,8 @@ ResolveItem::visit (AST::InherentImpl &impl_block) resolver->push_new_name_rib (resolver->get_name_scope ().peek ()); resolver->push_new_type_rib (resolver->get_type_scope ().peek ()); + resolve_visibility (impl_block.get_visibility ()); + if (impl_block.has_generics ()) { for (auto &generic : impl_block.get_generic_params ()) @@ -640,6 +663,9 @@ ResolveItem::visit (AST::Method &method) method.get_node_id (), cpath); NodeId scope_node_id = method.get_node_id (); + + resolve_visibility (method.get_visibility ()); + resolver->get_name_scope ().push (scope_node_id); resolver->get_type_scope ().push (scope_node_id); resolver->get_label_scope ().push (scope_node_id); @@ -711,6 +737,9 @@ void ResolveItem::visit (AST::TraitImpl &impl_block) { NodeId scope_node_id = impl_block.get_node_id (); + + resolve_visibility (impl_block.get_visibility ()); + resolver->get_name_scope ().push (scope_node_id); resolver->get_type_scope ().push (scope_node_id); resolver->push_new_name_rib (resolver->get_name_scope ().peek ()); @@ -812,6 +841,9 @@ void ResolveItem::visit (AST::Trait &trait) { NodeId scope_node_id = trait.get_node_id (); + + resolve_visibility (trait.get_visibility ()); + resolver->get_name_scope ().push (scope_node_id); resolver->get_type_scope ().push (scope_node_id); resolver->push_new_name_rib (resolver->get_name_scope ().peek ()); @@ -862,6 +894,8 @@ ResolveItem::visit (AST::Trait &trait) void ResolveItem::visit (AST::ExternBlock &extern_block) { + resolve_visibility (extern_block.get_visibility ()); + for (auto &item : extern_block.get_extern_items ()) { resolve_extern_item (item.get ()); @@ -895,6 +929,8 @@ ResolveImplItems::visit (AST::TypeAlias &alias) { ResolveItem::visit (alias); + resolve_visibility (alias.get_visibility ()); + // FIXME this stops the erronious unused decls which will be fixed later on resolver->get_type_scope ().append_reference_for_def (alias.get_node_id (), alias.get_node_id ()); @@ -911,6 +947,9 @@ void ResolveExternItem::visit (AST::ExternalFunctionItem &function) { NodeId scope_node_id = function.get_node_id (); + + resolve_visibility (function.get_visibility ()); + resolver->get_name_scope ().push (scope_node_id); resolver->get_type_scope ().push (scope_node_id); resolver->get_label_scope ().push (scope_node_id); @@ -945,6 +984,8 @@ ResolveExternItem::visit (AST::ExternalFunctionItem &function) void ResolveExternItem::visit (AST::ExternalStaticItem &item) { + resolve_visibility (item.get_visibility ()); + ResolveType::go (item.get_type ().get (), item.get_node_id ()); } diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc b/gcc/rust/resolve/rust-ast-resolve-path.cc index 7aec4f8..c7597a2 100644 --- a/gcc/rust/resolve/rust-ast-resolve-path.cc +++ b/gcc/rust/resolve/rust-ast-resolve-path.cc @@ -38,6 +38,13 @@ ResolvePath::go (AST::QualifiedPathInExpression *expr, NodeId parent) } void +ResolvePath::go (AST::SimplePath *expr, NodeId parent) +{ + ResolvePath resolver (parent); + resolver.resolve_path (expr); +} + +void ResolvePath::resolve_path (AST::PathInExpression *expr) { // resolve root segment first then apply segments in turn @@ -272,5 +279,70 @@ ResolvePath::resolve_segments (CanonicalPath prefix, size_t offs, } } +static bool +lookup_and_insert_segment (Resolver *resolver, CanonicalPath path, + NodeId segment_id, NodeId *to_resolve, bool &is_type) +{ + if (resolver->get_name_scope ().lookup (path, to_resolve)) + { + resolver->insert_resolved_name (segment_id, *to_resolve); + } + else if (resolver->get_type_scope ().lookup (path, to_resolve)) + { + is_type = true; + resolver->insert_resolved_type (segment_id, *to_resolve); + } + else + { + return false; + } + + return true; +} + +void +ResolvePath::resolve_path (AST::SimplePath *simple_path) +{ + // resolve root segment first then apply segments in turn + auto expr_node_id = simple_path->get_node_id (); + auto is_type = false; + + auto path = CanonicalPath::create_empty (); + for (const auto &seg : simple_path->get_segments ()) + { + auto s = ResolveSimplePathSegmentToCanonicalPath::resolve (seg); + path = path.append (s); + + // Reset state + resolved_node = UNKNOWN_NODEID; + is_type = false; + + if (!lookup_and_insert_segment (resolver, path, seg.get_node_id (), + &resolved_node, is_type)) + { + rust_error_at (seg.get_locus (), + "cannot find simple path segment %qs", + seg.as_string ().c_str ()); + return; + } + } + + if (resolved_node == UNKNOWN_NODEID) + { + rust_error_at (simple_path->get_locus (), + "could not resolve simple path %qs", + simple_path->as_string ().c_str ()); + return; + } + + if (is_type) + resolver->insert_resolved_type (expr_node_id, resolved_node); + else + resolver->insert_resolved_name (expr_node_id, resolved_node); + + resolver->insert_new_definition (expr_node_id, + Definition{expr_node_id, parent}); +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-ast-resolve-path.h b/gcc/rust/resolve/rust-ast-resolve-path.h index 7a4413b..cbfe967 100644 --- a/gcc/rust/resolve/rust-ast-resolve-path.h +++ b/gcc/rust/resolve/rust-ast-resolve-path.h @@ -31,16 +31,33 @@ class ResolvePath : public ResolverBase public: static void go (AST::PathInExpression *expr, NodeId parent); static void go (AST::QualifiedPathInExpression *expr, NodeId parent); + static void go (AST::SimplePath *expr, NodeId parent); private: ResolvePath (NodeId parent) : ResolverBase (parent) {} void resolve_path (AST::PathInExpression *expr); void resolve_path (AST::QualifiedPathInExpression *expr); + void resolve_path (AST::SimplePath *expr); void resolve_segments (CanonicalPath prefix, size_t offs, std::vector<AST::PathExprSegment> &segs, NodeId expr_node_id, Location expr_locus); + + void + resolve_simple_path_segments (CanonicalPath prefix, size_t offs, + const std::vector<AST::SimplePathSegment> &segs, + NodeId expr_node_id, Location expr_locus); +}; + +class ResolveSimplePathSegmentToCanonicalPath +{ +public: + static CanonicalPath resolve (const AST::SimplePathSegment &seg) + { + // FIXME: Since this is so simple, maybe it can simply be a tiny function? + return CanonicalPath::new_seg (seg.get_node_id (), seg.get_segment_name ()); + } }; } // namespace Resolver diff --git a/gcc/testsuite/rust/compile/pub_restricted_1.rs b/gcc/testsuite/rust/compile/pub_restricted_1.rs new file mode 100644 index 0000000..01fb65e --- /dev/null +++ b/gcc/testsuite/rust/compile/pub_restricted_1.rs @@ -0,0 +1,14 @@ +pub mod foo { + pub mod bar { + pub fn baz() {} + } +} + +// this is invalid Rust: We just want to make sure the paths get resolved properly +pub(in foo::bar::baz) struct A0; + +pub(in foo::fah::baz) struct A1; // { dg-error "cannot find simple path segment .fah." } +pub(in fro::bulator::saindoux) struct A2; // { dg-error "cannot find simple path segment .fro." } +pub(in foo::bar::saindoux) struct A3; // { dg-error "cannot find simple path segment .saindoux." } + +fn main() {} |