Changeset 16ba4897


Ignore:
Timestamp:
Oct 9, 2024, 5:07:59 PM (21 hours ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
0766399
Parents:
1b770e40
Message:

Replaced SemanticErrorException::isEmpty with ...::throwIfNonEmpty. This is how it was used in every context and it saves a bit of text (if not two lines) at every use. I considered putting this function in the header for better inlining, but this should have at least the same preformance as the last version.

Location:
src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.hpp

    r1b770e40 r16ba4897  
    161161                }
    162162        }
    163         if ( ! errors.isEmpty() ) {
    164                 throw errors;
    165         }
     163        errors.throwIfNonEmpty();
    166164}
    167165
  • src/AST/Pass.impl.hpp

    r1b770e40 r16ba4897  
    250250        }
    251251        pass_visitor_stats.depth--;
    252         if ( !errors.isEmpty() ) { throw errors; }
     252        errors.throwIfNonEmpty();
    253253
    254254        return new_kids;
     
    287287        __pedantic_pass_assert( new_kids.size() == container.size() );
    288288        pass_visitor_stats.depth--;
    289         if ( !errors.isEmpty() ) { throw errors; }
     289        errors.throwIfNonEmpty();
    290290
    291291        return ast::__pass::resultN<container_t, node_t>{ mutated, new_kids };
     
    401401        }
    402402        pass_visitor_stats.depth--;
    403         if ( !errors.isEmpty() ) { throw errors; }
     403        errors.throwIfNonEmpty();
    404404}
    405405
  • src/Common/ErrorObjects.hpp

    r1b770e40 r16ba4897  
    4141        void append( SemanticErrorException & other );
    4242        void append( CodeLocation location, const std::string & );
    43         bool isEmpty() const;
     43        void throwIfNonEmpty();
    4444        void print();
    4545  private:
  • src/Common/SemanticError.cpp

    r1b770e40 r16ba4897  
    8888}
    8989
    90 bool SemanticErrorException::isEmpty() const {
    91         return errors.empty();
     90void SemanticErrorException::throwIfNonEmpty() {
     91        if ( !errors.empty() ) {
     92                throw *this;
     93        }
    9294}
    9395
  • src/ControlStruct/MultiLevelExit.cpp

    r1b770e40 r16ba4897  
    688688        }
    689689
    690         if ( !errors.isEmpty() ) {
    691                 throw errors;
    692         }
     690        errors.throwIfNonEmpty();
    693691        return ret;
    694692}
  • src/InitTweak/FixInit.cpp

    r1b770e40 r16ba4897  
    301301                } // try
    302302        } // for
    303         if ( ! errors.isEmpty() ) {
    304                 throw errors;
    305         } // if
     303        errors.throwIfNonEmpty();
    306304}
    307305
     
    11731171                function->stmts = mutStmts;
    11741172        }
    1175         if (! errors.isEmpty()) {
    1176                 throw errors;
    1177         }
     1173        errors.throwIfNonEmpty();
    11781174        return function;
    11791175}
  • src/Parser/DeclarationNode.cpp

    r1b770e40 r16ba4897  
    829829        } // for
    830830
    831         if ( ! errors.isEmpty() ) {
    832                 throw errors;
    833         } // if
     831        errors.throwIfNonEmpty();
    834832} // buildList
    835833
     
    879877        } // for
    880878
    881         if ( ! errors.isEmpty() ) {
    882                 throw errors;
    883         } // if
     879        errors.throwIfNonEmpty();
    884880} // buildList
    885881
     
    897893        } // for
    898894
    899         if ( ! errors.isEmpty() ) {
    900                 throw errors;
    901         } // if
     895        errors.throwIfNonEmpty();
    902896} // buildTypeList
    903897
  • src/Parser/DeclarationNode.hpp

    r1b770e40 r16ba4897  
    156156                } // try
    157157        } // for
    158         if ( ! errors.isEmpty() ) {
    159                 throw errors;
    160         } // if
     158        errors.throwIfNonEmpty();
    161159}
    162160
  • src/ResolvExpr/CandidateFinder.cpp

    r1b770e40 r16ba4897  
    11151115                // Implement SFINAE; resolution errors are only errors if there aren't any non-error
    11161116                // candidates
    1117                 if ( found.empty() && ! errors.isEmpty() ) { throw errors; }
     1117                if ( found.empty() ) errors.throwIfNonEmpty();
    11181118
    11191119                // only keep the best matching intrinsic result to match C semantics (no unexpected narrowing/widening)
  • src/Validate/CheckAssertions.cpp

    r1b770e40 r16ba4897  
    6060                makeTypeVarMap( decl, typeVars );
    6161                checkList( typeVars, errors, decl->assertions );
    62                 if ( !errors.isEmpty() ) { throw errors; }
     62                errors.throwIfNonEmpty();
    6363        }
    6464
     
    7272                }
    7373                if ( checkMembers ) checkList( typeVars, errors, decl->members );
    74                 if ( !errors.isEmpty() ) { throw errors; }
     74                errors.throwIfNonEmpty();
    7575        }
    7676
  • src/Validate/ReplaceTypedef.cpp

    r1b770e40 r16ba4897  
    327327        assert( declsToAddBefore.empty() );
    328328        assert( declsToAddAfter.empty() );
    329         if ( !errors.isEmpty() ) { throw errors; }
     329        errors.throwIfNonEmpty();
    330330
    331331        mut->members.clear();
Note: See TracChangeset for help on using the changeset viewer.