Skip to content

Commit 1c68485

Browse files
committed
Saving work on commsdsl2wireshark.
1 parent e23226f commit 1c68485

37 files changed

Lines changed: 389 additions & 60 deletions

app/commsdsl2comms/src/CommsField.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ bool CommsField::commsPrepare()
9292
auto& obj = m_genField.genParseObj();
9393

9494
bool overrides =
95-
commsPrepareOverrideInternal(obj.parseValueOverride(), "value", &CommsField::commsCustomValueCodeInternal, m_customCode.m_value, &m_customCode.m_hasValue) &&
96-
commsPrepareOverrideInternal(obj.parseReadOverride(), "read", &CommsField::commsCustomReadCodeInternal, m_customCode.m_read, &m_customCode.m_hasRead) &&
97-
commsPrepareOverrideInternal(obj.parseWriteOverride(), "write", &CommsField::commsCustomWriteCodeInternal, m_customCode.m_write, &m_customCode.m_hasWrite) &&
98-
commsPrepareOverrideInternal(obj.parseRefreshOverride(), "refresh", &CommsField::commsCustomRefreshCodeInternal, m_customCode.m_refresh, &m_customCode.m_hasRefresh) &&
99-
commsPrepareOverrideInternal(obj.parseLengthOverride(), "length", &CommsField::commsCustomLengthCodeInternal, m_customCode.m_length, &m_customCode.m_hasLength) &&
100-
commsPrepareOverrideInternal(obj.parseValidOverride(), "valid", &CommsField::commsCustomValidCodeInternal, m_customCode.m_valid, &m_customCode.m_hasValid) &&
101-
commsPrepareOverrideInternal(obj.parseNameOverride(), "name", &CommsField::commsCustomNameCodeInternal, m_customCode.m_name, &m_customCode.m_hasName)
95+
commsPrepareOverrideInternal(obj.parseValueOverride(), "value", &CommsField::commsCustomValueCodeInternal, m_customCode.m_value, m_customCode.m_hasValue) &&
96+
commsPrepareOverrideInternal(obj.parseReadOverride(), "read", &CommsField::commsCustomReadCodeInternal, m_customCode.m_read, m_customCode.m_hasRead) &&
97+
commsPrepareOverrideInternal(obj.parseWriteOverride(), "write", &CommsField::commsCustomWriteCodeInternal, m_customCode.m_write, m_customCode.m_hasWrite) &&
98+
commsPrepareOverrideInternal(obj.parseRefreshOverride(), "refresh", &CommsField::commsCustomRefreshCodeInternal, m_customCode.m_refresh, m_customCode.m_hasRefresh) &&
99+
commsPrepareOverrideInternal(obj.parseLengthOverride(), "length", &CommsField::commsCustomLengthCodeInternal, m_customCode.m_length, m_customCode.m_hasLength) &&
100+
commsPrepareOverrideInternal(obj.parseValidOverride(), "valid", &CommsField::commsCustomValidCodeInternal, m_customCode.m_valid, m_customCode.m_hasValid) &&
101+
commsPrepareOverrideInternal(obj.parseNameOverride(), "name", &CommsField::commsCustomNameCodeInternal, m_customCode.m_name, m_customCode.m_hasName)
102102
;
103103

