aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-06-11 18:05:52 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-06-11 18:05:52 +0100
commitd8d7deb33511c5776997447bb070279e770ab4be (patch)
tree36efed20e9ee9eb1c4d9c24e13e3ad04b0d1910e
parentdf36e6b9abb197ceb0ff5d1020482c75c6f1424a (diff)
downloadgcc-d8d7deb33511c5776997447bb070279e770ab4be.zip
gcc-d8d7deb33511c5776997447bb070279e770ab4be.tar.gz
gcc-d8d7deb33511c5776997447bb070279e770ab4be.tar.bz2
HIR should not contain any macros
This removes the macros tree's from HIR. HIR should be an expanded and simplifed representation of the compilation unit. Fixes #70
-rw-r--r--gcc/rust/analysis/rust-hir-liveness-base.h8
-rw-r--r--gcc/rust/backend/rust-compile-base.h17
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-decls.h18
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-test.cc257
-rw-r--r--gcc/rust/hir/tree/rust-hir-full.h2
-rw-r--r--gcc/rust/hir/tree/rust-hir-macro.h400
-rw-r--r--gcc/rust/hir/tree/rust-hir-visitor.h68
-rw-r--r--gcc/rust/hir/tree/rust-hir.h149
-rw-r--r--gcc/rust/typecheck/rust-hir-const-fold-base.h7
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-base.h7
10 files changed, 5 insertions, 928 deletions
diff --git a/gcc/rust/analysis/rust-hir-liveness-base.h b/gcc/rust/analysis/rust-hir-liveness-base.h
index 1a58f1a..e8a1682 100644
--- a/gcc/rust/analysis/rust-hir-liveness-base.h
+++ b/gcc/rust/analysis/rust-hir-liveness-base.h
@@ -32,7 +32,7 @@ class LivenessBase : public HIR::HIRVisitor
{
public:
virtual ~LivenessBase () {}
- virtual void visit (HIR::Token &) override {}
+
virtual void visit (HIR::IdentifierExpr &) override {}
virtual void visit (HIR::Lifetime &) override {}
virtual void visit (HIR::LifetimeParam &) override {}
@@ -151,12 +151,6 @@ public:
virtual void visit (HIR::ExternalFunctionItem &) override {}
virtual void visit (HIR::ExternBlock &) override {}
- virtual void visit (HIR::MacroMatchFragment &) override {}
- virtual void visit (HIR::MacroMatchRepetition &) override {}
- virtual void visit (HIR::MacroMatcher &) override {}
- virtual void visit (HIR::MacroRulesDefinition &) override {}
- virtual void visit (HIR::MacroInvocation &) override {}
-
virtual void visit (HIR::LiteralPattern &) override {}
virtual void visit (HIR::IdentifierPattern &) override {}
virtual void visit (HIR::WildcardPattern &) override {}
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index 24a7ccc..b071a30 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -32,19 +32,9 @@ public:
virtual ~HIRCompileBase () {}
// rust-ast.h
- virtual void visit (HIR::Token &tok) {}
- // virtual void visit(Stmt& stmt) {}
- // virtual void visit(Expr& expr) {}
virtual void visit (HIR::IdentifierExpr &ident_expr) {}
- // virtual void visit(Pattern& pattern) {}
- // virtual void visit(Type& type) {}
- // virtual void visit(TypeParamBound& type_param_bound) {}
virtual void visit (HIR::Lifetime &lifetime) {}
- // virtual void visit(GenericParam& generic_param) {}
virtual void visit (HIR::LifetimeParam &lifetime_param) {}
- // virtual void visit(TraitItem& trait_item) {}
- // virtual void visit(InherentImplItem& inherent_impl_item) {}
- // virtual void visit(TraitImplItem& trait_impl_item) {}
// rust-path.h
virtual void visit (HIR::PathInExpression &path) {}
@@ -164,13 +154,6 @@ public:
virtual void visit (HIR::ExternalFunctionItem &item) {}
virtual void visit (HIR::ExternBlock &block) {}
- // rust-macro.h
- virtual void visit (HIR::MacroMatchFragment &match) {}
- virtual void visit (HIR::MacroMatchRepetition &match) {}
- virtual void visit (HIR::MacroMatcher &matcher) {}
- virtual void visit (HIR::MacroRulesDefinition &rules_def) {}
- virtual void visit (HIR::MacroInvocation &macro_invoc) {}
-
// rust-pattern.h
virtual void visit (HIR::LiteralPattern &pattern) {}
virtual void visit (HIR::IdentifierPattern &pattern) {}
diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h
index cdbc0a0..6fae193 100644
--- a/gcc/rust/hir/tree/rust-hir-full-decls.h
+++ b/gcc/rust/hir/tree/rust-hir-full-decls.h
@@ -18,15 +18,10 @@
#ifndef RUST_HIR_FULL_DECLS_H
#define RUST_HIR_FULL_DECLS_H
-// Forward declarations for all HIR classes. Useful for not having to include
-// all definitions.
namespace Rust {
namespace HIR {
-// rust-ast.h
-class TokenTree;
-class MacroMatch;
-class Token;
+
struct Literal;
class Stmt;
class Item;
@@ -40,7 +35,7 @@ class TypeParamBound;
class Lifetime;
class GenericParam;
class LifetimeParam;
-class MacroItem;
+
class TraitItem;
class InherentImplItem;
class TraitImplItem;
@@ -208,15 +203,6 @@ struct NamedFunctionParam;
class ExternalFunctionItem;
class ExternBlock;
-// rust-macro.h
-class MacroMatchFragment;
-class MacroMatchRepetition;
-class MacroMatcher;
-struct MacroTranscriber;
-struct MacroRule;
-class MacroRulesDefinition;
-class MacroInvocation;
-
// rust-pattern.h
class LiteralPattern;
class IdentifierPattern;
diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc
index 63eb1bb..d080d8b 100644
--- a/gcc/rust/hir/tree/rust-hir-full-test.cc
+++ b/gcc/rust/hir/tree/rust-hir-full-test.cc
@@ -69,45 +69,6 @@ get_string_in_delims (std::string str_input, AST::DelimType delim_type)
gcc_unreachable ();
}
-// Converts a frag spec enum item to a string form.
-std::string
-frag_spec_to_str (MacroFragSpec frag_spec)
-{
- switch (frag_spec)
- {
- case BLOCK:
- return "block";
- case EXPR:
- return "expr";
- case IDENT:
- return "ident";
- case ITEM:
- return "item";
- case LIFETIME:
- return "lifetime";
- case LITERAL:
- return "literal";
- case META:
- return "meta";
- case PAT:
- return "pat";
- case PATH:
- return "path";
- case STMT:
- return "stmt";
- case TT:
- return "tt";
- case TY:
- return "ty";
- case VIS:
- return "vis";
- case INVALID:
- return "INVALID_FRAG_SPEC";
- default:
- return "ERROR_MARK_STRING - unknown frag spec";
- }
-}
-
std::string
Crate::as_string () const
{
@@ -164,18 +125,6 @@ Crate::as_string () const
}
std::string
-Token::as_string () const
-{
- /* FIXME: only works when not identifier or literal or whatever, i.e. when
- * doesn't store string value */
- // return get_token_description(token_id);
-
- // maybe fixed - stores everything as string though, so storage-inefficient
- std::string quote = is_string_lit () ? "\"" : "";
- return quote + str + quote;
-}
-
-std::string
Visibility::as_string () const
{
switch (public_vis_type)
@@ -1301,66 +1250,6 @@ ExternBlock::as_string () const
}
std::string
-MacroRule::as_string () const
-{
- std::string str ("Macro rule: ");
-
- str += "\n Matcher: \n ";
- str += matcher.as_string ();
-
- str += "\n Transcriber: \n ";
- str += transcriber.as_string ();
-
- return str;
-}
-
-std::string
-MacroRulesDefinition::as_string () const
-{
- std::string str ("macro_rules!");
-
- str += rule_name;
-
- str += "\n Macro rules: ";
- if (rules.empty ())
- {
- str += "none";
- }
- else
- {
- for (const auto &rule : rules)
- {
- str += "\n " + rule.as_string ();
- }
- }
-
- str += "\n Delim type: ";
- switch (delim_type)
- {
- case AST::DelimType::PARENS:
- str += "parentheses";
- break;
- case AST::DelimType::SQUARE:
- str += "square";
- break;
- case AST::DelimType::CURLY:
- str += "curly";
- break;
- default:
- return "ERROR_MARK_STRING - delim type in macro invocation";
- }
-
- return str;
-}
-
-std::string
-MacroInvocation::as_string () const
-{
- return "MacroInvocation: " + path.as_string () + "!"
- + token_tree.as_string ();
-}
-
-std::string
PathInExpression::as_string () const
{
std::string str;
@@ -2333,45 +2222,6 @@ TraitBound::as_string () const
}
std::string
-MacroMatcher::as_string () const
-{
- std::string str ("Macro matcher: ");
-
- str += "\n Delim type: ";
-
- switch (delim_type)
- {
- case AST::DelimType::PARENS:
- str += "parentheses";
- break;
- case AST::DelimType::SQUARE:
- str += "square";
- break;
- case AST::DelimType::CURLY:
- str += "curly";
- break;
- default:
- return "ERROR_MARK_STRING - macro matcher delim";
- }
-
- str += "\n Matches: ";
-
- if (matches.empty ())
- {
- str += "none";
- }
- else
- {
- for (const auto &match : matches)
- {
- str += "\n " + match->as_string ();
- }
- }
-
- return str;
-}
-
-std::string
LifetimeParam::as_string () const
{
std::string str ("LifetimeParam: ");
@@ -2405,12 +2255,6 @@ LifetimeParam::as_string () const
}
std::string
-MacroMatchFragment::as_string () const
-{
- return "$" + ident + ": " + frag_spec_to_str (frag_spec);
-}
-
-std::string
QualifiedPathInType::as_string () const
{
std::string str = path_type.as_string ();
@@ -2424,56 +2268,6 @@ QualifiedPathInType::as_string () const
}
std::string
-MacroMatchRepetition::as_string () const
-{
- std::string str ("Macro match repetition: ");
-
- str += "\n Matches: ";
- if (matches.empty ())
- {
- str += "none";
- }
- else
- {
- for (const auto &match : matches)
- {
- str += "\n " + match->as_string ();
- }
- }
-
- str += "\n Sep: ";
- if (!has_sep ())
- {
- str += "none";
- }
- else
- {
- str += sep->as_string ();
- }
-
- str += "\n Op: ";
- switch (op)
- {
- case ASTERISK:
- str += "*";
- break;
- case PLUS:
- str += "+";
- break;
- case QUESTION_MARK:
- str += "?";
- break;
- case NONE:
- str += "no op? shouldn't be allowed";
- break;
- default:
- return "ERROR_MARK_STRING - unknown op in macro match repetition";
- }
-
- return str;
-}
-
-std::string
Lifetime::as_string () const
{
if (is_error ())
@@ -4280,27 +4074,6 @@ ModuleBodied::add_crate_name (std::vector<std::string> &names) const
item->add_crate_name (names);
}
-std::vector<std::unique_ptr<Token> >
-Token::to_token_stream () const
-{
- /* initialisation list doesn't work as it needs copy constructor, so have to
- * do this */
- std::vector<std::unique_ptr<Token> > dummy_vector;
- dummy_vector.reserve (1);
- dummy_vector.push_back (std::unique_ptr<Token> (clone_token_impl ()));
- return dummy_vector;
-}
-
-/* Visitor implementations - these are short but inlining can't happen anyway
- * due to virtual functions and I didn't want to make the ast header includes
- * any longer than they already are. */
-
-void
-Token::accept_vis (HIRVisitor &vis)
-{
- vis.visit (*this);
-}
-
void
IdentifierExpr::accept_vis (HIRVisitor &vis)
{
@@ -4944,36 +4717,6 @@ ExternBlock::accept_vis (HIRVisitor &vis)
}
void
-MacroMatchFragment::accept_vis (HIRVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
-MacroMatchRepetition::accept_vis (HIRVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
-MacroMatcher::accept_vis (HIRVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
-MacroRulesDefinition::accept_vis (HIRVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
-MacroInvocation::accept_vis (HIRVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
LiteralPattern::accept_vis (HIRVisitor &vis)
{
vis.visit (*this);
diff --git a/gcc/rust/hir/tree/rust-hir-full.h b/gcc/rust/hir/tree/rust-hir-full.h
index 82525cd..3d4ed0f 100644
--- a/gcc/rust/hir/tree/rust-hir-full.h
+++ b/gcc/rust/hir/tree/rust-hir-full.h
@@ -19,7 +19,6 @@
#ifndef RUST_HIR_FULL_H
#define RUST_HIR_FULL_H
-// Use as a fast way of including all aspects of the HIR (i.e. all headers)
#include "rust-hir.h"
#include "rust-hir-expr.h"
#include "rust-hir-item.h"
@@ -27,6 +26,5 @@
#include "rust-hir-pattern.h"
#include "rust-hir-stmt.h"
#include "rust-hir-type.h"
-#include "rust-hir-macro.h"
#endif // RUST_HIR_FULL_H
diff --git a/gcc/rust/hir/tree/rust-hir-macro.h b/gcc/rust/hir/tree/rust-hir-macro.h
deleted file mode 100644
index 775c92f..0000000
--- a/gcc/rust/hir/tree/rust-hir-macro.h
+++ /dev/null
@@ -1,400 +0,0 @@
-// 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_HIR_MACRO_H
-#define RUST_HIR_MACRO_H
-
-#include "rust-ast-full-decls.h"
-#include "rust-hir.h"
-
-namespace Rust {
-namespace HIR {
-// Decls as definitions moved to rust-ast.h
-class MacroItem;
-
-enum MacroFragSpec
-{
- BLOCK,
- EXPR,
- IDENT,
- ITEM,
- LIFETIME,
- LITERAL,
- META,
- PAT,
- PATH,
- STMT,
- TT,
- TY,
- VIS,
- INVALID // not really a specifier, but used to mark invalid one passed in
-};
-
-inline MacroFragSpec
-get_frag_spec_from_str (std::string str)
-{
- if (str == "block")
- return BLOCK;
- else if (str == "expr")
- return EXPR;
- else if (str == "ident")
- return IDENT;
- else if (str == "item")
- return ITEM;
- else if (str == "lifetime")
- return LIFETIME;
- else if (str == "literal")
- return LITERAL;
- else if (str == "meta")
- return META;
- else if (str == "pat")
- return PAT;
- else if (str == "path")
- return PATH;
- else if (str == "stmt")
- return STMT;
- else if (str == "tt")
- return TT;
- else if (str == "ty")
- return TY;
- else if (str == "vis")
- return VIS;
- else
- {
- // error_at("invalid string '%s' used as fragment specifier",
- // str->c_str());
- return INVALID;
- }
-}
-
-// A macro match that has an identifier and fragment spec
-class MacroMatchFragment : public MacroMatch
-{
- Identifier ident;
- MacroFragSpec frag_spec;
-
- // TODO: should store location information?
-
-public:
- MacroMatchFragment (Identifier ident, MacroFragSpec frag_spec)
- : ident (std::move (ident)), frag_spec (frag_spec)
- {}
-
- // Returns whether macro match fragment is in an error state.
- bool is_error () const { return frag_spec == INVALID; }
-
- // Creates an error state macro match fragment.
- static MacroMatchFragment create_error ()
- {
- return MacroMatchFragment (std::string (""), INVALID);
- }
-
- std::string as_string () const override;
-
- void accept_vis (HIRVisitor &vis) override;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MacroMatchFragment *clone_macro_match_impl () const override
- {
- return new MacroMatchFragment (*this);
- }
-};
-
-// A repetition macro match
-class MacroMatchRepetition : public MacroMatch
-{
-public:
- enum MacroRepOp
- {
- NONE,
- ASTERISK,
- PLUS,
- QUESTION_MARK
- };
-
-private:
- std::vector<std::unique_ptr<MacroMatch> > matches;
- MacroRepOp op;
-
- // bool has_sep;
- typedef Token MacroRepSep;
- // any token except delimiters and repetition operators
- std::unique_ptr<MacroRepSep> sep;
-
- // TODO: should store location information?
-
-public:
- // Returns whether macro match repetition has separator token.
- bool has_sep () const { return sep != NULL; }
-
- MacroMatchRepetition (std::vector<std::unique_ptr<MacroMatch> > matches,
- MacroRepOp op, std::unique_ptr<MacroRepSep> sep)
- : matches (std::move (matches)), op (op), sep (std::move (sep))
- {}
-
- // Copy constructor with clone
- MacroMatchRepetition (MacroMatchRepetition const &other)
- : op (other.op), sep (other.sep->clone_token ())
- {
- matches.reserve (other.matches.size ());
- for (const auto &e : other.matches)
- matches.push_back (e->clone_macro_match ());
- }
-
- // Overloaded assignment operator to clone
- MacroMatchRepetition &operator= (MacroMatchRepetition const &other)
- {
- op = other.op;
- sep = other.sep->clone_token ();
-
- matches.reserve (other.matches.size ());
- for (const auto &e : other.matches)
- matches.push_back (e->clone_macro_match ());
-
- return *this;
- }
-
- // move constructors
- MacroMatchRepetition (MacroMatchRepetition &&other) = default;
- MacroMatchRepetition &operator= (MacroMatchRepetition &&other) = default;
-
- std::string as_string () const override;
-
- void accept_vis (HIRVisitor &vis) override;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MacroMatchRepetition *clone_macro_match_impl () const override
- {
- return new MacroMatchRepetition (*this);
- }
-};
-
-// can't inline due to polymorphism
-class MacroMatcher : public MacroMatch
-{
- AST::DelimType delim_type;
- std::vector<std::unique_ptr<MacroMatch> > matches;
-
- // TODO: think of way to mark invalid that doesn't take up more space
- bool is_invalid;
-
- // TODO: should store location information?
-
-public:
- MacroMatcher (AST::DelimType delim_type,
- std::vector<std::unique_ptr<MacroMatch> > matches)
- : delim_type (delim_type), matches (std::move (matches)), is_invalid (false)
- {}
-
- // copy constructor with vector clone
- MacroMatcher (MacroMatcher const &other) : delim_type (other.delim_type)
- {
- matches.reserve (other.matches.size ());
- for (const auto &e : other.matches)
- matches.push_back (e->clone_macro_match ());
- }
-
- // overloaded assignment operator with vector clone
- MacroMatcher &operator= (MacroMatcher const &other)
- {
- delim_type = other.delim_type;
-
- matches.reserve (other.matches.size ());
- for (const auto &e : other.matches)
- matches.push_back (e->clone_macro_match ());
-
- return *this;
- }
-
- // move constructors
- MacroMatcher (MacroMatcher &&other) = default;
- MacroMatcher &operator= (MacroMatcher &&other) = default;
-
- // Creates an error state macro matcher.
- static MacroMatcher create_error () { return MacroMatcher (true); }
-
- // Returns whether MacroMatcher is in an error state.
- bool is_error () const { return is_invalid; }
-
- std::string as_string () const override;
-
- void accept_vis (HIRVisitor &vis) override;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MacroMatcher *clone_macro_match_impl () const override
- {
- return new MacroMatcher (*this);
- }
-
- // constructor only used to create error matcher
- MacroMatcher (bool is_invalid)
- : delim_type (AST::DelimType::PARENS), is_invalid (is_invalid)
- {}
-};
-
-// TODO: inline?
-struct MacroTranscriber
-{
-private:
- AST::DelimTokenTree token_tree;
-
- // TODO: should store location information?
-
-public:
- MacroTranscriber (AST::DelimTokenTree token_tree)
- : token_tree (std::move (token_tree))
- {}
-
- std::string as_string () const { return token_tree.as_string (); }
-};
-
-// A macro rule? Matcher and transcriber pair?
-struct MacroRule
-{
-private:
- MacroMatcher matcher;
- MacroTranscriber transcriber;
-
- // TODO: should store location information?
-
-public:
- MacroRule (MacroMatcher matcher, MacroTranscriber transcriber)
- : matcher (std::move (matcher)), transcriber (std::move (transcriber))
- {}
-
- // Returns whether macro rule is in error state.
- bool is_error () const { return matcher.is_error (); }
-
- // Creates an error state macro rule.
- static MacroRule create_error ()
- {
- return MacroRule (MacroMatcher::create_error (),
- MacroTranscriber (AST::DelimTokenTree::create_empty ()));
- }
-
- std::string as_string () const;
-};
-
-// A macro rules definition item HIR node
-class MacroRulesDefinition : public MacroItem
-{
- Identifier rule_name;
- // MacroRulesDef rules_def; // TODO: inline
- // only curly without required semicolon at end
- AST::DelimType delim_type;
- // MacroRules rules;
- std::vector<MacroRule> rules; // inlined form
-
- Location locus;
-
-public:
- std::string as_string () const override;
-
- MacroRulesDefinition (Analysis::NodeMapping mappings, Identifier rule_name,
- AST::DelimType delim_type, std::vector<MacroRule> rules,
- AST::AttrVec outer_attrs, Location locus)
- : MacroItem (std::move (mappings), std::move (outer_attrs)),
- rule_name (std::move (rule_name)), delim_type (delim_type),
- rules (std::move (rules)), locus (locus)
- {}
-
- void accept_vis (HIRVisitor &vis) override;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MacroRulesDefinition *clone_item_impl () const override
- {
- return new MacroRulesDefinition (*this);
- }
-};
-
-/* HIR node of a macro invocation, which is replaced by the macro result at
- * compile time */
-class MacroInvocation : public TypeNoBounds,
- public Pattern,
- public ExprWithoutBlock
-{
- AST::SimplePath path;
- AST::DelimTokenTree token_tree;
- Location locus;
-
-public:
- std::string as_string () const override;
-
- MacroInvocation (Analysis::NodeMapping mappings, AST::SimplePath path,
- AST::DelimTokenTree token_tree, AST::AttrVec outer_attrs,
- Location locus)
- : TypeNoBounds (mappings),
- ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
- path (std::move (path)), token_tree (std::move (token_tree)),
- locus (locus)
- {}
-
- Location get_locus () const { return locus; }
- Location get_locus_slow () const override { return get_locus (); }
-
- void accept_vis (HIRVisitor &vis) override;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MacroInvocation *clone_pattern_impl () const override
- {
- return new MacroInvocation (*this);
- }
-
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MacroInvocation *clone_expr_impl () const override
- {
- return new MacroInvocation (*this);
- }
-
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MacroInvocation *clone_expr_without_block_impl () const override
- {
- return new MacroInvocation (*this);
- }
-
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MacroInvocation *clone_type_impl () const override
- {
- return new MacroInvocation (*this);
- }
-
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MacroInvocation *clone_type_no_bounds_impl () const override
- {
- return new MacroInvocation (*this);
- }
-};
-
-} // namespace HIR
-} // namespace Rust
-
-#endif
diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h
index 7e6752b..2efbbcf 100644
--- a/gcc/rust/hir/tree/rust-hir-visitor.h
+++ b/gcc/rust/hir/tree/rust-hir-visitor.h
@@ -18,42 +18,18 @@
#ifndef RUST_HIR_VISITOR_H
#define RUST_HIR_VISITOR_H
-// Visitor base for HIR
-// full include not required - only forward decls
#include "rust-hir-full-decls.h"
namespace Rust {
namespace HIR {
-/* Pure abstract class that provides an interface for accessing different
- * classes of the HIR. */
+
class HIRVisitor
{
public:
- // only concrete class overloads are required
-
- // rust-ast.h
- // virtual void visit(AttrInput& attr_input) = 0;
- // virtual void visit(TokenTree& token_tree) = 0;
- // virtual void visit(MacroMatch& macro_match) = 0;
- virtual void visit (Token &tok) = 0;
- // virtual void visit (DelimTokenTree &delim_tok_tree) = 0;
- // virtual void visit (AttrInputMetaItemContainer &input) = 0;
- // virtual void visit(MetaItem& meta_item) = 0;
- // virtual void visit(Stmt& stmt) = 0;
- // virtual void visit(Expr& expr) = 0;
virtual void visit (IdentifierExpr &ident_expr) = 0;
- // virtual void visit(Pattern& pattern) = 0;
- // virtual void visit(Type& type) = 0;
- // virtual void visit(TypeParamBound& type_param_bound) = 0;
virtual void visit (Lifetime &lifetime) = 0;
- // virtual void visit(GenericParam& generic_param) = 0;
virtual void visit (LifetimeParam &lifetime_param) = 0;
- // virtual void visit(TraitItem& trait_item) = 0;
- // virtual void visit(InherentImplItem& inherent_impl_item) = 0;
- // virtual void visit(TraitImplItem& trait_impl_item) = 0;
-
- // rust-path.h
virtual void visit (PathInExpression &path) = 0;
virtual void visit (TypePathSegment &segment) = 0;
virtual void visit (TypePathSegmentGeneric &segment) = 0;
@@ -61,12 +37,7 @@ public:
virtual void visit (TypePath &path) = 0;
virtual void visit (QualifiedPathInExpression &path) = 0;
virtual void visit (QualifiedPathInType &path) = 0;
-
- // rust-expr.h
virtual void visit (LiteralExpr &expr) = 0;
- // virtual void visit (AttrInputLiteral &attr_input) = 0;
- // virtual void visit (MetaItemLitExpr &meta_item) = 0;
- // virtual void visit (MetaItemPathLit &meta_item) = 0;
virtual void visit (BorrowExpr &expr) = 0;
virtual void visit (DereferenceExpr &expr) = 0;
virtual void visit (ErrorPropagationExpr &expr) = 0;
@@ -77,7 +48,6 @@ public:
virtual void visit (TypeCastExpr &expr) = 0;
virtual void visit (AssignmentExpr &expr) = 0;
virtual void visit (GroupedExpr &expr) = 0;
- // virtual void visit(ArrayElems& elems) = 0;
virtual void visit (ArrayElemsValues &elems) = 0;
virtual void visit (ArrayElemsCopied &elems) = 0;
virtual void visit (ArrayExpr &expr) = 0;
@@ -85,7 +55,6 @@ public:
virtual void visit (TupleExpr &expr) = 0;
virtual void visit (TupleIndexExpr &expr) = 0;
virtual void visit (StructExprStruct &expr) = 0;
- // virtual void visit(StructExprField& field) = 0;
virtual void visit (StructExprFieldIdentifier &field) = 0;
virtual void visit (StructExprFieldIdentifierValue &field) = 0;
virtual void visit (StructExprFieldIndexValue &field) = 0;
@@ -93,7 +62,6 @@ public:
virtual void visit (StructExprStructBase &expr) = 0;
virtual void visit (StructExprTuple &expr) = 0;
virtual void visit (StructExprUnit &expr) = 0;
- // virtual void visit(EnumExprField& field) = 0;
virtual void visit (EnumExprFieldIdentifier &field) = 0;
virtual void visit (EnumExprFieldIdentifierValue &field) = 0;
virtual void visit (EnumExprFieldIndexValue &field) = 0;
@@ -128,23 +96,16 @@ public:
virtual void visit (IfLetExprConseqElse &expr) = 0;
virtual void visit (IfLetExprConseqIf &expr) = 0;
virtual void visit (IfLetExprConseqIfLet &expr) = 0;
- // virtual void visit(MatchCase& match_case) = 0;
- // virtual void visit (MatchCaseBlockExpr &match_case) = 0;
- // virtual void visit (MatchCaseExpr &match_case) = 0;
virtual void visit (MatchExpr &expr) = 0;
virtual void visit (AwaitExpr &expr) = 0;
virtual void visit (AsyncBlockExpr &expr) = 0;
-
- // rust-item.h
virtual void visit (TypeParam &param) = 0;
- // virtual void visit(WhereClauseItem& item) = 0;
virtual void visit (LifetimeWhereClauseItem &item) = 0;
virtual void visit (TypeBoundWhereClauseItem &item) = 0;
virtual void visit (Method &method) = 0;
virtual void visit (ModuleBodied &module) = 0;
virtual void visit (ModuleNoBody &module) = 0;
virtual void visit (ExternCrate &crate) = 0;
- // virtual void visit(UseTree& use_tree) = 0;
virtual void visit (UseTreeGlob &use_tree) = 0;
virtual void visit (UseTreeList &use_tree) = 0;
virtual void visit (UseTreeRebind &use_tree) = 0;
@@ -168,57 +129,33 @@ public:
virtual void visit (Trait &trait) = 0;
virtual void visit (InherentImpl &impl) = 0;
virtual void visit (TraitImpl &impl) = 0;
- // virtual void visit(ExternalItem& item) = 0;
virtual void visit (ExternalStaticItem &item) = 0;
virtual void visit (ExternalFunctionItem &item) = 0;
virtual void visit (ExternBlock &block) = 0;
-
- // rust-macro.h
- virtual void visit (MacroMatchFragment &match) = 0;
- virtual void visit (MacroMatchRepetition &match) = 0;
- virtual void visit (MacroMatcher &matcher) = 0;
- virtual void visit (MacroRulesDefinition &rules_def) = 0;
- virtual void visit (MacroInvocation &macro_invoc) = 0;
- // virtual void visit (MetaItemPath &meta_item) = 0;
- // virtual void visit (MetaItemSeq &meta_item) = 0;
- // virtual void visit (MetaWord &meta_item) = 0;
- // virtual void visit (MetaNameValueStr &meta_item) = 0;
- // virtual void visit (MetaListPaths &meta_item) = 0;
- // virtual void visit (MetaListNameValueStr &meta_item) = 0;
-
- // rust-pattern.h
virtual void visit (LiteralPattern &pattern) = 0;
virtual void visit (IdentifierPattern &pattern) = 0;
virtual void visit (WildcardPattern &pattern) = 0;
- // virtual void visit(RangePatternBound& bound) = 0;
virtual void visit (RangePatternBoundLiteral &bound) = 0;
virtual void visit (RangePatternBoundPath &bound) = 0;
virtual void visit (RangePatternBoundQualPath &bound) = 0;
virtual void visit (RangePattern &pattern) = 0;
virtual void visit (ReferencePattern &pattern) = 0;
- // virtual void visit(StructPatternField& field) = 0;
virtual void visit (StructPatternFieldTuplePat &field) = 0;
virtual void visit (StructPatternFieldIdentPat &field) = 0;
virtual void visit (StructPatternFieldIdent &field) = 0;
virtual void visit (StructPattern &pattern) = 0;
- // virtual void visit(TupleStructItems& tuple_items) = 0;
virtual void visit (TupleStructItemsNoRange &tuple_items) = 0;
virtual void visit (TupleStructItemsRange &tuple_items) = 0;
virtual void visit (TupleStructPattern &pattern) = 0;
- // virtual void visit(TuplePatternItems& tuple_items) = 0;
virtual void visit (TuplePatternItemsMultiple &tuple_items) = 0;
virtual void visit (TuplePatternItemsRanged &tuple_items) = 0;
virtual void visit (TuplePattern &pattern) = 0;
virtual void visit (GroupedPattern &pattern) = 0;
virtual void visit (SlicePattern &pattern) = 0;
-
- // rust-stmt.h
virtual void visit (EmptyStmt &stmt) = 0;
virtual void visit (LetStmt &stmt) = 0;
virtual void visit (ExprStmtWithoutBlock &stmt) = 0;
virtual void visit (ExprStmtWithBlock &stmt) = 0;
-
- // rust-type.h
virtual void visit (TraitBound &bound) = 0;
virtual void visit (ImplTraitType &type) = 0;
virtual void visit (TraitObjectType &type) = 0;
@@ -233,9 +170,8 @@ public:
virtual void visit (SliceType &type) = 0;
virtual void visit (InferredType &type) = 0;
virtual void visit (BareFunctionType &type) = 0;
-
- // TODO: rust-cond-compilation.h visiting? not currently used
};
+
} // namespace HIR
} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index 0cc9d08..795e8e4 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -37,155 +37,6 @@ class HIRVisitor;
// forward decl for use in token tree method
class Token;
-// A tree of tokens (or a single token) - abstract base class
-class TokenTree
-{
-public:
- virtual ~TokenTree () {}
-
- // Unique pointer custom clone function
- std::unique_ptr<TokenTree> clone_token_tree () const
- {
- return std::unique_ptr<TokenTree> (clone_token_tree_impl ());
- }
-
- virtual std::string as_string () const = 0;
-
- virtual void accept_vis (HIRVisitor &vis) = 0;
-
- /* Converts token tree to a flat token stream. Tokens must be pointer to avoid
- * mutual dependency with Token. */
- virtual std::vector<std::unique_ptr<Token> > to_token_stream () const = 0;
-
-protected:
- // pure virtual clone implementation
- virtual TokenTree *clone_token_tree_impl () const = 0;
-};
-
-// Abstract base class for a macro match
-class MacroMatch
-{
-public:
- virtual ~MacroMatch () {}
-
- virtual std::string as_string () const = 0;
-
- // Unique pointer custom clone function
- std::unique_ptr<MacroMatch> clone_macro_match () const
- {
- return std::unique_ptr<MacroMatch> (clone_macro_match_impl ());
- }
-
- virtual void accept_vis (HIRVisitor &vis) = 0;
-
-protected:
- // pure virtual clone implementation
- virtual MacroMatch *clone_macro_match_impl () const = 0;
-};
-
-// A token is a kind of token tree (except delimiter tokens)
-class Token : public TokenTree, public MacroMatch
-{
- // A token is a kind of token tree (except delimiter tokens)
- // A token is a kind of MacroMatch (except $ and delimiter tokens)
- // TODO: improve member variables - current ones are the same as lexer token
- // Token kind.
- TokenId token_id;
- // Token location.
- Location locus;
- // Associated text (if any) of token.
- std::string str;
- // Token type hint (if any).
- PrimitiveCoreType type_hint;
-
-public:
- // Unique pointer custom clone function
- std::unique_ptr<Token> clone_token () const
- {
- return std::unique_ptr<Token> (clone_token_impl ());
- }
-
- /* constructor from general text - avoid using if lexer const_TokenPtr is
- * available */
- Token (TokenId token_id, Location locus, std::string str,
- PrimitiveCoreType type_hint)
- : token_id (token_id), locus (locus), str (std::move (str)),
- type_hint (type_hint)
- {}
-
- // Constructor from lexer const_TokenPtr
- /* TODO: find workaround for std::string being nullptr - probably have to
- * introduce new method in lexer Token, or maybe make conversion method
- * there */
- Token (const_TokenPtr lexer_token_ptr)
- : token_id (lexer_token_ptr->get_id ()),
- locus (lexer_token_ptr->get_locus ()), str (""),
- type_hint (lexer_token_ptr->get_type_hint ())
- {
- // FIXME: change to "should have str" later?
- if (lexer_token_ptr->has_str ())
- {
- str = lexer_token_ptr->get_str ();
-
- // DEBUG
- rust_debug ("ast token created with str '%s'", str.c_str ());
- }
- else
- {
- // FIXME: is this returning correct thing?
- str = lexer_token_ptr->get_token_description ();
-
- // DEBUG
- rust_debug ("ast token created with string '%s'", str.c_str ());
- }
-
- // DEBUG
- if (lexer_token_ptr->should_have_str () && !lexer_token_ptr->has_str ())
- {
- rust_debug ("BAD: for token '%s', should have string but does not!",
- lexer_token_ptr->get_token_description ());
- }
- }
-
- bool is_string_lit () const
- {
- switch (token_id)
- {
- case STRING_LITERAL:
- case BYTE_STRING_LITERAL:
- return true;
- default:
- return false;
- }
- }
-
- std::string as_string () const override;
-
- void accept_vis (HIRVisitor &vis) override;
-
- // Return copy of itself but in token stream form.
- std::vector<std::unique_ptr<Token> > to_token_stream () const override;
-
- TokenId get_id () const { return token_id; }
-
- Location get_locus () const { return locus; }
-
-protected:
- // No virtual for now as not polymorphic but can be in future
- /*virtual*/ Token *clone_token_impl () const { return new Token (*this); }
-
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- Token *clone_token_tree_impl () const override { return clone_token_impl (); }
-
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- Token *clone_macro_match_impl () const override
- {
- return clone_token_impl ();
- }
-};
-
// A literal - value with a type. Used in LiteralExpr and LiteralPattern.
struct Literal
{
diff --git a/gcc/rust/typecheck/rust-hir-const-fold-base.h b/gcc/rust/typecheck/rust-hir-const-fold-base.h
index 108d372..fce24d9 100644
--- a/gcc/rust/typecheck/rust-hir-const-fold-base.h
+++ b/gcc/rust/typecheck/rust-hir-const-fold-base.h
@@ -35,7 +35,6 @@ class ConstFoldBase : public HIR::HIRVisitor
public:
virtual ~ConstFoldBase () {}
- virtual void visit (HIR::Token &) override {}
virtual void visit (HIR::IdentifierExpr &) override {}
virtual void visit (HIR::Lifetime &) override {}
virtual void visit (HIR::LifetimeParam &) override {}
@@ -154,12 +153,6 @@ public:
virtual void visit (HIR::ExternalFunctionItem &) override {}
virtual void visit (HIR::ExternBlock &) override {}
- virtual void visit (HIR::MacroMatchFragment &) override {}
- virtual void visit (HIR::MacroMatchRepetition &) override {}
- virtual void visit (HIR::MacroMatcher &) override {}
- virtual void visit (HIR::MacroRulesDefinition &) override {}
- virtual void visit (HIR::MacroInvocation &) override {}
-
virtual void visit (HIR::LiteralPattern &) override {}
virtual void visit (HIR::IdentifierPattern &) override {}
virtual void visit (HIR::WildcardPattern &) override {}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h b/gcc/rust/typecheck/rust-hir-type-check-base.h
index a0ec0a0..3b2853c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.h
@@ -34,7 +34,6 @@ class TypeCheckBase : public HIR::HIRVisitor
public:
virtual ~TypeCheckBase () {}
- virtual void visit (HIR::Token &) override {}
virtual void visit (HIR::IdentifierExpr &) override {}
virtual void visit (HIR::Lifetime &) override {}
virtual void visit (HIR::LifetimeParam &) override {}
@@ -153,12 +152,6 @@ public:
virtual void visit (HIR::ExternalFunctionItem &) override {}
virtual void visit (HIR::ExternBlock &) override {}
- virtual void visit (HIR::MacroMatchFragment &) override {}
- virtual void visit (HIR::MacroMatchRepetition &) override {}
- virtual void visit (HIR::MacroMatcher &) override {}
- virtual void visit (HIR::MacroRulesDefinition &) override {}
- virtual void visit (HIR::MacroInvocation &) override {}
-
virtual void visit (HIR::LiteralPattern &) override {}
virtual void visit (HIR::IdentifierPattern &) override {}
virtual void visit (HIR::WildcardPattern &) override {}