Merge branch 'ht/mem-debug' into ht/graphs
[shapes.git] / source / shapesexceptions.cc
blob25009ba0c5540e286d2c11a014814b9f7ff7708b
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, 2013, 2014 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( const Ast::SourceLocation & loc, RefCountPtr< const char > msg )
62 : Exceptions::CatchableError( loc ), msg_( msg.getPtr( ) ), msgMem_( msg )
63 { }
65 Exceptions::MiscellaneousRequirement::MiscellaneousRequirement( const Ast::SourceLocation & loc, const char * msg )
66 : Exceptions::CatchableError( loc ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
67 { }
69 Exceptions::MiscellaneousRequirement::MiscellaneousRequirement( RefCountPtr< const char > msg )
70 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg )
71 { }
73 Exceptions::MiscellaneousRequirement::MiscellaneousRequirement( const char * msg )
74 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
75 { }
77 Exceptions::MiscellaneousRequirement::~MiscellaneousRequirement( )
78 { }
80 void
81 Exceptions::MiscellaneousRequirement::display( ostream & os ) const
83 os << "Failed to meet requirement: " << msg_ << std::endl ;
86 RefCountPtr< const Lang::Exception >
87 Exceptions::MiscellaneousRequirement::clone( const Kernel::ContRef & cont ) const
89 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
90 std::ostringstream os;
91 display( os );
92 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
93 kind,
94 RefCountPtr< const Lang::String >( new Lang::String( "(core, generic)", true ) ),
95 Lang::THE_VOID,
96 strrefdup( os ),
97 cont,
98 this->exitCode( ) ) );
102 Exceptions::HandlerError::HandlerError( RefCountPtr< const char > msg )
103 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg )
106 Exceptions::HandlerError::HandlerError( const char * msg )
107 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( strrefdup( msg ) )
110 Exceptions::HandlerError::~HandlerError( )
113 void
114 Exceptions::HandlerError::display( ostream & os ) const
116 os << "Error handler message: " << msg_ << std::endl ;
119 RefCountPtr< const Lang::Exception >
120 Exceptions::HandlerError::clone( const Kernel::ContRef & cont ) const
122 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
123 std::ostringstream os;
124 display( os );
125 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
126 kind,
127 RefCountPtr< const Lang::String >( new Lang::String( "(default error handler)", true ) ),
128 Lang::THE_VOID,
129 strrefdup( os ),
130 cont,
131 this->exitCode( ) ) );
135 Exceptions::MiscellaneousStaticInconsistency::MiscellaneousStaticInconsistency( const Ast::SourceLocation & loc, RefCountPtr< const char > msg )
136 : Exceptions::StaticInconsistency( loc ), msg_( msg )
139 Exceptions::MiscellaneousStaticInconsistency::~MiscellaneousStaticInconsistency( )
142 void
143 Exceptions::MiscellaneousStaticInconsistency::display( ostream & os ) const
145 os << "Misc error: " << msg_ << std::endl ;
149 Exceptions::ScannerError::ScannerError( const Ast::SourceLocation & loc, RefCountPtr< const char > msg )
150 : Exceptions::StaticInconsistency( loc ), msg_( msg )
153 Exceptions::ScannerError::~ScannerError( )
156 void
157 Exceptions::ScannerError::display( ostream & os ) const
159 os << "Scanner error: " << msg_ << std::endl ;
163 Exceptions::ParserError::ParserError( const Ast::SourceLocation & loc, RefCountPtr< const char > msg, bool justAWarning )
164 : Exceptions::StaticInconsistency( loc ), msg_( msg ), justAWarning_( justAWarning )
167 Exceptions::ParserError::~ParserError( )
170 void
171 Exceptions::ParserError::display( ostream & os ) const
173 os << "Parser " << ( justAWarning_ ? "warning" : "error" ) << ": " << msg_ << std::endl ;
177 Exceptions::MemberAlsoAbstract::MemberAlsoAbstract( const Ast::SourceLocation & memberLoc, const char * id, const Ast::SourceLocation & abstractLoc )
178 : Exceptions::StaticInconsistency( memberLoc ), id_( id ), abstractLoc_( abstractLoc )
181 Exceptions::MemberAlsoAbstract::~MemberAlsoAbstract( )
184 void
185 Exceptions::MemberAlsoAbstract::display( ostream & os ) const
187 os << "The member " << id_ << " is also declared abstract, at " << abstractLoc_ << "." << std::endl ;
191 Exceptions::MemberAlreadyDeclared::MemberAlreadyDeclared( const Ast::SourceLocation & memberLoc, const char * id, const Ast::SourceLocation & oldLoc )
192 : Exceptions::StaticInconsistency( memberLoc ), id_( id ), oldLoc_( oldLoc )
195 Exceptions::MemberAlreadyDeclared::~MemberAlreadyDeclared( )
198 void
199 Exceptions::MemberAlreadyDeclared::display( ostream & os ) const
201 os << "The member " << id_ << " has already been declared, at " << oldLoc_ << "." << std::endl ;
205 Exceptions::PublicGetSetInNonfinalClass::PublicGetSetInNonfinalClass( const Ast::SourceLocation & memberLoc, const char * id )
206 : Exceptions::StaticInconsistency( memberLoc ), id_( id )
209 Exceptions::PublicGetSetInNonfinalClass::~PublicGetSetInNonfinalClass( )
212 void
213 Exceptions::PublicGetSetInNonfinalClass::display( ostream & os ) const
215 os << "Only members of final classes may have the public get or set specifier. Member in question: " << id_ << "." << std::endl ;
219 Exceptions::TransformingMemberInNonfinalClass::TransformingMemberInNonfinalClass( const Ast::SourceLocation & memberLoc, const char * id )
220 : Exceptions::StaticInconsistency( memberLoc ), id_( id )
223 Exceptions::TransformingMemberInNonfinalClass::~TransformingMemberInNonfinalClass( )
226 void
227 Exceptions::TransformingMemberInNonfinalClass::display( ostream & os ) const
229 os << "Only members of final classes may have the <transforming> specifier. Member in question: " << id_ << "." << std::endl ;
233 Exceptions::RepeatedFormal::RepeatedFormal( const Ast::SourceLocation & loc, const char * id )
234 : Exceptions::StaticInconsistency( loc ), id_( id )
237 Exceptions::RepeatedFormal::~RepeatedFormal( )
240 void
241 Exceptions::RepeatedFormal::display( ostream & os ) const
243 os << "Repeated formal: " << id_ << std::endl ;
247 Exceptions::IllegalFreeStates::IllegalFreeStates( const Ast::SourceLocation & loc, Ast::StateIDSet * freeStates, const char * reason )
248 : Exceptions::StaticInconsistency( loc ), freeStates_( freeStates ), reason_( reason )
251 Exceptions::IllegalFreeStates::~IllegalFreeStates( )
254 void
255 Exceptions::IllegalFreeStates::display( ostream & os ) const
257 os << "Free states are illegal here (" << reason_ << "):" ;
258 typedef typeof *freeStates_ SetType;
259 for( SetType::const_iterator i = freeStates_->begin( ); i != freeStates_->end( ); ++i )
261 os << " " << *i ;
263 os << std::endl ;
267 Exceptions::FreeStateIsAlsoPassed::FreeStateIsAlsoPassed( const Ast::SourceLocation & loc, Ast::StateID stateID )
268 : Exceptions::StaticInconsistency( loc ), stateID_( stateID )
271 Exceptions::FreeStateIsAlsoPassed::~FreeStateIsAlsoPassed( )
274 void
275 Exceptions::FreeStateIsAlsoPassed::display( ostream & os ) const
277 os << "Non-pure, delayed, expressions may not have free states (state " << stateID_ << ") which are also passed as state arguments in the same non-pure function application. Please consider forcing immediate evaluation." << std::endl ;
281 Exceptions::RepeatedStateArgument::RepeatedStateArgument( const Ast::SourceLocation & loc, const RefCountPtr< Ast::StateIDSet > & passedStates )
282 : Exceptions::StaticInconsistency( loc ), passedStates_( passedStates )
285 Exceptions::RepeatedStateArgument::~RepeatedStateArgument( )
288 void
289 Exceptions::RepeatedStateArgument::display( ostream & os ) const
291 os << "Some of these states are being passed in more than one state argument position:" ;
292 typedef typeof *passedStates_ SetType;
293 for( SetType::const_iterator i = passedStates_->begin( ); i != passedStates_->end( ); ++i )
295 os << " " << *i ;
297 os << std::endl ;
301 Exceptions::PassingStateOut::PassingStateOut( const Ast::SourceLocation & loc, const char * id )
302 : Exceptions::StaticInconsistency( loc ), id_( id )
305 Exceptions::PassingStateOut::~PassingStateOut( )
308 void
309 Exceptions::PassingStateOut::display( std::ostream & os ) const
311 os << "States may not be returned, cannot return state " << id_ << "." << std::endl ;
315 Exceptions::IntroducingExisting::IntroducingExisting( const Ast::SourceLocation & loc, const char * id )
316 : Exceptions::StaticInconsistency( loc ), id_( id )
319 Exceptions::IntroducingExisting::~IntroducingExisting( )
322 void
323 Exceptions::IntroducingExisting::display( std::ostream & os ) const
325 os << "The variable " << id_ << " is already introduced in this scope." << std::endl ;
329 Exceptions::ExpectedImmediate::ExpectedImmediate( const Ast::SourceLocation & loc )
330 : Exceptions::StaticInconsistency( loc )
333 Exceptions::ExpectedImmediate::~ExpectedImmediate( )
336 void
337 Exceptions::ExpectedImmediate::display( std::ostream & os ) const
339 os << "It makes no sense to put a pure expression before the end of a code bracket." << std::endl ;
343 Exceptions::IllegalImperative::IllegalImperative( const Ast::SourceLocation & loc )
344 : Exceptions::StaticInconsistency( loc )
347 Exceptions::IllegalImperative::~IllegalImperative( )
350 void
351 Exceptions::IllegalImperative::display( std::ostream & os ) const
353 os << "Imperative expressions are not allowed here." << std::endl ;
357 Exceptions::FreezingUndefined::FreezingUndefined( const Ast::SourceLocation & loc, const char * id )
358 : Exceptions::StaticInconsistency( loc ), id_( id )
361 Exceptions::FreezingUndefined::~FreezingUndefined( )
364 void
365 Exceptions::FreezingUndefined::display( std::ostream & os ) const
367 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 ;
371 Exceptions::FileReadOpenError::FileReadOpenError( const Ast::SourceLocation & loc, RefCountPtr< const char > filename, const std::string * sourceDir, const std::list< std::string > * searchPath, Type type )
372 : loc_( loc ), filename_( filename ), type_( type ), sourceDir_( sourceDir ), searchPath_( searchPath )
375 Exceptions::FileReadOpenError::~FileReadOpenError( )
378 void
379 Exceptions::FileReadOpenError::display( std::ostream & os ) const
381 switch( type_ )
383 case OPEN:
384 os << loc_ << locsep << "Could not open file: " << filename_ ;
385 break;
386 case STAT:
387 os << loc_ << locsep << "Could not stat() file: " << filename_ ;
388 break;
390 if( searchPath_ != 0 )
392 os << " searching \"" ;
393 typedef typeof *searchPath_ ListType;
394 for( ListType::const_iterator i = searchPath_->begin( ); i != searchPath_->end( ); ++i )
396 if( i != searchPath_->begin( ) )
398 os << ":" ;
400 if( sourceDir_ != 0 && (*i)[0] != '/' )
402 os << *sourceDir_ ;
404 os << *i ;
406 os << "\"" ;
408 os << std::endl ;
412 Exceptions::FileWriteOpenError::FileWriteOpenError( const Ast::SourceLocation & loc, RefCountPtr< const char > filename, const char * purpose )
413 : loc_( loc ), filename_( filename ), purpose_( purpose )
416 Exceptions::FileWriteOpenError::~FileWriteOpenError( )
419 void
420 Exceptions::FileWriteOpenError::display( std::ostream & os ) const
422 os << loc_ << locsep << "Could not open " ;
423 if( purpose_ != 0 )
425 os << purpose_ ;
427 os << " file for write: " << filename_ ;
428 os << std::endl ;
432 Exceptions::TeXSetupTooLate::TeXSetupTooLate( const Ast::SourceLocation & loc )
433 : loc_( loc )
436 Exceptions::TeXSetupTooLate::~TeXSetupTooLate( )
439 void
440 Exceptions::TeXSetupTooLate::display( std::ostream & os ) const
442 os << loc_ << locsep << "It is too late to make modifications to the TeX context." << std::endl ;
446 Exceptions::EmptyFinalPicture::EmptyFinalPicture( )
449 Exceptions::EmptyFinalPicture::~EmptyFinalPicture( )
452 void
453 Exceptions::EmptyFinalPicture::display( std::ostream & os ) const
455 os << "Nothing was ever put in the global #" << Lang::CATALOG_ID << " or drawn to the global #" << Lang::CANVAS_ID << "." << std::endl ;
459 Exceptions::TeXSetupHasChanged::TeXSetupHasChanged( )
460 : Shapes::Exceptions::InternalError( "The TeX context check failed while loading fresh labels." )
463 Exceptions::TeXSetupHasChanged::~TeXSetupHasChanged( )
467 Exceptions::TypeMismatch::TypeMismatch( const Ast::SourceLocation & loc, RefCountPtr< const char > valueType, RefCountPtr< const char > expectedType )
468 : Exceptions::RuntimeError( loc ), hint_( 0 ), valueType_( valueType ), expectedType_( expectedType )
471 Exceptions::TypeMismatch::TypeMismatch( const Ast::SourceLocation & loc, const char * hint, RefCountPtr< const char > valueType, RefCountPtr< const char > expectedType )
472 : Exceptions::RuntimeError( loc ), hint_( hint ), valueType_( valueType ), expectedType_( expectedType )
475 Exceptions::TypeMismatch::~TypeMismatch( )
478 void
479 Exceptions::TypeMismatch::display( std::ostream & os ) const
481 if( hint_ != 0 )
483 os << hint_ << ": " ;
485 os << "Expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
488 Exceptions::ExpectedList::ExpectedList( const Ast::SourceLocation & loc, size_t index, RefCountPtr< const char > nonListType )
489 : Exceptions::RuntimeError( loc ), index_( index ), nonListType_( nonListType )
492 Exceptions::ExpectedList::~ExpectedList( )
495 void
496 Exceptions::ExpectedList::display( std::ostream & os ) const
498 os << "Expected a singly linked list, but encountered a " << nonListType_ << " after " << index_ << " elements." << std::endl ;
501 Exceptions::PDFVersionError::PDFVersionError( SimplePDF::PDF_Version::Version version, SimplePDF::PDF_Version::Version required, const RefCountPtr< const char > & msg, bool justAWarning )
502 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), version_( version ), required_( required ), msgMem_( msg ), msg_( msgMem_.getPtr( ) ), justAWarning_( justAWarning )
505 Exceptions::PDFVersionError::PDFVersionError( SimplePDF::PDF_Version::Version version, SimplePDF::PDF_Version::Version required, const char * msg, bool justAWarning )
506 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), version_( version ), required_( required ), msgMem_( NullPtr< const char >( ) ), msg_( msg ), justAWarning_( justAWarning )
509 Exceptions::PDFVersionError::~PDFVersionError( )
512 void
513 Exceptions::PDFVersionError::display( std::ostream & os ) const
515 os << SimplePDF::PDF_Version::toString( required_ ) << " " << ( justAWarning_ ? "warning" : "error" ) << " for target version " << SimplePDF::PDF_Version::toString( version_ ) << ": " << msg_ << std::endl ;
518 RefCountPtr< const Lang::Exception >
519 Exceptions::PDFVersionError::clone( const Kernel::ContRef & cont ) const
521 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "PDF_version" ) );
522 std::ostringstream os;
523 display( os );
524 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
525 kind,
526 RefCountPtr< const Lang::String >( new Lang::String( "(core PDF backend)", true ) ),
527 Lang::THE_VOID,
528 strrefdup( os ),
529 cont,
530 this->exitCode( ) ) );
534 Exceptions::RedefiningLexical::RedefiningLexical( const char * id )
535 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), id_( id )
538 Exceptions::RedefiningLexical::~RedefiningLexical( )
541 void
542 Exceptions::RedefiningLexical::display( std::ostream & os ) const
544 os << "Redefining " << id_ << std::endl ;
548 Exceptions::RedefiningDynamic::RedefiningDynamic( const char * id )
549 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), id_( id )
552 Exceptions::RedefiningDynamic::~RedefiningDynamic( )
555 void
556 Exceptions::RedefiningDynamic::display( std::ostream & os ) const
558 os << "Redefining " << "@" << id_ << std::endl ;
562 Exceptions::NonObjectMemberAssignment::NonObjectMemberAssignment( const Ast::SourceLocation & loc, RefCountPtr< const char > valueType )
563 : Exceptions::RuntimeError( loc ), valueType_( valueType )
566 Exceptions::NonObjectMemberAssignment::~NonObjectMemberAssignment( )
569 void
570 Exceptions::NonObjectMemberAssignment::display( std::ostream & os ) const
572 os << "Only object oriented values have fields that can be assigned. This value is of type " << valueType_ << "." << std::endl ;
576 Exceptions::ElementaryWithout::ElementaryWithout( Kind kind, Ref ref, RefCountPtr< const char > valueType )
577 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), ref_( ref ), valueType_( valueType )
580 Exceptions::ElementaryWithout::~ElementaryWithout( )
583 void
584 Exceptions::ElementaryWithout::display( std::ostream & os ) const
586 os << "This " ;
587 switch( kind_ )
589 case VALUE:
590 os << "value" ;
591 break;
592 case STATE:
593 os << "state" ;
594 break;
596 os << " is of the elementary type " << valueType_ << ", which has no " ;
597 switch( ref_ )
599 case FIELD:
600 os << "fields" ;
601 break;
602 case MUTATOR:
603 os << "mutators" ;
604 break;
606 os << "." << std::endl ;
610 Exceptions::NonExistentPosition::NonExistentPosition( size_t pos, size_t maxPos )
611 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), pos_( pos ), maxPos_( maxPos )
614 Exceptions::NonExistentPosition::~NonExistentPosition( )
617 void
618 Exceptions::NonExistentPosition::display( std::ostream & os ) const
620 os << "Referencing field at position " << pos_ << " is an error since the user struct has only " << maxPos_ << " ordered fields." << std::endl ;
624 Exceptions::UnaryPrefixNotApplicable::UnaryPrefixNotApplicable( const Ast::SourceLocation & loc, const Ast::Expression * expr, RefCountPtr< const char > valueType )
625 : Exceptions::RuntimeError( loc ), expr_( expr ), valueType_( valueType ), operatorSymbol_( "< ? >" )
628 Exceptions::UnaryPrefixNotApplicable::~UnaryPrefixNotApplicable( )
631 void
632 Exceptions::UnaryPrefixNotApplicable::setOperatorSymbol( const char * operatorSymbol )
634 operatorSymbol_ = operatorSymbol;
637 void
638 Exceptions::UnaryPrefixNotApplicable::display( std::ostream & os ) const
640 if( expr_ != 0 )
642 os << "Operator " ;
643 getLoc( ).copy( & os );
644 os << " not defined for " << valueType_ << " at " << expr_->loc( ) << "." << std::endl ;
646 else
648 os << "Operator " << operatorSymbol_ << " not defined for " << valueType_ << "." << std::endl ;
653 Exceptions::UnaryPostfixNotApplicable::UnaryPostfixNotApplicable( const Ast::SourceLocation & loc, const Ast::Expression * expr, RefCountPtr< const char > valueType )
654 : Exceptions::RuntimeError( loc ), expr_( expr ), valueType_( valueType ), operatorSymbol_( "< ? >" )
657 Exceptions::UnaryPostfixNotApplicable::~UnaryPostfixNotApplicable( )
660 void
661 Exceptions::UnaryPostfixNotApplicable::setOperatorSymbol( const char * operatorSymbol )
663 operatorSymbol_ = operatorSymbol;
666 void
667 Exceptions::UnaryPostfixNotApplicable::display( std::ostream & os ) const
669 if( expr_ != 0 )
671 os << "Operator " ;
672 getLoc( ).copy( & os );
673 os << " not defined for " << valueType_ << " at " << expr_->loc( ) << "." << std::endl ;
675 else
677 os << "Operator " << operatorSymbol_ << " not defined for " << valueType_ << "." << std::endl ;
682 Exceptions::BinaryInfixNotApplicable::BinaryInfixNotApplicable( const Ast::SourceLocation & loc, const Ast::Expression * expr1, RefCountPtr< const char > valueType1, const Ast::Expression * expr2, RefCountPtr< const char > valueType2 )
683 : Exceptions::RuntimeError( loc ), expr1_( expr1 ), valueType1_( valueType1 ), expr2_( expr2 ), valueType2_( valueType2 ), operatorSymbol_( "< ? >" )
686 Exceptions::BinaryInfixNotApplicable::~BinaryInfixNotApplicable( )
689 void
690 Exceptions::BinaryInfixNotApplicable::setOperatorSymbol( const char * operatorSymbol )
692 operatorSymbol_ = operatorSymbol;
695 void
696 Exceptions::BinaryInfixNotApplicable::display( std::ostream & os ) const
698 if( expr1_ != 0 && expr2_ != 0 )
700 os << "Operator " ;
701 getLoc( ).copy( & os );
702 os << " not defined for (" << valueType1_ << "," << valueType2_ << ") at " << expr1_->loc( ) << ", " << expr2_->loc( ) << "." << std::endl ;
704 else
706 os << "Operator " << operatorSymbol_ << " not defined for (" << valueType1_ << "," << valueType2_ << ")." << std::endl ;
711 Exceptions::LookupUnknown::LookupUnknown( const Ast::SourceLocation & loc, RefCountPtr< const char > id, Type type )
712 : Exceptions::StaticInconsistency( loc ), id_( id ), type_( type )
715 Exceptions::LookupUnknown::~LookupUnknown( )
718 void
719 Exceptions::LookupUnknown::display( std::ostream & os ) const
721 switch( type_ )
723 case VARIABLE:
724 os << "The variable " << id_ << " is unbound." << std::endl ;
725 break;
726 case STATE:
727 os << "There is no state called " << id_ << " around." << std::endl ;
728 break;
729 case DYNAMIC_VARIABLE:
730 os << "There is no dynamic variable called " << id_ << " around." << std::endl ;
731 break;
732 case DYNAMIC_STATE:
733 os << "There is no dynamic state called " << id_ << " around." << std::endl ;
734 break;
735 case TYPE:
736 os << "There is no type called " << id_ << " around." << std::endl ;
737 break;
742 Exceptions::StateBeyondFunctionBoundary::StateBeyondFunctionBoundary( const Ast::SourceLocation & loc, RefCountPtr< const char > id )
743 : Exceptions::StaticInconsistency( loc ), id_( id )
746 Exceptions::StateBeyondFunctionBoundary::~StateBeyondFunctionBoundary( )
749 void
750 Exceptions::StateBeyondFunctionBoundary::display( std::ostream & os ) const
752 os << "The state " << id_ << " resides outside a function boundary." << std::endl ;
756 Exceptions::IntroducingExistingUnit::IntroducingExistingUnit( const Ast::SourceLocation & loc, RefCountPtr< const char > id )
757 : Exceptions::StaticInconsistency( loc ), id_( id )
760 Exceptions::IntroducingExistingUnit::~IntroducingExistingUnit( )
763 void
764 Exceptions::IntroducingExistingUnit::display( std::ostream & os ) const
766 os << "Inconsistent definition of the existing unit " << id_ << "." << std::endl ;
770 Exceptions::LookupUnknownUnit::LookupUnknownUnit( const Ast::SourceLocation & loc, RefCountPtr< const char > id )
771 : Exceptions::StaticInconsistency( loc ), id_( id )
774 Exceptions::LookupUnknownUnit::~LookupUnknownUnit( )
777 void
778 Exceptions::LookupUnknownUnit::display( std::ostream & os ) const
780 os << "The unit " << id_ << " is unbound" << std::endl ;
784 Exceptions::OutOfRange::OutOfRange( RefCountPtr< const char > msg )
785 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg )
788 Exceptions::OutOfRange::OutOfRange( const char * msg )
789 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
792 Exceptions::OutOfRange::OutOfRange( const Ast::SourceLocation & loc, RefCountPtr< const char > msg )
793 : Exceptions::CatchableError( loc ), msg_( msg.getPtr( ) ), msgMem_( msg )
796 Exceptions::OutOfRange::OutOfRange( const Ast::SourceLocation & loc, const char * msg )
797 : Exceptions::CatchableError( loc ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
800 Exceptions::OutOfRange::~OutOfRange( )
803 void
804 Exceptions::OutOfRange::display( std::ostream & os ) const
806 os << "Out-of-range error: " << msg_ << std::endl ;
809 RefCountPtr< const Lang::Exception >
810 Exceptions::OutOfRange::clone( const Kernel::ContRef & cont ) const
812 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "out_of_range" ) );
813 std::ostringstream os;
814 display( os );
815 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
816 kind,
817 RefCountPtr< const Lang::String >( new Lang::String( "(core, generic)", true ) ),
818 Lang::THE_VOID,
819 strrefdup( os ),
820 cont,
821 this->exitCode( ) ) );
825 Exceptions::FontProblem::FontProblem( const RefCountPtr< const Lang::Symbol > & PostScript_name, RefCountPtr< const char > msg, bool justAWarning )
826 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), PostScript_name_( PostScript_name ), msg_( msg.getPtr( ) ), msgMem_( msg ), justAWarning_( justAWarning )
829 Exceptions::FontProblem::FontProblem( const RefCountPtr< const Lang::Symbol > & PostScript_name, const char * msg, bool justAWarning )
830 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), PostScript_name_( PostScript_name ), msg_( msg ), msgMem_( NullPtr< const char >( ) ), justAWarning_( justAWarning )
833 Exceptions::FontProblem::FontProblem( const RefCountPtr< const Lang::Symbol > & PostScript_name, const Ast::SourceLocation & loc, RefCountPtr< const char > msg, bool justAWarning )
834 : Exceptions::CatchableError( loc ), PostScript_name_( PostScript_name ), msg_( msg.getPtr( ) ), msgMem_( msg ), justAWarning_( justAWarning )
837 Exceptions::FontProblem::FontProblem( const RefCountPtr< const Lang::Symbol > & PostScript_name, const Ast::SourceLocation & loc, const char * msg, bool justAWarning )
838 : Exceptions::CatchableError( loc ), PostScript_name_( PostScript_name ), msg_( msg ), msgMem_( NullPtr< const char >( ) ), justAWarning_( justAWarning )
841 Exceptions::FontProblem::~FontProblem( )
844 void
845 Exceptions::FontProblem::display( std::ostream & os ) const
847 os << "Font " << ( justAWarning_ ? "warning" : "error" ) << " using " << PostScript_name_->name( ) << ": " << msg_ << std::endl ;
850 RefCountPtr< const Lang::Exception >
851 Exceptions::FontProblem::clone( const Kernel::ContRef & cont ) const
853 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
854 std::ostringstream os;
855 display( os );
856 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
857 kind,
858 RefCountPtr< const Lang::String >( new Lang::String( "(font problem)", true ) ),
859 Lang::THE_VOID,
860 strrefdup( os ),
861 cont,
862 this->exitCode( ) ) );
866 Exceptions::NonVoidStatement::NonVoidStatement( const Ast::SourceLocation & loc, RefCountPtr< const Lang::Value > val )
867 : Exceptions::RuntimeError( loc ), val_( val )
870 Exceptions::NonVoidStatement::~NonVoidStatement( )
873 void
874 Exceptions::NonVoidStatement::display( std::ostream & os ) const
876 os << "No implicit ignore of non-void value (of type " << val_->getTypeName( ) << ")" << std::endl ;
879 // Exceptions::RuntimeError::RuntimeError( )
880 // : loc_( "< unlocated runtime error >" )
881 // { }
883 Exceptions::RuntimeError::~RuntimeError( )
886 Exceptions::RuntimeError::RuntimeError( const Ast::SourceLocation & loc )
887 : loc_( loc )
890 Exceptions::RuntimeError::RuntimeError( Ast::Expression * expr )
891 : loc_( expr->loc( ) )
894 const Ast::SourceLocation &
895 Exceptions::RuntimeError::getLoc( ) const
897 return loc_;
901 Exceptions::CatchableError::CatchableError( const Ast::SourceLocation & loc )
902 : Exceptions::RuntimeError( loc )
905 Exceptions::CatchableError::CatchableError( Ast::Expression * expr )
906 : Exceptions::RuntimeError( expr )
909 Exceptions::CatchableError::~CatchableError( )
913 Exceptions::UncaughtError::UncaughtError( const RefCountPtr< const Lang::Exception > & ball )
914 : Exceptions::RuntimeError( ball->loc( ) ), ball_( ball )
917 Exceptions::UncaughtError::~UncaughtError( )
920 void
921 Exceptions::UncaughtError::display( std::ostream & os ) const
923 os << "Uncaught error: " ;
924 ball_->show( os );
925 os << std::endl ;
928 Interaction::ExitCode
929 Exceptions::UncaughtError::exitCode( ) const
931 return ball_->exitCode( );
935 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 )
936 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), source_( source ), details_( details ), message_( message )
939 Exceptions::UserError::~UserError( )
942 void
943 Exceptions::UserError::display( ostream & os ) const
945 os << "'" ;
946 kind_->show( os );
947 os << " error in " << source_->val_ << ": " << message_ << std::endl ;
950 RefCountPtr< const Lang::Exception >
951 Exceptions::UserError::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::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 )
966 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), source_( source ), details_( details ), message_( message )
969 Exceptions::UserOutOfRange::~UserOutOfRange( )
972 void
973 Exceptions::UserOutOfRange::display( ostream & os ) const
975 os << "In " << source_->val_ << ", argument " << details_->val_
976 << ", out-of-range: " << message_ << std::endl ;
979 RefCountPtr< const Lang::Exception >
980 Exceptions::UserOutOfRange::clone( const Kernel::ContRef & cont ) const
982 std::ostringstream os;
983 display( os );
984 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
985 kind_,
986 source_,
987 details_,
988 strrefdup( os ),
989 cont,
990 this->exitCode( ) ) );
994 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 )
995 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), kind_( kind ), source_( source ), details_( details ), expectedType_( expectedType ), valueType_( valueType )
998 Exceptions::UserTypeMismatch::~UserTypeMismatch( )
1001 void
1002 Exceptions::UserTypeMismatch::display( ostream & os ) const
1004 os << "In " << source_->val_ << ", argument " << details_->val_
1005 << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1008 RefCountPtr< const Lang::Exception >
1009 Exceptions::UserTypeMismatch::clone( const Kernel::ContRef & cont ) const
1011 std::ostringstream os;
1012 display( os );
1013 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1014 kind_,
1015 source_,
1016 details_,
1017 strrefdup( os ),
1018 cont,
1019 this->exitCode( ) ) );
1023 Exceptions::InternalError::InternalError( const Ast::SourceLocation & loc, RefCountPtr< const char > msg, bool justAWarning )
1024 : Exceptions::RuntimeError( loc ), msg_( msg.getPtr( ) ), msgMem_( msg ), justAWarning_( justAWarning )
1027 Exceptions::InternalError::InternalError( const Ast::SourceLocation & loc, const char * msg, bool justAWarning )
1028 : Exceptions::RuntimeError( loc ), msg_( msg ), msgMem_( NullPtr< const char >( ) ), justAWarning_( justAWarning )
1031 Exceptions::InternalError::InternalError( RefCountPtr< const char > msg, bool justAWarning )
1032 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg ), justAWarning_( justAWarning )
1035 Exceptions::InternalError::InternalError( const char * msg, bool justAWarning )
1036 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) ), justAWarning_( justAWarning )
1039 Exceptions::InternalError::InternalError( const std::ostringstream & msg, bool justAWarning )
1040 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), msg_( strdup( msg.str( ).c_str( ) ) ), msgMem_( msg_ ), justAWarning_( justAWarning )
1043 Exceptions::InternalError::~InternalError( )
1046 void
1047 Exceptions::InternalError::display( ostream & os ) const
1049 os << "Internal " << ( justAWarning_ ? "warning" : "error" ) << ": " << msg_ << std::endl ;
1053 Exceptions::ExternalError::ExternalError( RefCountPtr< const char > msg, bool justAWarning )
1054 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg.getPtr( ) ), msgMem_( msg ), justAWarning_( justAWarning )
1057 Exceptions::ExternalError::ExternalError( const char * msg, bool justAWarning )
1058 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), msg_( msg ), msgMem_( NullPtr< const char >( ) ), justAWarning_( justAWarning )
1061 Exceptions::ExternalError::~ExternalError( )
1064 void
1065 Exceptions::ExternalError::display( ostream & os ) const
1067 os << "External " << ( justAWarning_ ? "warning" : "error" ) << ": " << msg_ << std::endl ;
1070 RefCountPtr< const Lang::Exception >
1071 Exceptions::ExternalError::clone( const Kernel::ContRef & cont ) const
1073 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "external" ) );
1074 std::ostringstream os;
1075 display( os );
1076 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1077 kind,
1078 RefCountPtr< const Lang::String >( new Lang::String( "(external error)", true ) ),
1079 Lang::THE_VOID,
1080 strrefdup( os ),
1081 cont,
1082 this->exitCode( ) ) );
1085 Exceptions::ExternalError *
1086 Exceptions::ExternalError::cloneTyped( ) const
1088 return new Exceptions::ExternalError( msgMem_ );
1091 Exceptions::UserArityMismatch::UserArityMismatch( const Ast::SourceLocation & callLoc, const Ast::SourceLocation & formalsLoc, size_t functionArity, size_t callArity, Type type )
1092 : Exceptions::RuntimeError( callLoc ), formalsLoc_( formalsLoc ), functionArity_( functionArity ), callArity_( callArity ), type_( type )
1095 Exceptions::UserArityMismatch::~UserArityMismatch( )
1098 void
1099 Exceptions::UserArityMismatch::display( std::ostream & os ) const
1101 os << "Function with formals at " << formalsLoc_ << " expects " << functionArity_ ;
1102 switch( type_ )
1104 case VARIABLE:
1105 os << " value arguments" ;
1106 break;
1107 case STATE:
1108 os << " state arguments" ;
1109 break;
1111 os << ", not " << callArity_ << std::endl ;
1114 Exceptions::SinkRequired::SinkRequired( const Ast::SourceLocation & formalsLoc, size_t formalsArity, size_t callArity )
1115 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc_( formalsLoc ), formalsArity_( formalsArity ), callArity_( callArity )
1118 Exceptions::SinkRequired::~SinkRequired( )
1121 void
1122 Exceptions::SinkRequired::display( std::ostream & os ) const
1124 os << "Formals at " << formalsLoc_ << " contains no sink, so passing " << callArity_ << " ordered arguments is " << callArity_ - formalsArity_ << " too many." << std::endl ;
1128 Exceptions::NamedFormalMismatch::NamedFormalMismatch( const Ast::SourceLocation & formalsLoc, RefCountPtr< const char > name, Exceptions::NamedFormalMismatch::Type type )
1129 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc_( formalsLoc ), name_( name ), type_( type )
1132 Exceptions::NamedFormalMismatch::~NamedFormalMismatch( )
1135 void
1136 Exceptions::NamedFormalMismatch::display( std::ostream & os ) const
1138 os << "Function with formals at " << formalsLoc_ << " has no named ";
1139 switch( type_ )
1141 case VARIABLE:
1142 os << "variable" ;
1143 break;
1144 case STATE:
1145 os << "state" ;
1146 break;
1148 os << " called " << name_ << "." << std::endl ;
1152 Exceptions::NamedFormalAlreadySpecified::NamedFormalAlreadySpecified( const Ast::SourceLocation & formalsLoc, RefCountPtr< const char > name, size_t pos, Exceptions::NamedFormalAlreadySpecified::Type type )
1153 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), formalsLoc_( formalsLoc ), name_( name ), pos_( pos ), type_( type )
1156 Exceptions::NamedFormalAlreadySpecified::~NamedFormalAlreadySpecified( )
1159 void
1160 Exceptions::NamedFormalAlreadySpecified::display( std::ostream & os ) const
1162 os << "The formal " ;
1163 switch( type_ )
1165 case VARIABLE:
1166 os << "variable" ;
1167 break;
1168 case STATE:
1169 os << "state" ;
1170 break;
1172 os << " named " << name_ << ", defined at " << formalsLoc_ << " is already defined by order, at position " << pos_ << "." << std::endl ;
1175 Exceptions::MissingArguments::MissingArguments( const Ast::SourceLocation & callLoc, const Ast::SourceLocation & formalsLoc, std::map< size_t, RefCountPtr< const char > > * missingVariables, std::map< size_t, RefCountPtr< const char > > * missingStates )
1176 : Exceptions::RuntimeError( callLoc ), formalsLoc_( formalsLoc ), missingVariables_( missingVariables ), missingStates_( missingStates )
1179 Exceptions::MissingArguments::~MissingArguments( )
1182 void
1183 Exceptions::MissingArguments::display( std::ostream & os ) const
1185 os << "Among the formals at " << formalsLoc_ ;
1186 if( missingVariables_ != NullPtr< typeof *missingVariables_ >( ) )
1188 os << ", the following variables are missing:" ;
1189 typedef typeof *missingVariables_ MapType;
1190 for( MapType::const_iterator i = missingVariables_->begin( ); i != missingVariables_->end( ); ++i )
1192 if( i != missingVariables_->begin( ) )
1194 os << "," ;
1196 os << " (" << i->first << ")" << i->second.getPtr( ) ;
1199 if( missingStates_ != NullPtr< typeof *missingStates_ >( ) )
1201 os << ", " ;
1202 if( missingVariables_ != NullPtr< typeof *missingVariables_ >( ) )
1204 os << "and " ;
1206 os << "the following states are missing:" ;
1207 typedef typeof *missingStates_ MapType;
1208 for( MapType::const_iterator i = missingStates_->begin( ); i != missingStates_->end( ); ++i )
1210 if( i != missingStates_->begin( ) )
1212 os << "," ;
1214 os << " (" << i->first << ")" << i->second.getPtr( ) ;
1217 os << "." << std::endl ;
1221 Exceptions::CoreArityMismatch::CoreArityMismatch( const char * title, size_t functionArity, size_t callArity )
1222 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title_( title ), titleMem_( NullPtr< const char >( ) ), functionArityLow_( functionArity ), functionArityHigh_( functionArity ), callArity_( callArity )
1225 Exceptions::CoreArityMismatch::CoreArityMismatch( const char * title, size_t functionArityLow, size_t functionArityHigh, size_t callArity )
1226 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title_( title ), titleMem_( NullPtr< const char >( ) ), functionArityLow_( functionArityLow ), functionArityHigh_( functionArityHigh ), callArity_( callArity )
1229 Exceptions::CoreArityMismatch::CoreArityMismatch( const RefCountPtr< const char > & title, size_t functionArity, size_t callArity )
1230 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title_( title.getPtr( ) ), titleMem_( title ), functionArityLow_( functionArity ), functionArityHigh_( functionArity ), callArity_( callArity )
1233 Exceptions::CoreArityMismatch::CoreArityMismatch( const RefCountPtr< const char > & title, size_t functionArityLow, size_t functionArityHigh, size_t callArity )
1234 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title_( title.getPtr( ) ), titleMem_( title ), functionArityLow_( functionArityLow ), functionArityHigh_( functionArityHigh ), callArity_( callArity )
1237 Exceptions::CoreArityMismatch::~CoreArityMismatch( )
1240 void
1241 Exceptions::CoreArityMismatch::display( std::ostream & os ) const
1243 if( functionArityLow_ == functionArityHigh_ )
1245 os << "Core function " << title_ << " expects " << functionArityLow_ << " arguments, not " << callArity_ << std::endl ;
1247 else
1249 os << "Core function " << title_ << " expects [" << functionArityLow_ << ", " << functionArityHigh_ << "] arguments, not " << callArity_ << std::endl ;
1254 Exceptions::CoreNoNamedFormals::CoreNoNamedFormals( const char * title )
1255 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title_( title ), titleMem_( NullPtr< const char >( ) )
1258 Exceptions::CoreNoNamedFormals::CoreNoNamedFormals( const RefCountPtr< const char > & title )
1259 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), title_( title.getPtr( ) ), titleMem_( title )
1262 Exceptions::CoreNoNamedFormals::~CoreNoNamedFormals( )
1265 void
1266 Exceptions::CoreNoNamedFormals::display( std::ostream & os ) const
1268 os << "Core function " << title_ << " does not accept named arguments." << std::endl ;
1272 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1273 const char * title,
1274 const Ast::SourceLocation & argLoc,
1275 RefCountPtr< const char > valueType,
1276 RefCountPtr< const char > expectedType )
1277 : Exceptions::RuntimeError( callLoc ),
1278 title_( title ),
1279 titleMem_( NullPtr< const char >( ) ),
1280 argLoc_( argLoc ),
1281 valueType_( valueType ),
1282 expectedType_( expectedType )
1285 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1286 RefCountPtr< const char > title,
1287 const Ast::SourceLocation & argLoc,
1288 RefCountPtr< const char > valueType,
1289 RefCountPtr< const char > expectedType )
1290 : Exceptions::RuntimeError( callLoc ),
1291 title_( title.getPtr( ) ),
1292 titleMem_( title ),
1293 argLoc_( argLoc ),
1294 valueType_( valueType ),
1295 expectedType_( expectedType )
1298 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1299 const char * title,
1300 Kernel::Arguments & args,
1301 size_t argNo,
1302 RefCountPtr< const char > expectedType )
1303 : Exceptions::RuntimeError( callLoc ),
1304 title_( title ),
1305 titleMem_( NullPtr< const char >( ) ),
1306 argLoc_( args.getLoc( argNo ) ),
1307 valueType_( args.getValue( argNo )->getTypeName( ) ),
1308 expectedType_( expectedType )
1311 Exceptions::CoreTypeMismatch::CoreTypeMismatch( const Ast::SourceLocation & callLoc,
1312 RefCountPtr< const char > title,
1313 Kernel::Arguments & args,
1314 size_t argNo,
1315 RefCountPtr< const char > expectedType )
1316 : Exceptions::RuntimeError( callLoc ),
1317 title_( title.getPtr( ) ),
1318 titleMem_( title ),
1319 argLoc_( args.getLoc( argNo ) ),
1320 valueType_( args.getValue( argNo )->getTypeName( ) ),
1321 expectedType_( expectedType )
1324 Exceptions::CoreTypeMismatch::~CoreTypeMismatch( )
1327 void
1328 Exceptions::CoreTypeMismatch::display( std::ostream & os ) const
1330 os << "Core function " << title_ << ", argument ";
1331 // if( argName_ != 0 )
1332 // {
1333 // os << "\"" << argName_ << "\" " ;
1334 // }
1335 os << "at " << argLoc_ << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1339 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1340 const char * title,
1341 const Ast::SourceLocation & argLoc,
1342 RefCountPtr< const char > valueType,
1343 RefCountPtr< const char > expectedType )
1344 : Exceptions::RuntimeError( callLoc ),
1345 title_( title ),
1346 titleMem_( NullPtr< const char >( ) ),
1347 argLoc_( argLoc ),
1348 valueType_( valueType ),
1349 expectedType_( expectedType )
1352 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1353 RefCountPtr< const char > title,
1354 const Ast::SourceLocation & argLoc,
1355 RefCountPtr< const char > valueType,
1356 RefCountPtr< const char > expectedType )
1357 : Exceptions::RuntimeError( callLoc ),
1358 title_( title.getPtr( ) ),
1359 titleMem_( title ),
1360 argLoc_( argLoc ),
1361 valueType_( valueType ),
1362 expectedType_( expectedType )
1365 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1366 const char * title,
1367 Kernel::Arguments & args,
1368 size_t argNo,
1369 RefCountPtr< const char > expectedType )
1370 : Exceptions::RuntimeError( callLoc ),
1371 title_( title ),
1372 titleMem_( NullPtr< const char >( ) ),
1373 argLoc_( args.getStateLoc( argNo ) ),
1374 valueType_( args.getState( argNo )->getTypeName( ) ),
1375 expectedType_( expectedType )
1378 Exceptions::CoreStateTypeMismatch::CoreStateTypeMismatch( const Ast::SourceLocation & callLoc,
1379 RefCountPtr< const char > title,
1380 Kernel::Arguments & args,
1381 size_t argNo,
1382 RefCountPtr< const char > expectedType )
1383 : Exceptions::RuntimeError( callLoc ),
1384 title_( title.getPtr( ) ),
1385 titleMem_( title ),
1386 argLoc_( args.getStateLoc( argNo ) ),
1387 valueType_( args.getState( argNo )->getTypeName( ) ),
1388 expectedType_( expectedType )
1391 Exceptions::CoreStateTypeMismatch::~CoreStateTypeMismatch( )
1394 void
1395 Exceptions::CoreStateTypeMismatch::display( std::ostream & os ) const
1397 os << "Core function " << title_ << ", state ";
1398 // if( argName_ != 0 )
1399 // {
1400 // os << "\"" << argName_ << "\" " ;
1401 // }
1402 os << "at " << argLoc_ << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1406 Exceptions::CoreDynamicTypeMismatch::CoreDynamicTypeMismatch( const Ast::SourceLocation & callLoc,
1407 const char * title,
1408 const char * id,
1409 RefCountPtr< const char > valueType,
1410 RefCountPtr< const char > expectedType )
1411 : Exceptions::RuntimeError( callLoc ),
1412 title_( title ),
1413 titleMem_( NullPtr< const char >( ) ),
1414 id_( id ),
1415 idMem_( NullPtr< const char >( ) ),
1416 valueType_( valueType ),
1417 expectedType_( expectedType )
1420 Exceptions::CoreDynamicTypeMismatch::~CoreDynamicTypeMismatch( )
1423 void
1424 Exceptions::CoreDynamicTypeMismatch::display( std::ostream & os ) const
1426 os << "Core function " << title_ << " encountered a type mismatch in the dynamic variable @" << id_
1427 << ": expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1430 Exceptions::ContinuationTypeMismatch::ContinuationTypeMismatch( const Kernel::Continuation * locationCont,
1431 RefCountPtr< const char > valueType,
1432 RefCountPtr< const char > expectedType )
1433 : Exceptions::RuntimeError( locationCont->traceLoc( ) ),
1434 valueType_( valueType ),
1435 expectedType_( expectedType )
1438 Exceptions::ContinuationTypeMismatch::~ContinuationTypeMismatch( )
1441 void
1442 Exceptions::ContinuationTypeMismatch::display( std::ostream & os ) const
1444 os << "The continuation expected a " << expectedType_ << ", got a " << valueType_ << "." << std::endl ;
1448 Exceptions::CoreOutOfRange::CoreOutOfRange( const Ast::SourceLocation & callLoc, const char * title, Kernel::Arguments & args, size_t argNo, RefCountPtr< const char > msg )
1449 : Exceptions::CatchableError( callLoc ), title_( title ), argNo_( argNo ), argLoc_( args.getLoc( argNo ) ), msg_( msg.getPtr( ) ), msgMem_( msg )
1452 Exceptions::CoreOutOfRange::CoreOutOfRange( const Ast::SourceLocation & callLoc, const char * title, Kernel::Arguments & args, size_t argNo, const char * msg )
1453 : Exceptions::CatchableError( callLoc ), title_( title ), argNo_( argNo ), argLoc_( args.getLoc( argNo ) ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
1456 Exceptions::CoreOutOfRange::CoreOutOfRange( const char * title, Kernel::Arguments & args, size_t argNo, RefCountPtr< const char > msg )
1457 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), title_( title ), argNo_( argNo ), argLoc_( args.getLoc( argNo ) ), msg_( msg.getPtr( ) ), msgMem_( msg )
1460 Exceptions::CoreOutOfRange::CoreOutOfRange( const char * title, Kernel::Arguments & args, size_t argNo, const char * msg )
1461 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), title_( title ), argNo_( argNo ), argLoc_( args.getLoc( argNo ) ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
1464 Exceptions::CoreOutOfRange::~CoreOutOfRange( )
1467 void
1468 Exceptions::CoreOutOfRange::setMessage( RefCountPtr< const char > msg )
1470 msg_ = msg.getPtr( );
1471 msgMem_ = msg;
1474 void
1475 Exceptions::CoreOutOfRange::display( std::ostream & os ) const
1477 os << "Core function " << title_ << ": " ;
1478 os << "Argument at " << argLoc_ << " is out of range; " << msg_ << std::endl ;
1481 RefCountPtr< const Lang::Exception >
1482 Exceptions::CoreOutOfRange::clone( const Kernel::ContRef & cont ) const
1484 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "out_of_range" ) );
1485 std::ostringstream os;
1486 display( os );
1487 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1488 kind,
1489 RefCountPtr< const Lang::String >( new Lang::String( title_, true ) ),
1490 RefCountPtr< const Lang::Integer >( new Lang::Integer( argNo_ ) ),
1491 strrefdup( os ),
1492 cont,
1493 this->exitCode( ) ) );
1496 Exceptions::CoreRequirement::CoreRequirement( RefCountPtr< const char > msg, const char * title, const Ast::SourceLocation & callLoc )
1497 : Exceptions::CatchableError( callLoc ), title_( title ), msg_( msg.getPtr( ) ), msgMem_( msg )
1500 Exceptions::CoreRequirement::CoreRequirement( const char * msg, const char * title, const Ast::SourceLocation & callLoc )
1501 : Exceptions::CatchableError( callLoc ), title_( title ), msg_( msg ), msgMem_( NullPtr< const char >( ) )
1504 Exceptions::CoreRequirement::~CoreRequirement( )
1507 void
1508 Exceptions::CoreRequirement::display( std::ostream & os ) const
1510 os << "Core function " << title_ << ": " << msg_ << std::endl ;
1513 RefCountPtr< const Lang::Exception >
1514 Exceptions::CoreRequirement::clone( const Kernel::ContRef & cont ) const
1516 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
1517 std::ostringstream os;
1518 display( os );
1519 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1520 kind,
1521 RefCountPtr< const Lang::String >( new Lang::String( title_, true ) ),
1522 Lang::THE_VOID,
1523 strrefdup( os ),
1524 cont,
1525 this->exitCode( ) ) );
1529 Exceptions::BuildRequirement::BuildRequirement( const char * dependency, const char * title, const Ast::SourceLocation & callLoc )
1530 : Exceptions::CatchableError( callLoc ), title_( title ), dependency_( dependency )
1533 Exceptions::BuildRequirement::~BuildRequirement( )
1536 void
1537 Exceptions::BuildRequirement::display( std::ostream & os ) const
1539 os << "Core function stub " << title_ << ": Shapes was built without " << dependency_ << ", so this function cannot be called." << std::endl ;
1542 RefCountPtr< const Lang::Exception >
1543 Exceptions::BuildRequirement::clone( const Kernel::ContRef & cont ) const
1545 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
1546 std::ostringstream os;
1547 display( os );
1548 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1549 kind,
1550 RefCountPtr< const Lang::String >( new Lang::String( title_, true ) ),
1551 Lang::THE_VOID,
1552 strrefdup( os ),
1553 cont,
1554 this->exitCode( ) ) );
1558 Exceptions::TeXLabelError::TeXLabelError( bool quoted, const char * region, RefCountPtr< const char > summary, RefCountPtr< const char > details, const Ast::SourceLocation & loc )
1559 : Exceptions::RuntimeError( loc ), strLoc_( loc ), quoted_( quoted ), region_( region ), summary_( summary ), details_( details )
1562 Exceptions::TeXLabelError::~TeXLabelError( )
1565 void
1566 Exceptions::TeXLabelError::display( ostream & os ) const
1568 if( quoted_ )
1570 os << "TeX error in " << region_ ;
1572 else
1574 os << "Error in TeX " << region_ ;
1576 if( ! strLoc_.isUnknown( ) )
1578 os << " at " << strLoc_ ;
1580 os << ": " ;
1581 if( quoted_ )
1583 os << "\"" ;
1585 os << summary_ ;
1586 if( quoted_ )
1588 os << "\"" ;
1590 os << std::endl ;
1591 if( details_ != NullPtr< const char >( ) )
1593 Exceptions::prefixEachLine( additionalLinesPrefix, details_, os );
1598 Exceptions::StaticTeXLabelError::StaticTeXLabelError( bool quoted, const char * region, RefCountPtr< const char > summary, RefCountPtr< const char > details, const Ast::SourceLocation & loc )
1599 : Exceptions::StaticInconsistency( loc ), quoted_( quoted ), region_( region ), summary_( summary ), details_( details )
1602 Exceptions::StaticTeXLabelError::~StaticTeXLabelError( )
1605 void
1606 Exceptions::StaticTeXLabelError::display( ostream & os ) const
1608 if( quoted_ )
1610 os << "TeX error in " << region_ ;
1612 else
1614 os << "Error in TeX " << region_ ;
1616 os << ": " ;
1617 if( quoted_ )
1619 os << "\"" ;
1621 os << summary_ ;
1622 if( quoted_ )
1624 os << "\"" ;
1626 os << std::endl ;
1627 if( details_ != NullPtr< const char >( ) )
1629 Exceptions::prefixEachLine( additionalLinesPrefix, details_, os );
1634 Exceptions::MultipleDynamicBind::MultipleDynamicBind( const char * id, const Ast::SourceLocation & loc, const Ast::SourceLocation & prevLoc )
1635 : Exceptions::RuntimeError( loc ), id_( id ), prevLoc_( prevLoc )
1638 Exceptions::MultipleDynamicBind::~MultipleDynamicBind( )
1641 void
1642 Exceptions::MultipleDynamicBind::display( std::ostream & os ) const
1644 os << "This dynamic binding of " << id_ << " is merged with the conflicting binding at " << prevLoc_ << "." << std::endl ;
1648 Exceptions::UndefinedEscapeContinuation::UndefinedEscapeContinuation( const char * id, const Ast::SourceLocation & loc )
1649 : Exceptions::RuntimeError( loc ), id_( id )
1652 Exceptions::UndefinedEscapeContinuation::~UndefinedEscapeContinuation( )
1655 void
1656 Exceptions::UndefinedEscapeContinuation::display( std::ostream & os ) const
1658 os << "The escape continuation " << id_ << " was not defined in the dynamic context." << std::endl ;
1662 Exceptions::DeadStateAccess::DeadStateAccess( )
1663 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1666 Exceptions::DeadStateAccess::~DeadStateAccess( )
1669 void
1670 Exceptions::DeadStateAccess::display( std::ostream & os ) const
1672 os << "Accessing dead state." << std::endl ;
1676 Exceptions::UnFreezable::UnFreezable( )
1677 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1680 Exceptions::UnFreezable::~UnFreezable( )
1683 void
1684 Exceptions::UnFreezable::display( std::ostream & os ) const
1686 os << "The state cannot be frozen." << std::endl ;
1690 Exceptions::UnPeekable::UnPeekable( )
1691 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1694 Exceptions::UnPeekable::~UnPeekable( )
1697 void
1698 Exceptions::UnPeekable::display( std::ostream & os ) const
1700 os << "The state cannot be peeked. Consider freezing it." << std::endl ;
1704 Exceptions::UninitializedAccess::UninitializedAccess( )
1705 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION )
1708 Exceptions::UninitializedAccess::~UninitializedAccess( )
1711 void
1712 Exceptions::UninitializedAccess::display( std::ostream & os ) const
1714 os << "The accessed variable or state has not been initialized yet." << std::endl ;
1718 Exceptions::DtMinError::DtMinError( double dt )
1719 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), dt_( dt )
1722 Exceptions::DtMinError::~DtMinError( )
1725 void
1726 Exceptions::DtMinError::display( std::ostream & os ) const
1728 os << "Path segment too long in relation to arcdelta: dt = " << dt_ << " < " << Computation::the_dtMin << ". Either increase arcdelta, or inhibit this error." << std::endl ;
1731 RefCountPtr< const Lang::Exception >
1732 Exceptions::DtMinError::clone( const Kernel::ContRef & cont ) const
1734 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "dtmin" ) );
1735 std::ostringstream os;
1736 display( os );
1737 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1738 kind,
1739 RefCountPtr< const Lang::String >( new Lang::String( "(core path computation)", true ) ),
1740 RefCountPtr< const Lang::Float >( new Lang::Float( dt_ / Computation::the_dtMin ) ),
1741 strrefdup( os ),
1742 cont,
1743 this->exitCode( ) ) );
1747 Exceptions::AffineTransformKillsPlane::AffineTransformKillsPlane( double sigma2 )
1748 : Exceptions::CatchableError( Ast::THE_UNKNOWN_LOCATION ), sigma2_( sigma2 )
1751 Exceptions::AffineTransformKillsPlane::~AffineTransformKillsPlane( )
1754 void
1755 Exceptions::AffineTransformKillsPlane::display( std::ostream & os ) const
1757 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 ;
1760 RefCountPtr< const Lang::Exception >
1761 Exceptions::AffineTransformKillsPlane::clone( const Kernel::ContRef & cont ) const
1763 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "numeric" ) );
1764 std::ostringstream os;
1765 display( os );
1766 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1767 kind,
1768 RefCountPtr< const Lang::String >( new Lang::String( "(core float triple computation)", true ) ),
1769 Lang::THE_VOID,
1770 strrefdup( os ),
1771 cont,
1772 this->exitCode( ) ) );
1775 Exceptions::MissingFontMetrics::MissingFontMetrics( RefCountPtr< const char > fontname, const std::list< std::string > * searchPath )
1776 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), fontname_( fontname ), searchPath_( searchPath )
1779 Exceptions::MissingFontMetrics::~MissingFontMetrics( )
1782 void
1783 Exceptions::MissingFontMetrics::display( std::ostream & os ) const
1785 os << "The font metrics for " << fontname_ << ", named " << fontname_ << ".afm, could not be found in {" ;
1786 typedef typeof *searchPath_ ListType;
1787 for( ListType::const_iterator i = searchPath_->begin( ); i != searchPath_->end( ); ++i )
1789 os << " " << *i ;
1791 os << " }." << std::endl ;
1795 Exceptions::FontMetricsError::FontMetricsError( const RefCountPtr< const char > & fontname, const RefCountPtr< const char > & message )
1796 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION ), fontname_( fontname ), message_( message )
1799 Exceptions::FontMetricsError::~FontMetricsError( )
1802 void
1803 Exceptions::FontMetricsError::display( std::ostream & os ) const
1805 os << "There was a problem with the font metrics for " << fontname_ << ": " << message_ << std::endl ;
1809 Exceptions::InsertingEmptyPage::InsertingEmptyPage( const Ast::SourceLocation & loc )
1810 : Exceptions::CatchableError( loc )
1813 Exceptions::InsertingEmptyPage::~InsertingEmptyPage( )
1816 void
1817 Exceptions::InsertingEmptyPage::display( std::ostream & os ) const
1819 os << "Attempt to place empty page in catalog." << std::endl ;
1822 RefCountPtr< const Lang::Exception >
1823 Exceptions::InsertingEmptyPage::clone( const Kernel::ContRef & cont ) const
1825 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
1826 std::ostringstream os;
1827 display( os );
1828 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1829 kind,
1830 RefCountPtr< const Lang::String >( new Lang::String( "(core exception)", true ) ),
1831 Lang::THE_VOID,
1832 strrefdup( os ),
1833 cont,
1834 this->exitCode( ) ) );
1838 Exceptions::InvalidGraphKeyType::InvalidGraphKeyType( )
1839 : Shapes::Exceptions::InternalError( "Graph key was not of type §Symbol or §Integer." )
1842 Exceptions::InvalidGraphKeyType::~InvalidGraphKeyType( )
1845 Exceptions::GraphKeyTypeMismatch::GraphKeyTypeMismatch( const Ast::SourceLocation & loc, const char * hint, RefCountPtr< const char > valueType )
1846 : Shapes::Exceptions::TypeMismatch( loc, hint, valueType, expectedType )
1849 Exceptions::GraphKeyTypeMismatch::~GraphKeyTypeMismatch( )
1852 RefCountPtr< const char > Exceptions::GraphKeyTypeMismatch::expectedType = Helpers::typeSetString( Lang::Symbol::staticTypeName( ), Lang::Integer::staticTypeName( ) );
1853 RefCountPtr< const char > Exceptions::GraphKeyTypeMismatch::expectedTypeOrNode = Helpers::typeSetString( Lang::Node::staticTypeName( ), Lang::Symbol::staticTypeName( ), Lang::Integer::staticTypeName( ) );
1854 RefCountPtr< const char > Exceptions::GraphKeyTypeMismatch::expectedTypeOrStructure = Helpers::typeSetString( Lang::Structure::staticTypeName( ), Lang::Symbol::staticTypeName( ), Lang::Integer::staticTypeName( ) );
1857 Exceptions::InvalidGraphKey::InvalidGraphKey( Type type )
1858 : Shapes::Exceptions::InternalError( (type == NODE) ? "Graph key does not belong to any node in the graph." : "Graph key does not belong to any partition in the graph." )
1861 Exceptions::InvalidGraphKey::~InvalidGraphKey( )
1864 Exceptions::GraphKeyOutOfRange::GraphKeyOutOfRange( Type type, const Ast::SourceLocation & callLoc, const char * title, Kernel::Arguments & args, size_t argNo )
1865 : Shapes::Exceptions::CoreOutOfRange( callLoc, title, args, argNo, "" ), type_( type )
1867 RefCountPtr< const Lang::Value > key = args.getValue( argNo );
1868 std::ostringstream oss;
1869 switch( type_ )
1871 case NODE:
1872 oss << "The node key " ;
1873 key->show( oss );
1874 oss << " does not belong to any node in the graph." ;
1875 break;
1876 case PARTITION:
1877 oss << "The partition key " ;
1878 key->show( oss );
1879 oss << " does not belong to any partition in the graph." ;
1880 break;
1882 setMessage( strrefdup( oss ) );
1885 Exceptions::GraphKeyOutOfRange::~GraphKeyOutOfRange( )
1889 Exceptions::InvalidGraphElement::InvalidGraphElement( Type type, const Ast::SourceLocation & loc )
1890 : Exceptions::CatchableError( loc ), type_( type )
1893 Exceptions::InvalidGraphElement::~InvalidGraphElement( )
1896 void
1897 Exceptions::InvalidGraphElement::display( std::ostream & os ) const
1899 os << "The " ;
1900 switch( type_ )
1902 case NODE:
1903 os << "node" ;
1904 break;
1905 case EDGE:
1906 os << "edge" ;
1907 break;
1909 os << " does not belong to the graph." << std::endl ;
1912 RefCountPtr< const Lang::Exception >
1913 Exceptions::InvalidGraphElement::clone( const Kernel::ContRef & cont ) const
1915 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "type_mismatch" ) );
1916 std::ostringstream os;
1917 display( os );
1918 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1919 kind,
1920 RefCountPtr< const Lang::String >( new Lang::String( "(graph operation)", true ) ),
1921 Lang::THE_VOID,
1922 strrefdup( os ),
1923 cont,
1924 this->exitCode( ) ) );
1927 Exceptions::EdgeTraceError::EdgeTraceError( Type type, const RefCountPtr< const Lang::Value > & edgeKeyFrom, const RefCountPtr< const Lang::Value > & edgeKeyTo, const RefCountPtr< const Lang::Value > & nodeKey, const Ast::SourceLocation & loc )
1928 : Exceptions::CatchableError( loc ), type_( type ), edgeKeyFrom_( edgeKeyFrom ), edgeKeyTo_( edgeKeyTo ), nodeKey_( nodeKey )
1931 Exceptions::EdgeTraceError::~EdgeTraceError( )
1934 void
1935 Exceptions::EdgeTraceError::display( std::ostream & os ) const
1937 switch( type_ )
1939 case UNDIRECTED:
1940 os << "The undirected edge with node keys " ;
1941 edgeKeyFrom_->show( os );
1942 os << " and " ;
1943 edgeKeyTo_->show( os );
1944 os << " cannot be traced (or backtraced) from the node with key " ;
1945 nodeKey_->show( os );
1946 os << "." << std::endl ;
1947 break;
1948 case TRACE:
1949 case BACKTRACE:
1950 os << "The directed edge with source node key " ;
1951 edgeKeyFrom_->show( os );
1952 os << " and target node key " ;
1953 edgeKeyTo_->show( os );
1954 os << " cannot be " << ((type_ == TRACE) ? "traced" : "backtraced") << " from the node with key " ;
1955 nodeKey_->show( os );
1956 os << "." << std::endl ;
1957 break;
1961 RefCountPtr< const Lang::Exception >
1962 Exceptions::EdgeTraceError::clone( const Kernel::ContRef & cont ) const
1964 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
1965 std::ostringstream os;
1966 display( os );
1967 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
1968 kind,
1969 RefCountPtr< const Lang::String >( new Lang::String( "(edge tracing)", true ) ),
1970 Lang::THE_VOID,
1971 strrefdup( os ),
1972 cont,
1973 this->exitCode( ) ) );
1976 Exceptions::GraphDomainError::GraphDomainError( Type type, bool directed, const RefCountPtr< const Lang::Value > & edgeKeyFrom, const RefCountPtr< const Lang::Value > & edgeKeyTo, const Ast::SourceLocation & loc )
1977 : Exceptions::CatchableError( loc ), type_( type ), directed_( directed ), edgeKeyFrom_( edgeKeyFrom ), edgeKeyTo_( edgeKeyTo )
1980 Exceptions::GraphDomainError::~GraphDomainError( )
1983 void
1984 Exceptions::GraphDomainError::display( std::ostream & os ) const
1986 if( directed_ ){
1987 os << "The directed edge from " ;
1988 edgeKeyFrom_->show( os );
1989 os << " to " ;
1990 edgeKeyTo_->show( os );
1991 }else{
1992 os << "The undirected edge between " ;
1993 edgeKeyFrom_->show( os );
1994 os << " and " ;
1995 edgeKeyTo_->show( os );
1997 os << " is not allowed since the graph domain does not permit " ;
1998 switch( type_ ){
1999 case DIRECTED:
2000 os << "directed" ;
2001 break;
2002 case UNDIRECTED:
2003 os << "undirected" ;
2004 break;
2005 case LOOPS:
2006 os << "loop" ;
2007 break;
2008 case PARALLEL:
2009 os << "parallel" ;
2010 break;
2012 os << " edges." << std::endl ;
2015 RefCountPtr< const Lang::Exception >
2016 Exceptions::GraphDomainError::clone( const Kernel::ContRef & cont ) const
2018 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
2019 std::ostringstream os;
2020 display( os );
2021 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
2022 kind,
2023 RefCountPtr< const Lang::String >( new Lang::String( "(graph domain)", true ) ),
2024 Lang::THE_VOID,
2025 strrefdup( os ),
2026 cont,
2027 this->exitCode( ) ) );
2031 Exceptions::InvalidGraphPartition::InvalidGraphPartition( const RefCountPtr< const Lang::Value > & partition, const RefCountPtr< const Lang::SingleList > & partitions, const Ast::SourceLocation & loc )
2032 : Exceptions::CatchableError( loc ), partition_( partition ), partitions_( partitions )
2035 Exceptions::InvalidGraphPartition::~InvalidGraphPartition( )
2038 void
2039 Exceptions::InvalidGraphPartition::display( std::ostream & os ) const
2041 os << "The partition key " ;
2042 partition_->show( os );
2043 os << " is not among the declared keys: {" ;
2045 typedef const Lang::SingleList ArgType;
2046 RefCountPtr< const Lang::SingleListPair > p = partitions_.down_cast< const Lang::SingleListPair >( );
2047 while( p != NullPtr< const Lang::SingleListPair >( ) ){
2048 RefCountPtr< const Lang::Value > val = p->car_->getUntyped( );
2049 os << " " ;
2050 val->show( os );
2051 p = p->cdr_.down_cast< const Lang::SingleListPair >( );
2054 os << " }." << std::endl ;
2057 RefCountPtr< const Lang::Exception >
2058 Exceptions::InvalidGraphPartition::clone( const Kernel::ContRef & cont ) const
2060 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
2061 std::ostringstream os;
2062 display( os );
2063 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
2064 kind,
2065 RefCountPtr< const Lang::String >( new Lang::String( "(graph partition)", true ) ),
2066 Lang::THE_VOID,
2067 strrefdup( os ),
2068 cont,
2069 this->exitCode( ) ) );
2073 Exceptions::GraphPartitionViolation::GraphPartitionViolation( const RefCountPtr< const Lang::Value > & sourceKey, const RefCountPtr< const Lang::Value > & targetKey, const RefCountPtr< const Lang::Value > & partition, const Ast::SourceLocation & loc )
2074 : Exceptions::CatchableError( loc ), sourceKey_( sourceKey ), targetKey_( targetKey ), partition_( partition )
2077 Exceptions::GraphPartitionViolation::~GraphPartitionViolation( )
2080 void
2081 Exceptions::GraphPartitionViolation::display( std::ostream & os ) const
2083 os << "Edge incident to nodes with keys " ;
2084 sourceKey_->show( os );
2085 os << " and " ;
2086 targetKey_->show( os );
2087 os << " violates the graph partitioning, with both nodes having the partition key " ;
2088 partition_->show( os );
2089 os << "." << std::endl ;
2092 RefCountPtr< const Lang::Exception >
2093 Exceptions::GraphPartitionViolation::clone( const Kernel::ContRef & cont ) const
2095 static RefCountPtr< const Lang::Symbol > kind( new Lang::Symbol( "misc" ) );
2096 std::ostringstream os;
2097 display( os );
2098 return RefCountPtr< const Lang::Exception >( new Lang::Exception( this->getLoc( ),
2099 kind,
2100 RefCountPtr< const Lang::String >( new Lang::String( "(graph partition violation)", true ) ),
2101 Lang::THE_VOID,
2102 strrefdup( os ),
2103 cont,
2104 this->exitCode( ) ) );
2108 Exceptions::UndefinedCrossRef::UndefinedCrossRef( const Ast::SourceLocation & loc, RefCountPtr< const char > ref )
2109 : Exceptions::PostCondition( loc ), ref_( ref )
2112 Exceptions::UndefinedCrossRef::~UndefinedCrossRef( )
2115 void
2116 Exceptions::UndefinedCrossRef::display( std::ostream & os ) const
2118 os << "The cross reference \"" << ref_ << "\" is not defined." << std::endl ;
2121 Exceptions::BadSetValueState::BadSetValueState( )
2122 : Exceptions::InternalError( "Setting the value of a variable which is not in the right state." )
2125 Exceptions::BadSetValueState::~BadSetValueState( )
2129 void
2130 Exceptions::prefixEachLine( const std::string & prefix, std::istream & src, std::ostream & dst )
2132 std::string line;
2133 for( std::getline( src, line ); ! src.eof( ); std::getline( src, line ) )
2135 dst << prefix << line << std::endl ;
2139 void
2140 Exceptions::prefixEachLine( const std::string & prefix, const RefCountPtr< const char > & src, std::ostream & dst )
2142 std::istringstream is( src.getPtr( ) );
2143 Exceptions::prefixEachLine( prefix, is, dst );