-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdebug.cc
More file actions
147 lines (124 loc) · 3.48 KB
/
Copy pathdebug.cc
File metadata and controls
147 lines (124 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**********************************************************************
This file is part of the Quantum Computation Language QCL.
(c) Copyright by Bernhard Oemer <oemer@tph.tuwien.ac.at>, 1998
This program comes without any warranty; without even the implied
warranty of merchantability or fitness for any particular purpose.
This program is free software under the terms of the
GNU General Public Licence (GPL) version 2 or higher
************************************************************************/
#include "syntax.h"
#include "symbols.h"
#include "error.h"
#include "parse.h"
#include "options.h"
#include "debug.h"
#include "dump.h"
/*
objlist::objlist() : list<sObject*>() {
sObject *p;
while((p=parseobj())) push_back(p);
yyCleanUp();
}
objlist::~objlist() {
while(size()) {
delete front();
pop_front();
}
}
*/
int shell_depth=-1;
int qcllist(SymTable *loc,SymTable *gl,QuHeap *qh,sObject *obj,int flags) {
objlist *o;
sObject *p;
o=parseobj();
while(o->size()) {
p=o->front();
if(optEcho) qcloutput(p->prtstr(INDENT));
if(p->isInclude()) {
if(qclfile(((sInclude*)p)->filename(),loc,gl,qh,0,flags|QL_ERRORRETURN)) {
delete o;
return 1;
}
o->pop_front();
delete p;
continue;
}
try {
p->typecheck(loc,gl);
if(p->isDef()) {
((sDef*)p)->define(loc,gl,qh);
} else if(p->isStmt()) {
((sStmt*)p)->exec(loc,gl,qh);
delete p;
} else {
throw tError(errINT,"input is neither definition nor statement");
}
} catch(tError e) {
if(e.type()==errEXIT) { delete o; return 2; }
if(e.type()==errIGNORE) {
} else {
if(flags&QL_ERRORABORT) qclabort(e);
if(!(flags&QL_NOERRMSG)) qclerror(e);
if(flags&QL_ERRORRETURN) { delete o; return 1; }
}
delete p;
}
o->pop_front();
}
return 0;
}
int qclfile(string fname,SymTable *loc,SymTable *gl,QuHeap *qh,sObject *obj,int flags) {
FILE *f;
string s;
f=openqclfile(fname);
if(!f) { qclerror("Can't open "+fname); return 1; }
if(chksyntax(f)) return 1;
f=openqclfile(fname);
if(!f) {
qclerror("Can't reopen "+fname);
return 1;
}
yyScanFile(f);
return qcllist(loc,gl,qh,0,flags | QL_ERRORRETURN);
}
int qclshell(SymTable *loc,SymTable *gl,QuHeap *qh,sObject *obj,int cond) {
string s,prompt;
SymTab l,g(1);
SymTabComb lcomb((SymTable*)&l,loc),gcomb((SymTable*)&g,gl);
QuHeap lqh(qh);
irqOff();
shell_depth++;
if(cond==DB_ESCAPE) qclmessage("shell escape");
if(cond==DB_ERROR) {
qclmessage("debug shell");
qcloutput(loc->prtstr(1));
}
if(cond==DB_IRQ && obj) {
qclmessage("user interrupt in "+obj->defstr());
qcloutput(loc->prtstr(1));
}
prompt="qcl";
if(shell_depth>=1) prompt+=(char)('0'+shell_depth);
prompt+=cond==DB_ERROR ? "$ " : "> ";
while(1) {
if(isStateModified) lqh.state()->normalize();
if(optAutoDump && isStateModified) report_state(&lqh);
isStateModified=0;
s=qclinput(prompt);
if(s.substr(0,prompt.length())==prompt)
s=s.erase(0,prompt.length());
if(s=="\n") continue;
if(s=="") { cout << "\n"; break; }
s+=";";
if(chksyntax(s)) continue;
yyScanString(s);
if(qcllist(&lcomb,&gcomb,&lqh,0,QL_ERRORRETURN)==2) break;
};
shell_depth--;
return 0;
}
int qclstring(string s,SymTable *loc,SymTable *gl,QuHeap *qh) {
if(chksyntax(s)) return 1;
yyScanString(s);
return qcllist(loc,gl,qh,0,QL_ERRORRETURN);
}