Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r4ef7506 rd3b7937  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:50:04 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri Dec 18 15:34:05 2015
    13 // Update Count     : 218
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Jan 27 22:03:12 2016
     13// Update Count     : 225
    1414//
    1515
     
    4949#include "FixFunction.h"
    5050// #include "ImplementationType.h"
    51 #include "utility.h"
    52 #include "UniqueName.h"
     51#include "Common/utility.h"
     52#include "Common/UniqueName.h"
    5353#include "AddVisit.h"
    5454#include "MakeLibCfa.h"
     
    585585        }
    586586
    587         template< typename OutputIterator >
    588         void makeUnionFieldsAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, UnionInstType *unionType, OutputIterator out ) {
    589                 UntypedExpr *copy = new UntypedExpr( new NameExpr( "__builtin_memcpy" ) );
    590                 copy->get_args().push_back( new VariableExpr( dstParam ) );
    591                 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
    592                 copy->get_args().push_back( new SizeofExpr( unionType ) );
    593 
    594                 *out++ = new ExprStmt( noLabels, copy );
    595         }
    596 
    597587        //E ?=?(E volatile*, int),
    598588        //  ?=?(E _Atomic volatile*, int);
     
    663653
    664654                // Make function polymorphic in same parameters as generic struct, if applicable
    665                 bool isGeneric = false;  // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union)
    666655                std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
    667656                std::list< Expression* > structParams;  // List of matching parameters to put on types
    668657                for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
    669                         isGeneric = true;
    670658                        TypeDecl *typeParam = (*param)->clone();
    671659                        assignType->get_forall().push_back( typeParam );
     
    673661                }
    674662
    675                 ObjectDecl *returnVal = new ObjectDecl( "_ret", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 );
     663                ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 );
    676664                assignType->get_returnVals().push_back( returnVal );
    677665
     
    703691                                if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) {
    704692                                        makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
    705                                         if ( isGeneric ) makeArrayAssignment( srcParam, returnVal, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
    706693                                } else {
    707694                                        makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
    708                                         if ( isGeneric ) makeScalarAssignment( srcParam, returnVal, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
    709695                                } // if
    710696                        } // if
    711697                } // for
    712                 if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
     698                assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
    713699
    714700                return assignDecl;
     
    719705
    720706                // Make function polymorphic in same parameters as generic union, if applicable
    721                 bool isGeneric = false;  // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct)
    722707                std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
    723708                std::list< Expression* > unionParams;  // List of matching parameters to put on types
    724709                for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
    725                         isGeneric = true;
    726710                        TypeDecl *typeParam = (*param)->clone();
    727711                        assignType->get_forall().push_back( typeParam );
     
    729713                }
    730714
    731                 ObjectDecl *returnVal = new ObjectDecl( "_ret", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 );
     715                ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 );
    732716                assignType->get_returnVals().push_back( returnVal );
    733717
     
    743727                assignDecl->fixUniqueId();
    744728
    745                 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) );
    746                 if ( isGeneric ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) );
    747                
    748                 if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
     729                UntypedExpr *copy = new UntypedExpr( new NameExpr( "__builtin_memcpy" ) );
     730                copy->get_args().push_back( new VariableExpr( dstParam ) );
     731                copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
     732                copy->get_args().push_back( new SizeofExpr( cloneWithParams( refType, unionParams ) ) );
     733
     734                assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) );
     735                assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
    749736
    750737                return assignDecl;
Note: See TracChangeset for help on using the changeset viewer.