Changeset ac1ed49


Ignore:
Timestamp:
Feb 25, 2016, 5:14:15 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
33e6a2cc, 90c3b1c, c14cff1
Parents:
41a2620 (diff), 44b7088 (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:/u/cforall/software/cfa/cfa-cc

Location:
src
Files:
2 added
28 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/GenType.cc

    r41a2620 rac1ed49  
    3939                virtual void visit( EnumInstType *enumInst );
    4040                virtual void visit( TypeInstType *typeInst );
     41                virtual void visit( VarArgsType *varArgsType );
    4142 
    4243          private:
     
    191192        }
    192193
     194        void GenType::visit( VarArgsType *varArgsType ) {
     195                typeString = "__builtin_va_list " + typeString;
     196                // don't handle qualifiers, var args pack shouldn't have any
     197        }
     198
    193199        void GenType::handleQualifiers( Type *type ) {
    194200                if ( type->get_isConst() ) {
  • src/GenPoly/Box.cc

    r41a2620 rac1ed49  
    2525#include "PolyMutator.h"
    2626#include "FindFunction.h"
    27 #include "ScopedMap.h"
    2827#include "ScrubTyVars.h"
    2928
     
    3837
    3938#include "ResolvExpr/TypeEnvironment.h"
     39#include "ResolvExpr/TypeMap.h"
     40#include "ResolvExpr/typeops.h"
    4041
    4142#include "SymTab/Mangler.h"
     
    101102                        typedef std::map< std::string, DeclarationWithType *> AdapterMap;
    102103                        std::map< std::string, DeclarationWithType *> assignOps;
    103                         ScopedMap< std::string, DeclarationWithType *> scopedAssignOps;
     104                        ResolvExpr::TypeMap< DeclarationWithType > scopedAssignOps;
    104105                        std::stack< AdapterMap > adapters;
    105106                        DeclarationWithType *retval;
     
    248249                }
    249250
    250                 /// returns T if the given declaration is: (*?=?)(T *, T) for some T (return not checked, but maybe should be), NULL otherwise
    251                 ReferenceToType *isAssignment( DeclarationWithType *decl ) {
     251                /// Returns T if the given declaration is (*?=?)(T *, T) for some TypeInstType T (return not checked, but maybe should be), NULL otherwise
     252                TypeInstType *isTypeInstAssignment( DeclarationWithType *decl ) {
    252253                        if ( decl->get_name() == "?=?" ) {
    253254                                if ( FunctionType *funType = getFunctionType( decl->get_type() ) ) {
    254255                                        if ( funType->get_parameters().size() == 2 ) {
    255256                                                if ( PointerType *pointer = dynamic_cast< PointerType *>( funType->get_parameters().front()->get_type() ) ) {
    256                                                         if ( ReferenceToType *refType = dynamic_cast< ReferenceToType *>( pointer->get_base() ) ) {
    257                                                                 if ( ReferenceToType *refType2 = dynamic_cast< ReferenceToType *>( funType->get_parameters().back()->get_type() ) ) {
     257                                                        if ( TypeInstType *refType = dynamic_cast< TypeInstType *>( pointer->get_base() ) ) {
     258                                                                if ( TypeInstType *refType2 = dynamic_cast< TypeInstType *>( funType->get_parameters().back()->get_type() ) ) {
    258259                                                                        if ( refType->get_name() == refType2->get_name() ) {
    259260                                                                                return refType;
     
    267268                        return 0;
    268269                }
     270               
     271                /// returns T if the given declaration is: (*?=?)(T *, T) for some type T (return not checked, but maybe should be), NULL otherwise
     272                /// Only picks assignments where neither parameter is cv-qualified
     273                Type *isAssignment( DeclarationWithType *decl ) {
     274                        if ( decl->get_name() == "?=?" ) {
     275                                if ( FunctionType *funType = getFunctionType( decl->get_type() ) ) {
     276                                        if ( funType->get_parameters().size() == 2 ) {
     277                                                Type::Qualifiers defaultQualifiers;
     278                                                Type *paramType1 = funType->get_parameters().front()->get_type();
     279                                                if ( paramType1->get_qualifiers() != defaultQualifiers ) return 0;
     280                                                Type *paramType2 = funType->get_parameters().back()->get_type();
     281                                                if ( paramType2->get_qualifiers() != defaultQualifiers ) return 0;
     282                                               
     283                                                if ( PointerType *pointerType = dynamic_cast< PointerType* >( paramType1 ) ) {
     284                                                        Type *baseType1 = pointerType->get_base();
     285                                                        if ( baseType1->get_qualifiers() != defaultQualifiers ) return 0;
     286                                                        SymTab::Indexer dummy;
     287                                                        if ( ResolvExpr::typesCompatible( baseType1, paramType2, dummy ) ) {
     288                                                                return baseType1;
     289                                                        } // if
     290                                                } // if
     291                                        } // if
     292                                } // if
     293                        } // if
     294                        return 0;
     295                }
    269296
    270297                void Pass1::findAssignOps( const std::list< TypeDecl *> &forall ) {
     
    274301                                for ( std::list< DeclarationWithType *>::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
    275302                                        std::string typeName;
    276                                         if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( isAssignment( *assert ) ) ) {
     303                                        if ( TypeInstType *typeInst = isTypeInstAssignment( *assert ) ) {
    277304                                                assignOps[ typeInst->get_name() ] = *assert;
    278305                                        } // if
     
    283310                DeclarationWithType *Pass1::mutate( FunctionDecl *functionDecl ) {
    284311                        // if this is a polymorphic assignment function, put it in the map for this scope
    285                         if ( ReferenceToType *refType = isAssignment( functionDecl ) ) {
    286                                 if ( ! dynamic_cast< TypeInstType* >( refType ) ) {
    287                                         scopedAssignOps.insert( refType->get_name(), functionDecl );
     312                        if ( Type *assignedType = isAssignment( functionDecl ) ) {
     313                                if ( ! dynamic_cast< TypeInstType* >( assignedType ) ) {
     314                                        scopedAssignOps.insert( assignedType, functionDecl );
    288315                                }
    289316                        }
     
    934961                        TyVarMap exprTyVars;
    935962                        makeTyVarMap( function, exprTyVars );
    936                         ReferenceToType *polyRetType = 0;
    937 
    938                         if ( polyRetType = isPolyRet( function ) ) {
     963                        ReferenceToType *polyRetType = isPolyRet( function );
     964
     965                        if ( polyRetType ) {
    939966                                ret = addPolyRetParam( appExpr, function, polyRetType, arg );
    940967                        } else if ( needsAdapter( function, scopeTyVars ) ) {
     
    10421069                                } else if ( ReferenceToType *refType = dynamic_cast< ReferenceToType *>( retval->get_type() ) ) {
    10431070                                        // find assignment operator for generic type
    1044                                         ScopedMap< std::string, DeclarationWithType *>::const_iterator assignIter = scopedAssignOps.find( refType->get_name() );
    1045                                         if ( assignIter == scopedAssignOps.end() ) {
     1071                                        DeclarationWithType *functionDecl = scopedAssignOps.find( refType );
     1072                                        if ( ! functionDecl ) {
    10461073                                                throw SemanticError( "Attempt to return dtype or ftype generic object in ", returnStmt->get_expr() );
    10471074                                        }
    10481075
    10491076                                        // wrap it up in an application expression
    1050                                         DeclarationWithType *functionDecl = assignIter->second;
    10511077                                        assignExpr = new ApplicationExpr( wrapFunctionDecl( functionDecl ) );
    10521078                                        assignExpr->set_env( env->clone() );
     
    10631089                                                assert( ! asserts.empty() && "Type param needs assignment operator assertion" );
    10641090                                                DeclarationWithType *actualDecl = asserts.front();
    1065                                                 ReferenceToType *actualType = isAssignment( actualDecl );
     1091                                                TypeInstType *actualType = isTypeInstAssignment( actualDecl );
    10661092                                                assert( actualType && "First assertion of type with assertions should be assignment operator" );
    10671093                                                TypeExpr *formalTypeExpr = dynamic_cast< TypeExpr* >( *tyIt );
     
    10771103                                                        }
    10781104                                                        assertAssign = assertAssignIt->second;
    1079                                                         //assignExpr->get_env()->add( formalTypeInstType->get_name(), actualType );
    1080                                                 } else if ( ReferenceToType *formalReferenceType = dynamic_cast< ReferenceToType* >( formalType ) )  {
    1081                                                         ScopedMap< std::string, DeclarationWithType *>::const_iterator assertAssignIt = scopedAssignOps.find( formalReferenceType->get_name() );
    1082                                                         if ( assertAssignIt == scopedAssignOps.end() ) {
    1083                                                                 throw SemanticError( "No assignment operation found for ", formalReferenceType );
     1105                                                } else {
     1106                                                        assertAssign = scopedAssignOps.find( formalType );
     1107                                                        if ( ! assertAssign ) {
     1108                                                                throw SemanticError( "No assignment operation found for ", formalType );
    10841109                                                        }
    1085                                                         assertAssign = assertAssignIt->second;
    1086                                                 } else assert( false && "returning polymorphic types with non struct/polymorphic parameters not yet supported" );
     1110                                                }
    10871111                                               
    10881112
     
    14241448                        assert( newMemberExpr );
    14251449
    1426                         // wrap pointer members in appropriate cast
    1427                         if ( dynamic_cast< PointerType* >( memberExpr->get_member()->get_type() ) ) {
    1428                                 CastExpr *ptrCastExpr = new CastExpr( newMemberExpr, new PointerType( Type::Qualifiers(), new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ) ) );
     1450                        Type *memberType = memberExpr->get_member()->get_type();
     1451                        if ( ! isPolyType( memberType, scopeTyVars ) ) {
     1452                                // 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
     1453                                CastExpr *ptrCastExpr = new CastExpr( newMemberExpr, new PointerType( Type::Qualifiers(), memberType->clone() ) );
    14291454                                UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
    14301455                                derefExpr->get_args().push_back( ptrCastExpr );
  • src/Makefile.in

    r41a2620 rac1ed49  
    171171        SynTree/driver_cfa_cpp-TypeofType.$(OBJEXT) \
    172172        SynTree/driver_cfa_cpp-AttrType.$(OBJEXT) \
     173        SynTree/driver_cfa_cpp-VarArgsType.$(OBJEXT) \
    173174        SynTree/driver_cfa_cpp-Constant.$(OBJEXT) \
    174175        SynTree/driver_cfa_cpp-Expression.$(OBJEXT) \
     
    369370        SynTree/ArrayType.cc SynTree/FunctionType.cc \
    370371        SynTree/ReferenceToType.cc SynTree/TupleType.cc \
    371         SynTree/TypeofType.cc SynTree/AttrType.cc SynTree/Constant.cc \
     372        SynTree/TypeofType.cc SynTree/AttrType.cc \
     373        SynTree/VarArgsType.cc SynTree/Constant.cc \
    372374        SynTree/Expression.cc SynTree/TupleExpr.cc \
    373375        SynTree/CommaExpr.cc SynTree/TypeExpr.cc \
     
    703705SynTree/driver_cfa_cpp-AttrType.$(OBJEXT): SynTree/$(am__dirstamp) \
    704706        SynTree/$(DEPDIR)/$(am__dirstamp)
     707SynTree/driver_cfa_cpp-VarArgsType.$(OBJEXT): SynTree/$(am__dirstamp) \
     708        SynTree/$(DEPDIR)/$(am__dirstamp)
    705709SynTree/driver_cfa_cpp-Constant.$(OBJEXT): SynTree/$(am__dirstamp) \
    706710        SynTree/$(DEPDIR)/$(am__dirstamp)
     
    867871        -rm -f SynTree/driver_cfa_cpp-TypeSubstitution.$(OBJEXT)
    868872        -rm -f SynTree/driver_cfa_cpp-TypeofType.$(OBJEXT)
     873        -rm -f SynTree/driver_cfa_cpp-VarArgsType.$(OBJEXT)
    869874        -rm -f SynTree/driver_cfa_cpp-Visitor.$(OBJEXT)
    870875        -rm -f SynTree/driver_cfa_cpp-VoidType.$(OBJEXT)
     
    974979@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-TypeSubstitution.Po@am__quote@
    975980@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-TypeofType.Po@am__quote@
     981@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-VarArgsType.Po@am__quote@
    976982@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-Visitor.Po@am__quote@
    977983@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-VoidType.Po@am__quote@
     
    20482054@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    20492055@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-AttrType.obj `if test -f 'SynTree/AttrType.cc'; then $(CYGPATH_W) 'SynTree/AttrType.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/AttrType.cc'; fi`
     2056
     2057SynTree/driver_cfa_cpp-VarArgsType.o: SynTree/VarArgsType.cc
     2058@am__fastdepCXX_TRUE@   $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-VarArgsType.o -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-VarArgsType.Tpo -c -o SynTree/driver_cfa_cpp-VarArgsType.o `test -f 'SynTree/VarArgsType.cc' || echo '$(srcdir)/'`SynTree/VarArgsType.cc
     2059@am__fastdepCXX_TRUE@   $(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-VarArgsType.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-VarArgsType.Po
     2060@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='SynTree/VarArgsType.cc' object='SynTree/driver_cfa_cpp-VarArgsType.o' libtool=no @AMDEPBACKSLASH@
     2061@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     2062@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-VarArgsType.o `test -f 'SynTree/VarArgsType.cc' || echo '$(srcdir)/'`SynTree/VarArgsType.cc
     2063
     2064SynTree/driver_cfa_cpp-VarArgsType.obj: SynTree/VarArgsType.cc
     2065@am__fastdepCXX_TRUE@   $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-VarArgsType.obj -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-VarArgsType.Tpo -c -o SynTree/driver_cfa_cpp-VarArgsType.obj `if test -f 'SynTree/VarArgsType.cc'; then $(CYGPATH_W) 'SynTree/VarArgsType.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/VarArgsType.cc'; fi`
     2066@am__fastdepCXX_TRUE@   $(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-VarArgsType.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-VarArgsType.Po
     2067@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='SynTree/VarArgsType.cc' object='SynTree/driver_cfa_cpp-VarArgsType.obj' libtool=no @AMDEPBACKSLASH@
     2068@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     2069@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-VarArgsType.obj `if test -f 'SynTree/VarArgsType.cc'; then $(CYGPATH_W) 'SynTree/VarArgsType.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/VarArgsType.cc'; fi`
    20502070
    20512071SynTree/driver_cfa_cpp-Constant.o: SynTree/Constant.cc
  • src/ResolvExpr/AdjustExprType.cc

    r41a2620 rac1ed49  
    3636                virtual Type* mutate( TypeInstType *aggregateUseType );
    3737                virtual Type* mutate( TupleType *tupleType );
     38                virtual Type* mutate( VarArgsType *varArgsType );
    3839
    3940                const TypeEnvironment &env;
     
    111112                return tupleType;
    112113        }
     114
     115        Type *AdjustExprType::mutate( VarArgsType *varArgsType ) {
     116                return varArgsType;
     117        }
    113118} // namespace ResolvExpr
    114119
  • src/ResolvExpr/AlternativeFinder.cc

    r41a2620 rac1ed49  
    572572
    573573                AltList candidates;
     574                SemanticError errors;
    574575
    575576                for ( AltList::const_iterator func = funcFinder.alternatives.begin(); func != funcFinder.alternatives.end(); ++func ) {
    576                         PRINT(
    577                                 std::cerr << "working on alternative: " << std::endl;
    578                                 func->print( std::cerr, 8 );
    579                         )
    580                         // check if the type is pointer to function
    581                         PointerType *pointer;
    582                         if ( func->expr->get_results().size() == 1 && ( pointer = dynamic_cast< PointerType* >( func->expr->get_results().front() ) ) ) {
    583                                 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
    584                                         for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
    585                                                 // XXX
    586                                                 //Designators::check_alternative( function, *actualAlt );
    587                                                 makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) );
    588                                         }
    589                                 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( pointer->get_base() ) ) {
    590                                         EqvClass eqvClass;
    591                                         if ( func->env.lookup( typeInst->get_name(), eqvClass ) && eqvClass.type ) {
    592                                                 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) {
    593                                                         for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
    594                                                                 makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) );
    595                                                         } // for
     577                        try {
     578                                PRINT(
     579                                        std::cerr << "working on alternative: " << std::endl;
     580                                        func->print( std::cerr, 8 );
     581                                )
     582                                // check if the type is pointer to function
     583                                PointerType *pointer;
     584                                if ( func->expr->get_results().size() == 1 && ( pointer = dynamic_cast< PointerType* >( func->expr->get_results().front() ) ) ) {
     585                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
     586                                                for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
     587                                                        // XXX
     588                                                        //Designators::check_alternative( function, *actualAlt );
     589                                                        makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) );
     590                                                }
     591                                        } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( pointer->get_base() ) ) {
     592                                                EqvClass eqvClass;
     593                                                if ( func->env.lookup( typeInst->get_name(), eqvClass ) && eqvClass.type ) {
     594                                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) {
     595                                                                for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
     596                                                                        makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) );
     597                                                                } // for
     598                                                        } // if
    596599                                                } // if
    597600                                        } // if
     601                                } else {
     602                                        // seek a function operator that's compatible
     603                                        if ( ! doneInit ) {
     604                                                doneInit = true;
     605                                                NameExpr *opExpr = new NameExpr( "?()" );
     606                                                try {
     607                                                        funcOpFinder.findWithAdjustment( opExpr );
     608                                                } catch( SemanticError &e ) {
     609                                                        // it's ok if there aren't any defined function ops
     610                                                }
     611                                                PRINT(
     612                                                        std::cerr << "known function ops:" << std::endl;
     613                                                        printAlts( funcOpFinder.alternatives, std::cerr, 8 );
     614                                                )
     615                                        }
     616
     617                                        for ( AltList::const_iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) {
     618                                                // check if the type is pointer to function
     619                                                PointerType *pointer;
     620                                                if ( funcOp->expr->get_results().size() == 1
     621                                                        && ( pointer = dynamic_cast< PointerType* >( funcOp->expr->get_results().front() ) ) ) {
     622                                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
     623                                                                for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
     624                                                                        AltList currentAlt;
     625                                                                        currentAlt.push_back( *func );
     626                                                                        currentAlt.insert( currentAlt.end(), actualAlt->begin(), actualAlt->end() );
     627                                                                        makeFunctionAlternatives( *funcOp, function, currentAlt, std::back_inserter( candidates ) );
     628                                                                } // for
     629                                                        } // if
     630                                                } // if
     631                                        } // for
    598632                                } // if
    599                         } else {
    600                                 // seek a function operator that's compatible
    601                                 if ( ! doneInit ) {
    602                                         doneInit = true;
    603                                         NameExpr *opExpr = new NameExpr( "?()" );
    604                                         try {
    605                                                 funcOpFinder.findWithAdjustment( opExpr );
    606                                         } catch( SemanticError &e ) {
    607                                                 // it's ok if there aren't any defined function ops
    608                                         }
    609                                         PRINT(
    610                                                 std::cerr << "known function ops:" << std::endl;
    611                                                 printAlts( funcOpFinder.alternatives, std::cerr, 8 );
    612                                         )
    613                                 }
    614 
    615                                 for ( AltList::const_iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) {
    616                                         // check if the type is pointer to function
    617                                         PointerType *pointer;
    618                                         if ( funcOp->expr->get_results().size() == 1
    619                                                  && ( pointer = dynamic_cast< PointerType* >( funcOp->expr->get_results().front() ) ) ) {
    620                                                 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
    621                                                         for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
    622                                                                 AltList currentAlt;
    623                                                                 currentAlt.push_back( *func );
    624                                                                 currentAlt.insert( currentAlt.end(), actualAlt->begin(), actualAlt->end() );
    625                                                                 makeFunctionAlternatives( *funcOp, function, currentAlt, std::back_inserter( candidates ) );
    626                                                         } // for
    627                                                 } // if
    628                                         } // if
    629                                 } // for
    630                         } // if
    631                 } // for
     633                        } catch ( SemanticError &e ) {
     634                                errors.append( e );
     635                        }
     636                } // for
     637
     638                // Implement SFINAE; resolution errors are only errors if there aren't any non-erroneous resolutions
     639                if ( candidates.empty() && ! errors.isEmpty() ) { throw errors; }
    632640
    633641                for ( AltList::iterator withFunc = candidates.begin(); withFunc != candidates.end(); ++withFunc ) {
  • src/ResolvExpr/CommonType.cc

    r41a2620 rac1ed49  
    3838                virtual void visit( TypeInstType *aggregateUseType );
    3939                virtual void visit( TupleType *tupleType );
     40                virtual void visit( VarArgsType *varArgsType );
    4041
    4142                template< typename RefType > void handleRefType( RefType *inst, Type *other );
     
    213214        void CommonType::visit( TupleType *tupleType ) {
    214215        }
     216
     217        void CommonType::visit( VarArgsType *varArgsType ) {
     218        }
    215219} // namespace ResolvExpr
    216220
  • src/ResolvExpr/ConversionCost.cc

    r41a2620 rac1ed49  
    247247                } // if
    248248        }
     249
     250        void ConversionCost::visit(VarArgsType *varArgsType) {
     251                if ( VarArgsType *destAsVarArgs = dynamic_cast< VarArgsType* >( dest ) ) {
     252                        cost = Cost::zero;
     253                }
     254        }
    249255} // namespace ResolvExpr
    250256
  • src/ResolvExpr/ConversionCost.h

    r41a2620 rac1ed49  
    4040                virtual void visit(TypeInstType *aggregateUseType);
    4141                virtual void visit(TupleType *tupleType);
     42                virtual void visit(VarArgsType *varArgsType);
    4243          protected:
    4344                Type *dest;
  • src/ResolvExpr/PtrsAssignable.cc

    r41a2620 rac1ed49  
    3838                virtual void visit( TypeInstType *inst );
    3939                virtual void visit( TupleType *tupleType );
     40                virtual void visit( VarArgsType *varArgsType );
    4041          private:
    4142                Type *dest;
     
    137138///   }
    138139        }
     140
     141        void PtrsAssignable::visit( VarArgsType *varArgsType ) {
     142        }
    139143} // namespace ResolvExpr
    140144
  • src/ResolvExpr/PtrsCastable.cc

    r41a2620 rac1ed49  
    3939                virtual void visit(TypeInstType *inst);
    4040                virtual void visit(TupleType *tupleType);
     41                virtual void visit(VarArgsType *varArgsType);
    4142          private:
    4243                Type *dest;
     
    139140                result = objectCast( dest, env, indexer );
    140141        }
     142
     143        void PtrsCastable::visit(VarArgsType *varArgsType) {
     144                result = objectCast( dest, env, indexer );
     145        }
    141146} // namespace ResolvExpr
    142147
  • src/ResolvExpr/RenameVars.cc

    r41a2620 rac1ed49  
    113113        }
    114114
     115        void RenameVars::visit( VarArgsType *varArgsType ) {
     116                typeBefore( varArgsType );
     117                typeAfter( varArgsType );
     118        }
     119
    115120        void RenameVars::typeBefore( Type *type ) {
    116121                if ( ! type->get_forall().empty() ) {
  • src/ResolvExpr/RenameVars.h

    r41a2620 rac1ed49  
    4343                virtual void visit( TypeInstType *aggregateUseType );
    4444                virtual void visit( TupleType *tupleType );
     45                virtual void visit( VarArgsType *varArgsType );
    4546
    4647                void typeBefore( Type *type );
  • src/ResolvExpr/Unify.cc

    r41a2620 rac1ed49  
    5959                virtual void visit(TypeInstType *aggregateUseType);
    6060                virtual void visit(TupleType *tupleType);
     61                virtual void visit(VarArgsType *varArgsType);
    6162
    6263                template< typename RefType > void handleRefType( RefType *inst, Type *other );
     
    583584        }
    584585
     586        void Unify::visit(VarArgsType *varArgsType) {
     587                result = dynamic_cast< VarArgsType* >( type2 );
     588        }
     589
    585590} // namespace ResolvExpr
    586591
  • src/SymTab/FixFunction.cc

    r41a2620 rac1ed49  
    7272                return tupleType;
    7373        }
     74
     75        Type * FixFunction::mutate(VarArgsType *varArgsType) {
     76                return varArgsType;
     77        }
    7478} // namespace SymTab
    7579
  • src/SymTab/FixFunction.h

    r41a2620 rac1ed49  
    4141                virtual Type* mutate(TypeInstType *aggregateUseType);
    4242                virtual Type* mutate(TupleType *tupleType);
     43                virtual Type* mutate(VarArgsType *varArgsType);
    4344 
    4445                bool isVoid;
  • src/SymTab/ImplementationType.cc

    r41a2620 rac1ed49  
    4040                virtual void visit(TypeInstType *aggregateUseType);
    4141                virtual void visit(TupleType *tupleType);
     42                virtual void visit(VarArgsType *varArgsType);
    4243
    4344                Type *result;                   // synthesized
     
    116117                result = newType;
    117118        }
     119
     120        void ImplementationType::visit(VarArgsType *varArgsType) {
     121        }
    118122} // namespace SymTab
    119123
  • src/SymTab/Mangler.cc

    r41a2620 rac1ed49  
    224224                acceptAll( tupleType->get_types(), *this );
    225225                mangleName << "_";
     226        }
     227
     228        void Mangler::visit( VarArgsType *varArgsType ) {
     229                mangleName << "VARGS";
    226230        }
    227231
  • src/SymTab/Mangler.h

    r41a2620 rac1ed49  
    4545                virtual void visit( TypeInstType *aggregateUseType );
    4646                virtual void visit( TupleType *tupleType );
     47                virtual void visit( VarArgsType *varArgsType );
    4748 
    4849                std::string get_mangleName() { return mangleName.str(); }
  • src/SymTab/TypeEquality.cc

    r41a2620 rac1ed49  
    4141                virtual void visit( EnumInstType *enumInst );
    4242                virtual void visit( TypeInstType *typeInst );
     43                virtual void visit( VarArgsType *varArgsType );
    4344
    4445                void handleQualifiers( Type * t );
     
    191192                }
    192193        }
     194
     195        void TypeEquality::visit( VarArgsType *varArgsType ) {
     196                // don't handle qualifiers; var args pack shouldn't have any
     197                if ( ! dynamic_cast< VarArgsType * >( other ) ) {
     198                        result = false;
     199                }
     200        }
    193201} // namespace SymTab
  • src/SynTree/Mutator.cc

    r41a2620 rac1ed49  
    421421}
    422422
     423Type *Mutator::mutate( VarArgsType *varArgsType ) {
     424        mutateAll( varArgsType->get_forall(), *this );
     425        return varArgsType;
     426}
     427
    423428Initializer *Mutator::mutate( SingleInit *singleInit ) {
    424429        singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) );
  • src/SynTree/Mutator.h

    r41a2620 rac1ed49  
    9090        virtual Type* mutate( TypeofType *typeofType );
    9191        virtual Type* mutate( AttrType *attrType );
     92        virtual Type* mutate( VarArgsType *varArgsType );
    9293
    9394        virtual Initializer* mutate( SingleInit *singleInit );
  • src/SynTree/SynTree.h

    r41a2620 rac1ed49  
    9797class TypeofType;
    9898class AttrType;
     99class VarArgsType;
    99100
    100101class Initializer;
  • src/SynTree/Type.h

    r41a2620 rac1ed49  
    400400};
    401401
     402/// Represents the GCC built-in varargs type
     403class VarArgsType : public Type {
     404        VarArgsType();
     405
     406        virtual VarArgsType *clone() const { return new VarArgsType( *this ); }
     407        virtual void accept( Visitor &v ) { v.visit( this ); }
     408        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     409        virtual void print( std::ostream &os, int indent = 0 ) const;
     410};
     411
    402412inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) {
    403413        isConst |= other.isConst;
  • src/SynTree/TypeSubstitution.cc

    r41a2620 rac1ed49  
    198198}
    199199
     200Type * TypeSubstitution::mutate( VarArgsType *varArgsType ) {
     201        return handleType( varArgsType );
     202}
     203
    200204void TypeSubstitution::print( std::ostream &os, int indent ) const {
    201205        os << std::string( indent, ' ' ) << "Types:" << std::endl;
  • src/SynTree/TypeSubstitution.h

    r41a2620 rac1ed49  
    7474        virtual Type* mutate(ContextInstType *aggregateUseType);
    7575        virtual Type* mutate(TupleType *tupleType);
     76        virtual Type* mutate(VarArgsType *varArgsType);
    7677       
    7778        // TODO: worry about traversing into a forall-qualified function type or type decl with assertions
  • src/SynTree/Visitor.cc

    r41a2620 rac1ed49  
    355355}
    356356
     357void Visitor::visit( VarArgsType *varArgsType ) {
     358        acceptAll( varArgsType->get_forall(), *this );
     359}
     360
    357361void Visitor::visit( SingleInit *singleInit ) {
    358362        singleInit->get_value()->accept( *this );
  • src/SynTree/Visitor.h

    r41a2620 rac1ed49  
    9090        virtual void visit( TypeofType *typeofType );
    9191        virtual void visit( AttrType *attrType );
     92        virtual void visit( VarArgsType *varArgsType );
    9293
    9394        virtual void visit( SingleInit *singleInit );
  • src/SynTree/module.mk

    r41a2620 rac1ed49  
    2525       SynTree/TypeofType.cc \
    2626       SynTree/AttrType.cc \
     27       SynTree/VarArgsType.cc \
    2728       SynTree/Constant.cc \
    2829       SynTree/Expression.cc \
Note: See TracChangeset for help on using the changeset viewer.