Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeTools/ResolvProtoDump.cc

    r4c42a5f ra4a000d  
    196196                        }
    197197                       
    198                         // default to just name, with first character in lowercase
    199                         ss << pre
    200                            << (char)std::tolower( static_cast<unsigned char>(name[0]) )
    201                            << (name.c_str() + 1);
     198                        // default to just name
     199                        ss << pre << name;
    202200                }
    203201
    204202                /// ensures type inst names are uppercase
    205203                static void ti_name( const std::string& name, std::stringstream& ss ) {
    206                         unsigned i = 0;
    207                         while ( i < name.size() && name[i] == '_' ) { ++i; }
    208                         if ( i == name.size() ) {
    209                                 ss << "Anon";
    210                                 return;
    211                         }
    212                         ss << (char)std::toupper( static_cast<unsigned char>(name[i]) )
    213                            << (name.c_str() + i + 1);
     204                        ss << (char)std::toupper( static_cast<unsigned char>(name[0]) )
     205                           << (name.c_str() + 1);
    214206                }
    215207
     
    227219                        void previsit( BasicType* bt ) { ss << (int)bt->get_kind(); }
    228220
    229                         // pointers (except function pointers) represented as generic type
    230                         void previsit( PointerType* pt ) {
    231                                 if ( ! dynamic_cast<FunctionType*>(pt->base) ) { ss << "#$ptr<"; ++depth; }
    232                         }
    233                         void postvisit( PointerType* pt ) {
    234                                 if ( ! dynamic_cast<FunctionType*>(pt->base) ) { --depth; ss << '>'; }
    235                         }
    236 
    237                         // arrays represented as generic pointers
     221                        // pointers represented as generic type
     222                        // TODO except pointer to function
     223                        void previsit( PointerType* ) { ss << "#$ptr<"; ++depth; }
     224                        void postvisit( PointerType* ) { --depth; ss << '>'; }
     225
     226                        // arrays represented as generic type
    238227                        void previsit( ArrayType* at ) {
    239                                 ss << "#$ptr<";
     228                                ss << "#$arr<";
    240229                                ++depth;
    241230                                at->base->accept( *visitor );
     
    255244                        }
    256245
    257                         // print function types using prototype syntax
     246                        // encode function type as a 2-param generic type
     247                        // TODO handle forall functions
    258248                        void previsit( FunctionType* ft ) {
    259                                 ss << '[';
     249                                ss << "#$fn<";
    260250                                ++depth;
    261                                 build( *visitor, from_decls( ft->returnVals ), ss, preceded );
    262                                 ss << " : ";
    263                                 build( *visitor, from_decls( ft->parameters ), ss, terminated );
     251                                buildAsTuple( *visitor, from_decls( ft->returnVals ), ss );
     252                                ss << ' ';
     253                                buildAsTuple( *visitor, from_decls( ft->parameters ), ss );
    264254                                --depth;
    265                                 ss << ']';
     255                                ss << '>';
    266256                                visit_children = false;
    267257                        }
     
    351341                        }
    352342
    353                         // print variable declaration in prototype syntax
     343                        // print variable declaration as zero-arg function
    354344                        PassVisitor<TypePrinter> printTy{ closed, ss };
    355345                        norefs->accept( printTy );
    356                         ss << " &";
     346                        ss << ' ';
    357347                        rp_name( name, ss );
    358348                }
     
    391381                                : closed(closed), ss(ss) {}
    392382
    393                         /// Names handled as name expressions
     383                        /// Names handled as nullary function calls
    394384                        void previsit( NameExpr* expr ) {
    395                                 ss << '&';
    396385                                rp_name( expr->name, ss );
     386                                ss << "()";
    397387                        }
    398388
     
    426416                        }
    427417
    428                         /// Already-resolved calls skipped
    429                         void previsit( ApplicationExpr* ) {
    430                                 visit_children = false;
    431                         }
    432 
    433418                        /// Address-of handled as operator
    434419                        void previsit( AddressExpr* expr ) {
     
    600585
    601586                void previsit( FunctionDecl *decl ) {
    602                         // skip decls with ftype parameters
    603                         for ( TypeDecl* tyvar : decl->type->forall ) {
    604                                 if ( tyvar->get_kind() == TypeDecl::Ftype ) {
    605                                         visit_children = false;
    606                                         return;
    607                                 }
    608                         }
    609 
    610587                        // add function as declaration
    611588                        std::stringstream ss;
Note: See TracChangeset for help on using the changeset viewer.