Changes in / [0dc954b:b1e68d03]


Ignore:
Location:
src
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AdjustExprType.cc

    r0dc954b rb1e68d03  
    2828                void premutate( BasicType * ) { visit_children = false; }
    2929                void premutate( PointerType * ) { visit_children = false; }
     30                void premutate( ArrayType * ) { visit_children = false; }
    3031                void premutate( FunctionType * ) { visit_children = false; }
    3132                void premutate( StructInstType * ) { visit_children = false; }
     
    5960
    6061        Type * AdjustExprType::postmutate( ArrayType * arrayType ) {
    61                 // need to recursively mutate the base type in order for multi-dimensional arrays to work.
    6262                PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base );
    6363                arrayType->base = nullptr;
  • src/ResolvExpr/AlternativeFinder.cc

    r0dc954b rb1e68d03  
    180180                        throw SemanticError( "No reasonable alternatives for expression ", expr );
    181181                }
    182                 for ( AltList::iterator i = alternatives.begin(); i != alternatives.end(); ++i ) {
    183                         if ( adjust ) {
    184                                 adjustExprType( i->expr->get_result(), i->env, indexer );
    185                         }
    186                 }
    187182                if ( prune ) {
    188183                        PRINT(
     
    206201                                std::cerr << "there are " << alternatives.size() << " alternatives after elimination" << std::endl;
    207202                        )
     203                }
     204                // adjust types after pruning so that types substituted by pruneAlternatives are correctly adjusted
     205                for ( AltList::iterator i = alternatives.begin(); i != alternatives.end(); ++i ) {
     206                        if ( adjust ) {
     207                                adjustExprType( i->expr->get_result(), i->env, indexer );
     208                        }
    208209                }
    209210
  • src/ResolvExpr/Unify.cc

    r0dc954b rb1e68d03  
    1717#include <iterator>               // for back_insert_iterator, back_inserter
    1818#include <map>                    // for _Rb_tree_const_iterator, _Rb_tree_i...
    19 #include <memory>                 // for unique_ptr, auto_ptr
     19#include <memory>                 // for unique_ptr
    2020#include <set>                    // for set
    2121#include <string>                 // for string, operator==, operator!=, bas...
     
    170170                                Type *common = 0;
    171171                                // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to
    172                                 std::auto_ptr< Type > newType( curClass.type->clone() );
     172                                std::unique_ptr< Type > newType( curClass.type->clone() );
    173173                                newType->get_qualifiers() = typeInst->get_qualifiers();
    174174                                if ( unifyInexact( newType.get(), other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass.allowWidening, true ), indexer, common ) ) {
     
    459459                if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() ) {
    460460
    461                         // not positive this is correct in all cases, but it's needed for typedefs
    462                         if ( arrayType->get_isVarLen() || otherArray->get_isVarLen() ) {
    463                                 return;
    464                         }
    465 
    466461                        if ( ! arrayType->get_isVarLen() && ! otherArray->get_isVarLen() &&
    467462                                arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0 ) {
  • src/SymTab/FixFunction.cc

    r0dc954b rb1e68d03  
    5050
    5151        void FixFunction::premutate(FunctionDecl *) { visit_children = false; }
     52        void FixFunction::premutate(ArrayType *) { visit_children = false; }
    5253        void FixFunction::premutate(BasicType *) { visit_children = false; }
    5354        void FixFunction::premutate(PointerType *) { visit_children = false; }
  • src/SymTab/FixFunction.h

    r0dc954b rb1e68d03  
    3131                Type * postmutate(ArrayType * arrayType);
    3232
     33                void premutate(ArrayType * arrayType);
    3334                void premutate(VoidType * voidType);
    3435                void premutate(BasicType * basicType);
  • src/SymTab/Validate.cc

    r0dc954b rb1e68d03  
    668668                }
    669669                filter( translationUnit, isTypedef, true );
    670 
    671670        }
    672671
     
    676675                TypedefMap::const_iterator def = typedefNames.find( typeInst->get_name() );
    677676                if ( def != typedefNames.end() ) {
    678                         Type *ret = def->second.first->get_base()->clone();
     677                        Type *ret = def->second.first->base->clone();
    679678                        ret->get_qualifiers() |= typeInst->get_qualifiers();
    680679                        // place instance parameters on the typedef'd type
    681                         if ( ! typeInst->get_parameters().empty() ) {
     680                        if ( ! typeInst->parameters.empty() ) {
    682681                                ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret);
    683682                                if ( ! rtt ) {
    684                                         throw SemanticError("cannot apply type parameters to base type of " + typeInst->get_name());
     683                                        throw SemanticError("Cannot apply type parameters to base type of " + typeInst->name);
    685684                                }
    686685                                rtt->get_parameters().clear();
    687                                 cloneAll( typeInst->get_parameters(), rtt->get_parameters() );
    688                                 mutateAll( rtt->get_parameters(), *visitor );  // recursively fix typedefs on parameters
     686                                cloneAll( typeInst->parameters, rtt->parameters );
     687                                mutateAll( rtt->parameters, *visitor );  // recursively fix typedefs on parameters
    689688                        } // if
    690689                        delete typeInst;
     
    692691                } else {
    693692                        TypeDeclMap::const_iterator base = typedeclNames.find( typeInst->get_name() );
    694                         assertf( base != typedeclNames.end(), "Cannot find typedecl name %s", typeInst->get_name().c_str() );
     693                        assertf( base != typedeclNames.end(), "Cannot find typedecl name %s", typeInst->name.c_str() );
    695694                        typeInst->set_baseType( base->second );
    696695                } // if
    697696                return typeInst;
     697        }
     698
     699        struct VarLenChecker : WithShortCircuiting {
     700                void previsit( FunctionType * ) { visit_children = false; }
     701                void previsit( ArrayType * at ) {
     702                        isVarLen |= at->isVarLen;
     703                }
     704                bool isVarLen = false;
     705        };
     706
     707        bool isVariableLength( Type * t ) {
     708                PassVisitor<VarLenChecker> varLenChecker;
     709                maybeAccept( t, varLenChecker );
     710                return varLenChecker.pass.isVarLen;
    698711        }
    699712
     
    706719                        Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
    707720                        if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) {
    708                                 throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
     721                                throw SemanticError( "Cannot redefine typedef: " + tyDecl->name );
     722                        }
     723                        // cannot redefine VLA typedefs
     724                        if ( isVariableLength( t1 ) || isVariableLength( t2 ) ) {
     725                                throw SemanticError( "Cannot redefine typedef: " + tyDecl->name );
    709726                        }
    710727                } else {
  • src/SynTree/Type.h

    r0dc954b rb1e68d03  
    298298        void set_isStatic( bool newValue ) { isStatic = newValue; }
    299299
    300         virtual bool isComplete() const override { return ! isVarLen; }
     300        // array types are complete if they have a dimension expression or are
     301        // VLAs ('*' in parameter declaration), and incomplete otherwise.
     302        // See 6.7.6.2
     303        virtual bool isComplete() const override { return dimension || isVarLen; }
    301304
    302305        virtual ArrayType *clone() const override { return new ArrayType( *this ); }
  • src/tests/.expect/castError.txt

    r0dc954b rb1e68d03  
    44... to:
    55  charAlternatives are:
    6 Cost ( 1, 0, 0, 0 ): Cast of:
    7      Variable Expression: f: function
    8        accepting unspecified arguments
    9      ... returning nothing
    10 
    11    ... to:
    12      char
    13  (types:
    14    char
    15  )
    16  Environment:
    17 
    186Cost ( 1, 0, 0, 0 ): Cast of:
    197     Variable Expression: f: signed int
     
    3422 Environment:
    3523
     24Cost ( 1, 0, 0, 0 ): Cast of:
     25     Variable Expression: f: function
     26       accepting unspecified arguments
     27     ... returning nothing
    3628
     29   ... to:
     30     char
     31 (types:
     32   char
     33 )
     34 Environment:
     35
     36
  • src/tests/Makefile.am

    r0dc954b rb1e68d03  
    138138completeTypeError : completeTypeError.c @CFA_BINDIR@/@CFA_NAME@
    139139        ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
     140
     141typedefRedef-ERR1: typedefRedef.c @CFA_BINDIR@/@CFA_NAME@
     142        ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
  • src/tests/Makefile.in

    r0dc954b rb1e68d03  
    892892        ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
    893893
     894typedefRedef-ERR1: typedefRedef.c @CFA_BINDIR@/@CFA_NAME@
     895        ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
     896
    894897# Tell versions [3.59,3.63) of GNU make to not export all variables.
    895898# Otherwise a system limit (for SysV at least) may be exceeded.
Note: See TracChangeset for help on using the changeset viewer.