Ignore:
Timestamp:
Feb 16, 2017, 3:36:45 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
317450e
Parents:
c3d9adc
Message:

handle KR function declarations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TypeData.cc

    rc3d9adc r3a5131ed  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jan 27 15:28:56 2017
    13 // Update Count     : 428
     12// Last Modified On : Thu Feb 16 15:06:59 2017
     13// Update Count     : 455
    1414//
    1515
     
    724724Declaration * buildDecl( const TypeData * td, const string &name, DeclarationNode::StorageClass sc, Expression * bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, ConstantExpr *asmName, Initializer * init, std::list< Attribute * > attributes ) {
    725725        if ( td->kind == TypeData::Function ) {
     726                if ( td->function.idList ) {
     727                        buildKRFunction( td->function );
     728                } // if
     729
    726730                FunctionDecl * decl;
    727731                if ( td->function.hasBody ) {
     
    738742                        decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), nullptr, isInline, isNoreturn, attributes );
    739743                } // if
    740                 for ( DeclarationNode * cur = td->function.idList; cur != nullptr; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {
    741                         if ( cur->name ) {
    742                                 decl->get_oldIdents().insert( decl->get_oldIdents().end(), *cur->name );
    743                         } // if
    744                 } // for
    745                 buildList( td->function.oldDeclList, decl->get_oldDecls() );
    746744                return decl->set_asmName( asmName );
    747745        } else if ( td->kind == TypeData::Aggregate ) {
     
    778776} // buildFunction
    779777
     778void buildKRFunction( const TypeData::Function_t & function ) {
     779        assert( ! function.params );
     780        for ( DeclarationNode * decl = function.oldDeclList; decl != nullptr; decl = dynamic_cast< DeclarationNode* >( decl->get_next() ) ) {
     781                for ( DeclarationNode * param = function.idList; param != nullptr; param = dynamic_cast< DeclarationNode* >( param->get_next() ) ) {
     782                        if ( *decl->name == *param->name ) {
     783                                if ( param->type ) throw SemanticError( string( "duplicate declaration name " ) + *param->name );
     784                                if ( ! decl->type ) throw SemanticError( string( "duplicate parameter name " ) + *param->name );
     785                                param->type = decl->type;
     786                                decl->type = nullptr;
     787                                param->attributes.splice( param->attributes.end(), decl->attributes );
     788                        } // if
     789                } // for
     790                if ( decl->type ) throw SemanticError( string( "missing name in parameter list " ) + *decl->name );
     791        } // for
     792        for ( DeclarationNode * param = function.idList; param != nullptr; param = dynamic_cast< DeclarationNode* >( param->get_next() ) ) {
     793                if ( ! param->type ) {
     794                        param->type = new TypeData( TypeData::Basic );
     795                        param->type->basictype = DeclarationNode::Int;
     796                } // if
     797        } // for
     798
     799        function.params = function.idList;
     800        function.idList = nullptr;
     801        delete function.oldDeclList;
     802        function.oldDeclList = nullptr;
     803} // buildKRFunction
     804
    780805// Local Variables: //
    781806// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.