Age | Commit message (Collapse) | Author | Files | Lines |
|
Add a first draft for derive proc macros based on the attribute expander
code. Convert the result back to a parsable entity and parse it.
The procedural macro expander was beginning to require almost all
functionalities already provided by the macro expander, hence the merge.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.h: Update enum name to match
definition.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_derive):
Add call to expander.
(ExpandVisitor::expand_outer_attribute):
Change call to macro expander.
(ExpandVisitor::expand_inner_attribute): Likewise.
* expand/rust-expand-visitor.h: Remove const attribute to match
visitor declaration. Attach result to the AST. Add condition for
item erasure.
* expand/rust-proc-macro.h: Add token collector and expansion
call. Add lexers and parsers for each proc macro type and uses
them to parse macro output.
* expand/rust-macro-expand.h (struct MacroExpander): Add
functions.
* expand/rust-proc-macro.cc (ProcMacroExpander::import_proc_macros):
Moved from here...
* expand/rust-macro-expand.cc (MacroExpander::import_proc_macros):
... to here. Unify procedural macro parsing under one function.
Add a flag to determine whether it originate from a derive
macro.
(MacroExpander::parse_procmacro_output):
Parse macro output to statements. Store an error on parsing
failure.
* Make-lang.in: Add const_TokenPtr specific lexer.
* expand/rust-proc-macro-invoc-lexer.cc: New file.
* expand/rust-proc-macro-invoc-lexer.h: New file.
* rust-session-manager.cc (Session::expansion): Remove
ProcMacroExpander declaration.
* ast/rust-ast-fragment.cc (Fragment::Fragment): Add overwrite
flag.
(Fragment::should_overwrite): Add a getter to determine whether
the fragment shall overwrite it's parent or be appended after.
* ast/rust-ast-fragment.h: Add flag to declaration.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Items attribute were not correctly collected and thus could not be
expanded from a previous macro invocation.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Fix
attribute collection.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Make all trivial visitor functions public so we could easily call the
collection of an ast's subtree from any node.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.h: Make trivial visitors public.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Move implementation from cc file to header, in order to allow call from
other headers and prevent linker errors.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Move
implementation from here...
* ast/rust-ast-collector.h: ... to here.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
gcc/rust/ChangeLog:
* Make-lang.in: Add "rust-dir-owner.o".
* ast/rust-ast.cc: Include "rust-dir-owner.h".
(Module::process_file_path):
Handle non-mod-rs external file modules properly.
* parse/rust-parse-impl.h: Include "rust-dir-owner.h".
(Parser::parse_module):
Handle non-mod-rs external file modules properly.
* util/rust-dir-owner.cc: New file.
* util/rust-dir-owner.h: New file.
gcc/testsuite/ChangeLog:
* rust/compile/test_mod.rs: Moved to...
* rust/compile/issue-1089/test_mod.rs: ...here.
* rust/compile/mod_missing_middle.rs: Fix paths.
* rust/compile/missing_middle/both_path.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/both_path.rs: ...here.
* rust/compile/missing_middle/explicit.not.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/explicit.not.rs: ...here.
* rust/compile/missing_middle/other.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/explicit.not/other.rs: ...here.
* rust/compile/missing_middle/inner_path.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/inner_path.rs: ...here.
* rust/compile/missing_middle/outer_path.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/outer_path.rs: ...here.
* rust/compile/missing_middle/sub/mod.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/sub/mod.rs: ...here.
* rust/compile/torture/modules/mod.rs: Moved to...
* rust/compile/torture/extern_mod1/modules/mod.rs: ...here.
* rust/execute/torture/modules/mod.rs: Moved to...
* rust/execute/torture/extern_mod4/modules/mod.rs: ...here.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
|
|
This commit fixes printing of literals based on their
type.
Previous implementation printed literals the same, regardless
their type. Now we are printing:
* int, float, bool don't require special printing
* char -> '<char>'
* string -> "<string>"
* byte -> b'<byte>'
* byte_string -> b"<byte_string>"
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit):
print literals based on their type.
Signed-off-by: Charalampos Mitrodimas <charmitro@gmail.com>
|
|
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (AstBuilder::struct_expr_struct): New function.
(AstBuilder::let): Likewise.
(AstBuilder::struct_expr): Likewise.
(AstBuilder::struct_expr_field): Likewise.
(AstBuilder::field_access): Likewise.
(AstBuilder::wildcard): Likewise.
* ast/rust-ast-builder.h: Likewise.
* expand/rust-derive-clone.cc (DeriveClone::visit_union): Implement
properly.
gcc/testsuite/ChangeLog:
* rust/compile/derive_macro4.rs: New test.
* rust/compile/derive_macro6.rs: New test.
|
|
gcc/rust/ChangeLog:
* expand/rust-derive-clone.cc (DeriveClone::visit_struct): Implement proper
cloning for structs with fields.
* ast/rust-ast-builder.cc (AstBuilder::struct_expr): New function.
(AstBuilder::struct_expr_field): Likewise.
(AstBuilder::field_access): Likewise.
(AstBuilder::let): Likewise.
* ast/rust-ast-builder.h: Declare new functions.
gcc/testsuite/ChangeLog:
* rust/execute/torture/derive_macro4.rs: New test.
|
|
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc: New file.
* ast/rust-ast-builder.h: New file.
|
|
In #[cfg_attr(A, B, C(D))], only A is a predicate.
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Attribute::check_cfg_predicate):
Only check first item as a predicate.
gcc/testsuite/ChangeLog:
* rust/compile/cfg-attr.rs: New test.
Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
|
|
Propagate back type suffix to created tokens.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Propagate
coretype hint.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add `outer_attrs` to Item.
* ast/rust-expr.h: Make use of new inheritance methods.
* ast/rust-item.h: Likewise.
* ast/rust-macro.h: Likewise.
|
|
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc
(Dump::visit): Add AttrInputMacro visitor.
* ast/rust-ast-dump.h:
(Dump::visit): Likewise.
* ast/rust-ast-full-decls.h
(class AttrInputMacro): New.
* ast/rust-ast-collector.cc
(TokenCollector::visit):
Add and call out to AttrInputMacro visitor.
* ast/rust-ast-collector.h:
(TokenCollector::visit): Add AttrInputMacro visitor.
* ast/rust-ast-visitor.h:
(ASTVisitor::visit): Likewise.
* ast/rust-ast.cc
(AttrInputMacro::accept_vis): New.
(AttrInputMacro::as_string): New.
(AttrInputMacro::AttrInputMacro): New.
(AttrInputMacro::operator=): New.
* ast/rust-ast.h:
(AttrInput::AttrInputType::MACRO): New.
* ast/rust-expr.h
(class AttrInputMacro): New.
* checks/errors/rust-feature-gate.h:
(FeatureGate::visit): Add AttrInputMacro visitor.
* expand/rust-cfg-strip.cc
(CfgStrip::visit): Likewise.
* expand/rust-cfg-strip.h:
(CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h:
(ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h:
(ASTLoweringBase::visit): Likewise.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h:
(ResolverBase::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h:
(EarlyNameResolver::visit): Likewise.
* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
(check_doc_attribute): Handle AttrInputType::MACRO.
* util/rust-attributes.h:
(AttributeChecker::visit): Add AttrInputMacro visitor.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
|
|
gcc/rust/ChangeLog:
* ast/rust-macro.h
(MacroInvocation::clone_macro_invocation_impl): Make public.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
|
|
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Implement dump for
`TupleIndexExpr`.
|
|
`{ ... }.f;` is parsed as a single statement in rust. This means that we can't
determine whether an expression statement will need a semicolon terminator
until we finish parsing it. To handle this we change expression parsing to
check for this case by inspecting the expression returned from null_denotation
and looking ahead for a `.` or `?` token.
gcc/rust/ChangeLog:
* ast/rust-ast.h (Expr::as_expr_without_block): Remove.
(Expr::set_outer_attrs): Make public in base class.
* expand/rust-macro-expand.cc:
Add fixme comment for pre-existing bug.
* hir/tree/rust-hir.h: Remove Expr::as_expr_without_block.
* parse/rust-parse-impl.h (Parser::parse_lifetime): Use lifetime_from_token.
(Parser::lifetime_from_token): New method.
(Parser::null_denotation): Handle labelled loop expressions and for loop expressions.
(Parser::parse_loop_label): Make initial token a parameter.
(Parser::parse_labelled_loop_expr): Likewise.
(Parser::parse_for_loop_expr): Allow FOR token to already be skipped.
(Parser::parse_expr): Handle expr_can_be_stmt.
(Parser::parse_expr_with_block): Remove.
(Parser::parse_expr_stmt_with_block): Remove.
(Parser::parse_expr_stmt_without_block): Remove.
(Parser::parse_expr_without_block): Remove.
(Parser::parse_stmt_or_expr_with_block): Remove.
(Parser::parse_expr_stmt): Use parse_expr directly.
(Parser::parse_match_expr): Likewise.
(Parser::parse_stmt): Use parse_expr_stmt in more cases.
(Parser::parse_stmt_or_expr):
Rename from parse_stmt_or_expr_without_block, use parse_expr directly.
(Parser::parse_block_expr): Update error message.
* parse/rust-parse.h: Update declarations.
gcc/testsuite/ChangeLog:
* rust/compile/for_expr.rs: New test.
* rust/compile/issue-407-2.rs: Update compiler output.
* rust/compile/issue-407.rs: Update compiler output.
* rust/compile/issue-867.rs: Update compiler output.
* rust/compile/issue-2189.rs: New test.
* rust/compile/macro_call_statement.rs: New test.
* rust/compile/stmt_with_block_dot.rs: New test.
* rust/compile/torture/loop8.rs: New test.
Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
|
|
This distinction isn't very helpful and makes correct parsing harder.
gcc/rust/ChangeLog:
* ast/rust-ast-full-decls.h (class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
* ast/rust-stmt.h (class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
(class ExprStmt):
Make non-abstract, add common functionality from removed base classes.
* ast/rust-ast.h: Move to_stmt to base class.
* ast/rust-ast.cc (ExprStmtWithBlock::as_string): Remove.
* ast/rust-macro.h: Use new signature for to_stmt.
(ExprStmt::as_string): New method.
(ExprStmtWithoutBlock::as_string): Remove.
(BlockExpr::strip_tail_expr): Update for removed classes.
(ExprStmtWithoutBlock::accept_vis): Remove.
(ExprStmtWithBlock::accept_vis): Remove.
(ExprStmt::accept_vis): New method.
* ast/rust-ast-dump.cc (Dump::visit): Update for removed classes.
* ast/rust-ast-dump.h: Likewise.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-collector.cc (TokenStream::visit): Likewise.
* ast/rust-ast-visitor.h: Likewise.
* checks/errors/rust-feature-gate.h: Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h: Likewise.
* expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
* expand/rust-cfg-strip.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Likewise.
* hir/rust-ast-lower-stmt.h: Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
* util/rust-attributes.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Likewise.
* resolve/rust-early-name-resolver.h: Likewise.
* parse/rust-parse-impl.h (Parser::parse_match_expr): Likewise.
(Parser::parse_stmt_or_expr_without_block): Likewise.
* parse/rust-parse.h: Likewise.
Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
|
|
Move the token vector to tokenstream converter out of the TokenCollector
class. This code is not exactly related to the token collection and the
code would be clearer with this rather lengthy conversion split on it's
own.
gcc/rust/ChangeLog:
* Make-lang.in: Add new rust-token-converter file.
* ast/rust-ast-collector.cc (pop_group): Function moved from
TokenCollector.
(dispatch_float_literals): Likewise.
(dispatch_integer_literals): Likewise.
(TokenCollector::collect): Removed function.
* ast/rust-ast-collector.h: Removed function prototype.
* util/rust-token-converter.cc: New file.
* util/rust-token-converter.h: New file.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
The header guard did not match the file name anymore.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.h (RUST_AST_TOKENSTREAM_H): Rename
headerguard from RUST_AST_TOKENSTREAM_H ...
(RUST_AST_COLLECTOR_H): ... to RUST_AST_COLLECTOR_H.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
The file does not contain any TokenStream declaration anymore and thus
should be named more appropriately.
gcc/rust/ChangeLog:
* Make-lang.in: Change file name.
* ast/rust-ast-tokenstream.cc: Moved to...
* ast/rust-ast-collector.cc: ...here.
* ast/rust-ast-tokenstream.h: Moved to...
* ast/rust-ast-collector.h: ...here.
* rust-session-manager.cc: Change header name.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Rename the TokenStream class to TokenCollector as it may induce errors
in the future as it is not a tokenstream as defined by the rust
interface. Furthermore this change match more closely the actual behavior
of the class.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::TokenStream): Rename
TokenStream to TokenCollector.
(TokenCollector::TokenCollector): Likewise.
(TokenStream::collect_tokens): Likewise.
(TokenCollector::collect_tokens): Likewise.
(TokenStream::collect): Likewise.
(TokenCollector::collect): Likewise.
(TokenStream::visit): Likewise.
(TokenCollector::visit): Likewise.
(TokenStream::visit_items_joined_by_separator): Likewise.
(TokenCollector::visit_items_joined_by_separator): Likewise.
(TokenStream::visit_as_line): Likewise.
(TokenCollector::visit_as_line): Likewise.
(TokenStream::visit_items_as_lines): Likewise.
(TokenCollector::visit_items_as_lines): Likewise.
(TokenStream::visit_items_as_block): Likewise.
(TokenCollector::visit_items_as_block): Likewise.
(TokenStream::trailing_comma): Likewise.
(TokenCollector::trailing_comma): Likewise.
(TokenStream::newline): Likewise.
(TokenCollector::newline): Likewise.
(TokenStream::indentation): Likewise.
(TokenCollector::indentation): Likewise.
(TokenStream::increment_indentation): Likewise.
(TokenCollector::increment_indentation): Likewise.
(TokenStream::decrement_indentation): Likewise.
(TokenCollector::decrement_indentation): Likewise.
(TokenStream::visit_closure_common): Likewise.
(TokenCollector::visit_closure_common): Likewise.
(TokenStream::visit_loop_common): Likewise.
(TokenCollector::visit_loop_common): Likewise.
(TokenStream::visit_function_common): Likewise.
(TokenCollector::visit_function_common): Likewise.
* ast/rust-ast-tokenstream.h (class TokenStream): Likewise.
(class TokenCollector): Likewise.
* rust-session-manager.cc (Session::dump_tokenstream): Rename
token vector for clearer intent.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Add the conversion handler for float/double literal tokens to
tokenstream Literals.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (dispatch_float_literals): Add
dispatch function for floating point literals.
(TokenStream::collect): Add call to dispatcher.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Add a first draft for the literal integer conversion to tokenstream
Literal types.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (dispatch_integer_literals):
Add a static function to dispatch depending on the core type.
(TokenStream::collect): Add call to dispatch function.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Add conversion to tokenstream Literals for string and byte strings.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::collect): Add
conversion for byte string and string.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Add conversion from a rust token to tokenstream Idents.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::collect): Add Ident
conversion.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Add the conversion from tokens to punct structures in tokenstream
conversion function.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::collect): Add joint
punct token conversion.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Add the code to convert single punctuation tokens to a tokenstream
element.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::collect): Add
conversion for single punctuation tokens.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Add conversion for group delimiters.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (pop_group): Add a function to
easily collect a group from a given stack at the end of it.
(TokenStream::collect): Collect tokens as a rust compatible
Tokenstream type.
* ast/rust-ast-tokenstream.h (RUST_AST_TOKENSTREAM_H): Move
includes to stay constrained by guards.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Fixes Issue #1568
Added HIR node HIR::InlineAsm similar to the one found in rustc. In this
I also changed the defination of the AST::InlineAsm node, so that we can
reuse many of it's data members in the HIR::InlineAsm node.
gcc/rust/ChangeLog:
* ast/rust-ast-full-decls.h (enum class): Added declaration.
(struct AnonConst): Added declaration.
(struct InlineAsmRegOrRegClass): Added declaration.
(struct InlineAsmOperand): Added declaration.
(struct InlineAsmPlaceHolder): Added declaration.
(struct InlineAsmTemplatePiece): Added declaration.
(struct TupleClobber): Added declaration.
(struct TupleTemplateStr): Added declaration.
* ast/rust-expr.h (class InlineAsm): Defined all it's data members outside.
(enum class InlineAsmOptions): Converted this to a enum class so we could use it in the HIR.
(struct AnonConst): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmRegOrRegClass): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmOperand): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmPlaceHolder): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmTemplatePiece): Defined it independent of the AST::InlineAsm node.
(struct TupleClobber): Defined it independent of the AST::InlineAsm node.
(struct TupleTemplateStr): Defined it independent of the AST::InlineAsm node.
* hir/tree/rust-hir-expr.h (class InlineAsmReg): Added defination.
(class InlineAsmRegClass): Added defination.
(struct InlineAsmRegOrRegClass): Added defination.
(class InlineAsm): Added defination.
* hir/tree/rust-hir-full-decls.h (class InlineAsmReg): Added declaration.
(class InlineAsmRegClass): Added declaration.
(struct InlineAsmRegOrRegClass): Added declaration.
(class InlineAsm): Added declaration.
Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
|
|
gcc/rust/ChangeLog:
* ast/rust-ast.h (class AttrInputMetaItemContainer): Run clang-format.
(class DelimTokenTree): Likewise.
|
|
Both the AST::Crate and AST::Module class are std::unique_ptr<AST::Item>
containers, and may require spurious insertions in these containers,
for example when expanding a procedural macro, or in our case, escaping
macros through the #[macro_use] attribute. These functions allow you
to replace *all* of the items contained in such a container.
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add take_items() and set_items() method to Crate.
* ast/rust-item.h: Add take_items() and set_items() method to Module.
|
|
gcc/rust/ChangeLog:
* ast/rust-ast.h (enum Kind): Add MODULE variant.
* ast/rust-item.h: Return Kind::MODULE in AST::Module::get_kind().
|
|
This commit regroups information related to builtin macros in one place instead
of spreading it over multiple files. It also adds a simple bi-directional
hashmap in order to perform lookups from a key as well as a value.
gcc/rust/ChangeLog:
* ast/rust-macro.cc (builtin_macro_from_string): Move function.
* ast/rust-macro.h (enum class): Move enum.
(builtin_macro_from_string): Move function.
* expand/rust-macro-builtins.cc (builtin_macro_from_string): New function.
(make_macro_path_str): Use new bi-map.
(parse_single_string_literal): Use new `BuiltinMacro` enum.
(MacroBuiltin::include_bytes_handler): Likewise.
(MacroBuiltin::include_str_handler): Likewise.
(MacroBuiltin::compile_error_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::include_handler): Likewise.
(MacroBuiltin::sorry): New function.
* expand/rust-macro-builtins.h (enum class): Move enum here.
(builtin_macro_from_string): New function declaration.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Use
new function.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Remove old
builtin macro map.
|
|
gcc/rust/ChangeLog:
* ast/rust-ast.cc
(BlockExpr::strip_tail_expr):
Try to take new tail expression from statements list.
* ast/rust-expr.h
(BlockExpr::strip_tail_expr):
Replace definition with only declaration.
gcc/testsuite/ChangeLog:
* rust/execute/torture/cfg-tail.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
|
|
gcc/rust/ChangeLog:
* ast/rust-ast.h
(Stmt::is_expr): New.
* ast/rust-stmt.h
(ExprStmt::is_expr): New.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
|
|
Use parentheses to remove any ambiguities when dumping expressions with
unary ! and -.
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): print parentheses around
unique expression operand.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
|
|
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc: fix bad formatting for associated type.
Signed-off-by: Zheyuan Chen <sephirotheca17@gmail.com>
|
|
Qualified types had a simple colon output instead of full scope
resolution tokens in QualifiedPathInTypes.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix scope
resolution token output.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
The associated type was not kept in the tokenstream.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::visit): Keep
associated type.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
Function body were skipped in tokenstream when no return type was
provided.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::visit_function_common):
Fix function body output.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
...and return it from IdentifierExpr::get_ast_kind (). This enables
other code to dynamically test whether an expression is in fact an
IdentifierExpr.
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add AST::Kind::IDENTIFIER
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
|
|
We're going to introduce AST::Kind::IDENTIFIER next, and with the
default C-style enum member scoping, this would cause name clashes.
Instead, convert AST::Kind into an enum class, so that its members
are properly namespaced.
gcc/rust/ChangeLog:
* ast/rust-ast.h (Kind): Convert into a C++ enum class
* expand/rust-macro-builtins.cc: Adapt to the change
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
|
|
This simplifies the AST's representation of if-let-statements
to match the HIR.
gcc/rust/ChangeLog:
* ast/rust-expr.h
(class IfLetExprConseqElse): Make else_block ExprWithBlock.
(class IfLetExprConseqIf): Remove.
(class IfLetExprConseqIfLet): Remove.
* ast/rust-ast-full-decls.h
(class IfLetExprConseqIf): Remove.
(class IfLetExprConseqIfLet): Remove.
* ast/rust-ast.cc
(IfLetExprConseqElse::as_string): Adjust output.
(IfLetExprConseqIf::as_string): Remove.
(IfLetExprConseqIfLet::as_string): Remove.
(IfLetExprConseqIf::accept_vis): Remove.
(IfLetExprConseqIfLet::accept_vis): Remove.
* ast/rust-ast-visitor.h
(ASTVisitor::visit): Remove IfLetExprConseqIf{,Let} visitors.
* ast/rust-ast-dump.cc
(Dump::visit): Likewise.
* ast/rust-ast-dump.h:
(Dump::visit): Likewise.
* ast/rust-ast-tokenstream.cc
(TokenStream::visit): Likewise.
* ast/rust-ast-tokenstream.h
(TokenStream::visit): Likewise.
* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h:
(AttributeChecker::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h
(EarlyNameResolver::visit): Likewise.
* resolve/rust-ast-resolve-base.h
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Likewise.
* checks/errors/rust-feature-gate.h
(FeatureGate::visit): Likewise.
* expand/rust-cfg-strip.cc
(CfgStrip::visit): Likewise.
* expand/rust-cfg-strip.h:
(CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h
(ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h:
(ASTLoweringBase::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_if_let_expr): Replace IfLetExprConseqIf{,Let} with IfLetExprConseqElse.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
|
|
StructExprStructFields inherit from StructExprStruct and shall output
the struct name and curly braces.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add struct
name and curly braces to output tokenstream.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
This simplifies the AST's representation of if-statements
to match the HIR.
gcc/rust/ChangeLog:
* ast/rust-expr.h
(class IfExprConseqElse): Make else_block ExprWithBlock.
(class IfExprConseqIf): Remove.
(class IfExprConseqIfLet): Remove.
* ast/rust-ast-full-decls.h
(class IfExprConseqIf): Remove.
(class IfExprConseqIfLet): Remove.
* ast/rust-ast.cc
(IfExprConseqElse::as_string): Adjust output.
(IfExprConseqIf::as_string): Remove.
(IfExprConseqIfLet::as_string): Remove.
(IfExprConseqIf::accept_vis): Remove.
(IfExprConseqIfLet::accept_vis): Remove.
* ast/rust-ast-visitor.h
(ASTVisitor::visit): Remove IfExprConseqIf{,Let} visitors.
* ast/rust-ast-tokenstream.cc
(TokenStream::visit): Likewise.
* ast/rust-ast-tokenstream.h
(TokenStream::visit): Likewise.
* ast/rust-ast-dump.cc
(Dump::visit): Likewise.
* ast/rust-ast-dump.h
(Dump::visit): Likewise.
* checks/errors/rust-feature-gate.h
(FeatureGate::visit): Likewise.
* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h
(AttributeChecker::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h
(EarlyNameResolver::visit): Likewise.
* resolve/rust-ast-resolve-base.h
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-expr.h
(ResolveExpr::visit): Remove IfExprConseqIf visitor.
* resolve/rust-ast-resolve-expr.cc
(ResolveExpr::visit): Likewise.
* expand/rust-cfg-strip.cc
(CfgStrip::visit): Remove IfExprConseqIf{,Let} visitors.
* expand/rust-cfg-strip.h
(CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h
(ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-block.h
(ASTLoweringIfBlock::visit): Remove IfExprConseqIf visitor.
(ASTLoweringExprWithBlock::visit): Likewise.
* hir/rust-ast-lower.cc
(ASTLoweringIfBlock::visit):
Remove IfExprConseqIf visitor, adjust IfExprConseqElse lowering.
* hir/rust-ast-lower-expr.h
(ASTLoweringExpr::visit): Remove IfExprConseqIf visitor.
* hir/rust-ast-lower-expr.cc
(ASTLoweringExpr::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_if_expr): Replace IfExprConseqIf{,Let} with IfExprConseqElse.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
|
|
Inner attribute did not output exclamation tokens as there was no way to
differentiate inner from outer attributes previously.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix inner
attribute tokenstream output.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
AST::Visitable is an abstract class with a unique accept_vis() method.
Make all abstract AST node class inherit from this class.
Allows for easy definition of operations on nodes that must accept a
visitor.
The static Dump::dump() is an example of such use: the static method
accepts any AST node, creates a Dump visitor and have it visit the AST
starting at the node.
This change also inserts a debug(Visitable&) function in the global
namespace to make it easy to call from the debugger (similar to
debug_tree or debug(rtx*) functions).
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::debug): New.
* ast/rust-ast-dump.h (Dump::debug): Untemplate it.
(debug): New.
* ast/rust-ast.h (class Visitable): New.
(class TokenTree): Inherit from Visitable.
(class MacroMatch): Likewise.
(class AttrInput): Likewise.
(class MetaItemInner): Likewise.
(class Pattern): Likewise.
(classTypeParamBound): Likewise.
(class GenericParam): Likewise.
(class TraitItem): Likewise.
(classInherentImplItem): Likewise.
(class TraitImplItem): Likewise.
(class ExternalItem): Likewise.
(class SingleASTNode): Likewise.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
|
|
Add a boolean to tell inner and outer attributes ast nodes appart. This
meant refactoring a bit their parsing function.
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add boolean for differenciation.
* parse/rust-parse-impl.h (Parser::parse_doc_comment): Change
function interface to make code cleaner. It should return a body
instead of the whole attribute.
(Parser::parse_inner_attribute): Specify the inner status of the
node.
(Parser::parse_attribute_body): Change function interface to
make the code cleaner much like parse_doc_comment.
(Parser::parse_outer_attribute): Specify outer status of the
node.
* parse/rust-parse.h: Update functions prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
We need to retrieve outer attributes from some Expressions depending on
their context. This means this should be retrieved from their parent
node. But expr did not have a getter for outer attributes since some
expr can't have any outer attribute.
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add getter to Expr class.
* ast/rust-expr.h: Add override attribute to existing getters.
Also implement it for RangeExpr, attempting to retrieve outer
attributes on those types will crash the compiler.
* ast/rust-macro.h: Add override attribute to existing getters.
* ast/rust-path.h: Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|
|
The path should be retrieved only when a generic arg has either type.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix ICE.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
|