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
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 Henrik Tidefelt
19 #include "classexceptions.h"
22 using namespace Shapes
;
26 Exceptions::IllegalFinalReference::IllegalFinalReference( RefCountPtr
< const char > valueType
, const char * fieldID
)
27 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), valueType_( valueType
), fieldID_( fieldID
)
30 Exceptions::IllegalFinalReference::~IllegalFinalReference( )
34 Exceptions::IllegalFinalReference::display( std::ostream
& os
) const
36 os
<< "Attempt to access field of non-final class " << valueType_
<< " without home class. Use <HomeClass>#" << fieldID_
<< " instead." << std::endl
;
40 Exceptions::NonExistentMember::NonExistentMember( RefCountPtr
< const char > valueType
, const char * fieldID
)
41 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), valueType_( valueType
), fieldID_( fieldID
)
44 Exceptions::NonExistentMember::~NonExistentMember( )
48 Exceptions::NonExistentMember::display( std::ostream
& os
) const
50 os
<< "Class " << valueType_
<< " has no (non-private) field called " << fieldID_
<< "." << std::endl
;
54 Exceptions::NonExistentMutator::NonExistentMutator( RefCountPtr
< const char > valueType
, const char * mutatorID
)
55 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), valueType_( valueType
), mutatorID_( mutatorID
)
58 Exceptions::NonExistentMutator::~NonExistentMutator( )
62 Exceptions::NonExistentMutator::display( std::ostream
& os
) const
64 os
<< "State type " << valueType_
<< " has no mutator called " << mutatorID_
<< "." << std::endl
;
68 Exceptions::ProtectedMemberPublicScope::ProtectedMemberPublicScope( RefCountPtr
< const char > valueType
, const char * fieldID
)
69 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), valueType_( valueType
), fieldID_( fieldID
)
72 Exceptions::ProtectedMemberPublicScope::~ProtectedMemberPublicScope( )
76 Exceptions::ProtectedMemberPublicScope::display( std::ostream
& os
) const
78 os
<< "Trying to access protected member " << fieldID_
<< " of class " << valueType_
<< " via public instance." << std::endl
;
82 Exceptions::MemberNotAssignable::MemberNotAssignable( RefCountPtr
< const char > valueType
, const char * fieldID
, RefCountPtr
< const char > scope
)
83 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), valueType_( valueType
), fieldID_( fieldID
), scope_( scope
)
86 Exceptions::MemberNotAssignable::~MemberNotAssignable( )
90 Exceptions::MemberNotAssignable::display( std::ostream
& os
) const
92 os
<< "In " << scope_
<< " scope of " << valueType_
<< " : The member " << fieldID_
<< " is not assignable." << std::endl
;
96 Exceptions::InstantiatingAbstractClass::InstantiatingAbstractClass( RefCountPtr
< const Lang::Class
> cls
)
97 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
)
100 Exceptions::InstantiatingAbstractClass::~InstantiatingAbstractClass( )
104 Exceptions::InstantiatingAbstractClass::display( ostream
& os
) const
106 os
<< "Trying to instantiate abstract class: " << cls_
->getPrettyName( ) << std::endl
;
110 Exceptions::FailedToDeclareClassAbstract::FailedToDeclareClassAbstract( RefCountPtr
< const Lang::Class
> cls
, const Shapes::Ast::ClassFunction
* classExpr
)
111 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
), classExpr_( classExpr
)
114 Exceptions::FailedToDeclareClassAbstract::~FailedToDeclareClassAbstract( )
118 Exceptions::FailedToDeclareClassAbstract::display( ostream
& os
) const
120 os
<< classExpr_
->loc( ) << " " << "Class " << cls_
->getPrettyName( ) << " has abstract methods but is not declared abstract: " ;
121 cls_
->showAbstractSet( os
);
126 Exceptions::RepeatedImmediateParent::RepeatedImmediateParent( RefCountPtr
< const Lang::Class
> cls
, RefCountPtr
< const Lang::Class
> parent
)
127 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
), parent_( parent
)
130 Exceptions::RepeatedImmediateParent::~RepeatedImmediateParent( )
134 Exceptions::RepeatedImmediateParent::display( ostream
& os
) const
136 os
<< "When creating the class " << cls_
->getPrettyName( ) << ", the following class is a repeated immediate parent: " << parent_
->getPrettyName( ) << std::endl
;
140 Exceptions::OverridingNonParent::OverridingNonParent( RefCountPtr
< const Lang::Class
> cls
, RefCountPtr
< const Lang::Class
> parent
)
141 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
), parent_( parent
)
144 Exceptions::OverridingNonParent::~OverridingNonParent( )
148 Exceptions::OverridingNonParent::display( ostream
& os
) const
150 os
<< "The class " << cls_
->getPrettyName( ) << " cannot override methods from the class " << parent_
->getPrettyName( ) << ", since the latter is not a parent of the former." << std::endl
;
154 Exceptions::InheritingFinal::InheritingFinal( RefCountPtr
< const Lang::Class
> cls
, RefCountPtr
< const Lang::Class
> parent
)
155 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
), parent_( parent
)
158 Exceptions::InheritingFinal::~InheritingFinal( )
162 Exceptions::InheritingFinal::display( ostream
& os
) const
164 os
<< "When creating the class " << cls_
->getPrettyName( ) << ", trying to inherit from final class: " << parent_
->getPrettyName( ) << std::endl
;
168 Exceptions::OverridingUndeclaredMethod::OverridingUndeclaredMethod( RefCountPtr
< const Lang::Class
> cls
, RefCountPtr
< const Lang::Class
> parent
, const char * id
)
169 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
), parent_( parent
), id_( id
)
172 Exceptions::OverridingUndeclaredMethod::~OverridingUndeclaredMethod( )
176 Exceptions::OverridingUndeclaredMethod::display( ostream
& os
) const
178 os
<< "In override declaration in class " << cls_
->getPrettyName( ) << ": there is no method called " << id_
<< " in class " << parent_
->getPrettyName( ) << " to override." << std::endl
;
182 Exceptions::OverridingFinalMethod::OverridingFinalMethod( RefCountPtr
< const Lang::Class
> cls
, RefCountPtr
< const Lang::Class
> parent
, const char * id
)
183 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
), parent_( parent
), id_( id
)
186 Exceptions::OverridingFinalMethod::~OverridingFinalMethod( )
190 Exceptions::OverridingFinalMethod::display( ostream
& os
) const
192 os
<< "In override declaration in class " << cls_
->getPrettyName( ) << ": The method " << id_
<< " in class " << parent_
->getPrettyName( ) << " is final." << std::endl
;
196 Exceptions::IllegalRepeatedBase::IllegalRepeatedBase( RefCountPtr
< const Lang::Class
> cls
, RefCountPtr
< const Lang::Class
> parent
)
197 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
), parent_( parent
)
200 Exceptions::IllegalRepeatedBase::~IllegalRepeatedBase( )
204 Exceptions::IllegalRepeatedBase::display( ostream
& os
) const
206 os
<< "When creating the class " << cls_
->getPrettyName( ) << ", the following repeated base class may not be repeated: " << parent_
->getPrettyName( ) << std::endl
;
210 Exceptions::AmbiguousInheritedMethod::AmbiguousInheritedMethod( RefCountPtr
< const Lang::Class
> cls
, RefCountPtr
< const char > id
, std::set
< RefCountPtr
< const Lang::Class
> > parents
)
211 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
), id_( id
), parents_( parents
)
214 Exceptions::AmbiguousInheritedMethod::~AmbiguousInheritedMethod( )
218 Exceptions::AmbiguousInheritedMethod::display( ostream
& os
) const
220 os
<< "In class " << cls_
->getPrettyName( ) << ": the method name " << id_
<< " is ambiguous, as it is inherited from more than one class:" ;
221 for( std::set
< RefCountPtr
< const Lang::Class
> >::const_iterator i
= parents_
.begin( ); i
!= parents_
.end( ); ++i
)
223 os
<< " " << (*i
)->getPrettyName( ) ;
229 Exceptions::MisplacedSuperReference::MisplacedSuperReference( const Ast::SourceLocation
& loc
)
230 : Exceptions::RuntimeError( loc
)
233 Exceptions::MisplacedSuperReference::~MisplacedSuperReference( )
237 Exceptions::MisplacedSuperReference::display( std::ostream
& os
) const
239 os
<< "Misplaced reference to parent instance." << std::endl
;
243 Exceptions::SuperReferenceClassNotParent::SuperReferenceClassNotParent( RefCountPtr
< const Lang::Class
> cls
, RefCountPtr
< const Lang::Class
> parent
)
244 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
), parent_( parent
)
247 Exceptions::SuperReferenceClassNotParent::~SuperReferenceClassNotParent( )
251 Exceptions::SuperReferenceClassNotParent::display( std::ostream
& os
) const
253 os
<< "When referencing super instance, " << parent_
->getPrettyName( ) << " is not a parent of " << cls_
->getPrettyName( ) << "." << std::endl
;
257 Exceptions::NoSuchMethod::NoSuchMethod( RefCountPtr
< const Lang::Class
> cls
, const Kernel::MethodId
& method
)
258 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
), method_( method
)
261 Exceptions::NoSuchMethod::~NoSuchMethod( )
265 Exceptions::NoSuchMethod::display( std::ostream
& os
) const
267 os
<< "Class " << cls_
->getPrettyName( ) << " has no method called " << method_
.prettyName( ) << std::endl
;
271 Exceptions::NoSuchLocalMethod::NoSuchLocalMethod( RefCountPtr
< const Lang::Class
> cls
, const Kernel::MethodId
& method
)
272 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls_( cls
), method_( method
)
275 Exceptions::NoSuchLocalMethod::~NoSuchLocalMethod( )
279 Exceptions::NoSuchLocalMethod::display( std::ostream
& os
) const
281 os
<< "Class " << cls_
->getPrettyName( ) << " does not itself define the method " << method_
.prettyName( ) << std::endl
;