Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    rbd7e609 rf53836b  
    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 {
Note: See TracChangeset for help on using the changeset viewer.