diff options
author | Philip Herron <philip.herron@embecosm.com> | 2020-12-10 17:55:45 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2020-12-17 17:23:46 +0000 |
commit | 97d2003e8c0027601648364c3561b6aa479c842e (patch) | |
tree | 8bb1986fe2d890cadcddaa0ead2bac84cc195352 /gcc | |
parent | 6c89617fc9525b726a494d4b44d19178049169a0 (diff) | |
download | gcc-97d2003e8c0027601648364c3561b6aa479c842e.zip gcc-97d2003e8c0027601648364c3561b6aa479c842e.tar.gz gcc-97d2003e8c0027601648364c3561b6aa479c842e.tar.bz2 |
Add generated NodeId's to the AST
NodeIds are going to be used for Hir->Ast lookups later on.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-ast-full-decls.h | 528 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 128 | ||||
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 41 | ||||
-rw-r--r-- | gcc/rust/ast/rust-item.h | 44 | ||||
-rw-r--r-- | gcc/rust/ast/rust-path.h | 30 |
5 files changed, 481 insertions, 290 deletions
diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index 9b604a5..ebd2b2a 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -1,266 +1,286 @@ +// Copyright (C) 2020 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_AST_FULL_DECLS_H #define RUST_AST_FULL_DECLS_H -// Forward declarations for all AST classes. Useful for not having to include all definitions. + +// Forward declarations for all AST classes. Useful for not having to include +// all definitions. namespace Rust { - namespace AST { - // rust-ast.h - class AttrInput; - class TokenTree; - class MacroMatch; - class Token; - struct Literal; - class DelimTokenTree; - class PathSegment; - class SimplePathSegment; - class SimplePath; - struct Attribute; - class MetaItemInner; - class AttrInputMetaItemContainer; - class MetaItem; - class Stmt; - class Item; - class Expr; - class ExprWithoutBlock; - class IdentifierExpr; - class Pattern; - class Type; - class TypeNoBounds; - class TypeParamBound; - class Lifetime; - class GenericParam; - class LifetimeParam; - class MacroItem; - class TraitItem; - class InherentImplItem; - class TraitImplItem; - class MacroInvocationSemi; - struct Crate; - class PathExpr; +namespace AST { +// rust-ast.h +class AttrInput; +class TokenTree; +class MacroMatch; +class Token; +struct Literal; +class DelimTokenTree; +class PathSegment; +class SimplePathSegment; +class SimplePath; +struct Attribute; +class MetaItemInner; +class AttrInputMetaItemContainer; +class MetaItem; +class Stmt; +class Item; +class Expr; +class ExprWithoutBlock; +class IdentifierExpr; +class Pattern; +class Type; +class TypeNoBounds; +class TypeParamBound; +class Lifetime; +class GenericParam; +class LifetimeParam; +class MacroItem; +class TraitItem; +class InherentImplItem; +class TraitImplItem; +class MacroInvocationSemi; +struct Crate; +class PathExpr; - // rust-path.h - class PathIdentSegment; - struct GenericArgsBinding; - struct GenericArgs; - class PathExprSegment; - class PathPattern; - class PathInExpression; - class TypePathSegment; - class TypePathSegmentGeneric; - struct TypePathFunction; - class TypePathSegmentFunction; - class TypePath; - struct QualifiedPathType; - class QualifiedPathInExpression; - class QualifiedPathInType; +// rust-path.h +class PathIdentSegment; +struct GenericArgsBinding; +struct GenericArgs; +class PathExprSegment; +class PathPattern; +class PathInExpression; +class TypePathSegment; +class TypePathSegmentGeneric; +struct TypePathFunction; +class TypePathSegmentFunction; +class TypePath; +struct QualifiedPathType; +class QualifiedPathInExpression; +class QualifiedPathInType; - // rust-expr.h - class ExprWithBlock; - class LiteralExpr; - class AttrInputLiteral; - class MetaItemLitExpr; - class MetaItemPathLit; - class OperatorExpr; - class BorrowExpr; - class DereferenceExpr; - class ErrorPropagationExpr; - class NegationExpr; - class ArithmeticOrLogicalExpr; - class ComparisonExpr; - class LazyBooleanExpr; - class TypeCastExpr; - class AssignmentExpr; - class CompoundAssignmentExpr; - class GroupedExpr; - class ArrayElems; - class ArrayElemsValues; - class ArrayElemsCopied; - class ArrayExpr; - class ArrayIndexExpr; - class TupleExpr; - class TupleIndexExpr; - class StructExpr; - class StructExprStruct; - struct StructBase; - class StructExprField; - class StructExprFieldIdentifier; - class StructExprFieldWithVal; - class StructExprFieldIdentifierValue; - class StructExprFieldIndexValue; - class StructExprStructFields; - class StructExprStructBase; - class StructExprTuple; - class StructExprUnit; - class EnumVariantExpr; - class EnumExprField; - class EnumExprFieldIdentifier; - class EnumExprFieldWithVal; - class EnumExprFieldIdentifierValue; - class EnumExprFieldIndexValue; - class EnumExprStruct; - class EnumExprTuple; - class EnumExprFieldless; - class CallExpr; - class MethodCallExpr; - class FieldAccessExpr; - struct ClosureParam; - class ClosureExpr; - class ClosureExprInner; - class BlockExpr; - class ClosureExprInnerTyped; - class ContinueExpr; - class BreakExpr; - class RangeExpr; - class RangeFromToExpr; - class RangeFromExpr; - class RangeToExpr; - class RangeFullExpr; - class RangeFromToInclExpr; - class RangeToInclExpr; - class ReturnExpr; - class UnsafeBlockExpr; - class LoopLabel; - class BaseLoopExpr; - class LoopExpr; - class WhileLoopExpr; - class WhileLetLoopExpr; - class ForLoopExpr; - class IfExpr; - class IfExprConseqElse; - class IfExprConseqIf; - class IfLetExpr; - class IfExprConseqIfLet; - class IfLetExprConseqElse; - class IfLetExprConseqIf; - class IfLetExprConseqIfLet; - struct MatchArm; - // class MatchCase; - // class MatchCaseBlockExpr; - // class MatchCaseExpr; - struct MatchCase; - class MatchExpr; - class AwaitExpr; - class AsyncBlockExpr; +// rust-expr.h +class ExprWithBlock; +class LiteralExpr; +class AttrInputLiteral; +class MetaItemLitExpr; +class MetaItemPathLit; +class OperatorExpr; +class BorrowExpr; +class DereferenceExpr; +class ErrorPropagationExpr; +class NegationExpr; +class ArithmeticOrLogicalExpr; +class ComparisonExpr; +class LazyBooleanExpr; +class TypeCastExpr; +class AssignmentExpr; +class CompoundAssignmentExpr; +class GroupedExpr; +class ArrayElems; +class ArrayElemsValues; +class ArrayElemsCopied; +class ArrayExpr; +class ArrayIndexExpr; +class TupleExpr; +class TupleIndexExpr; +class StructExpr; +class StructExprStruct; +struct StructBase; +class StructExprField; +class StructExprFieldIdentifier; +class StructExprFieldWithVal; +class StructExprFieldIdentifierValue; +class StructExprFieldIndexValue; +class StructExprStructFields; +class StructExprStructBase; +class StructExprTuple; +class StructExprUnit; +class EnumVariantExpr; +class EnumExprField; +class EnumExprFieldIdentifier; +class EnumExprFieldWithVal; +class EnumExprFieldIdentifierValue; +class EnumExprFieldIndexValue; +class EnumExprStruct; +class EnumExprTuple; +class EnumExprFieldless; +class CallExpr; +class MethodCallExpr; +class FieldAccessExpr; +struct ClosureParam; +class ClosureExpr; +class ClosureExprInner; +class BlockExpr; +class ClosureExprInnerTyped; +class ContinueExpr; +class BreakExpr; +class RangeExpr; +class RangeFromToExpr; +class RangeFromExpr; +class RangeToExpr; +class RangeFullExpr; +class RangeFromToInclExpr; +class RangeToInclExpr; +class ReturnExpr; +class UnsafeBlockExpr; +class LoopLabel; +class BaseLoopExpr; +class LoopExpr; +class WhileLoopExpr; +class WhileLetLoopExpr; +class ForLoopExpr; +class IfExpr; +class IfExprConseqElse; +class IfExprConseqIf; +class IfLetExpr; +class IfExprConseqIfLet; +class IfLetExprConseqElse; +class IfLetExprConseqIf; +class IfLetExprConseqIfLet; +struct MatchArm; +// class MatchCase; +// class MatchCaseBlockExpr; +// class MatchCaseExpr; +struct MatchCase; +class MatchExpr; +class AwaitExpr; +class AsyncBlockExpr; - // rust-stmt.h - class EmptyStmt; - class LetStmt; - class ExprStmt; - class ExprStmtWithoutBlock; - class ExprStmtWithBlock; +// rust-stmt.h +class EmptyStmt; +class LetStmt; +class ExprStmt; +class ExprStmtWithoutBlock; +class ExprStmtWithBlock; - // rust-item.h - class TypeParam; - class WhereClauseItem; - class LifetimeWhereClauseItem; - class TypeBoundWhereClauseItem; - struct WhereClause; - struct SelfParam; - struct FunctionQualifiers; - struct FunctionParam; - struct Visibility; - class Method; - class VisItem; - class Module; - class ModuleBodied; - class ModuleNoBody; - class ExternCrate; - class UseTree; - class UseTreeGlob; - class UseTreeList; - class UseTreeRebind; - class UseDeclaration; - class Function; - class TypeAlias; - class Struct; - struct StructField; - class StructStruct; - struct TupleField; - class TupleStruct; - class EnumItem; - class EnumItemTuple; - class EnumItemStruct; - class EnumItemDiscriminant; - class Enum; - class Union; - class ConstantItem; - class StaticItem; - struct TraitFunctionDecl; - class TraitItemFunc; - struct TraitMethodDecl; - class TraitItemMethod; - class TraitItemConst; - class TraitItemType; - class Trait; - class Impl; - class InherentImpl; - class TraitImpl; - class ExternalItem; - class ExternalStaticItem; - struct NamedFunctionParam; - class ExternalFunctionItem; - class ExternBlock; +// rust-item.h +class TypeParam; +class WhereClauseItem; +class LifetimeWhereClauseItem; +class TypeBoundWhereClauseItem; +struct WhereClause; +struct SelfParam; +struct FunctionQualifiers; +struct FunctionParam; +struct Visibility; +class Method; +class VisItem; +class Module; +class ModuleBodied; +class ModuleNoBody; +class ExternCrate; +class UseTree; +class UseTreeGlob; +class UseTreeList; +class UseTreeRebind; +class UseDeclaration; +class Function; +class TypeAlias; +class Struct; +struct StructField; +class StructStruct; +struct TupleField; +class TupleStruct; +class EnumItem; +class EnumItemTuple; +class EnumItemStruct; +class EnumItemDiscriminant; +class Enum; +class Union; +class ConstantItem; +class StaticItem; +struct TraitFunctionDecl; +class TraitItemFunc; +struct TraitMethodDecl; +class TraitItemMethod; +class TraitItemConst; +class TraitItemType; +class Trait; +class Impl; +class InherentImpl; +class TraitImpl; +class ExternalItem; +class ExternalStaticItem; +struct NamedFunctionParam; +class ExternalFunctionItem; +class ExternBlock; - // rust-macro.h - class MacroMatchFragment; - class MacroMatchRepetition; - class MacroMatcher; - struct MacroTranscriber; - struct MacroRule; - class MacroRulesDefinition; - class MacroInvocation; - class MetaItemPath; - class MetaItemSeq; - class MetaWord; - class MetaNameValueStr; - class MetaListPaths; - class MetaListNameValueStr; +// rust-macro.h +class MacroMatchFragment; +class MacroMatchRepetition; +class MacroMatcher; +struct MacroTranscriber; +struct MacroRule; +class MacroRulesDefinition; +class MacroInvocation; +class MetaItemPath; +class MetaItemSeq; +class MetaWord; +class MetaNameValueStr; +class MetaListPaths; +class MetaListNameValueStr; - // rust-pattern.h - class LiteralPattern; - class IdentifierPattern; - class WildcardPattern; - class RangePatternBound; - class RangePatternBoundLiteral; - class RangePatternBoundPath; - class RangePatternBoundQualPath; - class RangePattern; - class ReferencePattern; - struct StructPatternEtc; - class StructPatternField; - class StructPatternFieldTuplePat; - class StructPatternFieldIdentPat; - class StructPatternFieldIdent; - struct StructPatternElements; - class StructPattern; - class TupleStructItems; - class TupleStructItemsNoRange; - class TupleStructItemsRange; - class TupleStructPattern; - class TuplePatternItems; - class TuplePatternItemsMultiple; - class TuplePatternItemsRanged; - class TuplePattern; - class GroupedPattern; - class SlicePattern; +// rust-pattern.h +class LiteralPattern; +class IdentifierPattern; +class WildcardPattern; +class RangePatternBound; +class RangePatternBoundLiteral; +class RangePatternBoundPath; +class RangePatternBoundQualPath; +class RangePattern; +class ReferencePattern; +struct StructPatternEtc; +class StructPatternField; +class StructPatternFieldTuplePat; +class StructPatternFieldIdentPat; +class StructPatternFieldIdent; +struct StructPatternElements; +class StructPattern; +class TupleStructItems; +class TupleStructItemsNoRange; +class TupleStructItemsRange; +class TupleStructPattern; +class TuplePatternItems; +class TuplePatternItemsMultiple; +class TuplePatternItemsRanged; +class TuplePattern; +class GroupedPattern; +class SlicePattern; - // rust-type.h - class TraitBound; - class ImplTraitType; - class TraitObjectType; - class ParenthesisedType; - class ImplTraitTypeOneBound; - class TraitObjectTypeOneBound; - class TupleType; - class NeverType; - class RawPointerType; - class ReferenceType; - class ArrayType; - class SliceType; - class InferredType; - struct MaybeNamedParam; - class BareFunctionType; - } -} +// rust-type.h +class TraitBound; +class ImplTraitType; +class TraitObjectType; +class ParenthesisedType; +class ImplTraitTypeOneBound; +class TraitObjectTypeOneBound; +class TupleType; +class NeverType; +class RawPointerType; +class ReferenceType; +class ArrayType; +class SliceType; +class InferredType; +struct MaybeNamedParam; +class BareFunctionType; +} // namespace AST +} // namespace Rust -#endif
\ No newline at end of file +#endif diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index bdc1f12..fe60ae0 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1,18 +1,31 @@ +// Copyright (C) 2020 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_AST_BASE_H #define RUST_AST_BASE_H // Base for AST used in gccrs, basically required by all specific ast things #include "rust-system.h" - -// STL imports -#include <memory> -#include <string> -#include <vector> +#include "rust-hir-map.h" // gccrs imports // required for AST::Token #include "rust-token.h" - #include "rust-location.h" namespace Rust { @@ -253,6 +266,95 @@ public: bool is_error () const { return value_as_string == ""; } }; +// A token tree with delimiters +class DelimTokenTree : public TokenTree, public AttrInput +{ + DelimType delim_type; + std::vector<std::unique_ptr<TokenTree> > token_trees; + Location locus; + +protected: + DelimTokenTree *clone_delim_tok_tree_impl () const + { + return new DelimTokenTree (*this); + } + + /* Use covariance to implement clone function as returning a DelimTokenTree + * object */ + DelimTokenTree *clone_attr_input_impl () const override + { + return clone_delim_tok_tree_impl (); + } + + /* Use covariance to implement clone function as returning a DelimTokenTree + * object */ + DelimTokenTree *clone_token_tree_impl () const override + { + return clone_delim_tok_tree_impl (); + } + +public: + DelimTokenTree (DelimType delim_type, + std::vector<std::unique_ptr<TokenTree> > token_trees + = std::vector<std::unique_ptr<TokenTree> > (), + Location locus = Location ()) + : delim_type (delim_type), token_trees (std::move (token_trees)), + locus (locus) + {} + + // Copy constructor with vector clone + DelimTokenTree (DelimTokenTree const &other) + : delim_type (other.delim_type), locus (other.locus) + { + token_trees.reserve (other.token_trees.size ()); + for (const auto &e : other.token_trees) + token_trees.push_back (e->clone_token_tree ()); + } + + // overloaded assignment operator with vector clone + DelimTokenTree &operator= (DelimTokenTree const &other) + { + delim_type = other.delim_type; + locus = other.locus; + + token_trees.reserve (other.token_trees.size ()); + for (const auto &e : other.token_trees) + token_trees.push_back (e->clone_token_tree ()); + + return *this; + } + + // move constructors + DelimTokenTree (DelimTokenTree &&other) = default; + DelimTokenTree &operator= (DelimTokenTree &&other) = default; + + static DelimTokenTree create_empty () { return DelimTokenTree (PARENS); } + + std::string as_string () const override; + + void accept_vis (ASTVisitor &vis) override; + + bool + check_cfg_predicate (const Session &session ATTRIBUTE_UNUSED) const override + { + // this should never be called - should be converted first + return false; + } + + AttrInput *parse_to_meta_item () const override; + + std::vector<std::unique_ptr<Token> > to_token_stream () const override; + + std::unique_ptr<DelimTokenTree> clone_delim_token_tree () const + { + return std::unique_ptr<DelimTokenTree> (clone_delim_tok_tree_impl ()); + } +}; + +/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to + * be defined */ +class AttrInputLiteral; + /* TODO: move applicable stuff into here or just don't include it because * nothing uses it A segment of a path (maybe) */ class PathSegment @@ -473,7 +575,7 @@ public: std::string as_string () const; // TODO: does this require visitor pattern as not polymorphic? - + const SimplePath &get_path () const { return path; } SimplePath &get_path () { return path; } @@ -768,10 +870,15 @@ public: virtual void mark_for_strip () = 0; virtual bool is_marked_for_strip () const = 0; + NodeId get_node_id () const { return node_id; } protected: + Stmt () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} + // Clone function implementation as pure virtual method virtual Stmt *clone_stmt_impl () const = 0; + + NodeId node_id; }; // Rust "item" AST node (declaration of top-level/module-level allowed stuff) @@ -848,10 +955,13 @@ public: virtual void mark_for_strip () = 0; virtual bool is_marked_for_strip () const = 0; + NodeId get_node_id () const { return node_id; } + protected: // Constructor Expr (std::vector<Attribute> outer_attribs = std::vector<Attribute> ()) - : outer_attrs (std::move (outer_attribs)) + : outer_attrs (std::move (outer_attribs)), + node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} // Clone function implementation as pure virtual method @@ -863,6 +973,8 @@ protected: { outer_attrs = std::move (outer_attrs_to_set); } + + NodeId node_id; }; // AST node for an expression without an accompanying block - abstract diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index f86aa54..864ee1d 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -1647,7 +1647,8 @@ class StructExprFieldIdentifierValue : public StructExprFieldWithVal public: StructExprFieldIdentifierValue (Identifier field_identifier, - std::unique_ptr<Expr> field_value, Location locus) + std::unique_ptr<Expr> field_value, + Location locus) : StructExprFieldWithVal (std::move (field_value)), field_name (std::move (field_identifier)), locus (locus) {} @@ -1679,7 +1680,8 @@ class StructExprFieldIndexValue : public StructExprFieldWithVal public: StructExprFieldIndexValue (TupleIndex tuple_index, std::unique_ptr<Expr> field_value, Location locus) - : StructExprFieldWithVal (std::move (field_value)), index (tuple_index), locus (locus) + : StructExprFieldWithVal (std::move (field_value)), index (tuple_index), + locus (locus) {} std::string as_string () const override; @@ -2039,7 +2041,8 @@ class EnumExprFieldIdentifierValue : public EnumExprFieldWithVal public: EnumExprFieldIdentifierValue (Identifier field_name, - std::unique_ptr<Expr> field_value, Location locus) + std::unique_ptr<Expr> field_value, + Location locus) : EnumExprFieldWithVal (std::move (field_value)), field_name (std::move (field_name)), locus (locus) {} @@ -2071,7 +2074,8 @@ class EnumExprFieldIndexValue : public EnumExprFieldWithVal public: EnumExprFieldIndexValue (TupleIndex field_index, std::unique_ptr<Expr> field_value, Location locus) - : EnumExprFieldWithVal (std::move (field_value)), index (field_index), locus (locus) + : EnumExprFieldWithVal (std::move (field_value)), index (field_index), + locus (locus) {} std::string as_string () const override; @@ -2325,6 +2329,20 @@ public: void mark_for_strip () override { function = nullptr; } bool is_marked_for_strip () const override { return function == nullptr; } + void iterate_params (std::function<bool (Expr *)> cb) + { + for (auto it = params.begin (); it != params.end (); it++) + { + if (!cb (it->get ())) + return; + } + } + +protected: + /* Use covariance to implement clone function as returning this object rather + * than base */ + CallExpr *clone_expr_impl () const override { return new CallExpr (*this); } + // TODO: this mutable getter seems really dodgy. Think up better way. const std::vector<std::unique_ptr<Expr> > &get_params () const { @@ -2793,13 +2811,16 @@ public: void accept_vis (ASTVisitor &vis) override; // Can be completely empty, so have to have a separate flag. - void mark_for_strip () override - { - marked_for_strip = true; - } - bool is_marked_for_strip () const override + void mark_for_strip () override { marked_for_strip = true; } + bool is_marked_for_strip () const override { return marked_for_strip; } + + void iterate_stmts (std::function<bool (Stmt *)> cb) { - return marked_for_strip; + for (auto it = statements.begin (); it != statements.end (); it++) + { + if (!cb (it->get ())) + return; + } } // TODO: this mutable getter seems really dodgy. Think up better way. diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index f18124d..4b3a2d5 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1,23 +1,23 @@ -#ifndef RUST_AST_ITEM_H -#define RUST_AST_ITEM_H -/* -Copyright (C) 2009-2020 Free Software Foundation, Inc. +// Copyright (C) 2020 Free Software Foundation, Inc. -This file is part of GCC. +// 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 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. +// 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/>. */ +// 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_AST_ITEM_H +#define RUST_AST_ITEM_H #include "rust-ast.h" #include "rust-path.h" @@ -504,11 +504,13 @@ public: std::unique_ptr<Type> param_type, std::vector<Attribute> outer_attrs, Location locus) : outer_attrs (std::move (outer_attrs)), locus (locus), - param_name (std::move (param_name)), type (std::move (param_type)) + param_name (std::move (param_name)), type (std::move (param_type)), + node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} // Copy constructor uses clone - FunctionParam (FunctionParam const &other) : locus (other.locus) + FunctionParam (FunctionParam const &other) + : locus (other.locus), node_id (other.node_id) { // guard to prevent nullptr dereference if (other.param_name != nullptr) @@ -521,6 +523,7 @@ public: FunctionParam &operator= (FunctionParam const &other) { locus = other.locus; + node_id = other.node_id; // guard to prevent nullptr dereference if (other.param_name != nullptr) @@ -569,6 +572,10 @@ public: rust_assert (type != nullptr); return type; } + NodeId get_node_id () const { return node_id; } + +protected: + NodeId node_id; }; // Visibility of item - if the item has it, then it is some form of public @@ -3320,6 +3327,7 @@ public: std::vector<std::unique_ptr<TraitItem> > trait_items, Visibility vis, std::vector<Attribute> outer_attrs, std::vector<Attribute> inner_attrs, Location locus) + : VisItem (std::move (vis), std::move (outer_attrs)), has_unsafe (is_unsafe), name (std::move (name)), generic_params (std::move (generic_params)), diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index 392fc18..20138b6 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -240,6 +240,8 @@ public: rust_assert (has_generic_args ()); return generic_args; } + + PathIdentSegment &get_ident_segment () { return segment_name; } }; // AST node representing a pattern that involves a "path" - abstract base class @@ -276,6 +278,15 @@ public: // TODO: this seems kinda dodgy std::vector<PathExprSegment> &get_segments () { return segments; } const std::vector<PathExprSegment> &get_segments () const { return segments; } + + void iterate_path_segments (std::function<bool (PathExprSegment &)> cb) + { + for (auto it = segments.begin (); it != segments.end (); it++) + { + if (!cb (*it)) + return; + } + } }; /* AST node representing a path-in-expression pattern (path that allows generic @@ -328,6 +339,7 @@ public: // Invalid if path is empty (error state), so base stripping on that. void mark_for_strip () override { remove_all_segments (); } bool is_marked_for_strip () const override { return is_error (); } + bool opening_scope_resolution () { return has_opening_scope_resolution; } protected: /* Use covariance to implement clone function as returning this object rather @@ -404,6 +416,13 @@ public: // not pure virtual as class not abstract virtual void accept_vis (ASTVisitor &vis); + + bool get_separating_scope_resolution () const + { + return has_separating_scope_resolution; + } + + PathIdentSegment get_ident_segment () { return ident_segment; }; }; // Segment used in type path with generic args @@ -689,6 +708,17 @@ public: { return segments; } + + size_t get_num_segments () const { return segments.size (); } + + void iterate_segments (std::function<bool (TypePathSegment *)> cb) + { + for (auto it = segments.begin (); it != segments.end (); it++) + { + if (!cb ((*it).get ())) + return; + } + } }; struct QualifiedPathType |