-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgenjs.h
More file actions
321 lines (281 loc) · 7.26 KB
/
genjs.h
File metadata and controls
321 lines (281 loc) · 7.26 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
* =====================================================================================
*
* Filename: genjs.h
*
* Description: Declarations of classes and functions for proxy generator
* for JavaScript
*
* Version: 1.0
* Created: 02/28/2024 02:49:52 PM
* Revision: none
* Compiler: gcc
*
* Author: Ming Zhi( woodhead99@gmail.com )
* Organization:
*
* Copyright: 2024 Ming Zhi( woodhead99@gmail.com )
*
* License: Licensed under GPL-3.0. You may not use this file except in
* compliance with the License. You may find a copy of the
* License at 'http://www.gnu.org/licenses/gpl-3.0.html'
*
* =====================================================================================
*/
#pragma once
#include <sys/stat.h>
#include "rpc.h"
using namespace rpcf;
#include "astnode.h"
#include "gencpp.h"
#include "sha1.h"
gint32 GenJsProj(
const std::string& strOutPath,
const std::string& strAppName,
ObjPtr pRoot );
struct CJsFileSet : public IFileSet
{
std::string m_strStructsJs;
std::string m_strMainCli;
std::string m_strObjDesc;
std::string m_strDriver;
std::string m_strMakefile;
std::string m_strReadme;
std::string m_strWebCfg;
std::string m_strHtml;
typedef IFileSet super;
CJsFileSet( const std::string& strOutPath,
const std::string& strAppName );
gint32 OpenFiles() override;
gint32 AddSvcImpl(
const stdstr& strSvcName ) override;
~CJsFileSet();
};
class CJsWriter : public CWriterBase
{
public:
ObjPtr m_pNode;
typedef CWriterBase super;
CJsWriter(
const std::string& strPath,
const std::string& strAppName,
ObjPtr pStmts ) :
super( strPath, strAppName )
{
std::unique_ptr< CJsFileSet > ptr(
new CJsFileSet( strPath, strAppName ) );
m_pFiles = std::move( ptr );
m_pNode = pStmts;
}
CJsWriter(
const std::string& strPath,
const std::string& strAppName ) :
super( strPath, strAppName )
{}
gint32 SelectStructsFile()
{
CJsFileSet* pFiles = static_cast< CJsFileSet* >
( m_pFiles.get() );
m_strCurFile = pFiles->m_strStructsJs;
return SelectImplFile( m_strCurFile );
}
gint32 SelectMainFuncFile()
{
CJsFileSet* pFiles = static_cast< CJsFileSet* >
( m_pFiles.get() );
m_strCurFile = pFiles->m_strMainCli;
return SelectImplFile( m_strCurFile );
}
gint32 SelectDescFile()
{
CJsFileSet* pFiles = static_cast< CJsFileSet* >
( m_pFiles.get() );
m_strCurFile = pFiles->m_strObjDesc;
return SelectImplFile( m_strCurFile );
}
gint32 SelectDrvFile()
{
CJsFileSet* pFiles = static_cast< CJsFileSet* >
( m_pFiles.get() );
m_strCurFile = pFiles->m_strDriver;
return SelectImplFile( m_strCurFile );
}
gint32 SelectMakefile()
{
CJsFileSet* pFiles = static_cast< CJsFileSet* >
( m_pFiles.get() );
m_strCurFile = pFiles->m_strMakefile;
return SelectImplFile( m_strCurFile );
}
gint32 SelectReadme()
{
CJsFileSet* pFiles = static_cast< CJsFileSet* >
( m_pFiles.get() );
m_strCurFile = pFiles->m_strReadme;
return SelectImplFile( m_strCurFile );
}
gint32 SelectWebCfg()
{
CJsFileSet* pFiles = static_cast< CJsFileSet* >
( m_pFiles.get() );
m_strCurFile = pFiles->m_strWebCfg;
return SelectImplFile( m_strCurFile );
}
gint32 SelectSampleHtml()
{
CJsFileSet* pFiles = static_cast< CJsFileSet* >
( m_pFiles.get() );
m_strCurFile = pFiles->m_strHtml;
return SelectImplFile( m_strCurFile );
}
};
class CDeclareJsStruct
{
protected:
CJsWriter* m_pWriter = nullptr;
CStructDecl* m_pNode = nullptr;
public:
CDeclareJsStruct( CJsWriter* pWriter,
ObjPtr& pNode );
virtual gint32 Output();
void OutputStructBase();
gint32 OutputRestore();
};
class CExportIndexJs
{
CStatements* m_pNode = nullptr;
CJsWriter* m_pWriter = nullptr;
public:
CExportIndexJs(
CJsWriter* pWriter, ObjPtr& pNode );
gint32 Output();
};
class CJsExportMakefile
{
CStatements* m_pNode = nullptr;
CWriterBase* m_pWriter = nullptr;
public:
CJsExportMakefile(
CJsWriter* pWriter, ObjPtr& pNode );
gint32 Output();
};
class CImplJsMthdProxyBase :
public CMethodWriter
{
CMethodDecl* m_pNode = nullptr;
CInterfaceDecl* m_pIf = nullptr;
public:
typedef CMethodWriter super;
CImplJsMthdProxyBase(
CJsWriter* pWriter, ObjPtr& pNode );
gint32 Output();
gint32 OutputSync();
gint32 OutputAsyncCbWrapper();
gint32 OutputEvent();
};
class CImplJsIfProxyBase
{
CInterfaceDecl* m_pNode = nullptr;
CJsWriter* m_pWriter = nullptr;
public:
CImplJsIfProxyBase(
CJsWriter* pWriter, ObjPtr& pNode );
gint32 Output();
};
class CImplJsSvcProxyBase
{
CServiceDecl* m_pNode = nullptr;
CJsWriter* m_pWriter = nullptr;
public:
CImplJsSvcProxyBase(
CJsWriter* pWriter, ObjPtr& pNode );
gint32 Output();
gint32 EmitSvcBaseCli();
gint32 EmitBuildEventTable();
};
class CImplJsMthdProxy :
public CMethodWriter
{
CMethodDecl* m_pNode = nullptr;
CInterfaceDecl* m_pIf = nullptr;
public:
typedef CMethodWriter super;
CImplJsMthdProxy(
CJsWriter* pWriter, ObjPtr& pNode );
gint32 Output();
gint32 OutputAsyncCallback();
gint32 OutputEvent();
};
class CImplJsIfProxy
{
CInterfaceDecl* m_pNode = nullptr;
CJsWriter* m_pWriter = nullptr;
public:
CImplJsIfProxy(
CJsWriter* pWriter, ObjPtr& pNode );
gint32 Output();
};
class CImplJsSvcProxy
{
CServiceDecl* m_pNode = nullptr;
CJsWriter* m_pWriter = nullptr;
public:
CImplJsSvcProxy(
CJsWriter* pWriter, ObjPtr& pNode );
gint32 Output();
gint32 OutputSvcProxyClass();
};
class CImplJsMainFunc :
public CArgListUtils
{
CJsWriter* m_pWriter = nullptr;
CStatements* m_pNode = nullptr;
public:
typedef CMethodWriter super;
CImplJsMainFunc(
CJsWriter* pWriter, ObjPtr& pNode );
gint32 Output();
gint32 OutputCli(
std::vector< ObjPtr >& vecSvcs );
gint32 EmitProxySampleCode( ObjPtr& pSvc );
};
class CExportJsReadme :
public CExportReadme
{
public:
typedef CExportReadme super;
CExportJsReadme( CWriterBase* pWriter,
ObjPtr& pNode )
: super( pWriter, pNode )
{}
gint32 Output();
gint32 Output_en();
gint32 Output_cn();
};
class CExportJsWebpack
{
CWriterBase* m_pWriter = nullptr;
CStatements* m_pNode = nullptr;
public:
CExportJsWebpack( CWriterBase* pWriter,
ObjPtr& pNode )
{
m_pWriter = pWriter;
m_pNode = pNode;
}
gint32 Output();
};
class CExportJsSampleHtml
{
public:
CWriterBase* m_pWriter = nullptr;
CStatements* m_pNode = nullptr;
public:
CExportJsSampleHtml( CWriterBase* pWriter,
ObjPtr& pNode )
{
m_pWriter = pWriter;
m_pNode = pNode;
}
gint32 Output();
};