Changeset eef8dfb for src/AST/Print.cpp


Ignore:
Timestamp:
Jan 7, 2021, 2:55:57 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
58fe85a
Parents:
bdfc032 (diff), 44e37ef (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into dkobets-vector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Print.cpp

    rbdfc032 reef8dfb  
    2121#include "Type.hpp"
    2222#include "TypeSubstitution.hpp"
     23#include "CompilationState.h"
    2324
    2425#include "Common/utility.h" // for group_iterate
     
    2930
    3031template <typename C, typename... T>
    31 constexpr auto make_array(T&&... values) ->
    32         array<C,sizeof...(T)>
     32constexpr array<C,sizeof...(T)> make_array(T&&... values)
    3333{
    3434        return array<C,sizeof...(T)>{
     
    129129
    130130        void print( const ast::Expr::InferUnion & inferred, unsigned level = 0 ) {
    131                 switch ( inferred.mode ) {
    132                 case ast::Expr::InferUnion::Empty: return;
    133                 case ast::Expr::InferUnion::Slots: {
    134                         os << indent << "with " << inferred.data.resnSlots.size()
     131                if (inferred.data.resnSlots && !inferred.data.resnSlots->empty()) {
     132                        os << indent << "with " << inferred.data.resnSlots->size()
    135133                           << " pending inference slots" << endl;
    136                         return;
    137                 }
    138                 case ast::Expr::InferUnion::Params: {
     134                }
     135                if (inferred.data.inferParams && !inferred.data.inferParams->empty()) {
    139136                        os << indent << "with inferred parameters " << level << ":" << endl;
    140137                        ++indent;
    141                         for ( const auto & i : inferred.data.inferParams ) {
     138                        for ( const auto & i : *inferred.data.inferParams ) {
    142139                                os << indent;
    143                                 short_print( Decl::fromId( i.second.decl ) );
     140                                short_print( i.second.declptr );
    144141                                os << endl;
    145142                                print( i.second.expr->inferred, level+1 );
    146143                        }
    147144                        --indent;
    148                         return;
    149                 }
    150                 }
    151         }
    152 
    153         void print( const ast::ParameterizedType::ForallList & forall ) {
     145                }
     146        }
     147
     148        void print( const ast::FunctionType::ForallList & forall ) {
    154149                if ( forall.empty() ) return;
    155150                os << "forall" << endl;
    156151                ++indent;
    157152                printAll( forall );
     153                os << indent;
     154                --indent;
     155        }
     156
     157        void print( const ast::FunctionType::AssertionList & assts ) {
     158                if (assts.empty()) return;
     159                os << "with assertions" << endl;
     160                ++indent;
     161                printAll(assts);
    158162                os << indent;
    159163                --indent;
     
    210214
    211215        void preprint( const ast::NamedTypeDecl * node ) {
    212                 if ( ! node->name.empty() ) os << node->name << ": ";
     216                if ( ! node->name.empty() ) {
     217                        os << node->name << ": ";
     218                }
    213219
    214220                if ( ! short_mode && node->linkage != Linkage::Cforall ) {
     
    226232                }
    227233
    228                 if ( ! node->params.empty() ) {
    229                         os << endl << indent << "... with parameters" << endl;
    230                         ++indent;
    231                         printAll( node->params );
    232                         --indent;
    233                 }
    234 
    235                 if ( ! short_mode && ! node->assertions.empty() ) {
     234                if ( ! node->assertions.empty() ) {
    236235                        os << endl << indent << "... with assertions" << endl;
    237236                        ++indent;
     
    244243                print( node->inferred );
    245244
     245                if ( node->result ) {
     246                        os << endl << indent << "... with resolved type:" << endl;
     247                        ++indent;
     248                        os << indent;
     249                        node->result->accept( *this );
     250                        --indent;
     251                }
     252
    246253                if ( node->env ) {
    247254                        os << endl << indent << "... with environment:" << endl;
     
    260267        }
    261268
    262         void preprint( const ast::ParameterizedType * node ) {
     269        void preprint( const ast::FunctionType * node ) {
    263270                print( node->forall );
     271                print( node->assertions );
    264272                print( node->qualifiers );
    265273        }
    266274
    267         void preprint( const ast::ReferenceToType * node ) {
    268                 print( node->forall );
     275        void preprint( const ast::BaseInstType * node ) {
    269276                print( node->attributes );
    270277                print( node->qualifiers );
     
    678685        }
    679686
     687        virtual const ast::Stmt * visit( const ast::SuspendStmt * node ) override final {
     688                os << "Suspend Statement";
     689                switch (node->type) {
     690                        case ast::SuspendStmt::None     : os << " with implicit target"; break;
     691                        case ast::SuspendStmt::Generator: os << " for generator"; break;
     692                        case ast::SuspendStmt::Coroutine: os << " for coroutine"; break;
     693                }
     694                os << endl;
     695
     696                ++indent;
     697                if(node->then) {
     698                        os << indent << " with post statement :" << endl;
     699                        safe_print( node->then );
     700                }
     701                ++indent;
     702
     703                return node;
     704        }
     705
    680706        virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) override final {
    681707                os << "Waitfor Statement" << endl;
     
    823849        virtual const ast::Expr * visit( const ast::CastExpr * node ) override final {
    824850                ++indent;
    825                 os << (node->isGenerated ? "Generated" : "Explicit") << " cast of:" << endl << indent;
     851                os << (node->isGenerated ? "Generated" : "Explicit") << " Cast of:" << endl << indent;
    826852                safe_print( node->arg );
    827853                os << endl << indent-1 << "... to:";
     
    13581384        virtual const ast::Type * visit( const ast::TypeInstType * node ) override final {
    13591385                preprint( node );
    1360                 os << "instance of type " << node->name
     1386                const auto & _name = deterministic_output && isUnboundType(node) ? "[unbound]" : node->typeString();
     1387                os << "instance of type " << _name
    13611388                   << " (" << (node->kind == ast::TypeDecl::Ftype ? "" : "not ") << "function type)";
    13621389                print( node->params );
     
    14841511                os << indent << "Types:" << endl;
    14851512                for ( const auto& i : *node ) {
    1486                         os << indent+1 << i.first << " -> ";
     1513                        os << indent+1 << i.first.typeString() << " -> ";
    14871514                        indent += 2;
    14881515                        safe_print( i.second );
    1489                         indent -= 2;
    1490                         os << endl;
    1491                 }
    1492                 os << indent << "Non-types:" << endl;
    1493                 for ( auto i = node->beginVar(); i != node->endVar(); ++i ) {
    1494                         os << indent+1 << i->first << " -> ";
    1495                         indent += 2;
    1496                         safe_print( i->second );
    14971516                        indent -= 2;
    14981517                        os << endl;
Note: See TracChangeset for help on using the changeset viewer.