Skip to content

Commit e23226f

Browse files
committed
Refining inftrastructure to allow field referencing.
1 parent fa0b73a commit e23226f

14 files changed

Lines changed: 192 additions & 169 deletions

app/commsdsl2wireshark/src/WiresharkBitfieldField.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,42 +119,33 @@ bool WiresharkBitfieldField::genPrepareImpl()
119119
return true;
120120
}
121121

122-
std::string WiresharkBitfieldField::wiresharkFieldRegistrationImpl(const std::string& objName, const std::string& refName) const
122+
std::string WiresharkBitfieldField::wiresharkFieldRegistrationImpl(const WiresharkField* refField) const
123123
{
124124
static const std::string Templ =
125125
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", \"#^#DISP_NAME#$#\", base.HEX, #^#NIL#$#, #^#MASK#$#, #^#DESC#$#))\n"
126126
;
127127

128-
auto mask = wiresharkForcedIntegralFieldMask();
129128
auto obj = genParseObj();
130129
util::GenReplacementMap repl = {
131-
{"OBJ_NAME", objName},
130+
{"OBJ_NAME", wiresharkFieldObjName(refField)},
132131
{"CREATE_FUNC", Wireshark::wiresharkCreateFieldFuncName(WiresharkGenerator::wiresharkCast(genGenerator()))},
133132
{"TYPE", wiresharkIntegralType()},
134-
{"REF_NAME", refName},
135-
{"DISP_NAME", util::genDisplayName(obj.parseDisplayName(), obj.parseName())},
133+
{"REF_NAME", wiresharkFieldRefName(refField)},
134+
{"DISP_NAME", wiresharkFieldDisplayNameStr(refField)},
136135
{"NIL", strings::genNilStr()},
137-
{"MASK", wiresharkForcedIntegralFieldMask()},
138-
{"DESC", wiresharkFieldDescriptionStr()},
136+
{"MASK", wiresharkForcedIntegralFieldMask(refField)},
137+
{"DESC", wiresharkFieldDescriptionStr(refField)},
139138
};
140139

141-
if (repl["OBJ_NAME"].empty()) {
142-
repl["OBJ_NAME"] = wiresharkFieldObjName();
143-
}
144-
145-
if (repl["REF_NAME"].empty()) {
146-
repl["REF_NAME"] = wiresharkFieldRefName();
147-
}
148-
149140
assert(!repl["TYPE"].empty());
150141
return util::genProcessTemplate(Templ, repl);
151142
}
152143

