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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
#!@PERL@
# global exception list file
my $global_list = '../../ExceptionCodes.txt';
my @exception;
my @exception_desc;
my $class;
my $class_number;
# read the description!
open EXCEPTION_DESC,$ARGV[0] or die "Can't open $ARGV[0]";
while(<EXCEPTION_DESC>)
{
chomp; s/\A\s+//; s/#.+\Z//; s/\s+\Z//; s/\s+/ /g;
next unless m/\S/;
if(m/\AEXCEPTION\s+(.+)\s+(\d+)\Z/)
{
$class = $1;
$class_number = $2;
}
else
{
my ($name,$number,$description) = split /\s+/,$_,3;
if($name eq '' || $number =~ m/\D/)
{
die "Bad line '$_'";
}
if($exception[$number] ne '')
{
die "Duplicate exception number $number";
}
$exception[$number] = $name;
$exception_desc[$number] = $description;
}
}
die "Exception class and number not specified" unless $class ne '' && $class_number ne '';
close EXCEPTION_DESC;
# write the code
print "Generating $class exception...\n";
open CPP,">autogen_${class}Exception.cpp" or die "Can't open cpp file for writing";
open H,">autogen_${class}Exception.h" or die "Can't open h file for writing";
# write header file
my $guardname = uc 'AUTOGEN_'.$class.'EXCEPTION_H';
print H <<__E;
// Auto-generated file -- do not edit
#ifndef $guardname
#define $guardname
#include "BoxException.h"
// --------------------------------------------------------------------------
//
// Class
// Name: ${class}Exception
// Purpose: Exception
// Created: autogen
//
// --------------------------------------------------------------------------
class ${class}Exception : public BoxException
{
public:
${class}Exception(unsigned int SubType,
const std::string& rMessage = "")
: mSubType(SubType), mMessage(rMessage),
mWhat(GetMessage(SubType) + std::string(rMessage.empty() ? "" : ": ") + rMessage)
{
}
${class}Exception(const ${class}Exception &rToCopy)
: mSubType(rToCopy.mSubType), mMessage(rToCopy.mMessage), mWhat(rToCopy.mWhat)
{
}
~${class}Exception() throw ()
{
}
enum
{
ExceptionType = $class_number
};
enum
{
__E
for(my $e = 0; $e <= $#exception; $e++)
{
if($exception[$e] ne '')
{
print H "\t\t".$exception[$e].' = '.$e.(($e==$#exception)?'':',')."\n"
}
}
print H <<__E;
};
virtual unsigned int GetType() const throw();
virtual unsigned int GetSubType() const throw();
virtual const char *what() const throw();
virtual const std::string& GetMessage() const
{
return mMessage;
}
static const char* GetMessage(int SubType);
private:
unsigned int mSubType;
std::string mMessage;
std::string mWhat;
};
#endif // $guardname
__E
# -----------------------------------------------------------------------------------------------------------
print CPP <<__E;
// Auto-generated file -- do not edit
#include "Box.h"
#include "autogen_${class}Exception.h"
#include "MemLeakFindOn.h"
unsigned int ${class}Exception::GetType() const throw()
{
return ${class}Exception::ExceptionType;
}
unsigned int ${class}Exception::GetSubType() const throw()
{
return mSubType;
}
const char * ${class}Exception::what() const throw()
{
return mWhat.c_str();
}
const char * ${class}Exception::GetMessage(int SubType)
{
switch(SubType)
{
__E
for(my $e = 0; $e <= $#exception; $e++)
{
if($exception[$e] ne '')
{
print CPP "\t\tcase ".$exception[$e].': return "'.$exception[$e].'";'."\n";
}
}
print CPP <<__E;
default: return "Unknown";
}
}
__E
close H;
close CPP;
# update the global exception list
my $list_before;
my $list_after;
my $is_after = 0;
if(open CURRENT,$global_list)
{
while(<CURRENT>)
{
next if m/\A#/;
if(m/\AEXCEPTION TYPE (\w+) (\d+)/)
{
# check that the number isn't being reused
if($2 == $class_number && $1 ne $class)
{
die "Class number $class_number is being used by $class and $1 -- correct this.\n";
}
if($2 > $class_number)
{
# This class comes after the current one (ensures numerical ordering)
$is_after = 1;
}
if($1 eq $class)
{
# skip this entry
while(<CURRENT>)
{
last if m/\AEND TYPE/;
}
$_ = '';
}
}
if($is_after)
{
$list_after .= $_;
}
else
{
$list_before .= $_;
}
}
close CURRENT;
}
open GLOBAL,">$global_list" or die "Can't open global exception code listing for writing";
print GLOBAL <<__E;
#
# automatically generated file, do not edit.
#
# This file lists all the exception codes used by the system.
# Use to look up more detailed descriptions of meanings of errors.
#
__E
print GLOBAL $list_before;
print GLOBAL "EXCEPTION TYPE $class $class_number\n";
for(my $e = 0; $e <= $#exception; $e++)
{
if($exception[$e] ne '')
{
my $ext = ($exception_desc[$e] ne '')?" - $exception_desc[$e]":'';
print GLOBAL "($class_number/$e) - ${class} ".$exception[$e].$ext."\n";
}
}
print GLOBAL "END TYPE\n";
print GLOBAL $list_after;
close GLOBAL;
|