Changeset 9facf3b for src/SymTab
- Timestamp:
- Dec 15, 2016, 1:33:23 PM (8 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r1486116 r9facf3b 61 61 #include <algorithm> 62 62 #include "InitTweak/InitTweak.h" 63 #include "CodeGen/CodeGenerator.h" 63 64 64 65 #define debugPrint( x ) if ( doDebug ) { std::cout << x; } 65 66 66 67 namespace SymTab { 67 class HoistStruct : public Visitor {68 class HoistStruct final : public Visitor { 68 69 public: 69 70 /// Flattens nested struct types … … 87 88 88 89 /// Fix return types so that every function returns exactly one value 89 class ReturnTypeFixer : public Visitor {90 class ReturnTypeFixer final : public Visitor { 90 91 public: 92 93 typedef Visitor Parent; 94 using Parent::visit; 95 91 96 static void fix( std::list< Declaration * > &translationUnit ); 97 98 virtual void visit( FunctionDecl * functionDecl ); 92 99 93 100 virtual void visit( FunctionType * ftype ); … … 95 102 96 103 /// 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 { 98 105 typedef Visitor Parent; 99 106 virtual void visit( EnumDecl *aggregateDecl ); … … 762 769 } 763 770 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 764 786 void ReturnTypeFixer::visit( FunctionType * ftype ) { 765 static UniqueName tempNamer( "_retval" );766 767 787 // xxx - need to handle named return values - this information needs to be saved somehow 768 788 // so that resolution has access to the names. … … 774 794 TupleType * tupleType = safe_dynamic_cast< TupleType * >( ResolvExpr::extractResultType( ftype ) ); 775 795 // 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 ) ); 777 797 deleteAll( retVals ); 778 798 retVals.clear(); 779 799 retVals.push_back( newRet ); 780 } else if ( retVals.size() == 1 ) {781 // ensure other return values have a name782 DeclarationWithType * ret = retVals.front();783 if ( ret->get_name() == "" ) {784 ret->set_name( tempNamer.newName() );785 }786 800 } 787 801 }
Note: See TracChangeset
for help on using the changeset viewer.