public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Merge #1287
@ 2022-06-08 12:51 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0866a4fbc6e7f70cd3708467419c60af8c6104f2

commit 0866a4fbc6e7f70cd3708467419c60af8c6104f2
Merge: 998f1f73c26 573b6298596
Author: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Date:   Wed Jun 1 10:44:16 2022 +0000

    Merge #1287
    
    1287: Add AST dump visitor r=CohenArthur a=CohenArthur
    
    This adds a base for pretty printing our AST through a new visitor (Addresses #1261).
    
    This adds enough code to pretty print "functions" without types in the parameters or return type. Looking for feedback on the implementation before we keep going with more code :)
    
    Here's a tiny patch if you want to see the output whenever you're running `-frust-dump-all`:
    
    ```diff
    diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
    index 0b0e5af915f..3e39c6a6e17 100644
    --- a/gcc/rust/rust-session-manager.cc
    +++ b/gcc/rust/rust-session-manager.cc
    `@@` -31,6 +31,7 `@@`
     #include "rust-cfg-parser.h"
     #include "rust-lint-scan-deadcode.h"
     #include "rust-lint-unused-var.h"
    +#include "rust-ast-dump.h"
    
     #include "diagnostic.h"
     #include "input.h"
    `@@` -1023,6 +1024,8 `@@` Session::dump_ast (Parser<Lexer> &parser, AST::Crate &crate) const
    
       parser.debug_dump_ast_output (crate, out);
       out.close ();
    +
    +  AST::Dump (std::cerr).go (crate);
     }
    
     void
    ```
    
    output:
    ```rust
    arthur@platypus ~/G/r/gccrs (add-ast-dump-visitor) [1]> cat test.rs
    fn foo0(a: i32) {
        let a = 15;
        let b: i32 = 15;
    }
    
    fn foo1(a: &i32) {}
    
    struct S;
    
    fn foo2(a: S) {}
    fn foo3(a: S) -> i32 {}
    
    arthur@platypus ~/G/r/gccrs (add-ast-dump-visitor)> build/gcc/rust1 test.rs -frust-dump-all
    fn foo0(a: ) {
            let a = ;
            let b:  = ;
    
    }
    
    fn foo1(a: ) {
    
    }
    
    fn foo2(a: ) {
    
    }
    
    fn foo3(a: ) -> {
    
    }
    
    test.rs:11:1: error: expected [i32] got [()]
       11 | fn foo3(a: S) -> i32 {}
          | ^                ~
    
    Analyzing compilation unit
    
    Time variable                                   usr           sys          wall           GGC
     phase setup                        :   0.00 (  0%)   0.00 (  0%)   0.01 (100%)   129k ( 94%)
     TOTAL                              :   0.00          0.00          0.01          137k
    Extra diagnostic checks enabled; compiler may run slowly.
    Configure with --enable-checking=release to disable checks.
    ```
    
    Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>

Diff:

 gcc/rust/Make-lang.in         |   1 +
 gcc/rust/ast/rust-ast-dump.cc | 750 ++++++++++++++++++++++++++++++++++++++++++
 gcc/rust/ast/rust-ast-dump.h  | 239 ++++++++++++++
 3 files changed, 990 insertions(+)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:51 [gcc/devel/rust/master] Merge #1287 Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).