| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 | |
| 4 | #ifndef CPPGENERATOR_H |
| 5 | #define CPPGENERATOR_H |
| 6 | |
| 7 | #include "lalr.h" |
| 8 | #include "compress.h" |
| 9 | |
| 10 | class Grammar; |
| 11 | class Automaton; |
| 12 | class Recognizer; |
| 13 | |
| 14 | class CppGenerator |
| 15 | { |
| 16 | public: |
| 17 | CppGenerator(const Recognizer &p, Grammar &grammar, Automaton &aut, bool verbose): |
| 18 | p (p), |
| 19 | grammar (grammar), |
| 20 | aut (aut), |
| 21 | verbose (verbose), |
| 22 | debug_info (false), |
| 23 | copyright (false), |
| 24 | warnings_are_errors(false) {} |
| 25 | |
| 26 | void operator () (); |
| 27 | |
| 28 | bool debugInfo () const { return debug_info; } |
| 29 | void setDebugInfo (bool d) { debug_info = d; } |
| 30 | |
| 31 | void setCopyright (bool t) { copyright = t; } |
| 32 | |
| 33 | void setWarningsAreErrors (bool e) { warnings_are_errors = e; } |
| 34 | |
| 35 | private: |
| 36 | void generateDecl (QTextStream &out); |
| 37 | void generateImpl (QTextStream &out); |
| 38 | |
| 39 | QString debugInfoProt() const; |
| 40 | QString copyrightHeader() const; |
| 41 | QString privateCopyrightHeader() const; |
| 42 | |
| 43 | private: |
| 44 | static QString startIncludeGuard(const QString &fileName); |
| 45 | static QString endIncludeGuard(const QString &fileName); |
| 46 | |
| 47 | const Recognizer &p; |
| 48 | Grammar &grammar; |
| 49 | Automaton &aut; |
| 50 | bool verbose; |
| 51 | int accept_state; |
| 52 | int state_count; |
| 53 | int terminal_count; |
| 54 | int non_terminal_count; |
| 55 | bool debug_info; |
| 56 | bool copyright; |
| 57 | bool warnings_are_errors; |
| 58 | Compress compressed_action; |
| 59 | Compress compressed_goto; |
| 60 | QList<int> count; |
| 61 | QList<int> defgoto; |
| 62 | }; |
| 63 | |
| 64 | #endif // CPPGENERATOR_H |
| 65 |
