comparison host/libcdl/interface.cxx @ 82:6736c52df507 ecos-sw-2000-04-14

Merge from eCos master repository on 2000-04-14-13:35:46-BST
author jlarmour
date Tue, 18 Apr 2000 21:51:55 +0000
parents 435cced73e2f
children 95f3e12a6327
comparison
equal deleted inserted replaced
81:89fef2181d7d 82:6736c52df507
116 { 116 {
117 CYG_REPORT_FUNCNAMETYPE("CdlInterface::parse_interface", "result %d"); 117 CYG_REPORT_FUNCNAMETYPE("CdlInterface::parse_interface", "result %d");
118 CYG_REPORT_FUNCARG1("argc %d", argc); 118 CYG_REPORT_FUNCARG1("argc %d", argc);
119 CYG_PRECONDITION_CLASSC(interp); 119 CYG_PRECONDITION_CLASSC(interp);
120 120
121 const char* diag_argv0 = CdlParse::get_tcl_cmd_name(argv[0]); 121 std::string diag_argv0 = CdlParse::get_tcl_cmd_name(argv[0]);
122 122
123 CdlLoadable loadable = interp->get_loadable(); 123 CdlLoadable loadable = interp->get_loadable();
124 CdlContainer parent = interp->get_container(); 124 CdlContainer parent = interp->get_container();
125 CdlToplevel toplevel = interp->get_toplevel(); 125 CdlToplevel toplevel = interp->get_toplevel();
126 std::string filename = interp->get_filename();
127 CYG_ASSERT_CLASSC(loadable); // There should always be a loadable during parsing 126 CYG_ASSERT_CLASSC(loadable); // There should always be a loadable during parsing
128 CYG_ASSERT_CLASSC(parent); 127 CYG_ASSERT_CLASSC(parent);
129 CYG_ASSERT_CLASSC(toplevel); 128 CYG_ASSERT_CLASSC(toplevel);
130 CYG_ASSERTC("" != filename);
131 129
132 // The new interface should be created and added to the loadable. 130 // The new interface should be created and added to the loadable.
133 // early on. If there is a parsing error it will get cleaned up 131 // early on. If there is a parsing error it will get cleaned up
134 // automatically as a consequence of the loadable destructor. 132 // automatically as a consequence of the loadable destructor.
135 // However it is necessary to validate the name first. Errors 133 // However it is necessary to validate the name first. Errors
140 int result = TCL_OK; 138 int result = TCL_OK;
141 try { 139 try {
142 140
143 // Currently there are no command-line options. This may change in future. 141 // Currently there are no command-line options. This may change in future.
144 if (3 != argc) { 142 if (3 != argc) {
145 CdlParse::report_error(interp, std::string("Incorrect number of arguments to ") + diag_argv0 + 143 CdlParse::report_error(interp, "", std::string("Incorrect number of arguments to `") + diag_argv0 +
146 "\n Expecting name and properties list."); 144 "'\nExpecting name and properties list.");
147 ok = false; 145 ok = false;
148 } else if (!Tcl_CommandComplete(argv[2])) { 146 } else if (!Tcl_CommandComplete(argv[2])) {
149 CdlParse::report_error(interp, std::string("Invalid property list for cdl_interface ") + argv[1]); 147 CdlParse::report_error(interp, "", std::string("Invalid property list for cdl_interface `") + argv[1] + "'.");
150 ok = false; 148 ok = false;
151 } else if (0 != toplevel->lookup(argv[1])) { 149 } else if (0 != toplevel->lookup(argv[1])) {
152 // FIXME: interfaces can be generated implicitly because of an 150 // FIXME: interfaces can be generated implicitly because of an
153 // unresolved implements property. This code should look for 151 // unresolved implements property. This code should look for
154 // an existing auto-generated interface object and replace it 152 // an existing auto-generated interface object and replace it
155 // if necessary. 153 // if necessary.
156 CdlParse::report_error(interp, std::string("Interface ") + argv[1] + " cannot be loaded.\n" + 154 CdlParse::report_error(interp, "", std::string("Interface `") + argv[1] +
157 " The name is already in use."); 155 "' cannot be loaded.\nThe name is already in use.");
158 ok = false; 156 ok = false;
159 } else { 157 } else {
160 new_interface = new CdlInterfaceBody(argv[1], false); 158 new_interface = new CdlInterfaceBody(argv[1], false);
161 toplevel->add_node(loadable, parent, new_interface); 159 toplevel->add_node(loadable, parent, new_interface);
162 } 160 }
166 // reason to abort the whole parsing process. 164 // reason to abort the whole parsing process.
167 CYG_REPORT_RETVAL(TCL_OK); 165 CYG_REPORT_RETVAL(TCL_OK);
168 return TCL_OK; 166 return TCL_OK;
169 } 167 }
170 } catch(std::bad_alloc e) { 168 } catch(std::bad_alloc e) {
171 interp->set_result(CdlParse::get_diagnostic_prefix(interp) + "Out of memory."); 169 interp->set_result(CdlParse::construct_diagnostic(interp, "internal error", "", "Out of memory"));
172 result = TCL_ERROR; 170 result = TCL_ERROR;
173 } catch(CdlParseException e) { 171 } catch(CdlParseException e) {
174 interp->set_result(e.get_message()); 172 interp->set_result(e.get_message());
175 result = TCL_ERROR; 173 result = TCL_ERROR;
176 } catch(...) { 174 } catch(...) {
177 interp->set_result(CdlParse::get_diagnostic_prefix(interp) + "internal error, unexpected C++ exception."); 175 interp->set_result(CdlParse::construct_diagnostic(interp, "internal error", "", "Unexpected C++ exception"));
178 result = TCL_ERROR; 176 result = TCL_ERROR;
179 } 177 }
180 if (TCL_OK != result) { 178 if (TCL_OK != result) {
181 CYG_REPORT_RETVAL(result); 179 CYG_REPORT_RETVAL(result);
182 return result; 180 return result;
235 233
236 // A few properties do not make sense for interfaces. 234 // A few properties do not make sense for interfaces.
237 // Start with the value-related ones. Interfaces always 235 // Start with the value-related ones. Interfaces always
238 // have the flavor Data. 236 // have the flavor Data.
239 if (new_interface->has_property(CdlPropertyId_Flavor)) { 237 if (new_interface->has_property(CdlPropertyId_Flavor)) {
240 CdlParse::report_error(interp, "An interface should not have a `flavor' property."); 238 CdlParse::report_error(interp, "", "An interface should not have a `flavor' property.");
241 } 239 }
242 // Interfaces cannot be modified directly by the user, so 240 // Interfaces cannot be modified directly by the user, so
243 // there is no point in entry_proc, check_proc, dialog or 241 // there is no point in entry_proc, check_proc, dialog or
244 // wizard 242 // wizard
245 if (new_interface->has_property(CdlPropertyId_EntryProc)) { 243 if (new_interface->has_property(CdlPropertyId_EntryProc)) {
246 CdlParse::report_error(interp, "An interface should not have an `entry_proc' property."); 244 CdlParse::report_error(interp, "", "An interface should not have an `entry_proc' property.");
247 } 245 }
248 if (new_interface->has_property(CdlPropertyId_CheckProc)) { 246 if (new_interface->has_property(CdlPropertyId_CheckProc)) {
249 CdlParse::report_error(interp, "An interface should not have a `check_proc' property."); 247 CdlParse::report_error(interp, "", "An interface should not have a `check_proc' property.");
250 } 248 }
251 if (new_interface->has_property(CdlPropertyId_Dialog)) { 249 if (new_interface->has_property(CdlPropertyId_Dialog)) {
252 CdlParse::report_error(interp, "An interface should not have a `dialog' property."); 250 CdlParse::report_error(interp, "", "An interface should not have a `dialog' property.");
253 } 251 }
254 if (new_interface->has_property(CdlPropertyId_Wizard)) { 252 if (new_interface->has_property(CdlPropertyId_Wizard)) {
255 CdlParse::report_error(interp, "An interface should not have a `wizard' property."); 253 CdlParse::report_error(interp, "", "An interface should not have a `wizard' property.");
256 } 254 }
257 // Calculated does not make sense, an interface is implicitly calculated 255 // Calculated does not make sense, an interface is implicitly calculated
258 // Nor does default_value. 256 // Nor does default_value.
259 if (new_interface->has_property(CdlPropertyId_Calculated)) { 257 if (new_interface->has_property(CdlPropertyId_Calculated)) {
260 CdlParse::report_error(interp, "An interface should not have a `calculated' property."); 258 CdlParse::report_error(interp, "", "An interface should not have a `calculated' property.");
261 } 259 }
262 if (new_interface->has_property(CdlPropertyId_DefaultValue)) { 260 if (new_interface->has_property(CdlPropertyId_DefaultValue)) {
263 CdlParse::report_error(interp, "An interface should not have a `default_value' property."); 261 CdlParse::report_error(interp, "", "An interface should not have a `default_value' property.");
264 } 262 }
265 // active_if might make sense, as a way of controlling 263 // active_if might make sense, as a way of controlling
266 // whether or not a #define will be generated. 264 // whether or not a #define will be generated.
267 265
268 // legal_values, requires and implements are all sensible 266 // legal_values, requires and implements are all sensible
281 } 279 }
282 } catch (std::bad_alloc e) { 280 } catch (std::bad_alloc e) {
283 // Errors at this stage should be reported via Tcl, not via C++. 281 // Errors at this stage should be reported via Tcl, not via C++.
284 // However there is no point in continuing with the parsing operation, 282 // However there is no point in continuing with the parsing operation,
285 // just give up. 283 // just give up.
286 interp->set_result(CdlParse::get_diagnostic_prefix(interp) + "Out of memory."); 284 interp->set_result(CdlParse::construct_diagnostic(interp, "internal error", "", "Out of memory"));
287 result = TCL_ERROR; 285 result = TCL_ERROR;
288 } catch (CdlParseException e) { 286 } catch (CdlParseException e) {
289 interp->set_result(e.get_message()); 287 interp->set_result(e.get_message());
290 result = TCL_ERROR; 288 result = TCL_ERROR;
291 } catch(...) { 289 } catch(...) {
292 interp->set_result(CdlParse::get_diagnostic_prefix(interp) + "internal error, unexpected C++ exception."); 290 interp->set_result(CdlParse::construct_diagnostic(interp, "internal error", "", "Unexpected C++ exception"));
293 result = TCL_ERROR; 291 result = TCL_ERROR;
294 } 292 }
295 293
296 // Restore the interpreter to its prior state. 294 // Restore the interpreter to its prior state.
297 interp->pop_node(old_node); 295 interp->pop_node(old_node);
384 CdlNode old_node = 0; 382 CdlNode old_node = 0;
385 383
386 try { 384 try {
387 385
388 if (3 != argc) { 386 if (3 != argc) {
389 CdlParse::report_error(interp, "Invalid cdl_interface command in savefile, expecting two arguments."); 387 CdlParse::report_error(interp, "", "Invalid cdl_interface command in savefile, expecting two arguments.");
390 } else { 388 } else {
391 389
392 CdlNode current_node = toplevel->lookup(argv[1]); 390 CdlNode current_node = toplevel->lookup(argv[1]);
393 if (0 == current_node) { 391 if (0 == current_node) {
394 // FIXME: save value in limbo 392 // FIXME: save value in limbo
395 CdlParse::report_error(interp, 393 CdlParse::report_error(interp, "",
396 std::string("The savefile contains a cdl_interface command for an unknown interface `") 394 std::string("The savefile contains a cdl_interface command for an unknown interface `")
397 + argv[1] + "'"); 395 + argv[1] + "'.");
398 } else { 396 } else {
399 toplevel->get_savefile_subcommands("cdl_interface", subcommands); 397 toplevel->get_savefile_subcommands("cdl_interface", subcommands);
400 toplevel_commands = interp->push_commands(subcommands); 398 toplevel_commands = interp->push_commands(subcommands);
401 old_node = interp->push_node(current_node); 399 old_node = interp->push_node(current_node);
402 400