Changeset 9facf3b for src/SymTab


Ignore:
Timestamp:
Dec 15, 2016, 1:33:23 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
5802a4f
Parents:
1486116
git-author:
Rob Schluntz <rschlunt@…> (12/15/16 12:00:08)
git-committer:
Rob Schluntz <rschlunt@…> (12/15/16 13:33:23)
Message:

update generation of return variables and the affected test outputs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r1486116 r9facf3b  
    6161#include <algorithm>
    6262#include "InitTweak/InitTweak.h"
     63#include "CodeGen/CodeGenerator.h"
    6364
    6465#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
    6566
    6667namespace SymTab {
    67         class HoistStruct : public Visitor {
     68        class HoistStruct final : public Visitor {
    6869          public:
    6970                /// Flattens nested struct types
     
    8788
    8889        /// Fix return types so that every function returns exactly one value
    89         class ReturnTypeFixer : public Visitor {
     90        class ReturnTypeFixer final : public Visitor {
    9091          public:
     92
     93                typedef Visitor Parent;
     94                using Parent::visit;
     95
    9196                static void fix( std::list< Declaration * > &translationUnit );
     97
     98                virtual void visit( FunctionDecl * functionDecl );
    9299
    93100                virtual void visit( FunctionType * ftype );
     
    95102
    96103        /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
    97         class EnumAndPointerDecayPass : public Visitor {
     104        class EnumAndPointerDecayPass final : public Visitor {
    98105                typedef Visitor Parent;
    99106                virtual void visit( EnumDecl *aggregateDecl );
     
    762769        }
    763770
     771        void ReturnTypeFixer::visit( FunctionDecl * functionDecl ) {
     772                Parent::visit( functionDecl );
     773                FunctionType * ftype = functionDecl->get_functionType();
     774                std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();
     775                assertf( retVals.size() == 0 || retVals.size() == 1, "Function %s has too many return values: %d", functionDecl->get_name().c_str(), retVals.size() );
     776                if ( retVals.size() == 1 ) {
     777                        // ensure all function return values have a name - use the name of the function to disambiguate (this also provides a nice bit of help for debugging)
     778                        // ensure other return values have a name
     779                        DeclarationWithType * ret = retVals.front();
     780                        if ( ret->get_name() == "" ) {
     781                                ret->set_name( toString( "_retval_", CodeGen::genName( functionDecl ) ) );
     782                        }
     783                }
     784        }
     785
    764786        void ReturnTypeFixer::visit( FunctionType * ftype ) {
    765                 static UniqueName tempNamer( "_retval" );
    766 
    767787                // xxx - need to handle named return values - this information needs to be saved somehow
    768788                // so that resolution has access to the names.
     
    774794                        TupleType * tupleType = safe_dynamic_cast< TupleType * >( ResolvExpr::extractResultType( ftype ) );
    775795                        // ensure return value is not destructed by explicitly creating an empty ListInit node wherein maybeConstruct is false.
    776                         ObjectDecl * newRet = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) );
     796                        ObjectDecl * newRet = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) );
    777797                        deleteAll( retVals );
    778798                        retVals.clear();
    779799                        retVals.push_back( newRet );
    780                 } else if ( retVals.size() == 1 ) {
    781                         // ensure other return values have a name
    782                         DeclarationWithType * ret = retVals.front();
    783                         if ( ret->get_name() == "" ) {
    784                                 ret->set_name( tempNamer.newName() );
    785                         }
    786800                }
    787801        }
Note: See TracChangeset for help on using the changeset viewer.