Merge branch 'gh/maint-clean' into ht/-include
[shapes.git] / source / shapesexceptions.cc
blobe41b888330dd8316749c247352f1f66f052afc51
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, bool justAWarning )
156 : Exceptions::StaticInconsistency( loc_ ), msg_( msg ), justAWarning_( justAWarning )
159 Exceptions::ParserError::~ParserError( )
162 void
163 Exceptions::ParserError::display( ostream & os ) const
165 os << "Parser " << ( justAWarning_ ? "warning" : "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, bool justAWarning )
483 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), version_( version ), required_( required ), msgMem_( msg ), msg_( msgMem_.getPtr( ) ), justAWarning_( justAWarning )
486 Exceptions::PDFVersionError::PDFVersionError( SimplePDF::PDF_Version::Version version, SimplePDF::PDF_Version::Version required, const char * msg, bool justAWarning )
487 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), version_( version ), required_( required ), msgMem_( NullPtr< const char >( ) ), msg_( msg ), justAWarning_( justAWarning )
490 Exceptions::PDFVersionError::~PDFVersionError( )
493 void
494 Exceptions::PDFVersionError::display( std::ostream & os ) const
496 os << SimplePDF::PDF_Version::toString( required_ ) << " " << ( justAWarning_ ? "warning" : "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::FontProblem::FontProblem( const RefCountPtr< const Lang::Symbol > & PostScript_name, RefCountPtr< const char > msg, bool justAWarning )
809 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), PostScript_name_( PostScript_name ), msg_( msg.getPtr( ) ), msgMem_( msg ), justAWarning_( justAWarning )
812 Exceptions::FontProblem::FontProblem( const RefCountPtr< const Lang::Symbol > & PostScript_name, const char * msg, bool justAWarning )
813 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), PostScript_name_( PostScript_name ), msg_( msg ), msgMem_( NullPtr< const char >( ) ), justAWarning_( justAWarning )
816 Exceptions::FontProblem::FontProblem( const RefCountPtr< const Lang::Symbol > & PostScript_name, const Ast::SourceLocation & _loc, RefCountPtr< const char > msg, bool justAWarning )
817 : Exceptions::CatchableError( _loc ), PostScript_name_( PostScript_name ), msg_( msg.getPtr( ) ), msgMem_( msg ), justAWarning_( justAWarning )
820 Exceptions::FontProblem::FontProblem( const RefCountPtr< const Lang::Symbol > & PostScript_name, const Ast::SourceLocation & _loc, const char * msg, bool justAWarning )
821 : Exceptions::CatchableError( _loc ), PostScript_name_( PostScript_name ), msg_( msg ), msgMem_( NullPtr< const char >( ) ), justAWarning_( justAWarning )
824 Exceptions::FontProblem::~FontProblem( )
827 void
828 Exceptions::FontProblem::display( std::ostream & os ) const
830 os << "Font " << ( justAWarning_ ? "warning" : "error" ) << " using " << PostScript_name_->name( ) << ": " << msg_ << std::endl ;
833 RefCountPtr< const Lang::Exception >
834 Exceptions::FontProblem::clone( const Kernel::ContRef & cont ) const
836 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
837 std::ostringstream os;
838 display( os );
839 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
840 kind,
841 RefCountPtr< const Lang::String >( new Lang::String( "(font problem)", true ) ),
842 Lang::THE_VOID,
843 strrefdup( os ),
844 cont,
845 this->exitCode( ) ) );
849 Exceptions::NonVoidStatement::NonVoidStatement( const Ast::SourceLocation & loc, RefCountPtr< const Lang::Value > val )
850 : Exceptions::RuntimeError( loc ), val_( val )
853 Exceptions::NonVoidStatement::~NonVoidStatement( )
856 void
857 Exceptions::NonVoidStatement::display( std::ostream & os ) const
859 os << "No implicit ignore of non-void value (of type " << val_->getTypeName( ) << ")" << std::endl ;
862 // Exceptions::RuntimeError::RuntimeError( )
863 // : loc_( "< unlocated runtime error >" )
864 // { }
866 Exceptions::RuntimeError::~RuntimeError( )
869 Exceptions::RuntimeError::RuntimeError( const Ast::SourceLocation & loc )
870 : loc_( loc )
873 Exceptions::RuntimeError::RuntimeError( Ast::Expression * expr )
874 : loc_( expr->loc( ) )
877 const Ast::SourceLocation &
878 Exceptions::RuntimeError::getLoc( ) const
880 return loc_;
884 Exceptions::CatchableError::CatchableError( const Ast::SourceLocation & loc )
885 : Exceptions::RuntimeError( loc )
888 Exceptions::CatchableError::CatchableError( Ast::Expression * expr )
889 : Exceptions::RuntimeError( expr )
892 Exceptions::CatchableError::~CatchableError( )
896 Exceptions::UncaughtError::UncaughtError( const RefCountPtr< const Lang::Exception > & ball )
897 : Exceptions::RuntimeError( ball->loc( ) ), ball_( ball )
900 Exceptions::UncaughtError::~UncaughtError( )
903 void
904 Exceptions::UncaughtError::display( std::ostream & os ) const
906 os << "Uncaught error: " ;
907 ball_->show( os );
908 os << std::endl ;
911 Interaction::ExitCode
912 Exceptions::UncaughtError::exitCode( ) const
914 return ball_->exitCode( );
918 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 )
919 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), source_( source ), details_( details ), message_( message )
922 Exceptions::UserError::~UserError( )
925 void
926 Exceptions::UserError::display( ostream & os ) const
928 os << "'" ;
929 kind_->show( os );
930 os << " error in " << source_->val_ << ": " << message_ << std::endl ;
933 RefCountPtr< const Lang::Exception >
934 Exceptions::UserError::clone( const Kernel::ContRef & cont ) const
936 std::ostringstream os;
937 display( os );
938 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
939 kind_,
940 source_,
941 details_,
942 strrefdup( os ),
943 cont,
944 this->exitCode( ) ) );
948 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 )
949 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), source_( source ), details_( details ), message_( message )
952 Exceptions::UserOutOfRange::~UserOutOfRange( )
955 void
956 Exceptions::UserOutOfRange::display( ostream & os ) const
958 os << "In " << source_->val_ << ", argument " << details_->val_
959 << ", out-of-range: " << message_ << std::endl ;
962 RefCountPtr< const Lang::Exception >
963 Exceptions::UserOutOfRange::clone( const Kernel::ContRef & cont ) const
965 std::ostringstream os;
966 display( os );
967 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
968 kind_,
969 source_,
970 details_,
971 strrefdup( os ),
972 cont,
973 this->exitCode( ) ) );
977 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 )
978 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), source_( source ), details_( details ), expectedType_( expectedType ), valueType_( valueType )
981 Exceptions::UserTypeMismatch::~UserTypeMismatch( )
984 void
985 Exceptions::UserTypeMismatch::display( ostream & os ) const
987 os << "In " << source_->val_ << ", argument " << details_->val_
988 << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
991 RefCountPtr< const Lang::Exception >
992 Exceptions::UserTypeMismatch::clone( const Kernel::ContRef & cont ) const
994 std::ostringstream os;
995 display( os );
996 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
997 kind_,
998 source_,
999 details_,
1000 strrefdup( os ),
1001 cont,
1002 this->exitCode( ) ) );
1006 Exceptions::InternalError::InternalError( const Ast::SourceLocation & loc, RefCountPtr< const char > msg, bool justAWarning )
1007 : Exceptions::RuntimeError( loc ), msg_( msg.getPtr( ) ), msgMem_( msg ), justAWarning_( justAWarning )
1010 Exceptions::InternalError::InternalError( const Ast::SourceLocation & loc, const char * msg, bool justAWarning )
1011 : Exceptions::RuntimeError( loc ), msg_( msg ), msgMem_( NullPtr< const char >( ) ), justAWarning_( justAWarning )
1014 Exceptions::InternalError::InternalError( RefCountPtr< const char > msg, bool justAWarning )
1015 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg ), justAWarning_( justAWarning )
1018 Exceptions::InternalError::InternalError( const char * msg, bool justAWarning )
1019 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) ), justAWarning_( justAWarning )
1022 Exceptions::InternalError::InternalError( const std::ostringstream & msg, bool justAWarning )
1023 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( strdup( msg.str( ).c_str( ) ) ), msgMem_( msg_ ), justAWarning_( justAWarning )
1026 Exceptions::InternalError::~InternalError( )
1029 void
1030 Exceptions::InternalError::display( ostream & os ) const
1032 os << "Internal " << ( justAWarning_ ? "warning" : "error" ) << ": " << msg_ << std::endl ;
1036 Exceptions::ExternalError::ExternalError( RefCountPtr< const char > msg, bool justAWarning )
1037 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg ), justAWarning_( justAWarning )
1040 Exceptions::ExternalError::ExternalError( const char * msg, bool justAWarning )
1041 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) ), justAWarning_( justAWarning )
1044 Exceptions::ExternalError::~ExternalError( )
1047 void
1048 Exceptions::ExternalError::display( ostream & os ) const
1050 os << "External " << ( justAWarning_ ? "warning" : "error" ) << ": " << msg_ << std::endl ;
1053 RefCountPtr< const Lang::Exception >
1054 Exceptions::ExternalError::clone( const Kernel::ContRef & cont ) const
1056 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "external" ) );
1057 std::ostringstream os;
1058 display( os );
1059 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1060 kind,
1061 RefCountPtr< const Lang::String >( new Lang::String( "(external error)", true ) ),
1062 Lang::THE_VOID,
1063 strrefdup( os ),
1064 cont,
1065 this->exitCode( ) ) );
1068 Exceptions::ExternalError *
1069 Exceptions::ExternalError::cloneTyped( ) const
1071 return new Exceptions::ExternalError( msgMem_ );
1074 Exceptions::UserArityMismatch::UserArityMismatch( const Ast::SourceLocation _formalsLoc, size_t _functionArity, size_t _callArity, Type type )
1075 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc( _formalsLoc ), functionArity( _functionArity ), callArity( _callArity ), type_( type )
1078 Exceptions::UserArityMismatch::~UserArityMismatch( )
1081 void
1082 Exceptions::UserArityMismatch::display( std::ostream & os ) const
1084 os << "Function with formals at " << formalsLoc << " expects " << functionArity ;
1085 switch( type_ )
1087 case VARIABLE:
1088 os << " value arguments" ;
1089 break;
1090 case STATE:
1091 os << " state arguments" ;
1092 break;
1093 default:
1094 os << " ?ERROR?" ;
1096 os << ", not " << callArity << std::endl ;
1099 Exceptions::SinkRequired::SinkRequired( const Ast::SourceLocation formalsLoc, size_t formalsArity, size_t callArity )
1100 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc_( formalsLoc ), formalsArity_( formalsArity ), callArity_( callArity )
1103 Exceptions::SinkRequired::~SinkRequired( )
1106 void
1107 Exceptions::SinkRequired::display( std::ostream & os ) const
1109 os << "Formals at " << formalsLoc_ << " contains no sink, so passing " << callArity_ << " ordered arguments is " << callArity_ - formalsArity_ << " too many." << std::endl ;
1113 Exceptions::NamedFormalMismatch::NamedFormalMismatch( const Ast::SourceLocation _formalsLoc, RefCountPtr< const char > _name, Exceptions::NamedFormalMismatch::Type type )
1114 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc( _formalsLoc ), name( _name ), type_( type )
1117 Exceptions::NamedFormalMismatch::~NamedFormalMismatch( )
1120 void
1121 Exceptions::NamedFormalMismatch::display( std::ostream & os ) const
1123 os << "Function with formals at " << formalsLoc << " has no named ";
1124 switch( type_ )
1126 case VARIABLE:
1127 os << "variable" ;
1128 break;
1129 case STATE:
1130 os << "state" ;
1131 break;
1132 default:
1133 os << "<?ERROR?" ;
1135 os << " called " << name << "." << std::endl ;
1139 Exceptions::NamedFormalAlreadySpecified::NamedFormalAlreadySpecified( const Ast::SourceLocation _formalsLoc, RefCountPtr< const char > _name, size_t _pos, Exceptions::NamedFormalAlreadySpecified::Type type )
1140 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc( _formalsLoc ), name( _name ), pos( _pos ), type_( type )
1143 Exceptions::NamedFormalAlreadySpecified::~NamedFormalAlreadySpecified( )
1146 void
1147 Exceptions::NamedFormalAlreadySpecified::display( std::ostream & os ) const
1149 os << "The formal " ;
1150 switch( type_ )
1152 case VARIABLE:
1153 os << "variable" ;
1154 break;
1155 case STATE:
1156 os << "state" ;
1157 break;
1158 default:
1159 os << "<?ERROR?" ;
1161 os << " named " << name << ", defined at " << formalsLoc << " is already defined by order, at position " << pos << "." << std::endl ;
1164 Exceptions::MissingArguments::MissingArguments( const Ast::SourceLocation formalsLoc, std::map< size_t, RefCountPtr< const char > > * missingVariables, std::map< size_t, RefCountPtr< const char > > * missingStates )
1165 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc_( formalsLoc ), missingVariables_( missingVariables ), missingStates_( missingStates )
1168 Exceptions::MissingArguments::~MissingArguments( )
1171 void
1172 Exceptions::MissingArguments::display( std::ostream & os ) const
1174 os << "Among the formals at " << formalsLoc_ ;
1175 if( missingVariables_ != NullPtr< typeof *missingVariables_ >( ) )
1177 os << ", the following variables are missing:" ;
1178 typedef typeof *missingVariables_ MapType;
1179 for( MapType::const_iterator i = missingVariables_->begin( ); i != missingVariables_->end( ); ++i )
1181 if( i != missingVariables_->begin( ) )
1183 os << "," ;
1185 os << " (" << i->first << ")" << i->second.getPtr( ) ;
1188 if( missingStates_ != NullPtr< typeof *missingStates_ >( ) )
1190 os << ", " ;
1191 if( missingVariables_ != NullPtr< typeof *missingVariables_ >( ) )
1193 os << "and " ;
1195 os << "the following states are missing:" ;
1196 typedef typeof *missingStates_ MapType;
1197 for( MapType::const_iterator i = missingStates_->begin( ); i != missingStates_->end( ); ++i )
1199 if( i != missingStates_->begin( ) )
1201 os << "," ;
1203 os << " (" << i->first << ")" << i->second.getPtr( ) ;
1206 os << "." << std::endl ;
1210 Exceptions::CoreArityMismatch::CoreArityMismatch( const char * _title, size_t _functionArity, size_t _callArity )
1211 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title ), titleMem( NullPtr< const char >( ) ), functionArityLow( _functionArity ), functionArityHigh( _functionArity ), callArity( _callArity )
1214 Exceptions::CoreArityMismatch::CoreArityMismatch( const char * _title, size_t _functionArityLow, size_t _functionArityHigh, size_t _callArity )
1215 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title ), titleMem( NullPtr< const char >( ) ), functionArityLow( _functionArityLow ), functionArityHigh( _functionArityHigh ), callArity( _callArity )
1218 Exceptions::CoreArityMismatch::CoreArityMismatch( const RefCountPtr< const char > & _title, size_t _functionArity, size_t _callArity )
1219 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title.getPtr( ) ), titleMem( _title ), functionArityLow( _functionArity ), functionArityHigh( _functionArity ), callArity( _callArity )
1222 Exceptions::CoreArityMismatch::CoreArityMismatch( const RefCountPtr< const char > & _title, size_t _functionArityLow, size_t _functionArityHigh, size_t _callArity )
1223 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title.getPtr( ) ), titleMem( _title ), functionArityLow( _functionArityLow ), functionArityHigh( _functionArityHigh ), callArity( _callArity )
1226 Exceptions::CoreArityMismatch::~CoreArityMismatch( )
1229 void
1230 Exceptions::CoreArityMismatch::display( std::ostream & os ) const
1232 if( functionArityLow == functionArityHigh )
1234 os << "Core function " << title << " expects " << functionArityLow << " arguments, not " << callArity << std::endl ;
1236 else
1238 os << "Core function " << title << " expects [" << functionArityLow << ", " << functionArityHigh << "] arguments, not " << callArity << std::endl ;
1243 Exceptions::CoreNoNamedFormals::CoreNoNamedFormals( const char * _title )
1244 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title ), titleMem( NullPtr< const char >( ) )
1247 Exceptions::CoreNoNamedFormals::CoreNoNamedFormals( const RefCountPtr< const char > & _title )
1248 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title( _title.getPtr( ) ), titleMem( _title )
1251 Exceptions::CoreNoNamedFormals::~CoreNoNamedFormals( )
1254 void
1255 Exceptions::CoreNoNamedFormals::display( std::ostream & os ) const
1257 os << "Core function " << title << " does not accept named arguments." << std::endl ;
1261 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1262 const char * title,
1263 const Ast::SourceLocation & argLoc,
1264 RefCountPtr< const char > valueType,
1265 RefCountPtr< const char > expectedType )
1266 : Exceptions::RuntimeError( callLoc ),
1267 title_( title ),
1268 titleMem_( NullPtr< const char >( ) ),
1269 argLoc_( argLoc ),
1270 valueType_( valueType ),
1271 expectedType_( expectedType )
1274 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1275 RefCountPtr< const char > title,
1276 const Ast::SourceLocation & argLoc,
1277 RefCountPtr< const char > valueType,
1278 RefCountPtr< const char > expectedType )
1279 : Exceptions::RuntimeError( callLoc ),
1280 title_( title.getPtr( ) ),
1281 titleMem_( title ),
1282 argLoc_( argLoc ),
1283 valueType_( valueType ),
1284 expectedType_( expectedType )
1287 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1288 const char * title,
1289 Kernel::Arguments & args,
1290 size_t argNo,
1291 RefCountPtr< const char > expectedType )
1292 : Exceptions::RuntimeError( callLoc ),
1293 title_( title ),
1294 titleMem_( NullPtr< const char >( ) ),
1295 argLoc_( args.getLoc( argNo ) ),
1296 valueType_( args.getValue( argNo )->getTypeName( ) ),
1297 expectedType_( expectedType )
1300 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1301 RefCountPtr< const char > title,
1302 Kernel::Arguments & args,
1303 size_t argNo,
1304 RefCountPtr< const char > expectedType )
1305 : Exceptions::RuntimeError( callLoc ),
1306 title_( title.getPtr( ) ),
1307 titleMem_( title ),
1308 argLoc_( args.getLoc( argNo ) ),
1309 valueType_( args.getValue( argNo )->getTypeName( ) ),
1310 expectedType_( expectedType )
1313 Exceptions::CoreTypeMismatch::~CoreTypeMismatch( )
1316 void
1317 Exceptions::CoreTypeMismatch::display( std::ostream & os ) const
1319 os << "Core function " << title_ << ", argument ";
1320 // if( argName_ != 0 )
1321 // {
1322 // os << "\"" << argName_ << "\" " ;
1323 // }
1324 os << "at " << argLoc_ << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1328 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1329 const char * title,
1330 const Ast::SourceLocation & argLoc,
1331 RefCountPtr< const char > valueType,
1332 RefCountPtr< const char > expectedType )
1333 : Exceptions::RuntimeError( callLoc ),
1334 title_( title ),
1335 titleMem_( NullPtr< const char >( ) ),
1336 argLoc_( argLoc ),
1337 valueType_( valueType ),
1338 expectedType_( expectedType )
1341 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1342 RefCountPtr< const char > title,
1343 const Ast::SourceLocation & argLoc,
1344 RefCountPtr< const char > valueType,
1345 RefCountPtr< const char > expectedType )
1346 : Exceptions::RuntimeError( callLoc ),
1347 title_( title.getPtr( ) ),
1348 titleMem_( title ),
1349 argLoc_( argLoc ),
1350 valueType_( valueType ),
1351 expectedType_( expectedType )
1354 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1355 const char * title,
1356 Kernel::Arguments & args,
1357 size_t argNo,
1358 RefCountPtr< const char > expectedType )
1359 : Exceptions::RuntimeError( callLoc ),
1360 title_( title ),
1361 titleMem_( NullPtr< const char >( ) ),
1362 argLoc_( args.getStateLoc( argNo ) ),
1363 valueType_( args.getState( argNo )->getTypeName( ) ),
1364 expectedType_( expectedType )
1367 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1368 RefCountPtr< const char > title,
1369 Kernel::Arguments & args,
1370 size_t argNo,
1371 RefCountPtr< const char > expectedType )
1372 : Exceptions::RuntimeError( callLoc ),
1373 title_( title.getPtr( ) ),
1374 titleMem_( title ),
1375 argLoc_( args.getStateLoc( argNo ) ),
1376 valueType_( args.getState( argNo )->getTypeName( ) ),
1377 expectedType_( expectedType )
1380 Exceptions::CoreStateTypeMismatch::~CoreStateTypeMismatch( )
1383 void
1384 Exceptions::CoreStateTypeMismatch::display( std::ostream & os ) const
1386 os << "Core function " << title_ << ", state ";
1387 // if( argName_ != 0 )
1388 // {
1389 // os << "\"" << argName_ << "\" " ;
1390 // }
1391 os << "at " << argLoc_ << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1395 Exceptions::CoreDynamicTypeMismatch::CoreDynamicTypeMismatch( const Ast::SourceLocation & callLoc,
1396 const char * title,
1397 const char * id,
1398 RefCountPtr< const char > valueType,
1399 RefCountPtr< const char > expectedType )
1400 : Exceptions::RuntimeError( callLoc ),
1401 title_( title ),
1402 titleMem_( NullPtr< const char >( ) ),
1403 id_( id ),
1404 idMem_( NullPtr< const char >( ) ),
1405 valueType_( valueType ),
1406 expectedType_( expectedType )
1409 Exceptions::CoreDynamicTypeMismatch::~CoreDynamicTypeMismatch( )
1412 void
1413 Exceptions::CoreDynamicTypeMismatch::display( std::ostream & os ) const
1415 os << "Core function " << title_ << " encountered a type mismatch in the dynamic variable @" << id_
1416 << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1419 Exceptions::ContinuationTypeMismatch::ContinuationTypeMismatch( const Kernel::Continuation * locationCont,
1420 RefCountPtr< const char > valueType,
1421 RefCountPtr< const char > expectedType )
1422 : Exceptions::RuntimeError( locationCont->traceLoc( ) ),
1423 valueType_( valueType ),
1424 expectedType_( expectedType )
1427 Exceptions::ContinuationTypeMismatch::~ContinuationTypeMismatch( )
1430 void
1431 Exceptions::ContinuationTypeMismatch::display( std::ostream & os ) const
1433 os << "The continuation expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1437 Exceptions::CoreOutOfRange::CoreOutOfRange( const char * title, Kernel::Arguments & args, size_t argNo, RefCountPtr< const char > msg )
1438 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), title_( title ), argNo_( argNo ), argLoc_( args.getLoc( argNo ) ), msg_( msg.getPtr( ) ), msgMem_( msg )
1441 Exceptions::CoreOutOfRange::CoreOutOfRange( const char * title, Kernel::Arguments & args, size_t argNo, const char * msg )
1442 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), title_( title ), argNo_( argNo ), argLoc_( args.getLoc( argNo ) ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
1445 Exceptions::CoreOutOfRange::~CoreOutOfRange( )
1448 void
1449 Exceptions::CoreOutOfRange::display( std::ostream & os ) const
1451 os << "Core function " << title_ << ": " ;
1452 os << "Argument at " << argLoc_ << " is out of range; " << msg_ << std::endl ;
1455 RefCountPtr< const Lang::Exception >
1456 Exceptions::CoreOutOfRange::clone( const Kernel::ContRef & cont ) const
1458 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "out_of_range" ) );
1459 std::ostringstream os;
1460 display( os );
1461 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1462 kind,
1463 RefCountPtr< const Lang::String >( new Lang::String( title_, true ) ),
1464 RefCountPtr< const Lang::Integer >( new Lang::Integer( argNo_ ) ),
1465 strrefdup( os ),
1466 cont,
1467 this->exitCode( ) ) );
1470 Exceptions::CoreRequirement::CoreRequirement( RefCountPtr< const char > msg, const char * title, const Ast::SourceLocation & callLoc )
1471 : Exceptions::CatchableError( callLoc ), title_( title ), msg_( msg.getPtr( ) ), msgMem_( msg )
1474 Exceptions::CoreRequirement::CoreRequirement( const char * msg, const char * title, const Ast::SourceLocation & callLoc )
1475 : Exceptions::CatchableError( callLoc ), title_( title ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
1478 Exceptions::CoreRequirement::~CoreRequirement( )
1481 void
1482 Exceptions::CoreRequirement::display( std::ostream & os ) const
1484 os << "Core function " << title_ << ": " << msg_ << std::endl ;
1487 RefCountPtr< const Lang::Exception >
1488 Exceptions::CoreRequirement::clone( const Kernel::ContRef & cont ) const
1490 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
1491 std::ostringstream os;
1492 display( os );
1493 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1494 kind,
1495 RefCountPtr< const Lang::String >( new Lang::String( title_, true ) ),
1496 Lang::THE_VOID,
1497 strrefdup( os ),
1498 cont,
1499 this->exitCode( ) ) );
1503 Exceptions::BuildRequirement::BuildRequirement( const char * dependency, const char * title, const Ast::SourceLocation & callLoc )
1504 : Exceptions::CatchableError( callLoc ), title_( title ), dependency_( dependency )
1507 Exceptions::BuildRequirement::~BuildRequirement( )
1510 void
1511 Exceptions::BuildRequirement::display( std::ostream & os ) const
1513 os << "Core function stub " << title_ << ": Shapes was built without " << dependency_ << ", so this function cannot be called." << std::endl ;
1516 RefCountPtr< const Lang::Exception >
1517 Exceptions::BuildRequirement::clone( const Kernel::ContRef & cont ) const
1519 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
1520 std::ostringstream os;
1521 display( os );
1522 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1523 kind,
1524 RefCountPtr< const Lang::String >( new Lang::String( title_, true ) ),
1525 Lang::THE_VOID,
1526 strrefdup( os ),
1527 cont,
1528 this->exitCode( ) ) );
1532 Exceptions::TeXLabelError::TeXLabelError( bool quoted, const char * region, RefCountPtr< const char > summary, RefCountPtr< const char > details, const Ast::SourceLocation & loc )
1533 : Exceptions::RuntimeError( loc ), strLoc_( loc ), quoted_( quoted ), region_( region ), summary_( summary ), details_( details )
1536 Exceptions::TeXLabelError::~TeXLabelError( )
1539 void
1540 Exceptions::TeXLabelError::display( ostream & os ) const
1542 if( quoted_ )
1544 os << "TeX error in " << region_ ;
1546 else
1548 os << "Error in TeX " << region_ ;
1550 if( ! strLoc_.isUnknown( ) )
1552 os << " at " << strLoc_ ;
1554 os << ": " ;
1555 if( quoted_ )
1557 os << "\"" ;
1559 os << summary_ ;
1560 if( quoted_ )
1562 os << "\"" ;
1564 os << std::endl ;
1565 if( details_ != NullPtr< const char >( ) )
1567 Exceptions::prefixEachLine( additionalLinesPrefix, details_, os );
1572 Exceptions::StaticTeXLabelError::StaticTeXLabelError( bool quoted, const char * region, RefCountPtr< const char > summary, RefCountPtr< const char > details, const Ast::SourceLocation & loc )
1573 : Exceptions::StaticInconsistency( loc ), quoted_( quoted ), region_( region ), summary_( summary ), details_( details )
1576 Exceptions::StaticTeXLabelError::~StaticTeXLabelError( )
1579 void
1580 Exceptions::StaticTeXLabelError::display( ostream & os ) const
1582 if( quoted_ )
1584 os << "TeX error in " << region_ ;
1586 else
1588 os << "Error in TeX " << region_ ;
1590 os << ": " ;
1591 if( quoted_ )
1593 os << "\"" ;
1595 os << summary_ ;
1596 if( quoted_ )
1598 os << "\"" ;
1600 os << std::endl ;
1601 if( details_ != NullPtr< const char >( ) )
1603 Exceptions::prefixEachLine( additionalLinesPrefix, details_, os );
1608 Exceptions::MultipleDynamicBind::MultipleDynamicBind( const char * _id, const Ast::SourceLocation & _loc, const Ast::SourceLocation & _prevLoc )
1609 : Exceptions::RuntimeError( _loc ), id( _id ), prevLoc( _prevLoc )
1612 Exceptions::MultipleDynamicBind::~MultipleDynamicBind( )
1615 void
1616 Exceptions::MultipleDynamicBind::display( std::ostream & os ) const
1618 os << "This dynamic binding of " << id << " is merged with the conflicting binding at " << prevLoc << "." << std::endl ;
1622 Exceptions::UndefinedEscapeContinuation::UndefinedEscapeContinuation( const char * _id, const Ast::SourceLocation & _loc )
1623 : Exceptions::RuntimeError( _loc ), id( _id )
1626 Exceptions::UndefinedEscapeContinuation::~UndefinedEscapeContinuation( )
1629 void
1630 Exceptions::UndefinedEscapeContinuation::display( std::ostream & os ) const
1632 os << "The escape continuation " << id << " was not defined in the dynamic context." << std::endl ;
1636 Exceptions::DeadStateAccess::DeadStateAccess( )
1637 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1640 Exceptions::DeadStateAccess::~DeadStateAccess( )
1643 void
1644 Exceptions::DeadStateAccess::display( std::ostream & os ) const
1646 os << "Accessing dead state." << std::endl ;
1650 Exceptions::UnFreezable::UnFreezable( )
1651 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1654 Exceptions::UnFreezable::~UnFreezable( )
1657 void
1658 Exceptions::UnFreezable::display( std::ostream & os ) const
1660 os << "The state cannot be frozen." << std::endl ;
1664 Exceptions::UnPeekable::UnPeekable( )
1665 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1668 Exceptions::UnPeekable::~UnPeekable( )
1671 void
1672 Exceptions::UnPeekable::display( std::ostream & os ) const
1674 os << "The state cannot be peeked. Consider freezing it." << std::endl ;
1678 Exceptions::UninitializedAccess::UninitializedAccess( )
1679 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1682 Exceptions::UninitializedAccess::~UninitializedAccess( )
1685 void
1686 Exceptions::UninitializedAccess::display( std::ostream & os ) const
1688 os << "The accessed variable or state has not been initialized yet." << std::endl ;
1692 Exceptions::DtMinError::DtMinError( double _dt )
1693 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), dt( _dt )
1696 Exceptions::DtMinError::~DtMinError( )
1699 void
1700 Exceptions::DtMinError::display( std::ostream & os ) const
1702 os << "Path segment too long in relation to arcdelta: dt = " << dt << " < " << Computation::the_dtMin << ". Either increase arcdelta, or inhibit this error." << std::endl ;
1705 RefCountPtr< const Lang::Exception >
1706 Exceptions::DtMinError::clone( const Kernel::ContRef & cont ) const
1708 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "dtmin" ) );
1709 std::ostringstream os;
1710 display( os );
1711 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1712 kind,
1713 RefCountPtr< const Lang::String >( new Lang::String( "(core path computation)", true ) ),
1714 RefCountPtr< const Lang::Float >( new Lang::Float( dt / Computation::the_dtMin ) ),
1715 strrefdup( os ),
1716 cont,
1717 this->exitCode( ) ) );
1721 Exceptions::AffineTransformKillsPlane::AffineTransformKillsPlane( double sigma2 )
1722 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), sigma2_( sigma2 )
1725 Exceptions::AffineTransformKillsPlane::~AffineTransformKillsPlane( )
1728 void
1729 Exceptions::AffineTransformKillsPlane::display( std::ostream & os ) const
1731 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 ;
1734 RefCountPtr< const Lang::Exception >
1735 Exceptions::AffineTransformKillsPlane::clone( const Kernel::ContRef & cont ) const
1737 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "numeric" ) );
1738 std::ostringstream os;
1739 display( os );
1740 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1741 kind,
1742 RefCountPtr< const Lang::String >( new Lang::String( "(core float triple computation)", true ) ),
1743 Lang::THE_VOID,
1744 strrefdup( os ),
1745 cont,
1746 this->exitCode( ) ) );
1749 Exceptions::MissingFontMetrics::MissingFontMetrics( RefCountPtr< const char > fontname, const std::list< std::string > * searchPath )
1750 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), fontname_( fontname ), searchPath_( searchPath )
1753 Exceptions::MissingFontMetrics::~MissingFontMetrics( )
1756 void
1757 Exceptions::MissingFontMetrics::display( std::ostream & os ) const
1759 os << "The font metrics for " << fontname_ << ", named " << fontname_ << ".afm, could not be found in {" ;
1760 typedef typeof *searchPath_ ListType;
1761 for( ListType::const_iterator i = searchPath_->begin( ); i != searchPath_->end( ); ++i )
1763 os << " " << *i ;
1765 os << " }." << std::endl ;
1769 Exceptions::FontMetricsError::FontMetricsError( const RefCountPtr< const char > & fontname, const RefCountPtr< const char > & message )
1770 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), fontname_( fontname ), message_( message )
1773 Exceptions::FontMetricsError::~FontMetricsError( )
1776 void
1777 Exceptions::FontMetricsError::display( std::ostream & os ) const
1779 os << "There was a problem with the font metrics for " << fontname_ << ": " << message_ << std::endl ;
1783 Exceptions::InsertingEmptyPage::InsertingEmptyPage( const Ast::SourceLocation & loc )
1784 : Exceptions::CatchableError( loc )
1787 Exceptions::InsertingEmptyPage::~InsertingEmptyPage( )
1790 void
1791 Exceptions::InsertingEmptyPage::display( std::ostream & os ) const
1793 os << "Attempt to place empty page in catalog." << std::endl ;
1796 RefCountPtr< const Lang::Exception >
1797 Exceptions::InsertingEmptyPage::clone( const Kernel::ContRef & cont ) const
1799 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
1800 std::ostringstream os;
1801 display( os );
1802 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1803 kind,
1804 RefCountPtr< const Lang::String >( new Lang::String( "(core exception)", true ) ),
1805 Lang::THE_VOID,
1806 strrefdup( os ),
1807 cont,
1808 this->exitCode( ) ) );
1812 Exceptions::UndefinedCrossRef::UndefinedCrossRef( const Ast::SourceLocation & _loc, RefCountPtr< const char > ref )
1813 : Exceptions::PostCondition( _loc ), ref_( ref )
1816 Exceptions::UndefinedCrossRef::~UndefinedCrossRef( )
1819 void
1820 Exceptions::UndefinedCrossRef::display( std::ostream & os ) const
1822 os << "The cross reference \"" << ref_ << "\" is not defined." << std::endl ;
1826 void
1827 Exceptions::prefixEachLine( const std::string & prefix, std::istream & src, std::ostream & dst )
1829 std::string line;
1830 for( std::getline( src, line ); ! src.eof( ); std::getline( src, line ) )
1832 dst << prefix << line << std::endl ;
1836 void
1837 Exceptions::prefixEachLine( const std::string & prefix, const RefCountPtr< const char > & src, std::ostream & dst )
1839 std::istringstream is( src.getPtr( ) );
1840 Exceptions::prefixEachLine( prefix, is, dst );