Skip to content

Commit bd00059

Browse files
committed
Dealing with growing number of local variables in commsdsl2wireshark.
1 parent 69d37f2 commit bd00059

27 files changed

Lines changed: 75 additions & 44 deletions

app/commsdsl2wireshark/src/Wireshark.cpp

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ const std::string& Wireshark::wiresharkProtocolObjName(const WiresharkGenerator&
5151

5252
std::string Wireshark::wiresharkCreateFieldFuncName(const WiresharkGenerator& generator)
5353
{
54-
return wiresharkProtocolObjName(generator) + "_createField";
54+
return wiresharkLocalNamespaceName(generator) + ".createField";
5555
}
5656

5757
std::string Wireshark::wiresharkCreateExtractorFuncName(const WiresharkGenerator& generator)
5858
{
59-
return wiresharkProtocolObjName(generator) + "_createExtractor";
59+
return wiresharkLocalNamespaceName(generator) + ".createExtractor";
6060
}
6161

6262
std::string Wireshark::wiresharkFieldsListName(const WiresharkGenerator& generator)
6363
{
64-
return wiresharkProtocolObjName(generator) + "_fields_list";
64+
return wiresharkLocalNamespaceName(generator) + ".fields_list";
6565
}
6666

6767
std::string Wireshark::wiresharkExtractorsMapName(const WiresharkGenerator& generator)
6868
{
69-
return wiresharkProtocolObjName(generator) + "_extractors_map";
69+
return wiresharkLocalNamespaceName(generator) + ".extractors_map";
7070
}
7171

7272
std::string Wireshark::wiresharkStatusCodeStr(const WiresharkGenerator& generator, WiresharkStatusCode code)
@@ -89,7 +89,12 @@ std::string Wireshark::wiresharkOptModeValsName(const WiresharkGenerator& genera
8989

9090
std::string Wireshark::wiresharkFieldValueFuncName(const WiresharkGenerator& generator)
9191
{
92-
return wiresharkProtocolObjName(generator) + "_field_value";
92+
return wiresharkLocalNamespaceName(generator) + ".field_value";
93+
}
94+
95+
std::string Wireshark::wiresharkLocalNamespaceName(const WiresharkGenerator& generator)
96+
{
97+
return wiresharkProtocolObjName(generator) + "_local";
9398
}
9499

95100
bool Wireshark::wiresharkWriteInternal() const
@@ -108,6 +113,7 @@ bool Wireshark::wiresharkWriteInternal() const
108113
const std::string Templ =
109114
"#^#GEN_COMMENT#$#\n"
110115
"#^#PROTOCOL#$#\n"
116+
"#^#LOCAL#$#\n"
111117
"#^#STATUS_CODE#$#\n"
112118
"#^#OPT_MODE#$#\n"
113119
"#^#FIELDS_REG#$#\n"
@@ -124,6 +130,7 @@ bool Wireshark::wiresharkWriteInternal() const
124130
util::GenReplacementMap repl = {
125131
{"GEN_COMMENT", m_wiresharkGenerator.wiresharkFileGeneratedComment()},
126132
{"PROTOCOL", wiresharkProtocolDefInternal()},
133+
{"LOCAL", wiresharkLocalInternal()},
127134
{"FIELDS_REG", wiresharkFieldsRegistrationInternal()},
128135
{"DISSECT_FUNC", wiresharkDissectFuncInternal()},
129136
{"NAME", wiresharkProtocolObjName(m_wiresharkGenerator)},
@@ -164,6 +171,19 @@ std::string Wireshark::wiresharkProtocolDefInternal() const
164171
return util::genProcessTemplate(Templ, repl);
165172
}
166173

174+
std::string Wireshark::wiresharkLocalInternal() const
175+
{
176+
const std::string Templ =
177+
"local #^#NAME#$# = {}\n"
178+
;
179+
180+
util::GenReplacementMap repl = {
181+
{"NAME", wiresharkLocalNamespaceName(m_wiresharkGenerator)},
182+
};
183+
184+
return util::genProcessTemplate(Templ, repl);
185+
}
186+
167187
std::string Wireshark::wiresharkDissectFuncInternal() const
168188
{
169189
const std::string Templ =
@@ -194,10 +214,10 @@ std::string Wireshark::wiresharkFieldsRegistrationInternal() const
194214
{
195215
const std::string Templ =
196216
"-- Field Management\n"
197-
"local #^#LIST#$# = {}\n"
217+
"#^#LIST#$# = {}\n"
198218
"\n"
199219
"-- Invoke this function every time the field is created\n"
200-
"local function #^#NAME#$#(obj)\n"
220+
"function #^#NAME#$#(obj)\n"
201221
" table.insert(#^#LIST#$#, obj)\n"
202222
" return obj\n"
203223
"end\n"
@@ -284,7 +304,7 @@ std::string Wireshark::wiresharkDissectFuncBodyInternal() const
284304

285305
std::string Wireshark::wiresharkStatusCodeNameInternal() const
286306
{
287-
return wiresharkProtocolObjName(m_wiresharkGenerator) + "_StatusCode";
307+
return wiresharkLocalNamespaceName(m_wiresharkGenerator) + ".StatusCode";
288308
}
289309

290310
std::string Wireshark::wiresharkStatusCodeDefInternal() const
@@ -296,7 +316,7 @@ std::string Wireshark::wiresharkStatusCodeDefInternal() const
296316
}
297317

298318
const std::string Templ =
299-
"local #^#NAME#$# = {\n"
319+
"#^#NAME#$# = {\n"
300320
" #^#VALS#$#\n"
301321
"}\n"
302322
;
@@ -311,7 +331,7 @@ std::string Wireshark::wiresharkStatusCodeDefInternal() const
311331

312332
std::string Wireshark::wiresharkOptModeNameInternal() const
313333
{
314-
return wiresharkProtocolObjName(m_wiresharkGenerator) + "_OptMode";
334+
return wiresharkLocalNamespaceName(m_wiresharkGenerator) + ".OptMode";
315335
}
316336

317337
std::string Wireshark::wiresharkOptionalModeDefInternal() const
@@ -340,11 +360,11 @@ std::string Wireshark::wiresharkOptionalModeDefInternal() const
340360
}
341361

342362
const std::string Templ =
343-
"local #^#NAME#$# = {\n"
363+
"#^#NAME#$# = {\n"
344364
" #^#VALS#$#\n"
345365
"}\n"
346366
"\n"
347-
"local #^#VALS_NAME#$# = {\n"
367+
"#^#VALS_NAME#$# = {\n"
348368
" #^#VAL_NAMES#$#\n"
349369
"}\n"
350370
;
@@ -363,10 +383,10 @@ std::string Wireshark::wiresharkExtractorsDeclInternal() const
363383
{
364384
const std::string Templ =
365385
"-- Extractors Management\n"
366-
"local #^#MAP#$# = {}\n"
386+
"#^#MAP#$# = {}\n"
367387
"\n"
368388
"-- Invoke this function every time the extractor needs to be created\n"
369-
"local function #^#NAME#$#(name, field)\n"
389+
"function #^#NAME#$#(name, field)\n"
370390
" #^#MAP#$#[field] = Field.new(name)\n"
371391
"end\n"
372392
;
@@ -397,7 +417,7 @@ std::string Wireshark::wiresharkExtractorsRegCodeInternal() const
397417
std::string Wireshark::wiresharkFieldValueFuncInternal() const
398418
{
399419
const std::string Templ =
400-
"local function #^#NAME#$#(field)\n"
420+
"function #^#NAME#$#(field)\n"
401421
" local extractor = #^#MAP#$#[field]\n"
402422
" local info = {extractor()}\n"
403423
" local last = info[#info]\n"

app/commsdsl2wireshark/src/Wireshark.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ class Wireshark
5252
static std::string wiresharkOptModeStr(const WiresharkGenerator& generator, WiresharkOptMode code);
5353
static std::string wiresharkOptModeValsName(const WiresharkGenerator& generator);
5454
static std::string wiresharkFieldValueFuncName(const WiresharkGenerator& generator);
55+
static std::string wiresharkLocalNamespaceName(const WiresharkGenerator& generator);
5556

5657
private:
5758
explicit Wireshark(const WiresharkGenerator& generator) : m_wiresharkGenerator(generator) {}
5859

5960
private:
6061
bool wiresharkWriteInternal() const;
6162
std::string wiresharkProtocolDefInternal() const;
63+
std::string wiresharkLocalInternal() const;
6264
std::string wiresharkDissectFuncInternal() const;
6365
std::string wiresharkFieldsRegistrationInternal() const;
6466
std::string wiresharkCodeInternal() const;

app/commsdsl2wireshark/src/WiresharkBitfieldField.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ bool WiresharkBitfieldField::genPrepareImpl()
135135
std::string WiresharkBitfieldField::wiresharkFieldRegistrationImpl(const WiresharkField* refField) const
136136
{
137137
static const std::string Templ =
138-
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, base.HEX, #^#NIL#$#, #^#MASK#$#, #^#DESC#$#))\n"
138+
"#^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, base.HEX, #^#NIL#$#, #^#MASK#$#, #^#DESC#$#))\n"
139139
;
140140

141141
auto obj = genParseObj();

app/commsdsl2wireshark/src/WiresharkEnumField.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ std::string WiresharkEnumField::wiresharkFieldRegistrationImpl(const WiresharkFi
4040
{
4141
static const std::string Templ =
4242
"#^#VALS#$#\n"
43-
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, #^#BASE#$#, #^#VALS_NAME#$#, #^#MASK#$#, #^#DESC#$#))\n"
43+
"#^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, #^#BASE#$#, #^#VALS_NAME#$#, #^#MASK#$#, #^#DESC#$#))\n"
4444
;
4545

4646
auto obj = genEnumFieldParseObj();
@@ -240,7 +240,7 @@ std::string WiresharkEnumField::wiresharkValsInternal(const WiresharkField* refF
240240
}
241241

242242
static const std::string Templ =
243-
"local #^#NAME#$##^#SUFFIX#$# = {\n"
243+
"#^#NAME#$##^#SUFFIX#$# = {\n"
244244
" #^#ELEMS#$#\n"
245245
"}\n"
246246
;

app/commsdsl2wireshark/src/WiresharkField.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ std::string WiresharkField::wiresharkDissectCodeImpl(const WiresharkField* refFi
685685
"#^#VALUE_FUNC#$#\n"
686686
"#^#VALID_FUNC#$#\n"
687687
"#^#PREPEND#$#\n"
688-
"local function #^#NAME#$##^#SUFFIX#$#(#^#SIG#$#)\n"
688+
"function #^#NAME#$##^#SUFFIX#$#(#^#SIG#$#)\n"
689689
" #^#REPLACE#$#\n"
690690
" #^#BODY#$#\n"
691691
"end\n"
@@ -788,13 +788,13 @@ std::string WiresharkField::wiresharkFieldObjNameImpl(const WiresharkField* refF
788788
}
789789
auto& wiresharkGenerator = WiresharkGenerator::wiresharkCast(genField->genGenerator());
790790
auto scope = comms::genScopeFor(*genField, wiresharkGenerator, false);
791-
return Wireshark::wiresharkProtocolObjName(wiresharkGenerator) + '_' + util::genStrReplace(scope, "::", "_");
791+
return Wireshark::wiresharkLocalNamespaceName(wiresharkGenerator) + '.' + util::genStrReplace(scope, "::", "_");
792792
}
793793

794794
std::string WiresharkField::wiresharkFieldRegistrationImpl(const WiresharkField* refField) const
795795
{
796796
static const std::string Templ =
797-
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.bytes(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, base.SPACE, #^#DESC#$#))\n"
797+
"#^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.bytes(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, base.SPACE, #^#DESC#$#))\n"
798798
;
799799

800800
util::GenReplacementMap repl = {
@@ -1266,7 +1266,7 @@ std::string WiresharkField::wiresharkNameDefInternal(const WiresharkField* refFi
12661266
{
12671267
static const std::string Templ =
12681268
"#^#COMMENT#$#"
1269-
"local #^#VAR_NAME#$# = \"#^#NAME#$#\"\n"
1269+
"#^#VAR_NAME#$# = \"#^#NAME#$#\"\n"
12701270
;
12711271

12721272
util::GenReplacementMap repl = {
@@ -1361,7 +1361,7 @@ std::string WiresharkField::wiresharkValidFuncCodeInternal(const WiresharkField*
13611361
}
13621362

13631363
static const std::string Templ =
1364-
"local function #^#NAME#$##^#SUFFIX#$#(#^#FIELD#$#)\n"
1364+
"function #^#NAME#$##^#SUFFIX#$#(#^#FIELD#$#)\n"
13651365
" #^#REPLACE#$#\n"
13661366
" #^#BODY#$#\n"
13671367
"end\n"
@@ -1396,7 +1396,7 @@ std::string WiresharkField::wiresharkValidFuncCodeInternal(const WiresharkField*
13961396
std::string WiresharkField::wiresharkValueFuncCodeInternal(const WiresharkField* refField) const
13971397
{
13981398
static const std::string Templ =
1399-
"local function #^#NAME#$##^#SUFFIX#$#(#^#FIELD#$#)\n"
1399+
"function #^#NAME#$##^#SUFFIX#$#(#^#FIELD#$#)\n"
14001400
" #^#REPLACE#$#\n"
14011401
" #^#BODY#$#\n"
14021402
"end\n"

app/commsdsl2wireshark/src/WiresharkFloatField.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool WiresharkFloatField::genPrepareImpl()
5050
std::string WiresharkFloatField::wiresharkFieldRegistrationImpl(const WiresharkField* refField) const
5151
{
5252
static const std::string Templ =
53-
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, #^#UNIT_NAME#$#, #^#DESC#$#))\n"
53+
"#^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, #^#UNIT_NAME#$#, #^#DESC#$#))\n"
5454
;
5555

5656
util::GenReplacementMap repl = {

app/commsdsl2wireshark/src/WiresharkFrame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ std::string WiresharkFrame::wiresharkDissectCode() const
5151
"#^#LAYERS#$#\n"
5252
"#^#FUNC_LIST#$#\n"
5353
"#^#PREPEND#$#\n"
54-
"local function #^#NAME#$##^#SUFFIX#$#(tvb, tree)\n"
54+
"function #^#NAME#$##^#SUFFIX#$#(tvb, tree)\n"
5555
" #^#REPLACE#$#\n"
5656
" #^#BODY#$#\n"
5757
"end\n"
@@ -221,7 +221,7 @@ const WiresharkInterface* WiresharkFrame::wiresharkInterfaceInternal() const
221221
std::string WiresharkFrame::wiresharkLayerFuncsListInternal() const
222222
{
223223
static const std::string Templ =
224-
"local #^#NAME#$# = {\n"
224+
"#^#NAME#$# = {\n"
225225
" #^#LAYERS#$#\n"
226226
"}\n"
227227
;

app/commsdsl2wireshark/src/WiresharkGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ std::string WiresharkGenerator::wiresharkScopeToName(const std::string& scope) c
199199
std::string WiresharkGenerator::wiresharkFuncNameFor(const GenElem& elem, const std::string& suffix) const
200200
{
201201
auto scope = comms::genScopeFor(elem, *this, false);
202-
auto protName = Wireshark::wiresharkProtocolObjName(*this);
203-
return protName + '_' + wiresharkScopeToName(scope) + suffix;
202+
auto protName = Wireshark::wiresharkLocalNamespaceName(*this);
203+
return protName + '.' + wiresharkScopeToName(scope) + suffix;
204204
}
205205

206206
std::string WiresharkGenerator::wiresharkDissectNameFor(const GenElem& elem) const

app/commsdsl2wireshark/src/WiresharkIdLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ std::string WiresharkIdLayer::wiresharkExtraDissectCodeImpl() const
9393
}
9494

9595
static const std::string Templ =
96-
"local #^#NAME#$# = {\n"
96+
"#^#NAME#$# = {\n"
9797
" #^#ELEMS#$#\n"
9898
"}\n"
9999
;

app/commsdsl2wireshark/src/WiresharkIntField.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ std::string WiresharkIntField::wiresharkFieldRegistrationImpl(const WiresharkFie
129129
{
130130
static const std::string Templ =
131131
"#^#SPECIALS#$#\n"
132-
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, #^#BASE#$#, #^#SPECIALS_NAME#$#, #^#MASK#$#, #^#DESC#$#))\n"
132+
"#^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, #^#BASE#$#, #^#SPECIALS_NAME#$#, #^#MASK#$#, #^#DESC#$#))\n"
133133
;
134134

135135
auto obj = genIntFieldParseObj();
@@ -399,7 +399,7 @@ std::string WiresharkIntField::wiresharkSpecialsInternal(const WiresharkField* r
399399
}
400400

401401
static const std::string Templ =
402-
"local #^#NAME#$##^#SUFFIX#$# = {\n"
402+
"#^#NAME#$##^#SUFFIX#$# = {\n"
403403
" #^#ELEMS#$#\n"
404404
"}\n"
405405
;

0 commit comments

Comments
 (0)