1 // file : xsd/cxx/tree/parser-header.cxx 2 // copyright : Copyright (c) 2005-2017 Code Synthesis Tools CC 3 // license : GNU GPL v2 + exceptions; see accompanying LICENSE file 4 5 #include <cxx/tree/parser-header.hxx> 6 7 #include <xsd-frontend/semantic-graph.hxx> 8 #include <xsd-frontend/traversal.hxx> 9 10 namespace CXX 11 { 12 namespace Tree 13 { 14 namespace 15 { 16 struct ElementFunction: Traversal::Element, 17 GlobalElementBase, 18 Context 19 { ElementFunctionCXX::Tree::__anon838eb6f90111::ElementFunction20 ElementFunction (Context& c) 21 : GlobalElementBase (c), Context (c) 22 { 23 } 24 25 virtual void traverseCXX::Tree::__anon838eb6f90111::ElementFunction26 traverse (Type& e) 27 { 28 if (!doc_root_p (e)) 29 return; 30 31 String const& name (eparser (e)); 32 String const& error_handler (error_handler_type); 33 34 if (doxygen) 35 { 36 os << "/**" << endl 37 << " * @name Parsing functions for the %" << 38 comment (e.name ()) << " document root." << endl; 39 40 if (e.annotated_p ()) 41 { 42 os << " *" << endl; 43 write_annotation (e.annotation ()); 44 } 45 46 os << " */" << endl 47 << "//@{" << endl 48 << endl; 49 } 50 51 if (!doxygen) 52 { 53 os << "// Parse a URI or a local file." << endl 54 << "//" << endl 55 << endl; 56 } 57 58 if (doxygen) 59 { 60 os << "/**" << endl 61 << " * @brief Parse a URI or a local file." << endl 62 << " *" << endl 63 << " * @param uri A URI or a local file name." << endl 64 << " * @param f Parsing flags." << endl 65 << " * @param p Parsing properties. " << endl 66 << " * @return A pointer to the root of the object model." << endl 67 << " *" << endl 68 << " * This function uses exceptions to report parsing errors." << endl 69 << " */" << endl; 70 } 71 72 os << inst_exp 73 << auto_ptr << "< " << type_name (e) << " >" << endl 74 << name << " (const " << string_type << "& uri," << endl 75 << flags_type << " f = 0," << endl 76 << "const " << properties_type << "& p = " << properties_type << " ());" 77 << endl; 78 79 if (doxygen) 80 { 81 os << "/**" << endl 82 << " * @brief Parse a URI or a local file with an error handler." << endl 83 << " *" << endl 84 << " * @param uri A URI or a local file name." << endl 85 << " * @param eh An error handler." << endl 86 << " * @param f Parsing flags." << endl 87 << " * @param p Parsing properties. " << endl 88 << " * @return A pointer to the root of the object model." << endl 89 << " *" << endl 90 << " * This function reports parsing errors by calling the " << 91 "error handler." << endl 92 << " */" << endl; 93 } 94 95 os << inst_exp 96 << auto_ptr << "< " << type_name (e) << " >" << endl 97 << name << " (const " << string_type << "& uri," << endl 98 << error_handler << "& eh," << endl 99 << flags_type << " f = 0," << endl 100 << "const " << properties_type << "& p = " << properties_type << " ());" 101 << endl; 102 103 if (doxygen) 104 { 105 os << "/**" << endl 106 << " * @brief Parse a URI or a local file with a Xerces-C++ " << 107 "DOM error" << endl 108 << " * handler." << endl 109 << " *" << endl 110 << " * @param uri A URI or a local file name." << endl 111 << " * @param eh A Xerces-C++ DOM error handler." << endl 112 << " * @param f Parsing flags." << endl 113 << " * @param p Parsing properties. " << endl 114 << " * @return A pointer to the root of the object model." << endl 115 << " *" << endl 116 << " * This function reports parsing errors by calling the " << 117 "error handler." << endl 118 << " */" << endl; 119 } 120 121 os << inst_exp 122 << auto_ptr << "< " << type_name (e) << " >" << endl 123 << name << " (const " << string_type << "& uri," << endl 124 << xerces_ns << "::DOMErrorHandler& eh," << endl 125 << flags_type << " f = 0," << endl 126 << "const " << properties_type << "& p = " << properties_type << " ());" 127 << endl; 128 129 if (!doxygen) 130 { 131 os << "// Parse std::istream." << endl 132 << "//" << endl 133 << endl; 134 } 135 136 if (doxygen) 137 { 138 os << "/**" << endl 139 << " * @brief Parse a standard input stream." << endl 140 << " *" << endl 141 << " * @param is A standrad input stream." << endl 142 << " * @param f Parsing flags." << endl 143 << " * @param p Parsing properties. " << endl 144 << " * @return A pointer to the root of the object model." << endl 145 << " *" << endl 146 << " * This function uses exceptions to report parsing errors." << endl 147 << " */" << endl; 148 } 149 150 os << inst_exp 151 << auto_ptr << "< " << type_name (e) << " >" << endl 152 << name << " (::std::istream& is," << endl 153 << flags_type << " f = 0," << endl 154 << "const " << properties_type << "& p = " << properties_type << " ());" 155 << endl; 156 157 if (doxygen) 158 { 159 os << "/**" << endl 160 << " * @brief Parse a standard input stream with an error handler." << endl 161 << " *" << endl 162 << " * @param is A standrad input stream." << endl 163 << " * @param eh An error handler." << endl 164 << " * @param f Parsing flags." << endl 165 << " * @param p Parsing properties. " << endl 166 << " * @return A pointer to the root of the object model." << endl 167 << " *" << endl 168 << " * This function reports parsing errors by calling the " << 169 "error handler." << endl 170 << " */" << endl; 171 } 172 173 os << inst_exp 174 << auto_ptr << "< " << type_name (e) << " >" << endl 175 << name << " (::std::istream& is," << endl 176 << error_handler << "& eh," << endl 177 << flags_type << " f = 0," << endl 178 << "const " << properties_type << "& p = " << properties_type << " ());" 179 << endl; 180 181 if (doxygen) 182 { 183 os << "/**" << endl 184 << " * @brief Parse a standard input stream with a " << 185 "Xerces-C++ DOM error" << endl 186 << " * handler." << endl 187 << " *" << endl 188 << " * @param is A standrad input stream." << endl 189 << " * @param eh A Xerces-C++ DOM error handler." << endl 190 << " * @param f Parsing flags." << endl 191 << " * @param p Parsing properties. " << endl 192 << " * @return A pointer to the root of the object model." << endl 193 << " *" << endl 194 << " * This function reports parsing errors by calling the " << 195 "error handler." << endl 196 << " */" << endl; 197 } 198 199 os << inst_exp 200 << auto_ptr << "< " << type_name (e) << " >" << endl 201 << name << " (::std::istream& is," << endl 202 << xerces_ns << "::DOMErrorHandler& eh," << endl 203 << flags_type << " f = 0," << endl 204 << "const " << properties_type << "& p = " << properties_type << " ());" 205 << endl; 206 207 if (doxygen) 208 { 209 os << "/**" << endl 210 << " * @brief Parse a standard input stream with a resource id." << endl 211 << " *" << endl 212 << " * @param is A standrad input stream." << endl 213 << " * @param id A resource id." << endl 214 << " * @param f Parsing flags." << endl 215 << " * @param p Parsing properties. " << endl 216 << " * @return A pointer to the root of the object model." << endl 217 << " *" << endl 218 << " * The resource id is used to identify the document " << 219 "being parsed in" << endl 220 << " * diagnostics as well as to resolve relative paths." << endl 221 << " *" << endl 222 << " * This function uses exceptions to report parsing errors." << endl 223 << " */" << endl; 224 } 225 226 os << inst_exp 227 << auto_ptr << "< " << type_name (e) << " >" << endl 228 << name << " (::std::istream& is," << endl 229 << "const " << string_type << "& id," << endl 230 << flags_type << " f = 0," << endl 231 << "const " << properties_type << "& p = " << properties_type << " ());" 232 << endl; 233 234 if (doxygen) 235 { 236 os << "/**" << endl 237 << " * @brief Parse a standard input stream with a resource " << 238 "id and an" << endl 239 << " * error handler." << endl 240 << " *" << endl 241 << " * @param is A standrad input stream." << endl 242 << " * @param id A resource id." << endl 243 << " * @param eh An error handler." << endl 244 << " * @param f Parsing flags." << endl 245 << " * @param p Parsing properties. " << endl 246 << " * @return A pointer to the root of the object model." << endl 247 << " *" << endl 248 << " * The resource id is used to identify the document " << 249 "being parsed in" << endl 250 << " * diagnostics as well as to resolve relative paths." << endl 251 << " *" << endl 252 << " * This function reports parsing errors by calling the " << 253 "error handler." << endl 254 << " */" << endl; 255 } 256 257 os << inst_exp 258 << auto_ptr << "< " << type_name (e) << " >" << endl 259 << name << " (::std::istream& is," << endl 260 << "const " << string_type << "& id," << endl 261 << error_handler << "& eh," << endl 262 << flags_type << " f = 0," << endl 263 << "const " << properties_type << "& p = " << properties_type << " ());" 264 << endl; 265 266 if (doxygen) 267 { 268 os << "/**" << endl 269 << " * @brief Parse a standard input stream with a resource " << 270 "id and a" << endl 271 << " * Xerces-C++ DOM error handler." << endl 272 << " *" << endl 273 << " * @param is A standrad input stream." << endl 274 << " * @param id A resource id." << endl 275 << " * @param eh A Xerces-C++ DOM error handler." << endl 276 << " * @param f Parsing flags." << endl 277 << " * @param p Parsing properties. " << endl 278 << " * @return A pointer to the root of the object model." << endl 279 << " *" << endl 280 << " * The resource id is used to identify the document " << 281 "being parsed in" << endl 282 << " * diagnostics as well as to resolve relative paths." << endl 283 << " *" << endl 284 << " * This function reports parsing errors by calling the " << 285 "error handler." << endl 286 << " */" << endl; 287 } 288 289 os << inst_exp 290 << auto_ptr << "< " << type_name (e) << " >" << endl 291 << name << " (::std::istream& is," << endl 292 << "const " << string_type << "& id," << endl 293 << xerces_ns << "::DOMErrorHandler& eh," << endl 294 << flags_type << " f = 0," << endl 295 << "const " << properties_type << "& p = " << properties_type << " ());" 296 << endl; 297 298 if (!doxygen) 299 { 300 os << "// Parse xercesc::InputSource." << endl 301 << "//" << endl 302 << endl; 303 } 304 305 if (doxygen) 306 { 307 os << "/**" << endl 308 << " * @brief Parse a Xerces-C++ input source." << endl 309 << " *" << endl 310 << " * @param is A Xerces-C++ input source." << endl 311 << " * @param f Parsing flags." << endl 312 << " * @param p Parsing properties. " << endl 313 << " * @return A pointer to the root of the object model." << endl 314 << " *" << endl 315 << " * This function uses exceptions to report parsing errors." << endl 316 << " */" << endl; 317 } 318 319 os << inst_exp 320 << auto_ptr << "< " << type_name (e) << " >" << endl 321 << name << " (" << xerces_ns << "::InputSource& is," << endl 322 << flags_type << " f = 0," << endl 323 << "const " << properties_type << "& p = " << properties_type << " ());" 324 << endl; 325 326 if (doxygen) 327 { 328 os << "/**" << endl 329 << " * @brief Parse a Xerces-C++ input source with an " << 330 "error handler." << endl 331 << " *" << endl 332 << " * @param is A Xerces-C++ input source." << endl 333 << " * @param eh An error handler." << endl 334 << " * @param f Parsing flags." << endl 335 << " * @param p Parsing properties. " << endl 336 << " * @return A pointer to the root of the object model." << endl 337 << " *" << endl 338 << " * This function reports parsing errors by calling the " << 339 "error handler." << endl 340 << " */" << endl; 341 } 342 343 os << inst_exp 344 << auto_ptr << "< " << type_name (e) << " >" << endl 345 << name << " (" << xerces_ns << "::InputSource& is," << endl 346 << error_handler << "& eh," << endl 347 << flags_type << " f = 0," << endl 348 << "const " << properties_type << "& p = " << properties_type << " ());" 349 << endl; 350 351 if (doxygen) 352 { 353 os << "/**" << endl 354 << " * @brief Parse a Xerces-C++ input source with a " << 355 "Xerces-C++ DOM" << endl 356 << " * error handler." << endl 357 << " *" << endl 358 << " * @param is A Xerces-C++ input source." << endl 359 << " * @param eh A Xerces-C++ DOM error handler." << endl 360 << " * @param f Parsing flags." << endl 361 << " * @param p Parsing properties. " << endl 362 << " * @return A pointer to the root of the object model." << endl 363 << " *" << endl 364 << " * This function reports parsing errors by calling the " << 365 "error handler." << endl 366 << " */" << endl; 367 } 368 369 os << inst_exp 370 << auto_ptr << "< " << type_name (e) << " >" << endl 371 << name << " (" << xerces_ns << "::InputSource& is," << endl 372 << xerces_ns << "::DOMErrorHandler& eh," << endl 373 << flags_type << " f = 0," << endl 374 << "const " << properties_type << "& p = " << properties_type << " ());" 375 << endl; 376 377 if (!doxygen) 378 { 379 os << "// Parse xercesc::DOMDocument." << endl 380 << "//" << endl 381 << endl; 382 } 383 384 if (doxygen) 385 { 386 os << "/**" << endl 387 << " * @brief Parse a Xerces-C++ DOM document." << endl 388 << " *" << endl 389 << " * @param d A Xerces-C++ DOM document." << endl 390 << " * @param f Parsing flags." << endl 391 << " * @param p Parsing properties. " << endl 392 << " * @return A pointer to the root of the object model." << endl 393 << " */" << endl; 394 } 395 396 os << inst_exp 397 << auto_ptr << "< " << type_name (e) << " >" << endl 398 << name << " (const " << xerces_ns << "::DOMDocument& d," << endl 399 << flags_type << " f = 0," << endl 400 << "const " << properties_type << "& p = " << properties_type << " ());" 401 << endl; 402 403 if (doxygen) 404 { 405 os << "/**" << endl 406 << " * @brief Parse a Xerces-C++ DOM document." << endl 407 << " *" << endl 408 << " * @param d A pointer to the Xerces-C++ DOM document." << endl 409 << " * @param f Parsing flags." << endl 410 << " * @param p Parsing properties. " << endl 411 << " * @return A pointer to the root of the object model." << endl 412 << " *" << endl 413 << " * This function is normally used together with the " << 414 "keep_dom and" << endl 415 << " * own_dom parsing flags to assign ownership of the DOM " << 416 "document" << endl 417 << " * to the object model." << endl 418 << " */" << endl; 419 } 420 421 os << inst_exp 422 << auto_ptr << "< " << type_name (e) << " >" << endl 423 << name << " (" << dom_auto_ptr << "< " << xerces_ns << 424 "::DOMDocument > d," << endl 425 << flags_type << " f = 0," << endl 426 << "const " << properties_type << "& p = " << properties_type << " ());" 427 << endl; 428 429 if (doxygen) 430 { 431 os << "//@}" << endl 432 << endl; 433 } 434 } 435 436 private: 437 String type_nameCXX::Tree::__anon838eb6f90111::ElementFunction438 type_name (Type& e) 439 { 440 std::wostringstream o; 441 442 MemberTypeName type (*this, o); 443 type.dispatch (e.type ()); 444 445 return o.str (); 446 } 447 }; 448 } 449 450 451 void generate_parser_header(Context & ctx)452 generate_parser_header (Context& ctx) 453 { 454 ctx.os << "#include <iosfwd>" << endl 455 << endl 456 << "#include <xercesc/sax/InputSource.hpp>" << endl 457 << "#include <xercesc/dom/DOMDocument.hpp>" << endl 458 << "#include <xercesc/dom/DOMErrorHandler.hpp>" << endl 459 << endl; 460 461 Traversal::Schema schema; 462 Sources sources; 463 Traversal::Names names_ns, names; 464 Namespace ns (ctx); 465 ElementFunction element (ctx); 466 467 schema >> sources >> schema; 468 schema >> names_ns >> ns >> names >> element; 469 470 schema.dispatch (ctx.schema_root); 471 } 472 } 473 } 474