Skip to content

Commit

Permalink
Merge branch 'Rust-GCC:master' into macro_export_checker
Browse files Browse the repository at this point in the history
  • Loading branch information
saeitoshi-10 authored Jan 13, 2025
2 parents 4bbad83 + bb58003 commit aec9efa
Show file tree
Hide file tree
Showing 75 changed files with 1,513 additions and 818 deletions.
1 change: 1 addition & 0 deletions gcc/rust/Make-lang.in
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ GRS_OBJS = \
rust/rust-ast-resolve-path.o \
rust/rust-ast-resolve-stmt.o \
rust/rust-ast-resolve-struct-expr-field.o \
rust/rust-forever-stack.o \
rust/rust-hir-type-check.o \
rust/rust-privacy-check.o \
rust/rust-privacy-ctx.o \
Expand Down
23 changes: 0 additions & 23 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,29 +250,6 @@ TokenCollector::visit (Visibility &vis)
}
}

void
TokenCollector::visit (NamedFunctionParam &param)
{
auto name = param.get_name ();
if (!param.is_variadic ())
{
push (
Rust::Token::make_identifier (param.get_locus (), std::move (name)));
push (Rust::Token::make (COLON, UNDEF_LOCATION));
visit (param.get_type ());
}
else
{
if (name != "")
{
push (Rust::Token::make_identifier (param.get_locus (),
std::move (name)));
push (Rust::Token::make (COLON, UNDEF_LOCATION));
}
push (Rust::Token::make (ELLIPSIS, UNDEF_LOCATION));
}
}

void
TokenCollector::visit (std::vector<std::unique_ptr<GenericParam>> &params)
{
Expand Down
1 change: 0 additions & 1 deletion gcc/rust/ast/rust-ast-collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ class TokenCollector : public ASTVisitor
void visit (TupleField &field);
void visit (StructField &field);
void visit (SimplePathSegment &segment);
void visit (NamedFunctionParam &param);
void visit (MacroRule &rule);
void visit (WhereClause &rule);
void visit (std::vector<LifetimeParam> &for_lifetimes);
Expand Down
1 change: 0 additions & 1 deletion gcc/rust/ast/rust-ast-full-decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ class TraitImpl;
class ExternalItem;
class ExternalTypeItem;
class ExternalStaticItem;
class NamedFunctionParam;
class ExternBlock;

// rust-macro.h
Expand Down
9 changes: 1 addition & 8 deletions gcc/rust/ast/rust-ast-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ DefaultASTVisitor::visit (AST::TraitImpl &impl)
if (impl.has_where_clause ())
visit (impl.get_where_clause ());
visit (impl.get_type ());
visit (impl.get_trait_path ());
visit_inner_attrs (impl);
for (auto &item : impl.get_impl_items ())
visit (item);
Expand All @@ -1059,14 +1060,6 @@ DefaultASTVisitor::visit (AST::ExternalStaticItem &item)
visit (item.get_type ());
}

void
DefaultASTVisitor::visit (AST::NamedFunctionParam &param)
{
visit_outer_attrs (param);
if (!param.is_variadic ())
visit (param.get_type ());
}

void
DefaultASTVisitor::visit (AST::ExternBlock &block)
{
Expand Down
1 change: 0 additions & 1 deletion gcc/rust/ast/rust-ast-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ class DefaultASTVisitor : public ASTVisitor
virtual void visit (AST::WhereClause &where);
virtual void visit (AST::StructField &field);
virtual void visit (AST::TupleField &field);
virtual void visit (AST::NamedFunctionParam &param);
virtual void visit (AST::MacroRule &rule);
virtual void visit (AST::MacroInvocData &data);
virtual void visit (AST::MacroTranscriber &transcriber);
Expand Down
16 changes: 0 additions & 16 deletions gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2997,22 +2997,6 @@ ExternalStaticItem::as_string () const
return str;
}

std::string
NamedFunctionParam::as_string () const
{
std::string str = append_attributes (outer_attrs, OUTER);

if (has_name ())
str += "\n" + name;

if (is_variadic ())
str += "...";
else
str += "\n Type: " + param_type->as_string ();

return str;
}

