FAUST compiler  0.9.9.6b8
errormsg.cpp
Go to the documentation of this file.
00001 /************************************************************************
00002  ************************************************************************
00003     FAUST compiler
00004     Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
00005     ---------------------------------------------------------------------
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  ************************************************************************
00020  ************************************************************************/
00021  
00022  
00023  
00024 #include "errormsg.hh"
00025 #include "boxes.hh"
00026 #include "ppbox.hh"
00027 #include <iostream>
00028 using namespace std;
00029 
00030 const char* yyfilename = "????";
00031 int         gErrorCount = 0;
00032 Tree        DEFLINEPROP = tree(symbol("DefLineProp"));
00033 
00034 void yyerror(char* msg) 
00035 { 
00036     fprintf(stderr, "%s:%d:%s\n", yyfilename, yylineno, msg); 
00037     gErrorCount++;
00038 }
00039 
00040 void evalerror(const char* filename, int linenum, const char* msg, Tree exp)
00041 {
00042     fprintf(stderr, "%s:%d: ERROR: %s ", filename, linenum, msg); 
00043     print(exp,stderr); fprintf(stderr, "\n");
00044     gErrorCount++;
00045 }
00046 
00047 void evalerrorbox(const char* filename, int linenum, const char* msg, Tree exp)
00048 {
00049     cerr << filename << ':' << linenum << ": ERROR: " << msg << " : " << boxpp(exp) << endl;
00050     gErrorCount++;
00051 }
00052 
00053 void evalwarning(const char* filename, int linenum, const char* msg, Tree exp)
00054 {
00055     fprintf(stderr, "%s:%d: WARNING: %s ", filename, linenum, msg); 
00056     print(exp,stderr); fprintf(stderr, "\n");
00057 }
00058 
00059 void evalremark(const char* filename, int linenum, const char* msg, Tree exp)
00060 {
00061     fprintf(stderr, "%s:%d: REMARK: %s ", filename, linenum, msg); 
00062     print(exp,stderr); fprintf(stderr, "\n");
00063 }
00064 
00065 
00066 void setDefProp(Tree sym, const char* filename, int lineno)
00067 {
00068     setProperty(sym, DEFLINEPROP, cons(tree(filename), tree(lineno)));
00069 }
00070 
00071 
00072 const char* getDefFileProp(Tree sym)
00073 {
00074     Tree n;
00075     if (getProperty(sym, DEFLINEPROP, n)) {
00076         return name(hd(n)->node().getSym());
00077     } else {
00078         return "????";
00079     }
00080 }
00081 
00082 int getDefLineProp(Tree sym)
00083 {
00084     Tree n;
00085     if (getProperty(sym, DEFLINEPROP, n)) {
00086         return tl(n)->node().getInt();
00087     } else {
00088         return -1;
00089     }
00090 }