Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / shapesexceptions.cc
blob39415ba6ce8c3bd08b51b59376a2cc7cb232c253
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, 2009 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::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg )
63 { }
65 Exceptions::MiscellaneousRequirement::MiscellaneousRequirement( const char * msg )
66 : Exceptions::CatchableError( 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 ;
78 RefCountPtr< const Lang::Exception >
79 Exceptions::MiscellaneousRequirement::clone( const Kernel::ContRef & cont ) const
81 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
82 std::ostringstream os;
83 display( os );
84 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
85 kind,
86 RefCountPtr< const Lang::String >( new Lang::String( "(core, generic)", true ) ),
87 Lang::THE_VOID,
88 strrefdup( os ),
89 cont,
90 this->exitCode( ) ) );
94 Exceptions::HandlerError::HandlerError( RefCountPtr< const char > _msg )
95 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg( _msg )
96 { }
98 Exceptions::HandlerError::HandlerError( const char * _msg )
99 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg( strrefdup( _msg ) )
102 Exceptions::HandlerError::~HandlerError( )
105 void
106 Exceptions::HandlerError::display( ostream & os ) const
108 os << "Error handler message: " << msg << std::endl ;
111 RefCountPtr< const Lang::Exception >
112 Exceptions::HandlerError::clone( const Kernel::ContRef & cont ) const
114 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
115 std::ostringstream os;
116 display( os );
117 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
118 kind,
119 RefCountPtr< const Lang::String >( new Lang::String( "(default error handler)", true ) ),
120 Lang::THE_VOID,
121 strrefdup( os ),
122 cont,
123 this->exitCode( ) ) );
127 Exceptions::MiscellaneousStaticInconsistency::MiscellaneousStaticInconsistency( const Ast::SourceLocation & loc, RefCountPtr< const char > _msg )
128 : Exceptions::StaticInconsistency( loc ), msg( _msg )
131 Exceptions::MiscellaneousStaticInconsistency::~MiscellaneousStaticInconsistency( )
134 void
135 Exceptions::MiscellaneousStaticInconsistency::display( ostream & os ) const
137 os << "Misc error: " << msg << std::endl ;
141 Exceptions::ScannerError::ScannerError( const Ast::SourceLocation & loc, RefCountPtr< const char > _msg )
142 : Exceptions::StaticInconsistency( loc ), msg( _msg )
145 Exceptions::ScannerError::~ScannerError( )
148 void
149 Exceptions::ScannerError::display( ostream & os ) const
151 os << "Scanner error: " << msg << std::endl ;
155 Exceptions::ParserError::ParserError( const Ast::SourceLocation & loc, RefCountPtr< const char > _msg )
156 : Exceptions::StaticInconsistency( loc ), msg( _msg )
159 Exceptions::ParserError::~ParserError( )
162 void
163 Exceptions::ParserError::display( ostream & os ) const
165 os << "Parser error: " << msg << std::endl ;
169 Exceptions::MemberAlsoAbstract::MemberAlsoAbstract( const Ast::SourceLocation & _memberLoc, const char * _id, const Ast::SourceLocation & _abstractLoc )
170 : Exceptions::StaticInconsistency( _memberLoc ), memberLoc( _memberLoc ), id( _id ), abstractLoc( _abstractLoc )
173 Exceptions::MemberAlsoAbstract::~MemberAlsoAbstract( )
176 void
177 Exceptions::MemberAlsoAbstract::display( ostream & os ) const
179 os << "The member " << id << " is also declared abstract, at " << abstractLoc << "." << std::endl ;
183 Exceptions::MemberAlreadyDeclared::MemberAlreadyDeclared( const Ast::SourceLocation & _memberLoc, const char * _id, const Ast::SourceLocation & _oldLoc )
184 : Exceptions::StaticInconsistency( _memberLoc ), memberLoc( _memberLoc ), id( _id ), oldLoc( _oldLoc )
187 Exceptions::MemberAlreadyDeclared::~MemberAlreadyDeclared( )
190 void
191 Exceptions::MemberAlreadyDeclared::display( ostream & os ) const
193 os << "The member " << id << " has already been declared, at " << oldLoc << "." << std::endl ;
197 Exceptions::PublicGetSetInNonfinalClass::PublicGetSetInNonfinalClass( const Ast::SourceLocation & _memberLoc, const char * _id )
198 : Exceptions::StaticInconsistency( _memberLoc ), memberLoc( _memberLoc ), id( _id )
201 Exceptions::PublicGetSetInNonfinalClass::~PublicGetSetInNonfinalClass( )
204 void
205 Exceptions::PublicGetSetInNonfinalClass::display( ostream & os ) const
207 os << "Only members of final classes may have the public get or set specifier. Member in question: " << id << "." << std::endl ;
211 Exceptions::TransformingMemberInNonfinalClass::TransformingMemberInNonfinalClass( const Ast::SourceLocation & _memberLoc, const char * _id )
212 : Exceptions::StaticInconsistency( _memberLoc ), memberLoc( _memberLoc ), id( _id )
215 Exceptions::TransformingMemberInNonfinalClass::~TransformingMemberInNonfinalClass( )
218 void
219 Exceptions::TransformingMemberInNonfinalClass::display( ostream & os ) const
221 os << "Only members of final classes may have the <transforming> specifier. Member in question: " << id << "." << std::endl ;
225 Exceptions::RepeatedFormal::RepeatedFormal( const Ast::SourceLocation & loc, const char * _id )
226 : Exceptions::StaticInconsistency( loc ), id( _id )
229 Exceptions::RepeatedFormal::~RepeatedFormal( )
232 void
233 Exceptions::RepeatedFormal::display( ostream & os ) const
235 os << "Repeated formal: " << id << std::endl ;
239 Exceptions::IllegalFreeStates::IllegalFreeStates( const Ast::SourceLocation & loc, Ast::StateIDSet * freeStates, const char * reason )
240 : Exceptions::StaticInconsistency( loc ), freeStates_( freeStates ), reason_( reason )
243 Exceptions::IllegalFreeStates::~IllegalFreeStates( )
246 void
247 Exceptions::IllegalFreeStates::display( ostream & os ) const
249 os << "Free states are illegal here (" << reason_ << "):" ;
250 typedef typeof *freeStates_ SetType;
251 for( SetType::const_iterator i = freeStates_->begin( ); i != freeStates_->end( ); ++i )
253 os << " " << *i ;
255 os << std::endl ;
259 Exceptions::FreeStateIsAlsoPassed::FreeStateIsAlsoPassed( const Ast::SourceLocation & loc, Ast::StateID stateID )
260 : Exceptions::StaticInconsistency( loc ), stateID_( stateID )
263 Exceptions::FreeStateIsAlsoPassed::~FreeStateIsAlsoPassed( )
266 void
267 Exceptions::FreeStateIsAlsoPassed::display( ostream & os ) const
269 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 ;
273 Exceptions::RepeatedStateArgument::RepeatedStateArgument( const Ast::SourceLocation & loc, const RefCountPtr< Ast::StateIDSet > & passedStates )
274 : Exceptions::StaticInconsistency( loc ), passedStates_( passedStates )
277 Exceptions::RepeatedStateArgument::~RepeatedStateArgument( )
280 void
281 Exceptions::RepeatedStateArgument::display( ostream & os ) const
283 os << "Some of these states are being passed in more than one state argument position:" ;
284 typedef typeof *passedStates_ SetType;
285 for( SetType::const_iterator i = passedStates_->begin( ); i != passedStates_->end( ); ++i )
287 os << " " << *i ;
289 os << std::endl ;
293 Exceptions::PassingStateOut::PassingStateOut( const Ast::SourceLocation & loc, const char * id )
294 : Exceptions::StaticInconsistency( loc ), id_( id )
297 Exceptions::PassingStateOut::~PassingStateOut( )
300 void
301 Exceptions::PassingStateOut::display( std::ostream & os ) const
303 os << "States may not be returned." << std::endl ;
307 Exceptions::IntroducingExisting::IntroducingExisting( const Ast::SourceLocation & _loc, const char * _id )
308 : Exceptions::StaticInconsistency( _loc ), loc( _loc ), id( _id )
311 Exceptions::IntroducingExisting::~IntroducingExisting( )
314 void
315 Exceptions::IntroducingExisting::display( std::ostream & os ) const
317 os << "The variable " << id << " is already introduced in this scope." << std::endl ;
321 Exceptions::ExpectedImmediate::ExpectedImmediate( const Ast::SourceLocation & _loc )
322 : Exceptions::StaticInconsistency( _loc ), loc( _loc )
325 Exceptions::ExpectedImmediate::~ExpectedImmediate( )
328 void
329 Exceptions::ExpectedImmediate::display( std::ostream & os ) const
331 os << "It makes no sense to put a pure expression before the end of a code bracket." << std::endl ;
335 Exceptions::IllegalImperative::IllegalImperative( const Ast::SourceLocation & _loc )
336 : Exceptions::StaticInconsistency( _loc ), loc( _loc )
339 Exceptions::IllegalImperative::~IllegalImperative( )
342 void
343 Exceptions::IllegalImperative::display( std::ostream & os ) const
345 os << "Imperative expressions are not allowed here." << std::endl ;
349 Exceptions::FreezingUndefined::FreezingUndefined( const Ast::SourceLocation & _loc, const char * _id )
350 : Exceptions::StaticInconsistency( _loc ), loc( _loc ), id( _id )
353 Exceptions::FreezingUndefined::~FreezingUndefined( )
356 void
357 Exceptions::FreezingUndefined::display( std::ostream & os ) const
359 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 ;
363 Exceptions::FileReadOpenError::FileReadOpenError( const Ast::SourceLocation & _loc, RefCountPtr< const char > _filename, const std::string * sourceDir, const std::list< std::string > * searchPath, Type _type )
364 : loc( _loc ), filename( _filename ), type( _type ), sourceDir_( sourceDir ), searchPath_( searchPath )
367 Exceptions::FileReadOpenError::~FileReadOpenError( )
370 void
371 Exceptions::FileReadOpenError::display( std::ostream & os ) const
373 switch( type )
375 case OPEN:
376 os << loc << locsep << "Could not open file: " << filename ;
377 break;
378 case STAT:
379 os << loc << locsep << "Could not stat() file: " << filename ;
380 break;
381 default:
382 os << loc << locsep << "Internal error when displaying FileReadOpenError on file: " << filename ;
384 if( searchPath_ != 0 )
386 os << " searching \"" ;
387 typedef typeof *searchPath_ ListType;
388 for( ListType::const_iterator i = searchPath_->begin( ); i != searchPath_->end( ); ++i )
390 if( i != searchPath_->begin( ) )
392 os << ":" ;
394 if( sourceDir_ != 0 && (*i)[0] != '/' )
396 os << *sourceDir_ ;
398 os << *i ;
400 os << "\"" ;
402 os << std::endl ;
406 Exceptions::FileWriteOpenError::FileWriteOpenError( const Ast::SourceLocation & _loc, RefCountPtr< const char > _filename, const char * purpose )
407 : loc( _loc ), filename( _filename ), purpose_( purpose )
410 Exceptions::FileWriteOpenError::~FileWriteOpenError( )
413 void
414 Exceptions::FileWriteOpenError::display( std::ostream & os ) const
416 os << loc << locsep << "Could not open " ;
417 if( purpose_ != 0 )
419 os << purpose_ ;
421 os << " file for write: " << filename ;
422 os << std::endl ;
426 Exceptions::TeXSetupTooLate::TeXSetupTooLate( const Ast::SourceLocation & _loc )
427 : loc( _loc )
430 Exceptions::TeXSetupTooLate::~TeXSetupTooLate( )
433 void
434 Exceptions::TeXSetupTooLate::display( std::ostream & os ) const
436 os << loc << locsep << "It is too late to make modifications to the TeX context." << std::endl ;
440 Exceptions::EmptyFinalPicture::EmptyFinalPicture( )
443 Exceptions::EmptyFinalPicture::~EmptyFinalPicture( )
446 void
447 Exceptions::EmptyFinalPicture::display( std::ostream & os ) const
449 os << "Nothing was ever put in the global #" << Lang::CATALOG_ID << " or drawn to the global #" << Lang::CANVAS_ID << "." << std::endl ;
453 Exceptions::TeXSetupHasChanged::TeXSetupHasChanged( )
454 : Shapes::Exceptions::InternalError( "The TeX context check failed while loading fresh labels." )
457 Exceptions::TeXSetupHasChanged::~TeXSetupHasChanged( )
461 Exceptions::TypeMismatch::TypeMismatch( const Ast::SourceLocation & loc, RefCountPtr< const char > _valueType, RefCountPtr< const char > _expectedType )
462 : Exceptions::RuntimeError( loc ), hint_( 0 ), valueType( _valueType ), expectedType( _expectedType )
465 Exceptions::TypeMismatch::TypeMismatch( const Ast::SourceLocation & loc, const char * hint, RefCountPtr< const char > _valueType, RefCountPtr< const char > _expectedType )
466 : Exceptions::RuntimeError( loc ), hint_( hint ), valueType( _valueType ), expectedType( _expectedType )
469 Exceptions::TypeMismatch::~TypeMismatch( )
472 void
473 Exceptions::TypeMismatch::display( std::ostream & os ) const
475 if( hint_ != 0 )
477 os << hint_ << ": " ;
479 os << "Expected a " << expectedType << ", got a " << valueType << "." << std::endl ;
482 Exceptions::PDFVersionError::PDFVersionError( SimplePDF::PDF_Version::Version version, SimplePDF::PDF_Version::Version required, const RefCountPtr< const char > & msg )
483 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), version_( version ), required_( required ), msgMem_( msg ), msg_( msgMem_.getPtr( ) )
486 Exceptions::PDFVersionError::PDFVersionError( SimplePDF::PDF_Version::Version version, SimplePDF::PDF_Version::Version required, const char * msg )
487 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), version_( version ), required_( required ), msgMem_( NullPtr< const char >( ) ), msg_( msg )
490 Exceptions::PDFVersionError::~PDFVersionError( )
493 void
494 Exceptions::PDFVersionError::display( std::ostream & os ) const
496 os << SimplePDF::PDF_Version::toString( required_ ) << " error: " << msg_ << std::endl ;
499 RefCountPtr< const Lang::Exception >
500 Exceptions::PDFVersionError::clone( const Kernel::ContRef & cont ) const
502 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "PDF_version" ) );
503 std::ostringstream os;
504 display( os );
505 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
506 kind,
507 RefCountPtr< const Lang::String >( new Lang::String( "(core PDF backend)", true ) ),
508 Lang::THE_VOID,
509 strrefdup( os ),
510 cont,
511 this->exitCode( ) ) );
515 Exceptions::RedefiningLexical::RedefiningLexical( const char * _id )
516 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), id( _id )
519 Exceptions::RedefiningLexical::~RedefiningLexical( )
522 void
523 Exceptions::RedefiningLexical::display( std::ostream & os ) const
525 os << "Redefining " << id << std::endl ;
529 Exceptions::RedefiningDynamic::RedefiningDynamic( const char * _id )
530 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), id( _id )
533 Exceptions::RedefiningDynamic::~RedefiningDynamic( )
536 void
537 Exceptions::RedefiningDynamic::display( std::ostream & os ) const
539 os << "Redefining " << "@" << id << std::endl ;
543 Exceptions::NonObjectMemberAssignment::NonObjectMemberAssignment( const Ast::SourceLocation & _loc, RefCountPtr< const char > _valueType )
544 : Exceptions::RuntimeError( _loc ), valueType( _valueType )
547 Exceptions::NonObjectMemberAssignment::~NonObjectMemberAssignment( )
550 void
551 Exceptions::NonObjectMemberAssignment::display( std::ostream & os ) const
553 os << "Only object oriented values have fields that can be assigned. This value is of type " << valueType << "." << std::endl ;
557 Exceptions::ElementaryWithout::ElementaryWithout( Kind kind, Ref ref, RefCountPtr< const char > _valueType )
558 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), ref_( ref ), valueType( _valueType )
561 Exceptions::ElementaryWithout::~ElementaryWithout( )
564 void
565 Exceptions::ElementaryWithout::display( std::ostream & os ) const
567 os << "This " ;
568 switch( kind_ )
570 case VALUE:
571 os << "value" ;
572 break;
573 case STATE:
574 os << "state" ;
575 break;
577 os << " is of the elementary type " << valueType << ", which has no " ;
578 switch( ref_ )
580 case FIELD:
581 os << "fields" ;
582 break;
583 case MUTATOR:
584 os << "mutators" ;
585 break;
587 os << "." << std::endl ;
591 Exceptions::NonExistentPosition::NonExistentPosition( size_t pos, size_t maxPos )
592 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), pos_( pos ), maxPos_( maxPos )
595 Exceptions::NonExistentPosition::~NonExistentPosition( )
598 void
599 Exceptions::NonExistentPosition::display( std::ostream & os ) const
601 os << "Referencing field at position " << pos_ << " is an error since the user struct has only " << maxPos_ << " ordered fields." << std::endl ;
605 Exceptions::UnaryPrefixNotApplicable::UnaryPrefixNotApplicable( const Ast::SourceLocation & _loc, const Ast::Expression * _expr, RefCountPtr< const char > _valueType )
606 : Exceptions::RuntimeError( _loc ), expr( _expr ), valueType( _valueType ), operatorSymbol( "< ? >" )
609 Exceptions::UnaryPrefixNotApplicable::~UnaryPrefixNotApplicable( )
612 void
613 Exceptions::UnaryPrefixNotApplicable::setOperatorSymbol( const char * _operatorSymbol )
615 operatorSymbol = _operatorSymbol;
618 void
619 Exceptions::UnaryPrefixNotApplicable::display( std::ostream & os ) const
621 if( expr != 0 )
623 os << "Operator " ;
624 getLoc( ).copy( & os );
625 os << " not defined for " << valueType << " at " << expr->loc( ) << "." << std::endl ;
627 else
629 os << "Operator " << operatorSymbol << " not defined for " << valueType << "." << std::endl ;
634 Exceptions::UnaryPostfixNotApplicable::UnaryPostfixNotApplicable( const Ast::SourceLocation & _loc, const Ast::Expression * _expr, RefCountPtr< const char > _valueType )
635 : Exceptions::RuntimeError( _loc ), expr( _expr ), valueType( _valueType ), operatorSymbol( "< ? >" )
638 Exceptions::UnaryPostfixNotApplicable::~UnaryPostfixNotApplicable( )
641 void
642 Exceptions::UnaryPostfixNotApplicable::setOperatorSymbol( const char * _operatorSymbol )
644 operatorSymbol = _operatorSymbol;
647 void
648 Exceptions::UnaryPostfixNotApplicable::display( std::ostream & os ) const
650 if( expr != 0 )
652 os << "Operator " ;
653 getLoc( ).copy( & os );
654 os << " not defined for " << valueType << " at " << expr->loc( ) << "." << std::endl ;
656 else
658 os << "Operator " << operatorSymbol << " not defined for " << valueType << "." << std::endl ;
663 Exceptions::BinaryInfixNotApplicable::BinaryInfixNotApplicable( const Ast::SourceLocation & _loc, const Ast::Expression * _expr1, RefCountPtr< const char > _valueType1, const Ast::Expression * _expr2, RefCountPtr< const char > _valueType2 )
664 : Exceptions::RuntimeError( _loc ), expr1( _expr1 ), valueType1( _valueType1 ), expr2( _expr2 ), valueType2( _valueType2 ), operatorSymbol( "< ? >" )
667 Exceptions::BinaryInfixNotApplicable::~BinaryInfixNotApplicable( )
670 void
671 Exceptions::BinaryInfixNotApplicable::setOperatorSymbol( const char * _operatorSymbol )
673 operatorSymbol = _operatorSymbol;
676 void
677 Exceptions::BinaryInfixNotApplicable::display( std::ostream & os ) const
679 if( expr1 != 0 && expr2 != 0 )
681 os << "Operator " ;
682 getLoc( ).copy( & os );
683 os << " not defined for (" << valueType1 << "," << valueType2 << ") at " << expr1->loc( ) << ", " << expr2->loc( ) << "." << std::endl ;
685 else
687 os << "Operator " << operatorSymbol << " not defined for (" << valueType1 << "," << valueType2 << ")." << std::endl ;
692 Exceptions::LookupUnknown::LookupUnknown( const Ast::SourceLocation & _loc, RefCountPtr< const char > _id, Type type )
693 : Exceptions::StaticInconsistency( _loc ), id( _id ), type_( type )
696 Exceptions::LookupUnknown::~LookupUnknown( )
699 void
700 Exceptions::LookupUnknown::display( std::ostream & os ) const
702 switch( type_ )
704 case VARIABLE:
705 os << "The variable " << id << " is unbound." << std::endl ;
706 break;
707 case STATE:
708 os << "There is no state called " << id << " around." << std::endl ;
709 break;
710 case DYNAMIC_VARIABLE:
711 os << "There is no dynamic variable called " << id << " around." << std::endl ;
712 break;
713 case DYNAMIC_STATE:
714 os << "There is no dynamic state called " << id << " around." << std::endl ;
715 break;
716 case TYPE:
717 os << "There is no type called " << id << " around." << std::endl ;
718 break;
719 default:
720 os << "<?ERROR?" ;
725 Exceptions::StateBeyondFunctionBoundary::StateBeyondFunctionBoundary( const Ast::SourceLocation & _loc, RefCountPtr< const char > _id )
726 : Exceptions::StaticInconsistency( _loc ), id( _id )
729 Exceptions::StateBeyondFunctionBoundary::~StateBeyondFunctionBoundary( )
732 void
733 Exceptions::StateBeyondFunctionBoundary::display( std::ostream & os ) const
735 os << "The state " << id << " resides outside a function boundary." << std::endl ;
739 Exceptions::IntroducingExistingUnit::IntroducingExistingUnit( const Ast::SourceLocation & _loc, RefCountPtr< const char > _id )
740 : Exceptions::StaticInconsistency( _loc ), id( _id )
743 Exceptions::IntroducingExistingUnit::~IntroducingExistingUnit( )
746 void
747 Exceptions::IntroducingExistingUnit::display( std::ostream & os ) const
749 os << "Inconsistent definition of the existing unit " << id << "." << std::endl ;
753 Exceptions::LookupUnknownUnit::LookupUnknownUnit( const Ast::SourceLocation & _loc, RefCountPtr< const char > _id )
754 : Exceptions::StaticInconsistency( _loc ), id( _id )
757 Exceptions::LookupUnknownUnit::~LookupUnknownUnit( )
760 void
761 Exceptions::LookupUnknownUnit::display( std::ostream & os ) const
763 os << "The unit " << id << " is unbound" << std::endl ;
767 Exceptions::OutOfRange::OutOfRange( RefCountPtr< const char > msg )
768 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg )
771 Exceptions::OutOfRange::OutOfRange( const char * msg )
772 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
775 Exceptions::OutOfRange::OutOfRange( const Ast::SourceLocation & _loc, RefCountPtr< const char > msg )
776 : Exceptions::CatchableError( _loc ), msg_( msg.getPtr( ) ), msgMem_( msg )
779 Exceptions::OutOfRange::OutOfRange( const Ast::SourceLocation & _loc, const char * msg )
780 : Exceptions::CatchableError( _loc ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
783 Exceptions::OutOfRange::~OutOfRange( )
786 void
787 Exceptions::OutOfRange::display( std::ostream & os ) const
789 os << "Out-of-range error: " << msg_ << std::endl ;
792 RefCountPtr< const Lang::Exception >
793 Exceptions::OutOfRange::clone( const Kernel::ContRef & cont ) const
795 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "out_of_range" ) );
796 std::ostringstream os;
797 display( os );
798 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
799 kind,
800 RefCountPtr< const Lang::String >( new Lang::String( "(core, generic)", true ) ),
801 Lang::THE_VOID,
802 strrefdup( os ),
803 cont,
804 this->exitCode( ) ) );
808 Exceptions::NonVoidStatement::NonVoidStatement( const Ast::SourceLocation & loc, RefCountPtr< const Lang::Value > val )
809 : Exceptions::RuntimeError( loc ), val_( val )
812 Exceptions::NonVoidStatement::~NonVoidStatement( )
815 void
816 Exceptions::NonVoidStatement::display( std::ostream & os ) const
818 os << "No implicit ignore of non-void value (of type " << val_->getTypeName( ) << ")" << std::endl ;
821 // Exceptions::RuntimeError::RuntimeError( )
822 // : loc_( "< unlocated runtime error >" )
823 // { }
825 Exceptions::RuntimeError::~RuntimeError( )
828 Exceptions::RuntimeError::RuntimeError( const Ast::SourceLocation & loc )
829 : loc_( loc )
832 Exceptions::RuntimeError::RuntimeError( Ast::Expression * expr )
833 : loc_( expr->loc( ) )
836 const Ast::SourceLocation &
837 Exceptions::RuntimeError::getLoc( ) const
839 return loc_;
843 Exceptions::CatchableError::CatchableError( const Ast::SourceLocation & loc )
844 : Exceptions::RuntimeError( loc )
847 Exceptions::CatchableError::CatchableError( Ast::Expression * expr )
848 : Exceptions::RuntimeError( expr )
851 Exceptions::CatchableError::~CatchableError( )
855 Exceptions::UncaughtError::UncaughtError( const RefCountPtr< const Lang::Exception > & ball )
856 : Exceptions::RuntimeError( ball->loc( ) ), ball_( ball )
859 Exceptions::UncaughtError::~UncaughtError( )
862 void
863 Exceptions::UncaughtError::display( std::ostream & os ) const
865 os << "Uncaught error: " ;
866 ball_->show( os );
867 os << std::endl ;
870 Interaction::ExitCode
871 Exceptions::UncaughtError::exitCode( ) const
873 return ball_->exitCode( );
877 Exceptions::UserError::UserError( const RefCountPtr< const Lang::Symbol > & kind, const RefCountPtr< const Lang::String > & source, const RefCountPtr< const Lang::Value > & details, const RefCountPtr< const char > & message )
878 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), source_( source ), details_( details ), message_( message )
881 Exceptions::UserError::~UserError( )
884 void
885 Exceptions::UserError::display( ostream & os ) const
887 os << "'" ;
888 kind_->show( os );
889 os << " error in " << source_->val_ << ": " << message_ << std::endl ;
892 RefCountPtr< const Lang::Exception >
893 Exceptions::UserError::clone( const Kernel::ContRef & cont ) const
895 std::ostringstream os;
896 display( os );
897 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
898 kind_,
899 source_,
900 details_,
901 strrefdup( os ),
902 cont,
903 this->exitCode( ) ) );
907 Exceptions::UserOutOfRange::UserOutOfRange( const RefCountPtr< const Lang::Symbol > & kind, const RefCountPtr< const Lang::String > & source, const RefCountPtr< const Lang::Integer > & details, const RefCountPtr< const char > & message )
908 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), source_( source ), details_( details ), message_( message )
911 Exceptions::UserOutOfRange::~UserOutOfRange( )
914 void
915 Exceptions::UserOutOfRange::display( ostream & os ) const
917 os << "In " << source_->val_ << ", argument " << details_->val_
918 << ", out-of-range: " << message_ << std::endl ;
921 RefCountPtr< const Lang::Exception >
922 Exceptions::UserOutOfRange::clone( const Kernel::ContRef & cont ) const
924 std::ostringstream os;
925 display( os );
926 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
927 kind_,
928 source_,
929 details_,
930 strrefdup( os ),
931 cont,
932 this->exitCode( ) ) );
936 Exceptions::UserTypeMismatch::UserTypeMismatch( const RefCountPtr< const Lang::Symbol > & kind, const RefCountPtr< const Lang::String > & source, const RefCountPtr< const Lang::Integer > & details, const RefCountPtr< const char > & expectedType, const RefCountPtr< const char > & valueType )
937 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), source_( source ), details_( details ), expectedType_( expectedType ), valueType_( valueType )
940 Exceptions::UserTypeMismatch::~UserTypeMismatch( )
943 void
944 Exceptions::UserTypeMismatch::display( ostream & os ) const
946 os << "In " << source_->val_ << ", argument " << details_->val_
947 << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
950 RefCountPtr< const Lang::Exception >
951 Exceptions::UserTypeMismatch::clone( const Kernel::ContRef & cont ) const
953 std::ostringstream os;
954 display( os );
955 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
956 kind_,
957 source_,
958 details_,
959 strrefdup( os ),
960 cont,
961 this->exitCode( ) ) );
965 Exceptions::InternalError::InternalError( const Ast::SourceLocation & loc, RefCountPtr< const char > msg )
966 : Exceptions::RuntimeError( loc ), msg_( msg.getPtr( ) ), msgMem_( msg )
969 Exceptions::InternalError::InternalError( const Ast::SourceLocation & loc, const char * msg )
970 : Exceptions::RuntimeError( loc ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
973 Exceptions::InternalError::InternalError( RefCountPtr< const char > msg )
974 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg )
977 Exceptions::InternalError::InternalError( const char * msg )
978 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
981 Exceptions::InternalError::InternalError( const std::ostringstream & msg )
982 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( strdup( msg.str( ).c_str( ) ) ), msgMem_( msg_ )
985 Exceptions::InternalError::~InternalError( )
988 void
989 Exceptions::InternalError::display( ostream & os ) const
991 os << "Internal error: " << msg_ << std::endl ;
995 Exceptions::ExternalError::ExternalError( RefCountPtr< const char > msg )
996 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg )
999 Exceptions::ExternalError::ExternalError( const char * msg )
1000 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
1003 Exceptions::ExternalError::~ExternalError( )
1006 void
1007 Exceptions::ExternalError::display( ostream & os ) const
1009 os << "External error: " << msg_ << std::endl ;
1012 RefCountPtr< const Lang::Exception >
1013 Exceptions::ExternalError::clone( const Kernel::ContRef & cont ) const
1015 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "external" ) );
1016 std::ostringstream os;
1017 display( os );
1018 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1019 kind,
1020 RefCountPtr< const Lang::String >( new Lang::String( "(external error)", true ) ),
1021 Lang::THE_VOID,
1022 strrefdup( os ),
1023 cont,
1024 this->exitCode( ) ) );
1027 Exceptions::ExternalError *
1028 Exceptions::ExternalError::cloneTyped( ) const
1030 return new Exceptions::ExternalError( msgMem_ );
1033 Exceptions::UserArityMismatch::UserArityMismatch( const Ast::SourceLocation _formalsLoc, size_t _functionArity, size_t _callArity, Type type )
1034 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc( _formalsLoc ), functionArity( _functionArity ), callArity( _callArity ), type_( type )
1037 Exceptions::UserArityMismatch::~UserArityMismatch( )
1040 void
1041 Exceptions::UserArityMismatch::display( std::ostream & os ) const
1043 os << "Function with formals at " << formalsLoc << " expects " << functionArity ;
1044 switch( type_ )
1046 case VARIABLE:
1047 os << " value arguments" ;
1048 break;
1049 case STATE:
1050 os << " state arguments" ;
1051 break;
1052 default:
1053 os << " ?ERROR?" ;
1055 os << ", not " << callArity << std::endl ;
1058 Exceptions::SinkRequired::SinkRequired( const Ast::SourceLocation formalsLoc, size_t formalsArity, size_t callArity )
1059 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc_( formalsLoc ), formalsArity_( formalsArity ), callArity_( callArity )
1062 Exceptions::SinkRequired::~SinkRequired( )
1065 void
1066 Exceptions::SinkRequired::display( std::ostream & os ) const
1068 os << "Formals at " << formalsLoc_ << " contains no sink, so passing " << callArity_ << " ordered arguments is " << callArity_ - formalsArity_ << " too many." << std::endl ;
1072 Exceptions::NamedFormalMismatch::NamedFormalMismatch( const Ast::SourceLocation _formalsLoc, RefCountPtr< const char > _name, Exceptions::NamedFormalMismatch::Type type )
1073 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc( _formalsLoc ), name( _name ), type_( type )
1076 Exceptions::NamedFormalMismatch::~NamedFormalMismatch( )
1079 void
1080 Exceptions::NamedFormalMismatch::display( std::ostream & os ) const
1082 os << "Function with formals at " << formalsLoc << " has no named ";
1083 switch( type_ )
1085 case VARIABLE:
1086 os << "variable" ;
1087 break;
1088 case STATE:
1089 os << "state" ;
1090 break;
1091 default:
1092 os << "<?ERROR?" ;
1094 os << " called " << name << "." << std::endl ;
1098 Exceptions::NamedFormalAlreadySpecified::NamedFormalAlreadySpecified( const Ast::SourceLocation _formalsLoc, RefCountPtr< const char > _name, size_t _pos, Exceptions::NamedFormalAlreadySpecified::Type type )
1099 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc( _formalsLoc ), name( _name ), pos( _pos ), type_( type )
1102 Exceptions::NamedFormalAlreadySpecified::~NamedFormalAlreadySpecified( )
1105 void
1106 Exceptions::NamedFormalAlreadySpecified::display( std::ostream & os ) const
1108 os << "The formal " ;
1109 switch( type_ )
1111 case VARIABLE:
1112 os << "variable" ;
1113 break;
1114 case STATE:
1115 os << "state" ;
1116 break;
1117 default:
1118 os << "<?ERROR?" ;
1120 os << " named " << name << ", defined at " << formalsLoc << " is already defined by order, at position " << pos << "." << std::endl ;
1123 Exceptions::MissingArguments::MissingArguments( const Ast::SourceLocation formalsLoc, std::map< size_t, RefCountPtr< const char > > * missingVariables, std::map< size_t, RefCountPtr< const char > > * missingStates )
1124 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc_( formalsLoc ), missingVariables_( missingVariables ), missingStates_( missingStates )
1127 Exceptions::MissingArguments::~MissingArguments( )
1130 void
1131 Exceptions::MissingArguments::display( std::ostream & os ) const
1133 os << "Among the formals at " << formalsLoc_ ;
1134 if( missingVariables_ != NullPtr< typeof *missingVariables_ >( ) )
1136 os << ", the following variables are missing:" ;
1137 typedef typeof *missingVariables_ MapType;
1138 for( MapType::const_iterator i = missingVariables_->begin( ); i != missingVariables_->end( ); ++i )
1140 if( i != missingVariables_->begin( ) )
1142 os << "," ;
1144 os << " (" << i->first << ")" << i->second.getPtr( ) ;
1147 if( missingStates_ != NullPtr< typeof *missingStates_ >( ) )
1149 os << ", " ;
1150 if( missingVariables_ != NullPtr< typeof *missingVariables_ >( ) )
1152 os << "and " ;
1154 os << "the following states are missing:" ;
1155 typedef typeof *missingStates_ MapType;
1156 for( MapType::const_iterator i = missingStates_->begin( ); i != missingStates_->end( ); ++i )
1158 if( i != missingStates_->begin( ) )
1160 os << "," ;
1162 os << " (" << i->first << ")" << i->second.getPtr( ) ;
1165 os << "." << std::endl ;
1169 Exceptions::CoreArityMismatch::CoreArityMismatch( const char * _title, size_t _functionArity, size_t _callArity )
1170 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title ), titleMem( NullPtr< const char >( ) ), functionArityLow( _functionArity ), functionArityHigh( _functionArity ), callArity( _callArity )
1173 Exceptions::CoreArityMismatch::CoreArityMismatch( const char * _title, size_t _functionArityLow, size_t _functionArityHigh, size_t _callArity )
1174 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title ), titleMem( NullPtr< const char >( ) ), functionArityLow( _functionArityLow ), functionArityHigh( _functionArityHigh ), callArity( _callArity )
1177 Exceptions::CoreArityMismatch::CoreArityMismatch( const RefCountPtr< const char > & _title, size_t _functionArity, size_t _callArity )
1178 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title.getPtr( ) ), titleMem( _title ), functionArityLow( _functionArity ), functionArityHigh( _functionArity ), callArity( _callArity )
1181 Exceptions::CoreArityMismatch::CoreArityMismatch( const RefCountPtr< const char > & _title, size_t _functionArityLow, size_t _functionArityHigh, size_t _callArity )
1182 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title.getPtr( ) ), titleMem( _title ), functionArityLow( _functionArityLow ), functionArityHigh( _functionArityHigh ), callArity( _callArity )
1185 Exceptions::CoreArityMismatch::~CoreArityMismatch( )
1188 void
1189 Exceptions::CoreArityMismatch::display( std::ostream & os ) const
1191 if( functionArityLow == functionArityHigh )
1193 os << "Core function " << title << " expects " << functionArityLow << " arguments, not " << callArity << std::endl ;
1195 else
1197 os << "Core function " << title << " expects [" << functionArityLow << ", " << functionArityHigh << "] arguments, not " << callArity << std::endl ;
1202 Exceptions::CoreNoNamedFormals::CoreNoNamedFormals( const char * _title )
1203 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title ), titleMem( NullPtr< const char >( ) )
1206 Exceptions::CoreNoNamedFormals::CoreNoNamedFormals( const RefCountPtr< const char > & _title )
1207 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title.getPtr( ) ), titleMem( _title )
1210 Exceptions::CoreNoNamedFormals::~CoreNoNamedFormals( )
1213 void
1214 Exceptions::CoreNoNamedFormals::display( std::ostream & os ) const
1216 os << "Core function " << title << " does not accept named arguments." << std::endl ;
1220 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1221 const char * title,
1222 const Ast::SourceLocation & argLoc,
1223 RefCountPtr< const char > valueType,
1224 RefCountPtr< const char > expectedType )
1225 : Exceptions::RuntimeError( callLoc ),
1226 title_( title ),
1227 titleMem_( NullPtr< const char >( ) ),
1228 argLoc_( argLoc ),
1229 valueType_( valueType ),
1230 expectedType_( expectedType )
1233 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1234 RefCountPtr< const char > title,
1235 const Ast::SourceLocation & argLoc,
1236 RefCountPtr< const char > valueType,
1237 RefCountPtr< const char > expectedType )
1238 : Exceptions::RuntimeError( callLoc ),
1239 title_( title.getPtr( ) ),
1240 titleMem_( title ),
1241 argLoc_( argLoc ),
1242 valueType_( valueType ),
1243 expectedType_( expectedType )
1246 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1247 const char * title,
1248 Kernel::Arguments & args,
1249 size_t argNo,
1250 RefCountPtr< const char > expectedType )
1251 : Exceptions::RuntimeError( callLoc ),
1252 title_( title ),
1253 titleMem_( NullPtr< const char >( ) ),
1254 argLoc_( args.getLoc( argNo ) ),
1255 valueType_( args.getValue( argNo )->getTypeName( ) ),
1256 expectedType_( expectedType )
1259 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1260 RefCountPtr< const char > title,
1261 Kernel::Arguments & args,
1262 size_t argNo,
1263 RefCountPtr< const char > expectedType )
1264 : Exceptions::RuntimeError( callLoc ),
1265 title_( title.getPtr( ) ),
1266 titleMem_( title ),
1267 argLoc_( args.getLoc( argNo ) ),
1268 valueType_( args.getValue( argNo )->getTypeName( ) ),
1269 expectedType_( expectedType )
1272 Exceptions::CoreTypeMismatch::~CoreTypeMismatch( )
1275 void
1276 Exceptions::CoreTypeMismatch::display( std::ostream & os ) const
1278 os << "Core function " << title_ << ", argument ";
1279 // if( argName_ != 0 )
1280 // {
1281 // os << "\"" << argName_ << "\" " ;
1282 // }
1283 os << "at " << argLoc_ << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1287 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1288 const char * title,
1289 const Ast::SourceLocation & argLoc,
1290 RefCountPtr< const char > valueType,
1291 RefCountPtr< const char > expectedType )
1292 : Exceptions::RuntimeError( callLoc ),
1293 title_( title ),
1294 titleMem_( NullPtr< const char >( ) ),
1295 argLoc_( argLoc ),
1296 valueType_( valueType ),
1297 expectedType_( expectedType )
1300 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1301 RefCountPtr< const char > title,
1302 const Ast::SourceLocation & argLoc,
1303 RefCountPtr< const char > valueType,
1304 RefCountPtr< const char > expectedType )
1305 : Exceptions::RuntimeError( callLoc ),
1306 title_( title.getPtr( ) ),
1307 titleMem_( title ),
1308 argLoc_( argLoc ),
1309 valueType_( valueType ),
1310 expectedType_( expectedType )
1313 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1314 const char * title,
1315 Kernel::Arguments & args,
1316 size_t argNo,
1317 RefCountPtr< const char > expectedType )
1318 : Exceptions::RuntimeError( callLoc ),
1319 title_( title ),
1320 titleMem_( NullPtr< const char >( ) ),
1321 argLoc_( args.getStateLoc( argNo ) ),
1322 valueType_( args.getState( argNo )->getTypeName( ) ),
1323 expectedType_( expectedType )
1326 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1327 RefCountPtr< const char > title,
1328 Kernel::Arguments & args,
1329 size_t argNo,
1330 RefCountPtr< const char > expectedType )
1331 : Exceptions::RuntimeError( callLoc ),
1332 title_( title.getPtr( ) ),
1333 titleMem_( title ),
1334 argLoc_( args.getStateLoc( argNo ) ),
1335 valueType_( args.getState( argNo )->getTypeName( ) ),
1336 expectedType_( expectedType )
1339 Exceptions::CoreStateTypeMismatch::~CoreStateTypeMismatch( )
1342 void
1343 Exceptions::CoreStateTypeMismatch::display( std::ostream & os ) const
1345 os << "Core function " << title_ << ", state ";
1346 // if( argName_ != 0 )
1347 // {
1348 // os << "\"" << argName_ << "\" " ;
1349 // }
1350 os << "at " << argLoc_ << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1354 Exceptions::CoreDynamicTypeMismatch::CoreDynamicTypeMismatch( const Ast::SourceLocation & callLoc,
1355 const char * title,
1356 const char * id,
1357 RefCountPtr< const char > valueType,
1358 RefCountPtr< const char > expectedType )
1359 : Exceptions::RuntimeError( callLoc ),
1360 title_( title ),
1361 titleMem_( NullPtr< const char >( ) ),
1362 id_( id ),
1363 idMem_( NullPtr< const char >( ) ),
1364 valueType_( valueType ),
1365 expectedType_( expectedType )
1368 Exceptions::CoreDynamicTypeMismatch::~CoreDynamicTypeMismatch( )
1371 void
1372 Exceptions::CoreDynamicTypeMismatch::display( std::ostream & os ) const
1374 os << "Core function " << title_ << " encountered a type mismatch in the dynamic variable @" << id_
1375 << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1378 Exceptions::ContinuationTypeMismatch::ContinuationTypeMismatch( const Kernel::Continuation * locationCont,
1379 RefCountPtr< const char > valueType,
1380 RefCountPtr< const char > expectedType )
1381 : Exceptions::RuntimeError( locationCont->traceLoc( ) ),
1382 valueType_( valueType ),
1383 expectedType_( expectedType )
1386 Exceptions::ContinuationTypeMismatch::~ContinuationTypeMismatch( )
1389 void
1390 Exceptions::ContinuationTypeMismatch::display( std::ostream & os ) const
1392 os << "The continuation expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1396 Exceptions::CoreOutOfRange::CoreOutOfRange( const char * title, Kernel::Arguments & args, size_t argNo, RefCountPtr< const char > msg )
1397 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), title_( title ), argNo_( argNo ), argLoc_( args.getLoc( argNo ) ), msg_( msg.getPtr( ) ), msgMem_( msg )
1400 Exceptions::CoreOutOfRange::CoreOutOfRange( const char * title, Kernel::Arguments & args, size_t argNo, const char * msg )
1401 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), title_( title ), argNo_( argNo ), argLoc_( args.getLoc( argNo ) ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
1404 Exceptions::CoreOutOfRange::~CoreOutOfRange( )
1407 void
1408 Exceptions::CoreOutOfRange::display( std::ostream & os ) const
1410 os << "Core function " << title_ << ": " ;
1411 os << "Argument at " << argLoc_ << " is out of range; " << msg_ << std::endl ;
1414 RefCountPtr< const Lang::Exception >
1415 Exceptions::CoreOutOfRange::clone( const Kernel::ContRef & cont ) const
1417 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "out_of_range" ) );
1418 std::ostringstream os;
1419 display( os );
1420 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1421 kind,
1422 RefCountPtr< const Lang::String >( new Lang::String( title_, true ) ),
1423 RefCountPtr< const Lang::Integer >( new Lang::Integer( argNo_ ) ),
1424 strrefdup( os ),
1425 cont,
1426 this->exitCode( ) ) );
1429 Exceptions::CoreRequirement::CoreRequirement( RefCountPtr< const char > msg, const char * title, const Ast::SourceLocation & callLoc )
1430 : Exceptions::CatchableError( callLoc ), title_( title ), msg_( msg.getPtr( ) ), msgMem_( msg )
1433 Exceptions::CoreRequirement::CoreRequirement( const char * msg, const char * title, const Ast::SourceLocation & callLoc )
1434 : Exceptions::CatchableError( callLoc ), title_( title ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
1437 Exceptions::CoreRequirement::~CoreRequirement( )
1440 void
1441 Exceptions::CoreRequirement::display( std::ostream & os ) const
1443 os << "Core function " << title_ << ": " << msg_ << std::endl ;
1446 RefCountPtr< const Lang::Exception >
1447 Exceptions::CoreRequirement::clone( const Kernel::ContRef & cont ) const
1449 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
1450 std::ostringstream os;
1451 display( os );
1452 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1453 kind,
1454 RefCountPtr< const Lang::String >( new Lang::String( title_, true ) ),
1455 Lang::THE_VOID,
1456 strrefdup( os ),
1457 cont,
1458 this->exitCode( ) ) );
1462 Exceptions::TeXLabelError::TeXLabelError( bool quoted, const char * region, RefCountPtr< const char > summary, RefCountPtr< const char > details, const Ast::SourceLocation & loc )
1463 : Exceptions::RuntimeError( loc ), strLoc_( loc ), quoted_( quoted ), region_( region ), summary_( summary ), details_( details )
1466 Exceptions::TeXLabelError::~TeXLabelError( )
1469 void
1470 Exceptions::TeXLabelError::display( ostream & os ) const
1472 if( quoted_ )
1474 os << "TeX error in " << region_ ;
1476 else
1478 os << "Error in TeX " << region_ ;
1480 if( ! strLoc_.isUnknown( ) )
1482 os << " at " << strLoc_ ;
1484 os << ": " ;
1485 if( quoted_ )
1487 os << "\"" ;
1489 os << summary_ ;
1490 if( quoted_ )
1492 os << "\"" ;
1494 os << std::endl ;
1495 if( details_ != NullPtr< const char >( ) )
1497 Exceptions::prefixEachLine( additionalLinesPrefix, details_, os );
1502 Exceptions::StaticTeXLabelError::StaticTeXLabelError( bool quoted, const char * region, RefCountPtr< const char > summary, RefCountPtr< const char > details, const Ast::SourceLocation & loc )
1503 : Exceptions::StaticInconsistency( loc ), quoted_( quoted ), region_( region ), summary_( summary ), details_( details )
1506 Exceptions::StaticTeXLabelError::~StaticTeXLabelError( )
1509 void
1510 Exceptions::StaticTeXLabelError::display( ostream & os ) const
1512 if( quoted_ )
1514 os << "TeX error in " << region_ ;
1516 else
1518 os << "Error in TeX " << region_ ;
1520 os << ": " ;
1521 if( quoted_ )
1523 os << "\"" ;
1525 os << summary_ ;
1526 if( quoted_ )
1528 os << "\"" ;
1530 os << std::endl ;
1531 if( details_ != NullPtr< const char >( ) )
1533 Exceptions::prefixEachLine( additionalLinesPrefix, details_, os );
1538 Exceptions::MultipleDynamicBind::MultipleDynamicBind( const char * _id, const Ast::SourceLocation & _loc, const Ast::SourceLocation & _prevLoc )
1539 : Exceptions::RuntimeError( _loc ), id( _id ), prevLoc( _prevLoc )
1542 Exceptions::MultipleDynamicBind::~MultipleDynamicBind( )
1545 void
1546 Exceptions::MultipleDynamicBind::display( std::ostream & os ) const
1548 os << "This dynamic binding of " << id << " is merged with the conflicting binding at " << prevLoc << "." << std::endl ;
1552 Exceptions::UndefinedEscapeContinuation::UndefinedEscapeContinuation( const char * _id, const Ast::SourceLocation & _loc )
1553 : Exceptions::RuntimeError( _loc ), id( _id )
1556 Exceptions::UndefinedEscapeContinuation::~UndefinedEscapeContinuation( )
1559 void
1560 Exceptions::UndefinedEscapeContinuation::display( std::ostream & os ) const
1562 os << "The escape continuation " << id << " was not defined in the dynamic context." << std::endl ;
1566 Exceptions::DeadStateAccess::DeadStateAccess( )
1567 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1570 Exceptions::DeadStateAccess::~DeadStateAccess( )
1573 void
1574 Exceptions::DeadStateAccess::display( std::ostream & os ) const
1576 os << "Accessing dead state." << std::endl ;
1580 Exceptions::UnFreezable::UnFreezable( )
1581 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1584 Exceptions::UnFreezable::~UnFreezable( )
1587 void
1588 Exceptions::UnFreezable::display( std::ostream & os ) const
1590 os << "The state cannot be frozen." << std::endl ;
1594 Exceptions::UnPeekable::UnPeekable( )
1595 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1598 Exceptions::UnPeekable::~UnPeekable( )
1601 void
1602 Exceptions::UnPeekable::display( std::ostream & os ) const
1604 os << "The state cannot be peeked. Consider freezing it." << std::endl ;
1608 Exceptions::UninitializedAccess::UninitializedAccess( )
1609 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1612 Exceptions::UninitializedAccess::~UninitializedAccess( )
1615 void
1616 Exceptions::UninitializedAccess::display( std::ostream & os ) const
1618 os << "The accessed variable or state has not been initialized yet." << std::endl ;
1622 Exceptions::DtMinError::DtMinError( double _dt )
1623 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), dt( _dt )
1626 Exceptions::DtMinError::~DtMinError( )
1629 void
1630 Exceptions::DtMinError::display( std::ostream & os ) const
1632 os << "Path segment too long in relation to arcdelta: dt = " << dt << " < " << Computation::the_dtMin << ". Either increase arcdelta, or inhibit this error." << std::endl ;
1635 RefCountPtr< const Lang::Exception >
1636 Exceptions::DtMinError::clone( const Kernel::ContRef & cont ) const
1638 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "dtmin" ) );
1639 std::ostringstream os;
1640 display( os );
1641 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1642 kind,
1643 RefCountPtr< const Lang::String >( new Lang::String( "(core path computation)", true ) ),
1644 RefCountPtr< const Lang::Float >( new Lang::Float( dt / Computation::the_dtMin ) ),
1645 strrefdup( os ),
1646 cont,
1647 this->exitCode( ) ) );
1651 Exceptions::AffineTransformKillsPlane::AffineTransformKillsPlane( double sigma2 )
1652 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), sigma2_( sigma2 )
1655 Exceptions::AffineTransformKillsPlane::~AffineTransformKillsPlane( )
1658 void
1659 Exceptions::AffineTransformKillsPlane::display( std::ostream & os ) const
1661 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 ;
1664 RefCountPtr< const Lang::Exception >
1665 Exceptions::AffineTransformKillsPlane::clone( const Kernel::ContRef & cont ) const
1667 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "numeric" ) );
1668 std::ostringstream os;
1669 display( os );
1670 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1671 kind,
1672 RefCountPtr< const Lang::String >( new Lang::String( "(core float triple computation)", true ) ),
1673 Lang::THE_VOID,
1674 strrefdup( os ),
1675 cont,
1676 this->exitCode( ) ) );
1679 Exceptions::MissingFontMetrics::MissingFontMetrics( RefCountPtr< const char > fontname, const std::list< std::string > * searchPath )
1680 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), fontname_( fontname ), searchPath_( searchPath )
1683 Exceptions::MissingFontMetrics::~MissingFontMetrics( )
1686 void
1687 Exceptions::MissingFontMetrics::display( std::ostream & os ) const
1689 os << "The font metrics for " << fontname_ << ", named " << fontname_ << ".afm, could not be found in {" ;
1690 typedef typeof *searchPath_ ListType;
1691 for( ListType::const_iterator i = searchPath_->begin( ); i != searchPath_->end( ); ++i )
1693 os << " " << *i ;
1695 os << " }." << std::endl ;
1699 Exceptions::FontMetricsError::FontMetricsError( const RefCountPtr< const char > & fontname, const RefCountPtr< const char > & message )
1700 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), fontname_( fontname ), message_( message )
1703 Exceptions::FontMetricsError::~FontMetricsError( )
1706 void
1707 Exceptions::FontMetricsError::display( std::ostream & os ) const
1709 os << "There was a problem with the font metrics for " << fontname_ << ": " << message_ << std::endl ;
1713 Exceptions::InsertingEmptyPage::InsertingEmptyPage( const Ast::SourceLocation & loc )
1714 : Exceptions::CatchableError( loc )
1717 Exceptions::InsertingEmptyPage::~InsertingEmptyPage( )
1720 void
1721 Exceptions::InsertingEmptyPage::display( std::ostream & os ) const
1723 os << "Attempt to place empty page in catalog." << std::endl ;
1726 RefCountPtr< const Lang::Exception >
1727 Exceptions::InsertingEmptyPage::clone( const Kernel::ContRef & cont ) const
1729 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
1730 std::ostringstream os;
1731 display( os );
1732 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1733 kind,
1734 RefCountPtr< const Lang::String >( new Lang::String( "(core exception)", true ) ),
1735 Lang::THE_VOID,
1736 strrefdup( os ),
1737 cont,
1738 this->exitCode( ) ) );
1742 Exceptions::UndefinedCrossRef::UndefinedCrossRef( const Ast::SourceLocation & _loc, RefCountPtr< const char > ref )
1743 : Exceptions::PostCondition( _loc ), ref_( ref )
1746 Exceptions::UndefinedCrossRef::~UndefinedCrossRef( )
1749 void
1750 Exceptions::UndefinedCrossRef::display( std::ostream & os ) const
1752 os << "The cross reference \"" << ref_ << "\" is not defined." << std::endl ;
1756 void
1757 Exceptions::prefixEachLine( const std::string & prefix, std::istream & src, std::ostream & dst )
1759 std::string line;
1760 for( std::getline( src, line ); ! src.eof( ); std::getline( src, line ) )
1762 dst << prefix << line << std::endl ;
1766 void
1767 Exceptions::prefixEachLine( const std::string & prefix, const RefCountPtr< const char > & src, std::ostream & dst )
1769 std::istringstream is( src.getPtr( ) );
1770 Exceptions::prefixEachLine( prefix, is, dst );