2013-09-06 23:18:14 +02:00
//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// author: Baozeng Ding <sploving1@gmail.com>
// author: Vassil Vassilev <vasil.georgiev.vasilev@cern.ch>
2014-01-07 11:08:37 +01:00
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
2013-09-06 23:18:14 +02:00
//------------------------------------------------------------------------------
2013-09-09 14:59:47 +02:00
# include "cling/Interpreter/RuntimeException.h"
2013-09-06 23:18:14 +02:00
2013-10-03 09:47:56 +02:00
# include "cling/Interpreter/Interpreter.h"
2013-09-06 23:18:14 +02:00
# include "clang/Basic/SourceLocation.h"
# include "clang/Sema/Sema.h"
# include "clang/Sema/SemaDiagnostic.h"
2013-09-11 23:04:36 +02:00
extern " C " {
void cling__runtime__internal__throwNullDerefException ( void * Sema , void * Expr ) {
clang : : Sema * S = ( clang : : Sema * ) Sema ;
clang : : Expr * E = ( clang : : Expr * ) Expr ;
2013-10-03 09:47:56 +02:00
// FIXME: workaround until JIT supports exceptions
//throw cling::runtime::NullDerefException(S, E);
S - > Diag ( E - > getLocStart ( ) , clang : : diag : : warn_null_arg ) < < E - > getSourceRange ( ) ;
if ( cling : : Interpreter : : getNullDerefJump ( ) )
longjmp ( * cling : : Interpreter : : getNullDerefJump ( ) , 1 ) ;
2013-09-11 23:04:36 +02:00
}
}
2013-09-06 23:18:14 +02:00
namespace cling {
namespace runtime {
2014-01-15 15:41:53 +01:00
// Pin vtable
InterpreterException : : ~ InterpreterException ( ) { }
2013-09-07 10:41:29 +02:00
const char * InterpreterException : : what ( ) const throw ( ) {
return " runtime_exception \n " ;
2013-09-06 23:30:42 +02:00
}
2014-01-15 15:41:53 +01:00
2013-09-09 14:40:26 +02:00
NullDerefException : : NullDerefException ( clang : : Sema * S , clang : : Expr * E )
: m_Sema ( S ) , m_Arg ( E ) { }
2013-09-06 23:18:14 +02:00
2013-09-06 23:23:45 +02:00
NullDerefException : : ~ NullDerefException ( ) { }
2013-09-06 23:18:14 +02:00
2013-09-07 10:41:29 +02:00
const char * NullDerefException : : what ( ) const throw ( ) {
return " Trying to dereference null pointer or trying to call routine taking non-null arguments " ;
}
2013-09-11 14:10:51 -05:00
2013-09-07 10:41:29 +02:00
void NullDerefException : : diagnose ( ) const throw ( ) {
2013-09-09 14:40:26 +02:00
m_Sema - > Diag ( m_Arg - > getLocStart ( ) , clang : : diag : : warn_null_arg )
< < m_Arg - > getSourceRange ( ) ;
2013-09-06 23:18:14 +02:00
}
} // end namespace runtime
} // end namespace cling