Changeset a16764a6
- Timestamp:
- Feb 28, 2018, 4:48:22 PM (6 years ago)
- 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
- Location:
- src
- Files:
-
- 1 added
- 45 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r6a8df56 ra16764a6 18 18 #include <list> // for _List_iterator, list, list<>::it... 19 19 20 #include "Common/SemanticError.h" // for SemanticError21 20 #include "Common/UniqueName.h" // for UniqueName 22 21 #include "Common/utility.h" // for CodeLocation, toString -
src/CodeGen/FixMain.cc
r6a8df56 ra16764a6 39 39 { 40 40 if(main_signature) { 41 throwSemanticError(functionDecl, "Multiple definition of main routine\n");41 SemanticError(functionDecl, "Multiple definition of main routine\n"); 42 42 } 43 43 main_signature.reset( functionDecl->clone() ); -
src/CodeGen/FixNames.cc
r6a8df56 ra16764a6 118 118 int nargs = functionDecl->get_functionType()->get_parameters().size(); 119 119 if( !(nargs == 0 || nargs == 2 || nargs == 3) ) { 120 throwSemanticError(functionDecl, "Main expected to have 0, 2 or 3 arguments\n");120 SemanticError(functionDecl, "Main expected to have 0, 2 or 3 arguments\n"); 121 121 } 122 122 functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( new ConstantExpr( Constant::from_int( 0 ) ) ) ); -
src/CodeTools/DeclStats.cc
r6a8df56 ra16764a6 24 24 25 25 #include "Common/PassVisitor.h" 26 #include "Common/SemanticError.h" // for SemanticError27 26 #include "Common/VectorMap.h" // for VectorMap 28 27 #include "GenPoly/GenPoly.h" // for hasPolyBase -
src/CodeTools/TrackLoc.cc
r6a8df56 ra16764a6 24 24 25 25 #include "Common/PassVisitor.h" // for PassVisitor 26 #include "Common/SemanticError.h" // for SemanticError27 26 #include "Common/utility.h" // for CodeLocation 28 27 #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode -
src/Common/PassVisitor.impl.h
r6a8df56 ra16764a6 65 65 DeclList_t* beforeDecls = visitor.get_beforeDecls(); 66 66 DeclList_t* afterDecls = visitor.get_afterDecls(); 67 SemanticError errors;67 SemanticErrorException errors; 68 68 69 69 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { … … 76 76 // run visitor on declaration 77 77 maybeAccept_impl( *i, visitor ); 78 } catch( SemanticError &e ) {78 } catch( SemanticErrorException &e ) { 79 79 errors.append( e ); 80 80 } … … 92 92 DeclList_t* beforeDecls = mutator.get_beforeDecls(); 93 93 DeclList_t* afterDecls = mutator.get_afterDecls(); 94 SemanticError errors;94 SemanticErrorException errors; 95 95 96 96 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { … … 102 102 // run mutator on declaration 103 103 maybeMutate_impl( *i, mutator ); 104 } catch( SemanticError &e ) {104 } catch( SemanticErrorException &e ) { 105 105 errors.append( e ); 106 106 } … … 125 125 inline void maybeAccept_impl( Container & container, PassVisitor< pass_type > & visitor ) { 126 126 if ( ! visitor.get_visit_children() ) return; 127 SemanticError errors;127 SemanticErrorException errors; 128 128 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 129 129 try { … … 131 131 (*i)->accept( visitor ); 132 132 } 133 } catch( SemanticError &e ) {133 } catch( SemanticErrorException &e ) { 134 134 errors.append( e ); 135 135 } … … 152 152 inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) { 153 153 if ( ! mutator.get_visit_children() ) return; 154 SemanticError errors;154 SemanticErrorException errors; 155 155 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 156 156 try { … … 159 159 assert( *i ); 160 160 } // if 161 } catch( SemanticError &e ) {161 } catch( SemanticErrorException &e ) { 162 162 errors.append( e ); 163 163 } // try … … 172 172 void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) { 173 173 if ( ! get_visit_children() ) return; 174 SemanticError errors;174 SemanticErrorException errors; 175 175 176 176 // don't want statements from outer CompoundStmts to be added to this CompoundStmt … … 195 195 || ( empty( beforeDecls ) && empty( afterDecls )) ); 196 196 197 } catch ( SemanticError &e ) {197 } catch ( SemanticErrorException &e ) { 198 198 errors.append( e ); 199 199 } -
src/Common/SemanticError.cc
r6a8df56 ra16764a6 23 23 #include "SemanticError.h" 24 24 25 SemanticError ::SemanticError( CodeLocation location, std::string error ) {25 SemanticErrorException::SemanticErrorException( CodeLocation location, std::string error ) { 26 26 append( location, error ); 27 27 } 28 28 29 void SemanticError ::append( SemanticError&other ) {29 void SemanticErrorException::append( SemanticErrorException &other ) { 30 30 errors.splice( errors.end(), other.errors ); 31 31 } 32 32 33 void SemanticError ::append( CodeLocation location, const std::string & msg ) {33 void SemanticErrorException::append( CodeLocation location, const std::string & msg ) { 34 34 errors.emplace_back( location, msg ); 35 35 } 36 36 37 bool SemanticError ::isEmpty() const {37 bool SemanticErrorException::isEmpty() const { 38 38 return errors.empty(); 39 39 } 40 40 41 void SemanticError ::print() {41 void SemanticErrorException::print() { 42 42 using std::to_string; 43 43 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; 45 45 } 46 46 } 47 47 48 SemanticWarning::SemanticWarning( CodeLocation location, std::string msg ) { 49 std::cerr << bold() << location << warning_str() << reset_font() << msg << std::endl; 48 void SemanticError( CodeLocation location, std::string error ) { 49 throw SemanticErrorException(location, error); 50 } 51 52 void 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 58 namespace 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 } 50 92 } 51 93 -
src/Common/SemanticError.h
r6a8df56 ra16764a6 16 16 #pragma once 17 17 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" 25 19 26 20 //----------------------------------------------------------------------------- 27 21 // Errors 28 struct error {29 CodeLocation location;30 std::string description;31 22 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 ); 58 24 59 25 template< 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 } 63 29 64 30 template< 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 } 68 34 69 35 //----------------------------------------------------------------------------- 70 36 // Warnings 71 class SemanticWarning {72 public:73 SemanticWarning( CodeLocation location, std::string error );74 ~SemanticWarning() throw() {}75 37 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); 38 constexpr const char * const WarningFormats[] = { 79 39 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 40 }; 87 41 88 template< typename T > 89 SemanticWarning::SemanticWarning( const T * obj, const std::string & error ) 90 : SemanticWarning( obj->location, toString( error, obj ) ) 91 {} 42 enum class Warning { 43 NUMBER_OF_WARNINGS, //This MUST be the last warning 44 }; 92 45 93 template< typename T > 94 SemanticWarning::SemanticWarning( CodeLocation location, const T * obj, const std::string & error ) 95 : SemanticWarning( location, toString( error, obj ) ) 96 {} 46 static_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 53 void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4))); 54 97 55 98 56 //----------------------------------------------------------------------------- 99 57 // Helpers 100 static inline const std::string & bold_ttycode() { 101 static std::string str = isatty( STDERR_FILENO ) ? "\e[1m" : ""; 102 return str; 58 namespace 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); 103 71 } 104 72 105 static inline const std::string & reset_font_ttycode() {106 static std::string str = isatty( STDERR_FILENO ) ? "\e[0m" : "";107 return str;108 }109 73 110 static inline std::string make_bold( const std::string & str ) {111 return bold_ttycode() + str + reset_font_ttycode();112 }113 74 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 }125 75 126 76 // Local Variables: // -
src/Concurrency/Keywords.cc
r6a8df56 ra16764a6 280 280 if( ! decl->body ) return; 281 281 282 if( !type_decl ) throwSemanticError( decl, context_error );282 if( !type_decl ) SemanticError( decl, context_error ); 283 283 284 284 FunctionDecl * func = forwardDeclare( decl ); … … 417 417 if( mutexArgs.empty() ) return; 418 418 419 if( CodeGen::isConstructor(decl->name) ) throwSemanticError( decl, "constructors cannot have mutex parameters" );419 if( CodeGen::isConstructor(decl->name) ) SemanticError( decl, "constructors cannot have mutex parameters" ); 420 420 421 421 bool isDtor = CodeGen::isDestructor( decl->name ); 422 422 423 if( isDtor && mutexArgs.size() != 1 ) throwSemanticError( decl, "destructors can only have 1 mutex argument" );423 if( isDtor && mutexArgs.size() != 1 ) SemanticError( decl, "destructors can only have 1 mutex argument" ); 424 424 425 425 for(auto arg : mutexArgs) { … … 430 430 if( ! body ) return; 431 431 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>" ); 435 434 436 435 if( isDtor ) { … … 478 477 //Makes sure it's not a copy 479 478 ReferenceType* rty = dynamic_cast< ReferenceType * >( ty ); 480 if( ! rty ) throwSemanticError( arg, "Mutex argument must be of reference type " );479 if( ! rty ) SemanticError( arg, "Mutex argument must be of reference type " ); 481 480 482 481 //Make sure the we are pointing directly to a type 483 482 Type* base = rty->get_base(); 484 if( dynamic_cast< ReferenceType * >( base ) ) throwSemanticError( arg, "Mutex argument have exactly one level of indirection " );485 if( dynamic_cast< PointerType * >( base ) ) throwSemanticError( 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 " ); 486 485 487 486 //Make sure that typed isn't mutex 488 if( base->get_mutex() ) throwSemanticError( arg, "mutex keyword may only appear once per argument " );487 if( base->get_mutex() ) SemanticError( arg, "mutex keyword may only appear once per argument " ); 489 488 } 490 489 … … 624 623 if( type && type->get_baseStruct()->is_thread() ) { 625 624 if( !thread_decl || !thread_ctor_seen ) { 626 throwSemanticError( 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>"); 627 626 } 628 627 -
src/Concurrency/Waitfor.cc
r6a8df56 ra16764a6 250 250 Statement * GenerateWaitForPass::postmutate( WaitForStmt * waitfor ) { 251 251 if( !decl_monitor || !decl_acceptable || !decl_mask ) 252 throwSemanticError( 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>" ); 253 253 254 254 CompoundStmt * stmt = new CompoundStmt(); -
src/ControlStruct/ExceptTranslate.cc
r6a8df56 ra16764a6 572 572 // Pass. 573 573 } else if ( CatchStmt::Terminate == catchStmt->get_kind() ) { 574 throwSemanticError(catchStmt->location, "catch must have exception type");574 SemanticError(catchStmt->location, "catch must have exception type"); 575 575 } else { 576 throwSemanticError(catchStmt->location, "catchResume must have exception type");576 SemanticError(catchStmt->location, "catchResume must have exception type"); 577 577 } 578 578 -
src/ControlStruct/LabelFixer.cc
r6a8df56 ra16764a6 92 92 } else if ( labelTable[ l ]->defined() ) { 93 93 // defined twice, error 94 throwSemanticError( l.get_statement()->location, "Duplicate definition of label: " + l.get_name() );94 SemanticError( l.get_statement()->location, "Duplicate definition of label: " + l.get_name() ); 95 95 } else { 96 96 // used previously, but undefined until now -> link with this entry … … 117 117 118 118 // 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 ) { 120 120 std::map< Label, Statement * > *ret = new std::map< Label, Statement * >(); 121 121 for ( std::map< Label, Entry * >::iterator i = labelTable.begin(); i != labelTable.end(); ++i ) { 122 122 if ( ! i->second->defined() ) { 123 throwSemanticError( 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() ); 124 124 } 125 125 (*ret)[ i->first ] = i->second->get_definition(); -
src/ControlStruct/LabelFixer.h
r6a8df56 ra16764a6 33 33 LabelFixer( LabelGenerator *gen = 0 ); 34 34 35 std::map < Label, Statement * > *resolveJumps() throw ( SemanticError );35 std::map < Label, Statement * > *resolveJumps() throw ( SemanticErrorException ); 36 36 37 37 // Declarations -
src/ControlStruct/MLEMutator.cc
r6a8df56 ra16764a6 98 98 99 99 100 Statement *MLEMutator::postmutate( BranchStmt *branchStmt ) throw ( SemanticError ) {100 Statement *MLEMutator::postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException ) { 101 101 std::string originalTarget = branchStmt->originalTarget; 102 102 … … 115 115 } else { 116 116 // break target is outmost control structure 117 if ( enclosingControlStructures.empty() ) throwSemanticError( 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" ); 118 118 targetEntry = enclosingControlStructures.rbegin(); 119 119 } // if … … 124 124 // ensure that selected target is valid 125 125 if ( targetEntry == enclosingControlStructures.rend() || (isContinue && ! isLoop( targetEntry->get_controlStructure() ) ) ) { 126 throwSemanticError( 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 ) ); 127 127 } // if 128 128 break; -
src/ControlStruct/MLEMutator.h
r6a8df56 ra16764a6 37 37 38 38 void premutate( CompoundStmt *cmpndStmt ); 39 Statement * postmutate( BranchStmt *branchStmt ) throw ( SemanticError );39 Statement * postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException ); 40 40 void premutate( WhileStmt *whileStmt ); 41 41 Statement * postmutate( WhileStmt *whileStmt ); -
src/ControlStruct/Mutate.cc
r6a8df56 ra16764a6 18 18 19 19 #include "Common/PassVisitor.h" // for mutateAll 20 #include "Common/SemanticError.h" // for SemanticError21 20 #include "ForExprMutator.h" // for ForExprMutator 22 21 #include "LabelFixer.h" // for LabelFixer -
src/GenPoly/Box.cc
r6a8df56 ra16764a6 215 215 inline void mutateTranslationUnit( std::list< Declaration* > &translationUnit, MutatorType &mutator ) { 216 216 bool seenIntrinsic = false; 217 SemanticError errors;217 SemanticErrorException errors; 218 218 for ( typename std::list< Declaration* >::iterator i = translationUnit.begin(); i != translationUnit.end(); ++i ) { 219 219 try { … … 228 228 assert( *i ); 229 229 } // if 230 } catch( SemanticError &e ) {230 } catch( SemanticErrorException &e ) { 231 231 errors.append( e ); 232 232 } // try … … 575 575 } 576 576 } else { 577 throwSemanticError( argBaseType, "Cannot pass non-struct type for generic struct: " );577 SemanticError( argBaseType, "Cannot pass non-struct type for generic struct: " ); 578 578 } 579 579 } … … 597 597 } else { 598 598 // xxx - should this be an assertion? 599 throwSemanticError( appExpr, toString( *env, "\nunbound type variable: ", tyParm->first, " in application " ) );599 SemanticError( appExpr, toString( *env, "\nunbound type variable: ", tyParm->first, " in application " ) ); 600 600 } // if 601 601 } // if -
src/GenPoly/FindFunction.cc
r6a8df56 ra16764a6 19 19 20 20 #include "Common/PassVisitor.h" // for PassVisitor 21 #include "Common/SemanticError.h" // for SemanticError22 21 #include "GenPoly/ErasableScopedMap.h" // for ErasableScopedMap<>::iterator 23 22 #include "GenPoly/GenPoly.h" // for TyVarMap -
src/GenPoly/InstantiateGeneric.cc
r6a8df56 ra16764a6 24 24 #include "Common/PassVisitor.h" // for PassVisitor, WithDeclsToAdd 25 25 #include "Common/ScopedMap.h" // for ScopedMap 26 #include "Common/SemanticError.h" // for SemanticError27 26 #include "Common/UniqueName.h" // for UniqueName 28 27 #include "Common/utility.h" // for deleteAll, cloneAll -
src/GenPoly/Lvalue.cc
r6a8df56 ra16764a6 18 18 19 19 #include "Common/PassVisitor.h" 20 #include "Common/SemanticError.h" // for SemanticError21 20 #include "GenPoly.h" // for isPolyType 22 21 #include "Lvalue.h" -
src/GenPoly/Specialize.cc
r6a8df56 ra16764a6 23 23 24 24 #include "Common/PassVisitor.h" 25 #include "Common/SemanticError.h" // for SemanticError26 25 #include "Common/UniqueName.h" // for UniqueName 27 26 #include "Common/utility.h" // for group_iterate -
src/InitTweak/FixGlobalInit.cc
r6a8df56 ra16764a6 21 21 22 22 #include "Common/PassVisitor.h" 23 #include "Common/SemanticError.h" // for SemanticError24 23 #include "Common/UniqueName.h" // for UniqueName 25 24 #include "InitTweak.h" // for isIntrinsicSingleArgCallStmt -
src/InitTweak/FixInit.cc
r6a8df56 ra16764a6 213 213 Expression * postmutate( UntypedExpr * expr ); 214 214 215 SemanticError errors;215 SemanticErrorException errors; 216 216 private: 217 217 template< typename... Params > … … 276 276 // can't use mutateAll, because need to insert declarations at top-level 277 277 // can't use DeclMutator, because sometimes need to insert IfStmt, etc. 278 SemanticError errors;278 SemanticErrorException errors; 279 279 for ( std::list< Declaration * >::iterator i = translationUnit.begin(); i != translationUnit.end(); ++i ) { 280 280 try { 281 281 maybeMutate( *i, fixer ); 282 282 translationUnit.splice( i, fixer.pass.staticDtorDecls ); 283 } catch( SemanticError &e ) {283 } catch( SemanticErrorException &e ) { 284 284 errors.append( e ); 285 285 } // try … … 894 894 ) 895 895 if ( ! diff.empty() ) { 896 throwSemanticError( 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() + " " ); 897 897 } // if 898 898 // S_G-S_L results in set of objects that must be destructed … … 945 945 GuardValue( isCtor ); 946 946 GuardValue( structDecl ); 947 errors = SemanticError (); // clear previous errors947 errors = SemanticErrorException(); // clear previous errors 948 948 949 949 // need to start with fresh sets … … 1034 1034 function->get_statements()->push_back( callStmt ); 1035 1035 } 1036 } catch ( SemanticError & error ) {1036 } catch ( SemanticErrorException & error ) { 1037 1037 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" ); 1038 1038 } … … 1110 1110 template< typename Visitor, typename... Params > 1111 1111 void error( Visitor & v, CodeLocation loc, const Params &... params ) { 1112 SemanticError err( loc, toString( params... ) );1112 SemanticErrorException err( loc, toString( params... ) ); 1113 1113 v.errors.append( err ); 1114 1114 } -
src/InitTweak/GenInit.cc
r6a8df56 ra16764a6 317 317 if ( tryConstruct( objDecl ) && ( managedTypes.isManaged( objDecl ) || ((! inFunction || objDecl->get_storageClasses().is_static ) && ! isConstExpr( objDecl->get_init() ) ) ) ) { 318 318 // constructed objects cannot be designated 319 if ( isDesignated( objDecl->get_init() ) ) throwSemanticError( 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" ); 320 320 // constructed objects should not have initializers nested too deeply 321 if ( ! checkInitDepth( objDecl ) ) throwSemanticError( objDecl, "Managed object's initializer is too deep " );321 if ( ! checkInitDepth( objDecl ) ) SemanticError( objDecl, "Managed object's initializer is too deep " ); 322 322 323 323 objDecl->set_init( genCtorInit( objDecl ) ); -
src/InitTweak/InitTweak.cc
r6a8df56 ra16764a6 225 225 // xxx - this shouldn't be an error, but need a way to 226 226 // terminate without creating output, so should catch this error 227 throwSemanticError( init->location, "unbalanced list initializers" );227 SemanticError( init->location, "unbalanced list initializers" ); 228 228 } 229 229 -
src/Parser/DeclarationNode.cc
r6a8df56 ra16764a6 576 576 dst->basictype = src->basictype; 577 577 } else if ( src->basictype != DeclarationNode::NoBasicType ) 578 throwSemanticError( 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: " ); 579 579 580 580 if ( dst->complextype == DeclarationNode::NoComplexType ) { 581 581 dst->complextype = src->complextype; 582 582 } else if ( src->complextype != DeclarationNode::NoComplexType ) 583 throwSemanticError( 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: " ); 584 584 585 585 if ( dst->signedness == DeclarationNode::NoSignedness ) { 586 586 dst->signedness = src->signedness; 587 587 } else if ( src->signedness != DeclarationNode::NoSignedness ) 588 throwSemanticError( 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: " ); 589 589 590 590 if ( dst->length == DeclarationNode::NoLength ) { … … 593 593 dst->length = DeclarationNode::LongLong; 594 594 } else if ( src->length != DeclarationNode::NoLength ) 595 throwSemanticError( 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: " ); 596 596 } // if 597 597 break; … … 940 940 941 941 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ) { 942 SemanticError errors;942 SemanticErrorException errors; 943 943 std::back_insert_iterator< std::list< Declaration * > > out( outputList ); 944 944 … … 960 960 * out++ = decl; 961 961 } // if 962 } catch( SemanticError &e ) {962 } catch( SemanticErrorException &e ) { 963 963 errors.append( e ); 964 964 } // try … … 971 971 972 972 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) { 973 SemanticError errors;973 SemanticErrorException errors; 974 974 std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList ); 975 975 … … 994 994 } // if 995 995 } // if 996 } catch( SemanticError &e ) {996 } catch( SemanticErrorException &e ) { 997 997 errors.append( e ); 998 998 } // try … … 1005 1005 1006 1006 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) { 1007 SemanticError errors;1007 SemanticErrorException errors; 1008 1008 std::back_insert_iterator< std::list< Type * > > out( outputList ); 1009 1009 const DeclarationNode * cur = firstNode; … … 1012 1012 try { 1013 1013 * out++ = cur->buildType(); 1014 } catch( SemanticError &e ) {1014 } catch( SemanticErrorException &e ) { 1015 1015 errors.append( e ); 1016 1016 } // try … … 1024 1024 1025 1025 Declaration * DeclarationNode::build() const { 1026 if ( ! error.empty() ) throwSemanticError( this, error + " in declaration of " );1026 if ( ! error.empty() ) SemanticError( this, error + " in declaration of " ); 1027 1027 1028 1028 if ( asmStmt ) { … … 1047 1047 // inline _Noreturn int i; // disallowed 1048 1048 if ( type->kind != TypeData::Function && funcSpecs.any() ) { 1049 throwSemanticError( this, "invalid function specifier for " );1049 SemanticError( this, "invalid function specifier for " ); 1050 1050 } // if 1051 1051 return buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, maybeBuild< Initializer >(initializer), attributes )->set_extension( extension ); … … 1057 1057 // inlne _Noreturn enum E { ... }; // disallowed 1058 1058 if ( funcSpecs.any() ) { 1059 throwSemanticError( this, "invalid function specifier for " );1059 SemanticError( this, "invalid function specifier for " ); 1060 1060 } // if 1061 1061 assertf( name, "ObjectDecl must a have name\n" ); -
src/Parser/ExpressionNode.cc
r6a8df56 ra16764a6 356 356 357 357 Expression * build_field_name_FLOATING_FRACTIONconstant( const string & str ) { 358 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throwSemanticError( yylloc, "invalid tuple index " + str );358 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) SemanticError( yylloc, "invalid tuple index " + str ); 359 359 Expression * ret = build_constantInteger( *new string( str.substr(1) ) ); 360 360 delete &str; … … 363 363 364 364 Expression * build_field_name_FLOATING_DECIMALconstant( const string & str ) { 365 if ( str[str.size()-1] != '.' ) throwSemanticError( yylloc, "invalid tuple index " + str );365 if ( str[str.size()-1] != '.' ) SemanticError( yylloc, "invalid tuple index " + str ); 366 366 Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) ); 367 367 delete &str; -
src/Parser/LinkageSpec.cc
r6a8df56 ra16764a6 34 34 return BuiltinC; 35 35 } else { 36 throwSemanticError( location, "Invalid linkage specifier " + *spec );36 SemanticError( location, "Invalid linkage specifier " + *spec ); 37 37 } // if 38 38 } … … 48 48 return old_spec; 49 49 } else { 50 throwSemanticError( location, "Invalid linkage specifier " + *cmd );50 SemanticError( location, "Invalid linkage specifier " + *cmd ); 51 51 } // if 52 52 } -
src/Parser/ParseNode.h
r6a8df56 ra16764a6 419 419 template< typename SynTreeType, typename NodeType, template< typename, typename...> class Container, typename... Args > 420 420 void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > &outputList ) { 421 SemanticError errors;421 SemanticErrorException errors; 422 422 std::back_insert_iterator< Container< SynTreeType *, Args... > > out( outputList ); 423 423 const NodeType * cur = firstNode; … … 432 432 assertf(false, "buildList unknown type"); 433 433 } // if 434 } catch( SemanticError &e ) {434 } catch( SemanticErrorException &e ) { 435 435 errors.append( e ); 436 436 } // try -
src/Parser/TypeData.cc
r6a8df56 ra16764a6 519 519 520 520 static string genTSError( string msg, DeclarationNode::BasicType basictype ) { 521 throwSemanticError( yylloc, string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." );521 SemanticError( yylloc, string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." ); 522 522 } // genTSError 523 523 … … 919 919 // type set => parameter name already transformed by a declaration names so there is a duplicate 920 920 // declaration name attempting a second transformation 921 if ( param->type ) throwSemanticError( param->location, string( "duplicate declaration name " ) + *param->name );921 if ( param->type ) SemanticError( param->location, string( "duplicate declaration name " ) + *param->name ); 922 922 // declaration type reset => declaration already transformed by a parameter name so there is a duplicate 923 923 // parameter name attempting a second transformation 924 if ( ! decl->type ) throwSemanticError( param->location, string( "duplicate parameter name " ) + *param->name );924 if ( ! decl->type ) SemanticError( param->location, string( "duplicate parameter name " ) + *param->name ); 925 925 param->type = decl->type; // set copy declaration type to parameter type 926 926 decl->type = nullptr; // reset declaration type … … 929 929 } // for 930 930 // declaration type still set => type not moved to a matching parameter so there is a missing parameter name 931 if ( decl->type ) throwSemanticError( 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 ); 932 932 } // for 933 933 -
src/Parser/lex.ll
r6a8df56 ra16764a6 453 453 void yyerror( const char * errmsg ) { 454 454 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; 456 456 } 457 457 -
src/Parser/parser.yy
r6a8df56 ra16764a6 482 482 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); } 483 483 | type_name '.' no_attr_identifier // CFA, nested type 484 { throwSemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; } // FIX ME484 { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; } // FIX ME 485 485 | type_name '.' '[' push field_list pop ']' // CFA, nested type / tuple field selector 486 { throwSemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; } // FIX ME486 { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; } // FIX ME 487 487 | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11 488 { throwSemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; } // FIX ME488 { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; } // FIX ME 489 489 ; 490 490 … … 780 780 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); } 781 781 | unary_expression '=' '{' initializer_list comma_opt '}' 782 { throwSemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } // FIX ME782 { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } // FIX ME 783 783 ; 784 784 … … 850 850 | exception_statement 851 851 | enable_disable_statement 852 { throwSemanticError( yylloc, "enable/disable statement is currently unimplemented." ); $$ = nullptr; } // FIX ME852 { SemanticError( yylloc, "enable/disable statement is currently unimplemented." ); $$ = nullptr; } // FIX ME 853 853 | asm_statement 854 854 ; … … 1067 1067 { $$ = new StatementNode( build_return( $2 ) ); } 1068 1068 | RETURN '{' initializer_list comma_opt '}' 1069 { throwSemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } // FIX ME1069 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } // FIX ME 1070 1070 | THROW assignment_expression_opt ';' // handles rethrow 1071 1071 { $$ = new StatementNode( build_throw( $2 ) ); } … … 1086 1086 mutex_statement: 1087 1087 MUTEX '(' argument_expression_list ')' statement 1088 { throwSemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; } // FIX ME1088 { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; } // FIX ME 1089 1089 ; 1090 1090 … … 1316 1316 static_assert: 1317 1317 STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11 1318 { throwSemanticError( yylloc, "Static assert is currently unimplemented." ); $$ = nullptr; } // FIX ME1318 { SemanticError( yylloc, "Static assert is currently unimplemented." ); $$ = nullptr; } // FIX ME 1319 1319 1320 1320 // C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function -
src/ResolvExpr/AlternativeFinder.cc
r6a8df56 ra16764a6 240 240 std::cerr << "No reasonable alternatives for expression " << expr << std::endl; 241 241 ) 242 throwSemanticError( expr, "No reasonable alternatives for expression " );242 SemanticError( expr, "No reasonable alternatives for expression " ); 243 243 } 244 244 if ( prune ) { … … 258 258 stream << " Alternatives are:\n"; 259 259 printAlts( winners, stream, 1 ); 260 throwSemanticError( expr->location, stream.str() );260 SemanticError( expr->location, stream.str() ); 261 261 } 262 262 alternatives = move(pruned); … … 495 495 return; 496 496 } else if ( level >= recursionLimit ) { 497 throwSemanticError( newAlt.expr->location, "Too many recursive assertions" );497 SemanticError( newAlt.expr->location, "Too many recursive assertions" ); 498 498 } else { 499 499 AssertionSet newerNeed; … … 1112 1112 1113 1113 AltList candidates; 1114 SemanticError errors;1114 SemanticErrorException errors; 1115 1115 for ( AltList::iterator func = funcFinder.alternatives.begin(); func != funcFinder.alternatives.end(); ++func ) { 1116 1116 try { … … 1138 1138 } // if 1139 1139 } 1140 } catch ( SemanticError &e ) {1140 } catch ( SemanticErrorException &e ) { 1141 1141 errors.append( e ); 1142 1142 } … … 1167 1167 } 1168 1168 } 1169 } catch ( SemanticError &e ) {1169 } catch ( SemanticErrorException &e ) { 1170 1170 errors.append( e ); 1171 1171 } … … 1409 1409 findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) ); 1410 1410 if ( winners.size() != 1 ) { 1411 throwSemanticError( sizeofExpr->get_expr(), "Ambiguous expression in sizeof operand: " );1411 SemanticError( sizeofExpr->get_expr(), "Ambiguous expression in sizeof operand: " ); 1412 1412 } // if 1413 1413 // return the lowest cost alternative for the argument … … 1430 1430 findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) ); 1431 1431 if ( winners.size() != 1 ) { 1432 throwSemanticError( alignofExpr->get_expr(), "Ambiguous expression in alignof operand: " );1432 SemanticError( alignofExpr->get_expr(), "Ambiguous expression in alignof operand: " ); 1433 1433 } // if 1434 1434 // return the lowest cost alternative for the argument -
src/ResolvExpr/CurrentObject.cc
r6a8df56 ra16764a6 141 141 base = at->get_base(); 142 142 memberIter = createMemberIterator( base ); 143 if ( at->isVarLen ) throwSemanticError( at, "VLA initialization does not support @=" );143 if ( at->isVarLen ) SemanticError( at, "VLA initialization does not support @=" ); 144 144 setSize( at->get_dimension() ); 145 145 } … … 155 155 size = constExpr->intValue(); 156 156 PRINT( std::cerr << "array type with size: " << size << std::endl; ) 157 } catch ( SemanticError & ) {158 throwSemanticError( 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: " ); 159 159 } 160 160 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { … … 178 178 try { 179 179 index = constExpr->intValue(); 180 } catch( SemanticError & ) {181 throwSemanticError( 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: " ); 182 182 } 183 183 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { … … 532 532 } // for 533 533 if ( desigAlts.size() > 1 ) { 534 throwSemanticError( designation, toString("Too many alternatives (", desigAlts.size(), ") for designation: ") );534 SemanticError( designation, toString("Too many alternatives (", desigAlts.size(), ") for designation: ") ); 535 535 } else if ( desigAlts.size() == 0 ) { 536 throwSemanticError( designation, "No reasonable alternatives for designation: " );536 SemanticError( designation, "No reasonable alternatives for designation: " ); 537 537 } 538 538 DesignatorChain & d = desigAlts.back(); -
src/ResolvExpr/Resolver.cc
r6a8df56 ra16764a6 174 174 findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) ); 175 175 if ( winners.size() == 0 ) { 176 throwSemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") );176 SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") ); 177 177 } else if ( winners.size() != 1 ) { 178 178 std::ostringstream stream; … … 181 181 stream << " Alternatives are:\n"; 182 182 printAlts( winners, stream, 1 ); 183 throwSemanticError( untyped->location, stream.str() );183 SemanticError( untyped->location, stream.str() ); 184 184 } 185 185 … … 187 187 Alternative & choice = winners.front(); 188 188 if ( findDeletedExpr( choice.expr ) ) { 189 throwSemanticError( choice.expr, "Unique best alternative includes deleted identifier in " );189 SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " ); 190 190 } 191 191 alt = std::move( choice ); … … 484 484 ss << strict_dynamic_cast<NameExpr*>( clause.target.function )->name; 485 485 ss << "' in call to waitfor"; 486 throwSemanticError( stmt->location, ss.str() );486 SemanticError( stmt->location, ss.str() ); 487 487 } 488 488 … … 501 501 // try matching the arguments to the parameters 502 502 // not the other way around because we have more arguments than parameters 503 SemanticError errors;503 SemanticErrorException errors; 504 504 for ( Alternative & func : funcFinder.get_alternatives() ) { 505 505 try { 506 506 PointerType * pointer = dynamic_cast< PointerType* >( func.expr->get_result()->stripReferences() ); 507 507 if( !pointer ) { 508 throwSemanticError( 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" ); 509 509 } 510 510 511 511 FunctionType * function = dynamic_cast< FunctionType* >( pointer->get_base() ); 512 512 if( !function ) { 513 throwSemanticError( pointer->get_base(), "candidate not viable: not a function type\n" );513 SemanticError( pointer->get_base(), "candidate not viable: not a function type\n" ); 514 514 } 515 515 … … 520 520 521 521 if( !advance_to_mutex( param, param_end ) ) { 522 throwSemanticError(function, "candidate function not viable: no mutex parameters\n");522 SemanticError(function, "candidate function not viable: no mutex parameters\n"); 523 523 } 524 524 } … … 559 559 // We ran out of parameters but still have arguments 560 560 // this function doesn't match 561 throwSemanticError( function, "candidate function not viable: too many mutex arguments\n" );561 SemanticError( function, "candidate function not viable: too many mutex arguments\n" ); 562 562 } 563 563 … … 571 571 (*param)->get_type()->print( ss ); 572 572 ss << "'\n"; 573 throwSemanticError( function, ss.str() );573 SemanticError( function, ss.str() ); 574 574 } 575 575 … … 583 583 // We ran out of arguments but still have parameters left 584 584 // this function doesn't match 585 throwSemanticError( function, "candidate function not viable: too few mutex arguments\n" );585 SemanticError( function, "candidate function not viable: too few mutex arguments\n" ); 586 586 } 587 587 … … 599 599 600 600 } 601 catch( SemanticError &e ) {601 catch( SemanticErrorException &e ) { 602 602 errors.append( e ); 603 603 } 604 604 } 605 605 } 606 catch( SemanticError &e ) {606 catch( SemanticErrorException &e ) { 607 607 errors.append( e ); 608 608 } … … 610 610 611 611 // 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; } 616 616 // TODO: need to use findDeletedExpr to ensure no deleted identifiers are used. 617 617 -
src/SymTab/Autogen.cc
r6a8df56 ra16764a6 331 331 definitions.push_back( dcl ); 332 332 indexer.addId( dcl ); 333 } catch ( SemanticError err ) {333 } catch ( SemanticErrorException err ) { 334 334 // okay if decl does not resolve - that means the function should not be generated 335 335 delete dcl; -
src/SymTab/Indexer.cc
r6a8df56 ra16764a6 443 443 // isomorphic to C type-compatibility, which it may not be. 444 444 if ( hasIncompatibleCDecl( name, mangleName, scope ) ) { 445 throwSemanticError( decl, "conflicting overload of C function " );445 SemanticError( decl, "conflicting overload of C function " ); 446 446 } 447 447 } else { 448 448 // Check that a Cforall declaration doesn't override any C declaration 449 449 if ( hasCompatibleCDecl( name, mangleName, scope ) ) { 450 throwSemanticError( decl, "Cforall declaration hides C function " );450 SemanticError( decl, "Cforall declaration hides C function " ); 451 451 } 452 452 } … … 463 463 void Indexer::addId( DeclarationWithType * decl, Expression * baseExpr ) { 464 464 // default handling of conflicts is to raise an error 465 addId( decl, [decl](IdData &, const std::string & msg) { throwSemanticError( decl, msg ); return true; }, baseExpr );465 addId( decl, [decl](IdData &, const std::string & msg) { SemanticError( decl, msg ); return true; }, baseExpr ); 466 466 } 467 467 468 468 void Indexer::addDeletedId( DeclarationWithType * decl, BaseSyntaxNode * deleteStmt ) { 469 469 // default handling of conflicts is to raise an error 470 addId( decl, [decl](IdData &, const std::string & msg) { throwSemanticError( decl, msg ); return true; }, nullptr, deleteStmt );470 addId( decl, [decl](IdData &, const std::string & msg) { SemanticError( decl, msg ); return true; }, nullptr, deleteStmt ); 471 471 } 472 472 … … 477 477 return true; 478 478 } else { 479 throwSemanticError( added, "redeclaration of " );479 SemanticError( added, "redeclaration of " ); 480 480 } 481 481 } … … 504 504 return false; 505 505 } else if ( ! added->get_members().empty() ) { 506 throwSemanticError( added, "redeclaration of " );506 SemanticError( added, "redeclaration of " ); 507 507 } // if 508 508 return true; -
src/SymTab/Validate.cc
r6a8df56 ra16764a6 360 360 // the only case in which "void" is valid is where it is the only one in the list 361 361 if ( containsVoid && ( nvals > 1 || isVarArgs ) ) { 362 throwSemanticError( func, "invalid type void in function type " );362 SemanticError( func, "invalid type void in function type " ); 363 363 } 364 364 … … 401 401 for ( Expression * param : inst->parameters ) { 402 402 if ( ! dynamic_cast< TypeExpr * >( param ) ) { 403 throwSemanticError( inst, "Expression parameters for generic types are currently unsupported: " );403 SemanticError( inst, "Expression parameters for generic types are currently unsupported: " ); 404 404 } 405 405 } … … 501 501 TraitDecl *traitDecl = local_indexer->lookupTrait( traitInst->name ); 502 502 if ( ! traitDecl ) { 503 throwSemanticError( traitInst->location, "use of undeclared trait " + traitInst->name );503 SemanticError( traitInst->location, "use of undeclared trait " + traitInst->name ); 504 504 } // if 505 505 if ( traitDecl->get_parameters().size() != traitInst->get_parameters().size() ) { 506 throwSemanticError( traitInst, "incorrect number of trait parameters: " );506 SemanticError( traitInst, "incorrect number of trait parameters: " ); 507 507 } // if 508 508 traitInst->baseTrait = traitDecl; … … 512 512 TypeExpr * expr = dynamic_cast< TypeExpr * >( std::get<1>(p) ); 513 513 if ( ! expr ) { 514 throwSemanticError( 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: " ); 515 515 } 516 516 if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) { … … 618 618 bool isVoid = fixFunction( assertion ); 619 619 if ( isVoid ) { 620 throwSemanticError( node, "invalid type void in assertion of function " );620 SemanticError( node, "invalid type void in assertion of function " ); 621 621 } // if 622 622 } // for … … 662 662 // were cast to void. 663 663 if ( ! returnStmt->get_expr() && returnVals.size() != 0 ) { 664 throwSemanticError( returnStmt, "Non-void function returns no values: " );664 SemanticError( returnStmt, "Non-void function returns no values: " ); 665 665 } 666 666 } … … 703 703 ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret); 704 704 if ( ! rtt ) { 705 throwSemanticError( 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 ); 706 706 } 707 707 rtt->get_parameters().clear(); … … 741 741 Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base(); 742 742 if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) { 743 throwSemanticError( tyDecl->location, "Cannot redefine typedef: " + tyDecl->name );743 SemanticError( tyDecl->location, "Cannot redefine typedef: " + tyDecl->name ); 744 744 } 745 745 // Cannot redefine VLA typedefs. Note: this is slightly incorrect, because our notion of VLAs … … 748 748 // to fix this corner case likely outweighs the utility of allowing it. 749 749 if ( isVariableLength( t1 ) || isVariableLength( t2 ) ) { 750 throwSemanticError( tyDecl->location, "Cannot redefine typedef: " + tyDecl->name );750 SemanticError( tyDecl->location, "Cannot redefine typedef: " + tyDecl->name ); 751 751 } 752 752 } else { … … 897 897 if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc. 898 898 if ( params.size() == 0 ) { 899 throwSemanticError( funcDecl, "Constructors, destructors, and assignment functions require at least one parameter " );899 SemanticError( funcDecl, "Constructors, destructors, and assignment functions require at least one parameter " ); 900 900 } 901 901 ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() ); 902 902 if ( ! refType ) { 903 throwSemanticError( 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 " ); 904 904 } 905 905 if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) { 906 throwSemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " );906 SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " ); 907 907 } 908 908 } … … 939 939 940 940 sub.apply( inst ); 941 if ( args.size() < params->size() ) throwSemanticError( inst, "Too few type arguments in generic type " );942 if ( args.size() > params->size() ) throwSemanticError( 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 " ); 943 943 } 944 944 } -
src/SynTree/Expression.cc
r6a8df56 ra16764a6 93 93 return 0; 94 94 } 95 throwSemanticError( this, "Constant expression of non-integral type " );95 SemanticError( this, "Constant expression of non-integral type " ); 96 96 } 97 97 -
src/SynTree/Mutator.h
r6a8df56 ra16764a6 136 136 template< typename Container, typename MutatorType > 137 137 inline void mutateAll( Container &container, MutatorType &mutator ) { 138 SemanticError errors;138 SemanticErrorException errors; 139 139 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 140 140 try { … … 144 144 assert( *i ); 145 145 } // if 146 } catch( SemanticError &e ) {146 } catch( SemanticErrorException &e ) { 147 147 errors.append( e ); 148 148 } // try -
src/SynTree/Statement.cc
r6a8df56 ra16764a6 96 96 const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" }; 97 97 98 BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticError ) :98 BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) : 99 99 Statement(), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) { 100 100 //actually this is a syntactic error signaled by the parser 101 101 if ( type == BranchStmt::Goto && target.empty() ) { 102 throwSemanticError( 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 106 BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticErrorException ) : 107 107 Statement(), computedTarget( computedTarget ), type( type ) { 108 108 if ( type != BranchStmt::Goto || computedTarget == nullptr ) { 109 throwSemanticError( computedTarget->location, "Computed target not valid in branch statement");109 SemanticError( computedTarget->location, "Computed target not valid in branch statement"); 110 110 } 111 111 } … … 201 201 } 202 202 203 CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :203 CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticErrorException ) : 204 204 Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) { 205 if ( isDefault() && condition != 0 ) throwSemanticError( condition, "default case with condition: " );205 if ( isDefault() && condition != 0 ) SemanticError( condition, "default case with condition: " ); 206 206 } 207 207 -
src/SynTree/Statement.h
r6a8df56 ra16764a6 179 179 std::list<Statement *> stmts; 180 180 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); 182 182 CaseStmt( const CaseStmt &other ); 183 183 virtual ~CaseStmt(); … … 263 263 Type type; 264 264 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); 267 267 268 268 Label get_originalTarget() { return originalTarget; } -
src/SynTree/TypeSubstitution.h
r6a8df56 ra16764a6 98 98 } // if 99 99 } else { 100 throwSemanticError( 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 " ) ); 101 101 } // if 102 102 } else { -
src/SynTree/Visitor.h
r6a8df56 ra16764a6 132 132 template< typename Container, typename VisitorType > 133 133 inline void acceptAll( Container &container, VisitorType &visitor ) { 134 SemanticError errors;134 SemanticErrorException errors; 135 135 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 136 136 try { … … 138 138 (*i)->accept( visitor ); 139 139 } 140 } catch( SemanticError &e ) {140 } catch( SemanticErrorException &e ) { 141 141 errors.append( e ); 142 142 } -
src/main.cc
r6a8df56 ra16764a6 357 357 delete output; 358 358 } // if 359 } catch ( SemanticError &e ) {359 } catch ( SemanticErrorException &e ) { 360 360 if ( errorp ) { 361 361 cerr << "---AST at error:---" << endl;
Note: See TracChangeset
for help on using the changeset viewer.