Changeset bb0f974


Ignore:
Timestamp:
Sep 28, 2018, 5:34:42 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:
d0bacde
Parents:
096a2ff
Message:

Fix bugs in RPDump

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeTools/ResolvProtoDump.cc

    r096a2ff rbb0f974  
    204204                /// ensures type inst names are uppercase
    205205                static void ti_name( const std::string& name, std::stringstream& ss ) {
     206                        // replace built-in wide character types with named types
     207                        if ( name == "char16_t" || name == "char32_t" || name == "wchar_t" ) {
     208                                ss << "#" << name;
     209                                return;
     210                        }
     211
     212                        // strip leading underscore
    206213                        unsigned i = 0;
    207214                        while ( i < name.size() && name[i] == '_' ) { ++i; }
     
    210217                                return;
    211218                        }
    212                         ss << (char)std::toupper( static_cast<unsigned char>(name[i]) )
    213                            << (name.c_str() + i + 1);
     219
     220                        std::string stripped = name.substr(i);
     221                        // strip trailing "_generic_" from autogen names (avoids some user-generation issues)
     222                        char generic[] = "_generic_"; size_t n_generic = sizeof(generic) - 1;
     223                        if ( stripped.size() >= n_generic
     224                                        && stripped.substr( stripped.size() - n_generic ) == generic ) {
     225                                stripped.resize( stripped.size() - n_generic );
     226                        }
     227
     228                        // uppercase first character
     229                        ss << (char)std::toupper( static_cast<unsigned char>(stripped[0]) )
     230                           << (stripped.c_str() + 1);
    214231                }
    215232
     
    397414                        }
    398415
     416                        /// Handle already-resolved variables as type constants
     417                        void previsit( VariableExpr* expr ) {
     418                                PassVisitor<TypePrinter> tyPrinter{ closed, ss };
     419                                expr->var->get_type()->accept( tyPrinter );
     420                                visit_children = false;
     421                        }
     422
    399423                        /// Calls handled as calls
    400424                        void previsit( UntypedExpr* expr ) {
     
    426450                        }
    427451
    428                         /// Already-resolved calls skipped
    429                         void previsit( ApplicationExpr* ) {
     452                        /// Already-resolved calls reduced to their type constant
     453                        void previsit( ApplicationExpr* expr ) {
     454                                PassVisitor<TypePrinter> tyPrinter{ closed, ss };
     455                                expr->result->accept( tyPrinter );
    430456                                visit_children = false;
    431457                        }
     
    532558                                for ( Initializer* it : li->initializers ) {
    533559                                        build( it, ss );
    534                                         ss << ' ';
    535560                                }
    536561                        }
     
    539564                /// Adds an object initializer to the list of expressions
    540565                void build( const std::string& name, Initializer* init, std::stringstream& ss ) {
    541                         ss << "$constructor( ";
     566                        ss << "$constructor( &";
    542567                        rp_name( name, ss );
    543                         ss << "() ";
     568                        ss << ' ';
    544569                        build( init, ss );
    545570                        ss << ')';
     
    676701                }
    677702
     703                void previsit( AsmStmt* ) {
     704                        // skip asm statements
     705                        visit_children = false;
     706                }
     707
    678708                void previsit( Expression* expr ) {
    679709                        std::stringstream ss;
     
    686716                /// Print non-prelude global declarations for resolv proto
    687717                void printGlobals() const {
    688                         std::cout << "#ptr<T> $addr T" << std::endl;  // &?
     718                        std::cout << "#$ptr<T> $addr T" << std::endl;  // &?
    689719                        int i = (int)BasicType::SignedInt;
    690720                        std::cout << i << " $and " << i << ' ' << i << std::endl;  // ?&&?
Note: See TracChangeset for help on using the changeset viewer.