Changeset d55d7a6


Ignore:
Timestamp:
Feb 15, 2018, 3:58:56 PM (7 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:
75e3cb2
Parents:
d27e340
Message:

Massive change to errors to enable warnings

Location:
src
Files:
32 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/FixMain.cc

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

    rd27e340 rd55d7a6  
    118118                        int nargs = functionDecl->get_functionType()->get_parameters().size();
    119119                        if( !(nargs == 0 || nargs == 2 || nargs == 3) ) {
    120                                 throw SemanticError("Main expected to have 0, 2 or 3 arguments\n", functionDecl);
     120                                throw 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/Common/PassVisitor.impl.h

    rd27e340 rd55d7a6  
    7777                        maybeAccept_impl( *i, visitor );
    7878                } catch( SemanticError &e ) {
    79                         e.set_location( (*i)->location );
    8079                        errors.append( e );
    8180                }
     
    104103                        maybeMutate_impl( *i, mutator );
    105104                } catch( SemanticError &e ) {
    106                         e.set_location( (*i)->location );
    107105                        errors.append( e );
    108106                }
     
    134132                        }
    135133                } catch( SemanticError &e ) {
    136                         e.set_location( (*i)->location );
    137134                        errors.append( e );
    138135                }
     
    163160                        } // if
    164161                } catch( SemanticError &e ) {
    165                         e.set_location( (*i)->location );
    166162                        errors.append( e );
    167163                } // try
     
    200196
    201197                } catch ( SemanticError &e ) {
    202                         e.set_location( (*i)->location );
    203198                        errors.append( e );
    204199                }
  • src/Common/SemanticError.cc

    rd27e340 rd55d7a6  
    2323#include "SemanticError.h"
    2424
    25 SemanticError::SemanticError() {
    26 }
    27 
    28 SemanticError::SemanticError( std::string error ) {
    29         append( error );
     25SemanticError::SemanticError( CodeLocation location, std::string error ) {
     26        append( location, error );
    3027}
    3128
     
    3431}
    3532
    36 void SemanticError::append( const std::string & msg ) {
    37         errors.emplace_back( error_str() + msg );
     33void SemanticError::append( CodeLocation location, const std::string & msg ) {
     34        errors.emplace_back( location, msg );
    3835}
    3936
     
    4239}
    4340
    44 void SemanticError::print( std::ostream &os ) {
     41void SemanticError::print() {
    4542        using std::to_string;
    4643        for( auto err : errors ) {
    47                 os << err.location << err.description << std::endl;
     44                std::cerr << bold() << err.location << error_str() << reset_font() << err.description << std::endl;
    4845        }
    4946}
    5047
    51 void SemanticError::set_location( const CodeLocation& location ) {
    52         errors.begin()->maybeSet( location );
     48SemanticWarning::SemanticWarning( CodeLocation location, std::string msg ) {
     49        std::cerr << bold() << location << warning_str() << reset_font() << msg << std::endl;
    5350}
    5451
  • src/Common/SemanticError.h

    rd27e340 rd55d7a6  
    2424#include "CodeLocation.h"                                                               // for CodeLocation, toString
    2525
     26//-----------------------------------------------------------------------------
     27// Errors
    2628struct error {
     29        CodeLocation location;
    2730        std::string description;
    28         CodeLocation location;
    2931
    3032        error() = default;
    31         error( const std::string & str ) : description( str ) {}
    32 
    33         void maybeSet( const CodeLocation & location ) {
    34                 if( this->location.isUnset() ) {
    35                         this->location = location;
    36                 }
    37         }
     33        error( CodeLocation loc, const std::string & str ) : location( loc ), description( str ) {}
    3834};
    3935
    4036class SemanticError : public std::exception {
    4137  public:
    42         SemanticError();
    43         SemanticError( std::string error );
    44         template< typename T > SemanticError( const std::string & error, const T * obj );
     38        SemanticError() = default;
     39        SemanticError( CodeLocation location, std::string error );
    4540        ~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);
    4645
    4746        static inline const std::string & error_str() {
     
    5150
    5251        void append( SemanticError & other );
    53         void append( const std::string & );
     52        void append( CodeLocation location, const std::string & );
    5453        bool isEmpty() const;
    55         void print( std::ostream & os );
    56 
    57         void set_location( const CodeLocation & location );
    58         // constructs an exception using the given message and the printed representation of the obj (T must have a print
    59         // method)
     54        void print();
    6055  private:
    6156        std::list< error > errors;
     
    6358
    6459template< typename T >
    65 SemanticError::SemanticError( const std::string & error, const T * obj ) {
    66         append( toString( error, obj ) );
     60SemanticError::SemanticError( const T * obj, const std::string & error )
     61        : SemanticError( obj->location, toString( error, obj ) )
     62{}
     63
     64template< typename T >
     65SemanticError::SemanticError( CodeLocation location, const T * obj, const std::string & error )
     66        : SemanticError( location, toString( error, obj ) )
     67{}
     68
     69//-----------------------------------------------------------------------------
     70// Warnings
     71class SemanticWarning {
     72  public:
     73        SemanticWarning( CodeLocation location, std::string error );
     74        ~SemanticWarning() throw() {}
     75
     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);
     79
     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:
     86};
     87
     88template< typename T >
     89SemanticWarning::SemanticWarning( const T * obj, const std::string & error )
     90        : SemanticWarning( obj->location, toString( error, obj ) )
     91{}
     92
     93template< typename T >
     94SemanticWarning::SemanticWarning( CodeLocation location, const T * obj, const std::string & error )
     95        : SemanticWarning( location, toString( error, obj ) )
     96{}
     97
     98//-----------------------------------------------------------------------------
     99// Helpers
     100static inline const std::string & bold_ttycode() {
     101        static std::string str = isatty( STDERR_FILENO ) ? "\e[1m" : "";
     102        return str;
     103}
     104
     105static inline const std::string & reset_font_ttycode() {
     106        static std::string str = isatty( STDERR_FILENO ) ? "\e[0m" : "";
     107        return str;
     108}
     109
     110static inline std::string make_bold( const std::string & str ) {
     111        return bold_ttycode() + str + reset_font_ttycode();
     112}
     113
     114struct bold {};
     115static inline std::ostream & operator<<(std::ostream & os, bold) {
     116        os << bold_ttycode();
     117        return os;
     118}
     119
     120struct reset_font {};
     121static inline std::ostream & operator<<(std::ostream & os, reset_font) {
     122        os << reset_font_ttycode();
     123        return os;
    67124}
    68125
  • src/Concurrency/Keywords.cc

    rd27e340 rd55d7a6  
    276276                        handle( decl );
    277277                }
    278 
    279278        }
    280279
     
    282281                if( ! decl->body ) return;
    283282
    284                 if( !type_decl ) throw SemanticError( context_error, decl );
     283                if( !type_decl ) throw SemanticError( decl, context_error );
    285284
    286285                FunctionDecl * func = forwardDeclare( decl );
     
    419418                if( mutexArgs.empty() ) return;
    420419
    421                 if( CodeGen::isConstructor(decl->name) ) throw SemanticError( "constructors cannot have mutex parameters", decl );
     420                if( CodeGen::isConstructor(decl->name) ) throw SemanticError( decl, "constructors cannot have mutex parameters" );
    422421
    423422                bool isDtor = CodeGen::isDestructor( decl->name );
    424423
    425                 if( isDtor && mutexArgs.size() != 1 ) throw SemanticError( "destructors can only have 1 mutex argument", decl );
     424                if( isDtor && mutexArgs.size() != 1 ) throw SemanticError( decl, "destructors can only have 1 mutex argument" );
    426425
    427426                for(auto arg : mutexArgs) {
     
    432431                if( ! body ) return;
    433432
    434                 if( !monitor_decl ) throw SemanticError( "mutex keyword requires monitors to be in scope, add #include <monitor>", decl );
    435                 if( !guard_decl ) throw SemanticError( "mutex keyword requires monitors to be in scope, add #include <monitor>", decl );
    436                 if( !dtor_guard_decl ) throw SemanticError( "mutex keyword requires monitors to be in scope, add #include <monitor>", decl );
     433                if( !monitor_decl ) throw SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>" );
     434                if( !guard_decl ) throw SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>" );
     435                if( !dtor_guard_decl ) throw SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>" );
    437436
    438437                if( isDtor ) {
     
    480479                //Makes sure it's not a copy
    481480                ReferenceType* rty = dynamic_cast< ReferenceType * >( ty );
    482                 if( ! rty ) throw SemanticError( "Mutex argument must be of reference type ", arg );
     481                if( ! rty ) throw SemanticError( arg, "Mutex argument must be of reference type " );
    483482
    484483                //Make sure the we are pointing directly to a type
    485484                Type* base = rty->get_base();
    486                 if( dynamic_cast< ReferenceType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg );
    487                 if( dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg );
     485                if( dynamic_cast< ReferenceType * >( base ) ) throw SemanticError( arg, "Mutex argument have exactly one level of indirection " );
     486                if( dynamic_cast< PointerType * >( base ) ) throw SemanticError( arg, "Mutex argument have exactly one level of indirection " );
    488487
    489488                //Make sure that typed isn't mutex
    490                 if( base->get_mutex() ) throw SemanticError( "mutex keyword may only appear once per argument ", arg );
     489                if( base->get_mutex() ) throw SemanticError( arg, "mutex keyword may only appear once per argument " );
    491490        }
    492491
     
    626625                if( type && type->get_baseStruct()->is_thread() ) {
    627626                        if( !thread_decl || !thread_ctor_seen ) {
    628                                 throw SemanticError("thread keyword requires threads to be in scope, add #include <thread>");
     627                                throw SemanticError( type->get_baseStruct()->location, "thread keyword requires threads to be in scope, add #include <thread>");
    629628                        }
    630629
  • src/Concurrency/Waitfor.cc

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

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

    rd27e340 rd55d7a6  
    9292                        } else if ( labelTable[ l ]->defined() ) {
    9393                                // defined twice, error
    94                                 throw SemanticError( "Duplicate definition of label: " + l.get_name() );
     94                                throw 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
     
    121121                for ( std::map< Label, Entry * >::iterator i = labelTable.begin(); i != labelTable.end(); ++i ) {
    122122                        if ( ! i->second->defined() ) {
    123                                 throw SemanticError( "Use of undefined label: " + i->first.get_name() );
     123                                throw 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/MLEMutator.cc

    rd27e340 rd55d7a6  
    115115                                        } else {
    116116                                                // break target is outmost control structure
    117                                                 if ( enclosingControlStructures.empty() ) throw SemanticError( "'break' outside a loop, switch, or labelled block" );
     117                                                if ( enclosingControlStructures.empty() ) throw 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( toString( (isContinue ? "'continue'" : "'break'"), " target must be an enclosing ", (isContinue ? "loop: " : "control structure: "), originalTarget ) );
     126                                        throw SemanticError( branchStmt->location, toString( (isContinue ? "'continue'" : "'break'"), " target must be an enclosing ", (isContinue ? "loop: " : "control structure: "), originalTarget ) );
    127127                                } // if
    128128                                break;
  • src/GenPoly/Box.cc

    rd27e340 rd55d7a6  
    229229                                } // if
    230230                        } catch( SemanticError &e ) {
    231                                 e.set_location( (*i)->location );
    232231                                errors.append( e );
    233232                        } // try
     
    576575                                                }
    577576                                        } else {
    578                                                 throw SemanticError( "Cannot pass non-struct type for generic struct: ", argBaseType );
     577                                                throw SemanticError( argBaseType, "Cannot pass non-struct type for generic struct: " );
    579578                                        }
    580579                                }
     
    598597                                        } else {
    599598                                                // xxx - should this be an assertion?
    600                                                 throw SemanticError( toString( *env, "\nunbound type variable: ", tyParm->first, " in application " ), appExpr );
     599                                                throw SemanticError( appExpr, toString( *env, "\nunbound type variable: ", tyParm->first, " in application " ) );
    601600                                        } // if
    602601                                } // if
  • src/InitTweak/FixInit.cc

    rd27e340 rd55d7a6  
    282282                                        translationUnit.splice( i, fixer.pass.staticDtorDecls );
    283283                                } catch( SemanticError &e ) {
    284                                         e.set_location( (*i)->location );
    285284                                        errors.append( e );
    286285                                } // try
     
    895894                        )
    896895                        if ( ! diff.empty() ) {
    897                                 throw SemanticError( std::string("jump to label '") + stmt->get_target().get_name() + "' crosses initialization of " + (*diff.begin())->get_name() + " ", stmt );
     896                                throw SemanticError( stmt, std::string("jump to label '") + stmt->get_target().get_name() + "' crosses initialization of " + (*diff.begin())->get_name() + " " );
    898897                        } // if
    899898                        // S_G-S_L results in set of objects that must be destructed
     
    11111110                template< typename Visitor, typename... Params >
    11121111                void error( Visitor & v, CodeLocation loc, const Params &... params ) {
    1113                         SemanticError err( toString( params... ) );
    1114                         err.set_location( loc );
     1112                        SemanticError err( loc, toString( params... ) );
    11151113                        v.errors.append( err );
    11161114                }
  • src/InitTweak/GenInit.cc

    rd27e340 rd55d7a6  
    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( "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n", objDecl );
     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" );
    320320                        // constructed objects should not have initializers nested too deeply
    321                         if ( ! checkInitDepth( objDecl ) ) throw SemanticError( "Managed object's initializer is too deep ", objDecl );
     321                        if ( ! checkInitDepth( objDecl ) ) throw SemanticError( objDecl, "Managed object's initializer is too deep " );
    322322
    323323                        objDecl->set_init( genCtorInit( objDecl ) );
  • src/InitTweak/InitTweak.cc

    rd27e340 rd55d7a6  
    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( "unbalanced list initializers" );
     227                                        throw SemanticError( init->location, "unbalanced list initializers" );
    228228                                }
    229229
  • src/Parser/DeclarationNode.cc

    rd27e340 rd55d7a6  
    581581                                        dst->basictype = src->basictype;
    582582                                } else if ( src->basictype != DeclarationNode::NoBasicType )
    583                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: ", src );
     583                                        throw SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: " );
    584584
    585585                                if ( dst->complextype == DeclarationNode::NoComplexType ) {
    586586                                        dst->complextype = src->complextype;
    587587                                } else if ( src->complextype != DeclarationNode::NoComplexType )
    588                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: ", src );
     588                                        throw SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: " );
    589589
    590590                                if ( dst->signedness == DeclarationNode::NoSignedness ) {
    591591                                        dst->signedness = src->signedness;
    592592                                } else if ( src->signedness != DeclarationNode::NoSignedness )
    593                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: ", src );
     593                                        throw SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: " );
    594594
    595595                                if ( dst->length == DeclarationNode::NoLength ) {
     
    598598                                        dst->length = DeclarationNode::LongLong;
    599599                                } else if ( src->length != DeclarationNode::NoLength )
    600                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: ", src );
     600                                        throw SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: " );
    601601                        } // if
    602602                        break;
     
    966966                        } // if
    967967                } catch( SemanticError &e ) {
    968                         e.set_location( cur->location );
    969968                        errors.append( e );
    970969                } // try
     
    10011000                        } // if
    10021001                } catch( SemanticError &e ) {
    1003                         e.set_location( cur->location );
    10041002                        errors.append( e );
    10051003                } // try
     
    10201018                        * out++ = cur->buildType();
    10211019                } catch( SemanticError &e ) {
    1022                         e.set_location( cur->location );
    10231020                        errors.append( e );
    10241021                } // try
     
    10321029
    10331030Declaration * DeclarationNode::build() const {
    1034         if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this );
     1031        if ( ! error.empty() ) throw SemanticError( this, error + " in declaration of " );
    10351032
    10361033        if ( asmStmt ) {
     
    10551052                //    inline _Noreturn int i;                   // disallowed
    10561053                if ( type->kind != TypeData::Function && funcSpecs.any() ) {
    1057                         throw SemanticError( "invalid function specifier for ", this );
     1054                        throw SemanticError( this, "invalid function specifier for " );
    10581055                } // if
    10591056                return buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, maybeBuild< Initializer >(initializer), attributes )->set_extension( extension );
     
    10651062        //    inlne _Noreturn enum   E { ... };         // disallowed
    10661063        if ( funcSpecs.any() ) {
    1067                 throw SemanticError( "invalid function specifier for ", this );
     1064                throw SemanticError( this, "invalid function specifier for " );
    10681065        } // if
    10691066        assertf( name, "ObjectDecl must a have name\n" );
  • src/Parser/ExpressionNode.cc

    rd27e340 rd55d7a6  
    356356
    357357Expression * build_field_name_FLOATING_FRACTIONconstant( const string & str ) {
    358         if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str );
     358        if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw 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( "invalid tuple index " + str );
     365        if ( str[str.size()-1] != '.' ) throw 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

    rd27e340 rd55d7a6  
    2424namespace LinkageSpec {
    2525
    26 Spec linkageCheck( const string * spec ) {
     26Spec linkageCheck( CodeLocation location, const string * spec ) {
    2727        assert( spec );
    2828        unique_ptr<const string> guard( spec ); // allocated by lexer
     
    3434                return BuiltinC;
    3535        } else {
    36                 throw SemanticError( "Invalid linkage specifier " + *spec );
     36                throw SemanticError( location, "Invalid linkage specifier " + *spec );
    3737        } // if
    3838}
    3939
    40 Spec linkageUpdate( Spec old_spec, const string * cmd ) {
     40Spec linkageUpdate( CodeLocation location, Spec old_spec, const string * cmd ) {
    4141        assert( cmd );
    4242        unique_ptr<const string> guard( cmd ); // allocated by lexer
     
    4848                return old_spec;
    4949        } else {
    50                 throw SemanticError( "Invalid linkage specifier " + *cmd );
     50                throw SemanticError( location, "Invalid linkage specifier " + *cmd );
    5151        } // if
    5252}
  • src/Parser/LinkageSpec.h

    rd27e340 rd55d7a6  
    1717
    1818#include <string>
     19
     20#include "Common/CodeLocation.h"
    1921
    2022namespace LinkageSpec {
     
    4547
    4648
    47         Spec linkageCheck( const std::string * );
     49        Spec linkageCheck( CodeLocation location, const std::string * );
    4850        // Returns the Spec with the given name (limited to C, Cforall & BuiltinC)
    49         Spec linkageUpdate( Spec old_spec, const std::string * cmd );
     51        Spec linkageUpdate( CodeLocation location, Spec old_spec, const std::string * cmd );
    5052        /* If cmd = "C" returns a Spec that is old_spec with is_mangled = false
    5153         * If cmd = "Cforall" returns old_spec Spec with is_mangled = true
  • src/Parser/ParseNode.h

    rd27e340 rd55d7a6  
    434434                        } // if
    435435                } catch( SemanticError &e ) {
    436                         e.set_location( cur->location );
    437436                        errors.append( e );
    438437                } // try
  • src/Parser/TypeData.cc

    rd27e340 rd55d7a6  
    521521
    522522static string genTSError( string msg, DeclarationNode::BasicType basictype ) {
    523         throw SemanticError( string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." );
     523        throw SemanticError( yylloc, string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." );
    524524} // genTSError
    525525
     
    923923                                // type set => parameter name already transformed by a declaration names so there is a duplicate
    924924                                // declaration name attempting a second transformation
    925                                 if ( param->type ) throw SemanticError( string( "duplicate declaration name " ) + *param->name );
     925                                if ( param->type ) throw SemanticError( param->location, string( "duplicate declaration name " ) + *param->name );
    926926                                // declaration type reset => declaration already transformed by a parameter name so there is a duplicate
    927927                                // parameter name attempting a second transformation
    928                                 if ( ! decl->type ) throw SemanticError( string( "duplicate parameter name " ) + *param->name );
     928                                if ( ! decl->type ) throw SemanticError( param->location, string( "duplicate parameter name " ) + *param->name );
    929929                                param->type = decl->type;                               // set copy declaration type to parameter type
    930930                                decl->type = nullptr;                                   // reset declaration type
     
    933933                } // for
    934934                // declaration type still set => type not moved to a matching parameter so there is a missing parameter name
    935                 if ( decl->type ) throw SemanticError( string( "missing name in parameter list " ) + *decl->name );
     935                if ( decl->type ) throw SemanticError( decl->location, string( "missing name in parameter list " ) + *decl->name );
    936936        } // for
    937937
  • src/Parser/parser.yy

    rd27e340 rd55d7a6  
    482482                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); }
    483483        | type_name '.' no_attr_identifier                                      // CFA, nested type
    484                 { throw SemanticError("Qualified names are currently unimplemented."); $$ = nullptr; } // FIX ME
     484                { throw 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("Qualified names are currently unimplemented."); $$ = nullptr; } // FIX ME
     486                { throw SemanticError(yylloc, "Qualified names are currently unimplemented."); $$ = nullptr; } // FIX ME
    487487        ;
    488488
     
    10721072mutex_statement:
    10731073        MUTEX '(' argument_expression_list ')' statement
    1074                 { throw SemanticError("Mutex statement is currently unimplemented."); $$ = nullptr; } // FIX ME
     1074                { throw SemanticError(yylloc, "Mutex statement is currently unimplemented."); $$ = nullptr; } // FIX ME
    10751075        ;
    10761076
     
    12931293static_assert:
    12941294        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    1295                 { throw SemanticError("Static assert is currently unimplemented."); $$ = nullptr; }     // FIX ME
     1295                { throw SemanticError(yylloc, "Static assert is currently unimplemented."); $$ = nullptr; }     // FIX ME
    12961296
    12971297// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
     
    23812381                {
    23822382                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2383                         linkage = LinkageSpec::linkageUpdate( linkage, $2 );
     2383                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23842384                }
    23852385          '{' external_definition_list_opt '}'
  • src/ResolvExpr/AlternativeFinder.cc

    rd27e340 rd55d7a6  
    252252                                std::cerr << "No reasonable alternatives for expression " << expr << std::endl;
    253253                        )
    254                         throw SemanticError( "No reasonable alternatives for expression ", expr );
     254                        throw SemanticError( expr, "No reasonable alternatives for expression " );
    255255                }
    256256                if ( prune ) {
     
    270270                                stream << "Alternatives are:\n";
    271271                                printAlts( winners, stream, 1 );
    272                                 throw SemanticError( stream.str() );
     272                                throw SemanticError( expr->location, stream.str() );
    273273                        }
    274274                        alternatives = move(pruned);
     
    507507                                return;
    508508                        } else if ( level >= recursionLimit ) {
    509                                 throw SemanticError( "Too many recursive assertions" );
     509                                throw SemanticError( newAlt.expr->location, "Too many recursive assertions" );
    510510                        } else {
    511511                                AssertionSet newerNeed;
     
    14211421                        findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) );
    14221422                        if ( winners.size() != 1 ) {
    1423                                 throw SemanticError( "Ambiguous expression in sizeof operand: ", sizeofExpr->get_expr() );
     1423                                throw SemanticError( sizeofExpr->get_expr(), "Ambiguous expression in sizeof operand: " );
    14241424                        } // if
    14251425                        // return the lowest cost alternative for the argument
     
    14421442                        findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) );
    14431443                        if ( winners.size() != 1 ) {
    1444                                 throw SemanticError( "Ambiguous expression in alignof operand: ", alignofExpr->get_expr() );
     1444                                throw SemanticError( alignofExpr->get_expr(), "Ambiguous expression in alignof operand: " );
    14451445                        } // if
    14461446                        // return the lowest cost alternative for the argument
  • src/ResolvExpr/CurrentObject.cc

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

    rd27e340 rd55d7a6  
    188188                        findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) );
    189189                        if ( winners.size() == 0 ) {
    190                                 throw SemanticError( "No reasonable alternatives for " + kindStr + " expression: ", untyped );
     190                                throw SemanticError( untyped, "No reasonable alternatives for " + kindStr + " expression: " );
    191191                        } else if ( winners.size() != 1 ) {
    192192                                std::ostringstream stream;
     
    195195                                stream << "Alternatives are:\n";
    196196                                printAlts( winners, stream, 1 );
    197                                 throw SemanticError( stream.str() );
     197                                throw SemanticError( untyped->location, stream.str() );
    198198                        }
    199199
     
    429429                                ss << strict_dynamic_cast<NameExpr*>( clause.target.function )->name;
    430430                                ss << "' in call to waitfor";
    431                                 throw SemanticError( ss.str() );
     431                                throw SemanticError( stmt->location, ss.str() );
    432432                        }
    433433
     
    451451                                        PointerType * pointer = dynamic_cast< PointerType* >( func.expr->get_result()->stripReferences() );
    452452                                        if( !pointer ) {
    453                                                 throw SemanticError( "candidate not viable: not a pointer type\n", func.expr->get_result() );
     453                                                throw SemanticError( func.expr->get_result(), "candidate not viable: not a pointer type\n" );
    454454                                        }
    455455
    456456                                        FunctionType * function = dynamic_cast< FunctionType* >( pointer->get_base() );
    457457                                        if( !function ) {
    458                                                 throw SemanticError( "candidate not viable: not a function type\n", pointer->get_base() );
     458                                                throw SemanticError( pointer->get_base(), "candidate not viable: not a function type\n" );
    459459                                        }
    460460
     
    465465
    466466                                                if( !advance_to_mutex( param, param_end ) ) {
    467                                                         throw SemanticError("candidate function not viable: no mutex parameters\n", function);
     467                                                        throw SemanticError(function, "candidate function not viable: no mutex parameters\n");
    468468                                                }
    469469                                        }
     
    504504                                                                        // We ran out of parameters but still have arguments
    505505                                                                        // this function doesn't match
    506                                                                         throw SemanticError("candidate function not viable: too many mutex arguments\n", function);
     506                                                                        throw SemanticError( function, "candidate function not viable: too many mutex arguments\n" );
    507507                                                                }
    508508
     
    516516                                                                        (*param)->get_type()->print( ss );
    517517                                                                        ss << "'\n";
    518                                                                         throw SemanticError(ss.str(), function);
     518                                                                        throw SemanticError( function, ss.str() );
    519519                                                                }
    520520
     
    528528                                                                // We ran out of arguments but still have parameters left
    529529                                                                // this function doesn't match
    530                                                                 throw SemanticError("candidate function not viable: too few mutex arguments\n", function);
     530                                                                throw SemanticError( function, "candidate function not viable: too few mutex arguments\n" );
    531531                                                        }
    532532
     
    555555
    556556                        // Make sure we got the right number of arguments
    557                         if( func_candidates.empty() )    { SemanticError top( "No alternatives for function in call to waitfor"  ); top.append( errors ); throw top; }
    558                         if( args_candidates.empty() )    { SemanticError top( "No alternatives for arguments in call to waitfor" ); top.append( errors ); throw top; }
    559                         if( func_candidates.size() > 1 ) { SemanticError top( "Ambiguous function in call to waitfor"            ); top.append( errors ); throw top; }
    560                         if( args_candidates.size() > 1 ) { SemanticError top( "Ambiguous arguments in call to waitfor"           ); top.append( errors ); throw top; }
     557                        if( func_candidates.empty() )    { SemanticError top( stmt->location, "No alternatives for function in call to waitfor"  ); top.append( errors ); throw top; }
     558                        if( args_candidates.empty() )    { SemanticError top( stmt->location, "No alternatives for arguments in call to waitfor" ); top.append( errors ); throw top; }
     559                        if( func_candidates.size() > 1 ) { SemanticError top( stmt->location, "Ambiguous function in call to waitfor"            ); top.append( errors ); throw top; }
     560                        if( args_candidates.size() > 1 ) { SemanticError top( stmt->location, "Ambiguous arguments in call to waitfor"           ); top.append( errors ); throw top; }
    561561
    562562
  • src/SymTab/Indexer.cc

    rd27e340 rd55d7a6  
    388388                        if ( newentry && oldentry ) {
    389389                                if ( newentry->get_statements() && oldentry->get_statements() ) {
    390                                         throw SemanticError( "duplicate function definition for ", added );
     390                                        throw SemanticError( added, "duplicate function definition for " );
    391391                                } // if
    392392                        } else {
     
    398398                                ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( existing );
    399399                                if ( ! newobj->get_storageClasses().is_extern && ! oldobj->get_storageClasses().is_extern ) {
    400                                         throw SemanticError( "duplicate object definition for ", added );
     400                                        throw SemanticError( added, "duplicate object definition for " );
    401401                                } // if
    402402                        } // if
    403403                } else {
    404                         throw SemanticError( "duplicate definition for ", added );
     404                        throw SemanticError( added, "duplicate definition for " );
    405405                } // if
    406406
     
    431431                        // isomorphic to C type-compatibility, which it may not be.
    432432                        if ( hasIncompatibleCDecl( name, mangleName, scope ) ) {
    433                                 throw SemanticError( "conflicting overload of C function ", decl );
     433                                throw SemanticError( decl, "conflicting overload of C function " );
    434434                        }
    435435                } else {
    436436                        // Check that a Cforall declaration doesn't overload any C declaration
    437437                        if ( hasCompatibleCDecl( name, mangleName, scope ) ) {
    438                                 throw SemanticError( "Cforall declaration hides C function ", decl );
     438                                throw SemanticError( decl, "Cforall declaration hides C function " );
    439439                        }
    440440                }
     
    455455                        return true;
    456456                } else {
    457                         throw SemanticError( "redeclaration of ", added );
     457                        throw SemanticError( added, "redeclaration of " );
    458458                }
    459459        }
     
    482482                        return false;
    483483                } else if ( ! added->get_members().empty() ) {
    484                         throw SemanticError( "redeclaration of ", added );
     484                        throw SemanticError( added, "redeclaration of " );
    485485                } // if
    486486                return true;
  • src/SymTab/Validate.cc

    rd27e340 rd55d7a6  
    366366                                dwts.erase( j );
    367367                                if ( i != end ) {
    368                                         throw SemanticError( "invalid type void in function type ", func );
     368                                        throw SemanticError( func, "invalid type void in function type " );
    369369                                } // if
    370370                        } else {
     
    374374                                        *i = (*i)->acceptMutator( fixer );
    375375                                        if ( fixer.pass.isVoid ) {
    376                                                 throw SemanticError( "invalid type void in function type ", func );
     376                                                throw SemanticError( func, "invalid type void in function type " );
    377377                                        } // if
    378378                                } // for
     
    411411                for ( Expression * param : inst->parameters ) {
    412412                        if ( ! dynamic_cast< TypeExpr * >( param ) ) {
    413                                 throw SemanticError( "Expression parameters for generic types are currently unsupported: ", inst );
     413                                throw SemanticError( inst, "Expression parameters for generic types are currently unsupported: " );
    414414                        }
    415415                }
     
    511511                TraitDecl *traitDecl = local_indexer->lookupTrait( traitInst->name );
    512512                if ( ! traitDecl ) {
    513                         throw SemanticError( "use of undeclared trait " + traitInst->name );
     513                        throw SemanticError( traitInst->location, "use of undeclared trait " + traitInst->name );
    514514                } // if
    515515                if ( traitDecl->get_parameters().size() != traitInst->get_parameters().size() ) {
    516                         throw SemanticError( "incorrect number of trait parameters: ", traitInst );
     516                        throw SemanticError( traitInst, "incorrect number of trait parameters: " );
    517517                } // if
    518518                traitInst->baseTrait = traitDecl;
     
    522522                        TypeExpr * expr = dynamic_cast< TypeExpr * >( std::get<1>(p) );
    523523                        if ( ! expr ) {
    524                                 throw SemanticError( "Expression parameters for trait instances are currently unsupported: ", std::get<1>(p) );
     524                                throw SemanticError( std::get<1>(p), "Expression parameters for trait instances are currently unsupported: " );
    525525                        }
    526526                        if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) {
     
    629629                                assertion = assertion->acceptMutator( fixer );
    630630                                if ( fixer.pass.isVoid ) {
    631                                         throw SemanticError( "invalid type void in assertion of function ", node );
     631                                        throw SemanticError( node, "invalid type void in assertion of function " );
    632632                                } // if
    633633                        } // for
     
    673673                // were cast to void.
    674674                if ( ! returnStmt->get_expr() && returnVals.size() != 0 ) {
    675                         throw SemanticError( "Non-void function returns no values: " , returnStmt );
     675                        throw SemanticError( returnStmt, "Non-void function returns no values: " );
    676676                }
    677677        }
     
    714714                                ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret);
    715715                                if ( ! rtt ) {
    716                                         throw SemanticError("Cannot apply type parameters to base type of " + typeInst->name);
     716                                        throw SemanticError( typeInst->location, "Cannot apply type parameters to base type of " + typeInst->name );
    717717                                }
    718718                                rtt->get_parameters().clear();
     
    752752                        Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
    753753                        if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) {
    754                                 throw SemanticError( "Cannot redefine typedef: " + tyDecl->name );
     754                                throw SemanticError( tyDecl->location, "Cannot redefine typedef: " + tyDecl->name );
    755755                        }
    756756                        // Cannot redefine VLA typedefs. Note: this is slightly incorrect, because our notion of VLAs
     
    759759                        // to fix this corner case likely outweighs the utility of allowing it.
    760760                        if ( isVariableLength( t1 ) || isVariableLength( t2 ) ) {
    761                                 throw SemanticError( "Cannot redefine typedef: " + tyDecl->name );
     761                                throw SemanticError( tyDecl->location, "Cannot redefine typedef: " + tyDecl->name );
    762762                        }
    763763                } else {
     
    908908                if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc.
    909909                        if ( params.size() == 0 ) {
    910                                 throw SemanticError( "Constructors, destructors, and assignment functions require at least one parameter ", funcDecl );
     910                                throw SemanticError( funcDecl, "Constructors, destructors, and assignment functions require at least one parameter " );
    911911                        }
    912912                        ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() );
    913913                        if ( ! refType ) {
    914                                 throw SemanticError( "First parameter of a constructor, destructor, or assignment function must be a reference ", funcDecl );
     914                                throw SemanticError( funcDecl, "First parameter of a constructor, destructor, or assignment function must be a reference " );
    915915                        }
    916916                        if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
    917                                 throw SemanticError( "Constructors and destructors cannot have explicit return values ", funcDecl );
     917                                throw SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " );
    918918                        }
    919919                }
     
    950950
    951951                        sub.apply( inst );
    952                         if ( args.size() < params->size() ) throw SemanticError( "Too few type arguments in generic type ", inst );
    953                         if ( args.size() > params->size() ) throw SemanticError( "Too many type arguments in generic type ", inst );
     952                        if ( args.size() < params->size() ) throw SemanticError( inst, "Too few type arguments in generic type " );
     953                        if ( args.size() > params->size() ) throw SemanticError( inst, "Too many type arguments in generic type " );
    954954                }
    955955        }
  • src/SynTree/Expression.cc

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

    rd27e340 rd55d7a6  
    148148                        } // if
    149149                } catch( SemanticError &e ) {
    150                         e.set_location( (*i)->location );
    151150                        errors.append( e );
    152151                } // try
  • src/SynTree/Statement.cc

    rd27e340 rd55d7a6  
    100100        //actually this is a syntactic error signaled by the parser
    101101        if ( type == BranchStmt::Goto && target.empty() ) {
    102                 throw SemanticError("goto without target");
     102                throw SemanticError( target.get_statement()->location, "goto without target");
    103103        }
    104104}
     
    107107        Statement(), computedTarget( computedTarget ), type( type ) {
    108108        if ( type != BranchStmt::Goto || computedTarget == nullptr ) {
    109                 throw SemanticError("Computed target not valid in branch statement");
     109                throw SemanticError( computedTarget->location, "Computed target not valid in branch statement");
    110110        }
    111111}
     
    203203CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
    204204        Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    205         if ( isDefault() && condition != 0 ) throw SemanticError("default case with condition: ", condition);
     205        if ( isDefault() && condition != 0 ) throw SemanticError( condition, "default case with condition: " );
    206206}
    207207
  • src/SynTree/TypeSubstitution.h

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

    rd27e340 rd55d7a6  
    142142                        }
    143143                } catch( SemanticError &e ) {
    144                         e.set_location( (*i)->location );
    145144                        errors.append( e );
    146145                }
  • src/main.cc

    rd27e340 rd55d7a6  
    361361                        cerr << endl << "---End of AST, begin error message:---\n" << endl;
    362362                } // if
    363                 e.print( cerr );
     363                e.print();
    364364                if ( output != &cout ) {
    365365                        delete output;
Note: See TracChangeset for help on using the changeset viewer.