-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathObCppGen.h
88 lines (83 loc) · 4.91 KB
/
ObCppGen.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef OBCPPGEN_H
#define OBCPPGEN_H
/*
* Copyright 2019 Rochus Keller <mailto:[email protected]>
*
* This file is part of the Oberon parser/code model library.
*
* The following is the license that applies to this copy of the
* library. For a license to use the library under conditions
* other than those described here, please email to [email protected].
*
* GNU General Public License Usage
* This file may be used under the terms of the GNU General Public
* License (GPL) versions 2.0 or 3.0 as published by the Free Software
* Foundation and appearing in the file LICENSE.GPL included in
* the packaging of this file. Please review the following information
* to ensure GNU General Public Licensing requirements will be met:
* http://www.fsf.org/licensing/licenses/info/GPLv2.html and
* http://www.gnu.org/copyleft/gpl.html.
*/
#include <Oberon/ObCodeModel.h>
#include <Oberon/ObErrors.h>
#include <QTextStream>
namespace Ob
{
// Automatically translate Lola-2 compiler to C++.
class CppGen : public QObject
{
public:
CppGen(CodeModel*);
void setGenStubs(bool on) { d_genStubs = on; }
bool emitModules(const QString& outdir, const QString& ns = QString(), const QString& mod = QString() );
protected:
bool emitObnUtils( const QString& outdir, const QString& ns = QString(), const QString& mod = QString() );
void emitModule(const CodeModel::Module*);
void emitHeader(const CodeModel::Module*, QTextStream& out, int level);
void emitBody(const CodeModel::Module*, QTextStream& out);
QString includeFileName( const QString& modName );
QString ws(int level);
QString basicType( const CodeModel::Type* );
void emitType(const CodeModel::Unit*,const CodeModel::Type* , QTextStream&, int level);
void emitProcType(const CodeModel::Unit*, const CodeModel::Type*, const QByteArray& name , QTextStream&, int level );
void emitExpression( const CodeModel::Unit*, const SynTree*, QTextStream&, int level );
void emitSimpleExpression(const CodeModel::Unit* ds,const SynTree* st, QTextStream& out, int level);
void emitTerm(const CodeModel::Unit* ds,const SynTree* st, QTextStream& out, int level );
void emitTerm(const CodeModel::Unit* ds,const QList<SynTree*> st, int i, QTextStream& out, int level );
void emitFactor(const CodeModel::Unit* ds,const SynTree* st, QTextStream& out, int level );
void emitLiteral(const CodeModel::Unit* ds,const SynTree* st, QTextStream& out, int level );
bool emitDesig(const CodeModel::Unit*,const SynTree* st, bool procCall, QTextStream&, int level);
void emitTypeDecl(const CodeModel::Unit*,const CodeModel::Type* , QTextStream&, int level);
void emitVarDecl(const CodeModel::Unit*, const CodeModel::Element* st, QTextStream&, int level);
void emitStubProcDecl(const CodeModel::Unit*, const CodeModel::Element* st, QTextStream&, int level);
void emitRecDecl(const CodeModel::Unit*,const CodeModel::Type*, const QByteArray& name, QTextStream&, int level);
void emitProcDecl( const CodeModel::Procedure*, QTextStream&, int level);
void emitProcParams(const CodeModel::Unit*, const QList<CodeModel::Element*>&, QTextStream&);
void emitProcBody(const CodeModel::Procedure*p, QTextStream&out);
void emitDecls(const CodeModel::Unit*, QTextStream&, int level);
void emitStatementSeq( const CodeModel::Unit*, const QList<SynTree*>& seq, QTextStream&, int level );
bool emitPredefProc( const CodeModel::Unit*, const CodeModel::DesigOpList&, QTextStream&, int level );
void emitIfStatement(const CodeModel::Unit* ds, const SynTree*,QTextStream& out, int level);
void emitWhileStatement(const CodeModel::Unit* ds, const SynTree*,QTextStream& out, int level);
void emitRepeatStatement(const CodeModel::Unit* ds, const SynTree*,QTextStream& out, int level);
void emitForStatement(const CodeModel::Unit* ds, const SynTree*,QTextStream& out, int level);
void emitCaseStatement(const CodeModel::Unit* ds, const SynTree*,QTextStream& out, int level);
void emitSet( const CodeModel::Unit*, const SynTree*,QTextStream& out, int level );
void emitScopedName( const CodeModel::Unit*, const CodeModel::NamedThing*, QTextStream& out );
void emitComment(const SynTree*, QTextStream& out, int level);
void emitLabel(const CodeModel::Unit*, const SynTree*,QTextStream& out, int level);
static bool isSimpleType( const CodeModel::Type* );
static QByteArray escape( const QByteArray& );
bool error(Errors::Source s, const SynTree*, const QString& msg);
bool warning(Errors::Source s, const SynTree*, const QString& msg);
private:
CodeModel* d_mdl;
Errors* d_errs;
QString d_ns, d_outdir, d_mod;
QList<Token> d_cmts;
quint16 d_nextCmt;
quint16 d_nameNr;
bool d_genStubs;
};
}
#endif // OBCPPGEN_H