Changeset 5600747 for src


Ignore:
Timestamp:
Mar 8, 2018, 9:23:32 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
4c11fce, ab0203df
Parents:
e5d4e5c (diff), fb11446e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    re5d4e5c r5600747  
    163163                        void premutate( DeclStmt *declStmt );
    164164                        Expression *postmutate( MemberExpr *memberExpr );
     165                        void premutate( AddressExpr *addrExpr );
     166                        Expression *postmutate( AddressExpr *addrExpr );
    165167                        Expression *postmutate( SizeofExpr *sizeofExpr );
    166168                        Expression *postmutate( AlignofExpr *alignofExpr );
     
    193195                        ScopedSet< std::string > knownOffsets;          ///< Set of non-generic types for which the offset array exists in the current scope, indexed by offsetofName
    194196                        UniqueName bufNamer;                           ///< Namer for VLA buffers
     197                        Expression * addrMember = nullptr;             ///< AddressExpr argument is MemberExpr?
    195198                };
    196199
     
    11741177                        if ( expr->result && isPolyType( expr->result, scopeTyVars, env ) ) {
    11751178                                if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->function ) ) {
    1176                                         if ( name->get_name() == "*?" ) {
     1179                                        if ( name->name == "*?" ) {
    11771180                                                Expression *ret = expr->args.front();
    11781181                                                expr->args.clear();
     
    11871190                void Pass1::premutate( AddressExpr * ) { visit_children = false; }
    11881191                Expression * Pass1::postmutate( AddressExpr * addrExpr ) {
    1189                         assert( addrExpr->get_arg()->result && ! addrExpr->get_arg()->get_result()->isVoid() );
     1192                        assert( addrExpr->arg->result && ! addrExpr->arg->result->isVoid() );
    11901193
    11911194                        bool needs = false;
    1192                         if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) {
    1193                                 if ( expr->result && isPolyType( expr->get_result(), scopeTyVars, env ) ) {
    1194                                         if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    1195                                                 if ( name->get_name() == "*?" ) {
    1196                                                         if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) {
    1197                                                                 assert( appExpr->get_function()->result );
    1198                                                                 FunctionType *function = getFunctionType( appExpr->get_function()->get_result() );
     1195                        if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->arg ) ) {
     1196                                if ( expr->result && isPolyType( expr->result, scopeTyVars, env ) ) {
     1197                                        if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->function ) ) {
     1198                                                if ( name->name == "*?" ) {
     1199                                                        if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->args.front() ) ) {
     1200                                                                assert( appExpr->function->result );
     1201                                                                FunctionType *function = getFunctionType( appExpr->function->result );
    11991202                                                                assert( function );
    12001203                                                                needs = needsAdapter( function, scopeTyVars );
     
    12061209                        // isPolyType check needs to happen before mutating addrExpr arg, so pull it forward
    12071210                        // out of the if condition.
    1208                         addrExpr->arg = addrExpr->get_arg()->acceptMutator( *visitor );
     1211                        addrExpr->arg = addrExpr->arg->acceptMutator( *visitor );
    12091212                        // ... but must happen after mutate, since argument might change (e.g. intrinsic *?, ?[?]) - re-evaluate above comment
    1210                         bool polytype = isPolyType( addrExpr->get_arg()->get_result(), scopeTyVars, env );
     1213                        bool polytype = isPolyType( addrExpr->arg->result, scopeTyVars, env );
    12111214                        if ( polytype || needs ) {
    1212                                 Expression *ret = addrExpr->get_arg();
    1213                                 delete ret->get_result();
    1214                                 ret->set_result( addrExpr->get_result()->clone() );
    1215                                 addrExpr->set_arg( 0 );
     1215                                Expression *ret = addrExpr->arg;
     1216                                delete ret->result;
     1217                                ret->result = addrExpr->result->clone();
     1218                                addrExpr->arg = nullptr;
    12161219                                delete addrExpr;
    12171220                                return ret;
     
    12501253
    12511254                void Pass2::addAdapters( FunctionType *functionType ) {
    1252                         std::list< DeclarationWithType *> &paramList = functionType->get_parameters();
     1255                        std::list< DeclarationWithType *> &paramList = functionType->parameters;
    12531256                        std::list< FunctionType *> functions;
    12541257                        for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
     
    12711274
    12721275                DeclarationWithType * Pass2::postmutate( FunctionDecl *functionDecl ) {
    1273                         FunctionType * ftype = functionDecl->get_functionType();
    1274                         if ( ! ftype->get_returnVals().empty() && functionDecl->get_statements() ) {
    1275                                 if ( ! isPrefix( functionDecl->get_name(), "_thunk" ) && ! isPrefix( functionDecl->get_name(), "_adapter" ) ) { // xxx - remove check for prefix once thunks properly use ctor/dtors
    1276                                         assert( ftype->get_returnVals().size() == 1 );
    1277                                         DeclarationWithType * retval = ftype->get_returnVals().front();
    1278                                         if ( retval->get_name() == "" ) {
    1279                                                 retval->set_name( "_retval" );
     1276                        FunctionType * ftype = functionDecl->type;
     1277                        if ( ! ftype->returnVals.empty() && functionDecl->statements ) {
     1278                                if ( ! isPrefix( functionDecl->name, "_thunk" ) && ! isPrefix( functionDecl->name, "_adapter" ) ) { // xxx - remove check for prefix once thunks properly use ctor/dtors
     1279                                        assert( ftype->returnVals.size() == 1 );
     1280                                        DeclarationWithType * retval = ftype->returnVals.front();
     1281                                        if ( retval->name == "" ) {
     1282                                                retval->name = "_retval";
    12801283                                        }
    1281                                         functionDecl->get_statements()->get_kids().push_front( new DeclStmt( retval ) );
     1284                                        functionDecl->statements->kids.push_front( new DeclStmt( retval ) );
    12821285                                        DeclarationWithType * newRet = retval->clone(); // for ownership purposes
    1283                                         ftype->get_returnVals().front() = newRet;
     1286                                        ftype->returnVals.front() = newRet;
    12841287                                }
    12851288                        }
    12861289                        // errors should have been caught by this point, remove initializers from parameters to allow correct codegen of default arguments
    1287                         for ( Declaration * param : functionDecl->get_functionType()->get_parameters() ) {
     1290                        for ( Declaration * param : functionDecl->type->parameters ) {
    12881291                                if ( ObjectDecl * obj = dynamic_cast< ObjectDecl * >( param ) ) {
    1289                                         delete obj->get_init();
    1290                                         obj->set_init( nullptr );
     1292                                        delete obj->init;
     1293                                        obj->init = nullptr;
    12911294                                }
    12921295                        }
     
    15841587                        assert( newMemberExpr );
    15851588
    1586                         Type *memberType = memberExpr->member->get_type();
     1589                        // Must apply the generic substitution to the member type to handle cases where the member is a generic parameter substituted by a known concrete type, e.g.
     1590                        //   forall(otype T) struct Box { T x; }
     1591                        //   forall(otype T) f() {
     1592                        //     Box(T *) b; b.x;
     1593                        //   }
     1594                        // TODO: memberExpr->result should be exactly memberExpr->member->get_type() after substitution, so it doesn't seem like it should be necessary to apply the substitution manually. For some reason this is not currently the case. This requires more investigation.
     1595                        Type *memberType = memberExpr->member->get_type()->clone();
     1596                        TypeSubstitution sub = objectType->genericSubstitution();
     1597                        sub.apply( memberType );
    15871598                        if ( ! isPolyType( memberType, scopeTyVars ) ) {
    15881599                                // Not all members of a polymorphic type are themselves of polymorphic type; in this case the member expression should be wrapped and dereferenced to form an lvalue
     
    15921603                        }
    15931604
     1605                        delete memberType;
    15941606                        delete memberExpr;
    15951607                        return newMemberExpr;
     1608                }
     1609
     1610                void PolyGenericCalculator::premutate( AddressExpr * addrExpr ) {
     1611                        GuardValue( addrMember );
     1612                        // is the argument a MemberExpr before mutating?
     1613                        addrMember = dynamic_cast< MemberExpr * >( addrExpr->arg );
     1614                }
     1615
     1616                Expression * PolyGenericCalculator::postmutate( AddressExpr * addrExpr ) {
     1617                        if ( addrMember && addrMember != addrExpr->arg ) {
     1618                                // arg was a MemberExpr and has been mutated
     1619                                if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * >( addrExpr->arg ) ) {
     1620                                        if ( InitTweak::getFunctionName( untyped ) == "?+?" ) {
     1621                                                // MemberExpr was converted to pointer+offset, and it is not valid C to take the address of an addition, so strip the address-of
     1622                                                // TODO: should  addrExpr->arg->result be changed to addrExpr->result?
     1623                                                Expression * ret = addrExpr->arg;
     1624                                                addrExpr->arg = nullptr;
     1625                                                std::swap( addrExpr->env, ret->env );
     1626                                                delete addrExpr;
     1627                                                return ret;
     1628                                        }
     1629                                }
     1630                        }
     1631                        return addrExpr;
    15961632                }
    15971633
  • src/SynTree/Expression.cc

    re5d4e5c r5600747  
    345345}
    346346
    347 namespace {
    348         TypeSubstitution makeSub( Type * t ) {
    349                 if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( t ) ) {
    350                         return makeSub( refType->get_base() );
    351                 } else if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) {
    352                         return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() );
    353                 } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
    354                         return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() );
    355                 } else {
    356                         assertf( false, "makeSub expects struct or union type for aggregate, but got: %s", toString( t ).c_str() );
    357                 }
    358         }
    359 }
    360 
    361 
    362347MemberExpr::MemberExpr( DeclarationWithType *member, Expression *aggregate ) :
    363348                Expression(), member(member), aggregate(aggregate) {
    364349        assert( member );
    365350        assert( aggregate );
    366 
    367         TypeSubstitution sub( makeSub( aggregate->get_result() ) );
     351        assert( aggregate->result );
     352
     353        TypeSubstitution sub = aggregate->result->genericSubstitution();
    368354        Type * res = member->get_type()->clone();
    369355        sub.apply( res );
  • src/SynTree/ReferenceToType.cc

    re5d4e5c r5600747  
    1414//
    1515
    16 #include <cassert>           // for assert
    17 #include <list>              // for list, _List_const_iterator, list<>::cons...
    18 #include <ostream>           // for operator<<, basic_ostream, ostream, endl
    19 #include <string>            // for string, operator<<, char_traits, operator==
    20 
    21 #include "Common/utility.h"  // for printAll, cloneAll, deleteAll
    22 #include "Declaration.h"     // for StructDecl, UnionDecl, EnumDecl, Declara...
    23 #include "Expression.h"      // for Expression
    24 #include "Type.h"            // for TypeInstType, StructInstType, UnionInstType
     16#include <cassert>            // for assert
     17#include <list>               // for list, _List_const_iterator, list<>::cons...
     18#include <ostream>            // for operator<<, basic_ostream, ostream, endl
     19#include <string>             // for string, operator<<, char_traits, operator==
     20
     21#include "Common/utility.h"   // for printAll, cloneAll, deleteAll
     22#include "Declaration.h"      // for StructDecl, UnionDecl, EnumDecl, Declara...
     23#include "Expression.h"       // for Expression
     24#include "Type.h"             // for TypeInstType, StructInstType, UnionInstType
     25#include "TypeSubstitution.h" // for TypeSubstitution
    2526
    2627class Attribute;
     
    6364std::string StructInstType::typeString() const { return "struct"; }
    6465
     66const std::list<TypeDecl*>* StructInstType::get_baseParameters() const {
     67        if ( ! baseStruct ) return nullptr;
     68        return &baseStruct->get_parameters();
     69}
     70
    6571std::list<TypeDecl*>* StructInstType::get_baseParameters() {
    6672        if ( ! baseStruct ) return nullptr;
     
    7177
    7278AggregateDecl * StructInstType::getAggr() { return baseStruct; }
     79
     80TypeSubstitution StructInstType::genericSubstitution() const {
     81        return TypeSubstitution( get_baseParameters()->begin(), get_baseParameters()->end(), parameters.begin() );
     82}
    7383
    7484void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
     
    102112}
    103113
     114const std::list< TypeDecl * > * UnionInstType::get_baseParameters() const {
     115        if ( ! baseUnion ) return nullptr;
     116        return &baseUnion->get_parameters();
     117}
     118
    104119bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; }
    105120
    106121AggregateDecl * UnionInstType::getAggr() { return baseUnion; }
     122
     123TypeSubstitution UnionInstType::genericSubstitution() const {
     124        return TypeSubstitution( get_baseParameters()->begin(), get_baseParameters()->end(), parameters.begin() );
     125}
    107126
    108127void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
  • src/SynTree/ReferenceType.cc

    re5d4e5c r5600747  
    1616#include "Type.h"
    1717#include "Expression.h"
     18#include "TypeSubstitution.h"
    1819#include "Common/utility.h"
    1920
     
    3536}
    3637
     38TypeSubstitution ReferenceType::genericSubstitution() const { return base->genericSubstitution(); }
     39
    3740void ReferenceType::print( std::ostream &os, Indenter indent ) const {
    3841        Type::print( os, indent );
  • src/SynTree/Type.cc

    re5d4e5c r5600747  
    1515#include "Type.h"
    1616
    17 #include "Attribute.h"               // for Attribute
    18 #include "Common/utility.h"          // for cloneAll, deleteAll, printAll
    19 #include "InitTweak/InitTweak.h"     // for getPointerBase
    20 #include "SynTree/BaseSyntaxNode.h"  // for BaseSyntaxNode
    21 #include "SynTree/Declaration.h"     // for TypeDecl
     17#include "Attribute.h"                // for Attribute
     18#include "Common/utility.h"           // for cloneAll, deleteAll, printAll
     19#include "InitTweak/InitTweak.h"      // for getPointerBase
     20#include "SynTree/BaseSyntaxNode.h"   // for BaseSyntaxNode
     21#include "SynTree/Declaration.h"      // for TypeDecl
     22#include "SynTree/TypeSubstitution.h" // for TypeSubstitution
    2223
    2324using namespace std;
     
    8182int Type::referenceDepth() const { return 0; }
    8283
     84TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
     85
    8386void Type::print( std::ostream &os, Indenter indent ) const {
    8487        if ( ! forall.empty() ) {
  • src/SynTree/Type.h

    re5d4e5c r5600747  
    178178        virtual bool isComplete() const { return true; }
    179179
    180         virtual AggregateDecl * getAggr() {     assertf( false, "Non-aggregate type: %s", toString( this ).c_str() ); }
     180        virtual AggregateDecl * getAggr() { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
     181
     182        virtual TypeSubstitution genericSubstitution() const;
    181183
    182184        virtual Type *clone() const = 0;
     
    329331        virtual unsigned size() const override { return base->size(); }
    330332
     333        virtual TypeSubstitution genericSubstitution() const override;
     334
    331335        virtual ReferenceType *clone() const override { return new ReferenceType( *this ); }
    332336        virtual void accept( Visitor & v ) override { v.visit( this ); }
     
    406410        /// Accesses generic parameters of base struct (NULL if none such)
    407411        std::list<TypeDecl*> * get_baseParameters();
     412        const std::list<TypeDecl*> * get_baseParameters() const;
    408413
    409414        virtual bool isComplete() const override;
    410415
    411416        virtual AggregateDecl * getAggr() override;
     417
     418        virtual TypeSubstitution genericSubstitution() const override;
    412419
    413420        /// Looks up the members of this struct named "name" and places them into "foundDecls".
     
    439446
    440447        /// Accesses generic parameters of base union (NULL if none such)
    441         std::list< TypeDecl * > * get_baseParameters();
     448        std::list<TypeDecl*> * get_baseParameters();
     449        const std::list<TypeDecl*> * get_baseParameters() const;
    442450
    443451        virtual bool isComplete() const override;
    444452
    445453        virtual AggregateDecl * getAggr() override;
     454
     455        virtual TypeSubstitution genericSubstitution() const override;
    446456
    447457        /// looks up the members of this union named "name" and places them into "foundDecls"
  • src/tests/.expect/literals.x86.txt

    re5d4e5c r5600747  
    522522signed int __main__Fi___1(){
    523523    __attribute__ ((unused)) signed int ___retval_main__i_1;
     524    ((void)0b01101011);
     525    ((void)0b01101011u);
     526    ((void)0b01101011l);
     527    ((void)0b01101011ll);
     528    ((void)0b01101011ul);
     529    ((void)0b01101011lu);
     530    ((void)0b01101011ull);
     531    ((void)0b01101011llu);
     532    ((void)(+0b01101011));
     533    ((void)(+0b01101011u));
     534    ((void)(+0b01101011l));
     535    ((void)(+0b01101011ll));
     536    ((void)(+0b01101011ul));
     537    ((void)(+0b01101011lu));
     538    ((void)(+0b01101011ull));
     539    ((void)(+0b01101011llu));
     540    ((void)(-0b01101011));
     541    ((void)(-0b01101011u));
     542    ((void)(-0b01101011l));
     543    ((void)(-0b01101011ll));
     544    ((void)(-0b01101011ul));
     545    ((void)(-0b01101011lu));
     546    ((void)(-0b01101011ull));
     547    ((void)(-0b01101011llu));
    524548    ((void)01234567);
    525549    ((void)01234567u);
     
    10171041    ((void)(-0X0123456789.0123456789P-09F));
    10181042    ((void)(-0X0123456789.0123456789P-09L));
     1043    ((void)((signed char )0b01101011));
     1044    ((void)((signed short int )0b01101011));
     1045    ((void)((signed int )0b01101011));
     1046    ((void)((signed long long int )0b01101011));
     1047    ((void)((__int128 )0b01101011));
     1048    ((void)((unsigned char )0b01101011u));
     1049    ((void)((signed short int )0b01101011u));
     1050    ((void)((unsigned int )0b01101011u));
     1051    ((void)((signed long long int )0b01101011u));
     1052    ((void)((__int128 )0b01101011u));
     1053    ((void)(+((signed int )((signed char )0b01101011))));
     1054    ((void)(+((signed int )((signed short int )0b01101011))));
     1055    ((void)(+((signed int )0b01101011)));
     1056    ((void)(+((signed long long int )0b01101011)));
     1057    ((void)(+((float )((__int128 )0b01101011))));
     1058    ((void)(+((signed int )((unsigned char )0b01101011u))));
     1059    ((void)(+((signed int )((signed short int )0b01101011u))));
     1060    ((void)(+((unsigned int )0b01101011u)));
     1061    ((void)(+((signed long long int )0b01101011u)));
     1062    ((void)(+((float )((__int128 )0b01101011u))));
     1063    ((void)(-((signed int )((signed char )0b01101011))));
     1064    ((void)(-((signed int )((signed short int )0b01101011))));
     1065    ((void)(-((signed int )0b01101011)));
     1066    ((void)(-((signed long long int )0b01101011)));
     1067    ((void)(-((float )((__int128 )0b01101011))));
     1068    ((void)(-((signed int )((unsigned char )0b01101011u))));
     1069    ((void)(-((signed int )((signed short int )0b01101011u))));
     1070    ((void)(-((unsigned int )0b01101011u)));
     1071    ((void)(-((signed long long int )0b01101011u)));
     1072    ((void)(-((float )((__int128 )0b01101011u))));
    10191073    ((void)((signed char )01234567));
    10201074    ((void)((signed short int )01234567));
Note: See TracChangeset for help on using the changeset viewer.