Changes in / [3ca912a:68c9165]


Ignore:
Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Print.cpp

    r3ca912a r68c9165  
    9999        }
    100100
     101        void print( const ast::ParameterizedType::ForallList & forall ) {
     102                if ( forall.empty() ) return;   
     103                os << "forall" << std::endl;
     104                ++indent;
     105                printAll( forall );
     106                os << indent;
     107                --indent;
     108        }
     109
     110        void print( const std::vector<ptr<Attribute>> & attrs ) {
     111                if ( attrs.empty() ) return;
     112                os << "with attributes" << std::endl;
     113                ++indent;
     114                printAll( attrs );
     115                --indent;
     116        }
     117
     118        void print( const std::vector<ptr<Expr>> & params ) {
     119                if ( params.empty() ) return;
     120                os << std::endl << indent << "... with parameters" << std::endl;
     121                ++indent;
     122                printAll( params );
     123                --indent;
     124        }
     125
     126        void preprint( const ast::Type * node ) {
     127                print( node->qualifiers );
     128        }
     129
     130        void preprint( const ast::ParameterizedType * node ) {
     131                print( node->forall );
     132                print( node->qualifiers );
     133        }
     134
     135        void preprint( const ast::ReferenceToType * node ) {
     136                print( node->forall );
     137                print( node->attributes );
     138                print( node->qualifiers );
     139        }
     140       
    101141        void print( const ast::AggregateDecl * node ) {
    102142                os << node->typeString() << " " << node->name << ":";
     
    566606
    567607        virtual const ast::Type * visit( const ast::VoidType * node ) {
     608                preprint( node );
     609                os << "void";
    568610                return node;
    569611        }
    570612
    571613        virtual const ast::Type * visit( const ast::BasicType * node ) {
     614                preprint( node );
     615                os << ast::BasicType::typeNames[ node->kind ];
    572616                return node;
    573617        }
    574618
    575619        virtual const ast::Type * visit( const ast::PointerType * node ) {
     620                preprint( node );
     621                if ( ! node->isArray() ) {
     622                        os << "pointer to ";
     623                } else {
     624                        os << "decayed ";
     625                        if ( node->isStatic ) {
     626                                os << "static ";
     627                        }
     628
     629                        if ( node->isVarLen ) {
     630                                os << "variable length array of ";
     631                        } else if ( node->dimension ) {
     632                                os << "array of ";
     633                                node->dimension->accept( *this );
     634                                os << " ";
     635                        }
     636                }
     637
     638                if ( node->base ) {
     639                        node->base->accept( *this );
     640                } else {
     641                        os << "UNDEFINED";
     642                }
    576643                return node;
    577644        }
    578645
    579646        virtual const ast::Type * visit( const ast::ArrayType * node ) {
     647                preprint( node );
     648                if ( node->isStatic ) {
     649                        os << "static ";
     650                }
     651
     652                if ( node->isVarLen ) {
     653                        os << "variable length array of ";
     654                } else if ( node->dimension ) {
     655                        os << "array of ";
     656                } else {
     657                        os << "open array of ";
     658                }
     659
     660                if ( node->base ) {
     661                        node->base->accept( *this );
     662                } else {
     663                        os << "UNDEFINED";
     664                }
     665
     666                if ( node->dimension ) {
     667                        os << " with dimension of ";
     668                        node->dimension->accept( *this );
     669                }
     670
    580671                return node;
    581672        }
    582673
    583674        virtual const ast::Type * visit( const ast::ReferenceType * node ) {
     675                preprint( node );
     676
     677                os << "reference to ";
     678                if ( node->base ) {
     679                        node->base->accept( *this );
     680                } else {
     681                        os << "UNDEFINED";
     682                }
     683
    584684                return node;
    585685        }
    586686
    587687        virtual const ast::Type * visit( const ast::QualifiedType * node ) {
     688                preprint( node );
     689
     690                ++indent;
     691                os << "Qualified Type:" << std::endl << indent;
     692                node->parent->accept( *this );
     693                os << std::endl << indent;
     694                node->child->accept( *this );
     695                os << std::endl;
     696                --indent;
     697
    588698                return node;
    589699        }
    590700
    591701        virtual const ast::Type * visit( const ast::FunctionType * node ) {
     702                preprint( node );
     703
     704                os << "function" << std::endl;
     705                if ( ! node->params.empty() ) {
     706                        os << indent << "... with parameters" << std::endl;
     707                        ++indent;
     708                        printAll( node->params );
     709                        if ( node->isVarArgs ) {
     710                                os << indent << "and a variable number of other arguments" << std::endl;
     711                        }
     712                        --indent;
     713                } else if ( node->isVarArgs ) {
     714                        os << indent+1 << "accepting unspecified arguments" << std::endl;
     715                }
     716
     717                os << indent << "... returning";
     718                if ( node->returns.empty() ) {
     719                        os << " nothing" << std::endl;
     720                } else {
     721                        os << std::endl;
     722                        ++indent;
     723                        printAll( node->returns );
     724                        --indent;
     725                }
     726
    592727                return node;
    593728        }
    594729
    595730        virtual const ast::Type * visit( const ast::StructInstType * node ) {
     731                preprint( node );
     732
     733                os << "instance of struct " << node->name;
     734                if ( node->base ) {
     735                        os << " " << ( node->base->body ? "with" : "without" ) << " body";
     736                }
     737                print( node->params );
     738
    596739                return node;
    597740        }
    598741
    599742        virtual const ast::Type * visit( const ast::UnionInstType * node ) {
     743                preprint( node );
     744
     745                os << "instance of union " << node->name;
     746                if ( node->base ) {
     747                        os << " " << ( node->base->body ? "with" : "without" ) << " body";
     748                }
     749                print( node->params );
     750
    600751                return node;
    601752        }
    602753
    603754        virtual const ast::Type * visit( const ast::EnumInstType * node ) {
     755                preprint( node );
     756
     757                os << "instance of enum " << node->name;
     758                if ( node->base ) {
     759                        os << " " << ( node->base->body ? "with" : "without" ) << " body";
     760                }
     761                print( node->params );
     762
    604763                return node;
    605764        }
    606765
    607766        virtual const ast::Type * visit( const ast::TraitInstType * node ) {
     767                preprint( node );
     768
     769                os << "instance of trait " << node->name;
     770                print( node->params );
     771
    608772                return node;
    609773        }
    610774
    611775        virtual const ast::Type * visit( const ast::TypeInstType * node ) {
     776                preprint( node );
     777
     778                os << "instance of type " << node->name
     779                   << " (" << (node->kind == ast::TypeVar::Ftype ? "" : "not ") << "function type)";
     780                print( node->params );
     781
    612782                return node;
    613783        }
    614784
    615785        virtual const ast::Type * visit( const ast::TupleType * node ) {
     786                preprint( node );
     787
     788                os << "tuple of types" << std::endl;
     789                ++indent;
     790                printAll( node->types );
     791                --indent;
     792
    616793                return node;
    617794        }
    618795
    619796        virtual const ast::Type * visit( const ast::TypeofType * node ) {
     797                preprint( node );
     798
     799                if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; }
     800                os << "type-of expression ";
     801                if ( node->expr ) {
     802                        node->expr->accept( *this );
     803                } else {
     804                        os << "UNDEFINED";
     805                }
     806
    620807                return node;
    621808        }
    622809
    623810        virtual const ast::Type * visit( const ast::VarArgsType * node ) {
     811                preprint( node );
     812                os << "builtin var args pack";
    624813                return node;
    625814        }
    626815
    627816        virtual const ast::Type * visit( const ast::ZeroType * node ) {
     817                preprint( node );
     818                os << "zero_t";
    628819                return node;
    629820        }
    630821
    631822        virtual const ast::Type * visit( const ast::OneType * node ) {
     823                preprint( node );
     824                os << "one_t";
    632825                return node;
    633826        }
    634827
    635828        virtual const ast::Type * visit( const ast::GlobalScopeType * node ) {
     829                preprint( node );
     830                os << "Global Scope Type";
    636831                return node;
    637832        }
  • src/AST/Type.hpp

    r3ca912a r68c9165  
    308308        virtual ReferenceToType * clone() const override = 0;
    309309        MUTATE_FRIEND
    310 
    311 protected:
    312         /// Name for the kind of type this is
    313         virtual std::string typeString() const = 0;
    314310};
    315311
     
    333329        StructInstType * clone() const override { return new StructInstType{ *this }; }
    334330        MUTATE_FRIEND
    335 
    336         std::string typeString() const override { return "struct"; }
    337331};
    338332
     
    356350        UnionInstType * clone() const override { return new UnionInstType{ *this }; }
    357351        MUTATE_FRIEND
    358 
    359         std::string typeString() const override { return "union"; }
    360352};
    361353
     
    379371        EnumInstType * clone() const override { return new EnumInstType{ *this }; }
    380372        MUTATE_FRIEND
    381 
    382         std::string typeString() const override { return "enum"; }
    383373};
    384374
     
    403393        TraitInstType * clone() const override { return new TraitInstType{ *this }; }
    404394        MUTATE_FRIEND
    405 
    406         std::string typeString() const override { return "trait"; }
    407395};
    408396
     
    432420        TypeInstType * clone() const override { return new TypeInstType{ *this }; }
    433421        MUTATE_FRIEND
    434 
    435         std::string typeString() const override { return "type"; }
    436422};
    437423
Note: See TracChangeset for help on using the changeset viewer.