1 /***************************************************************************
2                               gdlexception.hpp
3                              -------------------
4     begin                : July 22 2002
5     copyright            : (C) 2002 by Marc Schellens
6     email                : m_schellens@users.sf.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef GDLEXCEPTION_HPP_
19 #define GDLEXCEPTION_HPP_
20 
21 #include <string>
22 #include <iostream>
23 
24 #include "prognode.hpp"
25 
26 #include <antlr/ANTLRException.hpp>
27 
28 //using namespace std;
29 
30 class EnvUDT;
31 
32 class GDLException: public antlr::ANTLRException
33 {
34   static DInterpreter* interpreter;
35 
36   std::string msg;
37 
38   RefDNode  errorNode;
39   ProgNodeP errorNodeP;
40   DLong     errorCode;
41   SizeT line;
42   SizeT col;
43   bool prefix;
44 
45   bool arrayexprIndexeeFailed;
46 
47 protected:
48   bool ioException;
49 
50 private:
51   EnvUDT* targetEnv; // where to stop (depending on ON_ERROR)
52 
53 public:
Interpreter()54   static DInterpreter* Interpreter() { return interpreter;}
SetInterpreter(DInterpreter * i)55   static void SetInterpreter( DInterpreter* i) { interpreter = i;}
56 
57   static std::string Name( BaseGDL* b);
58 
SetErrorNodeP(ProgNodeP p)59   void SetErrorNodeP( ProgNodeP p) { errorNodeP = p;}
60 
GetArrayexprIndexeeFailed() const61   bool GetArrayexprIndexeeFailed() const { return arrayexprIndexeeFailed;}
SetArrayexprIndexeeFailed(bool b)62   void SetArrayexprIndexeeFailed( bool b) { arrayexprIndexeeFailed = b;}
63 
GDLException()64   GDLException(): ANTLRException(),
65     errorNode(static_cast<RefDNode>(antlr::nullAST)),
66 		  errorNodeP( NULL),
67 		  errorCode(-1),
68 		  line( 0), col( 0), prefix( true),
69 		  arrayexprIndexeeFailed(false),
70 		  ioException( false),
71 		  targetEnv( NULL)
72   {}
GDLException(DLong eC)73   GDLException( DLong eC): ANTLRException(),
74     errorNode(static_cast<RefDNode>(antlr::nullAST)),
75 		  errorNodeP( NULL),
76 		  errorCode(eC),
77 		  line( 0), col( 0), prefix( true),
78 		  arrayexprIndexeeFailed(false),
79 		  ioException( false),
80 		  targetEnv( NULL)
81   {}
82   GDLException(const std::string& s, bool pre = true, bool decorate=true);
83   GDLException(const RefDNode eN, const std::string& s);
84   GDLException(const ProgNodeP eN, const std::string& s, bool decorate=true, bool overWriteNode=true);
85   GDLException(SizeT l, SizeT c, const std::string& s);
86 
87   GDLException(DLong eC, const std::string& s, bool pre = true, bool decorate=true);
88   GDLException(DLong eC, const RefDNode eN, const std::string& s);
89   GDLException(DLong eC, const ProgNodeP eN, const std::string& s, bool decorate=true, bool overWriteNode=true);
90   GDLException(DLong eC, SizeT l, SizeT c, const std::string& s);
91 
~GDLException()92   ~GDLException() throw() {}
93 
ErrorCode() const94   DLong ErrorCode() const { return errorCode;}
95 
toString() const96   std::string toString() const
97   {
98 	  return msg;
99   }
100 
getLine() const101   SizeT getLine() const
102   {
103     if( line != 0)
104       return line;
105     if( errorNodeP != NULL)
106       return errorNodeP->getLine();
107     if( errorNode != static_cast<RefDNode>(antlr::nullAST))
108       return errorNode->getLine();
109     return 0;
110   }
111 
SetLine(SizeT l)112   void SetLine( SizeT l) { line = l;}
113 
getColumn() const114   SizeT getColumn() const
115   {
116     //    if( errorNode != static_cast<RefDNode>(antlr::nullAST))
117     //      return errorNode->getColumn();
118     return col;
119   }
120 
Prefix() const121   bool Prefix() const
122   {
123     return prefix;
124   }
125 
SetTargetEnv(EnvUDT * tEnv)126   void SetTargetEnv( EnvUDT* tEnv)
127   {
128     targetEnv = tEnv;
129   }
130 
GetTargetEnv()131   EnvUDT* GetTargetEnv()
132   {
133     return targetEnv;
134   }
135 
IsIOException() const136   bool IsIOException() const { return ioException;}
137 };
138 
139 // for ON_IOERROR
140 class GDLIOException: public GDLException
141 {
142 public:
GDLIOException()143   GDLIOException():
144     GDLException()
145   { ioException = true;}
146 
GDLIOException(const std::string & s,bool pre=true)147   GDLIOException(const std::string& s, bool pre = true):
148     GDLException( s, pre)
149   { ioException = true;}
150 
GDLIOException(const ProgNodeP eN,const std::string & s)151   GDLIOException(const ProgNodeP eN, const std::string& s):
152     GDLException( eN, s)
153   { ioException = true;}
154 
GDLIOException(DLong eC)155   GDLIOException(DLong eC):
156     GDLException(eC)
157   { ioException = true;}
158 
GDLIOException(DLong eC,const std::string & s,bool pre=true)159   GDLIOException(DLong eC,const std::string& s, bool pre = true):
160     GDLException( eC, s, pre)
161   { ioException = true;}
162 
GDLIOException(DLong eC,const ProgNodeP eN,const std::string & s)163   GDLIOException(DLong eC,const ProgNodeP eN, const std::string& s):
164     GDLException( eC, eN, s)
165   { ioException = true;}
166 };
167 
168 // warnings ignore !QUIET
169 void Warning(const std::string& s);
170 
171 // messages honor !QUIET
172 void Message(const std::string& s);
173 
174 void ThrowGDLException( const std::string& str);
175 
176 void WarnAboutObsoleteRoutine(const std::string& name);
177 void WarnAboutObsoleteRoutine(const RefDNode eN, const std::string& name);
178 
179 #endif
180 
181