New exceptions for static errors detected during analysis of free states.
[shapes.git] / source / shapesexceptions.cc
blob50f88c64f009fa11c045cf220df487f43fbb8ed3
1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * any later version.
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008 Henrik Tidefelt
19 #include "shapesexceptions.h"
20 #include "ast.h"
21 #include "astclass.h"
22 #include "globals.h"
23 #include "functiontypes.h"
25 using namespace Shapes;
26 using namespace std;
29 const std::string Exceptions::additionalLinesPrefix = "| ";
31 namespace Shapes
33 namespace Exceptions
35 void prefixEachLine( const std::string & prefix, std::istream & src, std::ostream & dst );
36 void prefixEachLine( const std::string & prefix, const RefCountPtr< const char > & src, std::ostream & dst );
40 Exceptions::NotImplemented::NotImplemented( const char * _functionality )
41 : functionality( _functionality )
42 { }
44 Exceptions::NotImplemented::~NotImplemented( )
45 { }
47 void
48 Exceptions::NotImplemented::display( std::ostream & os ) const
50 os << "Under construction: " << functionality << " is not implemented." << std::endl ;
53 const char * Exceptions::Exception::locsep = ": ";
55 Exceptions::Exception::Exception( )
56 { }
58 Exceptions::Exception::~Exception( )
59 { }
61 Exceptions::MiscellaneousRequirement::MiscellaneousRequirement( RefCountPtr< const char > msg )
62 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg )
63 { }
65 Exceptions::MiscellaneousRequirement::MiscellaneousRequirement( const char * msg )
66 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
67 { }
69 Exceptions::MiscellaneousRequirement::~MiscellaneousRequirement( )
70 { }
72 void
73 Exceptions::MiscellaneousRequirement::display( ostream & os ) const
75 os << "Failed to meet requirement: " << msg_ << std::endl ;
79 Exceptions::HandlerError::HandlerError( RefCountPtr< const char > _msg )
80 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg( _msg )
81 { }
83 Exceptions::HandlerError::HandlerError( const char * _msg )
84 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg( strrefdup( _msg ) )
85 { }
87 Exceptions::HandlerError::~HandlerError( )
88 { }
90 void
91 Exceptions::HandlerError::display( ostream & os ) const
93 os << "Error handler message: " << msg << std::endl ;
97 Exceptions::ScannerError::ScannerError( const Ast::SourceLocation & loc, RefCountPtr< const char > _msg )
98 : Exceptions::StaticInconsistency( loc ), msg( _msg )
99 { }
101 Exceptions::ScannerError::~ScannerError( )
104 void
105 Exceptions::ScannerError::display( ostream & os ) const
107 os << "Scanner error: " << msg << std::endl ;
111 Exceptions::ParserError::ParserError( const Ast::SourceLocation & loc, RefCountPtr< const char > _msg )
112 : Exceptions::StaticInconsistency( loc ), msg( _msg )
115 Exceptions::ParserError::~ParserError( )
118 void
119 Exceptions::ParserError::display( ostream & os ) const
121 os << "Parser error: " << msg << std::endl ;
125 Exceptions::MemberAlsoAbstract::MemberAlsoAbstract( const Ast::SourceLocation & _memberLoc, const char * _id, const Ast::SourceLocation & _abstractLoc )
126 : Exceptions::StaticInconsistency( _memberLoc ), memberLoc( _memberLoc ), id( _id ), abstractLoc( _abstractLoc )
129 Exceptions::MemberAlsoAbstract::~MemberAlsoAbstract( )
132 void
133 Exceptions::MemberAlsoAbstract::display( ostream & os ) const
135 os << "The member " << id << " is also declared abstract, at " << abstractLoc << "." << std::endl ;
139 Exceptions::MemberAlreadyDeclared::MemberAlreadyDeclared( const Ast::SourceLocation & _memberLoc, const char * _id, const Ast::SourceLocation & _oldLoc )
140 : Exceptions::StaticInconsistency( _memberLoc ), memberLoc( _memberLoc ), id( _id ), oldLoc( _oldLoc )
143 Exceptions::MemberAlreadyDeclared::~MemberAlreadyDeclared( )
146 void
147 Exceptions::MemberAlreadyDeclared::display( ostream & os ) const
149 os << "The member " << id << " has already been declared, at " << oldLoc << "." << std::endl ;
153 Exceptions::PublicGetSetInNonfinalClass::PublicGetSetInNonfinalClass( const Ast::SourceLocation & _memberLoc, const char * _id )
154 : Exceptions::StaticInconsistency( _memberLoc ), memberLoc( _memberLoc ), id( _id )
157 Exceptions::PublicGetSetInNonfinalClass::~PublicGetSetInNonfinalClass( )
160 void
161 Exceptions::PublicGetSetInNonfinalClass::display( ostream & os ) const
163 os << "Only members of final classes may have the public get or set specifier. Member in question: " << id << "." << std::endl ;
167 Exceptions::TransformingMemberInNonfinalClass::TransformingMemberInNonfinalClass( const Ast::SourceLocation & _memberLoc, const char * _id )
168 : Exceptions::StaticInconsistency( _memberLoc ), memberLoc( _memberLoc ), id( _id )
171 Exceptions::TransformingMemberInNonfinalClass::~TransformingMemberInNonfinalClass( )
174 void
175 Exceptions::TransformingMemberInNonfinalClass::display( ostream & os ) const
177 os << "Only members of final classes may have the <transforming> specifier. Member in question: " << id << "." << std::endl ;
181 Exceptions::RepeatedFormal::RepeatedFormal( const Ast::SourceLocation & loc, const char * _id )
182 : Exceptions::StaticInconsistency( loc ), id( _id )
185 Exceptions::RepeatedFormal::~RepeatedFormal( )
188 void
189 Exceptions::RepeatedFormal::display( ostream & os ) const
191 os << "Repeated formal: " << id << std::endl ;
195 Exceptions::IllegalFreeStates::IllegalFreeStates( const Ast::SourceLocation & loc, Ast::StateIDSet * freeStates, const char * reason )
196 : Exceptions::StaticInconsistency( loc ), freeStates_( freeStates ), reason_( reason )
199 Exceptions::IllegalFreeStates::~IllegalFreeStates( )
202 void
203 Exceptions::IllegalFreeStates::display( ostream & os ) const
205 os << "Free states are illegal here (" << reason_ << "):" ;
206 typedef typeof *freeStates_ SetType;
207 for( SetType::const_iterator i = freeStates_->begin( ); i != freeStates_->end( ); ++i )
209 os << " " << *i ;
211 os << std::endl ;
215 Exceptions::FreeStateIsAlsoPassed::FreeStateIsAlsoPassed( const Ast::SourceLocation & loc, Ast::StateID stateID )
216 : Exceptions::StaticInconsistency( loc ), stateID_( stateID )
219 Exceptions::FreeStateIsAlsoPassed::~FreeStateIsAlsoPassed( )
222 void
223 Exceptions::FreeStateIsAlsoPassed::display( ostream & os ) const
225 os << "Non-pure, delayed, expressions may not have free states which are also passed as state arguments in the same non-pure function application. Please consider forcing immediate evaluation." << std::endl ;
229 Exceptions::RepeatedStateArgument::RepeatedStateArgument( const Ast::SourceLocation & loc, const RefCountPtr< Ast::StateIDSet > & passedStates )
230 : Exceptions::StaticInconsistency( loc ), passedStates_( passedStates )
233 Exceptions::RepeatedStateArgument::~RepeatedStateArgument( )
236 void
237 Exceptions::RepeatedStateArgument::display( ostream & os ) const
239 os << "Some of these states are being passed in more than one state argument position:" ;
240 typedef typeof *passedStates_ SetType;
241 for( SetType::const_iterator i = passedStates_->begin( ); i != passedStates_->end( ); ++i )
243 os << " " << *i ;
245 os << std::endl ;
249 Exceptions::PassingStateOut::PassingStateOut( const Ast::SourceLocation & loc, const char * id )
250 : Exceptions::StaticInconsistency( loc ), id_( id )
253 Exceptions::PassingStateOut::~PassingStateOut( )
256 void
257 Exceptions::PassingStateOut::display( std::ostream & os ) const
259 os << "States may not be returned." << std::endl ;
263 Exceptions::IntroducingExisting::IntroducingExisting( const Ast::SourceLocation & _loc, const char * _id )
264 : Exceptions::StaticInconsistency( _loc ), loc( _loc ), id( _id )
267 Exceptions::IntroducingExisting::~IntroducingExisting( )
270 void
271 Exceptions::IntroducingExisting::display( std::ostream & os ) const
273 os << "The variable " << id << " is already introduced in this scope." << std::endl ;
277 Exceptions::ExpectedImperative::ExpectedImperative( const Ast::SourceLocation & _loc )
278 : Exceptions::StaticInconsistency( _loc ), loc( _loc )
281 Exceptions::ExpectedImperative::~ExpectedImperative( )
284 void
285 Exceptions::ExpectedImperative::display( std::ostream & os ) const
287 os << "It makes no sense to put a pure expression before the end of a code bracket." << std::endl ;
291 Exceptions::IllegalImperative::IllegalImperative( const Ast::SourceLocation & _loc )
292 : Exceptions::StaticInconsistency( _loc ), loc( _loc )
295 Exceptions::IllegalImperative::~IllegalImperative( )
298 void
299 Exceptions::IllegalImperative::display( std::ostream & os ) const
301 os << "Imperative expressions are not allowed here." << std::endl ;
305 Exceptions::FreezingUndefined::FreezingUndefined( const Ast::SourceLocation & _loc, const char * _id )
306 : Exceptions::StaticInconsistency( _loc ), loc( _loc ), id( _id )
309 Exceptions::FreezingUndefined::~FreezingUndefined( )
312 void
313 Exceptions::FreezingUndefined::display( std::ostream & os ) const
315 os << "Internal error: The variable " << id << " is freezed before it was defined. Either this should be caught by during the parse, or it is due to an error in the setup of the initial environment." << std::endl ;
319 Exceptions::FileReadOpenError::FileReadOpenError( const Ast::SourceLocation & _loc, RefCountPtr< const char > _filename, const std::string * sourceDir, const std::list< std::string > * searchPath, Type _type )
320 : loc( _loc ), filename( _filename ), type( _type ), sourceDir_( sourceDir ), searchPath_( searchPath )
323 Exceptions::FileReadOpenError::~FileReadOpenError( )
326 void
327 Exceptions::FileReadOpenError::display( std::ostream & os ) const
329 switch( type )
331 case OPEN:
332 os << loc << locsep << "Could not open file: " << filename ;
333 break;
334 case STAT:
335 os << loc << locsep << "Could not stat() file: " << filename ;
336 break;
337 default:
338 os << loc << locsep << "Internal error when displaying FileReadOpenError on file: " << filename ;
340 if( searchPath_ != 0 )
342 os << " searching \"" ;
343 typedef typeof *searchPath_ ListType;
344 for( ListType::const_iterator i = searchPath_->begin( ); i != searchPath_->end( ); ++i )
346 if( i != searchPath_->begin( ) )
348 os << ":" ;
350 if( sourceDir_ != 0 && (*i)[0] != '/' )
352 os << *sourceDir_ ;
354 os << *i ;
356 os << "\"" ;
358 os << std::endl ;
362 Exceptions::FileWriteOpenError::FileWriteOpenError( const Ast::SourceLocation & _loc, RefCountPtr< const char > _filename, const char * purpose )
363 : loc( _loc ), filename( _filename ), purpose_( purpose )
366 Exceptions::FileWriteOpenError::~FileWriteOpenError( )
369 void
370 Exceptions::FileWriteOpenError::display( std::ostream & os ) const
372 os << loc << locsep << "Could not open " ;
373 if( purpose_ != 0 )
375 os << purpose_ ;
377 os << " file for write: " << filename ;
378 os << std::endl ;
382 Exceptions::TeXSetupTooLate::TeXSetupTooLate( const Ast::SourceLocation & _loc )
383 : loc( _loc )
386 Exceptions::TeXSetupTooLate::~TeXSetupTooLate( )
389 void
390 Exceptions::TeXSetupTooLate::display( std::ostream & os ) const
392 os << loc << locsep << "It is too late to make modifications to the TeX context." << std::endl ;
396 Exceptions::EmptyFinalPicture::EmptyFinalPicture( )
399 Exceptions::EmptyFinalPicture::~EmptyFinalPicture( )
402 void
403 Exceptions::EmptyFinalPicture::display( std::ostream & os ) const
405 os << "Nothing was ever put in the global #" << Lang::CATALOG_ID << " or drawn to the global #" << Lang::CANVAS_ID << "." << std::endl ;
409 Exceptions::TeXSetupHasChanged::TeXSetupHasChanged( )
410 : Shapes::Exceptions::InternalError( "The TeX context check failed while loading fresh labels." )
413 Exceptions::TeXSetupHasChanged::~TeXSetupHasChanged( )
417 Exceptions::TypeMismatch::TypeMismatch( const Ast::SourceLocation & loc, RefCountPtr< const char > _valueType, RefCountPtr< const char > _expectedType )
418 : Exceptions::RuntimeError( loc ), hint_( 0 ), valueType( _valueType ), expectedType( _expectedType )
421 Exceptions::TypeMismatch::TypeMismatch( const Ast::SourceLocation & loc, const char * hint, RefCountPtr< const char > _valueType, RefCountPtr< const char > _expectedType )
422 : Exceptions::RuntimeError( loc ), hint_( hint ), valueType( _valueType ), expectedType( _expectedType )
425 Exceptions::TypeMismatch::~TypeMismatch( )
428 void
429 Exceptions::TypeMismatch::display( std::ostream & os ) const
431 if( hint_ != 0 )
433 os << hint_ << ": " ;
435 os << "Expected a " << expectedType << ", got a " << valueType << "." << std::endl ;
438 Exceptions::PDFVersionError::PDFVersionError( SimplePDF::PDF_Version::Version version, SimplePDF::PDF_Version::Version required, const RefCountPtr< const char > & msg )
439 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), version_( version ), required_( required ), msgMem_( msg ), msg_( msgMem_.getPtr( ) )
442 Exceptions::PDFVersionError::PDFVersionError( SimplePDF::PDF_Version::Version version, SimplePDF::PDF_Version::Version required, const char * msg )
443 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), version_( version ), required_( required ), msgMem_( NullPtr< const char >( ) ), msg_( msg )
446 Exceptions::PDFVersionError::~PDFVersionError( )
449 void
450 Exceptions::PDFVersionError::display( std::ostream & os ) const
452 os << SimplePDF::PDF_Version::toString( required_ ) << " error: " << msg_ << std::endl ;
456 Exceptions::RedefiningLexical::RedefiningLexical( const char * _id )
457 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), id( _id )
460 Exceptions::RedefiningLexical::~RedefiningLexical( )
463 void
464 Exceptions::RedefiningLexical::display( std::ostream & os ) const
466 os << "Redefining " << id << std::endl ;
470 Exceptions::RedefiningDynamic::RedefiningDynamic( const char * _id )
471 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), id( _id )
474 Exceptions::RedefiningDynamic::~RedefiningDynamic( )
477 void
478 Exceptions::RedefiningDynamic::display( std::ostream & os ) const
480 os << "Redefining " << "@" << id << std::endl ;
484 Exceptions::ConditionTypeMismatch::ConditionTypeMismatch( RefCountPtr< const char > _valueType )
485 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), valueType( _valueType )
488 Exceptions::ConditionTypeMismatch::~ConditionTypeMismatch( )
491 void
492 Exceptions::ConditionTypeMismatch::display( std::ostream & os ) const
494 os << "A variable condition check must result in a " << Lang::Boolean::staticTypeName( ) << ", got a " << valueType << std::endl ;
498 Exceptions::VariableTypeMismatch::VariableTypeMismatch( const Ast::SourceLocation & _loc, RefCountPtr< const char > _id, RefCountPtr< const char > _valueType, RefCountPtr< const char > _expectedType )
499 : Exceptions::RuntimeError( _loc ), id( _id ), valueType( _valueType ), expectedType( _expectedType )
502 Exceptions::VariableTypeMismatch::~VariableTypeMismatch( )
505 void
506 Exceptions::VariableTypeMismatch::display( std::ostream & os ) const
508 os << "The variable " << id << " was expected to refer to a " << expectedType << ", found a " << valueType << std::endl ;
512 Exceptions::NonObjectMemberAssignment::NonObjectMemberAssignment( const Ast::SourceLocation & _loc, RefCountPtr< const char > _valueType )
513 : Exceptions::RuntimeError( _loc ), valueType( _valueType )
516 Exceptions::NonObjectMemberAssignment::~NonObjectMemberAssignment( )
519 void
520 Exceptions::NonObjectMemberAssignment::display( std::ostream & os ) const
522 os << "Only object oriented values have fields that can be assigned. This value is of type " << valueType << "." << std::endl ;
526 Exceptions::ElementaryWithout::ElementaryWithout( Kind kind, Ref ref, RefCountPtr< const char > _valueType )
527 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), ref_( ref ), valueType( _valueType )
530 Exceptions::ElementaryWithout::~ElementaryWithout( )
533 void
534 Exceptions::ElementaryWithout::display( std::ostream & os ) const
536 os << "This " ;
537 switch( kind_ )
539 case VALUE:
540 os << "value" ;
541 break;
542 case STATE:
543 os << "state" ;
544 break;
546 os << " is of the elementary type " << valueType << ", which has no " ;
547 switch( ref_ )
549 case FIELD:
550 os << "fields" ;
551 break;
552 case MUTATOR:
553 os << "mutators" ;
554 break;
556 os << "." << std::endl ;
560 Exceptions::IllegalFinalReference::IllegalFinalReference( RefCountPtr< const char > _valueType, const char * _fieldID )
561 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), valueType( _valueType ), fieldID( _fieldID )
564 Exceptions::IllegalFinalReference::~IllegalFinalReference( )
567 void
568 Exceptions::IllegalFinalReference::display( std::ostream & os ) const
570 os << "Attempt to access field of non-final class " << valueType << " without home class. Use <HomeClass>#" << fieldID << " instead." << std::endl ;
574 Exceptions::NonExistentMember::NonExistentMember( RefCountPtr< const char > _valueType, const char * _fieldID )
575 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), valueType( _valueType ), fieldID( _fieldID )
578 Exceptions::NonExistentMember::~NonExistentMember( )
581 void
582 Exceptions::NonExistentMember::display( std::ostream & os ) const
584 os << "Class " << valueType << " has no (non-private) field called " << fieldID << "." << std::endl ;
588 Exceptions::NonExistentMutator::NonExistentMutator( RefCountPtr< const char > _valueType, const char * _mutatorID )
589 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), valueType( _valueType ), mutatorID( _mutatorID )
592 Exceptions::NonExistentMutator::~NonExistentMutator( )
595 void
596 Exceptions::NonExistentMutator::display( std::ostream & os ) const
598 os << "State type " << valueType << " has no mutator called " << mutatorID << "." << std::endl ;
602 Exceptions::NonExistentPosition::NonExistentPosition( size_t pos, size_t maxPos )
603 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), pos_( pos ), maxPos_( maxPos )
606 Exceptions::NonExistentPosition::~NonExistentPosition( )
609 void
610 Exceptions::NonExistentPosition::display( std::ostream & os ) const
612 os << "Referencing field at position " << pos_ << " is an error since the user struct has only " << maxPos_ << " ordered fields." << std::endl ;
616 Exceptions::ProtectedMemberPublicScope::ProtectedMemberPublicScope( RefCountPtr< const char > _valueType, const char * _fieldID )
617 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), valueType( _valueType ), fieldID( _fieldID )
620 Exceptions::ProtectedMemberPublicScope::~ProtectedMemberPublicScope( )
623 void
624 Exceptions::ProtectedMemberPublicScope::display( std::ostream & os ) const
626 os << "Trying to access protected member " << fieldID << " of class " << valueType << " via public instance." << std::endl ;
630 Exceptions::MemberNotAssignable::MemberNotAssignable( RefCountPtr< const char > _valueType, const char * _fieldID, RefCountPtr< const char > _scope )
631 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), valueType( _valueType ), fieldID( _fieldID ), scope( _scope )
634 Exceptions::MemberNotAssignable::~MemberNotAssignable( )
637 void
638 Exceptions::MemberNotAssignable::display( std::ostream & os ) const
640 os << "In " << scope << " scope of " << valueType << " : The member " << fieldID << " is not assignable." << std::endl ;
644 Exceptions::NotApplicable::NotApplicable( )
647 Exceptions::NotApplicable::~NotApplicable( )
650 void
651 Exceptions::NotApplicable::display( std::ostream & os ) const
653 os << "An operator was not applicable. It is an internal error that no better error message is given." << std::endl ;
657 Exceptions::UnaryPrefixNotApplicable::UnaryPrefixNotApplicable( const Ast::SourceLocation & _loc, const Ast::Expression * _expr, RefCountPtr< const char > _valueType )
658 : Exceptions::RuntimeError( _loc ), expr( _expr ), valueType( _valueType ), operatorSymbol( "< ? >" )
661 Exceptions::UnaryPrefixNotApplicable::~UnaryPrefixNotApplicable( )
664 void
665 Exceptions::UnaryPrefixNotApplicable::setOperatorSymbol( const char * _operatorSymbol )
667 operatorSymbol = _operatorSymbol;
670 void
671 Exceptions::UnaryPrefixNotApplicable::display( std::ostream & os ) const
673 if( expr != 0 )
675 os << "Operator " ;
676 getLoc( ).copy( & os );
677 os << " not defined for " << valueType << " at " << expr->loc( ) << "." << std::endl ;
679 else
681 os << "Operator " << operatorSymbol << " not defined for " << valueType << "." << std::endl ;
686 Exceptions::UnaryPostfixNotApplicable::UnaryPostfixNotApplicable( const Ast::SourceLocation & _loc, const Ast::Expression * _expr, RefCountPtr< const char > _valueType )
687 : Exceptions::RuntimeError( _loc ), expr( _expr ), valueType( _valueType ), operatorSymbol( "< ? >" )
690 Exceptions::UnaryPostfixNotApplicable::~UnaryPostfixNotApplicable( )
693 void
694 Exceptions::UnaryPostfixNotApplicable::setOperatorSymbol( const char * _operatorSymbol )
696 operatorSymbol = _operatorSymbol;
699 void
700 Exceptions::UnaryPostfixNotApplicable::display( std::ostream & os ) const
702 if( expr != 0 )
704 os << "Operator " ;
705 getLoc( ).copy( & os );
706 os << " not defined for " << valueType << " at " << expr->loc( ) << "." << std::endl ;
708 else
710 os << "Operator " << operatorSymbol << " not defined for " << valueType << "." << std::endl ;
715 Exceptions::BinaryInfixNotApplicable::BinaryInfixNotApplicable( const Ast::SourceLocation & _loc, const Ast::Expression * _expr1, RefCountPtr< const char > _valueType1, const Ast::Expression * _expr2, RefCountPtr< const char > _valueType2 )
716 : Exceptions::RuntimeError( _loc ), expr1( _expr1 ), valueType1( _valueType1 ), expr2( _expr2 ), valueType2( _valueType2 ), operatorSymbol( "< ? >" )
719 Exceptions::BinaryInfixNotApplicable::~BinaryInfixNotApplicable( )
722 void
723 Exceptions::BinaryInfixNotApplicable::setOperatorSymbol( const char * _operatorSymbol )
725 operatorSymbol = _operatorSymbol;
728 void
729 Exceptions::BinaryInfixNotApplicable::display( std::ostream & os ) const
731 if( expr1 != 0 && expr2 != 0 )
733 os << "Operator " ;
734 getLoc( ).copy( & os );
735 os << " not defined for (" << valueType1 << "," << valueType2 << ") at " << expr1->loc( ) << ", " << expr2->loc( ) << "." << std::endl ;
737 else
739 os << "Operator " << operatorSymbol << " not defined for (" << valueType1 << "," << valueType2 << ")." << std::endl ;
744 Exceptions::ProhibitedTypeChange::ProhibitedTypeChange( const Ast::SourceLocation & _loc, RefCountPtr< const char > _id, RefCountPtr< const char > _oldType, RefCountPtr< const char > _newType )
745 : Exceptions::RuntimeError( _loc ), id( _id ), oldType( _oldType ), newType( _newType )
748 Exceptions::ProhibitedTypeChange::~ProhibitedTypeChange( )
751 void
752 Exceptions::ProhibitedTypeChange::display( std::ostream & os ) const
754 os << "The type of " << id << " is locked to " << oldType << ", but the new value is of type " << newType << "." << std::endl ;
758 Exceptions::LookupUnknown::LookupUnknown( const Ast::SourceLocation & _loc, RefCountPtr< const char > _id, Type type )
759 : Exceptions::StaticInconsistency( _loc ), id( _id ), type_( type )
762 Exceptions::LookupUnknown::~LookupUnknown( )
765 void
766 Exceptions::LookupUnknown::display( std::ostream & os ) const
768 switch( type_ )
770 case VARIABLE:
771 os << "The variable " << id << " is unbound." << std::endl ;
772 break;
773 case STATE:
774 os << "There is no state called " << id << " around." << std::endl ;
775 break;
776 case DYNAMIC_VARIABLE:
777 os << "There is no dynamic variable called " << id << " around." << std::endl ;
778 break;
779 case DYNAMIC_STATE:
780 os << "There is no dynamic state called " << id << " around." << std::endl ;
781 break;
782 case TYPE:
783 os << "There is no type called " << id << " around." << std::endl ;
784 break;
785 default:
786 os << "<?ERROR?" ;
791 Exceptions::StateBeyondFunctionBoundary::StateBeyondFunctionBoundary( const Ast::SourceLocation & _loc, RefCountPtr< const char > _id )
792 : Exceptions::StaticInconsistency( _loc ), id( _id )
795 Exceptions::StateBeyondFunctionBoundary::~StateBeyondFunctionBoundary( )
798 void
799 Exceptions::StateBeyondFunctionBoundary::display( std::ostream & os ) const
801 os << "The state " << id << " resides outside a function boundary." << std::endl ;
805 Exceptions::IntroducingExistingUnit::IntroducingExistingUnit( const Ast::SourceLocation & _loc, RefCountPtr< const char > _id )
806 : Exceptions::StaticInconsistency( _loc ), id( _id )
809 Exceptions::IntroducingExistingUnit::~IntroducingExistingUnit( )
812 void
813 Exceptions::IntroducingExistingUnit::display( std::ostream & os ) const
815 os << "Inconsistent definition of the existing unit " << id << "." << std::endl ;
819 Exceptions::LookupUnknownUnit::LookupUnknownUnit( const Ast::SourceLocation & _loc, RefCountPtr< const char > _id )
820 : Exceptions::StaticInconsistency( _loc ), id( _id )
823 Exceptions::LookupUnknownUnit::~LookupUnknownUnit( )
826 void
827 Exceptions::LookupUnknownUnit::display( std::ostream & os ) const
829 os << "The unit " << id << " is unbound" << std::endl ;
833 Exceptions::OutOfRange::OutOfRange( RefCountPtr< const char > msg )
834 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg )
837 Exceptions::OutOfRange::OutOfRange( const char * msg )
838 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
841 Exceptions::OutOfRange::OutOfRange( const Ast::SourceLocation & _loc, RefCountPtr< const char > msg )
842 : Exceptions::RuntimeError( _loc ), msg_( msg.getPtr( ) ), msgMem_( msg )
845 Exceptions::OutOfRange::OutOfRange( const Ast::SourceLocation & _loc, const char * msg )
846 : Exceptions::RuntimeError( _loc ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
849 Exceptions::OutOfRange::~OutOfRange( )
852 void
853 Exceptions::OutOfRange::display( std::ostream & os ) const
855 os << "Out-of-range error: " << msg_ << std::endl ;
859 Exceptions::NonVoidStatement::NonVoidStatement( const Ast::SourceLocation & _loc, RefCountPtr< const Lang::Value > _val )
860 : Exceptions::RuntimeError( _loc ), val( _val )
863 Exceptions::NonVoidStatement::~NonVoidStatement( )
866 void
867 Exceptions::NonVoidStatement::display( std::ostream & os ) const
869 os << "No implicit ignore of non-void value (of type " << val->getTypeName( ) << ")" << std::endl ;
872 // Exceptions::RuntimeError::RuntimeError( )
873 // : loc_( "< unlocated runtime error >" )
874 // { }
876 Exceptions::RuntimeError::~RuntimeError( )
879 Exceptions::RuntimeError::RuntimeError( const Ast::SourceLocation & loc )
880 : loc_( loc )
883 Exceptions::RuntimeError::RuntimeError( Ast::Expression * expr )
884 : loc_( expr->loc( ) )
887 const Ast::SourceLocation &
888 Exceptions::RuntimeError::getLoc( ) const
890 return loc_;
894 Exceptions::UserError::UserError( RefCountPtr< const char > _msg )
895 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg( _msg )
898 Exceptions::UserError::~UserError( )
901 void
902 Exceptions::UserError::display( ostream & os ) const
904 os << "User error: " << msg << std::endl ;
908 Exceptions::InternalError::InternalError( const Ast::SourceLocation & loc, RefCountPtr< const char > msg )
909 : Exceptions::RuntimeError( loc ), msg_( msg.getPtr( ) ), msgMem_( msg )
912 Exceptions::InternalError::InternalError( const Ast::SourceLocation & loc, const char * msg )
913 : Exceptions::RuntimeError( loc ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
916 Exceptions::InternalError::InternalError( RefCountPtr< const char > msg )
917 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg )
920 Exceptions::InternalError::InternalError( const char * msg )
921 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
924 Exceptions::InternalError::InternalError( const std::ostringstream & msg )
925 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( strdup( msg.str( ).c_str( ) ) ), msgMem_( msg_ )
928 Exceptions::InternalError::~InternalError( )
931 void
932 Exceptions::InternalError::display( ostream & os ) const
934 os << "Internal error: " << msg_ << std::endl ;
938 Exceptions::ExternalError::ExternalError( RefCountPtr< const char > msg )
939 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg )
942 Exceptions::ExternalError::ExternalError( const char * msg )
943 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
946 Exceptions::ExternalError::~ExternalError( )
949 void
950 Exceptions::ExternalError::display( ostream & os ) const
952 os << "External error: " << msg_ << std::endl ;
955 Exceptions::ExternalError *
956 Exceptions::ExternalError::clone( ) const
958 return new Exceptions::ExternalError( msgMem_ );
961 Exceptions::UserArityMismatch::UserArityMismatch( const Ast::SourceLocation _formalsLoc, size_t _functionArity, size_t _callArity, Type type )
962 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc( _formalsLoc ), functionArity( _functionArity ), callArity( _callArity ), type_( type )
965 Exceptions::UserArityMismatch::~UserArityMismatch( )
968 void
969 Exceptions::UserArityMismatch::display( std::ostream & os ) const
971 os << "Function with formals at " << formalsLoc << " expects " << functionArity ;
972 switch( type_ )
974 case VARIABLE:
975 os << " value arguments" ;
976 break;
977 case STATE:
978 os << " state arguments" ;
979 break;
980 default:
981 os << " ?ERROR?" ;
983 os << ", not " << callArity << std::endl ;
986 Exceptions::SinkRequired::SinkRequired( const Ast::SourceLocation formalsLoc, size_t formalsArity, size_t callArity )
987 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc_( formalsLoc ), formalsArity_( formalsArity ), callArity_( callArity )
990 Exceptions::SinkRequired::~SinkRequired( )
993 void
994 Exceptions::SinkRequired::display( std::ostream & os ) const
996 os << "Formals at " << formalsLoc_ << " contains no sink, so passing " << callArity_ << " ordered arguments is " << callArity_ - formalsArity_ << " too many." << std::endl ;
1000 Exceptions::NamedFormalMismatch::NamedFormalMismatch( const Ast::SourceLocation _formalsLoc, RefCountPtr< const char > _name, Exceptions::NamedFormalMismatch::Type type )
1001 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc( _formalsLoc ), name( _name ), type_( type )
1004 Exceptions::NamedFormalMismatch::~NamedFormalMismatch( )
1007 void
1008 Exceptions::NamedFormalMismatch::display( std::ostream & os ) const
1010 os << "Function with formals at " << formalsLoc << " has no named ";
1011 switch( type_ )
1013 case VARIABLE:
1014 os << "variable" ;
1015 break;
1016 case STATE:
1017 os << "state" ;
1018 break;
1019 default:
1020 os << "<?ERROR?" ;
1022 os << " called " << name << "." << std::endl ;
1026 Exceptions::NamedFormalAlreadySpecified::NamedFormalAlreadySpecified( const Ast::SourceLocation _formalsLoc, RefCountPtr< const char > _name, size_t _pos, Exceptions::NamedFormalAlreadySpecified::Type type )
1027 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc( _formalsLoc ), name( _name ), pos( _pos ), type_( type )
1030 Exceptions::NamedFormalAlreadySpecified::~NamedFormalAlreadySpecified( )
1033 void
1034 Exceptions::NamedFormalAlreadySpecified::display( std::ostream & os ) const
1036 os << "The formal " ;
1037 switch( type_ )
1039 case VARIABLE:
1040 os << "variable" ;
1041 break;
1042 case STATE:
1043 os << "state" ;
1044 break;
1045 default:
1046 os << "<?ERROR?" ;
1048 os << " named " << name << ", defined at " << formalsLoc << " is already defined by order, at position " << pos << "." << std::endl ;
1051 Exceptions::MissingArguments::MissingArguments( const Ast::SourceLocation _formalsLoc, std::map< size_t, RefCountPtr< const char > > * _missingVariables, std::map< size_t, RefCountPtr< const char > > * _missingStates )
1052 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc( _formalsLoc ), missingVariables( _missingVariables ), missingStates( _missingStates )
1055 Exceptions::MissingArguments::~MissingArguments( )
1057 if( missingVariables != 0 )
1059 delete missingVariables;
1061 if( missingStates != 0 )
1063 delete missingStates;
1067 void
1068 Exceptions::MissingArguments::display( std::ostream & os ) const
1070 os << "Among the formals at " << formalsLoc ;
1071 if( missingVariables != 0 )
1073 os << ", the following variables are missing:" ;
1074 typedef typeof *missingVariables MapType;
1075 for( MapType::const_iterator i = missingVariables->begin( ); i != missingVariables->end( ); ++i )
1077 if( i != missingVariables->begin( ) )
1079 os << "," ;
1081 os << " (" << i->first << ")" << i->second.getPtr( ) ;
1084 if( missingStates != 0 )
1086 os << ", " ;
1087 if( missingVariables != 0 )
1089 os << "and " ;
1091 os << "the following states are missing:" ;
1092 typedef typeof *missingStates MapType;
1093 for( MapType::const_iterator i = missingStates->begin( ); i != missingStates->end( ); ++i )
1095 if( i != missingStates->begin( ) )
1097 os << "," ;
1099 os << " (" << i->first << ")" << i->second.getPtr( ) ;
1102 os << "." << std::endl ;
1106 Exceptions::CoreArityMismatch::CoreArityMismatch( const char * _title, size_t _functionArity, size_t _callArity )
1107 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title ), titleMem( NullPtr< const char >( ) ), functionArityLow( _functionArity ), functionArityHigh( _functionArity ), callArity( _callArity )
1110 Exceptions::CoreArityMismatch::CoreArityMismatch( const char * _title, size_t _functionArityLow, size_t _functionArityHigh, size_t _callArity )
1111 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title ), titleMem( NullPtr< const char >( ) ), functionArityLow( _functionArityLow ), functionArityHigh( _functionArityHigh ), callArity( _callArity )
1114 Exceptions::CoreArityMismatch::CoreArityMismatch( const RefCountPtr< const char > & _title, size_t _functionArity, size_t _callArity )
1115 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title.getPtr( ) ), titleMem( _title ), functionArityLow( _functionArity ), functionArityHigh( _functionArity ), callArity( _callArity )
1118 Exceptions::CoreArityMismatch::CoreArityMismatch( const RefCountPtr< const char > & _title, size_t _functionArityLow, size_t _functionArityHigh, size_t _callArity )
1119 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title.getPtr( ) ), titleMem( _title ), functionArityLow( _functionArityLow ), functionArityHigh( _functionArityHigh ), callArity( _callArity )
1122 Exceptions::CoreArityMismatch::~CoreArityMismatch( )
1125 void
1126 Exceptions::CoreArityMismatch::display( std::ostream & os ) const
1128 if( functionArityLow == functionArityHigh )
1130 os << "Core function " << title << " expects " << functionArityLow << " arguments, not " << callArity << std::endl ;
1132 else
1134 os << "Core function " << title << " expects [" << functionArityLow << ", " << functionArityHigh << "] arguments, not " << callArity << std::endl ;
1139 Exceptions::CoreNoNamedFormals::CoreNoNamedFormals( const char * _title )
1140 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title ), titleMem( NullPtr< const char >( ) )
1143 Exceptions::CoreNoNamedFormals::CoreNoNamedFormals( const RefCountPtr< const char > & _title )
1144 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title.getPtr( ) ), titleMem( _title )
1147 Exceptions::CoreNoNamedFormals::~CoreNoNamedFormals( )
1150 void
1151 Exceptions::CoreNoNamedFormals::display( std::ostream & os ) const
1153 os << "Core function " << title << " does not accept named arguments." << std::endl ;
1157 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1158 const char * title,
1159 const Ast::SourceLocation & argLoc,
1160 RefCountPtr< const char > valueType,
1161 RefCountPtr< const char > expectedType )
1162 : Exceptions::RuntimeError( callLoc ),
1163 title_( title ),
1164 titleMem_( NullPtr< const char >( ) ),
1165 argLoc_( argLoc ),
1166 valueType_( valueType ),
1167 expectedType_( expectedType )
1170 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1171 RefCountPtr< const char > title,
1172 const Ast::SourceLocation & argLoc,
1173 RefCountPtr< const char > valueType,
1174 RefCountPtr< const char > expectedType )
1175 : Exceptions::RuntimeError( callLoc ),
1176 title_( title.getPtr( ) ),
1177 titleMem_( title ),
1178 argLoc_( argLoc ),
1179 valueType_( valueType ),
1180 expectedType_( expectedType )
1183 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1184 const char * title,
1185 Kernel::Arguments & args,
1186 size_t argNo,
1187 RefCountPtr< const char > expectedType )
1188 : Exceptions::RuntimeError( callLoc ),
1189 title_( title ),
1190 titleMem_( NullPtr< const char >( ) ),
1191 argLoc_( args.getLoc( argNo ) ),
1192 valueType_( args.getValue( argNo )->getTypeName( ) ),
1193 expectedType_( expectedType )
1196 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1197 RefCountPtr< const char > title,
1198 Kernel::Arguments & args,
1199 size_t argNo,
1200 RefCountPtr< const char > expectedType )
1201 : Exceptions::RuntimeError( callLoc ),
1202 title_( title.getPtr( ) ),
1203 titleMem_( title ),
1204 argLoc_( args.getLoc( argNo ) ),
1205 valueType_( args.getValue( argNo )->getTypeName( ) ),
1206 expectedType_( expectedType )
1209 Exceptions::CoreTypeMismatch::~CoreTypeMismatch( )
1212 void
1213 Exceptions::CoreTypeMismatch::display( std::ostream & os ) const
1215 os << "Core function " << title_ << ", argument ";
1216 // if( argName_ != 0 )
1217 // {
1218 // os << "\"" << argName_ << "\" " ;
1219 // }
1220 os << "at " << argLoc_ << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1224 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1225 const char * title,
1226 const Ast::SourceLocation & argLoc,
1227 RefCountPtr< const char > valueType,
1228 RefCountPtr< const char > expectedType )
1229 : Exceptions::RuntimeError( callLoc ),
1230 title_( title ),
1231 titleMem_( NullPtr< const char >( ) ),
1232 argLoc_( argLoc ),
1233 valueType_( valueType ),
1234 expectedType_( expectedType )
1237 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1238 RefCountPtr< const char > title,
1239 const Ast::SourceLocation & argLoc,
1240 RefCountPtr< const char > valueType,
1241 RefCountPtr< const char > expectedType )
1242 : Exceptions::RuntimeError( callLoc ),
1243 title_( title.getPtr( ) ),
1244 titleMem_( title ),
1245 argLoc_( argLoc ),
1246 valueType_( valueType ),
1247 expectedType_( expectedType )
1250 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1251 const char * title,
1252 Kernel::Arguments & args,
1253 size_t argNo,
1254 RefCountPtr< const char > expectedType )
1255 : Exceptions::RuntimeError( callLoc ),
1256 title_( title ),
1257 titleMem_( NullPtr< const char >( ) ),
1258 argLoc_( args.getStateLoc( argNo ) ),
1259 valueType_( args.getState( argNo )->getTypeName( ) ),
1260 expectedType_( expectedType )
1263 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1264 RefCountPtr< const char > title,
1265 Kernel::Arguments & args,
1266 size_t argNo,
1267 RefCountPtr< const char > expectedType )
1268 : Exceptions::RuntimeError( callLoc ),
1269 title_( title.getPtr( ) ),
1270 titleMem_( title ),
1271 argLoc_( args.getStateLoc( argNo ) ),
1272 valueType_( args.getState( argNo )->getTypeName( ) ),
1273 expectedType_( expectedType )
1276 Exceptions::CoreStateTypeMismatch::~CoreStateTypeMismatch( )
1279 void
1280 Exceptions::CoreStateTypeMismatch::display( std::ostream & os ) const
1282 os << "Core function " << title_ << ", state ";
1283 // if( argName_ != 0 )
1284 // {
1285 // os << "\"" << argName_ << "\" " ;
1286 // }
1287 os << "at " << argLoc_ << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1291 Exceptions::CoreDynamicTypeMismatch::CoreDynamicTypeMismatch( const Ast::SourceLocation & callLoc,
1292 const char * title,
1293 const char * id,
1294 RefCountPtr< const char > valueType,
1295 RefCountPtr< const char > expectedType )
1296 : Exceptions::RuntimeError( callLoc ),
1297 title_( title ),
1298 titleMem_( NullPtr< const char >( ) ),
1299 id_( id ),
1300 idMem_( NullPtr< const char >( ) ),
1301 valueType_( valueType ),
1302 expectedType_( expectedType )
1305 Exceptions::CoreDynamicTypeMismatch::~CoreDynamicTypeMismatch( )
1308 void
1309 Exceptions::CoreDynamicTypeMismatch::display( std::ostream & os ) const
1311 os << "Core function " << title_ << " encountered a type mismatch in the dynamic variable @" << id_
1312 << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1315 Exceptions::ContinuationTypeMismatch::ContinuationTypeMismatch( const Kernel::Continuation * locationCont,
1316 RefCountPtr< const char > valueType,
1317 RefCountPtr< const char > expectedType )
1318 : Exceptions::RuntimeError( locationCont->traceLoc( ) ),
1319 valueType_( valueType ),
1320 expectedType_( expectedType )
1323 Exceptions::ContinuationTypeMismatch::~ContinuationTypeMismatch( )
1326 void
1327 Exceptions::ContinuationTypeMismatch::display( std::ostream & os ) const
1329 os << "The continuation expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1333 Exceptions::EmptyApplication::EmptyApplication( )
1334 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1337 Exceptions::EmptyApplication::~EmptyApplication( )
1340 void
1341 Exceptions::EmptyApplication::display( std::ostream & os ) const
1343 os << "Empty application." << std::endl ;
1347 Exceptions::CoreOutOfRange::CoreOutOfRange( const char * _title, Kernel::Arguments & args, size_t argNo, RefCountPtr< const char > msg )
1348 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title ), argLoc_( args.getLoc( argNo ) ), msg_( msg.getPtr( ) ), msgMem_( msg )
1351 Exceptions::CoreOutOfRange::CoreOutOfRange( const char * _title, Kernel::Arguments & args, size_t argNo, const char * msg )
1352 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title ), argLoc_( args.getLoc( argNo ) ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
1355 Exceptions::CoreOutOfRange::~CoreOutOfRange( )
1358 void
1359 Exceptions::CoreOutOfRange::display( std::ostream & os ) const
1361 os << "Core function " << title << ": ";
1362 os << "Argument at " << argLoc_ << " is out of range; " << msg_ << std::endl ;
1365 Exceptions::CoreRequirement::CoreRequirement( RefCountPtr< const char > msg, const char * _title, const Ast::SourceLocation & callLoc )
1366 : Exceptions::RuntimeError( callLoc ), title( _title ), msg_( msg.getPtr( ) ), msgMem_( msg )
1369 Exceptions::CoreRequirement::CoreRequirement( const char * msg, const char * _title, const Ast::SourceLocation & callLoc )
1370 : Exceptions::RuntimeError( callLoc ), title( _title ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
1373 Exceptions::CoreRequirement::~CoreRequirement( )
1376 void
1377 Exceptions::CoreRequirement::display( std::ostream & os ) const
1379 os << "Core function " << title << ": " << msg_ << std::endl ;
1383 Exceptions::TeXLabelError::TeXLabelError( bool quoted, const char * region, RefCountPtr< const char > summary, RefCountPtr< const char > details, const Ast::SourceLocation & loc )
1384 : Exceptions::RuntimeError( loc ), strLoc_( loc ), quoted_( quoted ), region_( region ), summary_( summary ), details_( details )
1387 Exceptions::TeXLabelError::~TeXLabelError( )
1390 void
1391 Exceptions::TeXLabelError::display( ostream & os ) const
1393 if( quoted_ )
1395 os << "TeX error in " << region_ ;
1397 else
1399 os << "Error in TeX " << region_ ;
1401 if( ! strLoc_.isUnknown( ) )
1403 os << " at " << strLoc_ ;
1405 os << ": " ;
1406 if( quoted_ )
1408 os << "\"" ;
1410 os << summary_ ;
1411 if( quoted_ )
1413 os << "\"" ;
1415 os << std::endl ;
1416 if( details_ != NullPtr< const char >( ) )
1418 Exceptions::prefixEachLine( additionalLinesPrefix, details_, os );
1423 Exceptions::StaticTeXLabelError::StaticTeXLabelError( bool quoted, const char * region, RefCountPtr< const char > summary, RefCountPtr< const char > details, const Ast::SourceLocation & loc )
1424 : Exceptions::StaticInconsistency( loc ), quoted_( quoted ), region_( region ), summary_( summary ), details_( details )
1427 Exceptions::StaticTeXLabelError::~StaticTeXLabelError( )
1430 void
1431 Exceptions::StaticTeXLabelError::display( ostream & os ) const
1433 if( quoted_ )
1435 os << "TeX error in " << region_ ;
1437 else
1439 os << "Error in TeX " << region_ ;
1441 os << ": " ;
1442 if( quoted_ )
1444 os << "\"" ;
1446 os << summary_ ;
1447 if( quoted_ )
1449 os << "\"" ;
1451 os << std::endl ;
1452 if( details_ != NullPtr< const char >( ) )
1454 Exceptions::prefixEachLine( additionalLinesPrefix, details_, os );
1459 Exceptions::InstantiatingAbstractClass::InstantiatingAbstractClass( RefCountPtr< const Lang::Class > _cls )
1460 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls )
1463 Exceptions::InstantiatingAbstractClass::~InstantiatingAbstractClass( )
1466 void
1467 Exceptions::InstantiatingAbstractClass::display( ostream & os ) const
1469 os << "Trying to instantiate abstract class: " << cls->getPrettyName( ) << std::endl ;
1473 Exceptions::FailedToDeclareClassAbstract::FailedToDeclareClassAbstract( RefCountPtr< const Lang::Class > _cls, const Shapes::Ast::ClassFunction * _classExpr )
1474 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls ), classExpr( _classExpr )
1477 Exceptions::FailedToDeclareClassAbstract::~FailedToDeclareClassAbstract( )
1480 void
1481 Exceptions::FailedToDeclareClassAbstract::display( ostream & os ) const
1483 os << classExpr->loc( ) << " " << "Class " << cls->getPrettyName( ) << " has abstract methods but is not declared abstract: " ;
1484 cls->showAbstractSet( os );
1485 os << std::endl ;
1489 Exceptions::RepeatedImmediateParent::RepeatedImmediateParent( RefCountPtr< const Lang::Class > _cls, RefCountPtr< const Lang::Class > _parent )
1490 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls ), parent( _parent )
1493 Exceptions::RepeatedImmediateParent::~RepeatedImmediateParent( )
1496 void
1497 Exceptions::RepeatedImmediateParent::display( ostream & os ) const
1499 os << "When creating the class " << cls->getPrettyName( ) << ", the following class is a repeated immediate parent: " << parent->getPrettyName( ) << std::endl ;
1503 Exceptions::OverridingNonParent::OverridingNonParent( RefCountPtr< const Lang::Class > _cls, RefCountPtr< const Lang::Class > _parent )
1504 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls ), parent( _parent )
1507 Exceptions::OverridingNonParent::~OverridingNonParent( )
1510 void
1511 Exceptions::OverridingNonParent::display( ostream & os ) const
1513 os << "The class " << cls->getPrettyName( ) << " cannot override methods from the class " << parent->getPrettyName( ) << ", since the latter is not a parent of the former." << std::endl ;
1517 Exceptions::InheritingFinal::InheritingFinal( RefCountPtr< const Lang::Class > _cls, RefCountPtr< const Lang::Class > _parent )
1518 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls ), parent( _parent )
1521 Exceptions::InheritingFinal::~InheritingFinal( )
1524 void
1525 Exceptions::InheritingFinal::display( ostream & os ) const
1527 os << "When creating the class " << cls->getPrettyName( ) << ", trying to inherit from final class: " << parent->getPrettyName( ) << std::endl ;
1531 Exceptions::OverridingUndeclaredMethod::OverridingUndeclaredMethod( RefCountPtr< const Lang::Class > _cls, RefCountPtr< const Lang::Class > _parent, const char * _id )
1532 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls ), parent( _parent ), id( _id )
1535 Exceptions::OverridingUndeclaredMethod::~OverridingUndeclaredMethod( )
1538 void
1539 Exceptions::OverridingUndeclaredMethod::display( ostream & os ) const
1541 os << "In override declaration in class " << cls->getPrettyName( ) << ": there is no method called " << id << " in class " << parent->getPrettyName( ) << " to override." << std::endl ;
1545 Exceptions::OverridingFinalMethod::OverridingFinalMethod( RefCountPtr< const Lang::Class > _cls, RefCountPtr< const Lang::Class > _parent, const char * _id )
1546 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls ), parent( _parent ), id( _id )
1549 Exceptions::OverridingFinalMethod::~OverridingFinalMethod( )
1552 void
1553 Exceptions::OverridingFinalMethod::display( ostream & os ) const
1555 os << "In override declaration in class " << cls->getPrettyName( ) << ": The method " << id << " in class " << parent->getPrettyName( ) << " is final." << std::endl ;
1559 Exceptions::IllegalRepeatedBase::IllegalRepeatedBase( RefCountPtr< const Lang::Class > _cls, RefCountPtr< const Lang::Class > _parent )
1560 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls ), parent( _parent )
1563 Exceptions::IllegalRepeatedBase::~IllegalRepeatedBase( )
1566 void
1567 Exceptions::IllegalRepeatedBase::display( ostream & os ) const
1569 os << "When creating the class " << cls->getPrettyName( ) << ", the following repeated base class may not be repeated: " << parent->getPrettyName( ) << std::endl ;
1573 Exceptions::AmbiguousInheritedMethod::AmbiguousInheritedMethod( RefCountPtr< const Lang::Class > _cls, RefCountPtr< const char > _id, std::set< RefCountPtr< const Lang::Class > > _parents )
1574 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls ), id( _id ), parents( _parents )
1577 Exceptions::AmbiguousInheritedMethod::~AmbiguousInheritedMethod( )
1580 void
1581 Exceptions::AmbiguousInheritedMethod::display( ostream & os ) const
1583 os << "In class " << cls->getPrettyName( ) << ": the method name " << id << " is ambiguous, as it is inherited from more than one class:" ;
1584 for( std::set< RefCountPtr< const Lang::Class > >::const_iterator i = parents.begin( ); i != parents.end( ); ++i )
1586 os << " " << (*i)->getPrettyName( ) ;
1588 os << std::endl ;
1592 Exceptions::MisplacedSuperReference::MisplacedSuperReference( const Ast::SourceLocation & _loc )
1593 : Exceptions::RuntimeError( _loc )
1596 Exceptions::MisplacedSuperReference::~MisplacedSuperReference( )
1599 void
1600 Exceptions::MisplacedSuperReference::display( std::ostream & os ) const
1602 os << "Misplaced reference to parent instance." << std::endl ;
1606 Exceptions::SuperReferenceClassNotParent::SuperReferenceClassNotParent( RefCountPtr< const Lang::Class > _cls, RefCountPtr< const Lang::Class > _parent )
1607 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls ), parent( _parent )
1610 Exceptions::SuperReferenceClassNotParent::~SuperReferenceClassNotParent( )
1613 void
1614 Exceptions::SuperReferenceClassNotParent::display( std::ostream & os ) const
1616 os << "When referencing super instance, " << parent->getPrettyName( ) << " is not a parent of " << cls->getPrettyName( ) << "." << std::endl ;
1620 Exceptions::NoSuchMethod::NoSuchMethod( RefCountPtr< const Lang::Class > _cls, const Kernel::MethodId & _method )
1621 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls ), method( _method )
1624 Exceptions::NoSuchMethod::~NoSuchMethod( )
1627 void
1628 Exceptions::NoSuchMethod::display( std::ostream & os ) const
1630 os << "Class " << cls->getPrettyName( ) << " has no method called " << method.prettyName( ) << std::endl ;
1634 Exceptions::NoSuchLocalMethod::NoSuchLocalMethod( RefCountPtr< const Lang::Class > _cls, const Kernel::MethodId & _method )
1635 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), cls( _cls ), method( _method )
1638 Exceptions::NoSuchLocalMethod::~NoSuchLocalMethod( )
1641 void
1642 Exceptions::NoSuchLocalMethod::display( std::ostream & os ) const
1644 os << "Class " << cls->getPrettyName( ) << " does not itself define the method " << method.prettyName( ) << std::endl ;
1648 Exceptions::MultipleDynamicBind::MultipleDynamicBind( const char * _id, const Ast::SourceLocation & _loc, const Ast::SourceLocation & _prevLoc )
1649 : Exceptions::RuntimeError( _loc ), id( _id ), prevLoc( _prevLoc )
1652 Exceptions::MultipleDynamicBind::~MultipleDynamicBind( )
1655 void
1656 Exceptions::MultipleDynamicBind::display( std::ostream & os ) const
1658 os << "This dynamic binding of " << id << " is merged with the conflicting binding at " << prevLoc << "." << std::endl ;
1662 Exceptions::UndefinedEscapeContinuation::UndefinedEscapeContinuation( const char * _id, const Ast::SourceLocation & _loc )
1663 : Exceptions::RuntimeError( _loc ), id( _id )
1666 Exceptions::UndefinedEscapeContinuation::~UndefinedEscapeContinuation( )
1669 void
1670 Exceptions::UndefinedEscapeContinuation::display( std::ostream & os ) const
1672 os << "The escape continuation " << id << " was not defined in the dynamic context." << std::endl ;
1676 Exceptions::DeadStateAccess::DeadStateAccess( )
1677 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1680 Exceptions::DeadStateAccess::~DeadStateAccess( )
1683 void
1684 Exceptions::DeadStateAccess::display( std::ostream & os ) const
1686 os << "Accessing dead state." << std::endl ;
1690 Exceptions::UnFreezable::UnFreezable( )
1691 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1694 Exceptions::UnFreezable::~UnFreezable( )
1697 void
1698 Exceptions::UnFreezable::display( std::ostream & os ) const
1700 os << "The state cannot be frozen." << std::endl ;
1704 Exceptions::UnPeekable::UnPeekable( )
1705 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1708 Exceptions::UnPeekable::~UnPeekable( )
1711 void
1712 Exceptions::UnPeekable::display( std::ostream & os ) const
1714 os << "The state cannot be peeked. Consider freezing it." << std::endl ;
1718 Exceptions::UninitializedAccess::UninitializedAccess( )
1719 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1722 Exceptions::UninitializedAccess::~UninitializedAccess( )
1725 void
1726 Exceptions::UninitializedAccess::display( std::ostream & os ) const
1728 os << "The accessed variable or state has not been initialized yet." << std::endl ;
1732 Exceptions::DtMinError::DtMinError( double _dt )
1733 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), dt( _dt )
1736 Exceptions::DtMinError::~DtMinError( )
1739 void
1740 Exceptions::DtMinError::display( std::ostream & os ) const
1742 os << "Path segment too long in relation to arcdelta: dt = " << dt << " < " << Computation::the_dtMin << ". Either increase arcdelta, or inhibit this error." << std::endl ;
1746 Exceptions::AffineTransformKillsPlane::AffineTransformKillsPlane( double sigma2 )
1747 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), sigma2_( sigma2 )
1750 Exceptions::AffineTransformKillsPlane::~AffineTransformKillsPlane( )
1753 void
1754 Exceptions::AffineTransformKillsPlane::display( std::ostream & os ) const
1756 os << "When transforming a plane normal, it was found that the affine transform is too singular, with a second largest singular value of " << sigma2_ << "." << std::endl ;
1759 Exceptions::MissingFontMetrics::MissingFontMetrics( RefCountPtr< const char > fontname, const std::list< std::string > * searchPath )
1760 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), fontname_( fontname ), searchPath_( searchPath )
1763 Exceptions::MissingFontMetrics::~MissingFontMetrics( )
1766 void
1767 Exceptions::MissingFontMetrics::display( std::ostream & os ) const
1769 os << "The font metrics for " << fontname_ << ", named " << fontname_ << ".afm, could not be found in {" ;
1770 typedef typeof *searchPath_ ListType;
1771 for( ListType::const_iterator i = searchPath_->begin( ); i != searchPath_->end( ); ++i )
1773 os << " " << *i ;
1775 os << " }." << std::endl ;
1779 Exceptions::FontMetricsError::FontMetricsError( const RefCountPtr< const char > & fontname, const RefCountPtr< const char > & message )
1780 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), fontname_( fontname ), message_( message )
1783 Exceptions::FontMetricsError::~FontMetricsError( )
1786 void
1787 Exceptions::FontMetricsError::display( std::ostream & os ) const
1789 os << "There was a problem with the font metrics for " << fontname_ << ": " << message_ << std::endl ;
1793 Exceptions::InsertingEmptyPage::InsertingEmptyPage( const Ast::SourceLocation & loc )
1794 : Exceptions::RuntimeError( loc )
1797 Exceptions::InsertingEmptyPage::~InsertingEmptyPage( )
1800 void
1801 Exceptions::InsertingEmptyPage::display( std::ostream & os ) const
1803 os << "Attempt to place empty page in catalog." << std::endl ;
1807 Exceptions::UndefinedCrossRef::UndefinedCrossRef( const Ast::SourceLocation & _loc, RefCountPtr< const char > ref )
1808 : Exceptions::PostCondition( _loc ), ref_( ref )
1811 Exceptions::UndefinedCrossRef::~UndefinedCrossRef( )
1814 void
1815 Exceptions::UndefinedCrossRef::display( std::ostream & os ) const
1817 os << "The cross reference \"" << ref_ << "\" is not defined." << std::endl ;
1821 void
1822 Exceptions::prefixEachLine( const std::string & prefix, std::istream & src, std::ostream & dst )
1824 std::string line;
1825 for( std::getline( src, line ); ! src.eof( ); std::getline( src, line ) )
1827 dst << prefix << line << std::endl ;
1831 void
1832 Exceptions::prefixEachLine( const std::string & prefix, const RefCountPtr< const char > & src, std::ostream & dst )
1834 std::istringstream is( src.getPtr( ) );
1835 Exceptions::prefixEachLine( prefix, is, dst );