Changes in / [68c9165:3ca912a]


Ignore:
Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Print.cpp

    r68c9165 r3ca912a  
    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        
    141101        void print( const ast::AggregateDecl * node ) {
    142102                os << node->typeString() << " " << node->name << ":";
     
    606566
    607567        virtual const ast::Type * visit( const ast::VoidType * node ) {
    608                 preprint( node );
    609                 os << "void";
    610568                return node;
    611569        }
    612570
    613571        virtual const ast::Type * visit( const ast::BasicType * node ) {
    614                 preprint( node );
    615                 os << ast::BasicType::typeNames[ node->kind ];
    616572                return node;
    617573        }
    618574
    619575        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                 }
    643576                return node;
    644577        }
    645578
    646579        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 
    671580                return node;
    672581        }
    673582
    674583        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 
    684584                return node;
    685585        }
    686586
    687587        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 
    698588                return node;
    699589        }
    700590
    701591        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 
    727592                return node;
    728593        }
    729594
    730595        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 
    739596                return node;
    740597        }
    741598
    742599        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 
    751600                return node;
    752601        }
    753602
    754603        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 
    763604                return node;
    764605        }
    765606
    766607        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 
    772608                return node;
    773609        }
    774610
    775611        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 
    782612                return node;
    783613        }
    784614
    785615        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 
    793616                return node;
    794617        }
    795618
    796619        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 
    807620                return node;
    808621        }
    809622
    810623        virtual const ast::Type * visit( const ast::VarArgsType * node ) {
    811                 preprint( node );
    812                 os << "builtin var args pack";
    813624                return node;
    814625        }
    815626
    816627        virtual const ast::Type * visit( const ast::ZeroType * node ) {
    817                 preprint( node );
    818                 os << "zero_t";
    819628                return node;
    820629        }
    821630
    822631        virtual const ast::Type * visit( const ast::OneType * node ) {
    823                 preprint( node );
    824                 os << "one_t";
    825632                return node;
    826633        }
    827634
    828635        virtual const ast::Type * visit( const ast::GlobalScopeType * node ) {
    829                 preprint( node );
    830                 os << "Global Scope Type";
    831636                return node;
    832637        }
  • src/AST/Type.hpp

    r68c9165 r3ca912a  
    308308        virtual ReferenceToType * clone() const override = 0;
    309309        MUTATE_FRIEND
     310
     311protected:
     312        /// Name for the kind of type this is
     313        virtual std::string typeString() const = 0;
    310314};
    311315
     
    329333        StructInstType * clone() const override { return new StructInstType{ *this }; }
    330334        MUTATE_FRIEND
     335
     336        std::string typeString() const override { return "struct"; }
    331337};
    332338
     
    350356        UnionInstType * clone() const override { return new UnionInstType{ *this }; }
    351357        MUTATE_FRIEND
     358
     359        std::string typeString() const override { return "union"; }
    352360};
    353361
     
    371379        EnumInstType * clone() const override { return new EnumInstType{ *this }; }
    372380        MUTATE_FRIEND
     381
     382        std::string typeString() const override { return "enum"; }
    373383};
    374384
     
    393403        TraitInstType * clone() const override { return new TraitInstType{ *this }; }
    394404        MUTATE_FRIEND
     405
     406        std::string typeString() const override { return "trait"; }
    395407};
    396408
     
    420432        TypeInstType * clone() const override { return new TypeInstType{ *this }; }
    421433        MUTATE_FRIEND
     434
     435        std::string typeString() const override { return "type"; }
    422436};
    423437
Note: See TracChangeset for help on using the changeset viewer.