Changeset a16764a6


Ignore:
Timestamp:
Feb 28, 2018, 4:48:22 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
446ffa3
Parents:
6a8df56
Message:

Changed warning system to prepare for toggling warnings

Location:
src
Files:
1 added
45 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r6a8df56 ra16764a6  
    1818#include <list>                      // for _List_iterator, list, list<>::it...
    1919
    20 #include "Common/SemanticError.h"    // for SemanticError
    2120#include "Common/UniqueName.h"       // for UniqueName
    2221#include "Common/utility.h"          // for CodeLocation, toString
  • src/CodeGen/FixMain.cc

    r6a8df56 ra16764a6  
    3939        {
    4040                if(main_signature) {
    41                         throw SemanticError(functionDecl, "Multiple definition of main routine\n");
     41                        SemanticError(functionDecl, "Multiple definition of main routine\n");
    4242                }
    4343                main_signature.reset( functionDecl->clone() );
  • src/CodeGen/FixNames.cc

    r6a8df56 ra16764a6  
    118118                        int nargs = functionDecl->get_functionType()->get_parameters().size();
    119119                        if( !(nargs == 0 || nargs == 2 || nargs == 3) ) {
    120                                 throw SemanticError(functionDecl, "Main expected to have 0, 2 or 3 arguments\n");
     120                                SemanticError(functionDecl, "Main expected to have 0, 2 or 3 arguments\n");
    121121                        }
    122122                        functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( new ConstantExpr( Constant::from_int( 0 ) ) ) );
  • src/CodeTools/DeclStats.cc

    r6a8df56 ra16764a6  
    2424
    2525#include "Common/PassVisitor.h"
    26 #include "Common/SemanticError.h"  // for SemanticError
    2726#include "Common/VectorMap.h"      // for VectorMap
    2827#include "GenPoly/GenPoly.h"       // for hasPolyBase
  • src/CodeTools/TrackLoc.cc

    r6a8df56 ra16764a6  
    2424
    2525#include "Common/PassVisitor.h"      // for PassVisitor
    26 #include "Common/SemanticError.h"    // for SemanticError
    2726#include "Common/utility.h"          // for CodeLocation
    2827#include "SynTree/BaseSyntaxNode.h"  // for BaseSyntaxNode
  • src/Common/PassVisitor.impl.h

    r6a8df56 ra16764a6  
    6565        DeclList_t* beforeDecls = visitor.get_beforeDecls();
    6666        DeclList_t* afterDecls  = visitor.get_afterDecls();
    67         SemanticError errors;
     67        SemanticErrorException errors;
    6868
    6969        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     
    7676                        // run visitor on declaration
    7777                        maybeAccept_impl( *i, visitor );
    78                 } catch( SemanticError &e ) {
     78                } catch( SemanticErrorException &e ) {
    7979                        errors.append( e );
    8080                }
     
    9292        DeclList_t* beforeDecls = mutator.get_beforeDecls();
    9393        DeclList_t* afterDecls  = mutator.get_afterDecls();
    94         SemanticError errors;
     94        SemanticErrorException errors;
    9595
    9696        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     
    102102                        // run mutator on declaration
    103103                        maybeMutate_impl( *i, mutator );
    104                 } catch( SemanticError &e ) {
     104                } catch( SemanticErrorException &e ) {
    105105                        errors.append( e );
    106106                }
     
    125125inline void maybeAccept_impl( Container & container, PassVisitor< pass_type > & visitor ) {
    126126        if ( ! visitor.get_visit_children() ) return;
    127         SemanticError errors;
     127        SemanticErrorException errors;
    128128        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    129129                try {
     
    131131                                (*i)->accept( visitor );
    132132                        }
    133                 } catch( SemanticError &e ) {
     133                } catch( SemanticErrorException &e ) {
    134134                        errors.append( e );
    135135                }
     
    152152inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) {
    153153        if ( ! mutator.get_visit_children() ) return;
    154         SemanticError errors;
     154        SemanticErrorException errors;
    155155        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    156156                try {
     
    159159                                assert( *i );
    160160                        } // if
    161                 } catch( SemanticError &e ) {
     161                } catch( SemanticErrorException &e ) {
    162162                        errors.append( e );
    163163                } // try
     
    172172void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) {
    173173        if ( ! get_visit_children() ) return;
    174         SemanticError errors;
     174        SemanticErrorException errors;
    175175
    176176        // don't want statements from outer CompoundStmts to be added to this CompoundStmt
     
    195195                            || ( empty( beforeDecls ) && empty( afterDecls )) );
    196196
    197                 } catch ( SemanticError &e ) {
     197                } catch ( SemanticErrorException &e ) {
    198198                        errors.append( e );
    199199                }
  • src/Common/SemanticError.cc

    r6a8df56 ra16764a6  
    2323#include "SemanticError.h"
    2424
    25 SemanticError::SemanticError( CodeLocation location, std::string error ) {
     25SemanticErrorException::SemanticErrorException( CodeLocation location, std::string error ) {
    2626        append( location, error );
    2727}
    2828
    29 void SemanticError::append( SemanticError &other ) {
     29void SemanticErrorException::append( SemanticErrorException &other ) {
    3030        errors.splice( errors.end(), other.errors );
    3131}
    3232
    33 void SemanticError::append( CodeLocation location, const std::string & msg ) {
     33void SemanticErrorException::append( CodeLocation location, const std::string & msg ) {
    3434        errors.emplace_back( location, msg );
    3535}
    3636
    37 bool SemanticError::isEmpty() const {
     37bool SemanticErrorException::isEmpty() const {
    3838        return errors.empty();
    3939}
    4040
    41 void SemanticError::print() {
     41void SemanticErrorException::print() {
    4242        using std::to_string;
    4343        for( auto err : errors ) {
    44                 std::cerr << bold() << err.location << error_str() << reset_font() << err.description << std::endl;
     44                std::cerr << ErrorHelpers::bold() << err.location << ErrorHelpers::error_str() << ErrorHelpers::reset_font() << err.description << std::endl;
    4545        }
    4646}
    4747
    48 SemanticWarning::SemanticWarning( CodeLocation location, std::string msg ) {
    49         std::cerr << bold() << location << warning_str() << reset_font() << msg << std::endl;
     48void SemanticError( CodeLocation location, std::string error ) {
     49        throw SemanticErrorException(location, error);
     50}
     51
     52void SemanticWarningImpl( CodeLocation location, std::string msg ) {
     53        std::cerr << ErrorHelpers::bold() << location << ErrorHelpers::warning_str() << ErrorHelpers::reset_font() << msg << std::endl;
     54}
     55
     56//-----------------------------------------------------------------------------
     57// Helpers
     58namespace ErrorHelpers {
     59        const std::string & error_str() {
     60                static std::string str = isatty( STDERR_FILENO ) ? "\e[31merror:\e[39m " : "error: ";
     61                return str;
     62        }
     63
     64        const std::string & warning_str() {
     65                static std::string str = isatty( STDERR_FILENO ) ? "\e[95mwarning:\e[39m " : "warning: ";
     66                return str;
     67        }
     68
     69        const std::string & bold_ttycode() {
     70                static std::string str = isatty( STDERR_FILENO ) ? "\e[1m" : "";
     71                return str;
     72        }
     73
     74        const std::string & reset_font_ttycode() {
     75                static std::string str = isatty( STDERR_FILENO ) ? "\e[0m" : "";
     76                return str;
     77        }
     78
     79        std::string make_bold( const std::string & str ) {
     80                return bold_ttycode() + str + reset_font_ttycode();
     81        }
     82
     83        std::ostream & operator<<(std::ostream & os, bold) {
     84                os << bold_ttycode();
     85                return os;
     86        }
     87
     88        std::ostream & operator<<(std::ostream & os, reset_font) {
     89                os << reset_font_ttycode();
     90                return os;
     91        }
    5092}
    5193
  • src/Common/SemanticError.h

    r6a8df56 ra16764a6  
    1616#pragma once
    1717
    18 #include <exception>                                                                    // for exception
    19 #include <iostream>                                                                             // for ostream
    20 #include <list>                                                                                 // for list
    21 #include <string>                                                                               // for string
    22 #include <unistd.h>                                                                             // for isatty
    23 
    24 #include "CodeLocation.h"                                                               // for CodeLocation, toString
     18#include "ErrorObjects.h"
    2519
    2620//-----------------------------------------------------------------------------
    2721// Errors
    28 struct error {
    29         CodeLocation location;
    30         std::string description;
    3122
    32         error() = default;
    33         error( CodeLocation loc, const std::string & str ) : location( loc ), description( str ) {}
    34 };
    35 
    36 class SemanticError : public std::exception {
    37   public:
    38         SemanticError() = default;
    39         SemanticError( CodeLocation location, std::string error );
    40         ~SemanticError() throw() {}
    41 
    42         // constructs an exception using the given message and the printed representation of the obj (T must have a print method)
    43         template< typename T > SemanticError(const T * obj, const std::string & error);
    44         template< typename T > SemanticError( CodeLocation location, const T * obj, const std::string & error);
    45 
    46         static inline const std::string & error_str() {
    47                 static std::string str = isatty( STDERR_FILENO ) ? "\e[31merror:\e[39m " : "error: ";
    48                 return str;
    49         }
    50 
    51         void append( SemanticError & other );
    52         void append( CodeLocation location, const std::string & );
    53         bool isEmpty() const;
    54         void print();
    55   private:
    56         std::list< error > errors;
    57 };
     23__attribute__((noreturn)) void SemanticError( CodeLocation location, std::string error );
    5824
    5925template< typename T >
    60 SemanticError::SemanticError( const T * obj, const std::string & error )
    61         : SemanticError( obj->location, toString( error, obj ) )
    62 {}
     26__attribute__((noreturn)) static inline void SemanticError( const T * obj, const std::string & error ) {
     27        SemanticError( obj->location, toString( error, obj ) );
     28}
    6329
    6430template< typename T >
    65 SemanticError::SemanticError( CodeLocation location, const T * obj, const std::string & error )
    66         : SemanticError( location, toString( error, obj ) )
    67 {}
     31__attribute__((noreturn)) static inline void SemanticError( CodeLocation location, const T * obj, const std::string & error ) {
     32        SemanticError( location, toString( error, obj ) );
     33}
    6834
    6935//-----------------------------------------------------------------------------
    7036// Warnings
    71 class SemanticWarning {
    72   public:
    73         SemanticWarning( CodeLocation location, std::string error );
    74         ~SemanticWarning() throw() {}
    7537
    76         // constructs an exception using the given message and the printed representation of the obj (T must have a print method)
    77         template< typename T > SemanticWarning(const T * obj, const std::string & error);
    78         template< typename T > SemanticWarning( CodeLocation location, const T * obj, const std::string & error);
     38constexpr const char * const WarningFormats[] = {
    7939
    80         static inline const std::string & warning_str() {
    81                 static std::string str = isatty( STDERR_FILENO ) ? "\e[95mwarning:\e[39m " : "warning: ";
    82                 return str;
    83         }
    84 
    85   private:
    8640};
    8741
    88 template< typename T >
    89 SemanticWarning::SemanticWarning( const T * obj, const std::string & error )
    90         : SemanticWarning( obj->location, toString( error, obj ) )
    91 {}
     42enum class Warning {
     43        NUMBER_OF_WARNINGS, //This MUST be the last warning
     44};
    9245
    93 template< typename T >
    94 SemanticWarning::SemanticWarning( CodeLocation location, const T * obj, const std::string & error )
    95         : SemanticWarning( location, toString( error, obj ) )
    96 {}
     46static_assert(
     47        (sizeof(WarningFormats) / sizeof(WarningFormats[0])) == ((unsigned long)Warning::NUMBER_OF_WARNINGS),
     48        "Each warning format should have a corresponding warning enum value"
     49);
     50
     51#define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[id], __VA_ARGS__)
     52
     53void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
     54
    9755
    9856//-----------------------------------------------------------------------------
    9957// Helpers
    100 static inline const std::string & bold_ttycode() {
    101         static std::string str = isatty( STDERR_FILENO ) ? "\e[1m" : "";
    102         return str;
     58namespace ErrorHelpers {
     59        const std::string & error_str();
     60        const std::string & warning_str();
     61        const std::string & bold_ttycode();
     62        const std::string & reset_font_ttycode();
     63
     64        std::string make_bold( const std::string & str );
     65
     66        struct bold {};
     67        std::ostream & operator<<(std::ostream & os, bold);
     68
     69        struct reset_font {};
     70        std::ostream & operator<<(std::ostream & os, reset_font);
    10371}
    10472
    105 static inline const std::string & reset_font_ttycode() {
    106         static std::string str = isatty( STDERR_FILENO ) ? "\e[0m" : "";
    107         return str;
    108 }
    10973
    110 static inline std::string make_bold( const std::string & str ) {
    111         return bold_ttycode() + str + reset_font_ttycode();
    112 }
    11374
    114 struct bold {};
    115 static inline std::ostream & operator<<(std::ostream & os, bold) {
    116         os << bold_ttycode();
    117         return os;
    118 }
    119 
    120 struct reset_font {};
    121 static inline std::ostream & operator<<(std::ostream & os, reset_font) {
    122         os << reset_font_ttycode();
    123         return os;
    124 }
    12575
    12676// Local Variables: //
  • src/Concurrency/Keywords.cc

    r6a8df56 ra16764a6  
    280280                if( ! decl->body ) return;
    281281
    282                 if( !type_decl ) throw SemanticError( decl, context_error );
     282                if( !type_decl ) SemanticError( decl, context_error );
    283283
    284284                FunctionDecl * func = forwardDeclare( decl );
     
    417417                if( mutexArgs.empty() ) return;
    418418
    419                 if( CodeGen::isConstructor(decl->name) ) throw SemanticError( decl, "constructors cannot have mutex parameters" );
     419                if( CodeGen::isConstructor(decl->name) ) SemanticError( decl, "constructors cannot have mutex parameters" );
    420420
    421421                bool isDtor = CodeGen::isDestructor( decl->name );
    422422
    423                 if( isDtor && mutexArgs.size() != 1 ) throw SemanticError( decl, "destructors can only have 1 mutex argument" );
     423                if( isDtor && mutexArgs.size() != 1 ) SemanticError( decl, "destructors can only have 1 mutex argument" );
    424424
    425425                for(auto arg : mutexArgs) {
     
    430430                if( ! body ) return;
    431431
    432                 if( !monitor_decl ) throw SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>" );
    433                 if( !guard_decl ) throw SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>" );
    434                 if( !dtor_guard_decl ) throw SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>" );
     432                if( !monitor_decl || !guard_decl || !dtor_guard_decl )
     433                        SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>" );
    435434
    436435                if( isDtor ) {
     
    478477                //Makes sure it's not a copy
    479478                ReferenceType* rty = dynamic_cast< ReferenceType * >( ty );
    480                 if( ! rty ) throw SemanticError( arg, "Mutex argument must be of reference type " );
     479                if( ! rty ) SemanticError( arg, "Mutex argument must be of reference type " );
    481480
    482481                //Make sure the we are pointing directly to a type
    483482                Type* base = rty->get_base();
    484                 if( dynamic_cast< ReferenceType * >( base ) ) throw SemanticError( arg, "Mutex argument have exactly one level of indirection " );
    485                 if( dynamic_cast< PointerType * >( base ) ) throw SemanticError( arg, "Mutex argument have exactly one level of indirection " );
     483                if( dynamic_cast< ReferenceType * >( base ) ) SemanticError( arg, "Mutex argument have exactly one level of indirection " );
     484                if( dynamic_cast< PointerType * >( base ) ) SemanticError( arg, "Mutex argument have exactly one level of indirection " );
    486485
    487486                //Make sure that typed isn't mutex
    488                 if( base->get_mutex() ) throw SemanticError( arg, "mutex keyword may only appear once per argument " );
     487                if( base->get_mutex() ) SemanticError( arg, "mutex keyword may only appear once per argument " );
    489488        }
    490489
     
    624623                if( type && type->get_baseStruct()->is_thread() ) {
    625624                        if( !thread_decl || !thread_ctor_seen ) {
    626                                 throw SemanticError( type->get_baseStruct()->location, "thread keyword requires threads to be in scope, add #include <thread>");
     625                                SemanticError( type->get_baseStruct()->location, "thread keyword requires threads to be in scope, add #include <thread>");
    627626                        }
    628627
  • src/Concurrency/Waitfor.cc

    r6a8df56 ra16764a6  
    250250        Statement * GenerateWaitForPass::postmutate( WaitForStmt * waitfor ) {
    251251                if( !decl_monitor || !decl_acceptable || !decl_mask )
    252                         throw SemanticError( waitfor, "waitfor keyword requires monitors to be in scope, add #include <monitor>" );
     252                        SemanticError( waitfor, "waitfor keyword requires monitors to be in scope, add #include <monitor>" );
    253253
    254254                CompoundStmt * stmt = new CompoundStmt();
  • src/ControlStruct/ExceptTranslate.cc

    r6a8df56 ra16764a6  
    572572                        // Pass.
    573573                } else if ( CatchStmt::Terminate == catchStmt->get_kind() ) {
    574                         throw SemanticError(catchStmt->location, "catch must have exception type");
     574                        SemanticError(catchStmt->location, "catch must have exception type");
    575575                } else {
    576                         throw SemanticError(catchStmt->location, "catchResume must have exception type");
     576                        SemanticError(catchStmt->location, "catchResume must have exception type");
    577577                }
    578578
  • src/ControlStruct/LabelFixer.cc

    r6a8df56 ra16764a6  
    9292                        } else if ( labelTable[ l ]->defined() ) {
    9393                                // defined twice, error
    94                                 throw SemanticError( l.get_statement()->location, "Duplicate definition of label: " + l.get_name() );
     94                                SemanticError( l.get_statement()->location, "Duplicate definition of label: " + l.get_name() );
    9595                        }       else {
    9696                                // used previously, but undefined until now -> link with this entry
     
    117117
    118118        // Builds a table that maps a label to its defining statement.
    119         std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) {
     119        std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticErrorException ) {
    120120                std::map< Label, Statement * > *ret = new std::map< Label, Statement * >();
    121121                for ( std::map< Label, Entry * >::iterator i = labelTable.begin(); i != labelTable.end(); ++i ) {
    122122                        if ( ! i->second->defined() ) {
    123                                 throw SemanticError( i->first.get_statement()->location, "Use of undefined label: " + i->first.get_name() );
     123                                SemanticError( i->first.get_statement()->location, "Use of undefined label: " + i->first.get_name() );
    124124                        }
    125125                        (*ret)[ i->first ] = i->second->get_definition();
  • src/ControlStruct/LabelFixer.h

    r6a8df56 ra16764a6  
    3333                LabelFixer( LabelGenerator *gen = 0 );
    3434
    35                 std::map < Label, Statement * > *resolveJumps() throw ( SemanticError );
     35                std::map < Label, Statement * > *resolveJumps() throw ( SemanticErrorException );
    3636
    3737                // Declarations
  • src/ControlStruct/MLEMutator.cc

    r6a8df56 ra16764a6  
    9898
    9999
    100         Statement *MLEMutator::postmutate( BranchStmt *branchStmt ) throw ( SemanticError ) {
     100        Statement *MLEMutator::postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException ) {
    101101                std::string originalTarget = branchStmt->originalTarget;
    102102
     
    115115                                        } else {
    116116                                                // break target is outmost control structure
    117                                                 if ( enclosingControlStructures.empty() ) throw SemanticError( branchStmt->location, "'break' outside a loop, switch, or labelled block" );
     117                                                if ( enclosingControlStructures.empty() ) SemanticError( branchStmt->location, "'break' outside a loop, switch, or labelled block" );
    118118                                                targetEntry = enclosingControlStructures.rbegin();
    119119                                        } // if
     
    124124                                // ensure that selected target is valid
    125125                                if ( targetEntry == enclosingControlStructures.rend() || (isContinue && ! isLoop( targetEntry->get_controlStructure() ) ) ) {
    126                                         throw SemanticError( branchStmt->location, toString( (isContinue ? "'continue'" : "'break'"), " target must be an enclosing ", (isContinue ? "loop: " : "control structure: "), originalTarget ) );
     126                                        SemanticError( branchStmt->location, toString( (isContinue ? "'continue'" : "'break'"), " target must be an enclosing ", (isContinue ? "loop: " : "control structure: "), originalTarget ) );
    127127                                } // if
    128128                                break;
  • src/ControlStruct/MLEMutator.h

    r6a8df56 ra16764a6  
    3737
    3838                void premutate( CompoundStmt *cmpndStmt );
    39                 Statement * postmutate( BranchStmt *branchStmt ) throw ( SemanticError );
     39                Statement * postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException );
    4040                void premutate( WhileStmt *whileStmt );
    4141                Statement * postmutate( WhileStmt *whileStmt );
  • src/ControlStruct/Mutate.cc

    r6a8df56 ra16764a6  
    1818
    1919#include "Common/PassVisitor.h"    // for mutateAll
    20 #include "Common/SemanticError.h"  // for SemanticError
    2120#include "ForExprMutator.h"        // for ForExprMutator
    2221#include "LabelFixer.h"            // for LabelFixer
  • src/GenPoly/Box.cc

    r6a8df56 ra16764a6  
    215215        inline void mutateTranslationUnit( std::list< Declaration* > &translationUnit, MutatorType &mutator ) {
    216216                bool seenIntrinsic = false;
    217                 SemanticError errors;
     217                SemanticErrorException errors;
    218218                for ( typename std::list< Declaration* >::iterator i = translationUnit.begin(); i != translationUnit.end(); ++i ) {
    219219                        try {
     
    228228                                        assert( *i );
    229229                                } // if
    230                         } catch( SemanticError &e ) {
     230                        } catch( SemanticErrorException &e ) {
    231231                                errors.append( e );
    232232                        } // try
     
    575575                                                }
    576576                                        } else {
    577                                                 throw SemanticError( argBaseType, "Cannot pass non-struct type for generic struct: " );
     577                                                SemanticError( argBaseType, "Cannot pass non-struct type for generic struct: " );
    578578                                        }
    579579                                }
     
    597597                                        } else {
    598598                                                // xxx - should this be an assertion?
    599                                                 throw SemanticError( appExpr, toString( *env, "\nunbound type variable: ", tyParm->first, " in application " ) );
     599                                                SemanticError( appExpr, toString( *env, "\nunbound type variable: ", tyParm->first, " in application " ) );
    600600                                        } // if
    601601                                } // if
  • src/GenPoly/FindFunction.cc

    r6a8df56 ra16764a6  
    1919
    2020#include "Common/PassVisitor.h"         // for PassVisitor
    21 #include "Common/SemanticError.h"       // for SemanticError
    2221#include "GenPoly/ErasableScopedMap.h"  // for ErasableScopedMap<>::iterator
    2322#include "GenPoly/GenPoly.h"            // for TyVarMap
  • src/GenPoly/InstantiateGeneric.cc

    r6a8df56 ra16764a6  
    2424#include "Common/PassVisitor.h"        // for PassVisitor, WithDeclsToAdd
    2525#include "Common/ScopedMap.h"          // for ScopedMap
    26 #include "Common/SemanticError.h"      // for SemanticError
    2726#include "Common/UniqueName.h"         // for UniqueName
    2827#include "Common/utility.h"            // for deleteAll, cloneAll
  • src/GenPoly/Lvalue.cc

    r6a8df56 ra16764a6  
    1818
    1919#include "Common/PassVisitor.h"
    20 #include "Common/SemanticError.h"        // for SemanticError
    2120#include "GenPoly.h"                     // for isPolyType
    2221#include "Lvalue.h"
  • src/GenPoly/Specialize.cc

    r6a8df56 ra16764a6  
    2323
    2424#include "Common/PassVisitor.h"
    25 #include "Common/SemanticError.h"        // for SemanticError
    2625#include "Common/UniqueName.h"           // for UniqueName
    2726#include "Common/utility.h"              // for group_iterate
  • src/InitTweak/FixGlobalInit.cc

    r6a8df56 ra16764a6  
    2121
    2222#include "Common/PassVisitor.h"
    23 #include "Common/SemanticError.h"  // for SemanticError
    2423#include "Common/UniqueName.h"     // for UniqueName
    2524#include "InitTweak.h"             // for isIntrinsicSingleArgCallStmt
  • src/InitTweak/FixInit.cc

    r6a8df56 ra16764a6  
    213213                        Expression * postmutate( UntypedExpr * expr );
    214214
    215                         SemanticError errors;
     215                        SemanticErrorException errors;
    216216                  private:
    217217                        template< typename... Params >
     
    276276                        // can't use mutateAll, because need to insert declarations at top-level
    277277                        // can't use DeclMutator, because sometimes need to insert IfStmt, etc.
    278                         SemanticError errors;
     278                        SemanticErrorException errors;
    279279                        for ( std::list< Declaration * >::iterator i = translationUnit.begin(); i != translationUnit.end(); ++i ) {
    280280                                try {
    281281                                        maybeMutate( *i, fixer );
    282282                                        translationUnit.splice( i, fixer.pass.staticDtorDecls );
    283                                 } catch( SemanticError &e ) {
     283                                } catch( SemanticErrorException &e ) {
    284284                                        errors.append( e );
    285285                                } // try
     
    894894                        )
    895895                        if ( ! diff.empty() ) {
    896                                 throw SemanticError( stmt, std::string("jump to label '") + stmt->get_target().get_name() + "' crosses initialization of " + (*diff.begin())->get_name() + " " );
     896                                SemanticError( stmt, std::string("jump to label '") + stmt->get_target().get_name() + "' crosses initialization of " + (*diff.begin())->get_name() + " " );
    897897                        } // if
    898898                        // S_G-S_L results in set of objects that must be destructed
     
    945945                        GuardValue( isCtor );
    946946                        GuardValue( structDecl );
    947                         errors = SemanticError();  // clear previous errors
     947                        errors = SemanticErrorException();  // clear previous errors
    948948
    949949                        // need to start with fresh sets
     
    10341034                                                                function->get_statements()->push_back( callStmt );
    10351035                                                        }
    1036                                                 } catch ( SemanticError & error ) {
     1036                                                } catch ( SemanticErrorException & error ) {
    10371037                                                        emit( funcDecl->location, "in ", CodeGen::genPrettyType( function->get_functionType(), function->get_name() ), ", field ", field->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed",  " and no ", isCtor ? "default constructor" : "destructor", " found" );
    10381038                                                }
     
    11101110                template< typename Visitor, typename... Params >
    11111111                void error( Visitor & v, CodeLocation loc, const Params &... params ) {
    1112                         SemanticError err( loc, toString( params... ) );
     1112                        SemanticErrorException err( loc, toString( params... ) );
    11131113                        v.errors.append( err );
    11141114                }
  • src/InitTweak/GenInit.cc

    r6a8df56 ra16764a6  
    317317                if ( tryConstruct( objDecl ) && ( managedTypes.isManaged( objDecl ) || ((! inFunction || objDecl->get_storageClasses().is_static ) && ! isConstExpr( objDecl->get_init() ) ) ) ) {
    318318                        // constructed objects cannot be designated
    319                         if ( isDesignated( objDecl->get_init() ) ) throw SemanticError( objDecl, "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n" );
     319                        if ( isDesignated( objDecl->get_init() ) ) SemanticError( objDecl, "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n" );
    320320                        // constructed objects should not have initializers nested too deeply
    321                         if ( ! checkInitDepth( objDecl ) ) throw SemanticError( objDecl, "Managed object's initializer is too deep " );
     321                        if ( ! checkInitDepth( objDecl ) ) SemanticError( objDecl, "Managed object's initializer is too deep " );
    322322
    323323                        objDecl->set_init( genCtorInit( objDecl ) );
  • src/InitTweak/InitTweak.cc

    r6a8df56 ra16764a6  
    225225                                        // xxx - this shouldn't be an error, but need a way to
    226226                                        // terminate without creating output, so should catch this error
    227                                         throw SemanticError( init->location, "unbalanced list initializers" );
     227                                        SemanticError( init->location, "unbalanced list initializers" );
    228228                                }
    229229
  • src/Parser/DeclarationNode.cc

    r6a8df56 ra16764a6  
    576576                                        dst->basictype = src->basictype;
    577577                                } else if ( src->basictype != DeclarationNode::NoBasicType )
    578                                         throw SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: " );
     578                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: " );
    579579
    580580                                if ( dst->complextype == DeclarationNode::NoComplexType ) {
    581581                                        dst->complextype = src->complextype;
    582582                                } else if ( src->complextype != DeclarationNode::NoComplexType )
    583                                         throw SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: " );
     583                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: " );
    584584
    585585                                if ( dst->signedness == DeclarationNode::NoSignedness ) {
    586586                                        dst->signedness = src->signedness;
    587587                                } else if ( src->signedness != DeclarationNode::NoSignedness )
    588                                         throw SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: " );
     588                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: " );
    589589
    590590                                if ( dst->length == DeclarationNode::NoLength ) {
     
    593593                                        dst->length = DeclarationNode::LongLong;
    594594                                } else if ( src->length != DeclarationNode::NoLength )
    595                                         throw SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: " );
     595                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: " );
    596596                        } // if
    597597                        break;
     
    940940
    941941void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ) {
    942         SemanticError errors;
     942        SemanticErrorException errors;
    943943        std::back_insert_iterator< std::list< Declaration * > > out( outputList );
    944944
     
    960960                                * out++ = decl;
    961961                        } // if
    962                 } catch( SemanticError &e ) {
     962                } catch( SemanticErrorException &e ) {
    963963                        errors.append( e );
    964964                } // try
     
    971971
    972972void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) {
    973         SemanticError errors;
     973        SemanticErrorException errors;
    974974        std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
    975975
     
    994994                                } // if
    995995                        } // if
    996                 } catch( SemanticError &e ) {
     996                } catch( SemanticErrorException &e ) {
    997997                        errors.append( e );
    998998                } // try
     
    10051005
    10061006void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) {
    1007         SemanticError errors;
     1007        SemanticErrorException errors;
    10081008        std::back_insert_iterator< std::list< Type * > > out( outputList );
    10091009        const DeclarationNode * cur = firstNode;
     
    10121012                try {
    10131013                        * out++ = cur->buildType();
    1014                 } catch( SemanticError &e ) {
     1014                } catch( SemanticErrorException &e ) {
    10151015                        errors.append( e );
    10161016                } // try
     
    10241024
    10251025Declaration * DeclarationNode::build() const {
    1026         if ( ! error.empty() ) throw SemanticError( this, error + " in declaration of " );
     1026        if ( ! error.empty() ) SemanticError( this, error + " in declaration of " );
    10271027
    10281028        if ( asmStmt ) {
     
    10471047                //    inline _Noreturn int i;                   // disallowed
    10481048                if ( type->kind != TypeData::Function && funcSpecs.any() ) {
    1049                         throw SemanticError( this, "invalid function specifier for " );
     1049                        SemanticError( this, "invalid function specifier for " );
    10501050                } // if
    10511051                return buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, maybeBuild< Initializer >(initializer), attributes )->set_extension( extension );
     
    10571057        //    inlne _Noreturn enum   E { ... };         // disallowed
    10581058        if ( funcSpecs.any() ) {
    1059                 throw SemanticError( this, "invalid function specifier for " );
     1059                SemanticError( this, "invalid function specifier for " );
    10601060        } // if
    10611061        assertf( name, "ObjectDecl must a have name\n" );
  • src/Parser/ExpressionNode.cc

    r6a8df56 ra16764a6  
    356356
    357357Expression * build_field_name_FLOATING_FRACTIONconstant( const string & str ) {
    358         if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( yylloc, "invalid tuple index " + str );
     358        if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) SemanticError( yylloc, "invalid tuple index " + str );
    359359        Expression * ret = build_constantInteger( *new string( str.substr(1) ) );
    360360        delete &str;
     
    363363
    364364Expression * build_field_name_FLOATING_DECIMALconstant( const string & str ) {
    365         if ( str[str.size()-1] != '.' ) throw SemanticError( yylloc, "invalid tuple index " + str );
     365        if ( str[str.size()-1] != '.' ) SemanticError( yylloc, "invalid tuple index " + str );
    366366        Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) );
    367367        delete &str;
  • src/Parser/LinkageSpec.cc

    r6a8df56 ra16764a6  
    3434                return BuiltinC;
    3535        } else {
    36                 throw SemanticError( location, "Invalid linkage specifier " + *spec );
     36                SemanticError( location, "Invalid linkage specifier " + *spec );
    3737        } // if
    3838}
     
    4848                return old_spec;
    4949        } else {
    50                 throw SemanticError( location, "Invalid linkage specifier " + *cmd );
     50                SemanticError( location, "Invalid linkage specifier " + *cmd );
    5151        } // if
    5252}
  • src/Parser/ParseNode.h

    r6a8df56 ra16764a6  
    419419template< typename SynTreeType, typename NodeType, template< typename, typename...> class Container, typename... Args >
    420420void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > &outputList ) {
    421         SemanticError errors;
     421        SemanticErrorException errors;
    422422        std::back_insert_iterator< Container< SynTreeType *, Args... > > out( outputList );
    423423        const NodeType * cur = firstNode;
     
    432432                                assertf(false, "buildList unknown type");
    433433                        } // if
    434                 } catch( SemanticError &e ) {
     434                } catch( SemanticErrorException &e ) {
    435435                        errors.append( e );
    436436                } // try
  • src/Parser/TypeData.cc

    r6a8df56 ra16764a6  
    519519
    520520static string genTSError( string msg, DeclarationNode::BasicType basictype ) {
    521         throw SemanticError( yylloc, string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." );
     521        SemanticError( yylloc, string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." );
    522522} // genTSError
    523523
     
    919919                                // type set => parameter name already transformed by a declaration names so there is a duplicate
    920920                                // declaration name attempting a second transformation
    921                                 if ( param->type ) throw SemanticError( param->location, string( "duplicate declaration name " ) + *param->name );
     921                                if ( param->type ) SemanticError( param->location, string( "duplicate declaration name " ) + *param->name );
    922922                                // declaration type reset => declaration already transformed by a parameter name so there is a duplicate
    923923                                // parameter name attempting a second transformation
    924                                 if ( ! decl->type ) throw SemanticError( param->location, string( "duplicate parameter name " ) + *param->name );
     924                                if ( ! decl->type ) SemanticError( param->location, string( "duplicate parameter name " ) + *param->name );
    925925                                param->type = decl->type;                               // set copy declaration type to parameter type
    926926                                decl->type = nullptr;                                   // reset declaration type
     
    929929                } // for
    930930                // declaration type still set => type not moved to a matching parameter so there is a missing parameter name
    931                 if ( decl->type ) throw SemanticError( decl->location, string( "missing name in parameter list " ) + *decl->name );
     931                if ( decl->type ) SemanticError( decl->location, string( "missing name in parameter list " ) + *decl->name );
    932932        } // for
    933933
  • src/Parser/lex.ll

    r6a8df56 ra16764a6  
    453453void yyerror( const char * errmsg ) {
    454454        cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1
    455                  << ": " << SemanticError::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl;
     455                 << ": " << ErrorHelpers::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl;
    456456}
    457457
  • src/Parser/parser.yy

    r6a8df56 ra16764a6  
    482482                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); }
    483483        | type_name '.' no_attr_identifier                                      // CFA, nested type
    484                 { throw SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; } // FIX ME
     484                { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; } // FIX ME
    485485        | type_name '.' '[' push field_list pop ']'                     // CFA, nested type / tuple field selector
    486                 { throw SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; } // FIX ME
     486                { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; } // FIX ME
    487487        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    488                 { throw SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; } // FIX ME
     488                { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; } // FIX ME
    489489        ;
    490490
     
    780780                { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); }
    781781        | unary_expression '=' '{' initializer_list comma_opt '}'
    782                 { throw SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } // FIX ME
     782                { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } // FIX ME
    783783        ;
    784784
     
    850850        | exception_statement
    851851        | enable_disable_statement
    852                 { throw SemanticError( yylloc, "enable/disable statement is currently unimplemented." ); $$ = nullptr; } // FIX ME
     852                { SemanticError( yylloc, "enable/disable statement is currently unimplemented." ); $$ = nullptr; } // FIX ME
    853853        | asm_statement
    854854        ;
     
    10671067                { $$ = new StatementNode( build_return( $2 ) ); }
    10681068        | RETURN '{' initializer_list comma_opt '}'
    1069                 { throw SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } // FIX ME
     1069                { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } // FIX ME
    10701070        | THROW assignment_expression_opt ';'                           // handles rethrow
    10711071                { $$ = new StatementNode( build_throw( $2 ) ); }
     
    10861086mutex_statement:
    10871087        MUTEX '(' argument_expression_list ')' statement
    1088                 { throw SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; } // FIX ME
     1088                { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; } // FIX ME
    10891089        ;
    10901090
     
    13161316static_assert:
    13171317        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    1318                 { throw SemanticError( yylloc, "Static assert is currently unimplemented." ); $$ = nullptr; }   // FIX ME
     1318                { SemanticError( yylloc, "Static assert is currently unimplemented." ); $$ = nullptr; } // FIX ME
    13191319
    13201320// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
  • src/ResolvExpr/AlternativeFinder.cc

    r6a8df56 ra16764a6  
    240240                                std::cerr << "No reasonable alternatives for expression " << expr << std::endl;
    241241                        )
    242                         throw SemanticError( expr, "No reasonable alternatives for expression " );
     242                        SemanticError( expr, "No reasonable alternatives for expression " );
    243243                }
    244244                if ( prune ) {
     
    258258                                stream << " Alternatives are:\n";
    259259                                printAlts( winners, stream, 1 );
    260                                 throw SemanticError( expr->location, stream.str() );
     260                                SemanticError( expr->location, stream.str() );
    261261                        }
    262262                        alternatives = move(pruned);
     
    495495                                return;
    496496                        } else if ( level >= recursionLimit ) {
    497                                 throw SemanticError( newAlt.expr->location, "Too many recursive assertions" );
     497                                SemanticError( newAlt.expr->location, "Too many recursive assertions" );
    498498                        } else {
    499499                                AssertionSet newerNeed;
     
    11121112
    11131113                AltList candidates;
    1114                 SemanticError errors;
     1114                SemanticErrorException errors;
    11151115                for ( AltList::iterator func = funcFinder.alternatives.begin(); func != funcFinder.alternatives.end(); ++func ) {
    11161116                        try {
     
    11381138                                        } // if
    11391139                                }
    1140                         } catch ( SemanticError &e ) {
     1140                        } catch ( SemanticErrorException &e ) {
    11411141                                errors.append( e );
    11421142                        }
     
    11671167                                                }
    11681168                                        }
    1169                                 } catch ( SemanticError &e ) {
     1169                                } catch ( SemanticErrorException &e ) {
    11701170                                        errors.append( e );
    11711171                                }
     
    14091409                        findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) );
    14101410                        if ( winners.size() != 1 ) {
    1411                                 throw SemanticError( sizeofExpr->get_expr(), "Ambiguous expression in sizeof operand: " );
     1411                                SemanticError( sizeofExpr->get_expr(), "Ambiguous expression in sizeof operand: " );
    14121412                        } // if
    14131413                        // return the lowest cost alternative for the argument
     
    14301430                        findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) );
    14311431                        if ( winners.size() != 1 ) {
    1432                                 throw SemanticError( alignofExpr->get_expr(), "Ambiguous expression in alignof operand: " );
     1432                                SemanticError( alignofExpr->get_expr(), "Ambiguous expression in alignof operand: " );
    14331433                        } // if
    14341434                        // return the lowest cost alternative for the argument
  • src/ResolvExpr/CurrentObject.cc

    r6a8df56 ra16764a6  
    141141                        base = at->get_base();
    142142                        memberIter = createMemberIterator( base );
    143                         if ( at->isVarLen ) throw SemanticError( at, "VLA initialization does not support @=" );
     143                        if ( at->isVarLen ) SemanticError( at, "VLA initialization does not support @=" );
    144144                        setSize( at->get_dimension() );
    145145                }
     
    155155                                        size = constExpr->intValue();
    156156                                        PRINT( std::cerr << "array type with size: " << size << std::endl; )
    157                                 } catch ( SemanticError & ) {
    158                                         throw SemanticError( expr, "Constant expression of non-integral type in array dimension: " );
     157                                } catch ( SemanticErrorException & ) {
     158                                        SemanticError( expr, "Constant expression of non-integral type in array dimension: " );
    159159                                }
    160160                        }       else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) {
     
    178178                                try {
    179179                                        index = constExpr->intValue();
    180                                 } catch( SemanticError & ) {
    181                                         throw SemanticError( expr, "Constant expression of non-integral type in array designator: " );
     180                                } catch( SemanticErrorException & ) {
     181                                        SemanticError( expr, "Constant expression of non-integral type in array designator: " );
    182182                                }
    183183                        } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) {
     
    532532                } // for
    533533                if ( desigAlts.size() > 1 ) {
    534                         throw SemanticError( designation, toString("Too many alternatives (", desigAlts.size(), ") for designation: ") );
     534                        SemanticError( designation, toString("Too many alternatives (", desigAlts.size(), ") for designation: ") );
    535535                } else if ( desigAlts.size() == 0 ) {
    536                         throw SemanticError( designation, "No reasonable alternatives for designation: " );
     536                        SemanticError( designation, "No reasonable alternatives for designation: " );
    537537                }
    538538                DesignatorChain & d = desigAlts.back();
  • src/ResolvExpr/Resolver.cc

    r6a8df56 ra16764a6  
    174174                        findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) );
    175175                        if ( winners.size() == 0 ) {
    176                                 throw SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") );
     176                                SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") );
    177177                        } else if ( winners.size() != 1 ) {
    178178                                std::ostringstream stream;
     
    181181                                stream << " Alternatives are:\n";
    182182                                printAlts( winners, stream, 1 );
    183                                 throw SemanticError( untyped->location, stream.str() );
     183                                SemanticError( untyped->location, stream.str() );
    184184                        }
    185185
     
    187187                        Alternative & choice = winners.front();
    188188                        if ( findDeletedExpr( choice.expr ) ) {
    189                                 throw SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " );
     189                                SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " );
    190190                        }
    191191                        alt = std::move( choice );
     
    484484                                ss << strict_dynamic_cast<NameExpr*>( clause.target.function )->name;
    485485                                ss << "' in call to waitfor";
    486                                 throw SemanticError( stmt->location, ss.str() );
     486                                SemanticError( stmt->location, ss.str() );
    487487                        }
    488488
     
    501501                        //      try matching the arguments to the parameters
    502502                        //      not the other way around because we have more arguments than parameters
    503                         SemanticError errors;
     503                        SemanticErrorException errors;
    504504                        for ( Alternative & func : funcFinder.get_alternatives() ) {
    505505                                try {
    506506                                        PointerType * pointer = dynamic_cast< PointerType* >( func.expr->get_result()->stripReferences() );
    507507                                        if( !pointer ) {
    508                                                 throw SemanticError( func.expr->get_result(), "candidate not viable: not a pointer type\n" );
     508                                                SemanticError( func.expr->get_result(), "candidate not viable: not a pointer type\n" );
    509509                                        }
    510510
    511511                                        FunctionType * function = dynamic_cast< FunctionType* >( pointer->get_base() );
    512512                                        if( !function ) {
    513                                                 throw SemanticError( pointer->get_base(), "candidate not viable: not a function type\n" );
     513                                                SemanticError( pointer->get_base(), "candidate not viable: not a function type\n" );
    514514                                        }
    515515
     
    520520
    521521                                                if( !advance_to_mutex( param, param_end ) ) {
    522                                                         throw SemanticError(function, "candidate function not viable: no mutex parameters\n");
     522                                                        SemanticError(function, "candidate function not viable: no mutex parameters\n");
    523523                                                }
    524524                                        }
     
    559559                                                                        // We ran out of parameters but still have arguments
    560560                                                                        // this function doesn't match
    561                                                                         throw SemanticError( function, "candidate function not viable: too many mutex arguments\n" );
     561                                                                        SemanticError( function, "candidate function not viable: too many mutex arguments\n" );
    562562                                                                }
    563563
     
    571571                                                                        (*param)->get_type()->print( ss );
    572572                                                                        ss << "'\n";
    573                                                                         throw SemanticError( function, ss.str() );
     573                                                                        SemanticError( function, ss.str() );
    574574                                                                }
    575575
     
    583583                                                                // We ran out of arguments but still have parameters left
    584584                                                                // this function doesn't match
    585                                                                 throw SemanticError( function, "candidate function not viable: too few mutex arguments\n" );
     585                                                                SemanticError( function, "candidate function not viable: too few mutex arguments\n" );
    586586                                                        }
    587587
     
    599599
    600600                                                }
    601                                                 catch( SemanticError &e ) {
     601                                                catch( SemanticErrorException &e ) {
    602602                                                        errors.append( e );
    603603                                                }
    604604                                        }
    605605                                }
    606                                 catch( SemanticError &e ) {
     606                                catch( SemanticErrorException &e ) {
    607607                                        errors.append( e );
    608608                                }
     
    610610
    611611                        // Make sure we got the right number of arguments
    612                         if( func_candidates.empty() )    { SemanticError top( stmt->location, "No alternatives for function in call to waitfor"  ); top.append( errors ); throw top; }
    613                         if( args_candidates.empty() )    { SemanticError top( stmt->location, "No alternatives for arguments in call to waitfor" ); top.append( errors ); throw top; }
    614                         if( func_candidates.size() > 1 ) { SemanticError top( stmt->location, "Ambiguous function in call to waitfor"            ); top.append( errors ); throw top; }
    615                         if( args_candidates.size() > 1 ) { SemanticError top( stmt->location, "Ambiguous arguments in call to waitfor"           ); top.append( errors ); throw top; }
     612                        if( func_candidates.empty() )    { SemanticErrorException top( stmt->location, "No alternatives for function in call to waitfor"  ); top.append( errors ); throw top; }
     613                        if( args_candidates.empty() )    { SemanticErrorException top( stmt->location, "No alternatives for arguments in call to waitfor" ); top.append( errors ); throw top; }
     614                        if( func_candidates.size() > 1 ) { SemanticErrorException top( stmt->location, "Ambiguous function in call to waitfor"            ); top.append( errors ); throw top; }
     615                        if( args_candidates.size() > 1 ) { SemanticErrorException top( stmt->location, "Ambiguous arguments in call to waitfor"           ); top.append( errors ); throw top; }
    616616                        // TODO: need to use findDeletedExpr to ensure no deleted identifiers are used.
    617617
  • src/SymTab/Autogen.cc

    r6a8df56 ra16764a6  
    331331                        definitions.push_back( dcl );
    332332                        indexer.addId( dcl );
    333                 } catch ( SemanticError err ) {
     333                } catch ( SemanticErrorException err ) {
    334334                        // okay if decl does not resolve - that means the function should not be generated
    335335                        delete dcl;
  • src/SymTab/Indexer.cc

    r6a8df56 ra16764a6  
    443443                        // isomorphic to C type-compatibility, which it may not be.
    444444                        if ( hasIncompatibleCDecl( name, mangleName, scope ) ) {
    445                                 throw SemanticError( decl, "conflicting overload of C function " );
     445                                SemanticError( decl, "conflicting overload of C function " );
    446446                        }
    447447                } else {
    448448                        // Check that a Cforall declaration doesn't override any C declaration
    449449                        if ( hasCompatibleCDecl( name, mangleName, scope ) ) {
    450                                 throw SemanticError( decl, "Cforall declaration hides C function " );
     450                                SemanticError( decl, "Cforall declaration hides C function " );
    451451                        }
    452452                }
     
    463463        void Indexer::addId( DeclarationWithType * decl, Expression * baseExpr ) {
    464464                // default handling of conflicts is to raise an error
    465                 addId( decl, [decl](IdData &, const std::string & msg) { throw SemanticError( decl, msg ); return true; }, baseExpr );
     465                addId( decl, [decl](IdData &, const std::string & msg) { SemanticError( decl, msg ); return true; }, baseExpr );
    466466        }
    467467
    468468        void Indexer::addDeletedId( DeclarationWithType * decl, BaseSyntaxNode * deleteStmt ) {
    469469                // default handling of conflicts is to raise an error
    470                 addId( decl, [decl](IdData &, const std::string & msg) { throw SemanticError( decl, msg ); return true; }, nullptr, deleteStmt );
     470                addId( decl, [decl](IdData &, const std::string & msg) { SemanticError( decl, msg ); return true; }, nullptr, deleteStmt );
    471471        }
    472472
     
    477477                        return true;
    478478                } else {
    479                         throw SemanticError( added, "redeclaration of " );
     479                        SemanticError( added, "redeclaration of " );
    480480                }
    481481        }
     
    504504                        return false;
    505505                } else if ( ! added->get_members().empty() ) {
    506                         throw SemanticError( added, "redeclaration of " );
     506                        SemanticError( added, "redeclaration of " );
    507507                } // if
    508508                return true;
  • src/SymTab/Validate.cc

    r6a8df56 ra16764a6  
    360360                        // the only case in which "void" is valid is where it is the only one in the list
    361361                        if ( containsVoid && ( nvals > 1 || isVarArgs ) ) {
    362                                 throw SemanticError( func, "invalid type void in function type " );
     362                                SemanticError( func, "invalid type void in function type " );
    363363                        }
    364364
     
    401401                for ( Expression * param : inst->parameters ) {
    402402                        if ( ! dynamic_cast< TypeExpr * >( param ) ) {
    403                                 throw SemanticError( inst, "Expression parameters for generic types are currently unsupported: " );
     403                                SemanticError( inst, "Expression parameters for generic types are currently unsupported: " );
    404404                        }
    405405                }
     
    501501                TraitDecl *traitDecl = local_indexer->lookupTrait( traitInst->name );
    502502                if ( ! traitDecl ) {
    503                         throw SemanticError( traitInst->location, "use of undeclared trait " + traitInst->name );
     503                        SemanticError( traitInst->location, "use of undeclared trait " + traitInst->name );
    504504                } // if
    505505                if ( traitDecl->get_parameters().size() != traitInst->get_parameters().size() ) {
    506                         throw SemanticError( traitInst, "incorrect number of trait parameters: " );
     506                        SemanticError( traitInst, "incorrect number of trait parameters: " );
    507507                } // if
    508508                traitInst->baseTrait = traitDecl;
     
    512512                        TypeExpr * expr = dynamic_cast< TypeExpr * >( std::get<1>(p) );
    513513                        if ( ! expr ) {
    514                                 throw SemanticError( std::get<1>(p), "Expression parameters for trait instances are currently unsupported: " );
     514                                SemanticError( std::get<1>(p), "Expression parameters for trait instances are currently unsupported: " );
    515515                        }
    516516                        if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) {
     
    618618                                bool isVoid = fixFunction( assertion );
    619619                                if ( isVoid ) {
    620                                         throw SemanticError( node, "invalid type void in assertion of function " );
     620                                        SemanticError( node, "invalid type void in assertion of function " );
    621621                                } // if
    622622                        } // for
     
    662662                // were cast to void.
    663663                if ( ! returnStmt->get_expr() && returnVals.size() != 0 ) {
    664                         throw SemanticError( returnStmt, "Non-void function returns no values: " );
     664                        SemanticError( returnStmt, "Non-void function returns no values: " );
    665665                }
    666666        }
     
    703703                                ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret);
    704704                                if ( ! rtt ) {
    705                                         throw SemanticError( typeInst->location, "Cannot apply type parameters to base type of " + typeInst->name );
     705                                        SemanticError( typeInst->location, "Cannot apply type parameters to base type of " + typeInst->name );
    706706                                }
    707707                                rtt->get_parameters().clear();
     
    741741                        Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
    742742                        if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) {
    743                                 throw SemanticError( tyDecl->location, "Cannot redefine typedef: " + tyDecl->name );
     743                                SemanticError( tyDecl->location, "Cannot redefine typedef: " + tyDecl->name );
    744744                        }
    745745                        // Cannot redefine VLA typedefs. Note: this is slightly incorrect, because our notion of VLAs
     
    748748                        // to fix this corner case likely outweighs the utility of allowing it.
    749749                        if ( isVariableLength( t1 ) || isVariableLength( t2 ) ) {
    750                                 throw SemanticError( tyDecl->location, "Cannot redefine typedef: " + tyDecl->name );
     750                                SemanticError( tyDecl->location, "Cannot redefine typedef: " + tyDecl->name );
    751751                        }
    752752                } else {
     
    897897                if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc.
    898898                        if ( params.size() == 0 ) {
    899                                 throw SemanticError( funcDecl, "Constructors, destructors, and assignment functions require at least one parameter " );
     899                                SemanticError( funcDecl, "Constructors, destructors, and assignment functions require at least one parameter " );
    900900                        }
    901901                        ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() );
    902902                        if ( ! refType ) {
    903                                 throw SemanticError( funcDecl, "First parameter of a constructor, destructor, or assignment function must be a reference " );
     903                                SemanticError( funcDecl, "First parameter of a constructor, destructor, or assignment function must be a reference " );
    904904                        }
    905905                        if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
    906                                 throw SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " );
     906                                SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " );
    907907                        }
    908908                }
     
    939939
    940940                        sub.apply( inst );
    941                         if ( args.size() < params->size() ) throw SemanticError( inst, "Too few type arguments in generic type " );
    942                         if ( args.size() > params->size() ) throw SemanticError( inst, "Too many type arguments in generic type " );
     941                        if ( args.size() < params->size() ) SemanticError( inst, "Too few type arguments in generic type " );
     942                        if ( args.size() > params->size() ) SemanticError( inst, "Too many type arguments in generic type " );
    943943                }
    944944        }
  • src/SynTree/Expression.cc

    r6a8df56 ra16764a6  
    9393                return 0;
    9494        }
    95         throw SemanticError( this, "Constant expression of non-integral type " );
     95        SemanticError( this, "Constant expression of non-integral type " );
    9696}
    9797
  • src/SynTree/Mutator.h

    r6a8df56 ra16764a6  
    136136template< typename Container, typename MutatorType >
    137137inline void mutateAll( Container &container, MutatorType &mutator ) {
    138         SemanticError errors;
     138        SemanticErrorException errors;
    139139        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    140140                try {
     
    144144                                assert( *i );
    145145                        } // if
    146                 } catch( SemanticError &e ) {
     146                } catch( SemanticErrorException &e ) {
    147147                        errors.append( e );
    148148                } // try
  • src/SynTree/Statement.cc

    r6a8df56 ra16764a6  
    9696const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
    9797
    98 BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticError ) :
     98BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) :
    9999        Statement(), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) {
    100100        //actually this is a syntactic error signaled by the parser
    101101        if ( type == BranchStmt::Goto && target.empty() ) {
    102                 throw SemanticError( target.get_statement()->location, "goto without target");
    103         }
    104 }
    105 
    106 BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticError ) :
     102                SemanticError( target.get_statement()->location, "goto without target");
     103        }
     104}
     105
     106BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticErrorException ) :
    107107        Statement(), computedTarget( computedTarget ), type( type ) {
    108108        if ( type != BranchStmt::Goto || computedTarget == nullptr ) {
    109                 throw SemanticError( computedTarget->location, "Computed target not valid in branch statement");
     109                SemanticError( computedTarget->location, "Computed target not valid in branch statement");
    110110        }
    111111}
     
    201201}
    202202
    203 CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
     203CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticErrorException ) :
    204204        Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    205         if ( isDefault() && condition != 0 ) throw SemanticError( condition, "default case with condition: " );
     205        if ( isDefault() && condition != 0 ) SemanticError( condition, "default case with condition: " );
    206206}
    207207
  • src/SynTree/Statement.h

    r6a8df56 ra16764a6  
    179179        std::list<Statement *> stmts;
    180180
    181         CaseStmt( Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
     181        CaseStmt( Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw (SemanticErrorException);
    182182        CaseStmt( const CaseStmt &other );
    183183        virtual ~CaseStmt();
     
    263263        Type type;
    264264
    265         BranchStmt( Label target, Type ) throw (SemanticError);
    266         BranchStmt( Expression *computedTarget, Type ) throw (SemanticError);
     265        BranchStmt( Label target, Type ) throw (SemanticErrorException);
     266        BranchStmt( Expression *computedTarget, Type ) throw (SemanticErrorException);
    267267
    268268        Label get_originalTarget() { return originalTarget; }
  • src/SynTree/TypeSubstitution.h

    r6a8df56 ra16764a6  
    9898                                } // if
    9999                        } else {
    100                                 throw SemanticError( formal, toString( "Attempt to provide non-type parameter: ", toString( *actualIt ).c_str(), " for type parameter " ) );
     100                                SemanticError( formal, toString( "Attempt to provide non-type parameter: ", toString( *actualIt ).c_str(), " for type parameter " ) );
    101101                        } // if
    102102                } else {
  • src/SynTree/Visitor.h

    r6a8df56 ra16764a6  
    132132template< typename Container, typename VisitorType >
    133133inline void acceptAll( Container &container, VisitorType &visitor ) {
    134         SemanticError errors;
     134        SemanticErrorException errors;
    135135        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    136136                try {
     
    138138                                (*i)->accept( visitor );
    139139                        }
    140                 } catch( SemanticError &e ) {
     140                } catch( SemanticErrorException &e ) {
    141141                        errors.append( e );
    142142                }
  • src/main.cc

    r6a8df56 ra16764a6  
    357357                        delete output;
    358358                } // if
    359         } catch ( SemanticError &e ) {
     359        } catch ( SemanticErrorException &e ) {
    360360                if ( errorp ) {
    361361                        cerr << "---AST at error:---" << endl;
Note: See TracChangeset for help on using the changeset viewer.