339 fprintf (stderr, "*** cannot create %s\n", qPrintable(grammar.merged_output)); |
339 fprintf (stderr, "*** cannot create %s\n", qPrintable(grammar.merged_output)); |
340 return; |
340 return; |
341 } |
341 } |
342 |
342 |
343 QTextStream out (&f); |
343 QTextStream out (&f); |
344 out << "// This file was generated by qlalr - DO NOT EDIT!\n"; |
344 |
345 |
345 // copyright headers must come first, otherwise the headers tests will fail |
346 if (copyright) |
346 if (copyright) |
347 { |
347 { |
348 out << copyrightHeader() |
348 out << copyrightHeader() |
349 << privateCopyrightHeader() |
349 << privateCopyrightHeader() |
350 << endl; |
350 << endl; |
351 } |
351 } |
352 |
352 |
|
353 out << "// This file was generated by qlalr - DO NOT EDIT!\n"; |
|
354 |
353 out << startIncludeGuard(grammar.merged_output) << endl; |
355 out << startIncludeGuard(grammar.merged_output) << endl; |
|
356 |
|
357 if (copyright) { |
|
358 out << "#if defined(Q_OS_VXWORKS) && defined(ERROR)" << endl |
|
359 << "# undef ERROR" << endl |
|
360 << "#endif" << endl << endl; |
|
361 } |
354 |
362 |
355 generateDecl (out); |
363 generateDecl (out); |
356 generateImpl (out); |
364 generateImpl (out); |
357 out << p.decls(); |
365 out << p.decls(); |
358 out << p.impls(); |
366 out << p.impls(); |
369 |
377 |
370 { // decls... |
378 { // decls... |
371 QFile f (declFileName); |
379 QFile f (declFileName); |
372 f.open (QFile::WriteOnly); |
380 f.open (QFile::WriteOnly); |
373 QTextStream out (&f); |
381 QTextStream out (&f); |
374 out << "// This file was generated by qlalr - DO NOT EDIT!\n"; |
|
375 |
382 |
376 QString prot = declFileName.toUpper ().replace (QLatin1Char ('.'), QLatin1Char ('_')); |
383 QString prot = declFileName.toUpper ().replace (QLatin1Char ('.'), QLatin1Char ('_')); |
377 |
384 |
|
385 // copyright headers must come first, otherwise the headers tests will fail |
378 if (copyright) |
386 if (copyright) |
379 { |
387 { |
380 out << copyrightHeader() |
388 out << copyrightHeader() |
381 << privateCopyrightHeader() |
389 << privateCopyrightHeader() |
382 << endl; |
390 << endl; |
383 } |
391 } |
384 |
392 |
|
393 out << "// This file was generated by qlalr - DO NOT EDIT!\n"; |
|
394 |
385 out << "#ifndef " << prot << endl |
395 out << "#ifndef " << prot << endl |
386 << "#define " << prot << endl |
396 << "#define " << prot << endl |
387 << endl; |
397 << endl; |
388 |
398 |
|
399 if (copyright) { |
|
400 out << "#include <QtCore/qglobal.h>" << endl << endl; |
|
401 out << "QT_BEGIN_NAMESPACE" << endl << endl; |
|
402 } |
389 generateDecl (out); |
403 generateDecl (out); |
|
404 if (copyright) |
|
405 out << "QT_END_NAMESPACE" << endl; |
390 |
406 |
391 out << "#endif // " << prot << endl << endl; |
407 out << "#endif // " << prot << endl << endl; |
392 } // end decls |
408 } // end decls |
393 |
409 |
394 { // bits... |
410 { // bits... |
395 QFile f (bitsFileName); |
411 QFile f (bitsFileName); |
396 f.open (QFile::WriteOnly); |
412 f.open (QFile::WriteOnly); |
397 QTextStream out (&f); |
413 QTextStream out (&f); |
398 out << "// This file was generated by qlalr - DO NOT EDIT!\n"; |
414 |
399 |
415 // copyright headers must come first, otherwise the headers tests will fail |
400 if (copyright) |
416 if (copyright) |
401 out << copyrightHeader(); |
417 out << copyrightHeader(); |
402 |
418 |
|
419 out << "// This file was generated by qlalr - DO NOT EDIT!\n"; |
|
420 |
403 out << "#include \"" << declFileName << "\"" << endl << endl; |
421 out << "#include \"" << declFileName << "\"" << endl << endl; |
|
422 if (copyright) |
|
423 out << "QT_BEGIN_NAMESPACE" << endl << endl; |
404 generateImpl(out); |
424 generateImpl(out); |
|
425 if (copyright) |
|
426 out << "QT_END_NAMESPACE" << endl; |
405 |
427 |
406 } // end bits |
428 } // end bits |
407 |
429 |
408 if (! grammar.decl_file_name.isEmpty ()) |
430 if (! grammar.decl_file_name.isEmpty ()) |
409 { |
431 { |
410 QFile f (grammar.decl_file_name); |
432 QFile f (grammar.decl_file_name); |
411 f.open (QFile::WriteOnly); |
433 f.open (QFile::WriteOnly); |
412 QTextStream out (&f); |
434 QTextStream out (&f); |
413 out << "// This file was generated by qlalr - DO NOT EDIT!\n"; |
|
414 out << p.decls(); |
435 out << p.decls(); |
415 } |
436 } |
416 |
437 |
417 if (! grammar.impl_file_name.isEmpty ()) |
438 if (! grammar.impl_file_name.isEmpty ()) |
418 { |
439 { |
419 QFile f (grammar.impl_file_name); |
440 QFile f (grammar.impl_file_name); |
420 f.open (QFile::WriteOnly); |
441 f.open (QFile::WriteOnly); |
421 QTextStream out (&f); |
442 QTextStream out (&f); |
422 out << "// This file was generated by qlalr - DO NOT EDIT!\n"; |
|
423 out << p.impls(); |
443 out << p.impls(); |
424 } |
444 } |
425 } |
445 } |
426 |
446 |
427 QString CppGenerator::debugInfoProt() const |
447 QString CppGenerator::debugInfoProt() const |
466 << " GOTO_INDEX_OFFSET = " << compressed_action.index.size () << "," << endl |
486 << " GOTO_INDEX_OFFSET = " << compressed_action.index.size () << "," << endl |
467 << " GOTO_INFO_OFFSET = " << compressed_action.info.size () << "," << endl |
487 << " GOTO_INFO_OFFSET = " << compressed_action.info.size () << "," << endl |
468 << " GOTO_CHECK_OFFSET = " << compressed_action.check.size () << endl |
488 << " GOTO_CHECK_OFFSET = " << compressed_action.check.size () << endl |
469 << " };" << endl |
489 << " };" << endl |
470 << endl |
490 << endl |
471 << " static const char *const spell [];" << endl |
491 << " static const char *const spell [];" << endl |
472 << " static const int lhs [];" << endl |
492 << " static const short lhs [];" << endl |
473 << " static const int rhs [];" << endl; |
493 << " static const short rhs [];" << endl; |
474 |
494 |
475 if (debug_info) |
495 if (debug_info) |
476 { |
496 { |
477 QString prot = debugInfoProt(); |
497 QString prot = debugInfoProt(); |
478 |
498 |
480 << " static const int rule_index [];" << endl |
500 << " static const int rule_index [];" << endl |
481 << " static const int rule_info [];" << endl |
501 << " static const int rule_info [];" << endl |
482 << "#endif // " << prot << endl << endl; |
502 << "#endif // " << prot << endl << endl; |
483 } |
503 } |
484 |
504 |
485 out << " static const int goto_default [];" << endl |
505 out << " static const short goto_default [];" << endl |
486 << " static const int action_default [];" << endl |
506 << " static const short action_default [];" << endl |
487 << " static const int action_index [];" << endl |
507 << " static const short action_index [];" << endl |
488 << " static const int action_info [];" << endl |
508 << " static const short action_info [];" << endl |
489 << " static const int action_check [];" << endl |
509 << " static const short action_check [];" << endl |
490 << endl |
510 << endl |
491 << " static inline int nt_action (int state, int nt)" << endl |
511 << " static inline int nt_action (int state, int nt)" << endl |
492 << " {" << endl |
512 << " {" << endl |
493 << " const int *const goto_index = &action_index [GOTO_INDEX_OFFSET];" << endl |
513 << " const int yyn = action_index [GOTO_INDEX_OFFSET + state] + nt;" << endl |
494 << " const int *const goto_check = &action_check [GOTO_CHECK_OFFSET];" << endl |
514 << " if (yyn < 0 || action_check [GOTO_CHECK_OFFSET + yyn] != nt)" << endl |
495 << endl |
|
496 << " const int yyn = goto_index [state] + nt;" << endl |
|
497 << endl |
|
498 << " if (yyn < 0 || goto_check [yyn] != nt)" << endl |
|
499 << " return goto_default [nt];" << endl |
515 << " return goto_default [nt];" << endl |
500 << endl |
516 << endl |
501 << " const int *const goto_info = &action_info [GOTO_INFO_OFFSET];" << endl |
517 << " return action_info [GOTO_INFO_OFFSET + yyn];" << endl |
502 << " return goto_info [yyn];" << endl |
|
503 << " }" << endl |
518 << " }" << endl |
504 << endl |
519 << endl |
505 << " static inline int t_action (int state, int token)" << endl |
520 << " static inline int t_action (int state, int token)" << endl |
506 << " {" << endl |
521 << " {" << endl |
507 << " const int yyn = action_index [state] + token;" << endl |
522 << " const int yyn = action_index [state] + token;" << endl |