Changeset 4c42a5f


Ignore:
Timestamp:
Sep 20, 2018, 3:01:43 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
371ef1d
Parents:
91a950c
Message:

Add function pointer types and variable decls and expressions to RPDump

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeTools/ResolvProtoDump.cc

    r91a950c r4c42a5f  
    196196                        }
    197197                       
    198                         // default to just name
    199                         ss << pre << name;
     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);
    200202                }
    201203
    202204                /// ensures type inst names are uppercase
    203205                static void ti_name( const std::string& name, std::stringstream& ss ) {
    204                         ss << (char)std::toupper( static_cast<unsigned char>(name[0]) )
    205                            << (name.c_str() + 1);
     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);
    206214                }
    207215
     
    219227                        void previsit( BasicType* bt ) { ss << (int)bt->get_kind(); }
    220228
    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
     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
    227238                        void previsit( ArrayType* at ) {
    228                                 ss << "#$arr<";
     239                                ss << "#$ptr<";
    229240                                ++depth;
    230241                                at->base->accept( *visitor );
     
    244255                        }
    245256
    246                         // encode function type as a 2-param generic type
    247                         // TODO handle forall functions
     257                        // print function types using prototype syntax
    248258                        void previsit( FunctionType* ft ) {
    249                                 ss << "#$fn<";
     259                                ss << '[';
    250260                                ++depth;
    251                                 buildAsTuple( *visitor, from_decls( ft->returnVals ), ss );
    252                                 ss << ' ';
    253                                 buildAsTuple( *visitor, from_decls( ft->parameters ), ss );
     261                                build( *visitor, from_decls( ft->returnVals ), ss, preceded );
     262                                ss << " : ";
     263                                build( *visitor, from_decls( ft->parameters ), ss, terminated );
    254264                                --depth;
    255                                 ss << '>';
     265                                ss << ']';
    256266                                visit_children = false;
    257267                        }
     
    341351                        }
    342352
    343                         // print variable declaration as zero-arg function
     353                        // print variable declaration in prototype syntax
    344354                        PassVisitor<TypePrinter> printTy{ closed, ss };
    345355                        norefs->accept( printTy );
    346                         ss << ' ';
     356                        ss << " &";
    347357                        rp_name( name, ss );
    348358                }
     
    381391                                : closed(closed), ss(ss) {}
    382392
    383                         /// Names handled as nullary function calls
     393                        /// Names handled as name expressions
    384394                        void previsit( NameExpr* expr ) {
     395                                ss << '&';
    385396                                rp_name( expr->name, ss );
    386                                 ss << "()";
    387397                        }
    388398
     
    416426                        }
    417427
     428                        /// Already-resolved calls skipped
     429                        void previsit( ApplicationExpr* ) {
     430                                visit_children = false;
     431                        }
     432
    418433                        /// Address-of handled as operator
    419434                        void previsit( AddressExpr* expr ) {
     
    585600
    586601                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
    587610                        // add function as declaration
    588611                        std::stringstream ss;
Note: See TracChangeset for help on using the changeset viewer.