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 Henrik Tidefelt
19 #include "classexceptions.h"
22 using namespace Shapes
;
30 void prefixEachLine( const std::string
& prefix
, std::istream
& src
, std::ostream
& dst
);
31 void prefixEachLine( const std::string
& prefix
, const RefCountPtr
< const char > & src
, std::ostream
& dst
);
36 Exceptions::IllegalFinalReference::IllegalFinalReference( RefCountPtr
< const char > _valueType
, const char * _fieldID
)
37 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), valueType( _valueType
), fieldID( _fieldID
)
40 Exceptions::IllegalFinalReference::~IllegalFinalReference( )
44 Exceptions::IllegalFinalReference::display( std::ostream
& os
) const
46 os
<< "Attempt to access field of non-final class " << valueType
<< " without home class. Use <HomeClass>#" << fieldID
<< " instead." << std::endl
;
50 Exceptions::NonExistentMember::NonExistentMember( RefCountPtr
< const char > _valueType
, const char * _fieldID
)
51 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), valueType( _valueType
), fieldID( _fieldID
)
54 Exceptions::NonExistentMember::~NonExistentMember( )
58 Exceptions::NonExistentMember::display( std::ostream
& os
) const
60 os
<< "Class " << valueType
<< " has no (non-private) field called " << fieldID
<< "." << std::endl
;
64 Exceptions::NonExistentMutator::NonExistentMutator( RefCountPtr
< const char > _valueType
, const char * _mutatorID
)
65 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), valueType( _valueType
), mutatorID( _mutatorID
)
68 Exceptions::NonExistentMutator::~NonExistentMutator( )
72 Exceptions::NonExistentMutator::display( std::ostream
& os
) const
74 os
<< "State type " << valueType
<< " has no mutator called " << mutatorID
<< "." << std::endl
;
78 Exceptions::ProtectedMemberPublicScope::ProtectedMemberPublicScope( RefCountPtr
< const char > _valueType
, const char * _fieldID
)
79 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), valueType( _valueType
), fieldID( _fieldID
)
82 Exceptions::ProtectedMemberPublicScope::~ProtectedMemberPublicScope( )
86 Exceptions::ProtectedMemberPublicScope::display( std::ostream
& os
) const
88 os
<< "Trying to access protected member " << fieldID
<< " of class " << valueType
<< " via public instance." << std::endl
;
92 Exceptions::MemberNotAssignable::MemberNotAssignable( RefCountPtr
< const char > _valueType
, const char * _fieldID
, RefCountPtr
< const char > _scope
)
93 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), valueType( _valueType
), fieldID( _fieldID
), scope( _scope
)
96 Exceptions::MemberNotAssignable::~MemberNotAssignable( )
100 Exceptions::MemberNotAssignable::display( std::ostream
& os
) const
102 os
<< "In " << scope
<< " scope of " << valueType
<< " : The member " << fieldID
<< " is not assignable." << std::endl
;
106 Exceptions::InstantiatingAbstractClass::InstantiatingAbstractClass( RefCountPtr
< const Lang::Class
> _cls
)
107 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
)
110 Exceptions::InstantiatingAbstractClass::~InstantiatingAbstractClass( )
114 Exceptions::InstantiatingAbstractClass::display( ostream
& os
) const
116 os
<< "Trying to instantiate abstract class: " << cls
->getPrettyName( ) << std::endl
;
120 Exceptions::FailedToDeclareClassAbstract::FailedToDeclareClassAbstract( RefCountPtr
< const Lang::Class
> _cls
, const Shapes::Ast::ClassFunction
* _classExpr
)
121 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
), classExpr( _classExpr
)
124 Exceptions::FailedToDeclareClassAbstract::~FailedToDeclareClassAbstract( )
128 Exceptions::FailedToDeclareClassAbstract::display( ostream
& os
) const
130 os
<< classExpr
->loc( ) << " " << "Class " << cls
->getPrettyName( ) << " has abstract methods but is not declared abstract: " ;
131 cls
->showAbstractSet( os
);
136 Exceptions::RepeatedImmediateParent::RepeatedImmediateParent( RefCountPtr
< const Lang::Class
> _cls
, RefCountPtr
< const Lang::Class
> _parent
)
137 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
), parent( _parent
)
140 Exceptions::RepeatedImmediateParent::~RepeatedImmediateParent( )
144 Exceptions::RepeatedImmediateParent::display( ostream
& os
) const
146 os
<< "When creating the class " << cls
->getPrettyName( ) << ", the following class is a repeated immediate parent: " << parent
->getPrettyName( ) << std::endl
;
150 Exceptions::OverridingNonParent::OverridingNonParent( RefCountPtr
< const Lang::Class
> _cls
, RefCountPtr
< const Lang::Class
> _parent
)
151 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
), parent( _parent
)
154 Exceptions::OverridingNonParent::~OverridingNonParent( )
158 Exceptions::OverridingNonParent::display( ostream
& os
) const
160 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
;
164 Exceptions::InheritingFinal::InheritingFinal( RefCountPtr
< const Lang::Class
> _cls
, RefCountPtr
< const Lang::Class
> _parent
)
165 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
), parent( _parent
)
168 Exceptions::InheritingFinal::~InheritingFinal( )
172 Exceptions::InheritingFinal::display( ostream
& os
) const
174 os
<< "When creating the class " << cls
->getPrettyName( ) << ", trying to inherit from final class: " << parent
->getPrettyName( ) << std::endl
;
178 Exceptions::OverridingUndeclaredMethod::OverridingUndeclaredMethod( RefCountPtr
< const Lang::Class
> _cls
, RefCountPtr
< const Lang::Class
> _parent
, const char * _id
)
179 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
), parent( _parent
), id( _id
)
182 Exceptions::OverridingUndeclaredMethod::~OverridingUndeclaredMethod( )
186 Exceptions::OverridingUndeclaredMethod::display( ostream
& os
) const
188 os
<< "In override declaration in class " << cls
->getPrettyName( ) << ": there is no method called " << id
<< " in class " << parent
->getPrettyName( ) << " to override." << std::endl
;
192 Exceptions::OverridingFinalMethod::OverridingFinalMethod( RefCountPtr
< const Lang::Class
> _cls
, RefCountPtr
< const Lang::Class
> _parent
, const char * _id
)
193 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
), parent( _parent
), id( _id
)
196 Exceptions::OverridingFinalMethod::~OverridingFinalMethod( )
200 Exceptions::OverridingFinalMethod::display( ostream
& os
) const
202 os
<< "In override declaration in class " << cls
->getPrettyName( ) << ": The method " << id
<< " in class " << parent
->getPrettyName( ) << " is final." << std::endl
;
206 Exceptions::IllegalRepeatedBase::IllegalRepeatedBase( RefCountPtr
< const Lang::Class
> _cls
, RefCountPtr
< const Lang::Class
> _parent
)
207 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
), parent( _parent
)
210 Exceptions::IllegalRepeatedBase::~IllegalRepeatedBase( )
214 Exceptions::IllegalRepeatedBase::display( ostream
& os
) const
216 os
<< "When creating the class " << cls
->getPrettyName( ) << ", the following repeated base class may not be repeated: " << parent
->getPrettyName( ) << std::endl
;
220 Exceptions::AmbiguousInheritedMethod::AmbiguousInheritedMethod( RefCountPtr
< const Lang::Class
> _cls
, RefCountPtr
< const char > _id
, std::set
< RefCountPtr
< const Lang::Class
> > _parents
)
221 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
), id( _id
), parents( _parents
)
224 Exceptions::AmbiguousInheritedMethod::~AmbiguousInheritedMethod( )
228 Exceptions::AmbiguousInheritedMethod::display( ostream
& os
) const
230 os
<< "In class " << cls
->getPrettyName( ) << ": the method name " << id
<< " is ambiguous, as it is inherited from more than one class:" ;
231 for( std::set
< RefCountPtr
< const Lang::Class
> >::const_iterator i
= parents
.begin( ); i
!= parents
.end( ); ++i
)
233 os
<< " " << (*i
)->getPrettyName( ) ;
239 Exceptions::MisplacedSuperReference::MisplacedSuperReference( const Ast::SourceLocation
& _loc
)
240 : Exceptions::RuntimeError( _loc
)
243 Exceptions::MisplacedSuperReference::~MisplacedSuperReference( )
247 Exceptions::MisplacedSuperReference::display( std::ostream
& os
) const
249 os
<< "Misplaced reference to parent instance." << std::endl
;
253 Exceptions::SuperReferenceClassNotParent::SuperReferenceClassNotParent( RefCountPtr
< const Lang::Class
> _cls
, RefCountPtr
< const Lang::Class
> _parent
)
254 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
), parent( _parent
)
257 Exceptions::SuperReferenceClassNotParent::~SuperReferenceClassNotParent( )
261 Exceptions::SuperReferenceClassNotParent::display( std::ostream
& os
) const
263 os
<< "When referencing super instance, " << parent
->getPrettyName( ) << " is not a parent of " << cls
->getPrettyName( ) << "." << std::endl
;
267 Exceptions::NoSuchMethod::NoSuchMethod( RefCountPtr
< const Lang::Class
> _cls
, const Kernel::MethodId
& _method
)
268 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
), method( _method
)
271 Exceptions::NoSuchMethod::~NoSuchMethod( )
275 Exceptions::NoSuchMethod::display( std::ostream
& os
) const
277 os
<< "Class " << cls
->getPrettyName( ) << " has no method called " << method
.prettyName( ) << std::endl
;
281 Exceptions::NoSuchLocalMethod::NoSuchLocalMethod( RefCountPtr
< const Lang::Class
> _cls
, const Kernel::MethodId
& _method
)
282 : Exceptions::RuntimeError( Ast::THE_UNKNOWN_LOCATION
), cls( _cls
), method( _method
)
285 Exceptions::NoSuchLocalMethod::~NoSuchLocalMethod( )
289 Exceptions::NoSuchLocalMethod::display( std::ostream
& os
) const
291 os
<< "Class " << cls
->getPrettyName( ) << " does not itself define the method " << method
.prettyName( ) << std::endl
;