std::string
TraitItemConst::as_string () const
{
Expand Down
94 changes: 66 additions & 28 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,13 @@ namespace AST {
class ASTVisitor;
using AttrVec = std::vector<Attribute>;

// The available kinds of AST Nodes
enum class Kind
{
UNKNOWN,
MODULE,
MACRO_RULES_DEFINITION,
MACRO_INVOCATION,
IDENTIFIER,
};

class Visitable
{
public:
virtual ~Visitable () = default;
virtual void accept_vis (ASTVisitor &vis) = 0;
};

// Abstract base class for all AST elements
class Node : public Visitable
{
public:
/**
* Get the kind of Node this is. This is used to differentiate various AST
* elements with very little overhead when extracting the derived type
* through static casting is not necessary.
*/
// FIXME: Mark this as `= 0` in the future to make sure every node
// implements it
virtual Kind get_ast_kind () const { return Kind::UNKNOWN; }
};

// Delimiter types - used in macros and whatever.
enum DelimType
{
Expand Down Expand Up @@ -1092,7 +1068,7 @@ class MetaListNameValueStr;
/* Base statement abstract class. Note that most "statements" are not allowed
* in top-level module scope - only a subclass of statements called "items"
* are. */
class Stmt : public Node
class Stmt : public Visitable
{
public:
enum class Kind
Expand Down Expand Up @@ -1141,6 +1117,28 @@ class Stmt : public Node
class Item : public Stmt
{
public:
enum class Kind
{
MacroRulesDefinition,
MacroInvocation,
Module,
ExternCrate,
UseDeclaration,
Function,
TypeAlias,
Struct,
EnumItem,
Enum,
Union,
ConstantItem,
StaticItem,
Trait,
Impl,
ExternBlock,
};

virtual Kind get_item_kind () const = 0;

// Unique pointer custom clone function
std::unique_ptr<Item> clone_item () const
{
Expand Down Expand Up @@ -1221,14 +1219,54 @@ class VisItem : public Item
{
return outer_attrs;
}

virtual Item::Kind get_item_kind () const override = 0;
};

// forward decl of ExprWithoutBlock
class ExprWithoutBlock;

// Base expression AST node - abstract
class Expr : public Node
class Expr : public Visitable
{
public:
enum class Kind
{
PathInExpression,
QualifiedPathInExpression,
Literal,
Operator,
Grouped,
Array,
ArrayIndex,
Tuple,
TupleIndex,
Struct,
Call,
MethodCall,
FieldAccess,
Closure,
Block,
Continue,
Break,
Range,
Box,
Return,
UnsafeBlock,
Loop,
If,
IfLet,
Match,
Await,
AsyncBlock,
InlineAsm,
Identifier,
FormatArgs,
MacroInvocation,
};

virtual Kind get_expr_kind () const = 0;

// Unique pointer custom clone function
std::unique_ptr<Expr> clone_expr () const
{
Expand Down Expand Up @@ -1343,7 +1381,7 @@ class IdentifierExpr : public ExprWithoutBlock
outer_attrs = std::move (new_attrs);
}

Kind get_ast_kind () const override { return Kind::IDENTIFIER; }
Expr::Kind get_expr_kind () const override { return Expr::Kind::Identifier; }

protected:
// Clone method implementation
Expand Down Expand Up @@ -1410,7 +1448,7 @@ class Pattern : public Visitable
class TraitBound;

// Base class for types as represented in AST - abstract
class Type : public Node
class Type : public Visitable
{
public:
// Unique pointer custom clone function
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/ast/rust-builtin-ast-nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ class FormatArgs : public Expr
const FormatArguments &get_arguments () const { return arguments; }
virtual location_t get_locus () const override;

Expr::Kind get_expr_kind () const override { return Expr::Kind::FormatArgs; }

private:
location_t loc;
// FIXME: This probably needs to be a separate type - it is one in rustc's
Expand Down
Loading

0 comments on commit aec9efa

Please sign in to comment.