00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #include <cstdlib>
00057 #include "options_recorder.hh"
00058 #include "prop_registry.hh"
00059
00060
00061 OptionsRecorder::OptDesc OptionsRecorder::optDescriptors[] =
00062 {
00063 {OptionsRecorder::OptDesc::o_bool, "DEBUG_PARSER", "false"},
00064 {OptionsRecorder::OptDesc::o_bool, "DEBUG_SCANNER" , "false"},
00065 {OptionsRecorder::OptDesc::o_bool, "CASE_SENSITIVE", "true"},
00066 {OptionsRecorder::OptDesc::o_bool, "USE_EXCEPTIONS", "true"},
00067 {OptionsRecorder::OptDesc::o_int, "DEFAULT_LOOKAHEAD", "1"},
00068 {OptionsRecorder::OptDesc::o_bool, "TOKENS_SPAN_EOF", "false"},
00069
00070
00071 {OptionsRecorder::OptDesc::o_bool, "COUNT_COLUMNS", "true"},
00072 {OptionsRecorder::OptDesc::o_bool, "SHARP_LINES", "true"},
00073 {OptionsRecorder::OptDesc::o_string, "PROFILING_FILE", ""},
00074
00075
00076 {OptionsRecorder::OptDesc::o_int, NULL, NULL},
00077 };
00078
00079 char *OptionsRecorder::OptDesc::kNames[] = {"integer", "string", "boolean"};
00080
00081 OptionsRecorder::OptionsRecorder (PropRegistry ®istry_) :
00082 registry(registry_)
00083 {
00084 for (int i = 0; optDescriptors[i].name != NULL; i++)
00085 switch (optDescriptors[i].kind)
00086 {
00087 case OptDesc::o_int:
00088 setOption(optDescriptors[i].name, atoi(optDescriptors[i].defVal));
00089 break;
00090 case OptDesc::o_string:
00091 setOption(optDescriptors[i].name, optDescriptors[i].defVal);
00092 break;
00093 case OptDesc::o_bool:
00094 setOption(optDescriptors[i].name, !strcmp(optDescriptors[i].defVal, "true"));
00095 break;
00096 default:
00097 ASSERT(0, "Bad OptionRecorder default value.");
00098 }
00099 }
00100
00101
00102 void OptionsRecorder::checkName (const string &name, OptDesc::t_kinds kind)
00103 throw (ParseException)
00104 {
00105 for (int i = 0; optDescriptors[i].name != NULL; i++)
00106 if (optDescriptors[i].name == name) {
00107 if (optDescriptors[i].kind != kind)
00108 throw ParseException(string("Option \"") + name +
00109 "\" takes a " +
00110 OptDesc::kNames[optDescriptors[i].kind] +
00111 " value.");
00112 return;
00113 }
00114 throw ParseException((string) "Option \"" + name + "\" not recognized.");
00115 }
00116
00117
00118 void OptionsRecorder::setOption (const string &key, const string &value)
00119 throw (ParseException)
00120 {
00121 checkName(key, OptDesc::o_string);
00122 registry[key] = value;
00123 }
00124
00125 void OptionsRecorder::setOption (const string &key, const char *value)
00126 throw (ParseException)
00127 {
00128 checkName(key, OptDesc::o_string);
00129 registry[key] = string(value);
00130 }
00131
00132
00133 void OptionsRecorder::setOption (const string &key, int value)
00134 throw (ParseException)
00135 {
00136
00137 checkName(key, OptDesc::o_int);
00138 registry[key] = value;
00139 }
00140
00141
00142 void OptionsRecorder::setOption (const string &key, bool value)
00143 throw (ParseException)
00144 {
00145
00146 checkName(key, OptDesc::o_bool);
00147 registry[key] = value;
00148 }
00149
00150
00151 #ifdef DEBUG
00152
00153 void OptionsRecorder::dumpRegistry ()
00154 {
00155 if (((string)registry["debug"]).find('o') != string::npos)
00156 cerr << "Registry dump: " << endl << registry << "endl";
00157 }
00158
00159 #endif