104104
if (!overrides) {
@@ -850,7 +850,7 @@ bool CommsField::commsPrepareOverrideInternal(
850850
const std::string& name,
851851
CommsCustomCodeFunc codeFunc,
852852
std::string& code,
853-
bool* hasCode)
853+
bool& hasCode)
854854
{
855855
if (commsIsOverrideCodeRequired(type) && (!comms::genIsGlobalField(m_genField))) {
856856
m_genField.genGenerator().genLogger().genError(
@@ -859,32 +859,24 @@ bool CommsField::commsPrepareOverrideInternal(
859859
return false;
860860
}
861861

862-
auto updateHasCodeFlag =
863-
[hasCode](bool val)
864-
{
865-
if (hasCode != nullptr) {
866-
*hasCode = val;
867-
}
868-
};
869-
870862
do {
871863
if (!commsIsOverrideCodeAllowed(type)) {
872864
code.clear();
873-
updateHasCodeFlag(false);
865+
hasCode = false;
874866
break;
875867
}
876868

877869
bool hasCodeTmp = false;
878870
auto customCode = (this->*codeFunc)(hasCodeTmp);
879-
if ((hasCodeTmp) || (code.empty())) {
871+
if ((hasCodeTmp) || (!hasCode)) {
880872
code = std::move(customCode);
881-
updateHasCodeFlag(hasCodeTmp);
873+
hasCode = hasCode || hasCodeTmp;
882874
break;
883875
}
884876

885877
} while (false);
886878

887-
if (code.empty() && commsIsOverrideCodeRequired(type)) {
879+
if ((!hasCode) && commsIsOverrideCodeRequired(type)) {
888880
m_genField.genGenerator().genLogger().genError(
889881
"Overriding \"" + name + "\" operation is not provided in injected code for field \"" +
890882
m_genField.genParseObj().parseExternalRef() + "\".");

app/commsdsl2comms/src/CommsField.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class CommsField
196196
const std::string& name,
197197
CommsCustomCodeFunc codeFunc,
198198
std::string& code,
199-
bool* hasCode);
199+
bool& hasCode);
200200
std::string commsCustomValueCodeInternal(bool& hasRealCode) const;
201201
std::string commsCustomReadCodeInternal(bool& hasRealCode) const;
202202
std::string commsCustomWriteCodeInternal(bool& hasRealCode) const;

app/commsdsl2wireshark/src/Wireshark.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ std::string Wireshark::wiresharkDissectFuncInternal() const
135135
;
136136

137137
bool bodyReplaced = false;
138-
auto replacePath = m_wiresharkGenerator.wiresharkInputRelPathFor(wiresharkProtocolObjName(m_wiresharkGenerator) + ".dissector") + strings::genReplaceFileSuffixStr();
138+
auto replacePath = m_wiresharkGenerator.wiresharkInputDissectRelPathFor(wiresharkProtocolObjName(m_wiresharkGenerator) + ".dissector") + strings::genReplaceFileSuffixStr();
139139
auto replaceCode = m_wiresharkGenerator.genReadCodeInjectCode(replacePath, "Replace body", &bodyReplaced);
140140

141141
util::GenReplacementMap repl = {

app/commsdsl2wireshark/src/WiresharkBitfieldField.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ unsigned WiresharkBitfieldField::wiresharkMaskShiftFor(const WiresharkField& mem
111111

112112
bool WiresharkBitfieldField::genPrepareImpl()
113113
{
114-
if (!GenBase::genPrepareImpl()) {
114+
if ((!GenBase::genPrepareImpl()) ||
115+
(!WiresharkBase::wiresharkPrepare())) {
115116
return false;
116117
}
117118

@@ -122,7 +123,7 @@ bool WiresharkBitfieldField::genPrepareImpl()
122123
std::string WiresharkBitfieldField::wiresharkFieldRegistrationImpl(const WiresharkField* refField) const
123124
{
124125
static const std::string Templ =
125-
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", \"#^#DISP_NAME#$#\", base.HEX, #^#NIL#$#, #^#MASK#$#, #^#DESC#$#))\n"
126+
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, base.HEX, #^#NIL#$#, #^#MASK#$#, #^#DESC#$#))\n"
126127
;
127128

128129
auto obj = genParseObj();
@@ -131,7 +132,7 @@ std::string WiresharkBitfieldField::wiresharkFieldRegistrationImpl(const Wiresha
131132
{"CREATE_FUNC", Wireshark::wiresharkCreateFieldFuncName(WiresharkGenerator::wiresharkCast(genGenerator()))},
132133
{"TYPE", wiresharkIntegralType()},
133134
{"REF_NAME", wiresharkFieldRefName(refField)},
134-
{"DISP_NAME", wiresharkFieldDisplayNameStr(refField)},
135+
{"DISP_NAME", wiresharkFieldNameVarNameStr(refField)},
135136
{"NIL", strings::genNilStr()},
136137
{"MASK", wiresharkForcedIntegralFieldMask(refField)},
137138
{"DESC", wiresharkFieldDescriptionStr(refField)},

app/commsdsl2wireshark/src/WiresharkBundleField.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ WiresharkBundleField::WiresharkBundleField(WiresharkGenerator& generator, ParseF
3535

3636
bool WiresharkBundleField::genPrepareImpl()
3737
{
38-
if (!GenBase::genPrepareImpl()) {
38+
if ((!GenBase::genPrepareImpl()) ||
39+
(!WiresharkBase::wiresharkPrepare())) {
3940
return false;
4041
}
4142

@@ -46,15 +47,15 @@ bool WiresharkBundleField::genPrepareImpl()
4647
std::string WiresharkBundleField::wiresharkFieldRegistrationImpl(const WiresharkField* refField) const
4748
{
4849
static const std::string Templ =
49-
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.bytes(\"#^#REF_NAME#$#\", \"#^#DISP_NAME#$#\", base.SPACE, #^#DESC#$#))\n"
50+
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.bytes(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, base.SPACE, #^#DESC#$#))\n"
5051
;
5152

5253
auto obj = genParseObj();
5354
util::GenReplacementMap repl = {
5455
{"OBJ_NAME", wiresharkFieldObjName(refField)},
5556
{"CREATE_FUNC", Wireshark::wiresharkCreateFieldFuncName(WiresharkGenerator::wiresharkCast(genGenerator()))},
5657
{"REF_NAME", wiresharkFieldRefName(refField)},
57-
{"DISP_NAME", wiresharkFieldDisplayNameStr(refField)},
58+
{"DISP_NAME", wiresharkFieldNameVarNameStr(refField)},
5859
{"DESC", wiresharkFieldDescriptionStr(refField)},
5960
};
6061

app/commsdsl2wireshark/src/WiresharkDataField.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,13 @@ WiresharkDataField::WiresharkDataField(WiresharkGenerator& generator, ParseField
2626
{
2727
}
2828

29+
bool WiresharkDataField::genPrepareImpl()
30+
{
31+
if ((!GenBase::genPrepareImpl()) ||
32+
(!WiresharkBase::wiresharkPrepare())) {
33+
return false;
34+
}
35+
return true;
36+
}
37+
2938
} // namespace commsdsl2wireshark

app/commsdsl2wireshark/src/WiresharkDataField.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class WiresharkDataField final : public commsdsl::gen::GenDataField, public Wire
3333
using GenElem = commsdsl::gen::GenElem;
3434

3535
WiresharkDataField(WiresharkGenerator& generator, ParseField parseObj, GenElem* parent);
36+
37+
protected:
38+
virtual bool genPrepareImpl() override;
3639
};
3740

3841
} // namespace commsdsl2wireshark

app/commsdsl2wireshark/src/WiresharkEnumField.cpp

Lines changed: 11 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+
"local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.#^#TYPE#$#(\"#^#REF_NAME#$#\", #^#DISP_NAME#$#, #^#BASE#$#, #^#VALS_NAME#$#, #^#MASK#$#, #^#DESC#$#))\n"
4444
;
4545

4646
auto obj = genEnumFieldParseObj();
@@ -50,7 +50,7 @@ std::string WiresharkEnumField::wiresharkFieldRegistrationImpl(const WiresharkFi
5050
{"CREATE_FUNC", Wireshark::wiresharkCreateFieldFuncName(WiresharkGenerator::wiresharkCast(genGenerator()))},
5151
{"TYPE", wiresharkForcedIntegralFieldType(refField)},
5252
{"REF_NAME", wiresharkFieldRefName(refField)},
53-
{"DISP_NAME", wiresharkFieldDisplayNameStr(refField)},
53+
{"DISP_NAME", wiresharkFieldNameVarNameStr(refField)},
5454
{"VALS_NAME", wiresharkFieldObjName(refField) + strings::genValsSuffixStr()},
5555
{"BASE", "base.DEC_HEX"},
5656
{"MASK", wiresharkForcedIntegralFieldMask(refField)},
@@ -118,4 +118,13 @@ std::string WiresharkEnumField::wiresharkValsInternal(const WiresharkField* refF
118118
return util::genProcessTemplate(Templ, repl);
119119
}
120120

121+
bool WiresharkEnumField::genPrepareImpl()
122+
{
123+
if ((!GenBase::genPrepareImpl()) ||
124+
(!WiresharkBase::wiresharkPrepare())) {
125+
return false;
126+
}
127+
return true;
128+
}
129+
121130
} // namespace commsdsl2wireshark

app/commsdsl2wireshark/src/WiresharkEnumField.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ 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 WiresharkField* refField) const override;
38+
virtual bool genPrepareImpl() override;
39+
virtual std::string wiresharkFieldRegistrationImpl(const WiresharkField* refField) const override;
3940

4041
private:
4142
std::string wiresharkValsInternal(const WiresharkField* refField) const;

0 commit comments

Comments
 (0)