Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8848a3

Browse files
committed
Removed unuseful things.
1 parent c05ee54 commit f8848a3

File tree

4 files changed

+75
-83
lines changed

4 files changed

+75
-83
lines changed

src/codegen/c-main-generator.cpp

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ CiMainGenerator::CiMainGenerator()
3838

3939
void CiMainGenerator::Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd)
4040
{
41-
p_dlist = &dlist;
4241
// Load income messages to sig printer
4342
sigprt->LoadMessages(dlist.msgs);
4443

@@ -91,8 +90,8 @@ void CiMainGenerator::Gen_MainHeader()
9190
fwriter->Append();
9291

9392
fwriter->Append("// DBC file version");
94-
fwriter->Append("#define %s (%uU)", fdesc->gen.verhigh_def.c_str(), p_dlist->ver.hi);
95-
fwriter->Append("#define %s (%uU)", fdesc->gen.verlow_def.c_str(), p_dlist->ver.low);
93+
fwriter->Append("#define %s (%uU)", fdesc->gen.verhigh_def.c_str(), fdesc->gen.hiver);
94+
fwriter->Append("#define %s (%uU)", fdesc->gen.verlow_def.c_str(), fdesc->gen.lowver);
9695
fwriter->Append();
9796

9897
fwriter->Append("// include current dbc-driver compilation config");
@@ -290,7 +289,7 @@ void CiMainGenerator::Gen_MainSource()
290289

291290
fwriter->Append("// DBC file version");
292291
fwriter->Append("#if (%s != (%uU)) || (%s != (%uU))",
293-
fdesc->gen.verhigh_def.c_str(), p_dlist->ver.hi, fdesc->gen.verlow_def.c_str(), p_dlist->ver.low);
292+
fdesc->gen.verhigh_def.c_str(), fdesc->gen.hiver, fdesc->gen.verlow_def.c_str(), fdesc->gen.lowver);
294293

295294
fwriter->Append("#error The %s dbc source files have different versions", fdesc->gen.DRVNAME.c_str());
296295
fwriter->Append("#endif");
@@ -376,76 +375,15 @@ void CiMainGenerator::Gen_ConfigHeader()
376375

