FAUST compiler  0.9.9.6b8
errormsg.cpp
Go to the documentation of this file.
1 /************************************************************************
2  ************************************************************************
3  FAUST compiler
4  Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5  ---------------------------------------------------------------------
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  ************************************************************************
20  ************************************************************************/
21 
22 
23 
24 #include "errormsg.hh"
25 #include "boxes.hh"
26 #include "ppbox.hh"
27 #include <iostream>
28 using namespace std;
29 
30 const char* yyfilename = "????";
31 int gErrorCount = 0;
32 Tree DEFLINEPROP = tree(symbol("DefLineProp"));
33 
34 void yyerror(const char* msg)
35 {
36  fprintf(stderr, "%s:%d:%s\n", yyfilename, yylineno, msg);
37  gErrorCount++;
38 }
39 
40 void evalerror(const char* filename, int linenum, const char* msg, Tree exp)
41 {
42  fprintf(stderr, "%s:%d: ERROR: %s ", filename, linenum, msg);
43  print(exp,stderr); fprintf(stderr, "\n");
44  gErrorCount++;
45 }
46 
47 void evalerrorbox(const char* filename, int linenum, const char* msg, Tree exp)
48 {
49  cerr << filename << ':' << linenum << ": ERROR: " << msg << " : " << boxpp(exp) << endl;
50  gErrorCount++;
51 }
52 
53 void evalwarning(const char* filename, int linenum, const char* msg, Tree exp)
54 {
55  fprintf(stderr, "%s:%d: WARNING: %s ", filename, linenum, msg);
56  print(exp,stderr); fprintf(stderr, "\n");
57 }
58 
59 void evalremark(const char* filename, int linenum, const char* msg, Tree exp)
60 {
61  fprintf(stderr, "%s:%d: REMARK: %s ", filename, linenum, msg);
62  print(exp,stderr); fprintf(stderr, "\n");
63 }
64 
65 
66 void setDefProp(Tree sym, const char* filename, int lineno)
67 {
68  setProperty(sym, DEFLINEPROP, cons(tree(filename), tree(lineno)));
69 }
70 
71 
72 const char* getDefFileProp(Tree sym)
73 {
74  Tree n;
75  if (getProperty(sym, DEFLINEPROP, n)) {
76  return name(hd(n)->node().getSym());
77  } else {
78  return "????";
79  }
80 }
81 
83 {
84  Tree n;
85  if (getProperty(sym, DEFLINEPROP, n)) {
86  return tl(n)->node().getInt();
87  } else {
88  return -1;
89  }
90 }
void evalerrorbox(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:47
Tree cons(Tree a, Tree b)
Definition: list.hh:124
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
void evalremark(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:59
Tree hd(Tree l)
Definition: list.hh:133
const Node & node() const
return the content of the tree
Definition: tree.hh:143
Tree DEFLINEPROP
Definition: errormsg.cpp:32
void evalwarning(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:53
void setDefProp(Tree sym, const char *filename, int lineno)
Definition: errormsg.cpp:66
int getDefLineProp(Tree sym)
Definition: errormsg.cpp:82
int gErrorCount
Definition: errormsg.cpp:31
void evalerror(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:40
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Tree tree(const Node &n)
Definition: tree.hh:186
const char * yyfilename
Definition: errormsg.cpp:30
int getInt() const
Definition: node.hh:104
Definition: ppbox.hh:58
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418
void yyerror(const char *msg)
Definition: errormsg.cpp:34
Symbol * symbol(const char *str)
Returns (and creates if new) the symbol of name str.
Definition: symbol.hh:95
Tree tl(Tree l)
Definition: list.hh:134
int yylineno
Definition: faustlexer.cpp:357
const char * getDefFileProp(Tree sym)
Definition: errormsg.cpp:72
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423
void print(Tree t, FILE *out)
Definition: list.cpp:154