153-
std::string WiresharkBitfieldField::wiresharkMembersDissectCodeImpl() const
144+
std::string WiresharkBitfieldField::wiresharkMembersDissectCodeImpl(const WiresharkField* refField) const
154145
{
155146
util::GenStringsList elems;
156147
for (auto* f : m_wiresharkFields) {
157-
auto str = f->wiresharkDissectCode();
148+
auto str = f->wiresharkDissectCode(refField);
158149
if (str.empty()) {
159150
continue;
160151
}

app/commsdsl2wireshark/src/WiresharkBitfieldField.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class WiresharkBitfieldField final : public commsdsl::gen::GenBitfieldField, pub
4141
protected:
4242
virtual bool genPrepareImpl() override;
4343

44-
virtual std::string wiresharkFieldRegistrationImpl(const std::string& objName, const std::string& refName) const override;
45-
virtual std::string wiresharkMembersDissectCodeImpl() const override;
44+
virtual std::string wiresharkFieldRegistrationImpl(const WiresharkField* refField) const override;
45+
virtual std::string wiresharkMembersDissectCodeImpl(const WiresharkField* refField) const override;
4646

4747
private:
4848
WiresharkFieldsList m_wiresharkFields;

app/commsdsl2wireshark/src/WiresharkBundleField.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,29 @@ bool WiresharkBundleField::genPrepareImpl()
4343
return true;
4444
}
4545

46-
std::string WiresharkBundleField::wiresharkFieldRegistrationImpl(const std::string& objName, const std::string& refName) const
46+
std::string WiresharkBundleField::wiresharkFieldRegistrationImpl(const WiresharkField* refField) const
4747
{
4848
static const std::string Templ =
4949
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.bytes(\"#^#REF_NAME#$#\", \"#^#DISP_NAME#$#\", base.SPACE, #^#DESC#$#))\n"
5050
;
5151

52-
auto mask = wiresharkForcedIntegralFieldMask();
5352
auto obj = genParseObj();
5453
util::GenReplacementMap repl = {
55-
{"OBJ_NAME", objName},
54+
{"OBJ_NAME", wiresharkFieldObjName(refField)},
5655
{"CREATE_FUNC", Wireshark::wiresharkCreateFieldFuncName(WiresharkGenerator::wiresharkCast(genGenerator()))},
57-
{"REF_NAME", refName},
58-
{"DISP_NAME", util::genDisplayName(obj.parseDisplayName(), obj.parseName())},
59-
{"DESC", wiresharkFieldDescriptionStr()},
56+
{"REF_NAME", wiresharkFieldRefName(refField)},
57+
{"DISP_NAME", wiresharkFieldDisplayNameStr(refField)},
58+
{"DESC", wiresharkFieldDescriptionStr(refField)},
6059
};
6160

62-
if (repl["OBJ_NAME"].empty()) {
63-
repl["OBJ_NAME"] = wiresharkFieldObjName();
64-
}
65-
66-
if (repl["REF_NAME"].empty()) {
67-
repl["REF_NAME"] = wiresharkFieldRefName();
68-
}
69-
7061
return util::genProcessTemplate(Templ, repl);
7162
}
7263

73-
std::string WiresharkBundleField::wiresharkMembersDissectCodeImpl() const
64+
std::string WiresharkBundleField::wiresharkMembersDissectCodeImpl(const WiresharkField* refField) const
7465
{
7566
util::GenStringsList elems;
7667
for (auto* f : m_wiresharkFields) {
77-
auto str = f->wiresharkDissectCode();
68+
auto str = f->wiresharkDissectCode(refField);
7869
if (str.empty()) {
7970
continue;
8071
}

app/commsdsl2wireshark/src/WiresharkBundleField.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class WiresharkBundleField final : public commsdsl::gen::GenBundleField, public
3737
protected:
3838
virtual bool genPrepareImpl() override;
3939

40-
virtual std::string wiresharkFieldRegistrationImpl(const std::string& objName, const std::string& refName) const override;
41-
virtual std::string wiresharkMembersDissectCodeImpl() const override;
40+
virtual std::string wiresharkFieldRegistrationImpl(const WiresharkField* refField) const override;
41+
virtual std::string wiresharkMembersDissectCodeImpl(const WiresharkField* refField) const override;
4242

4343
private:
4444
WiresharkFieldsList m_wiresharkFields;

app/commsdsl2wireshark/src/WiresharkEnumField.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ WiresharkEnumField::WiresharkEnumField(WiresharkGenerator& generator, ParseField
3636
{
3737
}
3838

39-
std::string WiresharkEnumField::wiresharkFieldRegistrationImpl(const std::string& objName, const std::string& refName) const
39+
std::string WiresharkEnumField::wiresharkFieldRegistrationImpl(const WiresharkField* refField) const
4040
{
4141
static const std::string Templ =
4242
"#^#VALS#$#\n"
@@ -45,26 +45,18 @@ std::string WiresharkEnumField::wiresharkFieldRegistrationImpl(const std::string
4545

4646
auto obj = genEnumFieldParseObj();
4747
util::GenReplacementMap repl = {
48-
{"VALS", wiresharkValsInternal()},
49-
{"OBJ_NAME", objName},
48+
{"VALS", wiresharkValsInternal(refField)},
49+
{"OBJ_NAME", wiresharkFieldObjName(refField)},
5050
{"CREATE_FUNC", Wireshark::wiresharkCreateFieldFuncName(WiresharkGenerator::wiresharkCast(genGenerator()))},
51-
{"TYPE", wiresharkForcedIntegralFieldType()},
52-
{"REF_NAME", refName},
53-
{"DISP_NAME", util::genDisplayName(obj.parseDisplayName(), obj.parseName())},
54-
{"VALS_NAME", wiresharkFieldObjName() + strings::genValsSuffixStr()},
51+
{"TYPE", wiresharkForcedIntegralFieldType(refField)},
52+
{"REF_NAME", wiresharkFieldRefName(refField)},
53+
{"DISP_NAME", wiresharkFieldDisplayNameStr(refField)},
54+
{"VALS_NAME", wiresharkFieldObjName(refField) + strings::genValsSuffixStr()},
5555
{"BASE", "base.DEC_HEX"},
56-
{"MASK", wiresharkForcedIntegralFieldMask()},
57-
{"DESC", wiresharkFieldDescriptionStr()},
56+
{"MASK", wiresharkForcedIntegralFieldMask(refField)},
57+
{"DESC", wiresharkFieldDescriptionStr(refField)},
5858
};
5959

60-
if (repl["OBJ_NAME"].empty()) {
61-
repl["OBJ_NAME"] = wiresharkFieldObjName();
62-
}
63-
64-
if (repl["REF_NAME"].empty()) {
65-
repl["REF_NAME"] = wiresharkFieldRefName();
66-
}
67-
6860
if (obj.parseHexAssign()) {
6961
repl["BASE"] = "base.HEX_DEC";
7062
}
@@ -80,7 +72,7 @@ std::string WiresharkEnumField::wiresharkFieldRegistrationImpl(const std::string
8072
return util::genProcessTemplate(Templ, repl);
8173
}
8274

83-
std::string WiresharkEnumField::wiresharkValsInternal() const
75+
std::string WiresharkEnumField::wiresharkValsInternal(const WiresharkField* refField) const
8476
{
8577
auto& values = genSortedRevValues();
8678
assert(!values.empty());
@@ -118,7 +110,7 @@ std::string WiresharkEnumField::wiresharkValsInternal() const
118110
;
119111

120112
util::GenReplacementMap repl = {
121-
{"NAME", wiresharkFieldObjName()},
113+
{"NAME", wiresharkFieldObjName(refField)},
122114
{"SUFFIX", strings::genValsSuffixStr()},
123115
{"ELEMS", util::genStrListToString(elems, ",\n", "")},
124116
};

app/commsdsl2wireshark/src/WiresharkEnumField.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ class WiresharkEnumField final : public commsdsl::gen::GenEnumField, public Wire
3535
WiresharkEnumField(WiresharkGenerator& generator, ParseField parseObj, GenElem* parent);
3636

3737
protected:
38-
std::string wiresharkFieldRegistrationImpl(const std::string& objName, const std::string& refName) const override;
38+
std::string wiresharkFieldRegistrationImpl(const WiresharkField* refField) const override;
3939

4040
private:
41-
std::string wiresharkValsInternal() const;
41+
std::string wiresharkValsInternal(const WiresharkField* refField) const;
4242
};
4343

4444
} // namespace commsdsl2wireshark

0 commit comments

Comments
 (0)