Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

except.cc

Go to the documentation of this file.
00001 // AUTOMATICALLY GENERATED -- DO NOT EDIT!         -*- c++ -*-
00002 
00003 #include "except.h"
00004 #include "except_i.h"
00005 
00006 
00007 #line 99 "except.cpp"
00008 static Ptree*
00009 find_leaf(Ptree* tree, char** fn_out, int* fn_length_out, unsigned int* line_out);
00010 
00011 #line 116 "except.cpp"
00012 static void
00013 print_location(std::ostream& os, Ptree* tree);
00014 #line 34 "except.cpp"
00015 
00016 #ifdef USE_BACKTRACER
00017 #line 37 "except.cpp"
00018 #else
00019 #line 38 "except.cpp"
00020 #  define printBacktrace(x)
00021 #line 39 "except.cpp"
00022 #endif
00023 #line 40 "except.cpp"
00024 
00025 bool Compile_error::had_errors = 0;
00026 
00027 #line 42 "except.cpp"
00028 
00029 void
00030 compile_error(const char* str)
00031 {
00032     throw Compile_error(str);
00033 }
00034 
00035 #line 48 "except.cpp"
00036 
00037 void
00038 compile_error(std::string str)
00039 {
00040     throw Compile_error(str);
00041 }
00042 
00043 #line 54 "except.cpp"
00044 
00045 void
00046 bogus_ptree_error(const char* str, Ptree* tree)
00047 {
00048     bogus_ptree_error(std::string(str), tree);
00049 }
00050 
00051 #line 60 "except.cpp"
00052 
00053 void
00054 bogus_ptree_error(std::string str, Ptree* tree)
00055 {
00056     printBacktrace(std::cerr);
00057     std::ostringstream o;
00058     if (tree) {
00059         o << "Could not understand this ptree: ";
00060         tree->Display2(o);
00061     } else {
00062         o << "Null Ptree encountered\n";
00063     }
00064     throw Compile_error(o.str() + str);
00065 }
00066 
00067 #line 74 "except.cpp"
00068 
00069 void
00070 expect_ptree(Ptree* p, const char* str)
00071 {
00072     if (!p->Eq((char*)str))
00073         bogus_ptree_error(std::string("expected `") + str + "'", p);
00074 }
00075 
00076 #line 81 "except.cpp"
00077 
00078 void
00079 expect_ptree(Ptree* p, char c)
00080 {
00081     if (!p->Eq(c))
00082         bogus_ptree_error(std::string("expected `") + c + "'", p);
00083 }
00084 
00085 #line 88 "except.cpp"
00086 
00087 
00088 Compile_error::Compile_error(std::string str)
00089     : std::runtime_error(str)
00090 { }
00091 
00092 #line 93 "except.cpp"
00093 
00094 
00095 Compile_error::Compile_error(const char* str)
00096     : std::runtime_error(str)
00097 { }
00098 
00099 #line 98 "except.cpp"
00100 
00101 static Ptree*
00102 find_leaf(Ptree* tree, char** fn_out, int* fn_length_out, unsigned int* line_out)
00103 {
00104     if (!tree)
00105         return 0;
00106     else if (tree->IsLeaf())
00107         if ((*line_out = Source::instance().program()->LineNumber(tree->GetPosition(),
00108                                                                   *fn_out, *fn_length_out)))
00109             return tree;
00110         else
00111             return 0;
00112     else if (Ptree* p = find_leaf(tree->Car(), fn_out, fn_length_out, line_out))
00113         return p;
00114     else
00115         return find_leaf(tree->Cdr(), fn_out, fn_length_out, line_out);
00116 }
00117 
00118 #line 115 "except.cpp"
00119 
00120 static void
00121 print_location(std::ostream& os, Ptree* tree)
00122 {
00123     unsigned int line;
00124     char* fn;
00125     int fn_length;
00126     
00127     tree = find_leaf(tree, &fn, &fn_length, &line);
00128     if (tree) {
00129         if (line) {
00130             os.write(fn, fn_length);
00131             os << ":" << line;
00132         } else {
00133             os << "<replaced>";
00134         }
00135     } else {
00136         os << "<unknown>";
00137     }
00138 }
00139 
00140 #line 135 "except.cpp"
00141 
00142 void
00143 Compile_error::print(std::ostream& os, Ptree* tree)
00144 {
00145     print_location(os, tree);
00146     os << ": " << what() << "\n";
00147     had_errors = true;
00148 }
00149 
00150 #line 143 "except.cpp"
00151 
00152 void
00153 compile_warning(const char* str, Ptree* tree)
00154 {
00155     print_location(std::cerr, tree);
00156     std::cerr << ": warning: " << str << "\n";
00157 }
00158 
00159 #line 150 "except.cpp"
00160 
00161 void
00162 compile_warning(std::string str, Ptree* tree)
00163 {
00164     print_location(std::cerr, tree);
00165     std::cerr << ": warning: " << str << "\n";
00166 }

Generated on Mon Feb 10 17:32:47 2003 for VFiasco Semantics Compiler by doxygen1.2.15