error.h
1 //error.h
2 //----------------------------------------------------------------------
3 /*
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301, USA.
18  */
19 //----------------------------------------------------------------------
20 #ifndef _ERROR_
21 #define _ERROR_
22 #include <string>
23 #include <iostream>
24 #include <sstream>
25 #include <exception>
26 #include <queue>
27 #include "run/tree/runTree.h"
28 #include "run/stmts/stmtNode.h"
29 #include "lshParser.h"
30 #define ERROR 0
31 #define ERROR_DATA 1
32 #define ERROR_PARAMS 2
33 extern string infile;
34 extern bool inline_param;
35 extern int yyerror(const char *s);
36 
37 using namespace std;
38 class errorException :
39  public std::exception {
40  public:
41  errorException (string msg = "", string dev = "", int code = 0, int exit = 0): code_(code), msg_ (msg), exit_ (exit), dev_ (dev) {}
42  const char* what() const throw() {
43  return "Break fuera de bloque.";
44  }
45  ~errorException () throw() {}
46  void error (string file = "", int line = 0);
47  private:
48  int code_, exit_;
49  string msg_, dev_;
50 };
51 class warningQueue {
52  public:
53  static void warning (string file = "", int line = 0) {
54  string file_txt;
55  string line_txt;
56  if (file != "") {
57  file_txt = "file " + file + " ";
58  }
59  if (line && !inline_param) {
60  stringstream ss;
61  ss << line;
62  line_txt = "line " + ss.str() + " => ";
63  }
64  while (!q_.empty()) {
65  cerr << "Warning: "
66  << file_txt << line_txt
67  << q_.front() << endl;
68  q_.pop();
69  }
70  }
71  static void add (string msg) {
72  q_.push (msg);
73  }
74  static queue<string> q_;
75 };
76 
77 
78 
79 #endif /*CCALC_H_*/
Nodos de sentencias generales .
Árbol de ejecución.