Changeset 3a5131ed for src/Parser


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

Location:
src/Parser
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rc3d9adc r3a5131ed  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb  9 15:54:59 2017
    13 // Update Count     : 742
     12// Last Modified On : Thu Feb 16 13:06:50 2017
     13// Update Count     : 753
    1414//
    1515
     
    913913        SemanticError errors;
    914914        std::back_insert_iterator< std::list< Declaration * > > out( outputList );
    915         const DeclarationNode * cur = firstNode;
    916 
    917         while ( cur ) {
     915
     916        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    918917                try {
    919918                        if ( DeclarationNode * extr = cur->extractAggregate() ) {
     
    936935                        errors.append( e );
    937936                } // try
    938                 cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    939937        } // while
    940938
     
    947945        SemanticError errors;
    948946        std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
    949         const DeclarationNode * cur = firstNode;
    950         while ( cur ) {
     947       
     948        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    951949                try {
    952950                        Declaration * decl = cur->build();
     
    972970                        errors.append( e );
    973971                } // try
    974                 cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    975         } // while
     972        } // for
     973
    976974        if ( ! errors.isEmpty() ) {
    977975                throw errors;
  • src/Parser/ParseNode.h

    rc3d9adc r3a5131ed  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb  9 14:45:28 2017
    13 // Update Count     : 658
     12// Last Modified On : Thu Feb 16 13:15:55 2017
     13// Update Count     : 661
    1414//
    1515
     
    437437template< typename SynTreeType, typename NodeType >
    438438void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {
    439         buildList(firstNode, outputList);
     439        buildList( firstNode, outputList );
    440440        delete firstNode;
    441441}
  • 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 //
  • src/Parser/TypeData.h

    rc3d9adc r3a5131ed  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb  2 17:02:09 2017
    13 // Update Count     : 146
     12// Last Modified On : Thu Feb 16 14:30:05 2017
     13// Update Count     : 153
    1414//
    1515
     
    5252
    5353        struct Function_t {
    54                 DeclarationNode * params;
    55                 DeclarationNode * idList;                                               // old-style
    56                 DeclarationNode * oldDeclList;
     54                mutable DeclarationNode * params;                               // mutables modified in buildKRFunction
     55                mutable DeclarationNode * idList;                               // old-style
     56                mutable DeclarationNode * oldDeclList;
    5757                StatementNode * body;
    5858                bool hasBody;
     
    113113Declaration * buildDecl( const TypeData *, const std::string &, DeclarationNode::StorageClass, Expression *, bool isInline, bool isNoreturn, LinkageSpec::Spec, ConstantExpr *asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );
    114114FunctionType * buildFunction( const TypeData * );
     115void buildKRFunction( const TypeData::Function_t & function );
    115116
    116117#endif // TYPEDATA_H
Note: See TracChangeset for help on using the changeset viewer.