Changeset 028e512


Ignore:
Timestamp:
Apr 19, 2023, 11:58:01 AM (19 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master
Children:
45e753c
Parents:
a5ea261
Message:

Cleaned up some DeclarationNode? code that had some extra code no longer needed because of the translation. Also added a helper function for clarity.

Location:
src/Parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    ra5ea261 r028e512  
    10531053                                        unionDecl = dynamic_cast<ast::UnionDecl *>( decl );
    10541054
    1055                                         decl->location = cur->location;
    10561055                                        *out++ = decl;
    10571056
     
    11211120                                                } // if
    11221121                                        } // if
    1123                                         decl->location = cur->location;
    11241122                                        *out++ = decl;
    11251123                                } // if
  • src/Parser/DeclarationNode.h

    ra5ea261 r028e512  
    177177}
    178178
     179template<typename NodeType>
     180NodeType * strict_next( NodeType * node ) {
     181        ParseNode * next = node->get_next();
     182        if ( nullptr == next ) return nullptr;
     183        if ( NodeType * ret = dynamic_cast<NodeType *>( next ) ) return ret;
     184        SemanticError( next->location, "internal error, non-homogeneous nodes founds in buildList processing." );
     185}
     186
    179187// This generic buildList is here along side its overloads.
    180188template<typename AstType, typename NodeType,
     
    184192        SemanticErrorException errors;
    185193        std::back_insert_iterator<Container<ast::ptr<AstType>, Args...>> out( output );
    186         NodeType * cur = firstNode;
    187 
    188         while ( cur ) {
     194
     195        for ( NodeType * cur = firstNode ; cur ; cur = strict_next( cur ) ) {
    189196                try {
    190                         if ( auto result = dynamic_cast<AstType *>( maybeBuild( cur ) ) ) {
    191                                 *out++ = result;
    192                         } else {
    193                                 assertf(false, __PRETTY_FUNCTION__ );
    194                                 SemanticError( cur->location, "type specifier declaration in forall clause is currently unimplemented." );
    195                         } // if
    196                 } catch( SemanticErrorException & e ) {
     197                        AstType * node = dynamic_cast<AstType *>( maybeBuild( cur ) );
     198                        assertf( node, "buildList: Did not build node of correct type." );
     199                        *out++ = node;
     200                } catch ( SemanticErrorException & e ) {
    197201                        errors.append( e );
    198202                } // try
    199                 ParseNode * temp = cur->get_next();
    200                 // Should not return nullptr, then it is non-homogeneous:
    201                 cur = dynamic_cast<NodeType *>( temp );
    202                 if ( !cur && temp ) {
    203                         SemanticError( temp->location, "internal error, non-homogeneous nodes founds in buildList processing." );
    204                 } // if
    205         } // while
     203        } // for
    206204        if ( ! errors.isEmpty() ) {
    207205                throw errors;
Note: See TracChangeset for help on using the changeset viewer.