377376
void CiMainGenerator::Gen_FMonHeader()
378377
{
379-
if (fdesc->gen.start_info.size() > 0)
380-
{
381-
// replace all '\n' on "\n //" for c code comment text
382-
fwriter->Append("// " + std::regex_replace(fdesc->gen.start_info, std::regex("\n"), "\n// "));
383-
}
384-
385-
fwriter->Append("#pragma once");
386-
fwriter->Append();
387-
388-
fwriter->Append("#ifdef __cplusplus\nextern \"C\" {\n#endif");
389-
fwriter->Append();
390-
391-
fwriter->Append("// DBC file version");
392-
fwriter->Append("#define %s_FMON (%uU)", fdesc->gen.verhigh_def.c_str(), p_dlist->ver.hi);
393-
fwriter->Append("#define %s_FMON (%uU)", fdesc->gen.verlow_def.c_str(), p_dlist->ver.low);
394-
fwriter->Append();
395-
396-
fwriter->Append("#include <%s-config.h>", fdesc->gen.drvname.c_str());
397-
fwriter->Append();
398-
399-
// put diagmonitor ifdef selection for including @drv-fmon header
400-
// with FMon_* signatures to call from unpack function
401-
fwriter->Append("#ifdef %s", fdesc->gen.usemon_def.c_str());
402-
fwriter->Append();
403-
fwriter->Append("#include <canmonitorutil.h>");
404-
fwriter->Append("/*\n\
405-
This file contains the prototypes of all the functions that will be called\n\
406-
from each Unpack_*name* function to detect DBC related errors\n\
407-
It is the user responsibility to defined these functions in the\n\
408-
separated .c file. If it won't be done the linkage error will happen\n*/");
409-
fwriter->Append();
410-
411378
MonGenerator mongen;
412-
413-
mongen.FillHeader((*fwriter), sigprt->sigs_expr, fdesc->gen);
414-
415-
fwriter->Append("#endif // %s", fdesc->gen.usemon_def.c_str());
416-
fwriter->Append();
417-
418-
fwriter->Append("#ifdef __cplusplus\n}\n#endif");
419-
379+
mongen.FillHeader((*fwriter), sigprt->sigs_expr, *fdesc);
420380
fwriter->Flush(fdesc->file.fmon_h.fpath);
421381
}
422382

423383
void CiMainGenerator::Gen_FMonSource()
424384
{
425-
if (fdesc->gen.start_info.size() > 0)
426-
{
427-
// replace all '\n' on "\n //" for c code comment text
428-
fwriter->Append("// " + std::regex_replace(fdesc->gen.start_info, std::regex("\n"), "\n// "));
429-
}
430-
431-
fwriter->Append("#include <%s>", fdesc->file.fmon_h.fname.c_str());
432-
fwriter->Append();
433-
// put diagmonitor ifdef selection for including @drv-fmon header
434-
// with FMon_* signatures to call from unpack function
435-
fwriter->Append("#ifdef %s", fdesc->gen.usemon_def.c_str());
436-
fwriter->Append();
437-
438-
fwriter->Append("/*\n\
439-
Put the monitor function content here, keep in mind -\n\
440-
next generation will completely clear all manually added code (!)\n\
441-
*/\n\n");
442-
443385
MonGenerator mongen;
444-
445-
mongen.FillSource((*fwriter), sigprt->sigs_expr, fdesc->gen);
446-
447-
fwriter->Append("#endif // %s", fdesc->gen.usemon_def.c_str());
448-
386+
mongen.FillSource((*fwriter), sigprt->sigs_expr, *fdesc);
449387
fwriter->Flush(fdesc->file.fmon_c.fpath);
450388
}
451389

src/codegen/c-main-generator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ class CiMainGenerator {
3535
std::unique_ptr<CSigPrinter> sigprt;
3636
std::unique_ptr<FileWriter> fwriter;
3737
const AppSettings_t* fdesc;
38-
const DbcMessageList_t* p_dlist;
3938
};

src/codegen/mon-generator.cpp

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,52 @@
22
#include "helpers/formatter.h"
33

44
uint32_t MonGenerator::FillHeader(FileWriter& wr, std::vector<CiExpr_t*>& sigs,
5-
const GenDescriptor_t& gsett)
5+
const AppSettings_t& aset)
66
{
7-
wr.Append("#ifdef %s_USE_MONO_FMON", gsett.DRVNAME.c_str());
7+
if (aset.gen.start_info.size() > 0)
8+
{
9+
wr.Append(aset.gen.start_info);
10+
}
11+
12+
wr.Append("#pragma once");
13+
wr.Append();
14+
15+
wr.Append("#ifdef __cplusplus\nextern \"C\" {\n#endif");
16+
wr.Append();
17+
18+
wr.Append("// DBC file version");
19+
wr.Append("#define %s_FMON (%uU)", aset.gen.verhigh_def.c_str(), aset.gen.hiver);
20+
wr.Append("#define %s_FMON (%uU)", aset.gen.verlow_def.c_str(), aset.gen.lowver);
821
wr.Append();
922

10-
wr.Append("void _FMon_MONO_%s(FrameMonitor_t* _mon, uint32_t msgid);", gsett.drvname.c_str());
23+
wr.Append("#include <%s-config.h>", aset.gen.drvname.c_str());
24+
wr.Append();
25+
26+
// put diagmonitor ifdef selection for including @drv-fmon header
27+
// with FMon_* signatures to call from unpack function
28+
wr.Append("#ifdef %s", aset.gen.usemon_def.c_str());
29+
wr.Append();
30+
wr.Append("#include <canmonitorutil.h>");
31+
wr.Append("/*\n\
32+
This file contains the prototypes of all the functions that will be called\n\
33+
from each Unpack_*name* function to detect DBC related errors\n\
34+
It is the user responsibility to defined these functions in the\n\
35+
separated .c file. If it won't be done the linkage error will happen\n*/");
36+
wr.Append();
37+
38+
wr.Append("#ifdef %s_USE_MONO_FMON", aset.gen.DRVNAME.c_str());
39+
wr.Append();
40+
41+
wr.Append("void _FMon_MONO_%s(FrameMonitor_t* _mon, uint32_t msgid);", aset.gen.drvname.c_str());
1142
wr.Append();
1243

1344
for (auto it = sigs.begin(); it != sigs.end(); ++it)
1445
{
1546

1647
auto msg = &((*it)->msg);
1748
wr.Append("#define FMon_%s_%s(x, y) _FMon_MONO_%s((x), (y))", msg->Name.c_str(),
18-
gsett.drvname.c_str(),
19-
gsett.drvname.c_str());
49+
aset.gen.drvname.c_str(),
50+
aset.gen.drvname.c_str());
2051
}
2152

2253
wr.Append();
@@ -27,7 +58,7 @@ uint32_t MonGenerator::FillHeader(FileWriter& wr, std::vector<CiExpr_t*>& sigs,
2758
{
2859
auto msg = &((*it)->msg);
2960
wr.Append("void _FMon_%s_%s(FrameMonitor_t* _mon, uint32_t msgid);",
30-
msg->Name.c_str(), gsett.drvname.c_str());
61+
msg->Name.c_str(), aset.gen.drvname.c_str());
3162
}
3263

3364
wr.Append();
@@ -36,23 +67,45 @@ uint32_t MonGenerator::FillHeader(FileWriter& wr, std::vector<CiExpr_t*>& sigs,
3667
{
3768
auto msg = &((*it)->msg);
3869
wr.Append("#define FMon_%s_%s(x, y) _FMon_%s_%s((x), (y))",
39-
msg->Name.c_str(), gsett.drvname.c_str(),
40-
msg->Name.c_str(), gsett.drvname.c_str());
70+
msg->Name.c_str(), aset.gen.drvname.c_str(),
71+
msg->Name.c_str(), aset.gen.drvname.c_str());
4172
}
4273

4374
wr.Append();
4475
wr.Append("#endif");
4576
wr.Append();
4677

78+
wr.Append("#endif // %s", aset.gen.usemon_def.c_str());
79+
wr.Append();
80+
81+
wr.Append("#ifdef __cplusplus\n}\n#endif");
82+
4783
return 0;
4884
}
4985

5086
uint32_t MonGenerator::FillSource(FileWriter& wr, std::vector<CiExpr_t*>& sigs,
51-
const GenDescriptor_t& gsett)
87+
const AppSettings_t& aset)
5288
{
53-
wr.Append("#ifdef %s_USE_MONO_FMON", gsett.DRVNAME.c_str());
89+
if (aset.gen.start_info.size() > 0)
90+
{
91+
wr.Append(aset.gen.start_info);
92+
}
93+
94+
wr.Append("#include <%s>", aset.file.fmon_h.fname.c_str());
95+
wr.Append();
96+
// put diagmonitor ifdef selection for including @drv-fmon header
97+
// with FMon_* signatures to call from unpack function
98+
wr.Append("#ifdef %s", aset.gen.usemon_def.c_str());
99+
wr.Append();
100+
101+
wr.Append("/*\n\
102+
Put the monitor function content here, keep in mind -\n\
103+
next generation will completely clear all manually added code (!)\n\
104+
*/\n\n");
105+
106+
wr.Append("#ifdef %s_USE_MONO_FMON", aset.gen.DRVNAME.c_str());
54107
wr.Append();
55-
wr.Append("void _FMon_MONO_%s(FrameMonitor_t* _mon, uint32_t msgid)", gsett.drvname.c_str());
108+
wr.Append("void _FMon_MONO_%s(FrameMonitor_t* _mon, uint32_t msgid)", aset.gen.drvname.c_str());
56109
wr.Append("{");
57110
wr.Append(" (void)_mon;");
58111
wr.Append(" (void)msgid;");
@@ -65,11 +118,13 @@ uint32_t MonGenerator::FillSource(FileWriter& wr, std::vector<CiExpr_t*>& sigs,
65118
{
66119
auto msg = &((*it)->msg);
67120
wr.Append("void _FMon_%s_%s(FrameMonitor_t* _mon, uint32_t msgid)\n{\n (void)_mon;\n (void)msgid;\n}\n\n",
68-
msg->Name.c_str(), gsett.drvname.c_str());
121+
msg->Name.c_str(), aset.gen.drvname.c_str());
69122
}
70123

71-
wr.Append("#endif // %s_USE_MONO_FMON", gsett.DRVNAME.c_str());
124+
wr.Append("#endif // %s_USE_MONO_FMON", aset.gen.DRVNAME.c_str());
72125
wr.Append();
73126

127+
wr.Append("#endif // %s", aset.gen.usemon_def.c_str());
128+
74129
return 0;
75130
}

src/codegen/mon-generator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class MonGenerator {
1010

1111
MonGenerator() = default;
1212

13-
uint32_t FillHeader(FileWriter& wr, std::vector<CiExpr_t*>& sigs, const GenDescriptor_t& gsett);
14-
uint32_t FillSource(FileWriter& wr, std::vector<CiExpr_t*>& sigs, const GenDescriptor_t& gsett);
13+
uint32_t FillHeader(FileWriter& wr, std::vector<CiExpr_t*>& sigs, const AppSettings_t& gsett);
14+
uint32_t FillSource(FileWriter& wr, std::vector<CiExpr_t*>& sigs, const AppSettings_t& gsett);
1515
};

0 commit comments

Comments
 (0)